]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/wincmn.cpp
pc 2 mac conversion for file operations
[wxWidgets.git] / src / common / wincmn.cpp
index b701f7aa6df3fac1a58cb1eb450502c8209daa22..383c61e8fa112b6d18a7f86ae65e77a1db9c0680 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     13/07/98
 // RCS-ID:      $Id$
 // Copyright:   (c) wxWindows team
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
@@ -58,7 +58,7 @@
 #endif // wxUSE_DRAG_AND_DROP
 
 #if wxUSE_ACCESSIBILITY
-    #include "wx/access.h"    
+    #include "wx/access.h"
 #endif
 
 #if wxUSE_HELP
@@ -149,15 +149,13 @@ void wxWindowBase::InitBase()
     m_hasBgCol =
     m_hasFgCol =
     m_hasFont = FALSE;
+    
+    m_isBeingDeleted = FALSE;
 
     // no style bits
     m_exStyle =
     m_windowStyle = 0;
 
-    // an optimization for the event processing: checking this flag is much
-    // faster than using IsKindOf(CLASSINFO(wxWindow))
-    m_isWindow = TRUE;
-
 #if wxUSE_CONSTRAINTS
     // no constraints whatsoever
     m_constraints = (wxLayoutConstraints *) NULL;
@@ -208,11 +206,6 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent,
                               const wxValidator& validator,
                               const wxString& name)
 {
-    // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
-    // member variables - check that it has been called (will catch the case
-    // when a new ctor is added which doesn't call InitWindow)
-    wxASSERT_MSG( m_isWindow, wxT("Init() must have been called before!") );
-
 #if wxUSE_STATBOX
     // wxGTK doesn't allow to create controls with static box as the parent so
     // this will result in a crash when the program is ported to wxGTK so warn
@@ -224,8 +217,14 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent,
                   _T("wxStaticBox can't be used as a window parent!") );
 #endif // wxUSE_STATBOX
 
+    // ids are limited to 16 bits under MSW so if you care about portability,
+    // it's not a good idea to use ids out of this range (and negative ids are
+    // reserved for wxWindows own usage)
+    wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767),
+                  _T("invalid id value") );
+
     // generate a new id if the user doesn't care about it
-    m_windowId = id == -1 ? NewControlId() : id;
+    m_windowId = id == wxID_ANY ? NewControlId() : id;
 
     SetName(name);
     SetWindowStyleFlag(style);
@@ -615,6 +614,12 @@ void wxWindowBase::SetSizeHints(int minW, int minH,
                                 int maxW, int maxH,
                                 int WXUNUSED(incW), int WXUNUSED(incH))
 {
+    // setting min width greater than max width leads to infinite loops under
+    // X11 and generally doesn't make any sense, so don't allow it
+    wxCHECK_RET( (minW == -1 || maxW == -1 || minW <= maxW) &&
+                    (minH == -1 || maxH == -1 || minH <= maxH),
+                 _T("min width/height must be less than max width/height!") );
+
     m_minWidth = minW;
     m_maxWidth = maxW;
     m_minHeight = minH;
@@ -1953,7 +1958,7 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
 #if wxUSE_ACCESSIBILITY
 void wxWindowBase::SetAccessible(wxAccessible* accessible)
 {
-    if (m_accessible)
+    if (m_accessible && (accessible != m_accessible))
         delete m_accessible;
     m_accessible = accessible;
     if (m_accessible)
@@ -2078,6 +2083,61 @@ void wxWindowBase::ReleaseMouse()
                GetCapture());
 }
 
