winnt-dont-display-ibm-legal-message-20040326
[openafs.git] / src / WINNT / afssvrcfg / graphics.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 /*
11  * INCLUDES ___________________________________________________________________
12  *
13  */
14 extern "C" {
15 #include <afs/param.h>
16 #include <afs/stds.h>
17 }
18
19 #include "afscfg.h"
20 #include "config.h"
21 #include "graphics.h"
22 #include "resource.h"
23
24
25 /*
26  * DEFINITIONS _________________________________________________________________
27  *
28  */
29 static const COLORREF STEP_IN_PROGRESS_COLOR = 0x00FF00;                // Green
30 static const COLORREF STEP_TO_BE_DONE_COLOR = 0xFF0000;                 // Blue
31
32
33 /*
34  * STATIC FUNCTIONS _________________________________________________________________
35  *
36  */
37 static void EraseRect(HDC hdc, RECT rect)
38 {
39         HBRUSH hbr = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
40         HGDIOBJ hbrOld = SelectObject(hdc, hbr);
41
42         HPEN hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNFACE));
43         HGDIOBJ hOldPen = SelectObject(hdc, hPen);
44
45         Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
46         
47         SelectObject(hdc, hOldPen);
48         SelectObject(hdc, hbrOld);
49
50         DeleteObject(hPen);
51         DeleteObject(hbr);
52 }
53
54 static void DrawCircle(HDC hdc, RECT rect, COLORREF crCircleColor)
55 {
56         HBRUSH hBrush = CreateSolidBrush(crCircleColor);
57         HGDIOBJ hOldBrush = SelectObject(hdc, hBrush);
58
59         HPEN hPen = CreatePen(PS_SOLID, 1, crCircleColor);
60         HGDIOBJ hOldPen = SelectObject(hdc, hPen);
61
62         OffsetRect(&rect, 1, -1);
63
64         int midX = rect.left + ((rect.right - rect.left) / 2);
65         int midY = rect.top + ((rect.bottom - rect.top) / 2);
66         
67         MoveToEx(hdc, midX - 1, midY - 2, 0);
68         LineTo(hdc, midX + 2, midY - 2);
69
70         MoveToEx(hdc, midX - 2, midY - 1, 0);
71         LineTo(hdc, midX + 3, midY - 1);
72
73         MoveToEx(hdc, midX - 2, midY, 0);
74         LineTo(hdc, midX + 3, midY);
75
76         MoveToEx(hdc, midX - 2, midY + 1, 0);
77         LineTo(hdc, midX + 3, midY + 1);
78
79         MoveToEx(hdc, midX - 1, midY + 2, 0);
80         LineTo(hdc, midX + 2, midY + 2);
81         
82         SelectObject(hdc, hOldPen);
83         SelectObject(hdc, hOldBrush);
84
85         DeleteObject(hPen);
86         DeleteObject(hBrush);
87 }
88
89 static void DrawCheckmark(HDC hdc, RECT rect)
90 {
91 #define cxCHECKBOX        (2+9+2)
92 #define cyCHECKBOX        (2+9+2)
93         
94         // Checkmark
95         HPEN hpNew = CreatePen(PS_SOLID, 1, RGB(0,0,0));
96         HGDIOBJ hpOld = (HPEN)SelectObject(hdc, hpNew);
97
98         POINT ptCheckbox;
99         ptCheckbox.x = rect.left;
100         ptCheckbox.y = rect.top + ((rect.bottom - rect.top) - cyCHECKBOX) / 2;
101         
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);
105
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);
109
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);
113
114         SelectObject(hdc, hpOld);
115         DeleteObject(hpNew);
116 }
117
118 static void DrawX(HDC hdc, RECT rect)
119 {
120         // Red X
121         static COLORREF crXColor = 0X0000FF;
122
123         HBRUSH hbrRed = CreateSolidBrush(crXColor);
124         HGDIOBJ hbrOld = SelectObject(hdc, hbrRed);
125
126         HPEN hPen = CreatePen(PS_SOLID, 1, crXColor);
127         HGDIOBJ hOldPen = SelectObject(hdc, hPen);
128
129         OffsetRect(&rect, 3, 0);
130
131         rect.top++;
132         rect.bottom++;
133
134         int nLen = 7;
135
136         MoveToEx(hdc, rect.left, rect.top, 0);
137         LineTo(hdc, rect.left + nLen, rect.top + nLen);
138
139         MoveToEx(hdc, rect.left, rect.top + 1, 0);
140         LineTo(hdc, rect.left + nLen, rect.top + nLen + 1);
141
142         MoveToEx(hdc, rect.left, rect.top - 1, 0);
143         LineTo(hdc, rect.left + nLen, rect.top + nLen - 1);
144
145
146         MoveToEx(hdc, rect.left + nLen - 1, rect.top, 0);
147         LineTo(hdc, rect.left - 1, rect.top + nLen);
148
149         MoveToEx(hdc, rect.left + nLen - 1, rect.top + 1, 0);
150         LineTo(hdc, rect.left - 1, rect.top + nLen + 1);
151
152         MoveToEx(hdc, rect.left + nLen - 1, rect.top - 1, 0);
153         LineTo(hdc, rect.left - 1, rect.top + nLen - 1);
154
155         SelectObject(hdc, hOldPen);
156         SelectObject(hdc, hbrOld);
157
158         DeleteObject(hPen);
159         DeleteObject(hbrRed);
160 }
161
162
163 /*
164  * EXPORTED FUNCTIONS _________________________________________________________
165  *
166  */
167 void PaintStepGraphic(HWND hwnd, STEP_STATE state)
168 {
169         PAINTSTRUCT ps;
170
171         HDC hdc = BeginPaint(hwnd, &ps);
172         _ASSERTE(hdc);
173
174         RECT rect;
175         GetClientRect(hwnd, &rect);
176
177         InflateRect(&rect, -2, -2);
178
179         // First erase the background
180         EraseRect(hdc, rect);
181
182         // Draw an image that corresponds to the state
183         switch (state) {
184                 case SS_STEP_IN_PROGRESS:       DrawCircle(hdc, rect, STEP_IN_PROGRESS_COLOR);
185                                                                         break;
186
187                 case SS_STEP_TO_BE_DONE:        DrawCircle(hdc, rect, STEP_TO_BE_DONE_COLOR);
188                                                                         break;
189                 
190                 case SS_STEP_FINISHED:          DrawCheckmark(hdc, rect);
191                                                                         break;
192
193                 case SS_STEP_FAILED:            DrawX(hdc, rect);
194                                                                         break;
195         }
196         
197         EndPaint(hwnd, &ps);
198 }
199
200
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)
210
211 #define cxLEFT_MARGIN      10
212 #define cxRIGHT_MARGIN     10
213 #define cyBOTTOM_MARGIN     5
214 #define cyAREA             100
215 #define cyBELOW_CURRENT    15
216 #define cyBELOW_ARROW      10
217
218 void CALLBACK PaintPageGraphic(LPWIZARD pWiz, HDC hdc, LPRECT prTarget, HPALETTE hpal)
219 {
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);
228
229         // First find out where we'll be drawing things.
230         RECT rArea;
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;
235
236         // Draw the "Current Step:" text
237         HGDIOBJ hFontOld = SelectObject(hdc, hFont);
238         COLORREF clrTextOld = SetTextColor (hdc, clrTEXT_CURRENT);
239         SetBkMode (hdc, TRANSPARENT);
240
241         TCHAR szText[cchRESOURCE];
242         GetResString(IDS_CURRENT_STEP, szText);
243
244         RECT rText = rArea;
245         DWORD dwFlags = DT_CENTER | DT_TOP | DT_SINGLELINE;
246         DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags | DT_CALCRECT, NULL);
247
248         rText.right = rArea.right;
249         DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags, NULL);
250
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...
258
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
264
265         RECT rBar = rArea;
266         rBar.top = rText.bottom + cyBELOW_CURRENT;
267         rBar.bottom = rBar.top + 6;
268
269         RECT rBarInterior = rBar;
270         InflateRect (&rBarInterior, -2, -2);
271
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
278
279         // Draw that bar!
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);
285
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);
290
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);
295
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);
300
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);
307         }
308
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);
315         }
316         SelectObject (hdc, hPenOld);
317
318         // Draw the arrow underneath it; it should look like this:
319         //             wb
320         //            whsb
321         //           whassb
322         //          whaaassb
323         //         whaaaaassb
324         //        wssssssssssb
325         // Remember that the topmost "w" is where xCurPos is.
326
327         RECT rArrow;
328         rArrow.top = rBar.bottom +1;
329         rArrow.bottom = rArrow.top +6;
330         rArrow.left = xCurPos -5;
331         rArrow.right = xCurPos +7;
332
333         hPenOld = SelectObject (hdc, hPenWhite);
334         MoveToEx (hdc, rArrow.left, rArrow.bottom-1, 0);
335         LineTo (hdc, xCurPos+1, rArrow.top-1);
336
337         SelectObject (hdc, hPenHighlight);
338         MoveToEx (hdc, rArrow.left+2, rArrow.bottom-2, 0);
339         LineTo (hdc, xCurPos+1, rArrow.top);
340
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);
348
349         SelectObject (hdc, hPenBlack);
350         MoveToEx (hdc, xCurPos+1, rArrow.top, 0);
351         LineTo (hdc, rArrow.right, rArrow.bottom);
352
353         //             wb
354         //            whsb
355         //           whassb
356         //          whaaassb
357         //         whaaaaassb
358         //        wssssssssssb
359
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);
367
368         SelectObject (hdc, hPenOld);
369
370         // Draw the description text
371         SetTextColor (hdc, clrTEXT_STEP);
372         GetResString(g_StateDesc[g_pWiz->GetState()], szText);
373
374         rText = rArea;
375         rText.top = rArrow.bottom + cyBELOW_ARROW;
376         dwFlags = DT_CENTER | DT_TOP | DT_WORDBREAK;
377         DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags, NULL);
378
379         SetTextColor (hdc, clrTextOld);
380         SelectObject (hdc, hFontOld);
381 }
382