]>
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) | |
97a9929e | 5 | // Modified by: Robin Dunn, Vadim Zeitlin |
f85afd4e MB |
6 | // Created: 1/08/1999 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Michael Bedward (mbedward@ozemail.com.au) | |
65571936 | 9 | // Licence: wxWindows licence |
f85afd4e MB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
758cbedf VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
f85afd4e MB |
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 | ||
f85afd4e MB |
35 | #ifndef WX_PRECOMP |
36 | #include "wx/utils.h" | |
37 | #include "wx/dcclient.h" | |
38 | #include "wx/settings.h" | |
39 | #include "wx/log.h" | |
508011ce VZ |
40 | #include "wx/textctrl.h" |
41 | #include "wx/checkbox.h" | |
4ee5fc9c | 42 | #include "wx/combobox.h" |
816be743 | 43 | #include "wx/valtext.h" |
60d876f3 | 44 | #include "wx/intl.h" |
f85afd4e MB |
45 | #endif |
46 | ||
cb5df486 | 47 | #include "wx/textfile.h" |
816be743 | 48 | #include "wx/spinctrl.h" |
c4608a8a | 49 | #include "wx/tokenzr.h" |
4d1bc39c | 50 | #include "wx/renderer.h" |
6d004f67 | 51 | |
07296f0b | 52 | #include "wx/grid.h" |
b5808881 | 53 | #include "wx/generic/gridsel.h" |
07296f0b | 54 | |
0b7e6e7d SN |
55 | #if defined(__WXMOTIF__) |
56 | #define WXUNUSED_MOTIF(identifier) WXUNUSED(identifier) | |
c78b3acd | 57 | #else |
0b7e6e7d | 58 | #define WXUNUSED_MOTIF(identifier) identifier |
c78b3acd SN |
59 | #endif |
60 | ||
61 | #if defined(__WXGTK__) | |
62 | #define WXUNUSED_GTK(identifier) WXUNUSED(identifier) | |
63 | #else | |
64 | #define WXUNUSED_GTK(identifier) identifier | |
65 | #endif | |
66 | ||
3f8e5072 JS |
67 | // Required for wxIs... functions |
68 | #include <ctype.h> | |
69 | ||
b99be8fb | 70 | // ---------------------------------------------------------------------------- |
758cbedf | 71 | // array classes |
b99be8fb VZ |
72 | // ---------------------------------------------------------------------------- |
73 | ||
d5d29b8a | 74 | WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridCellAttr *, wxArrayAttrs, |
160ba750 | 75 | class WXDLLIMPEXP_ADV); |
758cbedf | 76 | |
b99be8fb VZ |
77 | struct wxGridCellWithAttr |
78 | { | |
2e9a6788 VZ |
79 | wxGridCellWithAttr(int row, int col, wxGridCellAttr *attr_) |
80 | : coords(row, col), attr(attr_) | |
b99be8fb VZ |
81 | { |
82 | } | |
83 | ||
2e9a6788 VZ |
84 | ~wxGridCellWithAttr() |
85 | { | |
86 | attr->DecRef(); | |
87 | } | |
88 | ||
b99be8fb | 89 | wxGridCellCoords coords; |
2e9a6788 | 90 | wxGridCellAttr *attr; |
22f3361e VZ |
91 | |
92 | // Cannot do this: | |
93 | // DECLARE_NO_COPY_CLASS(wxGridCellWithAttr) | |
94 | // without rewriting the macros, which require a public copy constructor. | |
b99be8fb VZ |
95 | }; |
96 | ||
160ba750 VS |
97 | WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellWithAttr, wxGridCellWithAttrArray, |
98 | class WXDLLIMPEXP_ADV); | |
b99be8fb VZ |
99 | |
100 | #include "wx/arrimpl.cpp" | |
101 | ||
102 | WX_DEFINE_OBJARRAY(wxGridCellCoordsArray) | |
103 | WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray) | |
104 | ||
0f442030 RR |
105 | // ---------------------------------------------------------------------------- |
106 | // events | |
107 | // ---------------------------------------------------------------------------- | |
108 | ||
2e4df4bf VZ |
109 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK) |
110 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK) | |
111 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK) | |
112 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK) | |
79dbea21 | 113 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_BEGIN_DRAG) |
2e4df4bf VZ |
114 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK) |
115 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK) | |
116 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK) | |
117 | DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK) | |
118 | DEFINE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE) | |
119 | DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SIZE) | |
120 | DEFINE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT) | |
121 | DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE) | |
122 | DEFINE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL) | |
123 | DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN) | |
124 | DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN) | |
bf7945ce | 125 | DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_CREATED) |
0f442030 | 126 | |
b99be8fb VZ |
127 | // ---------------------------------------------------------------------------- |
128 | // private classes | |
129 | // ---------------------------------------------------------------------------- | |
130 | ||
12f190b0 | 131 | class WXDLLIMPEXP_ADV wxGridRowLabelWindow : public wxWindow |
b99be8fb VZ |
132 | { |
133 | public: | |
134 | wxGridRowLabelWindow() { m_owner = (wxGrid *)NULL; } | |
135 | wxGridRowLabelWindow( wxGrid *parent, wxWindowID id, | |
136 | const wxPoint &pos, const wxSize &size ); | |
137 | ||
138 | private: | |
139 | wxGrid *m_owner; | |
140 | ||
141 | void OnPaint( wxPaintEvent& event ); | |
142 | void OnMouseEvent( wxMouseEvent& event ); | |
b51c3f27 | 143 | void OnMouseWheel( wxMouseEvent& event ); |
b99be8fb | 144 | void OnKeyDown( wxKeyEvent& event ); |
f6bcfd97 | 145 | void OnKeyUp( wxKeyEvent& ); |
b99be8fb VZ |
146 | |
147 | DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow) | |
148 | DECLARE_EVENT_TABLE() | |
22f3361e | 149 | DECLARE_NO_COPY_CLASS(wxGridRowLabelWindow) |
b99be8fb VZ |
150 | }; |
151 | ||
152 | ||
12f190b0 | 153 | class WXDLLIMPEXP_ADV wxGridColLabelWindow : public wxWindow |
b99be8fb VZ |
154 | { |
155 | public: | |
156 | wxGridColLabelWindow() { m_owner = (wxGrid *)NULL; } | |
157 | wxGridColLabelWindow( wxGrid *parent, wxWindowID id, | |
158 | const wxPoint &pos, const wxSize &size ); | |
159 | ||
160 | private: | |
161 | wxGrid *m_owner; | |
162 | ||
163 | void OnPaint( wxPaintEvent &event ); | |
164 | void OnMouseEvent( wxMouseEvent& event ); | |
b51c3f27 | 165 | void OnMouseWheel( wxMouseEvent& event ); |
b99be8fb | 166 | void OnKeyDown( wxKeyEvent& event ); |
f6bcfd97 | 167 | void OnKeyUp( wxKeyEvent& ); |
b99be8fb VZ |
168 | |
169 | DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow) | |
170 | DECLARE_EVENT_TABLE() | |
22f3361e | 171 | DECLARE_NO_COPY_CLASS(wxGridColLabelWindow) |
b99be8fb VZ |
172 | }; |
173 | ||
174 | ||
12f190b0 | 175 | class WXDLLIMPEXP_ADV wxGridCornerLabelWindow : public wxWindow |
b99be8fb VZ |
176 | { |
177 | public: | |
178 | wxGridCornerLabelWindow() { m_owner = (wxGrid *)NULL; } | |
179 | wxGridCornerLabelWindow( wxGrid *parent, wxWindowID id, | |
180 | const wxPoint &pos, const wxSize &size ); | |
181 | ||
182 | private: | |
183 | wxGrid *m_owner; | |
184 | ||
185 | void OnMouseEvent( wxMouseEvent& event ); | |
b51c3f27 | 186 | void OnMouseWheel( wxMouseEvent& event ); |
b99be8fb | 187 | void OnKeyDown( wxKeyEvent& event ); |
f6bcfd97 | 188 | void OnKeyUp( wxKeyEvent& ); |
b99be8fb VZ |
189 | void OnPaint( wxPaintEvent& event ); |
190 | ||
191 | DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow) | |
192 | DECLARE_EVENT_TABLE() | |
22f3361e | 193 | DECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow) |
b99be8fb VZ |
194 | }; |
195 | ||
12f190b0 | 196 | class WXDLLIMPEXP_ADV wxGridWindow : public wxWindow |
b99be8fb VZ |
197 | { |
198 | public: | |
199 | wxGridWindow() | |
200 | { | |
201 | m_owner = (wxGrid *)NULL; | |
202 | m_rowLabelWin = (wxGridRowLabelWindow *)NULL; | |
203 | m_colLabelWin = (wxGridColLabelWindow *)NULL; | |
204 | } | |
205 | ||
206 | wxGridWindow( wxGrid *parent, | |
207 | wxGridRowLabelWindow *rowLblWin, | |
208 | wxGridColLabelWindow *colLblWin, | |
209 | wxWindowID id, const wxPoint &pos, const wxSize &size ); | |
1b941f2d | 210 | ~wxGridWindow(){} |
b99be8fb VZ |
211 | |
212 | void ScrollWindow( int dx, int dy, const wxRect *rect ); | |
213 | ||
b819b854 JS |
214 | wxGrid* GetOwner() { return m_owner; } |
215 | ||
b99be8fb VZ |
216 | private: |
217 | wxGrid *m_owner; | |
218 | wxGridRowLabelWindow *m_rowLabelWin; | |
219 | wxGridColLabelWindow *m_colLabelWin; | |
220 | ||
221 | void OnPaint( wxPaintEvent &event ); | |
b51c3f27 | 222 | void OnMouseWheel( wxMouseEvent& event ); |
b99be8fb VZ |
223 | void OnMouseEvent( wxMouseEvent& event ); |
224 | void OnKeyDown( wxKeyEvent& ); | |
f6bcfd97 | 225 | void OnKeyUp( wxKeyEvent& ); |
2796cce3 | 226 | void OnEraseBackground( wxEraseEvent& ); |
80acaf25 | 227 | void OnFocus( wxFocusEvent& ); |
b99be8fb VZ |
228 | |
229 | DECLARE_DYNAMIC_CLASS(wxGridWindow) | |
230 | DECLARE_EVENT_TABLE() | |
22f3361e | 231 | DECLARE_NO_COPY_CLASS(wxGridWindow) |
b99be8fb VZ |
232 | }; |
233 | ||
2796cce3 RD |
234 | |
235 | ||
236 | class wxGridCellEditorEvtHandler : public wxEvtHandler | |
237 | { | |
238 | public: | |
239 | wxGridCellEditorEvtHandler() | |
240 | : m_grid(0), m_editor(0) | |
241 | { } | |
242 | wxGridCellEditorEvtHandler(wxGrid* grid, wxGridCellEditor* editor) | |
243 | : m_grid(grid), m_editor(editor) | |
244 | { } | |
245 | ||
246 | void OnKeyDown(wxKeyEvent& event); | |
fb0de762 | 247 | void OnChar(wxKeyEvent& event); |
2796cce3 RD |
248 | |
249 | private: | |
250 | wxGrid* m_grid; | |
251 | wxGridCellEditor* m_editor; | |
252 | DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler) | |
253 | DECLARE_EVENT_TABLE() | |
22f3361e | 254 | DECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler) |
2796cce3 RD |
255 | }; |
256 | ||
257 | ||
258 | IMPLEMENT_DYNAMIC_CLASS( wxGridCellEditorEvtHandler, wxEvtHandler ) | |
259 | BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler, wxEvtHandler ) | |
260 | EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown ) | |
fb0de762 | 261 | EVT_CHAR( wxGridCellEditorEvtHandler::OnChar ) |
2796cce3 RD |
262 | END_EVENT_TABLE() |
263 | ||
264 | ||
265 | ||
758cbedf | 266 | // ---------------------------------------------------------------------------- |
b99be8fb | 267 | // the internal data representation used by wxGridCellAttrProvider |
758cbedf VZ |
268 | // ---------------------------------------------------------------------------- |
269 | ||
270 | // this class stores attributes set for cells | |
12f190b0 | 271 | class WXDLLIMPEXP_ADV wxGridCellAttrData |
b99be8fb VZ |
272 | { |
273 | public: | |
2e9a6788 | 274 | void SetAttr(wxGridCellAttr *attr, int row, int col); |
b99be8fb | 275 | wxGridCellAttr *GetAttr(int row, int col) const; |
4d60017a SN |
276 | void UpdateAttrRows( size_t pos, int numRows ); |
277 | void UpdateAttrCols( size_t pos, int numCols ); | |
b99be8fb VZ |
278 | |
279 | private: | |
280 | // searches for the attr for given cell, returns wxNOT_FOUND if not found | |
281 | int FindIndex(int row, int col) const; | |
282 | ||
283 | wxGridCellWithAttrArray m_attrs; | |
284 | }; | |
285 | ||
758cbedf | 286 | // this class stores attributes set for rows or columns |
12f190b0 | 287 | class WXDLLIMPEXP_ADV wxGridRowOrColAttrData |
758cbedf VZ |
288 | { |
289 | public: | |
ee6694a7 VZ |
290 | // empty ctor to suppress warnings |
291 | wxGridRowOrColAttrData() { } | |
758cbedf VZ |
292 | ~wxGridRowOrColAttrData(); |
293 | ||
294 | void SetAttr(wxGridCellAttr *attr, int rowOrCol); | |
295 | wxGridCellAttr *GetAttr(int rowOrCol) const; | |
4d60017a | 296 | void UpdateAttrRowsOrCols( size_t pos, int numRowsOrCols ); |
758cbedf VZ |
297 | |
298 | private: | |
299 | wxArrayInt m_rowsOrCols; | |
300 | wxArrayAttrs m_attrs; | |
301 | }; | |
302 | ||
303 | // NB: this is just a wrapper around 3 objects: one which stores cell | |
304 | // attributes, and 2 others for row/col ones | |
12f190b0 | 305 | class WXDLLIMPEXP_ADV wxGridCellAttrProviderData |
758cbedf VZ |
306 | { |
307 | public: | |
308 | wxGridCellAttrData m_cellAttrs; | |
309 | wxGridRowOrColAttrData m_rowAttrs, | |
310 | m_colAttrs; | |
311 | }; | |
312 | ||
f2d76237 RD |
313 | |
314 | // ---------------------------------------------------------------------------- | |
315 | // data structures used for the data type registry | |
316 | // ---------------------------------------------------------------------------- | |
317 | ||
b94ae1ea VZ |
318 | struct wxGridDataTypeInfo |
319 | { | |
f2d76237 RD |
320 | wxGridDataTypeInfo(const wxString& typeName, |
321 | wxGridCellRenderer* renderer, | |
322 | wxGridCellEditor* editor) | |
323 | : m_typeName(typeName), m_renderer(renderer), m_editor(editor) | |
324 | { } | |
325 | ||
39bcce60 VZ |
326 | ~wxGridDataTypeInfo() |
327 | { | |
328 | wxSafeDecRef(m_renderer); | |
329 | wxSafeDecRef(m_editor); | |
330 | } | |
f2d76237 RD |
331 | |
332 | wxString m_typeName; | |
333 | wxGridCellRenderer* m_renderer; | |
334 | wxGridCellEditor* m_editor; | |
22f3361e VZ |
335 | |
336 | DECLARE_NO_COPY_CLASS(wxGridDataTypeInfo) | |
f2d76237 RD |
337 | }; |
338 | ||
339 | ||
d5d29b8a | 340 | WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridDataTypeInfo*, wxGridDataTypeInfoArray, |
160ba750 | 341 | class WXDLLIMPEXP_ADV); |
f2d76237 RD |
342 | |
343 | ||
12f190b0 | 344 | class WXDLLIMPEXP_ADV wxGridTypeRegistry |
b94ae1ea | 345 | { |
f2d76237 | 346 | public: |
c78b3acd | 347 | wxGridTypeRegistry() {} |
f2d76237 | 348 | ~wxGridTypeRegistry(); |
b94ae1ea | 349 | |
f2d76237 RD |
350 | void RegisterDataType(const wxString& typeName, |
351 | wxGridCellRenderer* renderer, | |
352 | wxGridCellEditor* editor); | |
c4608a8a VZ |
353 | |
354 | // find one of already registered data types | |
355 | int FindRegisteredDataType(const wxString& typeName); | |
356 | ||
357 | // try to FindRegisteredDataType(), if this fails and typeName is one of | |
358 | // standard typenames, register it and return its index | |
f2d76237 | 359 | int FindDataType(const wxString& typeName); |
c4608a8a VZ |
360 | |
361 | // try to FindDataType(), if it fails see if it is not one of already | |
362 | // registered data types with some params in which case clone the | |
363 | // registered data type and set params for it | |
364 | int FindOrCloneDataType(const wxString& typeName); | |
365 | ||
f2d76237 RD |
366 | wxGridCellRenderer* GetRenderer(int index); |
367 | wxGridCellEditor* GetEditor(int index); | |
368 | ||
369 | private: | |
370 | wxGridDataTypeInfoArray m_typeinfo; | |
371 | }; | |
372 | ||
b99be8fb VZ |
373 | // ---------------------------------------------------------------------------- |
374 | // conditional compilation | |
375 | // ---------------------------------------------------------------------------- | |
376 | ||
9496deb5 MB |
377 | #ifndef WXGRID_DRAW_LINES |
378 | #define WXGRID_DRAW_LINES 1 | |
796df70a SN |
379 | #endif |
380 | ||
0a976765 VZ |
381 | // ---------------------------------------------------------------------------- |
382 | // globals | |
383 | // ---------------------------------------------------------------------------- | |
384 | ||
385 | //#define DEBUG_ATTR_CACHE | |
386 | #ifdef DEBUG_ATTR_CACHE | |
387 | static size_t gs_nAttrCacheHits = 0; | |
388 | static size_t gs_nAttrCacheMisses = 0; | |
389 | #endif // DEBUG_ATTR_CACHE | |
f85afd4e | 390 | |
43947979 VZ |
391 | // ---------------------------------------------------------------------------- |
392 | // constants | |
393 | // ---------------------------------------------------------------------------- | |
394 | ||
f85afd4e MB |
395 | wxGridCellCoords wxGridNoCellCoords( -1, -1 ); |
396 | wxRect wxGridNoCellRect( -1, -1, -1, -1 ); | |
397 | ||
f0102d2a | 398 | // scroll line size |
faec5a43 SN |
399 | // TODO: this doesn't work at all, grid cells have different sizes and approx |
400 | // calculations don't work as because of the size mismatch scrollbars | |
401 | // sometimes fail to be shown when they should be or vice versa | |
b51c3f27 RD |
402 | // |
403 | // The scroll bars may be a little flakey once in a while, but that is | |
404 | // surely much less horrible than having scroll lines of only 1!!! | |
405 | // -- Robin | |
97a9929e VZ |
406 | // |
407 | // Well, it's still seriously broken so it might be better but needs | |
408 | // fixing anyhow | |
409 | // -- Vadim | |
410 | static const size_t GRID_SCROLL_LINE_X = 15; // 1; | |
411 | static const size_t GRID_SCROLL_LINE_Y = GRID_SCROLL_LINE_X; | |
f85afd4e | 412 | |
43947979 VZ |
413 | // the size of hash tables used a bit everywhere (the max number of elements |
414 | // in these hash tables is the number of rows/columns) | |
415 | static const int GRID_HASH_SIZE = 100; | |
416 | ||
608754c4 | 417 | #if 0 |
97a9929e VZ |
418 | // ---------------------------------------------------------------------------- |
419 | // private functions | |
420 | // ---------------------------------------------------------------------------- | |
421 | ||
d0eb7e56 | 422 | static inline int GetScrollX(int x) |
97a9929e VZ |
423 | { |
424 | return (x + GRID_SCROLL_LINE_X - 1) / GRID_SCROLL_LINE_X; | |
425 | } | |
426 | ||
d0eb7e56 | 427 | static inline int GetScrollY(int y) |
97a9929e VZ |
428 | { |
429 | return (y + GRID_SCROLL_LINE_Y - 1) / GRID_SCROLL_LINE_Y; | |
430 | } | |
608754c4 | 431 | #endif |
97a9929e | 432 | |
ab79958a VZ |
433 | // ============================================================================ |
434 | // implementation | |
435 | // ============================================================================ | |
436 | ||
2796cce3 RD |
437 | // ---------------------------------------------------------------------------- |
438 | // wxGridCellEditor | |
439 | // ---------------------------------------------------------------------------- | |
440 | ||
441 | wxGridCellEditor::wxGridCellEditor() | |
442 | { | |
443 | m_control = NULL; | |
1bd71df9 | 444 | m_attr = NULL; |
2796cce3 RD |
445 | } |
446 | ||
447 | ||
448 | wxGridCellEditor::~wxGridCellEditor() | |
449 | { | |
450 | Destroy(); | |
451 | } | |
452 | ||
508011ce VZ |
453 | void wxGridCellEditor::Create(wxWindow* WXUNUSED(parent), |
454 | wxWindowID WXUNUSED(id), | |
455 | wxEvtHandler* evtHandler) | |
456 | { | |
189d0213 | 457 | if ( evtHandler ) |
508011ce VZ |
458 | m_control->PushEventHandler(evtHandler); |
459 | } | |
2796cce3 | 460 | |
189d0213 VZ |
461 | void wxGridCellEditor::PaintBackground(const wxRect& rectCell, |
462 | wxGridCellAttr *attr) | |
463 | { | |
464 | // erase the background because we might not fill the cell | |
465 | wxClientDC dc(m_control->GetParent()); | |
b819b854 JS |
466 | wxGridWindow* gridWindow = wxDynamicCast(m_control->GetParent(), wxGridWindow); |
467 | if (gridWindow) | |
468 | gridWindow->GetOwner()->PrepareDC(dc); | |
ef5df12b | 469 | |
189d0213 VZ |
470 | dc.SetPen(*wxTRANSPARENT_PEN); |
471 | dc.SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID)); | |
472 | dc.DrawRectangle(rectCell); | |
473 | ||
474 | // redraw the control we just painted over | |
475 | m_control->Refresh(); | |
476 | } | |
477 | ||
2796cce3 RD |
478 | void wxGridCellEditor::Destroy() |
479 | { | |
508011ce VZ |
480 | if (m_control) |
481 | { | |
ca65c044 | 482 | m_control->PopEventHandler(true /* delete it*/); |
b94ae1ea | 483 | |
2796cce3 RD |
484 | m_control->Destroy(); |
485 | m_control = NULL; | |
486 | } | |
487 | } | |
488 | ||
3da93aae | 489 | void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr) |
2796cce3 RD |
490 | { |
491 | wxASSERT_MSG(m_control, | |
492 | wxT("The wxGridCellEditor must be Created first!")); | |
493 | m_control->Show(show); | |
3da93aae VZ |
494 | |
495 | if ( show ) | |
496 | { | |
497 | // set the colours/fonts if we have any | |
498 | if ( attr ) | |
499 | { | |
f2d76237 RD |
500 | m_colFgOld = m_control->GetForegroundColour(); |
501 | m_control->SetForegroundColour(attr->GetTextColour()); | |
3da93aae | 502 | |
f2d76237 RD |
503 | m_colBgOld = m_control->GetBackgroundColour(); |
504 | m_control->SetBackgroundColour(attr->GetBackgroundColour()); | |
3da93aae | 505 | |
0e871ad0 | 506 | // Workaround for GTK+1 font setting problem on some platforms |
ea2d542c | 507 | #if !defined(__WXGTK__) || defined(__WXGTK20__) |
f2d76237 RD |
508 | m_fontOld = m_control->GetFont(); |
509 | m_control->SetFont(attr->GetFont()); | |
ea2d542c | 510 | #endif |
3da93aae VZ |
511 | // can't do anything more in the base class version, the other |
512 | // attributes may only be used by the derived classes | |
513 | } | |
514 | } | |
515 | else | |
516 | { | |
517 | // restore the standard colours fonts | |
518 | if ( m_colFgOld.Ok() ) | |
519 | { | |
520 | m_control->SetForegroundColour(m_colFgOld); | |
521 | m_colFgOld = wxNullColour; | |
522 | } | |
523 | ||
524 | if ( m_colBgOld.Ok() ) | |
525 | { | |
526 | m_control->SetBackgroundColour(m_colBgOld); | |
527 | m_colBgOld = wxNullColour; | |
528 | } | |
0e871ad0 | 529 | // Workaround for GTK+1 font setting problem on some platforms |
ea2d542c | 530 | #if !defined(__WXGTK__) || defined(__WXGTK20__) |
3da93aae VZ |
531 | if ( m_fontOld.Ok() ) |
532 | { | |
533 | m_control->SetFont(m_fontOld); | |
534 | m_fontOld = wxNullFont; | |
535 | } | |
ea2d542c | 536 | #endif |
3da93aae | 537 | } |
2796cce3 RD |
538 | } |
539 | ||
540 | void wxGridCellEditor::SetSize(const wxRect& rect) | |
541 | { | |
542 | wxASSERT_MSG(m_control, | |
543 | wxT("The wxGridCellEditor must be Created first!")); | |
28a77bc4 | 544 | m_control->SetSize(rect, wxSIZE_ALLOW_MINUS_ONE); |
2796cce3 RD |
545 | } |
546 | ||
547 | void wxGridCellEditor::HandleReturn(wxKeyEvent& event) | |
548 | { | |
549 | event.Skip(); | |
550 | } | |
551 | ||
f6bcfd97 BP |
552 | bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event) |
553 | { | |
554 | // accept the simple key presses, not anything with Ctrl/Alt/Meta | |
a4f7bf58 | 555 | return !(event.ControlDown() || event.AltDown()); |
f6bcfd97 | 556 | } |
2796cce3 | 557 | |
2c9a89e0 RD |
558 | void wxGridCellEditor::StartingKey(wxKeyEvent& event) |
559 | { | |
e195a54c VZ |
560 | event.Skip(); |
561 | } | |
2c9a89e0 | 562 | |
e195a54c VZ |
563 | void wxGridCellEditor::StartingClick() |
564 | { | |
b54ba671 | 565 | } |
2c9a89e0 | 566 | |
3a8c693a VZ |
567 | #if wxUSE_TEXTCTRL |
568 | ||
b54ba671 VZ |
569 | // ---------------------------------------------------------------------------- |
570 | // wxGridCellTextEditor | |
571 | // ---------------------------------------------------------------------------- | |
2c9a89e0 | 572 | |
2796cce3 RD |
573 | wxGridCellTextEditor::wxGridCellTextEditor() |
574 | { | |
c4608a8a | 575 | m_maxChars = 0; |
2796cce3 RD |
576 | } |
577 | ||
578 | void wxGridCellTextEditor::Create(wxWindow* parent, | |
579 | wxWindowID id, | |
2796cce3 RD |
580 | wxEvtHandler* evtHandler) |
581 | { | |
508011ce | 582 | m_control = new wxTextCtrl(parent, id, wxEmptyString, |
2c9a89e0 | 583 | wxDefaultPosition, wxDefaultSize |
2796cce3 | 584 | #if defined(__WXMSW__) |
aaae069f | 585 | , wxTE_PROCESS_TAB | wxTE_AUTO_SCROLL |
2796cce3 | 586 | #endif |
508011ce | 587 | ); |
2796cce3 | 588 | |
46a5010a RD |
589 | // set max length allowed in the textctrl, if the parameter was set |
590 | if (m_maxChars != 0) | |
591 | { | |
592 | ((wxTextCtrl*)m_control)->SetMaxLength(m_maxChars); | |
593 | } | |
c4608a8a | 594 | |
508011ce | 595 | wxGridCellEditor::Create(parent, id, evtHandler); |
2796cce3 RD |
596 | } |
597 | ||
189d0213 VZ |
598 | void wxGridCellTextEditor::PaintBackground(const wxRect& WXUNUSED(rectCell), |
599 | wxGridCellAttr * WXUNUSED(attr)) | |
600 | { | |
601 | // as we fill the entire client area, don't do anything here to minimize | |
602 | // flicker | |
603 | } | |
2796cce3 | 604 | |
99306db2 VZ |
605 | void wxGridCellTextEditor::SetSize(const wxRect& rectOrig) |
606 | { | |
607 | wxRect rect(rectOrig); | |
608 | ||
609 | // Make the edit control large enough to allow for internal | |
610 | // margins | |
611 | // | |
612 | // TODO: remove this if the text ctrl sizing is improved esp. for | |
613 | // unix | |
614 | // | |
615 | #if defined(__WXGTK__) | |
b0e282b3 RR |
616 | if (rect.x != 0) |
617 | { | |
618 | rect.x += 1; | |
619 | rect.y += 1; | |
620 | rect.width -= 1; | |
621 | rect.height -= 1; | |
622 | } | |
99306db2 | 623 | #else // !GTK |
cb105ad4 | 624 | int extra_x = ( rect.x > 2 )? 2 : 1; |
84912ef8 RD |
625 | |
626 | // MB: treat MSW separately here otherwise the caret doesn't show | |
627 | // when the editor is in the first row. | |
a0948e27 MB |
628 | #if defined(__WXMSW__) |
629 | int extra_y = 2; | |
630 | #else | |
cb105ad4 | 631 | int extra_y = ( rect.y > 2 )? 2 : 1; |
a0948e27 MB |
632 | #endif // MSW |
633 | ||
99306db2 | 634 | #if defined(__WXMOTIF__) |
cb105ad4 SN |
635 | extra_x *= 2; |
636 | extra_y *= 2; | |
99306db2 | 637 | #endif |
cb105ad4 SN |
638 | rect.SetLeft( wxMax(0, rect.x - extra_x) ); |
639 | rect.SetTop( wxMax(0, rect.y - extra_y) ); | |
640 | rect.SetRight( rect.GetRight() + 2*extra_x ); | |
641 | rect.SetBottom( rect.GetBottom() + 2*extra_y ); | |
99306db2 VZ |
642 | #endif // GTK/!GTK |
643 | ||
644 | wxGridCellEditor::SetSize(rect); | |
645 | } | |
646 | ||
3da93aae | 647 | void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid) |
2796cce3 RD |
648 | { |
649 | wxASSERT_MSG(m_control, | |
650 | wxT("The wxGridCellEditor must be Created first!")); | |
651 | ||
652 | m_startValue = grid->GetTable()->GetValue(row, col); | |
816be743 VZ |
653 | |
654 | DoBeginEdit(m_startValue); | |
655 | } | |
656 | ||
657 | void wxGridCellTextEditor::DoBeginEdit(const wxString& startValue) | |
658 | { | |
659 | Text()->SetValue(startValue); | |
b54ba671 | 660 | Text()->SetInsertionPointEnd(); |
505f70de | 661 | Text()->SetSelection(-1,-1); |
b54ba671 | 662 | Text()->SetFocus(); |
2796cce3 RD |
663 | } |
664 | ||
3324d5f5 | 665 | bool wxGridCellTextEditor::EndEdit(int row, int col, |
3da93aae | 666 | wxGrid* grid) |
2796cce3 RD |
667 | { |
668 | wxASSERT_MSG(m_control, | |
669 | wxT("The wxGridCellEditor must be Created first!")); | |
670 | ||
ca65c044 | 671 | bool changed = false; |
b54ba671 | 672 | wxString value = Text()->GetValue(); |
2796cce3 | 673 | if (value != m_startValue) |
ca65c044 | 674 | changed = true; |
2796cce3 RD |
675 | |
676 | if (changed) | |
677 | grid->GetTable()->SetValue(row, col, value); | |
2c9a89e0 | 678 | |
3da93aae | 679 | m_startValue = wxEmptyString; |
7b519e5e JS |
680 | // No point in setting the text of the hidden control |
681 | //Text()->SetValue(m_startValue); | |
2796cce3 RD |
682 | |
683 | return changed; | |
684 | } | |
685 | ||
686 | ||
687 | void wxGridCellTextEditor::Reset() | |
688 | { | |
689 | wxASSERT_MSG(m_control, | |
690 | wxT("The wxGridCellEditor must be Created first!")); | |
691 | ||
816be743 VZ |
692 | DoReset(m_startValue); |
693 | } | |
694 | ||
695 | void wxGridCellTextEditor::DoReset(const wxString& startValue) | |
696 | { | |
697 | Text()->SetValue(startValue); | |
b54ba671 | 698 | Text()->SetInsertionPointEnd(); |
2796cce3 RD |
699 | } |
700 | ||
f6bcfd97 BP |
701 | bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event) |
702 | { | |
703 | if ( wxGridCellEditor::IsAcceptedKey(event) ) | |
704 | { | |
705 | int keycode = event.GetKeyCode(); | |
706 | switch ( keycode ) | |
707 | { | |
708 | case WXK_NUMPAD0: | |
709 | case WXK_NUMPAD1: | |
710 | case WXK_NUMPAD2: | |
711 | case WXK_NUMPAD3: | |
712 | case WXK_NUMPAD4: | |
713 | case WXK_NUMPAD5: | |
714 | case WXK_NUMPAD6: | |
715 | case WXK_NUMPAD7: | |
716 | case WXK_NUMPAD8: | |
717 | case WXK_NUMPAD9: | |
718 | case WXK_MULTIPLY: | |
719 | case WXK_NUMPAD_MULTIPLY: | |
720 | case WXK_ADD: | |
721 | case WXK_NUMPAD_ADD: | |
722 | case WXK_SUBTRACT: | |
723 | case WXK_NUMPAD_SUBTRACT: | |
724 | case WXK_DECIMAL: | |
725 | case WXK_NUMPAD_DECIMAL: | |
726 | case WXK_DIVIDE: | |
727 | case WXK_NUMPAD_DIVIDE: | |
ca65c044 | 728 | return true; |
f6bcfd97 BP |
729 | |
730 | default: | |
731 | // accept 8 bit chars too if isprint() agrees | |
0c6099b7 | 732 | if ( (keycode < 255) && (wxIsprint(keycode)) ) |
ca65c044 | 733 | return true; |
f6bcfd97 BP |
734 | } |
735 | } | |
736 | ||
ca65c044 | 737 | return false; |
f6bcfd97 BP |
738 | } |
739 | ||
2c9a89e0 RD |
740 | void wxGridCellTextEditor::StartingKey(wxKeyEvent& event) |
741 | { | |
94af7d45 | 742 | if ( !Text()->EmulateKeyPress(event) ) |
f6bcfd97 BP |
743 | { |
744 | event.Skip(); | |
745 | } | |
b54ba671 | 746 | } |
2c9a89e0 | 747 | |
c78b3acd | 748 | void wxGridCellTextEditor::HandleReturn( wxKeyEvent& |
0b7e6e7d | 749 | WXUNUSED_GTK(WXUNUSED_MOTIF(event)) ) |
2796cce3 RD |
750 | { |
751 | #if defined(__WXMOTIF__) || defined(__WXGTK__) | |
752 | // wxMotif needs a little extra help... | |
6fc0f38f | 753 | size_t pos = (size_t)( Text()->GetInsertionPoint() ); |
b54ba671 | 754 | wxString s( Text()->GetValue() ); |
8dd8f875 | 755 | s = s.Left(pos) + wxT("\n") + s.Mid(pos); |
b54ba671 VZ |
756 | Text()->SetValue(s); |
757 | Text()->SetInsertionPoint( pos ); | |
2796cce3 RD |
758 | #else |
759 | // the other ports can handle a Return key press | |
760 | // | |
761 | event.Skip(); | |
762 | #endif | |
763 | } | |
764 | ||
c4608a8a VZ |
765 | void wxGridCellTextEditor::SetParameters(const wxString& params) |
766 | { | |
767 | if ( !params ) | |
768 | { | |
769 | // reset to default | |
770 | m_maxChars = 0; | |
771 | } | |
772 | else | |
773 | { | |
774 | long tmp; | |
775 | if ( !params.ToLong(&tmp) ) | |
776 | { | |
f6bcfd97 | 777 | wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params.c_str()); |
c4608a8a VZ |
778 | } |
779 | else | |
780 | { | |
781 | m_maxChars = (size_t)tmp; | |
782 | } | |
783 | } | |
784 | } | |
785 | ||
73145b0e JS |
786 | // return the value in the text control |
787 | wxString wxGridCellTextEditor::GetValue() const | |
788 | { | |
789 | return Text()->GetValue(); | |
790 | } | |
791 | ||
816be743 VZ |
792 | // ---------------------------------------------------------------------------- |
793 | // wxGridCellNumberEditor | |
794 | // ---------------------------------------------------------------------------- | |
795 | ||
796 | wxGridCellNumberEditor::wxGridCellNumberEditor(int min, int max) | |
797 | { | |
798 | m_min = min; | |
799 | m_max = max; | |
800 | } | |
801 | ||
802 | void wxGridCellNumberEditor::Create(wxWindow* parent, | |
803 | wxWindowID id, | |
804 | wxEvtHandler* evtHandler) | |
805 | { | |
0e871ad0 | 806 | #if wxUSE_SPINCTRL |
816be743 VZ |
807 | if ( HasRange() ) |
808 | { | |
809 | // create a spin ctrl | |
ca65c044 | 810 | m_control = new wxSpinCtrl(parent, wxID_ANY, wxEmptyString, |
816be743 VZ |
811 | wxDefaultPosition, wxDefaultSize, |
812 | wxSP_ARROW_KEYS, | |
813 | m_min, m_max); | |
814 | ||
815 | wxGridCellEditor::Create(parent, id, evtHandler); | |
816 | } | |
817 | else | |
0e871ad0 | 818 | #endif |
816be743 VZ |
819 | { |
820 | // just a text control | |
821 | wxGridCellTextEditor::Create(parent, id, evtHandler); | |
822 | ||
823 | #if wxUSE_VALIDATORS | |
85bc0351 | 824 | Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); |
816be743 VZ |
825 | #endif // wxUSE_VALIDATORS |
826 | } | |
827 | } | |
828 | ||
829 | void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid) | |
830 | { | |
831 | // first get the value | |
832 | wxGridTableBase *table = grid->GetTable(); | |
833 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) ) | |
834 | { | |
835 | m_valueOld = table->GetValueAsLong(row, col); | |
836 | } | |
837 | else | |
838 | { | |
8a60ff0a | 839 | m_valueOld = 0; |
a5777624 | 840 | wxString sValue = table->GetValue(row, col); |
0e871ad0 | 841 | if (! sValue.ToLong(&m_valueOld) && ! sValue.empty()) |
a5777624 RD |
842 | { |
843 | wxFAIL_MSG( _T("this cell doesn't have numeric value") ); | |
844 | return; | |
845 | } | |
816be743 VZ |
846 | } |
847 | ||
0e871ad0 | 848 | #if wxUSE_SPINCTRL |
816be743 VZ |
849 | if ( HasRange() ) |
850 | { | |
4a64bee4 | 851 | Spin()->SetValue((int)m_valueOld); |
f6bcfd97 | 852 | Spin()->SetFocus(); |
816be743 VZ |
853 | } |
854 | else | |
0e871ad0 | 855 | #endif |
816be743 VZ |
856 | { |
857 | DoBeginEdit(GetString()); | |
858 | } | |
859 | } | |
860 | ||
3324d5f5 | 861 | bool wxGridCellNumberEditor::EndEdit(int row, int col, |
816be743 VZ |
862 | wxGrid* grid) |
863 | { | |
864 | bool changed; | |
8a60ff0a RD |
865 | long value = 0; |
866 | wxString text; | |
816be743 | 867 | |
0e871ad0 | 868 | #if wxUSE_SPINCTRL |
816be743 VZ |
869 | if ( HasRange() ) |
870 | { | |
871 | value = Spin()->GetValue(); | |
872 | changed = value != m_valueOld; | |
8a60ff0a RD |
873 | if (changed) |
874 | text = wxString::Format(wxT("%ld"), value); | |
816be743 VZ |
875 | } |
876 | else | |
0e871ad0 | 877 | #endif |
816be743 | 878 | { |
8a60ff0a | 879 | text = Text()->GetValue(); |
0e871ad0 | 880 | changed = (text.empty() || text.ToLong(&value)) && (value != m_valueOld); |
816be743 VZ |
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 | |
8a60ff0a | 888 | grid->GetTable()->SetValue(row, col, text); |
816be743 VZ |
889 | } |
890 | ||
891 | return changed; | |
892 | } | |
893 | ||
894 | void wxGridCellNumberEditor::Reset() | |
895 | { | |
0e871ad0 | 896 | #if wxUSE_SPINCTRL |
816be743 VZ |
897 | if ( HasRange() ) |
898 | { | |
4a64bee4 | 899 | Spin()->SetValue((int)m_valueOld); |
816be743 VZ |
900 | } |
901 | else | |
0e871ad0 | 902 | #endif |
816be743 VZ |
903 | { |
904 | DoReset(GetString()); | |
905 | } | |
906 | } | |
907 | ||
f6bcfd97 BP |
908 | bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent& event) |
909 | { | |
910 | if ( wxGridCellEditor::IsAcceptedKey(event) ) | |
911 | { | |
912 | int keycode = event.GetKeyCode(); | |
913 | switch ( keycode ) | |
914 | { | |
915 | case WXK_NUMPAD0: | |
916 | case WXK_NUMPAD1: | |
917 | case WXK_NUMPAD2: | |
918 | case WXK_NUMPAD3: | |
919 | case WXK_NUMPAD4: | |
920 | case WXK_NUMPAD5: | |
921 | case WXK_NUMPAD6: | |
922 | case WXK_NUMPAD7: | |
923 | case WXK_NUMPAD8: | |
924 | case WXK_NUMPAD9: | |
925 | case WXK_ADD: | |
926 | case WXK_NUMPAD_ADD: | |
927 | case WXK_SUBTRACT: | |
928 | case WXK_NUMPAD_SUBTRACT: | |
929 | case WXK_UP: | |
930 | case WXK_DOWN: | |
ca65c044 | 931 | return true; |
f6bcfd97 BP |
932 | |
933 | default: | |
0c6099b7 | 934 | if ( (keycode < 128) && wxIsdigit(keycode) ) |
ca65c044 | 935 | return true; |
f6bcfd97 BP |
936 | } |
937 | } | |
938 | ||
ca65c044 | 939 | return false; |
f6bcfd97 BP |
940 | } |
941 | ||
816be743 VZ |
942 | void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event) |
943 | { | |
944 | if ( !HasRange() ) | |
945 | { | |
12a3f227 | 946 | int keycode = event.GetKeyCode(); |
0c6099b7 | 947 | if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-' |
85d8c319 JS |
948 | || keycode == WXK_NUMPAD0 |
949 | || keycode == WXK_NUMPAD1 | |
950 | || keycode == WXK_NUMPAD2 | |
951 | || keycode == WXK_NUMPAD3 | |
952 | || keycode == WXK_NUMPAD4 | |
953 | || keycode == WXK_NUMPAD5 | |
954 | || keycode == WXK_NUMPAD6 | |
955 | || keycode == WXK_NUMPAD7 | |
956 | || keycode == WXK_NUMPAD8 | |
957 | || keycode == WXK_NUMPAD9 | |
958 | || keycode == WXK_ADD | |
959 | || keycode == WXK_NUMPAD_ADD | |
960 | || keycode == WXK_SUBTRACT | |
961 | || keycode == WXK_NUMPAD_SUBTRACT) | |
816be743 VZ |
962 | { |
963 | wxGridCellTextEditor::StartingKey(event); | |
964 | ||
965 | // skip Skip() below | |
966 | return; | |
967 | } | |
968 | } | |
969 | ||
970 | event.Skip(); | |
971 | } | |
9c4ba614 | 972 | |
c4608a8a VZ |
973 | void wxGridCellNumberEditor::SetParameters(const wxString& params) |
974 | { | |
975 | if ( !params ) | |
976 | { | |
977 | // reset to default | |
978 | m_min = | |
979 | m_max = -1; | |
980 | } | |
981 | else | |
982 | { | |
983 | long tmp; | |
984 | if ( params.BeforeFirst(_T(',')).ToLong(&tmp) ) | |
985 | { | |
986 | m_min = (int)tmp; | |
987 | ||
988 | if ( params.AfterFirst(_T(',')).ToLong(&tmp) ) | |
989 | { | |
990 | m_max = (int)tmp; | |
991 | ||
992 | // skip the error message below | |
993 | return; | |
994 | } | |
995 | } | |
996 | ||
f6bcfd97 | 997 | wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params.c_str()); |
c4608a8a VZ |
998 | } |
999 | } | |
1000 | ||
73145b0e JS |
1001 | // return the value in the spin control if it is there (the text control otherwise) |
1002 | wxString wxGridCellNumberEditor::GetValue() const | |
1003 | { | |
0e871ad0 WS |
1004 | wxString s; |
1005 | ||
1006 | #if wxUSE_SPINCTRL | |
1007 | if( HasRange() ) | |
1008 | { | |
1009 | long value = Spin()->GetValue(); | |
1010 | s.Printf(wxT("%ld"), value); | |
1011 | } | |
1012 | else | |
1013 | #endif | |
1014 | { | |
1015 | s = Text()->GetValue(); | |
1016 | } | |
1017 | ||
1018 | return s; | |
73145b0e JS |
1019 | } |
1020 | ||
816be743 VZ |
1021 | // ---------------------------------------------------------------------------- |
1022 | // wxGridCellFloatEditor | |
1023 | // ---------------------------------------------------------------------------- | |
1024 | ||
f6bcfd97 BP |
1025 | wxGridCellFloatEditor::wxGridCellFloatEditor(int width, int precision) |
1026 | { | |
1027 | m_width = width; | |
1028 | m_precision = precision; | |
1029 | } | |
1030 | ||
816be743 VZ |
1031 | void wxGridCellFloatEditor::Create(wxWindow* parent, |
1032 | wxWindowID id, | |
1033 | wxEvtHandler* evtHandler) | |
1034 | { | |
1035 | wxGridCellTextEditor::Create(parent, id, evtHandler); | |
1036 | ||
1037 | #if wxUSE_VALIDATORS | |
85bc0351 | 1038 | Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); |
816be743 VZ |
1039 | #endif // wxUSE_VALIDATORS |
1040 | } | |
1041 | ||
1042 | void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid) | |
1043 | { | |
1044 | // first get the value | |
1045 | wxGridTableBase *table = grid->GetTable(); | |
1046 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) ) | |
1047 | { | |
1048 | m_valueOld = table->GetValueAsDouble(row, col); | |
1049 | } | |
1050 | else | |
1051 | { | |
8a60ff0a | 1052 | m_valueOld = 0.0; |
a5777624 | 1053 | wxString sValue = table->GetValue(row, col); |
0e871ad0 | 1054 | if (! sValue.ToDouble(&m_valueOld) && ! sValue.empty()) |
a5777624 RD |
1055 | { |
1056 | wxFAIL_MSG( _T("this cell doesn't have float value") ); | |
1057 | return; | |
1058 | } | |
816be743 VZ |
1059 | } |
1060 | ||
1061 | DoBeginEdit(GetString()); | |
1062 | } | |
1063 | ||
3324d5f5 | 1064 | bool wxGridCellFloatEditor::EndEdit(int row, int col, |
816be743 VZ |
1065 | wxGrid* grid) |
1066 | { | |
8a60ff0a RD |
1067 | double value = 0.0; |
1068 | wxString text(Text()->GetValue()); | |
1069 | ||
0e871ad0 | 1070 | if ( (text.empty() || text.ToDouble(&value)) && (value != m_valueOld) ) |
816be743 | 1071 | { |
a5777624 RD |
1072 | if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT)) |
1073 | grid->GetTable()->SetValueAsDouble(row, col, value); | |
1074 | else | |
8a60ff0a | 1075 | grid->GetTable()->SetValue(row, col, text); |
816be743 | 1076 | |
ca65c044 | 1077 | return true; |
816be743 | 1078 | } |
ca65c044 | 1079 | return false; |
816be743 VZ |
1080 | } |
1081 | ||
1082 | void wxGridCellFloatEditor::Reset() | |
1083 | { | |
1084 | DoReset(GetString()); | |
1085 | } | |
1086 | ||
1087 | void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event) | |
1088 | { | |
12a3f227 | 1089 | int keycode = event.GetKeyCode(); |
3fe73755 SN |
1090 | char tmpbuf[2]; |
1091 | tmpbuf[0] = (char) keycode; | |
1092 | tmpbuf[1] = '\0'; | |
42841dfc WS |
1093 | wxString strbuf(tmpbuf, *wxConvCurrent); |
1094 | bool is_decimal_point = ( strbuf == | |
3fe73755 | 1095 | wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER) ); |
0c6099b7 | 1096 | if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-' |
3fe73755 | 1097 | || is_decimal_point |
85d8c319 JS |
1098 | || keycode == WXK_NUMPAD0 |
1099 | || keycode == WXK_NUMPAD1 | |
1100 | || keycode == WXK_NUMPAD2 | |
1101 | || keycode == WXK_NUMPAD3 | |
1102 | || keycode == WXK_NUMPAD4 | |
1103 | || keycode == WXK_NUMPAD5 | |
1104 | || keycode == WXK_NUMPAD6 | |
1105 | || keycode == WXK_NUMPAD7 | |
1106 | || keycode == WXK_NUMPAD8 | |
1107 | || keycode == WXK_NUMPAD9 | |
1108 | || keycode == WXK_ADD | |
1109 | || keycode == WXK_NUMPAD_ADD | |
1110 | || keycode == WXK_SUBTRACT | |
1111 | || keycode == WXK_NUMPAD_SUBTRACT) | |
816be743 VZ |
1112 | { |
1113 | wxGridCellTextEditor::StartingKey(event); | |
1114 | ||
1115 | // skip Skip() below | |
1116 | return; | |
1117 | } | |
1118 | ||
1119 | event.Skip(); | |
1120 | } | |
1121 | ||
f6bcfd97 BP |
1122 | void wxGridCellFloatEditor::SetParameters(const wxString& params) |
1123 | { | |
1124 | if ( !params ) | |
1125 | { | |
1126 | // reset to default | |
1127 | m_width = | |
1128 | m_precision = -1; | |
1129 | } | |
1130 | else | |
1131 | { | |
1132 | long tmp; | |
1133 | if ( params.BeforeFirst(_T(',')).ToLong(&tmp) ) | |
1134 | { | |
1135 | m_width = (int)tmp; | |
1136 | ||
1137 | if ( params.AfterFirst(_T(',')).ToLong(&tmp) ) | |
1138 | { | |
1139 | m_precision = (int)tmp; | |
1140 | ||
1141 | // skip the error message below | |
1142 | return; | |
1143 | } | |
1144 | } | |
1145 | ||
1146 | wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params.c_str()); | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | wxString wxGridCellFloatEditor::GetString() const | |
1151 | { | |
1152 | wxString fmt; | |
1153 | if ( m_width == -1 ) | |
1154 | { | |
1155 | // default width/precision | |
ec53826c | 1156 | fmt = _T("%f"); |
f6bcfd97 BP |
1157 | } |
1158 | else if ( m_precision == -1 ) | |
1159 | { | |
1160 | // default precision | |
ec53826c | 1161 | fmt.Printf(_T("%%%d.f"), m_width); |
f6bcfd97 BP |
1162 | } |
1163 | else | |
1164 | { | |
ec53826c | 1165 | fmt.Printf(_T("%%%d.%df"), m_width, m_precision); |
f6bcfd97 BP |
1166 | } |
1167 | ||
1168 | return wxString::Format(fmt, m_valueOld); | |
1169 | } | |
1170 | ||
1171 | bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event) | |
1172 | { | |
1173 | if ( wxGridCellEditor::IsAcceptedKey(event) ) | |
1174 | { | |
1175 | int keycode = event.GetKeyCode(); | |
1176 | switch ( keycode ) | |
1177 | { | |
1178 | case WXK_NUMPAD0: | |
1179 | case WXK_NUMPAD1: | |
1180 | case WXK_NUMPAD2: | |
1181 | case WXK_NUMPAD3: | |
1182 | case WXK_NUMPAD4: | |
1183 | case WXK_NUMPAD5: | |
1184 | case WXK_NUMPAD6: | |
1185 | case WXK_NUMPAD7: | |
1186 | case WXK_NUMPAD8: | |
1187 | case WXK_NUMPAD9: | |
1188 | case WXK_ADD: | |
1189 | case WXK_NUMPAD_ADD: | |
1190 | case WXK_SUBTRACT: | |
1191 | case WXK_NUMPAD_SUBTRACT: | |
1192 | case WXK_DECIMAL: | |
1193 | case WXK_NUMPAD_DECIMAL: | |
ca65c044 | 1194 | return true; |
f6bcfd97 | 1195 | |
ca65c044 | 1196 | default: |
3fe73755 SN |
1197 | { |
1198 | // additionally accept 'e' as in '1e+6', also '-', '+', and '.' | |
1199 | char tmpbuf[2]; | |
1200 | tmpbuf[0] = (char) keycode; | |
1201 | tmpbuf[1] = '\0'; | |
8253f2e0 | 1202 | wxString strbuf(tmpbuf, *wxConvCurrent); |
0e871ad0 | 1203 | bool is_decimal_point = |
8253f2e0 WS |
1204 | ( strbuf == wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, |
1205 | wxLOCALE_CAT_NUMBER) ); | |
f6bcfd97 | 1206 | if ( (keycode < 128) && |
0c6099b7 | 1207 | (wxIsdigit(keycode) || tolower(keycode) == 'e' || |
3fe73755 | 1208 | is_decimal_point || keycode == '+' || keycode == '-') ) |
ca65c044 | 1209 | return true; |
3fe73755 | 1210 | } |
f6bcfd97 BP |
1211 | } |
1212 | } | |
1213 | ||
ca65c044 | 1214 | return false; |
f6bcfd97 BP |
1215 | } |
1216 | ||
3a8c693a VZ |
1217 | #endif // wxUSE_TEXTCTRL |
1218 | ||
1219 | #if wxUSE_CHECKBOX | |
1220 | ||
508011ce VZ |
1221 | // ---------------------------------------------------------------------------- |
1222 | // wxGridCellBoolEditor | |
1223 | // ---------------------------------------------------------------------------- | |
1224 | ||
1225 | void wxGridCellBoolEditor::Create(wxWindow* parent, | |
1226 | wxWindowID id, | |
1227 | wxEvtHandler* evtHandler) | |
1228 | { | |
1229 | m_control = new wxCheckBox(parent, id, wxEmptyString, | |
1230 | wxDefaultPosition, wxDefaultSize, | |
1231 | wxNO_BORDER); | |
1232 | ||
1233 | wxGridCellEditor::Create(parent, id, evtHandler); | |
1234 | } | |
1235 | ||
1236 | void wxGridCellBoolEditor::SetSize(const wxRect& r) | |
1237 | { | |
ca65c044 | 1238 | bool resize = false; |
b94ae1ea VZ |
1239 | wxSize size = m_control->GetSize(); |
1240 | wxCoord minSize = wxMin(r.width, r.height); | |
1241 | ||
1242 | // check if the checkbox is not too big/small for this cell | |
1243 | wxSize sizeBest = m_control->GetBestSize(); | |
1244 | if ( !(size == sizeBest) ) | |
1245 | { | |
1246 | // reset to default size if it had been made smaller | |
1247 | size = sizeBest; | |
1248 | ||
ca65c044 | 1249 | resize = true; |
b94ae1ea VZ |
1250 | } |
1251 | ||
1252 | if ( size.x >= minSize || size.y >= minSize ) | |
1253 | { | |
1254 | // leave 1 pixel margin | |
1255 | size.x = size.y = minSize - 2; | |
1256 | ||
ca65c044 | 1257 | resize = true; |
b94ae1ea VZ |
1258 | } |
1259 | ||
1260 | if ( resize ) | |
1261 | { | |
1262 | m_control->SetSize(size); | |
1263 | } | |
1264 | ||
508011ce | 1265 | // position it in the centre of the rectangle (TODO: support alignment?) |
508011ce | 1266 | |
b94ae1ea | 1267 | #if defined(__WXGTK__) || defined (__WXMOTIF__) |
508011ce VZ |
1268 | // the checkbox without label still has some space to the right in wxGTK, |
1269 | // so shift it to the right | |
b94ae1ea VZ |
1270 | size.x -= 8; |
1271 | #elif defined(__WXMSW__) | |
a95e38c0 VZ |
1272 | // here too, but in other way |
1273 | size.x += 1; | |
b94ae1ea VZ |
1274 | size.y -= 2; |
1275 | #endif | |
508011ce | 1276 | |
1bd71df9 JS |
1277 | int hAlign = wxALIGN_CENTRE; |
1278 | int vAlign = wxALIGN_CENTRE; | |
1279 | if (GetCellAttr()) | |
1280 | GetCellAttr()->GetAlignment(& hAlign, & vAlign); | |
52d6f640 | 1281 | |
1bd71df9 JS |
1282 | int x = 0, y = 0; |
1283 | if (hAlign == wxALIGN_LEFT) | |
1284 | { | |
1285 | x = r.x + 2; | |
1286 | #ifdef __WXMSW__ | |
1287 | x += 2; | |
52d6f640 | 1288 | #endif |
1bd71df9 JS |
1289 | y = r.y + r.height/2 - size.y/2; |
1290 | } | |
1291 | else if (hAlign == wxALIGN_RIGHT) | |
1292 | { | |
1293 | x = r.x + r.width - size.x - 2; | |
1294 | y = r.y + r.height/2 - size.y/2; | |
1295 | } | |
1296 | else if (hAlign == wxALIGN_CENTRE) | |
1297 | { | |
1298 | x = r.x + r.width/2 - size.x/2; | |
1299 | y = r.y + r.height/2 - size.y/2; | |
1300 | } | |
52d6f640 | 1301 | |
1bd71df9 | 1302 | m_control->Move(x, y); |
508011ce VZ |
1303 | } |
1304 | ||
1305 | void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr) | |
1306 | { | |
99306db2 VZ |
1307 | m_control->Show(show); |
1308 | ||
189d0213 | 1309 | if ( show ) |
508011ce | 1310 | { |
189d0213 VZ |
1311 | wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY; |
1312 | CBox()->SetBackgroundColour(colBg); | |
508011ce | 1313 | } |
508011ce VZ |
1314 | } |
1315 | ||
1316 | void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid) | |
1317 | { | |
1318 | wxASSERT_MSG(m_control, | |
1319 | wxT("The wxGridCellEditor must be Created first!")); | |
1320 | ||
28a77bc4 | 1321 | if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) |
f2d76237 RD |
1322 | m_startValue = grid->GetTable()->GetValueAsBool(row, col); |
1323 | else | |
695a3263 MB |
1324 | { |
1325 | wxString cellval( grid->GetTable()->GetValue(row, col) ); | |
8dd8f875 | 1326 | m_startValue = !( !cellval || (cellval == wxT("0")) ); |
695a3263 | 1327 | } |
508011ce VZ |
1328 | CBox()->SetValue(m_startValue); |
1329 | CBox()->SetFocus(); | |
1330 | } | |
1331 | ||
1332 | bool wxGridCellBoolEditor::EndEdit(int row, int col, | |
508011ce VZ |
1333 | wxGrid* grid) |
1334 | { | |
1335 | wxASSERT_MSG(m_control, | |
1336 | wxT("The wxGridCellEditor must be Created first!")); | |
1337 | ||
ca65c044 | 1338 | bool changed = false; |
508011ce VZ |
1339 | bool value = CBox()->GetValue(); |
1340 | if ( value != m_startValue ) | |
ca65c044 | 1341 | changed = true; |
508011ce VZ |
1342 | |
1343 | if ( changed ) | |
1344 | { | |
28a77bc4 | 1345 | if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) |
f2d76237 RD |
1346 | grid->GetTable()->SetValueAsBool(row, col, value); |
1347 | else | |
1348 | grid->GetTable()->SetValue(row, col, value ? _T("1") : wxEmptyString); | |
508011ce VZ |
1349 | } |
1350 | ||
1351 | return changed; | |
1352 | } | |
1353 | ||
1354 | void wxGridCellBoolEditor::Reset() | |
1355 | { | |
1356 | wxASSERT_MSG(m_control, | |
1357 | wxT("The wxGridCellEditor must be Created first!")); | |
1358 | ||
1359 | CBox()->SetValue(m_startValue); | |
1360 | } | |
1361 | ||
e195a54c | 1362 | void wxGridCellBoolEditor::StartingClick() |
508011ce | 1363 | { |
e195a54c | 1364 | CBox()->SetValue(!CBox()->GetValue()); |
508011ce VZ |
1365 | } |
1366 | ||
f6bcfd97 BP |
1367 | bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent& event) |
1368 | { | |
1369 | if ( wxGridCellEditor::IsAcceptedKey(event) ) | |
1370 | { | |
1371 | int keycode = event.GetKeyCode(); | |
1372 | switch ( keycode ) | |
1373 | { | |
1374 | case WXK_MULTIPLY: | |
1375 | case WXK_NUMPAD_MULTIPLY: | |
1376 | case WXK_ADD: | |
1377 | case WXK_NUMPAD_ADD: | |
1378 | case WXK_SUBTRACT: | |
1379 | case WXK_NUMPAD_SUBTRACT: | |
1380 | case WXK_SPACE: | |
1381 | case '+': | |
1382 | case '-': | |
ca65c044 | 1383 | return true; |
f6bcfd97 BP |
1384 | } |
1385 | } | |
1386 | ||
ca65c044 | 1387 | return false; |
f6bcfd97 | 1388 | } |
04418332 | 1389 | |
73145b0e JS |
1390 | // return the value as "1" for true and the empty string for false |
1391 | wxString wxGridCellBoolEditor::GetValue() const | |
1392 | { | |
1393 | bool bSet = CBox()->GetValue(); | |
04418332 | 1394 | return bSet ? _T("1") : wxEmptyString; |
73145b0e | 1395 | } |
f6bcfd97 | 1396 | |
3a8c693a VZ |
1397 | #endif // wxUSE_CHECKBOX |
1398 | ||
1399 | #if wxUSE_COMBOBOX | |
1400 | ||
4ee5fc9c VZ |
1401 | // ---------------------------------------------------------------------------- |
1402 | // wxGridCellChoiceEditor | |
1403 | // ---------------------------------------------------------------------------- | |
1404 | ||
7db33cc3 MB |
1405 | wxGridCellChoiceEditor::wxGridCellChoiceEditor(const wxArrayString& choices, |
1406 | bool allowOthers) | |
1407 | : m_choices(choices), | |
1408 | m_allowOthers(allowOthers) { } | |
1409 | ||
4ee5fc9c | 1410 | wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count, |
f6bcfd97 | 1411 | const wxString choices[], |
4ee5fc9c VZ |
1412 | bool allowOthers) |
1413 | : m_allowOthers(allowOthers) | |
1414 | { | |
c4608a8a | 1415 | if ( count ) |
4ee5fc9c | 1416 | { |
c4608a8a VZ |
1417 | m_choices.Alloc(count); |
1418 | for ( size_t n = 0; n < count; n++ ) | |
1419 | { | |
1420 | m_choices.Add(choices[n]); | |
1421 | } | |
4ee5fc9c VZ |
1422 | } |
1423 | } | |
1424 | ||
c4608a8a VZ |
1425 | wxGridCellEditor *wxGridCellChoiceEditor::Clone() const |
1426 | { | |
1427 | wxGridCellChoiceEditor *editor = new wxGridCellChoiceEditor; | |
1428 | editor->m_allowOthers = m_allowOthers; | |
1429 | editor->m_choices = m_choices; | |
1430 | ||
1431 | return editor; | |
1432 | } | |
1433 | ||
4ee5fc9c VZ |
1434 | void wxGridCellChoiceEditor::Create(wxWindow* parent, |
1435 | wxWindowID id, | |
1436 | wxEvtHandler* evtHandler) | |
1437 | { | |
4ee5fc9c VZ |
1438 | m_control = new wxComboBox(parent, id, wxEmptyString, |
1439 | wxDefaultPosition, wxDefaultSize, | |
584ad2a3 | 1440 | m_choices, |
4ee5fc9c VZ |
1441 | m_allowOthers ? 0 : wxCB_READONLY); |
1442 | ||
4ee5fc9c VZ |
1443 | wxGridCellEditor::Create(parent, id, evtHandler); |
1444 | } | |
1445 | ||
a5777624 RD |
1446 | void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell, |
1447 | wxGridCellAttr * attr) | |
4ee5fc9c VZ |
1448 | { |
1449 | // as we fill the entire client area, don't do anything here to minimize | |
1450 | // flicker | |
a5777624 RD |
1451 | |
1452 | // TODO: It doesn't actually fill the client area since the height of a | |
1453 | // combo always defaults to the standard... Until someone has time to | |
1454 | // figure out the right rectangle to paint, just do it the normal way... | |
1455 | wxGridCellEditor::PaintBackground(rectCell, attr); | |
4ee5fc9c VZ |
1456 | } |
1457 | ||
1458 | void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid) | |
1459 | { | |
1460 | wxASSERT_MSG(m_control, | |
1461 | wxT("The wxGridCellEditor must be Created first!")); | |
1462 | ||
1463 | m_startValue = grid->GetTable()->GetValue(row, col); | |
1464 | ||
2b5f62a0 VZ |
1465 | if (m_allowOthers) |
1466 | Combo()->SetValue(m_startValue); | |
1467 | else | |
28a77bc4 | 1468 | { |
2b5f62a0 VZ |
1469 | // find the right position, or default to the first if not found |
1470 | int pos = Combo()->FindString(m_startValue); | |
1471 | if (pos == -1) | |
1472 | pos = 0; | |
1473 | Combo()->SetSelection(pos); | |
28a77bc4 | 1474 | } |
4ee5fc9c VZ |
1475 | Combo()->SetInsertionPointEnd(); |
1476 | Combo()->SetFocus(); | |
1477 | } | |
1478 | ||
28a77bc4 | 1479 | bool wxGridCellChoiceEditor::EndEdit(int row, int col, |
4ee5fc9c VZ |
1480 | wxGrid* grid) |
1481 | { | |
1482 | wxString value = Combo()->GetValue(); | |
faffacec VZ |
1483 | if ( value == m_startValue ) |
1484 | return false; | |
4ee5fc9c | 1485 | |
faffacec | 1486 | grid->GetTable()->SetValue(row, col, value); |
4ee5fc9c | 1487 | |
faffacec | 1488 | return true; |
4ee5fc9c VZ |
1489 | } |
1490 | ||
1491 | void wxGridCellChoiceEditor::Reset() | |
1492 | { | |
1493 | Combo()->SetValue(m_startValue); | |
1494 | Combo()->SetInsertionPointEnd(); | |
1495 | } | |
1496 | ||
c4608a8a VZ |
1497 | void wxGridCellChoiceEditor::SetParameters(const wxString& params) |
1498 | { | |
1499 | if ( !params ) | |
1500 | { | |
1501 | // what can we do? | |
1502 | return; | |
1503 | } | |
1504 | ||
1505 | m_choices.Empty(); | |
1506 | ||
1507 | wxStringTokenizer tk(params, _T(',')); | |
1508 | while ( tk.HasMoreTokens() ) | |
1509 | { | |
1510 | m_choices.Add(tk.GetNextToken()); | |
1511 | } | |
1512 | } | |
1513 | ||
73145b0e JS |
1514 | // return the value in the text control |
1515 | wxString wxGridCellChoiceEditor::GetValue() const | |
1516 | { | |
1517 | return Combo()->GetValue(); | |
1518 | } | |
04418332 | 1519 | |
3a8c693a VZ |
1520 | #endif // wxUSE_COMBOBOX |
1521 | ||
508011ce VZ |
1522 | // ---------------------------------------------------------------------------- |
1523 | // wxGridCellEditorEvtHandler | |
1524 | // ---------------------------------------------------------------------------- | |
2796cce3 RD |
1525 | |
1526 | void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event) | |
1527 | { | |
12a3f227 | 1528 | switch ( event.GetKeyCode() ) |
2796cce3 RD |
1529 | { |
1530 | case WXK_ESCAPE: | |
1531 | m_editor->Reset(); | |
b54ba671 | 1532 | m_grid->DisableCellEditControl(); |
2796cce3 RD |
1533 | break; |
1534 | ||
2c9a89e0 | 1535 | case WXK_TAB: |
b51c3f27 | 1536 | m_grid->GetEventHandler()->ProcessEvent( event ); |
9b4aede2 RD |
1537 | break; |
1538 | ||
2796cce3 | 1539 | case WXK_RETURN: |
faec5a43 SN |
1540 | case WXK_NUMPAD_ENTER: |
1541 | if (!m_grid->GetEventHandler()->ProcessEvent(event)) | |
2796cce3 RD |
1542 | m_editor->HandleReturn(event); |
1543 | break; | |
1544 | ||
2796cce3 RD |
1545 | |
1546 | default: | |
1547 | event.Skip(); | |
1548 | } | |
1549 | } | |
1550 | ||
fb0de762 RD |
1551 | void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event) |
1552 | { | |
12a3f227 | 1553 | switch ( event.GetKeyCode() ) |
fb0de762 RD |
1554 | { |
1555 | case WXK_ESCAPE: | |
1556 | case WXK_TAB: | |
1557 | case WXK_RETURN: | |
a4f7bf58 | 1558 | case WXK_NUMPAD_ENTER: |
fb0de762 RD |
1559 | break; |
1560 | ||
1561 | default: | |
1562 | event.Skip(); | |
1563 | } | |
1564 | } | |
1565 | ||
c4608a8a VZ |
1566 | // ---------------------------------------------------------------------------- |
1567 | // wxGridCellWorker is an (almost) empty common base class for | |
1568 | // wxGridCellRenderer and wxGridCellEditor managing ref counting | |
1569 | // ---------------------------------------------------------------------------- | |
1570 | ||
1571 | void wxGridCellWorker::SetParameters(const wxString& WXUNUSED(params)) | |
1572 | { | |
1573 | // nothing to do | |
1574 | } | |
1575 | ||
1576 | wxGridCellWorker::~wxGridCellWorker() | |
1577 | { | |
1578 | } | |
1579 | ||
508011ce VZ |
1580 | // ============================================================================ |
1581 | // renderer classes | |
1582 | // ============================================================================ | |
1583 | ||
ab79958a VZ |
1584 | // ---------------------------------------------------------------------------- |
1585 | // wxGridCellRenderer | |
1586 | // ---------------------------------------------------------------------------- | |
1587 | ||
1588 | void wxGridCellRenderer::Draw(wxGrid& grid, | |
2796cce3 | 1589 | wxGridCellAttr& attr, |
ab79958a VZ |
1590 | wxDC& dc, |
1591 | const wxRect& rect, | |
c78b3acd | 1592 | int WXUNUSED(row), int WXUNUSED(col), |
ab79958a VZ |
1593 | bool isSelected) |
1594 | { | |
1595 | dc.SetBackgroundMode( wxSOLID ); | |
1596 | ||
04418332 | 1597 | // grey out fields if the grid is disabled |
73145b0e | 1598 | if( grid.IsEnabled() ) |
ab79958a | 1599 | { |
ec157c8f WS |
1600 | if ( isSelected ) |
1601 | { | |
1602 | dc.SetBrush( wxBrush(grid.GetSelectionBackground(), wxSOLID) ); | |
1603 | } | |
1604 | else | |
1605 | { | |
1606 | dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) ); | |
1607 | } | |
52d6f640 | 1608 | } |
ab79958a VZ |
1609 | else |
1610 | { | |
ec157c8f | 1611 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE), wxSOLID)); |
ab79958a VZ |
1612 | } |
1613 | ||
1614 | dc.SetPen( *wxTRANSPARENT_PEN ); | |
ab79958a VZ |
1615 | dc.DrawRectangle(rect); |
1616 | } | |
1617 | ||
508011ce VZ |
1618 | // ---------------------------------------------------------------------------- |
1619 | // wxGridCellStringRenderer | |
1620 | // ---------------------------------------------------------------------------- | |
1621 | ||
816be743 VZ |
1622 | void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid& grid, |
1623 | wxGridCellAttr& attr, | |
1624 | wxDC& dc, | |
1625 | bool isSelected) | |
ab79958a | 1626 | { |
ab79958a VZ |
1627 | dc.SetBackgroundMode( wxTRANSPARENT ); |
1628 | ||
283b7808 VZ |
1629 | // TODO some special colours for attr.IsReadOnly() case? |
1630 | ||
04418332 | 1631 | // different coloured text when the grid is disabled |
73145b0e | 1632 | if( grid.IsEnabled() ) |
ab79958a | 1633 | { |
73145b0e JS |
1634 | if ( isSelected ) |
1635 | { | |
1636 | dc.SetTextBackground( grid.GetSelectionBackground() ); | |
1637 | dc.SetTextForeground( grid.GetSelectionForeground() ); | |
1638 | } | |
1639 | else | |
1640 | { | |
1641 | dc.SetTextBackground( attr.GetBackgroundColour() ); | |
1642 | dc.SetTextForeground( attr.GetTextColour() ); | |
1643 | } | |
ab79958a VZ |
1644 | } |
1645 | else | |
1646 | { | |
ec157c8f WS |
1647 | dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); |
1648 | dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); | |
ab79958a | 1649 | } |
816be743 | 1650 | |
2796cce3 | 1651 | dc.SetFont( attr.GetFont() ); |
816be743 VZ |
1652 | } |
1653 | ||
65e4e78e VZ |
1654 | wxSize wxGridCellStringRenderer::DoGetBestSize(wxGridCellAttr& attr, |
1655 | wxDC& dc, | |
1656 | const wxString& text) | |
1657 | { | |
f6bcfd97 | 1658 | wxCoord x = 0, y = 0, max_x = 0; |
65e4e78e | 1659 | dc.SetFont(attr.GetFont()); |
f6bcfd97 BP |
1660 | wxStringTokenizer tk(text, _T('\n')); |
1661 | while ( tk.HasMoreTokens() ) | |
1662 | { | |
1663 | dc.GetTextExtent(tk.GetNextToken(), &x, &y); | |
1664 | max_x = wxMax(max_x, x); | |
1665 | } | |
1666 | ||
1667 | y *= 1 + text.Freq(wxT('\n')); // multiply by the number of lines. | |
65e4e78e | 1668 | |
f6bcfd97 | 1669 | return wxSize(max_x, y); |
65e4e78e VZ |
1670 | } |
1671 | ||
1672 | wxSize wxGridCellStringRenderer::GetBestSize(wxGrid& grid, | |
1673 | wxGridCellAttr& attr, | |
1674 | wxDC& dc, | |
1675 | int row, int col) | |
1676 | { | |
1677 | return DoGetBestSize(attr, dc, grid.GetCellValue(row, col)); | |
1678 | } | |
1679 | ||
816be743 VZ |
1680 | void wxGridCellStringRenderer::Draw(wxGrid& grid, |
1681 | wxGridCellAttr& attr, | |
1682 | wxDC& dc, | |
1683 | const wxRect& rectCell, | |
1684 | int row, int col, | |
1685 | bool isSelected) | |
1686 | { | |
27f35b66 | 1687 | wxRect rect = rectCell; |
dc1f566f SN |
1688 | rect.Inflate(-1); |
1689 | ||
1690 | // erase only this cells background, overflow cells should have been erased | |
1691 | wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); | |
1692 | ||
1693 | int hAlign, vAlign; | |
1694 | attr.GetAlignment(&hAlign, &vAlign); | |
27f35b66 | 1695 | |
39b80349 SN |
1696 | int overflowCols = 0; |
1697 | ||
27f35b66 SN |
1698 | if (attr.GetOverflow()) |
1699 | { | |
1700 | int cols = grid.GetNumberCols(); | |
1701 | int best_width = GetBestSize(grid,attr,dc,row,col).GetWidth(); | |
1702 | int cell_rows, cell_cols; | |
1703 | attr.GetSize( &cell_rows, &cell_cols ); // shouldn't get here if <=0 | |
1704 | if ((best_width > rectCell.width) && (col < cols) && grid.GetTable()) | |
1705 | { | |
1706 | int i, c_cols, c_rows; | |
1707 | for (i = col+cell_cols; i < cols; i++) | |
1708 | { | |
ca65c044 | 1709 | bool is_empty = true; |
39b80349 | 1710 | for (int j=row; j<row+cell_rows; j++) |
27f35b66 | 1711 | { |
39b80349 | 1712 | // check w/ anchor cell for multicell block |
ef4d6ce8 | 1713 | grid.GetCellSize(j, i, &c_rows, &c_cols); |
39b80349 | 1714 | if (c_rows > 0) c_rows = 0; |
ef4d6ce8 | 1715 | if (!grid.GetTable()->IsEmptyCell(j+c_rows, i)) |
39b80349 | 1716 | { |
ca65c044 | 1717 | is_empty = false; |
ef4d6ce8 | 1718 | break; |
39b80349 | 1719 | } |
27f35b66 | 1720 | } |
39b80349 SN |
1721 | if (is_empty) |
1722 | rect.width += grid.GetColSize(i); | |
dc1f566f SN |
1723 | else |
1724 | { | |
1725 | i--; | |
1726 | break; | |
1727 | } | |
39b80349 | 1728 | if (rect.width >= best_width) break; |
2b5f62a0 | 1729 | } |
39b80349 | 1730 | overflowCols = i - col - cell_cols + 1; |
2b5f62a0 | 1731 | if (overflowCols >= cols) overflowCols = cols - 1; |
39b80349 | 1732 | } |
27f35b66 | 1733 | |
dc1f566f SN |
1734 | if (overflowCols > 0) // redraw overflow cells w/ proper hilight |
1735 | { | |
39b80349 | 1736 | hAlign = wxALIGN_LEFT; // if oveflowed then it's left aligned |
2b5f62a0 | 1737 | wxRect clip = rect; |
39b80349 | 1738 | clip.x += rectCell.width; |
dc1f566f SN |
1739 | // draw each overflow cell individually |
1740 | int col_end = col+cell_cols+overflowCols; | |
1741 | if (col_end >= grid.GetNumberCols()) | |
2b5f62a0 | 1742 | col_end = grid.GetNumberCols() - 1; |
dc1f566f SN |
1743 | for (int i = col+cell_cols; i <= col_end; i++) |
1744 | { | |
dc1f566f SN |
1745 | clip.width = grid.GetColSize(i) - 1; |
1746 | dc.DestroyClippingRegion(); | |
1747 | dc.SetClippingRegion(clip); | |
39b80349 SN |
1748 | |
1749 | SetTextColoursAndFont(grid, attr, dc, | |
2b5f62a0 | 1750 | grid.IsInSelection(row,i)); |
39b80349 | 1751 | |
dc1f566f | 1752 | grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), |
2b5f62a0 | 1753 | rect, hAlign, vAlign); |
39b80349 | 1754 | clip.x += grid.GetColSize(i) - 1; |
dc1f566f | 1755 | } |
ab79958a | 1756 | |
39b80349 | 1757 | rect = rectCell; |
2b5f62a0 | 1758 | rect.Inflate(-1); |
dc1f566f | 1759 | rect.width++; |
39b80349 | 1760 | dc.DestroyClippingRegion(); |
dc1f566f | 1761 | } |
39b80349 | 1762 | } |
ab79958a | 1763 | |
dc1f566f SN |
1764 | // now we only have to draw the text |
1765 | SetTextColoursAndFont(grid, attr, dc, isSelected); | |
39b80349 | 1766 | |
ab79958a VZ |
1767 | grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), |
1768 | rect, hAlign, vAlign); | |
1769 | } | |
1770 | ||
65e4e78e VZ |
1771 | // ---------------------------------------------------------------------------- |
1772 | // wxGridCellNumberRenderer | |
1773 | // ---------------------------------------------------------------------------- | |
1774 | ||
1775 | wxString wxGridCellNumberRenderer::GetString(wxGrid& grid, int row, int col) | |
1776 | { | |
1777 | wxGridTableBase *table = grid.GetTable(); | |
1778 | wxString text; | |
1779 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) ) | |
1780 | { | |
1781 | text.Printf(_T("%ld"), table->GetValueAsLong(row, col)); | |
1782 | } | |
9c4ba614 VZ |
1783 | else |
1784 | { | |
1785 | text = table->GetValue(row, col); | |
1786 | } | |
65e4e78e VZ |
1787 | |
1788 | return text; | |
1789 | } | |
1790 | ||
816be743 VZ |
1791 | void wxGridCellNumberRenderer::Draw(wxGrid& grid, |
1792 | wxGridCellAttr& attr, | |
1793 | wxDC& dc, | |
1794 | const wxRect& rectCell, | |
1795 | int row, int col, | |
1796 | bool isSelected) | |
1797 | { | |
1798 | wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); | |
1799 | ||
1800 | SetTextColoursAndFont(grid, attr, dc, isSelected); | |
1801 | ||
1802 | // draw the text right aligned by default | |
1803 | int hAlign, vAlign; | |
1804 | attr.GetAlignment(&hAlign, &vAlign); | |
4c7277db | 1805 | hAlign = wxALIGN_RIGHT; |
816be743 VZ |
1806 | |
1807 | wxRect rect = rectCell; | |
1808 | rect.Inflate(-1); | |
1809 | ||
65e4e78e VZ |
1810 | grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign); |
1811 | } | |
816be743 | 1812 | |
65e4e78e VZ |
1813 | wxSize wxGridCellNumberRenderer::GetBestSize(wxGrid& grid, |
1814 | wxGridCellAttr& attr, | |
1815 | wxDC& dc, | |
1816 | int row, int col) | |
1817 | { | |
1818 | return DoGetBestSize(attr, dc, GetString(grid, row, col)); | |
816be743 VZ |
1819 | } |
1820 | ||
1821 | // ---------------------------------------------------------------------------- | |
1822 | // wxGridCellFloatRenderer | |
1823 | // ---------------------------------------------------------------------------- | |
1824 | ||
1825 | wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width, int precision) | |
1826 | { | |
1827 | SetWidth(width); | |
1828 | SetPrecision(precision); | |
1829 | } | |
1830 | ||
e72b4213 VZ |
1831 | wxGridCellRenderer *wxGridCellFloatRenderer::Clone() const |
1832 | { | |
1833 | wxGridCellFloatRenderer *renderer = new wxGridCellFloatRenderer; | |
1834 | renderer->m_width = m_width; | |
1835 | renderer->m_precision = m_precision; | |
1836 | renderer->m_format = m_format; | |
1837 | ||
1838 | return renderer; | |
1839 | } | |
1840 | ||
65e4e78e VZ |
1841 | wxString wxGridCellFloatRenderer::GetString(wxGrid& grid, int row, int col) |
1842 | { | |
1843 | wxGridTableBase *table = grid.GetTable(); | |
0b190b0f VZ |
1844 | |
1845 | bool hasDouble; | |
1846 | double val; | |
65e4e78e VZ |
1847 | wxString text; |
1848 | if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) ) | |
1849 | { | |
0b190b0f | 1850 | val = table->GetValueAsDouble(row, col); |
ca65c044 | 1851 | hasDouble = true; |
65e4e78e | 1852 | } |
9c4ba614 VZ |
1853 | else |
1854 | { | |
1855 | text = table->GetValue(row, col); | |
0b190b0f | 1856 | hasDouble = text.ToDouble(&val); |
9c4ba614 | 1857 | } |
65e4e78e | 1858 | |
0b190b0f VZ |
1859 | if ( hasDouble ) |
1860 | { | |
1861 | if ( !m_format ) | |
1862 | { | |
1863 | if ( m_width == -1 ) | |
1864 | { | |
19d7140e VZ |
1865 | if ( m_precision == -1 ) |
1866 | { | |
2b5f62a0 VZ |
1867 | // default width/precision |
1868 | m_format = _T("%f"); | |
1869 | } | |
19d7140e VZ |
1870 | else |
1871 | { | |
1872 | m_format.Printf(_T("%%.%df"), m_precision); | |
1873 | } | |
0b190b0f VZ |
1874 | } |
1875 | else if ( m_precision == -1 ) | |
1876 | { | |
1877 | // default precision | |
1878 | m_format.Printf(_T("%%%d.f"), m_width); | |
1879 | } | |
1880 | else | |
1881 | { | |
1882 | m_format.Printf(_T("%%%d.%df"), m_width, m_precision); | |
1883 | } | |
1884 | } | |
1885 | ||
1886 | text.Printf(m_format, val); | |
19d7140e | 1887 | |
0b190b0f VZ |
1888 | } |
1889 | //else: text already contains the string | |
1890 | ||
65e4e78e VZ |
1891 | return text; |
1892 | } | |
1893 | ||
816be743 VZ |
1894 | void wxGridCellFloatRenderer::Draw(wxGrid& grid, |
1895 | wxGridCellAttr& attr, | |
1896 | wxDC& dc, | |
1897 | const wxRect& rectCell, | |
1898 | int row, int col, | |
1899 | bool isSelected) | |
1900 | { | |
1901 | wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); | |
1902 | ||
1903 | SetTextColoursAndFont(grid, attr, dc, isSelected); | |
1904 | ||
1905 | // draw the text right aligned by default | |
1906 | int hAlign, vAlign; | |
1907 | attr.GetAlignment(&hAlign, &vAlign); | |
4c7277db | 1908 | hAlign = wxALIGN_RIGHT; |
816be743 VZ |
1909 | |
1910 | wxRect rect = rectCell; | |
1911 | rect.Inflate(-1); | |
1912 | ||
65e4e78e VZ |
1913 | grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign); |
1914 | } | |
816be743 | 1915 | |
65e4e78e VZ |
1916 | wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid, |
1917 | wxGridCellAttr& attr, | |
1918 | wxDC& dc, | |
1919 | int row, int col) | |
1920 | { | |
1921 | return DoGetBestSize(attr, dc, GetString(grid, row, col)); | |
816be743 VZ |
1922 | } |
1923 | ||
0b190b0f VZ |
1924 | void wxGridCellFloatRenderer::SetParameters(const wxString& params) |
1925 | { | |
0b190b0f VZ |
1926 | if ( !params ) |
1927 | { | |
1928 | // reset to defaults | |
1929 | SetWidth(-1); | |
1930 | SetPrecision(-1); | |
1931 | } | |
1932 | else | |
1933 | { | |
1934 | wxString tmp = params.BeforeFirst(_T(',')); | |
ec157c8f | 1935 | if ( !tmp.empty() ) |
0b190b0f VZ |
1936 | { |
1937 | long width; | |
19d7140e | 1938 | if ( tmp.ToLong(&width) ) |
0b190b0f | 1939 | { |
19d7140e | 1940 | SetWidth((int)width); |
0b190b0f VZ |
1941 | } |
1942 | else | |
1943 | { | |
19d7140e VZ |
1944 | wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str()); |
1945 | } | |
0b190b0f | 1946 | |
19d7140e | 1947 | } |
0b190b0f | 1948 | tmp = params.AfterFirst(_T(',')); |
ec157c8f | 1949 | if ( !tmp.empty() ) |
0b190b0f VZ |
1950 | { |
1951 | long precision; | |
19d7140e | 1952 | if ( tmp.ToLong(&precision) ) |
0b190b0f | 1953 | { |
19d7140e | 1954 | SetPrecision((int)precision); |
0b190b0f VZ |
1955 | } |
1956 | else | |
1957 | { | |
19d7140e | 1958 | wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str()); |
0b190b0f VZ |
1959 | } |
1960 | ||
0b190b0f VZ |
1961 | } |
1962 | } | |
1963 | } | |
1964 | ||
19d7140e | 1965 | |
508011ce VZ |
1966 | // ---------------------------------------------------------------------------- |
1967 | // wxGridCellBoolRenderer | |
1968 | // ---------------------------------------------------------------------------- | |
1969 | ||
65e4e78e | 1970 | wxSize wxGridCellBoolRenderer::ms_sizeCheckMark; |
508011ce | 1971 | |
b94ae1ea VZ |
1972 | // FIXME these checkbox size calculations are really ugly... |
1973 | ||
65e4e78e | 1974 | // between checkmark and box |
a95e38c0 | 1975 | static const wxCoord wxGRID_CHECKMARK_MARGIN = 2; |
508011ce | 1976 | |
65e4e78e VZ |
1977 | wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid, |
1978 | wxGridCellAttr& WXUNUSED(attr), | |
1979 | wxDC& WXUNUSED(dc), | |
1980 | int WXUNUSED(row), | |
1981 | int WXUNUSED(col)) | |
1982 | { | |
1983 | // compute it only once (no locks for MT safeness in GUI thread...) | |
1984 | if ( !ms_sizeCheckMark.x ) | |
297da4ba | 1985 | { |
65e4e78e | 1986 | // get checkbox size |
ca65c044 | 1987 | wxCheckBox *checkbox = new wxCheckBox(&grid, wxID_ANY, wxEmptyString); |
297da4ba | 1988 | wxSize size = checkbox->GetBestSize(); |
999836aa | 1989 | wxCoord checkSize = size.y + 2*wxGRID_CHECKMARK_MARGIN; |
297da4ba | 1990 | |
65e4e78e | 1991 | // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result |
69d8f612 | 1992 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
65e4e78e | 1993 | checkSize -= size.y / 2; |
297da4ba VZ |
1994 | #endif |
1995 | ||
1996 | delete checkbox; | |
65e4e78e VZ |
1997 | |
1998 | ms_sizeCheckMark.x = ms_sizeCheckMark.y = checkSize; | |
297da4ba VZ |
1999 | } |
2000 | ||
65e4e78e VZ |
2001 | return ms_sizeCheckMark; |
2002 | } | |
2003 | ||
2004 | void wxGridCellBoolRenderer::Draw(wxGrid& grid, | |
2005 | wxGridCellAttr& attr, | |
2006 | wxDC& dc, | |
2007 | const wxRect& rect, | |
2008 | int row, int col, | |
2009 | bool isSelected) | |
2010 | { | |
2011 | wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected); | |
2012 | ||
297da4ba | 2013 | // draw a check mark in the centre (ignoring alignment - TODO) |
65e4e78e | 2014 | wxSize size = GetBestSize(grid, attr, dc, row, col); |
b94ae1ea VZ |
2015 | |
2016 | // don't draw outside the cell | |
2017 | wxCoord minSize = wxMin(rect.width, rect.height); | |
2018 | if ( size.x >= minSize || size.y >= minSize ) | |
2019 | { | |
2020 | // and even leave (at least) 1 pixel margin | |
2021 | size.x = size.y = minSize - 2; | |
2022 | } | |
2023 | ||
2024 | // draw a border around checkmark | |
1bd71df9 JS |
2025 | int vAlign, hAlign; |
2026 | attr.GetAlignment(& hAlign, &vAlign); | |
52d6f640 | 2027 | |
a95e38c0 | 2028 | wxRect rectBorder; |
1bd71df9 JS |
2029 | if (hAlign == wxALIGN_CENTRE) |
2030 | { | |
2031 | rectBorder.x = rect.x + rect.width/2 - size.x/2; | |
2032 | rectBorder.y = rect.y + rect.height/2 - size.y/2; | |
2033 | rectBorder.width = size.x; | |
2034 | rectBorder.height = size.y; | |
2035 | } | |
2036 | else if (hAlign == wxALIGN_LEFT) | |
2037 | { | |
2038 | rectBorder.x = rect.x + 2; | |
2039 | rectBorder.y = rect.y + rect.height/2 - size.y/2; | |
2040 | rectBorder.width = size.x; | |
52d6f640 | 2041 | rectBorder.height = size.y; |
1bd71df9 JS |
2042 | } |
2043 | else if (hAlign == wxALIGN_RIGHT) | |
2044 | { | |
2045 | rectBorder.x = rect.x + rect.width - size.x - 2; | |
2046 | rectBorder.y = rect.y + rect.height/2 - size.y/2; | |
2047 | rectBorder.width = size.x; | |
52d6f640 | 2048 | rectBorder.height = size.y; |
1bd71df9 | 2049 | } |
b94ae1ea | 2050 | |
f2d76237 | 2051 | bool value; |
b94ae1ea | 2052 | if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) |
f2d76237 RD |
2053 | value = grid.GetTable()->GetValueAsBool(row, col); |
2054 | else | |
695a3263 MB |
2055 | { |
2056 | wxString cellval( grid.GetTable()->GetValue(row, col) ); | |
8dd8f875 | 2057 | value = !( !cellval || (cellval == wxT("0")) ); |
695a3263 | 2058 | } |
f2d76237 RD |
2059 | |
2060 | if ( value ) | |
508011ce | 2061 | { |
a95e38c0 VZ |
2062 | wxRect rectMark = rectBorder; |
2063 | #ifdef __WXMSW__ | |
2064 | // MSW DrawCheckMark() is weird (and should probably be changed...) | |
2065 | rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN/2); | |
2066 | rectMark.x++; | |
2067 | rectMark.y++; | |
2068 | #else // !MSW | |
2069 | rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN); | |
2070 | #endif // MSW/!MSW | |
2071 | ||
508011ce VZ |
2072 | dc.SetTextForeground(attr.GetTextColour()); |
2073 | dc.DrawCheckMark(rectMark); | |
2074 | } | |
a95e38c0 VZ |
2075 | |
2076 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
2077 | dc.SetPen(wxPen(attr.GetTextColour(), 1, wxSOLID)); | |
2078 | dc.DrawRectangle(rectBorder); | |
508011ce VZ |
2079 | } |
2080 | ||
2796cce3 RD |
2081 | // ---------------------------------------------------------------------------- |
2082 | // wxGridCellAttr | |
2083 | // ---------------------------------------------------------------------------- | |
2084 | ||
1df4050d VZ |
2085 | void wxGridCellAttr::Init(wxGridCellAttr *attrDefault) |
2086 | { | |
2087 | m_nRef = 1; | |
2088 | ||
2089 | m_isReadOnly = Unset; | |
2090 | ||
2091 | m_renderer = NULL; | |
2092 | m_editor = NULL; | |
2093 | ||
2094 | m_attrkind = wxGridCellAttr::Cell; | |
2095 | ||
27f35b66 | 2096 | m_sizeRows = m_sizeCols = 1; |
b63fce94 | 2097 | m_overflow = UnsetOverflow; |
27f35b66 | 2098 | |
1df4050d VZ |
2099 | SetDefAttr(attrDefault); |
2100 | } | |
2101 | ||
39bcce60 | 2102 | wxGridCellAttr *wxGridCellAttr::Clone() const |
a68c1246 | 2103 | { |
1df4050d VZ |
2104 | wxGridCellAttr *attr = new wxGridCellAttr(m_defGridAttr); |
2105 | ||
a68c1246 VZ |
2106 | if ( HasTextColour() ) |
2107 | attr->SetTextColour(GetTextColour()); | |
2108 | if ( HasBackgroundColour() ) | |
2109 | attr->SetBackgroundColour(GetBackgroundColour()); | |
2110 | if ( HasFont() ) | |
2111 | attr->SetFont(GetFont()); | |
2112 | if ( HasAlignment() ) | |
2113 | attr->SetAlignment(m_hAlign, m_vAlign); | |
2114 | ||
27f35b66 SN |
2115 | attr->SetSize( m_sizeRows, m_sizeCols ); |
2116 | ||
a68c1246 VZ |
2117 | if ( m_renderer ) |
2118 | { | |
2119 | attr->SetRenderer(m_renderer); | |
39bcce60 | 2120 | m_renderer->IncRef(); |
a68c1246 VZ |
2121 | } |
2122 | if ( m_editor ) | |
2123 | { | |
2124 | attr->SetEditor(m_editor); | |
39bcce60 | 2125 | m_editor->IncRef(); |
a68c1246 VZ |
2126 | } |
2127 | ||
2128 | if ( IsReadOnly() ) | |
2129 | attr->SetReadOnly(); | |
2130 | ||
19d7140e VZ |
2131 | attr->SetKind( m_attrkind ); |
2132 | ||
a68c1246 VZ |
2133 | return attr; |
2134 | } | |
2135 | ||
19d7140e VZ |
2136 | void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom) |
2137 | { | |
2138 | if ( !HasTextColour() && mergefrom->HasTextColour() ) | |
2139 | SetTextColour(mergefrom->GetTextColour()); | |
2140 | if ( !HasBackgroundColour() && mergefrom->HasBackgroundColour() ) | |
2141 | SetBackgroundColour(mergefrom->GetBackgroundColour()); | |
2142 | if ( !HasFont() && mergefrom->HasFont() ) | |
2143 | SetFont(mergefrom->GetFont()); | |
7e48d7d9 | 2144 | if ( !HasAlignment() && mergefrom->HasAlignment() ){ |
19d7140e VZ |
2145 | int hAlign, vAlign; |
2146 | mergefrom->GetAlignment( &hAlign, &vAlign); | |
2147 | SetAlignment(hAlign, vAlign); | |
2148 | } | |
2149 | ||
27f35b66 SN |
2150 | mergefrom->GetSize( &m_sizeRows, &m_sizeCols ); |
2151 | ||
19d7140e VZ |
2152 | // Directly access member functions as GetRender/Editor don't just return |
2153 | // m_renderer/m_editor | |
2154 | // | |
2155 | // Maybe add support for merge of Render and Editor? | |
2156 | if (!HasRenderer() && mergefrom->HasRenderer() ) | |
bf7945ce | 2157 | { |
19d7140e VZ |
2158 | m_renderer = mergefrom->m_renderer; |
2159 | m_renderer->IncRef(); | |
2160 | } | |
2161 | if ( !HasEditor() && mergefrom->HasEditor() ) | |
2162 | { | |
2163 | m_editor = mergefrom->m_editor; | |
2164 | m_editor->IncRef(); | |
2165 | } | |
2166 | if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() ) | |
2167 | SetReadOnly(mergefrom->IsReadOnly()); | |
2168 | ||
ef5df12b | 2169 | if (!HasOverflowMode() && mergefrom->HasOverflowMode() ) |
ff699386 | 2170 | SetOverflow(mergefrom->GetOverflow()); |
ef5df12b | 2171 | |
19d7140e VZ |
2172 | SetDefAttr(mergefrom->m_defGridAttr); |
2173 | } | |
2174 | ||
27f35b66 SN |
2175 | void wxGridCellAttr::SetSize(int num_rows, int num_cols) |
2176 | { | |
2177 | // The size of a cell is normally 1,1 | |
2178 | ||
2179 | // If this cell is larger (2,2) then this is the top left cell | |
2180 | // the other cells that will be covered (lower right cells) must be | |
2181 | // set to negative or zero values such that | |
2182 | // row + num_rows of the covered cell points to the larger cell (this cell) | |
2183 | // same goes for the col + num_cols. | |
2184 | ||
2185 | // Size of 0,0 is NOT valid, neither is <=0 and any positive value | |
2186 | ||
2187 | wxASSERT_MSG( (!((num_rows>0)&&(num_cols<=0)) || | |
2188 | !((num_rows<=0)&&(num_cols>0)) || | |
2189 | !((num_rows==0)&&(num_cols==0))), | |
2190 | wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values")); | |
2191 | ||
2192 | m_sizeRows = num_rows; | |
2193 | m_sizeCols = num_cols; | |
2194 | } | |
2195 | ||
2796cce3 RD |
2196 | const wxColour& wxGridCellAttr::GetTextColour() const |
2197 | { | |
2198 | if (HasTextColour()) | |
508011ce | 2199 | { |
2796cce3 | 2200 | return m_colText; |
508011ce | 2201 | } |
0926b2fc | 2202 | else if (m_defGridAttr && m_defGridAttr != this) |
508011ce | 2203 | { |
2796cce3 | 2204 | return m_defGridAttr->GetTextColour(); |
508011ce VZ |
2205 | } |
2206 | else | |
2207 | { | |
2796cce3 RD |
2208 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
2209 | return wxNullColour; | |
2210 | } | |
2211 | } | |
2212 | ||
2213 | ||
2214 | const wxColour& wxGridCellAttr::GetBackgroundColour() const | |
2215 | { | |
2216 | if (HasBackgroundColour()) | |
2217 | return m_colBack; | |
0926b2fc | 2218 | else if (m_defGridAttr && m_defGridAttr != this) |
2796cce3 | 2219 | return m_defGridAttr->GetBackgroundColour(); |
508011ce VZ |
2220 | else |
2221 | { | |
2796cce3 RD |
2222 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
2223 | return wxNullColour; | |
2224 | } | |
2225 | } | |
2226 | ||
2227 | ||
2228 | const wxFont& wxGridCellAttr::GetFont() const | |
2229 | { | |
2230 | if (HasFont()) | |
2231 | return m_font; | |
0926b2fc | 2232 | else if (m_defGridAttr && m_defGridAttr != this) |
2796cce3 | 2233 | return m_defGridAttr->GetFont(); |
508011ce VZ |
2234 | else |
2235 | { | |
2796cce3 RD |
2236 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
2237 | return wxNullFont; | |
2238 | } | |
2239 | } | |
2240 | ||
2241 | ||
2242 | void wxGridCellAttr::GetAlignment(int *hAlign, int *vAlign) const | |
2243 | { | |
508011ce VZ |
2244 | if (HasAlignment()) |
2245 | { | |
2796cce3 RD |
2246 | if ( hAlign ) *hAlign = m_hAlign; |
2247 | if ( vAlign ) *vAlign = m_vAlign; | |
2248 | } | |
0926b2fc | 2249 | else if (m_defGridAttr && m_defGridAttr != this) |
2796cce3 | 2250 | m_defGridAttr->GetAlignment(hAlign, vAlign); |
508011ce VZ |
2251 | else |
2252 | { | |
2796cce3 RD |
2253 | wxFAIL_MSG(wxT("Missing default cell attribute")); |
2254 | } | |
2255 | } | |
2256 | ||
27f35b66 SN |
2257 | void wxGridCellAttr::GetSize( int *num_rows, int *num_cols ) const |
2258 | { | |
2259 | if ( num_rows ) *num_rows = m_sizeRows; | |
2260 | if ( num_cols ) *num_cols = m_sizeCols; | |
2261 | } | |
2796cce3 | 2262 | |
f2d76237 | 2263 | // GetRenderer and GetEditor use a slightly different decision path about |
28a77bc4 RD |
2264 | // which attribute to use. If a non-default attr object has one then it is |
2265 | // used, otherwise the default editor or renderer is fetched from the grid and | |
2266 | // used. It should be the default for the data type of the cell. If it is | |
2267 | // NULL (because the table has a type that the grid does not have in its | |
2268 | // registry,) then the grid's default editor or renderer is used. | |
2269 | ||
2270 | wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGrid* grid, int row, int col) const | |
2271 | { | |
3cf883a2 | 2272 | wxGridCellRenderer *renderer; |
28a77bc4 | 2273 | |
3cf883a2 | 2274 | if ( m_renderer && this != m_defGridAttr ) |
0b190b0f | 2275 | { |
3cf883a2 VZ |
2276 | // use the cells renderer if it has one |
2277 | renderer = m_renderer; | |
2278 | renderer->IncRef(); | |
0b190b0f | 2279 | } |
3cf883a2 | 2280 | else // no non default cell renderer |
0b190b0f | 2281 | { |
3cf883a2 VZ |
2282 | // get default renderer for the data type |
2283 | if ( grid ) | |
2284 | { | |
2285 | // GetDefaultRendererForCell() will do IncRef() for us | |
2286 | renderer = grid->GetDefaultRendererForCell(row, col); | |
2287 | } | |
2288 | else | |
2289 | { | |
2290 | renderer = NULL; | |
2291 | } | |
0b190b0f | 2292 | |
3cf883a2 VZ |
2293 | if ( !renderer ) |
2294 | { | |
0926b2fc | 2295 | if (m_defGridAttr && this != m_defGridAttr ) |
3cf883a2 VZ |
2296 | { |
2297 | // if we still don't have one then use the grid default | |
2298 | // (no need for IncRef() here neither) | |
2299 | renderer = m_defGridAttr->GetRenderer(NULL, 0, 0); | |
2300 | } | |
2301 | else // default grid attr | |
2302 | { | |
2303 | // use m_renderer which we had decided not to use initially | |
2304 | renderer = m_renderer; | |
2305 | if ( renderer ) | |
2306 | renderer->IncRef(); | |
2307 | } | |
2308 | } | |
0b190b0f | 2309 | } |
28a77bc4 | 2310 | |
3cf883a2 VZ |
2311 | // we're supposed to always find something |
2312 | wxASSERT_MSG(renderer, wxT("Missing default cell renderer")); | |
28a77bc4 RD |
2313 | |
2314 | return renderer; | |
2796cce3 RD |
2315 | } |
2316 | ||
3cf883a2 | 2317 | // same as above, except for s/renderer/editor/g |
28a77bc4 | 2318 | wxGridCellEditor* wxGridCellAttr::GetEditor(wxGrid* grid, int row, int col) const |
07296f0b | 2319 | { |
3cf883a2 | 2320 | wxGridCellEditor *editor; |
0b190b0f | 2321 | |
3cf883a2 | 2322 | if ( m_editor && this != m_defGridAttr ) |
0b190b0f | 2323 | { |
3cf883a2 VZ |
2324 | // use the cells editor if it has one |
2325 | editor = m_editor; | |
2326 | editor->IncRef(); | |
0b190b0f | 2327 | } |
3cf883a2 | 2328 | else // no non default cell editor |
0b190b0f | 2329 | { |
3cf883a2 VZ |
2330 | // get default editor for the data type |
2331 | if ( grid ) | |
2332 | { | |
2333 | // GetDefaultEditorForCell() will do IncRef() for us | |
2334 | editor = grid->GetDefaultEditorForCell(row, col); | |
2335 | } | |
2336 | else | |
2337 | { | |
2338 | editor = NULL; | |
2339 | } | |
2340 | ||
2341 | if ( !editor ) | |
2342 | { | |
0926b2fc | 2343 | if ( m_defGridAttr && this != m_defGridAttr ) |
3cf883a2 VZ |
2344 | { |
2345 | // if we still don't have one then use the grid default | |
2346 | // (no need for IncRef() here neither) | |
2347 | editor = m_defGridAttr->GetEditor(NULL, 0, 0); | |
2348 | } | |
2349 | else // default grid attr | |
2350 | { | |
2351 | // use m_editor which we had decided not to use initially | |
2352 | editor = m_editor; | |
2353 | if ( editor ) | |
2354 | editor->IncRef(); | |
2355 | } | |
2356 | } | |
0b190b0f | 2357 | } |
28a77bc4 | 2358 | |
3cf883a2 VZ |
2359 | // we're supposed to always find something |
2360 | wxASSERT_MSG(editor, wxT("Missing default cell editor")); | |
2361 | ||
28a77bc4 | 2362 | return editor; |
07296f0b RD |
2363 | } |
2364 | ||
b99be8fb | 2365 | // ---------------------------------------------------------------------------- |
758cbedf | 2366 | // wxGridCellAttrData |
b99be8fb VZ |
2367 | // ---------------------------------------------------------------------------- |
2368 | ||
758cbedf | 2369 | void wxGridCellAttrData::SetAttr(wxGridCellAttr *attr, int row, int col) |
b99be8fb VZ |
2370 | { |
2371 | int n = FindIndex(row, col); | |
2372 | if ( n == wxNOT_FOUND ) | |
2373 | { | |
2374 | // add the attribute | |
2375 | m_attrs.Add(new wxGridCellWithAttr(row, col, attr)); | |
2376 | } | |
2377 | else | |
2378 | { | |
6f36917b VZ |
2379 | // free the old attribute |
2380 | m_attrs[(size_t)n].attr->DecRef(); | |
2381 | ||
b99be8fb VZ |
2382 | if ( attr ) |
2383 | { | |
2384 | // change the attribute | |
2e9a6788 | 2385 | m_attrs[(size_t)n].attr = attr; |
b99be8fb VZ |
2386 | } |
2387 | else | |
2388 | { | |
2389 | // remove this attribute | |
2390 | m_attrs.RemoveAt((size_t)n); | |
2391 | } | |
2392 | } | |
b99be8fb VZ |
2393 | } |
2394 | ||
758cbedf | 2395 | wxGridCellAttr *wxGridCellAttrData::GetAttr(int row, int col) const |
b99be8fb VZ |
2396 | { |
2397 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; | |
2398 | ||
2399 | int n = FindIndex(row, col); | |
2400 | if ( n != wxNOT_FOUND ) | |
2401 | { | |
2e9a6788 VZ |
2402 | attr = m_attrs[(size_t)n].attr; |
2403 | attr->IncRef(); | |
b99be8fb VZ |
2404 | } |
2405 | ||
2406 | return attr; | |
2407 | } | |
2408 | ||
4d60017a SN |
2409 | void wxGridCellAttrData::UpdateAttrRows( size_t pos, int numRows ) |
2410 | { | |
2411 | size_t count = m_attrs.GetCount(); | |
2412 | for ( size_t n = 0; n < count; n++ ) | |
2413 | { | |
2414 | wxGridCellCoords& coords = m_attrs[n].coords; | |
d1c0b4f9 VZ |
2415 | wxCoord row = coords.GetRow(); |
2416 | if ((size_t)row >= pos) | |
2417 | { | |
2418 | if (numRows > 0) | |
2419 | { | |
2420 | // If rows inserted, include row counter where necessary | |
2421 | coords.SetRow(row + numRows); | |
2422 | } | |
2423 | else if (numRows < 0) | |
2424 | { | |
2425 | // If rows deleted ... | |
2426 | if ((size_t)row >= pos - numRows) | |
2427 | { | |
2428 | // ...either decrement row counter (if row still exists)... | |
2429 | coords.SetRow(row + numRows); | |
2430 | } | |
2431 | else | |
2432 | { | |
2433 | // ...or remove the attribute | |
01dd42b6 VZ |
2434 | m_attrs[n].attr->DecRef(); |
2435 | m_attrs.RemoveAt(n); | |
d1c0b4f9 VZ |
2436 | n--; count--; |
2437 | } | |
2438 | } | |
4d60017a SN |
2439 | } |
2440 | } | |
2441 | } | |
2442 | ||
2443 | void wxGridCellAttrData::UpdateAttrCols( size_t pos, int numCols ) | |
2444 | { | |
2445 | size_t count = m_attrs.GetCount(); | |
2446 | for ( size_t n = 0; n < count; n++ ) | |
2447 | { | |
2448 | wxGridCellCoords& coords = m_attrs[n].coords; | |
d1c0b4f9 VZ |
2449 | wxCoord col = coords.GetCol(); |
2450 | if ( (size_t)col >= pos ) | |
2451 | { | |
2452 | if ( numCols > 0 ) | |
2453 | { | |
2454 | // If rows inserted, include row counter where necessary | |
2455 | coords.SetCol(col + numCols); | |
2456 | } | |
2457 | else if (numCols < 0) | |
2458 | { | |
2459 | // If rows deleted ... | |
2460 | if ((size_t)col >= pos - numCols) | |
2461 | { | |
2462 | // ...either decrement row counter (if row still exists)... | |
2463 | coords.SetCol(col + numCols); | |
2464 | } | |
2465 | else | |
2466 | { | |
2467 | // ...or remove the attribute | |
01dd42b6 VZ |
2468 | m_attrs[n].attr->DecRef(); |
2469 | m_attrs.RemoveAt(n); | |
d1c0b4f9 VZ |
2470 | n--; count--; |
2471 | } | |
2472 | } | |
4d60017a SN |
2473 | } |
2474 | } | |
2475 | } | |
2476 | ||
758cbedf | 2477 | int wxGridCellAttrData::FindIndex(int row, int col) const |
b99be8fb VZ |
2478 | { |
2479 | size_t count = m_attrs.GetCount(); | |
2480 | for ( size_t n = 0; n < count; n++ ) | |
2481 | { | |
2482 | const wxGridCellCoords& coords = m_attrs[n].coords; | |
2483 | if ( (coords.GetRow() == row) && (coords.GetCol() == col) ) | |
2484 | { | |
2485 | return n; | |
2486 | } | |
2487 | } | |
2488 | ||
2489 | return wxNOT_FOUND; | |
2490 | } | |
2491 | ||
758cbedf VZ |
2492 | // ---------------------------------------------------------------------------- |
2493 | // wxGridRowOrColAttrData | |
2494 | // ---------------------------------------------------------------------------- | |
2495 | ||
2496 | wxGridRowOrColAttrData::~wxGridRowOrColAttrData() | |
2497 | { | |
2498 | size_t count = m_attrs.Count(); | |
2499 | for ( size_t n = 0; n < count; n++ ) | |
2500 | { | |
2501 | m_attrs[n]->DecRef(); | |
2502 | } | |
2503 | } | |
2504 | ||
2505 | wxGridCellAttr *wxGridRowOrColAttrData::GetAttr(int rowOrCol) const | |
2506 | { | |
2507 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; | |
2508 | ||
2509 | int n = m_rowsOrCols.Index(rowOrCol); | |
2510 | if ( n != wxNOT_FOUND ) | |
2511 | { | |
2512 | attr = m_attrs[(size_t)n]; | |
2513 | attr->IncRef(); | |
2514 | } | |
2515 | ||
2516 | return attr; | |
2517 | } | |
2518 | ||
2519 | void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr *attr, int rowOrCol) | |
2520 | { | |
a95e38c0 VZ |
2521 | int i = m_rowsOrCols.Index(rowOrCol); |
2522 | if ( i == wxNOT_FOUND ) | |
758cbedf VZ |
2523 | { |
2524 | // add the attribute | |
2525 | m_rowsOrCols.Add(rowOrCol); | |
2526 | m_attrs.Add(attr); | |
2527 | } | |
2528 | else | |
2529 | { | |
a95e38c0 | 2530 | size_t n = (size_t)i; |
758cbedf VZ |
2531 | if ( attr ) |
2532 | { | |
2533 | // change the attribute | |
a95e38c0 VZ |
2534 | m_attrs[n]->DecRef(); |
2535 | m_attrs[n] = attr; | |
758cbedf VZ |
2536 | } |
2537 | else | |
2538 | { | |
2539 | // remove this attribute | |
a95e38c0 VZ |
2540 | m_attrs[n]->DecRef(); |
2541 | m_rowsOrCols.RemoveAt(n); | |
2542 | m_attrs.RemoveAt(n); | |
758cbedf VZ |
2543 | } |
2544 | } | |
2545 | } | |
2546 | ||
4d60017a SN |
2547 | void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos, int numRowsOrCols ) |
2548 | { | |
2549 | size_t count = m_attrs.GetCount(); | |
2550 | for ( size_t n = 0; n < count; n++ ) | |
2551 | { | |
2552 | int & rowOrCol = m_rowsOrCols[n]; | |
d1c0b4f9 VZ |
2553 | if ( (size_t)rowOrCol >= pos ) |
2554 | { | |
2555 | if ( numRowsOrCols > 0 ) | |
2556 | { | |
2557 | // If rows inserted, include row counter where necessary | |
2558 | rowOrCol += numRowsOrCols; | |
2559 | } | |
2560 | else if ( numRowsOrCols < 0) | |
2561 | { | |
2562 | // If rows deleted, either decrement row counter (if row still exists) | |
2563 | if ((size_t)rowOrCol >= pos - numRowsOrCols) | |
2564 | rowOrCol += numRowsOrCols; | |
2565 | else | |
2566 | { | |
01dd42b6 VZ |
2567 | m_rowsOrCols.RemoveAt(n); |
2568 | m_attrs[n]->DecRef(); | |
2569 | m_attrs.RemoveAt(n); | |
d1c0b4f9 VZ |
2570 | n--; count--; |
2571 | } | |
2572 | } | |
4d60017a SN |
2573 | } |
2574 | } | |
2575 | } | |
2576 | ||
b99be8fb VZ |
2577 | // ---------------------------------------------------------------------------- |
2578 | // wxGridCellAttrProvider | |
2579 | // ---------------------------------------------------------------------------- | |
2580 | ||
2581 | wxGridCellAttrProvider::wxGridCellAttrProvider() | |
2582 | { | |
2583 | m_data = (wxGridCellAttrProviderData *)NULL; | |
2584 | } | |
2585 | ||
2586 | wxGridCellAttrProvider::~wxGridCellAttrProvider() | |
2587 | { | |
2588 | delete m_data; | |
2589 | } | |
2590 | ||
2591 | void wxGridCellAttrProvider::InitData() | |
2592 | { | |
2593 | m_data = new wxGridCellAttrProviderData; | |
2594 | } | |
2595 | ||
19d7140e VZ |
2596 | wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col, |
2597 | wxGridCellAttr::wxAttrKind kind ) const | |
b99be8fb | 2598 | { |
758cbedf VZ |
2599 | wxGridCellAttr *attr = (wxGridCellAttr *)NULL; |
2600 | if ( m_data ) | |
2601 | { | |
19d7140e | 2602 | switch(kind) |
758cbedf | 2603 | { |
19d7140e VZ |
2604 | case (wxGridCellAttr::Any): |
2605 | //Get cached merge attributes. | |
2606 | // Currenlty not used as no cache implemented as not mutiable | |
2607 | // attr = m_data->m_mergeAttr.GetAttr(row, col); | |
2608 | if(!attr) | |
2609 | { | |
2610 | //Basicaly implement old version. | |
2611 | //Also check merge cache, so we don't have to re-merge every time.. | |
999836aa VZ |
2612 | wxGridCellAttr *attrcell = m_data->m_cellAttrs.GetAttr(row, col); |
2613 | wxGridCellAttr *attrrow = m_data->m_rowAttrs.GetAttr(row); | |
2614 | wxGridCellAttr *attrcol = m_data->m_colAttrs.GetAttr(col); | |
19d7140e | 2615 | |
2d0c2e79 RD |
2616 | if((attrcell != attrrow) && (attrrow != attrcol) && (attrcell != attrcol)){ |
2617 | // Two or more are non NULL | |
19d7140e VZ |
2618 | attr = new wxGridCellAttr; |
2619 | attr->SetKind(wxGridCellAttr::Merged); | |
2620 | ||
bf7945ce | 2621 | //Order important.. |
19d7140e VZ |
2622 | if(attrcell){ |
2623 | attr->MergeWith(attrcell); | |
2624 | attrcell->DecRef(); | |
2625 | } | |
2626 | if(attrcol){ | |
2627 | attr->MergeWith(attrcol); | |
2628 | attrcol->DecRef(); | |
2629 | } | |
2630 | if(attrrow){ | |
2631 | attr->MergeWith(attrrow); | |
2632 | attrrow->DecRef(); | |
2633 | } | |
2634 | //store merge attr if cache implemented | |
2635 | //attr->IncRef(); | |
2636 | //m_data->m_mergeAttr.SetAttr(attr, row, col); | |
2637 | } | |
2638 | else | |
2d0c2e79 | 2639 | { |
19d7140e VZ |
2640 | // one or none is non null return it or null. |
2641 | if(attrrow) attr = attrrow; | |
2d0c2e79 RD |
2642 | if(attrcol) |
2643 | { | |
2644 | if(attr) | |
2645 | attr->DecRef(); | |
2646 | attr = attrcol; | |
2647 | } | |
2648 | if(attrcell) | |
2649 | { | |
2650 | if(attr) | |
2651 | attr->DecRef(); | |
2652 | attr = attrcell; | |
2653 | } | |
19d7140e VZ |
2654 | } |
2655 | } | |
2656 | break; | |
2657 | case (wxGridCellAttr::Cell): | |
2658 | attr = m_data->m_cellAttrs.GetAttr(row, col); | |
2659 | break; | |
2660 | case (wxGridCellAttr::Col): | |
2d0c2e79 | 2661 | attr = m_data->m_colAttrs.GetAttr(col); |
19d7140e VZ |
2662 | break; |
2663 | case (wxGridCellAttr::Row): | |
2d0c2e79 | 2664 | attr = m_data->m_rowAttrs.GetAttr(row); |
19d7140e VZ |
2665 | break; |
2666 | default: | |
2667 | // unused as yet... | |
2668 | // (wxGridCellAttr::Default): | |
2669 | // (wxGridCellAttr::Merged): | |
2670 | break; | |
758cbedf VZ |
2671 | } |
2672 | } | |
758cbedf | 2673 | return attr; |
b99be8fb VZ |
2674 | } |
2675 | ||
2e9a6788 | 2676 | void wxGridCellAttrProvider::SetAttr(wxGridCellAttr *attr, |
b99be8fb VZ |
2677 | int row, int col) |
2678 | { | |
2679 | if ( !m_data ) | |
2680 | InitData(); | |
2681 | ||
758cbedf VZ |
2682 | m_data->m_cellAttrs.SetAttr(attr, row, col); |
2683 | } | |
2684 | ||
2685 | void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr *attr, int row) | |
2686 | { | |
2687 | if ( !m_data ) | |
2688 | InitData(); | |
2689 | ||
2690 | m_data->m_rowAttrs.SetAttr(attr, row); | |
2691 | } | |
2692 | ||
2693 | void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr *attr, int col) | |
2694 | { | |
2695 | if ( !m_data ) | |
2696 | InitData(); | |
2697 | ||
2698 | m_data->m_colAttrs.SetAttr(attr, col); | |
b99be8fb VZ |
2699 | } |
2700 | ||
4d60017a SN |
2701 | void wxGridCellAttrProvider::UpdateAttrRows( size_t pos, int numRows ) |
2702 | { | |
2703 | if ( m_data ) | |
2704 | { | |
2705 | m_data->m_cellAttrs.UpdateAttrRows( pos, numRows ); | |
2706 | ||
d1c0b4f9 | 2707 | m_data->m_rowAttrs.UpdateAttrRowsOrCols( pos, numRows ); |
4d60017a SN |
2708 | } |
2709 | } | |
2710 | ||
2711 | void wxGridCellAttrProvider::UpdateAttrCols( size_t pos, int numCols ) | |
2712 | { | |
2713 | if ( m_data ) | |
2714 | { | |
2715 | m_data->m_cellAttrs.UpdateAttrCols( pos, numCols ); | |
2716 | ||
d1c0b4f9 | 2717 | m_data->m_colAttrs.UpdateAttrRowsOrCols( pos, numCols ); |
4d60017a SN |
2718 | } |
2719 | } | |
2720 | ||
f2d76237 RD |
2721 | // ---------------------------------------------------------------------------- |
2722 | // wxGridTypeRegistry | |
2723 | // ---------------------------------------------------------------------------- | |
2724 | ||
2725 | wxGridTypeRegistry::~wxGridTypeRegistry() | |
2726 | { | |
b94ae1ea VZ |
2727 | size_t count = m_typeinfo.Count(); |
2728 | for ( size_t i = 0; i < count; i++ ) | |
f2d76237 RD |
2729 | delete m_typeinfo[i]; |
2730 | } | |
2731 | ||
2732 | ||
2733 | void wxGridTypeRegistry::RegisterDataType(const wxString& typeName, | |
2734 | wxGridCellRenderer* renderer, | |
2735 | wxGridCellEditor* editor) | |
2736 | { | |
f2d76237 RD |
2737 | wxGridDataTypeInfo* info = new wxGridDataTypeInfo(typeName, renderer, editor); |
2738 | ||
2739 | // is it already registered? | |
c4608a8a | 2740 | int loc = FindRegisteredDataType(typeName); |
39bcce60 VZ |
2741 | if ( loc != wxNOT_FOUND ) |
2742 | { | |
f2d76237 RD |
2743 | delete m_typeinfo[loc]; |
2744 | m_typeinfo[loc] = info; | |
2745 | } | |
39bcce60 VZ |
2746 | else |
2747 | { | |
f2d76237 RD |
2748 | m_typeinfo.Add(info); |
2749 | } | |
2750 | } | |
2751 | ||
c4608a8a VZ |
2752 | int wxGridTypeRegistry::FindRegisteredDataType(const wxString& typeName) |
2753 | { | |
2754 | size_t count = m_typeinfo.GetCount(); | |
2755 | for ( size_t i = 0; i < count; i++ ) | |
2756 | { | |
2757 | if ( typeName == m_typeinfo[i]->m_typeName ) | |
2758 | { | |
2759 | return i; | |
2760 | } | |
2761 | } | |
2762 | ||
2763 | return wxNOT_FOUND; | |
2764 | } | |
2765 | ||
f2d76237 RD |
2766 | int wxGridTypeRegistry::FindDataType(const wxString& typeName) |
2767 | { | |
c4608a8a VZ |
2768 | int index = FindRegisteredDataType(typeName); |
2769 | if ( index == wxNOT_FOUND ) | |
2770 | { | |
2771 | // check whether this is one of the standard ones, in which case | |
2772 | // register it "on the fly" | |
3a8c693a | 2773 | #if wxUSE_TEXTCTRL |
c4608a8a VZ |
2774 | if ( typeName == wxGRID_VALUE_STRING ) |
2775 | { | |
2776 | RegisterDataType(wxGRID_VALUE_STRING, | |
2777 | new wxGridCellStringRenderer, | |
2778 | new wxGridCellTextEditor); | |
3a8c693a VZ |
2779 | } else |
2780 | #endif // wxUSE_TEXTCTRL | |
2781 | #if wxUSE_CHECKBOX | |
2782 | if ( typeName == wxGRID_VALUE_BOOL ) | |
c4608a8a VZ |
2783 | { |
2784 | RegisterDataType(wxGRID_VALUE_BOOL, | |
2785 | new wxGridCellBoolRenderer, | |
2786 | new wxGridCellBoolEditor); | |
3a8c693a VZ |
2787 | } else |
2788 | #endif // wxUSE_CHECKBOX | |
2789 | #if wxUSE_TEXTCTRL | |
2790 | if ( typeName == wxGRID_VALUE_NUMBER ) | |
c4608a8a VZ |
2791 | { |
2792 | RegisterDataType(wxGRID_VALUE_NUMBER, | |
2793 | new wxGridCellNumberRenderer, | |
2794 | new wxGridCellNumberEditor); | |
2795 | } | |
2796 | else if ( typeName == wxGRID_VALUE_FLOAT ) | |
2797 | { | |
2798 | RegisterDataType(wxGRID_VALUE_FLOAT, | |
2799 | new wxGridCellFloatRenderer, | |
2800 | new wxGridCellFloatEditor); | |
3a8c693a VZ |
2801 | } else |
2802 | #endif // wxUSE_TEXTCTRL | |
2803 | #if wxUSE_COMBOBOX | |
2804 | if ( typeName == wxGRID_VALUE_CHOICE ) | |
c4608a8a VZ |
2805 | { |
2806 | RegisterDataType(wxGRID_VALUE_CHOICE, | |
2807 | new wxGridCellStringRenderer, | |
2808 | new wxGridCellChoiceEditor); | |
3a8c693a VZ |
2809 | } else |
2810 | #endif // wxUSE_COMBOBOX | |
c4608a8a VZ |
2811 | { |
2812 | return wxNOT_FOUND; | |
2813 | } | |
f2d76237 | 2814 | |
c4608a8a VZ |
2815 | // we get here only if just added the entry for this type, so return |
2816 | // the last index | |
2817 | index = m_typeinfo.GetCount() - 1; | |
2818 | } | |
2819 | ||
2820 | return index; | |
2821 | } | |
2822 | ||
2823 | int wxGridTypeRegistry::FindOrCloneDataType(const wxString& typeName) | |
2824 | { | |
2825 | int index = FindDataType(typeName); | |
2826 | if ( index == wxNOT_FOUND ) | |
2827 | { | |
2828 | // the first part of the typename is the "real" type, anything after ':' | |
2829 | // are the parameters for the renderer | |
2830 | index = FindDataType(typeName.BeforeFirst(_T(':'))); | |
2831 | if ( index == wxNOT_FOUND ) | |
2832 | { | |
2833 | return wxNOT_FOUND; | |
f2d76237 | 2834 | } |
c4608a8a VZ |
2835 | |
2836 | wxGridCellRenderer *renderer = GetRenderer(index); | |
2837 | wxGridCellRenderer *rendererOld = renderer; | |
2838 | renderer = renderer->Clone(); | |
2839 | rendererOld->DecRef(); | |
2840 | ||
2841 | wxGridCellEditor *editor = GetEditor(index); | |
2842 | wxGridCellEditor *editorOld = editor; | |
2843 | editor = editor->Clone(); | |
2844 | editorOld->DecRef(); | |
2845 | ||
2846 | // do it even if there are no parameters to reset them to defaults | |
2847 | wxString params = typeName.AfterFirst(_T(':')); | |
2848 | renderer->SetParameters(params); | |
2849 | editor->SetParameters(params); | |
2850 | ||
2851 | // register the new typename | |
c4608a8a VZ |
2852 | RegisterDataType(typeName, renderer, editor); |
2853 | ||
2854 | // we just registered it, it's the last one | |
2855 | index = m_typeinfo.GetCount() - 1; | |
f2d76237 RD |
2856 | } |
2857 | ||
c4608a8a | 2858 | return index; |
f2d76237 RD |
2859 | } |
2860 | ||
2861 | wxGridCellRenderer* wxGridTypeRegistry::GetRenderer(int index) | |
2862 | { | |
2863 | wxGridCellRenderer* renderer = m_typeinfo[index]->m_renderer; | |
faec5a43 SN |
2864 | if (renderer) |
2865 | renderer->IncRef(); | |
f2d76237 RD |
2866 | return renderer; |
2867 | } | |
2868 | ||
0b190b0f | 2869 | wxGridCellEditor* wxGridTypeRegistry::GetEditor(int index) |
f2d76237 RD |
2870 | { |
2871 | wxGridCellEditor* editor = m_typeinfo[index]->m_editor; | |
faec5a43 SN |
2872 | if (editor) |
2873 | editor->IncRef(); | |
f2d76237 RD |
2874 | return editor; |
2875 | } | |
2876 | ||
758cbedf VZ |
2877 | // ---------------------------------------------------------------------------- |
2878 | // wxGridTableBase | |
2879 | // ---------------------------------------------------------------------------- | |
2880 | ||
f85afd4e MB |
2881 | IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase, wxObject ) |
2882 | ||
2883 | ||
2884 | wxGridTableBase::wxGridTableBase() | |
f85afd4e MB |
2885 | { |
2886 | m_view = (wxGrid *) NULL; | |
b99be8fb | 2887 | m_attrProvider = (wxGridCellAttrProvider *) NULL; |
f85afd4e MB |
2888 | } |
2889 | ||
2890 | wxGridTableBase::~wxGridTableBase() | |
2891 | { | |
b99be8fb VZ |
2892 | delete m_attrProvider; |
2893 | } | |
2894 | ||
2895 | void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider *attrProvider) | |
2896 | { | |
2897 | delete m_attrProvider; | |
2898 | m_attrProvider = attrProvider; | |
f85afd4e MB |
2899 | } |
2900 | ||
f2d76237 RD |
2901 | bool wxGridTableBase::CanHaveAttributes() |
2902 | { | |
2903 | if ( ! GetAttrProvider() ) | |
2904 | { | |
2905 | // use the default attr provider by default | |
2906 | SetAttrProvider(new wxGridCellAttrProvider); | |
2907 | } | |
ca65c044 | 2908 | return true; |
f2d76237 RD |
2909 | } |
2910 | ||
19d7140e | 2911 | wxGridCellAttr *wxGridTableBase::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) |
b99be8fb VZ |
2912 | { |
2913 | if ( m_attrProvider ) | |
19d7140e | 2914 | return m_attrProvider->GetAttr(row, col, kind); |
b99be8fb VZ |
2915 | else |
2916 | return (wxGridCellAttr *)NULL; | |
2917 | } | |
2918 | ||
758cbedf | 2919 | void wxGridTableBase::SetAttr(wxGridCellAttr* attr, int row, int col) |
b99be8fb VZ |
2920 | { |
2921 | if ( m_attrProvider ) | |
2922 | { | |
19d7140e | 2923 | attr->SetKind(wxGridCellAttr::Cell); |
b99be8fb VZ |
2924 | m_attrProvider->SetAttr(attr, row, col); |
2925 | } | |
2926 | else | |
2927 | { | |
2928 | // as we take ownership of the pointer and don't store it, we must | |
2929 | // free it now | |
39bcce60 | 2930 | wxSafeDecRef(attr); |
b99be8fb VZ |
2931 | } |
2932 | } | |
2933 | ||
758cbedf VZ |
2934 | void wxGridTableBase::SetRowAttr(wxGridCellAttr *attr, int row) |
2935 | { | |
2936 | if ( m_attrProvider ) | |
2937 | { | |
19d7140e | 2938 | attr->SetKind(wxGridCellAttr::Row); |
758cbedf VZ |
2939 | m_attrProvider->SetRowAttr(attr, row); |
2940 | } | |
2941 | else | |
2942 | { | |
2943 | // as we take ownership of the pointer and don't store it, we must | |
2944 | // free it now | |
39bcce60 | 2945 | wxSafeDecRef(attr); |
758cbedf VZ |
2946 | } |
2947 | } | |
2948 | ||
2949 | void wxGridTableBase::SetColAttr(wxGridCellAttr *attr, int col) | |
2950 | { | |
2951 | if ( m_attrProvider ) | |
2952 | { | |
19d7140e | 2953 | attr->SetKind(wxGridCellAttr::Col); |
758cbedf VZ |
2954 | m_attrProvider->SetColAttr(attr, col); |
2955 | } | |
2956 | else | |
2957 | { | |
2958 | // as we take ownership of the pointer and don't store it, we must | |
2959 | // free it now | |
39bcce60 | 2960 | wxSafeDecRef(attr); |
758cbedf VZ |
2961 | } |
2962 | } | |
2963 | ||
aa5e1f75 SN |
2964 | bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos), |
2965 | size_t WXUNUSED(numRows) ) | |
f85afd4e | 2966 | { |
f6bcfd97 | 2967 | wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") ); |
8f177c8e | 2968 | |
ca65c044 | 2969 | return false; |
f85afd4e MB |
2970 | } |
2971 | ||
aa5e1f75 | 2972 | bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows) ) |
f85afd4e | 2973 | { |
f6bcfd97 | 2974 | wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function")); |
8f177c8e | 2975 | |
ca65c044 | 2976 | return false; |
f85afd4e MB |
2977 | } |
2978 | ||
aa5e1f75 SN |
2979 | bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos), |
2980 | size_t WXUNUSED(numRows) ) | |
f85afd4e | 2981 | { |
f6bcfd97 | 2982 | wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function")); |
8f177c8e | 2983 | |
ca65c044 | 2984 | return false; |
f85afd4e MB |
2985 | } |
2986 | ||
aa5e1f75 SN |
2987 | bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos), |
2988 | size_t WXUNUSED(numCols) ) | |
f85afd4e | 2989 | { |
f6bcfd97 | 2990 | wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function")); |
8f177c8e | 2991 | |
ca65c044 | 2992 | return false; |
f85afd4e MB |
2993 | } |
2994 | ||
aa5e1f75 | 2995 | bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols) ) |
f85afd4e | 2996 | { |
f6bcfd97 | 2997 | wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function")); |
8f177c8e | 2998 | |
ca65c044 | 2999 | return false; |
f85afd4e MB |
3000 | } |
3001 | ||
aa5e1f75 SN |
3002 | bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos), |
3003 | size_t WXUNUSED(numCols) ) | |
f85afd4e | 3004 | { |
f6bcfd97 | 3005 | wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function")); |
8f177c8e | 3006 | |
ca65c044 | 3007 | return false; |
f85afd4e MB |
3008 | } |
3009 | ||
3010 | ||
3011 | wxString wxGridTableBase::GetRowLabelValue( int row ) | |
3012 | { | |
3013 | wxString s; | |
f2d76237 RD |
3014 | s << row + 1; // RD: Starting the rows at zero confuses users, no matter |
3015 | // how much it makes sense to us geeks. | |
f85afd4e MB |
3016 | return s; |
3017 | } | |
3018 | ||
3019 | wxString wxGridTableBase::GetColLabelValue( int col ) | |
3020 | { | |
3021 | // default col labels are: | |
3022 | // cols 0 to 25 : A-Z | |
3023 | // cols 26 to 675 : AA-ZZ | |
3024 | // etc. | |
3025 | ||
3026 | wxString s; | |
3027 | unsigned int i, n; | |
3028 | for ( n = 1; ; n++ ) | |
3029 | { | |
fef5c556 | 3030 | s += (wxChar) (_T('A') + (wxChar)( col%26 )); |
f85afd4e MB |
3031 | col = col/26 - 1; |
3032 | if ( col < 0 ) break; | |
3033 | } | |
3034 | ||
3035 | // reverse the string... | |
3036 | wxString s2; | |
3037 | for ( i = 0; i < n; i++ ) | |
3038 | { | |
3039 | s2 += s[n-i-1]; | |
3040 | } | |
3041 | ||
3042 | return s2; | |
3043 | } | |
3044 | ||
3045 | ||
f2d76237 RD |
3046 | wxString wxGridTableBase::GetTypeName( int WXUNUSED(row), int WXUNUSED(col) ) |
3047 | { | |
816be743 | 3048 | return wxGRID_VALUE_STRING; |
f2d76237 RD |
3049 | } |
3050 | ||
3051 | bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row), int WXUNUSED(col), | |
3052 | const wxString& typeName ) | |
3053 | { | |
816be743 | 3054 | return typeName == wxGRID_VALUE_STRING; |
f2d76237 RD |
3055 | } |
3056 | ||
3057 | bool wxGridTableBase::CanSetValueAs( int row, int col, const wxString& typeName ) | |
3058 | { | |
3059 | return CanGetValueAs(row, col, typeName); | |
3060 | } | |
3061 | ||
3062 | long wxGridTableBase::GetValueAsLong( int WXUNUSED(row), int WXUNUSED(col) ) | |
3063 | { | |
3064 | return 0; | |
3065 | } | |
3066 | ||
3067 | double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row), int WXUNUSED(col) ) | |
3068 | { | |
3069 | return 0.0; | |
3070 | } | |
3071 | ||
3072 | bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row), int WXUNUSED(col) ) | |
3073 | { | |
ca65c044 | 3074 | return false; |
f2d76237 RD |
3075 | } |
3076 | ||
3077 | void wxGridTableBase::SetValueAsLong( int WXUNUSED(row), int WXUNUSED(col), | |
3078 | long WXUNUSED(value) ) | |
3079 | { | |
3080 | } | |
3081 | ||
3082 | void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row), int WXUNUSED(col), | |
3083 | double WXUNUSED(value) ) | |
3084 | { | |
3085 | } | |
3086 | ||
3087 | void wxGridTableBase::SetValueAsBool( int WXUNUSED(row), int WXUNUSED(col), | |
3088 | bool WXUNUSED(value) ) | |
3089 | { | |
3090 | } | |
3091 | ||
3092 | ||
3093 | void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row), int WXUNUSED(col), | |
3094 | const wxString& WXUNUSED(typeName) ) | |
3095 | { | |
3096 | return NULL; | |
3097 | } | |
3098 | ||
3099 | void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row), int WXUNUSED(col), | |
3100 | const wxString& WXUNUSED(typeName), | |
3101 | void* WXUNUSED(value) ) | |
3102 | { | |
3103 | } | |
3104 | ||
f85afd4e MB |
3105 | ////////////////////////////////////////////////////////////////////// |
3106 | // | |
3107 | // Message class for the grid table to send requests and notifications | |
3108 | // to the grid view | |
3109 | // | |
3110 | ||
3111 | wxGridTableMessage::wxGridTableMessage() | |
3112 | { | |
3113 | m_table = (wxGridTableBase *) NULL; | |
3114 | m_id = -1; | |
3115 | m_comInt1 = -1; | |
3116 | m_comInt2 = -1; | |
3117 | } | |
3118 | ||
3119 | wxGridTableMessage::wxGridTableMessage( wxGridTableBase *table, int id, | |
3120 | int commandInt1, int commandInt2 ) | |
3121 | { | |
3122 | m_table = table; | |
3123 | m_id = id; | |
3124 | m_comInt1 = commandInt1; | |
3125 | m_comInt2 = commandInt2; | |
3126 | } | |
3127 | ||
3128 | ||
3129 | ||
3130 | ////////////////////////////////////////////////////////////////////// | |
3131 | // | |
3132 | // A basic grid table for string data. An object of this class will | |
3133 | // created by wxGrid if you don't specify an alternative table class. | |
3134 | // | |
3135 | ||
223d09f6 | 3136 | WX_DEFINE_OBJARRAY(wxGridStringArray) |
f85afd4e MB |
3137 | |
3138 | IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase ) | |
3139 | ||
3140 | wxGridStringTable::wxGridStringTable() | |
3141 | : wxGridTableBase() | |
3142 | { | |
3143 | } | |
3144 | ||
3145 | wxGridStringTable::wxGridStringTable( int numRows, int numCols ) | |
3146 | : wxGridTableBase() | |
3147 | { | |
f85afd4e MB |
3148 | m_data.Alloc( numRows ); |
3149 | ||
3150 | wxArrayString sa; | |
3151 | sa.Alloc( numCols ); | |
27f35b66 | 3152 | sa.Add( wxEmptyString, numCols ); |
8f177c8e | 3153 | |
27f35b66 | 3154 | m_data.Add( sa, numRows ); |
f85afd4e MB |
3155 | } |
3156 | ||
3157 | wxGridStringTable::~wxGridStringTable() | |
3158 | { | |
3159 | } | |
3160 | ||
e32352cf | 3161 | int wxGridStringTable::GetNumberRows() |
f85afd4e MB |
3162 | { |
3163 | return m_data.GetCount(); | |
3164 | } | |
3165 | ||
e32352cf | 3166 | int wxGridStringTable::GetNumberCols() |
f85afd4e MB |
3167 | { |
3168 | if ( m_data.GetCount() > 0 ) | |
3169 | return m_data[0].GetCount(); | |
3170 | else | |
3171 | return 0; | |
3172 | } | |
3173 | ||
3174 | wxString wxGridStringTable::GetValue( int row, int col ) | |
3175 | { | |
3e13956a RD |
3176 | wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()), |
3177 | wxEmptyString, | |
3178 | _T("invalid row or column index in wxGridStringTable") ); | |
af547d51 | 3179 | |
f85afd4e MB |
3180 | return m_data[row][col]; |
3181 | } | |
3182 | ||
f2d76237 | 3183 | void wxGridStringTable::SetValue( int row, int col, const wxString& value ) |
f85afd4e | 3184 | { |
3e13956a RD |
3185 | wxCHECK_RET( (row < GetNumberRows()) && (col < GetNumberCols()), |
3186 | _T("invalid row or column index in wxGridStringTable") ); | |
af547d51 | 3187 | |
f2d76237 | 3188 | m_data[row][col] = value; |
f85afd4e MB |
3189 | } |
3190 | ||
3191 | bool wxGridStringTable::IsEmptyCell( int row, int col ) | |
3192 | { | |
3e13956a RD |
3193 | wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()), |
3194 | true, | |
af547d51 VZ |
3195 | _T("invalid row or column index in wxGridStringTable") ); |
3196 | ||
f85afd4e MB |
3197 | return (m_data[row][col] == wxEmptyString); |
3198 | } | |
3199 | ||
f85afd4e MB |
3200 | void wxGridStringTable::Clear() |
3201 | { | |
3202 | int row, col; | |
3203 | int numRows, numCols; | |
8f177c8e | 3204 | |
f85afd4e MB |
3205 | numRows = m_data.GetCount(); |
3206 | if ( numRows > 0 ) | |
3207 | { | |
3208 | numCols = m_data[0].GetCount(); | |
3209 | ||
3210 | for ( row = 0; row < numRows; row++ ) | |
3211 | { | |
3212 | for ( col = 0; col < numCols; col++ ) | |
3213 | { | |
3214 | m_data[row][col] = wxEmptyString; | |
3215 | } | |
3216 | } | |
3217 | } | |
3218 | } | |
3219 | ||
3220 | ||
3221 | bool wxGridStringTable::InsertRows( size_t pos, size_t numRows ) | |
3222 | { | |
f85afd4e | 3223 | size_t curNumRows = m_data.GetCount(); |
f6bcfd97 BP |
3224 | size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : |
3225 | ( GetView() ? GetView()->GetNumberCols() : 0 ) ); | |
8f177c8e | 3226 | |
f85afd4e MB |
3227 | if ( pos >= curNumRows ) |
3228 | { | |
3229 | return AppendRows( numRows ); | |
3230 | } | |
8f177c8e | 3231 | |
f85afd4e MB |
3232 | wxArrayString sa; |
3233 | sa.Alloc( curNumCols ); | |
27f35b66 SN |
3234 | sa.Add( wxEmptyString, curNumCols ); |
3235 | m_data.Insert( sa, pos, numRows ); | |
f85afd4e MB |
3236 | if ( GetView() ) |
3237 | { | |
3238 | wxGridTableMessage msg( this, | |
3239 | wxGRIDTABLE_NOTIFY_ROWS_INSERTED, | |
3240 | pos, | |
3241 | numRows ); | |
8f177c8e | 3242 | |
f85afd4e MB |
3243 | GetView()->ProcessTableMessage( msg ); |
3244 | } | |
3245 | ||
ca65c044 | 3246 | return true; |
f85afd4e MB |
3247 | } |
3248 | ||
3249 | bool wxGridStringTable::AppendRows( size_t numRows ) | |
3250 | { | |
f85afd4e | 3251 | size_t curNumRows = m_data.GetCount(); |
f6bcfd97 BP |
3252 | size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : |
3253 | ( GetView() ? GetView()->GetNumberCols() : 0 ) ); | |
8f177c8e | 3254 | |
f85afd4e MB |
3255 | wxArrayString sa; |
3256 | if ( curNumCols > 0 ) | |
3257 | { | |
3258 | sa.Alloc( curNumCols ); | |
27f35b66 | 3259 | sa.Add( wxEmptyString, curNumCols ); |
f85afd4e | 3260 | } |
8f177c8e | 3261 | |
27f35b66 | 3262 | m_data.Add( sa, numRows ); |
f85afd4e MB |
3263 | |
3264 | if ( GetView() ) | |
3265 | { | |
3266 | wxGridTableMessage msg( this, | |
3267 | wxGRIDTABLE_NOTIFY_ROWS_APPENDED, | |
3268 | numRows ); | |
8f177c8e | 3269 | |
f85afd4e MB |
3270 | GetView()->ProcessTableMessage( msg ); |
3271 | } | |
3272 | ||
ca65c044 | 3273 | return true; |
f85afd4e MB |
3274 | } |
3275 | ||
3276 | bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows ) | |
3277 | { | |
f85afd4e | 3278 | size_t curNumRows = m_data.GetCount(); |
8f177c8e | 3279 | |
f85afd4e MB |
3280 | if ( pos >= curNumRows ) |
3281 | { | |
e91d2033 VZ |
3282 | wxFAIL_MSG( wxString::Format |
3283 | ( | |
3284 | wxT("Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"), | |
3285 | (unsigned long)pos, | |
3286 | (unsigned long)numRows, | |
3287 | (unsigned long)curNumRows | |
3288 | ) ); | |
3289 | ||
ca65c044 | 3290 | return false; |
f85afd4e MB |
3291 | } |
3292 | ||
3293 | if ( numRows > curNumRows - pos ) | |
3294 | { | |
3295 | numRows = curNumRows - pos; | |
3296 | } | |
8f177c8e | 3297 | |
f85afd4e MB |
3298 | if ( numRows >= curNumRows ) |
3299 | { | |
d57ad377 | 3300 | m_data.Clear(); |
f85afd4e MB |
3301 | } |
3302 | else | |
3303 | { | |
27f35b66 | 3304 | m_data.RemoveAt( pos, numRows ); |
f85afd4e | 3305 | } |
f85afd4e MB |
3306 | if ( GetView() ) |
3307 | { | |
3308 | wxGridTableMessage msg( this, | |
3309 | wxGRIDTABLE_NOTIFY_ROWS_DELETED, | |
3310 | pos, | |
3311 | numRows ); | |
8f177c8e | 3312 | |
f85afd4e MB |
3313 | GetView()->ProcessTableMessage( msg ); |
3314 | } | |
3315 | ||
ca65c044 | 3316 | return true; |
f85afd4e MB |
3317 | } |
3318 | ||
3319 | bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) | |
3320 | { | |
3321 | size_t row, col; | |
3322 | ||
3323 | size_t curNumRows = m_data.GetCount(); | |
f6bcfd97 BP |
3324 | size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : |
3325 | ( GetView() ? GetView()->GetNumberCols() : 0 ) ); | |
8f177c8e | 3326 | |
f85afd4e MB |
3327 | if ( pos >= curNumCols ) |
3328 | { | |
3329 | return AppendCols( numCols ); | |
3330 | } | |
3331 | ||
3332 | for ( row = 0; row < curNumRows; row++ ) | |
3333 | { | |
3334 | for ( col = pos; col < pos + numCols; col++ ) | |
3335 | { | |
3336 | m_data[row].Insert( wxEmptyString, col ); | |
3337 | } | |
3338 | } | |
f85afd4e MB |
3339 | if ( GetView() ) |
3340 | { | |
3341 | wxGridTableMessage msg( this, | |
3342 | wxGRIDTABLE_NOTIFY_COLS_INSERTED, | |
3343 | pos, | |
3344 | numCols ); | |
8f177c8e | 3345 | |
f85afd4e MB |
3346 | GetView()->ProcessTableMessage( msg ); |
3347 | } | |
3348 | ||
ca65c044 | 3349 | return true; |
f85afd4e MB |
3350 | } |
3351 | ||
3352 | bool wxGridStringTable::AppendCols( size_t numCols ) | |
3353 | { | |
27f35b66 | 3354 | size_t row; |
f85afd4e MB |
3355 | |
3356 | size_t curNumRows = m_data.GetCount(); | |
f6bcfd97 | 3357 | #if 0 |
f85afd4e MB |
3358 | if ( !curNumRows ) |
3359 | { | |
3360 | // TODO: something better than this ? | |
3361 | // | |
f6bcfd97 | 3362 | wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\nCall AppendRows() first") ); |
ca65c044 | 3363 | return false; |
f85afd4e | 3364 | } |
f6bcfd97 | 3365 | #endif |
8f177c8e | 3366 | |
f85afd4e MB |
3367 | for ( row = 0; row < curNumRows; row++ ) |
3368 | { | |
27f35b66 | 3369 | m_data[row].Add( wxEmptyString, numCols ); |
f85afd4e MB |
3370 | } |
3371 | ||
3372 | if ( GetView() ) | |
3373 | { | |
3374 | wxGridTableMessage msg( this, | |
3375 | wxGRIDTABLE_NOTIFY_COLS_APPENDED, | |
3376 | numCols ); | |
8f177c8e | 3377 | |
f85afd4e MB |
3378 | GetView()->ProcessTableMessage( msg ); |
3379 | } | |
3380 | ||
ca65c044 | 3381 | return true; |
f85afd4e MB |
3382 | } |
3383 | ||
3384 | bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols ) | |
3385 | { | |
27f35b66 | 3386 | size_t row; |
f85afd4e MB |
3387 | |
3388 | size_t curNumRows = m_data.GetCount(); | |
f6bcfd97 BP |
3389 | size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : |
3390 | ( GetView() ? GetView()->GetNumberCols() : 0 ) ); | |
8f177c8e | 3391 | |
f85afd4e MB |
3392 | if ( pos >= curNumCols ) |
3393 | { | |
e91d2033 VZ |
3394 | wxFAIL_MSG( wxString::Format |
3395 | ( | |
3396 | wxT("Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"), | |
3397 | (unsigned long)pos, | |
3398 | (unsigned long)numCols, | |
3399 | (unsigned long)curNumCols | |
3400 | ) ); | |
ca65c044 | 3401 | return false; |
f85afd4e MB |
3402 | } |
3403 | ||
3404 | if ( numCols > curNumCols - pos ) | |
3405 | { | |
8f177c8e | 3406 | numCols = curNumCols - pos; |
f85afd4e MB |
3407 | } |
3408 | ||
3409 | for ( row = 0; row < curNumRows; row++ ) | |
3410 | { | |
3411 | if ( numCols >= curNumCols ) | |
3412 | { | |
dcdce64e | 3413 | m_data[row].Clear(); |
f85afd4e MB |
3414 | } |
3415 | else | |
3416 | { | |
27f35b66 | 3417 | m_data[row].RemoveAt( pos, numCols ); |
f85afd4e MB |
3418 | } |
3419 | } | |
f85afd4e MB |
3420 | if ( GetView() ) |
3421 | { | |
3422 | wxGridTableMessage msg( this, | |
3423 | wxGRIDTABLE_NOTIFY_COLS_DELETED, | |
3424 | pos, | |
3425 | numCols ); | |
8f177c8e | 3426 | |
f85afd4e MB |
3427 | GetView()->ProcessTableMessage( msg ); |
3428 | } | |
3429 | ||
ca65c044 | 3430 | return true; |
f85afd4e MB |
3431 | } |
3432 | ||
3433 | wxString wxGridStringTable::GetRowLabelValue( int row ) | |
3434 | { | |
3435 | if ( row > (int)(m_rowLabels.GetCount()) - 1 ) | |
3436 | { | |
3437 | // using default label | |
3438 | // | |
3439 | return wxGridTableBase::GetRowLabelValue( row ); | |
3440 | } | |
3441 | else | |
3442 | { | |
3443 | return m_rowLabels[ row ]; | |
3444 | } | |
3445 | } | |
3446 | ||
3447 | wxString wxGridStringTable::GetColLabelValue( int col ) | |
3448 | { | |
3449 | if ( col > (int)(m_colLabels.GetCount()) - 1 ) | |
3450 | { | |
3451 | // using default label | |
3452 | // | |
3453 | return wxGridTableBase::GetColLabelValue( col ); | |
3454 | } | |
3455 | else | |
3456 | { | |
3457 | return m_colLabels[ col ]; | |
3458 | } | |
3459 | } | |
3460 | ||
3461 | void wxGridStringTable::SetRowLabelValue( int row, const wxString& value ) | |
3462 | { | |
3463 | if ( row > (int)(m_rowLabels.GetCount()) - 1 ) | |
3464 | { | |
3465 | int n = m_rowLabels.GetCount(); | |
3466 | int i; | |
3467 | for ( i = n; i <= row; i++ ) | |
3468 | { | |
3469 | m_rowLabels.Add( wxGridTableBase::GetRowLabelValue(i) ); | |
3470 | } | |
3471 | } | |
3472 | ||
3473 | m_rowLabels[row] = value; | |
3474 | } | |
3475 | ||
3476 | void wxGridStringTable::SetColLabelValue( int col, const wxString& value ) | |
3477 | { | |
3478 | if ( col > (int)(m_colLabels.GetCount()) - 1 ) | |
3479 | { | |
3480 | int n = m_colLabels.GetCount(); | |
3481 | int i; | |
3482 | for ( i = n; i <= col; i++ ) | |
3483 | { | |
3484 | m_colLabels.Add( wxGridTableBase::GetColLabelValue(i) ); | |
3485 | } | |
3486 | } | |
3487 | ||
3488 | m_colLabels[col] = value; | |
3489 | } | |
3490 | ||
3491 | ||
3492 | ||
f85afd4e | 3493 | ////////////////////////////////////////////////////////////////////// |
2d66e025 MB |
3494 | ////////////////////////////////////////////////////////////////////// |
3495 | ||
3496 | IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow, wxWindow ) | |
3497 | ||
3498 | BEGIN_EVENT_TABLE( wxGridRowLabelWindow, wxWindow ) | |
3499 | EVT_PAINT( wxGridRowLabelWindow::OnPaint ) | |
b51c3f27 | 3500 | EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel) |
2d66e025 MB |
3501 | EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent ) |
3502 | EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown ) | |
f6bcfd97 | 3503 | EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp ) |
2d66e025 MB |
3504 | END_EVENT_TABLE() |
3505 | ||
60ff3b99 VZ |
3506 | wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid *parent, |
3507 | wxWindowID id, | |
2d66e025 | 3508 | const wxPoint &pos, const wxSize &size ) |
73bb6776 | 3509 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE ) |
2d66e025 MB |
3510 | { |
3511 | m_owner = parent; | |
3512 | } | |
3513 | ||
aa5e1f75 | 3514 | void wxGridRowLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
2d66e025 MB |
3515 | { |
3516 | wxPaintDC dc(this); | |
3517 | ||
3518 | // NO - don't do this because it will set both the x and y origin | |
3519 | // coords to match the parent scrolled window and we just want to | |
3520 | // set the y coord - MB | |
3521 | // | |
3522 | // m_owner->PrepareDC( dc ); | |
60ff3b99 | 3523 | |
790ad94f | 3524 | int x, y; |
2d66e025 MB |
3525 | m_owner->CalcUnscrolledPosition( 0, 0, &x, &y ); |
3526 | dc.SetDeviceOrigin( 0, -y ); | |
60ff3b99 | 3527 | |
d10f4bf9 VZ |
3528 | wxArrayInt rows = m_owner->CalcRowLabelsExposed( GetUpdateRegion() ); |
3529 | m_owner->DrawRowLabels( dc , rows ); | |
2d66e025 MB |
3530 | } |
3531 | ||
3532 | ||
3533 | void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent& event ) | |
3534 | { | |
3535 | m_owner->ProcessRowLabelMouseEvent( event ); | |
3536 | } | |
3537 | ||
3538 | ||
b51c3f27 RD |
3539 | void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent& event ) |
3540 | { | |
3541 | m_owner->GetEventHandler()->ProcessEvent(event); | |
3542 | } | |
3543 | ||
3544 | ||
2d66e025 MB |
3545 | // This seems to be required for wxMotif otherwise the mouse |
3546 | // cursor must be in the cell edit control to get key events | |
3547 | // | |
3548 | void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent& event ) | |
3549 | { | |
ffdd3c98 | 3550 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
2d66e025 MB |
3551 | } |
3552 | ||
f6bcfd97 BP |
3553 | void wxGridRowLabelWindow::OnKeyUp( wxKeyEvent& event ) |
3554 | { | |
ffdd3c98 | 3555 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
f6bcfd97 BP |
3556 | } |
3557 | ||
2d66e025 MB |
3558 | |
3559 | ||
3560 | ////////////////////////////////////////////////////////////////////// | |
3561 | ||
3562 | IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow, wxWindow ) | |
3563 | ||
3564 | BEGIN_EVENT_TABLE( wxGridColLabelWindow, wxWindow ) | |
3565 | EVT_PAINT( wxGridColLabelWindow::OnPaint ) | |
b51c3f27 | 3566 | EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel) |
2d66e025 MB |
3567 | EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent ) |
3568 | EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown ) | |
f6bcfd97 | 3569 | EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp ) |
2d66e025 MB |
3570 | END_EVENT_TABLE() |
3571 | ||
60ff3b99 VZ |
3572 | wxGridColLabelWindow::wxGridColLabelWindow( wxGrid *parent, |
3573 | wxWindowID id, | |
2d66e025 | 3574 | const wxPoint &pos, const wxSize &size ) |
73bb6776 | 3575 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE ) |
2d66e025 MB |
3576 | { |
3577 | m_owner = parent; | |
3578 | } | |
3579 | ||
aa5e1f75 | 3580 | void wxGridColLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
2d66e025 MB |
3581 | { |
3582 | wxPaintDC dc(this); | |
3583 | ||
3584 | // NO - don't do this because it will set both the x and y origin | |
3585 | // coords to match the parent scrolled window and we just want to | |
3586 | // set the x coord - MB | |
3587 | // | |
3588 | // m_owner->PrepareDC( dc ); | |
60ff3b99 | 3589 | |
790ad94f | 3590 | int x, y; |
2d66e025 MB |
3591 | m_owner->CalcUnscrolledPosition( 0, 0, &x, &y ); |
3592 | dc.SetDeviceOrigin( -x, 0 ); | |
3593 | ||
d10f4bf9 VZ |
3594 | wxArrayInt cols = m_owner->CalcColLabelsExposed( GetUpdateRegion() ); |
3595 | m_owner->DrawColLabels( dc , cols ); | |
2d66e025 MB |
3596 | } |
3597 | ||
3598 | ||
3599 | void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent& event ) | |
3600 | { | |
3601 | m_owner->ProcessColLabelMouseEvent( event ); | |
3602 | } | |
3603 | ||
b51c3f27 RD |
3604 | void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent& event ) |
3605 | { | |
3606 | m_owner->GetEventHandler()->ProcessEvent(event); | |
3607 | } | |
3608 | ||
2d66e025 MB |
3609 | |
3610 | // This seems to be required for wxMotif otherwise the mouse | |
3611 | // cursor must be in the cell edit control to get key events | |
3612 | // | |
3613 | void wxGridColLabelWindow::OnKeyDown( wxKeyEvent& event ) | |
3614 | { | |
ffdd3c98 | 3615 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
2d66e025 MB |
3616 | } |
3617 | ||
f6bcfd97 BP |
3618 | void wxGridColLabelWindow::OnKeyUp( wxKeyEvent& event ) |
3619 | { | |
ffdd3c98 | 3620 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
f6bcfd97 BP |
3621 | } |
3622 | ||
2d66e025 MB |
3623 | |
3624 | ||
3625 | ////////////////////////////////////////////////////////////////////// | |
3626 | ||
3627 | IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow, wxWindow ) | |
3628 | ||
3629 | BEGIN_EVENT_TABLE( wxGridCornerLabelWindow, wxWindow ) | |
b51c3f27 | 3630 | EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel) |
2d66e025 | 3631 | EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent ) |
d2fdd8d2 | 3632 | EVT_PAINT( wxGridCornerLabelWindow::OnPaint) |
2d66e025 | 3633 | EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown ) |
f6bcfd97 | 3634 | EVT_KEY_UP( wxGridCornerLabelWindow::OnKeyUp ) |
2d66e025 MB |
3635 | END_EVENT_TABLE() |
3636 | ||
60ff3b99 VZ |
3637 | wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid *parent, |
3638 | wxWindowID id, | |
2d66e025 | 3639 | const wxPoint &pos, const wxSize &size ) |
73bb6776 | 3640 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE ) |
2d66e025 MB |
3641 | { |
3642 | m_owner = parent; | |
3643 | } | |
3644 | ||
d2fdd8d2 RR |
3645 | void wxGridCornerLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
3646 | { | |
3647 | wxPaintDC dc(this); | |
b99be8fb | 3648 | |
d2fdd8d2 RR |
3649 | int client_height = 0; |
3650 | int client_width = 0; | |
3651 | GetClientSize( &client_width, &client_height ); | |
b99be8fb | 3652 | |
4d1bc39c RR |
3653 | #if __WXGTK__ |
3654 | wxRect rect; | |
3655 | rect.SetX( 1 ); | |
3656 | rect.SetY( 1 ); | |
3657 | rect.SetWidth( client_width - 2 ); | |
3658 | rect.SetHeight( client_height - 2 ); | |
ec157c8f | 3659 | |
4d1bc39c RR |
3660 | wxRendererNative::Get().DrawHeaderButton( this, dc, rect, 0 ); |
3661 | #else | |
73145b0e | 3662 | dc.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW),1, wxSOLID) ); |
d2fdd8d2 RR |
3663 | dc.DrawLine( client_width-1, client_height-1, client_width-1, 0 ); |
3664 | dc.DrawLine( client_width-1, client_height-1, 0, client_height-1 ); | |
d2fdd8d2 RR |
3665 | dc.DrawLine( 0, 0, client_width, 0 ); |
3666 | dc.DrawLine( 0, 0, 0, client_height ); | |
73145b0e JS |
3667 | |
3668 | dc.SetPen( *wxWHITE_PEN ); | |
3669 | dc.DrawLine( 1, 1, client_width-1, 1 ); | |
3670 | dc.DrawLine( 1, 1, 1, client_height-1 ); | |
4d1bc39c | 3671 | #endif |
d2fdd8d2 RR |
3672 | } |
3673 | ||
2d66e025 MB |
3674 | |
3675 | void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent& event ) | |
3676 | { | |
3677 | m_owner->ProcessCornerLabelMouseEvent( event ); | |
3678 | } | |
3679 | ||
3680 | ||
b51c3f27 RD |
3681 | void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent& event ) |
3682 | { | |
3683 | m_owner->GetEventHandler()->ProcessEvent(event); | |
3684 | } | |
3685 | ||
2d66e025 MB |
3686 | // This seems to be required for wxMotif otherwise the mouse |
3687 | // cursor must be in the cell edit control to get key events | |
3688 | // | |
3689 | void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent& event ) | |
3690 | { | |
ffdd3c98 | 3691 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
2d66e025 MB |
3692 | } |
3693 | ||
f6bcfd97 BP |
3694 | void wxGridCornerLabelWindow::OnKeyUp( wxKeyEvent& event ) |
3695 | { | |
ffdd3c98 | 3696 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
f6bcfd97 BP |
3697 | } |
3698 | ||
2d66e025 MB |
3699 | |
3700 | ||
f85afd4e MB |
3701 | ////////////////////////////////////////////////////////////////////// |
3702 | ||
59ddac01 | 3703 | IMPLEMENT_DYNAMIC_CLASS( wxGridWindow, wxWindow ) |
2d66e025 | 3704 | |
59ddac01 | 3705 | BEGIN_EVENT_TABLE( wxGridWindow, wxWindow ) |
2d66e025 | 3706 | EVT_PAINT( wxGridWindow::OnPaint ) |
b51c3f27 | 3707 | EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel) |
2d66e025 MB |
3708 | EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent ) |
3709 | EVT_KEY_DOWN( wxGridWindow::OnKeyDown ) | |
f6bcfd97 | 3710 | EVT_KEY_UP( wxGridWindow::OnKeyUp ) |
80acaf25 JS |
3711 | EVT_SET_FOCUS( wxGridWindow::OnFocus ) |
3712 | EVT_KILL_FOCUS( wxGridWindow::OnFocus ) | |
2796cce3 | 3713 | EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground ) |
2d66e025 MB |
3714 | END_EVENT_TABLE() |
3715 | ||
60ff3b99 VZ |
3716 | wxGridWindow::wxGridWindow( wxGrid *parent, |
3717 | wxGridRowLabelWindow *rowLblWin, | |
2d66e025 | 3718 | wxGridColLabelWindow *colLblWin, |
04418332 VZ |
3719 | wxWindowID id, |
3720 | const wxPoint &pos, | |
3721 | const wxSize &size ) | |
73bb6776 | 3722 | : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxCLIP_CHILDREN|wxFULL_REPAINT_ON_RESIZE, |
04418332 | 3723 | wxT("grid window") ) |
73145b0e | 3724 | |
2d66e025 MB |
3725 | { |
3726 | m_owner = parent; | |
3727 | m_rowLabelWin = rowLblWin; | |
3728 | m_colLabelWin = colLblWin; | |
2d66e025 MB |
3729 | } |
3730 | ||
3731 | ||
2d66e025 MB |
3732 | void wxGridWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
3733 | { | |
3734 | wxPaintDC dc( this ); | |
3735 | m_owner->PrepareDC( dc ); | |
796df70a | 3736 | wxRegion reg = GetUpdateRegion(); |
d10f4bf9 VZ |
3737 | wxGridCellCoordsArray DirtyCells = m_owner->CalcCellsExposed( reg ); |
3738 | m_owner->DrawGridCellArea( dc , DirtyCells); | |
9496deb5 | 3739 | #if WXGRID_DRAW_LINES |
796df70a SN |
3740 | m_owner->DrawAllGridLines( dc, reg ); |
3741 | #endif | |
a5777624 | 3742 | m_owner->DrawGridSpace( dc ); |
d10f4bf9 | 3743 | m_owner->DrawHighlight( dc , DirtyCells ); |
2d66e025 MB |
3744 | } |
3745 | ||
3746 | ||
3747 | void wxGridWindow::ScrollWindow( int dx, int dy, const wxRect *rect ) | |
3748 | { | |
59ddac01 | 3749 | wxWindow::ScrollWindow( dx, dy, rect ); |
2d66e025 MB |
3750 | m_rowLabelWin->ScrollWindow( 0, dy, rect ); |
3751 | m_colLabelWin->ScrollWindow( dx, 0, rect ); | |
3752 | } | |
3753 | ||
3754 | ||
3755 | void wxGridWindow::OnMouseEvent( wxMouseEvent& event ) | |
3756 | { | |
3757 | m_owner->ProcessGridCellMouseEvent( event ); | |
3758 | } | |
3759 | ||
b51c3f27 RD |
3760 | void wxGridWindow::OnMouseWheel( wxMouseEvent& event ) |
3761 | { | |
3762 | m_owner->GetEventHandler()->ProcessEvent(event); | |
3763 | } | |
2d66e025 | 3764 | |
f6bcfd97 | 3765 | // This seems to be required for wxMotif/wxGTK otherwise the mouse |
2d66e025 MB |
3766 | // cursor must be in the cell edit control to get key events |
3767 | // | |
3768 | void wxGridWindow::OnKeyDown( wxKeyEvent& event ) | |
3769 | { | |
ffdd3c98 | 3770 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
2d66e025 | 3771 | } |
f85afd4e | 3772 | |
f6bcfd97 BP |
3773 | void wxGridWindow::OnKeyUp( wxKeyEvent& event ) |
3774 | { | |
ffdd3c98 | 3775 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); |
f6bcfd97 | 3776 | } |
7c8a8ad5 | 3777 | |
aa5e1f75 | 3778 | void wxGridWindow::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ) |
8dd4f536 | 3779 | { |
8dd4f536 | 3780 | } |
025562fe | 3781 | |
80acaf25 JS |
3782 | void wxGridWindow::OnFocus(wxFocusEvent& event) |
3783 | { | |
3784 | if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) | |
3785 | event.Skip(); | |
3786 | } | |
2d66e025 MB |
3787 | |
3788 | ////////////////////////////////////////////////////////////////////// | |
3789 | ||
33188aa4 SN |
3790 | // Internal Helper function for computing row or column from some |
3791 | // (unscrolled) coordinate value, using either | |
70e8d961 | 3792 | // m_defaultRowHeight/m_defaultColWidth or binary search on array |
33188aa4 SN |
3793 | // of m_rowBottoms/m_ColRights to speed up the search! |
3794 | ||
3795 | // Internal helper macros for simpler use of that function | |
3796 | ||
3797 | static int CoordToRowOrCol(int coord, int defaultDist, int minDist, | |
64e15340 | 3798 | const wxArrayInt& BorderArray, int nMax, |
a967f048 | 3799 | bool clipToMinMax); |
33188aa4 SN |
3800 | |
3801 | #define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \ | |
b8d24d4e | 3802 | m_minAcceptableColWidth, \ |
ca65c044 | 3803 | m_colRights, m_numCols, true) |
33188aa4 | 3804 | #define internalYToRow(y) CoordToRowOrCol(y, m_defaultRowHeight, \ |
b8d24d4e | 3805 | m_minAcceptableRowHeight, \ |
ca65c044 | 3806 | m_rowBottoms, m_numRows, true) |
33188aa4 | 3807 | ///////////////////////////////////////////////////////////////////// |
07296f0b | 3808 | |
b0a877ec | 3809 | #if wxUSE_EXTENDED_RTTI |
73c36334 JS |
3810 | WX_DEFINE_FLAGS( wxGridStyle ) |
3811 | ||
3ff066a4 | 3812 | wxBEGIN_FLAGS( wxGridStyle ) |
73c36334 JS |
3813 | // new style border flags, we put them first to |
3814 | // use them for streaming out | |
3ff066a4 SC |
3815 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
3816 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
3817 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
3818 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
3819 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
3820 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
ca65c044 | 3821 | |
73c36334 | 3822 | // old style border flags |
3ff066a4 SC |
3823 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
3824 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
3825 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
3826 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
3827 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 3828 | wxFLAGS_MEMBER(wxBORDER) |
73c36334 JS |
3829 | |
3830 | // standard window styles | |
3ff066a4 SC |
3831 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
3832 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
3833 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
3834 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 3835 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
3836 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
3837 | wxFLAGS_MEMBER(wxVSCROLL) | |
3838 | wxFLAGS_MEMBER(wxHSCROLL) | |
73c36334 | 3839 | |
3ff066a4 | 3840 | wxEND_FLAGS( wxGridStyle ) |
73c36334 | 3841 | |
b0a877ec SC |
3842 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxGrid, wxScrolledWindow,"wx/grid.h") |
3843 | ||
3ff066a4 SC |
3844 | wxBEGIN_PROPERTIES_TABLE(wxGrid) |
3845 | wxHIDE_PROPERTY( Children ) | |
af498247 | 3846 | wxPROPERTY_FLAGS( WindowStyle , wxGridStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 3847 | wxEND_PROPERTIES_TABLE() |
b0a877ec | 3848 | |
3ff066a4 SC |
3849 | wxBEGIN_HANDLERS_TABLE(wxGrid) |
3850 | wxEND_HANDLERS_TABLE() | |
b0a877ec | 3851 | |
ca65c044 | 3852 | wxCONSTRUCTOR_5( wxGrid , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
b0a877ec SC |
3853 | |
3854 | /* | |
2d0c2e79 | 3855 | Content-type: text/html ]>