+
+void wxWindowBase::SendDestroyEvent()
+{
+    wxWindowDestroyEvent event;
+    event.SetEventObject(this);
+    event.SetId(GetId());
+    GetEventHandler()->ProcessEvent(event);
+}
+
+// ----------------------------------------------------------------------------
+// event processing
+// ----------------------------------------------------------------------------
+
+#if wxUSE_VALIDATORS
+
+bool wxWindowBase::TryValidator(wxEvent& event)
+{
+    // Can only use the validator of the window which
+    // is receiving the event
+    if ( event.GetEventObject() == this )
+    {
+        wxValidator *validator = GetValidator();
+        if ( validator && validator->ProcessEvent(event) )
+        {
+            return TRUE;
+        }
+    }
+
+    return FALSE;
+}
+
+#endif // wxUSE_VALIDATORS
+
+bool wxWindowBase::TryParent(wxEvent& event)
+{
+    // Carry on up the parent-child hierarchy, but only if event is a command
+    // event: it wouldn't make sense for a parent to receive a child's size
+    // event, for example
+    if ( event.IsCommandEvent() )
+    {
+        // honour the requests to stop propagation at this window: this is
+        // used by the dialogs, for example, to prevent processing the events
+        // from the dialog controls in the parent frame which rarely, if ever,
+        // makes sense
+        if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
+        {
+            wxWindow *parent = GetParent();
+            if ( parent && !parent->IsBeingDeleted() )
+                return parent->GetEventHandler()->ProcessEvent(event);
+        }
+    }
+
+    return wxEvtHandler::TryParent(event);
+}
+
 // ----------------------------------------------------------------------------
 // global functions
 // ----------------------------------------------------------------------------
@@ -2113,6 +2173,28 @@ wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId)
     if (!GetWindow())
         return wxACC_FAIL;
 
+    wxWindow* win = NULL;
+    if (elementId == 0)
+    {
+        win = GetWindow();
+    }
+    else
+    {
+        if (elementId <= (int) GetWindow()->GetChildren().GetCount())
+        {
+            win = (wxWindow*) GetWindow()->GetChildren().Nth(elementId-1)->GetData();
+        }
+        else
+            return wxACC_FAIL;
+    }
+    if (win)
+    {
+        rect = win->GetRect();
+        if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
+            rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
+        return wxACC_OK;
+    }
+
     return wxACC_NOT_IMPLEMENTED;
 }
 
@@ -2124,6 +2206,86 @@ wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId,
     if (!GetWindow())
         return wxACC_FAIL;
 
+    switch (navDir)
+    {
+    case wxNAVDIR_FIRSTCHILD:
+        {
+            if (GetWindow()->GetChildren().GetCount() == 0)
+                return wxACC_FALSE;
+            wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData();
+            *toObject = childWindow->GetOrCreateAccessible();
+
+            return wxACC_OK;
+        }
+    case wxNAVDIR_LASTCHILD:
+        {
+            if (GetWindow()->GetChildren().GetCount() == 0)
+                return wxACC_FALSE;
+            wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData();
+            *toObject = childWindow->GetOrCreateAccessible();
+
+            return wxACC_OK;
+        }
+    case wxNAVDIR_RIGHT:
+    case wxNAVDIR_DOWN:
+    case wxNAVDIR_NEXT:
+        {
+            wxWindowList::Node *node = NULL;
+            if (fromId == 0)
+            {
+                // Can't navigate to sibling of this window
+                // if we're a top-level window.
+                if (!GetWindow()->GetParent())
+                    return wxACC_NOT_IMPLEMENTED;
+
+                node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
+            }
+            else
+            {
+                if (fromId <= (int) GetWindow()->GetChildren().GetCount())
+                    node = (wxWindowList::Node*) GetWindow()->GetChildren().Nth(fromId-1);
+            }
+
+            if (node && node->GetNext())
+            {
+                wxWindow* nextWindow = (wxWindow*) node->GetNext()->Data();
+                *toObject = nextWindow->GetOrCreateAccessible();
+                return wxACC_OK;
+            }
+            else
+                return wxACC_FALSE;
+        }
+    case wxNAVDIR_LEFT:
+    case wxNAVDIR_UP:
+    case wxNAVDIR_PREVIOUS:
+        {
+            wxWindowList::Node *node = NULL;
+            if (fromId == 0)
+            {
+                // Can't navigate to sibling of this window
+                // if we're a top-level window.
+                if (!GetWindow()->GetParent())
+                    return wxACC_NOT_IMPLEMENTED;
+
+                node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
+            }
+            else
+            {
+                if (fromId <= (int) GetWindow()->GetChildren().GetCount())
+                    node = (wxWindowList::Node*) GetWindow()->GetChildren().Nth(fromId-1);
+            }
+
+            if (node && node->GetPrevious())
+            {
+                wxWindow* previousWindow = (wxWindow*) node->GetPrevious()->Data();
+                *toObject = previousWindow->GetOrCreateAccessible();
+                return wxACC_OK;
+            }
+            else
+                return wxACC_FALSE;
+        }
+    }
+
     return wxACC_NOT_IMPLEMENTED;
 }
 
