File: dbbrowse.cpp

package info (click to toggle)
wxwidgets2.6 2.6.3.2.1.5%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 83,228 kB
  • ctags: 130,941
  • sloc: cpp: 820,043; ansic: 113,030; python: 107,485; makefile: 42,996; sh: 10,305; lex: 194; yacc: 128; xml: 95; pascal: 74
file content (328 lines) | stat: -rw-r--r-- 18,373 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
//----------------------------------------------------------------------------------------
// Name:        dbbrowse.cpp
// Purpose:     Through ODBC - Databases Browsen
// Author:      Mark Johnson
// Modified by:
// BJO        : Bart A.M. JOURQUIN
// Created:     19991127
// Copyright:   (c) Mark Johnson
// Licence:     wxWindows license
// RCS-ID:      $Id: dbbrowse.cpp,v 1.21 2005/05/31 09:17:53 JS Exp $
//----------------------------------------------------------------------------------------
//-- all #ifdefs that the whole Project needs. -------------------------------------------
//----------------------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
//----------------------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
//----------------------------------------------------------------------------------------
#ifdef __BORLANDC__
#pragma hdrstop
#endif
//----------------------------------------------------------------------------------------
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "wx/stockitem.h"
//----------------------------------------------------------------------------------------
#ifndef __WXMSW__
#include "bitmaps/logo.xpm"
#endif
//----------------------------------------------------------------------------------------
//-- all #includes that every .cpp needs             --- 19990807.mj10777 ----------------
//----------------------------------------------------------------------------------------
#include "std.h"    // sorgsam Pflegen !
// #include <iostream>
//----------------------------------------------------------------------------------------
//-- Some Global Vars for this file ------------------------------------------------------
//----------------------------------------------------------------------------------------
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
    EVT_MENU(wxID_EXIT, MainFrame::OnQuit)                  // Program End
    EVT_MENU(wxID_ABOUT, MainFrame::OnAbout)                // Program Discription
    EVT_MENU(wxID_HELP, MainFrame::OnHelp)                  // Program Help
END_EVENT_TABLE()

//----------------------------------------------------------------------------------------
IMPLEMENT_APP(MainApp)      // This declares wxApp::MainApp as "the" Application

