1 // configure_theme_dlg.cpp : implementation file
2 //
3
4 #include "studiox_includes.h"
5 #include "afxdialogex.h"
6 #include "configure_theme_dlg.h"
7 #include "PaletteLayoutDlg.h"
8
9 #ifdef _DEBUG
10 #define new DEBUG_NEW
11 #endif
12
13 enum configure_theme_dlg_test_commands{
14 TEST_SELECT_DISPLAY_NAME = 1,
15 TEST_ADD_THEME,
16 TEST_DELETE_THEME,
17 TEST_SET_ACTIVE_THEME,
18 TEST_SELECT_THEME_INDEX,
19 TEST_SET_THEME_NAME,
20 TEST_EDIT_PALETTE,
21 TEST_CANCEL_THEME_CONFIGURE,
22 TEST_SAVE_THEME_CONFIGURE
23 };
24
25 // configure_theme_dlg dialog
26
IMPLEMENT_DYNAMIC(configure_theme_dlg,express_dialog)27 IMPLEMENT_DYNAMIC(configure_theme_dlg, express_dialog)
28
29 BEGIN_MESSAGE_MAP(configure_theme_dlg, express_dialog)
30 ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_THEME_INDEX, &configure_theme_dlg::OnDeltaposSpinThemeIndex)
31 ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_NUM_THEMES, &configure_theme_dlg::OnDeltaposSpinNumThemes)
32 ON_CBN_SELCHANGE(IDC_DISPLAY_NAME, &configure_theme_dlg::OnCbnSelchangeDisplayName)
33 ON_BN_CLICKED(IDB_EDIT_PALETTE, &configure_theme_dlg::OnBnClickedEditPalette)
34 ON_BN_CLICKED(IDOK, &configure_theme_dlg::OnOK)
35 ON_EN_KILLFOCUS(IDC_THEME_NAME, &configure_theme_dlg::OnEnKillfocusThemeName)
36 ON_MESSAGE(STUDIO_TEST, &configure_theme_dlg::OnTestMessage)
37 END_MESSAGE_MAP()
38
39 configure_theme_dlg::configure_theme_dlg(int DisplayIndex, CWnd* pParent /*=NULL*/)
40 : express_dialog(configure_theme_dlg::IDD, pParent)
41 {
42 IconId = IDB_CONFIGURE_THEMES;
43 SetTitleText("Configure Themes");
44
45 mDisplayIndex = DisplayIndex;
46 mThemeIndex = 0;
47 mNumThemes = 0;
48
49 if (mDisplayIndex < 0 || mDisplayIndex >= MAX_DISPLAYS)
50 {
51 mDisplayIndex = 0;
52 }
53 }
54
~configure_theme_dlg()55 configure_theme_dlg::~configure_theme_dlg()
56 {
57 }
58
OnInitDialog()59 BOOL configure_theme_dlg::OnInitDialog()
60 {
61 int index;
62 express_dialog::OnInitDialog();
63
64 ShowHidePaletteEditButton();
65
66 CSpinButtonCtrl *pb = (CSpinButtonCtrl *) GetDlgItem(IDC_SPIN_NUM_THEMES);
67 CEdit *pe = (CEdit *) GetDlgItem(IDC_NUM_THEMES);
68 pb->SetBuddy(pe);
69 pb->SetRange(1, MAX_THEMES);
70
71 pb = (CSpinButtonCtrl *) GetDlgItem(IDC_SPIN_THEME_INDEX);
72 pe = (CEdit *) GetDlgItem(IDC_THEME_INDEX);
73 SetDlgItemText(IDC_THEME_INDEX, _T("1"));
74 pb->SetBuddy(pe);
75
76 studiox_project* project = GetOpenProject();
77 mNumThemes = project->mDisplays[mDisplayIndex].num_themes;
78
79 if (project)
80 {
81 pb->SetRange(1, mNumThemes);
82 }
83
84 for (index = 0; index < project->mHeader.num_displays; index++)
85 {
86 mDisplayNameCombo.AddString(project->mDisplays[index].name);
87 }
88 mDisplayNameCombo.SetCurSel(mDisplayIndex);
89
90 // Initiate theme name combo
91 for (index = 0; index < mNumThemes; index++)
92 {
93 mThemeNames[index] = project->mDisplays[mDisplayIndex].themes[index].theme_name;
94 mStaticallyDefined[index] = project->mDisplays[mDisplayIndex].themes[index].statically_defined;
95 mThemeNameCombo.AddString(mThemeNames[index]);
96 }
97 mStaticallyDefinedCheck.SetCheck(project->mDisplays[mDisplayIndex].themes[0].statically_defined);
98 mThemeNameCombo.SetCurSel(project->mDisplays[mDisplayIndex].active_theme);
99
100 CRect size;
101 mDisplayNameCombo.GetWindowRect(&size);
102 size.bottom = size.top + 100;
103 ScreenToClient(&size);
104 mDisplayNameCombo.MoveWindow(size);
105
106 SetDlgItemText(IDC_THEME_NAME, project->mDisplays[mDisplayIndex].themes[DEFAULT_THEME].theme_name);
107
108 AddCancelButton();
109 AddSaveButton();
110
111 //SetWindowText(_T("configure_themes"));
112
113 return TRUE; // return TRUE unless you set the focus to a control
114 }
115
InitializeThemeResourcesThreadEntry(LPVOID thread_input)116 static DWORD WINAPI InitializeThemeResourcesThreadEntry(LPVOID thread_input)
117 {
118 studiox_project* project = GetOpenProject();
119
120 if (project)
121 {
122 INT* param_array = (INT*)thread_input;
123
124 int old_num_themes = param_array[0];
125 int new_num_themes = param_array[1];
126 int display = param_array[2];
127
128 for (int theme = old_num_themes; theme < new_num_themes; theme++)
129 {
130
131 // create default theme resources
132 res_info* theme_0 = project->mDisplays[display].themes[0].GetFirstResourceInfo();
133 res_info* pInfo = new res_info(NULL, *theme_0, TRUE);
134
135 project->mDisplays[display].themes[theme].SetFirstResourceInfo(pInfo);
136
137 project->InitializeThemeResources(display, theme, pInfo);
138 }
139 }
140 EndBusyMsg();
141
142 return TRUE;
143 }
144
DoDataExchange(CDataExchange * pDX)145 void configure_theme_dlg::DoDataExchange(CDataExchange* pDX)
146 {
147 express_dialog::DoDataExchange(pDX);
148
149 DDX_Control(pDX, IDC_DISPLAY_NAME, mDisplayNameCombo);
150 DDX_Control(pDX, IDC_THEME_NAME_COMBO, mThemeNameCombo);
151 DDX_Control(pDX, IDC_THEME_NAME, mThemeName);
152 DDX_Control(pDX, IDC_SPIN_NUM_THEMES, mSpinNumThemes);
153 DDX_Control(pDX, IDC_SPIN_THEME_INDEX, mSpinThemeIndex);
154 DDX_Control(pDX, IDC_STATICALLY_DEFINED, mStaticallyDefinedCheck);
155
156 studiox_project *project = GetOpenProject();
157
158 if (!project)
159 {
160 return;
161 }
162
163 INT old_num_themes = project->mDisplays[mDisplayIndex].num_themes;
164
165 DDX_Text(pDX, IDC_NUM_THEMES, project->mDisplays[mDisplayIndex].num_themes);
166
167 if (pDX->m_bSaveAndValidate)
168 {
169 int index = mSpinThemeIndex.GetPos();
170 mStaticallyDefined[index - 1] = mStaticallyDefinedCheck.GetCheck();
171
172 for (int index = 0; index < mNumThemes; index++)
173 {
174 project->mDisplays[mDisplayIndex].themes[index].theme_name = mThemeNames[index];
175 project->mDisplays[mDisplayIndex].themes[index].statically_defined = mStaticallyDefined[index];
176 }
177
178 for (int theme = mNumThemes; theme < old_num_themes; theme++)
179 {
180 // delete theme resources
181 project->CleanupThemeResources(&project->mDisplays[mDisplayIndex], theme);
182 }
183
184 // create default theme resources
185 INT param_array[3] = { old_num_themes, mNumThemes, mDisplayIndex };
186
187 StartWorkThread(InitializeThemeResourcesThreadEntry, param_array, "Initializing Theme Resources.", TRUE);
188
189 for (int index = 0; index < mNumThemes; index++)
190 {
191 res_info *pInfo = project->mDisplays[mDisplayIndex].themes[index].GetFirstResourceInfo();
192 res_info *pThemeHeader = project->FindResourceFolder(pInfo, RES_TYPE_HEADER, THEME_HEADER);
193
194 if (pThemeHeader)
195 {
196 pThemeHeader->name = project->mDisplays[mDisplayIndex].themes[index].theme_name;
197 }
198 }
199
200 int active_theme = mThemeNameCombo.GetCurSel();
201
202 if (active_theme != project->mDisplays[mDisplayIndex].active_theme)
203 {
204 project->mDisplays[mDisplayIndex].active_theme = active_theme;
205
206 // install active theme resources
207 GetResourceView()->InstallResources(mDisplayIndex);
208 }
209 }
210 }
211
OnCancel()212 void configure_theme_dlg::OnCancel()
213 {
214 // TODO: Add your specialized code here and/or call the base class
215
216 studiox_project* project = GetOpenProject();
217
218 if (!project)
219 {
220 return;
221 }
222
223 for (int theme = project->mDisplays[mDisplayIndex].num_themes; theme < MAX_THEMES; theme++)
224 {
225 // delete theme resources
226 project->CleanupThemeResources(&project->mDisplays[mDisplayIndex], theme);
227 }
228
229 express_dialog::OnCancel();
230 }
231
232 // configure_theme_dlg message handlers
233
OnDeltaposSpinThemeIndex(NMHDR * pNMHDR,LRESULT * pResult)234 void configure_theme_dlg::OnDeltaposSpinThemeIndex(NMHDR *pNMHDR, LRESULT *pResult)
235 {
236 LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
237 // TODO: Add your control notification handler code here
238
239 int upper;
240 int lower;
241
242 mSpinThemeIndex.GetRange(lower, upper);
243 studiox_project *project = GetOpenProject();
244
245 if (!project)
246 {
247 return;
248 }
249
250 int oldval = pNMUpDown ->iPos;
251 int newval = oldval + pNMUpDown->iDelta;
252
253 // save the current name, update to new name, if the value is within
254 // limits
255 if (oldval <= upper && oldval >= lower &&
256 newval <= upper && newval >= lower)
257 {
258 if (!TestInputName(&mThemeName, "Theme Name", mThemeNames[oldval - 1], this))
259 {
260 *pResult = -1;
261 return;
262 }
263 SetDlgItemText(IDC_THEME_NAME, mThemeNames[newval - 1]);
264
265 mStaticallyDefined[oldval - 1] = mStaticallyDefinedCheck.GetCheck();
266 mStaticallyDefinedCheck.SetCheck(mStaticallyDefined[newval - 1]);
267
268 mThemeIndex = newval - 1;
269
270 UpdateThemeNameCombo();
271 }
272
273 *pResult = 0;
274 }
275
276 /////////////////////////////////////////////////////////////////////////////
OnDeltaposSpinNumThemes(NMHDR * pNMHDR,LRESULT * pResult)277 void configure_theme_dlg::OnDeltaposSpinNumThemes(NMHDR *pNMHDR, LRESULT *pResult)
278 {
279 LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
280 // TODO: Add your control notification handler code here
281
282 int oldval = pNMUpDown ->iPos;
283 int newval = oldval + pNMUpDown->iDelta;
284 studiox_project *project = GetOpenProject();
285
286 // save the current name, update to new name, if the value is within
287 // limits
288 if (oldval <= MAX_THEMES && oldval >= 1 &&
289 newval <= MAX_THEMES && newval >= 1)
290 {
291 if (newval < oldval)
292 {
293 // decreased theme number
294 CString msg;
295 msg.Format(_T("The theme \"%s\" will be deleted. Are you sure?"), mThemeNames[oldval - 1].GetString());
296
297 if (!AskUser(CT2A(msg.GetString()), this))
298 {
299 mSpinNumThemes.SetPos(oldval + oldval - newval);
300 return;
301 }
302
303 if (mSpinThemeIndex.GetPos() > newval)
304 {
305 mSpinThemeIndex.SetPos(newval);
306 SetDlgItemText(IDC_THEME_NAME, mThemeNames[newval - 1]);
307 mStaticallyDefinedCheck.SetCheck(mStaticallyDefined[newval - 1]);
308 }
309 }
310 else
311 {
312 // increased theme number
313 mThemeNames[newval - 1].Format(_T("theme_%d"), newval);
314 mStaticallyDefined[newval - 1] = TRUE;
315 }
316
317 mSpinThemeIndex.SetRange(1, newval);
318 mSpinThemeIndex.Invalidate();
319 mNumThemes = newval;
320 UpdateThemeNameCombo();
321 }
322
323 *pResult = 0;
324 }
325
326 /////////////////////////////////////////////////////////////////////////////
OnCbnSelchangeDisplayName()327 void configure_theme_dlg::OnCbnSelchangeDisplayName()
328 {
329 // TODO: Add your control notification handler code here
330 studiox_project *project = GetOpenProject();
331 int new_display_index = mDisplayNameCombo.GetCurSel();
332 if (project && (mDisplayIndex != new_display_index))
333 {
334 mDisplayIndex = new_display_index;
335 mNumThemes = project->mDisplays[mDisplayIndex].num_themes;
336
337 UpdateThemeNameCombo();
338
339 mThemeIndex = mThemeNameCombo.GetCurSel();
340
341 mSpinThemeIndex.SetPos(1);
342 mSpinThemeIndex.SetRange(1, mNumThemes);
343 mSpinNumThemes.SetPos(mNumThemes);
344 SetDlgItemText(IDC_THEME_NAME, project->mDisplays[mDisplayIndex].themes[0].theme_name);
345
346 ShowHidePaletteEditButton();
347 }
348 }
349
350 /////////////////////////////////////////////////////////////////////////////
OnBnClickedEditPalette()351 void configure_theme_dlg::OnBnClickedEditPalette()
352 {
353 // TODO: Add your control notification handler code here
354 PaletteLayoutDlg dlg(mDisplayIndex, mThemeIndex, this);
355 dlg.DoModal();
356 GetDlgItem(IDB_EDIT_PALETTE)->SetFocus();
357 }
358
359 /////////////////////////////////////////////////////////////////////////////
OnOK()360 void configure_theme_dlg::OnOK()
361 {
362 int theme = GetDlgItemInt(IDC_THEME_INDEX) - 1;
363
364 if (TestInputName(&mThemeName, "Theme Name", mThemeNames[theme], this))
365 {
366 express_dialog::OnOK();
367 }
368
369 }
370
371 /////////////////////////////////////////////////////////////////////////////
UpdateThemeNameCombo()372 void configure_theme_dlg::UpdateThemeNameCombo()
373 {
374 studiox_project *project = GetOpenProject();
375
376 if (!project)
377 {
378 return;
379 }
380
381 int active_theme = mThemeNameCombo.GetCurSel();
382
383 mThemeNameCombo.ResetContent();
384 for (int index = 0; index < mNumThemes; index++)
385 {
386 mThemeNameCombo.AddString(mThemeNames[index]);
387 }
388
389 int last = mThemeNameCombo.GetCount() - 1;
390
391 if (active_theme > last)
392 {
393 active_theme = last;
394 }
395
396 mThemeNameCombo.SetCurSel(active_theme);
397 }
398
399 /////////////////////////////////////////////////////////////////////////////
ShowHidePaletteEditButton()400 void configure_theme_dlg::ShowHidePaletteEditButton()
401 {
402 studiox_project* project = GetOpenProject();
403 BOOL ShowEditDlgBtn = FALSE;
404
405 if (project)
406 {
407 if ((project->mDisplays[mDisplayIndex].bits_per_pix == 8) &&
408 (project->mDisplays[mDisplayIndex].packed_format == FALSE) &&
409 (project->mDisplays[mDisplayIndex].format_332 == FALSE))
410 {
411 ShowEditDlgBtn = TRUE;
412 }
413 }
414
415 GetDlgItem(IDB_EDIT_PALETTE)->ShowWindow(ShowEditDlgBtn);
416 }
417
418 /////////////////////////////////////////////////////////////////////////////
OnEnKillfocusThemeName()419 void configure_theme_dlg::OnEnKillfocusThemeName()
420 {
421 // TODO: Add your control notification handler code here
422 int theme = GetDlgItemInt(IDC_THEME_INDEX) - 1;
423 GetDlgItemText(IDC_THEME_NAME, mThemeNames[theme]);
424 UpdateThemeNameCombo();
425 }
426
427
428 /////////////////////////////////////////////////////////////////////////////
OnTestMessage(WPARAM wParam,LPARAM lParam)429 afx_msg LRESULT configure_theme_dlg::OnTestMessage(WPARAM wParam, LPARAM lParam)
430 {
431 NMUPDOWN NMUpDown;
432 NMHDR hdr;
433
434 switch (wParam)
435 {
436 case TEST_SELECT_DISPLAY_NAME:
437 mDisplayNameCombo.SelectString(0, GetTestingParam(0));
438 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_DISPLAY_NAME, CBN_SELCHANGE), (LPARAM)mDisplayNameCombo.m_hWnd);
439 break;
440
441 case TEST_ADD_THEME:
442 hdr.hwndFrom = mSpinNumThemes.m_hWnd;
443 hdr.idFrom = IDC_SPIN_NUM_THEMES;
444 hdr.code = UDN_DELTAPOS;
445
446 NMUpDown.hdr = hdr;
447 NMUpDown.iPos = mSpinNumThemes.GetPos();
448 NMUpDown.iDelta = 1;
449
450 mSpinNumThemes.SetPos(NMUpDown.iPos + 1);
451 SetDlgItemInt(IDC_NUM_THEMES, NMUpDown.iPos + 1);
452
453 SendMessage(WM_NOTIFY, IDC_SPIN_NUM_THEMES, (LPARAM)&NMUpDown);
454 break;
455
456 case TEST_DELETE_THEME:
457 hdr.hwndFrom = mSpinNumThemes.m_hWnd;
458 hdr.idFrom = IDC_SPIN_NUM_THEMES;
459 hdr.code = UDN_DELTAPOS;
460
461 NMUpDown.hdr = hdr;
462 NMUpDown.iPos = mSpinNumThemes.GetPos();
463 NMUpDown.iDelta = -1;
464
465 mSpinNumThemes.SetPos(NMUpDown.iPos - 1);
466 SetDlgItemInt(IDC_NUM_THEMES, NMUpDown.iPos - 1);
467
468 SendMessage(WM_NOTIFY, IDC_SPIN_NUM_THEMES, (LPARAM)&NMUpDown);
469 break;
470
471 case TEST_SET_ACTIVE_THEME:
472 mThemeNameCombo.SelectString(0, GetTestingParam(0));
473 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_THEME_NAME_COMBO, CBN_SELCHANGE), (LPARAM)mThemeNameCombo.m_hWnd);
474 break;
475
476 case TEST_SELECT_THEME_INDEX:
477 hdr.hwndFrom = mSpinThemeIndex.m_hWnd;
478 hdr.idFrom = IDC_SPIN_THEME_INDEX;
479 hdr.code = UDN_DELTAPOS;
480
481 NMUpDown.hdr = hdr;
482 NMUpDown.iPos = mSpinThemeIndex.GetPos();
483 NMUpDown.iDelta = lParam - NMUpDown.iPos;
484
485 mSpinThemeIndex.SetPos(lParam);
486 SetDlgItemInt(IDC_LANGUAGE_INDEX, lParam);
487
488 SendMessage(WM_NOTIFY, IDC_SPIN_THEME_INDEX, (LPARAM)&NMUpDown);
489 break;
490
491 case TEST_SET_THEME_NAME:
492 mThemeName.SetWindowText(GetTestingParam(0));
493 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_THEME_NAME, EN_KILLFOCUS), (LPARAM)mThemeName.m_hWnd);
494 break;
495
496 case TEST_EDIT_PALETTE:
497 OnBnClickedEditPalette();
498 break;
499
500 case TEST_CANCEL_THEME_CONFIGURE:
501 OnCancel();
502 break;
503
504 case TEST_SAVE_THEME_CONFIGURE:
505 OnOK();
506 break;
507 }
508
509 return 0;
510 }
511