+// ----------------------------------------------------------------------------
+// operations classes abstracting the difference between operating on rows and
+// columns
+// ----------------------------------------------------------------------------
+
+// This class allows to write a function only once because by using its methods
+// it will apply to both columns and rows.
+//
+// This is an abstract interface definition, the two concrete implementations
+// below should be used when working with rows and columns respectively.
+class wxGridOperations
+{
+public:
+ // Returns the operations in the other direction, i.e. wxGridRowOperations
+ // if this object is a wxGridColumnOperations and vice versa.
+ virtual wxGridOperations& Dual() const = 0;
+
+ // Return the number of rows or columns.
+ virtual int GetNumberOfLines(const wxGrid *grid) const = 0;
+
+ // Return the selection mode which allows selecting rows or columns.
+ virtual wxGrid::wxGridSelectionModes GetSelectionMode() const = 0;
+
+ // Make a wxGridCellCoords from the given components: thisDir is row or
+ // column and otherDir is column or row
+ virtual wxGridCellCoords MakeCoords(int thisDir, int otherDir) const = 0;
+
+ // Calculate the scrolled position of the given abscissa or ordinate.
+ virtual int CalcScrolledPosition(wxGrid *grid, int pos) const = 0;
+
+ // Selects the horizontal or vertical component from the given object.
+ virtual int Select(const wxPoint& pt) const = 0;
+ virtual int Select(const wxSize& sz) const = 0;
+ virtual int Select(const wxRect& r) const = 0;
+ virtual int& Select(wxRect& r) const = 0;
+
+ // Returns width or height of the rectangle
+ virtual int& SelectSize(wxRect& r) const = 0;
+
+ // Make a wxSize such that Select() applied to it returns first component
+ virtual wxSize MakeSize(int first, int second) const = 0;
+
+
+ // Draws a line parallel to the row or column, i.e. horizontal or vertical:
+ // pos is the vertical or horizontal position of the line and start and end
+ // are the coordinates of the line extremities in the other direction
+ virtual void
+ DrawParallelLine(wxDC& dc, int start, int end, int pos) const = 0;
+
+
+ // Return the row or column at the given pixel coordinate.
+ virtual int PosToLine(wxGrid *grid, int pos, bool clip = false) const = 0;
+
+ // Get the top/left position, in pixels, of the given row or column
+ virtual int GetLineStartPos(const wxGrid *grid, int line) const = 0;
+
+ // Get wxGrid::m_rowBottoms/m_colRights array
+ virtual const wxArrayInt& GetLineEnds(const wxGrid *grid) const = 0;
+
+ // Get default height row height or column width
+ virtual int GetDefaultLineSize(const wxGrid *grid) const = 0;
+
+ // Return the minimal acceptable row height or column width
+ virtual int GetMinimalAcceptableLineSize(const wxGrid *grid) const = 0;
+
+ // Return the minimal row height or column width
+ virtual int GetMinimalLineSize(const wxGrid *grid, int line) const = 0;
+
+ // Set the row height or column width
+ virtual void SetLineSize(wxGrid *grid, int line, int size) const = 0;
+
+
+ // Return the index of the line at the given position
+ //
+ // NB: currently this is always identity for the rows as reordering is only
+ // implemented for the lines
+ virtual int GetLineAt(const wxGrid *grid, int line) const = 0;
+
+
+ // Get the row or column label window
+ virtual wxWindow *GetHeaderWindow(wxGrid *grid) const = 0;
+
+ // Get the width or height of the row or column label window
+ virtual int GetHeaderWindowSize(wxGrid *grid) const = 0;
+};
+
+class wxGridRowOperations : public wxGridOperations
+{
+public:
+ virtual wxGridOperations& Dual() const;
+
+ virtual int GetNumberOfLines(const wxGrid *grid) const
+ { return grid->GetNumberRows(); }
+
+ virtual wxGrid::wxGridSelectionModes GetSelectionMode() const
+ { return wxGrid::wxGridSelectRows; }
+
+ virtual wxGridCellCoords MakeCoords(int thisDir, int otherDir) const
+ { return wxGridCellCoords(thisDir, otherDir); }
+
+ virtual int CalcScrolledPosition(wxGrid *grid, int pos) const
+ { return grid->CalcScrolledPosition(wxPoint(pos, 0)).x; }
+
+ virtual int Select(const wxPoint& pt) const { return pt.x; }
+ virtual int Select(const wxSize& sz) const { return sz.x; }
+ virtual int Select(const wxRect& r) const { return r.x; }
+ virtual int& Select(wxRect& r) const { return r.x; }
+ virtual int& SelectSize(wxRect& r) const { return r.width; }
+ virtual wxSize MakeSize(int first, int second) const
+ { return wxSize(first, second); }
+
+ virtual void DrawParallelLine(wxDC& dc, int start, int end, int pos) const
+ { dc.DrawLine(start, pos, end, pos); }
+
+ virtual int PosToLine(wxGrid *grid, int pos, bool clip = false) const
+ { return grid->YToRow(pos, clip); }
+ virtual int GetLineStartPos(const wxGrid *grid, int line) const
+ { return grid->GetRowTop(line); }
+ virtual const wxArrayInt& GetLineEnds(const wxGrid *grid) const
+ { return grid->m_rowBottoms; }
+ virtual int GetDefaultLineSize(const wxGrid *grid) const
+ { return grid->GetDefaultRowSize(); }
+ virtual int GetMinimalAcceptableLineSize(const wxGrid *grid) const
+ { return grid->GetRowMinimalAcceptableHeight(); }
+ virtual int GetMinimalLineSize(const wxGrid *grid, int line) const
+ { return grid->GetRowMinimalHeight(line); }
+ virtual void SetLineSize(wxGrid *grid, int line, int size) const
+ { grid->SetRowSize(line, size); }
+
+ virtual int GetLineAt(const wxGrid * WXUNUSED(grid), int line) const
+ { return line; } // TODO: implement row reordering
+
+ virtual wxWindow *GetHeaderWindow(wxGrid *grid) const
+ { return grid->GetGridRowLabelWindow(); }
+ virtual int GetHeaderWindowSize(wxGrid *grid) const
+ { return grid->GetRowLabelSize(); }
+};
+
+class wxGridColumnOperations : public wxGridOperations
+{
+public:
+ virtual wxGridOperations& Dual() const;
+
+ virtual int GetNumberOfLines(const wxGrid *grid) const
+ { return grid->GetNumberCols(); }
+
+ virtual wxGrid::wxGridSelectionModes GetSelectionMode() const
+ { return wxGrid::wxGridSelectColumns; }
+
+ virtual wxGridCellCoords MakeCoords(int thisDir, int otherDir) const
+ { return wxGridCellCoords(otherDir, thisDir); }
+
+ virtual int CalcScrolledPosition(wxGrid *grid, int pos) const
+ { return grid->CalcScrolledPosition(wxPoint(0, pos)).y; }
+
+ virtual int Select(const wxPoint& pt) const { return pt.y; }
+ virtual int Select(const wxSize& sz) const { return sz.y; }
+ virtual int Select(const wxRect& r) const { return r.y; }
+ virtual int& Select(wxRect& r) const { return r.y; }
+ virtual int& SelectSize(wxRect& r) const { return r.height; }
+ virtual wxSize MakeSize(int first, int second) const
+ { return wxSize(second, first); }
+
+ virtual void DrawParallelLine(wxDC& dc, int start, int end, int pos) const
+ { dc.DrawLine(pos, start, pos, end); }
+
+ virtual int PosToLine(wxGrid *grid, int pos, bool clip = false) const
+ { return grid->XToCol(pos, clip); }
+ virtual int GetLineStartPos(const wxGrid *grid, int line) const
+ { return grid->GetColLeft(line); }
+ virtual const wxArrayInt& GetLineEnds(const wxGrid *grid) const
+ { return grid->m_colRights; }
+ virtual int GetDefaultLineSize(const wxGrid *grid) const
+ { return grid->GetDefaultColSize(); }
+ virtual int GetMinimalAcceptableLineSize(const wxGrid *grid) const
+ { return grid->GetColMinimalAcceptableWidth(); }
+ virtual int GetMinimalLineSize(const wxGrid *grid, int line) const
+ { return grid->GetColMinimalWidth(line); }
+ virtual void SetLineSize(wxGrid *grid, int line, int size) const
+ { grid->SetColSize(line, size); }
+
+ virtual int GetLineAt(const wxGrid *grid, int line) const
+ { return grid->GetColAt(line); }
+
+ virtual wxWindow *GetHeaderWindow(wxGrid *grid) const
+ { return grid->GetGridColLabelWindow(); }
+ virtual int GetHeaderWindowSize(wxGrid *grid) const
+ { return grid->GetColLabelSize(); }
+};
+
+wxGridOperations& wxGridRowOperations::Dual() const
+{
+ static wxGridColumnOperations s_colOper;
+
+ return s_colOper;
+}
+
+wxGridOperations& wxGridColumnOperations::Dual() const
+{
+ static wxGridRowOperations s_rowOper;
+
+ return s_rowOper;
+}
+
+