]>
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 //---------------------------------------------------------------------------
42 MainFrame
*frame
= NULL
; // The one and only MainFrame
43 // wxLogNull logNo; // No Log messages
44 //---------------------------------------------------------------------------
45 // verify that the item is ok and insult the user if it is not
46 #define CHECK_ITEM(item) \
49 wxMessageBox(_("Please select some item first!"),_("Tree sample error"), \
50 wxOK | wxICON_EXCLAMATION,this); \
53 //---------------------------------------------------------------------------
54 BEGIN_EVENT_TABLE(MainFrame
, wxFrame
)
55 EVT_MENU(QUIT
, MainFrame::OnQuit
)
56 EVT_MENU(ABOUT
, MainFrame::OnAbout
)
57 EVT_MENU(HELP
, MainFrame::OnHelp
)
58 EVT_SIZE(MainFrame::OnSize
)
60 //---------------------------------------------------------------------------
62 //---------------------------------------------------------------------------
63 // `Main program' equivalent, creating windows and returning main app frame
64 //---------------------------------------------------------------------------
65 bool MyApp::OnInit(void)
67 //---------------------------------------------------------------------------------------
68 // set the language to use
69 const char *langhelp
= NULL
;
70 const char *language
= NULL
;
71 const char *langid
= NULL
;
72 //---------------------------------------------------------------------------------------
74 wxImage::AddHandler( new wxPNGHandler
); // use only when needed, otherwise big .exe's
78 wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's
80 wxImage::AddHandler( new wxGIFHandler ); // use only when needed, otherwise big .exe's
81 wxImage::AddHandler( new wxPCXHandler ); // use only when needed, otherwise big .exe's
82 wxImage::AddHandler( new wxPNMHandler ); // use only when needed, otherwise big .exe's
85 // wxBitmap::AddHandler( new wxXPMFileHandler ); // use only when needed, otherwise big .exe's
86 // wxBitmap::AddHandler( new wxXPMDataHandler ); // use only when needed, otherwise big .exe's
88 //---------------------------------------------------------------------------------------
89 langid
= "std"; // BJO20000125 instead of ""
93 // ignore the other args, fall through
104 //---------------------------------------------------------------------------------------
105 // we're using wxConfig's "create-on-demand" feature: it will create the
106 // config object when it's used for the first time. It has a number of
107 // advantages compared with explicitly creating our wxConfig:
108 // 1) we don't pay for it if we don't use it
109 // 2) there is no danger to create it twice
111 // application and vendor name are used by wxConfig to construct the name
112 // of the config file/registry key and must be set before the first call
113 // to Get() if you want to override the default values (the application
114 // name is the name of the executable and the vendor name is the same)
115 //---------------------------------------------------------------------------------------
116 SetVendorName("mj10777");
117 SetAppName("DBBrowser"); // not needed, it's the default value
118 p_ProgramCfg
= wxConfigBase::Get();
119 // p_ProgramCfg->DeleteAll();
120 p_ProgramCfg
->SetPath("/");
121 wxString Temp0
, Temp1
;
124 //---------------------------------------------------------------------------------------
125 //-- Set the Language and remember it for the next time. --------------------------------
126 //---------------------------------------------------------------------------------------
127 langhelp
= "help.std/dbbrowse.hhp";
130 p_ProgramCfg
->Read("/Local/langid",&Temp0
); // >const char *langid< can't be used here
137 p_ProgramCfg
->Write("/Local/langid",Temp0
); // >const char *langid< can't be used here
138 //---------------------------------------------------------------------------------------
139 // Support the following languages
144 language
= "czech"; // csy or czech
145 langhelp
= "help.cz/dbbrowse.hhp";
147 if ((Temp0
== "de") || (Temp0
== "a"))
149 language
= "german"; // deu or german
150 langhelp
= "help.de/dbbrowse.hhp";
154 language
= "french"; // fra or french
155 langhelp
= "help.fr/dbbrowse.hhp";
159 language
= "polish"; // plk or polish
160 langhelp
= "help.pl/dbbrowse.hhp";
162 if (!m_locale
.Init(language
, langid
, language
)) // setlocale(LC_ALL,""); does not work
163 wxMessageBox("SetLocale error");
164 m_locale
.AddCatalog("PgmText");
165 m_locale
.AddCatalog("Help");
167 p_ProgramCfg
->Write("/Local/language",Temp0
);
172 p_ProgramCfg
->Write("/Local/language",Temp0
);
173 Temp0
= "std"; // allways english if not german or french (at the moment austrian)
177 p_ProgramCfg
->Write("/NONE",Temp0
);
178 p_ProgramCfg
->Write("/Paths/NONE",Temp0
);
179 p_ProgramCfg
->Write("/MainFrame/NONE",Temp0
);
180 //-----------------------------------------------------------------------------
181 p_ProgramCfg
->Write("/Paths/Work",wxGetCwd());
182 p_ProgramCfg
->SetPath("/");
183 //-----------------------------------------------------------------------------
184 // or you could also write something like this:
185 // wxFileConfig *p_ProgramCfg = new wxFileConfig("conftest");
186 // wxConfigBase::Set(p_ProgramCfg);
187 // where you can also specify the file names explicitly if you wish.
188 // Of course, calling Set() is optional and you only must do it if
189 // you want to later retrieve this pointer with Get().
190 //----------------------------------------------------------------------------
191 // SetPath() understands ".."
192 // restore frame position and size
193 int x
= p_ProgramCfg
->Read("/MainFrame/x", 1), y
= p_ProgramCfg
->Read("/MainFrame/y", 1),
194 w
= p_ProgramCfg
->Read("/MainFrame/w", 600), h
= p_ProgramCfg
->Read("/MainFrame/h", 450);
195 //---------------------------------------------------------------------------------------
196 // Create the main frame window
197 frame
= new MainFrame((wxFrame
*) NULL
, (char *) _("DBBrowser - mj10777"),x
,y
,w
,h
);
198 //---------------------------------------------------------------------------------------
199 // This reduces flicker effects - even better would be to define OnEraseBackground
200 // to do Temp0. When the list control's scrollbars are show or hidden, the
201 // frame is sent a background erase event.
202 //---------------------------------------------------------------------------------------
203 frame
->SetBackgroundColour( *wxWHITE
);
204 // frame->SetBackgroundColour(wxColour(255, 255, 255));
206 //---------------------------------------------------------------------------------------
208 wxMenu
*file_menu
= new wxMenu
;
209 wxMenu
*help_menu
= new wxMenu
;
211 help_menu
->Append(HELP
, _("&Help"));
212 help_menu
->AppendSeparator();
213 help_menu
->Append(ABOUT
, _("&About"));
214 file_menu
->Append(QUIT
, _("E&xit"));
216 wxMenuBar
*menu_bar
= new wxMenuBar
;
217 menu_bar
->Append(file_menu
, _("&File"));
218 menu_bar
->Append(help_menu
, _("&Help"));
219 frame
->SetMenuBar(menu_bar
);
220 frame
->CreateStatusBar(1);
221 Temp0
.Printf(_("%s has started !"),p_ProgramCfg
->GetAppName().c_str());
222 frame
->SetStatusText(Temp0
, 0);
223 //---------------------------------------------------------------------------------------
225 frame
->GetClientSize(&width
, &height
);
227 frame
->p_Splitter
= new DocSplitterWindow(frame
, SPLITTER_WINDOW
);
229 // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL));
230 frame
->pDoc
= new mjDoc();
231 frame
->pDoc
->p_MainFrame
= frame
;
232 frame
->pDoc
->p_Splitter
= frame
->p_Splitter
;
233 frame
->pDoc
->p_Splitter
->pDoc
= frame
->pDoc
; // ControlBase: saving the Sash
234 if (!frame
->pDoc
->OnNewDocument())
236 // frame->Maximize();
237 // frame->SetSize(-1,-1); // the wxSplitter does not show correctly without this !
238 frame
->SetClientSize(width
, height
); // the wxSplitter does not show correctly without this !
239 //---------------------------------------------------------------------------------------
240 //-- Problem : GetClientSize(Width,Hight) are not the same as the values given in the ---
241 //-- construction of the Frame. ---
242 //-- Solved : GetClientSize is called here and the difference is noted. When the ---
243 //-- Window is closed the diff. is added to the result of GetClientSize. ---
244 //---------------------------------------------------------------------------------------
245 frame
->GetClientSize(&frame
->DiffW
, &frame
->DiffH
); frame
->DiffW
-=w
; frame
->DiffH
-=h
;
246 //----------------------------------------------------------------------------
248 //----------------------------------------------------------------------------
250 frame
->help
.UseConfig(p_ProgramCfg
);
251 frame
->help
.AddBook(langhelp
);
253 if (!frame->help.AddBook("helpfiles/dbbrowse.hhp"))
254 wxMessageBox("Failed adding book helpfiles/dbbrowse.hhp");
255 if (!frame->help.AddBook("helpfiles/testing.hhp"))
256 wxMessageBox("Failed adding book helpfiles/testing.hhp");
257 if (!frame->help.AddBook("helpfiles/another.hhp"))
258 wxMessageBox("Failed adding book helpfiles/another.hhp");
262 //---------------------------------------------------------------------------------------
263 p_ProgramCfg
->Flush(TRUE
); // sicher Objekt
265 //---------------------------------------------------------------------------------------
274 //---------------------------------------------------------------------------
275 // My frame constructor
276 //---------------------------------------------------------------------------
277 MainFrame::MainFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
):
278 wxFrame(frame
, SPLITTER_FRAME
, title
, wxPoint(x
, y
), wxSize(w
, h
))
281 // This reduces flicker effects - even better would be to define OnEraseBackground
282 // to do Temp0. When the list control's scrollbars are show or hidden, the
283 // frame is sent a background erase event.
284 SetBackgroundColour( *wxWHITE
);
285 // frame->SetBackgroundColour(wxColour(255, 255, 255));
286 //---------------------------------------------------------------------------------------
288 SetIcon( wxICON(Logo
) );
289 //---------------------------------------------------------------------------------------
291 //---------------------------------------------------------------------------
292 MainFrame::~MainFrame(void)
294 // save the control's values to the config
295 if ( p_ProgramCfg
== NULL
)
297 // save the frame position
300 GetClientSize(&w
, &h
); w
-= DiffW
; h
-= DiffH
;
301 p_ProgramCfg
->Write("/MainFrame/x", (long) x
);
302 p_ProgramCfg
->Write("/MainFrame/y", (long) y
);
303 p_ProgramCfg
->Write("/MainFrame/w", (long) w
);
304 p_ProgramCfg
->Write("/MainFrame/h", (long) h
);
305 p_ProgramCfg
->Write("/MainFrame/Sash", (long) pDoc
->Sash
);
306 // clean up: Set() returns the active config object as Get() does, but unlike
307 // Get() it doesn't try to create one if there is none (definitely not what
309 // delete wxConfigBase::Set((wxConfigBase *) NULL);
310 p_ProgramCfg
->Flush(TRUE
); // sichert Objekt
313 //--------------------------------------------------------------------------------------
314 void MainFrame::InitializeMenu()
316 //---------------------------------------------------------------------------------------
318 //---------------------------------------------------------------------------------------
319 wxMenu
*file_menu
= new wxMenu
;
321 file_menu
->Append(ABOUT
, _("&About"));
322 file_menu
->AppendSeparator();
323 file_menu
->Append(QUIT
, _("E&xit"));
326 wxMenuBar
*menu_bar
= new wxMenuBar
;
327 menu_bar
->Append(file_menu
, _("&File"));
328 SetMenuBar(menu_bar
);
330 //---------------------------------------------------------------------------
331 void MainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
333 // Close the help frame; this will cause the config data to
335 if (help
.GetFrame()) // returns NULL if no help frame active
336 help
.GetFrame()->Close(TRUE
);
339 //---------------------------------------------------------------------------
340 void MainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
342 wxMessageDialog
dialog(this, _("DBBrowser\nMark Johnson\nBerlin, Germany\nmj10777@gmx.net\n (c) 1999"),
343 _("About DBBrowser"), wxOK
|wxCANCEL
);
347 //---------------------------------------------------------------------------
348 void MainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
350 help
.Display("Main page");
352 //---------------------------------------------------------------------------