ReactOS  0.4.15-dev-4603-gb922b6d
scrollbox.cpp
Go to the documentation of this file.
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 #include <atltypes.h>
13 
14 /*
15  * Scrollbar functional modes:
16  * 0 view < canvas
17  * 1 view < canvas + scroll width
18  * 2 view >= canvas + scroll width
19  *
20  * Matrix of scrollbar presence (VERTICAL,HORIZONTAL) given by
21  * vertical & horizontal scrollbar modes (view:canvas ratio):
22  *
23  * horizontal mode
24  * | 0 | 1 | 2
25  * vertical ---+-------------+-------------+------------
26  * mode 0 | TRUE,TRUE | TRUE,TRUE | TRUE,FALSE
27  * ---+-------------+-------------+------------
28  * 1 | TRUE,TRUE | FALSE,FALSE | FALSE,FALSE
29  * ---+-------------+-------------+------------
30  * 2 | FALSE,TRUE | FALSE,FALSE | FALSE,FALSE
31  */
32 
34 {
37 };
38 
40 {
41  { { TRUE,TRUE }, { TRUE,TRUE }, { TRUE,FALSE } },
42  { { TRUE,TRUE }, { FALSE,FALSE }, { FALSE,FALSE } },
43  { { FALSE,TRUE }, { FALSE,FALSE }, { FALSE,FALSE } }
44 };
45 
48 
49 
50 /* FUNCTIONS ********************************************************/
51 
52 void
54 {
55  CRect tempRect;
56  CSize sizeImageArea;
57  CSize sizeScrollBox;
58  INT vmode, hmode;
59  SCROLLINFO si;
60 
61  scrollboxWindow.GetWindowRect(&tempRect);
62  sizeScrollBox = CSize(tempRect.Width(), tempRect.Height());
63 
64  if (imageArea.IsWindow())
65  imageArea.GetClientRect(&tempRect);
66  sizeImageArea = CSize(tempRect.Width(), tempRect.Height());
67  sizeImageArea += CSize(GRIP_SIZE * 2, GRIP_SIZE * 2);
68 
69  /* show/hide the scrollbars */
70  vmode = (sizeScrollBox.cy < sizeImageArea.cy ? 0 :
71  (sizeScrollBox.cy < sizeImageArea.cy + HSCROLL_WIDTH ? 1 : 2));
72  hmode = (sizeScrollBox.cx < sizeImageArea.cx ? 0 :
73  (sizeScrollBox.cx < sizeImageArea.cx + VSCROLL_WIDTH ? 1 : 2));
74  scrollboxWindow.ShowScrollBar(SB_VERT, sp_mx[vmode][hmode].bVert);
75  scrollboxWindow.ShowScrollBar(SB_HORZ, sp_mx[vmode][hmode].bHoriz);
76 
77  si.cbSize = sizeof(SCROLLINFO);
78  si.fMask = SIF_PAGE | SIF_RANGE;
79  si.nMin = 0;
80 
81  si.nMax = sizeImageArea.cx +
82  (sp_mx[vmode][hmode].bVert == TRUE ? HSCROLL_WIDTH : 0);
83  si.nPage = sizeScrollBox.cx;
84  scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
85 
86  si.nMax = sizeImageArea.cy +
87  (sp_mx[vmode][hmode].bHoriz == TRUE ? VSCROLL_WIDTH : 0);
88  si.nPage = sizeScrollBox.cy;
89  scrollboxWindow.SetScrollInfo(SB_VERT, &si);
90 
91  if (scrlClientWindow.IsWindow())
92  {
93  scrlClientWindow.MoveWindow(
94  -scrollboxWindow.GetScrollPos(SB_HORZ), -scrollboxWindow.GetScrollPos(SB_VERT),
95  sizeImageArea.cx, sizeImageArea.cy, TRUE);
96  }
97 }
98 
100 {
101  if (m_hWnd && m_hWnd == scrollboxWindow.m_hWnd)
102  {
103  UpdateScrollbox();
104  }
105  return 0;
106 }
107 
109 {
110  if (m_hWnd == scrollboxWindow.m_hWnd)
111  {
112  SCROLLINFO si;
113  si.cbSize = sizeof(SCROLLINFO);
114  si.fMask = SIF_ALL;
115  scrollboxWindow.GetScrollInfo(SB_HORZ, &si);
116  switch (LOWORD(wParam))
117  {
118  case SB_THUMBTRACK:
119  case SB_THUMBPOSITION:
120  si.nPos = HIWORD(wParam);
121  break;
122  case SB_LINELEFT:
123  si.nPos -= 5;
124  break;
125  case SB_LINERIGHT:
126  si.nPos += 5;
127  break;
128  case SB_PAGELEFT:
129  si.nPos -= si.nPage;
130  break;
131  case SB_PAGERIGHT:
132  si.nPos += si.nPage;
133  break;
134  }
135  scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
136  scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
137  -scrollboxWindow.GetScrollPos(SB_VERT),
140  }
141  return 0;
142 }
143 
145 {
146  if (m_hWnd == scrollboxWindow.m_hWnd)
147  {
148  SCROLLINFO si;
149  si.cbSize = sizeof(SCROLLINFO);
150  si.fMask = SIF_ALL;
151  scrollboxWindow.GetScrollInfo(SB_VERT, &si);
152  switch (LOWORD(wParam))
153  {
154  case SB_THUMBTRACK:
155  case SB_THUMBPOSITION:
156  si.nPos = HIWORD(wParam);
157  break;
158  case SB_LINEUP:
159  si.nPos -= 5;
160  break;
161  case SB_LINEDOWN:
162  si.nPos += 5;
163  break;
164  case SB_PAGEUP:
165  si.nPos -= si.nPage;
166  break;
167  case SB_PAGEDOWN:
168  si.nPos += si.nPage;
169  break;
170  }
171  scrollboxWindow.SetScrollInfo(SB_VERT, &si);
172  scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
173  -scrollboxWindow.GetScrollPos(SB_VERT),
176  }
177  return 0;
178 }
179 
181 {
182  selectionWindow.ShowWindow(SW_HIDE);
183 
184  switch (toolsModel.GetActiveTool())
185  {
186  case TOOL_BEZIER:
187  case TOOL_SHAPE:
188  if (ToolBase::pointSP != 0)
189  {
192  }
193  break;
194 
195  default:
196  break;
197  }
198 
199  toolsModel.resetTool(); // resets the point-buffer of the polygon and bezier functions
200  return 0;
201 }
202 
204 {
206 }
static int Zoomed(int xy)
Definition: common.h:37
#define SB_PAGEDOWN
Definition: winuser.h:569
ToolsModel toolsModel
Definition: main.cpp:18
#define SB_PAGEUP
Definition: winuser.h:568
#define SM_CYHSCROLL
Definition: winuser.h:956
#define SIF_RANGE
Definition: winuser.h:1225
void resetTool()
Definition: toolsmodel.cpp:231
int Width() const
Definition: atltypes.h:407
#define SB_VERT
Definition: winuser.h:553
#define TRUE
Definition: types.h:120
#define SW_HIDE
Definition: winuser.h:762
void OnCancelDraw()
Definition: toolsmodel.cpp:215
#define SB_HORZ
Definition: winuser.h:552
BOOL IsWindow() const
Definition: atlwin.h:913
UINT_PTR WPARAM
Definition: windef.h:207
CONST INT HSCROLL_WIDTH
Definition: scrollbox.cpp:46
int32_t INT
Definition: typedefs.h:58
LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: scrollbox.cpp:144
#define SIF_PAGE
Definition: winuser.h:1223
LRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: scrollbox.cpp:99
WPARAM wParam
Definition: combotst.c:138
CImgAreaWindow imageArea
Definition: main.cpp:72
LRESULT OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: scrollbox.cpp:203
CONST INT VSCROLL_WIDTH
Definition: scrollbox.cpp:47
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL GetClientRect(LPRECT lpRect) const
Definition: atlwin.h:507
#define SB_THUMBPOSITION
Definition: winuser.h:572
LONG cx
Definition: windef.h:334
LONG_PTR LPARAM
Definition: windef.h:208
int Height() const
Definition: atltypes.h:318
int GetWidth() const
Definition: history.cpp:215
struct tagSCROLLINFO SCROLLINFO
static INT pointSP
Definition: toolsmodel.h:39
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: scrollbox.cpp:180
CScrollboxWindow scrlClientWindow
Definition: main.cpp:70
#define SB_THUMBTRACK
Definition: winuser.h:573
int WINAPI GetSystemMetrics(_In_ int)
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:76
#define GRIP_SIZE
Definition: common.h:13
#define SB_PAGELEFT
Definition: winuser.h:570
ImageModel imageModel
Definition: main.cpp:32
#define SB_LINERIGHT
Definition: winuser.h:567
HWND WINAPI GetParent(_In_ HWND)
int GetHeight() const
Definition: history.cpp:220
CONST ScrollbarPresence sp_mx[3][3]
Definition: scrollbox.cpp:39
#define SB_PAGERIGHT
Definition: winuser.h:571
unsigned int UINT
Definition: ndis.h:50
#define SB_LINEDOWN
Definition: winuser.h:565
#define SB_LINEUP
Definition: winuser.h:564
#define SM_CXVSCROLL
Definition: winuser.h:955
CScrollboxWindow scrollboxWindow
Definition: main.cpp:69
void UpdateScrollbox()
Definition: scrollbox.cpp:53
BOOL Invalidate(BOOL bErase=TRUE)
Definition: atlwin.h:862
#define SendMessage
Definition: winuser.h:5823
#define HIWORD(l)
Definition: typedefs.h:247
#define SB_LINELEFT
Definition: winuser.h:566
LONG_PTR LRESULT
Definition: windef.h:209
LRESULT OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: scrollbox.cpp:108
LONG cy
Definition: windef.h:335
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define CONST
Definition: pedump.c:81
CSelectionWindow selectionWindow
Definition: main.cpp:71
#define SIF_ALL
Definition: winuser.h:1222