1 /* The emacs frame widget.
2 Copyright (C) 1992-1993, 2000-2012 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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 3 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 /* Emacs 19 face widget ported by Fred Pierresteguy */
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.
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/
41 #include "dispextern.h"
42 #include "blockinput.h"
44 #include <X11/StringDefs.h>
45 #include <X11/IntrinsicP.h>
46 #include <X11/cursorfont.h>
47 #include "widgetprv.h"
48 #include <X11/ObjectP.h>
49 #include <X11/Shell.h>
50 #include <X11/ShellP.h>
51 #include "../lwlib/lwlib.h"
54 #include "syssignal.h"
56 #include "character.h"
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.
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.
73 #### Perhaps we could have this code explicitly set XtDefaultFont to this?
75 #define DEFAULT_FACE_FONT "-*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*"
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
);
81 static void EmacsFrameResize (Widget widget
);
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
);
87 #define XtOffset(p_type,field) \
88 ((Cardinal) (((char *) (&(((p_type)0)->field))) - ((char *)0)))
89 #define offset(field) XtOffset (EmacsFrame, emacs_frame.field)
91 static XtResource resources
[] = {
92 {XtNgeometry
, XtCGeometry
, XtRString
, sizeof (String
),
93 offset (geometry
), XtRString
, (XtPointer
) 0},
94 {XtNiconic
, XtCIconic
, XtRBoolean
, sizeof (Boolean
),
95 offset (iconic
), XtRImmediate
, (XtPointer
) False
},
97 {XtNemacsFrame
, XtCEmacsFrame
, XtRPointer
, sizeof (XtPointer
),
98 offset (frame
), XtRImmediate
, 0},
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},
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"},
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},
126 emacsFrameActionsTable [] = {
127 {"keypress", key_press},
128 {"focus_in", emacs_frame_focus_handler},
129 {"focus_out", emacs_frame_focus_handler},
133 emacsFrameTranslations [] = "\
134 <KeyPress>: keypress()\n\
135 <FocusIn>: focus_in()\n\
136 <FocusOut>: focus_out()\n\
140 static EmacsFrameClassRec emacsFrameClassRec
= {
142 /* superclass */ &widgetClassRec
,
143 /* class_name */ "EmacsFrame",
144 /* widget_size */ sizeof (EmacsFrameRec
),
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
,
154 /* resource_count */ XtNumber (resources
),
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
,
177 WidgetClass emacsFrameClass
= (WidgetClass
) &emacsFrameClassRec
;
180 get_default_char_pixel_size (EmacsFrame ew
, int *pixel_width
, int *pixel_height
)
182 struct frame
* f
= ew
->emacs_frame
.frame
;
183 *pixel_width
= FRAME_COLUMN_WIDTH (f
);
184 *pixel_height
= FRAME_LINE_HEIGHT (f
);
188 pixel_to_char_size (EmacsFrame ew
, Dimension pixel_width
, Dimension pixel_height
, int *char_width
, int *char_height
)
190 struct frame
* f
= ew
->emacs_frame
.frame
;
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
);
196 char_to_pixel_size (EmacsFrame ew
, int char_width
, int char_height
, Dimension
*pixel_width
, Dimension
*pixel_height
)
198 struct frame
* f
= ew
->emacs_frame
.frame
;
199 *pixel_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, char_width
);
200 *pixel_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, char_height
);
204 round_size_to_char (EmacsFrame ew
, Dimension in_width
, Dimension in_height
, Dimension
*out_width
, Dimension
*out_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
);
213 get_wm_shell (Widget w
)
217 for (wmshell
= XtParent (w
);
218 wmshell
&& !XtIsWMShell (wmshell
);
219 wmshell
= XtParent (wmshell
));
224 #if 0 /* Currently not used. */
227 mark_shell_size_user_specified (Widget wmshell
)
229 if (! XtIsWMShell (wmshell
)) emacs_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
;
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.
245 static Boolean first_frame_p
= True
;
249 set_frame_size (EmacsFrame ew
)
251 /* The widget hierarchy is
253 argv[0] emacsShell pane Frame-NAME
254 ApplicationShell EmacsShell Paned EmacsFrame
256 We accept geometry specs in this order:
262 Other possibilities for widget hierarchies might be
264 argv[0] frame pane Frame-NAME
265 ApplicationShell EmacsShell Paned EmacsFrame
267 argv[0] Frame-NAME pane Frame-NAME
268 ApplicationShell EmacsShell Paned EmacsFrame
270 argv[0] Frame-NAME pane emacsTextPane
271 ApplicationShell EmacsFrame Paned EmacsTextPane
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.)
278 The EmacsShell widget is simply a replacement for the Shell widget
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
286 /* Hairily merged geometry */
287 unsigned int w
= FRAME_COLS (ew
->emacs_frame
.frame
);
288 unsigned int h
= FRAME_LINES (ew
->emacs_frame
.frame
);
290 Widget wmshell
= get_wm_shell ((Widget
) ew
);
291 /* Each Emacs shell is now independent and top-level. */
293 if (! XtIsSubclass (wmshell
, shellWidgetClass
)) emacs_abort ();
295 /* We don't need this for the moment. The geometry is computed in
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?
301 if (ew
->emacs_frame
.geometry
== 0)
302 XtVaGetValues (wmshell
, XtNgeometry
, &ew
->emacs_frame
.geometry
, NULL
);
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
)
307 XtVaGetValues (wmshell
, XtNiconic
, &ew
->emacs_frame
.iconic
, NULL
);
312 XtVaGetValues (app_shell
, XtNgeometry
, &geom
, NULL
);
314 app_flags
= XParseGeometry (geom
, &app_x
, &app_y
, &app_w
, &app_h
);
317 if (ew
->emacs_frame
.geometry
)
318 frame_flags
= XParseGeometry (ew
->emacs_frame
.geometry
,
324 /* If this is the first frame created:
325 ====================================
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")
332 - If the AppShell is iconic, the frame should be iconic.
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
338 if (app_flags
& (XValue
| YValue
))
340 x
= app_x
; y
= app_y
;
341 flags
|= (app_flags
& (XValue
| YValue
| XNegative
| YNegative
));
343 else if (frame_flags
& (XValue
| YValue
))
345 x
= frame_x
; y
= frame_y
;
346 flags
|= (frame_flags
& (XValue
| YValue
| XNegative
| YNegative
));
349 if (app_flags
& (WidthValue
| HeightValue
))
351 w
= app_w
; h
= app_h
;
352 flags
|= (app_flags
& (WidthValue
| HeightValue
));
354 else if (frame_flags
& (WidthValue
| HeightValue
))
356 w
= frame_w
; h
= frame_h
;
357 flags
|= (frame_flags
& (WidthValue
| HeightValue
));
360 /* If the AppShell is iconic, then the EmacsFrame is iconic. */
361 if (!ew
->emacs_frame
.iconic
)
362 XtVaGetValues (app_shell
, XtNiconic
, &ew
->emacs_frame
.iconic
, NULL
);
364 first_frame_p
= False
;
368 /* If this is not the first frame created:
369 ========================================
371 - use the EmacsFrame's size/position if specified
372 - Otherwise, use the ApplicationShell's size, but not position.
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".
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.
382 if (frame_flags
& (XValue
| YValue
))
384 x
= frame_x
; y
= frame_y
;
385 flags
|= (frame_flags
& (XValue
| YValue
| XNegative
| YNegative
));
388 if (frame_flags
& (WidthValue
| HeightValue
))
390 w
= frame_w
; h
= frame_h
;
391 flags
|= (frame_flags
& (WidthValue
| HeightValue
));
393 else if (app_flags
& (WidthValue
| HeightValue
))
397 flags
|= (app_flags
& (WidthValue
| HeightValue
));
402 struct frame
*f
= ew
->emacs_frame
.frame
;
403 Dimension pixel_width
, pixel_height
;
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
410 f
->scroll_bar_actual_width
411 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
413 compute_fringe_widths (f
, 0);
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. */
418 change_frame_size (f
, h
, w
, 1, 0, 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
;
424 #if 0 /* xfns.c takes care of this now. */
425 /* If a position was specified, assign it to the shell widget.
426 (Else WM won't do anything with it.)
428 if (flags
& (XValue
| YValue
))
430 /* the tricky things with the sign is to make sure that
432 sprintf (shell_position
, "=%c%d%c%d",
433 flags
& XNegative
? '-' : '+', x
< 0 ? -x
: x
,
434 flags
& YNegative
? '-' : '+', y
< 0 ? -y
: y
);
435 XtVaSetValues (wmshell
, XtNgeometry
, xstrdup (shell_position
), NULL
);
437 else if (flags
& (WidthValue
| HeightValue
))
439 sprintf (shell_position
, "=%dx%d", pixel_width
, pixel_height
);
440 XtVaSetValues (wmshell
, XtNgeometry
, xstrdup (shell_position
), NULL
);
443 /* If the geometry spec we're using has W/H components, mark the size
444 in the WM_SIZE_HINTS as user specified. */
445 if (flags
& (WidthValue
| HeightValue
))
446 mark_shell_size_user_specified (wmshell
);
448 /* Also assign the iconic status of the frame to the Shell, so that
450 XtVaSetValues (wmshell
, XtNiconic
, ew
->emacs_frame
.iconic
, NULL
);
456 update_wm_hints (EmacsFrame ew
)
458 Widget wmshell
= get_wm_shell ((Widget
)ew
);
461 Dimension rounded_width
;
462 Dimension rounded_height
;
467 int min_rows
= 0, min_cols
= 0;
469 /* This happens when the frame is just created. */
470 if (! wmshell
) return;
473 check_frame_size (ew
->emacs_frame
.frame
, &min_rows
, &min_cols
);
476 pixel_to_char_size (ew
, ew
->core
.width
, ew
->core
.height
,
477 &char_width
, &char_height
);
478 char_to_pixel_size (ew
, char_width
, char_height
,
479 &rounded_width
, &rounded_height
);
480 get_default_char_pixel_size (ew
, &cw
, &ch
);
482 base_width
= (wmshell
->core
.width
- ew
->core
.width
483 + (rounded_width
- (char_width
* cw
)));
484 base_height
= (wmshell
->core
.height
- ew
->core
.height
485 + (rounded_height
- (char_height
* ch
)));
487 /* This is kind of sleazy, but I can't see how else to tell it to
488 make it mark the WM_SIZE_HINTS size as user specified.
490 /* ((WMShellWidget) wmshell)->wm.size_hints.flags |= USSize;*/
492 XtVaSetValues (wmshell
,
493 XtNbaseWidth
, (XtArgVal
) base_width
,
494 XtNbaseHeight
, (XtArgVal
) base_height
,
495 XtNwidthInc
, (XtArgVal
) cw
,
496 XtNheightInc
, (XtArgVal
) ch
,
497 XtNminWidth
, (XtArgVal
) (base_width
+ min_cols
* cw
),
498 XtNminHeight
, (XtArgVal
) (base_height
+ min_rows
* ch
),
503 widget_update_wm_size_hints (Widget widget
)
505 EmacsFrame ew
= (EmacsFrame
)widget
;
506 update_wm_hints (ew
);
513 create_frame_gcs (EmacsFrame ew
)
515 struct frame
*s
= ew
->emacs_frame
.frame
;
517 s
->output_data
.x
->normal_gc
518 = XCreateGC (XtDisplay (ew
), RootWindowOfScreen (XtScreen (ew
)), 0, 0);
519 s
->output_data
.x
->reverse_gc
520 = XCreateGC (XtDisplay (ew
), RootWindowOfScreen (XtScreen (ew
)), 0, 0);
521 s
->output_data
.x
->cursor_gc
522 = XCreateGC (XtDisplay (ew
), RootWindowOfScreen (XtScreen (ew
)), 0, 0);
523 s
->output_data
.x
->black_relief
.gc
= 0;
524 s
->output_data
.x
->white_relief
.gc
= 0;
529 static char setup_frame_cursor_bits
[] =
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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
538 setup_frame_gcs (EmacsFrame ew
)
541 struct frame
* s
= ew
->emacs_frame
.frame
;
542 Pixmap blank_stipple
, blank_tile
;
543 unsigned long valuemask
= (GCForeground
| GCBackground
| GCGraphicsExposures
544 | GCStipple
| GCTile
);
547 XSETFONT (font
, ew
->emacs_frame
.font
);
548 font
= Ffont_xlfd_name (font
, Qnil
);
551 XFontStruct
*xfont
= XLoadQueryFont (FRAME_X_DISPLAY_INFO (s
)->display
,
555 gc_values
.font
= xfont
->fid
;
560 /* We have to initialize all of our GCs to have a stipple/tile, otherwise
561 XGetGCValues returns uninitialized data when we query the stipple
562 (instead of None or something sensible) and it makes things hard.
564 This should be fixed for real by not querying the GCs but instead having
565 some GC-based cache instead of the current face-based cache which doesn't
566 effectively cache all of the GC settings we need to use.
570 = XCreateBitmapFromData (XtDisplay (ew
),
571 RootWindowOfScreen (XtScreen (ew
)),
572 setup_frame_cursor_bits
, 2, 2);
574 /* use fg = 0, bg = 1 below, but it's irrelevant since this pixmap should
575 never actually get used as a background tile!
578 = XCreatePixmapFromBitmapData (XtDisplay (ew
),
579 RootWindowOfScreen (XtScreen (ew
)),
580 setup_frame_cursor_bits
, 2, 2,
581 0, 1, ew
->core
.depth
);
584 gc_values
.foreground
= ew
->emacs_frame
.foreground_pixel
;
585 gc_values
.background
= ew
->core
.background_pixel
;
586 gc_values
.graphics_exposures
= False
;
587 gc_values
.stipple
= blank_stipple
;
588 gc_values
.tile
= blank_tile
;
589 XChangeGC (XtDisplay (ew
), s
->output_data
.x
->normal_gc
,
590 valuemask
, &gc_values
);
592 /* Reverse video style. */
593 gc_values
.foreground
= ew
->core
.background_pixel
;
594 gc_values
.background
= ew
->emacs_frame
.foreground_pixel
;
595 gc_values
.graphics_exposures
= False
;
596 gc_values
.stipple
= blank_stipple
;
597 gc_values
.tile
= blank_tile
;
598 XChangeGC (XtDisplay (ew
), s
->output_data
.x
->reverse_gc
,
599 valuemask
, &gc_values
);
601 /* Cursor has to have an empty stipple. */
602 gc_values
.foreground
= ew
->core
.background_pixel
;
603 gc_values
.background
= ew
->emacs_frame
.cursor_color
;
604 gc_values
.graphics_exposures
= False
;
605 gc_values
.tile
= blank_tile
;
607 = XCreateBitmapFromData (XtDisplay (ew
),
608 RootWindowOfScreen (XtScreen (ew
)),
609 setup_frame_cursor_bits
, 16, 16);
610 XChangeGC (XtDisplay (ew
), s
->output_data
.x
->cursor_gc
,
611 valuemask
, &gc_values
);
615 update_various_frame_slots (EmacsFrame ew
)
617 struct frame
*f
= ew
->emacs_frame
.frame
;
618 struct x_output
*x
= f
->output_data
.x
;
619 FRAME_PIXEL_HEIGHT (f
) = ew
->core
.height
+ x
->menubar_height
;
620 FRAME_PIXEL_WIDTH (f
) = ew
->core
.width
;
621 f
->internal_border_width
= ew
->emacs_frame
.internal_border_width
;
626 update_from_various_frame_slots (EmacsFrame ew
)
628 struct frame
*f
= ew
->emacs_frame
.frame
;
629 struct x_output
*x
= f
->output_data
.x
;
630 ew
->core
.height
= FRAME_PIXEL_HEIGHT (f
) - x
->menubar_height
;
631 ew
->core
.width
= FRAME_PIXEL_WIDTH (f
);
632 ew
->core
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
633 ew
->emacs_frame
.internal_border_width
= f
->internal_border_width
;
634 ew
->emacs_frame
.font
= x
->font
;
635 ew
->emacs_frame
.foreground_pixel
= FRAME_FOREGROUND_PIXEL (f
);
636 ew
->emacs_frame
.cursor_color
= x
->cursor_pixel
;
637 ew
->core
.border_pixel
= x
->border_pixel
;
641 EmacsFrameInitialize (Widget request
, Widget
new, ArgList dum1
, Cardinal
*dum2
)
643 EmacsFrame ew
= (EmacsFrame
)new;
645 if (!ew
->emacs_frame
.frame
)
648 "can't create an emacs frame widget without a frame\n");
652 update_from_various_frame_slots (ew
);
658 EmacsFrameRealize (Widget widget
, XtValueMask
*mask
, XSetWindowAttributes
*attrs
)
660 EmacsFrame ew
= (EmacsFrame
)widget
;
662 /* This used to contain SubstructureRedirectMask, but this turns out
663 to be a problem with XIM on Solaris, and events from that mask
664 don't seem to be used. Let's check that. */
665 attrs
->event_mask
= (STANDARD_EVENT_SET
667 | SubstructureNotifyMask
);
668 *mask
|= CWEventMask
;
669 XtCreateWindow (widget
, InputOutput
, (Visual
*)CopyFromParent
, *mask
,
671 update_wm_hints (ew
);
675 EmacsFrameDestroy (Widget widget
)
677 EmacsFrame ew
= (EmacsFrame
) widget
;
678 struct frame
* s
= ew
->emacs_frame
.frame
;
680 if (! s
) emacs_abort ();
681 if (! s
->output_data
.x
) emacs_abort ();
685 if (s
->output_data
.x
->white_relief
.gc
)
686 XFreeGC (XtDisplay (widget
), s
->output_data
.x
->white_relief
.gc
);
687 if (s
->output_data
.x
->black_relief
.gc
)
688 XFreeGC (XtDisplay (widget
), s
->output_data
.x
->black_relief
.gc
);
693 EmacsFrameResize (Widget widget
)
695 EmacsFrame ew
= (EmacsFrame
)widget
;
696 struct frame
*f
= ew
->emacs_frame
.frame
;
700 pixel_to_char_size (ew
, ew
->core
.width
, ew
->core
.height
, &columns
, &rows
);
701 change_frame_size (f
, rows
, columns
, 0, 1, 0);
702 update_wm_hints (ew
);
703 update_various_frame_slots (ew
);
705 cancel_mouse_face (f
);
709 EmacsFrameSetValues (Widget cur_widget
, Widget req_widget
, Widget new_widget
, ArgList dum1
, Cardinal
*dum2
)
711 EmacsFrame cur
= (EmacsFrame
)cur_widget
;
712 EmacsFrame
new = (EmacsFrame
)new_widget
;
714 Boolean needs_a_refresh
= False
;
715 Boolean has_to_recompute_size
;
716 Boolean has_to_recompute_gcs
;
717 Boolean has_to_update_hints
;
719 int char_width
, char_height
;
720 Dimension pixel_width
;
721 Dimension pixel_height
;
723 /* AFAIK, this function is never called. -- Jan D, Oct 2009. */
724 has_to_recompute_gcs
= (cur
->emacs_frame
.font
!= new->emacs_frame
.font
725 || (cur
->emacs_frame
.foreground_pixel
726 != new->emacs_frame
.foreground_pixel
)
727 || (cur
->core
.background_pixel
728 != new->core
.background_pixel
)
731 has_to_recompute_size
= (cur
->emacs_frame
.font
!= new->emacs_frame
.font
732 && cur
->core
.width
== new->core
.width
733 && cur
->core
.height
== new->core
.height
);
735 has_to_update_hints
= (cur
->emacs_frame
.font
!= new->emacs_frame
.font
);
737 if (has_to_recompute_gcs
)
739 setup_frame_gcs (new);
740 needs_a_refresh
= True
;
743 if (has_to_recompute_size
)
745 pixel_width
= new->core
.width
;
746 pixel_height
= new->core
.height
;
747 pixel_to_char_size (new, pixel_width
, pixel_height
, &char_width
,
749 char_to_pixel_size (new, char_width
, char_height
, &pixel_width
,
751 new->core
.width
= pixel_width
;
752 new->core
.height
= pixel_height
;
754 change_frame_size (new->emacs_frame
.frame
, char_height
, char_width
,
756 needs_a_refresh
= True
;
759 if (has_to_update_hints
)
760 update_wm_hints (new);
762 update_various_frame_slots (new);
764 /* #### This doesn't work, I haven't been able to find ANY kludge that
765 will let (x-create-frame '((iconic . t))) work. It seems that changes
766 to wm_shell's iconic slot have no effect after it has been realized,
767 and calling XIconifyWindow doesn't work either (even though the window
768 has been created.) Perhaps there is some property we could smash
769 directly, but I'm sick of this for now.
771 if (cur
->emacs_frame
.iconic
!= new->emacs_frame
.iconic
)
773 Widget wmshell
= get_wm_shell ((Widget
) cur
);
774 XtVaSetValues (wmshell
, XtNiconic
,
775 (XtArgVal
) new->emacs_frame
.iconic
, NULL
);
778 return needs_a_refresh
;
781 static XtGeometryResult
782 EmacsFrameQueryGeometry (Widget widget
, XtWidgetGeometry
*request
, XtWidgetGeometry
*result
)
784 EmacsFrame ew
= (EmacsFrame
)widget
;
786 int mask
= request
->request_mode
;
787 Dimension ok_width
, ok_height
;
789 if (mask
& (CWWidth
| CWHeight
))
791 round_size_to_char (ew
,
792 (mask
& CWWidth
) ? request
->width
: ew
->core
.width
,
793 ((mask
& CWHeight
) ? request
->height
795 &ok_width
, &ok_height
);
796 if ((mask
& CWWidth
) && (ok_width
!= request
->width
))
798 result
->request_mode
|= CWWidth
;
799 result
->width
= ok_width
;
801 if ((mask
& CWHeight
) && (ok_height
!= request
->height
))
803 result
->request_mode
|= CWHeight
;
804 result
->height
= ok_height
;
807 return result
->request_mode
? XtGeometryAlmost
: XtGeometryYes
;
810 /* Special entry points */
812 EmacsFrameSetCharSize (Widget widget
, int columns
, int rows
)
814 EmacsFrame ew
= (EmacsFrame
) widget
;
815 struct frame
*f
= ew
->emacs_frame
.frame
;
817 x_set_window_size (f
, 0, columns
, rows
);
822 widget_store_internal_border (Widget widget
)
824 EmacsFrame ew
= (EmacsFrame
) widget
;
825 FRAME_PTR f
= ew
->emacs_frame
.frame
;
827 ew
->emacs_frame
.internal_border_width
= f
->internal_border_width
;