[dasher] Gtk2 Fix offset when text selected with cursor at rhs



commit 8fcdf92684be982f50548a4e782f0472ac963592
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Mon Dec 20 18:35:15 2010 +0000

    Gtk2 Fix offset when text selected with cursor at rhs
    
    (should be the beginning of the selection)
    
    dasher_internal_buffer used in "traditional" mode w/ Dasher's own edit box
    
    dasher_external_buffer used in direct mode. With --disable-a11y, this uses
      native X commands to send keypresses, which works ok, but Dasher will not
      pick up the context you are editing; with a11y enabled (=>note gdb will crash
      crazily  if you hit a breakpoint with the GUI loaded & have to be killed
      from a separate _console_!), it'll use atspi to both send keypresses and
      get the context (the only time the new code here is used); this works if
      "Enable Assistive Technologies" in System/Preferences/Assitive Technologies
      is on, but if off you'll get warnings
    
     ** (dasher:19808): WARNING **: AT_SPI_REGISTRY was not started at
     session startup.
    
     ** (dasher:19808): WARNING **: Could not locate registry
     ** Message: Could not initialise SPI - accessibility options disabled
    
      & neither keystroke-sending nor context-picking up will work.

 Src/Gtk2/dasher_external_buffer.cpp |   10 +++++++---
 Src/Gtk2/dasher_internal_buffer.cpp |    7 ++++---
 2 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/Src/Gtk2/dasher_external_buffer.cpp b/Src/Gtk2/dasher_external_buffer.cpp
index 4086515..d5e1077 100644
--- a/Src/Gtk2/dasher_external_buffer.cpp
+++ b/Src/Gtk2/dasher_external_buffer.cpp
@@ -15,6 +15,7 @@
 #endif
 
 #include <X11/keysym.h>
+#include <algorithm>
 
 #include "dasher_buffer_set.h"
 #include "dasher_external_buffer.h"
@@ -311,10 +312,13 @@ dasher_external_buffer_get_offset(DasherExternalBuffer *pSelf) {
 #ifdef GNOME_A11Y
   DasherExternalBufferPrivate *pPrivate = (DasherExternalBufferPrivate *)(pSelf->private_data);
 
-  if(pPrivate->pAccessibleText)
-    return AccessibleText_getCaretOffset(pPrivate->pAccessibleText);
-  else
+  if(!pPrivate->pAccessibleText)
     return 0;
+  if (AccessibleText_getNSelections(pPrivate->pAccessibleText)==0)
+    return AccessibleText_getCaretOffset(pPrivate->pAccessibleText);
+  long int start,end;
+  AccessibleText_getSelection(pPrivate->pAccessibleText, 0, &start, &end);
+  return std::min(start,end);
 #else
   return 0;
 #endif
diff --git a/Src/Gtk2/dasher_internal_buffer.cpp b/Src/Gtk2/dasher_internal_buffer.cpp
index 0772f99..e1d9070 100644
--- a/Src/Gtk2/dasher_internal_buffer.cpp
+++ b/Src/Gtk2/dasher_internal_buffer.cpp
@@ -372,9 +372,10 @@ void dasher_internal_buffer_clear(DasherInternalBuffer *pSelf) {
 gint dasher_internal_buffer_get_offset(DasherInternalBuffer *pSelf) {
   DasherInternalBufferPrivate *pPrivate = (DasherInternalBufferPrivate *)(pSelf->private_data);
  
-  GtkTextIter oIter;
-  gtk_text_buffer_get_iter_at_mark(pPrivate->pBuffer, &oIter, gtk_text_buffer_get_mark(pPrivate->pBuffer, "insert"));
-  return gtk_text_iter_get_offset(&oIter);
+  GtkTextIter iter1,iter2;
+  gtk_text_buffer_get_iter_at_mark(pPrivate->pBuffer, &iter1, gtk_text_buffer_get_insert(pPrivate->pBuffer));
+  gtk_text_buffer_get_iter_at_mark(pPrivate->pBuffer, &iter2, gtk_text_buffer_get_selection_bound(pPrivate->pBuffer));
+  return std::min(gtk_text_iter_get_offset(&iter1),gtk_text_iter_get_offset(&iter2));
 }
 
 



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