X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/27bb2c8cb78e39d8a4def1c349e0677fd32a2c06..3c3ead1d1513a5eb79091a604f4e42b45d1bdf5d:/interface/wx/grid.h?ds=sidebyside diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 5fbea265ac..27cd239a6e 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -484,6 +484,26 @@ protected: class wxGridCellAttr { public: + /** + Kind of the attribute to retrieve. + + @see wxGridCellAttrProvider::GetAttr(), wxGridTableBase::GetAttr() + */ + enum wxAttrKind + { + /// Return the combined effective attribute for the cell. + Any, + + /// Return the attribute explicitly set for this cell. + Cell, + + /// Return the attribute set for this cells row. + Row, + + /// Return the attribute set for this cells column. + Col + }; + /** Default constructor. */ @@ -622,6 +642,282 @@ public: void SetTextColour(const wxColour& colText); }; +/** + Base class for corner window renderer. + + This is the simplest of all header renderers and only has a single + function. + + @see wxGridCellAttrProvider::GetCornerRenderer() + + @since 2.9.1 + */ +class wxGridCornerHeaderRenderer +{ +public: + /** + Called by the grid to draw the corner window border. + + This method is responsible for drawing the border inside the given @a + rect and adjusting the rectangle size to correspond to the area inside + the border, i.e. usually call wxRect::Deflate() to account for the + border width. + + @param grid + The grid whose corner window is being drawn. + @param dc + The device context to use for drawing. + @param rect + Input/output parameter which contains the border rectangle on input + and should be updated to contain the area inside the border on + function return. + */ + virtual void DrawBorder(const wxGrid& grid, + wxDC& dc, + wxRect& rect) const = 0; +}; +/** + Common base class for row and column headers renderers. + + @see wxGridColumnHeaderRenderer, wxGridRowHeaderRenderer + + @since 2.9.1 + */ +class wxGridHeaderLabelsRenderer : public wxGridCornerHeaderRenderer +{ +public: + /** + Called by the grid to draw the specified label. + + Notice that the base class DrawBorder() method is called before this + one. + + The default implementation uses wxGrid::GetLabelTextColour() and + wxGrid::GetLabelFont() to draw the label. + */ + virtual void DrawLabel(const wxGrid& grid, + wxDC& dc, + const wxString& value, + const wxRect& rect, + int horizAlign, + int vertAlign, + int textOrientation) const; +}; + +/** + Base class for row headers renderer. + + This is the same as wxGridHeaderLabelsRenderer currently but we still use a + separate class for it to distinguish it from wxGridColumnHeaderRenderer. + + @see wxGridRowHeaderRendererDefault + + @see wxGridCellAttrProvider::GetRowHeaderRenderer() + + @since 2.9.1 + */ +class wxGridRowHeaderRenderer : public wxGridHeaderLabelsRenderer +{ +}; + +/** + Base class for column headers renderer. + + This is the same as wxGridHeaderLabelsRenderer currently but we still use a + separate class for it to distinguish it from wxGridRowHeaderRenderer. + + @see wxGridColumnHeaderRendererDefault + + @see wxGridCellAttrProvider::GetColumnHeaderRenderer() + + @since 2.9.1 + */ +class wxGridColumnHeaderRenderer : public wxGridHeaderLabelsRenderer +{ +}; + +/** + Default row header renderer. + + You may derive from this class if you need to only override one of its + methods (i.e. either DrawLabel() or DrawBorder()) but continue to use the + default implementation for the other one. + + @see wxGridColumnHeaderRendererDefault + + @since 2.9.1 + */ +class wxGridRowHeaderRendererDefault : public wxGridRowHeaderRendererDefault +{ +public: + /// Implement border drawing for the row labels. + virtual void DrawBorder(const wxGrid& grid, + wxDC& dc, + wxRect& rect) const; +}; + +/** + Default column header renderer. + + @see wxGridRowHeaderRendererDefault + + @since 2.9.1 + */ +class wxGridColumnHeaderRendererDefault : public wxGridColumnHeaderRenderer +{ +public: + /// Implement border drawing for the column labels. + virtual void DrawBorder(const wxGrid& grid, + wxDC& dc, + wxRect& rect) const; +}; + +/** + Default corner window renderer. + + @see wxGridColumnHeaderRendererDefault, wxGridRowHeaderRendererDefault + + @since 2.9.1 + */ +class wxGridCornerHeaderRendererDefault : public wxGridCornerHeaderRenderer +{ +public: + /// Implement border drawing for the corner window. + virtual void DrawBorder(const wxGrid& grid, + wxDC& dc, + wxRect& rect) const; +}; + +/** + Class providing attributes to be used for the grid cells. + + This class both defines an interface which grid cell attributes providers + should implement -- and which can be implemented differently in derived + classes -- and a default implementation of this interface which is often + good enough to be used without modification, especially with not very large + grids for which the efficiency of attributes storage hardly matters (see + the discussion below). + + An object of this class can be associated with a wxGrid using + wxGridTableBase::SetAttrProvider() but it's not necessary to call it if you + intend to use the default provider as it is used by wxGridTableBase by + default anyhow. + + Notice that while attributes provided by this class can be set for + individual cells using SetAttr() or the entire rows or columns using + SetRowAttr() and SetColAttr() they are always retrieved using GetAttr() + function. + + + The default implementation of this class stores the attributes passed to + its SetAttr(), SetRowAttr() and SetColAttr() in a straightforward way. A + derived class may use its knowledge about how the attributes are used in + your program to implement it much more efficiently: for example, using a + special background colour for all even-numbered rows can be implemented by + simply returning the same attribute from GetAttr() if the row number is + even instead of having to store N/2 row attributes where N is the total + number of rows in the grid. + + Notice that objects of this class can't be copied. + */ +class wxGridCellAttrProvider : public wxClientDataContainer +{ +public: + /// Trivial default constructor. + wxGridCellAttrProvider(); + + /// Destructor releases any attributes held by this class. + virtual ~wxGridCellAttrProvider(); + + /** + Get the attribute to use for the specified cell. + + If wxGridCellAttr::Any is used as @a kind value, this function combines + the attributes set for this cell using SetAttr() and those for its row + or column (set with SetRowAttr() or SetColAttr() respectively), with + the cell attribute having the highest precedence. + + Notice that the caller must call DecRef() on the returned pointer if it + is non-@NULL. + + @param row + The row of the cell. + @param col + The column of the cell. + @param kind + The kind of the attribute to return. + @return + The attribute to use which should be DecRef()'d by caller or @NULL + if no attributes are defined for this cell. + */ + virtual wxGridCellAttr *GetAttr(int row, int col, + wxGridCellAttr::wxAttrKind kind) const; + + /** + Setting attributes. + + All these functions take ownership of the attribute passed to them, + i.e. will call DecRef() on it themselves later and so it should not be + destroyed by the caller. And the attribute can be @NULL to reset a + previously set value. + */ + //@{ + + /// Set attribute for the specified cell. + virtual void SetAttr(wxGridCellAttr *attr, int row, int col); + + /// Set attribute for the specified row. + virtual void SetRowAttr(wxGridCellAttr *attr, int row); + + /// Set attribute for the specified column. + virtual void SetColAttr(wxGridCellAttr *attr, int col); + + //@} + + /** + Getting header renderers. + + These functions return the renderers for the given row or column header + label and the corner window. Unlike cell attributes, these objects are + not reference counted and are never @NULL so they are returned by + reference and not pointer and DecRef() shouldn't (and can't) be called + for them. + + All these functions were added in wxWidgets 2.9.1. + */ + //@{ + + /** + Return the renderer used for drawing column headers. + + By default wxGridColumnHeaderRendererDefault is returned. + + @see wxGrid::SetUseNativeColLabels(), wxGrid::UseNativeColHeader() + + @since 2.9.1 + */ + virtual const wxGridColumnHeaderRenderer& GetColumnHeaderRenderer(int col); + + /** + Return the renderer used for drawing row headers. + + By default wxGridRowHeaderRendererDefault is returned. + + @since 2.9.1 + */ + virtual const wxGridRowHeaderRenderer& GetRowHeaderRenderer(int row); + + /** + Return the renderer used for drawing the corner window. + + By default wxGridCornerHeaderRendererDefault is returned. + + @since 2.9.1 + */ + virtual const wxGridCornerHeaderRenderer& GetCornerRenderer(); + + //@} +}; /** @@ -3546,7 +3842,8 @@ public: The user double-clicked a label with the right mouse button. Processes a @c wxEVT_GRID_LABEL_RIGHT_DCLICK event type. @event{EVT_GRID_SELECT_CELL(func)} - The user moved to, and selected a cell. Processes a + The given cell was made current, either by user or by the program via a + call to SetGridCursor() or GoToCell(). Processes a @c wxEVT_GRID_SELECT_CELL event type. @event{EVT_GRID_COL_MOVE(func)} The user tries to change the order of the columns in the grid by