Ticket #4134: 0001-Implement-OSK-resizing-on-the-AbiWidget.patch

File 0001-Implement-OSK-resizing-on-the-AbiWidget.patch, 3.1 KB (added by garnacho, 11 years ago)

Write patch, implement OSK resize in a subclass of Abi.Widget

  • AbiWordActivity.py

    From a318634d324e6047e6803b5bc4817906eb422fe3 Mon Sep 17 00:00:00 2001
    From: Carlos Garnacho <carlosg@gnome.org>
    Date: Wed, 21 Nov 2012 16:10:42 +0100
    Subject: [PATCH] Implement OSK resizing on the AbiWidget
    
    A new class deriving from Abi.Widget has been added, this class
    handles document view resizing, and ensures the cursor stays
    visible after the resize.
    ---
     AbiWordActivity.py |  3 ++-
     widgets.py         | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
     2 files changed, 54 insertions(+), 1 deletion(-)
    
    diff --git a/AbiWordActivity.py b/AbiWordActivity.py
    index ccfec0e..8c75cd2 100644
    a b from toolbar import ListToolbar 
    4848from toolbar import InsertToolbar
    4949from toolbar import ParagraphToolbar
    5050from widgets import ExportButtonFactory
     51from widgets import DocumentView
    5152from port import chooser
    5253
    5354import speech
    class AbiWordActivity(activity.Activity): 
    6566        os.chdir(os.path.expanduser('~'))
    6667
    6768        # create our main abiword canvas
    68         self.abiword_canvas = Abi.Widget()
     69        self.abiword_canvas = DocumentView()
    6970        self._shared_activity = None
    7071        self._new_instance = True
    7172        toolbar_box = ToolbarBox()
  • widgets.py

    diff --git a/widgets.py b/widgets.py
    index b4c68f8..4514c1f 100644
    a b class ExportButtonFactory(): 
    247247        datastore.write(fileObject, transfer_ownership=True)
    248248        fileObject.destroy()
    249249        del fileObject
     250
     251class DocumentView(Abi.Widget):
     252  def __init__(self):
     253    Abi.Widget.__init__(self)
     254    self.connect ('size-allocate', self.__size_allocate_cb)
     255    self.connect ('request-clear-area', self.__request_clear_area_cb)
     256    self.connect ('unset-clear-area', self.__unset_clear_area_cb)
     257    self.osk_changed = False
     258    self.dy = 0
     259
     260  def __shallow_move_cb(self):
     261    self.moveto_right()
     262    return False
     263
     264  def __size_allocate_cb(self, widget, allocation):
     265    self.set_allocation(allocation)
     266
     267    if self.get_child() is not None:
     268      child_allocation = allocation
     269      child_allocation.y = 0
     270      child_allocation.x = 0
     271      child_allocation.height -= self.dy
     272      self.get_child().size_allocate(allocation)
     273
     274    if self.osk_changed is True:
     275      self.moveto_left()
     276      GLib.timeout_add(100, self.__shallow_move_cb)
     277      self.osk_changed = False
     278
     279  def __request_clear_area_cb(self, widget, clear, cursor):
     280    allocation = widget.get_allocation()
     281    allocation.x, allocation.y = widget.get_window().get_root_coords(allocation.x, allocation.y)
     282
     283    if clear.y > allocation.y + allocation.height or \
     284          clear.y + clear.height < allocation.y:
     285      return False
     286
     287    self.dy = allocation.y + allocation.height - clear.y - 32
     288
     289    # Ensure there's at least some room for the view
     290    if self.dy > allocation.height - 80:
     291      self.dy = 0
     292      return False
     293
     294    self.osk_changed = True
     295    self.queue_resize()
     296    return True
     297
     298  def __unset_clear_area_cb (self, widget, snap_back):
     299    self.dy = 0
     300    self.queue_resize()
     301    return True