]>
git.saurik.com Git - wxWidgets.git/blob - demos/dbbrowse/dbbrowse.cpp
8f19fc8526ce6ca6b678235e2277932c9dedcf4d
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 //----------------------------------------------------------------------------------------
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
15 //----------------------------------------------------------------------------------------
19 //----------------------------------------------------------------------------------------
24 #include "wx/stockitem.h"
25 //----------------------------------------------------------------------------------------
27 #include "bitmaps/logo.xpm"
29 //----------------------------------------------------------------------------------------
30 //-- all #includes that every .cpp needs --- 19990807.mj10777 ----------------
31 //----------------------------------------------------------------------------------------
32 #include "std.h" // sorgsam Pflegen !
33 // #include <iostream>
34 //----------------------------------------------------------------------------------------
35 //-- Some Global Vars for this file ------------------------------------------------------
36 //----------------------------------------------------------------------------------------
37 BEGIN_EVENT_TABLE(MainFrame
, wxFrame
)
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
43 //----------------------------------------------------------------------------------------
44 IMPLEMENT_APP(MainApp
) // This declares wxApp::MainApp as "the" Application
46 //----------------------------------------------------------------------------------------
47 // 'Main program' equivalent, creating windows and returning main app frame
48 //----------------------------------------------------------------------------------------
49 bool MainApp::OnInit(void) // Does everything needed for a program start
51 wxString Temp0
; // Use as needed
52 //---------------------------------------------------------------------------------------
53 // set the language to use // Help.?? (.std = english, .de = german etc.)
54 const wxChar
*language
= NULL
; // czech, german, french, polish
55 const wxChar
*langid
= NULL
; // std = english , cz, de = german, fr = french, pl = polish
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 //---------------------------------------------------------------------------------------
63 wxImage::AddHandler( new wxPNGHandler
); // needed for help System
67 wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's
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
74 // wxBitmap::AddHandler( new wxXPMFileHandler ); // Attempt to use XPS instead of ico
75 // wxBitmap::AddHandler( new wxXPMDataHandler ); // - Attempt failed
77 //---------------------------------------------------------------------------------------
81 // ignore the other args, fall through
83 language
= argv
[2]; // czech, english, french, german , polish
84 langid
= argv
[1]; // cz, std, fr, de , pl
87 langid
= argv
[1]; // cz, std, fr, de , pl
93 //---------------------------------------------------------------------------------------
94 // Win-Registry : Workplace\HKEY_CURRENT_USERS\Software\%GetVendorName()\%GetAppName()
95 //---------------------------------------------------------------------------------------
96 SetVendorName(_T("mj10777")); // Needed to get Configuration Information
97 SetAppName(_T("DBBrowse")); // "" , also needed for s_LangHelp
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
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
112 p_ProgramCfg
->SetPath(_T("/")); // Start at root
113 //---------------------------------------------------------------------------------------
114 //-- Set the Language and remember it for the next time. --------------------------------
115 //---------------------------------------------------------------------------------------
116 if (langid
== NULL
) // No Parameter was given
119 p_ProgramCfg
->Read(_T("/Local/langid"),&Temp0
); // >const char *langid< can't be used here
121 langid
= _T("std"); // Standard language is "std" = english
125 Temp0
.Printf(_T("%s"),langid
);
126 //---------------------------------------------------------------------------------------
127 // Support the following languages (std = english)
128 if ((Temp0
== _T("a")) || (Temp0
== _T("cz")) || (Temp0
== _T("de")) ||
129 (Temp0
== _T("fr")) || (Temp0
== _T("pl")))
130 { // The three-letter language-string codes are only valid in Windows NT and Windows 95.
131 if (Temp0
== _T("cz"))
132 language
= _T("czech"); // csy or czech
133 if ((Temp0
== _T("de")) || (Temp0
== _T("a")))
135 language
= _T("german"); // deu or german
136 if (Temp0
== _T("a"))
137 { langid
= Temp0
= _T("de"); } // Austrian = german
138 } // german / austrian
139 if (Temp0
== _T("fr"))
140 language
= _T("french"); // fra or french
141 if (Temp0
== _T("pl"))
142 language
= _T("polish"); // plk or polish
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
145 wxLogMessage(_T("-E-> %s : SetLocale error : langid(%s) ; language(%s)"),GetAppName().c_str(),langid
,language
);
147 language
= _T("C"); // english, english-aus , -can , -nz , -uk , -usa
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());
154 m_locale
.AddCatalog(_T("help"));
156 } // Support the following languages (std = english)
160 language
= _T("C"); // english, english-aus , -can , -nz , -uk , -usa
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";
167 s_LangHelp
= s_LangHelp
.Lower(); // A must for Linux
168 //---------------------------------------------------------------------------------------
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
173 //---------------------------------------------------------------------------------------
174 p_ProgramCfg
->Write(_T("/Paths/Work"),wxGetCwd()); // Get current Working Path
175 p_ProgramCfg
->SetPath(_T("/"));
176 //---------------------------------------------------------------------------------------
177 // restore frame position and size, if empty start Values (1,1) and (750,600)
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);
180 //---------------------------------------------------------------------------------------
181 // Create the main frame window
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
));
184 //---------------------------------------------------------------------------------------
185 // Set the Backgroundcolour (only needed if you are NOT using wxSYS_COLOUR_BACKGROUND)
186 frame
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND
));
187 // frame->SetBackgroundColour(wxColour(255, 255, 255));
188 // frame->SetBackgroundColour(* wxWHITE);
189 //---------------------------------------------------------------------------------------
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 //---------------------------------------------------------------------------------------
204 wxMenu
*file_menu
= new wxMenu
;
205 wxMenu
*help_menu
= new wxMenu
;
207 help_menu
->Append(wxID_HELP
, wxGetStockLabel(wxID_HELP
));
208 help_menu
->AppendSeparator();
209 help_menu
->Append(wxID_ABOUT
, _("&About"));
210 file_menu
->Append(wxID_EXIT
, wxGetStockLabel(wxID_EXIT
));
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
);
217 frame
->CreateStatusBar(1);
218 Temp0
.Printf(_("%s has started !"),p_ProgramCfg
->GetAppName().c_str());
219 frame
->SetStatusText(Temp0
, 0);
220 #endif // wxUSE_STATUSBAR
221 //---------------------------------------------------------------------------------------
223 frame
->GetClientSize(&width
, &height
);
224 //---------------------------------------------------------------------------------------
225 frame
->p_Splitter
= new DocSplitterWindow(frame
,wxID_ANY
);
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 //---------------------------------------------------------------------------------------
232 //-- Problem : GetClientSize(Width,Height) are not the same as the values given in the ---
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
246 wxLogMessage(_T("-E-> %s : AddBook error : s_LangHelp(%s)"),GetAppName().c_str(),s_LangHelp
.c_str());
248 frame
->pDoc
->p_Help
= frame
->p_Help
; // Save the information to the document
249 //---------------------------------------------------------------------------------------
250 frame
->Show(true); // Show the frame
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())
256 // Kill a "Splash Screen" because OnNewDocument, if you have one
257 //---------------------------------------------------------------------------------------
258 p_ProgramCfg
->Flush(true); // save the configuration
260 } // bool MainApp::OnInit(void)
262 //----------------------------------------------------------------------------------------
263 // My frame constructor
264 //----------------------------------------------------------------------------------------
265 MainFrame::MainFrame(wxFrame
*frame
, wxChar
*title
, const wxPoint
& pos
, const wxSize
& size
):
266 wxFrame(frame
, wxID_ANY
, title
, pos
, size
)
268 p_Splitter
= NULL
; pDoc
= NULL
; p_Help
= NULL
; // Keep the Pointers clean !
269 //--- Everything else is done in MainApp::OnInit() --------------------------------------
272 //----------------------------------------------------------------------------------------
273 MainFrame::~MainFrame(void)
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
277 p_Help
->GetFrame()->Close(true);
278 delete p_Help
; // Memory Leak
280 // save the control's values to the config
281 if (p_ProgramCfg
== NULL
)
283 // save the frame position before it is destroyed
286 GetClientSize(&w
, &h
); w
-= DiffW
; h
-= DiffH
;
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
);
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
295 // delete wxConfigBase::Set((wxConfigBase *) NULL);
296 p_ProgramCfg
->Flush(true); // saves Objekt
297 if (pDoc
) // If we have a Valid Document
298 delete pDoc
; // Cleanup (MainDoc::~MainDoc)
299 } // MainFrame::~MainFrame(void)
301 //----------------------------------------------------------------------------------------
302 void MainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
307 //----------------------------------------------------------------------------------------
308 void MainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
310 wxString Temp0
, Temp1
;
311 Temp0
.Printf(_("%s\nMark Johnson\nBerlin, Germany\nwxWindows@mj10777.de\n (c) 2000"),p_ProgramCfg
->GetAppName().c_str());
312 Temp1
.Printf(_("About %s"),p_ProgramCfg
->GetAppName().c_str());
313 wxMessageDialog
dialog(this, Temp0
,Temp1
,wxOK
|wxCANCEL
);
317 //----------------------------------------------------------------------------------------
318 void MainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
320 p_Help
->Display(_T("Main page"));
322 //----------------------------------------------------------------------------------------