attempt to convert most of this mess into something which at least look like C code
[reactos.git] / reactos / base / applications / paint / winproc.c
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: winproc.c
5 * PURPOSE: Window procedure of the main window and all children apart from
6 * hPalWin, hToolSettings and hSelection
7 * PROGRAMMERS: Benedikt Freisen
8 */
9
10 /* INCLUDES *********************************************************/
11
12 #include <windows.h>
13 #include <commctrl.h>
14 //#include <htmlhelp.h>
15 #include <stdio.h>
16 #include <tchar.h>
17 #include "definitions.h"
18 #include "globalvar.h"
19 #include "dialogs.h"
20 #include "dib.h"
21 #include "drawing.h"
22 #include "history.h"
23 #include "mouse.h"
24 #include "registry.h"
25
26 /* FUNCTIONS ********************************************************/
27
28 void selectTool(int tool)
29 {
30 ShowWindow(hSelection, SW_HIDE);
31 activeTool = tool;
32 SendMessage(hToolSettings, WM_PAINT, 0, 0);
33 }
34
35 void updateCanvasAndScrollbars()
36 {
37 ShowWindow(hSelection, SW_HIDE);
38 MoveWindow(hImageArea, 3, 3, imgXRes*zoom/1000, imgYRes*zoom/1000, FALSE);
39 InvalidateRect(hScrollbox, NULL, TRUE);
40 InvalidateRect(hImageArea, NULL, FALSE);
41
42 SetScrollPos(hScrollbox, SB_HORZ, 0, TRUE);
43 SetScrollPos(hScrollbox, SB_VERT, 0, TRUE);
44 }
45
46 void ZoomTo(int newZoom)
47 {
48 zoom = newZoom;
49 updateCanvasAndScrollbars();
50 }
51
52 HDC hdc;
53 BOOL drawing;
54
55 LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
56 {
57 switch (message) /* handle the messages */
58 {
59 case WM_DESTROY:
60 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
61 break;
62 case WM_CLOSE:
63 if (undoSteps>0)
64 {
65 TCHAR programname[20];
66 TCHAR saveprompttext[100];
67 TCHAR temptext[500];
68 LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
69 LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, saveprompttext, SIZEOF(saveprompttext));
70 _stprintf(temptext, saveprompttext, filename);
71 switch (MessageBox(hwnd, temptext, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
72 {
73 case IDNO:
74 DestroyWindow(hwnd);
75 break;
76 case IDYES:
77 SendMessage(hwnd, WM_COMMAND, IDM_FILESAVEAS, 0);
78 DestroyWindow(hwnd);
79 break;
80 }
81 }
82 else
83 {
84 DestroyWindow(hwnd);
85 }
86 break;
87 case WM_INITMENUPOPUP:
88 switch (lParam)
89 {
90 case 0:
91 if (isAFile)
92 {
93 EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERPLANE, MF_ENABLED | MF_BYCOMMAND);
94 EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERCENTERED, MF_ENABLED | MF_BYCOMMAND);
95 EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERSTRETCHED, MF_ENABLED | MF_BYCOMMAND);
96 }
97 else
98 {
99 EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERPLANE, MF_GRAYED | MF_BYCOMMAND);
100 EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERCENTERED, MF_GRAYED | MF_BYCOMMAND);
101 EnableMenuItem(GetMenu(hMainWnd), IDM_FILEASWALLPAPERSTRETCHED, MF_GRAYED | MF_BYCOMMAND);
102 }
103 break;
104 case 1:
105 if (undoSteps>0)
106 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITUNDO, MF_ENABLED | MF_BYCOMMAND);
107 else
108 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITUNDO, MF_GRAYED | MF_BYCOMMAND);
109 if (redoSteps>0)
110 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITREDO, MF_ENABLED | MF_BYCOMMAND);
111 else
112 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITREDO, MF_GRAYED | MF_BYCOMMAND);
113 if (IsWindowVisible(hSelection))
114 {
115 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCUT, MF_ENABLED | MF_BYCOMMAND);
116 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCOPY, MF_ENABLED | MF_BYCOMMAND);
117 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITDELETESELECTION, MF_ENABLED | MF_BYCOMMAND);
118 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITINVERTSELECTION, MF_ENABLED | MF_BYCOMMAND);
119 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCOPYTO, MF_ENABLED | MF_BYCOMMAND);
120 }
121 else
122 {
123 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCUT, MF_GRAYED | MF_BYCOMMAND);
124 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCOPY, MF_GRAYED | MF_BYCOMMAND);
125 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITDELETESELECTION, MF_GRAYED | MF_BYCOMMAND);
126 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITINVERTSELECTION, MF_GRAYED | MF_BYCOMMAND);
127 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITCOPYTO, MF_GRAYED | MF_BYCOMMAND);
128 }
129 OpenClipboard(hMainWnd);
130 if (GetClipboardData(CF_BITMAP)!=NULL)
131 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITPASTE, MF_ENABLED | MF_BYCOMMAND);
132 else
133 EnableMenuItem(GetMenu(hMainWnd), IDM_EDITPASTE, MF_GRAYED | MF_BYCOMMAND);
134 CloseClipboard();
135 break;
136 case 3:
137 if (IsWindowVisible(hSelection))
138 EnableMenuItem(GetMenu(hMainWnd), IDM_IMAGECROP, MF_ENABLED | MF_BYCOMMAND);
139 else
140 EnableMenuItem(GetMenu(hMainWnd), IDM_IMAGECROP, MF_GRAYED | MF_BYCOMMAND);
141 if (transpBg==0)
142 CheckMenuItem(GetMenu(hMainWnd), IDM_IMAGEDRAWOPAQUE, MF_CHECKED | MF_BYCOMMAND);
143 else
144 CheckMenuItem(GetMenu(hMainWnd), IDM_IMAGEDRAWOPAQUE, MF_UNCHECKED | MF_BYCOMMAND);
145 break;
146 }
147 break;
148 case WM_SIZE:
149 if (hwnd==hMainWnd)
150 {
151 int test[] = {LOWORD(lParam)-260, LOWORD(lParam)-140, LOWORD(lParam)-20};
152 SendMessage(hStatusBar, WM_SIZE, wParam, lParam);
153 SendMessage(hStatusBar, SB_SETPARTS, 3, (int)&test);
154 MoveWindow(hScrollbox, 56, 49,LOWORD(lParam)-56, HIWORD(lParam)-72, TRUE);
155 //InvalidateRect(hwnd, NULL, TRUE);
156 }
157 if ((hwnd==hImageArea)||(hwnd==hScrollbox))
158 {
159 long clientRectScrollbox[4];
160 long clientRectImageArea[4];
161 SCROLLINFO horzScroll;
162 SCROLLINFO vertScroll;
163 GetClientRect(hScrollbox, (LPRECT)&clientRectScrollbox);
164 GetClientRect(hImageArea, (LPRECT)&clientRectImageArea);
165 MoveWindow(hScrlClient, 0, 0, max(clientRectImageArea[2]+6, clientRectScrollbox[2]), max(clientRectImageArea[3]+6, clientRectScrollbox[3]), TRUE);
166 horzScroll.cbSize = sizeof(SCROLLINFO);
167 horzScroll.fMask = SIF_PAGE | SIF_RANGE;
168 horzScroll.nMax = 10000;
169 horzScroll.nMin = 0;
170 horzScroll.nPage = clientRectScrollbox[2]*10000/(clientRectImageArea[2]+6);
171 horzScroll.nPos = 0;
172 horzScroll.nTrackPos = 0;
173 SetScrollInfo(hScrollbox, SB_HORZ, &horzScroll, TRUE);
174 GetClientRect(hScrollbox, (LPRECT)clientRectScrollbox);
175 vertScroll.cbSize = sizeof(SCROLLINFO);
176 vertScroll.fMask = SIF_PAGE | SIF_RANGE;
177 vertScroll.nMax = 10000;
178 vertScroll.nMin = 0;
179 vertScroll.nPage = clientRectScrollbox[3]*10000/(clientRectImageArea[3]+6);
180 vertScroll.nPos = 0;
181 vertScroll.nTrackPos = 0;
182 SetScrollInfo(hScrollbox, SB_VERT, &vertScroll, TRUE);
183 }
184 break;
185 case WM_HSCROLL:
186 if (hwnd==hScrollbox)
187 {
188 if ((LOWORD(wParam)==SB_THUMBPOSITION)||(LOWORD(wParam)==SB_THUMBTRACK))
189 {
190 SetScrollPos(hScrollbox, SB_HORZ, HIWORD(wParam), TRUE);
191 MoveWindow(hScrlClient, -(imgXRes*zoom/1000+6)*GetScrollPos(hScrollbox, SB_HORZ)/10000,
192 -(imgYRes*zoom/1000+6)*GetScrollPos(hScrollbox, SB_VERT)/10000, imgXRes*zoom/1000+6, imgYRes*zoom/1000+6, TRUE);
193 }
194 }
195 break;
196 case WM_VSCROLL:
197 if (hwnd==hScrollbox)
198 {
199 if ((LOWORD(wParam)==SB_THUMBPOSITION)||(LOWORD(wParam)==SB_THUMBTRACK))
200 {
201 SetScrollPos(hScrollbox, SB_VERT, HIWORD(wParam), TRUE);
202 MoveWindow(hScrlClient, -(imgXRes*zoom/1000+6)*GetScrollPos(hScrollbox, SB_HORZ)/10000,
203 -(imgYRes*zoom/1000+6)*GetScrollPos(hScrollbox, SB_VERT)/10000, imgXRes*zoom/1000+6, imgYRes*zoom/1000+6, TRUE);
204 }
205 }
206 break;
207 case WM_GETMINMAXINFO:
208 if (hwnd==hMainWnd)
209 {
210 MINMAXINFO *mm = (LPMINMAXINFO)lParam;
211 (*mm).ptMinTrackSize.x = 330;
212 (*mm).ptMinTrackSize.y = 430;
213 }
214 break;
215 case WM_PAINT:
216 DefWindowProc (hwnd, message, wParam, lParam);
217 if (hwnd==hImageArea)
218 {
219 HDC hdc = GetDC(hImageArea);
220 StretchBlt(hdc, 0, 0, imgXRes*zoom/1000, imgYRes*zoom/1000, hDrawingDC, 0, 0, imgXRes, imgYRes, SRCCOPY);
221 ReleaseDC(hImageArea, hdc);
222 SendMessage(hSelection, WM_PAINT, 0, 0);
223 }
224 break;
225
226 // mouse events used for drawing
227
228 case WM_SETCURSOR:
229 if (hwnd==hImageArea)
230 {
231 switch (activeTool)
232 {
233 case 4:
234 SetCursor(hCurFill);
235 break;
236 case 5:
237 SetCursor(hCurColor);
238 break;
239 case 6:
240 SetCursor(hCurZoom);
241 break;
242 case 7:
243 SetCursor(hCurPen);
244 break;
245 case 9:
246 SetCursor(hCurAirbrush);
247 break;
248 default:
249 SetCursor(LoadCursor(NULL, IDC_CROSS));
250 }
251 } else DefWindowProc(hwnd, message, wParam, lParam);
252 break;
253 case WM_LBUTTONDOWN:
254 if (hwnd==hImageArea)
255 {
256 if ((!drawing)||(activeTool==5))
257 {
258 SetCapture(hImageArea);
259 drawing = TRUE;
260 startPainting(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom, fgColor, bgColor);
261 }else
262 {
263 SendMessage(hwnd, WM_LBUTTONUP, wParam, lParam);
264 undo();
265 }
266 SendMessage(hImageArea, WM_PAINT, 0, 0);
267 if ((activeTool==6)&&(zoom<8000)) ZoomTo(zoom*2);
268 }
269 break;
270 case WM_RBUTTONDOWN:
271 if (hwnd==hImageArea)
272 {
273 if ((!drawing)||(activeTool==5))
274 {
275 SetCapture(hImageArea);
276 drawing = TRUE;
277 startPainting(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom, bgColor, fgColor);
278 }else
279 {
280 SendMessage(hwnd, WM_RBUTTONUP, wParam, lParam);
281 undo();
282 }
283 SendMessage(hImageArea, WM_PAINT, 0, 0);
284 if ((activeTool==6)&&(zoom>125)) ZoomTo(zoom/2);
285 }
286 break;
287 case WM_LBUTTONUP:
288 if ((hwnd==hImageArea)&&drawing)
289 {
290 ReleaseCapture();
291 drawing = FALSE;
292 endPainting(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom, fgColor, bgColor);
293 SendMessage(hImageArea, WM_PAINT, 0, 0);
294 if (activeTool==5)
295 {
296 int tempColor = GetPixel(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom);
297 if (tempColor!=CLR_INVALID) fgColor = tempColor;
298 SendMessage(hPalWin, WM_PAINT, 0, 0);
299 }
300 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM)"");
301 }
302 break;
303 case WM_RBUTTONUP:
304 if ((hwnd==hImageArea)&&drawing)
305 {
306 ReleaseCapture();
307 drawing = FALSE;
308 endPainting(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom, bgColor, fgColor);
309 SendMessage(hImageArea, WM_PAINT, 0, 0);
310 if (activeTool==5)
311 {
312 int tempColor = GetPixel(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom);
313 if (tempColor!=CLR_INVALID) bgColor = tempColor;
314 SendMessage(hPalWin, WM_PAINT, 0, 0);
315 }
316 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM)"");
317 }
318 break;
319 case WM_MOUSEMOVE:
320 if (hwnd==hImageArea)
321 {
322 if ((!drawing)||(activeTool<=9))
323 {
324 TCHAR coordStr[100];
325 _stprintf(coordStr, _T("%d, %d"), (short)LOWORD(lParam)*1000/zoom, (short)HIWORD(lParam)*1000/zoom);
326 SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM)coordStr);
327 }
328 if (drawing)
329 {
330 if ((wParam&MK_LBUTTON)!=0)
331 {
332 whilePainting(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom, fgColor, bgColor);
333 SendMessage(hImageArea, WM_PAINT, 0, 0);
334 if ((activeTool>=10)||(activeTool==2))
335 {
336 TCHAR sizeStr[100];
337 _stprintf(sizeStr, _T("%d x %d"), (short)LOWORD(lParam)*1000/zoom-startX, (short)HIWORD(lParam)*1000/zoom-startY);
338 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM)sizeStr);
339 }
340 }
341 if ((wParam&MK_RBUTTON)!=0)
342 {
343 whilePainting(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom, bgColor, fgColor);
344 SendMessage(hImageArea, WM_PAINT, 0, 0);
345 if (activeTool>=10)
346 {
347 TCHAR sizeStr[100];
348 _stprintf(sizeStr, _T("%d x %d"), (short)LOWORD(lParam)*1000/zoom-startX, (short)HIWORD(lParam)*1000/zoom-startY);
349 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM)sizeStr);
350 }
351 }
352 }
353 } else
354 {
355 SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM)_T(""));
356 }
357 break;
358
359 // menu and button events
360
361 case WM_COMMAND:
362 switch (LOWORD(wParam))
363 {
364 case IDM_HELPINFO:
365 {
366 HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON));
367 TCHAR infotitle[100];
368 TCHAR infotext[200];
369 LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle));
370 LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext));
371 ShellAbout(hMainWnd, infotitle, infotext, paintIcon);
372 DeleteObject(paintIcon);
373 }
374 break;
375 case IDM_HELPHELPTOPICS:
376 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
377 break;
378 case IDM_FILEEXIT:
379 SendMessage(hwnd, WM_CLOSE, wParam, lParam);
380 break;
381 case IDM_FILENEW:
382 Rectangle(hDrawingDC, 0-1, 0-1, imgXRes+1, imgYRes+1);
383 SendMessage(hImageArea, WM_PAINT, 0, 0);
384 break;
385 case IDM_FILEOPEN:
386 if (GetOpenFileName(&ofn)!=0)
387 {
388 HBITMAP bmNew = (HBITMAP)LoadDIBFromFile(ofn.lpstrFile);
389 if (bmNew!=NULL)
390 {
391 TCHAR tempstr[1000];
392 TCHAR resstr[100];
393 insertReversible(bmNew);
394 updateCanvasAndScrollbars();
395 CopyMemory(filename, ofn.lpstrFileTitle, sizeof(filename));
396 CopyMemory(filepathname, ofn.lpstrFileTitle, sizeof(filepathname));
397 LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
398 _stprintf(tempstr, resstr, filename);
399 SetWindowText(hMainWnd, tempstr);
400 clearHistory();
401 isAFile = TRUE;
402 }
403 }
404 break;
405 case IDM_FILESAVE:
406 if (isAFile)
407 SaveDIBToFile(hBms[currInd], filepathname, hDrawingDC);
408 else
409 SendMessage(hwnd, WM_COMMAND, IDM_FILESAVEAS, 0);
410 break;
411 case IDM_FILESAVEAS:
412 if (GetSaveFileName(&sfn)!=0)
413 {
414 TCHAR tempstr[1000];
415 TCHAR resstr[100];
416 SaveDIBToFile(hBms[currInd], sfn.lpstrFile, hDrawingDC);
417 CopyMemory(filename, sfn.lpstrFileTitle, sizeof(filename));
418 CopyMemory(filepathname, sfn.lpstrFileTitle, sizeof(filepathname));
419 LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
420 _stprintf(tempstr, resstr, filename);
421 SetWindowText(hMainWnd, tempstr);
422 isAFile = TRUE;
423 }
424 break;
425 case IDM_FILEASWALLPAPERPLANE:
426 SetWallpaper(filepathname, 1, 1);
427 break;
428 case IDM_FILEASWALLPAPERCENTERED:
429 SetWallpaper(filepathname, 1, 0);
430 break;
431 case IDM_FILEASWALLPAPERSTRETCHED:
432 SetWallpaper(filepathname, 2, 0);
433 break;
434 case IDM_EDITUNDO:
435 undo();
436 SendMessage(hImageArea, WM_PAINT, 0, 0);
437 break;
438 case IDM_EDITREDO:
439 redo();
440 SendMessage(hImageArea, WM_PAINT, 0, 0);
441 break;
442 case IDM_EDITCOPY:
443 OpenClipboard(hMainWnd);
444 EmptyClipboard();
445 SetClipboardData(CF_BITMAP, CopyImage(hSelBm, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
446 CloseClipboard();
447 break;
448 case IDM_EDITPASTE:
449 OpenClipboard(hMainWnd);
450 if (GetClipboardData(CF_BITMAP)!=NULL)
451 {
452 DeleteObject(SelectObject(hSelDC, hSelBm = CopyImage(GetClipboardData(CF_BITMAP), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)));
453 newReversible();
454 rectSel_src[0] = rectSel_src[1] = rectSel_src[2] = rectSel_src[3] = 0;
455 rectSel_dest[0] = rectSel_dest[1] = 0;
456 rectSel_dest[2] = GetDIBWidth(hSelBm);
457 rectSel_dest[3] = GetDIBHeight(hSelBm);
458 BitBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, SRCCOPY);
459 placeSelWin();
460 ShowWindow(hSelection, SW_SHOW);
461 }
462 CloseClipboard();
463 break;
464 case IDM_EDITDELETESELECTION:
465 ShowWindow(hSelection, SW_HIDE);
466 break;
467 case IDM_EDITSELECTALL:
468 if (activeTool==2)
469 {
470 startPainting(hDrawingDC, 0, 0, fgColor, bgColor);
471 whilePainting(hDrawingDC, imgXRes, imgYRes, fgColor, bgColor);
472 endPainting(hDrawingDC, imgXRes, imgYRes, fgColor, bgColor);
473 }
474 break;
475 case IDM_EDITCOPYTO:
476 if (GetSaveFileName(&ofn)!=0) SaveDIBToFile(hSelBm, ofn.lpstrFile, hDrawingDC);
477 break;
478 case IDM_COLORSEDITPALETTE:
479 if (ChooseColor(&choosecolor))
480 {
481 fgColor = choosecolor.rgbResult;
482 SendMessage(hPalWin, WM_PAINT, 0, 0);
483 }
484 break;
485 case IDM_IMAGEINVERTCOLORS:
486 {
487 RECT tempRect;
488 newReversible();
489 SetRect(&tempRect, 0, 0, imgXRes, imgYRes);
490 InvertRect(hDrawingDC, &tempRect);
491 SendMessage(hImageArea, WM_PAINT, 0, 0);
492 }
493 break;
494 case IDM_IMAGEDELETEIMAGE:
495 newReversible();
496 Rect(hDrawingDC, 0, 0, imgXRes, imgYRes, bgColor, bgColor, 0, TRUE);
497 SendMessage(hImageArea, WM_PAINT, 0, 0);
498 break;
499 case IDM_IMAGEROTATEMIRROR:
500 switch (mirrorRotateDlg())
501 {
502 case 1:
503 newReversible();
504 StretchBlt(hDrawingDC, imgXRes-1, 0, -imgXRes, imgYRes, hDrawingDC, 0, 0, imgXRes, imgYRes, SRCCOPY);
505 SendMessage(hImageArea, WM_PAINT, 0, 0);
506 break;
507 case 2:
508 newReversible();
509 StretchBlt(hDrawingDC, 0, imgYRes-1, imgXRes, -imgYRes, hDrawingDC, 0, 0, imgXRes, imgYRes, SRCCOPY);
510 SendMessage(hImageArea, WM_PAINT, 0, 0);
511 break;
512 case 4:
513 newReversible();
514 StretchBlt(hDrawingDC, imgXRes-1, imgYRes-1, -imgXRes, -imgYRes, hDrawingDC, 0, 0, imgXRes, imgYRes, SRCCOPY);
515 SendMessage(hImageArea, WM_PAINT, 0, 0);
516 break;
517 }
518 break;
519 case IDM_IMAGEATTRIBUTES:
520 {
521 int retVal = attributesDlg();
522 if ((LOWORD(retVal)!=0)&&(HIWORD(retVal)!=0))
523 {
524 // cropReversible broken, dirty hack:
525 // insertReversible(CopyImage(hBms[currInd], IMAGE_BITMAP, LOWORD(retVal), HIWORD(retVal), 0));
526 cropReversible(LOWORD(retVal), HIWORD(retVal));
527 updateCanvasAndScrollbars();
528 }
529 }
530 break;
531 case IDM_IMAGECHANGESIZE:
532 {
533 int retVal = changeSizeDlg();
534 if ((LOWORD(retVal)!=0)&&(HIWORD(retVal)!=0))
535 {
536 insertReversible(CopyImage(hBms[currInd], IMAGE_BITMAP, imgXRes*LOWORD(retVal)/100, imgYRes*HIWORD(retVal)/100, 0));
537 updateCanvasAndScrollbars();
538 }
539 }
540 break;
541 case IDM_IMAGEDRAWOPAQUE:
542 transpBg = 1-transpBg;
543 SendMessage(hToolSettings, WM_PAINT, 0, 0);
544 break;
545 case IDM_IMAGECROP:
546 insertReversible(CopyImage(hSelBm, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
547 updateCanvasAndScrollbars();
548 break;
549
550 case IDM_VIEWZOOM125:
551 ZoomTo(125);
552 break;
553 case IDM_VIEWZOOM25:
554 ZoomTo(250);
555 break;
556 case IDM_VIEWZOOM50:
557 ZoomTo(500);
558 break;
559 case IDM_VIEWZOOM100:
560 ZoomTo(1000);
561 break;
562 case IDM_VIEWZOOM200:
563 ZoomTo(2000);
564 break;
565 case IDM_VIEWZOOM400:
566 ZoomTo(4000);
567 break;
568 case IDM_VIEWZOOM800:
569 ZoomTo(8000);
570 break;
571 case ID_FREESEL:
572 selectTool(1);
573 break;
574 case ID_RECTSEL:
575 selectTool(2);
576 break;
577 case ID_RUBBER:
578 selectTool(3);
579 break;
580 case ID_FILL:
581 selectTool(4);
582 break;
583 case ID_COLOR:
584 selectTool(5);
585 break;
586 case ID_ZOOM:
587 selectTool(6);
588 break;
589 case ID_PEN:
590 selectTool(7);
591 break;
592 case ID_BRUSH:
593 selectTool(8);
594 break;
595 case ID_AIRBRUSH:
596 selectTool(9);
597 break;
598 case ID_TEXT:
599 selectTool(10);
600 break;
601 case ID_LINE:
602 selectTool(11);
603 break;
604 case ID_BEZIER:
605 selectTool(12);
606 break;
607 case ID_RECT:
608 selectTool(13);
609 break;
610 case ID_SHAPE:
611 selectTool(14);
612 break;
613 case ID_ELLIPSE:
614 selectTool(15);
615 break;
616 case ID_RRECT:
617 selectTool(16);
618 break;
619 }
620 break;
621 default:
622 return DefWindowProc (hwnd, message, wParam, lParam);
623 }
624
625 return 0;
626 }
627