X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/14f355c2b5c71fc7c3d680aea366582d2ac60f7b..aa57eeea83fac24e9d188fa800bdc96c95f5bbeb:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 03bae1969d..ee086a77c8 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -41,6 +41,7 @@ #include "wx/checkbox.h" #include "wx/combobox.h" #include "wx/valtext.h" + #include "wx/intl.h" #endif #include "wx/textfile.h" @@ -69,7 +70,7 @@ // array classes // ---------------------------------------------------------------------------- -WX_DEFINE_ARRAY_WITH_DECL_NO_PTR(wxGridCellAttr *, wxArrayAttrs, +WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridCellAttr *, wxArrayAttrs, class WXDLLIMPEXP_ADV); struct wxGridCellWithAttr @@ -221,7 +222,7 @@ private: void OnKeyDown( wxKeyEvent& ); void OnKeyUp( wxKeyEvent& ); void OnEraseBackground( wxEraseEvent& ); - + void OnFocus( wxFocusEvent& ); DECLARE_DYNAMIC_CLASS(wxGridWindow) DECLARE_EVENT_TABLE() @@ -334,7 +335,7 @@ struct wxGridDataTypeInfo }; -WX_DEFINE_ARRAY_WITH_DECL_NO_PTR(wxGridDataTypeInfo*, wxGridDataTypeInfoArray, +WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridDataTypeInfo*, wxGridDataTypeInfoArray, class WXDLLIMPEXP_ADV); @@ -573,8 +574,7 @@ 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 ); @@ -669,7 +669,8 @@ bool wxGridCellTextEditor::EndEdit(int row, int col, grid->GetTable()->SetValue(row, col, value); m_startValue = wxEmptyString; - Text()->SetValue(m_startValue); + // No point in setting the text of the hidden control + //Text()->SetValue(m_startValue); return changed; } @@ -1067,7 +1068,13 @@ void wxGridCellFloatEditor::Reset() void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event) { int keycode = event.GetKeyCode(); - if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-' || keycode == '.' + char tmpbuf[2]; + tmpbuf[0] = (char) keycode; + tmpbuf[1] = '\0'; + bool is_decimal_point = ( wxString(tmpbuf, *wxConvCurrent) == + wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER) ); + if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-' + || is_decimal_point || keycode == WXK_NUMPAD0 || keycode == WXK_NUMPAD1 || keycode == WXK_NUMPAD2 @@ -1166,11 +1173,21 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event) case WXK_NUMPAD_DECIMAL: return TRUE; - default: - // additionally accept 'e' as in '1e+6' + default: + { + // additionally accept 'e' as in '1e+6', also '-', '+', and '.' + char tmpbuf[2]; + tmpbuf[0] = (char) keycode; + tmpbuf[1] = '\0'; + bool is_decimal_point = + ( wxString(tmpbuf, *wxConvCurrent) == + wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, + wxLOCALE_CAT_NUMBER) ); if ( (keycode < 128) && - (wxIsdigit(keycode) || tolower(keycode) == 'e') ) + (wxIsdigit(keycode) || tolower(keycode) == 'e' || + is_decimal_point || keycode == '+' || keycode == '-') ) return TRUE; + } } } @@ -1365,6 +1382,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) @@ -1393,20 +1415,11 @@ void wxGridCellChoiceEditor::Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) { - size_t count = m_choices.GetCount(); - wxString *choices = new wxString[count]; - for ( size_t n = 0; n < count; n++ ) - { - choices[n] = m_choices[n]; - } - m_control = new wxComboBox(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, - count, choices, + m_choices, m_allowOthers ? 0 : wxCB_READONLY); - delete [] choices; - wxGridCellEditor::Create(parent, id, evtHandler); } @@ -1957,10 +1970,9 @@ wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid, if ( !ms_sizeCheckMark.x ) { // get checkbox size - wxCoord checkSize = 0; wxCheckBox *checkbox = new wxCheckBox(&grid, -1, wxEmptyString); wxSize size = checkbox->GetBestSize(); - checkSize = size.y + 2*wxGRID_CHECKMARK_MARGIN; + wxCoord checkSize = size.y + 2*wxGRID_CHECKMARK_MARGIN; // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result #if defined(__WXGTK__) || defined(__WXMOTIF__) @@ -2580,13 +2592,9 @@ wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col, { //Basicaly implement old version. //Also check merge cache, so we don't have to re-merge every time.. - wxGridCellAttr *attrcell = (wxGridCellAttr *)NULL, - *attrrow = (wxGridCellAttr *)NULL, - *attrcol = (wxGridCellAttr *)NULL; - - attrcell = m_data->m_cellAttrs.GetAttr(row, col); - attrcol = m_data->m_colAttrs.GetAttr(col); - attrrow = m_data->m_rowAttrs.GetAttr(row); + wxGridCellAttr *attrcell = m_data->m_cellAttrs.GetAttr(row, col); + wxGridCellAttr *attrrow = m_data->m_rowAttrs.GetAttr(row); + wxGridCellAttr *attrcol = m_data->m_colAttrs.GetAttr(col); if((attrcell != attrrow) && (attrrow !=attrcol) && (attrcell != attrcol)){ // Two or move are non NULL @@ -2992,7 +3000,7 @@ wxString wxGridTableBase::GetColLabelValue( int col ) unsigned int i, n; for ( n = 1; ; n++ ) { - s += (_T('A') + (wxChar)( col%26 )); + s += (wxChar) (_T('A') + (wxChar)( col%26 )); col = col/26 - 1; if ( col < 0 ) break; } @@ -3138,23 +3146,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); @@ -3469,7 +3479,7 @@ END_EVENT_TABLE() wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid *parent, wxWindowID id, const wxPoint &pos, const wxSize &size ) - : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE ) + : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE ) { m_owner = parent; } @@ -3535,7 +3545,7 @@ END_EVENT_TABLE() wxGridColLabelWindow::wxGridColLabelWindow( wxGrid *parent, wxWindowID id, const wxPoint &pos, const wxSize &size ) - : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE ) + : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE ) { m_owner = parent; } @@ -3600,7 +3610,7 @@ END_EVENT_TABLE() wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid *parent, wxWindowID id, const wxPoint &pos, const wxSize &size ) - : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE ) + : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE ) { m_owner = parent; } @@ -3661,6 +3671,8 @@ BEGIN_EVENT_TABLE( wxGridWindow, wxWindow ) EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent ) EVT_KEY_DOWN( wxGridWindow::OnKeyDown ) EVT_KEY_UP( wxGridWindow::OnKeyUp ) + EVT_SET_FOCUS( wxGridWindow::OnFocus ) + EVT_KILL_FOCUS( wxGridWindow::OnFocus ) EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground ) END_EVENT_TABLE() @@ -3670,7 +3682,7 @@ wxGridWindow::wxGridWindow( wxGrid *parent, wxWindowID id, const wxPoint &pos, const wxSize &size ) - : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxCLIP_CHILDREN, + : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxCLIP_CHILDREN|wxFULL_REPAINT_ON_RESIZE, wxT("grid window") ) { @@ -3736,6 +3748,11 @@ void wxGridWindow::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ) { } +void wxGridWindow::OnFocus(wxFocusEvent& event) +{ + if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) + event.Skip(); +} ////////////////////////////////////////////////////////////////////// @@ -3758,7 +3775,57 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist, 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 ) @@ -3768,6 +3835,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, @@ -3781,6 +3858,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() { @@ -3916,21 +4010,21 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, { if ( m_created ) { - // stop all processing - m_created = FALSE; + // stop all processing + m_created = FALSE; if (m_ownTable) { wxGridTableBase *t=m_table; m_table=0; - delete t; + delete t; } - delete m_selection; - - m_table=0; - m_selection=0; - m_numRows=0; - m_numCols=0; + delete m_selection; + + m_table=0; + m_selection=0; + m_numRows=0; + m_numCols=0; } if (table) { @@ -4154,28 +4248,11 @@ void wxGrid::CalcDimensions() int x, y; GetViewStart( &x, &y ); - // maybe we don't need scrollbars at all? - // - // also adjust the position to be valid for the new scroll rangs - if ( w <= cw ) - { - w = x = 0; - } - else - { - if ( x >= w ) - x = w - 1; - } - - if ( h <= ch ) - { - h = y = 0; - } - else - { - if ( y >= h ) - y = h - 1; - } + // ensure the position is valid for the new scroll ranges + if ( x >= w ) + x = wxMax( w - 1, 0 ); + if ( y >= h ) + y = wxMax( h - 1, 0 ); // do set scrollbar parameters SetScrollbars( GRID_SCROLL_LINE_X, GRID_SCROLL_LINE_Y, @@ -4190,6 +4267,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 ); @@ -5914,7 +5996,7 @@ int wxGrid::SendEvent( const wxEventType type, wxMouseEvent& mouseEv ) { bool claimed; - bool vetoed= FALSE; + bool vetoed; if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE ) { @@ -5981,7 +6063,7 @@ int wxGrid::SendEvent( const wxEventType type, int row, int col ) { bool claimed; - bool vetoed= FALSE; + bool vetoed; if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE ) { @@ -7395,7 +7477,9 @@ bool wxGrid::IsCurrentCellReadOnly() const bool wxGrid::CanEnableCellControl() const { - return m_editable && !IsCurrentCellReadOnly(); + return m_editable && (m_currentCellCoords != wxGridNoCellCoords) && + !IsCurrentCellReadOnly(); + } bool wxGrid::IsCellEditControlEnabled() const @@ -7658,7 +7742,10 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist, if ( coord >= BorderArray[i_max]) { i_min = i_max; - i_max = coord / minDist; + if (minDist) + i_max = coord / minDist; + else + i_max = BorderArray.GetCount() - 1; } if ( i_max >= BorderArray.GetCount()) i_max = BorderArray.GetCount() - 1; @@ -9004,9 +9091,7 @@ void wxGrid::SetColFormatFloat(int col, int width, int precision) void wxGrid::SetColFormatCustom(int col, const wxString& typeName) { - wxGridCellAttr *attr = (wxGridCellAttr *)NULL; - - attr = m_table->GetAttr(-1, col, wxGridCellAttr::Col ); + wxGridCellAttr *attr = m_table->GetAttr(-1, col, wxGridCellAttr::Col ); if(!attr) attr = new wxGridCellAttr; wxGridCellRenderer *renderer = GetDefaultRendererForType(typeName); @@ -9339,13 +9424,13 @@ void wxGrid::SetColSize( int col, int width ) // 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 + // 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() ) { // need to really create the array @@ -9405,14 +9490,18 @@ int wxGrid::GetRowMinimalHeight(int row) const void wxGrid::SetColMinimalAcceptableWidth( int width ) { - if ( width<1 ) + // We do allow a width of 0 since this gives us + // an easy way to temporarily hidding columns. + if ( width<0 ) return; m_minAcceptableColWidth = width; } void wxGrid::SetRowMinimalAcceptableHeight( int height ) { - if ( height<1 ) + // We do allow a height of 0 since this gives us + // an easy way to temporarily hidding rows. + if ( height<0 ) return; m_minAcceptableRowHeight = height; };