added SetColMinimalWidth()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6184 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
0e09f76e6d
commit
439479796a
@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: grid.h
|
// Name: wx/generic/grid.h
|
||||||
// Purpose: wxGrid and related classes
|
// Purpose: wxGrid and related classes
|
||||||
// Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
|
// Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
|
||||||
// Modified by:
|
// Modified by:
|
||||||
@ -22,6 +22,7 @@
|
|||||||
#pragma interface "grid.h"
|
#pragma interface "grid.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/hash.h"
|
||||||
#include "wx/panel.h"
|
#include "wx/panel.h"
|
||||||
#include "wx/scrolwin.h"
|
#include "wx/scrolwin.h"
|
||||||
#include "wx/string.h"
|
#include "wx/string.h"
|
||||||
@ -559,11 +560,13 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
// ============================================================================
|
||||||
//
|
|
||||||
// Grid view classes
|
// Grid view classes
|
||||||
//
|
// ============================================================================
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxGridCellCoords: location of a cell in the grid
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLEXPORT wxGridCellCoords
|
class WXDLLEXPORT wxGridCellCoords
|
||||||
{
|
{
|
||||||
@ -619,8 +622,6 @@ extern wxRect wxGridNoCellRect;
|
|||||||
//
|
//
|
||||||
WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray);
|
WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxGrid
|
// wxGrid
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -842,6 +843,12 @@ public:
|
|||||||
void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
|
void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
|
||||||
|
|
||||||
void SetColSize( int col, int width );
|
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 SetDefaultCellBackgroundColour( const wxColour& );
|
||||||
void SetCellBackgroundColour( int row, int col, const wxColour& );
|
void SetCellBackgroundColour( int row, int col, const wxColour& );
|
||||||
void SetDefaultCellTextColour( const wxColour& );
|
void SetDefaultCellTextColour( const wxColour& );
|
||||||
@ -1200,6 +1207,12 @@ protected:
|
|||||||
wxColour m_gridLineColour;
|
wxColour m_gridLineColour;
|
||||||
bool m_gridLinesEnabled;
|
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?
|
// do we have some place to store attributes in?
|
||||||
bool CanHaveAttributes();
|
bool CanHaveAttributes();
|
||||||
@ -1322,12 +1335,9 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Grid event class and event types
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
//
|
|
||||||
// ------ Grid event class and event types
|
|
||||||
//
|
|
||||||
|
|
||||||
class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
|
class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
|
||||||
{
|
{
|
||||||
|
@ -110,7 +110,7 @@ GridFrame::GridFrame()
|
|||||||
int logW = gridW, logH = 100;
|
int logW = gridW, logH = 100;
|
||||||
|
|
||||||
wxMenu *fileMenu = new wxMenu;
|
wxMenu *fileMenu = new wxMenu;
|
||||||
fileMenu->Append( ID_VTABLE, "&Virtual table test");
|
fileMenu->Append( ID_VTABLE, "&Virtual table test\tCtrl-V");
|
||||||
fileMenu->AppendSeparator();
|
fileMenu->AppendSeparator();
|
||||||
fileMenu->Append( wxID_EXIT, "E&xit\tAlt-X" );
|
fileMenu->Append( wxID_EXIT, "E&xit\tAlt-X" );
|
||||||
|
|
||||||
@ -220,8 +220,9 @@ GridFrame::GridFrame()
|
|||||||
attr->SetBackgroundColour(*wxBLUE);
|
attr->SetBackgroundColour(*wxBLUE);
|
||||||
grid->SetRowAttr(5, attr);
|
grid->SetRowAttr(5, attr);
|
||||||
|
|
||||||
// VZ: cell borders don't look nice otherwise :-) (for now...)
|
grid->SetCellValue(2, 4, "a wider column");
|
||||||
grid->SetDefaultCellBackgroundColour(wxColour(200, 200, 180));
|
grid->SetColSize(4, 120);
|
||||||
|
grid->SetColMinimalWidth(4, 120);
|
||||||
|
|
||||||
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
||||||
topSizer->Add( grid,
|
topSizer->Add( grid,
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
|
|
||||||
#include "wx/grid.h"
|
#include "wx/grid.h"
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// array classes
|
// array classes
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -267,6 +266,10 @@ public:
|
|||||||
static size_t gs_nAttrCacheMisses = 0;
|
static size_t gs_nAttrCacheMisses = 0;
|
||||||
#endif // DEBUG_ATTR_CACHE
|
#endif // DEBUG_ATTR_CACHE
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// constants
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxGridCellCoords wxGridNoCellCoords( -1, -1 );
|
wxGridCellCoords wxGridNoCellCoords( -1, -1 );
|
||||||
wxRect wxGridNoCellRect( -1, -1, -1, -1 );
|
wxRect wxGridNoCellRect( -1, -1, -1, -1 );
|
||||||
|
|
||||||
@ -274,6 +277,10 @@ wxRect wxGridNoCellRect( -1, -1, -1, -1 );
|
|||||||
// TODO: fixed so far - make configurable later (and also different for x/y)
|
// TODO: fixed so far - make configurable later (and also different for x/y)
|
||||||
static const size_t GRID_SCROLL_LINE = 10;
|
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
|
// implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@ -2020,7 +2027,8 @@ wxGrid::wxGrid( wxWindow *parent,
|
|||||||
const wxSize& size,
|
const wxSize& size,
|
||||||
long style,
|
long style,
|
||||||
const wxString& name )
|
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();
|
Create();
|
||||||
}
|
}
|
||||||
@ -2887,7 +2895,9 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
|
|||||||
|
|
||||||
wxClientDC dc( m_gridWin );
|
wxClientDC dc( m_gridWin );
|
||||||
PrepareDC( dc );
|
PrepareDC( dc );
|
||||||
x = wxMax( x, GetColLeft(m_dragRowOrCol) + WXGRID_MIN_COL_WIDTH );
|
|
||||||
|
x = wxMax( x, GetColLeft(m_dragRowOrCol) +
|
||||||
|
GetColMinimalWidth(m_dragRowOrCol));
|
||||||
dc.SetLogicalFunction(wxINVERT);
|
dc.SetLogicalFunction(wxINVERT);
|
||||||
if ( m_dragLastPos >= 0 )
|
if ( m_dragLastPos >= 0 )
|
||||||
{
|
{
|
||||||
@ -3212,7 +3222,8 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
|
|
||||||
wxClientDC dc( m_gridWin );
|
wxClientDC dc( m_gridWin );
|
||||||
PrepareDC( dc );
|
PrepareDC( dc );
|
||||||
x = wxMax( x, GetColLeft(m_dragRowOrCol) + WXGRID_MIN_COL_WIDTH );
|
x = wxMax( x, GetColLeft(m_dragRowOrCol) +
|
||||||
|
GetColMinimalWidth(m_dragRowOrCol) );
|
||||||
dc.SetLogicalFunction(wxINVERT);
|
dc.SetLogicalFunction(wxINVERT);
|
||||||
if ( m_dragLastPos >= 0 )
|
if ( m_dragLastPos >= 0 )
|
||||||
{
|
{
|
||||||
@ -3482,7 +3493,8 @@ void wxGrid::DoEndDragResizeCol()
|
|||||||
|
|
||||||
int colLeft = GetColLeft(m_dragRowOrCol);
|
int colLeft = GetColLeft(m_dragRowOrCol);
|
||||||
SetColSize( m_dragRowOrCol,
|
SetColSize( m_dragRowOrCol,
|
||||||
wxMax( m_dragLastPos - colLeft, WXGRID_MIN_COL_WIDTH ) );
|
wxMax( m_dragLastPos - colLeft,
|
||||||
|
GetColMinimalWidth(m_dragRowOrCol) ) );
|
||||||
|
|
||||||
if ( !GetBatchCount() )
|
if ( !GetBatchCount() )
|
||||||
{
|
{
|
||||||
@ -6035,6 +6047,8 @@ void wxGrid::SetColSize( int col, int width )
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( col >= 0 && col < m_numCols, _T("invalid column index") );
|
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() )
|
if ( m_colWidths.IsEmpty() )
|
||||||
{
|
{
|
||||||
// need to really create the array
|
// need to really create the array
|
||||||
@ -6054,6 +6068,17 @@ void wxGrid::SetColSize( int col, int width )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
// ------ cell value accessor functions
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user