tagging release
[dasher.git] / trunk / Src / Win32 / Widgets / KeyControl.cpp
blobc604941cfc4433853fd3abb77e116861f893d1ca
1 // KeyControl.cpp
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002 Iain Murray, Inference Group, Cavendish, Cambridge.
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 #include "WinCommon.h"
11 #include "KeyControl.h"
12 #include "../resource.h"
13 #include "../Dasher.h"
15 #include <utility> // for std::pair
16 //#include <sstream>
18 using namespace Dasher;
19 using namespace std;
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);
28 m_hwnd = 0;
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);
37 string ItemName;
38 WinUTF8::wstring_to_UTF8string(Buffer, ItemName);
39 delete[]Buffer;
40 return ItemName;
43 void CKeyBox::PopulateWidgets() {
44 // int widgets[18];
45 // char dummybuffer[256];
46 // wchar_t widebuffer[256];
48 /* widgets[0]=IDC_UPX;
49 widgets[1]=IDC_UPY;
50 widgets[2]=IDC_DOWNX;
51 widgets[3]=IDC_DOWNY;
52 widgets[4]=IDC_LEFTX;
53 widgets[5]=IDC_LEFTY;
54 widgets[6]=IDC_RIGHTX;
55 widgets[7]=IDC_RIGHTY;
56 widgets[8]=IDC_5X;
57 widgets[9]=IDC_5Y;
58 widgets[10]=IDC_6X;
59 widgets[11]=IDC_6Y;
60 widgets[12]=IDC_7X;
61 widgets[13]=IDC_7Y;
62 widgets[14]=IDC_8X;
63 widgets[15]=IDC_8Y;
64 widgets[16]=IDC_9X;
65 widgets[17]=IDC_9Y;
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);
98 } */
101 LRESULT CKeyBox::WndProc(HWND Window, UINT message, WPARAM wParam, LPARAM lParam) {
102 switch (message) {
103 case WM_INITDIALOG:
105 if(!m_hwnd) { // If this is the initial dialog for the first time
106 m_hwnd = Window;
107 PopulateWidgets();
109 return TRUE;
110 break;
113 case WM_COMMAND:
114 switch (LOWORD(wParam)) {
115 case (IDC_DISPLAY):
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);
121 string ItemName;
122 SendMessage(GetDlgItem(Window, IDC_TEXT), WM_SETTEXT, 0, (LPARAM) Buffer);
123 delete[]Buffer;
125 break;
126 case (IDOK_KEYCONT):
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);
154 } else {
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);
160 } else {
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);
166 } else {
167 m_pCanvas->setselect(false);
168 } */
169 return TRUE;
170 break;
171 case (IDCANCEL):
173 EndDialog(Window, LOWORD(wParam));
174 return TRUE;
176 case ID_CANCEL_KEYCONT:
177 EndDialog(Window, LOWORD(wParam));
178 return TRUE;
179 break;
181 default:
182 return FALSE;