]> git.saurik.com Git - wxWidgets.git/commitdiff
Use wxDatePickerCtrl in wxDataViewDateRenderer.
authorVáclav Slavík <vslavik@fastmail.fm>
Wed, 19 Oct 2011 16:20:06 +0000 (16:20 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Wed, 19 Oct 2011 16:20:06 +0000 (16:20 +0000)
Inline editor is more in line with the behavior of other editors,
requiring double click to edit values was unexpected.

Also merge the two almost-but-not-quite identical implementations in
generic and GTK+ versions.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69471 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dvrenderers.h
include/wx/generic/dvrenderers.h
include/wx/gtk/dvrenderers.h
src/common/datavcmn.cpp
src/generic/datavgen.cpp
src/gtk/dataview.cpp

index 1d77b0911453f7edc441321c0d07255e52dfdb69..a73d67337876703f630d6d06f731e6ea6d28e6ce 100644 (file)
@@ -386,6 +386,37 @@ public:
 
 #endif // generic or Carbon versions
 
+#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)
+
+// ----------------------------------------------------------------------------
+// wxDataViewDateRenderer
+// ----------------------------------------------------------------------------
+
+#if wxUSE_DATEPICKCTRL
+class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
+{
+public:
+    wxDataViewDateRenderer(const wxString &varianttype = wxT("datetime"),
+                           wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
+                           int align = wxDVR_DEFAULT_ALIGNMENT);
+
+    virtual bool HasEditorCtrl() const { return true; }
+    virtual wxWindow *CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant &value);
+    virtual bool GetValueFromEditorCtrl(wxWindow* editor, wxVariant &value);
+    virtual bool SetValue(const wxVariant &value);
+    virtual bool GetValue(wxVariant& value) const;
+    virtual bool Render( wxRect cell, wxDC *dc, int state );
+    virtual wxSize GetSize() const;
+
+private:
+    wxDateTime    m_date;
+};
+#else // !wxUSE_DATEPICKCTRL
+typedef wxDataViewTextRenderer wxDataViewDateRenderer;
+#endif
+
+#endif // generic or GTK+ versions
+
 // this class is obsolete, its functionality was merged in
 // wxDataViewTextRenderer itself now, don't use it any more
 #define wxDataViewTextRendererAttr wxDataViewTextRenderer
index 513189496050cbb58100173e4da6854a141007c8..8064d0939b0e505973aa681bbd9b4d751f7d2181 100644 (file)
@@ -193,36 +193,5 @@ protected:
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
 };
 
-// ---------------------------------------------------------
-// wxDataViewDateRenderer
-// ---------------------------------------------------------
-
-class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
-{
-public:
-    wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
-                            wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
-                            int align = wxDVR_DEFAULT_ALIGNMENT );
-
-    bool SetValue( const wxVariant &value );
-    bool GetValue( wxVariant& value ) const;
-
-    virtual bool Render( wxRect cell, wxDC *dc, int state );
-    virtual wxSize GetSize() const;
-
-    // Implementation only, don't use nor override
-    virtual bool WXOnActivate(const wxRect& cell,
-                              wxDataViewModel *model,
-                              const wxDataViewItem& item,
-                              unsigned int col);
-
-private:
-    wxDateTime    m_date;
-
-protected:
-    DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
-};
-
-
 #endif // _WX_GENERIC_DVRENDERERS_H_
 
index f833f8edd341247ee679efd1c7c300d9363a84e7..785d7f9a2b77004ef40c4ffdf2ffcd79c680d891 100644 (file)
@@ -235,34 +235,6 @@ private:
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
 };
 
-// ---------------------------------------------------------
-// wxDataViewDateRenderer
-// ---------------------------------------------------------
-
-class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
-{
-public:
-    wxDataViewDateRenderer( const wxString &varianttype = "datetime",
-                            wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
-                            int align = wxDVR_DEFAULT_ALIGNMENT );
-
-    bool SetValue( const wxVariant &value );
-    bool GetValue( wxVariant &value ) const;
-
-    virtual bool Render( wxRect cell, wxDC *dc, int state );
-    virtual wxSize GetSize() const;
-    virtual bool Activate( const wxRect& cell,
-                           wxDataViewModel *model,
-                           const wxDataViewItem &item,
-                           unsigned int col );
-
-private:
-    wxDateTime    m_date;
-
-protected:
-    DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
-};
-
 // -------------------------------------
 // wxDataViewChoiceRenderer
 // -------------------------------------
