MSW and GTK, and hopefully make it easy to make the same tweaks for
other ports. There are still some very minor anomalies (changing
colors of the grid doesn't change the IPE control, etc.) but it is
definitely useable now.
The IPE control now gets the fore/background color of the cell.
Changed how the current cell highlight is drawn so mulitple clicks in
a single cell don't leave the highlight in an inconsistent state for
GTK.
Changed a dangerous static variable to a member variable.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3182
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
void UpdateDimensions();
void SetCurrentRect (int Row, int Column, int canvasW = -1, int canvasH = -1);
void UpdateDimensions();
void SetCurrentRect (int Row, int Column, int canvasW = -1, int canvasH = -1);
- void HighlightCell (wxDC *dc);
+ void HighlightCell(wxDC *dc, bool doHighlight);
void DrawCellText();
void SetGridClippingRegion(wxDC *dc);
void DrawCellText();
void SetGridClippingRegion(wxDC *dc);
bool m_editable;
bool m_editInPlace;
bool m_inOnTextInPlace;
bool m_editable;
bool m_editInPlace;
bool m_inOnTextInPlace;
int m_totalRows;
int m_totalCols;
int m_totalRows;
int m_totalCols;
wxBrush m_labelBackgroundBrush;
wxFont m_labelTextFont;
wxPen m_divisionPen;
wxBrush m_labelBackgroundBrush;
wxFont m_labelTextFont;
wxPen m_divisionPen;
wxBitmap* m_doubleBufferingBitmap;
// Position of Edit control
wxBitmap* m_doubleBufferingBitmap;
// Position of Edit control
#include "wx/generic/gridg.h"
#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.
- #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 __WXGTK__
+#define wxIPE_ADJUST -1
+#define wxIPE_STYLE wxNO_BORDER
+#define wxIPE_HIGHLIGHT 0
+#define wxUSE_DOUBLE_BUFFERING 1
+#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
#define wxGRID_DRAG_NONE 0
#define wxGRID_DRAG_LEFT_RIGHT 1
#define wxGRID_DRAG_UP_DOWN 2
m_editInPlace = FALSE;
m_inOnTextInPlace = FALSE;
m_editInPlace = FALSE;
m_inOnTextInPlace = FALSE;
#if defined(__WIN95__)
m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
#if defined(__WIN95__)
m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
m_dragStartPosition = 0;
m_dragLastPosition = 0;
m_divisionPen = wxNullPen;
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;
m_leftOfSheet = wxGRID_DEFAULT_SHEET_LEFT;
m_topOfSheet = wxGRID_DEFAULT_SHEET_TOP;
m_cellHeight = wxGRID_DEFAULT_CELL_HEIGHT;
m_editable = TRUE;
m_editInPlace = FALSE;
m_inOnTextInPlace = FALSE;
m_editable = TRUE;
m_editInPlace = FALSE;
m_inOnTextInPlace = FALSE;
#if defined(__WIN95__)
m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
#elif defined(__WXGTK__)
#if defined(__WIN95__)
m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
#elif defined(__WXGTK__)
m_dragStartPosition = 0;
m_dragLastPosition = 0;
m_divisionPen = * wxThePenList->FindOrCreatePen("LIGHT GREY", 1, wxSOLID);
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())
m_doubleBufferingBitmap = (wxBitmap *) NULL;
if (!m_horizontalSashCursor.Ok())
// SetSize(pos.x, pos.y, size.x, size.y);
m_inPlaceTextItem = new wxTextCtrl( (wxPanel*)this, wxGRID_EDIT_IN_PLACE_TEXT_CTRL, "",
// 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 )
wxNO_BORDER | wxTE_PROCESS_ENTER );
m_inPlaceTextItem->Show(m_editInPlace);
if ( m_editInPlace )
/* Hilight present cell */
SetCurrentRect(m_wCursorRow, m_wCursorColumn);
/* 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);
dc.DestroyClippingRegion();
dc.SetOptimization(TRUE);
SetGridClippingRegion(dc);
// Remove the highlight from the old cell
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, FALSE);
if ( m_currentRect.x <= 0 )
{
x = 0;
if ( m_currentRect.x <= 0 )
{
x = 0;
- width = m_currentRect.width + 2;
+ width = m_currentRect.width + wxIPE_ADJUST;
- 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;
}
if ( m_currentRect.y <= 0 )
{
y = 0;
- height = m_currentRect.height + 2;
+ height = m_currentRect.height + wxIPE_ADJUST;
- 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 );
}
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( "" );
m_inPlaceTextItem->SetValue( "" );
- }
- else
- {
- m_inPlaceTextItem->SetFont( cell->GetFont() );
m_inPlaceTextItem->SetValue( cell->GetTextValue() );
m_inPlaceTextItem->SetValue( cell->GetTextValue() );
m_inPlaceTextItem->Show(TRUE);
m_inPlaceTextItem->SetFocus();
m_inPlaceTextItem->Show(TRUE);
m_inPlaceTextItem->SetFocus();
+ if (wxIPE_HIGHLIGHT)
+ HighlightCell(dc, TRUE);
//
// 3) It *is* needed for Motif - michael
//
//
// 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);
-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,
// Top
dc->DrawLine( m_currentRect.x + 1,
dc->DrawLine( m_currentRect.x + m_currentRect.width - 1,
m_currentRect.y + 1,
m_currentRect.x + m_currentRect.width - 1,
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,
// Bottom
dc->DrawLine( m_currentRect.x + m_currentRect.width - 1,
m_currentRect.y + m_currentRect.height - 1,
m_currentRect.x + 1,
m_currentRect.y + 1);
m_currentRect.x + 1,
m_currentRect.y + 1);
- dc->SetLogicalFunction(wxCOPY);
}
void wxGenericGrid::DrawCellText()
}
void wxGenericGrid::DrawCellText()
{
if ( m_currentRectVisible && m_editable )
{
{
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);
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( "" );
m_inPlaceTextItem->SetValue( "" );
- }
- else
- {
- m_inPlaceTextItem->SetFont( cell->GetFont() );
m_inPlaceTextItem->SetValue( cell->GetTextValue() );
m_inPlaceTextItem->SetValue( cell->GetTextValue() );
m_inPlaceTextItem->Show( TRUE );
m_inPlaceTextItem->SetFocus();
m_inPlaceTextItem->Show( TRUE );
m_inPlaceTextItem->SetFocus();
SetGridClippingRegion(& dc);
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;
m_wCursorRow = row;
m_wCursorColumn = col;
SetCurrentRect(row, col, cw, ch);
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();
dc.DestroyClippingRegion();
dc.EndDrawing();
m_inPlaceTextItem->SetValue( grid->GetTextItem()->GetValue() );
}
m_inPlaceTextItem->SetValue( grid->GetTextItem()->GetValue() );
}
+ 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,
//grid->OnCellChange(grid->GetCursorRow(), grid->GetCursorColumn());
wxGridEvent g_evt(GetId(), wxEVT_GRID_CELL_CHANGE, grid,
void wxGenericGrid::OnGridScroll(wxScrollEvent& ev)
{
void wxGenericGrid::OnGridScroll(wxScrollEvent& ev)
{
- static bool inScroll = FALSE;
-
- if ( inScroll )
return;
if ( m_editInPlace ) m_inPlaceTextItem->Show(FALSE);
return;
if ( m_editInPlace ) m_inPlaceTextItem->Show(FALSE);
wxGenericGrid *win = this;
bool change = FALSE;
wxGenericGrid *win = this;
bool change = FALSE;
if ( m_editInPlace && m_currentRectVisible )
{
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();
}
m_inPlaceTextItem->Show( TRUE );
m_inPlaceTextItem->SetFocus();
}