428
|
1 /* Emacs manager widget.
|
|
2 Copyright (C) 1993-1995 Sun Microsystems, Inc.
|
|
3 Copyright (C) 1995 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
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
|
|
10 later version.
|
|
11
|
|
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
|
|
15 for more details.
|
|
16
|
|
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. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* Written by Ben Wing, May, 1994. */
|
|
25
|
|
26 #include <config.h>
|
|
27
|
|
28 #include <X11/StringDefs.h>
|
|
29 #include "EmacsManagerP.h"
|
|
30 #ifdef LWLIB_MENUBARS_MOTIF
|
1315
|
31 #include "xmotif.h"
|
428
|
32 #include <Xm/RowColumn.h>
|
|
33 #endif /* LWLIB_MENUBARS_MOTIF */
|
|
34
|
|
35 /* For I, Emacs, am a kind god. Unlike the goddess Athena and the
|
|
36 Titan Motif, I require no ritual sacrifices to placate the lesser
|
|
37 daemons of geometry management. */
|
|
38
|
|
39 static XtResource resources[] = {
|
|
40 #define offset(field) XtOffset(EmacsManagerWidget, emacs_manager.field)
|
440
|
41 { XtNresizeCallback, XtCCallback,
|
|
42 XtRCallback, sizeof (XtCallbackList),
|
|
43 offset(resize_callback), XtRImmediate, (XtPointer) 0 },
|
|
44 { XtNqueryGeometryCallback, XtCCallback,
|
|
45 XtRCallback, sizeof (XtCallbackList),
|
|
46 offset(query_geometry_callback), XtRImmediate, (XtPointer) 0 },
|
|
47 { XtNuserData, XtCUserData,
|
|
48 XtRPointer, sizeof (XtPointer),
|
|
49 offset(user_data), XtRImmediate, (XtPointer) 0 },
|
428
|
50 };
|
|
51
|
|
52 /****************************************************************
|
|
53 *
|
|
54 * Full class record constant
|
|
55 *
|
|
56 ****************************************************************/
|
|
57
|
|
58 static XtGeometryResult QueryGeometry (Widget wid,
|
|
59 XtWidgetGeometry *request,
|
|
60 XtWidgetGeometry *reply);
|
|
61 static void Resize (Widget w);
|
|
62 static XtGeometryResult GeometryManager (Widget w, XtWidgetGeometry *request,
|
|
63 XtWidgetGeometry *reply);
|
|
64 static void ChangeManaged (Widget w);
|
|
65 static void Realize (Widget w, Mask *valueMask,
|
|
66 XSetWindowAttributes *attributes);
|
|
67 static void ClassInitialize (void);
|
|
68
|
|
69 EmacsManagerClassRec emacsManagerClassRec = {
|
|
70 {
|
|
71 /* core_class fields */
|
|
72 #ifdef LWLIB_USES_MOTIF
|
|
73 /* superclass */ (WidgetClass) &xmManagerClassRec,
|
|
74 #else
|
|
75 /* superclass */ (WidgetClass) &compositeClassRec,
|
|
76 #endif
|
|
77 /* class_name */ "EmacsManager",
|
440
|
78 /* widget_size */ sizeof (EmacsManagerRec),
|
428
|
79 /* class_initialize */ ClassInitialize,
|
|
80 /* class_part_init */ NULL,
|
|
81 /* class_inited */ FALSE,
|
|
82 /* initialize */ NULL,
|
|
83 /* initialize_hook */ NULL,
|
|
84 /* realize */ Realize,
|
|
85 /* actions */ NULL,
|
|
86 /* num_actions */ 0,
|
|
87 /* resources */ resources,
|
|
88 /* num_resources */ XtNumber(resources),
|
|
89 /* xrm_class */ NULLQUARK,
|
|
90 /* compress_motion */ TRUE,
|
1294
|
91 /* compress_exposure */ XtExposeCompressMaximal | XtExposeNoRegion,
|
428
|
92 /* compress_enterleave*/ TRUE,
|
|
93 /* visible_interest */ FALSE,
|
|
94 /* destroy */ NULL,
|
|
95 /* resize */ Resize,
|
|
96 /* expose */ NULL,
|
|
97 /* set_values */ NULL,
|
|
98 /* set_values_hook */ NULL,
|
|
99 /* set_values_almost */ XtInheritSetValuesAlmost,
|
|
100 /* get_values_hook */ NULL,
|
|
101 /* accept_focus */ NULL,
|
|
102 /* version */ XtVersion,
|
|
103 /* callback_private */ NULL,
|
|
104 /* tm_table */ XtInheritTranslations,
|
|
105 /* query_geometry */ QueryGeometry,
|
|
106 /* display_accelerator*/ XtInheritDisplayAccelerator,
|
|
107 /* extension */ NULL
|
|
108 },
|
|
109 {
|
|
110 /* composite_class fields */
|
|
111 /* geometry_manager */ GeometryManager,
|
|
112 /* change_managed */ ChangeManaged,
|
|
113 /* insert_child */ XtInheritInsertChild,
|
|
114 /* delete_child */ XtInheritDeleteChild,
|
|
115 /* extension */ NULL
|
|
116 },
|
|
117 #ifdef LWLIB_USES_MOTIF
|
|
118 {
|
|
119 /* constraint_class fields */
|
|
120 NULL, /* resource list */
|
|
121 0, /* num resources */
|
|
122 0, /* constraint size */
|
|
123 (XtInitProc)NULL, /* init proc */
|
|
124 (XtWidgetProc)NULL, /* destroy proc */
|
|
125 (XtSetValuesFunc)NULL, /* set values proc */
|
|
126 NULL, /* extension */
|
|
127 },
|
|
128 {
|
|
129 /* manager_class fields */
|
|
130 XtInheritTranslations, /* translations */
|
|
131 NULL, /* syn_resources */
|
|
132 0, /* num_syn_resources */
|
|
133 NULL, /* syn_cont_resources */
|
|
134 0, /* num_syn_cont_resources */
|
|
135 XmInheritParentProcess, /* parent_process */
|
|
136 NULL, /* extension */
|
|
137 },
|
|
138 #endif
|
|
139 {
|
|
140 /* emacs_manager_class fields */
|
|
141 /* empty */ 0,
|
|
142 }
|
|
143 };
|
|
144
|
|
145 WidgetClass emacsManagerWidgetClass = (WidgetClass)&emacsManagerClassRec;
|
|
146
|
|
147 /* What is my preferred size? A suggested size may be given. */
|
|
148
|
|
149 static XtGeometryResult
|
|
150 QueryGeometry (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
|
|
151 {
|
|
152 EmacsManagerWidget emw = (EmacsManagerWidget) w;
|
|
153 EmacsManagerQueryGeometryStruct struc;
|
440
|
154 int request_mode = request->request_mode;
|
428
|
155
|
440
|
156 struc.request_mode = request_mode;
|
|
157 struc.proposed_width = (request_mode & CWWidth) ? request->width : 0;
|
|
158 struc.proposed_height = (request_mode & CWHeight) ? request->height : 0;
|
428
|
159 XtCallCallbackList (w, emw->emacs_manager.query_geometry_callback, &struc);
|
|
160 reply->request_mode = CWWidth | CWHeight;
|
|
161 reply->width = struc.proposed_width;
|
|
162 reply->height = struc.proposed_height;
|
440
|
163 if (((request_mode & CWWidth) && (request->width != reply->width)) ||
|
|
164 ((request_mode & CWHeight) && (request->height != reply->height)))
|
428
|
165 return XtGeometryAlmost;
|
|
166 return XtGeometryYes;
|
|
167 }
|
|
168
|
|
169 static void
|
|
170 Resize (Widget w)
|
|
171 {
|
|
172 EmacsManagerWidget emw = (EmacsManagerWidget) w;
|
|
173 EmacsManagerResizeStruct struc;
|
|
174
|
|
175 struc.width = w->core.width;
|
|
176 struc.height = w->core.height;
|
|
177 XtCallCallbackList (w, emw->emacs_manager.resize_callback, &struc);
|
|
178 }
|
|
179
|
|
180 static XtGeometryResult
|
|
181 GeometryManager (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
|
|
182 {
|
|
183 /* Sure, any changes are fine. */
|
|
184
|
440
|
185 #ifdef LWLIB_MENUBARS_MOTIF
|
428
|
186 /* The Motif menubar will merrily request a new size every time a
|
|
187 child is added or deleted. Blow it off because it doesn't know
|
|
188 what it's talking about. */
|
440
|
189 if (XtClass (w) != xmRowColumnWidgetClass)
|
428
|
190 #endif /* LWLIB_MENUBARS_MOTIF */
|
|
191 {
|
440
|
192 if (request->request_mode & CWWidth) w->core.width = request->width;
|
|
193 if (request->request_mode & CWHeight) w->core.height = request->height;
|
428
|
194 }
|
440
|
195 if (request->request_mode & CWBorderWidth)
|
|
196 w->core.border_width = request->border_width;
|
|
197 if (request->request_mode & CWX) w->core.x = request->x;
|
|
198 if (request->request_mode & CWY) w->core.y = request->y;
|
428
|
199
|
|
200 return XtGeometryYes;
|
|
201 }
|
|
202
|
|
203 static void
|
|
204 ChangeManaged (Widget w)
|
|
205 {
|
|
206 if (!XtIsRealized (w))
|
|
207 {
|
440
|
208 XtWidgetGeometry request, reply;
|
428
|
209
|
|
210 /* find out how big we'd like to be ... */
|
|
211
|
440
|
212 request.request_mode = 0;
|
|
213 XtQueryGeometry (w, &request, &reply);
|
|
214 EmacsManagerChangeSize (w, reply.width, reply.height);
|
428
|
215 }
|
|
216 }
|
|
217
|
|
218 static void
|
|
219 Realize (Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
|
|
220 {
|
|
221 attributes->bit_gravity = NorthWestGravity;
|
|
222 *valueMask |= CWBitGravity;
|
|
223
|
|
224 XtCreateWindow (w, (unsigned) InputOutput, (Visual *) CopyFromParent,
|
|
225 *valueMask, attributes);
|
|
226 }
|
|
227
|
|
228 static void
|
|
229 ClassInitialize (void)
|
|
230 {
|
|
231 return;
|
|
232 }
|
|
233
|
|
234 void
|
|
235 EmacsManagerChangeSize (Widget w, Dimension width, Dimension height)
|
|
236 {
|
|
237 if (width == 0)
|
|
238 width = w->core.width;
|
|
239 if (height == 0)
|
|
240 height = w->core.height;
|
|
241
|
|
242 /* do nothing if we're already that size */
|
|
243 if (w->core.width != width || w->core.height != height)
|
|
244 if (XtMakeResizeRequest (w, width, height, &w->core.width, &w->core.height)
|
|
245 == XtGeometryAlmost)
|
|
246 XtMakeResizeRequest (w, w->core.width, w->core.height, NULL, NULL);
|
|
247
|
|
248 Resize (w);
|
|
249 }
|
|
250
|
|
251
|