tagging release
[dasher.git] / trunk / Src / Win32 / Widgets / AdvancedPage.cpp
blobcd94283dce8f0b13ad1c4f18cc8eb084d18eda6b
1 // AdvancedPage.cpp
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002 Iain Murray, Inference Group, Cavendish, Cambridge.
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 #include "WinCommon.h"
11 #include "AdvancedPage.h"
12 #include "../resource.h"
13 #include "../Common/StringUtils.h"
15 #include <utility> // for std::pair
17 using namespace Dasher;
18 using namespace std;
20 // Track memory leaks on Windows to the line that new'd the memory
21 #ifdef _WIN32
22 #ifdef _DEBUG
23 #define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
24 #define new DEBUG_NEW
25 #undef THIS_FILE
26 static char THIS_FILE[] = __FILE__;
27 #endif
28 #endif
30 CAdvancedPage::CAdvancedPage(HWND Parent, CDasherInterfaceBase *DI, CAppSettings *pAppSettings)
31 :CPrefsPageBase(Parent, DI, pAppSettings) {
34 struct menuentry {
35 int paramNum; // enum value in Parameters.h for setting store
36 int idcNum; // #define value in resource.h for dasher.rc
39 // List of menu items that will be displayed in the General Preferences
40 static menuentry menutable[] = {
41 {APP_BP_TIME_STAMP, IDC_TIMESTAMP}, // Not global setting - specific to editbox/widget
42 {APP_BP_COPY_ALL_ON_STOP, IDC_COPYALLONSTOP},
43 {APP_BP_SPEECH_MODE, IDC_SPEECH}
46 std::string CAdvancedPage::GetControlText(HWND Dialog, int ControlID)
48 HWND Control = GetDlgItem(Dialog, ControlID);
49 std::wstring str;
50 wincommon::GetWindowText( Control, str);
52 string ItemName;
53 WinUTF8::wstring_to_UTF8string(str, ItemName);
54 return ItemName;
57 void CAdvancedPage::PopulateList() {
59 //if(m_pAppSettings->GetBoolParameter(APP_BP_TIME_STAMP)) {
60 // SendMessage(GetDlgItem(m_hwnd, IDC_TIMESTAMP), BM_SETCHECK, BST_CHECKED, 0);
61 // }
62 // else {
63 // SendMessage(GetDlgItem(m_hwnd, IDC_TIMESTAMP), BM_SETCHECK, BST_UNCHECKED, 0);
64 // }
67 // Populate the controls in the dialogue box based on the relevent parameters
68 // in m_pDasherInterface
69 for(int ii = 0; ii<sizeof(menutable)/sizeof(menuentry); ii++)
71 if(m_pAppSettings->GetBoolParameter(menutable[ii].paramNum)) {
72 SendMessage(GetDlgItem(m_hwnd, menutable[ii].idcNum), BM_SETCHECK, BST_CHECKED, 0);
74 else {
75 SendMessage(GetDlgItem(m_hwnd, menutable[ii].idcNum), BM_SETCHECK, BST_UNCHECKED, 0);
79 int ypixels = m_pDasherInterface->GetLongParameter(LP_YSCALE);
80 int mouseposdist = m_pDasherInterface->GetLongParameter(LP_MOUSEPOSDIST);
82 /* for (int i=0; i<18; i++) {
83 keycoords[i]=coords[i];
86 HWND EditBox = GetDlgItem(m_hwnd, IDC_YPIX);
87 SendMessage(EditBox, LB_RESETCONTENT, 0, 0);
89 // Perhaps a typedef for std::basic_ostringstream<TCHAR> would be useful
90 // std::basic_ostringstream<TCHAR> strYPix;
91 // strYPix << ypixels;
93 _sntprintf(m_tcBuffer, 100, TEXT("%d"), ypixels);
95 // SendMessage(EditBox, WM_SETTEXT, 0, (LPARAM)(LPCSTR) Buffer);
96 SendMessage(EditBox, WM_SETTEXT, 0, (LPARAM) m_tcBuffer);
97 // delete[] Buffer;
99 EditBox = GetDlgItem(m_hwnd, IDC_MOUSEPOSDIST);
100 SendMessage(EditBox, LB_RESETCONTENT, 0, 0);
102 _sntprintf(m_tcBuffer, 100, TEXT("%d"), mouseposdist);
103 // std::basic_ostringstream<TCHAR> strMousePosDist;
104 // strMousePosDist << mouseposdist;
106 SendMessage(EditBox, WM_SETTEXT, 0, (LPARAM) m_tcBuffer);
107 // delete[] Buffer;
111 bool CAdvancedPage::Validate() {
112 // 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.
113 return TRUE;
116 bool CAdvancedPage::Apply() {
118 for(int ii = 0; ii<sizeof(menutable)/sizeof(menuentry); ii++) {
119 m_pAppSettings->SetBoolParameter(menutable[ii].paramNum, SendMessage(GetDlgItem(m_hwnd, menutable[ii].idcNum), BM_GETCHECK, 0, 0) == BST_CHECKED );
122 // m_pAppSettings->SetBoolParameter( APP_BP_TIME_STAMP, SendMessage(GetDlgItem(m_hwnd, IDC_TIMESTAMP), BM_GETCHECK, 0, 0));
124 int ypixels = atoi(GetControlText(m_hwnd, IDC_YPIX).c_str());
125 int mouseposdist = atoi(GetControlText(m_hwnd, IDC_MOUSEPOSDIST).c_str());
127 m_pDasherInterface->SetLongParameter(LP_YSCALE, ypixels);
128 m_pDasherInterface->SetLongParameter(LP_MOUSEPOSDIST, mouseposdist);
130 return TRUE;