//----------------------------------------------------------------------------------------
// 'Main program' equivalent, creating windows and returning main app frame
//----------------------------------------------------------------------------------------
bool MainApp::OnInit(void)  // Does everything needed for a program start
{
    wxString Temp0;            // Use as needed
    //---------------------------------------------------------------------------------------
    // set the language to use   // Help.??  (.std = english, .de = german etc.)
    const wxChar *language = NULL; // czech, german, french, polish
    const wxChar *langid   = NULL; // std = english , cz, de = german, fr = french, pl = polish
    wxString   s_LangHelp;       // Directory/Filename.hhp of the Help-Project file
    wxString   s_LangId, s_Language;
    s_Language.Empty(); s_LangId.Empty(); s_LangHelp.Empty();
    //---------------------------------------------------------------------------------------
    //-- Graphic File suport - use only when needed, otherwise big .exe's
    //---------------------------------------------------------------------------------------
#if wxUSE_LIBPNG
    wxImage::AddHandler( new wxPNGHandler );   // needed for help System
#endif
/*
    #if wxUSE_LIBJPEG
    wxImage::AddHandler(new wxJPEGHandler );   // use only when needed, otherwise big .exe's
    #endif
    wxImage::AddHandler( new wxGIFHandler );   // use only when needed, otherwise big .exe's
    wxImage::AddHandler( new wxPCXHandler );   // use only when needed, otherwise big .exe's
    wxImage::AddHandler( new wxPNMHandler );   // use only when needed, otherwise big .exe's
*/
#ifdef __WXMSW__
    // wxBitmap::AddHandler( new wxXPMFileHandler );   // Attempt to use XPS instead of ico
    // wxBitmap::AddHandler( new wxXPMDataHandler );   // - Attempt failed
#endif
    //---------------------------------------------------------------------------------------
    switch ( argc )
    {
    default:
        // ignore the other args, fall through
    case 3:
        language = argv[2];         // czech, english, french, german , polish
        langid   = argv[1];         // cz, std, fr, de , pl
        break;
    case 2:
        langid   = argv[1];         // cz, std, fr, de , pl
        break;
    case 1:
    case 0:
        break;
    };
    //---------------------------------------------------------------------------------------
    // Win-Registry : Workplace\HKEY_CURRENT_USERS\Software\%GetVendorName()\%GetAppName()
    //---------------------------------------------------------------------------------------
    SetVendorName(_T("mj10777"));           // Needed to get Configuration Information
    SetAppName(_T("DBBrowse"));             // "" , also needed for s_LangHelp
    //---------------------------------------------------------------------------------------
    // we're using wxConfig's "create-on-demand" feature: it will create the
    // config object when it's used for the first time. It has a number of
    // advantages compared with explicitly creating our wxConfig:
    //  1) we don't pay for it if we don't use it
    //  2) there is no danger to create it twice

    // application and vendor name are used by wxConfig to construct the name
    // of the config file/registry key and must be set before the first call
    // to Get() if you want to override the default values (the application
    // name is the name of the executable and the vendor name is the same)
    //---------------------------------------------------------------------------------------
    p_ProgramCfg = wxConfigBase::Get();  // Get Program Configuration from Registry
    // p_ProgramCfg->DeleteAll();           // This is how the Config can be erased
    p_ProgramCfg->SetPath(_T("/"));          // Start at root
    //---------------------------------------------------------------------------------------
    //-- Set the Language and remember it for the next time. --------------------------------
    //---------------------------------------------------------------------------------------
    if (langid == NULL) // No Parameter was given
    {
        Temp0.Empty();
        p_ProgramCfg->Read(_T("/Local/langid"),&Temp0); // >const char *langid< can't be used here
        if (Temp0.empty())
            langid = _T("std");  // Standard language is "std" = english
        else
            langid = Temp0;
    }
    Temp0.Printf(_T("%s"),langid);
    //---------------------------------------------------------------------------------------
    // Support the following languages  (std = english)
    if ((Temp0 == _T("a"))  || (Temp0 == _T("cz")) || (Temp0 == _T("de")) ||
        (Temp0 == _T("fr")) || (Temp0 == _T("pl")))
    { // The three-letter language-string codes are only valid in Windows NT and Windows 95.
        if (Temp0 == _T("cz"))
            language = _T("czech");  // csy or czech
        if ((Temp0 == _T("de")) || (Temp0 == _T("a")))
        {
            language = _T("german");  // deu or german
            if (Temp0 == _T("a"))
            { langid = Temp0 = _T("de"); }  // Austrian = german
        } // german / austrian
        if (Temp0 == _T("fr"))
            language = _T("french");  // fra or french
        if (Temp0 == _T("pl"))
            language = _T("polish");  // plk or polish
        if (!m_locale.Init(language, langid, language)) // Don't do this for english (std)
        { // You should recieve errors here for cz and pl since there is no cz/ and pl/ directory
            wxLogMessage(_T("-E-> %s : SetLocale error : langid(%s) ; language(%s)"),GetAppName().c_str(),langid,language);
            langid = _T("std");
            language = _T("C");  // english, english-aus , -can , -nz , -uk , -usa
        }
        else
        { // Read in Foreign language's text for GetAppName() and Help
            Temp0 = GetAppName();
            Temp0 = Temp0.Lower();
            m_locale.AddCatalog(Temp0.c_str());
            m_locale.AddCatalog(_T("help"));
        }
    } // Support the following languages  (std = english)
    else
    {
        langid = _T("std");
        language = _T("C");  // english, english-aus , -can , -nz , -uk , -usa
    }
    s_Language.Printf(_T("%s"),language);                       // language is a pointer
    s_LangId.Printf(_T("%s"),langid);                           // langid   is a pointer
    p_ProgramCfg->Write(_T("/Local/language"),s_Language);
    p_ProgramCfg->Write(_T("/Local/langid"),s_LangId);
    s_LangHelp.Printf(_T("help.%s/%s.hhp"),s_LangId.c_str(),GetAppName().c_str()); // "help.std/Garantie.hhp";
    s_LangHelp = s_LangHelp.Lower();                       // A must for Linux
    //---------------------------------------------------------------------------------------
    Temp0 = _T("NONE");                               // I don't remember why I did this
    p_ProgramCfg->Write(_T("/NONE"),Temp0);           // I don't remember why I did this
    p_ProgramCfg->Write(_T("/Paths/NONE"),Temp0);     // I don't remember why I did this
    p_ProgramCfg->Write(_T("/MainFrame/NONE"),Temp0); // I don't remember why I did this
    //---------------------------------------------------------------------------------------
    p_ProgramCfg->Write(_T("/Paths/Work"),wxGetCwd()); // Get current Working Path
    p_ProgramCfg->SetPath(_T("/"));
    //---------------------------------------------------------------------------------------
    // restore frame position and size, if empty start Values (1,1) and (750,600)
    int x = p_ProgramCfg->Read(_T("/MainFrame/x"), 1), y = p_ProgramCfg->Read(_T("/MainFrame/y"), 1),
        w = p_ProgramCfg->Read(_T("/MainFrame/w"), 750), h = p_ProgramCfg->Read(_T("/MainFrame/h"), 600);
    //---------------------------------------------------------------------------------------
    // Create the main frame window
    Temp0.Printf(_T("%s - %s"),GetAppName().c_str(),GetVendorName().c_str());
    frame = new MainFrame((wxFrame *) NULL,(wxChar *) Temp0.c_str(),wxPoint(x,y),wxSize(w,h));
    //---------------------------------------------------------------------------------------
    // Set the Backgroundcolour (only needed if you are NOT using wxSYS_COLOUR_BACKGROUND)
    frame->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND));
    // frame->SetBackgroundColour(wxColour(255, 255, 255));
    // frame->SetBackgroundColour(* wxWHITE);
    //---------------------------------------------------------------------------------------
    // Give it an icon
    //---------------------------------------------------------------------------------------
    // 12.02.2000 - Guillermo Rodriguez Garcia :
    //---------------------------------------------------------------------------------------
    // This is different for Win9x and WinNT; one of them takes the first ico
    // in the .rc file, while the other takes the icon with the lowest name,
    // so to be sure that it always work, put your icon the first *and* give
    // it a name such a 'appicon' or something.
    //---------------------------------------------------------------------------------------
    // mj10777 : any special rule in Linux ?
    //---------------------------------------------------------------------------------------
    frame->SetIcon(wxICON(aLogo));    // lowest name and first entry in RC File
    //---------------------------------------------------------------------------------------
    // Make a menubar
    wxMenu *file_menu = new wxMenu;
    wxMenu *help_menu = new wxMenu;

    help_menu->Append(wxID_HELP, wxGetStockLabel(wxID_HELP));
    help_menu->AppendSeparator();
    help_menu->Append(wxID_ABOUT, _("&About"));
    file_menu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT));

    wxMenuBar *menu_bar = new wxMenuBar;
    menu_bar->Append(file_menu, _("&File"));
    menu_bar->Append(help_menu, _("&Help"));
    frame->SetMenuBar(menu_bar);
