[dasher] Finish untangling #ifdef GNOME_A11Y spaghetti - no functional change



commit 989d3a1c2a0ffb7c350b51c547871b2b3965db88
Author: Patrick Welche <prlw1 cam ac uk>
Date:   Thu Dec 13 12:09:44 2012 +0000

    Finish untangling #ifdef GNOME_A11Y spaghetti - no functional change
    
    Create new DasherEditorExternalPrivate struct in DasherEditorPrivate.

 Src/Gtk2/dasher_editor.cpp                |    9 +---
 Src/Gtk2/dasher_editor_external.h         |    8 ++-
 Src/Gtk2/dasher_editor_external_cspi.cpp  |   70 +++++++++++++++++------------
 Src/Gtk2/dasher_editor_external_xtest.cpp |    8 ++--
 Src/Gtk2/dasher_editor_private.h          |    8 +--
 5 files changed, 54 insertions(+), 49 deletions(-)
---
diff --git a/Src/Gtk2/dasher_editor.cpp b/Src/Gtk2/dasher_editor.cpp
index e537782..54e9847 100644
--- a/Src/Gtk2/dasher_editor.cpp
+++ b/Src/Gtk2/dasher_editor.cpp
@@ -9,10 +9,6 @@
 #endif
 #include <gtk/gtk.h>
 
-#ifdef GNOME_A11Y
-#include <cspi/spi.h>
-#endif
-
 #include "dasher_editor.h"
 #include "dasher_editor_private.h"
 #include "dasher_editor_external.h"
@@ -190,10 +186,7 @@ static void
 dasher_editor_finalize(GObject *pObject) {
   DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pObject);
 
-#ifdef GNOME_A11Y
-  SPI_deregisterGlobalEventListener(pPrivate->pFocusListener, "focus:");
-  SPI_deregisterGlobalEventListener(pPrivate->pCaretListener, "object:text-caret-moved");
-#endif
+  dasher_editor_external_finalize(pObject);
 
   if(pPrivate->szFilename)
     g_free(pPrivate->szFilename);
diff --git a/Src/Gtk2/dasher_editor_external.h b/Src/Gtk2/dasher_editor_external.h
index 0b3c588..690dba6 100644
--- a/Src/Gtk2/dasher_editor_external.h
+++ b/Src/Gtk2/dasher_editor_external.h
@@ -1,11 +1,13 @@
-#ifndef __dasher_editor_external_h__
-#define __dasher_editor_external_h__
+#ifndef DASHER_EDITOR_EXTERNAL_H
+#define DASHER_EDITOR_EXTERNAL_H
 
 typedef struct _DasherEditor DasherEditor;
 struct _DasherEditor;
+typedef struct _GObject GObject;
+struct _GObject;
 
+void dasher_editor_external_finalize(GObject*);
 void dasher_editor_external_create_buffer(DasherEditor*); //  for dasher_editor_external_initialise, and calls focus bits
-/* dasher_editor_external_output just calls SPI sendText */
 void dasher_editor_external_output(DasherEditor *pSelf, const gchar *szText, int iOffset);
 void dasher_editor_external_delete(DasherEditor *pSelf, int iLength, int iOffset);
 const gchar * dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength);
diff --git a/Src/Gtk2/dasher_editor_external_cspi.cpp b/Src/Gtk2/dasher_editor_external_cspi.cpp
index d986fd9..d30fcb4 100644
--- a/Src/Gtk2/dasher_editor_external_cspi.cpp
+++ b/Src/Gtk2/dasher_editor_external_cspi.cpp
@@ -1,7 +1,3 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
@@ -16,6 +12,14 @@
 #include "dasher_main.h"
 #include "../DasherCore/ControlManager.h"
 
+typedef struct _DasherEditorExternalPrivate DasherEditorExternalPrivate;
+
+struct _DasherEditorExternalPrivate {
+  AccessibleEventListener *pFocusListener;
+  AccessibleEventListener *pCaretListener;
+  AccessibleText *pAccessibleText;
+};
+
 void dasher_editor_external_handle_focus(DasherEditor *pSelf, const AccessibleEvent *pEvent);
 void dasher_editor_external_handle_caret(DasherEditor *pSelf, const AccessibleEvent *pEvent);
 
