File: doc.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 (333 lines) | stat: -rw-r--r-- 14,725 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
329
330
331
332
333
//----------------------------------------------------------------------------------------
// Name:        doc.cpp
// Purpose:     Holds information for DBBrowser - (a do-it-yourself document)
// Author:      Mark Johnson
// Modified by: 19990808.mj10777
// BJO        : Bart A.M. JOURQUIN
// Created:     19990808
// Copyright:   (c) Mark Johnson
// Licence:     wxWindows license
// RCS-ID:      $Id: doc.cpp,v 1.27 2005/03/07 22:17:01 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
//----------------------------------------------------------------------------------------
//-- all #includes that every .cpp needs             ----19990807.mj10777 ----------------
//----------------------------------------------------------------------------------------
#include "std.h"       // sorgsam Pflegen !
//----------------------------------------------------------------------------------------
//-- Some Global Vars for all Files (extern in ?.h needed) -------------------------------
// Global structure for holding ODBC connection information
extern wxDbConnectInf DbConnectInf;

//----------------------------------------------------------------------------------------
wxConfigBase   *p_ProgramCfg;       // All Config and Path information
wxLogTextCtrl  *p_LogBook;          // All Log messages
wxString        LogBuf;             // String for all Logs

//----------------------------------------------------------------------------------------
MainDoc::MainDoc()
{
    db_Br          = NULL;
    p_DSN          = NULL;
    i_DSN          = 0;
    p_Splitter     = NULL;
    p_MainFrame    = NULL;
    p_PgmCtrl      = NULL;               // Is not active
    p_DBTree       = NULL;
    p_DBGrid       = NULL;
    p_LogWin       = NULL;
    p_TabArea      = NULL;
    p_PageArea     = NULL;
    i_TabNr        = 0;
    i_PageNr       = 0;
    s_BColour      = _T("WHEAT");
    ft_Doc         = new wxFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT));
}

//----------------------------------------------------------------------------------------
MainDoc::~MainDoc()
{
    p_TabArea->Show(false);    // Deactivate the Window
    p_PageArea->Show(false);    // Deactivate the Window

    // ----------------------------------------------------------
    // -E-> The Tree Controls take to long to close : Why ??
    // ----------------------------------------------------------
    delete ft_Doc;     ft_Doc  = NULL;
    delete p_PgmCtrl;  p_PgmCtrl = NULL;
    delete [] p_DSN;
    delete p_DBTree;
    delete p_TabArea;  p_TabArea  = NULL;
    delete p_PageArea; p_PageArea = NULL;
    delete p_Splitter; p_Splitter = NULL;
    delete [] db_Br;   db_Br      = NULL;
    //  wxMessageBox("~MainDoc");
}

//----------------------------------------------------------------------------------------
bool MainDoc::OnNewDocument()
{
    wxStopWatch sw;
    //---------------------------------------------------------------------------------------
    if (!OnInitView())
        return false;
    p_PgmCtrl->OnPopulate();
    //---------------------------------------------------------------------------------------
    wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw.Time());
    return true;
}

