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