[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 if ((HMENU)wParam != GetSubMenu(menu, 0))
226 break;
227 EnableMenuItem(menu, IDM_FILEASWALLPAPERPLANE, ENABLED_IF(isAFile));
228 EnableMenuItem(menu, IDM_FILEASWALLPAPERCENTERED, ENABLED_IF(isAFile));
229 EnableMenuItem(menu, IDM_FILEASWALLPAPERSTRETCHED, ENABLED_IF(isAFile));
230 RemoveMenu(menu, IDM_FILE1, MF_BYCOMMAND);
231 RemoveMenu(menu, IDM_FILE2, MF_BYCOMMAND);
232 RemoveMenu(menu, IDM_FILE3, MF_BYCOMMAND);
233 RemoveMenu(menu, IDM_FILE4, MF_BYCOMMAND);
234 if (!registrySettings.strFile1.IsEmpty())
235 {
236 RemoveMenu(menu, IDM_FILEMOSTRECENTLYUSEDFILE, MF_BYCOMMAND);
237 CPath pathFile1(registrySettings.strFile1);
238 pathFile1.CompactPathEx(30);
239 if (!registrySettings.strFile2.IsEmpty())
240 {
241 CPath pathFile2(registrySettings.strFile2);
242 pathFile2.CompactPathEx(30);
243 if (!registrySettings.strFile3.IsEmpty())
244 {
245 CPath pathFile3(registrySettings.strFile3);
246 pathFile3.CompactPathEx(30);
247 if (!registrySettings.strFile4.IsEmpty())
248 {
249 CPath pathFile4(registrySettings.strFile4);
250 pathFile4.CompactPathEx(30);
251 InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE4, _T("4 ") + pathFile4);
252 }
253 InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE3, _T("3 ") + pathFile3);
254 }
255 InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE2, _T("2 ") + pathFile2);
256 }
257 InsertMenu((HMENU)wParam, 17, MF_BYPOSITION | MF_STRING, IDM_FILE1, _T("1 ") + pathFile1);
258 }
259 break;
260 case 1: /* Edit menu */
261 EnableMenuItem(menu, IDM_EDITUNDO, ENABLED_IF(imageModel.HasUndoSteps()));
262 EnableMenuItem(menu, IDM_EDITREDO, ENABLED_IF(imageModel.HasRedoSteps()));
263 EnableMenuItem(menu, IDM_EDITCUT, ENABLED_IF(trueSelection));
264 EnableMenuItem(menu, IDM_EDITCOPY, ENABLED_IF(trueSelection));
265 EnableMenuItem(menu, IDM_EDITDELETESELECTION, ENABLED_IF(trueSelection));
266 EnableMenuItem(menu, IDM_EDITINVERTSELECTION, ENABLED_IF(trueSelection));
267 EnableMenuItem(menu, IDM_EDITCOPYTO, ENABLED_IF(trueSelection));
268 OpenClipboard();
269 EnableMenuItem(menu, IDM_EDITPASTE, ENABLED_IF(GetClipboardData(CF_BITMAP) != NULL));
270 CloseClipboard();
271 break;
272 case 2: /* View menu */
273 CheckMenuItem(menu, IDM_VIEWTOOLBOX, CHECKED_IF(toolBoxContainer.IsWindowVisible()));
274 CheckMenuItem(menu, IDM_VIEWCOLORPALETTE, CHECKED_IF(paletteWindow.IsWindowVisible()));
275 CheckMenuItem(menu, IDM_VIEWSTATUSBAR, CHECKED_IF(::IsWindowVisible(hStatusBar)));
276 CheckMenuItem(menu, IDM_FORMATICONBAR, CHECKED_IF(textEditWindow.IsWindowVisible()));
277 EnableMenuItem(menu, IDM_FORMATICONBAR, ENABLED_IF(toolsModel.GetActiveTool() == TOOL_TEXT));
278
279 CheckMenuItem(menu, IDM_VIEWSHOWGRID, CHECKED_IF(showGrid));
280 CheckMenuItem(menu, IDM_VIEWSHOWMINIATURE, CHECKED_IF(showMiniature));
281 break;
282 case 3: /* Image menu */
283 EnableMenuItem(menu, IDM_IMAGECROP, ENABLED_IF(selectionWindow.IsWindowVisible()));
284 CheckMenuItem(menu, IDM_IMAGEDRAWOPAQUE, CHECKED_IF(!toolsModel.IsBackgroundTransparent()));
285 break;
286 }
287
288 CheckMenuItem(menu, IDM_VIEWZOOM125, CHECKED_IF(toolsModel.GetZoom() == 125));
289 CheckMenuItem(menu, IDM_VIEWZOOM25, CHECKED_IF(toolsModel.GetZoom() == 250));
290 CheckMenuItem(menu, IDM_VIEWZOOM50, CHECKED_IF(toolsModel.GetZoom() == 500));
291 CheckMenuItem(menu, IDM_VIEWZOOM100, CHECKED_IF(toolsModel.GetZoom() == 1000));
292 CheckMenuItem(menu, IDM_VIEWZOOM200, CHECKED_IF(toolsModel.GetZoom() == 2000));
293 CheckMenuItem(menu, IDM_VIEWZOOM400, CHECKED_IF(toolsModel.GetZoom() == 4000));
294 CheckMenuItem(menu, IDM_VIEWZOOM800, CHECKED_IF(toolsModel.GetZoom() == 8000));
295
296 CheckMenuItem(menu, IDM_COLORSMODERNPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == 1));
297 CheckMenuItem(menu, IDM_COLORSOLDPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == 2));
298 return 0;
299 }
300
301 LRESULT CMainWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
302 {
303 int test[] = { LOWORD(lParam) - 260, LOWORD(lParam) - 140, LOWORD(lParam) - 20 };
304 SendMessage(hStatusBar, WM_SIZE, wParam, lParam);
305 SendMessage(hStatusBar, SB_SETPARTS, 3, (LPARAM)&test);
306 alignChildrenToMainWindow();
307 Invalidate(TRUE);
308 return 0;
309 }
310
311 LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
312 {
313 MINMAXINFO *mm = (LPMINMAXINFO) lParam;
314 mm->ptMinTrackSize.x = 330;
315 mm->ptMinTrackSize.y = 430;
316 return 0;
317 }
318
319 LRESULT CMainWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
320 {
321 SetCursor(LoadCursor(NULL, IDC_ARROW));
322 bHandled = FALSE;
323 return 0;
324 }
325
326 LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
327 {
328 if (wParam == VK_ESCAPE)
329 {
330 if (!imageArea.drawing)
331 {
332 /* Deselect */
333 if ((toolsModel.GetActiveTool() == TOOL_RECTSEL) || (toolsModel.GetActiveTool() == TOOL_FREESEL))
334 {
335 startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
336 whilePaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
337 endPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
338 selectionWindow.ShowWindow(SW_HIDE);
339 }
340 }
341 /* FIXME: also cancel current drawing underway */
342 }
343 return 0;
344 }
345
346 LRESULT CMainWindow::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
347 {
348 /* Redirect message to common controls */
349 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
350 SendMessage(hToolbar, WM_SYSCOLORCHANGE, 0, 0);
351 return 0;
352 }
353
354 LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
355 {
356 switch (LOWORD(wParam))
357 {
358 case IDM_HELPINFO:
359 {
360 HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON));
361 TCHAR infotitle[100];
362 TCHAR infotext[200];
363 LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle));
364 LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext));
365 ShellAbout(m_hWnd, infotitle, infotext, paintIcon);
366 DeleteObject(paintIcon);
367 break;
368 }
369 case IDM_HELPHELPTOPICS:
370 HtmlHelp(m_hWnd, _T("help\\Paint.chm"), 0, 0);
371 break;
372 case IDM_FILEEXIT:
373 SendMessage(WM_CLOSE, wParam, lParam);
374 break;
375 case IDM_FILENEW:
376 {
377 BOOL reset = TRUE;
378 if (!imageModel.IsImageSaved())
379 {
380 CString strProgramName;
381 strProgramName.LoadString(IDS_PROGRAMNAME);
382 CPath pathFileName(filepathname);
383 pathFileName.StripPath();
384 CString strSavePromptText;
385 strSavePromptText.Format(IDS_SAVEPROMPTTEXT, (LPCTSTR)pathFileName);
386 switch (MessageBox(strSavePromptText, strProgramName, MB_YESNOCANCEL | MB_ICONQUESTION))
387 {
388 case IDNO:
389 imageModel.imageSaved = TRUE; //TODO: move to ImageModel
390 break;
391 case IDYES:
392 saveImage(FALSE);
393 break;
394 case IDCANCEL:
395 reset = FALSE;
396 break;
397 }
398 }
399 if (reset && imageModel.IsImageSaved()) //TODO: move to ImageModel
400 {
401 imageModel.Clear();
402 imageModel.ClearHistory();
403 }
404 break;
405 }
406 case IDM_FILEOPEN:
407 if (GetOpenFileName(&ofn) != 0)
408 {
409 HBITMAP bmNew = NULL;
410 LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
411 if (bmNew != NULL)
412 {
413 UpdateApplicationProperties(bmNew, ofn.lpstrFile);
414 }
415 }
416 break;
417 case IDM_FILESAVE:
418 saveImage(TRUE);
419 break;
420 case IDM_FILESAVEAS:
421 saveImage(FALSE);
422 break;
423 case IDM_FILEPAGESETUP:
424 // DUMMY: Shows the dialog only, no functionality
425 PAGESETUPDLG psd;
426 ZeroMemory(&psd, sizeof(psd));
427 psd.lStructSize = sizeof(psd);
428 psd.hwndOwner = m_hWnd;
429 PageSetupDlg(&psd);
430 break;
431 case IDM_FILEPRINT:
432 // TODO: Test whether it actually works
433 PRINTDLG pd;
434 ZeroMemory(&pd, sizeof(pd));
435 pd.lStructSize = sizeof(pd);
436 pd.hwndOwner = m_hWnd;
437 pd.hDevMode = NULL; // freed by user
438 pd.hDevNames = NULL; // freed by user
439 pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
440 pd.nCopies = 1;
441 pd.nFromPage = 0xffff;
442 pd.nToPage = 0xffff;
443 pd.nMinPage = 1;
444 pd.nMaxPage = 0xffff;
445 if (PrintDlg(&pd) == TRUE)
446 {
447 BitBlt(pd.hDC, 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), imageModel.GetDC(), 0, 0, SRCCOPY);
448 DeleteDC(pd.hDC);
449 }
450 if (pd.hDevMode)
451 GlobalFree(pd.hDevMode);
452 if (pd.hDevNames)
453 GlobalFree(pd.hDevNames);
454 break;
455 case IDM_FILEASWALLPAPERPLANE:
456 RegistrySettings::SetWallpaper(filepathname, RegistrySettings::TILED);
457 break;
458 case IDM_FILEASWALLPAPERCENTERED:
459 RegistrySettings::SetWallpaper(filepathname, RegistrySettings::CENTERED);
460 break;
461 case IDM_FILEASWALLPAPERSTRETCHED:
462 RegistrySettings::SetWallpaper(filepathname, RegistrySettings::STRETCHED);
463 break;
464 case IDM_FILE1:
465 {
466 HBITMAP bmNew = NULL;
467 LoadDIBFromFile(&bmNew, registrySettings.strFile1, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
468 if (bmNew != NULL)
469 {
470 UpdateApplicationProperties(bmNew, registrySettings.strFile1);
471 }
472 break;
473 }
474 case IDM_FILE2:
475 {
476 HBITMAP bmNew = NULL;
477 LoadDIBFromFile(&bmNew, registrySettings.strFile2, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
478 if (bmNew != NULL)
479 {
480 UpdateApplicationProperties(bmNew, registrySettings.strFile2);
481 }
482 break;
483 }
484 case IDM_FILE3:
485 {
486 HBITMAP bmNew = NULL;
487 LoadDIBFromFile(&bmNew, registrySettings.strFile3, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
488 if (bmNew != NULL)
489 {
490 UpdateApplicationProperties(bmNew, registrySettings.strFile3);
491 }
492 break;
493 }
494 case IDM_FILE4:
495 {
496 HBITMAP bmNew = NULL;
497 LoadDIBFromFile(&bmNew, registrySettings.strFile4, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
498 if (bmNew != NULL)
499 {
500 UpdateApplicationProperties(bmNew, registrySettings.strFile4);
501 }
502 break;
503 }
504 case IDM_EDITUNDO:
505 imageModel.Undo();
506 imageArea.Invalidate(FALSE);
507 break;
508 case IDM_EDITREDO:
509 imageModel.Redo();
510 imageArea.Invalidate(FALSE);
511 break;
512 case IDM_EDITCOPY:
513 OpenClipboard();
514 EmptyClipboard();
515 SetClipboardData(CF_BITMAP, CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
516 CloseClipboard();
517 break;
518 case IDM_EDITCUT:
519 /* Copy */
520 SendMessage(WM_COMMAND, IDM_EDITCOPY, 0);
521 /* Delete selection */
522 SendMessage(WM_COMMAND, IDM_EDITDELETESELECTION, 0);
523 break;
524 case IDM_EDITPASTE:
525 OpenClipboard();
526 if (GetClipboardData(CF_BITMAP) != NULL)
527 {
528 InsertSelectionFromHBITMAP((HBITMAP) GetClipboardData(CF_BITMAP), m_hWnd);
529 }
530 CloseClipboard();
531 break;
532 case IDM_EDITDELETESELECTION:
533 {
534 /* remove selection window and already painted content using undo */
535 imageModel.Undo();
536 break;
537 }
538 case IDM_EDITSELECTALL:
539 {
540 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
541 SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
542 toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
543 //TODO: do this properly
544 startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
545 whilePaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
546 endPaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
547 break;
548 }
549 case IDM_EDITCOPYTO:
550 if (GetSaveFileName(&ofn) != 0)
551 SaveDIBToFile(selectionModel.GetBitmap(), ofn.lpstrFile, imageModel.GetDC(), NULL, NULL, fileHPPM, fileVPPM);
552 break;
553 case IDM_EDITPASTEFROM:
554 if (GetOpenFileName(&ofn) != 0)
555 {
556 HBITMAP bmNew = NULL;
557 LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
558 if (bmNew != NULL)
559 {
560 InsertSelectionFromHBITMAP(bmNew, m_hWnd);
561 DeleteObject(bmNew);
562 }
563 }
564 break;
565 case IDM_COLORSEDITPALETTE:
566 if (ChooseColor(&choosecolor))
567 paletteModel.SetFgColor(choosecolor.rgbResult);
568 break;
569 case IDM_COLORSMODERNPALETTE:
570 paletteModel.SelectPalette(1);
571 break;
572 case IDM_COLORSOLDPALETTE:
573 paletteModel.SelectPalette(2);
574 break;
575 case IDM_IMAGEINVERTCOLORS:
576 {
577 imageModel.InvertColors();
578 break;
579 }
580 case IDM_IMAGEDELETEIMAGE:
581 imageModel.CopyPrevious();
582 Rect(imageModel.GetDC(), 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE);
583 imageArea.Invalidate(FALSE);
584 break;
585 case IDM_IMAGEROTATEMIRROR:
586 switch (mirrorRotateDlg())
587 {
588 case 1: /* flip horizontally */
589 if (selectionWindow.IsWindowVisible())
590 selectionModel.FlipHorizontally();
591 else
592 imageModel.FlipHorizontally();
593 break;
594 case 2: /* flip vertically */
595 if (selectionWindow.IsWindowVisible())
596 selectionModel.FlipVertically();
597 else
598 imageModel.FlipVertically();
599 break;
600 case 3: /* rotate 90 degrees */
601 break;
602 case 4: /* rotate 180 degrees */
603 if (selectionWindow.IsWindowVisible())
604 selectionModel.RotateNTimes90Degrees(2);
605 else
606 imageModel.RotateNTimes90Degrees(2);
607 break;
608 case 5: /* rotate 270 degrees */
609 break;
610 }
611 break;
612 case IDM_IMAGEATTRIBUTES:
613 {
614 if (attributesDlg())
615 {
616 imageModel.Crop(widthSetInDlg, heightSetInDlg, 0, 0);
617 }
618 break;
619 }
620 case IDM_IMAGESTRETCHSKEW:
621 {
622 if (changeSizeDlg())
623 {
624 imageModel.StretchSkew(stretchSkew.percentage.x, stretchSkew.percentage.y,
625 stretchSkew.angle.x, stretchSkew.angle.y);
626 }
627 break;
628 }
629 case IDM_IMAGEDRAWOPAQUE:
630 toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
631 break;
632 case IDM_IMAGECROP:
633 imageModel.Insert((HBITMAP) CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
634 break;
635
636 case IDM_VIEWTOOLBOX:
637 toolBoxContainer.ShowWindow(toolBoxContainer.IsWindowVisible() ? SW_HIDE : SW_SHOW);
638 alignChildrenToMainWindow();
639 break;
640 case IDM_VIEWCOLORPALETTE:
641 paletteWindow.ShowWindow(paletteWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
642 alignChildrenToMainWindow();
643 break;
644 case IDM_VIEWSTATUSBAR:
645 ::ShowWindow(hStatusBar, ::IsWindowVisible(hStatusBar) ? SW_HIDE : SW_SHOW);
646 alignChildrenToMainWindow();
647 break;
648 case IDM_FORMATICONBAR:
649 textEditWindow.ShowWindow(textEditWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
650 break;
651 case IDM_VIEWSHOWGRID:
652 showGrid = !showGrid;
653 imageArea.Invalidate(FALSE);
654 break;
655 case IDM_VIEWSHOWMINIATURE:
656 showMiniature = !showMiniature;
657 miniature.ShowWindow(showMiniature ? SW_SHOW : SW_HIDE);
658 break;
659
660 case IDM_VIEWZOOM125:
661 zoomTo(125, 0, 0);
662 break;
663 case IDM_VIEWZOOM25:
664 zoomTo(250, 0, 0);
665 break;
666 case IDM_VIEWZOOM50:
667 zoomTo(500, 0, 0);
668 break;
669 case IDM_VIEWZOOM100:
670 zoomTo(1000, 0, 0);
671 break;
672 case IDM_VIEWZOOM200:
673 zoomTo(2000, 0, 0);
674 break;
675 case IDM_VIEWZOOM400:
676 zoomTo(4000, 0, 0);
677 break;
678 case IDM_VIEWZOOM800:
679 zoomTo(8000, 0, 0);
680 break;
681
682 case IDM_VIEWFULLSCREEN:
683 fullscreenWindow.ShowWindow(SW_SHOW);
684 ShowWindow(SW_HIDE);
685 break;
686 }
687 return 0;
688 }