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
25 * $XConsortium: abobj_align.c /main/3 1995/11/06 17:14:58 rswiston $
27 * @(#)abobj_align.c 1.21 24 May 1994 cde_app_builder/src/libABobj
29 * RESTRICTED CONFIDENTIAL INFORMATION:
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
39 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
45 ***********************************************************************
46 * ab_align.c - User-Interface alignment functions.
49 ***********************************************************************
52 #include <X11/Intrinsic.h>
53 #include <X11/Composite.h>
54 #include <X11/Shell.h>
56 #include <Xm/CascadeB.h>
57 #include <Xm/ScrolledW.h>
58 #include <Xm/RowColumn.h>
61 #include <ab_private/trav.h>
62 #include <ab_private/proj.h>
63 #include <Dt/xpm.h> /* will this be in include/Dt? */
67 static void align_left_edges(ABObj *sel_list, int sel_count);
68 static void align_vcenters(ABObj *sel_list, int sel_count);
69 static void align_right_edges(ABObj *sel_list, int sel_count);
70 static void align_labels(ABObj *sel_list, int sel_count);
73 static void align_top_edges(ABObj *sel_list, int sel_count);
74 static void align_hcenters(ABObj *sel_list, int sel_count);
75 static void align_bottom_edges(ABObj *sel_list, int sel_count);
77 static void distribute_horizontal(ABObj *sel_list, int sel_count, int hspacing);
78 static void distribute_vertical(ABObj *sel_list, int sel_count, int vspacing);
79 static void center_horizontal(ABObj *sel_list, int sel_count);
80 static void center_vertical(ABObj *sel_list, int sel_count);
82 /*************************************************************************
84 ** Function Definitions **
86 **************************************************************************/
89 unsigned long align_mask
93 extern int AB_grid_size;
99 abobj_get_selected(proj_get_project(), FALSE, FALSE, &sel);
103 if (align_mask & LEFT_EDGES)
104 align_left_edges(sel.list, sel.count);
105 if (align_mask & VCENTERS)
106 align_vcenters(sel.list, sel.count);
107 if (align_mask & RIGHT_EDGES)
108 align_right_edges(sel.list, sel.count);
109 if (align_mask & LABELS)
110 align_labels(sel.list, sel.count);
113 * Horizonatal alignment
115 if (align_mask & TOP_EDGES)
116 align_top_edges(sel.list, sel.count);
117 if (align_mask & HCENTERS)
118 align_hcenters(sel.list, sel.count);
119 if (align_mask & BOTTOM_EDGES)
120 align_bottom_edges(sel.list, sel.count);
125 if (align_mask & HSPACING)
126 distribute_horizontal(sel.list, sel.count, AB_grid_size);
127 if (align_mask & VSPACING)
128 distribute_vertical(sel.list, sel.count, AB_grid_size);
131 * Centering within parent
133 if (align_mask & HCENTERED)
134 center_horizontal(sel.list, sel.count);
135 if (align_mask & VCENTERED)
136 center_vertical(sel.list, sel.count);
153 for (i = 0; i < sel_count; i++)
156 if (obj_get_x(obj) < x)
160 for (i = 0; i < sel_count; i++)
164 undo_record_move(obj);
166 abobj_set_xy(obj, x, obj_get_y(obj));
167 abobj_instantiate_changes(obj);
185 for (i = 0; i < sel_count; i++)
188 x += obj_get_x(obj) + abobj_get_actual_width(obj) / 2;
193 for (i = 0; i < sel_count; i++)
197 undo_record_move(obj);
199 abobj_set_xy(obj, x - abobj_get_actual_width(obj)/2, obj_get_y(obj));
200 abobj_instantiate_changes(obj);
218 for (i = 0; i < sel_count; i++)
221 xtmp = obj_get_x(obj) + abobj_get_actual_width(obj);
226 for (i = 0; i < sel_count; i++)
230 undo_record_move(obj);
232 abobj_set_xy(obj, x - abobj_get_actual_width(obj), obj_get_y(obj));
233 abobj_instantiate_changes(obj);
240 * Align all selected items to the topmost object's value x.
253 for (i = 0; i < sel_count; i++)
256 if (obj_get_y(obj) < y)
258 new_label_x = obj_get_x(obj) +
259 abobj_get_label_width(obj);
264 for (i = 0; i < sel_count; i++)
267 abobj_set_xy(obj, new_label_x - abobj_get_label_width(obj),
269 abobj_instantiate_changes(obj);
286 for (i = 0; i < sel_count; i++)
289 if (obj_get_y(obj) < y)
293 for (i = 0; i < sel_count; i++)
297 undo_record_move(obj);
299 abobj_set_xy(obj, obj_get_x(obj), y);
300 abobj_instantiate_changes(obj);
318 for (i = 0; i < sel_count; i++)
321 y += obj_get_y(obj) + abobj_get_actual_height(obj) / 2;
326 for (i = 0; i < sel_count; i++)
330 undo_record_move(obj);
332 abobj_set_xy(obj, obj_get_x(obj), y - abobj_get_actual_height(obj)/2);
333 abobj_instantiate_changes(obj);
351 for (i = 0; i < sel_count; i++)
354 ytmp = obj_get_y(obj) + abobj_get_actual_height(obj);
359 for (i = 0; i < sel_count; i++) {
362 undo_record_move(obj);
364 abobj_set_xy(obj, obj_get_x(obj), y - abobj_get_actual_height(obj));
365 abobj_instantiate_changes(obj);
371 * distribute_horizontal
374 distribute_horizontal(
385 * Sort list of objects based on X values
387 abobj_sort_sel_list(sel_list, sel_count, XSORT);
390 * Walk through the list and distribute the objects.
392 for (i = 1; i < sel_count; i++)
395 prev = sel_list[i-1];
397 undo_record_move(obj);
399 abobj_set_xy(obj, obj_get_x(prev) + abobj_get_actual_width(prev) +
400 hspacing, obj_get_y(obj));
401 abobj_instantiate_changes(obj);
407 * distribute_vertical
421 * Sort list of objects based on Y values
423 abobj_sort_sel_list(sel_list, sel_count, YSORT);
426 * Walk through the list and distribute the objects.
428 for (i = 1; i < sel_count; i++)
431 prev = sel_list[i-1];
433 undo_record_move(obj);
435 abobj_set_xy(obj, obj_get_x(obj), obj_get_y(prev) +
436 abobj_get_actual_height(prev) + vspacing);
437 abobj_instantiate_changes(obj);
444 * Center selected objects horizontally within their parent
452 ABObj owner_obj = obj_get_parent(sel_list[0]);
453 int ownerwidth = abobj_get_actual_width(owner_obj);
454 XRectangle current_rect;
457 abobj_get_rect_for_objects(sel_list, sel_count, ¤t_rect);
459 new_rect.x = ownerwidth / 2 - current_rect.width / 2;
460 new_rect.y = current_rect.y;
462 abobj_move_selected(sel_list, sel_count, ¤t_rect, &new_rect);
468 * Center selected objects vertically within their parent
476 ABObj owner_obj = obj_get_parent(sel_list[0]);
477 int owneheight = abobj_get_actual_height(owner_obj);
478 XRectangle current_rect;
481 abobj_get_rect_for_objects(sel_list, sel_count, ¤t_rect);
483 new_rect.x = current_rect.x;
484 new_rect.y = owneheight / 2 - current_rect.height / 2;
485 abobj_move_selected(sel_list, sel_count, ¤t_rect, &new_rect);