]>
Commit | Line | Data |
---|---|---|
b5ffecfc GT |
1 | //--------------------------------------------------------------------------- |
2 | // Name: DBGrid.cpp | |
3 | // Purpose: wxGrid sample | |
4 | // Author: Mark Johnson | |
5 | // Modified by: 19990929.mj10777 a reuseable DBGrid | |
6 | // Created: 19990929 | |
b5ffecfc GT |
7 | // Copyright: (c) |
8 | // Licence: wxWindows license | |
c09d434d | 9 | // RCS-ID: $Id$ |
b5ffecfc GT |
10 | //--------------------------------------------------------------------------- |
11 | //-- all #ifdefs that the whole Project needs. ------------------------------ | |
12 | //--------------------------------------------------------------------------- | |
13 | #ifdef __GNUG__ | |
14 | #pragma implementation | |
15 | #pragma interface | |
16 | #endif | |
17 | //--------------------------------------------------------------------------- | |
18 | // For compilers that support precompilation, includes "wx/wx.h". | |
19 | #include "wx/wxprec.h" | |
20 | //--------------------------------------------------------------------------- | |
21 | #ifdef __BORLANDC__ | |
22 | #pragma hdrstop | |
23 | #endif | |
24 | //--------------------------------------------------------------------------- | |
25 | #ifndef WX_PRECOMP | |
26 | #include "wx/wx.h" | |
27 | #endif | |
28 | //--------------------------------------------------------------------------- | |
29 | //-- all #includes that every .cpp needs --- 19990807.mj10777 --- | |
30 | //--------------------------------------------------------------------------- | |
31 | #include "std.h" // sorgsam Pflegen ! | |
32 | //--------------------------------------------------------------------------- | |
33 | BEGIN_EVENT_TABLE(DBGrid, wxGrid) | |
b5ce269b BJ |
34 | EVT_MOTION (DBGrid::OnMouseMove) |
35 | // DBGrid | |
36 | EVT_GRID_LABEL_LEFT_CLICK( DBGrid::OnLabelLeftClick ) | |
37 | EVT_GRID_LABEL_RIGHT_CLICK( DBGrid::OnLabelRightClick ) | |
38 | EVT_GRID_LABEL_LEFT_DCLICK( DBGrid::OnLabelLeftDClick ) | |
39 | EVT_GRID_LABEL_RIGHT_DCLICK( DBGrid::OnLabelRightDClick ) | |
40 | EVT_GRID_CELL_LEFT_CLICK( DBGrid::OnCellLeftClick ) | |
41 | EVT_GRID_CELL_RIGHT_CLICK( DBGrid::OnCellRightClick ) | |
42 | EVT_GRID_CELL_LEFT_DCLICK( DBGrid::OnCellLeftDClick ) | |
43 | EVT_GRID_CELL_RIGHT_DCLICK( DBGrid::OnCellRightDClick ) | |
44 | EVT_GRID_ROW_SIZE( DBGrid::OnRowSize ) | |
45 | // EVT_GRID_COL_SIZE( DBGrid::OnColSize ) | |
46 | EVT_GRID_RANGE_SELECT( DBGrid::OnRangeSelected ) | |
47 | EVT_GRID_CELL_CHANGE( DBGrid::OnCellChange ) | |
48 | EVT_MENU(GRID_EDIT,DBGrid::OnModusEdit) | |
49 | EVT_MENU(GRID_BROWSE,DBGrid::OnModusBrowse) | |
50 | END_EVENT_TABLE() | |
51 | //--------------------------------------------------------------------------- | |
52 | // wxListCtrl(parent, id, pos, size, style) | |
53 | // wxGrid(parent,-1,wxPoint( 0, 0 ), wxSize( 400, 300 ) ); | |
54 | //--------------------------------------------------------------------------- | |
55 | // DBGrid | |
56 | //--------------------------------------------------------------------------- | |
57 | // DBGrid::DBGrid(wxWindow *parent, const wxWindowID id,const wxPoint& pos,const wxSize& size): | |
58 | // wxGrid(parent, id, pos, size) | |
59 | DBGrid::DBGrid(wxWindow *parent, const wxWindowID id,const wxPoint& pos,const wxSize& size, long style): | |
60 | wxGrid(parent, id, pos, size, style) | |
b5ffecfc | 61 | { |
b3630c4f BJ |
62 | //f_Temp = new wxFont(10,wxSWISS,wxNORMAL,wxBOLD,FALSE,"Comic Sans MS"); |
63 | //wxPanel::SetFont(* f_Temp); | |
b5ce269b BJ |
64 | b_EditModus = TRUE; |
65 | //---------------------------------------------------------------------------------------------------------------------------- | |
66 | popupMenu1 = new wxMenu(""); | |
67 | popupMenu1->Append(GRID_EDIT, _("Edit Modus")); | |
68 | popupMenu2 = new wxMenu(""); | |
69 | popupMenu2->Append(GRID_BROWSE, _("Browse Modus")); | |
b5ffecfc GT |
70 | } |
71 | //--------------------------------------------------------------------------- | |
72 | DBGrid::~DBGrid() | |
73 | { | |
74 | } | |
75 | //--------------------------------------------------------------------------- | |
76 | int DBGrid::OnTableView(wxString Table) | |
77 | { | |
b5ce269b BJ |
78 | //--------------------------------------------------------------------------- |
79 | int i=0,x,y,z, ValidTable=0; | |
80 | wxString Temp0; | |
b3630c4f BJ |
81 | //SetLabelFont(* f_Temp); |
82 | ||
83 | wxBeginBusyCursor(); | |
b5ce269b BJ |
84 | //--------------------------------------------------------------------------- |
85 | ct_BrowserDB = (db_Br+i_Which)->ct_BrowserDB; // Get the DSN Pointer | |
86 | //---------------------------------------------------------------------------- | |
87 | if (ct_BrowserDB) // Valid pointer (!= NULL) ? | |
88 | { // Pointer is Valid, use the wxDatabase Information | |
89 | for (x=0;x<ct_BrowserDB->numTables;x++) // go through the Tables | |
90 | { | |
91 | if (!wxStrcmp((ct_BrowserDB->pTableInf+x)->tableName,Table)) // is this our Table ? | |
92 | { // Yes, the Data of this Table shall be put into the Grid | |
93 | ValidTable = x; // Save the Tablenumber | |
94 | (db_Br+i_Which)->OnSelect(Table,FALSE); // Select * from "table" | |
95 | // Set the local Pointer to the Column Information we are going to use | |
96 | (db_Br+i_Which)->cl_BrowserDB = (ct_BrowserDB->pTableInf+x)->pColInf; | |
97 | if ((ct_BrowserDB->pTableInf+x)->pColInf) // Valid pointer (!= NULL) ? | |
98 | { // Pointer is Valid, Column Informationen sind Vorhanden | |
99 | i = (db_Br+i_Which)->i_Records; // How many Records are there | |
100 | (db_Br+i_Which)->i_Which = ValidTable; // Still used ???? mj10777 | |
101 | if (i == 0) // If the Table is empty, then show one empty row | |
102 | i++; | |
103 | CreateGrid(i,(ct_BrowserDB->pTableInf+x)->numCols); // Records , Columns | |
104 | for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) // Loop through the Fields | |
105 | { // The Field / Column name is used here as Row Titel | |
106 | SetColLabelValue(y,((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName); | |
107 | SetColSize(y,95); | |
108 | } // for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) | |
109 | SetColSize(((ct_BrowserDB->pTableInf+x)->numCols-1),120); // Make the last Column Wider | |
110 | // The Grid has been created, now fill it | |
111 | for (z=0;z<(db_Br+i_Which)->i_Records;z++) // Loop through the Records | |
112 | { | |
113 | Temp0.Printf("%06d",z+1); SetRowLabelValue(z,Temp0); // Set Row Lable Value | |
114 | (db_Br+i_Which)->OnGetNext((ct_BrowserDB->pTableInf+ValidTable)->numCols,FALSE); | |
115 | for (y=0;y<(ct_BrowserDB->pTableInf+ValidTable)->numCols;y++) // Loop through the Fields | |
116 | { // BrowserDB::OnGetNext Formats the field Value into tablename | |
117 | SetCellValue(z, y,((db_Br+i_Which)->cl_BrowserDB+y)->tableName); | |
118 | } | |
119 | if (z % 50 == 0) | |
120 | { | |
121 | Temp0.Printf(_("-I-> DBGrid::OnTableView(%s) - Record %6d has been read."),Table.c_str(),z); | |
122 | pDoc->p_MainFrame->SetStatusText(Temp0, 0); | |
123 | } | |
124 | } // for (z=0;z<(db_Br+i_Which)->i_Records;z++) | |
125 | Temp0.Printf(_("-I-> DBGrid::OnTableView(%s) - %6d Records have been read."),Table.c_str(),z); | |
126 | pDoc->p_MainFrame->SetStatusText(Temp0, 0); | |
127 | // The Grid has been filled, now leave | |
128 | goto Weiter; | |
129 | } // if ((ct_BrowserDB->pTableInf+x)->pColInf) | |
130 | else | |
131 | wxLogMessage(_("\n-E-> DBGrid::OnTableView():: Invalid Column Pointer : Failed")); | |
132 | } // if ((ct_BrowserDB->pTableInf+x)->tableType == "TABLE") | |
133 | } // for (x=0;x<ct_BrowserDB->numTables;x++) | |
134 | } // if (ct_BrowserDB) | |
135 | else | |
136 | wxLogMessage(_("\n-E-> DBGrid::OnTableView():: Invalid DSN Pointer : Failed")); | |
137 | //--------------------------------------------------------------------------- | |
b5ffecfc | 138 | Weiter: |
b5ce269b | 139 | SetEditInPlace(b_EditModus); // Activate in-place Editing (FALSE) |
b3630c4f | 140 | wxEndBusyCursor(); |
b5ce269b BJ |
141 | //--------------------------------------------------------------------------- |
142 | wxLogMessage(_("-I-> DBGrid::OnTableView() - End")); | |
143 | return 0; | |
b5ffecfc GT |
144 | } |
145 | //--------------------------------------------------------------------------- | |
146 | void DBGrid::OnModusEdit(wxMenu& menu, wxCommandEvent& event) | |
147 | { | |
b5ce269b BJ |
148 | b_EditModus = TRUE; // Needed by PopupMenu |
149 | SetEditable(FALSE); // Do not Edit with Text Edit Control | |
150 | SetEditInPlace(b_EditModus); // Deactivate in-place Editing | |
151 | UpdateDimensions(); // Redraw the Grid | |
b5ffecfc GT |
152 | } |
153 | //--------------------------------------------------------------------------- | |
154 | void DBGrid::OnModusBrowse(wxMenu& menu, wxCommandEvent& event) | |
155 | { | |
b5ce269b BJ |
156 | b_EditModus = FALSE; // Needed by PopupMenu |
157 | SetEditInPlace(b_EditModus); // Deactivate in-place Editing | |
158 | UpdateDimensions(); // Redraw the Grid | |
b5ffecfc GT |
159 | } |
160 | //------------------------------------------------------------------------------ | |
161 | void DBGrid::OnMouseMove(wxMouseEvent &event) | |
162 | { | |
b5ce269b | 163 | MousePos = event.GetPosition(); |
b5ffecfc GT |
164 | } |
165 | //--------------------------------------------------------------------------- | |
166 | void DBGrid::OnLabelLeftClick( wxGridEvent& ev ) | |
167 | { | |
b5ce269b BJ |
168 | logBuf = "DBGrid::OnLabelLeftClick : "; |
169 | if ( ev.GetRow() != -1 ) | |
170 | { | |
171 | logBuf << "row label " << ev.GetRow(); | |
172 | } | |
173 | else if ( ev.GetCol() != -1 ) | |
174 | { | |
175 | logBuf << "col label " << ev.GetCol(); | |
176 | } | |
177 | else | |
178 | { | |
179 | logBuf << "corner label"; | |
180 | } | |
181 | if ( ev.ShiftDown() ) | |
182 | logBuf << " (shift down)"; | |
183 | // wxLogMessage( "%s", logBuf.c_str() ); | |
184 | logBuf += "\n"; | |
185 | wxLogMessage(logBuf.c_str()); | |
186 | ev.Skip(); | |
b5ffecfc GT |
187 | } |
188 | //--------------------------------------------------------------------------- | |
189 | void DBGrid::OnLabelRightClick( wxGridEvent& ev ) | |
190 | { | |
191 | //------------------- | |
b5ce269b BJ |
192 | if (b_EditModus) |
193 | PopupMenu(popupMenu2,MousePos.x,MousePos.y); | |
194 | else | |
195 | PopupMenu(popupMenu1,MousePos.x,MousePos.y); | |
196 | //------------------- | |
197 | logBuf = "DBGrid::OnLabelRightClick : "; | |
198 | if ( ev.GetRow() != -1 ) | |
199 | { | |
200 | logBuf << "row label " << ev.GetRow(); | |
201 | } | |
202 | else if ( ev.GetCol() != -1 ) | |
203 | { | |
204 | logBuf << "col label " << ev.GetCol(); | |
205 | } | |
206 | else | |
207 | { | |
208 | logBuf << "corner label"; | |
209 | } | |
210 | if ( ev.ShiftDown() ) | |
211 | logBuf << " (shift down)"; | |
212 | // wxLogMessage( "%s", logBuf.c_str() ); | |
213 | logBuf += "\n"; | |
214 | wxLogMessage(logBuf.c_str()); | |
215 | ev.Skip(); | |
b5ffecfc GT |
216 | } |
217 | //--------------------------------------------------------------------------- | |
218 | void DBGrid::OnLabelLeftDClick( wxGridEvent& ev ) | |
219 | { | |
b5ce269b BJ |
220 | logBuf = "DBGrid::OnLabelLeftDClick : "; |
221 | if ( ev.GetRow() != -1 ) | |
222 | { | |
223 | logBuf << "row label " << ev.GetRow(); | |
224 | } | |
225 | else if ( ev.GetCol() != -1 ) | |
226 | { | |
227 | logBuf << "col label " << ev.GetCol(); | |
228 | } | |
229 | else | |
230 | { | |
231 | logBuf << "corner label"; | |
232 | } | |
233 | if ( ev.ShiftDown() ) | |
234 | logBuf << " (shift down)"; | |
235 | // wxLogMessage( "%s", logBuf.c_str() ); | |
236 | logBuf += "\n"; | |
237 | wxLogMessage(logBuf.c_str()); | |
238 | ev.Skip(); | |
b5ffecfc GT |
239 | } |
240 | //--------------------------------------------------------------------------- | |
241 | void DBGrid::OnLabelRightDClick( wxGridEvent& ev ) | |
242 | { | |
b5ce269b BJ |
243 | logBuf = "DBGrid::OnLabelRightDClick : "; |
244 | if ( ev.GetRow() != -1 ) | |
245 | { | |
246 | logBuf << "row label " << ev.GetRow(); | |
247 | } | |
248 | else if ( ev.GetCol() != -1 ) | |
249 | { | |
250 | logBuf << "col label " << ev.GetCol(); | |
251 | } | |
252 | else | |
253 | { | |
254 | logBuf << "corner label"; | |
255 | } | |
256 | if ( ev.ShiftDown() ) | |
257 | logBuf << " (shift down)"; | |
258 | // wxLogMessage( "%s", logBuf.c_str() ); | |
259 | logBuf += "\n"; | |
260 | wxLogMessage(logBuf.c_str()); | |
261 | ev.Skip(); | |
b5ffecfc GT |
262 | } |
263 | //--------------------------------------------------------------------------- | |
264 | void DBGrid::OnCellLeftClick( wxGridEvent& ev ) | |
265 | { | |
b5ce269b BJ |
266 | logBuf = "DBGrid::OnCellLeftClick : "; |
267 | logBuf << "Cell at row " << ev.GetRow() | |
268 | << " col " << ev.GetCol(); | |
269 | // wxLogMessage( "%s", logBuf.c_str() ); | |
270 | // wxMessageBox(logBuf); | |
271 | logBuf += "\n"; | |
272 | wxLogMessage(logBuf.c_str()); | |
273 | // you must call event skip if you want default grid processing | |
274 | // (cell highlighting etc.) | |
275 | // | |
276 | ev.Skip(); | |
b5ffecfc GT |
277 | } |
278 | //--------------------------------------------------------------------------- | |
279 | void DBGrid::OnCellRightClick( wxGridEvent& ev ) | |
280 | { | |
b5ce269b BJ |
281 | logBuf = "DBGrid::OnCellRightClick : "; |
282 | logBuf << "Cell at row " << ev.GetRow() | |
283 | << " col " << ev.GetCol(); | |
284 | // wxLogMessage( "%s", logBuf.c_str() ); | |
285 | // wxMessageBox(logBuf); | |
286 | logBuf += "\n"; | |
287 | wxLogMessage(logBuf.c_str()); | |
288 | // you must call event skip if you want default grid processing | |
289 | // (cell highlighting etc.) | |
290 | // | |
291 | ev.Skip(); | |
b5ffecfc GT |
292 | } |
293 | //--------------------------------------------------------------------------- | |
294 | void DBGrid::OnCellLeftDClick( wxGridEvent& ev ) | |
295 | { | |
b5ce269b BJ |
296 | logBuf = "DBGrid::OnCellLeftDClick : "; |
297 | logBuf << "Cell at row " << ev.GetRow() | |
298 | << " col " << ev.GetCol(); | |
299 | // wxLogMessage( "%s", logBuf.c_str() ); | |
300 | // wxMessageBox(logBuf); | |
301 | logBuf += "\n"; | |
302 | wxLogMessage(logBuf.c_str()); | |
303 | // you must call event skip if you want default grid processing | |
304 | // (cell highlighting etc.) | |
305 | // | |
306 | ev.Skip(); | |
b5ffecfc GT |
307 | } |
308 | //--------------------------------------------------------------------------- | |
309 | void DBGrid::OnCellRightDClick( wxGridEvent& ev ) | |
310 | { | |
b5ce269b BJ |
311 | logBuf = "DBGrid::OnCellRightDClick : "; |
312 | logBuf << "Cell at row " << ev.GetRow() | |
313 | << " col " << ev.GetCol(); | |
314 | // wxLogMessage( "%s", logBuf.c_str() ); | |
315 | // wxMessageBox(logBuf); | |
316 | logBuf += "\n"; | |
317 | wxLogMessage(logBuf.c_str()); | |
318 | // you must call event skip if you want default grid processing | |
319 | // (cell highlighting etc.) | |
320 | // | |
321 | ev.Skip(); | |
b5ffecfc GT |
322 | } |
323 | //--------------------------------------------------------------------------- | |
324 | void DBGrid::OnCellChange( wxGridEvent& ev ) | |
325 | { | |
b5ce269b BJ |
326 | logBuf = "DBGrid::OnCellChange : "; |
327 | logBuf << "Cell at row " << ev.GetRow() | |
328 | << " col " << ev.GetCol(); | |
329 | // wxLogMessage( "%s", logBuf.c_str() ); | |
330 | // wxMessageBox(logBuf); | |
331 | logBuf += "\n"; | |
332 | wxLogMessage(logBuf.c_str()); | |
333 | // you must call event skip if you want default grid processing | |
334 | // (cell highlighting etc.) | |
335 | // | |
336 | ev.Skip(); | |
b5ffecfc GT |
337 | } |
338 | //--------------------------------------------------------------------------- | |
339 | void DBGrid::OnRowSize( wxGridSizeEvent& ev ) | |
340 | { | |
b5ce269b BJ |
341 | logBuf = "DBGrid::OnRowSize : "; |
342 | logBuf << "Resized row " << ev.GetRowOrCol(); | |
343 | // wxLogMessage( "%s", logBuf.c_str() ); | |
344 | logBuf += "\n"; | |
345 | wxLogMessage(logBuf.c_str()); | |
346 | ev.Skip(); | |
b5ffecfc GT |
347 | } |
348 | //--------------------------------------------------------------------------- | |
349 | void DBGrid::OnColSize( wxGridSizeEvent& ev ) | |
350 | { | |
b5ce269b BJ |
351 | logBuf = "DBGrid::OnColSize : "; |
352 | logBuf << "Resized col " << ev.GetRowOrCol(); | |
353 | // wxLogMessage( "%s", logBuf.c_str() ); | |
354 | logBuf += "\n"; | |
355 | wxLogMessage(logBuf.c_str()); | |
356 | ||
357 | ev.Skip(); | |
b5ffecfc GT |
358 | } |
359 | //--------------------------------------------------------------------------- | |
360 | void DBGrid::OnRangeSelected( wxGridRangeSelectEvent& ev ) | |
361 | { | |
b5ce269b BJ |
362 | logBuf = "DBGrid::OnRangeSelected : "; |
363 | logBuf << "Selected cells from row " << ev.GetTopRow() | |
364 | << " col " << ev.GetLeftCol() | |
365 | << " to row " << ev.GetBottomRow() | |
366 | << " col " << ev.GetRightCol(); | |
367 | ||
368 | logBuf += "\n"; | |
369 | // wxLogMessage( "%s", logBuf.c_str() ); | |
370 | wxLogMessage(logBuf.c_str()); | |
371 | ||
372 | ev.Skip(); | |
b5ffecfc GT |
373 | } |
374 | //--------------------------------------------------------------------------- | |
b5ce269b | 375 |