Scope
ScopeScrollbarCtrl.cpp
1 #include "stdafx.h"
2 #include "ScopeScrollbarCtrl.h"
3 #include "helpers/ScopeNumber.h"
4 #include "helpers/helpers.h"
5 
6 namespace scope {
7  namespace gui {
8 
9 CScopeScrollbarCtrl::CScopeScrollbarCtrl(ScopeNumber<double>* _scopenum, const double& _smallincrement, const double& _largeincrement, const bool& _connectback, const bool& _connectcontrolstate)
10  : created(false)
11  , scopenum(_scopenum)
12  , smallincrement((_smallincrement==0.0)?(scopenum->ul()-scopenum->ll()) / 100:_smallincrement)
13  , largeincrement((_largeincrement==0.0)?(scopenum->ul()-scopenum->ll()) / 20:_largeincrement) {
14  if ( _connectback )
16  if ( _connectcontrolstate )
17  stateconnection = scopenum->ConnectState(std::bind(&CScopeScrollbarCtrl::SetState, this, std::placeholders::_1));
18 }
19 
21  valueconnection.disconnect();
22  stateconnection.disconnect();
23 }
24 
26  if ( SubclassWindow(hWnd) ) {
27  created = true;
28  SetScrollRange(0, 100, TRUE);
29  UpdateControl();
30  return TRUE;
31  }
32  return FALSE;
33 }
34 
35 void CScopeScrollbarCtrl::OnScroll(int nSBCode, short nPos, CScrollBar pScrollBar) {
36  // adjust scopenum on dragging the slider
37  // nPos 0 at top, but bottom should be 0, thus 100-nPos
38  if ( nSBCode == SB_THUMBPOSITION )
39  scopenum->Set(scopenum->ll() + static_cast<double>(100 - nPos) * (scopenum->ul()-scopenum->ll())/100 );
40  // on clicking on the arrows at the end of the scrollbar
41  if ( (nSBCode == SB_LINEUP) || (nSBCode == SB_LINELEFT) )
43  if ( (nSBCode == SB_LINEDOWN) || (nSBCode == SB_LINERIGHT) )
45  // and on clicking into scrollbar
46  if ( (nSBCode == SB_PAGEUP) || (nSBCode == SB_PAGELEFT) )
48  if ( (nSBCode == SB_PAGEDOWN) || (nSBCode == SB_PAGERIGHT) )
50 }
51 
52 LRESULT CScopeScrollbarCtrl::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
53  switch (wParam) {
54  case VK_RETURN:
55  case VK_TAB:
56  ::PostMessage(GetParent(), WM_NEXTDLGCTL, shiftstate, 0L);
57  return FALSE;
58  case VK_SHIFT:
59  shiftstate = true;
60  }
61  return DefWindowProc(uMsg, wParam, lParam);
62 }
63 
64 LRESULT CScopeScrollbarCtrl::OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
65  switch (wParam) {
66  case VK_SHIFT:
67  shiftstate = false;
68  }
69  return DefWindowProc(uMsg, wParam, lParam);
70 }
71 
72 LRESULT CScopeScrollbarCtrl::OnUpdateControl(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
73  // nPos 0 at top, but bottom should be 0, thus 100-
74  SetScrollPos(100 - round2i32( (scopenum->Value()-scopenum->ll()) / ((scopenum->ul()-scopenum->ll())/100) ) );
75  return 0;
76 }
77 
79  ::PostMessage(m_hWnd, WM_UPDATECONTROL, NULL, NULL);
80 }
81 
82 void CScopeScrollbarCtrl::SetState(const bool& state) {
83  if ( created )
84  EnableWindow(state);
85 }
86 
87 void CScopeScrollbarCtrl::SetSmallIncrement(const double& incr) {
88  smallincrement = (incr==0.0)?(scopenum->ul()-scopenum->ll()) / 100:incr;
89 }
90 
91 }
92 
93 }
boost::signals2::connection ConnectGUI(signalchange_t::slot_type slot)
Connect signal to slot to GUI.
bool created
true if window created
LRESULT OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Resets state of shift key.
void SetSmallIncrement(const double &incr)
Sets the small increment.
virtual T Set(const T &_v, const bool &_callguisignal=true, const bool &_callothersignal=true, const bool &_callatnochange=false)
Sets the value and calls both change signals if the value actually changed.
Definition: ScopeValue.h:67
boost::signals2::connection stateconnection
The connection object for the control state (connection to the scopenum rw state change) ...
T Value() const
Definition: ScopeValue.h:46
ScopeNumber< double > *const scopenum
pointer to underlying ScopeValue
bool shiftstate
stores state of shift key
void OnScroll(int nSBCode, short nPos, CScrollBar pScrollBar)
Updates the ScopeNumber from the slider position.
This is the include file for standard system include files, or project specific include files that ar...
double smallincrement
if != 0, then scopenum is changed by increment on click on scrollbar arrows, otherwise by range/100 ...
void SetState(const bool &state)
Sets the enabled/disabled control state.
boost::signals2::connection ConnectState(signalstate_t::slot_type slot)
Connect signal to slot for state changes.
boost::signals2::connection valueconnection
The connection object for the control state (connection to the scopenum value change) ...
~CScopeScrollbarCtrl()
Disconnects everything.
LRESULT OnUpdateControl(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Worker for UpdateControl.
BOOL AttachToDlgItem(HWND hWnd)
Attach the control to a dialog item and set range and tick frequency.
* CScopeScrollbarCtrl(ScopeNumber< double > *_scopenum, const double &_smallincrement, const double &_largeincrement, const bool &_connectback=false, const bool &_connectcontrolstate=false)
()
LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Switches to next control on return or tab and updates ScopeValue scope_val Also sets state of shift k...
Various helper functions and classes for Scope.
void UpdateControl()
Updates the slider position from the ScopeNumber.
double largeincrement
if != 0, then scopenum is changed by largeincrement on click inside scrollbar, otherwise by range/20 ...