2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * INCLUDES ___________________________________________________________________
15 #include <afs/param.h>
26 * DEFINITIONS _________________________________________________________________
29 static const COLORREF STEP_IN_PROGRESS_COLOR = 0x00FF00; // Green
30 static const COLORREF STEP_TO_BE_DONE_COLOR = 0xFF0000; // Blue
34 * STATIC FUNCTIONS _________________________________________________________________
37 static void EraseRect(HDC hdc, RECT rect)
39 HBRUSH hbr = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
40 HGDIOBJ hbrOld = SelectObject(hdc, hbr);
42 HPEN hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNFACE));
43 HGDIOBJ hOldPen = SelectObject(hdc, hPen);
45 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
47 SelectObject(hdc, hOldPen);
48 SelectObject(hdc, hbrOld);
54 static void DrawCircle(HDC hdc, RECT rect, COLORREF crCircleColor)
56 HBRUSH hBrush = CreateSolidBrush(crCircleColor);
57 HGDIOBJ hOldBrush = SelectObject(hdc, hBrush);
59 HPEN hPen = CreatePen(PS_SOLID, 1, crCircleColor);
60 HGDIOBJ hOldPen = SelectObject(hdc, hPen);
62 OffsetRect(&rect, 1, -1);
64 int midX = rect.left + ((rect.right - rect.left) / 2);
65 int midY = rect.top + ((rect.bottom - rect.top) / 2);
67 MoveToEx(hdc, midX - 1, midY - 2, 0);
68 LineTo(hdc, midX + 2, midY - 2);
70 MoveToEx(hdc, midX - 2, midY - 1, 0);
71 LineTo(hdc, midX + 3, midY - 1);
73 MoveToEx(hdc, midX - 2, midY, 0);
74 LineTo(hdc, midX + 3, midY);
76 MoveToEx(hdc, midX - 2, midY + 1, 0);
77 LineTo(hdc, midX + 3, midY + 1);
79 MoveToEx(hdc, midX - 1, midY + 2, 0);
80 LineTo(hdc, midX + 2, midY + 2);
82 SelectObject(hdc, hOldPen);
83 SelectObject(hdc, hOldBrush);
89 static void DrawCheckmark(HDC hdc, RECT rect)
91 #define cxCHECKBOX (2+9+2)
92 #define cyCHECKBOX (2+9+2)
95 HPEN hpNew = CreatePen(PS_SOLID, 1, RGB(0,0,0));
96 HGDIOBJ hpOld = (HPEN)SelectObject(hdc, hpNew);
99 ptCheckbox.x = rect.left;
100 ptCheckbox.y = rect.top + ((rect.bottom - rect.top) - cyCHECKBOX) / 2;
102 MoveToEx(hdc, ptCheckbox.x +3, ptCheckbox.y+5, NULL);
103 LineTo(hdc, ptCheckbox.x +5, ptCheckbox.y+7);
104 LineTo(hdc, ptCheckbox.x+10, ptCheckbox.y+2);
106 MoveToEx(hdc, ptCheckbox.x +3, ptCheckbox.y+6, NULL);
107 LineTo(hdc, ptCheckbox.x +5, ptCheckbox.y+8);
108 LineTo(hdc, ptCheckbox.x+10, ptCheckbox.y+3);
110 MoveToEx(hdc, ptCheckbox.x +3, ptCheckbox.y+7, NULL);
111 LineTo(hdc, ptCheckbox.x +5, ptCheckbox.y+9);
112 LineTo(hdc, ptCheckbox.x+10, ptCheckbox.y+4);
114 SelectObject(hdc, hpOld);
118 static void DrawX(HDC hdc, RECT rect)
121 static COLORREF crXColor = 0X0000FF;
123 HBRUSH hbrRed = CreateSolidBrush(crXColor);
124 HGDIOBJ hbrOld = SelectObject(hdc, hbrRed);
126 HPEN hPen = CreatePen(PS_SOLID, 1, crXColor);
127 HGDIOBJ hOldPen = SelectObject(hdc, hPen);
129 OffsetRect(&rect, 3, 0);
136 MoveToEx(hdc, rect.left, rect.top, 0);
137 LineTo(hdc, rect.left + nLen, rect.top + nLen);
139 MoveToEx(hdc, rect.left, rect.top + 1, 0);
140 LineTo(hdc, rect.left + nLen, rect.top + nLen + 1);
142 MoveToEx(hdc, rect.left, rect.top - 1, 0);
143 LineTo(hdc, rect.left + nLen, rect.top + nLen - 1);
146 MoveToEx(hdc, rect.left + nLen - 1, rect.top, 0);
147 LineTo(hdc, rect.left - 1, rect.top + nLen);
149 MoveToEx(hdc, rect.left + nLen - 1, rect.top + 1, 0);
150 LineTo(hdc, rect.left - 1, rect.top + nLen + 1);
152 MoveToEx(hdc, rect.left + nLen - 1, rect.top - 1, 0);
153 LineTo(hdc, rect.left - 1, rect.top + nLen - 1);
155 SelectObject(hdc, hOldPen);
156 SelectObject(hdc, hbrOld);
159 DeleteObject(hbrRed);
164 * EXPORTED FUNCTIONS _________________________________________________________
167 void PaintStepGraphic(HWND hwnd, STEP_STATE state)
171 HDC hdc = BeginPaint(hwnd, &ps);
175 GetClientRect(hwnd, &rect);
177 InflateRect(&rect, -2, -2);
179 // First erase the background
180 EraseRect(hdc, rect);
182 // Draw an image that corresponds to the state
184 case SS_STEP_IN_PROGRESS: DrawCircle(hdc, rect, STEP_IN_PROGRESS_COLOR);
187 case SS_STEP_TO_BE_DONE: DrawCircle(hdc, rect, STEP_TO_BE_DONE_COLOR);
190 case SS_STEP_FINISHED: DrawCheckmark(hdc, rect);
193 case SS_STEP_FAILED: DrawX(hdc, rect);
201 #define clrWHITE RGB(255,255,255)
202 #define clrHIGHLIGHT RGB(192,192,192)
203 #define clrSHADOW RGB(128,128,128)
204 #define clrBLACK RGB(100,100,100)
205 #define clrBAR_INT_LEFT RGB(0,255,0)
206 #define clrBAR_INT_RIGHT RGB(128,0,0)
207 #define clrARROW_INTERIOR RGB(128,128,0)
208 #define clrTEXT_CURRENT RGB(255,255,255)
209 #define clrTEXT_STEP RGB(0,255,0)
211 #define cxLEFT_MARGIN 10
212 #define cxRIGHT_MARGIN 10
213 #define cyBOTTOM_MARGIN 5
215 #define cyBELOW_CURRENT 15
216 #define cyBELOW_ARROW 10
218 void CALLBACK PaintPageGraphic(LPWIZARD pWiz, HDC hdc, LPRECT prTarget, HPALETTE hpal)
220 static HFONT hFont = AfsAppLib_CreateFont(IDS_GRAPHIC_FONT);
221 static HPEN hPenWhite = CreatePen(PS_SOLID, 1, clrWHITE);
222 static HPEN hPenHighlight = CreatePen(PS_SOLID, 1, clrHIGHLIGHT);
223 static HPEN hPenShadow = CreatePen(PS_SOLID, 1, clrSHADOW);
224 static HPEN hPenBlack = CreatePen(PS_SOLID, 1, clrBLACK);
225 static HPEN hPenBarIntLeft = CreatePen(PS_SOLID, 1, clrBAR_INT_LEFT);
226 static HPEN hPenBarIntRight = CreatePen(PS_SOLID, 1, clrBAR_INT_RIGHT);
227 static HPEN hPenArrowInterior = CreatePen(PS_SOLID, 1, clrARROW_INTERIOR);
229 // First find out where we'll be drawing things.
231 rArea.top = prTarget->bottom - cyAREA - cyBOTTOM_MARGIN;
232 rArea.bottom = prTarget->bottom - cyBOTTOM_MARGIN;
233 rArea.left = prTarget->left + cxLEFT_MARGIN;
234 rArea.right = prTarget->right - cxRIGHT_MARGIN;
236 // Draw the "Current Step:" text
237 HGDIOBJ hFontOld = SelectObject(hdc, hFont);
238 COLORREF clrTextOld = SetTextColor (hdc, clrTEXT_CURRENT);
239 SetBkMode (hdc, TRANSPARENT);
241 TCHAR szText[cchRESOURCE];
242 GetResString(IDS_CURRENT_STEP, szText);
245 DWORD dwFlags = DT_CENTER | DT_TOP | DT_SINGLELINE;
246 DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags | DT_CALCRECT, NULL);
248 rText.right = rArea.right;
249 DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags, NULL);
251 // Draw the progress bar; it should look like this:
252 // wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww // (w=white, b=black...
253 // whhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhb // h=highlight, s=shadow...
254 // whllllllllllllllllrrrrrrrrrrrrrrrsb // l=left/int, r=right/int)
255 // whllllllllllllllllrrrrrrrrrrrrrrrsb // l=left/int, r=right/int)
256 // whssssssssssssssssssssssssssssssssb // h=highlight, s=shadow...
257 // wbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb // h=highlight, s=shadow...
259 // Oh--we'll need to know where the pointer's point should go. We'll
260 // make that be where the leftmost dot of the pointer's tip, and the
261 // rightmost dot that's colored "l". One state 0, we want the pointer
262 // to be all the way to the left--and on state {g_nNumStates-1}, we want
263 // it all the way to the right
266 rBar.top = rText.bottom + cyBELOW_CURRENT;
267 rBar.bottom = rBar.top + 6;
269 RECT rBarInterior = rBar;
270 InflateRect (&rBarInterior, -2, -2);
272 int nStepSize = (rBarInterior.right - rBarInterior.left) / (g_nNumStates-1);
273 int xCurPos = rBarInterior.left + (g_pWiz->GetState() * nStepSize);
274 if (!g_pWiz->GetState())
275 xCurPos = rBarInterior.left-1; // don't draw *any* green
276 else if (g_pWiz->GetState() == (int)(g_nNumStates-1))
277 xCurPos = rBarInterior.right-1; // don't draw *any* red
280 HGDIOBJ hPenOld = SelectObject (hdc, hPenWhite);
281 MoveToEx (hdc, rBar.left, rBar.bottom-1, 0);
282 LineTo (hdc, rBar.left, rBar.top);
283 LineTo (hdc, rBar.right, rBar.top);
284 MoveToEx (hdc, rBar.left, rBar.bottom, 0);
286 SelectObject (hdc, hPenHighlight);
287 MoveToEx (hdc, rBar.left+1, rBar.bottom-2, 0);
288 LineTo (hdc, rBar.left+1, rBar.top+1);
289 LineTo (hdc, rBar.right-1, rBar.top+1);
291 SelectObject (hdc, hPenShadow);
292 MoveToEx (hdc, rBar.left+2, rBar.bottom-2, 0);
293 LineTo (hdc, rBar.right-2, rBar.bottom-2);
294 LineTo (hdc, rBar.right-2, rBar.top+1);
296 SelectObject (hdc, hPenBlack);
297 MoveToEx (hdc, rBar.left+1, rBar.bottom-1, 0);
298 LineTo (hdc, rBar.right-1, rBar.bottom-1);
299 LineTo (hdc, rBar.right-1, rBar.top);
301 if (xCurPos >= rBarInterior.left) {
302 SelectObject (hdc, hPenBarIntLeft);
303 MoveToEx (hdc, rBarInterior.left, rBarInterior.top, 0);
304 LineTo (hdc, xCurPos+1, rBarInterior.top);
305 MoveToEx (hdc, rBarInterior.left, rBarInterior.top+1, 0);
306 LineTo (hdc, xCurPos+1, rBarInterior.top+1);
309 if (xCurPos < rBarInterior.right-1) {
310 SelectObject (hdc, hPenBarIntRight);
311 MoveToEx (hdc, xCurPos+1, rBarInterior.top, 0);
312 LineTo (hdc, rBarInterior.right, rBarInterior.top);
313 MoveToEx (hdc, xCurPos+1, rBarInterior.top+1, 0);
314 LineTo (hdc, rBarInterior.right, rBarInterior.top+1);
316 SelectObject (hdc, hPenOld);
318 // Draw the arrow underneath it; it should look like this:
325 // Remember that the topmost "w" is where xCurPos is.
328 rArrow.top = rBar.bottom +1;
329 rArrow.bottom = rArrow.top +6;
330 rArrow.left = xCurPos -5;
331 rArrow.right = xCurPos +7;
333 hPenOld = SelectObject (hdc, hPenWhite);
334 MoveToEx (hdc, rArrow.left, rArrow.bottom-1, 0);
335 LineTo (hdc, xCurPos+1, rArrow.top-1);
337 SelectObject (hdc, hPenHighlight);
338 MoveToEx (hdc, rArrow.left+2, rArrow.bottom-2, 0);
339 LineTo (hdc, xCurPos+1, rArrow.top);
341 SelectObject (hdc, hPenShadow);
342 MoveToEx (hdc, rArrow.left+1, rArrow.bottom-1, 0);
343 LineTo (hdc, rArrow.right-1, rArrow.bottom-1);
344 MoveToEx (hdc, xCurPos+1, rArrow.top+1, 0);
345 LineTo (hdc, rArrow.right, rArrow.bottom);
346 MoveToEx (hdc, xCurPos+1, rArrow.top+2, 0);
347 LineTo (hdc, rArrow.right-1, rArrow.bottom);
349 SelectObject (hdc, hPenBlack);
350 MoveToEx (hdc, xCurPos+1, rArrow.top, 0);
351 LineTo (hdc, rArrow.right, rArrow.bottom);
360 SelectObject (hdc, hPenArrowInterior);
361 MoveToEx (hdc, xCurPos, rArrow.top+2, 0);
362 LineTo (hdc, xCurPos+1, rArrow.top+2);
363 MoveToEx (hdc, xCurPos-1, rArrow.top+3, 0);
364 LineTo (hdc, xCurPos+2, rArrow.top+3);
365 MoveToEx (hdc, xCurPos-2, rArrow.top+4, 0);
366 LineTo (hdc, xCurPos+3, rArrow.top+4);
368 SelectObject (hdc, hPenOld);
370 // Draw the description text
371 SetTextColor (hdc, clrTEXT_STEP);
372 GetResString(g_StateDesc[g_pWiz->GetState()], szText);
375 rText.top = rArrow.bottom + cyBELOW_ARROW;
376 dwFlags = DT_CENTER | DT_TOP | DT_WORDBREAK;
377 DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags, NULL);
379 SetTextColor (hdc, clrTextOld);
380 SelectObject (hdc, hFontOld);