//----------------------------------------------------------------------------------------
bool MainDoc::OnInitView()
{
    Sash = p_ProgramCfg->Read(_T("/MainFrame/Sash"), 200);
    // wxMessageBox("OnInitView() - Begin ","-I->MainDoc::OnInitView");
    //---------------------------------------------------------------------------------------
    // create "workplace" window
    //---------------------------------------------------------------------------------------
    p_TabArea = new wxTabbedWindow(); // Init the Pointer
    p_TabArea->Create(p_Splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE);
    //---------------------------------------------------------------------------------------
    p_PgmCtrl = new PgmCtrl(p_TabArea, TREE_CTRL_PGM,wxDefaultPosition, wxDefaultSize,
        wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
    p_PgmCtrl->i_TabArt = 0; // 0 = Tab ; 1 = Page
    p_PgmCtrl->i_ViewNr = p_TabArea->GetTabCount()-1;
    //---------------------------------------------------------------------------------------
    wxBitmap *p_FolderClose = new wxBitmap(_T("PgmCtrl")); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115
    //---------------------------------------------------------------------------------------
    p_TabArea->AddTab(p_PgmCtrl,_T("PgmCtrl"),p_FolderClose);
    delete p_FolderClose;      // Memory leak
    p_FolderClose = NULL;
    wxUnusedVar(p_FolderClose);
    //---------------------------------------------------------------------------------------
    // now create "output" window
    //---------------------------------------------------------------------------------------
    p_PageArea = new wxPagedWindow();  // Init the Pointer
    p_PageArea->Create(p_Splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE);
    //---------------------------------------------------------------------------------------
    p_LogWin = new wxTextCtrl(p_PageArea,wxID_ANY,wxEmptyString,
        wxDefaultPosition, wxDefaultSize,wxTE_MULTILINE );
    p_LogWin->SetFont(* ft_Doc);
    // Don't forget ! This is always : i_TabArt = 0 ; i_ViewNr = 1;
    //---------------------------------------------------------------------------------------
    p_LogBook = new wxLogTextCtrl(p_LogWin); // make p_LogWin the LogBook
    p_LogBook->SetActiveTarget(p_LogBook);
    p_LogBook->SetTimestamp( NULL );
    //---------------------------------------------------------------------------------------
    p_PageArea->AddTab(p_LogWin,_("LogBook"), _T("what is this?") );
    i_TabNr  = p_TabArea->GetTabCount()-1;  // Add one when a new AddTab is done;
    i_PageNr = p_PageArea->GetTabCount()-1; // Add one when a new AddTab is done;
    //---------------------------------------------------------------------------------------
    p_PgmCtrl->pDoc = this;
    p_TabArea->SetActiveTab(i_PageNr);
    //---------------------------------------------------------------------------------------
    p_Splitter->Initialize(p_TabArea);
    p_Splitter->SplitHorizontally(p_TabArea,p_PageArea,Sash);
    //---------------------------------------------------------------------------------------
    // if (!OnInitODBC())
    //  return false;
    OnInitODBC();
    //---------------------------------------------------------------------------------------
#if wxUSE_STATUSBAR
    Temp0.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN);
    p_MainFrame->SetStatusText(Temp0, 0);
    wxLogMessage(Temp0);
#endif // wxUSE_STATUSBAR
    return true;
}

//----------------------------------------------------------------------------------------
bool MainDoc::OnInitODBC()
{
    wxChar Dsn[SQL_MAX_DSN_LENGTH+1];
    wxChar DsDesc[254+1]; // BJO20002501 instead of 512
    Temp0 = wxEmptyString;
    i_DSN = 0;       // Counter
    int i;
    //---------------------------------------------------------------------------------------
    // Initialize the ODBC Environment for Database Operations

    if (!DbConnectInf.AllocHenv())
    {
        return false;
    }

    //---------------------------------------------------------------------------------------
    const wxChar sep = 3; // separator character used in string between DSN and DsDesc
    wxSortedArrayString s_SortDSNList, s_SortDsDescList;
    // BJO-20000127
    // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string.
    // The key will be removed after sorting
    wxString KeyString;
    //---------------------------------------------------------------------------------------
    while (wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, SQL_MAX_DSN_LENGTH, DsDesc, 254))
    {
        i_DSN++;   // How many Dsn have we ?
        KeyString.Printf(_T("%s%c%s"),Dsn, sep, DsDesc);
        s_SortDSNList.Add(Dsn);
        s_SortDsDescList.Add(KeyString);
    }

    //---------------------------------------------------------------------------------------
    // Allocate n ODBC-DSN objects to hold the information
    // Allocate n wxDatabase objects to hold the column information
    p_DSN = new DSN[i_DSN];  //BJO
    db_Br = new BrowserDB[i_DSN];
    for (i=0;i<i_DSN;i++)
    {
        KeyString = s_SortDsDescList[i];
        KeyString = KeyString.AfterFirst(sep);

        // ODBC-DSN object
        (p_DSN+i)->Dsn = s_SortDSNList[i];
        (p_DSN+i)->Drv = KeyString;
        (p_DSN+i)->Usr = wxEmptyString;
        (p_DSN+i)->Pas = wxEmptyString;
        Temp0.Printf(_T("%02d) Dsn(%s) DsDesc(%s)"),i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str());
        wxLogMessage(Temp0);

        // wxDataBase object
        (db_Br+i)->p_LogWindow = p_LogWin;
        (db_Br+i)->ODBCSource  = (p_DSN+i)->Dsn;
        (db_Br+i)->UserName    = (p_DSN+i)->Usr;
        (db_Br+i)->Password    = (p_DSN+i)->Pas;
        (db_Br+i)->pDoc        = this;
        (db_Br+i)->i_Which     = i;
    }

    DbConnectInf.FreeHenv();

    //---------------------------------------------------------------------------------------
    if (!i_DSN)
    {
        wxString message = _("No Dataset names found in ODBC!\n");
        message += _("           Program will exit!\n\n");
        message += _("                       Ciao");
        wxMessageBox( message,_("-E-> Fatal situation"));
        return false;
    }
    //---------------------------------------------------------------------------------------
    return true;
}

