~onli/simdock/master

« back to all changes in this revision

Viewing changes to src/settingsDialog.cc

  • Committer: onli
  • Date: 2011-07-07 12:24:23 UTC
  • Revision ID: git-v1:96c327bf55055eb2a7070d498dbcbf04f309221c
moved sources from unstable-svn-branch to here

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  
 
2
 *   Copyright 2007 Simone Della Longa <simonedll@yahoo.it>
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License, or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not, write to the Free Software
 
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "settingsDialog.h"
 
20
#include "wx/textctrl.h"
 
21
 
 
22
using namespace std;
 
23
 
 
24
 
 
25
IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog)
 
26
 
 
27
BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog)
 
28
EVT_BUTTON(ID_Browse_Bg, SettingsDialog::OnBrowseEvent)
 
29
END_EVENT_TABLE()
 
30
 
 
31
 
 
32
 
 
33
SettingsDialog::SettingsDialog(wxWindow* win, simSettings* settings)
 
34
{
 
35
    this->settings = settings;
 
36
    SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY);
 
37
 
 
38
 
 
39
    int  tabImage1 = 0;
 
40
        int tabImage2 = 1;
 
41
        int tabImage3 = 2;
 
42
 
 
43
    int sheetStyle = wxPROPSHEET_TOOLBOOK;
 
44
 
 
45
 
 
46
    SetSheetStyle(sheetStyle);
 
47
    SetSheetInnerBorder(0);
 
48
    SetSheetOuterBorder(0);
 
49
    // create a dummy image list with a few icons
 
50
    const wxSize imageSize(32, 32);
 
51
 
 
52
    m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight());
 
53
        
 
54
    /* TODO: Check for wxNullIcon here */
 
55
    m_imageList->Add(wxArtProvider::GetIcon(_T("applications-system"), wxART_OTHER, imageSize));
 
56
    m_imageList->Add(wxArtProvider::GetIcon(_T("applications-accessories"), wxART_OTHER, imageSize));
 
57
    m_imageList->Add(wxArtProvider::GetIcon(_T("applications-graphics"), wxART_OTHER, imageSize));
 
58
    m_imageList->Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize));
 
59
 
 
60
 
 
61
    Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize,
 
62
        wxDEFAULT_DIALOG_STYLE| wxRESIZE_BORDER);
 
63
        
 
64
 
 
65
    notebook = GetBookCtrl();
 
66
    
 
67
    notebook->SetImageList(m_imageList);
 
68
 
 
69
    generalSettings = CreateGeneralSettingsPage(notebook);
 
70
    aestheticSettings = CreateAestheticSettingsPage(notebook);
 
71
    backgroundSettings = CreateBackgroundPage(notebook);
 
72
 
 
73
    if (!notebook->AddPage(generalSettings, _("General"), true, tabImage1))
 
74
    {
 
75
        cout << "Error adding general settings page" << endl;
 
76
    }
 
77
    if (!notebook->AddPage(aestheticSettings, _("Borders"), false, tabImage2))
 
78
    {
 
79
        cout << "Error adding Borders settings page" << endl;
 
80
    }
 
81
    if (!notebook->AddPage(backgroundSettings, _("Appearance"), false, tabImage3))
 
82
    {
 
83
        cout << "Error adding Background settings page" << endl;
 
84
    }
 
85
 
 
86
    CreateButtons(wxOK|wxCANCEL);
 
87
    LayoutDialog();
 
88
    
 
89
}
 
90
 
 
91
 
 
92
SettingsDialog::~SettingsDialog()
 
93
 
94
    delete(m_imageList); 
 
95
 /*   delete (zoom_text); 
 
96
    delete (range_text); 
 
97
    delete(bg_height_text);
 
98
    delete (bg_path_text);
 
99
    delete (left_border_text);
 
100
    delete (right_border_text);
 
101
    delete (bottom_border_text);
 
102
    delete (spacer_border_text);
 
103
    delete (width_text);
 
104
    delete (height_text);
 
105
    delete (reflex_enabled);
 
106
    delete (reflex_scaling_text);
 
107
    delete (reflex_alpha_text);
 
108
    delete (browse_button);
 
109
    */
 
