summaryrefslogtreecommitdiff
path: root/src/emacsgtkfixed.c
diff options
context:
space:
mode:
authorJan Djärv <jan.h.d@swipnet.se>2011-06-14 23:08:20 +0200
committerJan Djärv <jan.h.d@swipnet.se>2011-06-14 23:08:20 +0200
commitc195f2de12d7fc5466bf8b5bd2cf98a42a749691 (patch)
treed1d117469249ed5e7a2012eb35d1145a317f5258 /src/emacsgtkfixed.c
parentc5dd5a516c9f0f4b622452c42e34e95ca2e2fae5 (diff)
downloademacs-c195f2de12d7fc5466bf8b5bd2cf98a42a749691.tar.gz
Fix resize and change of scroll bar width for Gtk3.
* 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.
Diffstat (limited to 'src/emacsgtkfixed.c')
-rw-r--r--src/emacsgtkfixed.c123
1 files changed, 123 insertions, 0 deletions
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;
+}