[dasher] Gtk2: fix start-on-mouse-pos checkbox+dropdown & combine their signal handlers



commit ed07bef42df8ecd78d46a6894bbeae7b04812fa3
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Thu Dec 30 20:47:36 2010 +0000

    Gtk2: fix start-on-mouse-pos checkbox+dropdown & combine their signal handlers

 Data/GUI/dasher.preferences.ui |   10 ++----
 Src/Gtk2/Preferences.cpp       |   63 +++++++++++++--------------------------
 2 files changed, 24 insertions(+), 49 deletions(-)
---
diff --git a/Data/GUI/dasher.preferences.ui b/Data/GUI/dasher.preferences.ui
index c4967ff..a551fdf 100644
--- a/Data/GUI/dasher.preferences.ui
+++ b/Data/GUI/dasher.preferences.ui
@@ -742,7 +742,7 @@ your writing speed.</property>
                                         <property name="label" translatable="yes">Start with mouse position:</property>
                                         <property name="use_underline">True</property>
                                         <property name="draw_indicator">True</property>
-                                        <signal handler="startonmousepos" name="clicked"/>
+                                        <signal handler="OnMousePosChanged" name="clicked"/>
                                       </object>
                                       <packing>
                                         <property name="expand">False</property>
@@ -756,13 +756,9 @@ your writing speed.</property>
                                         <property name="xalign">1</property>
                                         <property name="left_padding">24</property>
                                         <child>
-                                          <object class="GtkComboBoxEntry" id="MousePosStyle">
+                                          <object class="GtkComboBox" id="MousePosStyle">
                                             <property name="visible">True</property>
-                                            <signal handler="OnMousePosStyleChanged" name="changed"/>
-                                            <child internal-child="entry">
-                                              <object class="GtkEntry" id="comboboxentry-entry1">
-                                              </object>
-                                            </child>
+                                            <signal handler="OnMousePosChanged" name="changed"/>
                                             <property name="model">model1</property>
                                             <child>
                                               <object class="GtkCellRendererText" id="renderer1"/>
diff --git a/Src/Gtk2/Preferences.cpp b/Src/Gtk2/Preferences.cpp
index 0f921d3..abba068 100644
--- a/Src/Gtk2/Preferences.cpp
+++ b/Src/Gtk2/Preferences.cpp
@@ -534,14 +534,14 @@ static void dasher_preferences_dialogue_populate_special_mouse_start(DasherPrefe
 
   if(dasher_app_settings_get_bool(pPrivate->pAppSettings, BP_MOUSEPOS_MODE)) {
     gtk_combo_box_set_active(pPrivate->pMousePosStyle, 1);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtk_builder_get_object(pPrivate->pXML, "mouseposbutton")), true);
+    gtk_toggle_button_set_active(pPrivate->pMousePosButton, true);
   }
   else if(dasher_app_settings_get_bool(pPrivate->pAppSettings, BP_CIRCLE_START)) {
     gtk_combo_box_set_active(pPrivate->pMousePosStyle, 0);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtk_builder_get_object(pPrivate->pXML, "mouseposbutton")), true);
+    gtk_toggle_button_set_active(pPrivate->pMousePosButton, true);
   }
   else {
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtk_builder_get_object(pPrivate->pXML, "mouseposbutton")), false);
+    gtk_toggle_button_set_active(pPrivate->pMousePosButton, false);
   }
 #endif 
 }
@@ -747,49 +747,28 @@ static void dasher_preferences_dialogue_update_special(DasherPreferencesDialogue
 // --- Callbacks for 'special case' controls ---
 
 // TODO: Give these a systematic naming convention
-// TODO: Think about trying to combine OnMousePosStyleChanged and startonmousepos
 
-extern "C" void OnMousePosStyleChanged(GtkWidget *widget, gpointer user_data) {
+extern "C" void OnMousePosChanged(GtkWidget *widget, gpointer user_data) {
   //  DasherPreferencesDialoguePrivate *pPrivate = DASHER_PREFERENCES_DIALOGUE_PRIVATE(pSelf);
   DasherPreferencesDialoguePrivate *pPrivate = DASHER_PREFERENCES_DIALOGUE_PRIVATE(g_pPreferencesDialogue); // TODO: Fix NULL
 
-  // FIXME - duplicate code from extern "C" void startonmousepos
-  if(gtk_toggle_button_get_active(pPrivate->pMousePosButton)) {
-    int iIndex;
-    iIndex = gtk_combo_box_get_active(pPrivate->pMousePosStyle);
-    
-    if(iIndex == 1) {
-      dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_MOUSEPOS_MODE, true);
-      dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_CIRCLE_START, false);
-    }
-    else {
-      dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_MOUSEPOS_MODE, false);
-      dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_CIRCLE_START, true);
-    }
-  }
-}
-
-extern "C" void startonmousepos(GtkWidget *widget, gpointer user_data) {
-  //  DasherPreferencesDialoguePrivate *pPrivate = DASHER_PREFERENCES_DIALOGUE_PRIVATE(pSelf);
-  DasherPreferencesDialoguePrivate *pPrivate = DASHER_PREFERENCES_DIALOGUE_PRIVATE(g_pPreferencesDialogue); // TODO: Fix NULL
-
-  if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
-    int iIndex;
-    iIndex = gtk_combo_box_get_active(pPrivate->pMousePosStyle);
-
-    if(iIndex == 1) {
-      dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_MOUSEPOS_MODE, true);
-      dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_CIRCLE_START, false);
-    }
-    else {
-      dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_MOUSEPOS_MODE, false);
-      dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_CIRCLE_START, true);
-    }
-  }
-  else {
-    dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_MOUSEPOS_MODE, false);
-    dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_CIRCLE_START, false);
-  }
+  bool bActive = gtk_toggle_button_get_active(pPrivate->pMousePosButton);
+  
+  gtk_widget_set_sensitive(GTK_WIDGET(pPrivate->pMousePosStyle),bActive);
+  
+  int iIndex;
+  if (bActive) {
+	  iIndex=gtk_combo_box_get_active(pPrivate->pMousePosStyle);
+	  if ((iIndex | 1) != 1) {
+  	    //neither 0 or 1 => neither Circle nor Two-Box is actually selected
+  	    // (i.e. combo box is empty) => forcibly select Circle
+  	  gtk_combo_box_set_active(pPrivate->pMousePosStyle, iIndex=0);
+	}
+  } else iIndex=-1;
+  
+  dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_MOUSEPOS_MODE, iIndex==1);
+  dasher_app_settings_set_bool(pPrivate->pAppSettings, BP_CIRCLE_START, iIndex==0);
+  
 }
 
 extern "C" void PrefsSpeedSliderChanged(GtkHScale *hscale, gpointer user_data) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]