3 /////////////////////////////////////////////////////////////////////////////
5 // Copyright (c) 2002 Iain Murray, Inference Group, Cavendish, Cambridge.
7 /////////////////////////////////////////////////////////////////////////////
11 #include "KeyControl.h"
12 #include "../resource.h"
13 #include "../Dasher.h"
15 #include <utility> // for std::pair
18 using namespace Dasher
;
22 // FIXME - lines marked //F need to be reimplemented using the new scheme
24 CKeyBox::CKeyBox(HWND Parent
, CDasher
*pDasher
)
25 :m_pDasher(pDasher
), NewUniform(-1)
27 // m_sBuffer.resize(1000);
29 DialogBoxParam(WinHelper::hInstApp
, (LPCTSTR
) IDD_KEYCONTROL1
, Parent
, (DLGPROC
) WinWrapMap::WndProc
, (LPARAM
) this);
32 std::string
CKeyBox::GetControlText(HWND Dialog
, int ControlID
) {
33 HWND Control
= GetDlgItem(Dialog
, ControlID
);
34 LRESULT BufferLength
= SendMessage(Control
, WM_GETTEXTLENGTH
, 0, 0) + 1; // +1 to allow for terminator
35 TCHAR
*Buffer
= new TCHAR
[BufferLength
];
36 SendMessage(Control
, WM_GETTEXT
, BufferLength
, (LPARAM
) Buffer
);
38 WinUTF8::wstring_to_UTF8string(Buffer
, ItemName
);
43 void CKeyBox::PopulateWidgets() {
45 // char dummybuffer[256];
46 // wchar_t widebuffer[256];
48 /* widgets[0]=IDC_UPX;
54 widgets[6]=IDC_RIGHTX;
55 widgets[7]=IDC_RIGHTY;
67 int* coords = m_pCanvas->getkeycoords(); */
72 // std::basic_ostringstream<TCHAR> strUniform;
73 // strUniform.setf(ios::fixed);
74 // strUniform.precision(1);
75 // strUniform << m_pCanvas->getuniform()/10.0;
77 // FIXME - why do we store things like 'uniform' here - surely they should be stored in the interface?
81 /* for (int i=0; i<18; i++) {
82 EditBox = GetDlgItem(m_hwnd, widgets[i]);
83 SendMessage(EditBox, LB_RESETCONTENT, 0, 0);
85 itoa(keycoords[i],dummybuffer,10);
86 mbstowcs(widebuffer,dummybuffer,256);
88 SendMessage(EditBox, WM_SETTEXT, 0, (LPARAM) widebuffer);
90 if (m_pCanvas->getforward()==true) {
91 SendMessage(GetDlgItem(m_hwnd, IDC_KCFORWARD), BM_SETCHECK, BST_CHECKED, 0);
93 if (m_pCanvas->getbackward()==true) {
94 SendMessage(GetDlgItem(m_hwnd, IDC_KCBACK), BM_SETCHECK, BST_CHECKED, 0);
96 if (m_pCanvas->getselect()==true) {
97 SendMessage(GetDlgItem(m_hwnd, IDC_KCSELECT), BM_SETCHECK, BST_CHECKED, 0);
101 LRESULT
CKeyBox::WndProc(HWND Window
, UINT message
, WPARAM wParam
, LPARAM lParam
) {
105 if(!m_hwnd
) { // If this is the initial dialog for the first time
114 switch (LOWORD(wParam
)) {
116 if(HIWORD(wParam
) == EN_CHANGE
) {
117 HWND Control
= GetDlgItem(Window
, IDC_DISPLAY
);
118 LRESULT BufferLength
= SendMessage(Control
, WM_GETTEXTLENGTH
, 0, 0) + 1; // +1 to allow for terminator
119 TCHAR
*Buffer
= new TCHAR
[BufferLength
];
120 SendMessage(Control
, WM_GETTEXT
, BufferLength
, (LPARAM
) Buffer
);
122 SendMessage(GetDlgItem(Window
, IDC_TEXT
), WM_SETTEXT
, 0, (LPARAM
) Buffer
);
127 /* keycoords[0]=atoi(GetControlText(Window,IDC_UPX).c_str());
128 keycoords[1]=atoi(GetControlText(Window,IDC_UPY).c_str());
129 keycoords[2]=atoi(GetControlText(Window,IDC_DOWNX).c_str());
130 keycoords[3]=atoi(GetControlText(Window,IDC_DOWNY).c_str());
131 keycoords[4]=atoi(GetControlText(Window,IDC_LEFTX).c_str());
132 keycoords[5]=atoi(GetControlText(Window,IDC_LEFTY).c_str());
133 keycoords[6]=atoi(GetControlText(Window,IDC_RIGHTX).c_str());
134 keycoords[7]=atoi(GetControlText(Window,IDC_RIGHTY).c_str());
135 keycoords[8]=atoi(GetControlText(Window,IDC_5X).c_str());
136 keycoords[9]=atoi(GetControlText(Window,IDC_5Y).c_str());
137 keycoords[10]=atoi(GetControlText(Window,IDC_6X).c_str());
138 keycoords[11]=atoi(GetControlText(Window,IDC_6Y).c_str());
139 keycoords[12]=atoi(GetControlText(Window,IDC_7X).c_str());
140 keycoords[13]=atoi(GetControlText(Window,IDC_7Y).c_str());
141 keycoords[14]=atoi(GetControlText(Window,IDC_8X).c_str());
142 keycoords[15]=atoi(GetControlText(Window,IDC_8Y).c_str());
143 keycoords[16]=atoi(GetControlText(Window,IDC_9X).c_str());
144 keycoords[17]=atoi(GetControlText(Window,IDC_9Y).c_str()); */
146 if(NewUniform
!= -1) {
147 // DJW - this looks a bit nasty
148 m_pDasher
->SetLongParameter(LP_UNIFORM
, static_cast < long >(NewUniform
));
151 // Move forward on button press
152 /* if (SendMessage(GetDlgItem(Window,IDC_KCFORWARD), BM_GETCHECK, 0, 0)==BST_CHECKED) {
153 m_pCanvas->setforward(true);
155 m_pCanvas->setforward(false);
157 // Move backward on button press
158 if (SendMessage(GetDlgItem(Window,IDC_KCBACK), BM_GETCHECK, 0, 0)==BST_CHECKED) {
159 m_pCanvas->setbackward(true);
161 m_pCanvas->setbackward(false);
163 // Select on button press
164 if (SendMessage(GetDlgItem(Window,IDC_KCSELECT), BM_GETCHECK, 0, 0)==BST_CHECKED) {
165 m_pCanvas->setselect(true);
167 m_pCanvas->setselect(false);
173 EndDialog(Window
, LOWORD(wParam
));
176 case ID_CANCEL_KEYCONT
:
177 EndDialog(Window
, LOWORD(wParam
));