]> git.saurik.com Git - wxWidgets.git/blob - demos/dbbrowse/dbbrowse.cpp
First version of the DbBrowser demo program
[wxWidgets.git] / demos / dbbrowse / dbbrowse.cpp
1 //------------------------------------------------------------------------------
2 // Name: dbbrowse.cpp
3 // Purpose: Through ODBC - Databases Browsen
4 // Author: Mark Johnson, mj10777@gmx.net
5 // Modified by:
6 // BJO : Bart A.M. JOURQUIN
7 // Created: 19991127
8 // Copyright: (c) Mark Johnson
9 // Licence: wxWindows license
10 //------------------------------------------------------------------------------
11 //-- all #ifdefs that the whole Project needs. ------------------------------
12 //---------------------------------------------------------------------------
13 #ifdef __GNUG__
14 #pragma implementation
15 #pragma interface
16 #endif
17 //---------------------------------------------------------------------------
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
20 //---------------------------------------------------------------------------
21 #ifdef __BORLANDC__
22 #pragma hdrstop
23 #endif
24 //---------------------------------------------------------------------------
25 #ifndef WX_PRECOMP
26 #include "wx/wx.h"
27 #endif
28 //---------------------------------------------------------------------------
29 #ifndef __WXMSW__
30 #endif
31 #include "bitmaps/logo.xpm"
32 //---------------------------------------------------------------------------
33 //-- all #includes that every .cpp needs --- 19990807.mj10777 ---
34 //---------------------------------------------------------------------------
35 #include "std.h" // sorgsam Pflegen !
36 #include <iostream>
37 //---------------------------------------------------------------------------
38 //-- Some Global Vars for this file ----------------------------------------
39 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 MainFrame *frame = NULL; // The one and only MainFrame
42 // wxLogNull logNo; // No Log messages
43 //---------------------------------------------------------------------------
44 // verify that the item is ok and insult the user if it is not
45 #define CHECK_ITEM(item) \
46 if (!item.IsOk()) \
47 { \
48 wxMessageBox(_("Please select some item first!"),_("Tree sample error"), \
49 wxOK | wxICON_EXCLAMATION,this); \
50 return; \
51 } \
52 //---------------------------------------------------------------------------
53 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
54 EVT_MENU(QUIT, MainFrame::OnQuit)
55 EVT_MENU(ABOUT, MainFrame::OnAbout)
56 EVT_MENU(HELP, MainFrame::OnHelp)
57 EVT_SIZE(MainFrame::OnSize)
58 END_EVENT_TABLE()
59 //---------------------------------------------------------------------------
60 IMPLEMENT_APP(MyApp)
61 //---------------------------------------------------------------------------
62 // `Main program' equivalent, creating windows and returning main app frame
63 //---------------------------------------------------------------------------
64 bool MyApp::OnInit(void)
65 {
66 //---------------------------------------------------------------------------------------
67 // set the language to use
68 const char *langhelp = NULL;
69 const char *language = NULL;
70 const char *langid = NULL;
71 //---------------------------------------------------------------------------------------
72 #if wxUSE_LIBPNG
73 wxImage::AddHandler( new wxPNGHandler ); // use only when needed, otherwise big .exe's
74 #endif
75 /*
76 #if wxUSE_LIBJPEG
77 wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's
78 #endif
79 wxImage::AddHandler( new wxGIFHandler ); // use only when needed, otherwise big .exe's
80 wxImage::AddHandler( new wxPCXHandler ); // use only when needed, otherwise big .exe's
81 wxImage::AddHandler( new wxPNMHandler ); // use only when needed, otherwise big .exe's
82 */
83 #ifdef __WXMSW__
84 // wxBitmap::AddHandler( new wxXPMFileHandler ); // use only when needed, otherwise big .exe's
85 // wxBitmap::AddHandler( new wxXPMDataHandler ); // use only when needed, otherwise big .exe's
86 #endif
87 //---------------------------------------------------------------------------------------
88 langid = "std"; // BJO20000125 instead of ""
89 switch ( argc )
90 {
91 default:
92 // ignore the other args, fall through
93 case 3:
94 language = argv[2];
95 langid = argv[1];
96 break;
97 case 2:
98 langid = argv[1];
99 break;
100 case 1:
101 break;
102 };
103 //---------------------------------------------------------------------------------------
104 // we're using wxConfig's "create-on-demand" feature: it will create the
105 // config object when it's used for the first time. It has a number of
106 // advantages compared with explicitly creating our wxConfig:
107 // 1) we don't pay for it if we don't use it
108 // 2) there is no danger to create it twice
109
110 // application and vendor name are used by wxConfig to construct the name
111 // of the config file/registry key and must be set before the first call
112 // to Get() if you want to override the default values (the application
113 // name is the name of the executable and the vendor name is the same)
114 //---------------------------------------------------------------------------------------
115 SetVendorName("mj10777");
116 SetAppName("DBBrowser"); // not needed, it's the default value
117 p_ProgramCfg = wxConfigBase::Get();
118 // p_ProgramCfg->DeleteAll();
119 p_ProgramCfg->SetPath("/");
120 wxString Temp0, Temp1;
121 Temp0.Empty();
122
123 //---------------------------------------------------------------------------------------
124 //-- Set the Language and remember it for the next time. --------------------------------
125 //---------------------------------------------------------------------------------------
126 langhelp = "help.std/dbbrowse.hhp";
127 if (langid == "std")
128 {
129 p_ProgramCfg->Read("/Local/langid",&Temp0); // >const char *langid< can't be used here
130 if (Temp0 == "")
131 langid = "std";
132 else
133 langid = Temp0;
134 }
135 Temp0 = langid;
136 p_ProgramCfg->Write("/Local/langid",Temp0); // >const char *langid< can't be used here
137 //---------------------------------------------------------------------------------------
138 // Support the following languages
139 if (Temp0 != "std")
140 {
141 if (Temp0 == "cz")
142 {
143 language = "czech"; // csy or czech
144 langhelp = "help.cz/dbbrowse.hhp";
145 }
146 if ((Temp0 == "de") || (Temp0 == "a"))
147 {
148 language = "german"; // deu or german
149 langhelp = "help.de/dbbrowse.hhp";
150 }
151 if (Temp0 == "fr")
152 {
153 language = "french"; // fra or french
154 langhelp = "help.fr/dbbrowse.hhp";
155 }
156 if (Temp0 == "pl")
157 {
158 language = "polish"; // plk or polish
159 langhelp = "help.pl/dbbrowse.hhp";
160 }
161 if (!m_locale.Init(language, langid, language)) // setlocale(LC_ALL,""); does not work
162 wxMessageBox("SetLocale error");
163 m_locale.AddCatalog("PgmText");
164 m_locale.AddCatalog("Help");
165 Temp0 = language;
166 p_ProgramCfg->Write("/Local/language",Temp0);
167 }
168 else
169 {
170 Temp0 = "english";
171 p_ProgramCfg->Write("/Local/language",Temp0);
172 Temp0 = "std"; // allways english if not german or french (at the moment austrian)
173 }
174
175 Temp0 = "NONE";
176 p_ProgramCfg->Write("/NONE",Temp0);
177 p_ProgramCfg->Write("/Paths/NONE",Temp0);
178 p_ProgramCfg->Write("/MainFrame/NONE",Temp0);
179 //-----------------------------------------------------------------------------
180 p_ProgramCfg->Write("/Paths/Work",wxGetCwd());
181 p_ProgramCfg->SetPath("/");
182 //-----------------------------------------------------------------------------
183 // or you could also write something like this:
184 // wxFileConfig *p_ProgramCfg = new wxFileConfig("conftest");
185 // wxConfigBase::Set(p_ProgramCfg);
186 // where you can also specify the file names explicitly if you wish.
187 // Of course, calling Set() is optional and you only must do it if
188 // you want to later retrieve this pointer with Get().
189 //----------------------------------------------------------------------------
190 // SetPath() understands ".."
191 // restore frame position and size
192 int x = p_ProgramCfg->Read("/MainFrame/x", 1), y = p_ProgramCfg->Read("/MainFrame/y", 1),
193 w = p_ProgramCfg->Read("/MainFrame/w", 600), h = p_ProgramCfg->Read("/MainFrame/h", 450);
194 //---------------------------------------------------------------------------------------
195 // Create the main frame window
196 frame = new MainFrame((wxFrame *) NULL, (char *) _("DBBrowser - mj10777"),x,y,w,h);
197 //---------------------------------------------------------------------------------------
198 // This reduces flicker effects - even better would be to define OnEraseBackground
199 // to do Temp0. When the list control's scrollbars are show or hidden, the
200 // frame is sent a background erase event.
201 //---------------------------------------------------------------------------------------
202 frame->SetBackgroundColour( *wxWHITE );
203 // frame->SetBackgroundColour(wxColour(255, 255, 255));
204
205 //---------------------------------------------------------------------------------------
206 // Make a menubar
207 wxMenu *file_menu = new wxMenu;
208 wxMenu *help_menu = new wxMenu;
209
210 help_menu->Append(HELP, _("&Help"));
211 help_menu->AppendSeparator();
212 help_menu->Append(ABOUT, _("&About"));
213 file_menu->Append(QUIT, _("E&xit"));
214
215 wxMenuBar *menu_bar = new wxMenuBar;
216 menu_bar->Append(file_menu, _("&File"));
217 menu_bar->Append(help_menu, _("&Help"));
218 frame->SetMenuBar(menu_bar);
219 frame->CreateStatusBar(1);
220 Temp0.Printf(_("%s has started !"),p_ProgramCfg->GetAppName().c_str());
221 frame->SetStatusText(Temp0, 0);
222 //---------------------------------------------------------------------------------------
223 int width, height;
224 frame->GetClientSize(&width, &height);
225
226 frame->p_Splitter = new DocSplitterWindow(frame, SPLITTER_WINDOW);
227
228 // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL));
229 frame->pDoc = new mjDoc();
230 frame->pDoc->p_MainFrame = frame;
231 frame->pDoc->p_Splitter = frame->p_Splitter;
232 frame->pDoc->p_Splitter->pDoc = frame->pDoc; // ControlBase: saving the Sash
233 if (!frame->pDoc->OnNewDocument())
234 frame->Close(TRUE);
235 // frame->Maximize();
236 // frame->SetSize(-1,-1); // the wxSplitter does not show correctly without this !
237 frame->SetClientSize(width, height); // the wxSplitter does not show correctly without this !
238 //---------------------------------------------------------------------------------------
239 //-- Problem : GetClientSize(Width,Hight) are not the same as the values given in the ---
240 //-- construction of the Frame. ---
241 //-- Solved : GetClientSize is called here and the difference is noted. When the ---
242 //-- Window is closed the diff. is added to the result of GetClientSize. ---
243 //---------------------------------------------------------------------------------------
244 frame->GetClientSize(&frame->DiffW, &frame->DiffH); frame->DiffW-=w; frame->DiffH-=h;
245 //----------------------------------------------------------------------------
246 //-- Help : ---
247 //----------------------------------------------------------------------------
248
249 frame->help.UseConfig(p_ProgramCfg);
250 frame->help.AddBook(langhelp);
251 /*
252 if (!frame->help.AddBook("helpfiles/dbbrowse.hhp"))
253 wxMessageBox("Failed adding book helpfiles/dbbrowse.hhp");
254 if (!frame->help.AddBook("helpfiles/testing.hhp"))
255 wxMessageBox("Failed adding book helpfiles/testing.hhp");
256 if (!frame->help.AddBook("helpfiles/another.hhp"))
257 wxMessageBox("Failed adding book helpfiles/another.hhp");
258 */
259
260
261 //---------------------------------------------------------------------------------------
262 p_ProgramCfg->Flush(TRUE); // sicher Objekt
263
264 //---------------------------------------------------------------------------------------
265 // Show the frame
266 frame->Show(TRUE);
267 SetTopWindow(frame);
268
269
270
271 return TRUE;
272 }
273 //---------------------------------------------------------------------------
274 // My frame constructor
275 //---------------------------------------------------------------------------
276 MainFrame::MainFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
277 wxFrame(frame, SPLITTER_FRAME, title, wxPoint(x, y), wxSize(w, h))
278 {
279 InitializeMenu();
280 // This reduces flicker effects - even better would be to define OnEraseBackground
281 // to do Temp0. When the list control's scrollbars are show or hidden, the
282 // frame is sent a background erase event.
283 SetBackgroundColour( *wxWHITE );
284 // frame->SetBackgroundColour(wxColour(255, 255, 255));
285 //---------------------------------------------------------------------------------------
286 // Give it an icon
287 SetIcon( wxICON(Logo) );
288 //---------------------------------------------------------------------------------------
289 }
290 //---------------------------------------------------------------------------
291 MainFrame::~MainFrame(void)
292 {
293 // save the control's values to the config
294 if ( p_ProgramCfg == NULL )
295 return;
296 // save the frame position
297 int x, y, w, h;
298 GetPosition(&x, &y);
299 GetClientSize(&w, &h); w -= DiffW; h -= DiffH;
300 p_ProgramCfg->Write("/MainFrame/x", (long) x);
301 p_ProgramCfg->Write("/MainFrame/y", (long) y);
302 p_ProgramCfg->Write("/MainFrame/w", (long) w);
303 p_ProgramCfg->Write("/MainFrame/h", (long) h);
304 p_ProgramCfg->Write("/MainFrame/Sash", (long) pDoc->Sash);
305 // clean up: Set() returns the active config object as Get() does, but unlike
306 // Get() it doesn't try to create one if there is none (definitely not what
307 // we want here!)
308 // delete wxConfigBase::Set((wxConfigBase *) NULL);
309 p_ProgramCfg->Flush(TRUE); // sichert Objekt
310 delete frame->pDoc;
311 }
312 //--------------------------------------------------------------------------------------
313 void MainFrame::InitializeMenu()
314 {
315 //---------------------------------------------------------------------------------------
316 // Make a menubar
317 //---------------------------------------------------------------------------------------
318 wxMenu *file_menu = new wxMenu;
319
320 file_menu->Append(ABOUT, _("&About"));
321 file_menu->AppendSeparator();
322 file_menu->Append(QUIT, _("E&xit"));
323
324
325 wxMenuBar *menu_bar = new wxMenuBar;
326 menu_bar->Append(file_menu, _("&File"));
327 SetMenuBar(menu_bar);
328 }
329 //---------------------------------------------------------------------------
330 void MainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
331 {
332 // Close the help frame; this will cause the config data to
333 // get written.
334 if (help.GetFrame()) // returns NULL if no help frame active
335 help.GetFrame()->Close(TRUE);
336 Close(TRUE);
337 }
338 //---------------------------------------------------------------------------
339 void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
340 {
341 wxMessageDialog dialog(this, _("DBBrowser\nMark Johnson\nBerlin, Germany\nmj10777@gmx.net\n (c) 1999"),
342 _("About DBBrowser"), wxOK|wxCANCEL);
343
344 dialog.ShowModal();
345 }
346 //---------------------------------------------------------------------------
347 void MainFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
348 {
349 help.Display("Main page");
350 }
351 //---------------------------------------------------------------------------