110
    delete (generalSettings);
 
111
    delete (aestheticSettings);
 
112
    delete (backgroundSettings);
 
113
    delete (notebook);
 
114
}
 
115
 
 
116
bool checkInt(wxTextCtrl* control, int* value, unsigned long minvalue, unsigned long maxvalue)
 
117
{
 
118
    unsigned long temp;
 
119
    if (!control->GetValue().ToULong(&temp,10))
 
120
    {
 
121
            wxMessageBox (_T ("Cannot convert this to number? ") + control->GetValue() , _T ("SimDock"), wxOK | wxICON_ERROR, NULL);
 
122
            return false;
 
123
    }
 
124
    else
 
125
    {
 
126
            if (temp < minvalue || temp > maxvalue)
 
127
            {
 
128
            wxMessageBox (_T ("Wrong value! ") + control->GetValue()+
 
129
            wxString::Format(_T("Should be between %d and %d"),minvalue,maxvalue) , _T ("SimDock"), wxOK | wxICON_ERROR, NULL);
 
130
            return false;
 
131
            }
 
132
    
 
133
        *value = (int) temp;    
 
134
        return true;
 
135
    }
 
136
 
 
137
}
 
138
simSettings* SettingsDialog::GetSettings()
 
139
{
 
140
    /* Zoom */
 
141
    if (!checkInt(zoom_text, &settings->PERCENT,0,1000))
 
142
        return NULL;
 
143
        
 
144
    if (!checkInt(range_text, &settings->RANGE,0,1000))
 
145
        return NULL;
 
146
        
 
147
    /* BackGround */
 
148
    
 
149
    if (!checkInt(bg_height_text, &settings->BG_HEIGHT,0,1000))
 
150
        return NULL;
 
151
        
 
152
    if (!wxFileExists(bg_path_text->GetValue()))
 
153
    {
 
154
            wxMessageBox (_T ("Invalid value for ") + bg_path_text->GetValue() , _T ("SimDock"), wxOK | wxICON_ERROR, NULL);
 
155
            return NULL;
 
156
    }
 
157
    else
 
158
    {
 
159
        settings->BG_PATH = bg_path_text->GetValue();
 
160
    }
 
161
    
 
162
        
 
163
    /* Borders */
 
164
          if (!checkInt(left_border_text, &settings->LEFT_BORDER,0,1000))
 
165
        return NULL;
 
166
          if (!checkInt(right_border_text, &settings->RIGHT_BORDER,0,1000))
 
167
        return NULL;
 
168
          if (!checkInt(bottom_border_text, &settings->BOTTOM_BORDER,0,1000))
 
169
        return NULL;
 
170
          if (!checkInt(spacer_border_text, &settings->SPACER,0,1000))
 
171
        return NULL;
 
172
          if (!checkInt(width_text, &settings->ICONW,0,200))
 
173
        return NULL;
 
174
          if (!checkInt(height_text, &settings->ICONH,0,200))
 
175
        return NULL;
 
176
         if (!checkInt(reflex_scaling_text, &settings->REFLEX_SCALING,1,100))
 
177
        return NULL;
 
178
        if (!checkInt(reflex_alpha_text, &settings->REFLEX_ALPHA,0,255))
 
179
          return NULL;
 
180
 
 
181
        settings->SHOW_REFLEXES = reflex_enabled->IsChecked();
 
182
        settings->AUTO_POSITION = auto_position->IsChecked();
 
183
        settings->ENABLE_TASKS = enable_tasks->IsChecked();     
 
184
    
 
185
  return settings;
 
186
    
 
187
 
 
188
}
 
189
 
 
190
 
 
191
 
 
192
wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent)
 
