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