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