]>
Commit | Line | Data |
---|---|---|
c92b0f9a | 1 | //---------------------------------------------------------------------------------------- |
b5ffecfc GT |
2 | // Name: dbbrowse.cpp |
3 | // Purpose: Through ODBC - Databases Browsen | |
829c421b | 4 | // Author: Mark Johnson |
b5ffecfc GT |
5 | // Modified by: |
6 | // BJO : Bart A.M. JOURQUIN | |
7 | // Created: 19991127 | |
8 | // Copyright: (c) Mark Johnson | |
9 | // Licence: wxWindows license | |
c09d434d | 10 | // RCS-ID: $Id$ |
c92b0f9a MJ |
11 | //---------------------------------------------------------------------------------------- |
12 | //-- all #ifdefs that the whole Project needs. ------------------------------------------- | |
13 | //---------------------------------------------------------------------------------------- | |
b5ffecfc | 14 | #ifdef __GNUG__ |
645889ad GT |
15 | #pragma implementation |
16 | #pragma interface | |
b5ffecfc | 17 | #endif |
c92b0f9a | 18 | //---------------------------------------------------------------------------------------- |
b5ffecfc GT |
19 | // For compilers that support precompilation, includes "wx/wx.h". |
20 | #include "wx/wxprec.h" | |
c92b0f9a | 21 | //---------------------------------------------------------------------------------------- |
b5ffecfc | 22 | #ifdef __BORLANDC__ |
645889ad | 23 | #pragma hdrstop |
b5ffecfc | 24 | #endif |
c92b0f9a | 25 | //---------------------------------------------------------------------------------------- |
b5ffecfc | 26 | #ifndef WX_PRECOMP |
645889ad | 27 | #include "wx/wx.h" |
b5ffecfc | 28 | #endif |
5d2ac6b8 WS |
29 | |
30 | #include "wx/stockitem.h" | |
c92b0f9a | 31 | //---------------------------------------------------------------------------------------- |
b5ffecfc | 32 | #ifndef __WXMSW__ |
645889ad | 33 | #include "bitmaps/logo.xpm" |
a1c5f7a3 | 34 | #endif |
c92b0f9a MJ |
35 | //---------------------------------------------------------------------------------------- |
36 | //-- all #includes that every .cpp needs --- 19990807.mj10777 ---------------- | |
37 | //---------------------------------------------------------------------------------------- | |
b5ffecfc | 38 | #include "std.h" // sorgsam Pflegen ! |
a1c5f7a3 | 39 | // #include <iostream> |
c92b0f9a MJ |
40 | //---------------------------------------------------------------------------------------- |
41 | //-- Some Global Vars for this file ------------------------------------------------------ | |
42 | //---------------------------------------------------------------------------------------- | |
b5ffecfc | 43 | BEGIN_EVENT_TABLE(MainFrame, wxFrame) |
5d2ac6b8 WS |
44 | EVT_MENU(wxID_EXIT, MainFrame::OnQuit) // Program End |
45 | EVT_MENU(wxID_ABOUT, MainFrame::OnAbout) // Program Discription | |
46 | EVT_MENU(wxID_HELP, MainFrame::OnHelp) // Program Help | |
b5ffecfc | 47 | END_EVENT_TABLE() |
645889ad | 48 | |
c92b0f9a | 49 | //---------------------------------------------------------------------------------------- |
a1c5f7a3 | 50 | IMPLEMENT_APP(MainApp) // This declares wxApp::MainApp as "the" Application |
645889ad | 51 | |
c92b0f9a MJ |
52 | //---------------------------------------------------------------------------------------- |
53 | // 'Main program' equivalent, creating windows and returning main app frame | |
54 | //---------------------------------------------------------------------------------------- | |
a1c5f7a3 | 55 | bool MainApp::OnInit(void) // Does everything needed for a program start |
b5ffecfc | 56 | { |
645889ad GT |
57 | wxString Temp0; // Use as needed |
58 | //--------------------------------------------------------------------------------------- | |
59 | // set the language to use // Help.?? (.std = english, .de = german etc.) | |
daf06bb8 JS |
60 | const wxChar *language = NULL; // czech, german, french, polish |
61 | const wxChar *langid = NULL; // std = english , cz, de = german, fr = french, pl = polish | |
645889ad GT |
62 | wxString s_LangHelp; // Directory/Filename.hhp of the Help-Project file |
63 | wxString s_LangId, s_Language; | |
64 | s_Language.Empty(); s_LangId.Empty(); s_LangHelp.Empty(); | |
65 | //--------------------------------------------------------------------------------------- | |
66 | //-- Graphic File suport - use only when needed, otherwise big .exe's | |
67 | //--------------------------------------------------------------------------------------- | |
b5ffecfc | 68 | #if wxUSE_LIBPNG |
645889ad | 69 | wxImage::AddHandler( new wxPNGHandler ); // needed for help System |
b5ffecfc GT |
70 | #endif |
71 | /* | |
645889ad GT |
72 | #if wxUSE_LIBJPEG |
73 | wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's | |
74 | #endif | |
75 | wxImage::AddHandler( new wxGIFHandler ); // use only when needed, otherwise big .exe's | |
76 | wxImage::AddHandler( new wxPCXHandler ); // use only when needed, otherwise big .exe's | |
77 | wxImage::AddHandler( new wxPNMHandler ); // use only when needed, otherwise big .exe's | |
b5ffecfc GT |
78 | */ |
79 | #ifdef __WXMSW__ | |
645889ad GT |
80 | // wxBitmap::AddHandler( new wxXPMFileHandler ); // Attempt to use XPS instead of ico |
81 | // wxBitmap::AddHandler( new wxXPMDataHandler ); // - Attempt failed | |
b5ffecfc | 82 | #endif |
645889ad GT |
83 | //--------------------------------------------------------------------------------------- |
84 | switch ( argc ) | |
85 | { | |
86 | default: | |
87 | // ignore the other args, fall through | |
88 | case 3: | |
89 | language = argv[2]; // czech, english, french, german , polish | |
90 | langid = argv[1]; // cz, std, fr, de , pl | |
91 | break; | |
92 | case 2: | |
93 | langid = argv[1]; // cz, std, fr, de , pl | |
94 | break; | |
95 | case 1: | |
5890ad78 | 96 | case 0: |
645889ad GT |
97 | break; |
98 | }; | |
99 | //--------------------------------------------------------------------------------------- | |
100 | // Win-Registry : Workplace\HKEY_CURRENT_USERS\Software\%GetVendorName()\%GetAppName() | |
101 | //--------------------------------------------------------------------------------------- | |
daf06bb8 | 102 | SetVendorName(_T("mj10777")); // Needed to get Configuration Information |
5d2ac6b8 | 103 | SetAppName(_T("DBBrowse")); // "" , also needed for s_LangHelp |
645889ad GT |
104 | //--------------------------------------------------------------------------------------- |
105 | // we're using wxConfig's "create-on-demand" feature: it will create the | |
106 | // config object when it's used for the first time. It has a number of | |
107 | // advantages compared with explicitly creating our wxConfig: | |
108 | // 1) we don't pay for it if we don't use it | |
109 | // 2) there is no danger to create it twice | |
5d2ac6b8 | 110 | |
645889ad GT |
111 | // application and vendor name are used by wxConfig to construct the name |
112 | // of the config file/registry key and must be set before the first call | |
113 | // to Get() if you want to override the default values (the application | |
114 | // name is the name of the executable and the vendor name is the same) | |
115 | //--------------------------------------------------------------------------------------- | |
116 | p_ProgramCfg = wxConfigBase::Get(); // Get Program Configuration from Registry | |
117 | // p_ProgramCfg->DeleteAll(); // This is how the Config can be erased | |
daf06bb8 | 118 | p_ProgramCfg->SetPath(_T("/")); // Start at root |
645889ad GT |
119 | //--------------------------------------------------------------------------------------- |
120 | //-- Set the Language and remember it for the next time. -------------------------------- | |
121 | //--------------------------------------------------------------------------------------- | |
122 | if (langid == NULL) // No Parameter was given | |
123 | { | |
124 | Temp0.Empty(); | |
daf06bb8 | 125 | p_ProgramCfg->Read(_T("/Local/langid"),&Temp0); // >const char *langid< can't be used here |
5d2ac6b8 | 126 | if (Temp0.empty()) |
daf06bb8 | 127 | langid = _T("std"); // Standard language is "std" = english |
645889ad GT |
128 | else |
129 | langid = Temp0; | |
130 | } | |
daf06bb8 | 131 | Temp0.Printf(_T("%s"),langid); |
645889ad GT |
132 | //--------------------------------------------------------------------------------------- |
133 | // Support the following languages (std = english) | |
daf06bb8 JS |
134 | if ((Temp0 == _T("a")) || (Temp0 == _T("cz")) || (Temp0 == _T("de")) || |
135 | (Temp0 == _T("fr")) || (Temp0 == _T("pl"))) | |
645889ad | 136 | { // The three-letter language-string codes are only valid in Windows NT and Windows 95. |
daf06bb8 JS |
137 | if (Temp0 == _T("cz")) |
138 | language = _T("czech"); // csy or czech | |
139 | if ((Temp0 == _T("de")) || (Temp0 == _T("a"))) | |
645889ad | 140 | { |
daf06bb8 JS |
141 | language = _T("german"); // deu or german |
142 | if (Temp0 == _T("a")) | |
143 | { langid = Temp0 = _T("de"); } // Austrian = german | |
645889ad | 144 | } // german / austrian |
daf06bb8 JS |
145 | if (Temp0 == _T("fr")) |
146 | language = _T("french"); // fra or french | |
147 | if (Temp0 == _T("pl")) | |
148 | language = _T("polish"); // plk or polish | |
645889ad GT |
149 | if (!m_locale.Init(language, langid, language)) // Don't do this for english (std) |
150 | { // You should recieve errors here for cz and pl since there is no cz/ and pl/ directory | |
daf06bb8 JS |
151 | wxLogMessage(_T("-E-> %s : SetLocale error : langid(%s) ; language(%s)"),GetAppName().c_str(),langid,language); |
152 | langid = _T("std"); | |
153 | language = _T("C"); // english, english-aus , -can , -nz , -uk , -usa | |
645889ad GT |
154 | } |
155 | else | |
156 | { // Read in Foreign language's text for GetAppName() and Help | |
157 | Temp0 = GetAppName(); | |
158 | Temp0 = Temp0.Lower(); | |
159 | m_locale.AddCatalog(Temp0.c_str()); | |
daf06bb8 | 160 | m_locale.AddCatalog(_T("help")); |
645889ad GT |
161 | } |
162 | } // Support the following languages (std = english) | |
163 | else | |
164 | { | |
daf06bb8 JS |
165 | langid = _T("std"); |
166 | language = _T("C"); // english, english-aus , -can , -nz , -uk , -usa | |
645889ad | 167 | } |
daf06bb8 JS |
168 | s_Language.Printf(_T("%s"),language); // language is a pointer |
169 | s_LangId.Printf(_T("%s"),langid); // langid is a pointer | |
170 | p_ProgramCfg->Write(_T("/Local/language"),s_Language); | |
171 | p_ProgramCfg->Write(_T("/Local/langid"),s_LangId); | |
172 | s_LangHelp.Printf(_T("help.%s/%s.hhp"),s_LangId.c_str(),GetAppName().c_str()); // "help.std/Garantie.hhp"; | |
645889ad GT |
173 | s_LangHelp = s_LangHelp.Lower(); // A must for Linux |
174 | //--------------------------------------------------------------------------------------- | |
daf06bb8 JS |
175 | Temp0 = _T("NONE"); // I don't remember why I did this |
176 | p_ProgramCfg->Write(_T("/NONE"),Temp0); // I don't remember why I did this | |
177 | p_ProgramCfg->Write(_T("/Paths/NONE"),Temp0); // I don't remember why I did this | |
178 | p_ProgramCfg->Write(_T("/MainFrame/NONE"),Temp0); // I don't remember why I did this | |
645889ad | 179 | //--------------------------------------------------------------------------------------- |
daf06bb8 JS |
180 | p_ProgramCfg->Write(_T("/Paths/Work"),wxGetCwd()); // Get current Working Path |
181 | p_ProgramCfg->SetPath(_T("/")); | |
645889ad GT |
182 | //--------------------------------------------------------------------------------------- |
183 | // restore frame position and size, if empty start Values (1,1) and (750,600) | |
daf06bb8 JS |
184 | int x = p_ProgramCfg->Read(_T("/MainFrame/x"), 1), y = p_ProgramCfg->Read(_T("/MainFrame/y"), 1), |
185 | w = p_ProgramCfg->Read(_T("/MainFrame/w"), 750), h = p_ProgramCfg->Read(_T("/MainFrame/h"), 600); | |
645889ad GT |
186 | //--------------------------------------------------------------------------------------- |
187 | // Create the main frame window | |
daf06bb8 JS |
188 | Temp0.Printf(_T("%s - %s"),GetAppName().c_str(),GetVendorName().c_str()); |
189 | frame = new MainFrame((wxFrame *) NULL,(wxChar *) Temp0.c_str(),wxPoint(x,y),wxSize(w,h)); | |
645889ad | 190 | //--------------------------------------------------------------------------------------- |
a0d9c6cb | 191 | // Set the Backgroundcolour (only needed if you are NOT using wxSYS_COLOUR_BACKGROUND) |
e1c6c6ae | 192 | frame->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND)); |
645889ad GT |
193 | // frame->SetBackgroundColour(wxColour(255, 255, 255)); |
194 | // frame->SetBackgroundColour(* wxWHITE); | |
195 | //--------------------------------------------------------------------------------------- | |
196 | // Give it an icon | |
197 | //--------------------------------------------------------------------------------------- | |
198 | // 12.02.2000 - Guillermo Rodriguez Garcia : | |
199 | //--------------------------------------------------------------------------------------- | |
200 | // This is different for Win9x and WinNT; one of them takes the first ico | |
201 | // in the .rc file, while the other takes the icon with the lowest name, | |
202 | // so to be sure that it always work, put your icon the first *and* give | |
203 | // it a name such a 'appicon' or something. | |
204 | //--------------------------------------------------------------------------------------- | |
205 | // mj10777 : any special rule in Linux ? | |
206 | //--------------------------------------------------------------------------------------- | |
207 | frame->SetIcon(wxICON(aLogo)); // lowest name and first entry in RC File | |
208 | //--------------------------------------------------------------------------------------- | |
209 | // Make a menubar | |
210 | wxMenu *file_menu = new wxMenu; | |
211 | wxMenu *help_menu = new wxMenu; | |
5d2ac6b8 WS |
212 | |
213 | help_menu->Append(wxID_HELP, wxGetStockLabel(wxID_HELP)); | |
645889ad | 214 | help_menu->AppendSeparator(); |
5d2ac6b8 WS |
215 | help_menu->Append(wxID_ABOUT, _("&About")); |
216 | file_menu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT)); | |
217 | ||
645889ad GT |
218 | wxMenuBar *menu_bar = new wxMenuBar; |
219 | menu_bar->Append(file_menu, _("&File")); | |
220 | menu_bar->Append(help_menu, _("&Help")); | |
221 | frame->SetMenuBar(menu_bar); | |
67a99992 | 222 | #if wxUSE_STATUSBAR |
645889ad GT |
223 | frame->CreateStatusBar(1); |
224 | Temp0.Printf(_("%s has started !"),p_ProgramCfg->GetAppName().c_str()); | |
225 | frame->SetStatusText(Temp0, 0); | |
67a99992 | 226 | #endif // wxUSE_STATUSBAR |
645889ad GT |
227 | //--------------------------------------------------------------------------------------- |
228 | int width, height; | |
229 | frame->GetClientSize(&width, &height); | |
230 | //--------------------------------------------------------------------------------------- | |
5151c7af | 231 | frame->p_Splitter = new DocSplitterWindow(frame,wxID_ANY); |
645889ad GT |
232 | // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL)); |
233 | frame->pDoc = new MainDoc(); | |
234 | frame->pDoc->p_MainFrame = frame; | |
235 | frame->pDoc->p_Splitter = frame->p_Splitter; | |
236 | frame->pDoc->p_Splitter->pDoc = frame->pDoc; // ControlBase: saving the Sash | |
237 | //--------------------------------------------------------------------------------------- | |
3103e8a9 | 238 | //-- Problem : GetClientSize(Width,Height) are not the same as the values given in the --- |
645889ad GT |
239 | //-- construction of the Frame. --- |
240 | //-- Solved : GetClientSize is called here and the difference is noted. When the --- | |
241 | //-- Window is closed the diff. is added to the result of GetClientSize. --- | |
242 | //--------------------------------------------------------------------------------------- | |
243 | frame->GetClientSize(&frame->DiffW, &frame->DiffH); frame->DiffW-=w; frame->DiffH-=h; | |
244 | //---------------------------------------------------------------------------- | |
245 | //-- Help : Load the help.%langid/%GetAppName().hhp (help.std/dbbrowse.hhp) file --- | |
246 | //---------------------------------------------------------------------------- | |
247 | frame->p_Help = new wxHtmlHelpController(); // construct the Help System | |
248 | frame->p_Help->UseConfig(p_ProgramCfg); // Don't rember what this was for | |
249 | // You should recieve errors here for fr since there is no help.fr/ directory | |
250 | if (!frame->p_Help->AddBook(s_LangHelp)) // Use the language set | |
251 | { // You should recieve errors here for fr since there is no help.fr/ but a fr/ directory | |
daf06bb8 | 252 | wxLogMessage(_T("-E-> %s : AddBook error : s_LangHelp(%s)"),GetAppName().c_str(),s_LangHelp.c_str()); |
645889ad GT |
253 | } |
254 | frame->pDoc->p_Help = frame->p_Help; // Save the information to the document | |
255 | //--------------------------------------------------------------------------------------- | |
5151c7af | 256 | frame->Show(true); // Show the frame |
645889ad GT |
257 | SetTopWindow(frame); // At this point the frame can be seen |
258 | //--------------------------------------------------------------------------------------- | |
259 | // If you need a "Splash Screen" because of a long OnNewDocument, do it here | |
260 | if (!frame->pDoc->OnNewDocument()) | |
5151c7af | 261 | frame->Close(true); |
645889ad GT |
262 | // Kill a "Splash Screen" because OnNewDocument, if you have one |
263 | //--------------------------------------------------------------------------------------- | |
5151c7af WS |
264 | p_ProgramCfg->Flush(true); // save the configuration |
265 | return true; | |
c92b0f9a | 266 | } // bool MainApp::OnInit(void) |
645889ad | 267 | |
c92b0f9a | 268 | //---------------------------------------------------------------------------------------- |
b5ffecfc | 269 | // My frame constructor |
c92b0f9a | 270 | //---------------------------------------------------------------------------------------- |
daf06bb8 | 271 | MainFrame::MainFrame(wxFrame *frame, wxChar *title, const wxPoint& pos, const wxSize& size): |
5151c7af | 272 | wxFrame(frame, wxID_ANY, title, pos, size) |
b5ffecfc | 273 | { |
645889ad GT |
274 | p_Splitter = NULL; pDoc = NULL; p_Help = NULL; // Keep the Pointers clean ! |
275 | //--- Everything else is done in MainApp::OnInit() -------------------------------------- | |
b5ffecfc | 276 | } |
645889ad | 277 | |
c92b0f9a | 278 | //---------------------------------------------------------------------------------------- |
b5ffecfc GT |
279 | MainFrame::~MainFrame(void) |
280 | { | |
645889ad GT |
281 | // Close the help frame; this will cause the config data to get written. |
282 | if (p_Help->GetFrame()) // returns NULL if no help frame active | |
5151c7af | 283 | p_Help->GetFrame()->Close(true); |
645889ad GT |
284 | delete p_Help; // Memory Leak |
285 | p_Help = NULL; | |
286 | // save the control's values to the config | |
287 | if (p_ProgramCfg == NULL) | |
288 | return; | |
289 | // save the frame position before it is destroyed | |
290 | int x, y, w, h; | |
291 | GetPosition(&x, &y); | |
292 | GetClientSize(&w, &h); w -= DiffW; h -= DiffH; | |
daf06bb8 JS |
293 | p_ProgramCfg->Write(_T("/MainFrame/x"), (long) x); |
294 | p_ProgramCfg->Write(_T("/MainFrame/y"), (long) y); | |
295 | p_ProgramCfg->Write(_T("/MainFrame/w"), (long) w); | |
296 | p_ProgramCfg->Write(_T("/MainFrame/h"), (long) h); | |
297 | p_ProgramCfg->Write(_T("/MainFrame/Sash"), (long) pDoc->Sash); | |
645889ad GT |
298 | // clean up: Set() returns the active config object as Get() does, but unlike |
299 | // Get() it doesn't try to create one if there is none (definitely not what | |
300 | // we want here!) | |
301 | // delete wxConfigBase::Set((wxConfigBase *) NULL); | |
5151c7af | 302 | p_ProgramCfg->Flush(true); // saves Objekt |
645889ad GT |
303 | if (pDoc) // If we have a Valid Document |
304 | delete pDoc; // Cleanup (MainDoc::~MainDoc) | |
a1c5f7a3 | 305 | } // MainFrame::~MainFrame(void) |
645889ad | 306 | |
c92b0f9a | 307 | //---------------------------------------------------------------------------------------- |
b5ffecfc GT |
308 | void MainFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
309 | { | |
5151c7af | 310 | Close(true); |
b5ffecfc | 311 | } |
645889ad | 312 | |
c92b0f9a | 313 | //---------------------------------------------------------------------------------------- |
b5ffecfc GT |
314 | void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
315 | { | |
645889ad | 316 | wxString Temp0, Temp1; |
829c421b | 317 | Temp0.Printf(_("%s\nMark Johnson\nBerlin, Germany\nwxWindows@mj10777.de\n (c) 2000"),p_ProgramCfg->GetAppName().c_str()); |
645889ad GT |
318 | Temp1.Printf(_("About %s"),p_ProgramCfg->GetAppName().c_str()); |
319 | wxMessageDialog dialog(this, Temp0,Temp1,wxOK|wxCANCEL); | |
320 | dialog.ShowModal(); | |
b5ffecfc | 321 | } |
645889ad | 322 | |
c92b0f9a | 323 | //---------------------------------------------------------------------------------------- |
b5ffecfc GT |
324 | void MainFrame::OnHelp(wxCommandEvent& WXUNUSED(event)) |
325 | { | |
daf06bb8 | 326 | p_Help->Display(_T("Main page")); |
b5ffecfc | 327 | } |
c92b0f9a | 328 | //---------------------------------------------------------------------------------------- |