[dasher] Untangle some #ifdef GNOME_A11Y spaghetti - no functional change
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher] Untangle some #ifdef GNOME_A11Y spaghetti - no functional change
- Date: Fri, 14 Dec 2012 00:08:27 +0000 (UTC)
commit 24db5c02b2e8ebc13160bb62cfa5f513ccdb0663
Author: Patrick Welche <prlw1 cam ac uk>
Date: Wed Dec 12 00:41:03 2012 +0000
Untangle some #ifdef GNOME_A11Y spaghetti - no functional change
- Split dasher_editor_external.cpp into dasher_editor_external_{cspi,xtest}.cpp
- Remove DasherSpi.{h,cpp} as they just provided sendText which was all
that dasher_editor_external_output called, and merge into
dasher_editor_external_*.cpp
Src/Gtk2/DasherSpi.h | 14 ----
Src/Gtk2/Makefile.am | 11 ++-
...xternal.cpp => dasher_editor_external_cspi.cpp} | 61 ++++++----------
...herSpi.cpp => dasher_editor_external_xtest.cpp} | 75 +++++++++++---------
4 files changed, 74 insertions(+), 87 deletions(-)
---
diff --git a/Src/Gtk2/Makefile.am b/Src/Gtk2/Makefile.am
index eb9198c..0f904e2 100644
--- a/Src/Gtk2/Makefile.am
+++ b/Src/Gtk2/Makefile.am
@@ -71,10 +71,7 @@ libdashergtk_la_SOURCES = \
Preferences.cpp \
Preferences.h \
dasher.h \
- DasherSpi.h \
- DasherSpi.cpp \
dasher_editor_external.h \
- dasher_editor_external.cpp \
dasher_editor_private.h \
dasher_editor.cpp \
dasher_editor.h \
@@ -85,4 +82,12 @@ libdashergtk_la_SOURCES = \
module_settings_window.cpp \
module_settings_window.h
+if GNOME_A11Y
+libdashergtk_la_SOURCES += \
+ dasher_editor_external_cspi.cpp
+else
+libdashergtk_la_SOURCES += \
+ dasher_editor_external_xtest.cpp
+endif
+
AM_CXXFLAGS = -I$(srcdir)/../DasherCore -DPROGDATA=\"$(pkgdatadir)\" $(GTKBUILD_CFLAGS)
diff --git a/Src/Gtk2/dasher_editor_external.cpp b/Src/Gtk2/dasher_editor_external_cspi.cpp
similarity index 90%
rename from Src/Gtk2/dasher_editor_external.cpp
rename to Src/Gtk2/dasher_editor_external_cspi.cpp
index 2416e5f..d986fd9 100644
--- a/Src/Gtk2/dasher_editor_external.cpp
+++ b/Src/Gtk2/dasher_editor_external_cspi.cpp
@@ -5,14 +5,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#ifdef GNOME_A11Y
#include <cspi/spi.h>
-#else
-#include <X11/X.h>
-#include <X11/Xlib.h>
-#include <X11/extensions/XTest.h>
-#include <gdk/gdkx.h>
-#endif
#include <X11/keysym.h>
#include <algorithm>
@@ -22,21 +15,30 @@
#include "dasher_lock_dialogue.h"
#include "dasher_main.h"
#include "../DasherCore/ControlManager.h"
-#include "DasherSpi.h"
-#ifdef GNOME_A11Y
void dasher_editor_external_handle_focus(DasherEditor *pSelf, const AccessibleEvent *pEvent);
void dasher_editor_external_handle_caret(DasherEditor *pSelf, const AccessibleEvent *pEvent);
void focus_listener(const AccessibleEvent *pEvent, void *pUserData);
void caret_listener(const AccessibleEvent *pEvent, void *pUserData);
-#endif
+
+enum {
+ NOT_INIT,
+ INIT_SUCCESS,
+ INIT_FAIL
+} status = NOT_INIT;
+
+bool initSPI() {
+ if (status == NOT_INIT) {
+ status = (SPI_init()==2) ? INIT_FAIL : INIT_SUCCESS;
+ }
+ return (status==INIT_SUCCESS);
+}
void
dasher_editor_external_create_buffer(DasherEditor *pSelf) {
DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
-#ifdef GNOME_A11Y
if(!initSPI()) {
g_message("Could not initialise SPI - accessibility options disabled");
@@ -55,49 +57,40 @@ dasher_editor_external_create_buffer(DasherEditor *pSelf) {
}
pPrivate->pAccessibleText = 0;
-#endif
}
void
-dasher_editor_external_output(DasherEditor *pSelf, const gchar *szText, int iOffset) {
- sendText(szText);
+dasher_editor_external_output(DasherEditor *pSelf, const gchar *szText, int iOffset /* unused */) {
+ if(!initSPI())
+ return;
+
+ char *szNewText;
+ szNewText = new char[strlen(szText) + 1];
+ strcpy(szNewText, szText);
+
+ SPI_generateKeyboardEvent(0, szNewText, SPI_KEY_STRING);
+
+ delete[] szNewText;
}
void
dasher_editor_external_delete(DasherEditor *pSelf, int iLength, int iOffset) {
-#ifdef GNOME_A11Y
if(!initSPI()) return;
SPI_generateKeyboardEvent(XK_BackSpace, NULL, SPI_KEY_SYM);
-#else
- Display *dpy;
- dpy = gdk_x11_get_default_xdisplay();
- KeyCode code;
- code = XKeysymToKeycode(dpy, XK_BackSpace);
- for(int i = 0; i < iLength; i++) {
- XTestFakeKeyEvent(dpy, code, True, 0);
- XTestFakeKeyEvent(dpy, code, False, 0);
- }
- XFlush(dpy);
-#endif
}
const gchar *
dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength) {
-#ifdef GNOME_A11Y
DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
if(pPrivate->pAccessibleText)
return AccessibleText_getText(pPrivate->pAccessibleText, iOffset, iOffset + iLength);
else
return "";
-#else
- return "";
-#endif
}
gint
dasher_editor_external_get_offset(DasherEditor *pSelf) {
-#ifdef GNOME_A11Y
DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
if(!pPrivate->pAccessibleText)
@@ -107,12 +100,8 @@ dasher_editor_external_get_offset(DasherEditor *pSelf) {
long int start,end;
AccessibleText_getSelection(pPrivate->pAccessibleText, 0, &start, &end);
return std::min(start,end);
-#else
- return 0;
-#endif
}
-#ifdef GNOME_A11Y
void dasher_editor_external_handle_focus(DasherEditor *pSelf, const AccessibleEvent *pEvent) {
DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
@@ -217,5 +206,3 @@ void focus_listener(const AccessibleEvent *pEvent, void *pUserData) {
void caret_listener(const AccessibleEvent *pEvent, void *pUserData) {
dasher_editor_external_handle_caret((DasherEditor *)pUserData, pEvent);
}
-
-#endif
diff --git a/Src/Gtk2/DasherSpi.cpp b/Src/Gtk2/dasher_editor_external_xtest.cpp
similarity index 68%
rename from Src/Gtk2/DasherSpi.cpp
rename to Src/Gtk2/dasher_editor_external_xtest.cpp
index 8517038..c9acc40 100644
--- a/Src/Gtk2/DasherSpi.cpp
+++ b/Src/Gtk2/dasher_editor_external_xtest.cpp
@@ -1,43 +1,30 @@
-#include "DasherSpi.h"
-
-#ifdef GNOME_A11Y
-
-#include <cspi/spi.h>
-#include <string.h>
-
-enum {
- NOT_INIT,
- INIT_SUCCESS,
- INIT_FAIL
-} status = NOT_INIT;
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
-bool initSPI() {
- if (status == NOT_INIT) {
- status = (SPI_init()==2) ? INIT_FAIL : INIT_SUCCESS;
- }
- return (status==INIT_SUCCESS);
-}
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
-#else
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <gdk/gdkx.h>
-#endif
-void sendText(const char *szText) {
-#ifdef GNOME_A11Y
- if(!initSPI())
- return;
+#include <X11/keysym.h>
+#include <algorithm>
- char *szNewText;
- szNewText = new char[strlen(szText) + 1];
- strcpy(szNewText, szText);
-
- SPI_generateKeyboardEvent(0, szNewText, SPI_KEY_STRING);
-
- delete[] szNewText;
-#else
+#include "dasher_editor_external.h"
+#include "dasher_editor_private.h"
+#include "dasher_lock_dialogue.h"
+#include "dasher_main.h"
+#include "../DasherCore/ControlManager.h"
+
+void
+dasher_editor_external_create_buffer(DasherEditor *pSelf) {
+}
+
+void
+dasher_editor_external_output(DasherEditor *pSelf, const gchar *szText, int iOffset /* unused */) {
glong numoutput;
int numcodes;
Display *dpy = gdk_x11_get_default_xdisplay();
@@ -103,5 +90,27 @@ void sendText(const char *szText) {
XSync(dpy, true);
g_free(wideoutput);
}
-#endif
+}
+
+void
+dasher_editor_external_delete(DasherEditor *pSelf, int iLength, int iOffset) {
+ Display *dpy;
+ dpy = gdk_x11_get_default_xdisplay();
+ KeyCode code;
+ code = XKeysymToKeycode(dpy, XK_BackSpace);
+ for(int i = 0; i < iLength; i++) {
+ XTestFakeKeyEvent(dpy, code, True, 0);
+ XTestFakeKeyEvent(dpy, code, False, 0);
+ }
+ XFlush(dpy);
+}
+
+const gchar *
+dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength) {
+ return "";
+}
+
+gint
+dasher_editor_external_get_offset(DasherEditor *pSelf) {
+ return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]