Mercurial > emacs
annotate src/widget.c @ 5695:6d93eb3d5bc7
(diary-day-of-year, diary-iso-date, diary-islamic-date,
diary-hebrew-date, diary-julian-date, diary-astro-day-number):
Use new functions from calendar.el.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 30 Jan 1994 00:26:04 +0000 |
parents | 3929b3fb37ee |
children | 75570af32e92 |
rev | line source |
---|---|
5626 | 1 /* The emacs frame widget. |
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc. | |
3 | |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
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 | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 /* Emacs 19 face widget ported by Fred Pierresteguy */ | |
21 | |
22 #include <stdio.h> | |
23 #include "config.h" | |
24 #include "lisp.h" | |
25 #include "xterm.h" | |
26 | |
27 #include "frame.h" | |
28 | |
29 #include "dispextern.h" | |
30 | |
31 | |
32 #include <X11/StringDefs.h> | |
33 #include <X11/IntrinsicP.h> | |
34 #include <X11/cursorfont.h> | |
35 #include "widgetprv.h" | |
5655
3929b3fb37ee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5626
diff
changeset
|
36 #include <X11/ObjectP.h> |
5626 | 37 #include <X11/Shell.h> |
38 #include <X11/ShellP.h> | |
39 | |
40 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
41 | |
42 /* This sucks: this is the first default that x-faces.el tries. This won't | |
43 be used unless neither the "Emacs.EmacsFrame" resource nor the | |
44 "Emacs.EmacsFrame" resource is set; the frame | |
45 may have the wrong default size if this font doesn't exist, but some other | |
46 font that x-faces.el does. The workaround is to specify some font in the | |
47 resource database; I don't know a solution other than duplicating the font- | |
48 searching code from x-faces.el in this file. | |
49 | |
50 This also means that if "Emacs.EmacsFrame" is specified as a non- | |
51 existent font, then Xt is going to substitute "XtDefaultFont" for it, | |
52 which is a different size than this one. The solution for this is to | |
53 make x-faces.el try to use XtDefaultFont. The problem with that is that | |
54 XtDefaultFont is almost certainly variable-width. | |
55 | |
56 #### Perhaps we could have this code explicitly set XtDefaultFont to this? | |
57 */ | |
58 #define DEFAULT_FACE_FONT "-*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*" | |
59 | |
60 | |
61 static void EmacsFrameInitialize (Widget, Widget, ArgList, Cardinal *); | |
62 static void EmacsFrameDestroy (Widget); | |
63 static void EmacsFrameRealize (Widget, XtValueMask*, XSetWindowAttributes*); | |
64 void EmacsFrameResize (Widget widget); | |
65 static Boolean EmacsFrameSetValues (Widget, Widget, Widget, | |
66 ArgList, Cardinal *); | |
67 static XtGeometryResult EmacsFrameQueryGeometry (Widget, XtWidgetGeometry*, | |
68 XtWidgetGeometry*); | |
69 | |
70 | |
71 #undef XtOffset | |
72 #define XtOffset(p_type,field) \ | |
73 ((Cardinal) (((char *) (&(((p_type)0)->field))) - ((char *)0))) | |
74 #define offset(field) XtOffset(EmacsFrame, emacs_frame.field) | |
75 | |
76 static XtResource resources[] = { | |
77 {XtNgeometry, XtCGeometry, XtRString, sizeof(String), | |
78 offset (geometry), XtRString, (XtPointer) 0}, | |
79 {XtNiconic, XtCIconic, XtRBoolean, sizeof(Boolean), | |
80 offset (iconic), XtRImmediate, (XtPointer) False}, | |
81 | |
82 {XtNemacsFrame, XtCEmacsFrame, XtRPointer, sizeof (XtPointer), | |
83 offset (frame), XtRImmediate, 0}, | |
84 | |
85 {XtNminibuffer, XtCMinibuffer, XtRInt, sizeof (int), | |
86 offset (minibuffer), XtRImmediate, (XtPointer)0}, | |
87 {XtNunsplittable, XtCUnsplittable, XtRBoolean, sizeof (Boolean), | |
88 offset (unsplittable), XtRImmediate, (XtPointer)0}, | |
89 {XtNinternalBorderWidth, XtCInternalBorderWidth, XtRInt, sizeof (int), | |
90 offset (internal_border_width), XtRImmediate, (XtPointer)4}, | |
91 {XtNinterline, XtCInterline, XtRInt, sizeof (int), | |
92 offset (interline), XtRImmediate, (XtPointer)0}, | |
93 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), | |
94 offset(font),XtRString, DEFAULT_FACE_FONT}, | |
95 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), | |
96 offset(foreground_pixel), XtRString, "XtDefaultForeground"}, | |
97 {XtNcursorColor, XtCForeground, XtRPixel, sizeof(Pixel), | |
98 offset(cursor_color), XtRString, "XtDefaultForeground"}, | |
99 {XtNbarCursor, XtCBarCursor, XtRBoolean, sizeof (Boolean), | |
100 offset (bar_cursor), XtRImmediate, (XtPointer)0}, | |
101 {XtNvisualBell, XtCVisualBell, XtRBoolean, sizeof (Boolean), | |
102 offset (visual_bell), XtRImmediate, (XtPointer)0}, | |
103 {XtNbellVolume, XtCBellVolume, XtRInt, sizeof (int), | |
104 offset (bell_volume), XtRImmediate, (XtPointer)0}, | |
105 }; | |
106 | |
107 #undef offset | |
108 | |
109 /* | |
110 static XtActionsRec | |
111 emacsFrameActionsTable [] = { | |
112 {"keypress", key_press}, | |
113 {"focus_in", emacs_frame_focus_handler}, | |
114 {"focus_out", emacs_frame_focus_handler}, | |
115 }; | |
116 | |
117 static char | |
118 emacsFrameTranslations [] = "\ | |
119 <KeyPress>: keypress()\n\ | |
120 <FocusIn>: focus_in()\n\ | |
121 <FocusOut>: focus_out()\n\ | |
122 "; | |
123 */ | |
124 | |
125 EmacsFrameClassRec emacsFrameClassRec = { | |
126 { /* core fields */ | |
127 /* superclass */ &widgetClassRec, | |
128 /* class_name */ "EmacsFrame", | |
129 /* widget_size */ sizeof(EmacsFrameRec), | |
130 /* class_initialize */ 0, | |
131 /* class_part_initialize */ 0, | |
132 /* class_inited */ FALSE, | |
133 /* initialize */ EmacsFrameInitialize, | |
134 /* initialize_hook */ 0, | |
135 /* realize */ EmacsFrameRealize, | |
136 /* actions */ 0, /*emacsFrameActionsTable*/ | |
137 /* num_actions */ 0, /*XtNumber (emacsFrameActionsTable)*/ | |
138 /* resources */ resources, | |
139 /* resource_count */ XtNumber(resources), | |
140 /* xrm_class */ NULLQUARK, | |
141 /* compress_motion */ TRUE, | |
142 /* compress_exposure */ TRUE, | |
143 /* compress_enterleave */ TRUE, | |
144 /* visible_interest */ FALSE, | |
145 /* destroy */ EmacsFrameDestroy, | |
146 /* resize */ EmacsFrameResize, | |
147 /* expose */ XtInheritExpose, | |
148 /* set_values */ EmacsFrameSetValues, | |
149 /* set_values_hook */ 0, | |
150 /* set_values_almost */ XtInheritSetValuesAlmost, | |
151 /* get_values_hook */ 0, | |
152 /* accept_focus */ XtInheritAcceptFocus, | |
153 /* version */ XtVersion, | |
154 /* callback_private */ 0, | |
155 /* tm_table */ 0, /*emacsFrameTranslations*/ | |
156 /* query_geometry */ EmacsFrameQueryGeometry, | |
157 /* display_accelerator */ XtInheritDisplayAccelerator, | |
158 /* extension */ 0 | |
159 } | |
160 }; | |
161 | |
162 WidgetClass emacsFrameClass = (WidgetClass) &emacsFrameClassRec; | |
163 | |
164 static void | |
165 get_default_char_pixel_size (EmacsFrame ew, int* pixel_width, | |
166 int* pixel_height) | |
167 { | |
168 /* | |
169 *pixel_width = XTextWidth (ew->emacs_frame.font, "n", 1); | |
170 *pixel_height = | |
171 ew->emacs_frame.font->ascent + ew->emacs_frame.font->descent; | |
172 */ | |
173 struct frame* f = ew->emacs_frame.frame; | |
174 *pixel_width = FONT_WIDTH (f->display.x->font); | |
175 *pixel_height = FONT_HEIGHT (f->display.x->font); | |
176 } | |
177 | |
178 static void | |
179 pixel_to_char_size (EmacsFrame ew, | |
180 Dimension pixel_width, Dimension pixel_height, | |
181 int* char_width, int* char_height) | |
182 { | |
183 struct frame* f = ew->emacs_frame.frame; | |
184 *char_width = PIXEL_TO_CHAR_WIDTH (f, pixel_width); | |
185 *char_height = PIXEL_TO_CHAR_HEIGHT (f, pixel_height); | |
186 } | |
187 | |
188 static void | |
189 char_to_pixel_size (EmacsFrame ew, int char_width, int char_height, | |
190 Dimension* pixel_width, Dimension* pixel_height) | |
191 { | |
192 struct frame* f = ew->emacs_frame.frame; | |
193 *pixel_width = CHAR_TO_PIXEL_WIDTH (f, char_width); | |
194 *pixel_height = CHAR_TO_PIXEL_HEIGHT (f, char_height); | |
195 } | |
196 | |
197 static void | |
198 round_size_to_char (EmacsFrame ew, | |
199 Dimension in_width, Dimension in_height, | |
200 Dimension* out_width, Dimension* out_height) | |
201 { | |
202 int char_width; | |
203 int char_height; | |
204 pixel_to_char_size (ew, in_width, in_height, &char_width, &char_height); | |
205 char_to_pixel_size (ew, char_width, char_height, out_width, out_height); | |
206 } | |
207 | |
208 static Widget | |
209 get_wm_shell (Widget w) | |
210 { | |
211 Widget wmshell; | |
212 | |
213 for (wmshell = XtParent (w); | |
214 wmshell && !XtIsWMShell (wmshell); | |
215 wmshell = XtParent (wmshell)); | |
216 | |
217 return wmshell; | |
218 } | |
219 | |
220 static void | |
221 mark_shell_size_user_specified (Widget wmshell) | |
222 { | |
223 if (! XtIsWMShell (wmshell)) abort (); | |
224 /* This is kind of sleazy, but I can't see how else to tell it to make it | |
225 mark the WM_SIZE_HINTS size as user specified when appropriate. */ | |
226 ((WMShellWidget) wmshell)->wm.size_hints.flags |= USSize; | |
227 } | |
228 | |
229 | |
230 /* Can't have static frame locals because of some broken compilers. | |
231 Normally, initializing a variable like this doesn't work in emacs, | |
232 but it's ok in this file because it must come after lastfile (and | |
233 thus have its data not go into text space) because Xt needs to | |
234 write to initialized data objects too. | |
235 */ | |
236 static Boolean first_frame_p = True; | |
237 | |
238 static void | |
239 set_frame_size (EmacsFrame ew) | |
240 { | |
241 /* The widget hierarchy is | |
242 | |
243 argv[0] emacsShell pane Frame-NAME | |
244 ApplicationShell EmacsShell Paned EmacsFrame | |
245 | |
246 We accept geometry specs in this order: | |
247 | |
248 *Frame-NAME.geometry | |
249 *EmacsFrame.geometry | |
250 Emacs.geometry | |
251 | |
252 Other possibilities for widget hierarchies might be | |
253 | |
254 argv[0] frame pane Frame-NAME | |
255 ApplicationShell EmacsShell Paned EmacsFrame | |
256 or | |
257 argv[0] Frame-NAME pane Frame-NAME | |
258 ApplicationShell EmacsShell Paned EmacsFrame | |
259 or | |
260 argv[0] Frame-NAME pane emacsTextPane | |
261 ApplicationShell EmacsFrame Paned EmacsTextPane | |
262 | |
263 With the current setup, the text-display-area is the part which is | |
264 an emacs "frame", since that's the only part managed by emacs proper | |
265 (the menubar and the parent of the menubar and all that sort of thing | |
266 are managed by lwlib.) | |
267 | |
268 The EmacsShell widget is simply a replacement for the Shell widget | |
269 which is able to deal with using an externally-supplied window instead | |
270 of always creating its own. It is not actually emacs specific, and | |
271 should possibly have class "Shell" instead of "EmacsShell" to simplify | |
272 the resources. | |
273 | |
274 */ | |
275 | |
276 /* Geometry of the AppShell */ | |
277 int app_flags = 0; | |
278 int app_x = 0; | |
279 int app_y = 0; | |
280 unsigned int app_w = 0; | |
281 unsigned int app_h = 0; | |
282 | |
283 /* Geometry of the EmacsFrame */ | |
284 int frame_flags = 0; | |
285 int frame_x = 0; | |
286 int frame_y = 0; | |
287 unsigned int frame_w = 0; | |
288 unsigned int frame_h = 0; | |
289 | |
290 /* Hairily merged geometry */ | |
291 int x = 0; | |
292 int y = 0; | |
293 unsigned int w = ew->emacs_frame.frame->width; | |
294 unsigned int h = ew->emacs_frame.frame->height; | |
295 int flags = 0; | |
296 | |
297 Widget wmshell = get_wm_shell ((Widget) ew); | |
298 Widget app_shell = XtParent ((Widget) wmshell); | |
299 | |
300 | |
301 if (! XtIsSubclass (wmshell, shellWidgetClass)) abort (); | |
302 if (! XtIsSubclass (app_shell, shellWidgetClass)) abort (); | |
303 | |
304 /* If the EmacsFrame doesn't have a geometry but the shell does, | |
305 treat that as the geometry of the frame. (Is this bogus? | |
306 I'm not sure.) */ | |
307 if (ew->emacs_frame.geometry == 0) | |
308 XtVaGetValues (wmshell, XtNgeometry, &ew->emacs_frame.geometry, 0); | |
309 | |
310 /* If the Shell is iconic, then the EmacsFrame is iconic. (Is | |
311 this bogus? I'm not sure.) */ | |
312 if (!ew->emacs_frame.iconic) | |
313 XtVaGetValues (wmshell, XtNiconic, &ew->emacs_frame.iconic, 0); | |
314 | |
315 | |
316 { | |
317 char *geom = 0; | |
318 XtVaGetValues (app_shell, XtNgeometry, &geom, 0); | |
319 if (geom) | |
320 app_flags = XParseGeometry (geom, &app_x, &app_y, &app_w, &app_h); | |
321 } | |
322 | |
323 if (ew->emacs_frame.geometry) | |
324 frame_flags = XParseGeometry (ew->emacs_frame.geometry, | |
325 &frame_x, &frame_y, | |
326 &frame_w, &frame_h); | |
327 | |
328 if (first_frame_p) | |
329 { | |
330 /* If this is the first frame created: | |
331 ==================================== | |
332 | |
333 - Use the ApplicationShell's size/position, if specified. | |
334 (This is "Emacs.geometry", or the "-geometry" command line arg.) | |
335 - Else use the EmacsFrame's size/position. | |
336 (This is "*Frame-NAME.geometry") | |
337 | |
338 - If the AppShell is iconic, the frame should be iconic. | |
339 | |
340 AppShell comes first so that -geometry always applies to the first | |
341 frame created, even if there is an "every frame" entry in the | |
342 resource database. | |
343 */ | |
344 if (app_flags & (XValue | YValue)) | |
345 { | |
346 x = app_x; y = app_y; | |
347 flags |= (app_flags & (XValue | YValue | XNegative | YNegative)); | |
348 } | |
349 else if (frame_flags & (XValue | YValue)) | |
350 { | |
351 x = frame_x; y = frame_y; | |
352 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative)); | |
353 } | |
354 | |
355 if (app_flags & (WidthValue | HeightValue)) | |
356 { | |
357 w = app_w; h = app_h; | |
358 flags |= (app_flags & (WidthValue | HeightValue)); | |
359 } | |
360 else if (frame_flags & (WidthValue | HeightValue)) | |
361 { | |
362 w = frame_w; h = frame_h; | |
363 flags |= (frame_flags & (WidthValue | HeightValue)); | |
364 } | |
365 | |
366 /* If the AppShell is iconic, then the EmacsFrame is iconic. */ | |
367 if (!ew->emacs_frame.iconic) | |
368 XtVaGetValues (app_shell, XtNiconic, &ew->emacs_frame.iconic, 0); | |
369 | |
370 first_frame_p = False; | |
371 } | |
372 else | |
373 { | |
374 /* If this is not the first frame created: | |
375 ======================================== | |
376 | |
377 - use the EmacsFrame's size/position if specified | |
378 - Otherwise, use the ApplicationShell's size, but not position. | |
379 | |
380 So that means that one can specify the position of the first frame | |
381 with "Emacs.geometry" or `-geometry'; but can only specify the | |
382 position of subsequent frames with "*Frame-NAME.geometry". | |
383 | |
384 AppShell comes second so that -geometry does not apply to subsequent | |
385 frames when there is an "every frame" entry in the resource db, | |
386 but does apply to the first frame. | |
387 */ | |
388 if (frame_flags & (XValue | YValue)) | |
389 { | |
390 x = frame_x; y = frame_y; | |
391 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative)); | |
392 } | |
393 | |
394 if (frame_flags & (WidthValue | HeightValue)) | |
395 { | |
396 w = frame_w; h = frame_h; | |
397 flags |= (frame_flags & (WidthValue | HeightValue)); | |
398 } | |
399 else if (app_flags & (WidthValue | HeightValue)) | |
400 { | |
401 w = app_w; | |
402 h = app_h; | |
403 flags |= (app_flags & (WidthValue | HeightValue)); | |
404 } | |
405 } | |
406 | |
407 { | |
408 struct frame* frame = ew->emacs_frame.frame; | |
409 Dimension pixel_width, pixel_height; | |
410 char shell_position [32]; | |
411 | |
412 /* Take into account the size of the scrollbar */ | |
413 frame->display.x->vertical_scroll_bar_extra | |
414 = (FRAME_HAS_VERTICAL_SCROLL_BARS (frame) | |
415 ? VERTICAL_SCROLL_BAR_PIXEL_WIDTH (frame) | |
416 : 0); | |
417 | |
418 | |
419 change_frame_size (frame, h, w, 1, 0); | |
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 | |
424 | |
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); | |
440 XtVaSetValues (wmshell, XtNgeometry, tem, 0); | |
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); | |
450 XtVaSetValues (wmshell, XtNgeometry, tem, 0); | |
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. */ | |
460 XtVaSetValues (wmshell, XtNiconic, ew->emacs_frame.iconic, 0); | |
461 } | |
462 } | |
463 | |
464 | |
465 static void | |
466 update_wm_hints (EmacsFrame ew) | |
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 | |
479 check_frame_size (ew->emacs_frame.frame, &min_rows, &min_cols); | |
480 | |
481 pixel_to_char_size (ew, ew->core.width, ew->core.height, | |
482 &char_width, &char_height); | |
483 char_to_pixel_size (ew, char_width, char_height, | |
484 &rounded_width, &rounded_height); | |
485 get_default_char_pixel_size (ew, &cw, &ch); | |
486 | |
487 base_width = (wmshell->core.width - ew->core.width | |
488 + (rounded_width - (char_width * cw))); | |
489 base_height = (wmshell->core.height - ew->core.height | |
490 + (rounded_height - (char_height * ch))); | |
491 | |
492 /* This is kind of sleazy, but I can't see how else to tell it to | |
493 make it mark the WM_SIZE_HINTS size as user specified. | |
494 */ | |
495 /* ((WMShellWidget) wmshell)->wm.size_hints.flags |= USSize;*/ | |
496 | |
497 XtVaSetValues (wmshell, | |
498 XtNbaseWidth, base_width, | |
499 XtNbaseHeight, base_height, | |
500 XtNwidthInc, cw, | |
501 XtNheightInc, ch, | |
502 XtNminWidth, base_width + min_cols * cw, | |
503 XtNminHeight, base_height + min_rows * ch, | |
504 0); | |
505 } | |
506 | |
507 static void | |
508 create_frame_gcs (EmacsFrame ew) | |
509 { | |
510 struct frame* s = ew->emacs_frame.frame; | |
511 | |
512 s->display.x->normal_gc = | |
513 XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0); | |
514 s->display.x->reverse_gc = | |
515 XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0); | |
516 s->display.x->cursor_gc = | |
517 XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0); | |
518 } | |
519 | |
520 static void | |
521 setup_frame_gcs (EmacsFrame ew) | |
522 { | |
523 XGCValues gc_values; | |
524 struct frame* s = ew->emacs_frame.frame; | |
525 Pixmap blank_stipple, blank_tile; | |
526 | |
527 static char cursor_bits[] = | |
528 { | |
529 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
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 }; | |
534 | |
535 /* We have to initialize all of our GCs to have a stipple/tile, otherwise | |
536 XGetGCValues returns uninitialized data when we query the stipple | |
537 (instead of None or something sensible) and it makes things hard. | |
538 | |
539 This should be fixed for real by not querying the GCs but instead having | |
540 some GC-based cache instead of the current face-based cache which doesn't | |
541 effectively cache all of the GC settings we need to use. | |
542 */ | |
543 | |
544 blank_stipple = | |
545 XCreateBitmapFromData (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), | |
546 cursor_bits, 2, 2); | |
547 | |
548 /* use fg = 0, bg = 1 below, but it's irrelevant since this pixmap should | |
549 never actually get used as a background tile! | |
550 */ | |
551 blank_tile = | |
552 XCreatePixmapFromBitmapData (XtDisplay(ew), | |
553 RootWindowOfScreen (XtScreen (ew)), | |
554 cursor_bits, 2, 2, 0, 1, ew->core.depth); | |
555 | |
556 /* Normal video */ | |
557 gc_values.font = ew->emacs_frame.font->fid; | |
558 gc_values.foreground = ew->emacs_frame.foreground_pixel; | |
559 gc_values.background = ew->core.background_pixel; | |
560 gc_values.graphics_exposures = False; | |
561 gc_values.stipple = blank_stipple; | |
562 gc_values.tile = blank_tile; | |
563 XChangeGC (XtDisplay (ew), s->display.x->normal_gc, | |
564 (GCFont | GCForeground | GCBackground | GCGraphicsExposures | |
565 | GCStipple | GCTile), | |
566 &gc_values); | |
567 | |
568 /* Reverse video style. */ | |
569 gc_values.font = ew->emacs_frame.font->fid; | |
570 gc_values.foreground = ew->core.background_pixel; | |
571 gc_values.background = ew->emacs_frame.foreground_pixel; | |
572 gc_values.graphics_exposures = False; | |
573 gc_values.stipple = blank_stipple; | |
574 gc_values.tile = blank_tile; | |
575 XChangeGC (XtDisplay (ew), s->display.x->reverse_gc, | |
576 (GCFont | GCForeground | GCBackground | GCGraphicsExposures | |
577 | GCStipple | GCTile), | |
578 &gc_values); | |
579 | |
580 /* Cursor has to have an empty stipple. */ | |
581 gc_values.font = ew->emacs_frame.font->fid; | |
582 gc_values.foreground = ew->core.background_pixel; | |
583 gc_values.background = ew->emacs_frame.cursor_color; | |
584 gc_values.graphics_exposures = False; | |
585 gc_values.tile = blank_tile; | |
586 gc_values.stipple = | |
587 XCreateBitmapFromData (XtDisplay (ew), | |
588 RootWindowOfScreen (XtScreen (ew)), | |
589 cursor_bits, 16, 16); | |
590 XChangeGC (XtDisplay (ew), s->display.x->cursor_gc, | |
591 (GCFont | GCForeground | GCBackground | GCGraphicsExposures | |
592 | GCStipple | GCTile), | |
593 &gc_values); | |
594 } | |
595 | |
596 static void | |
597 update_various_frame_slots (EmacsFrame ew) | |
598 { | |
599 struct x_display* x = ew->emacs_frame.frame->display.x; | |
600 x->pixel_height = ew->core.height; | |
601 x->pixel_width = ew->core.width; | |
602 x->internal_border_width = ew->emacs_frame.internal_border_width; | |
603 | |
604 } | |
605 | |
606 static void | |
607 update_from_various_frame_slots (EmacsFrame ew) | |
608 { | |
609 struct x_display* x = ew->emacs_frame.frame->display.x; | |
610 ew->core.height = x->pixel_height; | |
611 ew->core.width = x->pixel_width; | |
612 ew->core.background_pixel = x->background_pixel; | |
613 ew->emacs_frame.internal_border_width = x->internal_border_width; | |
614 ew->emacs_frame.font = x->font; | |
615 ew->emacs_frame.foreground_pixel = x->foreground_pixel; | |
616 ew->emacs_frame.cursor_color = x->cursor_pixel; | |
617 ew->core.border_pixel = x->border_pixel; | |
618 } | |
619 | |
620 static void | |
621 EmacsFrameInitialize (Widget request, Widget new, | |
622 ArgList dum1, Cardinal *dum2) | |
623 { | |
624 EmacsFrame ew = (EmacsFrame)new; | |
625 | |
626 if (!ew->emacs_frame.frame) | |
627 { | |
628 fprintf (stderr, | |
629 "can't create an emacs frame widget without a frame\n"); | |
630 exit (1); | |
631 } | |
632 | |
633 #if 0 /* done in xfns.c */ | |
634 /* If the "Emacs.EmacsFrame.{default,Face}.{attributeFont,AttributeFont}" | |
635 resource is set, then it always overrides "Emacs.EmacsFrame.{font,Font}". | |
636 It's unfortunate that we have to do this, but we need to know the font | |
637 size for frame-sizing purposes before the faces get initialized. If | |
638 the "default.attributeFont" isn't set, then we use the font of this | |
639 EmacsFrame itself, defaulting to XtDefaultFont. Up in the lisp code, | |
640 the "default" face will use the frame's font if its own is not set, | |
641 so everything stays in sync -- it's not possible for the frame's font | |
642 and the default face's font to be different. | |
643 */ | |
644 { | |
645 XFontStruct *f = 0; | |
646 XtResource face_res; | |
647 face_res.resource_name = "attributeFont"; | |
648 face_res.resource_class = "AttributeFont"; | |
649 face_res.resource_type = XtRFontStruct; | |
650 face_res.resource_size = sizeof (XFontStruct *); | |
651 face_res.resource_offset = 0; | |
652 face_res.default_type = XtRImmediate; | |
653 face_res.default_addr = 0; | |
654 XtGetSubresources ((Widget) ew, (XtPointer) &f, "default", "Face", | |
655 &face_res, 1, NULL, 0); | |
656 | |
657 if (f) | |
658 ew->emacs_frame.font = f; | |
659 else if (! ew->emacs_frame.font) | |
660 { | |
661 fprintf (stderr, "emacs frame widget could not load a font\n"); | |
662 exit (1); | |
663 } | |
664 } | |
665 | |
666 /* Update the font field in frame */ | |
667 ew->emacs_frame.frame->display.x->font = ew->emacs_frame.font; | |
668 #endif | |
669 | |
670 update_from_various_frame_slots (ew); | |
671 set_frame_size (ew); | |
672 /*create_frame_gcs (ew); | |
673 setup_frame_gcs (ew); | |
674 update_various_frame_slots (ew); */ | |
675 } | |
676 | |
677 | |
678 static void | |
679 EmacsFrameRealize (Widget widget, XtValueMask *mask, | |
680 XSetWindowAttributes *attrs) | |
681 { | |
682 EmacsFrame ew = (EmacsFrame)widget; | |
683 | |
684 attrs->event_mask = (KeyPressMask | ExposureMask | ButtonPressMask | | |
685 ButtonReleaseMask | StructureNotifyMask | | |
686 FocusChangeMask | PointerMotionHintMask | | |
687 PointerMotionMask | LeaveWindowMask | EnterWindowMask | | |
688 VisibilityChangeMask | PropertyChangeMask | | |
689 StructureNotifyMask | SubstructureNotifyMask | | |
690 SubstructureRedirectMask); | |
691 *mask |= CWEventMask; | |
692 XtCreateWindow (widget, InputOutput, (Visual *)CopyFromParent, *mask, | |
693 attrs); | |
694 update_wm_hints (ew); | |
695 } | |
696 | |
697 extern void free_frame_faces (struct frame *); | |
698 | |
699 static void | |
700 EmacsFrameDestroy (Widget widget) | |
701 { | |
702 EmacsFrame ew = (EmacsFrame) widget; | |
703 struct frame* s = ew->emacs_frame.frame; | |
704 | |
705 if (! s) abort (); | |
706 if (! s->display.x) abort (); | |
707 if (! s->display.x->normal_gc) abort (); | |
708 | |
709 /* this would be called from Fdelete_frame() but it needs to free some | |
710 stuff after the widget has been finalized but before the widget has | |
711 been freed. */ | |
712 free_frame_faces (s); | |
713 | |
714 /* need to be careful that the face-freeing code doesn't free these too */ | |
715 XFreeGC (XtDisplay (widget), s->display.x->normal_gc); | |
716 XFreeGC (XtDisplay (widget), s->display.x->reverse_gc); | |
717 XFreeGC (XtDisplay (widget), s->display.x->cursor_gc); | |
718 } | |
719 | |
720 void | |
721 EmacsFrameResize (Widget widget) | |
722 { | |
723 EmacsFrame ew = (EmacsFrame)widget; | |
724 struct frame *f = ew->emacs_frame.frame; | |
725 int columns; | |
726 int rows; | |
727 | |
728 pixel_to_char_size (ew, ew->core.width, ew->core.height, &columns, &rows); | |
729 change_frame_size (f, rows, columns, 1, 0); | |
730 update_wm_hints (ew); | |
731 { | |
732 Window win, child; | |
733 int win_x, win_y; | |
734 | |
735 /* Find the position of the outside upper-left corner of | |
736 the window, in the root coordinate system. Don't | |
737 refer to the parent window here; we may be processing | |
738 this event after the window manager has changed our | |
739 parent, but before we have reached the ReparentNotify. */ | |
740 XTranslateCoordinates (x_current_display, | |
741 | |
742 /* From-window, to-window. */ | |
743 XtWindow(XtParent(ew)), | |
744 ROOT_WINDOW, | |
745 | |
746 /* From-position, to-position. */ | |
747 -f->display.x->widget->core.border_width, | |
748 -f->display.x->widget->core.border_width, | |
749 &win_x, &win_y, | |
750 | |
751 /* Child of win. */ | |
752 &child); | |
753 f->display.x->widget->core.x = win_x; | |
754 f->display.x->widget->core.y = win_y; | |
755 } | |
756 update_various_frame_slots (ew); | |
757 } | |
758 | |
759 static Boolean | |
760 EmacsFrameSetValues (Widget cur_widget, Widget req_widget, Widget new_widget, | |
761 ArgList dum1, Cardinal *dum2) | |
762 { | |
763 EmacsFrame cur = (EmacsFrame)cur_widget; | |
764 EmacsFrame new = (EmacsFrame)new_widget; | |
765 | |
766 Boolean needs_a_refresh = False; | |
767 Boolean has_to_recompute_size; | |
768 Boolean has_to_recompute_gcs; | |
769 Boolean has_to_update_hints; | |
770 | |
771 int char_width, char_height; | |
772 Dimension pixel_width; | |
773 Dimension pixel_height; | |
774 | |
775 has_to_recompute_gcs = (cur->emacs_frame.font != new->emacs_frame.font | |
776 || (cur->emacs_frame.foreground_pixel | |
777 != new->emacs_frame.foreground_pixel) | |
778 || (cur->core.background_pixel | |
779 != new->core.background_pixel) | |
780 ); | |
781 | |
782 has_to_recompute_size = (cur->emacs_frame.font != new->emacs_frame.font | |
783 && cur->core.width == new->core.width | |
784 && cur->core.height == new->core.height); | |
785 | |
786 has_to_update_hints = (cur->emacs_frame.font != new->emacs_frame.font); | |
787 | |
788 if (has_to_recompute_gcs) | |
789 { | |
790 setup_frame_gcs (new); | |
791 needs_a_refresh = True; | |
792 } | |
793 | |
794 if (has_to_recompute_size) | |
795 { | |
796 pixel_width = new->core.width; | |
797 pixel_height = new->core.height; | |
798 pixel_to_char_size (new, pixel_width, pixel_height, &char_width, | |
799 &char_height); | |
800 char_to_pixel_size (new, char_width, char_height, &pixel_width, | |
801 &pixel_height); | |
802 new->core.width = pixel_width; | |
803 new->core.height = pixel_height; | |
804 | |
805 change_frame_size (new->emacs_frame.frame, char_height, char_width, | |
806 1, 0); | |
807 needs_a_refresh = True; | |
808 } | |
809 | |
810 if (has_to_update_hints) | |
811 update_wm_hints (new); | |
812 | |
813 update_various_frame_slots (new); | |
814 | |
815 /* #### This doesn't work, I haven't been able to find ANY kludge that | |
816 will let (x-create-frame '((iconic . t))) work. It seems that changes | |
817 to wm_shell's iconic slot have no effect after it has been realized, | |
818 and calling XIconifyWindow doesn't work either (even thought the window | |
819 has been created.) Perhaps there is some property we could smash | |
820 directly, but I'm sick of this for now. Xt is a steaming pile of shit! | |
821 */ | |
822 if (cur->emacs_frame.iconic != new->emacs_frame.iconic) | |
823 { | |
824 Widget wmshell = get_wm_shell ((Widget) cur); | |
825 XtVaSetValues (wmshell, XtNiconic, new->emacs_frame.iconic, 0); | |
826 } | |
827 | |
828 return needs_a_refresh; | |
829 } | |
830 | |
831 static XtGeometryResult | |
832 EmacsFrameQueryGeometry (Widget widget, XtWidgetGeometry* request, | |
833 XtWidgetGeometry* result) | |
834 { | |
835 EmacsFrame ew = (EmacsFrame)widget; | |
836 | |
837 int mask = request->request_mode; | |
838 Dimension ok_width, ok_height; | |
839 | |
840 if (mask & (CWWidth | CWHeight)) | |
841 { | |
842 round_size_to_char (ew, | |
843 (mask & CWWidth) ? request->width : ew->core.width, | |
844 ((mask & CWHeight) ? request->height | |
845 : ew->core.height), | |
846 &ok_width, &ok_height); | |
847 if ((mask & CWWidth) && (ok_width != request->width)) | |
848 { | |
849 result->request_mode |= CWWidth; | |
850 result->width = ok_width; | |
851 } | |
852 if ((mask & CWHeight) && (ok_height != request->height)) | |
853 { | |
854 result->request_mode |= CWHeight; | |
855 result->height = ok_height; | |
856 } | |
857 } | |
858 return result->request_mode ? XtGeometryAlmost : XtGeometryYes; | |
859 } | |
860 | |
861 #if 0 | |
862 /* I don't know why this is necessary; Matthieu said he had to do | |
863 it to make the focus handlers work?? | |
864 */ | |
865 static void | |
866 key_press (Widget w, XEvent* event, String *params, Cardinal *n_params) | |
867 { | |
868 } | |
869 | |
870 static void | |
871 emacs_frame_focus_handler (Widget w, XEvent *event, String *params, | |
872 Cardinal *n_params) | |
873 { | |
874 emacs_Xt_focus_event_handler (event, 0); | |
875 } | |
876 #endif | |
877 | |
878 /* Special entrypoints */ | |
879 void | |
880 EmacsFrameSetCharSize (Widget widget, int columns, int rows) | |
881 { | |
882 EmacsFrame ew = (EmacsFrame) widget; | |
883 Dimension pixel_width, pixel_height, granted_width, granted_height; | |
884 XtGeometryResult result; | |
885 if (columns < 3) columns = 3; /* no way buddy */ | |
886 if (rows < 3) rows = 3; | |
887 | |
888 char_to_pixel_size (ew, columns, rows, &pixel_width, &pixel_height); | |
889 result = XtMakeResizeRequest ((Widget)ew, | |
890 pixel_width, pixel_height, | |
891 &granted_width, &granted_height); | |
892 if (result == XtGeometryAlmost) | |
893 XtMakeResizeRequest ((Widget) ew, granted_width, granted_height, | |
894 NULL, NULL); | |
895 /* damn Paned widget won't ever change its width. Force it. */ | |
896 if (ew->core.width != pixel_width) | |
897 { | |
898 XtVaSetValues (XtParent ((Widget) ew), XtNwidth, pixel_width, 0); | |
899 XtVaSetValues ((Widget) ew, XtNwidth, pixel_width, 0); | |
900 } | |
901 } |