/////////////////////////////////////////////////////////////////////////////
-// 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"
-//////////////////////////////////////////////////////////////////////
-//
+// ============================================================================
// Grid view classes
-//
-//////////////////////////////////////////////////////////////////////
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxGridCellCoords: location of a cell in the grid
+// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGridCellCoords
{
//
WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray);
-
-
// ----------------------------------------------------------------------------
// wxGrid
// ----------------------------------------------------------------------------
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& );
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();
};
-
-
-
-//
-// ------ Grid event class and event types
-//
+// ----------------------------------------------------------------------------
+// Grid event class and event types
+// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
{
int logW = gridW, logH = 100;
wxMenu *fileMenu = new wxMenu;
- fileMenu->Append( ID_VTABLE, "&Virtual table test");
+ fileMenu->Append( ID_VTABLE, "&Virtual table test\tCtrl-V");
fileMenu->AppendSeparator();
fileMenu->Append( wxID_EXIT, "E&xit\tAlt-X" );
attr->SetBackgroundColour(*wxBLUE);
grid->SetRowAttr(5, attr);
- // VZ: cell borders don't look nice otherwise :-) (for now...)
- grid->SetDefaultCellBackgroundColour(wxColour(200, 200, 180));
+ grid->SetCellValue(2, 4, "a wider column");
+ grid->SetColSize(4, 120);
+ grid->SetColMinimalWidth(4, 120);
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
topSizer->Add( grid,
#include "wx/grid.h"
-
// ----------------------------------------------------------------------------
// array classes
// ----------------------------------------------------------------------------
static size_t gs_nAttrCacheMisses = 0;
#endif // DEBUG_ATTR_CACHE
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
wxGridCellCoords wxGridNoCellCoords( -1, -1 );
wxRect wxGridNoCellRect( -1, -1, -1, -1 );
// TODO: fixed so far - make configurable later (and also different for x/y)
static const size_t GRID_SCROLL_LINE = 10;
+// the size of hash tables used a bit everywhere (the max number of elements
+// in these hash tables is the number of rows/columns)
+static const int GRID_HASH_SIZE = 100;
+
// ============================================================================
// implementation
// ============================================================================
const wxSize& size,
long style,
const wxString& name )
- : wxScrolledWindow( parent, id, pos, size, style, name )
+ : wxScrolledWindow( parent, id, pos, size, style, name ),
+ m_colMinWidths(wxKEY_INTEGER, GRID_HASH_SIZE)
{
Create();
}
wxClientDC dc( m_gridWin );
PrepareDC( dc );
- x = wxMax( x, GetColLeft(m_dragRowOrCol) + WXGRID_MIN_COL_WIDTH );
+
+ x = wxMax( x, GetColLeft(m_dragRowOrCol) +
+ GetColMinimalWidth(m_dragRowOrCol));
dc.SetLogicalFunction(wxINVERT);
if ( m_dragLastPos >= 0 )
{
wxClientDC dc( m_gridWin );
PrepareDC( dc );
- x = wxMax( x, GetColLeft(m_dragRowOrCol) + WXGRID_MIN_COL_WIDTH );
+ x = wxMax( x, GetColLeft(m_dragRowOrCol) +
+ GetColMinimalWidth(m_dragRowOrCol) );
dc.SetLogicalFunction(wxINVERT);
if ( m_dragLastPos >= 0 )
{
int colLeft = GetColLeft(m_dragRowOrCol);
SetColSize( m_dragRowOrCol,
- wxMax( m_dragLastPos - colLeft, WXGRID_MIN_COL_WIDTH ) );
+ wxMax( m_dragLastPos - colLeft,
+ GetColMinimalWidth(m_dragRowOrCol) ) );
if ( !GetBatchCount() )
{
{
wxCHECK_RET( col >= 0 && col < m_numCols, _T("invalid column index") );
+ // should we check that it's bigger than GetColMinimalWidth(col) here?
+
if ( m_colWidths.IsEmpty() )
{
// need to really create the array
}
+void wxGrid::SetColMinimalWidth( int col, int width )
+{
+ m_colMinWidths.Put(col, (wxObject *)width);
+}
+
+int wxGrid::GetColMinimalWidth(int col) const
+{
+ wxObject *obj = m_colMinWidths.Get(m_dragRowOrCol);
+ return obj ? (int)obj : WXGRID_MIN_COL_WIDTH;
+}
+
//
// ------ cell value accessor functions
//