From: Vadim Zeitlin Date: Mon, 5 Oct 2009 22:55:10 +0000 (+0000) Subject: Added native wxInfoBar implementation for wxGTK. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ed8efd46d9c8fa3bf5d10b2a6efd295a6dd71bdb Added native wxInfoBar implementation for wxGTK. Straightforward implementation of wxInfoBar using GtkInfoBar widget available in GTK+ 2.18. Some side effects of this change: - Rename wxInfoBar version in wx/generic/infobar.h to wxInfoBarGeneric and define wxInfoBar in wx/infobar.h. - Also change default value of flags argument to ShowMessage() to wxICON_INFORMATION from wxICON_NONE as the default colour for wxICON_NONE messages is surprisingly ugly in GTK native version. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62276 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/Makefile.in b/Makefile.in index 37ae7210ff..59de148a1e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -3371,7 +3371,8 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_ADVANCED_PLATFORM_NATIVE_HDR = \ wx/gtk/bmpcbox.h \ wx/gtk/calctrl.h \ wx/gtk/dataview.h \ - wx/gtk/hyperlink.h + wx/gtk/hyperlink.h \ + wx/gtk/infobar.h @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@ADVANCED_PLATFORM_NATIVE_HDR = $(COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_ADVANCED_PLATFORM_NATIVE_HDR) @COND_TOOLKIT_MSW@ADVANCED_PLATFORM_NATIVE_HDR = \ @COND_TOOLKIT_MSW@ wx/generic/animate.h wx/msw/bmpcbox.h wx/msw/calctrl.h \ @@ -5615,7 +5616,7 @@ COND_WXUNIV_0___ADVANCED_SRC_OBJECTS = \ monodll_gridsel.o \ monodll_helpext.o \ monodll_hyperlinkg.o \ - monodll_infobar.o \ + monodll_generic_infobar.o \ monodll_laywin.o \ monodll_notifmsgg.o \ monodll_odcombo.o \ @@ -5645,7 +5646,7 @@ COND_WXUNIV_1___ADVANCED_SRC_OBJECTS = \ monodll_gridsel.o \ monodll_helpext.o \ monodll_hyperlinkg.o \ - monodll_infobar.o \ + monodll_generic_infobar.o \ monodll_laywin.o \ monodll_notifmsgg.o \ monodll_odcombo.o \ @@ -5663,7 +5664,8 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS = \ monodll_gtk_bmpcbox.o \ monodll_gtk_calctrl.o \ monodll_gtk_dataview.o \ - monodll_hyperlink.o + monodll_hyperlink.o \ + monodll_gtk_infobar.o @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS = $(COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS) COND_TOOLKIT_MSW___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS = \ monodll_animateg.o \ @@ -7427,7 +7429,7 @@ COND_WXUNIV_0___ADVANCED_SRC_OBJECTS_1 = \ monolib_gridsel.o \ monolib_helpext.o \ monolib_hyperlinkg.o \ - monolib_infobar.o \ + monolib_generic_infobar.o \ monolib_laywin.o \ monolib_notifmsgg.o \ monolib_odcombo.o \ @@ -7457,7 +7459,7 @@ COND_WXUNIV_1___ADVANCED_SRC_OBJECTS_1 = \ monolib_gridsel.o \ monolib_helpext.o \ monolib_hyperlinkg.o \ - monolib_infobar.o \ + monolib_generic_infobar.o \ monolib_laywin.o \ monolib_notifmsgg.o \ monolib_odcombo.o \ @@ -7475,7 +7477,8 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_1 = \ monolib_gtk_bmpcbox.o \ monolib_gtk_calctrl.o \ monolib_gtk_dataview.o \ - monolib_hyperlink.o + monolib_hyperlink.o \ + monolib_gtk_infobar.o @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_1 = $(COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_1) COND_TOOLKIT_MSW___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_1 = \ monolib_animateg.o \ @@ -10921,7 +10924,7 @@ COND_WXUNIV_0___ADVANCED_SRC_OBJECTS_2 = \ advdll_gridsel.o \ advdll_helpext.o \ advdll_hyperlinkg.o \ - advdll_infobar.o \ + advdll_generic_infobar.o \ advdll_laywin.o \ advdll_notifmsgg.o \ advdll_odcombo.o \ @@ -10951,7 +10954,7 @@ COND_WXUNIV_1___ADVANCED_SRC_OBJECTS_2 = \ advdll_gridsel.o \ advdll_helpext.o \ advdll_hyperlinkg.o \ - advdll_infobar.o \ + advdll_generic_infobar.o \ advdll_laywin.o \ advdll_notifmsgg.o \ advdll_odcombo.o \ @@ -10969,7 +10972,8 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_2 = \ advdll_gtk_bmpcbox.o \ advdll_gtk_calctrl.o \ advdll_gtk_dataview.o \ - advdll_hyperlink.o + advdll_hyperlink.o \ + advdll_gtk_infobar.o @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_2 = $(COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_2) COND_TOOLKIT_MSW___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_2 = \ advdll_animateg.o \ @@ -11017,7 +11021,7 @@ COND_WXUNIV_0___ADVANCED_SRC_OBJECTS_3 = \ advlib_gridsel.o \ advlib_helpext.o \ advlib_hyperlinkg.o \ - advlib_infobar.o \ + advlib_generic_infobar.o \ advlib_laywin.o \ advlib_notifmsgg.o \ advlib_odcombo.o \ @@ -11047,7 +11051,7 @@ COND_WXUNIV_1___ADVANCED_SRC_OBJECTS_3 = \ advlib_gridsel.o \ advlib_helpext.o \ advlib_hyperlinkg.o \ - advlib_infobar.o \ + advlib_generic_infobar.o \ advlib_laywin.o \ advlib_notifmsgg.o \ advlib_odcombo.o \ @@ -11065,7 +11069,8 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_3 = \ advlib_gtk_bmpcbox.o \ advlib_gtk_calctrl.o \ advlib_gtk_dataview.o \ - advlib_hyperlink.o + advlib_hyperlink.o \ + advlib_gtk_infobar.o @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_3 = $(COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_3) COND_TOOLKIT_MSW___ADVANCED_PLATFORM_NATIVE_SRC_OBJECTS_3 = \ advlib_animateg.o \ @@ -15850,6 +15855,9 @@ monodll_gtk_dataview.o: $(srcdir)/src/gtk/dataview.cpp $(MONODLL_ODEP) monodll_hyperlink.o: $(srcdir)/src/gtk/hyperlink.cpp $(MONODLL_ODEP) $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/gtk/hyperlink.cpp +monodll_gtk_infobar.o: $(srcdir)/src/gtk/infobar.cpp $(MONODLL_ODEP) + $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/gtk/infobar.cpp + monodll_mediactrlcmn.o: $(srcdir)/src/common/mediactrlcmn.cpp $(MONODLL_ODEP) $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/mediactrlcmn.cpp @@ -18724,7 +18732,7 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP) @COND_USE_GUI_1@monodll_hyperlinkg.o: $(srcdir)/src/generic/hyperlinkg.cpp $(MONODLL_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/hyperlinkg.cpp -@COND_USE_GUI_1@monodll_infobar.o: $(srcdir)/src/generic/infobar.cpp $(MONODLL_ODEP) +@COND_USE_GUI_1@monodll_generic_infobar.o: $(srcdir)/src/generic/infobar.cpp $(MONODLL_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/infobar.cpp @COND_USE_GUI_1@monodll_laywin.o: $(srcdir)/src/generic/laywin.cpp $(MONODLL_ODEP) @@ -20623,6 +20631,9 @@ monolib_gtk_dataview.o: $(srcdir)/src/gtk/dataview.cpp $(MONOLIB_ODEP) monolib_hyperlink.o: $(srcdir)/src/gtk/hyperlink.cpp $(MONOLIB_ODEP) $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/gtk/hyperlink.cpp +monolib_gtk_infobar.o: $(srcdir)/src/gtk/infobar.cpp $(MONOLIB_ODEP) + $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/gtk/infobar.cpp + monolib_mediactrlcmn.o: $(srcdir)/src/common/mediactrlcmn.cpp $(MONOLIB_ODEP) $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/mediactrlcmn.cpp @@ -23497,7 +23508,7 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP) @COND_USE_GUI_1@monolib_hyperlinkg.o: $(srcdir)/src/generic/hyperlinkg.cpp $(MONOLIB_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/hyperlinkg.cpp -@COND_USE_GUI_1@monolib_infobar.o: $(srcdir)/src/generic/infobar.cpp $(MONOLIB_ODEP) +@COND_USE_GUI_1@monolib_generic_infobar.o: $(srcdir)/src/generic/infobar.cpp $(MONOLIB_ODEP) @COND_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/infobar.cpp @COND_USE_GUI_1@monolib_laywin.o: $(srcdir)/src/generic/laywin.cpp $(MONOLIB_ODEP) @@ -31933,6 +31944,9 @@ advdll_gtk_dataview.o: $(srcdir)/src/gtk/dataview.cpp $(ADVDLL_ODEP) advdll_hyperlink.o: $(srcdir)/src/gtk/hyperlink.cpp $(ADVDLL_ODEP) $(CXXC) -c -o $@ $(ADVDLL_CXXFLAGS) $(srcdir)/src/gtk/hyperlink.cpp +advdll_gtk_infobar.o: $(srcdir)/src/gtk/infobar.cpp $(ADVDLL_ODEP) + $(CXXC) -c -o $@ $(ADVDLL_CXXFLAGS) $(srcdir)/src/gtk/infobar.cpp + advdll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(ADVDLL_ODEP) $(CXXC) -c -o $@ $(ADVDLL_CXXFLAGS) $(srcdir)/src/unix/sound_sdl.cpp @@ -31987,7 +32001,7 @@ advdll_helpext.o: $(srcdir)/src/generic/helpext.cpp $(ADVDLL_ODEP) advdll_hyperlinkg.o: $(srcdir)/src/generic/hyperlinkg.cpp $(ADVDLL_ODEP) $(CXXC) -c -o $@ $(ADVDLL_CXXFLAGS) $(srcdir)/src/generic/hyperlinkg.cpp -advdll_infobar.o: $(srcdir)/src/generic/infobar.cpp $(ADVDLL_ODEP) +advdll_generic_infobar.o: $(srcdir)/src/generic/infobar.cpp $(ADVDLL_ODEP) $(CXXC) -c -o $@ $(ADVDLL_CXXFLAGS) $(srcdir)/src/generic/infobar.cpp advdll_laywin.o: $(srcdir)/src/generic/laywin.cpp $(ADVDLL_ODEP) @@ -32260,6 +32274,9 @@ advlib_gtk_dataview.o: $(srcdir)/src/gtk/dataview.cpp $(ADVLIB_ODEP) advlib_hyperlink.o: $(srcdir)/src/gtk/hyperlink.cpp $(ADVLIB_ODEP) $(CXXC) -c -o $@ $(ADVLIB_CXXFLAGS) $(srcdir)/src/gtk/hyperlink.cpp +advlib_gtk_infobar.o: $(srcdir)/src/gtk/infobar.cpp $(ADVLIB_ODEP) + $(CXXC) -c -o $@ $(ADVLIB_CXXFLAGS) $(srcdir)/src/gtk/infobar.cpp + advlib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(ADVLIB_ODEP) $(CXXC) -c -o $@ $(ADVLIB_CXXFLAGS) $(srcdir)/src/unix/sound_sdl.cpp @@ -32314,7 +32331,7 @@ advlib_helpext.o: $(srcdir)/src/generic/helpext.cpp $(ADVLIB_ODEP) advlib_hyperlinkg.o: $(srcdir)/src/generic/hyperlinkg.cpp $(ADVLIB_ODEP) $(CXXC) -c -o $@ $(ADVLIB_CXXFLAGS) $(srcdir)/src/generic/hyperlinkg.cpp -advlib_infobar.o: $(srcdir)/src/generic/infobar.cpp $(ADVLIB_ODEP) +advlib_generic_infobar.o: $(srcdir)/src/generic/infobar.cpp $(ADVLIB_ODEP) $(CXXC) -c -o $@ $(ADVLIB_CXXFLAGS) $(srcdir)/src/generic/infobar.cpp advlib_laywin.o: $(srcdir)/src/generic/laywin.cpp $(ADVLIB_ODEP) diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 894d467972..5e0b47d3cc 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -3028,6 +3028,7 @@ src/osx/iphone/window.mm src/gtk/calctrl.cpp src/gtk/dataview.cpp src/gtk/hyperlink.cpp + src/gtk/infobar.cpp wx/gtk/animate.h @@ -3035,6 +3036,7 @@ src/osx/iphone/window.mm wx/gtk/calctrl.h wx/gtk/dataview.h wx/gtk/hyperlink.h + wx/gtk/infobar.h diff --git a/include/wx/generic/infobar.h b/include/wx/generic/infobar.h index 085bc40d50..13c20ff2a6 100644 --- a/include/wx/generic/infobar.h +++ b/include/wx/generic/infobar.h @@ -19,14 +19,14 @@ class WXDLLIMPEXP_FWD_CORE wxStaticText; // wxInfoBar // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_ADV wxInfoBar : public wxInfoBarBase +class WXDLLIMPEXP_ADV wxInfoBarGeneric : public wxInfoBarBase { public: // the usual ctors and Create() but remember that info bar is created // hidden - wxInfoBar() { Init(); } + wxInfoBarGeneric() { Init(); } - wxInfoBar(wxWindow *parent, wxWindowID winid = wxID_ANY) + wxInfoBarGeneric(wxWindow *parent, wxWindowID winid = wxID_ANY) { Init(); Create(parent, winid); @@ -38,7 +38,8 @@ public: // implement base class methods // ---------------------------- - virtual void ShowMessage(const wxString& msg, int flags = wxICON_NONE); + virtual void ShowMessage(const wxString& msg, + int flags = wxICON_INFORMATION); virtual void AddButton(wxWindowID btnid, const wxString& label = wxString()); @@ -76,6 +77,11 @@ public: // (default font is a larger and bold version of the normal one) virtual bool SetFont(const wxFont& font); +protected: + // update the parent to take our new or changed size into account (notably + // should be called when we're shown or hidden) + void UpdateParent(); + private: // common part of all ctors void Init(); @@ -83,9 +89,6 @@ private: // handler for the close button void OnButton(wxCommandEvent& event); - // update the parent after we're shown or hidden - void UpdateParent(); - // change the parent background colour to match that of our sibling void ChangeParentBackground(); @@ -110,7 +113,7 @@ private: // the original parent background colour, before we changed it wxColour m_origParentBgCol; - wxDECLARE_NO_COPY_CLASS(wxInfoBar); + wxDECLARE_NO_COPY_CLASS(wxInfoBarGeneric); }; #endif // _WX_GENERIC_INFOBAR_H_ diff --git a/include/wx/gtk/infobar.h b/include/wx/gtk/infobar.h new file mode 100644 index 0000000000..8178db0343 --- /dev/null +++ b/include/wx/gtk/infobar.h @@ -0,0 +1,64 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/gtk/infobar.h +// Purpose: native implementation of wxInfoBar for GTK+ 2.18 and later +// Author: Vadim Zeitlin +// Created: 2009-09-26 +// RCS-ID: $Id: wxhead.h,v 1.11 2009-06-29 10:23:04 zeitlin Exp $ +// Copyright: (c) 2009 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_GTK_INFOBAR_H_ +#define _WX_GTK_INFOBAR_H_ + +#include "wx/generic/infobar.h" + +// ---------------------------------------------------------------------------- +// wxInfoBar for GTK+ +// ---------------------------------------------------------------------------- + +// notice that the native GTK+ implementation is only available since +// (relatively recent) 2.18 so we inherit from the generic one to be able to +// fall back to it if GTK+ version is determined to be too old during run-time +class WXDLLIMPEXP_ADV wxInfoBar : public wxInfoBarGeneric +{ +public: + wxInfoBar() { Init(); } + + wxInfoBar(wxWindow *parent, wxWindowID winid = wxID_ANY) + { + Init(); + Create(parent, winid); + } + + bool Create(wxWindow *parent, wxWindowID winid = wxID_ANY); + + virtual ~wxInfoBar(); + + // implement base class methods + // ---------------------------- + + virtual void ShowMessage(const wxString& msg, + int flags = wxICON_INFORMATION); + + virtual void AddButton(wxWindowID btnid, + const wxString& label = wxString()); + + // implementation only + // ------------------- + + void GTKResponse(int btnid); + +protected: + virtual bool GTKShouldConnectSizeRequest() const { return false; } + +private: + void Init() { m_label = NULL; } + + GtkWidget *m_label; + + wxDECLARE_NO_COPY_CLASS(wxInfoBar); +}; + +#endif // _WX_GTK_INFOBAR_H_ + diff --git a/include/wx/infobar.h b/include/wx/infobar.h index eb8b7e1703..00046d1e4c 100644 --- a/include/wx/infobar.h +++ b/include/wx/infobar.h @@ -21,7 +21,7 @@ // wxInfoBar shows non-critical but important information to the user // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_ADV wxInfoBarBase : public wxWindow +class WXDLLIMPEXP_ADV wxInfoBarBase : public wxControl { public: // real ctors are provided by the derived classes, just notice that unlike @@ -33,7 +33,8 @@ public: // show the info bar with the given message and optionally an icon - virtual void ShowMessage(const wxString& msg, int flags = wxICON_NONE) = 0; + virtual void ShowMessage(const wxString& msg, + int flags = wxICON_INFORMATION) = 0; // add an extra button to the bar, near the message virtual void AddButton(wxWindowID btnid, @@ -43,10 +44,20 @@ private: wxDECLARE_NO_COPY_CLASS(wxInfoBarBase); }; -// include platform-dependent implementation -// -// TODO-GTK: implement a native version using GtkInfoBar (GTK+ 2.18+) -#include "wx/generic/infobar.h" +// currently only GTK+ has a native implementation +#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__) + #include + #if GTK_CHECK_VERSION(2, 18, 0) + #include "wx/gtk/infobar.h" + #define wxHAS_NATIVE_INFOBAR + #endif +#endif // wxGTK2 + +// if the generic version is the only one we have, use it +#ifndef wxHAS_NATIVE_INFOBAR + #include "wx/generic/infobar.h" + #define wxInfoBar wxInfoBarGeneric +#endif #endif // wxUSE_INFOBAR diff --git a/interface/wx/infobar.h b/interface/wx/infobar.h index 70f662b95e..0eb6e6f0fe 100644 --- a/interface/wx/infobar.h +++ b/interface/wx/infobar.h @@ -59,10 +59,10 @@ See the dialogs sample for more sophisticated examples. - Only generic implementation of this class exists currently but it is - planned to provide a native GTK+-based version in future wxWidgets releases - so avoid the use of the methods marked "generic only" for maximal - portability. + Currently this class is implemented generically (i.e. in the same + platform-independent way for all ports) and also natively in wxGTK but the + native implementation requires a recent -- as of this writing -- GTK+ 2.18 + version. @library{wxadv} @category{miscwnd} @@ -140,10 +140,14 @@ public: @param msg The text of the message. @param flags - One of wxICON_NONE (default), wxICON_INFORMATION, wxICON_QUESTION, + One of wxICON_NONE, wxICON_INFORMATION (default), wxICON_QUESTION, wxICON_WARNING or wxICON_ERROR values. These flags have the same - meaning as in wxMessageDialog, i.e. show the corresponding icon in - the bar. + meaning as in wxMessageDialog for the generic version, i.e. show + (or not, in case of wxICON_NONE) the corresponding icon in the bar + but can be interpreted by the native versions. For example, the + GTK+ native implementation doesn't show icons at all but uses this + parameter to select the appropriate background colour for the + notification. */ void ShowMessage(const wxString& msg, int flags = wxICON_NONE); @@ -153,9 +157,9 @@ public: All these methods exist in the generic version of the class only. The generic version uses wxWindow::ShowWithEffect() function to - progressively show it on the platforms which support it. The methods - here allow to change the default effect used (or disable it entirely) - and change its duration. + progressively show it on the platforms which support it (currently only + wxMSW). The methods here allow to change the default effect used (or + disable it entirely) and change its duration. */ //@{ diff --git a/src/generic/infobar.cpp b/src/generic/infobar.cpp index c5e84d838f..d6cbe2e054 100644 --- a/src/generic/infobar.cpp +++ b/src/generic/infobar.cpp @@ -26,7 +26,6 @@ #if wxUSE_INFOBAR #ifndef WX_PRECOMP - #include "wx/artprov.h" #include "wx/bmpbuttn.h" #include "wx/button.h" #include "wx/settings.h" @@ -36,6 +35,7 @@ #include "wx/infobar.h" +#include "wx/artprov.h" #include "wx/scopeguard.h" #include "wx/sizer.h" @@ -43,7 +43,7 @@ // implementation // ============================================================================ -void wxInfoBar::Init() +void wxInfoBarGeneric::Init() { m_icon = NULL; m_text = NULL; @@ -56,7 +56,7 @@ void wxInfoBar::Init() m_effectDuration = 0; } -bool wxInfoBar::Create(wxWindow *parent, wxWindowID winid) +bool wxInfoBarGeneric::Create(wxWindow *parent, wxWindowID winid) { // calling Hide() before Create() ensures that we're created initially // hidden @@ -92,7 +92,7 @@ bool wxInfoBar::Create(wxWindow *parent, wxWindowID winid) Connect ( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxInfoBar::OnButton), + wxCommandEventHandler(wxInfoBarGeneric::OnButton), NULL, this ); @@ -113,7 +113,7 @@ bool wxInfoBar::Create(wxWindow *parent, wxWindowID winid) return true; } -bool wxInfoBar::SetFont(const wxFont& font) +bool wxInfoBarGeneric::SetFont(const wxFont& font) { if ( !wxInfoBarBase::SetFont(font) ) return false; @@ -125,13 +125,13 @@ bool wxInfoBar::SetFont(const wxFont& font) return true; } -void wxInfoBar::UpdateParent() +void wxInfoBarGeneric::UpdateParent() { wxWindow * const parent = wxGetTopLevelParent(GetParent()); parent->Layout(); } -void wxInfoBar::ChangeParentBackground() +void wxInfoBarGeneric::ChangeParentBackground() { wxWindow * const parent = GetParent(); m_origParentBgCol = parent->GetBackgroundColour(); @@ -169,21 +169,21 @@ void wxInfoBar::ChangeParentBackground() parent->SetOwnBackgroundColour(sibling->GetBackgroundColour()); } -void wxInfoBar::RestoreParentBackground() +void wxInfoBarGeneric::RestoreParentBackground() { GetParent()->SetOwnBackgroundColour(m_origParentBgCol); } -void wxInfoBar::DoHide() +void wxInfoBarGeneric::DoHide() { ChangeParentBackground(); - wxON_BLOCK_EXIT_THIS0( wxInfoBar::RestoreParentBackground ); + wxON_BLOCK_EXIT_THIS0( wxInfoBarGeneric::RestoreParentBackground ); HideWithEffect(m_hideEffect, m_effectDuration); UpdateParent(); } -void wxInfoBar::DoShow() +void wxInfoBarGeneric::DoShow() { // re-layout the parent first so that the window expands into an already // unoccupied by the other controls area: for this we need to change our @@ -199,7 +199,7 @@ void wxInfoBar::DoShow() // 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( wxInfoBar::RestoreParentBackground ); + wxON_BLOCK_EXIT_THIS0( wxInfoBarGeneric::RestoreParentBackground ); // adjust the parent layout to account for us UpdateParent(); @@ -213,7 +213,7 @@ void wxInfoBar::DoShow() ShowWithEffect(m_showEffect, m_effectDuration); } -void wxInfoBar::ShowMessage(const wxString& msg, int flags) +void wxInfoBarGeneric::ShowMessage(const wxString& msg, int flags) { // first update the controls const int icon = flags & wxICON_MASK; @@ -244,7 +244,7 @@ void wxInfoBar::ShowMessage(const wxString& msg, int flags) } } -void wxInfoBar::AddButton(wxWindowID btnid, const wxString& label) +void wxInfoBarGeneric::AddButton(wxWindowID btnid, const wxString& label) { wxSizer * const sizer = GetSizer(); wxCHECK_RET( sizer, "must be created first" ); @@ -254,7 +254,7 @@ void wxInfoBar::AddButton(wxWindowID btnid, const wxString& label) wxSizerFlags().Centre().DoubleBorder()); } -void wxInfoBar::OnButton(wxCommandEvent& WXUNUSED(event)) +void wxInfoBarGeneric::OnButton(wxCommandEvent& WXUNUSED(event)) { DoHide(); } diff --git a/src/gtk/infobar.cpp b/src/gtk/infobar.cpp new file mode 100644 index 0000000000..604838abfc --- /dev/null +++ b/src/gtk/infobar.cpp @@ -0,0 +1,150 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/gtk/infobar.cpp +// Purpose: wxInfoBar implementation for GTK +// Author: Vadim Zeitlin +// Created: 2009-09-27 +// RCS-ID: $Id: wxhead.cpp,v 1.10 2009-06-29 10:23:04 zeitlin Exp $ +// Copyright: (c) 2009 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/infobar.h" + +#if wxUSE_INFOBAR && defined(wxHAS_NATIVE_INFOBAR) + +#ifndef WX_PRECOMP +#endif // WX_PRECOMP + +#include "wx/gtk/private.h" +#include "wx/gtk/private/messagetype.h" + +// ---------------------------------------------------------------------------- +// local functions +// ---------------------------------------------------------------------------- + +namespace +{ + +inline bool UseNative() +{ + // native GtkInfoBar widget is only available in GTK+ 2.18 and later + return gtk_check_version(2, 18, 0) == 0; +} + +} // anonymous namespace + +extern "C" +{ + +static void wxgtk_infobar_response(GtkInfoBar * WXUNUSED(infobar), + gint btnid, + wxInfoBar *win) +{ + win->GTKResponse(btnid); +} + +static void wxgtk_infobar_close(GtkInfoBar * WXUNUSED(infobar), + wxInfoBar *win) +{ + win->GTKResponse(wxID_CANCEL); +} + +} // extern "C" section with GTK+ callbacks + +// ============================================================================ +// wxInfoBar implementation +// ============================================================================ + +bool wxInfoBar::Create(wxWindow *parent, wxWindowID winid) +{ + if ( !UseNative() ) + return wxInfoBarGeneric::Create(parent, winid); + + // this control is created initially hidden + Hide(); + if ( !CreateBase(parent, winid) ) + return false; + + // create the info bar widget itself + m_widget = gtk_info_bar_new(); + wxCHECK_MSG( m_widget, false, "failed to create GtkInfoBar" ); + g_object_ref(m_widget); + + // also create a label which will be used to show our message + m_label = gtk_label_new(""); + gtk_widget_show(m_label); + + GtkWidget * const + contentArea = gtk_info_bar_get_content_area(GTK_INFO_BAR(m_widget)); + wxCHECK_MSG( contentArea, false, "failed to get GtkInfoBar content area" ); + gtk_container_add(GTK_CONTAINER(contentArea), m_label); + + // finish creation and connect to all the signals we're interested in + m_parent->DoAddChild(this); + + PostCreation(wxDefaultSize); + + GTKConnectWidget("response", G_CALLBACK(wxgtk_infobar_response)); + GTKConnectWidget("close", G_CALLBACK(wxgtk_infobar_close)); + + return false; +} + +void wxInfoBar::ShowMessage(const wxString& msg, int flags) +{ + if ( !UseNative() ) + { + wxInfoBarGeneric::ShowMessage(msg, flags); + return; + } + + GtkMessageType type; + if ( wxGTKImpl::ConvertMessageTypeFromWX(flags, &type) ) + gtk_info_bar_set_message_type(GTK_INFO_BAR(m_widget), type); + gtk_label_set_text(GTK_LABEL(m_label), wxGTK_CONV(msg)); + + if ( !IsShown() ) + Show(); + + UpdateParent(); +} + +void wxInfoBar::GTKResponse(int WXUNUSED(btnid)) +{ + Hide(); + + UpdateParent(); +} + +void wxInfoBar::AddButton(wxWindowID btnid, const wxString& label) +{ + if ( !UseNative() ) + { + wxInfoBarGeneric::AddButton(btnid, label); + return; + } + + gtk_info_bar_add_button + ( + GTK_INFO_BAR(m_widget), + label.empty() ? GTKConvertMnemonics(wxGetStockGtkID(btnid)) : label, + btnid + ); +} + +#endif // wxUSE_INFOBAR