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 | |
ba318903 | 4 | Copyright (C) 2011-2014 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 JD |
23 | #include "lisp.h" |
24 | #include "frame.h" | |
25 | #include "xterm.h" | |
9d7693d7 | 26 | #include "emacsgtkfixed.h" |
c195f2de | 27 | |
5f0cb45a | 28 | /* Silence a bogus diagnostic; see GNOME bug 683906. */ |
9ca960e2 | 29 | #if 4 < __GNUC__ + (7 <= __GNUC_MINOR__) |
8ea47e3a PE |
30 | # pragma GCC diagnostic push |
31 | # pragma GCC diagnostic ignored "-Wunused-local-typedefs" | |
32 | #endif | |
5f0cb45a | 33 | |
1068fe4d PE |
34 | #define EMACS_TYPE_FIXED emacs_fixed_get_type () |
35 | #define EMACS_FIXED(obj) \ | |
36 | G_TYPE_CHECK_INSTANCE_CAST (obj, EMACS_TYPE_FIXED, EmacsFixed) | |
37 | ||
38 | typedef struct _EmacsFixed EmacsFixed; | |
39 | typedef struct _EmacsFixedPrivate EmacsFixedPrivate; | |
40 | typedef struct _EmacsFixedClass EmacsFixedClass; | |
41 | ||
42 | struct _EmacsFixed | |
43 | { | |
44 | GtkFixed container; | |
45 | ||
46 | /*< private >*/ | |
47 | EmacsFixedPrivate *priv; | |
48 | }; | |
49 | ||
50 | struct _EmacsFixedClass | |
51 | { | |
52 | GtkFixedClass parent_class; | |
53 | }; | |
54 | ||
c195f2de JD |
55 | struct _EmacsFixedPrivate |
56 | { | |
c7e73be5 | 57 | struct frame *f; |
c195f2de JD |
58 | }; |
59 | ||
60 | ||
61 | static void emacs_fixed_get_preferred_width (GtkWidget *widget, | |
62 | gint *minimum, | |
63 | gint *natural); | |
64 | static void emacs_fixed_get_preferred_height (GtkWidget *widget, | |
65 | gint *minimum, | |
66 | gint *natural); | |
1068fe4d | 67 | static GType emacs_fixed_get_type (void); |
c195f2de JD |
68 | G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED) |
69 | ||
70 | static void | |
71 | emacs_fixed_class_init (EmacsFixedClass *klass) | |
72 | { | |
73 | GtkWidgetClass *widget_class; | |
c195f2de JD |
74 | |
75 | widget_class = (GtkWidgetClass*) klass; | |
c195f2de JD |
76 | |
77 | widget_class->get_preferred_width = emacs_fixed_get_preferred_width; | |
78 | widget_class->get_preferred_height = emacs_fixed_get_preferred_height; | |
79 | g_type_class_add_private (klass, sizeof (EmacsFixedPrivate)); | |
80 | } | |
81 | ||
c195f2de JD |
82 | static void |
83 | emacs_fixed_init (EmacsFixed *fixed) | |
84 | { | |
85 | fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, EMACS_TYPE_FIXED, | |
86 | EmacsFixedPrivate); | |
c7e73be5 | 87 | fixed->priv->f = 0; |
c195f2de JD |
88 | } |
89 | ||
90 | /** | |
91 | * emacs_fixed_new: | |
92 | * | |
93 | * Creates a new #EmacsFixed. | |
94 | * | |
95 | * Returns: a new #EmacsFixed. | |
96 | */ | |
97 | GtkWidget* | |
c7e73be5 | 98 | emacs_fixed_new (struct frame *f) |
c195f2de | 99 | { |
c7e73be5 JD |
100 | EmacsFixed *fixed = g_object_new (EMACS_TYPE_FIXED, NULL); |
101 | EmacsFixedPrivate *priv = fixed->priv; | |
102 | priv->f = f; | |
103 | return GTK_WIDGET (fixed); | |
c195f2de JD |
104 | } |
105 | ||
106 | static void | |
107 | emacs_fixed_get_preferred_width (GtkWidget *widget, | |
108 | gint *minimum, | |
109 | gint *natural) | |
110 | { | |
111 | EmacsFixed *fixed = EMACS_FIXED (widget); | |
112 | EmacsFixedPrivate *priv = fixed->priv; | |
c7e73be5 JD |
113 | int w = priv->f->output_data.x->size_hints.min_width; |
114 | if (minimum) *minimum = w; | |
115 | if (natural) *natural = w; | |
c195f2de JD |
116 | } |
117 | ||
118 | static void | |
119 | emacs_fixed_get_preferred_height (GtkWidget *widget, | |
120 | gint *minimum, | |
121 | gint *natural) | |
122 | { | |
123 | EmacsFixed *fixed = EMACS_FIXED (widget); | |
124 | EmacsFixedPrivate *priv = fixed->priv; | |
c7e73be5 JD |
125 | int h = priv->f->output_data.x->size_hints.min_height; |
126 | if (minimum) *minimum = h; | |
127 | if (natural) *natural = h; | |
c195f2de JD |
128 | } |
129 | ||
c7e73be5 JD |
130 | |
131 | /* Override the X function so we can intercept Gtk+ 3 calls. | |
132 | Use our values for min_width/height so that KDE don't freak out | |
133 | (Bug#8919), and so users can resize our frames as they wish. */ | |
134 | ||
c195f2de | 135 | void |
5e617bc2 JB |
136 | XSetWMSizeHints (Display* d, |
137 | Window w, | |
138 | XSizeHints* hints, | |
139 | Atom prop) | |
c195f2de | 140 | { |
c7e73be5 JD |
141 | struct x_display_info *dpyinfo = x_display_info_for_display (d); |
142 | struct frame *f = x_top_window_to_frame (dpyinfo, w); | |
143 | long data[18]; | |
144 | data[0] = hints->flags; | |
145 | data[1] = hints->x; | |
146 | data[2] = hints->y; | |
147 | data[3] = hints->width; | |
148 | data[4] = hints->height; | |
149 | data[5] = hints->min_width; | |
150 | data[6] = hints->min_height; | |
151 | data[7] = hints->max_width; | |
152 | data[8] = hints->max_height; | |
153 | data[9] = hints->width_inc; | |
154 | data[10] = hints->height_inc; | |
155 | data[11] = hints->min_aspect.x; | |
156 | data[12] = hints->min_aspect.y; | |
157 | data[13] = hints->max_aspect.x; | |
158 | data[14] = hints->max_aspect.y; | |
159 | data[15] = hints->base_width; | |
160 | data[16] = hints->base_height; | |
161 | data[17] = hints->win_gravity; | |
162 | ||
163 | if ((hints->flags & PMinSize) && f) | |
164 | { | |
165 | int w = f->output_data.x->size_hints.min_width; | |
166 | int h = f->output_data.x->size_hints.min_height; | |
167 | data[5] = w; | |
168 | data[6] = h; | |
169 | } | |
170 | ||
171 | XChangeProperty (d, w, prop, XA_WM_SIZE_HINTS, 32, PropModeReplace, | |
172 | (unsigned char *) data, 18); | |
173 | } | |
c195f2de | 174 | |
c7e73be5 JD |
175 | /* Override this X11 function. |
176 | This function is in the same X11 file as the one above. So we must | |
177 | provide it also. */ | |
5e617bc2 | 178 | |
c7e73be5 JD |
179 | void |
180 | XSetWMNormalHints (Display *d, Window w, XSizeHints *hints) | |
181 | { | |
182 | XSetWMSizeHints (d, w, hints, XA_WM_NORMAL_HINTS); | |
c195f2de | 183 | } |