]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/generic/grid.h | |
3 | // Purpose: wxGrid and related classes | |
4 | // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn) | |
5 | // Modified by: Santiago Palacios | |
6 | // Created: 1/08/1999 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Michael Bedward | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_GENERIC_GRID_H_ | |
13 | #define _WX_GENERIC_GRID_H_ | |
14 | ||
15 | #include "wx/defs.h" | |
16 | ||
17 | #if wxUSE_GRID | |
18 | ||
19 | #include "wx/scrolwin.h" | |
20 | ||
21 | // ---------------------------------------------------------------------------- | |
22 | // constants | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
25 | extern WXDLLIMPEXP_DATA_ADV(const char) wxGridNameStr[]; | |
26 | ||
27 | // Default parameters for wxGrid | |
28 | // | |
29 | #define WXGRID_DEFAULT_NUMBER_ROWS 10 | |
30 | #define WXGRID_DEFAULT_NUMBER_COLS 10 | |
31 | #if defined(__WXMSW__) || defined(__WXGTK20__) | |
32 | #define WXGRID_DEFAULT_ROW_HEIGHT 25 | |
33 | #else | |
34 | #define WXGRID_DEFAULT_ROW_HEIGHT 30 | |
35 | #endif // __WXMSW__ | |
36 | #define WXGRID_DEFAULT_COL_WIDTH 80 | |
37 | #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32 | |
38 | #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82 | |
39 | #define WXGRID_LABEL_EDGE_ZONE 2 | |
40 | #define WXGRID_MIN_ROW_HEIGHT 15 | |
41 | #define WXGRID_MIN_COL_WIDTH 15 | |
42 | #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16 | |
43 | ||
44 | // type names for grid table values | |
45 | #define wxGRID_VALUE_STRING _T("string") | |
46 | #define wxGRID_VALUE_BOOL _T("bool") | |
47 | #define wxGRID_VALUE_NUMBER _T("long") | |
48 | #define wxGRID_VALUE_FLOAT _T("double") | |
49 | #define wxGRID_VALUE_CHOICE _T("choice") | |
50 | ||
51 | #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING | |
52 | #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER | |
53 | ||
54 | // magic constant which tells (to some functions) to automatically calculate | |
55 | // the appropriate size | |
56 | #define wxGRID_AUTOSIZE (-1) | |
57 | ||
58 | // many wxGrid methods work either with columns or rows, this enum is used for | |
59 | // the parameter indicating which one should it be | |
60 | enum wxGridDirection | |
61 | { | |
62 | wxGRID_COLUMN, | |
63 | wxGRID_ROW | |
64 | }; | |
65 | ||
66 | // ---------------------------------------------------------------------------- | |
67 | // forward declarations | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
70 | class WXDLLIMPEXP_FWD_ADV wxGrid; | |
71 | class WXDLLIMPEXP_FWD_ADV wxGridCellAttr; | |
72 | class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData; | |
73 | class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow; | |
74 | class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow; | |
75 | class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow; | |
76 | class WXDLLIMPEXP_FWD_ADV wxGridWindow; | |
77 | class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry; | |
78 | class WXDLLIMPEXP_FWD_ADV wxGridSelection; | |
79 | ||
80 | class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl; | |
81 | class WXDLLIMPEXP_FWD_CORE wxCheckBox; | |
82 | class WXDLLIMPEXP_FWD_CORE wxComboBox; | |
83 | class WXDLLIMPEXP_FWD_CORE wxTextCtrl; | |
84 | #if wxUSE_SPINCTRL | |
85 | class WXDLLIMPEXP_FWD_CORE wxSpinCtrl; | |
86 | #endif | |
87 | ||
88 | class wxGridOperations; | |
89 | class wxGridRowOperations; | |
90 | class wxGridColumnOperations; | |
91 | class wxGridDirectionOperations; | |
92 | ||
93 | ||
94 | // ---------------------------------------------------------------------------- | |
95 | // macros | |
96 | // ---------------------------------------------------------------------------- | |
97 | ||
98 | #define wxSafeIncRef(p) if ( p ) (p)->IncRef() | |
99 | #define wxSafeDecRef(p) if ( p ) (p)->DecRef() | |
100 | ||
101 | // ---------------------------------------------------------------------------- | |
102 | // wxGridCellWorker: common base class for wxGridCellRenderer and | |
103 | // wxGridCellEditor | |
104 | // | |
105 | // NB: this is more an implementation convenience than a design issue, so this | |
106 | // class is not documented and is not public at all | |
107 | // ---------------------------------------------------------------------------- | |
108 | ||
109 | class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer | |
110 | { | |
111 | public: | |
112 | wxGridCellWorker() { m_nRef = 1; } | |
113 | ||
114 | // this class is ref counted: it is created with ref count of 1, so | |
115 | // calling DecRef() once will delete it. Calling IncRef() allows to lock | |
116 | // it until the matching DecRef() is called | |
117 | void IncRef() { m_nRef++; } | |
118 | void DecRef() { if ( --m_nRef == 0 ) delete this; } | |
119 | ||
120 | // interpret renderer parameters: arbitrary string whose interpretatin is | |
121 | // left to the derived classes | |
122 | virtual void SetParameters(const wxString& params); | |
123 | ||
124 | protected: | |
125 | // virtual dtor for any base class - private because only DecRef() can | |
126 | // delete us | |
127 | virtual ~wxGridCellWorker(); | |
128 | ||
129 | private: | |
130 | size_t m_nRef; | |
131 | ||
132 | // suppress the stupid gcc warning about the class having private dtor and | |
133 | // no friends | |
134 | friend class wxGridCellWorkerDummyFriend; | |
135 | }; | |
136 | ||
137 | // ---------------------------------------------------------------------------- | |
138 | // wxGridCellRenderer: this class is responsible for actually drawing the cell | |
139 | // in the grid. You may pass it to the wxGridCellAttr (below) to change the | |
140 | // format of one given cell or to wxGrid::SetDefaultRenderer() to change the | |
141 | // view of all cells. This is an ABC, you will normally use one of the | |
142 | // predefined derived classes or derive your own class from it. | |
143 | // ---------------------------------------------------------------------------- | |
144 | ||
145 | class WXDLLIMPEXP_ADV wxGridCellRenderer : public wxGridCellWorker | |
146 | { | |
147 | public: | |
148 | // draw the given cell on the provided DC inside the given rectangle | |
149 | // using the style specified by the attribute and the default or selected | |
150 | // state corresponding to the isSelected value. | |
151 | // | |
152 | // this pure virtual function has a default implementation which will | |
153 | // prepare the DC using the given attribute: it will draw the rectangle | |
154 | // with the bg colour from attr and set the text colour and font | |
155 | virtual void Draw(wxGrid& grid, | |
156 | wxGridCellAttr& attr, | |
157 | wxDC& dc, | |
158 | const wxRect& rect, | |
159 | int row, int col, | |
160 | bool isSelected) = 0; | |
161 | ||
162 | // get the preferred size of the cell for its contents | |
163 | virtual wxSize GetBestSize(wxGrid& grid, | |
164 | wxGridCellAttr& attr, | |
165 | wxDC& dc, | |
166 | int row, int col) = 0; | |
167 | ||
168 | // create a new object which is the copy of this one | |
169 | virtual wxGridCellRenderer *Clone() const = 0; | |
170 | }; | |
171 | ||
172 | // ---------------------------------------------------------------------------- | |
173 | // wxGridCellEditor: This class is responsible for providing and manipulating | |
174 | // the in-place edit controls for the grid. Instances of wxGridCellEditor | |
175 | // (actually, instances of derived classes since it is an ABC) can be | |
176 | // associated with the cell attributes for individual cells, rows, columns, or | |
177 | // even for the entire grid. | |
178 | // ---------------------------------------------------------------------------- | |
179 | ||
180 | class WXDLLIMPEXP_ADV wxGridCellEditor : public wxGridCellWorker | |
181 | { | |
182 | public: | |
183 | wxGridCellEditor(); | |
184 | ||
185 | bool IsCreated() { return m_control != NULL; } | |
186 | wxControl* GetControl() { return m_control; } | |
187 | void SetControl(wxControl* control) { m_control = control; } | |
188 | ||
189 | wxGridCellAttr* GetCellAttr() { return m_attr; } | |
190 | void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; } | |
191 | ||
192 | // Creates the actual edit control | |
193 | virtual void Create(wxWindow* parent, | |
194 | wxWindowID id, | |
195 | wxEvtHandler* evtHandler) = 0; | |
196 | ||
197 | // Size and position the edit control | |
198 | virtual void SetSize(const wxRect& rect); | |
199 | ||
200 | // Show or hide the edit control, use the specified attributes to set | |
201 | // colours/fonts for it | |
202 | virtual void Show(bool show, wxGridCellAttr *attr = NULL); | |
203 | ||
204 | // Draws the part of the cell not occupied by the control: the base class | |
205 | // version just fills it with background colour from the attribute | |
206 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); | |
207 | ||
208 | ||
209 | // The methods called by wxGrid when a cell is edited: first BeginEdit() is | |
210 | // called, then EndEdit() is and if it returns true and if the change is | |
211 | // not vetoed by a user-defined event handler, finally ApplyEdit() is called | |
212 | ||
213 | // Fetch the value from the table and prepare the edit control | |
214 | // to begin editing. Set the focus to the edit control. | |
215 | virtual void BeginEdit(int row, int col, wxGrid* grid) = 0; | |
216 | ||
217 | // Returns false if nothing changed, otherwise returns true and return the | |
218 | // new value in its string form in the newval output parameter. | |
219 | // | |
220 | // This should also store the new value in its real type internally so that | |
221 | // it could be used by ApplyEdit(). | |
222 | virtual bool EndEdit(const wxString& oldval, wxString *newval) = 0; | |
223 | ||
224 | // Complete the editing of the current cell by storing the value saved by | |
225 | // the previous call to EndEdit() in the grid | |
226 | virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0; | |
227 | ||
228 | ||
229 | // Reset the value in the control back to its starting value | |
230 | virtual void Reset() = 0; | |
231 | ||
232 | // return true to allow the given key to start editing: the base class | |
233 | // version only checks that the event has no modifiers. The derived | |
234 | // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in | |
235 | // their IsAcceptedKey() implementation, although, of course, it is not a | |
236 | // mandatory requirment. | |
237 | // | |
238 | // NB: if the key is F2 (special), editing will always start and this | |
239 | // method will not be called at all (but StartingKey() will) | |
240 | virtual bool IsAcceptedKey(wxKeyEvent& event); | |
241 | ||
242 | // If the editor is enabled by pressing keys on the grid, this will be | |
243 | // called to let the editor do something about that first key if desired | |
244 | virtual void StartingKey(wxKeyEvent& event); | |
245 | ||
246 | // if the editor is enabled by clicking on the cell, this method will be | |
247 | // called | |
248 | virtual void StartingClick(); | |
249 | ||
250 | // Some types of controls on some platforms may need some help | |
251 | // with the Return key. | |
252 | virtual void HandleReturn(wxKeyEvent& event); | |
253 | ||
254 | // Final cleanup | |
255 | virtual void Destroy(); | |
256 | ||
257 | // create a new object which is the copy of this one | |
258 | virtual wxGridCellEditor *Clone() const = 0; | |
259 | ||
260 | // added GetValue so we can get the value which is in the control | |
261 | virtual wxString GetValue() const = 0; | |
262 | ||
263 | protected: | |
264 | // the dtor is private because only DecRef() can delete us | |
265 | virtual ~wxGridCellEditor(); | |
266 | ||
267 | // the control we show on screen | |
268 | wxControl* m_control; | |
269 | ||
270 | // a temporary pointer to the attribute being edited | |
271 | wxGridCellAttr* m_attr; | |
272 | ||
273 | // if we change the colours/font of the control from the default ones, we | |
274 | // must restore the default later and we save them here between calls to | |
275 | // Show(true) and Show(false) | |
276 | wxColour m_colFgOld, | |
277 | m_colBgOld; | |
278 | wxFont m_fontOld; | |
279 | ||
280 | // suppress the stupid gcc warning about the class having private dtor and | |
281 | // no friends | |
282 | friend class wxGridCellEditorDummyFriend; | |
283 | ||
284 | DECLARE_NO_COPY_CLASS(wxGridCellEditor) | |
285 | }; | |
286 | ||
287 | ||
288 | // ---------------------------------------------------------------------------- | |
289 | // wxGridCellAttr: this class can be used to alter the cells appearance in | |
290 | // the grid by changing their colour/font/... from default. An object of this | |
291 | // class may be returned by wxGridTable::GetAttr(). | |
292 | // ---------------------------------------------------------------------------- | |
293 | ||
294 | class WXDLLIMPEXP_ADV wxGridCellAttr : public wxClientDataContainer | |
295 | { | |
296 | public: | |
297 | enum wxAttrKind | |
298 | { | |
299 | Any, | |
300 | Default, | |
301 | Cell, | |
302 | Row, | |
303 | Col, | |
304 | Merged | |
305 | }; | |
306 | ||
307 | // ctors | |
308 | wxGridCellAttr(wxGridCellAttr *attrDefault = NULL) | |
309 | { | |
310 | Init(attrDefault); | |
311 | ||
312 | // MB: args used to be 0,0 here but wxALIGN_LEFT is 0 | |
313 | SetAlignment(-1, -1); | |
314 | } | |
315 | ||
316 | // VZ: considering the number of members wxGridCellAttr has now, this ctor | |
317 | // seems to be pretty useless... may be we should just remove it? | |
318 | wxGridCellAttr(const wxColour& colText, | |
319 | const wxColour& colBack, | |
320 | const wxFont& font, | |
321 | int hAlign, | |
322 | int vAlign) | |
323 | : m_colText(colText), m_colBack(colBack), m_font(font) | |
324 | { | |
325 | Init(); | |
326 | SetAlignment(hAlign, vAlign); | |
327 | } | |
328 | ||
329 | // creates a new copy of this object | |
330 | wxGridCellAttr *Clone() const; | |
331 | void MergeWith(wxGridCellAttr *mergefrom); | |
332 | ||
333 | // this class is ref counted: it is created with ref count of 1, so | |
334 | // calling DecRef() once will delete it. Calling IncRef() allows to lock | |
335 | // it until the matching DecRef() is called | |
336 | void IncRef() { m_nRef++; } | |
337 | void DecRef() { if ( --m_nRef == 0 ) delete this; } | |
338 | ||
339 | // setters | |
340 | void SetTextColour(const wxColour& colText) { m_colText = colText; } | |
341 | void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } | |
342 | void SetFont(const wxFont& font) { m_font = font; } | |
343 | void SetAlignment(int hAlign, int vAlign) | |
344 | { | |
345 | m_hAlign = hAlign; | |
346 | m_vAlign = vAlign; | |
347 | } | |
348 | void SetSize(int num_rows, int num_cols); | |
349 | void SetOverflow(bool allow = true) | |
350 | { m_overflow = allow ? Overflow : SingleCell; } | |
351 | void SetReadOnly(bool isReadOnly = true) | |
352 | { m_isReadOnly = isReadOnly ? ReadOnly : ReadWrite; } | |
353 | ||
354 | // takes ownership of the pointer | |
355 | void SetRenderer(wxGridCellRenderer *renderer) | |
356 | { wxSafeDecRef(m_renderer); m_renderer = renderer; } | |
357 | void SetEditor(wxGridCellEditor* editor) | |
358 | { wxSafeDecRef(m_editor); m_editor = editor; } | |
359 | ||
360 | void SetKind(wxAttrKind kind) { m_attrkind = kind; } | |
361 | ||
362 | // accessors | |
363 | bool HasTextColour() const { return m_colText.Ok(); } | |
364 | bool HasBackgroundColour() const { return m_colBack.Ok(); } | |
365 | bool HasFont() const { return m_font.Ok(); } | |
366 | bool HasAlignment() const { return (m_hAlign != -1 || m_vAlign != -1); } | |
367 | bool HasRenderer() const { return m_renderer != NULL; } | |
368 | bool HasEditor() const { return m_editor != NULL; } | |
369 | bool HasReadWriteMode() const { return m_isReadOnly != Unset; } | |
370 | bool HasOverflowMode() const { return m_overflow != UnsetOverflow; } | |
371 | bool HasSize() const { return m_sizeRows != 1 || m_sizeCols != 1; } | |
372 | ||
373 | const wxColour& GetTextColour() const; | |
374 | const wxColour& GetBackgroundColour() const; | |
375 | const wxFont& GetFont() const; | |
376 | void GetAlignment(int *hAlign, int *vAlign) const; | |
377 | void GetSize(int *num_rows, int *num_cols) const; | |
378 | bool GetOverflow() const | |
379 | { return m_overflow != SingleCell; } | |
380 | wxGridCellRenderer *GetRenderer(const wxGrid* grid, int row, int col) const; | |
381 | wxGridCellEditor *GetEditor(const wxGrid* grid, int row, int col) const; | |
382 | ||
383 | bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; } | |
384 | ||
385 | wxAttrKind GetKind() { return m_attrkind; } | |
386 | ||
387 | void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; } | |
388 | ||
389 | protected: | |
390 | // the dtor is private because only DecRef() can delete us | |
391 | virtual ~wxGridCellAttr() | |
392 | { | |
393 | wxSafeDecRef(m_renderer); | |
394 | wxSafeDecRef(m_editor); | |
395 | } | |
396 | ||
397 | private: | |
398 | enum wxAttrReadMode | |
399 | { | |
400 | Unset = -1, | |
401 | ReadWrite, | |
402 | ReadOnly | |
403 | }; | |
404 | ||
405 | enum wxAttrOverflowMode | |
406 | { | |
407 | UnsetOverflow = -1, | |
408 | Overflow, | |
409 | SingleCell | |
410 | }; | |
411 | ||
412 | // the common part of all ctors | |
413 | void Init(wxGridCellAttr *attrDefault = NULL); | |
414 | ||
415 | ||
416 | // the ref count - when it goes to 0, we die | |
417 | size_t m_nRef; | |
418 | ||
419 | wxColour m_colText, | |
420 | m_colBack; | |
421 | wxFont m_font; | |
422 | int m_hAlign, | |
423 | m_vAlign; | |
424 | int m_sizeRows, | |
425 | m_sizeCols; | |
426 | ||
427 | wxAttrOverflowMode m_overflow; | |
428 | ||
429 | wxGridCellRenderer* m_renderer; | |
430 | wxGridCellEditor* m_editor; | |
431 | wxGridCellAttr* m_defGridAttr; | |
432 | ||
433 | wxAttrReadMode m_isReadOnly; | |
434 | ||
435 | wxAttrKind m_attrkind; | |
436 | ||
437 | // use Clone() instead | |
438 | DECLARE_NO_COPY_CLASS(wxGridCellAttr) | |
439 | ||
440 | // suppress the stupid gcc warning about the class having private dtor and | |
441 | // no friends | |
442 | friend class wxGridCellAttrDummyFriend; | |
443 | }; | |
444 | ||
445 | // ---------------------------------------------------------------------------- | |
446 | // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the | |
447 | // cell attributes. | |
448 | // ---------------------------------------------------------------------------- | |
449 | ||
450 | // implementation note: we separate it from wxGridTableBase because we wish to | |
451 | // avoid deriving a new table class if possible, and sometimes it will be | |
452 | // enough to just derive another wxGridCellAttrProvider instead | |
453 | // | |
454 | // the default implementation is reasonably efficient for the generic case, | |
455 | // but you might still wish to implement your own for some specific situations | |
456 | // if you have performance problems with the stock one | |
457 | class WXDLLIMPEXP_ADV wxGridCellAttrProvider : public wxClientDataContainer | |
458 | { | |
459 | public: | |
460 | wxGridCellAttrProvider(); | |
461 | virtual ~wxGridCellAttrProvider(); | |
462 | ||
463 | // DecRef() must be called on the returned pointer | |
464 | virtual wxGridCellAttr *GetAttr(int row, int col, | |
465 | wxGridCellAttr::wxAttrKind kind ) const; | |
466 | ||
467 | // all these functions take ownership of the pointer, don't call DecRef() | |
468 | // on it | |
469 | virtual void SetAttr(wxGridCellAttr *attr, int row, int col); | |
470 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); | |
471 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
472 | ||
473 | // these functions must be called whenever some rows/cols are deleted | |
474 | // because the internal data must be updated then | |
475 | void UpdateAttrRows( size_t pos, int numRows ); | |
476 | void UpdateAttrCols( size_t pos, int numCols ); | |
477 | ||
478 | private: | |
479 | void InitData(); | |
480 | ||
481 | wxGridCellAttrProviderData *m_data; | |
482 | ||
483 | DECLARE_NO_COPY_CLASS(wxGridCellAttrProvider) | |
484 | }; | |
485 | ||
486 | // ---------------------------------------------------------------------------- | |
487 | // wxGridCellCoords: location of a cell in the grid | |
488 | // ---------------------------------------------------------------------------- | |
489 | ||
490 | class WXDLLIMPEXP_ADV wxGridCellCoords | |
491 | { | |
492 | public: | |
493 | wxGridCellCoords() { m_row = m_col = -1; } | |
494 | wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; } | |
495 | ||
496 | // default copy ctor is ok | |
497 | ||
498 | int GetRow() const { return m_row; } | |
499 | void SetRow( int n ) { m_row = n; } | |
500 | int GetCol() const { return m_col; } | |
501 | void SetCol( int n ) { m_col = n; } | |
502 | void Set( int row, int col ) { m_row = row; m_col = col; } | |
503 | ||
504 | wxGridCellCoords& operator=( const wxGridCellCoords& other ) | |
505 | { | |
506 | if ( &other != this ) | |
507 | { | |
508 | m_row=other.m_row; | |
509 | m_col=other.m_col; | |
510 | } | |
511 | return *this; | |
512 | } | |
513 | ||
514 | bool operator==( const wxGridCellCoords& other ) const | |
515 | { | |
516 | return (m_row == other.m_row && m_col == other.m_col); | |
517 | } | |
518 | ||
519 | bool operator!=( const wxGridCellCoords& other ) const | |
520 | { | |
521 | return (m_row != other.m_row || m_col != other.m_col); | |
522 | } | |
523 | ||
524 | bool operator!() const | |
525 | { | |
526 | return (m_row == -1 && m_col == -1 ); | |
527 | } | |
528 | ||
529 | private: | |
530 | int m_row; | |
531 | int m_col; | |
532 | }; | |
533 | ||
534 | ||
535 | // For comparisons... | |
536 | // | |
537 | extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords; | |
538 | extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect; | |
539 | ||
540 | // An array of cell coords... | |
541 | // | |
542 | WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords, wxGridCellCoordsArray, | |
543 | class WXDLLIMPEXP_ADV); | |
544 | ||
545 | // ---------------------------------------------------------------------------- | |
546 | // Grid table classes | |
547 | // ---------------------------------------------------------------------------- | |
548 | ||
549 | // the abstract base class | |
550 | class WXDLLIMPEXP_ADV wxGridTableBase : public wxObject, | |
551 | public wxClientDataContainer | |
552 | { | |
553 | public: | |
554 | wxGridTableBase(); | |
555 | virtual ~wxGridTableBase(); | |
556 | ||
557 | // You must override these functions in a derived table class | |
558 | // | |
559 | ||
560 | // return the number of rows and columns in this table | |
561 | virtual int GetNumberRows() = 0; | |
562 | virtual int GetNumberCols() = 0; | |
563 | ||
564 | // the methods above are unfortunately non-const even though they should | |
565 | // have been const -- but changing it now is not possible any longer as it | |
566 | // would break the existing code overriding them, so instead we provide | |
567 | // these const synonyms which can be used from const-correct code | |
568 | int GetRowsCount() const | |
569 | { return const_cast<wxGridTableBase *>(this)->GetNumberRows(); } | |
570 | int GetColsCount() const | |
571 | { return const_cast<wxGridTableBase *>(this)->GetNumberCols(); } | |
572 | ||
573 | ||
574 | virtual bool IsEmptyCell( int row, int col ) | |
575 | { | |
576 | return GetValue(row, col).empty(); | |
577 | } | |
578 | ||
579 | bool IsEmpty(const wxGridCellCoords& coord) | |
580 | { | |
581 | return IsEmptyCell(coord.GetRow(), coord.GetCol()); | |
582 | } | |
583 | ||
584 | virtual wxString GetValue( int row, int col ) = 0; | |
585 | virtual void SetValue( int row, int col, const wxString& value ) = 0; | |
586 | ||
587 | // Data type determination and value access | |
588 | virtual wxString GetTypeName( int row, int col ); | |
589 | virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); | |
590 | virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); | |
591 | ||
592 | virtual long GetValueAsLong( int row, int col ); | |
593 | virtual double GetValueAsDouble( int row, int col ); | |
594 | virtual bool GetValueAsBool( int row, int col ); | |
595 | ||
596 | virtual void SetValueAsLong( int row, int col, long value ); | |
597 | virtual void SetValueAsDouble( int row, int col, double value ); | |
598 | virtual void SetValueAsBool( int row, int col, bool value ); | |
599 | ||
600 | // For user defined types | |
601 | virtual void* GetValueAsCustom( int row, int col, const wxString& typeName ); | |
602 | virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value ); | |
603 | ||
604 | ||
605 | // Overriding these is optional | |
606 | // | |
607 | virtual void SetView( wxGrid *grid ) { m_view = grid; } | |
608 | virtual wxGrid * GetView() const { return m_view; } | |
609 | ||
610 | virtual void Clear() {} | |
611 | virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
612 | virtual bool AppendRows( size_t numRows = 1 ); | |
613 | virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
614 | virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
615 | virtual bool AppendCols( size_t numCols = 1 ); | |
616 | virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
617 | ||
618 | virtual wxString GetRowLabelValue( int row ); | |
619 | virtual wxString GetColLabelValue( int col ); | |
620 | virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {} | |
621 | virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {} | |
622 | ||
623 | // Attribute handling | |
624 | // | |
625 | ||
626 | // give us the attr provider to use - we take ownership of the pointer | |
627 | void SetAttrProvider(wxGridCellAttrProvider *attrProvider); | |
628 | ||
629 | // get the currently used attr provider (may be NULL) | |
630 | wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; } | |
631 | ||
632 | // Does this table allow attributes? Default implementation creates | |
633 | // a wxGridCellAttrProvider if necessary. | |
634 | virtual bool CanHaveAttributes(); | |
635 | ||
636 | // by default forwarded to wxGridCellAttrProvider if any. May be | |
637 | // overridden to handle attributes directly in the table. | |
638 | virtual wxGridCellAttr *GetAttr( int row, int col, | |
639 | wxGridCellAttr::wxAttrKind kind ); | |
640 | ||
641 | ||
642 | // these functions take ownership of the pointer | |
643 | virtual void SetAttr(wxGridCellAttr* attr, int row, int col); | |
644 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); | |
645 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
646 | ||
647 | private: | |
648 | wxGrid * m_view; | |
649 | wxGridCellAttrProvider *m_attrProvider; | |
650 | ||
651 | DECLARE_ABSTRACT_CLASS(wxGridTableBase) | |
652 | DECLARE_NO_COPY_CLASS(wxGridTableBase) | |
653 | }; | |
654 | ||
655 | ||
656 | // ---------------------------------------------------------------------------- | |
657 | // wxGridTableMessage | |
658 | // ---------------------------------------------------------------------------- | |
659 | ||
660 | // IDs for messages sent from grid table to view | |
661 | // | |
662 | enum wxGridTableRequest | |
663 | { | |
664 | wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000, | |
665 | wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES, | |
666 | wxGRIDTABLE_NOTIFY_ROWS_INSERTED, | |
667 | wxGRIDTABLE_NOTIFY_ROWS_APPENDED, | |
668 | wxGRIDTABLE_NOTIFY_ROWS_DELETED, | |
669 | wxGRIDTABLE_NOTIFY_COLS_INSERTED, | |
670 | wxGRIDTABLE_NOTIFY_COLS_APPENDED, | |
671 | wxGRIDTABLE_NOTIFY_COLS_DELETED | |
672 | }; | |
673 | ||
674 | class WXDLLIMPEXP_ADV wxGridTableMessage | |
675 | { | |
676 | public: | |
677 | wxGridTableMessage(); | |
678 | wxGridTableMessage( wxGridTableBase *table, int id, | |
679 | int comInt1 = -1, | |
680 | int comInt2 = -1 ); | |
681 | ||
682 | void SetTableObject( wxGridTableBase *table ) { m_table = table; } | |
683 | wxGridTableBase * GetTableObject() const { return m_table; } | |
684 | void SetId( int id ) { m_id = id; } | |
685 | int GetId() { return m_id; } | |
686 | void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; } | |
687 | int GetCommandInt() { return m_comInt1; } | |
688 | void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; } | |
689 | int GetCommandInt2() { return m_comInt2; } | |
690 | ||
691 | private: | |
692 | wxGridTableBase *m_table; | |
693 | int m_id; | |
694 | int m_comInt1; | |
695 | int m_comInt2; | |
696 | ||
697 | DECLARE_NO_COPY_CLASS(wxGridTableMessage) | |
698 | }; | |
699 | ||
700 | ||
701 | ||
702 | // ------ wxGridStringArray | |
703 | // A 2-dimensional array of strings for data values | |
704 | // | |
705 | ||
706 | WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString, wxGridStringArray, | |
707 | class WXDLLIMPEXP_ADV); | |
708 | ||
709 | ||
710 | ||
711 | // ------ wxGridStringTable | |
712 | // | |
713 | // Simplest type of data table for a grid for small tables of strings | |
714 | // that are stored in memory | |
715 | // | |
716 | ||
717 | class WXDLLIMPEXP_ADV wxGridStringTable : public wxGridTableBase | |
718 | { | |
719 | public: | |
720 | wxGridStringTable(); | |
721 | wxGridStringTable( int numRows, int numCols ); | |
722 | virtual ~wxGridStringTable(); | |
723 | ||
724 | // these are pure virtual in wxGridTableBase | |
725 | // | |
726 | int GetNumberRows(); | |
727 | int GetNumberCols(); | |
728 | wxString GetValue( int row, int col ); | |
729 | void SetValue( int row, int col, const wxString& s ); | |
730 | ||
731 | // overridden functions from wxGridTableBase | |
732 | // | |
733 | void Clear(); | |
734 | bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
735 | bool AppendRows( size_t numRows = 1 ); | |
736 | bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
737 | bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
738 | bool AppendCols( size_t numCols = 1 ); | |
739 | bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
740 | ||
741 | void SetRowLabelValue( int row, const wxString& ); | |
742 | void SetColLabelValue( int col, const wxString& ); | |
743 | wxString GetRowLabelValue( int row ); | |
744 | wxString GetColLabelValue( int col ); | |
745 | ||
746 | private: | |
747 | wxGridStringArray m_data; | |
748 | ||
749 | // These only get used if you set your own labels, otherwise the | |
750 | // GetRow/ColLabelValue functions return wxGridTableBase defaults | |
751 | // | |
752 | wxArrayString m_rowLabels; | |
753 | wxArrayString m_colLabels; | |
754 | ||
755 | DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable ) | |
756 | }; | |
757 | ||
758 | ||
759 | ||
760 | // ============================================================================ | |
761 | // Grid view classes | |
762 | // ============================================================================ | |
763 | ||
764 | // ---------------------------------------------------------------------------- | |
765 | // wxGrid | |
766 | // ---------------------------------------------------------------------------- | |
767 | ||
768 | class WXDLLIMPEXP_ADV wxGrid : public wxScrolledWindow | |
769 | { | |
770 | public: | |
771 | // possible selection modes | |
772 | enum wxGridSelectionModes | |
773 | { | |
774 | wxGridSelectCells = 0, // allow selecting anything | |
775 | wxGridSelectRows = 1, // allow selecting only entire rows | |
776 | wxGridSelectColumns = 2, // allow selecting only entire columns | |
777 | wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns | |
778 | }; | |
779 | ||
780 | // creation and destruction | |
781 | // ------------------------ | |
782 | ||
783 | // ctor and Create() create the grid window, as with the other controls | |
784 | wxGrid() { Init(); } | |
785 | ||
786 | wxGrid(wxWindow *parent, | |
787 | wxWindowID id, | |
788 | const wxPoint& pos = wxDefaultPosition, | |
789 | const wxSize& size = wxDefaultSize, | |
790 | long style = wxWANTS_CHARS, | |
791 | const wxString& name = wxGridNameStr) | |
792 | { | |
793 | Init(); | |
794 | ||
795 | Create(parent, id, pos, size, style, name); | |
796 | } | |
797 | ||
798 | bool Create(wxWindow *parent, | |
799 | wxWindowID id, | |
800 | const wxPoint& pos = wxDefaultPosition, | |
801 | const wxSize& size = wxDefaultSize, | |
802 | long style = wxWANTS_CHARS, | |
803 | const wxString& name = wxGridNameStr); | |
804 | ||
805 | virtual ~wxGrid(); | |
806 | ||
807 | // however to initialize grid data either CreateGrid() or SetTable() must | |
808 | // be also called | |
809 | ||
810 | // this is basically equivalent to | |
811 | // | |
812 | // SetTable(new wxGridStringTable(numRows, numCols), true, selmode) | |
813 | // | |
814 | bool CreateGrid( int numRows, int numCols, | |
815 | wxGridSelectionModes selmode = wxGridSelectCells ); | |
816 | ||
817 | bool SetTable( wxGridTableBase *table, | |
818 | bool takeOwnership = false, | |
819 | wxGridSelectionModes selmode = wxGridSelectCells ); | |
820 | ||
821 | bool ProcessTableMessage(wxGridTableMessage&); | |
822 | ||
823 | wxGridTableBase *GetTable() const { return m_table; } | |
824 | ||
825 | ||
826 | void SetSelectionMode(wxGridSelectionModes selmode); | |
827 | wxGridSelectionModes GetSelectionMode() const; | |
828 | ||
829 | // ------ grid dimensions | |
830 | // | |
831 | int GetNumberRows() const { return m_numRows; } | |
832 | int GetNumberCols() const { return m_numCols; } | |
833 | ||
834 | ||
835 | // ------ display update functions | |
836 | // | |
837 | wxArrayInt CalcRowLabelsExposed( const wxRegion& reg ) const; | |
838 | ||
839 | wxArrayInt CalcColLabelsExposed( const wxRegion& reg ) const; | |
840 | wxGridCellCoordsArray CalcCellsExposed( const wxRegion& reg ) const; | |
841 | ||
842 | ||
843 | void ClearGrid(); | |
844 | bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true) | |
845 | { | |
846 | return DoModifyLines(&wxGridTableBase::InsertRows, | |
847 | pos, numRows, updateLabels); | |
848 | } | |
849 | bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true) | |
850 | { | |
851 | return DoModifyLines(&wxGridTableBase::InsertCols, | |
852 | pos, numCols, updateLabels); | |
853 | } | |
854 | ||
855 | bool AppendRows(int numRows = 1, bool updateLabels = true) | |
856 | { | |
857 | return DoAppendLines(&wxGridTableBase::AppendRows, numRows, updateLabels); | |
858 | } | |
859 | bool AppendCols(int numCols = 1, bool updateLabels = true) | |
860 | { | |
861 | return DoAppendLines(&wxGridTableBase::AppendCols, numCols, updateLabels); | |
862 | } | |
863 | ||
864 | bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true) | |
865 | { | |
866 | return DoModifyLines(&wxGridTableBase::DeleteRows, | |
867 | pos, numRows, updateLabels); | |
868 | } | |
869 | bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true) | |
870 | { | |
871 | return DoModifyLines(&wxGridTableBase::DeleteCols, | |
872 | pos, numCols, updateLabels); | |
873 | } | |
874 | ||
875 | void DrawGridCellArea( wxDC& dc , const wxGridCellCoordsArray& cells ); | |
876 | void DrawGridSpace( wxDC& dc ); | |
877 | void DrawCellBorder( wxDC& dc, const wxGridCellCoords& ); | |
878 | void DrawAllGridLines( wxDC& dc, const wxRegion & reg ); | |
879 | void DrawCell( wxDC& dc, const wxGridCellCoords& ); | |
880 | void DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells); | |
881 | ||
882 | // this function is called when the current cell highlight must be redrawn | |
883 | // and may be overridden by the user | |
884 | virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ); | |
885 | ||
886 | virtual void DrawRowLabels( wxDC& dc, const wxArrayInt& rows ); | |
887 | virtual void DrawRowLabel( wxDC& dc, int row ); | |
888 | ||
889 | virtual void DrawColLabels( wxDC& dc, const wxArrayInt& cols ); | |
890 | virtual void DrawColLabel( wxDC& dc, int col ); | |
891 | ||
892 | virtual void DrawCornerLabel(wxDC& dc); | |
893 | ||
894 | // ------ Cell text drawing functions | |
895 | // | |
896 | void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&, | |
897 | int horizontalAlignment = wxALIGN_LEFT, | |
898 | int verticalAlignment = wxALIGN_TOP, | |
899 | int textOrientation = wxHORIZONTAL ); | |
900 | ||
901 | void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&, | |
902 | int horizontalAlignment = wxALIGN_LEFT, | |
903 | int verticalAlignment = wxALIGN_TOP, | |
904 | int textOrientation = wxHORIZONTAL ); | |
905 | ||
906 | ||
907 | // Split a string containing newline characters into an array of | |
908 | // strings and return the number of lines | |
909 | // | |
910 | void StringToLines( const wxString& value, wxArrayString& lines ) const; | |
911 | ||
912 | void GetTextBoxSize( const wxDC& dc, | |
913 | const wxArrayString& lines, | |
914 | long *width, long *height ) const; | |
915 | ||
916 | ||
917 | // ------ | |
918 | // Code that does a lot of grid modification can be enclosed | |
919 | // between BeginBatch() and EndBatch() calls to avoid screen | |
920 | // flicker | |
921 | // | |
922 | void BeginBatch() { m_batchCount++; } | |
923 | void EndBatch(); | |
924 | ||
925 | int GetBatchCount() { return m_batchCount; } | |
926 | ||
927 | virtual void Refresh(bool eraseb = true, const wxRect* rect = NULL); | |
928 | ||
929 | // Use this, rather than wxWindow::Refresh(), to force an | |
930 | // immediate repainting of the grid. Has no effect if you are | |
931 | // already inside a BeginBatch / EndBatch block. | |
932 | // | |
933 | // This function is necessary because wxGrid has a minimal OnPaint() | |
934 | // handler to reduce screen flicker. | |
935 | // | |
936 | void ForceRefresh(); | |
937 | ||
938 | ||
939 | // ------ edit control functions | |
940 | // | |
941 | bool IsEditable() const { return m_editable; } | |
942 | void EnableEditing( bool edit ); | |
943 | ||
944 | void EnableCellEditControl( bool enable = true ); | |
945 | void DisableCellEditControl() { EnableCellEditControl(false); } | |
946 | bool CanEnableCellControl() const; | |
947 | bool IsCellEditControlEnabled() const; | |
948 | bool IsCellEditControlShown() const; | |
949 | ||
950 | bool IsCurrentCellReadOnly() const; | |
951 | ||
952 | void ShowCellEditControl(); | |
953 | void HideCellEditControl(); | |
954 | void SaveEditControlValue(); | |
955 | ||
956 | ||
957 | // ------ grid location functions | |
958 | // Note that all of these functions work with the logical coordinates of | |
959 | // grid cells and labels so you will need to convert from device | |
960 | // coordinates for mouse events etc. | |
961 | // | |
962 | wxGridCellCoords XYToCell(int x, int y) const; | |
963 | void XYToCell(int x, int y, wxGridCellCoords& coords) const | |
964 | { coords = XYToCell(x, y); } | |
965 | wxGridCellCoords XYToCell(const wxPoint& pos) const | |
966 | { return XYToCell(pos.x, pos.y); } | |
967 | ||
968 | // these functions return the index of the row/columns corresponding to the | |
969 | // given logical position in pixels | |
970 | // | |
971 | // if clipToMinMax is false (default, wxNOT_FOUND is returned if the | |
972 | // position is outside any row/column, otherwise the first/last element is | |
973 | // returned in this case | |
974 | int YToRow( int y, bool clipToMinMax = false ) const; | |
975 | int XToCol( int x, bool clipToMinMax = false ) const; | |
976 | ||
977 | int YToEdgeOfRow( int y ) const; | |
978 | int XToEdgeOfCol( int x ) const; | |
979 | ||
980 | wxRect CellToRect( int row, int col ) const; | |
981 | wxRect CellToRect( const wxGridCellCoords& coords ) const | |
982 | { return CellToRect( coords.GetRow(), coords.GetCol() ); } | |
983 | ||
984 | int GetGridCursorRow() const { return m_currentCellCoords.GetRow(); } | |
985 | int GetGridCursorCol() const { return m_currentCellCoords.GetCol(); } | |
986 | ||
987 | // check to see if a cell is either wholly visible (the default arg) or | |
988 | // at least partially visible in the grid window | |
989 | // | |
990 | bool IsVisible( int row, int col, bool wholeCellVisible = true ) const; | |
991 | bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = true ) const | |
992 | { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); } | |
993 | void MakeCellVisible( int row, int col ); | |
994 | void MakeCellVisible( const wxGridCellCoords& coords ) | |
995 | { MakeCellVisible( coords.GetRow(), coords.GetCol() ); } | |
996 | ||
997 | ||
998 | // ------ grid cursor movement functions | |
999 | // | |
1000 | void SetGridCursor(int row, int col) { SetCurrentCell(row, col); } | |
1001 | void SetGridCursor(const wxGridCellCoords& c) { SetCurrentCell(c); } | |
1002 | ||
1003 | void GoToCell(int row, int col) | |
1004 | { | |
1005 | if ( SetCurrentCell(row, col) ) | |
1006 | MakeCellVisible(row, col); | |
1007 | } | |
1008 | ||
1009 | void GoToCell(const wxGridCellCoords& coords) | |
1010 | { | |
1011 | if ( SetCurrentCell(coords) ) | |
1012 | MakeCellVisible(coords); | |
1013 | } | |
1014 | ||
1015 | bool MoveCursorUp( bool expandSelection ); | |
1016 | bool MoveCursorDown( bool expandSelection ); | |
1017 | bool MoveCursorLeft( bool expandSelection ); | |
1018 | bool MoveCursorRight( bool expandSelection ); | |
1019 | bool MovePageDown(); | |
1020 | bool MovePageUp(); | |
1021 | bool MoveCursorUpBlock( bool expandSelection ); | |
1022 | bool MoveCursorDownBlock( bool expandSelection ); | |
1023 | bool MoveCursorLeftBlock( bool expandSelection ); | |
1024 | bool MoveCursorRightBlock( bool expandSelection ); | |
1025 | ||
1026 | ||
1027 | // ------ label and gridline formatting | |
1028 | // | |
1029 | int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; } | |
1030 | int GetRowLabelSize() const { return m_rowLabelWidth; } | |
1031 | int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; } | |
1032 | int GetColLabelSize() const { return m_colLabelHeight; } | |
1033 | wxColour GetLabelBackgroundColour() const { return m_labelBackgroundColour; } | |
1034 | wxColour GetLabelTextColour() const { return m_labelTextColour; } | |
1035 | wxFont GetLabelFont() const { return m_labelFont; } | |
1036 | void GetRowLabelAlignment( int *horiz, int *vert ) const; | |
1037 | void GetColLabelAlignment( int *horiz, int *vert ) const; | |
1038 | int GetColLabelTextOrientation() const; | |
1039 | wxString GetRowLabelValue( int row ) const; | |
1040 | wxString GetColLabelValue( int col ) const; | |
1041 | ||
1042 | wxColour GetCellHighlightColour() const { return m_cellHighlightColour; } | |
1043 | int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; } | |
1044 | int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; } | |
1045 | ||
1046 | // this one will use wxHeaderCtrl for the column labels | |
1047 | void UseNativeColHeader(bool native = true); | |
1048 | ||
1049 | // this one will still draw them manually but using the native renderer | |
1050 | // instead of using the same appearance as for the row labels | |
1051 | void SetUseNativeColLabels( bool native = true ); | |
1052 | ||
1053 | void SetRowLabelSize( int width ); | |
1054 | void SetColLabelSize( int height ); | |
1055 | void HideRowLabels() { SetRowLabelSize( 0 ); } | |
1056 | void HideColLabels() { SetColLabelSize( 0 ); } | |
1057 | void SetLabelBackgroundColour( const wxColour& ); | |
1058 | void SetLabelTextColour( const wxColour& ); | |
1059 | void SetLabelFont( const wxFont& ); | |
1060 | void SetRowLabelAlignment( int horiz, int vert ); | |
1061 | void SetColLabelAlignment( int horiz, int vert ); | |
1062 | void SetColLabelTextOrientation( int textOrientation ); | |
1063 | void SetRowLabelValue( int row, const wxString& ); | |
1064 | void SetColLabelValue( int col, const wxString& ); | |
1065 | void SetCellHighlightColour( const wxColour& ); | |
1066 | void SetCellHighlightPenWidth(int width); | |
1067 | void SetCellHighlightROPenWidth(int width); | |
1068 | ||
1069 | void EnableDragRowSize( bool enable = true ); | |
1070 | void DisableDragRowSize() { EnableDragRowSize( false ); } | |
1071 | bool CanDragRowSize() const { return m_canDragRowSize; } | |
1072 | void EnableDragColSize( bool enable = true ); | |
1073 | void DisableDragColSize() { EnableDragColSize( false ); } | |
1074 | bool CanDragColSize() const { return m_canDragColSize; } | |
1075 | void EnableDragColMove( bool enable = true ); | |
1076 | void DisableDragColMove() { EnableDragColMove( false ); } | |
1077 | bool CanDragColMove() const { return m_canDragColMove; } | |
1078 | void EnableDragGridSize(bool enable = true); | |
1079 | void DisableDragGridSize() { EnableDragGridSize(false); } | |
1080 | bool CanDragGridSize() const { return m_canDragGridSize; } | |
1081 | ||
1082 | void EnableDragCell( bool enable = true ); | |
1083 | void DisableDragCell() { EnableDragCell( false ); } | |
1084 | bool CanDragCell() const { return m_canDragCell; } | |
1085 | ||
1086 | ||
1087 | // grid lines | |
1088 | // ---------- | |
1089 | ||
1090 | // enable or disable drawing of the lines | |
1091 | void EnableGridLines(bool enable = true); | |
1092 | bool GridLinesEnabled() const { return m_gridLinesEnabled; } | |
1093 | ||
1094 | // by default grid lines stop at last column/row, but this may be changed | |
1095 | void ClipHorzGridLines(bool clip) | |
1096 | { DoClipGridLines(m_gridLinesClipHorz, clip); } | |
1097 | void ClipVertGridLines(bool clip) | |
1098 | { DoClipGridLines(m_gridLinesClipVert, clip); } | |
1099 | bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz; } | |
1100 | bool AreVertGridLinesClipped() const { return m_gridLinesClipVert; } | |
1101 | ||
1102 | // this can be used to change the global grid lines colour | |
1103 | void SetGridLineColour(const wxColour& col); | |
1104 | wxColour GetGridLineColour() const { return m_gridLineColour; } | |
1105 | ||
1106 | // these methods may be overridden to customize individual grid lines | |
1107 | // appearance | |
1108 | virtual wxPen GetDefaultGridLinePen(); | |
1109 | virtual wxPen GetRowGridLinePen(int row); | |
1110 | virtual wxPen GetColGridLinePen(int col); | |
1111 | ||
1112 | ||
1113 | // attributes | |
1114 | // ---------- | |
1115 | ||
1116 | // this sets the specified attribute for this cell or in this row/col | |
1117 | void SetAttr(int row, int col, wxGridCellAttr *attr); | |
1118 | void SetRowAttr(int row, wxGridCellAttr *attr); | |
1119 | void SetColAttr(int col, wxGridCellAttr *attr); | |
1120 | ||
1121 | // returns the attribute we may modify in place: a new one if this cell | |
1122 | // doesn't have any yet or the existing one if it does | |
1123 | // | |
1124 | // DecRef() must be called on the returned pointer, as usual | |
1125 | wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const; | |
1126 | ||
1127 | ||
1128 | // shortcuts for setting the column parameters | |
1129 | ||
1130 | // set the format for the data in the column: default is string | |
1131 | void SetColFormatBool(int col); | |
1132 | void SetColFormatNumber(int col); | |
1133 | void SetColFormatFloat(int col, int width = -1, int precision = -1); | |
1134 | void SetColFormatCustom(int col, const wxString& typeName); | |
1135 | ||
1136 | // ------ row and col formatting | |
1137 | // | |
1138 | int GetDefaultRowSize() const; | |
1139 | int GetRowSize( int row ) const; | |
1140 | bool IsRowShown(int row) const { return GetRowSize(row) != 0; } | |
1141 | int GetDefaultColSize() const; | |
1142 | int GetColSize( int col ) const; | |
1143 | bool IsColShown(int col) const { return GetColSize(col) != 0; } | |
1144 | wxColour GetDefaultCellBackgroundColour() const; | |
1145 | wxColour GetCellBackgroundColour( int row, int col ) const; | |
1146 | wxColour GetDefaultCellTextColour() const; | |
1147 | wxColour GetCellTextColour( int row, int col ) const; | |
1148 | wxFont GetDefaultCellFont() const; | |
1149 | wxFont GetCellFont( int row, int col ) const; | |
1150 | void GetDefaultCellAlignment( int *horiz, int *vert ) const; | |
1151 | void GetCellAlignment( int row, int col, int *horiz, int *vert ) const; | |
1152 | bool GetDefaultCellOverflow() const; | |
1153 | bool GetCellOverflow( int row, int col ) const; | |
1154 | void GetCellSize( int row, int col, int *num_rows, int *num_cols ) const; | |
1155 | wxSize GetCellSize(const wxGridCellCoords& coords) | |
1156 | { | |
1157 | wxSize s; | |
1158 | GetCellSize(coords.GetRow(), coords.GetCol(), &s.x, &s.y); | |
1159 | return s; | |
1160 | } | |
1161 | ||
1162 | // ------ row and col sizes | |
1163 | void SetDefaultRowSize( int height, bool resizeExistingRows = false ); | |
1164 | void SetRowSize( int row, int height ); | |
1165 | void HideRow(int row) { SetRowSize(row, 0); } | |
1166 | void ShowRow(int row) { SetRowSize(row, -1); } | |
1167 | ||
1168 | void SetDefaultColSize( int width, bool resizeExistingCols = false ); | |
1169 | void SetColSize( int col, int width ); | |
1170 | void HideCol(int col) { SetColSize(col, 0); } | |
1171 | void ShowCol(int col) { SetColSize(col, -1); } | |
1172 | ||
1173 | ||
1174 | // ------- columns (only, for now) reordering | |
1175 | ||
1176 | // columns index <-> positions mapping: by default, the position of the | |
1177 | // column is the same as its index, but the columns can also be reordered | |
1178 | // (either by calling SetColPos() explicitly or by the user dragging the | |
1179 | // columns around) in which case their indices don't correspond to their | |
1180 | // positions on display any longer | |
1181 | // | |
1182 | // internally we always work with indices except for the functions which | |
1183 | // have "Pos" in their names (and which work with columns, not pixels) and | |
1184 | // only the display and hit testing code really cares about display | |
1185 | // positions at all | |
1186 | ||
1187 | // set the positions of all columns at once (this method uses the same | |
1188 | // conventions as wxHeaderCtrl::SetColumnsOrder() for the order array) | |
1189 | void SetColumnsOrder(const wxArrayInt& order); | |
1190 | ||
1191 | // return the column index corresponding to the given (valid) position | |
1192 | int GetColAt(int pos) const | |
1193 | { | |
1194 | return m_colAt.empty() ? pos : m_colAt[pos]; | |
1195 | } | |
1196 | ||
1197 | // reorder the columns so that the column with the given index is now shown | |
1198 | // as the position pos | |
1199 | void SetColPos(int idx, int pos); | |
1200 | ||
1201 | // return the position at which the column with the given index is | |
1202 | // displayed: notice that this is a slow operation as we don't maintain the | |
1203 | // reverse mapping currently | |
1204 | int GetColPos(int idx) const | |
1205 | { | |
1206 | if ( m_colAt.IsEmpty() ) | |
1207 | return idx; | |
1208 | ||
1209 | for ( int i = 0; i < m_numCols; i++ ) | |
1210 | { | |
1211 | if ( m_colAt[i] == idx ) | |
1212 | return i; | |
1213 | } | |
1214 | ||
1215 | wxFAIL_MSG( "invalid column index" ); | |
1216 | ||
1217 | return wxNOT_FOUND; | |
1218 | } | |
1219 | ||
1220 | // reset the columns positions to the default order | |
1221 | void ResetColPos(); | |
1222 | ||
1223 | ||
1224 | // automatically size the column or row to fit to its contents, if | |
1225 | // setAsMin is true, this optimal width will also be set as minimal width | |
1226 | // for this column | |
1227 | void AutoSizeColumn( int col, bool setAsMin = true ) | |
1228 | { AutoSizeColOrRow(col, setAsMin, wxGRID_COLUMN); } | |
1229 | void AutoSizeRow( int row, bool setAsMin = true ) | |
1230 | { AutoSizeColOrRow(row, setAsMin, wxGRID_ROW); } | |
1231 | ||
1232 | // auto size all columns (very ineffective for big grids!) | |
1233 | void AutoSizeColumns( bool setAsMin = true ) | |
1234 | { (void)SetOrCalcColumnSizes(false, setAsMin); } | |
1235 | ||
1236 | void AutoSizeRows( bool setAsMin = true ) | |
1237 | { (void)SetOrCalcRowSizes(false, setAsMin); } | |
1238 | ||
1239 | // auto size the grid, that is make the columns/rows of the "right" size | |
1240 | // and also set the grid size to just fit its contents | |
1241 | void AutoSize(); | |
1242 | ||
1243 | // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize: | |
1244 | // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column | |
1245 | // instead of data column. Note that this operation may be slow for large | |
1246 | // tables. | |
1247 | // autosize row height depending on label text | |
1248 | void AutoSizeRowLabelSize( int row ); | |
1249 | ||
1250 | // autosize column width depending on label text | |
1251 | void AutoSizeColLabelSize( int col ); | |
1252 | ||
1253 | // column won't be resized to be lesser width - this must be called during | |
1254 | // the grid creation because it won't resize the column if it's already | |
1255 | // narrower than the minimal width | |
1256 | void SetColMinimalWidth( int col, int width ); | |
1257 | void SetRowMinimalHeight( int row, int width ); | |
1258 | ||
1259 | /* These members can be used to query and modify the minimal | |
1260 | * acceptable size of grid rows and columns. Call this function in | |
1261 | * your code which creates the grid if you want to display cells | |
1262 | * with a size smaller than the default acceptable minimum size. | |
1263 | * Like the members SetColMinimalWidth and SetRowMinimalWidth, | |
1264 | * the existing rows or columns will not be checked/resized. | |
1265 | */ | |
1266 | void SetColMinimalAcceptableWidth( int width ); | |
1267 | void SetRowMinimalAcceptableHeight( int width ); | |
1268 | int GetColMinimalAcceptableWidth() const; | |
1269 | int GetRowMinimalAcceptableHeight() const; | |
1270 | ||
1271 | void SetDefaultCellBackgroundColour( const wxColour& ); | |
1272 | void SetCellBackgroundColour( int row, int col, const wxColour& ); | |
1273 | void SetDefaultCellTextColour( const wxColour& ); | |
1274 | ||
1275 | void SetCellTextColour( int row, int col, const wxColour& ); | |
1276 | void SetDefaultCellFont( const wxFont& ); | |
1277 | void SetCellFont( int row, int col, const wxFont& ); | |
1278 | void SetDefaultCellAlignment( int horiz, int vert ); | |
1279 | void SetCellAlignment( int row, int col, int horiz, int vert ); | |
1280 | void SetDefaultCellOverflow( bool allow ); | |
1281 | void SetCellOverflow( int row, int col, bool allow ); | |
1282 | void SetCellSize( int row, int col, int num_rows, int num_cols ); | |
1283 | ||
1284 | // takes ownership of the pointer | |
1285 | void SetDefaultRenderer(wxGridCellRenderer *renderer); | |
1286 | void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer); | |
1287 | wxGridCellRenderer *GetDefaultRenderer() const; | |
1288 | wxGridCellRenderer* GetCellRenderer(int row, int col) const; | |
1289 | ||
1290 | // takes ownership of the pointer | |
1291 | void SetDefaultEditor(wxGridCellEditor *editor); | |
1292 | void SetCellEditor(int row, int col, wxGridCellEditor *editor); | |
1293 | wxGridCellEditor *GetDefaultEditor() const; | |
1294 | wxGridCellEditor* GetCellEditor(int row, int col) const; | |
1295 | ||
1296 | ||
1297 | ||
1298 | // ------ cell value accessors | |
1299 | // | |
1300 | wxString GetCellValue( int row, int col ) const | |
1301 | { | |
1302 | if ( m_table ) | |
1303 | { | |
1304 | return m_table->GetValue( row, col ); | |
1305 | } | |
1306 | else | |
1307 | { | |
1308 | return wxEmptyString; | |
1309 | } | |
1310 | } | |
1311 | ||
1312 | wxString GetCellValue( const wxGridCellCoords& coords ) const | |
1313 | { return GetCellValue( coords.GetRow(), coords.GetCol() ); } | |
1314 | ||
1315 | void SetCellValue( int row, int col, const wxString& s ); | |
1316 | void SetCellValue( const wxGridCellCoords& coords, const wxString& s ) | |
1317 | { SetCellValue( coords.GetRow(), coords.GetCol(), s ); } | |
1318 | ||
1319 | // returns true if the cell can't be edited | |
1320 | bool IsReadOnly(int row, int col) const; | |
1321 | ||
1322 | // make the cell editable/readonly | |
1323 | void SetReadOnly(int row, int col, bool isReadOnly = true); | |
1324 | ||
1325 | // ------ select blocks of cells | |
1326 | // | |
1327 | void SelectRow( int row, bool addToSelected = false ); | |
1328 | void SelectCol( int col, bool addToSelected = false ); | |
1329 | ||
1330 | void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, | |
1331 | bool addToSelected = false ); | |
1332 | ||
1333 | void SelectBlock( const wxGridCellCoords& topLeft, | |
1334 | const wxGridCellCoords& bottomRight, | |
1335 | bool addToSelected = false ) | |
1336 | { SelectBlock( topLeft.GetRow(), topLeft.GetCol(), | |
1337 | bottomRight.GetRow(), bottomRight.GetCol(), | |
1338 | addToSelected ); } | |
1339 | ||
1340 | void SelectAll(); | |
1341 | ||
1342 | bool IsSelection() const; | |
1343 | ||
1344 | // ------ deselect blocks or cells | |
1345 | // | |
1346 | void DeselectRow( int row ); | |
1347 | void DeselectCol( int col ); | |
1348 | void DeselectCell( int row, int col ); | |
1349 | ||
1350 | void ClearSelection(); | |
1351 | ||
1352 | bool IsInSelection( int row, int col ) const; | |
1353 | ||
1354 | bool IsInSelection( const wxGridCellCoords& coords ) const | |
1355 | { return IsInSelection( coords.GetRow(), coords.GetCol() ); } | |
1356 | ||
1357 | wxGridCellCoordsArray GetSelectedCells() const; | |
1358 | wxGridCellCoordsArray GetSelectionBlockTopLeft() const; | |
1359 | wxGridCellCoordsArray GetSelectionBlockBottomRight() const; | |
1360 | wxArrayInt GetSelectedRows() const; | |
1361 | wxArrayInt GetSelectedCols() const; | |
1362 | ||
1363 | // This function returns the rectangle that encloses the block of cells | |
1364 | // limited by TopLeft and BottomRight cell in device coords and clipped | |
1365 | // to the client size of the grid window. | |
1366 | // | |
1367 | wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft, | |
1368 | const wxGridCellCoords & bottomRight ) const; | |
1369 | ||
1370 | // Access or update the selection fore/back colours | |
1371 | wxColour GetSelectionBackground() const | |
1372 | { return m_selectionBackground; } | |
1373 | wxColour GetSelectionForeground() const | |
1374 | { return m_selectionForeground; } | |
1375 | ||
1376 | void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; } | |
1377 | void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; } | |
1378 | ||
1379 | ||
1380 | // Methods for a registry for mapping data types to Renderers/Editors | |
1381 | void RegisterDataType(const wxString& typeName, | |
1382 | wxGridCellRenderer* renderer, | |
1383 | wxGridCellEditor* editor); | |
1384 | // DJC MAPTEK | |
1385 | virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const; | |
1386 | wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const | |
1387 | { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); } | |
1388 | virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const; | |
1389 | virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const; | |
1390 | virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const; | |
1391 | ||
1392 | // grid may occupy more space than needed for its rows/columns, this | |
1393 | // function allows to set how big this extra space is | |
1394 | void SetMargins(int extraWidth, int extraHeight) | |
1395 | { | |
1396 | m_extraWidth = extraWidth; | |
1397 | m_extraHeight = extraHeight; | |
1398 | ||
1399 | CalcDimensions(); | |
1400 | } | |
1401 | ||
1402 | // Accessors for component windows | |
1403 | wxWindow* GetGridWindow() const { return (wxWindow*)m_gridWin; } | |
1404 | wxWindow* GetGridRowLabelWindow() const { return (wxWindow*)m_rowLabelWin; } | |
1405 | wxWindow* GetGridColLabelWindow() const { return m_colWindow; } | |
1406 | wxWindow* GetGridCornerLabelWindow() const { return (wxWindow*)m_cornerLabelWin; } | |
1407 | ||
1408 | // This one can only be called if we are using the native header window | |
1409 | wxHeaderCtrl *GetGridColHeader() const | |
1410 | { | |
1411 | wxASSERT_MSG( m_useNativeHeader, "no column header window" ); | |
1412 | ||
1413 | // static_cast<> doesn't work without the full class declaration in | |
1414 | // view and we prefer to avoid adding more compile-time dependencies | |
1415 | // even at the cost of using reinterpret_cast<> | |
1416 | return reinterpret_cast<wxHeaderCtrl *>(m_colWindow); | |
1417 | } | |
1418 | ||
1419 | // Allow adjustment of scroll increment. The default is (15, 15). | |
1420 | void SetScrollLineX(int x) { m_scrollLineX = x; } | |
1421 | void SetScrollLineY(int y) { m_scrollLineY = y; } | |
1422 | int GetScrollLineX() const { return m_scrollLineX; } | |
1423 | int GetScrollLineY() const { return m_scrollLineY; } | |
1424 | ||
1425 | // ------- drag and drop | |
1426 | #if wxUSE_DRAG_AND_DROP | |
1427 | virtual void SetDropTarget(wxDropTarget *dropTarget); | |
1428 | #endif // wxUSE_DRAG_AND_DROP | |
1429 | ||
1430 | ||
1431 | // ------- sorting support | |
1432 | ||
1433 | // wxGrid doesn't support sorting on its own but it can indicate the sort | |
1434 | // order in the column header (currently only if native header control is | |
1435 | // used though) | |
1436 | ||
1437 | // return the column currently displaying the sort indicator or wxNOT_FOUND | |
1438 | // if none | |
1439 | int GetSortingColumn() const { return m_sortCol; } | |
1440 | ||
1441 | // return true if this column is currently used for sorting | |
1442 | bool IsSortingBy(int col) const { return GetSortingColumn() == col; } | |
1443 | ||
1444 | // return the current sorting order (on GetSortingColumn()): true for | |
1445 | // ascending sort and false for descending; it doesn't make sense to call | |
1446 | // it if GetSortingColumn() returns wxNOT_FOUND | |
1447 | bool IsSortOrderAscending() const { return m_sortIsAscending; } | |
1448 | ||
1449 | // set the sorting column (or unsets any existing one if wxNOT_FOUND) and | |
1450 | // the order in which to sort | |
1451 | void SetSortingColumn(int col, bool ascending = true); | |
1452 | ||
1453 | // unset any existing sorting column | |
1454 | void UnsetSortingColumn() { SetSortingColumn(wxNOT_FOUND); } | |
1455 | ||
1456 | #ifdef WXWIN_COMPATIBILITY_2_8 | |
1457 | // ------ For compatibility with previous wxGrid only... | |
1458 | // | |
1459 | // ************************************************ | |
1460 | // ** Don't use these in new code because they ** | |
1461 | // ** are liable to disappear in a future ** | |
1462 | // ** revision ** | |
1463 | // ************************************************ | |
1464 | // | |
1465 | ||
1466 | wxGrid( wxWindow *parent, | |
1467 | int x, int y, int w = wxDefaultCoord, int h = wxDefaultCoord, | |
1468 | long style = wxWANTS_CHARS, | |
1469 | const wxString& name = wxPanelNameStr ) | |
1470 | { | |
1471 | Init(); | |
1472 | Create(parent, wxID_ANY, wxPoint(x, y), wxSize(w, h), style, name); | |
1473 | } | |
1474 | ||
1475 | void SetCellValue( const wxString& val, int row, int col ) | |
1476 | { SetCellValue( row, col, val ); } | |
1477 | ||
1478 | void UpdateDimensions() | |
1479 | { CalcDimensions(); } | |
1480 | ||
1481 | int GetRows() const { return GetNumberRows(); } | |
1482 | int GetCols() const { return GetNumberCols(); } | |
1483 | int GetCursorRow() const { return GetGridCursorRow(); } | |
1484 | int GetCursorColumn() const { return GetGridCursorCol(); } | |
1485 | ||
1486 | int GetScrollPosX() const { return 0; } | |
1487 | int GetScrollPosY() const { return 0; } | |
1488 | ||
1489 | void SetScrollX( int WXUNUSED(x) ) { } | |
1490 | void SetScrollY( int WXUNUSED(y) ) { } | |
1491 | ||
1492 | void SetColumnWidth( int col, int width ) | |
1493 | { SetColSize( col, width ); } | |
1494 | ||
1495 | int GetColumnWidth( int col ) const | |
1496 | { return GetColSize( col ); } | |
1497 | ||
1498 | void SetRowHeight( int row, int height ) | |
1499 | { SetRowSize( row, height ); } | |
1500 | ||
1501 | // GetRowHeight() is below | |
1502 | ||
1503 | int GetViewHeight() const // returned num whole rows visible | |
1504 | { return 0; } | |
1505 | ||
1506 | int GetViewWidth() const // returned num whole cols visible | |
1507 | { return 0; } | |
1508 | ||
1509 | void SetLabelSize( int orientation, int sz ) | |
1510 | { | |
1511 | if ( orientation == wxHORIZONTAL ) | |
1512 | SetColLabelSize( sz ); | |
1513 | else | |
1514 | SetRowLabelSize( sz ); | |
1515 | } | |
1516 | ||
1517 | int GetLabelSize( int orientation ) const | |
1518 | { | |
1519 | if ( orientation == wxHORIZONTAL ) | |
1520 | return GetColLabelSize(); | |
1521 | else | |
1522 | return GetRowLabelSize(); | |
1523 | } | |
1524 | ||
1525 | void SetLabelAlignment( int orientation, int align ) | |
1526 | { | |
1527 | if ( orientation == wxHORIZONTAL ) | |
1528 | SetColLabelAlignment( align, -1 ); | |
1529 | else | |
1530 | SetRowLabelAlignment( align, -1 ); | |
1531 | } | |
1532 | ||
1533 | int GetLabelAlignment( int orientation, int WXUNUSED(align) ) const | |
1534 | { | |
1535 | int h, v; | |
1536 | if ( orientation == wxHORIZONTAL ) | |
1537 | { | |
1538 | GetColLabelAlignment( &h, &v ); | |
1539 | return h; | |
1540 | } | |
1541 | else | |
1542 | { | |
1543 | GetRowLabelAlignment( &h, &v ); | |
1544 | return h; | |
1545 | } | |
1546 | } | |
1547 | ||
1548 | void SetLabelValue( int orientation, const wxString& val, int pos ) | |
1549 | { | |
1550 | if ( orientation == wxHORIZONTAL ) | |
1551 | SetColLabelValue( pos, val ); | |
1552 | else | |
1553 | SetRowLabelValue( pos, val ); | |
1554 | } | |
1555 | ||
1556 | wxString GetLabelValue( int orientation, int pos) const | |
1557 | { | |
1558 | if ( orientation == wxHORIZONTAL ) | |
1559 | return GetColLabelValue( pos ); | |
1560 | else | |
1561 | return GetRowLabelValue( pos ); | |
1562 | } | |
1563 | ||
1564 | wxFont GetCellTextFont() const | |
1565 | { return m_defaultCellAttr->GetFont(); } | |
1566 | ||
1567 | wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const | |
1568 | { return m_defaultCellAttr->GetFont(); } | |
1569 | ||
1570 | void SetCellTextFont(const wxFont& fnt) | |
1571 | { SetDefaultCellFont( fnt ); } | |
1572 | ||
1573 | void SetCellTextFont(const wxFont& fnt, int row, int col) | |
1574 | { SetCellFont( row, col, fnt ); } | |
1575 | ||
1576 | void SetCellTextColour(const wxColour& val, int row, int col) | |
1577 | { SetCellTextColour( row, col, val ); } | |
1578 | ||
1579 | void SetCellTextColour(const wxColour& col) | |
1580 | { SetDefaultCellTextColour( col ); } | |
1581 | ||
1582 | void SetCellBackgroundColour(const wxColour& col) | |
1583 | { SetDefaultCellBackgroundColour( col ); } | |
1584 | ||
1585 | void SetCellBackgroundColour(const wxColour& colour, int row, int col) | |
1586 | { SetCellBackgroundColour( row, col, colour ); } | |
1587 | ||
1588 | bool GetEditable() const { return IsEditable(); } | |
1589 | void SetEditable( bool edit = true ) { EnableEditing( edit ); } | |
1590 | bool GetEditInPlace() const { return IsCellEditControlEnabled(); } | |
1591 | ||
1592 | void SetEditInPlace(bool WXUNUSED(edit) = true) { } | |
1593 | ||
1594 | void SetCellAlignment( int align, int row, int col) | |
1595 | { SetCellAlignment(row, col, align, wxALIGN_CENTER); } | |
1596 | void SetCellAlignment( int WXUNUSED(align) ) {} | |
1597 | void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col)) | |
1598 | { } | |
1599 | void SetDividerPen(const wxPen& WXUNUSED(pen)) { } | |
1600 | wxPen& GetDividerPen() const; | |
1601 | void OnActivate(bool WXUNUSED(active)) {} | |
1602 | ||
1603 | // ******** End of compatibility functions ********** | |
1604 | ||
1605 | ||
1606 | ||
1607 | // ------ control IDs | |
1608 | enum { wxGRID_CELLCTRL = 2000, | |
1609 | wxGRID_TOPCTRL }; | |
1610 | ||
1611 | // ------ control types | |
1612 | enum { wxGRID_TEXTCTRL = 2100, | |
1613 | wxGRID_CHECKBOX, | |
1614 | wxGRID_CHOICE, | |
1615 | wxGRID_COMBOBOX }; | |
1616 | #endif // WXWIN_COMPATIBILITY_2_8 | |
1617 | ||
1618 | ||
1619 | // override some base class functions | |
1620 | virtual bool Enable(bool enable = true); | |
1621 | virtual wxWindow *GetMainWindowOfCompositeControl() | |
1622 | { return (wxWindow*)m_gridWin; } | |
1623 | virtual void Fit(); | |
1624 | ||
1625 | // implementation only | |
1626 | void CancelMouseCapture(); | |
1627 | ||
1628 | protected: | |
1629 | virtual wxSize DoGetBestSize() const; | |
1630 | ||
1631 | bool m_created; | |
1632 | ||
1633 | wxGridWindow *m_gridWin; | |
1634 | wxGridCornerLabelWindow *m_cornerLabelWin; | |
1635 | wxGridRowLabelWindow *m_rowLabelWin; | |
1636 | ||
1637 | // the real type of the column window depends on m_useNativeHeader value: | |
1638 | // if it is true, its dynamic type is wxHeaderCtrl, otherwise it is | |
1639 | // wxGridColLabelWindow, use accessors below when the real type matters | |
1640 | wxWindow *m_colWindow; | |
1641 | ||
1642 | wxGridColLabelWindow *GetColLabelWindow() const | |
1643 | { | |
1644 | wxASSERT_MSG( !m_useNativeHeader, "no column label window" ); | |
1645 | ||
1646 | return reinterpret_cast<wxGridColLabelWindow *>(m_colWindow); | |
1647 | } | |
1648 | ||
1649 | wxGridTableBase *m_table; | |
1650 | bool m_ownTable; | |
1651 | ||
1652 | int m_numRows; | |
1653 | int m_numCols; | |
1654 | ||
1655 | wxGridCellCoords m_currentCellCoords; | |
1656 | ||
1657 | // the corners of the block being currently selected or wxGridNoCellCoords | |
1658 | wxGridCellCoords m_selectedBlockTopLeft; | |
1659 | wxGridCellCoords m_selectedBlockBottomRight; | |
1660 | ||
1661 | // when selecting blocks of cells (either from the keyboard using Shift | |
1662 | // with cursor keys, or by dragging the mouse), the selection is anchored | |
1663 | // at m_currentCellCoords which defines one of the corners of the rectangle | |
1664 | // being selected -- and this variable defines the other corner, i.e. it's | |
1665 | // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on | |
1666 | // which of them is not m_currentCellCoords | |
1667 | // | |
1668 | // if no block selection is in process, it is set to wxGridNoCellCoords | |
1669 | wxGridCellCoords m_selectedBlockCorner; | |
1670 | ||
1671 | wxGridSelection *m_selection; | |
1672 | ||
1673 | wxColour m_selectionBackground; | |
1674 | wxColour m_selectionForeground; | |
1675 | ||
1676 | // NB: *never* access m_row/col arrays directly because they are created | |
1677 | // on demand, *always* use accessor functions instead! | |
1678 | ||
1679 | // init the m_rowHeights/Bottoms arrays with default values | |
1680 | void InitRowHeights(); | |
1681 | ||
1682 | int m_defaultRowHeight; | |
1683 | int m_minAcceptableRowHeight; | |
1684 | wxArrayInt m_rowHeights; | |
1685 | wxArrayInt m_rowBottoms; | |
1686 | ||
1687 | // init the m_colWidths/Rights arrays | |
1688 | void InitColWidths(); | |
1689 | ||
1690 | int m_defaultColWidth; | |
1691 | int m_minAcceptableColWidth; | |
1692 | wxArrayInt m_colWidths; | |
1693 | wxArrayInt m_colRights; | |
1694 | ||
1695 | int m_sortCol; | |
1696 | bool m_sortIsAscending; | |
1697 | ||
1698 | bool m_useNativeHeader, | |
1699 | m_nativeColumnLabels; | |
1700 | ||
1701 | // get the col/row coords | |
1702 | int GetColWidth(int col) const; | |
1703 | int GetColLeft(int col) const; | |
1704 | int GetColRight(int col) const; | |
1705 | ||
1706 | // this function must be public for compatibility... | |
1707 | public: | |
1708 | int GetRowHeight(int row) const; | |
1709 | protected: | |
1710 | ||
1711 | int GetRowTop(int row) const; | |
1712 | int GetRowBottom(int row) const; | |
1713 | ||
1714 | int m_rowLabelWidth; | |
1715 | int m_colLabelHeight; | |
1716 | ||
1717 | // the size of the margin left to the right and bottom of the cell area | |
1718 | int m_extraWidth, | |
1719 | m_extraHeight; | |
1720 | ||
1721 | wxColour m_labelBackgroundColour; | |
1722 | wxColour m_labelTextColour; | |
1723 | wxFont m_labelFont; | |
1724 | ||
1725 | int m_rowLabelHorizAlign; | |
1726 | int m_rowLabelVertAlign; | |
1727 | int m_colLabelHorizAlign; | |
1728 | int m_colLabelVertAlign; | |
1729 | int m_colLabelTextOrientation; | |
1730 | ||
1731 | bool m_defaultRowLabelValues; | |
1732 | bool m_defaultColLabelValues; | |
1733 | ||
1734 | wxColour m_gridLineColour; | |
1735 | bool m_gridLinesEnabled; | |
1736 | bool m_gridLinesClipHorz, | |
1737 | m_gridLinesClipVert; | |
1738 | wxColour m_cellHighlightColour; | |
1739 | int m_cellHighlightPenWidth; | |
1740 | int m_cellHighlightROPenWidth; | |
1741 | ||
1742 | ||
1743 | // common part of AutoSizeColumn/Row() and GetBestSize() | |
1744 | int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = true); | |
1745 | int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = true); | |
1746 | ||
1747 | // common part of AutoSizeColumn/Row() | |
1748 | void AutoSizeColOrRow(int n, bool setAsMin, wxGridDirection direction); | |
1749 | ||
1750 | // Calculate the minimum acceptable size for labels area | |
1751 | wxCoord CalcColOrRowLabelAreaMinSize(wxGridDirection direction); | |
1752 | ||
1753 | // if a column has a minimal width, it will be the value for it in this | |
1754 | // hash table | |
1755 | wxLongToLongHashMap m_colMinWidths, | |
1756 | m_rowMinHeights; | |
1757 | ||
1758 | // get the minimal width of the given column/row | |
1759 | int GetColMinimalWidth(int col) const; | |
1760 | int GetRowMinimalHeight(int col) const; | |
1761 | ||
1762 | // do we have some place to store attributes in? | |
1763 | bool CanHaveAttributes() const; | |
1764 | ||
1765 | // cell attribute cache (currently we only cache 1, may be will do | |
1766 | // more/better later) | |
1767 | struct CachedAttr | |
1768 | { | |
1769 | int row, col; | |
1770 | wxGridCellAttr *attr; | |
1771 | } m_attrCache; | |
1772 | ||
1773 | // invalidates the attribute cache | |
1774 | void ClearAttrCache(); | |
1775 | ||
1776 | // adds an attribute to cache | |
1777 | void CacheAttr(int row, int col, wxGridCellAttr *attr) const; | |
1778 | ||
1779 | // looks for an attr in cache, returns true if found | |
1780 | bool LookupAttr(int row, int col, wxGridCellAttr **attr) const; | |
1781 | ||
1782 | // looks for the attr in cache, if not found asks the table and caches the | |
1783 | // result | |
1784 | wxGridCellAttr *GetCellAttr(int row, int col) const; | |
1785 | wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords ) const | |
1786 | { return GetCellAttr( coords.GetRow(), coords.GetCol() ); } | |
1787 | ||
1788 | // the default cell attr object for cells that don't have their own | |
1789 | wxGridCellAttr* m_defaultCellAttr; | |
1790 | ||
1791 | ||
1792 | bool m_inOnKeyDown; | |
1793 | int m_batchCount; | |
1794 | ||
1795 | ||
1796 | wxGridTypeRegistry* m_typeRegistry; | |
1797 | ||
1798 | enum CursorMode | |
1799 | { | |
1800 | WXGRID_CURSOR_SELECT_CELL, | |
1801 | WXGRID_CURSOR_RESIZE_ROW, | |
1802 | WXGRID_CURSOR_RESIZE_COL, | |
1803 | WXGRID_CURSOR_SELECT_ROW, | |
1804 | WXGRID_CURSOR_SELECT_COL, | |
1805 | WXGRID_CURSOR_MOVE_COL | |
1806 | }; | |
1807 | ||
1808 | // this method not only sets m_cursorMode but also sets the correct cursor | |
1809 | // for the given mode and, if captureMouse is not false releases the mouse | |
1810 | // if it was captured and captures it if it must be captured | |
1811 | // | |
1812 | // for this to work, you should always use it and not set m_cursorMode | |
1813 | // directly! | |
1814 | void ChangeCursorMode(CursorMode mode, | |
1815 | wxWindow *win = NULL, | |
1816 | bool captureMouse = true); | |
1817 | ||
1818 | wxWindow *m_winCapture; // the window which captured the mouse | |
1819 | ||
1820 | // this variable is used not for finding the correct current cursor but | |
1821 | // mainly for finding out what is going to happen if the mouse starts being | |
1822 | // dragged right now | |
1823 | // | |
1824 | // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is | |
1825 | // going on, and it is set to one of RESIZE/SELECT/MOVE values while the | |
1826 | // corresponding operation will be started if the user starts dragging the | |
1827 | // mouse from the current position | |
1828 | CursorMode m_cursorMode; | |
1829 | ||
1830 | ||
1831 | //Column positions | |
1832 | wxArrayInt m_colAt; | |
1833 | ||
1834 | bool m_canDragRowSize; | |
1835 | bool m_canDragColSize; | |
1836 | bool m_canDragColMove; | |
1837 | bool m_canDragGridSize; | |
1838 | bool m_canDragCell; | |
1839 | ||
1840 | // the last position (horizontal or vertical depending on whether the user | |
1841 | // is resizing a column or a row) where a row or column separator line was | |
1842 | // dragged by the user or -1 of there is no drag operation in progress | |
1843 | int m_dragLastPos; | |
1844 | int m_dragRowOrCol; | |
1845 | ||
1846 | // true if a drag operation is in progress; when this is true, | |
1847 | // m_startDragPos is valid, i.e. not wxDefaultPosition | |
1848 | bool m_isDragging; | |
1849 | ||
1850 | // the position (in physical coordinates) where the user started dragging | |
1851 | // the mouse or wxDefaultPosition if mouse isn't being dragged | |
1852 | // | |
1853 | // notice that this can be != wxDefaultPosition while m_isDragging is still | |
1854 | // false because we wait until the mouse is moved some distance away before | |
1855 | // setting m_isDragging to true | |
1856 | wxPoint m_startDragPos; | |
1857 | ||
1858 | bool m_waitForSlowClick; | |
1859 | ||
1860 | wxGridCellCoords m_selectionStart; | |
1861 | ||
1862 | wxCursor m_rowResizeCursor; | |
1863 | wxCursor m_colResizeCursor; | |
1864 | ||
1865 | bool m_editable; // applies to whole grid | |
1866 | bool m_cellEditCtrlEnabled; // is in-place edit currently shown? | |
1867 | ||
1868 | int m_scrollLineX; // X scroll increment | |
1869 | int m_scrollLineY; // Y scroll increment | |
1870 | ||
1871 | void Init(); // common part of all ctors | |
1872 | void Create(); | |
1873 | void CreateColumnWindow(); | |
1874 | void CalcDimensions(); | |
1875 | void CalcWindowSizes(); | |
1876 | bool Redimension( wxGridTableMessage& ); | |
1877 | ||
1878 | ||
1879 | // generate the appropriate grid event and return -1 if it was vetoed, 1 if | |
1880 | // it was processed (but not vetoed) and 0 if it wasn't processed | |
1881 | int SendEvent(const wxEventType evtType, | |
1882 | int row, int col, | |
1883 | wxMouseEvent& e); | |
1884 | int SendEvent(const wxEventType evtType, | |
1885 | const wxGridCellCoords& coords, | |
1886 | wxMouseEvent& e) | |
1887 | { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); } | |
1888 | int SendEvent(const wxEventType evtType, | |
1889 | int row, int col, | |
1890 | const wxString& s = wxString()); | |
1891 | int SendEvent(const wxEventType evtType, | |
1892 | const wxGridCellCoords& coords, | |
1893 | const wxString& s = wxString()) | |
1894 | { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), s); } | |
1895 | int SendEvent(const wxEventType evtType, const wxString& s = wxString()) | |
1896 | { return SendEvent(evtType, m_currentCellCoords, s); } | |
1897 | ||
1898 | void OnPaint( wxPaintEvent& ); | |
1899 | void OnSize( wxSizeEvent& ); | |
1900 | void OnKeyDown( wxKeyEvent& ); | |
1901 | void OnKeyUp( wxKeyEvent& ); | |
1902 | void OnChar( wxKeyEvent& ); | |
1903 | void OnEraseBackground( wxEraseEvent& ); | |
1904 | ||
1905 | ||
1906 | bool SetCurrentCell( const wxGridCellCoords& coords ); | |
1907 | bool SetCurrentCell( int row, int col ) | |
1908 | { return SetCurrentCell( wxGridCellCoords(row, col) ); } | |
1909 | ||
1910 | ||
1911 | // this function is called to extend the block being currently selected | |
1912 | // from mouse and keyboard event handlers | |
1913 | void UpdateBlockBeingSelected(int topRow, int leftCol, | |
1914 | int bottomRow, int rightCol); | |
1915 | ||
1916 | void UpdateBlockBeingSelected(const wxGridCellCoords& topLeft, | |
1917 | const wxGridCellCoords& bottomRight) | |
1918 | { UpdateBlockBeingSelected(topLeft.GetRow(), topLeft.GetCol(), | |
1919 | bottomRight.GetRow(), bottomRight.GetCol()); } | |
1920 | ||
1921 | // ------ functions to get/send data (see also public functions) | |
1922 | // | |
1923 | bool GetModelValues(); | |
1924 | bool SetModelValues(); | |
1925 | ||
1926 | friend class WXDLLIMPEXP_FWD_ADV wxGridSelection; | |
1927 | friend class wxGridRowOperations; | |
1928 | friend class wxGridColumnOperations; | |
1929 | ||
1930 | // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent() | |
1931 | friend class wxGridCornerLabelWindow; | |
1932 | friend class wxGridColLabelWindow; | |
1933 | friend class wxGridRowLabelWindow; | |
1934 | friend class wxGridWindow; | |
1935 | ||
1936 | friend class wxGridHeaderCtrl; | |
1937 | ||
1938 | private: | |
1939 | // implement wxScrolledWindow method to return m_gridWin size | |
1940 | virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); | |
1941 | ||
1942 | // redraw the grid lines, should be called after changing their attributes | |
1943 | void RedrawGridLines(); | |
1944 | ||
1945 | // common part of Clip{Horz,Vert}GridLines | |
1946 | void DoClipGridLines(bool& var, bool clip); | |
1947 | ||
1948 | // update the sorting indicator shown in the specified column (whose index | |
1949 | // must be valid) | |
1950 | // | |
1951 | // this will use GetSortingColumn() and IsSortOrderAscending() to determine | |
1952 | // the sorting indicator to effectively show | |
1953 | void UpdateColumnSortingIndicator(int col); | |
1954 | ||
1955 | // update the grid after changing the columns order (common part of | |
1956 | // SetColPos() and ResetColPos()) | |
1957 | void RefreshAfterColPosChange(); | |
1958 | ||
1959 | ||
1960 | // return the position (not index) of the column at the given logical pixel | |
1961 | // position | |
1962 | // | |
1963 | // this always returns a valid position, even if the coordinate is out of | |
1964 | // bounds (in which case first/last column is returned) | |
1965 | int XToPos(int x) const; | |
1966 | ||
1967 | ||
1968 | // event handlers and their helpers | |
1969 | // -------------------------------- | |
1970 | ||
1971 | // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode | |
1972 | void DoGridCellDrag(wxMouseEvent& event, | |
1973 | const wxGridCellCoords& coords, | |
1974 | bool isFirstDrag); | |
1975 | ||
1976 | // process row/column resizing drag event | |
1977 | void DoGridLineDrag(wxMouseEvent& event, const wxGridOperations& oper); | |
1978 | ||
1979 | // process mouse drag event in the grid window | |
1980 | void DoGridDragEvent(wxMouseEvent& event, const wxGridCellCoords& coords); | |
1981 | ||
1982 | // process different clicks on grid cells | |
1983 | void DoGridCellLeftDown(wxMouseEvent& event, | |
1984 | const wxGridCellCoords& coords, | |
1985 | const wxPoint& pos); | |
1986 | void DoGridCellLeftDClick(wxMouseEvent& event, | |
1987 | const wxGridCellCoords& coords, | |
1988 | const wxPoint& pos); | |
1989 | void DoGridCellLeftUp(wxMouseEvent& event, const wxGridCellCoords& coords); | |
1990 | ||
1991 | // process movement (but not dragging) event in the grid cell area | |
1992 | void DoGridMouseMoveEvent(wxMouseEvent& event, | |
1993 | const wxGridCellCoords& coords, | |
1994 | const wxPoint& pos); | |
1995 | ||
1996 | // process mouse events in the grid window | |
1997 | void ProcessGridCellMouseEvent(wxMouseEvent& event); | |
1998 | ||
1999 | // process mouse events in the row/column labels/corner windows | |
2000 | void ProcessRowLabelMouseEvent(wxMouseEvent& event); | |
2001 | void ProcessColLabelMouseEvent(wxMouseEvent& event); | |
2002 | void ProcessCornerLabelMouseEvent(wxMouseEvent& event); | |
2003 | ||
2004 | void DoColHeaderClick(int col); | |
2005 | ||
2006 | void DoStartResizeCol(int col); | |
2007 | void DoUpdateResizeCol(int x); | |
2008 | void DoUpdateResizeColWidth(int w); | |
2009 | void DoStartMoveCol(int col); | |
2010 | ||
2011 | void DoEndDragResizeRow(); | |
2012 | void DoEndDragResizeCol(wxMouseEvent *event = NULL); | |
2013 | void DoEndMoveCol(int pos); | |
2014 | ||
2015 | ||
2016 | // common implementations of methods defined for both rows and columns | |
2017 | void DeselectLine(int line, const wxGridOperations& oper); | |
2018 | void DoEndDragResizeLine(const wxGridOperations& oper); | |
2019 | int PosToLinePos(int pos, bool clipToMinMax, | |
2020 | const wxGridOperations& oper) const; | |
2021 | int PosToLine(int pos, bool clipToMinMax, | |
2022 | const wxGridOperations& oper) const; | |
2023 | int PosToEdgeOfLine(int pos, const wxGridOperations& oper) const; | |
2024 | ||
2025 | bool DoMoveCursor(bool expandSelection, | |
2026 | const wxGridDirectionOperations& diroper); | |
2027 | bool DoMoveCursorByPage(const wxGridDirectionOperations& diroper); | |
2028 | bool DoMoveCursorByBlock(bool expandSelection, | |
2029 | const wxGridDirectionOperations& diroper); | |
2030 | void AdvanceToNextNonEmpty(wxGridCellCoords& coords, | |
2031 | const wxGridDirectionOperations& diroper); | |
2032 | ||
2033 | // common part of {Insert,Delete}{Rows,Cols} | |
2034 | bool DoModifyLines(bool (wxGridTableBase::*funcModify)(size_t, size_t), | |
2035 | int pos, int num, bool updateLabels); | |
2036 | // Append{Rows,Cols} is a bit different because of one less parameter | |
2037 | bool DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t), | |
2038 | int num, bool updateLabels); | |
2039 | ||
2040 | DECLARE_DYNAMIC_CLASS( wxGrid ) | |
2041 | DECLARE_EVENT_TABLE() | |
2042 | DECLARE_NO_COPY_CLASS(wxGrid) | |
2043 | }; | |
2044 | ||
2045 | // ---------------------------------------------------------------------------- | |
2046 | // wxGridUpdateLocker prevents updates to a grid during its lifetime | |
2047 | // ---------------------------------------------------------------------------- | |
2048 | ||
2049 | class WXDLLIMPEXP_ADV wxGridUpdateLocker | |
2050 | { | |
2051 | public: | |
2052 | // if the pointer is NULL, Create() can be called later | |
2053 | wxGridUpdateLocker(wxGrid *grid = NULL) | |
2054 | { | |
2055 | Init(grid); | |
2056 | } | |
2057 | ||
2058 | // can be called if ctor was used with a NULL pointer, must not be called | |
2059 | // more than once | |
2060 | void Create(wxGrid *grid) | |
2061 | { | |
2062 | wxASSERT_MSG( !m_grid, _T("shouldn't be called more than once") ); | |
2063 | ||
2064 | Init(grid); | |
2065 | } | |
2066 | ||
2067 | ~wxGridUpdateLocker() | |
2068 | { | |
2069 | if ( m_grid ) | |
2070 | m_grid->EndBatch(); | |
2071 | } | |
2072 | ||
2073 | private: | |
2074 | void Init(wxGrid *grid) | |
2075 | { | |
2076 | m_grid = grid; | |
2077 | if ( m_grid ) | |
2078 | m_grid->BeginBatch(); | |
2079 | } | |
2080 | ||
2081 | wxGrid *m_grid; | |
2082 | ||
2083 | DECLARE_NO_COPY_CLASS(wxGridUpdateLocker) | |
2084 | }; | |
2085 | ||
2086 | // ---------------------------------------------------------------------------- | |
2087 | // Grid event class and event types | |
2088 | // ---------------------------------------------------------------------------- | |
2089 | ||
2090 | class WXDLLIMPEXP_ADV wxGridEvent : public wxNotifyEvent, | |
2091 | public wxKeyboardState | |
2092 | { | |
2093 | public: | |
2094 | wxGridEvent() | |
2095 | : wxNotifyEvent() | |
2096 | { | |
2097 | Init(-1, -1, -1, -1, false); | |
2098 | } | |
2099 | ||
2100 | wxGridEvent(int id, | |
2101 | wxEventType type, | |
2102 | wxObject* obj, | |
2103 | int row = -1, int col = -1, | |
2104 | int x = -1, int y = -1, | |
2105 | bool sel = true, | |
2106 | const wxKeyboardState& kbd = wxKeyboardState()) | |
2107 | : wxNotifyEvent(type, id), | |
2108 | wxKeyboardState(kbd) | |
2109 | { | |
2110 | Init(row, col, x, y, sel); | |
2111 | SetEventObject(obj); | |
2112 | } | |
2113 | ||
2114 | // explicitly specifying inline allows gcc < 3.4 to | |
2115 | // handle the deprecation attribute even in the constructor. | |
2116 | wxDEPRECATED( inline | |
2117 | wxGridEvent(int id, | |
2118 | wxEventType type, | |
2119 | wxObject* obj, | |
2120 | int row, int col, | |
2121 | int x, int y, | |
2122 | bool sel, | |
2123 | bool control, | |
2124 | bool shift = false, bool alt = false, bool meta = false)); | |
2125 | ||
2126 | virtual int GetRow() { return m_row; } | |
2127 | virtual int GetCol() { return m_col; } | |
2128 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } | |
2129 | bool Selecting() { return m_selecting; } | |
2130 | ||
2131 | virtual wxEvent *Clone() const { return new wxGridEvent(*this); } | |
2132 | ||
2133 | protected: | |
2134 | int m_row; | |
2135 | int m_col; | |
2136 | int m_x; | |
2137 | int m_y; | |
2138 | bool m_selecting; | |
2139 | ||
2140 | private: | |
2141 | void Init(int row, int col, int x, int y, bool sel) | |
2142 | { | |
2143 | m_row = row; | |
2144 | m_col = col; | |
2145 | m_x = x; | |
2146 | m_y = y; | |
2147 | m_selecting = sel; | |
2148 | } | |
2149 | ||
2150 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent) | |
2151 | }; | |
2152 | ||
2153 | class WXDLLIMPEXP_ADV wxGridSizeEvent : public wxNotifyEvent, | |
2154 | public wxKeyboardState | |
2155 | { | |
2156 | public: | |
2157 | wxGridSizeEvent() | |
2158 | : wxNotifyEvent() | |
2159 | { | |
2160 | Init(-1, -1, -1); | |
2161 | } | |
2162 | ||
2163 | wxGridSizeEvent(int id, | |
2164 | wxEventType type, | |
2165 | wxObject* obj, | |
2166 | int rowOrCol = -1, | |
2167 | int x = -1, int y = -1, | |
2168 | const wxKeyboardState& kbd = wxKeyboardState()) | |
2169 | : wxNotifyEvent(type, id), | |
2170 | wxKeyboardState(kbd) | |
2171 | { | |
2172 | Init(rowOrCol, x, y); | |
2173 | ||
2174 | SetEventObject(obj); | |
2175 | } | |
2176 | ||
2177 | wxDEPRECATED( inline | |
2178 | wxGridSizeEvent(int id, | |
2179 | wxEventType type, | |
2180 | wxObject* obj, | |
2181 | int rowOrCol, | |
2182 | int x, int y, | |
2183 | bool control, | |
2184 | bool shift = false, | |
2185 | bool alt = false, | |
2186 | bool meta = false) ); | |
2187 | ||
2188 | int GetRowOrCol() { return m_rowOrCol; } | |
2189 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } | |
2190 | ||
2191 | virtual wxEvent *Clone() const { return new wxGridSizeEvent(*this); } | |
2192 | ||
2193 | protected: | |
2194 | int m_rowOrCol; | |
2195 | int m_x; | |
2196 | int m_y; | |
2197 | ||
2198 | private: | |
2199 | void Init(int rowOrCol, int x, int y) | |
2200 | { | |
2201 | m_rowOrCol = rowOrCol; | |
2202 | m_x = x; | |
2203 | m_y = y; | |
2204 | } | |
2205 | ||
2206 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent) | |
2207 | }; | |
2208 | ||
2209 | ||
2210 | class WXDLLIMPEXP_ADV wxGridRangeSelectEvent : public wxNotifyEvent, | |
2211 | public wxKeyboardState | |
2212 | { | |
2213 | public: | |
2214 | wxGridRangeSelectEvent() | |
2215 | : wxNotifyEvent() | |
2216 | { | |
2217 | Init(wxGridNoCellCoords, wxGridNoCellCoords, false); | |
2218 | } | |
2219 | ||
2220 | wxGridRangeSelectEvent(int id, | |
2221 | wxEventType type, | |
2222 | wxObject* obj, | |
2223 | const wxGridCellCoords& topLeft, | |
2224 | const wxGridCellCoords& bottomRight, | |
2225 | bool sel = true, | |
2226 | const wxKeyboardState& kbd = wxKeyboardState()) | |
2227 | : wxNotifyEvent(type, id), | |
2228 | wxKeyboardState(kbd) | |
2229 | { | |
2230 | Init(topLeft, bottomRight, sel); | |
2231 | ||
2232 | SetEventObject(obj); | |
2233 | } | |
2234 | ||
2235 | wxDEPRECATED( inline | |
2236 | wxGridRangeSelectEvent(int id, | |
2237 | wxEventType type, | |
2238 | wxObject* obj, | |
2239 | const wxGridCellCoords& topLeft, | |
2240 | const wxGridCellCoords& bottomRight, | |
2241 | bool sel, | |
2242 | bool control, | |
2243 | bool shift = false, | |
2244 | bool alt = false, | |
2245 | bool meta = false) ); | |
2246 | ||
2247 | wxGridCellCoords GetTopLeftCoords() { return m_topLeft; } | |
2248 | wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; } | |
2249 | int GetTopRow() { return m_topLeft.GetRow(); } | |
2250 | int GetBottomRow() { return m_bottomRight.GetRow(); } | |
2251 | int GetLeftCol() { return m_topLeft.GetCol(); } | |
2252 | int GetRightCol() { return m_bottomRight.GetCol(); } | |
2253 | bool Selecting() { return m_selecting; } | |
2254 | ||
2255 | virtual wxEvent *Clone() const { return new wxGridRangeSelectEvent(*this); } | |
2256 | ||
2257 | protected: | |
2258 | void Init(const wxGridCellCoords& topLeft, | |
2259 | const wxGridCellCoords& bottomRight, | |
2260 | bool selecting) | |
2261 | { | |
2262 | m_topLeft = topLeft; | |
2263 | m_bottomRight = bottomRight; | |
2264 | m_selecting = selecting; | |
2265 | } | |
2266 | ||
2267 | wxGridCellCoords m_topLeft; | |
2268 | wxGridCellCoords m_bottomRight; | |
2269 | bool m_selecting; | |
2270 | ||
2271 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent) | |
2272 | }; | |
2273 | ||
2274 | ||
2275 | class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent : public wxCommandEvent | |
2276 | { | |
2277 | public: | |
2278 | wxGridEditorCreatedEvent() | |
2279 | : wxCommandEvent() | |
2280 | { | |
2281 | m_row = 0; | |
2282 | m_col = 0; | |
2283 | m_ctrl = NULL; | |
2284 | } | |
2285 | ||
2286 | wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj, | |
2287 | int row, int col, wxControl* ctrl); | |
2288 | ||
2289 | int GetRow() { return m_row; } | |
2290 | int GetCol() { return m_col; } | |
2291 | wxControl* GetControl() { return m_ctrl; } | |
2292 | void SetRow(int row) { m_row = row; } | |
2293 | void SetCol(int col) { m_col = col; } | |
2294 | void SetControl(wxControl* ctrl) { m_ctrl = ctrl; } | |
2295 | ||
2296 | virtual wxEvent *Clone() const { return new wxGridEditorCreatedEvent(*this); } | |
2297 | ||
2298 | private: | |
2299 | int m_row; | |
2300 | int m_col; | |
2301 | wxControl* m_ctrl; | |
2302 | ||
2303 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent) | |
2304 | }; | |
2305 | ||
2306 | ||
2307 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_LEFT_CLICK, wxGridEvent ) | |
2308 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEvent ) | |
2309 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEvent ) | |
2310 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_RIGHT_DCLICK, wxGridEvent ) | |
2311 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEvent ) | |
2312 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEvent ) | |
2313 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEvent ) | |
2314 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent ) | |
2315 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_ROW_SIZE, wxGridSizeEvent ) | |
2316 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SIZE, wxGridSizeEvent ) | |
2317 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent ) | |
2318 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGING, wxGridEvent ) | |
2319 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGED, wxGridEvent ) | |
2320 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_SELECT_CELL, wxGridEvent ) | |
2321 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_SHOWN, wxGridEvent ) | |
2322 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_HIDDEN, wxGridEvent ) | |
2323 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_CREATED, wxGridEditorCreatedEvent ) | |
2324 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_BEGIN_DRAG, wxGridEvent ) | |
2325 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_MOVE, wxGridEvent ) | |
2326 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SORT, wxGridEvent ) | |
2327 | ||
2328 | typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&); | |
2329 | typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&); | |
2330 | typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&); | |
2331 | typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreatedEvent&); | |
2332 | ||
2333 | #define wxGridEventHandler(func) \ | |
2334 | wxEVENT_HANDLER_CAST(wxGridEventFunction, func) | |
2335 | ||
2336 | #define wxGridSizeEventHandler(func) \ | |
2337 | wxEVENT_HANDLER_CAST(wxGridSizeEventFunction, func) | |
2338 | ||
2339 | #define wxGridRangeSelectEventHandler(func) \ | |
2340 | wxEVENT_HANDLER_CAST(wxGridRangeSelectEventFunction, func) | |
2341 | ||
2342 | #define wxGridEditorCreatedEventHandler(func) \ | |
2343 | wxEVENT_HANDLER_CAST(wxGridEditorCreatedEventFunction, func) | |
2344 | ||
2345 | #define wx__DECLARE_GRIDEVT(evt, id, fn) \ | |
2346 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn)) | |
2347 | ||
2348 | #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \ | |
2349 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn)) | |
2350 | ||
2351 | #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \ | |
2352 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn)) | |
2353 | ||
2354 | #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \ | |
2355 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn)) | |
2356 | ||
2357 | #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn) | |
2358 | #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn) | |
2359 | #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn) | |
2360 | #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn) | |
2361 | #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn) | |
2362 | #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn) | |
2363 | #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn) | |
2364 | #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn) | |
2365 | #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn) | |
2366 | #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn) | |
2367 | #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn) | |
2368 | #define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn) | |
2369 | #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn) | |
2370 | #define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn) | |
2371 | #define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn) | |
2372 | #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn) | |
2373 | #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn) | |
2374 | #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn) | |
2375 | #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn) | |
2376 | #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn) | |
2377 | ||
2378 | // same as above but for any id (exists mainly for backwards compatibility but | |
2379 | // then it's also true that you rarely have multiple grid in the same window) | |
2380 | #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn) | |
2381 | #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn) | |
2382 | #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn) | |
2383 | #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn) | |
2384 | #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn) | |
2385 | #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn) | |
2386 | #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn) | |
2387 | #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn) | |
2388 | #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn) | |
2389 | #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn) | |
2390 | #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn) | |
2391 | #define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn) | |
2392 | #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn) | |
2393 | #define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn) | |
2394 | #define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn) | |
2395 | #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn) | |
2396 | #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn) | |
2397 | #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn) | |
2398 | #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn) | |
2399 | #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn) | |
2400 | ||
2401 | // we used to have a single wxEVT_GRID_CELL_CHANGE event but it was split into | |
2402 | // wxEVT_GRID_CELL_CHANGING and CHANGED ones in wx 2.9.0, however the CHANGED | |
2403 | // is basically the same as the old CHANGE event so we keep the name for | |
2404 | // compatibility | |
2405 | #if WXWIN_COMPATIBILITY_2_8 | |
2406 | #define wxEVT_GRID_CELL_CHANGE wxEVT_GRID_CELL_CHANGED | |
2407 | ||
2408 | #define EVT_GRID_CMD_CELL_CHANGE EVT_GRID_CMD_CELL_CHANGED | |
2409 | #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED | |
2410 | #endif // WXWIN_COMPATIBILITY_2_8 | |
2411 | ||
2412 | #if 0 // TODO: implement these ? others ? | |
2413 | ||
2414 | extern const int wxEVT_GRID_CREATE_CELL; | |
2415 | extern const int wxEVT_GRID_CHANGE_LABELS; | |
2416 | extern const int wxEVT_GRID_CHANGE_SEL_LABEL; | |
2417 | ||
2418 | #define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), | |
2419 | #define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), | |
2420 | #define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), | |
2421 | ||
2422 | #endif | |
2423 | ||
2424 | #endif // wxUSE_GRID | |
2425 | #endif // _WX_GENERIC_GRID_H_ |