1 /************************************************************
2 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
32 #include "xkbcommon/xkbcommon.h"
33 #include "XKBcommonint.h"
36 #define MINSHORT -32768
39 #define MAXSHORT 32767
43 _XkbCheckBounds(struct xkb_bounds * bounds, int x, int y)
56 XkbcComputeShapeBounds(struct xkb_shape * shape)
59 struct xkb_outline * outline;
60 struct xkb_point * pt;
62 if ((!shape) || (shape->num_outlines < 1))
65 shape->bounds.x1 = shape->bounds.y1 = MAXSHORT;
66 shape->bounds.x2 = shape->bounds.y2 = MINSHORT;
68 for (outline = shape->outlines, o = 0; o < shape->num_outlines;
71 for (pt = outline->points, p = 0; p < outline->num_points; p++, pt++)
72 _XkbCheckBounds(&shape->bounds, pt->x, pt->y);
73 if (outline->num_points < 2)
74 _XkbCheckBounds(&shape->bounds, 0, 0);
80 XkbcComputeRowBounds(struct xkb_geometry * geom, struct xkb_section * section, struct xkb_row * row)
84 struct xkb_bounds *bounds, *sbounds;
86 if (!geom || !section || !row)
90 bounds = &row->bounds;
91 bzero(bounds, sizeof(struct xkb_bounds));
93 for (key = row->keys, pos = k = 0; k < row->num_keys; k++, key++) {
94 sbounds = &XkbKeyShape(geom, key)->bounds;
95 _XkbCheckBounds(bounds, pos, 0);
100 _XkbCheckBounds(bounds, pos, 0);
102 _XkbCheckBounds(bounds, pos + sbounds->x1, sbounds->y1);
103 _XkbCheckBounds(bounds, pos + sbounds->x2, sbounds->y2);
109 _XkbCheckBounds(bounds, 0, pos);
111 _XkbCheckBounds(bounds,pos + sbounds->x1, sbounds->y1);
112 _XkbCheckBounds(bounds,pos + sbounds->x2, sbounds->y2);
121 XkbcComputeSectionBounds(struct xkb_geometry * geom, struct xkb_section * section)
124 struct xkb_shape * shape;
125 struct xkb_row * row;
126 union xkb_doodad * doodad;
127 struct xkb_bounds * bounds, *rbounds = NULL;
129 if (!geom || !section)
132 bounds = §ion->bounds;
133 bzero(bounds, sizeof(struct xkb_bounds));
135 for (i = 0, row = section->rows; i < section->num_rows; i++, row++) {
136 if (!XkbcComputeRowBounds(geom, section, row))
138 rbounds = &row->bounds;
139 _XkbCheckBounds(bounds, row->left + rbounds->x1,
140 row->top + rbounds->y1);
141 _XkbCheckBounds(bounds, row->left + rbounds->x2,
142 row->top + rbounds->y2);
145 for (i = 0, doodad = section->doodads; i < section->num_doodads;
148 static struct xkb_bounds tbounds;
150 switch (doodad->any.type) {
151 case XkbOutlineDoodad:
153 shape = XkbShapeDoodadShape(geom, &doodad->shape);
154 rbounds = &shape->bounds;
157 tbounds.x1 = doodad->text.left;
158 tbounds.y1 = doodad->text.top;
159 tbounds.x2 = tbounds.x1 + doodad->text.width;
160 tbounds.y2 = tbounds.y1 + doodad->text.height;
163 case XkbIndicatorDoodad:
164 shape = XkbIndicatorDoodadShape(geom, &doodad->indicator);
165 rbounds = &shape->bounds;
168 shape = XkbLogoDoodadShape(geom, &doodad->logo);
169 rbounds = &shape->bounds;
172 tbounds.x1 = tbounds.x2 = doodad->any.left;
173 tbounds.y1 = tbounds.y2 = doodad->any.top;
177 _XkbCheckBounds(bounds, rbounds->x1, rbounds->y1);
178 _XkbCheckBounds(bounds, rbounds->x2, rbounds->y2);