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