Scope
ScopeCheckBoxCtrl.cpp
1 #include "StdAfx.h"
2 #include "ScopeCheckBoxCtrl.h"
3 
4 namespace scope {
5  namespace gui {
6 
7 CScopeCheckBoxCtrl::CScopeCheckBoxCtrl(ScopeValue<bool>* _scopeval, const bool& _connectback, const bool& _connectcontrolstate)
8  : created(false)
9  , scope_val(_scopeval)
10  , shiftstate(false) {
11  if ( _connectback )
13  if ( _connectcontrolstate )
14  stateconnection = scope_val->ConnectState(std::bind(&CScopeCheckBoxCtrl::SetState, this, std::placeholders::_1));
15 }
16 
18  valueconnection.disconnect();
19  stateconnection.disconnect();
20 }
21 
23  if ( SubclassWindow(hWnd) ) {
24  created = true;
25  UpdateControl();
26  return true;
27  }
28  return false;
29 }
30 
31 void CScopeCheckBoxCtrl::OnReflectedCommand(UINT uNotifyCode, int nID, CWindow wndCtl) {
32  if ( uNotifyCode == BN_CLICKED ) {
33  UpdateValue();
34  }
35 }
36 
37 LRESULT CScopeCheckBoxCtrl::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
38  switch (wParam) {
39  // space key automatically triggers OnClicked
40  case VK_RETURN:
41  case VK_TAB:
42  //UpdateValue(); We do not need this, since value is updated on click or on space by other member functions
43  ::PostMessage(GetParent(), WM_NEXTDLGCTL, shiftstate, 0L);
44  return FALSE;
45  case VK_SHIFT:
46  shiftstate = true;
47  }
48  return DefWindowProc(uMsg, wParam, lParam);
49 }
50 
51 LRESULT CScopeCheckBoxCtrl::OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
52  switch (wParam) {
53  case VK_SHIFT:
54  shiftstate = false;
55  }
56  return DefWindowProc(uMsg, wParam, lParam);
57 }
58 
59 LRESULT CScopeCheckBoxCtrl::OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
60  UpdateValue();
61  return DefWindowProc(uMsg, wParam, lParam);
62 }
63 
64 LRESULT CScopeCheckBoxCtrl::OnUpdateControl(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
65  bool val = scope_val->Value();
66  if ( val )
67  SetCheck(BST_CHECKED);
68  else
69  SetCheck(BST_UNCHECKED);
70  return 0;
71 }
72 
74  ::PostMessage(m_hWnd, WM_UPDATECONTROL, NULL, NULL);
75 }
76 
78  UINT state = GetCheck();
79  if ( state == BST_CHECKED )
80  scope_val->Set(true);
81  if ( state == BST_UNCHECKED )
82  scope_val->Set(false);
83 }
84 
85 void CScopeCheckBoxCtrl::SetState(const bool& state) {
86  if ( created )
87  EnableWindow(state);
88 }
89 
90 }
91 
92 }
boost::signals2::connection ConnectGUI(signalchange_t::slot_type slot)
Connect signal to slot to GUI.
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
LRESULT OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Resets state of shift key.
bool created
true after window creation
T Value() const
Definition: ScopeValue.h:46
void SetState(const bool &state)
Sets the enabled/disabled state of the control.
boost::signals2::connection valueconnection
The connection object for the control state (connection to the scope_val value change) ...
void OnReflectedCommand(UINT uNotifyCode, int nID, CWindow wndCtl)
Updates value on reflected BN_CLICKED.
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...
LRESULT OnUpdateControl(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Worker for UpdateControl.
LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Update scope_val when leaving focus.
This is the include file for standard system include files, or project specific include files that ar...
* CScopeCheckBoxCtrl(ScopeValue< bool > *_scopeval, const bool &_connectback=false, const bool &_connectcontrolstate=false)
()
ScopeValue< bool > *const scope_val
pointer to underlying ScopeValue
bool shiftstate
stores state of shift key
boost::signals2::connection ConnectState(signalstate_t::slot_type slot)
Connect signal to slot for state changes.
bool AttachToDlgItem(HWND hWnd)
Attach the control to a dialog item.
boost::signals2::connection stateconnection
The connection object for the control state (connection to the scopenum rw state change) ...
void UpdateValue()
Updates the ScopeValue from the string inside the control.
void UpdateControl()
Updates the string inside the control from the ScopeValues' value.