1 /* Emacs manager widget.
2 Copyright (C) 1993-1995 Sun Microsystems, Inc.
3 Copyright (C) 1995 Ben Wing.
5 This file is part of SXEmacs
7 SXEmacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 SXEmacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* Synched up with: Not in FSF. */
23 /* Written by Ben Wing, May, 1994. */
27 #include <X11/StringDefs.h>
28 #include "EmacsManagerP.h"
29 #ifdef LWLIB_MENUBARS_MOTIF
30 #include <Xm/RowColumn.h>
31 #endif /* LWLIB_MENUBARS_MOTIF */
33 /* For I, Emacs, am a kind god. Unlike the goddess Athena and the
34 Titan Motif, I require no ritual sacrifices to placate the lesser
35 daemons of geometry management. */
37 static XtResource resources[] = {
38 #define offset(field) XtOffset(EmacsManagerWidget, emacs_manager.field)
39 {XtNresizeCallback, XtCCallback,
40 XtRCallback, sizeof(XtCallbackList),
41 offset(resize_callback), XtRImmediate, (XtPointer) 0}
43 {XtNqueryGeometryCallback, XtCCallback,
44 XtRCallback, sizeof(XtCallbackList),
45 offset(query_geometry_callback), XtRImmediate, (XtPointer) 0}
47 {XtNuserData, XtCUserData,
48 XtRPointer, sizeof(XtPointer),
49 offset(user_data), XtRImmediate, (XtPointer) 0}
53 /****************************************************************
55 * Full class record constant
57 ****************************************************************/
59 static XtGeometryResult QueryGeometry(Widget wid,
60 XtWidgetGeometry * request,
61 XtWidgetGeometry * reply);
62 static void Resize(Widget w);
63 static XtGeometryResult GeometryManager(Widget w, XtWidgetGeometry * request,
64 XtWidgetGeometry * reply);
65 static void ChangeManaged(Widget w);
66 static void Realize(Widget w, Mask * valueMask,
67 XSetWindowAttributes * attributes);
68 static void ClassInitialize(void);
70 EmacsManagerClassRec emacsManagerClassRec = {
72 /* core_class fields */
73 #ifdef LWLIB_USES_MOTIF
74 /* superclass */ (WidgetClass) & xmManagerClassRec,
76 /* superclass */ (WidgetClass) & compositeClassRec,
78 /* class_name */ "EmacsManager",
79 /* widget_size */ sizeof(EmacsManagerRec),
80 /* class_initialize */ ClassInitialize,
81 /* class_part_init */ NULL,
82 /* class_inited */ FALSE,
83 /* initialize */ NULL,
84 /* initialize_hook */ NULL,
85 /* realize */ Realize,
88 /* resources */ resources,
89 /* num_resources */ XtNumber(resources),
90 /* xrm_class */ NULLQUARK,
91 /* compress_motion */ TRUE,
92 /* compress_exposure */ XtExposeCompressMaximal | XtExposeNoRegion,
93 /* compress_enterleave */ TRUE,
94 /* visible_interest */ FALSE,
98 /* set_values */ NULL,
99 /* set_values_hook */ NULL,
100 /* set_values_almost */ XtInheritSetValuesAlmost,
101 /* get_values_hook */ NULL,
102 /* accept_focus */ NULL,
103 /* version */ XtVersion,
104 /* callback_private */ NULL,
105 /* tm_table */ XtInheritTranslations,
106 /* query_geometry */ QueryGeometry,
107 /* display_accelerator */ XtInheritDisplayAccelerator,
112 /* composite_class fields */
113 /* geometry_manager */ GeometryManager,
114 /* change_managed */ ChangeManaged,
115 /* insert_child */ XtInheritInsertChild,
116 /* delete_child */ XtInheritDeleteChild,
120 #ifdef LWLIB_USES_MOTIF
122 /* constraint_class fields */
123 NULL, /* resource list */
124 0, /* num resources */
125 0, /* constraint size */
126 (XtInitProc) NULL, /* init proc */
127 (XtWidgetProc) NULL, /* destroy proc */
128 (XtSetValuesFunc) NULL, /* set values proc */
129 NULL, /* extension */
133 /* manager_class fields */
134 XtInheritTranslations, /* translations */
135 NULL, /* syn_resources */
136 0, /* num_syn_resources */
137 NULL, /* syn_cont_resources */
138 0, /* num_syn_cont_resources */
139 XmInheritParentProcess, /* parent_process */
140 NULL, /* extension */
145 /* emacs_manager_class fields */
150 WidgetClass emacsManagerWidgetClass = (WidgetClass) & emacsManagerClassRec;
152 /* What is my preferred size? A suggested size may be given. */
154 static XtGeometryResult
155 QueryGeometry(Widget w, XtWidgetGeometry * request, XtWidgetGeometry * reply)
157 EmacsManagerWidget emw = (EmacsManagerWidget) w;
158 EmacsManagerQueryGeometryStruct struc;
159 int request_mode = request->request_mode;
161 struc.request_mode = request_mode;
162 struc.proposed_width = (request_mode & CWWidth) ? request->width : 0;
163 struc.proposed_height = (request_mode & CWHeight) ? request->height : 0;
164 XtCallCallbackList(w, emw->emacs_manager.query_geometry_callback,
166 reply->request_mode = CWWidth | CWHeight;
167 reply->width = struc.proposed_width;
168 reply->height = struc.proposed_height;
169 if (((request_mode & CWWidth) && (request->width != reply->width)) ||
170 ((request_mode & CWHeight) && (request->height != reply->height)))
171 return XtGeometryAlmost;
172 return XtGeometryYes;
175 static void Resize(Widget w)
177 EmacsManagerWidget emw = (EmacsManagerWidget) w;
178 EmacsManagerResizeStruct struc;
180 struc.width = w->core.width;
181 struc.height = w->core.height;
182 XtCallCallbackList(w, emw->emacs_manager.resize_callback, &struc);
185 static XtGeometryResult
186 GeometryManager(Widget w, XtWidgetGeometry * request, XtWidgetGeometry * reply)
188 /* Sure, any changes are fine. */
190 #ifdef LWLIB_MENUBARS_MOTIF
191 /* The Motif menubar will merrily request a new size every time a
192 child is added or deleted. Blow it off because it doesn't know
193 what it's talking about. */
194 if (XtClass(w) != xmRowColumnWidgetClass)
195 #endif /* LWLIB_MENUBARS_MOTIF */
197 if (request->request_mode & CWWidth)
198 w->core.width = request->width;
199 if (request->request_mode & CWHeight)
200 w->core.height = request->height;
202 if (request->request_mode & CWBorderWidth)
203 w->core.border_width = request->border_width;
204 if (request->request_mode & CWX)
205 w->core.x = request->x;
206 if (request->request_mode & CWY)
207 w->core.y = request->y;
209 return XtGeometryYes;
212 static void ChangeManaged(Widget w)
214 if (!XtIsRealized(w)) {
215 XtWidgetGeometry request, reply;
217 /* find out how big we'd like to be ... */
219 request.request_mode = 0;
220 XtQueryGeometry(w, &request, &reply);
221 EmacsManagerChangeSize(w, reply.width, reply.height);
226 Realize(Widget w, Mask * valueMask, XSetWindowAttributes * attributes)
228 attributes->bit_gravity = NorthWestGravity;
229 *valueMask |= CWBitGravity;
231 XtCreateWindow(w, (unsigned)InputOutput, (Visual *) CopyFromParent,
232 *valueMask, attributes);
235 static void ClassInitialize(void)
240 void EmacsManagerChangeSize(Widget w, Dimension width, Dimension height)
243 width = w->core.width;
245 height = w->core.height;
247 /* do nothing if we're already that size */
248 if (w->core.width != width || w->core.height != height) {
249 XtGeometryResult result =
250 XtMakeResizeRequest(w, width, height, &w->core.width,
252 if (result == XtGeometryNo)
254 if (result == XtGeometryAlmost)
255 XtMakeResizeRequest(w, w->core.width, w->core.height,