- Revert 47615. Please fix actual sysreg instead of adding inconsistency between...
[reactos.git] / rosapps / templates / imagesoft / floatwindow.c
1 #include "precomp.h"
2
3 static const TCHAR szFloatWndClass[] = TEXT("ImageSoftFloatWndClass");
4
5 #define ID_TIMER1 1
6 #define ID_TIMER2 2
7 #define ID_TIMER3 3
8
9 TBBUTTON ToolsButtons[] = {
10 /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
11 {TBICON_RECTSEL, ID_RECTSEL, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* rectangle select */
12 {TBICON_MOVESEL, ID_MOVESEL, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* move selected pixels */
13 {TBICON_LASOO, ID_LASOO, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* lasso select */
14 {TBICON_MOVE, ID_MOVE, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* move selection */
15 {TBICON_ECLIPSESEL, ID_ECLIPSESEL, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* elipse select */
16 {TBICON_ZOOM, ID_ZOOM, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* zoom */
17 {TBICON_MAGICWAND, ID_MAGICWAND, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* magic wand */
18 {TBICON_TEXT, ID_TEXT, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* text */
19 {TBICON_PAINTBRUSH, ID_PAINTBRUSH, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* paintbrush */
20 {TBICON_ERASER, ID_ERASER, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* eraser */
21 {TBICON_PENCIL, ID_PENCIL, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* pencil */
22 {TBICON_COLORPICKER, ID_COLORPICKER, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* color picker */
23 {TBICON_CLONESTAMP, ID_CLONESTAMP, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* clone stamp */
24 {TBICON_RECOLORING, ID_RECOLORING, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* recolor */
25 {TBICON_PAINTBUCKET, ID_PAINTBUCKET, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* paint bucket */
26 {TBICON_LINE, ID_LINE, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* line */
27 {TBICON_RECTANGLE, ID_RECTANGLE, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* rectangle */
28 {TBICON_ROUNDRECT, ID_ROUNDRECT, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* round rectangle */
29 {TBICON_ECLIPSE, ID_ECLIPSE, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* elipse */
30 {TBICON_FREEFORM, ID_FREEFORM, TBSTATE_ENABLED, BTNS_BUTTON | TBSTYLE_GROUP | TBSTYLE_CHECK, {0}, 0, 0}, /* free form */
31
32 {10, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},
33 };
34
35 TBBUTTON HistoryButtons[] = {
36 {TBICON_BACKSM, ID_BACK, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* back */
37 {TBICON_UNDOSM, ID_UNDO, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* undo */
38 {TBICON_REDOSM, ID_REDO, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* redo */
39 {TBICON_FORWARDSM, ID_FORWARD, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* forward */
40 {TBICON_DELETESM, ID_DELETE, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* delete */
41 };
42
43
44 BOOL
45 ShowHideWindow(HWND hwnd)
46 {
47 if (IsWindowVisible(hwnd))
48 return ShowWindow(hwnd, SW_HIDE);
49 else
50 return ShowWindow(hwnd, SW_SHOW);
51 }
52
53
54 BOOL
55 FloatToolbarCreateToolsGui(PMAIN_WND_INFO Info)
56 {
57 HWND hTb;
58 HIMAGELIST hImageList;
59 INT NumButtons;
60
61 NumButtons = sizeof(ToolsButtons) / sizeof(ToolsButtons[0]);
62
63 hTb = CreateWindowEx(0,
64 TOOLBARCLASSNAME,
65 NULL,
66 WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_WRAPABLE | CCS_NODIVIDER,
67 0, 0, 32, 200,
68 Info->fltTools->hSelf,
69 NULL,
70 hInstance,
71 NULL);
72 if (hTb != NULL)
73 {
74 SendMessage(hTb,
75 TB_SETEXTENDEDSTYLE,
76 0,
77 TBSTYLE_EX_HIDECLIPPEDBUTTONS);
78
79 SendMessage(hTb,
80 TB_BUTTONSTRUCTSIZE,
81 sizeof(ToolsButtons[0]),
82 0);
83
84 SendMessage(hTb,
85 TB_SETBITMAPSIZE,
86 0,
87 (LPARAM)MAKELONG(16, 16));
88
89 hImageList = InitImageList(NumButtons,
90 IDB_TOOLSRECTSEL);
91
92 ImageList_Destroy((HIMAGELIST)SendMessage(hTb,
93 TB_SETIMAGELIST,
94 0,
95 (LPARAM)hImageList));
96
97 SendMessage(hTb,
98 TB_ADDBUTTONS,
99 NumButtons,
100 (LPARAM)ToolsButtons);
101
102 SendMessage(hTb,
103 TB_AUTOSIZE,
104 0,
105 0);
106
107 return TRUE;
108 }
109
110 return FALSE;
111 }
112
113
114 VOID
115 FloatWindowPaintColorPicker(HWND hColorPicker)
116 {
117 HDC hdc;
118 RECT rect;
119
120 InvalidateRect(hColorPicker,
121 NULL,
122 TRUE);
123 UpdateWindow(hColorPicker);
124
125 hdc = GetDC(hColorPicker);
126
127 GetClientRect(hColorPicker,
128 &rect);
129
130 Ellipse(hdc,
131 rect.left,
132 rect.top,
133 rect.right,
134 rect.bottom);
135
136 ReleaseDC(hColorPicker,
137 hdc);
138
139 }
140
141 VOID
142 FloatWindowPaintHueSlider(HWND hHueSlider)
143 {
144 HDC hdc;
145 RECT rect;
146
147 InvalidateRect(hHueSlider,
148 NULL,
149 TRUE);
150 UpdateWindow(hHueSlider);
151
152 hdc = GetDC(hHueSlider);
153
154 GetClientRect(hHueSlider,
155 &rect);
156
157 Rectangle(hdc,
158 rect.left,
159 rect.top,
160 rect.right,
161 rect.bottom);
162
163 ReleaseDC(hHueSlider,
164 hdc);
165
166 }
167
168
169 BOOL
170 FloatToolbarCreateColorsGui(PMAIN_WND_INFO Info)
171 {
172 HWND hColorPicker;
173 HWND hHueSlider;
174 HWND hMouseButton;
175 HWND hMore;
176 RECT rect;
177 HBITMAP hMoreBitmap;
178
179 GetClientRect(Info->fltColors->hSelf,
180 &rect);
181
182 hColorPicker = CreateWindowEx(0,
183 WC_STATIC,
184 NULL,
185 WS_CHILD | WS_VISIBLE | CBS_DROPDOWN,
186 2,
187 2,
188 (int) (rect.right * 0.65),
189 rect.bottom - 2,
190 Info->fltColors->hSelf,
191 NULL,
192 hInstance,
193 NULL);
194 if (hColorPicker == NULL)
195 return FALSE;
196
197 hHueSlider = CreateWindowEx(0,
198 WC_STATIC,
199 NULL,
200 WS_CHILD | WS_VISIBLE | CBS_DROPDOWN,
201 145,
202 35,
203 25,
204 135,
205 Info->fltColors->hSelf,
206 NULL,
207 hInstance,
208 NULL);
209 if (hHueSlider == NULL)
210 return FALSE;
211
212 hMouseButton = CreateWindowEx(0,
213 WC_COMBOBOX,
214 NULL,
215 WS_CHILD | WS_VISIBLE | CBS_DROPDOWN,
216 118, 5, 75, 25,
217 Info->fltColors->hSelf,
218 NULL,
219 hInstance,
220 NULL);
221 if (hMouseButton == NULL)
222 return FALSE;
223
224 MakeFlatCombo(hMouseButton);
225
226 /* temp, just testing */
227 SendMessage(hMouseButton, CB_ADDSTRING, 0, (LPARAM)_T("Primary"));
228 SendMessage(hMouseButton, CB_ADDSTRING, 0, (LPARAM)_T("Secondary"));
229 SendMessage(hMouseButton, CB_SETCURSEL, 0, 0);
230
231
232 hMore = CreateWindowEx(WS_EX_STATICEDGE,
233 WC_BUTTON,
234 NULL,
235 WS_CHILD | WS_VISIBLE | BS_BITMAP,
236 rect.right - 15,
237 rect.bottom - 15,
238 15, 15,
239 Info->fltColors->hSelf,
240 NULL,
241 hInstance,
242 NULL);
243 if (hMore == NULL)
244 return FALSE;
245
246 hMoreBitmap = (HBITMAP)LoadImage(hInstance,
247 MAKEINTRESOURCE(IDB_COLORSMORE),
248 IMAGE_BITMAP,
249 12,
250 11,
251 LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS);
252 if (hMoreBitmap != NULL)
253 {
254 SendMessage(hMore,
255 BM_SETIMAGE,
256 IMAGE_BITMAP,
257 (LPARAM)hMoreBitmap);
258 }
259
260
261 /* temp functions for playing about with possible layouts */
262 FloatWindowPaintHueSlider(hHueSlider);
263 FloatWindowPaintColorPicker(hColorPicker);
264
265 if (hColorPicker != NULL)
266 {
267 HDC hDc = GetDC(hColorPicker);
268 TextOut(hDc, 8, 75, _T("Possible layout?"), 16);
269 ReleaseDC(hColorPicker, hDc);
270 }
271
272 return TRUE;
273
274 }
275
276
277 BOOL
278 FloatToolbarCreateHistoryGui(PMAIN_WND_INFO Info)
279 {
280 HWND hList;
281 HWND hButtons;
282 HIMAGELIST hImageList;
283 INT NumButtons;
284
285 hList = CreateWindowEx(0,
286 WC_LISTBOX,
287 NULL,
288 WS_CHILD | WS_VISIBLE | LBS_EXTENDEDSEL,
289 0, 0, 143, 100,
290 Info->fltHistory->hSelf,
291 NULL,
292 hInstance,
293 NULL);
294 if (hList == NULL)
295 return FALSE;
296
297 NumButtons = sizeof(HistoryButtons) / sizeof(HistoryButtons[0]);
298 hButtons = CreateWindowEx(0,
299 TOOLBARCLASSNAME,
300 NULL,
301 WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | CCS_BOTTOM | CCS_NODIVIDER,
302 0, 0, 0, 0,
303 Info->fltHistory->hSelf,
304 NULL,
305 hInstance,
306 NULL);
307 if (hButtons != NULL)
308 {
309 SendMessage(hButtons,
310 TB_BUTTONSTRUCTSIZE,
311 sizeof(ToolsButtons[0]),
312 0);
313
314 SendMessage(hButtons,
315 TB_SETBITMAPSIZE,
316 0,
317 (LPARAM)MAKELONG(10, 10));
318
319 hImageList = InitImageList(NumButtons,
320 IDB_HISTBACK);
321
322 ImageList_Destroy((HIMAGELIST)SendMessage(hButtons,
323 TB_SETIMAGELIST,
324 0,
325 (LPARAM)hImageList));
326
327 SendMessage(hButtons,
328 TB_SETBUTTONSIZE,
329 0,
330 MAKELONG(18, 16));
331
332 SendMessage(hButtons,
333 TB_ADDBUTTONS,
334 NumButtons,
335 (LPARAM)HistoryButtons);
336
337 return TRUE;
338 }
339
340 return FALSE;
341 }
342
343
344 static VOID
345 DoTimer(PFLT_WND FltInfo,
346 UINT idTimer)
347 {
348 switch (idTimer)
349 {
350 /* timer to check if cursor is in toolbar coords */
351 case ID_TIMER1:
352 {
353 POINT pt;
354
355 /* kill timer if toobar is not opaque */
356 if (FltInfo->bOpaque != TRUE)
357 {
358 KillTimer(FltInfo->hSelf,
359 ID_TIMER1);
360 break;
361 }
362
363 if (GetCursorPos(&pt))
364 {
365 RECT rect;
366
367 if (GetWindowRect(FltInfo->hSelf,
368 &rect))
369 {
370 if (!PtInRect(&rect,
371 pt))
372 {
373 KillTimer(FltInfo->hSelf,
374 ID_TIMER1);
375 KillTimer(FltInfo->hSelf,
376 ID_TIMER2);
377
378 /* timer to fade out toolbar */
379 SetTimer(FltInfo->hSelf,
380 ID_TIMER3,
381 50,
382 NULL);
383 }
384 }
385 }
386 }
387 break;
388
389 /* timer to fade in toolbar */
390 case ID_TIMER2:
391 {
392 SetLayeredWindowAttributes(FltInfo->hSelf,
393 0,
394 (255 * FltInfo->Transparancy) / 100,
395 LWA_ALPHA);
396
397 /* increment transparancy until it is opaque (100) */
398 FltInfo->Transparancy += 5;
399
400 if (FltInfo->Transparancy == 100)
401 {
402 SetWindowLongPtr(FltInfo->hSelf,
403 GWL_EXSTYLE,
404 GetWindowLongPtr(FltInfo->hSelf,
405 GWL_EXSTYLE) & ~WS_EX_LAYERED);
406
407 FltInfo->bOpaque = TRUE;
408
409 KillTimer(FltInfo->hSelf,
410 ID_TIMER2);
411 }
412 }
413 break;
414
415 case ID_TIMER3:
416 {
417 LONG Style;
418
419 Style = GetWindowLongPtr(FltInfo->hSelf,
420 GWL_EXSTYLE);
421
422 if (Style & ~WS_EX_LAYERED)
423 {
424 SetWindowLongPtr(FltInfo->hSelf,
425 GWL_EXSTYLE,
426 Style | WS_EX_LAYERED);
427 }
428
429 FltInfo->Transparancy -= 5;
430
431 if (FltInfo->Transparancy >= 60)
432 {
433 /* set the tranclucency to 60% */
434 SetLayeredWindowAttributes(FltInfo->hSelf,
435 0,
436 (255 * FltInfo->Transparancy) / 100,
437 LWA_ALPHA);
438
439 if (FltInfo->Transparancy == 60)
440 {
441 FltInfo->bOpaque = FALSE;
442
443 KillTimer(FltInfo->hSelf,
444 ID_TIMER3);
445 }
446
447 }
448 }
449 break;
450 }
451 }
452
453 LRESULT CALLBACK
454 FloatToolbarWndProc(HWND hwnd,
455 UINT Message,
456 WPARAM wParam,
457 LPARAM lParam)
458 {
459 PFLT_WND FltInfo;
460
461 /* Get the window context */
462 FltInfo = (PFLT_WND)GetWindowLongPtr(hwnd,
463 GWLP_USERDATA);
464 if (FltInfo == NULL && Message != WM_CREATE)
465 {
466 goto HandleDefaultMessage;
467 }
468
469 switch(Message)
470 {
471 case WM_CREATE:
472 {
473 FltInfo = (PFLT_WND)(((LPCREATESTRUCT)lParam)->lpCreateParams);
474
475 /*FIXME: read this from registry */
476 // FltInfo->bShow = TRUE;
477
478 SetWindowLongPtr(hwnd,
479 GWLP_USERDATA,
480 (LONG_PTR)FltInfo);
481
482 FltInfo->bOpaque = FALSE;
483
484 SetWindowLongPtr(hwnd,
485 GWL_EXSTYLE,
486 GetWindowLongPtr(hwnd,
487 GWL_EXSTYLE) | WS_EX_LAYERED);
488
489 /* set the tranclucency to 60% */
490 FltInfo->Transparancy = 60;
491 SetLayeredWindowAttributes(hwnd,
492 0,
493 (255 * FltInfo->Transparancy) / 100,
494 LWA_ALPHA);
495 }
496 break;
497
498 case WM_TIMER:
499 {
500 DoTimer(FltInfo,
501 wParam);
502 }
503 break;
504
505 case WM_NCMOUSEMOVE:
506 case WM_MOUSEMOVE:
507 {
508 if (FltInfo->bOpaque == FALSE)
509 {
510
511 RedrawWindow(hwnd,
512 NULL,
513 NULL,
514 RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
515
516 FltInfo->bOpaque = TRUE;
517 //MessageBox(NULL, _T("in"), _T("Hit test"), MB_OK | MB_ICONEXCLAMATION);
518
519 /* timer to check if cursor is in toolbar coords */
520 SetTimer(hwnd,
521 ID_TIMER1,
522 200,
523 NULL);
524
525 /* timer to fade in the toolbars */
526 SetTimer(hwnd,
527 ID_TIMER2,
528 50,
529 NULL);
530 }
531 }
532 break;
533
534 case WM_CLOSE:
535 ShowHideWindow(FltInfo->hSelf);
536 break;
537
538 case WM_COMMAND:
539 {
540 if (LOWORD(wParam) == IDCANCEL)
541 ShowHideWindow(FltInfo->hSelf);
542
543 switch(LOWORD(wParam))
544 {
545 case ID_NEW:
546 MessageBox(hwnd, _T("Kapow!"), _T("Hit test"), MB_OK | MB_ICONEXCLAMATION);
547 break;
548
549 case ID_CLONESTAMP:
550 case ID_COLORPICKER:
551 case ID_ECLIPSE:
552 case ID_ECLIPSESEL:
553 case ID_ERASER:
554 case ID_FREEFORM:
555 case ID_LASOO:
556 case ID_LINE:
557 case ID_MAGICWAND:
558 case ID_MOVE:
559 case ID_MOVESEL:
560 case ID_PAINTBRUSH:
561 case ID_PAINTBUCKET:
562 case ID_PENCIL:
563 case ID_RECOLORING:
564 case ID_RECTANGLE:
565 case ID_ROUNDRECT:
566 case ID_TEXT:
567 case ID_ZOOM:
568 /*SendMessage(Info->hSelf,
569 LOWORD(wParam),
570 wParam,
571 lParam);*/
572 break;
573 }
574 }
575 break;
576
577 case WM_NCACTIVATE:
578 /* FIXME: needs fully implementing */
579 return DefWindowProc(hwnd,
580 Message,
581 TRUE,
582 lParam);
583 break;
584
585 case WM_DESTROY:
586 SetWindowLongPtr(hwnd,
587 GWLP_USERDATA,
588 0);
589 break;
590
591 default:
592 HandleDefaultMessage:
593 return DefWindowProc(hwnd,
594 Message,
595 wParam,
596 lParam);
597 }
598
599 return 0;
600 }
601
602
603 BOOL
604 InitFloatWndClass(VOID)
605 {
606 WNDCLASSEX wc = {0};
607
608 wc.cbSize = sizeof(WNDCLASSEX);
609 wc.style = CS_HREDRAW | CS_VREDRAW;
610 wc.lpfnWndProc = FloatToolbarWndProc;
611 wc.hInstance = hInstance;
612 wc.hIcon = NULL;
613 wc.hCursor = LoadCursor(NULL,
614 IDC_ARROW);
615 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
616 wc.lpszClassName = szFloatWndClass;
617 wc.hIconSm = NULL;
618
619 return RegisterClassEx(&wc) != (ATOM)0;
620 }
621
622 VOID
623 UninitFloatWndImpl(VOID)
624 {
625 UnregisterClass(szFloatWndClass,
626 hInstance);
627 }
628
629