#include "wx/checkbox.h"
#include "wx/combobox.h"
#include "wx/valtext.h"
+ #include "wx/intl.h"
#endif
#include "wx/textfile.h"
// array classes
// ----------------------------------------------------------------------------
-WX_DEFINE_ARRAY_WITH_DECL_NO_PTR(wxGridCellAttr *, wxArrayAttrs,
+WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridCellAttr *, wxArrayAttrs,
class WXDLLIMPEXP_ADV);
struct wxGridCellWithAttr
void OnKeyDown( wxKeyEvent& );
void OnKeyUp( wxKeyEvent& );
void OnEraseBackground( wxEraseEvent& );
-
+ void OnFocus( wxFocusEvent& );
DECLARE_DYNAMIC_CLASS(wxGridWindow)
DECLARE_EVENT_TABLE()
};
-WX_DEFINE_ARRAY_WITH_DECL_NO_PTR(wxGridDataTypeInfo*, wxGridDataTypeInfoArray,
+WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridDataTypeInfo*, wxGridDataTypeInfoArray,
class WXDLLIMPEXP_ADV);
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;
}
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
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;
+ }
}
}
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);
}
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__)
{
//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
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;
}
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;
}
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;
}
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;
}
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()
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") )
{
m_owner = parent;
m_rowLabelWin = rowLblWin;
m_colLabelWin = colLblWin;
- SetBackgroundColour(_T("WHITE"));
}
{
}
+void wxGridWindow::OnFocus(wxFocusEvent& event)
+{
+ if ( !m_owner->GetEventHandler()->ProcessEvent( event ) )
+ event.Skip();
+}
//////////////////////////////////////////////////////////////////////
wxBEGIN_PROPERTIES_TABLE(wxGrid)
wxHIDE_PROPERTY( Children )
- wxPROPERTY_FLAGS( WindowStyle , wxGridStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
+ wxPROPERTY_FLAGS( WindowStyle , wxGridStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
wxEND_PROPERTIES_TABLE()
wxBEGIN_HANDLERS_TABLE(wxGrid)
// ----- internal init and update functions
//
+// NOTE: If using the default visual attributes works everywhere then this can
+// be removed as well as the #else cases below.
+#define _USE_VISATTR 0
+
+#if _USE_VISATTR
+#include "wx/listbox.h"
+#endif
+
void wxGrid::Create()
{
m_created = FALSE; // set to TRUE by CreateGrid
m_defaultCellAttr->SetKind(wxGridCellAttr::Default);
m_defaultCellAttr->SetFont(GetFont());
m_defaultCellAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_TOP);
+ m_defaultCellAttr->SetRenderer(new wxGridCellStringRenderer);
+ m_defaultCellAttr->SetEditor(new wxGridCellTextEditor);
+
+#if _USE_VISATTR
+ wxVisualAttributes gva = wxListBox::GetClassDefaultAttributes();
+ wxVisualAttributes lva = wxPanel::GetClassDefaultAttributes();
+
+ m_defaultCellAttr->SetTextColour(gva.colFg);
+ m_defaultCellAttr->SetBackgroundColour(gva.colBg);
+
+#else
m_defaultCellAttr->SetTextColour(
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
m_defaultCellAttr->SetBackgroundColour(
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
- m_defaultCellAttr->SetRenderer(new wxGridCellStringRenderer);
- m_defaultCellAttr->SetEditor(new wxGridCellTextEditor);
-
+#endif
m_numRows = 0;
m_numCols = 0;
SetTargetWindow( m_gridWin );
+#if _USE_VISATTR
+ wxColour gfg = gva.colFg;
+ wxColour gbg = gva.colBg;
+ wxColour lfg = lva.colFg;
+ wxColour lbg = lva.colBg;
+#else
+ wxColour gfg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
+ wxColour gbg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
+ wxColour lfg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
+ wxColour lbg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
+#endif
+ m_cornerLabelWin->SetDefaultForegroundColour(lfg);
+ m_cornerLabelWin->SetDefaultBackgroundColour(lbg);
+ m_rowLabelWin->SetDefaultForegroundColour(lfg);
+ m_rowLabelWin->SetDefaultBackgroundColour(lbg);
+ m_colLabelWin->SetDefaultForegroundColour(lfg);
+ m_colLabelWin->SetDefaultBackgroundColour(lbg);
+
+ m_gridWin->SetDefaultForegroundColour(gfg);
+ m_gridWin->SetDefaultBackgroundColour(gbg);
+
Init();
}
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,
wxMouseEvent& mouseEv )
{
bool claimed;
- bool vetoed= FALSE;
+ bool vetoed;
if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
{
int row, int col )
{
bool claimed;
- bool vetoed= FALSE;
+ bool vetoed;
if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
{
else
{
// at the bottom of a column
- HideCellEditControl();
- SaveEditControlValue();
+ DisableCellEditControl();
}
}
break;
else
{
// at left of grid
- HideCellEditControl();
- SaveEditControlValue();
+ DisableCellEditControl();
}
}
else
else
{
// at right of grid
- HideCellEditControl();
- SaveEditControlValue();
+ DisableCellEditControl();
}
}
break;
if ( m_currentCellCoords != wxGridNoCellCoords )
{
- HideCellEditControl();
DisableCellEditControl();
if ( IsVisible( m_currentCellCoords, FALSE ) )
bool wxGrid::CanEnableCellControl() const
{
- return m_editable && !IsCurrentCellReadOnly();
+ return m_editable && (m_currentCellCoords != wxGridNoCellCoords) &&
+ !IsCurrentCellReadOnly();
+
}
bool wxGrid::IsCellEditControlEnabled() const
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;
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);
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;
};
{
wxClientDC dc(m_gridWin);
+ //Cancel editting of cell
+ HideCellEditControl();
+ SaveEditControlValue();
+
// init both of them to avoid compiler warnings, even if weo nly need one
int row = -1,
col = -1;