[dasher] Gtk Preferences: reduce use of global g_pPreferencesDialogue



commit d94b1d6a15ea5f4b252a8d75b08121b2d2b0abd7
Author: Patrick Welche <prlw1 cam ac uk>
Date:   Mon Mar 23 17:06:01 2015 +0100

    Gtk Preferences: reduce use of global g_pPreferencesDialogue
    
    - Give Preferences access to DasherMainPrivate
    - Use DASHER_PREFERENCES_DIALOGUE_PRIVATE

 Src/Gtk2/Preferences.cpp       |   33 +++++++++++++--------------
 Src/Gtk2/dasher_main.cpp       |   45 +-----------------------------------
 Src/Gtk2/dasher_main_private.h |   49 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 61 deletions(-)
---
diff --git a/Src/Gtk2/Preferences.cpp b/Src/Gtk2/Preferences.cpp
index 64eb5de..165ee2c 100644
--- a/Src/Gtk2/Preferences.cpp
+++ b/Src/Gtk2/Preferences.cpp
@@ -5,7 +5,7 @@
 #include <glib/gi18n.h>
 #include <libintl.h>
 #include <cstring>
-#include <math.h>
+#include <cmath>
 
 #include "../Common/Common.h"
 #include "DasherTypes.h"
@@ -13,6 +13,7 @@
 #include "Preferences.h"
 #include "Parameters.h"
 #include "module_settings_window.h"
+#include "dasher_main_private.h"
 
 #define DASHER_PREFERENCES_DIALOGUE_PRIVATE(pSelf) (DasherPreferencesDialoguePrivate *)(pSelf->private_data);
 
