ReactOS  0.4.11-dev-946-g431643b
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  CONST INT EXTRASIZE = 5; /* 3 px of selection markers + 2 px of border */
56 
57  CRect tempRect;
58  CSize sizeImageArea;
59  CSize sizeScrollBox;
60  INT vmode, hmode;
61  SCROLLINFO si;
62 
63  scrollboxWindow.GetWindowRect(&tempRect);
64  sizeScrollBox = CSize(tempRect.Width(), tempRect.Height());
65 
66  imageArea.GetClientRect(&tempRect);
67  sizeImageArea = CSize(tempRect.Width(), tempRect.Height());
68  sizeImageArea += CSize(EXTRASIZE * 2, EXTRASIZE * 2);
69 
70  /* show/hide the scrollbars */
71  vmode = (sizeScrollBox.cy < sizeImageArea.cy ? 0 :
72  (sizeScrollBox.cy < sizeImageArea.cy + HSCROLL_WIDTH ? 1 : 2));
73  hmode = (sizeScrollBox.cx < sizeImageArea.cx ? 0 :
74  (sizeScrollBox.cx < sizeImageArea.cx + VSCROLL_WIDTH ? 1 : 2));
75  scrollboxWindow.ShowScrollBar(SB_VERT, sp_mx[vmode][hmode].bVert);
76  scrollboxWindow.ShowScrollBar(SB_HORZ, sp_mx[vmode][hmode].bHoriz);
77 
78  si.cbSize = sizeof(SCROLLINFO);
79  si.fMask = SIF_PAGE | SIF_RANGE;
80  si.nMin = 0;
81 
82  si.nMax = sizeImageArea.cx +
83  (sp_mx[vmode][hmode].bVert == TRUE ? HSCROLL_WIDTH : 0);
84  si.nPage = sizeScrollBox.cx;
85  scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
86 
87  si.nMax = sizeImageArea.cy +
88  (sp_mx[vmode][hmode].bHoriz == TRUE ? VSCROLL_WIDTH : 0);
89  si.nPage = sizeScrollBox.cy;
90  scrollboxWindow.SetScrollInfo(SB_VERT, &si);
91 
92  scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
93  -scrollboxWindow.GetScrollPos(SB_VERT),
94  sizeImageArea.cx, sizeImageArea.cy, TRUE);
95 }
96 
98 {
99  if (m_hWnd == scrollboxWindow.m_hWnd)
100  {
101  UpdateScrollbox();
102  }
103  return 0;
104 }
105 
107 {
108  if (m_hWnd == scrollboxWindow.m_hWnd)
109  {
110  SCROLLINFO si;
111  si.cbSize = sizeof(SCROLLINFO);
112  si.fMask = SIF_ALL;
113  scrollboxWindow.GetScrollInfo(SB_HORZ, &si);
114  switch (LOWORD(wParam))
115  {
116  case SB_THUMBTRACK:
117  case SB_THUMBPOSITION:
118  si.nPos = HIWORD(wParam);
119  break;
120  case SB_LINELEFT:
121  si.nPos -= 5;
122  break;
123  case SB_LINERIGHT:
124  si.nPos += 5;
125  break;
126  case SB_PAGELEFT:
127  si.nPos -= si.nPage;
128  break;
129  case SB_PAGERIGHT:
130  si.nPos += si.nPage;
131  break;
132  }
133  scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
134  scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
135  -scrollboxWindow.GetScrollPos(SB_VERT), imageModel.GetWidth() * toolsModel.GetZoom() / 1000 + 6,
136  imageModel.GetHeight() * toolsModel.GetZoom() / 1000 + 6, TRUE);
137  }
138  return 0;
139 }
140 
142 {
143  if (m_hWnd == scrollboxWindow.m_hWnd)
144  {
145  SCROLLINFO si;
146  si.cbSize = sizeof(SCROLLINFO);
147  si.fMask = SIF_ALL;
148  scrollboxWindow.GetScrollInfo(SB_VERT, &si);
149  switch (LOWORD(wParam))
150  {
151  case SB_THUMBTRACK:
152  case SB_THUMBPOSITION:
153  si.nPos = HIWORD(wParam);
154  break;
155  case SB_LINEUP:
156  si.nPos -= 5;
157  break;
158  case SB_LINEDOWN:
159  si.nPos += 5;
160  break;
161  case SB_PAGEUP:
162  si.nPos -= si.nPage;
163  break;
164  case SB_PAGEDOWN:
165  si.nPos += si.nPage;
166  break;
167  }
168  scrollboxWindow.SetScrollInfo(SB_VERT, &si);
169  scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
170  -scrollboxWindow.GetScrollPos(SB_VERT), imageModel.GetWidth() * toolsModel.GetZoom() / 1000 + 6,
171  imageModel.GetHeight() * toolsModel.GetZoom() / 1000 + 6, TRUE);
172  }
173  return 0;
174 }
175 
177 {
178  selectionWindow.ShowWindow(SW_HIDE);
179  pointSP = 0; // resets the point-buffer of the polygon and bezier functions
180  return 0;
181 }
#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:952
#define TRUE
Definition: types.h:120
#define SIF_RANGE
Definition: winuser.h:1221
int Width() const
Definition: atltypes.h:404
#define SB_VERT
Definition: winuser.h:553
#define SW_HIDE
Definition: winuser.h:762
#define SB_HORZ
Definition: winuser.h:552
CONST INT HSCROLL_WIDTH
Definition: scrollbox.cpp:46
int32_t INT
Definition: typedefs.h:56
LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: scrollbox.cpp:141
#define SIF_PAGE
Definition: winuser.h:1219
LRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: scrollbox.cpp:97
WPARAM wParam
Definition: combotst.c:138
int GetZoom()
Definition: toolsmodel.cpp:104
UINT_PTR WPARAM
Definition: windef.h:207
CImgAreaWindow imageArea
Definition: main.cpp:71
CONST INT VSCROLL_WIDTH
Definition: scrollbox.cpp:47
LONG_PTR LPARAM
Definition: windef.h:208
BOOL GetClientRect(LPRECT lpRect) const
Definition: atlwin.h:498
#define SB_THUMBPOSITION
Definition: winuser.h:572
LONG cx
Definition: windef.h:324
#define CONST
Definition: compiler.h:170
int Height() const
Definition: atltypes.h:318
struct tagSCROLLINFO SCROLLINFO
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: scrollbox.cpp:176
CScrollboxWindow scrlClientWindow
Definition: main.cpp:69
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SB_THUMBTRACK
Definition: winuser.h:573
short pointSP
Definition: mouse.cpp:53
unsigned int UINT
Definition: ndis.h:50
int WINAPI GetSystemMetrics(_In_ int)
int GetWidth()
Definition: history.cpp:195
int GetHeight()
Definition: history.cpp:200
#define SB_PAGELEFT
Definition: winuser.h:570
ImageModel imageModel
Definition: main.cpp:32
#define SB_LINERIGHT
Definition: winuser.h:567
CONST ScrollbarPresence sp_mx[3][3]
Definition: scrollbox.cpp:39
#define SB_PAGERIGHT
Definition: winuser.h:571
#define SB_LINEDOWN
Definition: winuser.h:565
#define SB_LINEUP
Definition: winuser.h:564
#define SM_CXVSCROLL
Definition: winuser.h:951
CScrollboxWindow scrollboxWindow
Definition: main.cpp:68
void UpdateScrollbox()
Definition: scrollbox.cpp:53
#define HIWORD(l)
Definition: typedefs.h:246
#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:106
LONG cy
Definition: windef.h:325
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
CSelectionWindow selectionWindow
Definition: main.cpp:70
#define SIF_ALL
Definition: winuser.h:1218