]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/dbbrowse.cpp
Enhanced stock labels usage. Source cleaning.
[wxWidgets.git] / demos / dbbrowse / dbbrowse.cpp
CommitLineData
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 43BEGIN_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 47END_EVENT_TABLE()
645889ad 48
c92b0f9a 49//----------------------------------------------------------------------------------------
a1c5f7a3 50IMPLEMENT_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 55bool 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:
96 break;
97 };
98 //---------------------------------------------------------------------------------------
99 // Win-Registry : Workplace\HKEY_CURRENT_USERS\Software\%GetVendorName()\%GetAppName()
100 //---------------------------------------------------------------------------------------
daf06bb8 101 SetVendorName(_T("mj10777")); // Needed to get Configuration Information
5d2ac6b8 102 SetAppName(_T("DBBrowse")); // "" , also needed for s_LangHelp
645889ad
GT
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
5d2ac6b8 109
645889ad
GT
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 p_ProgramCfg = wxConfigBase::Get(); // Get Program Configuration from Registry
116 // p_ProgramCfg->DeleteAll(); // This is how the Config can be erased
daf06bb8 117 p_ProgramCfg->SetPath(_T("/")); // Start at root
645889ad
GT
118 //---------------------------------------------------------------------------------------
119 //-- Set the Language and remember it for the next time. --------------------------------
120 //---------------------------------------------------------------------------------------
121 if (langid == NULL) // No Parameter was given
122 {
123 Temp0.Empty();
daf06bb8 124 p_ProgramCfg->Read(_T("/Local/langid"),&Temp0); // >const char *langid< can't be used here
5d2ac6b8 125 if (Temp0.empty())
daf06bb8 126 langid = _T("std"); // Standard language is "std" = english
645889ad
GT
127 else
128 langid = Temp0;
129 }
daf06bb8 130 Temp0.Printf(_T("%s"),langid);
645889ad
GT
131 //---------------------------------------------------------------------------------------
132 // Support the following languages (std = english)
daf06bb8
JS
133 if ((Temp0 == _T("a")) || (Temp0 == _T("cz")) || (Temp0 == _T("de")) ||
134 (Temp0 == _T("fr")) || (Temp0 == _T("pl")))
645889ad 135 { // The three-letter language-string codes are only valid in Windows NT and Windows 95.
daf06bb8
JS
136 if (Temp0 == _T("cz"))
137 language = _T("czech"); // csy or czech
138 if ((Temp0 == _T("de")) || (Temp0 == _T("a")))
645889ad 139 {
daf06bb8
JS
140 language = _T("german"); // deu or german
141 if (Temp0 == _T("a"))
142 { langid = Temp0 = _T("de"); } // Austrian = german
645889ad 143 } // german / austrian
daf06bb8
JS
144 if (Temp0 == _T("fr"))
145 language = _T("french"); // fra or french
146 if (Temp0 == _T("pl"))
147 language = _T("polish"); // plk or polish
645889ad
GT
148 if (!m_locale.Init(language, langid, language)) // Don't do this for english (std)
149 { // You should recieve errors here for cz and pl since there is no cz/ and pl/ directory
daf06bb8
JS
150 wxLogMessage(_T("-E-> %s : SetLocale error : langid(%s) ; language(%s)"),GetAppName().c_str(),langid,language);
151 langid = _T("std");
152 language = _T("C"); // english, english-aus , -can , -nz , -uk , -usa
645889ad
GT
153 }
154 else
155 { // Read in Foreign language's text for GetAppName() and Help
156 Temp0 = GetAppName();
157 Temp0 = Temp0.Lower();
158 m_locale.AddCatalog(Temp0.c_str());
daf06bb8 159 m_locale.AddCatalog(_T("help"));
645889ad
GT
160 }
161 } // Support the following languages (std = english)
162 else
163 {
daf06bb8
JS
164 langid = _T("std");
165 language = _T("C"); // english, english-aus , -can , -nz , -uk , -usa
645889ad 166 }
daf06bb8
JS
167 s_Language.Printf(_T("%s"),language); // language is a pointer
168 s_LangId.Printf(_T("%s"),langid); // langid is a pointer
169 p_ProgramCfg->Write(_T("/Local/language"),s_Language);
170 p_ProgramCfg->Write(_T("/Local/langid"),s_LangId);
171 s_LangHelp.Printf(_T("help.%s/%s.hhp"),s_LangId.c_str(),GetAppName().c_str()); // "help.std/Garantie.hhp";
645889ad
GT
172 s_LangHelp = s_LangHelp.Lower(); // A must for Linux
173 //---------------------------------------------------------------------------------------
daf06bb8
JS
174 Temp0 = _T("NONE"); // I don't remember why I did this
175 p_ProgramCfg->Write(_T("/NONE"),Temp0); // I don't remember why I did this
176 p_ProgramCfg->Write(_T("/Paths/NONE"),Temp0); // I don't remember why I did this
177 p_ProgramCfg->Write(_T("/MainFrame/NONE"),Temp0); // I don't remember why I did this
645889ad 178 //---------------------------------------------------------------------------------------
daf06bb8
JS
179 p_ProgramCfg->Write(_T("/Paths/Work"),wxGetCwd()); // Get current Working Path
180 p_ProgramCfg->SetPath(_T("/"));
645889ad
GT
181 //---------------------------------------------------------------------------------------
182 // restore frame position and size, if empty start Values (1,1) and (750,600)
daf06bb8
JS
183 int x = p_ProgramCfg->Read(_T("/MainFrame/x"), 1), y = p_ProgramCfg->Read(_T("/MainFrame/y"), 1),
184 w = p_ProgramCfg->Read(_T("/MainFrame/w"), 750), h = p_ProgramCfg->Read(_T("/MainFrame/h"), 600);
645889ad
GT
185 //---------------------------------------------------------------------------------------
186 // Create the main frame window
daf06bb8
JS
187 Temp0.Printf(_T("%s - %s"),GetAppName().c_str(),GetVendorName().c_str());
188 frame = new MainFrame((wxFrame *) NULL,(wxChar *) Temp0.c_str(),wxPoint(x,y),wxSize(w,h));
645889ad 189 //---------------------------------------------------------------------------------------
a0d9c6cb 190 // Set the Backgroundcolour (only needed if you are NOT using wxSYS_COLOUR_BACKGROUND)
e1c6c6ae 191 frame->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND));
645889ad
GT
192 // frame->SetBackgroundColour(wxColour(255, 255, 255));
193 // frame->SetBackgroundColour(* wxWHITE);
194 //---------------------------------------------------------------------------------------
195 // Give it an icon
196 //---------------------------------------------------------------------------------------
197 // 12.02.2000 - Guillermo Rodriguez Garcia :
198 //---------------------------------------------------------------------------------------
199 // This is different for Win9x and WinNT; one of them takes the first ico
200 // in the .rc file, while the other takes the icon with the lowest name,
201 // so to be sure that it always work, put your icon the first *and* give
202 // it a name such a 'appicon' or something.
203 //---------------------------------------------------------------------------------------
204 // mj10777 : any special rule in Linux ?
205 //---------------------------------------------------------------------------------------
206 frame->SetIcon(wxICON(aLogo)); // lowest name and first entry in RC File
207 //---------------------------------------------------------------------------------------
208 // Make a menubar
209 wxMenu *file_menu = new wxMenu;
210 wxMenu *help_menu = new wxMenu;
5d2ac6b8
WS
211
212 help_menu->Append(wxID_HELP, wxGetStockLabel(wxID_HELP));
645889ad 213 help_menu->AppendSeparator();
5d2ac6b8
WS
214 help_menu->Append(wxID_ABOUT, _("&About"));
215 file_menu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT));
216
645889ad
GT
217 wxMenuBar *menu_bar = new wxMenuBar;
218 menu_bar->Append(file_menu, _("&File"));
219 menu_bar->Append(help_menu, _("&Help"));
220 frame->SetMenuBar(menu_bar);
67a99992 221#if wxUSE_STATUSBAR
645889ad
GT
222 frame->CreateStatusBar(1);
223 Temp0.Printf(_("%s has started !"),p_ProgramCfg->GetAppName().c_str());
224 frame->SetStatusText(Temp0, 0);
67a99992 225#endif // wxUSE_STATUSBAR
645889ad
GT
226 //---------------------------------------------------------------------------------------
227 int width, height;
228 frame->GetClientSize(&width, &height);
229 //---------------------------------------------------------------------------------------
5151c7af 230 frame->p_Splitter = new DocSplitterWindow(frame,wxID_ANY);
645889ad
GT
231 // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL));
232 frame->pDoc = new MainDoc();
233 frame->pDoc->p_MainFrame = frame;
234 frame->pDoc->p_Splitter = frame->p_Splitter;
235 frame->pDoc->p_Splitter->pDoc = frame->pDoc; // ControlBase: saving the Sash
236 //---------------------------------------------------------------------------------------
237 //-- Problem : GetClientSize(Width,Hight) are not the same as the values given in the ---
238 //-- construction of the Frame. ---
239 //-- Solved : GetClientSize is called here and the difference is noted. When the ---
240 //-- Window is closed the diff. is added to the result of GetClientSize. ---
241 //---------------------------------------------------------------------------------------
242 frame->GetClientSize(&frame->DiffW, &frame->DiffH); frame->DiffW-=w; frame->DiffH-=h;
243 //----------------------------------------------------------------------------
244 //-- Help : Load the help.%langid/%GetAppName().hhp (help.std/dbbrowse.hhp) file ---
245 //----------------------------------------------------------------------------
246 frame->p_Help = new wxHtmlHelpController(); // construct the Help System
247 frame->p_Help->UseConfig(p_ProgramCfg); // Don't rember what this was for
248 // You should recieve errors here for fr since there is no help.fr/ directory
249 if (!frame->p_Help->AddBook(s_LangHelp)) // Use the language set
250 { // You should recieve errors here for fr since there is no help.fr/ but a fr/ directory
daf06bb8 251 wxLogMessage(_T("-E-> %s : AddBook error : s_LangHelp(%s)"),GetAppName().c_str(),s_LangHelp.c_str());
645889ad
GT
252 }
253 frame->pDoc->p_Help = frame->p_Help; // Save the information to the document
254 //---------------------------------------------------------------------------------------
5151c7af 255 frame->Show(true); // Show the frame
645889ad
GT
256 SetTopWindow(frame); // At this point the frame can be seen
257 //---------------------------------------------------------------------------------------
258 // If you need a "Splash Screen" because of a long OnNewDocument, do it here
259 if (!frame->pDoc->OnNewDocument())
5151c7af 260 frame->Close(true);
645889ad
GT
261 // Kill a "Splash Screen" because OnNewDocument, if you have one
262 //---------------------------------------------------------------------------------------
5151c7af
WS
263 p_ProgramCfg->Flush(true); // save the configuration
264 return true;
c92b0f9a 265} // bool MainApp::OnInit(void)
645889ad 266
c92b0f9a 267//----------------------------------------------------------------------------------------
b5ffecfc 268// My frame constructor
c92b0f9a 269//----------------------------------------------------------------------------------------
daf06bb8 270MainFrame::MainFrame(wxFrame *frame, wxChar *title, const wxPoint& pos, const wxSize& size):
5151c7af 271wxFrame(frame, wxID_ANY, title, pos, size)
b5ffecfc 272{
645889ad
GT
273 p_Splitter = NULL; pDoc = NULL; p_Help = NULL; // Keep the Pointers clean !
274 //--- Everything else is done in MainApp::OnInit() --------------------------------------
b5ffecfc 275}
645889ad 276
c92b0f9a 277//----------------------------------------------------------------------------------------
b5ffecfc
GT
278MainFrame::~MainFrame(void)
279{
645889ad
GT
280 // Close the help frame; this will cause the config data to get written.
281 if (p_Help->GetFrame()) // returns NULL if no help frame active
5151c7af 282 p_Help->GetFrame()->Close(true);
645889ad
GT
283 delete p_Help; // Memory Leak
284 p_Help = NULL;
285 // save the control's values to the config
286 if (p_ProgramCfg == NULL)
287 return;
288 // save the frame position before it is destroyed
289 int x, y, w, h;
290 GetPosition(&x, &y);
291 GetClientSize(&w, &h); w -= DiffW; h -= DiffH;
daf06bb8
JS
292 p_ProgramCfg->Write(_T("/MainFrame/x"), (long) x);
293 p_ProgramCfg->Write(_T("/MainFrame/y"), (long) y);
294 p_ProgramCfg->Write(_T("/MainFrame/w"), (long) w);
295 p_ProgramCfg->Write(_T("/MainFrame/h"), (long) h);
296 p_ProgramCfg->Write(_T("/MainFrame/Sash"), (long) pDoc->Sash);
645889ad
GT
297 // clean up: Set() returns the active config object as Get() does, but unlike
298 // Get() it doesn't try to create one if there is none (definitely not what
299 // we want here!)
300 // delete wxConfigBase::Set((wxConfigBase *) NULL);
5151c7af 301 p_ProgramCfg->Flush(true); // saves Objekt
645889ad
GT
302 if (pDoc) // If we have a Valid Document
303 delete pDoc; // Cleanup (MainDoc::~MainDoc)
a1c5f7a3 304} // MainFrame::~MainFrame(void)
645889ad 305
c92b0f9a 306//----------------------------------------------------------------------------------------
b5ffecfc
GT
307void MainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
308{
5151c7af 309 Close(true);
b5ffecfc 310}
645889ad 311
c92b0f9a 312//----------------------------------------------------------------------------------------
b5ffecfc
GT
313void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
314{
645889ad 315 wxString Temp0, Temp1;
829c421b 316 Temp0.Printf(_("%s\nMark Johnson\nBerlin, Germany\nwxWindows@mj10777.de\n (c) 2000"),p_ProgramCfg->GetAppName().c_str());
645889ad
GT
317 Temp1.Printf(_("About %s"),p_ProgramCfg->GetAppName().c_str());
318 wxMessageDialog dialog(this, Temp0,Temp1,wxOK|wxCANCEL);
319 dialog.ShowModal();
b5ffecfc 320}
645889ad 321
c92b0f9a 322//----------------------------------------------------------------------------------------
b5ffecfc
GT
323void MainFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
324{
daf06bb8 325 p_Help->Display(_T("Main page"));
b5ffecfc 326}
c92b0f9a 327//----------------------------------------------------------------------------------------