]> git.saurik.com Git - wxWidgets.git/commitdiff
generate double click events in the native MSW version of wxCalendarCtrl
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 4 Apr 2008 15:49:08 +0000 (15:49 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 4 Apr 2008 15:49:08 +0000 (15:49 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53008 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/calctrl.h
include/wx/msw/calctrl.h
src/msw/calctrl.cpp

index ae92b232c160de54795714591c1d471521774232..4c51a9419fe1ce3fa2d8798eef5cb6e4b248531c 100644 (file)
@@ -298,11 +298,11 @@ public:
     // implementation only from now on
 
 protected:
-    // generate the given calendar event(s)
-    void GenerateEvent(wxEventType type)
+    // generate the given calendar event, return true if it was processed
+    bool GenerateEvent(wxEventType type)
     {
         wxCalendarEvent event(this, GetDate(), type);
-        HandleWindowEvent(event);
+        return HandleWindowEvent(event);
     }
 
     // generate all the events for the selection change from dateOld to current
index 9a2da34dd2bf84a4b2335663891bd06ba209b6c4..3f527182f1c70efb661c2703d1b1f7c73a88bd02 100644 (file)
@@ -55,6 +55,8 @@ protected:
 
     virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
 
+    void MSWOnDoubleClick(wxMouseEvent& event);
+
 private:
     wxDateTime m_date;
 
index 8432ccc6bd8fe49aeecdd0f6260e6b9a5c57adee..53e802a82765744a6a76ce43422d6b0f850c70e2 100644 (file)
@@ -60,12 +60,38 @@ wxCalendarCtrl::Create(wxWindow *parent,
     if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
         return false;
 
-    // create the native control
-    if ( !MSWCreateControl(MONTHCAL_CLASS, wxEmptyString, pos, size) )
+    // create the native control: this is a bit tricky as we want to receive
+    // double click events but the MONTHCAL_CLASS doesn't use CS_DBLCLKS style
+    // and so we create our own copy of it which does
+    static ClassRegistrar s_clsMonthCal;
+    if ( !s_clsMonthCal.IsInitialized() )
+    {
+        // get a copy of standard class and modify it
+        WNDCLASS wc;
+        if ( ::GetClassInfo(NULL, MONTHCAL_CLASS, &wc) )
+        {
+            wc.lpszClassName = wxT("_wx_SysMonthCtl32");
+            wc.style |= CS_DBLCLKS;
+            s_clsMonthCal.Register(wc);
+        }
+        else
+        {
+            wxLogLastError(_T("GetClassInfoEx(SysMonthCal32)"));
+        }
+    }
+
+    const wxChar * const clsname = s_clsMonthCal.IsRegistered()
+        ? s_clsMonthCal.GetName().wx_str()
+        : MONTHCAL_CLASS;
+
+    if ( !MSWCreateControl(clsname, wxEmptyString, pos, size) )
         return false;
 
     SetDate(dt.IsValid() ? dt : wxDateTime::Today());
 
+    Connect(wxEVT_LEFT_DOWN,
+            wxMouseEventHandler(wxCalendarCtrl::MSWOnDoubleClick));
+
     return true;
 }
 
@@ -300,4 +326,15 @@ bool wxCalendarCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
     return wxCalendarCtrlBase::MSWOnNotify(idCtrl, lParam, result);
 }
 
+void wxCalendarCtrl::MSWOnDoubleClick(wxMouseEvent& event)
+{
+    if ( HitTest(event.GetPosition()) == wxCAL_HITTEST_DAY )
+    {
+        if ( GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED) )
+            return; // skip event.Skip() below
+    }
+
+    event.Skip();
+}
+
 #endif // wxUSE_CALENDARCTRL