Commit | Line | Data |
---|---|---|
07bf635f | 1 | /* The emacs frame widget. |
73b0cd50 | 2 | Copyright (C) 1992-1993, 2000-2011 Free Software Foundation, Inc. |
07bf635f RS |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
9ec0b715 | 6 | GNU Emacs is free software: you can redistribute it and/or modify |
07bf635f | 7 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
8 | the Free Software Foundation, either version 3 of the License, or |
9 | (at your option) any later version. | |
07bf635f RS |
10 | |
11 | GNU Emacs is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 17 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
07bf635f RS |
18 | |
19 | /* Emacs 19 face widget ported by Fred Pierresteguy */ | |
20 | ||
ac26ca64 KH |
21 | /* This file has been censored by the Communications Decency Act. |
22 | That law was passed under the guise of a ban on pornography, but | |
23 | it bans far more than that. This file did not contain pornography, | |
24 | but it was censored nonetheless. | |
25 | ||
26 | For information on US government censorship of the Internet, and | |
27 | what you can do to bring back freedom of the press, see the web | |
28 | site http://www.vtw.org/ | |
29 | */ | |
30 | ||
9e65ad77 | 31 | #include <config.h> |
565620a5 | 32 | #include <stdio.h> |
d7306fe6 | 33 | #include <setjmp.h> |
07bf635f RS |
34 | #include "lisp.h" |
35 | #include "xterm.h" | |
36 | ||
87a43646 | 37 | #include "keyboard.h" |
07bf635f | 38 | #include "frame.h" |
dfcf069d | 39 | #include "window.h" |
07bf635f RS |
40 | |
41 | #include "dispextern.h" | |
49fe12a9 | 42 | #include "blockinput.h" |
07bf635f RS |
43 | |
44 | #include <X11/StringDefs.h> | |
45 | #include <X11/IntrinsicP.h> | |
46 | #include <X11/cursorfont.h> | |
47 | #include "widgetprv.h" | |
65fbf4a3 | 48 | #include <X11/ObjectP.h> |
07bf635f RS |
49 | #include <X11/Shell.h> |
50 | #include <X11/ShellP.h> | |
69524b98 | 51 | #include "../lwlib/lwlib.h" |
07bf635f | 52 | |
a5d3ec3f GM |
53 | #include <signal.h> |
54 | #include "syssignal.h" | |
55 | ||
39d14c25 CY |
56 | #include "character.h" |
57 | #include "font.h" | |
58 | ||
07bf635f RS |
59 | /* This sucks: this is the first default that x-faces.el tries. This won't |
60 | be used unless neither the "Emacs.EmacsFrame" resource nor the | |
61 | "Emacs.EmacsFrame" resource is set; the frame | |
62 | may have the wrong default size if this font doesn't exist, but some other | |
63 | font that x-faces.el does. The workaround is to specify some font in the | |
64 | resource database; I don't know a solution other than duplicating the font- | |
65 | searching code from x-faces.el in this file. | |
66 | ||
67 | This also means that if "Emacs.EmacsFrame" is specified as a non- | |
68 | existent font, then Xt is going to substitute "XtDefaultFont" for it, | |
69 | which is a different size than this one. The solution for this is to | |
70 | make x-faces.el try to use XtDefaultFont. The problem with that is that | |
71 | XtDefaultFont is almost certainly variable-width. | |
72 | ||
73 | #### Perhaps we could have this code explicitly set XtDefaultFont to this? | |
74 | */ | |
75 | #define DEFAULT_FACE_FONT "-*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*" | |
76 | ||
77 | ||
ebd15611 DN |
78 | static void EmacsFrameInitialize (Widget request, Widget new, ArgList dum1, Cardinal *dum2); |
79 | static void EmacsFrameDestroy (Widget widget); | |
80 | static void EmacsFrameRealize (Widget widget, XtValueMask *mask, XSetWindowAttributes *attrs); | |
4475bec4 | 81 | static void EmacsFrameResize (Widget widget); |
ebd15611 DN |
82 | static Boolean EmacsFrameSetValues (Widget cur_widget, Widget req_widget, Widget new_widget, ArgList dum1, Cardinal *dum2); |
83 | static XtGeometryResult EmacsFrameQueryGeometry (Widget widget, XtWidgetGeometry *request, XtWidgetGeometry *result); | |
07bf635f RS |
84 | |
85 | ||
86 | #undef XtOffset | |
87 | #define XtOffset(p_type,field) \ | |
88 | ((Cardinal) (((char *) (&(((p_type)0)->field))) - ((char *)0))) | |
5e617bc2 | 89 | #define offset(field) XtOffset (EmacsFrame, emacs_frame.field) |
07bf635f RS |
90 | |
91 | static XtResource resources[] = { | |
5e617bc2 | 92 | {XtNgeometry, XtCGeometry, XtRString, sizeof (String), |
07bf635f | 93 | offset (geometry), XtRString, (XtPointer) 0}, |
5e617bc2 | 94 | {XtNiconic, XtCIconic, XtRBoolean, sizeof (Boolean), |
07bf635f RS |
95 | offset (iconic), XtRImmediate, (XtPointer) False}, |
96 | ||
97 | {XtNemacsFrame, XtCEmacsFrame, XtRPointer, sizeof (XtPointer), | |
98 | offset (frame), XtRImmediate, 0}, | |
99 | ||
100 | {XtNminibuffer, XtCMinibuffer, XtRInt, sizeof (int), | |
101 | offset (minibuffer), XtRImmediate, (XtPointer)0}, | |
102 | {XtNunsplittable, XtCUnsplittable, XtRBoolean, sizeof (Boolean), | |
103 | offset (unsplittable), XtRImmediate, (XtPointer)0}, | |
104 | {XtNinternalBorderWidth, XtCInternalBorderWidth, XtRInt, sizeof (int), | |
105 | offset (internal_border_width), XtRImmediate, (XtPointer)4}, | |
106 | {XtNinterline, XtCInterline, XtRInt, sizeof (int), | |
107 | offset (interline), XtRImmediate, (XtPointer)0}, | |
5e617bc2 JB |
108 | {XtNfont, XtCFont, XtRFontStruct, sizeof (struct font *), |
109 | offset (font),XtRString, DEFAULT_FACE_FONT}, | |
110 | {XtNforeground, XtCForeground, XtRPixel, sizeof (Pixel), | |
111 | offset (foreground_pixel), XtRString, "XtDefaultForeground"}, | |
112 | {XtNcursorColor, XtCForeground, XtRPixel, sizeof (Pixel), | |
113 | offset (cursor_color), XtRString, "XtDefaultForeground"}, | |
07bf635f RS |
114 | {XtNbarCursor, XtCBarCursor, XtRBoolean, sizeof (Boolean), |
115 | offset (bar_cursor), XtRImmediate, (XtPointer)0}, | |
116 | {XtNvisualBell, XtCVisualBell, XtRBoolean, sizeof (Boolean), | |
117 | offset (visual_bell), XtRImmediate, (XtPointer)0}, | |
118 | {XtNbellVolume, XtCBellVolume, XtRInt, sizeof (int), | |
119 | offset (bell_volume), XtRImmediate, (XtPointer)0}, | |
120 | }; | |
121 | ||
122 | #undef offset | |
123 | ||
124 | /* | |
125 | static XtActionsRec | |
126 | emacsFrameActionsTable [] = { | |
127 | {"keypress", key_press}, | |
128 | {"focus_in", emacs_frame_focus_handler}, | |
129 | {"focus_out", emacs_frame_focus_handler}, | |
130 | }; | |
131 | ||
132 | static char | |
133 | emacsFrameTranslations [] = "\ | |
134 | <KeyPress>: keypress()\n\ | |
135 | <FocusIn>: focus_in()\n\ | |
136 | <FocusOut>: focus_out()\n\ | |
137 | "; | |
138 | */ | |
139 | ||
4475bec4 | 140 | static EmacsFrameClassRec emacsFrameClassRec = { |
07bf635f RS |
141 | { /* core fields */ |
142 | /* superclass */ &widgetClassRec, | |
143 | /* class_name */ "EmacsFrame", | |
5e617bc2 | 144 | /* widget_size */ sizeof (EmacsFrameRec), |
07bf635f RS |
145 | /* class_initialize */ 0, |
146 | /* class_part_initialize */ 0, | |
147 | /* class_inited */ FALSE, | |
148 | /* initialize */ EmacsFrameInitialize, | |
149 | /* initialize_hook */ 0, | |
150 | /* realize */ EmacsFrameRealize, | |
151 | /* actions */ 0, /*emacsFrameActionsTable*/ | |
152 | /* num_actions */ 0, /*XtNumber (emacsFrameActionsTable)*/ | |
153 | /* resources */ resources, | |
5e617bc2 | 154 | /* resource_count */ XtNumber (resources), |
07bf635f RS |
155 | /* xrm_class */ NULLQUARK, |
156 | /* compress_motion */ TRUE, | |
157 | /* compress_exposure */ TRUE, | |
158 | /* compress_enterleave */ TRUE, | |
159 | /* visible_interest */ FALSE, | |
160 | /* destroy */ EmacsFrameDestroy, | |
161 | /* resize */ EmacsFrameResize, | |
162 | /* expose */ XtInheritExpose, | |
163 | /* set_values */ EmacsFrameSetValues, | |
164 | /* set_values_hook */ 0, | |
165 | /* set_values_almost */ XtInheritSetValuesAlmost, | |
166 | /* get_values_hook */ 0, | |
167 | /* accept_focus */ XtInheritAcceptFocus, | |
168 | /* version */ XtVersion, | |
169 | /* callback_private */ 0, | |
170 | /* tm_table */ 0, /*emacsFrameTranslations*/ | |
171 | /* query_geometry */ EmacsFrameQueryGeometry, | |
172 | /* display_accelerator */ XtInheritDisplayAccelerator, | |
173 | /* extension */ 0 | |
174 | } | |
175 | }; | |
176 | ||
177 | WidgetClass emacsFrameClass = (WidgetClass) &emacsFrameClassRec; | |
178 | ||
179 | static void | |
ebd15611 | 180 | get_default_char_pixel_size (EmacsFrame ew, int *pixel_width, int *pixel_height) |
07bf635f | 181 | { |
07bf635f | 182 | struct frame* f = ew->emacs_frame.frame; |
90022f5a KS |
183 | *pixel_width = FRAME_COLUMN_WIDTH (f); |
184 | *pixel_height = FRAME_LINE_HEIGHT (f); | |
07bf635f RS |
185 | } |
186 | ||
187 | static void | |
ebd15611 | 188 | pixel_to_char_size (EmacsFrame ew, Dimension pixel_width, Dimension pixel_height, int *char_width, int *char_height) |
07bf635f RS |
189 | { |
190 | struct frame* f = ew->emacs_frame.frame; | |
90022f5a KS |
191 | *char_width = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, (int) pixel_width); |
192 | *char_height = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, (int) pixel_height); | |
07bf635f RS |
193 | } |
194 | ||
195 | static void | |
ebd15611 | 196 | char_to_pixel_size (EmacsFrame ew, int char_width, int char_height, Dimension *pixel_width, Dimension *pixel_height) |
07bf635f RS |
197 | { |
198 | struct frame* f = ew->emacs_frame.frame; | |
90022f5a KS |
199 | *pixel_width = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, char_width); |
200 | *pixel_height = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, char_height); | |
07bf635f RS |
201 | } |
202 | ||
203 | static void | |
ebd15611 | 204 | round_size_to_char (EmacsFrame ew, Dimension in_width, Dimension in_height, Dimension *out_width, Dimension *out_height) |
07bf635f RS |
205 | { |
206 | int char_width; | |
207 | int char_height; | |
208 | pixel_to_char_size (ew, in_width, in_height, &char_width, &char_height); | |
209 | char_to_pixel_size (ew, char_width, char_height, out_width, out_height); | |
210 | } | |
211 | ||
212 | static Widget | |
ebd15611 | 213 | get_wm_shell (Widget w) |
07bf635f RS |
214 | { |
215 | Widget wmshell; | |
216 | ||
217 | for (wmshell = XtParent (w); | |
218 | wmshell && !XtIsWMShell (wmshell); | |
219 | wmshell = XtParent (wmshell)); | |
220 | ||
221 | return wmshell; | |
222 | } | |
223 | ||
ccce6056 GM |
224 | #if 0 /* Currently not used. */ |
225 | ||
07bf635f | 226 | static void |
1dae0f0a | 227 | mark_shell_size_user_specified (Widget wmshell) |
07bf635f RS |
228 | { |
229 | if (! XtIsWMShell (wmshell)) abort (); | |
230 | /* This is kind of sleazy, but I can't see how else to tell it to make it | |
231 | mark the WM_SIZE_HINTS size as user specified when appropriate. */ | |
232 | ((WMShellWidget) wmshell)->wm.size_hints.flags |= USSize; | |
233 | } | |
234 | ||
ccce6056 GM |
235 | #endif |
236 | ||
07bf635f RS |
237 | |
238 | /* Can't have static frame locals because of some broken compilers. | |
239 | Normally, initializing a variable like this doesn't work in emacs, | |
240 | but it's ok in this file because it must come after lastfile (and | |
241 | thus have its data not go into text space) because Xt needs to | |
242 | write to initialized data objects too. | |
243 | */ | |
ccce6056 | 244 | #if 0 |
07bf635f | 245 | static Boolean first_frame_p = True; |
ccce6056 | 246 | #endif |
07bf635f RS |
247 | |
248 | static void | |
ebd15611 | 249 | set_frame_size (EmacsFrame ew) |
07bf635f RS |
250 | { |
251 | /* The widget hierarchy is | |
252 | ||
253 | argv[0] emacsShell pane Frame-NAME | |
254 | ApplicationShell EmacsShell Paned EmacsFrame | |
255 | ||
256 | We accept geometry specs in this order: | |
257 | ||
258 | *Frame-NAME.geometry | |
259 | *EmacsFrame.geometry | |
260 | Emacs.geometry | |
261 | ||
262 | Other possibilities for widget hierarchies might be | |
263 | ||
264 | argv[0] frame pane Frame-NAME | |
265 | ApplicationShell EmacsShell Paned EmacsFrame | |
266 | or | |
267 | argv[0] Frame-NAME pane Frame-NAME | |
268 | ApplicationShell EmacsShell Paned EmacsFrame | |
269 | or | |
270 | argv[0] Frame-NAME pane emacsTextPane | |
271 | ApplicationShell EmacsFrame Paned EmacsTextPane | |
272 | ||
273 | With the current setup, the text-display-area is the part which is | |
274 | an emacs "frame", since that's the only part managed by emacs proper | |
275 | (the menubar and the parent of the menubar and all that sort of thing | |
276 | are managed by lwlib.) | |
277 | ||
177c0ea7 | 278 | The EmacsShell widget is simply a replacement for the Shell widget |
07bf635f RS |
279 | which is able to deal with using an externally-supplied window instead |
280 | of always creating its own. It is not actually emacs specific, and | |
281 | should possibly have class "Shell" instead of "EmacsShell" to simplify | |
282 | the resources. | |
283 | ||
284 | */ | |
285 | ||
07bf635f | 286 | /* Hairily merged geometry */ |
90022f5a KS |
287 | unsigned int w = FRAME_COLS (ew->emacs_frame.frame); |
288 | unsigned int h = FRAME_LINES (ew->emacs_frame.frame); | |
177c0ea7 | 289 | |
07bf635f | 290 | Widget wmshell = get_wm_shell ((Widget) ew); |
38971c41 | 291 | /* Each Emacs shell is now independent and top-level. */ |
177c0ea7 | 292 | |
07bf635f | 293 | if (! XtIsSubclass (wmshell, shellWidgetClass)) abort (); |
07bf635f | 294 | |
177c0ea7 | 295 | /* We don't need this for the moment. The geometry is computed in |
edaf359b FP |
296 | xfns.c. */ |
297 | #if 0 | |
07bf635f RS |
298 | /* If the EmacsFrame doesn't have a geometry but the shell does, |
299 | treat that as the geometry of the frame. (Is this bogus? | |
300 | I'm not sure.) */ | |
301 | if (ew->emacs_frame.geometry == 0) | |
c52e7aa6 | 302 | XtVaGetValues (wmshell, XtNgeometry, &ew->emacs_frame.geometry, NULL); |
07bf635f RS |
303 | |
304 | /* If the Shell is iconic, then the EmacsFrame is iconic. (Is | |
305 | this bogus? I'm not sure.) */ | |
306 | if (!ew->emacs_frame.iconic) | |
c52e7aa6 | 307 | XtVaGetValues (wmshell, XtNiconic, &ew->emacs_frame.iconic, NULL); |
177c0ea7 JB |
308 | |
309 | ||
07bf635f RS |
310 | { |
311 | char *geom = 0; | |
c52e7aa6 | 312 | XtVaGetValues (app_shell, XtNgeometry, &geom, NULL); |
07bf635f RS |
313 | if (geom) |
314 | app_flags = XParseGeometry (geom, &app_x, &app_y, &app_w, &app_h); | |
315 | } | |
177c0ea7 | 316 | |
07bf635f RS |
317 | if (ew->emacs_frame.geometry) |
318 | frame_flags = XParseGeometry (ew->emacs_frame.geometry, | |
319 | &frame_x, &frame_y, | |
320 | &frame_w, &frame_h); | |
177c0ea7 | 321 | |
07bf635f RS |
322 | if (first_frame_p) |
323 | { | |
324 | /* If this is the first frame created: | |
325 | ==================================== | |
326 | ||
327 | - Use the ApplicationShell's size/position, if specified. | |
328 | (This is "Emacs.geometry", or the "-geometry" command line arg.) | |
329 | - Else use the EmacsFrame's size/position. | |
330 | (This is "*Frame-NAME.geometry") | |
331 | ||
332 | - If the AppShell is iconic, the frame should be iconic. | |
333 | ||
334 | AppShell comes first so that -geometry always applies to the first | |
335 | frame created, even if there is an "every frame" entry in the | |
336 | resource database. | |
337 | */ | |
338 | if (app_flags & (XValue | YValue)) | |
339 | { | |
340 | x = app_x; y = app_y; | |
341 | flags |= (app_flags & (XValue | YValue | XNegative | YNegative)); | |
342 | } | |
343 | else if (frame_flags & (XValue | YValue)) | |
344 | { | |
345 | x = frame_x; y = frame_y; | |
346 | flags |= (frame_flags & (XValue | YValue | XNegative | YNegative)); | |
347 | } | |
348 | ||
349 | if (app_flags & (WidthValue | HeightValue)) | |
350 | { | |
351 | w = app_w; h = app_h; | |
352 | flags |= (app_flags & (WidthValue | HeightValue)); | |
353 | } | |
354 | else if (frame_flags & (WidthValue | HeightValue)) | |
355 | { | |
356 | w = frame_w; h = frame_h; | |
357 | flags |= (frame_flags & (WidthValue | HeightValue)); | |
358 | } | |
359 | ||
360 | /* If the AppShell is iconic, then the EmacsFrame is iconic. */ | |
361 | if (!ew->emacs_frame.iconic) | |
c52e7aa6 | 362 | XtVaGetValues (app_shell, XtNiconic, &ew->emacs_frame.iconic, NULL); |
07bf635f RS |
363 | |
364 | first_frame_p = False; | |
365 | } | |
366 | else | |
367 | { | |
368 | /* If this is not the first frame created: | |
369 | ======================================== | |
370 | ||
371 | - use the EmacsFrame's size/position if specified | |
372 | - Otherwise, use the ApplicationShell's size, but not position. | |
373 | ||
374 | So that means that one can specify the position of the first frame | |
375 | with "Emacs.geometry" or `-geometry'; but can only specify the | |
376 | position of subsequent frames with "*Frame-NAME.geometry". | |
377 | ||
378 | AppShell comes second so that -geometry does not apply to subsequent | |
379 | frames when there is an "every frame" entry in the resource db, | |
380 | but does apply to the first frame. | |
381 | */ | |
382 | if (frame_flags & (XValue | YValue)) | |
383 | { | |
384 | x = frame_x; y = frame_y; | |
385 | flags |= (frame_flags & (XValue | YValue | XNegative | YNegative)); | |
386 | } | |
387 | ||
388 | if (frame_flags & (WidthValue | HeightValue)) | |
389 | { | |
390 | w = frame_w; h = frame_h; | |
391 | flags |= (frame_flags & (WidthValue | HeightValue)); | |
392 | } | |
393 | else if (app_flags & (WidthValue | HeightValue)) | |
394 | { | |
395 | w = app_w; | |
396 | h = app_h; | |
397 | flags |= (app_flags & (WidthValue | HeightValue)); | |
398 | } | |
399 | } | |
edaf359b | 400 | #endif /* 0 */ |
07bf635f | 401 | { |
90022f5a | 402 | struct frame *f = ew->emacs_frame.frame; |
07bf635f | 403 | Dimension pixel_width, pixel_height; |
07bf635f | 404 | |
f403d3c3 GM |
405 | /* Take into account the size of the scrollbar. Always use the |
406 | number of columns occupied by the scroll bar here otherwise we | |
407 | might end up with a frame width that is not a multiple of the | |
408 | frame's character width which is bad for vertically split | |
409 | windows. */ | |
90022f5a KS |
410 | f->scroll_bar_actual_width |
411 | = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f); | |
07bf635f | 412 | |
90022f5a | 413 | compute_fringe_widths (f, 0); |
f403d3c3 | 414 | |
de70f8b6 RS |
415 | #if 0 /* This can run Lisp code, and it is dangerous to give |
416 | out the frame to Lisp code before it officially exists. | |
417 | This is handled in Fx_create_frame so not needed here. */ | |
90022f5a | 418 | change_frame_size (f, h, w, 1, 0, 0); |
de70f8b6 | 419 | #endif |
07bf635f RS |
420 | char_to_pixel_size (ew, w, h, &pixel_width, &pixel_height); |
421 | ew->core.width = pixel_width; | |
422 | ew->core.height = pixel_height; | |
423 | ||
6ae9a3f2 | 424 | #if 0 /* xfns.c takes care of this now. */ |
07bf635f RS |
425 | /* If a position was specified, assign it to the shell widget. |
426 | (Else WM won't do anything with it.) | |
427 | */ | |
428 | if (flags & (XValue | YValue)) | |
429 | { | |
430 | /* the tricky things with the sign is to make sure that | |
431 | -0 is printed -0. */ | |
432 | int len; | |
433 | char *tem; | |
434 | sprintf (shell_position, "=%c%d%c%d", | |
435 | flags & XNegative ? '-' : '+', x < 0 ? -x : x, | |
436 | flags & YNegative ? '-' : '+', y < 0 ? -y : y); | |
437 | len = strlen (shell_position) + 1; | |
438 | tem = (char *) xmalloc (len); | |
439 | strncpy (tem, shell_position, len); | |
c52e7aa6 | 440 | XtVaSetValues (wmshell, XtNgeometry, tem, NULL); |
07bf635f RS |
441 | } |
442 | else if (flags & (WidthValue | HeightValue)) | |
443 | { | |
444 | int len; | |
445 | char *tem; | |
446 | sprintf (shell_position, "=%dx%d", pixel_width, pixel_height); | |
447 | len = strlen (shell_position) + 1; | |
448 | tem = (char *) xmalloc (len); | |
449 | strncpy (tem, shell_position, len); | |
c52e7aa6 | 450 | XtVaSetValues (wmshell, XtNgeometry, tem, NULL); |
07bf635f RS |
451 | } |
452 | ||
453 | /* If the geometry spec we're using has W/H components, mark the size | |
454 | in the WM_SIZE_HINTS as user specified. */ | |
455 | if (flags & (WidthValue | HeightValue)) | |
456 | mark_shell_size_user_specified (wmshell); | |
457 | ||
458 | /* Also assign the iconic status of the frame to the Shell, so that | |
459 | the WM sees it. */ | |
c52e7aa6 | 460 | XtVaSetValues (wmshell, XtNiconic, ew->emacs_frame.iconic, NULL); |
edaf359b | 461 | #endif /* 0 */ |
07bf635f RS |
462 | } |
463 | } | |
464 | ||
07bf635f | 465 | static void |
ebd15611 | 466 | update_wm_hints (EmacsFrame ew) |
07bf635f RS |
467 | { |
468 | Widget wmshell = get_wm_shell ((Widget)ew); | |
469 | int cw; | |
470 | int ch; | |
471 | Dimension rounded_width; | |
472 | Dimension rounded_height; | |
473 | int char_width; | |
474 | int char_height; | |
475 | int base_width; | |
476 | int base_height; | |
477 | int min_rows = 0, min_cols = 0; | |
478 | ||
cfcd12d6 | 479 | #if 0 |
07bf635f | 480 | check_frame_size (ew->emacs_frame.frame, &min_rows, &min_cols); |
cfcd12d6 | 481 | #endif |
07bf635f RS |
482 | |
483 | pixel_to_char_size (ew, ew->core.width, ew->core.height, | |
484 | &char_width, &char_height); | |
485 | char_to_pixel_size (ew, char_width, char_height, | |
486 | &rounded_width, &rounded_height); | |
177c0ea7 | 487 | get_default_char_pixel_size (ew, &cw, &ch); |
07bf635f RS |
488 | |
489 | base_width = (wmshell->core.width - ew->core.width | |
490 | + (rounded_width - (char_width * cw))); | |
491 | base_height = (wmshell->core.height - ew->core.height | |
492 | + (rounded_height - (char_height * ch))); | |
493 | ||
494 | /* This is kind of sleazy, but I can't see how else to tell it to | |
495 | make it mark the WM_SIZE_HINTS size as user specified. | |
496 | */ | |
497 | /* ((WMShellWidget) wmshell)->wm.size_hints.flags |= USSize;*/ | |
498 | ||
499 | XtVaSetValues (wmshell, | |
cbec8c51 GM |
500 | XtNbaseWidth, (XtArgVal) base_width, |
501 | XtNbaseHeight, (XtArgVal) base_height, | |
177c0ea7 | 502 | XtNwidthInc, (XtArgVal) cw, |
cbec8c51 GM |
503 | XtNheightInc, (XtArgVal) ch, |
504 | XtNminWidth, (XtArgVal) (base_width + min_cols * cw), | |
505 | XtNminHeight, (XtArgVal) (base_height + min_rows * ch), | |
c52e7aa6 | 506 | NULL); |
07bf635f RS |
507 | } |
508 | ||
ccce6056 GM |
509 | #if 0 |
510 | ||
07bf635f | 511 | static void |
1dae0f0a | 512 | create_frame_gcs (EmacsFrame ew) |
07bf635f | 513 | { |
7f18598b | 514 | struct frame *s = ew->emacs_frame.frame; |
07bf635f | 515 | |
54e9e953 | 516 | s->output_data.x->normal_gc |
578c21e6 | 517 | = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0); |
54e9e953 | 518 | s->output_data.x->reverse_gc |
578c21e6 | 519 | = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0); |
54e9e953 | 520 | s->output_data.x->cursor_gc |
578c21e6 | 521 | = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0); |
f403d3c3 GM |
522 | s->output_data.x->black_relief.gc = 0; |
523 | s->output_data.x->white_relief.gc = 0; | |
07bf635f RS |
524 | } |
525 | ||
ccce6056 GM |
526 | #endif /* 0 */ |
527 | ||
1ad2277b RS |
528 | static char setup_frame_cursor_bits[] = |
529 | { | |
530 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
531 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
532 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
533 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
534 | }; | |
535 | ||
07bf635f | 536 | static void |
ebd15611 | 537 | setup_frame_gcs (EmacsFrame ew) |
07bf635f RS |
538 | { |
539 | XGCValues gc_values; | |
540 | struct frame* s = ew->emacs_frame.frame; | |
541 | Pixmap blank_stipple, blank_tile; | |
39d14c25 CY |
542 | unsigned long valuemask = (GCForeground | GCBackground | GCGraphicsExposures |
543 | | GCStipple | GCTile); | |
544 | Lisp_Object font; | |
545 | ||
546 | XSETFONT (font, ew->emacs_frame.font); | |
547 | font = Ffont_xlfd_name (font, Qnil); | |
548 | if (STRINGP (font)) | |
549 | { | |
550 | XFontStruct *xfont = XLoadQueryFont (FRAME_X_DISPLAY_INFO (s)->display, | |
42a5b22f | 551 | SSDATA (font)); |
39d14c25 CY |
552 | if (xfont) |
553 | { | |
554 | gc_values.font = xfont->fid; | |
555 | valuemask |= GCFont; | |
556 | } | |
557 | } | |
07bf635f | 558 | |
07bf635f RS |
559 | /* We have to initialize all of our GCs to have a stipple/tile, otherwise |
560 | XGetGCValues returns uninitialized data when we query the stipple | |
561 | (instead of None or something sensible) and it makes things hard. | |
562 | ||
563 | This should be fixed for real by not querying the GCs but instead having | |
564 | some GC-based cache instead of the current face-based cache which doesn't | |
565 | effectively cache all of the GC settings we need to use. | |
566 | */ | |
567 | ||
85e53327 KH |
568 | blank_stipple |
569 | = XCreateBitmapFromData (XtDisplay (ew), | |
570 | RootWindowOfScreen (XtScreen (ew)), | |
571 | setup_frame_cursor_bits, 2, 2); | |
07bf635f RS |
572 | |
573 | /* use fg = 0, bg = 1 below, but it's irrelevant since this pixmap should | |
574 | never actually get used as a background tile! | |
575 | */ | |
85e53327 | 576 | blank_tile |
5e617bc2 | 577 | = XCreatePixmapFromBitmapData (XtDisplay (ew), |
85e53327 KH |
578 | RootWindowOfScreen (XtScreen (ew)), |
579 | setup_frame_cursor_bits, 2, 2, | |
578c21e6 | 580 | 0, 1, ew->core.depth); |
07bf635f RS |
581 | |
582 | /* Normal video */ | |
07bf635f RS |
583 | gc_values.foreground = ew->emacs_frame.foreground_pixel; |
584 | gc_values.background = ew->core.background_pixel; | |
585 | gc_values.graphics_exposures = False; | |
586 | gc_values.stipple = blank_stipple; | |
587 | gc_values.tile = blank_tile; | |
54e9e953 | 588 | XChangeGC (XtDisplay (ew), s->output_data.x->normal_gc, |
39d14c25 | 589 | valuemask, &gc_values); |
07bf635f RS |
590 | |
591 | /* Reverse video style. */ | |
07bf635f RS |
592 | gc_values.foreground = ew->core.background_pixel; |
593 | gc_values.background = ew->emacs_frame.foreground_pixel; | |
594 | gc_values.graphics_exposures = False; | |
595 | gc_values.stipple = blank_stipple; | |
596 | gc_values.tile = blank_tile; | |
54e9e953 | 597 | XChangeGC (XtDisplay (ew), s->output_data.x->reverse_gc, |
39d14c25 | 598 | valuemask, &gc_values); |
07bf635f RS |
599 | |
600 | /* Cursor has to have an empty stipple. */ | |
07bf635f RS |
601 | gc_values.foreground = ew->core.background_pixel; |
602 | gc_values.background = ew->emacs_frame.cursor_color; | |
603 | gc_values.graphics_exposures = False; | |
604 | gc_values.tile = blank_tile; | |
85e53327 KH |
605 | gc_values.stipple |
606 | = XCreateBitmapFromData (XtDisplay (ew), | |
607 | RootWindowOfScreen (XtScreen (ew)), | |
608 | setup_frame_cursor_bits, 16, 16); | |
54e9e953 | 609 | XChangeGC (XtDisplay (ew), s->output_data.x->cursor_gc, |
39d14c25 | 610 | valuemask, &gc_values); |
07bf635f RS |
611 | } |
612 | ||
613 | static void | |
ebd15611 | 614 | update_various_frame_slots (EmacsFrame ew) |
07bf635f | 615 | { |
90022f5a KS |
616 | struct frame *f = ew->emacs_frame.frame; |
617 | struct x_output *x = f->output_data.x; | |
618 | FRAME_PIXEL_HEIGHT (f) = ew->core.height + x->menubar_height; | |
619 | FRAME_PIXEL_WIDTH (f) = ew->core.width; | |
620 | f->internal_border_width = ew->emacs_frame.internal_border_width; | |
07bf635f RS |
621 | |
622 | } | |
623 | ||
624 | static void | |
ebd15611 | 625 | update_from_various_frame_slots (EmacsFrame ew) |
07bf635f | 626 | { |
90022f5a KS |
627 | struct frame *f = ew->emacs_frame.frame; |
628 | struct x_output *x = f->output_data.x; | |
629 | ew->core.height = FRAME_PIXEL_HEIGHT (f) - x->menubar_height; | |
630 | ew->core.width = FRAME_PIXEL_WIDTH (f); | |
ce593f6e | 631 | ew->core.background_pixel = FRAME_BACKGROUND_PIXEL (f); |
90022f5a | 632 | ew->emacs_frame.internal_border_width = f->internal_border_width; |
07bf635f | 633 | ew->emacs_frame.font = x->font; |
ce593f6e | 634 | ew->emacs_frame.foreground_pixel = FRAME_FOREGROUND_PIXEL (f); |
07bf635f RS |
635 | ew->emacs_frame.cursor_color = x->cursor_pixel; |
636 | ew->core.border_pixel = x->border_pixel; | |
637 | } | |
638 | ||
177c0ea7 | 639 | static void |
ebd15611 | 640 | EmacsFrameInitialize (Widget request, Widget new, ArgList dum1, Cardinal *dum2) |
07bf635f RS |
641 | { |
642 | EmacsFrame ew = (EmacsFrame)new; | |
643 | ||
644 | if (!ew->emacs_frame.frame) | |
645 | { | |
646 | fprintf (stderr, | |
647 | "can't create an emacs frame widget without a frame\n"); | |
648 | exit (1); | |
649 | } | |
650 | ||
07bf635f | 651 | update_from_various_frame_slots (ew); |
177c0ea7 | 652 | set_frame_size (ew); |
07bf635f RS |
653 | } |
654 | ||
655 | ||
656 | static void | |
ebd15611 | 657 | EmacsFrameRealize (Widget widget, XtValueMask *mask, XSetWindowAttributes *attrs) |
07bf635f RS |
658 | { |
659 | EmacsFrame ew = (EmacsFrame)widget; | |
660 | ||
486a103d GM |
661 | /* This used to contain SubstructureRedirectMask, but this turns out |
662 | to be a problem with XIM on Solaris, and events from that mask | |
2fce2bb4 | 663 | don't seem to be used. Let's check that. */ |
486a103d GM |
664 | attrs->event_mask = (STANDARD_EVENT_SET |
665 | | PropertyChangeMask | |
666 | | SubstructureNotifyMask); | |
07bf635f RS |
667 | *mask |= CWEventMask; |
668 | XtCreateWindow (widget, InputOutput, (Visual *)CopyFromParent, *mask, | |
669 | attrs); | |
177c0ea7 | 670 | update_wm_hints (ew); |
07bf635f RS |
671 | } |
672 | ||
ebd15611 | 673 | extern void free_frame_faces (struct frame *); |
07bf635f RS |
674 | |
675 | static void | |
ebd15611 | 676 | EmacsFrameDestroy (Widget widget) |
07bf635f RS |
677 | { |
678 | EmacsFrame ew = (EmacsFrame) widget; | |
679 | struct frame* s = ew->emacs_frame.frame; | |
680 | ||
681 | if (! s) abort (); | |
54e9e953 | 682 | if (! s->output_data.x) abort (); |
07bf635f | 683 | |
49fe12a9 | 684 | BLOCK_INPUT; |
0dea0fed | 685 | x_free_gcs (s); |
f403d3c3 GM |
686 | if (s->output_data.x->white_relief.gc) |
687 | XFreeGC (XtDisplay (widget), s->output_data.x->white_relief.gc); | |
688 | if (s->output_data.x->black_relief.gc) | |
689 | XFreeGC (XtDisplay (widget), s->output_data.x->black_relief.gc); | |
49fe12a9 | 690 | UNBLOCK_INPUT; |
07bf635f RS |
691 | } |
692 | ||
4475bec4 | 693 | static void |
ebd15611 | 694 | EmacsFrameResize (Widget widget) |
07bf635f RS |
695 | { |
696 | EmacsFrame ew = (EmacsFrame)widget; | |
697 | struct frame *f = ew->emacs_frame.frame; | |
698 | int columns; | |
699 | int rows; | |
700 | ||
701 | pixel_to_char_size (ew, ew->core.width, ew->core.height, &columns, &rows); | |
2b653806 | 702 | change_frame_size (f, rows, columns, 0, 1, 0); |
177c0ea7 | 703 | update_wm_hints (ew); |
07bf635f | 704 | update_various_frame_slots (ew); |
49feb47d RS |
705 | |
706 | cancel_mouse_face (f); | |
07bf635f RS |
707 | } |
708 | ||
709 | static Boolean | |
ebd15611 | 710 | EmacsFrameSetValues (Widget cur_widget, Widget req_widget, Widget new_widget, ArgList dum1, Cardinal *dum2) |
07bf635f RS |
711 | { |
712 | EmacsFrame cur = (EmacsFrame)cur_widget; | |
713 | EmacsFrame new = (EmacsFrame)new_widget; | |
714 | ||
715 | Boolean needs_a_refresh = False; | |
716 | Boolean has_to_recompute_size; | |
717 | Boolean has_to_recompute_gcs; | |
718 | Boolean has_to_update_hints; | |
719 | ||
720 | int char_width, char_height; | |
721 | Dimension pixel_width; | |
722 | Dimension pixel_height; | |
177c0ea7 | 723 | |
5c646d5a | 724 | /* AFAIK, this function is never called. -- Jan D, Oct 2009. */ |
07bf635f RS |
725 | has_to_recompute_gcs = (cur->emacs_frame.font != new->emacs_frame.font |
726 | || (cur->emacs_frame.foreground_pixel | |
727 | != new->emacs_frame.foreground_pixel) | |
728 | || (cur->core.background_pixel | |
729 | != new->core.background_pixel) | |
730 | ); | |
177c0ea7 | 731 | |
07bf635f RS |
732 | has_to_recompute_size = (cur->emacs_frame.font != new->emacs_frame.font |
733 | && cur->core.width == new->core.width | |
734 | && cur->core.height == new->core.height); | |
735 | ||
736 | has_to_update_hints = (cur->emacs_frame.font != new->emacs_frame.font); | |
737 | ||
738 | if (has_to_recompute_gcs) | |
739 | { | |
740 | setup_frame_gcs (new); | |
741 | needs_a_refresh = True; | |
742 | } | |
177c0ea7 | 743 | |
07bf635f RS |
744 | if (has_to_recompute_size) |
745 | { | |
746 | pixel_width = new->core.width; | |
747 | pixel_height = new->core.height; | |
748 | pixel_to_char_size (new, pixel_width, pixel_height, &char_width, | |
749 | &char_height); | |
750 | char_to_pixel_size (new, char_width, char_height, &pixel_width, | |
751 | &pixel_height); | |
752 | new->core.width = pixel_width; | |
753 | new->core.height = pixel_height; | |
754 | ||
755 | change_frame_size (new->emacs_frame.frame, char_height, char_width, | |
2b653806 | 756 | 1, 0, 0); |
07bf635f RS |
757 | needs_a_refresh = True; |
758 | } | |
759 | ||
760 | if (has_to_update_hints) | |
761 | update_wm_hints (new); | |
762 | ||
763 | update_various_frame_slots (new); | |
764 | ||
765 | /* #### This doesn't work, I haven't been able to find ANY kludge that | |
766 | will let (x-create-frame '((iconic . t))) work. It seems that changes | |
767 | to wm_shell's iconic slot have no effect after it has been realized, | |
2dd5c7f7 | 768 | and calling XIconifyWindow doesn't work either (even though the window |
07bf635f | 769 | has been created.) Perhaps there is some property we could smash |
ac26ca64 | 770 | directly, but I'm sick of this for now. |
07bf635f RS |
771 | */ |
772 | if (cur->emacs_frame.iconic != new->emacs_frame.iconic) | |
773 | { | |
774 | Widget wmshell = get_wm_shell ((Widget) cur); | |
cbec8c51 GM |
775 | XtVaSetValues (wmshell, XtNiconic, |
776 | (XtArgVal) new->emacs_frame.iconic, NULL); | |
07bf635f RS |
777 | } |
778 | ||
779 | return needs_a_refresh; | |
780 | } | |
781 | ||
782 | static XtGeometryResult | |
ebd15611 | 783 | EmacsFrameQueryGeometry (Widget widget, XtWidgetGeometry *request, XtWidgetGeometry *result) |
07bf635f RS |
784 | { |
785 | EmacsFrame ew = (EmacsFrame)widget; | |
786 | ||
787 | int mask = request->request_mode; | |
788 | Dimension ok_width, ok_height; | |
789 | ||
790 | if (mask & (CWWidth | CWHeight)) | |
791 | { | |
792 | round_size_to_char (ew, | |
793 | (mask & CWWidth) ? request->width : ew->core.width, | |
794 | ((mask & CWHeight) ? request->height | |
795 | : ew->core.height), | |
796 | &ok_width, &ok_height); | |
797 | if ((mask & CWWidth) && (ok_width != request->width)) | |
798 | { | |
799 | result->request_mode |= CWWidth; | |
800 | result->width = ok_width; | |
801 | } | |
802 | if ((mask & CWHeight) && (ok_height != request->height)) | |
803 | { | |
804 | result->request_mode |= CWHeight; | |
805 | result->height = ok_height; | |
806 | } | |
807 | } | |
808 | return result->request_mode ? XtGeometryAlmost : XtGeometryYes; | |
809 | } | |
810 | ||
07bf635f RS |
811 | /* Special entrypoints */ |
812 | void | |
ebd15611 | 813 | EmacsFrameSetCharSize (Widget widget, int columns, int rows) |
07bf635f RS |
814 | { |
815 | EmacsFrame ew = (EmacsFrame) widget; | |
982a94d9 | 816 | struct frame *f = ew->emacs_frame.frame; |
177c0ea7 | 817 | |
5c646d5a | 818 | x_set_window_size (f, 0, columns, rows); |
07bf635f | 819 | } |
f403d3c3 | 820 | |
d793b105 | 821 | \f |
dfcf069d | 822 | void |
ebd15611 | 823 | widget_store_internal_border (Widget widget) |
d793b105 RS |
824 | { |
825 | EmacsFrame ew = (EmacsFrame) widget; | |
826 | FRAME_PTR f = ew->emacs_frame.frame; | |
827 | ||
90022f5a | 828 | ew->emacs_frame.internal_border_width = f->internal_border_width; |
d793b105 | 829 | } |