193
{
 
194
    wxPanel* panel = new wxPanel(parent, wxID_ANY);
 
195
    wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
 
196
    
 
197
    /* ---------------  ZOOM STUFF  ----------------------*/
 
198
    wxStaticBoxSizer* item2 = new wxStaticBoxSizer(wxVERTICAL, panel, _T("Zoom"));
 
199
    /* Zoom */
 
200
    wxBoxSizer* itemSizer6 = new wxBoxSizer( wxHORIZONTAL );
 
201
    zoom_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->PERCENT));
 
202
    zoom_text->SetMaxLength(5);
 
203
    itemSizer6->Add(new wxStaticText(panel,-1,_T("Zoom")),wxGROW|wxALL,5);
 
204
    itemSizer6->Add(zoom_text,wxGROW|wxALL,5);
 
205
    item2->Add(itemSizer6, 0, wxGROW|wxALL, 5);
 
206
    
 
207
    /* Zoom range */
 
208
    wxBoxSizer* itemSizer7 = new wxBoxSizer( wxHORIZONTAL );
 
209
    range_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->RANGE));
 
210
    range_text->SetMaxLength(5);
 
211
    itemSizer7->Add(new wxStaticText(panel,-1,_T("Range")),wxGROW|wxALL,5);
 
212
    itemSizer7->Add(range_text,wxGROW|wxALL,5);
 
213
    item2->Add(itemSizer7, 0, wxGROW|wxALL, 5);
 
214
 
 
215
    topSizer->Add( item2, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
 
216
    /* ---------------  ZOOM STUFF  ----------------------*/
 
217
    
 
218
    
 
219
    /* ---------------  BEHAVIOUR STUFF  ----------------------*/
 
220
    wxStaticBoxSizer* item3 = new wxStaticBoxSizer(wxVERTICAL, panel, _T("Behaviour"));
 
221
    /* Automatic positioning */    
 
222
    auto_position = new wxCheckBox(panel,-1,_T("Automatic positioning"));
 
223
    auto_position->SetValue(settings->AUTO_POSITION);
 
224
    item3->Add(auto_position, 0, wxGROW|wxALL, 5);
 
225
    
 
226
    /* Enable tasks */
 
227
    enable_tasks = new wxCheckBox(panel,-1,_T("Show tasks"));
 
228
    enable_tasks->SetValue(settings->ENABLE_TASKS);
 
229
    item3->Add(enable_tasks, 0, wxGROW|wxALL, 5);
 
230
 
 
231
    topSizer->Add( item3, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
 
232
    /* ---------------  BEHAVIOUR STUFF  ----------------------*/
 
233
 
 
234
    panel->SetSizer(topSizer);
 
235
    topSizer->Fit(panel);
 
236
 
 
237
    return panel;
 
238
}
 
239
 
 
240
wxPanel* SettingsDialog::CreateBackgroundPage(wxWindow* parent)
 
241
{
 
242
    wxPanel* panel = new wxPanel(parent, wxID_ANY);
 
243
    wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
 
244
    
 
245
    /* --------------- BACKGROUND STUFF ----------------------*/
 
246
    wxStaticBoxSizer* item0 = new wxStaticBoxSizer(wxVERTICAL, panel, _T("Background"));
 
247
 
 
248
 
 
249
    /* Background height */
 
250
    wxBoxSizer* itemSizer4 = new wxBoxSizer( wxHORIZONTAL );
 
251
    bg_height_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->BG_HEIGHT));
 
252
    bg_height_text->SetMaxLength(5);
 
253
    itemSizer4->Add(new wxStaticText(panel,-1,_T("Background Height")),wxGROW|wxALL,5);
 
254
    itemSizer4->Add(bg_height_text,wxGROW|wxALL,5);
 
255
    item0->Add(itemSizer4, 0, wxGROW|wxALL, 5);
 
256
    
 
257
    /* Background path */
 
258
    wxBoxSizer* itemSizer5 = new wxBoxSizer( wxHORIZONTAL );
 
259
    bg_path_text = new wxTextCtrl(panel,-1,settings->BG_PATH,wxDefaultPosition,wxSize(150,wxDefaultSize.GetHeight()));
 
