-rw-r--r-- | ActionPage.cpp | 278 |
1 files changed, 278 insertions, 0 deletions
diff --git a/ActionPage.cpp b/ActionPage.cpp new file mode 100644 index 0000000..ec9699c --- a/dev/null +++ b/ActionPage.cpp | |||
@@ -0,0 +1,278 @@ | |||
1 | // ActionPage.cpp : implementation file | ||
2 | // | ||
3 | |||
4 | #include "stdafx.h" | ||
5 | #include "BigBrother.h" | ||
6 | #include "ActionPage.h" | ||
7 | #include "HostPropertyPages.h" | ||
8 | #include "BigBrotherDoc.h" | ||
9 | #include "BigBrotherView.h" | ||
10 | |||
11 | #ifdef _DEBUG | ||
12 | #define new DEBUG_NEW | ||
13 | #undef THIS_FILE | ||
14 | static char THIS_FILE[] = __FILE__; | ||
15 | #endif | ||
16 | |||
17 | ///////////////////////////////////////////////////////////////////////////// | ||
18 | // CActionPage property page | ||
19 | |||
20 | IMPLEMENT_DYNCREATE(CActionPage, CPropertyPage) | ||
21 | |||
22 | CActionPage::CActionPage() : CPropertyPage(CActionPage::IDD) | ||
23 | { | ||
24 | //{{AFX_DATA_INIT(CActionPage) | ||
25 | m_bCustomDn = FALSE; | ||
26 | m_bCustomUp = FALSE; | ||
27 | m_OverrideAction = FALSE; | ||
28 | m_bPlayASoundDn = FALSE; | ||
29 | m_bPlayASoundUp = FALSE; | ||
30 | m_CustomDn = _T(""); | ||
31 | m_CustomUp = _T(""); | ||
32 | m_SoundDn = _T(""); | ||
33 | m_SoundUp = _T(""); | ||
34 | //}}AFX_DATA_INIT | ||
35 | m_PreplayIcon = AfxGetApp()->LoadIcon(IDI_PREPLAY); | ||
36 | m_BrowseIcon = AfxGetApp()->LoadIcon(IDI_BROWSESOUND); | ||
37 | } | ||
38 | |||
39 | CActionPage::~CActionPage() | ||
40 | { | ||
41 | } | ||
42 | |||
43 | void CActionPage::DoDataExchange(CDataExchange* pDX) | ||
44 | { | ||
45 | CPropertyPage::DoDataExchange(pDX); | ||
46 | //{{AFX_DATA_MAP(CActionPage) | ||
47 | DDX_Control(pDX, IDC_BROWSE_SOUND_UP, m_BrowseUpCtl); | ||
48 | DDX_Control(pDX, IDC_BROWSE_SOUND_DOWN, m_BrowseDnCtl); | ||
49 | DDX_Control(pDX, IDC_PREVIEW_SOUND_UP, m_SoundPreviewUp); | ||
50 | DDX_Control(pDX, IDC_PREVIEW_SOUND_DOWN, m_SoundPreviewDn); | ||
51 | DDX_Control(pDX, IDC_SOUND_UP, m_SoundUpCtl); | ||
52 | DDX_Control(pDX, IDC_SOUND_DOWN, m_SoundDnCtl); | ||
53 | DDX_Control(pDX, IDC_PROGRAM_UP, m_CustomUpCtl); | ||
54 | DDX_Control(pDX, IDC_PROGRAM_DOWN, m_CustomDnCtl); | ||
55 | DDX_Control(pDX, IDC_PLAYASOUND_UP, m_bPlayASoundUpCtl); | ||
56 | DDX_Control(pDX, IDC_PLAYASOUND_DOWN, m_bPlayASoundDnCtl); | ||
57 | DDX_Control(pDX, IDC_OVERRIDE_ACTION, m_OverrideActionCtl); | ||
58 | DDX_Control(pDX, IDC_CUSTOM_UP, m_bCustomUpCtl); | ||
59 | DDX_Control(pDX, IDC_CUSTOM_DOWN, m_bCustomDnCtl); | ||
60 | DDX_Check(pDX, IDC_CUSTOM_DOWN, m_bCustomDn); | ||
61 | DDX_Check(pDX, IDC_CUSTOM_UP, m_bCustomUp); | ||
62 | DDX_Check(pDX, IDC_OVERRIDE_ACTION, m_OverrideAction); | ||
63 | DDX_Check(pDX, IDC_PLAYASOUND_DOWN, m_bPlayASoundDn); | ||
64 | DDX_Check(pDX, IDC_PLAYASOUND_UP, m_bPlayASoundUp); | ||
65 | DDX_Text(pDX, IDC_PROGRAM_DOWN, m_CustomDn); | ||
66 | DDX_Text(pDX, IDC_PROGRAM_UP, m_CustomUp); | ||
67 | DDX_CBString(pDX, IDC_SOUND_DOWN, m_SoundDn); | ||
68 | DDX_CBString(pDX, IDC_SOUND_UP, m_SoundUp); | ||
69 | //}}AFX_DATA_MAP | ||
70 | } | ||
71 | |||
72 | |||
73 | BEGIN_MESSAGE_MAP(CActionPage, CPropertyPage) | ||
74 | //{{AFX_MSG_MAP(CActionPage) | ||
75 | ON_BN_CLICKED(IDC_CUSTOM_DOWN, OnCustomDown) | ||
76 | ON_BN_CLICKED(IDC_CUSTOM_UP, OnCustomUp) | ||
77 | ON_BN_CLICKED(IDC_OVERRIDE_ACTION, OnOverrideAction) | ||
78 | ON_BN_CLICKED(IDC_PLAYASOUND_DOWN, OnPlayasoundDown) | ||
79 | ON_BN_CLICKED(IDC_PLAYASOUND_UP, OnPlayasoundUp) | ||
80 | ON_BN_CLICKED(IDC_PREVIEW_SOUND_UP, OnPreviewSoundUp) | ||
81 | ON_BN_CLICKED(IDC_PREVIEW_SOUND_DOWN, OnPreviewSoundDown) | ||
82 | ON_BN_CLICKED(IDC_BROWSE_SOUND_DOWN, OnBrowseSoundDown) | ||
83 | ON_BN_CLICKED(IDC_BROWSE_SOUND_UP, OnBrowseSoundUp) | ||
84 | //}}AFX_MSG_MAP | ||
85 | END_MESSAGE_MAP() | ||
86 | |||
87 | ///////////////////////////////////////////////////////////////////////////// | ||
88 | // CActionPage message handlers | ||
89 | |||
90 | void CActionPage::SetupControls() | ||
91 | { | ||
92 | m_bPlayASoundUpCtl.EnableWindow(m_OverrideAction); | ||
93 | m_bPlayASoundDnCtl.EnableWindow(m_OverrideAction); | ||
94 | m_bCustomUpCtl.EnableWindow(m_OverrideAction); | ||
95 | m_bCustomDnCtl.EnableWindow(m_OverrideAction); | ||
96 | m_SoundUpCtl.EnableWindow(m_bPlayASoundUp&&m_OverrideAction); | ||
97 | m_SoundDnCtl.EnableWindow(m_bPlayASoundDn&&m_OverrideAction); | ||
98 | m_SoundPreviewUp.EnableWindow(m_bPlayASoundUp); | ||
99 | m_SoundPreviewDn.EnableWindow(m_bPlayASoundDn); | ||
100 | m_BrowseUpCtl.EnableWindow(m_bPlayASoundUp&&m_OverrideAction); | ||
101 | m_BrowseDnCtl.EnableWindow(m_bPlayASoundDn&&m_OverrideAction); | ||
102 | m_CustomUpCtl.EnableWindow(m_bCustomUp&&m_OverrideAction); | ||
103 | m_CustomDnCtl.EnableWindow(m_bCustomDn&&m_OverrideAction); | ||
104 | } | ||
105 | |||
106 | void CActionPage::UpdatePage() | ||
107 | { | ||
108 | if(!m_dad->m_Brother) | ||
109 | return; | ||
110 | if(::IsWindow(m_hWnd)){ | ||
111 | m_SoundPreviewUp.SetIcon(m_PreplayIcon); | ||
112 | m_SoundPreviewDn.SetIcon(m_PreplayIcon); | ||
113 | m_BrowseUpCtl.SetIcon(m_BrowseIcon); | ||
114 | m_BrowseDnCtl.SetIcon(m_BrowseIcon); | ||
115 | if(m_dad->m_Brother->m_Daddy) | ||
116 | m_OverrideActionCtl.EnableWindow(TRUE); | ||
117 | else | ||
118 | m_OverrideActionCtl.EnableWindow(FALSE); | ||
119 | } | ||
120 | if(m_dad->m_Brother->flags&CBrother::flagsOverrideActions) | ||
121 | m_OverrideAction=TRUE; | ||
122 | else | ||
123 | m_OverrideAction=FALSE; | ||
124 | if(m_dad->m_Brother->m_Up.flags&CAction::flagsPlayASound) | ||
125 | m_bPlayASoundUp=TRUE; | ||
126 | else | ||
127 | m_bPlayASoundUp=FALSE; | ||
128 | if(m_dad->m_Brother->m_Up.flags&CAction::flagsRunCustom) | ||
129 | m_bCustomUp=TRUE; | ||
130 | else | ||
131 | m_bCustomUp=FALSE; | ||
132 | if(m_dad->m_Brother->m_Down.flags&CAction::flagsPlayASound) | ||
133 | m_bPlayASoundDn=TRUE; | ||
134 | else | ||
135 | m_bPlayASoundDn=FALSE; | ||
136 | if(m_dad->m_Brother->m_Down.flags&CAction::flagsRunCustom) | ||
137 | m_bCustomDn=TRUE; | ||
138 | else | ||
139 | m_bCustomDn=FALSE; | ||
140 | m_SoundUp=m_dad->m_Brother->m_Up.m_Sound; | ||
141 | m_CustomUp=m_dad->m_Brother->m_Up.m_Custom; | ||
142 | m_SoundDn=m_dad->m_Brother->m_Down.m_Sound; | ||
143 | m_CustomDn=m_dad->m_Brother->m_Down.m_Custom; | ||
144 | if(::IsWindow(m_hWnd)){ | ||
145 | UpdateData(FALSE); | ||
146 | SetupControls(); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | BOOL CActionPage::OnSetActive() | ||
151 | { | ||
152 | UpdatePage(); | ||
153 | return CPropertyPage::OnSetActive(); | ||
154 | } | ||
155 | |||
156 | void CActionPage::UpdateBrother() | ||
157 | { | ||
158 | if(!m_dad->m_Brother){ | ||
159 | TRACE0("No brother on update\n"); | ||
160 | return; | ||
161 | } | ||
162 | if(::IsWindow(m_hWnd)) | ||
163 | UpdateData(); | ||
164 | CBrother toCompare; | ||
165 | toCompare = *m_dad->m_Brother; | ||
166 | if(m_OverrideAction) | ||
167 | m_dad->m_Brother->flags|=CBrother::flagsOverrideActions; | ||
168 | else | ||
169 | m_dad->m_Brother->flags&=~CBrother::flagsOverrideActions; | ||
170 | if(m_bPlayASoundUp) | ||
171 | m_dad->m_Brother->m_Up.flags|=CAction::flagsPlayASound; | ||
172 | else | ||
173 | m_dad->m_Brother->m_Up.flags&=~CAction::flagsPlayASound; | ||
174 | m_dad->m_Brother->m_Up.m_Sound=m_SoundUp; | ||
175 | if(m_bCustomUp) | ||
176 | m_dad->m_Brother->m_Up.flags|=CAction::flagsRunCustom; | ||
177 | else | ||
178 | m_dad->m_Brother->m_Up.flags&=~CAction::flagsRunCustom; | ||
179 | m_dad->m_Brother->m_Up.m_Custom=m_CustomUp; | ||
180 | if(m_bPlayASoundDn) | ||
181 | m_dad->m_Brother->m_Down.flags|=CAction::flagsPlayASound; | ||
182 | else | ||
183 | m_dad->m_Brother->m_Down.flags&=~CAction::flagsPlayASound; | ||
184 | m_dad->m_Brother->m_Down.m_Sound=m_SoundDn; | ||
185 | if(m_bCustomDn) | ||
186 | m_dad->m_Brother->m_Down.flags|=CAction::flagsRunCustom; | ||
187 | else | ||
188 | m_dad->m_Brother->m_Down.flags&=~CAction::flagsRunCustom; | ||
189 | m_dad->m_Brother->m_Down.m_Custom=m_CustomDn; | ||
190 | m_dad->m_Brother->ParentalAdjust(); | ||
191 | if(toCompare!=(*m_dad->m_Brother)){ | ||
192 | ASSERT(m_dad->m_Daddy); | ||
193 | CDocument *pDoc = m_dad->m_Daddy->GetDocument(); | ||
194 | ASSERT(pDoc); | ||
195 | pDoc->SetModifiedFlag(); | ||
196 | } | ||
197 | if(::IsWindow(m_hWnd)){ | ||
198 | UpdateData(FALSE); | ||
199 | SetupControls(); | ||
200 | } | ||
201 | } | ||
202 | |||
203 | BOOL CActionPage::OnKillActive() | ||
204 | { | ||
205 | UpdateBrother(); | ||
206 | return CPropertyPage::OnKillActive(); | ||
207 | } | ||
208 | |||
209 | void CActionPage::OnCustomDown() | ||
210 | { | ||
211 | UpdateBrother(); | ||
212 | if(m_bCustomDn) | ||
213 | m_CustomDnCtl.SetFocus(); | ||
214 | } | ||
215 | |||
216 | void CActionPage::OnCustomUp() | ||
217 | { | ||
218 | UpdateBrother(); | ||
219 | if(m_bCustomUp) | ||
220 | m_CustomUpCtl.SetFocus(); | ||
221 | } | ||
222 | |||
223 | void CActionPage::OnOverrideAction() | ||
224 | { | ||
225 | UpdateBrother(); | ||
226 | } | ||
227 | |||
228 | void CActionPage::OnPlayasoundDown() | ||
229 | { | ||
230 | UpdateBrother(); | ||
231 | if(m_bPlayASoundDn) | ||
232 | m_SoundDnCtl.SetFocus(); | ||
233 | } | ||
234 | |||
235 | void CActionPage::OnPlayasoundUp() | ||
236 | { | ||
237 | UpdateBrother(); | ||
238 | if(m_bPlayASoundUp) | ||
239 | m_SoundUpCtl.SetFocus(); | ||
240 | } | ||
241 | |||
242 | void CActionPage::OnPreviewSoundUp() | ||
243 | { | ||
244 | ASSERT(m_bPlayASoundUp); | ||
245 | UpdateBrother(); | ||
246 | CAction::PlayASound(m_SoundUp); | ||
247 | } | ||
248 | |||
249 | void CActionPage::OnPreviewSoundDown() | ||
250 | { | ||
251 | ASSERT(m_bPlayASoundDn); | ||
252 | UpdateBrother(); | ||
253 | CAction::PlayASound(m_SoundDn); | ||
254 | } | ||
255 | |||
256 | void CActionPage::OnBrowseSoundDown() | ||
257 | { | ||
258 | BrowseCtl(m_SoundDnCtl); | ||
259 | } | ||
260 | |||
261 | void CActionPage::OnBrowseSoundUp() | ||
262 | { | ||
263 | BrowseCtl(m_SoundUpCtl); | ||
264 | } | ||
265 | |||
266 | void CActionPage::BrowseCtl(CComboBox& ctl) | ||
267 | { | ||
268 | CString filter; | ||
269 | filter.LoadString(IDS_WAVFILTER); | ||
270 | CString title; | ||
271 | title.LoadString(IDS_SOUND_SELECT); | ||
272 | CFileDialog cfd(TRUE,NULL,NULL,OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,filter,this); | ||
273 | cfd.m_ofn.lpstrTitle=title; | ||
274 | if(cfd.DoModal()==IDOK){ | ||
275 | ctl.SetWindowText(cfd.GetPathName()); | ||
276 | UpdateBrother(); | ||
277 | } | ||
278 | } | ||