1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/generic/grid.h 3 // Purpose: wxGrid and related classes 4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn) 5 // Modified by: Santiago Palacios 6 // Created: 1/08/1999 7 // Copyright: (c) Michael Bedward 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_GENERIC_GRID_H_ 12 #define _WX_GENERIC_GRID_H_ 13 14 #include "wx/defs.h" 15 16 #if wxUSE_GRID 17 18 #include "wx/hashmap.h" 19 20 #include "wx/scrolwin.h" 21 22 #if wxUSE_STD_CONTAINERS_COMPATIBLY 23 #include <iterator> 24 #endif 25 26 // ---------------------------------------------------------------------------- 27 // constants 28 // ---------------------------------------------------------------------------- 29 30 extern WXDLLIMPEXP_DATA_CORE(const char) wxGridNameStr[]; 31 32 // Obsolete constants not used by wxWidgets itself any longer, preserved only 33 // for compatibility. 34 #define WXGRID_DEFAULT_NUMBER_ROWS 10 35 #define WXGRID_DEFAULT_NUMBER_COLS 10 36 #if defined(__WXMSW__) || defined(__WXGTK20__) 37 #define WXGRID_DEFAULT_ROW_HEIGHT 25 38 #else 39 #define WXGRID_DEFAULT_ROW_HEIGHT 30 40 #endif // __WXMSW__ 41 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16 42 43 // Various constants used in wxGrid code. 44 // 45 // Note that all the values are in DIPs, not pixels, i.e. you must use 46 // FromDIP() when using them in your code. 47 #define WXGRID_DEFAULT_COL_WIDTH 80 48 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32 49 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82 50 #define WXGRID_LABEL_EDGE_ZONE 2 51 #define WXGRID_MIN_ROW_HEIGHT 15 52 #define WXGRID_MIN_COL_WIDTH 15 53 54 // type names for grid table values 55 #define wxGRID_VALUE_STRING wxT("string") 56 #define wxGRID_VALUE_BOOL wxT("bool") 57 #define wxGRID_VALUE_NUMBER wxT("long") 58 #define wxGRID_VALUE_FLOAT wxT("double") 59 #define wxGRID_VALUE_CHOICE wxT("choice") 60 #define wxGRID_VALUE_DATE wxT("date") 61 62 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING 63 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER 64 65 // magic constant which tells (to some functions) to automatically calculate 66 // the appropriate size 67 #define wxGRID_AUTOSIZE (-1) 68 69 // many wxGrid methods work either with columns or rows, this enum is used for 70 // the parameter indicating which one should it be 71 enum wxGridDirection 72 { 73 wxGRID_COLUMN, 74 wxGRID_ROW 75 }; 76 77 // Flags used with wxGrid::Render() to select parts of the grid to draw. 78 enum wxGridRenderStyle 79 { 80 wxGRID_DRAW_ROWS_HEADER = 0x001, 81 wxGRID_DRAW_COLS_HEADER = 0x002, 82 wxGRID_DRAW_CELL_LINES = 0x004, 83 wxGRID_DRAW_BOX_RECT = 0x008, 84 wxGRID_DRAW_SELECTION = 0x010, 85 wxGRID_DRAW_DEFAULT = wxGRID_DRAW_ROWS_HEADER | 86 wxGRID_DRAW_COLS_HEADER | 87 wxGRID_DRAW_CELL_LINES | 88 wxGRID_DRAW_BOX_RECT 89 }; 90 91 // ---------------------------------------------------------------------------- 92 // forward declarations 93 // ---------------------------------------------------------------------------- 94 95 class WXDLLIMPEXP_FWD_CORE wxGrid; 96 class WXDLLIMPEXP_FWD_CORE wxGridCellAttr; 97 class WXDLLIMPEXP_FWD_CORE wxGridCellAttrProviderData; 98 class WXDLLIMPEXP_FWD_CORE wxGridColLabelWindow; 99 class WXDLLIMPEXP_FWD_CORE wxGridCornerLabelWindow; 100 class WXDLLIMPEXP_FWD_CORE wxGridEvent; 101 class WXDLLIMPEXP_FWD_CORE wxGridRowLabelWindow; 102 class WXDLLIMPEXP_FWD_CORE wxGridWindow; 103 class WXDLLIMPEXP_FWD_CORE wxGridTypeRegistry; 104 class WXDLLIMPEXP_FWD_CORE wxGridSelection; 105 106 class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl; 107 class WXDLLIMPEXP_FWD_CORE wxCheckBox; 108 class WXDLLIMPEXP_FWD_CORE wxComboBox; 109 class WXDLLIMPEXP_FWD_CORE wxTextCtrl; 110 #if wxUSE_SPINCTRL 111 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl; 112 #endif 113 #if wxUSE_DATEPICKCTRL 114 class WXDLLIMPEXP_FWD_CORE wxDatePickerCtrl; 115 #endif 116 117 class wxGridFixedIndicesSet; 118 119 class wxGridOperations; 120 class wxGridRowOperations; 121 class wxGridColumnOperations; 122 class wxGridDirectionOperations; 123 124 125 // ---------------------------------------------------------------------------- 126 // macros 127 // ---------------------------------------------------------------------------- 128 129 #define wxSafeIncRef(p) if ( p ) (p)->IncRef() 130 #define wxSafeDecRef(p) if ( p ) (p)->DecRef() 131 132 // ---------------------------------------------------------------------------- 133 // wxGridCellWorker: common base class for wxGridCellRenderer and 134 // wxGridCellEditor 135 // 136 // NB: this is more an implementation convenience than a design issue, so this 137 // class is not documented and is not public at all 138 // ---------------------------------------------------------------------------- 139 140 class WXDLLIMPEXP_CORE wxGridCellWorker : public wxClientDataContainer, public wxRefCounter 141 { 142 public: wxGridCellWorker()143 wxGridCellWorker() { } 144 145 // interpret renderer parameters: arbitrary string whose interpretation is 146 // left to the derived classes 147 virtual void SetParameters(const wxString& params); 148 149 protected: 150 // virtual dtor for any base class - private because only DecRef() can 151 // delete us 152 virtual ~wxGridCellWorker(); 153 154 private: 155 // suppress the stupid gcc warning about the class having private dtor and 156 // no friends 157 friend class wxGridCellWorkerDummyFriend; 158 }; 159 160 // ---------------------------------------------------------------------------- 161 // wxGridCellRenderer: this class is responsible for actually drawing the cell 162 // in the grid. You may pass it to the wxGridCellAttr (below) to change the 163 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the 164 // view of all cells. This is an ABC, you will normally use one of the 165 // predefined derived classes or derive your own class from it. 166 // ---------------------------------------------------------------------------- 167 168 class WXDLLIMPEXP_CORE wxGridCellRenderer : public wxGridCellWorker 169 { 170 public: 171 // draw the given cell on the provided DC inside the given rectangle 172 // using the style specified by the attribute and the default or selected 173 // state corresponding to the isSelected value. 174 // 175 // this pure virtual function has a default implementation which will 176 // prepare the DC using the given attribute: it will draw the rectangle 177 // with the bg colour from attr and set the text colour and font 178 virtual void Draw(wxGrid& grid, 179 wxGridCellAttr& attr, 180 wxDC& dc, 181 const wxRect& rect, 182 int row, int col, 183 bool isSelected) = 0; 184 185 // get the preferred size of the cell for its contents 186 virtual wxSize GetBestSize(wxGrid& grid, 187 wxGridCellAttr& attr, 188 wxDC& dc, 189 int row, int col) = 0; 190 191 // Get the preferred height for a given width. Override this method if the 192 // renderer computes height as function of its width, as is the case of the 193 // standard wxGridCellAutoWrapStringRenderer, for example. 194 // and vice versa GetBestHeight(wxGrid & grid,wxGridCellAttr & attr,wxDC & dc,int row,int col,int WXUNUSED (width))195 virtual int GetBestHeight(wxGrid& grid, 196 wxGridCellAttr& attr, 197 wxDC& dc, 198 int row, int col, 199 int WXUNUSED(width)) 200 { 201 return GetBestSize(grid, attr, dc, row, col).GetHeight(); 202 } 203 204 // Get the preferred width for a given height, this is the symmetric 205 // version of GetBestHeight(). GetBestWidth(wxGrid & grid,wxGridCellAttr & attr,wxDC & dc,int row,int col,int WXUNUSED (height))206 virtual int GetBestWidth(wxGrid& grid, 207 wxGridCellAttr& attr, 208 wxDC& dc, 209 int row, int col, 210 int WXUNUSED(height)) 211 { 212 return GetBestSize(grid, attr, dc, row, col).GetWidth(); 213 } 214 215 216 // Unlike GetBestSize(), this functions is optional: it is used when 217 // auto-sizing columns to determine the best width without iterating over 218 // all cells in this column, if possible. 219 // 220 // If it isn't, return wxDefaultSize as the base class version does by 221 // default. GetMaxBestSize(wxGrid & WXUNUSED (grid),wxGridCellAttr & WXUNUSED (attr),wxDC & WXUNUSED (dc))222 virtual wxSize GetMaxBestSize(wxGrid& WXUNUSED(grid), 223 wxGridCellAttr& WXUNUSED(attr), 224 wxDC& WXUNUSED(dc)) 225 { 226 return wxDefaultSize; 227 } 228 229 // create a new object which is the copy of this one 230 virtual wxGridCellRenderer *Clone() const = 0; 231 232 protected: 233 // set the text colours before drawing 234 void SetTextColoursAndFont(const wxGrid& grid, 235 const wxGridCellAttr& attr, 236 wxDC& dc, 237 bool isSelected); 238 }; 239 240 // Smart pointer to wxGridCellRenderer, calling DecRef() on it automatically. 241 typedef wxObjectDataPtr<wxGridCellRenderer> wxGridCellRendererPtr; 242 243 244 // ---------------------------------------------------------------------------- 245 // Helper classes used by wxGridCellEditor::TryActivate() and DoActivate(). 246 // ---------------------------------------------------------------------------- 247 248 // This class represents a source of cell activation, which may be either a 249 // user event (mouse or keyboard) or the program itself. 250 // 251 // Note that objects of this class are supposed to be ephemeral and so store 252 // pointers to the events specified when creating them, which are supposed to 253 // have life-time greater than that of the objects of this class. 254 class wxGridActivationSource 255 { 256 public: 257 enum Origin 258 { 259 Program, 260 Key, 261 Mouse 262 }; 263 264 // Factory functions, only used by the library itself. FromProgram()265 static wxGridActivationSource FromProgram() 266 { 267 return wxGridActivationSource(Program, NULL); 268 } 269 From(const wxKeyEvent & event)270 static wxGridActivationSource From(const wxKeyEvent& event) 271 { 272 return wxGridActivationSource(Key, &event); 273 } 274 From(const wxMouseEvent & event)275 static wxGridActivationSource From(const wxMouseEvent& event) 276 { 277 return wxGridActivationSource(Mouse, &event); 278 } 279 280 // Accessors allowing to retrieve information about the source. 281 282 // Can be called for any object. GetOrigin()283 Origin GetOrigin() const { return m_origin; } 284 285 // Can be called for objects with Key origin only. GetKeyEvent()286 const wxKeyEvent& GetKeyEvent() const 287 { 288 wxASSERT( m_origin == Key ); 289 290 return *static_cast<const wxKeyEvent*>(m_event); 291 } 292 293 // Can be called for objects with Mouse origin only. GetMouseEvent()294 const wxMouseEvent& GetMouseEvent() const 295 { 296 wxASSERT( m_origin == Mouse ); 297 298 return *static_cast<const wxMouseEvent*>(m_event); 299 } 300 301 private: wxGridActivationSource(Origin origin,const wxEvent * event)302 wxGridActivationSource(Origin origin, const wxEvent* event) 303 : m_origin(origin), 304 m_event(event) 305 { 306 } 307 308 const Origin m_origin; 309 const wxEvent* const m_event; 310 }; 311 312 // This class represents the result of TryActivate(), which may be either 313 // absence of any action (if activating wouldn't change the value anyhow), 314 // attempt to change the value to the specified one or just start normal 315 // editing, which is the default for the editors not supporting activation. 316 class wxGridActivationResult 317 { 318 public: 319 enum Action 320 { 321 Ignore, 322 Change, 323 ShowEditor 324 }; 325 326 // Factory functions, only used by the library itself. DoNothing()327 static wxGridActivationResult DoNothing() 328 { 329 return wxGridActivationResult(Ignore); 330 } 331 DoChange(const wxString & newval)332 static wxGridActivationResult DoChange(const wxString& newval) 333 { 334 return wxGridActivationResult(Change, newval); 335 } 336 DoEdit()337 static wxGridActivationResult DoEdit() 338 { 339 return wxGridActivationResult(ShowEditor); 340 } 341 342 // Accessors allowing to retrieve information about the result. 343 344 // Can be called for any object. GetAction()345 Action GetAction() const { return m_action; } 346 347 // Can be called for objects with Change action type only. GetNewValue()348 const wxString& GetNewValue() const 349 { 350 wxASSERT( m_action == Change ); 351 352 return m_newval; 353 } 354 355 private: 356 explicit 357 wxGridActivationResult(Action action, const wxString& newval = wxString()) m_action(action)358 : m_action(action), 359 m_newval(newval) 360 { 361 } 362 363 const Action m_action; 364 const wxString m_newval; 365 }; 366 367 // ---------------------------------------------------------------------------- 368 // wxGridCellEditor: This class is responsible for providing and manipulating 369 // the in-place edit controls for the grid. Instances of wxGridCellEditor 370 // (actually, instances of derived classes since it is an ABC) can be 371 // associated with the cell attributes for individual cells, rows, columns, or 372 // even for the entire grid. 373 // ---------------------------------------------------------------------------- 374 375 class WXDLLIMPEXP_CORE wxGridCellEditor : public wxGridCellWorker 376 { 377 public: 378 wxGridCellEditor(); 379 IsCreated()380 bool IsCreated() const { return m_control != NULL; } 381 GetWindow()382 wxWindow* GetWindow() const { return m_control; } SetWindow(wxWindow * window)383 void SetWindow(wxWindow* window) { m_control = window; } 384 GetCellAttr()385 wxGridCellAttr* GetCellAttr() const { return m_attr; } SetCellAttr(wxGridCellAttr * attr)386 void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; } 387 388 // Creates the actual edit control 389 virtual void Create(wxWindow* parent, 390 wxWindowID id, 391 wxEvtHandler* evtHandler) = 0; 392 393 // Size and position the edit control 394 virtual void SetSize(const wxRect& rect); 395 396 // Show or hide the edit control, use the specified attributes to set 397 // colours/fonts for it 398 virtual void Show(bool show, wxGridCellAttr *attr = NULL); 399 400 // Draws the part of the cell not occupied by the control: the base class 401 // version just fills it with background colour from the attribute 402 virtual void PaintBackground(wxDC& dc, 403 const wxRect& rectCell, 404 const wxGridCellAttr& attr); 405 406 407 // The methods called by wxGrid when a cell is edited: first BeginEdit() is 408 // called, then EndEdit() is and if it returns true and if the change is 409 // not vetoed by a user-defined event handler, finally ApplyEdit() is called 410 411 // Fetch the value from the table and prepare the edit control 412 // to begin editing. Set the focus to the edit control. 413 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0; 414 415 // Returns false if nothing changed, otherwise returns true and return the 416 // new value in its string form in the newval output parameter. 417 // 418 // This should also store the new value in its real type internally so that 419 // it could be used by ApplyEdit() but it must not modify the grid as the 420 // change could still be vetoed. 421 virtual bool EndEdit(int row, int col, const wxGrid *grid, 422 const wxString& oldval, wxString *newval) = 0; 423 424 // Complete the editing of the current cell by storing the value saved by 425 // the previous call to EndEdit() in the grid 426 virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0; 427 428 429 // Reset the value in the control back to its starting value 430 virtual void Reset() = 0; 431 432 // return true to allow the given key to start editing: the base class 433 // version only checks that the event has no modifiers. The derived 434 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in 435 // their IsAcceptedKey() implementation, although, of course, it is not a 436 // mandatory requirement. 437 // 438 // NB: if the key is F2 (special), editing will always start and this 439 // method will not be called at all (but StartingKey() will) 440 virtual bool IsAcceptedKey(wxKeyEvent& event); 441 442 // If the editor is enabled by pressing keys on the grid, this will be 443 // called to let the editor do something about that first key if desired 444 virtual void StartingKey(wxKeyEvent& event); 445 446 // if the editor is enabled by clicking on the cell, this method will be 447 // called 448 virtual void StartingClick(); 449 450 // Some types of controls on some platforms may need some help 451 // with the Return key. 452 virtual void HandleReturn(wxKeyEvent& event); 453 454 // Final cleanup 455 virtual void Destroy(); 456 457 // create a new object which is the copy of this one 458 virtual wxGridCellEditor *Clone() const = 0; 459 460 // added GetValue so we can get the value which is in the control 461 virtual wxString GetValue() const = 0; 462 463 464 // These functions exist only for backward compatibility, use Get and 465 // SetWindow() instead in the new code. GetControl()466 wxControl* GetControl() { return wxDynamicCast(m_control, wxControl); } SetControl(wxControl * control)467 void SetControl(wxControl* control) { m_control = control; } 468 469 470 // Support for "activatable" editors: those change the value of the cell 471 // immediately, instead of creating an editor control and waiting for user 472 // input. 473 // 474 // See wxGridCellBoolEditor for an example of such editor. 475 476 // Override this function to return "Change" activation result from it to 477 // show that the editor supports activation. DoActivate() will be called if 478 // the cell changing event is not vetoed. 479 virtual 480 wxGridActivationResult TryActivate(int WXUNUSED (row),int WXUNUSED (col),wxGrid * WXUNUSED (grid),const wxGridActivationSource & WXUNUSED (actSource))481 TryActivate(int WXUNUSED(row), int WXUNUSED(col), 482 wxGrid* WXUNUSED(grid), 483 const wxGridActivationSource& WXUNUSED(actSource)) 484 { 485 return wxGridActivationResult::DoEdit(); 486 } 487 488 virtual 489 void DoActivate(int WXUNUSED (row),int WXUNUSED (col),wxGrid * WXUNUSED (grid))490 DoActivate(int WXUNUSED(row), int WXUNUSED(col), wxGrid* WXUNUSED(grid)) 491 { 492 wxFAIL_MSG( "Must be overridden if TryActivate() is overridden" ); 493 } 494 495 protected: 496 // the dtor is private because only DecRef() can delete us 497 virtual ~wxGridCellEditor(); 498 499 // Helper for the derived classes positioning the control according to the 500 // attribute alignment if the desired control size is smaller than the cell 501 // size, or centering it vertically if its size is bigger: this looks like 502 // the best compromise when the editor control doesn't fit into the cell. 503 void DoPositionEditor(const wxSize& size, 504 const wxRect& rectCell, 505 int hAlign = wxALIGN_LEFT, 506 int vAlign = wxALIGN_CENTRE_VERTICAL); 507 508 509 // the actual window we show on screen (this variable should actually be 510 // named m_window, but m_control is kept for backward compatibility) 511 wxWindow* m_control; 512 513 // a temporary pointer to the attribute being edited 514 wxGridCellAttr* m_attr; 515 516 // if we change the colours/font of the control from the default ones, we 517 // must restore the default later and we save them here between calls to 518 // Show(true) and Show(false) 519 wxColour m_colFgOld, 520 m_colBgOld; 521 wxFont m_fontOld; 522 523 // suppress the stupid gcc warning about the class having private dtor and 524 // no friends 525 friend class wxGridCellEditorDummyFriend; 526 527 wxDECLARE_NO_COPY_CLASS(wxGridCellEditor); 528 }; 529 530 // Smart pointer to wxGridCellEditor, calling DecRef() on it automatically. 531 typedef wxObjectDataPtr<wxGridCellEditor> wxGridCellEditorPtr; 532 533 // Base class for editors that can be only activated and not edited normally. 534 class wxGridCellActivatableEditor : public wxGridCellEditor 535 { 536 public: 537 // In this class these methods must be overridden. 538 virtual wxGridActivationResult 539 TryActivate(int row, int col, wxGrid* grid, 540 const wxGridActivationSource& actSource) wxOVERRIDE = 0; 541 virtual void DoActivate(int row, int col, wxGrid* grid) wxOVERRIDE = 0; 542 543 // All the other methods that normally must be implemented in an editor are 544 // defined as just stubs below, as they should be never called. 545 Create(wxWindow *,wxWindowID,wxEvtHandler *)546 virtual void Create(wxWindow*, wxWindowID, wxEvtHandler*) wxOVERRIDE 547 { wxFAIL; } BeginEdit(int,int,wxGrid *)548 virtual void BeginEdit(int, int, wxGrid*) wxOVERRIDE 549 { wxFAIL; } EndEdit(int,int,const wxGrid *,const wxString &,wxString *)550 virtual bool EndEdit(int, int, const wxGrid*, 551 const wxString&, wxString*) wxOVERRIDE 552 { wxFAIL; return false; } ApplyEdit(int,int,wxGrid *)553 virtual void ApplyEdit(int, int, wxGrid*) wxOVERRIDE 554 { wxFAIL; } Reset()555 virtual void Reset() wxOVERRIDE 556 { wxFAIL; } GetValue()557 virtual wxString GetValue() const wxOVERRIDE 558 { wxFAIL; return wxString(); } 559 }; 560 561 // ---------------------------------------------------------------------------- 562 // wxGridHeaderRenderer and company: like wxGridCellRenderer but for headers 563 // ---------------------------------------------------------------------------- 564 565 // Base class for header cells renderers. 566 class WXDLLIMPEXP_CORE wxGridHeaderLabelsRenderer 567 { 568 public: ~wxGridHeaderLabelsRenderer()569 virtual ~wxGridHeaderLabelsRenderer() {} 570 571 // Draw the border around cell window. 572 virtual void DrawBorder(const wxGrid& grid, 573 wxDC& dc, 574 wxRect& rect) const = 0; 575 576 // Draw header cell label 577 virtual void DrawLabel(const wxGrid& grid, 578 wxDC& dc, 579 const wxString& value, 580 const wxRect& rect, 581 int horizAlign, 582 int vertAlign, 583 int textOrientation) const; 584 }; 585 586 // Currently the row/column/corner renders don't need any methods other than 587 // those already in wxGridHeaderLabelsRenderer but still define separate classes 588 // for them for future extensions and also for better type safety (i.e. to 589 // avoid inadvertently using a column header renderer for the row headers) 590 class WXDLLIMPEXP_CORE wxGridRowHeaderRenderer 591 : public wxGridHeaderLabelsRenderer 592 { 593 }; 594 595 class WXDLLIMPEXP_CORE wxGridColumnHeaderRenderer 596 : public wxGridHeaderLabelsRenderer 597 { 598 }; 599 600 class WXDLLIMPEXP_CORE wxGridCornerHeaderRenderer 601 : public wxGridHeaderLabelsRenderer 602 { 603 }; 604 605 // Also define the default renderers which are used by wxGridCellAttrProvider 606 // by default 607 class WXDLLIMPEXP_CORE wxGridRowHeaderRendererDefault 608 : public wxGridRowHeaderRenderer 609 { 610 public: 611 virtual void DrawBorder(const wxGrid& grid, 612 wxDC& dc, 613 wxRect& rect) const wxOVERRIDE; 614 }; 615 616 // Column header cells renderers 617 class WXDLLIMPEXP_CORE wxGridColumnHeaderRendererDefault 618 : public wxGridColumnHeaderRenderer 619 { 620 public: 621 virtual void DrawBorder(const wxGrid& grid, 622 wxDC& dc, 623 wxRect& rect) const wxOVERRIDE; 624 }; 625 626 // Header corner renderer 627 class WXDLLIMPEXP_CORE wxGridCornerHeaderRendererDefault 628 : public wxGridCornerHeaderRenderer 629 { 630 public: 631 virtual void DrawBorder(const wxGrid& grid, 632 wxDC& dc, 633 wxRect& rect) const wxOVERRIDE; 634 }; 635 636 // ---------------------------------------------------------------------------- 637 // Helper class used to define What should happen if the cell contents doesn't 638 // fit into its allotted space. 639 // ---------------------------------------------------------------------------- 640 641 class wxGridFitMode 642 { 643 public: 644 // Default ctor creates an object not specifying any particular behaviour. wxGridFitMode()645 wxGridFitMode() : m_mode(Mode_Unset) {} 646 647 // Static methods allowing to create objects actually specifying behaviour. Clip()648 static wxGridFitMode Clip() { return wxGridFitMode(Mode_Clip); } Overflow()649 static wxGridFitMode Overflow() { return wxGridFitMode(Mode_Overflow); } 650 static wxGridFitMode Ellipsize(wxEllipsizeMode ellipsize = wxELLIPSIZE_END) 651 { 652 // This cast works because the enum elements are the same, see below. 653 return wxGridFitMode(static_cast<Mode>(ellipsize)); 654 } 655 656 // Accessors. IsSpecified()657 bool IsSpecified() const { return m_mode != Mode_Unset; } IsClip()658 bool IsClip() const { return m_mode == Mode_Clip; } IsOverflow()659 bool IsOverflow() const { return m_mode == Mode_Overflow; } 660 GetEllipsizeMode()661 wxEllipsizeMode GetEllipsizeMode() const 662 { 663 switch ( m_mode ) 664 { 665 case Mode_Unset: 666 case Mode_EllipsizeStart: 667 case Mode_EllipsizeMiddle: 668 case Mode_EllipsizeEnd: 669 return static_cast<wxEllipsizeMode>(m_mode); 670 671 case Mode_Overflow: 672 case Mode_Clip: 673 break; 674 } 675 676 return wxELLIPSIZE_NONE; 677 } 678 679 // This one is used in the implementation only. FromOverflowFlag(bool allow)680 static wxGridFitMode FromOverflowFlag(bool allow) 681 { return allow ? Overflow() : Clip(); } 682 683 private: 684 enum Mode 685 { 686 // This is a hack to save space: the first 4 elements of this enum are 687 // the same as those of wxEllipsizeMode. 688 Mode_Unset = wxELLIPSIZE_NONE, 689 Mode_EllipsizeStart = wxELLIPSIZE_START, 690 Mode_EllipsizeMiddle = wxELLIPSIZE_MIDDLE, 691 Mode_EllipsizeEnd = wxELLIPSIZE_END, 692 Mode_Overflow, 693 Mode_Clip 694 }; 695 wxGridFitMode(Mode mode)696 explicit wxGridFitMode(Mode mode) : m_mode(mode) {} 697 698 Mode m_mode; 699 }; 700 701 // ---------------------------------------------------------------------------- 702 // wxGridCellAttr: this class can be used to alter the cells appearance in 703 // the grid by changing their colour/font/... from default. An object of this 704 // class may be returned by wxGridTable::GetAttr(). 705 // ---------------------------------------------------------------------------- 706 707 class WXDLLIMPEXP_CORE wxGridCellAttr : public wxClientDataContainer, public wxRefCounter 708 { 709 public: 710 enum wxAttrKind 711 { 712 Any, 713 Default, 714 Cell, 715 Row, 716 Col, 717 Merged 718 }; 719 720 // default ctor 721 explicit wxGridCellAttr(wxGridCellAttr *attrDefault = NULL) 722 { 723 Init(attrDefault); 724 725 SetAlignment(wxALIGN_INVALID, wxALIGN_INVALID); 726 } 727 728 // ctor setting the most common attributes wxGridCellAttr(const wxColour & colText,const wxColour & colBack,const wxFont & font,int hAlign,int vAlign)729 wxGridCellAttr(const wxColour& colText, 730 const wxColour& colBack, 731 const wxFont& font, 732 int hAlign, 733 int vAlign) 734 : m_colText(colText), m_colBack(colBack), m_font(font) 735 { 736 Init(); 737 SetAlignment(hAlign, vAlign); 738 } 739 740 // creates a new copy of this object 741 wxGridCellAttr *Clone() const; 742 void MergeWith(wxGridCellAttr *mergefrom); 743 744 // setters SetTextColour(const wxColour & colText)745 void SetTextColour(const wxColour& colText) { m_colText = colText; } SetBackgroundColour(const wxColour & colBack)746 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } SetFont(const wxFont & font)747 void SetFont(const wxFont& font) { m_font = font; } SetAlignment(int hAlign,int vAlign)748 void SetAlignment(int hAlign, int vAlign) 749 { 750 m_hAlign = hAlign; 751 m_vAlign = vAlign; 752 } 753 void SetSize(int num_rows, int num_cols); SetFitMode(wxGridFitMode fitMode)754 void SetFitMode(wxGridFitMode fitMode) { m_fitMode = fitMode; } 755 void SetOverflow(bool allow = true) 756 { SetFitMode(wxGridFitMode::FromOverflowFlag(allow)); } 757 void SetReadOnly(bool isReadOnly = true) 758 { m_isReadOnly = isReadOnly ? ReadOnly : ReadWrite; } 759 760 // takes ownership of the pointer SetRenderer(wxGridCellRenderer * renderer)761 void SetRenderer(wxGridCellRenderer *renderer) 762 { wxSafeDecRef(m_renderer); m_renderer = renderer; } SetEditor(wxGridCellEditor * editor)763 void SetEditor(wxGridCellEditor* editor) 764 { wxSafeDecRef(m_editor); m_editor = editor; } 765 SetKind(wxAttrKind kind)766 void SetKind(wxAttrKind kind) { m_attrkind = kind; } 767 768 // accessors HasTextColour()769 bool HasTextColour() const { return m_colText.IsOk(); } HasBackgroundColour()770 bool HasBackgroundColour() const { return m_colBack.IsOk(); } HasFont()771 bool HasFont() const { return m_font.IsOk(); } HasAlignment()772 bool HasAlignment() const 773 { 774 return m_hAlign != wxALIGN_INVALID || m_vAlign != wxALIGN_INVALID; 775 } HasRenderer()776 bool HasRenderer() const { return m_renderer != NULL; } HasEditor()777 bool HasEditor() const { return m_editor != NULL; } HasReadWriteMode()778 bool HasReadWriteMode() const { return m_isReadOnly != Unset; } HasOverflowMode()779 bool HasOverflowMode() const { return m_fitMode.IsSpecified(); } HasSize()780 bool HasSize() const { return m_sizeRows != 1 || m_sizeCols != 1; } 781 782 const wxColour& GetTextColour() const; 783 const wxColour& GetBackgroundColour() const; 784 const wxFont& GetFont() const; 785 void GetAlignment(int *hAlign, int *vAlign) const; 786 787 // unlike GetAlignment() which always overwrites its output arguments with 788 // the alignment values to use, falling back on default alignment if this 789 // attribute doesn't have any, this function will preserve the values of 790 // parameters on entry if the corresponding alignment is not set in this 791 // attribute meaning that they can be initialized to default alignment (and 792 // also that they must be initialized, unlike with GetAlignment()) 793 void GetNonDefaultAlignment(int *hAlign, int *vAlign) const; 794 795 void GetSize(int *num_rows, int *num_cols) const; 796 wxGridFitMode GetFitMode() const; GetOverflow()797 bool GetOverflow() const { return GetFitMode().IsOverflow(); } 798 // whether the cell will draw the overflowed text to neighbour cells 799 // currently only left aligned cells can overflow 800 bool CanOverflow() const; 801 802 wxGridCellRenderer *GetRenderer(const wxGrid* grid, int row, int col) const; GetRendererPtr(const wxGrid * grid,int row,int col)803 wxGridCellRendererPtr GetRendererPtr(const wxGrid* grid, int row, int col) const 804 { 805 return wxGridCellRendererPtr(GetRenderer(grid, row, col)); 806 } 807 808 wxGridCellEditor *GetEditor(const wxGrid* grid, int row, int col) const; GetEditorPtr(const wxGrid * grid,int row,int col)809 wxGridCellEditorPtr GetEditorPtr(const wxGrid* grid, int row, int col) const 810 { 811 return wxGridCellEditorPtr(GetEditor(grid, row, col)); 812 } 813 IsReadOnly()814 bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; } 815 GetKind()816 wxAttrKind GetKind() { return m_attrkind; } 817 SetDefAttr(wxGridCellAttr * defAttr)818 void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; } 819 820 protected: 821 // the dtor is private because only DecRef() can delete us ~wxGridCellAttr()822 virtual ~wxGridCellAttr() 823 { 824 wxSafeDecRef(m_renderer); 825 wxSafeDecRef(m_editor); 826 } 827 828 private: 829 enum wxAttrReadMode 830 { 831 Unset = -1, 832 ReadWrite, 833 ReadOnly 834 }; 835 836 // the common part of all ctors 837 void Init(wxGridCellAttr *attrDefault = NULL); 838 839 840 wxColour m_colText, 841 m_colBack; 842 wxFont m_font; 843 int m_hAlign, 844 m_vAlign; 845 int m_sizeRows, 846 m_sizeCols; 847 848 wxGridFitMode m_fitMode; 849 850 wxGridCellRenderer* m_renderer; 851 wxGridCellEditor* m_editor; 852 wxGridCellAttr* m_defGridAttr; 853 854 wxAttrReadMode m_isReadOnly; 855 856 wxAttrKind m_attrkind; 857 858 // use Clone() instead 859 wxDECLARE_NO_COPY_CLASS(wxGridCellAttr); 860 861 // suppress the stupid gcc warning about the class having private dtor and 862 // no friends 863 friend class wxGridCellAttrDummyFriend; 864 }; 865 866 // Smart pointer to wxGridCellAttr, calling DecRef() on it automatically. 867 typedef wxObjectDataPtr<wxGridCellAttr> wxGridCellAttrPtr; 868 869 // ---------------------------------------------------------------------------- 870 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the 871 // cell attributes. 872 // ---------------------------------------------------------------------------- 873 874 // implementation note: we separate it from wxGridTableBase because we wish to 875 // avoid deriving a new table class if possible, and sometimes it will be 876 // enough to just derive another wxGridCellAttrProvider instead 877 // 878 // the default implementation is reasonably efficient for the generic case, 879 // but you might still wish to implement your own for some specific situations 880 // if you have performance problems with the stock one 881 class WXDLLIMPEXP_CORE wxGridCellAttrProvider : public wxClientDataContainer 882 { 883 public: 884 wxGridCellAttrProvider(); 885 virtual ~wxGridCellAttrProvider(); 886 887 // DecRef() must be called on the returned pointer 888 virtual wxGridCellAttr *GetAttr(int row, int col, 889 wxGridCellAttr::wxAttrKind kind ) const; 890 891 // Helper returning smart pointer calling DecRef() automatically. GetAttrPtr(int row,int col,wxGridCellAttr::wxAttrKind kind)892 wxGridCellAttrPtr GetAttrPtr(int row, int col, 893 wxGridCellAttr::wxAttrKind kind ) const 894 { 895 return wxGridCellAttrPtr(GetAttr(row, col, kind)); 896 } 897 898 // all these functions take ownership of the pointer, don't call DecRef() 899 // on it 900 virtual void SetAttr(wxGridCellAttr *attr, int row, int col); 901 virtual void SetRowAttr(wxGridCellAttr *attr, int row); 902 virtual void SetColAttr(wxGridCellAttr *attr, int col); 903 904 // these functions must be called whenever some rows/cols are deleted 905 // because the internal data must be updated then 906 void UpdateAttrRows( size_t pos, int numRows ); 907 void UpdateAttrCols( size_t pos, int numCols ); 908 909 910 // get renderers for the given row/column header label and the corner 911 // window: unlike cell renderers, these objects are not reference counted 912 // and are never NULL so they are returned by reference 913 virtual const wxGridColumnHeaderRenderer& GetColumnHeaderRenderer(int col); 914 virtual const wxGridRowHeaderRenderer& GetRowHeaderRenderer(int row); 915 virtual const wxGridCornerHeaderRenderer& GetCornerRenderer(); 916 917 private: 918 void InitData(); 919 920 wxGridCellAttrProviderData *m_data; 921 922 wxDECLARE_NO_COPY_CLASS(wxGridCellAttrProvider); 923 }; 924 925 // ---------------------------------------------------------------------------- 926 // wxGridCellCoords: location of a cell in the grid 927 // ---------------------------------------------------------------------------- 928 929 class WXDLLIMPEXP_CORE wxGridCellCoords 930 { 931 public: wxGridCellCoords()932 wxGridCellCoords() { m_row = m_col = -1; } wxGridCellCoords(int r,int c)933 wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; } 934 935 // default copy ctor is ok 936 GetRow()937 int GetRow() const { return m_row; } SetRow(int n)938 void SetRow( int n ) { m_row = n; } GetCol()939 int GetCol() const { return m_col; } SetCol(int n)940 void SetCol( int n ) { m_col = n; } Set(int row,int col)941 void Set( int row, int col ) { m_row = row; m_col = col; } 942 943 bool operator==( const wxGridCellCoords& other ) const 944 { 945 return (m_row == other.m_row && m_col == other.m_col); 946 } 947 948 bool operator!=( const wxGridCellCoords& other ) const 949 { 950 return (m_row != other.m_row || m_col != other.m_col); 951 } 952 953 bool operator!() const 954 { 955 return (m_row == -1 && m_col == -1 ); 956 } 957 958 private: 959 int m_row; 960 int m_col; 961 }; 962 963 964 // ---------------------------------------------------------------------------- 965 // wxGridBlockCoords: location of a block of cells in the grid 966 // ---------------------------------------------------------------------------- 967 968 struct wxGridBlockDiffResult; 969 970 class WXDLLIMPEXP_CORE wxGridBlockCoords 971 { 972 public: wxGridBlockCoords()973 wxGridBlockCoords() : 974 m_topRow(-1), 975 m_leftCol(-1), 976 m_bottomRow(-1), 977 m_rightCol(-1) 978 { 979 } 980 wxGridBlockCoords(int topRow,int leftCol,int bottomRow,int rightCol)981 wxGridBlockCoords(int topRow, int leftCol, int bottomRow, int rightCol) : 982 m_topRow(topRow), 983 m_leftCol(leftCol), 984 m_bottomRow(bottomRow), 985 m_rightCol(rightCol) 986 { 987 } 988 989 // default copy ctor is ok 990 GetTopRow()991 int GetTopRow() const { return m_topRow; } SetTopRow(int row)992 void SetTopRow(int row) { m_topRow = row; } GetLeftCol()993 int GetLeftCol() const { return m_leftCol; } SetLeftCol(int col)994 void SetLeftCol(int col) { m_leftCol = col; } GetBottomRow()995 int GetBottomRow() const { return m_bottomRow; } SetBottomRow(int row)996 void SetBottomRow(int row) { m_bottomRow = row; } GetRightCol()997 int GetRightCol() const { return m_rightCol; } SetRightCol(int col)998 void SetRightCol(int col) { m_rightCol = col; } 999 GetTopLeft()1000 wxGridCellCoords GetTopLeft() const 1001 { 1002 return wxGridCellCoords(m_topRow, m_leftCol); 1003 } 1004 GetBottomRight()1005 wxGridCellCoords GetBottomRight() const 1006 { 1007 return wxGridCellCoords(m_bottomRow, m_rightCol); 1008 } 1009 Canonicalize()1010 wxGridBlockCoords Canonicalize() const 1011 { 1012 wxGridBlockCoords result = *this; 1013 1014 if ( result.m_topRow > result.m_bottomRow ) 1015 wxSwap(result.m_topRow, result.m_bottomRow); 1016 1017 if ( result.m_leftCol > result.m_rightCol ) 1018 wxSwap(result.m_leftCol, result.m_rightCol); 1019 1020 return result; 1021 } 1022 Intersects(const wxGridBlockCoords & other)1023 bool Intersects(const wxGridBlockCoords& other) const 1024 { 1025 return m_topRow <= other.m_bottomRow && m_bottomRow >= other.m_topRow && 1026 m_leftCol <= other.m_rightCol && m_rightCol >= other.m_leftCol; 1027 } 1028 1029 // Return whether this block contains the given cell. Contains(const wxGridCellCoords & cell)1030 bool Contains(const wxGridCellCoords& cell) const 1031 { 1032 return m_topRow <= cell.GetRow() && cell.GetRow() <= m_bottomRow && 1033 m_leftCol <= cell.GetCol() && cell.GetCol() <= m_rightCol; 1034 } 1035 1036 // Return whether this blocks fully contains another one. Contains(const wxGridBlockCoords & other)1037 bool Contains(const wxGridBlockCoords& other) const 1038 { 1039 return m_topRow <= other.m_topRow && other.m_bottomRow <= m_bottomRow && 1040 m_leftCol <= other.m_leftCol && other.m_rightCol <= m_rightCol; 1041 } 1042 1043 // Calculates the result blocks by subtracting the other block from this 1044 // block. splitOrientation can be wxVERTICAL or wxHORIZONTAL. 1045 wxGridBlockDiffResult 1046 Difference(const wxGridBlockCoords& other, int splitOrientation) const; 1047 1048 // Calculates the symmetric difference of the blocks. 1049 wxGridBlockDiffResult 1050 SymDifference(const wxGridBlockCoords& other) const; 1051 1052 bool operator==(const wxGridBlockCoords& other) const 1053 { 1054 return m_topRow == other.m_topRow && m_leftCol == other.m_leftCol && 1055 m_bottomRow == other.m_bottomRow && m_rightCol == other.m_rightCol; 1056 } 1057 1058 bool operator!=(const wxGridBlockCoords& other) const 1059 { 1060 return !(*this == other); 1061 } 1062 1063 bool operator!() const 1064 { 1065 return m_topRow == -1 && m_leftCol == -1 && 1066 m_bottomRow == -1 && m_rightCol == -1; 1067 } 1068 1069 private: 1070 int m_topRow; 1071 int m_leftCol; 1072 int m_bottomRow; 1073 int m_rightCol; 1074 }; 1075 1076 typedef wxVector<wxGridBlockCoords> wxGridBlockCoordsVector; 1077 1078 // ---------------------------------------------------------------------------- 1079 // wxGridBlockDiffResult: The helper struct uses as a result type for difference 1080 // functions of wxGridBlockCoords class. 1081 // Parts can be uninitialized (equals to wxGridNoBlockCoords), that means 1082 // that the corresponding part doesn't exists in the result. 1083 // ---------------------------------------------------------------------------- 1084 1085 struct wxGridBlockDiffResult 1086 { 1087 wxGridBlockCoords m_parts[4]; 1088 }; 1089 1090 // ---------------------------------------------------------------------------- 1091 // wxGridBlocks: a range of grid blocks that can be iterated over 1092 // ---------------------------------------------------------------------------- 1093 1094 class wxGridBlocks 1095 { 1096 typedef wxGridBlockCoordsVector::const_iterator iterator_impl; 1097 1098 public: 1099 class iterator 1100 { 1101 public: 1102 #if wxUSE_STD_CONTAINERS_COMPATIBLY 1103 typedef std::forward_iterator_tag iterator_category; 1104 #endif 1105 typedef ptrdiff_t difference_type; 1106 typedef wxGridBlockCoords value_type; 1107 typedef const value_type& reference; 1108 typedef const value_type* pointer; 1109 iterator()1110 iterator() : m_it() { } 1111 1112 reference operator*() const { return *m_it; } 1113 pointer operator->() const { return &*m_it; } 1114 1115 iterator& operator++() 1116 { ++m_it; return *this; } 1117 iterator operator++(int) 1118 { iterator tmp = *this; ++m_it; return tmp; } 1119 1120 bool operator==(const iterator& it) const 1121 { return m_it == it.m_it; } 1122 bool operator!=(const iterator& it) const 1123 { return m_it != it.m_it; } 1124 1125 private: iterator(iterator_impl it)1126 explicit iterator(iterator_impl it) : m_it(it) { } 1127 1128 iterator_impl m_it; 1129 1130 friend class wxGridBlocks; 1131 }; 1132 begin()1133 iterator begin() const 1134 { 1135 return m_begin; 1136 } 1137 end()1138 iterator end() const 1139 { 1140 return m_end; 1141 } 1142 1143 private: wxGridBlocks()1144 wxGridBlocks() : 1145 m_begin(), 1146 m_end() 1147 { 1148 } 1149 wxGridBlocks(iterator_impl ibegin,iterator_impl iend)1150 wxGridBlocks(iterator_impl ibegin, iterator_impl iend) : 1151 m_begin(ibegin), 1152 m_end(iend) 1153 { 1154 } 1155 1156 const iterator m_begin; 1157 const iterator m_end; 1158 1159 friend class wxGrid; 1160 }; 1161 1162 // For comparisons... 1163 // 1164 extern WXDLLIMPEXP_CORE wxGridCellCoords wxGridNoCellCoords; 1165 extern WXDLLIMPEXP_CORE wxGridBlockCoords wxGridNoBlockCoords; 1166 extern WXDLLIMPEXP_CORE wxRect wxGridNoCellRect; 1167 1168 // An array of cell coords... 1169 // 1170 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords, wxGridCellCoordsArray, 1171 class WXDLLIMPEXP_CORE); 1172 1173 // ---------------------------------------------------------------------------- 1174 // Grid table classes 1175 // ---------------------------------------------------------------------------- 1176 1177 // the abstract base class 1178 class WXDLLIMPEXP_CORE wxGridTableBase : public wxObject, 1179 public wxClientDataContainer 1180 { 1181 public: 1182 wxGridTableBase(); 1183 virtual ~wxGridTableBase(); 1184 1185 // You must override these functions in a derived table class 1186 // 1187 1188 // return the number of rows and columns in this table 1189 virtual int GetNumberRows() = 0; 1190 virtual int GetNumberCols() = 0; 1191 1192 // the methods above are unfortunately non-const even though they should 1193 // have been const -- but changing it now is not possible any longer as it 1194 // would break the existing code overriding them, so instead we provide 1195 // these const synonyms which can be used from const-correct code GetRowsCount()1196 int GetRowsCount() const 1197 { return const_cast<wxGridTableBase *>(this)->GetNumberRows(); } GetColsCount()1198 int GetColsCount() const 1199 { return const_cast<wxGridTableBase *>(this)->GetNumberCols(); } 1200 1201 IsEmptyCell(int row,int col)1202 virtual bool IsEmptyCell( int row, int col ) 1203 { 1204 return GetValue(row, col).empty(); 1205 } 1206 IsEmpty(const wxGridCellCoords & coord)1207 bool IsEmpty(const wxGridCellCoords& coord) 1208 { 1209 return IsEmptyCell(coord.GetRow(), coord.GetCol()); 1210 } 1211 1212 virtual wxString GetValue( int row, int col ) = 0; 1213 virtual void SetValue( int row, int col, const wxString& value ) = 0; 1214 1215 // Data type determination and value access 1216 virtual wxString GetTypeName( int row, int col ); 1217 virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); 1218 virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); 1219 1220 virtual long GetValueAsLong( int row, int col ); 1221 virtual double GetValueAsDouble( int row, int col ); 1222 virtual bool GetValueAsBool( int row, int col ); 1223 1224 virtual void SetValueAsLong( int row, int col, long value ); 1225 virtual void SetValueAsDouble( int row, int col, double value ); 1226 virtual void SetValueAsBool( int row, int col, bool value ); 1227 1228 // For user defined types 1229 virtual void* GetValueAsCustom( int row, int col, const wxString& typeName ); 1230 virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value ); 1231 1232 1233 // Overriding these is optional 1234 // SetView(wxGrid * grid)1235 virtual void SetView( wxGrid *grid ) { m_view = grid; } GetView()1236 virtual wxGrid * GetView() const { return m_view; } 1237 Clear()1238 virtual void Clear() {} 1239 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 ); 1240 virtual bool AppendRows( size_t numRows = 1 ); 1241 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); 1242 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 ); 1243 virtual bool AppendCols( size_t numCols = 1 ); 1244 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); 1245 1246 virtual wxString GetRowLabelValue( int row ); 1247 virtual wxString GetColLabelValue( int col ); 1248 virtual wxString GetCornerLabelValue() const; SetRowLabelValue(int WXUNUSED (row),const wxString &)1249 virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {} SetColLabelValue(int WXUNUSED (col),const wxString &)1250 virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {} SetCornerLabelValue(const wxString &)1251 virtual void SetCornerLabelValue( const wxString& ) {} 1252 1253 // Attribute handling 1254 // 1255 1256 // give us the attr provider to use - we take ownership of the pointer 1257 void SetAttrProvider(wxGridCellAttrProvider *attrProvider); 1258 1259 // get the currently used attr provider (may be NULL) GetAttrProvider()1260 wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; } 1261 1262 // Does this table allow attributes? Default implementation creates 1263 // a wxGridCellAttrProvider if necessary. 1264 virtual bool CanHaveAttributes(); 1265 1266 // by default forwarded to wxGridCellAttrProvider if any. May be 1267 // overridden to handle attributes directly in the table. 1268 virtual wxGridCellAttr *GetAttr( int row, int col, 1269 wxGridCellAttr::wxAttrKind kind ); 1270 GetAttrPtr(int row,int col,wxGridCellAttr::wxAttrKind kind)1271 wxGridCellAttrPtr GetAttrPtr(int row, int col, 1272 wxGridCellAttr::wxAttrKind kind) 1273 { 1274 return wxGridCellAttrPtr(GetAttr(row, col, kind)); 1275 } 1276 1277 // This is an optimization for a common case when the entire column uses 1278 // roughly the same attribute, which can thus be reused for measuring all 1279 // the cells in this column. Override this to return true (possibly for 1280 // some columns only) to speed up AutoSizeColumns() for the grids using 1281 // this table. CanMeasureColUsingSameAttr(int WXUNUSED (col))1282 virtual bool CanMeasureColUsingSameAttr(int WXUNUSED(col)) const 1283 { 1284 return false; 1285 } 1286 1287 // these functions take ownership of the pointer 1288 virtual void SetAttr(wxGridCellAttr* attr, int row, int col); 1289 virtual void SetRowAttr(wxGridCellAttr *attr, int row); 1290 virtual void SetColAttr(wxGridCellAttr *attr, int col); 1291 1292 private: 1293 wxGrid * m_view; 1294 wxGridCellAttrProvider *m_attrProvider; 1295 1296 wxDECLARE_ABSTRACT_CLASS(wxGridTableBase); 1297 wxDECLARE_NO_COPY_CLASS(wxGridTableBase); 1298 }; 1299 1300 1301 // ---------------------------------------------------------------------------- 1302 // wxGridTableMessage 1303 // ---------------------------------------------------------------------------- 1304 1305 // IDs for messages sent from grid table to view 1306 // 1307 enum wxGridTableRequest 1308 { 1309 // The first two requests never did anything, simply don't use them. 1310 #if WXWIN_COMPATIBILITY_3_0 1311 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000, 1312 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES, 1313 #endif // WXWIN_COMPATIBILITY_3_0 1314 wxGRIDTABLE_NOTIFY_ROWS_INSERTED = 2002, 1315 wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1316 wxGRIDTABLE_NOTIFY_ROWS_DELETED, 1317 wxGRIDTABLE_NOTIFY_COLS_INSERTED, 1318 wxGRIDTABLE_NOTIFY_COLS_APPENDED, 1319 wxGRIDTABLE_NOTIFY_COLS_DELETED 1320 }; 1321 1322 class WXDLLIMPEXP_CORE wxGridTableMessage 1323 { 1324 public: 1325 wxGridTableMessage(); 1326 wxGridTableMessage( wxGridTableBase *table, int id, 1327 int comInt1 = -1, 1328 int comInt2 = -1 ); 1329 SetTableObject(wxGridTableBase * table)1330 void SetTableObject( wxGridTableBase *table ) { m_table = table; } GetTableObject()1331 wxGridTableBase * GetTableObject() const { return m_table; } SetId(int id)1332 void SetId( int id ) { m_id = id; } GetId()1333 int GetId() const { return m_id; } SetCommandInt(int comInt1)1334 void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; } GetCommandInt()1335 int GetCommandInt() const { return m_comInt1; } SetCommandInt2(int comInt2)1336 void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; } GetCommandInt2()1337 int GetCommandInt2() const { return m_comInt2; } 1338 1339 private: 1340 wxGridTableBase *m_table; 1341 int m_id; 1342 int m_comInt1; 1343 int m_comInt2; 1344 1345 wxDECLARE_NO_COPY_CLASS(wxGridTableMessage); 1346 }; 1347 1348 1349 1350 // ------ wxGridStringArray 1351 // A 2-dimensional array of strings for data values 1352 // 1353 1354 WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString, wxGridStringArray, 1355 class WXDLLIMPEXP_CORE); 1356 1357 1358 1359 // ------ wxGridStringTable 1360 // 1361 // Simplest type of data table for a grid for small tables of strings 1362 // that are stored in memory 1363 // 1364 1365 class WXDLLIMPEXP_CORE wxGridStringTable : public wxGridTableBase 1366 { 1367 public: 1368 wxGridStringTable(); 1369 wxGridStringTable( int numRows, int numCols ); 1370 1371 // these are pure virtual in wxGridTableBase 1372 // GetNumberRows()1373 virtual int GetNumberRows() wxOVERRIDE { return static_cast<int>(m_data.size()); } GetNumberCols()1374 virtual int GetNumberCols() wxOVERRIDE { return m_numCols; } 1375 virtual wxString GetValue( int row, int col ) wxOVERRIDE; 1376 virtual void SetValue( int row, int col, const wxString& s ) wxOVERRIDE; 1377 1378 // overridden functions from wxGridTableBase 1379 // 1380 void Clear() wxOVERRIDE; 1381 bool InsertRows( size_t pos = 0, size_t numRows = 1 ) wxOVERRIDE; 1382 bool AppendRows( size_t numRows = 1 ) wxOVERRIDE; 1383 bool DeleteRows( size_t pos = 0, size_t numRows = 1 ) wxOVERRIDE; 1384 bool InsertCols( size_t pos = 0, size_t numCols = 1 ) wxOVERRIDE; 1385 bool AppendCols( size_t numCols = 1 ) wxOVERRIDE; 1386 bool DeleteCols( size_t pos = 0, size_t numCols = 1 ) wxOVERRIDE; 1387 1388 void SetRowLabelValue( int row, const wxString& ) wxOVERRIDE; 1389 void SetColLabelValue( int col, const wxString& ) wxOVERRIDE; 1390 void SetCornerLabelValue( const wxString& ) wxOVERRIDE; 1391 wxString GetRowLabelValue( int row ) wxOVERRIDE; 1392 wxString GetColLabelValue( int col ) wxOVERRIDE; 1393 wxString GetCornerLabelValue() const wxOVERRIDE; 1394 1395 private: 1396 wxGridStringArray m_data; 1397 1398 // notice that while we don't need to store the number of our rows as it's 1399 // always equal to the size of m_data array, we do need to store the number 1400 // of our columns as we can't retrieve it from m_data when the number of 1401 // rows is 0 (see #10818) 1402 int m_numCols; 1403 1404 // These only get used if you set your own labels, otherwise the 1405 // GetRow/ColLabelValue functions return wxGridTableBase defaults 1406 // 1407 wxArrayString m_rowLabels; 1408 wxArrayString m_colLabels; 1409 1410 wxString m_cornerLabel; 1411 1412 wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxGridStringTable); 1413 }; 1414 1415 1416 1417 // ============================================================================ 1418 // Grid view classes 1419 // ============================================================================ 1420 1421 // ---------------------------------------------------------------------------- 1422 // wxGridSizesInfo stores information about sizes of the rows or columns. 1423 // 1424 // It assumes that most of the columns or rows have default size and so stores 1425 // the default size separately and uses a hash to map column or row numbers to 1426 // their non default size for those which don't have the default size. 1427 // ---------------------------------------------------------------------------- 1428 1429 // hash map to store positions as the keys and sizes as the values 1430 WX_DECLARE_HASH_MAP_WITH_DECL( unsigned, int, wxIntegerHash, wxIntegerEqual, 1431 wxUnsignedToIntHashMap, class WXDLLIMPEXP_CORE ); 1432 1433 struct WXDLLIMPEXP_CORE wxGridSizesInfo 1434 { 1435 // default ctor, initialize m_sizeDefault and m_customSizes later wxGridSizesInfowxGridSizesInfo1436 wxGridSizesInfo() { } 1437 1438 // ctor used by wxGrid::Get{Col,Row}Sizes() 1439 wxGridSizesInfo(int defSize, const wxArrayInt& allSizes); 1440 1441 // default copy ctor, assignment operator and dtor are ok 1442 1443 // Get the size of the element with the given index 1444 int GetSize(unsigned pos) const; 1445 1446 1447 // default size 1448 int m_sizeDefault; 1449 1450 // position -> size map containing all elements with non-default size 1451 wxUnsignedToIntHashMap m_customSizes; 1452 }; 1453 1454 // ---------------------------------------------------------------------------- 1455 // wxGrid 1456 // ---------------------------------------------------------------------------- 1457 1458 class WXDLLIMPEXP_CORE wxGrid : public wxScrolledCanvas 1459 { 1460 public: 1461 // possible selection modes 1462 enum wxGridSelectionModes 1463 { 1464 wxGridSelectCells = 0, // allow selecting anything 1465 wxGridSelectRows = 1, // allow selecting only entire rows 1466 wxGridSelectColumns = 2, // allow selecting only entire columns 1467 wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns, 1468 wxGridSelectNone = 4 // disallow selecting anything 1469 }; 1470 1471 // Different behaviour of the TAB key when the end (or the beginning, for 1472 // Shift-TAB) of the current row is reached: 1473 enum TabBehaviour 1474 { 1475 Tab_Stop, // Do nothing, this is default. 1476 Tab_Wrap, // Move to the next (or previous) row. 1477 Tab_Leave // Move to the next (or previous) control. 1478 }; 1479 1480 // creation and destruction 1481 // ------------------------ 1482 1483 // ctor and Create() create the grid window, as with the other controls wxGrid()1484 wxGrid() { Init(); } 1485 1486 wxGrid(wxWindow *parent, 1487 wxWindowID id, 1488 const wxPoint& pos = wxDefaultPosition, 1489 const wxSize& size = wxDefaultSize, 1490 long style = wxWANTS_CHARS, 1491 const wxString& name = wxASCII_STR(wxGridNameStr)) 1492 { 1493 Init(); 1494 1495 Create(parent, id, pos, size, style, name); 1496 } 1497 1498 bool Create(wxWindow *parent, 1499 wxWindowID id, 1500 const wxPoint& pos = wxDefaultPosition, 1501 const wxSize& size = wxDefaultSize, 1502 long style = wxWANTS_CHARS, 1503 const wxString& name = wxASCII_STR(wxGridNameStr)); 1504 1505 virtual ~wxGrid(); 1506 1507 // however to initialize grid data either CreateGrid() (to use a simple 1508 // default table class) or {Set,Assign}Table() (to use a custom table) must 1509 // be also called 1510 1511 // this is basically equivalent to 1512 // 1513 // AssignTable(new wxGridStringTable(numRows, numCols), selmode) 1514 // 1515 bool CreateGrid( int numRows, int numCols, 1516 wxGridSelectionModes selmode = wxGridSelectCells ); 1517 1518 bool SetTable( wxGridTableBase *table, 1519 bool takeOwnership = false, 1520 wxGridSelectionModes selmode = wxGridSelectCells ); 1521 1522 void AssignTable( wxGridTableBase *table, 1523 wxGridSelectionModes selmode = wxGridSelectCells ); 1524 1525 bool ProcessTableMessage(wxGridTableMessage&); 1526 GetTable()1527 wxGridTableBase *GetTable() const { return m_table; } 1528 1529 1530 void SetSelectionMode(wxGridSelectionModes selmode); 1531 wxGridSelectionModes GetSelectionMode() const; 1532 1533 // ------ grid dimensions 1534 // GetNumberRows()1535 int GetNumberRows() const { return m_numRows; } GetNumberCols()1536 int GetNumberCols() const { return m_numCols; } 1537 GetNumberFrozenRows()1538 int GetNumberFrozenRows() const { return m_numFrozenRows; } GetNumberFrozenCols()1539 int GetNumberFrozenCols() const { return m_numFrozenCols; } 1540 1541 // ------ display update functions 1542 // 1543 wxArrayInt CalcRowLabelsExposed( const wxRegion& reg, 1544 wxGridWindow *gridWindow = NULL) const; 1545 wxArrayInt CalcColLabelsExposed( const wxRegion& reg, 1546 wxGridWindow *gridWindow = NULL) const; 1547 wxGridCellCoordsArray CalcCellsExposed( const wxRegion& reg, 1548 wxGridWindow *gridWindow = NULL) const; 1549 1550 void PrepareDCFor(wxDC &dc, wxGridWindow *gridWindow); 1551 1552 void ClearGrid(); 1553 bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true) 1554 { 1555 return DoModifyLines(&wxGridTableBase::InsertRows, 1556 pos, numRows, updateLabels); 1557 } 1558 bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true) 1559 { 1560 return DoModifyLines(&wxGridTableBase::InsertCols, 1561 pos, numCols, updateLabels); 1562 } 1563 1564 bool AppendRows(int numRows = 1, bool updateLabels = true) 1565 { 1566 return DoAppendLines(&wxGridTableBase::AppendRows, numRows, updateLabels); 1567 } 1568 bool AppendCols(int numCols = 1, bool updateLabels = true) 1569 { 1570 return DoAppendLines(&wxGridTableBase::AppendCols, numCols, updateLabels); 1571 } 1572 1573 bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true) 1574 { 1575 return DoModifyLines(&wxGridTableBase::DeleteRows, 1576 pos, numRows, updateLabels); 1577 } 1578 bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true) 1579 { 1580 return DoModifyLines(&wxGridTableBase::DeleteCols, 1581 pos, numCols, updateLabels); 1582 } 1583 1584 bool FreezeTo(int row, int col); FreezeTo(const wxGridCellCoords & coords)1585 bool FreezeTo(const wxGridCellCoords& coords) 1586 { 1587 return FreezeTo(coords.GetRow(), coords.GetCol()); 1588 } 1589 1590 bool IsFrozen() const; 1591 1592 void DrawGridCellArea( wxDC& dc , const wxGridCellCoordsArray& cells ); 1593 void DrawGridSpace( wxDC& dc, wxGridWindow *gridWindow ); 1594 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& ); 1595 void DrawAllGridLines(); 1596 void DrawAllGridWindowLines( wxDC& dc, const wxRegion & reg , wxGridWindow *gridWindow); 1597 void DrawCell( wxDC& dc, const wxGridCellCoords& ); 1598 void DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells); 1599 void DrawFrozenBorder( wxDC& dc, wxGridWindow *gridWindow ); 1600 void DrawLabelFrozenBorder( wxDC& dc, wxWindow *window, bool isRow ); 1601 1602 void ScrollWindow( int dx, int dy, const wxRect *rect ) wxOVERRIDE; 1603 1604 void UpdateGridWindows() const; 1605 1606 // this function is called when the current cell highlight must be redrawn 1607 // and may be overridden by the user 1608 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ); 1609 1610 virtual void DrawRowLabels( wxDC& dc, const wxArrayInt& rows ); 1611 virtual void DrawRowLabel( wxDC& dc, int row ); 1612 1613 virtual void DrawColLabels( wxDC& dc, const wxArrayInt& cols ); 1614 virtual void DrawColLabel( wxDC& dc, int col ); 1615 1616 virtual void DrawCornerLabel(wxDC& dc); 1617 1618 // ------ Cell text drawing functions 1619 // 1620 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&, 1621 int horizontalAlignment = wxALIGN_LEFT, 1622 int verticalAlignment = wxALIGN_TOP, 1623 int textOrientation = wxHORIZONTAL ) const; 1624 1625 void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&, 1626 int horizontalAlignment = wxALIGN_LEFT, 1627 int verticalAlignment = wxALIGN_TOP, 1628 int textOrientation = wxHORIZONTAL ) const; 1629 1630 void DrawTextRectangle(wxDC& dc, 1631 const wxString& text, 1632 const wxRect& rect, 1633 const wxGridCellAttr& attr, 1634 int defaultHAlign = wxALIGN_INVALID, 1635 int defaultVAlign = wxALIGN_INVALID) const; 1636 1637 // ------ grid render function for printing 1638 // 1639 void Render( wxDC& dc, 1640 const wxPoint& pos = wxDefaultPosition, 1641 const wxSize& size = wxDefaultSize, 1642 const wxGridCellCoords& topLeft = wxGridCellCoords(-1, -1), 1643 const wxGridCellCoords& bottomRight = wxGridCellCoords(-1, -1), 1644 int style = wxGRID_DRAW_DEFAULT ); 1645 1646 // Split a string containing newline characters into an array of 1647 // strings and return the number of lines 1648 // 1649 void StringToLines( const wxString& value, wxArrayString& lines ) const; 1650 1651 void GetTextBoxSize( const wxDC& dc, 1652 const wxArrayString& lines, 1653 long *width, long *height ) const; 1654 1655 // If bottomRight is invalid, i.e. == wxGridNoCellCoords, it defaults to 1656 // topLeft. If topLeft itself is invalid, the function simply returns. 1657 void RefreshBlock(const wxGridCellCoords& topLeft, 1658 const wxGridCellCoords& bottomRight); 1659 1660 void RefreshBlock(int topRow, int leftCol, 1661 int bottomRow, int rightCol); 1662 1663 // ------ 1664 // Code that does a lot of grid modification can be enclosed 1665 // between BeginBatch() and EndBatch() calls to avoid screen 1666 // flicker 1667 // BeginBatch()1668 void BeginBatch() { m_batchCount++; } 1669 void EndBatch(); 1670 GetBatchCount()1671 int GetBatchCount() const { return m_batchCount; } 1672 1673 virtual void Refresh(bool eraseb = true, const wxRect* rect = NULL) wxOVERRIDE; 1674 1675 // Use this, rather than wxWindow::Refresh(), to force an 1676 // immediate repainting of the grid. Has no effect if you are 1677 // already inside a BeginBatch / EndBatch block. 1678 // 1679 // This function is necessary because wxGrid has a minimal OnPaint() 1680 // handler to reduce screen flicker. 1681 // 1682 void ForceRefresh(); 1683 1684 1685 // ------ edit control functions 1686 // IsEditable()1687 bool IsEditable() const { return m_editable; } 1688 void EnableEditing( bool edit ); 1689 1690 void EnableCellEditControl( bool enable = true ); DisableCellEditControl()1691 void DisableCellEditControl() { EnableCellEditControl(false); } 1692 bool CanEnableCellControl() const; IsCellEditControlEnabled()1693 bool IsCellEditControlEnabled() const { return m_cellEditCtrlEnabled; } 1694 bool IsCellEditControlShown() const; 1695 1696 bool IsCurrentCellReadOnly() const; 1697 1698 void ShowCellEditControl(); // Use EnableCellEditControl() instead. 1699 void HideCellEditControl(); 1700 void SaveEditControlValue(); 1701 1702 1703 // ------ grid location functions 1704 // Note that all of these functions work with the logical coordinates of 1705 // grid cells and labels so you will need to convert from device 1706 // coordinates for mouse events etc. 1707 // 1708 wxGridCellCoords XYToCell(int x, int y, wxGridWindow *gridWindow = NULL) const; 1709 void XYToCell(int x, int y, 1710 wxGridCellCoords& coords, 1711 wxGridWindow *gridWindow = NULL) const 1712 { coords = XYToCell(x, y, gridWindow); } 1713 1714 wxGridCellCoords XYToCell(const wxPoint& pos, 1715 wxGridWindow *gridWindow = NULL) const 1716 { return XYToCell(pos.x, pos.y, gridWindow); } 1717 1718 // these functions return the index of the row/columns corresponding to the 1719 // given logical position in pixels 1720 // 1721 // if clipToMinMax is false (default, wxNOT_FOUND is returned if the 1722 // position is outside any row/column, otherwise the first/last element is 1723 // returned in this case 1724 int YToRow( int y, bool clipToMinMax = false, wxGridWindow *gridWindow = NULL ) const; 1725 int XToCol( int x, bool clipToMinMax = false, wxGridWindow *gridWindow = NULL ) const; 1726 1727 int YToEdgeOfRow( int y ) const; 1728 int XToEdgeOfCol( int x ) const; 1729 1730 wxRect CellToRect( int row, int col ) const; CellToRect(const wxGridCellCoords & coords)1731 wxRect CellToRect( const wxGridCellCoords& coords ) const 1732 { return CellToRect( coords.GetRow(), coords.GetCol() ); } 1733 1734 wxGridWindow* CellToGridWindow( int row, int col ) const; CellToGridWindow(const wxGridCellCoords & coords)1735 wxGridWindow* CellToGridWindow( const wxGridCellCoords& coords ) const 1736 { return CellToGridWindow( coords.GetRow(), coords.GetCol() ); } 1737 GetGridCursorCoords()1738 const wxGridCellCoords& GetGridCursorCoords() const 1739 { return m_currentCellCoords; } 1740 GetGridCursorRow()1741 int GetGridCursorRow() const { return m_currentCellCoords.GetRow(); } GetGridCursorCol()1742 int GetGridCursorCol() const { return m_currentCellCoords.GetCol(); } 1743 1744 void GetGridWindowOffset(const wxGridWindow *gridWindow, int &x, int &y) const; 1745 wxPoint GetGridWindowOffset(const wxGridWindow *gridWindow) const; 1746 1747 wxGridWindow* DevicePosToGridWindow(wxPoint pos) const; 1748 wxGridWindow* DevicePosToGridWindow(int x, int y) const; 1749 1750 void CalcGridWindowUnscrolledPosition(int x, int y, int *xx, int *yy, 1751 const wxGridWindow *gridWindow) const; 1752 wxPoint CalcGridWindowUnscrolledPosition(const wxPoint& pt, 1753 const wxGridWindow *gridWindow) const; 1754 1755 void CalcGridWindowScrolledPosition(int x, int y, int *xx, int *yy, 1756 const wxGridWindow *gridWindow) const; 1757 wxPoint CalcGridWindowScrolledPosition(const wxPoint& pt, 1758 const wxGridWindow *gridWindow) const; 1759 1760 // check to see if a cell is either wholly visible (the default arg) or 1761 // at least partially visible in the grid window 1762 // 1763 bool IsVisible( int row, int col, bool wholeCellVisible = true ) const; 1764 bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = true ) const 1765 { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); } 1766 void MakeCellVisible( int row, int col ); MakeCellVisible(const wxGridCellCoords & coords)1767 void MakeCellVisible( const wxGridCellCoords& coords ) 1768 { MakeCellVisible( coords.GetRow(), coords.GetCol() ); } 1769 1770 // Returns the topmost row of the current visible area. 1771 int GetFirstFullyVisibleRow() const; 1772 // Returns the leftmost column of the current visible area. 1773 int GetFirstFullyVisibleColumn() const; 1774 1775 // ------ grid cursor movement functions 1776 // SetGridCursor(int row,int col)1777 void SetGridCursor(int row, int col) { SetCurrentCell(row, col); } SetGridCursor(const wxGridCellCoords & c)1778 void SetGridCursor(const wxGridCellCoords& c) { SetCurrentCell(c); } 1779 GoToCell(int row,int col)1780 void GoToCell(int row, int col) 1781 { 1782 if ( SetCurrentCell(row, col) ) 1783 MakeCellVisible(row, col); 1784 } 1785 GoToCell(const wxGridCellCoords & coords)1786 void GoToCell(const wxGridCellCoords& coords) 1787 { 1788 if ( SetCurrentCell(coords) ) 1789 MakeCellVisible(coords); 1790 } 1791 1792 bool MoveCursorUp( bool expandSelection ); 1793 bool MoveCursorDown( bool expandSelection ); 1794 bool MoveCursorLeft( bool expandSelection ); 1795 bool MoveCursorRight( bool expandSelection ); 1796 bool MovePageDown(); 1797 bool MovePageUp(); 1798 bool MoveCursorUpBlock( bool expandSelection ); 1799 bool MoveCursorDownBlock( bool expandSelection ); 1800 bool MoveCursorLeftBlock( bool expandSelection ); 1801 bool MoveCursorRightBlock( bool expandSelection ); 1802 SetTabBehaviour(TabBehaviour behaviour)1803 void SetTabBehaviour(TabBehaviour behaviour) { m_tabBehaviour = behaviour; } 1804 1805 1806 // ------ label and gridline formatting 1807 // GetDefaultRowLabelSize()1808 int GetDefaultRowLabelSize() const { return FromDIP(WXGRID_DEFAULT_ROW_LABEL_WIDTH); } GetRowLabelSize()1809 int GetRowLabelSize() const { return m_rowLabelWidth; } GetDefaultColLabelSize()1810 int GetDefaultColLabelSize() const { return FromDIP(WXGRID_DEFAULT_COL_LABEL_HEIGHT); } GetColLabelSize()1811 int GetColLabelSize() const { return m_colLabelHeight; } GetLabelBackgroundColour()1812 wxColour GetLabelBackgroundColour() const { return m_labelBackgroundColour; } GetLabelTextColour()1813 wxColour GetLabelTextColour() const { return m_labelTextColour; } GetLabelFont()1814 wxFont GetLabelFont() const { return m_labelFont; } 1815 void GetRowLabelAlignment( int *horiz, int *vert ) const; 1816 void GetColLabelAlignment( int *horiz, int *vert ) const; 1817 void GetCornerLabelAlignment( int *horiz, int *vert ) const; 1818 int GetColLabelTextOrientation() const; 1819 int GetCornerLabelTextOrientation() const; 1820 wxString GetRowLabelValue( int row ) const; 1821 wxString GetColLabelValue( int col ) const; 1822 wxString GetCornerLabelValue() const; 1823 GetCellHighlightColour()1824 wxColour GetCellHighlightColour() const { return m_cellHighlightColour; } GetCellHighlightPenWidth()1825 int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; } GetCellHighlightROPenWidth()1826 int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; } GetGridFrozenBorderColour()1827 wxColor GetGridFrozenBorderColour() const { return m_gridFrozenBorderColour; } GetGridFrozenBorderPenWidth()1828 int GetGridFrozenBorderPenWidth() const { return m_gridFrozenBorderPenWidth; } 1829 1830 // this one will use wxHeaderCtrl for the column labels 1831 bool UseNativeColHeader(bool native = true); 1832 1833 // this one will still draw them manually but using the native renderer 1834 // instead of using the same appearance as for the row labels 1835 void SetUseNativeColLabels( bool native = true ); 1836 1837 void SetRowLabelSize( int width ); 1838 void SetColLabelSize( int height ); HideRowLabels()1839 void HideRowLabels() { SetRowLabelSize( 0 ); } HideColLabels()1840 void HideColLabels() { SetColLabelSize( 0 ); } 1841 void SetLabelBackgroundColour( const wxColour& ); 1842 void SetLabelTextColour( const wxColour& ); 1843 void SetLabelFont( const wxFont& ); 1844 void SetRowLabelAlignment( int horiz, int vert ); 1845 void SetColLabelAlignment( int horiz, int vert ); 1846 void SetCornerLabelAlignment( int horiz, int vert ); 1847 void SetColLabelTextOrientation( int textOrientation ); 1848 void SetCornerLabelTextOrientation( int textOrientation ); 1849 void SetRowLabelValue( int row, const wxString& ); 1850 void SetColLabelValue( int col, const wxString& ); 1851 void SetCornerLabelValue( const wxString& ); 1852 void SetCellHighlightColour( const wxColour& ); 1853 void SetCellHighlightPenWidth( int width ); 1854 void SetCellHighlightROPenWidth( int width ); 1855 void SetGridFrozenBorderColour( const wxColour& ); 1856 void SetGridFrozenBorderPenWidth( int width ); 1857 1858 // interactive grid mouse operations control 1859 // ----------------------------------------- 1860 1861 // functions globally enabling row/column interactive resizing (enabled by 1862 // default) 1863 void EnableDragRowSize( bool enable = true ); DisableDragRowSize()1864 void DisableDragRowSize() { EnableDragRowSize( false ); } 1865 1866 void EnableDragColSize( bool enable = true ); DisableDragColSize()1867 void DisableDragColSize() { EnableDragColSize( false ); } 1868 1869 // if interactive resizing is enabled, some rows/columns can still have 1870 // fixed size DisableRowResize(int row)1871 void DisableRowResize(int row) { DoDisableLineResize(row, m_setFixedRows); } DisableColResize(int col)1872 void DisableColResize(int col) { DoDisableLineResize(col, m_setFixedCols); } 1873 1874 // These function return true if resizing rows/columns by dragging 1875 // their edges inside the grid is enabled. Note that this doesn't cover 1876 // dragging their separators in the label windows (which can be enabled 1877 // for the columns even if dragging inside the grid is not), nor checks 1878 // whether a particular row/column is resizeable or not, so you should 1879 // always check CanDrag{Row,Col}Size() below too. CanDragGridRowEdges()1880 bool CanDragGridRowEdges() const 1881 { 1882 return m_canDragGridSize && m_canDragRowSize; 1883 } 1884 CanDragGridColEdges()1885 bool CanDragGridColEdges() const 1886 { 1887 // When using the native header window we can only resize the columns by 1888 // dragging the dividers in the header itself, but not by dragging them 1889 // in the grid because we can't make the native control enter into the 1890 // column resizing mode programmatically. 1891 return m_canDragGridSize && m_canDragColSize && !m_useNativeHeader; 1892 } 1893 1894 // These functions return whether the given row/column can be 1895 // effectively resized: for this interactive resizing must be enabled 1896 // and this index must not have been passed to DisableRow/ColResize() CanDragRowSize(int row)1897 bool CanDragRowSize(int row) const 1898 { return m_canDragRowSize && DoCanResizeLine(row, m_setFixedRows); } CanDragColSize(int col)1899 bool CanDragColSize(int col) const 1900 { return m_canDragColSize && DoCanResizeLine(col, m_setFixedCols); } 1901 1902 // interactive column reordering (disabled by default) 1903 bool EnableDragColMove( bool enable = true ); DisableDragColMove()1904 void DisableDragColMove() { EnableDragColMove( false ); } CanDragColMove()1905 bool CanDragColMove() const { return m_canDragColMove; } 1906 1907 // interactive column hiding (enabled by default, works only for native header) 1908 bool EnableHidingColumns( bool enable = true ); DisableHidingColumns()1909 void DisableHidingColumns() { EnableHidingColumns(false); } CanHideColumns()1910 bool CanHideColumns() const { return m_canHideColumns; } 1911 1912 // interactive resizing of grid cells (enabled by default) 1913 void EnableDragGridSize(bool enable = true); DisableDragGridSize()1914 void DisableDragGridSize() { EnableDragGridSize(false); } CanDragGridSize()1915 bool CanDragGridSize() const { return m_canDragGridSize; } 1916 1917 // interactive dragging of cells (disabled by default) 1918 void EnableDragCell( bool enable = true ); DisableDragCell()1919 void DisableDragCell() { EnableDragCell( false ); } CanDragCell()1920 bool CanDragCell() const { return m_canDragCell; } 1921 1922 1923 // grid lines 1924 // ---------- 1925 1926 // enable or disable drawing of the lines 1927 void EnableGridLines(bool enable = true); GridLinesEnabled()1928 bool GridLinesEnabled() const { return m_gridLinesEnabled; } 1929 1930 // by default grid lines stop at last column/row, but this may be changed ClipHorzGridLines(bool clip)1931 void ClipHorzGridLines(bool clip) 1932 { DoClipGridLines(m_gridLinesClipHorz, clip); } ClipVertGridLines(bool clip)1933 void ClipVertGridLines(bool clip) 1934 { DoClipGridLines(m_gridLinesClipVert, clip); } AreHorzGridLinesClipped()1935 bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz; } AreVertGridLinesClipped()1936 bool AreVertGridLinesClipped() const { return m_gridLinesClipVert; } 1937 1938 // this can be used to change the global grid lines colour 1939 void SetGridLineColour(const wxColour& col); GetGridLineColour()1940 wxColour GetGridLineColour() const { return m_gridLineColour; } 1941 1942 // these methods may be overridden to customize individual grid lines 1943 // appearance 1944 virtual wxPen GetDefaultGridLinePen(); 1945 virtual wxPen GetRowGridLinePen(int row); 1946 virtual wxPen GetColGridLinePen(int col); 1947 1948 1949 // attributes 1950 // ---------- 1951 1952 // this sets the specified attribute for this cell or in this row/col 1953 void SetAttr(int row, int col, wxGridCellAttr *attr); 1954 void SetRowAttr(int row, wxGridCellAttr *attr); 1955 void SetColAttr(int col, wxGridCellAttr *attr); 1956 1957 // the grid can cache attributes for the recently used cells (currently it 1958 // only caches one attribute for the most recently used one) and might 1959 // notice that its value in the attribute provider has changed -- if this 1960 // happens, call this function to force it 1961 void RefreshAttr(int row, int col); 1962 1963 // returns the attribute we may modify in place: a new one if this cell 1964 // doesn't have any yet or the existing one if it does 1965 // 1966 // DecRef() must be called on the returned pointer, as usual 1967 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const; 1968 GetOrCreateCellAttrPtr(int row,int col)1969 wxGridCellAttrPtr GetOrCreateCellAttrPtr(int row, int col) const 1970 { 1971 return wxGridCellAttrPtr(GetOrCreateCellAttr(row, col)); 1972 } 1973 1974 1975 // shortcuts for setting the column parameters 1976 1977 // set the format for the data in the column: default is string 1978 void SetColFormatBool(int col); 1979 void SetColFormatNumber(int col); 1980 void SetColFormatFloat(int col, int width = -1, int precision = -1); 1981 void SetColFormatDate(int col, const wxString& format = wxString()); 1982 void SetColFormatCustom(int col, const wxString& typeName); 1983 1984 // ------ row and col formatting 1985 // 1986 int GetDefaultRowSize() const; 1987 int GetRowSize( int row ) const; IsRowShown(int row)1988 bool IsRowShown(int row) const { return GetRowSize(row) != 0; } 1989 int GetDefaultColSize() const; 1990 int GetColSize( int col ) const; IsColShown(int col)1991 bool IsColShown(int col) const { return GetColSize(col) != 0; } 1992 wxColour GetDefaultCellBackgroundColour() const; 1993 wxColour GetCellBackgroundColour( int row, int col ) const; 1994 wxColour GetDefaultCellTextColour() const; 1995 wxColour GetCellTextColour( int row, int col ) const; 1996 wxFont GetDefaultCellFont() const; 1997 wxFont GetCellFont( int row, int col ) const; 1998 void GetDefaultCellAlignment( int *horiz, int *vert ) const; 1999 void GetCellAlignment( int row, int col, int *horiz, int *vert ) const; 2000 2001 wxGridFitMode GetDefaultCellFitMode() const; 2002 wxGridFitMode GetCellFitMode(int row, int col) const; 2003 GetDefaultCellOverflow()2004 bool GetDefaultCellOverflow() const 2005 { return GetDefaultCellFitMode().IsOverflow(); } GetCellOverflow(int row,int col)2006 bool GetCellOverflow( int row, int col ) const 2007 { return GetCellFitMode(row, col).IsOverflow(); } 2008 2009 // this function returns 1 in num_rows and num_cols for normal cells, 2010 // positive numbers for a cell spanning multiple columns/rows (as set with 2011 // SetCellSize()) and _negative_ numbers corresponding to the offset of the 2012 // top left cell of the span from this one for the other cells covered by 2013 // this cell 2014 // 2015 // the return value is CellSpan_None, CellSpan_Main or CellSpan_Inside for 2016 // each of these cases respectively 2017 enum CellSpan 2018 { 2019 CellSpan_Inside = -1, 2020 CellSpan_None = 0, 2021 CellSpan_Main 2022 }; 2023 2024 CellSpan GetCellSize( int row, int col, int *num_rows, int *num_cols ) const; 2025 GetCellSize(const wxGridCellCoords & coords)2026 wxSize GetCellSize(const wxGridCellCoords& coords) const 2027 { 2028 wxSize s; 2029 GetCellSize(coords.GetRow(), coords.GetCol(), &s.x, &s.y); 2030 return s; 2031 } 2032 2033 // ------ row and col sizes 2034 void SetDefaultRowSize( int height, bool resizeExistingRows = false ); 2035 void SetRowSize( int row, int height ); HideRow(int row)2036 void HideRow(int row) { DoSetRowSize(row, 0); } ShowRow(int row)2037 void ShowRow(int row) { DoSetRowSize(row, -1); } 2038 2039 void SetDefaultColSize( int width, bool resizeExistingCols = false ); 2040 void SetColSize( int col, int width ); HideCol(int col)2041 void HideCol(int col) { DoSetColSize(col, 0); } ShowCol(int col)2042 void ShowCol(int col) { DoSetColSize(col, -1); } 2043 2044 // the row and column sizes can be also set all at once using 2045 // wxGridSizesInfo which holds all of them at once 2046 GetColSizes()2047 wxGridSizesInfo GetColSizes() const 2048 { return wxGridSizesInfo(GetDefaultColSize(), m_colWidths); } GetRowSizes()2049 wxGridSizesInfo GetRowSizes() const 2050 { return wxGridSizesInfo(GetDefaultRowSize(), m_rowHeights); } 2051 2052 void SetColSizes(const wxGridSizesInfo& sizeInfo); 2053 void SetRowSizes(const wxGridSizesInfo& sizeInfo); 2054 2055 2056 // ------- columns (only, for now) reordering 2057 2058 // columns index <-> positions mapping: by default, the position of the 2059 // column is the same as its index, but the columns can also be reordered 2060 // (either by calling SetColPos() explicitly or by the user dragging the 2061 // columns around) in which case their indices don't correspond to their 2062 // positions on display any longer 2063 // 2064 // internally we always work with indices except for the functions which 2065 // have "Pos" in their names (and which work with columns, not pixels) and 2066 // only the display and hit testing code really cares about display 2067 // positions at all 2068 2069 // set the positions of all columns at once (this method uses the same 2070 // conventions as wxHeaderCtrl::SetColumnsOrder() for the order array) 2071 void SetColumnsOrder(const wxArrayInt& order); 2072 2073 // return the column index corresponding to the given (valid) position GetColAt(int pos)2074 int GetColAt(int pos) const 2075 { 2076 return m_colAt.empty() ? pos : m_colAt[pos]; 2077 } 2078 2079 // reorder the columns so that the column with the given index is now shown 2080 // as the position pos 2081 void SetColPos(int idx, int pos); 2082 2083 // return the position at which the column with the given index is 2084 // displayed: notice that this is a slow operation as we don't maintain the 2085 // reverse mapping currently GetColPos(int idx)2086 int GetColPos(int idx) const 2087 { 2088 wxASSERT_MSG( idx >= 0 && idx < m_numCols, "invalid column index" ); 2089 2090 if ( m_colAt.IsEmpty() ) 2091 return idx; 2092 2093 int pos = m_colAt.Index(idx); 2094 wxASSERT_MSG( pos != wxNOT_FOUND, "invalid column index" ); 2095 2096 return pos; 2097 } 2098 2099 // reset the columns positions to the default order 2100 void ResetColPos(); 2101 2102 2103 // automatically size the column or row to fit to its contents, if 2104 // setAsMin is true, this optimal width will also be set as minimal width 2105 // for this column 2106 void AutoSizeColumn( int col, bool setAsMin = true ) 2107 { AutoSizeColOrRow(col, setAsMin, wxGRID_COLUMN); } 2108 void AutoSizeRow( int row, bool setAsMin = true ) 2109 { AutoSizeColOrRow(row, setAsMin, wxGRID_ROW); } 2110 2111 // auto size all columns (very ineffective for big grids!) 2112 void AutoSizeColumns( bool setAsMin = true ); 2113 void AutoSizeRows( bool setAsMin = true ); 2114 2115 // auto size the grid, that is make the columns/rows of the "right" size 2116 // and also set the grid size to just fit its contents 2117 void AutoSize(); 2118 2119 // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize: 2120 // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column 2121 // instead of data column. Note that this operation may be slow for large 2122 // tables. 2123 // autosize row height depending on label text 2124 void AutoSizeRowLabelSize( int row ); 2125 2126 // autosize column width depending on label text 2127 void AutoSizeColLabelSize( int col ); 2128 2129 // column won't be resized to be lesser width - this must be called during 2130 // the grid creation because it won't resize the column if it's already 2131 // narrower than the minimal width 2132 void SetColMinimalWidth( int col, int width ); 2133 void SetRowMinimalHeight( int row, int width ); 2134 2135 /* These members can be used to query and modify the minimal 2136 * acceptable size of grid rows and columns. Call this function in 2137 * your code which creates the grid if you want to display cells 2138 * with a size smaller than the default acceptable minimum size. 2139 * Like the members SetColMinimalWidth and SetRowMinimalWidth, 2140 * the existing rows or columns will not be checked/resized. 2141 */ 2142 void SetColMinimalAcceptableWidth( int width ); 2143 void SetRowMinimalAcceptableHeight( int width ); 2144 int GetColMinimalAcceptableWidth() const; 2145 int GetRowMinimalAcceptableHeight() const; 2146 2147 void SetDefaultCellBackgroundColour( const wxColour& ); 2148 void SetCellBackgroundColour( int row, int col, const wxColour& ); 2149 void SetDefaultCellTextColour( const wxColour& ); 2150 2151 void SetCellTextColour( int row, int col, const wxColour& ); 2152 void SetDefaultCellFont( const wxFont& ); 2153 void SetCellFont( int row, int col, const wxFont& ); 2154 void SetDefaultCellAlignment( int horiz, int vert ); 2155 void SetCellAlignment( int row, int col, int horiz, int vert ); 2156 2157 void SetDefaultCellFitMode(wxGridFitMode fitMode); 2158 void SetCellFitMode(int row, int col, wxGridFitMode fitMode); SetDefaultCellOverflow(bool allow)2159 void SetDefaultCellOverflow( bool allow ) 2160 { SetDefaultCellFitMode(wxGridFitMode::FromOverflowFlag(allow)); } SetCellOverflow(int row,int col,bool allow)2161 void SetCellOverflow( int row, int col, bool allow ) 2162 { SetCellFitMode(row, col, wxGridFitMode::FromOverflowFlag(allow)); } 2163 2164 void SetCellSize( int row, int col, int num_rows, int num_cols ); 2165 2166 // takes ownership of the pointer 2167 void SetDefaultRenderer(wxGridCellRenderer *renderer); 2168 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer); 2169 wxGridCellRenderer *GetDefaultRenderer() const; 2170 wxGridCellRenderer* GetCellRenderer(int row, int col) const; 2171 2172 // takes ownership of the pointer 2173 void SetDefaultEditor(wxGridCellEditor *editor); 2174 void SetCellEditor(int row, int col, wxGridCellEditor *editor); 2175 wxGridCellEditor *GetDefaultEditor() const; 2176 wxGridCellEditor* GetCellEditor(int row, int col) const; 2177 2178 2179 2180 // ------ cell value accessors 2181 // GetCellValue(int row,int col)2182 wxString GetCellValue( int row, int col ) const 2183 { 2184 if ( m_table ) 2185 { 2186 return m_table->GetValue( row, col ); 2187 } 2188 else 2189 { 2190 return wxEmptyString; 2191 } 2192 } 2193 GetCellValue(const wxGridCellCoords & coords)2194 wxString GetCellValue( const wxGridCellCoords& coords ) const 2195 { return GetCellValue( coords.GetRow(), coords.GetCol() ); } 2196 2197 void SetCellValue( int row, int col, const wxString& s ); SetCellValue(const wxGridCellCoords & coords,const wxString & s)2198 void SetCellValue( const wxGridCellCoords& coords, const wxString& s ) 2199 { SetCellValue( coords.GetRow(), coords.GetCol(), s ); } 2200 2201 // returns true if the cell can't be edited 2202 bool IsReadOnly(int row, int col) const; 2203 2204 // make the cell editable/readonly 2205 void SetReadOnly(int row, int col, bool isReadOnly = true); 2206 2207 // ------ select blocks of cells 2208 // 2209 void SelectRow( int row, bool addToSelected = false ); 2210 void SelectCol( int col, bool addToSelected = false ); 2211 2212 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, 2213 bool addToSelected = false ); 2214 2215 void SelectBlock( const wxGridCellCoords& topLeft, 2216 const wxGridCellCoords& bottomRight, 2217 bool addToSelected = false ) 2218 { SelectBlock( topLeft.GetRow(), topLeft.GetCol(), 2219 bottomRight.GetRow(), bottomRight.GetCol(), 2220 addToSelected ); } 2221 2222 void SelectAll(); 2223 2224 bool IsSelection() const; 2225 2226 // ------ deselect blocks or cells 2227 // 2228 void DeselectRow( int row ); 2229 void DeselectCol( int col ); 2230 void DeselectCell( int row, int col ); 2231 2232 void ClearSelection(); 2233 2234 bool IsInSelection( int row, int col ) const; 2235 IsInSelection(const wxGridCellCoords & coords)2236 bool IsInSelection( const wxGridCellCoords& coords ) const 2237 { return IsInSelection( coords.GetRow(), coords.GetCol() ); } 2238 2239 // Efficient methods returning the selected blocks (there are few of those). 2240 wxGridBlocks GetSelectedBlocks() const; 2241 wxGridBlockCoordsVector GetSelectedRowBlocks() const; 2242 wxGridBlockCoordsVector GetSelectedColBlocks() const; 2243 2244 // Less efficient (but maybe more convenient methods) returning all 2245 // selected cells, rows or columns -- there can be many and many of those. 2246 wxGridCellCoordsArray GetSelectedCells() const; 2247 wxGridCellCoordsArray GetSelectionBlockTopLeft() const; 2248 wxGridCellCoordsArray GetSelectionBlockBottomRight() const; 2249 wxArrayInt GetSelectedRows() const; 2250 wxArrayInt GetSelectedCols() const; 2251 2252 // This function returns the rectangle that encloses the block of cells 2253 // limited by TopLeft and BottomRight cell in device coords and clipped 2254 // to the client size of the grid window. 2255 // 2256 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft, 2257 const wxGridCellCoords & bottomRight, 2258 const wxGridWindow *gridWindow = NULL) const; 2259 2260 // Access or update the selection fore/back colours GetSelectionBackground()2261 wxColour GetSelectionBackground() const 2262 { return m_selectionBackground; } GetSelectionForeground()2263 wxColour GetSelectionForeground() const 2264 { return m_selectionForeground; } 2265 SetSelectionBackground(const wxColour & c)2266 void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; } SetSelectionForeground(const wxColour & c)2267 void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; } 2268 2269 2270 // Methods for a registry for mapping data types to Renderers/Editors 2271 void RegisterDataType(const wxString& typeName, 2272 wxGridCellRenderer* renderer, 2273 wxGridCellEditor* editor); 2274 // DJC MAPTEK 2275 virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const; GetDefaultEditorForCell(const wxGridCellCoords & c)2276 wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const 2277 { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); } 2278 virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const; 2279 virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const; 2280 virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const; 2281 2282 // grid may occupy more space than needed for its rows/columns, this 2283 // function allows to set how big this extra space is SetMargins(int extraWidth,int extraHeight)2284 void SetMargins(int extraWidth, int extraHeight) 2285 { 2286 m_extraWidth = extraWidth; 2287 m_extraHeight = extraHeight; 2288 2289 CalcDimensions(); 2290 } 2291 2292 // Accessors for component windows GetGridWindow()2293 wxWindow* GetGridWindow() const { return (wxWindow*)m_gridWin; } GetFrozenCornerGridWindow()2294 wxWindow* GetFrozenCornerGridWindow()const { return (wxWindow*)m_frozenCornerGridWin; } GetFrozenRowGridWindow()2295 wxWindow* GetFrozenRowGridWindow() const { return (wxWindow*)m_frozenRowGridWin; } GetFrozenColGridWindow()2296 wxWindow* GetFrozenColGridWindow() const { return (wxWindow*)m_frozenColGridWin; } GetGridRowLabelWindow()2297 wxWindow* GetGridRowLabelWindow() const { return (wxWindow*)m_rowLabelWin; } GetGridColLabelWindow()2298 wxWindow* GetGridColLabelWindow() const { return m_colLabelWin; } GetGridCornerLabelWindow()2299 wxWindow* GetGridCornerLabelWindow() const { return (wxWindow*)m_cornerLabelWin; } 2300 2301 // Return true if native header is used by the grid. IsUsingNativeHeader()2302 bool IsUsingNativeHeader() const { return m_useNativeHeader; } 2303 2304 // This one can only be called if we are using the native header window GetGridColHeader()2305 wxHeaderCtrl *GetGridColHeader() const 2306 { 2307 wxASSERT_MSG( m_useNativeHeader, "no column header window" ); 2308 2309 // static_cast<> doesn't work without the full class declaration in 2310 // view and we prefer to avoid adding more compile-time dependencies 2311 // even at the cost of using reinterpret_cast<> 2312 return reinterpret_cast<wxHeaderCtrl *>(m_colLabelWin); 2313 } 2314 2315 // Allow adjustment of scroll increment. The default is (15, 15). SetScrollLineX(int x)2316 void SetScrollLineX(int x) { m_xScrollPixelsPerLine = x; } SetScrollLineY(int y)2317 void SetScrollLineY(int y) { m_yScrollPixelsPerLine = y; } GetScrollLineX()2318 int GetScrollLineX() const { return m_xScrollPixelsPerLine; } GetScrollLineY()2319 int GetScrollLineY() const { return m_yScrollPixelsPerLine; } 2320 2321 // ------- drag and drop 2322 #if wxUSE_DRAG_AND_DROP 2323 virtual void SetDropTarget(wxDropTarget *dropTarget) wxOVERRIDE; 2324 #endif // wxUSE_DRAG_AND_DROP 2325 2326 2327 // ------- sorting support 2328 2329 // wxGrid doesn't support sorting on its own but it can indicate the sort 2330 // order in the column header (currently only if native header control is 2331 // used though) 2332 2333 // return the column currently displaying the sort indicator or wxNOT_FOUND 2334 // if none GetSortingColumn()2335 int GetSortingColumn() const { return m_sortCol; } 2336 2337 // return true if this column is currently used for sorting IsSortingBy(int col)2338 bool IsSortingBy(int col) const { return GetSortingColumn() == col; } 2339 2340 // return the current sorting order (on GetSortingColumn()): true for 2341 // ascending sort and false for descending; it doesn't make sense to call 2342 // it if GetSortingColumn() returns wxNOT_FOUND IsSortOrderAscending()2343 bool IsSortOrderAscending() const { return m_sortIsAscending; } 2344 2345 // set the sorting column (or unsets any existing one if wxNOT_FOUND) and 2346 // the order in which to sort 2347 void SetSortingColumn(int col, bool ascending = true); 2348 2349 // unset any existing sorting column UnsetSortingColumn()2350 void UnsetSortingColumn() { SetSortingColumn(wxNOT_FOUND); } 2351 2352 #if WXWIN_COMPATIBILITY_2_8 2353 // ------ For compatibility with previous wxGrid only... 2354 // 2355 // ************************************************ 2356 // ** Don't use these in new code because they ** 2357 // ** are liable to disappear in a future ** 2358 // ** revision ** 2359 // ************************************************ 2360 // 2361 2362 wxGrid( wxWindow *parent, 2363 int x, int y, int w = wxDefaultCoord, int h = wxDefaultCoord, 2364 long style = wxWANTS_CHARS, 2365 const wxString& name = wxASCII_STR(wxPanelNameStr) ) 2366 { 2367 Init(); 2368 Create(parent, wxID_ANY, wxPoint(x, y), wxSize(w, h), style, name); 2369 } 2370 SetCellValue(const wxString & val,int row,int col)2371 void SetCellValue( const wxString& val, int row, int col ) 2372 { SetCellValue( row, col, val ); } 2373 UpdateDimensions()2374 void UpdateDimensions() 2375 { CalcDimensions(); } 2376 GetRows()2377 int GetRows() const { return GetNumberRows(); } GetCols()2378 int GetCols() const { return GetNumberCols(); } GetCursorRow()2379 int GetCursorRow() const { return GetGridCursorRow(); } GetCursorColumn()2380 int GetCursorColumn() const { return GetGridCursorCol(); } 2381 GetScrollPosX()2382 int GetScrollPosX() const { return 0; } GetScrollPosY()2383 int GetScrollPosY() const { return 0; } 2384 SetScrollX(int WXUNUSED (x))2385 void SetScrollX( int WXUNUSED(x) ) { } SetScrollY(int WXUNUSED (y))2386 void SetScrollY( int WXUNUSED(y) ) { } 2387 SetColumnWidth(int col,int width)2388 void SetColumnWidth( int col, int width ) 2389 { SetColSize( col, width ); } 2390 GetColumnWidth(int col)2391 int GetColumnWidth( int col ) const 2392 { return GetColSize( col ); } 2393 SetRowHeight(int row,int height)2394 void SetRowHeight( int row, int height ) 2395 { SetRowSize( row, height ); } 2396 2397 // GetRowHeight() is below 2398 GetViewHeight()2399 int GetViewHeight() const // returned num whole rows visible 2400 { return 0; } 2401 GetViewWidth()2402 int GetViewWidth() const // returned num whole cols visible 2403 { return 0; } 2404 SetLabelSize(int orientation,int sz)2405 void SetLabelSize( int orientation, int sz ) 2406 { 2407 if ( orientation == wxHORIZONTAL ) 2408 SetColLabelSize( sz ); 2409 else 2410 SetRowLabelSize( sz ); 2411 } 2412 GetLabelSize(int orientation)2413 int GetLabelSize( int orientation ) const 2414 { 2415 if ( orientation == wxHORIZONTAL ) 2416 return GetColLabelSize(); 2417 else 2418 return GetRowLabelSize(); 2419 } 2420 SetLabelAlignment(int orientation,int align)2421 void SetLabelAlignment( int orientation, int align ) 2422 { 2423 if ( orientation == wxHORIZONTAL ) 2424 SetColLabelAlignment( align, wxALIGN_INVALID ); 2425 else 2426 SetRowLabelAlignment( align, wxALIGN_INVALID ); 2427 } 2428 GetLabelAlignment(int orientation,int WXUNUSED (align))2429 int GetLabelAlignment( int orientation, int WXUNUSED(align) ) const 2430 { 2431 int h, v; 2432 if ( orientation == wxHORIZONTAL ) 2433 { 2434 GetColLabelAlignment( &h, &v ); 2435 return h; 2436 } 2437 else 2438 { 2439 GetRowLabelAlignment( &h, &v ); 2440 return h; 2441 } 2442 } 2443 SetLabelValue(int orientation,const wxString & val,int pos)2444 void SetLabelValue( int orientation, const wxString& val, int pos ) 2445 { 2446 if ( orientation == wxHORIZONTAL ) 2447 SetColLabelValue( pos, val ); 2448 else 2449 SetRowLabelValue( pos, val ); 2450 } 2451 GetLabelValue(int orientation,int pos)2452 wxString GetLabelValue( int orientation, int pos) const 2453 { 2454 if ( orientation == wxHORIZONTAL ) 2455 return GetColLabelValue( pos ); 2456 else 2457 return GetRowLabelValue( pos ); 2458 } 2459 GetCellTextFont()2460 wxFont GetCellTextFont() const 2461 { return m_defaultCellAttr->GetFont(); } 2462 GetCellTextFont(int WXUNUSED (row),int WXUNUSED (col))2463 wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const 2464 { return m_defaultCellAttr->GetFont(); } 2465 SetCellTextFont(const wxFont & fnt)2466 void SetCellTextFont(const wxFont& fnt) 2467 { SetDefaultCellFont( fnt ); } 2468 SetCellTextFont(const wxFont & fnt,int row,int col)2469 void SetCellTextFont(const wxFont& fnt, int row, int col) 2470 { SetCellFont( row, col, fnt ); } 2471 SetCellTextColour(const wxColour & val,int row,int col)2472 void SetCellTextColour(const wxColour& val, int row, int col) 2473 { SetCellTextColour( row, col, val ); } 2474 SetCellTextColour(const wxColour & col)2475 void SetCellTextColour(const wxColour& col) 2476 { SetDefaultCellTextColour( col ); } 2477 SetCellBackgroundColour(const wxColour & col)2478 void SetCellBackgroundColour(const wxColour& col) 2479 { SetDefaultCellBackgroundColour( col ); } 2480 SetCellBackgroundColour(const wxColour & colour,int row,int col)2481 void SetCellBackgroundColour(const wxColour& colour, int row, int col) 2482 { SetCellBackgroundColour( row, col, colour ); } 2483 GetEditable()2484 bool GetEditable() const { return IsEditable(); } 2485 void SetEditable( bool edit = true ) { EnableEditing( edit ); } GetEditInPlace()2486 bool GetEditInPlace() const { return IsCellEditControlEnabled(); } 2487 WXUNUSED(edit)2488 void SetEditInPlace(bool WXUNUSED(edit) = true) { } 2489 SetCellAlignment(int align,int row,int col)2490 void SetCellAlignment( int align, int row, int col) 2491 { SetCellAlignment(row, col, align, wxALIGN_CENTER); } SetCellAlignment(int WXUNUSED (align))2492 void SetCellAlignment( int WXUNUSED(align) ) {} SetCellBitmap(wxBitmap * WXUNUSED (bitmap),int WXUNUSED (row),int WXUNUSED (col))2493 void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col)) 2494 { } SetDividerPen(const wxPen & WXUNUSED (pen))2495 void SetDividerPen(const wxPen& WXUNUSED(pen)) { } 2496 wxPen& GetDividerPen() const; OnActivate(bool WXUNUSED (active))2497 void OnActivate(bool WXUNUSED(active)) {} 2498 2499 // ******** End of compatibility functions ********** 2500 2501 2502 2503 // ------ control IDs 2504 enum { wxGRID_CELLCTRL = 2000, 2505 wxGRID_TOPCTRL }; 2506 2507 // ------ control types 2508 enum { wxGRID_TEXTCTRL = 2100, 2509 wxGRID_CHECKBOX, 2510 wxGRID_CHOICE, 2511 wxGRID_COMBOBOX }; 2512 2513 wxDEPRECATED_INLINE(bool CanDragRowSize() const, return m_canDragRowSize; ) 2514 wxDEPRECATED_INLINE(bool CanDragColSize() const, return m_canDragColSize; ) 2515 #endif // WXWIN_COMPATIBILITY_2_8 2516 2517 2518 // override some base class functions 2519 virtual void Fit() wxOVERRIDE; 2520 virtual void SetFocus() wxOVERRIDE; 2521 2522 // implementation only 2523 void CancelMouseCapture(); 2524 2525 protected: 2526 virtual wxSize DoGetBestSize() const wxOVERRIDE; 2527 virtual void DoEnable(bool enable) wxOVERRIDE; 2528 2529 bool m_created; 2530 2531 wxGridWindow *m_gridWin; 2532 wxGridWindow *m_frozenColGridWin; 2533 wxGridWindow *m_frozenRowGridWin; 2534 wxGridWindow *m_frozenCornerGridWin; 2535 wxGridCornerLabelWindow *m_cornerLabelWin; 2536 wxGridRowLabelWindow *m_rowLabelWin; 2537 wxGridRowLabelWindow *m_rowFrozenLabelWin; 2538 2539 // the real type of the column window depends on m_useNativeHeader value: 2540 // if it is true, its dynamic type is wxHeaderCtrl, otherwise it is 2541 // wxGridColLabelWindow, use accessors below when the real type matters 2542 wxWindow *m_colLabelWin; 2543 wxWindow *m_colFrozenLabelWin; 2544 GetColLabelWindow()2545 wxGridColLabelWindow *GetColLabelWindow() const 2546 { 2547 wxASSERT_MSG( !m_useNativeHeader, "no column label window" ); 2548 2549 return reinterpret_cast<wxGridColLabelWindow *>(m_colLabelWin); 2550 } 2551 2552 wxGridTableBase *m_table; 2553 bool m_ownTable; 2554 2555 int m_numRows; 2556 int m_numCols; 2557 2558 // Number of frozen rows/columns in the beginning of the grid, 0 if none. 2559 int m_numFrozenRows; 2560 int m_numFrozenCols; 2561 2562 wxGridCellCoords m_currentCellCoords; 2563 2564 // the corners of the block being currently selected or wxGridNoCellCoords 2565 wxGridCellCoords m_selectedBlockTopLeft; 2566 wxGridCellCoords m_selectedBlockBottomRight; 2567 2568 // when selecting blocks of cells (either from the keyboard using Shift 2569 // with cursor keys, or by dragging the mouse), the selection is anchored 2570 // at m_currentCellCoords which defines one of the corners of the rectangle 2571 // being selected -- and this variable defines the other corner, i.e. it's 2572 // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on 2573 // which of them is not m_currentCellCoords 2574 // 2575 // if no block selection is in process, it is set to wxGridNoCellCoords 2576 wxGridCellCoords m_selectedBlockCorner; 2577 2578 wxGridSelection *m_selection; 2579 2580 wxColour m_selectionBackground; 2581 wxColour m_selectionForeground; 2582 2583 // NB: *never* access m_row/col arrays directly because they are created 2584 // on demand, *always* use accessor functions instead! 2585 2586 // init the m_rowHeights/Bottoms arrays with default values 2587 void InitRowHeights(); 2588 2589 int m_defaultRowHeight; 2590 int m_minAcceptableRowHeight; 2591 wxArrayInt m_rowHeights; 2592 wxArrayInt m_rowBottoms; 2593 2594 // init the m_colWidths/Rights arrays 2595 void InitColWidths(); 2596 2597 int m_defaultColWidth; 2598 int m_minAcceptableColWidth; 2599 wxArrayInt m_colWidths; 2600 wxArrayInt m_colRights; 2601 2602 int m_sortCol; 2603 bool m_sortIsAscending; 2604 2605 bool m_useNativeHeader, 2606 m_nativeColumnLabels; 2607 2608 // get the col/row coords 2609 int GetColWidth(int col) const; 2610 int GetColLeft(int col) const; 2611 int GetColRight(int col) const; 2612 2613 // this function must be public for compatibility... 2614 public: 2615 int GetRowHeight(int row) const; 2616 protected: 2617 2618 int GetRowTop(int row) const; 2619 int GetRowBottom(int row) const; 2620 2621 int m_rowLabelWidth; 2622 int m_colLabelHeight; 2623 2624 // the size of the margin left to the right and bottom of the cell area 2625 int m_extraWidth, 2626 m_extraHeight; 2627 2628 wxColour m_labelBackgroundColour; 2629 wxColour m_labelTextColour; 2630 wxFont m_labelFont; 2631 2632 int m_rowLabelHorizAlign; 2633 int m_rowLabelVertAlign; 2634 int m_colLabelHorizAlign; 2635 int m_colLabelVertAlign; 2636 int m_colLabelTextOrientation; 2637 int m_cornerLabelHorizAlign; 2638 int m_cornerLabelVertAlign; 2639 int m_cornerLabelTextOrientation; 2640 2641 bool m_defaultRowLabelValues; 2642 bool m_defaultColLabelValues; 2643 2644 wxColour m_gridLineColour; 2645 bool m_gridLinesEnabled; 2646 bool m_gridLinesClipHorz, 2647 m_gridLinesClipVert; 2648 wxColour m_cellHighlightColour; 2649 int m_cellHighlightPenWidth; 2650 int m_cellHighlightROPenWidth; 2651 wxColour m_gridFrozenBorderColour; 2652 int m_gridFrozenBorderPenWidth; 2653 2654 // common part of AutoSizeColumn/Row() 2655 void AutoSizeColOrRow(int n, bool setAsMin, wxGridDirection direction); 2656 2657 // Calculate the minimum acceptable size for labels area 2658 wxCoord CalcColOrRowLabelAreaMinSize(wxGridDirection direction); 2659 2660 // if a column has a minimal width, it will be the value for it in this 2661 // hash table 2662 wxLongToLongHashMap m_colMinWidths, 2663 m_rowMinHeights; 2664 2665 // get the minimal width of the given column/row 2666 int GetColMinimalWidth(int col) const; 2667 int GetRowMinimalHeight(int col) const; 2668 2669 // do we have some place to store attributes in? 2670 bool CanHaveAttributes() const; 2671 2672 // cell attribute cache (currently we only cache 1, may be will do 2673 // more/better later) 2674 struct CachedAttr 2675 { 2676 int row, col; 2677 wxGridCellAttr *attr; 2678 } m_attrCache; 2679 2680 // invalidates the attribute cache 2681 void ClearAttrCache(); 2682 2683 // adds an attribute to cache 2684 void CacheAttr(int row, int col, wxGridCellAttr *attr) const; 2685 2686 // looks for an attr in cache, returns true if found 2687 bool LookupAttr(int row, int col, wxGridCellAttr **attr) const; 2688 2689 // looks for the attr in cache, if not found asks the table and caches the 2690 // result 2691 wxGridCellAttr *GetCellAttr(int row, int col) const; GetCellAttr(const wxGridCellCoords & coords)2692 wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords ) const 2693 { return GetCellAttr( coords.GetRow(), coords.GetCol() ); } 2694 GetCellAttrPtr(int row,int col)2695 wxGridCellAttrPtr GetCellAttrPtr(int row, int col) const 2696 { 2697 return wxGridCellAttrPtr(GetCellAttr(row, col)); 2698 } GetCellAttrPtr(const wxGridCellCoords & coords)2699 wxGridCellAttrPtr GetCellAttrPtr(const wxGridCellCoords& coords) const 2700 { 2701 return wxGridCellAttrPtr(GetCellAttr(coords)); 2702 } 2703 2704 2705 // the default cell attr object for cells that don't have their own 2706 wxGridCellAttr* m_defaultCellAttr; 2707 2708 2709 int m_batchCount; 2710 2711 2712 wxGridTypeRegistry* m_typeRegistry; 2713 2714 enum CursorMode 2715 { 2716 WXGRID_CURSOR_SELECT_CELL, 2717 WXGRID_CURSOR_RESIZE_ROW, 2718 WXGRID_CURSOR_RESIZE_COL, 2719 WXGRID_CURSOR_SELECT_ROW, 2720 WXGRID_CURSOR_SELECT_COL, 2721 WXGRID_CURSOR_MOVE_COL 2722 }; 2723 2724 // this method not only sets m_cursorMode but also sets the correct cursor 2725 // for the given mode and, if captureMouse is not false releases the mouse 2726 // if it was captured and captures it if it must be captured 2727 // 2728 // for this to work, you should always use it and not set m_cursorMode 2729 // directly! 2730 void ChangeCursorMode(CursorMode mode, 2731 wxWindow *win = NULL, 2732 bool captureMouse = true); 2733 2734 wxWindow *m_winCapture; // the window which captured the mouse 2735 2736 // this variable is used not for finding the correct current cursor but 2737 // mainly for finding out what is going to happen if the mouse starts being 2738 // dragged right now 2739 // 2740 // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is 2741 // going on, and it is set to one of RESIZE/SELECT/MOVE values while the 2742 // corresponding operation will be started if the user starts dragging the 2743 // mouse from the current position 2744 CursorMode m_cursorMode; 2745 2746 2747 //Column positions 2748 wxArrayInt m_colAt; 2749 2750 bool m_canDragRowSize; 2751 bool m_canDragColSize; 2752 bool m_canDragColMove; 2753 bool m_canHideColumns; 2754 bool m_canDragGridSize; 2755 bool m_canDragCell; 2756 2757 // Index of the column being drag-moved or -1 if there is no move operation 2758 // in progress. 2759 int m_dragMoveCol; 2760 2761 // Last horizontal mouse position while drag-moving a column. 2762 int m_dragLastPos; 2763 2764 // Row or column (depending on m_cursorMode value) currently being resized 2765 // or -1 if there is no resize operation in progress. 2766 int m_dragRowOrCol; 2767 2768 // true if a drag operation is in progress; when this is true, 2769 // m_startDragPos is valid, i.e. not wxDefaultPosition 2770 bool m_isDragging; 2771 2772 // the position (in physical coordinates) where the user started dragging 2773 // the mouse or wxDefaultPosition if mouse isn't being dragged 2774 // 2775 // notice that this can be != wxDefaultPosition while m_isDragging is still 2776 // false because we wait until the mouse is moved some distance away before 2777 // setting m_isDragging to true 2778 wxPoint m_startDragPos; 2779 2780 bool m_waitForSlowClick; 2781 2782 wxCursor m_rowResizeCursor; 2783 wxCursor m_colResizeCursor; 2784 2785 bool m_editable; // applies to whole grid 2786 bool m_cellEditCtrlEnabled; // is in-place edit currently shown? 2787 2788 TabBehaviour m_tabBehaviour; // determines how the TAB key behaves 2789 2790 void Init(); // common part of all ctors 2791 void Create(); 2792 void CreateColumnWindow(); 2793 void CalcDimensions(); 2794 void CalcWindowSizes(); 2795 bool Redimension( wxGridTableMessage& ); 2796 2797 2798 enum EventResult 2799 { 2800 Event_Vetoed = -1, 2801 Event_Unhandled, 2802 Event_Handled, 2803 Event_CellDeleted // Event handler deleted the cell. 2804 }; 2805 2806 // Send the given grid event and returns one of the event handling results 2807 // defined above. 2808 EventResult DoSendEvent(wxGridEvent& gridEvt); 2809 2810 // Generate an event of the given type and call DoSendEvent(). 2811 EventResult SendEvent(wxEventType evtType, 2812 int row, int col, 2813 const wxMouseEvent& e); SendEvent(wxEventType evtType,const wxGridCellCoords & coords,const wxMouseEvent & e)2814 EventResult SendEvent(wxEventType evtType, 2815 const wxGridCellCoords& coords, 2816 const wxMouseEvent& e) 2817 { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); } 2818 EventResult SendEvent(wxEventType evtType, 2819 int row, int col, 2820 const wxString& s = wxString()); 2821 EventResult SendEvent(wxEventType evtType, 2822 const wxGridCellCoords& coords, 2823 const wxString& s = wxString()) 2824 { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), s); } 2825 EventResult SendEvent(wxEventType evtType, const wxString& s = wxString()) 2826 { return SendEvent(evtType, m_currentCellCoords, s); } 2827 2828 // send wxEVT_GRID_{ROW,COL}_SIZE or wxEVT_GRID_COL_AUTO_SIZE, return true 2829 // if the event was processed, false otherwise 2830 bool SendGridSizeEvent(wxEventType type, 2831 int row, int col, 2832 const wxMouseEvent& mouseEv); 2833 2834 void OnSize( wxSizeEvent& ); 2835 void OnKeyDown( wxKeyEvent& ); 2836 void OnKeyUp( wxKeyEvent& ); 2837 void OnChar( wxKeyEvent& ); 2838 2839 2840 bool SetCurrentCell( const wxGridCellCoords& coords ); SetCurrentCell(int row,int col)2841 bool SetCurrentCell( int row, int col ) 2842 { return SetCurrentCell( wxGridCellCoords(row, col) ); } 2843 2844 ShouldScrollToChildOnFocus(wxWindow * WXUNUSED (win))2845 virtual bool ShouldScrollToChildOnFocus(wxWindow* WXUNUSED(win)) wxOVERRIDE 2846 { return false; } 2847 2848 friend class WXDLLIMPEXP_FWD_CORE wxGridSelection; 2849 friend class wxGridRowOperations; 2850 friend class wxGridColumnOperations; 2851 2852 // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent() 2853 friend class wxGridCornerLabelWindow; 2854 friend class wxGridColLabelWindow; 2855 friend class wxGridRowLabelWindow; 2856 friend class wxGridWindow; 2857 friend class wxGridHeaderRenderer; 2858 2859 friend class wxGridHeaderColumn; 2860 friend class wxGridHeaderCtrl; 2861 2862 private: 2863 // This is called from both Create() and OnDPIChanged() to (re)initialize 2864 // the values in pixels, which depend on the current DPI. 2865 void InitPixelFields(); 2866 2867 // Event handler for DPI change event recomputes pixel values and relays 2868 // out the grid. 2869 void OnDPIChanged(wxDPIChangedEvent& event); 2870 2871 // implement wxScrolledCanvas method to return m_gridWin size 2872 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size) wxOVERRIDE; 2873 2874 // depending on the values of m_numFrozenRows and m_numFrozenCols, it will 2875 // create and initialize or delete the frozen windows 2876 void InitializeFrozenWindows(); 2877 2878 // redraw the grid lines, should be called after changing their attributes 2879 void RedrawGridLines(); 2880 2881 // draw all grid lines in the given cell region (unlike the public 2882 // DrawAllGridLines() which just draws all of them) 2883 void DrawRangeGridLines(wxDC& dc, const wxRegion& reg, 2884 const wxGridCellCoords& topLeft, 2885 const wxGridCellCoords& bottomRight); 2886 2887 // draw all lines from top to bottom row and left to right column in the 2888 // rectangle determined by (top, left)-(bottom, right) -- but notice that 2889 // the caller must have set up the clipping correctly, this rectangle is 2890 // only used here for optimization 2891 void DoDrawGridLines(wxDC& dc, 2892 int top, int left, 2893 int bottom, int right, 2894 int topRow, int leftCol, 2895 int bottomRight, int rightCol); 2896 2897 // common part of Clip{Horz,Vert}GridLines 2898 void DoClipGridLines(bool& var, bool clip); 2899 2900 // Redimension() helper: update m_currentCellCoords if necessary after a 2901 // grid size change 2902 void UpdateCurrentCellOnRedim(); 2903 2904 // update the sorting indicator shown in the specified column (whose index 2905 // must be valid) 2906 // 2907 // this will use GetSortingColumn() and IsSortOrderAscending() to determine 2908 // the sorting indicator to effectively show 2909 void UpdateColumnSortingIndicator(int col); 2910 2911 // update the grid after changing the columns order (common part of 2912 // SetColPos() and ResetColPos()) 2913 void RefreshAfterColPosChange(); 2914 2915 // reset the variables used during dragging operations after it ended, 2916 // either because we called EndDraggingIfNecessary() ourselves or because 2917 // we lost mouse capture 2918 void DoAfterDraggingEnd(); 2919 2920 // release the mouse capture if it's currently captured 2921 void EndDraggingIfNecessary(); 2922 2923 // return true if the grid should be refreshed right now ShouldRefresh()2924 bool ShouldRefresh() const 2925 { 2926 return !GetBatchCount() && IsShownOnScreen(); 2927 } 2928 2929 2930 // return the position (not index) of the column at the given logical pixel 2931 // position 2932 // 2933 // this always returns a valid position, even if the coordinate is out of 2934 // bounds (in which case first/last column is returned) 2935 int XToPos(int x, wxGridWindow *gridWindow) const; 2936 2937 // event handlers and their helpers 2938 // -------------------------------- 2939 2940 // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode 2941 bool DoGridCellDrag(wxMouseEvent& event, 2942 const wxGridCellCoords& coords, 2943 bool isFirstDrag); 2944 2945 // process mouse drag event in the grid window, return false if starting 2946 // dragging was vetoed by the user-defined wxEVT_GRID_CELL_BEGIN_DRAG 2947 // handler 2948 bool DoGridDragEvent(wxMouseEvent& event, 2949 const wxGridCellCoords& coords, 2950 bool isFirstDrag, 2951 wxGridWindow* gridWindow); 2952 2953 // Update the width/height of the column/row being drag-resized. 2954 void DoGridDragResize(const wxPoint& position, 2955 const wxGridOperations& oper, 2956 wxGridWindow* gridWindow); 2957 2958 // process different clicks on grid cells 2959 void DoGridCellLeftDown(wxMouseEvent& event, 2960 const wxGridCellCoords& coords, 2961 const wxPoint& pos); 2962 void DoGridCellLeftDClick(wxMouseEvent& event, 2963 const wxGridCellCoords& coords, 2964 const wxPoint& pos); 2965 void DoGridCellLeftUp(wxMouseEvent& event, 2966 const wxGridCellCoords& coords, 2967 wxGridWindow* gridWindow); 2968 2969 // process movement (but not dragging) event in the grid cell area 2970 void DoGridMouseMoveEvent(wxMouseEvent& event, 2971 const wxGridCellCoords& coords, 2972 const wxPoint& pos, 2973 wxGridWindow* gridWindow); 2974 2975 // process mouse events in the grid window 2976 void ProcessGridCellMouseEvent(wxMouseEvent& event, wxGridWindow* gridWindow); 2977 2978 // process mouse events in the row/column labels/corner windows 2979 void ProcessRowLabelMouseEvent(wxMouseEvent& event, 2980 wxGridRowLabelWindow* rowLabelWin); 2981 void ProcessColLabelMouseEvent(wxMouseEvent& event, 2982 wxGridColLabelWindow* colLabelWin); 2983 void ProcessCornerLabelMouseEvent(wxMouseEvent& event); 2984 2985 void HandleColumnAutosize(int col, const wxMouseEvent& event); 2986 2987 void DoColHeaderClick(int col); 2988 2989 void DoStartResizeRowOrCol(int col); 2990 void DoStartMoveCol(int col); 2991 2992 void DoEndDragResizeRow(const wxMouseEvent& event, wxGridWindow *gridWindow); 2993 void DoEndDragResizeCol(const wxMouseEvent& event, wxGridWindow *gridWindow); 2994 void DoEndMoveCol(int pos); 2995 2996 // Helper function returning the position (only the horizontal component 2997 // really counts) corresponding to the given column drag-resize event. 2998 // 2999 // It's a bit ugly to create a phantom mouse position when we really only 3000 // need the column width anyhow, but wxGrid code was originally written to 3001 // expect the position and not the width and it's simpler to keep it happy 3002 // by giving it the position than to change it. 3003 wxPoint GetPositionForResizeEvent(int width) const; 3004 3005 // functions called by wxGridHeaderCtrl while resizing m_dragRowOrCol 3006 void DoHeaderStartDragResizeCol(int col); 3007 void DoHeaderDragResizeCol(int width); 3008 void DoHeaderEndDragResizeCol(int width); 3009 3010 // process a TAB keypress 3011 void DoGridProcessTab(wxKeyboardState& kbdState); 3012 3013 // common implementations of methods defined for both rows and columns 3014 int PosToLinePos(int pos, bool clipToMinMax, 3015 const wxGridOperations& oper, 3016 wxGridWindow *gridWindow) const; 3017 int PosToLine(int pos, bool clipToMinMax, 3018 const wxGridOperations& oper, 3019 wxGridWindow *gridWindow) const; 3020 int PosToEdgeOfLine(int pos, const wxGridOperations& oper) const; 3021 3022 void DoMoveCursorFromKeyboard(const wxKeyboardState& kbdState, 3023 const wxGridDirectionOperations& diroper); 3024 bool DoMoveCursor(const wxKeyboardState& kbdState, 3025 const wxGridDirectionOperations& diroper); 3026 bool DoMoveCursorByPage(const wxKeyboardState& kbdState, 3027 const wxGridDirectionOperations& diroper); 3028 bool AdvanceByPage(wxGridCellCoords& coords, 3029 const wxGridDirectionOperations& diroper); 3030 bool DoMoveCursorByBlock(const wxKeyboardState& kbdState, 3031 const wxGridDirectionOperations& diroper); 3032 void AdvanceToNextNonEmpty(wxGridCellCoords& coords, 3033 const wxGridDirectionOperations& diroper); 3034 bool AdvanceByBlock(wxGridCellCoords& coords, 3035 const wxGridDirectionOperations& diroper); 3036 3037 // common part of {Insert,Delete}{Rows,Cols} 3038 bool DoModifyLines(bool (wxGridTableBase::*funcModify)(size_t, size_t), 3039 int pos, int num, bool updateLabels); 3040 // Append{Rows,Cols} is a bit different because of one less parameter 3041 bool DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t), 3042 int num, bool updateLabels); 3043 3044 // common part of Set{Col,Row}Sizes 3045 void DoSetSizes(const wxGridSizesInfo& sizeInfo, 3046 const wxGridOperations& oper); 3047 3048 // common part of Disable{Row,Col}Resize and CanDrag{Row,Col}Size 3049 void DoDisableLineResize(int line, wxGridFixedIndicesSet *& setFixed); 3050 bool DoCanResizeLine(int line, const wxGridFixedIndicesSet *setFixed) const; 3051 3052 // Helper of Render(): get grid size, origin offset and fill cell arrays 3053 void GetRenderSizes( const wxGridCellCoords& topLeft, 3054 const wxGridCellCoords& bottomRight, 3055 wxPoint& pointOffSet, wxSize& sizeGrid, 3056 wxGridCellCoordsArray& renderCells, 3057 wxArrayInt& arrayCols, wxArrayInt& arrayRows ) const; 3058 3059 // Helper of Render(): set the scale to draw the cells at the right size. 3060 void SetRenderScale( wxDC& dc, const wxPoint& pos, const wxSize& size, 3061 const wxSize& sizeGrid ); 3062 3063 // Helper of Render(): get render start position from passed parameter 3064 wxPoint GetRenderPosition( wxDC& dc, const wxPoint& position ); 3065 3066 // Helper of Render(): draws a box around the rendered area 3067 void DoRenderBox( wxDC& dc, const int& style, 3068 const wxPoint& pointOffSet, 3069 const wxSize& sizeCellArea, 3070 const wxGridCellCoords& topLeft, 3071 const wxGridCellCoords& bottomRight ); 3072 3073 // Implementation of public Set{Row,Col}Size() and {Hide,Show}{Row,Col}(). 3074 // They interpret their height or width parameter slightly different from 3075 // the public methods where -1 in it means "auto fit to the label" for the 3076 // compatibility reasons. Here it means "show a previously hidden row or 3077 // column" while 0 means "hide it" just as in the public methods. And any 3078 // positive values are handled naturally, i.e. they just specify the size. 3079 void DoSetRowSize( int row, int height ); 3080 void DoSetColSize( int col, int width ); 3081 3082 // These methods can only be called when m_useNativeHeader is true and call 3083 // SetColumnCount() and Set- or ResetColumnsOrder() as necessary on the 3084 // native wxHeaderCtrl being used. Note that the first one already calls 3085 // the second one, so it's never necessary to call both of them. 3086 void SetNativeHeaderColCount(); 3087 void SetNativeHeaderColOrder(); 3088 3089 // Return the editor which should be used for the current cell. GetCurrentCellEditorPtr()3090 wxGridCellEditorPtr GetCurrentCellEditorPtr() const 3091 { 3092 return GetCellAttrPtr(m_currentCellCoords)->GetEditorPtr 3093 ( 3094 this, 3095 m_currentCellCoords.GetRow(), 3096 m_currentCellCoords.GetCol() 3097 ); 3098 } 3099 3100 // Show/hide the cell editor for the current cell unconditionally. 3101 3102 // Return false if the editor was activated instead of being shown and also 3103 // sets m_cellEditCtrlEnabled to true when it returns true as a side effect. 3104 bool DoShowCellEditControl(const wxGridActivationSource& actSource); 3105 void DoHideCellEditControl(); 3106 3107 // Unconditionally try showing the editor for the current cell. 3108 // 3109 // Returns false if the user code vetoed wxEVT_GRID_EDITOR_SHOWN or if the 3110 // editor was simply activated and won't be permanently shown. 3111 bool DoEnableCellEditControl(const wxGridActivationSource& actSource); 3112 3113 // Unconditionally disable (accepting the changes) the editor. 3114 void DoDisableCellEditControl(); 3115 3116 // Accept the changes in the edit control, i.e. save them to the table and 3117 // dismiss the editor. Also reset m_cellEditCtrlEnabled. 3118 void DoAcceptCellEditControl(); 3119 3120 // As above, but do nothing if the control is not currently shown. 3121 void AcceptCellEditControlIfShown(); 3122 3123 // Unlike the public SaveEditControlValue(), this method doesn't check if 3124 // the edit control is shown, but just supposes that it is. 3125 void DoSaveEditControlValue(); 3126 3127 // these sets contain the indices of fixed, i.e. non-resizable 3128 // interactively, grid rows or columns and are NULL if there are no fixed 3129 // elements (which is the default) 3130 wxGridFixedIndicesSet *m_setFixedRows, 3131 *m_setFixedCols; 3132 3133 wxDECLARE_DYNAMIC_CLASS(wxGrid); 3134 wxDECLARE_EVENT_TABLE(); 3135 wxDECLARE_NO_COPY_CLASS(wxGrid); 3136 }; 3137 3138 // ---------------------------------------------------------------------------- 3139 // wxGridUpdateLocker prevents updates to a grid during its lifetime 3140 // ---------------------------------------------------------------------------- 3141 3142 class WXDLLIMPEXP_CORE wxGridUpdateLocker 3143 { 3144 public: 3145 // if the pointer is NULL, Create() can be called later 3146 wxGridUpdateLocker(wxGrid *grid = NULL) 3147 { 3148 Init(grid); 3149 } 3150 3151 // can be called if ctor was used with a NULL pointer, must not be called 3152 // more than once Create(wxGrid * grid)3153 void Create(wxGrid *grid) 3154 { 3155 wxASSERT_MSG( !m_grid, wxT("shouldn't be called more than once") ); 3156 3157 Init(grid); 3158 } 3159 ~wxGridUpdateLocker()3160 ~wxGridUpdateLocker() 3161 { 3162 if ( m_grid ) 3163 m_grid->EndBatch(); 3164 } 3165 3166 private: Init(wxGrid * grid)3167 void Init(wxGrid *grid) 3168 { 3169 m_grid = grid; 3170 if ( m_grid ) 3171 m_grid->BeginBatch(); 3172 } 3173 3174 wxGrid *m_grid; 3175 3176 wxDECLARE_NO_COPY_CLASS(wxGridUpdateLocker); 3177 }; 3178 3179 // ---------------------------------------------------------------------------- 3180 // Grid event class and event types 3181 // ---------------------------------------------------------------------------- 3182 3183 class WXDLLIMPEXP_CORE wxGridEvent : public wxNotifyEvent, 3184 public wxKeyboardState 3185 { 3186 public: wxGridEvent()3187 wxGridEvent() 3188 : wxNotifyEvent() 3189 { 3190 Init(-1, -1, -1, -1, false); 3191 } 3192 3193 wxGridEvent(int id, 3194 wxEventType type, 3195 wxObject* obj, 3196 int row = -1, int col = -1, 3197 int x = -1, int y = -1, 3198 bool sel = true, 3199 const wxKeyboardState& kbd = wxKeyboardState()) wxNotifyEvent(type,id)3200 : wxNotifyEvent(type, id), 3201 wxKeyboardState(kbd) 3202 { 3203 Init(row, col, x, y, sel); 3204 SetEventObject(obj); 3205 } 3206 3207 // explicitly specifying inline allows gcc < 3.4 to 3208 // handle the deprecation attribute even in the constructor. 3209 wxDEPRECATED_CONSTRUCTOR( 3210 wxGridEvent(int id, 3211 wxEventType type, 3212 wxObject* obj, 3213 int row, int col, 3214 int x, int y, 3215 bool sel, 3216 bool control, 3217 bool shift = false, bool alt = false, bool meta = false)); 3218 GetRow()3219 int GetRow() const { return m_row; } GetCol()3220 int GetCol() const { return m_col; } GetPosition()3221 wxPoint GetPosition() const { return wxPoint( m_x, m_y ); } Selecting()3222 bool Selecting() const { return m_selecting; } 3223 Clone()3224 virtual wxEvent *Clone() const wxOVERRIDE { return new wxGridEvent(*this); } 3225 3226 protected: 3227 int m_row; 3228 int m_col; 3229 int m_x; 3230 int m_y; 3231 bool m_selecting; 3232 3233 private: Init(int row,int col,int x,int y,bool sel)3234 void Init(int row, int col, int x, int y, bool sel) 3235 { 3236 m_row = row; 3237 m_col = col; 3238 m_x = x; 3239 m_y = y; 3240 m_selecting = sel; 3241 } 3242 3243 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent); 3244 }; 3245 3246 class WXDLLIMPEXP_CORE wxGridSizeEvent : public wxNotifyEvent, 3247 public wxKeyboardState 3248 { 3249 public: wxGridSizeEvent()3250 wxGridSizeEvent() 3251 : wxNotifyEvent() 3252 { 3253 Init(-1, -1, -1); 3254 } 3255 3256 wxGridSizeEvent(int id, 3257 wxEventType type, 3258 wxObject* obj, 3259 int rowOrCol = -1, 3260 int x = -1, int y = -1, 3261 const wxKeyboardState& kbd = wxKeyboardState()) wxNotifyEvent(type,id)3262 : wxNotifyEvent(type, id), 3263 wxKeyboardState(kbd) 3264 { 3265 Init(rowOrCol, x, y); 3266 3267 SetEventObject(obj); 3268 } 3269 3270 wxDEPRECATED_CONSTRUCTOR( 3271 wxGridSizeEvent(int id, 3272 wxEventType type, 3273 wxObject* obj, 3274 int rowOrCol, 3275 int x, int y, 3276 bool control, 3277 bool shift = false, 3278 bool alt = false, 3279 bool meta = false) ); 3280 GetRowOrCol()3281 int GetRowOrCol() const { return m_rowOrCol; } GetPosition()3282 wxPoint GetPosition() const { return wxPoint( m_x, m_y ); } 3283 Clone()3284 virtual wxEvent *Clone() const wxOVERRIDE { return new wxGridSizeEvent(*this); } 3285 3286 protected: 3287 int m_rowOrCol; 3288 int m_x; 3289 int m_y; 3290 3291 private: Init(int rowOrCol,int x,int y)3292 void Init(int rowOrCol, int x, int y) 3293 { 3294 m_rowOrCol = rowOrCol; 3295 m_x = x; 3296 m_y = y; 3297 } 3298 3299 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent); 3300 }; 3301 3302 3303 class WXDLLIMPEXP_CORE wxGridRangeSelectEvent : public wxNotifyEvent, 3304 public wxKeyboardState 3305 { 3306 public: wxGridRangeSelectEvent()3307 wxGridRangeSelectEvent() 3308 : wxNotifyEvent() 3309 { 3310 Init(wxGridNoCellCoords, wxGridNoCellCoords, false); 3311 } 3312 3313 wxGridRangeSelectEvent(int id, 3314 wxEventType type, 3315 wxObject* obj, 3316 const wxGridCellCoords& topLeft, 3317 const wxGridCellCoords& bottomRight, 3318 bool sel = true, 3319 const wxKeyboardState& kbd = wxKeyboardState()) wxNotifyEvent(type,id)3320 : wxNotifyEvent(type, id), 3321 wxKeyboardState(kbd) 3322 { 3323 Init(topLeft, bottomRight, sel); 3324 3325 SetEventObject(obj); 3326 } 3327 3328 wxDEPRECATED_CONSTRUCTOR( 3329 wxGridRangeSelectEvent(int id, 3330 wxEventType type, 3331 wxObject* obj, 3332 const wxGridCellCoords& topLeft, 3333 const wxGridCellCoords& bottomRight, 3334 bool sel, 3335 bool control, 3336 bool shift = false, 3337 bool alt = false, 3338 bool meta = false) ); 3339 GetTopLeftCoords()3340 wxGridCellCoords GetTopLeftCoords() const { return m_topLeft; } GetBottomRightCoords()3341 wxGridCellCoords GetBottomRightCoords() const { return m_bottomRight; } GetTopRow()3342 int GetTopRow() const { return m_topLeft.GetRow(); } GetBottomRow()3343 int GetBottomRow() const { return m_bottomRight.GetRow(); } GetLeftCol()3344 int GetLeftCol() const { return m_topLeft.GetCol(); } GetRightCol()3345 int GetRightCol() const { return m_bottomRight.GetCol(); } Selecting()3346 bool Selecting() const { return m_selecting; } 3347 Clone()3348 virtual wxEvent *Clone() const wxOVERRIDE { return new wxGridRangeSelectEvent(*this); } 3349 3350 protected: Init(const wxGridCellCoords & topLeft,const wxGridCellCoords & bottomRight,bool selecting)3351 void Init(const wxGridCellCoords& topLeft, 3352 const wxGridCellCoords& bottomRight, 3353 bool selecting) 3354 { 3355 m_topLeft = topLeft; 3356 m_bottomRight = bottomRight; 3357 m_selecting = selecting; 3358 } 3359 3360 wxGridCellCoords m_topLeft; 3361 wxGridCellCoords m_bottomRight; 3362 bool m_selecting; 3363 3364 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent); 3365 }; 3366 3367 3368 class WXDLLIMPEXP_CORE wxGridEditorCreatedEvent : public wxCommandEvent 3369 { 3370 public: wxGridEditorCreatedEvent()3371 wxGridEditorCreatedEvent() 3372 : wxCommandEvent() 3373 { 3374 m_row = 0; 3375 m_col = 0; 3376 m_window = NULL; 3377 } 3378 3379 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj, 3380 int row, int col, wxWindow* window); 3381 GetRow()3382 int GetRow() const { return m_row; } GetCol()3383 int GetCol() const { return m_col; } GetWindow()3384 wxWindow* GetWindow() const { return m_window; } SetRow(int row)3385 void SetRow(int row) { m_row = row; } SetCol(int col)3386 void SetCol(int col) { m_col = col; } SetWindow(wxWindow * window)3387 void SetWindow(wxWindow* window) { m_window = window; } 3388 3389 // These functions exist only for backward compatibility, use Get and 3390 // SetWindow() instead in the new code. GetControl()3391 wxControl* GetControl() { return wxDynamicCast(m_window, wxControl); } SetControl(wxControl * ctrl)3392 void SetControl(wxControl* ctrl) { m_window = ctrl; } 3393 Clone()3394 virtual wxEvent *Clone() const wxOVERRIDE { return new wxGridEditorCreatedEvent(*this); } 3395 3396 private: 3397 int m_row; 3398 int m_col; 3399 wxWindow* m_window; 3400 3401 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent); 3402 }; 3403 3404 3405 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_CELL_LEFT_CLICK, wxGridEvent ); 3406 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEvent ); 3407 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEvent ); 3408 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_CELL_RIGHT_DCLICK, wxGridEvent ); 3409 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEvent ); 3410 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEvent ); 3411 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEvent ); 3412 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent ); 3413 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_ROW_SIZE, wxGridSizeEvent ); 3414 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_COL_SIZE, wxGridSizeEvent ); 3415 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_COL_AUTO_SIZE, wxGridSizeEvent ); 3416 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_RANGE_SELECTING, wxGridRangeSelectEvent ); 3417 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_RANGE_SELECTED, wxGridRangeSelectEvent ); 3418 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_CELL_CHANGING, wxGridEvent ); 3419 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_CELL_CHANGED, wxGridEvent ); 3420 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_SELECT_CELL, wxGridEvent ); 3421 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_EDITOR_SHOWN, wxGridEvent ); 3422 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_EDITOR_HIDDEN, wxGridEvent ); 3423 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_EDITOR_CREATED, wxGridEditorCreatedEvent ); 3424 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_CELL_BEGIN_DRAG, wxGridEvent ); 3425 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_COL_MOVE, wxGridEvent ); 3426 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_COL_SORT, wxGridEvent ); 3427 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_TABBING, wxGridEvent ); 3428 3429 typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&); 3430 typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&); 3431 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&); 3432 typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreatedEvent&); 3433 3434 #define wxGridEventHandler(func) \ 3435 wxEVENT_HANDLER_CAST(wxGridEventFunction, func) 3436 3437 #define wxGridSizeEventHandler(func) \ 3438 wxEVENT_HANDLER_CAST(wxGridSizeEventFunction, func) 3439 3440 #define wxGridRangeSelectEventHandler(func) \ 3441 wxEVENT_HANDLER_CAST(wxGridRangeSelectEventFunction, func) 3442 3443 #define wxGridEditorCreatedEventHandler(func) \ 3444 wxEVENT_HANDLER_CAST(wxGridEditorCreatedEventFunction, func) 3445 3446 #define wx__DECLARE_GRIDEVT(evt, id, fn) \ 3447 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn)) 3448 3449 #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \ 3450 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn)) 3451 3452 #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \ 3453 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn)) 3454 3455 #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \ 3456 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn)) 3457 3458 #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn) 3459 #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn) 3460 #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn) 3461 #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn) 3462 #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn) 3463 #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn) 3464 #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn) 3465 #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn) 3466 #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn) 3467 #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn) 3468 #define EVT_GRID_CMD_COL_AUTO_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_AUTO_SIZE, id, fn) 3469 #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn) 3470 #define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn) 3471 #define EVT_GRID_CMD_RANGE_SELECTING(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECTING, id, fn) 3472 #define EVT_GRID_CMD_RANGE_SELECTED(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECTED, id, fn) 3473 #define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn) 3474 #define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn) 3475 #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn) 3476 #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn) 3477 #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn) 3478 #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn) 3479 #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn) 3480 #define EVT_GRID_CMD_TABBING(id, fn) wx__DECLARE_GRIDEVT(TABBING, id, fn) 3481 3482 // same as above but for any id (exists mainly for backwards compatibility but 3483 // then it's also true that you rarely have multiple grid in the same window) 3484 #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn) 3485 #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn) 3486 #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn) 3487 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn) 3488 #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn) 3489 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn) 3490 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn) 3491 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn) 3492 #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn) 3493 #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn) 3494 #define EVT_GRID_COL_AUTO_SIZE(fn) EVT_GRID_CMD_COL_AUTO_SIZE(wxID_ANY, fn) 3495 #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn) 3496 #define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn) 3497 #define EVT_GRID_RANGE_SELECTING(fn) EVT_GRID_CMD_RANGE_SELECTING(wxID_ANY, fn) 3498 #define EVT_GRID_RANGE_SELECTED(fn) EVT_GRID_CMD_RANGE_SELECTED(wxID_ANY, fn) 3499 #define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn) 3500 #define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn) 3501 #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn) 3502 #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn) 3503 #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn) 3504 #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn) 3505 #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn) 3506 #define EVT_GRID_TABBING(fn) EVT_GRID_CMD_TABBING(wxID_ANY, fn) 3507 3508 // we used to have a single wxEVT_GRID_CELL_CHANGE event but it was split into 3509 // wxEVT_GRID_CELL_CHANGING and CHANGED ones in wx 2.9.0, however the CHANGED 3510 // is basically the same as the old CHANGE event so we keep the name for 3511 // compatibility 3512 #if WXWIN_COMPATIBILITY_2_8 3513 #define wxEVT_GRID_CELL_CHANGE wxEVT_GRID_CELL_CHANGED 3514 3515 #define EVT_GRID_CMD_CELL_CHANGE EVT_GRID_CMD_CELL_CHANGED 3516 #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED 3517 #endif // WXWIN_COMPATIBILITY_2_8 3518 3519 // same as above: RANGE_SELECT was split in RANGE_SELECTING and SELECTED in 3.2, 3520 // but we keep the old name for compatibility 3521 #if WXWIN_COMPATIBILITY_3_0 3522 #define wxEVT_GRID_RANGE_SELECT wxEVT_GRID_RANGE_SELECTED 3523 3524 #define EVT_GRID_RANGE_SELECT EVT_GRID_RANGE_SELECTED 3525 #endif // WXWIN_COMPATIBILITY_3_0 3526 3527 3528 #if 0 // TODO: implement these ? others ? 3529 3530 extern const int wxEVT_GRID_CREATE_CELL; 3531 extern const int wxEVT_GRID_CHANGE_LABELS; 3532 extern const int wxEVT_GRID_CHANGE_SEL_LABEL; 3533 3534 #define EVT_GRID_CREATE_CELL(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), 3535 #define EVT_GRID_CHANGE_LABELS(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), 3536 #define EVT_GRID_CHANGE_SEL_LABEL(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), 3537 3538 #endif 3539 3540 #endif // wxUSE_GRID 3541 #endif // _WX_GENERIC_GRID_H_ 3542