#if wxUSE_STATUSBAR
    frame->CreateStatusBar(1);
    Temp0.Printf(_("%s has started !"),p_ProgramCfg->GetAppName().c_str());
    frame->SetStatusText(Temp0, 0);
#endif // wxUSE_STATUSBAR
    //---------------------------------------------------------------------------------------
    int width, height;
    frame->GetClientSize(&width, &height);
    //---------------------------------------------------------------------------------------
    frame->p_Splitter = new DocSplitterWindow(frame,wxID_ANY);
    // p_Splitter->SetCursor(wxCursor(wxCURSOR_PENCIL));
    frame->pDoc                       = new MainDoc();
    frame->pDoc->p_MainFrame          = frame;
    frame->pDoc->p_Splitter           = frame->p_Splitter;
    frame->pDoc->p_Splitter->pDoc     = frame->pDoc;       // ControlBase: saving the Sash
    //---------------------------------------------------------------------------------------
    //-- Problem : GetClientSize(Width,Height) are not the same as the values given in the ---
    //--            construction of the Frame.                                            ---
    //-- Solved  : GetClientSize is called here and the difference is noted. When the     ---
    //--           Window is closed the diff. is added to the result of GetClientSize.    ---
    //---------------------------------------------------------------------------------------
    frame->GetClientSize(&frame->DiffW, &frame->DiffH); frame->DiffW-=w; frame->DiffH-=h;
    //----------------------------------------------------------------------------
    //-- Help    : Load the help.%langid/%GetAppName().hhp (help.std/dbbrowse.hhp) file                                                                       ---
    //----------------------------------------------------------------------------
    frame->p_Help = new wxHtmlHelpController();   // construct the Help System
    frame->p_Help->UseConfig(p_ProgramCfg);       // Don't rember what this was for
    // You should recieve errors here for fr since there is no help.fr/ directory
    if (!frame->p_Help->AddBook(s_LangHelp))      // Use the language set
    { // You should recieve errors here for fr since there is no help.fr/ but a fr/ directory
        wxLogMessage(_T("-E-> %s : AddBook error : s_LangHelp(%s)"),GetAppName().c_str(),s_LangHelp.c_str());
    }
    frame->pDoc->p_Help = frame->p_Help;          // Save the information to the document
    //---------------------------------------------------------------------------------------
    frame->Show(true);                            // Show the frame
    SetTopWindow(frame);                          // At this point the frame can be seen
    //---------------------------------------------------------------------------------------
    // If you need a "Splash Screen" because of a long OnNewDocument, do it here
    if (!frame->pDoc->OnNewDocument())
        frame->Close(true);
    // Kill a "Splash Screen" because OnNewDocument, if you have one
    //---------------------------------------------------------------------------------------
    p_ProgramCfg->Flush(true);        // save the configuration
    return true;
} // bool MainApp::OnInit(void)

