0
|
1 /* The emacs frame widget.
|
|
2 Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1993-1995 Sun Microsystems, Inc.
|
|
4 Copyright (C) 1995 Ben Wing.
|
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
|
25 /* #### Note to potential hackers: Don't mess with this unless you're
|
|
26 sure you know what you're doing! Xt is a lot more subtle than
|
|
27 you may think. */
|
|
28
|
|
29 #include <config.h>
|
|
30 #include "lisp.h"
|
|
31
|
|
32 #include "console-x.h"
|
|
33 #include "glyphs-x.h"
|
|
34 #include "objects-x.h"
|
|
35 #include <X11/Shell.h>
|
|
36 #include "EmacsFrameP.h"
|
|
37 #include "EmacsManager.h" /* for EmacsManagerChangeSize */
|
|
38 #include "xmu.h"
|
|
39
|
|
40 #include "faces.h"
|
|
41 #include "frame.h"
|
|
42 #include "toolbar.h"
|
|
43 #include "redisplay.h"
|
|
44 #include "window.h"
|
|
45
|
|
46 static void EmacsFrameClassInitialize (void);
|
|
47 static void EmacsFrameInitialize (Widget, Widget, ArgList, Cardinal *);
|
|
48 static void EmacsFrameRealize (Widget, XtValueMask*, XSetWindowAttributes*);
|
|
49 static void EmacsFrameResize (Widget widget);
|
|
50 static Boolean EmacsFrameSetValues (Widget, Widget, Widget,
|
|
51 ArgList, Cardinal *);
|
|
52 static XtGeometryResult EmacsFrameQueryGeometry (Widget, XtWidgetGeometry*,
|
|
53 XtWidgetGeometry*);
|
|
54
|
|
55 extern void
|
|
56 emacs_Xt_mapping_action (Widget w, XMappingEvent* event);
|
|
57
|
|
58 #undef XtOffset
|
|
59 #define XtOffset(p_type,field) \
|
|
60 ((Cardinal) (((char *) (&(((p_type)0)->field))) - ((char *)0)))
|
|
61 #define offset(field) XtOffset(EmacsFrame, emacs_frame.field)
|
|
62
|
|
63 static XtResource resources[] = {
|
|
64 {XtNgeometry, XtCGeometry, XtRString, sizeof(String),
|
|
65 offset (geometry), XtRString, (XtPointer) 0},
|
|
66 {XtNiconic, XtCIconic, XtRBoolean, sizeof(Boolean),
|
|
67 offset (iconic), XtRImmediate, (XtPointer) False},
|
|
68
|
|
69 {XtNemacsFrame, XtCEmacsFrame, XtRPointer, sizeof (XtPointer),
|
|
70 offset (frame), XtRImmediate, 0},
|
|
71 {XtNmenubar, XtCMenubar, XtRBoolean, sizeof (Boolean),
|
|
72 offset (menubar_p), XtRImmediate, (XtPointer) True},
|
|
73 {XtNinitiallyUnmapped, XtCInitiallyUnmapped, XtRBoolean, sizeof (Boolean),
|
|
74 offset (initially_unmapped), XtRImmediate, (XtPointer) False},
|
|
75 {XtNminibuffer, XtCMinibuffer, XtRBoolean, sizeof (Boolean),
|
|
76 offset (minibuffer), XtRImmediate, (XtPointer) True},
|
|
77 {XtNunsplittable, XtCUnsplittable, XtRBoolean, sizeof (Boolean),
|
|
78 offset (unsplittable), XtRImmediate, (XtPointer) False},
|
|
79 {XtNinternalBorderWidth, XtCInternalBorderWidth, XtRInt, sizeof (int),
|
|
80 offset (internal_border_width), XtRImmediate, (XtPointer)4},
|
|
81 #ifdef HAVE_SCROLLBARS
|
|
82 {XtNscrollBarWidth, XtCScrollBarWidth, XtRInt, sizeof (int),
|
|
83 offset (scrollbar_width), XtRImmediate, (XtPointer)-1},
|
|
84 {XtNscrollBarHeight, XtCScrollBarHeight, XtRInt, sizeof (int),
|
|
85 offset (scrollbar_height), XtRImmediate, (XtPointer)-1},
|
|
86 {XtNscrollBarPlacement, XtCScrollBarPlacement, XtRScrollBarPlacement,
|
|
87 sizeof(unsigned char), offset(scrollbar_placement), XtRImmediate,
|
|
88 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
|
|
89 (XtPointer) XtBOTTOM_RIGHT
|
|
90 #else
|
|
91 (XtPointer) XtBOTTOM_LEFT
|
|
92 #endif
|
|
93 },
|
|
94 #endif /* HAVE_SCROLLBARS */
|
|
95 #ifdef HAVE_TOOLBARS
|
|
96 {XtNtopToolBarHeight, XtCTopToolBarHeight, XtRInt, sizeof (int),
|
|
97 offset (top_toolbar_height), XtRImmediate, (XtPointer)-1},
|
|
98 {XtNbottomToolBarHeight, XtCBottomToolBarHeight, XtRInt, sizeof (int),
|
|
99 offset (bottom_toolbar_height), XtRImmediate, (XtPointer)-1},
|
|
100 {XtNleftToolBarWidth, XtCLeftToolBarWidth, XtRInt, sizeof (int),
|
|
101 offset (left_toolbar_width), XtRImmediate, (XtPointer)-1},
|
|
102 {XtNrightToolBarWidth, XtCRightToolBarWidth, XtRInt, sizeof (int),
|
|
103 offset (right_toolbar_width), XtRImmediate, (XtPointer)-1},
|
|
104 {XtNtopToolBarShadowColor, XtCTopToolBarShadowColor, XtRPixel, sizeof(Pixel),
|
2
|
105 offset(top_toolbar_shadow_pixel), XtRString, (String) "Gray90"},
|
0
|
106 {XtNbottomToolBarShadowColor, XtCBottomToolBarShadowColor, XtRPixel,
|
|
107 sizeof(Pixel), offset(bottom_toolbar_shadow_pixel), XtRString,
|
2
|
108 (String) "Gray40"},
|
0
|
109 {XtNbackgroundToolBarColor, XtCBackgroundToolBarColor, XtRPixel,
|
|
110 sizeof(Pixel), offset(background_toolbar_pixel), XtRString,
|
2
|
111 (String) "Gray75"},
|
0
|
112 {XtNtopToolBarShadowPixmap, XtCTopToolBarShadowPixmap, XtRPixmap,
|
|
113 sizeof (Pixmap), offset(top_toolbar_shadow_pixmap), XtRImmediate,
|
|
114 (XtPointer)None},
|
|
115 {XtNbottomToolBarShadowPixmap, XtCBottomToolBarShadowPixmap, XtRPixmap,
|
|
116 sizeof (Pixmap), offset(bottom_toolbar_shadow_pixmap), XtRImmediate,
|
|
117 (XtPointer)None},
|
|
118 {XtNtoolBarShadowThickness, XtCToolBarShadowThickness, XtRDimension,
|
|
119 sizeof (Dimension), offset (toolbar_shadow_thickness), XtRImmediate,
|
|
120 (XtPointer)2},
|
|
121 #endif /* HAVE_TOOLBARS */
|
|
122 {XtNinterline, XtCInterline, XtRInt, sizeof (int),
|
|
123 offset (interline), XtRImmediate, (XtPointer)0},
|
|
124 {
|
|
125 #ifdef I18N4
|
|
126 XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet),
|
|
127 #else
|
|
128 XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
|
|
129 #endif
|
|
130 offset(font), XtRImmediate, (XtPointer)0
|
|
131 },
|
|
132 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
|
2
|
133 offset(foreground_pixel), XtRString, (String) "XtDefaultForeground"},
|
0
|
134 {XtNcursorColor, XtCForeground, XtRPixel, sizeof(Pixel),
|
2
|
135 offset(cursor_color), XtRString, (String) "XtDefaultForeground"},
|
0
|
136 {XtNbarCursor, XtCBarCursor, XtRBoolean, sizeof (Boolean),
|
|
137 offset (bar_cursor), XtRImmediate, (XtPointer)0},
|
|
138 {XtNvisualBell, XtCVisualBell, XtRBoolean, sizeof (Boolean),
|
|
139 offset (visual_bell), XtRImmediate, (XtPointer)0},
|
|
140 {XtNbellVolume, XtCBellVolume, XtRInt, sizeof (int),
|
|
141 offset (bell_volume), XtRImmediate, (XtPointer)0},
|
|
142 {XtNuseBackingStore, XtCUseBackingStore, XtRBoolean, sizeof (Boolean),
|
|
143 offset (use_backing_store), XtRImmediate, (XtPointer)0},
|
|
144 {XtNpreferredWidth, XtCPreferredWidth, XtRDimension, sizeof (Dimension),
|
|
145 offset (preferred_width), XtRImmediate, (XtPointer)0},
|
|
146 {XtNpreferredHeight, XtCPreferredHeight, XtRDimension, sizeof (Dimension),
|
|
147 offset (preferred_height), XtRImmediate, (XtPointer)0},
|
|
148 };
|
|
149
|
|
150 #undef offset
|
|
151
|
|
152 /* Xt is stupid and dumb.
|
|
153 Xt is stupid and dumb.
|
|
154 Xt is stupid and dumb. */
|
|
155
|
|
156 static XtActionsRec
|
|
157 emacsFrameActionsTable [] = {
|
2
|
158 {(String) "mapping", (XtActionProc) emacs_Xt_mapping_action},
|
0
|
159 };
|
|
160
|
|
161 static char
|
|
162 emacsFrameTranslations [] = "\
|
|
163 <Mapping>: mapping()\n\
|
|
164 ";
|
|
165
|
|
166 /* If we're running under Motif, make this widget a subclass
|
|
167 of XmPrimitive. It's not clear this is necessary, but it
|
|
168 may make focus behavior work better. */
|
|
169
|
|
170 EmacsFrameClassRec emacsFrameClassRec = {
|
|
171 { /* core fields */
|
|
172 #ifdef LWLIB_USES_MOTIF
|
|
173 /* superclass */ (WidgetClass) &xmPrimitiveClassRec,
|
|
174 #else
|
|
175 /* superclass */ &widgetClassRec,
|
|
176 #endif
|
2
|
177 /* class_name */ (String) "EmacsFrame",
|
0
|
178 /* widget_size */ sizeof(EmacsFrameRec),
|
|
179 /* class_initialize */ EmacsFrameClassInitialize,
|
|
180 /* class_part_initialize */ 0,
|
|
181 /* class_inited */ FALSE,
|
|
182 /* initialize */ EmacsFrameInitialize,
|
|
183 /* initialize_hook */ 0,
|
|
184 /* realize */ EmacsFrameRealize,
|
|
185 /* actions */ emacsFrameActionsTable,
|
|
186 /* num_actions */ XtNumber (emacsFrameActionsTable),
|
|
187 /* resources */ resources,
|
|
188 /* resource_count */ XtNumber(resources),
|
|
189 /* xrm_class */ NULLQUARK,
|
|
190 /* compress_motion */ TRUE,
|
|
191 /* compress_exposure */ TRUE,
|
|
192 /* compress_enterleave */ TRUE,
|
|
193 /* visible_interest */ FALSE,
|
|
194 /* destroy */ NULL,
|
|
195 /* resize */ EmacsFrameResize,
|
|
196 /* expose */ XtInheritExpose,
|
|
197 /* set_values */ EmacsFrameSetValues,
|
|
198 /* set_values_hook */ 0,
|
|
199 /* set_values_almost */ XtInheritSetValuesAlmost,
|
|
200 /* get_values_hook */ 0,
|
|
201 /* accept_focus */ XtInheritAcceptFocus,
|
|
202 /* version */ XtVersion,
|
|
203 /* callback_private */ 0,
|
|
204 /* tm_table */ emacsFrameTranslations,
|
|
205 /* query_geometry */ EmacsFrameQueryGeometry,
|
|
206 /* display_accelerator */ XtInheritDisplayAccelerator,
|
|
207 /* extension */ 0
|
|
208 },
|
|
209 #ifdef LWLIB_USES_MOTIF
|
|
210 { /* XmPrimitiveClassPart
|
|
211 */
|
|
212 (XtWidgetProc) _XtInherit, /* border_highlight */
|
|
213 (XtWidgetProc) _XtInherit, /* border_unhighlight */
|
|
214 /* Setting the following to NULL causes PrimitiveInitialize()
|
|
215 not to add traversal (TAB etc. to switch focus) and
|
|
216 focus-in/out (border highlight/unhighlight) translations.
|
|
217 If you want those translations, use the value XtInheritTranslations
|
|
218 instead. Doing this, however, will interfere with Emacs
|
|
219 focus handling (which highlights/unhighlights the text cursor),
|
|
220 and will lead to strange display results around the border of the
|
|
221 widget. */
|
|
222 NULL, /* translations */
|
|
223 NULL, /* arm_and_activate */
|
|
224 NULL, /* get resources */
|
|
225 0, /* num get_resources */
|
|
226 NULL, /* extension */
|
|
227 },
|
|
228 #endif /* LWLIB_USES_MOTIF */
|
|
229 {
|
|
230 0
|
|
231 }
|
|
232 };
|
|
233 WidgetClass emacsFrameClass = (WidgetClass) &emacsFrameClassRec;
|
|
234
|
|
235 static void
|
|
236 update_various_frame_slots (EmacsFrame ew)
|
|
237 {
|
|
238 ew->emacs_frame.frame->pixheight = ew->core.height;
|
|
239 ew->emacs_frame.frame->pixwidth = ew->core.width;
|
|
240 ew->emacs_frame.frame->internal_border_width =
|
|
241 ew->emacs_frame.internal_border_width;
|
|
242 }
|
|
243
|
|
244 static void
|
|
245 EmacsFrameInitialize (Widget request, Widget new,
|
|
246 ArgList dum1, Cardinal *dum2)
|
|
247 {
|
|
248 EmacsFrame ew = (EmacsFrame)new;
|
|
249 struct frame *f = ew->emacs_frame.frame;
|
|
250
|
|
251 if (!f)
|
|
252 fatal ("can't create an emacs frame widget without a frame.");
|
|
253 }
|
|
254
|
|
255 void emacs_Xt_event_handler (Widget wid /* unused */,
|
|
256 XtPointer closure /* unused */,
|
|
257 XEvent *event,
|
|
258 Boolean *continue_to_dispatch /* unused */);
|
|
259
|
|
260 static void
|
|
261 EmacsFrameRealize (Widget widget, XtValueMask *mask,
|
|
262 XSetWindowAttributes *attrs)
|
|
263 {
|
|
264 EmacsFrame ew = (EmacsFrame) widget;
|
|
265 struct frame *f = ew->emacs_frame.frame;
|
|
266 Widget shell_widget = FRAME_X_SHELL_WIDGET (f);
|
|
267
|
2
|
268 attrs->event_mask =
|
|
269 ExposureMask |
|
|
270 VisibilityChangeMask |
|
|
271 PropertyChangeMask |
|
|
272 StructureNotifyMask |
|
|
273 SubstructureNotifyMask |
|
|
274 /*SubstructureRedirectMask |*/ /* Only for WMs! */
|
|
275 KeyPressMask |
|
|
276 KeyReleaseMask |
|
|
277 ButtonPressMask |
|
|
278 ButtonReleaseMask |
|
|
279 FocusChangeMask |
|
|
280 PointerMotionHintMask |
|
|
281 PointerMotionMask |
|
|
282 LeaveWindowMask |
|
|
283 EnterWindowMask;
|
|
284
|
0
|
285
|
|
286 #ifdef I18N4
|
|
287 /* Make sure that events wanted by the input method are selected. */
|
|
288 attrs->event_mask |= input_method_event_mask;
|
|
289 #endif
|
|
290
|
|
291 *mask |= CWEventMask;
|
|
292
|
|
293 if (ew->emacs_frame.use_backing_store)
|
|
294 {
|
|
295 attrs->backing_store = Always;
|
|
296 *mask |= CWBackingStore;
|
|
297 }
|
|
298 XtCreateWindow (widget, InputOutput, (Visual *)CopyFromParent, *mask,
|
|
299 attrs);
|
|
300
|
|
301 /* snarf the events we want. */
|
|
302 XtInsertEventHandler (widget, attrs->event_mask, TRUE,
|
|
303 emacs_Xt_event_handler, NULL, XtListHead);
|
|
304 /* some events (e.g. map-notify and WM_DELETE_WINDOW) get sent
|
|
305 directly to the shell, and the above event handler won't see
|
|
306 them. So add a handler to get them. These events don't
|
|
307 propagate, so there's no danger of them being seen twice. */
|
|
308 XtInsertEventHandler (shell_widget,
|
|
309 EnterWindowMask | LeaveWindowMask |
|
|
310 VisibilityChangeMask | StructureNotifyMask |
|
|
311 KeyPressMask,
|
|
312 TRUE, emacs_Xt_event_handler, NULL, XtListHead);
|
|
313
|
|
314 #ifdef EXTERNAL_WIDGET
|
|
315 /* #### Not sure if this special case is necessary */
|
|
316 if (!FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
317 #endif
|
|
318 /* This is necessary under Motif in order to make it possible to click in
|
|
319 a buffer and move focus out of a dialog box or control panel and back
|
|
320 into emacs-land; also necessary so that you can still type chars
|
|
321 if the cursor is over the menubar or scrollbar. */
|
|
322 lw_set_keyboard_focus (shell_widget, FRAME_X_TEXT_WIDGET (f));
|
|
323 }
|
|
324
|
|
325 /* DO NOT CALL THIS FUNCTION! Only Xt is supposed to do this. */
|
|
326
|
|
327 static void
|
|
328 EmacsFrameResize (Widget widget)
|
|
329 {
|
|
330 EmacsFrame ew = (EmacsFrame)widget;
|
|
331 struct frame *f = ew->emacs_frame.frame;
|
|
332 int columns;
|
|
333 int rows;
|
|
334 XtWidgetGeometry req, repl;
|
|
335
|
|
336 pixel_to_char_size (f, ew->core.width, ew->core.height, &columns, &rows);
|
|
337 update_various_frame_slots (ew);
|
|
338 change_frame_size (f, rows, columns, 0);
|
|
339
|
|
340 /* Now we tell the EmacsShell that we've changed the size of the non-fixed
|
|
341 portion of the frame. Note that, if we the resize occurred as a result
|
|
342 of EmacsFrameSetCharSize(), this information will be stored twice.
|
|
343 This is not a big deal, as storing this information doesn't actually
|
|
344 do anything until the next resize. */
|
|
345 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
346 x_wm_set_variable_size (FRAME_X_SHELL_WIDGET (f), columns, rows);
|
|
347
|
|
348 /* Kick the manager so that it knows we've changed size. */
|
|
349 req.request_mode = 0;
|
|
350 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
|
|
351 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width,
|
|
352 repl.height);
|
|
353 }
|
|
354
|
|
355 static Boolean
|
|
356 EmacsFrameSetValues (Widget cur_widget, Widget req_widget, Widget new_widget,
|
|
357 ArgList dum1, Cardinal *dum2)
|
|
358 {
|
|
359 EmacsFrame cur = (EmacsFrame) cur_widget;
|
|
360 EmacsFrame new = (EmacsFrame) new_widget;
|
|
361 Lisp_Object frame = Qnil;
|
|
362
|
|
363 XSETFRAME (frame, new->emacs_frame.frame);
|
|
364 in_resource_setting++;
|
|
365 /* This function does not need to do much. Pretty much everything
|
|
366 interesting will get done in the resize method, which will
|
|
367 (if necessary) get called by Xt when this function returns
|
|
368 (see below).
|
|
369 */
|
|
370
|
|
371 /* #### This function will not work if it is not called from
|
|
372 update_EmacsFrame(), called from SET_FACE_PROPERTY().
|
|
373 The code located there should be moved inside of here instead,
|
|
374 so that things work if either SET_FACE_PROPERTY() is
|
|
375 called or XtSetValues() is called.
|
|
376 */
|
|
377
|
|
378 if (cur->emacs_frame.iconic != new->emacs_frame.iconic &&
|
|
379 FRAME_X_TOP_LEVEL_FRAME_P (new->emacs_frame.frame))
|
|
380 x_wm_set_shell_iconic_p (FRAME_X_SHELL_WIDGET (new->emacs_frame.frame),
|
|
381 new->emacs_frame.iconic);
|
|
382
|
|
383 if (!in_specifier_change_function)
|
|
384 {
|
|
385 /* If we got here, then we were likely called as a result of
|
|
386 the EditRes protocol, so go ahead and change scrollbar-width
|
|
387 and scrollbar-height. Otherwise, we're merely mirroring
|
|
388 a change made to scrollbar-width etc. so don't do anything
|
|
389 special. */
|
|
390 #ifdef HAVE_SCROLLBARS
|
|
391 if (cur->emacs_frame.scrollbar_width !=
|
|
392 new->emacs_frame.scrollbar_width)
|
|
393 Fadd_spec_to_specifier
|
|
394 (Vscrollbar_width,
|
|
395 make_int (new->emacs_frame.scrollbar_width),
|
|
396 frame, Qnil, Qnil);
|
|
397 if (cur->emacs_frame.scrollbar_height !=
|
|
398 new->emacs_frame.scrollbar_height)
|
|
399 Fadd_spec_to_specifier
|
|
400 (Vscrollbar_height,
|
|
401 make_int (new->emacs_frame.scrollbar_height),
|
|
402 frame, Qnil, Qnil);
|
|
403 #endif
|
|
404 #ifdef HAVE_TOOLBARS
|
|
405 if (cur->emacs_frame.top_toolbar_height !=
|
|
406 new->emacs_frame.top_toolbar_height)
|
|
407 Fadd_spec_to_specifier
|
|
408 (Vtoolbar_size[TOP_TOOLBAR],
|
|
409 make_int (new->emacs_frame.top_toolbar_height),
|
|
410 frame, Qnil, Qnil);
|
|
411 if (cur->emacs_frame.bottom_toolbar_height !=
|
|
412 new->emacs_frame.bottom_toolbar_height)
|
|
413 Fadd_spec_to_specifier
|
|
414 (Vtoolbar_size[BOTTOM_TOOLBAR],
|
|
415 make_int (new->emacs_frame.bottom_toolbar_height),
|
|
416 frame, Qnil, Qnil);
|
|
417 if (cur->emacs_frame.left_toolbar_width !=
|
|
418 new->emacs_frame.left_toolbar_width)
|
|
419 Fadd_spec_to_specifier
|
|
420 (Vtoolbar_size[LEFT_TOOLBAR],
|
|
421 make_int (new->emacs_frame.left_toolbar_width),
|
|
422 frame, Qnil, Qnil);
|
|
423 if (cur->emacs_frame.right_toolbar_width !=
|
|
424 new->emacs_frame.right_toolbar_width)
|
|
425 Fadd_spec_to_specifier
|
|
426 (Vtoolbar_size[RIGHT_TOOLBAR],
|
|
427 make_int (new->emacs_frame.right_toolbar_width),
|
|
428 frame, Qnil, Qnil);
|
|
429 #endif
|
|
430 }
|
|
431 in_resource_setting--;
|
|
432
|
|
433 return False;
|
|
434
|
|
435 /* Note that if either (a) we return True, or (b) the width or
|
|
436 height has changed, an Expose event will be generated. The Xt
|
|
437 manual says you should not return True if the width or height has
|
|
438 changed, because then two Expose events will be generated.
|
|
439
|
|
440 In any case, there is no need to return True because
|
|
441 SET_FACE_PROPERTY(), which does the resource
|
|
442 setting, automatically forces a redisplay as necessary. */
|
|
443 }
|
|
444
|
|
445 static XtGeometryResult
|
|
446 EmacsFrameQueryGeometry (Widget widget, XtWidgetGeometry *request,
|
|
447 XtWidgetGeometry *result)
|
|
448 {
|
|
449 EmacsFrame ew = (EmacsFrame) widget;
|
|
450 int mask = request->request_mode;
|
|
451 Dimension width, height;
|
|
452 int ok_width_int, ok_height_int;
|
|
453 Dimension ok_width, ok_height;
|
|
454
|
|
455 /* We have a definite preference for what size we would like
|
|
456 to be.
|
|
457
|
|
458 1) If a preferred size was specified for us, use it.
|
|
459 (This is not currently used)
|
|
460 2) If a proposed size was given, round it to the nearest
|
|
461 multiple of the default char size and return it.
|
|
462 3) Otherwise, take our current size and round it to the
|
|
463 nearest multiple of the default char size. */
|
|
464
|
|
465 width = mask & CWWidth ? request->width : ew->core.width;
|
|
466 height = mask & CWHeight ? request->height : ew->core.height;
|
|
467 round_size_to_char (ew->emacs_frame.frame, width, height,
|
|
468 &ok_width_int, &ok_height_int);
|
|
469 ok_width = (Dimension) ok_width_int;
|
|
470 ok_height = (Dimension) ok_height_int;
|
|
471 if (ew->emacs_frame.preferred_width)
|
|
472 ok_width = ew->emacs_frame.preferred_width;
|
|
473 if (ew->emacs_frame.preferred_height)
|
|
474 ok_height = ew->emacs_frame.preferred_height;
|
|
475 result->request_mode |= CWWidth | CWHeight;
|
|
476 result->width = ok_width;
|
|
477 result->height = ok_height;
|
|
478 if (((mask & CWWidth) && ok_width != request->width)
|
|
479 || ((mask & CWHeight) && ok_height != request->height))
|
|
480 return XtGeometryAlmost;
|
|
481 else
|
|
482 return XtGeometryYes;
|
|
483 }
|
|
484 /**** string-to-scrollbar-placement converter: modelled after edge-type
|
|
485 converter in Xaw/Form.c ****/
|
|
486
|
|
487 #define done(address, type) \
|
|
488 toVal->size = sizeof(type); \
|
|
489 toVal->addr = (XtPointer) address; \
|
|
490 return /* `;' supplied by caller */
|
|
491
|
|
492 /* This variable cannot be a stack variable. */
|
|
493 static unsigned char cvt_string_scrollbar_placement;
|
|
494
|
|
495 /* ARGSUSED */
|
|
496 static void
|
|
497 _CvtStringToScrollBarPlacement (args, num_args, fromVal, toVal)
|
|
498 XrmValuePtr args; /* unused */
|
|
499 Cardinal *num_args; /* unused */
|
|
500 XrmValuePtr fromVal;
|
|
501 XrmValuePtr toVal;
|
|
502 {
|
|
503 XrmQuark q;
|
|
504 char lowerName[1000];
|
|
505
|
|
506 XmuCopyISOLatin1Lowered (lowerName, (char*)fromVal->addr);
|
|
507 q = XrmStringToQuark(lowerName);
|
|
508 if (q == XrmStringToQuark ("top_left"))
|
|
509 {
|
|
510 cvt_string_scrollbar_placement = XtTOP_LEFT;
|
|
511 done (&cvt_string_scrollbar_placement, unsigned char);
|
|
512 }
|
|
513 if (q == XrmStringToQuark ("bottom_left"))
|
|
514 {
|
|
515 cvt_string_scrollbar_placement = XtBOTTOM_LEFT;
|
|
516 done (&cvt_string_scrollbar_placement, unsigned char);
|
|
517 }
|
|
518 if (q == XrmStringToQuark ("top_right"))
|
|
519 {
|
|
520 cvt_string_scrollbar_placement = XtTOP_RIGHT;
|
|
521 done (&cvt_string_scrollbar_placement, unsigned char);
|
|
522 }
|
|
523 if (q == XrmStringToQuark ("bottom_right"))
|
|
524 {
|
|
525 cvt_string_scrollbar_placement = XtBOTTOM_RIGHT;
|
|
526 done (&cvt_string_scrollbar_placement, unsigned char);
|
|
527 }
|
|
528 XtStringConversionWarning (fromVal->addr, "scrollBarPlacement");
|
|
529 toVal->addr = NULL;
|
|
530 toVal->size = 0;
|
|
531 }
|
|
532
|
|
533 static void
|
|
534 EmacsFrameClassInitialize (void)
|
|
535 {
|
|
536 XtAddConverter (XtRString, XtRScrollBarPlacement,
|
|
537 _CvtStringToScrollBarPlacement, NULL, 0);
|
|
538 }
|
|
539
|
|
540 /********************* Special entrypoints *******************/
|
|
541
|
|
542 void
|
|
543 EmacsFrameRecomputeCellSize (Widget w)
|
|
544 {
|
|
545 EmacsFrame ew = (EmacsFrame) w;
|
|
546 int cw, ch;
|
|
547 struct frame *f = ew->emacs_frame.frame;
|
|
548
|
|
549 if (! XtIsSubclass (w, emacsFrameClass))
|
|
550 abort ();
|
|
551
|
|
552 default_face_height_and_width (make_frame (f), &ch, &cw);
|
|
553 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
554 x_wm_set_cell_size (FRAME_X_SHELL_WIDGET (f), cw, ch);
|
|
555 }
|
|
556
|
|
557 /* Set the size of the widget to have the number of rows and columns
|
|
558 specified. This both causes the X window to change and the
|
|
559 internal frame structures to get modified to match. */
|
|
560
|
|
561 void
|
|
562 EmacsFrameSetCharSize (Widget widget, int columns, int rows)
|
|
563 {
|
|
564 EmacsFrame ew = (EmacsFrame) widget;
|
|
565 int pixel_width, pixel_height;
|
|
566 struct frame *f = ew->emacs_frame.frame;
|
|
567
|
|
568 if (columns < 3)
|
|
569 columns = 3; /* no way buddy */
|
|
570 if (rows < 1)
|
|
571 rows = 1;
|
|
572
|
|
573 char_to_pixel_size (f, columns, rows, &pixel_width, &pixel_height);
|
|
574
|
|
575 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
576 x_wm_set_variable_size (FRAME_X_SHELL_WIDGET (f), columns, rows);
|
|
577
|
|
578 XtVaSetValues ((Widget) ew,
|
|
579 XtNwidth, (Dimension) pixel_width,
|
|
580 XtNheight, (Dimension) pixel_height,
|
|
581 0);
|
|
582 }
|