ReactOS  0.4.11-dev-946-g431643b
sizebox.cpp
Go to the documentation of this file.
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 
21 {
22  if ((m_hWnd == sizeboxLeftTop.m_hWnd) || (m_hWnd == sizeboxRightBottom.m_hWnd))
24  if ((m_hWnd == sizeboxLeftBottom.m_hWnd) || (m_hWnd == sizeboxRightTop.m_hWnd))
26  if ((m_hWnd == sizeboxLeftCenter.m_hWnd) || (m_hWnd == sizeboxRightCenter.m_hWnd))
28  if ((m_hWnd == sizeboxCenterTop.m_hWnd) || (m_hWnd == sizeboxCenterBottom.m_hWnd))
30  return 0;
31 }
32 
34 {
35  resizing = TRUE;
36  xOrig = GET_X_LPARAM(lParam);
37  yOrig = GET_Y_LPARAM(lParam);
38  SetCapture();
39  return 0;
40 }
41 
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);
70  }
71  return 0;
72 }
73 
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);
101  }
102  resizing = FALSE;
103  ReleaseCapture();
104  return 0;
105 }
106 
108 {
109  resizing = FALSE;
110  return 0;
111 }
112 
114 {
115  if (wParam == VK_ESCAPE)
116  {
117  if (GetCapture() == m_hWnd)
118  {
119  ReleaseCapture();
120  }
121  }
122  return 0;
123 }
#define IDC_SIZEWE
Definition: winuser.h:689
ToolsModel toolsModel
Definition: main.cpp:18
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: sizebox.cpp:20
CSizeboxWindow sizeboxRightCenter
Definition: main.cpp:76
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:668
#define VK_ESCAPE
Definition: winuser.h:2168
#define IDC_SIZENESW
Definition: winuser.h:688
WPARAM wParam
Definition: combotst.c:138
#define IDC_SIZENS
Definition: winuser.h:690
int GetZoom()
Definition: toolsmodel.cpp:104
UINT_PTR WPARAM
Definition: windef.h:207
void Crop(int nWidth, int nHeight, int nOffsetX=0, int nOffsetY=0)
Definition: history.cpp:124
static BOOL resizing
Definition: sizebox.cpp:16
CSizeboxWindow sizeboxCenterTop
Definition: main.cpp:73
CSizeboxWindow sizeboxRightTop
Definition: main.cpp:74
#define IDC_SIZENWSE
Definition: winuser.h:687
CSizeboxWindow sizeboxCenterBottom
Definition: main.cpp:78
LONG_PTR LPARAM
Definition: windef.h:208
HWND WINAPI GetCapture(void)
Definition: message.c:2855
smooth NULL
Definition: ftsmooth.c:416
CSizeboxWindow sizeboxRightBottom
Definition: main.cpp:79
#define GET_X_LPARAM(lp)
Definition: precomp.h:67
static short yOrig
Definition: sizebox.cpp:18
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: sizebox.cpp:33
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned int UINT
Definition: ndis.h:50
HWND hStatusBar
Definition: main.cpp:35
LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: sizebox.cpp:113
int GetWidth()
Definition: history.cpp:195
int GetHeight()
Definition: history.cpp:200
#define SB_SETTEXT
Definition: commctrl.h:1919
CSizeboxWindow sizeboxLeftCenter
Definition: main.cpp:75
LRESULT OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: sizebox.cpp:107
ImageModel imageModel
Definition: main.cpp:32
#define LoadCursor
Definition: winuser.h:5678
LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: sizebox.cpp:42
static short xOrig
Definition: sizebox.cpp:17
HWND WINAPI SetCapture(_In_ HWND hWnd)
CSizeboxWindow sizeboxLeftBottom
Definition: main.cpp:77
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: sizebox.cpp:74
#define GET_Y_LPARAM(lp)
Definition: precomp.h:68
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2864
CSizeboxWindow sizeboxLeftTop
Definition: main.cpp:72
#define SendMessage
Definition: winuser.h:5709
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139