[Xfce4-commits] [apps/mousepad] 02/11: Build with GSEAL_ENABLE defined

noreply at xfce.org noreply at xfce.org
Sat Jul 19 13:54:44 CEST 2014


This is an automated email from the git hooks/post-receive script.

mbrush pushed a commit to branch master
in repository apps/mousepad.

commit 9f303b7e3e0565eca3bf1025aed0cc2379d0636e
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Wed Jul 16 00:14:20 2014 -0700

    Build with GSEAL_ENABLE defined
    
    Sadly this disables the (semi-buggy but still useful) vertical
    selection since I have absolutely no idea how this code works and
    it uses some GtkTextView internals. The code is still active if not
    building with either GTK3 or GSEAL_ENABLE.
    
    Another thing is extending the hacks related to adding our GtkUiManager
    menu as the GtkTextView popup menu. Instead of directly replacing
    GtkTextView's internal menu pointer, empty its menu and move our own
    items there from the UI manager menu.
---
 mousepad/mousepad-gtkcompat.h |   19 +++++
 mousepad/mousepad-util.c      |   77 +++++++++++++++--
 mousepad/mousepad-util.h      |    7 ++
 mousepad/mousepad-view.c      |   65 +++++++++++++--
 mousepad/mousepad-window.c    |  185 +++++++++++++++++++++++++++++++----------
 5 files changed, 296 insertions(+), 57 deletions(-)

diff --git a/mousepad/mousepad-gtkcompat.h b/mousepad/mousepad-gtkcompat.h
index db1857b..1f5c0e6 100644
--- a/mousepad/mousepad-gtkcompat.h
+++ b/mousepad/mousepad-gtkcompat.h
@@ -8,4 +8,23 @@
 # define gtk_combo_box_text_new            gtk_combo_box_new_text
 #endif
 
+#if ! GTK_CHECK_VERSION(3, 0, 0)
+static inline gint
+gtk_widget_get_allocated_width (GtkWidget *widget)
+{
+  GtkAllocation alloc = { 0, 0, 0, 0 };
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), -1);
+  gtk_widget_get_allocation (widget, &alloc);
+  return alloc.width;
+}
+static inline gint
+gtk_widget_get_allocated_height (GtkWidget *widget)
+{
+  GtkAllocation alloc = { 0, 0, 0, 0 };
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), -1);
+  gtk_widget_get_allocation (widget, &alloc);
+  return alloc.height;
+}
+#endif
+
 #endif /* __MOUSEPAD_GTK_COMPAT_H__ */
