]>
Commit | Line | Data |
---|---|---|
2796cce3 | 1 | /////////////////////////////////////////////////////////////////////////// |
d16c04bb | 2 | // Name: generic/grid.cpp |
f85afd4e MB |
3 | // Purpose: wxGrid and related classes |
4 | // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn) | |
5 | // Modified by: | |
6 | // Created: 1/08/1999 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Michael Bedward (mbedward@ozemail.com.au) | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
758cbedf VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
f85afd4e MB |
20 | #ifdef __GNUG__ |
21 | #pragma implementation "grid.h" | |
22 | #endif | |
23 | ||
f6bcfd97 | 24 | // For compilers that support precompilatixon, includes "wx/wx.h". |
4d85bcd1 JS |
25 | #include "wx/wxprec.h" |
26 | ||
27 | #include "wx/defs.h" | |
f85afd4e MB |
28 | |
29 | #ifdef __BORLANDC__ | |
30 | #pragma hdrstop | |
31 | #endif | |
32 | ||
27b92ca4 VZ |
33 | #if wxUSE_GRID |
34 | ||
8f177c8e | 35 | #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) |
27b92ca4 VZ |
36 | #include "gridg.cpp" |
37 | #else // wxUSE_NEW_GRID | |
4d85bcd1 | 38 | |
f85afd4e MB |
39 | #ifndef WX_PRECOMP |
40 | #include "wx/utils.h" | |
41 | #include "wx/dcclient.h" | |
42 | #include "wx/settings.h" | |
43 | #include "wx/log.h" | |
508011ce VZ |
44 | #include "wx/textctrl.h" |
45 | #include "wx/checkbox.h" | |
4ee5fc9c | 46 | #include "wx/combobox.h" |
816be743 | 47 | #include "wx/valtext.h" |
f85afd4e MB |
48 | #endif |
49 | ||
cb5df486 | 50 | #include "wx/textfile.h" |
816be743 | 51 | #include "wx/spinctrl.h" |
c4608a8a | 52 | #include "wx/tokenzr.h" |
6d004f67 | 53 | |
07296f0b | 54 | #include "wx/grid.h" |
b5808881 | 55 | #include "wx/generic/gridsel.h" |
07296f0b | 56 | |
0b7e6e7d SN |
57 | #if defined(__WXMOTIF__) |
58 | #define WXUNUSED_MOTIF(identifier) WXUNUSED(identifier) | |
c78b3acd | 59 | #else |
0b7e6e7d | 60 | #define WXUNUSED_MOTIF(identifier) identifier |
c78b3acd SN |
61 | #endif |
62 | ||
63 | #if defined(__WXGTK__) | |
64 | #define WXUNUSED_GTK(identifier) WXUNUSED(identifier) | |
65 | #else | |
66 | #define WXUNUSED_GTK(identifier) identifier | |
67 | #endif | |
68 | ||
3f8e5072 JS |
69 | // Required for wxIs... functions |
70 | #include <ctype.h> | |
71 | ||
b99be8fb | 72 | // ---------------------------------------------------------------------------- |
758cbedf | 73 | // array classes |
b99be8fb VZ |
74 | // ---------------------------------------------------------------------------- |
75 | ||
f6bcfd97 | 76 | WX_DEFINE_EXPORTED_ARRAY(wxGridCellAttr *, wxArrayAttrs); |
758cbedf | 77 | |
b99be8fb VZ |
78 | struct wxGridCellWithAttr |
79 | { | |
2e9a6788 VZ |
80 | wxGridCellWithAttr(int row, int col, wxGridCellAttr *attr_) |
81 | : coords(row, col), attr(attr_) | |
b99be8fb VZ |
82 | { |
83 | } | |
84 | ||
2e9a6788 VZ |
85 | ~wxGridCellWithAttr() |
86 | { | |
87 | attr->DecRef(); | |
88 | } | |
89 | ||
b99be8fb | 90 | wxGridCellCoords coords; |
2e9a6788 | 91 | wxGridCellAttr *attr; |
b99be8fb VZ |
92 | }; |
93 | ||
f6bcfd97 | 94 | WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellWithAttr, wxGridCellWithAttrArray); |
b99be8fb VZ |
95 | |
96 | #include "wx/arrimpl.cpp" | |
97 | ||
98 | WX_DEFINE_OBJARRAY(wxGridCellCoordsArray) | |
99 | WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray) | |
100 | ||
0f442030 RR |
101 | // ---------------------------------------------------------------------------- |
102 | // events | |
103 | // ---------------------------------------------------------------------------- | |
104 | ||
2e4df4bf VZ |
105 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK) |
106 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK) | |
107 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK) | |
108 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK) | |
109 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK) | |
110 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK) | |
111 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK) | |
112 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK) | |
113 | DEFINE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE) | |
114 | DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SIZE) | |
115 | DEFINE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT) | |
116 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE) | |
117 | DEFINE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL) | |
118 | DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN) | |
119 | DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN) | |
bf7945ce | 120 | DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_CREATED) |
0f442030 | 121 | |
b99be8fb VZ |
122 | // ---------------------------------------------------------------------------- |
123 | // private classes | |
124 | // ---------------------------------------------------------------------------- | |
125 | ||
126 | class WXDLLEXPORT wxGridRowLabelWindow : public wxWindow | |
127 | { | |
128 | public: | |
129 | wxGridRowLabelWindow() { m_owner = (wxGrid *)NULL; } | |
130 | wxGridRowLabelWindow( wxGrid *parent, wxWindowID id, | |
131 | const wxPoint &pos, const wxSize &size ); | |
132 | ||
133 | private: | |
134 | wxGrid *m_owner; | |
135 | ||
136 | void OnPaint( wxPaintEvent& event ); | |
137 | void OnMouseEvent( wxMouseEvent& event ); | |
b51c3f27 | 138 | void OnMouseWheel( wxMouseEvent& event ); |
b99be8fb | 139 | void OnKeyDown( wxKeyEvent& event ); |
f6bcfd97 | 140 | void OnKeyUp( wxKeyEvent& ); |
b99be8fb VZ |
141 | |
142 | DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow) | |
143 | DECLARE_EVENT_TABLE() | |
144 | }; | |
145 | ||
146 | ||
147 | class WXDLLEXPORT wxGridColLabelWindow : public wxWindow | |
148 | { | |
149 | public: | |
150 | wxGridColLabelWindow() { m_owner = (wxGrid *)NULL; } | |
151 | wxGridColLabelWindow( wxGrid *parent, wxWindowID id, | |
152 | const wxPoint &pos, const wxSize &size ); | |
153 | ||
154 | private: | |
155 | wxGrid *m_owner; | |
156 | ||
157 | void OnPaint( wxPaintEvent &event ); | |
158 | void OnMouseEvent( wxMouseEvent& event ); | |
b51c3f27 | 159 | void OnMouseWheel( wxMouseEvent& event ); |
b99be8fb | 160 | void OnKeyDown( wxKeyEvent& event ); |
f6bcfd97 | 161 | void OnKeyUp( wxKeyEvent& ); |
b99be8fb VZ |
162 | |
163 | DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow) | |
164 | DECLARE_EVENT_TABLE() | |
165 | }; | |
166 | ||
167 | ||
168 | class WXDLLEXPORT wxGridCornerLabelWindow : public wxWindow | |
169 | { | |
170 | public: | |
171 | wxGridCornerLabelWindow() { m_owner = (wxGrid *)NULL; } | |
172 | wxGridCornerLabelWindow( wxGrid *parent, wxWindowID id, | |
173 | const wxPoint &pos, const wxSize &size ); | |
174 | ||
175 | private: | |
176 | wxGrid *m_owner; | |
177 | ||
178 | void OnMouseEvent( wxMouseEvent& event ); | |
b51c3f27 | 179 | void OnMouseWheel( wxMouseEvent& event ); |
b99be8fb | 180 | void OnKeyDown( wxKeyEvent& event ); |
f6bcfd97 | 181 | void OnKeyUp( wxKeyEvent& ); |
b99be8fb VZ |
182 | void OnPaint( wxPaintEvent& event ); |
183 | ||
184 | DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow) | |
185 | DECLARE_EVENT_TABLE() | |
186 | }; | |
187 | ||
188 | class WXDLLEXPORT wxGridWindow : public wxPanel | |
189 | { | |
190 | public: | |
191 | wxGridWindow() | |
192 | { | |
193 | m_owner = (wxGrid *)NULL; | |
194 | m_rowLabelWin = (wxGridRowLabelWindow *)NULL; | |
195 | m_colLabelWin = (wxGridColLabelWindow *)NULL; | |
196 | } | |
197 | ||
198 | wxGridWindow( wxGrid *parent, | |
199 | wxGridRowLabelWindow *rowLblWin, | |
200 | wxGridColLabelWindow *colLblWin, | |
201 | wxWindowID id, const wxPoint &pos, const wxSize &size ); | |
202 | ~wxGridWindow(); | |
203 | ||
204 | void ScrollWindow( int dx, int dy, const wxRect *rect ); | |
205 | ||
206 | private: | |
207 | wxGrid *m_owner; | |
208 | wxGridRowLabelWindow *m_rowLabelWin; | |
209 | wxGridColLabelWindow *m_colLabelWin; | |
210 | ||
211 | void OnPaint( wxPaintEvent &event ); | |
b51c3f27 | 212 | void OnMouseWheel( wxMouseEvent& event ); |
b99be8fb VZ |
213 | void OnMouseEvent( wxMouseEvent& event ); |
214 | void OnKeyDown( wxKeyEvent& ); | |
f6bcfd97 | 215 | void OnKeyUp( wxKeyEvent& ); |
2796cce3 RD |
216 | void OnEraseBackground( wxEraseEvent& ); |
217 | ||
b99be8fb VZ |
218 | |
219 | DECLARE_DYNAMIC_CLASS(wxGridWindow) | |
220 | DECLARE_EVENT_TABLE() | |
221 | }; | |
222 | ||
2796cce3 RD |
223 | |
224 | ||
225 | class wxGridCellEditorEvtHandler : public wxEvtHandler | |
226 | { | |
227 | public: | |
228 | wxGridCellEditorEvtHandler() | |
229 | : m_grid(0), m_editor(0) | |
230 | { } | |
231 | wxGridCellEditorEvtHandler(wxGrid* grid, wxGridCellEditor* editor) | |
232 | : m_grid(grid), m_editor(editor) | |
233 | { } | |
234 | ||
235 | void OnKeyDown(wxKeyEvent& event); | |
fb0de762 | 236 | void OnChar(wxKeyEvent& event); |
2796cce3 RD |
237 | |
238 | private: | |
239 | wxGrid* m_grid; | |
240 | wxGridCellEditor* m_editor; | |
241 | DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler) | |
242 | DECLARE_EVENT_TABLE() | |
243 | }; | |
244 | ||
245 | ||
246 | IMPLEMENT_DYNAMIC_CLASS( wxGridCellEditorEvtHandler, wxEvtHandler ) | |
247 | BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler, wxEvtHandler ) | |
248 | EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown ) | |
fb0de762 | 249 | EVT_CHAR( wxGridCellEditorEvtHandler::OnChar ) |
2796cce3 RD |
250 | END_EVENT_TABLE() |
251 | ||
252 | ||
253 | ||
758cbedf | 254 | // ---------------------------------------------------------------------------- |
b99be8fb | 255 | // the internal data representation used by wxGridCellAttrProvider |
758cbedf VZ |
256 | // ---------------------------------------------------------------------------- |
257 | ||
258 | // this class stores attributes set for cells | |
259 | class WXDLLEXPORT wxGridCellAttrData | |
b99be8fb VZ |
260 | { |
261 | public: | |
2e9a6788 | 262 | void SetAttr(wxGridCellAttr *attr, int row, int col); |
b99be8fb | 263 | wxGridCellAttr *GetAttr(int row, int col) const; |
4d60017a SN |
264 | void UpdateAttrRows( size_t pos, int numRows ); |
265 | void UpdateAttrCols( size_t pos, int numCols ); | |
b99be8fb VZ |
266 | |
267 | private: | |
268 | // searches for the attr for given cell, returns wxNOT_FOUND if not found | |
269 | int FindIndex(int row, int col) const; | |
270 | ||
271 | wxGridCellWithAttrArray m_attrs; | |
272 | }; | |
273 | ||
758cbedf VZ |
274 | // this class stores attributes set for rows or columns |
275 | class WXDLLEXPORT wxGridRowOrColAttrData | |
276 | { | |
277 | public: | |
ee6694a7 VZ |
278 | // empty ctor to suppress warnings |
279 | wxGridRowOrColAttrData() { } | |
758cbedf VZ |
280 | ~wxGridRowOrColAttrData(); |
281 | ||
282 | void SetAttr(wxGridCellAttr *attr, int rowOrCol); | |
283 | wxGridCellAttr *GetAttr(int rowOrCol) const; | |
4d60017a | 284 | void UpdateAttrRowsOrCols( size_t pos, int numRowsOrCols ); |
758cbedf VZ |
285 | |
286 | private: | |
287 | wxArrayInt m_rowsOrCols; | |
288 | wxArrayAttrs m_attrs; | |
289 | }; | |
290 | ||
291 | // NB: this is just a wrapper around 3 objects: one which stores cell | |
292 | // attributes, and 2 others for row/col ones | |
293 | class WXDLLEXPORT wxGridCellAttrProviderData | |
294 | { | |
295 | public: | |
296 | wxGridCellAttrData m_cellAttrs; | |
297 | wxGridRowOrColAttrData m_rowAttrs, | |
298 | m_colAttrs; | |
299 | }; | |
300 | ||
f2d76237 RD |
301 | |
302 | // ---------------------------------------------------------------------------- | |
303 | // data structures used for the data type registry | |
304 | // ---------------------------------------------------------------------------- | |
305 | ||
b94ae1ea VZ |
306 | struct wxGridDataTypeInfo |
307 | { | |
f2d76237 RD |
308 | wxGridDataTypeInfo(const wxString& typeName, |
309 | wxGridCellRenderer* renderer, | |
310 | wxGridCellEditor* editor) | |
311 | : m_typeName(typeName), m_renderer(renderer), m_editor(editor) | |
312 | { } | |
313 | ||
39bcce60 VZ |
314 | ~wxGridDataTypeInfo() |
315 | { | |
316 | wxSafeDecRef(m_renderer); | |
317 | wxSafeDecRef(m_editor); | |
318 | } | |
f2d76237 RD |
319 | |
320 | wxString m_typeName; | |
321 | wxGridCellRenderer* m_renderer; | |
322 | wxGridCellEditor* m_editor; | |
323 | }; | |
324 | ||
325 | ||
f6bcfd97 | 326 | WX_DEFINE_EXPORTED_ARRAY(wxGridDataTypeInfo*, wxGridDataTypeInfoArray); |
f2d76237 RD |
327 | |
328 | ||
b94ae1ea VZ |
329 | class WXDLLEXPORT wxGridTypeRegistry |
330 | { | |
f2d76237 | 331 | public: |
c78b3acd | 332 | wxGridTypeRegistry() {} |
f2d76237 | 333 | ~wxGridTypeRegistry(); |
b94ae1ea | 334 | |
f2d76237 RD |
335 | void RegisterDataType(const wxString& typeName, |
336 | wxGridCellRenderer* renderer, | |
337 | wxGridCellEditor* editor); | |
c4608a8a VZ |
338 | |
339 | // find one of already registered data types | |
340 | int FindRegisteredDataType(const wxString& typeName); | |
341 | ||
342 | // try to FindRegisteredDataType(), if this fails and typeName is one of | |
343 | // standard typenames, register it and return its index | |
f2d76237 | 344 | int FindDataType(const wxString& typeName); |
c4608a8a VZ |
345 | |
346 | // try to FindDataType(), if it fails see if it is not one of already | |
347 | // registered data types with some params in which case clone the | |
348 | // registered data type and set params for it | |
349 | int FindOrCloneDataType(const wxString& typeName); | |
350 | ||
f2d76237 RD |
351 | wxGridCellRenderer* GetRenderer(int index); |
352 | wxGridCellEditor* GetEditor(int index); | |
353 | ||
354 | private: | |
355 | wxGridDataTypeInfoArray m_typeinfo; | |
356 | }; | |
357 | ||
b99be8fb VZ |
358 | // ---------------------------------------------------------------------------- |
359 | // conditional compilation | |
360 | // ---------------------------------------------------------------------------- | |
361 | ||
9496deb5 MB |
362 | #ifndef WXGRID_DRAW_LINES |
363 | #define WXGRID_DRAW_LINES 1 | |
796df70a SN |
364 | #endif |
365 | ||
0a976765 VZ |
366 | // ---------------------------------------------------------------------------- |
367 | // globals | |
368 | // ---------------------------------------------------------------------------- | |
369 | ||
370 | //#define DEBUG_ATTR_CACHE | |
371 | #ifdef DEBUG_ATTR_CACHE | |
372 | static size_t gs_nAttrCacheHits = 0; | |
373 | static size_t gs_nAttrCacheMisses = 0; | |
374 | #endif // DEBUG_ATTR_CACHE | |
f85afd4e | 375 | |
43947979 VZ |
376 | // ---------------------------------------------------------------------------- |
377 | // constants | |
378 | // ---------------------------------------------------------------------------- | |
379 | ||
f85afd4e MB |
380 | wxGridCellCoords wxGridNoCellCoords( -1, -1 ); |
381 | wxRect wxGridNoCellRect( -1, -1, -1, -1 ); | |
382 | ||
f0102d2a | 383 | // scroll line size |
faec5a43 SN |
384 | // TODO: this doesn't work at all, grid cells have different sizes and approx |
385 | // calculations don't work as because of the size mismatch scrollbars | |
386 | // sometimes fail to be shown when they should be or vice versa | |
b51c3f27 RD |
387 | // |
388 | // The scroll bars may be a little flakey once in a while, but that is | |
389 | // surely much less horrible than having scroll lines of only 1!!! | |
390 | // -- Robin | |
391 | static const size_t GRID_SCROLL_LINE = 15; // 1; | |
392 | ||
f85afd4e | 393 | |
43947979 VZ |
394 | // the size of hash tables used a bit everywhere (the max number of elements |
395 | // in these hash tables is the number of rows/columns) | |
396 | static const int GRID_HASH_SIZE = 100; | |
397 | ||
ab79958a VZ |
398 | // ============================================================================ |
399 | // implementation | |
400 | // ============================================================================ | |
401 | ||
2796cce3 RD |
402 | // ---------------------------------------------------------------------------- |
403 | // wxGridCellEditor | |
404 | // ---------------------------------------------------------------------------- | |
405 | ||
406 | wxGridCellEditor::wxGridCellEditor() | |
407 | { | |
408 | m_control = NULL; | |
409 | } | |
410 | ||
411 | ||
412 | wxGridCellEditor::~wxGridCellEditor() | |
413 | { | |
414 | Destroy(); | |
415 | } | |
416 | ||
508011ce VZ |
417 | void wxGridCellEditor::Create(wxWindow* WXUNUSED(parent), |
418 | wxWindowID WXUNUSED(id), | |
419 | wxEvtHandler* evtHandler) | |
420 | { | |
189d0213 | 421 | if ( evtHandler ) |
508011ce VZ |
422 | m_control->PushEventHandler(evtHandler); |
423 | } | |
2796cce3 | 424 | |
189d0213 VZ |
425 | void wxGridCellEditor::PaintBackground(const wxRect& rectCell, |
426 | wxGridCellAttr *attr) | |
427 | { | |
428 | // erase the background because we might not fill the cell | |
429 | wxClientDC dc(m_control->GetParent()); | |
430 | dc.SetPen(*wxTRANSPARENT_PEN); | |
431 | dc.SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID)); | |
432 | dc.DrawRectangle(rectCell); | |
433 | ||
434 | // redraw the control we just painted over | |
435 | m_control->Refresh(); | |
436 | } | |
437 | ||
2796cce3 RD |
438 | void wxGridCellEditor::Destroy() |
439 | { | |
508011ce VZ |
440 | if (m_control) |
441 | { | |
b94ae1ea VZ |
442 | m_control->PopEventHandler(TRUE /* delete it*/); |
443 | ||
2796cce3 RD |
444 | m_control->Destroy(); |
445 | m_control = NULL; | |
446 | } | |
447 | } | |
448 | ||
3da93aae | 449 | void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr) |
2796cce3 RD |
450 | { |
451 | wxASSERT_MSG(m_control, | |
452 | wxT("The wxGridCellEditor must be Created first!")); | |
453 | m_control->Show(show); | |
3da93aae VZ |
454 | |
455 | if ( show ) | |
456 | { | |
457 | // set the colours/fonts if we have any | |
458 | if ( attr ) | |
459 | { | |
f2d76237 RD |
460 | m_colFgOld = m_control->GetForegroundColour(); |
461 | m_control->SetForegroundColour(attr->GetTextColour()); | |
3da93aae | 462 | |
f2d76237 RD |
463 | m_colBgOld = m_control->GetBackgroundColour(); |
464 | m_control->SetBackgroundColour(attr->GetBackgroundColour()); | |
3da93aae | 465 | |
f2d76237 RD |
466 | m_fontOld = m_control->GetFont(); |
467 | m_control->SetFont(attr->GetFont()); | |
3da93aae VZ |
468 | |
469 | // can't do anything more in the base class version, the other | |
470 | // attributes may only be used by the derived classes | |
471 | } | |
472 | } | |
473 | else | |
474 | { | |
475 | // restore the standard colours fonts | |
476 | if ( m_colFgOld.Ok() ) | |
477 | { | |
478 | m_control->SetForegroundColour(m_colFgOld); | |
479 | m_colFgOld = wxNullColour; | |
480 | } | |
481 | ||
482 | if ( m_colBgOld.Ok() ) | |
483 | { | |
484 | m_control->SetBackgroundColour(m_colBgOld); | |
485 | m_colBgOld = wxNullColour; | |
486 | } | |
487 | ||
488 | if ( m_fontOld.Ok() ) | |
489 | { | |
490 | m_control->SetFont(m_fontOld); | |
491 | m_fontOld = wxNullFont; | |
492 | } | |
493 | } | |
2796cce3 RD |
494 | } |
495 | ||
496 | void wxGridCellEditor::SetSize(const wxRect& rect) | |
497 | { | |
498 | wxASSERT_MSG(m_control, | |
499 | wxT("The wxGridCellEditor must be Created first!")); | |
28a77bc4 | 500 | m_control->SetSize(rect, wxSIZE_ALLOW_MINUS_ONE); |
2796cce3 RD |
501 | } |
502 | ||
503 | void wxGridCellEditor::HandleReturn(wxKeyEvent& event) | |
504 | { | |
505 | event.Skip(); | |
506 | } | |
507 | ||
f6bcfd97 BP |
508 | bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event) |
509 | { | |
510 | // accept the simple key presses, not anything with Ctrl/Alt/Meta | |
a4f7bf58 | 511 | return !(event.ControlDown() || event.AltDown()); |
f6bcfd97 | 512 | } |
2796cce3 | 513 | |
2c9a89e0 RD |
514 | void wxGridCellEditor::StartingKey(wxKeyEvent& event) |
515 | { | |
e195a54c VZ |
516 | event.Skip(); |
517 | } | |
2c9a89e0 | 518 | |
e195a54c VZ |
519 | void wxGridCellEditor::StartingClick() |
520 | { | |
b54ba671 | 521 | } |
2c9a89e0 | 522 | |
3a8c693a VZ |
523 | #if wxUSE_TEXTCTRL |
524 | ||
b54ba671 VZ |
525 | // ---------------------------------------------------------------------------- |
526 | // wxGridCellTextEditor | |
527 | // ---------------------------------------------------------------------------- | |
2c9a89e0 | 528 | |
2796cce3 RD |
529 | wxGridCellTextEditor::wxGridCellTextEditor() |
530 | { | |
c4608a8a | 531 | m_maxChars = 0; |
2796cce3 RD |
532 | } |
533 | ||
534 | void wxGridCellTextEditor::Create(wxWindow* parent, | |
535 | wxWindowID id, | |
2796cce3 RD |
536 | wxEvtHandler* evtHandler) |
537 | { | |
508011ce | 538 | m_control = new wxTextCtrl(parent, id, wxEmptyString, |
2c9a89e0 | 539 | wxDefaultPosition, wxDefaultSize |
2796cce3 | 540 | #if defined(__WXMSW__) |
84912ef8 RD |
541 | , wxTE_PROCESS_TAB | wxTE_MULTILINE | |
542 | wxTE_NO_VSCROLL | wxTE_AUTO_SCROLL | |
2796cce3 | 543 | #endif |
508011ce | 544 | ); |
2796cce3 | 545 | |
c4608a8a VZ |
546 | // TODO: use m_maxChars |
547 | ||
508011ce | 548 | wxGridCellEditor::Create(parent, id, evtHandler); |
2796cce3 RD |
549 | } |
550 | ||
189d0213 VZ |
551 | void wxGridCellTextEditor::PaintBackground(const wxRect& WXUNUSED(rectCell), |
552 | wxGridCellAttr * WXUNUSED(attr)) | |
553 | { | |
554 | // as we fill the entire client area, don't do anything here to minimize | |
555 | // flicker | |
556 | } | |
2796cce3 | 557 | |
99306db2 VZ |
558 | void wxGridCellTextEditor::SetSize(const wxRect& rectOrig) |
559 | { | |
560 | wxRect rect(rectOrig); | |
561 | ||
562 | // Make the edit control large enough to allow for internal | |
563 | // margins | |
564 | // | |
565 | // TODO: remove this if the text ctrl sizing is improved esp. for | |
566 | // unix | |
567 | // | |
568 | #if defined(__WXGTK__) | |
b0e282b3 RR |
569 | if (rect.x != 0) |
570 | { | |
571 | rect.x += 1; | |
572 | rect.y += 1; | |
573 | rect.width -= 1; | |
574 | rect.height -= 1; | |
575 | } | |
99306db2 | 576 | #else // !GTK |
cb105ad4 | 577 | int extra_x = ( rect.x > 2 )? 2 : 1; |
84912ef8 RD |
578 | |
579 | // MB: treat MSW separately here otherwise the caret doesn't show | |
580 | // when the editor is in the first row. | |
a0948e27 MB |
581 | #if defined(__WXMSW__) |
582 | int extra_y = 2; | |
583 | #else | |
cb105ad4 | 584 | int extra_y = ( rect.y > 2 )? 2 : 1; |
a0948e27 MB |
585 | #endif // MSW |
586 | ||
99306db2 | 587 | #if defined(__WXMOTIF__) |
cb105ad4 SN |
588 | extra_x *= 2; |
589 | extra_y *= 2; | |
99306db2 | 590 | #endif |
cb105ad4 SN |
591 | rect.SetLeft( wxMax(0, rect.x - extra_x) ); |
592 | rect.SetTop( wxMax(0, rect.y - extra_y) ); | |
593 | rect.SetRight( rect.GetRight() + 2*extra_x ); | |
594 | rect.SetBottom( rect.GetBottom() + 2*extra_y ); | |
99306db2 VZ |
595 | #endif // GTK/!GTK |
596 | ||
597 | wxGridCellEditor::SetSize(rect); | |
598 | } | |
599 | ||
3da93aae | 600 | void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid) |
2796cce3 RD |
601 | { |
602 | wxASSERT_MSG(m_control, | |
603 | wxT("The wxGridCellEditor must be Created first!")); | |
604 | ||
605 | m_startValue = grid->GetTable()->GetValue(row, col); | |
816be743 VZ |
606 | |
607 | DoBeginEdit(m_startValue); | |
608 | } | |
609 | ||
610 | void wxGridCellTextEditor::DoBeginEdit(const wxString& startValue) | |
611 | { | |
612 | Text()->SetValue(startValue); | |
b54ba671 VZ |
613 | Text()->SetInsertionPointEnd(); |
614 | Text()->SetFocus(); | |
2796cce3 RD |
615 | } |
616 | ||
3324d5f5 | 617 | bool wxGridCellTextEditor::EndEdit(int row, int col, |
3da93aae | 618 | wxGrid* grid) |
2796cce3 RD |
619 | { |
620 | wxASSERT_MSG(m_control, | |
621 | wxT("The wxGridCellEditor must be Created first!")); | |
622 | ||
623 | bool changed = FALSE; | |
b54ba671 | 624 | wxString value = Text()->GetValue(); |
2796cce3 RD |
625 | if (value != m_startValue) |
626 | changed = TRUE; | |
627 | ||
628 | if (changed) | |
629 | grid->GetTable()->SetValue(row, col, value); | |
2c9a89e0 | 630 | |
3da93aae | 631 | m_startValue = wxEmptyString; |
b54ba671 | 632 | Text()->SetValue(m_startValue); |
2796cce3 RD |
633 | |
634 | return changed; | |
635 | } | |
636 | ||
637 | ||
638 | void wxGridCellTextEditor::Reset() | |
639 | { | |
640 | wxASSERT_MSG(m_control, | |
641 | wxT("The wxGridCellEditor must be Created first!")); | |
642 | ||
816be743 VZ |
643 | DoReset(m_startValue); |
644 | } | |
645 | ||
646 | void wxGridCellTextEditor::DoReset(const wxString& startValue) | |
647 | { | |
648 | Text()->SetValue(startValue); | |
b54ba671 | 649 | Text()->SetInsertionPointEnd(); |
2796cce3 RD |
650 | } |
651 | ||
f6bcfd97 BP |
652 | bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event) |
653 | { | |
654 | if ( wxGridCellEditor::IsAcceptedKey(event) ) | |
655 | { | |
656 | int keycode = event.GetKeyCode(); | |
657 | switch ( keycode ) | |
658 | { | |
659 | case WXK_NUMPAD0: | |
660 | case WXK_NUMPAD1: | |
661 | case WXK_NUMPAD2: | |
662 | case WXK_NUMPAD3: | |
663 | case WXK_NUMPAD4: | |
664 | case WXK_NUMPAD5: | |
665 | case WXK_NUMPAD6: | |
666 | case WXK_NUMPAD7: | |
667 | case WXK_NUMPAD8: | |
668 | case WXK_NUMPAD9: | |
669 | case WXK_MULTIPLY: | |
670 | case WXK_NUMPAD_MULTIPLY: | |
671 | case WXK_ADD: | |
672 | case WXK_NUMPAD_ADD: | |
673 | case WXK_SUBTRACT: | |
674 | case WXK_NUMPAD_SUBTRACT: | |
675 | case WXK_DECIMAL: | |
676 | case WXK_NUMPAD_DECIMAL: | |
677 | case WXK_DIVIDE: | |
678 | case WXK_NUMPAD_DIVIDE: | |
679 | return TRUE; | |
680 | ||
681 | default: | |
682 | // accept 8 bit chars too if isprint() agrees | |
683 | if ( (keycode < 255) && (isprint(keycode)) ) | |
684 | return TRUE; | |
685 | } | |
686 | } | |
687 | ||
688 | return FALSE; | |
689 | } | |
690 | ||
2c9a89e0 RD |
691 | void wxGridCellTextEditor::StartingKey(wxKeyEvent& event) |
692 | { | |
f6bcfd97 BP |
693 | // we don't check for !HasModifiers() because IsAcceptedKey() did it |
694 | ||
695 | // insert the key in the control | |
696 | wxChar ch; | |
697 | int keycode = event.GetKeyCode(); | |
698 | switch ( keycode ) | |
699 | { | |
700 | case WXK_NUMPAD0: | |
701 | case WXK_NUMPAD1: | |
702 | case WXK_NUMPAD2: | |
703 | case WXK_NUMPAD3: | |
704 | case WXK_NUMPAD4: | |
705 | case WXK_NUMPAD5: | |
706 | case WXK_NUMPAD6: | |
707 | case WXK_NUMPAD7: | |
708 | case WXK_NUMPAD8: | |
709 | case WXK_NUMPAD9: | |
710 | ch = _T('0') + keycode - WXK_NUMPAD0; | |
711 | break; | |
b54ba671 | 712 | |
f6bcfd97 BP |
713 | case WXK_MULTIPLY: |
714 | case WXK_NUMPAD_MULTIPLY: | |
715 | ch = _T('*'); | |
716 | break; | |
b54ba671 | 717 | |
f6bcfd97 BP |
718 | case WXK_ADD: |
719 | case WXK_NUMPAD_ADD: | |
720 | ch = _T('+'); | |
721 | break; | |
2c9a89e0 | 722 | |
f6bcfd97 BP |
723 | case WXK_SUBTRACT: |
724 | case WXK_NUMPAD_SUBTRACT: | |
725 | ch = _T('-'); | |
726 | break; | |
727 | ||
728 | case WXK_DECIMAL: | |
729 | case WXK_NUMPAD_DECIMAL: | |
730 | ch = _T('.'); | |
731 | break; | |
732 | ||
733 | case WXK_DIVIDE: | |
734 | case WXK_NUMPAD_DIVIDE: | |
735 | ch = _T('/'); | |
736 | break; | |
737 | ||
738 | default: | |
739 | if ( keycode < 256 && keycode >= 0 && isprint(keycode) ) | |
740 | { | |
741 | // FIXME this is not going to work for non letters... | |
742 | if ( !event.ShiftDown() ) | |
743 | { | |
744 | keycode = tolower(keycode); | |
745 | } | |
746 | ||
747 | ch = (wxChar)keycode; | |
748 | } | |
749 | else | |
750 | { | |
751 | ch = _T('\0'); | |
752 | } | |
2c9a89e0 | 753 | } |
2c9a89e0 | 754 | |
f6bcfd97 BP |
755 | if ( ch ) |
756 | { | |
757 | Text()->AppendText(ch); | |
758 | } | |
759 | else | |
760 | { | |
761 | event.Skip(); | |
762 | } | |
b54ba671 | 763 | } |
2c9a89e0 | 764 | |
c78b3acd | 765 | void wxGridCellTextEditor::HandleReturn( wxKeyEvent& |
0b7e6e7d | 766 | WXUNUSED_GTK(WXUNUSED_MOTIF(event)) ) |
2796cce3 RD |
767 | { |
768 | #if defined(__WXMOTIF__) || defined(__WXGTK__) | |
769 | // wxMotif needs a little extra help... | |
6fc0f38f | 770 | size_t pos = (size_t)( Text()->GetInsertionPoint() ); |
b54ba671 | 771 | wxString s( Text()->GetValue() ); |
2796cce3 | 772 | s = s.Left(pos) + "\n" + s.Mid(pos); |
b54ba671 VZ |
773 | Text()->SetValue(s); |
774 | Text()->SetInsertionPoint( pos ); | |
2796cce3 RD |
775 | #else |
776 | // the other ports can handle a Return key press | |
777 | // | |
778 | event.Skip(); | |
779 | #endif | |
780 | } | |
781 | ||
c4608a8a VZ |
782 | void wxGridCellTextEditor::SetParameters(const wxString& params) |
783 | { | |
784 | if ( !params ) | |
785 | { | |
786 | // reset to default | |
787 | m_maxChars = 0; | |
788 | } | |
789 | else | |
790 | { | |
791 | long tmp; | |
792 | if ( !params.ToLong(&tmp) ) | |
793 | { | |
f6bcfd97 | 794 | wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params.c_str()); |
c4608a8a VZ |
795 | } |
796 | else | |
797 | { | |
798 | m_maxChars = (size_t)tmp; | |
799 | } | |
800 | } | |
801 | } | |
802 | ||
816be743 VZ |
803 | // ---------------------------------------------------------------------------- |
804 | // wxGridCellNumberEditor | |
805 | // ---------------------------------------------------------------------------- | |
806 | ||
807 | wxGridCellNumberEditor::wxGridCellNumberEditor(int min, int max) | |
808 | { | |
809 | m_min = min; | |
810 | m_max = max; | |
811 | } | |
812 | ||
813 | void wxGridCellNumberEditor::Create(wxWindow* parent, | |
814 | wxWindowID id, | |
815 | wxEvtHandler* evtHandler) | |
816 | { | |
817 | if ( HasRange() ) | |
818 | { | |
819 | // create a spin ctrl | |
820 | m_control = new wxSpinCtrl(parent, -1, wxEmptyString, | |
821 | wxDefaultPosition, wxDefaultSize, | |
822 | wxSP_ARROW_KEYS, | |
823 | m_min, m_max); | |
824 | ||
825 | wxGridCellEditor::Create(parent, id, evtHandler); | |
826 | } | |
827 | else | |
828 | { | |
829 | // just a text control | |
830 | wxGridCellTextEditor::Create(parent, id, evtHandler); | |
831 | ||
832 | #if wxUSE_VALIDATORS | |
85bc0351 | 833 | Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); |
816be743 VZ |
834 | #endif // wxUSE_VALIDATORS |
835 | } | |
836 | } | |
837 | ||
838 | void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid) | |
839 | { | |
840 | // first get the value | |
841 | wxGridTableBase *table = grid->GetTable(); | |
842 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) ) | |
843 | { | |
844 | m_valueOld = table->GetValueAsLong(row, col); | |
845 | } | |
846 | else | |
847 | { | |
a5777624 RD |
848 | wxString sValue = table->GetValue(row, col); |
849 | if (! sValue.ToLong(&m_valueOld)) | |
850 | { | |
851 | wxFAIL_MSG( _T("this cell doesn't have numeric value") ); | |
852 | return; | |
853 | } | |
816be743 VZ |
854 | } |
855 | ||
856 | if ( HasRange() ) | |
857 | { | |
4a64bee4 | 858 | Spin()->SetValue((int)m_valueOld); |
f6bcfd97 | 859 | Spin()->SetFocus(); |
816be743 VZ |
860 | } |
861 | else | |
862 | { | |
863 | DoBeginEdit(GetString()); | |
864 | } | |
865 | } | |
866 | ||
3324d5f5 | 867 | bool wxGridCellNumberEditor::EndEdit(int row, int col, |
816be743 VZ |
868 | wxGrid* grid) |
869 | { | |
870 | bool changed; | |
871 | long value; | |
872 | ||
873 | if ( HasRange() ) | |
874 | { | |
875 | value = Spin()->GetValue(); | |
876 | changed = value != m_valueOld; | |
877 | } | |
878 | else | |
879 | { | |
880 | changed = Text()->GetValue().ToLong(&value) && (value != m_valueOld); | |
881 | } | |
882 | ||
883 | if ( changed ) | |
884 | { | |
a5777624 RD |
885 | if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER)) |
886 | grid->GetTable()->SetValueAsLong(row, col, value); | |
887 | else | |
f6bcfd97 | 888 | grid->GetTable()->SetValue(row, col, wxString::Format(wxT("%ld"), value)); |
816be743 VZ |
889 | } |
890 | ||
891 | return changed; | |
892 | } | |
893 | ||
894 | void wxGridCellNumberEditor::Reset() | |
895 | { | |
896 | if ( HasRange() ) | |
897 | { | |
4a64bee4 | 898 | Spin()->SetValue((int)m_valueOld); |
816be743 VZ |
899 | } |
900 | else | |
901 | { | |
902 | DoReset(GetString()); | |
903 | } | |
904 | } | |
905 | ||
f6bcfd97 BP |
906 | bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent& event) |
907 | { | |
908 | if ( wxGridCellEditor::IsAcceptedKey(event) ) | |
909 | { | |
910 | int keycode = event.GetKeyCode(); | |
911 | switch ( keycode ) | |
912 | { | |
913 | case WXK_NUMPAD0: | |
914 | case WXK_NUMPAD1: | |
915 | case WXK_NUMPAD2: | |
916 | case WXK_NUMPAD3: | |
917 | case WXK_NUMPAD4: | |
918 | case WXK_NUMPAD5: | |
919 | case WXK_NUMPAD6: | |
920 | case WXK_NUMPAD7: | |
921 | case WXK_NUMPAD8: | |
922 | case WXK_NUMPAD9: | |
923 | case WXK_ADD: | |
924 | case WXK_NUMPAD_ADD: | |
925 | case WXK_SUBTRACT: | |
926 | case WXK_NUMPAD_SUBTRACT: | |
927 | case WXK_UP: | |
928 | case WXK_DOWN: | |
929 | return TRUE; | |
930 | ||
931 | default: | |
932 | if ( (keycode < 128) && isdigit(keycode) ) | |
933 | return TRUE; | |
934 | } | |
935 | } | |
936 | ||
937 | return FALSE; | |
938 | } | |
939 | ||
816be743 VZ |
940 | void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event) |
941 | { | |
942 | if ( !HasRange() ) | |
943 | { | |
4a64bee4 | 944 | int keycode = (int) event.KeyCode(); |
816be743 VZ |
945 | if ( isdigit(keycode) || keycode == '+' || keycode == '-' ) |
946 | { | |
947 | wxGridCellTextEditor::StartingKey(event); | |
948 | ||
949 | // skip Skip() below | |
950 | return; | |
951 | } | |
952 | } | |
953 | ||
954 | event.Skip(); | |
955 | } | |
9c4ba614 | 956 | |
c4608a8a VZ |
957 | void wxGridCellNumberEditor::SetParameters(const wxString& params) |
958 | { | |
959 | if ( !params ) | |
960 | { | |
961 | // reset to default | |
962 | m_min = | |
963 | m_max = -1; | |
964 | } | |
965 | else | |
966 | { | |
967 | long tmp; | |
968 | if ( params.BeforeFirst(_T(',')).ToLong(&tmp) ) | |
969 | { | |
970 | m_min = (int)tmp; | |
971 | ||
972 | if ( params.AfterFirst(_T(',')).ToLong(&tmp) ) | |
973 | { | |
974 | m_max = (int)tmp; | |
975 | ||
976 | // skip the error message below | |
977 | return; | |
978 | } | |
979 | } | |
980 | ||
f6bcfd97 | 981 | wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params.c_str()); |
c4608a8a VZ |
982 | } |
983 | } | |
984 | ||
816be743 VZ |
985 | // ---------------------------------------------------------------------------- |
986 | // wxGridCellFloatEditor | |
987 | // ---------------------------------------------------------------------------- | |
988 | ||
f6bcfd97 BP |
989 | wxGridCellFloatEditor::wxGridCellFloatEditor(int width, int precision) |
990 | { | |
991 | m_width = width; | |
992 | m_precision = precision; | |
993 | } | |
994 | ||
816be743 VZ |
995 | void wxGridCellFloatEditor::Create(wxWindow* parent, |
996 | wxWindowID id, | |
997 | wxEvtHandler* evtHandler) | |
998 | { | |
999 | wxGridCellTextEditor::Create(parent, id, evtHandler); | |
1000 | ||
1001 | #if wxUSE_VALIDATORS | |
85bc0351 | 1002 | Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); |
816be743 VZ |
1003 | #endif // wxUSE_VALIDATORS |
1004 | } | |
1005 | ||
1006 | void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid) | |
1007 | { | |
1008 | // first get the value | |
1009 | wxGridTableBase *table = grid->GetTable(); | |
1010 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) ) | |
1011 | { | |
1012 | m_valueOld = table->GetValueAsDouble(row, col); | |
1013 | } | |
1014 | else | |
1015 | { | |
a5777624 RD |
1016 | wxString sValue = table->GetValue(row, col); |
1017 | if (! sValue.ToDouble(&m_valueOld)) | |
1018 | { | |
1019 | wxFAIL_MSG( _T("this cell doesn't have float value") ); | |
1020 | return; | |
1021 | } | |
816be743 VZ |
1022 | } |
1023 | ||
1024 | DoBeginEdit(GetString()); | |
1025 | } | |
1026 | ||
3324d5f5 | 1027 | bool wxGridCellFloatEditor::EndEdit(int row, int col, |
816be743 VZ |
1028 | wxGrid* grid) |
1029 | { | |
1030 | double value; | |
1031 | if ( Text()->GetValue().ToDouble(&value) && (value != m_valueOld) ) | |
1032 | { | |
a5777624 RD |
1033 | if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT)) |
1034 | grid->GetTable()->SetValueAsDouble(row, col, value); | |
1035 | else | |
f6bcfd97 | 1036 | grid->GetTable()->SetValue(row, col, wxString::Format(wxT("%f"), value)); |
816be743 VZ |
1037 | |
1038 | return TRUE; | |
1039 | } | |
1040 | else | |
1041 | { | |
1042 | return FALSE; | |
1043 | } | |
1044 | } | |
1045 | ||
1046 | void wxGridCellFloatEditor::Reset() | |
1047 | { | |
1048 | DoReset(GetString()); | |
1049 | } | |
1050 | ||
1051 | void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event) | |
1052 | { | |
4a64bee4 | 1053 | int keycode = (int)event.KeyCode(); |
816be743 VZ |
1054 | if ( isdigit(keycode) || |
1055 | keycode == '+' || keycode == '-' || keycode == '.' ) | |
1056 | { | |
1057 | wxGridCellTextEditor::StartingKey(event); | |
1058 | ||
1059 | // skip Skip() below | |
1060 | return; | |
1061 | } | |
1062 | ||
1063 | event.Skip(); | |
1064 | } | |
1065 | ||
f6bcfd97 BP |
1066 | void wxGridCellFloatEditor::SetParameters(const wxString& params) |
1067 | { | |
1068 | if ( !params ) | |
1069 | { | |
1070 | // reset to default | |
1071 | m_width = | |
1072 | m_precision = -1; | |
1073 | } | |
1074 | else | |
1075 | { | |
1076 | long tmp; | |
1077 | if ( params.BeforeFirst(_T(',')).ToLong(&tmp) ) | |
1078 | { | |
1079 | m_width = (int)tmp; | |
1080 | ||
1081 | if ( params.AfterFirst(_T(',')).ToLong(&tmp) ) | |
1082 | { | |
1083 | m_precision = (int)tmp; | |
1084 | ||
1085 | // skip the error message below | |
1086 | return; | |
1087 | } | |
1088 | } | |
1089 | ||
1090 | wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params.c_str()); | |
1091 | } | |
1092 | } | |
1093 | ||
1094 | wxString wxGridCellFloatEditor::GetString() const | |
1095 | { | |
1096 | wxString fmt; | |
1097 | if ( m_width == -1 ) | |
1098 | { | |
1099 | // default width/precision | |
1100 | fmt = _T("%g"); | |
1101 | } | |
1102 | else if ( m_precision == -1 ) | |
1103 | { | |
1104 | // default precision | |
1105 | fmt.Printf(_T("%%%d.g"), m_width); | |
1106 | } | |
1107 | else | |
1108 | { | |
1109 | fmt.Printf(_T("%%%d.%dg"), m_width, m_precision); | |
1110 | } | |
1111 | ||
1112 | return wxString::Format(fmt, m_valueOld); | |
1113 | } | |
1114 | ||
1115 | bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event) | |
1116 | { | |
1117 | if ( wxGridCellEditor::IsAcceptedKey(event) ) | |
1118 | { | |
1119 | int keycode = event.GetKeyCode(); | |
1120 | switch ( keycode ) | |
1121 | { | |
1122 | case WXK_NUMPAD0: | |
1123 | case WXK_NUMPAD1: | |
1124 | case WXK_NUMPAD2: | |
1125 | case WXK_NUMPAD3: | |
1126 | case WXK_NUMPAD4: | |
1127 | case WXK_NUMPAD5: | |
1128 | case WXK_NUMPAD6: | |
1129 | case WXK_NUMPAD7: | |
1130 | case WXK_NUMPAD8: | |
1131 | case WXK_NUMPAD9: | |
1132 | case WXK_ADD: | |
1133 | case WXK_NUMPAD_ADD: | |
1134 | case WXK_SUBTRACT: | |
1135 | case WXK_NUMPAD_SUBTRACT: | |
1136 | case WXK_DECIMAL: | |
1137 | case WXK_NUMPAD_DECIMAL: | |
1138 | return TRUE; | |
1139 | ||
1140 | default: | |
1141 | // additionally accept 'e' as in '1e+6' | |
1142 | if ( (keycode < 128) && | |
1143 | (isdigit(keycode) || tolower(keycode) == 'e') ) | |
1144 | return TRUE; | |
1145 | } | |
1146 | } | |
1147 | ||
1148 | return FALSE; | |
1149 | } | |
1150 | ||
3a8c693a VZ |
1151 | #endif // wxUSE_TEXTCTRL |
1152 | ||
1153 | #if wxUSE_CHECKBOX | |
1154 | ||
508011ce VZ |
1155 | // ---------------------------------------------------------------------------- |
1156 | // wxGridCellBoolEditor | |
1157 | // ---------------------------------------------------------------------------- | |
1158 | ||
1159 | void wxGridCellBoolEditor::Create(wxWindow* parent, | |
1160 | wxWindowID id, | |
1161 | wxEvtHandler* evtHandler) | |
1162 | { | |
1163 | m_control = new wxCheckBox(parent, id, wxEmptyString, | |
1164 | wxDefaultPosition, wxDefaultSize, | |
1165 | wxNO_BORDER); | |
1166 | ||
1167 | wxGridCellEditor::Create(parent, id, evtHandler); | |
1168 | } | |
1169 | ||
1170 | void wxGridCellBoolEditor::SetSize(const wxRect& r) | |
1171 | { | |
b94ae1ea VZ |
1172 | bool resize = FALSE; |
1173 | wxSize size = m_control->GetSize(); | |
1174 | wxCoord minSize = wxMin(r.width, r.height); | |
1175 | ||
1176 | // check if the checkbox is not too big/small for this cell | |
1177 | wxSize sizeBest = m_control->GetBestSize(); | |
1178 | if ( !(size == sizeBest) ) | |
1179 | { | |
1180 | // reset to default size if it had been made smaller | |
1181 | size = sizeBest; | |
1182 | ||
1183 | resize = TRUE; | |
1184 | } | |
1185 | ||
1186 | if ( size.x >= minSize || size.y >= minSize ) | |
1187 | { | |
1188 | // leave 1 pixel margin | |
1189 | size.x = size.y = minSize - 2; | |
1190 | ||
1191 | resize = TRUE; | |
1192 | } | |
1193 | ||
1194 | if ( resize ) | |
1195 | { | |
1196 | m_control->SetSize(size); | |
1197 | } | |
1198 | ||
508011ce | 1199 | // position it in the centre of the rectangle (TODO: support alignment?) |
508011ce | 1200 | |
b94ae1ea | 1201 | #if defined(__WXGTK__) || defined (__WXMOTIF__) |
508011ce VZ |
1202 | // the checkbox without label still has some space to the right in wxGTK, |
1203 | // so shift it to the right | |
b94ae1ea VZ |
1204 | size.x -= 8; |
1205 | #elif defined(__WXMSW__) | |
a95e38c0 VZ |
1206 | // here too, but in other way |
1207 | size.x += 1; | |
b94ae1ea VZ |
1208 | size.y -= 2; |
1209 | #endif | |
508011ce | 1210 | |
b94ae1ea | 1211 | m_control->Move(r.x + r.width/2 - size.x/2, r.y + r.height/2 - size.y/2); |
508011ce VZ |
1212 | } |
1213 | ||
1214 | void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr) | |
1215 | { | |
99306db2 VZ |
1216 | m_control->Show(show); |
1217 | ||
189d0213 | 1218 | if ( show ) |
508011ce | 1219 | { |
189d0213 VZ |
1220 | wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY; |
1221 | CBox()->SetBackgroundColour(colBg); | |
508011ce | 1222 | } |
508011ce VZ |
1223 | } |
1224 | ||
1225 | void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid) | |
1226 | { | |
1227 | wxASSERT_MSG(m_control, | |
1228 | wxT("The wxGridCellEditor must be Created first!")); | |
1229 | ||
28a77bc4 | 1230 | if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) |
f2d76237 RD |
1231 | m_startValue = grid->GetTable()->GetValueAsBool(row, col); |
1232 | else | |
695a3263 MB |
1233 | { |
1234 | wxString cellval( grid->GetTable()->GetValue(row, col) ); | |
1235 | m_startValue = !( !cellval || (cellval == "0") ); | |
1236 | } | |
508011ce VZ |
1237 | CBox()->SetValue(m_startValue); |
1238 | CBox()->SetFocus(); | |
1239 | } | |
1240 | ||
1241 | bool wxGridCellBoolEditor::EndEdit(int row, int col, | |
508011ce VZ |
1242 | wxGrid* grid) |
1243 | { | |
1244 | wxASSERT_MSG(m_control, | |
1245 | wxT("The wxGridCellEditor must be Created first!")); | |
1246 | ||
1247 | bool changed = FALSE; | |
1248 | bool value = CBox()->GetValue(); | |
1249 | if ( value != m_startValue ) | |
1250 | changed = TRUE; | |
1251 | ||
1252 | if ( changed ) | |
1253 | { | |
28a77bc4 | 1254 | if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) |
f2d76237 RD |
1255 | grid->GetTable()->SetValueAsBool(row, col, value); |
1256 | else | |
1257 | grid->GetTable()->SetValue(row, col, value ? _T("1") : wxEmptyString); | |
508011ce VZ |
1258 | } |
1259 | ||
1260 | return changed; | |
1261 | } | |
1262 | ||
1263 | void wxGridCellBoolEditor::Reset() | |
1264 | { | |
1265 | wxASSERT_MSG(m_control, | |
1266 | wxT("The wxGridCellEditor must be Created first!")); | |
1267 | ||
1268 | CBox()->SetValue(m_startValue); | |
1269 | } | |
1270 | ||
e195a54c | 1271 | void wxGridCellBoolEditor::StartingClick() |
508011ce | 1272 | { |
e195a54c | 1273 | CBox()->SetValue(!CBox()->GetValue()); |
508011ce VZ |
1274 | } |
1275 | ||
f6bcfd97 BP |
1276 | bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent& event) |
1277 | { | |
1278 | if ( wxGridCellEditor::IsAcceptedKey(event) ) | |
1279 | { | |
1280 | int keycode = event.GetKeyCode(); | |
1281 | switch ( keycode ) | |
1282 | { | |
1283 | case WXK_MULTIPLY: | |
1284 | case WXK_NUMPAD_MULTIPLY: | |
1285 | case WXK_ADD: | |
1286 | case WXK_NUMPAD_ADD: | |
1287 | case WXK_SUBTRACT: | |
1288 | case WXK_NUMPAD_SUBTRACT: | |
1289 | case WXK_SPACE: | |
1290 | case '+': | |
1291 | case '-': | |
1292 | return TRUE; | |
1293 | } | |
1294 | } | |
1295 | ||
1296 | return FALSE; | |
1297 | } | |
1298 | ||
3a8c693a VZ |
1299 | #endif // wxUSE_CHECKBOX |
1300 | ||
1301 | #if wxUSE_COMBOBOX | |
1302 | ||
4ee5fc9c VZ |
1303 | // ---------------------------------------------------------------------------- |
1304 | // wxGridCellChoiceEditor | |
1305 | // ---------------------------------------------------------------------------- | |
1306 | ||
1307 | wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count, | |
f6bcfd97 | 1308 | const wxString choices[], |
4ee5fc9c VZ |
1309 | bool allowOthers) |
1310 | : m_allowOthers(allowOthers) | |
1311 | { | |
c4608a8a | 1312 | if ( count ) |
4ee5fc9c | 1313 | { |
c4608a8a VZ |
1314 | m_choices.Alloc(count); |
1315 | for ( size_t n = 0; n < count; n++ ) | |
1316 | { | |
1317 | m_choices.Add(choices[n]); | |
1318 | } | |
4ee5fc9c VZ |
1319 | } |
1320 | } | |
1321 | ||
c4608a8a VZ |
1322 | wxGridCellEditor *wxGridCellChoiceEditor::Clone() const |
1323 | { | |
1324 | wxGridCellChoiceEditor *editor = new wxGridCellChoiceEditor; | |
1325 | editor->m_allowOthers = m_allowOthers; | |
1326 | editor->m_choices = m_choices; | |
1327 | ||
1328 | return editor; | |
1329 | } | |
1330 | ||
4ee5fc9c VZ |
1331 | void wxGridCellChoiceEditor::Create(wxWindow* parent, |
1332 | wxWindowID id, | |
1333 | wxEvtHandler* evtHandler) | |
1334 | { | |
1335 | size_t count = m_choices.GetCount(); | |
1336 | wxString *choices = new wxString[count]; | |
1337 | for ( size_t n = 0; n < count; n++ ) | |
1338 | { | |
1339 | choices[n] = m_choices[n]; | |
1340 | } | |
1341 | ||
1342 | m_control = new wxComboBox(parent, id, wxEmptyString, | |
1343 | wxDefaultPosition, wxDefaultSize, | |
1344 | count, choices, | |
1345 | m_allowOthers ? 0 : wxCB_READONLY); | |
1346 | ||
1347 | delete [] choices; | |
1348 | ||
1349 | wxGridCellEditor::Create(parent, id, evtHandler); | |
1350 | } | |
1351 | ||
a5777624 RD |
1352 | void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell, |
1353 | wxGridCellAttr * attr) | |
4ee5fc9c VZ |
1354 | { |
1355 | // as we fill the entire client area, don't do anything here to minimize | |
1356 | // flicker | |
a5777624 RD |
1357 | |
1358 | // TODO: It doesn't actually fill the client area since the height of a | |
1359 | // combo always defaults to the standard... Until someone has time to | |
1360 | // figure out the right rectangle to paint, just do it the normal way... | |
1361 | wxGridCellEditor::PaintBackground(rectCell, attr); | |
4ee5fc9c VZ |
1362 | } |
1363 | ||
1364 | void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid) | |
1365 | { | |
1366 | wxASSERT_MSG(m_control, | |
1367 | wxT("The wxGridCellEditor must be Created first!")); | |
1368 | ||
1369 | m_startValue = grid->GetTable()->GetValue(row, col); | |
1370 | ||
1371 | Combo()->SetValue(m_startValue); | |
28a77bc4 RD |
1372 | size_t count = m_choices.GetCount(); |
1373 | for (size_t i=0; i<count; i++) | |
1374 | { | |
1375 | if (m_startValue == m_choices[i]) | |
1376 | { | |
1377 | Combo()->SetSelection(i); | |
1378 | break; | |
1379 | } | |
1380 | } | |
4ee5fc9c VZ |
1381 | Combo()->SetInsertionPointEnd(); |
1382 | Combo()->SetFocus(); | |
1383 | } | |
1384 | ||
28a77bc4 | 1385 | bool wxGridCellChoiceEditor::EndEdit(int row, int col, |
4ee5fc9c VZ |
1386 | wxGrid* grid) |
1387 | { | |
1388 | wxString value = Combo()->GetValue(); | |
1389 | bool changed = value != m_startValue; | |
1390 | ||
1391 | if ( changed ) | |
1392 | grid->GetTable()->SetValue(row, col, value); | |
1393 | ||
1394 | m_startValue = wxEmptyString; | |
1395 | Combo()->SetValue(m_startValue); | |
1396 | ||
1397 | return changed; | |
1398 | } | |
1399 | ||
1400 | void wxGridCellChoiceEditor::Reset() | |
1401 | { | |
1402 | Combo()->SetValue(m_startValue); | |
1403 | Combo()->SetInsertionPointEnd(); | |
1404 | } | |
1405 | ||
c4608a8a VZ |
1406 | void wxGridCellChoiceEditor::SetParameters(const wxString& params) |
1407 | { | |
1408 | if ( !params ) | |
1409 | { | |
1410 | // what can we do? | |
1411 | return; | |
1412 | } | |
1413 | ||
1414 | m_choices.Empty(); | |
1415 | ||
1416 | wxStringTokenizer tk(params, _T(',')); | |
1417 | while ( tk.HasMoreTokens() ) | |
1418 | { | |
1419 | m_choices.Add(tk.GetNextToken()); | |
1420 | } | |
1421 | } | |
1422 | ||
3a8c693a VZ |
1423 | #endif // wxUSE_COMBOBOX |
1424 | ||
508011ce VZ |
1425 | // ---------------------------------------------------------------------------- |
1426 | // wxGridCellEditorEvtHandler | |
1427 | // ---------------------------------------------------------------------------- | |
2796cce3 RD |
1428 | |
1429 | void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event) | |
1430 | { | |
1431 | switch ( event.KeyCode() ) | |
1432 | { | |
1433 | case WXK_ESCAPE: | |
1434 | m_editor->Reset(); | |
b54ba671 | 1435 | m_grid->DisableCellEditControl(); |
2796cce3 RD |
1436 | break; |
1437 | ||
2c9a89e0 | 1438 | case WXK_TAB: |
b51c3f27 | 1439 | m_grid->GetEventHandler()->ProcessEvent( event ); |
9b4aede2 RD |
1440 | break; |
1441 | ||
2796cce3 | 1442 | case WXK_RETURN: |
faec5a43 SN |
1443 | case WXK_NUMPAD_ENTER: |
1444 | if (!m_grid->GetEventHandler()->ProcessEvent(event)) | |
2796cce3 RD |
1445 | m_editor->HandleReturn(event); |
1446 | break; | |
1447 | ||
2796cce3 RD |
1448 | |
1449 | default: | |
1450 | event.Skip(); | |
1451 | } | |
1452 | } | |
1453 | ||
fb0de762 RD |
1454 | void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event) |
1455 | { | |
1456 | switch ( event.KeyCode() ) | |
1457 | { | |
1458 | case WXK_ESCAPE: | |
1459 | case WXK_TAB: | |
1460 | case WXK_RETURN: | |
a4f7bf58 | 1461 | case WXK_NUMPAD_ENTER: |
fb0de762 RD |
1462 | break; |
1463 | ||
1464 | default: | |
1465 | event.Skip(); | |
1466 | } | |
1467 | } | |
1468 | ||
c4608a8a VZ |
1469 | // ---------------------------------------------------------------------------- |
1470 | // wxGridCellWorker is an (almost) empty common base class for | |
1471 | // wxGridCellRenderer and wxGridCellEditor managing ref counting | |
1472 | // ---------------------------------------------------------------------------- | |
1473 | ||
1474 | void wxGridCellWorker::SetParameters(const wxString& WXUNUSED(params)) | |
1475 | { | |
1476 | // nothing to do | |
1477 | } | |
1478 | ||
1479 | wxGridCellWorker::~wxGridCellWorker() | |
1480 | { | |
1481 | } | |
1482 | ||
508011ce VZ |
1483 | // ============================================================================ |
1484 | // renderer classes | |
1485 | // ============================================================================ | |
1486 | ||
ab79958a VZ |
1487 | // ---------------------------------------------------------------------------- |
1488 | // wxGridCellRenderer | |
1489 | // ---------------------------------------------------------------------------- | |
1490 | ||
1491 | void wxGridCellRenderer::Draw(wxGrid& grid, | |
2796cce3 | 1492 | wxGridCellAttr& attr, |
ab79958a VZ |
1493 | wxDC& dc, |
1494 | const wxRect& rect, | |
c78b3acd | 1495 | int WXUNUSED(row), int WXUNUSED(col), |
ab79958a VZ |
1496 | bool isSelected) |
1497 | { | |
1498 | dc.SetBackgroundMode( wxSOLID ); | |
1499 | ||
1500 | if ( isSelected ) | |
1501 | { | |
2796cce3 | 1502 | dc.SetBrush( wxBrush(grid.GetSelectionBackground(), wxSOLID) ); |
ab79958a VZ |
1503 | } |
1504 | else | |
1505 | { | |
2796cce3 | 1506 | dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) ); |
ab79958a VZ |
1507 | } |
1508 | ||
1509 | dc.SetPen( *wxTRANSPARENT_PEN ); | |
ab79958a VZ |
1510 | dc.DrawRectangle(rect); |
1511 | } | |
1512 | ||
508011ce VZ |
1513 | // ---------------------------------------------------------------------------- |
1514 | // wxGridCellStringRenderer | |
1515 | // ---------------------------------------------------------------------------- | |
1516 | ||
816be743 VZ |
1517 | void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid& grid, |
1518 | wxGridCellAttr& attr, | |
1519 | wxDC& dc, | |
1520 | bool isSelected) | |
ab79958a | 1521 | { |
ab79958a VZ |
1522 | dc.SetBackgroundMode( wxTRANSPARENT ); |
1523 | ||
283b7808 VZ |
1524 | // TODO some special colours for attr.IsReadOnly() case? |
1525 | ||
ab79958a VZ |
1526 | if ( isSelected ) |
1527 | { | |
2796cce3 RD |
1528 | dc.SetTextBackground( grid.GetSelectionBackground() ); |
1529 | dc.SetTextForeground( grid.GetSelectionForeground() ); | |
ab79958a VZ |
1530 | } |
1531 | else | |
1532 | { | |
2796cce3 RD |
1533 | dc.SetTextBackground( attr.GetBackgroundColour() ); |
1534 | dc.SetTextForeground( attr.GetTextColour() ); | |
ab79958a | 1535 | } |
816be743 | 1536 | |
2796cce3 | 1537 | dc.SetFont( attr.GetFont() ); |
816be743 VZ |
1538 | } |
1539 | ||
65e4e78e VZ |
1540 | wxSize wxGridCellStringRenderer::DoGetBestSize(wxGridCellAttr& attr, |
1541 | wxDC& dc, | |
1542 | const wxString& text) | |
1543 | { | |
f6bcfd97 | 1544 | wxCoord x = 0, y = 0, max_x = 0; |
65e4e78e | 1545 | dc.SetFont(attr.GetFont()); |
f6bcfd97 BP |
1546 | wxStringTokenizer tk(text, _T('\n')); |
1547 | while ( tk.HasMoreTokens() ) | |
1548 | { | |
1549 | dc.GetTextExtent(tk.GetNextToken(), &x, &y); | |
1550 | max_x = wxMax(max_x, x); | |
1551 | } | |
1552 | ||
1553 | y *= 1 + text.Freq(wxT('\n')); // multiply by the number of lines. | |
65e4e78e | 1554 | |
f6bcfd97 | 1555 | return wxSize(max_x, y); |
65e4e78e VZ |
1556 | } |
1557 | ||
1558 | wxSize wxGridCellStringRenderer::GetBestSize(wxGrid& grid, | |
1559 | wxGridCellAttr& attr, | |
1560 | wxDC& dc, | |
1561 | int row, int col) | |
1562 | { | |
1563 | return DoGetBestSize(attr, dc, grid.GetCellValue(row, col)); | |
1564 | } | |
1565 | ||
816be743 VZ |
1566 | void wxGridCellStringRenderer::Draw(wxGrid& grid, |
1567 | wxGridCellAttr& attr, | |
1568 | wxDC& dc, | |
1569 | const wxRect& rectCell, | |
1570 | int row, int col, | |
1571 | bool isSelected) | |
1572 | { | |
1573 | wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); | |
1574 | ||
1575 | // now we only have to draw the text | |
1576 | SetTextColoursAndFont(grid, attr, dc, isSelected); | |
ab79958a VZ |
1577 | |
1578 | int hAlign, vAlign; | |
2796cce3 | 1579 | attr.GetAlignment(&hAlign, &vAlign); |
ab79958a VZ |
1580 | |
1581 | wxRect rect = rectCell; | |
816be743 | 1582 | rect.Inflate(-1); |
ab79958a VZ |
1583 | |
1584 | grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), | |
1585 | rect, hAlign, vAlign); | |
1586 | } | |
1587 | ||
65e4e78e VZ |
1588 | // ---------------------------------------------------------------------------- |
1589 | // wxGridCellNumberRenderer | |
1590 | // ---------------------------------------------------------------------------- | |
1591 | ||
1592 | wxString wxGridCellNumberRenderer::GetString(wxGrid& grid, int row, int col) | |
1593 | { | |
1594 | wxGridTableBase *table = grid.GetTable(); | |
1595 | wxString text; | |
1596 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) ) | |
1597 | { | |
1598 | text.Printf(_T("%ld"), table->GetValueAsLong(row, col)); | |
1599 | } | |
9c4ba614 VZ |
1600 | else |
1601 | { | |
1602 | text = table->GetValue(row, col); | |
1603 | } | |
65e4e78e VZ |
1604 | |
1605 | return text; | |
1606 | } | |
1607 | ||
816be743 VZ |
1608 | void wxGridCellNumberRenderer::Draw(wxGrid& grid, |
1609 | wxGridCellAttr& attr, | |
1610 | wxDC& dc, | |
1611 | const wxRect& rectCell, | |
1612 | int row, int col, | |
1613 | bool isSelected) | |
1614 | { | |
1615 | wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); | |
1616 | ||
1617 | SetTextColoursAndFont(grid, attr, dc, isSelected); | |
1618 | ||
1619 | // draw the text right aligned by default | |
1620 | int hAlign, vAlign; | |
1621 | attr.GetAlignment(&hAlign, &vAlign); | |
4c7277db | 1622 | hAlign = wxALIGN_RIGHT; |
816be743 VZ |
1623 | |
1624 | wxRect rect = rectCell; | |
1625 | rect.Inflate(-1); | |
1626 | ||
65e4e78e VZ |
1627 | grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign); |
1628 | } | |
816be743 | 1629 | |
65e4e78e VZ |
1630 | wxSize wxGridCellNumberRenderer::GetBestSize(wxGrid& grid, |
1631 | wxGridCellAttr& attr, | |
1632 | wxDC& dc, | |
1633 | int row, int col) | |
1634 | { | |
1635 | return DoGetBestSize(attr, dc, GetString(grid, row, col)); | |
816be743 VZ |
1636 | } |
1637 | ||
1638 | // ---------------------------------------------------------------------------- | |
1639 | // wxGridCellFloatRenderer | |
1640 | // ---------------------------------------------------------------------------- | |
1641 | ||
1642 | wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width, int precision) | |
1643 | { | |
1644 | SetWidth(width); | |
1645 | SetPrecision(precision); | |
1646 | } | |
1647 | ||
e72b4213 VZ |
1648 | wxGridCellRenderer *wxGridCellFloatRenderer::Clone() const |
1649 | { | |
1650 | wxGridCellFloatRenderer *renderer = new wxGridCellFloatRenderer; | |
1651 | renderer->m_width = m_width; | |
1652 | renderer->m_precision = m_precision; | |
1653 | renderer->m_format = m_format; | |
1654 | ||
1655 | return renderer; | |
1656 | } | |
1657 | ||
65e4e78e VZ |
1658 | wxString wxGridCellFloatRenderer::GetString(wxGrid& grid, int row, int col) |
1659 | { | |
1660 | wxGridTableBase *table = grid.GetTable(); | |
0b190b0f VZ |
1661 | |
1662 | bool hasDouble; | |
1663 | double val; | |
65e4e78e VZ |
1664 | wxString text; |
1665 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) ) | |
1666 | { | |
0b190b0f VZ |
1667 | val = table->GetValueAsDouble(row, col); |
1668 | hasDouble = TRUE; | |
65e4e78e | 1669 | } |
9c4ba614 VZ |
1670 | else |
1671 | { | |
1672 | text = table->GetValue(row, col); | |
0b190b0f | 1673 | hasDouble = text.ToDouble(&val); |
9c4ba614 | 1674 | } |
65e4e78e | 1675 | |
0b190b0f VZ |
1676 | if ( hasDouble ) |
1677 | { | |
1678 | if ( !m_format ) | |
1679 | { | |
1680 | if ( m_width == -1 ) | |
1681 | { | |
19d7140e VZ |
1682 | if ( m_precision == -1 ) |
1683 | { | |
0b190b0f VZ |
1684 | // default width/precision |
1685 | m_format = _T("%f"); | |
19d7140e VZ |
1686 | } |
1687 | else | |
1688 | { | |
1689 | m_format.Printf(_T("%%.%df"), m_precision); | |
1690 | } | |
0b190b0f VZ |
1691 | } |
1692 | else if ( m_precision == -1 ) | |
1693 | { | |
1694 | // default precision | |
1695 | m_format.Printf(_T("%%%d.f"), m_width); | |
1696 | } | |
1697 | else | |
1698 | { | |
1699 | m_format.Printf(_T("%%%d.%df"), m_width, m_precision); | |
1700 | } | |
1701 | } | |
1702 | ||
1703 | text.Printf(m_format, val); | |
19d7140e | 1704 | |
0b190b0f VZ |
1705 | } |
1706 | //else: text already contains the string | |
1707 | ||
65e4e78e VZ |
1708 | return text; |
1709 | } | |
1710 | ||
816be743 VZ |
1711 | void wxGridCellFloatRenderer::Draw(wxGrid& grid, |
1712 | wxGridCellAttr& attr, | |
1713 | wxDC& dc, | |
1714 | const wxRect& rectCell, | |
1715 | int row, int col, | |
1716 | bool isSelected) | |
1717 | { | |
1718 | wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); | |
1719 | ||
1720 | SetTextColoursAndFont(grid, attr, dc, isSelected); | |
1721 | ||
1722 | // draw the text right aligned by default | |
1723 | int hAlign, vAlign; | |
1724 | attr.GetAlignment(&hAlign, &vAlign); | |
4c7277db | 1725 | hAlign = wxALIGN_RIGHT; |
816be743 VZ |
1726 | |
1727 | wxRect rect = rectCell; | |
1728 | rect.Inflate(-1); | |
1729 | ||
65e4e78e VZ |
1730 | grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign); |
1731 | } | |
816be743 | 1732 | |
65e4e78e VZ |
1733 | wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid, |
1734 | wxGridCellAttr& attr, | |
1735 | wxDC& dc, | |
1736 | int row, int col) | |
1737 | { | |
1738 | return DoGetBestSize(attr, dc, GetString(grid, row, col)); | |
816be743 VZ |
1739 | } |
1740 | ||
0b190b0f VZ |
1741 | void wxGridCellFloatRenderer::SetParameters(const wxString& params) |
1742 | { | |
0b190b0f VZ |
1743 | if ( !params ) |
1744 | { | |
1745 | // reset to defaults | |
1746 | SetWidth(-1); | |
1747 | SetPrecision(-1); | |
1748 | } | |
1749 | else | |
1750 | { | |
1751 | wxString tmp = params.BeforeFirst(_T(',')); | |
1752 | if ( !!tmp ) | |
1753 | { | |
1754 | long width; | |
19d7140e | 1755 | if ( tmp.ToLong(&width) ) |
0b190b0f | 1756 | { |
19d7140e | 1757 | SetWidth((int)width); |
0b190b0f VZ |
1758 | } |
1759 | else | |
1760 | { | |
19d7140e VZ |
1761 | wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str()); |
1762 | } | |
0b190b0f | 1763 | |
19d7140e | 1764 | } |
0b190b0f VZ |
1765 | tmp = params.AfterFirst(_T(',')); |
1766 | if ( !!tmp ) | |
1767 | { | |
1768 | long precision; | |
19d7140e | 1769 | if ( tmp.ToLong(&precision) ) |
0b190b0f | 1770 | { |
19d7140e | 1771 | SetPrecision((int)precision); |
0b190b0f VZ |
1772 | } |
1773 | else | |
1774 | { | |
19d7140e | 1775 | wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str()); |
0b190b0f VZ |
1776 | } |
1777 | ||
0b190b0f VZ |
1778 | } |
1779 | } | |
1780 | } | |
1781 | ||
19d7140e | 1782 | |
508011ce VZ |
1783 | // ---------------------------------------------------------------------------- |
1784 | // wxGridCellBoolRenderer | |
1785 | // ---------------------------------------------------------------------------- | |
1786 | ||
65e4e78e | 1787 | wxSize wxGridCellBoolRenderer::ms_sizeCheckMark; |
508011ce | 1788 | |
b94ae1ea VZ |
1789 | // FIXME these checkbox size calculations are really ugly... |
1790 | ||
65e4e78e | 1791 | // between checkmark and box |
a95e38c0 | 1792 | static const wxCoord wxGRID_CHECKMARK_MARGIN = 2; |
508011ce | 1793 | |
65e4e78e VZ |
1794 | wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid, |
1795 | wxGridCellAttr& WXUNUSED(attr), | |
1796 | wxDC& WXUNUSED(dc), | |
1797 | int WXUNUSED(row), | |
1798 | int WXUNUSED(col)) | |
1799 | { | |
1800 | // compute it only once (no locks for MT safeness in GUI thread...) | |
1801 | if ( !ms_sizeCheckMark.x ) | |
297da4ba | 1802 | { |
65e4e78e VZ |
1803 | // get checkbox size |
1804 | wxCoord checkSize = 0; | |
297da4ba VZ |
1805 | wxCheckBox *checkbox = new wxCheckBox(&grid, -1, wxEmptyString); |
1806 | wxSize size = checkbox->GetBestSize(); | |
a95e38c0 | 1807 | checkSize = size.y + 2*wxGRID_CHECKMARK_MARGIN; |
297da4ba | 1808 | |
65e4e78e | 1809 | // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result |
69d8f612 | 1810 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
65e4e78e | 1811 | checkSize -= size.y / 2; |
297da4ba VZ |
1812 | #endif |
1813 | ||
1814 | delete checkbox; | |
65e4e78e VZ |
1815 | |
1816 | ms_sizeCheckMark.x = ms_sizeCheckMark.y = checkSize; | |
297da4ba VZ |
1817 | } |
1818 | ||
65e4e78e VZ |
1819 | return ms_sizeCheckMark; |
1820 | } | |
1821 | ||
1822 | void wxGridCellBoolRenderer::Draw(wxGrid& grid, | |
1823 | wxGridCellAttr& attr, | |
1824 | wxDC& dc, | |
1825 | const wxRect& rect, | |
1826 | int row, int col, | |
1827 | bool isSelected) | |
1828 | { | |
1829 | wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected); | |
1830 | ||
297da4ba | 1831 | // draw a check mark in the centre (ignoring alignment - TODO) |
65e4e78e | 1832 | wxSize size = GetBestSize(grid, attr, dc, row, col); |
b94ae1ea VZ |
1833 | |
1834 | // don't draw outside the cell | |
1835 | wxCoord minSize = wxMin(rect.width, rect.height); | |
1836 | if ( size.x >= minSize || size.y >= minSize ) | |
1837 | { | |
1838 | // and even leave (at least) 1 pixel margin | |
1839 | size.x = size.y = minSize - 2; | |
1840 | } | |
1841 | ||
1842 | // draw a border around checkmark | |
a95e38c0 VZ |
1843 | wxRect rectBorder; |
1844 | rectBorder.x = rect.x + rect.width/2 - size.x/2; | |
1845 | rectBorder.y = rect.y + rect.height/2 - size.y/2; | |
1846 | rectBorder.width = size.x; | |
1847 | rectBorder.height = size.y; | |
b94ae1ea | 1848 | |
f2d76237 | 1849 | bool value; |
b94ae1ea | 1850 | if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) |
f2d76237 RD |
1851 | value = grid.GetTable()->GetValueAsBool(row, col); |
1852 | else | |
695a3263 MB |
1853 | { |
1854 | wxString cellval( grid.GetTable()->GetValue(row, col) ); | |
1855 | value = !( !cellval || (cellval == "0") ); | |
1856 | } | |
f2d76237 RD |
1857 | |
1858 | if ( value ) | |
508011ce | 1859 | { |
a95e38c0 VZ |
1860 | wxRect rectMark = rectBorder; |
1861 | #ifdef __WXMSW__ | |
1862 | // MSW DrawCheckMark() is weird (and should probably be changed...) | |
1863 | rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN/2); | |
1864 | rectMark.x++; | |
1865 | rectMark.y++; | |
1866 | #else // !MSW | |
1867 | rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN); | |
1868 | #endif // MSW/!MSW | |
1869 | ||
508011ce VZ |
1870 | dc.SetTextForeground(attr.GetTextColour()); |
1871 | dc.DrawCheckMark(rectMark); | |
1872 | } | |
a95e38c0 VZ |
1873 | |
1874 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
1875 | dc.SetPen(wxPen(attr.GetTextColour(), 1, wxSOLID)); | |
1876 | dc.DrawRectangle(rectBorder); | |
508011ce VZ |
1877 | } |
1878 | ||
2796cce3 RD |
1879 | // ---------------------------------------------------------------------------- |
1880 | // wxGridCellAttr | |
1881 | // ---------------------------------------------------------------------------- | |
1882 | ||
39bcce60 | 1883 | wxGridCellAttr *wxGridCellAttr::Clone() const |
a68c1246 VZ |
1884 | { |
1885 | wxGridCellAttr *attr = new wxGridCellAttr; | |
1886 | if ( HasTextColour() ) | |
1887 | attr->SetTextColour(GetTextColour()); | |
1888 | if ( HasBackgroundColour() ) | |
1889 | attr->SetBackgroundColour(GetBackgroundColour()); | |
1890 | if ( HasFont() ) | |
1891 | attr->SetFont(GetFont()); | |
1892 | if ( HasAlignment() ) | |
1893 | attr->SetAlignment(m_hAlign, m_vAlign); | |
1894 | ||
1895 | if ( m_renderer ) | |
1896 | { | |
1897 | attr->SetRenderer(m_renderer); | |
39bcce60 | 1898 | m_renderer->IncRef(); |
a68c1246 VZ |
1899 | } |
1900 | if ( m_editor ) | |
1901 | { | |
1902 | attr->SetEditor(m_editor); | |
39bcce60 | 1903 | m_editor->IncRef(); |
a68c1246 VZ |
1904 | } |
1905 | ||
1906 | if ( IsReadOnly() ) | |
1907 | attr->SetReadOnly(); | |
1908 | ||
19d7140e VZ |
1909 | attr->SetKind( m_attrkind ); |
1910 | ||
a68c1246 VZ |
1911 | attr->SetDefAttr(m_defGridAttr); |
1912 | ||
1913 | return attr; | |
1914 | } | |
1915 | ||
19d7140e VZ |
1916 | void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom) |
1917 | { | |
1918 | if ( !HasTextColour() && mergefrom->HasTextColour() ) | |
1919 | SetTextColour(mergefrom->GetTextColour()); | |
1920 | if ( !HasBackgroundColour() && mergefrom->HasBackgroundColour() ) | |
1921 | SetBackgroundColour(mergefrom->GetBackgroundColour()); | |
1922 | if ( !HasFont() && mergefrom->HasFont() ) | |
1923 | SetFont(mergefrom->GetFont()); | |
1924 | if ( !!HasAlignment() && mergefrom->HasAlignment() ){ | |
1925 | int hAlign, vAlign; | |
1926 | mergefrom->GetAlignment( &hAlign, &vAlign); | |
1927 | SetAlignment(hAlign, vAlign); | |
1928 | } | |
1929 | ||
1930 | // Directly access member functions as GetRender/Editor don't just return | |
1931 | // m_renderer/m_editor | |
1932 | // | |
1933 | // Maybe add support for merge of Render and Editor? | |
1934 | if (!HasRenderer() && mergefrom->HasRenderer() ) | |
bf7945ce | 1935 | { |
19d7140e VZ |
1936 | m_renderer = mergefrom->m_renderer; |
1937 | m_renderer->IncRef(); | |
1938 | } | |
1939 | if ( !HasEditor() && mergefrom->HasEditor() ) | |
1940 | { | |
1941 | m_editor = mergefrom->m_editor; | |
1942 | m_editor->IncRef(); | |
1943 | } | |
1944 | if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() ) | |
1945 | SetReadOnly(mergefrom->IsReadOnly()); | |
1946 | ||
1947 | SetDefAttr(mergefrom->m_defGridAttr); | |
1948 | } | |
1949 | ||
2796cce3 RD |
1950 | const wxColour& wxGridCellAttr::GetTextColour() const |
1951 | { | |
1952 | if (HasTextColour()) | |
508011ce | 1953 | { |
2796cce3 | 1954 | return m_colText; |
508011ce | 1955 | } |
2796cce3 | 1956 | else if (m_defGridAttr != this) |
508011ce | 1957 | { |
2796cce3 | 1958 | return m_defGridAttr->GetTextColour(); |
508011ce VZ |
1959 | } |
1960 | else | |
1961 | { | |
2796cce3 RD |
1962 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
1963 | return wxNullColour; | |
1964 | } | |
1965 | } | |
1966 | ||
1967 | ||
1968 | const wxColour& wxGridCellAttr::GetBackgroundColour() const | |
1969 | { | |
1970 | if (HasBackgroundColour()) | |
1971 | return m_colBack; | |
1972 | else if (m_defGridAttr != this) | |
1973 | return m_defGridAttr->GetBackgroundColour(); | |
508011ce VZ |
1974 | else |
1975 | { | |
2796cce3 RD |
1976 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
1977 | return wxNullColour; | |
1978 | } | |
1979 | } | |
1980 | ||
1981 | ||
1982 | const wxFont& wxGridCellAttr::GetFont() const | |
1983 | { | |
1984 | if (HasFont()) | |
1985 | return m_font; | |
1986 | else if (m_defGridAttr != this) | |
1987 | return m_defGridAttr->GetFont(); | |
508011ce VZ |
1988 | else |
1989 | { | |
2796cce3 RD |
1990 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
1991 | return wxNullFont; | |
1992 | } | |
1993 | } | |
1994 | ||
1995 | ||
1996 | void wxGridCellAttr::GetAlignment(int *hAlign, int *vAlign) const | |
1997 | { | |
508011ce VZ |
1998 | if (HasAlignment()) |
1999 | { | |
2796cce3 RD |
2000 | if ( hAlign ) *hAlign = m_hAlign; |
2001 | if ( vAlign ) *vAlign = m_vAlign; | |
2002 | } | |
2003 | else if (m_defGridAttr != this) | |
2004 | m_defGridAttr->GetAlignment(hAlign, vAlign); | |
508011ce VZ |
2005 | else |
2006 | { | |
2796cce3 RD |
2007 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
2008 | } | |
2009 | } | |
2010 | ||
2011 | ||
f2d76237 | 2012 | // GetRenderer and GetEditor use a slightly different decision path about |
28a77bc4 RD |
2013 | // which attribute to use. If a non-default attr object has one then it is |
2014 | // used, otherwise the default editor or renderer is fetched from the grid and | |
2015 | // used. It should be the default for the data type of the cell. If it is | |
2016 | // NULL (because the table has a type that the grid does not have in its | |
2017 | // registry,) then the grid's default editor or renderer is used. | |
2018 | ||
2019 | wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGrid* grid, int row, int col) const | |
2020 | { | |
28a77bc4 | 2021 | wxGridCellRenderer* renderer = NULL; |
28a77bc4 | 2022 | |
0b190b0f VZ |
2023 | if ( m_defGridAttr != this || grid == NULL ) |
2024 | { | |
2025 | renderer = m_renderer; // use local attribute | |
2026 | if ( renderer ) | |
2027 | renderer->IncRef(); | |
2028 | } | |
2029 | ||
2030 | if ( !renderer && grid ) // get renderer for the data type | |
2031 | { | |
2032 | // GetDefaultRendererForCell() will do IncRef() for us | |
2033 | renderer = grid->GetDefaultRendererForCell(row, col); | |
2034 | } | |
2035 | ||
2036 | if ( !renderer ) | |
2037 | { | |
28a77bc4 | 2038 | // if we still don't have one then use the grid default |
0b190b0f | 2039 | // (no need for IncRef() here neither) |
28a77bc4 | 2040 | renderer = m_defGridAttr->GetRenderer(NULL,0,0); |
0b190b0f | 2041 | } |
28a77bc4 | 2042 | |
0b190b0f VZ |
2043 | if ( !renderer) |
2044 | { | |
2796cce3 | 2045 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
0b190b0f | 2046 | } |
28a77bc4 RD |
2047 | |
2048 | return renderer; | |
2796cce3 RD |
2049 | } |
2050 | ||
28a77bc4 | 2051 | wxGridCellEditor* wxGridCellAttr::GetEditor(wxGrid* grid, int row, int col) const |
07296f0b | 2052 | { |
28a77bc4 | 2053 | wxGridCellEditor* editor = NULL; |
0b190b0f VZ |
2054 | |
2055 | if ( m_defGridAttr != this || grid == NULL ) | |
2056 | { | |
2057 | editor = m_editor; // use local attribute | |
2058 | if ( editor ) | |
2059 | editor->IncRef(); | |
2060 | } | |
2061 | ||
a95e38c0 VZ |
2062 | if ( !editor && grid ) // get renderer for the data type |
2063 | editor = grid->GetDefaultEditorForCell(row, col); | |
28a77bc4 | 2064 | |
0b190b0f | 2065 | if ( !editor ) |
28a77bc4 RD |
2066 | // if we still don't have one then use the grid default |
2067 | editor = m_defGridAttr->GetEditor(NULL,0,0); | |
2068 | ||
0b190b0f VZ |
2069 | if ( !editor ) |
2070 | { | |
07296f0b | 2071 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
0b190b0f | 2072 | } |
28a77bc4 RD |
2073 | |
2074 | return editor; | |
07296f0b RD |
2075 | } |
2076 | ||
b99be8fb | 2077 | // ---------------------------------------------------------------------------- |
758cbedf | 2078 | // wxGridCellAttrData |
b99be8fb VZ |
2079 | // ---------------------------------------------------------------------------- |
2080 | ||
758cbedf | 2081 | void wxGridCellAttrData::SetAttr(wxGridCellAttr *attr, int row, int col) |
b99be8fb VZ |
2082 | { |
2083 | int n = FindIndex(row, col); | |
2084 | if ( n == wxNOT_FOUND ) | |
2085 | { | |
2086 | // add the attribute | |
2087 | m_attrs.Add(new wxGridCellWithAttr(row, col, attr)); | |
2088 | } | |
2089 | else | |
2090 | { | |
2091 | if ( attr ) | |
2092 | { | |
2093 | // change the attribute | |
2e9a6788 | 2094 | m_attrs[(size_t)n].attr = attr; |
b99be8fb VZ |
2095 | } |
2096 | else | |
2097 | { | |
2098 | // remove this attribute | |
2099 | m_attrs.RemoveAt((size_t)n); | |
2100 | } | |
2101 | } | |
b99be8fb VZ |
2102 | } |
2103 | ||
758cbedf | 2104 | wxGridCellAttr *wxGridCellAttrData::GetAttr(int row, int col) const |
b99be8fb VZ |
2105 | { |
2106 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; | |
2107 | ||
2108 | int n = FindIndex(row, col); | |
2109 | if ( n != wxNOT_FOUND ) | |
2110 | { | |
2e9a6788 VZ |
2111 | attr = m_attrs[(size_t)n].attr; |
2112 | attr->IncRef(); | |
b99be8fb VZ |
2113 | } |
2114 | ||
2115 | return attr; | |
2116 | } | |
2117 | ||
4d60017a SN |
2118 | void wxGridCellAttrData::UpdateAttrRows( size_t pos, int numRows ) |
2119 | { | |
2120 | size_t count = m_attrs.GetCount(); | |
2121 | for ( size_t n = 0; n < count; n++ ) | |
2122 | { | |
2123 | wxGridCellCoords& coords = m_attrs[n].coords; | |
d1c0b4f9 VZ |
2124 | wxCoord row = coords.GetRow(); |
2125 | if ((size_t)row >= pos) | |
2126 | { | |
2127 | if (numRows > 0) | |
2128 | { | |
2129 | // If rows inserted, include row counter where necessary | |
2130 | coords.SetRow(row + numRows); | |
2131 | } | |
2132 | else if (numRows < 0) | |
2133 | { | |
2134 | // If rows deleted ... | |
2135 | if ((size_t)row >= pos - numRows) | |
2136 | { | |
2137 | // ...either decrement row counter (if row still exists)... | |
2138 | coords.SetRow(row + numRows); | |
2139 | } | |
2140 | else | |
2141 | { | |
2142 | // ...or remove the attribute | |
2143 | m_attrs.RemoveAt((size_t)n); | |
2144 | n--; count--; | |
2145 | } | |
2146 | } | |
4d60017a SN |
2147 | } |
2148 | } | |
2149 | } | |
2150 | ||
2151 | void wxGridCellAttrData::UpdateAttrCols( size_t pos, int numCols ) | |
2152 | { | |
2153 | size_t count = m_attrs.GetCount(); | |
2154 | for ( size_t n = 0; n < count; n++ ) | |
2155 | { | |
2156 | wxGridCellCoords& coords = m_attrs[n].coords; | |
d1c0b4f9 VZ |
2157 | wxCoord col = coords.GetCol(); |
2158 | if ( (size_t)col >= pos ) | |
2159 | { | |
2160 | if ( numCols > 0 ) | |
2161 | { | |
2162 | // If rows inserted, include row counter where necessary | |
2163 | coords.SetCol(col + numCols); | |
2164 | } | |
2165 | else if (numCols < 0) | |
2166 | { | |
2167 | // If rows deleted ... | |
2168 | if ((size_t)col >= pos - numCols) | |
2169 | { | |
2170 | // ...either decrement row counter (if row still exists)... | |
2171 | coords.SetCol(col + numCols); | |
2172 | } | |
2173 | else | |
2174 | { | |
2175 | // ...or remove the attribute | |
2176 | m_attrs.RemoveAt((size_t)n); | |
2177 | n--; count--; | |
2178 | } | |
2179 | } | |
4d60017a SN |
2180 | } |
2181 | } | |
2182 | } | |
2183 | ||
758cbedf | 2184 | int wxGridCellAttrData::FindIndex(int row, int col) const |
b99be8fb VZ |
2185 | { |
2186 | size_t count = m_attrs.GetCount(); | |
2187 | for ( size_t n = 0; n < count; n++ ) | |
2188 | { | |
2189 | const wxGridCellCoords& coords = m_attrs[n].coords; | |
2190 | if ( (coords.GetRow() == row) && (coords.GetCol() == col) ) | |
2191 | { | |
2192 | return n; | |
2193 | } | |
2194 | } | |
2195 | ||
2196 | return wxNOT_FOUND; | |
2197 | } | |
2198 | ||
758cbedf VZ |
2199 | // ---------------------------------------------------------------------------- |
2200 | // wxGridRowOrColAttrData | |
2201 | // ---------------------------------------------------------------------------- | |
2202 | ||
2203 | wxGridRowOrColAttrData::~wxGridRowOrColAttrData() | |
2204 | { | |
2205 | size_t count = m_attrs.Count(); | |
2206 | for ( size_t n = 0; n < count; n++ ) | |
2207 | { | |
2208 | m_attrs[n]->DecRef(); | |
2209 | } | |
2210 | } | |
2211 | ||
2212 | wxGridCellAttr *wxGridRowOrColAttrData::GetAttr(int rowOrCol) const | |
2213 | { | |
2214 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; | |
2215 | ||
2216 | int n = m_rowsOrCols.Index(rowOrCol); | |
2217 | if ( n != wxNOT_FOUND ) | |
2218 | { | |
2219 | attr = m_attrs[(size_t)n]; | |
2220 | attr->IncRef(); | |
2221 | } | |
2222 | ||
2223 | return attr; | |
2224 | } | |
2225 | ||
2226 | void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr *attr, int rowOrCol) | |
2227 | { | |
a95e38c0 VZ |
2228 | int i = m_rowsOrCols.Index(rowOrCol); |
2229 | if ( i == wxNOT_FOUND ) | |
758cbedf VZ |
2230 | { |
2231 | // add the attribute | |
2232 | m_rowsOrCols.Add(rowOrCol); | |
2233 | m_attrs.Add(attr); | |
2234 | } | |
2235 | else | |
2236 | { | |
a95e38c0 | 2237 | size_t n = (size_t)i; |
758cbedf VZ |
2238 | if ( attr ) |
2239 | { | |
2240 | // change the attribute | |
a95e38c0 VZ |
2241 | m_attrs[n]->DecRef(); |
2242 | m_attrs[n] = attr; | |
758cbedf VZ |
2243 | } |
2244 | else | |
2245 | { | |
2246 | // remove this attribute | |
a95e38c0 VZ |
2247 | m_attrs[n]->DecRef(); |
2248 | m_rowsOrCols.RemoveAt(n); | |
2249 | m_attrs.RemoveAt(n); | |
758cbedf VZ |
2250 | } |
2251 | } | |
2252 | } | |
2253 | ||
4d60017a SN |
2254 | void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos, int numRowsOrCols ) |
2255 | { | |
2256 | size_t count = m_attrs.GetCount(); | |
2257 | for ( size_t n = 0; n < count; n++ ) | |
2258 | { | |
2259 | int & rowOrCol = m_rowsOrCols[n]; | |
d1c0b4f9 VZ |
2260 | if ( (size_t)rowOrCol >= pos ) |
2261 | { | |
2262 | if ( numRowsOrCols > 0 ) | |
2263 | { | |
2264 | // If rows inserted, include row counter where necessary | |
2265 | rowOrCol += numRowsOrCols; | |
2266 | } | |
2267 | else if ( numRowsOrCols < 0) | |
2268 | { | |
2269 | // If rows deleted, either decrement row counter (if row still exists) | |
2270 | if ((size_t)rowOrCol >= pos - numRowsOrCols) | |
2271 | rowOrCol += numRowsOrCols; | |
2272 | else | |
2273 | { | |
2274 | m_rowsOrCols.RemoveAt((size_t)n); | |
2275 | m_attrs.RemoveAt((size_t)n); | |
2276 | n--; count--; | |
2277 | } | |
2278 | } | |
4d60017a SN |
2279 | } |
2280 | } | |
2281 | } | |
2282 | ||
b99be8fb VZ |
2283 | // ---------------------------------------------------------------------------- |
2284 | // wxGridCellAttrProvider | |
2285 | // ---------------------------------------------------------------------------- | |
2286 | ||
2287 | wxGridCellAttrProvider::wxGridCellAttrProvider() | |
2288 | { | |
2289 | m_data = (wxGridCellAttrProviderData *)NULL; | |
2290 | } | |
2291 | ||
2292 | wxGridCellAttrProvider::~wxGridCellAttrProvider() | |
2293 | { | |
2294 | delete m_data; | |
2295 | } | |
2296 | ||
2297 | void wxGridCellAttrProvider::InitData() | |
2298 | { | |
2299 | m_data = new wxGridCellAttrProviderData; | |
2300 | } | |
2301 | ||
19d7140e VZ |
2302 | wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col, |
2303 | wxGridCellAttr::wxAttrKind kind ) const | |
b99be8fb | 2304 | { |
758cbedf VZ |
2305 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; |
2306 | if ( m_data ) | |
2307 | { | |
19d7140e | 2308 | switch(kind) |
758cbedf | 2309 | { |
19d7140e VZ |
2310 | case (wxGridCellAttr::Any): |
2311 | //Get cached merge attributes. | |
2312 | // Currenlty not used as no cache implemented as not mutiable | |
2313 | // attr = m_data->m_mergeAttr.GetAttr(row, col); | |
2314 | if(!attr) | |
2315 | { | |
2316 | //Basicaly implement old version. | |
2317 | //Also check merge cache, so we don't have to re-merge every time.. | |
2318 | wxGridCellAttr *attrcell = (wxGridCellAttr *)NULL, | |
2319 | *attrrow = (wxGridCellAttr *)NULL, | |
bf7945ce RD |
2320 | *attrcol = (wxGridCellAttr *)NULL; |
2321 | ||
19d7140e VZ |
2322 | attrcell = m_data->m_cellAttrs.GetAttr(row, col); |
2323 | attrcol = m_data->m_colAttrs.GetAttr(col); | |
2324 | attrrow = m_data->m_rowAttrs.GetAttr(row); | |
2325 | ||
bf7945ce | 2326 | if((attrcell != attrrow) && (attrrow !=attrcol) && (attrcell != attrcol)){ |
19d7140e VZ |
2327 | // Two or move are non NULL |
2328 | attr = new wxGridCellAttr; | |
2329 | attr->SetKind(wxGridCellAttr::Merged); | |
2330 | ||
bf7945ce | 2331 | //Order important.. |
19d7140e VZ |
2332 | if(attrcell){ |
2333 | attr->MergeWith(attrcell); | |
2334 | attrcell->DecRef(); | |
2335 | } | |
2336 | if(attrcol){ | |
2337 | attr->MergeWith(attrcol); | |
2338 | attrcol->DecRef(); | |
2339 | } | |
2340 | if(attrrow){ | |
2341 | attr->MergeWith(attrrow); | |
2342 | attrrow->DecRef(); | |
2343 | } | |
2344 | //store merge attr if cache implemented | |
2345 | //attr->IncRef(); | |
2346 | //m_data->m_mergeAttr.SetAttr(attr, row, col); | |
2347 | } | |
2348 | else | |
758cbedf | 2349 | { |
19d7140e VZ |
2350 | // one or none is non null return it or null. |
2351 | if(attrrow) attr = attrrow; | |
2352 | if(attrcol) attr = attrcol; | |
bf7945ce | 2353 | if(attrcell) attr = attrcell; |
19d7140e VZ |
2354 | } |
2355 | } | |
2356 | break; | |
2357 | case (wxGridCellAttr::Cell): | |
2358 | attr = m_data->m_cellAttrs.GetAttr(row, col); | |
2359 | break; | |
2360 | case (wxGridCellAttr::Col): | |
2361 | attr = m_data->m_colAttrs.GetAttr(col); | |
2362 | break; | |
2363 | case (wxGridCellAttr::Row): | |
758cbedf | 2364 | attr = m_data->m_rowAttrs.GetAttr(row); |
19d7140e VZ |
2365 | break; |
2366 | default: | |
2367 | // unused as yet... | |
2368 | // (wxGridCellAttr::Default): | |
2369 | // (wxGridCellAttr::Merged): | |
2370 | break; | |
758cbedf VZ |
2371 | } |
2372 | } | |
758cbedf | 2373 | return attr; |
b99be8fb VZ |
2374 | } |
2375 | ||
2e9a6788 | 2376 | void wxGridCellAttrProvider::SetAttr(wxGridCellAttr *attr, |
b99be8fb VZ |
2377 | int row, int col) |
2378 | { | |
2379 | if ( !m_data ) | |
2380 | InitData(); | |
2381 | ||
758cbedf VZ |
2382 | m_data->m_cellAttrs.SetAttr(attr, row, col); |
2383 | } | |
2384 | ||
2385 | void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr *attr, int row) | |
2386 | { | |
2387 | if ( !m_data ) | |
2388 | InitData(); | |
2389 | ||
2390 | m_data->m_rowAttrs.SetAttr(attr, row); | |
2391 | } | |
2392 | ||
2393 | void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr *attr, int col) | |
2394 | { | |
2395 | if ( !m_data ) | |
2396 | InitData(); | |
2397 | ||
2398 | m_data->m_colAttrs.SetAttr(attr, col); | |
b99be8fb VZ |
2399 | } |
2400 | ||
4d60017a SN |
2401 | void wxGridCellAttrProvider::UpdateAttrRows( size_t pos, int numRows ) |
2402 | { | |
2403 | if ( m_data ) | |
2404 | { | |
2405 | m_data->m_cellAttrs.UpdateAttrRows( pos, numRows ); | |
2406 | ||
d1c0b4f9 | 2407 | m_data->m_rowAttrs.UpdateAttrRowsOrCols( pos, numRows ); |
4d60017a SN |
2408 | } |
2409 | } | |
2410 | ||
2411 | void wxGridCellAttrProvider::UpdateAttrCols( size_t pos, int numCols ) | |
2412 | { | |
2413 | if ( m_data ) | |
2414 | { | |
2415 | m_data->m_cellAttrs.UpdateAttrCols( pos, numCols ); | |
2416 | ||
d1c0b4f9 | 2417 | m_data->m_colAttrs.UpdateAttrRowsOrCols( pos, numCols ); |
4d60017a SN |
2418 | } |
2419 | } | |
2420 | ||
f2d76237 RD |
2421 | // ---------------------------------------------------------------------------- |
2422 | // wxGridTypeRegistry | |
2423 | // ---------------------------------------------------------------------------- | |
2424 | ||
2425 | wxGridTypeRegistry::~wxGridTypeRegistry() | |
2426 | { | |
b94ae1ea VZ |
2427 | size_t count = m_typeinfo.Count(); |
2428 | for ( size_t i = 0; i < count; i++ ) | |
f2d76237 RD |
2429 | delete m_typeinfo[i]; |
2430 | } | |
2431 | ||
2432 | ||
2433 | void wxGridTypeRegistry::RegisterDataType(const wxString& typeName, | |
2434 | wxGridCellRenderer* renderer, | |
2435 | wxGridCellEditor* editor) | |
2436 | { | |
f2d76237 RD |
2437 | wxGridDataTypeInfo* info = new wxGridDataTypeInfo(typeName, renderer, editor); |
2438 | ||
2439 | // is it already registered? | |
c4608a8a | 2440 | int loc = FindRegisteredDataType(typeName); |
39bcce60 VZ |
2441 | if ( loc != wxNOT_FOUND ) |
2442 | { | |
f2d76237 RD |
2443 | delete m_typeinfo[loc]; |
2444 | m_typeinfo[loc] = info; | |
2445 | } | |
39bcce60 VZ |
2446 | else |
2447 | { | |
f2d76237 RD |
2448 | m_typeinfo.Add(info); |
2449 | } | |
2450 | } | |
2451 | ||
c4608a8a VZ |
2452 | int wxGridTypeRegistry::FindRegisteredDataType(const wxString& typeName) |
2453 | { | |
2454 | size_t count = m_typeinfo.GetCount(); | |
2455 | for ( size_t i = 0; i < count; i++ ) | |
2456 | { | |
2457 | if ( typeName == m_typeinfo[i]->m_typeName ) | |
2458 | { | |
2459 | return i; | |
2460 | } | |
2461 | } | |
2462 | ||
2463 | return wxNOT_FOUND; | |
2464 | } | |
2465 | ||
f2d76237 RD |
2466 | int wxGridTypeRegistry::FindDataType(const wxString& typeName) |
2467 | { | |
c4608a8a VZ |
2468 | int index = FindRegisteredDataType(typeName); |
2469 | if ( index == wxNOT_FOUND ) | |
2470 | { | |
2471 | // check whether this is one of the standard ones, in which case | |
2472 | // register it "on the fly" | |
3a8c693a | 2473 | #if wxUSE_TEXTCTRL |
c4608a8a VZ |
2474 | if ( typeName == wxGRID_VALUE_STRING ) |
2475 | { | |
2476 | RegisterDataType(wxGRID_VALUE_STRING, | |
2477 | new wxGridCellStringRenderer, | |
2478 | new wxGridCellTextEditor); | |
3a8c693a VZ |
2479 | } else |
2480 | #endif // wxUSE_TEXTCTRL | |
2481 | #if wxUSE_CHECKBOX | |
2482 | if ( typeName == wxGRID_VALUE_BOOL ) | |
c4608a8a VZ |
2483 | { |
2484 | RegisterDataType(wxGRID_VALUE_BOOL, | |
2485 | new wxGridCellBoolRenderer, | |
2486 | new wxGridCellBoolEditor); | |
3a8c693a VZ |
2487 | } else |
2488 | #endif // wxUSE_CHECKBOX | |
2489 | #if wxUSE_TEXTCTRL | |
2490 | if ( typeName == wxGRID_VALUE_NUMBER ) | |
c4608a8a VZ |
2491 | { |
2492 | RegisterDataType(wxGRID_VALUE_NUMBER, | |
2493 | new wxGridCellNumberRenderer, | |
2494 | new wxGridCellNumberEditor); | |
2495 | } | |
2496 | else if ( typeName == wxGRID_VALUE_FLOAT ) | |
2497 | { | |
2498 | RegisterDataType(wxGRID_VALUE_FLOAT, | |
2499 | new wxGridCellFloatRenderer, | |
2500 | new wxGridCellFloatEditor); | |
3a8c693a VZ |
2501 | } else |
2502 | #endif // wxUSE_TEXTCTRL | |
2503 | #if wxUSE_COMBOBOX | |
2504 | if ( typeName == wxGRID_VALUE_CHOICE ) | |
c4608a8a VZ |
2505 | { |
2506 | RegisterDataType(wxGRID_VALUE_CHOICE, | |
2507 | new wxGridCellStringRenderer, | |
2508 | new wxGridCellChoiceEditor); | |
3a8c693a VZ |
2509 | } else |
2510 | #endif // wxUSE_COMBOBOX | |
c4608a8a VZ |
2511 | { |
2512 | return wxNOT_FOUND; | |
2513 | } | |
f2d76237 | 2514 | |
c4608a8a VZ |
2515 | // we get here only if just added the entry for this type, so return |
2516 | // the last index | |
2517 | index = m_typeinfo.GetCount() - 1; | |
2518 | } | |
2519 | ||
2520 | return index; | |
2521 | } | |
2522 | ||
2523 | int wxGridTypeRegistry::FindOrCloneDataType(const wxString& typeName) | |
2524 | { | |
2525 | int index = FindDataType(typeName); | |
2526 | if ( index == wxNOT_FOUND ) | |
2527 | { | |
2528 | // the first part of the typename is the "real" type, anything after ':' | |
2529 | // are the parameters for the renderer | |
2530 | index = FindDataType(typeName.BeforeFirst(_T(':'))); | |
2531 | if ( index == wxNOT_FOUND ) | |
2532 | { | |
2533 | return wxNOT_FOUND; | |
f2d76237 | 2534 | } |
c4608a8a VZ |
2535 | |
2536 | wxGridCellRenderer *renderer = GetRenderer(index); | |
2537 | wxGridCellRenderer *rendererOld = renderer; | |
2538 | renderer = renderer->Clone(); | |
2539 | rendererOld->DecRef(); | |
2540 | ||
2541 | wxGridCellEditor *editor = GetEditor(index); | |
2542 | wxGridCellEditor *editorOld = editor; | |
2543 | editor = editor->Clone(); | |
2544 | editorOld->DecRef(); | |
2545 | ||
2546 | // do it even if there are no parameters to reset them to defaults | |
2547 | wxString params = typeName.AfterFirst(_T(':')); | |
2548 | renderer->SetParameters(params); | |
2549 | editor->SetParameters(params); | |
2550 | ||
2551 | // register the new typename | |
c4608a8a VZ |
2552 | RegisterDataType(typeName, renderer, editor); |
2553 | ||
2554 | // we just registered it, it's the last one | |
2555 | index = m_typeinfo.GetCount() - 1; | |
f2d76237 RD |
2556 | } |
2557 | ||
c4608a8a | 2558 | return index; |
f2d76237 RD |
2559 | } |
2560 | ||
2561 | wxGridCellRenderer* wxGridTypeRegistry::GetRenderer(int index) | |
2562 | { | |
2563 | wxGridCellRenderer* renderer = m_typeinfo[index]->m_renderer; | |
faec5a43 SN |
2564 | if (renderer) |
2565 | renderer->IncRef(); | |
f2d76237 RD |
2566 | return renderer; |
2567 | } | |
2568 | ||
0b190b0f | 2569 | wxGridCellEditor* wxGridTypeRegistry::GetEditor(int index) |
f2d76237 RD |
2570 | { |
2571 | wxGridCellEditor* editor = m_typeinfo[index]->m_editor; | |
faec5a43 SN |
2572 | if (editor) |
2573 | editor->IncRef(); | |
f2d76237 RD |
2574 | return editor; |
2575 | } | |
2576 | ||
758cbedf VZ |
2577 | // ---------------------------------------------------------------------------- |
2578 | // wxGridTableBase | |
2579 | // ---------------------------------------------------------------------------- | |
2580 | ||
f85afd4e MB |
2581 | IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase, wxObject ) |
2582 | ||
2583 | ||
2584 | wxGridTableBase::wxGridTableBase() | |
f85afd4e MB |
2585 | { |
2586 | m_view = (wxGrid *) NULL; | |
b99be8fb | 2587 | m_attrProvider = (wxGridCellAttrProvider *) NULL; |
f85afd4e MB |
2588 | } |
2589 | ||
2590 | wxGridTableBase::~wxGridTableBase() | |
2591 | { | |
b99be8fb VZ |
2592 | delete m_attrProvider; |
2593 | } | |
2594 | ||
2595 | void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider *attrProvider) | |
2596 | { | |
2597 | delete m_attrProvider; | |
2598 | m_attrProvider = attrProvider; | |
f85afd4e MB |
2599 | } |
2600 | ||
f2d76237 RD |
2601 | bool wxGridTableBase::CanHaveAttributes() |
2602 | { | |
2603 | if ( ! GetAttrProvider() ) | |
2604 | { | |
2605 | // use the default attr provider by default | |
2606 | SetAttrProvider(new wxGridCellAttrProvider); | |
2607 | } | |
2608 | return TRUE; | |
2609 | } | |
2610 | ||
19d7140e | 2611 | wxGridCellAttr *wxGridTableBase::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) |
b99be8fb VZ |
2612 | { |
2613 | if ( m_attrProvider ) | |
19d7140e | 2614 | return m_attrProvider->GetAttr(row, col, kind); |
b99be8fb VZ |
2615 | else |
2616 | return (wxGridCellAttr *)NULL; | |
2617 | } | |
2618 | ||
758cbedf | 2619 | void wxGridTableBase::SetAttr(wxGridCellAttr* attr, int row, int col) |
b99be8fb VZ |
2620 | { |
2621 | if ( m_attrProvider ) | |
2622 | { | |
19d7140e | 2623 | attr->SetKind(wxGridCellAttr::Cell); |
b99be8fb VZ |
2624 | m_attrProvider->SetAttr(attr, row, col); |
2625 | } | |
2626 | else | |
2627 | { | |
2628 | // as we take ownership of the pointer and don't store it, we must | |
2629 | // free it now | |
39bcce60 | 2630 | wxSafeDecRef(attr); |
b99be8fb VZ |
2631 | } |
2632 | } | |
2633 | ||
758cbedf VZ |
2634 | void wxGridTableBase::SetRowAttr(wxGridCellAttr *attr, int row) |
2635 | { | |
2636 | if ( m_attrProvider ) | |
2637 | { | |
19d7140e | 2638 | attr->SetKind(wxGridCellAttr::Row); |
758cbedf VZ |
2639 | m_attrProvider->SetRowAttr(attr, row); |
2640 | } | |
2641 | else | |
2642 | { | |
2643 | // as we take ownership of the pointer and don't store it, we must | |
2644 | // free it now | |
39bcce60 | 2645 | wxSafeDecRef(attr); |
758cbedf VZ |
2646 | } |
2647 | } | |
2648 | ||
2649 | void wxGridTableBase::SetColAttr(wxGridCellAttr *attr, int col) | |
2650 | { | |
2651 | if ( m_attrProvider ) | |
2652 | { | |
19d7140e | 2653 | attr->SetKind(wxGridCellAttr::Col); |
758cbedf VZ |
2654 | m_attrProvider->SetColAttr(attr, col); |
2655 | } | |
2656 | else | |
2657 | { | |
2658 | // as we take ownership of the pointer and don't store it, we must | |
2659 | // free it now | |
39bcce60 | 2660 | wxSafeDecRef(attr); |
758cbedf VZ |
2661 | } |
2662 | } | |
2663 | ||
aa5e1f75 SN |
2664 | bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos), |
2665 | size_t WXUNUSED(numRows) ) | |
f85afd4e | 2666 | { |
f6bcfd97 | 2667 | wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") ); |
8f177c8e | 2668 | |
f85afd4e MB |
2669 | return FALSE; |
2670 | } | |
2671 | ||
aa5e1f75 | 2672 | bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows) ) |
f85afd4e | 2673 | { |
f6bcfd97 | 2674 | wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function")); |
8f177c8e | 2675 | |
f85afd4e MB |
2676 | return FALSE; |
2677 | } | |
2678 | ||
aa5e1f75 SN |
2679 | bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos), |
2680 | size_t WXUNUSED(numRows) ) | |
f85afd4e | 2681 | { |
f6bcfd97 | 2682 | wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function")); |
8f177c8e | 2683 | |
f85afd4e MB |
2684 | return FALSE; |
2685 | } | |
2686 | ||
aa5e1f75 SN |
2687 | bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos), |
2688 | size_t WXUNUSED(numCols) ) | |
f85afd4e | 2689 | { |
f6bcfd97 | 2690 | wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function")); |
8f177c8e | 2691 | |
f85afd4e MB |
2692 | return FALSE; |
2693 | } | |
2694 | ||
aa5e1f75 | 2695 | bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols) ) |
f85afd4e | 2696 | { |
f6bcfd97 | 2697 | wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function")); |
8f177c8e | 2698 | |
f85afd4e MB |
2699 | return FALSE; |
2700 | } | |
2701 | ||
aa5e1f75 SN |
2702 | bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos), |
2703 | size_t WXUNUSED(numCols) ) | |
f85afd4e | 2704 | { |
f6bcfd97 | 2705 | wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function")); |
8f177c8e | 2706 | |
f85afd4e MB |
2707 | return FALSE; |
2708 | } | |
2709 | ||
2710 | ||
2711 | wxString wxGridTableBase::GetRowLabelValue( int row ) | |
2712 | { | |
2713 | wxString s; | |
f2d76237 RD |
2714 | s << row + 1; // RD: Starting the rows at zero confuses users, no matter |
2715 | // how much it makes sense to us geeks. | |
f85afd4e MB |
2716 | return s; |
2717 | } | |
2718 | ||
2719 | wxString wxGridTableBase::GetColLabelValue( int col ) | |
2720 | { | |
2721 | // default col labels are: | |
2722 | // cols 0 to 25 : A-Z | |
2723 | // cols 26 to 675 : AA-ZZ | |
2724 | // etc. | |
2725 | ||
2726 | wxString s; | |
2727 | unsigned int i, n; | |
2728 | for ( n = 1; ; n++ ) | |
2729 | { | |
f0102d2a | 2730 | s += (_T('A') + (wxChar)( col%26 )); |
f85afd4e MB |
2731 | col = col/26 - 1; |
2732 | if ( col < 0 ) break; | |
2733 | } | |
2734 | ||
2735 | // reverse the string... | |
2736 | wxString s2; | |
2737 | for ( i = 0; i < n; i++ ) | |
2738 | { | |
2739 | s2 += s[n-i-1]; | |
2740 | } | |
2741 | ||
2742 | return s2; | |
2743 | } | |
2744 | ||
2745 | ||
f2d76237 RD |
2746 | wxString wxGridTableBase::GetTypeName( int WXUNUSED(row), int WXUNUSED(col) ) |
2747 | { | |
816be743 | 2748 | return wxGRID_VALUE_STRING; |
f2d76237 RD |
2749 | } |
2750 | ||
2751 | bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row), int WXUNUSED(col), | |
2752 | const wxString& typeName ) | |
2753 | { | |
816be743 | 2754 | return typeName == wxGRID_VALUE_STRING; |
f2d76237 RD |
2755 | } |
2756 | ||
2757 | bool wxGridTableBase::CanSetValueAs( int row, int col, const wxString& typeName ) | |
2758 | { | |
2759 | return CanGetValueAs(row, col, typeName); | |
2760 | } | |
2761 | ||
2762 | long wxGridTableBase::GetValueAsLong( int WXUNUSED(row), int WXUNUSED(col) ) | |
2763 | { | |
2764 | return 0; | |
2765 | } | |
2766 | ||
2767 | double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row), int WXUNUSED(col) ) | |
2768 | { | |
2769 | return 0.0; | |
2770 | } | |
2771 | ||
2772 | bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row), int WXUNUSED(col) ) | |
2773 | { | |
2774 | return FALSE; | |
2775 | } | |
2776 | ||
2777 | void wxGridTableBase::SetValueAsLong( int WXUNUSED(row), int WXUNUSED(col), | |
2778 | long WXUNUSED(value) ) | |
2779 | { | |
2780 | } | |
2781 | ||
2782 | void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row), int WXUNUSED(col), | |
2783 | double WXUNUSED(value) ) | |
2784 | { | |
2785 | } | |
2786 | ||
2787 | void wxGridTableBase::SetValueAsBool( int WXUNUSED(row), int WXUNUSED(col), | |
2788 | bool WXUNUSED(value) ) | |
2789 | { | |
2790 | } | |
2791 | ||
2792 | ||
2793 | void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row), int WXUNUSED(col), | |
2794 | const wxString& WXUNUSED(typeName) ) | |
2795 | { | |
2796 | return NULL; | |
2797 | } | |
2798 | ||
2799 | void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row), int WXUNUSED(col), | |
2800 | const wxString& WXUNUSED(typeName), | |
2801 | void* WXUNUSED(value) ) | |
2802 | { | |
2803 | } | |
2804 | ||
f85afd4e MB |
2805 | ////////////////////////////////////////////////////////////////////// |
2806 | // | |
2807 | // Message class for the grid table to send requests and notifications | |
2808 | // to the grid view | |
2809 | // | |
2810 | ||
2811 | wxGridTableMessage::wxGridTableMessage() | |
2812 | { | |
2813 | m_table = (wxGridTableBase *) NULL; | |
2814 | m_id = -1; | |
2815 | m_comInt1 = -1; | |
2816 | m_comInt2 = -1; | |
2817 | } | |
2818 | ||
2819 | wxGridTableMessage::wxGridTableMessage( wxGridTableBase *table, int id, | |
2820 | int commandInt1, int commandInt2 ) | |
2821 | { | |
2822 | m_table = table; | |
2823 | m_id = id; | |
2824 | m_comInt1 = commandInt1; | |
2825 | m_comInt2 = commandInt2; | |
2826 | } | |
2827 | ||
2828 | ||
2829 | ||
2830 | ////////////////////////////////////////////////////////////////////// | |
2831 | // | |
2832 | // A basic grid table for string data. An object of this class will | |
2833 | // created by wxGrid if you don't specify an alternative table class. | |
2834 | // | |
2835 | ||
223d09f6 | 2836 | WX_DEFINE_OBJARRAY(wxGridStringArray) |
f85afd4e MB |
2837 | |
2838 | IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase ) | |
2839 | ||
2840 | wxGridStringTable::wxGridStringTable() | |
2841 | : wxGridTableBase() | |
2842 | { | |
2843 | } | |
2844 | ||
2845 | wxGridStringTable::wxGridStringTable( int numRows, int numCols ) | |
2846 | : wxGridTableBase() | |
2847 | { | |
2848 | int row, col; | |
8f177c8e | 2849 | |
f85afd4e MB |
2850 | m_data.Alloc( numRows ); |
2851 | ||
2852 | wxArrayString sa; | |
2853 | sa.Alloc( numCols ); | |
2854 | for ( col = 0; col < numCols; col++ ) | |
2855 | { | |
2856 | sa.Add( wxEmptyString ); | |
2857 | } | |
8f177c8e | 2858 | |
f85afd4e MB |
2859 | for ( row = 0; row < numRows; row++ ) |
2860 | { | |
2861 | m_data.Add( sa ); | |
2862 | } | |
2863 | } | |
2864 | ||
2865 | wxGridStringTable::~wxGridStringTable() | |
2866 | { | |
2867 | } | |
2868 | ||
e32352cf | 2869 | int wxGridStringTable::GetNumberRows() |
f85afd4e MB |
2870 | { |
2871 | return m_data.GetCount(); | |
2872 | } | |
2873 | ||
e32352cf | 2874 | int wxGridStringTable::GetNumberCols() |
f85afd4e MB |
2875 | { |
2876 | if ( m_data.GetCount() > 0 ) | |
2877 | return m_data[0].GetCount(); | |
2878 | else | |
2879 | return 0; | |
2880 | } | |
2881 | ||
2882 | wxString wxGridStringTable::GetValue( int row, int col ) | |
2883 | { | |
831243b1 | 2884 | wxASSERT_MSG( (row < GetNumberRows()) && (col < GetNumberCols()), |
af547d51 VZ |
2885 | _T("invalid row or column index in wxGridStringTable") ); |
2886 | ||
f85afd4e MB |
2887 | return m_data[row][col]; |
2888 | } | |
2889 | ||
f2d76237 | 2890 | void wxGridStringTable::SetValue( int row, int col, const wxString& value ) |
f85afd4e | 2891 | { |
831243b1 | 2892 | wxASSERT_MSG( (row < GetNumberRows()) && (col < GetNumberCols()), |
af547d51 VZ |
2893 | _T("invalid row or column index in wxGridStringTable") ); |
2894 | ||
f2d76237 | 2895 | m_data[row][col] = value; |
f85afd4e MB |
2896 | } |
2897 | ||
2898 | bool wxGridStringTable::IsEmptyCell( int row, int col ) | |
2899 | { | |
831243b1 | 2900 | wxASSERT_MSG( (row < GetNumberRows()) && (col < GetNumberCols()), |
af547d51 VZ |
2901 | _T("invalid row or column index in wxGridStringTable") ); |
2902 | ||
f85afd4e MB |
2903 | return (m_data[row][col] == wxEmptyString); |
2904 | } | |
2905 | ||
f85afd4e MB |
2906 | void wxGridStringTable::Clear() |
2907 | { | |
2908 | int row, col; | |
2909 | int numRows, numCols; | |
8f177c8e | 2910 | |
f85afd4e MB |
2911 | numRows = m_data.GetCount(); |
2912 | if ( numRows > 0 ) | |
2913 | { | |
2914 | numCols = m_data[0].GetCount(); | |
2915 | ||
2916 | for ( row = 0; row < numRows; row++ ) | |
2917 | { | |
2918 | for ( col = 0; col < numCols; col++ ) | |
2919 | { | |
2920 | m_data[row][col] = wxEmptyString; | |
2921 | } | |
2922 | } | |
2923 | } | |
2924 | } | |
2925 | ||
2926 | ||
2927 | bool wxGridStringTable::InsertRows( size_t pos, size_t numRows ) | |
2928 | { | |
2929 | size_t row, col; | |
2930 | ||
2931 | size_t curNumRows = m_data.GetCount(); | |
f6bcfd97 BP |
2932 | size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : |
2933 | ( GetView() ? GetView()->GetNumberCols() : 0 ) ); | |
8f177c8e | 2934 | |
f85afd4e MB |
2935 | if ( pos >= curNumRows ) |
2936 | { | |
2937 | return AppendRows( numRows ); | |
2938 | } | |
8f177c8e | 2939 | |
f85afd4e MB |
2940 | wxArrayString sa; |
2941 | sa.Alloc( curNumCols ); | |
2942 | for ( col = 0; col < curNumCols; col++ ) | |
2943 | { | |
2944 | sa.Add( wxEmptyString ); | |
2945 | } | |
2946 | ||
2947 | for ( row = pos; row < pos + numRows; row++ ) | |
2948 | { | |
2949 | m_data.Insert( sa, row ); | |
2950 | } | |
f85afd4e MB |
2951 | if ( GetView() ) |
2952 | { | |
2953 | wxGridTableMessage msg( this, | |
2954 | wxGRIDTABLE_NOTIFY_ROWS_INSERTED, | |
2955 | pos, | |
2956 | numRows ); | |
8f177c8e | 2957 | |
f85afd4e MB |
2958 | GetView()->ProcessTableMessage( msg ); |
2959 | } | |
2960 | ||
2961 | return TRUE; | |
2962 | } | |
2963 | ||
2964 | bool wxGridStringTable::AppendRows( size_t numRows ) | |
2965 | { | |
2966 | size_t row, col; | |
2967 | ||
2968 | size_t curNumRows = m_data.GetCount(); | |
f6bcfd97 BP |
2969 | size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : |
2970 | ( GetView() ? GetView()->GetNumberCols() : 0 ) ); | |
8f177c8e | 2971 | |
f85afd4e MB |
2972 | wxArrayString sa; |
2973 | if ( curNumCols > 0 ) | |
2974 | { | |
2975 | sa.Alloc( curNumCols ); | |
2976 | for ( col = 0; col < curNumCols; col++ ) | |
2977 | { | |
2978 | sa.Add( wxEmptyString ); | |
2979 | } | |
2980 | } | |
8f177c8e | 2981 | |
f85afd4e MB |
2982 | for ( row = 0; row < numRows; row++ ) |
2983 | { | |
2984 | m_data.Add( sa ); | |
2985 | } | |
2986 | ||
2987 | if ( GetView() ) | |
2988 | { | |
2989 | wxGridTableMessage msg( this, | |
2990 | wxGRIDTABLE_NOTIFY_ROWS_APPENDED, | |
2991 | numRows ); | |
8f177c8e | 2992 | |
f85afd4e MB |
2993 | GetView()->ProcessTableMessage( msg ); |
2994 | } | |
2995 | ||
8f177c8e | 2996 | return TRUE; |
f85afd4e MB |
2997 | } |
2998 | ||
2999 | bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows ) | |
3000 | { | |
3001 | size_t n; | |
3002 | ||
3003 | size_t curNumRows = m_data.GetCount(); | |
8f177c8e | 3004 | |
f85afd4e MB |
3005 | if ( pos >= curNumRows ) |
3006 | { | |
bd3c6758 | 3007 | wxString errmsg; |
f6bcfd97 | 3008 | errmsg.Printf(wxT("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)\nPos value is invalid for present table with %d rows"), |
bd3c6758 | 3009 | pos, numRows, curNumRows ); |
f6bcfd97 | 3010 | wxFAIL_MSG( errmsg ); |
f85afd4e MB |
3011 | return FALSE; |
3012 | } | |
3013 | ||
3014 | if ( numRows > curNumRows - pos ) | |
3015 | { | |
3016 | numRows = curNumRows - pos; | |
3017 | } | |
8f177c8e | 3018 | |
f85afd4e MB |
3019 | if ( numRows >= curNumRows ) |
3020 | { | |
3021 | m_data.Empty(); // don't release memory just yet | |
3022 | } | |
3023 | else | |
3024 | { | |
3025 | for ( n = 0; n < numRows; n++ ) | |
3026 | { | |
b54e41c5 | 3027 | m_data.RemoveAt( pos ); |
f85afd4e MB |
3028 | } |
3029 | } | |
f85afd4e MB |
3030 | if ( GetView() ) |
3031 | { | |
3032 | wxGridTableMessage msg( this, | |
3033 | wxGRIDTABLE_NOTIFY_ROWS_DELETED, | |
3034 | pos, | |
3035 | numRows ); | |
8f177c8e | 3036 | |
f85afd4e MB |
3037 | GetView()->ProcessTableMessage( msg ); |
3038 | } | |
3039 | ||
8f177c8e | 3040 | return TRUE; |
f85afd4e MB |
3041 | } |
3042 | ||
3043 | bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) | |
3044 | { | |
3045 | size_t row, col; | |
3046 | ||
3047 | size_t curNumRows = m_data.GetCount(); | |
f6bcfd97 BP |
3048 | size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : |
3049 | ( GetView() ? GetView()->GetNumberCols() : 0 ) ); | |
8f177c8e | 3050 | |
f85afd4e MB |
3051 | if ( pos >= curNumCols ) |
3052 | { | |
3053 | return AppendCols( numCols ); | |
3054 | } | |
3055 | ||
3056 | for ( row = 0; row < curNumRows; row++ ) | |
3057 | { | |
3058 | for ( col = pos; col < pos + numCols; col++ ) | |
3059 | { | |
3060 | m_data[row].Insert( wxEmptyString, col ); | |
3061 | } | |
3062 | } | |
f85afd4e MB |
3063 | if ( GetView() ) |
3064 | { | |
3065 | wxGridTableMessage msg( this, | |
3066 | wxGRIDTABLE_NOTIFY_COLS_INSERTED, | |
3067 | pos, | |
3068 | numCols ); | |
8f177c8e | 3069 | |
f85afd4e MB |
3070 | GetView()->ProcessTableMessage( msg ); |
3071 | } | |
3072 | ||
3073 | return TRUE; | |
3074 | } | |
3075 | ||
3076 | bool wxGridStringTable::AppendCols( size_t numCols ) | |
3077 | { | |
3078 | size_t row, n; | |
3079 | ||
3080 | size_t curNumRows = m_data.GetCount(); | |
f6bcfd97 | 3081 | #if 0 |
f85afd4e MB |
3082 | if ( !curNumRows ) |
3083 | { | |
3084 | // TODO: something better than this ? | |
3085 | // | |
f6bcfd97 | 3086 | wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\nCall AppendRows() first") ); |
f85afd4e MB |
3087 | return FALSE; |
3088 | } | |
f6bcfd97 | 3089 | #endif |
8f177c8e | 3090 | |
f85afd4e MB |
3091 | for ( row = 0; row < curNumRows; row++ ) |
3092 | { | |
3093 | for ( n = 0; n < numCols; n++ ) | |
3094 | { | |
3095 | m_data[row].Add( wxEmptyString ); | |
3096 | } | |
3097 | } | |
3098 | ||
3099 | if ( GetView() ) | |
3100 | { | |
3101 | wxGridTableMessage msg( this, | |
3102 | wxGRIDTABLE_NOTIFY_COLS_APPENDED, | |
3103 | numCols ); | |
8f177c8e | 3104 | |
f85afd4e MB |
3105 | GetView()->ProcessTableMessage( msg ); |
3106 | } | |
3107 | ||
3108 | return TRUE; | |
3109 | } | |
3110 | ||
3111 | bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols ) | |
3112 | { | |
3113 | size_t row, n; | |
3114 | ||
3115 | size_t curNumRows = m_data.GetCount(); | |
f6bcfd97 BP |
3116 | size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : |
3117 | ( GetView() ? GetView()->GetNumberCols() : 0 ) ); | |
8f177c8e | 3118 | |
f85afd4e MB |
3119 | if ( pos >= curNumCols ) |
3120 | { | |
bd3c6758 | 3121 | wxString errmsg; |
f6bcfd97 | 3122 | errmsg.Printf( wxT("Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\nPos value is invalid for present table with %d cols"), |
bd3c6758 | 3123 | pos, numCols, curNumCols ); |
f6bcfd97 | 3124 | wxFAIL_MSG( errmsg ); |
8f177c8e | 3125 | return FALSE; |
f85afd4e MB |
3126 | } |
3127 | ||
3128 | if ( numCols > curNumCols - pos ) | |
3129 | { | |
8f177c8e | 3130 | numCols = curNumCols - pos; |
f85afd4e MB |
3131 | } |
3132 | ||
3133 | for ( row = 0; row < curNumRows; row++ ) | |
3134 | { | |
3135 | if ( numCols >= curNumCols ) | |
3136 | { | |
3137 | m_data[row].Clear(); | |
3138 | } | |
3139 | else | |
3140 | { | |
3141 | for ( n = 0; n < numCols; n++ ) | |
3142 | { | |
4403ced6 | 3143 | m_data[row].RemoveAt( pos ); |
f85afd4e MB |
3144 | } |
3145 | } | |
3146 | } | |
f85afd4e MB |
3147 | if ( GetView() ) |
3148 | { | |
3149 | wxGridTableMessage msg( this, | |
3150 | wxGRIDTABLE_NOTIFY_COLS_DELETED, | |
3151 | pos, | |
3152 | numCols ); | |
8f177c8e | 3153 | |
f85afd4e MB |
3154 | GetView()->ProcessTableMessage( msg ); |
3155 | } | |
3156 | ||
8f177c8e | 3157 | return TRUE; |
f85afd4e MB |
3158 | } |
3159 | ||
3160 | wxString wxGridStringTable::GetRowLabelValue( int row ) | |
3161 | { | |
3162 | if ( row > (int)(m_rowLabels.GetCount()) - 1 ) | |
3163 | { | |
3164 | // using default label | |
3165 | // | |
3166 | return wxGridTableBase::GetRowLabelValue( row ); | |
3167 | } | |
3168 | else | |
3169 | { | |
3170 | return m_rowLabels[ row ]; | |
3171 | } | |
3172 | } | |
3173 | ||
3174 | wxString wxGridStringTable::GetColLabelValue( int col ) | |
3175 | { | |
3176 | if ( col > (int)(m_colLabels.GetCount()) - 1 ) | |
3177 | { | |
3178 | // using default label | |
3179 | // | |
3180 | return wxGridTableBase::GetColLabelValue( col ); | |
3181 | } | |
3182 | else | |
3183 | { | |
3184 | return m_colLabels[ col ]; | |
3185 | } | |
3186 | } | |
3187 | ||
3188 | void wxGridStringTable::SetRowLabelValue( int row, const wxString& value ) | |
3189 | { | |
3190 | if ( row > (int)(m_rowLabels.GetCount()) - 1 ) | |
3191 | { | |
3192 | int n = m_rowLabels.GetCount(); | |
3193 | int i; | |
3194 | for ( i = n; i <= row; i++ ) | |
3195 | { | |
3196 | m_rowLabels.Add( wxGridTableBase::GetRowLabelValue(i) ); | |
3197 | } | |
3198 | } | |
3199 | ||
3200 | m_rowLabels[row] = value; | |
3201 | } | |
3202 | ||
3203 | void wxGridStringTable::SetColLabelValue( int col, const wxString& value ) | |
3204 | { | |
3205 | if ( col > (int)(m_colLabels.GetCount()) - 1 ) | |
3206 | { | |
3207 | int n = m_colLabels.GetCount(); | |
3208 | int i; | |
3209 | for ( i = n; i <= col; i++ ) | |
3210 | { | |
3211 | m_colLabels.Add( wxGridTableBase::GetColLabelValue(i) ); | |
3212 | } | |
3213 | } | |
3214 | ||
3215 | m_colLabels[col] = value; | |
3216 | } | |
3217 | ||
3218 | ||
3219 | ||
f85afd4e | 3220 | ////////////////////////////////////////////////////////////////////// |
2d66e025 MB |
3221 | ////////////////////////////////////////////////////////////////////// |
3222 | ||
3223 | IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow, wxWindow ) | |
3224 | ||
3225 | BEGIN_EVENT_TABLE( wxGridRowLabelWindow, wxWindow ) | |
3226 | EVT_PAINT( wxGridRowLabelWindow::OnPaint ) | |
b51c3f27 | 3227 | EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel) |
2d66e025 MB |
3228 | EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent ) |
3229 | EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown ) | |
f6bcfd97 | 3230 | EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp ) |
2d66e025 MB |
3231 | END_EVENT_TABLE() |
3232 | ||
60ff3b99 VZ |
3233 | wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid *parent, |
3234 | wxWindowID id, | |
2d66e025 | 3235 | const wxPoint &pos, const wxSize &size ) |
ebd773c6 | 3236 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS ) |
2d66e025 MB |
3237 | { |
3238 | m_owner = parent; | |
3239 | } | |
3240 | ||
aa5e1f75 | 3241 | void wxGridRowLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
2d66e025 MB |
3242 | { |
3243 | wxPaintDC dc(this); | |
3244 | ||
3245 | // NO - don't do this because it will set both the x and y origin | |
3246 | // coords to match the parent scrolled window and we just want to | |
3247 | // set the y coord - MB | |
3248 | // | |
3249 | // m_owner->PrepareDC( dc ); | |
60ff3b99 | 3250 | |
790ad94f | 3251 | int x, y; |
2d66e025 MB |
3252 | m_owner->CalcUnscrolledPosition( 0, 0, &x, &y ); |
3253 | dc.SetDeviceOrigin( 0, -y ); | |
60ff3b99 | 3254 | |
d10f4bf9 VZ |
3255 | wxArrayInt rows = m_owner->CalcRowLabelsExposed( GetUpdateRegion() ); |
3256 | m_owner->DrawRowLabels( dc , rows ); | |
2d66e025 MB |
3257 | } |
3258 | ||
3259 | ||
3260 | void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent& event ) | |
3261 | { | |
3262 | m_owner->ProcessRowLabelMouseEvent( event ); | |
3263 | } | |
3264 | ||
3265 | ||
b51c3f27 RD |
3266 | void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent& event ) |
3267 | { | |
3268 | m_owner->GetEventHandler()->ProcessEvent(event); | |
3269 | } | |
3270 | ||
3271 | ||
2d66e025 MB |
3272 | // This seems to be required for wxMotif otherwise the mouse |
3273 | // cursor must be in the cell edit control to get key events | |
3274 | // | |
3275 | void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent& event ) | |
3276 | { | |
ffdd3c98 | 3277 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
2d66e025 MB |
3278 | } |
3279 | ||
f6bcfd97 BP |
3280 | void wxGridRowLabelWindow::OnKeyUp( wxKeyEvent& event ) |
3281 | { | |
ffdd3c98 | 3282 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
f6bcfd97 BP |
3283 | } |
3284 | ||
2d66e025 MB |
3285 | |
3286 | ||
3287 | ////////////////////////////////////////////////////////////////////// | |
3288 | ||
3289 | IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow, wxWindow ) | |
3290 | ||
3291 | BEGIN_EVENT_TABLE( wxGridColLabelWindow, wxWindow ) | |
3292 | EVT_PAINT( wxGridColLabelWindow::OnPaint ) | |
b51c3f27 | 3293 | EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel) |
2d66e025 MB |
3294 | EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent ) |
3295 | EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown ) | |
f6bcfd97 | 3296 | EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp ) |
2d66e025 MB |
3297 | END_EVENT_TABLE() |
3298 | ||
60ff3b99 VZ |
3299 | wxGridColLabelWindow::wxGridColLabelWindow( wxGrid *parent, |
3300 | wxWindowID id, | |
2d66e025 | 3301 | const wxPoint &pos, const wxSize &size ) |
ebd773c6 | 3302 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS ) |
2d66e025 MB |
3303 | { |
3304 | m_owner = parent; | |
3305 | } | |
3306 | ||
aa5e1f75 | 3307 | void wxGridColLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
2d66e025 MB |
3308 | { |
3309 | wxPaintDC dc(this); | |
3310 | ||
3311 | // NO - don't do this because it will set both the x and y origin | |
3312 | // coords to match the parent scrolled window and we just want to | |
3313 | // set the x coord - MB | |
3314 | // | |
3315 | // m_owner->PrepareDC( dc ); | |
60ff3b99 | 3316 | |
790ad94f | 3317 | int x, y; |
2d66e025 MB |
3318 | m_owner->CalcUnscrolledPosition( 0, 0, &x, &y ); |
3319 | dc.SetDeviceOrigin( -x, 0 ); | |
3320 | ||
d10f4bf9 VZ |
3321 | wxArrayInt cols = m_owner->CalcColLabelsExposed( GetUpdateRegion() ); |
3322 | m_owner->DrawColLabels( dc , cols ); | |
2d66e025 MB |
3323 | } |
3324 | ||
3325 | ||
3326 | void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent& event ) | |
3327 | { | |
3328 | m_owner->ProcessColLabelMouseEvent( event ); | |
3329 | } | |
3330 | ||
b51c3f27 RD |
3331 | void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent& event ) |
3332 | { | |
3333 | m_owner->GetEventHandler()->ProcessEvent(event); | |
3334 | } | |
3335 | ||
2d66e025 MB |
3336 | |
3337 | // This seems to be required for wxMotif otherwise the mouse | |
3338 | // cursor must be in the cell edit control to get key events | |
3339 | // | |
3340 | void wxGridColLabelWindow::OnKeyDown( wxKeyEvent& event ) | |
3341 | { | |
ffdd3c98 | 3342 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
2d66e025 MB |
3343 | } |
3344 | ||
f6bcfd97 BP |
3345 | void wxGridColLabelWindow::OnKeyUp( wxKeyEvent& event ) |
3346 | { | |
ffdd3c98 | 3347 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
f6bcfd97 BP |
3348 | } |
3349 | ||
2d66e025 MB |
3350 | |
3351 | ||
3352 | ////////////////////////////////////////////////////////////////////// | |
3353 | ||
3354 | IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow, wxWindow ) | |
3355 | ||
3356 | BEGIN_EVENT_TABLE( wxGridCornerLabelWindow, wxWindow ) | |
b51c3f27 | 3357 | EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel) |
2d66e025 | 3358 | EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent ) |
d2fdd8d2 | 3359 | EVT_PAINT( wxGridCornerLabelWindow::OnPaint) |
2d66e025 | 3360 | EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown ) |
f6bcfd97 | 3361 | EVT_KEY_UP( wxGridCornerLabelWindow::OnKeyUp ) |
2d66e025 MB |
3362 | END_EVENT_TABLE() |
3363 | ||
60ff3b99 VZ |
3364 | wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid *parent, |
3365 | wxWindowID id, | |
2d66e025 | 3366 | const wxPoint &pos, const wxSize &size ) |
ebd773c6 | 3367 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS ) |
2d66e025 MB |
3368 | { |
3369 | m_owner = parent; | |
3370 | } | |
3371 | ||
d2fdd8d2 RR |
3372 | void wxGridCornerLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
3373 | { | |
3374 | wxPaintDC dc(this); | |
b99be8fb | 3375 | |
d2fdd8d2 RR |
3376 | int client_height = 0; |
3377 | int client_width = 0; | |
3378 | GetClientSize( &client_width, &client_height ); | |
b99be8fb | 3379 | |
d2fdd8d2 RR |
3380 | dc.SetPen( *wxBLACK_PEN ); |
3381 | dc.DrawLine( client_width-1, client_height-1, client_width-1, 0 ); | |
3382 | dc.DrawLine( client_width-1, client_height-1, 0, client_height-1 ); | |
b99be8fb | 3383 | |
d2fdd8d2 RR |
3384 | dc.SetPen( *wxWHITE_PEN ); |
3385 | dc.DrawLine( 0, 0, client_width, 0 ); | |
3386 | dc.DrawLine( 0, 0, 0, client_height ); | |
3387 | } | |
3388 | ||
2d66e025 MB |
3389 | |
3390 | void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent& event ) | |
3391 | { | |
3392 | m_owner->ProcessCornerLabelMouseEvent( event ); | |
3393 | } | |
3394 | ||
3395 | ||
b51c3f27 RD |
3396 | void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent& event ) |
3397 | { | |
3398 | m_owner->GetEventHandler()->ProcessEvent(event); | |
3399 | } | |
3400 | ||
2d66e025 MB |
3401 | // This seems to be required for wxMotif otherwise the mouse |
3402 | // cursor must be in the cell edit control to get key events | |
3403 | // | |
3404 | void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent& event ) | |
3405 | { | |
ffdd3c98 | 3406 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
2d66e025 MB |
3407 | } |
3408 | ||
f6bcfd97 BP |
3409 | void wxGridCornerLabelWindow::OnKeyUp( wxKeyEvent& event ) |
3410 | { | |
ffdd3c98 | 3411 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
f6bcfd97 BP |
3412 | } |
3413 | ||
2d66e025 MB |
3414 | |
3415 | ||
f85afd4e MB |
3416 | ////////////////////////////////////////////////////////////////////// |
3417 | ||
2d66e025 MB |
3418 | IMPLEMENT_DYNAMIC_CLASS( wxGridWindow, wxPanel ) |
3419 | ||
3420 | BEGIN_EVENT_TABLE( wxGridWindow, wxPanel ) | |
3421 | EVT_PAINT( wxGridWindow::OnPaint ) | |
b51c3f27 | 3422 | EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel) |
2d66e025 MB |
3423 | EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent ) |
3424 | EVT_KEY_DOWN( wxGridWindow::OnKeyDown ) | |
f6bcfd97 | 3425 | EVT_KEY_UP( wxGridWindow::OnKeyUp ) |
2796cce3 | 3426 | EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground ) |
2d66e025 MB |
3427 | END_EVENT_TABLE() |
3428 | ||
60ff3b99 VZ |
3429 | wxGridWindow::wxGridWindow( wxGrid *parent, |
3430 | wxGridRowLabelWindow *rowLblWin, | |
2d66e025 MB |
3431 | wxGridColLabelWindow *colLblWin, |
3432 | wxWindowID id, const wxPoint &pos, const wxSize &size ) | |
ebd773c6 | 3433 | : wxPanel( parent, id, pos, size, wxWANTS_CHARS, "grid window" ) |
2d66e025 MB |
3434 | { |
3435 | m_owner = parent; | |
3436 | m_rowLabelWin = rowLblWin; | |
3437 | m_colLabelWin = colLblWin; | |
edb89f7e | 3438 | SetBackgroundColour(_T("WHITE")); |
2d66e025 MB |
3439 | } |
3440 | ||
3441 | ||
3442 | wxGridWindow::~wxGridWindow() | |
3443 | { | |
3444 | } | |
3445 | ||
3446 | ||
3447 | void wxGridWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
3448 | { | |
3449 | wxPaintDC dc( this ); | |
3450 | m_owner->PrepareDC( dc ); | |
796df70a | 3451 | wxRegion reg = GetUpdateRegion(); |
d10f4bf9 VZ |
3452 | wxGridCellCoordsArray DirtyCells = m_owner->CalcCellsExposed( reg ); |
3453 | m_owner->DrawGridCellArea( dc , DirtyCells); | |
9496deb5 | 3454 | #if WXGRID_DRAW_LINES |
796df70a SN |
3455 | m_owner->DrawAllGridLines( dc, reg ); |
3456 | #endif | |
a5777624 | 3457 | m_owner->DrawGridSpace( dc ); |
d10f4bf9 | 3458 | m_owner->DrawHighlight( dc , DirtyCells ); |
2d66e025 MB |
3459 | } |
3460 | ||
3461 | ||
3462 | void wxGridWindow::ScrollWindow( int dx, int dy, const wxRect *rect ) | |
3463 | { | |
3464 | wxPanel::ScrollWindow( dx, dy, rect ); | |
3465 | m_rowLabelWin->ScrollWindow( 0, dy, rect ); | |
3466 | m_colLabelWin->ScrollWindow( dx, 0, rect ); | |
3467 | } | |
3468 | ||
3469 | ||
3470 | void wxGridWindow::OnMouseEvent( wxMouseEvent& event ) | |
3471 | { | |
3472 | m_owner->ProcessGridCellMouseEvent( event ); | |
3473 | } | |
3474 | ||
b51c3f27 RD |
3475 | void wxGridWindow::OnMouseWheel( wxMouseEvent& event ) |
3476 | { | |
3477 | m_owner->GetEventHandler()->ProcessEvent(event); | |
3478 | } | |
2d66e025 | 3479 | |
f6bcfd97 | 3480 | // This seems to be required for wxMotif/wxGTK otherwise the mouse |
2d66e025 MB |
3481 | // cursor must be in the cell edit control to get key events |
3482 | // | |
3483 | void wxGridWindow::OnKeyDown( wxKeyEvent& event ) | |
3484 | { | |
ffdd3c98 | 3485 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
2d66e025 | 3486 | } |
f85afd4e | 3487 | |
f6bcfd97 BP |
3488 | void wxGridWindow::OnKeyUp( wxKeyEvent& event ) |
3489 | { | |
ffdd3c98 | 3490 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
f6bcfd97 | 3491 | } |
7c8a8ad5 | 3492 | |
aa5e1f75 | 3493 | void wxGridWindow::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ) |
8dd4f536 | 3494 | { |
8dd4f536 | 3495 | } |
025562fe | 3496 | |
2d66e025 MB |
3497 | |
3498 | ////////////////////////////////////////////////////////////////////// | |
3499 | ||
07296f0b | 3500 | |
2d66e025 MB |
3501 | IMPLEMENT_DYNAMIC_CLASS( wxGrid, wxScrolledWindow ) |
3502 | ||
3503 | BEGIN_EVENT_TABLE( wxGrid, wxScrolledWindow ) | |
f85afd4e MB |
3504 | EVT_PAINT( wxGrid::OnPaint ) |
3505 | EVT_SIZE( wxGrid::OnSize ) | |
f85afd4e | 3506 | EVT_KEY_DOWN( wxGrid::OnKeyDown ) |
f6bcfd97 | 3507 | EVT_KEY_UP( wxGrid::OnKeyUp ) |
2796cce3 | 3508 | EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground ) |
f85afd4e | 3509 | END_EVENT_TABLE() |
8f177c8e | 3510 | |
2d66e025 MB |
3511 | wxGrid::wxGrid( wxWindow *parent, |
3512 | wxWindowID id, | |
3513 | const wxPoint& pos, | |
3514 | const wxSize& size, | |
3515 | long style, | |
3516 | const wxString& name ) | |
ebd773c6 | 3517 | : wxScrolledWindow( parent, id, pos, size, (style | wxWANTS_CHARS), name ), |
af547d51 VZ |
3518 | m_colMinWidths(GRID_HASH_SIZE), |
3519 | m_rowMinHeights(GRID_HASH_SIZE) | |
2d66e025 MB |
3520 | { |
3521 | Create(); | |
58dd5b3b MB |
3522 | } |
3523 | ||
3524 | ||
3525 | wxGrid::~wxGrid() | |
3526 | { | |
606b005f JS |
3527 | // Must do this or ~wxScrollHelper will pop the wrong event handler |
3528 | SetTargetWindow(this); | |
0a976765 | 3529 | ClearAttrCache(); |
39bcce60 | 3530 | wxSafeDecRef(m_defaultCellAttr); |
0a976765 VZ |
3531 | |
3532 | #ifdef DEBUG_ATTR_CACHE | |
3533 | size_t total = gs_nAttrCacheHits + gs_nAttrCacheMisses; | |
3534 | wxPrintf(_T("wxGrid attribute cache statistics: " | |
3535 | "total: %u, hits: %u (%u%%)\n"), | |
3536 | total, gs_nAttrCacheHits, | |
3537 | total ? (gs_nAttrCacheHits*100) / total : 0); | |
3538 | #endif | |
3539 | ||
2796cce3 RD |
3540 | if (m_ownTable) |
3541 | delete m_table; | |
f2d76237 RD |
3542 | |
3543 | delete m_typeRegistry; | |
b5808881 | 3544 | delete m_selection; |
58dd5b3b MB |
3545 | } |
3546 | ||
2d66e025 | 3547 | |
58dd5b3b MB |
3548 | // |
3549 | // ----- internal init and update functions | |
3550 | // | |
3551 | ||
3552 | void wxGrid::Create() | |
f0102d2a | 3553 | { |
4634a5d6 | 3554 | m_created = FALSE; // set to TRUE by CreateGrid |
4634a5d6 MB |
3555 | |
3556 | m_table = (wxGridTableBase *) NULL; | |
2796cce3 | 3557 | m_ownTable = FALSE; |
2c9a89e0 RD |
3558 | |
3559 | m_cellEditCtrlEnabled = FALSE; | |
4634a5d6 | 3560 | |
2796cce3 RD |
3561 | m_defaultCellAttr = new wxGridCellAttr; |
3562 | m_defaultCellAttr->SetDefAttr(m_defaultCellAttr); | |
f2d76237 RD |
3563 | |
3564 | // Set default cell attributes | |
19d7140e | 3565 | m_defaultCellAttr->SetKind(wxGridCellAttr::Default); |
f2d76237 | 3566 | m_defaultCellAttr->SetFont(GetFont()); |
4c7277db | 3567 | m_defaultCellAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_TOP); |
f2d76237 RD |
3568 | m_defaultCellAttr->SetTextColour( |
3569 | wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT)); | |
3570 | m_defaultCellAttr->SetBackgroundColour( | |
3571 | wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); | |
3572 | m_defaultCellAttr->SetRenderer(new wxGridCellStringRenderer); | |
3573 | m_defaultCellAttr->SetEditor(new wxGridCellTextEditor); | |
2796cce3 RD |
3574 | |
3575 | ||
4634a5d6 MB |
3576 | m_numRows = 0; |
3577 | m_numCols = 0; | |
3578 | m_currentCellCoords = wxGridNoCellCoords; | |
b99be8fb | 3579 | |
18f9565d MB |
3580 | m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH; |
3581 | m_colLabelHeight = WXGRID_DEFAULT_COL_LABEL_HEIGHT; | |
2d66e025 | 3582 | |
c4608a8a | 3583 | // create the type registry |
f2d76237 | 3584 | m_typeRegistry = new wxGridTypeRegistry; |
b5808881 | 3585 | m_selection = 0; |
f2d76237 | 3586 | // subwindow components that make up the wxGrid |
7807d81c MB |
3587 | m_cornerLabelWin = new wxGridCornerLabelWindow( this, |
3588 | -1, | |
18f9565d MB |
3589 | wxDefaultPosition, |
3590 | wxDefaultSize ); | |
7807d81c | 3591 | |
60ff3b99 VZ |
3592 | m_rowLabelWin = new wxGridRowLabelWindow( this, |
3593 | -1, | |
18f9565d MB |
3594 | wxDefaultPosition, |
3595 | wxDefaultSize ); | |
2d66e025 MB |
3596 | |
3597 | m_colLabelWin = new wxGridColLabelWindow( this, | |
3598 | -1, | |
18f9565d MB |
3599 | wxDefaultPosition, |
3600 | wxDefaultSize ); | |
60ff3b99 | 3601 | |
60ff3b99 VZ |
3602 | m_gridWin = new wxGridWindow( this, |
3603 | m_rowLabelWin, | |
3604 | m_colLabelWin, | |
3605 | -1, | |
18f9565d | 3606 | wxDefaultPosition, |
2d66e025 MB |
3607 | wxDefaultSize ); |
3608 | ||
3609 | SetTargetWindow( m_gridWin ); | |
2d66e025 | 3610 | } |
f85afd4e | 3611 | |
2d66e025 | 3612 | |
b5808881 SN |
3613 | bool wxGrid::CreateGrid( int numRows, int numCols, |
3614 | wxGrid::wxGridSelectionModes selmode ) | |
2d66e025 | 3615 | { |
f6bcfd97 BP |
3616 | wxCHECK_MSG( !m_created, |
3617 | FALSE, | |
3618 | wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") ); | |
3619 | ||
3620 | m_numRows = numRows; | |
3621 | m_numCols = numCols; | |
3622 | ||
3623 | m_table = new wxGridStringTable( m_numRows, m_numCols ); | |
3624 | m_table->SetView( this ); | |
3625 | m_ownTable = TRUE; | |
3626 | m_selection = new wxGridSelection( this, selmode ); | |
3627 | Init(); | |
3628 | m_created = TRUE; | |
2d66e025 | 3629 | |
2796cce3 RD |
3630 | return m_created; |
3631 | } | |
3632 | ||
f1567cdd SN |
3633 | void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode) |
3634 | { | |
3635 | if ( !m_created ) | |
3636 | { | |
3637 | wxFAIL_MSG( wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") ); | |
3638 | } | |
3639 | else | |
3640 | m_selection->SetSelectionMode( selmode ); | |
3641 | } | |
3642 | ||
043d16b2 SN |
3643 | bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, |
3644 | wxGrid::wxGridSelectionModes selmode ) | |
2796cce3 RD |
3645 | { |
3646 | if ( m_created ) | |
3647 | { | |
fb295790 RD |
3648 | // RD: Actually, this should probably be allowed. I think it would be |
3649 | // nice to be able to switch multiple Tables in and out of a single | |
3650 | // View at runtime. Is there anything in the implmentation that would | |
3651 | // prevent this? | |
3652 | ||
d95b0c2b | 3653 | // At least, you now have to cope with m_selection |
2796cce3 RD |
3654 | wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") ); |
3655 | return FALSE; | |
3656 | } | |
3657 | else | |
3658 | { | |
3659 | m_numRows = table->GetNumberRows(); | |
3660 | m_numCols = table->GetNumberCols(); | |
3661 | ||
3662 | m_table = table; | |
3663 | m_table->SetView( this ); | |
3664 | if (takeOwnership) | |
3665 | m_ownTable = TRUE; | |
043d16b2 | 3666 | m_selection = new wxGridSelection( this, selmode ); |
f6bcfd97 | 3667 | Init(); |
2d66e025 MB |
3668 | m_created = TRUE; |
3669 | } | |
f85afd4e | 3670 | |
2d66e025 | 3671 | return m_created; |
f85afd4e MB |
3672 | } |
3673 | ||
2d66e025 | 3674 | |
f85afd4e MB |
3675 | void wxGrid::Init() |
3676 | { | |
f85afd4e MB |
3677 | m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH; |
3678 | m_colLabelHeight = WXGRID_DEFAULT_COL_LABEL_HEIGHT; | |
3679 | ||
60ff3b99 VZ |
3680 | if ( m_rowLabelWin ) |
3681 | { | |
3682 | m_labelBackgroundColour = m_rowLabelWin->GetBackgroundColour(); | |
3683 | } | |
3684 | else | |
3685 | { | |
3686 | m_labelBackgroundColour = wxColour( _T("WHITE") ); | |
3687 | } | |
3688 | ||
3689 | m_labelTextColour = wxColour( _T("BLACK") ); | |
f85afd4e | 3690 | |
0a976765 VZ |
3691 | // init attr cache |
3692 | m_attrCache.row = -1; | |
3693 | ||
f85afd4e MB |
3694 | // TODO: something better than this ? |
3695 | // | |
3696 | m_labelFont = this->GetFont(); | |
3697 | m_labelFont.SetWeight( m_labelFont.GetWeight() + 2 ); | |
8f177c8e | 3698 | |
4c7277db MB |
3699 | m_rowLabelHorizAlign = wxALIGN_LEFT; |
3700 | m_rowLabelVertAlign = wxALIGN_CENTRE; | |
f85afd4e | 3701 | |
4c7277db MB |
3702 | m_colLabelHorizAlign = wxALIGN_CENTRE; |
3703 | m_colLabelVertAlign = wxALIGN_TOP; | |
f85afd4e | 3704 | |
f85afd4e | 3705 | m_defaultColWidth = WXGRID_DEFAULT_COL_WIDTH; |
1f1ce288 MB |
3706 | m_defaultRowHeight = m_gridWin->GetCharHeight(); |
3707 | ||
d2fdd8d2 | 3708 | #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl() |
1f1ce288 MB |
3709 | m_defaultRowHeight += 8; |
3710 | #else | |
3711 | m_defaultRowHeight += 4; | |
3712 | #endif | |
3713 | ||
2d66e025 | 3714 | m_gridLineColour = wxColour( 128, 128, 255 ); |
f85afd4e | 3715 | m_gridLinesEnabled = TRUE; |
f6bcfd97 | 3716 | m_cellHighlightColour = m_gridLineColour; |
bf7945ce | 3717 | m_cellHighlightPenWidth = 2; |
d2520c85 | 3718 | m_cellHighlightROPenWidth = 1; |
8f177c8e | 3719 | |
58dd5b3b | 3720 | m_cursorMode = WXGRID_CURSOR_SELECT_CELL; |
e2b42eeb | 3721 | m_winCapture = (wxWindow *)NULL; |
6e8524b1 MB |
3722 | m_canDragRowSize = TRUE; |
3723 | m_canDragColSize = TRUE; | |
4cfa5de6 | 3724 | m_canDragGridSize = TRUE; |
f85afd4e MB |
3725 | m_dragLastPos = -1; |
3726 | m_dragRowOrCol = -1; | |
3727 | m_isDragging = FALSE; | |
07296f0b | 3728 | m_startDragPos = wxDefaultPosition; |
f85afd4e | 3729 | |
07296f0b | 3730 | m_waitForSlowClick = FALSE; |
025562fe | 3731 | |
f85afd4e MB |
3732 | m_rowResizeCursor = wxCursor( wxCURSOR_SIZENS ); |
3733 | m_colResizeCursor = wxCursor( wxCURSOR_SIZEWE ); | |
3734 | ||
3735 | m_currentCellCoords = wxGridNoCellCoords; | |
f85afd4e | 3736 | |
b5808881 SN |
3737 | m_selectingTopLeft = wxGridNoCellCoords; |
3738 | m_selectingBottomRight = wxGridNoCellCoords; | |
2796cce3 RD |
3739 | m_selectionBackground = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT); |
3740 | m_selectionForeground = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT); | |
8f177c8e | 3741 | |
f85afd4e MB |
3742 | m_editable = TRUE; // default for whole grid |
3743 | ||
2d66e025 MB |
3744 | m_inOnKeyDown = FALSE; |
3745 | m_batchCount = 0; | |
3c79cf49 | 3746 | |
266e8367 VZ |
3747 | m_extraWidth = |
3748 | m_extraHeight = 50; | |
3749 | ||
3c79cf49 | 3750 | CalcDimensions(); |
7c1cb261 VZ |
3751 | } |
3752 | ||
3753 | // ---------------------------------------------------------------------------- | |
3754 | // the idea is to call these functions only when necessary because they create | |
3755 | // quite big arrays which eat memory mostly unnecessary - in particular, if | |
3756 | // default widths/heights are used for all rows/columns, we may not use these | |
3757 | // arrays at all | |
3758 | // | |
3759 | // with some extra code, it should be possible to only store the | |
3760 | // widths/heights different from default ones but this will be done later... | |
3761 | // ---------------------------------------------------------------------------- | |
3762 | ||
3763 | void wxGrid::InitRowHeights() | |
3764 | { | |
3765 | m_rowHeights.Empty(); | |
3766 | m_rowBottoms.Empty(); | |
3767 | ||
3768 | m_rowHeights.Alloc( m_numRows ); | |
3769 | m_rowBottoms.Alloc( m_numRows ); | |
3770 | ||
3771 | int rowBottom = 0; | |
3772 | for ( int i = 0; i < m_numRows; i++ ) | |
3773 | { | |
3774 | m_rowHeights.Add( m_defaultRowHeight ); | |
3775 | rowBottom += m_defaultRowHeight; | |
3776 | m_rowBottoms.Add( rowBottom ); | |
3777 | } | |
3778 | } | |
3779 | ||
3780 | void wxGrid::InitColWidths() | |
3781 | { | |
3782 | m_colWidths.Empty(); | |
3783 | m_colRights.Empty(); | |
3784 | ||
3785 | m_colWidths.Alloc( m_numCols ); | |
3786 | m_colRights.Alloc( m_numCols ); | |
3787 | int colRight = 0; | |
3788 | for ( int i = 0; i < m_numCols; i++ ) | |
3789 | { | |
3790 | m_colWidths.Add( m_defaultColWidth ); | |
3791 | colRight += m_defaultColWidth; | |
3792 | m_colRights.Add( colRight ); | |
3793 | } | |
3794 | } | |
3795 | ||
3796 | int wxGrid::GetColWidth(int col) const | |
3797 | { | |
3798 | return m_colWidths.IsEmpty() ? m_defaultColWidth : m_colWidths[col]; | |
3799 | } | |
3800 | ||
3801 | int wxGrid::GetColLeft(int col) const | |
3802 | { | |
3803 | return m_colRights.IsEmpty() ? col * m_defaultColWidth | |
3804 | : m_colRights[col] - m_colWidths[col]; | |
3805 | } | |
3806 | ||
3807 | int wxGrid::GetColRight(int col) const | |
3808 | { | |
3809 | return m_colRights.IsEmpty() ? (col + 1) * m_defaultColWidth | |
3810 | : m_colRights[col]; | |
3811 | } | |
3812 | ||
3813 | int wxGrid::GetRowHeight(int row) const | |
3814 | { | |
3815 | return m_rowHeights.IsEmpty() ? m_defaultRowHeight : m_rowHeights[row]; | |
3816 | } | |
2d66e025 | 3817 | |
7c1cb261 VZ |
3818 | int wxGrid::GetRowTop(int row) const |
3819 | { | |
3820 | return m_rowBottoms.IsEmpty() ? row * m_defaultRowHeight | |
3821 | : m_rowBottoms[row] - m_rowHeights[row]; | |
f85afd4e MB |
3822 | } |
3823 | ||
7c1cb261 VZ |
3824 | int wxGrid::GetRowBottom(int row) const |
3825 | { | |
3826 | return m_rowBottoms.IsEmpty() ? (row + 1) * m_defaultRowHeight | |
3827 | : m_rowBottoms[row]; | |
3828 | } | |
f85afd4e MB |
3829 | |
3830 | void wxGrid::CalcDimensions() | |
3831 | { | |
f85afd4e | 3832 | int cw, ch; |
2d66e025 | 3833 | GetClientSize( &cw, &ch ); |
f85afd4e | 3834 | |
faec5a43 SN |
3835 | if ( m_colLabelWin->IsShown() ) |
3836 | cw -= m_rowLabelWidth; | |
3837 | if ( m_rowLabelWin->IsShown() ) | |
3838 | ch -= m_colLabelHeight; | |
60ff3b99 | 3839 | |
faec5a43 SN |
3840 | // grid total size |
3841 | int w = m_numCols > 0 ? GetColRight(m_numCols - 1) + m_extraWidth + 1 : 0; | |
3842 | int h = m_numRows > 0 ? GetRowBottom(m_numRows - 1) + m_extraHeight + 1 : 0; | |
3843 | ||
3844 | // preserve (more or less) the previous position | |
3845 | int x, y; | |
3846 | GetViewStart( &x, &y ); | |
3847 | // maybe we don't need scrollbars at all? and if we do, transform w and h | |
3848 | // from pixels into logical units | |
3849 | if ( w <= cw ) | |
3850 | { | |
3851 | w = 0; x= 0; | |
3852 | } | |
3853 | else | |
3854 | { | |
edb89f7e VZ |
3855 | w = (w + GRID_SCROLL_LINE - 1)/GRID_SCROLL_LINE; |
3856 | if ( x >= w ) | |
3857 | x = w - 1; | |
f85afd4e | 3858 | } |
faec5a43 SN |
3859 | if ( h <= ch ) |
3860 | { | |
edb89f7e | 3861 | h = 0; y = 0; |
faec5a43 SN |
3862 | } |
3863 | else | |
3864 | { | |
edb89f7e VZ |
3865 | h = (h + GRID_SCROLL_LINE - 1)/GRID_SCROLL_LINE; |
3866 | if ( y >= h ) | |
3867 | y = h - 1; | |
faec5a43 SN |
3868 | } |
3869 | ||
3870 | // do set scrollbar parameters | |
3871 | SetScrollbars( GRID_SCROLL_LINE, GRID_SCROLL_LINE, | |
edb89f7e | 3872 | w, h, x, y, (GetBatchCount() != 0)); |
f85afd4e MB |
3873 | } |
3874 | ||
3875 | ||
7807d81c MB |
3876 | void wxGrid::CalcWindowSizes() |
3877 | { | |
3878 | int cw, ch; | |
3879 | GetClientSize( &cw, &ch ); | |
b99be8fb | 3880 | |
7807d81c MB |
3881 | if ( m_cornerLabelWin->IsShown() ) |
3882 | m_cornerLabelWin->SetSize( 0, 0, m_rowLabelWidth, m_colLabelHeight ); | |
3883 | ||
3884 | if ( m_colLabelWin->IsShown() ) | |
3885 | m_colLabelWin->SetSize( m_rowLabelWidth, 0, cw-m_rowLabelWidth, m_colLabelHeight); | |
3886 | ||
3887 | if ( m_rowLabelWin->IsShown() ) | |
3888 | m_rowLabelWin->SetSize( 0, m_colLabelHeight, m_rowLabelWidth, ch-m_colLabelHeight); | |
3889 | ||
3890 | if ( m_gridWin->IsShown() ) | |
3891 | m_gridWin->SetSize( m_rowLabelWidth, m_colLabelHeight, cw-m_rowLabelWidth, ch-m_colLabelHeight); | |
3892 | } | |
3893 | ||
3894 | ||
f85afd4e MB |
3895 | // this is called when the grid table sends a message to say that it |
3896 | // has been redimensioned | |
3897 | // | |
3898 | bool wxGrid::Redimension( wxGridTableMessage& msg ) | |
3899 | { | |
3900 | int i; | |
f6bcfd97 | 3901 | bool result = FALSE; |
8f177c8e | 3902 | |
f6bcfd97 | 3903 | #if 0 |
7c1cb261 VZ |
3904 | // if we were using the default widths/heights so far, we must change them |
3905 | // now | |
3906 | if ( m_colWidths.IsEmpty() ) | |
3907 | { | |
3908 | InitColWidths(); | |
3909 | } | |
3910 | ||
3911 | if ( m_rowHeights.IsEmpty() ) | |
3912 | { | |
3913 | InitRowHeights(); | |
3914 | } | |
f6bcfd97 | 3915 | #endif |
7c1cb261 | 3916 | |
f85afd4e MB |
3917 | switch ( msg.GetId() ) |
3918 | { | |
3919 | case wxGRIDTABLE_NOTIFY_ROWS_INSERTED: | |
3920 | { | |
3921 | size_t pos = msg.GetCommandInt(); | |
3922 | int numRows = msg.GetCommandInt2(); | |
f6bcfd97 | 3923 | |
f85afd4e | 3924 | m_numRows += numRows; |
2d66e025 | 3925 | |
f6bcfd97 BP |
3926 | if ( !m_rowHeights.IsEmpty() ) |
3927 | { | |
3928 | for ( i = 0; i < numRows; i++ ) | |
3929 | { | |
3930 | m_rowHeights.Insert( m_defaultRowHeight, pos ); | |
3931 | m_rowBottoms.Insert( 0, pos ); | |
3932 | } | |
3933 | ||
3934 | int bottom = 0; | |
3935 | if ( pos > 0 ) bottom = m_rowBottoms[pos-1]; | |
60ff3b99 | 3936 | |
f6bcfd97 BP |
3937 | for ( i = pos; i < m_numRows; i++ ) |
3938 | { | |
3939 | bottom += m_rowHeights[i]; | |
3940 | m_rowBottoms[i] = bottom; | |
3941 | } | |
3942 | } | |
3943 | if ( m_currentCellCoords == wxGridNoCellCoords ) | |
3944 | { | |
3945 | // if we have just inserted cols into an empty grid the current | |
3946 | // cell will be undefined... | |
3947 | // | |
3948 | SetCurrentCell( 0, 0 ); | |
3949 | } | |
3950 | m_selection->UpdateRows( pos, numRows ); | |
3951 | wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider(); | |
3952 | if (attrProvider) | |
3953 | attrProvider->UpdateAttrRows( pos, numRows ); | |
3954 | ||
3955 | if ( !GetBatchCount() ) | |
2d66e025 | 3956 | { |
f6bcfd97 BP |
3957 | CalcDimensions(); |
3958 | m_rowLabelWin->Refresh(); | |
2d66e025 | 3959 | } |
f85afd4e | 3960 | } |
f6bcfd97 BP |
3961 | result = TRUE; |
3962 | break; | |
f85afd4e MB |
3963 | |
3964 | case wxGRIDTABLE_NOTIFY_ROWS_APPENDED: | |
3965 | { | |
3966 | int numRows = msg.GetCommandInt(); | |
2d66e025 | 3967 | int oldNumRows = m_numRows; |
f85afd4e | 3968 | m_numRows += numRows; |
2d66e025 | 3969 | |
f6bcfd97 BP |
3970 | if ( !m_rowHeights.IsEmpty() ) |
3971 | { | |
3972 | for ( i = 0; i < numRows; i++ ) | |
3973 | { | |
3974 | m_rowHeights.Add( m_defaultRowHeight ); | |
3975 | m_rowBottoms.Add( 0 ); | |
3976 | } | |
60ff3b99 | 3977 | |
f6bcfd97 BP |
3978 | int bottom = 0; |
3979 | if ( oldNumRows > 0 ) bottom = m_rowBottoms[oldNumRows-1]; | |
3980 | ||
3981 | for ( i = oldNumRows; i < m_numRows; i++ ) | |
3982 | { | |
3983 | bottom += m_rowHeights[i]; | |
3984 | m_rowBottoms[i] = bottom; | |
3985 | } | |
3986 | } | |
3987 | if ( m_currentCellCoords == wxGridNoCellCoords ) | |
3988 | { | |
3989 | // if we have just inserted cols into an empty grid the current | |
3990 | // cell will be undefined... | |
3991 | // | |
3992 | SetCurrentCell( 0, 0 ); | |
3993 | } | |
3994 | if ( !GetBatchCount() ) | |
2d66e025 | 3995 | { |
f6bcfd97 BP |
3996 | CalcDimensions(); |
3997 | m_rowLabelWin->Refresh(); | |
2d66e025 | 3998 | } |
f85afd4e | 3999 | } |
f6bcfd97 BP |
4000 | result = TRUE; |
4001 | break; | |
f85afd4e MB |
4002 | |
4003 | case wxGRIDTABLE_NOTIFY_ROWS_DELETED: | |
4004 | { | |
4005 | size_t pos = msg.GetCommandInt(); | |
4006 | int numRows = msg.GetCommandInt2(); | |
f85afd4e MB |
4007 | m_numRows -= numRows; |
4008 | ||
f6bcfd97 | 4009 | if ( !m_rowHeights.IsEmpty() ) |
f85afd4e | 4010 | { |
f6bcfd97 BP |
4011 | for ( i = 0; i < numRows; i++ ) |
4012 | { | |
4403ced6 VZ |
4013 | m_rowHeights.RemoveAt( pos ); |
4014 | m_rowBottoms.RemoveAt( pos ); | |
f6bcfd97 | 4015 | } |
2d66e025 MB |
4016 | |
4017 | int h = 0; | |
4018 | for ( i = 0; i < m_numRows; i++ ) | |
4019 | { | |
4020 | h += m_rowHeights[i]; | |
4021 | m_rowBottoms[i] = h; | |
4022 | } | |
f85afd4e | 4023 | } |
f6bcfd97 BP |
4024 | if ( !m_numRows ) |
4025 | { | |
4026 | m_currentCellCoords = wxGridNoCellCoords; | |
4027 | } | |
4028 | else | |
4029 | { | |
4030 | if ( m_currentCellCoords.GetRow() >= m_numRows ) | |
4031 | m_currentCellCoords.Set( 0, 0 ); | |
4032 | } | |
4033 | m_selection->UpdateRows( pos, -((int)numRows) ); | |
4034 | wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider(); | |
4035 | if (attrProvider) { | |
4036 | attrProvider->UpdateAttrRows( pos, -((int)numRows) ); | |
84912ef8 RD |
4037 | // ifdef'd out following patch from Paul Gammans |
4038 | #if 0 | |
3ca6a5f0 | 4039 | // No need to touch column attributes, unless we |
f6bcfd97 BP |
4040 | // removed _all_ rows, in this case, we remove |
4041 | // all column attributes. | |
4042 | // I hate to do this here, but the | |
4043 | // needed data is not available inside UpdateAttrRows. | |
4044 | if ( !GetNumberRows() ) | |
4045 | attrProvider->UpdateAttrCols( 0, -GetNumberCols() ); | |
84912ef8 | 4046 | #endif |
f6bcfd97 BP |
4047 | } |
4048 | if ( !GetBatchCount() ) | |
4049 | { | |
4050 | CalcDimensions(); | |
4051 | m_rowLabelWin->Refresh(); | |
4052 | } | |
f85afd4e | 4053 | } |
f6bcfd97 BP |
4054 | result = TRUE; |
4055 | break; | |
f85afd4e MB |
4056 | |
4057 | case wxGRIDTABLE_NOTIFY_COLS_INSERTED: | |
4058 | { | |
4059 | size_t pos = msg.GetCommandInt(); | |
4060 | int numCols = msg.GetCommandInt2(); | |
f85afd4e | 4061 | m_numCols += numCols; |
2d66e025 | 4062 | |
f6bcfd97 BP |
4063 | if ( !m_colWidths.IsEmpty() ) |
4064 | { | |
4065 | for ( i = 0; i < numCols; i++ ) | |
4066 | { | |
4067 | m_colWidths.Insert( m_defaultColWidth, pos ); | |
4068 | m_colRights.Insert( 0, pos ); | |
4069 | } | |
4070 | ||
4071 | int right = 0; | |
4072 | if ( pos > 0 ) right = m_colRights[pos-1]; | |
60ff3b99 | 4073 | |
f6bcfd97 BP |
4074 | for ( i = pos; i < m_numCols; i++ ) |
4075 | { | |
4076 | right += m_colWidths[i]; | |
4077 | m_colRights[i] = right; | |
4078 | } | |
4079 | } | |
4080 | if ( m_currentCellCoords == wxGridNoCellCoords ) | |
2d66e025 | 4081 | { |
f6bcfd97 BP |
4082 | // if we have just inserted cols into an empty grid the current |
4083 | // cell will be undefined... | |
4084 | // | |
4085 | SetCurrentCell( 0, 0 ); | |
2d66e025 | 4086 | } |
f6bcfd97 BP |
4087 | m_selection->UpdateCols( pos, numCols ); |
4088 | wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider(); | |
4089 | if (attrProvider) | |
4090 | attrProvider->UpdateAttrCols( pos, numCols ); | |
4091 | if ( !GetBatchCount() ) | |
4092 | { | |
4093 | CalcDimensions(); | |
4094 | m_colLabelWin->Refresh(); | |
4095 | } | |
4096 | ||
f85afd4e | 4097 | } |
f6bcfd97 BP |
4098 | result = TRUE; |
4099 | break; | |
f85afd4e MB |
4100 | |
4101 | case wxGRIDTABLE_NOTIFY_COLS_APPENDED: | |
4102 | { | |
4103 | int numCols = msg.GetCommandInt(); | |
2d66e025 | 4104 | int oldNumCols = m_numCols; |
f85afd4e | 4105 | m_numCols += numCols; |
f6bcfd97 BP |
4106 | if ( !m_colWidths.IsEmpty() ) |
4107 | { | |
4108 | for ( i = 0; i < numCols; i++ ) | |
4109 | { | |
4110 | m_colWidths.Add( m_defaultColWidth ); | |
4111 | m_colRights.Add( 0 ); | |
4112 | } | |
2d66e025 | 4113 | |
f6bcfd97 BP |
4114 | int right = 0; |
4115 | if ( oldNumCols > 0 ) right = m_colRights[oldNumCols-1]; | |
60ff3b99 | 4116 | |
f6bcfd97 BP |
4117 | for ( i = oldNumCols; i < m_numCols; i++ ) |
4118 | { | |
4119 | right += m_colWidths[i]; | |
4120 | m_colRights[i] = right; | |
4121 | } | |
4122 | } | |
4123 | if ( m_currentCellCoords == wxGridNoCellCoords ) | |
2d66e025 | 4124 | { |
f6bcfd97 BP |
4125 | // if we have just inserted cols into an empty grid the current |
4126 | // cell will be undefined... | |
4127 | // | |
4128 | SetCurrentCell( 0, 0 ); | |
4129 | } | |
4130 | if ( !GetBatchCount() ) | |
4131 | { | |
4132 | CalcDimensions(); | |
4133 | m_colLabelWin->Refresh(); | |
2d66e025 | 4134 | } |
f85afd4e | 4135 | } |
f6bcfd97 BP |
4136 | result = TRUE; |
4137 | break; | |
f85afd4e MB |
4138 | |
4139 | case wxGRIDTABLE_NOTIFY_COLS_DELETED: | |
4140 | { | |
4141 | size_t pos = msg.GetCommandInt(); | |
4142 | int numCols = msg.GetCommandInt2(); | |
f85afd4e | 4143 | m_numCols -= numCols; |
f85afd4e | 4144 | |
f6bcfd97 | 4145 | if ( !m_colWidths.IsEmpty() ) |
f85afd4e | 4146 | { |
f6bcfd97 BP |
4147 | for ( i = 0; i < numCols; i++ ) |
4148 | { | |
4403ced6 VZ |
4149 | m_colWidths.RemoveAt( pos ); |
4150 | m_colRights.RemoveAt( pos ); | |
f6bcfd97 | 4151 | } |
2d66e025 MB |
4152 | |
4153 | int w = 0; | |
4154 | for ( i = 0; i < m_numCols; i++ ) | |
4155 | { | |
4156 | w += m_colWidths[i]; | |
4157 | m_colRights[i] = w; | |
4158 | } | |
f85afd4e | 4159 | } |
f6bcfd97 BP |
4160 | if ( !m_numCols ) |
4161 | { | |
4162 | m_currentCellCoords = wxGridNoCellCoords; | |
4163 | } | |
4164 | else | |
4165 | { | |
4166 | if ( m_currentCellCoords.GetCol() >= m_numCols ) | |
4167 | m_currentCellCoords.Set( 0, 0 ); | |
4168 | } | |
4169 | m_selection->UpdateCols( pos, -((int)numCols) ); | |
4170 | wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider(); | |
4171 | if (attrProvider) { | |
4172 | attrProvider->UpdateAttrCols( pos, -((int)numCols) ); | |
84912ef8 RD |
4173 | // ifdef'd out following patch from Paul Gammans |
4174 | #if 0 | |
f6bcfd97 BP |
4175 | // No need to touch row attributes, unless we |
4176 | // removed _all_ columns, in this case, we remove | |
4177 | // all row attributes. | |
4178 | // I hate to do this here, but the | |
4179 | // needed data is not available inside UpdateAttrCols. | |
4180 | if ( !GetNumberCols() ) | |
4181 | attrProvider->UpdateAttrRows( 0, -GetNumberRows() ); | |
84912ef8 | 4182 | #endif |
f6bcfd97 BP |
4183 | } |
4184 | if ( !GetBatchCount() ) | |
4185 | { | |
4186 | CalcDimensions(); | |
4187 | m_colLabelWin->Refresh(); | |
4188 | } | |
f85afd4e | 4189 | } |
faec5a43 | 4190 | result = TRUE; |
f6bcfd97 | 4191 | break; |
f85afd4e MB |
4192 | } |
4193 | ||
f6bcfd97 BP |
4194 | if (result && !GetBatchCount() ) |
4195 | m_gridWin->Refresh(); | |
4196 | return result; | |
f85afd4e MB |
4197 | } |
4198 | ||
4199 | ||
d10f4bf9 | 4200 | wxArrayInt wxGrid::CalcRowLabelsExposed( const wxRegion& reg ) |
f85afd4e | 4201 | { |
2d66e025 MB |
4202 | wxRegionIterator iter( reg ); |
4203 | wxRect r; | |
f85afd4e | 4204 | |
275c4ae4 RD |
4205 | wxArrayInt rowlabels; |
4206 | ||
2d66e025 MB |
4207 | int top, bottom; |
4208 | while ( iter ) | |
f85afd4e | 4209 | { |
2d66e025 | 4210 | r = iter.GetRect(); |
f85afd4e | 4211 | |
2d66e025 MB |
4212 | // TODO: remove this when we can... |
4213 | // There is a bug in wxMotif that gives garbage update | |
4214 | // rectangles if you jump-scroll a long way by clicking the | |
4215 | // scrollbar with middle button. This is a work-around | |
4216 | // | |
4217 | #if defined(__WXMOTIF__) | |
4218 | int cw, ch; | |
4219 | m_gridWin->GetClientSize( &cw, &ch ); | |
4220 | if ( r.GetTop() > ch ) r.SetTop( 0 ); | |
4221 | r.SetBottom( wxMin( r.GetBottom(), ch ) ); | |
4222 | #endif | |
f85afd4e | 4223 | |
2d66e025 MB |
4224 | // logical bounds of update region |
4225 | // | |
4226 | int dummy; | |
4227 | CalcUnscrolledPosition( 0, r.GetTop(), &dummy, &top ); | |
4228 | CalcUnscrolledPosition( 0, r.GetBottom(), &dummy, &bottom ); | |
4229 | ||
4230 | // find the row labels within these bounds | |
4231 | // | |
4232 | int row; | |
2d66e025 MB |
4233 | for ( row = 0; row < m_numRows; row++ ) |
4234 | { | |
7c1cb261 VZ |
4235 | if ( GetRowBottom(row) < top ) |
4236 | continue; | |
2d66e025 | 4237 | |
6d55126d | 4238 | if ( GetRowTop(row) > bottom ) |
7c1cb261 | 4239 | break; |
60ff3b99 | 4240 | |
d10f4bf9 | 4241 | rowlabels.Add( row ); |
2d66e025 | 4242 | } |
60ff3b99 | 4243 | |
2d66e025 | 4244 | iter++ ; |
f85afd4e | 4245 | } |
d10f4bf9 VZ |
4246 | |
4247 | return rowlabels; | |
f85afd4e MB |
4248 | } |
4249 | ||
4250 | ||
d10f4bf9 | 4251 | wxArrayInt wxGrid::CalcColLabelsExposed( const wxRegion& reg ) |
f85afd4e | 4252 | { |
2d66e025 MB |
4253 | wxRegionIterator iter( reg ); |
4254 | wxRect r; | |
f85afd4e | 4255 | |
d10f4bf9 | 4256 | wxArrayInt colLabels; |
f85afd4e | 4257 | |
2d66e025 MB |
4258 | int left, right; |
4259 | while ( iter ) | |
f85afd4e | 4260 | { |
2d66e025 | 4261 | r = iter.GetRect(); |
f85afd4e | 4262 | |
2d66e025 MB |
4263 | // TODO: remove this when we can... |
4264 | // There is a bug in wxMotif that gives garbage update | |
4265 | // rectangles if you jump-scroll a long way by clicking the | |
4266 | // scrollbar with middle button. This is a work-around | |
4267 | // | |
4268 | #if defined(__WXMOTIF__) | |
4269 | int cw, ch; | |
4270 | m_gridWin->GetClientSize( &cw, &ch ); | |
4271 | if ( r.GetLeft() > cw ) r.SetLeft( 0 ); | |
4272 | r.SetRight( wxMin( r.GetRight(), cw ) ); | |
4273 | #endif | |
4274 | ||
4275 | // logical bounds of update region | |
4276 | // | |
4277 | int dummy; | |
4278 | CalcUnscrolledPosition( r.GetLeft(), 0, &left, &dummy ); | |
4279 | CalcUnscrolledPosition( r.GetRight(), 0, &right, &dummy ); | |
4280 | ||
4281 | // find the cells within these bounds | |
4282 | // | |
4283 | int col; | |
2d66e025 MB |
4284 | for ( col = 0; col < m_numCols; col++ ) |
4285 | { | |
7c1cb261 VZ |
4286 | if ( GetColRight(col) < left ) |
4287 | continue; | |
60ff3b99 | 4288 | |
7c1cb261 VZ |
4289 | if ( GetColLeft(col) > right ) |
4290 | break; | |
2d66e025 | 4291 | |
d10f4bf9 | 4292 | colLabels.Add( col ); |
2d66e025 | 4293 | } |
60ff3b99 | 4294 | |
2d66e025 | 4295 | iter++ ; |
f85afd4e | 4296 | } |
d10f4bf9 | 4297 | return colLabels; |
f85afd4e MB |
4298 | } |
4299 | ||
4300 | ||
d10f4bf9 | 4301 | wxGridCellCoordsArray wxGrid::CalcCellsExposed( const wxRegion& reg ) |
f85afd4e | 4302 | { |
2d66e025 MB |
4303 | wxRegionIterator iter( reg ); |
4304 | wxRect r; | |
f85afd4e | 4305 | |
d10f4bf9 | 4306 | wxGridCellCoordsArray cellsExposed; |
f85afd4e | 4307 | |
2d66e025 MB |
4308 | int left, top, right, bottom; |
4309 | while ( iter ) | |
4310 | { | |
4311 | r = iter.GetRect(); | |
f85afd4e | 4312 | |
2d66e025 MB |
4313 | // TODO: remove this when we can... |
4314 | // There is a bug in wxMotif that gives garbage update | |
4315 | // rectangles if you jump-scroll a long way by clicking the | |
4316 | // scrollbar with middle button. This is a work-around | |
4317 | // | |
4318 | #if defined(__WXMOTIF__) | |
f85afd4e | 4319 | int cw, ch; |
2d66e025 MB |
4320 | m_gridWin->GetClientSize( &cw, &ch ); |
4321 | if ( r.GetTop() > ch ) r.SetTop( 0 ); | |
4322 | if ( r.GetLeft() > cw ) r.SetLeft( 0 ); | |
4323 | r.SetRight( wxMin( r.GetRight(), cw ) ); | |
4324 | r.SetBottom( wxMin( r.GetBottom(), ch ) ); | |
4325 | #endif | |
8f177c8e | 4326 | |
2d66e025 MB |
4327 | // logical bounds of update region |
4328 | // | |
4329 | CalcUnscrolledPosition( r.GetLeft(), r.GetTop(), &left, &top ); | |
4330 | CalcUnscrolledPosition( r.GetRight(), r.GetBottom(), &right, &bottom ); | |
f85afd4e | 4331 | |
2d66e025 | 4332 | // find the cells within these bounds |
f85afd4e | 4333 | // |
2d66e025 | 4334 | int row, col; |
2d66e025 | 4335 | for ( row = 0; row < m_numRows; row++ ) |
f85afd4e | 4336 | { |
7c1cb261 VZ |
4337 | if ( GetRowBottom(row) <= top ) |
4338 | continue; | |
f85afd4e | 4339 | |
7c1cb261 VZ |
4340 | if ( GetRowTop(row) > bottom ) |
4341 | break; | |
60ff3b99 | 4342 | |
f85afd4e | 4343 | |
2d66e025 MB |
4344 | for ( col = 0; col < m_numCols; col++ ) |
4345 | { | |
7c1cb261 VZ |
4346 | if ( GetColRight(col) <= left ) |
4347 | continue; | |
60ff3b99 | 4348 | |
7c1cb261 VZ |
4349 | if ( GetColLeft(col) > right ) |
4350 | break; | |
60ff3b99 | 4351 | |
d10f4bf9 | 4352 | cellsExposed.Add( wxGridCellCoords( row, col ) ); |
2d66e025 MB |
4353 | } |
4354 | } | |
60ff3b99 | 4355 | |
7c1cb261 | 4356 | iter++; |
f85afd4e | 4357 | } |
d10f4bf9 VZ |
4358 | |
4359 | return cellsExposed; | |
f85afd4e MB |
4360 | } |
4361 | ||
4362 | ||
2d66e025 | 4363 | void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event ) |
f85afd4e | 4364 | { |
2d66e025 MB |
4365 | int x, y, row; |
4366 | wxPoint pos( event.GetPosition() ); | |
4367 | CalcUnscrolledPosition( pos.x, pos.y, &x, &y ); | |
60ff3b99 | 4368 | |
2d66e025 | 4369 | if ( event.Dragging() ) |
f85afd4e MB |
4370 | { |
4371 | m_isDragging = TRUE; | |
8f177c8e | 4372 | |
2d66e025 | 4373 | if ( event.LeftIsDown() ) |
f85afd4e MB |
4374 | { |
4375 | switch( m_cursorMode ) | |
4376 | { | |
f85afd4e MB |
4377 | case WXGRID_CURSOR_RESIZE_ROW: |
4378 | { | |
2d66e025 MB |
4379 | int cw, ch, left, dummy; |
4380 | m_gridWin->GetClientSize( &cw, &ch ); | |
4381 | CalcUnscrolledPosition( 0, 0, &left, &dummy ); | |
60ff3b99 | 4382 | |
2d66e025 MB |
4383 | wxClientDC dc( m_gridWin ); |
4384 | PrepareDC( dc ); | |
af547d51 VZ |
4385 | y = wxMax( y, |
4386 | GetRowTop(m_dragRowOrCol) + | |
4387 | GetRowMinimalHeight(m_dragRowOrCol) ); | |
d2fdd8d2 | 4388 | dc.SetLogicalFunction(wxINVERT); |
f85afd4e MB |
4389 | if ( m_dragLastPos >= 0 ) |
4390 | { | |
2d66e025 | 4391 | dc.DrawLine( left, m_dragLastPos, left+cw, m_dragLastPos ); |
f85afd4e | 4392 | } |
2d66e025 MB |
4393 | dc.DrawLine( left, y, left+cw, y ); |
4394 | m_dragLastPos = y; | |
f85afd4e MB |
4395 | } |
4396 | break; | |
4397 | ||
4398 | case WXGRID_CURSOR_SELECT_ROW: | |
e32352cf | 4399 | if ( (row = YToRow( y )) >= 0 ) |
aa5e1f75 SN |
4400 | { |
4401 | m_selection->SelectRow( row, | |
4402 | event.ControlDown(), | |
4403 | event.ShiftDown(), | |
4404 | event.AltDown(), | |
4405 | event.MetaDown() ); | |
f85afd4e | 4406 | } |
e2b42eeb VZ |
4407 | |
4408 | // default label to suppress warnings about "enumeration value | |
4409 | // 'xxx' not handled in switch | |
4410 | default: | |
4411 | break; | |
f85afd4e MB |
4412 | } |
4413 | } | |
4414 | return; | |
4415 | } | |
4416 | ||
4417 | m_isDragging = FALSE; | |
8f177c8e | 4418 | |
60ff3b99 | 4419 | |
6d004f67 MB |
4420 | // ------------ Entering or leaving the window |
4421 | // | |
4422 | if ( event.Entering() || event.Leaving() ) | |
4423 | { | |
e2b42eeb | 4424 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin); |
6d004f67 MB |
4425 | } |
4426 | ||
e2b42eeb | 4427 | |
2d66e025 | 4428 | // ------------ Left button pressed |
f85afd4e | 4429 | // |
6d004f67 | 4430 | else if ( event.LeftDown() ) |
f85afd4e | 4431 | { |
2d66e025 MB |
4432 | // don't send a label click event for a hit on the |
4433 | // edge of the row label - this is probably the user | |
4434 | // wanting to resize the row | |
4435 | // | |
4436 | if ( YToEdgeOfRow(y) < 0 ) | |
f85afd4e | 4437 | { |
2d66e025 | 4438 | row = YToRow(y); |
58dd5b3b | 4439 | if ( row >= 0 && |
b54ba671 | 4440 | !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) ) |
f85afd4e | 4441 | { |
aa5e1f75 SN |
4442 | if ( !event.ShiftDown() && !event.ControlDown() ) |
4443 | ClearSelection(); | |
4444 | if ( event.ShiftDown() ) | |
4445 | m_selection->SelectBlock( m_currentCellCoords.GetRow(), | |
4446 | 0, | |
4447 | row, | |
4448 | GetNumberCols() - 1, | |
4449 | event.ControlDown(), | |
4450 | event.ShiftDown(), | |
4451 | event.AltDown(), | |
4452 | event.MetaDown() ); | |
4453 | else | |
4454 | m_selection->SelectRow( row, | |
4455 | event.ControlDown(), | |
4456 | event.ShiftDown(), | |
4457 | event.AltDown(), | |
4458 | event.MetaDown() ); | |
e2b42eeb | 4459 | ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, m_rowLabelWin); |
f85afd4e | 4460 | } |
2d66e025 MB |
4461 | } |
4462 | else | |
4463 | { | |
4464 | // starting to drag-resize a row | |
4465 | // | |
6e8524b1 MB |
4466 | if ( CanDragRowSize() ) |
4467 | ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin); | |
2d66e025 MB |
4468 | } |
4469 | } | |
f85afd4e | 4470 | |
f85afd4e | 4471 | |
2d66e025 MB |
4472 | // ------------ Left double click |
4473 | // | |
4474 | else if (event.LeftDClick() ) | |
4475 | { | |
4476 | if ( YToEdgeOfRow(y) < 0 ) | |
4477 | { | |
4478 | row = YToRow(y); | |
b54ba671 | 4479 | SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event ); |
f85afd4e MB |
4480 | } |
4481 | } | |
60ff3b99 VZ |
4482 | |
4483 | ||
2d66e025 | 4484 | // ------------ Left button released |
f85afd4e | 4485 | // |
2d66e025 | 4486 | else if ( event.LeftUp() ) |
f85afd4e | 4487 | { |
2d66e025 | 4488 | if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW ) |
f85afd4e | 4489 | { |
6d004f67 | 4490 | DoEndDragResizeRow(); |
60ff3b99 | 4491 | |
6d004f67 MB |
4492 | // Note: we are ending the event *after* doing |
4493 | // default processing in this case | |
4494 | // | |
b54ba671 | 4495 | SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event ); |
2d66e025 | 4496 | } |
f85afd4e | 4497 | |
e2b42eeb VZ |
4498 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin); |
4499 | m_dragLastPos = -1; | |
2d66e025 | 4500 | } |
f85afd4e | 4501 | |
f85afd4e | 4502 | |
2d66e025 MB |
4503 | // ------------ Right button down |
4504 | // | |
4505 | else if ( event.RightDown() ) | |
4506 | { | |
4507 | row = YToRow(y); | |
b54ba671 | 4508 | if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) ) |
2d66e025 MB |
4509 | { |
4510 | // no default action at the moment | |
f85afd4e MB |
4511 | } |
4512 | } | |
60ff3b99 VZ |
4513 | |
4514 | ||
2d66e025 | 4515 | // ------------ Right double click |
f85afd4e | 4516 | // |
2d66e025 MB |
4517 | else if ( event.RightDClick() ) |
4518 | { | |
4519 | row = YToRow(y); | |
b54ba671 | 4520 | if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) ) |
2d66e025 MB |
4521 | { |
4522 | // no default action at the moment | |
4523 | } | |
4524 | } | |
60ff3b99 VZ |
4525 | |
4526 | ||
2d66e025 | 4527 | // ------------ No buttons down and mouse moving |
f85afd4e | 4528 | // |
2d66e025 | 4529 | else if ( event.Moving() ) |
f85afd4e | 4530 | { |
2d66e025 MB |
4531 | m_dragRowOrCol = YToEdgeOfRow( y ); |
4532 | if ( m_dragRowOrCol >= 0 ) | |
8f177c8e | 4533 | { |
2d66e025 | 4534 | if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL ) |
8f177c8e | 4535 | { |
e2b42eeb | 4536 | // don't capture the mouse yet |
6e8524b1 MB |
4537 | if ( CanDragRowSize() ) |
4538 | ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin, FALSE); | |
8f177c8e | 4539 | } |
2d66e025 | 4540 | } |
6d004f67 | 4541 | else if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL ) |
2d66e025 | 4542 | { |
e2b42eeb | 4543 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin, FALSE); |
8f177c8e | 4544 | } |
f85afd4e | 4545 | } |
2d66e025 MB |
4546 | } |
4547 | ||
4548 | ||
4549 | void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event ) | |
4550 | { | |
4551 | int x, y, col; | |
4552 | wxPoint pos( event.GetPosition() ); | |
4553 | CalcUnscrolledPosition( pos.x, pos.y, &x, &y ); | |
60ff3b99 | 4554 | |
2d66e025 | 4555 | if ( event.Dragging() ) |
f85afd4e | 4556 | { |
2d66e025 | 4557 | m_isDragging = TRUE; |
8f177c8e | 4558 | |
2d66e025 | 4559 | if ( event.LeftIsDown() ) |
8f177c8e | 4560 | { |
2d66e025 | 4561 | switch( m_cursorMode ) |
8f177c8e | 4562 | { |
2d66e025 | 4563 | case WXGRID_CURSOR_RESIZE_COL: |
8f177c8e | 4564 | { |
2d66e025 MB |
4565 | int cw, ch, dummy, top; |
4566 | m_gridWin->GetClientSize( &cw, &ch ); | |
4567 | CalcUnscrolledPosition( 0, 0, &dummy, &top ); | |
60ff3b99 | 4568 | |
2d66e025 MB |
4569 | wxClientDC dc( m_gridWin ); |
4570 | PrepareDC( dc ); | |
43947979 VZ |
4571 | |
4572 | x = wxMax( x, GetColLeft(m_dragRowOrCol) + | |
4573 | GetColMinimalWidth(m_dragRowOrCol)); | |
d2fdd8d2 | 4574 | dc.SetLogicalFunction(wxINVERT); |
2d66e025 MB |
4575 | if ( m_dragLastPos >= 0 ) |
4576 | { | |
4577 | dc.DrawLine( m_dragLastPos, top, m_dragLastPos, top+ch ); | |
4578 | } | |
4579 | dc.DrawLine( x, top, x, top+ch ); | |
4580 | m_dragLastPos = x; | |
f85afd4e | 4581 | } |
2d66e025 | 4582 | break; |
f85afd4e | 4583 | |
2d66e025 | 4584 | case WXGRID_CURSOR_SELECT_COL: |
e32352cf | 4585 | if ( (col = XToCol( x )) >= 0 ) |
aa5e1f75 SN |
4586 | { |
4587 | m_selection->SelectCol( col, | |
4588 | event.ControlDown(), | |
4589 | event.ShiftDown(), | |
4590 | event.AltDown(), | |
4591 | event.MetaDown() ); | |
2d66e025 | 4592 | } |
e2b42eeb VZ |
4593 | |
4594 | // default label to suppress warnings about "enumeration value | |
4595 | // 'xxx' not handled in switch | |
4596 | default: | |
4597 | break; | |
2d66e025 | 4598 | } |
f85afd4e | 4599 | } |
2d66e025 | 4600 | return; |
f85afd4e | 4601 | } |
2d66e025 MB |
4602 | |
4603 | m_isDragging = FALSE; | |
4604 | ||
60ff3b99 | 4605 | |
6d004f67 MB |
4606 | // ------------ Entering or leaving the window |
4607 | // | |
4608 | if ( event.Entering() || event.Leaving() ) | |
4609 | { | |
e2b42eeb | 4610 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin); |
6d004f67 MB |
4611 | } |
4612 | ||
e2b42eeb | 4613 | |
2d66e025 | 4614 | // ------------ Left button pressed |
f85afd4e | 4615 | // |
6d004f67 | 4616 | else if ( event.LeftDown() ) |
f85afd4e | 4617 | { |
2d66e025 MB |
4618 | // don't send a label click event for a hit on the |
4619 | // edge of the col label - this is probably the user | |
4620 | // wanting to resize the col | |
4621 | // | |
4622 | if ( XToEdgeOfCol(x) < 0 ) | |
8f177c8e | 4623 | { |
2d66e025 | 4624 | col = XToCol(x); |
58dd5b3b | 4625 | if ( col >= 0 && |
b54ba671 | 4626 | !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) ) |
8f177c8e | 4627 | { |
aa5e1f75 SN |
4628 | if ( !event.ShiftDown() && !event.ControlDown() ) |
4629 | ClearSelection(); | |
4630 | if ( event.ShiftDown() ) | |
4631 | m_selection->SelectBlock( 0, | |
4632 | m_currentCellCoords.GetCol(), | |
4633 | GetNumberRows() - 1, col, | |
4634 | event.ControlDown(), | |
4635 | event.ShiftDown(), | |
4636 | event.AltDown(), | |
4637 | event.MetaDown() ); | |
4638 | else | |
4639 | m_selection->SelectCol( col, | |
4640 | event.ControlDown(), | |
4641 | event.ShiftDown(), | |
4642 | event.AltDown(), | |
4643 | event.MetaDown() ); | |
e2b42eeb | 4644 | ChangeCursorMode(WXGRID_CURSOR_SELECT_COL, m_colLabelWin); |
f85afd4e | 4645 | } |
2d66e025 MB |
4646 | } |
4647 | else | |
4648 | { | |
4649 | // starting to drag-resize a col | |
4650 | // | |
6e8524b1 MB |
4651 | if ( CanDragColSize() ) |
4652 | ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, m_colLabelWin); | |
2d66e025 MB |
4653 | } |
4654 | } | |
f85afd4e | 4655 | |
f85afd4e | 4656 | |
2d66e025 MB |
4657 | // ------------ Left double click |
4658 | // | |
4659 | if ( event.LeftDClick() ) | |
4660 | { | |
4661 | if ( XToEdgeOfCol(x) < 0 ) | |
4662 | { | |
4663 | col = XToCol(x); | |
b54ba671 | 4664 | SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event ); |
2d66e025 MB |
4665 | } |
4666 | } | |
60ff3b99 VZ |
4667 | |
4668 | ||
2d66e025 MB |
4669 | // ------------ Left button released |
4670 | // | |
4671 | else if ( event.LeftUp() ) | |
4672 | { | |
4673 | if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL ) | |
4674 | { | |
6d004f67 | 4675 | DoEndDragResizeCol(); |
e2b42eeb | 4676 | |
6d004f67 MB |
4677 | // Note: we are ending the event *after* doing |
4678 | // default processing in this case | |
4679 | // | |
b54ba671 | 4680 | SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event ); |
2d66e025 | 4681 | } |
f85afd4e | 4682 | |
e2b42eeb | 4683 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin); |
2d66e025 | 4684 | m_dragLastPos = -1; |
60ff3b99 VZ |
4685 | } |
4686 | ||
4687 | ||
2d66e025 MB |
4688 | // ------------ Right button down |
4689 | // | |
4690 | else if ( event.RightDown() ) | |
4691 | { | |
4692 | col = XToCol(x); | |
b54ba671 | 4693 | if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) ) |
2d66e025 MB |
4694 | { |
4695 | // no default action at the moment | |
f85afd4e MB |
4696 | } |
4697 | } | |
60ff3b99 VZ |
4698 | |
4699 | ||
2d66e025 | 4700 | // ------------ Right double click |
f85afd4e | 4701 | // |
2d66e025 MB |
4702 | else if ( event.RightDClick() ) |
4703 | { | |
4704 | col = XToCol(x); | |
b54ba671 | 4705 | if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) ) |
2d66e025 MB |
4706 | { |
4707 | // no default action at the moment | |
4708 | } | |
4709 | } | |
60ff3b99 VZ |
4710 | |
4711 | ||
2d66e025 | 4712 | // ------------ No buttons down and mouse moving |
f85afd4e | 4713 | // |
2d66e025 | 4714 | else if ( event.Moving() ) |
f85afd4e | 4715 | { |
2d66e025 MB |
4716 | m_dragRowOrCol = XToEdgeOfCol( x ); |
4717 | if ( m_dragRowOrCol >= 0 ) | |
f85afd4e | 4718 | { |
2d66e025 | 4719 | if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL ) |
f85afd4e | 4720 | { |
e2b42eeb | 4721 | // don't capture the cursor yet |
6e8524b1 MB |
4722 | if ( CanDragColSize() ) |
4723 | ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, m_colLabelWin, FALSE); | |
f85afd4e | 4724 | } |
2d66e025 | 4725 | } |
6d004f67 | 4726 | else if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL ) |
2d66e025 | 4727 | { |
e2b42eeb | 4728 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin, FALSE); |
8f177c8e | 4729 | } |
f85afd4e MB |
4730 | } |
4731 | } | |
4732 | ||
4733 | ||
2d66e025 | 4734 | void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent& event ) |
f85afd4e | 4735 | { |
2d66e025 | 4736 | if ( event.LeftDown() ) |
f85afd4e | 4737 | { |
2d66e025 MB |
4738 | // indicate corner label by having both row and |
4739 | // col args == -1 | |
f85afd4e | 4740 | // |
b54ba671 | 4741 | if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, event ) ) |
2d66e025 MB |
4742 | { |
4743 | SelectAll(); | |
4744 | } | |
f85afd4e MB |
4745 | } |
4746 | ||
2d66e025 MB |
4747 | else if ( event.LeftDClick() ) |
4748 | { | |
b54ba671 | 4749 | SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, event ); |
2d66e025 | 4750 | } |
8f177c8e | 4751 | |
2d66e025 | 4752 | else if ( event.RightDown() ) |
f85afd4e | 4753 | { |
b54ba671 | 4754 | if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, event ) ) |
f85afd4e | 4755 | { |
2d66e025 MB |
4756 | // no default action at the moment |
4757 | } | |
4758 | } | |
f85afd4e | 4759 | |
2d66e025 MB |
4760 | else if ( event.RightDClick() ) |
4761 | { | |
b54ba671 | 4762 | if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, event ) ) |
2d66e025 MB |
4763 | { |
4764 | // no default action at the moment | |
4765 | } | |
4766 | } | |
4767 | } | |
f85afd4e | 4768 | |
e2b42eeb VZ |
4769 | void wxGrid::ChangeCursorMode(CursorMode mode, |
4770 | wxWindow *win, | |
4771 | bool captureMouse) | |
4772 | { | |
4773 | #ifdef __WXDEBUG__ | |
4774 | static const wxChar *cursorModes[] = | |
4775 | { | |
4776 | _T("SELECT_CELL"), | |
4777 | _T("RESIZE_ROW"), | |
4778 | _T("RESIZE_COL"), | |
4779 | _T("SELECT_ROW"), | |
4780 | _T("SELECT_COL") | |
4781 | }; | |
4782 | ||
181bfffd VZ |
4783 | wxLogTrace(_T("grid"), |
4784 | _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"), | |
e2b42eeb VZ |
4785 | win == m_colLabelWin ? _T("colLabelWin") |
4786 | : win ? _T("rowLabelWin") | |
4787 | : _T("gridWin"), | |
4788 | cursorModes[m_cursorMode], cursorModes[mode]); | |
4789 | #endif // __WXDEBUG__ | |
4790 | ||
faec5a43 SN |
4791 | if ( mode == m_cursorMode && |
4792 | win == m_winCapture && | |
4793 | captureMouse == (m_winCapture != NULL)) | |
e2b42eeb VZ |
4794 | return; |
4795 | ||
4796 | if ( !win ) | |
4797 | { | |
4798 | // by default use the grid itself | |
4799 | win = m_gridWin; | |
4800 | } | |
4801 | ||
4802 | if ( m_winCapture ) | |
4803 | { | |
4804 | m_winCapture->ReleaseMouse(); | |
4805 | m_winCapture = (wxWindow *)NULL; | |
4806 | } | |
4807 | ||
4808 | m_cursorMode = mode; | |
4809 | ||
4810 | switch ( m_cursorMode ) | |
4811 | { | |
4812 | case WXGRID_CURSOR_RESIZE_ROW: | |
4813 | win->SetCursor( m_rowResizeCursor ); | |
4814 | break; | |
4815 | ||
4816 | case WXGRID_CURSOR_RESIZE_COL: | |
4817 | win->SetCursor( m_colResizeCursor ); | |
4818 | break; | |
4819 | ||
4820 | default: | |
4821 | win->SetCursor( *wxSTANDARD_CURSOR ); | |
4822 | } | |
4823 | ||
4824 | // we need to capture mouse when resizing | |
4825 | bool resize = m_cursorMode == WXGRID_CURSOR_RESIZE_ROW || | |
4826 | m_cursorMode == WXGRID_CURSOR_RESIZE_COL; | |
4827 | ||
4828 | if ( captureMouse && resize ) | |
4829 | { | |
4830 | win->CaptureMouse(); | |
4831 | m_winCapture = win; | |
4832 | } | |
4833 | } | |
8f177c8e | 4834 | |
2d66e025 MB |
4835 | void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) |
4836 | { | |
4837 | int x, y; | |
4838 | wxPoint pos( event.GetPosition() ); | |
4839 | CalcUnscrolledPosition( pos.x, pos.y, &x, &y ); | |
60ff3b99 | 4840 | |
2d66e025 MB |
4841 | wxGridCellCoords coords; |
4842 | XYToCell( x, y, coords ); | |
60ff3b99 | 4843 | |
2d66e025 MB |
4844 | if ( event.Dragging() ) |
4845 | { | |
07296f0b RD |
4846 | //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol()); |
4847 | ||
4848 | // Don't start doing anything until the mouse has been drug at | |
4849 | // least 3 pixels in any direction... | |
508011ce VZ |
4850 | if (! m_isDragging) |
4851 | { | |
4852 | if (m_startDragPos == wxDefaultPosition) | |
4853 | { | |
07296f0b RD |
4854 | m_startDragPos = pos; |
4855 | return; | |
4856 | } | |
4857 | if (abs(m_startDragPos.x - pos.x) < 4 && abs(m_startDragPos.y - pos.y) < 4) | |
4858 | return; | |
4859 | } | |
4860 | ||
2d66e025 | 4861 | m_isDragging = TRUE; |
2d66e025 MB |
4862 | if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL ) |
4863 | { | |
f0102d2a VZ |
4864 | // Hide the edit control, so it |
4865 | // won't interfer with drag-shrinking. | |
f6bcfd97 | 4866 | if ( IsCellEditControlShown() ) |
a5777624 | 4867 | { |
f0102d2a | 4868 | HideCellEditControl(); |
a5777624 RD |
4869 | SaveEditControlValue(); |
4870 | } | |
07296f0b RD |
4871 | |
4872 | // Have we captured the mouse yet? | |
508011ce VZ |
4873 | if (! m_winCapture) |
4874 | { | |
07296f0b RD |
4875 | m_winCapture = m_gridWin; |
4876 | m_winCapture->CaptureMouse(); | |
4877 | } | |
4878 | ||
2d66e025 MB |
4879 | if ( coords != wxGridNoCellCoords ) |
4880 | { | |
aa5e1f75 SN |
4881 | if ( event.ControlDown() ) |
4882 | { | |
4883 | if ( m_selectingKeyboard == wxGridNoCellCoords) | |
4884 | m_selectingKeyboard = coords; | |
c9097836 | 4885 | HighlightBlock ( m_selectingKeyboard, coords ); |
aa5e1f75 SN |
4886 | } |
4887 | else | |
4888 | { | |
4889 | if ( !IsSelection() ) | |
4890 | { | |
c9097836 | 4891 | HighlightBlock( coords, coords ); |
aa5e1f75 SN |
4892 | } |
4893 | else | |
4894 | { | |
c9097836 | 4895 | HighlightBlock( m_currentCellCoords, coords ); |
aa5e1f75 | 4896 | } |
f85afd4e | 4897 | } |
07296f0b | 4898 | |
508011ce VZ |
4899 | if (! IsVisible(coords)) |
4900 | { | |
07296f0b RD |
4901 | MakeCellVisible(coords); |
4902 | // TODO: need to introduce a delay or something here. The | |
e32352cf | 4903 | // scrolling is way to fast, at least on MSW - also on GTK. |
07296f0b | 4904 | } |
2d66e025 MB |
4905 | } |
4906 | } | |
6d004f67 MB |
4907 | else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW ) |
4908 | { | |
4909 | int cw, ch, left, dummy; | |
4910 | m_gridWin->GetClientSize( &cw, &ch ); | |
4911 | CalcUnscrolledPosition( 0, 0, &left, &dummy ); | |
8f177c8e | 4912 | |
6d004f67 MB |
4913 | wxClientDC dc( m_gridWin ); |
4914 | PrepareDC( dc ); | |
a95e38c0 VZ |
4915 | y = wxMax( y, GetRowTop(m_dragRowOrCol) + |
4916 | GetRowMinimalHeight(m_dragRowOrCol) ); | |
6d004f67 MB |
4917 | dc.SetLogicalFunction(wxINVERT); |
4918 | if ( m_dragLastPos >= 0 ) | |
4919 | { | |
4920 | dc.DrawLine( left, m_dragLastPos, left+cw, m_dragLastPos ); | |
4921 | } | |
4922 | dc.DrawLine( left, y, left+cw, y ); | |
4923 | m_dragLastPos = y; | |
4924 | } | |
4925 | else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL ) | |
4926 | { | |
4927 | int cw, ch, dummy, top; | |
4928 | m_gridWin->GetClientSize( &cw, &ch ); | |
4929 | CalcUnscrolledPosition( 0, 0, &dummy, &top ); | |
e2b42eeb | 4930 | |
6d004f67 MB |
4931 | wxClientDC dc( m_gridWin ); |
4932 | PrepareDC( dc ); | |
43947979 VZ |
4933 | x = wxMax( x, GetColLeft(m_dragRowOrCol) + |
4934 | GetColMinimalWidth(m_dragRowOrCol) ); | |
6d004f67 MB |
4935 | dc.SetLogicalFunction(wxINVERT); |
4936 | if ( m_dragLastPos >= 0 ) | |
4937 | { | |
4938 | dc.DrawLine( m_dragLastPos, top, m_dragLastPos, top+ch ); | |
4939 | } | |
4940 | dc.DrawLine( x, top, x, top+ch ); | |
4941 | m_dragLastPos = x; | |
4942 | } | |
e2b42eeb | 4943 | |
2d66e025 MB |
4944 | return; |
4945 | } | |
66242c80 | 4946 | |
2d66e025 | 4947 | m_isDragging = FALSE; |
07296f0b RD |
4948 | m_startDragPos = wxDefaultPosition; |
4949 | ||
a5777624 RD |
4950 | // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL |
4951 | // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under | |
4952 | // wxGTK | |
e2b42eeb | 4953 | #if 0 |
a5777624 RD |
4954 | if ( event.Entering() || event.Leaving() ) |
4955 | { | |
4956 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL); | |
4957 | m_gridWin->SetCursor( *wxSTANDARD_CURSOR ); | |
4958 | } | |
4959 | else | |
e2b42eeb VZ |
4960 | #endif // 0 |
4961 | ||
a5777624 RD |
4962 | // ------------ Left button pressed |
4963 | // | |
4964 | if ( event.LeftDown() && coords != wxGridNoCellCoords ) | |
f6bcfd97 BP |
4965 | { |
4966 | if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK, | |
4967 | coords.GetRow(), | |
4968 | coords.GetCol(), | |
4969 | event ) ) | |
a5777624 | 4970 | { |
f6bcfd97 BP |
4971 | if ( !event.ControlDown() ) |
4972 | ClearSelection(); | |
4973 | if ( event.ShiftDown() ) | |
4974 | { | |
4975 | m_selection->SelectBlock( m_currentCellCoords.GetRow(), | |
4976 | m_currentCellCoords.GetCol(), | |
4977 | coords.GetRow(), | |
4978 | coords.GetCol(), | |
4979 | event.ControlDown(), | |
4980 | event.ShiftDown(), | |
4981 | event.AltDown(), | |
4982 | event.MetaDown() ); | |
4983 | } | |
4984 | else if ( XToEdgeOfCol(x) < 0 && | |
4985 | YToEdgeOfRow(y) < 0 ) | |
58dd5b3b | 4986 | { |
a5777624 RD |
4987 | DisableCellEditControl(); |
4988 | MakeCellVisible( coords ); | |
4989 | ||
4990 | // if this is the second click on this cell then start | |
4991 | // the edit control | |
4992 | if ( m_waitForSlowClick && | |
4993 | (coords == m_currentCellCoords) && | |
4994 | CanEnableCellControl()) | |
58dd5b3b | 4995 | { |
a5777624 | 4996 | EnableCellEditControl(); |
e195a54c | 4997 | |
a5777624 | 4998 | wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords); |
0b190b0f VZ |
4999 | wxGridCellEditor *editor = attr->GetEditor(this, |
5000 | coords.GetRow(), | |
5001 | coords.GetCol()); | |
5002 | editor->StartingClick(); | |
5003 | editor->DecRef(); | |
a5777624 | 5004 | attr->DecRef(); |
e195a54c | 5005 | |
a5777624 RD |
5006 | m_waitForSlowClick = FALSE; |
5007 | } | |
5008 | else | |
5009 | { | |
aa5e1f75 SN |
5010 | if ( event.ControlDown() ) |
5011 | { | |
5012 | m_selection->ToggleCellSelection( coords.GetRow(), | |
5013 | coords.GetCol(), | |
5014 | event.ControlDown(), | |
5015 | event.ShiftDown(), | |
5016 | event.AltDown(), | |
5017 | event.MetaDown() ); | |
5018 | m_selectingTopLeft = wxGridNoCellCoords; | |
5019 | m_selectingBottomRight = wxGridNoCellCoords; | |
5020 | m_selectingKeyboard = coords; | |
5021 | } | |
5022 | else | |
f6bcfd97 | 5023 | { |
aa5e1f75 | 5024 | SetCurrentCell( coords ); |
f6bcfd97 BP |
5025 | if ( m_selection->GetSelectionMode() |
5026 | != wxGrid::wxGridSelectCells) | |
c9097836 | 5027 | HighlightBlock( coords, coords ); |
f6bcfd97 | 5028 | } |
a5777624 | 5029 | m_waitForSlowClick = TRUE; |
58dd5b3b MB |
5030 | } |
5031 | } | |
f85afd4e | 5032 | } |
a5777624 | 5033 | } |
f85afd4e | 5034 | |
f85afd4e | 5035 | |
a5777624 RD |
5036 | // ------------ Left double click |
5037 | // | |
5038 | else if ( event.LeftDClick() && coords != wxGridNoCellCoords ) | |
5039 | { | |
5040 | DisableCellEditControl(); | |
5041 | ||
5042 | if ( XToEdgeOfCol(x) < 0 && YToEdgeOfRow(y) < 0 ) | |
58dd5b3b | 5043 | { |
a5777624 RD |
5044 | SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK, |
5045 | coords.GetRow(), | |
5046 | coords.GetCol(), | |
5047 | event ); | |
58dd5b3b | 5048 | } |
a5777624 | 5049 | } |
f85afd4e | 5050 | |
8f177c8e | 5051 | |
a5777624 RD |
5052 | // ------------ Left button released |
5053 | // | |
5054 | else if ( event.LeftUp() ) | |
5055 | { | |
5056 | if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL ) | |
f85afd4e | 5057 | { |
b5808881 SN |
5058 | if ( m_selectingTopLeft != wxGridNoCellCoords && |
5059 | m_selectingBottomRight != wxGridNoCellCoords ) | |
52068ea5 | 5060 | { |
a5777624 | 5061 | if (m_winCapture) |
58dd5b3b | 5062 | { |
a5777624 RD |
5063 | m_winCapture->ReleaseMouse(); |
5064 | m_winCapture = NULL; | |
58dd5b3b | 5065 | } |
5c8fc7c1 SN |
5066 | m_selection->SelectBlock( m_selectingTopLeft.GetRow(), |
5067 | m_selectingTopLeft.GetCol(), | |
5068 | m_selectingBottomRight.GetRow(), | |
5069 | m_selectingBottomRight.GetCol(), | |
d95b0c2b SN |
5070 | event.ControlDown(), |
5071 | event.ShiftDown(), | |
5072 | event.AltDown(), | |
5073 | event.MetaDown() ); | |
5c8fc7c1 SN |
5074 | m_selectingTopLeft = wxGridNoCellCoords; |
5075 | m_selectingBottomRight = wxGridNoCellCoords; | |
6d004f67 | 5076 | } |
2d66e025 | 5077 | |
a5777624 RD |
5078 | // Show the edit control, if it has been hidden for |
5079 | // drag-shrinking. | |
5080 | ShowCellEditControl(); | |
5081 | } | |
5082 | else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW ) | |
5083 | { | |
5084 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL); | |
5085 | DoEndDragResizeRow(); | |
e2b42eeb | 5086 | |
a5777624 RD |
5087 | // Note: we are ending the event *after* doing |
5088 | // default processing in this case | |
5089 | // | |
5090 | SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event ); | |
5091 | } | |
5092 | else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL ) | |
5093 | { | |
5094 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL); | |
5095 | DoEndDragResizeCol(); | |
e2b42eeb | 5096 | |
a5777624 RD |
5097 | // Note: we are ending the event *after* doing |
5098 | // default processing in this case | |
5099 | // | |
5100 | SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event ); | |
58dd5b3b | 5101 | } |
f85afd4e | 5102 | |
a5777624 RD |
5103 | m_dragLastPos = -1; |
5104 | } | |
5105 | ||
f85afd4e | 5106 | |
a5777624 RD |
5107 | // ------------ Right button down |
5108 | // | |
5109 | else if ( event.RightDown() && coords != wxGridNoCellCoords ) | |
5110 | { | |
5111 | DisableCellEditControl(); | |
5112 | if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK, | |
5113 | coords.GetRow(), | |
5114 | coords.GetCol(), | |
5115 | event ) ) | |
f85afd4e | 5116 | { |
a5777624 | 5117 | // no default action at the moment |
60ff3b99 | 5118 | } |
a5777624 | 5119 | } |
2d66e025 | 5120 | |
60ff3b99 | 5121 | |
a5777624 RD |
5122 | // ------------ Right double click |
5123 | // | |
5124 | else if ( event.RightDClick() && coords != wxGridNoCellCoords ) | |
5125 | { | |
5126 | DisableCellEditControl(); | |
5127 | if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK, | |
5128 | coords.GetRow(), | |
5129 | coords.GetCol(), | |
5130 | event ) ) | |
f85afd4e | 5131 | { |
a5777624 | 5132 | // no default action at the moment |
60ff3b99 | 5133 | } |
a5777624 RD |
5134 | } |
5135 | ||
5136 | // ------------ Moving and no button action | |
5137 | // | |
5138 | else if ( event.Moving() && !event.IsButton() ) | |
5139 | { | |
5140 | int dragRow = YToEdgeOfRow( y ); | |
5141 | int dragCol = XToEdgeOfCol( x ); | |
790cc417 | 5142 | |
a5777624 RD |
5143 | // Dragging on the corner of a cell to resize in both |
5144 | // directions is not implemented yet... | |
790cc417 | 5145 | // |
a5777624 | 5146 | if ( dragRow >= 0 && dragCol >= 0 ) |
790cc417 | 5147 | { |
a5777624 RD |
5148 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL); |
5149 | return; | |
5150 | } | |
6d004f67 | 5151 | |
a5777624 RD |
5152 | if ( dragRow >= 0 ) |
5153 | { | |
5154 | m_dragRowOrCol = dragRow; | |
6d004f67 | 5155 | |
a5777624 | 5156 | if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL ) |
6d004f67 | 5157 | { |
a5777624 RD |
5158 | if ( CanDragRowSize() && CanDragGridSize() ) |
5159 | ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW); | |
6d004f67 | 5160 | } |
e2b42eeb | 5161 | |
b94ae1ea VZ |
5162 | if ( dragCol >= 0 ) |
5163 | { | |
5164 | m_dragRowOrCol = dragCol; | |
122603f1 | 5165 | } |
b94ae1ea | 5166 | |
a5777624 RD |
5167 | return; |
5168 | } | |
e2b42eeb | 5169 | |
a5777624 RD |
5170 | if ( dragCol >= 0 ) |
5171 | { | |
5172 | m_dragRowOrCol = dragCol; | |
e2b42eeb | 5173 | |
a5777624 | 5174 | if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL ) |
6d004f67 | 5175 | { |
a5777624 RD |
5176 | if ( CanDragColSize() && CanDragGridSize() ) |
5177 | ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL); | |
6d004f67 | 5178 | } |
a5777624 RD |
5179 | |
5180 | return; | |
6d004f67 | 5181 | } |
a5777624 RD |
5182 | |
5183 | // Neither on a row or col edge | |
5184 | // | |
5185 | if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL ) | |
5186 | { | |
5187 | ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL); | |
5188 | } | |
5189 | } | |
6d004f67 MB |
5190 | } |
5191 | ||
5192 | ||
5193 | void wxGrid::DoEndDragResizeRow() | |
5194 | { | |
5195 | if ( m_dragLastPos >= 0 ) | |
5196 | { | |
5197 | // erase the last line and resize the row | |
5198 | // | |
5199 | int cw, ch, left, dummy; | |
5200 | m_gridWin->GetClientSize( &cw, &ch ); | |
5201 | CalcUnscrolledPosition( 0, 0, &left, &dummy ); | |
5202 | ||
5203 | wxClientDC dc( m_gridWin ); | |
5204 | PrepareDC( dc ); | |
5205 | dc.SetLogicalFunction( wxINVERT ); | |
5206 | dc.DrawLine( left, m_dragLastPos, left+cw, m_dragLastPos ); | |
5207 | HideCellEditControl(); | |
a5777624 | 5208 | SaveEditControlValue(); |
6d004f67 | 5209 | |
7c1cb261 | 5210 | int rowTop = GetRowTop(m_dragRowOrCol); |
6d004f67 MB |
5211 | SetRowSize( m_dragRowOrCol, |
5212 | wxMax( m_dragLastPos - rowTop, WXGRID_MIN_ROW_HEIGHT ) ); | |
e2b42eeb | 5213 | |
6d004f67 MB |
5214 | if ( !GetBatchCount() ) |
5215 | { | |
5216 | // Only needed to get the correct rect.y: | |
5217 | wxRect rect ( CellToRect( m_dragRowOrCol, 0 ) ); | |
5218 | rect.x = 0; | |
5219 | CalcScrolledPosition(0, rect.y, &dummy, &rect.y); | |
5220 | rect.width = m_rowLabelWidth; | |
5221 | rect.height = ch - rect.y; | |
5222 | m_rowLabelWin->Refresh( TRUE, &rect ); | |
5223 | rect.width = cw; | |
5224 | m_gridWin->Refresh( FALSE, &rect ); | |
5225 | } | |
5226 | ||
5227 | ShowCellEditControl(); | |
5228 | } | |
5229 | } | |
5230 | ||
5231 | ||
5232 | void wxGrid::DoEndDragResizeCol() | |
5233 | { | |
5234 | if ( m_dragLastPos >= 0 ) | |
5235 | { | |
5236 | // erase the last line and resize the col | |
5237 | // | |
5238 | int cw, ch, dummy, top; | |
5239 | m_gridWin->GetClientSize( &cw, &ch ); | |
5240 | CalcUnscrolledPosition( 0, 0, &dummy, &top ); | |
5241 | ||
5242 | wxClientDC dc( m_gridWin ); | |
5243 | PrepareDC( dc ); | |
5244 | dc.SetLogicalFunction( wxINVERT ); | |
5245 | dc.DrawLine( m_dragLastPos, top, m_dragLastPos, top+ch ); | |
5246 | HideCellEditControl(); | |
a5777624 | 5247 | SaveEditControlValue(); |
6d004f67 | 5248 | |
7c1cb261 | 5249 | int colLeft = GetColLeft(m_dragRowOrCol); |
6d004f67 | 5250 | SetColSize( m_dragRowOrCol, |
43947979 VZ |
5251 | wxMax( m_dragLastPos - colLeft, |
5252 | GetColMinimalWidth(m_dragRowOrCol) ) ); | |
6d004f67 MB |
5253 | |
5254 | if ( !GetBatchCount() ) | |
5255 | { | |
5256 | // Only needed to get the correct rect.x: | |
5257 | wxRect rect ( CellToRect( 0, m_dragRowOrCol ) ); | |
5258 | rect.y = 0; | |
5259 | CalcScrolledPosition(rect.x, 0, &rect.x, &dummy); | |
5260 | rect.width = cw - rect.x; | |
5261 | rect.height = m_colLabelHeight; | |
5262 | m_colLabelWin->Refresh( TRUE, &rect ); | |
5263 | rect.height = ch; | |
5264 | m_gridWin->Refresh( FALSE, &rect ); | |
790cc417 | 5265 | } |
e2b42eeb | 5266 | |
6d004f67 | 5267 | ShowCellEditControl(); |
f85afd4e | 5268 | } |
f85afd4e MB |
5269 | } |
5270 | ||
5271 | ||
6d004f67 | 5272 | |
2d66e025 MB |
5273 | // |
5274 | // ------ interaction with data model | |
5275 | // | |
5276 | bool wxGrid::ProcessTableMessage( wxGridTableMessage& msg ) | |
f85afd4e | 5277 | { |
2d66e025 | 5278 | switch ( msg.GetId() ) |
17732cec | 5279 | { |
2d66e025 MB |
5280 | case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES: |
5281 | return GetModelValues(); | |
17732cec | 5282 | |
2d66e025 MB |
5283 | case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES: |
5284 | return SetModelValues(); | |
f85afd4e | 5285 | |
2d66e025 MB |
5286 | case wxGRIDTABLE_NOTIFY_ROWS_INSERTED: |
5287 | case wxGRIDTABLE_NOTIFY_ROWS_APPENDED: | |
5288 | case wxGRIDTABLE_NOTIFY_ROWS_DELETED: | |
5289 | case wxGRIDTABLE_NOTIFY_COLS_INSERTED: | |
5290 | case wxGRIDTABLE_NOTIFY_COLS_APPENDED: | |
5291 | case wxGRIDTABLE_NOTIFY_COLS_DELETED: | |
5292 | return Redimension( msg ); | |
5293 | ||
5294 | default: | |
5295 | return FALSE; | |
f85afd4e | 5296 | } |
2d66e025 | 5297 | } |
f85afd4e | 5298 | |
f85afd4e | 5299 | |
f85afd4e | 5300 | |
2d66e025 MB |
5301 | // The behaviour of this function depends on the grid table class |
5302 | // Clear() function. For the default wxGridStringTable class the | |
5303 | // behavious is to replace all cell contents with wxEmptyString but | |
5304 | // not to change the number of rows or cols. | |
5305 | // | |
5306 | void wxGrid::ClearGrid() | |
5307 | { | |
5308 | if ( m_table ) | |
f85afd4e | 5309 | { |
4cfa5de6 RD |
5310 | if (IsCellEditControlEnabled()) |
5311 | DisableCellEditControl(); | |
5312 | ||
2d66e025 | 5313 | m_table->Clear(); |
1f1ce288 | 5314 | if ( !GetBatchCount() ) m_gridWin->Refresh(); |
f85afd4e MB |
5315 | } |
5316 | } | |
5317 | ||
5318 | ||
2d66e025 | 5319 | bool wxGrid::InsertRows( int pos, int numRows, bool WXUNUSED(updateLabels) ) |
f85afd4e | 5320 | { |
2d66e025 | 5321 | // TODO: something with updateLabels flag |
8f177c8e | 5322 | |
2d66e025 | 5323 | if ( !m_created ) |
f85afd4e | 5324 | { |
bd3c6758 | 5325 | wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") ); |
2d66e025 MB |
5326 | return FALSE; |
5327 | } | |
8f177c8e | 5328 | |
2d66e025 MB |
5329 | if ( m_table ) |
5330 | { | |
b7fff980 | 5331 | if (IsCellEditControlEnabled()) |
b54ba671 | 5332 | DisableCellEditControl(); |
b7fff980 | 5333 | |
f6bcfd97 | 5334 | return m_table->InsertRows( pos, numRows ); |
f85afd4e | 5335 | |
2d66e025 MB |
5336 | // the table will have sent the results of the insert row |
5337 | // operation to this view object as a grid table message | |
f85afd4e | 5338 | } |
f6bcfd97 | 5339 | return FALSE; |
f85afd4e MB |
5340 | } |
5341 | ||
5342 | ||
2d66e025 | 5343 | bool wxGrid::AppendRows( int numRows, bool WXUNUSED(updateLabels) ) |
f85afd4e | 5344 | { |
2d66e025 MB |
5345 | // TODO: something with updateLabels flag |
5346 | ||
5347 | if ( !m_created ) | |
f85afd4e | 5348 | { |
bd3c6758 | 5349 | wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") ); |
2d66e025 MB |
5350 | return FALSE; |
5351 | } | |
5352 | ||
f6bcfd97 BP |
5353 | return ( m_table && m_table->AppendRows( numRows ) ); |
5354 | // the table will have sent the results of the append row | |
5355 | // operation to this view object as a grid table message | |
f85afd4e MB |
5356 | } |
5357 | ||
2d66e025 MB |
5358 | |
5359 | bool wxGrid::DeleteRows( int pos, int numRows, bool WXUNUSED(updateLabels) ) | |
f85afd4e | 5360 | { |
2d66e025 MB |
5361 | // TODO: something with updateLabels flag |
5362 | ||
5363 | if ( !m_created ) | |
f85afd4e | 5364 | { |
bd3c6758 | 5365 | wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") ); |
2d66e025 MB |
5366 | return FALSE; |
5367 | } | |
5368 | ||
b7fff980 | 5369 | if ( m_table ) |
2d66e025 | 5370 | { |
b7fff980 | 5371 | if (IsCellEditControlEnabled()) |
b54ba671 | 5372 | DisableCellEditControl(); |
f85afd4e | 5373 | |
f6bcfd97 BP |
5374 | return (m_table->DeleteRows( pos, numRows )); |
5375 | // the table will have sent the results of the delete row | |
5376 | // operation to this view object as a grid table message | |
2d66e025 | 5377 | } |
b7fff980 | 5378 | return FALSE; |
2d66e025 | 5379 | } |
f85afd4e | 5380 | |
f85afd4e | 5381 | |
2d66e025 MB |
5382 | bool wxGrid::InsertCols( int pos, int numCols, bool WXUNUSED(updateLabels) ) |
5383 | { | |
5384 | // TODO: something with updateLabels flag | |
8f177c8e | 5385 | |
2d66e025 MB |
5386 | if ( !m_created ) |
5387 | { | |
bd3c6758 | 5388 | wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") ); |
2d66e025 MB |
5389 | return FALSE; |
5390 | } | |
f85afd4e | 5391 | |
2d66e025 MB |
5392 | if ( m_table ) |
5393 | { | |
b7fff980 | 5394 | if (IsCellEditControlEnabled()) |
b54ba671 | 5395 | DisableCellEditControl(); |
b7fff980 | 5396 | |
f6bcfd97 | 5397 | return m_table->InsertCols( pos, numCols ); |
2d66e025 MB |
5398 | // the table will have sent the results of the insert col |
5399 | // operation to this view object as a grid table message | |
f85afd4e | 5400 | } |
f6bcfd97 | 5401 | return FALSE; |
f85afd4e MB |
5402 | } |
5403 | ||
2d66e025 MB |
5404 | |
5405 | bool wxGrid::AppendCols( int numCols, bool WXUNUSED(updateLabels) ) | |
f85afd4e | 5406 | { |
2d66e025 MB |
5407 | // TODO: something with updateLabels flag |
5408 | ||
5409 | if ( !m_created ) | |
f85afd4e | 5410 | { |
bd3c6758 | 5411 | wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") ); |
2d66e025 MB |
5412 | return FALSE; |
5413 | } | |
f85afd4e | 5414 | |
f6bcfd97 BP |
5415 | return ( m_table && m_table->AppendCols( numCols ) ); |
5416 | // the table will have sent the results of the append col | |
5417 | // operation to this view object as a grid table message | |
f85afd4e MB |
5418 | } |
5419 | ||
5420 | ||
2d66e025 | 5421 | bool wxGrid::DeleteCols( int pos, int numCols, bool WXUNUSED(updateLabels) ) |
f85afd4e | 5422 | { |
2d66e025 | 5423 | // TODO: something with updateLabels flag |
8f177c8e | 5424 | |
2d66e025 | 5425 | if ( !m_created ) |
f85afd4e | 5426 | { |
bd3c6758 | 5427 | wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") ); |
2d66e025 | 5428 | return FALSE; |
f85afd4e MB |
5429 | } |
5430 | ||
b7fff980 | 5431 | if ( m_table ) |
2d66e025 | 5432 | { |
b7fff980 | 5433 | if (IsCellEditControlEnabled()) |
b54ba671 | 5434 | DisableCellEditControl(); |
8f177c8e | 5435 | |
f6bcfd97 BP |
5436 | return ( m_table->DeleteCols( pos, numCols ) ); |
5437 | // the table will have sent the results of the delete col | |
5438 | // operation to this view object as a grid table message | |
f85afd4e | 5439 | } |
b7fff980 | 5440 | return FALSE; |
f85afd4e MB |
5441 | } |
5442 | ||
5443 | ||
2d66e025 MB |
5444 | |
5445 | // | |
5446 | // ----- event handlers | |
f85afd4e | 5447 | // |
8f177c8e | 5448 | |
2d66e025 MB |
5449 | // Generate a grid event based on a mouse event and |
5450 | // return the result of ProcessEvent() | |
5451 | // | |
5452 | bool wxGrid::SendEvent( const wxEventType type, | |
5453 | int row, int col, | |
5454 | wxMouseEvent& mouseEv ) | |
5455 | { | |
b54ba671 | 5456 | if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE ) |
f85afd4e | 5457 | { |
2d66e025 MB |
5458 | int rowOrCol = (row == -1 ? col : row); |
5459 | ||
5460 | wxGridSizeEvent gridEvt( GetId(), | |
5461 | type, | |
5462 | this, | |
5463 | rowOrCol, | |
faec5a43 SN |
5464 | mouseEv.GetX() + GetRowLabelSize(), |
5465 | mouseEv.GetY() + GetColLabelSize(), | |
2d66e025 MB |
5466 | mouseEv.ControlDown(), |
5467 | mouseEv.ShiftDown(), | |
5468 | mouseEv.AltDown(), | |
5469 | mouseEv.MetaDown() ); | |
2d66e025 | 5470 | return GetEventHandler()->ProcessEvent(gridEvt); |
f85afd4e | 5471 | } |
b54ba671 | 5472 | else if ( type == wxEVT_GRID_RANGE_SELECT ) |
2d66e025 | 5473 | { |
f6bcfd97 | 5474 | // Right now, it should _never_ end up here! |
2d66e025 MB |
5475 | wxGridRangeSelectEvent gridEvt( GetId(), |
5476 | type, | |
5477 | this, | |
b5808881 SN |
5478 | m_selectingTopLeft, |
5479 | m_selectingBottomRight, | |
5c8fc7c1 | 5480 | TRUE, |
2d66e025 MB |
5481 | mouseEv.ControlDown(), |
5482 | mouseEv.ShiftDown(), | |
5483 | mouseEv.AltDown(), | |
5484 | mouseEv.MetaDown() ); | |
f85afd4e | 5485 | |
2d66e025 MB |
5486 | return GetEventHandler()->ProcessEvent(gridEvt); |
5487 | } | |
5488 | else | |
5489 | { | |
5490 | wxGridEvent gridEvt( GetId(), | |
5491 | type, | |
5492 | this, | |
5493 | row, col, | |
faec5a43 SN |
5494 | mouseEv.GetX() + GetRowLabelSize(), |
5495 | mouseEv.GetY() + GetColLabelSize(), | |
d7da9756 | 5496 | FALSE, |
2d66e025 MB |
5497 | mouseEv.ControlDown(), |
5498 | mouseEv.ShiftDown(), | |
5499 | mouseEv.AltDown(), | |
5500 | mouseEv.MetaDown() ); | |
2d66e025 MB |
5501 | return GetEventHandler()->ProcessEvent(gridEvt); |
5502 | } | |
f85afd4e MB |
5503 | } |
5504 | ||
5505 | ||
2d66e025 MB |
5506 | // Generate a grid event of specified type and return the result |
5507 | // of ProcessEvent(). | |
f85afd4e | 5508 | // |
2d66e025 MB |
5509 | bool wxGrid::SendEvent( const wxEventType type, |
5510 | int row, int col ) | |
f85afd4e | 5511 | { |
b54ba671 | 5512 | if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE ) |
f85afd4e | 5513 | { |
2d66e025 | 5514 | int rowOrCol = (row == -1 ? col : row); |
f85afd4e | 5515 | |
2d66e025 MB |
5516 | wxGridSizeEvent gridEvt( GetId(), |
5517 | type, | |
5518 | this, | |
5519 | rowOrCol ); | |
5520 | ||
5521 | return GetEventHandler()->ProcessEvent(gridEvt); | |
5522 | } | |
5523 | else | |
5524 | { | |
5525 | wxGridEvent gridEvt( GetId(), | |
5526 | type, | |
5527 | this, | |
5528 | row, col ); | |
8f177c8e | 5529 | |
2d66e025 MB |
5530 | return GetEventHandler()->ProcessEvent(gridEvt); |
5531 | } | |
f85afd4e MB |
5532 | } |
5533 | ||
5534 | ||
2d66e025 | 5535 | void wxGrid::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
f85afd4e | 5536 | { |
f6bcfd97 | 5537 | wxPaintDC dc(this); // needed to prevent zillions of paint events on MSW |
8f177c8e | 5538 | } |
f85afd4e MB |
5539 | |
5540 | ||
18f9565d MB |
5541 | // This is just here to make sure that CalcDimensions gets called when |
5542 | // the grid view is resized... then the size event is skipped to allow | |
5543 | // the box sizers to handle everything | |
5544 | // | |
aa5e1f75 | 5545 | void wxGrid::OnSize( wxSizeEvent& WXUNUSED(event) ) |
f85afd4e | 5546 | { |
7807d81c | 5547 | CalcWindowSizes(); |
2d66e025 | 5548 | CalcDimensions(); |
f85afd4e MB |
5549 | } |
5550 | ||
f85afd4e | 5551 | |
2d66e025 | 5552 | void wxGrid::OnKeyDown( wxKeyEvent& event ) |
f85afd4e | 5553 | { |
2d66e025 | 5554 | if ( m_inOnKeyDown ) |
f85afd4e | 5555 | { |
2d66e025 MB |
5556 | // shouldn't be here - we are going round in circles... |
5557 | // | |
07296f0b | 5558 | wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") ); |
f85afd4e MB |
5559 | } |
5560 | ||
2d66e025 | 5561 | m_inOnKeyDown = TRUE; |
f85afd4e | 5562 | |
2d66e025 MB |
5563 | // propagate the event up and see if it gets processed |
5564 | // | |
5565 | wxWindow *parent = GetParent(); | |
5566 | wxKeyEvent keyEvt( event ); | |
5567 | keyEvt.SetEventObject( parent ); | |
5568 | ||
5569 | if ( !parent->GetEventHandler()->ProcessEvent( keyEvt ) ) | |
f85afd4e | 5570 | { |
9b4aede2 | 5571 | |
2d66e025 MB |
5572 | // try local handlers |
5573 | // | |
5574 | switch ( event.KeyCode() ) | |
5575 | { | |
5576 | case WXK_UP: | |
5577 | if ( event.ControlDown() ) | |
5578 | { | |
5c8fc7c1 | 5579 | MoveCursorUpBlock( event.ShiftDown() ); |
2d66e025 MB |
5580 | } |
5581 | else | |
5582 | { | |
5c8fc7c1 | 5583 | MoveCursorUp( event.ShiftDown() ); |
2d66e025 MB |
5584 | } |
5585 | break; | |
f85afd4e | 5586 | |
2d66e025 MB |
5587 | case WXK_DOWN: |
5588 | if ( event.ControlDown() ) | |
5589 | { | |
5c8fc7c1 | 5590 | MoveCursorDownBlock( event.ShiftDown() ); |
2d66e025 MB |
5591 | } |
5592 | else | |
5593 | { | |
5c8fc7c1 | 5594 | MoveCursorDown( event.ShiftDown() ); |
2d66e025 MB |
5595 | } |
5596 | break; | |
8f177c8e | 5597 | |
2d66e025 MB |
5598 | case WXK_LEFT: |
5599 | if ( event.ControlDown() ) | |
5600 | { | |
5c8fc7c1 | 5601 | MoveCursorLeftBlock( event.ShiftDown() ); |
2d66e025 MB |
5602 | } |
5603 | else | |
5604 | { | |
5c8fc7c1 | 5605 | MoveCursorLeft( event.ShiftDown() ); |
2d66e025 MB |
5606 | } |
5607 | break; | |
5608 | ||
5609 | case WXK_RIGHT: | |
5610 | if ( event.ControlDown() ) | |
5611 | { | |
5c8fc7c1 | 5612 | MoveCursorRightBlock( event.ShiftDown() ); |
2d66e025 MB |
5613 | } |
5614 | else | |
5615 | { | |
5c8fc7c1 | 5616 | MoveCursorRight( event.ShiftDown() ); |
2d66e025 MB |
5617 | } |
5618 | break; | |
b99be8fb | 5619 | |
2d66e025 | 5620 | case WXK_RETURN: |
a4f7bf58 | 5621 | case WXK_NUMPAD_ENTER: |
58dd5b3b MB |
5622 | if ( event.ControlDown() ) |
5623 | { | |
5624 | event.Skip(); // to let the edit control have the return | |
5625 | } | |
5626 | else | |
5627 | { | |
f6bcfd97 BP |
5628 | if ( GetGridCursorRow() < GetNumberRows()-1 ) |
5629 | { | |
5630 | MoveCursorDown( event.ShiftDown() ); | |
5631 | } | |
5632 | else | |
5633 | { | |
5634 | // at the bottom of a column | |
5635 | HideCellEditControl(); | |
5636 | SaveEditControlValue(); | |
5637 | } | |
58dd5b3b | 5638 | } |
2d66e025 MB |
5639 | break; |
5640 | ||
5c8fc7c1 | 5641 | case WXK_ESCAPE: |
e32352cf | 5642 | ClearSelection(); |
5c8fc7c1 SN |
5643 | break; |
5644 | ||
2c9a89e0 RD |
5645 | case WXK_TAB: |
5646 | if (event.ShiftDown()) | |
f6bcfd97 BP |
5647 | { |
5648 | if ( GetGridCursorCol() > 0 ) | |
5649 | { | |
5650 | MoveCursorLeft( FALSE ); | |
5651 | } | |
5652 | else | |
5653 | { | |
5654 | // at left of grid | |
5655 | HideCellEditControl(); | |
5656 | SaveEditControlValue(); | |
5657 | } | |
5658 | } | |
2c9a89e0 | 5659 | else |
f6bcfd97 BP |
5660 | { |
5661 | if ( GetGridCursorCol() < GetNumberCols()-1 ) | |
5662 | { | |
5663 | MoveCursorRight( FALSE ); | |
5664 | } | |
5665 | else | |
5666 | { | |
5667 | // at right of grid | |
5668 | HideCellEditControl(); | |
5669 | SaveEditControlValue(); | |
5670 | } | |
5671 | } | |
2c9a89e0 RD |
5672 | break; |
5673 | ||
2d66e025 MB |
5674 | case WXK_HOME: |
5675 | if ( event.ControlDown() ) | |
5676 | { | |
5677 | MakeCellVisible( 0, 0 ); | |
5678 | SetCurrentCell( 0, 0 ); | |
5679 | } | |
5680 | else | |
5681 | { | |
5682 | event.Skip(); | |
5683 | } | |
5684 | break; | |
5685 | ||
5686 | case WXK_END: | |
5687 | if ( event.ControlDown() ) | |
5688 | { | |
5689 | MakeCellVisible( m_numRows-1, m_numCols-1 ); | |
5690 | SetCurrentCell( m_numRows-1, m_numCols-1 ); | |
5691 | } | |
5692 | else | |
5693 | { | |
5694 | event.Skip(); | |
5695 | } | |
5696 | break; | |
5697 | ||
5698 | case WXK_PRIOR: | |
5699 | MovePageUp(); | |
5700 | break; | |
5701 | ||
5702 | case WXK_NEXT: | |
5703 | MovePageDown(); | |
5704 | break; | |
5705 | ||
07296f0b | 5706 | case WXK_SPACE: |
aa5e1f75 SN |
5707 | if ( event.ControlDown() ) |
5708 | { | |
5709 | m_selection->ToggleCellSelection( m_currentCellCoords.GetRow(), | |
5710 | m_currentCellCoords.GetCol(), | |
5711 | event.ControlDown(), | |
5712 | event.ShiftDown(), | |
5713 | event.AltDown(), | |
5714 | event.MetaDown() ); | |
5715 | break; | |
5716 | } | |
07296f0b RD |
5717 | if ( !IsEditable() ) |
5718 | { | |
5c8fc7c1 | 5719 | MoveCursorRight( FALSE ); |
07296f0b RD |
5720 | break; |
5721 | } | |
5722 | // Otherwise fall through to default | |
5723 | ||
2d66e025 | 5724 | default: |
f6bcfd97 BP |
5725 | // is it possible to edit the current cell at all? |
5726 | if ( !IsCellEditControlEnabled() && CanEnableCellControl() ) | |
b54ba671 | 5727 | { |
f6bcfd97 | 5728 | // yes, now check whether the cells editor accepts the key |
f2d76237 RD |
5729 | int row = m_currentCellCoords.GetRow(); |
5730 | int col = m_currentCellCoords.GetCol(); | |
5731 | wxGridCellAttr* attr = GetCellAttr(row, col); | |
0b190b0f | 5732 | wxGridCellEditor *editor = attr->GetEditor(this, row, col); |
f6bcfd97 BP |
5733 | |
5734 | // <F2> is special and will always start editing, for | |
5735 | // other keys - ask the editor itself | |
5736 | if ( (event.KeyCode() == WXK_F2 && !event.HasModifiers()) | |
5737 | || editor->IsAcceptedKey(event) ) | |
5738 | { | |
5739 | EnableCellEditControl(); | |
5740 | editor->StartingKey(event); | |
5741 | } | |
5742 | else | |
5743 | { | |
5744 | event.Skip(); | |
5745 | } | |
5746 | ||
0b190b0f | 5747 | editor->DecRef(); |
2c9a89e0 RD |
5748 | attr->DecRef(); |
5749 | } | |
b3a7510d VZ |
5750 | else |
5751 | { | |
b94ae1ea VZ |
5752 | // let others process char events with modifiers or all |
5753 | // char events for readonly cells | |
b3a7510d VZ |
5754 | event.Skip(); |
5755 | } | |
025562fe | 5756 | break; |
2d66e025 | 5757 | } |
f85afd4e MB |
5758 | } |
5759 | ||
2d66e025 | 5760 | m_inOnKeyDown = FALSE; |
f85afd4e MB |
5761 | } |
5762 | ||
f6bcfd97 BP |
5763 | void wxGrid::OnKeyUp( wxKeyEvent& event ) |
5764 | { | |
5765 | // try local handlers | |
5766 | // | |
5767 | if ( event.KeyCode() == WXK_SHIFT ) | |
5768 | { | |
5769 | if ( m_selectingTopLeft != wxGridNoCellCoords && | |
5770 | m_selectingBottomRight != wxGridNoCellCoords ) | |
5771 | m_selection->SelectBlock( m_selectingTopLeft.GetRow(), | |
5772 | m_selectingTopLeft.GetCol(), | |
5773 | m_selectingBottomRight.GetRow(), | |
5774 | m_selectingBottomRight.GetCol(), | |
5775 | event.ControlDown(), | |
5776 | TRUE, | |
5777 | event.AltDown(), | |
5778 | event.MetaDown() ); | |
5779 | m_selectingTopLeft = wxGridNoCellCoords; | |
5780 | m_selectingBottomRight = wxGridNoCellCoords; | |
5781 | m_selectingKeyboard = wxGridNoCellCoords; | |
5782 | } | |
5783 | } | |
5784 | ||
2796cce3 | 5785 | void wxGrid::OnEraseBackground(wxEraseEvent&) |
508011ce VZ |
5786 | { |
5787 | } | |
07296f0b | 5788 | |
2d66e025 | 5789 | void wxGrid::SetCurrentCell( const wxGridCellCoords& coords ) |
66242c80 | 5790 | { |
f6bcfd97 BP |
5791 | if ( SendEvent( wxEVT_GRID_SELECT_CELL, coords.GetRow(), coords.GetCol() ) ) |
5792 | { | |
5793 | // the event has been intercepted - do nothing | |
5794 | return; | |
5795 | } | |
5796 | ||
5797 | wxClientDC dc(m_gridWin); | |
5798 | PrepareDC(dc); | |
5799 | ||
2a7750d9 | 5800 | if ( m_currentCellCoords != wxGridNoCellCoords ) |
2d66e025 | 5801 | { |
2d66e025 | 5802 | HideCellEditControl(); |
b54ba671 | 5803 | DisableCellEditControl(); |
07296f0b | 5804 | |
3ca6a5f0 | 5805 | if ( IsVisible( m_currentCellCoords, FALSE ) ) |
f6bcfd97 BP |
5806 | { |
5807 | wxRect r; | |
d10f4bf9 | 5808 | r = BlockToDeviceRect(m_currentCellCoords, coords); |
f6bcfd97 BP |
5809 | if ( !m_gridLinesEnabled ) |
5810 | { | |
5811 | r.x--; | |
5812 | r.y--; | |
5813 | r.width++; | |
5814 | r.height++; | |
5815 | } | |
d1c0b4f9 | 5816 | |
d10f4bf9 | 5817 | wxGridCellCoordsArray cells = CalcCellsExposed( r ); |
84912ef8 | 5818 | |
f6bcfd97 BP |
5819 | // Otherwise refresh redraws the highlight! |
5820 | m_currentCellCoords = coords; | |
275c4ae4 | 5821 | |
d10f4bf9 | 5822 | DrawGridCellArea(dc,cells); |
f6bcfd97 BP |
5823 | DrawAllGridLines( dc, r ); |
5824 | } | |
66242c80 | 5825 | } |
8f177c8e | 5826 | |
2d66e025 MB |
5827 | m_currentCellCoords = coords; |
5828 | ||
2a7750d9 MB |
5829 | wxGridCellAttr* attr = GetCellAttr(coords); |
5830 | DrawCellHighlight(dc, attr); | |
5831 | attr->DecRef(); | |
66242c80 MB |
5832 | } |
5833 | ||
2d66e025 | 5834 | |
c9097836 MB |
5835 | void wxGrid::HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCol ) |
5836 | { | |
5837 | int temp; | |
5838 | wxGridCellCoords updateTopLeft, updateBottomRight; | |
5839 | ||
5840 | if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows ) | |
5841 | { | |
5842 | leftCol = 0; | |
5843 | rightCol = GetNumberCols() - 1; | |
5844 | } | |
5845 | else if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectColumns ) | |
5846 | { | |
5847 | topRow = 0; | |
5848 | bottomRow = GetNumberRows() - 1; | |
5849 | } | |
5850 | if ( topRow > bottomRow ) | |
5851 | { | |
5852 | temp = topRow; | |
5853 | topRow = bottomRow; | |
5854 | bottomRow = temp; | |
5855 | } | |
5856 | ||
5857 | if ( leftCol > rightCol ) | |
5858 | { | |
5859 | temp = leftCol; | |
5860 | leftCol = rightCol; | |
5861 | rightCol = temp; | |
5862 | } | |
5863 | ||
5864 | updateTopLeft = wxGridCellCoords( topRow, leftCol ); | |
5865 | updateBottomRight = wxGridCellCoords( bottomRow, rightCol ); | |
5866 | ||
5867 | if ( m_selectingTopLeft != updateTopLeft || | |
5868 | m_selectingBottomRight != updateBottomRight ) | |
5869 | { | |
5870 | // Compute two optimal update rectangles: | |
5871 | // Either one rectangle is a real subset of the | |
5872 | // other, or they are (almost) disjoint! | |
5873 | wxRect rect[4]; | |
5874 | bool need_refresh[4]; | |
5875 | need_refresh[0] = | |
5876 | need_refresh[1] = | |
5877 | need_refresh[2] = | |
5878 | need_refresh[3] = FALSE; | |
5879 | int i; | |
5880 | ||
5881 | // Store intermediate values | |
5882 | wxCoord oldLeft = m_selectingTopLeft.GetCol(); | |
5883 | wxCoord oldTop = m_selectingTopLeft.GetRow(); | |
5884 | wxCoord oldRight = m_selectingBottomRight.GetCol(); | |
5885 | wxCoord oldBottom = m_selectingBottomRight.GetRow(); | |
5886 | ||
5887 | // Determine the outer/inner coordinates. | |
5888 | if (oldLeft > leftCol) | |
5889 | { | |
5890 | temp = oldLeft; | |
5891 | oldLeft = leftCol; | |
5892 | leftCol = temp; | |
5893 | } | |
5894 | if (oldTop > topRow ) | |
5895 | { | |
5896 | temp = oldTop; | |
5897 | oldTop = topRow; | |
5898 | topRow = temp; | |
5899 | } | |
5900 | if (oldRight < rightCol ) | |
5901 | { | |
5902 | temp = oldRight; | |
5903 | oldRight = rightCol; | |
5904 | rightCol = temp; | |
5905 | } | |
5906 | if (oldBottom < bottomRow) | |
5907 | { | |
5908 | temp = oldBottom; | |
5909 | oldBottom = bottomRow; | |
5910 | bottomRow = temp; | |
5911 | } | |
5912 | ||
5913 | // Now, either the stuff marked old is the outer | |
5914 | // rectangle or we don't have a situation where one | |
5915 | // is contained in the other. | |
5916 | ||
5917 | if ( oldLeft < leftCol ) | |
5918 | { | |
5919 | need_refresh[0] = TRUE; | |
5920 | rect[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop, | |
5921 | oldLeft ), | |
5922 | wxGridCellCoords ( oldBottom, | |
5923 | leftCol - 1 ) ); | |
5924 | } | |
5925 | ||
5926 | if ( oldTop < topRow ) | |
5927 | { | |
5928 | need_refresh[1] = TRUE; | |
5929 | rect[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop, | |
5930 | leftCol ), | |
5931 | wxGridCellCoords ( topRow - 1, | |
5932 | rightCol ) ); | |
5933 | } | |
5934 | ||
5935 | if ( oldRight > rightCol ) | |
5936 | { | |
5937 | need_refresh[2] = TRUE; | |
5938 | rect[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop, | |
5939 | rightCol + 1 ), | |
5940 | wxGridCellCoords ( oldBottom, | |
5941 | oldRight ) ); | |
5942 | } | |
5943 | ||
5944 | if ( oldBottom > bottomRow ) | |
5945 | { | |
5946 | need_refresh[3] = TRUE; | |
5947 | rect[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow + 1, | |
5948 | leftCol ), | |
5949 | wxGridCellCoords ( oldBottom, | |
5950 | rightCol ) ); | |
5951 | } | |
5952 | ||
5953 | ||
5954 | // Change Selection | |
5955 | m_selectingTopLeft = updateTopLeft; | |
5956 | m_selectingBottomRight = updateBottomRight; | |
5957 | ||
5958 | // various Refresh() calls | |
5959 | for (i = 0; i < 4; i++ ) | |
5960 | if ( need_refresh[i] && rect[i] != wxGridNoCellRect ) | |
5961 | m_gridWin->Refresh( FALSE, &(rect[i]) ); | |
5962 | } | |
5963 | ||
5964 | // never generate an event as it will be generated from | |
5965 | // wxGridSelection::SelectBlock! | |
5966 | // (old comment from when this was the body of SelectBlock) | |
5967 | } | |
5968 | ||
2d66e025 MB |
5969 | // |
5970 | // ------ functions to get/send data (see also public functions) | |
5971 | // | |
5972 | ||
5973 | bool wxGrid::GetModelValues() | |
66242c80 | 5974 | { |
2d66e025 | 5975 | if ( m_table ) |
66242c80 | 5976 | { |
2d66e025 | 5977 | // all we need to do is repaint the grid |
66242c80 | 5978 | // |
2d66e025 | 5979 | m_gridWin->Refresh(); |
66242c80 MB |
5980 | return TRUE; |
5981 | } | |
8f177c8e | 5982 | |
66242c80 MB |
5983 | return FALSE; |
5984 | } | |
5985 | ||
2d66e025 MB |
5986 | |
5987 | bool wxGrid::SetModelValues() | |
f85afd4e | 5988 | { |
2d66e025 | 5989 | int row, col; |
8f177c8e | 5990 | |
2d66e025 MB |
5991 | if ( m_table ) |
5992 | { | |
5993 | for ( row = 0; row < m_numRows; row++ ) | |
f85afd4e | 5994 | { |
2d66e025 | 5995 | for ( col = 0; col < m_numCols; col++ ) |
f85afd4e | 5996 | { |
2d66e025 | 5997 | m_table->SetValue( row, col, GetCellValue(row, col) ); |
f85afd4e MB |
5998 | } |
5999 | } | |
8f177c8e | 6000 | |
f85afd4e MB |
6001 | return TRUE; |
6002 | } | |
6003 | ||
6004 | return FALSE; | |
6005 | } | |
6006 | ||
2d66e025 MB |
6007 | |
6008 | ||
6009 | // Note - this function only draws cells that are in the list of | |
6010 | // exposed cells (usually set from the update region by | |
6011 | // CalcExposedCells) | |
6012 | // | |
d10f4bf9 | 6013 | void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells ) |
f85afd4e | 6014 | { |
2d66e025 | 6015 | if ( !m_numRows || !m_numCols ) return; |
60ff3b99 | 6016 | |
2d66e025 | 6017 | size_t i; |
d10f4bf9 | 6018 | size_t numCells = cells.GetCount(); |
60ff3b99 | 6019 | |
2d66e025 | 6020 | for ( i = 0; i < numCells; i++ ) |
f85afd4e | 6021 | { |
d10f4bf9 | 6022 | DrawCell( dc, cells[i] ); |
2d66e025 MB |
6023 | } |
6024 | } | |
8f177c8e | 6025 | |
8f177c8e | 6026 | |
7c8a8ad5 MB |
6027 | void wxGrid::DrawGridSpace( wxDC& dc ) |
6028 | { | |
f6bcfd97 BP |
6029 | int cw, ch; |
6030 | m_gridWin->GetClientSize( &cw, &ch ); | |
7c8a8ad5 | 6031 | |
f6bcfd97 BP |
6032 | int right, bottom; |
6033 | CalcUnscrolledPosition( cw, ch, &right, &bottom ); | |
7c8a8ad5 | 6034 | |
f6bcfd97 BP |
6035 | int rightCol = m_numCols > 0 ? GetColRight(m_numCols - 1) : 0; |
6036 | int bottomRow = m_numRows > 0 ? GetRowBottom(m_numRows - 1) : 0 ; | |
7c8a8ad5 | 6037 | |
f6bcfd97 BP |
6038 | if ( right > rightCol || bottom > bottomRow ) |
6039 | { | |
6040 | int left, top; | |
6041 | CalcUnscrolledPosition( 0, 0, &left, &top ); | |
7c8a8ad5 | 6042 | |
f6bcfd97 BP |
6043 | dc.SetBrush( wxBrush(GetDefaultCellBackgroundColour(), wxSOLID) ); |
6044 | dc.SetPen( *wxTRANSPARENT_PEN ); | |
7c8a8ad5 | 6045 | |
f6bcfd97 BP |
6046 | if ( right > rightCol ) |
6047 | { | |
6048 | dc.DrawRectangle( rightCol, top, right - rightCol, ch); | |
6049 | } | |
6050 | ||
6051 | if ( bottom > bottomRow ) | |
6052 | { | |
6053 | dc.DrawRectangle( left, bottomRow, cw, bottom - bottomRow); | |
6054 | } | |
6055 | } | |
7c8a8ad5 MB |
6056 | } |
6057 | ||
6058 | ||
2d66e025 MB |
6059 | void wxGrid::DrawCell( wxDC& dc, const wxGridCellCoords& coords ) |
6060 | { | |
ab79958a VZ |
6061 | int row = coords.GetRow(); |
6062 | int col = coords.GetCol(); | |
60ff3b99 | 6063 | |
7c1cb261 | 6064 | if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) |
ab79958a VZ |
6065 | return; |
6066 | ||
6067 | // we draw the cell border ourselves | |
9496deb5 | 6068 | #if !WXGRID_DRAW_LINES |
2d66e025 MB |
6069 | if ( m_gridLinesEnabled ) |
6070 | DrawCellBorder( dc, coords ); | |
796df70a | 6071 | #endif |
f85afd4e | 6072 | |
189d0213 VZ |
6073 | wxGridCellAttr* attr = GetCellAttr(row, col); |
6074 | ||
6075 | bool isCurrent = coords == m_currentCellCoords; | |
508011ce | 6076 | |
f6bcfd97 | 6077 | wxRect rect = CellToRect( row, col ); |
f85afd4e | 6078 | |
189d0213 | 6079 | // if the editor is shown, we should use it and not the renderer |
f6bcfd97 BP |
6080 | // Note: However, only if it is really _shown_, i.e. not hidden! |
6081 | if ( isCurrent && IsCellEditControlShown() ) | |
189d0213 | 6082 | { |
0b190b0f VZ |
6083 | wxGridCellEditor *editor = attr->GetEditor(this, row, col); |
6084 | editor->PaintBackground(rect, attr); | |
6085 | editor->DecRef(); | |
189d0213 VZ |
6086 | } |
6087 | else | |
6088 | { | |
6089 | // but all the rest is drawn by the cell renderer and hence may be | |
6090 | // customized | |
0b190b0f VZ |
6091 | wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col); |
6092 | renderer->Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords)); | |
6093 | renderer->DecRef(); | |
189d0213 | 6094 | } |
07296f0b | 6095 | |
283b7808 VZ |
6096 | attr->DecRef(); |
6097 | } | |
07296f0b | 6098 | |
283b7808 | 6099 | void wxGrid::DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ) |
07296f0b RD |
6100 | { |
6101 | int row = m_currentCellCoords.GetRow(); | |
6102 | int col = m_currentCellCoords.GetCol(); | |
6103 | ||
7c1cb261 | 6104 | if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) |
07296f0b RD |
6105 | return; |
6106 | ||
f6bcfd97 | 6107 | wxRect rect = CellToRect(row, col); |
07296f0b | 6108 | |
b3a7510d VZ |
6109 | // hmmm... what could we do here to show that the cell is disabled? |
6110 | // for now, I just draw a thinner border than for the other ones, but | |
6111 | // it doesn't look really good | |
b3a7510d | 6112 | |
d2520c85 RD |
6113 | int penWidth = attr->IsReadOnly() ? m_cellHighlightROPenWidth : m_cellHighlightPenWidth; |
6114 | ||
6115 | if (penWidth > 0) { | |
6116 | ||
6117 | // The center of th drawn line is where the position/width/height of | |
6118 | // the rectangle is actually at, (on wxMSW atr least,) so we will | |
6119 | // reduce the size of the rectangle to compensate for the thickness of | |
6120 | // the line. If this is too strange on non wxMSW platforms then | |
6121 | // please #ifdef this appropriately. | |
6122 | rect.x += penWidth/2; | |
6123 | rect.y += penWidth/2; | |
6124 | rect.width -= penWidth-1; | |
6125 | rect.height -= penWidth-1; | |
6126 | ||
6127 | ||
6128 | // Now draw the rectangle | |
6129 | dc.SetPen(wxPen(m_cellHighlightColour, penWidth, wxSOLID)); | |
6130 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
6131 | dc.DrawRectangle(rect); | |
6132 | } | |
07296f0b | 6133 | |
283b7808 | 6134 | #if 0 |
b3a7510d | 6135 | // VZ: my experiments with 3d borders... |
283b7808 | 6136 | |
b3a7510d | 6137 | // how to properly set colours for arbitrary bg? |
283b7808 VZ |
6138 | wxCoord x1 = rect.x, |
6139 | y1 = rect.y, | |
00cf1208 RR |
6140 | x2 = rect.x + rect.width -1, |
6141 | y2 = rect.y + rect.height -1; | |
283b7808 VZ |
6142 | |
6143 | dc.SetPen(*wxWHITE_PEN); | |
00cf1208 RR |
6144 | dc.DrawLine(x1, y1, x2, y1); |
6145 | dc.DrawLine(x1, y1, x1, y2); | |
283b7808 | 6146 | |
283b7808 | 6147 | dc.DrawLine(x1 + 1, y2 - 1, x2 - 1, y2 - 1); |
00cf1208 | 6148 | dc.DrawLine(x2 - 1, y1 + 1, x2 - 1, y2 ); |
283b7808 VZ |
6149 | |
6150 | dc.SetPen(*wxBLACK_PEN); | |
6151 | dc.DrawLine(x1, y2, x2, y2); | |
00cf1208 | 6152 | dc.DrawLine(x2, y1, x2, y2+1); |
b3a7510d | 6153 | #endif // 0 |
2d66e025 | 6154 | } |
f85afd4e | 6155 | |
f2d76237 | 6156 | |
2d66e025 MB |
6157 | void wxGrid::DrawCellBorder( wxDC& dc, const wxGridCellCoords& coords ) |
6158 | { | |
2d66e025 MB |
6159 | int row = coords.GetRow(); |
6160 | int col = coords.GetCol(); | |
7c1cb261 VZ |
6161 | if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) |
6162 | return; | |
6163 | ||
6164 | dc.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID) ); | |
60ff3b99 | 6165 | |
2d66e025 MB |
6166 | // right hand border |
6167 | // | |
7c1cb261 VZ |
6168 | dc.DrawLine( GetColRight(col), GetRowTop(row), |
6169 | GetColRight(col), GetRowBottom(row) ); | |
2d66e025 MB |
6170 | |
6171 | // bottom border | |
6172 | // | |
7c1cb261 VZ |
6173 | dc.DrawLine( GetColLeft(col), GetRowBottom(row), |
6174 | GetColRight(col), GetRowBottom(row) ); | |
f85afd4e MB |
6175 | } |
6176 | ||
d10f4bf9 | 6177 | void wxGrid::DrawHighlight(wxDC& dc,const wxGridCellCoordsArray& cells) |
b3a7510d | 6178 | { |
2a7750d9 MB |
6179 | // This if block was previously in wxGrid::OnPaint but that doesn't |
6180 | // seem to get called under wxGTK - MB | |
6181 | // | |
6182 | if ( m_currentCellCoords == wxGridNoCellCoords && | |
6183 | m_numRows && m_numCols ) | |
6184 | { | |
6185 | m_currentCellCoords.Set(0, 0); | |
6186 | } | |
6187 | ||
f6bcfd97 | 6188 | if ( IsCellEditControlShown() ) |
99306db2 VZ |
6189 | { |
6190 | // don't show highlight when the edit control is shown | |
6191 | return; | |
6192 | } | |
6193 | ||
b3a7510d VZ |
6194 | // if the active cell was repainted, repaint its highlight too because it |
6195 | // might have been damaged by the grid lines | |
d10f4bf9 | 6196 | size_t count = cells.GetCount(); |
b3a7510d VZ |
6197 | for ( size_t n = 0; n < count; n++ ) |
6198 | { | |
d10f4bf9 | 6199 | if ( cells[n] == m_currentCellCoords ) |
b3a7510d VZ |
6200 | { |
6201 | wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords); | |
6202 | DrawCellHighlight(dc, attr); | |
6203 | attr->DecRef(); | |
6204 | ||
6205 | break; | |
6206 | } | |
6207 | } | |
6208 | } | |
2d66e025 | 6209 | |
2d66e025 MB |
6210 | // TODO: remove this ??? |
6211 | // This is used to redraw all grid lines e.g. when the grid line colour | |
6212 | // has been changed | |
6213 | // | |
33ac7e6f | 6214 | void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) ) |
f85afd4e | 6215 | { |
60ff3b99 VZ |
6216 | if ( !m_gridLinesEnabled || |
6217 | !m_numRows || | |
2d66e025 | 6218 | !m_numCols ) return; |
f85afd4e | 6219 | |
2d66e025 | 6220 | int top, bottom, left, right; |
796df70a | 6221 | |
f6bcfd97 | 6222 | #if 0 //#ifndef __WXGTK__ |
508011ce VZ |
6223 | if (reg.IsEmpty()) |
6224 | { | |
796df70a SN |
6225 | int cw, ch; |
6226 | m_gridWin->GetClientSize(&cw, &ch); | |
6227 | ||
6228 | // virtual coords of visible area | |
6229 | // | |
6230 | CalcUnscrolledPosition( 0, 0, &left, &top ); | |
6231 | CalcUnscrolledPosition( cw, ch, &right, &bottom ); | |
6232 | } | |
508011ce VZ |
6233 | else |
6234 | { | |
796df70a SN |
6235 | wxCoord x, y, w, h; |
6236 | reg.GetBox(x, y, w, h); | |
6237 | CalcUnscrolledPosition( x, y, &left, &top ); | |
6238 | CalcUnscrolledPosition( x + w, y + h, &right, &bottom ); | |
6239 | } | |
8e217128 RR |
6240 | #else |
6241 | int cw, ch; | |
6242 | m_gridWin->GetClientSize(&cw, &ch); | |
6243 | CalcUnscrolledPosition( 0, 0, &left, &top ); | |
6244 | CalcUnscrolledPosition( cw, ch, &right, &bottom ); | |
6245 | #endif | |
f85afd4e | 6246 | |
9496deb5 MB |
6247 | // avoid drawing grid lines past the last row and col |
6248 | // | |
7c1cb261 VZ |
6249 | right = wxMin( right, GetColRight(m_numCols - 1) ); |
6250 | bottom = wxMin( bottom, GetRowBottom(m_numRows - 1) ); | |
9496deb5 | 6251 | |
2d66e025 | 6252 | dc.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID) ); |
f85afd4e | 6253 | |
2d66e025 | 6254 | // horizontal grid lines |
f85afd4e | 6255 | // |
60ff3b99 | 6256 | int i; |
9496deb5 | 6257 | for ( i = 0; i < m_numRows; i++ ) |
f85afd4e | 6258 | { |
6d55126d | 6259 | int bot = GetRowBottom(i) - 1; |
7c1cb261 | 6260 | |
6d55126d | 6261 | if ( bot > bottom ) |
2d66e025 MB |
6262 | { |
6263 | break; | |
6264 | } | |
7c1cb261 | 6265 | |
6d55126d | 6266 | if ( bot >= top ) |
2d66e025 | 6267 | { |
6d55126d | 6268 | dc.DrawLine( left, bot, right, bot ); |
2d66e025 | 6269 | } |
f85afd4e MB |
6270 | } |
6271 | ||
f85afd4e | 6272 | |
2d66e025 MB |
6273 | // vertical grid lines |
6274 | // | |
9496deb5 | 6275 | for ( i = 0; i < m_numCols; i++ ) |
f85afd4e | 6276 | { |
7c1cb261 VZ |
6277 | int colRight = GetColRight(i) - 1; |
6278 | if ( colRight > right ) | |
2d66e025 MB |
6279 | { |
6280 | break; | |
6281 | } | |
7c1cb261 VZ |
6282 | |
6283 | if ( colRight >= left ) | |
2d66e025 | 6284 | { |
7c1cb261 | 6285 | dc.DrawLine( colRight, top, colRight, bottom ); |
2d66e025 MB |
6286 | } |
6287 | } | |
6288 | } | |
f85afd4e | 6289 | |
8f177c8e | 6290 | |
d10f4bf9 | 6291 | void wxGrid::DrawRowLabels( wxDC& dc ,const wxArrayInt& rows) |
2d66e025 | 6292 | { |
f6bcfd97 | 6293 | if ( !m_numRows ) return; |
60ff3b99 | 6294 | |
2d66e025 | 6295 | size_t i; |
d10f4bf9 | 6296 | size_t numLabels = rows.GetCount(); |
60ff3b99 | 6297 | |
2d66e025 MB |
6298 | for ( i = 0; i < numLabels; i++ ) |
6299 | { | |
d10f4bf9 | 6300 | DrawRowLabel( dc, rows[i] ); |
60ff3b99 | 6301 | } |
f85afd4e MB |
6302 | } |
6303 | ||
6304 | ||
2d66e025 | 6305 | void wxGrid::DrawRowLabel( wxDC& dc, int row ) |
f85afd4e | 6306 | { |
7c1cb261 VZ |
6307 | if ( GetRowHeight(row) <= 0 ) |
6308 | return; | |
60ff3b99 | 6309 | |
7c1cb261 VZ |
6310 | int rowTop = GetRowTop(row), |
6311 | rowBottom = GetRowBottom(row) - 1; | |
b99be8fb | 6312 | |
2d66e025 | 6313 | dc.SetPen( *wxBLACK_PEN ); |
b0d6ff2f | 6314 | dc.DrawLine( m_rowLabelWidth-1, rowTop, |
7c1cb261 | 6315 | m_rowLabelWidth-1, rowBottom ); |
b99be8fb | 6316 | |
7c1cb261 | 6317 | dc.DrawLine( 0, rowBottom, m_rowLabelWidth-1, rowBottom ); |
b99be8fb | 6318 | |
2d66e025 | 6319 | dc.SetPen( *wxWHITE_PEN ); |
7c1cb261 | 6320 | dc.DrawLine( 0, rowTop, 0, rowBottom ); |
b0d6ff2f | 6321 | dc.DrawLine( 0, rowTop, m_rowLabelWidth-1, rowTop ); |
60ff3b99 | 6322 | |
f85afd4e | 6323 | dc.SetBackgroundMode( wxTRANSPARENT ); |
f85afd4e MB |
6324 | dc.SetTextForeground( GetLabelTextColour() ); |
6325 | dc.SetFont( GetLabelFont() ); | |
8f177c8e | 6326 | |
f85afd4e | 6327 | int hAlign, vAlign; |
2d66e025 | 6328 | GetRowLabelAlignment( &hAlign, &vAlign ); |
60ff3b99 | 6329 | |
2d66e025 MB |
6330 | wxRect rect; |
6331 | rect.SetX( 2 ); | |
7c1cb261 | 6332 | rect.SetY( GetRowTop(row) + 2 ); |
2d66e025 | 6333 | rect.SetWidth( m_rowLabelWidth - 4 ); |
7c1cb261 | 6334 | rect.SetHeight( GetRowHeight(row) - 4 ); |
60ff3b99 | 6335 | DrawTextRectangle( dc, GetRowLabelValue( row ), rect, hAlign, vAlign ); |
f85afd4e MB |
6336 | } |
6337 | ||
6338 | ||
d10f4bf9 | 6339 | void wxGrid::DrawColLabels( wxDC& dc,const wxArrayInt& cols ) |
f85afd4e | 6340 | { |
f6bcfd97 | 6341 | if ( !m_numCols ) return; |
60ff3b99 | 6342 | |
2d66e025 | 6343 | size_t i; |
d10f4bf9 | 6344 | size_t numLabels = cols.GetCount(); |
60ff3b99 | 6345 | |
2d66e025 | 6346 | for ( i = 0; i < numLabels; i++ ) |
f85afd4e | 6347 | { |
d10f4bf9 | 6348 | DrawColLabel( dc, cols[i] ); |
60ff3b99 | 6349 | } |
f85afd4e MB |
6350 | } |
6351 | ||
6352 | ||
2d66e025 | 6353 | void wxGrid::DrawColLabel( wxDC& dc, int col ) |
f85afd4e | 6354 | { |
7c1cb261 VZ |
6355 | if ( GetColWidth(col) <= 0 ) |
6356 | return; | |
60ff3b99 | 6357 | |
7c1cb261 VZ |
6358 | int colLeft = GetColLeft(col), |
6359 | colRight = GetColRight(col) - 1; | |
b99be8fb | 6360 | |
2d66e025 | 6361 | dc.SetPen( *wxBLACK_PEN ); |
7c1cb261 VZ |
6362 | dc.DrawLine( colRight, 0, |
6363 | colRight, m_colLabelHeight-1 ); | |
b99be8fb | 6364 | |
b0d6ff2f | 6365 | dc.DrawLine( colLeft, m_colLabelHeight-1, |
7c1cb261 | 6366 | colRight, m_colLabelHeight-1 ); |
b99be8fb | 6367 | |
f85afd4e | 6368 | dc.SetPen( *wxWHITE_PEN ); |
b0d6ff2f | 6369 | dc.DrawLine( colLeft, 0, colLeft, m_colLabelHeight-1 ); |
7c1cb261 | 6370 | dc.DrawLine( colLeft, 0, colRight, 0 ); |
f85afd4e | 6371 | |
b0d6ff2f MB |
6372 | dc.SetBackgroundMode( wxTRANSPARENT ); |
6373 | dc.SetTextForeground( GetLabelTextColour() ); | |
6374 | dc.SetFont( GetLabelFont() ); | |
8f177c8e | 6375 | |
f85afd4e | 6376 | dc.SetBackgroundMode( wxTRANSPARENT ); |
f85afd4e MB |
6377 | dc.SetTextForeground( GetLabelTextColour() ); |
6378 | dc.SetFont( GetLabelFont() ); | |
8f177c8e | 6379 | |
f85afd4e | 6380 | int hAlign, vAlign; |
2d66e025 | 6381 | GetColLabelAlignment( &hAlign, &vAlign ); |
60ff3b99 | 6382 | |
2d66e025 | 6383 | wxRect rect; |
7c1cb261 | 6384 | rect.SetX( colLeft + 2 ); |
2d66e025 | 6385 | rect.SetY( 2 ); |
7c1cb261 | 6386 | rect.SetWidth( GetColWidth(col) - 4 ); |
2d66e025 | 6387 | rect.SetHeight( m_colLabelHeight - 4 ); |
60ff3b99 | 6388 | DrawTextRectangle( dc, GetColLabelValue( col ), rect, hAlign, vAlign ); |
f85afd4e MB |
6389 | } |
6390 | ||
2d66e025 MB |
6391 | void wxGrid::DrawTextRectangle( wxDC& dc, |
6392 | const wxString& value, | |
6393 | const wxRect& rect, | |
6394 | int horizAlign, | |
6395 | int vertAlign ) | |
f85afd4e | 6396 | { |
2d66e025 | 6397 | wxArrayString lines; |
f85afd4e | 6398 | |
2d66e025 MB |
6399 | dc.SetClippingRegion( rect ); |
6400 | StringToLines( value, lines ); | |
d10f4bf9 VZ |
6401 | |
6402 | ||
6403 | //Forward to new API. | |
6404 | DrawTextRectangle( dc, | |
6405 | lines, | |
6406 | rect, | |
6407 | horizAlign, | |
6408 | vertAlign ); | |
6409 | ||
6410 | } | |
6411 | ||
6412 | void wxGrid::DrawTextRectangle( wxDC& dc, | |
6413 | const wxArrayString& lines, | |
6414 | const wxRect& rect, | |
6415 | int horizAlign, | |
6416 | int vertAlign ) | |
6417 | { | |
6418 | long textWidth, textHeight; | |
6419 | long lineWidth, lineHeight; | |
6420 | ||
2d66e025 MB |
6421 | if ( lines.GetCount() ) |
6422 | { | |
6423 | GetTextBoxSize( dc, lines, &textWidth, &textHeight ); | |
6424 | dc.GetTextExtent( lines[0], &lineWidth, &lineHeight ); | |
f85afd4e | 6425 | |
2d66e025 MB |
6426 | float x, y; |
6427 | switch ( horizAlign ) | |
6428 | { | |
4c7277db | 6429 | case wxALIGN_RIGHT: |
2d66e025 MB |
6430 | x = rect.x + (rect.width - textWidth - 1); |
6431 | break; | |
f85afd4e | 6432 | |
4c7277db | 6433 | case wxALIGN_CENTRE: |
2d66e025 MB |
6434 | x = rect.x + ((rect.width - textWidth)/2); |
6435 | break; | |
f85afd4e | 6436 | |
4c7277db | 6437 | case wxALIGN_LEFT: |
2d66e025 MB |
6438 | default: |
6439 | x = rect.x + 1; | |
6440 | break; | |
6441 | } | |
f85afd4e | 6442 | |
2d66e025 MB |
6443 | switch ( vertAlign ) |
6444 | { | |
4c7277db | 6445 | case wxALIGN_BOTTOM: |
2d66e025 MB |
6446 | y = rect.y + (rect.height - textHeight - 1); |
6447 | break; | |
f85afd4e | 6448 | |
4c7277db | 6449 | case wxALIGN_CENTRE: |
8f177c8e | 6450 | y = rect.y + ((rect.height - textHeight)/2); |
f85afd4e MB |
6451 | break; |
6452 | ||
4c7277db | 6453 | case wxALIGN_TOP: |
f85afd4e | 6454 | default: |
8f177c8e | 6455 | y = rect.y + 1; |
f85afd4e MB |
6456 | break; |
6457 | } | |
6458 | ||
b540eb2b | 6459 | for ( size_t i = 0; i < lines.GetCount(); i++ ) |
f85afd4e | 6460 | { |
4a64bee4 | 6461 | dc.DrawText( lines[i], (int)x, (int)y ); |
f85afd4e MB |
6462 | y += lineHeight; |
6463 | } | |
6464 | } | |
8f177c8e | 6465 | |
f85afd4e | 6466 | dc.DestroyClippingRegion(); |
f85afd4e MB |
6467 | } |
6468 | ||
6469 | ||
6470 | // Split multi line text up into an array of strings. Any existing | |
6471 | // contents of the string array are preserved. | |
6472 | // | |
6473 | void wxGrid::StringToLines( const wxString& value, wxArrayString& lines ) | |
6474 | { | |
f85afd4e MB |
6475 | int startPos = 0; |
6476 | int pos; | |
6d004f67 | 6477 | wxString eol = wxTextFile::GetEOL( wxTextFileType_Unix ); |
2433bb2e | 6478 | wxString tVal = wxTextFile::Translate( value, wxTextFileType_Unix ); |
e2b42eeb | 6479 | |
2433bb2e | 6480 | while ( startPos < (int)tVal.Length() ) |
f85afd4e | 6481 | { |
2433bb2e | 6482 | pos = tVal.Mid(startPos).Find( eol ); |
f85afd4e MB |
6483 | if ( pos < 0 ) |
6484 | { | |
6485 | break; | |
6486 | } | |
6487 | else if ( pos == 0 ) | |
6488 | { | |
6489 | lines.Add( wxEmptyString ); | |
6490 | } | |
6491 | else | |
6492 | { | |
2433bb2e | 6493 | lines.Add( value.Mid(startPos, pos) ); |
f85afd4e MB |
6494 | } |
6495 | startPos += pos+1; | |
6496 | } | |
b540eb2b | 6497 | if ( startPos < (int)value.Length() ) |
f85afd4e MB |
6498 | { |
6499 | lines.Add( value.Mid( startPos ) ); | |
6500 | } | |
6501 | } | |
6502 | ||
6503 | ||
6504 | void wxGrid::GetTextBoxSize( wxDC& dc, | |
d10f4bf9 | 6505 | const wxArrayString& lines, |
f85afd4e MB |
6506 | long *width, long *height ) |
6507 | { | |
6508 | long w = 0; | |
6509 | long h = 0; | |
6510 | long lineW, lineH; | |
6511 | ||
b540eb2b | 6512 | size_t i; |
f85afd4e MB |
6513 | for ( i = 0; i < lines.GetCount(); i++ ) |
6514 | { | |
6515 | dc.GetTextExtent( lines[i], &lineW, &lineH ); | |
6516 | w = wxMax( w, lineW ); | |
6517 | h += lineH; | |
6518 | } | |
6519 | ||
6520 | *width = w; | |
6521 | *height = h; | |
6522 | } | |
6523 | ||
f6bcfd97 BP |
6524 | // |
6525 | // ------ Batch processing. | |
6526 | // | |
6527 | void wxGrid::EndBatch() | |
6528 | { | |
6529 | if ( m_batchCount > 0 ) | |
6530 | { | |
6531 | m_batchCount--; | |
6532 | if ( !m_batchCount ) | |
6533 | { | |
6534 | CalcDimensions(); | |
6535 | m_rowLabelWin->Refresh(); | |
6536 | m_colLabelWin->Refresh(); | |
6537 | m_cornerLabelWin->Refresh(); | |
6538 | m_gridWin->Refresh(); | |
6539 | } | |
6540 | } | |
6541 | } | |
f85afd4e | 6542 | |
d8232393 MB |
6543 | // Use this, rather than wxWindow::Refresh(), to force an immediate |
6544 | // repainting of the grid. Has no effect if you are already inside a | |
6545 | // BeginBatch / EndBatch block. | |
6546 | // | |
6547 | void wxGrid::ForceRefresh() | |
6548 | { | |
6549 | BeginBatch(); | |
6550 | EndBatch(); | |
6551 | } | |
6552 | ||
6553 | ||
f85afd4e | 6554 | // |
2d66e025 | 6555 | // ------ Edit control functions |
f85afd4e MB |
6556 | // |
6557 | ||
2d66e025 MB |
6558 | |
6559 | void wxGrid::EnableEditing( bool edit ) | |
f85afd4e | 6560 | { |
2d66e025 MB |
6561 | // TODO: improve this ? |
6562 | // | |
6563 | if ( edit != m_editable ) | |
f85afd4e | 6564 | { |
632efa47 | 6565 | if(!edit) EnableCellEditControl(edit); |
2d66e025 | 6566 | m_editable = edit; |
f85afd4e | 6567 | } |
f85afd4e MB |
6568 | } |
6569 | ||
6570 | ||
2d66e025 | 6571 | void wxGrid::EnableCellEditControl( bool enable ) |
f85afd4e | 6572 | { |
2c9a89e0 RD |
6573 | if (! m_editable) |
6574 | return; | |
6575 | ||
dcfe4c3d SN |
6576 | if ( m_currentCellCoords == wxGridNoCellCoords ) |
6577 | SetCurrentCell( 0, 0 ); | |
60ff3b99 | 6578 | |
2c9a89e0 RD |
6579 | if ( enable != m_cellEditCtrlEnabled ) |
6580 | { | |
b54ba671 VZ |
6581 | // TODO allow the app to Veto() this event? |
6582 | SendEvent(enable ? wxEVT_GRID_EDITOR_SHOWN : wxEVT_GRID_EDITOR_HIDDEN); | |
6583 | ||
dcfe4c3d | 6584 | if ( enable ) |
f85afd4e | 6585 | { |
b54ba671 VZ |
6586 | // this should be checked by the caller! |
6587 | wxASSERT_MSG( CanEnableCellControl(), | |
6588 | _T("can't enable editing for this cell!") ); | |
6589 | ||
6590 | // do it before ShowCellEditControl() | |
dcfe4c3d | 6591 | m_cellEditCtrlEnabled = enable; |
b54ba671 | 6592 | |
2d66e025 | 6593 | ShowCellEditControl(); |
2d66e025 MB |
6594 | } |
6595 | else | |
6596 | { | |
2d66e025 MB |
6597 | HideCellEditControl(); |
6598 | SaveEditControlValue(); | |
b54ba671 VZ |
6599 | |
6600 | // do it after HideCellEditControl() | |
dcfe4c3d | 6601 | m_cellEditCtrlEnabled = enable; |
f85afd4e | 6602 | } |
f85afd4e | 6603 | } |
f85afd4e | 6604 | } |
f85afd4e | 6605 | |
b54ba671 | 6606 | bool wxGrid::IsCurrentCellReadOnly() const |
283b7808 | 6607 | { |
b54ba671 VZ |
6608 | // const_cast |
6609 | wxGridCellAttr* attr = ((wxGrid *)this)->GetCellAttr(m_currentCellCoords); | |
6610 | bool readonly = attr->IsReadOnly(); | |
6611 | attr->DecRef(); | |
283b7808 | 6612 | |
b54ba671 VZ |
6613 | return readonly; |
6614 | } | |
283b7808 | 6615 | |
b54ba671 VZ |
6616 | bool wxGrid::CanEnableCellControl() const |
6617 | { | |
6618 | return m_editable && !IsCurrentCellReadOnly(); | |
6619 | } | |
6620 | ||
6621 | bool wxGrid::IsCellEditControlEnabled() const | |
6622 | { | |
6623 | // the cell edit control might be disable for all cells or just for the | |
6624 | // current one if it's read only | |
6625 | return m_cellEditCtrlEnabled ? !IsCurrentCellReadOnly() : FALSE; | |
283b7808 VZ |
6626 | } |
6627 | ||
f6bcfd97 BP |
6628 | bool wxGrid::IsCellEditControlShown() const |
6629 | { | |
6630 | bool isShown = FALSE; | |
6631 | ||
6632 | if ( m_cellEditCtrlEnabled ) | |
6633 | { | |
6634 | int row = m_currentCellCoords.GetRow(); | |
6635 | int col = m_currentCellCoords.GetCol(); | |
6636 | wxGridCellAttr* attr = GetCellAttr(row, col); | |
6637 | wxGridCellEditor* editor = attr->GetEditor((wxGrid*) this, row, col); | |
6638 | attr->DecRef(); | |
6639 | ||
6640 | if ( editor ) | |
6641 | { | |
6642 | if ( editor->IsCreated() ) | |
6643 | { | |
6644 | isShown = editor->GetControl()->IsShown(); | |
6645 | } | |
6646 | ||
6647 | editor->DecRef(); | |
6648 | } | |
6649 | } | |
6650 | ||
6651 | return isShown; | |
6652 | } | |
6653 | ||
2d66e025 | 6654 | void wxGrid::ShowCellEditControl() |
f85afd4e | 6655 | { |
2d66e025 | 6656 | if ( IsCellEditControlEnabled() ) |
f85afd4e | 6657 | { |
2d66e025 MB |
6658 | if ( !IsVisible( m_currentCellCoords ) ) |
6659 | { | |
3ca6a5f0 | 6660 | m_cellEditCtrlEnabled = FALSE; |
2d66e025 MB |
6661 | return; |
6662 | } | |
6663 | else | |
6664 | { | |
2c9a89e0 RD |
6665 | wxRect rect = CellToRect( m_currentCellCoords ); |
6666 | int row = m_currentCellCoords.GetRow(); | |
6667 | int col = m_currentCellCoords.GetCol(); | |
2d66e025 MB |
6668 | |
6669 | // convert to scrolled coords | |
6670 | // | |
99306db2 | 6671 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); |
508011ce | 6672 | |
99306db2 VZ |
6673 | // done in PaintBackground() |
6674 | #if 0 | |
6675 | // erase the highlight and the cell contents because the editor | |
6676 | // might not cover the entire cell | |
6677 | wxClientDC dc( m_gridWin ); | |
6678 | PrepareDC( dc ); | |
6679 | dc.SetBrush(*wxLIGHT_GREY_BRUSH); //wxBrush(attr->GetBackgroundColour(), wxSOLID)); | |
6680 | dc.SetPen(*wxTRANSPARENT_PEN); | |
6681 | dc.DrawRectangle(rect); | |
6682 | #endif // 0 | |
d2fdd8d2 | 6683 | |
99306db2 VZ |
6684 | // cell is shifted by one pixel |
6685 | rect.x--; | |
6686 | rect.y--; | |
f0102d2a | 6687 | |
508011ce | 6688 | wxGridCellAttr* attr = GetCellAttr(row, col); |
28a77bc4 | 6689 | wxGridCellEditor* editor = attr->GetEditor(this, row, col); |
3da93aae VZ |
6690 | if ( !editor->IsCreated() ) |
6691 | { | |
2c9a89e0 RD |
6692 | editor->Create(m_gridWin, -1, |
6693 | new wxGridCellEditorEvtHandler(this, editor)); | |
bf7945ce RD |
6694 | |
6695 | wxGridEditorCreatedEvent evt(GetId(), | |
6696 | wxEVT_GRID_EDITOR_CREATED, | |
6697 | this, | |
6698 | row, | |
6699 | col, | |
6700 | editor->GetControl()); | |
6701 | GetEventHandler()->ProcessEvent(evt); | |
2d66e025 MB |
6702 | } |
6703 | ||
b0e282b3 | 6704 | editor->Show( TRUE, attr ); |
0b190b0f | 6705 | |
2c9a89e0 | 6706 | editor->SetSize( rect ); |
99306db2 | 6707 | |
3da93aae | 6708 | editor->BeginEdit(row, col, this); |
0b190b0f VZ |
6709 | |
6710 | editor->DecRef(); | |
2c9a89e0 RD |
6711 | attr->DecRef(); |
6712 | } | |
f85afd4e MB |
6713 | } |
6714 | } | |
6715 | ||
6716 | ||
2d66e025 | 6717 | void wxGrid::HideCellEditControl() |
f85afd4e | 6718 | { |
2d66e025 | 6719 | if ( IsCellEditControlEnabled() ) |
f85afd4e | 6720 | { |
2c9a89e0 RD |
6721 | int row = m_currentCellCoords.GetRow(); |
6722 | int col = m_currentCellCoords.GetCol(); | |
6723 | ||
3da93aae | 6724 | wxGridCellAttr* attr = GetCellAttr(row, col); |
0b190b0f VZ |
6725 | wxGridCellEditor *editor = attr->GetEditor(this, row, col); |
6726 | editor->Show( FALSE ); | |
6727 | editor->DecRef(); | |
2c9a89e0 RD |
6728 | attr->DecRef(); |
6729 | m_gridWin->SetFocus(); | |
f6bcfd97 BP |
6730 | wxRect rect( CellToRect( row, col ) ); |
6731 | m_gridWin->Refresh( FALSE, &rect ); | |
f85afd4e | 6732 | } |
2d66e025 | 6733 | } |
8f177c8e | 6734 | |
2d66e025 | 6735 | |
2d66e025 MB |
6736 | void wxGrid::SaveEditControlValue() |
6737 | { | |
3da93aae VZ |
6738 | if ( IsCellEditControlEnabled() ) |
6739 | { | |
2c9a89e0 RD |
6740 | int row = m_currentCellCoords.GetRow(); |
6741 | int col = m_currentCellCoords.GetCol(); | |
8f177c8e | 6742 | |
3da93aae | 6743 | wxGridCellAttr* attr = GetCellAttr(row, col); |
28a77bc4 | 6744 | wxGridCellEditor* editor = attr->GetEditor(this, row, col); |
3324d5f5 | 6745 | bool changed = editor->EndEdit(row, col, this); |
2d66e025 | 6746 | |
0b190b0f | 6747 | editor->DecRef(); |
2c9a89e0 | 6748 | attr->DecRef(); |
2d66e025 | 6749 | |
3da93aae VZ |
6750 | if (changed) |
6751 | { | |
b54ba671 | 6752 | SendEvent( wxEVT_GRID_CELL_CHANGE, |
2d66e025 MB |
6753 | m_currentCellCoords.GetRow(), |
6754 | m_currentCellCoords.GetCol() ); | |
6755 | } | |
f85afd4e MB |
6756 | } |
6757 | } | |
6758 | ||
2d66e025 MB |
6759 | |
6760 | // | |
60ff3b99 VZ |
6761 | // ------ Grid location functions |
6762 | // Note that all of these functions work with the logical coordinates of | |
2d66e025 MB |
6763 | // grid cells and labels so you will need to convert from device |
6764 | // coordinates for mouse events etc. | |
6765 | // | |
6766 | ||
6767 | void wxGrid::XYToCell( int x, int y, wxGridCellCoords& coords ) | |
f85afd4e | 6768 | { |
58dd5b3b MB |
6769 | int row = YToRow(y); |
6770 | int col = XToCol(x); | |
6771 | ||
6772 | if ( row == -1 || col == -1 ) | |
6773 | { | |
6774 | coords = wxGridNoCellCoords; | |
6775 | } | |
6776 | else | |
6777 | { | |
6778 | coords.Set( row, col ); | |
6779 | } | |
2d66e025 | 6780 | } |
f85afd4e | 6781 | |
8f177c8e | 6782 | |
2d66e025 MB |
6783 | int wxGrid::YToRow( int y ) |
6784 | { | |
6785 | int i; | |
8f177c8e | 6786 | |
2d66e025 | 6787 | for ( i = 0; i < m_numRows; i++ ) |
f85afd4e | 6788 | { |
7c1cb261 VZ |
6789 | if ( y < GetRowBottom(i) ) |
6790 | return i; | |
f85afd4e | 6791 | } |
2d66e025 | 6792 | |
4ee5fc9c | 6793 | return -1; |
f85afd4e MB |
6794 | } |
6795 | ||
2d66e025 MB |
6796 | |
6797 | int wxGrid::XToCol( int x ) | |
f85afd4e | 6798 | { |
2d66e025 | 6799 | int i; |
8f177c8e | 6800 | |
2d66e025 | 6801 | for ( i = 0; i < m_numCols; i++ ) |
f85afd4e | 6802 | { |
7c1cb261 VZ |
6803 | if ( x < GetColRight(i) ) |
6804 | return i; | |
f85afd4e MB |
6805 | } |
6806 | ||
4ee5fc9c | 6807 | return -1; |
2d66e025 | 6808 | } |
8f177c8e | 6809 | |
2d66e025 MB |
6810 | |
6811 | // return the row number that that the y coord is near the edge of, or | |
6812 | // -1 if not near an edge | |
6813 | // | |
6814 | int wxGrid::YToEdgeOfRow( int y ) | |
6815 | { | |
6816 | int i, d; | |
6817 | ||
6818 | for ( i = 0; i < m_numRows; i++ ) | |
6819 | { | |
7c1cb261 | 6820 | if ( GetRowHeight(i) > WXGRID_LABEL_EDGE_ZONE ) |
f85afd4e | 6821 | { |
7c1cb261 VZ |
6822 | d = abs( y - GetRowBottom(i) ); |
6823 | if ( d < WXGRID_LABEL_EDGE_ZONE ) | |
6824 | return i; | |
f85afd4e | 6825 | } |
f85afd4e | 6826 | } |
2d66e025 MB |
6827 | |
6828 | return -1; | |
6829 | } | |
6830 | ||
6831 | ||
6832 | // return the col number that that the x coord is near the edge of, or | |
6833 | // -1 if not near an edge | |
6834 | // | |
6835 | int wxGrid::XToEdgeOfCol( int x ) | |
6836 | { | |
6837 | int i, d; | |
6838 | ||
6839 | for ( i = 0; i < m_numCols; i++ ) | |
f85afd4e | 6840 | { |
7c1cb261 | 6841 | if ( GetColWidth(i) > WXGRID_LABEL_EDGE_ZONE ) |
2d66e025 | 6842 | { |
7c1cb261 VZ |
6843 | d = abs( x - GetColRight(i) ); |
6844 | if ( d < WXGRID_LABEL_EDGE_ZONE ) | |
6845 | return i; | |
2d66e025 | 6846 | } |
f85afd4e | 6847 | } |
2d66e025 MB |
6848 | |
6849 | return -1; | |
f85afd4e MB |
6850 | } |
6851 | ||
2d66e025 MB |
6852 | |
6853 | wxRect wxGrid::CellToRect( int row, int col ) | |
f85afd4e | 6854 | { |
2d66e025 | 6855 | wxRect rect( -1, -1, -1, -1 ); |
f85afd4e | 6856 | |
2d66e025 MB |
6857 | if ( row >= 0 && row < m_numRows && |
6858 | col >= 0 && col < m_numCols ) | |
f85afd4e | 6859 | { |
7c1cb261 VZ |
6860 | rect.x = GetColLeft(col); |
6861 | rect.y = GetRowTop(row); | |
6862 | rect.width = GetColWidth(col); | |
6863 | rect.height = GetRowHeight(row); | |
f85afd4e MB |
6864 | } |
6865 | ||
f6bcfd97 BP |
6866 | // if grid lines are enabled, then the area of the cell is a bit smaller |
6867 | if (m_gridLinesEnabled) { | |
6868 | rect.width -= 1; | |
6869 | rect.height -= 1; | |
6870 | } | |
2d66e025 MB |
6871 | return rect; |
6872 | } | |
6873 | ||
6874 | ||
6875 | bool wxGrid::IsVisible( int row, int col, bool wholeCellVisible ) | |
6876 | { | |
6877 | // get the cell rectangle in logical coords | |
6878 | // | |
6879 | wxRect r( CellToRect( row, col ) ); | |
60ff3b99 | 6880 | |
2d66e025 MB |
6881 | // convert to device coords |
6882 | // | |
6883 | int left, top, right, bottom; | |
6884 | CalcScrolledPosition( r.GetLeft(), r.GetTop(), &left, &top ); | |
6885 | CalcScrolledPosition( r.GetRight(), r.GetBottom(), &right, &bottom ); | |
60ff3b99 | 6886 | |
2d66e025 MB |
6887 | // check against the client area of the grid window |
6888 | // | |
6889 | int cw, ch; | |
6890 | m_gridWin->GetClientSize( &cw, &ch ); | |
60ff3b99 | 6891 | |
2d66e025 | 6892 | if ( wholeCellVisible ) |
f85afd4e | 6893 | { |
2d66e025 | 6894 | // is the cell wholly visible ? |
8f177c8e | 6895 | // |
2d66e025 MB |
6896 | return ( left >= 0 && right <= cw && |
6897 | top >= 0 && bottom <= ch ); | |
6898 | } | |
6899 | else | |
6900 | { | |
6901 | // is the cell partly visible ? | |
6902 | // | |
6903 | return ( ((left >=0 && left < cw) || (right > 0 && right <= cw)) && | |
6904 | ((top >=0 && top < ch) || (bottom > 0 && bottom <= ch)) ); | |
6905 | } | |
6906 | } | |
6907 | ||
6908 | ||
6909 | // make the specified cell location visible by doing a minimal amount | |
6910 | // of scrolling | |
6911 | // | |
6912 | void wxGrid::MakeCellVisible( int row, int col ) | |
6913 | { | |
275c4ae4 | 6914 | |
2d66e025 | 6915 | int i; |
60ff3b99 | 6916 | int xpos = -1, ypos = -1; |
2d66e025 MB |
6917 | |
6918 | if ( row >= 0 && row < m_numRows && | |
6919 | col >= 0 && col < m_numCols ) | |
6920 | { | |
6921 | // get the cell rectangle in logical coords | |
6922 | // | |
6923 | wxRect r( CellToRect( row, col ) ); | |
60ff3b99 | 6924 | |
2d66e025 MB |
6925 | // convert to device coords |
6926 | // | |
6927 | int left, top, right, bottom; | |
6928 | CalcScrolledPosition( r.GetLeft(), r.GetTop(), &left, &top ); | |
6929 | CalcScrolledPosition( r.GetRight(), r.GetBottom(), &right, &bottom ); | |
60ff3b99 | 6930 | |
2d66e025 MB |
6931 | int cw, ch; |
6932 | m_gridWin->GetClientSize( &cw, &ch ); | |
60ff3b99 | 6933 | |
2d66e025 | 6934 | if ( top < 0 ) |
3f296516 | 6935 | { |
2d66e025 | 6936 | ypos = r.GetTop(); |
3f296516 | 6937 | } |
2d66e025 MB |
6938 | else if ( bottom > ch ) |
6939 | { | |
6940 | int h = r.GetHeight(); | |
6941 | ypos = r.GetTop(); | |
6942 | for ( i = row-1; i >= 0; i-- ) | |
6943 | { | |
7c1cb261 VZ |
6944 | int rowHeight = GetRowHeight(i); |
6945 | if ( h + rowHeight > ch ) | |
6946 | break; | |
2d66e025 | 6947 | |
7c1cb261 VZ |
6948 | h += rowHeight; |
6949 | ypos -= rowHeight; | |
2d66e025 | 6950 | } |
f0102d2a VZ |
6951 | |
6952 | // we divide it later by GRID_SCROLL_LINE, make sure that we don't | |
6953 | // have rounding errors (this is important, because if we do, we | |
6954 | // might not scroll at all and some cells won't be redrawn) | |
275c4ae4 RD |
6955 | // |
6956 | // Sometimes GRID_SCROLL_LINE/2 is not enough, so just add a full | |
6957 | // scroll unit... | |
6958 | ypos += GRID_SCROLL_LINE; | |
2d66e025 MB |
6959 | } |
6960 | ||
6961 | if ( left < 0 ) | |
6962 | { | |
6963 | xpos = r.GetLeft(); | |
6964 | } | |
6965 | else if ( right > cw ) | |
6966 | { | |
6967 | int w = r.GetWidth(); | |
6968 | xpos = r.GetLeft(); | |
6969 | for ( i = col-1; i >= 0; i-- ) | |
6970 | { | |
7c1cb261 VZ |
6971 | int colWidth = GetColWidth(i); |
6972 | if ( w + colWidth > cw ) | |
6973 | break; | |
2d66e025 | 6974 | |
7c1cb261 VZ |
6975 | w += colWidth; |
6976 | xpos -= colWidth; | |
2d66e025 | 6977 | } |
f0102d2a VZ |
6978 | |
6979 | // see comment for ypos above | |
275c4ae4 | 6980 | xpos += GRID_SCROLL_LINE; |
2d66e025 MB |
6981 | } |
6982 | ||
6983 | if ( xpos != -1 || ypos != -1 ) | |
6984 | { | |
f0102d2a VZ |
6985 | if ( xpos != -1 ) xpos /= GRID_SCROLL_LINE; |
6986 | if ( ypos != -1 ) ypos /= GRID_SCROLL_LINE; | |
2d66e025 MB |
6987 | Scroll( xpos, ypos ); |
6988 | AdjustScrollbars(); | |
6989 | } | |
6990 | } | |
6991 | } | |
6992 | ||
6993 | ||
6994 | // | |
6995 | // ------ Grid cursor movement functions | |
6996 | // | |
6997 | ||
5c8fc7c1 | 6998 | bool wxGrid::MoveCursorUp( bool expandSelection ) |
2d66e025 MB |
6999 | { |
7000 | if ( m_currentCellCoords != wxGridNoCellCoords && | |
f6bcfd97 | 7001 | m_currentCellCoords.GetRow() >= 0 ) |
2d66e025 | 7002 | { |
f6bcfd97 | 7003 | if ( expandSelection) |
d95b0c2b SN |
7004 | { |
7005 | if ( m_selectingKeyboard == wxGridNoCellCoords ) | |
7006 | m_selectingKeyboard = m_currentCellCoords; | |
f6bcfd97 BP |
7007 | if ( m_selectingKeyboard.GetRow() > 0 ) |
7008 | { | |
7009 | m_selectingKeyboard.SetRow( m_selectingKeyboard.GetRow() - 1 ); | |
7010 | MakeCellVisible( m_selectingKeyboard.GetRow(), | |
7011 | m_selectingKeyboard.GetCol() ); | |
c9097836 | 7012 | HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); |
f6bcfd97 | 7013 | } |
d95b0c2b | 7014 | } |
f6bcfd97 | 7015 | else if ( m_currentCellCoords.GetRow() > 0 ) |
aa5e1f75 SN |
7016 | { |
7017 | ClearSelection(); | |
7018 | MakeCellVisible( m_currentCellCoords.GetRow() - 1, | |
7019 | m_currentCellCoords.GetCol() ); | |
d95b0c2b SN |
7020 | SetCurrentCell( m_currentCellCoords.GetRow() - 1, |
7021 | m_currentCellCoords.GetCol() ); | |
aa5e1f75 | 7022 | } |
f6bcfd97 BP |
7023 | else |
7024 | return FALSE; | |
8f177c8e | 7025 | return TRUE; |
f85afd4e | 7026 | } |
2d66e025 MB |
7027 | |
7028 | return FALSE; | |
7029 | } | |
7030 | ||
7031 | ||
5c8fc7c1 | 7032 | bool wxGrid::MoveCursorDown( bool expandSelection ) |
2d66e025 | 7033 | { |
2d66e025 | 7034 | if ( m_currentCellCoords != wxGridNoCellCoords && |
f6bcfd97 | 7035 | m_currentCellCoords.GetRow() < m_numRows ) |
f85afd4e | 7036 | { |
5c8fc7c1 | 7037 | if ( expandSelection ) |
d95b0c2b SN |
7038 | { |
7039 | if ( m_selectingKeyboard == wxGridNoCellCoords ) | |
7040 | m_selectingKeyboard = m_currentCellCoords; | |
f6bcfd97 BP |
7041 | if ( m_selectingKeyboard.GetRow() < m_numRows-1 ) |
7042 | { | |
7043 | m_selectingKeyboard.SetRow( m_selectingKeyboard.GetRow() + 1 ); | |
7044 | MakeCellVisible( m_selectingKeyboard.GetRow(), | |
7045 | m_selectingKeyboard.GetCol() ); | |
c9097836 | 7046 | HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); |
f6bcfd97 | 7047 | } |
d95b0c2b | 7048 | } |
f6bcfd97 | 7049 | else if ( m_currentCellCoords.GetRow() < m_numRows - 1 ) |
aa5e1f75 SN |
7050 | { |
7051 | ClearSelection(); | |
7052 | MakeCellVisible( m_currentCellCoords.GetRow() + 1, | |
7053 | m_currentCellCoords.GetCol() ); | |
d95b0c2b SN |
7054 | SetCurrentCell( m_currentCellCoords.GetRow() + 1, |
7055 | m_currentCellCoords.GetCol() ); | |
aa5e1f75 | 7056 | } |
f6bcfd97 BP |
7057 | else |
7058 | return FALSE; | |
2d66e025 | 7059 | return TRUE; |
f85afd4e | 7060 | } |
2d66e025 MB |
7061 | |
7062 | return FALSE; | |
f85afd4e MB |
7063 | } |
7064 | ||
2d66e025 | 7065 | |
5c8fc7c1 | 7066 | bool wxGrid::MoveCursorLeft( bool expandSelection ) |
f85afd4e | 7067 | { |
2d66e025 | 7068 | if ( m_currentCellCoords != wxGridNoCellCoords && |
f6bcfd97 | 7069 | m_currentCellCoords.GetCol() >= 0 ) |
2d66e025 | 7070 | { |
5c8fc7c1 | 7071 | if ( expandSelection ) |
d95b0c2b SN |
7072 | { |
7073 | if ( m_selectingKeyboard == wxGridNoCellCoords ) | |
7074 | m_selectingKeyboard = m_currentCellCoords; | |
f6bcfd97 BP |
7075 | if ( m_selectingKeyboard.GetCol() > 0 ) |
7076 | { | |
7077 | m_selectingKeyboard.SetCol( m_selectingKeyboard.GetCol() - 1 ); | |
7078 | MakeCellVisible( m_selectingKeyboard.GetRow(), | |
7079 | m_selectingKeyboard.GetCol() ); | |
c9097836 | 7080 | HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); |
f6bcfd97 | 7081 | } |
d95b0c2b | 7082 | } |
f6bcfd97 | 7083 | else if ( m_currentCellCoords.GetCol() > 0 ) |
aa5e1f75 SN |
7084 | { |
7085 | ClearSelection(); | |
7086 | MakeCellVisible( m_currentCellCoords.GetRow(), | |
7087 | m_currentCellCoords.GetCol() - 1 ); | |
d95b0c2b SN |
7088 | SetCurrentCell( m_currentCellCoords.GetRow(), |
7089 | m_currentCellCoords.GetCol() - 1 ); | |
aa5e1f75 | 7090 | } |
f6bcfd97 BP |
7091 | else |
7092 | return FALSE; | |
2d66e025 MB |
7093 | return TRUE; |
7094 | } | |
7095 | ||
7096 | return FALSE; | |
7097 | } | |
7098 | ||
7099 | ||
5c8fc7c1 | 7100 | bool wxGrid::MoveCursorRight( bool expandSelection ) |
2d66e025 MB |
7101 | { |
7102 | if ( m_currentCellCoords != wxGridNoCellCoords && | |
f6bcfd97 | 7103 | m_currentCellCoords.GetCol() < m_numCols ) |
f85afd4e | 7104 | { |
5c8fc7c1 | 7105 | if ( expandSelection ) |
d95b0c2b SN |
7106 | { |
7107 | if ( m_selectingKeyboard == wxGridNoCellCoords ) | |
7108 | m_selectingKeyboard = m_currentCellCoords; | |
f6bcfd97 BP |
7109 | if ( m_selectingKeyboard.GetCol() < m_numCols - 1 ) |
7110 | { | |
7111 | m_selectingKeyboard.SetCol( m_selectingKeyboard.GetCol() + 1 ); | |
7112 | MakeCellVisible( m_selectingKeyboard.GetRow(), | |
7113 | m_selectingKeyboard.GetCol() ); | |
c9097836 | 7114 | HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); |
f6bcfd97 | 7115 | } |
d95b0c2b | 7116 | } |
f6bcfd97 | 7117 | else if ( m_currentCellCoords.GetCol() < m_numCols - 1 ) |
aa5e1f75 SN |
7118 | { |
7119 | ClearSelection(); | |
7120 | MakeCellVisible( m_currentCellCoords.GetRow(), | |
7121 | m_currentCellCoords.GetCol() + 1 ); | |
7122 | SetCurrentCell( m_currentCellCoords.GetRow(), | |
d95b0c2b | 7123 | m_currentCellCoords.GetCol() + 1 ); |
aa5e1f75 | 7124 | } |
f6bcfd97 BP |
7125 | else |
7126 | return FALSE; | |
2d66e025 | 7127 | return TRUE; |
f85afd4e | 7128 | } |
8f177c8e | 7129 | |
2d66e025 MB |
7130 | return FALSE; |
7131 | } | |
7132 | ||
7133 | ||
7134 | bool wxGrid::MovePageUp() | |
7135 | { | |
7136 | if ( m_currentCellCoords == wxGridNoCellCoords ) return FALSE; | |
60ff3b99 | 7137 | |
2d66e025 MB |
7138 | int row = m_currentCellCoords.GetRow(); |
7139 | if ( row > 0 ) | |
f85afd4e | 7140 | { |
2d66e025 MB |
7141 | int cw, ch; |
7142 | m_gridWin->GetClientSize( &cw, &ch ); | |
60ff3b99 | 7143 | |
7c1cb261 | 7144 | int y = GetRowTop(row); |
2d66e025 MB |
7145 | int newRow = YToRow( y - ch + 1 ); |
7146 | if ( newRow == -1 ) | |
7147 | { | |
7148 | newRow = 0; | |
7149 | } | |
60ff3b99 | 7150 | else if ( newRow == row ) |
2d66e025 MB |
7151 | { |
7152 | newRow = row - 1; | |
7153 | } | |
8f177c8e | 7154 | |
2d66e025 MB |
7155 | MakeCellVisible( newRow, m_currentCellCoords.GetCol() ); |
7156 | SetCurrentCell( newRow, m_currentCellCoords.GetCol() ); | |
60ff3b99 | 7157 | |
f85afd4e MB |
7158 | return TRUE; |
7159 | } | |
2d66e025 MB |
7160 | |
7161 | return FALSE; | |
7162 | } | |
7163 | ||
7164 | bool wxGrid::MovePageDown() | |
7165 | { | |
7166 | if ( m_currentCellCoords == wxGridNoCellCoords ) return FALSE; | |
60ff3b99 | 7167 | |
2d66e025 MB |
7168 | int row = m_currentCellCoords.GetRow(); |
7169 | if ( row < m_numRows ) | |
f85afd4e | 7170 | { |
2d66e025 MB |
7171 | int cw, ch; |
7172 | m_gridWin->GetClientSize( &cw, &ch ); | |
60ff3b99 | 7173 | |
7c1cb261 | 7174 | int y = GetRowTop(row); |
2d66e025 MB |
7175 | int newRow = YToRow( y + ch ); |
7176 | if ( newRow == -1 ) | |
7177 | { | |
7178 | newRow = m_numRows - 1; | |
7179 | } | |
60ff3b99 | 7180 | else if ( newRow == row ) |
2d66e025 MB |
7181 | { |
7182 | newRow = row + 1; | |
7183 | } | |
7184 | ||
7185 | MakeCellVisible( newRow, m_currentCellCoords.GetCol() ); | |
7186 | SetCurrentCell( newRow, m_currentCellCoords.GetCol() ); | |
60ff3b99 | 7187 | |
2d66e025 | 7188 | return TRUE; |
f85afd4e | 7189 | } |
2d66e025 MB |
7190 | |
7191 | return FALSE; | |
f85afd4e | 7192 | } |
8f177c8e | 7193 | |
5c8fc7c1 | 7194 | bool wxGrid::MoveCursorUpBlock( bool expandSelection ) |
2d66e025 MB |
7195 | { |
7196 | if ( m_table && | |
7197 | m_currentCellCoords != wxGridNoCellCoords && | |
7198 | m_currentCellCoords.GetRow() > 0 ) | |
7199 | { | |
7200 | int row = m_currentCellCoords.GetRow(); | |
7201 | int col = m_currentCellCoords.GetCol(); | |
7202 | ||
7203 | if ( m_table->IsEmptyCell(row, col) ) | |
7204 | { | |
7205 | // starting in an empty cell: find the next block of | |
7206 | // non-empty cells | |
7207 | // | |
7208 | while ( row > 0 ) | |
7209 | { | |
7210 | row-- ; | |
7211 | if ( !(m_table->IsEmptyCell(row, col)) ) break; | |
7212 | } | |
7213 | } | |
7214 | else if ( m_table->IsEmptyCell(row-1, col) ) | |
7215 | { | |
7216 | // starting at the top of a block: find the next block | |
7217 | // | |
7218 | row--; | |
7219 | while ( row > 0 ) | |
7220 | { | |
7221 | row-- ; | |
7222 | if ( !(m_table->IsEmptyCell(row, col)) ) break; | |
7223 | } | |
7224 | } | |
7225 | else | |
7226 | { | |
7227 | // starting within a block: find the top of the block | |
7228 | // | |
7229 | while ( row > 0 ) | |
7230 | { | |
7231 | row-- ; | |
7232 | if ( m_table->IsEmptyCell(row, col) ) | |
7233 | { | |
7234 | row++ ; | |
7235 | break; | |
7236 | } | |
7237 | } | |
7238 | } | |
f85afd4e | 7239 | |
2d66e025 | 7240 | MakeCellVisible( row, col ); |
5c8fc7c1 | 7241 | if ( expandSelection ) |
d95b0c2b SN |
7242 | { |
7243 | m_selectingKeyboard = wxGridCellCoords( row, col ); | |
c9097836 | 7244 | HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); |
d95b0c2b SN |
7245 | } |
7246 | else | |
aa5e1f75 SN |
7247 | { |
7248 | ClearSelection(); | |
7249 | SetCurrentCell( row, col ); | |
7250 | } | |
2d66e025 MB |
7251 | return TRUE; |
7252 | } | |
f85afd4e | 7253 | |
2d66e025 MB |
7254 | return FALSE; |
7255 | } | |
f85afd4e | 7256 | |
5c8fc7c1 | 7257 | bool wxGrid::MoveCursorDownBlock( bool expandSelection ) |
f85afd4e | 7258 | { |
2d66e025 MB |
7259 | if ( m_table && |
7260 | m_currentCellCoords != wxGridNoCellCoords && | |
7261 | m_currentCellCoords.GetRow() < m_numRows-1 ) | |
f85afd4e | 7262 | { |
2d66e025 MB |
7263 | int row = m_currentCellCoords.GetRow(); |
7264 | int col = m_currentCellCoords.GetCol(); | |
7265 | ||
7266 | if ( m_table->IsEmptyCell(row, col) ) | |
7267 | { | |
7268 | // starting in an empty cell: find the next block of | |
7269 | // non-empty cells | |
7270 | // | |
7271 | while ( row < m_numRows-1 ) | |
7272 | { | |
7273 | row++ ; | |
7274 | if ( !(m_table->IsEmptyCell(row, col)) ) break; | |
7275 | } | |
7276 | } | |
7277 | else if ( m_table->IsEmptyCell(row+1, col) ) | |
7278 | { | |
7279 | // starting at the bottom of a block: find the next block | |
7280 | // | |
7281 | row++; | |
7282 | while ( row < m_numRows-1 ) | |
7283 | { | |
7284 | row++ ; | |
7285 | if ( !(m_table->IsEmptyCell(row, col)) ) break; | |
7286 | } | |
7287 | } | |
7288 | else | |
7289 | { | |
7290 | // starting within a block: find the bottom of the block | |
7291 | // | |
7292 | while ( row < m_numRows-1 ) | |
7293 | { | |
7294 | row++ ; | |
7295 | if ( m_table->IsEmptyCell(row, col) ) | |
7296 | { | |
7297 | row-- ; | |
7298 | break; | |
7299 | } | |
7300 | } | |
7301 | } | |
7302 | ||
7303 | MakeCellVisible( row, col ); | |
5c8fc7c1 | 7304 | if ( expandSelection ) |
d95b0c2b SN |
7305 | { |
7306 | m_selectingKeyboard = wxGridCellCoords( row, col ); | |
c9097836 | 7307 | HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); |
d95b0c2b SN |
7308 | } |
7309 | else | |
aa5e1f75 SN |
7310 | { |
7311 | ClearSelection(); | |
7312 | SetCurrentCell( row, col ); | |
7313 | } | |
2d66e025 MB |
7314 | |
7315 | return TRUE; | |
f85afd4e | 7316 | } |
f85afd4e | 7317 | |
2d66e025 MB |
7318 | return FALSE; |
7319 | } | |
f85afd4e | 7320 | |
5c8fc7c1 | 7321 | bool wxGrid::MoveCursorLeftBlock( bool expandSelection ) |
f85afd4e | 7322 | { |
2d66e025 MB |
7323 | if ( m_table && |
7324 | m_currentCellCoords != wxGridNoCellCoords && | |
7325 | m_currentCellCoords.GetCol() > 0 ) | |
f85afd4e | 7326 | { |
2d66e025 MB |
7327 | int row = m_currentCellCoords.GetRow(); |
7328 | int col = m_currentCellCoords.GetCol(); | |
7329 | ||
7330 | if ( m_table->IsEmptyCell(row, col) ) | |
7331 | { | |
7332 | // starting in an empty cell: find the next block of | |
7333 | // non-empty cells | |
7334 | // | |
7335 | while ( col > 0 ) | |
7336 | { | |
7337 | col-- ; | |
7338 | if ( !(m_table->IsEmptyCell(row, col)) ) break; | |
7339 | } | |
7340 | } | |
7341 | else if ( m_table->IsEmptyCell(row, col-1) ) | |
7342 | { | |
7343 | // starting at the left of a block: find the next block | |
7344 | // | |
7345 | col--; | |
7346 | while ( col > 0 ) | |
7347 | { | |
7348 | col-- ; | |
7349 | if ( !(m_table->IsEmptyCell(row, col)) ) break; | |
7350 | } | |
7351 | } | |
7352 | else | |
7353 | { | |
7354 | // starting within a block: find the left of the block | |
7355 | // | |
7356 | while ( col > 0 ) | |
7357 | { | |
7358 | col-- ; | |
7359 | if ( m_table->IsEmptyCell(row, col) ) | |
7360 | { | |
7361 | col++ ; | |
7362 | break; | |
7363 | } | |
7364 | } | |
7365 | } | |
f85afd4e | 7366 | |
2d66e025 | 7367 | MakeCellVisible( row, col ); |
5c8fc7c1 | 7368 | if ( expandSelection ) |
d95b0c2b SN |
7369 | { |
7370 | m_selectingKeyboard = wxGridCellCoords( row, col ); | |
c9097836 | 7371 | HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); |
d95b0c2b SN |
7372 | } |
7373 | else | |
aa5e1f75 SN |
7374 | { |
7375 | ClearSelection(); | |
7376 | SetCurrentCell( row, col ); | |
7377 | } | |
8f177c8e | 7378 | |
2d66e025 | 7379 | return TRUE; |
f85afd4e | 7380 | } |
2d66e025 MB |
7381 | |
7382 | return FALSE; | |
f85afd4e MB |
7383 | } |
7384 | ||
5c8fc7c1 | 7385 | bool wxGrid::MoveCursorRightBlock( bool expandSelection ) |
f85afd4e | 7386 | { |
2d66e025 MB |
7387 | if ( m_table && |
7388 | m_currentCellCoords != wxGridNoCellCoords && | |
7389 | m_currentCellCoords.GetCol() < m_numCols-1 ) | |
f85afd4e | 7390 | { |
2d66e025 MB |
7391 | int row = m_currentCellCoords.GetRow(); |
7392 | int col = m_currentCellCoords.GetCol(); | |
8f177c8e | 7393 | |
2d66e025 MB |
7394 | if ( m_table->IsEmptyCell(row, col) ) |
7395 | { | |
7396 | // starting in an empty cell: find the next block of | |
7397 | // non-empty cells | |
7398 | // | |
7399 | while ( col < m_numCols-1 ) | |
7400 | { | |
7401 | col++ ; | |
7402 | if ( !(m_table->IsEmptyCell(row, col)) ) break; | |
7403 | } | |
7404 | } | |
7405 | else if ( m_table->IsEmptyCell(row, col+1) ) | |
7406 | { | |
7407 | // starting at the right of a block: find the next block | |
7408 | // | |
7409 | col++; | |
7410 | while ( col < m_numCols-1 ) | |
7411 | { | |
7412 | col++ ; | |
7413 | if ( !(m_table->IsEmptyCell(row, col)) ) break; | |
7414 | } | |
7415 | } | |
7416 | else | |
7417 | { | |
7418 | // starting within a block: find the right of the block | |
7419 | // | |
7420 | while ( col < m_numCols-1 ) | |
7421 | { | |
7422 | col++ ; | |
7423 | if ( m_table->IsEmptyCell(row, col) ) | |
7424 | { | |
7425 | col-- ; | |
7426 | break; | |
7427 | } | |
7428 | } | |
7429 | } | |
8f177c8e | 7430 | |
2d66e025 | 7431 | MakeCellVisible( row, col ); |
5c8fc7c1 | 7432 | if ( expandSelection ) |
d95b0c2b SN |
7433 | { |
7434 | m_selectingKeyboard = wxGridCellCoords( row, col ); | |
c9097836 | 7435 | HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); |
d95b0c2b SN |
7436 | } |
7437 | else | |
aa5e1f75 SN |
7438 | { |
7439 | ClearSelection(); | |
7440 | SetCurrentCell( row, col ); | |
7441 | } | |
f85afd4e | 7442 | |
2d66e025 | 7443 | return TRUE; |
f85afd4e | 7444 | } |
2d66e025 MB |
7445 | |
7446 | return FALSE; | |
f85afd4e MB |
7447 | } |
7448 | ||
7449 | ||
2d66e025 | 7450 | |
f85afd4e | 7451 | // |
2d66e025 | 7452 | // ------ Label values and formatting |
f85afd4e MB |
7453 | // |
7454 | ||
7455 | void wxGrid::GetRowLabelAlignment( int *horiz, int *vert ) | |
7456 | { | |
7457 | *horiz = m_rowLabelHorizAlign; | |
7458 | *vert = m_rowLabelVertAlign; | |
7459 | } | |
7460 | ||
7461 | void wxGrid::GetColLabelAlignment( int *horiz, int *vert ) | |
7462 | { | |
7463 | *horiz = m_colLabelHorizAlign; | |
7464 | *vert = m_colLabelVertAlign; | |
7465 | } | |
7466 | ||
7467 | wxString wxGrid::GetRowLabelValue( int row ) | |
7468 | { | |
7469 | if ( m_table ) | |
7470 | { | |
7471 | return m_table->GetRowLabelValue( row ); | |
7472 | } | |
7473 | else | |
7474 | { | |
7475 | wxString s; | |
7476 | s << row; | |
7477 | return s; | |
7478 | } | |
7479 | } | |
7480 | ||
7481 | wxString wxGrid::GetColLabelValue( int col ) | |
7482 | { | |
7483 | if ( m_table ) | |
7484 | { | |
7485 | return m_table->GetColLabelValue( col ); | |
7486 | } | |
7487 | else | |
7488 | { | |
7489 | wxString s; | |
7490 | s << col; | |
7491 | return s; | |
7492 | } | |
7493 | } | |
7494 | ||
2e8cd977 | 7495 | |
f85afd4e MB |
7496 | void wxGrid::SetRowLabelSize( int width ) |
7497 | { | |
2e8cd977 MB |
7498 | width = wxMax( width, 0 ); |
7499 | if ( width != m_rowLabelWidth ) | |
7500 | { | |
2e8cd977 MB |
7501 | if ( width == 0 ) |
7502 | { | |
7503 | m_rowLabelWin->Show( FALSE ); | |
7807d81c | 7504 | m_cornerLabelWin->Show( FALSE ); |
2e8cd977 | 7505 | } |
7807d81c | 7506 | else if ( m_rowLabelWidth == 0 ) |
2e8cd977 | 7507 | { |
7807d81c MB |
7508 | m_rowLabelWin->Show( TRUE ); |
7509 | if ( m_colLabelHeight > 0 ) m_cornerLabelWin->Show( TRUE ); | |
2e8cd977 | 7510 | } |
b99be8fb | 7511 | |
2e8cd977 | 7512 | m_rowLabelWidth = width; |
7807d81c MB |
7513 | CalcWindowSizes(); |
7514 | Refresh( TRUE ); | |
2e8cd977 | 7515 | } |
f85afd4e MB |
7516 | } |
7517 | ||
2e8cd977 | 7518 | |
f85afd4e MB |
7519 | void wxGrid::SetColLabelSize( int height ) |
7520 | { | |
7807d81c | 7521 | height = wxMax( height, 0 ); |
2e8cd977 MB |
7522 | if ( height != m_colLabelHeight ) |
7523 | { | |
2e8cd977 MB |
7524 | if ( height == 0 ) |
7525 | { | |
2e8cd977 | 7526 | m_colLabelWin->Show( FALSE ); |
7807d81c | 7527 | m_cornerLabelWin->Show( FALSE ); |
2e8cd977 | 7528 | } |
7807d81c | 7529 | else if ( m_colLabelHeight == 0 ) |
2e8cd977 | 7530 | { |
7807d81c MB |
7531 | m_colLabelWin->Show( TRUE ); |
7532 | if ( m_rowLabelWidth > 0 ) m_cornerLabelWin->Show( TRUE ); | |
2e8cd977 | 7533 | } |
7807d81c | 7534 | |
2e8cd977 | 7535 | m_colLabelHeight = height; |
7807d81c MB |
7536 | CalcWindowSizes(); |
7537 | Refresh( TRUE ); | |
2e8cd977 | 7538 | } |
f85afd4e MB |
7539 | } |
7540 | ||
2e8cd977 | 7541 | |
f85afd4e MB |
7542 | void wxGrid::SetLabelBackgroundColour( const wxColour& colour ) |
7543 | { | |
2d66e025 MB |
7544 | if ( m_labelBackgroundColour != colour ) |
7545 | { | |
7546 | m_labelBackgroundColour = colour; | |
7547 | m_rowLabelWin->SetBackgroundColour( colour ); | |
7548 | m_colLabelWin->SetBackgroundColour( colour ); | |
7549 | m_cornerLabelWin->SetBackgroundColour( colour ); | |
7550 | ||
7551 | if ( !GetBatchCount() ) | |
7552 | { | |
7553 | m_rowLabelWin->Refresh(); | |
7554 | m_colLabelWin->Refresh(); | |
7555 | m_cornerLabelWin->Refresh(); | |
7556 | } | |
7557 | } | |
f85afd4e MB |
7558 | } |
7559 | ||
7560 | void wxGrid::SetLabelTextColour( const wxColour& colour ) | |
7561 | { | |
2d66e025 MB |
7562 | if ( m_labelTextColour != colour ) |
7563 | { | |
7564 | m_labelTextColour = colour; | |
7565 | if ( !GetBatchCount() ) | |
7566 | { | |
7567 | m_rowLabelWin->Refresh(); | |
7568 | m_colLabelWin->Refresh(); | |
7569 | } | |
7570 | } | |
f85afd4e MB |
7571 | } |
7572 | ||
7573 | void wxGrid::SetLabelFont( const wxFont& font ) | |
7574 | { | |
7575 | m_labelFont = font; | |
2d66e025 MB |
7576 | if ( !GetBatchCount() ) |
7577 | { | |
7578 | m_rowLabelWin->Refresh(); | |
7579 | m_colLabelWin->Refresh(); | |
7580 | } | |
f85afd4e MB |
7581 | } |
7582 | ||
7583 | void wxGrid::SetRowLabelAlignment( int horiz, int vert ) | |
7584 | { | |
4c7277db MB |
7585 | // allow old (incorrect) defs to be used |
7586 | switch ( horiz ) | |
7587 | { | |
7588 | case wxLEFT: horiz = wxALIGN_LEFT; break; | |
7589 | case wxRIGHT: horiz = wxALIGN_RIGHT; break; | |
7590 | case wxCENTRE: horiz = wxALIGN_CENTRE; break; | |
7591 | } | |
84912ef8 | 7592 | |
4c7277db MB |
7593 | switch ( vert ) |
7594 | { | |
7595 | case wxTOP: vert = wxALIGN_TOP; break; | |
7596 | case wxBOTTOM: vert = wxALIGN_BOTTOM; break; | |
7597 | case wxCENTRE: vert = wxALIGN_CENTRE; break; | |
7598 | } | |
84912ef8 | 7599 | |
4c7277db | 7600 | if ( horiz == wxALIGN_LEFT || horiz == wxALIGN_CENTRE || horiz == wxALIGN_RIGHT ) |
f85afd4e MB |
7601 | { |
7602 | m_rowLabelHorizAlign = horiz; | |
7603 | } | |
8f177c8e | 7604 | |
4c7277db | 7605 | if ( vert == wxALIGN_TOP || vert == wxALIGN_CENTRE || vert == wxALIGN_BOTTOM ) |
f85afd4e MB |
7606 | { |
7607 | m_rowLabelVertAlign = vert; | |
7608 | } | |
7609 | ||
2d66e025 MB |
7610 | if ( !GetBatchCount() ) |
7611 | { | |
7612 | m_rowLabelWin->Refresh(); | |
60ff3b99 | 7613 | } |
f85afd4e MB |
7614 | } |
7615 | ||
7616 | void wxGrid::SetColLabelAlignment( int horiz, int vert ) | |
7617 | { | |
4c7277db MB |
7618 | // allow old (incorrect) defs to be used |
7619 | switch ( horiz ) | |
7620 | { | |
7621 | case wxLEFT: horiz = wxALIGN_LEFT; break; | |
7622 | case wxRIGHT: horiz = wxALIGN_RIGHT; break; | |
7623 | case wxCENTRE: horiz = wxALIGN_CENTRE; break; | |
7624 | } | |
84912ef8 | 7625 | |
4c7277db MB |
7626 | switch ( vert ) |
7627 | { | |
7628 | case wxTOP: vert = wxALIGN_TOP; break; | |
7629 | case wxBOTTOM: vert = wxALIGN_BOTTOM; break; | |
7630 | case wxCENTRE: vert = wxALIGN_CENTRE; break; | |
7631 | } | |
84912ef8 | 7632 | |
4c7277db | 7633 | if ( horiz == wxALIGN_LEFT || horiz == wxALIGN_CENTRE || horiz == wxALIGN_RIGHT ) |
f85afd4e MB |
7634 | { |
7635 | m_colLabelHorizAlign = horiz; | |
7636 | } | |
8f177c8e | 7637 | |
4c7277db | 7638 | if ( vert == wxALIGN_TOP || vert == wxALIGN_CENTRE || vert == wxALIGN_BOTTOM ) |
f85afd4e MB |
7639 | { |
7640 | m_colLabelVertAlign = vert; | |
7641 | } | |
7642 | ||
2d66e025 MB |
7643 | if ( !GetBatchCount() ) |
7644 | { | |
2d66e025 | 7645 | m_colLabelWin->Refresh(); |
60ff3b99 | 7646 | } |
f85afd4e MB |
7647 | } |
7648 | ||
7649 | void wxGrid::SetRowLabelValue( int row, const wxString& s ) | |
7650 | { | |
7651 | if ( m_table ) | |
7652 | { | |
7653 | m_table->SetRowLabelValue( row, s ); | |
2d66e025 MB |
7654 | if ( !GetBatchCount() ) |
7655 | { | |
70c7a608 SN |
7656 | wxRect rect = CellToRect( row, 0); |
7657 | if ( rect.height > 0 ) | |
7658 | { | |
cb309039 | 7659 | CalcScrolledPosition(0, rect.y, &rect.x, &rect.y); |
b1944ebc | 7660 | rect.x = 0; |
70c7a608 SN |
7661 | rect.width = m_rowLabelWidth; |
7662 | m_rowLabelWin->Refresh( TRUE, &rect ); | |
7663 | } | |
2d66e025 | 7664 | } |
f85afd4e MB |
7665 | } |
7666 | } | |
7667 | ||
7668 | void wxGrid::SetColLabelValue( int col, const wxString& s ) | |
7669 | { | |
7670 | if ( m_table ) | |
7671 | { | |
7672 | m_table->SetColLabelValue( col, s ); | |
2d66e025 MB |
7673 | if ( !GetBatchCount() ) |
7674 | { | |
70c7a608 SN |
7675 | wxRect rect = CellToRect( 0, col ); |
7676 | if ( rect.width > 0 ) | |
7677 | { | |
cb309039 | 7678 | CalcScrolledPosition(rect.x, 0, &rect.x, &rect.y); |
b1944ebc | 7679 | rect.y = 0; |
70c7a608 SN |
7680 | rect.height = m_colLabelHeight; |
7681 | m_colLabelWin->Refresh( TRUE, &rect ); | |
7682 | } | |
2d66e025 | 7683 | } |
f85afd4e MB |
7684 | } |
7685 | } | |
7686 | ||
7687 | void wxGrid::SetGridLineColour( const wxColour& colour ) | |
7688 | { | |
2d66e025 MB |
7689 | if ( m_gridLineColour != colour ) |
7690 | { | |
7691 | m_gridLineColour = colour; | |
60ff3b99 | 7692 | |
2d66e025 MB |
7693 | wxClientDC dc( m_gridWin ); |
7694 | PrepareDC( dc ); | |
c6a51dcd | 7695 | DrawAllGridLines( dc, wxRegion() ); |
2d66e025 | 7696 | } |
f85afd4e MB |
7697 | } |
7698 | ||
f6bcfd97 BP |
7699 | |
7700 | void wxGrid::SetCellHighlightColour( const wxColour& colour ) | |
7701 | { | |
7702 | if ( m_cellHighlightColour != colour ) | |
7703 | { | |
7704 | m_cellHighlightColour = colour; | |
7705 | ||
7706 | wxClientDC dc( m_gridWin ); | |
7707 | PrepareDC( dc ); | |
7708 | wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords); | |
7709 | DrawCellHighlight(dc, attr); | |
7710 | attr->DecRef(); | |
7711 | } | |
7712 | } | |
7713 | ||
d2520c85 RD |
7714 | void wxGrid::SetCellHighlightPenWidth(int width) |
7715 | { | |
7716 | if (m_cellHighlightPenWidth != width) { | |
7717 | m_cellHighlightPenWidth = width; | |
7718 | ||
7719 | // Just redrawing the cell highlight is not enough since that won't | |
7720 | // make any visible change if the the thickness is getting smaller. | |
7721 | int row = m_currentCellCoords.GetRow(); | |
7722 | int col = m_currentCellCoords.GetCol(); | |
7723 | if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) | |
7724 | return; | |
7725 | wxRect rect = CellToRect(row, col); | |
7726 | m_gridWin->Refresh(TRUE, &rect); | |
7727 | } | |
7728 | } | |
7729 | ||
7730 | void wxGrid::SetCellHighlightROPenWidth(int width) | |
7731 | { | |
7732 | if (m_cellHighlightROPenWidth != width) { | |
7733 | m_cellHighlightROPenWidth = width; | |
7734 | ||
7735 | // Just redrawing the cell highlight is not enough since that won't | |
7736 | // make any visible change if the the thickness is getting smaller. | |
7737 | int row = m_currentCellCoords.GetRow(); | |
7738 | int col = m_currentCellCoords.GetCol(); | |
7739 | if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) | |
7740 | return; | |
7741 | wxRect rect = CellToRect(row, col); | |
7742 | m_gridWin->Refresh(TRUE, &rect); | |
7743 | } | |
7744 | } | |
7745 | ||
f85afd4e MB |
7746 | void wxGrid::EnableGridLines( bool enable ) |
7747 | { | |
7748 | if ( enable != m_gridLinesEnabled ) | |
7749 | { | |
7750 | m_gridLinesEnabled = enable; | |
2d66e025 MB |
7751 | |
7752 | if ( !GetBatchCount() ) | |
7753 | { | |
7754 | if ( enable ) | |
7755 | { | |
7756 | wxClientDC dc( m_gridWin ); | |
7757 | PrepareDC( dc ); | |
c6a51dcd | 7758 | DrawAllGridLines( dc, wxRegion() ); |
2d66e025 MB |
7759 | } |
7760 | else | |
7761 | { | |
7762 | m_gridWin->Refresh(); | |
7763 | } | |
7764 | } | |
f85afd4e MB |
7765 | } |
7766 | } | |
7767 | ||
7768 | ||
7769 | int wxGrid::GetDefaultRowSize() | |
7770 | { | |
7771 | return m_defaultRowHeight; | |
7772 | } | |
7773 | ||
7774 | int wxGrid::GetRowSize( int row ) | |
7775 | { | |
b99be8fb VZ |
7776 | wxCHECK_MSG( row >= 0 && row < m_numRows, 0, _T("invalid row index") ); |
7777 | ||
7c1cb261 | 7778 | return GetRowHeight(row); |
f85afd4e MB |
7779 | } |
7780 | ||
7781 | int wxGrid::GetDefaultColSize() | |
7782 | { | |
7783 | return m_defaultColWidth; | |
7784 | } | |
7785 | ||
7786 | int wxGrid::GetColSize( int col ) | |
7787 | { | |
b99be8fb VZ |
7788 | wxCHECK_MSG( col >= 0 && col < m_numCols, 0, _T("invalid column index") ); |
7789 | ||
7c1cb261 | 7790 | return GetColWidth(col); |
f85afd4e MB |
7791 | } |
7792 | ||
2e9a6788 VZ |
7793 | // ============================================================================ |
7794 | // access to the grid attributes: each of them has a default value in the grid | |
7795 | // itself and may be overidden on a per-cell basis | |
7796 | // ============================================================================ | |
7797 | ||
7798 | // ---------------------------------------------------------------------------- | |
7799 | // setting default attributes | |
7800 | // ---------------------------------------------------------------------------- | |
7801 | ||
7802 | void wxGrid::SetDefaultCellBackgroundColour( const wxColour& col ) | |
7803 | { | |
2796cce3 | 7804 | m_defaultCellAttr->SetBackgroundColour(col); |
c916e13b RR |
7805 | #ifdef __WXGTK__ |
7806 | m_gridWin->SetBackgroundColour(col); | |
7807 | #endif | |
2e9a6788 VZ |
7808 | } |
7809 | ||
7810 | void wxGrid::SetDefaultCellTextColour( const wxColour& col ) | |
7811 | { | |
2796cce3 | 7812 | m_defaultCellAttr->SetTextColour(col); |
2e9a6788 VZ |
7813 | } |
7814 | ||
7815 | void wxGrid::SetDefaultCellAlignment( int horiz, int vert ) | |
7816 | { | |
2796cce3 | 7817 | m_defaultCellAttr->SetAlignment(horiz, vert); |
2e9a6788 VZ |
7818 | } |
7819 | ||
7820 | void wxGrid::SetDefaultCellFont( const wxFont& font ) | |
7821 | { | |
2796cce3 RD |
7822 | m_defaultCellAttr->SetFont(font); |
7823 | } | |
7824 | ||
0ba143c9 RD |
7825 | void wxGrid::SetDefaultRenderer(wxGridCellRenderer *renderer) |
7826 | { | |
7827 | m_defaultCellAttr->SetRenderer(renderer); | |
7828 | } | |
2e9a6788 | 7829 | |
0ba143c9 RD |
7830 | void wxGrid::SetDefaultEditor(wxGridCellEditor *editor) |
7831 | { | |
7832 | m_defaultCellAttr->SetEditor(editor); | |
7833 | } | |
9b4aede2 | 7834 | |
2e9a6788 VZ |
7835 | // ---------------------------------------------------------------------------- |
7836 | // access to the default attrbiutes | |
7837 | // ---------------------------------------------------------------------------- | |
7838 | ||
f85afd4e MB |
7839 | wxColour wxGrid::GetDefaultCellBackgroundColour() |
7840 | { | |
2796cce3 | 7841 | return m_defaultCellAttr->GetBackgroundColour(); |
f85afd4e MB |
7842 | } |
7843 | ||
2e9a6788 VZ |
7844 | wxColour wxGrid::GetDefaultCellTextColour() |
7845 | { | |
2796cce3 | 7846 | return m_defaultCellAttr->GetTextColour(); |
2e9a6788 VZ |
7847 | } |
7848 | ||
7849 | wxFont wxGrid::GetDefaultCellFont() | |
7850 | { | |
2796cce3 | 7851 | return m_defaultCellAttr->GetFont(); |
2e9a6788 VZ |
7852 | } |
7853 | ||
7854 | void wxGrid::GetDefaultCellAlignment( int *horiz, int *vert ) | |
7855 | { | |
2796cce3 | 7856 | m_defaultCellAttr->GetAlignment(horiz, vert); |
2e9a6788 VZ |
7857 | } |
7858 | ||
0ba143c9 RD |
7859 | wxGridCellRenderer *wxGrid::GetDefaultRenderer() const |
7860 | { | |
0b190b0f | 7861 | return m_defaultCellAttr->GetRenderer(NULL, 0, 0); |
0ba143c9 | 7862 | } |
ab79958a | 7863 | |
0ba143c9 RD |
7864 | wxGridCellEditor *wxGrid::GetDefaultEditor() const |
7865 | { | |
28a77bc4 | 7866 | return m_defaultCellAttr->GetEditor(NULL,0,0); |
0ba143c9 | 7867 | } |
9b4aede2 | 7868 | |
2e9a6788 VZ |
7869 | // ---------------------------------------------------------------------------- |
7870 | // access to cell attributes | |
7871 | // ---------------------------------------------------------------------------- | |
7872 | ||
b99be8fb | 7873 | wxColour wxGrid::GetCellBackgroundColour(int row, int col) |
f85afd4e | 7874 | { |
0a976765 | 7875 | wxGridCellAttr *attr = GetCellAttr(row, col); |
2796cce3 | 7876 | wxColour colour = attr->GetBackgroundColour(); |
39bcce60 | 7877 | attr->DecRef(); |
b99be8fb | 7878 | return colour; |
f85afd4e MB |
7879 | } |
7880 | ||
b99be8fb | 7881 | wxColour wxGrid::GetCellTextColour( int row, int col ) |
f85afd4e | 7882 | { |
0a976765 | 7883 | wxGridCellAttr *attr = GetCellAttr(row, col); |
2796cce3 | 7884 | wxColour colour = attr->GetTextColour(); |
39bcce60 | 7885 | attr->DecRef(); |
b99be8fb | 7886 | return colour; |
f85afd4e MB |
7887 | } |
7888 | ||
b99be8fb | 7889 | wxFont wxGrid::GetCellFont( int row, int col ) |
f85afd4e | 7890 | { |
0a976765 | 7891 | wxGridCellAttr *attr = GetCellAttr(row, col); |
2796cce3 | 7892 | wxFont font = attr->GetFont(); |
39bcce60 | 7893 | attr->DecRef(); |
b99be8fb | 7894 | return font; |
f85afd4e MB |
7895 | } |
7896 | ||
b99be8fb | 7897 | void wxGrid::GetCellAlignment( int row, int col, int *horiz, int *vert ) |
f85afd4e | 7898 | { |
0a976765 | 7899 | wxGridCellAttr *attr = GetCellAttr(row, col); |
2796cce3 | 7900 | attr->GetAlignment(horiz, vert); |
39bcce60 | 7901 | attr->DecRef(); |
2e9a6788 VZ |
7902 | } |
7903 | ||
2796cce3 RD |
7904 | wxGridCellRenderer* wxGrid::GetCellRenderer(int row, int col) |
7905 | { | |
7906 | wxGridCellAttr* attr = GetCellAttr(row, col); | |
28a77bc4 | 7907 | wxGridCellRenderer* renderer = attr->GetRenderer(this, row, col); |
2796cce3 | 7908 | attr->DecRef(); |
0b190b0f | 7909 | |
2796cce3 RD |
7910 | return renderer; |
7911 | } | |
7912 | ||
9b4aede2 RD |
7913 | wxGridCellEditor* wxGrid::GetCellEditor(int row, int col) |
7914 | { | |
7915 | wxGridCellAttr* attr = GetCellAttr(row, col); | |
28a77bc4 | 7916 | wxGridCellEditor* editor = attr->GetEditor(this, row, col); |
9b4aede2 | 7917 | attr->DecRef(); |
0b190b0f | 7918 | |
9b4aede2 RD |
7919 | return editor; |
7920 | } | |
7921 | ||
283b7808 VZ |
7922 | bool wxGrid::IsReadOnly(int row, int col) const |
7923 | { | |
7924 | wxGridCellAttr* attr = GetCellAttr(row, col); | |
7925 | bool isReadOnly = attr->IsReadOnly(); | |
7926 | attr->DecRef(); | |
7927 | return isReadOnly; | |
7928 | } | |
7929 | ||
2e9a6788 | 7930 | // ---------------------------------------------------------------------------- |
758cbedf | 7931 | // attribute support: cache, automatic provider creation, ... |
2e9a6788 VZ |
7932 | // ---------------------------------------------------------------------------- |
7933 | ||
7934 | bool wxGrid::CanHaveAttributes() | |
7935 | { | |
7936 | if ( !m_table ) | |
7937 | { | |
7938 | return FALSE; | |
7939 | } | |
7940 | ||
f2d76237 | 7941 | return m_table->CanHaveAttributes(); |
2e9a6788 VZ |
7942 | } |
7943 | ||
0a976765 VZ |
7944 | void wxGrid::ClearAttrCache() |
7945 | { | |
7946 | if ( m_attrCache.row != -1 ) | |
7947 | { | |
39bcce60 | 7948 | wxSafeDecRef(m_attrCache.attr); |
19d7140e | 7949 | m_attrCache.attr = NULL; |
0a976765 VZ |
7950 | m_attrCache.row = -1; |
7951 | } | |
7952 | } | |
7953 | ||
7954 | void wxGrid::CacheAttr(int row, int col, wxGridCellAttr *attr) const | |
7955 | { | |
7956 | wxGrid *self = (wxGrid *)this; // const_cast | |
7957 | ||
7958 | self->ClearAttrCache(); | |
7959 | self->m_attrCache.row = row; | |
7960 | self->m_attrCache.col = col; | |
7961 | self->m_attrCache.attr = attr; | |
39bcce60 | 7962 | wxSafeIncRef(attr); |
0a976765 VZ |
7963 | } |
7964 | ||
7965 | bool wxGrid::LookupAttr(int row, int col, wxGridCellAttr **attr) const | |
7966 | { | |
7967 | if ( row == m_attrCache.row && col == m_attrCache.col ) | |
7968 | { | |
7969 | *attr = m_attrCache.attr; | |
39bcce60 | 7970 | wxSafeIncRef(m_attrCache.attr); |
0a976765 VZ |
7971 | |
7972 | #ifdef DEBUG_ATTR_CACHE | |
7973 | gs_nAttrCacheHits++; | |
7974 | #endif | |
7975 | ||
7976 | return TRUE; | |
7977 | } | |
7978 | else | |
7979 | { | |
7980 | #ifdef DEBUG_ATTR_CACHE | |
7981 | gs_nAttrCacheMisses++; | |
7982 | #endif | |
7983 | return FALSE; | |
7984 | } | |
7985 | } | |
7986 | ||
2e9a6788 VZ |
7987 | wxGridCellAttr *wxGrid::GetCellAttr(int row, int col) const |
7988 | { | |
0a976765 VZ |
7989 | wxGridCellAttr *attr; |
7990 | if ( !LookupAttr(row, col, &attr) ) | |
2e9a6788 | 7991 | { |
19d7140e | 7992 | attr = m_table ? m_table->GetAttr(row, col , wxGridCellAttr::Any) : (wxGridCellAttr *)NULL; |
0a976765 VZ |
7993 | CacheAttr(row, col, attr); |
7994 | } | |
508011ce VZ |
7995 | if (attr) |
7996 | { | |
2796cce3 | 7997 | attr->SetDefAttr(m_defaultCellAttr); |
508011ce VZ |
7998 | } |
7999 | else | |
8000 | { | |
2796cce3 RD |
8001 | attr = m_defaultCellAttr; |
8002 | attr->IncRef(); | |
8003 | } | |
2e9a6788 | 8004 | |
0a976765 VZ |
8005 | return attr; |
8006 | } | |
8007 | ||
8008 | wxGridCellAttr *wxGrid::GetOrCreateCellAttr(int row, int col) const | |
8009 | { | |
19d7140e | 8010 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; |
0a976765 | 8011 | wxASSERT_MSG( m_table, |
f6bcfd97 | 8012 | _T("we may only be called if CanHaveAttributes() returned TRUE and then m_table should be !NULL") ); |
0a976765 | 8013 | |
19d7140e | 8014 | attr = m_table->GetAttr(row, col, wxGridCellAttr::Cell ); |
0a976765 VZ |
8015 | if ( !attr ) |
8016 | { | |
8017 | attr = new wxGridCellAttr; | |
8018 | ||
8019 | // artificially inc the ref count to match DecRef() in caller | |
8020 | attr->IncRef(); | |
0a976765 VZ |
8021 | m_table->SetAttr(attr, row, col); |
8022 | } | |
2796cce3 | 8023 | attr->SetDefAttr(m_defaultCellAttr); |
2e9a6788 VZ |
8024 | return attr; |
8025 | } | |
8026 | ||
0b190b0f VZ |
8027 | // ---------------------------------------------------------------------------- |
8028 | // setting column attributes (wrappers around SetColAttr) | |
8029 | // ---------------------------------------------------------------------------- | |
8030 | ||
8031 | void wxGrid::SetColFormatBool(int col) | |
8032 | { | |
8033 | SetColFormatCustom(col, wxGRID_VALUE_BOOL); | |
8034 | } | |
8035 | ||
8036 | void wxGrid::SetColFormatNumber(int col) | |
8037 | { | |
8038 | SetColFormatCustom(col, wxGRID_VALUE_NUMBER); | |
8039 | } | |
8040 | ||
8041 | void wxGrid::SetColFormatFloat(int col, int width, int precision) | |
8042 | { | |
8043 | wxString typeName = wxGRID_VALUE_FLOAT; | |
8044 | if ( (width != -1) || (precision != -1) ) | |
8045 | { | |
8046 | typeName << _T(':') << width << _T(',') << precision; | |
8047 | } | |
8048 | ||
8049 | SetColFormatCustom(col, typeName); | |
8050 | } | |
8051 | ||
8052 | void wxGrid::SetColFormatCustom(int col, const wxString& typeName) | |
8053 | { | |
19d7140e VZ |
8054 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; |
8055 | ||
8056 | attr = m_table->GetAttr(-1, col, wxGridCellAttr::Col ); | |
8057 | if(!attr) | |
8058 | attr = new wxGridCellAttr; | |
0b190b0f VZ |
8059 | wxGridCellRenderer *renderer = GetDefaultRendererForType(typeName); |
8060 | attr->SetRenderer(renderer); | |
8061 | ||
8062 | SetColAttr(col, attr); | |
19d7140e | 8063 | |
0b190b0f VZ |
8064 | } |
8065 | ||
758cbedf VZ |
8066 | // ---------------------------------------------------------------------------- |
8067 | // setting cell attributes: this is forwarded to the table | |
8068 | // ---------------------------------------------------------------------------- | |
8069 | ||
8070 | void wxGrid::SetRowAttr(int row, wxGridCellAttr *attr) | |
8071 | { | |
8072 | if ( CanHaveAttributes() ) | |
8073 | { | |
8074 | m_table->SetRowAttr(attr, row); | |
19d7140e | 8075 | ClearAttrCache(); |
758cbedf VZ |
8076 | } |
8077 | else | |
8078 | { | |
39bcce60 | 8079 | wxSafeDecRef(attr); |
758cbedf VZ |
8080 | } |
8081 | } | |
8082 | ||
8083 | void wxGrid::SetColAttr(int col, wxGridCellAttr *attr) | |
8084 | { | |
8085 | if ( CanHaveAttributes() ) | |
8086 | { | |
8087 | m_table->SetColAttr(attr, col); | |
19d7140e | 8088 | ClearAttrCache(); |
758cbedf VZ |
8089 | } |
8090 | else | |
8091 | { | |
39bcce60 | 8092 | wxSafeDecRef(attr); |
758cbedf VZ |
8093 | } |
8094 | } | |
8095 | ||
2e9a6788 VZ |
8096 | void wxGrid::SetCellBackgroundColour( int row, int col, const wxColour& colour ) |
8097 | { | |
8098 | if ( CanHaveAttributes() ) | |
8099 | { | |
0a976765 | 8100 | wxGridCellAttr *attr = GetOrCreateCellAttr(row, col); |
2e9a6788 VZ |
8101 | attr->SetBackgroundColour(colour); |
8102 | attr->DecRef(); | |
8103 | } | |
8104 | } | |
8105 | ||
8106 | void wxGrid::SetCellTextColour( int row, int col, const wxColour& colour ) | |
8107 | { | |
8108 | if ( CanHaveAttributes() ) | |
8109 | { | |
0a976765 | 8110 | wxGridCellAttr *attr = GetOrCreateCellAttr(row, col); |
2e9a6788 VZ |
8111 | attr->SetTextColour(colour); |
8112 | attr->DecRef(); | |
8113 | } | |
8114 | } | |
8115 | ||
8116 | void wxGrid::SetCellFont( int row, int col, const wxFont& font ) | |
8117 | { | |
8118 | if ( CanHaveAttributes() ) | |
8119 | { | |
0a976765 | 8120 | wxGridCellAttr *attr = GetOrCreateCellAttr(row, col); |
2e9a6788 VZ |
8121 | attr->SetFont(font); |
8122 | attr->DecRef(); | |
8123 | } | |
8124 | } | |
8125 | ||
8126 | void wxGrid::SetCellAlignment( int row, int col, int horiz, int vert ) | |
8127 | { | |
8128 | if ( CanHaveAttributes() ) | |
8129 | { | |
0a976765 | 8130 | wxGridCellAttr *attr = GetOrCreateCellAttr(row, col); |
2e9a6788 VZ |
8131 | attr->SetAlignment(horiz, vert); |
8132 | attr->DecRef(); | |
ab79958a VZ |
8133 | } |
8134 | } | |
8135 | ||
8136 | void wxGrid::SetCellRenderer(int row, int col, wxGridCellRenderer *renderer) | |
8137 | { | |
8138 | if ( CanHaveAttributes() ) | |
8139 | { | |
0a976765 | 8140 | wxGridCellAttr *attr = GetOrCreateCellAttr(row, col); |
ab79958a VZ |
8141 | attr->SetRenderer(renderer); |
8142 | attr->DecRef(); | |
9b4aede2 RD |
8143 | } |
8144 | } | |
8145 | ||
8146 | void wxGrid::SetCellEditor(int row, int col, wxGridCellEditor* editor) | |
8147 | { | |
8148 | if ( CanHaveAttributes() ) | |
8149 | { | |
8150 | wxGridCellAttr *attr = GetOrCreateCellAttr(row, col); | |
8151 | attr->SetEditor(editor); | |
8152 | attr->DecRef(); | |
283b7808 VZ |
8153 | } |
8154 | } | |
8155 | ||
8156 | void wxGrid::SetReadOnly(int row, int col, bool isReadOnly) | |
8157 | { | |
8158 | if ( CanHaveAttributes() ) | |
8159 | { | |
8160 | wxGridCellAttr *attr = GetOrCreateCellAttr(row, col); | |
8161 | attr->SetReadOnly(isReadOnly); | |
8162 | attr->DecRef(); | |
2e9a6788 | 8163 | } |
f85afd4e MB |
8164 | } |
8165 | ||
f2d76237 RD |
8166 | // ---------------------------------------------------------------------------- |
8167 | // Data type registration | |
8168 | // ---------------------------------------------------------------------------- | |
8169 | ||
8170 | void wxGrid::RegisterDataType(const wxString& typeName, | |
8171 | wxGridCellRenderer* renderer, | |
8172 | wxGridCellEditor* editor) | |
8173 | { | |
8174 | m_typeRegistry->RegisterDataType(typeName, renderer, editor); | |
8175 | } | |
8176 | ||
8177 | ||
99306db2 | 8178 | wxGridCellEditor* wxGrid::GetDefaultEditorForCell(int row, int col) const |
f2d76237 RD |
8179 | { |
8180 | wxString typeName = m_table->GetTypeName(row, col); | |
8181 | return GetDefaultEditorForType(typeName); | |
8182 | } | |
8183 | ||
99306db2 | 8184 | wxGridCellRenderer* wxGrid::GetDefaultRendererForCell(int row, int col) const |
f2d76237 RD |
8185 | { |
8186 | wxString typeName = m_table->GetTypeName(row, col); | |
8187 | return GetDefaultRendererForType(typeName); | |
8188 | } | |
8189 | ||
99306db2 VZ |
8190 | wxGridCellEditor* |
8191 | wxGrid::GetDefaultEditorForType(const wxString& typeName) const | |
f2d76237 | 8192 | { |
c4608a8a | 8193 | int index = m_typeRegistry->FindOrCloneDataType(typeName); |
0b190b0f VZ |
8194 | if ( index == wxNOT_FOUND ) |
8195 | { | |
8196 | wxFAIL_MSG(wxT("Unknown data type name")); | |
8197 | ||
f2d76237 RD |
8198 | return NULL; |
8199 | } | |
0b190b0f | 8200 | |
f2d76237 RD |
8201 | return m_typeRegistry->GetEditor(index); |
8202 | } | |
8203 | ||
99306db2 VZ |
8204 | wxGridCellRenderer* |
8205 | wxGrid::GetDefaultRendererForType(const wxString& typeName) const | |
f2d76237 | 8206 | { |
c4608a8a | 8207 | int index = m_typeRegistry->FindOrCloneDataType(typeName); |
0b190b0f VZ |
8208 | if ( index == wxNOT_FOUND ) |
8209 | { | |
c4608a8a | 8210 | wxFAIL_MSG(wxT("Unknown data type name")); |
0b190b0f | 8211 | |
c4608a8a | 8212 | return NULL; |
e72b4213 | 8213 | } |
0b190b0f | 8214 | |
c4608a8a | 8215 | return m_typeRegistry->GetRenderer(index); |
f2d76237 RD |
8216 | } |
8217 | ||
8218 | ||
2e9a6788 VZ |
8219 | // ---------------------------------------------------------------------------- |
8220 | // row/col size | |
8221 | // ---------------------------------------------------------------------------- | |
8222 | ||
6e8524b1 MB |
8223 | void wxGrid::EnableDragRowSize( bool enable ) |
8224 | { | |
8225 | m_canDragRowSize = enable; | |
8226 | } | |
8227 | ||
8228 | ||
8229 | void wxGrid::EnableDragColSize( bool enable ) | |
8230 | { | |
8231 | m_canDragColSize = enable; | |
8232 | } | |
8233 | ||
4cfa5de6 RD |
8234 | void wxGrid::EnableDragGridSize( bool enable ) |
8235 | { | |
8236 | m_canDragGridSize = enable; | |
8237 | } | |
8238 | ||
6e8524b1 | 8239 | |
f85afd4e MB |
8240 | void wxGrid::SetDefaultRowSize( int height, bool resizeExistingRows ) |
8241 | { | |
8242 | m_defaultRowHeight = wxMax( height, WXGRID_MIN_ROW_HEIGHT ); | |
8243 | ||
8244 | if ( resizeExistingRows ) | |
8245 | { | |
7c1cb261 | 8246 | InitRowHeights(); |
edb89f7e VZ |
8247 | if ( !GetBatchCount() ) |
8248 | CalcDimensions(); | |
f85afd4e MB |
8249 | } |
8250 | } | |
8251 | ||
8252 | void wxGrid::SetRowSize( int row, int height ) | |
8253 | { | |
b99be8fb | 8254 | wxCHECK_RET( row >= 0 && row < m_numRows, _T("invalid row index") ); |
60ff3b99 | 8255 | |
7c1cb261 VZ |
8256 | if ( m_rowHeights.IsEmpty() ) |
8257 | { | |
8258 | // need to really create the array | |
8259 | InitRowHeights(); | |
8260 | } | |
60ff3b99 | 8261 | |
b99be8fb VZ |
8262 | int h = wxMax( 0, height ); |
8263 | int diff = h - m_rowHeights[row]; | |
60ff3b99 | 8264 | |
b99be8fb | 8265 | m_rowHeights[row] = h; |
7c1cb261 | 8266 | int i; |
b99be8fb | 8267 | for ( i = row; i < m_numRows; i++ ) |
f85afd4e | 8268 | { |
b99be8fb | 8269 | m_rowBottoms[i] += diff; |
f85afd4e | 8270 | } |
faec5a43 SN |
8271 | if ( !GetBatchCount() ) |
8272 | CalcDimensions(); | |
f85afd4e MB |
8273 | } |
8274 | ||
8275 | void wxGrid::SetDefaultColSize( int width, bool resizeExistingCols ) | |
8276 | { | |
8277 | m_defaultColWidth = wxMax( width, WXGRID_MIN_COL_WIDTH ); | |
8278 | ||
8279 | if ( resizeExistingCols ) | |
8280 | { | |
7c1cb261 | 8281 | InitColWidths(); |
edb89f7e VZ |
8282 | if ( !GetBatchCount() ) |
8283 | CalcDimensions(); | |
f85afd4e MB |
8284 | } |
8285 | } | |
8286 | ||
8287 | void wxGrid::SetColSize( int col, int width ) | |
8288 | { | |
b99be8fb | 8289 | wxCHECK_RET( col >= 0 && col < m_numCols, _T("invalid column index") ); |
60ff3b99 | 8290 | |
43947979 VZ |
8291 | // should we check that it's bigger than GetColMinimalWidth(col) here? |
8292 | ||
7c1cb261 VZ |
8293 | if ( m_colWidths.IsEmpty() ) |
8294 | { | |
8295 | // need to really create the array | |
8296 | InitColWidths(); | |
8297 | } | |
f85afd4e | 8298 | |
b99be8fb VZ |
8299 | int w = wxMax( 0, width ); |
8300 | int diff = w - m_colWidths[col]; | |
8301 | m_colWidths[col] = w; | |
60ff3b99 | 8302 | |
7c1cb261 | 8303 | int i; |
b99be8fb | 8304 | for ( i = col; i < m_numCols; i++ ) |
f85afd4e | 8305 | { |
b99be8fb | 8306 | m_colRights[i] += diff; |
f85afd4e | 8307 | } |
faec5a43 SN |
8308 | if ( !GetBatchCount() ) |
8309 | CalcDimensions(); | |
f85afd4e MB |
8310 | } |
8311 | ||
2d66e025 | 8312 | |
43947979 VZ |
8313 | void wxGrid::SetColMinimalWidth( int col, int width ) |
8314 | { | |
af547d51 VZ |
8315 | m_colMinWidths.Put(col, width); |
8316 | } | |
8317 | ||
8318 | void wxGrid::SetRowMinimalHeight( int row, int width ) | |
8319 | { | |
8320 | m_rowMinHeights.Put(row, width); | |
43947979 VZ |
8321 | } |
8322 | ||
8323 | int wxGrid::GetColMinimalWidth(int col) const | |
8324 | { | |
af547d51 VZ |
8325 | long value = m_colMinWidths.Get(col); |
8326 | return value != wxNOT_FOUND ? (int)value : WXGRID_MIN_COL_WIDTH; | |
8327 | } | |
8328 | ||
8329 | int wxGrid::GetRowMinimalHeight(int row) const | |
8330 | { | |
8331 | long value = m_rowMinHeights.Get(row); | |
8332 | return value != wxNOT_FOUND ? (int)value : WXGRID_MIN_ROW_HEIGHT; | |
43947979 VZ |
8333 | } |
8334 | ||
57c086ef VZ |
8335 | // ---------------------------------------------------------------------------- |
8336 | // auto sizing | |
8337 | // ---------------------------------------------------------------------------- | |
8338 | ||
af547d51 | 8339 | void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column ) |
65e4e78e VZ |
8340 | { |
8341 | wxClientDC dc(m_gridWin); | |
8342 | ||
a95e38c0 VZ |
8343 | // init both of them to avoid compiler warnings, even if weo nly need one |
8344 | int row = -1, | |
8345 | col = -1; | |
af547d51 VZ |
8346 | if ( column ) |
8347 | col = colOrRow; | |
8348 | else | |
8349 | row = colOrRow; | |
8350 | ||
8351 | wxCoord extent, extentMax = 0; | |
8352 | int max = column ? m_numRows : m_numCols; | |
39bcce60 | 8353 | for ( int rowOrCol = 0; rowOrCol < max; rowOrCol++ ) |
65e4e78e | 8354 | { |
af547d51 VZ |
8355 | if ( column ) |
8356 | row = rowOrCol; | |
8357 | else | |
8358 | col = rowOrCol; | |
8359 | ||
65e4e78e | 8360 | wxGridCellAttr* attr = GetCellAttr(row, col); |
28a77bc4 | 8361 | wxGridCellRenderer* renderer = attr->GetRenderer(this, row, col); |
65e4e78e VZ |
8362 | if ( renderer ) |
8363 | { | |
af547d51 VZ |
8364 | wxSize size = renderer->GetBestSize(*this, *attr, dc, row, col); |
8365 | extent = column ? size.x : size.y; | |
8366 | if ( extent > extentMax ) | |
65e4e78e | 8367 | { |
af547d51 | 8368 | extentMax = extent; |
65e4e78e | 8369 | } |
0b190b0f VZ |
8370 | |
8371 | renderer->DecRef(); | |
65e4e78e VZ |
8372 | } |
8373 | ||
8374 | attr->DecRef(); | |
8375 | } | |
8376 | ||
af547d51 VZ |
8377 | // now also compare with the column label extent |
8378 | wxCoord w, h; | |
65e4e78e | 8379 | dc.SetFont( GetLabelFont() ); |
294d195c MB |
8380 | |
8381 | if ( column ) | |
8382 | dc.GetTextExtent( GetColLabelValue(col), &w, &h ); | |
8383 | else | |
ee495e4c | 8384 | dc.GetTextExtent( GetRowLabelValue(row), &w, &h ); |
294d195c | 8385 | |
af547d51 VZ |
8386 | extent = column ? w : h; |
8387 | if ( extent > extentMax ) | |
65e4e78e | 8388 | { |
af547d51 | 8389 | extentMax = extent; |
65e4e78e VZ |
8390 | } |
8391 | ||
af547d51 | 8392 | if ( !extentMax ) |
65e4e78e | 8393 | { |
af547d51 VZ |
8394 | // empty column - give default extent (notice that if extentMax is less |
8395 | // than default extent but != 0, it's ok) | |
8396 | extentMax = column ? m_defaultColWidth : m_defaultRowHeight; | |
65e4e78e VZ |
8397 | } |
8398 | else | |
8399 | { | |
a95e38c0 VZ |
8400 | if ( column ) |
8401 | { | |
8402 | // leave some space around text | |
8403 | extentMax += 10; | |
8404 | } | |
f6bcfd97 BP |
8405 | else |
8406 | { | |
8407 | extentMax += 6; | |
8408 | } | |
65e4e78e VZ |
8409 | } |
8410 | ||
edb89f7e VZ |
8411 | if ( column ) |
8412 | { | |
af547d51 | 8413 | SetColSize(col, extentMax); |
faec5a43 SN |
8414 | if ( !GetBatchCount() ) |
8415 | { | |
edb89f7e VZ |
8416 | int cw, ch, dummy; |
8417 | m_gridWin->GetClientSize( &cw, &ch ); | |
8418 | wxRect rect ( CellToRect( 0, col ) ); | |
8419 | rect.y = 0; | |
8420 | CalcScrolledPosition(rect.x, 0, &rect.x, &dummy); | |
8421 | rect.width = cw - rect.x; | |
8422 | rect.height = m_colLabelHeight; | |
8423 | m_colLabelWin->Refresh( TRUE, &rect ); | |
8424 | } | |
8425 | } | |
8426 | else | |
8427 | { | |
39bcce60 | 8428 | SetRowSize(row, extentMax); |
faec5a43 SN |
8429 | if ( !GetBatchCount() ) |
8430 | { | |
edb89f7e VZ |
8431 | int cw, ch, dummy; |
8432 | m_gridWin->GetClientSize( &cw, &ch ); | |
8433 | wxRect rect ( CellToRect( row, 0 ) ); | |
8434 | rect.x = 0; | |
8435 | CalcScrolledPosition(0, rect.y, &dummy, &rect.y); | |
8436 | rect.width = m_rowLabelWidth; | |
faec5a43 | 8437 | rect.height = ch - rect.y; |
edb89f7e VZ |
8438 | m_rowLabelWin->Refresh( TRUE, &rect ); |
8439 | } | |
faec5a43 | 8440 | } |
65e4e78e VZ |
8441 | if ( setAsMin ) |
8442 | { | |
af547d51 VZ |
8443 | if ( column ) |
8444 | SetColMinimalWidth(col, extentMax); | |
8445 | else | |
39bcce60 | 8446 | SetRowMinimalHeight(row, extentMax); |
65e4e78e VZ |
8447 | } |
8448 | } | |
8449 | ||
266e8367 | 8450 | int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin) |
65e4e78e | 8451 | { |
57c086ef VZ |
8452 | int width = m_rowLabelWidth; |
8453 | ||
faec5a43 SN |
8454 | if ( !calcOnly ) |
8455 | BeginBatch(); | |
65e4e78e VZ |
8456 | for ( int col = 0; col < m_numCols; col++ ) |
8457 | { | |
266e8367 VZ |
8458 | if ( !calcOnly ) |
8459 | { | |
8460 | AutoSizeColumn(col, setAsMin); | |
8461 | } | |
57c086ef VZ |
8462 | |
8463 | width += GetColWidth(col); | |
65e4e78e | 8464 | } |
faec5a43 SN |
8465 | if ( !calcOnly ) |
8466 | EndBatch(); | |
266e8367 | 8467 | return width; |
65e4e78e VZ |
8468 | } |
8469 | ||
266e8367 | 8470 | int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin) |
57c086ef VZ |
8471 | { |
8472 | int height = m_colLabelHeight; | |
8473 | ||
faec5a43 SN |
8474 | if ( !calcOnly ) |
8475 | BeginBatch(); | |
57c086ef VZ |
8476 | for ( int row = 0; row < m_numRows; row++ ) |
8477 | { | |
af547d51 VZ |
8478 | if ( !calcOnly ) |
8479 | { | |
8480 | AutoSizeRow(row, setAsMin); | |
8481 | } | |
57c086ef VZ |
8482 | |
8483 | height += GetRowHeight(row); | |
8484 | } | |
faec5a43 SN |
8485 | if ( !calcOnly ) |
8486 | EndBatch(); | |
266e8367 | 8487 | return height; |
57c086ef VZ |
8488 | } |
8489 | ||
8490 | void wxGrid::AutoSize() | |
8491 | { | |
266e8367 | 8492 | // set the size too |
faec5a43 | 8493 | SetClientSize(SetOrCalcColumnSizes(FALSE), SetOrCalcRowSizes(FALSE)); |
266e8367 VZ |
8494 | } |
8495 | ||
8496 | wxSize wxGrid::DoGetBestSize() const | |
8497 | { | |
8498 | // don't set sizes, only calculate them | |
8499 | wxGrid *self = (wxGrid *)this; // const_cast | |
8500 | ||
8501 | return wxSize(self->SetOrCalcColumnSizes(TRUE), | |
8502 | self->SetOrCalcRowSizes(TRUE)); | |
8503 | } | |
8504 | ||
8505 | void wxGrid::Fit() | |
8506 | { | |
8507 | AutoSize(); | |
57c086ef VZ |
8508 | } |
8509 | ||
6fc0f38f SN |
8510 | |
8511 | wxPen& wxGrid::GetDividerPen() const | |
8512 | { | |
8513 | return wxNullPen; | |
8514 | } | |
8515 | ||
57c086ef VZ |
8516 | // ---------------------------------------------------------------------------- |
8517 | // cell value accessor functions | |
8518 | // ---------------------------------------------------------------------------- | |
f85afd4e MB |
8519 | |
8520 | void wxGrid::SetCellValue( int row, int col, const wxString& s ) | |
8521 | { | |
8522 | if ( m_table ) | |
8523 | { | |
f6bcfd97 | 8524 | m_table->SetValue( row, col, s ); |
2d66e025 MB |
8525 | if ( !GetBatchCount() ) |
8526 | { | |
8527 | wxClientDC dc( m_gridWin ); | |
8528 | PrepareDC( dc ); | |
8529 | DrawCell( dc, wxGridCellCoords(row, col) ); | |
8530 | } | |
60ff3b99 | 8531 | |
f85afd4e | 8532 | if ( m_currentCellCoords.GetRow() == row && |
4cfa5de6 | 8533 | m_currentCellCoords.GetCol() == col && |
f6bcfd97 BP |
8534 | IsCellEditControlShown()) |
8535 | // Note: If we are using IsCellEditControlEnabled, | |
8536 | // this interacts badly with calling SetCellValue from | |
8537 | // an EVT_GRID_CELL_CHANGE handler. | |
f85afd4e | 8538 | { |
4cfa5de6 RD |
8539 | HideCellEditControl(); |
8540 | ShowCellEditControl(); // will reread data from table | |
f85afd4e | 8541 | } |
f85afd4e MB |
8542 | } |
8543 | } | |
8544 | ||
8545 | ||
8546 | // | |
2d66e025 | 8547 | // ------ Block, row and col selection |
f85afd4e MB |
8548 | // |
8549 | ||
8550 | void wxGrid::SelectRow( int row, bool addToSelected ) | |
8551 | { | |
b5808881 | 8552 | if ( IsSelection() && !addToSelected ) |
e32352cf | 8553 | ClearSelection(); |
70c7a608 | 8554 | |
f6bcfd97 | 8555 | m_selection->SelectRow( row, FALSE, addToSelected ); |
f85afd4e MB |
8556 | } |
8557 | ||
8558 | ||
8559 | void wxGrid::SelectCol( int col, bool addToSelected ) | |
8560 | { | |
b5808881 | 8561 | if ( IsSelection() && !addToSelected ) |
e32352cf | 8562 | ClearSelection(); |
f85afd4e | 8563 | |
f6bcfd97 | 8564 | m_selection->SelectCol( col, FALSE, addToSelected ); |
f85afd4e MB |
8565 | } |
8566 | ||
8567 | ||
84912ef8 | 8568 | void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, |
c9097836 | 8569 | bool addToSelected ) |
f85afd4e | 8570 | { |
c9097836 MB |
8571 | if ( IsSelection() && !addToSelected ) |
8572 | ClearSelection(); | |
f85afd4e | 8573 | |
84912ef8 RD |
8574 | m_selection->SelectBlock( topRow, leftCol, bottomRow, rightCol, |
8575 | FALSE, addToSelected ); | |
f85afd4e MB |
8576 | } |
8577 | ||
c9097836 | 8578 | |
f85afd4e MB |
8579 | void wxGrid::SelectAll() |
8580 | { | |
f74d0b57 SN |
8581 | if ( m_numRows > 0 && m_numCols > 0 ) |
8582 | m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 ); | |
b5808881 | 8583 | } |
f85afd4e | 8584 | |
f7b4b343 VZ |
8585 | // |
8586 | // ------ Cell, row and col deselection | |
8587 | // | |
8588 | ||
8589 | void wxGrid::DeselectRow( int row ) | |
8590 | { | |
8591 | if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows ) | |
8592 | { | |
8593 | if ( m_selection->IsInSelection(row, 0 ) ) | |
8594 | m_selection->ToggleCellSelection( row, 0); | |
ffdd3c98 | 8595 | } |
f7b4b343 VZ |
8596 | else |
8597 | { | |
8598 | int nCols = GetNumberCols(); | |
8599 | for ( int i = 0; i < nCols ; i++ ) | |
8600 | { | |
8601 | if ( m_selection->IsInSelection(row, i ) ) | |
8602 | m_selection->ToggleCellSelection( row, i); | |
8603 | } | |
8604 | } | |
8605 | } | |
8606 | ||
8607 | void wxGrid::DeselectCol( int col ) | |
8608 | { | |
8609 | if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectColumns ) | |
8610 | { | |
8611 | if ( m_selection->IsInSelection(0, col ) ) | |
8612 | m_selection->ToggleCellSelection( 0, col); | |
8613 | } | |
8614 | else | |
8615 | { | |
8616 | int nRows = GetNumberRows(); | |
8617 | for ( int i = 0; i < nRows ; i++ ) | |
8618 | { | |
8619 | if ( m_selection->IsInSelection(i, col ) ) | |
8620 | m_selection->ToggleCellSelection(i, col); | |
8621 | } | |
8622 | } | |
8623 | } | |
8624 | ||
8625 | void wxGrid::DeselectCell( int row, int col ) | |
8626 | { | |
8627 | if ( m_selection->IsInSelection(row, col) ) | |
8628 | m_selection->ToggleCellSelection(row, col); | |
8629 | } | |
8630 | ||
b5808881 SN |
8631 | bool wxGrid::IsSelection() |
8632 | { | |
8633 | return ( m_selection->IsSelection() || | |
8634 | ( m_selectingTopLeft != wxGridNoCellCoords && | |
8635 | m_selectingBottomRight != wxGridNoCellCoords ) ); | |
f85afd4e MB |
8636 | } |
8637 | ||
b5808881 SN |
8638 | bool wxGrid::IsInSelection( int row, int col ) |
8639 | { | |
8640 | return ( m_selection->IsInSelection( row, col ) || | |
8641 | ( row >= m_selectingTopLeft.GetRow() && | |
8642 | col >= m_selectingTopLeft.GetCol() && | |
8643 | row <= m_selectingBottomRight.GetRow() && | |
8644 | col <= m_selectingBottomRight.GetCol() ) ); | |
8645 | } | |
f85afd4e MB |
8646 | |
8647 | void wxGrid::ClearSelection() | |
8648 | { | |
b5808881 SN |
8649 | m_selectingTopLeft = wxGridNoCellCoords; |
8650 | m_selectingBottomRight = wxGridNoCellCoords; | |
8651 | m_selection->ClearSelection(); | |
8f177c8e | 8652 | } |
f85afd4e MB |
8653 | |
8654 | ||
da6af900 | 8655 | // This function returns the rectangle that encloses the given block |
2d66e025 MB |
8656 | // in device coords clipped to the client size of the grid window. |
8657 | // | |
58dd5b3b MB |
8658 | wxRect wxGrid::BlockToDeviceRect( const wxGridCellCoords &topLeft, |
8659 | const wxGridCellCoords &bottomRight ) | |
f85afd4e | 8660 | { |
58dd5b3b | 8661 | wxRect rect( wxGridNoCellRect ); |
f85afd4e MB |
8662 | wxRect cellRect; |
8663 | ||
58dd5b3b MB |
8664 | cellRect = CellToRect( topLeft ); |
8665 | if ( cellRect != wxGridNoCellRect ) | |
f85afd4e | 8666 | { |
58dd5b3b MB |
8667 | rect = cellRect; |
8668 | } | |
8669 | else | |
8670 | { | |
8671 | rect = wxRect( 0, 0, 0, 0 ); | |
8672 | } | |
60ff3b99 | 8673 | |
58dd5b3b MB |
8674 | cellRect = CellToRect( bottomRight ); |
8675 | if ( cellRect != wxGridNoCellRect ) | |
8676 | { | |
8677 | rect += cellRect; | |
2d66e025 MB |
8678 | } |
8679 | else | |
8680 | { | |
8681 | return wxGridNoCellRect; | |
f85afd4e MB |
8682 | } |
8683 | ||
58dd5b3b MB |
8684 | // convert to scrolled coords |
8685 | // | |
8686 | int left, top, right, bottom; | |
8687 | CalcScrolledPosition( rect.GetLeft(), rect.GetTop(), &left, &top ); | |
8688 | CalcScrolledPosition( rect.GetRight(), rect.GetBottom(), &right, &bottom ); | |
8689 | ||
8690 | int cw, ch; | |
8691 | m_gridWin->GetClientSize( &cw, &ch ); | |
8692 | ||
f6bcfd97 BP |
8693 | if (right < 0 || bottom < 0 || left > cw || top > ch) |
8694 | return wxRect( 0, 0, 0, 0); | |
8695 | ||
58dd5b3b MB |
8696 | rect.SetLeft( wxMax(0, left) ); |
8697 | rect.SetTop( wxMax(0, top) ); | |
8698 | rect.SetRight( wxMin(cw, right) ); | |
8699 | rect.SetBottom( wxMin(ch, bottom) ); | |
8700 | ||
f85afd4e MB |
8701 | return rect; |
8702 | } | |
8703 | ||
8704 | ||
58dd5b3b | 8705 | |
f85afd4e MB |
8706 | // |
8707 | // ------ Grid event classes | |
8708 | // | |
8709 | ||
bf7945ce | 8710 | IMPLEMENT_DYNAMIC_CLASS( wxGridEvent, wxNotifyEvent ) |
f85afd4e MB |
8711 | |
8712 | wxGridEvent::wxGridEvent( int id, wxEventType type, wxObject* obj, | |
5c8fc7c1 | 8713 | int row, int col, int x, int y, bool sel, |
f85afd4e MB |
8714 | bool control, bool shift, bool alt, bool meta ) |
8715 | : wxNotifyEvent( type, id ) | |
8716 | { | |
8717 | m_row = row; | |
8718 | m_col = col; | |
8719 | m_x = x; | |
8720 | m_y = y; | |
5c8fc7c1 | 8721 | m_selecting = sel; |
f85afd4e MB |
8722 | m_control = control; |
8723 | m_shift = shift; | |
8724 | m_alt = alt; | |
8725 | m_meta = meta; | |
8f177c8e | 8726 | |
f85afd4e MB |
8727 | SetEventObject(obj); |
8728 | } | |
8729 | ||
8730 | ||
bf7945ce | 8731 | IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent, wxNotifyEvent ) |
f85afd4e MB |
8732 | |
8733 | wxGridSizeEvent::wxGridSizeEvent( int id, wxEventType type, wxObject* obj, | |
8734 | int rowOrCol, int x, int y, | |
8735 | bool control, bool shift, bool alt, bool meta ) | |
8736 | : wxNotifyEvent( type, id ) | |
8737 | { | |
8738 | m_rowOrCol = rowOrCol; | |
8739 | m_x = x; | |
8740 | m_y = y; | |
8741 | m_control = control; | |
8742 | m_shift = shift; | |
8743 | m_alt = alt; | |
8744 | m_meta = meta; | |
8f177c8e | 8745 | |
f85afd4e MB |
8746 | SetEventObject(obj); |
8747 | } | |
8748 | ||
8749 | ||
bf7945ce | 8750 | IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent, wxNotifyEvent ) |
f85afd4e MB |
8751 | |
8752 | wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj, | |
8f177c8e VZ |
8753 | const wxGridCellCoords& topLeft, |
8754 | const wxGridCellCoords& bottomRight, | |
5c8fc7c1 SN |
8755 | bool sel, bool control, |
8756 | bool shift, bool alt, bool meta ) | |
8f177c8e | 8757 | : wxNotifyEvent( type, id ) |
f85afd4e MB |
8758 | { |
8759 | m_topLeft = topLeft; | |
8760 | m_bottomRight = bottomRight; | |
5c8fc7c1 | 8761 | m_selecting = sel; |
f85afd4e MB |
8762 | m_control = control; |
8763 | m_shift = shift; | |
8764 | m_alt = alt; | |
8765 | m_meta = meta; | |
8766 | ||
8767 | SetEventObject(obj); | |
8768 | } | |
8769 | ||
8770 | ||
bf7945ce RD |
8771 | IMPLEMENT_DYNAMIC_CLASS(wxGridEditorCreatedEvent, wxCommandEvent) |
8772 | ||
8773 | wxGridEditorCreatedEvent::wxGridEditorCreatedEvent(int id, wxEventType type, | |
8774 | wxObject* obj, int row, | |
8775 | int col, wxControl* ctrl) | |
8776 | : wxCommandEvent(type, id) | |
8777 | { | |
8778 | SetEventObject(obj); | |
8779 | m_row = row; | |
8780 | m_col = col; | |
8781 | m_ctrl = ctrl; | |
8782 | } | |
8783 | ||
8784 | ||
27b92ca4 VZ |
8785 | #endif // !wxUSE_NEW_GRID/wxUSE_NEW_GRID |
8786 | ||
8787 | #endif // wxUSE_GRID | |
8788 |