xref: /reactos/base/applications/mspaint/canvas.h (revision 565bf9e3)
1 /*
2  * PROJECT:    PAINT for ReactOS
3  * LICENSE:    LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4  * PURPOSE:    Providing the canvas window class
5  * COPYRIGHT:  Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
6  */
7 
8 #pragma once
9 
10 class CCanvasWindow : public CWindowImpl<CCanvasWindow>
11 {
12 public:
13     DECLARE_WND_CLASS_EX(L"ReactOSPaintCanvas", CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW,
14                          COLOR_APPWORKSPACE)
15 
16     BEGIN_MSG_MAP(CCanvasWindow)
17         MESSAGE_HANDLER(WM_SIZE, OnSize)
18         MESSAGE_HANDLER(WM_PAINT, OnPaint)
19         MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
20         MESSAGE_HANDLER(WM_HSCROLL, OnHScroll)
21         MESSAGE_HANDLER(WM_VSCROLL, OnVScroll)
22         MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
23         MESSAGE_HANDLER(WM_LBUTTONDOWN, OnButtonDown)
24         MESSAGE_HANDLER(WM_RBUTTONDOWN, OnButtonDown)
25         MESSAGE_HANDLER(WM_MBUTTONDOWN, OnButtonDown)
26         MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnButtonDblClk)
27         MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnButtonDblClk)
28         MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
29         MESSAGE_HANDLER(WM_LBUTTONUP, OnButtonUp)
30         MESSAGE_HANDLER(WM_RBUTTONUP, OnButtonUp)
31         MESSAGE_HANDLER(WM_MBUTTONUP, OnButtonUp)
32         MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
33         MESSAGE_HANDLER(WM_MOUSEWHEEL, OnMouseWheel)
34         MESSAGE_HANDLER(WM_CANCELMODE, OnCancelMode)
35         MESSAGE_HANDLER(WM_CAPTURECHANGED, OnCaptureChanged)
36         MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnCtlColorEdit)
37         MESSAGE_HANDLER(WM_PALETTEMODELCOLORCHANGED, OnPaletteModelColorChanged)
38     END_MSG_MAP()
39 
40     CCanvasWindow();
41     virtual ~CCanvasWindow();
42 
43     BOOL m_drawing;
44 
45     VOID cancelDrawing();
46     VOID finishDrawing();
47     VOID updateScrollRange();
48     VOID updateScrollPos(INT x = 0, INT y = 0);
49 
50     VOID ImageToCanvas(POINT& pt);
51     VOID ImageToCanvas(RECT& rc);
52     VOID CanvasToImage(POINT& pt, BOOL bZoomed = FALSE);
53     VOID CanvasToImage(RECT& rc, BOOL bZoomed = FALSE);
54     VOID GetImageRect(RECT& rc);
55     VOID MoveSelection(INT xDelta, INT yDelta);
56     VOID getNewZoomRect(CRect& rcView, INT newZoom, CPoint ptTarget);
57     VOID zoomTo(INT newZoom, LONG left = 0, LONG top = 0);
58 
59 protected:
60     HITTEST m_hitSelection;
61     HITTEST m_hitCanvasSizeBox;
62     POINT m_ptOrig; // The origin of drag start
63     HBITMAP m_ahbmCached[2]; // The cached buffer bitmaps
64     CRect m_rcResizing; // Resizing rectagle
65 
66     HITTEST CanvasHitTest(POINT pt);
67     RECT GetBaseRect();
68     VOID DoDraw(HDC hDC, RECT& rcClient, RECT& rcPaint);
69     VOID OnHVScroll(WPARAM wParam, INT fnBar);
70 
71     HITTEST SelectionHitTest(POINT ptImage);
72     VOID StartSelectionDrag(HITTEST hit, POINT ptImage);
73     VOID SelectionDragging(POINT ptImage);
74     VOID EndSelectionDrag(POINT ptImage);
75 
76     LRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
77     LRESULT OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
78     LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
79     LRESULT OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
80     LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
81     LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
82     LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
83     LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
84     LRESULT OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
85     LRESULT OnCancelMode(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
86     LRESULT OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
87     LRESULT OnCtlColorEdit(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
88     LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
89 
90     UINT m_nMouseDownMsg = 0;
91     LRESULT OnButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
92     LRESULT OnButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
93     LRESULT OnButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
94 };
95