]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/generic/grid.h
moved wxMenuBar::FindMenu(title) from MSW to common code
[wxWidgets.git] / include / wx / generic / grid.h
index 64a2dcab8802f2c97d8e95f8b20aaf7acb8ce3ac..9df770ec8ea56dd2d2b93ad0caf8dd6ef6212bae 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        grid.h
+// Name:        wx/generic/grid.h
 // Purpose:     wxGrid and related classes
 // Author:      Michael Bedward (based on code by Julian Smart, Robin Dunn)
 // Modified by:
@@ -9,7 +9,6 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-
 #include "wx/defs.h"
 
 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
@@ -23,6 +22,7 @@
 #pragma interface "grid.h"
 #endif
 
+#include "wx/hash.h"
 #include "wx/panel.h"
 #include "wx/scrolwin.h"
 #include "wx/string.h"
@@ -61,6 +61,7 @@ class WXDLLEXPORT wxGridCornerLabelWindow;
 class WXDLLEXPORT wxGridRowLabelWindow;
 class WXDLLEXPORT wxGridTableBase;
 class WXDLLEXPORT wxGridWindow;
+class WXDLLEXPORT wxGridTypeRegistry;
 
 class WXDLLEXPORT wxCheckBox;
 class WXDLLEXPORT wxTextCtrl;
@@ -146,6 +147,10 @@ public:
     // colours/fonts for it
     virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
 
+    // Draws the part of the cell not occupied by the control: the base class
+    // version just fills it with background colour from the attribute
+    virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
+
     // Fetch the value from the table and prepare the edit control
     // to begin editing.  Set the focus to the edit control.
     virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
@@ -164,6 +169,10 @@ public:
     // that first key if desired.
     virtual void StartingKey(wxKeyEvent& event);
 
+    // if the editor is enabled by clicking on the cell, this method will be
+    // called
+    virtual void StartingClick();
+
     // Some types of controls on some platforms may need some help
     // with the Return key.
     virtual void HandleReturn(wxKeyEvent& event);
@@ -193,6 +202,8 @@ public:
                         wxWindowID id,
                         wxEvtHandler* evtHandler);
 
+    virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
+
     virtual void BeginEdit(int row, int col, wxGrid* grid);
     virtual bool EndEdit(int row, int col,  bool saveValue, wxGrid* grid);
 
@@ -222,15 +233,13 @@ public:
     virtual bool EndEdit(int row, int col,  bool saveValue, wxGrid* grid);
 
     virtual void Reset();
-    virtual void StartingKey(wxKeyEvent& event);
+    virtual void StartingClick();
 
 protected:
     wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
 
 private:
     bool m_startValue;
-
-    wxRect m_rectCell;  // the total size of the cell
 };
 
 // ----------------------------------------------------------------------------
@@ -301,8 +310,8 @@ public:
     const wxColour& GetBackgroundColour() const;
     const wxFont& GetFont() const;
     void GetAlignment(int *hAlign, int *vAlign) const;
-    wxGridCellRenderer *GetRenderer() const;
-    wxGridCellEditor *GetEditor() const;
+    wxGridCellRenderer *GetRenderer(wxGridCellRenderer* def) const;
+    wxGridCellEditor *GetEditor(wxGridCellEditor* def) const;
 
     bool IsReadOnly() const { return m_isReadOnly; }
 
@@ -398,9 +407,27 @@ public:
     //
     virtual long GetNumberRows() = 0;
     virtual long GetNumberCols() = 0;
-    virtual wxString GetValue( int row, int col ) = 0;
-    virtual void SetValue( int row, int col, const wxString& s ) = 0;
     virtual bool IsEmptyCell( int row, int col ) = 0;
+    virtual wxString GetValue( int row, int col ) = 0;
+    virtual void SetValue( int row, int col, const wxString& value ) = 0;
+
+    // Data type determination and value access
+    virtual wxString GetTypeName( int row, int col );
+    virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
+    virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
+
+    virtual long GetValueAsLong( int row, int col );
+    virtual double GetValueAsDouble( int row, int col );
+    virtual bool GetValueAsBool( int row, int col );
+
+    virtual void SetValueAsLong( int row, int col, long value );
+    virtual void SetValueAsDouble( int row, int col, double value );
+    virtual void SetValueAsBool( int row, int col, bool value );
+
+    // For user defined types
+    virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
+    virtual void  SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
+
 
     // Overriding these is optional
     //
@@ -429,12 +456,17 @@ public:
     // get the currently used attr provider (may be NULL)
     wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; }
 
+    // Does this table allow attributes?  Default implementation creates
+    // a wxGridCellAttrProvider if necessary.
+    virtual bool CanHaveAttributes();
+
+
     // change row/col number in attribute if needed
-    void UpdateAttrRows( size_t pos, int numRows );
-    void UpdateAttrCols( size_t pos, int numCols );
+    virtual void UpdateAttrRows( size_t pos, int numRows );
+    virtual void UpdateAttrCols( size_t pos, int numCols );
 
     // by default forwarded to wxGridCellAttrProvider if any. May be
-    // overridden to handle attributes directly in this class.
+    // overridden to handle attributes directly in the table.
     virtual wxGridCellAttr *GetAttr( int row, int col );
 
     // these functions take ownership of the pointer
@@ -552,11 +584,13 @@ private:
 
 
 
-//////////////////////////////////////////////////////////////////////
-//
+// ============================================================================
 //  Grid view classes
