+// ----------------------------------------------------------------------------
+// mouse capture
+// ----------------------------------------------------------------------------
+
+struct WXDLLEXPORT wxWindowNext
+{
+ wxWindow *win;
+ wxWindowNext *next;
+} *wxWindowBase::ms_winCaptureNext = NULL;
+
+void wxWindowBase::CaptureMouse()
+{
+ wxLogTrace(_T("mousecapture"), _T("CaptureMouse(0x%08x)"), this);
+
+ wxWindow *winOld = GetCapture();
+ if ( winOld )
+ {
+ ((wxWindowBase*) winOld)->DoReleaseMouse();
+
+ // save it on stack
+ wxWindowNext *item = new wxWindowNext;
+ item->win = winOld;
+ item->next = ms_winCaptureNext;
+ ms_winCaptureNext = item;
+ }
+ //else: no mouse capture to save
+
+ DoCaptureMouse();
+}
+
+void wxWindowBase::ReleaseMouse()
+{
+ wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(0x%08x)"), this);
+
+ wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") )
+
+ DoReleaseMouse();
+
+ if ( ms_winCaptureNext )
+ {
+ ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
+
+ wxWindowNext *item = ms_winCaptureNext;
+ ms_winCaptureNext = item->next;
+ delete item;
+ }
+ //else: stack is empty, no previous capture
+
+ wxLogTrace(_T("mousecapture"),
+ _T("After ReleaseMouse() mouse is captured by 0x%08x"),
+ GetCapture());
+}
+
+// ----------------------------------------------------------------------------
+// global functions
+// ----------------------------------------------------------------------------
+
+wxWindow* wxGetTopLevelParent(wxWindow *win)
+{
+ while ( win && !win->IsTopLevel() )
+ win = win->GetParent();
+
+ return win;
+}
+