diff --git a/mousepad/mousepad-util.c b/mousepad/mousepad-util.c
index bc85ba7..7d9cf03 100644
--- a/mousepad/mousepad-util.c
+++ b/mousepad/mousepad-util.c
@@ -413,10 +413,13 @@ mousepad_util_dialog_header (GtkDialog   *dialog,
   gchar     *full_title;
   GtkWidget *vbox, *ebox, *hbox;
   GtkWidget *icon, *label, *line;
+  GtkWidget *dialog_vbox;
+  GtkStyle  *style;
 
   /* remove the main vbox */
-  g_object_ref (G_OBJECT (dialog->vbox));
-  gtk_container_remove (GTK_CONTAINER (dialog), dialog->vbox);
+  dialog_vbox = gtk_bin_get_child (GTK_BIN (dialog));
+  g_object_ref (G_OBJECT (dialog_vbox));
+  gtk_container_remove (GTK_CONTAINER (dialog), dialog_vbox);
 
   /* add a new vbox to the main window */
   vbox = gtk_vbox_new (FALSE, 0);
@@ -426,7 +429,8 @@ mousepad_util_dialog_header (GtkDialog   *dialog,
   /* event box for the background color */
   ebox = gtk_event_box_new ();
   gtk_box_pack_start (GTK_BOX (vbox), ebox, FALSE, FALSE, 0);
-  gtk_widget_modify_bg (ebox, GTK_STATE_NORMAL, &ebox->style->base[GTK_STATE_NORMAL]);
+  style = gtk_widget_get_style (ebox);
+  gtk_widget_modify_bg (ebox, GTK_STATE_NORMAL, &style->base[GTK_STATE_NORMAL]);
   gtk_widget_show (ebox);
 
   /* create a hbox */
@@ -459,8 +463,8 @@ mousepad_util_dialog_header (GtkDialog   *dialog,
   gtk_widget_show (line);
 
   /* add the main dialog box to the new vbox */
-  gtk_box_pack_start (GTK_BOX (vbox), GTK_DIALOG (dialog)->vbox, TRUE, TRUE, 0);
-  g_object_unref (G_OBJECT (GTK_DIALOG (dialog)->vbox));
+  gtk_box_pack_start (GTK_BOX (vbox), dialog_vbox, TRUE, TRUE, 0);
+  g_object_unref (G_OBJECT (dialog_vbox));
 }
 
 
@@ -1095,3 +1099,66 @@ mousepad_util_icon_for_mime_type (const gchar *mime_type)
 
   return icon;
 }
+
+
+
+static void
+mousepad_util_container_foreach_counter (GtkWidget *widget,
+                                         guint     *n_children)
+{
+  *n_children++;
+}
+
+
+
+gboolean
+mousepad_util_container_has_children (GtkContainer *container)
+{
+  guint n_children = 0;
+
+  g_return_val_if_fail (GTK_IS_CONTAINER (container), FALSE);
+
+  gtk_container_foreach (container,
+                         (GtkCallback) mousepad_util_container_foreach_counter,
+                         &n_children);
+
+  return (n_children > 0);
+}
+
+
+void
+mousepad_util_container_clear (GtkContainer *container)
+{
+  GList *list, *iter;
+
+  g_return_if_fail (GTK_IS_CONTAINER (container));
+
+  list = gtk_container_get_children (container);
+
+  for (iter = list; iter != NULL; iter = g_list_next (iter))
+    gtk_container_remove (container, iter->data);
+
+  g_list_free (list);
+}
+
+
+
+void
+mousepad_util_container_move_children (GtkContainer *source,
+                                       GtkContainer *destination)
+{
+  GList *list, *iter;
+
+  list = gtk_container_get_children (source);
+
+  for (iter = list; iter != NULL; iter = g_list_next (iter))
+    {
+      GtkWidget *tmp = g_object_ref (iter->data);
+
+      gtk_container_remove (source, tmp);
+      gtk_container_add (destination, tmp);
+      g_object_unref (tmp);
+    }
+
+  g_list_free (list);
+}
diff --git a/mousepad/mousepad-util.h b/mousepad/mousepad-util.h
index cc4fc04..c83765a 100644
--- a/mousepad/mousepad-util.h
+++ b/mousepad/mousepad-util.h
@@ -119,6 +119,13 @@ GtkAction *mousepad_util_find_related_action              (GtkWidget           *
 
 GIcon     *mousepad_util_icon_for_mime_type               (const gchar         *mime_type);
 
+gboolean   mousepad_util_container_has_children           (GtkContainer        *container);
+
+void       mousepad_util_container_clear                  (GtkContainer        *container);
+
+void       mousepad_util_container_move_children          (GtkContainer        *source,
+                                                           GtkContainer        *destination);
+
 G_END_DECLS
 
 #endif /* !__MOUSEPAD_UTIL_H__ */
diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index 60bf1d5..47e7e98 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -24,6 +24,14 @@
 #include <gtksourceview/gtksourcestylescheme.h>
 #include <gtksourceview/gtksourcestyleschememanager.h>
 
+/* GTK+ 3 removed textview->im_context which is used for multi-selection and
+ * nobody has re-written multi-selection feature to not use this field
+ * so if building with GTK3 or with GSEAL_ENABLE disable the multi-select
+ * feature altogether :( */
+#if ! GTK_CHECK_VERSION(3, 0, 0) && ! defined(GSEAL_ENABLE)
+#define HAVE_MULTISELECT 1
+#endif
+
 
 
 #define MOUSEPAD_VIEW_DEFAULT_FONT "Monospace"
@@ -40,12 +48,15 @@ static void      mousepad_view_get_property                  (GObject
                                                               guint               prop_id,
                                                               GValue             *value,
                                                               GParamSpec         *pspec);
+#ifdef HAVE_MULTISELECT
 static void      mousepad_view_style_set                     (GtkWidget          *widget,
                                                               GtkStyle           *previous_style);
 static gint      mousepad_view_expose                        (GtkWidget          *widget,
                                                               GdkEventExpose     *event);
+#endif
 static gboolean  mousepad_view_key_press_event               (GtkWidget          *widget,
                                                               GdkEventKey        *event);
+#ifdef HAVE_MULTISELECT
 static gboolean  mousepad_view_button_press_event            (GtkWidget          *widget,
                                                               GdkEventButton     *event);
 static gboolean  mousepad_view_button_release_event          (GtkWidget          *widget,
@@ -67,6 +78,7 @@ static void      mousepad_view_selection_draw                (MousepadView
 static gboolean  mousepad_view_selection_timeout             (gpointer            user_data);
 static void      mousepad_view_selection_timeout_destroy     (gpointer            user_data);
 static gchar    *mousepad_view_selection_string              (MousepadView       *view);
+#endif
 static void      mousepad_view_indent_increase               (MousepadView       *view,
                                                               GtkTextIter        *iter);
 static void      mousepad_view_indent_decrease               (MousepadView       *view,
@@ -74,8 +86,10 @@ static void      mousepad_view_indent_decrease               (MousepadView
 static void      mousepad_view_indent_selection              (MousepadView       *view,
                                                               gboolean            increase,
                                                               gboolean            force);
+#ifdef HAVE_MULTISELECT
 static void      mousepad_view_transpose_multi_selection     (GtkTextBuffer       *buffer,
                                                               MousepadView        *view);
+#endif
 static void      mousepad_view_transpose_range               (GtkTextBuffer       *buffer,
                                                               GtkTextIter         *start_iter,
                                                               GtkTextIter         *end_iter);
@@ -163,11 +177,13 @@ mousepad_view_class_init (MousepadViewClass *klass)
   gobject_class->get_property = mousepad_view_get_property;
 
   widget_class = GTK_WIDGET_CLASS (klass);
+  widget_class->key_press_event      = mousepad_view_key_press_event;
+#ifdef HAVE_MUTLISELECT
   widget_class->expose_event         = mousepad_view_expose;
   widget_class->style_set            = mousepad_view_style_set;
-  widget_class->key_press_event      = mousepad_view_key_press_event;
   widget_class->button_press_event   = mousepad_view_button_press_event;
   widget_class->button_release_event = mousepad_view_button_release_event;
+#endif
 
   g_object_class_install_property (
     gobject_class,
@@ -283,8 +299,10 @@ mousepad_view_init (MousepadView *view)
   view->selection_start_x = view->selection_end_x = -1;
   view->selection_start_y = view->selection_end_y = -1;
 
+#ifdef HAVE_MULTISELECT
   g_signal_connect (GTK_TEXT_VIEW (view)->im_context, "commit",
                     G_CALLBACK (mousepad_view_commit_handler), view);
+#endif
 
   /* bind Gsettings */
 #define BIND_(setting, prop) \
@@ -412,6 +430,7 @@ mousepad_view_get_property (GObject    *object,
 
 
 
+#ifdef HAVE_MUTLISELECT
 static gboolean
 mousepad_view_expose (GtkWidget      *widget,
                       GdkEventExpose *event)
@@ -472,6 +491,7 @@ mousepad_view_style_set (GtkWidget *widget,
         mousepad_view_selection_draw (view, FALSE);
     }
 }
+#endif
 
 
 
@@ -484,7 +504,6 @@ mousepad_view_key_press_event (GtkWidget   *widget,
   GtkTextIter    iter;
   GtkTextMark   *cursor;
   guint          modifiers;
-  gboolean       im_handled;
   gboolean       is_editable;
 
   /* get the modifiers state */
@@ -557,13 +576,15 @@ mousepad_view_key_press_event (GtkWidget   *widget,
             /* delete or destroy the selection */
             if (view->selection_length > 0)
               mousepad_view_delete_selection (view);
+#ifdef HAVE_MULTISELECT
             else
               mousepad_view_selection_destroy (view);
-
+#endif
             return TRUE;
           }
         break;
 
+#ifdef HAVE_MULTISELECT
       case GDK_BackSpace:
         if (view->selection_marks != NULL && is_editable)
           {
@@ -573,10 +594,16 @@ mousepad_view_key_press_event (GtkWidget   *widget,
             return TRUE;
           }
         break;
+#endif
 
       default:
+#ifndef HAVE_MULTISELECT
+        break;
+#else
         if (G_UNLIKELY (view->selection_marks != NULL && is_editable))
           {
+            gboolean im_handled;
+
             /* block textview updates (from gtk) */
             gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
 
@@ -590,17 +617,21 @@ mousepad_view_key_press_event (GtkWidget   *widget,
             if (im_handled)
               return TRUE;
           }
+#endif
     }
 
+#ifdef HAVE_MULTISELECT
   /* remove the selection when no valid key combination has been pressed */
   if (G_UNLIKELY (view->selection_marks != NULL && event->is_modifier == FALSE))
     mousepad_view_selection_destroy (view);
+#endif
 
   return (*GTK_WIDGET_CLASS (mousepad_view_parent_class)->key_press_event) (widget, event);
 }
 
 
 
+#ifdef HAVE_MULTISELECT
 static void
 mousepad_view_commit_handler (GtkIMContext *context,
                               const gchar  *str,
@@ -701,12 +732,14 @@ mousepad_view_button_release_event (GtkWidget      *widget,
 
   return (*GTK_WIDGET_CLASS (mousepad_view_parent_class)->button_release_event) (widget, event);
 }
+#endif
 
 
 
 /**
  * Selection Functions
  **/
+#ifdef HAVE_MULTISELECT
 static gboolean
 mousepad_view_selection_word_range (const GtkTextIter *iter,
                                     GtkTextIter       *range_start,
@@ -1197,6 +1230,7 @@ mousepad_view_selection_string (MousepadView *view)
   /* return the string */
   return g_string_free (string, FALSE);
 }
+#endif
 
 
 
@@ -1362,6 +1396,7 @@ mousepad_view_scroll_to_cursor (MousepadView *view)
 
 
 
+#ifdef HAVE_MULTISELECT
 static void
 mousepad_view_transpose_multi_selection (GtkTextBuffer *buffer,
                                          MousepadView  *view)
@@ -1412,6 +1447,7 @@ mousepad_view_transpose_multi_selection (GtkTextBuffer *buffer,
   /* free list */
   g_slist_free (strings);
 }
+#endif
 
 
 
@@ -1606,12 +1642,15 @@ mousepad_view_transpose (MousepadView *view)
   /* begin user action */
   gtk_text_buffer_begin_user_action (buffer);
 
+#ifdef HAVE_MULTISELECT
   if (view->selection_marks != NULL)
     {
       /* transpose a multi selection */
       mousepad_view_transpose_multi_selection (buffer, view);
     }
-  else if (gtk_text_buffer_get_selection_bounds (buffer, &sel_start, &sel_end))
+  else
+#endif
+  if (gtk_text_buffer_get_selection_bounds (buffer, &sel_start, &sel_end))
     {
       /* if the selection is not on the same line, include the whole lines */
       if (gtk_text_iter_get_line (&sel_start) == gtk_text_iter_get_line (&sel_end))
@@ -1672,7 +1711,6 @@ mousepad_view_clipboard_cut (MousepadView *view)
 {
   GtkClipboard  *clipboard;
   GtkTextBuffer *buffer;
-  gchar         *string;
 
   g_return_if_fail (MOUSEPAD_IS_VIEW (view));
   g_return_if_fail (mousepad_view_get_selection_length (view, NULL) > 0);
@@ -1680,8 +1718,11 @@ mousepad_view_clipboard_cut (MousepadView *view)
   /* get the clipboard */
   clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view), GDK_SELECTION_CLIPBOARD);
 
+#ifdef HAVE_MULTISELECT
   if (view->selection_marks != NULL)
     {
+      gchar *string;
+
       /* get the selection string */
       string = mousepad_view_selection_string (view);
 
@@ -1698,6 +1739,7 @@ mousepad_view_clipboard_cut (MousepadView *view)
       mousepad_view_selection_destroy (view);
     }
   else
+#endif
     {
       /* get the buffer */
       buffer = mousepad_view_get_buffer (view);
@@ -1717,7 +1759,6 @@ mousepad_view_clipboard_copy (MousepadView *view)
 {
   GtkClipboard  *clipboard;
   GtkTextBuffer *buffer;
-  gchar         *string;
 
   g_return_if_fail (MOUSEPAD_IS_VIEW (view));
   g_return_if_fail (mousepad_view_get_selection_length (view, NULL) > 0);
@@ -1725,8 +1766,11 @@ mousepad_view_clipboard_copy (MousepadView *view)
   /* get the clipboard */
   clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view), GDK_SELECTION_CLIPBOARD);
 
+#ifdef HAVE_MULTISELECT
   if (view->selection_marks != NULL)
     {
+      gchar *string;
+
       /* get the selection string */
       string = mousepad_view_selection_string (view);
 
@@ -1737,6 +1781,7 @@ mousepad_view_clipboard_copy (MousepadView *view)
       g_free (string);
     }
   else
+#endif
     {
       /* get the buffer */
       buffer = mousepad_view_get_buffer (view);
@@ -1866,6 +1911,7 @@ mousepad_view_delete_selection (MousepadView *view)
   g_return_if_fail (MOUSEPAD_IS_VIEW (view));
   g_return_if_fail (mousepad_view_get_selection_length (view, NULL) > 0);
 
+#ifdef HAVE_MULTISELECT
   if (view->selection_marks != NULL)
     {
       /* remove the text in our selection */
@@ -1875,6 +1921,7 @@ mousepad_view_delete_selection (MousepadView *view)
       mousepad_view_selection_destroy (view);
     }
   else
+#endif
     {
       /* get the buffer */
       buffer = mousepad_view_get_buffer (view);
@@ -1897,9 +1944,11 @@ mousepad_view_select_all (MousepadView *view)
 
   g_return_if_fail (MOUSEPAD_IS_VIEW (view));
 
+#ifdef HAVE_MULTISELECT
   /* cleanup our selection */
   if (view->selection_marks != NULL)
     mousepad_view_selection_destroy (view);
+#endif
 
   /* get the buffer */
   buffer = mousepad_view_get_buffer (view);
@@ -1916,6 +1965,7 @@ mousepad_view_select_all (MousepadView *view)
 void
 mousepad_view_change_selection (MousepadView *view)
 {
+#ifdef HAVE_MULTISELECT
   GtkTextBuffer *buffer;
   GtkTextIter    start_iter, end_iter;
   GdkRectangle   rect;
@@ -1970,6 +2020,7 @@ mousepad_view_change_selection (MousepadView *view)
 
   /* allow notifications again */
   g_object_thaw_notify (G_OBJECT (buffer));
+#endif
 }
 
 
@@ -2076,11 +2127,13 @@ mousepad_view_convert_selection_case (MousepadView *view,
       /* select range */
       gtk_text_buffer_select_range (buffer, &end_iter, &start_iter);
     }
+#ifdef HAVE_MULTISELECT
   else
     {
       /* redraw column selection */
       mousepad_view_selection_draw (view, FALSE);
     }
+#endif
 
   /* end user action */
   gtk_text_buffer_end_user_action (buffer);
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 139299f..bc179c3 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -21,6 +21,7 @@
 #include <mousepad/mousepad-marshal.h>
 #include <mousepad/mousepad-document.h>
 #include <mousepad/mousepad-dialogs.h>
+#include <mousepad/mousepad-gtkcompat.h>
 #include <mousepad/mousepad-replace-dialog.h>
 #include <mousepad/mousepad-encoding-dialog.h>
 #include <mousepad/mousepad-search-bar.h>
@@ -169,7 +170,7 @@ static void              mousepad_window_menu_templates               (GtkWidget
 static void              mousepad_window_menu_tab_sizes               (MousepadWindow         *window);
 static void              mousepad_window_menu_tab_sizes_update        (MousepadWindow         *window);
 static void              mousepad_window_menu_textview_deactivate     (GtkWidget              *menu,
-                                                                       GtkTextView            *textview);
+                                                                       MousepadWindow         *window);
 static void              mousepad_window_menu_textview_popup          (GtkTextView            *textview,
                                                                        GtkMenu                *old_menu,
                                                                        MousepadWindow         *window);
@@ -1162,12 +1163,15 @@ mousepad_window_configure_event (GtkWidget         *widget,
                                  GdkEventConfigure *event)
 {
   MousepadWindow *window = MOUSEPAD_WINDOW (widget);
+  GtkAllocation   alloc = { 0, 0, 0, 0 };
+
+  gtk_widget_get_allocation (widget, &alloc);
 
   /* check if we have a new dimension here */
-  if (widget->allocation.width != event->width ||
-      widget->allocation.height != event->height ||
-      widget->allocation.x != event->x ||
-      widget->allocation.y != event->y)
+  if (alloc.width != event->width ||
+      alloc.height != event->height ||
+      alloc.x != event->x ||
+      alloc.y != event->y)
     {
       /* drop any previous timer source */
       if (window->save_geometry_timer_id > 0)
@@ -1325,7 +1329,7 @@ mousepad_window_save_geometry_timer (gpointer user_data)
       if (gtk_widget_get_visible (GTK_WIDGET(window)))
         {
           /* determine the current state of the window */
-          state = gdk_window_get_state (GTK_WIDGET (window)->window);
+          state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
 
           /* don't save geometry for maximized or fullscreen windows */
           if ((state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) == 0)
@@ -1911,18 +1915,81 @@ mousepad_window_notebook_menu_position (GtkMenu  *menu,
                                         gboolean *push_in,
                                         gpointer  user_data)
 {
-  GtkWidget *widget = GTK_WIDGET (user_data);
+  GtkWidget    *widget = GTK_WIDGET (user_data);
+  GtkAllocation alloc = { 0, 0, 0, 0 };
 
-  gdk_window_get_origin (widget->window, x, y);
+  gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
+  gtk_widget_get_allocation (widget, &alloc);
 
-  *x += widget->allocation.x;
-  *y += widget->allocation.y + widget->allocation.height;
+  *x += alloc.x;
+  *y += alloc.y + alloc.height;
 
   *push_in = TRUE;
 }
 
 
 
+/* stolen from Geany notebook.c */
+static gboolean
+mousepad_window_is_position_on_tab_bar(GtkNotebook *notebook, GdkEventButton *event)
+{
+  GtkWidget      *page, *tab, *nb;
+  GtkPositionType tab_pos;
+  gint            scroll_arrow_hlength, scroll_arrow_vlength;
+  gdouble         x, y;
+
+  page = gtk_notebook_get_nth_page (notebook, 0);
+  g_return_val_if_fail (page != NULL, FALSE);
+
+  tab = gtk_notebook_get_tab_label (notebook, page);
+  g_return_val_if_fail (tab != NULL, FALSE);
+
+  tab_pos = gtk_notebook_get_tab_pos (notebook);
+  nb = GTK_WIDGET (notebook);
+
+  gtk_widget_style_get (GTK_WIDGET (notebook),
+                        "scroll-arrow-hlength", &scroll_arrow_hlength,
+                        "scroll-arrow-vlength", &scroll_arrow_vlength,
+                        NULL);
+
+  if (! gdk_event_get_coords ((GdkEvent*) event, &x, &y))
+    {
+      x = event->x;
+      y = event->y;
+    }
+
+  switch (tab_pos)
+    {
+    case GTK_POS_TOP:
+    case GTK_POS_BOTTOM:
+      if (event->y >= 0 && event->y <= gtk_widget_get_allocated_height (tab))
+        {
+          if (! gtk_notebook_get_scrollable (notebook) || (
+            x > scroll_arrow_hlength &&
+            x < gtk_widget_get_allocated_width (nb) - scroll_arrow_hlength))
+          {
+            return TRUE;
+          }
+        }
+      break;
+    case GTK_POS_LEFT:
+    case GTK_POS_RIGHT:
+        if (event->x >= 0 && event->x <= gtk_widget_get_allocated_width (tab))
+          {
+            if (! gtk_notebook_get_scrollable (notebook) || (
+                y > scroll_arrow_vlength &&
+                y < gtk_widget_get_allocated_height (nb) - scroll_arrow_vlength))
+              {
+                return TRUE;
+              }
+          }
+    }
+
+  return FALSE;
+}
+
+
+
 static gboolean
 mousepad_window_notebook_button_press_event (GtkNotebook    *notebook,
                                              GdkEventButton *event,
@@ -1940,14 +2007,17 @@ mousepad_window_notebook_button_press_event (GtkNotebook    *notebook,
       /* walk through the tabs and look for the tab under the cursor */
       while ((page = gtk_notebook_get_nth_page (notebook, page_num)) != NULL)
         {
+          GtkAllocation alloc = { 0, 0, 0, 0 };
+
           label = gtk_notebook_get_tab_label (notebook, page);
 
           /* get the origin of the label */
-          gdk_window_get_origin (label->window, &x_root, NULL);
-          x_root = x_root + label->allocation.x;
+          gdk_window_get_origin (gtk_widget_get_window (label), &x_root, NULL);
+          gtk_widget_get_allocation (label, &alloc);
+          x_root = x_root + alloc.x;
 
           /* check if the cursor is inside this label */
-          if (event->x_root >= x_root && event->x_root <= (x_root + label->allocation.width))
+          if (event->x_root >= x_root && event->x_root <= (x_root + alloc.width))
             {
               /* switch to this tab */
               gtk_notebook_set_current_page (notebook, page_num);
@@ -1979,8 +2049,16 @@ mousepad_window_notebook_button_press_event (GtkNotebook    *notebook,
     }
   else if (event->type == GDK_2BUTTON_PRESS && event->button == 1)
     {
+      GtkWidget   *ev_widget, *nb_child;
+
+      ev_widget = gtk_get_event_widget ((GdkEvent*) event);
+      nb_child = gtk_notebook_get_nth_page (notebook,
+                                            gtk_notebook_get_current_page (notebook));
+      if (ev_widget == NULL || ev_widget == nb_child || gtk_widget_is_ancestor (ev_widget, nb_child))
+        return FALSE;
+      
       /* check if the event window is the notebook event window (not a tab) */
-      if (event->window == notebook->event_window)
+      if (mousepad_window_is_position_on_tab_bar (notebook, event))
         {
           /* create new document */
           mousepad_window_action_new (NULL, window);
@@ -2247,7 +2325,7 @@ mousepad_window_menu_templates_fill (MousepadWindow *window,
       mousepad_window_menu_templates_fill (window, submenu, li->data);
 
       /* check if the sub menu contains items */
-      if (G_LIKELY (GTK_MENU_SHELL (submenu)->children != NULL))
+      if (mousepad_util_container_has_children (GTK_CONTAINER (submenu)))
         {
           /* create directory label */
           label = g_filename_display_basename (li->data);
@@ -2504,48 +2582,57 @@ mousepad_window_menu_tab_sizes_update (MousepadWindow *window)
 
 
 static void
-mousepad_window_menu_textview_deactivate (GtkWidget   *menu,
-                                          GtkTextView *textview)
+mousepad_window_menu_textview_shown (GtkMenu        *menu,
+                                     MousepadWindow *window)
 {
-  g_return_if_fail (GTK_IS_TEXT_VIEW (textview));
-  g_return_if_fail (textview->popup_menu == menu);
+  GtkWidget *our_menu;
+
+  g_return_if_fail (MOUSEPAD_IS_WINDOW (window));
 
   /* disconnect this signal */
-  mousepad_disconnect_by_func (G_OBJECT (menu), mousepad_window_menu_textview_deactivate, textview);
+  mousepad_disconnect_by_func (menu, mousepad_window_menu_textview_shown, window);
 
-  /* unset the popup menu since your menu is owned by the ui manager */
-  GTK_TEXT_VIEW (textview)->popup_menu = NULL;
+  /* empty the original menu */
+  mousepad_util_container_clear (GTK_CONTAINER (menu));
+
+  /* get the ui manager menu and move its children into the other menu */
+  our_menu = gtk_ui_manager_get_widget (window->ui_manager, "/textview-menu");
+  mousepad_util_container_move_children (GTK_CONTAINER (our_menu), GTK_CONTAINER (menu));
 }
 
 
 
 static void
-mousepad_window_menu_textview_popup (GtkTextView    *textview,
-                                     GtkMenu        *old_menu,
-                                     MousepadWindow *window)
+mousepad_window_menu_textview_deactivate (GtkWidget      *menu,
+                                          MousepadWindow *window)
 {
-  GtkWidget *menu;
+  GtkWidget *our_menu;
 
-  g_return_if_fail (GTK_WIDGET (old_menu) == textview->popup_menu);
-  g_return_if_fail (GTK_IS_TEXT_VIEW (textview));
   g_return_if_fail (MOUSEPAD_IS_WINDOW (window));
-  g_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
-  g_return_if_fail (GTK_IS_MENU (textview->popup_menu));
 
-  /* destroy origional menu */
-  gtk_widget_destroy (textview->popup_menu);
+  /* disconnect this signal */
+  mousepad_disconnect_by_func (G_OBJECT (menu), mousepad_window_menu_textview_deactivate, window);
+
+  /* copy the menus children back into the ui manager menu */
+  our_menu = gtk_ui_manager_get_widget (window->ui_manager, "/textview-menu");
+  mousepad_util_container_move_children (GTK_CONTAINER (menu), GTK_CONTAINER (our_menu));
+}
 
-  /* get the textview menu */
-  menu = gtk_ui_manager_get_widget (window->ui_manager, "/textview-menu");
 
-  /* connect signal */
-  g_signal_connect (G_OBJECT (menu), "deactivate", G_CALLBACK (mousepad_window_menu_textview_deactivate), textview);
 
-  /* set screen */
-  gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (GTK_WIDGET (textview)));
+static void
+mousepad_window_menu_textview_popup (GtkTextView    *textview,
+                                     GtkMenu        *menu,
+                                     MousepadWindow *window)
+{
+  g_return_if_fail (GTK_IS_TEXT_VIEW (textview));
+  g_return_if_fail (GTK_IS_MENU (menu));
+  g_return_if_fail (MOUSEPAD_IS_WINDOW (window));
+  g_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
 
-  /* set ours */
-  textview->popup_menu = menu;
+  /* connect signal */
+  g_signal_connect (G_OBJECT (menu), "show", G_CALLBACK (mousepad_window_menu_textview_shown), window);
+  g_signal_connect (G_OBJECT (menu), "deactivate", G_CALLBACK (mousepad_window_menu_textview_deactivate), window);
 }
 
 
@@ -3114,10 +3201,12 @@ mousepad_window_drag_data_received (GtkWidget        *widget,
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
 
   /* we only accept text/uri-list drops with format 8 and atleast one byte of data */
-  if (info == TARGET_TEXT_URI_LIST && selection_data->format == 8 && selection_data->length > 0)
+  if (info == TARGET_TEXT_URI_LIST &&
+      gtk_selection_data_get_format (selection_data) == 8 &&
+      gtk_selection_data_get_length (selection_data) > 0)
     {
       /* extract the uris from the data */
-      uris = g_uri_list_extract_uris ((const gchar *)selection_data->data);
+      uris = g_uri_list_extract_uris ((const gchar *) gtk_selection_data_get_data (selection_data));
 
       /* get working directory */
       working_directory = g_get_current_dir ();
@@ -3138,7 +3227,7 @@ mousepad_window_drag_data_received (GtkWidget        *widget,
       notebook = gtk_drag_get_source_widget (context);
 
       /* get the document that has been dragged */
-      document = (GtkWidget **) selection_data->data;
+      document = (GtkWidget **) gtk_selection_data_get_data (selection_data);
 
       /* check */
       g_return_if_fail (MOUSEPAD_IS_DOCUMENT (*document));
@@ -3155,12 +3244,16 @@ mousepad_window_drag_data_received (GtkWidget        *widget,
       /* figure out where to insert the tab in the notebook */
       for (i = 0; i < n_pages; i++)
         {
+          GtkAllocation alloc = { 0, 0, 0, 0 };
+
           /* get the child label */
           child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), i);
           label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (window->notebook), child);
 
+          gtk_widget_get_allocation (label, &alloc);
+
           /* break if we have a matching drop position */
-          if (x < (label->allocation.x + label->allocation.width / 2))
+          if (x < (alloc.x + alloc.width / 2))
             break;
         }
 
@@ -3491,7 +3584,7 @@ mousepad_window_paste_history_menu (MousepadWindow *window)
   if (list_data != NULL)
     {
       /* add separator between history and active menu items */
-      if (GTK_MENU_SHELL (menu)->children != NULL)
+      if (mousepad_util_container_has_children (GTK_CONTAINER (menu)))
         {
           item = gtk_separator_menu_item_new ();
           gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
@@ -3505,7 +3598,7 @@ mousepad_window_paste_history_menu (MousepadWindow *window)
       g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (mousepad_window_paste_history_activate), window);
       gtk_widget_show (item);
     }
-  else if (GTK_MENU_SHELL (menu)->children == NULL)
+  else if (! mousepad_util_container_has_children (GTK_CONTAINER (menu)))
     {
       /* create an item to inform the user */
       item = gtk_menu_item_new_with_label (_("No clipboard data"));

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list