891d2dd871f12ede0f60724922114240ca6dc0c4
[reactos.git] / reactos / base / applications / mspaint / scrollbox.cpp
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/mspaint/scrollbox.cpp
5 * PURPOSE: Functionality surrounding the scroll box window class
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include "precomp.h"
12
13 /* FUNCTIONS ********************************************************/
14
15 void
16 UpdateScrollbox()
17 {
18 RECT clientRectScrollbox;
19 RECT clientRectImageArea;
20 SCROLLINFO si;
21 scrollboxWindow.GetClientRect(&clientRectScrollbox);
22 imageArea.GetClientRect(&clientRectImageArea);
23 si.cbSize = sizeof(SCROLLINFO);
24 si.fMask = SIF_PAGE | SIF_RANGE;
25 si.nMax = clientRectImageArea.right + 6 - 1;
26 si.nMin = 0;
27 si.nPage = clientRectScrollbox.right;
28 scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
29 scrollboxWindow.GetClientRect(&clientRectScrollbox);
30 si.nMax = clientRectImageArea.bottom + 6 - 1;
31 si.nPage = clientRectScrollbox.bottom;
32 scrollboxWindow.SetScrollInfo(SB_VERT, &si);
33 scrlClientWindow.MoveWindow(
34 -scrollboxWindow.GetScrollPos(SB_HORZ), -scrollboxWindow.GetScrollPos(SB_VERT),
35 max(clientRectImageArea.right + 6, clientRectScrollbox.right),
36 max(clientRectImageArea.bottom + 6, clientRectScrollbox.bottom), TRUE);
37 }
38
39 LRESULT CScrollboxWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
40 {
41 if (m_hWnd == scrollboxWindow.m_hWnd)
42 {
43 UpdateScrollbox();
44 }
45 return 0;
46 }
47
48 LRESULT CScrollboxWindow::OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
49 {
50 if (m_hWnd == scrollboxWindow.m_hWnd)
51 {
52 SCROLLINFO si;
53 si.cbSize = sizeof(SCROLLINFO);
54 si.fMask = SIF_ALL;
55 scrollboxWindow.GetScrollInfo(SB_HORZ, &si);
56 switch (LOWORD(wParam))
57 {
58 case SB_THUMBTRACK:
59 case SB_THUMBPOSITION:
60 si.nPos = HIWORD(wParam);
61 break;
62 case SB_LINELEFT:
63 si.nPos -= 5;
64 break;
65 case SB_LINERIGHT:
66 si.nPos += 5;
67 break;
68 case SB_PAGELEFT:
69 si.nPos -= si.nPage;
70 break;
71 case SB_PAGERIGHT:
72 si.nPos += si.nPage;
73 break;
74 }
75 scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
76 scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
77 -scrollboxWindow.GetScrollPos(SB_VERT), imageModel.GetWidth() * toolsModel.GetZoom() / 1000 + 6,
78 imageModel.GetHeight() * toolsModel.GetZoom() / 1000 + 6, TRUE);
79 }
80 return 0;
81 }
82
83 LRESULT CScrollboxWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
84 {
85 if (m_hWnd == scrollboxWindow.m_hWnd)
86 {
87 SCROLLINFO si;
88 si.cbSize = sizeof(SCROLLINFO);
89 si.fMask = SIF_ALL;
90 scrollboxWindow.GetScrollInfo(SB_VERT, &si);
91 switch (LOWORD(wParam))
92 {
93 case SB_THUMBTRACK:
94 case SB_THUMBPOSITION:
95 si.nPos = HIWORD(wParam);
96 break;
97 case SB_LINEUP:
98 si.nPos -= 5;
99 break;
100 case SB_LINEDOWN:
101 si.nPos += 5;
102 break;
103 case SB_PAGEUP:
104 si.nPos -= si.nPage;
105 break;
106 case SB_PAGEDOWN:
107 si.nPos += si.nPage;
108 break;
109 }
110 scrollboxWindow.SetScrollInfo(SB_VERT, &si);
111 scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
112 -scrollboxWindow.GetScrollPos(SB_VERT), imageModel.GetWidth() * toolsModel.GetZoom() / 1000 + 6,
113 imageModel.GetHeight() * toolsModel.GetZoom() / 1000 + 6, TRUE);
114 }
115 return 0;
116 }