/////////////////////////////////////////////////////////////////////////////
-// Name: choice.cpp
+// Name: src/gtk/choice.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
#include "wx/choice.h"
#include "wx/arrstr.h"
-#include "wx/gtk/private.h"
-
-//-----------------------------------------------------------------------------
-// idle system
-//-----------------------------------------------------------------------------
+// FIXME: We use GtkOptionMenu which has been deprecated since GTK+ 2.3.0 in
+// favour of GtkComboBox.
+// Later use GtkComboBox if GTK+ runtime version is new enough.
+#include <gtk/gtkversion.h>
+#if defined(GTK_DISABLE_DEPRECATED) && GTK_CHECK_VERSION(2,3,0)
+#undef GTK_DISABLE_DEPRECATED
+#endif
-extern void wxapp_install_idle_handler();
-extern bool g_isIdle;
+#include "wx/gtk/private.h"
//-----------------------------------------------------------------------------
// data
int selection = wxNOT_FOUND;
-#ifdef __WXGTK20__
selection = gtk_option_menu_get_history( GTK_OPTION_MENU(choice->GetHandle()) );
-#else
- GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(choice->GetHandle()) ) );
- int count = 0;
- GList *child = menu_shell->children;
- while (child)
- {
- GtkBin *bin = GTK_BIN( child->data );
- if (!bin->child)
- {
- selection = count;
- break;
- }
- child = child->next;
- count++;
- }
-#endif
choice->m_selection_hack = selection;
wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, choice->GetId() );
}
}
-int wxChoice::FindString( const wxString &string ) const
+int wxChoice::FindString( const wxString &string, bool bCase ) const
{
- wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice") );
+ wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid choice") );
// If you read this code once and you think you understand
// it, then you are very wrong. Robert Roebling.
if (bin->child)
label = GTK_LABEL(bin->child);
if (!label)
- label = GTK_LABEL( BUTTON_CHILD(m_widget) );
+ label = GTK_LABEL(GTK_BIN(m_widget)->child);
wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") );
-#ifdef __WXGTK20__
wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text( label) ) );
-#else
- wxString tmp( label->label );
-#endif
- if (string == tmp)
+ if (string.IsSameAs( tmp, bCase ))
return count;
child = child->next;
int wxChoice::GetSelection() const
{
- wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice") );
+ wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid choice") );
return m_selection_hack;
if (bin->child)
label = GTK_LABEL(bin->child);
if (!label)
- label = GTK_LABEL( BUTTON_CHILD(m_widget) );
+ label = GTK_LABEL(GTK_BIN(m_widget)->child);
wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") );
if (bin->child)
label = GTK_LABEL(bin->child);
if (!label)
- label = GTK_LABEL( BUTTON_CHILD(m_widget) );
+ label = GTK_LABEL(GTK_BIN(m_widget)->child);
wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") );
-#ifdef __WXGTK20__
return wxString( wxGTK_CONV_BACK( gtk_label_get_text( label) ) );
-#else
- return wxString( label->label );
-#endif
}
child = child->next;
count++;
if (bin->child)
label = bin->child;
if (!label)
- label = BUTTON_CHILD(m_widget);
+ label = GTK_BIN(m_widget)->child;
gtk_widget_modify_style( label, style );
// sorted control, need to insert at the correct index
index = m_strings->Add(item);
- gtk_menu_insert( GTK_MENU(menu), menu_item, index );
+ gtk_menu_shell_insert( GTK_MENU_SHELL(menu), menu_item, index );
if ( index )
{
// normal control, just append
if (pos == (int)m_clientList.GetCount())
{
- gtk_menu_append( GTK_MENU(menu), menu_item );
+ gtk_menu_shell_append( GTK_MENU_SHELL(menu), menu_item );
m_clientList.Append( (wxObject*) NULL );
index = m_clientList.GetCount() - 1;
}
else
{
- gtk_menu_insert( GTK_MENU(menu), menu_item, pos );
+ gtk_menu_shell_insert( GTK_MENU_SHELL(menu), menu_item, pos );
m_clientList.Insert( pos, (wxObject*) NULL );
index = pos;
}
// it has to change. Adapted from Matt Ownby.
InvalidateBestSize();
- gtk_signal_connect_after( GTK_OBJECT( menu_item ), "activate",
- GTK_SIGNAL_FUNC(gtk_choice_clicked_callback), (gpointer*)this );
+ g_signal_connect_after (menu_item, "activate",
+ G_CALLBACK (gtk_choice_clicked_callback),
+ this);
gtk_widget_show( menu_item );
bool wxChoice::IsOwnGtkWindow( GdkWindow *window )
{
-#ifdef __WXGTK20__
return GTK_BUTTON(m_widget)->event_window;
-#else
- return (window == m_widget->window);
-#endif
}
// static