[MSPAINT]
[reactos.git] / reactos / base / applications / mspaint / winproc.cpp
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/mspaint/winproc.cpp
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 "precomp.h"
13
14 #include "dialogs.h"
15
16 /* FUNCTIONS ********************************************************/
17
18 void
19 zoomTo(int newZoom, int mouseX, int mouseY)
20 {
21 RECT clientRectScrollbox;
22 RECT clientRectImageArea;
23 int x, y, w, h;
24 scrollboxWindow.GetClientRect(&clientRectScrollbox);
25 imageArea.GetClientRect(&clientRectImageArea);
26 w = clientRectImageArea.right * clientRectScrollbox.right / (clientRectImageArea.right * newZoom / toolsModel.GetZoom());
27 h = clientRectImageArea.bottom * clientRectScrollbox.bottom / (clientRectImageArea.bottom * newZoom / toolsModel.GetZoom());
28 x = max(0, min(clientRectImageArea.right - w, mouseX - w / 2)) * newZoom / toolsModel.GetZoom();
29 y = max(0, min(clientRectImageArea.bottom - h, mouseY - h / 2)) * newZoom / toolsModel.GetZoom();
30
31 toolsModel.SetZoom(newZoom);
32
33 selectionWindow.ShowWindow(SW_HIDE);
34 imageArea.MoveWindow(3, 3, imageModel.GetWidth() * toolsModel.GetZoom() / 1000, imageModel.GetHeight() * toolsModel.GetZoom() / 1000, FALSE);
35 scrollboxWindow.Invalidate(TRUE);
36 imageArea.Invalidate(FALSE);
37
38 scrollboxWindow.SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, x), 0);
39 scrollboxWindow.SendMessage(WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, y), 0);
40 }
41
42 void CMainWindow::alignChildrenToMainWindow()
43 {
44 int x, y, w, h;
45 RECT clientRect;
46 GetClientRect(&clientRect);
47
48 if (toolBoxContainer.IsWindowVisible())
49 {
50 x = 56;
51 w = clientRect.right - 56;
52 }
53 else
54 {
55 x = 0;
56 w = clientRect.right;
57 }
58 if (paletteWindow.IsWindowVisible())
59 {
60 y = 49;
61 h = clientRect.bottom - 49;
62 }
63 else
64 {
65 y = 3;
66 h = clientRect.bottom - 3;
67 }
68
69 scrollboxWindow.MoveWindow(x, y, w, ::IsWindowVisible(hStatusBar) ? h - 23 : h, TRUE);
70 paletteWindow.MoveWindow(x, 9, 255, 32, TRUE);
71 }
72
73 void CMainWindow::saveImage(BOOL overwrite)
74 {
75 if (isAFile && overwrite)
76 {
77 imageModel.SaveImage(filepathname);
78 }
79 else if (GetSaveFileName(&sfn) != 0)
80 {
81 imageModel.SaveImage(sfn.lpstrFile);
82 CString strTitle;
83 strTitle.Format(IDS_WINDOWTITLE, (LPCTSTR)sfn.lpstrFileTitle);
84 SetWindowText(strTitle);
85 isAFile = TRUE;
86 }
87 }
88
89 void CMainWindow::UpdateApplicationProperties(HBITMAP bitmap, LPCTSTR newfilepathname)
90 {
91 imageModel.Insert(bitmap);
92 CopyMemory(filepathname, newfilepathname, sizeof(filepathname));
93 CPath pathFileName(newfilepathname);
94 pathFileName.StripPath();
95 CString strTitle;
96 strTitle.Format(IDS_WINDOWTITLE, (LPCTSTR)pathFileName);
97 SetWindowText(strTitle);
98 imageModel.ClearHistory();
99 isAFile = TRUE;
100
101 registrySettings.SetMostRecentFile(newfilepathname);
102 }
103
104 void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
105 {
106 int width = GetDIBWidth(bitmap);
107 int height = GetDIBHeight(bitmap);
108 int curWidth = imageModel.GetWidth();
109 int curHeight = imageModel.GetHeight();
110
111 if (width > curWidth || height > curHeight)
112 {
113 BOOL shouldEnlarge = TRUE;
114
115 if (askBeforeEnlarging)
116 {
117 TCHAR programname[20];
118 TCHAR shouldEnlargePromptText[100];
119
120 LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
121 LoadString(hProgInstance, IDS_ENLARGEPROMPTTEXT, shouldEnlargePromptText, SIZEOF(shouldEnlargePromptText));
122
123 switch (MessageBox(shouldEnlargePromptText, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
124 {
125 case IDYES:
126 break;
127 case IDNO:
128 shouldEnlarge = FALSE;
129 break;
130 case IDCANCEL:
131 return;
132 }
133 }
134
135 if (shouldEnlarge)
136 {
137 if (width > curWidth)
138 curWidth = width;
139
140 if (height > curHeight)
141 curHeight = height;
142
143 imageModel.Crop(curWidth, curHeight, 0, 0);
144 }
145 }
146
147 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
148 SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
149 toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
150
151 imageModel.CopyPrevious();
152 selectionModel.InsertFromHBITMAP(bitmap);
153
154 placeSelWin();
155 selectionWindow.ShowWindow(SW_SHOW);
156 ForceRefreshSelectionContents();
157 }
158
159 LRESULT CMainWindow::OnDropFiles(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
160 {
161 HDROP drophandle;
162 TCHAR droppedfile[MAX_PATH];
163 HBITMAP bmNew = NULL;
164 drophandle = (HDROP)wParam;
165 DragQueryFile(drophandle, 0, droppedfile, SIZEOF(droppedfile));
166 DragFinish(drophandle);
167 LoadDIBFromFile(&bmNew, droppedfile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
168 if (bmNew != NULL)
169 {
170 UpdateApplicationProperties(bmNew, droppedfile);
171 }
172 return 0;
173 }
174
175 LRESULT CMainWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
176 {
177 SendMessage(WM_SETICON, ICON_BIG, (LPARAM) LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON)));
178 SendMessage(WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON)));
179 return 0;
180 }
181
182 LRESULT CMainWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
183 {
184 GetWindowPlacement(&(registrySettings.WindowPlacement));
185 PostQuitMessage(0); /* send a WM_QUIT to the message queue */
186 return 0;
187 }
188
189 LRESULT CMainWindow::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
190 {
191 if (!imageModel.IsImageSaved())
192 {
193 CString strProgramName;
194 strProgramName.LoadString(IDS_PROGRAMNAME);
195 CPath pathFileName(filepathname);
196 pathFileName.StripPath();
197 CString strSavePromptText;
198 strSavePromptText.Format(IDS_SAVEPROMPTTEXT, (LPCTSTR)pathFileName);
199 switch (MessageBox(strSavePromptText, strProgramName, MB_YESNOCANCEL | MB_ICONQUESTION))
200 {
201 case IDNO:
202 DestroyWindow();
203 break;
204 case IDYES:
205 saveImage(FALSE);
206 if (imageModel.IsImageSaved())
207 DestroyWindow();
208 break;
209 }
210 }
211 else
212 {
213 DestroyWindow();
214 }
215 return 0;
216 }
217
218 LRESULT CMainWindow::OnInitMenuPopup(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
219 {
220 HMENU menu = GetMenu();
221 BOOL trueSelection = (selectionWindow.IsWindowVisible() && ((toolsModel.GetActiveTool() == TOOL_FREESEL) || (toolsModel.GetActiveTool() == TOOL_RECTSEL)));
222 switch (lParam)
223 {
224 case 0: /* File menu */
225 EnableMenuItem(menu, IDM_FILEASWALLPAPERPLANE, ENABLED_IF(isAFile));
226 EnableMenuItem(menu, IDM_FILEASWALLPAPERCENTERED, ENABLED_IF(isAFile));
227 EnableMenuItem(menu, IDM_FILEASWALLPAPERSTRETCHED, ENABLED_IF(isAFile));
228 RemoveMenu(menu, IDM_FILE1, MF_BYCOMMAND);
229 RemoveMenu(menu, IDM_FILE2, MF_BYCOMMAND);
230 RemoveMenu(menu, IDM_FILE3, MF_BYCOMMAND);
231 RemoveMenu(menu, IDM_FILE4, MF_BYCOMMAND);
232 if (!registrySettings.strFile1.IsEmpty())
233 {
234 RemoveMenu(menu, IDM_FILEMOSTRECENTLYUSEDFILE, MF_BYCOMMAND);
235 CPath pathFile1(registrySettings.strFile1);
236 pathFile1.CompactPathEx(30);
237 if (!registrySettings.strFile2.IsEmpty())
238 {
239 CPath pathFile2(registrySettings.strFile2);
240 pathFile2.CompactPathEx(30);
241 if (!registrySettings.strFile3.IsEmpty())
242 {
243 CPath pathFile3(registrySettings.strFile3);
244 pathFile3.CompactPathEx(30);
245 if (!registrySettings.strFile4.IsEmpty())
246 {
247 CPath pathFile4(registrySettings.strFile4);
248 pathFile4.CompactPathEx(30);
249 InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE4, _T("4 ") + pathFile4);
250 }
251 InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE3, _T("3 ") + pathFile3);
252 }
253 InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE2, _T("2 ") + pathFile2);
254 }
255 InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE1, _T("1 ") + pathFile1);
256 }
257 break;
258 case 1: /* Edit menu */
259 EnableMenuItem(menu, IDM_EDITUNDO, ENABLED_IF(imageModel.HasUndoSteps()));
260 EnableMenuItem(menu, IDM_EDITREDO, ENABLED_IF(imageModel.HasRedoSteps()));
261 EnableMenuItem(menu, IDM_EDITCUT, ENABLED_IF(trueSelection));
262 EnableMenuItem(menu, IDM_EDITCOPY, ENABLED_IF(trueSelection));
263 EnableMenuItem(menu, IDM_EDITDELETESELECTION, ENABLED_IF(trueSelection));
264 EnableMenuItem(menu, IDM_EDITINVERTSELECTION, ENABLED_IF(trueSelection));
265 EnableMenuItem(menu, IDM_EDITCOPYTO, ENABLED_IF(trueSelection));
266 OpenClipboard();
267 EnableMenuItem(menu, IDM_EDITPASTE, ENABLED_IF(GetClipboardData(CF_BITMAP) != NULL));
268 CloseClipboard();
269 break;
270 case 2: /* View menu */
271 CheckMenuItem(menu, IDM_VIEWTOOLBOX, CHECKED_IF(toolBoxContainer.IsWindowVisible()));
272 CheckMenuItem(menu, IDM_VIEWCOLORPALETTE, CHECKED_IF(paletteWindow.IsWindowVisible()));
273 CheckMenuItem(menu, IDM_VIEWSTATUSBAR, CHECKED_IF(::IsWindowVisible(hStatusBar)));
274 CheckMenuItem(menu, IDM_FORMATICONBAR, CHECKED_IF(textEditWindow.IsWindowVisible()));
275 EnableMenuItem(menu, IDM_FORMATICONBAR, ENABLED_IF(toolsModel.GetActiveTool() == TOOL_TEXT));
276
277 CheckMenuItem(menu, IDM_VIEWSHOWGRID, CHECKED_IF(showGrid));
278 CheckMenuItem(menu, IDM_VIEWSHOWMINIATURE, CHECKED_IF(showMiniature));
279 break;
280 case 3: /* Image menu */
281 EnableMenuItem(menu, IDM_IMAGECROP, ENABLED_IF(selectionWindow.IsWindowVisible()));
282 CheckMenuItem(menu, IDM_IMAGEDRAWOPAQUE, CHECKED_IF(!toolsModel.IsBackgroundTransparent()));
283 break;
284 }
285
286 CheckMenuItem(menu, IDM_VIEWZOOM125, CHECKED_IF(toolsModel.GetZoom() == 125));
287 CheckMenuItem(menu, IDM_VIEWZOOM25, CHECKED_IF(toolsModel.GetZoom() == 250));
288 CheckMenuItem(menu, IDM_VIEWZOOM50, CHECKED_IF(toolsModel.GetZoom() == 500));
289 CheckMenuItem(menu, IDM_VIEWZOOM100, CHECKED_IF(toolsModel.GetZoom() == 1000));
290 CheckMenuItem(menu, IDM_VIEWZOOM200, CHECKED_IF(toolsModel.GetZoom() == 2000));
291 CheckMenuItem(menu, IDM_VIEWZOOM400, CHECKED_IF(toolsModel.GetZoom() == 4000));
292 CheckMenuItem(menu, IDM_VIEWZOOM800, CHECKED_IF(toolsModel.GetZoom() == 8000));
293
294 CheckMenuItem(menu, IDM_COLORSMODERNPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == 1));
295 CheckMenuItem(menu, IDM_COLORSOLDPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == 2));
296 return 0;
297 }
298
299 LRESULT CMainWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
300 {
301 int test[] = { LOWORD(lParam) - 260, LOWORD(lParam) - 140, LOWORD(lParam) - 20 };
302 SendMessage(hStatusBar, WM_SIZE, wParam, lParam);
303 SendMessage(hStatusBar, SB_SETPARTS, 3, (LPARAM)&test);
304 alignChildrenToMainWindow();
305 Invalidate(TRUE);
306 return 0;
307 }
308
309 LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
310 {
311 MINMAXINFO *mm = (LPMINMAXINFO) lParam;
312 mm->ptMinTrackSize.x = 330;
313 mm->ptMinTrackSize.y = 430;
314 return 0;
315 }
316
317 LRESULT CMainWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
318 {
319 SetCursor(LoadCursor(NULL, IDC_ARROW));
320 bHandled = FALSE;
321 return 0;
322 }
323
324 LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
325 {
326 if (wParam == VK_ESCAPE)
327 {
328 if (!imageArea.drawing)
329 {
330 /* Deselect */
331 if ((toolsModel.GetActiveTool() == TOOL_RECTSEL) || (toolsModel.GetActiveTool() == TOOL_FREESEL))
332 {
333 startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
334 whilePaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
335 endPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
336 selectionWindow.ShowWindow(SW_HIDE);
337 }
338 }
339 /* FIXME: also cancel current drawing underway */
340 }
341 return 0;
342 }
343
344 LRESULT CMainWindow::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
345 {
346 /* Redirect message to common controls */
347 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
348 SendMessage(hToolbar, WM_SYSCOLORCHANGE, 0, 0);
349 return 0;
350 }
351
352 LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
353 {
354 switch (LOWORD(wParam))
355 {
356 case IDM_HELPINFO:
357 {
358 HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON));
359 TCHAR infotitle[100];
360 TCHAR infotext[200];
361 LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle));
362 LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext));
363 ShellAbout(m_hWnd, infotitle, infotext, paintIcon);
364 DeleteObject(paintIcon);
365 break;
366 }
367 case IDM_HELPHELPTOPICS:
368 HtmlHelp(m_hWnd, _T("help\\Paint.chm"), 0, 0);
369 break;
370 case IDM_FILEEXIT:
371 SendMessage(WM_CLOSE, wParam, lParam);
372 break;
373 case IDM_FILENEW:
374 {
375 BOOL reset = TRUE;
376 if (!imageModel.IsImageSaved())
377 {
378 CString strProgramName;
379 strProgramName.LoadString(IDS_PROGRAMNAME);
380 CPath pathFileName(filepathname);
381 pathFileName.StripPath();
382 CString strSavePromptText;
383 strSavePromptText.Format(IDS_SAVEPROMPTTEXT, (LPCTSTR)pathFileName);
384 switch (MessageBox(strSavePromptText, strProgramName, MB_YESNOCANCEL | MB_ICONQUESTION))
385 {
386 case IDNO:
387 imageModel.imageSaved = TRUE; //TODO: move to ImageModel
388 break;
389 case IDYES:
390 saveImage(FALSE);
391 break;
392 case IDCANCEL:
393 reset = FALSE;
394 break;
395 }
396 }
397 if (reset && imageModel.IsImageSaved()) //TODO: move to ImageModel
398 {
399 imageModel.Clear();
400 imageModel.ClearHistory();
401 }
402 break;
403 }
404 case IDM_FILEOPEN:
405 if (GetOpenFileName(&ofn) != 0)
406 {
407 HBITMAP bmNew = NULL;
408 LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
409 if (bmNew != NULL)
410 {
411 UpdateApplicationProperties(bmNew, ofn.lpstrFile);
412 }
413 }
414 break;
415 case IDM_FILESAVE:
416 saveImage(TRUE);
417 break;
418 case IDM_FILESAVEAS:
419 saveImage(FALSE);
420 break;
421 case IDM_FILEPAGESETUP:
422 // DUMMY: Shows the dialog only, no functionality
423 PAGESETUPDLG psd;
424 ZeroMemory(&psd, sizeof(psd));
425 psd.lStructSize = sizeof(psd);
426 psd.hwndOwner = m_hWnd;
427 PageSetupDlg(&psd);
428 break;
429 case IDM_FILEPRINT:
430 // TODO: Test whether it actually works
431 PRINTDLG pd;
432 ZeroMemory(&pd, sizeof(pd));
433 pd.lStructSize = sizeof(pd);
434 pd.hwndOwner = m_hWnd;
435 pd.hDevMode = NULL; // freed by user
436 pd.hDevNames = NULL; // freed by user
437 pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
438 pd.nCopies = 1;
439 pd.nFromPage = 0xffff;
440 pd.nToPage = 0xffff;
441 pd.nMinPage = 1;
442 pd.nMaxPage = 0xffff;
443 if (PrintDlg(&pd) == TRUE)
444 {
445 BitBlt(pd.hDC, 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), imageModel.GetDC(), 0, 0, SRCCOPY);
446 DeleteDC(pd.hDC);
447 }
448 if (pd.hDevMode)
449 GlobalFree(pd.hDevMode);
450 if (pd.hDevNames)
451 GlobalFree(pd.hDevNames);
452 break;
453 case IDM_FILEASWALLPAPERPLANE:
454 RegistrySettings::SetWallpaper(filepathname, RegistrySettings::TILED);
455 break;
456 case IDM_FILEASWALLPAPERCENTERED:
457 RegistrySettings::SetWallpaper(filepathname, RegistrySettings::CENTERED);
458 break;
459 case IDM_FILEASWALLPAPERSTRETCHED:
460 RegistrySettings::SetWallpaper(filepathname, RegistrySettings::STRETCHED);
461 break;
462 case IDM_FILE1:
463 {
464 HBITMAP bmNew = NULL;
465 LoadDIBFromFile(&bmNew, registrySettings.strFile1, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
466 if (bmNew != NULL)
467 {
468 UpdateApplicationProperties(bmNew, registrySettings.strFile1);
469 }
470 break;
471 }
472 case IDM_FILE2:
473 {
474 HBITMAP bmNew = NULL;
475 LoadDIBFromFile(&bmNew, registrySettings.strFile2, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
476 if (bmNew != NULL)
477 {
478 UpdateApplicationProperties(bmNew, registrySettings.strFile2);
479 }
480 break;
481 }
482 case IDM_FILE3:
483 {
484 HBITMAP bmNew = NULL;
485 LoadDIBFromFile(&bmNew, registrySettings.strFile3, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
486 if (bmNew != NULL)
487 {
488 UpdateApplicationProperties(bmNew, registrySettings.strFile3);
489 }
490 break;
491 }
492 case IDM_FILE4:
493 {
494 HBITMAP bmNew = NULL;
495 LoadDIBFromFile(&bmNew, registrySettings.strFile4, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
496 if (bmNew != NULL)
497 {
498 UpdateApplicationProperties(bmNew, registrySettings.strFile4);
499 }
500 break;
501 }
502 case IDM_EDITUNDO:
503 imageModel.Undo();
504 imageArea.Invalidate(FALSE);
505 break;
506 case IDM_EDITREDO:
507 imageModel.Redo();
508 imageArea.Invalidate(FALSE);
509 break;
510 case IDM_EDITCOPY:
511 OpenClipboard();
512 EmptyClipboard();
513 SetClipboardData(CF_BITMAP, CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
514 CloseClipboard();
515 break;
516 case IDM_EDITCUT:
517 /* Copy */
518 SendMessage(WM_COMMAND, IDM_EDITCOPY, 0);
519 /* Delete selection */
520 SendMessage(WM_COMMAND, IDM_EDITDELETESELECTION, 0);
521 break;
522 case IDM_EDITPASTE:
523 OpenClipboard();
524 if (GetClipboardData(CF_BITMAP) != NULL)
525 {
526 InsertSelectionFromHBITMAP((HBITMAP) GetClipboardData(CF_BITMAP), m_hWnd);
527 }
528 CloseClipboard();
529 break;
530 case IDM_EDITDELETESELECTION:
531 {
532 /* remove selection window and already painted content using undo */
533 imageModel.Undo();
534 break;
535 }
536 case IDM_EDITSELECTALL:
537 {
538 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
539 SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
540 toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
541 //TODO: do this properly
542 startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
543 whilePaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
544 endPaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
545 break;
546 }
547 case IDM_EDITCOPYTO:
548 if (GetSaveFileName(&ofn) != 0)
549 SaveDIBToFile(selectionModel.GetBitmap(), ofn.lpstrFile, imageModel.GetDC(), NULL, NULL, fileHPPM, fileVPPM);
550 break;
551 case IDM_EDITPASTEFROM:
552 if (GetOpenFileName(&ofn) != 0)
553 {
554 HBITMAP bmNew = NULL;
555 LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
556 if (bmNew != NULL)
557 {
558 InsertSelectionFromHBITMAP(bmNew, m_hWnd);
559 DeleteObject(bmNew);
560 }
561 }
562 break;
563 case IDM_COLORSEDITPALETTE:
564 if (ChooseColor(&choosecolor))
565 paletteModel.SetFgColor(choosecolor.rgbResult);
566 break;
567 case IDM_COLORSMODERNPALETTE:
568 paletteModel.SelectPalette(1);
569 break;
570 case IDM_COLORSOLDPALETTE:
571 paletteModel.SelectPalette(2);
572 break;
573 case IDM_IMAGEINVERTCOLORS:
574 {
575 imageModel.InvertColors();
576 break;
577 }
578 case IDM_IMAGEDELETEIMAGE:
579 imageModel.CopyPrevious();
580 Rect(imageModel.GetDC(), 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE);
581 imageArea.Invalidate(FALSE);
582 break;
583 case IDM_IMAGEROTATEMIRROR:
584 switch (mirrorRotateDlg())
585 {
586 case 1: /* flip horizontally */
587 if (selectionWindow.IsWindowVisible())
588 selectionModel.FlipHorizontally();
589 else
590 imageModel.FlipHorizontally();
591 break;
592 case 2: /* flip vertically */
593 if (selectionWindow.IsWindowVisible())
594 selectionModel.FlipVertically();
595 else
596 imageModel.FlipVertically();
597 break;
598 case 3: /* rotate 90 degrees */
599 break;
600 case 4: /* rotate 180 degrees */
601 if (selectionWindow.IsWindowVisible())
602 selectionModel.RotateNTimes90Degrees(2);
603 else
604 imageModel.RotateNTimes90Degrees(2);
605 break;
606 case 5: /* rotate 270 degrees */
607 break;
608 }
609 break;
610 case IDM_IMAGEATTRIBUTES:
611 {
612 if (attributesDlg())
613 {
614 imageModel.Crop(widthSetInDlg, heightSetInDlg, 0, 0);
615 }
616 break;
617 }
618 case IDM_IMAGESTRETCHSKEW:
619 {
620 if (changeSizeDlg())
621 {
622 imageModel.StretchSkew(stretchSkew.percentage.x, stretchSkew.percentage.y,
623 stretchSkew.angle.x, stretchSkew.angle.y);
624 }
625 break;
626 }
627 case IDM_IMAGEDRAWOPAQUE:
628 toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
629 break;
630 case IDM_IMAGECROP:
631 imageModel.Insert((HBITMAP) CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
632 break;
633
634 case IDM_VIEWTOOLBOX:
635 toolBoxContainer.ShowWindow(toolBoxContainer.IsWindowVisible() ? SW_HIDE : SW_SHOW);
636 alignChildrenToMainWindow();
637 break;
638 case IDM_VIEWCOLORPALETTE:
639 paletteWindow.ShowWindow(paletteWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
640 alignChildrenToMainWindow();
641 break;
642 case IDM_VIEWSTATUSBAR:
643 ::ShowWindow(hStatusBar, ::IsWindowVisible(hStatusBar) ? SW_HIDE : SW_SHOW);
644 alignChildrenToMainWindow();
645 break;
646 case IDM_FORMATICONBAR:
647 textEditWindow.ShowWindow(textEditWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
648 break;
649 case IDM_VIEWSHOWGRID:
650 showGrid = !showGrid;
651 imageArea.Invalidate(FALSE);
652 break;
653 case IDM_VIEWSHOWMINIATURE:
654 showMiniature = !showMiniature;
655 miniature.ShowWindow(showMiniature ? SW_SHOW : SW_HIDE);
656 break;
657
658 case IDM_VIEWZOOM125:
659 zoomTo(125, 0, 0);
660 break;
661 case IDM_VIEWZOOM25:
662 zoomTo(250, 0, 0);
663 break;
664 case IDM_VIEWZOOM50:
665 zoomTo(500, 0, 0);
666 break;
667 case IDM_VIEWZOOM100:
668 zoomTo(1000, 0, 0);
669 break;
670 case IDM_VIEWZOOM200:
671 zoomTo(2000, 0, 0);
672 break;
673 case IDM_VIEWZOOM400:
674 zoomTo(4000, 0, 0);
675 break;
676 case IDM_VIEWZOOM800:
677 zoomTo(8000, 0, 0);
678 break;
679
680 case IDM_VIEWFULLSCREEN:
681 fullscreenWindow.ShowWindow(SW_SHOW);
682 ShowWindow(SW_HIDE);
683 break;
684 }
685 return 0;
686 }