VirtualBox

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

Last change on this file since 3804 was 3260, checked in by vboxsync, 17 years ago

export files

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