1 //
2 // C++ Implementation: BoxOptions
3 //
4 // Description: Implements the Options Box.
5 //
6 //
7 // Author: Max Magalhães Velasques <maxvelasques@gmail.com>, (C) 2006
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #include "wxDFast.h"
14 #include "wx/colordlg.h"
15
BEGIN_EVENT_TABLE(mBoxOptions,wxDialog)16 BEGIN_EVENT_TABLE(mBoxOptions, wxDialog)
17 EVT_BUTTON(XRCID("btnoptionsave"), mBoxOptions::OnOk)
18 EVT_BUTTON(XRCID("btnoptioncancel"), mBoxOptions::OnCancel)
19 EVT_BUTTON(XRCID("btnoptiondestination"), mBoxOptions::OnButtonDir)
20 EVT_BUTTON(XRCID("btnfilemanagerpath"), mBoxOptions::OnFileManagerPath)
21 EVT_BUTTON(XRCID("btnbrowserpath"), mBoxOptions::OnBrowserPath)
22 EVT_BUTTON(XRCID("btntemppath"), mBoxOptions::OnTempPath)
23
24 EVT_BUTTON(XRCID("graphbtnback"), mBoxOptions::OnGraphBackgroundColour)
25 EVT_BUTTON(XRCID("graphbtngrid"), mBoxOptions::OnGraphGridColour)
26 EVT_BUTTON(XRCID("graphbtnline"), mBoxOptions::OnGraphLineColour)
27 EVT_BUTTON(XRCID("graphbtnfont"), mBoxOptions::OnGraphFontColour)
28 EVT_BUTTON(XRCID("btnstartdate"), mBoxOptions::OnButtonStartDate)
29 EVT_BUTTON(XRCID("btnfinishdate"), mBoxOptions::OnButtonFinishDate)
30 EVT_BUTTON(XRCID("btnexceptionadd"), mBoxOptions::OnAdd)
31 EVT_BUTTON(XRCID("btnexceptionremove"), mBoxOptions::OnRemove)
32 END_EVENT_TABLE()
33
34 BEGIN_EVENT_TABLE(mBoxOptionsColorPanel, wxPanel)
35 EVT_PAINT(mBoxOptionsColorPanel::OnPaint)
36 END_EVENT_TABLE()
37
38 BEGIN_EVENT_TABLE(mDatePicker, wxDialog)
39 EVT_BUTTON(wxID_OK,mDatePicker::OnOk)
40 END_EVENT_TABLE()
41
42 void mBoxOptions::OnOk(wxCommandEvent& event)
43 {
44 EndModal(XRCID("btnoptionsave"));
45 }
46
OnCancel(wxCommandEvent & event)47 void mBoxOptions::OnCancel(wxCommandEvent& event)
48 {
49 EndModal(XRCID("btnoptioncancel"));
50 }
51
OnButtonDir(wxCommandEvent & event)52 void mBoxOptions::OnButtonDir(wxCommandEvent& event)
53 {
54 wxString dir;
55 dir = wxDirSelector(_("Select the directory:"));
56 if (dir != wxEmptyString)
57 XRCCTRL(*this, "edtdestination",wxTextCtrl)->SetValue(dir);
58 }
59
OnBrowserPath(wxCommandEvent & event)60 void mBoxOptions::OnBrowserPath(wxCommandEvent& event)
61 {
62 wxFileDialog dialog(this, _("Choose a file..."),wxEmptyString,wxEmptyString,wxT("*"),wxOPEN | wxFILE_MUST_EXIST);
63 if (dialog.ShowModal() == wxID_OK)
64 XRCCTRL(*this, "edtbrowserpath",wxTextCtrl)->SetValue(dialog.GetPath());
65 }
66
OnFileManagerPath(wxCommandEvent & event)67 void mBoxOptions::OnFileManagerPath(wxCommandEvent& event)
68 {
69 wxFileDialog dialog(this, _("Choose a file..."),wxEmptyString,wxEmptyString,wxT("*"),wxOPEN | wxFILE_MUST_EXIST);
70 if (dialog.ShowModal() == wxID_OK)
71 XRCCTRL(*this, "edtfilemanagerpath",wxTextCtrl)->SetValue(dialog.GetPath());
72 }
73
OnTempPath(wxCommandEvent & event)74 void mBoxOptions::OnTempPath(wxCommandEvent& event)
75 {
76 wxString dir;
77 dir = wxDirSelector(_("Select the directory:"));
78 if (dir != wxEmptyString)
79 XRCCTRL(*this, "edttemppath",wxTextCtrl)->SetValue(dir);
80 }
81
OnGraphBackgroundColour(wxCommandEvent & event)82 void mBoxOptions::OnGraphBackgroundColour(wxCommandEvent& event)
83 {
84 wxColour colour = wxGetColourFromUser(this);
85 if (colour.Ok())
86 {
87 XRCCTRL(*(this), "graphpanelback",mBoxOptionsColorPanel)->colour = colour;
88 XRCCTRL(*(this), "graphpanelback",mBoxOptionsColorPanel)->Refresh();
89 }
90 }
91
OnGraphGridColour(wxCommandEvent & event)92 void mBoxOptions::OnGraphGridColour(wxCommandEvent& event)
93 {
94 wxColour colour = wxGetColourFromUser(this);
95 if (colour.Ok())
96 {
97 XRCCTRL(*(this), "graphpanelgrid",mBoxOptionsColorPanel)->colour = colour;
98 XRCCTRL(*(this), "graphpanelgrid",mBoxOptionsColorPanel)->Refresh();
99 }
100 }
101
OnGraphLineColour(wxCommandEvent & event)102 void mBoxOptions::OnGraphLineColour(wxCommandEvent& event)
103 {
104 wxColour colour = wxGetColourFromUser(this);
105 if (colour.Ok())
106 {
107 XRCCTRL(*(this), "graphpanelline",mBoxOptionsColorPanel)->colour = colour;
108 XRCCTRL(*(this), "graphpanelline",mBoxOptionsColorPanel)->Refresh();
109 }
110 }
111
OnGraphFontColour(wxCommandEvent & event)112 void mBoxOptions::OnGraphFontColour(wxCommandEvent& event)
113 {
114 wxColour colour = wxGetColourFromUser(this);
115 if (colour.Ok())
116 {
117 XRCCTRL(*(this), "graphpanelfont",mBoxOptionsColorPanel)->colour = colour;
118 XRCCTRL(*(this), "graphpanelfont",mBoxOptionsColorPanel)->Refresh();
119 }
120 }
121
OnPaint(wxPaintEvent & event)122 void mBoxOptionsColorPanel::OnPaint(wxPaintEvent &event)
123 {
124 wxPaintDC dc(this);
125 if (colour.Ok())
126 {
127 wxBrush b(colour, wxSOLID);
128 dc.SetBackground(b);
129 dc.Clear();
130 }
131 }
132
OnButtonStartDate(wxCommandEvent & event)133 void mBoxOptions::OnButtonStartDate(wxCommandEvent& event)
134 {
135 mDatePicker datepicker(this,0,_("Select the date..."),XRCCTRL(*this, "edtstartdate",wxTextCtrl)->GetValue());
136 if (datepicker.ShowModal() == wxID_OK)
137 XRCCTRL(*this, "edtstartdate",wxTextCtrl)->SetValue(datepicker.GetSelectedDate());
138 }
139
OnButtonFinishDate(wxCommandEvent & event)140 void mBoxOptions::OnButtonFinishDate(wxCommandEvent& event)
141 {
142 mDatePicker datepicker(this,0,_("Select the date..."),XRCCTRL(*this, "edtfinishdate",wxTextCtrl)->GetValue());
143 if (datepicker.ShowModal() == wxID_OK)
144 XRCCTRL(*this, "edtfinishdate",wxTextCtrl)->SetValue(datepicker.GetSelectedDate());
145 }
146
OnAdd(wxCommandEvent & event)147 void mBoxOptions::OnAdd(wxCommandEvent& event)
148 {
149 if (XRCCTRL(*this, "lstexceptionlist",wxListBox)->GetCount() < MAX_SCHEDULE_EXCEPTIONS)
150 {
151 wxString start,finish,day,string;
152 start = MyUtilFunctions::int2wxstr(XRCCTRL(*this, "spinexceptionstarthour",wxSpinCtrl)->GetValue(),2) + wxT(":") + MyUtilFunctions::int2wxstr(XRCCTRL(*this, "spinexceptionstartminute",wxSpinCtrl)->GetValue(),2);
153 finish = MyUtilFunctions::int2wxstr(XRCCTRL(*this, "spinexceptionfinishhour",wxSpinCtrl)->GetValue(),2) + wxT(":") + MyUtilFunctions::int2wxstr(XRCCTRL(*this, "spinexceptionfinishminute",wxSpinCtrl)->GetValue(),2);
154 string = start + wxT(" | ") + finish + wxT(" | ") + XRCCTRL(*this, "comboweekdays",wxComboBox)->GetValue();
155 XRCCTRL(*this, "lstexceptionlist",wxListBox)->InsertItems(1,&string,0);
156 }
157 else
158 wxMessageBox(_("Remove some items before adding a new one."));
159 }
160
OnRemove(wxCommandEvent & event)161 void mBoxOptions::OnRemove(wxCommandEvent& event)
162 {
163 int i;
164 wxListBox *listbox = XRCCTRL(*this, "lstexceptionlist",wxListBox);
165 for (i = 0;i < MAX_SCHEDULE_EXCEPTIONS;i++)
166 {
167 if (listbox->IsSelected(i))
168 {
169 listbox->Delete(i);
170 break;
171 }
172 }
173 }
174