Scope
ScopeUpDownCtrl.h
1 #pragma once
2 
3 #include "helpers/ScopeNumber.h"
4 
5 namespace scope {
6  namespace gui {
7 
11 template <class ValT>
13  : public CWindowImpl<CScopeUpDownCtrl<ValT>, CUpDownCtrl> {
14 
15 protected:
17  bool created;
18 
21 
23  boost::signals2::connection stateconnection;
24 
26  const ValT increment;
27 
29  bool incdec;
30 
31 public:
32  BEGIN_MSG_MAP_EX(CScopeUpDownCtrl)
33  MSG_OCM_NOTIFY(OnUpDown)
34  DEFAULT_REFLECTION_HANDLER()
35  END_MSG_MAP()
36 
42  CScopeUpDownCtrl(ScopeNumber<ValT>* _scopeval, const ValT& _increment, const bool& _connectback = false, const bool& _connectcontrolstate = false)
43  : scopeval(_scopeval)
44  , increment(_increment) {
45  // We do not use connectback since the control has no visible value (although an internal iPos, which we do not use)
46  if ( _connectcontrolstate )
47  stateconnection = scopeval->ConnectState(std::bind(&CScopeUpDownCtrl<ValT>::SetState, this, std::placeholders::_1));
48  }
49 
52  stateconnection.disconnect();
53  }
54 
56  bool AttachToDlgItem(HWND hWnd) {
57  if ( SubclassWindow(hWnd) ) {
58  created = true;
59  return true;
60  }
61  return false;
62  }
63 
67  LRESULT OnUpDown(int idCtrl, LPNMHDR pnmh) {
68  if ( pnmh->hwndFrom == m_hWnd ) {
69  if ( pnmh->code == UDN_DELTAPOS ) {
70  LPNMUPDOWN lpnmud = (LPNMUPDOWN)pnmh;
71  if ( lpnmud->iDelta > 0 )
72  incdec = true;
73  else
74  incdec = false;
75  UpdateValue();
76  }
77  }
78  return 0;
79  }
83  void UpdateValue() {
84  if ( incdec )
85  scopeval->Set(scopeval->Value()-increment);
86  else
87  scopeval->Set(scopeval->Value()+increment);
88  }
89 
91  void SetState(const bool& state) {
92  if ( created )
93  EnableWindow(state);
94  }
95 };
96 
97 }
98 
99 }
LRESULT OnUpDown(int idCtrl, LPNMHDR pnmh)
Checks if the reflected notify is for this window and an UDN_DELTAPOS and calls UpdateVale accordingl...
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
T Value() const
Definition: ScopeValue.h:46
const ValT increment
ScopeNumber is incremented/decremented by this value.
boost::signals2::connection stateconnection
The connection object for the control state (connection to the scopenum rw state change) ...
void SetState(const bool &state)
Sets the enabled/disabled control state.
bool created
true if window created
boost::signals2::connection ConnectState(signalstate_t::slot_type slot)
Connect signal to slot for state changes.
bool incdec
does the next OnUpdateControl increment (true) or decrement (false)
void UpdateValue()
Updates the ScopeValue by incrementing or decrementing.
~CScopeUpDownCtrl(void)
Disconnects everything.
ScopeNumber< ValT > *const scopeval
pointer to the underlying ScopeNumber
An adapted CUpDownCtrl control around a ScopeNumber.
bool AttachToDlgItem(HWND hWnd)
Attach the control to a dialog item.