#include "wx/choice.h"
+//-----------------------------------------------------------------------------
+// data
+//-----------------------------------------------------------------------------
+
+extern bool g_blockEventsOnDrag;
+
//-----------------------------------------------------------------------------
// wxChoice
//-----------------------------------------------------------------------------
-void gtk_choice_clicked_callback( GtkWidget *WXUNUSED(widget), gpointer data )
+static void gtk_choice_clicked_callback( GtkWidget *WXUNUSED(widget), wxChoice *choice )
{
- wxChoice *choice = (wxChoice*)data;
- wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, choice->GetId());
+ if (!choice->HasVMT()) return;
+ if (g_blockEventsOnDrag) return;
+
+ wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, choice->GetId() );
event.SetInt( choice->GetSelection() );
wxString tmp( choice->GetStringSelection() );
event.SetString( WXSTRINGCAST(tmp) );
event.SetEventObject(choice);
- choice->ProcessEvent(event);
+ choice->GetEventHandler()->ProcessEvent(event);
};
//-----------------------------------------------------------------------------
int wxChoice::FindString( const wxString &string ) const
{
- // If you read this code once and you think you undestand
- // it, then you are very wrong. RR
+ // If you read this code once and you think you understand
+ // it, then you are very wrong. Robert Roebling.
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
int count = 0;
while (child)
{
GtkBin *bin = GTK_BIN( child->data );
- GtkLabel *label = GTK_LABEL(bin->child);
+ GtkLabel *label = NULL;
+ if (bin->child) label = GTK_LABEL(bin->child);
+
+ wxASSERT_MSG( label != NULL , "wxChoice: invalid label" );
+
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
if (string == label->label) return count;
child = child->next;
count++;
};
+
+ wxFAIL_MSG( "wxChoice: string not found" );
+
return -1;
};
child = child->next;
count++;
};
+
+ wxFAIL_MSG( "wxChoice: no selection" );
+
return -1;
};
GtkBin *bin = GTK_BIN( child->data );
if (count == n)
{
- GtkLabel *label = GTK_LABEL(bin->child);
+ GtkLabel *label = NULL;
+ if (bin->child) label = GTK_LABEL(bin->child);
+
+ wxASSERT_MSG( label != NULL , "wxChoice: invalid label" );
+
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
return label->label;
};
child = child->next;
count++;
};
+
+ wxFAIL_MSG( "wxChoice: string not found" );
+
return "";
};
wxString wxChoice::GetStringSelection(void) const
{
GtkLabel *label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
+
+ wxASSERT_MSG( label != NULL , "wxChoice: invalid label" );
+
return label->label;
};
int wxChoice::Number(void) const
{
- GtkMenu *menu = GTK_MENU( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
+ GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
int count = 0;
- GList *child = menu->children;
+ GList *child = menu_shell->children;
while (child)
{
count++;
{
int tmp = n;
gtk_option_menu_set_history( GTK_OPTION_MENU(m_widget), (gint)tmp );
+
+ gtk_choice_clicked_callback( NULL, this );
};
void wxChoice::SetStringSelection( const wxString &string )