#define WXUNUSED_GTK(identifier) identifier
#endif
+#ifdef __WXOSX__
+#include "wx/osx/private.h"
+#endif
+
// Required for wxIs... functions
#include <ctype.h>
m_control->PushEventHandler(evtHandler);
}
-void wxGridCellEditor::PaintBackground(const wxRect& rectCell,
- wxGridCellAttr *attr)
+void wxGridCellEditor::PaintBackground(wxDC& dc,
+ const wxRect& rectCell,
+ const wxGridCellAttr& attr)
{
// erase the background because we might not fill the cell
- wxClientDC dc(m_control->GetParent());
- wxGridWindow* gridWindow = wxDynamicCast(m_control->GetParent(), wxGridWindow);
- if (gridWindow)
- gridWindow->GetOwner()->PrepareDC(dc);
-
dc.SetPen(*wxTRANSPARENT_PEN);
- dc.SetBrush(wxBrush(attr->GetBackgroundColour()));
+ dc.SetBrush(wxBrush(attr.GetBackgroundColour()));
dc.DrawRectangle(rectCell);
-
- // redraw the control we just painted over
- m_control->Refresh();
}
void wxGridCellEditor::Destroy()
wxDefaultPosition, wxDefaultSize,
style);
+#ifdef __WXOSX__
+ wxWidgetImpl* impl = m_control->GetPeer();
+ impl->SetNeedsFocusRect(false);
+#endif
// set max length allowed in the textctrl, if the parameter was set
if ( m_maxChars != 0 )
{
wxGridCellEditor::Create(parent, id, evtHandler);
}
-void wxGridCellTextEditor::PaintBackground(const wxRect& WXUNUSED(rectCell),
- wxGridCellAttr * WXUNUSED(attr))
+void wxGridCellTextEditor::PaintBackground(wxDC& WXUNUSED(dc),
+ const wxRect& WXUNUSED(rectCell),
+ const wxGridCellAttr& WXUNUSED(attr))
{
// as we fill the entire client area,
// don't do anything here to minimize flicker
rect.width -= 2;
rect.height -= 2;
+#elif defined(__WXOSX__)
+ rect.x += 1;
+ rect.y += 1;
+
+ rect.width -= 1;
+ rect.height -= 1;
#else
int extra_x = ( rect.x > 2 ) ? 2 : 1;
int extra_y = ( rect.y > 2 ) ? 2 : 1;
{
Text()->SetValue(startValue);
Text()->SetInsertionPointEnd();
- Text()->SetSelection(-1, -1);
+ Text()->SelectAll();
Text()->SetFocus();
}
wxGridCellEditor::Create(parent, id, evtHandler);
}
-void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell,
- wxGridCellAttr * attr)
+void wxGridCellChoiceEditor::SetSize(const wxRect& rect)
+{
+ wxASSERT_MSG(m_control,
+ wxT("The wxGridCellChoiceEditor must be created first!"));
+
+ // Check that the height is not too small to fit the combobox.
+ wxRect rectTallEnough = rect;
+ const wxSize bestSize = m_control->GetBestSize();
+ const wxCoord diffY = bestSize.GetHeight() - rectTallEnough.GetHeight();
+ if ( diffY > 0 )
+ {
+ // Do make it tall enough.
+ rectTallEnough.height += diffY;
+
+ // Also centre the effective rectangle vertically with respect to the
+ // original one.
+ rectTallEnough.y -= diffY/2;
+ }
+ //else: The rectangle provided is already tall enough.
+
+ wxGridCellEditor::SetSize(rectTallEnough);
+}
+
+void wxGridCellChoiceEditor::PaintBackground(wxDC& dc,
+ const wxRect& rectCell,
+ const wxGridCellAttr& attr)
{
// as we fill the entire client area, don't do anything here to minimize
// flicker
// TODO: It doesn't actually fill the client area since the height of a
// combo always defaults to the standard. Until someone has time to
// figure out the right rectangle to paint, just do it the normal way.
- wxGridCellEditor::PaintBackground(rectCell, attr);
+ wxGridCellEditor::PaintBackground(dc, rectCell, attr);
}
void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
Combo()->SetFocus();
+#ifdef __WXOSX_COCOA__
+ // This is a work around for the combobox being simply dismissed when a
+ // choice is made in it under OS X. The bug is almost certainly due to a
+ // problem in focus events generation logic but it's not obvious to fix and
+ // for now this at least allows to use wxGrid.
+ Combo()->Popup();
+#endif
+
if (evtHandler)
{
// When dropping down the menu, a kill focus event
wxASSERT_MSG(m_control,
wxT("The wxGridCellEnumEditor must be Created first!"));
+ wxGridCellEditorEvtHandler* evtHandler = NULL;
+ if (m_control)
+ evtHandler = wxDynamicCast(m_control->GetEventHandler(), wxGridCellEditorEvtHandler);
+
+ // Don't immediately end if we get a kill focus event within BeginEdit
+ if (evtHandler)
+ evtHandler->SetInSetFocus(true);
+
wxGridTableBase *table = grid->GetTable();
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
Combo()->SetSelection(m_index);
Combo()->SetFocus();
+#ifdef __WXOSX_COCOA__
+ // This is a work around for the combobox being simply dismissed when a
+ // choice is made in it under OS X. The bug is almost certainly due to a
+ // problem in focus events generation logic but it's not obvious to fix and
+ // for now this at least allows to use wxGrid.
+ Combo()->Popup();
+#endif
+
+ if (evtHandler)
+ {
+ // When dropping down the menu, a kill focus event
+ // happens after this point, so we can't reset the flag yet.
+#if !defined(__WXGTK20__)
+ evtHandler->SetInSetFocus(false);
+#endif
+ }
}
bool wxGridCellEnumEditor::EndEdit(int WXUNUSED(row),