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