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