[MSPAINT_NEW] manage palette and tools data in a PaletteModel and ToolsModel class...
[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 CMainWindow::selectTool(int tool)
20 {
21 selectionWindow.ShowWindow(SW_HIDE);
22 toolsModel.SetActiveTool(tool);
23 pointSP = 0; // resets the point-buffer of the polygon and bezier functions
24 toolSettingsWindow.Invalidate(TRUE);
25 ::ShowWindow(hTrackbarZoom, (tool == TOOL_ZOOM) ? SW_SHOW : SW_HIDE);
26 textEditWindow.ShowWindow((tool == TOOL_TEXT) ? SW_SHOW : SW_HIDE);
27 }
28
29 void
30 updateCanvasAndScrollbars()
31 {
32 selectionWindow.ShowWindow(SW_HIDE);
33 imageArea.MoveWindow(3, 3, imgXRes * toolsModel.GetZoom() / 1000, imgYRes * toolsModel.GetZoom() / 1000, FALSE);
34 scrollboxWindow.Invalidate(TRUE);
35 imageArea.Invalidate(FALSE);
36
37 scrollboxWindow.SetScrollPos(SB_HORZ, 0, TRUE);
38 scrollboxWindow.SetScrollPos(SB_VERT, 0, TRUE);
39 }
40
41 void
42 zoomTo(int newZoom, int mouseX, int mouseY)
43 {
44 int tbPos = 0;
45 int tempZoom = newZoom;
46
47 RECT clientRectScrollbox;
48 RECT clientRectImageArea;
49 int x, y, w, h;
50 scrollboxWindow.GetClientRect(&clientRectScrollbox);
51 imageArea.GetClientRect(&clientRectImageArea);
52 w = clientRectImageArea.right * clientRectScrollbox.right / (clientRectImageArea.right * newZoom / toolsModel.GetZoom());
53 h = clientRectImageArea.bottom * clientRectScrollbox.bottom / (clientRectImageArea.bottom * newZoom / toolsModel.GetZoom());
54 x = max(0, min(clientRectImageArea.right - w, mouseX - w / 2)) * newZoom / toolsModel.GetZoom();
55 y = max(0, min(clientRectImageArea.bottom - h, mouseY - h / 2)) * newZoom / toolsModel.GetZoom();
56
57 toolsModel.SetZoom(newZoom);
58
59 selectionWindow.ShowWindow(SW_HIDE);
60 imageArea.MoveWindow(3, 3, imgXRes * toolsModel.GetZoom() / 1000, imgYRes * toolsModel.GetZoom() / 1000, FALSE);
61 scrollboxWindow.Invalidate(TRUE);
62 imageArea.Invalidate(FALSE);
63
64 scrollboxWindow.SendMessage(WM_HSCROLL, SB_THUMBPOSITION | (x << 16), 0);
65 scrollboxWindow.SendMessage(WM_VSCROLL, SB_THUMBPOSITION | (y << 16), 0);
66
67 while (tempZoom > 125)
68 {
69 tbPos++;
70 tempZoom = tempZoom >> 1;
71 }
72 SendMessage(hTrackbarZoom, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) tbPos);
73 }
74
75 void CMainWindow::alignChildrenToMainWindow()
76 {
77 int x, y, w, h;
78 RECT clientRect;
79 mainWindow.GetClientRect(&clientRect);
80
81 if (toolBoxContainer.IsWindowVisible())
82 {
83 x = 56;
84 w = clientRect.right - 56;
85 }
86 else
87 {
88 x = 0;
89 w = clientRect.right;
90 }
91 if (paletteWindow.IsWindowVisible())
92 {
93 y = 49;
94 h = clientRect.bottom - 49;
95 }
96 else
97 {
98 y = 3;
99 h = clientRect.bottom - 3;
100 }
101
102 scrollboxWindow.MoveWindow(x, y, w, ::IsWindowVisible(hStatusBar) ? h - 23 : h, TRUE);
103 paletteWindow.MoveWindow(x, 9, 255, 32, TRUE);
104 }
105
106 void CMainWindow::saveImage(BOOL overwrite)
107 {
108 if (isAFile && overwrite)
109 {
110 SaveDIBToFile(hBms[currInd], filepathname, hDrawingDC, &fileTime, &fileSize, fileHPPM,
111 fileVPPM);
112 imageSaved = TRUE;
113 }
114 else if (GetSaveFileName(&sfn) != 0)
115 {
116 TCHAR tempstr[1000];
117 TCHAR resstr[100];
118 SaveDIBToFile(hBms[currInd], sfn.lpstrFile, hDrawingDC, &fileTime, &fileSize,
119 fileHPPM, fileVPPM);
120 CopyMemory(filename, sfn.lpstrFileTitle, sizeof(filename));
121 CopyMemory(filepathname, sfn.lpstrFile, sizeof(filepathname));
122 LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
123 _stprintf(tempstr, resstr, filename);
124 mainWindow.SetWindowText(tempstr);
125 isAFile = TRUE;
126 imageSaved = TRUE;
127 }
128 }
129
130 void CMainWindow::UpdateApplicationProperties(HBITMAP bitmap, LPTSTR newfilename, LPTSTR newfilepathname)
131 {
132 TCHAR tempstr[1000];
133 TCHAR resstr[100];
134 insertReversible(bitmap);
135 updateCanvasAndScrollbars();
136 CopyMemory(filename, newfilename, sizeof(filename));
137 CopyMemory(filepathname, newfilepathname, sizeof(filepathname));
138 LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
139 _stprintf(tempstr, resstr, filename);
140 SetWindowText(tempstr);
141 clearHistory();
142 isAFile = TRUE;
143 }
144
145 void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
146 {
147 HDC hTempDC;
148 HBITMAP hTempMask;
149
150 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
151 SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELONG(TRUE, 0));
152 SendMessage(window, WM_COMMAND, ID_RECTSEL, 0);
153
154 DeleteObject(SelectObject(hSelDC, hSelBm = (HBITMAP) CopyImage(bitmap,
155 IMAGE_BITMAP, 0, 0,
156 LR_COPYRETURNORG)));
157 newReversible();
158 SetRectEmpty(&rectSel_src);
159 rectSel_dest.left = rectSel_dest.top = 0;
160 rectSel_dest.right = rectSel_dest.left + GetDIBWidth(hSelBm);
161 rectSel_dest.bottom = rectSel_dest.top + GetDIBHeight(hSelBm);
162
163 hTempDC = CreateCompatibleDC(hSelDC);
164 hTempMask = CreateBitmap(RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), 1, 1, NULL);
165 SelectObject(hTempDC, hTempMask);
166 Rect(hTempDC, rectSel_dest.left, rectSel_dest.top, rectSel_dest.right, rectSel_dest.bottom, 0x00ffffff, 0x00ffffff, 1, 1);
167 DeleteObject(hSelMask);
168 hSelMask = hTempMask;
169 DeleteDC(hTempDC);
170
171 placeSelWin();
172 selectionWindow.ShowWindow(SW_SHOW);
173 ForceRefreshSelectionContents();
174 }
175
176 LRESULT CMainWindow::OnDropFiles(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
177 {
178 HDROP drophandle;
179 TCHAR droppedfile[MAX_PATH];
180 HBITMAP bmNew = NULL;
181 drophandle = (HDROP)wParam;
182 DragQueryFile(drophandle, 0, droppedfile, SIZEOF(droppedfile));
183 DragFinish(drophandle);
184 LoadDIBFromFile(&bmNew, droppedfile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
185 if (bmNew != NULL)
186 {
187 TCHAR *pathend;
188 pathend = _tcsrchr(droppedfile, '\\');
189 pathend++;
190 UpdateApplicationProperties(bmNew, pathend, pathend);
191 }
192 return 0;
193 }
194
195 LRESULT CMainWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
196 {
197 SendMessage(WM_SETICON, ICON_BIG, (LPARAM) LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON)));
198 SendMessage(WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON)));
199 ptStack = NULL;
200 ptSP = 0;
201 return 0;
202 }
203
204 LRESULT CMainWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
205 {
206 PostQuitMessage(0); /* send a WM_QUIT to the message queue */
207 return 0;
208 }
209
210 LRESULT CMainWindow::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
211 {
212 if (!imageSaved)
213 {
214 TCHAR programname[20];
215 TCHAR saveprompttext[100];
216 TCHAR temptext[500];
217 LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
218 LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, saveprompttext, SIZEOF(saveprompttext));
219 _stprintf(temptext, saveprompttext, filename);
220 switch (MessageBox(temptext, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
221 {
222 case IDNO:
223 DestroyWindow();
224 break;
225 case IDYES:
226 saveImage(FALSE);
227 if (imageSaved)
228 DestroyWindow();
229 break;
230 }
231 }
232 else
233 {
234 DestroyWindow();
235 }
236 return 0;
237 }
238
239 LRESULT CMainWindow::OnInitMenuPopup(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
240 {
241 HMENU menu = GetMenu();
242 BOOL trueSelection = (selectionWindow.IsWindowVisible() && ((toolsModel.GetActiveTool() == TOOL_FREESEL) || (toolsModel.GetActiveTool() == TOOL_RECTSEL)));
243 switch (lParam)
244 {
245 case 0: /* File menu */
246 EnableMenuItem(menu, IDM_FILEASWALLPAPERPLANE, ENABLED_IF(isAFile));
247 EnableMenuItem(menu, IDM_FILEASWALLPAPERCENTERED, ENABLED_IF(isAFile));
248 EnableMenuItem(menu, IDM_FILEASWALLPAPERSTRETCHED, ENABLED_IF(isAFile));
249 break;
250 case 1: /* Edit menu */
251 EnableMenuItem(menu, IDM_EDITUNDO, ENABLED_IF(undoSteps > 0));
252 EnableMenuItem(menu, IDM_EDITREDO, ENABLED_IF(redoSteps > 0));
253 EnableMenuItem(menu, IDM_EDITCUT, ENABLED_IF(trueSelection));
254 EnableMenuItem(menu, IDM_EDITCOPY, ENABLED_IF(trueSelection));
255 EnableMenuItem(menu, IDM_EDITDELETESELECTION, ENABLED_IF(trueSelection));
256 EnableMenuItem(menu, IDM_EDITINVERTSELECTION, ENABLED_IF(trueSelection));
257 EnableMenuItem(menu, IDM_EDITCOPYTO, ENABLED_IF(trueSelection));
258 OpenClipboard();
259 EnableMenuItem(menu, IDM_EDITPASTE, ENABLED_IF(GetClipboardData(CF_BITMAP) != NULL));
260 CloseClipboard();
261 break;
262 case 2: /* View menu */
263 CheckMenuItem(menu, IDM_VIEWTOOLBOX, CHECKED_IF(toolBoxContainer.IsWindowVisible()));
264 CheckMenuItem(menu, IDM_VIEWCOLORPALETTE, CHECKED_IF(paletteWindow.IsWindowVisible()));
265 CheckMenuItem(menu, IDM_VIEWSTATUSBAR, CHECKED_IF(::IsWindowVisible(hStatusBar)));
266 CheckMenuItem(menu, IDM_FORMATICONBAR, CHECKED_IF(textEditWindow.IsWindowVisible()));
267 EnableMenuItem(menu, IDM_FORMATICONBAR, ENABLED_IF(toolsModel.GetActiveTool() == TOOL_TEXT));
268
269 CheckMenuItem(menu, IDM_VIEWSHOWGRID, CHECKED_IF(showGrid));
270 CheckMenuItem(menu, IDM_VIEWSHOWMINIATURE, CHECKED_IF(showMiniature));
271 break;
272 case 3: /* Image menu */
273 EnableMenuItem(menu, IDM_IMAGECROP, ENABLED_IF(selectionWindow.IsWindowVisible()));
274 CheckMenuItem(menu, IDM_IMAGEDRAWOPAQUE, CHECKED_IF(!toolsModel.IsBackgroundTransparent()));
275 break;
276 }
277
278 CheckMenuItem(menu, IDM_VIEWZOOM125, CHECKED_IF(toolsModel.GetZoom() == 125));
279 CheckMenuItem(menu, IDM_VIEWZOOM25, CHECKED_IF(toolsModel.GetZoom() == 250));
280 CheckMenuItem(menu, IDM_VIEWZOOM50, CHECKED_IF(toolsModel.GetZoom() == 500));
281 CheckMenuItem(menu, IDM_VIEWZOOM100, CHECKED_IF(toolsModel.GetZoom() == 1000));
282 CheckMenuItem(menu, IDM_VIEWZOOM200, CHECKED_IF(toolsModel.GetZoom() == 2000));
283 CheckMenuItem(menu, IDM_VIEWZOOM400, CHECKED_IF(toolsModel.GetZoom() == 4000));
284 CheckMenuItem(menu, IDM_VIEWZOOM800, CHECKED_IF(toolsModel.GetZoom() == 8000));
285
286 CheckMenuItem(menu, IDM_COLORSMODERNPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == 1));
287 CheckMenuItem(menu, IDM_COLORSOLDPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == 2));
288 return 0;
289 }
290
291 LRESULT CMainWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
292 {
293 if (m_hWnd == mainWindow.m_hWnd)
294 {
295 int test[] = { LOWORD(lParam) - 260, LOWORD(lParam) - 140, LOWORD(lParam) - 20 };
296 SendMessage(hStatusBar, WM_SIZE, wParam, lParam);
297 SendMessage(hStatusBar, SB_SETPARTS, 3, (LPARAM)&test);
298 alignChildrenToMainWindow();
299 Invalidate(TRUE);
300 }
301 return 0;
302 }
303
304 LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
305 {
306 if (m_hWnd == mainWindow.m_hWnd)
307 {
308 MINMAXINFO *mm = (LPMINMAXINFO) lParam;
309 mm->ptMinTrackSize.x = 330;
310 mm->ptMinTrackSize.y = 430;
311 }
312 return 0;
313 }
314
315 LRESULT CMainWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
316 {
317 SetCursor(LoadCursor(NULL, IDC_ARROW));
318 return 0;
319 }
320
321 LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
322 {
323 if (wParam == VK_ESCAPE)
324 {
325 if (!imageArea.drawing)
326 {
327 /* Deselect */
328 if ((toolsModel.GetActiveTool() == TOOL_RECTSEL) || (toolsModel.GetActiveTool() == TOOL_FREESEL))
329 {
330 startPaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
331 whilePaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
332 endPaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
333 selectionWindow.ShowWindow(SW_HIDE);
334 }
335 }
336 /* FIXME: also cancel current drawing underway */
337 }
338 return 0;
339 }
340
341 LRESULT CMainWindow::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
342 {
343 /* Redirect message to common controls */
344 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
345 SendMessage(hToolbar, WM_SYSCOLORCHANGE, 0, 0);
346 return 0;
347 }
348
349 LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
350 {
351 switch (LOWORD(wParam))
352 {
353 case IDM_HELPINFO:
354 {
355 HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON));
356 TCHAR infotitle[100];
357 TCHAR infotext[200];
358 LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle));
359 LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext));
360 ShellAbout(mainWindow.m_hWnd, infotitle, infotext, paintIcon);
361 DeleteObject(paintIcon);
362 break;
363 }
364 case IDM_HELPHELPTOPICS:
365 HtmlHelp(mainWindow.m_hWnd, _T("help\\Paint.chm"), 0, 0);
366 break;
367 case IDM_FILEEXIT:
368 SendMessage(WM_CLOSE, wParam, lParam);
369 break;
370 case IDM_FILENEW:
371 {
372 BOOL reset = TRUE;
373 if (!imageSaved)
374 {
375 TCHAR programname[20];
376 TCHAR saveprompttext[100];
377 TCHAR temptext[500];
378 LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
379 LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, saveprompttext, SIZEOF(saveprompttext));
380 _stprintf(temptext, saveprompttext, filename);
381 switch (MessageBox(temptext, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
382 {
383 case IDNO:
384 imageSaved = TRUE;
385 break;
386 case IDYES:
387 saveImage(FALSE);
388 break;
389 case IDCANCEL:
390 reset = FALSE;
391 break;
392 }
393 }
394 if (reset && imageSaved)
395 {
396 Rectangle(hDrawingDC, 0 - 1, 0 - 1, imgXRes + 1, imgYRes + 1);
397 imageArea.Invalidate(FALSE);
398 updateCanvasAndScrollbars();
399 clearHistory();
400 }
401 break;
402 }
403 case IDM_FILEOPEN:
404 if (GetOpenFileName(&ofn) != 0)
405 {
406 HBITMAP bmNew = NULL;
407 LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
408 if (bmNew != NULL)
409 {
410 UpdateApplicationProperties(bmNew, ofn.lpstrFileTitle, ofn.lpstrFileTitle);
411 }
412 }
413 break;
414 case IDM_FILESAVE:
415 saveImage(TRUE);
416 break;
417 case IDM_FILESAVEAS:
418 saveImage(FALSE);
419 break;
420 case IDM_FILEASWALLPAPERPLANE:
421 SetWallpaper(filepathname, 1, 1);
422 break;
423 case IDM_FILEASWALLPAPERCENTERED:
424 SetWallpaper(filepathname, 1, 0);
425 break;
426 case IDM_FILEASWALLPAPERSTRETCHED:
427 SetWallpaper(filepathname, 2, 0);
428 break;
429 case IDM_EDITUNDO:
430 undo();
431 imageArea.Invalidate(FALSE);
432 break;
433 case IDM_EDITREDO:
434 redo();
435 imageArea.Invalidate(FALSE);
436 break;
437 case IDM_EDITCOPY:
438 OpenClipboard();
439 EmptyClipboard();
440 SetClipboardData(CF_BITMAP, CopyImage(hSelBm, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
441 CloseClipboard();
442 break;
443 case IDM_EDITCUT:
444 /* Copy */
445 SendMessage(WM_COMMAND, IDM_EDITCOPY, 0);
446 /* Delete selection */
447 SendMessage(WM_COMMAND, IDM_EDITDELETESELECTION, 0);
448 break;
449 case IDM_EDITPASTE:
450 OpenClipboard();
451 if (GetClipboardData(CF_BITMAP) != NULL)
452 {
453 InsertSelectionFromHBITMAP((HBITMAP) GetClipboardData(CF_BITMAP), m_hWnd);
454 }
455 CloseClipboard();
456 break;
457 case IDM_EDITDELETESELECTION:
458 {
459 /* remove selection window and already painted content using undo(),
460 paint Rect for rectangular selections and Poly for freeform selections */
461 undo();
462 if (toolsModel.GetActiveTool() == TOOL_RECTSEL)
463 {
464 newReversible();
465 Rect(hDrawingDC, rectSel_dest.left, rectSel_dest.top, rectSel_dest.right,
466 rectSel_dest.bottom, paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE);
467 }
468 if (toolsModel.GetActiveTool() == TOOL_FREESEL)
469 {
470 newReversible();
471 Poly(hDrawingDC, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE, TRUE);
472 }
473 break;
474 }
475 case IDM_EDITSELECTALL:
476 {
477 HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
478 SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELONG(TRUE, 0));
479 SendMessage(WM_COMMAND, ID_RECTSEL, 0);
480 startPaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
481 whilePaintingL(hDrawingDC, imgXRes, imgYRes, paletteModel.GetFgColor(), paletteModel.GetBgColor());
482 endPaintingL(hDrawingDC, imgXRes, imgYRes, paletteModel.GetFgColor(), paletteModel.GetBgColor());
483 break;
484 }
485 case IDM_EDITCOPYTO:
486 if (GetSaveFileName(&ofn) != 0)
487 SaveDIBToFile(hSelBm, ofn.lpstrFile, hDrawingDC, NULL, NULL, fileHPPM, fileVPPM);
488 break;
489 case IDM_EDITPASTEFROM:
490 if (GetOpenFileName(&ofn) != 0)
491 {
492 HBITMAP bmNew = NULL;
493 LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
494 if (bmNew != NULL)
495 {
496 InsertSelectionFromHBITMAP(bmNew, m_hWnd);
497 DeleteObject(bmNew);
498 }
499 }
500 break;
501 case IDM_COLORSEDITPALETTE:
502 if (ChooseColor(&choosecolor))
503 {
504 paletteModel.SetFgColor(choosecolor.rgbResult);
505 paletteWindow.Invalidate(FALSE);
506 }
507 break;
508 case IDM_COLORSMODERNPALETTE:
509 paletteModel.SelectPalette(1);
510 paletteWindow.Invalidate(FALSE);
511 break;
512 case IDM_COLORSOLDPALETTE:
513 paletteModel.SelectPalette(2);
514 paletteWindow.Invalidate(FALSE);
515 break;
516 case IDM_IMAGEINVERTCOLORS:
517 {
518 RECT tempRect;
519 newReversible();
520 SetRect(&tempRect, 0, 0, imgXRes, imgYRes);
521 InvertRect(hDrawingDC, &tempRect);
522 imageArea.Invalidate(FALSE);
523 break;
524 }
525 case IDM_IMAGEDELETEIMAGE:
526 newReversible();
527 Rect(hDrawingDC, 0, 0, imgXRes, imgYRes, paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE);
528 imageArea.Invalidate(FALSE);
529 break;
530 case IDM_IMAGEROTATEMIRROR:
531 switch (mirrorRotateDlg())
532 {
533 case 1: /* flip horizontally */
534 if (selectionWindow.IsWindowVisible())
535 {
536 SelectObject(hSelDC, hSelMask);
537 StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, 0, -RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC,
538 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY);
539 SelectObject(hSelDC, hSelBm);
540 StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, 0, -RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC,
541 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY);
542 ForceRefreshSelectionContents();
543 }
544 else
545 {
546 newReversible();
547 StretchBlt(hDrawingDC, imgXRes - 1, 0, -imgXRes, imgYRes, hDrawingDC, 0, 0,
548 imgXRes, imgYRes, SRCCOPY);
549 imageArea.Invalidate(FALSE);
550 }
551 break;
552 case 2: /* flip vertically */
553 if (selectionWindow.IsWindowVisible())
554 {
555 SelectObject(hSelDC, hSelMask);
556 StretchBlt(hSelDC, 0, RECT_HEIGHT(rectSel_dest) - 1, RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC,
557 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY);
558 SelectObject(hSelDC, hSelBm);
559 StretchBlt(hSelDC, 0, RECT_HEIGHT(rectSel_dest) - 1, RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC,
560 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY);
561 ForceRefreshSelectionContents();
562 }
563 else
564 {
565 newReversible();
566 StretchBlt(hDrawingDC, 0, imgYRes - 1, imgXRes, -imgYRes, hDrawingDC, 0, 0,
567 imgXRes, imgYRes, SRCCOPY);
568 imageArea.Invalidate(FALSE);
569 }
570 break;
571 case 3: /* rotate 90 degrees */
572 break;
573 case 4: /* rotate 180 degrees */
574 if (selectionWindow.IsWindowVisible())
575 {
576 SelectObject(hSelDC, hSelMask);
577 StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, RECT_HEIGHT(rectSel_dest) - 1, -RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC,
578 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY);
579 SelectObject(hSelDC, hSelBm);
580 StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, RECT_HEIGHT(rectSel_dest) - 1, -RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC,
581 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY);
582 ForceRefreshSelectionContents();
583 }
584 else
585 {
586 newReversible();
587 StretchBlt(hDrawingDC, imgXRes - 1, imgYRes - 1, -imgXRes, -imgYRes, hDrawingDC,
588 0, 0, imgXRes, imgYRes, SRCCOPY);
589 imageArea.Invalidate(FALSE);
590 }
591 break;
592 case 5: /* rotate 270 degrees */
593 break;
594 }
595 break;
596 case IDM_IMAGEATTRIBUTES:
597 {
598 if (attributesDlg())
599 {
600 cropReversible(widthSetInDlg, heightSetInDlg, 0, 0);
601 updateCanvasAndScrollbars();
602 }
603 break;
604 }
605 case IDM_IMAGESTRETCHSKEW:
606 {
607 if (changeSizeDlg())
608 {
609 insertReversible((HBITMAP) CopyImage(hBms[currInd], IMAGE_BITMAP,
610 imgXRes * stretchSkew.percentage.x / 100,
611 imgYRes * stretchSkew.percentage.y / 100, 0));
612 updateCanvasAndScrollbars();
613 }
614 break;
615 }
616 case IDM_IMAGEDRAWOPAQUE:
617 toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
618 toolSettingsWindow.Invalidate(TRUE);
619 break;
620 case IDM_IMAGECROP:
621 insertReversible((HBITMAP) CopyImage(hSelBm, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
622 updateCanvasAndScrollbars();
623 break;
624
625 case IDM_VIEWTOOLBOX:
626 toolBoxContainer.ShowWindow(toolBoxContainer.IsWindowVisible() ? SW_HIDE : SW_SHOW);
627 alignChildrenToMainWindow();
628 break;
629 case IDM_VIEWCOLORPALETTE:
630 paletteWindow.ShowWindow(paletteWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
631 alignChildrenToMainWindow();
632 break;
633 case IDM_VIEWSTATUSBAR:
634 ::ShowWindow(hStatusBar, ::IsWindowVisible(hStatusBar) ? SW_HIDE : SW_SHOW);
635 alignChildrenToMainWindow();
636 break;
637 case IDM_FORMATICONBAR:
638 textEditWindow.ShowWindow(textEditWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
639
640 case IDM_VIEWSHOWGRID:
641 showGrid = !showGrid;
642 imageArea.Invalidate(FALSE);
643 break;
644 case IDM_VIEWSHOWMINIATURE:
645 showMiniature = !showMiniature;
646 miniature.ShowWindow(showMiniature ? SW_SHOW : SW_HIDE);
647 break;
648
649 case IDM_VIEWZOOM125:
650 zoomTo(125, 0, 0);
651 break;
652 case IDM_VIEWZOOM25:
653 zoomTo(250, 0, 0);
654 break;
655 case IDM_VIEWZOOM50:
656 zoomTo(500, 0, 0);
657 break;
658 case IDM_VIEWZOOM100:
659 zoomTo(1000, 0, 0);
660 break;
661 case IDM_VIEWZOOM200:
662 zoomTo(2000, 0, 0);
663 break;
664 case IDM_VIEWZOOM400:
665 zoomTo(4000, 0, 0);
666 break;
667 case IDM_VIEWZOOM800:
668 zoomTo(8000, 0, 0);
669 break;
670 case ID_FREESEL:
671 selectTool(1);
672 break;
673 case ID_RECTSEL:
674 selectTool(2);
675 break;
676 case ID_RUBBER:
677 selectTool(3);
678 break;
679 case ID_FILL:
680 selectTool(4);
681 break;
682 case ID_COLOR:
683 selectTool(5);
684 break;
685 case ID_ZOOM:
686 selectTool(6);
687 break;
688 case ID_PEN:
689 selectTool(7);
690 break;
691 case ID_BRUSH:
692 selectTool(8);
693 break;
694 case ID_AIRBRUSH:
695 selectTool(9);
696 break;
697 case ID_TEXT:
698 selectTool(10);
699 break;
700 case ID_LINE:
701 selectTool(11);
702 break;
703 case ID_BEZIER:
704 selectTool(12);
705 break;
706 case ID_RECT:
707 selectTool(13);
708 break;
709 case ID_SHAPE:
710 selectTool(14);
711 break;
712 case ID_ELLIPSE:
713 selectTool(15);
714 break;
715 case ID_RRECT:
716 selectTool(16);
717 break;
718 }
719 return 0;
720 }