xref: /reactos/base/applications/mspaint/canvas.h (revision b8598e09)
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 OnEndDraw(BOOL bCancel);
46     VOID updateScrollRange();
47     VOID updateScrollPos(INT x = 0, INT y = 0);
48 
49     VOID ImageToCanvas(POINT& pt);
50     VOID ImageToCanvas(RECT& rc);
51     VOID CanvasToImage(POINT& pt);
52     VOID CanvasToImage(RECT& rc);
53     VOID GetImageRect(RECT& rc);
54     VOID getNewZoomRect(CRect& rcView, INT newZoom, CPoint ptTarget);
55     VOID zoomTo(INT newZoom, LONG left = 0, LONG top = 0);
56 
57 protected:
58     HITTEST m_hitCanvasSizeBox;
59     POINT m_ptOrig; // The origin of drag start
60     HBITMAP m_ahbmCached[2]; // The cached buffer bitmaps
61     CRect m_rcResizing; // Resizing rectagle
62 
63     HITTEST CanvasHitTest(POINT pt);
64     RECT GetBaseRect();
65     VOID DoDraw(HDC hDC, RECT& rcClient, RECT& rcPaint);
66     VOID OnHVScroll(WPARAM wParam, INT fnBar);
67 
68     LRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
69     LRESULT OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
70     LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
71     LRESULT OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
72     LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
73     LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
74     LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
75     LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
76     LRESULT OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
77     LRESULT OnCancelMode(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
78     LRESULT OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
79     LRESULT OnCtlColorEdit(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
80     LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
81 
82     UINT m_nMouseDownMsg = 0;
83     LRESULT OnButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
84     LRESULT OnButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
85     LRESULT OnButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
86 };
87