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 //----------------------------------------------------------------------------------------
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
15 //----------------------------------------------------------------------------------------
19 //----------------------------------------------------------------------------------------
23 //----------------------------------------------------------------------------------------
24 //-- all #includes that every .cpp needs ----19990807.mj10777 ----------------
25 //----------------------------------------------------------------------------------------
26 #include "std.h" // sorgsam Pflegen !
27 //----------------------------------------------------------------------------------------
28 //-- Some Global Vars for all Files (extern in ?.h needed) -------------------------------
29 // Global structure for holding ODBC connection information
30 extern wxDbConnectInf DbConnectInf
;
32 //----------------------------------------------------------------------------------------
33 wxConfigBase
*p_ProgramCfg
; // All Config and Path information
34 wxLogTextCtrl
*p_LogBook
; // All Log messages
35 wxString LogBuf
; // String for all Logs
37 //----------------------------------------------------------------------------------------
45 p_PgmCtrl
= NULL
; // Is not active
53 s_BColour
= _T("WHEAT");
54 ft_Doc
= new wxFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT
));
57 //----------------------------------------------------------------------------------------
60 p_TabArea
->Show(false); // Deactivate the Window
61 p_PageArea
->Show(false); // Deactivate the Window
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
;
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");
77 //----------------------------------------------------------------------------------------
78 bool MainDoc::OnNewDocument()
81 //---------------------------------------------------------------------------------------
84 p_PgmCtrl
->OnPopulate();
85 //---------------------------------------------------------------------------------------
86 wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw
.Time());
90 //----------------------------------------------------------------------------------------
91 bool MainDoc::OnInitView()
93 Sash
= p_ProgramCfg
->Read(_T("/MainFrame/Sash"), 200);
94 // wxMessageBox("OnInitView() - Begin ","-I->MainDoc::OnInitView");
95 //---------------------------------------------------------------------------------------
96 // create "workplace" window
97 //---------------------------------------------------------------------------------------
98 p_TabArea
= new wxTabbedWindow(); // Init the Pointer
99 p_TabArea
->Create(p_Splitter
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxFULL_REPAINT_ON_RESIZE
);
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 //---------------------------------------------------------------------------------------
106 wxBitmap
*p_FolderClose
= new wxBitmap(_T("PgmCtrl")); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115
107 //---------------------------------------------------------------------------------------
108 p_TabArea
->AddTab(p_PgmCtrl
,_T("PgmCtrl"),p_FolderClose
);
109 delete p_FolderClose
; // Memory leak
110 p_FolderClose
= NULL
;
111 wxUnusedVar(p_FolderClose
);
112 //---------------------------------------------------------------------------------------
113 // now create "output" window
114 //---------------------------------------------------------------------------------------
115 p_PageArea
= new wxPagedWindow(); // Init the Pointer
116 p_PageArea
->Create(p_Splitter
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxFULL_REPAINT_ON_RESIZE
);
117 //---------------------------------------------------------------------------------------
118 p_LogWin
= new wxTextCtrl(p_PageArea
,wxID_ANY
,wxEmptyString
,
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 //---------------------------------------------------------------------------------------
127 p_PageArea
->AddTab(p_LogWin
,_("LogBook"), _T("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 // if (!OnInitODBC())
140 //---------------------------------------------------------------------------------------
142 Temp0
.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN
);
143 p_MainFrame
->SetStatusText(Temp0
, 0);
145 #endif // wxUSE_STATUSBAR
149 //----------------------------------------------------------------------------------------
150 bool MainDoc::OnInitODBC()
152 wxChar Dsn
[SQL_MAX_DSN_LENGTH
+1];
153 wxChar DsDesc
[254+1]; // BJO20002501 instead of 512
154 Temp0
= wxEmptyString
;
155 i_DSN
= 0; // Counter
157 //---------------------------------------------------------------------------------------
158 // Initialize the ODBC Environment for Database Operations
160 if (!DbConnectInf
.AllocHenv())
165 //---------------------------------------------------------------------------------------
166 const wxChar sep
= 3; // separator character used in string between DSN and DsDesc
167 wxSortedArrayString s_SortDSNList
, s_SortDsDescList
;
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
172 //---------------------------------------------------------------------------------------
173 while (wxDbGetDataSource(DbConnectInf
.GetHenv(), Dsn
, SQL_MAX_DSN_LENGTH
, DsDesc
, 254))
175 i_DSN
++; // How many Dsn have we ?
176 KeyString
.Printf(_T("%s%c%s"),Dsn
, sep
, DsDesc
);
177 s_SortDSNList
.Add(Dsn
);
178 s_SortDsDescList
.Add(KeyString
);
181 //---------------------------------------------------------------------------------------
182 // Allocate n ODBC-DSN objects to hold the information
183 // Allocate n wxDatabase objects to hold the column information
184 p_DSN
= new DSN
[i_DSN
]; //BJO
185 db_Br
= new BrowserDB
[i_DSN
];
186 for (i
=0;i
<i_DSN
;i
++)
188 KeyString
= s_SortDsDescList
[i
];
189 KeyString
= KeyString
.AfterFirst(sep
);
192 (p_DSN
+i
)->Dsn
= s_SortDSNList
[i
];
193 (p_DSN
+i
)->Drv
= KeyString
;
194 (p_DSN
+i
)->Usr
= wxEmptyString
;
195 (p_DSN
+i
)->Pas
= wxEmptyString
;
196 Temp0
.Printf(_T("%02d) Dsn(%s) DsDesc(%s)"),i
,(p_DSN
+i
)->Dsn
.c_str(),(p_DSN
+i
)->Drv
.c_str());
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
;
208 DbConnectInf
.FreeHenv();
210 //---------------------------------------------------------------------------------------
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"));
219 //---------------------------------------------------------------------------------------
223 //----------------------------------------------------------------------------------------
224 bool MainDoc::OnChosenDSN(int Which
)
226 // wxLogMessage("OnChosenDSN(%d) - Begin",Which);
227 //---------------------------------------------------------------------------------------
228 if (p_DBTree
!= NULL
)
230 p_TabArea
->Show(false); // Deactivate the Window
231 p_TabArea
->RemoveTab(p_DBTree
->i_ViewNr
);
232 p_TabArea
->Show(true); // Activate the Window
233 OnChosenTbl(77,wxEmptyString
);
235 //-------------------------
236 p_TabArea
->Show(false); // Deactivate the Window
237 p_DBTree
= new DBTree(p_TabArea
, TREE_CTRL_DB
,wxDefaultPosition
, wxDefaultSize
,
238 wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
239 p_TabArea
->AddTab(p_DBTree
,(p_DSN
+Which
)->Dsn
,_T(" ? "));
240 p_DBTree
->i_ViewNr
= p_TabArea
->GetTabCount()-1;
241 p_TabArea
->Show(true); // Deactivate the Window
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);
253 //----------------------------------------------------------------------------------------
254 bool MainDoc::OnChosenTbl(int Tab
,wxString Table
)
256 // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str());
257 //-------------------------
258 if (p_DBGrid
!= NULL
)
260 if (p_DBGrid
->i_TabArt
== 0)
262 p_TabArea
->Show(false); // Deactivate the Window
263 p_TabArea
->RemoveTab(p_DBGrid
->i_ViewNr
);
264 p_TabArea
->Show(true); // Activate the Window
266 if (p_DBGrid
->i_TabArt
== 1)
268 p_PageArea
->Show(false); // Deactivate the Window
269 p_PageArea
->RemoveTab(p_DBGrid
->i_ViewNr
);
270 p_PageArea
->Show(true); // Activate the Window
275 if (Tab
== 77) // Delete only
277 //-------------------------
278 if (Tab
== 0) // Tabview
280 p_TabArea
->Show(false); // Deactivate the Window
281 p_DBGrid
= new DBGrid(p_TabArea
,GRID_CTRL_DB
,wxDefaultPosition
, wxDefaultSize
,
283 p_TabArea
->AddTab(p_DBGrid
, Table
, wxEmptyString
);
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
);
289 p_TabArea
->Show(true); // Activate the Window
291 if (Tab
== 1) // Pageview
293 p_PageArea
->Show(false); // Deactivate the Window
294 p_DBGrid
= new DBGrid(p_PageArea
,GRID_CTRL_DB
,wxDefaultPosition
, wxDefaultSize
,
296 p_PageArea
->AddTab(p_DBGrid
, Table
, wxEmptyString
);
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
;
301 p_PageArea
->Show(true); // Activate the Window
302 p_DBGrid
->OnTableView(Table
);
303 p_PageArea
->SetActiveTab(p_DBGrid
->i_ViewNr
);
305 p_DBGrid
->i_TabArt
= Tab
;
306 //--------------------------
310 //----------------------------------------------------------------------------------------
311 void MainDoc::OnLeer(wxString Aufrufer
)
313 // Temp0.Printf(_("\nMainDoc::OnLeer(%s) : auch diese funktion steht eines Tages zur Verfügung !"),Aufrufer.c_str());
314 Temp0
.Printf(_("\nMainDoc::OnLeer(%s) : even this function will one day be available !"),Aufrufer
.c_str());
315 wxLogMessage(Temp0
); Temp0
.Empty();
319 //----------------------------------------------------------------------------------------
320 BEGIN_EVENT_TABLE(DocSplitterWindow
, wxSplitterWindow
)
323 //----------------------------------------------------------------------------------------
324 DocSplitterWindow::DocSplitterWindow(wxWindow
*parent
, wxWindowID id
) : wxSplitterWindow(parent
, id
)
325 { // Define a constructor for my p_Splitter
327 //----------------------------------------------------------------------------------------