3 Copyright (C) 2013 sapier
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "guiPathSelectMenu.h"
22 GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env,
23 gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
24 const std::string &title, const std::string &formname,
25 bool is_file_select) :
26 GUIModalMenu(env, parent, id, menumgr),
27 m_title(utf8_to_wide(title)),
31 m_file_select_dialog(is_file_select)
35 GUIFileSelectMenu::~GUIFileSelectMenu()
38 setlocale(LC_NUMERIC, "C");
41 void GUIFileSelectMenu::regenerateGui(v2u32 screensize)
46 core::dimension2du size(600, 400);
47 core::rect<s32> rect(0, 0, screensize.X, screensize.Y);
50 recalculateAbsolutePosition(false);
53 Environment->addFileOpenDialog(m_title.c_str(), false, this, -1);
55 core::position2di pos = core::position2di(screensize.X / 2 - size.Width / 2,
56 screensize.Y / 2 - size.Height / 2);
57 m_fileOpenDialog->setRelativePosition(pos);
58 m_fileOpenDialog->setMinSize(size);
61 void GUIFileSelectMenu::drawMenu()
63 gui::IGUISkin *skin = Environment->getSkin();
67 gui::IGUIElement::draw();
70 void GUIFileSelectMenu::acceptInput()
72 if ((m_text_dst != 0) && (this->m_formname != "")) {
76 if (!m_file_select_dialog) {
77 core::string<fschar_t> string =
78 m_fileOpenDialog->getDirectoryName();
79 path = std::string(string.c_str());
81 path = wide_to_utf8(m_fileOpenDialog->getFileName());
83 fields[m_formname + "_accepted"] = path;
85 fields[m_formname + "_canceled"] = m_formname;
87 this->m_text_dst->gotText(fields);
92 bool GUIFileSelectMenu::OnEvent(const SEvent &event)
94 if (event.EventType == irr::EET_GUI_EVENT) {
95 switch (event.GUIEvent.EventType) {
96 case gui::EGET_ELEMENT_CLOSED:
97 case gui::EGET_FILE_CHOOSE_DIALOG_CANCELLED:
101 case gui::EGET_DIRECTORY_SELECTED:
102 m_accepted = !m_file_select_dialog;
105 case gui::EGET_FILE_SELECTED:
106 m_accepted = m_file_select_dialog;
114 return Parent ? Parent->OnEvent(event) : false;