1 //----------------------------------------------------------------------------------------
3 // Purpose: Holds information for DBBrowser - (a do-it-yourself document)
4 // Author: Mark Johnson, mj10777@gmx.net
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 wxDbConnectInf DbConnectInf
;
37 //----------------------------------------------------------------------------------------
38 wxConfigBase
*p_ProgramCfg
; // All Config and Path information
39 wxLogTextCtrl
*p_LogBook
; // All Log messages
40 wxString LogBuf
; // String for all Logs
41 //----------------------------------------------------------------------------------------
49 p_PgmCtrl
= NULL
; // Is not active
58 ft_Doc
= new wxFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
60 //----------------------------------------------------------------------------------------
63 // ----------------------------------------------------------
64 // -E-> The Tree Controls take to long to close : Why ??
65 // ----------------------------------------------------------
68 p_TabArea
->Show(FALSE
); // Deactivate the Window
69 p_PageArea
->Show(FALSE
); // Deactivate the Window
74 p_TabArea
= NULL
; delete p_TabArea
;
75 p_PageArea
= NULL
; delete p_PageArea
;
79 // wxMessageBox("~MainDoc");
81 //----------------------------------------------------------------------------------------
82 bool MainDoc::OnNewDocument()
85 //---------------------------------------------------------------------------------------
88 p_PgmCtrl
->OnPopulate();
89 //---------------------------------------------------------------------------------------
90 wxLogMessage(_("-I-> MainDoc::OnNewDocument() - End - Time needed : %ld ms"),sw
.Time());
93 //----------------------------------------------------------------------------------------
94 bool MainDoc::OnInitView()
96 Sash
= p_ProgramCfg
->Read("/MainFrame/Sash", 200);
97 // wxMessageBox("OnInitView() - Begin ","-I->MainDoc::OnInitView");
98 //---------------------------------------------------------------------------------------
99 // create "workplace" window
100 //---------------------------------------------------------------------------------------
101 p_TabArea
= new wxTabbedWindow(); // Init the Pointer
102 p_TabArea
->Create(p_Splitter
, -1);
103 //---------------------------------------------------------------------------------------
104 p_PgmCtrl
= new PgmCtrl(p_TabArea
, TREE_CTRL_PGM
,wxDefaultPosition
, wxDefaultSize
,
105 wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
106 p_PgmCtrl
->i_TabArt
= 0; // 0 = Tab ; 1 = Page
107 p_PgmCtrl
->i_ViewNr
= p_TabArea
->GetTabCount()-1;
108 //---------------------------------------------------------------------------------------
109 wxBitmap
*p_FolderClose
= new wxBitmap("PgmCtrl"); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115
110 //---------------------------------------------------------------------------------------
111 p_TabArea
->AddTab(p_PgmCtrl
,"PgmCtrl",p_FolderClose
);
112 delete p_FolderClose
; // Memory leak
113 p_FolderClose
= NULL
;
114 //---------------------------------------------------------------------------------------
115 // now create "output" window
116 //---------------------------------------------------------------------------------------
117 p_PageArea
= new wxPaggedWindow(); // Init the Pointer
118 p_PageArea
->Create(p_Splitter
, -1);
119 //---------------------------------------------------------------------------------------
120 p_LogWin
= new wxTextCtrl(p_PageArea
,-1,wxEmptyString
,
121 wxDefaultPosition
, wxDefaultSize
,wxTE_MULTILINE
);
122 p_LogWin
->SetFont(* ft_Doc
);
123 // Don't forget ! This is always : i_TabArt = 0 ; i_ViewNr = 1;
124 //---------------------------------------------------------------------------------------
125 p_LogBook
= new wxLogTextCtrl(p_LogWin
); // make p_LogWin the LogBook
126 p_LogBook
->SetActiveTarget(p_LogBook
);
127 p_LogBook
->SetTimestamp( NULL
);
128 //---------------------------------------------------------------------------------------
129 p_PageArea
->AddTab(p_LogWin
,_("LogBook"), "what is this?" );
130 i_TabNr
= p_TabArea
->GetTabCount()-1; // Add one when a new AddTab is done;
131 i_PageNr
= p_PageArea
->GetTabCount()-1; // Add one when a new AddTab is done;
132 //---------------------------------------------------------------------------------------
133 p_PgmCtrl
->pDoc
= this;
134 p_TabArea
->SetActiveTab(i_PageNr
);
135 //---------------------------------------------------------------------------------------
136 p_Splitter
->Initialize(p_TabArea
);
137 p_Splitter
->SplitHorizontally(p_TabArea
,p_PageArea
,Sash
);
138 //---------------------------------------------------------------------------------------
139 // if (!OnInitODBC())
142 //---------------------------------------------------------------------------------------
143 Temp0
.Printf(_("-I-> MainDoc::OnInitView() - End - %d DSN's found"),i_DSN
);
144 p_MainFrame
->SetStatusText(Temp0
, 0);
148 //----------------------------------------------------------------------------------------
149 bool MainDoc::OnInitODBC()
151 char Dsn
[SQL_MAX_DSN_LENGTH
+ 1];
152 char DsDesc
[255]; // BJO20002501 instead of 512
154 i_DSN
= 0; // Counter
156 //---------------------------------------------------------------------------------------
157 // Initialize the ODBC Environment for Database Operations
159 if (SQLAllocEnv(&DbConnectInf
.Henv
) != SQL_SUCCESS
)
163 //---------------------------------------------------------------------------------------
164 const char sep
= 3; // separator character used in string between DSN ans DsDesc
165 wxStringList s_SortDSNList
, s_SortDsDescList
;
167 // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string.
168 // The key will be removed after sorting
170 //---------------------------------------------------------------------------------------
171 while(wxDbGetDataSource(DbConnectInf
.Henv
, Dsn
, sizeof(Dsn
), DsDesc
, sizeof(DsDesc
)))
173 i_DSN
++; // How many Dsn have we ?
174 KeyString
.Printf("%s%c%s",Dsn
, sep
, DsDesc
);
175 s_SortDSNList
.Add(Dsn
);
176 s_SortDsDescList
.Add(KeyString
);
178 s_SortDSNList
.Sort(); //BJO
179 s_SortDsDescList
.Sort(); //BJO
181 char ** s_SortDSN
= s_SortDSNList
.ListToArray(); //BJO
182 char ** s_SortDsDesc
= s_SortDsDescList
.ListToArray(); //BJO
183 //---------------------------------------------------------------------------------------
184 // Allocate n ODBC-DSN objects to hold the information
185 p_DSN
= new DSN
[i_DSN
]; //BJO
186 for (i
=0;i
<i_DSN
;i
++)
188 KeyString
= s_SortDsDesc
[i
];
189 KeyString
= KeyString
.AfterFirst(sep
);
190 strcpy(s_SortDsDesc
[i
],KeyString
.c_str());
191 (p_DSN
+i
)->Dsn
= s_SortDSN
[i
];
192 (p_DSN
+i
)->Drv
= s_SortDsDesc
[i
];
195 Temp0
.Printf("%02d) Dsn(%s) DsDesc(%s)",i
,(p_DSN
+i
)->Dsn
.c_str(),(p_DSN
+i
)->Drv
.c_str());
199 //---------------------------------------------------------------------------------------
200 // Allocate n wxDatabase objects to hold the column information
201 db_Br
= new BrowserDB
[i_DSN
];
202 for (i
=0;i
<i_DSN
;i
++)
204 (db_Br
+i
)->p_LogWindow
= p_LogWin
;
205 (db_Br
+i
)->ODBCSource
= (p_DSN
+i
)->Dsn
;
206 (db_Br
+i
)->UserName
= (p_DSN
+i
)->Usr
;
207 (db_Br
+i
)->Password
= (p_DSN
+i
)->Pas
;
208 (db_Br
+i
)->pDoc
= this;
209 (db_Br
+i
)->i_Which
= i
;
211 if (SQLFreeEnv(DbConnectInf
.Henv
) != SQL_SUCCESS
) // BJO20000125 / MJ10777.20000309 : no &
213 // Error freeing environment handle
216 delete [] s_SortDsDesc
;
217 //---------------------------------------------------------------------------------------
220 wxMessageBox(_("No Dataset names found in ODBC!\n" \
221 " Program will exit!\n\n" \
222 " Ciao"),"-E-> Fatal situation");
225 //---------------------------------------------------------------------------------------
228 //----------------------------------------------------------------------------------------
229 bool MainDoc::OnChosenDSN(int Which
)
231 // wxLogMessage("OnChosenDSN(%d) - Begin",Which);
232 //---------------------------------------------------------------------------------------
233 if (p_DBTree
!= NULL
)
235 p_TabArea
->Show(FALSE
); // Deactivate the Window
236 p_TabArea
->RemoveTab(p_DBTree
->i_ViewNr
);
237 p_TabArea
->Show(TRUE
); // Activate the Window
240 //-------------------------
241 p_TabArea
->Show(FALSE
); // Deactivate the Window
242 p_DBTree
= new DBTree(p_TabArea
, TREE_CTRL_DB
,wxDefaultPosition
, wxDefaultSize
,
243 wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
244 p_TabArea
->AddTab(p_DBTree
,(p_DSN
+Which
)->Dsn
," ? ");
245 p_DBTree
->i_ViewNr
= p_TabArea
->GetTabCount()-1;
246 p_TabArea
->Show(TRUE
); // Deactivate the Window
247 p_DBTree
->i_Which
= Which
;
248 p_DBTree
->s_DSN
= (p_DSN
+Which
)->Dsn
;
249 p_DBTree
->i_TabArt
= 0;
250 p_DBTree
->pDoc
= this;
251 p_DBTree
->OnPopulate();
252 p_TabArea
->SetActiveTab(p_DBTree
->i_ViewNr
);
253 //---------------------------------------------------------------------------------------
254 // wxLogMessage("OnChosenDSN(%d) - End",Which);
257 //----------------------------------------------------------------------------------------
258 bool MainDoc::OnChosenTbl(int Tab
,wxString Table
)
260 // wxLogMessage("OnChosenTbl(%d,%s)",Tab,Table.c_str());
261 //-------------------------
262 if (p_DBGrid
!= NULL
)
264 if (p_DBGrid
->i_TabArt
== 0)
266 p_TabArea
->Show(FALSE
); // Deactivate the Window
267 p_TabArea
->RemoveTab(p_DBGrid
->i_ViewNr
);
268 p_TabArea
->Show(TRUE
); // Activate the Window
270 if (p_DBGrid
->i_TabArt
== 1)
272 p_PageArea
->Show(FALSE
); // Deactivate the Window
273 p_PageArea
->RemoveTab(p_DBGrid
->i_ViewNr
);
274 p_PageArea
->Show(TRUE
); // Activate the Window
279 if (Tab
== 77) // Delete only
281 //-------------------------
282 if (Tab
== 0) // Tabview
284 p_TabArea
->Show(FALSE
); // Deactivate the Window
285 p_DBGrid
= new DBGrid(p_TabArea
,GRID_CTRL_DB
,wxDefaultPosition
, wxDefaultSize
,
287 p_TabArea
->AddTab(p_DBGrid
, Table
, "");
288 p_DBGrid
->i_ViewNr
= p_TabArea
->GetTabCount()-1;
289 p_DBGrid
->pDoc
= this;
290 p_DBGrid
->db_Br
= db_Br
;
291 p_DBGrid
->OnTableView(Table
);
292 p_TabArea
->SetActiveTab(p_DBGrid
->i_ViewNr
);
293 p_TabArea
->Show(TRUE
); // Activate the Window
295 if (Tab
== 1) // Pageview
297 p_PageArea
->Show(FALSE
); // Deactivate the Window
298 p_DBGrid
= new DBGrid(p_PageArea
,GRID_CTRL_DB
,wxDefaultPosition
, wxDefaultSize
,
300 p_PageArea
->AddTab(p_DBGrid
, Table
, "");
301 p_DBGrid
->i_ViewNr
= p_PageArea
->GetTabCount()-1;
302 p_DBGrid
->pDoc
= this;
303 p_DBGrid
->db_Br
= db_Br
;
304 p_DBGrid
->i_Which
= p_DBTree
->i_Which
;
305 p_PageArea
->Show(TRUE
); // Activate the Window
306 p_DBGrid
->OnTableView(Table
);
307 p_PageArea
->SetActiveTab(p_DBGrid
->i_ViewNr
);
309 p_DBGrid
->i_TabArt
= Tab
;
310 //--------------------------
313 //----------------------------------------------------------------------------------------
314 void MainDoc::OnLeer(wxString Aufrufer
)
316 // Temp0.Printf(_("\nMainDoc::OnLeer(%s) : auch diese funktion steht eines Tages zur Verfügung !"),Aufrufer.c_str());
317 Temp0
.Printf(_("\nMainDoc::OnLeer(%s) : even this function will one day be available !"),Aufrufer
.c_str());
318 wxLogMessage(Temp0
); Temp0
.Empty();
321 //----------------------------------------------------------------------------------------
322 BEGIN_EVENT_TABLE(DocSplitterWindow
, wxSplitterWindow
)
324 //----------------------------------------------------------------------------------------
325 DocSplitterWindow::DocSplitterWindow(wxWindow
*parent
, wxWindowID id
) : wxSplitterWindow(parent
, id
)
326 { // Define a constructor for my p_Splitter
328 //----------------------------------------------------------------------------------------