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