1 /* 2 * PROJECT: PAINT for ReactOS 3 * LICENSE: LGPL 4 * FILE: base/applications/mspaint/sizebox.cpp 5 * PURPOSE: Window procedure of the size boxes 6 * PROGRAMMERS: Benedikt Freisen 7 * Katayama Hirofumi MZ 8 */ 9 10 /* INCLUDES *********************************************************/ 11 12 #include "precomp.h" 13 14 /* FUNCTIONS ********************************************************/ 15 16 static BOOL resizing = FALSE; 17 static short xOrig; 18 static short yOrig; 19 20 LRESULT CSizeboxWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 21 { 22 if ((m_hWnd == sizeboxLeftTop.m_hWnd) || (m_hWnd == sizeboxRightBottom.m_hWnd)) 23 SetCursor(LoadCursor(NULL, IDC_SIZENWSE)); 24 if ((m_hWnd == sizeboxLeftBottom.m_hWnd) || (m_hWnd == sizeboxRightTop.m_hWnd)) 25 SetCursor(LoadCursor(NULL, IDC_SIZENESW)); 26 if ((m_hWnd == sizeboxLeftCenter.m_hWnd) || (m_hWnd == sizeboxRightCenter.m_hWnd)) 27 SetCursor(LoadCursor(NULL, IDC_SIZEWE)); 28 if ((m_hWnd == sizeboxCenterTop.m_hWnd) || (m_hWnd == sizeboxCenterBottom.m_hWnd)) 29 SetCursor(LoadCursor(NULL, IDC_SIZENS)); 30 return 0; 31 } 32 33 LRESULT CSizeboxWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 34 { 35 resizing = TRUE; 36 xOrig = GET_X_LPARAM(lParam); 37 yOrig = GET_Y_LPARAM(lParam); 38 SetCapture(); 39 return 0; 40 } 41 42 LRESULT CSizeboxWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 43 { 44 if (resizing) 45 { 46 CString strSize; 47 short xRel; 48 short yRel; 49 int imgXRes = imageModel.GetWidth(); 50 int imgYRes = imageModel.GetHeight(); 51 xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom(); 52 yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom(); 53 if (m_hWnd == sizeboxLeftTop.m_hWnd) 54 strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes - yRel); 55 if (m_hWnd == sizeboxCenterTop.m_hWnd) 56 strSize.Format(_T("%d x %d"), imgXRes, imgYRes - yRel); 57 if (m_hWnd == sizeboxRightTop.m_hWnd) 58 strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes - yRel); 59 if (m_hWnd == sizeboxLeftCenter.m_hWnd) 60 strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes); 61 if (m_hWnd == sizeboxRightCenter.m_hWnd) 62 strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes); 63 if (m_hWnd == sizeboxLeftBottom.m_hWnd) 64 strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes + yRel); 65 if (m_hWnd == sizeboxCenterBottom.m_hWnd) 66 strSize.Format(_T("%d x %d"), imgXRes, imgYRes + yRel); 67 if (m_hWnd == sizeboxRightBottom.m_hWnd) 68 strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes + yRel); 69 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize); 70 } 71 return 0; 72 } 73 74 LRESULT CSizeboxWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 75 { 76 if (resizing) 77 { 78 short xRel; 79 short yRel; 80 int imgXRes = imageModel.GetWidth(); 81 int imgYRes = imageModel.GetHeight(); 82 xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom(); 83 yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom(); 84 if (m_hWnd == sizeboxLeftTop) 85 imageModel.Crop(imgXRes - xRel, imgYRes - yRel, xRel, yRel); 86 if (m_hWnd == sizeboxCenterTop.m_hWnd) 87 imageModel.Crop(imgXRes, imgYRes - yRel, 0, yRel); 88 if (m_hWnd == sizeboxRightTop.m_hWnd) 89 imageModel.Crop(imgXRes + xRel, imgYRes - yRel, 0, yRel); 90 if (m_hWnd == sizeboxLeftCenter.m_hWnd) 91 imageModel.Crop(imgXRes - xRel, imgYRes, xRel, 0); 92 if (m_hWnd == sizeboxRightCenter.m_hWnd) 93 imageModel.Crop(imgXRes + xRel, imgYRes, 0, 0); 94 if (m_hWnd == sizeboxLeftBottom.m_hWnd) 95 imageModel.Crop(imgXRes - xRel, imgYRes + yRel, xRel, 0); 96 if (m_hWnd == sizeboxCenterBottom.m_hWnd) 97 imageModel.Crop(imgXRes, imgYRes + yRel, 0, 0); 98 if (m_hWnd == sizeboxRightBottom.m_hWnd) 99 imageModel.Crop(imgXRes + xRel, imgYRes + yRel, 0, 0); 100 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) _T("")); 101 } 102 resizing = FALSE; 103 ReleaseCapture(); 104 return 0; 105 } 106 107 LRESULT CSizeboxWindow::OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 108 { 109 resizing = FALSE; 110 return 0; 111 } 112 113 LRESULT CSizeboxWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 114 { 115 if (wParam == VK_ESCAPE) 116 { 117 if (GetCapture() == m_hWnd) 118 { 119 ReleaseCapture(); 120 } 121 } 122 return 0; 123 } 124