#if wxUSE_GRID
+#include "wx/grid.h"
+
#ifndef WX_PRECOMP
#include "wx/utils.h"
#include "wx/dcclient.h"
#include "wx/valtext.h"
#include "wx/intl.h"
#include "wx/math.h"
+ #include "wx/listbox.h"
#endif
#include "wx/textfile.h"
#include "wx/tokenzr.h"
#include "wx/renderer.h"
-#include "wx/grid.h"
#include "wx/generic/gridsel.h"
+const wxChar wxGridNameStr[] = wxT("grid");
+
#if defined(__WXMOTIF__)
#define WXUNUSED_MOTIF(identifier) WXUNUSED(identifier)
#else
wxGridRowLabelWindow *rowLblWin,
wxGridColLabelWindow *colLblWin,
wxWindowID id, const wxPoint &pos, const wxSize &size );
- ~wxGridWindow() {}
+ virtual ~wxGridWindow() {}
void ScrollWindow( int dx, int dy, const wxRect *rect );
{
if ( wxGridCellEditor::IsAcceptedKey(event) )
{
- int keycode = event.GetKeyCode();
- printf("%d\n", keycode);
- // accept digits, 'e' as in '1e+6', also '-', '+', and '.'
- char tmpbuf[2];
- tmpbuf[0] = (char) keycode;
- tmpbuf[1] = '\0';
- wxString strbuf(tmpbuf, *wxConvCurrent);
+ const int keycode = event.GetKeyCode();
+ if ( isascii(keycode) )
+ {
+ char tmpbuf[2];
+ tmpbuf[0] = (char) keycode;
+ tmpbuf[1] = '\0';
+ wxString strbuf(tmpbuf, *wxConvCurrent);
#if wxUSE_INTL
- bool is_decimal_point =
- ( strbuf == wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT,
- wxLOCALE_CAT_NUMBER) );
+ const wxString decimalPoint =
+ wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER);
#else
- bool is_decimal_point = ( strbuf == _T(".") );
+ const wxString decimalPoint(_T('.'));
#endif
- if ( (keycode < 128) &&
- (wxIsdigit(keycode) || tolower(keycode) == 'e' ||
- is_decimal_point || keycode == '+' || keycode == '-') )
- {
- return true;
+ // accept digits, 'e' as in '1e+6', also '-', '+', and '.'
+ if ( wxIsdigit(keycode) ||
+ tolower(keycode) == 'e' ||
+ keycode == decimalPoint ||
+ keycode == '+' ||
+ keycode == '-' )
+ {
+ return true;
+ }
}
}
if ( IsReadOnly() )
attr->SetReadOnly();
+ attr->SetOverflow( m_overflow == Overflow );
attr->SetKind( m_attrkind );
return attr;
int x, y;
m_owner->CalcUnscrolledPosition( 0, 0, &x, &y );
- dc.SetDeviceOrigin( 0, -y );
+ wxPoint pt = dc.GetDeviceOrigin();
+ dc.SetDeviceOrigin( pt.x, pt.y-y );
wxArrayInt rows = m_owner->CalcRowLabelsExposed( GetUpdateRegion() );
m_owner->DrawRowLabels( dc, rows );
int x, y;
m_owner->CalcUnscrolledPosition( 0, 0, &x, &y );
- dc.SetDeviceOrigin( -x, 0 );
+ wxPoint pt = dc.GetDeviceOrigin();
+ if (GetLayoutDirection() == wxLayout_RightToLeft)
+ dc.SetDeviceOrigin( pt.x+x, pt.y );
+ else
+ dc.SetDeviceOrigin( pt.x-x, pt.y );
wxArrayInt cols = m_owner->CalcColLabelsExposed( GetUpdateRegion() );
m_owner->DrawColLabels( dc, cols );
// be removed as well as the #else cases below.
#define _USE_VISATTR 0
-#if _USE_VISATTR
-#include "wx/listbox.h"
-#endif
-
void wxGrid::Create()
{
// set to true by CreateGrid
m_currentCellCoords = wxGridNoCellCoords;
- m_selectingTopLeft = wxGridNoCellCoords;
- m_selectingBottomRight = wxGridNoCellCoords;
+ ClearSelection();
+
m_selectionBackground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
m_selectionForeground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
switch ( m_cursorMode )
{
case WXGRID_CURSOR_RESIZE_COL:
- {
DoEndDragResizeCol();
// Note: we are ending the event *after* doing
// default processing in this case
//
SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
- }
- break;
+ break;
case WXGRID_CURSOR_MOVE_COL:
- {
DoEndDragMoveCol();
SendEvent( wxEVT_GRID_COL_MOVE, -1, m_dragRowOrCol, event );
- }
- break;
+ break;
+
+ case WXGRID_CURSOR_SELECT_COL:
+ case WXGRID_CURSOR_SELECT_CELL:
+ case WXGRID_CURSOR_RESIZE_ROW:
+ case WXGRID_CURSOR_SELECT_ROW:
+ // nothing to do (?)
+ break;
}
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
}
+ else if ( type == wxEVT_GRID_LABEL_LEFT_CLICK ||
+ type == wxEVT_GRID_LABEL_LEFT_DCLICK ||
+ type == wxEVT_GRID_LABEL_RIGHT_CLICK ||
+ type == wxEVT_GRID_LABEL_RIGHT_DCLICK )
+ {
+ wxPoint pos = mouseEv.GetPosition();
+
+ if ( mouseEv.GetEventObject() == GetGridRowLabelWindow() )
+ pos.y += GetColLabelSize();
+ if ( mouseEv.GetEventObject() == GetGridColLabelWindow() )
+ pos.x += GetRowLabelSize();
+
+ wxGridEvent gridEvt( GetId(),
+ type,
+ this,
+ row, col,
+ pos.x,
+ pos.y,
+ false,
+ mouseEv.ControlDown(),
+ mouseEv.ShiftDown(),
+ mouseEv.AltDown(),
+ mouseEv.MetaDown() );
+ claimed = GetEventHandler()->ProcessEvent(gridEvt);
+ vetoed = !gridEvt.IsAllowed();
+ }
else
{
wxGridEvent gridEvt( GetId(),
if ( !parent->GetEventHandler()->ProcessEvent( keyEvt ) )
{
+ if (GetLayoutDirection() == wxLayout_RightToLeft)
+ {
+ if (event.GetKeyCode() == WXK_RIGHT)
+ event.m_keyCode = WXK_LEFT;
+ else if (event.GetKeyCode() == WXK_LEFT)
+ event.m_keyCode = WXK_RIGHT;
+ }
+
// try local handlers
switch ( event.GetKeyCode() )
{
#endif
}
+wxPen wxGrid::GetDefaultGridLinePen()
+{
+ return wxPen(GetGridLineColour(), 1, wxSOLID);
+}
+
+wxPen wxGrid::GetRowGridLinePen(int WXUNUSED(row))
+{
+ return GetDefaultGridLinePen();
+}
+
+wxPen wxGrid::GetColGridLinePen(int WXUNUSED(col))
+{
+ return GetDefaultGridLinePen();
+}
+
void wxGrid::DrawCellBorder( wxDC& dc, const wxGridCellCoords& coords )
{
int row = coords.GetRow();
if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 )
return;
- dc.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID) );
wxRect rect = CellToRect( row, col );
// right hand border
+ dc.SetPen( GetColGridLinePen(col) );
dc.DrawLine( rect.x + rect.width, rect.y,
rect.x + rect.width, rect.y + rect.height + 1 );
// bottom border
+ dc.SetPen( GetRowGridLinePen(row) );
dc.DrawLine( rect.x, rect.y + rect.height,
rect.x + rect.width, rect.y + rect.height);
}
dc.SetClippingRegion( clippedcells );
- dc.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID) );
// horizontal grid lines
//
if ( bot >= top )
{
+ dc.SetPen( GetRowGridLinePen(i) );
dc.DrawLine( left, bot, right, bot );
}
}
{
i = GetColAt( colPos );
- int colRight = GetColRight(i) - 1;
+ int colRight = GetColRight(i);
+#ifdef __WXGTK__
+ if (GetLayoutDirection() != wxLayout_RightToLeft)
+#endif
+ colRight--;
+
if ( colRight > right )
{
break;
if ( colRight >= left )
{
+ dc.SetPen( GetColGridLinePen(i) );
dc.DrawLine( colRight, top, colRight, bottom );
}
}
continue;
}
- long lineWidth,
- lineHeight;
+ long lineWidth = 0,
+ lineHeight = 0;
dc.GetTextExtent(line, &lineWidth, &lineHeight);
switch ( horizAlign )
m_currentCellCoords.SetCol( col );
}
- // convert to scrolled coords
- CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
-
- int nXMove = 0;
- if (rect.x < 0)
- nXMove = rect.x;
-
// erase the highlight and the cell contents because the editor
// might not cover the entire cell
wxClientDC dc( m_gridWin );
dc.SetPen(*wxTRANSPARENT_PEN);
dc.DrawRectangle(rect);
+ // convert to scrolled coords
+ CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+
+ int nXMove = 0;
+ if (rect.x < 0)
+ nXMove = rect.x;
+
// cell is shifted by one pixel
// However, don't allow x or y to become negative
// since the SetSize() method interprets that as
return GetColAt( maxPos );
}
-// return the row number that that the y coord is near the edge of, or
-// -1 if not near an edge
+// return the row number that that the y coord is near
+// the edge of, or -1 if not near an edge.
+// coords can only possibly be near an edge if
+// (a) the row/column is large enough to still allow for an "inner" area
+// that is _not_ nead the edge (i.e., if the height/width is smaller
+// than WXGRID_LABEL_EDGE_ZONE, coords are _never_ considered to be
+// near the edge).
+// and
+// (b) resizing rows/columns (the thing for which edge detection is
+// relevant at all) is enabled.
//
int wxGrid::YToEdgeOfRow( int y )
{
int i;
i = internalYToRow(y);
- if ( GetRowHeight(i) > WXGRID_LABEL_EDGE_ZONE )
+ if ( GetRowHeight(i) > WXGRID_LABEL_EDGE_ZONE && CanDragRowSize() )
{
// We know that we are in row i, test whether we are
// close enough to lower or upper border, respectively.
// return the col number that that the x coord is near the edge of, or
// -1 if not near an edge
+// See comment at YToEdgeOfRow for conditions on edge detection.
//
int wxGrid::XToEdgeOfCol( int x )
{
int i;
i = internalXToCol(x);
- if ( GetColWidth(i) > WXGRID_LABEL_EDGE_ZONE )
+ if ( GetColWidth(i) > WXGRID_LABEL_EDGE_ZONE && CanDragColSize() )
{
// We know that we are in column i; test whether we are
// close enough to right or left border, respectively.
if ( column )
{
- dc.GetTextExtent( GetColLabelValue(col), &w, &h );
+ dc.GetMultiLineTextExtent( GetColLabelValue(col), &w, &h );
if ( GetColLabelTextOrientation() == wxVERTICAL )
w = h;
}
else
- dc.GetTextExtent( GetRowLabelValue(row), &w, &h );
+ dc.GetMultiLineTextExtent( GetRowLabelValue(row), &w, &h );
extent = column ? w : h;
if ( extent > extentMax )
void wxGrid::ClearSelection()
{
- m_selectingTopLeft = wxGridNoCellCoords;
- m_selectingBottomRight = wxGridNoCellCoords;
+ m_selectingTopLeft =
+ m_selectingBottomRight =
+ m_selectingKeyboard = wxGridNoCellCoords;
if ( m_selection )
m_selection->ClearSelection();
}