]> git.saurik.com Git - wxWidgets.git/blame - src/generic/grid.cpp
eVC4 updates
[wxWidgets.git] / src / generic / grid.cpp
Content-type: text/html ]> git.saurik.com Git - wxWidgets.git/blame - src/generic/grid.cpp


500 - Internal Server Error

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