2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/mspaint/selection.cpp
5 * PURPOSE: Window procedure of the selection window
6 * PROGRAMMERS: Benedikt Freisen
12 CSelectionWindow selectionWindow
;
14 /* FUNCTIONS ********************************************************/
16 const LPCTSTR
CSelectionWindow::m_lpszCursorLUT
[9] = { /* action to mouse cursor lookup table */
19 IDC_SIZENWSE
, IDC_SIZENS
, IDC_SIZENESW
,
20 IDC_SIZEWE
, IDC_SIZEWE
,
21 IDC_SIZENESW
, IDC_SIZENS
, IDC_SIZENWSE
24 void CSelectionWindow::ForceRefreshSelectionContents()
26 if (::IsWindowVisible(selectionWindow
))
28 imageModel
.ResetToPrevious();
29 imageModel
.DrawSelectionBackground(m_rgbBack
);
30 selectionModel
.DrawSelection(imageModel
.GetDC(), paletteModel
.GetBgColor(), toolsModel
.IsBackgroundTransparent());
34 int CSelectionWindow::IdentifyCorner(int iXPos
, int iYPos
, int iWidth
, int iHeight
)
39 LRESULT
CSelectionWindow::OnPaint(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
42 HDC hDC
= BeginPaint(&ps
);
46 GetClientRect(&rcClient
);
47 drawSizeBoxes(hDC
, &rcClient
, TRUE
, &ps
.rcPaint
);
53 LRESULT
CSelectionWindow::OnEraseBkgnd(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
55 // do nothing => transparent background
59 LRESULT
CSelectionWindow::OnCreate(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
62 m_iAction
= ACTION_MOVE
;
63 /* update the system selection color */
68 LRESULT
CSelectionWindow::OnSysColorChange(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
70 /* update the system selection color */
75 LRESULT
CSelectionWindow::OnSetCursor(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
78 GetClientRect(&rcClient
);
84 if (!setCursorOnSizeBox(getSizeBoxHitTest(pt
, &rcClient
)))
85 ::SetCursor(::LoadCursor(NULL
, IDC_SIZEALL
));
90 LRESULT
CSelectionWindow::OnLButtonDown(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
92 m_ptPos
.x
= GET_X_LPARAM(lParam
);
93 m_ptPos
.y
= GET_Y_LPARAM(lParam
);
97 if (m_iAction
!= ACTION_MOVE
)
98 SetCursor(LoadCursor(NULL
, m_lpszCursorLUT
[m_iAction
]));
100 imageArea
.InvalidateRect(NULL
, FALSE
);
101 imageArea
.SendMessage(WM_PAINT
, 0, 0);
102 m_rgbBack
= paletteModel
.GetBgColor();
106 LRESULT
CSelectionWindow::OnMouseMove(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
110 imageModel
.ResetToPrevious();
111 imageModel
.DrawSelectionBackground(m_rgbBack
);
112 m_ptFrac
.x
+= GET_X_LPARAM(lParam
) - m_ptPos
.x
;
113 m_ptFrac
.y
+= GET_Y_LPARAM(lParam
) - m_ptPos
.y
;
114 m_ptDelta
.x
+= UnZoomed(m_ptFrac
.x
);
115 m_ptDelta
.y
+= UnZoomed(m_ptFrac
.y
);
116 if (toolsModel
.GetZoom() < 1000)
123 m_ptFrac
.x
-= Zoomed(UnZoomed(m_ptFrac
.x
));
124 m_ptFrac
.y
-= Zoomed(UnZoomed(m_ptFrac
.y
));
126 selectionModel
.ModifyDestRect(m_ptDelta
, m_iAction
);
129 strSize
.Format(_T("%ld x %ld"), selectionModel
.GetDestRectWidth(), selectionModel
.GetDestRectHeight());
130 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) (LPCTSTR
) strSize
);
132 if (m_iAction
!= ACTION_MOVE
)
133 selectionModel
.DrawSelectionStretched(imageModel
.GetDC());
135 selectionModel
.DrawSelection(imageModel
.GetDC(), paletteModel
.GetBgColor(), toolsModel
.IsBackgroundTransparent());
136 imageArea
.InvalidateRect(NULL
, FALSE
);
137 imageArea
.SendMessage(WM_PAINT
, 0, 0);
138 m_ptPos
.x
= GET_X_LPARAM(lParam
);
139 m_ptPos
.y
= GET_Y_LPARAM(lParam
);
143 int w
= Zoomed(selectionModel
.GetDestRectWidth()) + 2 * GRIP_SIZE
;
144 int h
= Zoomed(selectionModel
.GetDestRectHeight()) + 2 * GRIP_SIZE
;
145 m_ptPos
.x
= GET_X_LPARAM(lParam
);
146 m_ptPos
.y
= GET_Y_LPARAM(lParam
);
147 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) NULL
);
148 m_iAction
= IdentifyCorner(m_ptPos
.x
, m_ptPos
.y
, w
, h
);
149 if (m_iAction
!= ACTION_MOVE
)
150 SetCursor(LoadCursor(NULL
, m_lpszCursorLUT
[m_iAction
]));
155 LRESULT
CSelectionWindow::OnMove(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
161 LRESULT
CSelectionWindow::OnLButtonUp(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
167 if (m_iAction
!= ACTION_MOVE
&& toolsModel
.GetActiveTool() != TOOL_TEXT
)
170 imageModel
.DrawSelectionBackground(m_rgbBack
);
171 selectionModel
.ScaleContentsToFit();
172 imageModel
.CopyPrevious();
179 LRESULT
CSelectionWindow::OnCaptureChanged(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
184 if (m_iAction
== ACTION_MOVE
)
186 if (toolsModel
.GetActiveTool() == TOOL_RECTSEL
)
187 imageArea
.cancelDrawing();
193 m_iAction
= ACTION_MOVE
;
200 LRESULT
CSelectionWindow::OnKeyDown(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
202 if (wParam
== VK_ESCAPE
)
204 if (GetCapture() == m_hWnd
)
212 LRESULT
CSelectionWindow::OnPaletteModelColorChanged(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
217 LRESULT
CSelectionWindow::OnToolsModelSettingsChanged(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
222 LRESULT
CSelectionWindow::OnSelectionModelRefreshNeeded(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
224 ForceRefreshSelectionContents();
228 LRESULT
CSelectionWindow::OnMouseWheel(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
230 return ::SendMessage(GetParent(), nMsg
, wParam
, lParam
);
233 LRESULT
CSelectionWindow::OnToolsModelZoomChanged(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)