tagging release
[dasher.git] / trunk / Src / Win32 / Widgets / AlphabetBox.cpp
blob5b1cc9dac3291aad6d731183ddcfe52165d71b7a
1 // AlphabetBox.cpp
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002 Iain Murray, Inference Group, Cavendish, Cambridge.
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 #include "WinCommon.h"
11 #include "AlphabetBox.h"
12 #include "../resource.h"
14 using namespace Dasher;
15 using namespace std;
17 // Track memory leaks on Windows to the line that new'd the memory
18 #ifdef _WIN32
19 #ifdef _DEBUG
20 #define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
21 #define new DEBUG_NEW
22 #undef THIS_FILE
23 static char THIS_FILE[] = __FILE__;
24 #endif
25 #endif
27 struct menuentry {
28 int paramNum; // enum value in Parameters.h for setting store
29 int idcNum; // #define value in resource.h for dasher.rc
30 bool bInvert;
33 // List of menu items that will be displayed in the General Preferences
34 static menuentry menutable[] = {
35 {BP_PALETTE_CHANGE, IDC_COLOURSCHEME, true}
38 CAlphabetBox::CAlphabetBox(HWND Parent, CDasherInterfaceBase *DI)
39 :m_pDasherInterface(DI), m_CurrentAlphabet(DI->GetStringParameter(SP_ALPHABET_ID)), m_CurrentColours(DI->GetStringParameter(SP_COLOUR_ID)), Editing(false), Cloning(false), EditChar(false), CustomBox(0), CurrentGroup(0), CurrentChar(0) {
40 m_hwnd = 0;
41 m_hPropertySheet = 0;
44 void CAlphabetBox::PopulateList() {
45 HWND ListBox = GetDlgItem(m_hwnd, IDC_ALPHABETS);
46 SendMessage(ListBox, LB_RESETCONTENT, 0, 0);
48 m_CurrentAlphabet = m_pDasherInterface->GetStringParameter(SP_ALPHABET_ID);
50 m_pDasherInterface->GetPermittedValues(SP_ALPHABET_ID, AlphabetList);
52 int iDefaultIndex(-1);
53 int iFallbackIndex(-1);
55 // Add each string to list box and index each one
56 bool SelectionSet = false;
57 for(unsigned int i = 0; i < AlphabetList.size(); i++) {
58 Tstring Item;
59 WinUTF8::UTF8string_to_wstring(AlphabetList[i], Item);
60 LRESULT Index = SendMessage(ListBox, LB_ADDSTRING, 0, (LPARAM) Item.c_str());
61 SendMessage(ListBox, LB_SETITEMDATA, Index, (LPARAM) i);
63 if(AlphabetList[i] == m_CurrentAlphabet) {
64 SendMessage(ListBox, LB_SETCURSEL, Index, 0);
65 SelectionSet = true;
70 if(SelectionSet == false) {
72 iDefaultIndex = SendMessage(ListBox, LB_FINDSTRING, -1, (LPARAM)L"English alphabet - limited punctuation");
73 if(iDefaultIndex == LB_ERR) {
74 iDefaultIndex = SendMessage(ListBox, LB_FINDSTRING, -1, (LPARAM)L"Default");
75 if(iDefaultIndex == LB_ERR)
76 iDefaultIndex = 0;
79 SendMessage(ListBox, LB_SETCURSEL, iDefaultIndex, 0);
80 LRESULT CurrentIndex = SendMessage(ListBox, LB_GETITEMDATA, 0, 0);
81 m_CurrentAlphabet = AlphabetList[CurrentIndex];
83 // Tell list box that we have set an item for it (so that delete and edit can be grayed if required)
84 SendMessage(m_hwnd, WM_COMMAND, MAKEWPARAM(IDC_ALPHABETS, LBN_SELCHANGE), 0);
86 ListBox = GetDlgItem(m_hwnd, IDC_COLOURS);
87 m_pDasherInterface->GetPermittedValues(SP_COLOUR_ID, ColourList);
89 // Add each string to list box and index each one
90 SelectionSet = false;
91 for(unsigned int i = 0; i < ColourList.size(); i++) {
92 Tstring Item;
93 WinUTF8::UTF8string_to_wstring(ColourList[i], Item);
94 LRESULT Index = SendMessage(ListBox, LB_ADDSTRING, 0, (LPARAM) Item.c_str());
95 SendMessage(ListBox, LB_SETITEMDATA, Index, (LPARAM) i);
96 if(ColourList[i] == m_CurrentColours) {
97 SendMessage(ListBox, LB_SETCURSEL, Index, 0);
98 SelectionSet = true;
101 if(SelectionSet == false) {
102 SendMessage(ListBox, LB_SETCURSEL, 0, 0);
103 LRESULT CurrentIndex = SendMessage(ListBox, LB_GETITEMDATA, 0, 0);
104 m_CurrentColours = ColourList[CurrentIndex];
106 // Tell list box that we have set an item for it (so that delete and edit can be grayed if required)
107 SendMessage(m_hwnd, WM_COMMAND, MAKEWPARAM(IDC_COLOURS, LBN_SELCHANGE), 0);
109 // all the button checkboxes
110 for(int ii = 0; ii<sizeof(menutable)/sizeof(menuentry); ii++)
112 if(m_pDasherInterface->GetBoolParameter(menutable[ii].paramNum) != menutable[ii].bInvert)
113 SendMessage(GetDlgItem(m_hwnd, menutable[ii].idcNum), BM_SETCHECK, BST_CHECKED, 0);
114 else
115 SendMessage(GetDlgItem(m_hwnd, menutable[ii].idcNum), BM_SETCHECK, BST_UNCHECKED, 0);
120 //void CAlphabetBox::InitCustomBox() {
121 // Editing = false;
123 // // Sort out "spin" or "up down" buttons so that I get messages from them.
124 // SendMessage(GetDlgItem(CustomBox, IDC_MOVE_GROUP), UDM_SETBUDDY, (WPARAM) GetDlgItem(CustomBox, IDC_GROUP_BUDDY), 0);
125 // SendMessage(GetDlgItem(CustomBox, IDC_MOVE_CHAR), UDM_SETBUDDY, (WPARAM) GetDlgItem(CustomBox, IDC_CHAR_BUDDY), 0);
127 // Tstring Data;
128 // WinUTF8::UTF8string_to_wstring(CurrentInfo.AlphID, Data);
129 // SendMessage(GetDlgItem(CustomBox, IDC_DESCRIPTION), WM_SETTEXT, 0, (LPARAM) Data.c_str());
130 // WinUTF8::UTF8string_to_wstring(CurrentInfo.TrainingFile, Data);
131 // SendMessage(GetDlgItem(CustomBox, IDC_TRAIN), WM_SETTEXT, 0, (LPARAM) Data.c_str());
133 // // Load encodings list box from resource strings
134 // vector < pair < int, int > >Encodings;
135 // Encodings.push_back(pair < int, int >(IDS_TYPE_None, Opts::MyNone));
136 // Encodings.push_back(pair < int, int >(IDS_TYPE_Arabic, Opts::Arabic));
137 // Encodings.push_back(pair < int, int >(IDS_TYPE_Baltic, Opts::Baltic));
138 // Encodings.push_back(pair < int, int >(IDS_TYPE_CentralEurope, Opts::CentralEurope));
139 // Encodings.push_back(pair < int, int >(IDS_TYPE_ChineseSimplified, Opts::ChineseSimplified));
140 // Encodings.push_back(pair < int, int >(IDS_TYPE_ChineseTraditional, Opts::ChineseTraditional));
141 // Encodings.push_back(pair < int, int >(IDS_TYPE_Cyrillic, Opts::Cyrillic));
142 // Encodings.push_back(pair < int, int >(IDS_TYPE_Greek, Opts::Greek));
143 // Encodings.push_back(pair < int, int >(IDS_TYPE_Hebrew, Opts::Hebrew));
144 // Encodings.push_back(pair < int, int >(IDS_TYPE_Japanese, Opts::Japanese));
145 // Encodings.push_back(pair < int, int >(IDS_TYPE_Korean, Opts::Korean));
146 // Encodings.push_back(pair < int, int >(IDS_TYPE_Thai, Opts::Thai));
147 // Encodings.push_back(pair < int, int >(IDS_TYPE_Turkish, Opts::Turkish));
148 // Encodings.push_back(pair < int, int >(IDS_TYPE_VietNam, Opts::VietNam));
149 // Encodings.push_back(pair < int, int >(IDS_TYPE_Western, Opts::Western));
150 // Tstring ResourceString;
151 // const HWND Encoding = GetDlgItem(CustomBox, IDC_ENCODING);
152 // for(unsigned int i = 0; i < Encodings.size(); i++) {
153 // WinLocalisation::GetResourceString(Encodings[i].first, &ResourceString);
154 // LRESULT Index = SendMessage(Encoding, CB_ADDSTRING, 0, (LPARAM) ResourceString.c_str());
155 // SendMessage(Encoding, CB_SETITEMDATA, Index, (LPARAM) Encodings[i].second);
156 // if((CurrentInfo.Type == (Opts::AlphabetTypes) Encodings[i].second) || (i == 0))
157 // SendMessage(Encoding, CB_SETCURSEL, Index, 0);
158 // }
160 // // Orientations list box
161 // vector < pair < int, int > >Orientations;
162 // Orientations.push_back(pair < int, int >(IDS_ORIENT_LR, Opts::LeftToRight));
163 // Orientations.push_back(pair < int, int >(IDS_ORIENT_RL, Opts::RightToLeft));
164 // Orientations.push_back(pair < int, int >(IDS_ORIENT_TB, Opts::TopToBottom));
165 // Orientations.push_back(pair < int, int >(IDS_ORIENT_BT, Opts::BottomToTop));
166 // const HWND Orientation = GetDlgItem(CustomBox, IDC_RO);
167 // for(unsigned int j = 0; j < Orientations.size(); j++) {
168 // WinLocalisation::GetResourceString(Orientations[j].first, &ResourceString);
169 // LRESULT Index = SendMessage(Orientation, CB_ADDSTRING, 0, (LPARAM) ResourceString.c_str());
170 // SendMessage(Orientation, CB_SETITEMDATA, Index, (LPARAM) Orientations[j].second);
171 // if((CurrentInfo.Orientation == (Opts::ScreenOrientations) Orientations[j].second) || (j == 0))
172 // SendMessage(Orientation, CB_SETCURSEL, Index, 0);
173 // }
175 // // Show Groups
176 // CurrentGroup = 0;
177 // CurrentChar = 0;
178 // ShowGroups();
180 // // Show characters for first group
181 // SendMessage(GetDlgItem(CustomBox, IDC_CHARS), LB_SETCOLUMNWIDTH, 34, 0);
183 // // Set check mark for the "space character"
184 // if(CurrentInfo.SpaceCharacter.Display != std::string(""))
185 // SendMessage(GetDlgItem(CustomBox, IDC_SPACE), BM_SETCHECK, BST_CHECKED, 0);
186 // // Set check mark for the "paragraph character"
187 // if(CurrentInfo.ParagraphCharacter.Display != std::string(""))
188 // SendMessage(GetDlgItem(CustomBox, IDC_PARAGRAPH), BM_SETCHECK, BST_CHECKED, 0);
189 // // Set check mark for the "control character"
190 // if(CurrentInfo.ControlCharacter.Display != std::string(""))
191 // SendMessage(GetDlgItem(CustomBox, IDC_CONTROLCHAR), BM_SETCHECK, BST_CHECKED, 0);
194 //std::string CAlphabetBox::GetControlText(HWND Dialog, int ControlID) {
195 // HWND Control = GetDlgItem(Dialog, ControlID);
196 // LRESULT BufferLength = SendMessage(Control, WM_GETTEXTLENGTH, 0, 0) + 1; // +1 to allow for terminator
197 // TCHAR *Buffer = new TCHAR[BufferLength];
198 // SendMessage(Control, WM_GETTEXT, BufferLength, (LPARAM) Buffer);
199 // string ItemName;
200 // WinUTF8::wstring_to_UTF8string(Buffer, ItemName);
201 // delete[]Buffer;
202 // return ItemName;
205 //void CAlphabetBox::NewGroup(std::string NewGroup) {
206 // HWND ListBox = GetDlgItem(CustomBox, IDC_GROUPS);
207 // Tstring Group;
208 // WinUTF8::UTF8string_to_wstring(NewGroup, Group);
209 // SendMessage(ListBox, LB_ADDSTRING, 0, (LPARAM) Group.c_str());
211 // CAlphIO::AlphInfo::group TmpGroup;
212 // TmpGroup.Description = NewGroup;
213 // CurrentInfo.Groups.push_back(TmpGroup);
216 //void CAlphabetBox::ShowGroups() {
217 // Tstring Data;
218 // const HWND Groups = GetDlgItem(CustomBox, IDC_GROUPS);
219 // SendMessage(Groups, LB_RESETCONTENT, 0, 0);
221 // if(CurrentInfo.Groups.size() == 0) {
222 // CurrentGroup = 0;
223 // ShowGroupChars();
224 // return;
225 // }
227 // for(unsigned int k = 0; k < CurrentInfo.Groups.size(); k++) {
228 // WinUTF8::UTF8string_to_wstring(CurrentInfo.Groups[k].Description, Data);
229 // SendMessage(Groups, LB_ADDSTRING, 0, (LPARAM) Data.c_str());
230 // }
232 // if(CurrentGroup >= CurrentInfo.Groups.size())
233 // CurrentGroup = CurrentInfo.Groups.size() - 1;
235 // SendMessage(Groups, LB_SETCURSEL, CurrentGroup, 0);
236 // ShowGroupChars();
239 //void CAlphabetBox::ShowGroupChars() {
240 // const HWND Chars = GetDlgItem(CustomBox, IDC_CHARS);
241 // SendMessage(Chars, LB_RESETCONTENT, 0, 0);
243 // if(CurrentInfo.Groups.size() == 0) { // If no groups are defined, don't try
244 // CurrentChar = 0;
245 // return;
246 // }
248 // Tstring Data;
249 // for(unsigned int j = 0; j < CurrentInfo.Groups[CurrentGroup].Characters.size(); j++) {
250 // WinUTF8::UTF8string_to_wstring(CurrentInfo.Groups[CurrentGroup].Characters[j].Display, Data);
251 // SendMessage(Chars, LB_ADDSTRING, 0, (LPARAM) Data.c_str());
252 // }
253 // SendMessage(Chars, LB_SETCURSEL, CurrentChar, 0);
256 //void CAlphabetBox::CustomCharacter(std::string Display, std::string Text, int Colour) {
257 // vector < CAlphIO::AlphInfo::character > &Chars = CurrentInfo.Groups[CurrentGroup].Characters;
259 // if(Chars.size() == 0) // Cannot edit a character if none exist
260 // EditChar = false;
262 // if(!EditChar) { // if need to add a character
263 // CAlphIO::AlphInfo::character NewChar;
264 // if(CurrentChar == Chars.size())
265 // Chars.push_back(NewChar);
266 // else {
267 // Chars.insert(Chars.begin() + CurrentChar + 1, NewChar);
268 // ++CurrentChar;
269 // }
270 // }
271 // else
272 // EditChar = false; // just resetting flag
274 // Chars[CurrentChar].Text = Text;
275 // Chars[CurrentChar].Display = Display;
276 // Chars[CurrentChar].Colour = Colour;
278 // ShowGroupChars(); // lazy, don't really need to update whole list
281 //bool CAlphabetBox::UpdateInfo() {
282 // CurrentInfo.AlphID = GetControlText(CustomBox, IDC_DESCRIPTION);
284 // // Check description is unique and not blank
285 // bool Unique = true;
286 // for(unsigned int i = 0; i < AlphabetList.size(); i++) {
287 // if((AlphabetList[i] == CurrentInfo.AlphID) && (AlphabetList[i] != m_CurrentAlphabet)) {
288 // Unique = false;
289 // break;
290 // }
291 // }
292 // if((CurrentInfo.AlphID == "") || (Unique == false)) {
293 // Tstring ErrMessage, AppTitle;
294 // WinLocalisation::GetResourceString(IDS_ERR_ALPH_DESC, &ErrMessage);
295 // WinLocalisation::GetResourceString(IDS_APP_TITLE, &AppTitle);
296 // MessageBox(CustomBox, ErrMessage.c_str(), AppTitle.c_str(), MB_ICONERROR);
297 // HWND Desc = GetDlgItem(CustomBox, IDC_DESCRIPTION);
298 // SetFocus(Desc);
299 // SendMessage(Desc, EM_SETSEL, 0, -1);
300 // return false;
301 // }
303 // HWND Encoding = GetDlgItem(CustomBox, IDC_ENCODING);
304 // LRESULT CurrentItem = SendMessage(Encoding, CB_GETCURSEL, 0, 0);
305 // CurrentInfo.Type = (Opts::AlphabetTypes) SendMessage(Encoding, CB_GETITEMDATA, CurrentItem, 0);
307 // CurrentInfo.Mutable = true;
309 // HWND Orientation = GetDlgItem(CustomBox, IDC_RO);
310 // CurrentItem = SendMessage(Orientation, CB_GETCURSEL, 0, 0);
311 // CurrentInfo.Orientation = (Opts::ScreenOrientations) SendMessage(Orientation, CB_GETITEMDATA, CurrentItem, 0);
313 // if(SendMessage(GetDlgItem(CustomBox, IDC_SPACE), BM_GETCHECK, 0, 0) == BST_CHECKED) {
314 // CurrentInfo.SpaceCharacter.Text = " ";
315 // CurrentInfo.SpaceCharacter.Display = "_";
316 // CurrentInfo.SpaceCharacter.Colour = 9;
317 // }
318 // else {
319 // CurrentInfo.SpaceCharacter.Text = "";
320 // CurrentInfo.SpaceCharacter.Display = "";
321 // CurrentInfo.SpaceCharacter.Colour = -1;
322 // }
324 // if(SendMessage(GetDlgItem(CustomBox, IDC_PARAGRAPH), BM_GETCHECK, 0, 0) == BST_CHECKED) {
325 // CurrentInfo.ParagraphCharacter.Text = "\r\n";
326 // CurrentInfo.ParagraphCharacter.Display = "¶";
327 // CurrentInfo.ParagraphCharacter.Colour = 9;
328 // }
329 // else {
330 // CurrentInfo.ParagraphCharacter.Text = "";
331 // CurrentInfo.ParagraphCharacter.Display = "";
332 // CurrentInfo.ParagraphCharacter.Colour = -1;
333 // }
335 // if(SendMessage(GetDlgItem(CustomBox, IDC_CONTROLCHAR), BM_GETCHECK, 0, 0) == BST_CHECKED) {
336 // CurrentInfo.ControlCharacter.Text = "Control";
337 // CurrentInfo.ControlCharacter.Display = "Control";
338 // CurrentInfo.ControlCharacter.Colour = 8;
339 // }
340 // else {
341 // CurrentInfo.ControlCharacter.Text = "";
342 // CurrentInfo.ControlCharacter.Display = "";
343 // CurrentInfo.ControlCharacter.Colour = -1;
344 // }
346 // CurrentInfo.TrainingFile = GetControlText(CustomBox, IDC_TRAIN);
348 // return true;
351 bool CAlphabetBox::Validate() {
352 // Return false if something is wrong to prevent user from clicking to a different page. Please also pop up a dialogue informing the user at this point.
353 return TRUE;
356 bool CAlphabetBox::Apply() {
358 if(m_CurrentAlphabet != std::string("")) {
359 if(m_CurrentAlphabet != m_pDasherInterface->GetStringParameter(SP_ALPHABET_ID))
360 m_pDasherInterface->SetStringParameter(SP_ALPHABET_ID, m_CurrentAlphabet);
363 if(m_CurrentColours != std::string("")) {
364 m_pDasherInterface->SetStringParameter(SP_COLOUR_ID, m_CurrentColours);
368 for(int ii = 0; ii<sizeof(menutable)/sizeof(menuentry); ii++)
370 m_pDasherInterface->SetBoolParameter(menutable[ii].paramNum,
371 (SendMessage(GetDlgItem(m_hwnd, menutable[ii].idcNum), BM_GETCHECK, 0, 0) == BST_CHECKED) != menutable[ii].bInvert);
375 // Return false (and notify the user) if something is wrong.
376 return TRUE;
379 LRESULT CAlphabetBox::WndProc(HWND Window, UINT message, WPARAM wParam, LPARAM lParam) {
380 NMHDR *pNMHDR;
382 switch (message) {
383 case WM_INITDIALOG:
384 if(!m_hwnd) { // If this is the initial dialog for the first time
385 m_hwnd = Window;
386 PopulateList();
388 //else if(Editing) {
389 // CustomBox = Window;
390 // InitCustomBox();
392 //else if(EditChar) {
393 // char colour[100];
394 // sprintf(colour, "%d", CurrentInfo.Groups[CurrentGroup].Characters[CurrentChar].Colour);
395 // SendMessage(GetDlgItem(Window, IDC_DISPLAY), WM_SETTEXT, 0, (LPARAM) (LPCSTR) CurrentInfo.Groups[CurrentGroup].Characters[CurrentChar].Display.c_str());
396 // SendMessage(GetDlgItem(Window, IDC_TEXT), WM_SETTEXT, 0, (LPARAM) (LPCSTR) CurrentInfo.Groups[CurrentGroup].Characters[CurrentChar].Text.c_str());
397 // SendMessage(GetDlgItem(Window, IDC_COLOUR), WM_SETTEXT, 0, (LPARAM) (LPCSTR) colour);
399 return TRUE;
400 break;
401 case WM_NOTIFY:{
402 pNMHDR = (NMHDR*)lParam;
403 if(m_hPropertySheet==0) {
404 m_hPropertySheet = pNMHDR->hwndFrom;
406 switch (pNMHDR->code) {
407 case PSN_KILLACTIVE: // About to lose focus
408 SetWindowLong( Window, DWL_MSGRESULT, !Validate());
409 return TRUE;
410 break;
411 case PSN_APPLY: // User clicked OK/Apply - apply the changes
412 if(Apply())
413 SetWindowLong( Window, DWL_MSGRESULT, PSNRET_NOERROR);
414 else
415 SetWindowLong( Window, DWL_MSGRESULT, PSNRET_INVALID);
416 return TRUE;
417 break;
418 //case UDN_DELTAPOS:
419 // // Moving stuff in here
420 // if(CurrentInfo.Groups.size() < 1) {
421 // return TRUE;
422 // break;
423 // }
424 // NMUPDOWN *Data = (NMUPDOWN *) lParam;
425 // if(Data->hdr.idFrom == IDC_MOVE_GROUP) {
426 // CAlphIO::AlphInfo::group Tmp = CurrentInfo.Groups[CurrentGroup];
427 // if(Data->iDelta > 0) {
428 // if(CurrentGroup + 1 < CurrentInfo.Groups.size()) {
429 // CurrentInfo.Groups[CurrentGroup] = CurrentInfo.Groups[CurrentGroup + 1];
430 // CurrentInfo.Groups[CurrentGroup + 1] = Tmp;
431 // ++CurrentGroup;
432 // }
433 // }
434 // else {
435 // if(CurrentGroup > 0) {
436 // CurrentInfo.Groups[CurrentGroup] = CurrentInfo.Groups[CurrentGroup - 1];
437 // CurrentInfo.Groups[CurrentGroup - 1] = Tmp;
438 // --CurrentGroup;
439 // }
440 // }
441 // ShowGroups();
442 // }
443 // if(Data->hdr.idFrom == IDC_MOVE_CHAR) {
444 // if(CurrentInfo.Groups[CurrentGroup].Characters.size() < 1) {
445 // return TRUE;
446 // break;
447 // }
448 // CAlphIO::AlphInfo::character Tmp = CurrentInfo.Groups[CurrentGroup].Characters[CurrentChar];
449 // if(Data->iDelta > 0) {
450 // if(CurrentChar + 1 < CurrentInfo.Groups[CurrentGroup].Characters.size()) {
451 // CurrentInfo.Groups[CurrentGroup].Characters[CurrentChar] = CurrentInfo.Groups[CurrentGroup].Characters[CurrentChar + 1];
452 // CurrentInfo.Groups[CurrentGroup].Characters[CurrentChar + 1] = Tmp;
453 // ++CurrentChar;
454 // }
455 // }
456 // else {
457 // if(CurrentChar > 0) {
458 // CurrentInfo.Groups[CurrentGroup].Characters[CurrentChar] = CurrentInfo.Groups[CurrentGroup].Characters[CurrentChar - 1];
459 // CurrentInfo.Groups[CurrentGroup].Characters[CurrentChar - 1] = Tmp;
460 // --CurrentChar;
461 // }
462 // }
463 // ShowGroupChars();
464 // }
465 // return TRUE;
466 // break; // End UDN_DELTAPOS
469 case WM_COMMAND:
471 if(HIWORD(wParam)==BN_CLICKED || HIWORD(wParam)==LBN_SELCHANGE) {
472 if(LOWORD(wParam) != 0 && m_hPropertySheet != 0 && m_hwnd != 0) {
473 PropSheet_Changed(m_hPropertySheet, m_hwnd); // enables the 'Apply' button
474 // Behaviour isn't *perfect* since it activates the Apply button even if you, say,
475 // click 'new' alphabet then click Cancel when asked for a name.
478 switch (LOWORD(wParam)) {
479 case (IDC_DISPLAY):
480 if(HIWORD(wParam) == EN_CHANGE) {
481 HWND Control = GetDlgItem(Window, IDC_DISPLAY);
482 LRESULT BufferLength = SendMessage(Control, WM_GETTEXTLENGTH, 0, 0) + 1; // +1 to allow for terminator
483 TCHAR *Buffer = new TCHAR[BufferLength];
484 SendMessage(Control, WM_GETTEXT, BufferLength, (LPARAM) Buffer);
485 string ItemName;
486 SendMessage(GetDlgItem(Window, IDC_TEXT), WM_SETTEXT, 0, (LPARAM) Buffer);
487 delete[]Buffer;
489 break;
490 case (IDC_ALPHABETS):
491 if(HIWORD(wParam) == LBN_SELCHANGE) {
492 HWND ListBox = GetDlgItem(m_hwnd, IDC_ALPHABETS);
493 LRESULT CurrentItem = SendMessage(ListBox, LB_GETCURSEL, 0, 0);
494 LRESULT CurrentIndex = SendMessage(ListBox, LB_GETITEMDATA, CurrentItem, 0);
495 m_CurrentAlphabet = AlphabetList[CurrentIndex];
496 CurrentInfo = m_pDasherInterface->GetInfo(m_CurrentAlphabet);
497 if(CurrentInfo.Mutable) {
498 EnableWindow(GetDlgItem(m_hwnd, IDC_DEL_ALPH), TRUE);
499 EnableWindow(GetDlgItem(m_hwnd, IDC_EDIT), TRUE);
501 else {
502 EnableWindow(GetDlgItem(m_hwnd, IDC_DEL_ALPH), FALSE);
503 EnableWindow(GetDlgItem(m_hwnd, IDC_EDIT), FALSE);
506 return TRUE;
507 break;
508 case (IDC_COLOURS):
509 if(HIWORD(wParam) == LBN_SELCHANGE) {
510 HWND ListBox = GetDlgItem(m_hwnd, IDC_COLOURS);
511 LRESULT CurrentItem = SendMessage(ListBox, LB_GETCURSEL, 0, 0);
512 LRESULT CurrentIndex = SendMessage(ListBox, LB_GETITEMDATA, CurrentItem, 0);
513 m_CurrentColours = ColourList[CurrentIndex];
515 return TRUE;
516 break;
517 /* case (IDC_GROUPS):
518 if(HIWORD(wParam) == LBN_SELCHANGE) {
519 HWND GroupList = GetDlgItem(Window, IDC_GROUPS);
520 CurrentGroup = SendMessage(GroupList, LB_GETCURSEL, 0, 0);
521 CurrentChar = 0;
522 ShowGroupChars();
524 return TRUE;
525 break;*/
526 //case (IDC_CHARS):
527 // if(HIWORD(wParam) == LBN_SELCHANGE) {
528 // HWND CharList = GetDlgItem(Window, IDC_CHARS);
529 // CurrentChar = SendMessage(CharList, LB_GETCURSEL, 0, 0);
530 // }
531 // return TRUE;
532 // break;
533 //case (IDC_EDIT_CHAR):
534 // if(CurrentInfo.Groups.size() < 1) // if no groups, can't edit character
535 // break;
536 // EditChar = true;
537 // DialogBoxParam(WinHelper::hInstApp, (LPCTSTR) IDD_EDITLETTER, Window, (DLGPROC) WinWrapMap::WndProc, (LPARAM) this);
538 // break;
539 //case (IDC_ADD_CHAR):
540 // if(CurrentInfo.Groups.size() < 1) // if no groups, can't add character
541 // break;
542 // DialogBoxParam(WinHelper::hInstApp, (LPCTSTR) IDD_ADDLETTERS, Window, (DLGPROC) WinWrapMap::WndProc, (LPARAM) this);
543 // break;
544 //case (IDOK_ADDCHAR):{
545 // string Display = GetControlText(Window, IDC_DISPLAY);
546 // string Text = GetControlText(Window, IDC_TEXT);
547 // int Colour = atoi(GetControlText(Window, IDC_COLOUR).c_str());
548 // CustomCharacter(Display, Text, Colour);
549 // TCHAR Terminator = '\0';
550 // SendMessage(GetDlgItem(Window, IDC_DISPLAY), WM_SETTEXT, 0, (LPARAM) & Terminator);
551 // SetFocus(GetDlgItem(Window, IDC_DISPLAY));
552 // break;
553 // }
554 //case (IDOK_CHAR):{
555 // string Display = GetControlText(Window, IDC_DISPLAY);
556 // string Text = GetControlText(Window, IDC_TEXT);
557 // int Colour = atoi(GetControlText(Window, IDC_COLOUR).c_str());
558 // CustomCharacter(Display, Text, Colour);
559 // EndDialog(Window, LOWORD(wParam));
560 // EditChar = false;
561 // break;
562 // }
563 //case (IDC_ADD_GROUP):
564 // DialogBoxParam(WinHelper::hInstApp, (LPCTSTR) IDD_NEWGROUP, Window, (DLGPROC) WinWrapMap::WndProc, (LPARAM) this);
565 // break;
566 //case (IDOK_NEWGROUP):{
567 // NewGroup(GetControlText(Window, IDC_GROUP_TEXT));
568 // EndDialog(Window, LOWORD(wParam));
569 // break;
570 // }
571 //case (IDC_DELGROUP):
572 // if(CurrentInfo.Groups.size() > CurrentGroup)
573 // CurrentInfo.Groups.erase(CurrentInfo.Groups.begin() + CurrentGroup);
574 // ShowGroups();
575 // break;
576 //case (IDC_DEL_CHAR):
577 // if(CurrentInfo.Groups.size() > CurrentGroup) {
578 // vector < CAlphIO::AlphInfo::character > &Tmp = CurrentInfo.Groups[CurrentGroup].Characters;
579 // if(Tmp.size() > CurrentChar) {
580 // Tmp.erase(Tmp.begin() + CurrentChar);
581 // CurrentChar = min(Tmp.size() - 1, CurrentChar);
582 // ShowGroupChars();
583 // }
584 // }
585 // break;
586 //case (IDOK_CUSTOMIZE):
587 // if(UpdateInfo()) {
588 // m_pDasherInterface->SetInfo(CurrentInfo);
589 // EndDialog(Window, LOWORD(wParam));
590 // PopulateList();
591 // }
592 // break;
593 case (IDC_DEL_ALPH):{
594 HWND ListBox = GetDlgItem(m_hwnd, IDC_ALPHABETS);
595 LRESULT CurrentItem = SendMessage(ListBox, LB_GETCURSEL, 0, 0);
596 LRESULT CurrentIndex = SendMessage(ListBox, LB_GETITEMDATA, CurrentItem, 0);
597 if(CurrentIndex >= 0 && (unsigned int)CurrentIndex < AlphabetList.size()) {
598 m_pDasherInterface->DeleteAlphabet(AlphabetList[CurrentIndex]);
599 PopulateList();
601 break;
603 //case (IDC_CLONE):
604 // Cloning = true;
605 // // deliberate fall through
606 //case (IDC_ADD_ALPH):
607 // DialogBoxParam(WinHelper::hInstApp, (LPCTSTR) IDD_NEWALPHABET, Window, (DLGPROC) WinWrapMap::WndProc, (LPARAM) this);
608 // break;
609 //case (IDOK_NEWALPH):{
610 // m_CurrentAlphabet = ""; // Prevent over-writing another alphabet in rare circumstances.
611 // string NewAlph = GetControlText(Window, IDC_NEW_ALPH_STRING);
612 // EndDialog(Window, LOWORD(wParam));
613 // if(Cloning) {
614 // Cloning = false;
615 // }
616 // else {
617 // CAlphIO::AlphInfo Tmp;
618 // CurrentInfo = Tmp;
619 // }
620 // CurrentInfo.AlphID = NewAlph;
621 // } // deliberate fall through
622 //case (IDC_EDIT):
623 // Editing = true;
624 // DialogBoxParam(WinHelper::hInstApp, (LPCTSTR) IDD_CUSTOMALPHABET, Window, (DLGPROC) WinWrapMap::WndProc, (LPARAM) this);
625 // break;
626 case (IDOK):
627 if(m_CurrentAlphabet != std::string("")) {
628 m_pDasherInterface->SetStringParameter(SP_ALPHABET_ID, m_CurrentAlphabet);
630 // deliberate fall through
631 case (IDCANCEL):
633 EndDialog(Window, LOWORD(wParam));
634 return TRUE;
636 case ID_CUSTOM_CANCEL:
637 PopulateList(); // Need to reget settings for current selection. Cheaty way to do it.
638 EndDialog(Window, LOWORD(wParam));
639 return TRUE;
640 break;
642 break;
644 return FALSE;