2015-05-08 16:02:36 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL
|
2015-05-08 16:27:46 +00:00
|
|
|
* FILE: base/applications/mspaint_new/winproc.cpp
|
2015-05-08 16:02:36 +00:00
|
|
|
* PURPOSE: Window procedure of the main window and all children apart from
|
|
|
|
* hPalWin, hToolSettings and hSelection
|
|
|
|
* PROGRAMMERS: Benedikt Freisen
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *********************************************************/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
#include "dialogs.h"
|
|
|
|
#include "registry.h"
|
|
|
|
|
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
zoomTo(int newZoom, int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
RECT clientRectScrollbox;
|
|
|
|
RECT clientRectImageArea;
|
|
|
|
int x, y, w, h;
|
2015-07-07 10:42:49 +00:00
|
|
|
scrollboxWindow.GetClientRect(&clientRectScrollbox);
|
|
|
|
imageArea.GetClientRect(&clientRectImageArea);
|
2015-07-07 11:15:24 +00:00
|
|
|
w = clientRectImageArea.right * clientRectScrollbox.right / (clientRectImageArea.right * newZoom / toolsModel.GetZoom());
|
|
|
|
h = clientRectImageArea.bottom * clientRectScrollbox.bottom / (clientRectImageArea.bottom * newZoom / toolsModel.GetZoom());
|
|
|
|
x = max(0, min(clientRectImageArea.right - w, mouseX - w / 2)) * newZoom / toolsModel.GetZoom();
|
|
|
|
y = max(0, min(clientRectImageArea.bottom - h, mouseY - h / 2)) * newZoom / toolsModel.GetZoom();
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 11:15:24 +00:00
|
|
|
toolsModel.SetZoom(newZoom);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
selectionWindow.ShowWindow(SW_HIDE);
|
2015-07-07 11:56:37 +00:00
|
|
|
imageArea.MoveWindow(3, 3, imageModel.GetWidth() * toolsModel.GetZoom() / 1000, imageModel.GetHeight() * toolsModel.GetZoom() / 1000, FALSE);
|
2015-07-07 10:42:49 +00:00
|
|
|
scrollboxWindow.Invalidate(TRUE);
|
|
|
|
imageArea.Invalidate(FALSE);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 11:44:50 +00:00
|
|
|
scrollboxWindow.SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, x), 0);
|
|
|
|
scrollboxWindow.SendMessage(WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, y), 0);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:02:30 +00:00
|
|
|
void CMainWindow::alignChildrenToMainWindow()
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
|
|
|
int x, y, w, h;
|
|
|
|
RECT clientRect;
|
2015-07-07 11:44:50 +00:00
|
|
|
GetClientRect(&clientRect);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
if (toolBoxContainer.IsWindowVisible())
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
|
|
|
x = 56;
|
|
|
|
w = clientRect.right - 56;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
w = clientRect.right;
|
|
|
|
}
|
2015-07-07 10:42:49 +00:00
|
|
|
if (paletteWindow.IsWindowVisible())
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
|
|
|
y = 49;
|
|
|
|
h = clientRect.bottom - 49;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y = 3;
|
|
|
|
h = clientRect.bottom - 3;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:02:30 +00:00
|
|
|
scrollboxWindow.MoveWindow(x, y, w, ::IsWindowVisible(hStatusBar) ? h - 23 : h, TRUE);
|
2015-07-07 10:42:49 +00:00
|
|
|
paletteWindow.MoveWindow(x, 9, 255, 32, TRUE);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 11:02:30 +00:00
|
|
|
void CMainWindow::saveImage(BOOL overwrite)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
|
|
|
if (isAFile && overwrite)
|
|
|
|
{
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.SaveImage(filepathname);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
else if (GetSaveFileName(&sfn) != 0)
|
|
|
|
{
|
|
|
|
TCHAR tempstr[1000];
|
|
|
|
TCHAR resstr[100];
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.SaveImage(sfn.lpstrFile);
|
2015-05-08 16:02:36 +00:00
|
|
|
CopyMemory(filename, sfn.lpstrFileTitle, sizeof(filename));
|
|
|
|
CopyMemory(filepathname, sfn.lpstrFile, sizeof(filepathname));
|
|
|
|
LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
|
|
|
|
_stprintf(tempstr, resstr, filename);
|
2015-07-07 11:44:50 +00:00
|
|
|
SetWindowText(tempstr);
|
2015-05-08 16:02:36 +00:00
|
|
|
isAFile = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:02:30 +00:00
|
|
|
void CMainWindow::UpdateApplicationProperties(HBITMAP bitmap, LPTSTR newfilename, LPTSTR newfilepathname)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
|
|
|
TCHAR tempstr[1000];
|
|
|
|
TCHAR resstr[100];
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Insert(bitmap);
|
2015-05-08 16:02:36 +00:00
|
|
|
CopyMemory(filename, newfilename, sizeof(filename));
|
|
|
|
CopyMemory(filepathname, newfilepathname, sizeof(filepathname));
|
|
|
|
LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
|
|
|
|
_stprintf(tempstr, resstr, filename);
|
2015-07-07 11:02:30 +00:00
|
|
|
SetWindowText(tempstr);
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.ClearHistory();
|
2015-05-08 16:02:36 +00:00
|
|
|
isAFile = TRUE;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:02:30 +00:00
|
|
|
void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-13 14:46:41 +00:00
|
|
|
int width = GetDIBWidth(bitmap);
|
|
|
|
int height = GetDIBHeight(bitmap);
|
|
|
|
int curWidth = imageModel.GetWidth();
|
|
|
|
int curHeight = imageModel.GetHeight();
|
|
|
|
|
|
|
|
if (width > curWidth || height > curHeight)
|
|
|
|
{
|
|
|
|
BOOL shouldEnlarge = TRUE;
|
|
|
|
|
|
|
|
if (askBeforeEnlarging)
|
|
|
|
{
|
|
|
|
TCHAR programname[20];
|
|
|
|
TCHAR shouldEnlargePromptText[100];
|
|
|
|
|
|
|
|
LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
|
|
|
|
LoadString(hProgInstance, IDS_ENLARGEPROMPTTEXT, shouldEnlargePromptText, SIZEOF(shouldEnlargePromptText));
|
|
|
|
|
|
|
|
switch (MessageBox(shouldEnlargePromptText, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
|
|
|
|
{
|
|
|
|
case IDYES:
|
|
|
|
break;
|
|
|
|
case IDNO:
|
|
|
|
shouldEnlarge = FALSE;
|
|
|
|
break;
|
|
|
|
case IDCANCEL:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldEnlarge)
|
|
|
|
{
|
|
|
|
if (width > curWidth)
|
|
|
|
curWidth = width;
|
|
|
|
|
|
|
|
if (height > curHeight)
|
|
|
|
curHeight = height;
|
|
|
|
|
|
|
|
imageModel.Crop(curWidth, curHeight, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
|
2015-07-07 11:44:50 +00:00
|
|
|
SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
|
|
|
|
toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.CopyPrevious();
|
2015-07-09 09:48:01 +00:00
|
|
|
selectionModel.InsertFromHBITMAP(bitmap);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
|
|
|
placeSelWin();
|
2015-07-07 10:42:49 +00:00
|
|
|
selectionWindow.ShowWindow(SW_SHOW);
|
2015-05-08 16:02:36 +00:00
|
|
|
ForceRefreshSelectionContents();
|
|
|
|
}
|
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CMainWindow::OnDropFiles(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
HDROP drophandle;
|
|
|
|
TCHAR droppedfile[MAX_PATH];
|
|
|
|
HBITMAP bmNew = NULL;
|
|
|
|
drophandle = (HDROP)wParam;
|
|
|
|
DragQueryFile(drophandle, 0, droppedfile, SIZEOF(droppedfile));
|
|
|
|
DragFinish(drophandle);
|
|
|
|
LoadDIBFromFile(&bmNew, droppedfile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
|
|
|
|
if (bmNew != NULL)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
TCHAR *pathend;
|
|
|
|
pathend = _tcsrchr(droppedfile, '\\');
|
|
|
|
pathend++;
|
|
|
|
UpdateApplicationProperties(bmNew, pathend, pathend);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CMainWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
SendMessage(WM_SETICON, ICON_BIG, (LPARAM) LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON)));
|
|
|
|
SendMessage(WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON)));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CMainWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
PostQuitMessage(0); /* send a WM_QUIT to the message queue */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CMainWindow::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2015-07-07 11:56:37 +00:00
|
|
|
if (!imageModel.IsImageSaved())
|
2015-07-07 10:42:49 +00:00
|
|
|
{
|
|
|
|
TCHAR programname[20];
|
|
|
|
TCHAR saveprompttext[100];
|
|
|
|
TCHAR temptext[500];
|
|
|
|
LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
|
|
|
|
LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, saveprompttext, SIZEOF(saveprompttext));
|
|
|
|
_stprintf(temptext, saveprompttext, filename);
|
|
|
|
switch (MessageBox(temptext, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDNO:
|
|
|
|
DestroyWindow();
|
|
|
|
break;
|
|
|
|
case IDYES:
|
|
|
|
saveImage(FALSE);
|
2015-07-07 11:56:37 +00:00
|
|
|
if (imageModel.IsImageSaved())
|
2015-07-07 10:42:49 +00:00
|
|
|
DestroyWindow();
|
|
|
|
break;
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DestroyWindow();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CMainWindow::OnInitMenuPopup(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
HMENU menu = GetMenu();
|
2015-07-07 11:15:24 +00:00
|
|
|
BOOL trueSelection = (selectionWindow.IsWindowVisible() && ((toolsModel.GetActiveTool() == TOOL_FREESEL) || (toolsModel.GetActiveTool() == TOOL_RECTSEL)));
|
2015-07-07 10:42:49 +00:00
|
|
|
switch (lParam)
|
|
|
|
{
|
|
|
|
case 0: /* File menu */
|
|
|
|
EnableMenuItem(menu, IDM_FILEASWALLPAPERPLANE, ENABLED_IF(isAFile));
|
|
|
|
EnableMenuItem(menu, IDM_FILEASWALLPAPERCENTERED, ENABLED_IF(isAFile));
|
|
|
|
EnableMenuItem(menu, IDM_FILEASWALLPAPERSTRETCHED, ENABLED_IF(isAFile));
|
|
|
|
break;
|
|
|
|
case 1: /* Edit menu */
|
2015-07-07 11:56:37 +00:00
|
|
|
EnableMenuItem(menu, IDM_EDITUNDO, ENABLED_IF(imageModel.HasUndoSteps()));
|
|
|
|
EnableMenuItem(menu, IDM_EDITREDO, ENABLED_IF(imageModel.HasRedoSteps()));
|
2015-07-07 10:42:49 +00:00
|
|
|
EnableMenuItem(menu, IDM_EDITCUT, ENABLED_IF(trueSelection));
|
|
|
|
EnableMenuItem(menu, IDM_EDITCOPY, ENABLED_IF(trueSelection));
|
|
|
|
EnableMenuItem(menu, IDM_EDITDELETESELECTION, ENABLED_IF(trueSelection));
|
|
|
|
EnableMenuItem(menu, IDM_EDITINVERTSELECTION, ENABLED_IF(trueSelection));
|
|
|
|
EnableMenuItem(menu, IDM_EDITCOPYTO, ENABLED_IF(trueSelection));
|
|
|
|
OpenClipboard();
|
|
|
|
EnableMenuItem(menu, IDM_EDITPASTE, ENABLED_IF(GetClipboardData(CF_BITMAP) != NULL));
|
|
|
|
CloseClipboard();
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case 2: /* View menu */
|
|
|
|
CheckMenuItem(menu, IDM_VIEWTOOLBOX, CHECKED_IF(toolBoxContainer.IsWindowVisible()));
|
|
|
|
CheckMenuItem(menu, IDM_VIEWCOLORPALETTE, CHECKED_IF(paletteWindow.IsWindowVisible()));
|
|
|
|
CheckMenuItem(menu, IDM_VIEWSTATUSBAR, CHECKED_IF(::IsWindowVisible(hStatusBar)));
|
|
|
|
CheckMenuItem(menu, IDM_FORMATICONBAR, CHECKED_IF(textEditWindow.IsWindowVisible()));
|
2015-07-07 11:15:24 +00:00
|
|
|
EnableMenuItem(menu, IDM_FORMATICONBAR, ENABLED_IF(toolsModel.GetActiveTool() == TOOL_TEXT));
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
CheckMenuItem(menu, IDM_VIEWSHOWGRID, CHECKED_IF(showGrid));
|
|
|
|
CheckMenuItem(menu, IDM_VIEWSHOWMINIATURE, CHECKED_IF(showMiniature));
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case 3: /* Image menu */
|
|
|
|
EnableMenuItem(menu, IDM_IMAGECROP, ENABLED_IF(selectionWindow.IsWindowVisible()));
|
2015-07-07 11:15:24 +00:00
|
|
|
CheckMenuItem(menu, IDM_IMAGEDRAWOPAQUE, CHECKED_IF(!toolsModel.IsBackgroundTransparent()));
|
2015-07-07 10:42:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:15:24 +00:00
|
|
|
CheckMenuItem(menu, IDM_VIEWZOOM125, CHECKED_IF(toolsModel.GetZoom() == 125));
|
|
|
|
CheckMenuItem(menu, IDM_VIEWZOOM25, CHECKED_IF(toolsModel.GetZoom() == 250));
|
|
|
|
CheckMenuItem(menu, IDM_VIEWZOOM50, CHECKED_IF(toolsModel.GetZoom() == 500));
|
|
|
|
CheckMenuItem(menu, IDM_VIEWZOOM100, CHECKED_IF(toolsModel.GetZoom() == 1000));
|
|
|
|
CheckMenuItem(menu, IDM_VIEWZOOM200, CHECKED_IF(toolsModel.GetZoom() == 2000));
|
|
|
|
CheckMenuItem(menu, IDM_VIEWZOOM400, CHECKED_IF(toolsModel.GetZoom() == 4000));
|
|
|
|
CheckMenuItem(menu, IDM_VIEWZOOM800, CHECKED_IF(toolsModel.GetZoom() == 8000));
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 11:15:24 +00:00
|
|
|
CheckMenuItem(menu, IDM_COLORSMODERNPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == 1));
|
|
|
|
CheckMenuItem(menu, IDM_COLORSOLDPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == 2));
|
2015-07-07 10:42:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CMainWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2015-07-07 11:44:50 +00:00
|
|
|
int test[] = { LOWORD(lParam) - 260, LOWORD(lParam) - 140, LOWORD(lParam) - 20 };
|
|
|
|
SendMessage(hStatusBar, WM_SIZE, wParam, lParam);
|
|
|
|
SendMessage(hStatusBar, SB_SETPARTS, 3, (LPARAM)&test);
|
|
|
|
alignChildrenToMainWindow();
|
|
|
|
Invalidate(TRUE);
|
2015-07-07 10:42:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2015-07-07 11:44:50 +00:00
|
|
|
MINMAXINFO *mm = (LPMINMAXINFO) lParam;
|
|
|
|
mm->ptMinTrackSize.x = 330;
|
|
|
|
mm->ptMinTrackSize.y = 430;
|
2015-07-07 10:42:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CMainWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2015-07-07 11:02:30 +00:00
|
|
|
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
2015-07-07 10:42:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (wParam == VK_ESCAPE)
|
|
|
|
{
|
2015-07-07 11:02:30 +00:00
|
|
|
if (!imageArea.drawing)
|
2015-07-07 10:42:49 +00:00
|
|
|
{
|
|
|
|
/* Deselect */
|
2015-07-07 11:15:24 +00:00
|
|
|
if ((toolsModel.GetActiveTool() == TOOL_RECTSEL) || (toolsModel.GetActiveTool() == TOOL_FREESEL))
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 11:15:24 +00:00
|
|
|
startPaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
|
|
|
|
whilePaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
|
|
|
|
endPaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
|
2015-07-07 10:42:49 +00:00
|
|
|
selectionWindow.ShowWindow(SW_HIDE);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
/* FIXME: also cancel current drawing underway */
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CMainWindow::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
/* Redirect message to common controls */
|
|
|
|
HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
|
|
|
|
SendMessage(hToolbar, WM_SYSCOLORCHANGE, 0, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDM_HELPINFO:
|
|
|
|
{
|
|
|
|
HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON));
|
|
|
|
TCHAR infotitle[100];
|
|
|
|
TCHAR infotext[200];
|
|
|
|
LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle));
|
|
|
|
LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext));
|
2015-07-07 11:44:50 +00:00
|
|
|
ShellAbout(m_hWnd, infotitle, infotext, paintIcon);
|
2015-07-07 10:42:49 +00:00
|
|
|
DeleteObject(paintIcon);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IDM_HELPHELPTOPICS:
|
2015-07-07 11:44:50 +00:00
|
|
|
HtmlHelp(m_hWnd, _T("help\\Paint.chm"), 0, 0);
|
2015-07-07 10:42:49 +00:00
|
|
|
break;
|
|
|
|
case IDM_FILEEXIT:
|
|
|
|
SendMessage(WM_CLOSE, wParam, lParam);
|
|
|
|
break;
|
|
|
|
case IDM_FILENEW:
|
|
|
|
{
|
|
|
|
BOOL reset = TRUE;
|
2015-07-07 11:56:37 +00:00
|
|
|
if (!imageModel.IsImageSaved())
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
TCHAR programname[20];
|
|
|
|
TCHAR saveprompttext[100];
|
|
|
|
TCHAR temptext[500];
|
|
|
|
LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
|
|
|
|
LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, saveprompttext, SIZEOF(saveprompttext));
|
|
|
|
_stprintf(temptext, saveprompttext, filename);
|
|
|
|
switch (MessageBox(temptext, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDNO:
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.imageSaved = TRUE; //TODO: move to ImageModel
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDYES:
|
|
|
|
saveImage(FALSE);
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDCANCEL:
|
|
|
|
reset = FALSE;
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-07-07 11:56:37 +00:00
|
|
|
if (reset && imageModel.IsImageSaved()) //TODO: move to ImageModel
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Clear();
|
|
|
|
imageModel.ClearHistory();
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
case IDM_FILEOPEN:
|
|
|
|
if (GetOpenFileName(&ofn) != 0)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
HBITMAP bmNew = NULL;
|
|
|
|
LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
|
|
|
|
if (bmNew != NULL)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
UpdateApplicationProperties(bmNew, ofn.lpstrFileTitle, ofn.lpstrFileTitle);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDM_FILESAVE:
|
|
|
|
saveImage(TRUE);
|
|
|
|
break;
|
|
|
|
case IDM_FILESAVEAS:
|
|
|
|
saveImage(FALSE);
|
|
|
|
break;
|
|
|
|
case IDM_FILEASWALLPAPERPLANE:
|
|
|
|
SetWallpaper(filepathname, 1, 1);
|
|
|
|
break;
|
|
|
|
case IDM_FILEASWALLPAPERCENTERED:
|
|
|
|
SetWallpaper(filepathname, 1, 0);
|
|
|
|
break;
|
|
|
|
case IDM_FILEASWALLPAPERSTRETCHED:
|
|
|
|
SetWallpaper(filepathname, 2, 0);
|
|
|
|
break;
|
|
|
|
case IDM_EDITUNDO:
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Undo();
|
2015-07-07 10:42:49 +00:00
|
|
|
imageArea.Invalidate(FALSE);
|
|
|
|
break;
|
|
|
|
case IDM_EDITREDO:
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Redo();
|
2015-07-07 10:42:49 +00:00
|
|
|
imageArea.Invalidate(FALSE);
|
|
|
|
break;
|
|
|
|
case IDM_EDITCOPY:
|
|
|
|
OpenClipboard();
|
|
|
|
EmptyClipboard();
|
2015-07-09 09:48:01 +00:00
|
|
|
SetClipboardData(CF_BITMAP, CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
|
2015-07-07 10:42:49 +00:00
|
|
|
CloseClipboard();
|
|
|
|
break;
|
|
|
|
case IDM_EDITCUT:
|
|
|
|
/* Copy */
|
|
|
|
SendMessage(WM_COMMAND, IDM_EDITCOPY, 0);
|
|
|
|
/* Delete selection */
|
|
|
|
SendMessage(WM_COMMAND, IDM_EDITDELETESELECTION, 0);
|
|
|
|
break;
|
|
|
|
case IDM_EDITPASTE:
|
|
|
|
OpenClipboard();
|
|
|
|
if (GetClipboardData(CF_BITMAP) != NULL)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
InsertSelectionFromHBITMAP((HBITMAP) GetClipboardData(CF_BITMAP), m_hWnd);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
2015-07-07 10:42:49 +00:00
|
|
|
CloseClipboard();
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDM_EDITDELETESELECTION:
|
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
/* remove selection window and already painted content using undo */
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Undo();
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
case IDM_EDITSELECTALL:
|
|
|
|
{
|
|
|
|
HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
|
2015-07-07 11:44:50 +00:00
|
|
|
SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
|
|
|
|
toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
|
2015-07-07 11:56:37 +00:00
|
|
|
//TODO: do this properly
|
2015-07-07 11:15:24 +00:00
|
|
|
startPaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
|
2015-07-07 11:56:37 +00:00
|
|
|
whilePaintingL(hDrawingDC, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
|
|
|
|
endPaintingL(hDrawingDC, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
|
2015-07-07 10:42:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IDM_EDITCOPYTO:
|
|
|
|
if (GetSaveFileName(&ofn) != 0)
|
2015-07-09 09:48:01 +00:00
|
|
|
SaveDIBToFile(selectionModel.GetBitmap(), ofn.lpstrFile, hDrawingDC, NULL, NULL, fileHPPM, fileVPPM);
|
2015-07-07 10:42:49 +00:00
|
|
|
break;
|
|
|
|
case IDM_EDITPASTEFROM:
|
|
|
|
if (GetOpenFileName(&ofn) != 0)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
HBITMAP bmNew = NULL;
|
|
|
|
LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
|
|
|
|
if (bmNew != NULL)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
InsertSelectionFromHBITMAP(bmNew, m_hWnd);
|
|
|
|
DeleteObject(bmNew);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDM_COLORSEDITPALETTE:
|
|
|
|
if (ChooseColor(&choosecolor))
|
2015-07-07 11:15:24 +00:00
|
|
|
paletteModel.SetFgColor(choosecolor.rgbResult);
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDM_COLORSMODERNPALETTE:
|
2015-07-07 11:15:24 +00:00
|
|
|
paletteModel.SelectPalette(1);
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDM_COLORSOLDPALETTE:
|
2015-07-07 11:15:24 +00:00
|
|
|
paletteModel.SelectPalette(2);
|
2015-07-07 10:42:49 +00:00
|
|
|
break;
|
|
|
|
case IDM_IMAGEINVERTCOLORS:
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.InvertColors();
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDM_IMAGEDELETEIMAGE:
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.CopyPrevious();
|
|
|
|
Rect(hDrawingDC, 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE);
|
2015-07-07 10:42:49 +00:00
|
|
|
imageArea.Invalidate(FALSE);
|
|
|
|
break;
|
|
|
|
case IDM_IMAGEROTATEMIRROR:
|
|
|
|
switch (mirrorRotateDlg())
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
case 1: /* flip horizontally */
|
|
|
|
if (selectionWindow.IsWindowVisible())
|
2015-07-09 09:48:01 +00:00
|
|
|
selectionModel.FlipHorizontally();
|
2015-07-07 10:42:49 +00:00
|
|
|
else
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.CopyPrevious();
|
|
|
|
StretchBlt(hDrawingDC, imageModel.GetWidth() - 1, 0, -imageModel.GetWidth(), imageModel.GetHeight(), hDrawingDC, 0, 0,
|
|
|
|
imageModel.GetWidth(), imageModel.GetHeight(), SRCCOPY);
|
2015-07-07 10:42:49 +00:00
|
|
|
imageArea.Invalidate(FALSE);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case 2: /* flip vertically */
|
|
|
|
if (selectionWindow.IsWindowVisible())
|
2015-07-09 09:48:01 +00:00
|
|
|
selectionModel.FlipVertically();
|
2015-07-07 10:42:49 +00:00
|
|
|
else
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.CopyPrevious();
|
|
|
|
StretchBlt(hDrawingDC, 0, imageModel.GetHeight() - 1, imageModel.GetWidth(), -imageModel.GetHeight(), hDrawingDC, 0, 0,
|
|
|
|
imageModel.GetWidth(), imageModel.GetHeight(), SRCCOPY);
|
2015-07-07 10:42:49 +00:00
|
|
|
imageArea.Invalidate(FALSE);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case 3: /* rotate 90 degrees */
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case 4: /* rotate 180 degrees */
|
|
|
|
if (selectionWindow.IsWindowVisible())
|
2015-07-09 09:48:01 +00:00
|
|
|
selectionModel.RotateNTimes90Degrees(2);
|
2015-07-07 10:42:49 +00:00
|
|
|
else
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.CopyPrevious();
|
|
|
|
StretchBlt(hDrawingDC, imageModel.GetWidth() - 1, imageModel.GetHeight() - 1, -imageModel.GetWidth(), -imageModel.GetHeight(), hDrawingDC,
|
|
|
|
0, 0, imageModel.GetWidth(), imageModel.GetHeight(), SRCCOPY);
|
2015-07-07 10:42:49 +00:00
|
|
|
imageArea.Invalidate(FALSE);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
case 5: /* rotate 270 degrees */
|
2015-05-08 16:02:36 +00:00
|
|
|
break;
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDM_IMAGEATTRIBUTES:
|
|
|
|
{
|
|
|
|
if (attributesDlg())
|
|
|
|
{
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.Crop(widthSetInDlg, heightSetInDlg, 0, 0);
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IDM_IMAGESTRETCHSKEW:
|
|
|
|
{
|
|
|
|
if (changeSizeDlg())
|
|
|
|
{
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.StretchSkew(stretchSkew.percentage.x, stretchSkew.percentage.y,
|
|
|
|
stretchSkew.angle.x, stretchSkew.angle.y);
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IDM_IMAGEDRAWOPAQUE:
|
2015-07-07 11:15:24 +00:00
|
|
|
toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
|
2015-07-07 10:42:49 +00:00
|
|
|
break;
|
|
|
|
case IDM_IMAGECROP:
|
2015-07-09 09:48:01 +00:00
|
|
|
imageModel.Insert((HBITMAP) CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
|
2015-07-07 10:42:49 +00:00
|
|
|
break;
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDM_VIEWTOOLBOX:
|
|
|
|
toolBoxContainer.ShowWindow(toolBoxContainer.IsWindowVisible() ? SW_HIDE : SW_SHOW);
|
|
|
|
alignChildrenToMainWindow();
|
|
|
|
break;
|
|
|
|
case IDM_VIEWCOLORPALETTE:
|
|
|
|
paletteWindow.ShowWindow(paletteWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
|
|
|
|
alignChildrenToMainWindow();
|
|
|
|
break;
|
|
|
|
case IDM_VIEWSTATUSBAR:
|
|
|
|
::ShowWindow(hStatusBar, ::IsWindowVisible(hStatusBar) ? SW_HIDE : SW_SHOW);
|
|
|
|
alignChildrenToMainWindow();
|
|
|
|
break;
|
|
|
|
case IDM_FORMATICONBAR:
|
|
|
|
textEditWindow.ShowWindow(textEditWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDM_VIEWSHOWGRID:
|
|
|
|
showGrid = !showGrid;
|
|
|
|
imageArea.Invalidate(FALSE);
|
|
|
|
break;
|
|
|
|
case IDM_VIEWSHOWMINIATURE:
|
|
|
|
showMiniature = !showMiniature;
|
|
|
|
miniature.ShowWindow(showMiniature ? SW_SHOW : SW_HIDE);
|
|
|
|
break;
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
case IDM_VIEWZOOM125:
|
|
|
|
zoomTo(125, 0, 0);
|
|
|
|
break;
|
|
|
|
case IDM_VIEWZOOM25:
|
|
|
|
zoomTo(250, 0, 0);
|
|
|
|
break;
|
|
|
|
case IDM_VIEWZOOM50:
|
|
|
|
zoomTo(500, 0, 0);
|
|
|
|
break;
|
|
|
|
case IDM_VIEWZOOM100:
|
|
|
|
zoomTo(1000, 0, 0);
|
|
|
|
break;
|
|
|
|
case IDM_VIEWZOOM200:
|
|
|
|
zoomTo(2000, 0, 0);
|
|
|
|
break;
|
|
|
|
case IDM_VIEWZOOM400:
|
|
|
|
zoomTo(4000, 0, 0);
|
|
|
|
break;
|
|
|
|
case IDM_VIEWZOOM800:
|
|
|
|
zoomTo(8000, 0, 0);
|
|
|
|
break;
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|