index b7ee97b28e21a64cc21db08f56081e2f6342c863..858aa98a9aca4e4b7112a2dd517e30599f2c75db 100644 (file)
@@ -26,6 +26,7 @@
     #include "wx/crt.h"
 #endif
 
+#include "wx/datectrl.h"
 #include "wx/spinctrl.h"
 #include "wx/choice.h"
 #include "wx/imaglist.h"
@@ -1609,6 +1610,64 @@ bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant &value ) const
 
 #endif
 
+// ---------------------------------------------------------
+// wxDataViewDateRenderer
+// ---------------------------------------------------------
+
+#if (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
+
+wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString& varianttype,
+                                              wxDataViewCellMode mode, int align)
+    : wxDataViewCustomRenderer(varianttype, mode, align)
+{
+}
+
+wxWindow *
+wxDataViewDateRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value)
+{
+    return new wxDatePickerCtrl
+               (
+                   parent,
+                   wxID_ANY,
+                   value.GetDateTime(),
+                   labelRect.GetTopLeft(),
+                   labelRect.GetSize()
+               );
+}
+
+bool wxDataViewDateRenderer::GetValueFromEditorCtrl(wxWindow *editor, wxVariant& value)
+{
+    wxDatePickerCtrl *ctrl = static_cast<wxDatePickerCtrl*>(editor);
+    value = ctrl->GetValue();
+    return true;
+}
+
+bool wxDataViewDateRenderer::SetValue(const wxVariant& value)
+{
+    m_date = value.GetDateTime();
+    return true;
+}
+
+bool wxDataViewDateRenderer::GetValue(wxVariant& value) const
+{
+    value = m_date;
+    return true;
+}
+
+bool wxDataViewDateRenderer::Render(wxRect cell, wxDC* dc, int state)
+{
+    wxString tmp = m_date.FormatDate();
+    RenderText( tmp, 0, cell, dc, state );
+    return true;
+}
+
+wxSize wxDataViewDateRenderer::GetSize() const
+{
+    return GetTextExtent(m_date.FormatDate());
+}
+
+#endif // (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
+
 //-----------------------------------------------------------------------------
 // wxDataViewListStore
 //-----------------------------------------------------------------------------
index 1de15c7da8a20714bf4dfab7c79283ead1223188..02d0a95344b77ca87efd6c3e6a0142622a7903df 100644 (file)
@@ -38,7 +38,6 @@
 #endif
 
 #include "wx/stockitem.h"
-#include "wx/calctrl.h"
 #include "wx/popupwin.h"
 #include "wx/renderer.h"
 #include "wx/dcbuffer.h"
@@ -1077,113 +1076,6 @@ wxSize wxDataViewProgressRenderer::GetSize() const
     return wxSize(40,12);
 }
 
-// ---------------------------------------------------------
-// wxDataViewDateRenderer
-// ---------------------------------------------------------
-
-#define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
-
-#if wxUSE_DATE_RENDERER_POPUP
-
-class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow
-{
-public:
-    wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value,
-        wxDataViewModel *model, const wxDataViewItem & item, unsigned int col) :
-        wxPopupTransientWindow( parent, wxBORDER_SIMPLE ),
-        m_item( item )
-    {
-        m_model = model;
-        m_col = col;
-        m_cal = new wxCalendarCtrl( this, wxID_ANY, *value );
-        wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
-        sizer->Add( m_cal, 1, wxGROW );
-        SetSizer( sizer );
-        sizer->Fit( this );
-    }
-
-    void OnCalendar( wxCalendarEvent &event );
-
-    wxCalendarCtrl      *m_cal;
-    wxDataViewModel *m_model;
-    unsigned int               m_col;
-    const wxDataViewItem &   m_item;
-
-protected:
-    virtual void OnDismiss()
-    {
-    }
-
-private:
-    DECLARE_EVENT_TABLE()
-};
-
-BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow)
-    EVT_CALENDAR( wxID_ANY, wxDataViewDateRendererPopupTransient::OnCalendar )
-END_EVENT_TABLE()
-
-void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event )
-{
-    m_model->ChangeValue( event.GetDate(), m_item, m_col );
-    DismissAndNotify();
-}
-
-#endif // wxUSE_DATE_RENDERER_POPUP
-
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer, wxDataViewRenderer)
-
-wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype,
-                        wxDataViewCellMode mode, int align ) :
-    wxDataViewRenderer( varianttype, mode, align )
-{
-}
-
-bool wxDataViewDateRenderer::SetValue( const wxVariant &value )
-{
-    m_date = value.GetDateTime();
-
-    return true;
-}
-
-bool wxDataViewDateRenderer::GetValue( wxVariant &value ) const
-{
-    value = m_date;
-    return true;
-}
-
-bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state )
-{
-    wxString tmp = m_date.FormatDate();
-    RenderText( tmp, 0, cell, dc, state );
-    return true;
-}
-
-wxSize wxDataViewDateRenderer::GetSize() const
-{
-    return GetTextExtent(m_date.FormatDate());
-}
-
-bool wxDataViewDateRenderer::WXOnActivate(const wxRect& WXUNUSED(cell),
-                                          wxDataViewModel *model,
-                                          const wxDataViewItem& item,
-                                          unsigned int col)
-{
-    wxDateTime dtOld = m_date;
-
-#if wxUSE_DATE_RENDERER_POPUP
-    wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
-        GetOwner()->GetOwner()->GetParent(), &dtOld, model, item, col);
-    wxPoint pos = wxGetMousePosition();
-    popup->Move( pos );
-    popup->Layout();
-    popup->Popup( popup->m_cal );
-#else // !wxUSE_DATE_RENDERER_POPUP
-    wxMessageBox(dtOld.Format());
-#endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
-
-    return true;
-}
-
 // ---------------------------------------------------------
 // wxDataViewIconTextRenderer
 // ---------------------------------------------------------
