]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/doc.cpp
Cleaned up the API for class/structure/function names to follow the wxWindows convent...
[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 713.
CommitLineData
c92b0f9a 1//----------------------------------------------------------------------------------------
b5ffecfc 2// Name: Doc.cpp
c92b0f9a 3// Purpose: Holds information for DBBrowser - (a do-it-yourself document)
b5ffecfc
GT
4// Author: Mark Johnson, mj10777@gmx.net
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
b5ce269b 36struct DbStuff DbConnectInf;
c92b0f9a 37//----------------------------------------------------------------------------------------
b5ffecfc
GT
38wxConfigBase *p_ProgramCfg; // All Config and Path information
39wxLogTextCtrl *p_LogBook; // All Log messages
40wxString LogBuf; // String for all Logs
c92b0f9a 41//----------------------------------------------------------------------------------------
3fa0976a 42MainDoc::MainDoc()
b5ffecfc 43{
c92b0f9a
MJ
44 db_Br = NULL;
45 p_DSN = NULL;
46 i_DSN = 0;
47 p_Splitter = NULL;
48 p_MainFrame = NULL;
49 p_PgmCtrl = NULL; // Is not active
50 p_DBTree = NULL;
51 p_DBGrid = NULL;
52 p_LogWin = NULL;
53 p_TabArea = NULL;
54 p_PageArea = NULL;
55 i_TabNr = 0;
56 i_PageNr = 0;
57 s_BColour = "WHEAT";
58 ft_Doc = new wxFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
b5ffecfc 59}
c92b0f9a 60//----------------------------------------------------------------------------------------
3fa0976a 61MainDoc::~MainDoc()
b5ffecfc 62{
c92b0f9a
MJ
63 // ----------------------------------------------------------
64 // -E-> The Tree Controls take to long to close : Why ??
65 // ----------------------------------------------------------
66 // wxMessageBox("-I-> end Doc");
67 p_TabArea->Show(FALSE); // Deactivate the Window
68 p_PageArea->Show(FALSE); // Deactivate the Window
69 p_PgmCtrl = NULL;
70 delete p_PgmCtrl;
71 delete [] p_DSN;
72 delete p_DBTree;
73 p_TabArea = NULL; delete p_TabArea;
74 p_PageArea = NULL; delete p_PageArea;
75 p_Splitter = NULL;
76 delete p_Splitter;
77 delete [] db_Br;
3fa0976a 78 // wxMessageBox("~MainDoc");
b5ffecfc 79}
c92b0f9a 80//----------------------------------------------------------------------------------------
3fa0976a 81bool MainDoc::OnNewDocument()
b5ffecfc 82{
897d36c2 83 wxStopWatch sw;
c92b0f9a
MJ
84 //---------------------------------------------------------------------------------------
85 if (!OnInitView())
c92b0f9a 86 return FALSE;
c92b0f9a
MJ
87 p_PgmCtrl->OnPopulate();
88 //---------------------------------------------------------------------------------------
3fa0976a 89 wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw.Time());
c92b0f9a 90 return TRUE;
b5ffecfc 91}
c92b0f9a 92//----------------------------------------------------------------------------------------
3fa0976a 93bool MainDoc::OnInitView()
b5ffecfc 94{
c92b0f9a 95 Sash = p_ProgramCfg->Read("/MainFrame/Sash", 200);
3fa0976a 96 // wxMessageBox("OnInitView() - Begin ","-I->MainDoc::OnInitView");
c92b0f9a
MJ
97 //---------------------------------------------------------------------------------------
98 // create "workplace" window
99 //---------------------------------------------------------------------------------------
100 p_TabArea = new wxTabbedWindow(); // Init the Pointer
101 p_TabArea->Create(p_Splitter, -1);
102 //---------------------------------------------------------------------------------------
103 p_PgmCtrl = new PgmCtrl(p_TabArea, TREE_CTRL_PGM,wxDefaultPosition, wxDefaultSize,
104 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
105 p_PgmCtrl->i_TabArt = 0; // 0 = Tab ; 1 = Page
106 p_PgmCtrl->i_ViewNr = p_TabArea->GetTabCount()-1;
107 //---------------------------------------------------------------------------------------
108 wxBitmap *p_FolderClose = new wxBitmap("PgmCtrl"); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115
109 //---------------------------------------------------------------------------------------
110 p_TabArea->AddTab(p_PgmCtrl,"PgmCtrl",p_FolderClose);
111 //---------------------------------------------------------------------------------------
112 // now create "output" window
113 //---------------------------------------------------------------------------------------
114 p_PageArea = new wxPaggedWindow(); // Init the Pointer
115 p_PageArea->Create(p_Splitter, -1);
116 //---------------------------------------------------------------------------------------
117 p_LogWin = new wxTextCtrl(p_PageArea,-1,wxEmptyString,
118 wxDefaultPosition, wxDefaultSize,wxTE_MULTILINE );
897d36c2 119 p_LogWin->SetFont(* ft_Doc);
c92b0f9a
MJ
120 // Don't forget ! This is always : i_TabArt = 0 ; i_ViewNr = 1;
121 //---------------------------------------------------------------------------------------
122 p_LogBook = new wxLogTextCtrl(p_LogWin); // make p_LogWin the LogBook
123 p_LogBook->SetActiveTarget(p_LogBook);
124 p_LogBook->SetTimestamp( NULL );
125 //---------------------------------------------------------------------------------------
126 p_PageArea->AddTab(p_LogWin,_("LogBook"), "what is this?" );
127 i_TabNr = p_TabArea->GetTabCount()-1; // Add one when a new AddTab is done;
128 i_PageNr = p_PageArea->GetTabCount()-1; // Add one when a new AddTab is done;
129 //---------------------------------------------------------------------------------------
130 p_PgmCtrl->pDoc = this;
131 p_TabArea->SetActiveTab(i_PageNr);
132 //---------------------------------------------------------------------------------------
133 p_Splitter->Initialize(p_TabArea);
134 p_Splitter->SplitHorizontally(p_TabArea,p_PageArea,Sash);
135 //---------------------------------------------------------------------------------------
36ba4665
MJ
136 // if (!OnInitODBC())
137 // return FALSE;
138 OnInitODBC();
c92b0f9a 139 //---------------------------------------------------------------------------------------
3fa0976a 140 Temp0.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN);
c92b0f9a
MJ
141 p_MainFrame->SetStatusText(Temp0, 0);
142 wxLogMessage(Temp0);
143 return TRUE;
b5ffecfc
GT
144}
145//----------------------------------------------------------------------------------------
3fa0976a 146bool MainDoc::OnInitODBC()
b5ffecfc 147{
c92b0f9a
MJ
148 char Dsn[SQL_MAX_DSN_LENGTH + 1];
149 char DsDesc[255]; // BJO20002501 instead of 512
150 Temp0 = "";
151 i_DSN = 0; // Counter
152 int i = 0;
153 //---------------------------------------------------------------------------------------
154 // Initialize the ODBC Environment for Database Operations
155
156 if (SQLAllocEnv(&DbConnectInf.Henv) != SQL_SUCCESS)
157 {
158 return FALSE;
159 }
160 //---------------------------------------------------------------------------------------
161 const char sep = 3; // separator character used in string between DSN ans DsDesc
162 wxStringList s_SortDSNList, s_SortDsDescList;
163 // BJO-20000127
164 // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string.
165 // The key will be removed after sorting
166 wxString KeyString;
167 //---------------------------------------------------------------------------------------
168 while(GetDataSource(DbConnectInf.Henv, Dsn, sizeof(Dsn), DsDesc, sizeof(DsDesc)))
169 {
170 i_DSN++; // How many Dsn have we ?
171 KeyString.Printf("%s%c%s",Dsn, sep, DsDesc);
172 s_SortDSNList.Add(Dsn);
173 s_SortDsDescList.Add(KeyString);
174 }
175 s_SortDSNList.Sort(); //BJO
176 s_SortDsDescList.Sort(); //BJO
177
178 char ** s_SortDSN = s_SortDSNList.ListToArray(); //BJO
179 char ** s_SortDsDesc = s_SortDsDescList.ListToArray(); //BJO
180 //---------------------------------------------------------------------------------------
181 // Allocate n ODBC-DSN objects to hold the information
182 p_DSN = new DSN[i_DSN]; //BJO
183 for (i=0;i<i_DSN;i++)
184 {
185 KeyString = s_SortDsDesc[i];
186 KeyString = KeyString.AfterFirst(sep);
187 strcpy(s_SortDsDesc[i],KeyString.c_str());
188 (p_DSN+i)->Dsn = s_SortDSN[i];
189 (p_DSN+i)->Drv = s_SortDsDesc[i];
190 (p_DSN+i)->Usr = "";
191 (p_DSN+i)->Pas = "";
192 Temp0.Printf("%02d) Dsn(%s) DsDesc(%s)",i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str());
193 wxLogMessage(Temp0);
194 }
195 i = 0;
196 //---------------------------------------------------------------------------------------
197 // Allocate n wxDatabase objects to hold the column information
198 db_Br = new BrowserDB[i_DSN];
199 for (i=0;i<i_DSN;i++)
200 {
201 (db_Br+i)->p_LogWindow = p_LogWin;
202 (db_Br+i)->ODBCSource = (p_DSN+i)->Dsn;
203 (db_Br+i)->UserName = (p_DSN+i)->Usr;
204 (db_Br+i)->Password = (p_DSN+i)->Pas;
205 (db_Br+i)->pDoc = this;
206 (db_Br+i)->i_Which = i;
207 }
30bb7c13 208 if (SQLFreeEnv(DbConnectInf.Henv) != SQL_SUCCESS) // BJO20000125 / MJ10777.20000309 : no &
c92b0f9a
MJ
209 {
210 // Error freeing environment handle
211 }
212 delete [] s_SortDSN;
213 delete [] s_SortDsDesc;
214 //---------------------------------------------------------------------------------------
215 if (!i_DSN)
216 {
217 wxMessageBox(_("No Dataset names found in ODBC!\n" \
218 " Program will exit!\n\n" \
219 " Ciao"),"-E-> Fatal situation");
220 return FALSE;
221 }
222 //---------------------------------------------------------------------------------------
223 return TRUE;
b5ffecfc
GT
224}
225//----------------------------------------------------------------------------------------
3fa0976a 226bool MainDoc::OnChosenDSN(int Which)
b5ffecfc 227{
c92b0f9a
MJ
228 // wxLogMessage("OnChosenDSN(%d) - Begin",Which);
229 //---------------------------------------------------------------------------------------
230 if (p_DBTree != NULL)
231 {
b5ffecfc 232 p_TabArea->Show(FALSE); // Deactivate the Window
c92b0f9a
MJ
233 p_TabArea->RemoveTab(p_DBTree->i_ViewNr);
234 p_TabArea->Show(TRUE); // Activate the Window
235 OnChosenTbl(77,"");
236 }
237 //-------------------------
238 p_TabArea->Show(FALSE); // Deactivate the Window
239 p_DBTree = new DBTree(p_TabArea, TREE_CTRL_DB,wxDefaultPosition, wxDefaultSize,
240 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
241 p_TabArea->AddTab(p_DBTree,(p_DSN+Which)->Dsn," ? ");
242 p_DBTree->i_ViewNr = p_TabArea->GetTabCount()-1;
243 p_TabArea->Show(TRUE); // Deactivate the Window
244 p_DBTree->i_Which = Which;
245 p_DBTree->s_DSN = (p_DSN+Which)->Dsn;
246 p_DBTree->i_TabArt = 0;
247 p_DBTree->pDoc = this;
248 p_DBTree->OnPopulate();
249 p_TabArea->SetActiveTab(p_DBTree->i_ViewNr);
250 //---------------------------------------------------------------------------------------
251 // wxLogMessage("OnChosenDSN(%d) - End",Which);
252 return TRUE;
b5ffecfc
GT
253}
254//----------------------------------------------------------------------------------------
3fa0976a 255bool MainDoc::OnChosenTbl(int Tab,wxString Table)
b5ffecfc 256{
c92b0f9a
MJ
257 // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str());
258 //-------------------------
259 if (p_DBGrid != NULL)
260 {
261 if (p_DBGrid->i_TabArt == 0)
262 {
263 p_TabArea->Show(FALSE); // Deactivate the Window
264 p_TabArea->RemoveTab(p_DBGrid->i_ViewNr);
265 p_TabArea->Show(TRUE); // Activate the Window
266 }
267 if (p_DBGrid->i_TabArt == 1)
268 {
269 p_PageArea->Show(FALSE); // Deactivate the Window
270 p_PageArea->RemoveTab(p_DBGrid->i_ViewNr);
271 p_PageArea->Show(TRUE); // Activate the Window
272 }
273 p_DBGrid = NULL;
274 delete p_DBGrid;
275 }
276 if (Tab == 77) // Delete only
277 return TRUE;
278 //-------------------------
279 if (Tab == 0) // Tabview
280 {
281 p_TabArea->Show(FALSE); // Deactivate the Window
282 p_DBGrid = new DBGrid(p_TabArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
283 wxSUNKEN_BORDER);
284 p_TabArea->AddTab(p_DBGrid, Table, "");
285 p_DBGrid->i_ViewNr = p_TabArea->GetTabCount()-1;
286 p_DBGrid->pDoc = this;
287 p_DBGrid->db_Br = db_Br;
288 p_DBGrid->OnTableView(Table);
289 p_TabArea->SetActiveTab(p_DBGrid->i_ViewNr);
290 p_TabArea->Show(TRUE); // Activate the Window
291 }
292 if (Tab == 1) // Pageview
293 {
294 p_PageArea->Show(FALSE); // Deactivate the Window
295 p_DBGrid = new DBGrid(p_PageArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
296 wxSUNKEN_BORDER);
297 p_PageArea->AddTab(p_DBGrid, Table, "");
298 p_DBGrid->i_ViewNr = p_PageArea->GetTabCount()-1;
299 p_DBGrid->pDoc = this;
300 p_DBGrid->db_Br = db_Br;
301 p_DBGrid->i_Which = p_DBTree->i_Which;
302 p_PageArea->Show(TRUE); // Activate the Window
303 p_DBGrid->OnTableView(Table);
304 p_PageArea->SetActiveTab(p_DBGrid->i_ViewNr);
305 }
306 p_DBGrid->i_TabArt = Tab;
307 //--------------------------
308 return TRUE;;
b5ffecfc
GT
309}
310//----------------------------------------------------------------------------------------
3fa0976a 311void MainDoc::OnLeer(wxString Aufrufer)
b5ffecfc 312{
3fa0976a
MJ
313