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