[dasher] Give GtkDasherControl a pointer to DasherEditor => stop using g_pDasherMain
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher] Give GtkDasherControl a pointer to DasherEditor => stop using g_pDasherMain
- Date: Tue, 22 Mar 2011 21:23:03 +0000 (UTC)
commit 4674caf994fecdebb4aa02245052a20f41df7c02
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Tue Mar 15 23:03:35 2011 +0000
Give GtkDasherControl a pointer to DasherEditor => stop using g_pDasherMain
(dasher_main_get_all_text replaced by dasher_control_get_all_text)
required fixing cycle GtkDasherControl.h includes DasherEditor.h includes
DasherAppSettings.h includes GtkDasherControl.h, all replaced with fwd decls,
but some fallout in other headers.
Src/Gtk2/DasherAppSettings.cpp | 63 ++++++++++++++--------------------
Src/Gtk2/DasherAppSettings.h | 6 +++-
Src/Gtk2/DasherControl.cpp | 3 +-
Src/Gtk2/GtkDasherControl.cpp | 17 +++++++++-
Src/Gtk2/GtkDasherControl.h | 6 +++
Src/Gtk2/KeyboardHelper.cpp | 3 ++
Src/Gtk2/Preferences.cpp | 1 +
Src/Gtk2/dasher_action_keyboard.cpp | 2 +-
Src/Gtk2/dasher_action_script.cpp | 1 +
Src/Gtk2/dasher_editor.h | 3 +-
Src/Gtk2/dasher_editor_external.cpp | 1 +
Src/Gtk2/dasher_editor_internal.cpp | 1 +
Src/Gtk2/dasher_main.cpp | 9 +----
Src/Gtk2/dasher_main.h | 1 -
14 files changed, 66 insertions(+), 51 deletions(-)
---
diff --git a/Src/Gtk2/DasherAppSettings.cpp b/Src/Gtk2/DasherAppSettings.cpp
index f27792d..2d390ff 100644
--- a/Src/Gtk2/DasherAppSettings.cpp
+++ b/Src/Gtk2/DasherAppSettings.cpp
@@ -23,17 +23,12 @@
// TODO: Rename this file to fit in with naming conventions
-// TODO: Bring this into the widget
-static GtkWidget *pDasherWidget = NULL;
-
-
struct _DasherAppSettingsPrivate {
#ifdef WITH_GCONF
// GConf interface
GConfClient *pGConfClient;
#endif
- GtkDasherControl *pWidget;
- gboolean bWidgetSet;
+ GtkDasherControl *pDasherWidget;
};
typedef struct _DasherAppSettingsPrivate DasherAppSettingsPrivate;
@@ -86,8 +81,7 @@ static void dasher_app_settings_init(DasherAppSettings *pDasherControl) {
#ifdef WITH_GCONF
pPrivate->pGConfClient = NULL;
#endif
- pPrivate->pWidget = NULL;
- pPrivate->bWidgetSet = FALSE;
+ pPrivate->pDasherWidget = NULL;
}
static void dasher_app_settings_destroy(GObject *pObject) {
@@ -106,15 +100,6 @@ static void dasher_app_settings_destroy(GObject *pObject) {
// of the parent classes here...
}
-void dasher_app_settings_set_widget(DasherAppSettings *pSelf, GtkDasherControl *pWidget) {
- DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
-
- pDasherWidget = GTK_WIDGET(pWidget);
-
- pPrivate->pWidget = pWidget;
- pPrivate->bWidgetSet = TRUE;
-}
-
static void dasher_app_settings_init_gconf(DasherAppSettings *pSelf, int argc, char **argv) {
#ifdef WITH_GCONF
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
@@ -227,8 +212,8 @@ void dasher_app_settings_reset(DasherAppSettings *pSelf, int iParameter) {
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
if(iParameter < END_OF_SPS) {
- if(pPrivate->bWidgetSet)
- gtk_dasher_control_reset_parameter(GTK_DASHER_CONTROL(pDasherWidget), iParameter);
+ if(pPrivate->pDasherWidget)
+ gtk_dasher_control_reset_parameter(pPrivate->pDasherWidget, iParameter);
return;
}
else {
@@ -254,8 +239,8 @@ void dasher_app_settings_reset(DasherAppSettings *pSelf, int iParameter) {
bool dasher_app_settings_get_bool(DasherAppSettings *pSelf, int iParameter) {
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
if( iParameter < END_OF_BPS ) {
- if(pPrivate->bWidgetSet)
- return gtk_dasher_control_get_parameter_bool(GTK_DASHER_CONTROL(pDasherWidget), iParameter);
+ if(pPrivate->pDasherWidget)
+ return gtk_dasher_control_get_parameter_bool(pPrivate->pDasherWidget, iParameter);
else
return false;
}
@@ -267,8 +252,8 @@ void dasher_app_settings_set_bool(DasherAppSettings *pSelf, int iParameter, bool
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
if( iParameter < END_OF_BPS ) {
- if(pPrivate->bWidgetSet) {
- gtk_dasher_control_set_parameter_bool(GTK_DASHER_CONTROL(pDasherWidget), iParameter, bValue);
+ if(pPrivate->pDasherWidget) {
+ gtk_dasher_control_set_parameter_bool(pPrivate->pDasherWidget, iParameter, bValue);
}
}
else {
@@ -300,8 +285,8 @@ gint dasher_app_settings_get_long(DasherAppSettings *pSelf, int iParameter) {
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
if( iParameter < END_OF_LPS) {
- if(pPrivate->bWidgetSet)
- return gtk_dasher_control_get_parameter_long(GTK_DASHER_CONTROL(pDasherWidget), iParameter);
+ if(pPrivate->pDasherWidget)
+ return gtk_dasher_control_get_parameter_long(pPrivate->pDasherWidget, iParameter);
else
return false;
}
@@ -313,8 +298,8 @@ void dasher_app_settings_set_long(DasherAppSettings *pSelf, int iParameter, gint
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
if( iParameter < END_OF_LPS) {
- if(pPrivate->bWidgetSet)
- gtk_dasher_control_set_parameter_long(GTK_DASHER_CONTROL(pDasherWidget), iParameter, iValue);
+ if(pPrivate->pDasherWidget)
+ gtk_dasher_control_set_parameter_long(pPrivate->pDasherWidget, iParameter, iValue);
}
else {
if(dasher_app_settings_get_long(pSelf, iParameter) == iValue)
@@ -386,8 +371,8 @@ const gchar *dasher_app_settings_get_string(DasherAppSettings *pSelf, int iParam
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
if( iParameter < END_OF_SPS ) {
- if(pPrivate->bWidgetSet)
- return gtk_dasher_control_get_parameter_string(GTK_DASHER_CONTROL(pDasherWidget), iParameter);
+ if(pPrivate->pDasherWidget)
+ return gtk_dasher_control_get_parameter_string(pPrivate->pDasherWidget, iParameter);
else
return false;
}
@@ -399,8 +384,8 @@ void dasher_app_settings_set_string(DasherAppSettings *pSelf, int iParameter, co
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
if( iParameter < END_OF_SPS ) {
- if(pPrivate->bWidgetSet)
- gtk_dasher_control_set_parameter_string(GTK_DASHER_CONTROL(pDasherWidget), iParameter, szValue);
+ if(pPrivate->pDasherWidget)
+ gtk_dasher_control_set_parameter_string(pPrivate->pDasherWidget, iParameter, szValue);
}
else {
if(!strcmp(dasher_app_settings_get_string(pSelf, iParameter), szValue))
@@ -500,16 +485,20 @@ void dasher_app_settings_launch_advanced(DasherAppSettings *pSelf) {
}
}
-void dasher_app_settings_set_widget(DasherAppSettings *pSelf, GtkWidget *pWidget) {
- pDasherWidget = pWidget;
+void dasher_app_settings_set_widget(DasherAppSettings *pSelf, GtkDasherControl *pWidget) {
+ DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
+
+ pPrivate->pDasherWidget = pWidget;
}
GArray *dasher_app_settings_get_allowed_values(DasherAppSettings *pSelf, int iParameter) {
- return gtk_dasher_control_get_allowed_values(GTK_DASHER_CONTROL(pDasherWidget), iParameter);
+ DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
+ return gtk_dasher_control_get_allowed_values(pPrivate->pDasherWidget, iParameter);
}
gboolean dasher_app_settings_get_module_settings(DasherAppSettings *pSelf, const gchar *szValue, SModuleSettings **pSettings, gint *iCount) {
- return gtk_dasher_control_get_module_settings(GTK_DASHER_CONTROL(pDasherWidget), szValue, pSettings, iCount);
+ DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
+ return gtk_dasher_control_get_module_settings(pPrivate->pDasherWidget, szValue, pSettings, iCount);
}
// Set the option szKey to szValue. Return NULL if everything worked, a
@@ -543,8 +532,8 @@ dasher_app_settings_cl_set(DasherAppSettings *pSelf, const gchar *szKey, const g
return 0;
}
}
-
- return gtk_dasher_control_cl_set(GTK_DASHER_CONTROL(pDasherWidget), szKey, szValue);
+ DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
+ return gtk_dasher_control_cl_set(pPrivate->pDasherWidget, szKey, szValue);
}
diff --git a/Src/Gtk2/DasherAppSettings.h b/Src/Gtk2/DasherAppSettings.h
index 2c5740a..44a2f3b 100644
--- a/Src/Gtk2/DasherAppSettings.h
+++ b/Src/Gtk2/DasherAppSettings.h
@@ -6,7 +6,11 @@
#include "../DasherCore/Parameters.h"
#include "../Common/AppSettingsHeader.h"
-#include "GtkDasherControl.h"
+#include "../Common/ModuleSettings.h"
+
+/*Forward declaration*/
+typedef struct _GtkDasherControl GtkDasherControl;
+struct _GtkDasherControl;
// Define first int value of the first element of each type.
// Useful for offsetting into specific arrays,
diff --git a/Src/Gtk2/DasherControl.cpp b/Src/Gtk2/DasherControl.cpp
index 942aa0b..f22e778 100644
--- a/Src/Gtk2/DasherControl.cpp
+++ b/Src/Gtk2/DasherControl.cpp
@@ -191,9 +191,8 @@ void CDasherControl::ScanColourFiles(std::vector<std::string> &vFileList) {
g_pattern_spec_free(colourglob);
}
-extern DasherMain *g_pDasherMain;
std::string CDasherControl::GetAllContext() {
- const gchar *text = dasher_main_get_all_text(g_pDasherMain);
+ const gchar *text = gtk_dasher_control_get_all_text(m_pDasherControl);
return text;
}
diff --git a/Src/Gtk2/GtkDasherControl.cpp b/Src/Gtk2/GtkDasherControl.cpp
index 94778e1..266538d 100644
--- a/Src/Gtk2/GtkDasherControl.cpp
+++ b/Src/Gtk2/GtkDasherControl.cpp
@@ -24,11 +24,12 @@
#include "GtkDasherControl.h"
#include "custom_marshal.h"
#include "game_mode_helper.h"
-
+#include "dasher_editor.h"
#include <gtk/gtkmarshal.h>
struct _GtkDasherControlPrivate {
CDasherControl *pControl;
+ DasherEditor *pEditor;
void* pGameHelper;
};
@@ -122,6 +123,14 @@ gtk_dasher_control_init(GtkDasherControl *pDasherControl) {
// g_signal_connect(G_OBJECT(pDasherControl), "key-release-event", G_CALLBACK(gtk_dasher_control_default_key_release_handler), pPrivate->pControl);
}
+void gtk_dasher_control_set_editor(GtkDasherControl *pDasherControl, DasherEditor *pEditor) {
+ GtkDasherControlPrivate *pPrivate = GTK_DASHER_CONTROL_GET_PRIVATE(pDasherControl);
+
+ DASHER_ASSERT (pPrivate->pEditor == NULL);
+ DASHER_ASSERT (pEditor != NULL);
+ pPrivate->pEditor = pEditor;
+}
+
static void
gtk_dasher_control_finalize(GObject *pObject) {
GtkDasherControl *pDasherControl = GTK_DASHER_CONTROL(pObject);
@@ -203,6 +212,12 @@ gtk_dasher_control_set_context(GtkDasherControl *pControl, const gchar *szContex
pPrivate->pControl->SetContext(szContext);
}
+const gchar *
+gtk_dasher_control_get_all_text(GtkDasherControl *pControl) {
+ GtkDasherControlPrivate *pPrivate = GTK_DASHER_CONTROL_GET_PRIVATE(pControl);
+ return dasher_editor_get_all_text(pPrivate->pEditor);
+}
+
void
gtk_dasher_control_set_buffer(GtkDasherControl *pControl, int iOffset) {
GtkDasherControlPrivate *pPrivate = GTK_DASHER_CONTROL_GET_PRIVATE(pControl);
diff --git a/Src/Gtk2/GtkDasherControl.h b/Src/Gtk2/GtkDasherControl.h
index 3856c79..40224b2 100644
--- a/Src/Gtk2/GtkDasherControl.h
+++ b/Src/Gtk2/GtkDasherControl.h
@@ -7,6 +7,10 @@
#include "Parameters.h"
#include "ControlManager.h"
+/*Forward declaration*/
+typedef struct _DasherEditor DasherEditor;
+struct _DasherEditor;
+
typedef struct _DasherLockInfo DasherLockInfo;
struct _DasherLockInfo {
@@ -75,6 +79,8 @@ const char *gtk_dasher_control_get_parameter_string(GtkDasherControl * pControl,
GArray *gtk_dasher_control_get_allowed_values(GtkDasherControl * pControl, int iParameter);
void gtk_dasher_control_train(GtkDasherControl * pControl, const gchar * szFilename);
void gtk_dasher_control_set_context(GtkDasherControl *pControl, const gchar *szContext);
+void gtk_dasher_control_set_editor(GtkDasherControl *pControl, DasherEditor *pEditor);
+const gchar* gtk_dasher_control_get_all_text(GtkDasherControl *pControl);
//void gtk_dasher_control_invalidate_context(GtkDasherControl *pControl, bool bForceStart);
void gtk_dasher_control_set_buffer(GtkDasherControl *pControl, int iOffset);
void gtk_dasher_control_set_offset(GtkDasherControl *pControl, int iOffset);
diff --git a/Src/Gtk2/KeyboardHelper.cpp b/Src/Gtk2/KeyboardHelper.cpp
index 937db58..53ccb1d 100644
--- a/Src/Gtk2/KeyboardHelper.cpp
+++ b/Src/Gtk2/KeyboardHelper.cpp
@@ -9,6 +9,9 @@
#include <sstream>
#include <string>
+using namespace std;
+#include <stdlib.h>
+
CKeyboardHelper::CKeyboardHelper(DasherAppSettings *pAppSettings) {
m_pAppSettings = pAppSettings;
diff --git a/Src/Gtk2/Preferences.cpp b/Src/Gtk2/Preferences.cpp
index 1410ef7..73d577a 100644
--- a/Src/Gtk2/Preferences.cpp
+++ b/Src/Gtk2/Preferences.cpp
@@ -5,6 +5,7 @@
#include <glib/gi18n.h>
#include <libintl.h>
#include <cstring>
+#include <math.h>
#include "../Common/Common.h"
#include "DasherTypes.h"
diff --git a/Src/Gtk2/dasher_action_keyboard.cpp b/Src/Gtk2/dasher_action_keyboard.cpp
index 13c8248..e5ad3cd 100644
--- a/Src/Gtk2/dasher_action_keyboard.cpp
+++ b/Src/Gtk2/dasher_action_keyboard.cpp
@@ -1,9 +1,9 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "../Common/Common.h"
#include "dasher_action_keyboard.h"
#include "dasher_editor.h"
-
#include <string.h>
struct _DasherActionKeyboardPrivate {
diff --git a/Src/Gtk2/dasher_action_script.cpp b/Src/Gtk2/dasher_action_script.cpp
index 11ae9dc..f3d639e 100644
--- a/Src/Gtk2/dasher_action_script.cpp
+++ b/Src/Gtk2/dasher_action_script.cpp
@@ -1,3 +1,4 @@
+#include "../Common/Common.h"
#include "dasher_action_script.h"
#include "dasher_editor.h"
diff --git a/Src/Gtk2/dasher_editor.h b/Src/Gtk2/dasher_editor.h
index a86eefa..767dab6 100644
--- a/Src/Gtk2/dasher_editor.h
+++ b/Src/Gtk2/dasher_editor.h
@@ -5,13 +5,14 @@
#include <glib-object.h>
#include <gtk/gtk.h>
-#include "DasherAppSettings.h"
#include "dasher_action.h"
#include "dasher_buffer_set.h"
/* Forward declaration */
typedef struct _DasherMain DasherMain;
struct _DasherMain;
+typedef struct _DasherAppSettings DasherAppSettings;
+struct _DasherAppSettings;
G_BEGIN_DECLS
#define DASHER_TYPE_EDITOR (dasher_editor_get_type())
diff --git a/Src/Gtk2/dasher_editor_external.cpp b/Src/Gtk2/dasher_editor_external.cpp
index 51088db..0b364de 100644
--- a/Src/Gtk2/dasher_editor_external.cpp
+++ b/Src/Gtk2/dasher_editor_external.cpp
@@ -9,6 +9,7 @@
#include "dasher_external_buffer.h"
#include "dasher_lock_dialogue.h"
#include "dasher_main.h"
+#include "../DasherCore/ControlManager.h"
//#include "game_mode_helper.h"
typedef struct _DasherEditorExternalPrivate DasherEditorExternalPrivate;
diff --git a/Src/Gtk2/dasher_editor_internal.cpp b/Src/Gtk2/dasher_editor_internal.cpp
index 87082a7..b90f5a5 100644
--- a/Src/Gtk2/dasher_editor_internal.cpp
+++ b/Src/Gtk2/dasher_editor_internal.cpp
@@ -25,6 +25,7 @@
#include "dasher_internal_buffer.h"
#include "dasher_lock_dialogue.h"
#include "dasher_main.h"
+#include "../DasherCore/ControlManager.h"
//#include "game_mode_helper.h"
// TODO: Maybe reimplement something along the lines of the following, which used to be in edit.cc
diff --git a/Src/Gtk2/dasher_main.cpp b/Src/Gtk2/dasher_main.cpp
index dfcfb41..4c66541 100644
--- a/Src/Gtk2/dasher_main.cpp
+++ b/Src/Gtk2/dasher_main.cpp
@@ -453,6 +453,8 @@ dasher_main_load_interface(DasherMain *pSelf) {
pPrivate->pToolbar = GTK_WIDGET(gtk_builder_get_object(pPrivate->pXML, "dasher_tool_bar"));
// pPrivate->pMenuBar = gtk_builder_get_object(pPrivate->pXML, "dasher_menu_bar");
pPrivate->pDasherWidget = GTK_WIDGET(gtk_builder_get_object(pPrivate->pXML, "DasherControl"));
+ pPrivate->pEditor = DASHER_EDITOR(gtk_builder_get_object(pPrivate->pXML, "DasherEditor"));
+ gtk_dasher_control_set_editor(GTK_DASHER_CONTROL(pPrivate->pDasherWidget), pPrivate->pEditor);
#ifndef WITH_MAEMO
pPrivate->pSpeedBox = GTK_SPIN_BUTTON(gtk_builder_get_object(pPrivate->pXML, "spinbutton1"));
@@ -587,7 +589,6 @@ dasher_main_load_interface(DasherMain *pSelf) {
gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object(pPrivate->pXML, "separatortoolitem2")));
}
- pPrivate->pEditor = DASHER_EDITOR(gtk_builder_get_object(pPrivate->pXML, "DasherEditor"));
// TODO: szFullPath
pPrivate->bWidgetsInitialised = true;
}
@@ -598,12 +599,6 @@ dasher_main_create_preferences(DasherMain *pSelf) {
pPrivate->pPreferencesDialogue = dasher_preferences_dialogue_new(pPrivate->pPrefXML, pPrivate->pEditor, pPrivate->pAppSettings, pPrivate->pMainWindow);
}
-const gchar *
-dasher_main_get_all_text(DasherMain *pSelf) {
- DasherMainPrivate *pPrivate = DASHER_MAIN_GET_PRIVATE(pSelf);
- return dasher_editor_get_all_text(pPrivate->pEditor);
-}
-
static void
dasher_main_handle_parameter_change(DasherMain *pSelf, int iParameter) {
DasherMainPrivate *pPrivate = DASHER_MAIN_GET_PRIVATE(pSelf);
diff --git a/Src/Gtk2/dasher_main.h b/Src/Gtk2/dasher_main.h
index 02a345b..23e567c 100644
--- a/Src/Gtk2/dasher_main.h
+++ b/Src/Gtk2/dasher_main.h
@@ -36,7 +36,6 @@ struct _SCommandLine {
DasherMain *dasher_main_new(int *argc, char ***argv, SCommandLine *pCommandLine);
GType dasher_main_get_type();
-const gchar *dasher_main_get_all_text(DasherMain *pSelf);
void dasher_main_show(DasherMain *pSelf);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]