]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/choice.cpp
one more minor wxLogWindow fix (I try to get it really right...)
[wxWidgets.git] / src / gtk / choice.cpp
index 57922091b9ca4b2afa7122de3d25d6e5d9406bfe..039b4fda7ff8e66bd186989662b0f5425c804896 100644 (file)
 
 #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);
 };
 
 //-----------------------------------------------------------------------------
@@ -103,8 +111,8 @@ void wxChoice::Clear(void)
 
 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;
@@ -112,12 +120,19 @@ int wxChoice::FindString( const wxString &string ) const
   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;
 };
 
@@ -138,6 +153,9 @@ int wxChoice::GetSelection(void)
     child = child->next;
     count++;
   };
+  
+  wxFAIL_MSG( "wxChoice: no selection" );
+  
   return -1;
 };
 
@@ -151,27 +169,37 @@ wxString wxChoice::GetString( int n ) const
     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++;
@@ -188,6 +216,8 @@ void wxChoice::SetSelection( int n )
 {
   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 )