remove Lisp_Free struct type
[bpt/emacs.git] / src / emacsgtkfixed.c
index fe3514b..c584dd8 100644 (file)
@@ -1,6 +1,7 @@
-/* A Gtk Widget that inherits GtkFixed, but can be shrinked. 
+/* A Gtk Widget that inherits GtkFixed, but can be shrunk.
+This file is only use when compiling with Gtk+ 3.
 
-Copyright (C) 2011  Free Software Foundation, Inc.
+Copyright (C) 2011-2014 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -17,12 +18,43 @@ 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 <config.h>
+
+#include "lisp.h"
+#include "frame.h"
+#include "xterm.h"
 #include "emacsgtkfixed.h"
 
+/* Silence a bogus diagnostic; see GNOME bug 683906.  */
+#if 4 < __GNUC__ + (7 <= __GNUC_MINOR__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wunused-local-typedefs"
+#endif
+
+#define EMACS_TYPE_FIXED emacs_fixed_get_type ()
+#define EMACS_FIXED(obj) \
+  G_TYPE_CHECK_INSTANCE_CAST (obj, EMACS_TYPE_FIXED, EmacsFixed)
+
+typedef struct _EmacsFixed EmacsFixed;
+typedef struct _EmacsFixedPrivate EmacsFixedPrivate;
+typedef struct _EmacsFixedClass EmacsFixedClass;
+
+struct _EmacsFixed
+{
+  GtkFixed container;
+
+  /*< private >*/
+  EmacsFixedPrivate *priv;
+};
+
+struct _EmacsFixedClass
+{
+  GtkFixedClass parent_class;
+};
 
 struct _EmacsFixedPrivate
 {
-  int minwidth, minheight;
+  struct frame *f;
 };
 
 
@@ -32,34 +64,27 @@ static void emacs_fixed_get_preferred_width  (GtkWidget *widget,
 static void emacs_fixed_get_preferred_height (GtkWidget *widget,
                                               gint      *minimum,
                                               gint      *natural);
+static GType emacs_fixed_get_type (void);
 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;
+  fixed->priv->f = 0;
 }
 
 /**
@@ -70,17 +95,12 @@ emacs_fixed_init (EmacsFixed *fixed)
  * Returns: a new #EmacsFixed.
  */
 GtkWidget*
-emacs_fixed_new (void)
-{
-  return g_object_new (EMACS_TYPE_FIXED, NULL);
-}
-
-static GtkWidgetClass *
-get_parent_class (EmacsFixed *fixed)
+emacs_fixed_new (struct frame *f)
 {
-  EmacsFixedClass *klass = EMACS_FIXED_GET_CLASS (fixed);
-  GtkFixedClass *parent_class = g_type_class_peek_parent (klass);
-  return (GtkWidgetClass*) parent_class;
+  EmacsFixed *fixed = g_object_new (EMACS_TYPE_FIXED, NULL);
+  EmacsFixedPrivate *priv = fixed->priv;
+  priv->f = f;
+  return GTK_WIDGET (fixed);
 }
 
 static void
@@ -90,9 +110,9 @@ emacs_fixed_get_preferred_width (GtkWidget *widget,
 {
   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;
+  int w = priv->f->output_data.x->size_hints.min_width;
+  if (minimum) *minimum = w;
+  if (natural) *natural = w;
 }
 
 static void
@@ -102,22 +122,62 @@ emacs_fixed_get_preferred_height (GtkWidget *widget,
 {
   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;
+  int h = priv->f->output_data.x->size_hints.min_height;
+  if (minimum) *minimum = h;
+  if (natural) *natural = h;
 }
 
+
+/* Override the X function so we can intercept Gtk+ 3 calls.
+   Use our values for min_width/height so that KDE don't freak out
+   (Bug#8919), and so users can resize our frames as they wish.  */
+
 void
-emacs_fixed_set_min_size (EmacsFixed *widget, int width, int height)
+XSetWMSizeHints (Display* d,
+                 Window w,
+                 XSizeHints* hints,
+                 Atom prop)
 {
-  EmacsFixedPrivate *priv = widget->priv;
-  GtkWidgetClass *widget_class = get_parent_class (widget);
-  int mw, nw, mh, nh;
+  struct x_display_info *dpyinfo = x_display_info_for_display (d);
+  struct frame *f = x_top_window_to_frame (dpyinfo, w);
+  long data[18];
+  data[0] = hints->flags;
+  data[1] = hints->x;
+  data[2] = hints->y;
+  data[3] = hints->width;
+  data[4] = hints->height;
+  data[5] = hints->min_width;
+  data[6] = hints->min_height;
+  data[7] = hints->max_width;
+  data[8] = hints->max_height;
+  data[9] = hints->width_inc;
+  data[10] = hints->height_inc;
+  data[11] = hints->min_aspect.x;
+  data[12] = hints->min_aspect.y;
+  data[13] = hints->max_aspect.x;
+  data[14] = hints->max_aspect.y;
+  data[15] = hints->base_width;
+  data[16] = hints->base_height;
+  data[17] = hints->win_gravity;
+
+  if ((hints->flags & PMinSize) && f)
+    {
+      int w = f->output_data.x->size_hints.min_width;
+      int h = f->output_data.x->size_hints.min_height;
+      data[5] = w;
+      data[6] = h;
+    }
+
+  XChangeProperty (d, w, prop, XA_WM_SIZE_HINTS, 32, PropModeReplace,
+                  (unsigned char *) data, 18);
+}
 
-  widget_class->get_preferred_height (GTK_WIDGET (widget), &mh, &nh);
-  widget_class->get_preferred_width (GTK_WIDGET (widget), &mw, &nw);
+/* Override this X11 function.
+   This function is in the same X11 file as the one above.  So we must
+   provide it also.  */
 
-  /* Gtk complains if min size is less than natural size.  */
-  if (width <= nw) priv->minwidth = width;
-  if (height <= nh) priv->minheight = height;
+void
+XSetWMNormalHints (Display *d, Window w, XSizeHints *hints)
+{
+  XSetWMSizeHints (d, w, hints, XA_WM_NORMAL_HINTS);
 }