VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxService/helpers.cpp@ 7104

Last change on this file since 7104 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/** @file
2 * helpers - Guest Additions Service helper functions
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#include <malloc.h>
18#include <windows.h>
19
20#include "helpers.h"
21
22static unsigned nextAdjacentRectXP (RECTL *paRects, unsigned nRects, unsigned iRect)
23{
24 unsigned i;
25 for (i = 0; i < nRects; i++)
26 {
27 if (paRects[iRect].right == paRects[i].left)
28 {
29 return i;
30 }
31 }
32 return ~0;
33}
34
35static unsigned nextAdjacentRectXN (RECTL *paRects, unsigned nRects, unsigned iRect)
36{
37 unsigned i;
38 for (i = 0; i < nRects; i++)
39 {
40 if (paRects[iRect].left == paRects[i].right)
41 {
42 return i;
43 }
44 }
45 return ~0;
46}
47
48static unsigned nextAdjacentRectYP (RECTL *paRects, unsigned nRects, unsigned iRect)
49{
50 unsigned i;
51 for (i = 0; i < nRects; i++)
52 {
53 if (paRects[iRect].bottom == paRects[i].top)
54 {
55 return i;
56 }
57 }
58 return ~0;
59}
60
61unsigned nextAdjacentRectYN (RECTL *paRects, unsigned nRects, unsigned iRect)
62{
63 unsigned i;
64 for (i = 0; i < nRects; i++)
65 {
66 if (paRects[iRect].top == paRects[i].bottom)
67 {
68 return i;
69 }
70 }
71 return ~0;
72}
73
74void resizeRect(RECTL *paRects, unsigned nRects, unsigned iPrimary, unsigned iResized, int NewWidth, int NewHeight)
75{
76 RECTL *paNewRects = (RECTL *)alloca (sizeof (RECTL) * nRects);
77 memcpy (paNewRects, paRects, sizeof (RECTL) * nRects);
78 paNewRects[iResized].right += NewWidth - (paNewRects[iResized].right - paNewRects[iResized].left);
79 paNewRects[iResized].bottom += NewHeight - (paNewRects[iResized].bottom - paNewRects[iResized].top);
80
81 /* Verify all pairs of originally adjacent rectangles for all 4 directions.
82 * If the pair has a "good" delta (that is the first rectangle intersects the second)
83 * at a direction and the second rectangle is not primary one (which can not be moved),
84 * move the second rectangle to make it adjacent to the first one.
85 */
86
87 /* X positive. */
88 unsigned iRect;
89 for (iRect = 0; iRect < nRects; iRect++)
90 {
91 /* Find the next adjacent original rect in x positive direction. */
92 unsigned iNextRect = nextAdjacentRectXP (paRects, nRects, iRect);
93 DDCLOG(("next %d -> %d\n", iRect, iNextRect));
94
95 if (iNextRect == ~0 || iNextRect == iPrimary)
96 {
97 continue;
98 }
99
100 /* Check whether there is an X intesection between these adjacent rects in the new rectangles
101 * and fix the intersection if delta is "good".
102 */
103 int delta = paNewRects[iRect].right - paNewRects[iNextRect].left;
104
105 if (delta > 0)
106 {
107 DDCLOG(("XP intersection right %d left %d, diff %d\n",
108 paNewRects[iRect].right, paNewRects[iNextRect].left,
109 delta));
110
111 paNewRects[iNextRect].left += delta;
112 paNewRects[iNextRect].right += delta;
113 }
114 }
115
116 /* X negative. */
117 for (iRect = 0; iRect < nRects; iRect++)
118 {
119 /* Find the next adjacent original rect in x negative direction. */
120 unsigned iNextRect = nextAdjacentRectXN (paRects, nRects, iRect);
121 DDCLOG(("next %d -> %d\n", iRect, iNextRect));
122
123 if (iNextRect == ~0 || iNextRect == iPrimary)
124 {
125 continue;
126 }
127
128 /* Check whether there is an X intesection between these adjacent rects in the new rectangles
129 * and fix the intersection if delta is "good".
130 */
131 int delta = paNewRects[iRect].left - paNewRects[iNextRect].right;
132
133 if (delta < 0)
134 {
135 DDCLOG(("XN intersection left %d right %d, diff %d\n",
136 paNewRects[iRect].left, paNewRects[iNextRect].right,
137 delta));
138
139 paNewRects[iNextRect].left += delta;
140 paNewRects[iNextRect].right += delta;
141 }
142 }
143
144 /* Y positive (in the computer sence, top->down). */
145 for (iRect = 0; iRect < nRects; iRect++)
146 {
147 /* Find the next adjacent original rect in y positive direction. */
148 unsigned iNextRect = nextAdjacentRectYP (paRects, nRects, iRect);
149 DDCLOG(("next %d -> %d\n", iRect, iNextRect));
150
151 if (iNextRect == ~0 || iNextRect == iPrimary)
152 {
153 continue;
154 }
155
156 /* Check whether there is an Y intesection between these adjacent rects in the new rectangles
157 * and fix the intersection if delta is "good".
158 */
159 int delta = paNewRects[iRect].bottom - paNewRects[iNextRect].top;
160
161 if (delta > 0)
162 {
163 DDCLOG(("YP intersection bottom %d top %d, diff %d\n",
164 paNewRects[iRect].bottom, paNewRects[iNextRect].top,
165 delta));
166
167 paNewRects[iNextRect].top += delta;
168 paNewRects[iNextRect].bottom += delta;
169 }
170 }
171
172 /* Y negative (in the computer sence, down->top). */
173 for (iRect = 0; iRect < nRects; iRect++)
174 {
175 /* Find the next adjacent original rect in x negative direction. */
176 unsigned iNextRect = nextAdjacentRectYN (paRects, nRects, iRect);
177 DDCLOG(("next %d -> %d\n", iRect, iNextRect));
178
179 if (iNextRect == ~0 || iNextRect == iPrimary)
180 {
181 continue;
182 }
183
184 /* Check whether there is an Y intesection between these adjacent rects in the new rectangles
185 * and fix the intersection if delta is "good".
186 */
187 int delta = paNewRects[iRect].top - paNewRects[iNextRect].bottom;
188
189 if (delta < 0)
190 {
191 DDCLOG(("YN intersection top %d bottom %d, diff %d\n",
192 paNewRects[iRect].top, paNewRects[iNextRect].bottom,
193 delta));
194
195 paNewRects[iNextRect].top += delta;
196 paNewRects[iNextRect].bottom += delta;
197 }
198 }
199
200 memcpy (paRects, paNewRects, sizeof (RECTL) * nRects);
201 return;
202}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette