Minor changes for ATAPI Srb Functions
[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 */
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 TCHAR tempstr[1000];
82 TCHAR resstr[100];
83 imageModel.SaveImage(sfn.lpstrFile);
84 CopyMemory(filename, sfn.lpstrFileTitle, sizeof(filename));
85 CopyMemory(filepathname, sfn.lpstrFile, sizeof(filepathname));
86 LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
87 _stprintf(tempstr, resstr, filename);
88 SetWindowText(tempstr);
89 isAFile = TRUE;
90 }
91 }
92
93 void CMainWindow::UpdateApplicationProperties(HBITMAP bitmap, LPTSTR newfilename, LPTSTR newfilepathname)
94 {
95 TCHAR tempstr[1000];
96 TCHAR resstr[100];
97 imageModel.Insert(bitmap);
98 CopyMemory(filename, newfilename, sizeof(filename));
99 CopyMemory(filepathname, newfilepathname, sizeof(filepathname));
100 LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
101 _stprintf(tempstr, resstr, filename);
102 SetWindowText(tempstr);
103 imageModel.ClearHistory();
104 isAFile = TRUE;
105 }
106
107 void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
108 {
109 int width = GetDIBWidth(bitmap);
110 int height = GetDIBHeight(bitmap);
111 int curWidth = imageModel.GetWidth();
112 int curHeight = imageModel.GetHeight();
113
114 if (width > curWidth || height > curHeight)
115 {
116 BOOL shouldEnlarge = TRUE;
117
118 if (askBeforeEnlarging)
119 {
120 TCHAR programname[20];
121 TCHAR shouldEnlargePromptText[100];
122
123 LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
124 LoadString(hProgInstance, IDS_ENLARGEPROMPTTEXT, shouldEnlargePromptText, SIZEOF(shouldEnlargePromptText));
125
126 switch (MessageBox(shouldEnlargePromptText, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
127 {
128 case IDYES:
129 break;
130 case IDNO:
131 shouldEnlarge = FALSE;
132 break;
133 case IDCANCEL:
134 return;
135 }
136 }
137
138 if (shouldEnlarge)
139 {
140 if (width > curWidth)
141 curWidth = width;
142
143 if (height > curHeight)
144 curHeight = height;
145
146 imageModel.Crop(curWidth, curHeight, 0, 0);
147 }
148 }
149
150 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
151 SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
152 toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
153
154 imageModel.CopyPrevious();
155 selectionModel.InsertFromHBITMAP(bitmap);
156
157 placeSelWin();
158 selectionWindow.ShowWindow(SW_SHOW);
159 ForceRefreshSelectionContents();
160 }
161
162 LRESULT CMainWindow::OnDropFiles(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
163 {
164 HDROP drophandle;
165 TCHAR droppedfile[MAX_PATH];
166 HBITMAP bmNew = NULL;
167 drophandle = (HDROP)wParam;
168 DragQueryFile(drophandle, 0, droppedfile, SIZEOF(droppedfile));
169 DragFinish(drophandle);
170 LoadDIBFromFile(&bmNew, droppedfile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
171 if (bmNew != NULL)
172 {
173 TCHAR *pathend;
174 pathend = _tcsrchr(droppedfile, '\\');
175 pathend++;
176 UpdateApplicationProperties(bmNew, pathend, pathend);
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 TCHAR programname[20];
200 TCHAR saveprompttext[100];
201 TCHAR temptext[500];
202 LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
203 LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, saveprompttext, SIZEOF(saveprompttext));
204 _stprintf(temptext, saveprompttext, filename);
205 switch (MessageBox(temptext, programname, 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 EnableMenuItem(menu, IDM_FILEASWALLPAPERPLANE, ENABLED_IF(isAFile));
232 EnableMenuItem(menu, IDM_FILEASWALLPAPERCENTERED, ENABLED_IF(isAFile));
233 EnableMenuItem(menu, IDM_FILEASWALLPAPERSTRETCHED, ENABLED_IF(isAFile));
234 break;
235 case 1: /* Edit menu */
236 EnableMenuItem(menu, IDM_EDITUNDO, ENABLED_IF(imageModel.HasUndoSteps()));
237 EnableMenuItem(menu, IDM_EDITREDO, ENABLED_IF(imageModel.HasRedoSteps()));
238 EnableMenuItem(menu, IDM_EDITCUT, ENABLED_IF(trueSelection));
239 EnableMenuItem(menu, IDM_EDITCOPY, ENABLED_IF(trueSelection));
240 EnableMenuItem(menu, IDM_EDITDELETESELECTION, ENABLED_IF(trueSelection));
241 EnableMenuItem(menu, IDM_EDITINVERTSELECTION, ENABLED_IF(trueSelection));
242 EnableMenuItem(menu, IDM_EDITCOPYTO, ENABLED_IF(trueSelection));
243 OpenClipboard();
244 EnableMenuItem(menu, IDM_EDITPASTE, ENABLED_IF(GetClipboardData(CF_BITMAP) != NULL));
245 CloseClipboard();
246 break;
247 case 2: /* View menu */
248 CheckMenuItem(menu, IDM_VIEWTOOLBOX, CHECKED_IF(toolBoxContainer.IsWindowVisible()));
249 CheckMenuItem(menu, IDM_VIEWCOLORPALETTE, CHECKED_IF(paletteWindow.IsWindowVisible()));
250 CheckMenuItem(menu, IDM_VIEWSTATUSBAR, CHECKED_IF(::IsWindowVisible(hStatusBar)));
251 CheckMenuItem(menu, IDM_FORMATICONBAR, CHECKED_IF(textEditWindow.IsWindowVisible()));
252 EnableMenuItem(menu, IDM_FORMATICONBAR, ENABLED_IF(toolsModel.GetActiveTool() == TOOL_TEXT));
253
254 CheckMenuItem(menu, IDM_VIEWSHOWGRID, CHECKED_IF(showGrid));
255 CheckMenuItem(menu, IDM_VIEWSHOWMINIATURE, CHECKED_IF(showMiniature));
256 break;
257 case 3: /* Image menu */
258 EnableMenuItem(menu, IDM_IMAGECROP, ENABLED_IF(selectionWindow.IsWindowVisible()));
259 CheckMenuItem(menu, IDM_IMAGEDRAWOPAQUE, CHECKED_IF(!toolsModel.IsBackgroundTransparent()));
260 break;
261 }
262
263 CheckMenuItem(menu, IDM_VIEWZOOM125, CHECKED_IF(toolsModel.GetZoom() == 125));
264 CheckMenuItem(menu, IDM_VIEWZOOM25, CHECKED_IF(toolsModel.GetZoom() == 250));
265 CheckMenuItem(menu, IDM_VIEWZOOM50, CHECKED_IF(toolsModel.GetZoom() == 500));
266 CheckMenuItem(menu, IDM_VIEWZOOM100, CHECKED_IF(toolsModel.GetZoom() == 1000));
267 CheckMenuItem(menu, IDM_VIEWZOOM200, CHECKED_IF(toolsModel.GetZoom() == 2000));
268 CheckMenuItem(menu, IDM_VIEWZOOM400, CHECKED_IF(toolsModel.GetZoom() == 4000));
269 CheckMenuItem(menu, IDM_VIEWZOOM800, CHECKED_IF(toolsModel.GetZoom() == 8000));
270
271 CheckMenuItem(menu, IDM_COLORSMODERNPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == 1));
272 CheckMenuItem(menu, IDM_COLORSOLDPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == 2));
273 return 0;
274 }
275
276 LRESULT CMainWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
277 {
278 int test[] = { LOWORD(lParam) - 260, LOWORD(lParam) - 140, LOWORD(lParam) - 20 };
279 SendMessage(hStatusBar, WM_SIZE, wParam, lParam);
280 SendMessage(hStatusBar, SB_SETPARTS, 3, (LPARAM)&test);
281 alignChildrenToMainWindow();
282 Invalidate(TRUE);
283 return 0;
284 }
285
286 LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
287 {
288 MINMAXINFO *mm = (LPMINMAXINFO) lParam;
289 mm->ptMinTrackSize.x = 330;
290 mm->ptMinTrackSize.y = 430;
291 return 0;
292 }
293
294 LRESULT CMainWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
295 {
296 SetCursor(LoadCursor(NULL, IDC_ARROW));
297 bHandled = FALSE;
298 return 0;
299 }
300
301 LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
302 {
303 if (wParam == VK_ESCAPE)
304 {
305 if (!imageArea.drawing)
306 {
307 /* Deselect */
308 if ((toolsModel.GetActiveTool() == TOOL_RECTSEL) || (toolsModel.GetActiveTool() == TOOL_FREESEL))
309 {
310 startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
311 whilePaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
312 endPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
313 selectionWindow.ShowWindow(SW_HIDE);
314 }
315 }
316 /* FIXME: also cancel current drawing underway */
317 }
318 return 0;
319 }
320
321 LRESULT CMainWindow::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
322 {
323 /* Redirect message to common controls */
324 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
325 SendMessage(hToolbar, WM_SYSCOLORCHANGE, 0, 0);
326 return 0;
327 }
328
329 LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
330 {
331 switch (LOWORD(wParam))
332 {
333 case IDM_HELPINFO:
334 {
335 HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON));
336 TCHAR infotitle[100];
337 TCHAR infotext[200];
338 LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle));
339 LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext));
340 ShellAbout(m_hWnd, infotitle, infotext, paintIcon);
341 DeleteObject(paintIcon);
342 break;
343 }
344 case IDM_HELPHELPTOPICS:
345 HtmlHelp(m_hWnd, _T("help\\Paint.chm"), 0, 0);
346 break;
347 case IDM_FILEEXIT:
348 SendMessage(WM_CLOSE, wParam, lParam);
349 break;
350 case IDM_FILENEW:
351 {
352 BOOL reset = TRUE;
353 if (!imageModel.IsImageSaved())
354 {
355 TCHAR programname[20];
356 TCHAR saveprompttext[100];
357 TCHAR temptext[500];
358 LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
359 LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, saveprompttext, SIZEOF(saveprompttext));
360 _stprintf(temptext, saveprompttext, filename);
361 switch (MessageBox(temptext, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
362 {
363 case IDNO:
364 imageModel.imageSaved = TRUE; //TODO: move to ImageModel
365 break;
366 case IDYES:
367 saveImage(FALSE);
368 break;
369 case IDCANCEL:
370 reset = FALSE;
371 break;
372 }
373 }
374 if (reset && imageModel.IsImageSaved()) //TODO: move to ImageModel
375 {
376 imageModel.Clear();
377 imageModel.ClearHistory();
378 }
379 break;
380 }
381 case IDM_FILEOPEN:
382 if (GetOpenFileName(&ofn) != 0)
383 {
384 HBITMAP bmNew = NULL;
385 LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
386 if (bmNew != NULL)
387 {
388 UpdateApplicationProperties(bmNew, ofn.lpstrFileTitle, ofn.lpstrFileTitle);
389 }
390 }
391 break;
392 case IDM_FILESAVE:
393 saveImage(TRUE);
394 break;
395 case IDM_FILESAVEAS:
396 saveImage(FALSE);
397 break;
398 case IDM_FILEPAGESETUP:
399 // DUMMY: Shows the dialog only, no functionality
400 PAGESETUPDLG psd;
401 ZeroMemory(&psd, sizeof(psd));
402 psd.lStructSize = sizeof(psd);
403 psd.hwndOwner = m_hWnd;
404 PageSetupDlg(&psd);
405 break;
406 case IDM_FILEPRINT:
407 // TODO: Test whether it actually works
408 PRINTDLG pd;
409 ZeroMemory(&pd, sizeof(pd));
410 pd.lStructSize = sizeof(pd);
411 pd.hwndOwner = m_hWnd;
412 pd.hDevMode = NULL; // freed by user
413 pd.hDevNames = NULL; // freed by user
414 pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
415 pd.nCopies = 1;
416 pd.nFromPage = 0xffff;
417 pd.nToPage = 0xffff;
418 pd.nMinPage = 1;
419 pd.nMaxPage = 0xffff;
420 if (PrintDlg(&pd) == TRUE)
421 {
422 BitBlt(pd.hDC, 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), imageModel.GetDC(), 0, 0, SRCCOPY);
423 DeleteDC(pd.hDC);
424 }
425 if (pd.hDevMode)
426 GlobalFree(pd.hDevMode);
427 if (pd.hDevNames)
428 GlobalFree(pd.hDevNames);
429 break;
430 case IDM_FILEASWALLPAPERPLANE:
431 RegistrySettings::SetWallpaper(filepathname, 1, 1);
432 break;
433 case IDM_FILEASWALLPAPERCENTERED:
434 RegistrySettings::SetWallpaper(filepathname, 1, 0);
435 break;
436 case IDM_FILEASWALLPAPERSTRETCHED:
437 RegistrySettings::SetWallpaper(filepathname, 2, 0);
438 break;
439 case IDM_EDITUNDO:
440 imageModel.Undo();
441 imageArea.Invalidate(FALSE);
442 break;
443 case IDM_EDITREDO:
444 imageModel.Redo();
445 imageArea.Invalidate(FALSE);
446 break;
447 case IDM_EDITCOPY:
448 OpenClipboard();
449 EmptyClipboard();
450 SetClipboardData(CF_BITMAP, CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
451 CloseClipboard();
452 break;
453 case IDM_EDITCUT:
454 /* Copy */
455 SendMessage(WM_COMMAND, IDM_EDITCOPY, 0);
456 /* Delete selection */
457 SendMessage(WM_COMMAND, IDM_EDITDELETESELECTION, 0);
458 break;
459 case IDM_EDITPASTE:
460 OpenClipboard();
461 if (GetClipboardData(CF_BITMAP) != NULL)
462 {
463 InsertSelectionFromHBITMAP((HBITMAP) GetClipboardData(CF_BITMAP), m_hWnd);
464 }
465 CloseClipboard();
466 break;
467 case IDM_EDITDELETESELECTION:
468 {
469 /* remove selection window and already painted content using undo */
470 imageModel.Undo();
471 break;
472 }
473 case IDM_EDITSELECTALL:
474 {
475 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
476 SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
477 toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
478 //TODO: do this properly
479 startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
480 whilePaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
481 endPaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
482 break;
483 }
484 case IDM_EDITCOPYTO:
485 if (GetSaveFileName(&ofn) != 0)
486 SaveDIBToFile(selectionModel.GetBitmap(), ofn.lpstrFile, imageModel.GetDC(), NULL, NULL, fileHPPM, fileVPPM);
487 break;
488 case IDM_EDITPASTEFROM:
489 if (GetOpenFileName(&ofn) != 0)
490 {
491 HBITMAP bmNew = NULL;
492 LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
493 if (bmNew != NULL)
494 {
495 InsertSelectionFromHBITMAP(bmNew, m_hWnd);
496 DeleteObject(bmNew);
497 }
498 }
499 break;
500 case IDM_COLORSEDITPALETTE:
501 if (ChooseColor(&choosecolor))
502 paletteModel.SetFgColor(choosecolor.rgbResult);
503 break;
504 case IDM_COLORSMODERNPALETTE:
505 paletteModel.SelectPalette(1);
506 break;
507 case IDM_COLORSOLDPALETTE:
508 paletteModel.SelectPalette(2);
509 break;
510 case IDM_IMAGEINVERTCOLORS:
511 {
512 imageModel.InvertColors();
513 break;
514 }
515 case IDM_IMAGEDELETEIMAGE:
516 imageModel.CopyPrevious();
517 Rect(imageModel.GetDC(), 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE);
518 imageArea.Invalidate(FALSE);
519 break;
520 case IDM_IMAGEROTATEMIRROR:
521 switch (mirrorRotateDlg())
522 {
523 case 1: /* flip horizontally */
524 if (selectionWindow.IsWindowVisible())
525 selectionModel.FlipHorizontally();
526 else
527 imageModel.FlipHorizontally();
528 break;
529 case 2: /* flip vertically */
530 if (selectionWindow.IsWindowVisible())
531 selectionModel.FlipVertically();
532 else
533 imageModel.FlipVertically();
534 break;
535 case 3: /* rotate 90 degrees */
536 break;
537 case 4: /* rotate 180 degrees */
538 if (selectionWindow.IsWindowVisible())
539 selectionModel.RotateNTimes90Degrees(2);
540 else
541 imageModel.RotateNTimes90Degrees(2);
542 break;
543 case 5: /* rotate 270 degrees */
544 break;
545 }
546 break;
547 case IDM_IMAGEATTRIBUTES:
548 {
549 if (attributesDlg())
550 {
551 imageModel.Crop(widthSetInDlg, heightSetInDlg, 0, 0);
552 }
553 break;
554 }
555 case IDM_IMAGESTRETCHSKEW:
556 {
557 if (changeSizeDlg())
558 {
559 imageModel.StretchSkew(stretchSkew.percentage.x, stretchSkew.percentage.y,
560 stretchSkew.angle.x, stretchSkew.angle.y);
561 }
562 break;
563 }
564 case IDM_IMAGEDRAWOPAQUE:
565 toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
566 break;
567 case IDM_IMAGECROP:
568 imageModel.Insert((HBITMAP) CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
569 break;
570
571 case IDM_VIEWTOOLBOX:
572 toolBoxContainer.ShowWindow(toolBoxContainer.IsWindowVisible() ? SW_HIDE : SW_SHOW);
573 alignChildrenToMainWindow();
574 break;
575 case IDM_VIEWCOLORPALETTE:
576 paletteWindow.ShowWindow(paletteWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
577 alignChildrenToMainWindow();
578 break;
579 case IDM_VIEWSTATUSBAR:
580 ::ShowWindow(hStatusBar, ::IsWindowVisible(hStatusBar) ? SW_HIDE : SW_SHOW);
581 alignChildrenToMainWindow();
582 break;
583 case IDM_FORMATICONBAR:
584 textEditWindow.ShowWindow(textEditWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
585
586 case IDM_VIEWSHOWGRID:
587 showGrid = !showGrid;
588 imageArea.Invalidate(FALSE);
589 break;
590 case IDM_VIEWSHOWMINIATURE:
591 showMiniature = !showMiniature;
592 miniature.ShowWindow(showMiniature ? SW_SHOW : SW_HIDE);
593 break;
594
595 case IDM_VIEWZOOM125:
596 zoomTo(125, 0, 0);
597 break;
598 case IDM_VIEWZOOM25:
599 zoomTo(250, 0, 0);
600 break;
601 case IDM_VIEWZOOM50:
602 zoomTo(500, 0, 0);
603 break;
604 case IDM_VIEWZOOM100:
605 zoomTo(1000, 0, 0);
606 break;
607 case IDM_VIEWZOOM200:
608 zoomTo(2000, 0, 0);
609 break;
610 case IDM_VIEWZOOM400:
611 zoomTo(4000, 0, 0);
612 break;
613 case IDM_VIEWZOOM800:
614 zoomTo(8000, 0, 0);
615 break;
616
617 case IDM_VIEWFULLSCREEN:
618 fullscreenWindow.ShowWindow(SW_SHOW);
619 ShowWindow(SW_HIDE);
620 break;
621 }
622 return 0;
623 }