// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "grid.h"
#endif
#if wxUSE_GRID
-#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
- #include "gridg.cpp"
-#else // wxUSE_NEW_GRID
-
#ifndef WX_PRECOMP
#include "wx/utils.h"
#include "wx/dcclient.h"
// array classes
// ----------------------------------------------------------------------------
-WX_DEFINE_EXPORTED_ARRAY(wxGridCellAttr *, wxArrayAttrs);
+WX_DEFINE_ARRAY_WITH_DECL_NO_PTR(wxGridCellAttr *, wxArrayAttrs,
+ class WXDLLIMPEXP_ADV);
struct wxGridCellWithAttr
{
wxGridCellCoords coords;
wxGridCellAttr *attr;
+
+// Cannot do this:
+// DECLARE_NO_COPY_CLASS(wxGridCellWithAttr)
+// without rewriting the macros, which require a public copy constructor.
};
-WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellWithAttr, wxGridCellWithAttrArray);
+WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellWithAttr, wxGridCellWithAttrArray,
+ class WXDLLIMPEXP_ADV);
#include "wx/arrimpl.cpp"
// private classes
// ----------------------------------------------------------------------------
-class WXDLLEXPORT wxGridRowLabelWindow : public wxWindow
+class WXDLLIMPEXP_ADV wxGridRowLabelWindow : public wxWindow
{
public:
wxGridRowLabelWindow() { m_owner = (wxGrid *)NULL; }
DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow)
DECLARE_EVENT_TABLE()
+ DECLARE_NO_COPY_CLASS(wxGridRowLabelWindow)
};
-class WXDLLEXPORT wxGridColLabelWindow : public wxWindow
+class WXDLLIMPEXP_ADV wxGridColLabelWindow : public wxWindow
{
public:
wxGridColLabelWindow() { m_owner = (wxGrid *)NULL; }
DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow)
DECLARE_EVENT_TABLE()
+ DECLARE_NO_COPY_CLASS(wxGridColLabelWindow)
};
-class WXDLLEXPORT wxGridCornerLabelWindow : public wxWindow
+class WXDLLIMPEXP_ADV wxGridCornerLabelWindow : public wxWindow
{
public:
wxGridCornerLabelWindow() { m_owner = (wxGrid *)NULL; }
DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow)
DECLARE_EVENT_TABLE()
+ DECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow)
};
-class WXDLLEXPORT wxGridWindow : public wxWindow
+class WXDLLIMPEXP_ADV wxGridWindow : public wxWindow
{
public:
wxGridWindow()
DECLARE_DYNAMIC_CLASS(wxGridWindow)
DECLARE_EVENT_TABLE()
+ DECLARE_NO_COPY_CLASS(wxGridWindow)
};
wxGridCellEditor* m_editor;
DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler)
DECLARE_EVENT_TABLE()
+ DECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler)
};
// ----------------------------------------------------------------------------
// this class stores attributes set for cells
-class WXDLLEXPORT wxGridCellAttrData
+class WXDLLIMPEXP_ADV wxGridCellAttrData
{
public:
void SetAttr(wxGridCellAttr *attr, int row, int col);
};
// this class stores attributes set for rows or columns
-class WXDLLEXPORT wxGridRowOrColAttrData
+class WXDLLIMPEXP_ADV wxGridRowOrColAttrData
{
public:
// empty ctor to suppress warnings
// NB: this is just a wrapper around 3 objects: one which stores cell
// attributes, and 2 others for row/col ones
-class WXDLLEXPORT wxGridCellAttrProviderData
+class WXDLLIMPEXP_ADV wxGridCellAttrProviderData
{
public:
wxGridCellAttrData m_cellAttrs;
wxString m_typeName;
wxGridCellRenderer* m_renderer;
wxGridCellEditor* m_editor;
+
+ DECLARE_NO_COPY_CLASS(wxGridDataTypeInfo)
};
-WX_DEFINE_EXPORTED_ARRAY(wxGridDataTypeInfo*, wxGridDataTypeInfoArray);
+WX_DEFINE_ARRAY_WITH_DECL_NO_PTR(wxGridDataTypeInfo*, wxGridDataTypeInfoArray,
+ class WXDLLIMPEXP_ADV);
-class WXDLLEXPORT wxGridTypeRegistry
+class WXDLLIMPEXP_ADV wxGridTypeRegistry
{
public:
wxGridTypeRegistry() {}
wxGridWindow* gridWindow = wxDynamicCast(m_control->GetParent(), wxGridWindow);
if (gridWindow)
gridWindow->GetOwner()->PrepareDC(dc);
-
+
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));
dc.DrawRectangle(rectCell);
m_control = new wxTextCtrl(parent, id, wxEmptyString,
wxDefaultPosition, wxDefaultSize
#if defined(__WXMSW__)
- , wxTE_PROCESS_TAB | wxTE_MULTILINE |
- wxTE_NO_VSCROLL | wxTE_AUTO_SCROLL
+ , wxTE_PROCESS_TAB | wxTE_AUTO_SCROLL
#endif
);
- // TODO: use m_maxChars
+ // set max length allowed in the textctrl, if the parameter was set
+ if (m_maxChars != 0)
+ {
+ ((wxTextCtrl*)m_control)->SetMaxLength(m_maxChars);
+ }
wxGridCellEditor::Create(parent, id, evtHandler);
}
default:
// accept 8 bit chars too if isprint() agrees
- if ( (keycode < 255) && (isprint(keycode)) )
+ if ( (keycode < 255) && (wxIsprint(keycode)) )
return TRUE;
}
}
return TRUE;
default:
- if ( (keycode < 128) && isdigit(keycode) )
+ if ( (keycode < 128) && wxIsdigit(keycode) )
return TRUE;
}
}
{
if ( !HasRange() )
{
- int keycode = (int) event.KeyCode();
- if ( isdigit(keycode) || keycode == '+' || keycode == '-'
+ int keycode = event.GetKeyCode();
+ if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-'
|| keycode == WXK_NUMPAD0
|| keycode == WXK_NUMPAD1
|| keycode == WXK_NUMPAD2
void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event)
{
- int keycode = (int)event.KeyCode();
- if ( isdigit(keycode) || keycode == '+' || keycode == '-' || keycode == '.'
+ int keycode = event.GetKeyCode();
+ if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-' || keycode == '.'
|| keycode == WXK_NUMPAD0
|| keycode == WXK_NUMPAD1
|| keycode == WXK_NUMPAD2
default:
// additionally accept 'e' as in '1e+6'
if ( (keycode < 128) &&
- (isdigit(keycode) || tolower(keycode) == 'e') )
+ (wxIsdigit(keycode) || tolower(keycode) == 'e') )
return TRUE;
}
}
int vAlign = wxALIGN_CENTRE;
if (GetCellAttr())
GetCellAttr()->GetAlignment(& hAlign, & vAlign);
-
+
int x = 0, y = 0;
if (hAlign == wxALIGN_LEFT)
{
x = r.x + 2;
#ifdef __WXMSW__
x += 2;
-#endif
+#endif
y = r.y + r.height/2 - size.y/2;
}
else if (hAlign == wxALIGN_RIGHT)
x = r.x + r.width/2 - size.x/2;
y = r.y + r.height/2 - size.y/2;
}
-
+
m_control->Move(x, y);
}
void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event)
{
- switch ( event.KeyCode() )
+ switch ( event.GetKeyCode() )
{
case WXK_ESCAPE:
m_editor->Reset();
void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event)
{
- switch ( event.KeyCode() )
+ switch ( event.GetKeyCode() )
{
case WXK_ESCAPE:
case WXK_TAB:
{
dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) );
}
- }
+ }
else
{
dc.SetBrush(wxBrush(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE), wxSOLID));
// draw a border around checkmark
int vAlign, hAlign;
attr.GetAlignment(& hAlign, &vAlign);
-
+
wxRect rectBorder;
if (hAlign == wxALIGN_CENTRE)
{
rectBorder.x = rect.x + 2;
rectBorder.y = rect.y + rect.height/2 - size.y/2;
rectBorder.width = size.x;
- rectBorder.height = size.y;
+ rectBorder.height = size.y;
}
else if (hAlign == wxALIGN_RIGHT)
{
rectBorder.x = rect.x + rect.width - size.x - 2;
rectBorder.y = rect.y + rect.height/2 - size.y/2;
rectBorder.width = size.x;
- rectBorder.height = size.y;
+ rectBorder.height = size.y;
}
bool value;
m_attrkind = wxGridCellAttr::Cell;
m_sizeRows = m_sizeCols = 1;
- m_overflow = TRUE;
+ m_overflow = UnsetOverflow;
SetDefAttr(attrDefault);
}
if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() )
SetReadOnly(mergefrom->IsReadOnly());
+ if (!HasOverflowMode() && mergefrom->HasOverflowMode() )
+ SetOverflow(mergefrom->GetOverflow());
+
SetDefAttr(mergefrom->m_defGridAttr);
}
wxString wxGridStringTable::GetValue( int row, int col )
{
- wxASSERT_MSG( (row < GetNumberRows()) && (col < GetNumberCols()),
- _T("invalid row or column index in wxGridStringTable") );
+ wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()),
+ wxEmptyString,
+ _T("invalid row or column index in wxGridStringTable") );
return m_data[row][col];
}
void wxGridStringTable::SetValue( int row, int col, const wxString& value )
{
- wxASSERT_MSG( (row < GetNumberRows()) && (col < GetNumberCols()),
- _T("invalid row or column index in wxGridStringTable") );
+ wxCHECK_RET( (row < GetNumberRows()) && (col < GetNumberCols()),
+ _T("invalid row or column index in wxGridStringTable") );
m_data[row][col] = value;
}
bool wxGridStringTable::IsEmptyCell( int row, int col )
{
- wxASSERT_MSG( (row < GetNumberRows()) && (col < GetNumberCols()),
+ wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()),
+ true,
_T("invalid row or column index in wxGridStringTable") );
return (m_data[row][col] == wxEmptyString);
wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid *parent,
wxWindowID id,
const wxPoint &pos, const wxSize &size )
- : wxWindow( parent, id, pos, size, wxWANTS_CHARS )
+ : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
{
m_owner = parent;
}
wxGridColLabelWindow::wxGridColLabelWindow( wxGrid *parent,
wxWindowID id,
const wxPoint &pos, const wxSize &size )
- : wxWindow( parent, id, pos, size, wxWANTS_CHARS )
+ : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
{
m_owner = parent;
}
wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid *parent,
wxWindowID id,
const wxPoint &pos, const wxSize &size )
- : wxWindow( parent, id, pos, size, wxWANTS_CHARS )
+ : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
{
m_owner = parent;
}
wxWindowID id,
const wxPoint &pos,
const wxSize &size )
- : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxCLIP_CHILDREN,
+ : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxCLIP_CHILDREN,
wxT("grid window") )
{
static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
const wxArrayInt& BorderArray, int nMax,
- bool maxOnOverflow);
+ bool clipToMinMax);
#define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
- WXGRID_MIN_COL_WIDTH, \
+ m_minAcceptableColWidth, \
m_colRights, m_numCols, TRUE)
#define internalYToRow(y) CoordToRowOrCol(y, m_defaultRowHeight, \
- WXGRID_MIN_ROW_HEIGHT, \
+ m_minAcceptableRowHeight, \
m_rowBottoms, m_numRows, TRUE)
/////////////////////////////////////////////////////////////////////
+#if wxUSE_EXTENDED_RTTI
+WX_DEFINE_FLAGS( wxGridStyle )
+
+wxBEGIN_FLAGS( wxGridStyle )
+ // new style border flags, we put them first to
+ // use them for streaming out
+ wxFLAGS_MEMBER(wxBORDER_SIMPLE)
+ wxFLAGS_MEMBER(wxBORDER_SUNKEN)
+ wxFLAGS_MEMBER(wxBORDER_DOUBLE)
+ wxFLAGS_MEMBER(wxBORDER_RAISED)
+ wxFLAGS_MEMBER(wxBORDER_STATIC)
+ wxFLAGS_MEMBER(wxBORDER_NONE)
+
+ // old style border flags
+ wxFLAGS_MEMBER(wxSIMPLE_BORDER)
+ wxFLAGS_MEMBER(wxSUNKEN_BORDER)
+ wxFLAGS_MEMBER(wxDOUBLE_BORDER)
+ wxFLAGS_MEMBER(wxRAISED_BORDER)
+ wxFLAGS_MEMBER(wxSTATIC_BORDER)
+ wxFLAGS_MEMBER(wxNO_BORDER)
+
+ // standard window styles
+ wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
+ wxFLAGS_MEMBER(wxCLIP_CHILDREN)
+ wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
+ wxFLAGS_MEMBER(wxWANTS_CHARS)
+ wxFLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE)
+ wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
+ wxFLAGS_MEMBER(wxVSCROLL)
+ wxFLAGS_MEMBER(wxHSCROLL)
+
+wxEND_FLAGS( wxGridStyle )
+
+IMPLEMENT_DYNAMIC_CLASS_XTI(wxGrid, wxScrolledWindow,"wx/grid.h")
+
+wxBEGIN_PROPERTIES_TABLE(wxGrid)
+ wxHIDE_PROPERTY( Children )
+ wxPROPERTY_FLAGS( WindowStyle , wxGridStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
+wxEND_PROPERTIES_TABLE()
+
+wxBEGIN_HANDLERS_TABLE(wxGrid)
+wxEND_HANDLERS_TABLE()
+
+wxCONSTRUCTOR_5( wxGrid , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
+
+/*
+ TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
+*/
+#else
IMPLEMENT_DYNAMIC_CLASS( wxGrid, wxScrolledWindow )
+#endif
BEGIN_EVENT_TABLE( wxGrid, wxScrolledWindow )
EVT_PAINT( wxGrid::OnPaint )
EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground )
END_EVENT_TABLE()
+wxGrid::wxGrid()
+{
+ // in order to make sure that a size event is not
+ // trigerred in a unfinished state
+ m_cornerLabelWin = NULL ;
+ m_rowLabelWin = NULL ;
+ m_colLabelWin = NULL ;
+ m_gridWin = NULL ;
+}
+
wxGrid::wxGrid( wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
Create();
}
+bool wxGrid::Create(wxWindow *parent, wxWindowID id,
+ const wxPoint& pos, const wxSize& size,
+ long style, const wxString& name)
+{
+ if (!wxScrolledWindow::Create(parent, id, pos, size,
+ style | wxWANTS_CHARS , name))
+ return FALSE;
+
+ m_colMinWidths = wxLongToLongHashMap(GRID_HASH_SIZE) ;
+ m_rowMinHeights = wxLongToLongHashMap(GRID_HASH_SIZE) ;
+
+ Create() ;
+
+
+ return TRUE;
+}
+
wxGrid::~wxGrid()
{
{
if ( m_created )
{
- // RD: Actually, this should probably be allowed. I think it would be
- // nice to be able to switch multiple Tables in and out of a single
- // View at runtime. Is there anything in the implementation that
- // would prevent this?
+ // stop all processing
+ m_created = FALSE;
- // At least, you now have to cope with m_selection
- wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
- return FALSE;
+ if (m_ownTable)
+ {
+ wxGridTableBase *t=m_table;
+ m_table=0;
+ delete t;
+ }
+ delete m_selection;
+
+ m_table=0;
+ m_selection=0;
+ m_numRows=0;
+ m_numCols=0;
}
- else
+ if (table)
{
m_numRows = table->GetNumberRows();
m_numCols = table->GetNumberCols();
// TODO: something better than this ?
//
m_labelFont = this->GetFont();
-// m_labelFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
-// m_labelFont.SetWeight( m_labelFont.GetWeight() + 2 );
+ m_labelFont.SetWeight( wxBOLD );
m_rowLabelHorizAlign = wxALIGN_CENTRE;
m_rowLabelVertAlign = wxALIGN_CENTRE;
m_colLabelHorizAlign = wxALIGN_CENTRE;
m_colLabelVertAlign = wxALIGN_CENTRE;
+ m_colLabelTextOrientation = wxHORIZONTAL;
m_defaultColWidth = WXGRID_DEFAULT_COL_WIDTH;
m_defaultRowHeight = m_gridWin->GetCharHeight();
+ m_minAcceptableColWidth = WXGRID_MIN_COL_WIDTH;
+ m_minAcceptableRowHeight = WXGRID_MIN_ROW_HEIGHT;
+
#if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
m_defaultRowHeight += 8;
#else
m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords;
-// m_selectionBackground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
-// m_selectionForeground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
- m_selectionBackground = *wxBLACK;
- m_selectionForeground = *wxWHITE;
+ m_selectionBackground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
+ m_selectionForeground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
m_editable = TRUE; // default for whole grid
void wxGrid::CalcWindowSizes()
{
+ // escape if the window is has not been fully created yet
+
+ if ( m_cornerLabelWin == NULL )
+ return ;
+
int cw, ch;
GetClientSize( &cw, &ch );
//
else if (event.LeftDClick() )
{
- if ( YToEdgeOfRow(y) < 0 )
+ int row = YToEdgeOfRow(y);
+ if ( row < 0 )
{
row = YToRow(y);
- SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event );
+ if ( row >=0 &&
+ !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event ) )
+ {
+ // no default action at the moment
+ }
+ }
+ else
+ {
+ // adjust row height depending on label text
+ AutoSizeRowLabelSize( row );
+
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
+ m_dragLastPos = -1;
}
}
else if ( event.RightDown() )
{
row = YToRow(y);
- if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
+ if ( row >=0 &&
+ !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
{
// no default action at the moment
}
else if ( event.RightDClick() )
{
row = YToRow(y);
- if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
+ if ( row >= 0 &&
+ !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
{
// no default action at the moment
}
//
if ( event.LeftDClick() )
{
- if ( XToEdgeOfCol(x) < 0 )
+ int col = XToEdgeOfCol(x);
+ if ( col < 0 )
{
col = XToCol(x);
- SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event );
+ if ( col >= 0 &&
+ ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event ) )
+ {
+ // no default action at the moment
+ }
+ }
+ else
+ {
+ // adjust column width depending on label text
+ AutoSizeColLabelSize( col );
+
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
+ m_dragLastPos = -1;
}
}
else if ( event.RightDown() )
{
col = XToCol(x);
- if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
+ if ( col >= 0 &&
+ !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
{
// no default action at the moment
}
else if ( event.RightDClick() )
{
col = XToCol(x);
- if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
+ if ( col >= 0 &&
+ !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
{
// no default action at the moment
}
{
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
- if ( m_selectingTopLeft != wxGridNoCellCoords &&
- m_selectingBottomRight != wxGridNoCellCoords )
+ if (m_winCapture)
{
- if (m_winCapture)
- {
- if (m_winCapture->HasCapture()) m_winCapture->ReleaseMouse();
- m_winCapture = NULL;
- }
+ if (m_winCapture->HasCapture()) m_winCapture->ReleaseMouse();
+ m_winCapture = NULL;
+ }
+
+ if ( coords == m_currentCellCoords && m_waitForSlowClick && CanEnableCellControl())
+ {
+ ClearSelection();
+ EnableCellEditControl();
+
+ wxGridCellAttr* attr = GetCellAttr(coords);
+ wxGridCellEditor *editor = attr->GetEditor(this, coords.GetRow(), coords.GetCol());
+ editor->StartingClick();
+ editor->DecRef();
+ attr->DecRef();
+ m_waitForSlowClick = FALSE;
+ }
+ else if ( m_selectingTopLeft != wxGridNoCellCoords &&
+ m_selectingBottomRight != wxGridNoCellCoords )
+ {
if ( m_selection )
{
m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
// drag-shrinking.
ShowCellEditControl();
}
- else
- {
- if( m_waitForSlowClick && CanEnableCellControl())
- {
- EnableCellEditControl();
-
- wxGridCellAttr* attr = GetCellAttr(coords);
- wxGridCellEditor *editor = attr->GetEditor(this, coords.GetRow(), coords.GetCol());
- editor->StartingClick();
- editor->DecRef();
- attr->DecRef();
-
- m_waitForSlowClick = FALSE;
- }
- }
}
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
{
int rowTop = GetRowTop(m_dragRowOrCol);
SetRowSize( m_dragRowOrCol,
- wxMax( m_dragLastPos - rowTop, WXGRID_MIN_ROW_HEIGHT ) );
+ wxMax( m_dragLastPos - rowTop, m_minAcceptableRowHeight ) );
if ( !GetBatchCount() )
{
{
int i, cell_rows, cell_cols, subtract_rows = 0;
int leftCol = XToCol(left);
- int rightCol = XToCol(left+cw);
+ int rightCol = internalXToCol(left+cw);
if (leftCol >= 0)
{
- if (rightCol < 0) rightCol = m_numCols;
for (i=leftCol; i<rightCol; i++)
{
GetCellSize(m_dragRowOrCol, i, &cell_rows, &cell_cols);
{
int i, cell_rows, cell_cols, subtract_cols = 0;
int topRow = YToRow(top);
- int bottomRow = YToRow(top+cw);
+ int bottomRow = internalYToRow(top+cw);
if (topRow >= 0)
{
- if (bottomRow < 0) bottomRow = m_numRows;
for (i=topRow; i<bottomRow; i++)
{
GetCellSize(i, m_dragRowOrCol, &cell_rows, &cell_cols);
if (IsCellEditControlEnabled())
DisableCellEditControl();
- return m_table->InsertRows( pos, numRows );
+ bool done = m_table->InsertRows( pos, numRows );
+ return done;
// the table will have sent the results of the insert row
// operation to this view object as a grid table message
return FALSE;
}
- return ( m_table && m_table->AppendRows( numRows ) );
- // the table will have sent the results of the append row
- // operation to this view object as a grid table message
+ if ( m_table )
+ {
+ bool done = m_table && m_table->AppendRows( numRows );
+ return done;
+ // the table will have sent the results of the append row
+ // operation to this view object as a grid table message
+ }
+ return FALSE;
}
if (IsCellEditControlEnabled())
DisableCellEditControl();
- return (m_table->DeleteRows( pos, numRows ));
+ bool done = m_table->DeleteRows( pos, numRows );
+ return done;
// the table will have sent the results of the delete row
// operation to this view object as a grid table message
}
if (IsCellEditControlEnabled())
DisableCellEditControl();
- return m_table->InsertCols( pos, numCols );
+ bool done = m_table->InsertCols( pos, numCols );
+ return done;
// the table will have sent the results of the insert col
// operation to this view object as a grid table message
}
return FALSE;
}
- return ( m_table && m_table->AppendCols( numCols ) );
- // the table will have sent the results of the append col
- // operation to this view object as a grid table message
+ if ( m_table )
+ {
+ bool done = m_table->AppendCols( numCols );
+ return done;
+ // the table will have sent the results of the append col
+ // operation to this view object as a grid table message
+ }
+ return FALSE;
}
if (IsCellEditControlEnabled())
DisableCellEditControl();
- return ( m_table->DeleteCols( pos, numCols ) );
+ bool done = m_table->DeleteCols( pos, numCols );
+ return done;
// the table will have sent the results of the delete col
// operation to this view object as a grid table message
}
// try local handlers
//
- switch ( event.KeyCode() )
+ switch ( event.GetKeyCode() )
{
case WXK_UP:
if ( event.ControlDown() )
// <F2> is special and will always start editing, for
// other keys - ask the editor itself
- if ( (event.KeyCode() == WXK_F2 && !event.HasModifiers())
+ if ( (event.GetKeyCode() == WXK_F2 && !event.HasModifiers())
|| editor->IsAcceptedKey(event) )
{
// ensure cell is visble
{
// try local handlers
//
- if ( event.KeyCode() == WXK_SHIFT )
+ if ( event.GetKeyCode() == WXK_SHIFT )
{
if ( m_selectingTopLeft != wxGridNoCellCoords &&
m_selectingBottomRight != wxGridNoCellCoords )
bottom = wxMin( bottom, GetRowBottom(m_numRows - 1) );
// no gridlines inside multicells, clip them out
- int leftCol = XToCol(left);
- int topRow = YToRow(top);
- int rightCol = XToCol(right);
- int bottomRow = YToRow(bottom);
+ int leftCol = internalXToCol(left);
+ int topRow = internalYToRow(top);
+ int rightCol = internalXToCol(right);
+ int bottomRow = internalYToRow(bottom);
wxRegion clippedcells(0, 0, cw, ch);
- if ((leftCol >= 0) && (topRow >= 0))
- {
- if (rightCol < 0) rightCol = m_numCols;
- if (bottomRow < 0) bottomRow = m_numRows;
- int i, j, cell_rows, cell_cols;
- wxRect rect;
+ int i, j, cell_rows, cell_cols;
+ wxRect rect;
- for (j=topRow; j<bottomRow; j++)
+ for (j=topRow; j<bottomRow; j++)
+ {
+ for (i=leftCol; i<rightCol; i++)
{
- for (i=leftCol; i<rightCol; i++)
+ GetCellSize( j, i, &cell_rows, &cell_cols );
+ if ((cell_rows > 1) || (cell_cols > 1))
{
- GetCellSize( j, i, &cell_rows, &cell_cols );
- if ((cell_rows > 1) || (cell_cols > 1))
- {
- rect = CellToRect(j,i);
- CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
- clippedcells.Subtract(rect);
- }
- else if ((cell_rows < 0) || (cell_cols < 0))
- {
- rect = CellToRect(j+cell_rows, i+cell_cols);
- CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
- clippedcells.Subtract(rect);
- }
+ rect = CellToRect(j,i);
+ CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+ clippedcells.Subtract(rect);
+ }
+ else if ((cell_rows < 0) || (cell_cols < 0))
+ {
+ rect = CellToRect(j+cell_rows, i+cell_cols);
+ CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+ clippedcells.Subtract(rect);
}
}
}
// horizontal grid lines
//
- int i;
+ // already declared above - int i;
for ( i = internalYToRow(top); i < m_numRows; i++ )
{
int bot = GetRowBottom(i) - 1;
dc.SetTextForeground( GetLabelTextColour() );
dc.SetFont( GetLabelFont() );
- dc.SetBackgroundMode( wxTRANSPARENT );
- dc.SetTextForeground( GetLabelTextColour() );
- dc.SetFont( GetLabelFont() );
-
- int hAlign, vAlign;
+ int hAlign, vAlign, orient;
GetColLabelAlignment( &hAlign, &vAlign );
+ orient = GetColLabelTextOrientation();
wxRect rect;
rect.SetX( colLeft + 2 );
rect.SetY( 2 );
rect.SetWidth( GetColWidth(col) - 4 );
rect.SetHeight( m_colLabelHeight - 4 );
- DrawTextRectangle( dc, GetColLabelValue( col ), rect, hAlign, vAlign );
+ DrawTextRectangle( dc, GetColLabelValue( col ), rect, hAlign, vAlign, orient );
}
void wxGrid::DrawTextRectangle( wxDC& dc,
const wxString& value,
const wxRect& rect,
int horizAlign,
- int vertAlign )
+ int vertAlign,
+ int textOrientation )
{
wxArrayString lines;
//Forward to new API.
DrawTextRectangle( dc,
- lines,
- rect,
- horizAlign,
- vertAlign );
+ lines,
+ rect,
+ horizAlign,
+ vertAlign,
+ textOrientation );
}
void wxGrid::DrawTextRectangle( wxDC& dc,
- const wxArrayString& lines,
- const wxRect& rect,
- int horizAlign,
- int vertAlign )
+ const wxArrayString& lines,
+ const wxRect& rect,
+ int horizAlign,
+ int vertAlign,
+ int textOrientation )
{
long textWidth, textHeight;
long lineWidth, lineHeight;
nLines = lines.GetCount();
if( nLines > 0 )
{
- int l;
- float x, y;
- GetTextBoxSize(dc, lines, &textWidth, &textHeight);
- switch( vertAlign )
- {
+ int l;
+ float x = 0.0, y = 0.0;
+
+ if( textOrientation == wxHORIZONTAL )
+ GetTextBoxSize(dc, lines, &textWidth, &textHeight);
+ else
+ GetTextBoxSize( dc, lines, &textHeight, &textWidth );
+
+ switch( vertAlign )
+ {
case wxALIGN_BOTTOM:
- y = rect.y + (rect.height - textHeight - 1);
- break;
+ if( textOrientation == wxHORIZONTAL )
+ y = rect.y + (rect.height - textHeight - 1);
+ else
+ x = rect.x + rect.width - textWidth;
+ break;
case wxALIGN_CENTRE:
- y = rect.y + ((rect.height - textHeight)/2);
- break;
+ if( textOrientation == wxHORIZONTAL )
+ y = rect.y + ((rect.height - textHeight)/2);
+ else
+ x = rect.x + ((rect.width - textWidth)/2);
+ break;
case wxALIGN_TOP:
default:
- y = rect.y + 1;
- break;
- }
-
- // Align each line of a multi-line label
- for( l = 0; l < nLines; l++ )
- {
- dc.GetTextExtent(lines[l], &lineWidth, &lineHeight);
+ if( textOrientation == wxHORIZONTAL )
+ y = rect.y + 1;
+ else
+ x = rect.x + 1;
+ break;
+ }
- switch( horizAlign )
+ // Align each line of a multi-line label
+ for( l = 0; l < nLines; l++ )
{
- case wxALIGN_RIGHT:
- x = rect.x + (rect.width - lineWidth - 1);
- break;
+ dc.GetTextExtent(lines[l], &lineWidth, &lineHeight);
- case wxALIGN_CENTRE:
- x = rect.x + ((rect.width - lineWidth)/2);
- break;
+ switch( horizAlign )
+ {
+ case wxALIGN_RIGHT:
+ if( textOrientation == wxHORIZONTAL )
+ x = rect.x + (rect.width - lineWidth - 1);
+ else
+ y = rect.y + lineWidth + 1;
+ break;
- case wxALIGN_LEFT:
- default:
- x = rect.x + 1;
- break;
- }
+ case wxALIGN_CENTRE:
+ if( textOrientation == wxHORIZONTAL )
+ x = rect.x + ((rect.width - lineWidth)/2);
+ else
+ y = rect.y + rect.height - ((rect.height - lineWidth)/2);
+ break;
- dc.DrawText( lines[l], (int)x, (int)y );
- y += lineHeight;
- }
+ case wxALIGN_LEFT:
+ default:
+ if( textOrientation == wxHORIZONTAL )
+ x = rect.x + 1;
+ else
+ y = rect.y + rect.height - 1;
+ break;
+ }
+
+ if( textOrientation == wxHORIZONTAL )
+ {
+ dc.DrawText( lines[l], (int)x, (int)y );
+ y += lineHeight;
+ }
+ else
+ {
+ dc.DrawRotatedText( lines[l], (int)x, (int)y, 90.0 );
+ x += lineHeight;
+ }
+ }
}
dc.DestroyClippingRegion();
}
static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
const wxArrayInt& BorderArray, int nMax,
- bool maxOnOverflow)
+ bool clipToMinMax)
{
+
+ if (coord < 0)
+ return clipToMinMax && (nMax > 0) ? 0 : -1;
+
+
if (!defaultDist)
defaultDist = 1;
+
size_t i_max = coord / defaultDist,
i_min = 0;
{
if((int) i_max < nMax)
return i_max;
- return maxOnOverflow ? nMax - 1 : -1;
+ return clipToMinMax ? nMax - 1 : -1;
}
if ( i_max >= BorderArray.GetCount())
i_max = BorderArray.GetCount() - 1;
}
if ( coord >= BorderArray[i_max])
- return maxOnOverflow ? (int)i_max : -1;
+ return clipToMinMax ? (int)i_max : -1;
if ( coord < BorderArray[0] )
return 0;
int wxGrid::YToRow( int y )
{
return CoordToRowOrCol(y, m_defaultRowHeight,
- WXGRID_MIN_ROW_HEIGHT, m_rowBottoms, m_numRows, FALSE);
+ m_minAcceptableRowHeight, m_rowBottoms, m_numRows, FALSE);
}
int wxGrid::XToCol( int x )
{
return CoordToRowOrCol(x, m_defaultColWidth,
- WXGRID_MIN_COL_WIDTH, m_colRights, m_numCols, FALSE);
+ m_minAcceptableColWidth, m_colRights, m_numCols, FALSE);
}
m_gridWin->GetClientSize( &cw, &ch );
int y = GetRowTop(row);
- int newRow = YToRow( y - ch + 1 );
- if ( newRow == -1 )
- {
- newRow = 0;
- }
- else if ( newRow == row )
+ int newRow = internalYToRow( y - ch + 1 );
+
+ if ( newRow == row )
{
+ //row > 0 , so newrow can never be less than 0 here.
newRow = row - 1;
}
if ( m_currentCellCoords == wxGridNoCellCoords ) return FALSE;
int row = m_currentCellCoords.GetRow();
- if ( row < m_numRows )
+ if ( (row+1) < m_numRows )
{
int cw, ch;
m_gridWin->GetClientSize( &cw, &ch );
int y = GetRowTop(row);
- int newRow = YToRow( y + ch );
- if ( newRow == -1 )
+ int newRow = internalYToRow( y + ch );
+ if ( newRow == row )
{
- newRow = m_numRows - 1;
- }
- else if ( newRow == row )
- {
- newRow = row + 1;
+ // row < m_numRows , so newrow can't overflow here.
+ newRow = row + 1;
}
MakeCellVisible( newRow, m_currentCellCoords.GetCol() );
*vert = m_colLabelVertAlign;
}
+int wxGrid::GetColLabelTextOrientation()
+{
+ return m_colLabelTextOrientation;
+}
+
wxString wxGrid::GetRowLabelValue( int row )
{
if ( m_table )
}
}
+// Note: under MSW, the default column label font must be changed because it
+// does not support vertical printing
+//
+// Example: wxFont font(9, wxSWISS, wxNORMAL, wxBOLD);
+// pGrid->SetLabelFont(font);
+// pGrid->SetColLabelTextOrientation(wxVERTICAL);
+//
+void wxGrid::SetColLabelTextOrientation( int textOrientation )
+{
+ if( textOrientation == wxHORIZONTAL || textOrientation == wxVERTICAL )
+ {
+ m_colLabelTextOrientation = textOrientation;
+ }
+
+ if ( !GetBatchCount() )
+ {
+ m_colLabelWin->Refresh();
+ }
+}
+
void wxGrid::SetRowLabelValue( int row, const wxString& s )
{
if ( m_table )
void wxGrid::SetDefaultRowSize( int height, bool resizeExistingRows )
{
- m_defaultRowHeight = wxMax( height, WXGRID_MIN_ROW_HEIGHT );
+ m_defaultRowHeight = wxMax( height, m_minAcceptableRowHeight );
if ( resizeExistingRows )
{
{
wxCHECK_RET( row >= 0 && row < m_numRows, _T("invalid row index") );
+ // See comment in SetColSize
+ if ( height < GetRowMinimalAcceptableHeight()) { return; }
+
if ( m_rowHeights.IsEmpty() )
{
// need to really create the array
void wxGrid::SetDefaultColSize( int width, bool resizeExistingCols )
{
- m_defaultColWidth = wxMax( width, WXGRID_MIN_COL_WIDTH );
+ m_defaultColWidth = wxMax( width, m_minAcceptableColWidth );
if ( resizeExistingCols )
{
wxCHECK_RET( col >= 0 && col < m_numCols, _T("invalid column index") );
// should we check that it's bigger than GetColMinimalWidth(col) here?
+ // (VZ)
+ // No, because it is reasonable to assume the library user know's
+ // what he is doing. However whe should test against the weaker
+ // constariant of minimalAcceptableWidth, as this breaks rendering
+ //
+ // This test then fixes sf.net bug #645734
+
+ if ( width < GetColMinimalAcceptableWidth()) { return; }
if ( m_colWidths.IsEmpty() )
{
void wxGrid::SetColMinimalWidth( int col, int width )
{
- m_colMinWidths.Put(col, width);
+ if (width > GetColMinimalAcceptableWidth()) {
+ m_colMinWidths[col] = width;
+ }
}
void wxGrid::SetRowMinimalHeight( int row, int width )
{
- m_rowMinHeights.Put(row, width);
+ if (width > GetRowMinimalAcceptableHeight()) {
+ m_rowMinHeights[row] = width;
+ }
}
int wxGrid::GetColMinimalWidth(int col) const
{
- long value = m_colMinWidths.Get(col);
- return value != wxNOT_FOUND ? (int)value : WXGRID_MIN_COL_WIDTH;
+ wxLongToLongHashMap::const_iterator it = m_colMinWidths.find(col);
+ return it != m_colMinWidths.end() ? (int)it->second : m_minAcceptableColWidth;
}
int wxGrid::GetRowMinimalHeight(int row) const
{
- long value = m_rowMinHeights.Get(row);
- return value != wxNOT_FOUND ? (int)value : WXGRID_MIN_ROW_HEIGHT;
+ wxLongToLongHashMap::const_iterator it = m_rowMinHeights.find(row);
+ return it != m_rowMinHeights.end() ? (int)it->second : m_minAcceptableRowHeight;
+}
+
+void wxGrid::SetColMinimalAcceptableWidth( int width )
+{
+ if ( width<1 )
+ return;
+ m_minAcceptableColWidth = width;
+}
+
+void wxGrid::SetRowMinimalAcceptableHeight( int height )
+{
+ if ( height<1 )
+ return;
+ m_minAcceptableRowHeight = height;
+};
+
+int wxGrid::GetColMinimalAcceptableWidth() const
+{
+ return m_minAcceptableColWidth;
+}
+
+int wxGrid::GetRowMinimalAcceptableHeight() const
+{
+ return m_minAcceptableRowHeight;
}
// ----------------------------------------------------------------------------
dc.SetFont( GetLabelFont() );
if ( column )
+ {
dc.GetTextExtent( GetColLabelValue(col), &w, &h );
+ if( GetColLabelTextOrientation() == wxVERTICAL )
+ w = h;
+ }
else
dc.GetTextExtent( GetRowLabelValue(row), &w, &h );
SetClientSize(sizeFit);
}
+void wxGrid::AutoSizeRowLabelSize( int row )
+{
+ wxArrayString lines;
+ long w, h;
+
+ // Hide the edit control, so it
+ // won't interfer with drag-shrinking.
+ if( IsCellEditControlShown() )
+ {
+ HideCellEditControl();
+ SaveEditControlValue();
+ }
+
+ // autosize row height depending on label text
+ StringToLines( GetRowLabelValue( row ), lines );
+ wxClientDC dc( m_rowLabelWin );
+ GetTextBoxSize( dc, lines, &w, &h);
+ if( h < m_defaultRowHeight )
+ h = m_defaultRowHeight;
+ SetRowSize(row, h);
+ ForceRefresh();
+}
+
+void wxGrid::AutoSizeColLabelSize( int col )
+{
+ wxArrayString lines;
+ long w, h;
+
+ // Hide the edit control, so it
+ // won't interfer with drag-shrinking.
+ if( IsCellEditControlShown() )
+ {
+ HideCellEditControl();
+ SaveEditControlValue();
+ }
+
+ // autosize column width depending on label text
+ StringToLines( GetColLabelValue( col ), lines );
+ wxClientDC dc( m_colLabelWin );
+ if( GetColLabelTextOrientation() == wxHORIZONTAL )
+ GetTextBoxSize( dc, lines, &w, &h);
+ else
+ GetTextBoxSize( dc, lines, &h, &w);
+ if( w < m_defaultColWidth )
+ w = m_defaultColWidth;
+ SetColSize(col, w);
+ ForceRefresh();
+}
+
wxSize wxGrid::DoGetBestSize() const
{
// don't set sizes, only calculate them
return rect;
}
-
-
//
// ------ Grid event classes
//
m_ctrl = ctrl;
}
-
-#endif // !wxUSE_NEW_GRID/wxUSE_NEW_GRID
-
#endif // wxUSE_GRID
+