]> git.saurik.com Git - wxWidgets.git/blame - demos/dbbrowse/doc.cpp
icons fix for unix
[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 712.
CommitLineData
b5ffecfc
GT
1//---------------------------------------------------------------------------
2// Name: Doc.cpp
3// Purpose: Holds information for DBBrowser
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$
b5ffecfc
GT
11//---------------------------------------------------------------------------
12//-- all #ifdefs that the whole Project needs. ------------------------------
13//---------------------------------------------------------------------------
14#ifdef __GNUG__
b5ce269b
BJ
15#pragma implementation
16#pragma interface
b5ffecfc
GT
17#endif
18//---------------------------------------------------------------------------
19// For compilers that support precompilation, includes "wx/wx.h".
20#include "wx/wxprec.h"
21//---------------------------------------------------------------------------
22#ifdef __BORLANDC__
b5ce269b 23#pragma hdrstop
b5ffecfc
GT
24#endif
25//---------------------------------------------------------------------------
26#ifndef WX_PRECOMP
b5ce269b 27#include "wx/wx.h"
b5ffecfc
GT
28#endif
29//---------------------------------------------------------------------------
30//---------------------------------------------------------------------------
31//-- all #includes that every .cpp needs ----19990807.mj10777 ---
32//---------------------------------------------------------------------------
33#include "std.h" // sorgsam Pflegen !
34//---------------------------------------------------------------------------
35//-- Some Global Vars for all Files (extern in ?.h needed) -----------------
36// Global structure for holding ODBC connection information
b5ce269b 37struct DbStuff DbConnectInf;
b5ffecfc
GT
38//---------------------------------------------------------------------------
39wxConfigBase *p_ProgramCfg; // All Config and Path information
40wxLogTextCtrl *p_LogBook; // All Log messages
41wxString LogBuf; // String for all Logs
42//---------------------------------------------------------------------------
43mjDoc::mjDoc()
44{
b5ce269b
BJ
45 db_Br = NULL;
46 p_DSN = NULL;
47 i_DSN = 0;
48 p_Splitter = NULL;
49 p_MainFrame = NULL;
50 p_PgmCtrl = NULL; // Is not active
51 p_DBTree = NULL;
52 p_DBGrid = NULL;
53 p_LogWin = NULL;
54 p_TabArea = NULL;
55 p_PageArea = NULL;
56 i_TabNr = 0;
57 i_PageNr = 0;
b5ffecfc
GT
58}
59//---------------------------------------------------------------------------
60mjDoc::~mjDoc()
61{
b5ce269b
BJ
62 // ----------------------------------------------------------
63 // -E-> The Tree Controls take to long to close : Why ??
64 // ----------------------------------------------------------
65 // wxMessageBox("-I-> end Doc");
66 p_TabArea->Show(FALSE); // Deactivate the Window
67 p_PageArea->Show(FALSE); // Deactivate the Window
68 p_PgmCtrl = NULL;
69 delete p_PgmCtrl;
70 delete [] p_DSN;
71 delete p_DBTree;
72 p_TabArea = NULL; delete p_TabArea;
73 p_PageArea = NULL; delete p_PageArea;
74 p_Splitter = NULL;
75 delete p_Splitter;
76 delete [] db_Br;
77 // wxMessageBox("~mjDoc");
b5ffecfc
GT
78}
79//---------------------------------------------------------------------------
80bool mjDoc::OnNewDocument()
81{
b5ce269b 82 //-------------------------------------------------------------------
ed6e827e
BJ
83 if (!OnInitView())
84 {
b5ce269b 85 return FALSE;
ed6e827e 86 }
b5ce269b
BJ
87 p_PgmCtrl->OnPopulate();
88 //-------------------------------------------------------------------
89 return TRUE;
b5ffecfc
GT
90}
91//---------------------------------------------------------------------------
92bool mjDoc::OnInitView()
93{
b5ce269b
BJ
94 Sash = p_ProgramCfg->Read("/MainFrame/Sash", 200);
95 // wxMessageBox("OnInitView() - Begin ","-I->mjDoc::OnInitView");
96 //--------------------------------------------------------------------------
97 // create "workplace" window
98 //--------------------------------------------------------------------------
99 p_TabArea = new wxTabbedWindow(); // Init the Pointer
100 p_TabArea->Create(p_Splitter, -1);
101 //--------------------------------------------------------------------------
102 p_PgmCtrl = new PgmCtrl(p_TabArea, TREE_CTRL_PGM,wxDefaultPosition, wxDefaultSize,
103 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
104 p_PgmCtrl->i_TabArt = 0; // 0 = Tab ; 1 = Page
105 p_PgmCtrl->i_ViewNr = p_TabArea->GetTabCount()-1;
106 //--------------------------------------------------------------------------
107 wxBitmap *p_FolderClose = new wxBitmap("PgmCtrl"); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115
108 //--------------------------------------------------------------------------
109 p_TabArea->AddTab(p_PgmCtrl,"PgmCtrl",p_FolderClose);
110 //--------------------------------------------------------------------------
111 // now create "output" window
112 //--------------------------------------------------------------------------
113 p_PageArea = new wxPaggedWindow(); // Init the Pointer
114 p_PageArea->Create(p_Splitter, -1);
115 //--------------------------------------------------------------------------
116 p_LogWin = new wxTextCtrl(p_PageArea,-1,wxEmptyString,
117 wxDefaultPosition, wxDefaultSize,wxTE_MULTILINE );
b3630c4f 118 //wxFont* ft_Temp = new wxFont(10,wxSWISS,wxNORMAL,wxBOLD,FALSE,"Comic Sans MS");
c45a4560
BJ
119 wxFont* ft_Temp = new wxFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
120 p_LogWin->SetFont(* ft_Temp);
b5ce269b
BJ
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 //------------------------------------------------------------------
127 p_PageArea->AddTab(p_LogWin,_("LogBook"), "what is this?" );
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
138 if (!OnInitODBC())
139 return FALSE;
140 //--------------------------------------------------------------------------
141 Temp0.Printf("-I-> mjDoc::OnInitView() - End - %d DSN's found",i_DSN);
142 p_MainFrame->SetStatusText(Temp0, 0);
143 wxLogMessage(Temp0);
144 return TRUE;
b5ffecfc
GT
145}
146//----------------------------------------------------------------------------------------
147bool mjDoc::OnInitODBC()
148{
b5ce269b
BJ
149 char Dsn[SQL_MAX_DSN_LENGTH + 1];
150 char DsDesc[255]; // BJO20002501 instead of 512
151 Temp0 = "";
152 i_DSN = 0; // Counter
153 int i = 0;
154 //---------------------------------------------------------------------------
155 // Initialize the ODBC Environment for Database Operations
156
157 if (SQLAllocEnv(&DbConnectInf.Henv) != SQL_SUCCESS)
158 {
159 return FALSE;
160 }
161 //---------------------------------------------------------------------------
162
163 const char sep = 3; // separator character used in string between DSN ans DsDesc
164 wxStringList s_SortDSNList, s_SortDsDescList;
165 // BJO-20000127
166 // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string.
167 // The key will be removed after sorting
168 wxString KeyString;
169 //---------------------------------------------------------------------------
170 while(GetDataSource(DbConnectInf.Henv, Dsn, sizeof(Dsn), DsDesc, sizeof(DsDesc)))
171 {
172 i_DSN++; // How many Dsn have we ?
173 KeyString.Printf("%s%c%s",Dsn, sep, DsDesc);
174 s_SortDSNList.Add(Dsn);
175 s_SortDsDescList.Add(KeyString);
176 }
177 s_SortDSNList.Sort(); //BJO
178 s_SortDsDescList.Sort(); //BJO
179
180 char ** s_SortDSN = s_SortDSNList.ListToArray(); //BJO
181 char ** s_SortDsDesc = s_SortDsDescList.ListToArray(); //BJO
182 //---------------------------------------------------------------------------
183 // Allocate n ODBC-DSN objects to hold the information
184 p_DSN = new DSN[i_DSN]; //BJO
185 for (i=0;i<i_DSN;i++)
186 {
187 KeyString = s_SortDsDesc[i];
188 KeyString = KeyString.AfterFirst(sep);
189 strcpy(s_SortDsDesc[i],KeyString.c_str());
190 (p_DSN+i)->Dsn = s_SortDSN[i];
191 (p_DSN+i)->Drv = s_SortDsDesc[i];
192 (p_DSN+i)->Usr = "";
193 (p_DSN+i)->Pas = "";
8a89af52 194 Temp0.Printf("%02d) Dsn(%s) DsDesc(%s)",i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str());
b5ce269b
BJ
195 wxLogMessage(Temp0);
196 }
197 i = 0;
198 //---------------------------------------------------------------------------
199 // Allocate n wxDatabase objects to hold the column information
200 db_Br = new BrowserDB[i_DSN];
201 for (i=0;i<i_DSN;i++)
202 {
203 (db_Br+i)->p_LogWindow = p_LogWin;
204 (db_Br+i)->ODBCSource = (p_DSN+i)->Dsn;
205 (db_Br+i)->UserName = (p_DSN+i)->Usr;
206 (db_Br+i)->Password = (p_DSN+i)->Pas;
207 (db_Br+i)->pDoc = this;
208 (db_Br+i)->i_Which = i;
209 }
210
211 if (SQLFreeEnv(&DbConnectInf.Henv) != SQL_SUCCESS) // BJO20000125
212 {
213 // Error freeing environment handle
214 }
215
216 delete [] s_SortDSN;
217 delete [] s_SortDsDesc;
218
219 //---------------------------------------------------------------------------
220 if (!i_DSN)
221 {
222 wxMessageBox(_("No Dataset names found in ODBC!\n" \
223 " Program will exit!\n\n" \
224 " Ciao"),"-E-> Fatal situation");
225 return FALSE;
226 }
227 //---------------------------------------------------------------------------
228 return TRUE;
b5ffecfc
GT
229}
230//----------------------------------------------------------------------------------------
231bool mjDoc::OnChosenDSN(int Which)
232{
b5ce269b
BJ
233 // wxLogMessage("OnChosenDSN(%d) - Begin",Which);
234 //---------------------------------------------------------------------------
235 if (p_DBTree != NULL)
236 {
237 p_TabArea->Show(FALSE); // Deactivate the Window
238 p_TabArea->RemoveTab(p_DBTree->i_ViewNr);
239 p_TabArea->Show(TRUE); // Activate the Window
240 OnChosenTbl(77,"");
241 }
242 //-------------------------
b5ffecfc 243 p_TabArea->Show(FALSE); // Deactivate the Window
b5ce269b
BJ
244 p_DBTree = new DBTree(p_TabArea, TREE_CTRL_DB,wxDefaultPosition, wxDefaultSize,
245 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
246 p_TabArea->AddTab(p_DBTree,(p_DSN+Which)->Dsn," ? ");
247 p_DBTree->i_ViewNr = p_TabArea->GetTabCount()-1;
248 p_TabArea->Show(TRUE); // Deactivate the Window
249 p_DBTree->i_Which = Which;
250 p_DBTree->s_DSN = (p_DSN+Which)->Dsn;
251 p_DBTree->i_TabArt = 0;
252 p_DBTree->pDoc = this;
253 p_DBTree->OnPopulate();
254 p_TabArea->SetActiveTab(p_DBTree->i_ViewNr);
255 //---------------------------------------------------------------------------
256 // wxLogMessage("OnChosenDSN(%d) - End",Which);
257 return TRUE;
b5ffecfc
GT
258}
259//----------------------------------------------------------------------------------------
260bool mjDoc::OnChosenTbl(int Tab,wxString Table)
261{
b5ce269b
BJ
262 // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str());
263 //-------------------------
264 if (p_DBGrid != NULL)
265 {
266 if (p_DBGrid->i_TabArt == 0)
267 {
268 p_TabArea->Show(FALSE); // Deactivate the Window
269 p_TabArea->RemoveTab(p_DBGrid->i_ViewNr);
270 p_TabArea->Show(TRUE); // Activate the Window
271 }
272 if (p_DBGrid->i_TabArt == 1)
273 {
274 p_PageArea->Show(FALSE); // Deactivate the Window
275 p_PageArea->RemoveTab(p_DBGrid->i_ViewNr);
276 p_PageArea->Show(TRUE); // Activate the Window
277 }
278 p_DBGrid = NULL;
279 delete p_DBGrid;
280 }
281 if (Tab == 77) // Delete only
282 return TRUE;
283 //-------------------------
284 if (Tab == 0) // Tabview
285 {
286 p_TabArea->Show(FALSE); // Deactivate the Window
287 p_DBGrid = new DBGrid(p_TabArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
288 wxSUNKEN_BORDER);
289 p_TabArea->AddTab(p_DBGrid, Table, "");
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);
295 p_TabArea->Show(TRUE); // Activate the Window
296 }
297 if (Tab == 1) // Pageview
298 {
299 p_PageArea->Show(FALSE); // Deactivate the Window
300 p_DBGrid = new DBGrid(p_PageArea,GRID_CTRL_DB,wxDefaultPosition, wxDefaultSize,
301 wxSUNKEN_BORDER);
302 p_PageArea->AddTab(p_DBGrid, Table, "");
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;
307 p_PageArea->Show(TRUE); // Activate the Window
308 p_DBGrid->OnTableView(Table);
309 p_PageArea->SetActiveTab(p_DBGrid->i_ViewNr);
310 }
311 p_DBGrid->i_TabArt = Tab;
312 //---*----------------------
313 return TRUE;;
b5ffecfc
GT
314}
315//----------------------------------------------------------------------------------------
316void mjDoc::OnLeer(wxString Aufrufer)
317{
b5ce269b
BJ
318