home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2233.zip / wxOS2-2_3_3.zip / wxWindows-2.3.3 / include / wx / generic / grid.h < prev    next >
C/C++ Source or Header  |  2002-09-08  |  75KB  |  2,040 lines

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