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 struct DbStuff 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 // ----------------------------------------------------------
66 // wxMessageBox("-I-> end Doc");
67 p_TabArea
->Show(FALSE
); // Deactivate the Window
68 p_PageArea
->Show(FALSE
); // Deactivate the Window
73 p_TabArea
= NULL
; delete p_TabArea
;
74 p_PageArea
= NULL
; delete p_PageArea
;
78 // wxMessageBox("~mjDoc");
80 //----------------------------------------------------------------------------------------
81 bool mjDoc::OnNewDocument()
84 //---------------------------------------------------------------------------------------
87 p_PgmCtrl
->OnPopulate();
88 //---------------------------------------------------------------------------------------
89 wxLogMessage(_("-I-> mjDoc::OnNewDocument() - End - Time needed : %ld ms"),sw
.Time());
92 //----------------------------------------------------------------------------------------
93 bool mjDoc::OnInitView()
95 Sash
= p_ProgramCfg
->Read("/MainFrame/Sash", 200);
96 // wxMessageBox("OnInitView() - Begin ","-I->mjDoc::OnInitView");
97 //---------------------------------------------------------------------------------------
98 // create "workplace" window
99 //---------------------------------------------------------------------------------------
100 p_TabArea
= new wxTabbedWindow(); // Init the Pointer
101 p_TabArea
->Create(p_Splitter
, -1);
102 //---------------------------------------------------------------------------------------
103 p_PgmCtrl
= new PgmCtrl(p_TabArea
, TREE_CTRL_PGM
,wxDefaultPosition
, wxDefaultSize
,
104 wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
105 p_PgmCtrl
->i_TabArt
= 0; // 0 = Tab ; 1 = Page
106 p_PgmCtrl
->i_ViewNr
= p_TabArea
->GetTabCount()-1;
107 //---------------------------------------------------------------------------------------
108 wxBitmap
*p_FolderClose
= new wxBitmap("PgmCtrl"); //, wxBITMAP_TYPE_BMP_RESOURCE); // BJO20000115
109 //---------------------------------------------------------------------------------------
110 p_TabArea
->AddTab(p_PgmCtrl
,"PgmCtrl",p_FolderClose
);
111 //---------------------------------------------------------------------------------------
112 // now create "output" window
113 //---------------------------------------------------------------------------------------
114 p_PageArea
= new wxPaggedWindow(); // Init the Pointer
115 p_PageArea
->Create(p_Splitter
, -1);
116 //---------------------------------------------------------------------------------------
117 p_LogWin
= new wxTextCtrl(p_PageArea
,-1,wxEmptyString
,
118 wxDefaultPosition
, wxDefaultSize
,wxTE_MULTILINE
);
119 p_LogWin
->SetFont(* ft_Doc
);
120 // Don't forget ! This is always : i_TabArt = 0 ; i_ViewNr = 1;
121 //---------------------------------------------------------------------------------------
122 p_LogBook
= new wxLogTextCtrl(p_LogWin
); // make p_LogWin the LogBook
123 p_LogBook
->SetActiveTarget(p_LogBook
);
124 p_LogBook
->SetTimestamp( NULL
);
125 //---------------------------------------------------------------------------------------
126 p_PageArea
->AddTab(p_LogWin
,_("LogBook"), "what is this?" );
127 i_TabNr
= p_TabArea
->GetTabCount()-1; // Add one when a new AddTab is done;
128 i_PageNr
= p_PageArea
->GetTabCount()-1; // Add one when a new AddTab is done;
129 //---------------------------------------------------------------------------------------
130 p_PgmCtrl
->pDoc
= this;
131 p_TabArea
->SetActiveTab(i_PageNr
);
132 //---------------------------------------------------------------------------------------
133 p_Splitter
->Initialize(p_TabArea
);
134 p_Splitter
->SplitHorizontally(p_TabArea
,p_PageArea
,Sash
);
135 //---------------------------------------------------------------------------------------
138 //---------------------------------------------------------------------------------------
139 Temp0
.Printf(_("-I-> mjDoc::OnInitView() - End - %d DSN's found"),i_DSN
);
140 p_MainFrame
->SetStatusText(Temp0
, 0);
144 //----------------------------------------------------------------------------------------
145 bool mjDoc::OnInitODBC()
147 char Dsn
[SQL_MAX_DSN_LENGTH
+ 1];
148 char DsDesc
[255]; // BJO20002501 instead of 512
150 i_DSN
= 0; // Counter
152 //---------------------------------------------------------------------------------------
153 // Initialize the ODBC Environment for Database Operations
155 if (SQLAllocEnv(&DbConnectInf
.Henv
) != SQL_SUCCESS
)
159 //---------------------------------------------------------------------------------------
160 const char sep
= 3; // separator character used in string between DSN ans DsDesc
161 wxStringList s_SortDSNList
, s_SortDsDescList
;
163 // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string.
164 // The key will be removed after sorting
166 //---------------------------------------------------------------------------------------
167 while(GetDataSource(DbConnectInf
.Henv
, Dsn
, sizeof(Dsn
), DsDesc
, sizeof(DsDesc
)))
169 i_DSN
++; // How many Dsn have we ?
170 KeyString
.Printf("%s%c%s",Dsn
, sep
, DsDesc
);
171 s_SortDSNList
.Add(Dsn
);
172 s_SortDsDescList
.Add(KeyString
);
174 s_SortDSNList
.Sort(); //BJO
175 s_SortDsDescList
.Sort(); //BJO
177 char ** s_SortDSN
= s_SortDSNList
.ListToArray(); //BJO
178 char ** s_SortDsDesc
= s_SortDsDescList
.ListToArray(); //BJO
179 //---------------------------------------------------------------------------------------
180 // Allocate n ODBC-DSN objects to hold the information
181 p_DSN
= new DSN
[i_DSN
]; //BJO
182 for (i
=0;i
<i_DSN
;i
++)
184 KeyString
= s_SortDsDesc
[i
];
185 KeyString
= KeyString
.AfterFirst(sep
);
186 strcpy(s_SortDsDesc
[i
],KeyString
.c_str());
187 (p_DSN
+i
)->Dsn
= s_SortDSN
[i
];
188 (p_DSN
+i
)->Drv
= s_SortDsDesc
[i
];
191 Temp0
.Printf("%02d) Dsn(%s) DsDesc(%s)",i
,(p_DSN
+i
)->Dsn
.c_str(),(p_DSN
+i
)->Drv
.c_str());
195 //---------------------------------------------------------------------------------------
196 // Allocate n wxDatabase objects to hold the column information
197 db_Br
= new BrowserDB
[i_DSN
];
198 for (i
=0;i
<i_DSN
;i
++)
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
;
207 if (SQLFreeEnv(&DbConnectInf
.Henv
) != SQL_SUCCESS
) // BJO20000125
209 // Error freeing environment handle
212 delete [] s_SortDsDesc
;
213 //---------------------------------------------------------------------------------------
216 wxMessageBox(_("No Dataset names found in ODBC!\n" \
217 " Program will exit!\n\n" \
218 " Ciao"),"-E-> Fatal situation");
221 //---------------------------------------------------------------------------------------
224 //----------------------------------------------------------------------------------------
225 bool mjDoc::OnChosenDSN(int Which
)
227 // wxLogMessage("OnChosenDSN(%d) - Begin",Which);
228 //---------------------------------------------------------------------------------------
229 if (p_DBTree
!= NULL
)
231 p_TabArea
->Show(FALSE
); // Deactivate the Window
232 p_TabArea
->RemoveTab(p_DBTree
->i_ViewNr
);
233 p_TabArea
->Show(TRUE
); // Activate the Window
236 //-------------------------
237 p_TabArea
->Show(FALSE
); // Deactivate the Window
238 p_DBTree
= new DBTree(p_TabArea
, TREE_CTRL_DB
,wxDefaultPosition
, wxDefaultSize
,
239 wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
240 p_TabArea
->AddTab(p_DBTree
,(p_DSN
+Which
)->Dsn
," ? ");
241 p_DBTree
->i_ViewNr
= p_TabArea
->GetTabCount()-1;
242 p_TabArea
->Show(TRUE
); // Deactivate the Window
243 p_DBTree
->i_Which
= Which
;
244 p_DBTree
->s_DSN
= (p_DSN
+Which
)->Dsn
;
245 p_DBTree
->i_TabArt
= 0;
246 p_DBTree
->pDoc
= this;
247 p_DBTree
->OnPopulate();
248 p_TabArea
->SetActiveTab(p_DBTree
->i_ViewNr
);
249 //---------------------------------------------------------------------------------------
250 // wxLogMessage("OnChosenDSN(%d) - End",Which);
253 //----------------------------------------------------------------------------------------
254 bool mjDoc::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
, "");
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
, "");
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 //--------------------------
309 //----------------------------------------------------------------------------------------
310 void mjDoc::OnLeer(wxString Aufrufer
)
312 // Temp0.Printf(_("\nmjDoc::OnLeer(%s) : auch diese funktion steht eines Tages zur Verfügung !"),Aufrufer.c_str());
313 Temp0
.Printf(_("\nmjDoc::OnLeer(%s) : even this function will one day be available !"),Aufrufer
.c_str());
314 wxLogMessage(Temp0
); Temp0
.Empty();
317 //----------------------------------------------------------------------------------------
318 BEGIN_EVENT_TABLE(DocSplitterWindow
, wxSplitterWindow
)
320 //----------------------------------------------------------------------------------------
321 DocSplitterWindow::DocSplitterWindow(wxWindow
*parent
, wxWindowID id
) : wxSplitterWindow(parent
, id
)
322 { // Define a constructor for my p_Splitter
324 //----------------------------------------------------------------------------------------