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