@@ -26,7 +30,7 @@ enum {
   NOT_INIT,
   INIT_SUCCESS,
   INIT_FAIL
-}  status = NOT_INIT;
+} status = NOT_INIT;
 
 bool initSPI() {
   if (status == NOT_INIT) {
@@ -36,6 +40,14 @@ bool initSPI() {
 }
 
 void
+dasher_editor_external_finalize(GObject *pSelf) {
+  DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
+
+  SPI_deregisterGlobalEventListener(pPrivate->pExtPrivate->pFocusListener, "focus:");
+  SPI_deregisterGlobalEventListener(pPrivate->pExtPrivate->pCaretListener, "object:text-caret-moved");
+}
+
+void
 dasher_editor_external_create_buffer(DasherEditor *pSelf) {
   DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
 
@@ -43,20 +55,20 @@ dasher_editor_external_create_buffer(DasherEditor *pSelf) {
   if(!initSPI()) {
     g_message("Could not initialise SPI - accessibility options disabled");
   } else {
-    pPrivate->pFocusListener = SPI_createAccessibleEventListener(focus_listener, pSelf);
-    pPrivate->pCaretListener = SPI_createAccessibleEventListener(caret_listener, pSelf);
+    pPrivate->pExtPrivate->pFocusListener = SPI_createAccessibleEventListener(focus_listener, pSelf);
+    pPrivate->pExtPrivate->pCaretListener = SPI_createAccessibleEventListener(caret_listener, pSelf);
     
     // TODO: Need to deregister these on destruction
     
-    if(pPrivate->pFocusListener && pPrivate->pCaretListener) {
-      SPI_registerGlobalEventListener(pPrivate->pFocusListener, "focus:");
-      SPI_registerGlobalEventListener(pPrivate->pCaretListener, "object:text-caret-moved");
+    if(pPrivate->pExtPrivate->pFocusListener && pPrivate->pExtPrivate->pCaretListener) {
+      SPI_registerGlobalEventListener(pPrivate->pExtPrivate->pFocusListener, "focus:");
+      SPI_registerGlobalEventListener(pPrivate->pExtPrivate->pCaretListener, "object:text-caret-moved");
     } else {
       g_message("Could not obtain an SPI listener");
     }
   }    
 
-  pPrivate->pAccessibleText = 0;
+  pPrivate->pExtPrivate->pAccessibleText = 0;
 }
 
 void
@@ -83,8 +95,8 @@ dasher_editor_external_delete(DasherEditor *pSelf, int iLength, int iOffset) {
 const gchar *
 dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength) {
   DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
-  if(pPrivate->pAccessibleText)
-    return AccessibleText_getText(pPrivate->pAccessibleText, iOffset, iOffset + iLength);
+  if(pPrivate->pExtPrivate->pAccessibleText)
+    return AccessibleText_getText(pPrivate->pExtPrivate->pAccessibleText, iOffset, iOffset + iLength);
   else
     return "";
 }
@@ -93,12 +105,12 @@ gint
 dasher_editor_external_get_offset(DasherEditor *pSelf) {
   DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
   
-  if(!pPrivate->pAccessibleText)
+  if(!pPrivate->pExtPrivate->pAccessibleText)
     return 0;
-  if (AccessibleText_getNSelections(pPrivate->pAccessibleText)==0)
-    return AccessibleText_getCaretOffset(pPrivate->pAccessibleText);
+  if (AccessibleText_getNSelections(pPrivate->pExtPrivate->pAccessibleText)==0)
+    return AccessibleText_getCaretOffset(pPrivate->pExtPrivate->pAccessibleText);
   long int start,end;
-  AccessibleText_getSelection(pPrivate->pAccessibleText, 0, &start, &end);
+  AccessibleText_getSelection(pPrivate->pExtPrivate->pAccessibleText, 0, &start, &end);
   return std::min(start,end);
 }
 
@@ -107,9 +119,9 @@ void dasher_editor_external_handle_focus(DasherEditor *pSelf, const AccessibleEv
 
   //  g_message("Focus");
   
-  if(pPrivate->pAccessibleText) {
-    AccessibleText_unref(pPrivate->pAccessibleText);
-    pPrivate->pAccessibleText = 0;
+  if(pPrivate->pExtPrivate->pAccessibleText) {
+    AccessibleText_unref(pPrivate->pExtPrivate->pAccessibleText);
+    pPrivate->pExtPrivate->pAccessibleText = 0;
   }
   
   Accessible *accessible = pEvent->source;
@@ -120,10 +132,10 @@ void dasher_editor_external_handle_focus(DasherEditor *pSelf, const AccessibleEv
   //g_message("%s", Accessible_getDescription(accessible));
 
   if(Accessible_isText(accessible) || Accessible_isEditableText(accessible)) {
-    pPrivate->pAccessibleText = Accessible_getText(accessible);
-    AccessibleText_ref(pPrivate->pAccessibleText);
+    pPrivate->pExtPrivate->pAccessibleText = Accessible_getText(accessible);
+    AccessibleText_ref(pPrivate->pExtPrivate->pAccessibleText);
 
-//     g_iExpectedPosition = AccessibleText_getCaretOffset(pPrivate->pAccessibleText);
+//     g_iExpectedPosition = AccessibleText_getCaretOffset(pPrivate->pExtPrivate->pAccessibleText);
 //     g_iOldPosition = g_iExpectedPosition;
 
     //ACL: in old code, external_buffer emitted signal, for which the editor_external had
@@ -146,9 +158,9 @@ void dasher_editor_external_handle_caret(DasherEditor *pSelf, const AccessibleEv
 
  //  g_message("Focus");
   
-  if(pPrivate->pAccessibleText) {
-    AccessibleText_unref(pPrivate->pAccessibleText);
-    pPrivate->pAccessibleText = 0;
+  if(pPrivate->pExtPrivate->pAccessibleText) {
+    AccessibleText_unref(pPrivate->pExtPrivate->pAccessibleText);
+    pPrivate->pExtPrivate->pAccessibleText = 0;
   }
   
   Accessible *accessible = pEvent->source;
@@ -159,10 +171,10 @@ void dasher_editor_external_handle_caret(DasherEditor *pSelf, const AccessibleEv
   //g_message("%s", Accessible_getDescription(accessible));
 
   if(Accessible_isText(accessible) || Accessible_isEditableText(accessible)) {
-    pPrivate->pAccessibleText = Accessible_getText(accessible);
-    AccessibleText_ref(pPrivate->pAccessibleText);
+    pPrivate->pExtPrivate->pAccessibleText = Accessible_getText(accessible);
+    AccessibleText_ref(pPrivate->pExtPrivate->pAccessibleText);
 
-//     g_iExpectedPosition = AccessibleText_getCaretOffset(pPrivate->pAccessibleText);
+//     g_iExpectedPosition = AccessibleText_getCaretOffset(pPrivate->pExtPrivate->pAccessibleText);
 //     g_iOldPosition = g_iExpectedPosition;
 
     //ACL: in old code, dasher_external_buffer emitted offset_changed signal,
diff --git a/Src/Gtk2/dasher_editor_external_xtest.cpp b/Src/Gtk2/dasher_editor_external_xtest.cpp
index c9acc40..b5fcf30 100644
--- a/Src/Gtk2/dasher_editor_external_xtest.cpp
+++ b/Src/Gtk2/dasher_editor_external_xtest.cpp
@@ -1,7 +1,3 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
@@ -20,6 +16,10 @@
 #include "../DasherCore/ControlManager.h"
 
 void
+dasher_editor_external_finalize(GObject *pSelf) {
+}
+
+void
 dasher_editor_external_create_buffer(DasherEditor *pSelf) {
 }
 
diff --git a/Src/Gtk2/dasher_editor_private.h b/Src/Gtk2/dasher_editor_private.h
index bfdc6ca..1a1f424 100644
--- a/Src/Gtk2/dasher_editor_private.h
+++ b/Src/Gtk2/dasher_editor_private.h
@@ -6,6 +6,8 @@ typedef struct _DasherAppSettings DasherAppSettings;
 struct _DasherAppSettings;
 typedef struct _GtkDasherControl GtkDasherControl;
 struct _GtkDasherControl;
+typedef struct _DasherEditorExternalPrivate DasherEditorExternalPrivate;
+struct _DasherEditorExternalPrivate;
 
 typedef struct _DasherEditorPrivate DasherEditorPrivate;
 
@@ -29,11 +31,7 @@ struct _DasherEditorPrivate {
   gint iCurrentState; // 0 = unconverted, 1 = converted
 
   // for direct mode:
-#ifdef GNOME_A11Y
-  AccessibleEventListener *pFocusListener;
-  AccessibleEventListener *pCaretListener;
-  AccessibleText *pAccessibleText;
-#endif
+  DasherEditorExternalPrivate *pExtPrivate;
 
   //Paralleling the previous approach in dasher_main, we _don't_ send context_changed
   // events if we're in the middle of executing a control action (as this would rebuild



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