]>
git.saurik.com Git - wxWidgets.git/blob - demos/dbbrowse/dbbrowse.cpp
1 //----------------------------------------------------------------------------------------
3 // Purpose: Through ODBC - Databases Browsen
4 // Author: Mark Johnson
6 // BJO : Bart A.M. JOURQUIN
8 // Copyright: (c) Mark Johnson
9 // Licence: wxWindows license
11 //----------------------------------------------------------------------------------------
12 //-- all #ifdefs that the whole Project needs. -------------------------------------------
13 //----------------------------------------------------------------------------------------
15 #pragma implementation
18 //----------------------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
21 //----------------------------------------------------------------------------------------
25 //----------------------------------------------------------------------------------------
30 #include "wx/stockitem.h"
31 //----------------------------------------------------------------------------------------
33 #include "bitmaps/logo.xpm"
35 //----------------------------------------------------------------------------------------
36 //-- all #includes that every .cpp needs --- 19990807.mj10777 ----------------
37 //----------------------------------------------------------------------------------------
38 #include "std.h" // sorgsam Pflegen !
39 // #include <iostream>
40 //----------------------------------------------------------------------------------------
41 //-- Some Global Vars for this file ------------------------------------------------------
42 //----------------------------------------------------------------------------------------
43 BEGIN_EVENT_TABLE(MainFrame
, wxFrame
)
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
49 //----------------------------------------------------------------------------------------
50 IMPLEMENT_APP(MainApp
) // This declares wxApp::MainApp as "the" Application
52 //----------------------------------------------------------------------------------------
53 // 'Main program' equivalent, creating windows and returning main app frame
54 //----------------------------------------------------------------------------------------
55 bool MainApp::OnInit(void) // Does everything needed for a program start
57 wxString Temp0
; // Use as needed
58 //---------------------------------------------------------------------------------------
59 // set the language to use // Help.?? (.std = english, .de = german etc.)
60 const wxChar
*language
= NULL
; // czech, german, french, polish
61 const wxChar
*langid
= NULL
; // std = english , cz, de = german, fr = french, pl = polish
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 //---------------------------------------------------------------------------------------
69 wxImage::AddHandler( new wxPNGHandler
); // needed for help System
73 wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's
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
80 // wxBitmap::AddHandler( new wxXPMFileHandler ); // Attempt to use XPS instead of ico
81 // wxBitmap::AddHandler( new wxXPMDataHandler ); // - Attempt failed
83 //---------------------------------------------------------------------------------------
87 // ignore the other args, fall through
89 language
= argv
[2]; // czech, english, french, german , polish
90 langid
= argv
[1]; // cz, std, fr, de , pl
93 langid
= argv
[1]; // cz, std, fr, de , pl
99 //---------------------------------------------------------------------------------------
100 // Win-Registry : Workplace\HKEY_CURRENT_USERS\Software\%GetVendorName()\%GetAppName()
101 //---------------------------------------------------------------------------------------
102 SetVendorName(_T("mj10777")); // Needed to get Configuration Information
103 SetAppName(_T("DBBrowse")); // "" , also needed for s_LangHelp
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
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 p_ProgramCfg
= wxConfigBase::Get(); // Get Program Configuration from Registry
117 // p_ProgramCfg->DeleteAll(); // This is how the Config can be erased
118 p_ProgramCfg
->SetPath(_T("/")); // Start at root
119 //---------------------------------------------------------------------------------------
120 //-- Set the Language and remember it for the next time. --------------------------------
121 //---------------------------------------------------------------------------------------
122 if (langid
== NULL
) // No Parameter was given
125 p_ProgramCfg
->Read(_T("/Local/langid"),&Temp0
); // >const char *langid< can't be used here
127 langid
= _T("std"); // Standard language is "std" = english
131 Temp0
.Printf(_T("%s"),langid
);
132 //---------------------------------------------------------------------------------------
133 // Support the following languages (std = english)
134 if ((Temp0
== _T("a")) || (Temp0
== _T("cz")) || (Temp0
== _T("de")) ||
135 (Temp0
== _T("fr")) || (Temp0
== _T("pl")))
136 { // The three-letter language-string codes are only valid in Windows NT and Windows 95.
137 if (Temp0
== _T("cz"))
138 language
= _T("czech"); // csy or czech
139 if ((Temp0
== _T("de")) || (Temp0
== _T("a")))
141 language
= _T("german"); // deu or german
142 if (Temp0
== _T("a"))
143 { langid
= Temp0
= _T("de"); } // Austrian = german
144 } // german / austrian
145 if (Temp0
== _T("fr"))
146 language
= _T("french"); // fra or french
147 if (Temp0
== _T("pl"))
148 language
= _T("polish"); // plk or polish
149 if (!m_locale
.Init(language
, langid
, language
)) // Don't do this for english (std)
150 { // You should recieve errors here for cz and pl since there is no cz/ and pl/ directory
151 wxLogMessage(_T("-E-> %s : SetLocale error : langid(%s) ; language(%s)"),GetAppName().c_str(),langid
,language
);
153 language
= _T("C"); // english, english-aus , -can , -nz , -uk , -usa
156 { // Read in Foreign language's text for GetAppName() and Help
157 Temp0
= GetAppName();
158 Temp0
= Temp0
.Lower();
159 m_locale
.AddCatalog(Temp0
.c_str());
160 m_locale
.AddCatalog(_T("help"));
162 } // Support the following languages (std = english)
166 language
= _T("C"); // english, english-aus , -can , -nz , -uk , -usa
168 s_Language
.Printf(_T("%s"),language
); // language is a pointer
169 s_LangId
.Printf(_T("%s"),langid
); // langid is a pointer
170 p_ProgramCfg
->Write(_T("/Local/language"),s_Language
);
171 p_ProgramCfg
->Write(_T("/Local/langid"),s_LangId
);
172 s_LangHelp
.Printf(_T("help.%s/%s.hhp"),s_LangId
.c_str(),GetAppName().c_str()); // "help.std/Garantie.hhp";
173 s_LangHelp
= s_LangHelp
.Lower(); // A must for Linux
174 //---------------------------------------------------------------------------------------
175 Temp0
= _T("NONE"); // I don't remember why I did this
176 p_ProgramCfg
->Write(_T("/NONE"),Temp0
); // I don't remember why I did this
177 p_ProgramCfg
->Write(_T("/Paths/NONE"),Temp0
); // I don't remember why I did this
178 p_ProgramCfg
->Write(_T("/MainFrame/NONE"),Temp0
); // I don't remember why I did this
179 //---------------------------------------------------------------------------------------
180 p_ProgramCfg
->Write(_T("/Paths/Work"),wxGetCwd()); // Get current Working Path
181 p_ProgramCfg
->SetPath(_T("/"));
182 //---------------------------------------------------------------------------------------
183 // restore frame position and size, if empty start Values (1,1) and (750,600)
184 int x
= p_ProgramCfg
->Read(_T("/MainFrame/x"), 1), y
= p_ProgramCfg
->Read(_T("/MainFrame/y"), 1),
185 w
= p_ProgramCfg
->Read(_T("/MainFrame/w"), 750), h
= p_ProgramCfg
->Read(_T("/MainFrame/h"), 600);
186 //---------------------------------------------------------------------------------------
187 // Create the main frame window
188 Temp0
.Printf(_T("%s - %s"),GetAppName().c_str(),GetVendorName().c_str());
189 frame
= new MainFrame((wxFrame
*) NULL
,(wxChar
*) Temp0
.c_str(),wxPoint(x
,y
),wxSize(w
,h
));
190 //---------------------------------------------------------------------------------------
191 // Set the Backgroundcolour (only needed if you are NOT using wxSYS_COLOUR_BACKGROUND)
192 frame
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND
));
193 // frame->SetBackgroundColour(wxColour(255, 255, 255));
194 // frame->SetBackgroundColour(* wxWHITE);
195 //---------------------------------------------------------------------------------------
197 //---------------------------------------------------------------------------------------
198 // 12.02.2000 - Guillermo Rodriguez Garcia :
199 //---------------------------------------------------------------------------------------
200 // This is different for Win9x and WinNT; one of them takes the first ico
201 // in the .rc file, while the other takes the icon with the lowest name,
202 // so to be sure that it always work, put your icon the first *and* give
203 // it a name such a 'appicon' or something.
204 //---------------------------------------------------------------------------------------
205 // mj10777 : any special rule in Linux ?
206 //---------------------------------------------------------------------------------------
207 frame
->SetIcon(wxICON(aLogo
)); // lowest name and first entry in RC File
208 //---------------------------------------------------------------------------------------
210 wxMenu
*file_menu
= new wxMenu
;
211 wxMenu
*help_menu
= new wxMenu
;
213 help_menu
->Append(wxID_HELP
, wxGetStockLabel(wxID_HELP
));
214 help_menu
->AppendSeparator();
215 help_menu
->Append(wxID_ABOUT
, _("&About"));
216 file_menu
->Append(wxID_EXIT
, wxGetStockLabel(wxID_EXIT
));
218 wxMenuBar
*menu_bar
= new wxMenuBar
;
219 menu_bar
->Append(file_menu
, _("&File"));
220 menu_bar
->Append(help_menu
, _("&Help"));
221 frame
->SetMenuBar(menu_bar
);
223 frame
->CreateStatusBar(1);
224 Temp0
.Printf(_("%s has started !"),p_ProgramCfg
->GetAppName().c_str());
225 frame
->SetStatusText(Temp0
, 0);
226 #endif // wxUSE_STATUSBAR
227 //---------------------------------------------------------------------------------------
229 frame
->GetClientSize(&width
, &height
);
230 //---------------------------------------------------------------------------------------
231 frame
->p_Splitter
= new DocSplitterWindow(frame
,wxID_ANY
);
232 // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL));
233 frame
->pDoc
= new MainDoc();
234 frame
->pDoc
->p_MainFrame
= frame
;
235 frame
->pDoc
->p_Splitter
= frame
->p_Splitter
;
236 frame
->pDoc
->p_Splitter
->pDoc
= frame
->pDoc
; // ControlBase: saving the Sash
237 //---------------------------------------------------------------------------------------
238 //-- Problem : GetClientSize(Width,Height) are not the same as the values given in the ---
239 //-- construction of the Frame. ---
240 //-- Solved : GetClientSize is called here and the difference is noted. When the ---
241 //-- Window is closed the diff. is added to the result of GetClientSize. ---
242 //---------------------------------------------------------------------------------------
243 frame
->GetClientSize(&frame
->DiffW
, &frame
->DiffH
); frame
->DiffW
-=w
; frame
->DiffH
-=h
;
244 //----------------------------------------------------------------------------
245 //-- Help : Load the help.%langid/%GetAppName().hhp (help.std/dbbrowse.hhp) file ---
246 //----------------------------------------------------------------------------
247 frame
->p_Help
= new wxHtmlHelpController(); // construct the Help System
248 frame
->p_Help
->UseConfig(p_ProgramCfg
); // Don't rember what this was for
249 // You should recieve errors here for fr since there is no help.fr/ directory
250 if (!frame
->p_Help
->AddBook(s_LangHelp
)) // Use the language set
251 { // You should recieve errors here for fr since there is no help.fr/ but a fr/ directory
252 wxLogMessage(_T("-E-> %s : AddBook error : s_LangHelp(%s)"),GetAppName().c_str(),s_LangHelp
.c_str());
254 frame
->pDoc
->p_Help
= frame
->p_Help
; // Save the information to the document
255 //---------------------------------------------------------------------------------------
256 frame
->Show(true); // Show the frame
257 SetTopWindow(frame
); // At this point the frame can be seen
258 //---------------------------------------------------------------------------------------
259 // If you need a "Splash Screen" because of a long OnNewDocument, do it here
260 if (!frame
->pDoc
->OnNewDocument())
262 // Kill a "Splash Screen" because OnNewDocument, if you have one
263 //---------------------------------------------------------------------------------------
264 p_ProgramCfg
->Flush(true); // save the configuration
266 } // bool MainApp::OnInit(void)
268 //----------------------------------------------------------------------------------------
269 // My frame constructor
270 //----------------------------------------------------------------------------------------
271 MainFrame::MainFrame(wxFrame
*frame
, wxChar
*title
, const wxPoint
& pos
, const wxSize
& size
):
272 wxFrame(frame
, wxID_ANY
, title
, pos
, size
)
274 p_Splitter
= NULL
; pDoc
= NULL
; p_Help
= NULL
; // Keep the Pointers clean !
275 //--- Everything else is done in MainApp::OnInit() --------------------------------------
278 //----------------------------------------------------------------------------------------
279 MainFrame::~MainFrame(void)
281 // Close the help frame; this will cause the config data to get written.
282 if (p_Help
->GetFrame()) // returns NULL if no help frame active
283 p_Help
->GetFrame()->Close(true);
284 delete p_Help
; // Memory Leak
286 // save the control's values to the config
287 if (p_ProgramCfg
== NULL
)
289 // save the frame position before it is destroyed
292 GetClientSize(&w
, &h
); w
-= DiffW
; h
-= DiffH
;
293 p_ProgramCfg
->Write(_T("/MainFrame/x"), (long) x
);
294 p_ProgramCfg
->Write(_T("/MainFrame/y"), (long) y
);
295 p_ProgramCfg
->Write(_T("/MainFrame/w"), (long) w
);
296 p_ProgramCfg
->Write(_T("/MainFrame/h"), (long) h
);
297 p_ProgramCfg
->Write(_T("/MainFrame/Sash"), (long) pDoc
->Sash
);
298 // clean up: Set() returns the active config object as Get() does, but unlike
299 // Get() it doesn't try to create one if there is none (definitely not what
301 // delete wxConfigBase::Set((wxConfigBase *) NULL);
302 p_ProgramCfg
->Flush(true); // saves Objekt
303 if (pDoc
) // If we have a Valid Document
304 delete pDoc
; // Cleanup (MainDoc::~MainDoc)
305 } // MainFrame::~MainFrame(void)
307 //----------------------------------------------------------------------------------------
308 void MainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
313 //----------------------------------------------------------------------------------------
314 void MainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
316 wxString Temp0
, Temp1
;
317 Temp0
.Printf(_("%s\nMark Johnson\nBerlin, Germany\nwxWindows@mj10777.de\n (c) 2000"),p_ProgramCfg
->GetAppName().c_str());
318 Temp1
.Printf(_("About %s"),p_ProgramCfg
->GetAppName().c_str());
319 wxMessageDialog
dialog(this, Temp0
,Temp1
,wxOK
|wxCANCEL
);
323 //----------------------------------------------------------------------------------------
324 void MainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
326 p_Help
->Display(_T("Main page"));
328 //----------------------------------------------------------------------------------------