Ticket #3921: 0001-GtkMenu-use-point_in_cell_renderer-for-CellRendereIn.patch

File 0001-GtkMenu-use-point_in_cell_renderer-for-CellRendereIn.patch, 3.4 KB (added by erikos, 12 years ago)

GtkMenu: use point_in_cell_renderer for CellRendereInvoker to check if a point is in

  • src/sugar3/graphics/palettewindow.py

    From e62b3ae80c3a650d705e8ee3db86c7f3cf75e80f Mon Sep 17 00:00:00 2001
    From: Simon Schampijer <simon@laptop.org>
    Date: Tue, 30 Oct 2012 09:30:31 +0100
    Subject: [PATCH toolkit-gtk3] GtkMenu: use point_in_cell_renderer for
     CellRendereInvoker to check if a point is in,
     part of SL #3921
    
    We use get_rect to check if the mouse is still over the invoker
    in order to know when to popdown the Palette. The CellRendererInvoker
    did return the allocation of the TreeView so far.
    
    We already have a point_in_cell_renderer method in the
    CellRendererInvoker so we can use this to check if the mouse pointer
    is over the cell or not. The method point_in_cell_renderer is made
    public to make it clearer that it can be used from the outside.
    
    Signed-off-by: Simon Schampijer <simon@laptop.org>
    ---
     src/sugar3/graphics/palettewindow.py | 19 ++++++++++++-------
     1 file changed, 12 insertions(+), 7 deletions(-)
    
    diff --git a/src/sugar3/graphics/palettewindow.py b/src/sugar3/graphics/palettewindow.py
    index 0407bfc..6e33efe 100644
    a b class _PaletteMenuWidget(Gtk.Menu): 
    205205        return False
    206206
    207207    def _motion_notify_cb(self, widget, event):
    208         rect = self._invoker.get_rect()
    209208        x = event.x_root
    210209        y = event.y_root
    211         in_invoker = x >= rect.x and x < (rect.x + rect.width) \
    212             and y >= rect.y and y < (rect.y + rect.height)
     210
     211        if type(self._invoker) is CellRendererInvoker:
     212            in_invoker = self._invoker.point_in_cell_renderer(x, y)
     213        else:
     214            rect = self._invoker.get_rect()
     215            in_invoker = x >= rect.x and x < (rect.x + rect.width) \
     216                and y >= rect.y and y < (rect.y + rect.height)
     217
    213218        if in_invoker != self._mouse_in_invoker:
    214219            self._mouse_in_invoker = in_invoker
    215220            self._reevaluate_state()
    class CellRendererInvoker(Invoker): 
    12561261    def __motion_notify_event_cb(self, widget, event):
    12571262        if event.window != widget.get_bin_window():
    12581263            return
    1259         if self._point_in_cell_renderer(event.x, event.y):
     1264        if self.point_in_cell_renderer(event.x, event.y):
    12601265
    12611266            tree_view = self._tree_view
    12621267            path, column_, x_, y_ = tree_view.get_path_at_pos(int(event.x),
    class CellRendererInvoker(Invoker): 
    12951300        return False
    12961301
    12971302    def __button_release_event_cb(self, widget, event):
    1298         if event.button == 1 and self._point_in_cell_renderer(event.x,
     1303        if event.button == 1 and self.point_in_cell_renderer(event.x,
    12991304            event.y):
    13001305            tree_view = self._tree_view
    13011306            path, column_, x_, y_ = tree_view.get_path_at_pos(int(event.x),
    class CellRendererInvoker(Invoker): 
    13031308            self._cell_renderer.emit('clicked', path)
    13041309            # So the treeview receives it and knows a drag isn't going on
    13051310            return False
    1306         if event.button == 3 and self._point_in_cell_renderer(event.x,
     1311        if event.button == 3 and self.point_in_cell_renderer(event.x,
    13071312            event.y):
    13081313            self.notify_right_click()
    13091314            return True
    13101315        else:
    13111316            return False
    13121317
    1313     def _point_in_cell_renderer(self, event_x, event_y):
     1318    def point_in_cell_renderer(self, event_x, event_y):
    13141319        pos = self._tree_view.get_path_at_pos(int(event_x), int(event_y))
    13151320        if pos is None:
    13161321            return False