]>
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 | |
7 | // RCS-ID: | |
8 | // Copyright: (c) | |
9 | // Licence: wxWindows license | |
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) | |
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) | |
61 | { | |
62 | f_Temp = new wxFont(10,wxSWISS,wxNORMAL,wxBOLD,FALSE,"Comic Sans MS"); | |
63 | wxPanel::SetFont(* f_Temp); | |
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")); | |
70 | } | |
71 | //--------------------------------------------------------------------------- | |
72 | DBGrid::~DBGrid() | |
73 | { | |
74 | } | |
75 | //--------------------------------------------------------------------------- | |
76 | int DBGrid::OnTableView(wxString Table) | |
77 | { | |
78 | //--------------------------------------------------------------------------- | |
79 | int i=0,x,y,z, ValidTable=0; | |
80 | wxString Temp0; | |
81 | SetLabelFont(* f_Temp); | |
82 | //--------------------------------------------------------------------------- | |
83 | ct_BrowserDB = (db_Br+i_Which)->ct_BrowserDB; // Get the DSN Pointer | |
84 | //---------------------------------------------------------------------------- | |
85 | if (ct_BrowserDB) // Valid pointer (!= NULL) ? | |
86 | { // Pointer is Valid, use the wxDatabase Information | |
87 | for (x=0;x<ct_BrowserDB->numTables;x++) // go through the Tables | |
88 | { | |
89 | if (!wxStrcmp((ct_BrowserDB->pTableInf+x)->tableName,Table)) // is this our Table ? | |
90 | { // Yes, the Data of this Table shall be put into the Grid | |
91 | ValidTable = x; // Save the Tablenumber | |
92 | (db_Br+i_Which)->OnSelect(Table,FALSE); // Select * from "table" | |
93 | // Set the local Pointer to the Column Information we are going to use | |
94 | (db_Br+i_Which)->cl_BrowserDB = (ct_BrowserDB->pTableInf+x)->pColInf; | |
95 | if ((ct_BrowserDB->pTableInf+x)->pColInf) // Valid pointer (!= NULL) ? | |
96 | { // Pointer is Valid, Column Informationen sind Vorhanden | |
97 | i = (db_Br+i_Which)->i_Records; // How many Records are there | |
98 | (db_Br+i_Which)->i_Which = ValidTable; // Still used ???? mj10777 | |
99 | if (i == 0) // If the Table is empty, then show one empty row | |
100 | i++; | |
101 | CreateGrid(i,(ct_BrowserDB->pTableInf+x)->numCols); // Records , Columns | |
102 | for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) // Loop through the Fields | |
103 | { // The Field / Column name is used here as Row Titel | |
104 | SetColLabelValue(y,((ct_BrowserDB->pTableInf+x)->pColInf+y)->colName); | |
105 | SetColSize(y,95); | |
106 | } // for (y=0;y<(ct_BrowserDB->pTableInf+x)->numCols;y++) | |
107 | SetColSize(((ct_BrowserDB->pTableInf+x)->numCols-1),120); // Make the last Column Wider | |
108 | // The Grid has been created, now fill it | |
109 | for (z=0;z<(db_Br+i_Which)->i_Records;z++) // Loop through the Records | |
110 | { | |
111 | Temp0.Printf("%06d",z+1); SetRowLabelValue(z,Temp0); // Set Row Lable Value | |
112 | (db_Br+i_Which)->OnGetNext((ct_BrowserDB->pTableInf+ValidTable)->numCols,FALSE); | |
113 | for (y=0;y<(ct_BrowserDB->pTableInf+ValidTable)->numCols;y++) // Loop through the Fields | |
114 | { // BrowserDB::OnGetNext Formats the field Value into tablename | |
115 | SetCellValue(z, y,((db_Br+i_Which)->cl_BrowserDB+y)->tableName); | |
116 | } | |
117 | if (z % 50 == 0) | |
118 | { | |
119 | Temp0.Printf(_("-I-> DBGrid::OnTableView(%s) - Record %6d has been read."),Table.c_str(),z); | |
120 | pDoc->p_MainFrame->SetStatusText(Temp0, 0); | |
121 | } | |
122 | } // for (z=0;z<(db_Br+i_Which)->i_Records;z++) | |
123 | Temp0.Printf(_("-I-> DBGrid::OnTableView(%s) - %6d Records have been read."),Table.c_str(),z); | |
124 | pDoc->p_MainFrame->SetStatusText(Temp0, 0); | |
125 | // The Grid has been filled, now leave | |
126 | goto Weiter; | |
127 | } // if ((ct_BrowserDB->pTableInf+x)->pColInf) | |
128 | else | |
129 | wxLogMessage(_("\n-E-> DBGrid::OnTableView():: Invalid Column Pointer : Failed")); | |
130 | } // if ((ct_BrowserDB->pTableInf+x)->tableType == "TABLE") | |
131 | } // for (x=0;x<ct_BrowserDB->numTables;x++) | |
132 | } // if (ct_BrowserDB) | |
133 | else | |
134 | wxLogMessage(_("\n-E-> DBGrid::OnTableView():: Invalid DSN Pointer : Failed")); | |
135 | //--------------------------------------------------------------------------- | |
136 | Weiter: | |
137 | SetEditInPlace(b_EditModus); // Activate in-place Editing (FALSE) | |
138 | //--------------------------------------------------------------------------- | |
139 | wxLogMessage(_("-I-> DBGrid::OnTableView() - End")); | |
140 | return 0; | |
141 | } | |
142 | //--------------------------------------------------------------------------- | |
143 | void DBGrid::OnModusEdit(wxMenu& menu, wxCommandEvent& event) | |
144 | { | |
145 | b_EditModus = TRUE; // Needed by PopupMenu | |
146 | SetEditable(FALSE); // Do not Edit with Text Edit Control | |
147 | SetEditInPlace(b_EditModus); // Deactivate in-place Editing | |
148 | UpdateDimensions(); // Redraw the Grid | |
149 | } | |
150 | //--------------------------------------------------------------------------- | |
151 | void DBGrid::OnModusBrowse(wxMenu& menu, wxCommandEvent& event) | |
152 | { | |
153 | b_EditModus = FALSE; // Needed by PopupMenu | |
154 | SetEditInPlace(b_EditModus); // Deactivate in-place Editing | |
155 | UpdateDimensions(); // Redraw the Grid | |
156 | } | |
157 | //------------------------------------------------------------------------------ | |
158 | void DBGrid::OnMouseMove(wxMouseEvent &event) | |
159 | { | |
160 | MousePos = event.GetPosition(); | |
161 | } | |
162 | //--------------------------------------------------------------------------- | |
163 | void DBGrid::OnLabelLeftClick( wxGridEvent& ev ) | |
164 | { | |
165 | logBuf = "DBGrid::OnLabelLeftClick : "; | |
166 | if ( ev.GetRow() != -1 ) | |
167 | { | |
168 | logBuf << "row label " << ev.GetRow(); | |
169 | } | |
170 | else if ( ev.GetCol() != -1 ) | |
171 | { | |
172 | logBuf << "col label " << ev.GetCol(); | |
173 | } | |
174 | else | |
175 | { | |
176 | logBuf << "corner label"; | |
177 | } | |
178 | if ( ev.ShiftDown() ) | |
179 | logBuf << " (shift down)"; | |
180 | // wxLogMessage( "%s", logBuf.c_str() ); | |
181 | logBuf += "\n"; | |
182 | wxLogMessage(logBuf.c_str()); | |
183 | ev.Skip(); | |
184 | } | |
185 | //--------------------------------------------------------------------------- | |
186 | void DBGrid::OnLabelRightClick( wxGridEvent& ev ) | |
187 | { | |
188 | //------------------- | |
189 | if (b_EditModus) | |
190 | PopupMenu(popupMenu2,MousePos.x,MousePos.y); | |
191 | else | |
192 | PopupMenu(popupMenu1,MousePos.x,MousePos.y); | |
193 | //------------------- | |
194 | logBuf = "DBGrid::OnLabelRightClick : "; | |
195 | if ( ev.GetRow() != -1 ) | |
196 | { | |
197 | logBuf << "row label " << ev.GetRow(); | |
198 | } | |
199 | else if ( ev.GetCol() != -1 ) | |
200 | { | |
201 | logBuf << "col label " << ev.GetCol(); | |
202 | } | |
203 | else | |
204 | { | |
205 | logBuf << "corner label"; | |
206 | } | |
207 | if ( ev.ShiftDown() ) | |
208 | logBuf << " (shift down)"; | |
209 | // wxLogMessage( "%s", logBuf.c_str() ); | |
210 | logBuf += "\n"; | |
211 | wxLogMessage(logBuf.c_str()); | |
212 | ev.Skip(); | |
213 | } | |
214 | //--------------------------------------------------------------------------- | |
215 | void DBGrid::OnLabelLeftDClick( wxGridEvent& ev ) | |
216 | { | |
217 | logBuf = "DBGrid::OnLabelLeftDClick : "; | |
218 | if ( ev.GetRow() != -1 ) | |
219 | { | |
220 | logBuf << "row label " << ev.GetRow(); | |
221 | } | |
222 | else if ( ev.GetCol() != -1 ) | |
223 | { | |
224 | logBuf << "col label " << ev.GetCol(); | |
225 | } | |
226 | else | |
227 | { | |
228 | logBuf << "corner label"; | |
229 | } | |
230 | if ( ev.ShiftDown() ) | |
231 | logBuf << " (shift down)"; | |
232 | // wxLogMessage( "%s", logBuf.c_str() ); | |
233 | logBuf += "\n"; | |
234 | wxLogMessage(logBuf.c_str()); | |
235 | ev.Skip(); | |
236 | } | |
237 | //--------------------------------------------------------------------------- | |
238 | void DBGrid::OnLabelRightDClick( wxGridEvent& ev ) | |
239 | { | |
240 | logBuf = "DBGrid::OnLabelRightDClick : "; | |
241 | if ( ev.GetRow() != -1 ) | |
242 | { | |
243 | logBuf << "row label " << ev.GetRow(); | |
244 | } | |
245 | else if ( ev.GetCol() != -1 ) | |
246 | { | |
247 | logBuf << "col label " << ev.GetCol(); | |
248 | } | |
249 | else | |
250 | { | |
251 | logBuf << "corner label"; | |
252 | } | |
253 | if ( ev.ShiftDown() ) | |
254 | logBuf << " (shift down)"; | |
255 | // wxLogMessage( "%s", logBuf.c_str() ); | |
256 | logBuf += "\n"; | |
257 | wxLogMessage(logBuf.c_str()); | |
258 | ev.Skip(); | |
259 | } | |
260 | //--------------------------------------------------------------------------- | |
261 | void DBGrid::OnCellLeftClick( wxGridEvent& ev ) | |
262 | { | |
263 | logBuf = "DBGrid::OnCellLeftClick : "; | |
264 | logBuf << "Cell at row " << ev.GetRow() | |
265 | << " col " << ev.GetCol(); | |
266 | // wxLogMessage( "%s", logBuf.c_str() ); | |
267 | // wxMessageBox(logBuf); | |
268 | logBuf += "\n"; | |
269 | wxLogMessage(logBuf.c_str()); | |
270 | // you must call event skip if you want default grid processing | |
271 | // (cell highlighting etc.) | |
272 | // | |
273 | ev.Skip(); | |
274 | } | |
275 | //--------------------------------------------------------------------------- | |
276 | void DBGrid::OnCellRightClick( wxGridEvent& ev ) | |
277 | { | |
278 | logBuf = "DBGrid::OnCellRightClick : "; | |
279 | logBuf << "Cell at row " << ev.GetRow() | |
280 | << " col " << ev.GetCol(); | |
281 | // wxLogMessage( "%s", logBuf.c_str() ); | |
282 | // wxMessageBox(logBuf); | |
283 | logBuf += "\n"; | |
284 | wxLogMessage(logBuf.c_str()); | |
285 | // you must call event skip if you want default grid processing | |
286 | // (cell highlighting etc.) | |
287 | // | |
288 | ev.Skip(); | |
289 | } | |
290 | //--------------------------------------------------------------------------- | |
291 | void DBGrid::OnCellLeftDClick( wxGridEvent& ev ) | |
292 | { | |
293 | logBuf = "DBGrid::OnCellLeftDClick : "; | |
294 | logBuf << "Cell at row " << ev.GetRow() | |
295 | << " col " << ev.GetCol(); | |
296 | // wxLogMessage( "%s", logBuf.c_str() ); | |
297 | // wxMessageBox(logBuf); | |
298 | logBuf += "\n"; | |
299 | wxLogMessage(logBuf.c_str()); | |
300 | // you must call event skip if you want default grid processing | |
301 | // (cell highlighting etc.) | |
302 | // | |
303 | ev.Skip(); | |
304 | } | |
305 | //--------------------------------------------------------------------------- | |
306 | void DBGrid::OnCellRightDClick( wxGridEvent& ev ) | |
307 | { | |
308 | logBuf = "DBGrid::OnCellRightDClick : "; | |
309 | logBuf << "Cell at row " << ev.GetRow() | |
310 | << " col " << ev.GetCol(); | |
311 | // wxLogMessage( "%s", logBuf.c_str() ); | |
312 | // wxMessageBox(logBuf); | |
313 | logBuf += "\n"; | |
314 | wxLogMessage(logBuf.c_str()); | |
315 | // you must call event skip if you want default grid processing | |
316 | // (cell highlighting etc.) | |
317 | // | |
318 | ev.Skip(); | |
319 | } | |
320 | //--------------------------------------------------------------------------- | |
321 | void DBGrid::OnCellChange( wxGridEvent& ev ) | |
322 | { | |
323 | logBuf = "DBGrid::OnCellChange : "; | |
324 | logBuf << "Cell at row " << ev.GetRow() | |
325 | << " col " << ev.GetCol(); | |
326 | // wxLogMessage( "%s", logBuf.c_str() ); | |
327 | // wxMessageBox(logBuf); | |
328 | logBuf += "\n"; | |
329 | wxLogMessage(logBuf.c_str()); | |
330 | // you must call event skip if you want default grid processing | |
331 | // (cell highlighting etc.) | |
332 | // | |
333 | ev.Skip(); | |
334 | } | |
335 | //--------------------------------------------------------------------------- | |
336 | void DBGrid::OnRowSize( wxGridSizeEvent& ev ) | |
337 | { | |
338 | logBuf = "DBGrid::OnRowSize : "; | |
339 | logBuf << "Resized row " << ev.GetRowOrCol(); | |
340 | // wxLogMessage( "%s", logBuf.c_str() ); | |
341 | logBuf += "\n"; | |
342 | wxLogMessage(logBuf.c_str()); | |
343 | ev.Skip(); | |
344 | } | |
345 | //--------------------------------------------------------------------------- | |
346 | void DBGrid::OnColSize( wxGridSizeEvent& ev ) | |
347 | { | |
348 | logBuf = "DBGrid::OnColSize : "; | |
349 | logBuf << "Resized col " << ev.GetRowOrCol(); | |
350 | // wxLogMessage( "%s", logBuf.c_str() ); | |
351 | logBuf += "\n"; | |
352 | wxLogMessage(logBuf.c_str()); | |
353 | ||
354 | ev.Skip(); | |
355 | } | |
356 | //--------------------------------------------------------------------------- | |
357 | void DBGrid::OnRangeSelected( wxGridRangeSelectEvent& ev ) | |
358 | { | |
359 | logBuf = "DBGrid::OnRangeSelected : "; | |
360 | logBuf << "Selected cells from row " << ev.GetTopRow() | |
361 | << " col " << ev.GetLeftCol() | |
362 | << " to row " << ev.GetBottomRow() | |
363 | << " col " << ev.GetRightCol(); | |
364 | ||
365 | logBuf += "\n"; | |
366 | // wxLogMessage( "%s", logBuf.c_str() ); | |
367 | wxLogMessage(logBuf.c_str()); | |
368 | ||
369 | ev.Skip(); | |
370 | } | |
371 | //--------------------------------------------------------------------------- |