index 12fc302973e74773fedf436faa147a03b58e6504..e8025a76a8a96454c9e6706b7e32a0812bba67df 100644 (file)
@@ -25,7 +25,6 @@
 #endif
 
 #include "wx/stockitem.h"
-#include "wx/calctrl.h"
 #include "wx/popupwin.h"
 #include "wx/listimpl.cpp"
 
@@ -2797,108 +2796,6 @@ bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant &value ) const
     return true;
 }
 
-// ---------------------------------------------------------
-// wxDataViewDateRenderer
-// ---------------------------------------------------------
-
-class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow
-{
-public:
-    wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value,
-        wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) :
-        wxPopupTransientWindow( parent, wxBORDER_SIMPLE )
-    {
-        m_model = model;
-        m_item = item;
-        m_col = col;
-        m_cal = new wxCalendarCtrl( this, -1, *value );
-        wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
-        sizer->Add( m_cal, 1, wxGROW );
-        SetSizer( sizer );
-        sizer->Fit( this );
-    }
-
-    virtual void OnDismiss()
-    {
-    }
-
-    void OnCalendar( wxCalendarEvent &event );
-
-    wxCalendarCtrl   *m_cal;
-    wxDataViewModel  *m_model;
-    wxDataViewItem    m_item;
-    unsigned int      m_col;
-
-private:
-    DECLARE_EVENT_TABLE()
-};
-
-BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow)
-    EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar )
-END_EVENT_TABLE()
-
-void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event )
-{
-    m_model->ChangeValue( event.GetDate(), m_item, m_col );
-    DismissAndNotify();
-}
-
-IMPLEMENT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer)
-
-wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype,
-                        wxDataViewCellMode mode, int align ) :
-    wxDataViewCustomRenderer( varianttype, mode, align )
-{
-    SetMode(mode);
-    SetAlignment(align);
-}
-
-bool wxDataViewDateRenderer::SetValue( const wxVariant &value )
-{
-    m_date = value.GetDateTime();
-
-    return true;
-}
-
-bool wxDataViewDateRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
-{
-    return false;
-}
-
-bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state )
-{
-    dc->SetFont( GetOwner()->GetOwner()->GetFont() );
-    wxString tmp = m_date.FormatDate();
-    RenderText( tmp, 0, cell, dc, state );
-    return true;
-}
-
-wxSize wxDataViewDateRenderer::GetSize() const
-{
-    wxString tmp = m_date.FormatDate();
-    wxCoord x,y,d;
-    GetView()->GetTextExtent( tmp, &x, &y, &d );
-    return wxSize(x,y+d);
-}
-
-bool wxDataViewDateRenderer::Activate( const wxRect& WXUNUSED(cell), wxDataViewModel *model,
-                                       const wxDataViewItem &item, unsigned int col )
-{
-    wxVariant variant;
-    model->GetValue( variant, item, col );
-    wxDateTime value = variant.GetDateTime();
-
-    wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
-        GetOwner()->GetOwner()->GetParent(), &value, model, item, col );
-    wxPoint pos = wxGetMousePosition();
-    popup->Move( pos );
-    popup->Layout();
-    popup->Popup( popup->m_cal );
-
-    return true;
-}
-
-
 // ---------------------------------------------------------
 // wxDataViewIconTextRenderer
 // ---------------------------------------------------------