]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/doc.cpp
deTABified
[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 744.
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;
59 s_BColour = "WHEAT";
e1c6c6ae 60 ft_Doc = new wxFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT));
b5ffecfc 61}
645889ad 62
c92b0f9a 63//----------------------------------------------------------------------------------------
3fa0976a 64MainDoc::~MainDoc()
b5ffecfc 65{
645889ad
GT
66 p_TabArea->Show(FALSE); // Deactivate the Window
67 p_PageArea->Show(FALSE); // Deactivate the Window
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())
89 return FALSE;
90 p_PgmCtrl->OnPopulate();
91 //---------------------------------------------------------------------------------------
92 wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw.Time());
93 return TRUE;
b5ffecfc 94}
645889ad 95
c92b0f9a 96//----------------------------------------------------------------------------------------
3fa0976a 97bool MainDoc::OnInitView()
b5ffecfc 98{
645889ad
GT
99 Sash = p_ProgramCfg->Read("/MainFrame/Sash", 200);
100 // wxMessageBox("OnInitView() - Begin ","-I->MainDoc::OnInitView");
101 //---------------------------------------------------------------------------------------
102 // create "workplace" window
103 //---------------------------------------------------------------------------------------
104 p_TabArea = new wxTabbedWindow(); // Init the Pointer
105 p_TabArea->Create(p_Splitter, -1);
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 //---------------------------------------------------------------------------------------
112 wxBitmap *p_FolderClose = new wxBitmap("PgmCtrl"); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115
113 //---------------------------------------------------------------------------------------
114 p_TabArea->AddTab(p_PgmCtrl,"PgmCtrl",p_FolderClose);
115 delete p_FolderClose; // Memory leak
116 p_FolderClose = NULL;
117 //---------------------------------------------------------------------------------------
118 // now create "output" window
119 //---------------------------------------------------------------------------------------
120 p_PageArea = new wxPagedWindow(); // Init the Pointer
121 p_PageArea->Create(p_Splitter, -1);
122 //---------------------------------------------------------------------------------------
123 p_LogWin = new wxTextCtrl(p_PageArea,-1,wxEmptyString,
124 wxDefaultPosition, wxDefaultSize,wxTE_MULTILINE );
125 p_LogWin->SetFont(* ft_Doc);
126 // Don't forget ! This is always : i_TabArt = 0 ; i_ViewNr = 1;
127 //---------------------------------------------------------------------------------------
128 p_LogBook = new wxLogTextCtrl(p_LogWin); // make p_LogWin the LogBook
129 p_LogBook->SetActiveTarget(p_LogBook);
130 p_LogBook->SetTimestamp( NULL );
131 //---------------------------------------------------------------------------------------
132 p_PageArea->AddTab(p_LogWin,_("LogBook"), "what is this?" );
133 i_TabNr = p_TabArea->GetTabCount()-1; // Add one when a new AddTab is done;
134 i_PageNr = p_PageArea->GetTabCount()-1; // Add one when a new AddTab is done;
135 //---------------------------------------------------------------------------------------
136 p_PgmCtrl->pDoc = this;
137 p_TabArea->SetActiveTab(i_PageNr);
138 //---------------------------------------------------------------------------------------
139 p_Splitter->Initialize(p_TabArea);
140 p_Splitter->SplitHorizontally(p_TabArea,p_PageArea,Sash);
141 //---------------------------------------------------------------------------------------
142 // if (!OnInitODBC())
143 // return FALSE;
144 OnInitODBC();
145 //---------------------------------------------------------------------------------------
146 Temp0.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN);
147 p_MainFrame->SetStatusText(Temp0, 0);
148 wxLogMessage(Temp0);
149 return TRUE;
b5ffecfc 150}
645889ad 151
b5ffecfc 152//----------------------------------------------------------------------------------------
3fa0976a 153bool MainDoc::OnInitODBC()
b5ffecfc 154{
645889ad
GT
155 char Dsn[SQL_MAX_DSN_LENGTH + 1];
156 char DsDesc[255]; // BJO20002501 instead of 512
157 Temp0 = "";
158 i_DSN = 0; // Counter
159 int i = 0;
160 //---------------------------------------------------------------------------------------
161 // Initialize the ODBC Environment for Database Operations
eacf9d88
GT
162
163 if (!DbConnectInf.AllocHenv())
645889ad
GT
164 {
165 return FALSE;
166 }
eacf9d88 167
645889ad
GT
168 //---------------------------------------------------------------------------------------
169 const char sep = 3; // separator character used in string between DSN ans DsDesc
170 wxStringList s_SortDSNList, s_SortDsDescList;
171 // BJO-20000127
172 // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string.
173 // The key will be removed after sorting
174 wxString KeyString;
175 //---------------------------------------------------------------------------------------
eacf9d88 176 while(wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, sizeof(Dsn), DsDesc, sizeof(DsDesc)))
645889ad
GT
177 {
178 i_DSN++; // How many Dsn have we ?
179 KeyString.Printf("%s%c%s",Dsn, sep, DsDesc);
180 s_SortDSNList.Add(Dsn);
181 s_SortDsDescList.Add(KeyString);
182 }
183 s_SortDSNList.Sort(); //BJO
184 s_SortDsDescList.Sort(); //BJO
185
186 char ** s_SortDSN = s_SortDSNList.ListToArray(); //BJO
187 char ** s_SortDsDesc = s_SortDsDescList.ListToArray(); //BJO
188 //---------------------------------------------------------------------------------------
189 // Allocate n ODBC-DSN objects to hold the information
190 p_DSN = new DSN[i_DSN]; //BJO
191 for (i=0;i<i_DSN;i++)
192 {
193 KeyString = s_SortDsDesc[i];
194 KeyString = KeyString.AfterFirst(sep);
195 strcpy(s_SortDsDesc[i],KeyString.c_str());
196 (p_DSN+i)->Dsn = s_SortDSN[i];
197 (p_DSN+i)->Drv = s_SortDsDesc[i];
198 (p_DSN+i)->Usr = "";
199 (p_DSN+i)->Pas = "";
200 Temp0.Printf("%02d) Dsn(%s) DsDesc(%s)",i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str());
201 wxLogMessage(Temp0);
202 }
203 i = 0;
204 //---------------------------------------------------------------------------------------
205 // Allocate n wxDatabase objects to hold the column information
206 db_Br = new BrowserDB[i_DSN];
207 for (i=0;i<i_DSN;i++)
208 {
209 (db_Br+i)->p_LogWindow = p_LogWin;
210 (db_Br+i)->ODBCSource = (p_DSN+i)->Dsn;
211 (db_Br+i)->UserName = (p_DSN+i)->Usr;
212 (db_Br+i)->Password = (p_DSN+i)->Pas;
213 (db_Br+i)->pDoc = this;
214 (db_Br+i)->i_Which = i;
215 }
eacf9d88
GT
216
217 DbConnectInf.FreeHenv();
218
645889ad
GT
219 delete [] s_SortDSN;
220 delete [] s_SortDsDesc;
221 //---------------------------------------------------------------------------------------
222 if (!i_DSN)
223 {
224 wxMessageBox(_("No Dataset names found in ODBC!\n" \
225 " Program will exit!\n\n" \
226 " Ciao"),"-E-> Fatal situation");
227 return FALSE;
228 }
229 //---------------------------------------------------------------------------------------
230 return TRUE;
b5ffecfc 231}
645889ad 232
b5ffecfc 233//----------------------------------------------------------------------------------------
3fa0976a 234bool MainDoc::OnChosenDSN(int Which)
b5ffecfc 235{
645889ad
GT
236 // wxLogMessage("OnChosenDSN(%d) - Begin",Which);
237 //---------------------------------------------------------------------------------------
238 if (p_DBTree != NULL)
239 {
240 p_TabArea->Show(FALSE); // Deactivate the Window
241 p_TabArea->RemoveTab(p_DBTree->i_ViewNr);
242 p_TabArea->Show(TRUE); // Activate the Window
243 OnChosenTbl(77,"");
244 }
245 //-------------------------
246 p_TabArea->Show(FALSE); // Deactivate the Window
247 p_DBTree = new DBTree(p_TabArea, TREE_CTRL_DB,wxDefaultPosition, wxDefaultSize,
248 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
249 p_TabArea->AddTab(p_DBTree,(p_DSN+Which)->Dsn," ? ");
250 p_DBTree->i_ViewNr = p_TabArea->GetTabCount()-1;
251 p_TabArea->Show(TRUE); // Deactivate the Window
252 p_DBTree->i_Which = Which;
253 p_DBTree->s_DSN = (p_DSN+Which)->Dsn;
254 p_DBTree->i_TabArt = 0;
255 p_DBTree->pDoc = this;
256 p_DBTree->OnPopulate();
257 p_TabArea->SetActiveTab(p_DBTree->i_ViewNr);
258 //---------------------------------------------------------------------------------------
259 // wxLogMessage("OnChosenDSN(%d) - End",Which);
260 return TRUE;
b5ffecfc 261}
645889ad 262
b5ffecfc 263//----------------------------------------------------------------------------------------
3fa0976a 264bool MainDoc::OnChosenTbl(int Tab,wxString Table)
b5ffecfc 265{
645889ad
GT
266 // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str());
267 //-------------------------
268 if (p_DBGrid != NULL)
269 {
270 if (p_DBGrid->i_TabArt == 0)
271 {
272 p_TabArea->Show(FALSE); // Deactivate the Window
273 p_TabArea->RemoveTab(p_DBGrid->i_ViewNr);
274 p_TabArea->Show(TRUE); // Activate the Window
275 }
276 if (p_DBGrid->i_TabArt == 1)
277 {
278 p_PageArea->Show(FALSE); // Deactivate the Window
279 p_PageArea->RemoveTab(p_DBGrid->i_ViewNr);
280 p_PageArea->Show(TRUE); // Activate the Window
281 }
282 p_DBGrid = NULL;
283 delete p_DBGrid;
284 }
285 if (Tab == 77) // Delete only
286 return TRUE;
287 //-------------------------
288 if (Tab == 0) // Tabview
289 {
290 p_TabArea->Show(FALSE); // Deactivate the Window
291 p_DBGrid = new DBGrid(p_TabArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
292 wxSUNKEN_BORDER);
293 p_TabArea->AddTab(p_DBGrid, Table, "");
294 p_DBGrid->i_ViewNr = p_TabArea->GetTabCount()-1;
295 p_DBGrid->pDoc = this;
296 p_DBGrid->db_Br = db_Br;
297 p_DBGrid->OnTableView(Table);
298 p_TabArea->SetActiveTab(p_DBGrid->i_ViewNr);
299 p_TabArea->Show(TRUE); // Activate the Window
300 }
301 if (Tab == 1) // Pageview
302 {
303 p_PageArea->Show(FALSE); // Deactivate the Window
304 p_DBGrid = new DBGrid(p_PageArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
305 wxSUNKEN_BORDER);
306 p_PageArea->AddTab(p_DBGrid, Table, "");
307 p_DBGrid->i_ViewNr = p_PageArea->GetTabCount()-1;
308 p_DBGrid->pDoc = this;
309 p_DBGrid->db_Br = db_Br;
310 p_DBGrid->i_Which = p_DBTree->i_Which;
311 p_PageArea->Show(TRUE); // Activate the Window
312 p_DBGrid->OnTableView(Table);
313 p_PageArea->SetActiveTab(p_DBGrid->i_ViewNr);
314 }
315 p_DBGrid->i_TabArt = Tab;
316 //--------------------------
317 return TRUE;;
b5ffecfc 318}
645889ad 319
b5ffecfc 320//----------------------------------------------------------------------------------------
3fa0976a 321void MainDoc::OnLeer(wxString Aufrufer)
b5ffecfc 322{
645889ad
GT
323