3 /////////////////////////////////////////////////////////////////////////////
5 // Copyright (c) 2002 Iain Murray, Inference Group, Cavendish, Cambridge.
7 /////////////////////////////////////////////////////////////////////////////
12 #include "ButtonPrefs.h"
13 #include "../../DasherCore/Parameters.h"
15 #include "../resource.h"
16 #include <utility> // for std::pair
17 #include "../Dasher.h"
19 using namespace Dasher
;
22 CButtonPrefs::CButtonPrefs(HWND hParent
, CDasher
*pDasher
, CAppSettings
*pAppSettings
)
23 :m_pDasher(pDasher
), m_pAppSettings(pAppSettings
) {
26 // FIXME - is hParent still needed here?
28 // m_pButtonSettingsPage = new CButtonSettingsPage(hParent, pDasher, pAppSettings);
30 // PROPSHEETPAGE psp[1];
31 // PROPSHEETHEADER psh;
33 ///* psp[0].dwSize = sizeof(PROPSHEETPAGE);
34 // psp[0].dwFlags = PSP_USEICONID | PSP_USETITLE;
35 // psp[0].hInstance = WinHelper::hInstApp;
36 // psp[0].pszTemplate = MAKEINTRESOURCE(IDD_BUTTON_PREFS);
37 // psp[0].pszIcon = NULL;
38 // psp[0].pfnDlgProc = (DLGPROC) WinWrapMap::PSWndProc;
39 // psp[0].pszTitle = MAKEINTRESOURCE(IDS_BUTTON_PREFS_TITLE);
40 // psp[0].lParam = (LPARAM) m_pButtonTypePage;
41 // psp[0].pfnCallback = NULL;*/
43 // psp[0].dwSize = sizeof(PROPSHEETPAGE);
44 // psp[0].dwFlags = PSP_USEICONID | PSP_USETITLE;
45 // psp[0].hInstance = WinHelper::hInstApp;
46 // psp[0].pszTemplate = MAKEINTRESOURCE(IDD_BUTTON_SETTINGS);
47 // psp[0].pszIcon = NULL;
48 // psp[0].pfnDlgProc = (DLGPROC) WinWrapMap::PSWndProc;
49 // psp[0].pszTitle = MAKEINTRESOURCE(IDS_BUTTON_SETTINGS_TITLE);
50 // psp[0].lParam = (LPARAM) m_pButtonSettingsPage;
51 // psp[0].pfnCallback = NULL;
53 // psh.dwSize = sizeof(PROPSHEETHEADER);
54 // psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE;
55 // psh.hwndParent = hParent;
56 // psh.hInstance = WinHelper::hInstApp;
57 // psh.pszIcon = NULL;
58 // psh.pszCaption = MAKEINTRESOURCE(IDS_BUTTON_PREFS_DIALOGUE_TITLE);
59 // psh.nPages = sizeof(psp) /
60 // sizeof(PROPSHEETPAGE);
61 // psh.nStartPage = 0;
62 // psh.ppsp = (LPCPROPSHEETPAGE) &psp;
63 // psh.pfnCallback = NULL;
64 // PropertySheet(&psh);
68 DialogBoxParam(WinHelper::hInstApp
, (LPCTSTR
) IDD_BUTTON_SETTINGS
, hParent
, (DLGPROC
) WinWrapMap::WndProc
, (LPARAM
) this);
73 CButtonPrefs::~CButtonPrefs()
75 //if (m_pAlphabetBox != NULL) {
76 // delete m_pAlphabetBox;
77 // m_pAlphabetBox = NULL;
83 void CButtonPrefs::PopulateWidgets() {
84 // Populate the controls in the dialogue box based on the relevent parameters
87 m_hZoomStepsSlider
= GetDlgItem(m_hwnd
, IDC_ZOOMSTEPS_SLIDER
);
88 SendMessage(m_hZoomStepsSlider
, TBM_SETPAGESIZE
, 0L, 1); // PgUp and PgDown change bitrate by reasonable amount
89 SendMessage(m_hZoomStepsSlider
, TBM_SETRANGE
, FALSE
, (LPARAM
) MAKELONG(1, 64));
90 SendMessage(m_hZoomStepsSlider
, TBM_SETPOS
, TRUE
, (LPARAM
) m_pAppSettings
->GetLongParameter(LP_ZOOMSTEPS
));
92 m_hZoomStepsBox
= GetDlgItem(m_hwnd
, IDC_ZOOMSTEPS_VALUE
);
93 _sntprintf(m_tcBuffer
, 100, TEXT("%d"), static_cast<int>(m_pAppSettings
->GetLongParameter(LP_ZOOMSTEPS
)));
94 SendMessage(m_hZoomStepsBox
, WM_SETTEXT
, 0, (LPARAM
) m_tcBuffer
);
97 m_hRightZoomSlider
= GetDlgItem(m_hwnd
, IDC_RIGHTZOOM_SLIDER
);
98 SendMessage(m_hRightZoomSlider
, TBM_SETPAGESIZE
, 0L, 1); // PgUp and PgDown change bitrate by reasonable amount
99 SendMessage(m_hRightZoomSlider
, TBM_SETRANGE
, FALSE
, (LPARAM
) MAKELONG(1, 9));
100 SendMessage(m_hRightZoomSlider
, TBM_SETPOS
, TRUE
, (LPARAM
) m_pAppSettings
->GetLongParameter(LP_RIGHTZOOM
)/1024.0);
102 m_hRightZoomBox
= GetDlgItem(m_hwnd
, IDC_RIGHTZOOM_VALUE
);
103 _sntprintf(m_tcBuffer
, 100, TEXT("%0.2f"), m_pAppSettings
->GetLongParameter(LP_RIGHTZOOM
)/1024.0);
104 SendMessage(m_hRightZoomBox
, WM_SETTEXT
, 0, (LPARAM
) m_tcBuffer
);
106 m_hNoBoxesSlider
= GetDlgItem(m_hwnd
, IDC_NOBOXES_SLIDER
);
107 SendMessage(m_hNoBoxesSlider
, TBM_SETPAGESIZE
, 0L, 1); // PgUp and PgDown change bitrate by reasonable amount
108 SendMessage(m_hNoBoxesSlider
, TBM_SETRANGE
, FALSE
, (LPARAM
) MAKELONG(2, 10));
109 SendMessage(m_hNoBoxesSlider
, TBM_SETPOS
, TRUE
, (LPARAM
) m_pAppSettings
->GetLongParameter(LP_B
));
111 m_hNoBoxesBox
= GetDlgItem(m_hwnd
, IDC_NBOXES_VALUE
);
112 _sntprintf(m_tcBuffer
, 100, TEXT("%d"), static_cast<int>(m_pAppSettings
->GetLongParameter(LP_B
)));
113 SendMessage(m_hNoBoxesBox
, WM_SETTEXT
, 0, (LPARAM
) m_tcBuffer
);
115 m_hSafetySlider
= GetDlgItem(m_hwnd
, IDC_SAFETY_SLIDER
);
116 SendMessage(m_hSafetySlider
, TBM_SETPAGESIZE
, 0L, 10); // PgUp and PgDown change bitrate by reasonable amount
117 SendMessage(m_hSafetySlider
, TBM_SETRANGE
, FALSE
, (LPARAM
) MAKELONG(0, 256));
118 SendMessage(m_hSafetySlider
, TBM_SETPOS
, TRUE
, (LPARAM
) m_pAppSettings
->GetLongParameter(LP_S
));
120 m_hSafetyBox
= GetDlgItem(m_hwnd
, IDC_SAFETY_VALUE
);
121 _sntprintf(m_tcBuffer
, 100, TEXT("%d"), static_cast<int>(m_pAppSettings
->GetLongParameter(LP_S
)));
122 SendMessage(m_hSafetyBox
, WM_SETTEXT
, 0, (LPARAM
) m_tcBuffer
);
124 m_hNonUniformSlider
= GetDlgItem(m_hwnd
, IDC_NONUNIFORM_SLIDER
);
125 SendMessage(m_hNonUniformSlider
, TBM_SETPAGESIZE
, 0L, 50); // PgUp and PgDown change bitrate by reasonable amount
126 SendMessage(m_hNonUniformSlider
, TBM_SETRANGE
, FALSE
, (LPARAM
) MAKELONG(-400, 400));
127 SendMessage(m_hNonUniformSlider
, TBM_SETPOS
, TRUE
, (LPARAM
) m_pAppSettings
->GetLongParameter(LP_R
));
129 m_hNonUniformBox
= GetDlgItem(m_hwnd
, IDC_NU_VALUE
);
130 _sntprintf(m_tcBuffer
, 100, TEXT("%d"), static_cast<int>(m_pAppSettings
->GetLongParameter(LP_R
)));
131 SendMessage(m_hNonUniformBox
, WM_SETTEXT
, 0, (LPARAM
) m_tcBuffer
);
134 bool CButtonPrefs::Apply()
138 NewValue
= SendMessage(m_hZoomStepsSlider
, TBM_GETPOS
, 0, 0);
139 m_pAppSettings
->SetLongParameter( LP_ZOOMSTEPS
, static_cast<int>(NewValue
));
141 NewValue
= SendMessage(m_hRightZoomSlider
, TBM_GETPOS
, 0, 0);
142 m_pAppSettings
->SetLongParameter( LP_RIGHTZOOM
, static_cast<int>(NewValue
* 1024));
144 NewValue
= SendMessage(m_hNoBoxesSlider
, TBM_GETPOS
, 0, 0);
145 m_pAppSettings
->SetLongParameter( LP_B
, static_cast<int>(NewValue
));
147 NewValue
= SendMessage(m_hSafetySlider
, TBM_GETPOS
, 0, 0);
148 m_pAppSettings
->SetLongParameter( LP_S
, static_cast<int>(NewValue
));
150 NewValue
= SendMessage(m_hNonUniformSlider
, TBM_GETPOS
, 0, 0);
151 m_pAppSettings
->SetLongParameter( LP_R
, static_cast<int>(NewValue
));
154 // Return false (and notify the user) if something is wrong.
158 LRESULT
CButtonPrefs::WndProc(HWND Window
, UINT message
, WPARAM wParam
, LPARAM lParam
) {
162 if(!m_hwnd
) { // If this is the initial dialog for the first time
172 dNewValue
= SendMessage(m_hZoomStepsSlider
, TBM_GETPOS
, 0, 0);
173 _sntprintf(m_tcBuffer
, 100, TEXT("%d"), static_cast<int>(dNewValue
));
174 SendMessage(m_hZoomStepsBox
, WM_SETTEXT
, 0, (LPARAM
) m_tcBuffer
);
176 dNewValue
= SendMessage(m_hRightZoomSlider
, TBM_GETPOS
, 0, 0);
177 _sntprintf(m_tcBuffer
, 100, TEXT("%0.2f"), dNewValue
);
178 SendMessage(m_hRightZoomBox
, WM_SETTEXT
, 0, (LPARAM
) m_tcBuffer
);
180 dNewValue
= SendMessage(m_hNoBoxesSlider
, TBM_GETPOS
, 0, 0);
181 _sntprintf(m_tcBuffer
, 100, TEXT("%d"), static_cast<int>(dNewValue
));
182 SendMessage(m_hNoBoxesBox
, WM_SETTEXT
, 0, (LPARAM
) m_tcBuffer
);
184 dNewValue
= SendMessage(m_hSafetySlider
, TBM_GETPOS
, 0, 0);
185 _sntprintf(m_tcBuffer
, 100, TEXT("%d"), static_cast<int>(dNewValue
));
186 SendMessage(m_hSafetyBox
, WM_SETTEXT
, 0, (LPARAM
) m_tcBuffer
);
188 dNewValue
= SendMessage(m_hNonUniformSlider
, TBM_GETPOS
, 0, 0);
189 _sntprintf(m_tcBuffer
, 100, TEXT("%d"), static_cast<int>(dNewValue
));
190 SendMessage(m_hNonUniformBox
, WM_SETTEXT
, 0, (LPARAM
) m_tcBuffer
);
192 EnableWindow(GetDlgItem(Window
, IDC_BP_APPLY
), true);
197 switch (LOWORD(wParam
)) {
199 if(HIWORD(wParam
) == EN_CHANGE
) {
200 HWND Control
= GetDlgItem(Window
, IDC_DISPLAY
);
201 LRESULT BufferLength
= SendMessage(Control
, WM_GETTEXTLENGTH
, 0, 0) + 1; // +1 to allow for terminator
202 TCHAR
*Buffer
= new TCHAR
[BufferLength
];
203 SendMessage(Control
, WM_GETTEXT
, BufferLength
, (LPARAM
) Buffer
);
205 SendMessage(GetDlgItem(Window
, IDC_TEXT
), WM_SETTEXT
, 0, (LPARAM
) Buffer
);
211 EndDialog(Window
, LOWORD(wParam
));
213 case (IDC_BP_CANCEL
):
214 EndDialog(Window
, LOWORD(wParam
));
218 EnableWindow(GetDlgItem(Window
, IDC_BP_APPLY
), false);
220 case ID_CANCEL_KEYCONT
:
221 EndDialog(Window
, LOWORD(wParam
));