/////////////////////////////////////////////////////////////////////////////
-// 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:
#pragma interface "grid.h"
#endif
+#include "wx/hash.h"
#include "wx/panel.h"
#include "wx/scrolwin.h"
#include "wx/string.h"
class WXDLLEXPORT wxGridRowLabelWindow;
class WXDLLEXPORT wxGridTableBase;
class WXDLLEXPORT wxGridWindow;
+class WXDLLEXPORT wxGridTypeRegistry;
class WXDLLEXPORT wxCheckBox;
class WXDLLEXPORT wxTextCtrl;
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; }
//
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
//
// 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
-//////////////////////////////////////////////////////////////////////
-//
+// ============================================================================
// Grid view classes
-//
-//////////////////////////////////////////////////////////////////////
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxGridCellCoords: location of a cell in the grid
+// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGridCellCoords
{
//
WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray);
-
-
// ----------------------------------------------------------------------------
// wxGrid
// ----------------------------------------------------------------------------
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);
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& );
wxGridCellEditor* GetCellEditor(int row, int col);
+
// ------ cell value accessors
//
wxString GetCellValue( int row, int col )
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...
//
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; }
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;
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();
bool m_inOnKeyDown;
int m_batchCount;
+
+ wxGridTypeRegistry* m_typeRegistry;
+
enum CursorMode
{
WXGRID_CURSOR_SELECT_CELL,
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;
-
-
-//
-// ------ Grid event class and event types
-//
+// ----------------------------------------------------------------------------
+// Grid event class and event types
+// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
{