Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtappbuilder / src / libABobj / obj_geometry.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23
24 /*
25  *      $XConsortium: obj_geometry.c /main/3 1995/11/06 18:34:59 rswiston $
26  *
27  *      @(#)obj_geometry.c      1.10 08 Mar 1994        cde_app_builder/src/libABobj
28  *
29  *      RESTRICTED CONFIDENTIAL INFORMATION:
30  *      
31  *      The information in this document is subject to special
32  *      restrictions in a confidential disclosure agreement between
33  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
34  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
35  *      Sun's specific written approval.  This document and all copies
36  *      and derivative works thereof must be returned or destroyed at
37  *      Sun's request.
38  *
39  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40  *
41  */
42
43
44 /*
45  *  obj_geometry.c - geometry management
46  */
47
48 #include "objP.h"
49 #include "obj_notifyP.h"
50
51 /*************************************************************************
52 **                                                                      **
53 **       Constants (#define and const)                                  **
54 **                                                                      **
55 **************************************************************************/
56
57 /*************************************************************************
58 **                                                                      **
59 **       Private Functions (C declarations and macros)                  **
60 **                                                                      **
61 **************************************************************************/
62
63 /*************************************************************************
64 **                                                                      **
65 **       Data                                                           **
66 **                                                                      **
67 **************************************************************************/
68
69 /*************************************************************************
70 **                                                                      **
71 **       Function Definitions                                           **
72 **                                                                      **
73 **************************************************************************/
74
75 /*************************************************************************
76 **                                                                      **
77 **       Get values                                                     **
78 **                                                                      **
79 **************************************************************************/
80
81 int
82 obj_get_geometry(ABObj obj, int *x, int *y, int *width, int *height)
83 {
84     *x= obj->x;
85     *y= obj->y;
86     *width= obj->width;
87     *height= obj->height;
88
89     return OK;
90 }
91
92
93 int
94 obj_get_position(ABObj obj, int *x, int *y)
95 {
96     *x= obj->x;
97     *y= obj->y;
98     return OK;
99 }
100
101
102 int
103 obj_get_size(ABObj obj, int *width, int *height)
104 {
105     *width= obj->width;
106     *height= obj->height;
107     return OK;
108 }
109
110
111 /*************************************************************************
112 **                                                                      **
113 **       Set values                                                     **
114 **                                                                      **
115 **************************************************************************/
116
117
118 int
119 obj_set_geometry(ABObj obj, int newX, int newY, int newWidth, int newHeight)
120 {
121     int         iReturn= 0;
122     int         iRC= 0;         /* return code */
123     int         oldX= obj->x;
124     int         oldY= obj->y;
125     int         oldWidth= obj->width;
126     int         oldHeight= obj->height;
127     BOOL        changed= (   (oldX != newX) 
128                           || (oldY != newY) 
129                           || (oldWidth != newWidth) 
130                           || (oldHeight != newHeight) );
131
132     if (!changed)
133     {
134         goto epilogue;
135     }
136
137     iRC= objP_notify_send_allow_geometry_change(obj, 
138                 newX, newY, newWidth, newHeight);
139     if (iRC < 0)
140     {
141         iReturn= iRC;
142         goto epilogue;
143     }
144     oldX = obj->x;
145     oldY = obj->y;
146     oldWidth = obj->width;
147     oldHeight = obj->height;
148     obj->x= newX;
149     obj->y= newY;
150     obj->width= newWidth;
151     obj->height= newHeight;
152
153     iReturn= objP_notify_send_geometry_change(
154                 obj, oldX, oldY, oldWidth, oldHeight);
155
156 epilogue:
157     return iReturn;
158 }
159
160
161 int
162 obj_move(ABObj obj, int newX, int newY)
163 {
164     return obj_set_geometry(obj, newX, newY, obj->width, obj->height);
165 }
166
167
168 int
169 obj_resize(ABObj obj, int newWidth, int newHeight)
170 {
171     return obj_set_geometry(obj, obj->x, obj->y, newWidth, newHeight);
172 }
173
174
175 /*************************************************************************
176 **                                                                      **
177 **       Tests                                                          **
178 **                                                                      **
179 **************************************************************************/
180
181 int
182 obj_test_set_geometry(ABObj obj, 
183         int newX, int newY, int newHeight, int newWidth)
184 {
185     int         iReturn= 0;
186     objP_notify_push_mode();
187         objP_notify_clear_mode(OBJEV_MODE_DISALLOW_ALL_EVS);
188
189         iReturn= objP_notify_send_allow_geometry_change(obj,
190                         newX, newY, newHeight, newWidth);
191
192     objP_notify_pop_mode();
193
194     return iReturn;
195 }
196
197
198 int
199 obj_test_move(ABObj obj, int newX, int newY)
200 {
201     return obj_test_set_geometry(obj, newX, newY, obj->width, obj->height);
202 }
203
204
205 int
206 obj_test_resize(ABObj obj, int newWidth, int newHeight)
207 {
208     return obj_test_set_geometry(obj, obj->x, obj->y, newWidth, newHeight);
209 }
210