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