]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/dbbrowse.cpp
Added enabling/disabling of cell edit control.
[wxWidgets.git] / demos / dbbrowse / dbbrowse.cpp
CommitLineData
c92b0f9a 1//----------------------------------------------------------------------------------------
b5ffecfc
GT
2// Name: dbbrowse.cpp
3// Purpose: Through ODBC - Databases Browsen
4// Author: Mark Johnson, mj10777@gmx.net
5// Modified by:
6// BJO : Bart A.M. JOURQUIN
7// Created: 19991127
8// Copyright: (c) Mark Johnson
9// Licence: wxWindows license
c09d434d 10// RCS-ID: $Id$
c92b0f9a
MJ
11//----------------------------------------------------------------------------------------
12//-- all #ifdefs that the whole Project needs. -------------------------------------------
13//----------------------------------------------------------------------------------------
b5ffecfc
GT
14#ifdef __GNUG__
15 #pragma implementation
16 #pragma interface
17#endif
c92b0f9a 18//----------------------------------------------------------------------------------------
b5ffecfc
GT
19// For compilers that support precompilation, includes "wx/wx.h".
20#include "wx/wxprec.h"
c92b0f9a 21//----------------------------------------------------------------------------------------
b5ffecfc
GT
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
c92b0f9a 25//----------------------------------------------------------------------------------------
b5ffecfc
GT
26#ifndef WX_PRECOMP
27 #include "wx/wx.h"
28#endif
c92b0f9a 29//----------------------------------------------------------------------------------------
b5ffecfc
GT
30#ifndef __WXMSW__
31#endif
32 #include "bitmaps/logo.xpm"
c92b0f9a
MJ
33//----------------------------------------------------------------------------------------
34//-- all #includes that every .cpp needs --- 19990807.mj10777 ----------------
35//----------------------------------------------------------------------------------------
b5ffecfc
GT
36#include "std.h" // sorgsam Pflegen !
37#include <iostream>
c92b0f9a
MJ
38//----------------------------------------------------------------------------------------
39//-- Some Global Vars for this file ------------------------------------------------------
40//----------------------------------------------------------------------------------------
b5ffecfc 41MainFrame *frame = NULL; // The one and only MainFrame
c92b0f9a 42//----------------------------------------------------------------------------------------
b5ffecfc
GT
43BEGIN_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)
48END_EVENT_TABLE()
c92b0f9a
MJ
49//----------------------------------------------------------------------------------------
50IMPLEMENT_APP(MainApp)
51//----------------------------------------------------------------------------------------
52// 'Main program' equivalent, creating windows and returning main app frame
53//----------------------------------------------------------------------------------------
54bool MainApp::OnInit(void)
b5ffecfc
GT
55{
56 //---------------------------------------------------------------------------------------
57 // set the language to use
58 const char *langhelp = NULL;
59 const char *language = NULL;
60 const char *langid = NULL;
61 //---------------------------------------------------------------------------------------
c92b0f9a
MJ
62 //-- Graphic File suport - use only when needed, otherwise big .exe's
63 //---------------------------------------------------------------------------------------
b5ffecfc 64#if wxUSE_LIBPNG
c92b0f9a 65 wxImage::AddHandler( new wxPNGHandler ); // needed for help System
b5ffecfc
GT
66#endif
67/*
68#if wxUSE_LIBJPEG
69 wxImage::AddHandler(new wxJPEGHandler ); // use only when needed, otherwise big .exe's
70#endif
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
74*/
75#ifdef __WXMSW__
c92b0f9a
MJ
76 // wxBitmap::AddHandler( new wxXPMFileHandler ); // Attempt to use XPS instead of ico
77 // wxBitmap::AddHandler( new wxXPMDataHandler ); // - Attempt failed
b5ffecfc
GT
78#endif
79 //---------------------------------------------------------------------------------------
c92b0f9a 80 langid = "std"; // Standard language is "std" = english
b5ffecfc
GT
81 switch ( argc )
82 {
83 default:
84 // ignore the other args, fall through
85 case 3:
86 language = argv[2];
87 langid = argv[1];
88 break;
89 case 2:
90 langid = argv[1];
91 break;
92 case 1:
93 break;
94 };
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
101
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");
c92b0f9a 108 SetAppName("DBBrowser");
b5ffecfc
GT
109 p_ProgramCfg = wxConfigBase::Get();
110 // p_ProgramCfg->DeleteAll();
111 p_ProgramCfg->SetPath("/");
112 wxString Temp0, Temp1;
113 Temp0.Empty();
b5ffecfc
GT
114 //---------------------------------------------------------------------------------------
115 //-- Set the Language and remember it for the next time. --------------------------------
116 //---------------------------------------------------------------------------------------
117 langhelp = "help.std/dbbrowse.hhp";
118 if (langid == "std")
119 {
120 p_ProgramCfg->Read("/Local/langid",&Temp0); // >const char *langid< can't be used here
121 if (Temp0 == "")
122 langid = "std";
123 else
124 langid = Temp0;
125 }
126 Temp0 = langid;
127 p_ProgramCfg->Write("/Local/langid",Temp0); // >const char *langid< can't be used here
128 //---------------------------------------------------------------------------------------
c92b0f9a 129 // Support the following languages (std = english)
b5ffecfc
GT
130 if (Temp0 != "std")
131 {
132 if (Temp0 == "cz")
133 {
134 language = "czech"; // csy or czech
135 langhelp = "help.cz/dbbrowse.hhp";
136 }
137 if ((Temp0 == "de") || (Temp0 == "a"))
138 {
139 language = "german"; // deu or german
140 langhelp = "help.de/dbbrowse.hhp";
141 }
142 if (Temp0 == "fr")
143 {
144 language = "french"; // fra or french
145 langhelp = "help.fr/dbbrowse.hhp";
146 }
147 if (Temp0 == "pl")
148 {
149 language = "polish"; // plk or polish
150 langhelp = "help.pl/dbbrowse.hhp";
151 }
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");
156 Temp0 = language;
157 p_ProgramCfg->Write("/Local/language",Temp0);
158 }
159 else
160 {
161 Temp0 = "english";
162 p_ProgramCfg->Write("/Local/language",Temp0);
163 Temp0 = "std"; // allways english if not german or french (at the moment austrian)
164 }
c92b0f9a 165 //---------------------------------------------------------------------------------------
b5ffecfc
GT
166 Temp0 = "NONE";
167 p_ProgramCfg->Write("/NONE",Temp0);
168 p_ProgramCfg->Write("/Paths/NONE",Temp0);
169 p_ProgramCfg->Write("/MainFrame/NONE",Temp0);
c92b0f9a 170 //---------------------------------------------------------------------------------------
b5ffecfc
GT
171 p_ProgramCfg->Write("/Paths/Work",wxGetCwd());
172 p_ProgramCfg->SetPath("/");
c92b0f9a
MJ
173 //---------------------------------------------------------------------------------------
174 // restore frame position and size, if empty start Values (1,1) and (750,600)
b5ffecfc 175 int x = p_ProgramCfg->Read("/MainFrame/x", 1), y = p_ProgramCfg->Read("/MainFrame/y", 1),
c92b0f9a 176 w = p_ProgramCfg->Read("/MainFrame/w", 750), h = p_ProgramCfg->Read("/MainFrame/h", 600);
b5ffecfc
GT
177 //---------------------------------------------------------------------------------------
178 // Create the main frame window
c92b0f9a 179 frame = new MainFrame((wxFrame *) NULL, (char *) _("DBBrowser - mj10777"),wxPoint(x,y),wxSize(w,h));
b5ffecfc 180 //---------------------------------------------------------------------------------------
c92b0f9a
MJ
181 // Set the Backgroundcolour (only need if your are NOT using wxSYS_COLOUR_BACKGROUND)
182 frame->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BACKGROUND));
b5ffecfc 183 // frame->SetBackgroundColour(wxColour(255, 255, 255));
c92b0f9a
MJ
184 // frame->SetBackgroundColour(* wxWHITE);
185 //---------------------------------------------------------------------------------------
186 // Give it an icon
187 frame->SetIcon(wxICON(aLogo)); // Programm Icon = lowest name in RC File
b5ffecfc
GT
188 //---------------------------------------------------------------------------------------
189 // Make a menubar
190 wxMenu *file_menu = new wxMenu;
191 wxMenu *help_menu = new wxMenu;
192
193 help_menu->Append(HELP, _("&Help"));
194 help_menu->AppendSeparator();
195 help_menu->Append(ABOUT, _("&About"));
196 file_menu->Append(QUIT, _("E&xit"));
197
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 //---------------------------------------------------------------------------------------
206 int width, height;
207 frame->GetClientSize(&width, &height);
c92b0f9a
MJ
208 //---------------------------------------------------------------------------------------
209 frame->p_Splitter = new DocSplitterWindow(frame,-1);
b5ffecfc
GT
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())
216 frame->Close(TRUE);
b5ffecfc
GT
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 //----------------------------------------------------------------------------
226 //-- Help : ---
227 //----------------------------------------------------------------------------
c92b0f9a
MJ
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
b5ffecfc
GT
232 //---------------------------------------------------------------------------------------
233 // Show the frame
234 frame->Show(TRUE);
235 SetTopWindow(frame);
c92b0f9a
MJ
236 //---------------------------------------------------------------------------------------
237 p_ProgramCfg->Flush(TRUE); // sicher Objekt
b5ffecfc 238 return TRUE;
c92b0f9a
MJ
239} // bool MainApp::OnInit(void)
240//----------------------------------------------------------------------------------------
b5ffecfc 241// My frame constructor
c92b0f9a
MJ
242//----------------------------------------------------------------------------------------
243MainFrame::MainFrame(wxFrame *frame, char *title, const wxPoint& pos, const wxSize& size):
244 wxFrame(frame, -1, title, pos, size)
b5ffecfc 245{
c92b0f9a 246 //--- Everything is done in MainApp -----------------------------------------------------
b5ffecfc 247}
c92b0f9a 248//----------------------------------------------------------------------------------------
b5ffecfc
GT
249MainFrame::~MainFrame(void)
250{
251 // save the control's values to the config
252 if ( p_ProgramCfg == NULL )
253 return;
254 // save the frame position
255 int x, y, w, h;
256 GetPosition(&x, &y);
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
265 // we want here!)
266 // delete wxConfigBase::Set((wxConfigBase *) NULL);
c92b0f9a
MJ
267 p_ProgramCfg->Flush(TRUE); // saves Objekt
268 delete frame->pDoc; // Cleanup
b5ffecfc 269}
c92b0f9a 270//----------------------------------------------------------------------------------------
b5ffecfc
GT
271void MainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
272{
c92b0f9a
MJ
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);
b5ffecfc
GT
276 Close(TRUE);
277}
c92b0f9a 278//----------------------------------------------------------------------------------------
b5ffecfc
GT
279void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
280{
281 wxMessageDialog dialog(this, _("DBBrowser\nMark Johnson\nBerlin, Germany\nmj10777@gmx.net\n (c) 1999"),
282 _("About DBBrowser"), wxOK|wxCANCEL);
283
284 dialog.ShowModal();
285}
c92b0f9a 286//----------------------------------------------------------------------------------------
b5ffecfc
GT
287void MainFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
288{
c92b0f9a 289 p_Help->Display("Main page");
b5ffecfc 290}
c92b0f9a 291//----------------------------------------------------------------------------------------