#if wxUSE_GRID
+#include "wx/hashmap.h"
+
#include "wx/scrolwin.h"
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_FWD_CORE wxSpinCtrl;
#endif
+class wxGridFixedIndicesSet;
+
class wxGridOperations;
class wxGridRowOperations;
class wxGridColumnOperations;
// class is not documented and is not public at all
// ----------------------------------------------------------------------------
-class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer
+class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer, public wxRefCounter
{
public:
- wxGridCellWorker() { m_nRef = 1; }
-
- // this class is ref counted: it is created with ref count of 1, so
- // calling DecRef() once will delete it. Calling IncRef() allows to lock
- // it until the matching DecRef() is called
- void IncRef() { m_nRef++; }
- void DecRef() { if ( --m_nRef == 0 ) delete this; }
+ wxGridCellWorker() { }
// interpret renderer parameters: arbitrary string whose interpretatin is
// left to the derived classes
virtual ~wxGridCellWorker();
private:
- size_t m_nRef;
-
// suppress the stupid gcc warning about the class having private dtor and
// no friends
friend class wxGridCellWorkerDummyFriend;
// new value in its string form in the newval output parameter.
//
// This should also store the new value in its real type internally so that
- // it could be used by ApplyEdit().
- virtual bool EndEdit(const wxString& oldval, wxString *newval) = 0;
+ // it could be used by ApplyEdit() but it must not modify the grid as the
+ // change could still be vetoed.
+ virtual bool EndEdit(int row, int col, const wxGrid *grid,
+ const wxString& oldval, wxString *newval) = 0;
// Complete the editing of the current cell by storing the value saved by
// the previous call to EndEdit() in the grid
// no friends
friend class wxGridCellEditorDummyFriend;
- DECLARE_NO_COPY_CLASS(wxGridCellEditor)
+ wxDECLARE_NO_COPY_CLASS(wxGridCellEditor);
};
// class may be returned by wxGridTable::GetAttr().
// ----------------------------------------------------------------------------
-class WXDLLIMPEXP_ADV wxGridCellAttr : public wxClientDataContainer
+class WXDLLIMPEXP_ADV wxGridCellAttr : public wxClientDataContainer, public wxRefCounter
{
public:
enum wxAttrKind
wxGridCellAttr *Clone() const;
void MergeWith(wxGridCellAttr *mergefrom);
- // this class is ref counted: it is created with ref count of 1, so
- // calling DecRef() once will delete it. Calling IncRef() allows to lock
- // it until the matching DecRef() is called
- void IncRef() { m_nRef++; }
- void DecRef() { if ( --m_nRef == 0 ) delete this; }
-
// setters
void SetTextColour(const wxColour& colText) { m_colText = colText; }
void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
void Init(wxGridCellAttr *attrDefault = NULL);
- // the ref count - when it goes to 0, we die
- size_t m_nRef;
-
wxColour m_colText,
m_colBack;
wxFont m_font;
wxAttrKind m_attrkind;
// use Clone() instead
- DECLARE_NO_COPY_CLASS(wxGridCellAttr)
+ wxDECLARE_NO_COPY_CLASS(wxGridCellAttr);
// suppress the stupid gcc warning about the class having private dtor and
// no friends
wxGridCellAttrProviderData *m_data;
- DECLARE_NO_COPY_CLASS(wxGridCellAttrProvider)
+ wxDECLARE_NO_COPY_CLASS(wxGridCellAttrProvider);
};
// ----------------------------------------------------------------------------
wxGridCellAttrProvider *m_attrProvider;
DECLARE_ABSTRACT_CLASS(wxGridTableBase)
- DECLARE_NO_COPY_CLASS(wxGridTableBase)
+ wxDECLARE_NO_COPY_CLASS(wxGridTableBase);
};
int m_comInt1;
int m_comInt2;
- DECLARE_NO_COPY_CLASS(wxGridTableMessage)
+ wxDECLARE_NO_COPY_CLASS(wxGridTableMessage);
};
public:
wxGridStringTable();
wxGridStringTable( int numRows, int numCols );
- virtual ~wxGridStringTable();
// these are pure virtual in wxGridTableBase
//
- int GetNumberRows();
- int GetNumberCols();
- wxString GetValue( int row, int col );
- void SetValue( int row, int col, const wxString& s );
+ virtual int GetNumberRows() { return m_data.size(); }
+ virtual int GetNumberCols() { return m_numCols; }
+ virtual wxString GetValue( int row, int col );
+ virtual void SetValue( int row, int col, const wxString& s );
// overridden functions from wxGridTableBase
//
private:
wxGridStringArray m_data;
+ // notice that while we don't need to store the number of our rows as it's
+ // always equal to the size of m_data array, we do need to store the number
+ // of our columns as we can't retrieve it from m_data when the number of
+ // rows is 0 (see #10818)
+ int m_numCols;
+
// These only get used if you set your own labels, otherwise the
// GetRow/ColLabelValue functions return wxGridTableBase defaults
//
// Grid view classes
// ============================================================================
+// ----------------------------------------------------------------------------
+// wxGridSizesInfo stores information about sizes of the rows or columns.
+//
+// It assumes that most of the columns or rows have default size and so stores
+// the default size separately and uses a hash to map column or row numbers to
+// their non default size for those which don't have the default size.
+// ----------------------------------------------------------------------------
+
+// hash map to store positions as the keys and sizes as the values
+WX_DECLARE_HASH_MAP_WITH_DECL( unsigned, int, wxIntegerHash, wxIntegerEqual,
+ wxUnsignedToIntHashMap, class WXDLLIMPEXP_ADV );
+
+struct WXDLLIMPEXP_ADV wxGridSizesInfo
+{
+ // default ctor, initialize m_sizeDefault and m_customSizes later
+ wxGridSizesInfo() { }
+
+ // ctor used by wxGrid::Get{Col,Row}Sizes()
+ wxGridSizesInfo(int defSize, const wxArrayInt& allSizes);
+
+ // default copy ctor, assignment operator and dtor are ok
+
+ // Get the size of the element with the given index
+ int GetSize(unsigned pos) const;
+
+
+ // default size
+ int m_sizeDefault;
+
+ // position -> size map containing all elements with non-default size
+ wxUnsignedToIntHashMap m_customSizes;
+};
+
// ----------------------------------------------------------------------------
// wxGrid
// ----------------------------------------------------------------------------
void SetCellHighlightPenWidth(int width);
void SetCellHighlightROPenWidth(int width);
+
+ // interactive grid mouse operations control
+ // -----------------------------------------
+
+ // functions globally enabling row/column interactive resizing (enabled by
+ // default)
void EnableDragRowSize( bool enable = true );
void DisableDragRowSize() { EnableDragRowSize( false ); }
- bool CanDragRowSize() const { return m_canDragRowSize; }
+
void EnableDragColSize( bool enable = true );
void DisableDragColSize() { EnableDragColSize( false ); }
- bool CanDragColSize() const { return m_canDragColSize; }
+
+ // if interactive resizing is enabled, some rows/columns can still have
+ // fixed size
+ void DisableRowResize(int row) { DoDisableLineResize(row, m_setFixedRows); }
+ void DisableColResize(int col) { DoDisableLineResize(col, m_setFixedCols); }
+
+ // these functions return whether the given row/column can be
+ // effectively resized: for this interactive resizing must be enabled
+ // and this index must not have been passed to DisableRow/ColResize()
+ bool CanDragRowSize(int row) const
+ { return m_canDragRowSize && DoCanResizeLine(row, m_setFixedRows); }
+ bool CanDragColSize(int col) const
+ { return m_canDragColSize && DoCanResizeLine(col, m_setFixedCols); }
+
+ // interactive column reordering (disabled by default)
void EnableDragColMove( bool enable = true );
void DisableDragColMove() { EnableDragColMove( false ); }
bool CanDragColMove() const { return m_canDragColMove; }
+
+ // interactive resizing of grid cells (enabled by default)
void EnableDragGridSize(bool enable = true);
void DisableDragGridSize() { EnableDragGridSize(false); }
bool CanDragGridSize() const { return m_canDragGridSize; }
+ // interactive dragging of cells (disabled by default)
void EnableDragCell( bool enable = true );
void DisableDragCell() { EnableDragCell( false ); }
bool CanDragCell() const { return m_canDragCell; }
void HideCol(int col) { SetColSize(col, 0); }
void ShowCol(int col) { SetColSize(col, -1); }
+ // the row and column sizes can be also set all at once using
+ // wxGridSizesInfo which holds all of them at once
+
+ wxGridSizesInfo GetColSizes() const
+ { return wxGridSizesInfo(GetDefaultColSize(), m_colWidths); }
+ wxGridSizesInfo GetRowSizes() const
+ { return wxGridSizesInfo(GetDefaultRowSize(), m_rowHeights); }
+
+ void SetColSizes(const wxGridSizesInfo& sizeInfo);
+ void SetRowSizes(const wxGridSizesInfo& sizeInfo);
+
// ------- columns (only, for now) reordering
wxGRID_CHECKBOX,
wxGRID_CHOICE,
wxGRID_COMBOBOX };
+
+ wxDEPRECATED_INLINE(bool CanDragRowSize() const, return m_canDragRowSize; )
+ wxDEPRECATED_INLINE(bool CanDragColSize() const, return m_canDragColSize; )
#endif // WXWIN_COMPATIBILITY_2_8
// it was processed (but not vetoed) and 0 if it wasn't processed
int SendEvent(const wxEventType evtType,
int row, int col,
- wxMouseEvent& e);
+ const wxMouseEvent& e);
int SendEvent(const wxEventType evtType,
const wxGridCellCoords& coords,
- wxMouseEvent& e)
+ const wxMouseEvent& e)
{ return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); }
int SendEvent(const wxEventType evtType,
int row, int col,
int SendEvent(const wxEventType evtType, const wxString& s = wxString())
{ return SendEvent(evtType, m_currentCellCoords, s); }
+ // send wxEVT_GRID_{ROW,COL}_SIZE
+ void SendGridSizeEvent(wxEventType type,
+ int row, int col,
+ const wxMouseEvent& mouseEv);
+
void OnPaint( wxPaintEvent& );
void OnSize( wxSizeEvent& );
void OnKeyDown( wxKeyEvent& );
void DoUpdateResizeColWidth(int w);
void DoStartMoveCol(int col);
- void DoEndDragResizeRow();
- void DoEndDragResizeCol(wxMouseEvent *event = NULL);
+ void DoEndDragResizeRow(const wxMouseEvent& event);
+ void DoEndDragResizeCol(const wxMouseEvent& event);
void DoEndMoveCol(int pos);
// common implementations of methods defined for both rows and columns
void DeselectLine(int line, const wxGridOperations& oper);
- void DoEndDragResizeLine(const wxGridOperations& oper);
+ bool DoEndDragResizeLine(const wxGridOperations& oper);
int PosToLinePos(int pos, bool clipToMinMax,
const wxGridOperations& oper) const;
int PosToLine(int pos, bool clipToMinMax,
bool DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t),
int num, bool updateLabels);
+ // common part of Set{Col,Row}Sizes
+ void DoSetSizes(const wxGridSizesInfo& sizeInfo,
+ const wxGridOperations& oper);
+
+ // common part of Disable{Row,Col}Resize and CanDrag{Row,Col}Size
+ void DoDisableLineResize(int line, wxGridFixedIndicesSet *& setFixed);
+ bool DoCanResizeLine(int line, const wxGridFixedIndicesSet *setFixed) const;
+
+
+
+ // these sets contain the indices of fixed, i.e. non-resizable
+ // interactively, grid rows or columns and are NULL if there are no fixed
+ // elements (which is the default)
+ wxGridFixedIndicesSet *m_setFixedRows,
+ *m_setFixedCols;
+
DECLARE_DYNAMIC_CLASS( wxGrid )
DECLARE_EVENT_TABLE()
- DECLARE_NO_COPY_CLASS(wxGrid)
+ wxDECLARE_NO_COPY_CLASS(wxGrid);
};
// ----------------------------------------------------------------------------
wxGrid *m_grid;
- DECLARE_NO_COPY_CLASS(wxGridUpdateLocker)
+ wxDECLARE_NO_COPY_CLASS(wxGridUpdateLocker);
};
// ----------------------------------------------------------------------------
// explicitly specifying inline allows gcc < 3.4 to
// handle the deprecation attribute even in the constructor.
- wxDEPRECATED( inline
+ wxDEPRECATED_CONSTRUCTOR(
wxGridEvent(int id,
wxEventType type,
wxObject* obj,
SetEventObject(obj);
}
- wxDEPRECATED( inline
+ wxDEPRECATED_CONSTRUCTOR(
wxGridSizeEvent(int id,
wxEventType type,
wxObject* obj,
SetEventObject(obj);
}
- wxDEPRECATED( inline
+ wxDEPRECATED_CONSTRUCTOR(
wxGridRangeSelectEvent(int id,
wxEventType type,
wxObject* obj,
};
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_ROW_SIZE;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_SIZE;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_RANGE_SELECT;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_CHANGING;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_CHANGED;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_SELECT_CELL;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_SHOWN;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_HIDDEN;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_CREATED;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_BEGIN_DRAG;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_MOVE;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_SORT;
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_LEFT_CLICK, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_RIGHT_DCLICK, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_ROW_SIZE, wxGridSizeEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SIZE, wxGridSizeEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGING, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGED, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_SELECT_CELL, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_SHOWN, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_HIDDEN, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_CREATED, wxGridEditorCreatedEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_BEGIN_DRAG, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_MOVE, wxGridEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SORT, wxGridEvent );
typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreatedEvent&);
#define wxGridEventHandler(func) \
- (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEventFunction, &func)
+ wxEVENT_HANDLER_CAST(wxGridEventFunction, func)
#define wxGridSizeEventHandler(func) \
- (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridSizeEventFunction, &func)
+ wxEVENT_HANDLER_CAST(wxGridSizeEventFunction, func)
#define wxGridRangeSelectEventHandler(func) \
- (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridRangeSelectEventFunction, &func)
+ wxEVENT_HANDLER_CAST(wxGridRangeSelectEventFunction, func)
#define wxGridEditorCreatedEventHandler(func) \
- (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEditorCreatedEventFunction, &func)
+ wxEVENT_HANDLER_CAST(wxGridEditorCreatedEventFunction, func)
#define wx__DECLARE_GRIDEVT(evt, id, fn) \
wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn))