]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/infobar.cpp
Fix completely wrong logic for veto checking in generic wxDVC.
[wxWidgets.git] / src / generic / infobar.cpp
index f0af9c9b8b20d9cbd89e6c39b50f5d78a689ec3b..76001a4a17e9df3035c16c1a588e55ff348f2f00 100644 (file)
@@ -3,7 +3,7 @@
 // Purpose:     generic wxInfoBar implementation
 // Author:      Vadim Zeitlin
 // Created:     2009-07-28
-// RCS-ID:      $Id: wxhead.cpp,v 1.10 2009-06-29 10:23:04 zeitlin Exp $
+// RCS-ID:      $Id$
 // Copyright:   (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 #if wxUSE_INFOBAR
 
+#include "wx/infobar.h"
+
 #ifndef WX_PRECOMP
     #include "wx/bmpbuttn.h"
     #include "wx/button.h"
+    #include "wx/dcmemory.h"
     #include "wx/settings.h"
     #include "wx/statbmp.h"
     #include "wx/stattext.h"
+    #include "wx/sizer.h"
 #endif // WX_PRECOMP
 
-#include "wx/infobar.h"
-
 #include "wx/artprov.h"
 #include "wx/renderer.h"
 #include "wx/scopeguard.h"
-#include "wx/sizer.h"
 
 BEGIN_EVENT_TABLE(wxInfoBarGeneric, wxInfoBarBase)
     EVT_BUTTON(wxID_ANY, wxInfoBarGeneric::OnButton)
@@ -82,8 +83,8 @@ void wxInfoBarGeneric::Init()
     m_text = NULL;
     m_button = NULL;
 
-    m_showEffect = wxSHOW_EFFECT_SLIDE_TO_BOTTOM;
-    m_hideEffect = wxSHOW_EFFECT_SLIDE_TO_TOP;
+    m_showEffect =
+    m_hideEffect = wxSHOW_EFFECT_MAX;
 
     // use default effect duration
     m_effectDuration = 0;
@@ -164,61 +165,78 @@ bool wxInfoBarGeneric::SetFont(const wxFont& font)
     return true;
 }
 
-void wxInfoBarGeneric::UpdateParent()
+wxInfoBarGeneric::BarPlacement wxInfoBarGeneric::GetBarPlacement() const
 {
-    wxWindow * const parent = wxGetTopLevelParent(GetParent());
-    parent->Layout();
+    wxSizer * const sizer = GetContainingSizer();
+    if ( !sizer )
+        return BarPlacement_Unknown;
+
+    // FIXME-VC6: can't compare "const wxInfoBarGeneric *" and "wxWindow *",
+    //            so need this workaround
+    wxWindow * const self = const_cast<wxInfoBarGeneric *>(this);
+    const wxSizerItemList& siblings = sizer->GetChildren();
+    if ( siblings.GetFirst()->GetData()->GetWindow() == self )
+        return BarPlacement_Top;
+    else if ( siblings.GetLast()->GetData()->GetWindow() == self )
+        return BarPlacement_Bottom;
+    else
+        return BarPlacement_Unknown;
 }
 
-void wxInfoBarGeneric::ChangeParentBackground()
+wxShowEffect wxInfoBarGeneric::GetShowEffect() const
 {
-    wxWindow * const parent = GetParent();
-    m_origParentBgCol = parent->GetBackgroundColour();
-
-    wxSizer * const sizer = GetContainingSizer();
-    if ( !sizer )
-        return;
+    if ( m_showEffect != wxSHOW_EFFECT_MAX )
+        return m_showEffect;
 
-    wxWindow *sibling = NULL;
-    for ( wxSizerItemList::compatibility_iterator
-            node = sizer->GetChildren().GetFirst();
-            node;
-            node = node->GetNext() )
+    switch ( GetBarPlacement() )
     {
-        if ( node->GetData()->GetWindow() == this )
-        {
-            // find the next window following us
-            for ( node = node->GetNext();
-                  node;
-                  node = node->GetNext() )
-            {
-                wxSizerItem * const item = node->GetData();
-                if ( item->IsWindow() )
-                {
-                    sibling = item->GetWindow();
-                    break;
-                }
-            }
+        case BarPlacement_Top:
+            return wxSHOW_EFFECT_SLIDE_TO_BOTTOM;
 
-            break;
-        }
+        case BarPlacement_Bottom:
+            return wxSHOW_EFFECT_SLIDE_TO_TOP;
+
+        default:
+            wxFAIL_MSG( "unknown info bar placement" );
+            // fall through
+
+        case BarPlacement_Unknown:
+            return wxSHOW_EFFECT_NONE;
     }
+}
+
+wxShowEffect wxInfoBarGeneric::GetHideEffect() const
+{
+    if ( m_hideEffect != wxSHOW_EFFECT_MAX )
+        return m_hideEffect;
+
+    switch ( GetBarPlacement() )
+    {
+        case BarPlacement_Top:
+            return wxSHOW_EFFECT_SLIDE_TO_TOP;
 
-    if ( sibling )
-        parent->SetOwnBackgroundColour(sibling->GetBackgroundColour());
+        case BarPlacement_Bottom:
+            return wxSHOW_EFFECT_SLIDE_TO_BOTTOM;
+
+        default:
+            wxFAIL_MSG( "unknown info bar placement" );
+            // fall through
+
+        case BarPlacement_Unknown:
+            return wxSHOW_EFFECT_NONE;
+    }
 }
 
-void wxInfoBarGeneric::RestoreParentBackground()
+void wxInfoBarGeneric::UpdateParent()
 {
-    GetParent()->SetOwnBackgroundColour(m_origParentBgCol);
+    wxWindow * const parent = GetParent();
+    parent->Layout();
 }
 
 void wxInfoBarGeneric::DoHide()
 {
-    ChangeParentBackground();
-    wxON_BLOCK_EXIT_THIS0( wxInfoBarGeneric::RestoreParentBackground );
+    HideWithEffect(GetHideEffect(), GetEffectDuration());
 
-    HideWithEffect(m_hideEffect, m_effectDuration);
     UpdateParent();
 }
 
@@ -234,12 +252,6 @@ void wxInfoBarGeneric::DoShow()
     // without really showing it
     wxWindowBase::Show();
 
-    // an extra hack: we want the temporarily uncovered area in which we're
-    // going to expand to look like part of this sibling for a better effect so
-    // temporarily change the background of our parent to the same colour
-    ChangeParentBackground();
-    wxON_BLOCK_EXIT_THIS0( wxInfoBarGeneric::RestoreParentBackground );
-
     // adjust the parent layout to account for us
     UpdateParent();
 
@@ -249,7 +261,7 @@ void wxInfoBarGeneric::DoShow()
 
 
     // finally do really show the window.
-    ShowWithEffect(m_showEffect, m_effectDuration);
+    ShowWithEffect(GetShowEffect(), GetEffectDuration());
 }
 
 void wxInfoBarGeneric::ShowMessage(const wxString& msg, int flags)