DialogActions.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:6k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // DialogActions.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ActionsSample.h"
  5. #include "DialogActions.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDialogActions dialog
  13. CDialogActions::CDialogActions(CWnd* pParent /*=NULL*/)
  14. : CDialog(CDialogActions::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CDialogActions)
  17. m_bChecked = FALSE;
  18. m_bEnabled = FALSE;
  19. m_bVisible = FALSE;
  20. m_strCaption = _T("");
  21. m_strDescription = _T("");
  22. m_strTooltip = _T("");
  23. //}}AFX_DATA_INIT
  24. m_pActions = 0;
  25. }
  26. void CDialogActions::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CDialogActions)
  30. DDX_Control(pDX, IDC_COMBO_ACTIONS, m_lstActions);
  31. DDX_Check(pDX, IDC_CHECK_CHECKED, m_bChecked);
  32. DDX_Check(pDX, IDC_CHECK_ENABLED, m_bEnabled);
  33. DDX_Check(pDX, IDC_CHECK_VISIBLE, m_bVisible);
  34. DDX_Text(pDX, IDC_EDIT_CAPTION, m_strCaption);
  35. DDX_Text(pDX, IDC_EDIT_DESCRIPTION, m_strDescription);
  36. DDX_Text(pDX, IDC_EDIT_TOOLTIP, m_strTooltip);
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(CDialogActions, CDialog)
  40. //{{AFX_MSG_MAP(CDialogActions)
  41. ON_CBN_SELCHANGE(IDC_COMBO_ACTIONS, OnComboActionsSelChanged)
  42. ON_BN_CLICKED(IDC_CHECK_VISIBLE, OnCheckVisible)
  43. ON_BN_CLICKED(IDC_CHECK_ENABLED, OnCheckEnabled)
  44. ON_BN_CLICKED(IDC_CHECK_CHECKED, OnCheckChecked)
  45. ON_EN_CHANGE(IDC_EDIT_CAPTION, OnChangeEditCaption)
  46. ON_EN_CHANGE(IDC_EDIT_TOOLTIP, OnChangeEditTooltip)
  47. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnChangeEditDescription)
  48. ON_BN_CLICKED(IDC_BUTTON_LOAD, OnButtonLoad)
  49. ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CDialogActions message handlers
  54. void CDialogActions::OnOK() 
  55. {
  56. }
  57. void CDialogActions::OnCancel() 
  58. {
  59. }
  60. BOOL CDialogActions::OnInitDialog() 
  61. {
  62. CDialog::OnInitDialog();
  63. CXTPFrameWnd* pFrame = (CXTPFrameWnd*)GetParentFrame();
  64. CXTPCommandBars* pCommandBars = pFrame->GetCommandBars();
  65. m_pActions = pCommandBars->GetActions();
  66. FillActionsCombos();
  67. OnComboActionsSelChanged();
  68. return TRUE;  // return TRUE unless you set the focus to a control
  69.               // EXCEPTION: OCX Property Pages should return FALSE
  70. }
  71. void CDialogActions::OnComboActionsSelChanged() 
  72. {
  73. int nSel = m_lstActions.GetCurSel();
  74. GetDlgItem(IDC_CHECK_VISIBLE)->EnableWindow(nSel != CB_ERR);
  75. GetDlgItem(IDC_CHECK_ENABLED)->EnableWindow(nSel != CB_ERR);
  76. GetDlgItem(IDC_CHECK_CHECKED)->EnableWindow(nSel != CB_ERR);
  77. GetDlgItem(IDC_EDIT_CAPTION)->EnableWindow(nSel != CB_ERR);
  78. GetDlgItem(IDC_EDIT_TOOLTIP)->EnableWindow(nSel != CB_ERR);
  79. GetDlgItem(IDC_EDIT_DESCRIPTION)->EnableWindow(nSel != CB_ERR);
  80. if (nSel == CB_ERR)
  81. return;
  82. CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData(nSel);
  83. m_bVisible = pAction->IsVisible();
  84. m_bEnabled = pAction->GetEnabled();
  85. m_bChecked = pAction->GetChecked();
  86. m_strCaption = pAction->GetCaption();
  87. m_strTooltip = pAction->GetTooltip();
  88. m_strDescription = pAction->GetDescription();
  89. UpdateData(FALSE);
  90. }
  91. void CDialogActions::FillActionsCombos()
  92. {
  93. for (int i = 0; i < m_pActions->GetCount(); i++)
  94. {
  95. CXTPControlAction* pAction = m_pActions->GetAt(i);
  96. CString strCaption;
  97. strCaption.Format(_T("%i - %s"), pAction->GetID(), (LPCTSTR)pAction->GetCaption());
  98. int nIndex = m_lstActions.AddString(strCaption);
  99. m_lstActions.SetItemData(nIndex, (DWORD_PTR)pAction);
  100. ASSERT(m_pActions->FindAction(pAction->GetID()));
  101. }
  102. }
  103. void CDialogActions::OnCheckVisible() 
  104. {
  105. UpdateData();
  106. CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData(m_lstActions.GetCurSel());
  107. pAction->SetVisible(m_bVisible);
  108. }
  109. void CDialogActions::OnCheckEnabled() 
  110. {
  111. UpdateData();
  112. CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData(m_lstActions.GetCurSel());
  113. pAction->SetEnabled(m_bEnabled);
  114. }
  115. void CDialogActions::OnCheckChecked() 
  116. {
  117. UpdateData();
  118. CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData(m_lstActions.GetCurSel());
  119. pAction->SetChecked(m_bChecked);
  120. }
  121. void CDialogActions::OnChangeEditCaption() 
  122. {
  123. UpdateData();
  124. CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData(m_lstActions.GetCurSel());
  125. pAction->SetCaption(m_strCaption);
  126. }
  127. void CDialogActions::OnChangeEditTooltip() 
  128. {
  129. UpdateData();
  130. CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData(m_lstActions.GetCurSel());
  131. pAction->SetTooltip(m_strTooltip);
  132. }
  133. void CDialogActions::OnChangeEditDescription() 
  134. {
  135. UpdateData();
  136. CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData(m_lstActions.GetCurSel());
  137. pAction->SetDescription(m_strDescription);
  138. }
  139. void CDialogActions::OnButtonLoad() 
  140. {
  141. CString strFilter = _T("XML Document(*.xml)|*.xml|All files (*.*)|*.*||");
  142. CFileDialog fd(TRUE, _T("xml"), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
  143. if (fd.DoModal() == IDOK)
  144. {
  145. CXTPPropExchangeXMLNode px(TRUE, 0, _T("Settings"));
  146. if (!px.LoadFromFile(fd.GetFileName()))
  147. return;
  148. CXTPFrameWnd* pFrame = (CXTPFrameWnd*)GetParentFrame();
  149. CXTPCommandBars* pCommandBars = pFrame->GetCommandBars();
  150. XTP_COMMANDBARS_PROPEXCHANGE_PARAM param;
  151. param.bSaveOriginalControls = FALSE;
  152. param.bSerializeControls = FALSE;
  153. param.bSerializeOptions = FALSE;
  154. param.bSerializeLayout = FALSE;
  155. param.bSerializeActions = TRUE;
  156. pCommandBars->DoPropExchange(&px, &param);
  157. OnComboActionsSelChanged();
  158. pCommandBars->RedrawCommandBars();
  159. }
  160. }
  161. void CDialogActions::OnButtonSave() 
  162. {
  163. CString strFilter = _T("XML Document(*.xml)|*.xml|All files (*.*)|*.*||");
  164. CFileDialog fd(FALSE, _T("xml"), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
  165. if (fd.DoModal() == IDOK)
  166. {
  167. CXTPPropExchangeXMLNode px(FALSE, 0, _T("Settings"));
  168. CXTPFrameWnd* pFrame = (CXTPFrameWnd*)GetParentFrame();
  169. CXTPCommandBars* pCommandBars = pFrame->GetCommandBars();
  170. XTP_COMMANDBARS_PROPEXCHANGE_PARAM param;
  171. param.bSaveOriginalControls = FALSE;
  172. param.bSerializeControls = FALSE;
  173. param.bSerializeOptions = FALSE;
  174. param.bSerializeLayout = FALSE;
  175. param.bSerializeActions = TRUE;
  176. pCommandBars->DoPropExchange(&px, &param);
  177. px.SaveToFile(fd.GetFileName());
  178. }
  179. }