]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/doc.cpp
Enhanced stock labels usage. Source cleaning.
[wxWidgets.git] / demos / dbbrowse / doc.cpp
Content-type: text/html ]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/doc.cpp


500 - Internal Server Error

Malformed UTF-8 character (fatal) at /usr/lib/x86_64-linux-gnu/perl5/5.40/HTML/Entities.pm line 485, <$fd> line 813.
CommitLineData
c92b0f9a 1//----------------------------------------------------------------------------------------
645889ad 2// Name: doc.cpp
c92b0f9a 3// Purpose: Holds information for DBBrowser - (a do-it-yourself document)
829c421b 4// Author: Mark Johnson
b5ffecfc
GT
5// Modified by: 19990808.mj10777
6// BJO : Bart A.M. JOURQUIN
7// Created: 19990808
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 14#ifdef __GNUG__
b5ce269b
BJ
15#pragma implementation
16#pragma interface
b5ffecfc 17#endif
c92b0f9a 18//----------------------------------------------------------------------------------------
b5ffecfc
GT
19// For compilers that support precompilation, includes "wx/wx.h".
20#include "wx/wxprec.h"
c92b0f9a 21//----------------------------------------------------------------------------------------
b5ffecfc 22#ifdef __BORLANDC__
b5ce269b 23#pragma hdrstop
b5ffecfc 24#endif
c92b0f9a 25//----------------------------------------------------------------------------------------
b5ffecfc 26#ifndef WX_PRECOMP
b5ce269b 27#include "wx/wx.h"
b5ffecfc 28#endif
c92b0f9a
MJ
29//----------------------------------------------------------------------------------------
30//-- all #includes that every .cpp needs ----19990807.mj10777 ----------------
31//----------------------------------------------------------------------------------------
b5ffecfc 32#include "std.h" // sorgsam Pflegen !
c92b0f9a
MJ
33//----------------------------------------------------------------------------------------
34//-- Some Global Vars for all Files (extern in ?.h needed) -------------------------------
b5ffecfc 35// Global structure for holding ODBC connection information
eacf9d88 36extern wxDbConnectInf DbConnectInf;
645889ad 37
c92b0f9a 38//----------------------------------------------------------------------------------------
b5ffecfc
GT
39wxConfigBase *p_ProgramCfg; // All Config and Path information
40wxLogTextCtrl *p_LogBook; // All Log messages
41wxString LogBuf; // String for all Logs
645889ad 42
c92b0f9a 43//----------------------------------------------------------------------------------------
3fa0976a 44MainDoc::MainDoc()
b5ffecfc 45{
645889ad
GT
46 db_Br = NULL;
47 p_DSN = NULL;
48 i_DSN = 0;
49 p_Splitter = NULL;
50 p_MainFrame = NULL;
51 p_PgmCtrl = NULL; // Is not active
52 p_DBTree = NULL;
53 p_DBGrid = NULL;
54 p_LogWin = NULL;
55 p_TabArea = NULL;
56 p_PageArea = NULL;
57 i_TabNr = 0;
58 i_PageNr = 0;
daf06bb8 59 s_BColour = _T("WHEAT");
e1c6c6ae 60 ft_Doc = new wxFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT));
b5ffecfc 61}
645889ad 62
c92b0f9a 63//----------------------------------------------------------------------------------------
3fa0976a 64MainDoc::~MainDoc()
b5ffecfc 65{
5151c7af
WS
66 p_TabArea->Show(false); // Deactivate the Window
67 p_PageArea->Show(false); // Deactivate the Window
645889ad
GT
68
69 // ----------------------------------------------------------
70 // -E-> The Tree Controls take to long to close : Why ??
71 // ----------------------------------------------------------
72 delete ft_Doc; ft_Doc = NULL;
73 delete p_PgmCtrl; p_PgmCtrl = NULL;
74 delete [] p_DSN;
75 delete p_DBTree;
76 delete p_TabArea; p_TabArea = NULL;
77 delete p_PageArea; p_PageArea = NULL;
78 delete p_Splitter; p_Splitter = NULL;
79 delete [] db_Br; db_Br = NULL;
80 // wxMessageBox("~MainDoc");
b5ffecfc 81}
645889ad 82
c92b0f9a 83//----------------------------------------------------------------------------------------
3fa0976a 84bool MainDoc::OnNewDocument()
b5ffecfc 85{
645889ad
GT
86 wxStopWatch sw;
87 //---------------------------------------------------------------------------------------
88 if (!OnInitView())
5151c7af 89 return false;
645889ad
GT
90 p_PgmCtrl->OnPopulate();
91 //---------------------------------------------------------------------------------------
92 wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw.Time());
5151c7af 93 return true;
b5ffecfc 94}
645889ad 95
c92b0f9a 96//----------------------------------------------------------------------------------------
3fa0976a 97bool MainDoc::OnInitView()
b5ffecfc 98{
daf06bb8 99 Sash = p_ProgramCfg->Read(_T("/MainFrame/Sash"), 200);
645889ad
GT
100 // wxMessageBox("OnInitView() - Begin ","-I->MainDoc::OnInitView");
101 //---------------------------------------------------------------------------------------
102 // create "workplace" window
103 //---------------------------------------------------------------------------------------
104 p_TabArea = new wxTabbedWindow(); // Init the Pointer
5151c7af 105 p_TabArea->Create(p_Splitter, wxID_ANY);
645889ad
GT
106 //---------------------------------------------------------------------------------------
107 p_PgmCtrl = new PgmCtrl(p_TabArea, TREE_CTRL_PGM,wxDefaultPosition, wxDefaultSize,
108 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
109 p_PgmCtrl->i_TabArt = 0; // 0 = Tab ; 1 = Page
110 p_PgmCtrl->i_ViewNr = p_TabArea->GetTabCount()-1;
111 //---------------------------------------------------------------------------------------
daf06bb8 112 wxBitmap *p_FolderClose = new wxBitmap(_T("PgmCtrl")); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115
645889ad 113 //---------------------------------------------------------------------------------------
daf06bb8 114 p_TabArea->AddTab(p_PgmCtrl,_T("PgmCtrl"),p_FolderClose);
645889ad
GT
115 delete p_FolderClose; // Memory leak
116 p_FolderClose = NULL;
74de91cc 117 wxUnusedVar(p_FolderClose);
645889ad
GT
118 //---------------------------------------------------------------------------------------
119 // now create "output" window
120 //---------------------------------------------------------------------------------------
121 p_PageArea = new wxPagedWindow(); // Init the Pointer
5151c7af 122 p_PageArea->Create(p_Splitter, wxID_ANY);
645889ad 123 //---------------------------------------------------------------------------------------
5151c7af 124 p_LogWin = new wxTextCtrl(p_PageArea,wxID_ANY,wxEmptyString,
645889ad
GT
125 wxDefaultPosition, wxDefaultSize,wxTE_MULTILINE );
126 p_LogWin->SetFont(* ft_Doc);
127 // Don't forget ! This is always : i_TabArt = 0 ; i_ViewNr = 1;
128 //---------------------------------------------------------------------------------------
129 p_LogBook = new wxLogTextCtrl(p_LogWin); // make p_LogWin the LogBook
130 p_LogBook->SetActiveTarget(p_LogBook);
131 p_LogBook->SetTimestamp( NULL );
132 //---------------------------------------------------------------------------------------
daf06bb8 133 p_PageArea->AddTab(p_LogWin,_("LogBook"), _T("what is this?") );
645889ad
GT
134 i_TabNr = p_TabArea->GetTabCount()-1; // Add one when a new AddTab is done;
135 i_PageNr = p_PageArea->GetTabCount()-1; // Add one when a new AddTab is done;
136 //---------------------------------------------------------------------------------------
137 p_PgmCtrl->pDoc = this;
138 p_TabArea->SetActiveTab(i_PageNr);
139 //---------------------------------------------------------------------------------------
140 p_Splitter->Initialize(p_TabArea);
141 p_Splitter->SplitHorizontally(p_TabArea,p_PageArea,Sash);
142 //---------------------------------------------------------------------------------------
143 // if (!OnInitODBC())
5151c7af 144 // return false;
645889ad
GT
145 OnInitODBC();
146 //---------------------------------------------------------------------------------------
67a99992 147#if wxUSE_STATUSBAR
645889ad
GT
148 Temp0.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN);
149 p_MainFrame->SetStatusText(Temp0, 0);
150 wxLogMessage(Temp0);
67a99992 151#endif // wxUSE_STATUSBAR
5151c7af 152 return true;
b5ffecfc 153}
645889ad 154
b5ffecfc 155//----------------------------------------------------------------------------------------
3fa0976a 156bool MainDoc::OnInitODBC()
b5ffecfc 157{
d73ae656
GT
158 wxChar Dsn[SQL_MAX_DSN_LENGTH+1];
159 wxChar DsDesc[254+1]; // BJO20002501 instead of 512
5d2ac6b8 160 Temp0 = wxEmptyString;
645889ad 161 i_DSN = 0; // Counter
74de91cc 162 int i;
645889ad
GT
163 //---------------------------------------------------------------------------------------
164 // Initialize the ODBC Environment for Database Operations
eacf9d88
GT
165
166 if (!DbConnectInf.AllocHenv())
645889ad 167 {
5151c7af 168 return false;
645889ad 169 }
eacf9d88 170
645889ad 171 //---------------------------------------------------------------------------------------
d73ae656 172 const wxChar sep = 3; // separator character used in string between DSN and DsDesc
44420d2e 173 wxSortedArrayString s_SortDSNList, s_SortDsDescList;
645889ad
GT
174 // BJO-20000127
175 // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string.
176 // The key will be removed after sorting
177 wxString KeyString;
178 //---------------------------------------------------------------------------------------
d73ae656 179 while (wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, SQL_MAX_DSN_LENGTH, DsDesc, 254))
645889ad
GT
180 {
181 i_DSN++; // How many Dsn have we ?
daf06bb8 182 KeyString.Printf(_T("%s%c%s"),Dsn, sep, DsDesc);
645889ad
GT
183 s_SortDSNList.Add(Dsn);
184 s_SortDsDescList.Add(KeyString);
185 }
5d2ac6b8 186
645889ad
GT
187 //---------------------------------------------------------------------------------------
188 // Allocate n ODBC-DSN objects to hold the information
44420d2e 189 // Allocate n wxDatabase objects to hold the column information
645889ad 190 p_DSN = new DSN[i_DSN]; //BJO
44420d2e 191 db_Br = new BrowserDB[i_DSN];
645889ad
GT
192 for (i=0;i<i_DSN;i++)
193 {
44420d2e 194 KeyString = s_SortDsDescList[i];
645889ad 195 KeyString = KeyString.AfterFirst(sep);
44420d2e
WS
196
197 // ODBC-DSN object
198 (p_DSN+i)->Dsn = s_SortDSNList[i];
199 (p_DSN+i)->Drv = KeyString;
5d2ac6b8
WS
200 (p_DSN+i)->Usr = wxEmptyString;
201 (p_DSN+i)->Pas = wxEmptyString;
daf06bb8 202 Temp0.Printf(_T("%02d) Dsn(%s) DsDesc(%s)"),i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str());
645889ad 203 wxLogMessage(Temp0);
44420d2e
WS
204
205 // wxDataBase object
645889ad
GT
206 (db_Br+i)->p_LogWindow = p_LogWin;
207 (db_Br+i)->ODBCSource = (p_DSN+i)->Dsn;
208 (db_Br+i)->UserName = (p_DSN+i)->Usr;
209 (db_Br+i)->Password = (p_DSN+i)->Pas;
210 (db_Br+i)->pDoc = this;
211 (db_Br+i)->i_Which = i;
212 }
eacf9d88
GT
213
214 DbConnectInf.FreeHenv();
215
645889ad
GT
216 //---------------------------------------------------------------------------------------
217 if (!i_DSN)
218 {
daf06bb8
JS
219 wxString message = _("No Dataset names found in ODBC!\n");
220 message += _(" Program will exit!\n\n");
221 message += _(" Ciao");
222 wxMessageBox( message,_("-E-> Fatal situation"));
5151c7af 223 return false;
645889ad
GT
224 }
225 //---------------------------------------------------------------------------------------
5151c7af 226 return true;
b5ffecfc 227}
645889ad 228
b5ffecfc 229//----------------------------------------------------------------------------------------
3fa0976a 230bool MainDoc::OnChosenDSN(int Which)
b5ffecfc 231{
645889ad
GT
232 // wxLogMessage("OnChosenDSN(%d) - Begin",Which);
233 //---------------------------------------------------------------------------------------
234 if (p_DBTree != NULL)
235 {
5151c7af 236 p_TabArea->Show(false); // Deactivate the Window
645889ad 237 p_TabArea->RemoveTab(p_DBTree->i_ViewNr);
5151c7af 238 p_TabArea->Show(true); // Activate the Window
5d2ac6b8 239 OnChosenTbl(77,wxEmptyString);
645889ad
GT
240 }
241 //-------------------------
5151c7af 242 p_TabArea->Show(false); // Deactivate the Window
645889ad
GT
243 p_DBTree = new DBTree(p_TabArea, TREE_CTRL_DB,wxDefaultPosition, wxDefaultSize,
244 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
daf06bb8 245 p_TabArea->AddTab(p_DBTree,(p_DSN+Which)->Dsn,_T(" ? "));
645889ad 246 p_DBTree->i_ViewNr = p_TabArea->GetTabCount()-1;
5151c7af 247 p_TabArea->Show(true); // Deactivate the Window
645889ad
GT
248 p_DBTree->i_Which = Which;
249 p_DBTree->s_DSN = (p_DSN+Which)->Dsn;
250 p_DBTree->i_TabArt = 0;
251 p_DBTree->pDoc = this;
252 p_DBTree->OnPopulate();
253 p_TabArea->SetActiveTab(p_DBTree->i_ViewNr);
254 //---------------------------------------------------------------------------------------
255 // wxLogMessage("OnChosenDSN(%d) - End",Which);
5151c7af 256 return true;
b5ffecfc 257}
645889ad 258
b5ffecfc 259//----------------------------------------------------------------------------------------
3fa0976a 260bool MainDoc::OnChosenTbl(int Tab,wxString Table)
b5ffecfc 261{
645889ad
GT
262 // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str());
263 //-------------------------
264 if (p_DBGrid != NULL)
265 {
266 if (p_DBGrid->i_TabArt == 0)
267 {
5151c7af 268 p_TabArea->Show(false); // Deactivate the Window
645889ad 269 p_TabArea->RemoveTab(p_DBGrid->i_ViewNr);
5151c7af 270 p_TabArea->Show(true); // Activate the Window
645889ad
GT
271 }
272 if (p_DBGrid->i_TabArt == 1)
273 {
5151c7af 274 p_PageArea->Show(false); // Deactivate the Window
645889ad 275 p_PageArea->RemoveTab(p_DBGrid->i_ViewNr);
5151c7af 276 p_PageArea->Show(true); // Activate the Window
645889ad
GT
277 }
278 p_DBGrid = NULL;
279 delete p_DBGrid;
280 }
281 if (Tab == 77) // Delete only
5151c7af 282 return true;
645889ad
GT
283 //-------------------------
284 if (Tab == 0) // Tabview
285 {
5151c7af 286 p_TabArea->Show(false); // Deactivate the Window
645889ad
GT
287 p_DBGrid = new DBGrid(p_TabArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
288 wxSUNKEN_BORDER);
5d2ac6b8 289 p_TabArea->AddTab(p_DBGrid, Table, wxEmptyString);
645889ad
GT
290 p_DBGrid->i_ViewNr = p_TabArea->GetTabCount()-1;
291 p_DBGrid->pDoc = this;
292 p_DBGrid->db_Br = db_Br;
293 p_DBGrid->OnTableView(Table);
294 p_TabArea->SetActiveTab(p_DBGrid->i_ViewNr);
5151c7af 295 p_TabArea->Show(true); // Activate the Window
645889ad
GT
296 }
297 if (Tab == 1) // Pageview
298 {
5151c7af 299 p_PageArea->Show(false); // Deactivate the Window
645889ad
GT
300 p_DBGrid = new DBGrid(p_PageArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
301 wxSUNKEN_BORDER);
5d2ac6b8 302 p_PageArea->AddTab(p_DBGrid, Table, wxEmptyString);
645889ad
GT
303 p_DBGrid->i_ViewNr = p_PageArea->GetTabCount()-1;
304 p_DBGrid->pDoc = this;
305 p_DBGrid->db_Br = db_Br;
306 p_DBGrid->i_Which = p_DBTree->i_Which;
5151c7af 307 p_PageArea->Show(true); // Activate the Window
645889ad
GT
308 p_DBGrid->OnTableView(Table);
309 p_PageArea->SetActiveTab(p_DBGrid->i_ViewNr);
310 }
311 p_DBGrid->i_TabArt = Tab;
312 //--------------------------
5151c7af 313 return true;
b5ffecfc 314}
645889ad 315
b5ffecfc 316//----------------------------------------------------------------------------------------
3fa0976a 317void MainDoc::OnLeer(wxString Aufrufer)
b5ffecfc 318{
645889ad
GT
319