tagging release
[dasher.git] / trunk / Src / Win32 / Widgets / LMPage.cpp
blob612ef3f1d92b7fa1aefac0c3467bbf358ceebaf2
1 // LMPage.cpp
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002 Iain Murray, Inference Group, Cavendish, Cambridge.
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 #include "WinCommon.h"
11 #include "LMPage.h"
12 #include "../resource.h"
14 #include <utility> // for std::pair
16 using namespace Dasher;
17 using namespace std;
19 // Track memory leaks on Windows to the line that new'd the memory
20 #ifdef _WIN32
21 #ifdef _DEBUG
22 #define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
23 #define new DEBUG_NEW
24 #undef THIS_FILE
25 static char THIS_FILE[] = __FILE__;
26 #endif
27 #endif
29 CLMPage::CLMPage(HWND Parent, CDasherInterfaceBase *DI, CAppSettings *pAppSettings)
30 :CPrefsPageBase(Parent, DI, pAppSettings) {
34 void CLMPage::PopulateList() {
35 #ifndef JAPANESE
36 EnableWindow(GetDlgItem(m_hwnd, IDC_LM_JAPANESE), FALSE);
37 #endif
39 slider = GetDlgItem(m_hwnd, IDC_UNIFORMSLIDER);
40 SendMessage(slider, TBM_SETPAGESIZE, 0L, 20); // PgUp and PgDown change bitrate by reasonable amount
41 SendMessage(slider, TBM_SETTICFREQ, 10, 0L);
42 SendMessage(slider, TBM_SETRANGE, FALSE, (LPARAM) MAKELONG(0, 1000));
44 uniformbox = GetDlgItem(m_hwnd, IDC_UNIFORMVAL);
46 if(m_pAppSettings->GetBoolParameter(BP_LM_ADAPTIVE)) {
47 SendMessage(GetDlgItem(m_hwnd, IDC_ADAPTIVE), BM_SETCHECK, BST_CHECKED, 0);
49 else {
50 SendMessage(GetDlgItem(m_hwnd, IDC_ADAPTIVE), BM_SETCHECK, BST_UNCHECKED, 0);
53 SendMessage(slider, TBM_SETPOS, TRUE, (LPARAM) m_pAppSettings->GetLongParameter(LP_UNIFORM));
55 _sntprintf(m_tcBuffer, 100, TEXT("%0.1f"), m_pAppSettings->GetLongParameter(LP_UNIFORM) / 10.0);
56 SendMessage(uniformbox, WM_SETTEXT, 0, (LPARAM) m_tcBuffer);
58 switch(m_pAppSettings->GetLongParameter(LP_LANGUAGE_MODEL_ID)) {
59 case 0:
60 SendMessage(GetDlgItem(m_hwnd, IDC_LM_PPM), BM_SETCHECK, BST_CHECKED, 0);
61 break;
62 case 2:
63 SendMessage(GetDlgItem(m_hwnd, IDC_LM_WORD), BM_SETCHECK, BST_CHECKED, 0);
64 break;
65 case 3:
66 SendMessage(GetDlgItem(m_hwnd, IDC_LM_MIXTURE), BM_SETCHECK, BST_CHECKED, 0);
67 break;
68 #ifdef JAPANESE
69 case 4:
70 SendMessage(GetDlgItem(m_hwnd, IDC_LM_JAPANESE), BM_SETCHECK, BST_CHECKED, 0);
71 break;
72 #endif
77 bool CLMPage::Validate() {
78 // 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.
79 return TRUE;
82 bool CLMPage::Apply() {
83 m_pAppSettings->SetBoolParameter( BP_LM_ADAPTIVE, SendMessage(GetDlgItem(m_hwnd, IDC_ADAPTIVE), BM_GETCHECK, 0, 0)!=0 );
85 double NewUniform;
86 NewUniform = SendMessage(slider, TBM_GETPOS, 0, 0);
87 m_pAppSettings->SetLongParameter( LP_UNIFORM, NewUniform);
89 if(SendMessage(GetDlgItem(m_hwnd, IDC_LM_PPM), BM_GETCHECK, 0, 0))
90 m_pAppSettings->SetLongParameter(LP_LANGUAGE_MODEL_ID, 0);
91 else if(SendMessage(GetDlgItem(m_hwnd, IDC_LM_WORD), BM_GETCHECK, 0, 0))
92 m_pAppSettings->SetLongParameter(LP_LANGUAGE_MODEL_ID, 2);
93 else if(SendMessage(GetDlgItem(m_hwnd, IDC_LM_MIXTURE), BM_GETCHECK, 0, 0))
94 m_pAppSettings->SetLongParameter(LP_LANGUAGE_MODEL_ID, 3);
95 #ifdef JAPANESE
96 else if(SendMessage(GetDlgItem(m_hwnd, IDC_LM_JAPANESE), BM_GETCHECK, 0, 0))
97 m_pAppSettings->SetLongParameter(LP_LANGUAGE_MODEL_ID, 4);
98 #endif
100 // Return false (and notify the user) if something is wrong.
101 return TRUE;
104 LRESULT CLMPage::WndProc(HWND Window, UINT message, WPARAM wParam, LPARAM lParam) {
106 double NewUniform;
108 // most things we pass on to CPrefsPageBase, but we need to handle slider motion
110 switch (message) {
111 case WM_HSCROLL:
112 if((LOWORD(wParam) == SB_THUMBPOSITION) | (LOWORD(wParam) == SB_THUMBTRACK)) {
113 // Some messages give the new postion
114 NewUniform = HIWORD(wParam);
116 else {
117 // Otherwise we have to ask for it
118 long Pos = SendMessage(slider, TBM_GETPOS, 0, 0);
119 NewUniform = Pos;
122 _sntprintf(m_tcBuffer, 100, TEXT("%0.1f"), NewUniform / 10);
123 SendMessage(uniformbox, WM_SETTEXT, 0, (LPARAM) m_tcBuffer);
125 return TRUE;
126 break;
127 default:
128 return CPrefsPageBase::WndProc(Window, message, wParam, lParam);
130 //return FALSE;