-//
-//////////////////////////////////////////////////////////////////////
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxGridCellCoords: location of a cell in the grid
+// ----------------------------------------------------------------------------
 
 class WXDLLEXPORT wxGridCellCoords
 {
@@ -612,8 +646,6 @@ extern wxRect           wxGridNoCellRect;
 //
 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray);
 
-
-
 // ----------------------------------------------------------------------------
 // wxGrid
 // ----------------------------------------------------------------------------
@@ -678,7 +710,11 @@ public:
     void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
     void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
     void DrawCell( wxDC& dc, const wxGridCellCoords& );
-    void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
+    void DrawHighlight(wxDC& dc);
+
+    // this function is called when the current cell highlight must be redrawn
+    // and may be overridden by the user
+    virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
 
     void DrawRowLabels( wxDC& dc );
     void DrawRowLabel( wxDC& dc, int row );
@@ -803,6 +839,13 @@ public:
     void     SetRowLabelValue( int row, const wxString& );
     void     SetColLabelValue( int col, const wxString& );
     void     SetGridLineColour( const wxColour& );
+    
+    void     EnableDragRowSize( bool enable = TRUE );
+    void     DisableDragRowSize() { EnableDragRowSize( FALSE ); }
+    bool     CanDragRowSize() { return m_canDragRowSize; }
+    void     EnableDragColSize( bool enable = TRUE );
+    void     DisableDragColSize() { EnableDragColSize( FALSE ); }
+    bool     CanDragColSize() { return m_canDragColSize; }
 
     // this sets the specified attribute for all cells in this row/col
     void     SetRowAttr(int row, wxGridCellAttr *attr);
@@ -831,6 +874,12 @@ public:
     void     SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
 
     void     SetColSize( int col, int width );
+
+    // column won't be resized to be lesser width - this must be called during
+    // the grid creation because it won't resize the column if it's already
+    // narrower than the minimal width
+    void     SetColMinimalWidth( int col, int width );
+
     void     SetDefaultCellBackgroundColour( const wxColour& );
     void     SetCellBackgroundColour( int row, int col, const wxColour& );
     void     SetDefaultCellTextColour( const wxColour& );
@@ -854,6 +903,7 @@ public:
     wxGridCellEditor* GetCellEditor(int row, int col);
 
 
+
     // ------ cell value accessors
     //
     wxString GetCellValue( int row, int col )
@@ -950,6 +1000,16 @@ public:
     void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; }
 
 
+    // Methods for a registry for mapping data types to Renderers/Editors
+    void RegisterDataType(const wxString& typeName,
+                          wxGridCellRenderer* renderer,
+                          wxGridCellEditor* editor);
+    wxGridCellEditor* GetDefaultEditorForCell(int row, int col);
+    wxGridCellRenderer* GetDefaultRendererForCell(int row, int col);
+    wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName);
+    wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName);
+
+
 
     // ------ For compatibility with previous wxGrid only...
     //
@@ -995,8 +1055,7 @@ public:
     void SetRowHeight( int row, int height )
         { SetRowSize( row, height ); }
 
-    int GetRowHeight( int row )
-        { return GetRowSize( row ); }
+    // GetRowHeight() is below
 
     int GetViewHeight() // returned num whole rows visible
         { return 0; }
@@ -1142,13 +1201,36 @@ protected:
     wxColour    m_selectionBackground;
     wxColour    m_selectionForeground;
 
+    // NB: *never* access m_row/col arrays directly because they are created
+    //     on demand, *always* use accessor functions instead!
+
+    // init the m_rowHeights/Bottoms arrays with default values
+    void InitRowHeights();
+
     int        m_defaultRowHeight;
     wxArrayInt m_rowHeights;
     wxArrayInt m_rowBottoms;
 
+    // init the m_colWidths/Rights arrays
+    void InitColWidths();
+
     int        m_defaultColWidth;
     wxArrayInt m_colWidths;
     wxArrayInt m_colRights;
+
+    // get the col/row coords
+    int GetColWidth(int col) const;
+    int GetColLeft(int col) const;
+    int GetColRight(int col) const;
+
+    // this function must be public for compatibility...
+public:
+    int GetRowHeight(int row) const;
+protected:
+
+    int GetRowTop(int row) const;
+    int GetRowBottom(int row) const;
+
     int m_rowLabelWidth;
     int m_colLabelHeight;
 
@@ -1167,6 +1249,12 @@ protected:
     wxColour   m_gridLineColour;
     bool       m_gridLinesEnabled;
 
+    // if a column has a minimal width, it will be the value for it in this
+    // hash table
+    wxHashTable m_colMinWidths;
+
+    // get the minimal width of the given column
+    int        GetColMinimalWidth(int col) const;
 
     // do we have some place to store attributes in?
     bool CanHaveAttributes();
@@ -1213,6 +1301,9 @@ protected:
     bool m_inOnKeyDown;
     int  m_batchCount;
 
+
+    wxGridTypeRegistry*    m_typeRegistry;
+
     enum CursorMode
     {
         WXGRID_CURSOR_SELECT_CELL,
@@ -1235,6 +1326,8 @@ protected:
     wxWindow *m_winCapture;     // the window which captured the mouse
     CursorMode m_cursorMode;
 
+    bool    m_canDragRowSize;
+    bool    m_canDragColSize;
     int     m_dragLastPos;
     int     m_dragRowOrCol;
     bool    m_isDragging;
@@ -1290,11 +1383,9 @@ protected:
 
 
 
-
-
-//
-// ------ Grid event class and event types
-//
+// ----------------------------------------------------------------------------
+// Grid event class and event types
+// ----------------------------------------------------------------------------
 
 class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
 {