]>
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 //----------------------------------------------------------------------------------------
32 #include "bitmaps/logo.xpm"
33 //----------------------------------------------------------------------------------------
34 //-- all #includes that every .cpp needs --- 19990807.mj10777 ----------------
35 //----------------------------------------------------------------------------------------
36 #include "std.h" // sorgsam Pflegen !
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
)
45 EVT_MENU(ABOUT
, MainFrame::OnAbout
)
46 EVT_MENU(HELP
, MainFrame::OnHelp
)
47 EVT_SIZE(MainFrame::OnSize
)
49 //----------------------------------------------------------------------------------------
50 IMPLEMENT_APP(MainApp
)
51 //----------------------------------------------------------------------------------------
52 // 'Main program' equivalent, creating windows and returning main app frame
53 //----------------------------------------------------------------------------------------
54 bool MainApp::OnInit(void)
56 //---------------------------------------------------------------------------------------
57 // set the language to use
58 const char *langhelp
= NULL
;
59 const char *language
= NULL
;
60 const char *langid
= NULL
;
61 //---------------------------------------------------------------------------------------
62 //-- Graphic File suport - use only when needed, otherwise big .exe's
63 //---------------------------------------------------------------------------------------
65 wxImage::AddHandler( new wxPNGHandler
); // needed for help System
69 wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's
71 wxImage::AddHandler( new wxGIFHandler ); // use only when needed, otherwise big .exe's
72 wxImage::AddHandler( new wxPCXHandler ); // use only when needed, otherwise big .exe's
73 wxImage::AddHandler( new wxPNMHandler ); // use only when needed, otherwise big .exe's
76 // wxBitmap::AddHandler( new wxXPMFileHandler ); // Attempt to use XPS instead of ico
77 // wxBitmap::AddHandler( new wxXPMDataHandler ); // - Attempt failed
79 //---------------------------------------------------------------------------------------
80 langid
= "std"; // Standard language is "std" = english
84 // ignore the other args, fall through
95 //---------------------------------------------------------------------------------------
96 // we're using wxConfig's "create-on-demand" feature: it will create the
97 // config object when it's used for the first time. It has a number of
98 // advantages compared with explicitly creating our wxConfig:
99 // 1) we don't pay for it if we don't use it
100 // 2) there is no danger to create it twice
102 // application and vendor name are used by wxConfig to construct the name
103 // of the config file/registry key and must be set before the first call
104 // to Get() if you want to override the default values (the application
105 // name is the name of the executable and the vendor name is the same)
106 //---------------------------------------------------------------------------------------
107 SetVendorName("mj10777");
108 SetAppName("DBBrowser");
109 p_ProgramCfg
= wxConfigBase::Get();
110 // p_ProgramCfg->DeleteAll();
111 p_ProgramCfg
->SetPath("/");
112 wxString Temp0
, Temp1
;
114 //---------------------------------------------------------------------------------------
115 //-- Set the Language and remember it for the next time. --------------------------------
116 //---------------------------------------------------------------------------------------
117 langhelp
= "help.std/dbbrowse.hhp";
120 p_ProgramCfg
->Read("/Local/langid",&Temp0
); // >const char *langid< can't be used here
127 p_ProgramCfg
->Write("/Local/langid",Temp0
); // >const char *langid< can't be used here
128 //---------------------------------------------------------------------------------------
129 // Support the following languages (std = english)
134 language
= "czech"; // csy or czech
135 langhelp
= "help.cz/dbbrowse.hhp";
137 if ((Temp0
== "de") || (Temp0
== "a"))
139 language
= "german"; // deu or german
140 langhelp
= "help.de/dbbrowse.hhp";
144 language
= "french"; // fra or french
145 langhelp
= "help.fr/dbbrowse.hhp";
149 language
= "polish"; // plk or polish
150 langhelp
= "help.pl/dbbrowse.hhp";
152 if (!m_locale
.Init(language
, langid
, language
)) // setlocale(LC_ALL,""); does not work
153 wxMessageBox("SetLocale error");
154 m_locale
.AddCatalog("PgmText");
155 m_locale
.AddCatalog("Help");
157 p_ProgramCfg
->Write("/Local/language",Temp0
);
162 p_ProgramCfg
->Write("/Local/language",Temp0
);
163 Temp0
= "std"; // allways english if not german or french (at the moment austrian)
165 //---------------------------------------------------------------------------------------
167 p_ProgramCfg
->Write("/NONE",Temp0
);
168 p_ProgramCfg
->Write("/Paths/NONE",Temp0
);
169 p_ProgramCfg
->Write("/MainFrame/NONE",Temp0
);
170 //---------------------------------------------------------------------------------------
171 p_ProgramCfg
->Write("/Paths/Work",wxGetCwd());
172 p_ProgramCfg
->SetPath("/");
173 //---------------------------------------------------------------------------------------
174 // restore frame position and size, if empty start Values (1,1) and (750,600)
175 int x
= p_ProgramCfg
->Read("/MainFrame/x", 1), y
= p_ProgramCfg
->Read("/MainFrame/y", 1),
176 w
= p_ProgramCfg
->Read("/MainFrame/w", 750), h
= p_ProgramCfg
->Read("/MainFrame/h", 600);
177 //---------------------------------------------------------------------------------------
178 // Create the main frame window
179 frame
= new MainFrame((wxFrame
*) NULL
, (char *) _("DBBrowser - mj10777"),wxPoint(x
,y
),wxSize(w
,h
));
180 //---------------------------------------------------------------------------------------
181 // Set the Backgroundcolour (only need if your are NOT using wxSYS_COLOUR_BACKGROUND)
182 frame
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BACKGROUND
));
183 // frame->SetBackgroundColour(wxColour(255, 255, 255));
184 // frame->SetBackgroundColour(* wxWHITE);
185 //---------------------------------------------------------------------------------------
187 frame
->SetIcon(wxICON(aLogo
)); // Programm Icon = lowest name in RC File
188 //---------------------------------------------------------------------------------------
190 wxMenu
*file_menu
= new wxMenu
;
191 wxMenu
*help_menu
= new wxMenu
;
193 help_menu
->Append(HELP
, _("&Help"));
194 help_menu
->AppendSeparator();
195 help_menu
->Append(ABOUT
, _("&About"));
196 file_menu
->Append(QUIT
, _("E&xit"));
198 wxMenuBar
*menu_bar
= new wxMenuBar
;
199 menu_bar
->Append(file_menu
, _("&File"));
200 menu_bar
->Append(help_menu
, _("&Help"));
201 frame
->SetMenuBar(menu_bar
);
202 frame
->CreateStatusBar(1);
203 Temp0
.Printf(_("%s has started !"),p_ProgramCfg
->GetAppName().c_str());
204 frame
->SetStatusText(Temp0
, 0);
205 //---------------------------------------------------------------------------------------
207 frame
->GetClientSize(&width
, &height
);
208 //---------------------------------------------------------------------------------------
209 frame
->p_Splitter
= new DocSplitterWindow(frame
,-1);
210 // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL));
211 frame
->pDoc
= new mjDoc();
212 frame
->pDoc
->p_MainFrame
= frame
;
213 frame
->pDoc
->p_Splitter
= frame
->p_Splitter
;
214 frame
->pDoc
->p_Splitter
->pDoc
= frame
->pDoc
; // ControlBase: saving the Sash
215 if (!frame
->pDoc
->OnNewDocument())
217 frame
->SetClientSize(width
, height
); // the wxSplitter does not show correctly without this !
218 //---------------------------------------------------------------------------------------
219 //-- Problem : GetClientSize(Width,Hight) are not the same as the values given in the ---
220 //-- construction of the Frame. ---
221 //-- Solved : GetClientSize is called here and the difference is noted. When the ---
222 //-- Window is closed the diff. is added to the result of GetClientSize. ---
223 //---------------------------------------------------------------------------------------
224 frame
->GetClientSize(&frame
->DiffW
, &frame
->DiffH
); frame
->DiffW
-=w
; frame
->DiffH
-=h
;
225 //----------------------------------------------------------------------------
227 //----------------------------------------------------------------------------
228 frame
->p_Help
= new wxHtmlHelpController(); // construct the Help System
229 frame
->p_Help
->UseConfig(p_ProgramCfg
); // Don't rember what this was for
230 frame
->p_Help
->AddBook(langhelp
); // Use the language set
231 frame
->pDoc
->p_Help
= frame
->p_Help
; // Save the information to the document
232 //---------------------------------------------------------------------------------------
236 //---------------------------------------------------------------------------------------
237 p_ProgramCfg
->Flush(TRUE
); // sicher Objekt
239 } // bool MainApp::OnInit(void)
240 //----------------------------------------------------------------------------------------
241 // My frame constructor
242 //----------------------------------------------------------------------------------------
243 MainFrame::MainFrame(wxFrame
*frame
, char *title
, const wxPoint
& pos
, const wxSize
& size
):
244 wxFrame(frame
, -1, title
, pos
, size
)
246 //--- Everything is done in MainApp -----------------------------------------------------
248 //----------------------------------------------------------------------------------------
249 MainFrame::~MainFrame(void)
251 // save the control's values to the config
252 if ( p_ProgramCfg
== NULL
)
254 // save the frame position
257 GetClientSize(&w
, &h
); w
-= DiffW
; h
-= DiffH
;
258 p_ProgramCfg
->Write("/MainFrame/x", (long) x
);
259 p_ProgramCfg
->Write("/MainFrame/y", (long) y
);
260 p_ProgramCfg
->Write("/MainFrame/w", (long) w
);
261 p_ProgramCfg
->Write("/MainFrame/h", (long) h
);
262 p_ProgramCfg
->Write("/MainFrame/Sash", (long) pDoc
->Sash
);
263 // clean up: Set() returns the active config object as Get() does, but unlike
264 // Get() it doesn't try to create one if there is none (definitely not what
266 // delete wxConfigBase::Set((wxConfigBase *) NULL);
267 p_ProgramCfg
->Flush(TRUE
); // saves Objekt
268 delete frame
->pDoc
; // Cleanup
270 //----------------------------------------------------------------------------------------
271 void MainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
273 // Close the help frame; this will cause the config data to get written.
274 if (p_Help
->GetFrame()) // returns NULL if no help frame active
275 p_Help
->GetFrame()->Close(TRUE
);
278 //----------------------------------------------------------------------------------------
279 void MainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
281 wxMessageDialog
dialog(this, _("DBBrowser\nMark Johnson\nBerlin, Germany\nmj10777@gmx.net\n (c) 1999"),
282 _("About DBBrowser"), wxOK
|wxCANCEL
);
286 //----------------------------------------------------------------------------------------
287 void MainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
289 p_Help
->Display("Main page");
291 //----------------------------------------------------------------------------------------