* configure.in: Add emacsgtkfixed.o to GTK_OBJ if HAVE_GTK3.
* src/emacsgtkfixed.c, src/emacsgtkfixed.h: New files.
* src/gtkutil.c: Include src/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.
(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.
* src/gtkutil.h (xg_get_default_scrollbar_width): Remove argument.
* src/xfns.c (x_set_scroll_bar_default_width): Remove argument to
xg_get_default_scrollbar_width.
+2011-06-14 Jan Djärv <jan.h.d@swipnet.se>
+
+ * configure.in: Add emacsgtkfixed.o to GTK_OBJ if HAVE_GTK3.
+
2011-06-08 Paul Eggert <eggert@cs.ucla.edu>
* lib/gnulib.mk, m4/gnulib-common.m4: Merge from gnulib.
HAVE_GTK=no
+GTK_OBJ=
if test "${with_gtk3}" = "yes"; then
GLIB_REQUIRED=2.28
GTK_REQUIRED=3.0
AC_MSG_ERROR($GTK_PKG_ERRORS)
fi
AC_DEFINE(HAVE_GTK3, 1, [Define to 1 if using GTK 3 or later.])
+ GTK_OBJ=emacsgtkfixed.o
fi
if test "$pkg_check_gtk" != "yes"; then
fi
fi
-GTK_OBJ=
if test x"$pkg_check_gtk" = xyes; then
AC_SUBST(GTK_CFLAGS)
else
HAVE_GTK=yes
AC_DEFINE(USE_GTK, 1, [Define to 1 if using GTK.])
- GTK_OBJ=gtkutil.o
+ GTK_OBJ="gtkutil.o $GTK_OBJ"
USE_X_TOOLKIT=none
if $PKG_CONFIG --atleast-version=2.10 gtk+-2.0; then
:
+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
--- /dev/null
+/* 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;
+}
--- /dev/null
+/* 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 */
#ifdef HAVE_GTK3
#include <gtk/gtkx.h>
+#include "emacsgtkfixed.h"
#endif
#define FRAME_TOTAL_PIXEL_HEIGHT(f) \
#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);
\f
/***********************************************************************
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;
/* 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. */
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)
{
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
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;
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. */
return 0;
}
-int
-xg_get_default_scrollbar_width (FRAME_PTR f)
+static void
+update_theme_scrollbar_width (void)
{
#ifdef HAVE_GTK3
GtkAdjustment *vadj;
#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.
}
}
+/* 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. */
(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 */
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);
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