]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/infobar.cpp
Added ability to switch off more components of the size page UI
[wxWidgets.git] / src / generic / infobar.cpp
index a85ead0f40cbf488098b743a3c1f1e105de78137..31f0d0ed7fed2bf715fafa44ff7b5c855d8ac22b 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)
 END_EVENT_TABLE()
 
-// ----------------------------------------------------------------------------
-// local helpers
-// ----------------------------------------------------------------------------
-
-namespace
-{
-
-#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
-
-wxBitmap
-GetCloseButtonBitmap(wxWindow *win,
-                     const wxSize& size,
-                     const wxColour& colBg,
-                     int flags = 0)
-{
-    wxBitmap bmp(size);
-    wxMemoryDC dc(bmp);
-    dc.SetBackground(colBg);
-    dc.Clear();
-    wxRendererNative::Get().
-        DrawTitleBarBitmap(win, dc, size, wxTITLEBAR_BUTTON_CLOSE, flags);
-    return bmp;
-}
-
-#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
-
-} // anonymous namespace
-
 // ============================================================================
 // implementation
 // ============================================================================
@@ -82,8 +54,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;
@@ -110,31 +82,7 @@ bool wxInfoBarGeneric::Create(wxWindow *parent, wxWindowID winid)
 
     m_text = new wxStaticText(this, wxID_ANY, "");
 
-#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
-    const wxSize sizeBmp = wxArtProvider::GetSizeHint(wxART_BUTTON);
-    wxBitmap bmp = GetCloseButtonBitmap(this, sizeBmp, colBg);
-#else // !wxHAS_DRAW_TITLE_BAR_BITMAP
-    wxBitmap bmp = wxArtProvider::GetBitmap(wxART_CLOSE, wxART_BUTTON);
-#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
-    m_button = new wxBitmapButton
-                   (
-                    this,
-                    wxID_ANY,
-                    bmp,
-                    wxDefaultPosition,
-                    wxDefaultSize,
-                    wxBORDER_NONE
-                   );
-
-#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
-    m_button->SetBitmapPressed(
-        GetCloseButtonBitmap(this, sizeBmp, colBg, wxCONTROL_PRESSED));
-
-    m_button->SetBitmapCurrent(
-        GetCloseButtonBitmap(this, sizeBmp, colBg, wxCONTROL_CURRENT));
-#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
-
-    m_button->SetBackgroundColour(colBg);
+    m_button = wxBitmapButton::NewCloseButton(this, wxID_ANY);
     m_button->SetToolTip(_("Hide this notification message."));
 
     // center the text inside the sizer with an icon to the left of it and a
@@ -164,15 +112,77 @@ bool wxInfoBarGeneric::SetFont(const wxFont& font)
     return true;
 }
 
+wxInfoBarGeneric::BarPlacement wxInfoBarGeneric::GetBarPlacement() const
+{
+    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;
+}
+
+wxShowEffect wxInfoBarGeneric::GetShowEffect() const
+{
+    if ( m_showEffect != wxSHOW_EFFECT_MAX )
+        return m_showEffect;
+
+    switch ( GetBarPlacement() )
+    {
+        case BarPlacement_Top:
+            return wxSHOW_EFFECT_SLIDE_TO_BOTTOM;
+
+        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;
+
+        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::UpdateParent()
 {
-    wxWindow * const parent = wxGetTopLevelParent(GetParent());
+    wxWindow * const parent = GetParent();
     parent->Layout();
 }
 
 void wxInfoBarGeneric::DoHide()
 {
-    HideWithEffect(m_hideEffect, m_effectDuration);
+    HideWithEffect(GetHideEffect(), GetEffectDuration());
 
     UpdateParent();
 }
@@ -198,7 +208,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)