X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4b8f49129801403f12a3b840077841d268b080f9..72ae85dd61608315d54cb417177d7850472c1989:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index df8ef76582..e2bfd20cf4 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "grid.h" #endif @@ -69,7 +69,8 @@ // array classes // ---------------------------------------------------------------------------- -WX_DEFINE_EXPORTED_ARRAY(wxGridCellAttr *, wxArrayAttrs); +WX_DEFINE_ARRAY_WITH_DECL_NO_PTR(wxGridCellAttr *, wxArrayAttrs, + class WXDLLIMPEXP_ADV); struct wxGridCellWithAttr { @@ -91,7 +92,8 @@ struct 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" @@ -123,7 +125,7 @@ DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_CREATED) // private classes // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxGridRowLabelWindow : public wxWindow +class WXDLLIMPEXP_ADV wxGridRowLabelWindow : public wxWindow { public: wxGridRowLabelWindow() { m_owner = (wxGrid *)NULL; } @@ -145,7 +147,7 @@ private: }; -class WXDLLEXPORT wxGridColLabelWindow : public wxWindow +class WXDLLIMPEXP_ADV wxGridColLabelWindow : public wxWindow { public: wxGridColLabelWindow() { m_owner = (wxGrid *)NULL; } @@ -167,7 +169,7 @@ private: }; -class WXDLLEXPORT wxGridCornerLabelWindow : public wxWindow +class WXDLLIMPEXP_ADV wxGridCornerLabelWindow : public wxWindow { public: wxGridCornerLabelWindow() { m_owner = (wxGrid *)NULL; } @@ -188,7 +190,7 @@ private: DECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow) }; -class WXDLLEXPORT wxGridWindow : public wxWindow +class WXDLLIMPEXP_ADV wxGridWindow : public wxWindow { public: wxGridWindow() @@ -263,7 +265,7 @@ END_EVENT_TABLE() // ---------------------------------------------------------------------------- // this class stores attributes set for cells -class WXDLLEXPORT wxGridCellAttrData +class WXDLLIMPEXP_ADV wxGridCellAttrData { public: void SetAttr(wxGridCellAttr *attr, int row, int col); @@ -279,7 +281,7 @@ private: }; // this class stores attributes set for rows or columns -class WXDLLEXPORT wxGridRowOrColAttrData +class WXDLLIMPEXP_ADV wxGridRowOrColAttrData { public: // empty ctor to suppress warnings @@ -297,7 +299,7 @@ private: // 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; @@ -332,10 +334,11 @@ struct 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() {} @@ -458,7 +461,7 @@ void wxGridCellEditor::PaintBackground(const wxRect& rectCell, 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); @@ -570,12 +573,15 @@ void wxGridCellTextEditor::Create(wxWindow* parent, 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); } @@ -713,7 +719,7 @@ bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event) default: // accept 8 bit chars too if isprint() agrees - if ( (keycode < 255) && (isprint(keycode)) ) + if ( (keycode < 255) && (wxIsprint(keycode)) ) return TRUE; } } @@ -907,7 +913,7 @@ bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent& event) return TRUE; default: - if ( (keycode < 128) && isdigit(keycode) ) + if ( (keycode < 128) && wxIsdigit(keycode) ) return TRUE; } } @@ -920,7 +926,7 @@ void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event) if ( !HasRange() ) { int keycode = event.GetKeyCode(); - if ( isdigit(keycode) || keycode == '+' || keycode == '-' + if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-' || keycode == WXK_NUMPAD0 || keycode == WXK_NUMPAD1 || keycode == WXK_NUMPAD2 @@ -1060,7 +1066,7 @@ void wxGridCellFloatEditor::Reset() void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event) { int keycode = event.GetKeyCode(); - if ( isdigit(keycode) || keycode == '+' || keycode == '-' || keycode == '.' + if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-' || keycode == '.' || keycode == WXK_NUMPAD0 || keycode == WXK_NUMPAD1 || keycode == WXK_NUMPAD2 @@ -1162,7 +1168,7 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event) default: // additionally accept 'e' as in '1e+6' if ( (keycode < 128) && - (isdigit(keycode) || tolower(keycode) == 'e') ) + (wxIsdigit(keycode) || tolower(keycode) == 'e') ) return TRUE; } } @@ -1358,6 +1364,11 @@ wxString wxGridCellBoolEditor::GetValue() const // wxGridCellChoiceEditor // ---------------------------------------------------------------------------- +wxGridCellChoiceEditor::wxGridCellChoiceEditor(const wxArrayString& choices, + bool allowOthers) + : m_choices(choices), + m_allowOthers(allowOthers) { } + wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count, const wxString choices[], bool allowOthers) @@ -2061,7 +2072,7 @@ void wxGridCellAttr::Init(wxGridCellAttr *attrDefault) m_attrkind = wxGridCellAttr::Cell; m_sizeRows = m_sizeCols = 1; - m_overflow = TRUE; + m_overflow = UnsetOverflow; SetDefAttr(attrDefault); } @@ -2133,6 +2144,9 @@ void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom) if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() ) SetReadOnly(mergefrom->IsReadOnly()); + if (!HasOverflowMode() && mergefrom->HasOverflowMode() ) + SetOverflow(mergefrom->GetOverflow()); + SetDefAttr(mergefrom->m_defGridAttr); } @@ -3128,23 +3142,25 @@ int wxGridStringTable::GetNumberCols() 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); @@ -3459,7 +3475,7 @@ END_EVENT_TABLE() 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; } @@ -3525,7 +3541,7 @@ END_EVENT_TABLE() 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; } @@ -3590,7 +3606,7 @@ END_EVENT_TABLE() 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; } @@ -3660,7 +3676,7 @@ wxGridWindow::wxGridWindow( wxGrid *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") ) { @@ -3741,14 +3757,64 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist, 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(wxBORDER) + + // standard window styles + wxFLAGS_MEMBER(wxTAB_TRAVERSAL) + wxFLAGS_MEMBER(wxCLIP_CHILDREN) + wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) + wxFLAGS_MEMBER(wxWANTS_CHARS) + wxFLAGS_MEMBER(wxFULL_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 ) @@ -3758,6 +3824,16 @@ BEGIN_EVENT_TABLE( wxGrid, wxScrolledWindow ) 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, @@ -3771,6 +3847,23 @@ wxGrid::wxGrid( wxWindow *parent, 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() { @@ -3906,16 +3999,23 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, { 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(); @@ -3971,6 +4071,9 @@ void wxGrid::Init() 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 @@ -4170,6 +4273,11 @@ void wxGrid::CalcDimensions() 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 ); @@ -4832,7 +4940,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event ) else if ( event.RightDown() ) { row = YToRow(y); - if ( row >=0 && + if ( row >=0 && !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) ) { // no default action at the moment @@ -5424,7 +5532,20 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) m_winCapture = NULL; } - if ( m_selectingTopLeft != wxGridNoCellCoords && + 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 ) @@ -5446,21 +5567,6 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) // 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 ) { @@ -5599,7 +5705,7 @@ void wxGrid::DoEndDragResizeRow() int rowTop = GetRowTop(m_dragRowOrCol); SetRowSize( m_dragRowOrCol, - wxMax( m_dragLastPos - rowTop, WXGRID_MIN_ROW_HEIGHT ) ); + wxMax( m_dragLastPos - rowTop, m_minAcceptableRowHeight ) ); if ( !GetBatchCount() ) { @@ -5759,7 +5865,8 @@ bool wxGrid::InsertRows( int pos, int numRows, bool WXUNUSED(updateLabels) ) 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 @@ -5778,9 +5885,14 @@ bool wxGrid::AppendRows( int numRows, bool WXUNUSED(updateLabels) ) 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; } @@ -5799,7 +5911,8 @@ bool wxGrid::DeleteRows( int pos, int numRows, bool WXUNUSED(updateLabels) ) 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 } @@ -5822,7 +5935,8 @@ bool wxGrid::InsertCols( int pos, int numCols, bool WXUNUSED(updateLabels) ) 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 } @@ -5840,9 +5954,14 @@ bool wxGrid::AppendCols( int numCols, bool WXUNUSED(updateLabels) ) 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; } @@ -5861,7 +5980,8 @@ bool wxGrid::DeleteCols( int pos, int numCols, bool WXUNUSED(updateLabels) ) 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 } @@ -7103,10 +7223,10 @@ void wxGrid::DrawTextRectangle( wxDC& dc, int textOrientation ) { wxArrayString lines; - + StringToLines( value, lines ); - - + + //Forward to new API. DrawTextRectangle( dc, lines, @@ -7114,7 +7234,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc, horizAlign, vertAlign, textOrientation ); - + } void wxGrid::DrawTextRectangle( wxDC& dc, @@ -7127,20 +7247,20 @@ void wxGrid::DrawTextRectangle( wxDC& dc, long textWidth, textHeight; long lineWidth, lineHeight; int nLines; - + dc.SetClippingRegion( rect ); - + nLines = lines.GetCount(); if( nLines > 0 ) { 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: @@ -7149,14 +7269,14 @@ void wxGrid::DrawTextRectangle( wxDC& dc, else x = rect.x + rect.width - textWidth; break; - + case wxALIGN_CENTRE: if( textOrientation == wxHORIZONTAL ) y = rect.y + ((rect.height - textHeight)/2); else x = rect.x + ((rect.width - textWidth)/2); break; - + case wxALIGN_TOP: default: if( textOrientation == wxHORIZONTAL ) @@ -7165,12 +7285,12 @@ void wxGrid::DrawTextRectangle( wxDC& dc, x = rect.x + 1; break; } - + // Align each line of a multi-line label for( l = 0; l < nLines; l++ ) { dc.GetTextExtent(lines[l], &lineWidth, &lineHeight); - + switch( horizAlign ) { case wxALIGN_RIGHT: @@ -7179,14 +7299,14 @@ void wxGrid::DrawTextRectangle( wxDC& dc, else y = rect.y + lineWidth + 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; - + case wxALIGN_LEFT: default: if( textOrientation == wxHORIZONTAL ) @@ -7195,7 +7315,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc, y = rect.y + rect.height - 1; break; } - + if( textOrientation == wxHORIZONTAL ) { dc.DrawText( lines[l], (int)x, (int)y ); @@ -7605,7 +7725,7 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist, if (coord < 0) return clipToMinMax && (nMax > 0) ? 0 : -1; - + if (!defaultDist) defaultDist = 1; @@ -7656,14 +7776,14 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist, 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); } @@ -8009,10 +8129,10 @@ bool wxGrid::MovePageUp() int y = GetRowTop(row); int newRow = internalYToRow( y - ch + 1 ); - + if ( newRow == row ) { - //row > 0 , so newrow can never be less than 0 here. + //row > 0 , so newrow can never be less than 0 here. newRow = row - 1; } @@ -8039,7 +8159,7 @@ bool wxGrid::MovePageDown() int newRow = internalYToRow( y + ch ); if ( newRow == row ) { - // row < m_numRows , so newrow can't overflow here. + // row < m_numRows , so newrow can't overflow here. newRow = row + 1; } @@ -9242,7 +9362,7 @@ void wxGrid::EnableDragGridSize( bool enable ) void wxGrid::SetDefaultRowSize( int height, bool resizeExistingRows ) { - m_defaultRowHeight = wxMax( height, WXGRID_MIN_ROW_HEIGHT ); + m_defaultRowHeight = wxMax( height, m_minAcceptableRowHeight ); if ( resizeExistingRows ) { @@ -9261,6 +9381,9 @@ void wxGrid::SetRowSize( int row, int height ) { 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 @@ -9282,7 +9405,7 @@ void wxGrid::SetRowSize( int row, int height ) void wxGrid::SetDefaultColSize( int width, bool resizeExistingCols ) { - m_defaultColWidth = wxMax( width, WXGRID_MIN_COL_WIDTH ); + m_defaultColWidth = wxMax( width, m_minAcceptableColWidth ); if ( resizeExistingCols ) { @@ -9302,6 +9425,14 @@ void wxGrid::SetColSize( int col, int width ) 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() ) { @@ -9336,24 +9467,52 @@ void wxGrid::SetColSize( int col, int width ) 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; } // ---------------------------------------------------------------------------- @@ -9953,8 +10112,6 @@ wxRect wxGrid::BlockToDeviceRect( const wxGridCellCoords &topLeft, return rect; } - - // // ------ Grid event classes //