//----------------------------------------------------------------------------------------
bool MainDoc::OnChosenDSN(int Which)
{
    // wxLogMessage("OnChosenDSN(%d) - Begin",Which);
    //---------------------------------------------------------------------------------------
    if (p_DBTree != NULL)
    {
        p_TabArea->Show(false);    // Deactivate the Window
        p_TabArea->RemoveTab(p_DBTree->i_ViewNr);
        p_TabArea->Show(true);     // Activate the Window
        OnChosenTbl(77,wxEmptyString);
    }
    //-------------------------
    p_TabArea->Show(false);    // Deactivate the Window
    p_DBTree = new DBTree(p_TabArea, TREE_CTRL_DB,wxDefaultPosition, wxDefaultSize,
        wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
    p_TabArea->AddTab(p_DBTree,(p_DSN+Which)->Dsn,_T(" ? "));
    p_DBTree->i_ViewNr = p_TabArea->GetTabCount()-1;
    p_TabArea->Show(true);    // Deactivate the Window
    p_DBTree->i_Which  = Which;
    p_DBTree->s_DSN    = (p_DSN+Which)->Dsn;
    p_DBTree->i_TabArt = 0;
    p_DBTree->pDoc     = this;
    p_DBTree->OnPopulate();
    p_TabArea->SetActiveTab(p_DBTree->i_ViewNr);
    //---------------------------------------------------------------------------------------
    // wxLogMessage("OnChosenDSN(%d) - End",Which);
    return true;
}

//----------------------------------------------------------------------------------------
bool MainDoc::OnChosenTbl(int Tab,wxString Table)
{
    // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str());
    //-------------------------
    if (p_DBGrid != NULL)
    {
        if (p_DBGrid->i_TabArt == 0)
        {
            p_TabArea->Show(false);    // Deactivate the Window
            p_TabArea->RemoveTab(p_DBGrid->i_ViewNr);
            p_TabArea->Show(true);     // Activate the Window
        }
        if (p_DBGrid->i_TabArt == 1)
        {
            p_PageArea->Show(false);   // Deactivate the Window
            p_PageArea->RemoveTab(p_DBGrid->i_ViewNr);
            p_PageArea->Show(true);    // Activate the Window
        }
        p_DBGrid = NULL;
        delete p_DBGrid;
    }
    if (Tab == 77)               // Delete only
        return true;
    //-------------------------
    if (Tab == 0)  // Tabview
    {
        p_TabArea->Show(false);    // Deactivate the Window
        p_DBGrid = new DBGrid(p_TabArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
            wxSUNKEN_BORDER);
        p_TabArea->AddTab(p_DBGrid, Table, wxEmptyString);
        p_DBGrid->i_ViewNr = p_TabArea->GetTabCount()-1;
        p_DBGrid->pDoc       = this;
        p_DBGrid->db_Br      = db_Br;
        p_DBGrid->OnTableView(Table);
        p_TabArea->SetActiveTab(p_DBGrid->i_ViewNr);
        p_TabArea->Show(true);     // Activate the Window
    }
    if (Tab == 1)  // Pageview
    {
        p_PageArea->Show(false);   // Deactivate the Window
        p_DBGrid = new DBGrid(p_PageArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
            wxSUNKEN_BORDER);
        p_PageArea->AddTab(p_DBGrid, Table, wxEmptyString);
        p_DBGrid->i_ViewNr = p_PageArea->GetTabCount()-1;
        p_DBGrid->pDoc       = this;
        p_DBGrid->db_Br      = db_Br;
        p_DBGrid->i_Which    = p_DBTree->i_Which;
        p_PageArea->Show(true);    // Activate the Window
        p_DBGrid->OnTableView(Table);
        p_PageArea->SetActiveTab(p_DBGrid->i_ViewNr);
    }
    p_DBGrid->i_TabArt = Tab;
    //--------------------------
    return true;
}

//----------------------------------------------------------------------------------------
void MainDoc::OnLeer(wxString Aufrufer)
{
    // Temp0.Printf(_("\nMainDoc::OnLeer(%s) : auch diese funktion steht eines Tages zur Verfgung !"),Aufrufer.c_str());
    Temp0.Printf(_("\nMainDoc::OnLeer(%s) : even this function will one day be available !"),Aufrufer.c_str());
    wxLogMessage(Temp0);  Temp0.Empty();
    return;
}

//----------------------------------------------------------------------------------------
BEGIN_EVENT_TABLE(DocSplitterWindow, wxSplitterWindow)
END_EVENT_TABLE()

//----------------------------------------------------------------------------------------
DocSplitterWindow::DocSplitterWindow(wxWindow *parent, wxWindowID id) : wxSplitterWindow(parent, id)
{ // Define a constructor for my p_Splitter
}
//----------------------------------------------------------------------------------------