//----------------------------------------------------------------------------------------
// My frame constructor
//----------------------------------------------------------------------------------------
MainFrame::MainFrame(wxFrame *frame, wxChar *title,  const wxPoint& pos, const wxSize& size):
wxFrame(frame, wxID_ANY, title,  pos, size)
{
    p_Splitter = NULL; pDoc = NULL; p_Help = NULL;    // Keep the Pointers clean !
    //--- Everything else is done in MainApp::OnInit() --------------------------------------
}

//----------------------------------------------------------------------------------------
MainFrame::~MainFrame(void)
{
    // Close the help frame; this will cause the config data to get written.
    if (p_Help->GetFrame()) // returns NULL if no help frame active
        p_Help->GetFrame()->Close(true);
    delete p_Help;  // Memory Leak
    p_Help = NULL;
    // save the control's values to the config
    if (p_ProgramCfg == NULL)
        return;
    // save the frame position before it is destroyed
    int x, y, w, h;
    GetPosition(&x, &y);
    GetClientSize(&w, &h); w -= DiffW; h -= DiffH;
    p_ProgramCfg->Write(_T("/MainFrame/x"), (long) x);
    p_ProgramCfg->Write(_T("/MainFrame/y"), (long) y);
    p_ProgramCfg->Write(_T("/MainFrame/w"), (long) w);
    p_ProgramCfg->Write(_T("/MainFrame/h"), (long) h);
    p_ProgramCfg->Write(_T("/MainFrame/Sash"), (long) pDoc->Sash);
    // clean up: Set() returns the active config object as Get() does, but unlike
    // Get() it doesn't try to create one if there is none (definitely not what
    // we want here!)
    // delete wxConfigBase::Set((wxConfigBase *) NULL);
    p_ProgramCfg->Flush(true);        // saves   Objekt
    if (pDoc)                         // If we have a Valid Document
        delete pDoc;                     // Cleanup (MainDoc::~MainDoc)
} // MainFrame::~MainFrame(void)

//----------------------------------------------------------------------------------------
void MainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    Close(true);
}

//----------------------------------------------------------------------------------------
void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
    wxString Temp0, Temp1;
    Temp0.Printf(_("%s\nMark Johnson\nBerlin, Germany\nwxWindows@mj10777.de\n (c) 2000"),p_ProgramCfg->GetAppName().c_str());
    Temp1.Printf(_("About %s"),p_ProgramCfg->GetAppName().c_str());
    wxMessageDialog dialog(this, Temp0,Temp1,wxOK|wxCANCEL);
    dialog.ShowModal();
}

//----------------------------------------------------------------------------------------
void MainFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
{
    p_Help->Display(_T("Main page"));
}
//----------------------------------------------------------------------------------------