// data structures used for the data type registry
// ----------------------------------------------------------------------------
-struct wxGridDataTypeInfo {
+struct wxGridDataTypeInfo
+{
wxGridDataTypeInfo(const wxString& typeName,
wxGridCellRenderer* renderer,
wxGridCellEditor* editor)
WX_DEFINE_ARRAY(wxGridDataTypeInfo*, wxGridDataTypeInfoArray);
-class WXDLLEXPORT wxGridTypeRegistry {
+class WXDLLEXPORT wxGridTypeRegistry
+{
public:
~wxGridTypeRegistry();
+
void RegisterDataType(const wxString& typeName,
wxGridCellRenderer* renderer,
wxGridCellEditor* editor);
wxGridDataTypeInfoArray m_typeinfo;
};
-
-
-
// ----------------------------------------------------------------------------
// conditional compilation
// ----------------------------------------------------------------------------
{
if (m_control)
{
+ m_control->PopEventHandler(TRUE /* delete it*/);
+
m_control->Destroy();
m_control = NULL;
}
void wxGridCellBoolEditor::SetSize(const wxRect& r)
{
+ bool resize = FALSE;
+ wxSize size = m_control->GetSize();
+ wxCoord minSize = wxMin(r.width, r.height);
+
+ // check if the checkbox is not too big/small for this cell
+ wxSize sizeBest = m_control->GetBestSize();
+ if ( !(size == sizeBest) )
+ {
+ // reset to default size if it had been made smaller
+ size = sizeBest;
+
+ resize = TRUE;
+ }
+
+ if ( size.x >= minSize || size.y >= minSize )
+ {
+ // leave 1 pixel margin
+ size.x = size.y = minSize - 2;
+
+ resize = TRUE;
+ }
+
+ if ( resize )
+ {
+ m_control->SetSize(size);
+ }
+
// position it in the centre of the rectangle (TODO: support alignment?)
- int w, h;
- m_control->GetSize(&w, &h);
+#if defined(__WXGTK__) || defined (__WXMOTIF__)
// the checkbox without label still has some space to the right in wxGTK,
// so shift it to the right
-#if defined(__WXGTK__) || defined (__WXMOTIF__)
- w -= 8;
-#endif // GTK && Motif
+ size.x -= 8;
+#elif defined(__WXMSW__)
+ // here too...
+ size.x -= 6;
+ size.y -= 2;
+#endif
- m_control->Move(r.x + r.width/2 - w/2, r.y + r.height/2 - h/2);
+ m_control->Move(r.x + r.width/2 - size.x/2, r.y + r.height/2 - size.y/2);
}
void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr)
wxSize wxGridCellBoolRenderer::ms_sizeCheckMark;
+// FIXME these checkbox size calculations are really ugly...
+
// between checkmark and box
-static const wxCoord wxGRID_CHECKMARK_MARGIN = 4;
+#ifdef __WXGTK__
+ static const wxCoord wxGRID_CHECKMARK_MARGIN = 4;
+#else
+ static const wxCoord wxGRID_CHECKMARK_MARGIN = 2;
+#endif
wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid,
wxGridCellAttr& WXUNUSED(attr),
// draw a check mark in the centre (ignoring alignment - TODO)
wxSize size = GetBestSize(grid, attr, dc, row, col);
+
+ // don't draw outside the cell
+ wxCoord minSize = wxMin(rect.width, rect.height);
+ if ( size.x >= minSize || size.y >= minSize )
+ {
+ // and even leave (at least) 1 pixel margin
+ size.x = size.y = minSize - 2;
+ }
+
+ // draw a border around checkmark
wxRect rectMark;
rectMark.x = rect.x + rect.width/2 - size.x/2;
rectMark.y = rect.y + rect.height/2 - size.y/2;
rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN);
+#ifdef __WXMSW__
+ // looks nicer under MSW
+ rectMark.x++;
+#endif // MSW
+
bool value;
- if (grid.GetTable()->CanGetValueAs(row, col, wxT("bool")))
+ if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )
value = grid.GetTable()->GetValueAsBool(row, col);
else
value = !!grid.GetTable()->GetValue(row, col);
wxGridTypeRegistry::~wxGridTypeRegistry()
{
- for (size_t i=0; i<m_typeinfo.Count(); i++)
+ size_t count = m_typeinfo.Count();
+ for ( size_t i = 0; i < count; i++ )
delete m_typeinfo[i];
}
ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW);
}
+ if ( dragCol >= 0 )
+ {
+ m_dragRowOrCol = dragCol;
+
return;
}
MovePageDown();
break;
- // We don't want these keys to trigger the edit control, any others?
- case WXK_SHIFT:
- case WXK_ALT:
- case WXK_CONTROL:
- case WXK_CAPITAL:
- event.Skip();
- break;
-
case WXK_SPACE:
if ( !IsEditable() )
{
// Otherwise fall through to default
default:
- // now try the cell edit control
- //
- if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
+ // alphanumeric keys enable the cell edit control
+ if ( !(event.AltDown() ||
+ event.MetaDown() ||
+ event.ControlDown()) &&
+ isalnum(event.KeyCode()) &&
+ !IsCellEditControlEnabled() &&
+ CanEnableCellControl() )
{
EnableCellEditControl();
int row = m_currentCellCoords.GetRow();
}
else
{
- // let others process char events for readonly cells
+ // let others process char events with modifiers or all
+ // char events for readonly cells
event.Skip();
}
break;
#define TV_FIRST 0x1100
#endif
+#ifndef TVS_CHECKBOXES
+ #define TVS_CHECKBOXES 0x0100
+#endif
+
// old headers might miss these messages (comctl32.dll 4.71+ only)
#ifndef TVM_SETBKCOLOR
#define TVM_SETBKCOLOR (TV_FIRST + 29)
!defined( __WATCOMC__ ) && \
(!defined(__VISUALC__) || (__VISUALC__ > 1010))
-#ifndef TVS_CHECKBOXES
-#define TVS_CHECKBOXES 0x0100
-#endif
-
// we emulate the multiple selection tree controls by using checkboxes: set
// up the image list we need for this if we do have multiple selections
if ( m_windowStyle & wxTR_MULTIPLE )
wxTextCtrl* wxTreeCtrl::GetEditControl() const
{
+ // normally, we could try to do something like this to return something
+ // even when the editing was started by the user and not by calling
+ // EditLabel() - but as nobody has asked for this so far and there might be
+ // problems in the code below, I leave it disabled for now (VZ)
+#if 0
+ if ( !m_textCtrl )
+ {
+ HWND hwndText = TreeView_GetEditControl(GetHwnd());
+ if ( hwndText )
+ {
+ m_textCtrl = new wxTextCtrl(this, -1);
+ m_textCtrl->Hide();
+ m_textCtrl->SetHWND((WXHWND)hwndText);
+ }
+ //else: not editing label right now
+ }
+#endif // 0
+
return m_textCtrl;
}
{
wxASSERT( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)) );
+ DeleteTextCtrl();
+
HWND hWnd = (HWND) TreeView_EditLabel(GetHwnd(), (HTREEITEM) (WXHTREEITEM) item);
// this is not an error - the TVN_BEGINLABELEDIT handler might have
return NULL;
}
- DeleteTextCtrl();
-
m_textCtrl = (wxTextCtrl *)textControlClass->CreateObject();
m_textCtrl->SetHWND((WXHWND)hWnd);
m_textCtrl->SubclassWin((WXHWND)hWnd);