]>
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
10 //------------------------------------------------------------------------------
11 //-- all #ifdefs that the whole Project needs. ------------------------------
12 //---------------------------------------------------------------------------
14 #pragma implementation
17 //---------------------------------------------------------------------------
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
20 //---------------------------------------------------------------------------
24 //---------------------------------------------------------------------------
28 //---------------------------------------------------------------------------
31 #include "bitmaps/logo.xpm"
32 //---------------------------------------------------------------------------
33 //-- all #includes that every .cpp needs --- 19990807.mj10777 ---
34 //---------------------------------------------------------------------------
35 #include "std.h" // sorgsam Pflegen !
37 //---------------------------------------------------------------------------
38 //-- Some Global Vars for this file ----------------------------------------
39 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 MainFrame
*frame
= NULL
; // The one and only MainFrame
42 // wxLogNull logNo; // No Log messages
43 //---------------------------------------------------------------------------
44 // verify that the item is ok and insult the user if it is not
45 #define CHECK_ITEM(item) \
48 wxMessageBox(_("Please select some item first!"),_("Tree sample error"), \
49 wxOK | wxICON_EXCLAMATION,this); \
52 //---------------------------------------------------------------------------
53 BEGIN_EVENT_TABLE(MainFrame
, wxFrame
)
54 EVT_MENU(QUIT
, MainFrame::OnQuit
)
55 EVT_MENU(ABOUT
, MainFrame::OnAbout
)
56 EVT_MENU(HELP
, MainFrame::OnHelp
)
57 EVT_SIZE(MainFrame::OnSize
)
59 //---------------------------------------------------------------------------
61 //---------------------------------------------------------------------------
62 // `Main program' equivalent, creating windows and returning main app frame
63 //---------------------------------------------------------------------------
64 bool MyApp::OnInit(void)
66 //---------------------------------------------------------------------------------------
67 // set the language to use
68 const char *langhelp
= NULL
;
69 const char *language
= NULL
;
70 const char *langid
= NULL
;
71 //---------------------------------------------------------------------------------------
73 wxImage::AddHandler( new wxPNGHandler
); // use only when needed, otherwise big .exe's
77 wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's
79 wxImage::AddHandler( new wxGIFHandler ); // use only when needed, otherwise big .exe's
80 wxImage::AddHandler( new wxPCXHandler ); // use only when needed, otherwise big .exe's
81 wxImage::AddHandler( new wxPNMHandler ); // use only when needed, otherwise big .exe's
84 // wxBitmap::AddHandler( new wxXPMFileHandler ); // use only when needed, otherwise big .exe's
85 // wxBitmap::AddHandler( new wxXPMDataHandler ); // use only when needed, otherwise big .exe's
87 //---------------------------------------------------------------------------------------
88 langid
= "std"; // BJO20000125 instead of ""
92 // ignore the other args, fall through
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 SetVendorName("mj10777");
116 SetAppName("DBBrowser"); // not needed, it's the default value
117 p_ProgramCfg
= wxConfigBase::Get();
118 // p_ProgramCfg->DeleteAll();
119 p_ProgramCfg
->SetPath("/");
120 wxString Temp0
, Temp1
;
123 //---------------------------------------------------------------------------------------
124 //-- Set the Language and remember it for the next time. --------------------------------
125 //---------------------------------------------------------------------------------------
126 langhelp
= "help.std/dbbrowse.hhp";
129 p_ProgramCfg
->Read("/Local/langid",&Temp0
); // >const char *langid< can't be used here
136 p_ProgramCfg
->Write("/Local/langid",Temp0
); // >const char *langid< can't be used here
137 //---------------------------------------------------------------------------------------
138 // Support the following languages
143 language
= "czech"; // csy or czech
144 langhelp
= "help.cz/dbbrowse.hhp";
146 if ((Temp0
== "de") || (Temp0
== "a"))
148 language
= "german"; // deu or german
149 langhelp
= "help.de/dbbrowse.hhp";
153 language
= "french"; // fra or french
154 langhelp
= "help.fr/dbbrowse.hhp";
158 language
= "polish"; // plk or polish
159 langhelp
= "help.pl/dbbrowse.hhp";
161 if (!m_locale
.Init(language
, langid
, language
)) // setlocale(LC_ALL,""); does not work
162 wxMessageBox("SetLocale error");
163 m_locale
.AddCatalog("PgmText");
164 m_locale
.AddCatalog("Help");
166 p_ProgramCfg
->Write("/Local/language",Temp0
);
171 p_ProgramCfg
->Write("/Local/language",Temp0
);
172 Temp0
= "std"; // allways english if not german or french (at the moment austrian)
176 p_ProgramCfg
->Write("/NONE",Temp0
);
177 p_ProgramCfg
->Write("/Paths/NONE",Temp0
);
178 p_ProgramCfg
->Write("/MainFrame/NONE",Temp0
);
179 //-----------------------------------------------------------------------------
180 p_ProgramCfg
->Write("/Paths/Work",wxGetCwd());
181 p_ProgramCfg
->SetPath("/");
182 //-----------------------------------------------------------------------------
183 // or you could also write something like this:
184 // wxFileConfig *p_ProgramCfg = new wxFileConfig("conftest");
185 // wxConfigBase::Set(p_ProgramCfg);
186 // where you can also specify the file names explicitly if you wish.
187 // Of course, calling Set() is optional and you only must do it if
188 // you want to later retrieve this pointer with Get().
189 //----------------------------------------------------------------------------
190 // SetPath() understands ".."
191 // restore frame position and size
192 int x
= p_ProgramCfg
->Read("/MainFrame/x", 1), y
= p_ProgramCfg
->Read("/MainFrame/y", 1),
193 w
= p_ProgramCfg
->Read("/MainFrame/w", 600), h
= p_ProgramCfg
->Read("/MainFrame/h", 450);
194 //---------------------------------------------------------------------------------------
195 // Create the main frame window
196 frame
= new MainFrame((wxFrame
*) NULL
, (char *) _("DBBrowser - mj10777"),x
,y
,w
,h
);
197 //---------------------------------------------------------------------------------------
198 // This reduces flicker effects - even better would be to define OnEraseBackground
199 // to do Temp0. When the list control's scrollbars are show or hidden, the
200 // frame is sent a background erase event.
201 //---------------------------------------------------------------------------------------
202 frame
->SetBackgroundColour( *wxWHITE
);
203 // frame->SetBackgroundColour(wxColour(255, 255, 255));
205 //---------------------------------------------------------------------------------------
207 wxMenu
*file_menu
= new wxMenu
;
208 wxMenu
*help_menu
= new wxMenu
;
210 help_menu
->Append(HELP
, _("&Help"));
211 help_menu
->AppendSeparator();
212 help_menu
->Append(ABOUT
, _("&About"));
213 file_menu
->Append(QUIT
, _("E&xit"));
215 wxMenuBar
*menu_bar
= new wxMenuBar
;
216 menu_bar
->Append(file_menu
, _("&File"));
217 menu_bar
->Append(help_menu
, _("&Help"));
218 frame
->SetMenuBar(menu_bar
);
219 frame
->CreateStatusBar(1);
220 Temp0
.Printf(_("%s has started !"),p_ProgramCfg
->GetAppName().c_str());
221 frame
->SetStatusText(Temp0
, 0);
222 //---------------------------------------------------------------------------------------
224 frame
->GetClientSize(&width
, &height
);
226 frame
->p_Splitter
= new DocSplitterWindow(frame
, SPLITTER_WINDOW
);
228 // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL));
229 frame
->pDoc
= new mjDoc();
230 frame
->pDoc
->p_MainFrame
= frame
;
231 frame
->pDoc
->p_Splitter
= frame
->p_Splitter
;
232 frame
->pDoc
->p_Splitter
->pDoc
= frame
->pDoc
; // ControlBase: saving the Sash
233 if (!frame
->pDoc
->OnNewDocument())
235 // frame->Maximize();
236 // frame->SetSize(-1,-1); // the wxSplitter does not show correctly without this !
237 frame
->SetClientSize(width
, height
); // the wxSplitter does not show correctly without this !
238 //---------------------------------------------------------------------------------------
239 //-- Problem : GetClientSize(Width,Hight) are not the same as the values given in the ---
240 //-- construction of the Frame. ---
241 //-- Solved : GetClientSize is called here and the difference is noted. When the ---
242 //-- Window is closed the diff. is added to the result of GetClientSize. ---
243 //---------------------------------------------------------------------------------------
244 frame
->GetClientSize(&frame
->DiffW
, &frame
->DiffH
); frame
->DiffW
-=w
; frame
->DiffH
-=h
;
245 //----------------------------------------------------------------------------
247 //----------------------------------------------------------------------------
249 frame
->help
.UseConfig(p_ProgramCfg
);
250 frame
->help
.AddBook(langhelp
);
252 if (!frame->help.AddBook("helpfiles/dbbrowse.hhp"))
253 wxMessageBox("Failed adding book helpfiles/dbbrowse.hhp");
254 if (!frame->help.AddBook("helpfiles/testing.hhp"))
255 wxMessageBox("Failed adding book helpfiles/testing.hhp");
256 if (!frame->help.AddBook("helpfiles/another.hhp"))
257 wxMessageBox("Failed adding book helpfiles/another.hhp");
261 //---------------------------------------------------------------------------------------
262 p_ProgramCfg
->Flush(TRUE
); // sicher Objekt
264 //---------------------------------------------------------------------------------------
273 //---------------------------------------------------------------------------
274 // My frame constructor
275 //---------------------------------------------------------------------------
276 MainFrame::MainFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
):
277 wxFrame(frame
, SPLITTER_FRAME
, title
, wxPoint(x
, y
), wxSize(w
, h
))
280 // This reduces flicker effects - even better would be to define OnEraseBackground
281 // to do Temp0. When the list control's scrollbars are show or hidden, the
282 // frame is sent a background erase event.
283 SetBackgroundColour( *wxWHITE
);
284 // frame->SetBackgroundColour(wxColour(255, 255, 255));
285 //---------------------------------------------------------------------------------------
287 SetIcon( wxICON(Logo
) );
288 //---------------------------------------------------------------------------------------
290 //---------------------------------------------------------------------------
291 MainFrame::~MainFrame(void)
293 // save the control's values to the config
294 if ( p_ProgramCfg
== NULL
)
296 // save the frame position
299 GetClientSize(&w
, &h
); w
-= DiffW
; h
-= DiffH
;
300 p_ProgramCfg
->Write("/MainFrame/x", (long) x
);
301 p_ProgramCfg
->Write("/MainFrame/y", (long) y
);
302 p_ProgramCfg
->Write("/MainFrame/w", (long) w
);
303 p_ProgramCfg
->Write("/MainFrame/h", (long) h
);
304 p_ProgramCfg
->Write("/MainFrame/Sash", (long) pDoc
->Sash
);
305 // clean up: Set() returns the active config object as Get() does, but unlike
306 // Get() it doesn't try to create one if there is none (definitely not what
308 // delete wxConfigBase::Set((wxConfigBase *) NULL);
309 p_ProgramCfg
->Flush(TRUE
); // sichert Objekt
312 //--------------------------------------------------------------------------------------
313 void MainFrame::InitializeMenu()
315 //---------------------------------------------------------------------------------------
317 //---------------------------------------------------------------------------------------
318 wxMenu
*file_menu
= new wxMenu
;
320 file_menu
->Append(ABOUT
, _("&About"));
321 file_menu
->AppendSeparator();
322 file_menu
->Append(QUIT
, _("E&xit"));
325 wxMenuBar
*menu_bar
= new wxMenuBar
;
326 menu_bar
->Append(file_menu
, _("&File"));
327 SetMenuBar(menu_bar
);
329 //---------------------------------------------------------------------------
330 void MainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
332 // Close the help frame; this will cause the config data to
334 if (help
.GetFrame()) // returns NULL if no help frame active
335 help
.GetFrame()->Close(TRUE
);
338 //---------------------------------------------------------------------------
339 void MainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
341 wxMessageDialog
dialog(this, _("DBBrowser\nMark Johnson\nBerlin, Germany\nmj10777@gmx.net\n (c) 1999"),
342 _("About DBBrowser"), wxOK
|wxCANCEL
);
346 //---------------------------------------------------------------------------
347 void MainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
349 help
.Display("Main page");
351 //---------------------------------------------------------------------------