Spelling fixes.
[bpt/emacs.git] / src / emacsgtkfixed.c
CommitLineData
c80e3b4a 1/* A Gtk Widget that inherits GtkFixed, but can be shrunk.
c7e73be5 2This file is only use when compiling with Gtk+ 3.
c195f2de 3
acaf905b 4Copyright (C) 2011-2012 Free Software Foundation, Inc.
c195f2de
JD
5
6This file is part of GNU Emacs.
7
8GNU Emacs is free software: you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation, either version 3 of the License, or
11(at your option) any later version.
12
13GNU Emacs is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20
c7e73be5 21#include <config.h>
c195f2de 22
c7e73be5
JD
23#include "emacsgtkfixed.h"
24#include <signal.h>
25#include <stdio.h>
26#include <setjmp.h>
27#include "lisp.h"
28#include "frame.h"
29#include "xterm.h"
c195f2de
JD
30
31struct _EmacsFixedPrivate
32{
c7e73be5 33 struct frame *f;
c195f2de
JD
34};
35
36
37static void emacs_fixed_get_preferred_width (GtkWidget *widget,
38 gint *minimum,
39 gint *natural);
40static void emacs_fixed_get_preferred_height (GtkWidget *widget,
41 gint *minimum,
42 gint *natural);
43G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED)
44
45static void
46emacs_fixed_class_init (EmacsFixedClass *klass)
47{
48 GtkWidgetClass *widget_class;
49 GtkFixedClass *fixed_class;
50
51 widget_class = (GtkWidgetClass*) klass;
52 fixed_class = (GtkFixedClass*) klass;
53
54 widget_class->get_preferred_width = emacs_fixed_get_preferred_width;
55 widget_class->get_preferred_height = emacs_fixed_get_preferred_height;
56 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate));
57}
58
59static GType
60emacs_fixed_child_type (GtkFixed *container)
61{
62 return GTK_TYPE_WIDGET;
63}
64
65static void
66emacs_fixed_init (EmacsFixed *fixed)
67{
68 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, EMACS_TYPE_FIXED,
69 EmacsFixedPrivate);
c7e73be5 70 fixed->priv->f = 0;
c195f2de
JD
71}
72
73/**
74 * emacs_fixed_new:
75 *
76 * Creates a new #EmacsFixed.
77 *
78 * Returns: a new #EmacsFixed.
79 */
80GtkWidget*
c7e73be5 81emacs_fixed_new (struct frame *f)
c195f2de 82{
c7e73be5
JD
83 EmacsFixed *fixed = g_object_new (EMACS_TYPE_FIXED, NULL);
84 EmacsFixedPrivate *priv = fixed->priv;
85 priv->f = f;
86 return GTK_WIDGET (fixed);
c195f2de
JD
87}
88
89static void
90emacs_fixed_get_preferred_width (GtkWidget *widget,
91 gint *minimum,
92 gint *natural)
93{
94 EmacsFixed *fixed = EMACS_FIXED (widget);
95 EmacsFixedPrivate *priv = fixed->priv;
c7e73be5
JD
96 int w = priv->f->output_data.x->size_hints.min_width;
97 if (minimum) *minimum = w;
98 if (natural) *natural = w;
c195f2de
JD
99}
100
101static void
102emacs_fixed_get_preferred_height (GtkWidget *widget,
103 gint *minimum,
104 gint *natural)
105{
106 EmacsFixed *fixed = EMACS_FIXED (widget);
107 EmacsFixedPrivate *priv = fixed->priv;
c7e73be5
JD
108 int h = priv->f->output_data.x->size_hints.min_height;
109 if (minimum) *minimum = h;
110 if (natural) *natural = h;
c195f2de
JD
111}
112
c7e73be5
JD
113
114/* Override the X function so we can intercept Gtk+ 3 calls.
115 Use our values for min_width/height so that KDE don't freak out
116 (Bug#8919), and so users can resize our frames as they wish. */
117
c195f2de 118void
5e617bc2
JB
119XSetWMSizeHints (Display* d,
120 Window w,
121 XSizeHints* hints,
122 Atom prop)
c195f2de 123{
c7e73be5
JD
124 struct x_display_info *dpyinfo = x_display_info_for_display (d);
125 struct frame *f = x_top_window_to_frame (dpyinfo, w);
126 long data[18];
127 data[0] = hints->flags;
128 data[1] = hints->x;
129 data[2] = hints->y;
130 data[3] = hints->width;
131 data[4] = hints->height;
132 data[5] = hints->min_width;
133 data[6] = hints->min_height;
134 data[7] = hints->max_width;
135 data[8] = hints->max_height;
136 data[9] = hints->width_inc;
137 data[10] = hints->height_inc;
138 data[11] = hints->min_aspect.x;
139 data[12] = hints->min_aspect.y;
140 data[13] = hints->max_aspect.x;
141 data[14] = hints->max_aspect.y;
142 data[15] = hints->base_width;
143 data[16] = hints->base_height;
144 data[17] = hints->win_gravity;
145
146 if ((hints->flags & PMinSize) && f)
147 {
148 int w = f->output_data.x->size_hints.min_width;
149 int h = f->output_data.x->size_hints.min_height;
150 data[5] = w;
151 data[6] = h;
152 }
153
154 XChangeProperty (d, w, prop, XA_WM_SIZE_HINTS, 32, PropModeReplace,
155 (unsigned char *) data, 18);
156}
c195f2de 157
c7e73be5
JD
158/* Override this X11 function.
159 This function is in the same X11 file as the one above. So we must
160 provide it also. */
5e617bc2 161
c7e73be5
JD
162void
163XSetWMNormalHints (Display *d, Window w, XSizeHints *hints)
164{
165 XSetWMSizeHints (d, w, hints, XA_WM_NORMAL_HINTS);
c195f2de 166}