1 #include "studiox_includes.h"
2 #include "trigger_action_edit_dlg.h"
3
4 // trigger_action_edit_dlg dialog
5 enum trigger_action_edit_dlg_test_commands {
6 TEST_ADD_ACTION = 1,
7 TEST_SELECT_ACTION,
8 TEST_DELETE_ACTION,
9 TEST_SELECT_TARGET,
10 TEST_SELECT_PARENT,
11 TEST_TARGET_SHOW_CHILD_WIDGETS,
12 TEST_PARENT_SHOW_CHILD_WIDGETS,
13 TEST_EDIT_ACTION_NAME,
14 TEST_EDIT_ANIMATION_INFO,
15 TEST_CHECK_DETACH_TARGET,
16 TEST_CONFIGURE_EASING_FUNCTION,
17 TEST_SAVE_TRIGGER_ACTION_EDIT,
18 TEST_CANCEL_TRIGGER_ACTION_EDIT
19 };
20
21 // Define animation parameter names
22 STRING_VAL_PAIR AnimationParamNames[] = {
23 { _T("Animation ID"), ID_ANIMATION_ID },
24 { _T("Start X"), ID_ANIMATION_START_X },
25 { _T("Start Y"), ID_ANIMATION_START_Y },
26 { _T("End X"), ID_ANIMATION_END_X },
27 { _T("End Y"), ID_ANIMATION_END_Y },
28 { _T("Steps"), ID_ANIMATION_STEPS },
29 { _T("Tick Rate"), ID_ANIMATION_TICK_RATE },
30 { _T("Delay Before"), ID_ANIMATION_DELAY_BEFORE },
31 { _T("Start Alpha"), ID_ANIMATION_START_ALPHA },
32 { _T("End Alpha"),ID_ANIMATION_END_ALPHA },
33 { _T(""), 0 }
34 };
35
36 CString SCREEN_STACK_POP_STRING(_T("gx_system_screen_stack_pop"));
37
38 extern CFont NormalFont;
39 extern CString target_class_name;
40
41
IMPLEMENT_DYNAMIC(trigger_action_edit_dlg,express_dialog)42 IMPLEMENT_DYNAMIC(trigger_action_edit_dlg, express_dialog)
43
44 BEGIN_MESSAGE_MAP(trigger_action_edit_dlg, express_dialog)
45 ON_BN_CLICKED(IDC_ADD_ACTION, &trigger_action_edit_dlg::OnAddAction)
46 ON_BN_CLICKED(IDC_DELETE_ACTION, &trigger_action_edit_dlg::OnDeleteAction)
47 ON_LBN_SELCHANGE(IDC_ADDED_ACTION_LIST, &trigger_action_edit_dlg::OnSelectAddedActionList)
48 ON_CBN_SELCHANGE(IDC_TARGET_COMBO, &trigger_action_edit_dlg::OnSelectTargetCombo)
49 ON_CBN_SELCHANGE(IDC_PARENT_COMBO, &trigger_action_edit_dlg::OnSelectParentCombo)
50 ON_EN_KILLFOCUS(IDC_ACTION_NAME, &trigger_action_edit_dlg::OnChangeActionName)
51 ON_BN_CLICKED(ID_EASING_FUNCTION_SELECT, OnClickEasingFunction)
52 ON_BN_CLICKED(IDC_TARGET_SHOW_CHILD_WIDGETS, &trigger_action_edit_dlg::OnClickTargetShowChildWidgets)
53 ON_BN_CLICKED(IDC_PARENT_SHOW_CHILD_WIDGETS, &trigger_action_edit_dlg::OnClickParentShowChildWidgets)
54 ON_MESSAGE(STUDIO_TEST, &trigger_action_edit_dlg::OnTestMessage)
55 END_MESSAGE_MAP()
56
57 ///////////////////////////////////////////////////////////////////////////////
58 trigger_action_edit_dlg::trigger_action_edit_dlg(int display_index, flow_item *item, trigger_info *trigger, CWnd* pParent /*=NULL*/)
59 : express_dialog(trigger_action_edit_dlg::IDD, pParent)
60 {
61 CString title;
62
63 IconId = IDB_MACRO_PLAYBACK_ICON;
64 if (trigger->event_type)
65 {
66 title.Format(_T("Edit Actions for Trigger [%s]"), trigger->trigger_name);
67 }
68 else
69 {
70 title.Format(_T("Add Actions for Trigger [%s]"), trigger->trigger_name);
71 }
72 SetTitleText(title);
73
74 mDisplayIndex = display_index;
75 mpTrigger = trigger;
76
77 action_info *action;
78 mActionList.RemoveAll();
79 for (int index = 0; index < trigger->action_list.GetCount(); index++)
80 {
81 action = new action_info(*trigger->action_list.GetAt(index));
82
83 mActionList.Add(action);
84 }
85
86 studiox_project *project = GetOpenProject();
87 widget_info *info = NULL;
88 if (project)
89 {
90 info = project->FindWidgetInfo(project->mDisplays[display_index].GetFirstChildFolder(), item->screen_name, FALSE);
91 }
92
93 mpInfo = info;
94 mAddedActionListSel = -1;
95 mAnimationEasingFuncId = 0;
96 }
97
98 ///////////////////////////////////////////////////////////////////////////////
~trigger_action_edit_dlg()99 trigger_action_edit_dlg::~trigger_action_edit_dlg()
100 {
101 trigger_info::CleanActionList(mActionList);
102 }
103
104 ///////////////////////////////////////////////////////////////////////////////
OnInitDialog()105 BOOL trigger_action_edit_dlg::OnInitDialog()
106 {
107 express_dialog::OnInitDialog();
108
109 // TODO: Add extra initialization here
110 CRect rect;
111 CRect size;
112 int item_height;
113 int item_width;
114 int index;
115
116 // Create animation parameter controls.
117 mAnimationParams.GetWindowRect(&rect);
118 ScreenToClient(&rect);
119
120 // get animation parameter group box text size
121 CString text;
122 mAnimationParams.GetWindowTextW(text);
123 CDC* pDC = mAnimationParams.GetDC();
124 CFont* pFont = mAnimationParams.GetFont();
125 CFont* pOldFont = pDC->SelectObject(pFont);
126 CSize sz = pDC->GetTextExtent(text);
127 pDC->SelectObject(pOldFont);
128
129 item_height = (rect.Height() - 30) / (ANIMATION_PARAMS_COUNT + 1) - 3;
130 item_width = (rect.Width() - 20) / 2 - 10;
131
132 size.top = rect.top + sz.cy + 10;
133
134 CFont *font = mAnimationParams.GetFont();
135
136 for (index = 0; index < ANIMATION_PARAMS_COUNT; index++)
137 {
138 size.left = rect.left + 5;
139
140 size.right = size.left + item_width * 2 / 3;
141 size.bottom = size.top + item_height;
142 mAnimationParamLabels[index].Create(AnimationParamNames[index].name, WS_CHILD | WS_VISIBLE, size, this);
143 mAnimationParamLabels[index].SetFont(font);
144 size.left = size.right + 5;
145 size.right = rect.right - 5;
146 mAnimationParamEdits[index].Create(WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | WS_TABSTOP | ES_AUTOHSCROLL,
147 size, this, AnimationParamNames[index].val);
148 mAnimationParamEdits[index].SetFont(font);
149
150 switch (AnimationParamNames[index].val)
151 {
152 case ID_ANIMATION_START_X:
153 case ID_ANIMATION_START_Y:
154 case ID_ANIMATION_END_X:
155 case ID_ANIMATION_END_Y:
156 mAnimationParamEdits[index].EnableNegativeValue();
157 mAnimationParamEdits[index].EnableNumberCheck();
158 break;
159
160 case ID_ANIMATION_STEPS:
161 case ID_ANIMATION_TICK_RATE:
162 case ID_ANIMATION_DELAY_BEFORE:
163 case ID_ANIMATION_START_ALPHA:
164 case ID_ANIMATION_END_ALPHA:
165 mAnimationParamEdits[index].EnableNumberCheck();
166 break;
167 }
168
169 size.top = size.bottom + 3;
170 }
171
172 size.left = rect.left + 5;
173 size.top = size.bottom + 8;
174 size.bottom = rect.bottom - 5;
175 size.right = size.left + item_width;
176 mEasingFunctionEdit.Create(WS_CHILD | SS_LEFT | WS_VISIBLE | WS_BORDER | ES_READONLY, size, this, 0);
177 mEasingFunctionEdit.SetFont(font);
178 SetEasingFunction();
179
180 size.left = size.right + 5;
181 size.right = rect.right - 5;
182 mEasingFunctionButton.Create(_T("Easing Func Select"), WS_CHILD | WS_VISIBLE | WS_TABSTOP, size, this, ID_EASING_FUNCTION_SELECT);
183 mEasingFunctionButton.SetFont(font);
184
185 mOnAnimationCompleteGroup.GetWindowRect(&rect);
186 ScreenToClient(&rect);
187
188 size.left = rect.left + 5;
189 size.top = rect.top + sz.cy + 10;
190 size.bottom = size.top + item_height;
191 size.right = size.left + item_width * 2;
192 mDetachTargetBox.Create(_T("Detach Target"), WS_CHILD | WS_TABSTOP | BS_AUTOCHECKBOX, size, this, IDC_DETACH_TARGET);
193 mDetachTargetBox.SetFont(font);
194
195 size.top += item_height + 3;
196 size.bottom += item_height + 3;
197 mPushTargetBox.Create(_T("Push Target to Screen Stack"), WS_CHILD | WS_TABSTOP | BS_AUTOCHECKBOX, size, this, IDC_TARGET_TO_SCREEN_STACK);
198 mPushTargetBox.SetFont(font);
199
200 InitActionLists();
201 ShowHideAnimationParams();
202
203 SetControlAccessibleName(mTargetShowChildWidgets.GetSafeHwnd(), _T("show target's child widget"));
204 SetControlAccessibleName(mParentShowChildWidgets.GetSafeHwnd(), _T("show parent's child widget"));
205 SetControlAccessibleName(mEasingFunctionEdit.GetSafeHwnd(), _T("easing function name"));
206
207 AddCancelButton();
208 AddSaveButton();
209
210 mStatusMsg.Create(L"", WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this);
211 SetLiveRegion(mStatusMsg.GetSafeHwnd());
212
213 return TRUE;
214 }
215
216 ///////////////////////////////////////////////////////////////////////////////
DoDataExchange(CDataExchange * pDX)217 void trigger_action_edit_dlg::DoDataExchange(CDataExchange* pDX)
218 {
219 express_dialog::DoDataExchange(pDX);
220 DDX_Control(pDX, IDC_ANIMATION_PARAMS, mAnimationParams);
221 DDX_Control(pDX, IDC_ADDED_ACTION_LIST, mAddedActionList);
222 DDX_Control(pDX, IDC_TARGET_COMBO, mTargetCombo);
223 DDX_Control(pDX, IDC_PARENT_COMBO, mParentCombo);
224 DDX_Control(pDX, IDC_TARGET_SHOW_CHILD_WIDGETS, mTargetShowChildWidgets);
225 DDX_Control(pDX, IDC_PARENT_SHOW_CHILD_WIDGETS, mParentShowChildWidgets);
226
227 DDX_Control(pDX, IDC_ON_ANIMATION_COMPLETE, mOnAnimationCompleteGroup);
228 }
229
230 ///////////////////////////////////////////////////////////////////////////////
OnOK()231 void trigger_action_edit_dlg::OnOK()
232 {
233 if (!SaveActionInfo())
234 {
235 return;
236 }
237
238 express_dialog::OnOK();
239 }
240
241 ///////////////////////////////////////////////////////////////////////////////
OnCancel()242 void trigger_action_edit_dlg::OnCancel()
243 {
244 action_info *action;
245 for (int index = 0; index < mActionList.GetCount(); index++)
246 {
247 action = mActionList.GetAt(index);
248 action->RemoveAnimationIdFromDictionary(mDisplayIndex);
249 }
250
251 mpTrigger->AddAnimationIdToDictionary(mDisplayIndex);
252
253 express_dialog::OnCancel();
254 }
255
256 ///////////////////////////////////////////////////////////////////////////////
PreTranslateMessage(MSG * pMsg)257 BOOL trigger_action_edit_dlg::PreTranslateMessage(MSG* pMsg)
258 {
259 if (pMsg->message == WM_KEYDOWN)
260 {
261
262 CWnd* focus_owner = GetFocus();
263 int ctrl_id = -1;
264
265 if (focus_owner)
266 {
267 ctrl_id = focus_owner->GetDlgCtrlID();
268 }
269 if ((pMsg->wParam == VK_RETURN) &&
270 (ctrl_id == IDC_ACTION_NAME))
271 {
272 OnChangeActionName();
273 return TRUE;
274 }
275 }
276
277 return express_dialog::PreTranslateMessage(pMsg);
278 }
279
280 ///////////////////////////////////////////////////////////////////////////////
OnAddAction()281 void trigger_action_edit_dlg::OnAddAction()
282 {
283 trigger_action_select_dlg dlg(this);
284
285 if (dlg.DoModal() == IDOK)
286 {
287 CString action_name("");
288 int action_type = 0;
289
290 action_name = dlg.GetSelectedActionName();
291 action_type = dlg.GetSelectedActionType();
292
293 if ((action_type > 0) && SaveAnimationInfo())
294 {
295 //add new action to the action list
296 action_info *action = new action_info;
297 action->action_type = action_type;
298 action->action_name = action_name;
299 action->target_widget_name = _T("");
300 action->parent_widget_name = _T("");
301 trigger_info::CreateUniqueActionName(mActionList, action);
302
303 mActionList.Add(action);
304
305 int sel = mAddedActionList.AddString(action->action_name);
306 mAddedActionList.SetItemData(sel, action_type);
307 mAddedActionList.SetCurSel(sel);
308
309 mAddedActionListSel = sel;
310
311 mTargetShowChildWidgets.SetCheck(FALSE);
312 mParentShowChildWidgets.SetCheck(FALSE);
313 OnClickTargetShowChildWidgets();
314 OnClickParentShowChildWidgets();
315
316 SetDlgItemText(IDC_ACTION_TYPE, trigger_action_select_dlg::GetActionTypeName(action->action_type));
317 SetDlgItemText(IDC_ACTION_NAME, action->action_name);
318
319 //if the new action type is animation, show animation params
320 ShowHideAnimationParams();
321
322 EnableDisableActionDeleteButton();
323 }
324 }
325 }
326
327 ///////////////////////////////////////////////////////////////////////////////
OnDeleteAction()328 void trigger_action_edit_dlg::OnDeleteAction()
329 {
330 int sel = mAddedActionList.GetCurSel();
331
332 if (sel >= 0)
333 {
334 int type = mAddedActionList.GetItemData(sel);
335 CString action_name;
336
337 mAddedActionList.GetText(sel, action_name);
338 mAddedActionList.DeleteString(sel);
339
340 action_info *action;
341 for (int index = 0; index < mActionList.GetCount(); index++)
342 {
343 action = mActionList.GetAt(index);
344
345 if (action->action_name == action_name)
346 {
347 action->RemoveAnimationIdFromDictionary(mDisplayIndex);
348
349 delete mActionList.GetAt(index);
350 mActionList.RemoveAt(index);
351 break;
352 }
353 }
354
355 if (sel < mAddedActionList.GetCount())
356 {
357 mAddedActionList.SetCurSel(sel);
358 }
359 else if (sel > 0)
360 {
361 mAddedActionList.SetCurSel(sel - 1);
362 }
363
364 mAddedActionListSel = -1;
365 OnSelectAddedActionList();
366
367 CMainFrame* pMain = (CMainFrame*)AfxGetApp()->GetMainWnd();
368
369 if (pMain)
370 {
371 CString msg;
372 msg.Format(L"%s action is deleted.", action_name);
373 mStatusMsg.SetWindowText(msg);
374 mStatusMsg.NotifyWinEvent(
375 EVENT_OBJECT_LIVEREGIONCHANGED,
376 OBJID_CLIENT,
377 CHILDID_SELF);
378 }
379
380 EnableDisableActionDeleteButton();
381 }
382 }
383
384
385 ///////////////////////////////////////////////////////////////////////////////
OnSelectAddedActionList()386 void trigger_action_edit_dlg::OnSelectAddedActionList()
387 {
388 // TODO: Add your control notification handler code here
389
390 if ((mAddedActionListSel >= 0) &&
391 (mAddedActionListSel < mAddedActionList.GetCount()))
392 {
393 int previous_sel_type = mAddedActionList.GetItemData(mAddedActionListSel);
394
395 if (previous_sel_type == GX_ACTION_TYPE_ANIMATION)
396 {
397 //save animation information for previous selected action
398 if (!SaveAnimationInfo())
399 {
400 mAddedActionList.SetCurSel(mAddedActionListSel);
401 return;
402 }
403 }
404 }
405
406 action_info *action = SelectedActionGet();
407 if (action)
408 {
409 BOOL check = mTargetShowChildWidgets.GetCheck();
410 if (check != action->target_show_child_widgets)
411 {
412 mTargetShowChildWidgets.SetCheck(action->target_show_child_widgets);
413 ResetTargets(&mTargetCombo);
414 }
415
416 check = mParentShowChildWidgets.GetCheck();
417 if (check != action->target_show_child_widgets)
418 {
419 mParentShowChildWidgets.SetCheck(action->parent_show_child_widgets);
420 ResetTargets(&mParentCombo);
421 }
422
423 // set target screen name for selected action
424 UpdateTargetCombo(&mTargetCombo, action->target_widget_name);
425 UpdateTargetCombo(&mParentCombo, action->parent_widget_name);
426
427 // set action type/name for selected action
428 SetDlgItemText(IDC_ACTION_TYPE, trigger_action_select_dlg::GetActionTypeName(action->action_type));
429 SetDlgItemText(IDC_ACTION_NAME, action->action_name);
430 }
431
432 mAddedActionListSel = mAddedActionList.GetCurSel();
433 ShowHideAnimationParams();
434 }
435
436 ///////////////////////////////////////////////////////////////////////////////
OnChangeActionName()437 void trigger_action_edit_dlg::OnChangeActionName()
438 {
439 action_info *action = SelectedActionGet();
440 if (action)
441 {
442 CString new_name;
443 GetDlgItemText(IDC_ACTION_NAME, new_name);
444
445 if (new_name.IsEmpty())
446 {
447 SetDlgItemText(IDC_ACTION_NAME, action->action_name);
448 ErrorMsg(_T("Invalid Action Name!"), this);
449 }
450 else if ((new_name != action->action_name) &&
451 (trigger_info::FindActionName(mActionList, new_name)))
452 {
453 SetDlgItemText(IDC_ACTION_NAME, action->action_name);
454 ErrorMsg(_T("Action Name Already Exist!"), this);
455 }
456 else
457 {
458 int sel = mAddedActionList.GetCurSel();
459 mAddedActionList.DeleteString(sel);
460
461 action->action_name = new_name;
462
463 sel = mAddedActionList.AddString(action->action_name);
464 mAddedActionList.SetItemData(sel, action->action_type);
465 mAddedActionList.SetCurSel(sel);
466
467 mAddedActionListSel = sel;
468
469
470 //Update horizontal extend
471 UpdateListBoxHorizontalExtend(&mAddedActionList);
472 }
473 }
474 }
475
476 ///////////////////////////////////////////////////////////////////////////////
OnSelectTargetCombo()477 void trigger_action_edit_dlg::OnSelectTargetCombo()
478 {
479 OnSelectTargetCombo(&mTargetCombo);
480 }
481
482 ///////////////////////////////////////////////////////////////////////////////
OnSelectParentCombo()483 void trigger_action_edit_dlg::OnSelectParentCombo()
484 {
485 OnSelectTargetCombo(&mParentCombo);
486 }
487
488 ///////////////////////////////////////////////////////////////////////////////
OnClickEasingFunction()489 void trigger_action_edit_dlg::OnClickEasingFunction()
490 {
491 easing_function_select_dlg dlg(mAnimationEasingFuncId, this);
492 if (dlg.DoModal() == IDOK)
493 {
494 mAnimationEasingFuncId = dlg.GetEasingFuncId();
495 SetEasingFunction();
496 }
497 }
498
499 ///////////////////////////////////////////////////////////////////////////////
OnClickTargetShowChildWidgets()500 void trigger_action_edit_dlg::OnClickTargetShowChildWidgets()
501 {
502 //reset target combolist with child widgets
503 ResetTargets(&mTargetCombo);
504
505 BOOL check = mTargetShowChildWidgets.GetCheck();
506
507 action_info *action = SelectedActionGet();
508
509 if (action)
510 {
511 UpdateTargetCombo(&mTargetCombo, action->target_widget_name);
512 action->target_show_child_widgets = check;
513 }
514 }
515
516 ///////////////////////////////////////////////////////////////////////////////
OnClickParentShowChildWidgets()517 void trigger_action_edit_dlg::OnClickParentShowChildWidgets()
518 {
519 //reset target and parent combolist with child widgets
520 ResetTargets(&mParentCombo);
521
522 BOOL check = mParentShowChildWidgets.GetCheck();
523
524 action_info *action = SelectedActionGet();
525
526 if (action)
527 {
528 UpdateTargetCombo(&mParentCombo, action->parent_widget_name);
529 action->parent_show_child_widgets = check;
530 }
531 }
532
533
534 ///////////////////////////////////////////////////////////////////////////////
SelectedActionGet()535 action_info *trigger_action_edit_dlg::SelectedActionGet()
536 {
537 int action_sel = mAddedActionList.GetCurSel();
538
539 if (action_sel >= 0)
540 {
541 CString action_name;
542 mAddedActionList.GetText(action_sel, action_name);
543
544 action_info *action;
545 for (int index = 0; index < mActionList.GetCount(); index++)
546 {
547 action = mActionList.GetAt(index);
548
549 if (action_name == action->action_name)
550 {
551 return action;
552 }
553 }
554 }
555 return NULL;
556 }
557
558 ///////////////////////////////////////////////////////////////////////////////
SetEasingFunction()559 void trigger_action_edit_dlg::SetEasingFunction()
560 {
561
562 CString easing_func = easing_function_select_dlg::GetEasingFuncIdName(mAnimationEasingFuncId);
563 if (easing_func.IsEmpty())
564 {
565 easing_func = _T("None");
566 }
567 mEasingFunctionEdit.SetWindowText(easing_func);
568 }
569
570 ///////////////////////////////////////////////////////////////////////////////
UpdateListBoxHorizontalExtend(CListBox * pList)571 void trigger_action_edit_dlg::UpdateListBoxHorizontalExtend(CListBox *pList)
572 {
573 // Find the longest string in the list box.
574 CString str;
575 CSize sz;
576 int dx = 0;
577 TEXTMETRIC tm;
578 CDC* pDC = pList->GetDC();
579 CFont* pFont = pList->GetFont();
580
581 // Select the listbox font, save the old font
582 CFont* pOldFont = pDC->SelectObject(pFont);
583 // Get the text metrics for avg char width
584 pDC->GetTextMetrics(&tm);
585
586 for (int index = 0; index < pList->GetCount(); index++)
587 {
588 pList->GetText(index, str);
589 sz = pDC->GetTextExtent(str);
590
591 // Add the avg width to prevent clipping
592 sz.cx += tm.tmAveCharWidth;
593
594 if (sz.cx > dx)
595 dx = sz.cx;
596 }
597 // Select the old font back into the DC
598 pDC->SelectObject(pOldFont);
599 pList->ReleaseDC(pDC);
600
601 // Set the horizontal extent so every character of all strings
602 // can be scrolled to.
603 pList->SetHorizontalExtent(dx);
604 }
605
606 ///////////////////////////////////////////////////////////////////////////////
OnSelectTargetCombo(CComboBox * pBox)607 void trigger_action_edit_dlg::OnSelectTargetCombo(CComboBox *pBox)
608 {
609 action_info *action = SelectedActionGet();
610
611 if (action)
612 {
613 int target_sel = pBox->GetCurSel();
614 CString target_name;
615
616 if (target_sel == 0)
617 {
618 target_name = "";
619 }
620 else
621 {
622 pBox->GetLBText(target_sel, target_name);
623 }
624
625 if (pBox == &mTargetCombo)
626 {
627 action->target_widget_name = target_name;
628 }
629 else
630 {
631 action->parent_widget_name = target_name;
632 }
633 }
634 }
635
636 ///////////////////////////////////////////////////////////////////////////////
UpdateTargetCombo(CComboBox * pBox,CString & string)637 void trigger_action_edit_dlg::UpdateTargetCombo(CComboBox *pBox, CString &string)
638 {
639 if (string.IsEmpty())
640 {
641 pBox->SetCurSel(0);
642 }
643 else
644 {
645 pBox->SelectString(0, string);
646 }
647 }
648
649 ///////////////////////////////////////////////////////////////////////////////
AddComboList(CComboBox * pBox,STRING_VAL_PAIR * list,LONG current_val)650 void trigger_action_edit_dlg::AddComboList(CComboBox *pBox, STRING_VAL_PAIR *list, LONG current_val)
651 {
652 STRING_VAL_PAIR *current = list;
653 int index;
654
655 while (current->name.GetLength())
656 {
657 index = pBox->AddString(current->name);
658 pBox->SetItemData(index, current->val);
659 current++;
660 }
661
662 pBox->InsertString(0, _T("None"));
663 SelectComboListItem(pBox, current_val);
664 }
665
SelectComboListItem(CComboBox * box,LONG val)666 void trigger_action_edit_dlg::SelectComboListItem(CComboBox *box, LONG val)
667 {
668 int sel_index = 0;
669
670 for (int box_index = 0; box_index < box->GetCount(); box_index++)
671 {
672 if (box->GetItemData(box_index) == val)
673 {
674 sel_index = box_index;
675 break;
676 }
677 }
678
679 box->SetCurSel(sel_index);
680 }
681
682 ///////////////////////////////////////////////////////////////////////////////
SelectComboListItem(CComboBox * box,CString string)683 void trigger_action_edit_dlg::SelectComboListItem(CComboBox *box, CString string)
684 {
685 CString get_string;
686 int sel_index = 0;
687
688 for (int box_index = 0; box_index < box->GetCount(); box_index++)
689 {
690 box->GetLBText(box_index, get_string);
691 if (get_string == string)
692 {
693 sel_index = box_index;
694 break;
695 }
696 }
697
698 box->SetCurSel(sel_index);
699 }
700
701 ///////////////////////////////////////////////////////////////////////////////
InitActionLists()702 void trigger_action_edit_dlg::InitActionLists()
703 {
704 CListBox *pBox= &mAddedActionList;
705
706 action_info *action;
707
708 if (mActionList.IsEmpty())
709 {
710 AddTargets(&mTargetCombo);
711 AddTargets(&mParentCombo);
712 }
713 else
714 {
715 for (int index = 0; index < mActionList.GetCount(); index++)
716 {
717 action = mActionList.GetAt(index);
718 int sel = pBox->AddString(action->action_name);
719 pBox->SetItemData(sel, action->action_type);
720 }
721 }
722
723 if (pBox->GetCount())
724 {
725 pBox->SetCurSel(0);
726 mAddedActionListSel = 0;
727 action = SelectedActionGet();
728
729 if (action)
730 {
731 mTargetShowChildWidgets.SetCheck(action->target_show_child_widgets);
732 mParentShowChildWidgets.SetCheck(action->parent_show_child_widgets);
733 AddTargets(&mTargetCombo);
734 AddTargets(&mParentCombo);
735
736 UpdateTargetCombo(&mTargetCombo, action->target_widget_name);
737 UpdateTargetCombo(&mParentCombo, action->parent_widget_name);
738 SetDlgItemText(IDC_ACTION_TYPE, trigger_action_select_dlg::GetActionTypeName(action->action_type));
739 SetDlgItemText(IDC_ACTION_NAME, action->action_name);
740 }
741 }
742
743 UpdateListBoxHorizontalExtend(pBox);
744 EnableDisableActionDeleteButton();
745 }
746
747 ///////////////////////////////////////////////////////////////////////////////
AddChildTargets(CComboBox * pBox,widget_info * info)748 void trigger_action_edit_dlg::AddChildTargets(CComboBox *pBox, widget_info *info)
749 {
750 widget_info *child = info->GetChildWidgetInfo();
751 while (child)
752 {
753 pBox->AddString(child->app_name);
754
755 if (child->GetChildWidgetInfo())
756 {
757 AddChildTargets(pBox, child);
758 }
759 child = child->GetNextWidgetInfo();
760 }
761 }
762
763 ///////////////////////////////////////////////////////////////////////////////
AddTargets(CComboBox * pBox)764 void trigger_action_edit_dlg::AddTargets(CComboBox *pBox)
765 {
766 int pos;
767 widget_info *info;
768 CButton *pButton;
769
770 if (pBox == &mTargetCombo)
771 {
772 pButton = &mTargetShowChildWidgets;
773 }
774 else
775 {
776 pButton = &mParentShowChildWidgets;
777 }
778
779 if (pButton->GetCheck())
780 {
781 //add current screen
782 //pBox->AddString(mpInfo->app_name);
783
784 //add child widgets
785 studiox_project *project = GetOpenProject();
786 if (project)
787 {
788 AddChildTargets(pBox, mpInfo);
789 }
790 }
791 else
792 {
793 //add top level widgets
794 CArray<widget_info *> screen_list;
795 GetProjectView()->GetTopLevelWidgetList(mDisplayIndex, &screen_list);
796
797 for (int index = 0; index < screen_list.GetCount(); index++)
798 {
799 info = screen_list.GetAt(index);
800
801 if (!info->is_template)
802 {
803 pos = pBox->AddString(info->app_name);
804 }
805 }
806 }
807
808 pBox->InsertString(0, _T("None"));
809 pBox->InsertString(1, SCREEN_STACK_POP_STRING);
810 pBox->SetCurSel(0);
811 }
812
813 ///////////////////////////////////////////////////////////////////////////////
ResetTargets(CComboBox * pBox)814 void trigger_action_edit_dlg::ResetTargets(CComboBox *pBox)
815 {
816 pBox->ResetContent();
817 AddTargets(pBox);
818 }
819
820 ///////////////////////////////////////////////////////////////////////////////
ShowHideAnimationParams()821 void trigger_action_edit_dlg::ShowHideAnimationParams()
822 {
823 BOOL show = FALSE;
824 action_info *action = NULL;
825 GX_ANIMATION_INFO *animation = NULL;
826
827 if (mAddedActionListSel >= 0)
828 {
829 int action_type = mAddedActionList.GetItemData(mAddedActionListSel);
830 if (action_type == GX_ACTION_TYPE_ANIMATION)
831 {
832 show = TRUE;
833 }
834
835 CString action_name;
836 mAddedActionList.GetText(mAddedActionListSel, action_name);
837
838 action = trigger_info::GetActionInfo(mActionList, action_name);
839 animation = action->animation;
840 }
841
842 mAnimationParams.ShowWindow(show);
843
844
845 if (animation)
846 {
847 if (animation->gx_animation_style & GX_ANIMATION_DETACH)
848 {
849 mDetachTargetBox.SetCheck(TRUE);
850 }
851 else
852 {
853 mDetachTargetBox.SetCheck(FALSE);
854 }
855
856 if (animation->gx_animation_style & GX_ANIMATION_PUSH_STACK)
857 {
858 mPushTargetBox.SetCheck(TRUE);
859 }
860 else
861 {
862 mPushTargetBox.SetCheck(FALSE);
863 }
864
865 mAnimationEasingFuncId = animation->gx_animation_style & GX_ANIMATION_EASING_FUNC_MASK;
866 SetEasingFunction();
867 }
868 else
869 {
870 mAnimationEasingFuncId = 0;
871 SetEasingFunction();
872 }
873
874 mEasingFunctionButton.ShowWindow(show);
875 mEasingFunctionEdit.ShowWindow(show);
876
877 CString string;
878 int index;
879
880 for (index = 0; index < ANIMATION_PARAMS_COUNT; index++)
881 {
882 mAnimationParamLabels[index].ShowWindow(show);
883 mAnimationParamEdits[index].ShowWindow(show);
884
885 switch (AnimationParamNames[index].val)
886 {
887 case ID_ANIMATION_ID:
888 if (animation)
889 {
890 string = action->animation_id_name;
891 }
892 else
893 {
894 string = _T("");
895 }
896 break;
897
898 case ID_ANIMATION_START_X:
899 if (animation)
900 {
901 string.Format(_T("%d"), animation->gx_animation_start_position.gx_point_x);
902 }
903 else
904 {
905 string = _T("0");
906 }
907 break;
908
909 case ID_ANIMATION_START_Y:
910 if (animation)
911 {
912 string.Format(_T("%d"), animation->gx_animation_start_position.gx_point_y);
913 }
914 else
915 {
916 string = _T("0");
917 }
918 break;
919
920 case ID_ANIMATION_END_X:
921 if (animation)
922 {
923 string.Format(_T("%d"), animation->gx_animation_end_position.gx_point_x);
924 }
925 else
926 {
927 string = _T("0");
928 }
929 break;
930
931 case ID_ANIMATION_END_Y:
932 if (animation)
933 {
934 string.Format(_T("%d"), animation->gx_animation_end_position.gx_point_y);
935 }
936 else
937 {
938 string = _T("0");
939 }
940 break;
941
942 case ID_ANIMATION_STEPS:
943 if (animation)
944 {
945 string.Format(_T("%d"), animation->gx_animation_steps);
946 }
947 else
948 {
949 string = _T("10");
950 }
951 break;
952
953 case ID_ANIMATION_TICK_RATE:
954 if (animation)
955 {
956 string.Format(_T("%d"), animation->gx_animation_frame_interval);
957 }
958 else
959 {
960 string = _T("1");
961 }
962 break;
963
964 case ID_ANIMATION_DELAY_BEFORE:
965 if (animation)
966 {
967 string.Format(_T("%d"), animation->gx_animation_start_delay);
968 }
969 else
970 {
971 string = _T("0");
972 }
973 break;
974
975 case ID_ANIMATION_START_ALPHA:
976 if (animation)
977 {
978 string.Format(_T("%d"), animation->gx_animation_start_alpha);
979 }
980 else
981 {
982 string = _T("255");
983 }
984 break;
985
986 case ID_ANIMATION_END_ALPHA:
987 if (animation)
988 {
989 string.Format(_T("%d"), animation->gx_animation_end_alpha);
990 }
991 else
992 {
993 string = _T("255");
994 }
995 break;
996 }
997
998 mAnimationParamEdits[index].SetWindowText(string);
999 }
1000
1001
1002 mOnAnimationCompleteGroup.ShowWindow(show);
1003
1004 mDetachTargetBox.ShowWindow(show);
1005 mPushTargetBox.ShowWindow(show);
1006 }
1007
1008 ///////////////////////////////////////////////////////////////////////////////
EnableDisableActionDeleteButton()1009 void trigger_action_edit_dlg::EnableDisableActionDeleteButton()
1010 {
1011 CWnd *delete_button = GetDlgItem(IDC_DELETE_ACTION);
1012
1013 if (!delete_button)
1014 {
1015 return;
1016 }
1017
1018 if (mActionList.GetCount() == 0)
1019 {
1020 if (GetFocus() == delete_button)
1021 {
1022 // Move focus to add button.
1023 CWnd *add_button = GetDlgItem(IDC_ADD_ACTION);
1024 if (add_button)
1025 {
1026 add_button->SetFocus();
1027 }
1028 }
1029
1030 delete_button->EnableWindow(FALSE);
1031 }
1032 else
1033 {
1034 delete_button->EnableWindow(TRUE);
1035 }
1036 }
1037
SaveActionInfo()1038 BOOL trigger_action_edit_dlg::SaveActionInfo()
1039 {
1040 if (!SaveAnimationInfo())
1041 {
1042 return FALSE;
1043 }
1044
1045 //save action list
1046 mpTrigger->CleanActionList(mpTrigger->action_list);
1047
1048 action_info *action;
1049 for (int index = 0; index < mActionList.GetCount(); index++)
1050 {
1051 action = mActionList.GetAt(index);
1052 mpTrigger->action_list.Add(action);
1053 }
1054
1055 mActionList.RemoveAll();
1056
1057 return TRUE;
1058 }
1059
1060 ///////////////////////////////////////////////////////////////////////////////
SaveAnimationInfo()1061 BOOL trigger_action_edit_dlg::SaveAnimationInfo()
1062 {
1063 studiox_project *project = GetOpenProject();
1064
1065 if (!project)
1066 {
1067 return FALSE;
1068 }
1069
1070 if (mAddedActionListSel < 0)
1071 {
1072 // no aciton been selected, just return
1073 return TRUE;
1074 }
1075
1076 int type = mAddedActionList.GetItemData(mAddedActionListSel);
1077
1078 if (type != GX_ACTION_TYPE_ANIMATION)
1079 {
1080 // current selected action type is not animation, just return
1081 return TRUE;
1082 }
1083
1084 CString action_name;
1085 mAddedActionList.GetText(mAddedActionListSel, action_name);
1086
1087 action_info *action = trigger_info::GetActionInfo(mActionList, action_name);
1088
1089 //int cursel = mAnimationTypesCombo.GetCurSel();
1090
1091 if (!action->animation)
1092 {
1093 action->animation = new GX_ANIMATION_INFO;
1094 memset(action->animation, 0, sizeof(GX_ANIMATION_INFO));
1095 }
1096
1097 for (int index = 0; index < ANIMATION_PARAMS_COUNT; index++)
1098 {
1099 CString text;
1100 mAnimationParamEdits[index].GetWindowText(text);
1101 int value = _ttoi(text);
1102
1103 switch (AnimationParamNames[index].val)
1104 {
1105 case ID_ANIMATION_ID:
1106 if (action->animation_id_name != text)
1107 {
1108 CString old_text = action->animation_id_name;
1109 if (text.IsEmpty())
1110 {
1111 screen_flow *flow = project->mDisplays[mDisplayIndex].screenflow;
1112 if (flow && flow->IsAnimationIdBeReferenced(old_text))
1113 {
1114 mAnimationParamEdits[index].SetWindowText(old_text);
1115 Notify("Animation id cannot be empty, it is referened by another trigger!", this);
1116 return FALSE;
1117 }
1118 else
1119 {
1120 //remove old animation id name
1121 action->RemoveAnimationIdFromDictionary(mDisplayIndex);
1122 action->animation_id_name = text;
1123 }
1124 }
1125 else if (TestInputName(&mAnimationParamEdits[index], "Animation ID", old_text, this))
1126 {
1127 //remove old animation id name
1128 action->RemoveAnimationIdFromDictionary(mDisplayIndex);
1129
1130 action->animation_id_name = text;
1131
1132 //add new animation id name
1133 action->AddAnimationIdToDictionary(mDisplayIndex);
1134 }
1135 else
1136 {
1137 return FALSE;
1138 }
1139 }
1140 break;
1141
1142 case ID_ANIMATION_START_X:
1143 action->animation->gx_animation_start_position.gx_point_x = value;
1144 break;
1145
1146 case ID_ANIMATION_START_Y:
1147 action->animation->gx_animation_start_position.gx_point_y = value;
1148 break;
1149
1150 case ID_ANIMATION_END_X:
1151 action->animation->gx_animation_end_position.gx_point_x = value;
1152 break;
1153
1154 case ID_ANIMATION_END_Y:
1155 action->animation->gx_animation_end_position.gx_point_y = value;
1156 break;
1157
1158 case ID_ANIMATION_STEPS:
1159 action->animation->gx_animation_steps = value;
1160 break;
1161
1162 case ID_ANIMATION_TICK_RATE:
1163 action->animation->gx_animation_frame_interval = value;
1164 break;
1165
1166 case ID_ANIMATION_DELAY_BEFORE:
1167 action->animation->gx_animation_start_delay = value;
1168 break;
1169
1170 case ID_ANIMATION_START_ALPHA:
1171 action->animation->gx_animation_start_alpha = value;
1172 break;
1173
1174 case ID_ANIMATION_END_ALPHA:
1175 action->animation->gx_animation_end_alpha = value;
1176 break;
1177 }
1178 }
1179
1180 if (mDetachTargetBox.GetCheck())
1181 {
1182 action->animation->gx_animation_style |= GX_ANIMATION_DETACH;
1183 }
1184 else
1185 {
1186 action->animation->gx_animation_style &= ~GX_ANIMATION_DETACH;
1187 }
1188
1189 if (mPushTargetBox.GetCheck())
1190 {
1191 action->animation->gx_animation_style |= GX_ANIMATION_PUSH_STACK;
1192 }
1193 else
1194 {
1195 action->animation->gx_animation_style &= ~GX_ANIMATION_PUSH_STACK;
1196 }
1197
1198 CString easingfunc;
1199 mEasingFunctionEdit.GetWindowText(easingfunc);
1200 mAnimationEasingFuncId = easing_function_select_dlg::GetEasingFuncId(easingfunc);
1201 action->animation->gx_animation_style &= ~GX_ANIMATION_EASING_FUNC_MASK;
1202 action->animation->gx_animation_style |= mAnimationEasingFuncId;
1203
1204 return TRUE;
1205 }
1206
1207 ///////////////////////////////////////////////////////////////////////////////
OnTestMessage(WPARAM wParam,LPARAM lParam)1208 LRESULT trigger_action_edit_dlg::OnTestMessage(WPARAM wParam, LPARAM lParam)
1209 {
1210 int ctrl_id;
1211 CWnd *pWnd;
1212 CString str;
1213 CStringArray param_list;
1214
1215 switch (wParam)
1216 {
1217 case TEST_ADD_ACTION:
1218 OnAddAction();
1219 break;
1220
1221 case TEST_SELECT_ACTION:
1222 mAddedActionList.SelectString(0, GetTestingParam(0));
1223 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_ADDED_ACTION_LIST, LBN_SELCHANGE), (LPARAM)mAddedActionList.m_hWnd);
1224 break;
1225
1226 case TEST_DELETE_ACTION:
1227 OnDeleteAction();
1228 break;
1229
1230 case TEST_SELECT_TARGET:
1231 mTargetCombo.SelectString(0, GetTestingParam(0));
1232 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_TARGET_COMBO, CBN_SELCHANGE), (LPARAM)mTargetCombo.m_hWnd);
1233 break;
1234
1235 case TEST_SELECT_PARENT:
1236 mParentCombo.SelectString(0, GetTestingParam(0));
1237 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_PARENT_COMBO, CBN_SELCHANGE), (LPARAM)mParentCombo.m_hWnd);
1238 break;
1239
1240 case TEST_EDIT_ACTION_NAME:
1241 ctrl_id = IDC_ACTION_NAME;
1242 pWnd = GetDlgItem(ctrl_id);
1243 if (pWnd)
1244 {
1245 ((CEdit *)pWnd)->SetWindowText(GetTestingParam(0));
1246 SendMessage(WM_COMMAND, MAKEWPARAM(ctrl_id, EN_KILLFOCUS), (LPARAM)pWnd->m_hWnd);
1247 }
1248 break;
1249
1250 case TEST_EDIT_ANIMATION_INFO:
1251 SplitString(GetTestingParam(0), ',', ¶m_list);
1252 if (param_list.GetCount() == 2)
1253 {
1254 ctrl_id = _tstoi(param_list.GetAt(0)) - ID_ANIMATION_ID;
1255 str = param_list.GetAt(1);
1256
1257 mAnimationParamEdits[ctrl_id].SetWindowText(str);
1258 }
1259 break;
1260
1261 case TEST_CHECK_DETACH_TARGET:
1262 mDetachTargetBox.SetCheck(lParam);
1263 break;
1264
1265 case TEST_CONFIGURE_EASING_FUNCTION:
1266 OnClickEasingFunction();
1267 break;
1268
1269 case TEST_TARGET_SHOW_CHILD_WIDGETS:
1270 mTargetShowChildWidgets.SetCheck(lParam);
1271 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_TARGET_SHOW_CHILD_WIDGETS, BN_CLICKED), (LPARAM)mTargetShowChildWidgets.m_hWnd);
1272 break;
1273
1274 case TEST_PARENT_SHOW_CHILD_WIDGETS:
1275 mParentShowChildWidgets.SetCheck(lParam);
1276 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_PARENT_SHOW_CHILD_WIDGETS, BN_CLICKED), (LPARAM)mParentShowChildWidgets.m_hWnd);
1277 break;
1278
1279 case TEST_SAVE_TRIGGER_ACTION_EDIT:
1280 OnOK();
1281 break;
1282
1283 case TEST_CANCEL_TRIGGER_ACTION_EDIT:
1284 OnCancel();
1285 break;
1286 }
1287
1288 return 0;
1289 }
1290