]>
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
98 //---------------------------------------------------------------------------------------
99 // Win-Registry : Workplace\HKEY_CURRENT_USERS\Software\%GetVendorName()\%GetAppName()
100 //---------------------------------------------------------------------------------------
101 SetVendorName(_T("mj10777")); // Needed to get Configuration Information
102 SetAppName(_T("DBBrowse")); // "" , also needed for s_LangHelp
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
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
117 p_ProgramCfg
->SetPath(_T("/")); // Start at root
118 //---------------------------------------------------------------------------------------
119 //-- Set the Language and remember it for the next time. --------------------------------
120 //---------------------------------------------------------------------------------------
121 if (langid
== NULL
) // No Parameter was given
124 p_ProgramCfg
->Read(_T("/Local/langid"),&Temp0
); // >const char *langid< can't be used here
126 langid
= _T("std"); // Standard language is "std" = english
130 Temp0
.Printf(_T("%s"),langid
);
131 //---------------------------------------------------------------------------------------
132 // Support the following languages (std = english)
133 if ((Temp0
== _T("a")) || (Temp0
== _T("cz")) || (Temp0
== _T("de")) ||
134 (Temp0
== _T("fr")) || (Temp0
== _T("pl")))
135 { // The three-letter language-string codes are only valid in Windows NT and Windows 95.
136 if (Temp0
== _T("cz"))
137 language
= _T("czech"); // csy or czech
138 if ((Temp0
== _T("de")) || (Temp0
== _T("a")))
140 language
= _T("german"); // deu or german
141 if (Temp0
== _T("a"))
142 { langid
= Temp0
= _T("de"); } // Austrian = german
143 } // german / austrian
144 if (Temp0
== _T("fr"))
145 language
= _T("french"); // fra or french
146 if (Temp0
== _T("pl"))
147 language
= _T("polish"); // plk or polish
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
150 wxLogMessage(_T("-E-> %s : SetLocale error : langid(%s) ; language(%s)"),GetAppName().c_str(),langid
,language
);
152 language
= _T("C"); // english, english-aus , -can , -nz , -uk , -usa
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());
159 m_locale
.AddCatalog(_T("help"));
161 } // Support the following languages (std = english)
165 language
= _T("C"); // english, english-aus , -can , -nz , -uk , -usa
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";
172 s_LangHelp
= s_LangHelp
.Lower(); // A must for Linux
173 //---------------------------------------------------------------------------------------
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
178 //---------------------------------------------------------------------------------------
179 p_ProgramCfg
->Write(_T("/Paths/Work"),wxGetCwd()); // Get current Working Path
180 p_ProgramCfg
->SetPath(_T("/"));
181 //---------------------------------------------------------------------------------------
182 // restore frame position and size, if empty start Values (1,1) and (750,600)
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);
185 //---------------------------------------------------------------------------------------
186 // Create the main frame window
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
));
189 //---------------------------------------------------------------------------------------
190 // Set the Backgroundcolour (only needed if you are NOT using wxSYS_COLOUR_BACKGROUND)
191 frame
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND
));
192 // frame->SetBackgroundColour(wxColour(255, 255, 255));
193 // frame->SetBackgroundColour(* wxWHITE);
194 //---------------------------------------------------------------------------------------
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 //---------------------------------------------------------------------------------------
209 wxMenu
*file_menu
= new wxMenu
;
210 wxMenu
*help_menu
= new wxMenu
;
212 help_menu
->Append(wxID_HELP
, wxGetStockLabel(wxID_HELP
));
213 help_menu
->AppendSeparator();
214 help_menu
->Append(wxID_ABOUT
, _("&About"));
215 file_menu
->Append(wxID_EXIT
, wxGetStockLabel(wxID_EXIT
));
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
);
222 frame
->CreateStatusBar(1);
223 Temp0
.Printf(_("%s has started !"),p_ProgramCfg
->GetAppName().c_str());
224 frame
->SetStatusText(Temp0
, 0);
225 #endif // wxUSE_STATUSBAR
226 //---------------------------------------------------------------------------------------
228 frame
->GetClientSize(&width
, &height
);
229 //---------------------------------------------------------------------------------------
230 frame
->p_Splitter
= new DocSplitterWindow(frame
,wxID_ANY
);
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
251 wxLogMessage(_T("-E-> %s : AddBook error : s_LangHelp(%s)"),GetAppName().c_str(),s_LangHelp
.c_str());
253 frame
->pDoc
->p_Help
= frame
->p_Help
; // Save the information to the document
254 //---------------------------------------------------------------------------------------
255 frame
->Show(true); // Show the frame
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())
261 // Kill a "Splash Screen" because OnNewDocument, if you have one
262 //---------------------------------------------------------------------------------------
263 p_ProgramCfg
->Flush(true); // save the configuration
265 } // bool MainApp::OnInit(void)
267 //----------------------------------------------------------------------------------------
268 // My frame constructor
269 //----------------------------------------------------------------------------------------
270 MainFrame::MainFrame(wxFrame
*frame
, wxChar
*title
, const wxPoint
& pos
, const wxSize
& size
):
271 wxFrame(frame
, wxID_ANY
, title
, pos
, size
)
273 p_Splitter
= NULL
; pDoc
= NULL
; p_Help
= NULL
; // Keep the Pointers clean !
274 //--- Everything else is done in MainApp::OnInit() --------------------------------------
277 //----------------------------------------------------------------------------------------
278 MainFrame::~MainFrame(void)
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
282 p_Help
->GetFrame()->Close(true);
283 delete p_Help
; // Memory Leak
285 // save the control's values to the config
286 if (p_ProgramCfg
== NULL
)
288 // save the frame position before it is destroyed
291 GetClientSize(&w
, &h
); w
-= DiffW
; h
-= DiffH
;
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
);
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
300 // delete wxConfigBase::Set((wxConfigBase *) NULL);
301 p_ProgramCfg
->Flush(true); // saves Objekt
302 if (pDoc
) // If we have a Valid Document
303 delete pDoc
; // Cleanup (MainDoc::~MainDoc)
304 } // MainFrame::~MainFrame(void)
306 //----------------------------------------------------------------------------------------
307 void MainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
312 //----------------------------------------------------------------------------------------
313 void MainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
315 wxString Temp0
, Temp1
;
316 Temp0
.Printf(_("%s\nMark Johnson\nBerlin, Germany\nwxWindows@mj10777.de\n (c) 2000"),p_ProgramCfg
->GetAppName().c_str());
317 Temp1
.Printf(_("About %s"),p_ProgramCfg
->GetAppName().c_str());
318 wxMessageDialog
dialog(this, Temp0
,Temp1
,wxOK
|wxCANCEL
);
322 //----------------------------------------------------------------------------------------
323 void MainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
325 p_Help
->Display(_T("Main page"));
327 //----------------------------------------------------------------------------------------