]>
Commit | Line | Data |
---|---|---|
f85afd4e MB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: grid.h | |
3 | // Purpose: wxGrid and related classes | |
4 | // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn) | |
5 | // Modified by: | |
6 | // Created: 1/08/1999 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Michael Bedward | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | ||
13 | #include "wx/defs.h" | |
14 | ||
15 | #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) | |
16 | #include "gridg.h" | |
17 | #else | |
18 | ||
19 | #ifndef __WXGRID_H__ | |
20 | #define __WXGRID_H__ | |
21 | ||
22 | #ifdef __GNUG__ | |
23 | #pragma interface "grid.h" | |
24 | #endif | |
25 | ||
26 | #include "wx/panel.h" | |
2d66e025 | 27 | #include "wx/scrolwin.h" |
f85afd4e MB |
28 | #include "wx/string.h" |
29 | #include "wx/scrolbar.h" | |
30 | #include "wx/event.h" | |
31 | #include "wx/textctrl.h" | |
32 | #include "wx/combobox.h" | |
33 | #include "wx/dynarray.h" | |
025562fe | 34 | #include "wx/timer.h" |
f85afd4e MB |
35 | |
36 | // Default parameters for wxGrid | |
37 | // | |
38 | #define WXGRID_DEFAULT_NUMBER_ROWS 10 | |
39 | #define WXGRID_DEFAULT_NUMBER_COLS 10 | |
40 | #ifdef __WXMSW__ | |
41 | #define WXGRID_DEFAULT_ROW_HEIGHT 25 | |
42 | #else | |
43 | #define WXGRID_DEFAULT_ROW_HEIGHT 30 | |
44 | #endif // __WXMSW__ | |
45 | #define WXGRID_DEFAULT_COL_WIDTH 80 | |
46 | #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32 | |
47 | #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82 | |
48 | #define WXGRID_LABEL_EDGE_ZONE 5 | |
49 | #define WXGRID_MIN_ROW_HEIGHT 15 | |
50 | #define WXGRID_MIN_COL_WIDTH 15 | |
51 | #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16 | |
f85afd4e | 52 | |
b99be8fb VZ |
53 | // ---------------------------------------------------------------------------- |
54 | // forward declarations | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
ab79958a VZ |
57 | class WXDLLEXPORT wxGrid; |
58 | class WXDLLEXPORT wxGridCellAttr; | |
b99be8fb | 59 | class WXDLLEXPORT wxGridCellAttrProviderData; |
b99be8fb VZ |
60 | class WXDLLEXPORT wxGridColLabelWindow; |
61 | class WXDLLEXPORT wxGridCornerLabelWindow; | |
ab79958a VZ |
62 | class WXDLLEXPORT wxGridRowLabelWindow; |
63 | class WXDLLEXPORT wxGridTableBase; | |
b99be8fb | 64 | class WXDLLEXPORT wxGridWindow; |
ab79958a VZ |
65 | |
66 | // ---------------------------------------------------------------------------- | |
67 | // wxGridCellRenderer: this class is responsible for actually drawing the cell | |
68 | // in the grid. You may pass it to the wxGridCellAttr (below) to change the | |
69 | // format of one given cell or to wxGrid::SetDefaultRenderer() to change the | |
70 | // view of all cells. This is an ABC, you will normally use one of the | |
71 | // predefined derived classes or derive oyur own class from it. | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | class WXDLLEXPORT wxGridCellRenderer | |
75 | { | |
76 | public: | |
77 | // draw the given cell on the provided DC inside the given rectangle | |
78 | // using the style specified by the attribute and the default or selected | |
79 | // state corresponding to the isSelected value. | |
80 | // | |
81 | // this pure virtual function has a default implementation which will | |
82 | // prepare the DC using the given attribute: it will draw the rectangle | |
83 | // with the bg colour from attr and set the text colour and font | |
84 | virtual void Draw(wxGrid& grid, | |
2796cce3 | 85 | wxGridCellAttr& attr, |
ab79958a VZ |
86 | wxDC& dc, |
87 | const wxRect& rect, | |
88 | int row, int col, | |
89 | bool isSelected) = 0; | |
90 | }; | |
91 | ||
92 | // the default renderer for the cells containing string data | |
93 | class WXDLLEXPORT wxGridCellStringRenderer : public wxGridCellRenderer | |
94 | { | |
95 | public: | |
96 | // draw the string | |
97 | virtual void Draw(wxGrid& grid, | |
2796cce3 | 98 | wxGridCellAttr& attr, |
ab79958a VZ |
99 | wxDC& dc, |
100 | const wxRect& rect, | |
101 | int row, int col, | |
102 | bool isSelected); | |
103 | }; | |
f85afd4e | 104 | |
2796cce3 RD |
105 | |
106 | // ---------------------------------------------------------------------------- | |
107 | // wxGridCellEditor: This class is responsible for providing and manipulating | |
108 | // the in-place edit controls for the grid. Instances of wxGridCellEditor | |
109 | // (actually, instances of derived classes since it is an ABC) can be | |
110 | // associated with the cell attributes for individual cells, rows, columns, or | |
111 | // even for the entire grid. | |
112 | // ---------------------------------------------------------------------------- | |
113 | ||
114 | class WXDLLEXPORT wxGridCellEditor | |
115 | { | |
116 | public: | |
117 | wxGridCellEditor(); | |
118 | virtual ~wxGridCellEditor(); | |
119 | ||
120 | bool IsCreated() { return m_control != NULL; } | |
121 | ||
122 | // Creates the actual edit control | |
123 | virtual void Create(wxWindow* parent, | |
124 | wxWindowID id, | |
2796cce3 RD |
125 | wxEvtHandler* evtHandler) = 0; |
126 | ||
127 | // Size and position the edit control | |
128 | virtual void SetSize(const wxRect& rect); | |
129 | ||
3da93aae VZ |
130 | // Show or hide the edit control, use the specified attributes to set |
131 | // colours/fonts for it | |
132 | virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL); | |
2796cce3 RD |
133 | |
134 | // Fetch the value from the table and prepare the edit control | |
135 | // to begin editing. Set the focus to the edit control. | |
3da93aae | 136 | virtual void BeginEdit(int row, int col, wxGrid* grid) = 0; |
2796cce3 RD |
137 | |
138 | // Complete the editing of the current cell. If saveValue is | |
139 | // true then send the new value back to the table. Returns true | |
140 | // if the value has changed. If necessary, the control may be | |
141 | // destroyed. | |
3da93aae | 142 | virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid) = 0; |
2796cce3 RD |
143 | |
144 | // Reset the value in the control back to its starting value | |
145 | virtual void Reset() = 0; | |
146 | ||
fb295790 RD |
147 | // If the editor is enabled by pressing keys on the grid, |
148 | // this will be called to let the editor do something about | |
149 | // that first key if desired. | |
2c9a89e0 RD |
150 | virtual void StartingKey(wxKeyEvent& event); |
151 | ||
2796cce3 RD |
152 | // Some types of controls on some platforms may need some help |
153 | // with the Return key. | |
154 | virtual void HandleReturn(wxKeyEvent& event); | |
155 | ||
156 | // Final cleanup | |
157 | virtual void Destroy(); | |
158 | ||
159 | protected: | |
3da93aae | 160 | // the control we show on screen |
2796cce3 | 161 | wxControl* m_control; |
3da93aae VZ |
162 | |
163 | // if we change the colours/font of the control from the default ones, we | |
164 | // must restore the default later and we save them here between calls to | |
165 | // Show(TRUE) and Show(FALSE) | |
166 | wxColour m_colFgOld, | |
167 | m_colBgOld; | |
168 | wxFont m_fontOld; | |
2796cce3 RD |
169 | }; |
170 | ||
171 | ||
172 | class WXDLLEXPORT wxGridCellTextEditor : public wxGridCellEditor | |
173 | { | |
174 | public: | |
175 | wxGridCellTextEditor(); | |
176 | ||
177 | virtual void Create(wxWindow* parent, | |
178 | wxWindowID id, | |
2796cce3 RD |
179 | wxEvtHandler* evtHandler); |
180 | ||
3da93aae VZ |
181 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
182 | virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid); | |
2796cce3 RD |
183 | |
184 | virtual void Reset(); | |
2c9a89e0 | 185 | virtual void StartingKey(wxKeyEvent& event); |
2796cce3 RD |
186 | virtual void HandleReturn(wxKeyEvent& event); |
187 | ||
188 | ||
189 | private: | |
190 | wxString m_startValue; | |
191 | }; | |
192 | ||
b99be8fb VZ |
193 | // ---------------------------------------------------------------------------- |
194 | // wxGridCellAttr: this class can be used to alter the cells appearance in | |
195 | // the grid by changing their colour/font/... from default. An object of this | |
196 | // class may be returned by wxGridTable::GetAttr(). | |
197 | // ---------------------------------------------------------------------------- | |
198 | ||
199 | class WXDLLEXPORT wxGridCellAttr | |
200 | { | |
201 | public: | |
202 | // ctors | |
203 | wxGridCellAttr() | |
204 | { | |
2e9a6788 | 205 | Init(); |
b99be8fb VZ |
206 | SetAlignment(0, 0); |
207 | } | |
208 | ||
209 | wxGridCellAttr(const wxColour& colText, | |
210 | const wxColour& colBack, | |
211 | const wxFont& font, | |
212 | int hAlign, | |
213 | int vAlign) | |
214 | : m_colText(colText), m_colBack(colBack), m_font(font) | |
215 | { | |
2e9a6788 | 216 | Init(); |
b99be8fb VZ |
217 | SetAlignment(hAlign, vAlign); |
218 | } | |
219 | ||
220 | // default copy ctor ok | |
221 | ||
2e9a6788 VZ |
222 | // this class is ref counted: it is created with ref count of 1, so |
223 | // calling DecRef() once will delete it. Calling IncRef() allows to lock | |
224 | // it until the matching DecRef() is called | |
225 | void IncRef() { m_nRef++; } | |
226 | void DecRef() { if ( !--m_nRef ) delete this; } | |
0a976765 | 227 | void SafeIncRef() { if ( this ) IncRef(); } |
2e9a6788 VZ |
228 | void SafeDecRef() { if ( this ) DecRef(); } |
229 | ||
b99be8fb VZ |
230 | // setters |
231 | void SetTextColour(const wxColour& colText) { m_colText = colText; } | |
232 | void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } | |
233 | void SetFont(const wxFont& font) { m_font = font; } | |
234 | void SetAlignment(int hAlign, int vAlign) | |
235 | { | |
236 | m_hAlign = hAlign; | |
237 | m_vAlign = vAlign; | |
238 | } | |
239 | ||
ab79958a VZ |
240 | // takes ownership of the pointer |
241 | void SetRenderer(wxGridCellRenderer *renderer) | |
242 | { delete m_renderer; m_renderer = renderer; } | |
07296f0b RD |
243 | void SetEditor(wxGridCellEditor* editor) |
244 | { delete m_editor; m_editor = editor; } | |
ab79958a | 245 | |
b99be8fb VZ |
246 | // accessors |
247 | bool HasTextColour() const { return m_colText.Ok(); } | |
248 | bool HasBackgroundColour() const { return m_colBack.Ok(); } | |
249 | bool HasFont() const { return m_font.Ok(); } | |
250 | bool HasAlignment() const { return m_hAlign || m_vAlign; } | |
2796cce3 | 251 | bool HasRenderer() const { return m_renderer != NULL; } |
07296f0b | 252 | bool HasEditor() const { return m_editor != NULL; } |
b99be8fb | 253 | |
2796cce3 RD |
254 | const wxColour& GetTextColour() const; |
255 | const wxColour& GetBackgroundColour() const; | |
256 | const wxFont& GetFont() const; | |
257 | void GetAlignment(int *hAlign, int *vAlign) const; | |
258 | wxGridCellRenderer *GetRenderer() const; | |
07296f0b | 259 | wxGridCellEditor *GetEditor() const; |
b99be8fb | 260 | |
2796cce3 | 261 | void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; } |
ab79958a | 262 | |
b99be8fb | 263 | private: |
2e9a6788 | 264 | // the common part of all ctors |
07296f0b RD |
265 | void Init() { |
266 | m_nRef = 1; | |
267 | m_renderer = NULL; | |
268 | m_editor = NULL; | |
269 | } | |
2e9a6788 VZ |
270 | |
271 | // the dtor is private because only DecRef() can delete us | |
07296f0b | 272 | ~wxGridCellAttr() { delete m_renderer; delete m_editor; } |
2e9a6788 VZ |
273 | |
274 | // the ref count - when it goes to 0, we die | |
275 | size_t m_nRef; | |
276 | ||
b99be8fb VZ |
277 | wxColour m_colText, |
278 | m_colBack; | |
279 | wxFont m_font; | |
280 | int m_hAlign, | |
281 | m_vAlign; | |
2e9a6788 | 282 | |
07296f0b RD |
283 | wxGridCellRenderer* m_renderer; |
284 | wxGridCellEditor* m_editor; | |
285 | wxGridCellAttr* m_defGridAttr; | |
ab79958a | 286 | |
2e9a6788 VZ |
287 | // suppress the stupid gcc warning about the class having private dtor and |
288 | // no friends | |
289 | friend class wxGridCellAttrDummyFriend; | |
b99be8fb VZ |
290 | }; |
291 | ||
292 | // ---------------------------------------------------------------------------- | |
293 | // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the | |
294 | // cell attributes. | |
295 | // ---------------------------------------------------------------------------- | |
296 | ||
297 | // implementation note: we separate it from wxGridTableBase because we wish to | |
298 | // avoid deriving a new table class if possible, and sometimes it will be | |
299 | // enough to just derive another wxGridCellAttrProvider instead | |
758cbedf VZ |
300 | // |
301 | // the default implementation is reasonably efficient for the generic case, | |
302 | // but you might still wish to implement your own for some specific situations | |
303 | // if you have performance problems with the stock one | |
b99be8fb VZ |
304 | class WXDLLEXPORT wxGridCellAttrProvider |
305 | { | |
306 | public: | |
307 | wxGridCellAttrProvider(); | |
308 | virtual ~wxGridCellAttrProvider(); | |
309 | ||
2e9a6788 | 310 | // DecRef() must be called on the returned pointer |
b99be8fb | 311 | virtual wxGridCellAttr *GetAttr(int row, int col) const; |
2e9a6788 | 312 | |
758cbedf VZ |
313 | // all these functions take ownership of the pointer, don't call DecRef() |
314 | // on it | |
2e9a6788 | 315 | virtual void SetAttr(wxGridCellAttr *attr, int row, int col); |
758cbedf VZ |
316 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); |
317 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
d1c0b4f9 VZ |
318 | |
319 | // these functions must be called whenever some rows/cols are deleted | |
320 | // because the internal data must be updated then | |
4d60017a SN |
321 | void UpdateAttrRows( size_t pos, int numRows ); |
322 | void UpdateAttrCols( size_t pos, int numCols ); | |
b99be8fb VZ |
323 | |
324 | private: | |
325 | void InitData(); | |
326 | ||
327 | wxGridCellAttrProviderData *m_data; | |
328 | }; | |
f85afd4e MB |
329 | |
330 | ////////////////////////////////////////////////////////////////////// | |
331 | // | |
332 | // Grid table classes | |
333 | // | |
334 | ////////////////////////////////////////////////////////////////////// | |
335 | ||
336 | ||
2d66e025 | 337 | class WXDLLEXPORT wxGridTableBase : public wxObject |
f85afd4e | 338 | { |
60ff3b99 | 339 | public: |
f85afd4e MB |
340 | wxGridTableBase(); |
341 | virtual ~wxGridTableBase(); | |
342 | ||
343 | // You must override these functions in a derived table class | |
344 | // | |
345 | virtual long GetNumberRows() = 0; | |
346 | virtual long GetNumberCols() = 0; | |
347 | virtual wxString GetValue( int row, int col ) = 0; | |
348 | virtual void SetValue( int row, int col, const wxString& s ) = 0; | |
349 | virtual bool IsEmptyCell( int row, int col ) = 0; | |
60ff3b99 | 350 | |
f85afd4e MB |
351 | // Overriding these is optional |
352 | // | |
353 | virtual void SetView( wxGrid *grid ) { m_view = grid; } | |
354 | virtual wxGrid * GetView() const { return m_view; } | |
355 | ||
356 | virtual void Clear() {} | |
357 | virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
358 | virtual bool AppendRows( size_t numRows = 1 ); | |
359 | virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
360 | virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
361 | virtual bool AppendCols( size_t numCols = 1 ); | |
362 | virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
363 | ||
364 | virtual wxString GetRowLabelValue( int row ); | |
365 | virtual wxString GetColLabelValue( int col ); | |
af111fc3 JS |
366 | virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {} |
367 | virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {} | |
60ff3b99 | 368 | |
b99be8fb VZ |
369 | // Attribute handling |
370 | // | |
371 | ||
372 | // give us the attr provider to use - we take ownership of the pointer | |
373 | void SetAttrProvider(wxGridCellAttrProvider *attrProvider); | |
374 | ||
375 | // get the currently used attr provider (may be NULL) | |
376 | wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; } | |
377 | ||
4d60017a SN |
378 | // change row/col number in attribute if needed |
379 | void UpdateAttrRows( size_t pos, int numRows ); | |
380 | void UpdateAttrCols( size_t pos, int numCols ); | |
381 | ||
b99be8fb VZ |
382 | // by default forwarded to wxGridCellAttrProvider if any. May be |
383 | // overridden to handle attributes directly in this class. | |
384 | virtual wxGridCellAttr *GetAttr( int row, int col ); | |
385 | ||
758cbedf VZ |
386 | // these functions take ownership of the pointer |
387 | virtual void SetAttr(wxGridCellAttr* attr, int row, int col); | |
388 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); | |
389 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
b99be8fb | 390 | |
60ff3b99 VZ |
391 | private: |
392 | wxGrid * m_view; | |
b99be8fb | 393 | wxGridCellAttrProvider *m_attrProvider; |
60ff3b99 | 394 | |
f85afd4e MB |
395 | DECLARE_ABSTRACT_CLASS( wxGridTableBase ); |
396 | }; | |
397 | ||
398 | ||
b99be8fb VZ |
399 | // ---------------------------------------------------------------------------- |
400 | // wxGridTableMessage | |
401 | // ---------------------------------------------------------------------------- | |
f85afd4e MB |
402 | |
403 | // IDs for messages sent from grid table to view | |
404 | // | |
60ff3b99 VZ |
405 | enum wxGridTableRequest |
406 | { | |
f85afd4e MB |
407 | wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000, |
408 | wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES, | |
409 | wxGRIDTABLE_NOTIFY_ROWS_INSERTED, | |
410 | wxGRIDTABLE_NOTIFY_ROWS_APPENDED, | |
411 | wxGRIDTABLE_NOTIFY_ROWS_DELETED, | |
412 | wxGRIDTABLE_NOTIFY_COLS_INSERTED, | |
413 | wxGRIDTABLE_NOTIFY_COLS_APPENDED, | |
414 | wxGRIDTABLE_NOTIFY_COLS_DELETED | |
415 | }; | |
416 | ||
2d66e025 | 417 | class WXDLLEXPORT wxGridTableMessage |
f85afd4e | 418 | { |
60ff3b99 | 419 | public: |
f85afd4e MB |
420 | wxGridTableMessage(); |
421 | wxGridTableMessage( wxGridTableBase *table, int id, | |
422 | int comInt1 = -1, | |
423 | int comInt2 = -1 ); | |
424 | ||
425 | void SetTableObject( wxGridTableBase *table ) { m_table = table; } | |
426 | wxGridTableBase * GetTableObject() const { return m_table; } | |
427 | void SetId( int id ) { m_id = id; } | |
428 | int GetId() { return m_id; } | |
429 | void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; } | |
430 | int GetCommandInt() { return m_comInt1; } | |
431 | void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; } | |
60ff3b99 VZ |
432 | int GetCommandInt2() { return m_comInt2; } |
433 | ||
434 | private: | |
435 | wxGridTableBase *m_table; | |
436 | int m_id; | |
437 | int m_comInt1; | |
438 | int m_comInt2; | |
f85afd4e MB |
439 | }; |
440 | ||
441 | ||
442 | ||
443 | // ------ wxGridStringArray | |
444 | // A 2-dimensional array of strings for data values | |
445 | // | |
446 | ||
2d66e025 MB |
447 | WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString, wxGridStringArray); |
448 | ||
f85afd4e MB |
449 | |
450 | ||
451 | // ------ wxGridStringTable | |
452 | // | |
453 | // Simplest type of data table for a grid for small tables of strings | |
454 | // that are stored in memory | |
455 | // | |
456 | ||
2d66e025 | 457 | class WXDLLEXPORT wxGridStringTable : public wxGridTableBase |
f85afd4e | 458 | { |
60ff3b99 | 459 | public: |
f85afd4e MB |
460 | wxGridStringTable(); |
461 | wxGridStringTable( int numRows, int numCols ); | |
462 | ~wxGridStringTable(); | |
463 | ||
464 | // these are pure virtual in wxGridTableBase | |
465 | // | |
466 | long GetNumberRows(); | |
467 | long GetNumberCols(); | |
468 | wxString GetValue( int row, int col ); | |
469 | void SetValue( int row, int col, const wxString& s ); | |
470 | bool IsEmptyCell( int row, int col ); | |
60ff3b99 | 471 | |
f85afd4e MB |
472 | // overridden functions from wxGridTableBase |
473 | // | |
474 | void Clear(); | |
475 | bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
476 | bool AppendRows( size_t numRows = 1 ); | |
477 | bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
478 | bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
479 | bool AppendCols( size_t numCols = 1 ); | |
480 | bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
481 | ||
482 | void SetRowLabelValue( int row, const wxString& ); | |
483 | void SetColLabelValue( int col, const wxString& ); | |
484 | wxString GetRowLabelValue( int row ); | |
485 | wxString GetColLabelValue( int col ); | |
60ff3b99 VZ |
486 | |
487 | private: | |
488 | wxGridStringArray m_data; | |
489 | ||
490 | // These only get used if you set your own labels, otherwise the | |
491 | // GetRow/ColLabelValue functions return wxGridTableBase defaults | |
492 | // | |
493 | wxArrayString m_rowLabels; | |
494 | wxArrayString m_colLabels; | |
495 | ||
f85afd4e MB |
496 | DECLARE_DYNAMIC_CLASS( wxGridStringTable ) |
497 | }; | |
498 | ||
499 | ||
500 | ||
f85afd4e MB |
501 | ////////////////////////////////////////////////////////////////////// |
502 | // | |
503 | // Grid view classes | |
504 | // | |
505 | ////////////////////////////////////////////////////////////////////// | |
506 | ||
2d66e025 | 507 | class WXDLLEXPORT wxGridCellCoords |
f85afd4e | 508 | { |
60ff3b99 | 509 | public: |
f85afd4e MB |
510 | wxGridCellCoords() { m_row = m_col = -1; } |
511 | wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; } | |
512 | ||
513 | // default copy ctor is ok | |
514 | ||
515 | long GetRow() const { return m_row; } | |
516 | void SetRow( long n ) { m_row = n; } | |
517 | long GetCol() const { return m_col; } | |
518 | void SetCol( long n ) { m_col = n; } | |
519 | void Set( long row, long col ) { m_row = row; m_col = col; } | |
60ff3b99 | 520 | |
f85afd4e MB |
521 | wxGridCellCoords& operator=( const wxGridCellCoords& other ) |
522 | { | |
523 | if ( &other != this ) | |
524 | { | |
525 | m_row=other.m_row; | |
526 | m_col=other.m_col; | |
527 | } | |
528 | return *this; | |
529 | } | |
530 | ||
531 | bool operator==( const wxGridCellCoords& other ) | |
532 | { | |
533 | return (m_row == other.m_row && m_col == other.m_col); | |
534 | } | |
535 | ||
536 | bool operator!=( const wxGridCellCoords& other ) | |
537 | { | |
538 | return (m_row != other.m_row || m_col != other.m_col); | |
539 | } | |
540 | ||
541 | bool operator!() | |
542 | { | |
543 | return (m_row == -1 && m_col == -1 ); | |
544 | } | |
60ff3b99 VZ |
545 | |
546 | private: | |
547 | long m_row; | |
548 | long m_col; | |
f85afd4e MB |
549 | }; |
550 | ||
551 | ||
552 | // For comparisons... | |
553 | // | |
554 | extern wxGridCellCoords wxGridNoCellCoords; | |
555 | extern wxRect wxGridNoCellRect; | |
556 | ||
2d66e025 MB |
557 | // An array of cell coords... |
558 | // | |
559 | WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray); | |
560 | ||
561 | ||
f85afd4e | 562 | |
b99be8fb VZ |
563 | // ---------------------------------------------------------------------------- |
564 | // wxGrid | |
565 | // ---------------------------------------------------------------------------- | |
f85afd4e | 566 | |
60ff3b99 VZ |
567 | class WXDLLEXPORT wxGrid : public wxScrolledWindow |
568 | { | |
569 | public: | |
f85afd4e | 570 | wxGrid() |
b99be8fb | 571 | { |
2c9a89e0 | 572 | Create(); |
58dd5b3b | 573 | } |
60ff3b99 | 574 | |
f85afd4e MB |
575 | wxGrid( wxWindow *parent, |
576 | wxWindowID id, | |
577 | const wxPoint& pos = wxDefaultPosition, | |
578 | const wxSize& size = wxDefaultSize, | |
579 | long style = 0, | |
2d66e025 MB |
580 | const wxString& name = wxPanelNameStr ); |
581 | ||
60ff3b99 | 582 | ~wxGrid(); |
f85afd4e | 583 | |
2d66e025 MB |
584 | bool CreateGrid( int numRows, int numCols ); |
585 | ||
60ff3b99 | 586 | |
2d66e025 MB |
587 | // ------ grid dimensions |
588 | // | |
589 | int GetNumberRows() { return m_numRows; } | |
590 | int GetNumberCols() { return m_numCols; } | |
591 | ||
60ff3b99 | 592 | |
2d66e025 MB |
593 | // ------ display update functions |
594 | // | |
60ff3b99 | 595 | void CalcRowLabelsExposed( wxRegion& reg ); |
8fb66724 | 596 | |
60ff3b99 VZ |
597 | void CalcColLabelsExposed( wxRegion& reg ); |
598 | void CalcCellsExposed( wxRegion& reg ); | |
599 | ||
2d66e025 | 600 | |
2d66e025 MB |
601 | // ------ event handlers |
602 | // | |
603 | void ProcessRowLabelMouseEvent( wxMouseEvent& event ); | |
604 | void ProcessColLabelMouseEvent( wxMouseEvent& event ); | |
605 | void ProcessCornerLabelMouseEvent( wxMouseEvent& event ); | |
60ff3b99 | 606 | void ProcessGridCellMouseEvent( wxMouseEvent& event ); |
2d66e025 | 607 | bool ProcessTableMessage( wxGridTableMessage& ); |
f85afd4e | 608 | |
6d004f67 MB |
609 | void DoEndDragResizeRow(); |
610 | void DoEndDragResizeCol(); | |
60ff3b99 | 611 | |
f85afd4e | 612 | wxGridTableBase * GetTable() const { return m_table; } |
2796cce3 | 613 | bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE ); |
f85afd4e MB |
614 | |
615 | void ClearGrid(); | |
616 | bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE ); | |
617 | bool AppendRows( int numRows = 1, bool updateLabels=TRUE ); | |
618 | bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE ); | |
619 | bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE ); | |
620 | bool AppendCols( int numCols = 1, bool updateLabels=TRUE ); | |
60ff3b99 | 621 | bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE ); |
f85afd4e | 622 | |
2d66e025 MB |
623 | void DrawGridCellArea( wxDC& dc ); |
624 | void DrawCellBorder( wxDC& dc, const wxGridCellCoords& ); | |
4634a5d6 | 625 | void DrawAllGridLines( wxDC& dc, const wxRegion & reg ); |
2d66e025 | 626 | void DrawCell( wxDC& dc, const wxGridCellCoords& ); |
07296f0b | 627 | void DrawCellHighlight( wxDC& dc ); |
1f1ce288 | 628 | |
2d66e025 MB |
629 | void DrawRowLabels( wxDC& dc ); |
630 | void DrawRowLabel( wxDC& dc, int row ); | |
8fb66724 | 631 | |
2d66e025 MB |
632 | void DrawColLabels( wxDC& dc ); |
633 | void DrawColLabel( wxDC& dc, int col ); | |
60ff3b99 | 634 | |
f85afd4e | 635 | |
2d66e025 | 636 | // ------ Cell text drawing functions |
f85afd4e | 637 | // |
2d66e025 MB |
638 | void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&, |
639 | int horizontalAlignment = wxLEFT, | |
640 | int verticalAlignment = wxTOP ); | |
f85afd4e | 641 | |
2d66e025 MB |
642 | // Split a string containing newline chararcters into an array of |
643 | // strings and return the number of lines | |
644 | // | |
645 | void StringToLines( const wxString& value, wxArrayString& lines ); | |
60ff3b99 | 646 | |
2d66e025 MB |
647 | void GetTextBoxSize( wxDC& dc, |
648 | wxArrayString& lines, | |
649 | long *width, long *height ); | |
60ff3b99 | 650 | |
2d66e025 | 651 | |
f85afd4e MB |
652 | // ------ |
653 | // Code that does a lot of grid modification can be enclosed | |
654 | // between BeginBatch() and EndBatch() calls to avoid screen | |
655 | // flicker | |
656 | // | |
657 | void BeginBatch() { m_batchCount++; } | |
658 | void EndBatch() { if ( m_batchCount > 0 ) m_batchCount--; } | |
659 | int GetBatchCount() { return m_batchCount; } | |
660 | ||
2d66e025 MB |
661 | |
662 | // ------ edit control functions | |
663 | // | |
664 | bool IsEditable() { return m_editable; } | |
665 | void EnableEditing( bool edit ); | |
666 | ||
667 | void EnableCellEditControl( bool enable ); | |
668 | ||
669 | bool IsCellEditControlEnabled() | |
2c9a89e0 | 670 | { return m_cellEditCtrlEnabled; } |
2d66e025 | 671 | |
2d66e025 MB |
672 | void ShowCellEditControl(); |
673 | void HideCellEditControl(); | |
674 | void SetEditControlValue( const wxString& s = wxEmptyString ); | |
675 | void SaveEditControlValue(); | |
676 | ||
60ff3b99 | 677 | |
2d66e025 | 678 | // ------ grid location functions |
60ff3b99 | 679 | // Note that all of these functions work with the logical coordinates of |
2d66e025 MB |
680 | // grid cells and labels so you will need to convert from device |
681 | // coordinates for mouse events etc. | |
682 | // | |
683 | void XYToCell( int x, int y, wxGridCellCoords& ); | |
684 | int YToRow( int y ); | |
685 | int XToCol( int x ); | |
686 | ||
687 | int YToEdgeOfRow( int y ); | |
688 | int XToEdgeOfCol( int x ); | |
689 | ||
690 | wxRect CellToRect( int row, int col ); | |
691 | wxRect CellToRect( const wxGridCellCoords& coords ) | |
692 | { return CellToRect( coords.GetRow(), coords.GetCol() ); } | |
693 | ||
694 | int GetGridCursorRow() { return m_currentCellCoords.GetRow(); } | |
695 | int GetGridCursorCol() { return m_currentCellCoords.GetCol(); } | |
60ff3b99 | 696 | |
2d66e025 MB |
697 | // check to see if a cell is either wholly visible (the default arg) or |
698 | // at least partially visible in the grid window | |
699 | // | |
700 | bool IsVisible( int row, int col, bool wholeCellVisible = TRUE ); | |
701 | bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE ) | |
702 | { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); } | |
703 | void MakeCellVisible( int row, int col ); | |
704 | void MakeCellVisible( const wxGridCellCoords& coords ) | |
705 | { MakeCellVisible( coords.GetRow(), coords.GetCol() ); } | |
706 | ||
60ff3b99 | 707 | |
2d66e025 MB |
708 | // ------ grid cursor movement functions |
709 | // | |
dfaf42d2 | 710 | void SetGridCursor( int row, int col ) |
b27f2615 | 711 | { SetCurrentCell( wxGridCellCoords(row, col) ); } |
dfaf42d2 | 712 | |
2d66e025 MB |
713 | bool MoveCursorUp(); |
714 | bool MoveCursorDown(); | |
715 | bool MoveCursorLeft(); | |
716 | bool MoveCursorRight(); | |
717 | bool MovePageDown(); | |
718 | bool MovePageUp(); | |
719 | bool MoveCursorUpBlock(); | |
720 | bool MoveCursorDownBlock(); | |
721 | bool MoveCursorLeftBlock(); | |
722 | bool MoveCursorRightBlock(); | |
723 | ||
60ff3b99 | 724 | |
f85afd4e MB |
725 | // ------ label and gridline formatting |
726 | // | |
727 | int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; } | |
728 | int GetRowLabelSize() { return m_rowLabelWidth; } | |
60ff3b99 | 729 | int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; } |
f85afd4e MB |
730 | int GetColLabelSize() { return m_colLabelHeight; } |
731 | wxColour GetLabelBackgroundColour() { return m_labelBackgroundColour; } | |
732 | wxColour GetLabelTextColour() { return m_labelTextColour; } | |
733 | wxFont GetLabelFont() { return m_labelFont; } | |
734 | void GetRowLabelAlignment( int *horiz, int *vert ); | |
735 | void GetColLabelAlignment( int *horiz, int *vert ); | |
736 | wxString GetRowLabelValue( int row ); | |
737 | wxString GetColLabelValue( int col ); | |
738 | wxColour GetGridLineColour() { return m_gridLineColour; } | |
739 | ||
ab79958a | 740 | void SetRowLabelSize( int width ); |
f85afd4e MB |
741 | void SetColLabelSize( int height ); |
742 | void SetLabelBackgroundColour( const wxColour& ); | |
743 | void SetLabelTextColour( const wxColour& ); | |
744 | void SetLabelFont( const wxFont& ); | |
745 | void SetRowLabelAlignment( int horiz, int vert ); | |
746 | void SetColLabelAlignment( int horiz, int vert ); | |
747 | void SetRowLabelValue( int row, const wxString& ); | |
748 | void SetColLabelValue( int col, const wxString& ); | |
749 | void SetGridLineColour( const wxColour& ); | |
750 | ||
758cbedf VZ |
751 | // this sets the specified attribute for all cells in this row/col |
752 | void SetRowAttr(int row, wxGridCellAttr *attr); | |
753 | void SetColAttr(int col, wxGridCellAttr *attr); | |
754 | ||
f85afd4e MB |
755 | void EnableGridLines( bool enable = TRUE ); |
756 | bool GridLinesEnabled() { return m_gridLinesEnabled; } | |
757 | ||
f85afd4e MB |
758 | // ------ row and col formatting |
759 | // | |
760 | int GetDefaultRowSize(); | |
761 | int GetRowSize( int row ); | |
762 | int GetDefaultColSize(); | |
763 | int GetColSize( int col ); | |
764 | wxColour GetDefaultCellBackgroundColour(); | |
765 | wxColour GetCellBackgroundColour( int row, int col ); | |
766 | wxColour GetDefaultCellTextColour(); | |
767 | wxColour GetCellTextColour( int row, int col ); | |
f85afd4e MB |
768 | wxFont GetDefaultCellFont(); |
769 | wxFont GetCellFont( int row, int col ); | |
770 | void GetDefaultCellAlignment( int *horiz, int *vert ); | |
771 | void GetCellAlignment( int row, int col, int *horiz, int *vert ); | |
60ff3b99 | 772 | |
f85afd4e MB |
773 | void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE ); |
774 | void SetRowSize( int row, int height ); | |
775 | void SetDefaultColSize( int width, bool resizeExistingCols = FALSE ); | |
8fb66724 | 776 | |
f85afd4e MB |
777 | void SetColSize( int col, int width ); |
778 | void SetDefaultCellBackgroundColour( const wxColour& ); | |
779 | void SetCellBackgroundColour( int row, int col, const wxColour& ); | |
780 | void SetDefaultCellTextColour( const wxColour& ); | |
8fb66724 | 781 | |
f85afd4e | 782 | void SetCellTextColour( int row, int col, const wxColour& ); |
f85afd4e MB |
783 | void SetDefaultCellFont( const wxFont& ); |
784 | void SetCellFont( int row, int col, const wxFont& ); | |
785 | void SetDefaultCellAlignment( int horiz, int vert ); | |
786 | void SetCellAlignment( int row, int col, int horiz, int vert ); | |
787 | ||
ab79958a | 788 | // takes ownership of the pointer |
2796cce3 | 789 | void SetDefaultRenderer(wxGridCellRenderer *renderer); |
ab79958a | 790 | void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer); |
2796cce3 RD |
791 | wxGridCellRenderer *GetDefaultRenderer() const; |
792 | wxGridCellRenderer* GetCellRenderer(int row, int col); | |
793 | ||
9b4aede2 RD |
794 | // takes ownership of the pointer |
795 | void SetDefaultEditor(wxGridCellEditor *editor); | |
796 | void SetCellEditor(int row, int col, wxGridCellEditor *editor); | |
797 | wxGridCellEditor *GetDefaultEditor() const; | |
798 | wxGridCellEditor* GetCellEditor(int row, int col); | |
799 | ||
60a67569 | 800 | |
f85afd4e MB |
801 | // ------ cell value accessors |
802 | // | |
803 | wxString GetCellValue( int row, int col ) | |
804 | { | |
805 | if ( m_table ) | |
806 | { | |
807 | return m_table->GetValue( row, col ); | |
808 | } | |
809 | else | |
810 | { | |
811 | return wxEmptyString; | |
812 | } | |
813 | } | |
814 | ||
815 | wxString GetCellValue( const wxGridCellCoords& coords ) | |
816 | { return GetCellValue( coords.GetRow(), coords.GetCol() ); } | |
60ff3b99 | 817 | |
f85afd4e MB |
818 | void SetCellValue( int row, int col, const wxString& s ); |
819 | void SetCellValue( const wxGridCellCoords& coords, const wxString& s ) | |
820 | { SetCellValue( coords.GetRow(), coords.GetCol(), s ); } | |
f85afd4e | 821 | |
60ff3b99 | 822 | |
f85afd4e MB |
823 | |
824 | // ------ selections of blocks of cells | |
825 | // | |
826 | void SelectRow( int row, bool addToSelected = FALSE ); | |
827 | void SelectCol( int col, bool addToSelected = FALSE ); | |
60ff3b99 | 828 | |
f85afd4e MB |
829 | void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol ); |
830 | ||
831 | void SelectBlock( const wxGridCellCoords& topLeft, | |
832 | const wxGridCellCoords& bottomRight ) | |
833 | { SelectBlock( topLeft.GetRow(), topLeft.GetCol(), | |
834 | bottomRight.GetRow(), bottomRight.GetCol() ); } | |
835 | ||
836 | void SelectAll(); | |
60ff3b99 | 837 | |
f85afd4e MB |
838 | bool IsSelection() |
839 | { return ( m_selectedTopLeft != wxGridNoCellCoords && | |
840 | m_selectedBottomRight != wxGridNoCellCoords ); | |
841 | } | |
842 | ||
843 | void ClearSelection(); | |
844 | ||
845 | bool IsInSelection( int row, int col ) | |
846 | { return ( IsSelection() && | |
847 | row >= m_selectedTopLeft.GetRow() && | |
848 | col >= m_selectedTopLeft.GetCol() && | |
849 | row <= m_selectedBottomRight.GetRow() && | |
850 | col <= m_selectedBottomRight.GetCol() ); | |
851 | } | |
852 | ||
853 | bool IsInSelection( const wxGridCellCoords& coords ) | |
854 | { return IsInSelection( coords.GetRow(), coords.GetCol() ); } | |
855 | ||
856 | void GetSelection( int* topRow, int* leftCol, int* bottomRow, int* rightCol ) | |
857 | { | |
858 | // these will all be -1 if there is no selected block | |
859 | // | |
860 | *topRow = m_selectedTopLeft.GetRow(); | |
861 | *leftCol = m_selectedTopLeft.GetCol(); | |
862 | *bottomRow = m_selectedBottomRight.GetRow(); | |
863 | *rightCol = m_selectedBottomRight.GetCol(); | |
864 | } | |
865 | ||
c3baf426 SN |
866 | |
867 | // This function returns the rectangle that encloses the block of cells | |
868 | // limited by TopLeft and BottomRight cell in device coords and clipped | |
869 | // to the client size of the grid window. | |
870 | // | |
58dd5b3b | 871 | wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft, |
b99be8fb | 872 | const wxGridCellCoords & bottomRight ); |
c3baf426 | 873 | |
2d66e025 MB |
874 | // This function returns the rectangle that encloses the selected cells |
875 | // in device coords and clipped to the client size of the grid window. | |
f85afd4e | 876 | // |
c3baf426 SN |
877 | wxRect SelectionToDeviceRect() |
878 | { | |
b99be8fb VZ |
879 | return BlockToDeviceRect( m_selectedTopLeft, |
880 | m_selectedBottomRight ); | |
881 | } | |
60ff3b99 | 882 | |
2796cce3 RD |
883 | // Access or update the selection fore/back colours |
884 | wxColour GetSelectionBackground() const | |
885 | { return m_selectionBackground; } | |
886 | wxColour GetSelectionForeground() const | |
887 | { return m_selectionForeground; } | |
888 | ||
889 | void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; } | |
890 | void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; } | |
891 | ||
892 | ||
f85afd4e MB |
893 | |
894 | // ------ For compatibility with previous wxGrid only... | |
895 | // | |
896 | // ************************************************ | |
897 | // ** Don't use these in new code because they ** | |
898 | // ** are liable to disappear in a future ** | |
899 | // ** revision ** | |
900 | // ************************************************ | |
901 | // | |
902 | ||
903 | wxGrid( wxWindow *parent, | |
904 | int x = -1, int y = -1, int w = -1, int h = -1, | |
905 | long style = 0, | |
906 | const wxString& name = wxPanelNameStr ) | |
2d66e025 | 907 | : wxScrolledWindow( parent, -1, wxPoint(x,y), wxSize(w,h), style, name ) |
60ff3b99 | 908 | { |
f85afd4e | 909 | Create(); |
60ff3b99 | 910 | } |
f85afd4e MB |
911 | |
912 | void SetCellValue( const wxString& val, int row, int col ) | |
913 | { SetCellValue( row, col, val ); } | |
60ff3b99 | 914 | |
f85afd4e MB |
915 | void UpdateDimensions() |
916 | { CalcDimensions(); } | |
917 | ||
918 | int GetRows() { return GetNumberRows(); } | |
919 | int GetCols() { return GetNumberCols(); } | |
920 | int GetCursorRow() { return GetGridCursorRow(); } | |
921 | int GetCursorColumn() { return GetGridCursorCol(); } | |
60ff3b99 | 922 | |
2d66e025 MB |
923 | int GetScrollPosX() { return 0; } |
924 | int GetScrollPosY() { return 0; } | |
60ff3b99 | 925 | |
2d66e025 MB |
926 | void SetScrollX( int x ) { } |
927 | void SetScrollY( int y ) { } | |
f85afd4e MB |
928 | |
929 | void SetColumnWidth( int col, int width ) | |
930 | { SetColSize( col, width ); } | |
60ff3b99 | 931 | |
f85afd4e MB |
932 | int GetColumnWidth( int col ) |
933 | { return GetColSize( col ); } | |
60ff3b99 | 934 | |
f85afd4e MB |
935 | void SetRowHeight( int row, int height ) |
936 | { SetRowSize( row, height ); } | |
60ff3b99 | 937 | |
f85afd4e MB |
938 | int GetRowHeight( int row ) |
939 | { return GetRowSize( row ); } | |
60ff3b99 | 940 | |
2d66e025 MB |
941 | int GetViewHeight() // returned num whole rows visible |
942 | { return 0; } | |
60ff3b99 | 943 | |
2d66e025 MB |
944 | int GetViewWidth() // returned num whole cols visible |
945 | { return 0; } | |
f85afd4e MB |
946 | |
947 | void SetLabelSize( int orientation, int sz ) | |
948 | { | |
949 | if ( orientation == wxHORIZONTAL ) | |
950 | SetColLabelSize( sz ); | |
951 | else | |
952 | SetRowLabelSize( sz ); | |
953 | } | |
954 | ||
955 | int GetLabelSize( int orientation ) | |
956 | { | |
957 | if ( orientation == wxHORIZONTAL ) | |
958 | return GetColLabelSize(); | |
959 | else | |
960 | return GetRowLabelSize(); | |
961 | } | |
962 | ||
963 | void SetLabelAlignment( int orientation, int align ) | |
964 | { | |
965 | if ( orientation == wxHORIZONTAL ) | |
966 | SetColLabelAlignment( align, -1 ); | |
967 | else | |
968 | SetRowLabelAlignment( align, -1 ); | |
969 | } | |
970 | ||
af111fc3 | 971 | int GetLabelAlignment( int orientation, int WXUNUSED(align) ) |
f85afd4e MB |
972 | { |
973 | int h, v; | |
974 | if ( orientation == wxHORIZONTAL ) | |
975 | { | |
976 | GetColLabelAlignment( &h, &v ); | |
977 | return h; | |
978 | } | |
979 | else | |
980 | { | |
981 | GetRowLabelAlignment( &h, &v ); | |
982 | return h; | |
983 | } | |
984 | } | |
985 | ||
986 | void SetLabelValue( int orientation, const wxString& val, int pos ) | |
987 | { | |
988 | if ( orientation == wxHORIZONTAL ) | |
989 | SetColLabelValue( pos, val ); | |
990 | else | |
991 | SetRowLabelValue( pos, val ); | |
992 | } | |
60ff3b99 | 993 | |
f85afd4e MB |
994 | wxString GetLabelValue( int orientation, int pos) |
995 | { | |
996 | if ( orientation == wxHORIZONTAL ) | |
997 | return GetColLabelValue( pos ); | |
998 | else | |
999 | return GetRowLabelValue( pos ); | |
1000 | } | |
1001 | ||
60ff3b99 | 1002 | wxFont GetCellTextFont() const |
2796cce3 | 1003 | { return m_defaultCellAttr->GetFont(); } |
60ff3b99 | 1004 | |
af111fc3 | 1005 | wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const |
2796cce3 | 1006 | { return m_defaultCellAttr->GetFont(); } |
60ff3b99 | 1007 | |
f85afd4e MB |
1008 | void SetCellTextFont(const wxFont& fnt) |
1009 | { SetDefaultCellFont( fnt ); } | |
60ff3b99 | 1010 | |
f85afd4e MB |
1011 | void SetCellTextFont(const wxFont& fnt, int row, int col) |
1012 | { SetCellFont( row, col, fnt ); } | |
60ff3b99 | 1013 | |
f85afd4e MB |
1014 | void SetCellTextColour(const wxColour& val, int row, int col) |
1015 | { SetCellTextColour( row, col, val ); } | |
60ff3b99 | 1016 | |
f85afd4e MB |
1017 | void SetCellTextColour(const wxColour& col) |
1018 | { SetDefaultCellTextColour( col ); } | |
60ff3b99 | 1019 | |
f85afd4e MB |
1020 | void SetCellBackgroundColour(const wxColour& col) |
1021 | { SetDefaultCellBackgroundColour( col ); } | |
60ff3b99 | 1022 | |
f85afd4e MB |
1023 | void SetCellBackgroundColour(const wxColour& colour, int row, int col) |
1024 | { SetCellBackgroundColour( row, col, colour ); } | |
60ff3b99 | 1025 | |
f85afd4e MB |
1026 | bool GetEditable() { return IsEditable(); } |
1027 | void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); } | |
1028 | bool GetEditInPlace() { return IsCellEditControlEnabled(); } | |
8fb66724 | 1029 | |
1f1ce288 | 1030 | void SetEditInPlace(bool edit = TRUE) { } |
f85afd4e | 1031 | |
60a67569 JS |
1032 | void SetCellAlignment( int align, int row, int col) |
1033 | { SetCellAlignment(row, col, align, wxCENTER); } | |
1034 | void SetCellAlignment( int WXUNUSED(align) ) {} | |
1035 | void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col)) | |
1036 | { } | |
1037 | void SetDividerPen(const wxPen& WXUNUSED(pen)) { } | |
1038 | wxPen& GetDividerPen() const { return wxNullPen; } | |
1039 | void OnActivate(bool WXUNUSED(active)) {} | |
60ff3b99 | 1040 | |
f85afd4e MB |
1041 | // ******** End of compatibility functions ********** |
1042 | ||
2d66e025 MB |
1043 | |
1044 | ||
f85afd4e | 1045 | // ------ control IDs |
2d66e025 | 1046 | enum { wxGRID_CELLCTRL = 2000, |
f85afd4e MB |
1047 | wxGRID_TOPCTRL }; |
1048 | ||
1049 | // ------ control types | |
2d66e025 | 1050 | enum { wxGRID_TEXTCTRL = 2100, |
f85afd4e MB |
1051 | wxGRID_CHECKBOX, |
1052 | wxGRID_CHOICE, | |
1053 | wxGRID_COMBOBOX }; | |
1054 | ||
60ff3b99 VZ |
1055 | protected: |
1056 | bool m_created; | |
4634a5d6 | 1057 | bool m_displayed; |
60ff3b99 VZ |
1058 | |
1059 | wxGridWindow *m_gridWin; | |
1060 | wxGridRowLabelWindow *m_rowLabelWin; | |
1061 | wxGridColLabelWindow *m_colLabelWin; | |
1062 | wxGridCornerLabelWindow *m_cornerLabelWin; | |
1063 | ||
60ff3b99 | 1064 | wxGridTableBase *m_table; |
2796cce3 | 1065 | bool m_ownTable; |
60ff3b99 VZ |
1066 | |
1067 | int m_left; | |
1068 | int m_top; | |
1069 | int m_right; | |
1070 | int m_bottom; | |
1071 | ||
1072 | int m_numRows; | |
1073 | int m_numCols; | |
1074 | ||
1075 | wxGridCellCoords m_currentCellCoords; | |
1076 | ||
1077 | wxGridCellCoords m_selectedTopLeft; | |
1078 | wxGridCellCoords m_selectedBottomRight; | |
2796cce3 RD |
1079 | wxColour m_selectionBackground; |
1080 | wxColour m_selectionForeground; | |
60ff3b99 VZ |
1081 | |
1082 | int m_defaultRowHeight; | |
1083 | wxArrayInt m_rowHeights; | |
1084 | wxArrayInt m_rowBottoms; | |
1085 | ||
1086 | int m_defaultColWidth; | |
1087 | wxArrayInt m_colWidths; | |
1088 | wxArrayInt m_colRights; | |
60ff3b99 VZ |
1089 | int m_rowLabelWidth; |
1090 | int m_colLabelHeight; | |
1091 | ||
1092 | wxColour m_labelBackgroundColour; | |
1093 | wxColour m_labelTextColour; | |
1094 | wxFont m_labelFont; | |
1095 | ||
1096 | int m_rowLabelHorizAlign; | |
1097 | int m_rowLabelVertAlign; | |
1098 | int m_colLabelHorizAlign; | |
1099 | int m_colLabelVertAlign; | |
1100 | ||
1101 | bool m_defaultRowLabelValues; | |
1102 | bool m_defaultColLabelValues; | |
1103 | ||
1104 | wxColour m_gridLineColour; | |
1105 | bool m_gridLinesEnabled; | |
1106 | ||
b99be8fb VZ |
1107 | |
1108 | // do we have some place to store attributes in? | |
1109 | bool CanHaveAttributes(); | |
60ff3b99 | 1110 | |
2e9a6788 VZ |
1111 | // returns the attribute we may modify in place: a new one if this cell |
1112 | // doesn't have any yet or the existing one if it does | |
1113 | // | |
1114 | // DecRef() must be called on the returned pointer, as usual | |
0a976765 VZ |
1115 | wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const; |
1116 | ||
1117 | // cell attribute cache (currently we only cache 1, may be will do | |
1118 | // more/better later) | |
1119 | struct CachedAttr | |
1120 | { | |
1121 | int row, col; | |
1122 | wxGridCellAttr *attr; | |
1123 | } m_attrCache; | |
1124 | ||
1125 | // invalidates the attribute cache | |
1126 | void ClearAttrCache(); | |
1127 | ||
1128 | // adds an attribute to cache | |
1129 | void CacheAttr(int row, int col, wxGridCellAttr *attr) const; | |
1130 | ||
1131 | // looks for an attr in cache, returns TRUE if found | |
1132 | bool LookupAttr(int row, int col, wxGridCellAttr **attr) const; | |
1133 | ||
1134 | // looks for the attr in cache, if not found asks the table and caches the | |
1135 | // result | |
2e9a6788 | 1136 | wxGridCellAttr *GetCellAttr(int row, int col) const; |
2c9a89e0 RD |
1137 | wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords ) |
1138 | { return GetCellAttr( coords.GetRow(), coords.GetCol() ); } | |
2e9a6788 | 1139 | |
2796cce3 RD |
1140 | // the default cell attr object for cells that don't have their own |
1141 | wxGridCellAttr* m_defaultCellAttr; | |
1142 | ||
1143 | ||
60ff3b99 VZ |
1144 | wxGridCellCoordsArray m_cellsExposed; |
1145 | wxArrayInt m_rowsExposed; | |
1146 | wxArrayInt m_colsExposed; | |
1147 | wxArrayInt m_rowLabelsExposed; | |
1148 | wxArrayInt m_colLabelsExposed; | |
1149 | ||
1150 | bool m_inOnKeyDown; | |
1151 | int m_batchCount; | |
1152 | ||
e2b42eeb VZ |
1153 | enum CursorMode |
1154 | { | |
1155 | WXGRID_CURSOR_SELECT_CELL, | |
1156 | WXGRID_CURSOR_RESIZE_ROW, | |
1157 | WXGRID_CURSOR_RESIZE_COL, | |
1158 | WXGRID_CURSOR_SELECT_ROW, | |
1159 | WXGRID_CURSOR_SELECT_COL | |
60ff3b99 VZ |
1160 | }; |
1161 | ||
e2b42eeb VZ |
1162 | // this method not only sets m_cursorMode but also sets the correct cursor |
1163 | // for the given mode and, if captureMouse is not FALSE releases the mouse | |
1164 | // if it was captured and captures it if it must be captured | |
1165 | // | |
1166 | // for this to work, you should always use it and not set m_cursorMode | |
1167 | // directly! | |
1168 | void ChangeCursorMode(CursorMode mode, | |
1169 | wxWindow *win = (wxWindow *)NULL, | |
1170 | bool captureMouse = TRUE); | |
1171 | ||
1172 | wxWindow *m_winCapture; // the window which captured the mouse | |
1173 | CursorMode m_cursorMode; | |
1174 | ||
07296f0b RD |
1175 | int m_dragLastPos; |
1176 | int m_dragRowOrCol; | |
1177 | bool m_isDragging; | |
1178 | wxPoint m_startDragPos; | |
60ff3b99 | 1179 | |
75ecbe45 | 1180 | bool m_waitForSlowClick; |
025562fe | 1181 | |
60ff3b99 VZ |
1182 | wxGridCellCoords m_selectionStart; |
1183 | ||
1184 | wxCursor m_rowResizeCursor; | |
1185 | wxCursor m_colResizeCursor; | |
1186 | ||
1187 | bool m_editable; // applies to whole grid | |
60ff3b99 VZ |
1188 | bool m_cellEditCtrlEnabled; |
1189 | ||
1190 | ||
1191 | void Create(); | |
1192 | void Init(); | |
1193 | void CalcDimensions(); | |
7807d81c | 1194 | void CalcWindowSizes(); |
60ff3b99 VZ |
1195 | bool Redimension( wxGridTableMessage& ); |
1196 | ||
1197 | ||
1198 | bool SendEvent( const wxEventType, | |
1199 | int row, int col, | |
1200 | wxMouseEvent& ); | |
1201 | ||
1202 | bool SendEvent( const wxEventType, | |
1203 | int row, int col ); | |
1204 | ||
1205 | ||
1206 | void OnPaint( wxPaintEvent& ); | |
1207 | void OnSize( wxSizeEvent& ); | |
1208 | void OnKeyDown( wxKeyEvent& ); | |
2796cce3 | 1209 | void OnEraseBackground( wxEraseEvent& ); |
60ff3b99 VZ |
1210 | |
1211 | ||
1212 | void SetCurrentCell( const wxGridCellCoords& coords ); | |
1213 | void SetCurrentCell( int row, int col ) | |
1214 | { SetCurrentCell( wxGridCellCoords(row, col) ); } | |
1215 | ||
1216 | ||
1217 | // ------ functions to get/send data (see also public functions) | |
1218 | // | |
1219 | bool GetModelValues(); | |
1220 | bool SetModelValues(); | |
1221 | ||
1222 | ||
2d66e025 | 1223 | DECLARE_DYNAMIC_CLASS( wxGrid ) |
f85afd4e MB |
1224 | DECLARE_EVENT_TABLE() |
1225 | }; | |
1226 | ||
1227 | ||
1228 | ||
1229 | ||
1230 | ||
1231 | // | |
1232 | // ------ Grid event class and event types | |
1233 | // | |
1234 | ||
1235 | class WXDLLEXPORT wxGridEvent : public wxNotifyEvent | |
1236 | { | |
60ff3b99 | 1237 | public: |
f85afd4e MB |
1238 | wxGridEvent() |
1239 | : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1), | |
1240 | m_control(0), m_meta(0), m_shift(0), m_alt(0) | |
1241 | { | |
1242 | } | |
1243 | ||
1244 | wxGridEvent(int id, wxEventType type, wxObject* obj, | |
1245 | int row=-1, int col=-1, int x=-1, int y=-1, | |
1246 | bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE); | |
1247 | ||
1248 | virtual int GetRow() { return m_row; } | |
1249 | virtual int GetCol() { return m_col; } | |
1250 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } | |
1251 | bool ControlDown() { return m_control; } | |
1252 | bool MetaDown() { return m_meta; } | |
1253 | bool ShiftDown() { return m_shift; } | |
1254 | bool AltDown() { return m_alt; } | |
2d66e025 | 1255 | |
60ff3b99 VZ |
1256 | protected: |
1257 | int m_row; | |
1258 | int m_col; | |
f85afd4e MB |
1259 | int m_x; |
1260 | int m_y; | |
1261 | bool m_control; | |
1262 | bool m_meta; | |
1263 | bool m_shift; | |
1264 | bool m_alt; | |
60ff3b99 VZ |
1265 | |
1266 | DECLARE_DYNAMIC_CLASS(wxGridEvent) | |
1267 | }; | |
1268 | ||
1269 | ||
1270 | class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent | |
1271 | { | |
1272 | public: | |
f85afd4e MB |
1273 | wxGridSizeEvent() |
1274 | : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1), | |
1275 | m_control(0), m_meta(0), m_shift(0), m_alt(0) | |
1276 | { | |
1277 | } | |
1278 | ||
1279 | wxGridSizeEvent(int id, wxEventType type, wxObject* obj, | |
1280 | int rowOrCol=-1, int x=-1, int y=-1, | |
1281 | bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE); | |
1282 | ||
1283 | int GetRowOrCol() { return m_rowOrCol; } | |
1284 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } | |
1285 | bool ControlDown() { return m_control; } | |
1286 | bool MetaDown() { return m_meta; } | |
1287 | bool ShiftDown() { return m_shift; } | |
1288 | bool AltDown() { return m_alt; } | |
2d66e025 | 1289 | |
60ff3b99 VZ |
1290 | protected: |
1291 | int m_rowOrCol; | |
1292 | int m_x; | |
1293 | int m_y; | |
1294 | bool m_control; | |
1295 | bool m_meta; | |
1296 | bool m_shift; | |
1297 | bool m_alt; | |
1298 | ||
2d66e025 | 1299 | DECLARE_DYNAMIC_CLASS(wxGridSizeEvent) |
f85afd4e MB |
1300 | }; |
1301 | ||
1302 | ||
1303 | class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent | |
1304 | { | |
60ff3b99 | 1305 | public: |
f85afd4e | 1306 | wxGridRangeSelectEvent() |
60ff3b99 VZ |
1307 | : wxNotifyEvent() |
1308 | { | |
1309 | m_topLeft = wxGridNoCellCoords; | |
1310 | m_bottomRight = wxGridNoCellCoords; | |
1311 | m_control = FALSE; | |
1312 | m_meta = FALSE; | |
1313 | m_shift = FALSE; | |
1314 | m_alt = FALSE; | |
1315 | } | |
f85afd4e MB |
1316 | |
1317 | wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj, | |
60ff3b99 VZ |
1318 | const wxGridCellCoords& topLeft, |
1319 | const wxGridCellCoords& bottomRight, | |
1320 | bool control=FALSE, bool shift=FALSE, | |
1321 | bool alt=FALSE, bool meta=FALSE); | |
f85afd4e MB |
1322 | |
1323 | wxGridCellCoords GetTopLeftCoords() { return m_topLeft; } | |
1324 | wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; } | |
1325 | int GetTopRow() { return m_topLeft.GetRow(); } | |
1326 | int GetBottomRow() { return m_bottomRight.GetRow(); } | |
1327 | int GetLeftCol() { return m_topLeft.GetCol(); } | |
1328 | int GetRightCol() { return m_bottomRight.GetCol(); } | |
1329 | bool ControlDown() { return m_control; } | |
1330 | bool MetaDown() { return m_meta; } | |
1331 | bool ShiftDown() { return m_shift; } | |
1332 | bool AltDown() { return m_alt; } | |
2d66e025 | 1333 | |
60ff3b99 VZ |
1334 | protected: |
1335 | wxGridCellCoords m_topLeft; | |
1336 | wxGridCellCoords m_bottomRight; | |
1337 | bool m_control; | |
1338 | bool m_meta; | |
1339 | bool m_shift; | |
1340 | bool m_alt; | |
1341 | ||
2d66e025 | 1342 | DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent) |
f85afd4e MB |
1343 | }; |
1344 | ||
1345 | ||
b5f788a5 MB |
1346 | const wxEventType EVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580; |
1347 | const wxEventType EVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581; | |
1348 | const wxEventType EVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582; | |
1349 | const wxEventType EVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583; | |
1350 | const wxEventType EVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584; | |
1351 | const wxEventType EVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585; | |
1352 | const wxEventType EVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586; | |
1353 | const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587; | |
1354 | const wxEventType EVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588; | |
1355 | const wxEventType EVT_GRID_COL_SIZE = wxEVT_FIRST + 1589; | |
1356 | const wxEventType EVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590; | |
1357 | const wxEventType EVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591; | |
749692cc MB |
1358 | const wxEventType EVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592; |
1359 | ||
f85afd4e MB |
1360 | |
1361 | typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&); | |
1362 | typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&); | |
1363 | typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&); | |
1364 | ||
b5f788a5 MB |
1365 | #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
1366 | #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1367 | #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1368 | #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1369 | #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1370 | #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1371 | #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1372 | #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1373 | #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL }, | |
1374 | #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL }, | |
1375 | #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL }, | |
60ff3b99 | 1376 | #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
749692cc | 1377 | #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
f85afd4e MB |
1378 | |
1379 | ||
1380 | #if 0 // TODO: implement these ? others ? | |
1381 | ||
b5f788a5 MB |
1382 | const wxEventType EVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576; |
1383 | const wxEventType EVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577; | |
1384 | const wxEventType EVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578; | |
f85afd4e | 1385 | |
b5f788a5 MB |
1386 | #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
1387 | #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1388 | #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
f85afd4e MB |
1389 | |
1390 | #endif | |
1391 | ||
1392 | #endif // #ifndef __WXGRID_H__ | |
1393 | ||
1394 | #endif // ifndef wxUSE_NEW_GRID | |
8fb66724 | 1395 |