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