{
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();
State_Dragging // the item is being dragged
};
+ // common part of both ctors
+ void Init();
// various event handlers
void OnCaptureLost(wxMouseCaptureLostEvent& event);
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;
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.
*/
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.
// 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))