| 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: |
| 6 | // Created: 1/08/1999 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) Michael Bedward |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #include "wx/defs.h" |
| 13 | |
| 14 | #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) |
| 15 | #include "gridg.h" |
| 16 | #else |
| 17 | |
| 18 | #ifndef __WXGRID_H__ |
| 19 | #define __WXGRID_H__ |
| 20 | |
| 21 | #ifdef __GNUG__ |
| 22 | #pragma interface "grid.h" |
| 23 | #endif |
| 24 | |
| 25 | #include "wx/hash.h" |
| 26 | #include "wx/panel.h" |
| 27 | #include "wx/scrolwin.h" |
| 28 | #include "wx/string.h" |
| 29 | #include "wx/scrolbar.h" |
| 30 | #include "wx/event.h" |
| 31 | #include "wx/combobox.h" |
| 32 | #include "wx/dynarray.h" |
| 33 | #include "wx/timer.h" |
| 34 | |
| 35 | // ---------------------------------------------------------------------------- |
| 36 | // constants |
| 37 | // ---------------------------------------------------------------------------- |
| 38 | |
| 39 | // Default parameters for wxGrid |
| 40 | // |
| 41 | #define WXGRID_DEFAULT_NUMBER_ROWS 10 |
| 42 | #define WXGRID_DEFAULT_NUMBER_COLS 10 |
| 43 | #ifdef __WXMSW__ |
| 44 | #define WXGRID_DEFAULT_ROW_HEIGHT 25 |
| 45 | #else |
| 46 | #define WXGRID_DEFAULT_ROW_HEIGHT 30 |
| 47 | #endif // __WXMSW__ |
| 48 | #define WXGRID_DEFAULT_COL_WIDTH 80 |
| 49 | #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32 |
| 50 | #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82 |
| 51 | #define WXGRID_LABEL_EDGE_ZONE 2 |
| 52 | #define WXGRID_MIN_ROW_HEIGHT 15 |
| 53 | #define WXGRID_MIN_COL_WIDTH 15 |
| 54 | #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16 |
| 55 | |
| 56 | // type names for grid table values |
| 57 | #define wxGRID_VALUE_STRING _T("string") |
| 58 | #define wxGRID_VALUE_BOOL _T("bool") |
| 59 | #define wxGRID_VALUE_NUMBER _T("long") |
| 60 | #define wxGRID_VALUE_FLOAT _T("double") |
| 61 | #define wxGRID_VALUE_CHOICE _T("choice") |
| 62 | |
| 63 | #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING |
| 64 | #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER |
| 65 | |
| 66 | // ---------------------------------------------------------------------------- |
| 67 | // forward declarations |
| 68 | // ---------------------------------------------------------------------------- |
| 69 | |
| 70 | class WXDLLEXPORT wxGrid; |
| 71 | class WXDLLEXPORT wxGridCellAttr; |
| 72 | class WXDLLEXPORT wxGridCellAttrProviderData; |
| 73 | class WXDLLEXPORT wxGridColLabelWindow; |
| 74 | class WXDLLEXPORT wxGridCornerLabelWindow; |
| 75 | class WXDLLEXPORT wxGridRowLabelWindow; |
| 76 | class WXDLLEXPORT wxGridTableBase; |
| 77 | class WXDLLEXPORT wxGridWindow; |
| 78 | class WXDLLEXPORT wxGridTypeRegistry; |
| 79 | class WXDLLEXPORT wxGridSelection; |
| 80 | |
| 81 | class WXDLLEXPORT wxCheckBox; |
| 82 | class WXDLLEXPORT wxComboBox; |
| 83 | class WXDLLEXPORT wxTextCtrl; |
| 84 | class WXDLLEXPORT wxSpinCtrl; |
| 85 | |
| 86 | // ---------------------------------------------------------------------------- |
| 87 | // macros |
| 88 | // ---------------------------------------------------------------------------- |
| 89 | |
| 90 | #define wxSafeIncRef(p) if ( p ) (p)->IncRef() |
| 91 | #define wxSafeDecRef(p) if ( p ) (p)->DecRef() |
| 92 | |
| 93 | // ---------------------------------------------------------------------------- |
| 94 | // wxGridCellWorker: common base class for wxGridCellRenderer and |
| 95 | // wxGridCellEditor |
| 96 | // |
| 97 | // NB: this is more an implementation convenience than a design issue, so this |
| 98 | // class is not documented and is not public at all |
| 99 | // ---------------------------------------------------------------------------- |
| 100 | |
| 101 | class WXDLLEXPORT wxGridCellWorker |
| 102 | { |
| 103 | public: |
| 104 | wxGridCellWorker() { m_nRef = 1; } |
| 105 | |
| 106 | // this class is ref counted: it is created with ref count of 1, so |
| 107 | // calling DecRef() once will delete it. Calling IncRef() allows to lock |
| 108 | // it until the matching DecRef() is called |
| 109 | void IncRef() { m_nRef++; } |
| 110 | void DecRef() { if ( !--m_nRef ) delete this; } |
| 111 | |
| 112 | // interpret renderer parameters: arbitrary string whose interpretatin is |
| 113 | // left to the derived classes |
| 114 | virtual void SetParameters(const wxString& params); |
| 115 | |
| 116 | protected: |
| 117 | // virtual dtor for any base class - private because only DecRef() can |
| 118 | // delete us |
| 119 | virtual ~wxGridCellWorker(); |
| 120 | |
| 121 | private: |
| 122 | size_t m_nRef; |
| 123 | |
| 124 | // suppress the stupid gcc warning about the class having private dtor and |
| 125 | // no friends |
| 126 | friend class wxGridCellWorkerDummyFriend; |
| 127 | }; |
| 128 | |
| 129 | // ---------------------------------------------------------------------------- |
| 130 | // wxGridCellRenderer: this class is responsible for actually drawing the cell |
| 131 | // in the grid. You may pass it to the wxGridCellAttr (below) to change the |
| 132 | // format of one given cell or to wxGrid::SetDefaultRenderer() to change the |
| 133 | // view of all cells. This is an ABC, you will normally use one of the |
| 134 | // predefined derived classes or derive your own class from it. |
| 135 | // ---------------------------------------------------------------------------- |
| 136 | |
| 137 | class WXDLLEXPORT wxGridCellRenderer : public wxGridCellWorker |
| 138 | { |
| 139 | public: |
| 140 | // draw the given cell on the provided DC inside the given rectangle |
| 141 | // using the style specified by the attribute and the default or selected |
| 142 | // state corresponding to the isSelected value. |
| 143 | // |
| 144 | // this pure virtual function has a default implementation which will |
| 145 | // prepare the DC using the given attribute: it will draw the rectangle |
| 146 | // with the bg colour from attr and set the text colour and font |
| 147 | virtual void Draw(wxGrid& grid, |
| 148 | wxGridCellAttr& attr, |
| 149 | wxDC& dc, |
| 150 | const wxRect& rect, |
| 151 | int row, int col, |
| 152 | bool isSelected) = 0; |
| 153 | |
| 154 | // get the preferred size of the cell for its contents |
| 155 | virtual wxSize GetBestSize(wxGrid& grid, |
| 156 | wxGridCellAttr& attr, |
| 157 | wxDC& dc, |
| 158 | int row, int col) = 0; |
| 159 | |
| 160 | // create a new object which is the copy of this one |
| 161 | virtual wxGridCellRenderer *Clone() const = 0; |
| 162 | }; |
| 163 | |
| 164 | // the default renderer for the cells containing string data |
| 165 | class WXDLLEXPORT wxGridCellStringRenderer : public wxGridCellRenderer |
| 166 | { |
| 167 | public: |
| 168 | // draw the string |
| 169 | virtual void Draw(wxGrid& grid, |
| 170 | wxGridCellAttr& attr, |
| 171 | wxDC& dc, |
| 172 | const wxRect& rect, |
| 173 | int row, int col, |
| 174 | bool isSelected); |
| 175 | |
| 176 | // return the string extent |
| 177 | virtual wxSize GetBestSize(wxGrid& grid, |
| 178 | wxGridCellAttr& attr, |
| 179 | wxDC& dc, |
| 180 | int row, int col); |
| 181 | |
| 182 | virtual wxGridCellRenderer *Clone() const |
| 183 | { return new wxGridCellStringRenderer; } |
| 184 | |
| 185 | protected: |
| 186 | // set the text colours before drawing |
| 187 | void SetTextColoursAndFont(wxGrid& grid, |
| 188 | wxGridCellAttr& attr, |
| 189 | wxDC& dc, |
| 190 | bool isSelected); |
| 191 | |
| 192 | // calc the string extent for given string/font |
| 193 | wxSize DoGetBestSize(wxGridCellAttr& attr, |
| 194 | wxDC& dc, |
| 195 | const wxString& text); |
| 196 | }; |
| 197 | |
| 198 | // the default renderer for the cells containing numeric (long) data |
| 199 | class WXDLLEXPORT wxGridCellNumberRenderer : public wxGridCellStringRenderer |
| 200 | { |
| 201 | public: |
| 202 | // draw the string right aligned |
| 203 | virtual void Draw(wxGrid& grid, |
| 204 | wxGridCellAttr& attr, |
| 205 | wxDC& dc, |
| 206 | const wxRect& rect, |
| 207 | int row, int col, |
| 208 | bool isSelected); |
| 209 | |
| 210 | virtual wxSize GetBestSize(wxGrid& grid, |
| 211 | wxGridCellAttr& attr, |
| 212 | wxDC& dc, |
| 213 | int row, int col); |
| 214 | |
| 215 | virtual wxGridCellRenderer *Clone() const |
| 216 | { return new wxGridCellNumberRenderer; } |
| 217 | |
| 218 | protected: |
| 219 | wxString GetString(wxGrid& grid, int row, int col); |
| 220 | }; |
| 221 | |
| 222 | class WXDLLEXPORT wxGridCellFloatRenderer : public wxGridCellStringRenderer |
| 223 | { |
| 224 | public: |
| 225 | wxGridCellFloatRenderer(int width = -1, int precision = -1); |
| 226 | |
| 227 | // get/change formatting parameters |
| 228 | int GetWidth() const { return m_width; } |
| 229 | void SetWidth(int width) { m_width = width; m_format.clear(); } |
| 230 | int GetPrecision() const { return m_precision; } |
| 231 | void SetPrecision(int precision) { m_precision = precision; m_format.clear(); } |
| 232 | |
| 233 | // draw the string right aligned with given width/precision |
| 234 | virtual void Draw(wxGrid& grid, |
| 235 | wxGridCellAttr& attr, |
| 236 | wxDC& dc, |
| 237 | const wxRect& rect, |
| 238 | int row, int col, |
| 239 | bool isSelected); |
| 240 | |
| 241 | virtual wxSize GetBestSize(wxGrid& grid, |
| 242 | wxGridCellAttr& attr, |
| 243 | wxDC& dc, |
| 244 | int row, int col); |
| 245 | |
| 246 | // parameters string format is "width[,precision]" |
| 247 | virtual void SetParameters(const wxString& params); |
| 248 | |
| 249 | virtual wxGridCellRenderer *Clone() const; |
| 250 | |
| 251 | protected: |
| 252 | wxString GetString(wxGrid& grid, int row, int col); |
| 253 | |
| 254 | private: |
| 255 | // formatting parameters |
| 256 | int m_width, |
| 257 | m_precision; |
| 258 | |
| 259 | wxString m_format; |
| 260 | }; |
| 261 | |
| 262 | // renderer for boolean fields |
| 263 | class WXDLLEXPORT wxGridCellBoolRenderer : public wxGridCellRenderer |
| 264 | { |
| 265 | public: |
| 266 | // draw a check mark or nothing |
| 267 | virtual void Draw(wxGrid& grid, |
| 268 | wxGridCellAttr& attr, |
| 269 | wxDC& dc, |
| 270 | const wxRect& rect, |
| 271 | int row, int col, |
| 272 | bool isSelected); |
| 273 | |
| 274 | // return the checkmark size |
| 275 | virtual wxSize GetBestSize(wxGrid& grid, |
| 276 | wxGridCellAttr& attr, |
| 277 | wxDC& dc, |
| 278 | int row, int col); |
| 279 | |
| 280 | virtual wxGridCellRenderer *Clone() const |
| 281 | { return new wxGridCellBoolRenderer; } |
| 282 | |
| 283 | private: |
| 284 | static wxSize ms_sizeCheckMark; |
| 285 | }; |
| 286 | |
| 287 | // ---------------------------------------------------------------------------- |
| 288 | // wxGridCellEditor: This class is responsible for providing and manipulating |
| 289 | // the in-place edit controls for the grid. Instances of wxGridCellEditor |
| 290 | // (actually, instances of derived classes since it is an ABC) can be |
| 291 | // associated with the cell attributes for individual cells, rows, columns, or |
| 292 | // even for the entire grid. |
| 293 | // ---------------------------------------------------------------------------- |
| 294 | |
| 295 | class WXDLLEXPORT wxGridCellEditor : public wxGridCellWorker |
| 296 | { |
| 297 | public: |
| 298 | wxGridCellEditor(); |
| 299 | |
| 300 | bool IsCreated() { return m_control != NULL; } |
| 301 | |
| 302 | // Creates the actual edit control |
| 303 | virtual void Create(wxWindow* parent, |
| 304 | wxWindowID id, |
| 305 | wxEvtHandler* evtHandler) = 0; |
| 306 | |
| 307 | // Size and position the edit control |
| 308 | virtual void SetSize(const wxRect& rect); |
| 309 | |
| 310 | // Show or hide the edit control, use the specified attributes to set |
| 311 | // colours/fonts for it |
| 312 | virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL); |
| 313 | |
| 314 | // Draws the part of the cell not occupied by the control: the base class |
| 315 | // version just fills it with background colour from the attribute |
| 316 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); |
| 317 | |
| 318 | // Fetch the value from the table and prepare the edit control |
| 319 | // to begin editing. Set the focus to the edit control. |
| 320 | virtual void BeginEdit(int row, int col, wxGrid* grid) = 0; |
| 321 | |
| 322 | // Complete the editing of the current cell. Returns true if the value has |
| 323 | // changed. If necessary, the control may be destroyed. |
| 324 | virtual bool EndEdit(int row, int col, wxGrid* grid) = 0; |
| 325 | |
| 326 | // Reset the value in the control back to its starting value |
| 327 | virtual void Reset() = 0; |
| 328 | |
| 329 | // If the editor is enabled by pressing keys on the grid, |
| 330 | // this will be called to let the editor do something about |
| 331 | // that first key if desired. |
| 332 | virtual void StartingKey(wxKeyEvent& event); |
| 333 | |
| 334 | // if the editor is enabled by clicking on the cell, this method will be |
| 335 | // called |
| 336 | virtual void StartingClick(); |
| 337 | |
| 338 | // Some types of controls on some platforms may need some help |
| 339 | // with the Return key. |
| 340 | virtual void HandleReturn(wxKeyEvent& event); |
| 341 | |
| 342 | // Final cleanup |
| 343 | virtual void Destroy(); |
| 344 | |
| 345 | // create a new object which is the copy of this one |
| 346 | virtual wxGridCellEditor *Clone() const = 0; |
| 347 | |
| 348 | protected: |
| 349 | // the dtor is private because only DecRef() can delete us |
| 350 | virtual ~wxGridCellEditor(); |
| 351 | |
| 352 | // the control we show on screen |
| 353 | wxControl* m_control; |
| 354 | |
| 355 | // if we change the colours/font of the control from the default ones, we |
| 356 | // must restore the default later and we save them here between calls to |
| 357 | // Show(TRUE) and Show(FALSE) |
| 358 | wxColour m_colFgOld, |
| 359 | m_colBgOld; |
| 360 | wxFont m_fontOld; |
| 361 | |
| 362 | // suppress the stupid gcc warning about the class having private dtor and |
| 363 | // no friends |
| 364 | friend class wxGridCellEditorDummyFriend; |
| 365 | }; |
| 366 | |
| 367 | // the editor for string/text data |
| 368 | class WXDLLEXPORT wxGridCellTextEditor : public wxGridCellEditor |
| 369 | { |
| 370 | public: |
| 371 | wxGridCellTextEditor(); |
| 372 | |
| 373 | virtual void Create(wxWindow* parent, |
| 374 | wxWindowID id, |
| 375 | wxEvtHandler* evtHandler); |
| 376 | virtual void SetSize(const wxRect& rect); |
| 377 | |
| 378 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); |
| 379 | |
| 380 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
| 381 | virtual bool EndEdit(int row, int col, wxGrid* grid); |
| 382 | |
| 383 | virtual void Reset(); |
| 384 | virtual void StartingKey(wxKeyEvent& event); |
| 385 | virtual void HandleReturn(wxKeyEvent& event); |
| 386 | |
| 387 | // parameters string format is "max_width" |
| 388 | virtual void SetParameters(const wxString& params); |
| 389 | |
| 390 | virtual wxGridCellEditor *Clone() const |
| 391 | { return new wxGridCellTextEditor; } |
| 392 | |
| 393 | protected: |
| 394 | wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; } |
| 395 | |
| 396 | // parts of our virtual functions reused by the derived classes |
| 397 | void DoBeginEdit(const wxString& startValue); |
| 398 | void DoReset(const wxString& startValue); |
| 399 | |
| 400 | private: |
| 401 | size_t m_maxChars; // max number of chars allowed |
| 402 | wxString m_startValue; |
| 403 | }; |
| 404 | |
| 405 | // the editor for numeric (long) data |
| 406 | class WXDLLEXPORT wxGridCellNumberEditor : public wxGridCellTextEditor |
| 407 | { |
| 408 | public: |
| 409 | // allows to specify the range - if min == max == -1, no range checking is |
| 410 | // done |
| 411 | wxGridCellNumberEditor(int min = -1, int max = -1); |
| 412 | |
| 413 | virtual void Create(wxWindow* parent, |
| 414 | wxWindowID id, |
| 415 | wxEvtHandler* evtHandler); |
| 416 | |
| 417 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
| 418 | virtual bool EndEdit(int row, int col, wxGrid* grid); |
| 419 | |
| 420 | virtual void Reset(); |
| 421 | virtual void StartingKey(wxKeyEvent& event); |
| 422 | |
| 423 | // parameters string format is "min,max" |
| 424 | virtual void SetParameters(const wxString& params); |
| 425 | |
| 426 | virtual wxGridCellEditor *Clone() const |
| 427 | { return new wxGridCellNumberEditor(m_min, m_max); } |
| 428 | |
| 429 | protected: |
| 430 | wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; } |
| 431 | |
| 432 | // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl |
| 433 | bool HasRange() const { return m_min != m_max; } |
| 434 | |
| 435 | // string representation of m_valueOld |
| 436 | wxString GetString() const |
| 437 | { return wxString::Format(_T("%ld"), m_valueOld); } |
| 438 | |
| 439 | private: |
| 440 | int m_min, |
| 441 | m_max; |
| 442 | |
| 443 | long m_valueOld; |
| 444 | }; |
| 445 | |
| 446 | // the editor for floating point numbers (double) data |
| 447 | class WXDLLEXPORT wxGridCellFloatEditor : public wxGridCellTextEditor |
| 448 | { |
| 449 | public: |
| 450 | virtual void Create(wxWindow* parent, |
| 451 | wxWindowID id, |
| 452 | wxEvtHandler* evtHandler); |
| 453 | |
| 454 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
| 455 | virtual bool EndEdit(int row, int col, wxGrid* grid); |
| 456 | |
| 457 | virtual void Reset(); |
| 458 | virtual void StartingKey(wxKeyEvent& event); |
| 459 | |
| 460 | virtual wxGridCellEditor *Clone() const |
| 461 | { return new wxGridCellFloatEditor; } |
| 462 | |
| 463 | protected: |
| 464 | // string representation of m_valueOld |
| 465 | wxString GetString() const |
| 466 | { return wxString::Format(_T("%f"), m_valueOld); } |
| 467 | |
| 468 | private: |
| 469 | double m_valueOld; |
| 470 | }; |
| 471 | |
| 472 | // the editor for boolean data |
| 473 | class WXDLLEXPORT wxGridCellBoolEditor : public wxGridCellEditor |
| 474 | { |
| 475 | public: |
| 476 | virtual void Create(wxWindow* parent, |
| 477 | wxWindowID id, |
| 478 | wxEvtHandler* evtHandler); |
| 479 | |
| 480 | virtual void SetSize(const wxRect& rect); |
| 481 | virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL); |
| 482 | |
| 483 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
| 484 | virtual bool EndEdit(int row, int col, wxGrid* grid); |
| 485 | |
| 486 | virtual void Reset(); |
| 487 | virtual void StartingClick(); |
| 488 | |
| 489 | virtual wxGridCellEditor *Clone() const |
| 490 | { return new wxGridCellBoolEditor; } |
| 491 | |
| 492 | protected: |
| 493 | wxCheckBox *CBox() const { return (wxCheckBox *)m_control; } |
| 494 | |
| 495 | private: |
| 496 | bool m_startValue; |
| 497 | }; |
| 498 | |
| 499 | // the editor for string data allowing to choose from the list of strings |
| 500 | class WXDLLEXPORT wxGridCellChoiceEditor : public wxGridCellEditor |
| 501 | { |
| 502 | public: |
| 503 | // if !allowOthers, user can't type a string not in choices array |
| 504 | wxGridCellChoiceEditor(size_t count = 0, |
| 505 | const wxChar* choices[] = NULL, |
| 506 | bool allowOthers = FALSE); |
| 507 | |
| 508 | virtual void Create(wxWindow* parent, |
| 509 | wxWindowID id, |
| 510 | wxEvtHandler* evtHandler); |
| 511 | |
| 512 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); |
| 513 | |
| 514 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
| 515 | virtual bool EndEdit(int row, int col, wxGrid* grid); |
| 516 | |
| 517 | virtual void Reset(); |
| 518 | |
| 519 | // parameters string format is "item1[,item2[...,itemN]]" |
| 520 | virtual void SetParameters(const wxString& params); |
| 521 | |
| 522 | virtual wxGridCellEditor *Clone() const; |
| 523 | |
| 524 | protected: |
| 525 | wxComboBox *Combo() const { return (wxComboBox *)m_control; } |
| 526 | |
| 527 | private: |
| 528 | wxString m_startValue; |
| 529 | wxArrayString m_choices; |
| 530 | bool m_allowOthers; |
| 531 | }; |
| 532 | |
| 533 | // ---------------------------------------------------------------------------- |
| 534 | // wxGridCellAttr: this class can be used to alter the cells appearance in |
| 535 | // the grid by changing their colour/font/... from default. An object of this |
| 536 | // class may be returned by wxGridTable::GetAttr(). |
| 537 | // ---------------------------------------------------------------------------- |
| 538 | |
| 539 | class WXDLLEXPORT wxGridCellAttr |
| 540 | { |
| 541 | public: |
| 542 | // ctors |
| 543 | wxGridCellAttr() |
| 544 | { |
| 545 | Init(); |
| 546 | SetAlignment(0, 0); |
| 547 | } |
| 548 | |
| 549 | // VZ: considering the number of members wxGridCellAttr has now, this ctor |
| 550 | // seems to be pretty useless... may be we should just remove it? |
| 551 | wxGridCellAttr(const wxColour& colText, |
| 552 | const wxColour& colBack, |
| 553 | const wxFont& font, |
| 554 | int hAlign, |
| 555 | int vAlign) |
| 556 | : m_colText(colText), m_colBack(colBack), m_font(font) |
| 557 | { |
| 558 | Init(); |
| 559 | SetAlignment(hAlign, vAlign); |
| 560 | } |
| 561 | |
| 562 | // creates a new copy of this object |
| 563 | wxGridCellAttr *Clone() const; |
| 564 | |
| 565 | // this class is ref counted: it is created with ref count of 1, so |
| 566 | // calling DecRef() once will delete it. Calling IncRef() allows to lock |
| 567 | // it until the matching DecRef() is called |
| 568 | void IncRef() { m_nRef++; } |
| 569 | void DecRef() { if ( !--m_nRef ) delete this; } |
| 570 | |
| 571 | // setters |
| 572 | void SetTextColour(const wxColour& colText) { m_colText = colText; } |
| 573 | void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } |
| 574 | void SetFont(const wxFont& font) { m_font = font; } |
| 575 | void SetAlignment(int hAlign, int vAlign) |
| 576 | { |
| 577 | m_hAlign = hAlign; |
| 578 | m_vAlign = vAlign; |
| 579 | } |
| 580 | void SetReadOnly(bool isReadOnly = TRUE) { m_isReadOnly = isReadOnly; } |
| 581 | |
| 582 | // takes ownership of the pointer |
| 583 | void SetRenderer(wxGridCellRenderer *renderer) |
| 584 | { wxSafeDecRef(m_renderer); m_renderer = renderer; } |
| 585 | void SetEditor(wxGridCellEditor* editor) |
| 586 | { wxSafeDecRef(m_editor); m_editor = editor; } |
| 587 | |
| 588 | // accessors |
| 589 | bool HasTextColour() const { return m_colText.Ok(); } |
| 590 | bool HasBackgroundColour() const { return m_colBack.Ok(); } |
| 591 | bool HasFont() const { return m_font.Ok(); } |
| 592 | bool HasAlignment() const { return m_hAlign || m_vAlign; } |
| 593 | bool HasRenderer() const { return m_renderer != NULL; } |
| 594 | bool HasEditor() const { return m_editor != NULL; } |
| 595 | |
| 596 | const wxColour& GetTextColour() const; |
| 597 | const wxColour& GetBackgroundColour() const; |
| 598 | const wxFont& GetFont() const; |
| 599 | void GetAlignment(int *hAlign, int *vAlign) const; |
| 600 | wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const; |
| 601 | wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const; |
| 602 | |
| 603 | bool IsReadOnly() const { return m_isReadOnly; } |
| 604 | |
| 605 | void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; } |
| 606 | |
| 607 | private: |
| 608 | // the common part of all ctors |
| 609 | void Init() |
| 610 | { |
| 611 | m_nRef = 1; |
| 612 | |
| 613 | m_isReadOnly = FALSE; |
| 614 | |
| 615 | m_renderer = NULL; |
| 616 | m_editor = NULL; |
| 617 | } |
| 618 | |
| 619 | // the dtor is private because only DecRef() can delete us |
| 620 | ~wxGridCellAttr() |
| 621 | { |
| 622 | wxSafeDecRef(m_renderer); |
| 623 | wxSafeDecRef(m_editor); |
| 624 | } |
| 625 | |
| 626 | // the ref count - when it goes to 0, we die |
| 627 | size_t m_nRef; |
| 628 | |
| 629 | wxColour m_colText, |
| 630 | m_colBack; |
| 631 | wxFont m_font; |
| 632 | int m_hAlign, |
| 633 | m_vAlign; |
| 634 | |
| 635 | wxGridCellRenderer* m_renderer; |
| 636 | wxGridCellEditor* m_editor; |
| 637 | wxGridCellAttr* m_defGridAttr; |
| 638 | |
| 639 | bool m_isReadOnly; |
| 640 | |
| 641 | // use Clone() instead |
| 642 | DECLARE_NO_COPY_CLASS(wxGridCellAttr); |
| 643 | |
| 644 | // suppress the stupid gcc warning about the class having private dtor and |
| 645 | // no friends |
| 646 | friend class wxGridCellAttrDummyFriend; |
| 647 | }; |
| 648 | |
| 649 | // ---------------------------------------------------------------------------- |
| 650 | // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the |
| 651 | // cell attributes. |
| 652 | // ---------------------------------------------------------------------------- |
| 653 | |
| 654 | // implementation note: we separate it from wxGridTableBase because we wish to |
| 655 | // avoid deriving a new table class if possible, and sometimes it will be |
| 656 | // enough to just derive another wxGridCellAttrProvider instead |
| 657 | // |
| 658 | // the default implementation is reasonably efficient for the generic case, |
| 659 | // but you might still wish to implement your own for some specific situations |
| 660 | // if you have performance problems with the stock one |
| 661 | class WXDLLEXPORT wxGridCellAttrProvider |
| 662 | { |
| 663 | public: |
| 664 | wxGridCellAttrProvider(); |
| 665 | virtual ~wxGridCellAttrProvider(); |
| 666 | |
| 667 | // DecRef() must be called on the returned pointer |
| 668 | virtual wxGridCellAttr *GetAttr(int row, int col) const; |
| 669 | |
| 670 | // all these functions take ownership of the pointer, don't call DecRef() |
| 671 | // on it |
| 672 | virtual void SetAttr(wxGridCellAttr *attr, int row, int col); |
| 673 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); |
| 674 | virtual void SetColAttr(wxGridCellAttr *attr, int col); |
| 675 | |
| 676 | // these functions must be called whenever some rows/cols are deleted |
| 677 | // because the internal data must be updated then |
| 678 | void UpdateAttrRows( size_t pos, int numRows ); |
| 679 | void UpdateAttrCols( size_t pos, int numCols ); |
| 680 | |
| 681 | private: |
| 682 | void InitData(); |
| 683 | |
| 684 | wxGridCellAttrProviderData *m_data; |
| 685 | }; |
| 686 | |
| 687 | ////////////////////////////////////////////////////////////////////// |
| 688 | // |
| 689 | // Grid table classes |
| 690 | // |
| 691 | ////////////////////////////////////////////////////////////////////// |
| 692 | |
| 693 | |
| 694 | class WXDLLEXPORT wxGridTableBase : public wxObject |
| 695 | { |
| 696 | public: |
| 697 | wxGridTableBase(); |
| 698 | virtual ~wxGridTableBase(); |
| 699 | |
| 700 | // You must override these functions in a derived table class |
| 701 | // |
| 702 | virtual int GetNumberRows() = 0; |
| 703 | virtual int GetNumberCols() = 0; |
| 704 | virtual bool IsEmptyCell( int row, int col ) = 0; |
| 705 | virtual wxString GetValue( int row, int col ) = 0; |
| 706 | virtual void SetValue( int row, int col, const wxString& value ) = 0; |
| 707 | |
| 708 | // Data type determination and value access |
| 709 | virtual wxString GetTypeName( int row, int col ); |
| 710 | virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); |
| 711 | virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); |
| 712 | |
| 713 | virtual long GetValueAsLong( int row, int col ); |
| 714 | virtual double GetValueAsDouble( int row, int col ); |
| 715 | virtual bool GetValueAsBool( int row, int col ); |
| 716 | |
| 717 | virtual void SetValueAsLong( int row, int col, long value ); |
| 718 | virtual void SetValueAsDouble( int row, int col, double value ); |
| 719 | virtual void SetValueAsBool( int row, int col, bool value ); |
| 720 | |
| 721 | // For user defined types |
| 722 | virtual void* GetValueAsCustom( int row, int col, const wxString& typeName ); |
| 723 | virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value ); |
| 724 | |
| 725 | |
| 726 | // Overriding these is optional |
| 727 | // |
| 728 | virtual void SetView( wxGrid *grid ) { m_view = grid; } |
| 729 | virtual wxGrid * GetView() const { return m_view; } |
| 730 | |
| 731 | virtual void Clear() {} |
| 732 | virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 ); |
| 733 | virtual bool AppendRows( size_t numRows = 1 ); |
| 734 | virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); |
| 735 | virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 ); |
| 736 | virtual bool AppendCols( size_t numCols = 1 ); |
| 737 | virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); |
| 738 | |
| 739 | virtual wxString GetRowLabelValue( int row ); |
| 740 | virtual wxString GetColLabelValue( int col ); |
| 741 | virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {} |
| 742 | virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {} |
| 743 | |
| 744 | // Attribute handling |
| 745 | // |
| 746 | |
| 747 | // give us the attr provider to use - we take ownership of the pointer |
| 748 | void SetAttrProvider(wxGridCellAttrProvider *attrProvider); |
| 749 | |
| 750 | // get the currently used attr provider (may be NULL) |
| 751 | wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; } |
| 752 | |
| 753 | // Does this table allow attributes? Default implementation creates |
| 754 | // a wxGridCellAttrProvider if necessary. |
| 755 | virtual bool CanHaveAttributes(); |
| 756 | |
| 757 | |
| 758 | // change row/col number in attribute if needed |
| 759 | virtual void UpdateAttrRows( size_t pos, int numRows ); |
| 760 | virtual void UpdateAttrCols( size_t pos, int numCols ); |
| 761 | |
| 762 | // by default forwarded to wxGridCellAttrProvider if any. May be |
| 763 | // overridden to handle attributes directly in the table. |
| 764 | virtual wxGridCellAttr *GetAttr( int row, int col ); |
| 765 | |
| 766 | // these functions take ownership of the pointer |
| 767 | virtual void SetAttr(wxGridCellAttr* attr, int row, int col); |
| 768 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); |
| 769 | virtual void SetColAttr(wxGridCellAttr *attr, int col); |
| 770 | |
| 771 | private: |
| 772 | wxGrid * m_view; |
| 773 | wxGridCellAttrProvider *m_attrProvider; |
| 774 | |
| 775 | DECLARE_ABSTRACT_CLASS( wxGridTableBase ); |
| 776 | }; |
| 777 | |
| 778 | |
| 779 | // ---------------------------------------------------------------------------- |
| 780 | // wxGridTableMessage |
| 781 | // ---------------------------------------------------------------------------- |
| 782 | |
| 783 | // IDs for messages sent from grid table to view |
| 784 | // |
| 785 | enum wxGridTableRequest |
| 786 | { |
| 787 | wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000, |
| 788 | wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES, |
| 789 | wxGRIDTABLE_NOTIFY_ROWS_INSERTED, |
| 790 | wxGRIDTABLE_NOTIFY_ROWS_APPENDED, |
| 791 | wxGRIDTABLE_NOTIFY_ROWS_DELETED, |
| 792 | wxGRIDTABLE_NOTIFY_COLS_INSERTED, |
| 793 | wxGRIDTABLE_NOTIFY_COLS_APPENDED, |
| 794 | wxGRIDTABLE_NOTIFY_COLS_DELETED |
| 795 | }; |
| 796 | |
| 797 | class WXDLLEXPORT wxGridTableMessage |
| 798 | { |
| 799 | public: |
| 800 | wxGridTableMessage(); |
| 801 | wxGridTableMessage( wxGridTableBase *table, int id, |
| 802 | int comInt1 = -1, |
| 803 | int comInt2 = -1 ); |
| 804 | |
| 805 | void SetTableObject( wxGridTableBase *table ) { m_table = table; } |
| 806 | wxGridTableBase * GetTableObject() const { return m_table; } |
| 807 | void SetId( int id ) { m_id = id; } |
| 808 | int GetId() { return m_id; } |
| 809 | void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; } |
| 810 | int GetCommandInt() { return m_comInt1; } |
| 811 | void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; } |
| 812 | int GetCommandInt2() { return m_comInt2; } |
| 813 | |
| 814 | private: |
| 815 | wxGridTableBase *m_table; |
| 816 | int m_id; |
| 817 | int m_comInt1; |
| 818 | int m_comInt2; |
| 819 | }; |
| 820 | |
| 821 | |
| 822 | |
| 823 | // ------ wxGridStringArray |
| 824 | // A 2-dimensional array of strings for data values |
| 825 | // |
| 826 | |
| 827 | WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString, wxGridStringArray); |
| 828 | |
| 829 | |
| 830 | |
| 831 | // ------ wxGridStringTable |
| 832 | // |
| 833 | // Simplest type of data table for a grid for small tables of strings |
| 834 | // that are stored in memory |
| 835 | // |
| 836 | |
| 837 | class WXDLLEXPORT wxGridStringTable : public wxGridTableBase |
| 838 | { |
| 839 | public: |
| 840 | wxGridStringTable(); |
| 841 | wxGridStringTable( int numRows, int numCols ); |
| 842 | ~wxGridStringTable(); |
| 843 | |
| 844 | // these are pure virtual in wxGridTableBase |
| 845 | // |
| 846 | int GetNumberRows(); |
| 847 | int GetNumberCols(); |
| 848 | wxString GetValue( int row, int col ); |
| 849 | void SetValue( int row, int col, const wxString& s ); |
| 850 | bool IsEmptyCell( int row, int col ); |
| 851 | |
| 852 | // overridden functions from wxGridTableBase |
| 853 | // |
| 854 | void Clear(); |
| 855 | bool InsertRows( size_t pos = 0, size_t numRows = 1 ); |
| 856 | bool AppendRows( size_t numRows = 1 ); |
| 857 | bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); |
| 858 | bool InsertCols( size_t pos = 0, size_t numCols = 1 ); |
| 859 | bool AppendCols( size_t numCols = 1 ); |
| 860 | bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); |
| 861 | |
| 862 | void SetRowLabelValue( int row, const wxString& ); |
| 863 | void SetColLabelValue( int col, const wxString& ); |
| 864 | wxString GetRowLabelValue( int row ); |
| 865 | wxString GetColLabelValue( int col ); |
| 866 | |
| 867 | private: |
| 868 | wxGridStringArray m_data; |
| 869 | |
| 870 | // These only get used if you set your own labels, otherwise the |
| 871 | // GetRow/ColLabelValue functions return wxGridTableBase defaults |
| 872 | // |
| 873 | wxArrayString m_rowLabels; |
| 874 | wxArrayString m_colLabels; |
| 875 | |
| 876 | DECLARE_DYNAMIC_CLASS( wxGridStringTable ) |
| 877 | }; |
| 878 | |
| 879 | |
| 880 | |
| 881 | // ============================================================================ |
| 882 | // Grid view classes |
| 883 | // ============================================================================ |
| 884 | |
| 885 | // ---------------------------------------------------------------------------- |
| 886 | // wxGridCellCoords: location of a cell in the grid |
| 887 | // ---------------------------------------------------------------------------- |
| 888 | |
| 889 | class WXDLLEXPORT wxGridCellCoords |
| 890 | { |
| 891 | public: |
| 892 | wxGridCellCoords() { m_row = m_col = -1; } |
| 893 | wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; } |
| 894 | |
| 895 | // default copy ctor is ok |
| 896 | |
| 897 | int GetRow() const { return m_row; } |
| 898 | void SetRow( int n ) { m_row = n; } |
| 899 | int GetCol() const { return m_col; } |
| 900 | void SetCol( int n ) { m_col = n; } |
| 901 | void Set( int row, int col ) { m_row = row; m_col = col; } |
| 902 | |
| 903 | wxGridCellCoords& operator=( const wxGridCellCoords& other ) |
| 904 | { |
| 905 | if ( &other != this ) |
| 906 | { |
| 907 | m_row=other.m_row; |
| 908 | m_col=other.m_col; |
| 909 | } |
| 910 | return *this; |
| 911 | } |
| 912 | |
| 913 | bool operator==( const wxGridCellCoords& other ) const |
| 914 | { |
| 915 | return (m_row == other.m_row && m_col == other.m_col); |
| 916 | } |
| 917 | |
| 918 | bool operator!=( const wxGridCellCoords& other ) const |
| 919 | { |
| 920 | return (m_row != other.m_row || m_col != other.m_col); |
| 921 | } |
| 922 | |
| 923 | bool operator!() const |
| 924 | { |
| 925 | return (m_row == -1 && m_col == -1 ); |
| 926 | } |
| 927 | |
| 928 | private: |
| 929 | int m_row; |
| 930 | int m_col; |
| 931 | }; |
| 932 | |
| 933 | |
| 934 | // For comparisons... |
| 935 | // |
| 936 | extern wxGridCellCoords wxGridNoCellCoords; |
| 937 | extern wxRect wxGridNoCellRect; |
| 938 | |
| 939 | // An array of cell coords... |
| 940 | // |
| 941 | WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray); |
| 942 | |
| 943 | // ---------------------------------------------------------------------------- |
| 944 | // wxGrid |
| 945 | // ---------------------------------------------------------------------------- |
| 946 | |
| 947 | class WXDLLEXPORT wxGrid : public wxScrolledWindow |
| 948 | { |
| 949 | public: |
| 950 | wxGrid() |
| 951 | { |
| 952 | Create(); |
| 953 | } |
| 954 | |
| 955 | wxGrid( wxWindow *parent, |
| 956 | wxWindowID id, |
| 957 | const wxPoint& pos = wxDefaultPosition, |
| 958 | const wxSize& size = wxDefaultSize, |
| 959 | long style = wxWANTS_CHARS, |
| 960 | const wxString& name = wxPanelNameStr ); |
| 961 | |
| 962 | ~wxGrid(); |
| 963 | |
| 964 | enum wxGridSelectionModes {wxGridSelectCells, |
| 965 | wxGridSelectRows, |
| 966 | wxGridSelectColumns}; |
| 967 | |
| 968 | bool CreateGrid( int numRows, int numCols, |
| 969 | wxGrid::wxGridSelectionModes selmode = |
| 970 | wxGrid::wxGridSelectCells ); |
| 971 | |
| 972 | void SetSelectionMode(wxGrid::wxGridSelectionModes selmode); |
| 973 | |
| 974 | // ------ grid dimensions |
| 975 | // |
| 976 | int GetNumberRows() { return m_numRows; } |
| 977 | int GetNumberCols() { return m_numCols; } |
| 978 | |
| 979 | |
| 980 | // ------ display update functions |
| 981 | // |
| 982 | void CalcRowLabelsExposed( wxRegion& reg ); |
| 983 | |
| 984 | void CalcColLabelsExposed( wxRegion& reg ); |
| 985 | void CalcCellsExposed( wxRegion& reg ); |
| 986 | |
| 987 | |
| 988 | // ------ event handlers |
| 989 | // |
| 990 | void ProcessRowLabelMouseEvent( wxMouseEvent& event ); |
| 991 | void ProcessColLabelMouseEvent( wxMouseEvent& event ); |
| 992 | void ProcessCornerLabelMouseEvent( wxMouseEvent& event ); |
| 993 | void ProcessGridCellMouseEvent( wxMouseEvent& event ); |
| 994 | bool ProcessTableMessage( wxGridTableMessage& ); |
| 995 | |
| 996 | void DoEndDragResizeRow(); |
| 997 | void DoEndDragResizeCol(); |
| 998 | |
| 999 | wxGridTableBase * GetTable() const { return m_table; } |
| 1000 | bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE, |
| 1001 | wxGrid::wxGridSelectionModes selmode = |
| 1002 | wxGrid::wxGridSelectCells ); |
| 1003 | |
| 1004 | void ClearGrid(); |
| 1005 | bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE ); |
| 1006 | bool AppendRows( int numRows = 1, bool updateLabels=TRUE ); |
| 1007 | bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE ); |
| 1008 | bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE ); |
| 1009 | bool AppendCols( int numCols = 1, bool updateLabels=TRUE ); |
| 1010 | bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE ); |
| 1011 | |
| 1012 | void DrawGridCellArea( wxDC& dc ); |
| 1013 | void DrawGridSpace( wxDC& dc ); |
| 1014 | void DrawCellBorder( wxDC& dc, const wxGridCellCoords& ); |
| 1015 | void DrawAllGridLines( wxDC& dc, const wxRegion & reg ); |
| 1016 | void DrawCell( wxDC& dc, const wxGridCellCoords& ); |
| 1017 | void DrawHighlight(wxDC& dc); |
| 1018 | |
| 1019 | // this function is called when the current cell highlight must be redrawn |
| 1020 | // and may be overridden by the user |
| 1021 | virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ); |
| 1022 | |
| 1023 | void DrawRowLabels( wxDC& dc ); |
| 1024 | void DrawRowLabel( wxDC& dc, int row ); |
| 1025 | |
| 1026 | void DrawColLabels( wxDC& dc ); |
| 1027 | void DrawColLabel( wxDC& dc, int col ); |
| 1028 | |
| 1029 | |
| 1030 | // ------ Cell text drawing functions |
| 1031 | // |
| 1032 | void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&, |
| 1033 | int horizontalAlignment = wxLEFT, |
| 1034 | int verticalAlignment = wxTOP ); |
| 1035 | |
| 1036 | // Split a string containing newline chararcters into an array of |
| 1037 | // strings and return the number of lines |
| 1038 | // |
| 1039 | void StringToLines( const wxString& value, wxArrayString& lines ); |
| 1040 | |
| 1041 | void GetTextBoxSize( wxDC& dc, |
| 1042 | wxArrayString& lines, |
| 1043 | long *width, long *height ); |
| 1044 | |
| 1045 | |
| 1046 | // ------ |
| 1047 | // Code that does a lot of grid modification can be enclosed |
| 1048 | // between BeginBatch() and EndBatch() calls to avoid screen |
| 1049 | // flicker |
| 1050 | // |
| 1051 | void BeginBatch() { m_batchCount++; } |
| 1052 | void EndBatch() { if ( m_batchCount > 0 ) m_batchCount--; } |
| 1053 | int GetBatchCount() { return m_batchCount; } |
| 1054 | |
| 1055 | |
| 1056 | // ------ edit control functions |
| 1057 | // |
| 1058 | bool IsEditable() { return m_editable; } |
| 1059 | void EnableEditing( bool edit ); |
| 1060 | |
| 1061 | void EnableCellEditControl( bool enable = TRUE ); |
| 1062 | void DisableCellEditControl() { EnableCellEditControl(FALSE); } |
| 1063 | bool CanEnableCellControl() const; |
| 1064 | bool IsCellEditControlEnabled() const; |
| 1065 | |
| 1066 | bool IsCurrentCellReadOnly() const; |
| 1067 | |
| 1068 | void ShowCellEditControl(); |
| 1069 | void HideCellEditControl(); |
| 1070 | void SaveEditControlValue(); |
| 1071 | |
| 1072 | |
| 1073 | // ------ grid location functions |
| 1074 | // Note that all of these functions work with the logical coordinates of |
| 1075 | // grid cells and labels so you will need to convert from device |
| 1076 | // coordinates for mouse events etc. |
| 1077 | // |
| 1078 | void XYToCell( int x, int y, wxGridCellCoords& ); |
| 1079 | int YToRow( int y ); |
| 1080 | int XToCol( int x ); |
| 1081 | |
| 1082 | int YToEdgeOfRow( int y ); |
| 1083 | int XToEdgeOfCol( int x ); |
| 1084 | |
| 1085 | wxRect CellToRect( int row, int col ); |
| 1086 | wxRect CellToRect( const wxGridCellCoords& coords ) |
| 1087 | { return CellToRect( coords.GetRow(), coords.GetCol() ); } |
| 1088 | |
| 1089 | int GetGridCursorRow() { return m_currentCellCoords.GetRow(); } |
| 1090 | int GetGridCursorCol() { return m_currentCellCoords.GetCol(); } |
| 1091 | |
| 1092 | // check to see if a cell is either wholly visible (the default arg) or |
| 1093 | // at least partially visible in the grid window |
| 1094 | // |
| 1095 | bool IsVisible( int row, int col, bool wholeCellVisible = TRUE ); |
| 1096 | bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE ) |
| 1097 | { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); } |
| 1098 | void MakeCellVisible( int row, int col ); |
| 1099 | void MakeCellVisible( const wxGridCellCoords& coords ) |
| 1100 | { MakeCellVisible( coords.GetRow(), coords.GetCol() ); } |
| 1101 | |
| 1102 | |
| 1103 | // ------ grid cursor movement functions |
| 1104 | // |
| 1105 | void SetGridCursor( int row, int col ) |
| 1106 | { SetCurrentCell( wxGridCellCoords(row, col) ); } |
| 1107 | |
| 1108 | bool MoveCursorUp( bool expandSelection ); |
| 1109 | bool MoveCursorDown( bool expandSelection ); |
| 1110 | bool MoveCursorLeft( bool expandSelection ); |
| 1111 | bool MoveCursorRight( bool expandSelection ); |
| 1112 | bool MovePageDown(); |
| 1113 | bool MovePageUp(); |
| 1114 | bool MoveCursorUpBlock( bool expandSelection ); |
| 1115 | bool MoveCursorDownBlock( bool expandSelection ); |
| 1116 | bool MoveCursorLeftBlock( bool expandSelection ); |
| 1117 | bool MoveCursorRightBlock( bool expandSelection ); |
| 1118 | |
| 1119 | |
| 1120 | // ------ label and gridline formatting |
| 1121 | // |
| 1122 | int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; } |
| 1123 | int GetRowLabelSize() { return m_rowLabelWidth; } |
| 1124 | int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; } |
| 1125 | int GetColLabelSize() { return m_colLabelHeight; } |
| 1126 | wxColour GetLabelBackgroundColour() { return m_labelBackgroundColour; } |
| 1127 | wxColour GetLabelTextColour() { return m_labelTextColour; } |
| 1128 | wxFont GetLabelFont() { return m_labelFont; } |
| 1129 | void GetRowLabelAlignment( int *horiz, int *vert ); |
| 1130 | void GetColLabelAlignment( int *horiz, int *vert ); |
| 1131 | wxString GetRowLabelValue( int row ); |
| 1132 | wxString GetColLabelValue( int col ); |
| 1133 | wxColour GetGridLineColour() { return m_gridLineColour; } |
| 1134 | |
| 1135 | void SetRowLabelSize( int width ); |
| 1136 | void SetColLabelSize( int height ); |
| 1137 | void SetLabelBackgroundColour( const wxColour& ); |
| 1138 | void SetLabelTextColour( const wxColour& ); |
| 1139 | void SetLabelFont( const wxFont& ); |
| 1140 | void SetRowLabelAlignment( int horiz, int vert ); |
| 1141 | void SetColLabelAlignment( int horiz, int vert ); |
| 1142 | void SetRowLabelValue( int row, const wxString& ); |
| 1143 | void SetColLabelValue( int col, const wxString& ); |
| 1144 | void SetGridLineColour( const wxColour& ); |
| 1145 | |
| 1146 | void EnableDragRowSize( bool enable = TRUE ); |
| 1147 | void DisableDragRowSize() { EnableDragRowSize( FALSE ); } |
| 1148 | bool CanDragRowSize() { return m_canDragRowSize; } |
| 1149 | void EnableDragColSize( bool enable = TRUE ); |
| 1150 | void DisableDragColSize() { EnableDragColSize( FALSE ); } |
| 1151 | bool CanDragColSize() { return m_canDragColSize; } |
| 1152 | void EnableDragGridSize(bool enable = TRUE); |
| 1153 | void DisableDragGridSize() { EnableDragGridSize(FALSE); } |
| 1154 | bool CanDragGridSize() { return m_canDragGridSize; } |
| 1155 | |
| 1156 | // this sets the specified attribute for all cells in this row/col |
| 1157 | void SetRowAttr(int row, wxGridCellAttr *attr); |
| 1158 | void SetColAttr(int col, wxGridCellAttr *attr); |
| 1159 | |
| 1160 | // shortcuts for setting the column parameters |
| 1161 | |
| 1162 | // set the format for the data in the column: default is string |
| 1163 | void SetColFormatBool(int col); |
| 1164 | void SetColFormatNumber(int col); |
| 1165 | void SetColFormatFloat(int col, int width = -1, int precision = -1); |
| 1166 | void SetColFormatCustom(int col, const wxString& typeName); |
| 1167 | |
| 1168 | void EnableGridLines( bool enable = TRUE ); |
| 1169 | bool GridLinesEnabled() { return m_gridLinesEnabled; } |
| 1170 | |
| 1171 | // ------ row and col formatting |
| 1172 | // |
| 1173 | int GetDefaultRowSize(); |
| 1174 | int GetRowSize( int row ); |
| 1175 | int GetDefaultColSize(); |
| 1176 | int GetColSize( int col ); |
| 1177 | wxColour GetDefaultCellBackgroundColour(); |
| 1178 | wxColour GetCellBackgroundColour( int row, int col ); |
| 1179 | wxColour GetDefaultCellTextColour(); |
| 1180 | wxColour GetCellTextColour( int row, int col ); |
| 1181 | wxFont GetDefaultCellFont(); |
| 1182 | wxFont GetCellFont( int row, int col ); |
| 1183 | void GetDefaultCellAlignment( int *horiz, int *vert ); |
| 1184 | void GetCellAlignment( int row, int col, int *horiz, int *vert ); |
| 1185 | |
| 1186 | void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE ); |
| 1187 | void SetRowSize( int row, int height ); |
| 1188 | void SetDefaultColSize( int width, bool resizeExistingCols = FALSE ); |
| 1189 | |
| 1190 | void SetColSize( int col, int width ); |
| 1191 | |
| 1192 | // automatically size the column or row to fit to its contents, if |
| 1193 | // setAsMin is TRUE, this optimal width will also be set as minimal width |
| 1194 | // for this column |
| 1195 | void AutoSizeColumn( int col, bool setAsMin = TRUE ) |
| 1196 | { AutoSizeColOrRow(col, setAsMin, TRUE); } |
| 1197 | void AutoSizeRow( int row, bool setAsMin = TRUE ) |
| 1198 | { AutoSizeColOrRow(row, setAsMin, FALSE); } |
| 1199 | |
| 1200 | // auto size all columns (very ineffective for big grids!) |
| 1201 | void AutoSizeColumns( bool setAsMin = TRUE ) |
| 1202 | { (void)SetOrCalcColumnSizes(FALSE, setAsMin); } |
| 1203 | |
| 1204 | void AutoSizeRows( bool setAsMin = TRUE ) |
| 1205 | { (void)SetOrCalcRowSizes(FALSE, setAsMin); } |
| 1206 | |
| 1207 | // auto size the grid, that is make the columns/rows of the "right" size |
| 1208 | // and also set the grid size to just fit its contents |
| 1209 | void AutoSize(); |
| 1210 | |
| 1211 | // column won't be resized to be lesser width - this must be called during |
| 1212 | // the grid creation because it won't resize the column if it's already |
| 1213 | // narrower than the minimal width |
| 1214 | void SetColMinimalWidth( int col, int width ); |
| 1215 | void SetRowMinimalHeight( int row, int width ); |
| 1216 | |
| 1217 | void SetDefaultCellBackgroundColour( const wxColour& ); |
| 1218 | void SetCellBackgroundColour( int row, int col, const wxColour& ); |
| 1219 | void SetDefaultCellTextColour( const wxColour& ); |
| 1220 | |
| 1221 | void SetCellTextColour( int row, int col, const wxColour& ); |
| 1222 | void SetDefaultCellFont( const wxFont& ); |
| 1223 | void SetCellFont( int row, int col, const wxFont& ); |
| 1224 | void SetDefaultCellAlignment( int horiz, int vert ); |
| 1225 | void SetCellAlignment( int row, int col, int horiz, int vert ); |
| 1226 | |
| 1227 | // takes ownership of the pointer |
| 1228 | void SetDefaultRenderer(wxGridCellRenderer *renderer); |
| 1229 | void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer); |
| 1230 | wxGridCellRenderer *GetDefaultRenderer() const; |
| 1231 | wxGridCellRenderer* GetCellRenderer(int row, int col); |
| 1232 | |
| 1233 | // takes ownership of the pointer |
| 1234 | void SetDefaultEditor(wxGridCellEditor *editor); |
| 1235 | void SetCellEditor(int row, int col, wxGridCellEditor *editor); |
| 1236 | wxGridCellEditor *GetDefaultEditor() const; |
| 1237 | wxGridCellEditor* GetCellEditor(int row, int col); |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | // ------ cell value accessors |
| 1242 | // |
| 1243 | wxString GetCellValue( int row, int col ) |
| 1244 | { |
| 1245 | if ( m_table ) |
| 1246 | { |
| 1247 | return m_table->GetValue( row, col ); |
| 1248 | } |
| 1249 | else |
| 1250 | { |
| 1251 | return wxEmptyString; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | wxString GetCellValue( const wxGridCellCoords& coords ) |
| 1256 | { return GetCellValue( coords.GetRow(), coords.GetCol() ); } |
| 1257 | |
| 1258 | void SetCellValue( int row, int col, const wxString& s ); |
| 1259 | void SetCellValue( const wxGridCellCoords& coords, const wxString& s ) |
| 1260 | { SetCellValue( coords.GetRow(), coords.GetCol(), s ); } |
| 1261 | |
| 1262 | // returns TRUE if the cell can't be edited |
| 1263 | bool IsReadOnly(int row, int col) const; |
| 1264 | |
| 1265 | // make the cell editable/readonly |
| 1266 | void SetReadOnly(int row, int col, bool isReadOnly = TRUE); |
| 1267 | |
| 1268 | // ------ selections of blocks of cells |
| 1269 | // |
| 1270 | void SelectRow( int row, bool addToSelected = FALSE ); |
| 1271 | void SelectCol( int col, bool addToSelected = FALSE ); |
| 1272 | |
| 1273 | void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol ); |
| 1274 | |
| 1275 | void SelectBlock( const wxGridCellCoords& topLeft, |
| 1276 | const wxGridCellCoords& bottomRight ) |
| 1277 | { SelectBlock( topLeft.GetRow(), topLeft.GetCol(), |
| 1278 | bottomRight.GetRow(), bottomRight.GetCol() ); } |
| 1279 | |
| 1280 | void SelectAll(); |
| 1281 | |
| 1282 | bool IsSelection(); |
| 1283 | |
| 1284 | void ClearSelection(); |
| 1285 | |
| 1286 | bool IsInSelection( int row, int col ); |
| 1287 | |
| 1288 | bool IsInSelection( const wxGridCellCoords& coords ) |
| 1289 | { return IsInSelection( coords.GetRow(), coords.GetCol() ); } |
| 1290 | |
| 1291 | |
| 1292 | // This function returns the rectangle that encloses the block of cells |
| 1293 | // limited by TopLeft and BottomRight cell in device coords and clipped |
| 1294 | // to the client size of the grid window. |
| 1295 | // |
| 1296 | wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft, |
| 1297 | const wxGridCellCoords & bottomRight ); |
| 1298 | |
| 1299 | // This function returns the rectangle that encloses the selected cells |
| 1300 | // in device coords and clipped to the client size of the grid window. |
| 1301 | // |
| 1302 | wxRect SelectionToDeviceRect() |
| 1303 | { |
| 1304 | return BlockToDeviceRect( m_selectingTopLeft, |
| 1305 | m_selectingBottomRight ); |
| 1306 | } |
| 1307 | |
| 1308 | // Access or update the selection fore/back colours |
| 1309 | wxColour GetSelectionBackground() const |
| 1310 | { return m_selectionBackground; } |
| 1311 | wxColour GetSelectionForeground() const |
| 1312 | { return m_selectionForeground; } |
| 1313 | |
| 1314 | void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; } |
| 1315 | void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; } |
| 1316 | |
| 1317 | |
| 1318 | // Methods for a registry for mapping data types to Renderers/Editors |
| 1319 | void RegisterDataType(const wxString& typeName, |
| 1320 | wxGridCellRenderer* renderer, |
| 1321 | wxGridCellEditor* editor); |
| 1322 | wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const; |
| 1323 | wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const |
| 1324 | { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); } |
| 1325 | wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const; |
| 1326 | wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const; |
| 1327 | wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const; |
| 1328 | |
| 1329 | // grid may occupy more space than needed for its rows/columns, this |
| 1330 | // function allows to set how big this extra space is |
| 1331 | void SetMargins(int extraWidth, int extraHeight) |
| 1332 | { |
| 1333 | m_extraWidth = extraWidth; |
| 1334 | m_extraHeight = extraHeight; |
| 1335 | } |
| 1336 | |
| 1337 | // ------ For compatibility with previous wxGrid only... |
| 1338 | // |
| 1339 | // ************************************************ |
| 1340 | // ** Don't use these in new code because they ** |
| 1341 | // ** are liable to disappear in a future ** |
| 1342 | // ** revision ** |
| 1343 | // ************************************************ |
| 1344 | // |
| 1345 | |
| 1346 | wxGrid( wxWindow *parent, |
| 1347 | int x, int y, int w = -1, int h = -1, |
| 1348 | long style = wxWANTS_CHARS, |
| 1349 | const wxString& name = wxPanelNameStr ) |
| 1350 | : wxScrolledWindow( parent, -1, wxPoint(x,y), wxSize(w,h), |
| 1351 | (style|wxWANTS_CHARS), name ) |
| 1352 | { |
| 1353 | Create(); |
| 1354 | } |
| 1355 | |
| 1356 | void SetCellValue( const wxString& val, int row, int col ) |
| 1357 | { SetCellValue( row, col, val ); } |
| 1358 | |
| 1359 | void UpdateDimensions() |
| 1360 | { CalcDimensions(); } |
| 1361 | |
| 1362 | int GetRows() { return GetNumberRows(); } |
| 1363 | int GetCols() { return GetNumberCols(); } |
| 1364 | int GetCursorRow() { return GetGridCursorRow(); } |
| 1365 | int GetCursorColumn() { return GetGridCursorCol(); } |
| 1366 | |
| 1367 | int GetScrollPosX() { return 0; } |
| 1368 | int GetScrollPosY() { return 0; } |
| 1369 | |
| 1370 | void SetScrollX( int WXUNUSED(x) ) { } |
| 1371 | void SetScrollY( int WXUNUSED(y) ) { } |
| 1372 | |
| 1373 | void SetColumnWidth( int col, int width ) |
| 1374 | { SetColSize( col, width ); } |
| 1375 | |
| 1376 | int GetColumnWidth( int col ) |
| 1377 | { return GetColSize( col ); } |
| 1378 | |
| 1379 | void SetRowHeight( int row, int height ) |
| 1380 | { SetRowSize( row, height ); } |
| 1381 | |
| 1382 | // GetRowHeight() is below |
| 1383 | |
| 1384 | int GetViewHeight() // returned num whole rows visible |
| 1385 | { return 0; } |
| 1386 | |
| 1387 | int GetViewWidth() // returned num whole cols visible |
| 1388 | { return 0; } |
| 1389 | |
| 1390 | void SetLabelSize( int orientation, int sz ) |
| 1391 | { |
| 1392 | if ( orientation == wxHORIZONTAL ) |
| 1393 | SetColLabelSize( sz ); |
| 1394 | else |
| 1395 | SetRowLabelSize( sz ); |
| 1396 | } |
| 1397 | |
| 1398 | int GetLabelSize( int orientation ) |
| 1399 | { |
| 1400 | if ( orientation == wxHORIZONTAL ) |
| 1401 | return GetColLabelSize(); |
| 1402 | else |
| 1403 | return GetRowLabelSize(); |
| 1404 | } |
| 1405 | |
| 1406 | void SetLabelAlignment( int orientation, int align ) |
| 1407 | { |
| 1408 | if ( orientation == wxHORIZONTAL ) |
| 1409 | SetColLabelAlignment( align, -1 ); |
| 1410 | else |
| 1411 | SetRowLabelAlignment( align, -1 ); |
| 1412 | } |
| 1413 | |
| 1414 | int GetLabelAlignment( int orientation, int WXUNUSED(align) ) |
| 1415 | { |
| 1416 | int h, v; |
| 1417 | if ( orientation == wxHORIZONTAL ) |
| 1418 | { |
| 1419 | GetColLabelAlignment( &h, &v ); |
| 1420 | return h; |
| 1421 | } |
| 1422 | else |
| 1423 | { |
| 1424 | GetRowLabelAlignment( &h, &v ); |
| 1425 | return h; |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | void SetLabelValue( int orientation, const wxString& val, int pos ) |
| 1430 | { |
| 1431 | if ( orientation == wxHORIZONTAL ) |
| 1432 | SetColLabelValue( pos, val ); |
| 1433 | else |
| 1434 | SetRowLabelValue( pos, val ); |
| 1435 | } |
| 1436 | |
| 1437 | wxString GetLabelValue( int orientation, int pos) |
| 1438 | { |
| 1439 | if ( orientation == wxHORIZONTAL ) |
| 1440 | return GetColLabelValue( pos ); |
| 1441 | else |
| 1442 | return GetRowLabelValue( pos ); |
| 1443 | } |
| 1444 | |
| 1445 | wxFont GetCellTextFont() const |
| 1446 | { return m_defaultCellAttr->GetFont(); } |
| 1447 | |
| 1448 | wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const |
| 1449 | { return m_defaultCellAttr->GetFont(); } |
| 1450 | |
| 1451 | void SetCellTextFont(const wxFont& fnt) |
| 1452 | { SetDefaultCellFont( fnt ); } |
| 1453 | |
| 1454 | void SetCellTextFont(const wxFont& fnt, int row, int col) |
| 1455 | { SetCellFont( row, col, fnt ); } |
| 1456 | |
| 1457 | void SetCellTextColour(const wxColour& val, int row, int col) |
| 1458 | { SetCellTextColour( row, col, val ); } |
| 1459 | |
| 1460 | void SetCellTextColour(const wxColour& col) |
| 1461 | { SetDefaultCellTextColour( col ); } |
| 1462 | |
| 1463 | void SetCellBackgroundColour(const wxColour& col) |
| 1464 | { SetDefaultCellBackgroundColour( col ); } |
| 1465 | |
| 1466 | void SetCellBackgroundColour(const wxColour& colour, int row, int col) |
| 1467 | { SetCellBackgroundColour( row, col, colour ); } |
| 1468 | |
| 1469 | bool GetEditable() { return IsEditable(); } |
| 1470 | void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); } |
| 1471 | bool GetEditInPlace() { return IsCellEditControlEnabled(); } |
| 1472 | |
| 1473 | void SetEditInPlace(bool WXUNUSED(edit) = TRUE) { } |
| 1474 | |
| 1475 | void SetCellAlignment( int align, int row, int col) |
| 1476 | { SetCellAlignment(row, col, align, wxCENTER); } |
| 1477 | void SetCellAlignment( int WXUNUSED(align) ) {} |
| 1478 | void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col)) |
| 1479 | { } |
| 1480 | void SetDividerPen(const wxPen& WXUNUSED(pen)) { } |
| 1481 | wxPen& GetDividerPen() const; |
| 1482 | void OnActivate(bool WXUNUSED(active)) {} |
| 1483 | |
| 1484 | // ******** End of compatibility functions ********** |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | // ------ control IDs |
| 1489 | enum { wxGRID_CELLCTRL = 2000, |
| 1490 | wxGRID_TOPCTRL }; |
| 1491 | |
| 1492 | // ------ control types |
| 1493 | enum { wxGRID_TEXTCTRL = 2100, |
| 1494 | wxGRID_CHECKBOX, |
| 1495 | wxGRID_CHOICE, |
| 1496 | wxGRID_COMBOBOX }; |
| 1497 | |
| 1498 | // overridden wxWindow methods |
| 1499 | virtual void Fit(); |
| 1500 | |
| 1501 | protected: |
| 1502 | virtual wxSize DoGetBestSize() const; |
| 1503 | |
| 1504 | bool m_created; |
| 1505 | |
| 1506 | wxGridWindow *m_gridWin; |
| 1507 | wxGridRowLabelWindow *m_rowLabelWin; |
| 1508 | wxGridColLabelWindow *m_colLabelWin; |
| 1509 | wxGridCornerLabelWindow *m_cornerLabelWin; |
| 1510 | |
| 1511 | wxGridTableBase *m_table; |
| 1512 | bool m_ownTable; |
| 1513 | |
| 1514 | int m_left; |
| 1515 | int m_top; |
| 1516 | int m_right; |
| 1517 | int m_bottom; |
| 1518 | |
| 1519 | int m_numRows; |
| 1520 | int m_numCols; |
| 1521 | |
| 1522 | wxGridCellCoords m_currentCellCoords; |
| 1523 | |
| 1524 | wxGridCellCoords m_selectingTopLeft; |
| 1525 | wxGridCellCoords m_selectingBottomRight; |
| 1526 | wxGridCellCoords m_selectingKeyboard; |
| 1527 | wxGridSelection *m_selection; |
| 1528 | wxColour m_selectionBackground; |
| 1529 | wxColour m_selectionForeground; |
| 1530 | |
| 1531 | // NB: *never* access m_row/col arrays directly because they are created |
| 1532 | // on demand, *always* use accessor functions instead! |
| 1533 | |
| 1534 | // init the m_rowHeights/Bottoms arrays with default values |
| 1535 | void InitRowHeights(); |
| 1536 | |
| 1537 | int m_defaultRowHeight; |
| 1538 | wxArrayInt m_rowHeights; |
| 1539 | wxArrayInt m_rowBottoms; |
| 1540 | |
| 1541 | // init the m_colWidths/Rights arrays |
| 1542 | void InitColWidths(); |
| 1543 | |
| 1544 | int m_defaultColWidth; |
| 1545 | wxArrayInt m_colWidths; |
| 1546 | wxArrayInt m_colRights; |
| 1547 | |
| 1548 | // get the col/row coords |
| 1549 | int GetColWidth(int col) const; |
| 1550 | int GetColLeft(int col) const; |
| 1551 | int GetColRight(int col) const; |
| 1552 | |
| 1553 | // this function must be public for compatibility... |
| 1554 | public: |
| 1555 | int GetRowHeight(int row) const; |
| 1556 | protected: |
| 1557 | |
| 1558 | int GetRowTop(int row) const; |
| 1559 | int GetRowBottom(int row) const; |
| 1560 | |
| 1561 | int m_rowLabelWidth; |
| 1562 | int m_colLabelHeight; |
| 1563 | |
| 1564 | // the size of the margin left to the right and bottom of the cell area |
| 1565 | int m_extraWidth, |
| 1566 | m_extraHeight; |
| 1567 | |
| 1568 | wxColour m_labelBackgroundColour; |
| 1569 | wxColour m_labelTextColour; |
| 1570 | wxFont m_labelFont; |
| 1571 | |
| 1572 | int m_rowLabelHorizAlign; |
| 1573 | int m_rowLabelVertAlign; |
| 1574 | int m_colLabelHorizAlign; |
| 1575 | int m_colLabelVertAlign; |
| 1576 | |
| 1577 | bool m_defaultRowLabelValues; |
| 1578 | bool m_defaultColLabelValues; |
| 1579 | |
| 1580 | wxColour m_gridLineColour; |
| 1581 | bool m_gridLinesEnabled; |
| 1582 | |
| 1583 | // common part of AutoSizeColumn/Row() and GetBestSize() |
| 1584 | int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = TRUE); |
| 1585 | int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = TRUE); |
| 1586 | |
| 1587 | // common part of AutoSizeColumn/Row() |
| 1588 | void AutoSizeColOrRow(int n, bool setAsMin, bool column /* or row? */); |
| 1589 | |
| 1590 | // if a column has a minimal width, it will be the value for it in this |
| 1591 | // hash table |
| 1592 | wxHashTableLong m_colMinWidths, |
| 1593 | m_rowMinHeights; |
| 1594 | |
| 1595 | // get the minimal width of the given column/row |
| 1596 | int GetColMinimalWidth(int col) const; |
| 1597 | int GetRowMinimalHeight(int col) const; |
| 1598 | |
| 1599 | // do we have some place to store attributes in? |
| 1600 | bool CanHaveAttributes(); |
| 1601 | |
| 1602 | // returns the attribute we may modify in place: a new one if this cell |
| 1603 | // doesn't have any yet or the existing one if it does |
| 1604 | // |
| 1605 | // DecRef() must be called on the returned pointer, as usual |
| 1606 | wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const; |
| 1607 | |
| 1608 | // cell attribute cache (currently we only cache 1, may be will do |
| 1609 | // more/better later) |
| 1610 | struct CachedAttr |
| 1611 | { |
| 1612 | int row, col; |
| 1613 | wxGridCellAttr *attr; |
| 1614 | } m_attrCache; |
| 1615 | |
| 1616 | // invalidates the attribute cache |
| 1617 | void ClearAttrCache(); |
| 1618 | |
| 1619 | // adds an attribute to cache |
| 1620 | void CacheAttr(int row, int col, wxGridCellAttr *attr) const; |
| 1621 | |
| 1622 | // looks for an attr in cache, returns TRUE if found |
| 1623 | bool LookupAttr(int row, int col, wxGridCellAttr **attr) const; |
| 1624 | |
| 1625 | // looks for the attr in cache, if not found asks the table and caches the |
| 1626 | // result |
| 1627 | wxGridCellAttr *GetCellAttr(int row, int col) const; |
| 1628 | wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords ) |
| 1629 | { return GetCellAttr( coords.GetRow(), coords.GetCol() ); } |
| 1630 | |
| 1631 | // the default cell attr object for cells that don't have their own |
| 1632 | wxGridCellAttr* m_defaultCellAttr; |
| 1633 | |
| 1634 | |
| 1635 | wxGridCellCoordsArray m_cellsExposed; |
| 1636 | wxArrayInt m_rowsExposed; |
| 1637 | wxArrayInt m_colsExposed; |
| 1638 | wxArrayInt m_rowLabelsExposed; |
| 1639 | wxArrayInt m_colLabelsExposed; |
| 1640 | |
| 1641 | bool m_inOnKeyDown; |
| 1642 | int m_batchCount; |
| 1643 | |
| 1644 | |
| 1645 | wxGridTypeRegistry* m_typeRegistry; |
| 1646 | |
| 1647 | enum CursorMode |
| 1648 | { |
| 1649 | WXGRID_CURSOR_SELECT_CELL, |
| 1650 | WXGRID_CURSOR_RESIZE_ROW, |
| 1651 | WXGRID_CURSOR_RESIZE_COL, |
| 1652 | WXGRID_CURSOR_SELECT_ROW, |
| 1653 | WXGRID_CURSOR_SELECT_COL |
| 1654 | }; |
| 1655 | |
| 1656 | // this method not only sets m_cursorMode but also sets the correct cursor |
| 1657 | // for the given mode and, if captureMouse is not FALSE releases the mouse |
| 1658 | // if it was captured and captures it if it must be captured |
| 1659 | // |
| 1660 | // for this to work, you should always use it and not set m_cursorMode |
| 1661 | // directly! |
| 1662 | void ChangeCursorMode(CursorMode mode, |
| 1663 | wxWindow *win = (wxWindow *)NULL, |
| 1664 | bool captureMouse = TRUE); |
| 1665 | |
| 1666 | wxWindow *m_winCapture; // the window which captured the mouse |
| 1667 | CursorMode m_cursorMode; |
| 1668 | |
| 1669 | bool m_canDragRowSize; |
| 1670 | bool m_canDragColSize; |
| 1671 | bool m_canDragGridSize; |
| 1672 | int m_dragLastPos; |
| 1673 | int m_dragRowOrCol; |
| 1674 | bool m_isDragging; |
| 1675 | wxPoint m_startDragPos; |
| 1676 | |
| 1677 | bool m_waitForSlowClick; |
| 1678 | |
| 1679 | wxGridCellCoords m_selectionStart; |
| 1680 | |
| 1681 | wxCursor m_rowResizeCursor; |
| 1682 | wxCursor m_colResizeCursor; |
| 1683 | |
| 1684 | bool m_editable; // applies to whole grid |
| 1685 | bool m_cellEditCtrlEnabled; // is in-place edit currently shown? |
| 1686 | |
| 1687 | |
| 1688 | void Create(); |
| 1689 | void Init(); |
| 1690 | void CalcDimensions(); |
| 1691 | void CalcWindowSizes(); |
| 1692 | bool Redimension( wxGridTableMessage& ); |
| 1693 | |
| 1694 | |
| 1695 | bool SendEvent( const wxEventType, int row, int col, wxMouseEvent& ); |
| 1696 | bool SendEvent( const wxEventType, int row, int col ); |
| 1697 | bool SendEvent( const wxEventType type) |
| 1698 | { |
| 1699 | return SendEvent(type, |
| 1700 | m_currentCellCoords.GetRow(), |
| 1701 | m_currentCellCoords.GetCol()); |
| 1702 | } |
| 1703 | |
| 1704 | void OnPaint( wxPaintEvent& ); |
| 1705 | void OnSize( wxSizeEvent& ); |
| 1706 | void OnKeyDown( wxKeyEvent& ); |
| 1707 | void OnEraseBackground( wxEraseEvent& ); |
| 1708 | |
| 1709 | |
| 1710 | void SetCurrentCell( const wxGridCellCoords& coords ); |
| 1711 | void SetCurrentCell( int row, int col ) |
| 1712 | { SetCurrentCell( wxGridCellCoords(row, col) ); } |
| 1713 | |
| 1714 | |
| 1715 | // ------ functions to get/send data (see also public functions) |
| 1716 | // |
| 1717 | bool GetModelValues(); |
| 1718 | bool SetModelValues(); |
| 1719 | |
| 1720 | friend class wxGridSelection; |
| 1721 | |
| 1722 | DECLARE_DYNAMIC_CLASS( wxGrid ) |
| 1723 | DECLARE_EVENT_TABLE() |
| 1724 | }; |
| 1725 | |
| 1726 | // ---------------------------------------------------------------------------- |
| 1727 | // Grid event class and event types |
| 1728 | // ---------------------------------------------------------------------------- |
| 1729 | |
| 1730 | class WXDLLEXPORT wxGridEvent : public wxNotifyEvent |
| 1731 | { |
| 1732 | public: |
| 1733 | wxGridEvent() |
| 1734 | : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1), |
| 1735 | m_selecting(0), m_control(0), m_meta(0), m_shift(0), m_alt(0) |
| 1736 | { |
| 1737 | } |
| 1738 | |
| 1739 | wxGridEvent(int id, wxEventType type, wxObject* obj, |
| 1740 | int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE, |
| 1741 | bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE); |
| 1742 | |
| 1743 | virtual int GetRow() { return m_row; } |
| 1744 | virtual int GetCol() { return m_col; } |
| 1745 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } |
| 1746 | bool Selecting() { return m_selecting; } |
| 1747 | bool ControlDown() { return m_control; } |
| 1748 | bool MetaDown() { return m_meta; } |
| 1749 | bool ShiftDown() { return m_shift; } |
| 1750 | bool AltDown() { return m_alt; } |
| 1751 | |
| 1752 | protected: |
| 1753 | int m_row; |
| 1754 | int m_col; |
| 1755 | int m_x; |
| 1756 | int m_y; |
| 1757 | bool m_selecting; |
| 1758 | bool m_control; |
| 1759 | bool m_meta; |
| 1760 | bool m_shift; |
| 1761 | bool m_alt; |
| 1762 | |
| 1763 | DECLARE_DYNAMIC_CLASS(wxGridEvent) |
| 1764 | }; |
| 1765 | |
| 1766 | class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent |
| 1767 | { |
| 1768 | public: |
| 1769 | wxGridSizeEvent() |
| 1770 | : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1), |
| 1771 | m_control(0), m_meta(0), m_shift(0), m_alt(0) |
| 1772 | { |
| 1773 | } |
| 1774 | |
| 1775 | wxGridSizeEvent(int id, wxEventType type, wxObject* obj, |
| 1776 | int rowOrCol=-1, int x=-1, int y=-1, |
| 1777 | bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE); |
| 1778 | |
| 1779 | int GetRowOrCol() { return m_rowOrCol; } |
| 1780 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } |
| 1781 | bool ControlDown() { return m_control; } |
| 1782 | bool MetaDown() { return m_meta; } |
| 1783 | bool ShiftDown() { return m_shift; } |
| 1784 | bool AltDown() { return m_alt; } |
| 1785 | |
| 1786 | protected: |
| 1787 | int m_rowOrCol; |
| 1788 | int m_x; |
| 1789 | int m_y; |
| 1790 | bool m_control; |
| 1791 | bool m_meta; |
| 1792 | bool m_shift; |
| 1793 | bool m_alt; |
| 1794 | |
| 1795 | DECLARE_DYNAMIC_CLASS(wxGridSizeEvent) |
| 1796 | }; |
| 1797 | |
| 1798 | |
| 1799 | class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent |
| 1800 | { |
| 1801 | public: |
| 1802 | wxGridRangeSelectEvent() |
| 1803 | : wxNotifyEvent() |
| 1804 | { |
| 1805 | m_topLeft = wxGridNoCellCoords; |
| 1806 | m_bottomRight = wxGridNoCellCoords; |
| 1807 | m_selecting = FALSE; |
| 1808 | m_control = FALSE; |
| 1809 | m_meta = FALSE; |
| 1810 | m_shift = FALSE; |
| 1811 | m_alt = FALSE; |
| 1812 | } |
| 1813 | |
| 1814 | wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj, |
| 1815 | const wxGridCellCoords& topLeft, |
| 1816 | const wxGridCellCoords& bottomRight, |
| 1817 | bool sel = TRUE, |
| 1818 | bool control=FALSE, bool shift=FALSE, |
| 1819 | bool alt=FALSE, bool meta=FALSE); |
| 1820 | |
| 1821 | wxGridCellCoords GetTopLeftCoords() { return m_topLeft; } |
| 1822 | wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; } |
| 1823 | int GetTopRow() { return m_topLeft.GetRow(); } |
| 1824 | int GetBottomRow() { return m_bottomRight.GetRow(); } |
| 1825 | int GetLeftCol() { return m_topLeft.GetCol(); } |
| 1826 | int GetRightCol() { return m_bottomRight.GetCol(); } |
| 1827 | bool Selecting() { return m_selecting; } |
| 1828 | bool ControlDown() { return m_control; } |
| 1829 | bool MetaDown() { return m_meta; } |
| 1830 | bool ShiftDown() { return m_shift; } |
| 1831 | bool AltDown() { return m_alt; } |
| 1832 | |
| 1833 | protected: |
| 1834 | wxGridCellCoords m_topLeft; |
| 1835 | wxGridCellCoords m_bottomRight; |
| 1836 | bool m_selecting; |
| 1837 | bool m_control; |
| 1838 | bool m_meta; |
| 1839 | bool m_shift; |
| 1840 | bool m_alt; |
| 1841 | |
| 1842 | DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent) |
| 1843 | }; |
| 1844 | |
| 1845 | // TODO move to wx/event.h |
| 1846 | const wxEventType wxEVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580; |
| 1847 | const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581; |
| 1848 | const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582; |
| 1849 | const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583; |
| 1850 | const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584; |
| 1851 | const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585; |
| 1852 | const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586; |
| 1853 | const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587; |
| 1854 | const wxEventType wxEVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588; |
| 1855 | const wxEventType wxEVT_GRID_COL_SIZE = wxEVT_FIRST + 1589; |
| 1856 | const wxEventType wxEVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590; |
| 1857 | const wxEventType wxEVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591; |
| 1858 | const wxEventType wxEVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592; |
| 1859 | const wxEventType wxEVT_GRID_EDITOR_SHOWN = wxEVT_FIRST + 1593; |
| 1860 | const wxEventType wxEVT_GRID_EDITOR_HIDDEN = wxEVT_FIRST + 1594; |
| 1861 | |
| 1862 | |
| 1863 | typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&); |
| 1864 | typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&); |
| 1865 | typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&); |
| 1866 | |
| 1867 | #define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1868 | #define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1869 | #define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1870 | #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1871 | #define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1872 | #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1873 | #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1874 | #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1875 | #define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL }, |
| 1876 | #define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL }, |
| 1877 | #define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL }, |
| 1878 | #define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1879 | #define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1880 | #define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1881 | #define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1882 | |
| 1883 | |
| 1884 | #if 0 // TODO: implement these ? others ? |
| 1885 | |
| 1886 | const wxEventType wxEVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576; |
| 1887 | const wxEventType wxEVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577; |
| 1888 | const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578; |
| 1889 | |
| 1890 | #define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1891 | #define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1892 | #define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
| 1893 | |
| 1894 | #endif |
| 1895 | |
| 1896 | #endif // #ifndef __WXGRID_H__ |
| 1897 | |
| 1898 | #endif // ifndef wxUSE_NEW_GRID |