1 //----------------------------------------------------------------------------------------
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
8 // Copyright: (c) Mark Johnson
9 // Licence: wxWindows license
11 //----------------------------------------------------------------------------------------
12 //-- all #ifdefs that the whole Project needs. -------------------------------------------
13 //----------------------------------------------------------------------------------------
15 #pragma implementation
18 //----------------------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
21 //----------------------------------------------------------------------------------------
25 //----------------------------------------------------------------------------------------
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
;
38 //----------------------------------------------------------------------------------------
39 wxConfigBase
*p_ProgramCfg
; // All Config and Path information
40 wxLogTextCtrl
*p_LogBook
; // All Log messages
41 wxString LogBuf
; // String for all Logs
43 //----------------------------------------------------------------------------------------
51 p_PgmCtrl
= NULL
; // Is not active
59 s_BColour
= _T("WHEAT");
60 ft_Doc
= new wxFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT
));
63 //----------------------------------------------------------------------------------------
66 p_TabArea
->Show(FALSE
); // Deactivate the Window
67 p_PageArea
->Show(FALSE
); // Deactivate the Window
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
;
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");
83 //----------------------------------------------------------------------------------------
84 bool MainDoc::OnNewDocument()
87 //---------------------------------------------------------------------------------------
90 p_PgmCtrl
->OnPopulate();
91 //---------------------------------------------------------------------------------------
92 wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw
.Time());
96 //----------------------------------------------------------------------------------------
97 bool MainDoc::OnInitView()
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
, -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(_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 //---------------------------------------------------------------------------------------
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"), _T("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())
145 //---------------------------------------------------------------------------------------
146 Temp0
.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN
);
147 p_MainFrame
->SetStatusText(Temp0
, 0);
152 //----------------------------------------------------------------------------------------
153 bool MainDoc::OnInitODBC()
155 wxChar Dsn
[SQL_MAX_DSN_LENGTH
+ 1];
156 wxChar DsDesc
[255]; // BJO20002501 instead of 512
158 i_DSN
= 0; // Counter
160 //---------------------------------------------------------------------------------------
161 // Initialize the ODBC Environment for Database Operations
163 if (!DbConnectInf
.AllocHenv())
168 //---------------------------------------------------------------------------------------
169 const char sep
= 3; // separator character used in string between DSN ans DsDesc
170 wxStringList s_SortDSNList
, s_SortDsDescList
;
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
175 //---------------------------------------------------------------------------------------
176 while(wxDbGetDataSource(DbConnectInf
.GetHenv(), Dsn
, sizeof(Dsn
), DsDesc
, sizeof(DsDesc
)))
178 i_DSN
++; // How many Dsn have we ?
179 KeyString
.Printf(_T("%s%c%s"),Dsn
, sep
, DsDesc
);
180 s_SortDSNList
.Add(Dsn
);
181 s_SortDsDescList
.Add(KeyString
);
183 s_SortDSNList
.Sort(); //BJO
184 s_SortDsDescList
.Sort(); //BJO
186 wxChar
** s_SortDSN
= s_SortDSNList
.ListToArray(); //BJO
187 wxChar
** 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
++)
193 KeyString
= s_SortDsDesc
[i
];
194 KeyString
= KeyString
.AfterFirst(sep
);
195 wxStrcpy(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
= _T("");
199 (p_DSN
+i
)->Pas
= _T("");
200 Temp0
.Printf(_T("%02d) Dsn(%s) DsDesc(%s)"),i
,(p_DSN
+i
)->Dsn
.c_str(),(p_DSN
+i
)->Drv
.c_str());
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
++)
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
;
217 DbConnectInf
.FreeHenv();
220 delete [] s_SortDsDesc
;
221 //---------------------------------------------------------------------------------------
224 wxString message
= _("No Dataset names found in ODBC!\n");
225 message
+= _(" Program will exit!\n\n");
226 message
+= _(" Ciao");
227 wxMessageBox( message
,_("-E-> Fatal situation"));
230 //---------------------------------------------------------------------------------------
234 //----------------------------------------------------------------------------------------
235 bool MainDoc::OnChosenDSN(int Which
)
237 // wxLogMessage("OnChosenDSN(%d) - Begin",Which);
238 //---------------------------------------------------------------------------------------
239 if (p_DBTree
!= NULL
)
241 p_TabArea
->Show(FALSE
); // Deactivate the Window
242 p_TabArea
->RemoveTab(p_DBTree
->i_ViewNr
);
243 p_TabArea
->Show(TRUE
); // Activate the Window
244 OnChosenTbl(77,_T(""));
246 //-------------------------
247 p_TabArea
->Show(FALSE
); // Deactivate the Window
248 p_DBTree
= new DBTree(p_TabArea
, TREE_CTRL_DB
,wxDefaultPosition
, wxDefaultSize
,
249 wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
250 p_TabArea
->AddTab(p_DBTree
,(p_DSN
+Which
)->Dsn
,_T(" ? "));
251 p_DBTree
->i_ViewNr
= p_TabArea
->GetTabCount()-1;
252 p_TabArea
->Show(TRUE
); // Deactivate the Window
253 p_DBTree
->i_Which
= Which
;
254 p_DBTree
->s_DSN
= (p_DSN
+Which
)->Dsn
;
255 p_DBTree
->i_TabArt
= 0;
256 p_DBTree
->pDoc
= this;
257 p_DBTree
->OnPopulate();
258 p_TabArea
->SetActiveTab(p_DBTree
->i_ViewNr
);
259 //---------------------------------------------------------------------------------------
260 // wxLogMessage("OnChosenDSN(%d) - End",Which);
264 //----------------------------------------------------------------------------------------
265 bool MainDoc::OnChosenTbl(int Tab
,wxString Table
)
267 // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str());
268 //-------------------------
269 if (p_DBGrid
!= NULL
)
271 if (p_DBGrid
->i_TabArt
== 0)
273 p_TabArea
->Show(FALSE
); // Deactivate the Window
274 p_TabArea
->RemoveTab(p_DBGrid
->i_ViewNr
);
275 p_TabArea
->Show(TRUE
); // Activate the Window
277 if (p_DBGrid
->i_TabArt
== 1)
279 p_PageArea
->Show(FALSE
); // Deactivate the Window
280 p_PageArea
->RemoveTab(p_DBGrid
->i_ViewNr
);
281 p_PageArea
->Show(TRUE
); // Activate the Window
286 if (Tab
== 77) // Delete only
288 //-------------------------
289 if (Tab
== 0) // Tabview
291 p_TabArea
->Show(FALSE
); // Deactivate the Window
292 p_DBGrid
= new DBGrid(p_TabArea
,GRID_CTRL_DB
,wxDefaultPosition
, wxDefaultSize
,
294 p_TabArea
->AddTab(p_DBGrid
, Table
, _T(""));
295 p_DBGrid
->i_ViewNr
= p_TabArea
->GetTabCount()-1;
296 p_DBGrid
->pDoc
= this;
297 p_DBGrid
->db_Br
= db_Br
;
298 p_DBGrid
->OnTableView(Table
);
299 p_TabArea
->SetActiveTab(p_DBGrid
->i_ViewNr
);
300 p_TabArea
->Show(TRUE
); // Activate the Window
302 if (Tab
== 1) // Pageview
304 p_PageArea
->Show(FALSE
); // Deactivate the Window
305 p_DBGrid
= new DBGrid(p_PageArea
,GRID_CTRL_DB
,wxDefaultPosition
, wxDefaultSize
,
307 p_PageArea
->AddTab(p_DBGrid
, Table
, _T(""));
308 p_DBGrid
->i_ViewNr
= p_PageArea
->GetTabCount()-1;
309 p_DBGrid
->pDoc
= this;
310 p_DBGrid
->db_Br
= db_Br
;
311 p_DBGrid
->i_Which
= p_DBTree
->i_Which
;
312 p_PageArea
->Show(TRUE
); // Activate the Window
313 p_DBGrid
->OnTableView(Table
);
314 p_PageArea
->SetActiveTab(p_DBGrid
->i_ViewNr
);
316 p_DBGrid
->i_TabArt
= Tab
;
317 //--------------------------
321 //----------------------------------------------------------------------------------------
322 void MainDoc::OnLeer(wxString Aufrufer
)
324 // Temp0.Printf(_("\nMainDoc::OnLeer(%s) : auch diese funktion steht eines Tages zur Verfügung !"),Aufrufer.c_str());
325 Temp0
.Printf(_("\nMainDoc::OnLeer(%s) : even this function will one day be available !"),Aufrufer
.c_str());
326 wxLogMessage(Temp0
); Temp0
.Empty();
330 //----------------------------------------------------------------------------------------
331 BEGIN_EVENT_TABLE(DocSplitterWindow
, wxSplitterWindow
)
334 //----------------------------------------------------------------------------------------
335 DocSplitterWindow::DocSplitterWindow(wxWindow
*parent
, wxWindowID id
) : wxSplitterWindow(parent
, id
)
336 { // Define a constructor for my p_Splitter
338 //----------------------------------------------------------------------------------------