]>
git.saurik.com Git - wxWidgets.git/blob - demos/dbbrowse/dbbrowse.cpp
1 //----------------------------------------------------------------------------------------
3 // Purpose: Through ODBC - Databases Browsen
4 // Author: Mark Johnson, mj10777@gmx.net
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 //----------------------------------------------------------------------------------------
29 //----------------------------------------------------------------------------------------
31 #include "bitmaps/logo.xpm"
33 //----------------------------------------------------------------------------------------
34 //-- all #includes that every .cpp needs --- 19990807.mj10777 ----------------
35 //----------------------------------------------------------------------------------------
36 #include "std.h" // sorgsam Pflegen !
37 // #include <iostream>
38 //----------------------------------------------------------------------------------------
39 //-- Some Global Vars for this file ------------------------------------------------------
40 //----------------------------------------------------------------------------------------
41 MainFrame
*frame
= NULL
; // The one and only MainFrame
42 //----------------------------------------------------------------------------------------
43 BEGIN_EVENT_TABLE(MainFrame
, wxFrame
)
44 EVT_MENU(QUIT
, MainFrame::OnQuit
) // Program End
45 EVT_MENU(ABOUT
, MainFrame::OnAbout
) // Program Discription
46 EVT_MENU(HELP
, MainFrame::OnHelp
) // Program Help
48 //----------------------------------------------------------------------------------------
49 IMPLEMENT_APP(MainApp
) // This declares wxApp::MainApp as "the" Application
50 //----------------------------------------------------------------------------------------
51 // 'Main program' equivalent, creating windows and returning main app frame
52 //----------------------------------------------------------------------------------------
53 bool MainApp::OnInit(void) // Does everything needed for a program start
55 wxString Temp0
; // Use as needed
56 //---------------------------------------------------------------------------------------
57 // set the language to use // Help.?? (.std = english, .de = german etc.)
58 const char *language
= NULL
; // czech, german, french, polish
59 const char *langid
= NULL
; // std = english , cz, de = german, fr = french, pl = polish
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 //---------------------------------------------------------------------------------------
67 wxImage::AddHandler( new wxPNGHandler
); // needed for help System
71 wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's
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
78 // wxBitmap::AddHandler( new wxXPMFileHandler ); // Attempt to use XPS instead of ico
79 // wxBitmap::AddHandler( new wxXPMDataHandler ); // - Attempt failed
81 //---------------------------------------------------------------------------------------
85 // ignore the other args, fall through
87 language
= argv
[2]; // czech, english, french, german , polish
88 langid
= argv
[1]; // cz, std, fr, de , pl
91 langid
= argv
[1]; // cz, std, fr, de , pl
96 //---------------------------------------------------------------------------------------
97 // Win-Registry : Workplace\HKEY_CURRENT_USERS\Software\%GetVendorName()\%GetAppName()
98 //---------------------------------------------------------------------------------------
99 SetVendorName("mj10777"); // Needed to get Configuration Information
100 SetAppName("DBBrowse"); // "" , also needed for s_LangHelp
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
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
115 p_ProgramCfg
->SetPath("/"); // Start at root
116 //---------------------------------------------------------------------------------------
117 //-- Set the Language and remember it for the next time. --------------------------------
118 //---------------------------------------------------------------------------------------
119 if (langid
== NULL
) // No Parameter was given
122 p_ProgramCfg
->Read("/Local/langid",&Temp0
); // >const char *langid< can't be used here
124 langid
= "std"; // Standard language is "std" = english
128 Temp0
.Printf("%s",langid
);
129 //---------------------------------------------------------------------------------------
130 // Support the following languages (std = english)
131 if ((Temp0
== "a") || (Temp0
== "cz") || (Temp0
== "de") ||
132 (Temp0
== "fr") || (Temp0
== "pl"))
133 { // The three-letter language-string codes are only valid in Windows NT and Windows 95.
135 language
= "czech"; // csy or czech
136 if ((Temp0
== "de") || (Temp0
== "a"))
138 language
= "german"; // deu or german
140 { langid
= Temp0
= "de"; } // Austrian = german
141 } // german / austrian
143 language
= "french"; // fra or french
145 language
= "polish"; // plk or polish
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
148 wxLogMessage("-E-> %s : SetLocale error : langid(%s) ; language(%s)",GetAppName().c_str(),langid
,language
);
150 language
= "C"; // english, english-aus , -can , -nz , -uk , -usa
153 { // Read in Foreign language's text for GetAppName() and Help
154 m_locale
.AddCatalog(GetAppName().c_str());
155 m_locale
.AddCatalog("Help");
157 } // Support the following languages (std = english)
161 language
= "C"; // english, english-aus , -can , -nz , -uk , -usa
163 s_Language
.Printf("%s",language
); // language is a pointer
164 s_LangId
.Printf("%s",langid
); // langid is a pointer
165 p_ProgramCfg
->Write("/Local/language",s_Language
);
166 p_ProgramCfg
->Write("/Local/langid",s_LangId
);
167 s_LangHelp
.Printf("help.%s/%s.hhp",s_LangId
.c_str(),GetAppName().c_str()); // "help.std/Garantie.hhp";
168 //---------------------------------------------------------------------------------------
169 Temp0
= "NONE"; // I don't remember why I did this
170 p_ProgramCfg
->Write("/NONE",Temp0
); // I don't remember why I did this
171 p_ProgramCfg
->Write("/Paths/NONE",Temp0
); // I don't remember why I did this
172 p_ProgramCfg
->Write("/MainFrame/NONE",Temp0
); // I don't remember why I did this
173 //---------------------------------------------------------------------------------------
174 p_ProgramCfg
->Write("/Paths/Work",wxGetCwd()); // Get current Working Path
175 p_ProgramCfg
->SetPath("/");
176 //---------------------------------------------------------------------------------------
177 // restore frame position and size, if empty start Values (1,1) and (750,600)
178 int x
= p_ProgramCfg
->Read("/MainFrame/x", 1), y
= p_ProgramCfg
->Read("/MainFrame/y", 1),
179 w
= p_ProgramCfg
->Read("/MainFrame/w", 750), h
= p_ProgramCfg
->Read("/MainFrame/h", 600);
180 //---------------------------------------------------------------------------------------
181 // Create the main frame window
182 frame
= new MainFrame((wxFrame
*) NULL
, (char *) _("DBBrowser - mj10777"),wxPoint(x
,y
),wxSize(w
,h
));
183 //---------------------------------------------------------------------------------------
184 // Set the Backgroundcolour (only need if your are NOT using wxSYS_COLOUR_BACKGROUND)
185 frame
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BACKGROUND
));
186 // frame->SetBackgroundColour(wxColour(255, 255, 255));
187 // frame->SetBackgroundColour(* wxWHITE);
188 //---------------------------------------------------------------------------------------
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
201 //---------------------------------------------------------------------------------------
203 wxMenu
*file_menu
= new wxMenu
;
204 wxMenu
*help_menu
= new wxMenu
;
206 help_menu
->Append(HELP
, _("&Help"));
207 help_menu
->AppendSeparator();
208 help_menu
->Append(ABOUT
, _("&About"));
209 file_menu
->Append(QUIT
, _("E&xit"));
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 //---------------------------------------------------------------------------------------
220 frame
->GetClientSize(&width
, &height
);
221 //---------------------------------------------------------------------------------------
222 frame
->p_Splitter
= new DocSplitterWindow(frame
,-1);
223 // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL));
224 frame
->pDoc
= new mjDoc();
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
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 //----------------------------------------------------------------------------
236 //-- Help : Load the help.%langid/%GetAppName().hhp (help.std/dbbrowse.hhp) file ---
237 //----------------------------------------------------------------------------
238 frame
->p_Help
= new wxHtmlHelpController(); // construct the Help System
239 frame
->p_Help
->UseConfig(p_ProgramCfg
); // Don't rember what this was for
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());
245 frame
->pDoc
->p_Help
= frame
->p_Help
; // Save the information to the document
246 //---------------------------------------------------------------------------------------
247 frame
->Show(TRUE
); // Show the frame
248 SetTopWindow(frame
); // At this point the frame can be seen
249 //---------------------------------------------------------------------------------------
250 // If you need a "Splash Screen" because of a long OnNewDocument, do it here
251 if (!frame
->pDoc
->OnNewDocument())
253 // Kill a "Splash Screen" because OnNewDocument, if you have one
254 //---------------------------------------------------------------------------------------
255 p_ProgramCfg
->Flush(TRUE
); // save the configuration
257 } // bool MainApp::OnInit(void)
258 //----------------------------------------------------------------------------------------
259 // My frame constructor
260 //----------------------------------------------------------------------------------------
261 MainFrame::MainFrame(wxFrame
*frame
, char *title
, const wxPoint
& pos
, const wxSize
& size
):
262 wxFrame(frame
, -1, title
, pos
, size
)
264 //--- Everything is done in MainApp -----------------------------------------------------
266 //----------------------------------------------------------------------------------------
267 MainFrame::~MainFrame(void)
269 // save the control's values to the config
270 if (p_ProgramCfg
== NULL
)
272 // save the frame position before it is destroyed
275 GetClientSize(&w
, &h
); w
-= DiffW
; h
-= DiffH
;
276 p_ProgramCfg
->Write("/MainFrame/x", (long) x
);
277 p_ProgramCfg
->Write("/MainFrame/y", (long) y
);
278 p_ProgramCfg
->Write("/MainFrame/w", (long) w
);
279 p_ProgramCfg
->Write("/MainFrame/h", (long) h
);
280 p_ProgramCfg
->Write("/MainFrame/Sash", (long) pDoc
->Sash
);
281 // clean up: Set() returns the active config object as Get() does, but unlike
282 // Get() it doesn't try to create one if there is none (definitely not what
284 // delete wxConfigBase::Set((wxConfigBase *) NULL);
285 p_ProgramCfg
->Flush(TRUE
); // saves Objekt
286 delete frame
->pDoc
; // Cleanup (mjDoc::~mjDoc)
287 } // MainFrame::~MainFrame(void)
288 //----------------------------------------------------------------------------------------
289 void MainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
291 // Close the help frame; this will cause the config data to get written.
292 if (p_Help
->GetFrame()) // returns NULL if no help frame active
293 p_Help
->GetFrame()->Close(TRUE
);
296 //----------------------------------------------------------------------------------------
297 void MainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
299 wxMessageDialog
dialog(this, _("DBBrowser\nMark Johnson\nBerlin, Germany\nmj10777@gmx.net\n (c) 1999"),
300 _("About DBBrowser"), wxOK
|wxCANCEL
);
304 //----------------------------------------------------------------------------------------
305 void MainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
307 p_Help
->Display("Main page");
309 //----------------------------------------------------------------------------------------