Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrcfg / graphics.cpp
blob5c7fcbd108ebcb0a8e6f78dc5a2af1cb6dea23f4
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
11 * INCLUDES ___________________________________________________________________
14 #include <winsock2.h>
15 #include <ws2tcpip.h>
17 extern "C" {
18 #include <afs/param.h>
19 #include <afs/stds.h>
22 #include "afscfg.h"
23 #include "config.h"
24 #include "graphics.h"
25 #include "resource.h"
29 * DEFINITIONS _________________________________________________________________
32 static const COLORREF STEP_IN_PROGRESS_COLOR = 0x00FF00; // Green
33 static const COLORREF STEP_TO_BE_DONE_COLOR = 0xFF0000; // Blue
37 * STATIC FUNCTIONS _________________________________________________________________
40 static void EraseRect(HDC hdc, RECT rect)
42 HBRUSH hbr = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
43 HGDIOBJ hbrOld = SelectObject(hdc, hbr);
45 HPEN hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNFACE));
46 HGDIOBJ hOldPen = SelectObject(hdc, hPen);
48 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
50 SelectObject(hdc, hOldPen);
51 SelectObject(hdc, hbrOld);
53 DeleteObject(hPen);
54 DeleteObject(hbr);
57 static void DrawCircle(HDC hdc, RECT rect, COLORREF crCircleColor)
59 HBRUSH hBrush = CreateSolidBrush(crCircleColor);
60 HGDIOBJ hOldBrush = SelectObject(hdc, hBrush);
62 HPEN hPen = CreatePen(PS_SOLID, 1, crCircleColor);
63 HGDIOBJ hOldPen = SelectObject(hdc, hPen);
65 OffsetRect(&rect, 1, -1);
67 int midX = rect.left + ((rect.right - rect.left) / 2);
68 int midY = rect.top + ((rect.bottom - rect.top) / 2);
70 MoveToEx(hdc, midX - 1, midY - 2, 0);
71 LineTo(hdc, midX + 2, midY - 2);
73 MoveToEx(hdc, midX - 2, midY - 1, 0);
74 LineTo(hdc, midX + 3, midY - 1);
76 MoveToEx(hdc, midX - 2, midY, 0);
77 LineTo(hdc, midX + 3, midY);
79 MoveToEx(hdc, midX - 2, midY + 1, 0);
80 LineTo(hdc, midX + 3, midY + 1);
82 MoveToEx(hdc, midX - 1, midY + 2, 0);
83 LineTo(hdc, midX + 2, midY + 2);
85 SelectObject(hdc, hOldPen);
86 SelectObject(hdc, hOldBrush);
88 DeleteObject(hPen);
89 DeleteObject(hBrush);
92 static void DrawCheckmark(HDC hdc, RECT rect)
94 #define cxCHECKBOX (2+9+2)
95 #define cyCHECKBOX (2+9+2)
97 // Checkmark
98 HPEN hpNew = CreatePen(PS_SOLID, 1, RGB(0,0,0));
99 HGDIOBJ hpOld = (HPEN)SelectObject(hdc, hpNew);
101 POINT ptCheckbox;
102 ptCheckbox.x = rect.left;
103 ptCheckbox.y = rect.top + ((rect.bottom - rect.top) - cyCHECKBOX) / 2;
105 MoveToEx(hdc, ptCheckbox.x +3, ptCheckbox.y+5, NULL);
106 LineTo(hdc, ptCheckbox.x +5, ptCheckbox.y+7);
107 LineTo(hdc, ptCheckbox.x+10, ptCheckbox.y+2);
109 MoveToEx(hdc, ptCheckbox.x +3, ptCheckbox.y+6, NULL);
110 LineTo(hdc, ptCheckbox.x +5, ptCheckbox.y+8);
111 LineTo(hdc, ptCheckbox.x+10, ptCheckbox.y+3);
113 MoveToEx(hdc, ptCheckbox.x +3, ptCheckbox.y+7, NULL);
114 LineTo(hdc, ptCheckbox.x +5, ptCheckbox.y+9);
115 LineTo(hdc, ptCheckbox.x+10, ptCheckbox.y+4);
117 SelectObject(hdc, hpOld);
118 DeleteObject(hpNew);
121 static void DrawX(HDC hdc, RECT rect)
123 // Red X
124 static COLORREF crXColor = 0X0000FF;
126 HBRUSH hbrRed = CreateSolidBrush(crXColor);
127 HGDIOBJ hbrOld = SelectObject(hdc, hbrRed);
129 HPEN hPen = CreatePen(PS_SOLID, 1, crXColor);
130 HGDIOBJ hOldPen = SelectObject(hdc, hPen);
132 OffsetRect(&rect, 3, 0);
134 rect.top++;
135 rect.bottom++;
137 int nLen = 7;
139 MoveToEx(hdc, rect.left, rect.top, 0);
140 LineTo(hdc, rect.left + nLen, rect.top + nLen);
142 MoveToEx(hdc, rect.left, rect.top + 1, 0);
143 LineTo(hdc, rect.left + nLen, rect.top + nLen + 1);
145 MoveToEx(hdc, rect.left, rect.top - 1, 0);
146 LineTo(hdc, rect.left + nLen, rect.top + nLen - 1);
148 MoveToEx(hdc, rect.left + nLen - 1, rect.top, 0);
149 LineTo(hdc, rect.left - 1, rect.top + nLen);
151 MoveToEx(hdc, rect.left + nLen - 1, rect.top + 1, 0);
152 LineTo(hdc, rect.left - 1, rect.top + nLen + 1);
154 MoveToEx(hdc, rect.left + nLen - 1, rect.top - 1, 0);
155 LineTo(hdc, rect.left - 1, rect.top + nLen - 1);
157 SelectObject(hdc, hOldPen);
158 SelectObject(hdc, hbrOld);
160 DeleteObject(hPen);
161 DeleteObject(hbrRed);
166 * EXPORTED FUNCTIONS _________________________________________________________
169 void PaintStepGraphic(HWND hwnd, STEP_STATE state)
171 PAINTSTRUCT ps;
173 HDC hdc = BeginPaint(hwnd, &ps);
174 _ASSERTE(hdc);
176 RECT rect;
177 GetClientRect(hwnd, &rect);
179 InflateRect(&rect, -2, -2);
181 // First erase the background
182 EraseRect(hdc, rect);
184 // Draw an image that corresponds to the state
185 switch (state) {
186 case SS_STEP_IN_PROGRESS:
187 DrawCircle(hdc, rect, STEP_IN_PROGRESS_COLOR);
188 break;
190 case SS_STEP_TO_BE_DONE:
191 DrawCircle(hdc, rect, STEP_TO_BE_DONE_COLOR);
192 break;
194 case SS_STEP_FINISHED:
195 DrawCheckmark(hdc, rect);
196 break;
199 case SS_STEP_FAILED:
200 DrawX(hdc, rect);
201 break;
204 EndPaint(hwnd, &ps);
208 #define clrWHITE RGB(255,255,255)
209 #define clrHIGHLIGHT RGB(192,192,192)
210 #define clrSHADOW RGB(128,128,128)
211 #define clrBLACK RGB(100,100,100)
212 #define clrBAR_INT_LEFT RGB(0,255,0)
213 #define clrBAR_INT_RIGHT RGB(128,0,0)
214 #define clrARROW_INTERIOR RGB(128,128,0)
215 #define clrTEXT_CURRENT RGB(255,255,255)
216 #define clrTEXT_STEP RGB(0,255,0)
218 #define cxLEFT_MARGIN 10
219 #define cxRIGHT_MARGIN 10
220 #define cyBOTTOM_MARGIN 5
221 #define cyAREA 100
222 #define cyBELOW_CURRENT 15
223 #define cyBELOW_ARROW 10
225 void CALLBACK PaintPageGraphic(LPWIZARD pWiz, HDC hdc, LPRECT prTarget, HPALETTE hpal)
227 static HFONT hFont = AfsAppLib_CreateFont(IDS_GRAPHIC_FONT);
228 static HPEN hPenWhite = CreatePen(PS_SOLID, 1, clrWHITE);
229 static HPEN hPenHighlight = CreatePen(PS_SOLID, 1, clrHIGHLIGHT);
230 static HPEN hPenShadow = CreatePen(PS_SOLID, 1, clrSHADOW);
231 static HPEN hPenBlack = CreatePen(PS_SOLID, 1, clrBLACK);
232 static HPEN hPenBarIntLeft = CreatePen(PS_SOLID, 1, clrBAR_INT_LEFT);
233 static HPEN hPenBarIntRight = CreatePen(PS_SOLID, 1, clrBAR_INT_RIGHT);
234 static HPEN hPenArrowInterior = CreatePen(PS_SOLID, 1, clrARROW_INTERIOR);
236 // First find out where we'll be drawing things.
237 RECT rArea;
238 rArea.top = prTarget->bottom - cyAREA - cyBOTTOM_MARGIN;
239 rArea.bottom = prTarget->bottom - cyBOTTOM_MARGIN;
240 rArea.left = prTarget->left + cxLEFT_MARGIN;
241 rArea.right = prTarget->right - cxRIGHT_MARGIN;
243 // Draw the "Current Step:" text
244 HGDIOBJ hFontOld = SelectObject(hdc, hFont);
245 COLORREF clrTextOld = SetTextColor (hdc, clrTEXT_CURRENT);
246 SetBkMode (hdc, TRANSPARENT);
248 TCHAR szText[cchRESOURCE];
249 GetResString(IDS_CURRENT_STEP, szText);
251 RECT rText = rArea;
252 DWORD dwFlags = DT_CENTER | DT_TOP | DT_SINGLELINE;
253 DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags | DT_CALCRECT, NULL);
255 rText.right = rArea.right;
256 DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags, NULL);
258 // Draw the progress bar; it should look like this:
259 // wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww // (w=white, b=black...
260 // whhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhb // h=highlight, s=shadow...
261 // whllllllllllllllllrrrrrrrrrrrrrrrsb // l=left/int, r=right/int)
262 // whllllllllllllllllrrrrrrrrrrrrrrrsb // l=left/int, r=right/int)
263 // whssssssssssssssssssssssssssssssssb // h=highlight, s=shadow...
264 // wbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb // h=highlight, s=shadow...
266 // Oh--we'll need to know where the pointer's point should go. We'll
267 // make that be where the leftmost dot of the pointer's tip, and the
268 // rightmost dot that's colored "l". One state 0, we want the pointer
269 // to be all the way to the left--and on state {g_nNumStates-1}, we want
270 // it all the way to the right
272 RECT rBar = rArea;
273 rBar.top = rText.bottom + cyBELOW_CURRENT;
274 rBar.bottom = rBar.top + 6;
276 RECT rBarInterior = rBar;
277 InflateRect (&rBarInterior, -2, -2);
279 int nStepSize = (rBarInterior.right - rBarInterior.left) / (g_nNumStates-1);
280 int xCurPos = rBarInterior.left + (g_pWiz->GetState() * nStepSize);
281 if (!g_pWiz->GetState())
282 xCurPos = rBarInterior.left-1; // don't draw *any* green
283 else if (g_pWiz->GetState() == (int)(g_nNumStates-1))
284 xCurPos = rBarInterior.right-1; // don't draw *any* red
286 // Draw that bar!
287 HGDIOBJ hPenOld = SelectObject (hdc, hPenWhite);
288 MoveToEx (hdc, rBar.left, rBar.bottom-1, 0);
289 LineTo (hdc, rBar.left, rBar.top);
290 LineTo (hdc, rBar.right, rBar.top);
291 MoveToEx (hdc, rBar.left, rBar.bottom, 0);
293 SelectObject (hdc, hPenHighlight);
294 MoveToEx (hdc, rBar.left+1, rBar.bottom-2, 0);
295 LineTo (hdc, rBar.left+1, rBar.top+1);
296 LineTo (hdc, rBar.right-1, rBar.top+1);
298 SelectObject (hdc, hPenShadow);
299 MoveToEx (hdc, rBar.left+2, rBar.bottom-2, 0);
300 LineTo (hdc, rBar.right-2, rBar.bottom-2);
301 LineTo (hdc, rBar.right-2, rBar.top+1);
303 SelectObject (hdc, hPenBlack);
304 MoveToEx (hdc, rBar.left+1, rBar.bottom-1, 0);
305 LineTo (hdc, rBar.right-1, rBar.bottom-1);
306 LineTo (hdc, rBar.right-1, rBar.top);
308 if (xCurPos >= rBarInterior.left) {
309 SelectObject (hdc, hPenBarIntLeft);
310 MoveToEx (hdc, rBarInterior.left, rBarInterior.top, 0);
311 LineTo (hdc, xCurPos+1, rBarInterior.top);
312 MoveToEx (hdc, rBarInterior.left, rBarInterior.top+1, 0);
313 LineTo (hdc, xCurPos+1, rBarInterior.top+1);
316 if (xCurPos < rBarInterior.right-1) {
317 SelectObject (hdc, hPenBarIntRight);
318 MoveToEx (hdc, xCurPos+1, rBarInterior.top, 0);
319 LineTo (hdc, rBarInterior.right, rBarInterior.top);
320 MoveToEx (hdc, xCurPos+1, rBarInterior.top+1, 0);
321 LineTo (hdc, rBarInterior.right, rBarInterior.top+1);
323 SelectObject (hdc, hPenOld);
325 // Draw the arrow underneath it; it should look like this:
326 // wb
327 // whsb
328 // whassb
329 // whaaassb
330 // whaaaaassb
331 // wssssssssssb
332 // Remember that the topmost "w" is where xCurPos is.
334 RECT rArrow;
335 rArrow.top = rBar.bottom +1;
336 rArrow.bottom = rArrow.top +6;
337 rArrow.left = xCurPos -5;
338 rArrow.right = xCurPos +7;
340 hPenOld = SelectObject (hdc, hPenWhite);
341 MoveToEx (hdc, rArrow.left, rArrow.bottom-1, 0);
342 LineTo (hdc, xCurPos+1, rArrow.top-1);
344 SelectObject (hdc, hPenHighlight);
345 MoveToEx (hdc, rArrow.left+2, rArrow.bottom-2, 0);
346 LineTo (hdc, xCurPos+1, rArrow.top);
348 SelectObject (hdc, hPenShadow);
349 MoveToEx (hdc, rArrow.left+1, rArrow.bottom-1, 0);
350 LineTo (hdc, rArrow.right-1, rArrow.bottom-1);
351 MoveToEx (hdc, xCurPos+1, rArrow.top+1, 0);
352 LineTo (hdc, rArrow.right, rArrow.bottom);
353 MoveToEx (hdc, xCurPos+1, rArrow.top+2, 0);
354 LineTo (hdc, rArrow.right-1, rArrow.bottom);
356 SelectObject (hdc, hPenBlack);
357 MoveToEx (hdc, xCurPos+1, rArrow.top, 0);
358 LineTo (hdc, rArrow.right, rArrow.bottom);
360 // wb
361 // whsb
362 // whassb
363 // whaaassb
364 // whaaaaassb
365 // wssssssssssb
367 SelectObject (hdc, hPenArrowInterior);
368 MoveToEx (hdc, xCurPos, rArrow.top+2, 0);
369 LineTo (hdc, xCurPos+1, rArrow.top+2);
370 MoveToEx (hdc, xCurPos-1, rArrow.top+3, 0);
371 LineTo (hdc, xCurPos+2, rArrow.top+3);
372 MoveToEx (hdc, xCurPos-2, rArrow.top+4, 0);
373 LineTo (hdc, xCurPos+3, rArrow.top+4);
375 SelectObject (hdc, hPenOld);
377 // Draw the description text
378 SetTextColor (hdc, clrTEXT_STEP);
379 GetResString(g_StateDesc[g_pWiz->GetState()], szText);
381 rText = rArea;
382 rText.top = rArrow.bottom + cyBELOW_ARROW;
383 dwFlags = DT_CENTER | DT_TOP | DT_WORDBREAK;
384 DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags, NULL);
386 SetTextColor (hdc, clrTextOld);
387 SelectObject (hdc, hFontOld);