1 /* Emacs manager widget.
2 Copyright (C) 1993-1995 Sun Microsystems, Inc.
3 Copyright (C) 1995 Ben Wing.
5 This file is part of XEmacs.
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Synched up with: Not in FSF. */
24 /* Written by Ben Wing, May, 1994. */
28 #include <X11/StringDefs.h>
29 #include "EmacsManagerP.h"
30 #ifdef LWLIB_MENUBARS_MOTIF
31 #include <Xm/RowColumn.h>
32 #endif /* LWLIB_MENUBARS_MOTIF */
34 /* For I, Emacs, am a kind god. Unlike the goddess Athena and the
35 Titan Motif, I require no ritual sacrifices to placate the lesser
36 daemons of geometry management. */
38 static XtResource resources[] = {
39 #define offset(field) XtOffset(EmacsManagerWidget, emacs_manager.field)
40 { XtNresizeCallback, XtCCallback,
41 XtRCallback, sizeof (XtCallbackList),
42 offset(resize_callback), XtRImmediate, (XtPointer) 0 },
43 { XtNqueryGeometryCallback, XtCCallback,
44 XtRCallback, sizeof (XtCallbackList),
45 offset(query_geometry_callback), XtRImmediate, (XtPointer) 0 },
46 { XtNuserData, XtCUserData,
47 XtRPointer, sizeof (XtPointer),
48 offset(user_data), XtRImmediate, (XtPointer) 0 },
51 /****************************************************************
53 * Full class record constant
55 ****************************************************************/
57 static XtGeometryResult QueryGeometry (Widget wid,
58 XtWidgetGeometry *request,
59 XtWidgetGeometry *reply);
60 static void Resize (Widget w);
61 static XtGeometryResult GeometryManager (Widget w, XtWidgetGeometry *request,
62 XtWidgetGeometry *reply);
63 static void ChangeManaged (Widget w);
64 static void Realize (Widget w, Mask *valueMask,
65 XSetWindowAttributes *attributes);
66 static void ClassInitialize (void);
68 EmacsManagerClassRec emacsManagerClassRec = {
70 /* core_class fields */
71 #ifdef LWLIB_USES_MOTIF
72 /* superclass */ (WidgetClass) &xmManagerClassRec,
74 /* superclass */ (WidgetClass) &compositeClassRec,
76 /* class_name */ "EmacsManager",
77 /* widget_size */ sizeof (EmacsManagerRec),
78 /* class_initialize */ ClassInitialize,
79 /* class_part_init */ NULL,
80 /* class_inited */ FALSE,
81 /* initialize */ NULL,
82 /* initialize_hook */ NULL,
83 /* realize */ Realize,
86 /* resources */ resources,
87 /* num_resources */ XtNumber(resources),
88 /* xrm_class */ NULLQUARK,
89 /* compress_motion */ TRUE,
90 /* compress_exposure */ XtExposeCompressMaximal | XtExposeNoRegion,
91 /* compress_enterleave*/ TRUE,
92 /* visible_interest */ FALSE,
96 /* set_values */ NULL,
97 /* set_values_hook */ NULL,
98 /* set_values_almost */ XtInheritSetValuesAlmost,
99 /* get_values_hook */ NULL,
100 /* accept_focus */ NULL,
101 /* version */ XtVersion,
102 /* callback_private */ NULL,
103 /* tm_table */ XtInheritTranslations,
104 /* query_geometry */ QueryGeometry,
105 /* display_accelerator*/ XtInheritDisplayAccelerator,
109 /* composite_class fields */
110 /* geometry_manager */ GeometryManager,
111 /* change_managed */ ChangeManaged,
112 /* insert_child */ XtInheritInsertChild,
113 /* delete_child */ XtInheritDeleteChild,
116 #ifdef LWLIB_USES_MOTIF
118 /* constraint_class fields */
119 NULL, /* resource list */
120 0, /* num resources */
121 0, /* constraint size */
122 (XtInitProc)NULL, /* init proc */
123 (XtWidgetProc)NULL, /* destroy proc */
124 (XtSetValuesFunc)NULL, /* set values proc */
125 NULL, /* extension */
128 /* manager_class fields */
129 XtInheritTranslations, /* translations */
130 NULL, /* syn_resources */
131 0, /* num_syn_resources */
132 NULL, /* syn_cont_resources */
133 0, /* num_syn_cont_resources */
134 XmInheritParentProcess, /* parent_process */
135 NULL, /* extension */
139 /* emacs_manager_class fields */
144 WidgetClass emacsManagerWidgetClass = (WidgetClass)&emacsManagerClassRec;
146 /* What is my preferred size? A suggested size may be given. */
148 static XtGeometryResult
149 QueryGeometry (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
151 EmacsManagerWidget emw = (EmacsManagerWidget) w;
152 EmacsManagerQueryGeometryStruct struc;
153 int request_mode = request->request_mode;
155 struc.request_mode = request_mode;
156 struc.proposed_width = (request_mode & CWWidth) ? request->width : 0;
157 struc.proposed_height = (request_mode & CWHeight) ? request->height : 0;
158 XtCallCallbackList (w, emw->emacs_manager.query_geometry_callback, &struc);
159 reply->request_mode = CWWidth | CWHeight;
160 reply->width = struc.proposed_width;
161 reply->height = struc.proposed_height;
162 if (((request_mode & CWWidth) && (request->width != reply->width)) ||
163 ((request_mode & CWHeight) && (request->height != reply->height)))
164 return XtGeometryAlmost;
165 return XtGeometryYes;
171 EmacsManagerWidget emw = (EmacsManagerWidget) w;
172 EmacsManagerResizeStruct struc;
174 struc.width = w->core.width;
175 struc.height = w->core.height;
176 XtCallCallbackList (w, emw->emacs_manager.resize_callback, &struc);
179 static XtGeometryResult
180 GeometryManager (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
182 /* Sure, any changes are fine. */
184 #ifdef LWLIB_MENUBARS_MOTIF
185 /* The Motif menubar will merrily request a new size every time a
186 child is added or deleted. Blow it off because it doesn't know
187 what it's talking about. */
188 if (XtClass (w) != xmRowColumnWidgetClass)
189 #endif /* LWLIB_MENUBARS_MOTIF */
191 if (request->request_mode & CWWidth) w->core.width = request->width;
192 if (request->request_mode & CWHeight) w->core.height = request->height;
194 if (request->request_mode & CWBorderWidth)
195 w->core.border_width = request->border_width;
196 if (request->request_mode & CWX) w->core.x = request->x;
197 if (request->request_mode & CWY) w->core.y = request->y;
199 return XtGeometryYes;
203 ChangeManaged (Widget w)
205 if (!XtIsRealized (w))
207 XtWidgetGeometry request, reply;
209 /* find out how big we'd like to be ... */
211 request.request_mode = 0;
212 XtQueryGeometry (w, &request, &reply);
213 EmacsManagerChangeSize (w, reply.width, reply.height);
218 Realize (Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
220 attributes->bit_gravity = NorthWestGravity;
221 *valueMask |= CWBitGravity;
223 XtCreateWindow (w, (unsigned) InputOutput, (Visual *) CopyFromParent,
224 *valueMask, attributes);
228 ClassInitialize (void)
234 EmacsManagerChangeSize (Widget w, Dimension width, Dimension height)
237 width = w->core.width;
239 height = w->core.height;
241 /* do nothing if we're already that size */
242 if (w->core.width != width || w->core.height != height)
244 XtGeometryResult result =
245 XtMakeResizeRequest (w, width, height, &w->core.width, &w->core.height);
246 if (result == XtGeometryNo)
248 if (result == XtGeometryAlmost)
249 XtMakeResizeRequest (w, w->core.width, w->core.height, NULL, NULL);