]> git.saurik.com Git - wxWidgets.git/commitdiff
added default ctor to wxMouseEventsManager, this is convenient when deriving window...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 31 May 2009 14:43:01 +0000 (14:43 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 31 May 2009 14:43:01 +0000 (14:43 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60839 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/mousemanager.h
interface/wx/mousemanager.h
src/common/mousemanager.cpp

index 75c8920df9d8b64cf357bca220832e3b21c01e0d..408209301bfc94f05f12acc4d19ecdc0ce4756bb 100644 (file)
@@ -34,8 +34,11 @@ class WXDLLIMPEXP_CORE wxMouseEventsManager : public wxEvtHandler
 {
 public:
     // a mouse event manager is always associated with a window and must be
-    // deleted by the window when it is destroyed
-    wxMouseEventsManager(wxWindow *win);
+    // deleted by the window when it is destroyed so if it is created using the
+    // default ctor Create() must be called later
+    wxMouseEventsManager() { Init(); }
+    wxMouseEventsManager(wxWindow *win) { Init(); Create(win); }
+    bool Create(wxWindow *win);
 
     virtual ~wxMouseEventsManager();
 
@@ -113,6 +116,8 @@ private:
         State_Dragging  // the item is being dragged
     };
 
+    // common part of both ctors
+    void Init();
 
     // various event handlers
     void OnCaptureLost(wxMouseCaptureLostEvent& event);
@@ -121,8 +126,9 @@ private:
     void OnMove(wxMouseEvent& event);
 
 
-    // the associated window, never NULL
-    wxWindow * const m_win;
+    // the associated window, never NULL except between the calls to the
+    // default ctor and Create()
+    wxWindow *m_win;
 
     // the current state
     State m_state;
index 2c8b05a1ae6ac256f0b737353aaf8e17927a573b..154f39064367a742b9ac4f15e4c7a61bf837cc7d 100644 (file)
 class wxMouseEventsManager : public wxEvtHandler
 {
 public:
+    /**
+        Default constructor.
+
+        You must call Create() to finish initializing the mouse events manager.
+        If possible, avoid the use of this constructor in favour of the other
+        one which fully initializes the mouse events manager immediately.
+     */
+    wxMouseEventsManager();
+
     /**
         Constructor creates the manager for the window.
 
@@ -46,6 +55,14 @@ public:
      */
     wxMouseEventsManager(wxWindow *win);
 
+    /**
+        Finishes initialization of the object created using default
+        constructor.
+
+        Currently always returns @true.
+     */
+    bool Create(wxWindow *win);
+
 protected:
     /**
         Must be overridden to return the item at the given position.
index b05922e3f77bef3e30da94cf2bad4d0a539efb17..0e9475f580ab86683082797be5be2fe906abc8a5 100644 (file)
@@ -45,18 +45,27 @@ END_EVENT_TABLE()
 // wxMouseEventsManager implementation
 // ============================================================================
 
-wxMouseEventsManager::wxMouseEventsManager(wxWindow *win)
-    : m_win(win)
+void wxMouseEventsManager::Init()
 {
+    m_win = NULL;
     m_state = State_Normal;
     m_item = wxNOT_FOUND;
+}
+
+bool wxMouseEventsManager::Create(wxWindow *win)
+{
+    wxASSERT_MSG( !m_win, "Create() must not be called twice" );
 
+    m_win = win;
     win->PushEventHandler(this);
+
+    return true;
 }
 
 wxMouseEventsManager::~wxMouseEventsManager()
 {
-    m_win->RemoveEventHandler(this);
+    if ( m_win )
+        m_win->RemoveEventHandler(this);
 }
 
 void wxMouseEventsManager::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))