260
    itemSizer5->Add(new wxStaticText(panel,-1,_T("Background Path")),wxGROW|wxALL,5);
 
261
    itemSizer5->Add(bg_path_text,wxGROW|wxALL,5);
 
262
    
 
263
    /* Browse button */
 
264
    wxBoxSizer* itemSizer6 = new wxBoxSizer( wxHORIZONTAL );
 
265
    browse_button  = new wxButton(panel,ID_Browse_Bg, _T("Browse"));  
 
266
    itemSizer6->Add( 200,20, 1 );
 
267
    itemSizer6->Add(browse_button,0,wxRIGHT);
 
268
    
 
269
    item0->Add(itemSizer5, 0, wxGROW|wxALL, 5);
 
270
    item0->Add(itemSizer6, wxALL,5);
 
271
 
 
272
    topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
 
273
    /* --------------- BACKGROUND STUFF ----------------------*/
 
274
    
 
275
    
 
276
    /* --------------- REFLEX STUFF ----------------------*/
 
277
    wxStaticBoxSizer* item3 = new wxStaticBoxSizer(wxVERTICAL, panel, _T("Reflexes"));
 
278
    
 
279
    /* enable reflexes */
 
280
    reflex_enabled = new wxCheckBox(panel,-1,_T("Enable reflexes"));
 
281
    reflex_enabled->SetValue(settings->SHOW_REFLEXES);
 
282
    item3->Add(reflex_enabled, 0, wxGROW|wxALL, 5);
 
283
    
 
284
    /* reflex scaling */
 
285
    wxBoxSizer* itemSizer9 = new wxBoxSizer( wxHORIZONTAL );
 
286
    reflex_scaling_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->REFLEX_SCALING));
 
287
    reflex_scaling_text->SetMaxLength(5);
 
288
    itemSizer9->Add(new wxStaticText(panel,-1,_T("Reflex scaling")),wxGROW|wxALL,5);
 
289
    itemSizer9->Add(reflex_scaling_text,wxGROW|wxALL,5);
 
290
    item3->Add(itemSizer9, 0, wxGROW|wxALL, 5);
 
291
    
 
292
    
 
293
    /* reflex transparency */
 
294
    wxBoxSizer* itemSizer10 = new wxBoxSizer( wxHORIZONTAL );
 
295
    reflex_alpha_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->REFLEX_ALPHA));
 
296
    reflex_alpha_text->SetMaxLength(5);
 
297
    itemSizer10->Add(new wxStaticText(panel,-1,_T("Reflex transparency")),wxGROW|wxALL,5);
 
298
    itemSizer10->Add(reflex_alpha_text,wxGROW|wxALL,5);
 
299
    item3->Add(itemSizer10, 0, wxGROW|wxALL, 5);
 
300
   
 
301
    
 
302
    
 
303
 
 
304
    topSizer->Add( item3, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
 
305
    /* --------------- REFLEX STUFF ----------------------*/
 
306
    
 
307
    
 
308
    
 
309
    
 
310
    
 
311
    
 
312
    panel->SetSizer(topSizer);
 
313
    topSizer->Fit(panel);
 
314
 
 
315
    return panel;
 
316
}
 
317
 
 
318
wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
 
319
{
 
320
    wxPanel* panel = new wxPanel(parent, wxID_ANY);
 
321
 
 
322
    wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
 
323
    wxStaticBoxSizer* item0 = new wxStaticBoxSizer(wxVERTICAL, panel, _T("Borders"));   
 
324
 
 
325
 
 
326
    /* Left border */
 
327
    wxBoxSizer* itemSizer0 = new wxBoxSizer( wxHORIZONTAL );
 
328
    left_border_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->LEFT_BORDER));
 
329
    left_border_text->SetMaxLength(5);
 
330
    itemSizer0->Add(new wxStaticText(panel,-1,_T("Left Border")),wxGROW|wxALL,5);
 
331
    itemSizer0->Add(left_border_text,wxGROW|wxALL,5);
 
332
    item0->Add(itemSizer0, 0, wxGROW|wxALL, 5);
 
