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