X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/73145b0ed18e99b66988c3caf6ad9119911913bb..851b3a889f69c33b8a94bf9c626141b7f1cadbbb:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 4d0b0fff74..a3390abd70 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -89,6 +89,10 @@ 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); @@ -141,6 +145,7 @@ private: DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow) DECLARE_EVENT_TABLE() + DECLARE_NO_COPY_CLASS(wxGridRowLabelWindow) }; @@ -162,6 +167,7 @@ private: DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow) DECLARE_EVENT_TABLE() + DECLARE_NO_COPY_CLASS(wxGridColLabelWindow) }; @@ -183,6 +189,7 @@ private: DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow) DECLARE_EVENT_TABLE() + DECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow) }; class WXDLLEXPORT wxGridWindow : public wxWindow @@ -203,6 +210,8 @@ public: void ScrollWindow( int dx, int dy, const wxRect *rect ); + wxGrid* GetOwner() { return m_owner; } + private: wxGrid *m_owner; wxGridRowLabelWindow *m_rowLabelWin; @@ -218,6 +227,7 @@ private: DECLARE_DYNAMIC_CLASS(wxGridWindow) DECLARE_EVENT_TABLE() + DECLARE_NO_COPY_CLASS(wxGridWindow) }; @@ -240,6 +250,7 @@ private: wxGridCellEditor* m_editor; DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler) DECLARE_EVENT_TABLE() + DECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler) }; @@ -320,6 +331,8 @@ struct wxGridDataTypeInfo wxString m_typeName; wxGridCellRenderer* m_renderer; wxGridCellEditor* m_editor; + + DECLARE_NO_COPY_CLASS(wxGridDataTypeInfo) }; @@ -424,6 +437,7 @@ static inline int GetScrollY(int y) wxGridCellEditor::wxGridCellEditor() { m_control = NULL; + m_attr = NULL; } @@ -445,6 +459,10 @@ void wxGridCellEditor::PaintBackground(const wxRect& rectCell, { // erase the background because we might not fill the cell wxClientDC dc(m_control->GetParent()); + 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); @@ -753,7 +771,6 @@ void wxGridCellTextEditor::SetParameters(const wxString& params) } } -// DJC MAPTEK // return the value in the text control wxString wxGridCellTextEditor::GetValue() const { @@ -906,7 +923,7 @@ void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event) { if ( !HasRange() ) { - int keycode = (int) event.KeyCode(); + int keycode = event.GetKeyCode(); if ( isdigit(keycode) || keycode == '+' || keycode == '-' || keycode == WXK_NUMPAD0 || keycode == WXK_NUMPAD1 @@ -961,7 +978,6 @@ void wxGridCellNumberEditor::SetParameters(const wxString& params) } } -// DJC MAPTEK // return the value in the spin control if it is there (the text control otherwise) wxString wxGridCellNumberEditor::GetValue() const { @@ -969,7 +985,7 @@ wxString wxGridCellNumberEditor::GetValue() const if( HasRange() ) { - int value = Spin()->GetValue(); + long value = Spin()->GetValue(); s.Printf(wxT("%ld"), value); } else @@ -1047,7 +1063,7 @@ void wxGridCellFloatEditor::Reset() void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event) { - int keycode = (int)event.KeyCode(); + int keycode = event.GetKeyCode(); if ( isdigit(keycode) || keycode == '+' || keycode == '-' || keycode == '.' || keycode == WXK_NUMPAD0 || keycode == WXK_NUMPAD1 @@ -1218,7 +1234,32 @@ void wxGridCellBoolEditor::SetSize(const wxRect& r) size.y -= 2; #endif - m_control->Move(r.x + r.width/2 - size.x/2, r.y + r.height/2 - size.y/2); + int hAlign = wxALIGN_CENTRE; + 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 + y = r.y + r.height/2 - size.y/2; + } + else if (hAlign == wxALIGN_RIGHT) + { + x = r.x + r.width - size.x - 2; + y = r.y + r.height/2 - size.y/2; + } + else if (hAlign == wxALIGN_CENTRE) + { + x = r.x + r.width/2 - size.x/2; + y = r.y + r.height/2 - size.y/2; + } + + m_control->Move(x, y); } void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr) @@ -1305,12 +1346,12 @@ bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent& event) return FALSE; } -// DJC MAPTEK + // return the value as "1" for true and the empty string for false wxString wxGridCellBoolEditor::GetValue() const { bool bSet = CBox()->GetValue(); - return bSet ? "1" : wxEmptyString; + return bSet ? _T("1") : wxEmptyString; } #endif // wxUSE_CHECKBOX @@ -1440,12 +1481,12 @@ void wxGridCellChoiceEditor::SetParameters(const wxString& params) } } -// DJC MAPTEK // return the value in the text control wxString wxGridCellChoiceEditor::GetValue() const { return Combo()->GetValue(); } + #endif // wxUSE_COMBOBOX // ---------------------------------------------------------------------------- @@ -1454,7 +1495,7 @@ wxString wxGridCellChoiceEditor::GetValue() const void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event) { - switch ( event.KeyCode() ) + switch ( event.GetKeyCode() ) { case WXK_ESCAPE: m_editor->Reset(); @@ -1479,7 +1520,7 @@ void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event) void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event) { - switch ( event.KeyCode() ) + switch ( event.GetKeyCode() ) { case WXK_ESCAPE: case WXK_TAB: @@ -1523,7 +1564,7 @@ void wxGridCellRenderer::Draw(wxGrid& grid, { dc.SetBackgroundMode( wxSOLID ); -// DJC (MAPTEK) grey out fields if the grid is disabled + // grey out fields if the grid is disabled if( grid.IsEnabled() ) { if ( isSelected ) @@ -1534,7 +1575,7 @@ void wxGridCellRenderer::Draw(wxGrid& grid, { dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) ); } - } + } else { dc.SetBrush(wxBrush(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE), wxSOLID)); @@ -1557,7 +1598,7 @@ void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid& grid, // TODO some special colours for attr.IsReadOnly() case? - // DJC (MAPTEK) different coloured text when the grid is disabled + // different coloured text when the grid is disabled if( grid.IsEnabled() ) { if ( isSelected ) @@ -1952,11 +1993,31 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, } // draw a border around checkmark + int vAlign, hAlign; + attr.GetAlignment(& hAlign, &vAlign); + wxRect rectBorder; - rectBorder.x = rect.x + rect.width/2 - size.x/2; - rectBorder.y = rect.y + rect.height/2 - size.y/2; - rectBorder.width = size.x; - rectBorder.height = size.y; + if (hAlign == wxALIGN_CENTRE) + { + rectBorder.x = rect.x + rect.width/2 - size.x/2; + rectBorder.y = rect.y + rect.height/2 - size.y/2; + rectBorder.width = size.x; + rectBorder.height = size.y; + } + else if (hAlign == wxALIGN_LEFT) + { + rectBorder.x = rect.x + 2; + rectBorder.y = rect.y + rect.height/2 - size.y/2; + rectBorder.width = size.x; + 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; + } bool value; if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) @@ -3597,12 +3658,14 @@ BEGIN_EVENT_TABLE( wxGridWindow, wxWindow ) EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground ) END_EVENT_TABLE() -// DJC (MAPTEK) 19-Jun-2001 use wxCLIP_CHILDREN as well wxGridWindow::wxGridWindow( wxGrid *parent, wxGridRowLabelWindow *rowLblWin, wxGridColLabelWindow *colLblWin, - wxWindowID id, const wxPoint &pos, const wxSize &size ) - : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxCLIP_CHILDREN, wxT("grid window") ) + wxWindowID id, + const wxPoint &pos, + const wxSize &size ) + : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxCLIP_CHILDREN, + wxT("grid window") ) { m_owner = parent; @@ -3900,8 +3963,7 @@ void wxGrid::Init() // 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; @@ -3945,8 +4007,8 @@ void wxGrid::Init() 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 = *wxBLACK; + m_selectionForeground = *wxWHITE; m_editable = TRUE; // default for whole grid @@ -4052,8 +4114,6 @@ void wxGrid::CalcDimensions() int w = m_numCols > 0 ? GetColRight(m_numCols - 1) + m_extraWidth + 1 : 0; int h = m_numRows > 0 ? GetRowBottom(m_numRows - 1) + m_extraHeight + 1 : 0; -// DJC (MAPTEK) 19-Jun-2001 account for editor since it could possibly -// be larger than the cell // take into account editor if shown if( IsCellEditControlShown() ) { @@ -6022,7 +6082,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& event ) // try local handlers // - switch ( event.KeyCode() ) + switch ( event.GetKeyCode() ) { case WXK_UP: if ( event.ControlDown() ) @@ -6187,15 +6247,16 @@ void wxGrid::OnKeyDown( wxKeyEvent& event ) // 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) ) { - // DJC MAPTEK - ensure cell is visble + // ensure cell is visble MakeCellVisible(row, col); EnableCellEditControl(); - // DJC MAPTEK - a problem can arise if the cell is not - // completely visible (even after calling MakeCellVisible - // the control is not created and calling StartingKey will + + // a problem can arise if the cell is not completely + // visible (even after calling MakeCellVisible the + // control is not created and calling StartingKey will // crash the app if( editor->IsCreated() && m_cellEditCtrlEnabled ) editor->StartingKey(event); } @@ -6224,7 +6285,7 @@ void wxGrid::OnKeyUp( wxKeyEvent& event ) { // try local handlers // - if ( event.KeyCode() == WXK_SHIFT ) + if ( event.GetKeyCode() == WXK_SHIFT ) { if ( m_selectingTopLeft != wxGridNoCellCoords && m_selectingBottomRight != wxGridNoCellCoords ) @@ -7389,14 +7450,16 @@ void wxGrid::ShowCellEditControl() rect.SetRight(client_right-1); } -// DJC (MAPTEK) 19-Feb-2001 do set size prior to showing the control + editor->SetCellAttr(attr); editor->SetSize( rect ); editor->Show( TRUE, attr ); -// DJC (MAPTEK) 19-Jun-2001 recalc dimensions in case we need to -// expand the scrolled window to account for editor + + // recalc dimensions in case we need to + // expand the scrolled window to account for editor CalcDimensions(); editor->BeginEdit(row, col, this); + editor->SetCellAttr(NULL); editor->DecRef(); attr->DecRef(); @@ -7717,7 +7780,6 @@ void wxGrid::MakeCellVisible( int row, int col ) } else if ( right > cw ) { - // DJC MAPTEK // position the view so that the cell is on the right int x0, y0; CalcUnscrolledPosition(0, 0, &x0, &y0); @@ -9172,7 +9234,7 @@ void wxGrid::SetColSize( int col, int width ) InitColWidths(); } - // DJC MAPTEK if < 0 calc new width from label + // if < 0 calc new width from label if( width < 0 ) { long w, h;