1 /*
2 / Dialogs.cpp
3 / various dialog classes
4 /
5 / version 1.7, 2013 May 8
6 /
7 / Author: Sandro Furieri a-furieri@lqt.it
8 /
9 / Copyright (C) 2008-2013  Alessandro Furieri
10 /
11 /    This program is free software: you can redistribute it and/or modify
12 /    it under the terms of the GNU General Public License as published by
13 /    the Free Software Foundation, either version 3 of the License, or
14 /    (at your option) any later version.
15 /
16 /    This program is distributed in the hope that it will be useful,
17 /    but WITHOUT ANY WARRANTY; without even the implied warranty of
18 /    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 /    GNU General Public License for more details.
20 /
21 /    You should have received a copy of the GNU General Public License
22 /    along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 /
24 */
25 
26 #include "Classdef.h"
27 
28 #include "wx/spinctrl.h"
29 #include "wx/listctrl.h"
30 #include "wx/html/htmlwin.h"
31 
Create(MyFrame * parent)32 bool SanitizeAllGeometriesDialog::Create(MyFrame * parent)
33 {
34 //
35 // creating the dialog
36 //
37   MainFrame = parent;
38   if (wxDialog::Create(parent, wxID_ANY, wxT("Sanitize All Geometries")) ==
39       false)
40     return false;
41 // populates individual controls
42   CreateControls();
43 // sets dialog sizer
44   GetSizer()->Fit(this);
45   GetSizer()->SetSizeHints(this);
46 // centers the dialog window
47   Centre();
48   return true;
49 }
50 
CreateControls()51 void SanitizeAllGeometriesDialog::CreateControls()
52 {
53 //
54 // creating individual control and setting initial values
55 //
56   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
57   this->SetSizer(topSizer);
58   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
59   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
60   wxBoxSizer *msgSizer = new wxBoxSizer(wxHORIZONTAL);
61   boxSizer->Add(msgSizer, 0, wxALIGN_RIGHT | wxALL, 0);
62   wxString msg =
63     wxT
64     ("Do you really intend attempting to sanitize all invalid Geometries ?\n\n");
65   msg +=
66     wxT("This will imply evaluating ST_MakeValid() for each single invalid\n");
67   msg += wxT("Geometry eventually stored within any \"layer\" defined in \n");
68   msg +=
69     wxT
70     ("\"geometry_columns\", and could possibly require a substantial time\n");
71   msg += wxT("for a huge DB\n\n");
72   msg += wxT("A HTML diagnostic report will be created.");
73   wxStaticText *msgLabel = new wxStaticText(this, wxID_STATIC, msg);
74   msgSizer->Add(msgLabel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
75 // First row: TMP_PREFIX
76   wxBoxSizer *tmpSizer = new wxBoxSizer(wxHORIZONTAL);
77   boxSizer->Add(tmpSizer, 0, wxALIGN_RIGHT | wxALL, 0);
78   wxStaticText *tmpLabel =
79     new wxStaticText(this, wxID_STATIC, wxT("&Prefix for Temporary Tables:"));
80   tmpSizer->Add(tmpLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
81   wxTextCtrl *tmpCtrl = new wxTextCtrl(this, ID_SANEGEOM_PREFIX, wxT("tmp_"),
82                                        wxDefaultPosition, wxSize(150, 22));
83   tmpSizer->Add(tmpCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
84 // YES - NO buttons
85   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
86   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
87   wxButton *yes = new wxButton(this, wxID_YES, wxT("&YES"));
88   okCancelBox->Add(yes, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
89   wxButton *no = new wxButton(this, wxID_NO, wxT("&NO"));
90   okCancelBox->Add(no, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
91 // appends event handlers
92   Connect(wxID_YES, wxEVT_COMMAND_BUTTON_CLICKED,
93           (wxObjectEventFunction) & SanitizeAllGeometriesDialog::OnYes);
94   Connect(wxID_NO, wxEVT_COMMAND_BUTTON_CLICKED,
95           (wxObjectEventFunction) & SanitizeAllGeometriesDialog::OnNo);
96 }
97 
OnNo(wxCommandEvent & WXUNUSED (event))98 void SanitizeAllGeometriesDialog::OnNo(wxCommandEvent & WXUNUSED(event))
99 {
100   wxDialog::EndModal(wxNO);
101 }
102 
OnYes(wxCommandEvent & WXUNUSED (event))103 void SanitizeAllGeometriesDialog::OnYes(wxCommandEvent & WXUNUSED(event))
104 {
105 //
106 // all done:
107 //
108   wxTextCtrl *tmpCtrl = (wxTextCtrl *) FindWindow(ID_SANEGEOM_PREFIX);
109   TmpPrefix = tmpCtrl->GetValue();
110   if (TmpPrefix.Len() < 1)
111     {
112       wxMessageBox(wxT("You must specify some Prefix !!!"),
113                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
114       return;
115     }
116   wxDialog::EndModal(wxYES);
117 }
118 
Create(MyFrame * parent,wxString & table,wxString & geom)119 bool CheckGeometryDialog::Create(MyFrame * parent, wxString & table,
120                                  wxString & geom)
121 {
122 //
123 // creating the dialog
124 //
125   MainFrame = parent;
126   if (wxDialog::Create(parent, wxID_ANY, wxT("Check Geometry Column")) == false)
127     return false;
128   Table = table;
129   Geometry = geom;
130 // populates individual controls
131   CreateControls();
132 // sets dialog sizer
133   GetSizer()->Fit(this);
134   GetSizer()->SetSizeHints(this);
135 // centers the dialog window
136   Centre();
137   return true;
138 }
139 
CreateControls()140 void CheckGeometryDialog::CreateControls()
141 {
142 //
143 // creating individual control and setting initial values
144 //
145   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
146   this->SetSizer(topSizer);
147   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
148   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
149 // First row: Layer selection (Table/Column)
150   wxBoxSizer *msgSizer = new wxBoxSizer(wxHORIZONTAL);
151   boxSizer->Add(msgSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
152   wxString msg =
153     wxT
154     ("Do you really intend checking for validity this Geometry Column ?\n\n");
155   msg +=
156     wxT
157     ("This will imply evaluating ST_IsValid() for each single Geometry stored\n");
158   msg +=
159     wxT
160     ("within the select Column, and could require a substantial time for a\n");
161   msg += wxT("huge Table\n\n");
162   msg += wxT("A HTML diagnostic report will be created.");
163   wxStaticText *msgLabel = new wxStaticText(this, wxID_STATIC, msg);
164   msgSizer->Add(msgLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
165   wxBoxSizer *lyrSizer = new wxBoxSizer(wxVERTICAL);
166   boxSizer->Add(lyrSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
167   wxBoxSizer *lyr1Sizer = new wxBoxSizer(wxHORIZONTAL);
168   lyrSizer->Add(lyr1Sizer, 0, wxALIGN_RIGHT | wxALL, 0);
169   wxStaticText *tblLabel = new wxStaticText(this, wxID_STATIC, wxT("Table:"));
170   lyr1Sizer->Add(tblLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
171   wxTextCtrl *tblCtrl = new wxTextCtrl(this, wxID_ANY, Table,
172                                        wxDefaultPosition, wxSize(150, 22),
173                                        wxTE_READONLY);
174   lyr1Sizer->Add(tblCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
175   wxBoxSizer *lyr2Sizer = new wxBoxSizer(wxHORIZONTAL);
176   lyrSizer->Add(lyr2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
177   wxStaticText *geoLabel = new wxStaticText(this, wxID_STATIC, wxT("Geomety:"));
178   lyr2Sizer->Add(geoLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
179   wxTextCtrl *geoCtrl = new wxTextCtrl(this, wxID_ANY, Geometry,
180                                        wxDefaultPosition, wxSize(150, 22),
181                                        wxTE_READONLY);
182   lyr2Sizer->Add(geoCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
183 // YES - NO buttons
184   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
185   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
186   wxButton *yes = new wxButton(this, wxID_YES, wxT("&YES"));
187   okCancelBox->Add(yes, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
188   wxButton *no = new wxButton(this, wxID_NO, wxT("&NO"));
189   okCancelBox->Add(no, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
190 // appends event handlers
191   Connect(wxID_YES, wxEVT_COMMAND_BUTTON_CLICKED,
192           (wxObjectEventFunction) & CheckGeometryDialog::OnYes);
193   Connect(wxID_NO, wxEVT_COMMAND_BUTTON_CLICKED,
194           (wxObjectEventFunction) & CheckGeometryDialog::OnNo);
195 }
196 
OnNo(wxCommandEvent & WXUNUSED (event))197 void CheckGeometryDialog::OnNo(wxCommandEvent & WXUNUSED(event))
198 {
199   wxDialog::EndModal(wxNO);
200 }
201 
OnYes(wxCommandEvent & WXUNUSED (event))202 void CheckGeometryDialog::OnYes(wxCommandEvent & WXUNUSED(event))
203 {
204 //
205 // all done:
206 //
207   wxDialog::EndModal(wxYES);
208 }
209 
Create(MyFrame * parent,wxString & table,wxString & geom)210 bool SanitizeGeometryDialog::Create(MyFrame * parent, wxString & table,
211                                     wxString & geom)
212 {
213 //
214 // creating the dialog
215 //
216   MainFrame = parent;
217   if (wxDialog::Create(parent, wxID_ANY, wxT("Sanitize Geometry Column")) ==
218       false)
219     return false;
220   Table = table;
221   Geometry = geom;
222 // populates individual controls
223   CreateControls();
224 // sets dialog sizer
225   GetSizer()->Fit(this);
226   GetSizer()->SetSizeHints(this);
227 // centers the dialog window
228   Centre();
229   return true;
230 }
231 
CreateControls()232 void SanitizeGeometryDialog::CreateControls()
233 {
234 //
235 // creating individual control and setting initial values
236 //
237   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
238   this->SetSizer(topSizer);
239   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
240   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
241 // First row: Layer selection (Table/Column)
242   wxBoxSizer *msgSizer = new wxBoxSizer(wxHORIZONTAL);
243   boxSizer->Add(msgSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
244   wxString msg =
245     wxT
246     ("Do you really intend attempting to sanitize all invalid Geometries for this Geometry Column ?\n\n");
247   msg +=
248     wxT
249     ("This will imply evaluating ST_MakeValid() for each single invalid Geometry eventually\n");
250   msg +=
251     wxT
252     ("stored within the selected column, and could possibly require a substantial time\n");
253   msg += wxT("for a huge Table\n\n");
254   msg += wxT("A HTML diagnostic report will be created.");
255   wxStaticText *msgLabel = new wxStaticText(this, wxID_STATIC, msg);
256   msgSizer->Add(msgLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
257   wxBoxSizer *lyrSizer = new wxBoxSizer(wxVERTICAL);
258   boxSizer->Add(lyrSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
259   wxBoxSizer *lyr1Sizer = new wxBoxSizer(wxHORIZONTAL);
260   lyrSizer->Add(lyr1Sizer, 0, wxALIGN_RIGHT | wxALL, 0);
261   wxStaticText *tblLabel = new wxStaticText(this, wxID_STATIC, wxT("Table:"));
262   lyr1Sizer->Add(tblLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
263   wxTextCtrl *tblCtrl = new wxTextCtrl(this, wxID_ANY, Table,
264                                        wxDefaultPosition, wxSize(150, 22),
265                                        wxTE_READONLY);
266   lyr1Sizer->Add(tblCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
267   wxBoxSizer *lyr2Sizer = new wxBoxSizer(wxHORIZONTAL);
268   lyrSizer->Add(lyr2Sizer, 0, wxALIGN_RIGHT | wxALL, 0);
269   wxStaticText *geoLabel = new wxStaticText(this, wxID_STATIC, wxT("Geomety:"));
270   lyr2Sizer->Add(geoLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
271   wxTextCtrl *geoCtrl = new wxTextCtrl(this, wxID_ANY, Geometry,
272                                        wxDefaultPosition, wxSize(150, 22),
273                                        wxTE_READONLY);
274   lyr2Sizer->Add(geoCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
275 // Second row: TMP_PREFIX
276   wxBoxSizer *tmpSizer = new wxBoxSizer(wxHORIZONTAL);
277   lyrSizer->Add(tmpSizer, 0, wxALIGN_RIGHT | wxALL, 0);
278   wxStaticText *tmpLabel =
279     new wxStaticText(this, wxID_STATIC, wxT("&Prefix for Temporary Tables:"));
280   tmpSizer->Add(tmpLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
281   wxTextCtrl *tmpCtrl = new wxTextCtrl(this, ID_SANEGEOM_PREFIX, wxT("tmp_"),
282                                        wxDefaultPosition, wxSize(150, 22));
283   tmpSizer->Add(tmpCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
284 // YES - NO buttons
285   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
286   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
287   wxButton *yes = new wxButton(this, wxID_YES, wxT("&YES"));
288   okCancelBox->Add(yes, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
289   wxButton *no = new wxButton(this, wxID_NO, wxT("&NO"));
290   okCancelBox->Add(no, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
291 // appends event handlers
292   Connect(wxID_YES, wxEVT_COMMAND_BUTTON_CLICKED,
293           (wxObjectEventFunction) & SanitizeGeometryDialog::OnYes);
294   Connect(wxID_NO, wxEVT_COMMAND_BUTTON_CLICKED,
295           (wxObjectEventFunction) & SanitizeGeometryDialog::OnNo);
296 }
297 
OnNo(wxCommandEvent & WXUNUSED (event))298 void SanitizeGeometryDialog::OnNo(wxCommandEvent & WXUNUSED(event))
299 {
300   wxDialog::EndModal(wxNO);
301 }
302 
OnYes(wxCommandEvent & WXUNUSED (event))303 void SanitizeGeometryDialog::OnYes(wxCommandEvent & WXUNUSED(event))
304 {
305 //
306 // all done:
307 //
308   wxTextCtrl *tmpCtrl = (wxTextCtrl *) FindWindow(ID_SANEGEOM_PREFIX);
309   TmpPrefix = tmpCtrl->GetValue();
310   if (TmpPrefix.Len() < 1)
311     {
312       wxMessageBox(wxT("You must specify some Prefix !!!"),
313                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
314       return;
315     }
316   wxDialog::EndModal(wxYES);
317 }
318 
Create(MyFrame * parent,wxString & table,wxString & geom,bool rdOnly,bool hidden)319 bool GisLayerAuthDialog::Create(MyFrame * parent, wxString & table,
320                                 wxString & geom, bool rdOnly, bool hidden)
321 {
322 //
323 // creating the dialog
324 //
325   MainFrame = parent;
326   Table = table;
327   Geometry = geom;
328   ReadOnly = rdOnly;
329   Hidden = hidden;
330   if (Hidden == true)
331     ReadOnly = false;
332   if (wxDialog::Create(parent, wxID_ANY, wxT("GIS Layer authorizations")) ==
333       false)
334     return false;
335 // populates individual controls
336   CreateControls();
337 // sets dialog sizer
338   GetSizer()->Fit(this);
339   GetSizer()->SetSizeHints(this);
340 // centers the dialog window
341   Centre();
342   return true;
343 }
344 
CreateControls()345 void GisLayerAuthDialog::CreateControls()
346 {
347 //
348 // creating individual control and setting initial values
349 //
350   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
351   this->SetSizer(topSizer);
352   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
353   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
354 // First row: TABLE name
355   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
356   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
357   wxStaticText *tableLabel =
358     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
359   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
360   wxTextCtrl *tableCtrl = new wxTextCtrl(this, wxID_ANY, Table,
361                                          wxDefaultPosition, wxSize(350, 22),
362                                          wxTE_READONLY);
363   tableCtrl->Enable(false);
364   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
365 // second row: GEOMETRY COLUMN name
366   wxBoxSizer *colSizer = new wxBoxSizer(wxHORIZONTAL);
367   boxSizer->Add(colSizer, 0, wxALIGN_RIGHT | wxALL, 0);
368   wxStaticText *colLabel =
369     new wxStaticText(this, wxID_STATIC, wxT("&Geometry name:"));
370   colSizer->Add(colLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
371   wxTextCtrl *colCtrl = new wxTextCtrl(this, wxID_ANY, Geometry,
372                                        wxDefaultPosition, wxSize(350, 22),
373                                        wxTE_READONLY);
374   colCtrl->Enable(false);
375   colSizer->Add(colCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
376 // third row: HIDDEN / VISIBLE
377   wxBoxSizer *authSizer = new wxBoxSizer(wxHORIZONTAL);
378   boxSizer->Add(authSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
379   wxString hidden[2];
380   hidden[0] = wxT("&Visible [ordinary GIS Layer]");
381   hidden[1] = wxT("&Hidden [not usable as a GIS Layer");
382   wxRadioBox *hiddenBox = new wxRadioBox(this, ID_AUTH_HIDDEN,
383                                          wxT("&GIS Layer status"),
384                                          wxDefaultPosition,
385                                          wxDefaultSize, 2,
386                                          hidden, 1,
387                                          wxRA_SPECIFY_COLS);
388   authSizer->Add(hiddenBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
389   if (Hidden == true)
390     hiddenBox->SetSelection(1);
391   else
392     hiddenBox->SetSelection(0);
393 // fourth row: READ-ONLY
394   wxString rdOnly[2];
395   rdOnly[0] = wxT("&ReadWrite [allows editing]");
396   rdOnly[1] = wxT("&ReadOnly [not editable]");
397   wxRadioBox *rdOnlyBox = new wxRadioBox(this, ID_AUTH_RDONLY,
398                                          wxT("&Editing mode"),
399                                          wxDefaultPosition,
400                                          wxDefaultSize, 2,
401                                          rdOnly, 1,
402                                          wxRA_SPECIFY_COLS);
403   authSizer->Add(rdOnlyBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
404   if (ReadOnly == true)
405     rdOnlyBox->SetSelection(1);
406   else
407     rdOnlyBox->SetSelection(0);
408   if (Hidden == true)
409     rdOnlyBox->Enable(false);
410 // OK - CANCEL buttons
411   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
412   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
413   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
414   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
415   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
416   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
417 // appends event handlers
418   Connect(ID_AUTH_HIDDEN, wxEVT_COMMAND_RADIOBOX_SELECTED,
419           (wxObjectEventFunction) & GisLayerAuthDialog::OnHiddenChanged);
420   Connect(ID_AUTH_RDONLY, wxEVT_COMMAND_RADIOBOX_SELECTED,
421           (wxObjectEventFunction) & GisLayerAuthDialog::OnReadOnlyChanged);
422   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
423           (wxObjectEventFunction) & GisLayerAuthDialog::OnOk);
424 }
425 
OnHiddenChanged(wxCommandEvent & WXUNUSED (event))426 void GisLayerAuthDialog::OnHiddenChanged(wxCommandEvent & WXUNUSED(event))
427 {
428 //
429 // HIDDEN / VISIBLE selection changed
430 //
431   wxRadioBox *hiddenCtrl = (wxRadioBox *) FindWindow(ID_AUTH_HIDDEN);
432   wxRadioBox *rdOnlyCtrl = (wxRadioBox *) FindWindow(ID_AUTH_RDONLY);
433   switch (hiddenCtrl->GetSelection())
434     {
435       case 0:
436         Hidden = false;
437         break;
438       case 1:
439         Hidden = true;
440         break;
441     };
442   if (Hidden == true)
443     {
444       ReadOnly = false;
445       rdOnlyCtrl->SetSelection(0);
446       rdOnlyCtrl->Enable(false);
447   } else
448     {
449       if (ReadOnly == false)
450         rdOnlyCtrl->SetSelection(0);
451       else
452         rdOnlyCtrl->SetSelection(1);
453       rdOnlyCtrl->Enable(true);
454     }
455 }
456 
OnReadOnlyChanged(wxCommandEvent & WXUNUSED (event))457 void GisLayerAuthDialog::OnReadOnlyChanged(wxCommandEvent & WXUNUSED(event))
458 {
459 //
460 // READ-ONLY selection changed
461 //
462   wxRadioBox *rdOnlyCtrl = (wxRadioBox *) FindWindow(ID_AUTH_RDONLY);
463   switch (rdOnlyCtrl->GetSelection())
464     {
465       case 0:
466         ReadOnly = false;
467         break;
468       case 1:
469         ReadOnly = true;
470         break;
471     };
472 }
473 
OnOk(wxCommandEvent & WXUNUSED (event))474 void GisLayerAuthDialog::OnOk(wxCommandEvent & WXUNUSED(event))
475 {
476 //
477 // all done:
478 //
479   wxDialog::EndModal(wxID_OK);
480 }
481 
Create(MyFrame * parent,wxString & path,wxString & table,wxString & defCs)482 bool VirtualShpDialog::Create(MyFrame * parent, wxString & path,
483                               wxString & table, wxString & defCs)
484 {
485 //
486 // creating the dialog
487 //
488   MainFrame = parent;
489   Path = path;
490   Table = table;
491   Default = defCs;
492   if (wxDialog::Create(parent, wxID_ANY, wxT("Creating Virtual Shapefile")) ==
493       false)
494     return false;
495 // populates individual controls
496   CreateControls();
497 // sets dialog sizer
498   GetSizer()->Fit(this);
499   GetSizer()->SetSizeHints(this);
500 // centers the dialog window
501   Centre();
502   return true;
503 }
504 
CreateControls()505 void VirtualShpDialog::CreateControls()
506 {
507 //
508 // creating individual control and setting initial values
509 //
510   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
511   this->SetSizer(topSizer);
512   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
513   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
514 // first row: the Shapefile path
515   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
516   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
517   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
518   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
519   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
520                                          Path, wxDefaultPosition,
521                                          wxSize(350, 22), wxTE_READONLY);
522   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
523 // second row: TABLE name
524   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
525   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
526   wxStaticText *tableLabel =
527     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
528   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
529   wxTextCtrl *tableCtrl = new wxTextCtrl(this, ID_VIRTSHP_TABLE, Table,
530                                          wxDefaultPosition, wxSize(350,
531                                                                    22));
532   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
533 // second row: SRID
534   wxBoxSizer *sridSizer = new wxBoxSizer(wxHORIZONTAL);
535   boxSizer->Add(sridSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
536   wxStaticText *sridLabel = new wxStaticText(this, wxID_STATIC, wxT("&SRID:"));
537   sridSizer->Add(sridLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
538   int srid = 0;
539   if (MainFrame->GetMetaDataType() != METADATA_CURRENT)
540     srid = -1;                  // old default SRID
541   wxSpinCtrl *sridCtrl = new wxSpinCtrl(this, ID_VIRTSHP_SRID, wxEmptyString,
542                                         wxDefaultPosition, wxSize(80, 20),
543                                         wxSP_ARROW_KEYS,
544                                         -1, 1000000, srid);
545   sridSizer->Add(sridCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
546 // third row: CHARSET
547   wxStaticBox *charsetBox = new wxStaticBox(this, wxID_STATIC,
548                                             wxT("Charset Encoding"),
549                                             wxDefaultPosition,
550                                             wxDefaultSize);
551   wxBoxSizer *charsetSizer = new wxStaticBoxSizer(charsetBox, wxHORIZONTAL);
552   sridSizer->Add(charsetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
553   wxListBox *charsetCtrl = new wxListBox(this, ID_VIRTSHP_CHARSET,
554                                          wxDefaultPosition, wxDefaultSize,
555                                          MainFrame->GetCharsetsLen(),
556                                          MainFrame->GetCharsetsNames(),
557                                          wxLB_SINGLE | wxLB_HSCROLL);
558   charsetCtrl->SetFont(wxFont
559                        (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
560                         wxFONTWEIGHT_NORMAL));
561   int idSel = MainFrame->GetCharsetIndex(Default);
562   if (idSel != wxNOT_FOUND)
563     charsetCtrl->SetSelection(idSel);
564   charsetSizer->Add(charsetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
565 // OK - CANCEL buttons
566   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
567   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
568   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
569   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
570   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
571   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
572 // appends event handler for OK button
573   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
574           (wxObjectEventFunction) & VirtualShpDialog::OnOk);
575 }
576 
OnOk(wxCommandEvent & WXUNUSED (event))577 void VirtualShpDialog::OnOk(wxCommandEvent & WXUNUSED(event))
578 {
579 //
580 // all done:
581 //
582   wxTextCtrl *tableCtrl = (wxTextCtrl *) FindWindow(ID_VIRTSHP_TABLE);
583   Table = tableCtrl->GetValue();
584   if (Table.Len() < 1)
585     {
586       wxMessageBox(wxT("You must specify the TABLE NAME !!!"),
587                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
588       return;
589     }
590   if (MainFrame->TableAlreadyExists(Table) == true)
591     {
592       wxMessageBox(wxT("a table name '") + Table + wxT("' already exists"),
593                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
594       return;
595     }
596   wxSpinCtrl *sridCtrl = (wxSpinCtrl *) FindWindow(ID_VIRTSHP_SRID);
597   Srid = sridCtrl->GetValue();
598   if (Srid <= 0)
599     ;
600   else if (MainFrame->SridNotExists(Srid) == true)
601     {
602       wxMessageBox(wxT("invalid SRID value"), wxT("spatialite_gui"),
603                    wxOK | wxICON_WARNING, this);
604       return;
605     }
606   wxListBox *charsetCtrl = (wxListBox *) FindWindow(ID_VIRTSHP_CHARSET);
607   int idSel = charsetCtrl->GetSelection();
608   if (idSel == wxNOT_FOUND)
609     {
610       wxMessageBox(wxT("you must select some Charset Encoding from the list"),
611                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
612       return;
613     }
614   wxString *charsets = MainFrame->GetCharsets();
615   Charset = *(charsets + idSel);
616   wxDialog::EndModal(wxID_OK);
617 }
618 
Create(MyFrame * parent,wxString & path,wxString & table,wxString & defCs)619 bool VirtualTxtDialog::Create(MyFrame * parent, wxString & path,
620                               wxString & table, wxString & defCs)
621 {
622 //
623 // creating the dialog
624 //
625   MainFrame = parent;
626   Path = path;
627   Table = table;
628   Default = defCs;
629   if (wxDialog::Create(parent, wxID_ANY, wxT("Creating Virtual CSV/TXT")) ==
630       false)
631     return false;
632 // populates individual controls
633   CreateControls();
634 // sets dialog sizer
635   GetSizer()->Fit(this);
636   GetSizer()->SetSizeHints(this);
637 // centers the dialog window
638   Centre();
639   return true;
640 }
641 
CreateControls()642 void VirtualTxtDialog::CreateControls()
643 {
644 //
645 // creating individual control and setting initial values
646 //
647   FirstLineTitles = true;
648   Separator = '\t';
649   TextSeparator = '"';
650   DecimalPointIsComma = false;
651   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
652   this->SetSizer(topSizer);
653   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
654   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
655 // first row: the CSV/TXT path
656   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
657   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
658   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
659   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
660   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
661                                          Path, wxDefaultPosition,
662                                          wxSize(350, 22), wxTE_READONLY);
663   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
664 // second row: TABLE name
665   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
666   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
667   wxStaticText *tableLabel =
668     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
669   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
670   wxTextCtrl *tableCtrl = new wxTextCtrl(this, ID_VIRTTXT_TABLE, Table,
671                                          wxDefaultPosition, wxSize(350,
672                                                                    22));
673   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
674 // second row: OPTIONS
675   wxBoxSizer *optSizer = new wxBoxSizer(wxHORIZONTAL);
676   boxSizer->Add(optSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
677   wxBoxSizer *modeSizer = new wxBoxSizer(wxVERTICAL);
678   optSizer->Add(modeSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
679   wxBoxSizer *mode1Sizer = new wxBoxSizer(wxHORIZONTAL);
680   modeSizer->Add(mode1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
681   wxCheckBox *titleCtrl = new wxCheckBox(this, ID_VIRTTXT_TITLES,
682                                          wxT
683                                          ("First line contains column names"),
684                                          wxDefaultPosition, wxDefaultSize);
685   titleCtrl->SetValue(true);
686   mode1Sizer->Add(titleCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
687   wxStaticBox *sepBox = new wxStaticBox(this, wxID_STATIC,
688                                         wxT("Separators"),
689                                         wxDefaultPosition, wxDefaultSize);
690   wxBoxSizer *sepSizer = new wxStaticBoxSizer(sepBox, wxVERTICAL);
691   modeSizer->Add(sepSizer, 0, wxALIGN_LEFT | wxALL, 0);
692   wxBoxSizer *mode2Sizer = new wxBoxSizer(wxHORIZONTAL);
693   sepSizer->Add(mode2Sizer, 0, wxALIGN_LEFT | wxALL, 0);
694   wxString quotes[3];
695   quotes[0] = wxT("&Double \"");
696   quotes[1] = wxT("&Single '");
697   quotes[2] = wxT("&None");
698   wxRadioBox *textSeparatorBox = new wxRadioBox(this, ID_VIRTTXT_QUOTE,
699                                                 wxT("&Text separator: quotes"),
700                                                 wxDefaultPosition,
701                                                 wxDefaultSize, 3,
702                                                 quotes, 3,
703                                                 wxRA_SPECIFY_COLS);
704   mode2Sizer->Add(textSeparatorBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
705   wxBoxSizer *mode3Sizer = new wxBoxSizer(wxHORIZONTAL);
706   sepSizer->Add(mode3Sizer, 0, wxALIGN_LEFT | wxALL, 0);
707   wxString separators[6];
708   separators[0] = wxT("&Tab");
709   separators[1] = wxT("&Space");
710   separators[2] = wxT("Co&mma ,");
711   separators[3] = wxT("&Colon :");
712   separators[4] = wxT("S&emicolon ;");
713   separators[5] = wxT("&Other");
714   wxRadioBox *separatorBox = new wxRadioBox(this, ID_VIRTTXT_SEPARATOR,
715                                             wxT("&Column separator"),
716                                             wxDefaultPosition, wxDefaultSize,
717                                             6,
718                                             separators, 2,
719                                             wxRA_SPECIFY_COLS);
720   mode3Sizer->Add(separatorBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
721   wxBoxSizer *mode4Sizer = new wxBoxSizer(wxHORIZONTAL);
722   sepSizer->Add(mode4Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
723   wxStaticText *charSeparatorLabel = new wxStaticText(this, wxID_STATIC,
724                                                       wxT("&Custom separator:"),
725                                                       wxDefaultPosition,
726                                                       wxDefaultSize, 0);
727   mode4Sizer->Add(charSeparatorLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
728   wxTextCtrl *dummy =
729     new wxTextCtrl(this, ID_VIRTTXT_CHARSEPARATOR, wxT("Dummy Text pq"),
730                    wxDefaultPosition,
731                    wxDefaultSize, 0);
732   wxSize sz = dummy->GetSize();
733   delete dummy;
734   sz.SetWidth(40);
735   wxTextCtrl *charSeparatorCtrl =
736     new wxTextCtrl(this, ID_VIRTTXT_CHARSEPARATOR, wxT("TAB"),
737                    wxDefaultPosition, sz, 0);
738   charSeparatorCtrl->SetMaxLength(1);
739   charSeparatorCtrl->Enable(false);
740   mode4Sizer->Add(charSeparatorCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
741   wxBoxSizer *mode5Sizer = new wxBoxSizer(wxHORIZONTAL);
742   sepSizer->Add(mode5Sizer, 0, wxALIGN_LEFT | wxALL, 0);
743   wxString points[2];
744   points[0] = wxT("&Point .");
745   points[1] = wxT("&Comma ,");
746   wxRadioBox *decimalSeparatorBox = new wxRadioBox(this, ID_VIRTTXT_POINT,
747                                                    wxT("&Decimal separator"),
748                                                    wxDefaultPosition,
749                                                    wxDefaultSize, 2,
750                                                    points, 2,
751                                                    wxRA_SPECIFY_COLS);
752   mode5Sizer->Add(decimalSeparatorBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
753 // third row: CHARSET
754   wxStaticBox *charsetBox = new wxStaticBox(this, wxID_STATIC,
755                                             wxT("Charset Encoding"),
756                                             wxDefaultPosition,
757                                             wxDefaultSize);
758   wxBoxSizer *charsetSizer = new wxStaticBoxSizer(charsetBox, wxHORIZONTAL);
759   optSizer->Add(charsetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
760   wxListBox *charsetCtrl = new wxListBox(this, ID_VIRTTXT_CHARSET,
761                                          wxDefaultPosition, wxDefaultSize,
762                                          MainFrame->GetCharsetsLen(),
763                                          MainFrame->GetCharsetsNames(),
764                                          wxLB_SINGLE | wxLB_HSCROLL);
765   charsetCtrl->SetFont(wxFont
766                        (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
767                         wxFONTWEIGHT_NORMAL));
768   int idSel = MainFrame->GetCharsetIndex(Default);
769   if (idSel != wxNOT_FOUND)
770     charsetCtrl->SetSelection(idSel);
771   charsetSizer->Add(charsetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
772 // OK - CANCEL buttons
773   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
774   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
775   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
776   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
777   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
778   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
779 // appends event handler for OK button
780   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
781           (wxObjectEventFunction) & VirtualTxtDialog::OnOk);
782 // appends event handler for radioboxes
783   Connect(ID_VIRTTXT_QUOTE, wxEVT_COMMAND_RADIOBOX_SELECTED,
784           (wxObjectEventFunction) & VirtualTxtDialog::OnQuote);
785   Connect(ID_VIRTTXT_SEPARATOR, wxEVT_COMMAND_RADIOBOX_SELECTED,
786           (wxObjectEventFunction) & VirtualTxtDialog::OnSeparator);
787   Connect(ID_VIRTTXT_POINT, wxEVT_COMMAND_RADIOBOX_SELECTED,
788           (wxObjectEventFunction) & VirtualTxtDialog::OnDecimalSeparator);
789 }
790 
OnDecimalSeparator(wxCommandEvent & WXUNUSED (event))791 void VirtualTxtDialog::OnDecimalSeparator(wxCommandEvent & WXUNUSED(event))
792 {
793 //
794 // POINT selection changed
795 //
796   wxRadioBox *decimalSeparatorCtrl =
797     (wxRadioBox *) FindWindow(ID_VIRTTXT_POINT);
798   switch (decimalSeparatorCtrl->GetSelection())
799     {
800       case 0:
801         DecimalPointIsComma = false;
802         break;
803       case 1:
804         DecimalPointIsComma = true;
805         break;
806     };
807 }
808 
OnQuote(wxCommandEvent & WXUNUSED (event))809 void VirtualTxtDialog::OnQuote(wxCommandEvent & WXUNUSED(event))
810 {
811 //
812 // QUOTE selection changed
813 //
814   wxRadioBox *separatorCtrl = (wxRadioBox *) FindWindow(ID_VIRTTXT_QUOTE);
815   switch (separatorCtrl->GetSelection())
816     {
817       case 0:
818         TextSeparator = '"';
819         break;
820       case 1:
821         TextSeparator = '\'';
822         break;
823       case 2:
824         TextSeparator = '\0';
825         break;
826     };
827 }
828 
OnSeparator(wxCommandEvent & WXUNUSED (event))829 void VirtualTxtDialog::OnSeparator(wxCommandEvent & WXUNUSED(event))
830 {
831 //
832 // SEPARATOR selection changed
833 //
834   wxTextCtrl *charSeparatorCtrl =
835     (wxTextCtrl *) FindWindow(ID_VIRTTXT_CHARSEPARATOR);
836   wxRadioBox *separatorCtrl = (wxRadioBox *) FindWindow(ID_VIRTTXT_SEPARATOR);
837   switch (separatorCtrl->GetSelection())
838     {
839       case 0:
840         Separator = '\t';
841         charSeparatorCtrl->SetValue(wxT("TAB"));
842         break;
843       case 1:
844         Separator = ' ';
845         charSeparatorCtrl->SetValue(wxT("SP"));
846         break;
847       case 2:
848         Separator = ',';
849         charSeparatorCtrl->SetValue(wxT(","));
850         break;
851       case 3:
852         Separator = ':';
853         charSeparatorCtrl->SetValue(wxT(":"));
854         break;
855       case 4:
856         Separator = ';';
857         charSeparatorCtrl->SetValue(wxT(";"));
858         break;
859       case 5:
860         Separator = '|';
861         charSeparatorCtrl->SetValue(wxT("|"));
862         break;
863     };
864   if (separatorCtrl->GetSelection() == 5)
865     charSeparatorCtrl->Enable(true);
866   else
867     charSeparatorCtrl->Enable(false);
868 }
869 
OnOk(wxCommandEvent & WXUNUSED (event))870 void VirtualTxtDialog::OnOk(wxCommandEvent & WXUNUSED(event))
871 {
872 //
873 // all done:
874 //
875   wxCheckBox *firstLineCtrl = (wxCheckBox *) FindWindow(ID_VIRTTXT_TITLES);
876   FirstLineTitles = firstLineCtrl->IsChecked();
877   wxTextCtrl *tableCtrl = (wxTextCtrl *) FindWindow(ID_VIRTTXT_TABLE);
878   Table = tableCtrl->GetValue();
879   if (Table.Len() < 1)
880     {
881       wxMessageBox(wxT("You must specify the TABLE NAME !!!"),
882                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
883       return;
884     }
885   if (MainFrame->TableAlreadyExists(Table) == true)
886     {
887       wxMessageBox(wxT("a table name '") + Table + wxT("' already exists"),
888                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
889       return;
890     }
891   wxListBox *charsetCtrl = (wxListBox *) FindWindow(ID_VIRTTXT_CHARSET);
892   int idSel = charsetCtrl->GetSelection();
893   if (idSel == wxNOT_FOUND)
894     {
895       wxMessageBox(wxT("you must select some Charset Encoding from the list"),
896                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
897       return;
898     }
899   wxString *charsets = MainFrame->GetCharsets();
900   Charset = *(charsets + idSel);
901   wxRadioBox *separatorCtrl = (wxRadioBox *) FindWindow(ID_VIRTTXT_SEPARATOR);
902   if (separatorCtrl->GetSelection() == 5)
903     {
904       wxTextCtrl *charSeparatorCtrl =
905         (wxTextCtrl *) FindWindow(ID_VIRTTXT_CHARSEPARATOR);
906       wxString separator = charSeparatorCtrl->GetValue();
907       if (separator.Len() != 1)
908         {
909           wxMessageBox(wxT
910                        ("you must specificy a single char as Custom Column Separator"),
911                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
912           return;
913         }
914       char dummy[64];
915       strcpy(dummy, separator.ToUTF8());
916       Separator = *dummy;
917     }
918   wxDialog::EndModal(wxID_OK);
919 }
920 
Create(MyFrame * parent,wxString & path,wxString & table,wxString & defCs)921 bool VirtualDbfDialog::Create(MyFrame * parent, wxString & path,
922                               wxString & table, wxString & defCs)
923 {
924 //
925 // creating the dialog
926 //
927   MainFrame = parent;
928   Path = path;
929   Table = table;
930   Default = defCs;
931   if (wxDialog::Create(parent, wxID_ANY, wxT("Creating Virtual DBF")) == false)
932     return false;
933 // populates individual controls
934   CreateControls();
935 // sets dialog sizer
936   GetSizer()->Fit(this);
937   GetSizer()->SetSizeHints(this);
938 // centers the dialog window
939   Centre();
940   return true;
941 }
942 
CreateControls()943 void VirtualDbfDialog::CreateControls()
944 {
945 //
946 // creating individual control and setting initial values
947 //
948   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
949   this->SetSizer(topSizer);
950   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
951   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
952 // first row: the DBF path
953   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
954   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
955   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
956   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
957   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
958                                          Path, wxDefaultPosition,
959                                          wxSize(350, 22), wxTE_READONLY);
960   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
961 // second row: TABLE name
962   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
963   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
964   wxStaticText *tableLabel =
965     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
966   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
967   wxTextCtrl *tableCtrl = new wxTextCtrl(this, ID_VIRTDBF_TABLE, Table,
968                                          wxDefaultPosition, wxSize(350,
969                                                                    22));
970   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
971 // third row: CHARSET
972   wxBoxSizer *optSizer = new wxBoxSizer(wxHORIZONTAL);
973   boxSizer->Add(optSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
974   wxStaticBox *charsetBox = new wxStaticBox(this, wxID_STATIC,
975                                             wxT("Charset Encoding"),
976                                             wxDefaultPosition,
977                                             wxDefaultSize);
978   wxBoxSizer *charsetSizer = new wxStaticBoxSizer(charsetBox, wxHORIZONTAL);
979   optSizer->Add(charsetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
980   wxListBox *charsetCtrl = new wxListBox(this, ID_VIRTDBF_CHARSET,
981                                          wxDefaultPosition, wxDefaultSize,
982                                          MainFrame->GetCharsetsLen(),
983                                          MainFrame->GetCharsetsNames(),
984                                          wxLB_SINGLE | wxLB_HSCROLL);
985   charsetCtrl->SetFont(wxFont
986                        (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
987                         wxFONTWEIGHT_NORMAL));
988   int idSel = MainFrame->GetCharsetIndex(Default);
989   if (idSel != wxNOT_FOUND)
990     charsetCtrl->SetSelection(idSel);
991   charsetSizer->Add(charsetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
992 // OK - CANCEL buttons
993   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
994   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
995   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
996   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
997   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
998   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
999 // appends event handler for OK button
1000   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
1001           (wxObjectEventFunction) & VirtualDbfDialog::OnOk);
1002 }
1003 
OnOk(wxCommandEvent & WXUNUSED (event))1004 void VirtualDbfDialog::OnOk(wxCommandEvent & WXUNUSED(event))
1005 {
1006 //
1007 // all done:
1008 //
1009   wxTextCtrl *tableCtrl = (wxTextCtrl *) FindWindow(ID_VIRTDBF_TABLE);
1010   Table = tableCtrl->GetValue();
1011   if (Table.Len() < 1)
1012     {
1013       wxMessageBox(wxT("You must specify the TABLE NAME !!!"),
1014                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1015       return;
1016     }
1017   if (MainFrame->TableAlreadyExists(Table) == true)
1018     {
1019       wxMessageBox(wxT("a table name '") + Table + wxT("' already exists"),
1020                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1021       return;
1022     }
1023   wxListBox *charsetCtrl = (wxListBox *) FindWindow(ID_VIRTDBF_CHARSET);
1024   int idSel = charsetCtrl->GetSelection();
1025   if (idSel == wxNOT_FOUND)
1026     {
1027       wxMessageBox(wxT("you must select some Charset Encoding from the list"),
1028                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1029       return;
1030     }
1031   wxString *charsets = MainFrame->GetCharsets();
1032   Charset = *(charsets + idSel);
1033   wxDialog::EndModal(wxID_OK);
1034 }
1035 
Create(MyFrame * parent,wxString & path,wxString & table)1036 bool VirtualXLDialog::Create(MyFrame * parent, wxString & path,
1037                              wxString & table)
1038 {
1039 //
1040 // creating the dialog
1041 //
1042   MainFrame = parent;
1043   Path = path;
1044   Table = table;
1045   FirstLineTitles = false;
1046   if (wxDialog::Create(parent, wxID_ANY, wxT("Creating Virtual XL")) == false)
1047     return false;
1048   GetWorksheets();
1049   WorksheetIndex = 0;
1050 // populates individual controls
1051   CreateControls();
1052 // sets dialog sizer
1053   GetSizer()->Fit(this);
1054   GetSizer()->SetSizeHints(this);
1055 // centers the dialog window
1056   Centre();
1057   return true;
1058 }
1059 
CreateControls()1060 void VirtualXLDialog::CreateControls()
1061 {
1062 //
1063 // creating individual control and setting initial values
1064 //
1065   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
1066   this->SetSizer(topSizer);
1067   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
1068   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1069 // first row: the XL path
1070   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
1071   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
1072   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
1073   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1074   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
1075                                          Path, wxDefaultPosition,
1076                                          wxSize(350, 22), wxTE_READONLY);
1077   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
1078 // second row: TABLE name
1079   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
1080   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
1081   wxStaticText *tableLabel =
1082     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
1083   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1084   wxTextCtrl *tableCtrl = new wxTextCtrl(this, ID_VIRTXL_TABLE, Table,
1085                                          wxDefaultPosition, wxSize(350,
1086                                                                    22));
1087   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
1088 // third row: Worksheets
1089   wxBoxSizer *optSizer = new wxBoxSizer(wxVERTICAL);
1090   boxSizer->Add(optSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1091   wxStaticBox *sheetBox = new wxStaticBox(this, wxID_STATIC,
1092                                           wxT("Worksheet Selection"),
1093                                           wxDefaultPosition,
1094                                           wxDefaultSize);
1095   wxBoxSizer *sheetSizer = new wxStaticBoxSizer(sheetBox, wxHORIZONTAL);
1096   optSizer->Add(sheetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1097   wxListBox *sheetCtrl = new wxListBox(this, ID_VIRTXL_WORKSHEET,
1098                                        wxDefaultPosition, wxSize(400, 100),
1099                                        WorksheetCount, Worksheets,
1100                                        wxLB_SINGLE | wxLB_HSCROLL);
1101   sheetCtrl->SetFont(wxFont
1102                      (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
1103                       wxFONTWEIGHT_NORMAL));
1104   sheetCtrl->SetSelection(0);
1105   sheetSizer->Add(sheetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
1106 // fourth row: First Line Titles
1107   wxCheckBox *titleCtrl = new wxCheckBox(this, ID_VIRTXL_TITLES,
1108                                          wxT
1109                                          ("First line contains column names"),
1110                                          wxDefaultPosition, wxDefaultSize);
1111   titleCtrl->SetValue(false);
1112   optSizer->Add(titleCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1113 // OK - CANCEL buttons
1114   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
1115   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1116   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
1117   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1118   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
1119   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1120 // appends event handler for OK button
1121   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
1122           (wxObjectEventFunction) & VirtualXLDialog::OnOk);
1123 }
1124 
GetWorksheets()1125 void VirtualXLDialog::GetWorksheets()
1126 {
1127 // attempting to build the Worksheet List
1128 #ifndef OMIT_FREEXL             /* only if FreeXL is enabled */
1129   Invalid = true;
1130   Worksheets = NULL;
1131   WorksheetCount = 0;
1132   int ret;
1133   const void *xl_handle;
1134   char dummy[1024];
1135   unsigned int info;
1136   unsigned int idx;
1137   const char *utf8_string;
1138 
1139 // opening the .XLS file [Workbook]
1140   strcpy(dummy, Path.ToUTF8());
1141   ret = freexl_open_info(dummy, &xl_handle);
1142   if (ret != FREEXL_OK)
1143     goto error;
1144 // checking if Password protected
1145   ret = freexl_get_info(xl_handle, FREEXL_BIFF_PASSWORD, &info);
1146   if (ret != FREEXL_OK)
1147     goto error;
1148   if (info != FREEXL_BIFF_PLAIN)
1149     goto error;
1150 // Worksheet entries
1151   ret = freexl_get_info(xl_handle, FREEXL_BIFF_SHEET_COUNT, &info);
1152   if (ret != FREEXL_OK)
1153     goto error;
1154   if (info == 0)
1155     goto error;
1156 
1157   Worksheets = new wxString[info];
1158   WorksheetCount = info;
1159   for (idx = 0; idx < info; idx++)
1160     {
1161       // fetching Worksheets entries
1162       unsigned int rows;
1163       unsigned short columns;
1164 
1165       ret = freexl_get_worksheet_name(xl_handle, idx, &utf8_string);
1166       if (ret != FREEXL_OK)
1167         goto error;
1168       ret = freexl_select_active_worksheet(xl_handle, idx);
1169       if (ret != FREEXL_OK)
1170         goto error;
1171       ret = freexl_worksheet_dimensions(xl_handle, &rows, &columns);
1172       if (ret != FREEXL_OK)
1173         goto error;
1174       if (utf8_string == NULL)
1175         sprintf(dummy, "%3u] NULL (unnamed) [%urows / %ucols]\n", idx, rows,
1176                 columns);
1177       else
1178         sprintf(dummy, "%3u] %s [%urows / %ucols]\n", idx, utf8_string, rows,
1179                 columns);
1180       Worksheets[idx] = wxString::FromUTF8(dummy);
1181     }
1182   Invalid = false;
1183   freexl_close(xl_handle);
1184   return;
1185 
1186 error:
1187   freexl_close(xl_handle);
1188   if (Worksheets)
1189     delete[]Worksheets;
1190   Worksheets = new wxString[1];
1191   Worksheets[0] = wxT("ERROR: no Worksheet found");
1192   WorksheetCount = 1;
1193 #endif /* end FreeXL conditional support */
1194 }
1195 
OnOk(wxCommandEvent & WXUNUSED (event))1196 void VirtualXLDialog::OnOk(wxCommandEvent & WXUNUSED(event))
1197 {
1198 //
1199 // all done:
1200 //
1201   if (Invalid)
1202     {
1203       wxMessageBox(wxT("You cannot confirm: INVALID XL datasource !!!"),
1204                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1205       return;
1206     }
1207   wxTextCtrl *tableCtrl = (wxTextCtrl *) FindWindow(ID_VIRTXL_TABLE);
1208   Table = tableCtrl->GetValue();
1209   if (Table.Len() < 1)
1210     {
1211       wxMessageBox(wxT("You must specify the TABLE NAME !!!"),
1212                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1213       return;
1214     }
1215   if (MainFrame->TableAlreadyExists(Table) == true)
1216     {
1217       wxMessageBox(wxT("a table name '") + Table + wxT("' already exists"),
1218                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1219       return;
1220     }
1221   wxListBox *sheetCtrl = (wxListBox *) FindWindow(ID_VIRTXL_WORKSHEET);
1222   int idSel = sheetCtrl->GetSelection();
1223   if (idSel == wxNOT_FOUND)
1224     {
1225       wxMessageBox(wxT("you must select some Worksheet from the list"),
1226                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1227       return;
1228     }
1229   WorksheetIndex = idSel;
1230   wxCheckBox *firstLineCtrl = (wxCheckBox *) FindWindow(ID_VIRTXL_TITLES);
1231   FirstLineTitles = firstLineCtrl->IsChecked();
1232   wxDialog::EndModal(wxID_OK);
1233 }
1234 
Create(MyFrame * parent,wxString & path,wxString & table)1235 bool LoadXLDialog::Create(MyFrame * parent, wxString & path, wxString & table)
1236 {
1237 //
1238 // creating the dialog
1239 //
1240   MainFrame = parent;
1241   Path = path;
1242   Table = table;
1243   FirstLineTitles = false;
1244   if (wxDialog::Create(parent, wxID_ANY, wxT("Load XL spreadsheet")) == false)
1245     return false;
1246   GetWorksheets();
1247   WorksheetIndex = 0;
1248 // populates individual controls
1249   CreateControls();
1250 // sets dialog sizer
1251   GetSizer()->Fit(this);
1252   GetSizer()->SetSizeHints(this);
1253 // centers the dialog window
1254   Centre();
1255   return true;
1256 }
1257 
CreateControls()1258 void LoadXLDialog::CreateControls()
1259 {
1260 //
1261 // creating individual control and setting initial values
1262 //
1263   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
1264   this->SetSizer(topSizer);
1265   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
1266   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1267 // first row: the XL path
1268   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
1269   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
1270   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
1271   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1272   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
1273                                          Path, wxDefaultPosition,
1274                                          wxSize(350, 22), wxTE_READONLY);
1275   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
1276 // second row: TABLE name
1277   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
1278   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
1279   wxStaticText *tableLabel =
1280     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
1281   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1282   wxTextCtrl *tableCtrl = new wxTextCtrl(this, ID_LDXL_TABLE, Table,
1283                                          wxDefaultPosition, wxSize(350,
1284                                                                    22));
1285   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
1286 // third row: Worksheets
1287   wxBoxSizer *optSizer = new wxBoxSizer(wxVERTICAL);
1288   boxSizer->Add(optSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1289   wxStaticBox *sheetBox = new wxStaticBox(this, wxID_STATIC,
1290                                           wxT("Worksheet Selection"),
1291                                           wxDefaultPosition,
1292                                           wxDefaultSize);
1293   wxBoxSizer *sheetSizer = new wxStaticBoxSizer(sheetBox, wxHORIZONTAL);
1294   optSizer->Add(sheetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1295   wxListBox *sheetCtrl = new wxListBox(this, ID_LDXL_WORKSHEET,
1296                                        wxDefaultPosition, wxSize(400, 100),
1297                                        WorksheetCount, Worksheets,
1298                                        wxLB_SINGLE | wxLB_HSCROLL);
1299   sheetCtrl->SetFont(wxFont
1300                      (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
1301                       wxFONTWEIGHT_NORMAL));
1302   sheetCtrl->SetSelection(0);
1303   sheetSizer->Add(sheetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
1304 // fourth row: First Line Titles
1305   wxCheckBox *titleCtrl = new wxCheckBox(this, ID_LDXL_TITLES,
1306                                          wxT
1307                                          ("First line contains column names"),
1308                                          wxDefaultPosition, wxDefaultSize);
1309   titleCtrl->SetValue(false);
1310   optSizer->Add(titleCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1311 // OK - CANCEL buttons
1312   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
1313   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1314   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
1315   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1316   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
1317   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1318 // appends event handler for OK button
1319   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
1320           (wxObjectEventFunction) & LoadXLDialog::OnOk);
1321 }
1322 
GetWorksheets()1323 void LoadXLDialog::GetWorksheets()
1324 {
1325 // attempting to build the Worksheet List
1326 #ifndef OMIT_FREEXL             /* only if FreeXL is enabled */
1327   Invalid = true;
1328   Worksheets = NULL;
1329   WorksheetCount = 0;
1330   int ret;
1331   const void *xl_handle;
1332   char dummy[1024];
1333   unsigned int info;
1334   unsigned int idx;
1335   const char *utf8_string;
1336 
1337 // opening the .XLS file [Workbook]
1338   strcpy(dummy, Path.ToUTF8());
1339   ret = freexl_open_info(dummy, &xl_handle);
1340   if (ret != FREEXL_OK)
1341     goto error;
1342 // checking if Password protected
1343   ret = freexl_get_info(xl_handle, FREEXL_BIFF_PASSWORD, &info);
1344   if (ret != FREEXL_OK)
1345     goto error;
1346   if (info != FREEXL_BIFF_PLAIN)
1347     goto error;
1348 // Worksheet entries
1349   ret = freexl_get_info(xl_handle, FREEXL_BIFF_SHEET_COUNT, &info);
1350   if (ret != FREEXL_OK)
1351     goto error;
1352   if (info == 0)
1353     goto error;
1354 
1355   Worksheets = new wxString[info];
1356   WorksheetCount = info;
1357   for (idx = 0; idx < info; idx++)
1358     {
1359       // fetching Worksheets entries
1360       unsigned int rows;
1361       unsigned short columns;
1362 
1363       ret = freexl_get_worksheet_name(xl_handle, idx, &utf8_string);
1364       if (ret != FREEXL_OK)
1365         goto error;
1366       ret = freexl_select_active_worksheet(xl_handle, idx);
1367       if (ret != FREEXL_OK)
1368         goto error;
1369       ret = freexl_worksheet_dimensions(xl_handle, &rows, &columns);
1370       if (ret != FREEXL_OK)
1371         goto error;
1372       if (utf8_string == NULL)
1373         sprintf(dummy, "%3u] NULL (unnamed) [%urows / %ucols]\n", idx, rows,
1374                 columns);
1375       else
1376         sprintf(dummy, "%3u] %s [%urows / %ucols]\n", idx, utf8_string, rows,
1377                 columns);
1378       Worksheets[idx] = wxString::FromUTF8(dummy);
1379     }
1380   Invalid = false;
1381   freexl_close(xl_handle);
1382   return;
1383 
1384 error:
1385   freexl_close(xl_handle);
1386   if (Worksheets)
1387     delete[]Worksheets;
1388   Worksheets = new wxString[1];
1389   Worksheets[0] = wxT("ERROR: no Worksheet found");
1390   WorksheetCount = 1;
1391 #endif /* end FreeXL conditional support */
1392 }
1393 
OnOk(wxCommandEvent & WXUNUSED (event))1394 void LoadXLDialog::OnOk(wxCommandEvent & WXUNUSED(event))
1395 {
1396 //
1397 // all done:
1398 //
1399   if (Invalid)
1400     {
1401       wxMessageBox(wxT("You cannot confirm: INVALID XL datasource !!!"),
1402                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1403       return;
1404     }
1405   wxTextCtrl *tableCtrl = (wxTextCtrl *) FindWindow(ID_LDXL_TABLE);
1406   Table = tableCtrl->GetValue();
1407   if (Table.Len() < 1)
1408     {
1409       wxMessageBox(wxT("You must specify the TABLE NAME !!!"),
1410                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1411       return;
1412     }
1413   if (MainFrame->TableAlreadyExists(Table) == true)
1414     {
1415       wxMessageBox(wxT("a table name '") + Table + wxT("' already exists"),
1416                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1417       return;
1418     }
1419   wxListBox *sheetCtrl = (wxListBox *) FindWindow(ID_LDXL_WORKSHEET);
1420   int idSel = sheetCtrl->GetSelection();
1421   if (idSel == wxNOT_FOUND)
1422     {
1423       wxMessageBox(wxT("you must select some Worksheet from the list"),
1424                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1425       return;
1426     }
1427   WorksheetIndex = idSel;
1428   wxCheckBox *firstLineCtrl = (wxCheckBox *) FindWindow(ID_LDXL_TITLES);
1429   FirstLineTitles = firstLineCtrl->IsChecked();
1430   wxDialog::EndModal(wxID_OK);
1431 }
1432 
Create(MyFrame * parent,wxString & path)1433 bool LoadXmlDialog::Create(MyFrame * parent, wxString & path)
1434 {
1435 //
1436 // creating the dialog
1437 //
1438   MainFrame = parent;
1439   Path = path;
1440   Compressed = true;
1441   Validate = false;
1442   if (wxDialog::Create(parent, wxID_ANY, wxT("Loading an XML Document")) ==
1443       false)
1444     return false;
1445 // populates individual controls
1446   CreateControls();
1447 // sets dialog sizer
1448   GetSizer()->Fit(this);
1449   GetSizer()->SetSizeHints(this);
1450 // centers the dialog window
1451   Centre();
1452   return true;
1453 }
1454 
CreateControls()1455 void LoadXmlDialog::CreateControls()
1456 {
1457 //
1458 // creating individual control and setting initial values
1459 //
1460   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
1461   this->SetSizer(topSizer);
1462   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
1463   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1464 // first row: the Xml path
1465   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
1466   boxSizer->Add(pathSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1467   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
1468   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1469   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
1470                                          Path, wxDefaultPosition,
1471                                          wxSize(350, 22), wxTE_READONLY);
1472   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
1473 // second row: Compressed XmlBLOB
1474   wxBoxSizer *comprSizer = new wxBoxSizer(wxHORIZONTAL);
1475   boxSizer->Add(comprSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1476   wxCheckBox *compressedCtrl = new wxCheckBox(this, ID_LDXML_COMPRESSED,
1477                                               wxT("Compressed XML BLOB"),
1478                                               wxDefaultPosition, wxDefaultSize);
1479   compressedCtrl->SetValue(true);
1480   comprSizer->Add(compressedCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1481 // third row: Schema Validation
1482   wxStaticBox *schemaBox = new wxStaticBox(this, wxID_STATIC,
1483                                            wxT("Schema Validation"),
1484                                            wxDefaultPosition, wxDefaultSize);
1485   wxBoxSizer *validateSizer = new wxStaticBoxSizer(schemaBox, wxVERTICAL);
1486   boxSizer->Add(validateSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1487   wxBoxSizer *valSizer = new wxBoxSizer(wxHORIZONTAL);
1488   validateSizer->Add(valSizer, 0, wxALIGN_LEFT | wxALL, 0);
1489   wxCheckBox *validateCtrl = new wxCheckBox(this, ID_LDXML_VALIDATE,
1490                                             wxT("Apply Schema Validation"),
1491                                             wxDefaultPosition, wxDefaultSize);
1492   validateCtrl->SetValue(false);
1493   valSizer->Add(validateCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1494   wxBoxSizer *schemaUriSizer = new wxBoxSizer(wxHORIZONTAL);
1495   validateSizer->Add(schemaUriSizer, 0, wxALIGN_LEFT | wxALL, 0);
1496   wxStaticText *schemaLabel =
1497     new wxStaticText(this, wxID_STATIC, wxT("&Schema URI:"));
1498   schemaUriSizer->Add(schemaLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1499   wxTextCtrl *schemaUriValue = new wxTextCtrl(this, ID_LDXML_SCHEMA_URI,
1500                                               wxT(""), wxDefaultPosition,
1501                                               wxSize(350, 22));
1502   schemaUriValue->Enable(false);
1503   schemaUriSizer->Add(schemaUriValue, 0, wxALIGN_RIGHT | wxALL, 5);
1504 // OK - CANCEL buttons
1505   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
1506   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1507   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
1508   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1509   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
1510   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1511 // appends event handler for OK button
1512   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
1513           (wxObjectEventFunction) & LoadXmlDialog::OnOk);
1514   Connect(ID_LDXML_COMPRESSED, wxEVT_COMMAND_CHECKBOX_CLICKED,
1515           (wxObjectEventFunction) & LoadXmlDialog::OnCompressionChanged);
1516   Connect(ID_LDXML_VALIDATE, wxEVT_COMMAND_CHECKBOX_CLICKED,
1517           (wxObjectEventFunction) & LoadXmlDialog::OnValidationChanged);
1518 }
1519 
OnCompressionChanged(wxCommandEvent & WXUNUSED (event))1520 void LoadXmlDialog::OnCompressionChanged(wxCommandEvent & WXUNUSED(event))
1521 {
1522 //
1523 // changed Compressed (on/off):
1524 //
1525   wxCheckBox *compressedCtrl = (wxCheckBox *) FindWindow(ID_LDXML_COMPRESSED);
1526   if (compressedCtrl->IsChecked() == true)
1527     Compressed = true;
1528   else
1529     Compressed = false;
1530 }
1531 
OnValidationChanged(wxCommandEvent & WXUNUSED (event))1532 void LoadXmlDialog::OnValidationChanged(wxCommandEvent & WXUNUSED(event))
1533 {
1534 //
1535 // changed Schema Validation (on/off):
1536 //
1537   wxCheckBox *validateCtrl = (wxCheckBox *) FindWindow(ID_LDXML_VALIDATE);
1538   wxTextCtrl *schemaUriCtrl = (wxTextCtrl *) FindWindow(ID_LDXML_SCHEMA_URI);
1539   if (validateCtrl->IsChecked())
1540     schemaUriCtrl->Enable(true);
1541   else
1542     {
1543       SchemaURI = wxT("");
1544       schemaUriCtrl->SetValue(SchemaURI);
1545       schemaUriCtrl->Enable(false);
1546     }
1547 }
1548 
OnOk(wxCommandEvent & WXUNUSED (event))1549 void LoadXmlDialog::OnOk(wxCommandEvent & WXUNUSED(event))
1550 {
1551 //
1552 // all done:
1553 //
1554   wxCheckBox *validateCtrl = (wxCheckBox *) FindWindow(ID_LDXML_VALIDATE);
1555   if (validateCtrl->IsChecked())
1556     {
1557       wxTextCtrl *schemaUriCtrl =
1558         (wxTextCtrl *) FindWindow(ID_LDXML_SCHEMA_URI);
1559       wxString schemaUri = schemaUriCtrl->GetValue().Trim(false);
1560       SchemaURI = schemaUri.Trim(true);
1561       if (SchemaURI.Len() < 1)
1562         {
1563           wxMessageBox(wxT("You must specify some Schema URI !!!"),
1564                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1565           return;
1566         }
1567     }
1568   wxDialog::EndModal(wxID_OK);
1569 }
1570 
Create(MyFrame * parent,wxString & path,wxString & table,wxString & defCs)1571 bool LoadTxtDialog::Create(MyFrame * parent, wxString & path, wxString & table,
1572                            wxString & defCs)
1573 {
1574 //
1575 // creating the dialog
1576 //
1577   MainFrame = parent;
1578   Path = path;
1579   Table = table;
1580   Default = defCs;
1581   if (wxDialog::Create(parent, wxID_ANY, wxT("Load CSV/TXT")) == false)
1582     return false;
1583 // populates individual controls
1584   CreateControls();
1585 // sets dialog sizer
1586   GetSizer()->Fit(this);
1587   GetSizer()->SetSizeHints(this);
1588 // centers the dialog window
1589   Centre();
1590   return true;
1591 }
1592 
CreateControls()1593 void LoadTxtDialog::CreateControls()
1594 {
1595 //
1596 // creating individual control and setting initial values
1597 //
1598   FirstLineTitles = true;
1599   Separator = '\t';
1600   TextSeparator = '"';
1601   DecimalPointIsComma = false;
1602   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
1603   this->SetSizer(topSizer);
1604   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
1605   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1606 // first row: the CSV/TXT path
1607   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
1608   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
1609   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
1610   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1611   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
1612                                          Path, wxDefaultPosition,
1613                                          wxSize(350, 22), wxTE_READONLY);
1614   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
1615 // second row: TABLE name
1616   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
1617   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
1618   wxStaticText *tableLabel =
1619     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
1620   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1621   wxTextCtrl *tableCtrl = new wxTextCtrl(this, ID_LDTXT_TABLE, Table,
1622                                          wxDefaultPosition, wxSize(350,
1623                                                                    22));
1624   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
1625 // second row: OPTIONS
1626   wxBoxSizer *optSizer = new wxBoxSizer(wxHORIZONTAL);
1627   boxSizer->Add(optSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1628   wxBoxSizer *modeSizer = new wxBoxSizer(wxVERTICAL);
1629   optSizer->Add(modeSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
1630   wxBoxSizer *mode1Sizer = new wxBoxSizer(wxHORIZONTAL);
1631   modeSizer->Add(mode1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1632   wxCheckBox *titleCtrl = new wxCheckBox(this, ID_LDTXT_TITLES,
1633                                          wxT
1634                                          ("First line contains column names"),
1635                                          wxDefaultPosition, wxDefaultSize);
1636   titleCtrl->SetValue(true);
1637   mode1Sizer->Add(titleCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1638   wxStaticBox *sepBox = new wxStaticBox(this, wxID_STATIC,
1639                                         wxT("Separators"),
1640                                         wxDefaultPosition, wxDefaultSize);
1641   wxBoxSizer *sepSizer = new wxStaticBoxSizer(sepBox, wxVERTICAL);
1642   modeSizer->Add(sepSizer, 0, wxALIGN_LEFT | wxALL, 0);
1643   wxBoxSizer *mode2Sizer = new wxBoxSizer(wxHORIZONTAL);
1644   sepSizer->Add(mode2Sizer, 0, wxALIGN_LEFT | wxALL, 0);
1645   wxString quotes[3];
1646   quotes[0] = wxT("&Double \"");
1647   quotes[1] = wxT("&Single '");
1648   quotes[2] = wxT("&None");
1649   wxRadioBox *textSeparatorBox = new wxRadioBox(this, ID_LDTXT_QUOTE,
1650                                                 wxT("&Text separator: quotes"),
1651                                                 wxDefaultPosition,
1652                                                 wxDefaultSize, 3,
1653                                                 quotes, 3,
1654                                                 wxRA_SPECIFY_COLS);
1655   mode2Sizer->Add(textSeparatorBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1656   wxBoxSizer *mode3Sizer = new wxBoxSizer(wxHORIZONTAL);
1657   sepSizer->Add(mode3Sizer, 0, wxALIGN_LEFT | wxALL, 0);
1658   wxString separators[6];
1659   separators[0] = wxT("&Tab");
1660   separators[1] = wxT("&Space");
1661   separators[2] = wxT("Co&mma ,");
1662   separators[3] = wxT("&Colon :");
1663   separators[4] = wxT("S&emicolon ;");
1664   separators[5] = wxT("&Other");
1665   wxRadioBox *separatorBox = new wxRadioBox(this, ID_LDTXT_SEPARATOR,
1666                                             wxT("&Column separator"),
1667                                             wxDefaultPosition, wxDefaultSize,
1668                                             6,
1669                                             separators, 2,
1670                                             wxRA_SPECIFY_COLS);
1671   mode3Sizer->Add(separatorBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1672   wxBoxSizer *mode4Sizer = new wxBoxSizer(wxHORIZONTAL);
1673   sepSizer->Add(mode4Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1674   wxStaticText *charSeparatorLabel = new wxStaticText(this, wxID_STATIC,
1675                                                       wxT("&Custom separator:"),
1676                                                       wxDefaultPosition,
1677                                                       wxDefaultSize, 0);
1678   mode4Sizer->Add(charSeparatorLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1679   wxTextCtrl *dummy =
1680     new wxTextCtrl(this, ID_LDTXT_CHARSEPARATOR, wxT("Dummy Text pq"),
1681                    wxDefaultPosition,
1682                    wxDefaultSize, 0);
1683   wxSize sz = dummy->GetSize();
1684   delete dummy;
1685   sz.SetWidth(40);
1686   wxTextCtrl *charSeparatorCtrl =
1687     new wxTextCtrl(this, ID_LDTXT_CHARSEPARATOR, wxT("TAB"),
1688                    wxDefaultPosition, sz, 0);
1689   charSeparatorCtrl->SetMaxLength(1);
1690   charSeparatorCtrl->Enable(false);
1691   mode4Sizer->Add(charSeparatorCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1692   wxBoxSizer *mode5Sizer = new wxBoxSizer(wxHORIZONTAL);
1693   sepSizer->Add(mode5Sizer, 0, wxALIGN_LEFT | wxALL, 0);
1694   wxString points[2];
1695   points[0] = wxT("&Point .");
1696   points[1] = wxT("&Comma ,");
1697   wxRadioBox *decimalSeparatorBox = new wxRadioBox(this, ID_LDTXT_POINT,
1698                                                    wxT("&Decimal separator"),
1699                                                    wxDefaultPosition,
1700                                                    wxDefaultSize, 2,
1701                                                    points, 2,
1702                                                    wxRA_SPECIFY_COLS);
1703   mode5Sizer->Add(decimalSeparatorBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1704 // third row: CHARSET
1705   wxStaticBox *charsetBox = new wxStaticBox(this, wxID_STATIC,
1706                                             wxT("Charset Encoding"),
1707                                             wxDefaultPosition,
1708                                             wxDefaultSize);
1709   wxBoxSizer *charsetSizer = new wxStaticBoxSizer(charsetBox, wxHORIZONTAL);
1710   optSizer->Add(charsetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1711   wxListBox *charsetCtrl = new wxListBox(this, ID_LDTXT_CHARSET,
1712                                          wxDefaultPosition, wxDefaultSize,
1713                                          MainFrame->GetCharsetsLen(),
1714                                          MainFrame->GetCharsetsNames(),
1715                                          wxLB_SINGLE | wxLB_HSCROLL);
1716   charsetCtrl->SetFont(wxFont
1717                        (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
1718                         wxFONTWEIGHT_NORMAL));
1719   int idSel = MainFrame->GetCharsetIndex(Default);
1720   if (idSel != wxNOT_FOUND)
1721     charsetCtrl->SetSelection(idSel);
1722   charsetSizer->Add(charsetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
1723 // OK - CANCEL buttons
1724   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
1725   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1726   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
1727   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1728   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
1729   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1730 // appends event handler for OK button
1731   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
1732           (wxObjectEventFunction) & LoadTxtDialog::OnOk);
1733 // appends event handler for radioboxes
1734   Connect(ID_LDTXT_QUOTE, wxEVT_COMMAND_RADIOBOX_SELECTED,
1735           (wxObjectEventFunction) & LoadTxtDialog::OnQuote);
1736   Connect(ID_LDTXT_SEPARATOR, wxEVT_COMMAND_RADIOBOX_SELECTED,
1737           (wxObjectEventFunction) & LoadTxtDialog::OnSeparator);
1738   Connect(ID_LDTXT_POINT, wxEVT_COMMAND_RADIOBOX_SELECTED,
1739           (wxObjectEventFunction) & LoadTxtDialog::OnDecimalSeparator);
1740 }
1741 
OnDecimalSeparator(wxCommandEvent & WXUNUSED (event))1742 void LoadTxtDialog::OnDecimalSeparator(wxCommandEvent & WXUNUSED(event))
1743 {
1744 //
1745 // POINT selection changed
1746 //
1747   wxRadioBox *decimalSeparatorCtrl = (wxRadioBox *) FindWindow(ID_LDTXT_POINT);
1748   switch (decimalSeparatorCtrl->GetSelection())
1749     {
1750       case 0:
1751         DecimalPointIsComma = false;
1752         break;
1753       case 1:
1754         DecimalPointIsComma = true;
1755         break;
1756     };
1757 }
1758 
OnQuote(wxCommandEvent & WXUNUSED (event))1759 void LoadTxtDialog::OnQuote(wxCommandEvent & WXUNUSED(event))
1760 {
1761 //
1762 // QUOTE selection changed
1763 //
1764   wxRadioBox *separatorCtrl = (wxRadioBox *) FindWindow(ID_LDTXT_QUOTE);
1765   switch (separatorCtrl->GetSelection())
1766     {
1767       case 0:
1768         TextSeparator = '"';
1769         break;
1770       case 1:
1771         TextSeparator = '\'';
1772         break;
1773       case 2:
1774         TextSeparator = '\0';
1775         break;
1776     };
1777 }
1778 
OnSeparator(wxCommandEvent & WXUNUSED (event))1779 void LoadTxtDialog::OnSeparator(wxCommandEvent & WXUNUSED(event))
1780 {
1781 //
1782 // SEPARATOR selection changed
1783 //
1784   wxTextCtrl *charSeparatorCtrl =
1785     (wxTextCtrl *) FindWindow(ID_LDTXT_CHARSEPARATOR);
1786   wxRadioBox *separatorCtrl = (wxRadioBox *) FindWindow(ID_LDTXT_SEPARATOR);
1787   switch (separatorCtrl->GetSelection())
1788     {
1789       case 0:
1790         Separator = '\t';
1791         charSeparatorCtrl->SetValue(wxT("TAB"));
1792         break;
1793       case 1:
1794         Separator = ' ';
1795         charSeparatorCtrl->SetValue(wxT("SP"));
1796         break;
1797       case 2:
1798         Separator = ',';
1799         charSeparatorCtrl->SetValue(wxT(","));
1800         break;
1801       case 3:
1802         Separator = ':';
1803         charSeparatorCtrl->SetValue(wxT(":"));
1804         break;
1805       case 4:
1806         Separator = ';';
1807         charSeparatorCtrl->SetValue(wxT(";"));
1808         break;
1809       case 5:
1810         Separator = '|';
1811         charSeparatorCtrl->SetValue(wxT("|"));
1812         break;
1813     };
1814   if (separatorCtrl->GetSelection() == 5)
1815     charSeparatorCtrl->Enable(true);
1816   else
1817     charSeparatorCtrl->Enable(false);
1818 }
1819 
OnOk(wxCommandEvent & WXUNUSED (event))1820 void LoadTxtDialog::OnOk(wxCommandEvent & WXUNUSED(event))
1821 {
1822 //
1823 // all done:
1824 //
1825   wxCheckBox *firstLineCtrl = (wxCheckBox *) FindWindow(ID_LDTXT_TITLES);
1826   FirstLineTitles = firstLineCtrl->IsChecked();
1827   wxTextCtrl *tableCtrl = (wxTextCtrl *) FindWindow(ID_LDTXT_TABLE);
1828   Table = tableCtrl->GetValue();
1829   if (Table.Len() < 1)
1830     {
1831       wxMessageBox(wxT("You must specify the TABLE NAME !!!"),
1832                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1833       return;
1834     }
1835   if (MainFrame->TableAlreadyExists(Table) == true)
1836     {
1837       wxMessageBox(wxT("a table name '") + Table + wxT("' already exists"),
1838                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1839       return;
1840     }
1841   wxListBox *charsetCtrl = (wxListBox *) FindWindow(ID_LDTXT_CHARSET);
1842   int idSel = charsetCtrl->GetSelection();
1843   if (idSel == wxNOT_FOUND)
1844     {
1845       wxMessageBox(wxT("you must select some Charset Encoding from the list"),
1846                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1847       return;
1848     }
1849   wxString *charsets = MainFrame->GetCharsets();
1850   Charset = *(charsets + idSel);
1851   wxRadioBox *separatorCtrl = (wxRadioBox *) FindWindow(ID_LDTXT_SEPARATOR);
1852   if (separatorCtrl->GetSelection() == 5)
1853     {
1854       wxTextCtrl *charSeparatorCtrl =
1855         (wxTextCtrl *) FindWindow(ID_LDTXT_CHARSEPARATOR);
1856       wxString separator = charSeparatorCtrl->GetValue();
1857       if (separator.Len() != 1)
1858         {
1859           wxMessageBox(wxT
1860                        ("you must specificy a single char as Custom Column Separator"),
1861                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
1862           return;
1863         }
1864       char dummy[64];
1865       strcpy(dummy, separator.ToUTF8());
1866       Separator = *dummy;
1867     }
1868   wxDialog::EndModal(wxID_OK);
1869 }
1870 
~LoadDbfDialog()1871 LoadDbfDialog::~LoadDbfDialog()
1872 {
1873 // destructor
1874   if (PKFields != NULL)
1875     delete[]PKFields;
1876   if (PKFieldsEx != NULL)
1877     delete[]PKFieldsEx;
1878 }
1879 
1880 
Create(MyFrame * parent,wxString & path,wxString & table,wxString & defCs)1881 bool LoadDbfDialog::Create(MyFrame * parent, wxString & path, wxString & table,
1882                            wxString & defCs)
1883 {
1884 //
1885 // creating the dialog
1886 //
1887   MainFrame = parent;
1888   Path = path;
1889   Table = table;
1890   Default = defCs;
1891   PKCount = 0;
1892   PKFields = NULL;
1893   PKFieldsEx = NULL;
1894   LoadPKFields();
1895   if (wxDialog::Create(parent, wxID_ANY, wxT("Load DBF")) == false)
1896     return false;
1897 // populates individual controls
1898   CreateControls();
1899 // sets dialog sizer
1900   GetSizer()->Fit(this);
1901   GetSizer()->SetSizeHints(this);
1902 // centers the dialog window
1903   Centre();
1904   return true;
1905 }
1906 
CreateControls()1907 void LoadDbfDialog::CreateControls()
1908 {
1909 //
1910 // creating individual control and setting initial values
1911 //
1912   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
1913   this->SetSizer(topSizer);
1914   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
1915   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1916 // first row: the DBF path
1917   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
1918   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
1919   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
1920   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1921   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
1922                                          Path, wxDefaultPosition,
1923                                          wxSize(350, 22), wxTE_READONLY);
1924   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
1925 // second row: TABLE name
1926   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
1927   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
1928   wxStaticText *tableLabel =
1929     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
1930   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1931   wxTextCtrl *tableCtrl = new wxTextCtrl(this, ID_LDDBF_TABLE, Table,
1932                                          wxDefaultPosition, wxSize(350,
1933                                                                    22));
1934   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
1935 // third row: CHARSET
1936   wxBoxSizer *optSizer = new wxBoxSizer(wxHORIZONTAL);
1937   boxSizer->Add(optSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1938   wxStaticBox *charsetBox = new wxStaticBox(this, wxID_STATIC,
1939                                             wxT("Charset Encoding"),
1940                                             wxDefaultPosition,
1941                                             wxDefaultSize);
1942   wxBoxSizer *charsetSizer = new wxStaticBoxSizer(charsetBox, wxHORIZONTAL);
1943   optSizer->Add(charsetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
1944   wxListBox *charsetCtrl = new wxListBox(this, ID_LDDBF_CHARSET,
1945                                          wxDefaultPosition, wxDefaultSize,
1946                                          MainFrame->GetCharsetsLen(),
1947                                          MainFrame->GetCharsetsNames(),
1948                                          wxLB_SINGLE | wxLB_HSCROLL);
1949   charsetCtrl->SetFont(wxFont
1950                        (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
1951                         wxFONTWEIGHT_NORMAL));
1952   int idSel = MainFrame->GetCharsetIndex(Default);
1953   if (idSel != wxNOT_FOUND)
1954     charsetCtrl->SetSelection(idSel);
1955   charsetSizer->Add(charsetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
1956 // User Defined Primary Key
1957   wxBoxSizer *userdefBox = new wxBoxSizer(wxHORIZONTAL);
1958   boxSizer->Add(userdefBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1959   wxStaticBox *userPKeyBox = new wxStaticBox(this, wxID_STATIC,
1960                                              wxT("Primary Key Column"),
1961                                              wxDefaultPosition,
1962                                              wxDefaultSize);
1963   wxBoxSizer *gPKeySizer = new wxStaticBoxSizer(userPKeyBox, wxVERTICAL);
1964   userdefBox->Add(gPKeySizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
1965   wxString pkey_selection[2];
1966   pkey_selection[0] = wxT("Automatic");
1967   pkey_selection[1] = wxT("User specified");
1968   wxRadioBox *gpkey_sel = new wxRadioBox(this, ID_LDDBF_USER_PKEY,
1969                                          wxT("&Mode"),
1970                                          wxDefaultPosition,
1971                                          wxDefaultSize, 2,
1972                                          pkey_selection, 2,
1973                                          wxRA_SPECIFY_COLS);
1974   gpkey_sel->SetSelection(0);
1975   gPKeySizer->Add(gpkey_sel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
1976   wxComboBox *pkeyList =
1977     new wxComboBox(this, ID_LDDBF_PKCOL, wxT(""), wxDefaultPosition,
1978                    wxSize(180, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
1979   pkeyList->Enable(false);
1980   gPKeySizer->Add(pkeyList, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1981 // OK - CANCEL buttons
1982   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
1983   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
1984   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
1985   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1986   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
1987   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1988 // appends event handler for OK button
1989   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
1990           (wxObjectEventFunction) & LoadDbfDialog::OnOk);
1991   Connect(ID_LDDBF_USER_PKEY, wxEVT_COMMAND_RADIOBOX_SELECTED,
1992           (wxObjectEventFunction) & LoadDbfDialog::OnUserPKey);
1993 }
1994 
1995 
LoadPKFields()1996 void LoadDbfDialog::LoadPKFields()
1997 {
1998 // loading the Primary Key Fields list
1999   char dbf_path[1024];
2000   char charset[1024];
2001   char dummy[1024];
2002   wxString dummyName;
2003   int cnt;
2004   int seed;
2005   int dup;
2006   int idup;
2007   wxString *charsets = MainFrame->GetCharsets();
2008   wxString cs;
2009   int idSel = MainFrame->GetCharsetIndex(Default);
2010   gaiaDbfPtr dbf = NULL;
2011   gaiaDbfFieldPtr dbf_field;
2012   if (PKFields != NULL)
2013     delete[]PKFields;
2014   PKFields = NULL;
2015   PKCount = 0;
2016 
2017 // opening the DBF in order to fetch field names
2018   dbf = gaiaAllocDbf();
2019   strcpy(dbf_path, Path.ToUTF8());
2020   cs = *(charsets + idSel);
2021   strcpy(charset, cs.ToUTF8());
2022   gaiaOpenDbfRead(dbf, dbf_path, charset, "UTF-8");
2023   if (!(dbf->Valid))
2024     {
2025       gaiaFreeDbf(dbf);
2026       return;
2027     }
2028 /* checking for duplicate / illegal column names and antialising them */
2029   dbf_field = dbf->Dbf->First;
2030   while (dbf_field)
2031     {
2032       /* counting DBF fields */
2033       PKCount++;
2034       dbf_field = dbf_field->Next;
2035     }
2036   PKFields = new wxString[PKCount];
2037   PKFieldsEx = new wxString[PKCount];
2038   cnt = 0;
2039   seed = 0;
2040   dbf_field = dbf->Dbf->First;
2041   while (dbf_field)
2042     {
2043       /* preparing column names */
2044       dummyName = wxString::FromUTF8(dbf_field->Name);
2045       dup = 0;
2046       for (idup = 0; idup < cnt; idup++)
2047         {
2048           if (dummyName == PKFields[idup])
2049             dup = 1;
2050         }
2051       if (dummyName == wxString::FromUTF8("PK_UID"))
2052         dup = 1;
2053       if (dup)
2054         {
2055           sprintf(dummy, "COL_%d", seed++);
2056           dummyName = wxString::FromUTF8(dummy);
2057         }
2058       PKFields[cnt] = dummyName;
2059       PKFieldsEx[cnt] = dummyName;
2060       dummyName = wxT(" [TEXT]");
2061       switch (dbf_field->Type)
2062         {
2063           case 'N':
2064             if (dbf_field->Decimals)
2065               dummyName = wxT(" [DOUBLE]");
2066             else
2067               {
2068                 if (dbf_field->Length <= 18)
2069                   dummyName = wxT(" [INTEGER]");
2070                 else
2071                   dummyName = wxT(" [DOUBLE]");
2072               }
2073             break;
2074           case 'D':
2075             dummyName = wxT(" [DOUBLE]");
2076             break;
2077           case 'F':
2078             dummyName = wxT(" [DOUBLE]");
2079             break;
2080           case 'L':
2081             dummyName = wxT(" [INTEGER]");
2082             break;
2083         };
2084       PKFieldsEx[cnt] += dummyName;
2085       cnt++;
2086       dbf_field = dbf_field->Next;
2087     }
2088 
2089 // memory cleanup
2090   gaiaFreeDbf(dbf);
2091 }
2092 
OnUserPKey(wxCommandEvent & WXUNUSED (event))2093 void LoadDbfDialog::OnUserPKey(wxCommandEvent & WXUNUSED(event))
2094 {
2095 //
2096 // the mode of user defined Primary Key Column changed
2097 //
2098   wxRadioBox *radioCtrl = (wxRadioBox *) FindWindow(ID_LDDBF_USER_PKEY);
2099   wxComboBox *comboCtrl = (wxComboBox *) FindWindow(ID_LDDBF_PKCOL);
2100   if (radioCtrl->GetSelection() == 0)
2101     {
2102       // automatic
2103       comboCtrl->Clear();
2104       comboCtrl->Enable(false);
2105   } else
2106     {
2107       // user specified
2108       int i;
2109       for (i = 0; i < PKCount; i++)
2110         {
2111           // setting PK Fields
2112           wxString str = PKFieldsEx[i];
2113           comboCtrl->Append(str);
2114         }
2115       comboCtrl->Enable(true);
2116       comboCtrl->SetSelection(wxNOT_FOUND);
2117     }
2118 }
2119 
2120 
OnOk(wxCommandEvent & WXUNUSED (event))2121 void LoadDbfDialog::OnOk(wxCommandEvent & WXUNUSED(event))
2122 {
2123 //
2124 // all done:
2125 //
2126   wxTextCtrl *tableCtrl = (wxTextCtrl *) FindWindow(ID_LDDBF_TABLE);
2127   Table = tableCtrl->GetValue();
2128   if (Table.Len() < 1)
2129     {
2130       wxMessageBox(wxT("You must specify the TABLE NAME !!!"),
2131                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2132       return;
2133     }
2134   if (MainFrame->TableAlreadyExists(Table) == true)
2135     {
2136       wxMessageBox(wxT("a table name '") + Table + wxT("' already exists"),
2137                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2138       return;
2139     }
2140   wxListBox *charsetCtrl = (wxListBox *) FindWindow(ID_LDDBF_CHARSET);
2141   int idSel = charsetCtrl->GetSelection();
2142   if (idSel == wxNOT_FOUND)
2143     {
2144       wxMessageBox(wxT("you must select some Charset Encoding from the list"),
2145                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2146       return;
2147     }
2148   wxString *charsets = MainFrame->GetCharsets();
2149   Charset = *(charsets + idSel);
2150   wxRadioBox *radioCtrl = (wxRadioBox *) FindWindow(ID_LDDBF_USER_PKEY);
2151   wxComboBox *comboCtrl = (wxComboBox *) FindWindow(ID_LDDBF_PKCOL);
2152   if (radioCtrl->GetSelection() == 0)
2153     {
2154       // automatic
2155       UserDefinedPKey = false;
2156       PKColumn = wxT("");
2157   } else
2158     {
2159       // user specified
2160       idSel = comboCtrl->GetSelection();
2161       if (idSel == wxNOT_FOUND)
2162         {
2163           wxMessageBox(wxT
2164                        ("you must select some User defined Primary Key Column from the list"),
2165                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2166           return;
2167         }
2168       UserDefinedPKey = true;
2169       PKColumn = PKFields[idSel];
2170     }
2171   wxDialog::EndModal(wxID_OK);
2172 }
2173 
~LoadShpDialog()2174 LoadShpDialog::~LoadShpDialog()
2175 {
2176 // destructor
2177   if (PKFields != NULL)
2178     delete[]PKFields;
2179   if (PKFieldsEx != NULL)
2180     delete[]PKFieldsEx;
2181 }
2182 
Create(MyFrame * parent,wxString & path,wxString & table,int srid,wxString & column,wxString & defCs)2183 bool LoadShpDialog::Create(MyFrame * parent, wxString & path, wxString & table,
2184                            int srid, wxString & column, wxString & defCs)
2185 {
2186 //
2187 // creating the dialog
2188 //
2189   MainFrame = parent;
2190   Path = path;
2191   Table = table;
2192   Srid = srid;
2193   Column = column;
2194   Default = defCs;
2195   Coerce2D = false;
2196   Compressed = false;
2197   SpatialIndex = false;
2198   PKCount = 0;
2199   PKFields = NULL;
2200   PKFieldsEx = NULL;
2201   LoadPKFields();
2202   if (wxDialog::Create(parent, wxID_ANY, wxT("Load Shapefile")) == false)
2203     return false;
2204 // populates individual controls
2205   CreateControls();
2206 // sets dialog sizer
2207   GetSizer()->Fit(this);
2208   GetSizer()->SetSizeHints(this);
2209 // centers the dialog window
2210   Centre();
2211   return true;
2212 }
2213 
CreateControls()2214 void LoadShpDialog::CreateControls()
2215 {
2216 //
2217 // creating individual control and setting initial values
2218 //
2219   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
2220   this->SetSizer(topSizer);
2221   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
2222   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2223 // first row: the Shapefile path
2224   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
2225   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
2226   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
2227   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2228   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
2229                                          Path, wxDefaultPosition,
2230                                          wxSize(350, 22), wxTE_READONLY);
2231   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 1);
2232 // second row: TABLE name
2233   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
2234   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
2235   wxStaticText *tableLabel =
2236     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
2237   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2238   wxTextCtrl *tableCtrl = new wxTextCtrl(this, ID_LDSHP_TABLE, Table,
2239                                          wxDefaultPosition, wxSize(350,
2240                                                                    22));
2241   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 1);
2242 // third row: GEOMETRY COLUMN name
2243   wxBoxSizer *colSizer = new wxBoxSizer(wxHORIZONTAL);
2244   boxSizer->Add(colSizer, 0, wxALIGN_RIGHT | wxALL, 0);
2245   wxStaticText *colLabel =
2246     new wxStaticText(this, wxID_STATIC, wxT("&GeomColumn name:"));
2247   colSizer->Add(colLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2248   wxTextCtrl *colCtrl = new wxTextCtrl(this, ID_LDSHP_COLUMN, Column,
2249                                        wxDefaultPosition, wxSize(350, 22));
2250   colSizer->Add(colCtrl, 0, wxALIGN_RIGHT | wxALL, 1);
2251 // fourth row: SRID
2252   wxBoxSizer *sridSizer = new wxBoxSizer(wxHORIZONTAL);
2253   boxSizer->Add(sridSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2254   wxStaticText *sridLabel = new wxStaticText(this, wxID_STATIC, wxT("&SRID:"));
2255   sridSizer->Add(sridLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2256   wxSpinCtrl *sridCtrl = new wxSpinCtrl(this, ID_LDSHP_SRID, wxEmptyString,
2257                                         wxDefaultPosition, wxSize(80, 20),
2258                                         wxSP_ARROW_KEYS,
2259                                         -1, 1000000, Srid);
2260   sridSizer->Add(sridCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2261 // fifth row: CHARSET
2262   wxStaticBox *charsetBox = new wxStaticBox(this, wxID_STATIC,
2263                                             wxT("Charset Encoding"),
2264                                             wxDefaultPosition,
2265                                             wxDefaultSize);
2266   wxBoxSizer *charsetSizer = new wxStaticBoxSizer(charsetBox, wxHORIZONTAL);
2267   sridSizer->Add(charsetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2268   wxListBox *charsetCtrl = new wxListBox(this, ID_LDSHP_CHARSET,
2269                                          wxDefaultPosition, wxDefaultSize,
2270                                          MainFrame->GetCharsetsLen(),
2271                                          MainFrame->GetCharsetsNames(),
2272                                          wxLB_SINGLE | wxLB_HSCROLL);
2273   charsetCtrl->SetFont(wxFont
2274                        (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
2275                         wxFONTWEIGHT_NORMAL));
2276   int idSel = MainFrame->GetCharsetIndex(Default);
2277   if (idSel != wxNOT_FOUND)
2278     charsetCtrl->SetSelection(idSel);
2279   charsetSizer->Add(charsetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
2280 // 2D + Compress
2281   wxBoxSizer *compressBox = new wxBoxSizer(wxHORIZONTAL);
2282   boxSizer->Add(compressBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2283   wxStaticBox *storageBox = new wxStaticBox(this, wxID_STATIC,
2284                                             wxT("Geometry storage"),
2285                                             wxDefaultPosition,
2286                                             wxDefaultSize);
2287   wxBoxSizer *storageSizer = new wxStaticBoxSizer(storageBox, wxHORIZONTAL);
2288   compressBox->Add(storageSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2289   wxCheckBox *coerce2DCtrl = new wxCheckBox(this, ID_LDSHP_COERCE_2D,
2290                                             wxT("Coerce 2D geometries [x,y]"),
2291                                             wxDefaultPosition, wxDefaultSize);
2292   coerce2DCtrl->SetValue(Coerce2D);
2293   storageSizer->Add(coerce2DCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2294   wxCheckBox *compressCtrl = new wxCheckBox(this, ID_LDSHP_COMPRESSED,
2295                                             wxT("Apply geometry compression"),
2296                                             wxDefaultPosition, wxDefaultSize);
2297   compressCtrl->SetValue(Compressed);
2298   storageSizer->Add(compressCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2299   wxCheckBox *rtreeCtrl = new wxCheckBox(this, ID_LDSHP_RTREE,
2300                                          wxT("With Spatial Index (R*Tree)"),
2301                                          wxDefaultPosition, wxDefaultSize);
2302   rtreeCtrl->SetValue(SpatialIndex);
2303   storageSizer->Add(rtreeCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2304   wxStaticBox *userGTypeBox = new wxStaticBox(this, wxID_STATIC,
2305                                               wxT("Geometry Type"),
2306                                               wxDefaultPosition,
2307                                               wxDefaultSize);
2308 // User Defined Geometry Type
2309   wxBoxSizer *userdefBox = new wxBoxSizer(wxHORIZONTAL);
2310   boxSizer->Add(userdefBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2311   wxBoxSizer *gTypeSizer = new wxStaticBoxSizer(userGTypeBox, wxVERTICAL);
2312   userdefBox->Add(gTypeSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2313   wxString gtype_selection[2];
2314   gtype_selection[0] = wxT("Automatic");
2315   gtype_selection[1] = wxT("User specified");
2316   wxRadioBox *gtyp_sel = new wxRadioBox(this, ID_LDSHP_USER_GTYPE,
2317                                         wxT("&Mode"),
2318                                         wxDefaultPosition,
2319                                         wxDefaultSize, 2,
2320                                         gtype_selection, 2,
2321                                         wxRA_SPECIFY_COLS);
2322   gtyp_sel->SetSelection(0);
2323   gTypeSizer->Add(gtyp_sel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2324   wxComboBox *typeList =
2325     new wxComboBox(this, ID_LDSHP_GTYPE, wxT(""), wxDefaultPosition,
2326                    wxSize(180, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
2327   typeList->Enable(false);
2328   gTypeSizer->Add(typeList, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2329 // User Defined Primary Key
2330   wxStaticBox *userPKeyBox = new wxStaticBox(this, wxID_STATIC,
2331                                              wxT("Primary Key Column"),
2332                                              wxDefaultPosition,
2333                                              wxDefaultSize);
2334   wxBoxSizer *gPKeySizer = new wxStaticBoxSizer(userPKeyBox, wxVERTICAL);
2335   userdefBox->Add(gPKeySizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2336   wxString pkey_selection[2];
2337   pkey_selection[0] = wxT("Automatic");
2338   pkey_selection[1] = wxT("User specified");
2339   wxRadioBox *gpkey_sel = new wxRadioBox(this, ID_LDSHP_USER_PKEY,
2340                                          wxT("&Mode"),
2341                                          wxDefaultPosition,
2342                                          wxDefaultSize, 2,
2343                                          pkey_selection, 2,
2344                                          wxRA_SPECIFY_COLS);
2345   gpkey_sel->SetSelection(0);
2346   gPKeySizer->Add(gpkey_sel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2347   wxComboBox *pkeyList =
2348     new wxComboBox(this, ID_LDSHP_PKCOL, wxT(""), wxDefaultPosition,
2349                    wxSize(180, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
2350   pkeyList->Enable(false);
2351   gPKeySizer->Add(pkeyList, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2352 // OK - CANCEL buttons
2353   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
2354   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2355   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
2356   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2357   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
2358   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2359 // appends event handler for OK button
2360   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
2361           (wxObjectEventFunction) & LoadShpDialog::OnOk);
2362   Connect(ID_LDSHP_USER_GTYPE, wxEVT_COMMAND_RADIOBOX_SELECTED,
2363           (wxObjectEventFunction) & LoadShpDialog::OnUserGType);
2364   Connect(ID_LDSHP_USER_PKEY, wxEVT_COMMAND_RADIOBOX_SELECTED,
2365           (wxObjectEventFunction) & LoadShpDialog::OnUserPKey);
2366 }
2367 
LoadPKFields()2368 void LoadShpDialog::LoadPKFields()
2369 {
2370 // loading the Primary Key Fields list
2371   char dbf_path[1024];
2372   char charset[1024];
2373   char dummy[1024];
2374   wxString dummyName;
2375   int cnt;
2376   int seed;
2377   int dup;
2378   int idup;
2379   wxString *charsets = MainFrame->GetCharsets();
2380   wxString cs;
2381   int idSel = MainFrame->GetCharsetIndex(Default);
2382   gaiaDbfPtr dbf = NULL;
2383   gaiaDbfFieldPtr dbf_field;
2384   if (PKFields != NULL)
2385     delete[]PKFields;
2386   PKFields = NULL;
2387   PKCount = 0;
2388 
2389 // opening the DBF in order to fetch field names
2390   dbf = gaiaAllocDbf();
2391   strcpy(dbf_path, Path.ToUTF8());
2392   strcat(dbf_path, ".dbf");
2393   cs = *(charsets + idSel);
2394   strcpy(charset, cs.ToUTF8());
2395   gaiaOpenDbfRead(dbf, dbf_path, charset, "UTF-8");
2396   if (!(dbf->Valid))
2397     {
2398       gaiaFreeDbf(dbf);
2399       return;
2400     }
2401 /* checking for duplicate / illegal column names and antialising them */
2402   dbf_field = dbf->Dbf->First;
2403   while (dbf_field)
2404     {
2405       /* counting DBF fields */
2406       PKCount++;
2407       dbf_field = dbf_field->Next;
2408     }
2409   PKFields = new wxString[PKCount];
2410   PKFieldsEx = new wxString[PKCount];
2411   cnt = 0;
2412   seed = 0;
2413   dbf_field = dbf->Dbf->First;
2414   while (dbf_field)
2415     {
2416       /* preparing column names */
2417       dummyName = wxString::FromUTF8(dbf_field->Name);
2418       dup = 0;
2419       for (idup = 0; idup < cnt; idup++)
2420         {
2421           if (dummyName == PKFields[idup])
2422             dup = 1;
2423         }
2424       if (dummyName == wxString::FromUTF8("PK_UID"))
2425         dup = 1;
2426       if (dup)
2427         {
2428           sprintf(dummy, "COL_%d", seed++);
2429           dummyName = wxString::FromUTF8(dummy);
2430         }
2431       PKFields[cnt] = dummyName;
2432       PKFieldsEx[cnt] = dummyName;
2433       dummyName = wxT(" [TEXT]");
2434       switch (dbf_field->Type)
2435         {
2436           case 'N':
2437             if (dbf_field->Decimals)
2438               dummyName = wxT(" [DOUBLE]");
2439             else
2440               {
2441                 if (dbf_field->Length <= 18)
2442                   dummyName = wxT(" [INTEGER]");
2443                 else
2444                   dummyName = wxT(" [DOUBLE]");
2445               }
2446             break;
2447           case 'D':
2448             dummyName = wxT(" [DOUBLE]");
2449             break;
2450           case 'F':
2451             dummyName = wxT(" [DOUBLE]");
2452             break;
2453           case 'L':
2454             dummyName = wxT(" [INTEGER]");
2455             break;
2456         };
2457       PKFieldsEx[cnt] += dummyName;
2458       cnt++;
2459       dbf_field = dbf_field->Next;
2460     }
2461 
2462 // memory cleanup
2463   gaiaFreeDbf(dbf);
2464 }
2465 
OnUserGType(wxCommandEvent & WXUNUSED (event))2466 void LoadShpDialog::OnUserGType(wxCommandEvent & WXUNUSED(event))
2467 {
2468 //
2469 // the mode of user defined Geometry Type changed
2470 //
2471   wxRadioBox *radioCtrl = (wxRadioBox *) FindWindow(ID_LDSHP_USER_GTYPE);
2472   wxComboBox *comboCtrl = (wxComboBox *) FindWindow(ID_LDSHP_GTYPE);
2473   if (radioCtrl->GetSelection() == 0)
2474     {
2475       // automatic
2476       comboCtrl->Clear();
2477       comboCtrl->Enable(false);
2478   } else
2479     {
2480       // user specified
2481       wxString str = wxT("LINESTRING");
2482       comboCtrl->Append(str);
2483       str = wxT("LINESTRINGZ");
2484       comboCtrl->Append(str);
2485       str = wxT("LINESTRINGM");
2486       comboCtrl->Append(str);
2487       str = wxT("LINESTRINGZM");
2488       comboCtrl->Append(str);
2489       str = wxT("MULTILINESTRING");
2490       comboCtrl->Append(str);
2491       str = wxT("MULTILINESTRINGZ");
2492       comboCtrl->Append(str);
2493       str = wxT("MULTILINESTRINGM");
2494       comboCtrl->Append(str);
2495       str = wxT("MULTILINESTRINGZM");
2496       comboCtrl->Append(str);
2497       str = wxT("POLYGON");
2498       comboCtrl->Append(str);
2499       str = wxT("POLYGONZ");
2500       comboCtrl->Append(str);
2501       str = wxT("POLYGONM");
2502       comboCtrl->Append(str);
2503       str = wxT("POLYGONZM");
2504       comboCtrl->Append(str);
2505       str = wxT("MULTIPOLYGON");
2506       comboCtrl->Append(str);
2507       str = wxT("MULTIPOLYGONZ");
2508       comboCtrl->Append(str);
2509       str = wxT("MULTIPOLYGONM");
2510       comboCtrl->Append(str);
2511       str = wxT("MULTIPOLYGONZM");
2512       comboCtrl->Append(str);
2513       comboCtrl->Enable(true);
2514       comboCtrl->SetSelection(wxNOT_FOUND);
2515     }
2516 }
2517 
OnUserPKey(wxCommandEvent & WXUNUSED (event))2518 void LoadShpDialog::OnUserPKey(wxCommandEvent & WXUNUSED(event))
2519 {
2520 //
2521 // the mode of user defined Primary Key Column changed
2522 //
2523   wxRadioBox *radioCtrl = (wxRadioBox *) FindWindow(ID_LDSHP_USER_PKEY);
2524   wxComboBox *comboCtrl = (wxComboBox *) FindWindow(ID_LDSHP_PKCOL);
2525   if (radioCtrl->GetSelection() == 0)
2526     {
2527       // automatic
2528       comboCtrl->Clear();
2529       comboCtrl->Enable(false);
2530   } else
2531     {
2532       // user specified
2533       int i;
2534       for (i = 0; i < PKCount; i++)
2535         {
2536           // setting PK Fields
2537           wxString str = PKFieldsEx[i];
2538           comboCtrl->Append(str);
2539         }
2540       comboCtrl->Enable(true);
2541       comboCtrl->SetSelection(wxNOT_FOUND);
2542     }
2543 }
2544 
OnOk(wxCommandEvent & WXUNUSED (event))2545 void LoadShpDialog::OnOk(wxCommandEvent & WXUNUSED(event))
2546 {
2547 //
2548 // all done:
2549 //
2550   wxTextCtrl *tableCtrl = (wxTextCtrl *) FindWindow(ID_LDSHP_TABLE);
2551   Table = tableCtrl->GetValue();
2552   if (Table.Len() < 1)
2553     {
2554       wxMessageBox(wxT("You must specify the TABLE NAME !!!"),
2555                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2556       return;
2557     }
2558   if (MainFrame->TableAlreadyExists(Table) == true)
2559     {
2560       wxMessageBox(wxT("a table name '") + Table + wxT("' already exists"),
2561                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2562       return;
2563     }
2564   wxTextCtrl *columnCtrl = (wxTextCtrl *) FindWindow(ID_LDSHP_COLUMN);
2565   Column = columnCtrl->GetValue();
2566   if (Column.Len() < 1)
2567     {
2568       wxMessageBox(wxT("You must specify the GEOMETRY COLUMN NAME !!!"),
2569                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2570       return;
2571     }
2572   wxSpinCtrl *sridCtrl = (wxSpinCtrl *) FindWindow(ID_LDSHP_SRID);
2573   Srid = sridCtrl->GetValue();
2574   if (MainFrame->SridNotExists(Srid) == true)
2575     {
2576       wxMessageBox(wxT("invalid SRID value"), wxT("spatialite_gui"),
2577                    wxOK | wxICON_WARNING, this);
2578       return;
2579     }
2580   wxListBox *charsetCtrl = (wxListBox *) FindWindow(ID_LDSHP_CHARSET);
2581   int idSel = charsetCtrl->GetSelection();
2582   if (idSel == wxNOT_FOUND)
2583     {
2584       wxMessageBox(wxT("you must select some Charset Encoding from the list"),
2585                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2586       return;
2587     }
2588   wxString *charsets = MainFrame->GetCharsets();
2589   Charset = *(charsets + idSel);
2590   wxCheckBox *coerce2DCtrl = (wxCheckBox *) FindWindow(ID_LDSHP_COERCE_2D);
2591   Coerce2D = coerce2DCtrl->GetValue();
2592   wxCheckBox *compressCtrl = (wxCheckBox *) FindWindow(ID_LDSHP_COMPRESSED);
2593   Compressed = compressCtrl->GetValue();
2594   wxCheckBox *rtreeCtrl = (wxCheckBox *) FindWindow(ID_LDSHP_RTREE);
2595   SpatialIndex = rtreeCtrl->GetValue();
2596   wxRadioBox *radioCtrl = (wxRadioBox *) FindWindow(ID_LDSHP_USER_GTYPE);
2597   wxComboBox *comboCtrl = (wxComboBox *) FindWindow(ID_LDSHP_GTYPE);
2598   if (radioCtrl->GetSelection() == 0)
2599     {
2600       // automatic
2601       UserDefinedGType = false;
2602       GeometryType = wxT("");
2603   } else
2604     {
2605       // user specified
2606       idSel = comboCtrl->GetSelection();
2607       if (idSel == wxNOT_FOUND)
2608         {
2609           wxMessageBox(wxT
2610                        ("you must select some User defined Geometry Type from the list"),
2611                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2612           return;
2613         }
2614       UserDefinedGType = true;
2615       GeometryType = comboCtrl->GetValue();
2616     }
2617   radioCtrl = (wxRadioBox *) FindWindow(ID_LDSHP_USER_PKEY);
2618   comboCtrl = (wxComboBox *) FindWindow(ID_LDSHP_PKCOL);
2619   if (radioCtrl->GetSelection() == 0)
2620     {
2621       // automatic
2622       UserDefinedPKey = false;
2623       PKColumn = wxT("");
2624   } else
2625     {
2626       // user specified
2627       idSel = comboCtrl->GetSelection();
2628       if (idSel == wxNOT_FOUND)
2629         {
2630           wxMessageBox(wxT
2631                        ("you must select some User defined Primary Key Column from the list"),
2632                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2633           return;
2634         }
2635       UserDefinedPKey = true;
2636       PKColumn = PKFields[idSel];
2637     }
2638   wxDialog::EndModal(wxID_OK);
2639 }
2640 
Create(MyFrame * parent,wxString & path,wxString & table,wxString & column,wxString & defCs)2641 bool DumpShpDialog::Create(MyFrame * parent, wxString & path, wxString & table,
2642                            wxString & column, wxString & defCs)
2643 {
2644 //
2645 // creating the dialog
2646 //
2647   MainFrame = parent;
2648   Path = path;
2649   Table = table;
2650   Column = column;
2651   Default = defCs;
2652   if (wxDialog::Create(parent, wxID_ANY, wxT("Dump Shapefile")) == false)
2653     return false;
2654 // populates individual controls
2655   CreateControls();
2656 // sets dialog sizer
2657   GetSizer()->Fit(this);
2658   GetSizer()->SetSizeHints(this);
2659 // centers the dialog window
2660   Centre();
2661   return true;
2662 }
2663 
CreateControls()2664 void DumpShpDialog::CreateControls()
2665 {
2666 //
2667 // creating individual control and setting initial values
2668 //
2669   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
2670   this->SetSizer(topSizer);
2671   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
2672   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2673 // first row: the Shapefile path
2674   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
2675   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
2676   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
2677   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2678   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
2679                                          Path, wxDefaultPosition,
2680                                          wxSize(350, 22), wxTE_READONLY);
2681   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
2682 // second row: TABLE name
2683   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
2684   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
2685   wxStaticText *tableLabel =
2686     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
2687   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2688   wxTextCtrl *tableCtrl = new wxTextCtrl(this, wxID_STATIC, Table,
2689                                          wxDefaultPosition, wxSize(350,
2690                                                                    22));
2691   tableCtrl->Enable(false);
2692   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
2693 // third row: GEOMETRY COLUMN name
2694   wxBoxSizer *colSizer = new wxBoxSizer(wxHORIZONTAL);
2695   boxSizer->Add(colSizer, 0, wxALIGN_RIGHT | wxALL, 0);
2696   wxStaticText *colLabel =
2697     new wxStaticText(this, wxID_STATIC, wxT("&GeomColumn name:"));
2698   colSizer->Add(colLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2699   wxTextCtrl *colCtrl = new wxTextCtrl(this, wxID_STATIC, Column,
2700                                        wxDefaultPosition, wxSize(350, 22));
2701   colCtrl->Enable(false);
2702   colSizer->Add(colCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
2703 // fourth row: CHARSET
2704   wxBoxSizer *csSizer = new wxBoxSizer(wxHORIZONTAL);
2705   boxSizer->Add(csSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2706   wxStaticBox *charsetBox = new wxStaticBox(this, wxID_STATIC,
2707                                             wxT("Charset Encoding"),
2708                                             wxDefaultPosition,
2709                                             wxDefaultSize);
2710   wxBoxSizer *charsetSizer = new wxStaticBoxSizer(charsetBox, wxHORIZONTAL);
2711   csSizer->Add(charsetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2712   wxListBox *charsetCtrl = new wxListBox(this, ID_DMPSHP_CHARSET,
2713                                          wxDefaultPosition, wxDefaultSize,
2714                                          MainFrame->GetCharsetsLen(),
2715                                          MainFrame->GetCharsetsNames(),
2716                                          wxLB_SINGLE | wxLB_HSCROLL);
2717   charsetCtrl->SetFont(wxFont
2718                        (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
2719                         wxFONTWEIGHT_NORMAL));
2720   int idSel = MainFrame->GetCharsetIndex(Default);
2721   if (idSel != wxNOT_FOUND)
2722     charsetCtrl->SetSelection(idSel);
2723   charsetSizer->Add(charsetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
2724 // OK - CANCEL buttons
2725   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
2726   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2727   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
2728   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2729   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
2730   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2731 // appends event handler for OK button
2732   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
2733           (wxObjectEventFunction) & DumpShpDialog::OnOk);
2734 }
2735 
OnOk(wxCommandEvent & WXUNUSED (event))2736 void DumpShpDialog::OnOk(wxCommandEvent & WXUNUSED(event))
2737 {
2738 //
2739 // all done:
2740 //
2741   wxListBox *charsetCtrl = (wxListBox *) FindWindow(ID_DMPSHP_CHARSET);
2742   int idSel = charsetCtrl->GetSelection();
2743   if (idSel == wxNOT_FOUND)
2744     {
2745       wxMessageBox(wxT("you must select some Charset Encoding from the list"),
2746                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2747       return;
2748     }
2749   wxString *charsets = MainFrame->GetCharsets();
2750   Charset = *(charsets + idSel);
2751   wxDialog::EndModal(wxID_OK);
2752 }
2753 
Create(MyFrame * parent,wxString & path,wxString & target,wxString & defCs)2754 bool DumpTxtDialog::Create(MyFrame * parent, wxString & path, wxString & target,
2755                            wxString & defCs)
2756 {
2757 //
2758 // creating the dialog
2759 //
2760   MainFrame = parent;
2761   Path = path;
2762   Default = defCs;
2763   if (wxDialog::Create(parent, wxID_ANY, wxT("Dump ") + target) == false)
2764     return false;
2765 // populates individual controls
2766   CreateControls();
2767 // sets dialog sizer
2768   GetSizer()->Fit(this);
2769   GetSizer()->SetSizeHints(this);
2770 // centers the dialog window
2771   Centre();
2772   return true;
2773 }
2774 
CreateControls()2775 void DumpTxtDialog::CreateControls()
2776 {
2777 //
2778 // creating individual control and setting initial values
2779 //
2780   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
2781   this->SetSizer(topSizer);
2782   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
2783   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2784 // first row: the Shapefile path
2785   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
2786   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
2787   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
2788   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2789   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
2790                                          Path, wxDefaultPosition,
2791                                          wxSize(350, 22), wxTE_READONLY);
2792   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
2793 // second row: CHARSET
2794   wxBoxSizer *csSizer = new wxBoxSizer(wxHORIZONTAL);
2795   boxSizer->Add(csSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2796   wxStaticBox *charsetBox = new wxStaticBox(this, wxID_STATIC,
2797                                             wxT("Charset Encoding"),
2798                                             wxDefaultPosition,
2799                                             wxDefaultSize);
2800   wxBoxSizer *charsetSizer = new wxStaticBoxSizer(charsetBox, wxHORIZONTAL);
2801   csSizer->Add(charsetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2802   wxListBox *charsetCtrl = new wxListBox(this, ID_DMPTXT_CHARSET,
2803                                          wxDefaultPosition, wxDefaultSize,
2804                                          MainFrame->GetCharsetsLen(),
2805                                          MainFrame->GetCharsetsNames(),
2806                                          wxLB_SINGLE | wxLB_HSCROLL);
2807   charsetCtrl->SetFont(wxFont
2808                        (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
2809                         wxFONTWEIGHT_NORMAL));
2810   int idSel = MainFrame->GetCharsetIndex(Default);
2811   if (idSel != wxNOT_FOUND)
2812     charsetCtrl->SetSelection(idSel);
2813   charsetSizer->Add(charsetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
2814 // OK - CANCEL buttons
2815   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
2816   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2817   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
2818   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2819   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
2820   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2821 // appends event handler for OK button
2822   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
2823           (wxObjectEventFunction) & DumpTxtDialog::OnOk);
2824 }
2825 
OnOk(wxCommandEvent & WXUNUSED (event))2826 void DumpTxtDialog::OnOk(wxCommandEvent & WXUNUSED(event))
2827 {
2828 //
2829 // all done:
2830 //
2831   wxListBox *charsetCtrl = (wxListBox *) FindWindow(ID_DMPTXT_CHARSET);
2832   int idSel = charsetCtrl->GetSelection();
2833   if (idSel == wxNOT_FOUND)
2834     {
2835       wxMessageBox(wxT("you must select some Charset Encoding from the list"),
2836                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
2837       return;
2838     }
2839   wxString *charsets = MainFrame->GetCharsets();
2840   Charset = *(charsets + idSel);
2841   wxDialog::EndModal(wxID_OK);
2842 }
2843 
Create(MyFrame * parent,wxString & table,wxString & column)2844 bool DumpKmlDialog::Create(MyFrame * parent, wxString & table,
2845                            wxString & column)
2846 {
2847 //
2848 // creating the dialog
2849 //
2850   MainFrame = parent;
2851   Table = table;
2852   Column = column;
2853   isNameConst = true;
2854   isDescConst = true;
2855   if (wxDialog::Create(parent, wxID_ANY, wxT("Dump KML")) == false)
2856     return false;
2857   ColumnList.Populate(MainFrame->GetSqlite(), Table);
2858 // populates individual controls
2859   CreateControls();
2860 // sets dialog sizer
2861   GetSizer()->Fit(this);
2862   GetSizer()->SetSizeHints(this);
2863 // centers the dialog window
2864   Centre();
2865   return true;
2866 }
2867 
CreateControls()2868 void DumpKmlDialog::CreateControls()
2869 {
2870 //
2871 // creating individual control and setting initial values
2872 //
2873   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
2874   this->SetSizer(topSizer);
2875   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
2876   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2877 // first row: TABLE name
2878   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
2879   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
2880   wxStaticText *tableLabel =
2881     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
2882   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2883   wxTextCtrl *tableCtrl = new wxTextCtrl(this, wxID_STATIC, Table,
2884                                          wxDefaultPosition, wxSize(350,
2885                                                                    22));
2886   tableCtrl->Enable(false);
2887   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
2888 // second row: GEOMETRY COLUMN name
2889   wxBoxSizer *colSizer = new wxBoxSizer(wxHORIZONTAL);
2890   boxSizer->Add(colSizer, 0, wxALIGN_RIGHT | wxALL, 0);
2891   wxStaticText *colLabel =
2892     new wxStaticText(this, wxID_STATIC, wxT("&GeomColumn name:"));
2893   colSizer->Add(colLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2894   wxTextCtrl *colCtrl = new wxTextCtrl(this, wxID_STATIC, Column,
2895                                        wxDefaultPosition, wxSize(350, 22));
2896   colCtrl->Enable(false);
2897   colSizer->Add(colCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
2898 
2899 // precision
2900   wxBoxSizer *precBoxSizer = new wxBoxSizer(wxHORIZONTAL);
2901   boxSizer->Add(precBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2902   wxStaticBox *precBox = new wxStaticBox(this, wxID_STATIC,
2903                                          wxT("Precision"),
2904                                          wxDefaultPosition,
2905                                          wxDefaultSize);
2906   wxBoxSizer *precSizer = new wxStaticBoxSizer(precBox, wxVERTICAL);
2907   precBoxSizer->Add(precSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2908   PrecisionCtrl = new wxSpinCtrl(this, ID_KML_PRECISION, wxEmptyString,
2909                                  wxDefaultPosition, wxSize(80, 20),
2910                                  wxSP_ARROW_KEYS, 1, 18, 8);
2911   precSizer->Add(PrecisionCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3);
2912 
2913 // the NAME pane
2914   wxBoxSizer *nameSizer = new wxBoxSizer(wxVERTICAL);
2915   boxSizer->Add(nameSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2916   wxStaticBox *nameBox = new wxStaticBox(this, wxID_STATIC,
2917                                          wxT("Name"),
2918                                          wxDefaultPosition,
2919                                          wxDefaultSize);
2920   wxBoxSizer *name2Sizer = new wxStaticBoxSizer(nameBox, wxHORIZONTAL);
2921   boxSizer->Add(name2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2922   wxStaticBox *nameColBox = new wxStaticBox(this, wxID_STATIC,
2923                                             wxT("from Column"),
2924                                             wxDefaultPosition,
2925                                             wxDefaultSize);
2926   wxBoxSizer *nameColSizer = new wxStaticBoxSizer(nameColBox, wxVERTICAL);
2927   name2Sizer->Add(nameColSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2928   NameCtrl =
2929     new wxComboBox(this, ID_KML_NAME, wxT(""), wxDefaultPosition,
2930                    wxSize(150, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
2931   InitializeComboColumns(NameCtrl);
2932   nameColSizer->Add(NameCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2933 
2934   wxStaticBox *nameConstBox = new wxStaticBox(this, wxID_STATIC,
2935                                               wxT("Constant value"),
2936                                               wxDefaultPosition,
2937                                               wxDefaultSize);
2938   wxBoxSizer *nameConstSizer = new wxStaticBoxSizer(nameConstBox, wxVERTICAL);
2939   name2Sizer->Add(nameConstSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2940   NameConstCtrl =
2941     new wxTextCtrl(this, ID_KML_NAME_K, wxT(""),
2942                    wxDefaultPosition, wxSize(250, 22));
2943   nameConstSizer->Add(NameConstCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2944 // the DESCRIPTION pane
2945   wxBoxSizer *descSizer = new wxBoxSizer(wxVERTICAL);
2946   boxSizer->Add(descSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2947   wxStaticBox *descBox = new wxStaticBox(this, wxID_STATIC,
2948                                          wxT("Description"),
2949                                          wxDefaultPosition,
2950                                          wxDefaultSize);
2951   wxBoxSizer *desc2Sizer = new wxStaticBoxSizer(descBox, wxHORIZONTAL);
2952   boxSizer->Add(desc2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2953   wxStaticBox *descColBox = new wxStaticBox(this, wxID_STATIC,
2954                                             wxT("from Column"),
2955                                             wxDefaultPosition,
2956                                             wxDefaultSize);
2957   wxBoxSizer *descColSizer = new wxStaticBoxSizer(descColBox, wxVERTICAL);
2958   desc2Sizer->Add(descColSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2959   DescCtrl =
2960     new wxComboBox(this, ID_KML_DESC, wxT(""), wxDefaultPosition,
2961                    wxSize(150, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
2962   InitializeComboColumns(DescCtrl);
2963   descColSizer->Add(DescCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2964 
2965   wxStaticBox *descConstBox = new wxStaticBox(this, wxID_STATIC,
2966                                               wxT("Constant value"),
2967                                               wxDefaultPosition,
2968                                               wxDefaultSize);
2969   wxBoxSizer *descConstSizer = new wxStaticBoxSizer(descConstBox, wxVERTICAL);
2970   desc2Sizer->Add(descConstSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2971   DescConstCtrl =
2972     new wxTextCtrl(this, ID_KML_DESC_K, wxT(""),
2973                    wxDefaultPosition, wxSize(250, 22));
2974   descConstSizer->Add(DescConstCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2975 
2976 // OK - CANCEL buttons
2977   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
2978   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2979   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
2980   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2981   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
2982   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
2983 // appends event handler for OK button
2984   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
2985           (wxObjectEventFunction) & DumpKmlDialog::OnOk);
2986   Connect(ID_KML_NAME, wxEVT_COMMAND_COMBOBOX_SELECTED,
2987           (wxObjectEventFunction) & DumpKmlDialog::OnNameSelected);
2988   Connect(ID_KML_DESC, wxEVT_COMMAND_COMBOBOX_SELECTED,
2989           (wxObjectEventFunction) & DumpKmlDialog::OnDescSelected);
2990 }
2991 
InitializeComboColumns(wxComboBox * ctrl)2992 void DumpKmlDialog::InitializeComboColumns(wxComboBox * ctrl)
2993 {
2994 //
2995 // initializing a column list ComboBox
2996 //
2997   ctrl->Clear();
2998   AuxColumn *pColumn;
2999   wxString col = wxT("none, use Constant");
3000   ctrl->Append(col);
3001   pColumn = ColumnList.GetFirst();
3002   while (pColumn)
3003     {
3004       if (pColumn->GetName() != Column)
3005         {
3006           col = pColumn->GetName();
3007           ctrl->Append(col);
3008         }
3009       pColumn = pColumn->GetNext();
3010     }
3011   ctrl->Select(0);
3012 }
3013 
OnNameSelected(wxCommandEvent & WXUNUSED (event))3014 void DumpKmlDialog::OnNameSelected(wxCommandEvent & WXUNUSED(event))
3015 {
3016 //
3017 // Name-column selection changed
3018 //
3019   if (NameCtrl->GetSelection() == 0)
3020     {
3021       // using a Constant value
3022       isNameConst = true;
3023       NameConstCtrl->Enable(true);
3024       return;
3025     }
3026   isNameConst = false;
3027   NameConstCtrl->Enable(false);
3028   NameConstCtrl->SetValue(wxT(""));
3029 }
3030 
OnDescSelected(wxCommandEvent & WXUNUSED (event))3031 void DumpKmlDialog::OnDescSelected(wxCommandEvent & WXUNUSED(event))
3032 {
3033 //
3034 // Desc-column selection changed
3035 //
3036   if (DescCtrl->GetSelection() == 0)
3037     {
3038       // using a Constant value
3039       isDescConst = true;
3040       DescConstCtrl->Enable(true);
3041       return;
3042     }
3043   isDescConst = false;
3044   DescConstCtrl->Enable(false);
3045   DescConstCtrl->SetValue(wxT(""));
3046 }
3047 
OnOk(wxCommandEvent & WXUNUSED (event))3048 void DumpKmlDialog::OnOk(wxCommandEvent & WXUNUSED(event))
3049 {
3050 //
3051 // all done:
3052 //
3053   Name = wxT("");
3054   Desc = wxT("");
3055   Precision = PrecisionCtrl->GetValue();
3056   if (isNameConst == true)
3057     Name = NameConstCtrl->GetValue();
3058   else
3059     Name = NameCtrl->GetValue();
3060   if (Name.Len() == 0)
3061     {
3062       wxMessageBox(wxT("you must specify a NAME (Column or Constant)"),
3063                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
3064       return;
3065     }
3066   if (isDescConst == true)
3067     Desc = DescConstCtrl->GetValue();
3068   else
3069     Desc = DescCtrl->GetValue();
3070   if (Desc.Len() == 0)
3071     {
3072       wxMessageBox(wxT("you must specify a DESCRIPTION (Column or Constant)"),
3073                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
3074       return;
3075     }
3076   wxDialog::EndModal(wxID_OK);
3077 }
3078 
Create(MyFrame * parent)3079 bool DumpSpreadsheetDialog::Create(MyFrame * parent)
3080 {
3081 //
3082 // creating the dialog
3083 //
3084   MainFrame = parent;
3085   DecimalPoint = '.';
3086   DateTimes = true;
3087   if (wxDialog::Create(parent, wxID_ANY, wxT("Dump Spreadsheet")) == false)
3088     return false;
3089 // populates individual controls
3090   CreateControls();
3091 // sets dialog sizer
3092   GetSizer()->Fit(this);
3093   GetSizer()->SetSizeHints(this);
3094 // centers the dialog window
3095   Centre();
3096   return true;
3097 }
3098 
CreateControls()3099 void DumpSpreadsheetDialog::CreateControls()
3100 {
3101 //
3102 // creating individual control and setting initial values
3103 //
3104   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
3105   this->SetSizer(topSizer);
3106   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
3107   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3108 // first row: Decimal Point
3109   wxBoxSizer *row = new wxBoxSizer(wxHORIZONTAL);
3110   boxSizer->Add(row, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3111   wxBoxSizer *pt = new wxBoxSizer(wxHORIZONTAL);
3112   row->Add(pt, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3113   wxString decimal_points[2];
3114   decimal_points[0] = wxT("POINT [.]");
3115   decimal_points[1] = wxT("COMMA [,]");
3116   wxRadioBox *Point = new wxRadioBox(this, ID_SHEET_DECIMAL_POINT,
3117                                      wxT("&Decimal Point"),
3118                                      wxDefaultPosition,
3119                                      wxDefaultSize, 2,
3120                                      decimal_points, 2,
3121                                      wxRA_SPECIFY_ROWS);
3122   Point->SetSelection(0);
3123   pt->Add(Point, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3124 // second row: Dates and Times
3125   wxBoxSizer *dt = new wxBoxSizer(wxHORIZONTAL);
3126   row->Add(dt, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3127   wxString dates[2];
3128   dates[0] = wxT("Don't care");
3129   dates[1] = wxT("Convert to SpreadSheet format");
3130   wxRadioBox *Dates = new wxRadioBox(this, ID_SHEET_DATE_TIME,
3131                                      wxT("&Dates, Data-Times and Times"),
3132                                      wxDefaultPosition,
3133                                      wxDefaultSize, 2,
3134                                      dates, 2,
3135                                      wxRA_SPECIFY_ROWS);
3136   Dates->SetSelection(1);
3137   dt->Add(Dates, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3138 // OK - CANCEL buttons
3139   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
3140   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3141   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
3142   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3143   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
3144   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3145 // appends event handler for OK button
3146   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
3147           (wxObjectEventFunction) & DumpSpreadsheetDialog::OnOk);
3148   Connect(ID_SHEET_DECIMAL_POINT, wxEVT_COMMAND_RADIOBOX_SELECTED,
3149           (wxObjectEventFunction) &
3150           DumpSpreadsheetDialog::OnDecimalPointSelected);
3151   Connect(ID_SHEET_DATE_TIME, wxEVT_COMMAND_RADIOBOX_SELECTED,
3152           (wxObjectEventFunction) & DumpSpreadsheetDialog::OnDateTimesSelected);
3153 }
3154 
3155 void DumpSpreadsheetDialog::
OnDecimalPointSelected(wxCommandEvent & WXUNUSED (event))3156 OnDecimalPointSelected(wxCommandEvent & WXUNUSED(event))
3157 {
3158 //
3159 // DECIMAL POINT radio box
3160 //
3161   wxRadioBox *Point = (wxRadioBox *) FindWindow(ID_SHEET_DECIMAL_POINT);
3162   if (DecimalPoint == '.')
3163     {
3164       DecimalPoint = ',';
3165       Point->SetSelection(1);
3166   } else
3167     {
3168       DecimalPoint = '.';
3169       Point->SetSelection(0);
3170     }
3171 }
3172 
3173 void DumpSpreadsheetDialog::
OnDateTimesSelected(wxCommandEvent & WXUNUSED (event))3174 OnDateTimesSelected(wxCommandEvent & WXUNUSED(event))
3175 {
3176 //
3177 // DATE/TIMES radio box
3178 //
3179   wxRadioBox *Dates = (wxRadioBox *) FindWindow(ID_SHEET_DATE_TIME);
3180   if (DateTimes == true)
3181     {
3182       DateTimes = false;
3183       Dates->SetSelection(0);
3184   } else
3185     {
3186       DateTimes = true;
3187       Dates->SetSelection(1);
3188     }
3189 }
3190 
OnOk(wxCommandEvent & WXUNUSED (event))3191 void DumpSpreadsheetDialog::OnOk(wxCommandEvent & WXUNUSED(event))
3192 {
3193 //
3194 // all done:
3195 //
3196   wxDialog::EndModal(wxID_OK);
3197 }
3198 
Create(MyFrame * parent,wxString & path,wxString & defCs)3199 bool SqlScriptDialog::Create(MyFrame * parent, wxString & path,
3200                              wxString & defCs)
3201 {
3202 //
3203 // creating the dialog
3204 //
3205   MainFrame = parent;
3206   Path = path;
3207   Default = defCs;
3208   if (wxDialog::Create(parent, wxID_ANY, wxT("SQL script execute")) == false)
3209     return false;
3210 // populates individual controls
3211   CreateControls();
3212 // sets dialog sizer
3213   GetSizer()->Fit(this);
3214   GetSizer()->SetSizeHints(this);
3215 // centers the dialog window
3216   Centre();
3217   return true;
3218 }
3219 
CreateControls()3220 void SqlScriptDialog::CreateControls()
3221 {
3222 //
3223 // creating individual control and setting initial values
3224 //
3225   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
3226   this->SetSizer(topSizer);
3227   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
3228   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3229 // first row: the SQL script path
3230   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
3231   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3232   wxStaticText *pathLabel = new wxStaticText(this, wxID_STATIC, wxT("&Path:"));
3233   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3234   wxTextCtrl *pathValue = new wxTextCtrl(this, wxID_STATIC,
3235                                          Path, wxDefaultPosition,
3236                                          wxSize(350, 22), wxTE_READONLY);
3237   pathSizer->Add(pathValue, 0, wxALIGN_RIGHT | wxALL, 5);
3238 // second row: CHARSET
3239   wxBoxSizer *csSizer = new wxBoxSizer(wxHORIZONTAL);
3240   boxSizer->Add(csSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3241   wxStaticBox *charsetBox = new wxStaticBox(this, wxID_STATIC,
3242                                             wxT("Charset Encoding"),
3243                                             wxDefaultPosition,
3244                                             wxDefaultSize);
3245   wxBoxSizer *charsetSizer = new wxStaticBoxSizer(charsetBox, wxHORIZONTAL);
3246   csSizer->Add(charsetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3247   wxListBox *charsetCtrl = new wxListBox(this, ID_SCRIPT_CHARSET,
3248                                          wxDefaultPosition, wxDefaultSize,
3249                                          MainFrame->GetCharsetsLen(),
3250                                          MainFrame->GetCharsetsNames(),
3251                                          wxLB_SINGLE | wxLB_HSCROLL);
3252   charsetCtrl->SetFont(wxFont
3253                        (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
3254                         wxFONTWEIGHT_NORMAL));
3255   int idSel = MainFrame->GetCharsetIndex(Default);
3256   if (idSel != wxNOT_FOUND)
3257     charsetCtrl->SetSelection(idSel);
3258   charsetSizer->Add(charsetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
3259 // OK - CANCEL buttons
3260   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
3261   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3262   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
3263   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3264   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
3265   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3266 // appends event handler for OK button
3267   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
3268           (wxObjectEventFunction) & SqlScriptDialog::OnOk);
3269 }
3270 
OnOk(wxCommandEvent & WXUNUSED (event))3271 void SqlScriptDialog::OnOk(wxCommandEvent & WXUNUSED(event))
3272 {
3273 //
3274 // all done:
3275 //
3276   wxListBox *charsetCtrl = (wxListBox *) FindWindow(ID_SCRIPT_CHARSET);
3277   int idSel = charsetCtrl->GetSelection();
3278   if (idSel == wxNOT_FOUND)
3279     {
3280       wxMessageBox(wxT("you must select some Charset Encoding from the list"),
3281                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
3282       return;
3283     }
3284   wxString *charsets = MainFrame->GetCharsets();
3285   Charset = *(charsets + idSel);
3286   wxDialog::EndModal(wxID_OK);
3287 }
3288 
Create(MyFrame * parent,wxString & charset,bool ask)3289 bool DefaultCharsetDialog::Create(MyFrame * parent, wxString & charset,
3290                                   bool ask)
3291 {
3292 //
3293 // creating the dialog
3294 //
3295   MainFrame = parent;
3296   Charset = charset;
3297   AskCharset = ask;
3298   if (wxDialog::Create(parent, wxID_ANY, wxT("Charset settings")) == false)
3299     return false;
3300 // populates individual controls
3301   CreateControls();
3302 // sets dialog sizer
3303   GetSizer()->Fit(this);
3304   GetSizer()->SetSizeHints(this);
3305 // centers the dialog window
3306   Centre();
3307   return true;
3308 }
3309 
CreateControls()3310 void DefaultCharsetDialog::CreateControls()
3311 {
3312 //
3313 // creating individual control and setting initial values
3314 //
3315   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
3316   this->SetSizer(topSizer);
3317   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
3318   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3319 // first row: the DEFAULT CHARSET
3320   wxBoxSizer *csSizer = new wxBoxSizer(wxHORIZONTAL);
3321   boxSizer->Add(csSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3322   wxStaticBox *charsetBox = new wxStaticBox(this, wxID_STATIC,
3323                                             wxT("Default Output Charset"),
3324                                             wxDefaultPosition,
3325                                             wxDefaultSize);
3326   wxBoxSizer *charsetSizer = new wxStaticBoxSizer(charsetBox, wxVERTICAL);
3327   csSizer->Add(charsetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3328   wxListBox *charsetCtrl = new wxListBox(this, ID_DFLT_CHARSET,
3329                                          wxDefaultPosition, wxDefaultSize,
3330                                          MainFrame->GetCharsetsLen(),
3331                                          MainFrame->GetCharsetsNames(),
3332                                          wxLB_SINGLE | wxLB_HSCROLL);
3333   charsetCtrl->SetFont(wxFont
3334                        (8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
3335                         wxFONTWEIGHT_NORMAL));
3336   int idSel = MainFrame->GetCharsetIndex(Charset);
3337   if (idSel != wxNOT_FOUND)
3338     charsetCtrl->SetSelection(idSel);
3339   charsetSizer->Add(charsetCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
3340 // second row: the ASK CHARSET
3341   wxBoxSizer *askSizer = new wxBoxSizer(wxHORIZONTAL);
3342   charsetSizer->Add(askSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3343   wxCheckBox *askCtrl = new wxCheckBox(this, ID_DFLT_ASK,
3344                                        wxT("Ask output charset every time"),
3345                                        wxDefaultPosition, wxDefaultSize);
3346   askCtrl->SetValue(AskCharset);
3347   askSizer->Add(askCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3348 // OK - CANCEL buttons
3349   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
3350   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3351   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
3352   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3353   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
3354   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3355 // appends event handler for OK button
3356   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
3357           (wxObjectEventFunction) & DefaultCharsetDialog::OnOk);
3358 }
3359 
OnOk(wxCommandEvent & WXUNUSED (event))3360 void DefaultCharsetDialog::OnOk(wxCommandEvent & WXUNUSED(event))
3361 {
3362 //
3363 // all done:
3364 //
3365   wxListBox *charsetCtrl = (wxListBox *) FindWindow(ID_DFLT_CHARSET);
3366   int idSel = charsetCtrl->GetSelection();
3367   if (idSel == wxNOT_FOUND)
3368     {
3369       wxMessageBox(wxT
3370                    ("you must select some Default Charset Encoding from the list"),
3371                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
3372       return;
3373     }
3374   wxString *charsets = MainFrame->GetCharsets();
3375   Charset = *(charsets + idSel);
3376   wxCheckBox *askCtrl = (wxCheckBox *) FindWindow(ID_DFLT_ASK);
3377   AskCharset = askCtrl->GetValue();
3378   wxDialog::EndModal(wxID_OK);
3379 }
3380 
Create(MyFrame * parent,wxString & table,wxString & column)3381 bool RecoverDialog::Create(MyFrame * parent, wxString & table,
3382                            wxString & column)
3383 {
3384 //
3385 // creating the dialog
3386 //
3387   MainFrame = parent;
3388   Table = table;
3389   Column = column;
3390   Srid = 0;
3391   Dimension = wxT("XY");
3392   if (wxDialog::Create(parent, wxID_ANY, wxT("Recover Geometry Column")) ==
3393       false)
3394     return false;
3395 // populates individual controls
3396   CreateControls();
3397 // sets dialog sizer
3398   GetSizer()->Fit(this);
3399   GetSizer()->SetSizeHints(this);
3400 // centers the dialog window
3401   Centre();
3402   return true;
3403 }
3404 
CreateControls()3405 void RecoverDialog::CreateControls()
3406 {
3407 //
3408 // creating individual control and setting initial values
3409 //
3410   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
3411   this->SetSizer(topSizer);
3412   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
3413   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3414 // First row: TABLE name
3415   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
3416   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3417   wxStaticText *tableLabel =
3418     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
3419   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3420   wxTextCtrl *tableCtrl = new wxTextCtrl(this, wxID_ANY, Table,
3421                                          wxDefaultPosition, wxSize(350, 22),
3422                                          wxTE_READONLY);
3423   tableCtrl->Enable(false);
3424   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3425 // second row: GEOMETRY COLUMN name
3426   wxBoxSizer *colSizer = new wxBoxSizer(wxHORIZONTAL);
3427   boxSizer->Add(colSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3428   wxStaticText *colLabel =
3429     new wxStaticText(this, wxID_STATIC, wxT("&Column name:"));
3430   colSizer->Add(colLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3431   wxTextCtrl *colCtrl = new wxTextCtrl(this, wxID_ANY, Column,
3432                                        wxDefaultPosition, wxSize(350, 22),
3433                                        wxTE_READONLY);
3434   colCtrl->Enable(false);
3435   colSizer->Add(colCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3436 // third row: SRID
3437   wxBoxSizer *triSizer = new wxBoxSizer(wxHORIZONTAL);
3438   boxSizer->Add(triSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3439   wxBoxSizer *sridDimsSizer = new wxBoxSizer(wxVERTICAL);
3440   triSizer->Add(sridDimsSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
3441   wxBoxSizer *sridSizer = new wxBoxSizer(wxHORIZONTAL);
3442   sridDimsSizer->Add(sridSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3443   wxStaticText *sridLabel = new wxStaticText(this, wxID_STATIC, wxT("&SRID:"));
3444   sridSizer->Add(sridLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3445   wxSpinCtrl *sridCtrl = new wxSpinCtrl(this, ID_RCVR_SRID, wxEmptyString,
3446                                         wxDefaultPosition, wxSize(80, 20),
3447                                         wxSP_ARROW_KEYS,
3448                                         -1, 1000000, Srid);
3449   sridSizer->Add(sridCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3450   wxStaticBox *dimsBox = new wxStaticBox(this, wxID_STATIC,
3451                                          wxT("Dims"),
3452                                          wxDefaultPosition, wxDefaultSize);
3453   wxBoxSizer *dimsSizer = new wxStaticBoxSizer(dimsBox, wxHORIZONTAL);
3454   sridDimsSizer->Add(dimsSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3455   wxString dims[4];
3456   dims[0] = wxT("XY");
3457   dims[1] = wxT("XYM");
3458   dims[2] = wxT("XYZ");
3459   dims[3] = wxT("XYZM");
3460   wxListBox *coordDims = new wxListBox(this, ID_RCVR_DIMS,
3461                                        wxDefaultPosition, wxDefaultSize, 4,
3462                                        dims, wxLB_SINGLE | wxLB_HSCROLL);
3463   dimsSizer->Add(coordDims, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
3464 // fourth row: GEOMETRY TYPE
3465   wxStaticBox *typeBox = new wxStaticBox(this, wxID_STATIC,
3466                                          wxT("Geometry Type"),
3467                                          wxDefaultPosition, wxDefaultSize);
3468   wxBoxSizer *typeSizer = new wxStaticBoxSizer(typeBox, wxHORIZONTAL);
3469   triSizer->Add(typeSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3470   wxString types[8];
3471   types[0] = wxT("POINT");
3472   types[1] = wxT("MULTIPOINT");
3473   types[2] = wxT("LINESTRING");
3474   types[3] = wxT("MULTILINESTRING");
3475   types[4] = wxT("POLYGON");
3476   types[5] = wxT("MULTIPOLYGON");
3477   types[6] = wxT("GEOMETRYCOLLECTION");
3478   types[7] = wxT("GEOMETRY");
3479   wxListBox *geomType = new wxListBox(this, ID_RCVR_TYPE,
3480                                       wxDefaultPosition, wxDefaultSize, 8,
3481                                       types, wxLB_SINGLE | wxLB_HSCROLL);
3482   typeSizer->Add(geomType, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
3483 // OK - CANCEL buttons
3484   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
3485   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3486   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
3487   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3488   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
3489   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3490 // appends event handler for OK button
3491   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
3492           (wxObjectEventFunction) & RecoverDialog::OnOk);
3493 }
3494 
OnOk(wxCommandEvent & WXUNUSED (event))3495 void RecoverDialog::OnOk(wxCommandEvent & WXUNUSED(event))
3496 {
3497 //
3498 // all done:
3499 //
3500   wxSpinCtrl *sridCtrl = (wxSpinCtrl *) FindWindow(ID_RCVR_SRID);
3501   wxListBox *geomType = (wxListBox *) FindWindow(ID_RCVR_TYPE);
3502   wxListBox *coordDims = (wxListBox *) FindWindow(ID_RCVR_DIMS);
3503   Srid = sridCtrl->GetValue();
3504   if (MainFrame->SridNotExists(Srid) == true)
3505     {
3506       wxMessageBox(wxT("invalid SRID value"), wxT("spatialite_gui"),
3507                    wxOK | wxICON_WARNING, this);
3508       return;
3509     }
3510   Type = geomType->GetStringSelection();
3511   if (Type.Len() < 1)
3512     {
3513       wxMessageBox(wxT("you must select some Geometry Type from the list"),
3514                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
3515       return;
3516     }
3517   Dimension = coordDims->GetStringSelection();
3518   if (Dimension.Len() < 1)
3519     {
3520       wxMessageBox(wxT("you must select some Coord Dimension from the list"),
3521                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
3522       return;
3523     }
3524   wxDialog::EndModal(wxID_OK);
3525 }
3526 
Create(MyFrame * parent,wxString & table,wxString & geometry)3527 bool ElementaryGeomsDialog::Create(MyFrame * parent, wxString & table,
3528                                    wxString & geometry)
3529 {
3530 //
3531 // creating the dialog
3532 //
3533   MainFrame = parent;
3534   InTable = table;
3535   Geometry = geometry;
3536   MainFrame->ElementaryGeoms(InTable, Geometry, OutTable, PrimaryKey, MultiID,
3537                              Type, &Srid, CoordDims, &SpatialIndex);
3538   if (wxDialog::Create(parent, wxID_ANY, wxT("Elementary Geometries")) == false)
3539     return false;
3540 // populates individual controls
3541   CreateControls();
3542 // sets dialog sizer
3543   GetSizer()->Fit(this);
3544   GetSizer()->SetSizeHints(this);
3545 // centers the dialog window
3546   Centre();
3547   return true;
3548 }
3549 
CreateControls()3550 void ElementaryGeomsDialog::CreateControls()
3551 {
3552 //
3553 // creating individual control and setting initial values
3554 //
3555   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
3556   this->SetSizer(topSizer);
3557   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
3558   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3559 // First row: input TABLE name
3560   wxStaticBox *inputBox = new wxStaticBox(this, wxID_STATIC,
3561                                           wxT("Input Table"),
3562                                           wxDefaultPosition,
3563                                           wxDefaultSize);
3564   wxBoxSizer *inputSizer = new wxStaticBoxSizer(inputBox, wxVERTICAL);
3565   boxSizer->Add(inputSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3566   wxBoxSizer *inTblSizer = new wxBoxSizer(wxHORIZONTAL);
3567   inputSizer->Add(inTblSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3568   wxStaticText *inTblLabel =
3569     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
3570   inTblSizer->Add(inTblLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3571   wxTextCtrl *inTblCtrl = new wxTextCtrl(this, wxID_ANY, InTable,
3572                                          wxDefaultPosition, wxSize(350, 22),
3573                                          wxTE_READONLY);
3574   inTblCtrl->Enable(false);
3575   inTblSizer->Add(inTblCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3576 // second row: GEOMETRY COLUMN name
3577   wxBoxSizer *colSizer = new wxBoxSizer(wxHORIZONTAL);
3578   inputSizer->Add(colSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3579   wxStaticText *colLabel =
3580     new wxStaticText(this, wxID_STATIC, wxT("&Geometry name:"));
3581   colSizer->Add(colLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3582   wxTextCtrl *colCtrl = new wxTextCtrl(this, wxID_ANY, Geometry,
3583                                        wxDefaultPosition, wxSize(350, 22),
3584                                        wxTE_READONLY);
3585   colCtrl->Enable(false);
3586   colSizer->Add(colCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3587 // third row: output TABLE name
3588   wxStaticBox *outputBox = new wxStaticBox(this, wxID_STATIC,
3589                                            wxT("Output Table"),
3590                                            wxDefaultPosition,
3591                                            wxDefaultSize);
3592   wxBoxSizer *outputSizer = new wxStaticBoxSizer(outputBox, wxVERTICAL);
3593   boxSizer->Add(outputSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3594   wxBoxSizer *outTblSizer = new wxBoxSizer(wxHORIZONTAL);
3595   outputSizer->Add(outTblSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3596   wxStaticText *outTblLabel =
3597     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
3598   outTblSizer->Add(outTblLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3599   wxTextCtrl *outTblCtrl = new wxTextCtrl(this, ID_ELEMGEOM_TABLE, OutTable,
3600                                           wxDefaultPosition, wxSize(350,
3601                                                                     22));
3602   outTblSizer->Add(outTblCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3603 // fourth row: output Primary Key
3604   wxBoxSizer *pKeySizer = new wxBoxSizer(wxHORIZONTAL);
3605   outputSizer->Add(pKeySizer, 0, wxALIGN_RIGHT | wxALL, 0);
3606   wxStaticText *pKeyLabel =
3607     new wxStaticText(this, wxID_STATIC, wxT("&Primary Key name:"));
3608   pKeySizer->Add(pKeyLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3609   wxTextCtrl *pKeyCtrl = new wxTextCtrl(this, ID_ELEMGEOM_PKEY, PrimaryKey,
3610                                         wxDefaultPosition, wxSize(350,
3611                                                                   22));
3612   pKeySizer->Add(pKeyCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3613 // fifth row: MULTI ID
3614   wxBoxSizer *multiSizer = new wxBoxSizer(wxHORIZONTAL);
3615   outputSizer->Add(multiSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3616   wxStaticText *multiLabel =
3617     new wxStaticText(this, wxID_STATIC, wxT("&MultiID name:"));
3618   multiSizer->Add(multiLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3619   wxTextCtrl *multiCtrl = new wxTextCtrl(this, ID_ELEMGEOM_MULTI_ID, MultiID,
3620                                          wxDefaultPosition, wxSize(350, 22));
3621   multiSizer->Add(multiCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3622 // sixth row: GEOMETRY TYPE
3623   wxBoxSizer *typeSizer = new wxBoxSizer(wxHORIZONTAL);
3624   outputSizer->Add(typeSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3625   wxStaticText *tpLabel =
3626     new wxStaticText(this, wxID_STATIC, wxT("&Geometry Type:"));
3627   typeSizer->Add(tpLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3628   wxTextCtrl *typeCtrl = new wxTextCtrl(this, ID_ELEMGEOM_TYPE, Type,
3629                                         wxDefaultPosition, wxSize(350, 22),
3630                                         wxTE_READONLY);
3631   typeCtrl->Enable(false);
3632   typeSizer->Add(typeCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3633 // seventh row: SRID
3634   wxBoxSizer *sridSizer = new wxBoxSizer(wxHORIZONTAL);
3635   outputSizer->Add(sridSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3636   wxStaticText *sridLabel = new wxStaticText(this, wxID_STATIC, wxT("&SRID:"));
3637   char xdummy[64];
3638   sprintf(xdummy, "%d", Srid);
3639   wxString dummy = wxString::FromUTF8(xdummy);
3640   sridSizer->Add(sridLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3641   wxTextCtrl *sridCtrl = new wxTextCtrl(this, wxID_ANY, dummy,
3642                                         wxDefaultPosition, wxSize(350, 22),
3643                                         wxTE_READONLY);
3644   sridCtrl->Enable(false);
3645   sridSizer->Add(sridCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3646 // heigth row: COORD DIMENSION
3647   wxBoxSizer *dimSizer = new wxBoxSizer(wxHORIZONTAL);
3648   outputSizer->Add(dimSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3649   wxStaticText *dimLabel =
3650     new wxStaticText(this, wxID_STATIC, wxT("&Coord Dimension:"));
3651   dimSizer->Add(dimLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3652   wxTextCtrl *dimCtrl = new wxTextCtrl(this, wxID_ANY, CoordDims,
3653                                        wxDefaultPosition, wxSize(350, 22),
3654                                        wxTE_READONLY);
3655   dimCtrl->Enable(false);
3656   dimSizer->Add(dimCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3657 // nineth row: Spatial Index
3658   wxCheckBox *rtreeCtrl = new wxCheckBox(this, ID_ELEMGEOM_RTREE,
3659                                          wxT("With Spatial Index (R*Tree)"),
3660                                          wxDefaultPosition, wxDefaultSize);
3661   rtreeCtrl->SetValue(SpatialIndex);
3662   outputSizer->Add(rtreeCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3663 // OK - CANCEL buttons
3664   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
3665   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3666   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
3667   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3668   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
3669   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3670 // appends event handler for OK button
3671   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
3672           (wxObjectEventFunction) & ElementaryGeomsDialog::OnOk);
3673 }
3674 
OnOk(wxCommandEvent & WXUNUSED (event))3675 void ElementaryGeomsDialog::OnOk(wxCommandEvent & WXUNUSED(event))
3676 {
3677 //
3678 // all done:
3679 //
3680   wxTextCtrl *textCtrl = (wxTextCtrl *) FindWindow(ID_ELEMGEOM_TABLE);
3681   OutTable = textCtrl->GetValue();
3682   textCtrl = (wxTextCtrl *) FindWindow(ID_ELEMGEOM_PKEY);
3683   PrimaryKey = textCtrl->GetValue();
3684   textCtrl = (wxTextCtrl *) FindWindow(ID_ELEMGEOM_MULTI_ID);
3685   MultiID = textCtrl->GetValue();
3686   wxCheckBox *boxCtrl = (wxCheckBox *) FindWindow(ID_ELEMGEOM_RTREE);
3687   if (boxCtrl->IsChecked())
3688     SpatialIndex = true;
3689   else
3690     SpatialIndex = false;
3691   wxDialog::EndModal(wxID_OK);
3692 }
3693 
Create(MyFrame * parent,wxString & table,wxString & column)3694 bool SetSridDialog::Create(MyFrame * parent, wxString & table,
3695                            wxString & column)
3696 {
3697 //
3698 // creating the dialog
3699 //
3700   MainFrame = parent;
3701   Table = table;
3702   Column = column;
3703   OldSrid = 0;
3704   Srid = 0;
3705   if (wxDialog::Create(parent, wxID_ANY, wxT("Changing SRID")) == false)
3706     return false;
3707 // populates individual controls
3708   CreateControls();
3709 // sets dialog sizer
3710   GetSizer()->Fit(this);
3711   GetSizer()->SetSizeHints(this);
3712 // centers the dialog window
3713   Centre();
3714   return true;
3715 }
3716 
CreateControls()3717 void SetSridDialog::CreateControls()
3718 {
3719 //
3720 // creating individual control and setting initial values
3721 //
3722   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
3723   this->SetSizer(topSizer);
3724   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
3725   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3726 // First row: TABLE name
3727   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
3728   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3729   wxStaticText *tableLabel =
3730     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
3731   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3732   wxTextCtrl *tableCtrl = new wxTextCtrl(this, wxID_ANY, Table,
3733                                          wxDefaultPosition, wxSize(350, 22),
3734                                          wxTE_READONLY);
3735   tableCtrl->Enable(false);
3736   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3737 // second row: GEOMETRY COLUMN name
3738   wxBoxSizer *colSizer = new wxBoxSizer(wxHORIZONTAL);
3739   boxSizer->Add(colSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3740   wxStaticText *colLabel =
3741     new wxStaticText(this, wxID_STATIC, wxT("&Column name:"));
3742   colSizer->Add(colLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3743   wxTextCtrl *colCtrl = new wxTextCtrl(this, wxID_ANY, Column,
3744                                        wxDefaultPosition, wxSize(350, 22),
3745                                        wxTE_READONLY);
3746   colCtrl->Enable(false);
3747   colSizer->Add(colCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3748 // third row: SRID
3749   wxBoxSizer *mySizer = new wxBoxSizer(wxHORIZONTAL);
3750   boxSizer->Add(mySizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3751   wxBoxSizer *oldSridSizer = new wxBoxSizer(wxHORIZONTAL);
3752   mySizer->Add(oldSridSizer, 0, wxALIGN_LEFT | wxALL, 0);
3753   wxStaticText *oldSridLabel =
3754     new wxStaticText(this, wxID_STATIC, wxT("&old SRID:"));
3755   oldSridSizer->Add(oldSridLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3756   wxSpinCtrl *oldSridCtrl = new wxSpinCtrl(this, ID_SRID_OLD, wxEmptyString,
3757                                            wxDefaultPosition, wxSize(80,
3758                                                                      20),
3759                                            wxSP_ARROW_KEYS,
3760                                            -1, 1000000, OldSrid);
3761   oldSridSizer->Add(oldSridCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3762 // fourth row: SRID
3763   wxBoxSizer *sridSizer = new wxBoxSizer(wxHORIZONTAL);
3764   mySizer->Add(sridSizer, 0, wxALIGN_RIGHT | wxLEFT, 20);
3765   wxStaticText *sridLabel =
3766     new wxStaticText(this, wxID_STATIC, wxT("&new SRID:"));
3767   sridSizer->Add(sridLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3768   wxSpinCtrl *sridCtrl = new wxSpinCtrl(this, ID_SRID_SRID, wxEmptyString,
3769                                         wxDefaultPosition, wxSize(80, 20),
3770                                         wxSP_ARROW_KEYS,
3771                                         -1, 1000000, Srid);
3772   sridSizer->Add(sridCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3773 // OK - CANCEL buttons
3774   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
3775   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3776   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
3777   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3778   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
3779   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3780 // appends event handler for OK button
3781   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
3782           (wxObjectEventFunction) & SetSridDialog::OnOk);
3783 }
3784 
OnOk(wxCommandEvent & WXUNUSED (event))3785 void SetSridDialog::OnOk(wxCommandEvent & WXUNUSED(event))
3786 {
3787 //
3788 // all done:
3789 //
3790   wxSpinCtrl *oldSridCtrl = (wxSpinCtrl *) FindWindow(ID_SRID_OLD);
3791   wxSpinCtrl *sridCtrl = (wxSpinCtrl *) FindWindow(ID_SRID_SRID);
3792   OldSrid = oldSridCtrl->GetValue();
3793   Srid = sridCtrl->GetValue();
3794   wxDialog::EndModal(wxID_OK);
3795 }
3796 
Create(MyFrame * parent)3797 bool SearchSridDialog::Create(MyFrame * parent)
3798 {
3799 //
3800 // creating the dialog
3801 //
3802   MainFrame = parent;
3803   SearchBySrid = false;
3804   if (wxDialog::Create(parent, wxID_ANY, wxT("Searching a SRID by its name")) ==
3805       false)
3806     return false;
3807 // populates individual controls
3808   CreateControls();
3809 // sets dialog sizer
3810   GetSizer()->Fit(this);
3811   GetSizer()->SetSizeHints(this);
3812 // centers the dialog window
3813   Centre();
3814   return true;
3815 }
3816 
CreateControls()3817 void SearchSridDialog::CreateControls()
3818 {
3819 //
3820 // creating individual control and setting initial values
3821 //
3822   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
3823   this->SetSizer(topSizer);
3824   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
3825   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3826 // First row: SEARCH string
3827   wxBoxSizer *searchSizer = new wxBoxSizer(wxHORIZONTAL);
3828   boxSizer->Add(searchSizer, 0, wxALIGN_RIGHT | wxALL, 0);
3829   wxStaticText *searchLabel =
3830     new wxStaticText(this, wxID_STATIC, wxT("&Search:"));
3831   searchSizer->Add(searchLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3832   wxTextCtrl *searchCtrl = new wxTextCtrl(this, ID_SEARCH, wxT(""),
3833                                           wxDefaultPosition, wxSize(150,
3834                                                                     22));
3835   searchSizer->Add(searchCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
3836 // Second row: by SRID / by Name
3837   wxBoxSizer *bySridSizer = new wxBoxSizer(wxHORIZONTAL);
3838   boxSizer->Add(bySridSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3839   wxString opts[2];
3840   opts[0] = wxT("by EPSG &SRID code");
3841   opts[1] = wxT("by &name");
3842   wxRadioBox *bySridSel = new wxRadioBox(this, ID_BY_SRID,
3843                                          wxT("&Search mode"),
3844                                          wxDefaultPosition,
3845                                          wxDefaultSize, 2,
3846                                          opts, 2,
3847                                          wxRA_SPECIFY_ROWS);
3848   bySridSel->SetSelection(1);
3849   bySridSizer->Add(bySridSel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3850 // OK - CANCEL buttons
3851   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
3852   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3853   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
3854   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3855   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
3856   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
3857 // appends event handler for OK button
3858   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
3859           (wxObjectEventFunction) & SearchSridDialog::OnOk);
3860   Connect(ID_BY_SRID, wxEVT_COMMAND_RADIOBOX_SELECTED,
3861           (wxObjectEventFunction) & SearchSridDialog::OnSearchBySrid);
3862 }
3863 
OnSearchBySrid(wxCommandEvent & WXUNUSED (event))3864 void SearchSridDialog::OnSearchBySrid(wxCommandEvent & WXUNUSED(event))
3865 {
3866 //
3867 // BY SRID radio box
3868 //
3869   wxRadioBox *bySridSel = (wxRadioBox *) FindWindow(ID_BY_SRID);
3870   if (SearchBySrid == true)
3871     {
3872       SearchBySrid = false;
3873       bySridSel->SetSelection(1);
3874   } else
3875     {
3876       SearchBySrid = true;
3877       bySridSel->SetSelection(0);
3878     }
3879 }
3880 
OnOk(wxCommandEvent & WXUNUSED (event))3881 void SearchSridDialog::OnOk(wxCommandEvent & WXUNUSED(event))
3882 {
3883 //
3884 // all done:
3885 //
3886   wxTextCtrl *searchCtrl = (wxTextCtrl *) FindWindow(ID_SEARCH);
3887   wxString txt = searchCtrl->GetValue();
3888   if (SearchBySrid == true)
3889     {
3890       // searching by SRID
3891       long srid;
3892       if (txt.ToLong(&srid) == false)
3893         {
3894           wxMessageBox(wxT("You must specify a numeric code to search for !!!"),
3895                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
3896           return;
3897         }
3898       Srid = srid;
3899   } else
3900     {
3901       // searching by NAME
3902       String = txt;
3903       if (String.Len() < 1)
3904         {
3905           wxMessageBox(wxT("You must specify a string to search for !!!"),
3906                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
3907           return;
3908         }
3909     }
3910   wxDialog::EndModal(wxID_OK);
3911 }
3912 
Create(MyFrame * parent)3913 bool HelpDialog::Create(MyFrame * parent)
3914 {
3915 //
3916 // creating the dialog
3917 //
3918   MainFrame = parent;
3919   if (wxDialog::Create(parent, wxID_ANY, wxT("SQLite + SpatiaLite help"),
3920                        wxDefaultPosition, wxDefaultSize,
3921                        wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) == false)
3922     return false;
3923 // populates individual controls
3924   CreateControls();
3925 // sets dialog sizer
3926   GetSizer()->Fit(this);
3927   GetSizer()->SetSizeHints(this);
3928 // centers the dialog window
3929   MainFrame->OpenHelpPane();
3930   Centre();
3931 // setting up an event handler [dialog closing]
3932   Connect(wxID_ANY, wxEVT_CLOSE_WINDOW,
3933           (wxObjectEventFunction) & HelpDialog::OnClose);
3934   return true;
3935 }
3936 
OnClose(wxCloseEvent & WXUNUSED (event))3937 void HelpDialog::OnClose(wxCloseEvent & WXUNUSED(event))
3938 {
3939 //
3940 // this window has been closed
3941 //
3942   MainFrame->CloseHelpPane();
3943   Destroy();
3944 }
3945 
CreateControls()3946 void HelpDialog::CreateControls()
3947 {
3948 //
3949 // creating individual control and setting initial values
3950 //
3951   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
3952   this->SetSizer(topSizer);
3953   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
3954   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3955   wxHtmlWindow *helpWin = new wxHtmlWindow(this, ID_HELP_HTML,
3956                                            wxDefaultPosition, wxSize(400,
3957                                                                      200));
3958   wxString html;
3959   MainFrame->GetHelp(html);
3960   helpWin->SetPage(html);
3961   topSizer->Add(helpWin, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3962 // setting up the event handlers
3963   Connect(wxID_ANY, wxEVT_SIZE, (wxObjectEventFunction) & HelpDialog::OnSize);
3964 }
3965 
OnSize(wxSizeEvent & WXUNUSED (event))3966 void HelpDialog::OnSize(wxSizeEvent & WXUNUSED(event))
3967 {
3968 //
3969 // this window has changed its size
3970 //
3971   wxSize sz = GetClientSize();
3972   wxHtmlWindow *helpWin = (wxHtmlWindow *) FindWindow(ID_HELP_HTML);
3973   helpWin->SetSize(sz.GetWidth() - 6, sz.GetHeight() - 6);
3974 }
3975 
Create(MyFrame * parent)3976 bool NetworkDialog::Create(MyFrame * parent)
3977 {
3978 //
3979 // creating the dialog
3980 //
3981   MainFrame = parent;
3982   FromColumn = wxT("");
3983   ToColumn = wxT("");
3984   GeomColumn = wxT("");
3985   GeomLength = true;
3986   CostColumn = wxT("");
3987   Bidirectional = true;
3988   OneWays = false;
3989   NameEnabled = false;
3990   AStarSupported = true;
3991   OneWayFromTo = wxT("");
3992   OneWayToFrom = wxT("");
3993   NameColumn = wxT("");
3994   if (wxDialog::Create(parent, wxID_ANY, wxT("Build Network")) == false)
3995     return false;
3996 // populates individual controls
3997   CreateControls();
3998 // sets dialog sizer
3999   GetSizer()->Fit(this);
4000   GetSizer()->SetSizeHints(this);
4001 // centers the dialog window
4002   Centre();
4003   return true;
4004 }
4005 
CreateControls()4006 void NetworkDialog::CreateControls()
4007 {
4008 //
4009 // creating individual control and setting initial values
4010 //
4011   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
4012   this->SetSizer(topSizer);
4013   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
4014   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
4015   wxBoxSizer *row0Sizer = new wxBoxSizer(wxHORIZONTAL);
4016   boxSizer->Add(row0Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
4017 // the Main TABLE
4018   wxBoxSizer *tableSizer = new wxBoxSizer(wxHORIZONTAL);
4019   row0Sizer->Add(tableSizer, 0, wxALIGN_CENTRE_VERTICAL | wxALL, 0);
4020   wxStaticBox *tableBox = new wxStaticBox(this, wxID_STATIC,
4021                                           wxT("Base Table [graph]"),
4022                                           wxDefaultPosition,
4023                                           wxDefaultSize);
4024   wxBoxSizer *tableNameSizer = new wxStaticBoxSizer(tableBox, wxVERTICAL);
4025   tableSizer->Add(tableNameSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
4026   int nTables;
4027   wxString *tables = MainFrame->GetTables(&nTables);
4028   wxSize size = wxSize(150, 300);
4029   wxListBox *tableCtrl = new wxListBox();
4030   tableNameSizer->Add(tableCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4031   tableCtrl->Create(this, ID_NET_TABLE, wxDefaultPosition, size, nTables,
4032                     tables, wxLB_SINGLE | wxLB_HSCROLL);
4033   size = wxSize(100, 80);
4034 // the NodeFrom COLUMN
4035   wxBoxSizer *netSizer = new wxBoxSizer(wxHORIZONTAL);
4036   row0Sizer->Add(netSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4037   wxStaticBox *netBox = new wxStaticBox(this, wxID_STATIC,
4038                                         wxT("Network configuration"),
4039                                         wxDefaultPosition,
4040                                         wxDefaultSize);
4041   wxBoxSizer *colSizer = new wxStaticBoxSizer(netBox, wxVERTICAL);
4042   netSizer->Add(colSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4043   wxBoxSizer *row1Sizer = new wxBoxSizer(wxHORIZONTAL);
4044   colSizer->Add(row1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4045   wxBoxSizer *fromSizer = new wxBoxSizer(wxHORIZONTAL);
4046   row1Sizer->Add(fromSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4047   wxStaticBox *fromBox = new wxStaticBox(this, wxID_STATIC,
4048                                          wxT("NodeFrom Column"),
4049                                          wxDefaultPosition,
4050                                          wxDefaultSize);
4051   wxBoxSizer *fromColSizer = new wxStaticBoxSizer(fromBox, wxVERTICAL);
4052   fromSizer->Add(fromColSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4053   wxListBox *fromCtrl = new wxListBox(this, ID_NET_FROM,
4054                                       wxDefaultPosition, size,
4055                                       0, NULL, wxLB_SINGLE | wxLB_HSCROLL);
4056   fromCtrl->Enable(false);
4057   fromColSizer->Add(fromCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4058 // the NodeTo COLUMN
4059   wxBoxSizer *toSizer = new wxBoxSizer(wxHORIZONTAL);
4060   row1Sizer->Add(toSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4061   wxStaticBox *toBox = new wxStaticBox(this, wxID_STATIC,
4062                                        wxT("NodeTo Column"),
4063                                        wxDefaultPosition,
4064                                        wxDefaultSize);
4065   wxBoxSizer *toColSizer = new wxStaticBoxSizer(toBox, wxVERTICAL);
4066   toSizer->Add(toColSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4067   wxListBox *toCtrl = new wxListBox(this, ID_NET_TO,
4068                                     wxDefaultPosition, size,
4069                                     0, NULL, wxLB_SINGLE | wxLB_HSCROLL);
4070   toCtrl->Enable(false);
4071   toColSizer->Add(toCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4072 // the Geometry COLUMN
4073   wxBoxSizer *geoSizer = new wxBoxSizer(wxHORIZONTAL);
4074   row1Sizer->Add(geoSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4075   wxStaticBox *geoBox = new wxStaticBox(this, wxID_STATIC,
4076                                         wxT("Geometry Column"),
4077                                         wxDefaultPosition,
4078                                         wxDefaultSize);
4079   wxBoxSizer *geoColSizer = new wxStaticBoxSizer(geoBox, wxVERTICAL);
4080   toSizer->Add(geoColSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4081   wxListBox *geoCtrl = new wxListBox(this, ID_NET_GEOM,
4082                                      wxDefaultPosition, size,
4083                                      0, NULL, wxLB_SINGLE | wxLB_HSCROLL);
4084   geoCtrl->Enable(false);
4085   geoColSizer->Add(geoCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4086 // UNIDIRECTIONAL / BIDIRECTIONAL
4087   wxBoxSizer *row2Sizer = new wxBoxSizer(wxHORIZONTAL);
4088   colSizer->Add(row2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4089   wxBoxSizer *row22Sizer = new wxBoxSizer(wxVERTICAL);
4090   row2Sizer->Add(row22Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4091   wxBoxSizer *row222Sizer = new wxBoxSizer(wxHORIZONTAL);
4092   row22Sizer->Add(row222Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4093   wxString dirs[2];
4094   dirs[0] = wxT("&Uni-Directional");
4095   dirs[1] = wxT("&Bi-Directional");
4096   wxRadioBox *dirSel = new wxRadioBox(this, ID_NET_BIDIR,
4097                                       wxT("&Arc connections"),
4098                                       wxDefaultPosition,
4099                                       wxDefaultSize, 2,
4100                                       dirs, 2,
4101                                       wxRA_SPECIFY_ROWS);
4102   dirSel->SetSelection(1);
4103   dirSel->Enable(false);
4104   row222Sizer->Add(dirSel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4105 // the COST is Lenth selection
4106   wxString costs[2];
4107   costs[0] = wxT("&Using Length as Cost");
4108   costs[1] = wxT("&Using Cost Column");
4109   wxRadioBox *costSel = new wxRadioBox(this, ID_NET_LENGTH,
4110                                        wxT("&Cost type"),
4111                                        wxDefaultPosition,
4112                                        wxDefaultSize, 2,
4113                                        costs, 2,
4114                                        wxRA_SPECIFY_ROWS);
4115   costSel->SetSelection(0);
4116   costSel->Enable(false);
4117   row222Sizer->Add(costSel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
4118 // enabling A* support
4119   wxBoxSizer *row223Sizer = new wxBoxSizer(wxHORIZONTAL);
4120   row22Sizer->Add(row223Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4121   wxString algorithms[2];
4122   algorithms[0] = wxT("&A* + Dijkstra");
4123   algorithms[1] = wxT("&Dijkstra only");
4124   wxRadioBox *aStarSel = new wxRadioBox(this, ID_NET_A_STAR,
4125                                         wxT
4126                                         ("&Supported Shortest Path Algorithms"),
4127                                         wxDefaultPosition,
4128                                         wxDefaultSize, 2,
4129                                         algorithms, 2,
4130                                         wxRA_SPECIFY_COLS);
4131   aStarSel->SetSelection(0);
4132   aStarSel->Enable(false);
4133   row223Sizer->Add(aStarSel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4134 // the COST COLUMN
4135   wxBoxSizer *costSizer = new wxBoxSizer(wxHORIZONTAL);
4136   row2Sizer->Add(costSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4137   wxStaticBox *costBox = new wxStaticBox(this, wxID_STATIC,
4138                                          wxT("Cost Column"),
4139                                          wxDefaultPosition,
4140                                          wxDefaultSize);
4141   wxBoxSizer *costColSizer = new wxStaticBoxSizer(costBox, wxVERTICAL);
4142   costSizer->Add(costColSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4143   wxListBox *costCtrl = new wxListBox(this, ID_NET_COST,
4144                                       wxDefaultPosition, size,
4145                                       0, NULL, wxLB_SINGLE | wxLB_HSCROLL);
4146   costCtrl->Enable(false);
4147   costColSizer->Add(costCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4148 // One Ways
4149   wxBoxSizer *row3Sizer = new wxBoxSizer(wxHORIZONTAL);
4150   colSizer->Add(row3Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4151   wxBoxSizer *oneWaySizer = new wxBoxSizer(wxHORIZONTAL);
4152   row3Sizer->Add(oneWaySizer, 0, wxALIGN_RIGHT | wxALL, 0);
4153   wxStaticBox *oneWayBox = new wxStaticBox(this, wxID_STATIC,
4154                                            wxT("OneWay Columns"),
4155                                            wxDefaultPosition,
4156                                            wxDefaultSize);
4157   wxBoxSizer *colWaySizer = new wxStaticBoxSizer(oneWayBox, wxVERTICAL);
4158   oneWaySizer->Add(colWaySizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4159 // OneWay Enable
4160   wxCheckBox *oneWayEnable =
4161     new wxCheckBox(this, ID_NET_ONEWAY, wxT("Enable &OneWays"));
4162   colWaySizer->Add(oneWayEnable, 0, wxALIGN_LEFT | wxALL, 5);
4163 // the OneWay FromTo COLUMN
4164   wxBoxSizer *fromToSizer = new wxBoxSizer(wxHORIZONTAL);
4165   colWaySizer->Add(fromToSizer, 0, wxALIGN_LEFT | wxALL, 0);
4166   wxStaticBox *fromToBox = new wxStaticBox(this, wxID_STATIC,
4167                                            wxT("From -> To"),
4168                                            wxDefaultPosition,
4169                                            wxDefaultSize);
4170   wxBoxSizer *fromToColSizer = new wxStaticBoxSizer(fromToBox, wxVERTICAL);
4171   fromToSizer->Add(fromToColSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4172   wxListBox *fromToCtrl = new wxListBox(this, ID_NET_FROM_TO,
4173                                         wxDefaultPosition, size,
4174                                         0, NULL, wxLB_SINGLE | wxLB_HSCROLL);
4175   fromToCtrl->Enable(false);
4176   fromToColSizer->Add(fromToCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4177 // the OneWay To From COLUMN
4178   wxStaticBox *toFromBox = new wxStaticBox(this, wxID_STATIC,
4179                                            wxT("To -> From"),
4180                                            wxDefaultPosition,
4181                                            wxDefaultSize);
4182   wxBoxSizer *toFromColSizer = new wxStaticBoxSizer(toFromBox, wxVERTICAL);
4183   fromToSizer->Add(toFromColSizer, 0, wxALIGN_RIGHT | wxALL, 1);
4184   wxListBox *toFromCtrl = new wxListBox(this, ID_NET_TO_FROM,
4185                                         wxDefaultPosition, size,
4186                                         0, NULL, wxLB_SINGLE | wxLB_HSCROLL);
4187   toFromCtrl->Enable(false);
4188   toFromColSizer->Add(toFromCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4189 // Name
4190   wxBoxSizer *nameSizer = new wxBoxSizer(wxHORIZONTAL);
4191   row3Sizer->Add(nameSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4192   wxStaticBox *nameBox = new wxStaticBox(this, wxID_STATIC,
4193                                          wxT("Name Column"),
4194                                          wxDefaultPosition,
4195                                          wxDefaultSize);
4196   wxBoxSizer *nameColSizer = new wxStaticBoxSizer(nameBox, wxVERTICAL);
4197   nameSizer->Add(nameColSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4198 // Name Enable
4199   wxCheckBox *nameEnable =
4200     new wxCheckBox(this, ID_NET_NAME_ENABLE, wxT("Enable &Name"));
4201   nameColSizer->Add(nameEnable, 0, wxALIGN_LEFT | wxALL, 5);
4202 // the Name COLUMN
4203   wxListBox *nameCtrl = new wxListBox(this, ID_NET_NAME,
4204                                       wxDefaultPosition, size,
4205                                       0, NULL, wxLB_SINGLE | wxLB_HSCROLL);
4206   nameCtrl->Enable(false);
4207   nameColSizer->Add(nameCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4208 // OK - CANCEL buttons
4209   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
4210   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4211   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
4212   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
4213   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
4214   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
4215 // appends event handler for OK button
4216   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
4217           (wxObjectEventFunction) & NetworkDialog::OnOk);
4218 // appends event handlers for radio buttons etc
4219   Connect(ID_NET_TABLE, wxEVT_COMMAND_LISTBOX_SELECTED,
4220           (wxObjectEventFunction) & NetworkDialog::OnTable);
4221   Connect(ID_NET_BIDIR, wxEVT_COMMAND_RADIOBOX_SELECTED,
4222           (wxObjectEventFunction) & NetworkDialog::OnDirection);
4223   Connect(ID_NET_LENGTH, wxEVT_COMMAND_RADIOBOX_SELECTED,
4224           (wxObjectEventFunction) & NetworkDialog::OnCost);
4225   Connect(ID_NET_ONEWAY, wxEVT_COMMAND_CHECKBOX_CLICKED,
4226           (wxObjectEventFunction) & NetworkDialog::OnOneWay);
4227   Connect(ID_NET_NAME_ENABLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
4228           (wxObjectEventFunction) & NetworkDialog::OnNameEnabled);
4229 }
4230 
OnTable(wxCommandEvent & WXUNUSED (event))4231 void NetworkDialog::OnTable(wxCommandEvent & WXUNUSED(event))
4232 {
4233 //
4234 // TABLE selection changed
4235 //
4236   wxListBox *tableCtrl = (wxListBox *) FindWindow(ID_NET_TABLE);
4237   TableName = tableCtrl->GetStringSelection();
4238   int n_cols;
4239   wxString *columns = MainFrame->GetColumnNames(TableName, &n_cols);
4240   wxListBox *fromCtrl = (wxListBox *) FindWindow(ID_NET_FROM);
4241   fromCtrl->Clear();
4242   fromCtrl->InsertItems(n_cols, columns, 0);
4243   fromCtrl->Enable(true);
4244   wxListBox *toCtrl = (wxListBox *) FindWindow(ID_NET_TO);
4245   toCtrl->Clear();
4246   toCtrl->InsertItems(n_cols, columns, 0);
4247   toCtrl->Enable(true);
4248   wxListBox *geomCtrl = (wxListBox *) FindWindow(ID_NET_GEOM);
4249   geomCtrl->Clear();
4250   geomCtrl->InsertItems(n_cols, columns, 0);
4251   geomCtrl->Enable(true);
4252   wxListBox *costCtrl = (wxListBox *) FindWindow(ID_NET_COST);
4253   costCtrl->Clear();
4254   costCtrl->InsertItems(n_cols, columns, 0);
4255   costCtrl->Enable(false);
4256   wxListBox *fromToCtrl = (wxListBox *) FindWindow(ID_NET_FROM_TO);
4257   fromToCtrl->Clear();
4258   fromToCtrl->InsertItems(n_cols, columns, 0);
4259   fromToCtrl->Enable(false);
4260   wxListBox *toFromCtrl = (wxListBox *) FindWindow(ID_NET_TO_FROM);
4261   toFromCtrl->Clear();
4262   toFromCtrl->InsertItems(n_cols, columns, 0);
4263   toFromCtrl->Enable(false);
4264   wxRadioBox *dirSel = (wxRadioBox *) FindWindow(ID_NET_BIDIR);
4265   Bidirectional = true;
4266   dirSel->SetSelection(1);
4267   dirSel->Enable(true);
4268   wxRadioBox *costSel = (wxRadioBox *) FindWindow(ID_NET_LENGTH);
4269   GeomLength = true;
4270   costSel->SetSelection(0);
4271   costSel->Enable(true);
4272   wxCheckBox *oneWaySel = (wxCheckBox *) FindWindow(ID_NET_ONEWAY);
4273   OneWays = false;
4274   oneWaySel->SetValue(false);
4275   oneWaySel->Enable(true);
4276   wxListBox *nameCtrl = (wxListBox *) FindWindow(ID_NET_NAME);
4277   nameCtrl->Clear();
4278   nameCtrl->InsertItems(n_cols, columns, 0);
4279   nameCtrl->Enable(false);
4280   wxCheckBox *nameEnable = (wxCheckBox *) FindWindow(ID_NET_NAME_ENABLE);
4281   NameEnabled = false;
4282   nameEnable->SetValue(false);
4283   nameEnable->Enable(true);
4284   wxRadioBox *aStarSel = (wxRadioBox *) FindWindow(ID_NET_A_STAR);
4285   aStarSel->Enable(true);
4286 }
4287 
OnDirection(wxCommandEvent & WXUNUSED (event))4288 void NetworkDialog::OnDirection(wxCommandEvent & WXUNUSED(event))
4289 {
4290 //
4291 // BIDIRECTIONAL radio box
4292 //
4293   wxCheckBox *oneWaySel = (wxCheckBox *) FindWindow(ID_NET_ONEWAY);
4294   wxRadioBox *dirSel = (wxRadioBox *) FindWindow(ID_NET_BIDIR);
4295   wxListBox *fromToCtrl = (wxListBox *) FindWindow(ID_NET_FROM_TO);
4296   wxListBox *toFromCtrl = (wxListBox *) FindWindow(ID_NET_TO_FROM);
4297   if (Bidirectional == true)
4298     {
4299       Bidirectional = false;
4300       dirSel->SetSelection(0);
4301       OneWays = false;
4302       oneWaySel->SetValue(false);
4303       oneWaySel->Enable(false);
4304       fromToCtrl->Enable(false);
4305       toFromCtrl->Enable(false);
4306   } else
4307     {
4308       Bidirectional = true;
4309       dirSel->SetSelection(1);
4310       OneWays = false;
4311       oneWaySel->SetValue(false);
4312       oneWaySel->Enable(true);
4313       fromToCtrl->Enable(false);
4314       toFromCtrl->Enable(false);
4315     }
4316 }
4317 
OnCost(wxCommandEvent & WXUNUSED (event))4318 void NetworkDialog::OnCost(wxCommandEvent & WXUNUSED(event))
4319 {
4320 //
4321 // COST radio box
4322 //
4323   wxRadioBox *costSel = (wxRadioBox *) FindWindow(ID_NET_LENGTH);
4324   wxListBox *costCtrl = (wxListBox *) FindWindow(ID_NET_COST);
4325   if (GeomLength == true)
4326     {
4327       GeomLength = false;
4328       costSel->SetSelection(1);
4329       costCtrl->Enable(true);
4330   } else
4331     {
4332       GeomLength = true;
4333       costSel->SetSelection(0);
4334       costCtrl->Enable(false);
4335     }
4336 }
4337 
OnOneWay(wxCommandEvent & WXUNUSED (event))4338 void NetworkDialog::OnOneWay(wxCommandEvent & WXUNUSED(event))
4339 {
4340 //
4341 // OneWay check box
4342 //
4343   wxCheckBox *oneWaySel = (wxCheckBox *) FindWindow(ID_NET_ONEWAY);
4344   wxListBox *fromToCtrl = (wxListBox *) FindWindow(ID_NET_FROM_TO);
4345   wxListBox *toFromCtrl = (wxListBox *) FindWindow(ID_NET_TO_FROM);
4346   if (OneWays == true)
4347     {
4348       OneWays = false;
4349       oneWaySel->SetValue(false);
4350       fromToCtrl->Enable(false);
4351       toFromCtrl->Enable(false);
4352   } else
4353     {
4354       OneWays = true;
4355       oneWaySel->SetValue(true);
4356       fromToCtrl->Enable(true);
4357       toFromCtrl->Enable(true);
4358     }
4359 }
4360 
OnNameEnabled(wxCommandEvent & WXUNUSED (event))4361 void NetworkDialog::OnNameEnabled(wxCommandEvent & WXUNUSED(event))
4362 {
4363 //
4364 // Name check box
4365 //
4366   wxCheckBox *nameEnable = (wxCheckBox *) FindWindow(ID_NET_NAME_ENABLE);
4367   wxListBox *nameCtrl = (wxListBox *) FindWindow(ID_NET_NAME);
4368   if (NameEnabled == true)
4369     {
4370       NameEnabled = false;
4371       nameEnable->SetValue(false);
4372       nameCtrl->Enable(false);
4373   } else
4374     {
4375       NameEnabled = true;
4376       nameEnable->SetValue(true);
4377       nameCtrl->Enable(true);
4378     }
4379 }
4380 
OnOk(wxCommandEvent & WXUNUSED (event))4381 void NetworkDialog::OnOk(wxCommandEvent & WXUNUSED(event))
4382 {
4383 //
4384 // all done:
4385 //
4386   wxListBox *tableCtrl = (wxListBox *) FindWindow(ID_NET_TABLE);
4387   TableName = tableCtrl->GetStringSelection();
4388   if (TableName.Len() < 1)
4389     {
4390       wxMessageBox(wxT("You must select some TABLE NAME !!!"),
4391                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
4392       return;
4393     }
4394   wxListBox *fromCtrl = (wxListBox *) FindWindow(ID_NET_FROM);
4395   FromColumn = fromCtrl->GetStringSelection();
4396   if (FromColumn.Len() < 1)
4397     {
4398       wxMessageBox(wxT("You must select some 'NodeFrom' COLUMN !!!"),
4399                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
4400       return;
4401     }
4402   wxListBox *toCtrl = (wxListBox *) FindWindow(ID_NET_TO);
4403   ToColumn = toCtrl->GetStringSelection();
4404   if (ToColumn.Len() < 1)
4405     {
4406       wxMessageBox(wxT("You must select some 'NodeTo' COLUMN !!!"),
4407                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
4408       return;
4409     }
4410   wxListBox *geomCtrl = (wxListBox *) FindWindow(ID_NET_GEOM);
4411   GeomColumn = geomCtrl->GetStringSelection();
4412   if (GeomColumn.Len() < 1)
4413     {
4414       wxMessageBox(wxT("You must select some 'Geometry' COLUMN !!!"),
4415                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
4416       return;
4417     }
4418   if (GeomLength == true)
4419     CostColumn = wxT("");
4420   else
4421     {
4422       wxListBox *costCtrl = (wxListBox *) FindWindow(ID_NET_COST);
4423       CostColumn = costCtrl->GetStringSelection();
4424       if (CostColumn.Len() < 1)
4425         {
4426           wxMessageBox(wxT("You must select some 'Cost' COLUMN !!!"),
4427                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
4428           return;
4429         }
4430     }
4431   if (Bidirectional == true && OneWays == true)
4432     {
4433       wxListBox *fromToCtrl = (wxListBox *) FindWindow(ID_NET_FROM_TO);
4434       OneWayFromTo = fromToCtrl->GetStringSelection();
4435       if (OneWayFromTo.Len() < 1)
4436         {
4437           wxMessageBox(wxT("You must select some 'OneWay From->To' COLUMN !!!"),
4438                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
4439           return;
4440         }
4441       wxListBox *toFromCtrl = (wxListBox *) FindWindow(ID_NET_TO_FROM);
4442       OneWayToFrom = toFromCtrl->GetStringSelection();
4443       if (OneWayToFrom.Len() < 1)
4444         {
4445           wxMessageBox(wxT("You must select some 'OneWay To->From' COLUMN !!!"),
4446                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
4447           return;
4448         }
4449   } else
4450     {
4451       OneWayFromTo = wxT("");
4452       OneWayToFrom = wxT("");
4453     }
4454   if (NameEnabled == true)
4455     {
4456       wxListBox *nameCtrl = (wxListBox *) FindWindow(ID_NET_NAME);
4457       NameColumn = nameCtrl->GetStringSelection();
4458       if (NameColumn.Len() < 1)
4459         {
4460           wxMessageBox(wxT("You must select some 'Name' COLUMN !!!"),
4461                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
4462           return;
4463         }
4464   } else
4465     NameColumn = wxT("");
4466   wxRadioBox *aStarSel = (wxRadioBox *) FindWindow(ID_NET_A_STAR);
4467   if (aStarSel->GetSelection() == 1)
4468     AStarSupported = false;
4469   else
4470     AStarSupported = true;
4471   wxDialog::EndModal(wxID_OK);
4472 }
4473 
Create(MyFrame * parent,wxString & dir_path,wxString & img_path)4474 bool ExifDialog::Create(MyFrame * parent, wxString & dir_path,
4475                         wxString & img_path)
4476 {
4477 //
4478 // creating the dialog
4479 //
4480   MainFrame = parent;
4481   DirPath = dir_path;
4482   ImgPath = img_path;
4483   Folder = false;
4484   Metadata = true;
4485   GpsOnly = false;
4486   if (wxDialog::Create(parent, wxID_ANY, wxT("Import EXIF Photos")) == false)
4487     return false;
4488 // populates individual controls
4489   CreateControls();
4490 // sets dialog sizer
4491   GetSizer()->Fit(this);
4492   GetSizer()->SetSizeHints(this);
4493 // centers the dialog window
4494   Centre();
4495   return true;
4496 }
4497 
CreateControls()4498 void ExifDialog::CreateControls()
4499 {
4500 //
4501 // creating individual control and setting initial values
4502 //
4503   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
4504   this->SetSizer(topSizer);
4505   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
4506   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
4507   wxBoxSizer *row0Sizer = new wxBoxSizer(wxVERTICAL);
4508   boxSizer->Add(row0Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
4509 // first row: the path and file/folder selection
4510   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
4511   row0Sizer->Add(pathSizer, 0, wxALIGN_CENTRE_VERTICAL | wxALL, 0);
4512   wxStaticBox *pathBox = new wxStaticBox(this, wxID_STATIC,
4513                                          wxT("Import from source"),
4514                                          wxDefaultPosition,
4515                                          wxDefaultSize);
4516   wxBoxSizer *pthSizer = new wxStaticBoxSizer(pathBox, wxVERTICAL);
4517   pathSizer->Add(pthSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
4518   wxStaticText *pathLabel = new wxStaticText(this, ID_EXIF_PATH, ImgPath);
4519   pthSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4520   wxString imgFolder[2];
4521   imgFolder[0] = wxT("Import &selected image only");
4522   imgFolder[1] = wxT("Import &any EXIF from selected folder");
4523   wxRadioBox *imgFolderSel = new wxRadioBox(this, ID_EXIF_FOLDER,
4524                                             wxT("&Source selection"),
4525                                             wxDefaultPosition,
4526                                             wxDefaultSize, 2,
4527                                             imgFolder, 2,
4528                                             wxRA_SPECIFY_ROWS);
4529   imgFolderSel->SetSelection(0);
4530   pthSizer->Add(imgFolderSel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
4531 // second row: the metadata and gps-only selection
4532   wxBoxSizer *modeSizer = new wxBoxSizer(wxHORIZONTAL);
4533   boxSizer->Add(modeSizer, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 0);
4534   wxString metadata[2];
4535   metadata[0] = wxT("Feed full EXIF &Metadata");
4536   metadata[1] = wxT("&Skip EXIF Metadata");
4537   wxRadioBox *metadataSel = new wxRadioBox(this, ID_EXIF_METADATA,
4538                                            wxT("&EXIF Metadata tables"),
4539                                            wxDefaultPosition,
4540                                            wxDefaultSize, 2,
4541                                            metadata, 2,
4542                                            wxRA_SPECIFY_ROWS);
4543   metadataSel->SetSelection(0);
4544   modeSizer->Add(metadataSel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
4545   wxString gpsOnly[2];
4546   gpsOnly[0] = wxT("Import any EXIF file");
4547   gpsOnly[1] = wxT("Import EXIF only if containing &GPS tags");
4548   wxRadioBox *gpsOnlySel = new wxRadioBox(this, ID_EXIF_GPS_ONLY,
4549                                           wxT("&GPS position"),
4550                                           wxDefaultPosition,
4551                                           wxDefaultSize, 2,
4552                                           gpsOnly, 2,
4553                                           wxRA_SPECIFY_ROWS);
4554   gpsOnlySel->SetSelection(0);
4555   modeSizer->Add(gpsOnlySel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
4556 // OK - CANCEL buttons
4557   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
4558   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4559   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
4560   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
4561   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
4562   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
4563 // appends event handler for OK button
4564   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
4565           (wxObjectEventFunction) & ExifDialog::OnOk);
4566 // appends event handlers for radio buttons etc
4567   Connect(ID_EXIF_FOLDER, wxEVT_COMMAND_RADIOBOX_SELECTED,
4568           (wxObjectEventFunction) & ExifDialog::OnFolder);
4569   Connect(ID_EXIF_METADATA, wxEVT_COMMAND_RADIOBOX_SELECTED,
4570           (wxObjectEventFunction) & ExifDialog::OnMetadata);
4571   Connect(ID_EXIF_GPS_ONLY, wxEVT_COMMAND_RADIOBOX_SELECTED,
4572           (wxObjectEventFunction) & ExifDialog::OnGpsOnly);
4573 }
4574 
OnFolder(wxCommandEvent & WXUNUSED (event))4575 void ExifDialog::OnFolder(wxCommandEvent & WXUNUSED(event))
4576 {
4577 //
4578 // File/Folder radio box
4579 //
4580   wxRadioBox *folderSel = (wxRadioBox *) FindWindow(ID_EXIF_FOLDER);
4581   wxStaticText *pathLabel = (wxStaticText *) FindWindow(ID_EXIF_PATH);
4582   if (Folder == true)
4583     {
4584       Folder = false;
4585       folderSel->SetSelection(0);
4586       pathLabel->SetLabel(ImgPath);
4587   } else
4588     {
4589       Folder = true;
4590       folderSel->SetSelection(1);
4591       pathLabel->SetLabel(DirPath);
4592     }
4593 }
4594 
OnMetadata(wxCommandEvent & WXUNUSED (event))4595 void ExifDialog::OnMetadata(wxCommandEvent & WXUNUSED(event))
4596 {
4597 //
4598 // Metadata radio box
4599 //
4600   wxRadioBox *metadataSel = (wxRadioBox *) FindWindow(ID_EXIF_METADATA);
4601   if (Metadata == true)
4602     {
4603       Metadata = false;
4604       metadataSel->SetSelection(1);
4605   } else
4606     {
4607       Metadata = true;
4608       metadataSel->SetSelection(0);
4609     }
4610 }
4611 
OnGpsOnly(wxCommandEvent & WXUNUSED (event))4612 void ExifDialog::OnGpsOnly(wxCommandEvent & WXUNUSED(event))
4613 {
4614 //
4615 // GpsOnly radio box
4616 //
4617   wxRadioBox *gpsOnlySel = (wxRadioBox *) FindWindow(ID_EXIF_GPS_ONLY);
4618   if (GpsOnly == true)
4619     {
4620       GpsOnly = false;
4621       gpsOnlySel->SetSelection(0);
4622   } else
4623     {
4624       GpsOnly = true;
4625       gpsOnlySel->SetSelection(1);
4626     }
4627 }
4628 
OnOk(wxCommandEvent & WXUNUSED (event))4629 void ExifDialog::OnOk(wxCommandEvent & WXUNUSED(event))
4630 {
4631 //
4632 // all done:
4633 //
4634   wxDialog::EndModal(wxID_OK);
4635 }
4636 
Create(MyFrame * parent,wxString & dir_path,wxString & xml_path)4637 bool XmlDocumentsDialog::Create(MyFrame * parent, wxString & dir_path,
4638                                 wxString & xml_path)
4639 {
4640 //
4641 // creating the dialog
4642 //
4643   MainFrame = parent;
4644   DirPath = dir_path;
4645   XmlPath = xml_path;
4646   Folder = false;
4647   Compressed = true;
4648   Validated = false;
4649   InternalSchema = false;
4650   OkSuffix = false;
4651   OkSchemaColumn = true;
4652   OkInPathColumn = true;
4653   OkParseErrorColumn = true;
4654   OkValidateErrorColumn = true;
4655   if (wxDialog::Create(parent, wxID_ANY, wxT("Import XML Documents")) == false)
4656     return false;
4657 // populates individual controls
4658   CreateControls();
4659 // sets dialog sizer
4660   GetSizer()->Fit(this);
4661   GetSizer()->SetSizeHints(this);
4662 // centers the dialog window
4663   Centre();
4664   return true;
4665 }
4666 
CreateControls()4667 void XmlDocumentsDialog::CreateControls()
4668 {
4669 //
4670 // creating individual control and setting initial values
4671 //
4672   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
4673   this->SetSizer(topSizer);
4674   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
4675   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4676   wxBoxSizer *row0Sizer = new wxBoxSizer(wxVERTICAL);
4677   boxSizer->Add(row0Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4678 // first row: the path and file/folder selection
4679   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
4680   row0Sizer->Add(pathSizer, 0, wxALIGN_CENTRE_VERTICAL | wxALL, 0);
4681   wxStaticBox *pathBox = new wxStaticBox(this, wxID_STATIC,
4682                                          wxT("Import from source"),
4683                                          wxDefaultPosition,
4684                                          wxDefaultSize);
4685   wxBoxSizer *pthSizer = new wxStaticBoxSizer(pathBox, wxVERTICAL);
4686   pathSizer->Add(pthSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4687   wxStaticText *pathLabel = new wxStaticText(this, ID_XML_PATH, XmlPath);
4688   pthSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4689   wxString xmlFolder[2];
4690   xmlFolder[0] = wxT("Import &selected XML Document only");
4691   xmlFolder[1] = wxT("Import &any XML Document from selected folder");
4692   wxRadioBox *xmlFolderSel = new wxRadioBox(this, ID_XML_FOLDER,
4693                                             wxT("&Source selection"),
4694                                             wxDefaultPosition,
4695                                             wxDefaultSize, 2,
4696                                             xmlFolder, 2,
4697                                             wxRA_SPECIFY_ROWS);
4698   xmlFolderSel->SetSelection(0);
4699   pthSizer->Add(xmlFolderSel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4700   wxBoxSizer *sufSizer = new wxBoxSizer(wxHORIZONTAL);
4701   pthSizer->Add(sufSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4702   wxCheckBox *okSufCtrl = new wxCheckBox(this, ID_XML_OK_SUFFIX,
4703                                          wxT(""),
4704                                          wxDefaultPosition, wxDefaultSize);
4705   sufSizer->Add(okSufCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
4706   okSufCtrl->SetValue(false);
4707   okSufCtrl->Enable(false);
4708   wxStaticText *sufLabel =
4709     new wxStaticText(this, wxID_STATIC, wxT("File &suffix:"));
4710   sufSizer->Add(sufLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4711   wxTextCtrl *SufValue = new wxTextCtrl(this, ID_XML_SUFFIX,
4712                                         wxT(""), wxDefaultPosition,
4713                                         wxSize(50, 22));
4714   SufValue->Enable(false);
4715   sufSizer->Add(SufValue, 0, wxALIGN_RIGHT | wxALL, 0);
4716 // second row: Compressed XmlBLOB
4717   wxBoxSizer *comprSizer = new wxBoxSizer(wxHORIZONTAL);
4718   boxSizer->Add(comprSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4719   wxCheckBox *compressedCtrl = new wxCheckBox(this, ID_XML_COMPRESSED,
4720                                               wxT
4721                                               ("Compressed XML Documents [DEFLATE-zip]"),
4722                                               wxDefaultPosition, wxDefaultSize);
4723   compressedCtrl->SetValue(true);
4724   comprSizer->Add(compressedCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4725 // third row: Schema Validation
4726   wxStaticBox *schemaBox = new wxStaticBox(this, wxID_STATIC,
4727                                            wxT("Schema Validation"),
4728                                            wxDefaultPosition, wxDefaultSize);
4729   wxBoxSizer *validateSizer = new wxStaticBoxSizer(schemaBox, wxVERTICAL);
4730   boxSizer->Add(validateSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
4731   wxBoxSizer *valSizer = new wxBoxSizer(wxHORIZONTAL);
4732   validateSizer->Add(valSizer, 0, wxALIGN_LEFT | wxALL, 0);
4733   wxCheckBox *validateCtrl = new wxCheckBox(this, ID_XML_VALIDATED,
4734                                             wxT("Apply Schema Validation"),
4735                                             wxDefaultPosition, wxDefaultSize);
4736   validateCtrl->SetValue(false);
4737   valSizer->Add(validateCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4738   wxString internalSchema[2];
4739   internalSchema[0] = wxT("Use &External SchemaURI");
4740   internalSchema[1] = wxT("Use &Internal SchemaURI");
4741   wxRadioBox *internalBox = new wxRadioBox(this, ID_XML_INTERNAL_SCHEMA,
4742                                            wxT("&SchemaURI mode"),
4743                                            wxDefaultPosition,
4744                                            wxDefaultSize, 2,
4745                                            internalSchema, 2,
4746                                            wxRA_SPECIFY_ROWS);
4747   valSizer->Add(internalBox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4748   internalBox->SetSelection(0);
4749   internalBox->Enable(false);
4750   wxBoxSizer *schemaUriSizer = new wxBoxSizer(wxHORIZONTAL);
4751   validateSizer->Add(schemaUriSizer, 0, wxALIGN_LEFT | wxALL, 0);
4752   wxStaticText *schemaLabel =
4753     new wxStaticText(this, wxID_STATIC, wxT("&Schema URI:"));
4754   schemaUriSizer->Add(schemaLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4755   wxTextCtrl *schemaUriValue = new wxTextCtrl(this, ID_XML_SCHEMA_URI,
4756                                               wxT(""), wxDefaultPosition,
4757                                               wxSize(350, 22));
4758   schemaUriValue->Enable(false);
4759   schemaUriSizer->Add(schemaUriValue, 0, wxALIGN_RIGHT | wxALL, 0);
4760 // fourth row: target Table / Column
4761   wxStaticBox *targetBox = new wxStaticBox(this, wxID_STATIC,
4762                                            wxT("Destination: Table/Columns"),
4763                                            wxDefaultPosition, wxDefaultSize);
4764   wxBoxSizer *targetSizer = new wxStaticBoxSizer(targetBox, wxVERTICAL);
4765   boxSizer->Add(targetSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4766   wxBoxSizer *tblSizer = new wxBoxSizer(wxHORIZONTAL);
4767   targetSizer->Add(tblSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4768   wxStaticText *tblLabel =
4769     new wxStaticText(this, wxID_STATIC, wxT("&Table name:"));
4770   tblSizer->Add(tblLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4771   wxTextCtrl *tableValue = new wxTextCtrl(this, ID_XML_TARGET_TABLE,
4772                                           wxT(""), wxDefaultPosition,
4773                                           wxSize(250, 22));
4774   tblSizer->Add(tableValue, 0, wxALIGN_RIGHT | wxALL, 0);
4775   wxBoxSizer *pkSizer = new wxBoxSizer(wxHORIZONTAL);
4776   targetSizer->Add(pkSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4777   wxStaticText *pkLabel =
4778     new wxStaticText(this, wxID_STATIC, wxT("&Primary Key Column:"));
4779   pkSizer->Add(pkLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4780   wxTextCtrl *pkColValue = new wxTextCtrl(this, ID_XML_PK_NAME,
4781                                           wxT("pk_uid"), wxDefaultPosition,
4782                                           wxSize(250, 22));
4783   pkSizer->Add(pkColValue, 0, wxALIGN_RIGHT | wxALL, 0);
4784   wxBoxSizer *xmlSizer = new wxBoxSizer(wxHORIZONTAL);
4785   targetSizer->Add(xmlSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4786   wxStaticText *xmlLabel =
4787     new wxStaticText(this, wxID_STATIC, wxT("&XMLDocument Column:"));
4788   xmlSizer->Add(xmlLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4789   wxTextCtrl *xmlColValue = new wxTextCtrl(this, ID_XML_BLOB_COLUMN,
4790                                            wxT("xml_document"),
4791                                            wxDefaultPosition,
4792                                            wxSize(250, 22));
4793   xmlSizer->Add(xmlColValue, 0, wxALIGN_RIGHT | wxALL, 0);
4794   wxBoxSizer *skSizer = new wxBoxSizer(wxHORIZONTAL);
4795   targetSizer->Add(skSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4796   wxCheckBox *okSkCtrl = new wxCheckBox(this, ID_XML_OK_SCHEMA_URI,
4797                                         wxT(""),
4798                                         wxDefaultPosition, wxDefaultSize);
4799   skSizer->Add(okSkCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
4800   okSkCtrl->SetValue(true);
4801   wxStaticText *skLabel =
4802     new wxStaticText(this, wxID_STATIC, wxT("&SchemaURI Column:"));
4803   skSizer->Add(skLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4804   wxTextCtrl *SchemaColValue = new wxTextCtrl(this, ID_XML_SCHEMA_URI_COLUMN,
4805                                               wxT("schema_uri"),
4806                                               wxDefaultPosition,
4807                                               wxSize(250, 22));
4808   skSizer->Add(SchemaColValue, 0, wxALIGN_RIGHT | wxALL, 0);
4809   wxBoxSizer *inPthSizer = new wxBoxSizer(wxHORIZONTAL);
4810   targetSizer->Add(inPthSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4811   wxCheckBox *okPthCtrl = new wxCheckBox(this, ID_XML_OK_PATH,
4812                                          wxT(""),
4813                                          wxDefaultPosition, wxDefaultSize);
4814   inPthSizer->Add(okPthCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
4815   okPthCtrl->SetValue(true);
4816   wxStaticText *pthLabel =
4817     new wxStaticText(this, wxID_STATIC, wxT("&InputPath Column:"));
4818   inPthSizer->Add(pthLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4819   wxTextCtrl *PathColValue = new wxTextCtrl(this, ID_XML_PATH_COLUMN,
4820                                             wxT("file_name"), wxDefaultPosition,
4821                                             wxSize(250, 22));
4822   inPthSizer->Add(PathColValue, 0, wxALIGN_RIGHT | wxALL, 0);
4823   wxBoxSizer *parseSizer = new wxBoxSizer(wxHORIZONTAL);
4824   targetSizer->Add(parseSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4825   wxCheckBox *okParseCtrl = new wxCheckBox(this, ID_XML_OK_PARSE_ERR,
4826                                            wxT(""),
4827                                            wxDefaultPosition, wxDefaultSize);
4828   parseSizer->Add(okParseCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
4829   okParseCtrl->SetValue(true);
4830   wxStaticText *parseLabel =
4831     new wxStaticText(this, wxID_STATIC, wxT("&Parse Errors Column:"));
4832   parseSizer->Add(parseLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4833   wxTextCtrl *ParseColValue = new wxTextCtrl(this, ID_XML_PARSE_ERR_COLUMN,
4834                                              wxT("parse_errors"),
4835                                              wxDefaultPosition,
4836                                              wxSize(250, 22));
4837   parseSizer->Add(ParseColValue, 0, wxALIGN_RIGHT | wxALL, 0);
4838   wxBoxSizer *validSizer = new wxBoxSizer(wxHORIZONTAL);
4839   targetSizer->Add(validSizer, 0, wxALIGN_RIGHT | wxALL, 0);
4840   wxCheckBox *okValidateCtrl = new wxCheckBox(this, ID_XML_OK_VALIDATE_ERR,
4841                                               wxT(""),
4842                                               wxDefaultPosition, wxDefaultSize);
4843   validSizer->Add(okValidateCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
4844   okValidateCtrl->SetValue(true);
4845   wxStaticText *validateLabel =
4846     new wxStaticText(this, wxID_STATIC, wxT("&Validate Errors Column:"));
4847   validSizer->Add(validateLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
4848   wxTextCtrl *ValidateColValue =
4849     new wxTextCtrl(this, ID_XML_VALIDATE_ERR_COLUMN,
4850                    wxT("validate_errors"), wxDefaultPosition,
4851                    wxSize(250, 22));
4852   validSizer->Add(ValidateColValue, 0, wxALIGN_RIGHT | wxALL, 0);
4853 // OK - CANCEL buttons
4854   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
4855   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4856   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
4857   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
4858   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
4859   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
4860 // appends event handler for OK button
4861   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
4862           (wxObjectEventFunction) & XmlDocumentsDialog::OnOk);
4863 // appends event handlers for radio buttons etc
4864   Connect(ID_XML_FOLDER, wxEVT_COMMAND_RADIOBOX_SELECTED,
4865           (wxObjectEventFunction) & XmlDocumentsDialog::OnFolder);
4866   Connect(ID_XML_COMPRESSED, wxEVT_COMMAND_CHECKBOX_CLICKED,
4867           (wxObjectEventFunction) & XmlDocumentsDialog::OnCompressionChanged);
4868   Connect(ID_XML_VALIDATED, wxEVT_COMMAND_CHECKBOX_CLICKED,
4869           (wxObjectEventFunction) & XmlDocumentsDialog::OnValidationChanged);
4870   Connect(ID_XML_INTERNAL_SCHEMA, wxEVT_COMMAND_RADIOBOX_SELECTED,
4871           (wxObjectEventFunction) &
4872           XmlDocumentsDialog::OnInternalSchemaChanged);
4873   Connect(ID_XML_OK_SUFFIX, wxEVT_COMMAND_CHECKBOX_CLICKED,
4874           (wxObjectEventFunction) & XmlDocumentsDialog::OnSuffixChanged);
4875   Connect(ID_XML_OK_SCHEMA_URI, wxEVT_COMMAND_CHECKBOX_CLICKED,
4876           (wxObjectEventFunction) & XmlDocumentsDialog::OnSchemaColumnChanged);
4877   Connect(ID_XML_OK_PATH, wxEVT_COMMAND_CHECKBOX_CLICKED,
4878           (wxObjectEventFunction) & XmlDocumentsDialog::OnInPathColumnChanged);
4879   Connect(ID_XML_OK_PARSE_ERR, wxEVT_COMMAND_CHECKBOX_CLICKED,
4880           (wxObjectEventFunction) &
4881           XmlDocumentsDialog::OnParseErrorColumnChanged);
4882   Connect(ID_XML_OK_VALIDATE_ERR, wxEVT_COMMAND_CHECKBOX_CLICKED,
4883           (wxObjectEventFunction) &
4884           XmlDocumentsDialog::OnValidateErrorColumnChanged);
4885 }
4886 
OnFolder(wxCommandEvent & WXUNUSED (event))4887 void XmlDocumentsDialog::OnFolder(wxCommandEvent & WXUNUSED(event))
4888 {
4889 //
4890 // File/Folder radio box
4891 //
4892   wxRadioBox *folderSel = (wxRadioBox *) FindWindow(ID_XML_FOLDER);
4893   wxStaticText *pathLabel = (wxStaticText *) FindWindow(ID_XML_PATH);
4894   wxCheckBox *okCtrl = (wxCheckBox *) FindWindow(ID_XML_OK_SUFFIX);
4895   wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_XML_SUFFIX);
4896   if (Folder == true)
4897     {
4898       Folder = false;
4899       folderSel->SetSelection(0);
4900       pathLabel->SetLabel(XmlPath);
4901       OkSuffix = false;
4902       okCtrl->SetValue(false);
4903       okCtrl->Enable(false);
4904       wxString val = wxT("");
4905       colCtrl->SetValue(val);
4906       colCtrl->Enable(false);
4907   } else
4908     {
4909       Folder = true;
4910       folderSel->SetSelection(1);
4911       pathLabel->SetLabel(DirPath);
4912       OkSuffix = true;
4913       okCtrl->SetValue(true);
4914       okCtrl->Enable(true);
4915       wxString val = wxT(".xml");
4916       colCtrl->SetValue(val);
4917       colCtrl->Enable(true);
4918     }
4919 }
4920 
OnCompressionChanged(wxCommandEvent & WXUNUSED (event))4921 void XmlDocumentsDialog::OnCompressionChanged(wxCommandEvent & WXUNUSED(event))
4922 {
4923 //
4924 // changed Compressed (on/off):
4925 //
4926   wxCheckBox *compressedCtrl = (wxCheckBox *) FindWindow(ID_XML_COMPRESSED);
4927   if (compressedCtrl->IsChecked() == true)
4928     Compressed = true;
4929   else
4930     Compressed = false;
4931 }
4932 
OnValidationChanged(wxCommandEvent & WXUNUSED (event))4933 void XmlDocumentsDialog::OnValidationChanged(wxCommandEvent & WXUNUSED(event))
4934 {
4935 //
4936 // changed Schema Validation (on/off):
4937 //
4938   wxCheckBox *validateCtrl = (wxCheckBox *) FindWindow(ID_XML_VALIDATED);
4939   wxTextCtrl *schemaUriCtrl = (wxTextCtrl *) FindWindow(ID_XML_SCHEMA_URI);
4940   wxRadioBox *internalCtrl = (wxRadioBox *) FindWindow(ID_XML_INTERNAL_SCHEMA);
4941   if (validateCtrl->IsChecked())
4942     {
4943       schemaUriCtrl->Enable(true);
4944       internalCtrl->Enable(true);
4945       internalCtrl->SetSelection(0);
4946   } else
4947     {
4948       SchemaURI = wxT("");
4949       schemaUriCtrl->SetValue(SchemaURI);
4950       schemaUriCtrl->Enable(false);
4951       internalCtrl->Enable(false);
4952       internalCtrl->SetSelection(0);
4953     }
4954 }
4955 
4956 void XmlDocumentsDialog::
OnInternalSchemaChanged(wxCommandEvent & WXUNUSED (event))4957 OnInternalSchemaChanged(wxCommandEvent & WXUNUSED(event))
4958 {
4959 //
4960 // InternalSchemaURI radio box
4961 //
4962   wxRadioBox *internalCtrl = (wxRadioBox *) FindWindow(ID_XML_INTERNAL_SCHEMA);
4963   wxTextCtrl *schemaUriCtrl = (wxTextCtrl *) FindWindow(ID_XML_SCHEMA_URI);
4964   if (internalCtrl->GetSelection() == 0)
4965     {
4966       InternalSchema = false;
4967       SchemaURI = wxT("");
4968       schemaUriCtrl->SetValue(SchemaURI);
4969       schemaUriCtrl->Enable(true);
4970   } else
4971     {
4972       InternalSchema = true;
4973       SchemaURI = wxT("");
4974       schemaUriCtrl->SetValue(SchemaURI);
4975       schemaUriCtrl->Enable(false);
4976     }
4977 }
4978 
OnSuffixChanged(wxCommandEvent & WXUNUSED (event))4979 void XmlDocumentsDialog::OnSuffixChanged(wxCommandEvent & WXUNUSED(event))
4980 {
4981 //
4982 // changed Suffix (on/off):
4983 //
4984   wxCheckBox *okCtrl = (wxCheckBox *) FindWindow(ID_XML_OK_SUFFIX);
4985   wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_XML_SUFFIX);
4986   if (okCtrl->IsChecked() == true)
4987     {
4988       OkSuffix = true;
4989       wxString val = wxT(".xml");
4990       colCtrl->SetValue(val);
4991       colCtrl->Enable(true);
4992   } else
4993     {
4994       OkSuffix = false;
4995       wxString val = wxT("");
4996       colCtrl->SetValue(val);
4997       colCtrl->Enable(false);
4998     }
4999 }
5000 
OnSchemaColumnChanged(wxCommandEvent & WXUNUSED (event))5001 void XmlDocumentsDialog::OnSchemaColumnChanged(wxCommandEvent & WXUNUSED(event))
5002 {
5003 //
5004 // changed Schema Column (on/off):
5005 //
5006   wxCheckBox *okCtrl = (wxCheckBox *) FindWindow(ID_XML_OK_SCHEMA_URI);
5007   wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_XML_SCHEMA_URI_COLUMN);
5008   if (okCtrl->IsChecked() == true)
5009     {
5010       OkSchemaColumn = true;
5011       wxString val = wxT("schema_uri");
5012       colCtrl->SetValue(val);
5013       colCtrl->Enable(true);
5014   } else
5015     {
5016       OkSchemaColumn = false;
5017       wxString val = wxT("");
5018       colCtrl->SetValue(val);
5019       colCtrl->Enable(false);
5020     }
5021 }
5022 
OnInPathColumnChanged(wxCommandEvent & WXUNUSED (event))5023 void XmlDocumentsDialog::OnInPathColumnChanged(wxCommandEvent & WXUNUSED(event))
5024 {
5025 //
5026 // changed InPath Column (on/off):
5027 //
5028   wxCheckBox *okCtrl = (wxCheckBox *) FindWindow(ID_XML_OK_PATH);
5029   wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_XML_PATH_COLUMN);
5030   if (okCtrl->IsChecked() == true)
5031     {
5032       OkInPathColumn = true;
5033       wxString val = wxT("file_name");
5034       colCtrl->SetValue(val);
5035       colCtrl->Enable(true);
5036   } else
5037     {
5038       OkInPathColumn = false;
5039       wxString val = wxT("");
5040       colCtrl->SetValue(val);
5041       colCtrl->Enable(false);
5042     }
5043 }
5044 
5045 void XmlDocumentsDialog::
OnParseErrorColumnChanged(wxCommandEvent & WXUNUSED (event))5046 OnParseErrorColumnChanged(wxCommandEvent & WXUNUSED(event))
5047 {
5048 //
5049 // changed ParseError Column (on/off):
5050 //
5051   wxCheckBox *okCtrl = (wxCheckBox *) FindWindow(ID_XML_OK_PARSE_ERR);
5052   wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_XML_PARSE_ERR_COLUMN);
5053   if (okCtrl->IsChecked() == true)
5054     {
5055       OkParseErrorColumn = true;
5056       wxString val = wxT("parse_errors");
5057       colCtrl->SetValue(val);
5058       colCtrl->Enable(true);
5059   } else
5060     {
5061       OkParseErrorColumn = false;
5062       wxString val = wxT("");
5063       colCtrl->SetValue(val);
5064       colCtrl->Enable(false);
5065     }
5066 }
5067 
5068 void XmlDocumentsDialog::
OnValidateErrorColumnChanged(wxCommandEvent & WXUNUSED (event))5069 OnValidateErrorColumnChanged(wxCommandEvent & WXUNUSED(event))
5070 {
5071 //
5072 // changed ValidateError Column (on/off):
5073 //
5074   wxCheckBox *okCtrl = (wxCheckBox *) FindWindow(ID_XML_OK_VALIDATE_ERR);
5075   wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_XML_VALIDATE_ERR_COLUMN);
5076   if (okCtrl->IsChecked() == true)
5077     {
5078       OkValidateErrorColumn = true;
5079       wxString val = wxT("validate_errors");
5080       colCtrl->SetValue(val);
5081       colCtrl->Enable(true);
5082   } else
5083     {
5084       OkValidateErrorColumn = false;
5085       wxString val = wxT("");
5086       colCtrl->SetValue(val);
5087       colCtrl->Enable(false);
5088     }
5089 }
5090 
OnOk(wxCommandEvent & WXUNUSED (event))5091 void XmlDocumentsDialog::OnOk(wxCommandEvent & WXUNUSED(event))
5092 {
5093 //
5094 // all done:
5095 //
5096   wxCheckBox *validateCtrl = (wxCheckBox *) FindWindow(ID_XML_VALIDATED);
5097   if (validateCtrl->IsChecked() && InternalSchema == false)
5098     {
5099       wxTextCtrl *schemaUriCtrl = (wxTextCtrl *) FindWindow(ID_XML_SCHEMA_URI);
5100       wxString schemaUri = schemaUriCtrl->GetValue().Trim(false);
5101       SchemaURI = schemaUri.Trim(true);
5102       if (SchemaURI.Len() < 1)
5103         {
5104           wxMessageBox(wxT("You must specify some Schema URI !!!"),
5105                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5106           return;
5107         }
5108     }
5109   wxTextCtrl *tableCtrl = (wxTextCtrl *) FindWindow(ID_XML_TARGET_TABLE);
5110   TargetTable = tableCtrl->GetValue();
5111   if (TargetTable.Len() < 1)
5112     {
5113       wxMessageBox(wxT("You must specify some Table name !!!"),
5114                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5115       return;
5116     }
5117   wxTextCtrl *pkCtrl = (wxTextCtrl *) FindWindow(ID_XML_PK_NAME);
5118   PkName = pkCtrl->GetValue();
5119   if (PkName.Len() < 1)
5120     {
5121       wxMessageBox(wxT("You must specify some PrimaryKeyColumn name !!!"),
5122                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5123       return;
5124     }
5125   wxTextCtrl *columnCtrl = (wxTextCtrl *) FindWindow(ID_XML_BLOB_COLUMN);
5126   XmlColumn = columnCtrl->GetValue();
5127   if (XmlColumn.Len() < 1)
5128     {
5129       wxMessageBox(wxT("You must specify some XMLColumn name !!!"),
5130                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5131       return;
5132     }
5133   if (Folder == true && OkSuffix == true)
5134     {
5135       wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_XML_SUFFIX);
5136       Suffix = colCtrl->GetValue();
5137   } else
5138     Suffix = wxT("");
5139   if (OkInPathColumn == true)
5140     {
5141       wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_XML_PATH_COLUMN);
5142       InPathColumn = colCtrl->GetValue();
5143       if (InPathColumn.Len() < 1)
5144         {
5145           wxMessageBox(wxT("You must specify some FileNameColumn name !!!"),
5146                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5147           return;
5148         }
5149   } else
5150     InPathColumn = wxT("");
5151   if (OkSchemaColumn == true)
5152     {
5153       wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_XML_SCHEMA_URI_COLUMN);
5154       SchemaUriColumn = colCtrl->GetValue();
5155       if (SchemaUriColumn.Len() < 1)
5156         {
5157           wxMessageBox(wxT("You must specify some SchemaURIColumn name !!!"),
5158                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5159           return;
5160         }
5161   } else
5162     SchemaUriColumn = wxT("");
5163   if (OkParseErrorColumn == true)
5164     {
5165       wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_XML_PARSE_ERR_COLUMN);
5166       ParseErrorColumn = colCtrl->GetValue();
5167       if (ParseErrorColumn.Len() < 1)
5168         {
5169           wxMessageBox(wxT("You must specify some ParseErrorColumn name !!!"),
5170                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5171           return;
5172         }
5173   } else
5174     ParseErrorColumn = wxT("");
5175   if (OkValidateErrorColumn == true)
5176     {
5177       wxTextCtrl *colCtrl =
5178         (wxTextCtrl *) FindWindow(ID_XML_VALIDATE_ERR_COLUMN);
5179       ValidateErrorColumn = colCtrl->GetValue();
5180       if (ValidateErrorColumn.Len() < 1)
5181         {
5182           wxMessageBox(wxT
5183                        ("You must specify some ValidateErrorColumn name !!!"),
5184                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5185           return;
5186         }
5187   } else
5188     ValidateErrorColumn = wxT("");
5189   wxDialog::EndModal(wxID_OK);
5190 }
5191 
Create(MyFrame * parent,wxString & path,int secs)5192 bool AutoSaveDialog::Create(MyFrame * parent, wxString & path, int secs)
5193 {
5194 //
5195 // creating the dialog
5196 //
5197   MainFrame = parent;
5198   Path = path;
5199   Seconds = secs;
5200   if (wxDialog::Create(parent, wxID_ANY, wxT("MEMORY-DB AutoSave settings")) ==
5201       false)
5202     return false;
5203 // populates individual controls
5204   CreateControls();
5205 // sets dialog sizer
5206   GetSizer()->Fit(this);
5207   GetSizer()->SetSizeHints(this);
5208 // centers the dialog window
5209   Centre();
5210   return true;
5211 }
5212 
CreateControls()5213 void AutoSaveDialog::CreateControls()
5214 {
5215 //
5216 // creating individual controls and setting initial values
5217 //
5218   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
5219   this->SetSizer(topSizer);
5220   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
5221   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
5222 // first row: export path
5223   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
5224   boxSizer->Add(pathSizer, 0, wxALIGN_RIGHT | wxALL, 0);
5225   wxStaticText *pathLabel =
5226     new wxStaticText(this, wxID_STATIC, wxT("&Save as:"));
5227   pathSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5228   wxString pth = Path;
5229   if (pth.Len() == 0)
5230     pth = wxT("*** not set: AutoSave IS DISABLED ***");
5231   PathCtrl = new wxTextCtrl(this, ID_AUTO_SAVE_PATH, pth, wxDefaultPosition,
5232                             wxSize(350, 22), wxTE_READONLY);
5233   pathSizer->Add(PathCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
5234 // second row: CHANGE PATH button
5235   wxBoxSizer *changeBox = new wxBoxSizer(wxHORIZONTAL);
5236   boxSizer->Add(changeBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
5237   wxButton *change =
5238     new wxButton(this, ID_AUTO_SAVE_CHANGE_PATH, wxT("&Set the export path"));
5239   changeBox->Add(change, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5240 // third row: INTERVAL
5241   wxBoxSizer *modeSizer = new wxBoxSizer(wxHORIZONTAL);
5242   boxSizer->Add(modeSizer, 0, wxALIGN_LEFT | wxALL, 0);
5243   wxString modes[6];
5244   modes[0] = wxT("&Disable AutoSaving");
5245   modes[1] = wxT("Every &30 seconds");
5246   modes[2] = wxT("Every &minute");
5247   modes[3] = wxT("Every &2 minutes");
5248   modes[4] = wxT("Every &5 minutes");
5249   modes[5] = wxT("Every &10 minutes");
5250   IntervalCtrl = new wxRadioBox(this, ID_AUTO_SAVE_INTERVAL,
5251                                 wxT("&AutoSave interval"),
5252                                 wxDefaultPosition, wxDefaultSize, 6, modes, 6,
5253                                 wxRA_SPECIFY_ROWS);
5254   if (Seconds <= 0)
5255     IntervalCtrl->SetSelection(0);
5256   else if (Seconds <= 30)
5257     IntervalCtrl->SetSelection(1);
5258   else if (Seconds <= 60)
5259     IntervalCtrl->SetSelection(2);
5260   else if (Seconds <= 120)
5261     IntervalCtrl->SetSelection(3);
5262   else if (Seconds <= 300)
5263     IntervalCtrl->SetSelection(4);
5264   else
5265     IntervalCtrl->SetSelection(5);
5266   modeSizer->Add(IntervalCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
5267 
5268 // OK - CANCEL buttons
5269   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
5270   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
5271   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
5272   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5273   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
5274   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5275 // appends event handler for OK button
5276   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
5277           (wxObjectEventFunction) & AutoSaveDialog::OnOk);
5278   Connect(ID_AUTO_SAVE_CHANGE_PATH, wxEVT_COMMAND_BUTTON_CLICKED,
5279           (wxObjectEventFunction) & AutoSaveDialog::OnChangePath);
5280   Connect(ID_AUTO_SAVE_INTERVAL, wxEVT_COMMAND_RADIOBOX_SELECTED,
5281           (wxObjectEventFunction) & AutoSaveDialog::OnIntervalChanged);
5282 }
5283 
OnChangePath(wxCommandEvent & WXUNUSED (event))5284 void AutoSaveDialog::OnChangePath(wxCommandEvent & WXUNUSED(event))
5285 {
5286 //
5287 //  exporting the MEMORY-DB into an external DB
5288 //
5289   int retdlg;
5290   wxString lastDir;
5291   wxFileDialog fileDialog(this, wxT("Saving the MEMORY-DB"), wxT(""),
5292                           wxT("db.sqlite"),
5293                           wxT
5294                           ("SQLite DB (*.sqlite)|*.sqlite|All files (*.*)|*.*"),
5295                           wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition,
5296                           wxDefaultSize, wxT("filedlg"));
5297   lastDir = MainFrame->GetLastDirectory();
5298   if (lastDir.Len() >= 1)
5299     fileDialog.SetDirectory(lastDir);
5300   retdlg = fileDialog.ShowModal();
5301   if (retdlg == wxID_OK)
5302     {
5303       // exporting the external DB
5304       wxString pth = fileDialog.GetPath();
5305       wxString extPth = wxT("*** not set: AutoSave IS DISABLED ***");
5306       MainFrame->SetExternalSqlitePath(pth);
5307       if (MainFrame->MemoryDbSave() == true)
5308         {
5309           wxMessageBox(wxT("Ok, MEMORY-DB was succesfully saved"),
5310                        wxT("spatialite_gui"), wxOK | wxICON_INFORMATION, this);
5311           wxFileName file(fileDialog.GetPath());
5312           lastDir = file.GetPath();
5313           MainFrame->SetLastDirectory(lastDir);
5314           extPth = MainFrame->GetExternalSqlitePath();
5315           PathCtrl->SetValue(extPth);
5316       } else
5317         PathCtrl->SetValue(extPth);
5318     }
5319 }
5320 
OnIntervalChanged(wxCommandEvent & WXUNUSED (event))5321 void AutoSaveDialog::OnIntervalChanged(wxCommandEvent & WXUNUSED(event))
5322 {
5323 //
5324 // Interval selection changed
5325 //
5326   if (IntervalCtrl->GetSelection() == 0)
5327     Seconds = 0;
5328   else if (IntervalCtrl->GetSelection() == 1)
5329     Seconds = 30;
5330   else if (IntervalCtrl->GetSelection() == 2)
5331     Seconds = 60;
5332   else if (IntervalCtrl->GetSelection() == 3)
5333     Seconds = 120;
5334   else if (IntervalCtrl->GetSelection() == 4)
5335     Seconds = 300;
5336   else
5337     Seconds = 600;
5338 }
5339 
OnOk(wxCommandEvent & WXUNUSED (event))5340 void AutoSaveDialog::OnOk(wxCommandEvent & WXUNUSED(event))
5341 {
5342 //
5343 // all done:
5344 //
5345   wxDialog::EndModal(wxID_OK);
5346 }
5347 
Create(MyFrame * parent,wxString & table)5348 bool DumpPostGISDialog::Create(MyFrame * parent, wxString & table)
5349 {
5350 //
5351 // creating the dialog
5352 //
5353   MainFrame = parent;
5354   SchemaName = wxT("");
5355   TableName = table;
5356   Lowercase = true;
5357   CreateTable = true;
5358   SpatialIndex = true;
5359   if (wxDialog::Create(parent, wxID_ANY, wxT("SQL Dump for PostGIS")) == false)
5360     return false;
5361 // populates individual controls
5362   CreateControls();
5363 // sets dialog sizer
5364   GetSizer()->Fit(this);
5365   GetSizer()->SetSizeHints(this);
5366 // centers the dialog window
5367   Centre();
5368   return true;
5369 }
5370 
CreateControls()5371 void DumpPostGISDialog::CreateControls()
5372 {
5373 //
5374 // creating individual control and setting initial values
5375 //
5376   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
5377   this->SetSizer(topSizer);
5378   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
5379   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
5380 // first row: SCHEMA name
5381   wxBoxSizer *schemaSizer = new wxBoxSizer(wxHORIZONTAL);
5382   boxSizer->Add(schemaSizer, 0, wxALIGN_RIGHT | wxALL, 0);
5383   wxStaticText *schemaLabel =
5384     new wxStaticText(this, wxID_STATIC, wxT("&PostGIS Schema name:"));
5385   schemaSizer->Add(schemaLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5386   wxTextCtrl *schemaCtrl = new wxTextCtrl(this, ID_POSTGIS_SCHEMA, SchemaName,
5387                                           wxDefaultPosition, wxSize(350,
5388                                                                     22));
5389   schemaSizer->Add(schemaCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
5390 // second row: TABLE name
5391   wxBoxSizer *tableSizer = new wxBoxSizer(wxVERTICAL);
5392   boxSizer->Add(tableSizer, 0, wxALIGN_RIGHT | wxALL, 0);
5393   wxStaticText *tableLabel =
5394     new wxStaticText(this, wxID_STATIC, wxT("&PostGIS Table name:"));
5395   tableSizer->Add(tableLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5396   wxTextCtrl *tableCtrl = new wxTextCtrl(this, ID_POSTGIS_TABLE, TableName,
5397                                          wxDefaultPosition, wxSize(350,
5398                                                                    22));
5399   tableSizer->Add(tableCtrl, 0, wxALIGN_RIGHT | wxALL, 5);
5400 // third row: Lowercase
5401   wxBoxSizer *lowerSizer = new wxBoxSizer(wxHORIZONTAL);
5402   tableSizer->Add(lowerSizer, 0, wxALIGN_LEFT | wxALL, 0);
5403   wxCheckBox *lowerCtrl = new wxCheckBox(this, ID_POSTGIS_LOWER,
5404                                          wxT("Lowercase column names"),
5405                                          wxDefaultPosition, wxDefaultSize);
5406   lowerCtrl->SetValue(true);
5407   lowerSizer->Add(lowerCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
5408 // fourth row: Create Table
5409   wxBoxSizer *createSizer = new wxBoxSizer(wxHORIZONTAL);
5410   tableSizer->Add(createSizer, 0, wxALIGN_LEFT | wxALL, 0);
5411   wxCheckBox *createCtrl = new wxCheckBox(this, ID_POSTGIS_CREATE,
5412                                           wxT("Create PostGIS Table"),
5413                                           wxDefaultPosition, wxDefaultSize);
5414   createCtrl->SetValue(true);
5415   createSizer->Add(createCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
5416 // fifth row: Spatial Index
5417   wxBoxSizer *spindexSizer = new wxBoxSizer(wxHORIZONTAL);
5418   tableSizer->Add(spindexSizer, 0, wxALIGN_LEFT | wxALL, 0);
5419   wxCheckBox *spindexCtrl = new wxCheckBox(this, ID_POSTGIS_SPINDEX,
5420                                            wxT("Create PostGIS Spatial Index"),
5421                                            wxDefaultPosition, wxDefaultSize);
5422   spindexCtrl->SetValue(true);
5423   spindexSizer->Add(spindexCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
5424 // OK - CANCEL buttons
5425   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
5426   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
5427   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
5428   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5429   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
5430   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5431 // appends event handler for OK button
5432   Connect(ID_POSTGIS_LOWER, wxEVT_COMMAND_CHECKBOX_CLICKED,
5433           (wxObjectEventFunction) & DumpPostGISDialog::OnLowercase);
5434   Connect(ID_POSTGIS_CREATE, wxEVT_COMMAND_CHECKBOX_CLICKED,
5435           (wxObjectEventFunction) & DumpPostGISDialog::OnCreateTable);
5436   Connect(ID_POSTGIS_SPINDEX, wxEVT_COMMAND_CHECKBOX_CLICKED,
5437           (wxObjectEventFunction) & DumpPostGISDialog::OnSpatialIndex);
5438   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
5439           (wxObjectEventFunction) & DumpPostGISDialog::OnOk);
5440 }
5441 
OnLowercase(wxCommandEvent & WXUNUSED (event))5442 void DumpPostGISDialog::OnLowercase(wxCommandEvent & WXUNUSED(event))
5443 {
5444 //
5445 // Lowercase check box
5446 //
5447   wxCheckBox *lowerCtrl = (wxCheckBox *) FindWindow(ID_POSTGIS_LOWER);
5448   if (Lowercase == true)
5449     Lowercase = false;
5450   else
5451     Lowercase = true;
5452   lowerCtrl->SetValue(Lowercase);
5453 }
5454 
OnCreateTable(wxCommandEvent & WXUNUSED (event))5455 void DumpPostGISDialog::OnCreateTable(wxCommandEvent & WXUNUSED(event))
5456 {
5457 //
5458 // Create Table check box
5459 //
5460   wxCheckBox *createCtrl = (wxCheckBox *) FindWindow(ID_POSTGIS_CREATE);
5461   wxCheckBox *spindexCtrl = (wxCheckBox *) FindWindow(ID_POSTGIS_SPINDEX);
5462   if (CreateTable == true)
5463     {
5464       CreateTable = false;
5465       SpatialIndex = false;
5466       spindexCtrl->SetValue(false);
5467       spindexCtrl->Enable(false);
5468   } else
5469     {
5470       CreateTable = true;
5471       SpatialIndex = true;
5472       spindexCtrl->SetValue(true);
5473       spindexCtrl->Enable(true);
5474     }
5475   createCtrl->SetValue(CreateTable);
5476 }
5477 
OnSpatialIndex(wxCommandEvent & WXUNUSED (event))5478 void DumpPostGISDialog::OnSpatialIndex(wxCommandEvent & WXUNUSED(event))
5479 {
5480 //
5481 // Spatial Index check box
5482 //
5483   wxCheckBox *spindexCtrl = (wxCheckBox *) FindWindow(ID_POSTGIS_SPINDEX);
5484   if (SpatialIndex == true)
5485     SpatialIndex = false;
5486   else
5487     SpatialIndex = true;
5488   spindexCtrl->SetValue(SpatialIndex);
5489 }
5490 
OnOk(wxCommandEvent & WXUNUSED (event))5491 void DumpPostGISDialog::OnOk(wxCommandEvent & WXUNUSED(event))
5492 {
5493 //
5494 // all done:
5495 //
5496   wxTextCtrl *schemaCtrl = (wxTextCtrl *) FindWindow(ID_POSTGIS_SCHEMA);
5497   SchemaName = schemaCtrl->GetValue();
5498   wxTextCtrl *tableCtrl = (wxTextCtrl *) FindWindow(ID_POSTGIS_TABLE);
5499   TableName = tableCtrl->GetValue();
5500   if (TableName.Len() < 1)
5501     {
5502       wxMessageBox(wxT("You must specify the PostGIS TABLE NAME !!!"),
5503                    wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5504       return;
5505     }
5506   wxDialog::EndModal(wxID_OK);
5507 }
5508 
Create(MyFrame * parent,wxString & dir_path,wxString & dxf_path)5509 bool DxfDialog::Create(MyFrame * parent, wxString & dir_path,
5510                        wxString & dxf_path)
5511 {
5512 //
5513 // creating the dialog
5514 //
5515   MainFrame = parent;
5516   DirPath = dir_path;
5517   DxfPath = dxf_path;
5518   Folder = false;
5519   OkPrefix = false;
5520   OkSingle = false;
5521   Force2D = false;
5522   Force3D = false;
5523   LinkedRings = false;
5524   UnlinkedRings = false;
5525   ImportMixed = false;
5526   AppendMode = true;
5527   if (wxDialog::Create(parent, wxID_ANY, wxT("Import DXF Drawings")) == false)
5528     return false;
5529 // populates individual controls
5530   CreateControls();
5531 // sets dialog sizer
5532   GetSizer()->Fit(this);
5533   GetSizer()->SetSizeHints(this);
5534 // centers the dialog window
5535   Centre();
5536   return true;
5537 }
5538 
CreateControls()5539 void DxfDialog::CreateControls()
5540 {
5541 //
5542 // creating individual control and setting initial values
5543 //
5544   wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
5545   this->SetSizer(topSizer);
5546   wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
5547   topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
5548   wxBoxSizer *row0Sizer = new wxBoxSizer(wxVERTICAL);
5549   boxSizer->Add(row0Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
5550 // first row: the path and file/folder selection
5551   wxBoxSizer *pathSizer = new wxBoxSizer(wxHORIZONTAL);
5552   row0Sizer->Add(pathSizer, 0, wxALIGN_CENTRE_VERTICAL | wxALL, 0);
5553   wxStaticBox *pathBox = new wxStaticBox(this, wxID_STATIC,
5554                                          wxT("Import from source"),
5555                                          wxDefaultPosition,
5556                                          wxDefaultSize);
5557   wxBoxSizer *pthSizer = new wxStaticBoxSizer(pathBox, wxVERTICAL);
5558   pathSizer->Add(pthSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
5559   wxStaticText *pathLabel = new wxStaticText(this, ID_DXF_PATH, DxfPath);
5560   pthSizer->Add(pathLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0);
5561   wxString dxfFolder[2];
5562   dxfFolder[0] = wxT("Import &selected DXF drawing file only");
5563   dxfFolder[1] = wxT("Import &any DXF drawing file from selected folder");
5564   wxRadioBox *dxfFolderSel = new wxRadioBox(this, ID_DXF_FOLDER,
5565                                             wxT("&Source selection"),
5566                                             wxDefaultPosition,
5567                                             wxDefaultSize, 2,
5568                                             dxfFolder, 2,
5569                                             wxRA_SPECIFY_ROWS);
5570   dxfFolderSel->SetSelection(0);
5571   pthSizer->Add(dxfFolderSel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
5572 // second row: SRID / Append
5573   wxBoxSizer *sridSizer = new wxBoxSizer(wxHORIZONTAL);
5574   boxSizer->Add(sridSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
5575   wxStaticText *sridLabel = new wxStaticText(this, wxID_STATIC, wxT("&SRID:"));
5576   sridSizer->Add(sridLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5577   wxSpinCtrl *sridCtrl = new wxSpinCtrl(this, ID_DXF_SRID, wxEmptyString,
5578                                         wxDefaultPosition, wxSize(80, 20),
5579                                         wxSP_ARROW_KEYS,
5580                                         -1, 1000000, -1);
5581   sridSizer->Add(sridCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5582   wxCheckBox *AppendCtrl = new wxCheckBox(this, ID_DXF_APPEND,
5583                                           wxT
5584                                           ("Append to already exixing tables"),
5585                                           wxDefaultPosition, wxDefaultSize);
5586   sridSizer->Add(AppendCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5587   AppendCtrl->SetValue(true);
5588 // third row: table-name prefix
5589   wxStaticBox *prefixBox = new wxStaticBox(this, wxID_STATIC,
5590                                            wxT("Prefix for DB Table names"),
5591                                            wxDefaultPosition,
5592                                            wxDefaultSize);
5593   wxBoxSizer *prefSizer = new wxStaticBoxSizer(prefixBox, wxHORIZONTAL);
5594   boxSizer->Add(prefSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
5595   wxCheckBox *okPrefCtrl = new wxCheckBox(this, ID_DXF_OK_PREFIX,
5596                                           wxT(""),
5597                                           wxDefaultPosition, wxDefaultSize);
5598   prefSizer->Add(okPrefCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
5599   okPrefCtrl->SetValue(false);
5600   wxTextCtrl *PrefValue = new wxTextCtrl(this, ID_DXF_PREFIX,
5601                                          wxT(""), wxDefaultPosition,
5602                                          wxSize(250, 22));
5603   PrefValue->Enable(false);
5604   prefSizer->Add(PrefValue, 0, wxALIGN_RIGHT | wxALL, 0);
5605 // fourth row: single selected DXF layer
5606   wxStaticBox *singleBox = new wxStaticBox(this, wxID_STATIC,
5607                                            wxT
5608                                            ("Select a single DXF layer to be imported"),
5609                                            wxDefaultPosition,
5610                                            wxDefaultSize);
5611   wxBoxSizer *selSizer = new wxStaticBoxSizer(singleBox, wxHORIZONTAL);
5612   boxSizer->Add(selSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
5613   wxCheckBox *okSingleCtrl = new wxCheckBox(this, ID_DXF_OK_SINGLE,
5614                                             wxT(""),
5615                                             wxDefaultPosition, wxDefaultSize);
5616   selSizer->Add(okSingleCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
5617   okSingleCtrl->SetValue(false);
5618   wxTextCtrl *SingleValue = new wxTextCtrl(this, ID_DXF_SINGLE,
5619                                            wxT(""), wxDefaultPosition,
5620                                            wxSize(250, 22));
5621   SingleValue->Enable(false);
5622   selSizer->Add(SingleValue, 0, wxALIGN_RIGHT | wxALL, 0);
5623 // fifth row: dimensions
5624   wxString dxfDims[3];
5625   dxfDims[0] = wxT("&authomatic 2D/3D");
5626   dxfDims[1] = wxT("always force 2D");
5627   dxfDims[2] = wxT("always force 3D");
5628   wxRadioBox *dxfDimsSel = new wxRadioBox(this, ID_DXF_DIMS,
5629                                           wxT("&Dimensions"),
5630                                           wxDefaultPosition,
5631                                           wxDefaultSize, 3,
5632                                           dxfDims, 3,
5633                                           wxRA_SPECIFY_COLS);
5634   dxfDimsSel->SetSelection(0);
5635   boxSizer->Add(dxfDimsSel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
5636 // sixth row: import mode
5637   wxString dxfMode[3];
5638   dxfMode[0] = wxT("preserve &distinct DXF layers");
5639   dxfMode[1] = wxT("&mixed layers (distinct by type)");
5640   wxRadioBox *dxfModeSel = new wxRadioBox(this, ID_DXF_MIXED,
5641                                           wxT("&Import mode"),
5642                                           wxDefaultPosition,
5643                                           wxDefaultSize, 2,
5644                                           dxfMode, 2,
5645                                           wxRA_SPECIFY_COLS);
5646   dxfModeSel->SetSelection(0);
5647   boxSizer->Add(dxfModeSel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
5648 // seventh row: import mode
5649   wxString dxfRings[3];
5650   dxfRings[0] = wxT("&none");
5651   dxfRings[1] = wxT("&linked rings");
5652   dxfRings[2] = wxT("&unlinked rings");
5653   wxRadioBox *dxfRingsSel = new wxRadioBox(this, ID_DXF_RINGS,
5654                                            wxT
5655                                            ("&Special Rings handling (holes)"),
5656                                            wxDefaultPosition,
5657                                            wxDefaultSize, 3,
5658                                            dxfRings, 3,
5659                                            wxRA_SPECIFY_COLS);
5660   dxfRingsSel->SetSelection(0);
5661   boxSizer->Add(dxfRingsSel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
5662 // OK - CANCEL buttons
5663   wxBoxSizer *okCancelBox = new wxBoxSizer(wxHORIZONTAL);
5664   boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
5665   wxButton *ok = new wxButton(this, wxID_OK, wxT("&OK"));
5666   okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5667   wxButton *cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
5668   okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
5669 // appends event handler for OK button
5670   Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
5671           (wxObjectEventFunction) & DxfDialog::OnOk);
5672 // appends event handlers for radio buttons etc
5673   Connect(ID_DXF_FOLDER, wxEVT_COMMAND_RADIOBOX_SELECTED,
5674           (wxObjectEventFunction) & DxfDialog::OnFolder);
5675   Connect(ID_DXF_OK_PREFIX, wxEVT_COMMAND_CHECKBOX_CLICKED,
5676           (wxObjectEventFunction) & DxfDialog::OnPrefixChanged);
5677   Connect(ID_DXF_OK_SINGLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
5678           (wxObjectEventFunction) & DxfDialog::OnSingleLayerChanged);
5679   Connect(ID_DXF_DIMS, wxEVT_COMMAND_RADIOBOX_SELECTED,
5680           (wxObjectEventFunction) & DxfDialog::OnDimensionChanged);
5681   Connect(ID_DXF_MIXED, wxEVT_COMMAND_RADIOBOX_SELECTED,
5682           (wxObjectEventFunction) & DxfDialog::OnModeChanged);
5683   Connect(ID_DXF_RINGS, wxEVT_COMMAND_RADIOBOX_SELECTED,
5684           (wxObjectEventFunction) & DxfDialog::OnRingsChanged);
5685 }
5686 
OnFolder(wxCommandEvent & WXUNUSED (event))5687 void DxfDialog::OnFolder(wxCommandEvent & WXUNUSED(event))
5688 {
5689 //
5690 // File/Folder radio box
5691 //
5692   wxRadioBox *folderSel = (wxRadioBox *) FindWindow(ID_DXF_FOLDER);
5693   wxStaticText *pathLabel = (wxStaticText *) FindWindow(ID_DXF_PATH);
5694   if (Folder == true)
5695     {
5696       Folder = false;
5697       folderSel->SetSelection(0);
5698       pathLabel->SetLabel(DxfPath);
5699   } else
5700     {
5701       Folder = true;
5702       folderSel->SetSelection(1);
5703       pathLabel->SetLabel(DirPath);
5704     }
5705 }
5706 
OnDimensionChanged(wxCommandEvent & WXUNUSED (event))5707 void DxfDialog::OnDimensionChanged(wxCommandEvent & WXUNUSED(event))
5708 {
5709 //
5710 // Dimensions radio box
5711 //
5712   wxRadioBox *dimsSel = (wxRadioBox *) FindWindow(ID_DXF_DIMS);
5713   Force2D = false;
5714   Force3D = false;
5715   if (dimsSel->GetSelection() == 1)
5716     {
5717       Force2D = true;
5718       Force3D = false;
5719     }
5720   if (dimsSel->GetSelection() == 2)
5721     {
5722       Force2D = false;
5723       Force3D = true;
5724     }
5725 }
5726 
OnRingsChanged(wxCommandEvent & WXUNUSED (event))5727 void DxfDialog::OnRingsChanged(wxCommandEvent & WXUNUSED(event))
5728 {
5729 //
5730 // Rings radio box
5731 //
5732   wxRadioBox *ringsSel = (wxRadioBox *) FindWindow(ID_DXF_RINGS);
5733   LinkedRings = false;
5734   UnlinkedRings = false;
5735   if (ringsSel->GetSelection() == 1)
5736     {
5737       LinkedRings = true;
5738       UnlinkedRings = false;
5739     }
5740   if (ringsSel->GetSelection() == 2)
5741     {
5742       LinkedRings = false;
5743       UnlinkedRings = true;
5744     }
5745 }
5746 
OnModeChanged(wxCommandEvent & WXUNUSED (event))5747 void DxfDialog::OnModeChanged(wxCommandEvent & WXUNUSED(event))
5748 {
5749 //
5750 // Import mode radio box
5751 //
5752   wxRadioBox *modeSel = (wxRadioBox *) FindWindow(ID_DXF_MIXED);
5753   ImportMixed = false;
5754   if (modeSel->GetSelection() == 1)
5755     ImportMixed = true;
5756 }
5757 
OnPrefixChanged(wxCommandEvent & WXUNUSED (event))5758 void DxfDialog::OnPrefixChanged(wxCommandEvent & WXUNUSED(event))
5759 {
5760 //
5761 // Prefix check-box
5762 //
5763   wxCheckBox *okCtrl = (wxCheckBox *) FindWindow(ID_DXF_OK_PREFIX);
5764   wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_DXF_PREFIX);
5765   if (okCtrl->IsChecked() == false)
5766     {
5767       OkPrefix = false;
5768       wxString val = wxT("");
5769       colCtrl->SetValue(val);
5770       colCtrl->Enable(false);
5771   } else
5772     {
5773       OkPrefix = true;
5774       wxString val = wxT("");
5775       colCtrl->SetValue(val);
5776       colCtrl->Enable(true);
5777     }
5778 }
5779 
OnSingleLayerChanged(wxCommandEvent & WXUNUSED (event))5780 void DxfDialog::OnSingleLayerChanged(wxCommandEvent & WXUNUSED(event))
5781 {
5782 //
5783 // selected Single Layer check-box
5784 //
5785   wxCheckBox *okCtrl = (wxCheckBox *) FindWindow(ID_DXF_OK_SINGLE);
5786   wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_DXF_SINGLE);
5787   if (okCtrl->IsChecked() == false)
5788     {
5789       OkSingle = false;
5790       wxString val = wxT("");
5791       colCtrl->SetValue(val);
5792       colCtrl->Enable(false);
5793   } else
5794     {
5795       OkSingle = true;
5796       wxString val = wxT("");
5797       colCtrl->SetValue(val);
5798       colCtrl->Enable(true);
5799     }
5800 }
5801 
OnOk(wxCommandEvent & WXUNUSED (event))5802 void DxfDialog::OnOk(wxCommandEvent & WXUNUSED(event))
5803 {
5804 //
5805 // all done:
5806 //
5807   if (OkPrefix == true)
5808     {
5809       wxTextCtrl *prefixCtrl = (wxTextCtrl *) FindWindow(ID_DXF_PREFIX);
5810       Prefix = prefixCtrl->GetValue();
5811       if (Prefix.Len() < 1)
5812         {
5813           wxMessageBox(wxT("You must specify some DB Table-name Prefix !!!"),
5814                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5815           return;
5816         }
5817     }
5818   if (OkSingle == true)
5819     {
5820       wxTextCtrl *singleCtrl = (wxTextCtrl *) FindWindow(ID_DXF_SINGLE);
5821       SingleLayer = singleCtrl->GetValue();
5822       if (SingleLayer.Len() < 1)
5823         {
5824           wxMessageBox(wxT("You must specify some DXF Layer name !!!"),
5825                        wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
5826           return;
5827         }
5828     }
5829   if (OkPrefix == true)
5830     {
5831       wxTextCtrl *colCtrl = (wxTextCtrl *) FindWindow(ID_DXF_PREFIX);
5832       Prefix = colCtrl->GetValue();
5833   } else
5834     Prefix = wxT("");
5835   wxSpinCtrl *sridCtrl = (wxSpinCtrl *) FindWindow(ID_DXF_SRID);
5836   Srid = sridCtrl->GetValue();
5837   if (Srid <= 0)
5838     ;
5839   else if (MainFrame->SridNotExists(Srid) == true)
5840     {
5841       wxMessageBox(wxT("invalid SRID value"), wxT("spatialite_gui"),
5842                    wxOK | wxICON_WARNING, this);
5843       return;
5844     }
5845   wxCheckBox *appendCtrl = (wxCheckBox *) FindWindow(ID_DXF_APPEND);
5846   AppendMode = appendCtrl->IsChecked();
5847   wxDialog::EndModal(wxID_OK);
5848 }
5849