1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/infobar.cpp
3 // Purpose: wxInfoBar implementation for GTK
4 // Author: Vadim Zeitlin
6 // RCS-ID: $Id: wxhead.cpp,v 1.10 2009-06-29 10:23:04 zeitlin Exp $
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/infobar.h"
28 #if wxUSE_INFOBAR && defined(wxHAS_NATIVE_INFOBAR)
33 #include "wx/gtk/private.h"
34 #include "wx/gtk/private/messagetype.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
43 inline bool UseNative()
45 // native GtkInfoBar widget is only available in GTK+ 2.18 and later
46 return gtk_check_version(2, 18, 0) == 0;
49 } // anonymous namespace
54 static void wxgtk_infobar_response(GtkInfoBar
* WXUNUSED(infobar
),
58 win
->GTKResponse(btnid
);
61 static void wxgtk_infobar_close(GtkInfoBar
* WXUNUSED(infobar
),
64 win
->GTKResponse(wxID_CANCEL
);
67 } // extern "C" section with GTK+ callbacks
69 // ============================================================================
70 // wxInfoBar implementation
71 // ============================================================================
73 bool wxInfoBar
::Create(wxWindow
*parent
, wxWindowID winid
)
76 return wxInfoBarGeneric
::Create(parent
, winid
);
78 // this control is created initially hidden
80 if ( !CreateBase(parent
, winid
) )
83 // create the info bar widget itself
84 m_widget
= gtk_info_bar_new();
85 wxCHECK_MSG( m_widget
, false, "failed to create GtkInfoBar" );
86 g_object_ref(m_widget
);
88 // also create a label which will be used to show our message
89 m_label
= gtk_label_new("");
90 gtk_widget_show(m_label
);
93 contentArea
= gtk_info_bar_get_content_area(GTK_INFO_BAR(m_widget
));
94 wxCHECK_MSG( contentArea
, false, "failed to get GtkInfoBar content area" );
95 gtk_container_add(GTK_CONTAINER(contentArea
), m_label
);
97 // finish creation and connect to all the signals we're interested in
98 m_parent
->DoAddChild(this);
100 PostCreation(wxDefaultSize
);
102 GTKConnectWidget("response", G_CALLBACK(wxgtk_infobar_response
));
103 GTKConnectWidget("close", G_CALLBACK(wxgtk_infobar_close
));
108 void wxInfoBar
::ShowMessage(const wxString
& msg
, int flags
)
112 wxInfoBarGeneric
::ShowMessage(msg
, flags
);
117 if ( wxGTKImpl
::ConvertMessageTypeFromWX(flags
, &type
) )
118 gtk_info_bar_set_message_type(GTK_INFO_BAR(m_widget
), type
);
119 gtk_label_set_text(GTK_LABEL(m_label
), wxGTK_CONV(msg
));
127 void wxInfoBar
::GTKResponse(int WXUNUSED(btnid
))
134 void wxInfoBar
::AddButton(wxWindowID btnid
, const wxString
& label
)
138 wxInfoBarGeneric
::AddButton(btnid
, label
);
142 gtk_info_bar_add_button
144 GTK_INFO_BAR(m_widget
),
145 label
.empty() ?
GTKConvertMnemonics(wxGetStockGtkID(btnid
)) : label
,
150 #endif // wxUSE_INFOBAR