@@ -211,7 +212,7 @@ static void dasher_preferences_dialogue_init(DasherPreferencesDialogue *pDasherC
 
 static void dasher_preferences_dialogue_destroy(GObject *pObject) {
   DasherPreferencesDialogue *pSelf = (DasherPreferencesDialogue *)pObject;
-  DasherPreferencesDialoguePrivate *pPrivate = (DasherPreferencesDialoguePrivate *)(pSelf->private_data);
+  DasherPreferencesDialoguePrivate *pPrivate = DASHER_PREFERENCES_DIALOGUE_PRIVATE(pSelf);
 
   g_object_unref(pPrivate->pXML);
 
@@ -223,12 +224,12 @@ static void dasher_preferences_dialogue_destroy(GObject *pObject) {
 // Public methods
 
 DasherPreferencesDialogue *dasher_preferences_dialogue_new(GtkBuilder *pXML, DasherEditor *pEditor, 
DasherAppSettings *pAppSettings, GtkWindow *pMainWindow) {
-  DasherPreferencesDialogue *pDasherControl;
-  pDasherControl = (DasherPreferencesDialogue *)(g_object_new(dasher_preferences_dialogue_get_type(), NULL));
+  DasherPreferencesDialogue *pDasherPref;
+  pDasherPref = (DasherPreferencesDialogue *)(g_object_new(dasher_preferences_dialogue_get_type(), NULL));
 
-  g_pPreferencesDialogue = pDasherControl;
+  g_pPreferencesDialogue = pDasherPref;
 
-  DasherPreferencesDialoguePrivate *pPrivate = (DasherPreferencesDialoguePrivate 
*)(pDasherControl->private_data);
+  DasherPreferencesDialoguePrivate *pPrivate = DASHER_PREFERENCES_DIALOGUE_PRIVATE(pDasherPref);
 
   pPrivate->bIgnoreSignals = false;
 
@@ -246,9 +247,9 @@ DasherPreferencesDialogue *dasher_preferences_dialogue_new(GtkBuilder *pXML, Das
   pPrivate->pMainWindow = pMainWindow;
 
   pPrivate->pSpeedSlider = GTK_RANGE(gtk_builder_get_object(pXML, "hscale1"));
-  dasher_preferences_dialogue_initialise_tables(pDasherControl);
-  dasher_preferences_dialogue_refresh_widget(pDasherControl, -1);
-  dasher_preferences_dialogue_update_special(pDasherControl, -1);
+  dasher_preferences_dialogue_initialise_tables(pDasherPref);
+  dasher_preferences_dialogue_refresh_widget(pDasherPref, -1);
+  dasher_preferences_dialogue_update_special(pDasherPref, -1);
 
 #ifdef WITH_MAEMO
 #ifndef WITH_MAEMOFULLSCREEN
@@ -262,11 +263,11 @@ DasherPreferencesDialogue *dasher_preferences_dialogue_new(GtkBuilder *pXML, Das
 
   //  InitialiseFontDialogues(pXML, pAppSettings);
 
-  return pDasherControl;
+  return pDasherPref;
 }
 
 void dasher_preferences_dialogue_show(DasherPreferencesDialogue *pSelf, gint iPage) {
-  DasherPreferencesDialoguePrivate *pPrivate = (DasherPreferencesDialoguePrivate *)(pSelf->private_data);
+  DasherPreferencesDialoguePrivate *pPrivate = DASHER_PREFERENCES_DIALOGUE_PRIVATE(pSelf);
   // FIXME - REIMPLEMENT
 
   // Keep the preferences window in the correct position relative to the
@@ -852,17 +853,15 @@ extern "C" void on_appstyle_changed(GtkWidget *widget, gpointer user_data) {
 }
 
 extern "C" void on_dasher_font_changed(GtkFontButton *pButton, gpointer pUserData) {
-  DasherPreferencesDialoguePrivate *pPrivate = DASHER_PREFERENCES_DIALOGUE_PRIVATE(g_pPreferencesDialogue);
-
-  dasher_app_settings_set_string(pPrivate->pAppSettings, 
+  DasherMainPrivate *pMainPrivate = DASHER_MAIN_GET_PRIVATE(pUserData);
+  dasher_app_settings_set_string(pMainPrivate->pAppSettings,
                                  SP_DASHER_FONT, 
                                  gtk_font_button_get_font_name(pButton));
 }
 
 extern "C" void on_edit_font_changed(GtkFontButton *pButton, gpointer pUserData) {
-  DasherPreferencesDialoguePrivate *pPrivate = DASHER_PREFERENCES_DIALOGUE_PRIVATE(g_pPreferencesDialogue);
-
-  dasher_app_settings_set_string(pPrivate->pAppSettings, 
+  DasherMainPrivate *pMainPrivate = DASHER_MAIN_GET_PRIVATE(pUserData);
+  dasher_app_settings_set_string(pMainPrivate->pAppSettings,
                                  APP_SP_EDIT_FONT, 
                                  gtk_font_button_get_font_name(pButton));
 }
diff --git a/Src/Gtk2/dasher_main.cpp b/Src/Gtk2/dasher_main.cpp
index e2d822e..1656cfe 100644
--- a/Src/Gtk2/dasher_main.cpp
+++ b/Src/Gtk2/dasher_main.cpp
@@ -23,49 +23,7 @@
 #include "dasher_editor.h"
 #include "math.h"
 
-struct _DasherMainPrivate {
-  GtkBuilder *pXML;
-  GtkBuilder *pPrefXML;
-
-  // Child objects owned here
-  DasherAppSettings *pAppSettings;
-  DasherPreferencesDialogue *pPreferencesDialogue;
-  DasherEditor *pEditor;
-
-  CKeyboardHelper *pKeyboardHelper;
-
-  // Various widgets which need to be cached:
-  // GtkWidget *pBufferView;
-  GtkPaned  *pDivider;
-  GtkWindow *pMainWindow;
-  GtkWidget *pToolbar;
-  GtkSpinButton *pSpeedBox;
-  GtkWidget *pAlphabetCombo;
-  GtkWidget *pStatusControl;
-  GtkWidget *pDasherWidget;
-
-  GtkListStore *pAlphabetList;
-  GtkAccelGroup *pAccel;
-
-  // Widgets used for maemo
-#ifdef WITH_MAEMO
-  DasherMaemoHelper *pMaemoHelper;
-#ifdef WITH_MAEMOFULLSCREEN
-  HildonProgram *pProgram;
-  HildonWindow *pHWindow;
-#endif
-#endif
-
-  // Properties of the main window
-  int iWidth;
-  int iHeight;
-  bool bWidgetsInitialised;
-};
-
-typedef struct _DasherMainPrivate DasherMainPrivate;
-
-// TODO: Make sure this is actually used
-#define DASHER_MAIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), DASHER_TYPE_MAIN, DasherMainPrivate))
+#include "dasher_main_private.h"
 
 enum {
   REALIZED,
@@ -721,7 +679,6 @@ dasher_main_handle_parameter_change(DasherMain *pSelf, int iParameter) {
 #endif
   }
 
-// XXX got here with pPrivate == NULL from response_cb response_id=-5 gtkfontbutton.c 1100
   if(pPrivate->pPreferencesDialogue)
     dasher_preferences_dialogue_handle_parameter_change(pPrivate->pPreferencesDialogue, iParameter);
 
diff --git a/Src/Gtk2/dasher_main_private.h b/Src/Gtk2/dasher_main_private.h
new file mode 100644
index 0000000..aca4fa5
--- /dev/null
+++ b/Src/Gtk2/dasher_main_private.h
@@ -0,0 +1,49 @@
+#ifndef DASHER_MAIN_PRIVATE_H
+#define DASHER_MAIN_PRIVATE_H
+
+#include "dasher_main.h"
+
+struct _DasherMainPrivate {
+  GtkBuilder *pXML;
+  GtkBuilder *pPrefXML;
+
+  // Child objects owned here
+  DasherAppSettings *pAppSettings;
+  DasherPreferencesDialogue *pPreferencesDialogue;
+  DasherEditor *pEditor;
+
+  CKeyboardHelper *pKeyboardHelper;
+
+  // Various widgets which need to be cached:
+  // GtkWidget *pBufferView;
+  GtkPaned  *pDivider;
+  GtkWindow *pMainWindow;
+  GtkWidget *pToolbar;
+  GtkSpinButton *pSpeedBox;
+  GtkWidget *pAlphabetCombo;
+  GtkWidget *pStatusControl;
+  GtkWidget *pDasherWidget;
+
+  GtkListStore *pAlphabetList;
+  GtkAccelGroup *pAccel;
+
+  // Widgets used for maemo
+#ifdef WITH_MAEMO
+  DasherMaemoHelper *pMaemoHelper;
+#ifdef WITH_MAEMOFULLSCREEN
+  HildonProgram *pProgram;
+  HildonWindow *pHWindow;
+#endif
+#endif
+
+  // Properties of the main window
+  int iWidth;
+  int iHeight;
+  bool bWidgetsInitialised;
+};
+
+typedef struct _DasherMainPrivate DasherMainPrivate;
+
+#define DASHER_MAIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), DASHER_TYPE_MAIN, DasherMainPrivate))
+
+#endif


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