333
    
 
334
    /* Right border */
 
335
    wxBoxSizer* itemSizer1 = new wxBoxSizer( wxHORIZONTAL );
 
336
    right_border_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->RIGHT_BORDER));
 
337
    right_border_text->SetMaxLength(5);
 
338
    itemSizer1->Add(new wxStaticText(panel,-1,_T("Right Border")),wxGROW|wxALL,5);
 
339
    itemSizer1->Add(right_border_text,wxGROW|wxALL,5);
 
340
    item0->Add(itemSizer1, 0, wxGROW|wxALL, 5);
 
341
    
 
342
    /* Bottom border */
 
343
    wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL );
 
344
    bottom_border_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->BOTTOM_BORDER));
 
345
    bottom_border_text->SetMaxLength(5);
 
346
    itemSizer2->Add(new wxStaticText(panel,-1,_T("Bottom Border")),wxGROW|wxALL,5);
 
347
    itemSizer2->Add(bottom_border_text,wxGROW|wxALL,5);
 
348
    item0->Add(itemSizer2, 0, wxGROW|wxALL, 5);
 
349
    
 
350
    /* Spacer */
 
351
    wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL );
 
352
    spacer_border_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->SPACER));
 
353
    spacer_border_text->SetMaxLength(5);
 
354
    itemSizer3->Add(new wxStaticText(panel,-1,_T("Icons spacer")),wxGROW|wxALL,5);
 
355
    itemSizer3->Add(spacer_border_text,wxGROW|wxALL,5);
 
356
    item0->Add(itemSizer3, 0, wxGROW|wxALL, 5);
 
357
    
 
358
    
 
359
    
 
360
    wxStaticBoxSizer* item1 = new wxStaticBoxSizer(wxVERTICAL, panel, _T("Icons"));
 
361
    
 
362
    /* Icons width */
 
363
    wxBoxSizer* itemSizer4 = new wxBoxSizer( wxHORIZONTAL );
 
364
    width_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->ICONW));
 
365
    width_text->SetMaxLength(5);
 
366
    itemSizer4->Add(new wxStaticText(panel,-1,_T("Icons width")),wxGROW|wxALL,5);
 
367
    itemSizer4->Add(width_text,wxGROW|wxALL,5);
 
368
    item1->Add(itemSizer4, 0, wxGROW|wxALL, 5);
 
369
    
 
370
    /* Icons height */
 
371
    wxBoxSizer* itemSizer5 = new wxBoxSizer( wxHORIZONTAL );
 
372
    height_text = new wxTextCtrl(panel,-1,wxString::Format(_T("%d"),settings->ICONH));
 
373
    height_text->SetMaxLength(5);
 
374
    itemSizer5->Add(new wxStaticText(panel,-1,_T("Icons height")),wxGROW|wxALL,5);
 
375
    itemSizer5->Add(height_text,wxGROW|wxALL,5);
 
376
    item1->Add(itemSizer5, 0, wxGROW|wxALL, 5);
 
377
 
 
378
    topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
 
379
    topSizer->Add( item1, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
 
380
    topSizer->AddSpacer(5);
 
381
 
 
382
    panel->SetSizer(topSizer);
 
383
    topSizer->Fit(panel);
 
384
 
 
385
    return panel;
 
386
}
 
387
 
 
388
/* -------------- Event callbacks -------------------- */
 
389
 
 
390
 
 
391
void SettingsDialog::OnBrowseEvent(wxCommandEvent& event)
 
392
{
 
393
wxFileName fn(bg_path_text->GetValue());
 
394
 
 
395
wxString filename = wxFileSelector(_T("Choose a file to open"),fn.GetPath(), _T(""), _T("png"), _T( "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif|PNG files (*.png)|*.png|All files (*.*)|*.*"), wxOPEN | wxFILE_MUST_EXIST);
 
396
if ( !filename.empty() )
 
397
{
 
398
        bg_path_text->SetValue(filename);
 
399
}
 
400
 
 
401
 
 
402
}
 
403
 
 
404
 
 
405