4e72294a99b54edd907295ff4cac2310d0baf20b
[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 GetClientRect(hwndMiniature, (LPRECT)&mclient);
317 HDC hdc = GetDC(hwndMiniature);
318 BitBlt(hdc, -min(imgXRes*GetScrollPos(hScrollbox, SB_HORZ)/10000, imgXRes-mclient[2]),
319 -min(imgYRes*GetScrollPos(hScrollbox, SB_VERT)/10000, imgYRes-mclient[3]), imgXRes, imgYRes, hDrawingDC, 0, 0, SRCCOPY);
320 ReleaseDC(hwndMiniature, hdc);
321 }
322 break;
323
324 // mouse events used for drawing
325
326 case WM_SETCURSOR:
327 if (hwnd==hImageArea)
328 {
329 switch (activeTool)
330 {
331 case 4:
332 SetCursor(hCurFill);
333 break;
334 case 5:
335 SetCursor(hCurColor);
336 break;
337 case 6:
338 SetCursor(hCurZoom);
339 break;
340 case 7:
341 SetCursor(hCurPen);
342 break;
343 case 9:
344 SetCursor(hCurAirbrush);
345 break;
346 default:
347 SetCursor(LoadCursor(NULL, IDC_CROSS));
348 }
349 } else DefWindowProc(hwnd, message, wParam, lParam);
350 break;
351 case WM_LBUTTONDOWN:
352 if (hwnd==hImageArea)
353 {
354 if ((!drawing)||(activeTool==5))
355 {
356 SetCapture(hImageArea);
357 drawing = TRUE;
358 startPaintingL(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom, fgColor, bgColor);
359 }else
360 {
361 SendMessage(hwnd, WM_LBUTTONUP, wParam, lParam);
362 undo();
363 }
364 SendMessage(hImageArea, WM_PAINT, 0, 0);
365 if ((activeTool==6)&&(zoom<8000)) ZoomTo(zoom*2);
366 }
367 break;
368 case WM_RBUTTONDOWN:
369 if (hwnd==hImageArea)
370 {
371 if ((!drawing)||(activeTool==5))
372 {
373 SetCapture(hImageArea);
374 drawing = TRUE;
375 startPaintingR(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom, fgColor, bgColor);
376 }else
377 {
378 SendMessage(hwnd, WM_RBUTTONUP, wParam, lParam);
379 undo();
380 }
381 SendMessage(hImageArea, WM_PAINT, 0, 0);
382 if ((activeTool==6)&&(zoom>125)) ZoomTo(zoom/2);
383 }
384 break;
385 case WM_LBUTTONUP:
386 if ((hwnd==hImageArea)&&drawing)
387 {
388 ReleaseCapture();
389 drawing = FALSE;
390 endPaintingL(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom, fgColor, bgColor);
391 SendMessage(hImageArea, WM_PAINT, 0, 0);
392 if (activeTool==5)
393 {
394 int tempColor = GetPixel(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom);
395 if (tempColor!=CLR_INVALID) fgColor = tempColor;
396 SendMessage(hPalWin, WM_PAINT, 0, 0);
397 }
398 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM)"");
399 }
400 break;
401 case WM_RBUTTONUP:
402 if ((hwnd==hImageArea)&&drawing)
403 {
404 ReleaseCapture();
405 drawing = FALSE;
406 endPaintingR(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom, fgColor, bgColor);
407 SendMessage(hImageArea, WM_PAINT, 0, 0);
408 if (activeTool==5)
409 {
410 int tempColor = GetPixel(hDrawingDC, LOWORD(lParam)*1000/zoom, HIWORD(lParam)*1000/zoom);
411 if (tempColor!=CLR_INVALID) bgColor = tempColor;
412 SendMessage(hPalWin, WM_PAINT, 0, 0);
413 }
414 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM)"");
415 }
416 break;
417 case WM_MOUSEMOVE:
418 if (hwnd==hImageArea)
419 {
420 if ((!drawing)||(activeTool<=9))
421 {
422 TCHAR coordStr[100];
423 _stprintf(coordStr, _T("%d, %d"), (short)LOWORD(lParam)*1000/zoom, (short)HIWORD(lParam)*1000/zoom);
424 SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM)coordStr);
425 }
426 if (drawing)
427 {
428 if ((wParam&MK_LBUTTON)!=0)
429 {
430 whilePaintingL(hDrawingDC, (short)LOWORD(lParam)*1000/zoom, (short)HIWORD(lParam)*1000/zoom, fgColor, bgColor);
431 SendMessage(hImageArea, WM_PAINT, 0, 0);
432 if ((activeTool>=10)||(activeTool==2))
433 {
434 TCHAR sizeStr[100];
435 _stprintf(sizeStr, _T("%d x %d"), (short)LOWORD(lParam)*1000/zoom-startX, (short)HIWORD(lParam)*1000/zoom-startY);
436 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM)sizeStr);
437 }
438 }
439 if ((wParam&MK_RBUTTON)!=0)
440 {
441 whilePaintingR(hDrawingDC, (short)LOWORD(lParam)*1000/zoom, (short)HIWORD(lParam)*1000/zoom, fgColor, bgColor);
442 SendMessage(hImageArea, WM_PAINT, 0, 0);
443 if (activeTool>=10)
444 {
445 TCHAR sizeStr[100];
446 _stprintf(sizeStr, _T("%d x %d"), (short)LOWORD(lParam)*1000/zoom-startX, (short)HIWORD(lParam)*1000/zoom-startY);
447 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM)sizeStr);
448 }
449 }
450 }
451 } else
452 {
453 SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM)_T(""));
454 }
455 break;
456
457 // menu and button events
458
459 case WM_COMMAND:
460 switch (LOWORD(wParam))
461 {
462 case IDM_HELPINFO:
463 {
464 HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON));
465 TCHAR infotitle[100];
466 TCHAR infotext[200];
467 LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle));
468 LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext));
469 ShellAbout(hMainWnd, infotitle, infotext, paintIcon);
470 DeleteObject(paintIcon);
471 }
472 break;
473 case IDM_HELPHELPTOPICS:
474 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
475 break;
476 case IDM_FILEEXIT:
477 SendMessage(hwnd, WM_CLOSE, wParam, lParam);
478 break;
479 case IDM_FILENEW:
480 Rectangle(hDrawingDC, 0-1, 0-1, imgXRes+1, imgYRes+1);
481 SendMessage(hImageArea, WM_PAINT, 0, 0);
482 break;
483 case IDM_FILEOPEN:
484 if (GetOpenFileName(&ofn)!=0)
485 {
486 HBITMAP bmNew = (HBITMAP)LoadDIBFromFile(ofn.lpstrFile);
487 if (bmNew!=NULL)
488 {
489 TCHAR tempstr[1000];
490 TCHAR resstr[100];
491 insertReversible(bmNew);
492 updateCanvasAndScrollbars();
493 CopyMemory(filename, ofn.lpstrFileTitle, sizeof(filename));
494 CopyMemory(filepathname, ofn.lpstrFileTitle, sizeof(filepathname));
495 LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
496 _stprintf(tempstr, resstr, filename);
497 SetWindowText(hMainWnd, tempstr);
498 clearHistory();
499 isAFile = TRUE;
500 }
501 }
502 break;
503 case IDM_FILESAVE:
504 if (isAFile)
505 SaveDIBToFile(hBms[currInd], filepathname, hDrawingDC);
506 else
507 SendMessage(hwnd, WM_COMMAND, IDM_FILESAVEAS, 0);
508 break;
509 case IDM_FILESAVEAS:
510 if (GetSaveFileName(&sfn)!=0)
511 {
512 TCHAR tempstr[1000];
513 TCHAR resstr[100];
514 SaveDIBToFile(hBms[currInd], sfn.lpstrFile, hDrawingDC);
515 CopyMemory(filename, sfn.lpstrFileTitle, sizeof(filename));
516 CopyMemory(filepathname, sfn.lpstrFileTitle, sizeof(filepathname));
517 LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
518 _stprintf(tempstr, resstr, filename);
519 SetWindowText(hMainWnd, tempstr);
520 isAFile = TRUE;
521 }
522 break;
523 case IDM_FILEASWALLPAPERPLANE:
524 SetWallpaper(filepathname, 1, 1);
525 break;
526 case IDM_FILEASWALLPAPERCENTERED:
527 SetWallpaper(filepathname, 1, 0);
528 break;
529 case IDM_FILEASWALLPAPERSTRETCHED:
530 SetWallpaper(filepathname, 2, 0);
531 break;
532 case IDM_EDITUNDO:
533 undo();
534 SendMessage(hImageArea, WM_PAINT, 0, 0);
535 break;
536 case IDM_EDITREDO:
537 redo();
538 SendMessage(hImageArea, WM_PAINT, 0, 0);
539 break;
540 case IDM_EDITCOPY:
541 OpenClipboard(hMainWnd);
542 EmptyClipboard();
543 SetClipboardData(CF_BITMAP, CopyImage(hSelBm, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
544 CloseClipboard();
545 break;
546 case IDM_EDITPASTE:
547 OpenClipboard(hMainWnd);
548 if (GetClipboardData(CF_BITMAP)!=NULL)
549 {
550 DeleteObject(SelectObject(hSelDC, hSelBm = CopyImage(GetClipboardData(CF_BITMAP), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)));
551 newReversible();
552 rectSel_src[0] = rectSel_src[1] = rectSel_src[2] = rectSel_src[3] = 0;
553 rectSel_dest[0] = rectSel_dest[1] = 0;
554 rectSel_dest[2] = GetDIBWidth(hSelBm);
555 rectSel_dest[3] = GetDIBHeight(hSelBm);
556 BitBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, SRCCOPY);
557 placeSelWin();
558 ShowWindow(hSelection, SW_SHOW);
559 }
560 CloseClipboard();
561 break;
562 case IDM_EDITDELETESELECTION:
563 ShowWindow(hSelection, SW_HIDE);
564 break;
565 case IDM_EDITSELECTALL:
566 if (activeTool==2)
567 {
568 startPaintingL(hDrawingDC, 0, 0, fgColor, bgColor);
569 whilePaintingL(hDrawingDC, imgXRes, imgYRes, fgColor, bgColor);
570 endPaintingL(hDrawingDC, imgXRes, imgYRes, fgColor, bgColor);
571 }
572 break;
573 case IDM_EDITCOPYTO:
574 if (GetSaveFileName(&ofn)!=0) SaveDIBToFile(hSelBm, ofn.lpstrFile, hDrawingDC);
575 break;
576 case IDM_COLORSEDITPALETTE:
577 if (ChooseColor(&choosecolor))
578 {
579 fgColor = choosecolor.rgbResult;
580 SendMessage(hPalWin, WM_PAINT, 0, 0);
581 }
582 break;
583 case IDM_IMAGEINVERTCOLORS:
584 {
585 RECT tempRect;
586 newReversible();
587 SetRect(&tempRect, 0, 0, imgXRes, imgYRes);
588 InvertRect(hDrawingDC, &tempRect);
589 SendMessage(hImageArea, WM_PAINT, 0, 0);
590 }
591 break;
592 case IDM_IMAGEDELETEIMAGE:
593 newReversible();
594 Rect(hDrawingDC, 0, 0, imgXRes, imgYRes, bgColor, bgColor, 0, TRUE);
595 SendMessage(hImageArea, WM_PAINT, 0, 0);
596 break;
597 case IDM_IMAGEROTATEMIRROR:
598 switch (mirrorRotateDlg())
599 {
600 case 1:
601 newReversible();
602 StretchBlt(hDrawingDC, imgXRes-1, 0, -imgXRes, imgYRes, hDrawingDC, 0, 0, imgXRes, imgYRes, SRCCOPY);
603 SendMessage(hImageArea, WM_PAINT, 0, 0);
604 break;
605 case 2:
606 newReversible();
607 StretchBlt(hDrawingDC, 0, imgYRes-1, imgXRes, -imgYRes, hDrawingDC, 0, 0, imgXRes, imgYRes, SRCCOPY);
608 SendMessage(hImageArea, WM_PAINT, 0, 0);
609 break;
610 case 4:
611 newReversible();
612 StretchBlt(hDrawingDC, imgXRes-1, imgYRes-1, -imgXRes, -imgYRes, hDrawingDC, 0, 0, imgXRes, imgYRes, SRCCOPY);
613 SendMessage(hImageArea, WM_PAINT, 0, 0);
614 break;
615 }
616 break;
617 case IDM_IMAGEATTRIBUTES:
618 {
619 int retVal = attributesDlg();
620 if ((LOWORD(retVal)!=0)&&(HIWORD(retVal)!=0))
621 {
622 cropReversible(LOWORD(retVal), HIWORD(retVal), 0, 0);
623 updateCanvasAndScrollbars();
624 }
625 }
626 break;
627 case IDM_IMAGECHANGESIZE:
628 {
629 int retVal = changeSizeDlg();
630 if ((LOWORD(retVal)!=0)&&(HIWORD(retVal)!=0))
631 {
632 insertReversible(CopyImage(hBms[currInd], IMAGE_BITMAP, imgXRes*LOWORD(retVal)/100, imgYRes*HIWORD(retVal)/100, 0));
633 updateCanvasAndScrollbars();
634 }
635 }
636 break;
637 case IDM_IMAGEDRAWOPAQUE:
638 transpBg = 1-transpBg;
639 SendMessage(hToolSettings, WM_PAINT, 0, 0);
640 break;
641 case IDM_IMAGECROP:
642 insertReversible(CopyImage(hSelBm, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
643 updateCanvasAndScrollbars();
644 break;
645
646 case IDM_VIEWSHOWGRID:
647 showGrid = !showGrid;
648 break;
649 case IDM_VIEWSHOWMINIATURE:
650 showMiniature = !showMiniature;
651 if (showMiniature)
652 ShowWindow(hwndMiniature, SW_SHOW);
653 else
654 ShowWindow(hwndMiniature, SW_HIDE);
655 break;
656
657 case IDM_VIEWZOOM125:
658 ZoomTo(125);
659 break;
660 case IDM_VIEWZOOM25:
661 ZoomTo(250);
662 break;
663 case IDM_VIEWZOOM50:
664 ZoomTo(500);
665 break;
666 case IDM_VIEWZOOM100:
667 ZoomTo(1000);
668 break;
669 case IDM_VIEWZOOM200:
670 ZoomTo(2000);
671 break;
672 case IDM_VIEWZOOM400:
673 ZoomTo(4000);
674 break;
675 case IDM_VIEWZOOM800:
676 ZoomTo(8000);
677 break;
678 case ID_FREESEL:
679 selectTool(1);
680 break;
681 case ID_RECTSEL:
682 selectTool(2);
683 break;
684 case ID_RUBBER:
685 selectTool(3);
686 break;
687 case ID_FILL:
688 selectTool(4);
689 break;
690 case ID_COLOR:
691 selectTool(5);
692 break;
693 case ID_ZOOM:
694 selectTool(6);
695 break;
696 case ID_PEN:
697 selectTool(7);
698 break;
699 case ID_BRUSH:
700 selectTool(8);
701 break;
702 case ID_AIRBRUSH:
703 selectTool(9);
704 break;
705 case ID_TEXT:
706 selectTool(10);
707 break;
708 case ID_LINE:
709 selectTool(11);
710 break;
711 case ID_BEZIER:
712 selectTool(12);
713 break;
714 case ID_RECT:
715 selectTool(13);
716 break;
717 case ID_SHAPE:
718 selectTool(14);
719 break;
720 case ID_ELLIPSE:
721 selectTool(15);
722 break;
723 case ID_RRECT:
724 selectTool(16);
725 break;
726 }
727 break;
728 default:
729 return DefWindowProc (hwnd, message, wParam, lParam);
730 }
731
732 return 0;
733 }
734