X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c3baf426f87f90b82ea5a610371001e63e106d99..80a58c9968cc740b50fb92cd95d6a014a1c6e9bf:/include/wx/generic/grid.h diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index f5bb92acc1..2a31656087 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -50,9 +50,100 @@ #define WXGRID_MIN_COL_WIDTH 15 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16 - +// ---------------------------------------------------------------------------- +// forward declarations +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxGridCellAttrProviderData; +class WXDLLEXPORT wxGridRowLabelWindow; +class WXDLLEXPORT wxGridColLabelWindow; +class WXDLLEXPORT wxGridCornerLabelWindow; +class WXDLLEXPORT wxGridWindow; class WXDLLEXPORT wxGrid; +// ---------------------------------------------------------------------------- +// wxGridCellAttr: this class can be used to alter the cells appearance in +// the grid by changing their colour/font/... from default. An object of this +// class may be returned by wxGridTable::GetAttr(). +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxGridCellAttr +{ +public: + // ctors + wxGridCellAttr() + { + SetAlignment(0, 0); + } + + wxGridCellAttr(const wxColour& colText, + const wxColour& colBack, + const wxFont& font, + int hAlign, + int vAlign) + : m_colText(colText), m_colBack(colBack), m_font(font) + { + SetAlignment(hAlign, vAlign); + } + + // default copy ctor ok + + // setters + void SetTextColour(const wxColour& colText) { m_colText = colText; } + void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } + void SetFont(const wxFont& font) { m_font = font; } + void SetAlignment(int hAlign, int vAlign) + { + m_hAlign = hAlign; + m_vAlign = vAlign; + } + + // accessors + bool HasTextColour() const { return m_colText.Ok(); } + bool HasBackgroundColour() const { return m_colBack.Ok(); } + bool HasFont() const { return m_font.Ok(); } + bool HasAlignment() const { return m_hAlign || m_vAlign; } + + const wxColour& GetTextColour() const { return m_colText; } + const wxColour& GetBackgroundColour() const { return m_colBack; } + const wxFont& GetFont() const { return m_font; } + void GetAlignment(int *hAlign, int *vAlign) + { + if ( hAlign ) *hAlign = m_hAlign; + if ( vAlign ) *vAlign = m_vAlign; + } + +private: + wxColour m_colText, + m_colBack; + wxFont m_font; + int m_hAlign, + m_vAlign; +}; + +// ---------------------------------------------------------------------------- +// wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the +// cell attributes. +// ---------------------------------------------------------------------------- + +// implementation note: we separate it from wxGridTableBase because we wish to +// avoid deriving a new table class if possible, and sometimes it will be +// enough to just derive another wxGridCellAttrProvider instead + +class WXDLLEXPORT wxGridCellAttrProvider +{ +public: + wxGridCellAttrProvider(); + virtual ~wxGridCellAttrProvider(); + + virtual wxGridCellAttr *GetAttr(int row, int col) const; + virtual void SetAttr(const wxGridCellAttr *attr, int row, int col); + +private: + void InitData(); + + wxGridCellAttrProviderData *m_data; +}; ////////////////////////////////////////////////////////////////////// // @@ -93,13 +184,33 @@ public: virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {} virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {} + // Attribute handling + // + + // give us the attr provider to use - we take ownership of the pointer + void SetAttrProvider(wxGridCellAttrProvider *attrProvider); + + // get the currently used attr provider (may be NULL) + wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; } + + // by default forwarded to wxGridCellAttrProvider if any. May be + // overridden to handle attributes directly in this class. + virtual wxGridCellAttr *GetAttr( int row, int col ); + + // takes ownership of the pointer + virtual void SetAttr(const wxGridCellAttr *attr, int row, int col ); + private: wxGrid * m_view; + wxGridCellAttrProvider *m_attrProvider; DECLARE_ABSTRACT_CLASS( wxGridTableBase ); }; +// ---------------------------------------------------------------------------- +// wxGridTableMessage +// ---------------------------------------------------------------------------- // IDs for messages sent from grid table to view // @@ -296,102 +407,22 @@ private: DECLARE_EVENT_TABLE() }; - -class WXDLLEXPORT wxGridRowLabelWindow : public wxWindow -{ -public: - wxGridRowLabelWindow() { m_owner = (wxGrid *)NULL; } - wxGridRowLabelWindow( wxGrid *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size ); - -private: - wxGrid *m_owner; - - void OnPaint( wxPaintEvent& event ); - void OnMouseEvent( wxMouseEvent& event ); - void OnKeyDown( wxKeyEvent& event ); - - DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow) - DECLARE_EVENT_TABLE() -}; - - -class WXDLLEXPORT wxGridColLabelWindow : public wxWindow -{ -public: - wxGridColLabelWindow() { m_owner = (wxGrid *)NULL; } - wxGridColLabelWindow( wxGrid *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size ); - -private: - wxGrid *m_owner; - - void OnPaint( wxPaintEvent &event ); - void OnMouseEvent( wxMouseEvent& event ); - void OnKeyDown( wxKeyEvent& event ); - - DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow) - DECLARE_EVENT_TABLE() -}; - - -class WXDLLEXPORT wxGridCornerLabelWindow : public wxWindow -{ -public: - wxGridCornerLabelWindow() { m_owner = (wxGrid *)NULL; } - wxGridCornerLabelWindow( wxGrid *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size ); - -private: - wxGrid *m_owner; - - void OnMouseEvent( wxMouseEvent& event ); - void OnKeyDown( wxKeyEvent& event ); - - DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow) - DECLARE_EVENT_TABLE() -}; - - - -class WXDLLEXPORT wxGridWindow : public wxPanel -{ -public: - wxGridWindow() - { - m_owner = (wxGrid *)NULL; - m_rowLabelWin = (wxGridRowLabelWindow *)NULL; - m_colLabelWin = (wxGridColLabelWindow *)NULL; - } - - wxGridWindow( wxGrid *parent, - wxGridRowLabelWindow *rowLblWin, - wxGridColLabelWindow *colLblWin, - wxWindowID id, const wxPoint &pos, const wxSize &size ); - ~wxGridWindow(); - - void ScrollWindow( int dx, int dy, const wxRect *rect ); - -private: - wxGrid *m_owner; - wxGridRowLabelWindow *m_rowLabelWin; - wxGridColLabelWindow *m_colLabelWin; - - void OnPaint( wxPaintEvent &event ); - void OnMouseEvent( wxMouseEvent& event ); - void OnKeyDown( wxKeyEvent& ); - - DECLARE_DYNAMIC_CLASS(wxGridWindow) - DECLARE_EVENT_TABLE() -}; - - +// ---------------------------------------------------------------------------- +// wxGrid +// ---------------------------------------------------------------------------- class WXDLLEXPORT wxGrid : public wxScrolledWindow { public: wxGrid() - { Create(); } + { + m_table = (wxGridTableBase *) NULL; + m_gridWin = (wxGridWindow *) NULL; + m_rowLabelWin = (wxGridRowLabelWindow *) NULL; + m_colLabelWin = (wxGridColLabelWindow *) NULL; + m_cornerLabelWin = (wxGridCornerLabelWindow *) NULL; + m_cellEditCtrl = (wxWindow *) NULL; + } wxGrid( wxWindow *parent, wxWindowID id, @@ -414,6 +445,7 @@ public: // ------ display update functions // void CalcRowLabelsExposed( wxRegion& reg ); + void CalcColLabelsExposed( wxRegion& reg ); void CalcCellsExposed( wxRegion& reg ); @@ -426,6 +458,8 @@ public: void ProcessGridCellMouseEvent( wxMouseEvent& event ); bool ProcessTableMessage( wxGridTableMessage& ); + void DoEndDragResizeRow(); + void DoEndDragResizeCol(); wxGridTableBase * GetTable() const { return m_table; } void SetTable( wxGridTableBase *table ) { m_table = table; } @@ -440,13 +474,14 @@ public: void DrawGridCellArea( wxDC& dc ); void DrawCellBorder( wxDC& dc, const wxGridCellCoords& ); - void DrawAllGridLines( wxDC& dc ); // TODO - delete this ? + void DrawAllGridLines( wxDC& dc, const wxRegion & reg ); void DrawCell( wxDC& dc, const wxGridCellCoords& ); void DrawCellBackground( wxDC& dc, const wxGridCellCoords& ); void DrawCellValue( wxDC& dc, const wxGridCellCoords& ); void DrawRowLabels( wxDC& dc ); void DrawRowLabel( wxDC& dc, int row ); + void DrawColLabels( wxDC& dc ); void DrawColLabel( wxDC& dc, int col ); @@ -590,10 +625,12 @@ public: void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE ); void SetRowSize( int row, int height ); void SetDefaultColSize( int width, bool resizeExistingCols = FALSE ); + void SetColSize( int col, int width ); void SetDefaultCellBackgroundColour( const wxColour& ); void SetCellBackgroundColour( int row, int col, const wxColour& ); void SetDefaultCellTextColour( const wxColour& ); + void SetCellTextColour( int row, int col, const wxColour& ); void SetDefaultCellFont( const wxFont& ); void SetCellFont( int row, int col, const wxFont& ); @@ -671,17 +708,17 @@ public: // limited by TopLeft and BottomRight cell in device coords and clipped // to the client size of the grid window. // - wxRect BlockToDeviceRect( const wxGridCellCoords & TopLeft, - const wxGridCellCoords & BottomRight ); + wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft, + const wxGridCellCoords & bottomRight ); // This function returns the rectangle that encloses the selected cells // in device coords and clipped to the client size of the grid window. // wxRect SelectionToDeviceRect() { - return BlockToDeviceRect( m_selectedTopLeft, - m_selectedBottomRight ); - } + return BlockToDeviceRect( m_selectedTopLeft, + m_selectedBottomRight ); + } // ------ For compatibility with previous wxGrid only... @@ -819,6 +856,7 @@ public: bool GetEditable() { return IsEditable(); } void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); } bool GetEditInPlace() { return IsCellEditControlEnabled(); } + void SetEditInPlace(bool edit = TRUE) { } void SetCellAlignment( int align, int row, int col) @@ -846,16 +884,13 @@ public: protected: bool m_created; + bool m_displayed; wxGridWindow *m_gridWin; wxGridRowLabelWindow *m_rowLabelWin; wxGridColLabelWindow *m_colLabelWin; wxGridCornerLabelWindow *m_cornerLabelWin; - wxBoxSizer *m_mainSizer; - wxBoxSizer *m_topSizer; - wxBoxSizer *m_middleSizer; - wxGridTableBase *m_table; int m_left; @@ -897,7 +932,13 @@ protected: wxColour m_gridLineColour; bool m_gridLinesEnabled; + // default cell attributes wxFont m_defaultCellFont; + int m_defaultCellHAlign, + m_defaultCellVAlign; + + // do we have some place to store attributes in? + bool CanHaveAttributes(); wxGridCellCoordsArray m_cellsExposed; wxArrayInt m_rowsExposed; @@ -909,8 +950,7 @@ protected: int m_batchCount; int m_cursorMode; - enum { WXGRID_CURSOR_DEFAULT, - WXGRID_CURSOR_SELECT_CELL, + enum { WXGRID_CURSOR_SELECT_CELL, WXGRID_CURSOR_RESIZE_ROW, WXGRID_CURSOR_RESIZE_COL, WXGRID_CURSOR_SELECT_ROW, @@ -935,6 +975,7 @@ protected: void Create(); void Init(); void CalcDimensions(); + void CalcWindowSizes(); bool Redimension( wxGridTableMessage& ); @@ -962,9 +1003,6 @@ protected: bool SetModelValues(); - ////////////////////// Public section //////////////////// - - DECLARE_DYNAMIC_CLASS( wxGrid ) DECLARE_EVENT_TABLE() }; @@ -1137,3 +1175,4 @@ const wxEventType EVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578; #endif // #ifndef __WXGRID_H__ #endif // ifndef wxUSE_NEW_GRID +