]>
Commit | Line | Data |
---|---|---|
1 | //---------------------------------------------------------------------------------------- | |
2 | // Name: doc.cpp | |
3 | // Purpose: Holds information for DBBrowser - (a do-it-yourself document) | |
4 | // Author: Mark Johnson | |
5 | // Modified by: 19990808.mj10777 | |
6 | // BJO : Bart A.M. JOURQUIN | |
7 | // Created: 19990808 | |
8 | // Copyright: (c) Mark Johnson | |
9 | // Licence: wxWindows license | |
10 | // RCS-ID: $Id$ | |
11 | //---------------------------------------------------------------------------------------- | |
12 | //-- all #ifdefs that the whole Project needs. ------------------------------------------- | |
13 | //---------------------------------------------------------------------------------------- | |
14 | #ifdef __GNUG__ | |
15 | #pragma implementation | |
16 | #pragma interface | |
17 | #endif | |
18 | //---------------------------------------------------------------------------------------- | |
19 | // For compilers that support precompilation, includes "wx/wx.h". | |
20 | #include "wx/wxprec.h" | |
21 | //---------------------------------------------------------------------------------------- | |
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | //---------------------------------------------------------------------------------------- | |
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/wx.h" | |
28 | #endif | |
29 | //---------------------------------------------------------------------------------------- | |
30 | //-- all #includes that every .cpp needs ----19990807.mj10777 ---------------- | |
31 | //---------------------------------------------------------------------------------------- | |
32 | #include "std.h" // sorgsam Pflegen ! | |
33 | //---------------------------------------------------------------------------------------- | |
34 | //-- Some Global Vars for all Files (extern in ?.h needed) ------------------------------- | |
35 | // Global structure for holding ODBC connection information | |
36 | extern wxDbConnectInf DbConnectInf; | |
37 | ||
38 | //---------------------------------------------------------------------------------------- | |
39 | wxConfigBase *p_ProgramCfg; // All Config and Path information | |
40 | wxLogTextCtrl *p_LogBook; // All Log messages | |
41 | wxString LogBuf; // String for all Logs | |
42 | ||
43 | //---------------------------------------------------------------------------------------- | |
44 | MainDoc::MainDoc() | |
45 | { | |
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 = _T("WHEAT"); | |
60 | ft_Doc = new wxFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT)); | |
61 | } | |
62 | ||
63 | //---------------------------------------------------------------------------------------- | |
64 | MainDoc::~MainDoc() | |
65 | { | |
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"); | |
81 | } | |
82 | ||
83 | //---------------------------------------------------------------------------------------- | |
84 | bool MainDoc::OnNewDocument() | |
85 | { | |
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; | |
94 | } | |
95 | ||
96 | //---------------------------------------------------------------------------------------- | |
97 | bool MainDoc::OnInitView() | |
98 | { | |
99 | Sash = p_ProgramCfg->Read(_T("/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, wxID_ANY); | |
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(_T("PgmCtrl")); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115 | |
113 | //--------------------------------------------------------------------------------------- | |
114 | p_TabArea->AddTab(p_PgmCtrl,_T("PgmCtrl"),p_FolderClose); | |
115 | delete p_FolderClose; // Memory leak | |
116 | p_FolderClose = NULL; | |
117 | wxUnusedVar(p_FolderClose); | |
118 | //--------------------------------------------------------------------------------------- | |
119 | // now create "output" window | |
120 | //--------------------------------------------------------------------------------------- | |
121 | p_PageArea = new wxPagedWindow(); // Init the Pointer | |
122 | p_PageArea->Create(p_Splitter, wxID_ANY); | |
123 | //--------------------------------------------------------------------------------------- | |
124 | p_LogWin = new wxTextCtrl(p_PageArea,wxID_ANY,wxEmptyString, | |
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 | //--------------------------------------------------------------------------------------- | |
133 | p_PageArea->AddTab(p_LogWin,_("LogBook"), _T("what is this?") ); | |
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()) | |
144 | // return false; | |
145 | OnInitODBC(); | |
146 | //--------------------------------------------------------------------------------------- | |
147 | #if wxUSE_STATUSBAR | |
148 | Temp0.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN); | |
149 | p_MainFrame->SetStatusText(Temp0, 0); | |
150 | wxLogMessage(Temp0); | |
151 | #endif // wxUSE_STATUSBAR | |
152 | return true; | |
153 | } | |
154 | ||
155 | //---------------------------------------------------------------------------------------- | |
156 | bool MainDoc::OnInitODBC() | |
157 | { | |
158 | wxChar Dsn[SQL_MAX_DSN_LENGTH + 1]; | |
159 | wxChar DsDesc[255]; // BJO20002501 instead of 512 | |
160 | Temp0 = _T(""); | |
161 | i_DSN = 0; // Counter | |
162 | int i; | |
163 | //--------------------------------------------------------------------------------------- | |
164 | // Initialize the ODBC Environment for Database Operations | |
165 | ||
166 | if (!DbConnectInf.AllocHenv()) | |
167 | { | |
168 | return false; | |
169 | } | |
170 | ||
171 | //--------------------------------------------------------------------------------------- | |
172 | const char sep = 3; // separator character used in string between DSN ans DsDesc | |
173 | wxStringList s_SortDSNList, s_SortDsDescList; | |
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 | //--------------------------------------------------------------------------------------- | |
179 | while(wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, sizeof(Dsn), DsDesc, sizeof(DsDesc))) | |
180 | { | |
181 | i_DSN++; // How many Dsn have we ? | |
182 | KeyString.Printf(_T("%s%c%s"),Dsn, sep, DsDesc); | |
183 | s_SortDSNList.Add(Dsn); | |
184 | s_SortDsDescList.Add(KeyString); | |
185 | } | |
186 | s_SortDSNList.Sort(); //BJO | |
187 | s_SortDsDescList.Sort(); //BJO | |
188 | ||
189 | wxChar ** s_SortDSN = s_SortDSNList.ListToArray(); //BJO | |
190 | wxChar ** s_SortDsDesc = s_SortDsDescList.ListToArray(); //BJO | |
191 | //--------------------------------------------------------------------------------------- | |
192 | // Allocate n ODBC-DSN objects to hold the information | |
193 | p_DSN = new DSN[i_DSN]; //BJO | |
194 | for (i=0;i<i_DSN;i++) | |
195 | { | |
196 | KeyString = s_SortDsDesc[i]; | |
197 | KeyString = KeyString.AfterFirst(sep); | |
198 | wxStrcpy(s_SortDsDesc[i],KeyString.c_str()); | |
199 | (p_DSN+i)->Dsn = s_SortDSN[i]; | |
200 | (p_DSN+i)->Drv = s_SortDsDesc[i]; | |
201 | (p_DSN+i)->Usr = _T(""); | |
202 | (p_DSN+i)->Pas = _T(""); | |
203 | Temp0.Printf(_T("%02d) Dsn(%s) DsDesc(%s)"),i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str()); | |
204 | wxLogMessage(Temp0); | |
205 | } | |
206 | //--------------------------------------------------------------------------------------- | |
207 | // Allocate n wxDatabase objects to hold the column information | |
208 | db_Br = new BrowserDB[i_DSN]; | |
209 | for (i=0;i<i_DSN;i++) | |
210 | { | |
211 | (db_Br+i)->p_LogWindow = p_LogWin; | |
212 | (db_Br+i)->ODBCSource = (p_DSN+i)->Dsn; | |
213 | (db_Br+i)->UserName = (p_DSN+i)->Usr; | |
214 | (db_Br+i)->Password = (p_DSN+i)->Pas; | |
215 | (db_Br+i)->pDoc = this; | |
216 | (db_Br+i)->i_Which = i; | |
217 | } | |
218 | ||
219 | DbConnectInf.FreeHenv(); | |
220 | ||
221 | delete [] s_SortDSN; | |
222 | delete [] s_SortDsDesc; | |
223 | //--------------------------------------------------------------------------------------- | |
224 | if (!i_DSN) | |
225 | { | |
226 | wxString message = _("No Dataset names found in ODBC!\n"); | |
227 | message += _(" Program will exit!\n\n"); | |
228 | message += _(" Ciao"); | |
229 | wxMessageBox( message,_("-E-> Fatal situation")); | |
230 | return false; | |
231 | } | |
232 | //--------------------------------------------------------------------------------------- | |
233 | return true; | |
234 | } | |
235 | ||
236 | //---------------------------------------------------------------------------------------- | |
237 | bool MainDoc::OnChosenDSN(int Which) | |
238 | { | |
239 | // wxLogMessage("OnChosenDSN(%d) - Begin",Which); | |
240 | //--------------------------------------------------------------------------------------- | |
241 | if (p_DBTree != NULL) | |
242 | { | |
243 | p_TabArea->Show(false); // Deactivate the Window | |
244 | p_TabArea->RemoveTab(p_DBTree->i_ViewNr); | |
245 | p_TabArea->Show(true); // Activate the Window | |
246 | OnChosenTbl(77,_T("")); | |
247 | } | |
248 | //------------------------- | |
249 | p_TabArea->Show(false); // Deactivate the Window | |
250 | p_DBTree = new DBTree(p_TabArea, TREE_CTRL_DB,wxDefaultPosition, wxDefaultSize, | |
251 | wxTR_HAS_BUTTONS | wxSUNKEN_BORDER); | |
252 | p_TabArea->AddTab(p_DBTree,(p_DSN+Which)->Dsn,_T(" ? ")); | |
253 | p_DBTree->i_ViewNr = p_TabArea->GetTabCount()-1; | |
254 | p_TabArea->Show(true); // Deactivate the Window | |
255 | p_DBTree->i_Which = Which; | |
256 | p_DBTree->s_DSN = (p_DSN+Which)->Dsn; | |
257 | p_DBTree->i_TabArt = 0; | |
258 | p_DBTree->pDoc = this; | |
259 | p_DBTree->OnPopulate(); | |
260 | p_TabArea->SetActiveTab(p_DBTree->i_ViewNr); | |
261 | //--------------------------------------------------------------------------------------- | |
262 | // wxLogMessage("OnChosenDSN(%d) - End",Which); | |
263 | return true; | |
264 | } | |
265 | ||
266 | //---------------------------------------------------------------------------------------- | |
267 | bool MainDoc::OnChosenTbl(int Tab,wxString Table) | |
268 | { | |
269 | // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str()); | |
270 | //------------------------- | |
271 | if (p_DBGrid != NULL) | |
272 | { | |
273 | if (p_DBGrid->i_TabArt == 0) | |
274 | { | |
275 | p_TabArea->Show(false); // Deactivate the Window | |
276 | p_TabArea->RemoveTab(p_DBGrid->i_ViewNr); | |
277 | p_TabArea->Show(true); // Activate the Window | |
278 | } | |
279 | if (p_DBGrid->i_TabArt == 1) | |
280 | { | |
281 | p_PageArea->Show(false); // Deactivate the Window | |
282 | p_PageArea->RemoveTab(p_DBGrid->i_ViewNr); | |
283 | p_PageArea->Show(true); // Activate the Window | |
284 | } | |
285 | p_DBGrid = NULL; | |
286 | delete p_DBGrid; | |
287 | } | |
288 | if (Tab == 77) // Delete only | |
289 | return true; | |
290 | //------------------------- | |
291 | if (Tab == 0) // Tabview | |
292 | { | |
293 | p_TabArea->Show(false); // Deactivate the Window | |
294 | p_DBGrid = new DBGrid(p_TabArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize, | |
295 | wxSUNKEN_BORDER); | |
296 | p_TabArea->AddTab(p_DBGrid, Table, _T("")); | |
297 | p_DBGrid->i_ViewNr = p_TabArea->GetTabCount()-1; | |
298 | p_DBGrid->pDoc = this; | |
299 | p_DBGrid->db_Br = db_Br; | |
300 | p_DBGrid->OnTableView(Table); | |
301 | p_TabArea->SetActiveTab(p_DBGrid->i_ViewNr); | |
302 | p_TabArea->Show(true); // Activate the Window | |
303 | } | |
304 | if (Tab == 1) // Pageview | |
305 | { | |
306 | p_PageArea->Show(false); // Deactivate the Window | |
307 | p_DBGrid = new DBGrid(p_PageArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize, | |
308 | wxSUNKEN_BORDER); | |
309 | p_PageArea->AddTab(p_DBGrid, Table, _T("")); | |
310 | p_DBGrid->i_ViewNr = p_PageArea->GetTabCount()-1; | |
311 | p_DBGrid->pDoc = this; | |
312 | p_DBGrid->db_Br = db_Br; | |
313 | p_DBGrid->i_Which = p_DBTree->i_Which; | |
314 | p_PageArea->Show(true); // Activate the Window | |
315 | p_DBGrid->OnTableView(Table); | |
316 | p_PageArea->SetActiveTab(p_DBGrid->i_ViewNr); | |
317 | } | |
318 | p_DBGrid->i_TabArt = Tab; | |
319 | //-------------------------- | |
320 | return true; | |
321 | } | |
322 | ||
323 | //---------------------------------------------------------------------------------------- | |
324 | void MainDoc::OnLeer(wxString Aufrufer) | |
325 | { | |
326 | Content-type: text/html ]>