]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/infobar.cpp
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/vector.h"
35 #include "wx/gtk/private.h"
36 #include "wx/gtk/private/messagetype.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 class wxInfoBarGTKImpl
54 Button(GtkWidget
*button_
, int id_
)
63 typedef wxVector
<Button
> Buttons
;
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
75 inline bool UseNative()
77 // native GtkInfoBar widget is only available in GTK+ 2.18 and later
78 return gtk_check_version(2, 18, 0) == 0;
81 } // anonymous namespace
86 static void wxgtk_infobar_response(GtkInfoBar
* WXUNUSED(infobar
),
90 win
->GTKResponse(btnid
);
93 static void wxgtk_infobar_close(GtkInfoBar
* WXUNUSED(infobar
),
96 win
->GTKResponse(wxID_CANCEL
);
99 } // extern "C" section with GTK+ callbacks
101 // ============================================================================
102 // wxInfoBar implementation
103 // ============================================================================
105 bool wxInfoBar::Create(wxWindow
*parent
, wxWindowID winid
)
108 return wxInfoBarGeneric::Create(parent
, winid
);
110 m_impl
= new wxInfoBarGTKImpl
;
112 // this control is created initially hidden
114 if ( !CreateBase(parent
, winid
) )
117 // create the info bar widget itself
118 m_widget
= gtk_info_bar_new();
119 wxCHECK_MSG( m_widget
, false, "failed to create GtkInfoBar" );
120 g_object_ref(m_widget
);
122 // also create a label which will be used to show our message
123 m_impl
->m_label
= gtk_label_new("");
124 gtk_widget_show(m_impl
->m_label
);
127 contentArea
= gtk_info_bar_get_content_area(GTK_INFO_BAR(m_widget
));
128 wxCHECK_MSG( contentArea
, false, "failed to get GtkInfoBar content area" );
129 gtk_container_add(GTK_CONTAINER(contentArea
), m_impl
->m_label
);
131 // finish creation and connect to all the signals we're interested in
132 m_parent
->DoAddChild(this);
134 PostCreation(wxDefaultSize
);
136 GTKConnectWidget("response", G_CALLBACK(wxgtk_infobar_response
));
137 GTKConnectWidget("close", G_CALLBACK(wxgtk_infobar_close
));
142 wxInfoBar::~wxInfoBar()
147 void wxInfoBar::ShowMessage(const wxString
& msg
, int flags
)
151 wxInfoBarGeneric::ShowMessage(msg
, flags
);
156 if ( wxGTKImpl::ConvertMessageTypeFromWX(flags
, &type
) )
157 gtk_info_bar_set_message_type(GTK_INFO_BAR(m_widget
), type
);
158 gtk_label_set_text(GTK_LABEL(m_impl
->m_label
), wxGTK_CONV(msg
));
166 void wxInfoBar::GTKResponse(int WXUNUSED(btnid
))
173 void wxInfoBar::AddButton(wxWindowID btnid
, const wxString
& label
)
177 wxInfoBarGeneric::AddButton(btnid
, label
);
181 GtkWidget
*button
= gtk_info_bar_add_button
183 GTK_INFO_BAR(m_widget
),
185 ? GTKConvertMnemonics(wxGetStockGtkID(btnid
))
189 wxCHECK_RET( button
, "unexpectedly failed to add button to info bar" );
191 g_object_ref(button
);
192 m_impl
->m_buttons
.push_back(wxInfoBarGTKImpl::Button(button
, btnid
));
195 void wxInfoBar::RemoveButton(wxWindowID btnid
)
199 wxInfoBarGeneric::RemoveButton(btnid
);
203 // as in the generic version, look for the button starting from the end
204 wxInfoBarGTKImpl::Buttons
& buttons
= m_impl
->m_buttons
;
205 for ( wxInfoBarGTKImpl::Buttons::reverse_iterator i
= buttons
.rbegin();
209 GtkWidget
* const button
= i
->button
;
210 buttons
.erase(i
.base());
211 gtk_widget_destroy(button
);
212 g_object_unref(button
);
216 wxFAIL_MSG( wxString::Format("button with id %d not found", btnid
) );
219 #endif // wxUSE_INFOBAR