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