@@ -2134,7 +2296,21 @@ wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name)
     if (!GetWindow())
         return wxACC_FAIL;
 
-    wxString title(GetWindow()->GetTitle());
+    wxString title;
+
+    // If a child, leave wxWindows to call the function on the actual
+    // child object.
+    if (childId > 0)
+        return wxACC_NOT_IMPLEMENTED;
+
+    // This will eventually be replaced by specialised
+    // accessible classes, one for each kind of wxWindows
+    // control or window.
+    if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
+        title = ((wxButton*) GetWindow())->GetLabel();
+    else
+        title = GetWindow()->GetName();
+    
     if (!title.IsEmpty())
     {
         *name = title;
@@ -2190,7 +2366,7 @@ wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent)
         return wxACC_FAIL;
 
     wxWindow* parentWindow = GetWindow()->GetParent();
-    if (!parent)
+    if (!parentWindow)
     {
         *parent = NULL;
         return wxACC_OK;
@@ -2240,6 +2416,12 @@ wxAccStatus wxWindowAccessible::GetDescription(int childId, wxString* descriptio
     if (!GetWindow())
         return wxACC_FAIL;
 
+    wxString ht(GetWindow()->GetHelpText());
+    if (!ht.IsEmpty())
+    {
+        *description = ht;
+        return wxACC_OK;
+    }
     return wxACC_NOT_IMPLEMENTED;
 }
 
@@ -2277,6 +2459,26 @@ wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role)
     if (!GetWindow())
         return wxACC_FAIL;
 
+    // If a child, leave wxWindows to call the function on the actual
+    // child object.
+    if (childId > 0)
+        return wxACC_NOT_IMPLEMENTED;
+
+    if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
+        return wxACC_NOT_IMPLEMENTED;
+#if wxUSE_STATUSBAR
+    if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
+        return wxACC_NOT_IMPLEMENTED;
+#endif
+#if wxUSE_TOOLBAR
+    if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
+        return wxACC_NOT_IMPLEMENTED;
+#endif
+
+    //*role = wxROLE_SYSTEM_CLIENT;
+    *role = wxROLE_SYSTEM_CLIENT;
+    return wxACC_OK;
+
     return wxACC_NOT_IMPLEMENTED;
 }
 
@@ -2287,6 +2489,26 @@ wxAccStatus wxWindowAccessible::GetState(int childId, long* state)
     if (!GetWindow())
         return wxACC_FAIL;
 
+    // If a child, leave wxWindows to call the function on the actual
+    // child object.
+    if (childId > 0)
+        return wxACC_NOT_IMPLEMENTED;
+
+    if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
+        return wxACC_NOT_IMPLEMENTED;
+
+#if wxUSE_STATUSBAR
+    if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
+        return wxACC_NOT_IMPLEMENTED;
+#endif
+#if wxUSE_TOOLBAR
+    if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
+        return wxACC_NOT_IMPLEMENTED;
+#endif
+
+    *state = 0;
+    return wxACC_OK;
+
     return wxACC_NOT_IMPLEMENTED;
 }