VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxTray/helpers.cpp@ 27164

最後變更 在這個檔案從27164是 27164,由 vboxsync 提交於 15 年 前

Windows guest additions multimonitor fixes (xTracker 4655).

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 8.2 KB
 
1/** @file
2 * helpers - Guest Additions Service helper functions
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
17 * Clara, CA 95054 USA or visit http://www.sun.com if you need
18 * additional information or have any questions.
19 */
20
21#include <malloc.h>
22#include <windows.h>
23
24#include <iprt/string.h>
25#include <VBox/VBoxGuestLib.h>
26
27#include <VBoxGuestInternal.h>
28
29#include "helpers.h"
30#include "resource.h"
31
32static unsigned nextAdjacentRectXP (RECTL *paRects, unsigned nRects, unsigned iRect)
33{
34 unsigned i;
35 for (i = 0; i < nRects; i++)
36 {
37 if (paRects[iRect].right == paRects[i].left)
38 {
39 return i;
40 }
41 }
42 return ~0;
43}
44
45static unsigned nextAdjacentRectXN (RECTL *paRects, unsigned nRects, unsigned iRect)
46{
47 unsigned i;
48 for (i = 0; i < nRects; i++)
49 {
50 if (paRects[iRect].left == paRects[i].right)
51 {
52 return i;
53 }
54 }
55 return ~0;
56}
57
58static unsigned nextAdjacentRectYP (RECTL *paRects, unsigned nRects, unsigned iRect)
59{
60 unsigned i;
61 for (i = 0; i < nRects; i++)
62 {
63 if (paRects[iRect].bottom == paRects[i].top)
64 {
65 return i;
66 }
67 }
68 return ~0;
69}
70
71unsigned nextAdjacentRectYN (RECTL *paRects, unsigned nRects, unsigned iRect)
72{
73 unsigned i;
74 for (i = 0; i < nRects; i++)
75 {
76 if (paRects[iRect].top == paRects[i].bottom)
77 {
78 return i;
79 }
80 }
81 return ~0;
82}
83
84void resizeRect(RECTL *paRects, unsigned nRects, unsigned iPrimary, unsigned iResized, int NewWidth, int NewHeight)
85{
86 DDCLOG(("nRects %d, iPrimary %d, iResized %d, NewWidth %d, NewHeight %d\n", nRects, iPrimary, iResized, NewWidth, NewHeight));
87
88 RECTL *paNewRects = (RECTL *)alloca (sizeof (RECTL) * nRects);
89 memcpy (paNewRects, paRects, sizeof (RECTL) * nRects);
90 paNewRects[iResized].right += NewWidth - (paNewRects[iResized].right - paNewRects[iResized].left);
91 paNewRects[iResized].bottom += NewHeight - (paNewRects[iResized].bottom - paNewRects[iResized].top);
92
93 /* Verify all pairs of originally adjacent rectangles for all 4 directions.
94 * If the pair has a "good" delta (that is the first rectangle intersects the second)
95 * at a direction and the second rectangle is not primary one (which can not be moved),
96 * move the second rectangle to make it adjacent to the first one.
97 */
98
99 /* X positive. */
100 unsigned iRect;
101 for (iRect = 0; iRect < nRects; iRect++)
102 {
103 /* Find the next adjacent original rect in x positive direction. */
104 unsigned iNextRect = nextAdjacentRectXP (paRects, nRects, iRect);
105 DDCLOG(("next %d -> %d\n", iRect, iNextRect));
106
107 if (iNextRect == ~0 || iNextRect == iPrimary)
108 {
109 continue;
110 }
111
112 /* Check whether there is an X intesection between these adjacent rects in the new rectangles
113 * and fix the intersection if delta is "good".
114 */
115 int delta = paNewRects[iRect].right - paNewRects[iNextRect].left;
116
117 if (delta != 0)
118 {
119 DDCLOG(("XP intersection right %d left %d, diff %d\n",
120 paNewRects[iRect].right, paNewRects[iNextRect].left,
121 delta));
122
123 paNewRects[iNextRect].left += delta;
124 paNewRects[iNextRect].right += delta;
125 }
126 }
127
128 /* X negative. */
129 for (iRect = 0; iRect < nRects; iRect++)
130 {
131 /* Find the next adjacent original rect in x negative direction. */
132 unsigned iNextRect = nextAdjacentRectXN (paRects, nRects, iRect);
133 DDCLOG(("next %d -> %d\n", iRect, iNextRect));
134
135 if (iNextRect == ~0 || iNextRect == iPrimary)
136 {
137 continue;
138 }
139
140 /* Check whether there is an X intesection between these adjacent rects in the new rectangles
141 * and fix the intersection if delta is "good".
142 */
143 int delta = paNewRects[iRect].left - paNewRects[iNextRect].right;
144
145 if (delta != 0)
146 {
147 DDCLOG(("XN intersection left %d right %d, diff %d\n",
148 paNewRects[iRect].left, paNewRects[iNextRect].right,
149 delta));
150
151 paNewRects[iNextRect].left += delta;
152 paNewRects[iNextRect].right += delta;
153 }
154 }
155
156 /* Y positive (in the computer sence, top->down). */
157 for (iRect = 0; iRect < nRects; iRect++)
158 {
159 /* Find the next adjacent original rect in y positive direction. */
160 unsigned iNextRect = nextAdjacentRectYP (paRects, nRects, iRect);
161 DDCLOG(("next %d -> %d\n", iRect, iNextRect));
162
163 if (iNextRect == ~0 || iNextRect == iPrimary)
164 {
165 continue;
166 }
167
168 /* Check whether there is an Y intesection between these adjacent rects in the new rectangles
169 * and fix the intersection if delta is "good".
170 */
171 int delta = paNewRects[iRect].bottom - paNewRects[iNextRect].top;
172
173 if (delta != 0)
174 {
175 DDCLOG(("YP intersection bottom %d top %d, diff %d\n",
176 paNewRects[iRect].bottom, paNewRects[iNextRect].top,
177 delta));
178
179 paNewRects[iNextRect].top += delta;
180 paNewRects[iNextRect].bottom += delta;
181 }
182 }
183
184 /* Y negative (in the computer sence, down->top). */
185 for (iRect = 0; iRect < nRects; iRect++)
186 {
187 /* Find the next adjacent original rect in x negative direction. */
188 unsigned iNextRect = nextAdjacentRectYN (paRects, nRects, iRect);
189 DDCLOG(("next %d -> %d\n", iRect, iNextRect));
190
191 if (iNextRect == ~0 || iNextRect == iPrimary)
192 {
193 continue;
194 }
195
196 /* Check whether there is an Y intesection between these adjacent rects in the new rectangles
197 * and fix the intersection if delta is "good".
198 */
199 int delta = paNewRects[iRect].top - paNewRects[iNextRect].bottom;
200
201 if (delta != 0)
202 {
203 DDCLOG(("YN intersection top %d bottom %d, diff %d\n",
204 paNewRects[iRect].top, paNewRects[iNextRect].bottom,
205 delta));
206
207 paNewRects[iNextRect].top += delta;
208 paNewRects[iNextRect].bottom += delta;
209 }
210 }
211
212 memcpy (paRects, paNewRects, sizeof (RECTL) * nRects);
213 return;
214}
215
216int showBalloonTip (HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags)
217{
218 NOTIFYICONDATA niData;
219 niData.cbSize = sizeof(NOTIFYICONDATA);
220 niData.uFlags = NIF_INFO;
221 niData.hWnd = hWnd;
222 niData.uID = uID;
223 niData.uTimeout = uTimeout;
224 if (dwInfoFlags == 0)
225 dwInfoFlags = NIIF_INFO;
226 niData.dwInfoFlags = dwInfoFlags;
227
228 OSVERSIONINFO info;
229 DWORD dwMajorVersion = 5; /* default XP */
230
231 info.dwOSVersionInfoSize = sizeof(info);
232 if (FALSE == GetVersionEx(&info))
233 return FALSE;
234
235 if (info.dwMajorVersion >= 5)
236 {
237 niData.uFlags |= NIF_ICON;
238 if ( info.dwMajorVersion == 5
239 && info.dwMinorVersion == 1) /* WinXP */
240 {
241 //niData.dwInfoFlags = NIIF_USER; /* Use an own icon instead of the default one */
242 niData.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_VIRTUALBOX));
243 }
244#ifdef BALLOON_WITH_VISTA_TOOLTIP_ICON
245 else if (info.dwMajorVersion == 6) /* Vista and up */
246 {
247 niData.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON; /* Use an own icon instead of the default one */
248 niData.hBalloonIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_VIRTUALBOX));
249 }
250#endif
251 }
252
253 strcpy(niData.szInfo, pszMsg ? pszMsg : "");
254 strcpy(niData.szInfoTitle, pszTitle ? pszTitle : "");
255
256 if (!Shell_NotifyIcon(NIM_MODIFY, &niData))
257 return GetLastError();
258 return 0;
259}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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