]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/wincmn.cpp
Corrected Normalize invocation by casting
[wxWidgets.git] / src / common / wincmn.cpp
index f71daad3b5433762a9c07c10b78491021ecc47be..89f902063e3d8f6644a11524558fc020ac40f690 100644 (file)
@@ -115,10 +115,6 @@ void wxWindowBase::InitBase()
     m_isShown = FALSE;
     m_isEnabled = TRUE;
 
     m_isShown = FALSE;
     m_isEnabled = TRUE;
 
-    // no client data (yet)
-    m_clientData = NULL;
-    m_clientDataType = wxClientData_None;
-
     // the default event handler is just this window
     m_eventHandler = this;
 
     // the default event handler is just this window
     m_eventHandler = this;
 
@@ -128,16 +124,21 @@ void wxWindowBase::InitBase()
 #endif // wxUSE_VALIDATORS
 
     // use the system default colours
 #endif // wxUSE_VALIDATORS
 
     // use the system default colours
-    m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE);
-    m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT);
+    m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
+    m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
 
     // don't set the font here for wxMSW as we don't call WM_SETFONT here and
     // so the font is *not* really set - but calls to SetFont() later won't do
     // anything because m_font appears to be already set!
 #ifndef __WXMSW__
 
     // don't set the font here for wxMSW as we don't call WM_SETFONT here and
     // so the font is *not* really set - but calls to SetFont() later won't do
     // anything because m_font appears to be already set!
 #ifndef __WXMSW__
-    m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
+    m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
 #endif // __WXMSW__
 
 #endif // __WXMSW__
 
+    // the colours/fonts are default for now
+    m_hasBgCol =
+    m_hasFgCol =
+    m_hasFont = FALSE;
+
     // no style bits
     m_exStyle =
     m_windowStyle = 0;
     // no style bits
     m_exStyle =
     m_windowStyle = 0;
@@ -213,6 +214,8 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent,
 // common clean up
 wxWindowBase::~wxWindowBase()
 {
 // common clean up
 wxWindowBase::~wxWindowBase()
 {
+    wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
+
     // FIXME if these 2 cases result from programming errors in the user code
     //       we should probably assert here instead of silently fixing them
 
     // FIXME if these 2 cases result from programming errors in the user code
     //       we should probably assert here instead of silently fixing them
 
@@ -236,10 +239,6 @@ wxWindowBase::~wxWindowBase()
         delete m_windowValidator;
 #endif // wxUSE_VALIDATORS
 
         delete m_windowValidator;
 #endif // wxUSE_VALIDATORS
 
-    // we only delete object data, not untyped
-    if ( m_clientDataType == wxClientData_Object )
-        delete m_clientObject;
-
 #if wxUSE_CONSTRAINTS
     // Have to delete constraints/sizer FIRST otherwise sizers may try to look
     // at deleted windows as they delete themselves.
 #if wxUSE_CONSTRAINTS
     // Have to delete constraints/sizer FIRST otherwise sizers may try to look
     // at deleted windows as they delete themselves.
@@ -634,6 +633,41 @@ wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
     return handlerA;
 }
 
     return handlerA;
 }
 
+bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler)
+{
+    wxCHECK_MSG( handler, FALSE, _T("RemoveEventHandler(NULL) called") );
+
+    wxEvtHandler *handlerPrev = NULL,
+                 *handlerCur = GetEventHandler();
+    while ( handlerCur )
+    {
+        wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
+
+        if ( handlerCur == handler )
+        {
+            if ( handlerPrev )
+            {
+                handlerPrev->SetNextHandler(handlerNext);
+            }
+            else
+            {
+                SetEventHandler(handlerNext);
+            }
+
+            handler->SetNextHandler(NULL);
+
+            return TRUE;
+        }
+
+        handlerPrev = handlerCur;
+        handlerCur = handlerNext;
+    }
+
+    wxFAIL_MSG( _T("where has the event handler gone?") );
+
+    return FALSE;
+}
+
 // ----------------------------------------------------------------------------
 // cursors, fonts &c
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // cursors, fonts &c
 // ----------------------------------------------------------------------------
@@ -645,6 +679,8 @@ bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
 
     m_backgroundColour = colour;
 
 
     m_backgroundColour = colour;
 
+    m_hasBgCol = TRUE;
+
     return TRUE;
 }
 
     return TRUE;
 }
 
@@ -655,6 +691,8 @@ bool wxWindowBase::SetForegroundColour( const wxColour &colour )
 
     m_foregroundColour = colour;
 
 
     m_foregroundColour = colour;
 
+    m_hasFgCol = TRUE;
+
     return TRUE;
 }
 
     return TRUE;
 }
 
@@ -686,6 +724,8 @@ bool wxWindowBase::SetFont(const wxFont& font)
 
     m_font = fontOk;
 
 
     m_font = fontOk;
 
+    m_hasFont = TRUE;
+
     return TRUE;
 }
 
     return TRUE;
 }
 
