2
* This file is part of DroidPad.
3
* DroidPad lets you use an Android mobile to control a joystick or mouse
4
* on a Windows or Linux computer.
6
* DroidPad is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* DroidPad is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with DroidPad, in the file COPYING.
18
* If not, see <http://www.gnu.org/licenses/>.
21
#include "preferences.hpp"
23
#include <wx/xrc/xmlres.h>
24
#include <wx/msgdlg.h>
28
BEGIN_EVENT_TABLE(Preferences, wxDialog)
29
EVT_BUTTON(XRCID("okButton"), Preferences::onDone)
30
EVT_BUTTON(XRCID("cancelButton"), Preferences::onCancel)
33
using namespace droidpad;
37
#define _FRAME_ICON wxT("icon.xpm")
39
#define _FRAME_ICON wxT("iconlarge.xpm")
42
#define CHECK_XML(_name) if(!_name) handleXMLError(wxT(#_name))
44
#define LOADXRC(_xml, _name, _type) _name = XRCCTRL(*this, #_xml, _type); \
45
if(_name == NULL) handleXMLError(wxT(#_xml));
48
#define NUM_BUTTONS 12
50
Preferences::Preferences(wxWindow *parent) {
51
if(!wxXmlResource::Get()->LoadDialog(this, parent, wxT("preferences"))) {
52
LOGE("Failed to load preferences dialog XML.");
55
SetIcon(wxIcon(Data::getFilePath(_FRAME_ICON), wxBITMAP_TYPE_XPM));
57
LOADXRC(slideshowBlackKey, blackKey, wxTextCtrl);
58
LOADXRC(slideshowWhiteKey, whiteKey, wxTextCtrl);
63
void Preferences::onDone(wxCommandEvent &evt) {
64
// Save selection to prefs again
65
if(blackKey->GetValue().size() > 0)
66
Data::blackKey = blackKey->GetValue().GetChar(0);
67
else Data::blackKey = 'b';
68
if(whiteKey->GetValue().size() > 0)
69
Data::whiteKey = whiteKey->GetValue().GetChar(0);
70
else Data::whiteKey = 'w';
71
Data::savePreferences();
74
void Preferences::onCancel(wxCommandEvent &evt) {
78
void Preferences::handleXMLError(wxString name)
80
wxMessageDialog(this, wxString::Format(_("Error loading layout while loading \"%s\".\nPlease report this as a bug."), name.c_str()), _("Error loading layout"), wxOK | wxICON_EXCLAMATION).ShowModal();