/[cvs]/dary/gui.cpp
ViewVC logotype

Contents of /dary/gui.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations)
Sat Feb 14 14:47:00 2009 UTC (9 years, 8 months ago) by riso
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +13 -4 lines
Konverzia na euro

1 #include "config.h"
2 #include "wx/wx.h"
3 #include "db_view.h"
4 #include <wx/config.h>
5 #include <wx/datetime.h>
6 #include <wx/grid.h>
7 #include <wx/print.h>
8 #include <math.h>
9 #include <stdio.h>
10
11 #define menuExit 1
12 #define menuAbout 2
13 #define buttonAdd 3
14 #define radioMode 4
15 #define radioSort 5
16 #define menuDb 6
17 #define menuConfig 7
18
19 #define buttonDelete 8
20 #define idName 9
21 #define buttonEnvelopes 10
22
23 #define DEFAULT_FONTSIZE "11"
24 #define DEFAULT_WIDTH "221"
25 #define DEFAULT_HEIGHT "110"
26 #define DEFAULT_XOFFSET "120"
27 #define DEFAULT_YOFFSET "60"
28
29 static wxMutex db;
30
31 class ConfigDialog: public wxDialog {
32 public:
33 ConfigDialog(wxWindow *parent);
34 private:
35 wxTextCtrl *width, *height, *xoffset, *yoffset, *size;
36 void OnOK(wxCommandEvent &event);
37
38 DECLARE_EVENT_TABLE()
39 };
40
41 BEGIN_EVENT_TABLE(ConfigDialog, wxDialog)
42 EVT_BUTTON(wxID_OK, ConfigDialog::OnOK)
43 END_EVENT_TABLE()
44
45 class PersonEditDialog: public wxDialog {
46 public:
47 PersonEditDialog(wxWindow *parent, tPersonId id);
48 private:
49 tPersonId id;
50 wxTextCtrl *name, *surname, *title, *addrname, *street, *city, *zip;
51 void OnOK(wxCommandEvent &event);
52 void OnDelete(wxCommandEvent &event);
53
54 DECLARE_EVENT_TABLE()
55 };
56
57 BEGIN_EVENT_TABLE(PersonEditDialog, wxDialog)
58 EVT_BUTTON(wxID_OK, PersonEditDialog::OnOK)
59 EVT_BUTTON(buttonDelete, PersonEditDialog::OnDelete)
60 END_EVENT_TABLE()
61
62 class EntryEditDialog: public wxDialog {
63 public:
64 EntryEditDialog(wxWindow *parent, tEntryId id);
65 private:
66 tEntryId id;
67 wxTextCtrl *name, *surname, *title, *addrname, *street, *city, *zip, *date, *sum;
68 void OnOK(wxCommandEvent &event);
69 void OnDelete(wxCommandEvent &event);
70
71 DECLARE_EVENT_TABLE()
72 };
73
74 BEGIN_EVENT_TABLE(EntryEditDialog, wxDialog)
75 EVT_BUTTON(wxID_OK, EntryEditDialog::OnOK)
76 EVT_BUTTON(buttonDelete, EntryEditDialog::OnDelete)
77 END_EVENT_TABLE()
78
79
80 class MyApp: public wxApp
81 { public:
82 virtual bool OnInit();
83 };
84
85 IMPLEMENT_APP(MyApp)
86
87 class MainGrid: public wxGrid {
88 public:
89 MainGrid(wxWindow* parent):wxGrid(parent, -1, wxDefaultPosition, wxDefaultSize) {}
90 void OnSize2(wxSizeEvent& event);
91 // void OnKeyDown2(wxKeyEvent& event);
92 void ResetWidth();
93
94 private:
95 DECLARE_EVENT_TABLE()
96 };
97
98 BEGIN_EVENT_TABLE(MainGrid, wxGrid)
99 EVT_SIZE(MainGrid::OnSize2)
100 // EVT_KEY_DOWN(MainGrid::OnKeyDown2)
101 END_EVENT_TABLE()
102
103 class MainFrame: public wxFrame
104 {
105 public:
106 MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size);
107 void OnExit(wxCloseEvent& event);
108 void OnExit2(wxCommandEvent& event);
109 void OnAbout(wxCommandEvent& event);
110 void OnModeChange(wxCommandEvent& event);
111 void OnSortChange(wxCommandEvent& event);
112 void OnDbChange(wxCommandEvent& event);
113 void OnConfig(wxCommandEvent& event);
114 void OnAdd(wxCommandEvent& event);
115 void OnGridClicked(wxGridEvent& event);
116 void OnNameUpdate(wxCommandEvent &event);
117 void OnNameSelect(wxCommandEvent &event);
118 void OnPrint(wxCommandEvent &event);
119
120 void UpdateView();
121
122 private:
123 wxRadioBox *listmode, *sortorder;
124 wxTextCtrl *name, *surname, *date, *sum;
125 wxButton *add, *envelopes;
126 wxMutex *dblock;
127 MainGrid *view;
128 wxListBox *comp;
129 wxTextCtrl *pocetludi, *pocetdarov, *sumadarov;
130 char **compa;
131 int disable_listbox_update;
132
133 wxStaticBox *statbox;
134 wxStaticBoxSizer *statistics;
135
136 DECLARE_EVENT_TABLE()
137 };
138
139 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
140 EVT_CLOSE(MainFrame::OnExit)
141 EVT_MENU(menuExit, MainFrame::OnExit2)
142 EVT_MENU(menuAbout, MainFrame::OnAbout)
143 EVT_MENU(menuDb, MainFrame::OnDbChange)
144 EVT_MENU(menuConfig, MainFrame::OnConfig)
145 EVT_RADIOBOX(radioMode, MainFrame::OnModeChange)
146 EVT_RADIOBOX(radioSort, MainFrame::OnSortChange)
147 EVT_BUTTON(buttonAdd, MainFrame::OnAdd)
148 EVT_BUTTON(buttonEnvelopes, MainFrame::OnPrint)
149 EVT_TEXT_ENTER(-1, MainFrame::OnAdd)
150 EVT_TEXT(idName, MainFrame::OnNameUpdate)
151 EVT_GRID_CELL_LEFT_CLICK(MainFrame::OnGridClicked)
152 EVT_LISTBOX(-1, MainFrame::OnNameSelect)
153 END_EVENT_TABLE()
154
155 class EnvelopesPrintout: public wxPrintout {
156 public:
157 EnvelopesPrintout(wxGrid *data, int mode);
158 ~EnvelopesPrintout();
159 virtual bool OnPrintPage(int pg);
160 virtual void OnPreparePrinting();
161 virtual bool HasPage(int pg);
162 virtual void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo);
163 private:
164 wxGrid *data;
165 int n, mode, rows, cols;
166 tPersonId *a;
167 double lineskip; //inches
168 wxCoord width, height, xoff, yoff, fontsize;
169
170 void StringSize(char *s, wxCoord *w, wxCoord *h);
171 void Write(char *s, wxCoord x, wxCoord y, double angle);
172 void PrintOne(tPersonId p, wxCoord x, wxCoord y);
173 };
174
175 void EnvelopesPrintout::StringSize(char *s2, wxCoord *w, wxCoord *h) {
176 wxCoord w2, h2, desc, lead;
177 int ppix, ppi;
178 char *q, *s;
179
180 lineskip=0.1;
181 s= ALLOC(char, strlen(s2)+1);
182 strcpy(s,s2);
183 s2=s;
184
185 *w = *h = 0;
186
187 GetPPIPrinter(&ppix, &ppi);
188
189 do {
190 q = strchr(s, '\n');
191 if (q!=NULL) q[0]=0;
192
193 GetDC()->GetTextExtent(s, &w2, &h2, &desc, &lead);
194 if (w2>*w) *w=w2;
195 *h += (int)(h2-desc+lead + lineskip*ppi);
196
197 if (q!=NULL) {
198 q[0]='\n';
199 s=q+1;
200 }
201 } while (q!=NULL);
202
203 free(s2);
204 }
205
206 void EnvelopesPrintout::Write(char *s2, wxCoord x, wxCoord y, double angle) {
207 wxCoord w2, h2, desc, lead;
208 int ppix, ppi;
209 char *q,*s;
210
211
212
213 s = ALLOC(char, strlen(s2)+1);
214 strcpy(s,s2);
215 s2=s;
216
217 GetPPIPrinter(&ppix, &ppi);
218
219 do {
220 q = strchr(s, '\n');
221 if (q!=NULL) q[0]=0;
222
223 GetDC()->GetTextExtent(s, &w2, &h2, &desc, &lead);
224
225 GetDC()->DrawRotatedText(s, x, y, angle);
226
227 h2 = (int)(h2-desc+lead + lineskip*ppi);
228
229 x += (int)(h2*sin(angle/180*M_PI));
230 y += (int)(h2*cos(angle/180*M_PI));
231
232 if (q!=NULL) {
233 q[0]='\n';
234 s=q+1;
235 }
236 } while (q!=NULL);
237
238 free(s2);
239 }
240
241 void EnvelopesPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) {
242 *pageFrom = * minPage = 1;
243 *pageTo = *maxPage = (n-1)/(rows*cols) +1;
244 }
245
246 static int ptrcmp(const void *a, const void *b) {
247 int A = *((int *)a);
248 int B = *((int *)b);
249 if (A<B) return -1;
250 if (A>B) return 1;
251 return 0;
252 }
253
254 EnvelopesPrintout::EnvelopesPrintout(wxGrid *data, int mode) : wxPrintout("Adresy") {
255 this->data = data;
256 this->mode = mode;
257
258 int i,j,k;
259
260 n = nRows();
261 if (data->GetRows()<n) n = data->GetRows();
262 if (n==0) return;
263
264 a = ALLOC(tPersonId, n);
265
266 for (j=i=0; j<n; j++) {
267 if (mode==MODE_PERSONS) {
268 for (k=0; k<4; k++)
269 if (data->IsInSelection(j,k)) {
270 a[i] = (tPersonId)(getRow(j));
271 i++;
272 break;
273 }
274 } else {
275 for (k=0; k<5; k++)
276 if (data->IsInSelection(j,k)) {
277 a[i] = ((tEntryId)(getRow(j)))->person;
278 i++;
279 break;
280 }
281 }
282 }
283
284 if ( (data->GetCursorRow() >=0) && (data->GetCursorRow() <n) ) {
285 if (i==0) {
286 if (mode==MODE_PERSONS) {
287 a[i] = (tPersonId)(getRow(data->GetCursorRow()));
288 i++;
289 } else {
290 a[i] = ((tEntryId)(getRow(data->GetCursorRow())))->person;
291 i++;
292 }
293 }
294 }
295
296 n=i;
297 if (n==0) return;
298 qsort(a,n,sizeof(tPersonId),ptrcmp);
299 for (i=0, j=1; j<n; j++) {
300 if (a[j-1]!=a[j]) {
301 a[++i]=a[j];
302 }
303 }
304 n = i+1;
305
306 a = (tPersonId *)realloc(a, sizeof(tPersonId) * n);
307
308 cols = rows = 1; // Eeek!
309 rows = 8;
310 cols = 3;
311
312
313 }
314
315 void EnvelopesPrintout::PrintOne(tPersonId p, wxCoord x, wxCoord y) {
316 int w, h;
317 wxCoord wt, ht;
318
319 GetDC()->SetMapMode(wxMM_TEXT);
320 GetDC()->SetFont(wxFont(fontsize, wxROMAN, wxNORMAL, wxNORMAL, FALSE, "", ENCODING));
321
322 StringSize(p->address.title, &wt, &ht);
323 Write(p->address.title, x, y, 0);
324 y += ht;
325
326 StringSize(p->address.name, &wt, &ht);
327 Write(p->address.name, x, y, 0);
328 y += ht;
329
330 StringSize(p->address.street, &wt, &ht);
331 Write(p->address.street, x, y, 0);
332 y += ht;
333
334 StringSize(p->address.zip, &wt, &ht);
335 Write(p->address.zip, x, y, 0);
336 x += wt;
337 StringSize(" ", &wt, &ht);
338 x += wt;
339
340 Write(p->address.city, x, y, 0);
341 }
342
343 bool EnvelopesPrintout::OnPrintPage(int pg) {
344 int i, j, q;
345
346 q = (pg-1)*(rows*cols);
347 if (q>=n) return FALSE;
348
349 for (i=0; i<rows; i++)
350 for (j=0; j<cols; j++) {
351 q = (pg-1)*(rows*cols) + i*cols + j;
352 if (q>=n) return TRUE;
353
354 PrintOne(a[q], xoff + j*width, yoff+i*height);
355 }
356
357 return TRUE;
358 }
359
360 void EnvelopesPrintout::OnPreparePrinting() {
361 {
362 double ffs, fw, fh, fxoff, fyoff;
363 int w, h;
364 int ppi, ppix;
365 // wxMessageBox("OnPreparePrinting0", "XXX", wxOK | wxCENTRE | wxICON_ERROR);
366
367 wxConfig *config = new wxConfig(wxGetApp().GetAppName());
368 sscanf(config->Read("fontsize",DEFAULT_FONTSIZE).c_str(),"%f",&ffs);
369 sscanf(config->Read("width",DEFAULT_WIDTH).c_str(),"%f",&fw);
370 sscanf(config->Read("height",DEFAULT_HEIGHT).c_str(),"%f",&fh);
371 sscanf(config->Read("xoffset",DEFAULT_XOFFSET).c_str(),"%f",&fxoff);
372 sscanf(config->Read("yoffset",DEFAULT_YOFFSET).c_str(),"%f",&fyoff);
373 // wxMessageBox(config->Read("width",DEFAULT_WIDTH).c_str(), "XXX", wxOK | wxCENTRE | wxICON_ERROR);
374 // wxMessageBox(wxString::Format("2 '%s'",config->Read("width",DEFAULT_WIDTH).c_str()), "XXX", wxOK | wxCENTRE | wxICON_ERROR);
375 delete config;
376
377 // dirt
378 ffs = 9;
379 fw = 70;
380 fh = 37;
381 fxoff = 1;
382 fyoff = 1;
383
384 GetPPIPrinter(&ppix, &ppi);
385 width = (wxCoord)(fw*ppi*0.0393701+0.5);
386 height = (wxCoord)(fh*ppi*0.0393701+0.5);
387 xoff = (wxCoord)(fxoff*ppi*0.0393701+0.5);
388 yoff = (wxCoord)(fyoff*ppi*0.0393701+0.5);
389 fontsize = (int)(ffs*ppi/72+0.5);
390
391
392 GetPageSizePixels(&w, &h);
393 // cols = (wxCoord)w/width;
394 // rows = (wxCoord)h/height;
395 rows = 8;
396 cols = 3;
397 // wxMessageBox("OnPreparePrinting2", "XXX", wxOK | wxCENTRE | wxICON_ERROR);
398 }
399 }
400
401 bool EnvelopesPrintout::HasPage(int pg) {
402 if (pg<=(n-1)/(rows*cols) +1) return TRUE;
403 return FALSE;
404 }
405
406 EnvelopesPrintout::~EnvelopesPrintout() {
407 free(a);
408 }
409
410 void MainGrid::ResetWidth() {
411 int i;
412 AutoSizeColumn(0);
413 for (i=1; i<GetCols(); i++)
414 SetColumnWidth(i, (GetClientSize().GetWidth()-GetColSize(0)-1)/ (GetCols()-1));
415 }
416
417 void MainGrid::OnSize2(wxSizeEvent &event) {
418 OnSize(event);
419 ResetWidth();
420 }
421
422 /*
423 void MainGrid::OnKeyDown2(wxKeyEvent& event) {
424 if (event.KeyCode()==WXK_TAB) GetParent()->ProcessEvent(event);
425 else event.Skip();
426 }
427 */
428
429 bool MyApp::OnInit()
430 {
431 wxFont::SetDefaultEncoding(ENCODING);
432 MainFrame *frame = new MainFrame(NULL, "Dary", wxPoint(-1, -1), wxSize(640, 480));
433 frame->Show(TRUE);
434
435 wxConfig *config = new wxConfig(GetAppName());
436
437 if (!config->HasEntry("dbdir")) {
438 wxDirDialog *dlg = new wxDirDialog(frame, "Zvo¾te adresár s databázou");
439 if (dlg->ShowModal()!=wxID_OK) {
440 delete dlg;
441 delete config;
442 frame->Destroy();
443 return FALSE;
444 }
445 db.Lock();
446 if (!OpenDb(dlg->GetPath().c_str())) {
447 // user zadal zly adresar
448 db.Unlock();
449 delete dlg;
450 delete config;
451 frame->Destroy();
452 return FALSE;
453 }
454 db.Unlock();
455 config->Write("dbdir",dlg->GetPath());
456
457 delete dlg;
458
459 } else {
460 // wxMessageBox(config->Read("dbdir","").c_str(),"XXX", wxOK | wxCENTRE | wxICON_ERROR);
461
462 if (!OpenDb(config->Read("dbdir","").c_str())) {
463 wxDirDialog *dlg = new wxDirDialog(frame, "Zvo¾te adresár s databázou");
464 if (dlg->ShowModal()!=wxID_OK) {
465 delete dlg;
466 delete config;
467 frame->Destroy();
468 return FALSE;
469 }
470 db.Lock();
471 if (!OpenDb(dlg->GetPath().c_str())) {
472 // user zadal zly adresar
473 db.Unlock();
474 delete dlg;
475 delete config;
476 frame->Destroy();
477 return FALSE;
478 }
479 db.Unlock();
480 config->Write("dbdir",dlg->GetPath());
481
482 delete dlg;
483 }
484 //wxMessageBox("DB_read OK","DB_read OK", wxOK | wxCENTRE | wxICON_ERROR);
485 }
486
487 delete config;
488
489 frame->UpdateView();
490
491 return TRUE;
492 }
493
494 MainFrame::MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size):
495 wxFrame(frame, -1, title, pos, size)
496 {
497 compa = NULL;
498 disable_listbox_update = 0;
499
500 wxMenu *file_menu = new wxMenu;
501 file_menu->Append(menuConfig, "&Nastavenia");
502 file_menu->Append(menuDb, "&Zmeò databázu");
503 file_menu->Append(menuAbout, "&Info");
504 file_menu->Append(menuExit, "&Koniec");
505
506 wxMenuBar *menuBar = new wxMenuBar;
507 menuBar->Append(file_menu, "&Súbor");
508 SetMenuBar(menuBar);
509
510 wxPanel *panel = new wxPanel(this, -1);
511
512 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
513
514 view = new MainGrid(panel);
515 view->CreateGrid(1,1);
516 view->SetLabelSize(wxHORIZONTAL,0);
517 view->SetLabelSize(wxVERTICAL,0);
518 view->SetEditable(FALSE);
519 topsizer->Add( view, 3, wxALL | wxGROW, 10 );
520
521 wxString LudiaDary[2]={"¼udia", "Dary"};
522 listmode = new wxRadioBox(panel, radioMode, "Zobrazi:", wxDefaultPosition,
523 wxDefaultSize, 2, LudiaDary);
524
525 wxString MenoSumaDatum[3]={"Meno", "Suma", "Dátum"} ;
526 sortorder = new wxRadioBox(panel, radioSort, "Triedi pod¾a:", wxDefaultPosition, wxDefaultSize,
527 3, MenoSumaDatum );
528
529 envelopes = new wxButton(panel, buttonEnvelopes, "Tlaèi obálky");
530
531 listmode->SetSelection(1);
532 sortorder->SetSelection(2);
533 db.Lock();
534 SetMode(MODE_ENTRIES);
535 SetSort(SORT_DATE);
536 db.Unlock();
537
538 pocetludi = new wxTextCtrl(panel, -1, "Poèet ¾udí: ");
539 pocetludi->SetEditable(false);
540 pocetdarov = new wxTextCtrl(panel, -1, "Poèet darov: ");
541 pocetdarov->SetEditable(false);
542 sumadarov = new wxTextCtrl(panel, -1, "Celková suma: ");
543 sumadarov->SetEditable(false);
544
545 // wxStaticBox; wxStaticBoxSizer
546 statbox = new wxStaticBox(panel, -1, "");
547 statistics = new wxStaticBoxSizer(statbox, wxVERTICAL);
548 statistics->Add(pocetludi, 0, wxALL | wxEXPAND, 3);
549 statistics->Add(10,0, 0, 0, 0 );
550 statistics->Add(pocetdarov, 0, wxALL | wxEXPAND, 3);
551 statistics->Add(10,0, 0, 0, 0 );
552 statistics->Add(sumadarov, 0, wxALL | wxEXPAND, 3);
553
554 {
555 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
556
557 line->Add( 10,0, 0, 0, 0 );
558 line->Add( listmode, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 10 );
559 line->Add( 10,0, 0, 0, 0 );
560 line->Add( sortorder, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 10 );
561 line->Add( 10,0, 0, 0, 0 );
562 line->Add( statistics, 2, wxALL | wxALIGN_CENTER_HORIZONTAL | wxGROW, 10 );
563 line->Add( 0,0, 2, 0, 0 );
564 line->Add( envelopes, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 10 );
565 line->Add( 10,0, 0, 0, 0 );
566
567 topsizer->Add( line, 0, wxALL | wxGROW, 0 );
568 }
569
570 comp = new wxListBox(panel, -1);
571 name = new wxTextCtrl(panel, idName, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
572 surname = new wxTextCtrl(panel, idName, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
573 date = new wxTextCtrl(panel, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
574 sum = new wxTextCtrl(panel, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
575 add = new wxButton(panel, buttonAdd, "Prida");
576
577 {
578 wxGridSizer *line = new wxGridSizer(5, 2, 10);
579 line->Add( new wxStaticText(panel, -1, "Meno"), 0, wxALIGN_CENTER_HORIZONTAL, 0 );
580 line->Add( new wxStaticText(panel, -1, "Priezvisko"), 0, wxALIGN_CENTER_HORIZONTAL, 0 );
581 line->Add( new wxStaticText(panel, -1, "Dátum"), 0, wxALIGN_CENTER_HORIZONTAL, 0 );
582 line->Add( new wxStaticText(panel, -1, "Suma"), 0, wxALIGN_CENTER_HORIZONTAL, 0 );
583 line->Add( 0,0, 0, wxALIGN_CENTER_HORIZONTAL, 0 );
584
585 line->Add( name, 1, wxGROW, 0 );
586 line->Add( surname, 1, wxGROW, 0 );
587 line->Add( date, 1, wxGROW, 0 );
588 line->Add( sum, 1, wxGROW, 0 );
589 line->Add( add, 1, wxGROW, 0 );
590
591 topsizer->Add( line, 0, wxALL | wxGROW, 10 );
592 }
593
594 {
595 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
596 line->Add( comp, 1, wxALIGN_CENTER | wxGROW, 0 );
597 topsizer->Add( line, 1, wxALL | wxGROW, 10 );
598 }
599
600 panel->SetAutoLayout( TRUE );
601 panel->SetSizer(topsizer);
602 panel->SetDefaultItem(add);
603 topsizer->SetSizeHints( this );
604 name->SetFocus();
605
606 }
607
608 void MainFrame::OnAbout(wxCommandEvent& event)
609 {
610 wxString msg;
611 msg.Printf( "Databáza darcov\n");
612
613 wxMessageBox(msg, "Databáza darcov", wxOK | wxICON_INFORMATION, this);
614 }
615
616 void MainFrame::OnExit(wxCloseEvent& event)
617 {
618 db.Lock();
619 CloseDb();
620 db.Unlock();
621 this->Destroy();
622 }
623
624 void MainFrame::OnExit2(wxCommandEvent& event)
625 {
626 db.Lock();
627 CloseDb();
628 db.Unlock();
629 this->Destroy();
630 }
631
632 void MainFrame::OnSortChange(wxCommandEvent& event)
633 {
634 db.Lock();
635 switch (sortorder->GetSelection()) {
636 case 0:
637 SetSort(SORT_NAME);
638 break;
639 case 1:
640 SetSort(SORT_SUM);
641 break;
642 case 2:
643 SetSort(SORT_DATE);
644 break;
645 }
646 db.Unlock();
647 UpdateView();
648 }
649
650 void MainFrame::OnModeChange(wxCommandEvent& event)
651 {
652 db.Lock();
653 switch (listmode->GetSelection()) {
654 case 0:
655 if (sortorder->GetSelection()==2) {
656 sortorder->SetSelection(0);
657 SetSort(SORT_NAME);
658 }
659 sortorder->Enable(2, FALSE);
660 SetMode(MODE_PERSONS);
661 break;
662 case 1:
663 sortorder->Enable(2, TRUE);
664 SetMode(MODE_ENTRIES);
665 break;
666 }
667 db.Unlock();
668 UpdateView();
669 }
670
671 void MainFrame::OnDbChange(wxCommandEvent &event) {
672 wxConfig *config = new wxConfig(wxGetApp().GetAppName());
673 wxDirDialog *dlg = new wxDirDialog(this, "Zvo¾te adresár s databázou",config->Read("dbdir",""));
674
675 if (dlg->ShowModal()!=wxID_OK) {
676 delete config;
677 delete dlg;
678 return;
679 }
680
681 CloseDb();
682 db.Lock();
683 if (!OpenDb(dlg->GetPath().c_str())) {
684 // mame problem - user zadal zly adresar
685 db.Unlock();
686 UpdateView();
687 delete config;
688 delete dlg;
689 this->Destroy();
690 return;
691 }
692 db.Unlock();
693 config->Write("dbdir",dlg->GetPath());
694 delete config;
695 delete dlg;
696 UpdateView();
697 }
698
699 void MainFrame::OnConfig(wxCommandEvent &event) {
700 ConfigDialog *dlg = new ConfigDialog(this);
701
702 dlg->ShowModal();
703 delete dlg;
704 }
705
706 void MyStrip(wxString &s) {
707 int i;
708 for (i=0; i<s.Len() && s.GetChar(i)==' '; i++);
709 s.Remove(0,i);
710 while (s.Len()>0 && s[s.Len()-1]==' ') s.RemoveLast();
711 }
712
713 void MainFrame::OnAdd(wxCommandEvent &event) {
714 double sum;
715 int date;
716
717 date = str2cal(this->date->GetValue().c_str());
718 if (date == DATE_ERR) {
719 wxMessageBox("Zadajte správny dátum.", "Zle zadaný dátum!", wxOK | wxCENTRE | wxICON_ERROR);
720 return;
721 }
722 if (!this->sum->GetValue().ToDouble(&sum)) {
723 wxMessageBox("Suma musí by èíslo.", "Zle zadaná suma!", wxOK | wxCENTRE | wxICON_ERROR);
724 return;
725 }
726 db.Lock();
727 // workaround for strip (that removes accented characters, too)
728 wxString sname = name->GetValue();
729 wxString ssurname = surname->GetValue();
730 MyStrip(sname); MyStrip(ssurname);
731 tPersonId p = GetPerson(sname.c_str(), ssurname.c_str());
732 if (p==NULL) p = NewPerson(sname.c_str(), ssurname.c_str());
733 tEntryId e = NewEntry(p, date, (long)(sum*100+0.5));
734 db.Unlock();
735
736 UpdateView();
737 this->date->SetValue("");
738 this->sum->SetValue("");
739 name->SetValue("");
740 surname->SetValue("");
741 name->SetFocus();
742 }
743
744 void MainFrame::UpdateView() {
745 int i;
746 wxString S;
747 wxCommandEvent unused;
748
749 db.Lock();
750 view->BeginBatch();
751
752 view->DeleteRows(0,view->GetRows());
753 view->DeleteCols(0,view->GetCols());
754 view->AppendRows(nRows());
755 view->AppendCols(1);
756 for (i=0; i<nRows(); i++) {
757 view->SetCellValue("...",i,0);
758 }
759
760 if (listmode->GetSelection()==1) {
761 // dary
762 view->AppendCols(4);
763 for (i=0; i<nRows(); i++) {
764 tEntryId e = (tEntryId)getRow(i);
765 view->SetCellValue(e->person->name, i,1);
766 view->SetCellValue(e->person->surname, i,2);
767 view->SetCellValue(cal2str(e->date), i,3);
768 S.Printf("%.2f", (double)(e->sum)/100);
769 view->SetCellValue(S,i,4);
770 }
771 } else {
772 // ludia
773 view->AppendCols(3);
774 for (i=0; i<nRows(); i++) {
775 tPersonId e = (tPersonId)getRow(i);
776 view->SetCellValue(e->name, i,1);
777 view->SetCellValue(e->surname, i,2);
778 S.Printf("%.2f", (double)(e->sum)/100);
779 view->SetCellValue(S,i,3);
780 }
781 }
782
783 view->UpdateDimensions();
784 view->AdjustScrollbars();
785 view->ResetWidth();
786 view->Refresh();
787 view->EndBatch();
788
789 pocetludi->SetValue( wxString::Format("Poèet ¾udí: %d", nPersons() ) );
790 pocetdarov->SetValue( wxString::Format("Poèet darov: %d", nEntries() ) );
791 sumadarov->SetValue( wxString::Format("Celková suma: %.2f", ((double)GlobalSum())/100.0 ) );
792
793 OnNameUpdate(unused);
794
795 db.Unlock();
796 }
797
798 void MainFrame::OnGridClicked(wxGridEvent &event) {
799 if (event.GetCol() == 0) { //edit
800 if ( listmode->GetSelection() == 0 ) {
801 db.Lock();
802 PersonEditDialog *e = new PersonEditDialog(this, (tPersonId)getRow(event.GetRow()));
803 if (e->ShowModal()==wxID_OK) {
804 db.Unlock();
805 UpdateView();
806 } else db.Unlock();
807 delete e;
808 } else {
809 db.Lock();
810 EntryEditDialog *e = new EntryEditDialog(this, (tEntryId)getRow(event.GetRow()));
811 if (e->ShowModal()==wxID_OK) {
812 db.Unlock();
813 UpdateView();
814 } else db.Unlock();
815 delete e;
816 }
817 } else {
818 event.Skip();
819 }
820 }
821
822 void MainFrame::OnNameUpdate(wxCommandEvent &event) {
823 char **p;
824 char *ns, *sns;
825
826 if (disable_listbox_update) return;
827 if (compa!=NULL) {
828 for (p=compa; *p!=NULL; p++) free(*p);
829 free(compa);
830 }
831
832 ns = ALLOC(char, strlen(name->GetValue().c_str())+1);
833 strcpy(ns, name->GetValue().c_str());
834 sns = ALLOC(char, strlen(surname->GetValue().c_str())+1);
835 strcpy(sns, surname->GetValue().c_str());
836
837 compa = Completion(ns, sns);
838 free(ns); free(sns);
839
840 comp->Clear();
841 if (compa==NULL) return;
842
843 for (p=compa; *p!=NULL; p+=2) {
844 comp->Append(wxString::Format("%s %s", p[0], p[1]));
845 }
846 }
847
848 void MainFrame::OnNameSelect(wxCommandEvent &event) {
849 disable_listbox_update=1;
850 name->SetValue( compa[comp->GetSelection()*2] );
851 disable_listbox_update=0;
852 surname->SetValue( compa[comp->GetSelection()*2+1] );
853 date->SetFocus();
854 }
855
856 void MainFrame::OnPrint(wxCommandEvent &event) {
857 wxPrinter printer;
858 int mode;
859 if (listmode->GetSelection()==0) mode = MODE_PERSONS;
860 else mode = MODE_ENTRIES;
861
862 EnvelopesPrintout p(view, mode);
863
864 printer.Print(this, &p, TRUE);
865 }
866
867 PersonEditDialog::PersonEditDialog(wxWindow *parent, tPersonId id) :
868 wxDialog(parent, -1, "Úprava", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
869 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
870
871 this->id = id;
872 wxStaticText *max = new wxStaticText(this, -1, "Priezvisko: ");
873
874 name = new wxTextCtrl(this, -1, id->name, wxDefaultPosition, wxDefaultSize, 0);
875 surname = new wxTextCtrl(this, -1, id->surname, wxDefaultPosition, wxDefaultSize, 0);
876 title = new wxTextCtrl(this, -1, id->address.title, wxDefaultPosition, wxDefaultSize, 0);
877 addrname = new wxTextCtrl(this, -1, id->address.name, wxDefaultPosition, wxDefaultSize, 0);
878 street = new wxTextCtrl(this, -1, id->address.street, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
879 city = new wxTextCtrl(this, -1, id->address.city, wxDefaultPosition, wxDefaultSize, 0);
880 zip = new wxTextCtrl(this, -1, id->address.zip, wxDefaultPosition, wxDefaultSize, 0);
881
882 street->SetSize(street->GetSize().GetWidth(), 50);
883 {
884 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
885 line->Add( new wxStaticText(this, -1, "Meno: ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
886 line->Add( name, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
887 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
888 }
889
890 {
891 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
892 line->Add( max, 0, wxALIGN_CENTER_VERTICAL, 10 );
893 line->Add( surname, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
894 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
895 }
896
897 {
898 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
899 line->Add( new wxStaticText(this, -1, "Adresa: ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
900 line->Add( title, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
901 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
902 }
903
904 {
905 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
906 line->Add( new wxStaticText(this, -1, "", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
907 line->Add( addrname, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
908 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
909 }
910
911 {
912 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
913 line->Add( new wxStaticText(this, -1, "", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
914 line->Add( street, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
915 topsizer->Add( line, 1, wxALL | wxGROW, 5 );
916 }
917
918 {
919 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
920 line->Add( new wxStaticText(this, -1, "Mesto: ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
921 line->Add( city, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
922 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
923 }
924
925 {
926 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
927 line->Add( new wxStaticText(this, -1, "PSÈ: ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
928 line->Add( zip, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
929 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
930 }
931 {
932 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
933 line->Add( 10,0, 1, 0, 0 );
934 line->Add( new wxButton(this, wxID_OK, "OK"), 0, wxALIGN_CENTER_VERTICAL, 10 );
935 line->Add( 10,0, 1, 0, 0 );
936 line->Add( new wxButton(this, wxID_CANCEL, "Zruši"), 0, wxALIGN_CENTER_VERTICAL, 10 );
937 line->Add( 10,0, 1, 0, 0 );
938 line->Add( new wxButton(this, buttonDelete, "Zmaza!"), 0, wxALIGN_CENTER_VERTICAL, 10 );
939 line->Add( 10,0, 1, 0, 0 );
940 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
941 }
942
943 SetAutoLayout( TRUE );
944 SetSizer(topsizer);
945 // SetDefaultItem(add);
946 topsizer->Fit(this);
947 topsizer->SetSizeHints( this );
948
949 }
950
951 void PersonEditDialog::OnOK(wxCommandEvent &event) {
952 tAddress addr;
953 addr.title = ALLOC(char, strlen(title->GetValue().c_str())+1); strcpy(addr.title, title->GetValue().c_str());
954 addr.name = ALLOC(char, strlen(addrname->GetValue().c_str())+1); strcpy(addr.name, addrname->GetValue().c_str());
955 addr.street = ALLOC(char, strlen(street->GetValue().c_str())+1); strcpy(addr.street, street->GetValue().c_str());
956 addr.city = ALLOC(char, strlen(city->GetValue().c_str())+1); strcpy(addr.city, city->GetValue().c_str());
957 addr.zip = ALLOC(char, strlen(zip->GetValue().c_str())+1); strcpy(addr.zip, zip->GetValue().c_str());
958 UpdatePerson(id, name->GetValue().c_str(), surname->GetValue().c_str(), &addr);
959 FreeAddress(&addr);
960 EndModal(wxID_OK);
961 }
962
963 void PersonEditDialog::OnDelete(wxCommandEvent &event) {
964 DelPerson(id);
965 EndModal(wxID_OK);
966 }
967
968 EntryEditDialog::EntryEditDialog(wxWindow *parent, tEntryId id) :
969 wxDialog(parent, -1, "Úprava", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
970 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
971
972 this->id = id;
973 wxStaticText *max = new wxStaticText(this, -1, "Priezvisko: ");
974
975 name = new wxTextCtrl(this, -1, id->person->name, wxDefaultPosition, wxDefaultSize, 0);
976 surname = new wxTextCtrl(this, -1, id->person->surname, wxDefaultPosition, wxDefaultSize, 0);
977 title = new wxTextCtrl(this, -1, id->person->address.title, wxDefaultPosition, wxDefaultSize, 0);
978 addrname = new wxTextCtrl(this, -1, id->person->address.name, wxDefaultPosition, wxDefaultSize, 0);
979 street = new wxTextCtrl(this, -1, id->person->address.street, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
980 city = new wxTextCtrl(this, -1, id->person->address.city, wxDefaultPosition, wxDefaultSize, 0);
981 zip = new wxTextCtrl(this, -1, id->person->address.zip, wxDefaultPosition, wxDefaultSize, 0);
982
983 date = new wxTextCtrl(this, -1, cal2str(id->date), wxDefaultPosition, wxDefaultSize, 0);
984 sum = new wxTextCtrl(this, -1, wxString::Format("%.2f",(double)(id->sum)/100), wxDefaultPosition, wxDefaultSize, 0);
985
986 street->SetSize(street->GetSize().GetWidth(), 50);
987
988 {
989 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
990 line->Add( new wxStaticText(this, -1, "Meno: ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
991 line->Add( name, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
992 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
993 }
994
995 {
996 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
997 line->Add( max, 0, wxALIGN_CENTER_VERTICAL, 10 );
998 line->Add( surname, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
999 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1000 }
1001
1002 {
1003 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1004 line->Add( new wxStaticText(this, -1, "Adresa: ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1005 line->Add( title, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1006 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1007 }
1008
1009 {
1010 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1011 line->Add( new wxStaticText(this, -1, "", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1012 line->Add( addrname, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1013 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1014 }
1015
1016 {
1017 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1018 line->Add( new wxStaticText(this, -1, "", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1019 line->Add( street, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1020 topsizer->Add( line, 1, wxALL | wxGROW, 5 );
1021 }
1022
1023 {
1024 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1025 line->Add( new wxStaticText(this, -1, "Mesto: ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1026 line->Add( city, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1027 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1028 }
1029
1030 {
1031 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1032 line->Add( new wxStaticText(this, -1, "PSÈ: ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1033 line->Add( zip, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1034 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1035 }
1036
1037 {
1038 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1039 line->Add( new wxStaticText(this, -1, "Dátum: ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1040 line->Add( date, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1041 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1042 }
1043
1044 {
1045 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1046 line->Add( new wxStaticText(this, -1, "Suma: ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1047 line->Add( sum, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1048 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1049 }
1050
1051 {
1052 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1053 line->Add( 10,0, 1, 0, 0 );
1054 line->Add( new wxButton(this, wxID_OK, "OK"), 0, wxALIGN_CENTER_VERTICAL, 10 );
1055 line->Add( 10,0, 1, 0, 0 );
1056 line->Add( new wxButton(this, wxID_CANCEL, "Zruši"), 0, wxALIGN_CENTER_VERTICAL, 10 );
1057 line->Add( 10,0, 1, 0, 0 );
1058 line->Add( new wxButton(this, buttonDelete, "Zmaza!"), 0, wxALIGN_CENTER_VERTICAL, 10 );
1059 line->Add( 10,0, 1, 0, 0 );
1060 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1061 }
1062
1063 SetAutoLayout( TRUE );
1064 SetSizer(topsizer);
1065 // SetDefaultItem(add);
1066 topsizer->Fit(this);
1067 topsizer->SetSizeHints( this );
1068
1069 }
1070
1071 void EntryEditDialog::OnOK(wxCommandEvent &event) {
1072 tAddress addr;
1073 int date;
1074 double sum;
1075
1076 date = str2cal(this->date->GetValue().c_str());
1077 if (date == DATE_ERR) {
1078 wxMessageBox("Zadajte správny dátum.", "Zle zadaný dátum!", wxOK | wxCENTRE | wxICON_ERROR);
1079 return;
1080 }
1081 if (!this->sum->GetValue().ToDouble(&sum)) {
1082 wxMessageBox("Suma musí by èíslo.", "Zle zadaná suma!", wxOK | wxCENTRE | wxICON_ERROR);
1083 return;
1084 }
1085
1086 addr.title = ALLOC(char, strlen(title->GetValue().c_str())+1); strcpy(addr.title, title->GetValue().c_str());
1087 addr.name = ALLOC(char, strlen(addrname->GetValue().c_str())+1); strcpy(addr.name, addrname->GetValue().c_str());
1088 addr.street = ALLOC(char, strlen(street->GetValue().c_str())+1); strcpy(addr.street, street->GetValue().c_str());
1089 addr.city = ALLOC(char, strlen(city->GetValue().c_str())+1); strcpy(addr.city, city->GetValue().c_str());
1090 addr.zip = ALLOC(char, strlen(zip->GetValue().c_str())+1); strcpy(addr.zip, zip->GetValue().c_str());
1091 UpdatePerson(id->person, name->GetValue().c_str(), surname->GetValue().c_str(), &addr);
1092
1093 UpdateEntry(id, id->person, date, (long)(sum*100+0.5));
1094
1095 FreeAddress(&addr);
1096 EndModal(wxID_OK);
1097 }
1098
1099 void EntryEditDialog::OnDelete(wxCommandEvent &event) {
1100 DelEntry(id);
1101 EndModal(wxID_OK);
1102 }
1103
1104
1105 /*
1106 void MainFrame::OnDump(wxCommandEvent &event) {
1107 int i;
1108 wxDate D;
1109
1110 db.Lock();
1111 D.SetFormat(wxEUROPEAN);
1112 printf("\n\nDump:\n");
1113 for (i=0; i<nRows(); i++) {
1114 if (listmode->GetSelection()==0) {
1115 tPersonId p = (tPersonId)getRow(i);
1116 printf("%s %s\nAdresa:\n%s\nSuma:%d\n\n--------\n\n",p->name, p->surname, p->address, p->sum);
1117 } else {
1118 tEntryId e = (tEntryId)getRow(i);
1119 D.Set(e->date);
1120 printf("%s %s\nAdresa:\n%s\nSuma:%d\nDátum:%s\nÈiastka:%d\n\n--------\n\n",e->person->name, e->person->surname,
1121 e->person->address, e->person->sum, D.FormatDate().c_str(), e->sum);
1122 }
1123 }
1124 db.Unlock();
1125 }
1126 */
1127
1128 ConfigDialog::ConfigDialog(wxWindow *parent) :
1129 wxDialog(parent, -1, "Nastavenia", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
1130 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
1131
1132 wxStaticText *max = new wxStaticText(this, -1, "Ve¾kos písma (pt): ");
1133
1134 wxConfig *config = new wxConfig(wxGetApp().GetAppName());
1135 width = new wxTextCtrl(this, -1, config->Read("width",DEFAULT_WIDTH), wxDefaultPosition, wxDefaultSize, 0);
1136 height = new wxTextCtrl(this, -1, config->Read("height",DEFAULT_HEIGHT), wxDefaultPosition, wxDefaultSize, 0);
1137 size = new wxTextCtrl(this, -1, config->Read("fontsize",DEFAULT_FONTSIZE), wxDefaultPosition, wxDefaultSize, 0);
1138 xoffset = new wxTextCtrl(this, -1, config->Read("xoffset",DEFAULT_XOFFSET), wxDefaultPosition, wxDefaultSize, 0);
1139 yoffset = new wxTextCtrl(this, -1, config->Read("yoffset",DEFAULT_YOFFSET), wxDefaultPosition, wxDefaultSize, 0);
1140 delete config;
1141
1142 {
1143 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1144 line->Add( max, 0, wxALIGN_CENTER_VERTICAL, 10 );
1145 line->Add( size, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1146 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1147 }
1148
1149 {
1150 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1151 line->Add( new wxStaticText(this, -1, "Šírka štítku (mm): ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1152 line->Add( width, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1153 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1154 }
1155
1156 {
1157 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1158 line->Add( new wxStaticText(this, -1, "Výška štítku (mm): ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1159 line->Add( height, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1160 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1161 }
1162
1163 {
1164 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1165 line->Add( new wxStaticText(this, -1, "¼avý okraj (mm): ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1166 line->Add( xoffset, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1167 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1168 }
1169
1170 {
1171 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1172 line->Add( new wxStaticText(this, -1, "Horný okraj (mm): ", wxDefaultPosition, max->GetSize()), 0, wxALIGN_CENTER_VERTICAL, 10 );
1173 line->Add( yoffset, 1, wxALIGN_CENTER_VERTICAL | wxGROW, 10 );
1174 topsizer->Add( line, 1, wxALL | wxGROW, 5 );
1175 }
1176
1177 {
1178 wxBoxSizer *line = new wxBoxSizer(wxHORIZONTAL);
1179 line->Add( 10,0, 1, 0, 0 );
1180 line->Add( new wxButton(this, wxID_OK, "OK"), 0, wxALIGN_CENTER_VERTICAL, 10 );
1181 line->Add( 10,0, 1, 0, 0 );
1182 line->Add( new wxButton(this, wxID_CANCEL, "Zruši"), 0, wxALIGN_CENTER_VERTICAL, 10 );
1183 line->Add( 10,0, 1, 0, 0 );
1184 topsizer->Add( line, 0, wxALL | wxGROW, 5 );
1185 }
1186
1187 SetAutoLayout( TRUE );
1188 SetSizer(topsizer);
1189 topsizer->Fit(this);
1190 topsizer->SetSizeHints( this );
1191
1192 }
1193
1194 void ConfigDialog::OnOK(wxCommandEvent &event) {
1195 float a;
1196
1197 if (sscanf(width->GetValue().c_str(),"%f",&a)!=1) {
1198 wxMessageBox("Šírka musí by reálne èíslo.", "Zle zadaná šírka!", wxOK | wxCENTRE | wxICON_ERROR);
1199 return;
1200 }
1201 if (sscanf(height->GetValue().c_str(),"%f",&a)!=1) {
1202 wxMessageBox("Výška musí by reálne èíslo.", "Zle zadaná výška!", wxOK | wxCENTRE | wxICON_ERROR);
1203 return;
1204 }
1205 if (sscanf(xoffset->GetValue().c_str(),"%f",&a)!=1) {
1206 wxMessageBox("¼avý okraj musí by reálne èíslo.", "Zle zadaný ¾avý okraj!", wxOK | wxCENTRE | wxICON_ERROR);
1207 return;
1208 }
1209 if (sscanf(yoffset->GetValue().c_str(),"%f",&a)!=1) {
1210 wxMessageBox("Horný okraj musí by reálne èíslo.", "Zle zadaný horný okraj!", wxOK | wxCENTRE | wxICON_ERROR);
1211 return;
1212 }
1213 if (sscanf(size->GetValue().c_str(),"%f",&a)!=1) {
1214 wxMessageBox("Ve¾kos písma musí by reálne èíslo.", "Zle zadaná ve¾kos písma!", wxOK | wxCENTRE | wxICON_ERROR);
1215 return;
1216 }
1217
1218 wxConfig *config = new wxConfig(wxGetApp().GetAppName());
1219 config->Write("width",width->GetValue());
1220 config->Write("height",height->GetValue());
1221 config->Write("xoffset",xoffset->GetValue());
1222 config->Write("yoffset",yoffset->GetValue());
1223 config->Write("fontsize",size->GetValue());
1224 delete config;
1225
1226 EndModal(wxID_OK);
1227 }
1228

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.26