2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * (c) Copyright 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC.
32 static char rcsid[] = "$XConsortium: Square.c /main/3 1995/10/27 10:42:28 rswiston $"
36 /*****************************************************************************
38 * Square.c - widget source file
40 ******************************************************************************/
44 #include <Mrm/MrmPublic.h>
45 #include <Xm/BulletinBP.h>
48 #define Width(w) XmField((w),square_offsets,Core,width,Dimension)
49 #define Height(w) XmField((w),square_offsets,Core,height,Dimension)
50 #define BorderWidth(w) XmField((w),square_offsets,Core,border_width,Dimension)
51 #define MajorDimension(w) XmField((w),square_offsets,Square,major_dimension,int)
53 #define MakeSquare(w) XmConstraintField((w),square_constraint_offsets, \
54 Square,make_square, Boolean)
56 static void ClassInitialize();
57 static void Initialize();
58 static Boolean SetValues();
59 static void ConstraintInitialize();
60 static Boolean ConstraintSetValues();
62 static XmPartResource resources[] = {
64 SquareNmajorDimension, SquareCMajorDimension, XmRInt, sizeof(int),
65 XmPartOffset(Square,major_dimension), XmRImmediate, (XtPointer)SquareWIDTH
69 static XmPartResource constraints[] = {
71 SquareNmakeSquare, SquareCMakeSquare, XmRBoolean, sizeof(Boolean),
72 XmConstraintPartOffset(Square,make_square),
73 XmRImmediate, (XtPointer)False
78 externaldef(squareclassrec) SquareClassRec squareClassRec =
80 { /* core_class fields */
81 (WidgetClass) &xmBulletinBoardClassRec, /* superclass */
82 "Square", /* class_name */
83 sizeof(SquarePart), /* widget_size */
84 ClassInitialize, /* class_initialize */
85 NULL, /* class init part proc */
86 False, /* class_inited */
87 Initialize, /* initialize */
88 NULL, /* initialize_notify */
89 XtInheritRealize, /* realize */
92 (XtResourceList)resources,/* resources */
93 XtNumber(resources), /* num_resources */
94 NULLQUARK, /* xrm_class */
95 False, /* compress_motion */
96 XtExposeCompressMaximal, /* compress_exposure */
97 False, /* compress_enterleave */
98 False, /* visible_interest */
100 XtInheritResize, /* resize */
101 XtInheritExpose, /* expose */
102 SetValues, /* set_values */
103 NULL, /* set_values_hook */
104 XtInheritSetValuesAlmost, /* set_values_almost */
105 NULL, /* get_values_hook */
106 NULL, /* accept_focus */
107 XtVersionDontCheck, /* version */
108 NULL, /* callback_private */
109 XtInheritTranslations, /* tm_table */
110 XtInheritQueryGeometry, /* Query Geometry proc */
111 NULL, /* disp accelerator */
112 NULL, /* extension */
115 { /* composite_class fields */
116 XtInheritGeometryManager, /* geometry_manager */
117 XtInheritChangeManaged, /* change_managed */
118 XtInheritInsertChild, /* insert_child */
119 XtInheritDeleteChild, /* delete_child */
120 NULL, /* extension */
123 { /* constraint_class fields */
124 (XtResourceList)constraints, /* constraint resource */
125 XtNumber(constraints), /* number of constraints */
126 sizeof(SquareConstraintPart), /* size of constraint */
127 ConstraintInitialize, /* initialization */
128 NULL, /* destroy proc */
129 ConstraintSetValues, /* set_values proc */
130 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 */
143 { /* bulletin_board_class fields */
144 FALSE, /* always_install_accelerators */
145 NULL, /* geo_matrix_create */
146 XtInheritFocusMovedProc, /* focus_moved_proc */
147 NULL, /* extension */
150 { /* square_class fields */
151 NULL, /* extension */
155 externaldef(squarewidgetclass) WidgetClass
156 squareWidgetClass = (WidgetClass) &squareClassRec;
158 static XmOffsetPtr square_offsets; /* Part offsets table */
159 static XmOffsetPtr square_constraint_offsets; /* Constraint offsets table */
161 /**********************************************************************
163 * SquareCreate - Convenience routine, used by Uil/Mrm.
165 *********************************************************************/
167 Widget SquareCreate(parent, name, arglist, nargs)
173 return(XtCreateWidget (name, squareWidgetClass, parent, arglist, nargs));
176 /**********************************************************************
178 * SquareMrmInitialize - register Square widget class with Mrm
180 *********************************************************************/
182 int SquareMrmInitialize()
184 return(MrmRegisterClass (MrmwcUnknown, "Square", "SquareCreate",
185 SquareCreate, (WidgetClass)&squareClassRec));
188 /**********************************************************************
192 *********************************************************************/
194 static void ClassInitialize()
196 XmResolveAllPartOffsets(squareWidgetClass, &square_offsets,
197 &square_constraint_offsets);
200 static void Initialize(req, new)
204 if (MajorDimension(new) != SquareWIDTH &&
205 MajorDimension(new) != SquareHEIGHT) {
206 XtWarning("Square: invalid majorDimension");
207 MajorDimension(new) = SquareWIDTH;
211 static Boolean SetValues(curr, req, new)
216 if (MajorDimension(new) != SquareWIDTH &&
217 MajorDimension(new) != SquareHEIGHT) {
218 XtWarning("Square: invalid majorDimension");
219 MajorDimension(new) = MajorDimension(curr);
224 static void ConstraintInitialize (req, new)
230 if(MakeSquare(new) == True) {
231 if (MajorDimension(XtParent(new))==SquareWIDTH)
236 XtResizeWidget(new, m, m, BorderWidth(new));
240 static Boolean ConstraintSetValues (old, ref, new)
245 Boolean redraw = False;
247 if (MakeSquare(new) != MakeSquare(old)) {
248 if(MakeSquare(new)==True) {
249 if (MajorDimension(XtParent(new))==SquareWIDTH)
250 Height(new) = Width(new);
252 Width(new) = Height(new);
258 if (MajorDimension(XtParent(new))==SquareWIDTH)
259 Height(new) = Height(new)/2;
261 Width(new) = Width(new)/2;
263 gi.request_mode = CWWidth | CWHeight;
264 gi.width = Width(new);
265 gi.height = Height(new);
266 if (XtQueryGeometry(new, &gi, &gp) == XtGeometryAlmost) {
267 if (gp.request_mode && CWWidth != 0) Width(new) = gp.width;
268 if (gp.request_mode && CWHeight != 0) Height(new) = gp.height;