@@ -1277,7 +1317,7 @@ void wxWindowBase::SetConstraintSizes(bool recurse)
         while (node)
         {
             wxWindow *win = node->GetData();
         while (node)
         {
             wxWindow *win = node->GetData();
-            if ( !win->IsTopLevel() )
+            if ( !win->IsTopLevel() && win->GetConstraints() )
                 win->SetConstraintSizes();
             node = node->GetNext();
         }
                 win->SetConstraintSizes();
             node = node->GetNext();
         }
@@ -1355,6 +1395,23 @@ void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
         GetClientSize(w, h);
 }
 
         GetClientSize(w, h);
 }
 
+void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
+{
+    // don't do it for the dialogs/frames - they float independently of their
+    // parent
+    if ( !IsTopLevel() )
+    {
+        wxWindow *parent = GetParent();
+        if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
+        {
+            wxPoint pt(parent->GetClientAreaOrigin());
+            x += pt.x;
+            y += pt.y;
+        }
+    }
+}
+
+
 void wxWindowBase::GetPositionConstraint(int *x, int *y) const
 {
     wxLayoutConstraints *constr = GetConstraints();
 void wxWindowBase::GetPositionConstraint(int *x, int *y) const
 {
     wxLayoutConstraints *constr = GetConstraints();
@@ -1454,51 +1511,6 @@ wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
     return pt2;
 }
 
     return pt2;
 }
 
-// ----------------------------------------------------------------------------
-// client data
-// ----------------------------------------------------------------------------
-
-void wxWindowBase::DoSetClientObject( wxClientData *data )
-{
-    wxASSERT_MSG( m_clientDataType != wxClientData_Void,
-                  wxT("can't have both object and void client data") );
-
-    if ( m_clientObject )
-        delete m_clientObject;
-
-    m_clientObject = data;
-    m_clientDataType = wxClientData_Object;
-}
-
-wxClientData *wxWindowBase::DoGetClientObject() const
-{
-    // it's not an error to call GetClientObject() on a window which doesn't
-    // have client data at all - NULL will be returned
-    wxASSERT_MSG( m_clientDataType != wxClientData_Void,
-                  wxT("this window doesn't have object client data") );
-
-    return m_clientObject;
-}
-
-void wxWindowBase::DoSetClientData( void *data )
-{
-    wxASSERT_MSG( m_clientDataType != wxClientData_Object,
-                  wxT("can't have both object and void client data") );
-
-    m_clientData = data;
-    m_clientDataType = wxClientData_Void;
-}
-
-void *wxWindowBase::DoGetClientData() const
-{
-    // it's not an error to call GetClientData() on a window which doesn't have
-    // client data at all - NULL will be returned
-    wxASSERT_MSG( m_clientDataType != wxClientData_Object,
-                  wxT("this window doesn't have void client data") );
-
-    return m_clientData;
-}
-
 // ----------------------------------------------------------------------------
 // event handlers
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // event handlers
 // ----------------------------------------------------------------------------
@@ -1536,10 +1548,16 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
     {
         // don't translate these strings
         wxString port;
     {
         // don't translate these strings
         wxString port;
+
+#ifdef __WXUNIVERSAL__
+        port = _T("Univ/");
+#endif // __WXUNIVERSAL__
+
         switch ( wxGetOsVersion() )
         {
             case wxMOTIF_X:     port = _T("Motif"); break;
         switch ( wxGetOsVersion() )
         {
             case wxMOTIF_X:     port = _T("Motif"); break;
-            case wxMACINTOSH:   port = _T("Mac"); break;
+            case wxMAC:
+            case wxMAC_DARWIN:  port = _T("Mac"); break;
             case wxBEOS:        port = _T("BeOS"); break;
             case wxGTK:
             case wxGTK_WIN32:
             case wxBEOS:        port = _T("BeOS"); break;
             case wxGTK:
             case wxGTK_WIN32:
@@ -1562,14 +1580,19 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
 
         wxMessageBox(wxString::Format(
                                       _T(
 
         wxMessageBox(wxString::Format(
                                       _T(
-                                        "       wxWindows Library (%s port)\nVersion %u.%u.%u, compiled at %s %s\n   Copyright (c) 1995-2000 wxWindows team"
+                                        "       wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n   Copyright (c) 1995-2002 wxWindows team"
                                         ),
                                       port.c_str(),
                                       wxMAJOR_VERSION,
                                       wxMINOR_VERSION,
                                       wxRELEASE_NUMBER,
                                         ),
                                       port.c_str(),
                                       wxMAJOR_VERSION,
                                       wxMINOR_VERSION,
                                       wxRELEASE_NUMBER,
-                                      __DATE__,
-                                      __TIME__
+#if wxUSE_UNICODE
+                                      L" (Unicode)",
+#else
+                                      "",
+#endif
+                                      __TDATE__,
+                                      __TTIME__
                                      ),
                      _T("wxWindows information"),
                      wxICON_INFORMATION | wxOK,
                                      ),
                      _T("wxWindows information"),
                      wxICON_INFORMATION | wxOK,
@@ -1631,3 +1654,54 @@ wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
     return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
 }
 
     return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
 }
 
+// ----------------------------------------------------------------------------
+// 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 )
+    {
+        // 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 )
+    {
+        ms_winCaptureNext->win->CaptureMouse();
+
+        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());
+}
+