Scope
ScopeButtonCtrl.cpp
1 #include "StdAfx.h"
2 #include "ScopeButtonCtrl.h"
3 
4 namespace scope {
5  namespace gui {
6 
7 CScopeButtonCtrl::CScopeButtonCtrl(ScopeButton* _butt, const bool& _connectcontrolstate)
8  : created(false)
9  , scope_button(_butt) {
10  // Connect and enable/disable
11  if ( _connectcontrolstate ) {
12  stateconnection = scope_button->ConnectControlState(std::bind(&CScopeButtonCtrl::Enable, this, std::placeholders::_1));
14  }
15 }
16 
17 
19  stateconnection.disconnect();
20 }
21 
23  if ( SubclassWindow(hWnd) ) {
24  created = true;
25  return true;
26  }
27  return false;
28 }
29 
30 void CScopeButtonCtrl::Connect(ScopeButton* _butt, const bool& _connectcontrolstate) {
31  std::lock_guard<std::mutex> lock(mutex);
32  scope_button = _butt;
33  // Connect and enable/disable
34  if ( _connectcontrolstate ) {
35  stateconnection.disconnect();
36  stateconnection = scope_button->ConnectControlState(std::bind(&CScopeButtonCtrl::Enable, this, std::placeholders::_1));
38  }
39 }
40 
41 void CScopeButtonCtrl::Disconnect() {
42  std::lock_guard<std::mutex> lock(mutex);
43  stateconnection.disconnect(); // Does not throw if not connected
44  scope_button = nullptr;
45 }
46 
47 LRESULT CScopeButtonCtrl::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
48  switch (wParam) {
49  case VK_RETURN:
50  case VK_TAB:
51  ::PostMessage(GetParent(), WM_NEXTDLGCTL, shiftstate, 0L);
52  return FALSE;
53  case VK_SHIFT:
54  shiftstate = true;
55  }
56  return DefWindowProc(uMsg, wParam, lParam);
57 }
58 
59 LRESULT CScopeButtonCtrl::OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
60  switch (wParam) {
61  case VK_SHIFT:
62  shiftstate = false;
63  }
64  return DefWindowProc(uMsg, wParam, lParam);
65 }
66 
67 LRESULT CScopeButtonCtrl::OnClicked(UINT uNotifyCode, int nID, CWindow wndCtl) {
68  std::lock_guard<std::mutex> lock(mutex);
69  if ( scope_button != nullptr )
71  return 0;
72 }
73 void CScopeButtonCtrl::Enable(const bool& state) {
74  if (created ) {
75  DBOUT(L"CScopeButtonCtrl enable/disable " << state);
76  EnableWindow(state);
77  }
78 }
79 
80 }
81 
82 }
bool shiftstate
stores state of shift key
std::mutex mutex
protect connection managment
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...
bool created
true after window creation
ScopeButton * scope_button
pointer to the underlying ScopeButton
LRESULT OnClicked(UINT uNotifyCode, int nID, CWindow wndCtl)
Call ScopeButton's click method.
* CScopeButtonCtrl(ScopeButton *_butt, const bool &_connectcontrolstate=true)
()
void Click()
Call signal.
Definition: ScopeButton.cpp:31
void Enable(const bool &state)
Sets the enabled/disabled state of the control.
This is the include file for standard system include files, or project specific include files that ar...
#define DBOUT(s)
A debug output to the debug console.
Definition: helpers.h:153
~CScopeButtonCtrl()
Disconnects control state.
Mimicks a button, glue between the GUI and controller, used in ScopeController.
Definition: ScopeButton.h:7
boost::signals2::connection stateconnection
The connection object for the control state (connection to the scope_button)
LRESULT OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Resets state of shift key.
boost::signals2::connection ConnectControlState(signalstate_t::slot_type slot)
Connect slot to control state signal.
Definition: ScopeButton.cpp:39
bool Enabled() const
Definition: ScopeButton.h:43
bool AttachToDlgItem(HWND hWnd)
Attach the control to a dialog item.