summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-06-15 11:07:38 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2011-06-15 11:07:38 -0700
commitff672d2c8785de6faba84a400fb8153e9fa07cd2 (patch)
tree4c5dc68b7a92e54c86e47f3bd9a804c14be57091 /src
parente69dafade3ccd5c2997a3f6fd6c7bea29e75ad8e (diff)
parentb96e6cde3e311cd79f8ad134291d41c8c64cc6ad (diff)
Merge from trunk.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog30
-rw-r--r--src/emacsgtkfixed.c123
-rw-r--r--src/emacsgtkfixed.h58
-rw-r--r--src/gtkutil.c76
-rw-r--r--src/gtkutil.h2
-rw-r--r--src/xfns.c2
6 files changed, 275 insertions, 16 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e477162b32b..87f64244c48 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,12 +1,12 @@
2011-06-15 Paul Eggert <eggert@cs.ucla.edu>
+ Integer overflow and signedness fixes.
+
* fileio.c: Don't assume EMACS_INT fits in off_t.
(emacs_lseek): New static function.
(Finsert_file_contents, Fwrite_region): Use it.
Use SEEK_SET, SEEK_CUR, SEEK_END as appropriate.
-2011-06-14 Paul Eggert <eggert@cs.ucla.edu>
-
* fns.c (Fload_average): Don't assume 100 * load average fits in int.
* fns.c: Don't overflow int when computing a list length.
@@ -66,8 +66,6 @@
* vm-limit.c (check_memory_limits): Fix incorrect extern function decls.
* mem-limits.h (SIZE): Remove; no longer used.
-2011-06-13 Paul Eggert <eggert@cs.ucla.edu>
-
* xterm.c (x_alloc_nearest_color_1): Prefer int to long when int works.
Remove unnecessary casts.
@@ -247,6 +245,30 @@
* alloc.c (Fmake_string): Check for out-of-range init.
+2011-06-14 Jan Djärv <jan.h.d@swipnet.se>
+
+ * xfns.c (x_set_scroll_bar_default_width): Remove argument to
+ xg_get_default_scrollbar_width.
+
+ * gtkutil.c: Include emacsgtkfixed.h if HAVE_GTK3.
+ (int_gtk_range_get_value): Move to the scroll bar part of the file.
+ (style_changed_cb): Call update_theme_scrollbar_width and call
+ x_set_scroll_bar_default_width and xg_frame_set_char_size for
+ all frames (Bug#8505).
+ (xg_create_frame_widgets): Call emacs_fixed_new if HAVE_GTK3 (Bug#8505).
+ Call gtk_window_set_resizable if HAVE_GTK3.
+ (x_wm_set_size_hint): Call emacs_fixed_set_min_size with min width
+ and height if HAVE_GTK3 (Bug#8505).
+ (scroll_bar_width_for_theme): New variable.
+ (update_theme_scrollbar_width): New function.
+ (xg_get_default_scrollbar_width): Move code to
+ update_theme_scrollbar_width, just return scroll_bar_width_for_theme.
+ (xg_initialize): Call update_theme_scrollbar_width.
+
+ * gtkutil.h (xg_get_default_scrollbar_width): Remove argument.
+
+ * emacsgtkfixed.c, emacsgtkfixed.h: New files.
+
2011-06-12 Martin Rudalics <rudalics@gmx.at>
* frame.c (make_frame): Call other_buffer_safely instead of
diff --git a/src/emacsgtkfixed.c b/src/emacsgtkfixed.c
new file mode 100644
index 00000000000..fe3514bce93
--- /dev/null
+++ b/src/emacsgtkfixed.c
@@ -0,0 +1,123 @@
+/* A Gtk Widget that inherits GtkFixed, but can be shrinked.
+
+Copyright (C) 2011 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "emacsgtkfixed.h"
+
+
+struct _EmacsFixedPrivate
+{
+ int minwidth, minheight;
+};
+
+
+static void emacs_fixed_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+static void emacs_fixed_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED)
+
+static void
+emacs_fixed_class_init (EmacsFixedClass *klass)
+{
+ GtkWidgetClass *widget_class;
+ GtkFixedClass *fixed_class;
+
+ widget_class = (GtkWidgetClass*) klass;
+ fixed_class = (GtkFixedClass*) klass;
+
+ widget_class->get_preferred_width = emacs_fixed_get_preferred_width;
+ widget_class->get_preferred_height = emacs_fixed_get_preferred_height;
+ g_type_class_add_private (klass, sizeof (EmacsFixedPrivate));
+}
+
+static GType
+emacs_fixed_child_type (GtkFixed *container)
+{
+ return GTK_TYPE_WIDGET;
+}
+
+static void
+emacs_fixed_init (EmacsFixed *fixed)
+{
+ fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, EMACS_TYPE_FIXED,
+ EmacsFixedPrivate);
+ fixed->priv->minwidth = fixed->priv->minheight = 0;
+}
+
+/**
+ * emacs_fixed_new:
+ *
+ * Creates a new #EmacsFixed.
+ *
+ * Returns: a new #EmacsFixed.
+ */
+GtkWidget*
+emacs_fixed_new (void)
+{
+ return g_object_new (EMACS_TYPE_FIXED, NULL);
+}
+
+static GtkWidgetClass *
+get_parent_class (EmacsFixed *fixed)
+{
+ EmacsFixedClass *klass = EMACS_FIXED_GET_CLASS (fixed);
+ GtkFixedClass *parent_class = g_type_class_peek_parent (klass);
+ return (GtkWidgetClass*) parent_class;
+}
+
+static void
+emacs_fixed_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ EmacsFixed *fixed = EMACS_FIXED (widget);
+ EmacsFixedPrivate *priv = fixed->priv;
+ GtkWidgetClass *widget_class = get_parent_class (fixed);
+ widget_class->get_preferred_width (widget, minimum, natural);
+ if (minimum) *minimum = priv->minwidth;
+}
+
+static void
+emacs_fixed_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ EmacsFixed *fixed = EMACS_FIXED (widget);
+ EmacsFixedPrivate *priv = fixed->priv;
+ GtkWidgetClass *widget_class = get_parent_class (fixed);
+ widget_class->get_preferred_height (widget, minimum, natural);
+ if (minimum) *minimum = priv->minheight;
+}
+
+void
+emacs_fixed_set_min_size (EmacsFixed *widget, int width, int height)
+{
+ EmacsFixedPrivate *priv = widget->priv;
+ GtkWidgetClass *widget_class = get_parent_class (widget);
+ int mw, nw, mh, nh;
+
+ widget_class->get_preferred_height (GTK_WIDGET (widget), &mh, &nh);
+ widget_class->get_preferred_width (GTK_WIDGET (widget), &mw, &nw);
+
+ /* Gtk complains if min size is less than natural size. */
+ if (width <= nw) priv->minwidth = width;
+ if (height <= nh) priv->minheight = height;
+}
diff --git a/src/emacsgtkfixed.h b/src/emacsgtkfixed.h
new file mode 100644
index 00000000000..405374373ec
--- /dev/null
+++ b/src/emacsgtkfixed.h
@@ -0,0 +1,58 @@
+/* A Gtk Widget that inherits GtkFixed, but can be shrinked.
+
+Copyright (C) 2011 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef EMACSGTKFIXED_H
+#define EMACSGTKFIXED_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EMACS_TYPE_FIXED (emacs_fixed_get_type ())
+#define EMACS_FIXED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMACS_TYPE_FIXED, EmacsFixed))
+#define EMACS_FIXED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EMACS_TYPE_FIXED, EmacsFixedClass))
+#define EMACS_IS_FIXED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMACS_TYPE_FIXED))
+#define EMACS_IS_FIXED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EMACS_TYPE_FIXED))
+#define EMACS_FIXED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EMACS_TYPE_FIXED, EmacsFixedClass))
+
+typedef struct _EmacsFixed EmacsFixed;
+typedef struct _EmacsFixedPrivate EmacsFixedPrivate;
+typedef struct _EmacsFixedClass EmacsFixedClass;
+
+struct _EmacsFixed
+{
+ GtkFixed container;
+
+ /*< private >*/
+ EmacsFixedPrivate *priv;
+};
+
+
+struct _EmacsFixedClass
+{
+ GtkFixedClass parent_class;
+};
+
+extern GtkWidget *emacs_fixed_new (void);
+extern void emacs_fixed_set_min_size (EmacsFixed *widget, int width, int height);
+extern GType emacs_fixed_get_type (void);
+
+G_END_DECLS
+
+#endif /* EMACSGTKFIXED_H */
diff --git a/src/gtkutil.c b/src/gtkutil.c
index dedb39a7a40..45f112ae9e5 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -42,6 +42,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_GTK3
#include <gtk/gtkx.h>
+#include "emacsgtkfixed.h"
#endif
#define FRAME_TOTAL_PIXEL_HEIGHT(f) \
@@ -88,12 +89,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#define XG_BIN_CHILD(x) gtk_bin_get_child (GTK_BIN (x))
-/* Get the current value of the range, truncated to an integer. */
-static int
-int_gtk_range_get_value (GtkRange *range)
-{
- return gtk_range_get_value (range);
-}
+static void update_theme_scrollbar_width (void);
/***********************************************************************
@@ -1015,6 +1011,7 @@ style_changed_cb (GObject *go,
struct input_event event;
GdkDisplay *gdpy = (GdkDisplay *) user_data;
const char *display_name = gdk_display_get_name (gdpy);
+ Display *dpy = GDK_DISPLAY_XDISPLAY (gdpy);
EVENT_INIT (event);
event.kind = CONFIG_CHANGED_EVENT;
@@ -1022,6 +1019,24 @@ style_changed_cb (GObject *go,
/* Theme doesn't change often, so intern is called seldom. */
event.arg = intern ("theme-name");
kbd_buffer_store_event (&event);
+
+ update_theme_scrollbar_width ();
+
+ /* If scroll bar width changed, we need set the new size on all frames
+ on this display. */
+ if (dpy)
+ {
+ Lisp_Object rest, frame;
+ FOR_EACH_FRAME (rest, frame)
+ {
+ FRAME_PTR f = XFRAME (frame);
+ if (FRAME_X_DISPLAY (f) == dpy)
+ {
+ x_set_scroll_bar_default_width (f);
+ xg_frame_set_char_size (f, FRAME_COLS (f), FRAME_LINES (f));
+ }
+ }
+ }
}
/* Called when a delete-event occurs on WIDGET. */
@@ -1069,7 +1084,12 @@ xg_create_frame_widgets (FRAME_PTR f)
wvbox = gtk_vbox_new (FALSE, 0);
whbox = gtk_hbox_new (FALSE, 0);
- wfixed = gtk_fixed_new (); /* Must have this to place scroll bars */
+
+#ifdef HAVE_GTK3
+ wfixed = emacs_fixed_new ();
+#else
+ wfixed = gtk_fixed_new ();
+#endif
if (! wtop || ! wvbox || ! whbox || ! wfixed)
{
@@ -1162,6 +1182,7 @@ xg_create_frame_widgets (FRAME_PTR f)
gtk_widget_modify_style (wfixed, style);
#else
gtk_widget_set_can_focus (wfixed, TRUE);
+ gtk_window_set_resizable (GTK_WINDOW (wtop), TRUE);
#endif
#ifdef USE_GTK_TOOLTIP
@@ -1265,6 +1286,18 @@ x_wm_set_size_hint (FRAME_PTR f, long int flags, int user_position)
size_hints.min_width = base_width + min_cols * size_hints.width_inc;
size_hints.min_height = base_height + min_rows * size_hints.height_inc;
+#ifdef HAVE_GTK3
+ /* Gtk3 ignores min width/height and overwrites them with its own idea
+ of min width/height. Put out min values to the widget so Gtk
+ gets the same value we want it to be. Without this, a user can't
+ shrink an Emacs frame.
+ */
+ if (FRAME_GTK_WIDGET (f))
+ emacs_fixed_set_min_size (EMACS_FIXED (FRAME_GTK_WIDGET (f)),
+ size_hints.min_width,
+ size_hints.min_height);
+#endif
+
/* These currently have a one to one mapping with the X values, but I
don't think we should rely on that. */
hint_flags |= GDK_HINT_WIN_GRAVITY;
@@ -3250,6 +3283,10 @@ xg_event_is_for_menubar (FRAME_PTR f, XEvent *event)
int xg_ignore_gtk_scrollbar;
+/* The width of the scroll bar for the current theme. */
+
+static int scroll_bar_width_for_theme;
+
/* Xlib's `Window' fits in 32 bits. But we want to store pointers, and they
may be larger than 32 bits. Keep a mapping from integer index to widget
pointers to get around the 32 bit limitation. */
@@ -3326,8 +3363,8 @@ xg_get_widget_from_map (int idx)
return 0;
}
-int
-xg_get_default_scrollbar_width (FRAME_PTR f)
+static void
+update_theme_scrollbar_width (void)
{
#ifdef HAVE_GTK3
GtkAdjustment *vadj;
@@ -3336,13 +3373,22 @@ xg_get_default_scrollbar_width (FRAME_PTR f)
#endif
GtkWidget *wscroll;
int w = 0, b = 0;
+
vadj = gtk_adjustment_new (XG_SB_MIN, XG_SB_MIN, XG_SB_MAX, 0.1, 0.1, 0.1);
wscroll = gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj));
+ g_object_ref_sink (G_OBJECT (wscroll));
gtk_widget_style_get (wscroll, "slider-width", &w, "trough-border", &b, NULL);
gtk_widget_destroy (wscroll);
+ g_object_unref (G_OBJECT (wscroll));
w += 2*b;
if (w < 16) w = 16;
- return w;
+ scroll_bar_width_for_theme = w;
+}
+
+int
+xg_get_default_scrollbar_width (void)
+{
+ return scroll_bar_width_for_theme;
}
/* Return the scrollbar id for X Window WID on display DPY.
@@ -3528,6 +3574,15 @@ xg_update_scrollbar_pos (FRAME_PTR f,
}
}
+/* Get the current value of the range, truncated to an integer. */
+
+static int
+int_gtk_range_get_value (GtkRange *range)
+{
+ return gtk_range_get_value (range);
+}
+
+
/* Set the thumb size and position of scroll bar BAR. We are currently
displaying PORTION out of a whole WHOLE, and our position POSITION. */
@@ -4680,6 +4735,7 @@ xg_initialize (void)
(GTK_TYPE_MENU_SHELL));
gtk_binding_entry_add_signal (binding_set, GDK_KEY_g, GDK_CONTROL_MASK,
"cancel", 0);
+ update_theme_scrollbar_width ();
}
#endif /* USE_GTK */
diff --git a/src/gtkutil.h b/src/gtkutil.h
index cf58d03b0ce..769e56da917 100644
--- a/src/gtkutil.h
+++ b/src/gtkutil.h
@@ -135,7 +135,7 @@ extern void xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
int position,
int whole);
extern int xg_event_is_for_scrollbar (FRAME_PTR f, XEvent *event);
-extern int xg_get_default_scrollbar_width (FRAME_PTR f);
+extern int xg_get_default_scrollbar_width (void);
extern void update_frame_tool_bar (FRAME_PTR f);
extern void free_frame_tool_bar (FRAME_PTR f);
diff --git a/src/xfns.c b/src/xfns.c
index f847e41855e..abc273c2bdf 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1700,7 +1700,7 @@ x_set_scroll_bar_default_width (struct frame *f)
int wid = FRAME_COLUMN_WIDTH (f);
#ifdef USE_TOOLKIT_SCROLL_BARS
#ifdef USE_GTK
- int minw = xg_get_default_scrollbar_width (f);
+ int minw = xg_get_default_scrollbar_width ();
#else
int minw = 16;
#endif