X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4f84c635dc03a42048661e5fe89d1a0c0e047408..065722d7b13d2dde15f536591f80567c489c561a:/src/generic/gridg.cpp?ds=sidebyside diff --git a/src/generic/gridg.cpp b/src/generic/gridg.cpp index e1a020e44d..4c33a1a32a 100644 --- a/src/generic/gridg.cpp +++ b/src/generic/gridg.cpp @@ -25,6 +25,8 @@ #pragma hdrstop #endif +#if wxUSE_GRID + #ifndef WX_PRECOMP #include "wx/utils.h" #include "wx/dcclient.h" @@ -39,13 +41,46 @@ #include "wx/generic/gridg.h" -// Set to zero to use no double-buffering + +// Values used to adjust the size of the in-place-edit control, and other +// goodies. Per-platform tweaks should be done here. #ifdef __WXMSW__ - #define wxUSE_DOUBLE_BUFFERING 1 -#else - #define wxUSE_DOUBLE_BUFFERING 0 +#define wxIPE_ADJUST -2 +#define wxIPE_STYLE wxNO_BORDER +#define wxIPE_HIGHLIGHT 1 +#define wxUSE_DOUBLE_BUFFERING 1 +#endif + +#ifdef __WXPM__ +#define wxIPE_ADJUST -1 +#define wxIPE_STYLE wxNO_BORDER +#define wxIPE_HIGHLIGHT 1 +#define wxUSE_DOUBLE_BUFFERING 1 +#endif + +#ifdef __WXGTK__ +#define wxIPE_ADJUST -1 +#define wxIPE_STYLE wxNO_BORDER +#define wxIPE_HIGHLIGHT 0 +#define wxUSE_DOUBLE_BUFFERING 1 +#endif + +#ifdef __WXMOTIF__ +#define wxIPE_ADJUST 2 +#define wxIPE_STYLE wxNO_BORDER +#define wxIPE_HIGHLIGHT 0 +#define wxUSE_DOUBLE_BUFFERING 0 +#endif + +#ifndef wxIPE_ADJUST +#define wxIPE_ADJUST 2 +#define wxIPE_STYLE wxNO_BORDER +#define wxIPE_HIGHLIGHT 0 +#define wxUSE_DOUBLE_BUFFERING 0 #endif + + #define wxGRID_DRAG_NONE 0 #define wxGRID_DRAG_LEFT_RIGHT 1 #define wxGRID_DRAG_UP_DOWN 2 @@ -90,7 +125,7 @@ wxGenericGrid::wxGenericGrid() m_cellBackgroundColour = *wxWHITE; m_labelTextColour = *wxBLACK; // m_labelBackgroundColour = *wxLIGHT_GREY; - m_labelBackgroundColour = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ); + m_labelBackgroundColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ); m_labelBackgroundBrush = wxNullBrush; m_labelTextFont = wxNullFont; m_cellTextFont = wxNullFont; @@ -100,11 +135,12 @@ wxGenericGrid::wxGenericGrid() m_editInPlace = FALSE; m_inOnTextInPlace = FALSE; + m_inScroll = FALSE; #if defined(__WIN95__) - m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X); + m_scrollWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); #elif defined(__WXGTK__) - m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X); + m_scrollWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); #else m_scrollWidth = 16; #endif @@ -113,6 +149,7 @@ wxGenericGrid::wxGenericGrid() m_dragStartPosition = 0; m_dragLastPosition = 0; m_divisionPen = wxNullPen; + m_highlightPen = wxNullPen; m_leftOfSheet = wxGRID_DEFAULT_SHEET_LEFT; m_topOfSheet = wxGRID_DEFAULT_SHEET_TOP; m_cellHeight = wxGRID_DEFAULT_CELL_HEIGHT; @@ -158,7 +195,7 @@ bool wxGenericGrid::Create(wxWindow *parent, m_cellBackgroundColour = *wxWHITE; m_labelTextColour = *wxBLACK; // m_labelBackgroundColour = *wxLIGHT_GREY; - m_labelBackgroundColour = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ); + m_labelBackgroundColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ); m_labelBackgroundBrush = wxNullBrush; m_labelTextFont = * wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxBOLD); m_cellTextFont = * wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL); @@ -167,10 +204,11 @@ bool wxGenericGrid::Create(wxWindow *parent, m_editable = TRUE; m_editInPlace = FALSE; m_inOnTextInPlace = FALSE; + m_inScroll = FALSE; #if defined(__WIN95__) - m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X); + m_scrollWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); #elif defined(__WXGTK__) - m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X); + m_scrollWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); #else m_scrollWidth = 16; #endif @@ -179,6 +217,7 @@ bool wxGenericGrid::Create(wxWindow *parent, m_dragStartPosition = 0; m_dragLastPosition = 0; m_divisionPen = * wxThePenList->FindOrCreatePen("LIGHT GREY", 1, wxSOLID); + m_highlightPen = * wxBLACK_PEN; m_doubleBufferingBitmap = (wxBitmap *) NULL; if (!m_horizontalSashCursor.Ok()) @@ -249,8 +288,8 @@ bool wxGenericGrid::Create(wxWindow *parent, // SetSize(pos.x, pos.y, size.x, size.y); m_inPlaceTextItem = new wxTextCtrl( (wxPanel*)this, wxGRID_EDIT_IN_PLACE_TEXT_CTRL, "", - wxPoint( m_currentRect.x-2, m_currentRect.y-2 ), - wxSize( m_currentRect.width+4, m_currentRect.height+4 ), + wxPoint( m_currentRect.x-wxIPE_ADJUST, m_currentRect.y-wxIPE_ADJUST ), + wxSize( m_currentRect.width+wxIPE_ADJUST*2, m_currentRect.height+wxIPE_ADJUST*2 ), wxNO_BORDER | wxTE_PROCESS_ENTER ); m_inPlaceTextItem->Show(m_editInPlace); if ( m_editInPlace ) @@ -546,8 +585,8 @@ void wxGenericGrid::PaintGrid(wxDC& dc) /* Hilight present cell */ SetCurrentRect(m_wCursorRow, m_wCursorColumn); - if (m_currentRectVisible && !(m_editable && m_editInPlace)) - HighlightCell(& dc); + if (m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace))) + HighlightCell(& dc, TRUE); dc.DestroyClippingRegion(); dc.SetOptimization(TRUE); @@ -1426,9 +1465,9 @@ void wxGenericGrid::OnSelectCellImplementation(wxDC *dc, int row, int col) SetGridClippingRegion(dc); // Remove the highlight from the old cell - if ( m_currentRectVisible && !(m_editable && m_editInPlace) ) + if ( m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace))) { - HighlightCell(dc); + HighlightCell(dc, FALSE); } @@ -1452,42 +1491,52 @@ void wxGenericGrid::OnSelectCellImplementation(wxDC *dc, int row, int col) if ( m_currentRect.x <= 0 ) { x = 0; - width = m_currentRect.width + 2; + width = m_currentRect.width + wxIPE_ADJUST; } else { - x = m_currentRect.x - 2; - width = m_currentRect.width + 4; + x = m_currentRect.x - wxIPE_ADJUST; + width = m_currentRect.width + wxIPE_ADJUST*2; } if ( m_currentRect.y <= 0 ) { y = 0; - height = m_currentRect.height + 2; + height = m_currentRect.height + wxIPE_ADJUST; } else { - y = m_currentRect.y - 2; - height = m_currentRect.height + 4; + y = m_currentRect.y - wxIPE_ADJUST; + height = m_currentRect.height + wxIPE_ADJUST*2; } m_inPlaceTextItem->SetSize( x, y, width, height ); - if ( cell ) - { - if ( cell->GetTextValue().IsNull() ) - { + if ( cell ) { + m_inPlaceTextItem->SetFont( cell->GetFont() ); + m_inPlaceTextItem->SetBackgroundColour(cell->GetBackgroundColour()); + m_inPlaceTextItem->SetForegroundColour(cell->GetTextColour()); + + if ( cell->GetTextValue().IsNull() ) { m_inPlaceTextItem->SetValue( "" ); - } - else - { - m_inPlaceTextItem->SetFont( cell->GetFont() ); + } + else { m_inPlaceTextItem->SetValue( cell->GetTextValue() ); - } - } + } + } m_inPlaceTextItem->Show(TRUE); m_inPlaceTextItem->SetFocus(); +#if defined(__VISAGECPP__) + { + int highlight = wxIPE_HIGHLIGHT; + if (highlight != 0) + HighlightCell(dc, TRUE); + } +#else + if (wxIPE_HIGHLIGHT != 0) + HighlightCell(dc, TRUE); +#endif } else { @@ -1498,9 +1547,9 @@ void wxGenericGrid::OnSelectCellImplementation(wxDC *dc, int row, int col) // // 3) It *is* needed for Motif - michael // -#ifdef __WXMOTIF__ - if ( !(m_editable && m_editInPlace) ) - HighlightCell(dc); +#if defined(__WXMOTIF__) + if ((wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace))) + HighlightCell(dc, TRUE); #endif } @@ -1557,9 +1606,13 @@ void wxGenericGrid::OnChangeSelectionLabel() } } -void wxGenericGrid::HighlightCell(wxDC *dc) +void wxGenericGrid::HighlightCell(wxDC *dc, bool doHighlight) { - dc->SetLogicalFunction(wxINVERT); + wxPen savePen = dc->GetPen(); + if (doHighlight) + dc->SetPen(m_highlightPen); + else + dc->SetPen(*wxThePenList->FindOrCreatePen(m_cellBackgroundColour, 1, wxSOLID)); // Top dc->DrawLine( m_currentRect.x + 1, @@ -1570,7 +1623,7 @@ void wxGenericGrid::HighlightCell(wxDC *dc) dc->DrawLine( m_currentRect.x + m_currentRect.width - 1, m_currentRect.y + 1, m_currentRect.x + m_currentRect.width - 1, - m_currentRect.y +m_currentRect.height - 1 ); + m_currentRect.y + m_currentRect.height - 1 ); // Bottom dc->DrawLine( m_currentRect.x + m_currentRect.width - 1, m_currentRect.y + m_currentRect.height - 1, @@ -1582,7 +1635,7 @@ void wxGenericGrid::HighlightCell(wxDC *dc) m_currentRect.x + 1, m_currentRect.y + 1); - dc->SetLogicalFunction(wxCOPY); + dc->SetPen(savePen); } void wxGenericGrid::DrawCellText() @@ -1735,21 +1788,21 @@ void wxGenericGrid::DrawTextRect(wxDC *dc, const wxString& text, wxRect *rect, i { case wxRIGHT: { - x = (rect->x + rect->width - textWidth - 1.0); - y = (rect->y + (rect->height - textHeight)/2.0); + x = (rect->x + rect->width - textWidth - (float)1.0); + y = (rect->y + (rect->height - textHeight)/(float)2.0); break; } case wxCENTRE: { - x = (rect->x + (rect->width - textWidth)/2.0); - y = (rect->y + (rect->height - textHeight)/2.0); + x = (rect->x + (rect->width - textWidth)/(float)2.0); + y = (rect->y + (rect->height - textHeight)/(float)2.0); break; } case wxLEFT: default: { - x = (rect->x + 1.0); - y = (rect->y + (rect->height - textHeight)/2.0); + x = (rect->x + (float)1.0); + y = (rect->y + (rect->height - textHeight)/(float)2.0); break; } } @@ -2094,23 +2147,25 @@ void wxGenericGrid::SetEditInPlace(bool edit) { if ( m_currentRectVisible && m_editable ) { - m_inPlaceTextItem->SetSize( m_currentRect.x-2, m_currentRect.y-2, - m_currentRect.width+4, m_currentRect.height+4 ); + m_inPlaceTextItem->SetSize( m_currentRect.x-wxIPE_ADJUST, + m_currentRect.y-wxIPE_ADJUST, + m_currentRect.width+wxIPE_ADJUST*2, + m_currentRect.height+wxIPE_ADJUST*2 ); wxGridCell *cell = GetCell(m_wCursorRow, m_wCursorColumn); - if ( cell ) - { - if ( cell->GetTextValue().IsNull() ) - { + if ( cell ) { + m_inPlaceTextItem->SetFont( cell->GetFont() ); + m_inPlaceTextItem->SetBackgroundColour(cell->GetBackgroundColour()); + m_inPlaceTextItem->SetForegroundColour(cell->GetTextColour()); + + if ( cell->GetTextValue().IsNull() ) { m_inPlaceTextItem->SetValue( "" ); - } - else - { - m_inPlaceTextItem->SetFont( cell->GetFont() ); + } + else { m_inPlaceTextItem->SetValue( cell->GetTextValue() ); - } - } + } + } m_inPlaceTextItem->Show( TRUE ); m_inPlaceTextItem->SetFocus(); @@ -2524,8 +2579,8 @@ void wxGenericGrid::SetGridCursor(int row, int col) SetGridClippingRegion(& dc); - if (m_currentRectVisible && !(m_editable && m_editInPlace) ) - HighlightCell(& dc); + if (m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace))) + HighlightCell(& dc, FALSE); m_wCursorRow = row; m_wCursorColumn = col; @@ -2535,8 +2590,8 @@ void wxGenericGrid::SetGridCursor(int row, int col) SetCurrentRect(row, col, cw, ch); - if (m_currentRectVisible && !(m_editable && m_editInPlace) ) - HighlightCell(& dc); + if (m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace))) + HighlightCell(& dc, TRUE); dc.DestroyClippingRegion(); dc.EndDrawing(); @@ -2603,15 +2658,17 @@ void wxGenericGrid::OnText(wxCommandEvent& WXUNUSED(ev) ) m_inPlaceTextItem->SetValue( grid->GetTextItem()->GetValue() ); } - wxClientDC dc(grid); + if (!m_editInPlace) { + wxClientDC dc(grid); - dc.BeginDrawing(); - grid->SetGridClippingRegion(& dc); - grid->DrawCellBackground(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn()); - grid->DrawCellValue(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn()); - if ( !(m_editable && m_editInPlace ) ) grid->HighlightCell(& dc); - dc.DestroyClippingRegion(); - dc.EndDrawing(); + dc.BeginDrawing(); + grid->SetGridClippingRegion(& dc); + grid->DrawCellBackground(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn()); + grid->DrawCellValue(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn()); + grid->HighlightCell(& dc, TRUE); + dc.DestroyClippingRegion(); + dc.EndDrawing(); + } //grid->OnCellChange(grid->GetCursorRow(), grid->GetCursorColumn()); wxGridEvent g_evt(GetId(), wxEVT_GRID_CELL_CHANGE, grid, @@ -2679,14 +2736,12 @@ void wxGenericGrid::OnTextInPlaceEnter(wxCommandEvent& WXUNUSED(ev) ) void wxGenericGrid::OnGridScroll(wxScrollEvent& ev) { - static bool inScroll = FALSE; - - if ( inScroll ) + if ( m_inScroll ) return; if ( m_editInPlace ) m_inPlaceTextItem->Show(FALSE); - inScroll = TRUE; + m_inScroll = TRUE; wxGenericGrid *win = this; bool change = FALSE; @@ -2715,13 +2770,15 @@ void wxGenericGrid::OnGridScroll(wxScrollEvent& ev) if ( m_editInPlace && m_currentRectVisible ) { - m_inPlaceTextItem->SetSize( m_currentRect.x-2, m_currentRect.y-2, - m_currentRect.width+4, m_currentRect.height+4 ); + m_inPlaceTextItem->SetSize( m_currentRect.x-wxIPE_ADJUST, + m_currentRect.y-wxIPE_ADJUST, + m_currentRect.width+wxIPE_ADJUST*2, + m_currentRect.height+wxIPE_ADJUST*2 ); m_inPlaceTextItem->Show( TRUE ); m_inPlaceTextItem->SetFocus(); } - inScroll = FALSE; + m_inScroll = FALSE; } @@ -2797,3 +2854,4 @@ void *wxGenericGrid::GetCellData(int row, int col) return rc; } +#endif // wxUSE_GRID