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

对话框与窗口

开发平台:

Visual C++

  1. // PaneProperties.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "CommandBarsDesigner.h"
  22. #include "PaneProperties.h"
  23. #include "ResourceManager.h"
  24. #include "DialogListEditor.h"
  25. #include "PropertyItemFlags.h"
  26. #include "MainFrm.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. LPCTSTR lpStyles[] = {_T("xtpButtonAutomatic"), _T("xtpButtonCaption"), _T("xtpButtonIcon"), _T("xtpButtonIconAndCaption"), _T("xtpButtonIconAndCaptionBelow"), _T("xtpButtonCaptionAndDescription") };
  33. LPCTSTR lpDropDownStyles[] = {_T("DropDown"), _T("DropDownList")};
  34. LPCTSTR lpVisibility[] = {_T("Always visible in menus"), _T("Visible if recently used")};
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CPaneProperties
  37. CPaneProperties::CPaneProperties()
  38. {
  39. m_pActiveObject = NULL;
  40. m_pActivePane = NULL;
  41. m_pActiveCommandBars = NULL;
  42. m_bApplyForGroup = FALSE;
  43. }
  44. CPaneProperties::~CPaneProperties()
  45. {
  46. }
  47. BEGIN_MESSAGE_MAP(CPaneProperties, CWnd)
  48. //{{AFX_MSG_MAP(CPaneProperties)
  49. ON_WM_CREATE()
  50. ON_WM_SIZE()
  51. ON_WM_SETFOCUS()
  52. ON_COMMAND(ID_PANEPROPERTIES_CATEGORIZED, OnPanePropertiesCategorized)
  53. ON_UPDATE_COMMAND_UI(ID_PANEPROPERTIES_CATEGORIZED, OnUpdatePanePropertiesCategorized)
  54. ON_COMMAND(ID_PANEPROPERTIES_ALPHABETIC, OnPanePropertiesAlphabetic)
  55. ON_UPDATE_COMMAND_UI(ID_PANEPROPERTIES_ALPHABETIC, OnUpdatePanePropertiesAlphabetic)
  56. ON_COMMAND(ID_PANEPROPERTIES_PAGES, OnPanePropertiesPages)
  57. ON_UPDATE_COMMAND_UI(ID_PANEPROPERTIES_PAGES, OnUpdatePanePropertiesPages)
  58. //}}AFX_MSG_MAP
  59. ON_MESSAGE(XTPWM_PROPERTYGRID_NOTIFY, OnGridNotify)
  60. END_MESSAGE_MAP()
  61. void CPaneProperties::Refresh(CPaneHolder* pActivePane /* = NULL */)
  62. {
  63. if (!m_hWnd)
  64. return;
  65. m_pActiveCommandBars = GetMainFrame()? GetMainFrame()->GetActiveCommandBars(): NULL;
  66. m_pActivePane = pActivePane;
  67. m_pActiveObject = NULL;
  68. m_wndPropertyGrid.BeginUpdate(m_stateExpanding);
  69. if (m_pActivePane)
  70. {
  71. RefreshPaneProperties();
  72. }
  73. else
  74. {
  75. RefreshControlProperties();
  76. }
  77. m_wndPropertyGrid.EndUpdate(m_stateExpanding);
  78. }
  79. void CPaneProperties::FillConstraintsID(CXTPPropertyGridItem* pItem)
  80. {
  81. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  82. CMapResources* pResources = pFrame->ResourceManager()->GetResources();
  83. POSITION pos = pResources->GetStartPosition();
  84. while (pos)
  85. {
  86. CResourceInfo* pInfo;
  87. CString strCaption;
  88. pResources->GetNextAssoc(pos, strCaption, (CObject*&)pInfo);
  89. pItem->GetConstraints()->AddConstraint(strCaption);
  90. }
  91. pItem->GetConstraints()->Sort();
  92. }
  93. void CPaneProperties::FillConstraintsActionsID(CXTPPropertyGridItem* pItem)
  94. {
  95. CXTPCommandBars* pCommandBars = GetMainFrame()->GetActiveCommandBars();
  96. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  97. CResourceManager* pResourceManager = pFrame->ResourceManager();
  98. for (int i = 0; i < pCommandBars->GetActions()->GetCount(); i++)
  99. {
  100. int nID = pCommandBars->GetActions()->GetAt(i)->GetID();
  101. CString strCaption = pResourceManager->GetStringID(nID);
  102. pItem->GetConstraints()->AddConstraint(strCaption);
  103. }
  104. pItem->GetConstraints()->Sort();
  105. }
  106. void CPaneProperties::FillActionProperties(CXTPPropertyGridItem* pCategory, CXTPControlAction* pAction)
  107. {
  108. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  109. pCategory->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_ACTION_CAPTION, pAction->GetCaption()));
  110. CString strIconID;
  111. if (pAction->GetIconId() != pAction->GetID())
  112. strIconID = pFrame->ResourceManager()->GetStringID(pAction->GetIconId());
  113. CXTPPropertyGridItem* pItemControlIconId = pCategory->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_ACTION_ICONID, strIconID));
  114. pItemControlIconId->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  115. FillConstraintsID(pItemControlIconId);
  116. pCategory->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_ACTION_DESCRIPTION, pAction->GetDescription()));
  117. pCategory->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_ACTION_TOOLTIP, pAction->GetTooltip()));
  118. CXTPPropertyGridItem* pItemControlCategory = pCategory->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_ACTION_CATEGORY, pAction->GetCategory()));
  119. pItemControlCategory->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  120. CXTPControls* pControls = pFrame->m_pControls;
  121. CXTPPropertyGridItemConstraints* pConstrants = pItemControlCategory->GetConstraints();
  122. for (int i = 0; i < pControls->GetCount(); i++)
  123. {
  124. CXTPControl* pControl = pControls->GetAt(i);
  125. if (pConstrants->FindConstraint(pControl->GetCategory()) == -1)
  126. {
  127. pConstrants->AddConstraint(pControl->GetCategory());
  128. }
  129. }
  130. CXTPCommandBarsOptions* pOptions = pAction->GetCommandBars()->GetCommandBarsOptions();
  131. BOOL bExists;
  132. BOOL bVisible = pOptions->m_mapHiddenCommands.Lookup(pAction->GetID(), bExists);
  133. CXTPPropertyGridItem* pItemControlVisibility = pCategory->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_VISIBILITY, lpVisibility[bVisible]));
  134. pConstrants = pItemControlVisibility->GetConstraints();
  135. pConstrants->AddConstraint(lpVisibility[0]);
  136. pConstrants->AddConstraint(lpVisibility[1]);
  137. pItemControlVisibility->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  138. }
  139. void CPaneProperties::RefreshControlProperties()
  140. {
  141. CXTPCommandBars* pCommandBars = GetMainFrame()->GetActiveCommandBars();
  142. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  143. if (!pCommandBars)
  144. return;
  145. CXTPControl* pControl = pCommandBars->GetDragControl();
  146. if (!pControl)
  147. return;
  148. if (!pControl->GetControls())
  149. return;
  150. BOOL bListControl = pControl->GetParent() == NULL;
  151. CXTPPropertyGridItem* pCategoryAppearance = m_wndPropertyGrid.AddCategory(ID_GRID_CATEGORY_APPEARANCE);
  152. CXTPPropertyGridItem* pCategoryBehavior = m_wndPropertyGrid.AddCategory(ID_GRID_CATEGORY_BEHAVIOR);
  153. BOOL bActionsEnable  = pCommandBars->IsActionsEnabled();
  154. BOOL bControlHasAction = pControl->GetAction() != NULL;
  155. if (bActionsEnable || bControlHasAction)
  156. {
  157. CString strID;
  158. if (bControlHasAction) strID =pFrame->ResourceManager()->GetStringID(pControl->GetID());
  159. CXTPPropertyGridItem* pItemControlAction = pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_ACTION, strID));
  160. pItemControlAction->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  161. FillConstraintsActionsID(pItemControlAction);
  162. if (bControlHasAction)
  163. {
  164. FillActionProperties(pItemControlAction, pControl->GetAction());
  165. }
  166. }
  167. if (!bControlHasAction)
  168. {
  169. pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_CAPTION, pControl->GetCaption()));
  170. CString strID = pFrame->ResourceManager()->GetStringID(pControl->GetID());
  171. CXTPPropertyGridItem* pItemControlId = pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_ID, strID));
  172. pItemControlId->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  173. FillConstraintsID(pItemControlId);
  174. CString strIconID;
  175. if (pControl->GetIconId() != pControl->GetID())
  176. strIconID = pFrame->ResourceManager()->GetStringID(pControl->GetIconId());
  177. CXTPPropertyGridItem* pItemControlIconId = pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_ICONID, strIconID));
  178. pItemControlIconId->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  179. FillConstraintsID(pItemControlIconId);
  180. }
  181. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_CONTROL_CLOSESUBMENUONCLICK, pControl->GetCloseSubMenuOnClick()));
  182. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemNumber(ID_GRID_ITEM_CONTROL_EXECUTEONPRESSINTERVAL, pControl->GetExecuteOnPressInterval()));
  183. if (!bControlHasAction)
  184. {
  185. pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_DESCRIPTION, pControl->GetDescription()));
  186. pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_TOOLTIP, pControl->GetTooltip()));
  187. }
  188. CXTPPropertyGridItem* pItemControlType = pCategoryAppearance->AddChildItem(new CXTPPropertyGridItemEnum(ID_GRID_ITEM_CONTROL_TYPE, pControl->GetType()));
  189. CXTPPropertyGridItemConstraints* pConstraints = pItemControlType->GetConstraints();
  190. for (int i = 0; i < _countof(lpTypes); i++) if (lpTypes[i])
  191. {
  192. pConstraints->AddConstraint(lpTypes[i], i);
  193. }
  194. if (pControl->GetType() != xtpControlCheckBox)
  195. {
  196. CXTPPropertyGridItem* pItemControlStyle = pCategoryAppearance->AddChildItem(new CXTPPropertyGridItemEnum(ID_GRID_ITEM_CONTROL_STYLE, pControl->GetStyle()));
  197. CXTPPropertyGridItemConstraints* pConstraints = pItemControlStyle->GetConstraints();
  198. for (int i = 0; i < _countof(lpStyles); i++)
  199. pConstraints->AddConstraint(lpStyles[i], i);
  200. }
  201. pCategoryBehavior->AddChildItem(new CPropertyGridItemControlFlags(ID_GRID_ITEM_CONTROL_FLAGS, pControl->GetFlags()));
  202. if (!bListControl)
  203. {
  204. CXTPPropertyGridItem* pItemControlBeginGroup = pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_CONTROL_BEGINGROUP, pControl->GetBeginGroup()));
  205. pItemControlBeginGroup->SetReadOnly(pControl->GetIndex() == 0);
  206. }
  207. if (bListControl && !bControlHasAction)
  208. {
  209. CXTPPropertyGridItem* pItemControlCategory = pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_CATEGORY, pControl->GetCategory()));
  210. pItemControlCategory->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  211. CXTPControls* pControls = pControl->GetControls();
  212. CXTPPropertyGridItemConstraints* pConstrants = pItemControlCategory->GetConstraints();
  213. for (int i = 0; i < pControls->GetCount(); i++)
  214. {
  215. CXTPControl* pControl = pControls->GetAt(i);
  216. if (pConstrants->FindConstraint(pControl->GetCategory()) == -1)
  217. {
  218. pConstrants->AddConstraint(pControl->GetCategory());
  219. }
  220. }
  221. }
  222. pCategoryAppearance->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_CONTROL_ITEMDEFAULT,
  223. pControl->IsItemDefault()));
  224. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemNumber(ID_GRID_ITEM_CONTROL_WIDTH,
  225. pControl->GetWidth()));
  226. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemNumber(ID_GRID_ITEM_CONTROL_HEIGHT,
  227. pControl->GetHeight()));
  228. if (pControl->GetType() == xtpControlComboBox)
  229. {
  230. CXTPPropertyGridItem* pCategoryData = m_wndPropertyGrid.AddCategory(ID_GRID_CATEGORY_BEHAVIOR);
  231. CXTPPropertyGridItem* pItemControlList = pCategoryData->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_LIST, _T("(Collection)")));
  232. pItemControlList->SetFlags(xtpGridItemHasExpandButton);
  233. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemNumber(ID_GRID_ITEM_CONTROL_DROPDOWNWIDTH,
  234. ((CXTPControlComboBox*)pControl)->GetDropDownWidth()));
  235. CString strSelected = ((CXTPControlComboBox*)pControl)->GetDropDownListStyle()? lpDropDownStyles[0]: lpDropDownStyles[1];
  236. CXTPPropertyGridItem* pItemControlDropDownStyle = pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_DROPDOWNSTYLE, strSelected));
  237. CXTPPropertyGridItemConstraints* pConstrants = pItemControlDropDownStyle->GetConstraints();
  238. pConstrants->AddConstraint(lpDropDownStyles[0]);
  239. pConstrants->AddConstraint(lpDropDownStyles[1]);
  240. pItemControlDropDownStyle->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  241. }
  242. if (pControl->GetType() == xtpControlEdit)
  243. {
  244. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_CONTROL_READONLY, ((CXTPControlEdit*)pControl)->GetReadOnly()));
  245. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_CONTROL_SHOWSPINBUTTONS, ((CXTPControlEdit*)pControl)->IsSpinButtonsVisible()));
  246. }
  247. if (!bListControl && pControl->GetParent()->GetType() == xtpBarTypePopup && pControl->GetID() > 0 && !bControlHasAction)
  248. {
  249. CXTPCommandBarsOptions* pOptions = pCommandBars->GetCommandBarsOptions();
  250. BOOL bExists;
  251. BOOL bVisible = pOptions->m_mapHiddenCommands.Lookup(pControl->GetID(), bExists);
  252. CXTPPropertyGridItem* pItemControlVisibility = pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_CONTROL_VISIBILITY, lpVisibility[bVisible]));
  253. CXTPPropertyGridItemConstraints* pConstrants = pItemControlVisibility->GetConstraints();
  254. pConstrants->AddConstraint(lpVisibility[0]);
  255. pConstrants->AddConstraint(lpVisibility[1]);
  256. pItemControlVisibility->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  257. }
  258. m_pActiveObject = pControl;
  259. if (!pCommandBars->IsActionsEnabled())
  260. {
  261. m_wndPropertyGrid.GetVerbs()->Add(_T("Enable Actions"), 0);
  262. }
  263. if (m_stateExpanding.IsEmpty())
  264. {
  265. pCategoryAppearance->Expand();
  266. pCategoryBehavior->Expand();
  267. }
  268. }
  269. void CPaneProperties::CreateActionList(CXTPCommandBars* pCommandBars, CXTPControls* pControls)
  270. {
  271. for (int i = 0; i < pControls->GetCount(); i++)
  272. {
  273. CXTPControl* pControl = pControls->GetAt(i);
  274. if (pControl->IsTemporary())
  275. continue;
  276. if (pControl->GetID() > 0 && pControl->GetID() < 0xFFFFFF && pControl->GetAction() == NULL)
  277. {
  278. CXTPControlAction* pAction = pCommandBars->CreateAction(pControl->GetID());
  279. if (!pControl->GetCaption().IsEmpty())
  280. pAction->SetCaption(pControl->GetCaption());
  281. if (!pControl->GetTooltip().IsEmpty())
  282. pAction->SetTooltip(pControl->GetTooltip());
  283. if (!pControl->GetDescription().IsEmpty())
  284. pAction->SetDescription(pControl->GetDescription());
  285. if (!pControl->GetCategory().IsEmpty())
  286. pAction->SetCategory(pControl->GetCategory());
  287. pControl->SetAction(pAction);
  288. }
  289. if (pControl->GetCommandBar())
  290. {
  291. CreateActionList(pCommandBars, pControl->GetCommandBar()->GetControls());
  292. }
  293. }
  294. }
  295. void CPaneProperties::EnableActions()
  296. {
  297. CXTPCommandBars* pCommandBars = GetMainFrame()->GetActiveCommandBars();
  298. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  299. if (!pCommandBars)
  300. return;
  301. pCommandBars->EnableActions();
  302. CXTPToolBar* pMenuBar = pCommandBars->GetMenuBar();
  303. int i;
  304. for (i = 0; i < pCommandBars->GetCount(); i++)
  305. {
  306. CXTPCommandBar* pCommandBar = pCommandBars->GetAt(i);
  307. if (pCommandBar != pMenuBar)
  308. CreateActionList(pCommandBars, pCommandBar->GetControls());
  309. }
  310. for (i = 0; i < pCommandBars->GetContextMenus()->GetCount(); i++)
  311. {
  312. CXTPCommandBar* pCommandBar = pCommandBars->GetContextMenus()->GetAt(i);
  313. CreateActionList(pCommandBars, pCommandBar->GetControls());
  314. }
  315. CreateActionList(pCommandBars, pFrame->m_pControls);
  316. if (pMenuBar)
  317. CreateActionList(pCommandBars, pCommandBars->GetMenuBar()->GetControls());
  318. Refresh();
  319. }
  320. void CPaneProperties::RefreshPaneProperties()
  321. {
  322. if (!m_pActivePane)
  323. return;
  324. m_pActiveObject = m_pActivePane->RefreshPropertyGrid(&m_wndPropertyGrid);
  325. }
  326. /////////////////////////////////////////////////////////////////////////////
  327. // CPaneProperties message handlers
  328. int CPaneProperties::OnCreate(LPCREATESTRUCT lpCreateStruct)
  329. {
  330. if (CWnd::OnCreate(lpCreateStruct) == -1)
  331. return -1;
  332. VERIFY(m_wndToolBar.CreateToolBar(WS_TABSTOP|WS_VISIBLE|WS_CHILD|CBRS_TOOLTIPS, this));
  333. VERIFY(m_wndToolBar.LoadToolBar(IDR_PANE_PROPERTIES));
  334. VERIFY(m_wndPropertyGrid.Create( CRect(0, 0, 0, 0), this, 0 ));
  335. m_wndPropertyGrid.SetTheme(xtpGridThemeWhidbey);
  336. return 0;
  337. }
  338. void CPaneProperties::OnSize(UINT nType, int cx, int cy)
  339. {
  340. CWnd::OnSize(nType, cx, cy);
  341. CSize sz(0);
  342. if (m_wndToolBar.GetSafeHwnd())
  343. {
  344. sz = m_wndToolBar.CalcDockingLayout(cx, /*LM_HIDEWRAP|*/ LM_HORZDOCK|LM_HORZ | LM_COMMIT);
  345. m_wndToolBar.MoveWindow(0, 0, cx, sz.cy);
  346. m_wndToolBar.Invalidate(FALSE);
  347. }
  348. if (m_wndPropertyGrid.GetSafeHwnd())
  349. {
  350. m_wndPropertyGrid.MoveWindow(0, sz.cy, cx, cy - sz.cy);
  351. }
  352. }
  353. void CPaneProperties::OnSetFocus(CWnd*)
  354. {
  355. m_wndPropertyGrid.SetFocus();
  356. }
  357. void CPaneProperties::OnPanePropertiesCategorized()
  358. {
  359. m_wndPropertyGrid.SetPropertySort(xtpGridSortCategorized);
  360. }
  361. void CPaneProperties::OnUpdatePanePropertiesCategorized(CCmdUI* pCmdUI)
  362. {
  363. pCmdUI->SetCheck(m_wndPropertyGrid.GetPropertySort() == xtpGridSortCategorized);
  364. }
  365. void CPaneProperties::OnPanePropertiesAlphabetic()
  366. {
  367. m_wndPropertyGrid.SetPropertySort(xtpGridSortAlphabetical);
  368. }
  369. void CPaneProperties::OnUpdatePanePropertiesAlphabetic(CCmdUI* pCmdUI)
  370. {
  371. pCmdUI->SetCheck(m_wndPropertyGrid.GetPropertySort() == xtpGridSortAlphabetical);
  372. }
  373. void CPaneProperties::RefreshToolbarsPane()
  374. {
  375. GetMainFrame()->m_paneToolbars.Refresh();
  376. }
  377. void CPaneProperties::RefreshControlsPane()
  378. {
  379. GetMainFrame()->m_paneControls.Refresh(TRUE);
  380. }
  381. void CPaneProperties::OnPropertyChanged(CXTPControl* pControl)
  382. {
  383. CXTPCommandBar* pCommandBar = pControl->GetParent();
  384. if (pCommandBar)
  385. {
  386. pCommandBar->SetSelected(-1);
  387. pCommandBar->SetPopuped(-1);
  388. if (pCommandBar->GetSafeHwnd())
  389. {
  390. pCommandBar->OnIdleUpdateCmdUI(NULL, NULL);
  391. }
  392. }
  393. }
  394. void CPaneProperties::OnControlValueChanged(CXTPPropertyGridItem* pItem )
  395. {
  396. ASSERT(pItem);
  397. ASSERT(m_pActiveObject);
  398. CXTPControl* pControl = DYNAMIC_DOWNCAST(CXTPControl, m_pActiveObject);
  399. if (!pControl)
  400. return;
  401. FINDCONTROLPARAM param;
  402. param.bIncludeSelf = FALSE;
  403. param.pItem = pItem;
  404. param.bRefresh = TRUE;
  405. OnControlValueChangedInstance(pControl, &param);
  406. }
  407. void CPaneProperties::OnControlValueChangedInstance(CXTPControl* pControl, FINDCONTROLPARAM* pParam )
  408. {
  409. CXTPPropertyGridItem* pItem = pParam->pItem;
  410. BOOL bRefresh = pParam->bRefresh;
  411. switch (pItem->GetID())
  412. {
  413. case ID_GRID_ITEM_CONTROL_CAPTION:
  414. ASSERT(pControl);
  415. pControl->SetCaption(pItem->GetValue());
  416. OnPropertyChanged(pControl);
  417. if (pControl->GetParent() == NULL) RefreshControlsPane();
  418. return;
  419. case ID_GRID_ITEM_ACTION_CAPTION:
  420. ASSERT(pControl && pControl->GetAction());
  421. pControl->GetAction()->SetCaption(pItem->GetValue());
  422. OnPropertyChanged(pControl);
  423. if (pControl->GetParent() == NULL) RefreshControlsPane();
  424. return;
  425. case ID_GRID_ITEM_CONTROL_CLOSESUBMENUONCLICK:
  426. ASSERT(pControl);
  427. pControl->SetCloseSubMenuOnClick(GetBoolValue(pItem));
  428. OnPropertyChanged(pControl);
  429. return;
  430. case ID_GRID_ITEM_CONTROL_EXECUTEONPRESSINTERVAL:
  431. ASSERT(pControl);
  432. pControl->SetExecuteOnPressInterval(GetNumberValue(pItem));
  433. OnPropertyChanged(pControl);
  434. return;
  435. case ID_GRID_ITEM_CONTROL_DESCRIPTION:
  436. ASSERT(pControl);
  437. pControl->SetDescription(pItem->GetValue());
  438. OnPropertyChanged(pControl);
  439. return;
  440. case ID_GRID_ITEM_ACTION_DESCRIPTION:
  441. ASSERT(pControl && pControl->GetAction());
  442. pControl->GetAction()->SetDescription(pItem->GetValue());
  443. OnPropertyChanged(pControl);
  444. return;
  445. case ID_GRID_ITEM_CONTROL_TOOLTIP:
  446. ASSERT(pControl);
  447. pControl->SetTooltip(pItem->GetValue());
  448. OnPropertyChanged(pControl);
  449. return;
  450. case ID_GRID_ITEM_ACTION_TOOLTIP:
  451. ASSERT(pControl && pControl->GetAction());
  452. pControl->GetAction()->SetTooltip(pItem->GetValue());
  453. OnPropertyChanged(pControl);
  454. return;
  455. case ID_GRID_ITEM_CONTROL_FLAGS:
  456. ASSERT(pControl);
  457. pControl->SetFlags(GetFlagsValue(pItem));
  458. OnPropertyChanged(pControl);
  459. pControl->DelayLayoutParent();
  460. return;
  461. case ID_GRID_ITEM_CONTROL_TYPE:
  462. {
  463. CXTPControls* pControls = pControl->GetControls();
  464. CXTPCommandBars* pCommandBars = pControls->GetCommandBars();
  465. XTPControlType type = (XTPControlType)GetEnumValue(pItem);
  466. int nIndex = pControl->GetIndex();
  467. if (bRefresh) pCommandBars->SetDragControl(NULL);
  468. pControl = pControls->SetControlType(nIndex, type);
  469. pControl->DelayLayoutParent();
  470. OnPropertyChanged(pControl);
  471. if (bRefresh) pCommandBars->SetDragControl(pControl);
  472. if (pControl->GetParent() == NULL) RefreshControlsPane();
  473. }
  474. return;
  475. case ID_GRID_ITEM_CONTROL_STYLE:
  476. pControl->SetStyle((XTPButtonStyle)GetEnumValue(pItem));
  477. OnPropertyChanged(pControl);
  478. return;
  479. case ID_GRID_ITEM_CONTROL_BEGINGROUP:
  480. ASSERT(pControl);
  481. pControl->SetBeginGroup(GetBoolValue(pItem));
  482. OnPropertyChanged(pControl);
  483. return;
  484. case ID_GRID_ITEM_CONTROL_CATEGORY:
  485. ASSERT(pControl);
  486. pControl->SetCategory(pItem->GetValue());
  487. RefreshControlsPane();
  488. return;
  489. case ID_GRID_ITEM_ACTION_CATEGORY:
  490. ASSERT(pControl && pControl->GetAction());
  491. pControl->GetAction()->SetCategory(pItem->GetValue());
  492. RefreshControlsPane();
  493. return;
  494. case ID_GRID_ITEM_CONTROL_ACTION:
  495. {
  496. ASSERT(pControl);
  497. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  498. ASSERT(pFrame);
  499. UINT nID = pFrame->ResourceManager()->GetStringID(pItem->GetValue());
  500. if (nID > 0)
  501. {
  502. CXTPControlAction* pAction = pFrame->GetCommandBars()->CreateAction(nID);
  503. pAction->SetKey(pItem->GetValue());
  504. pControl->SetAction( pAction);
  505. }
  506. else
  507. pControl->SetAction(NULL);
  508. pControl->DelayLayoutParent();
  509. OnPropertyChanged(pControl);
  510. if (pControl->GetParent() == NULL) RefreshControlsPane();
  511. if (bRefresh) Refresh();
  512. }
  513. return;
  514. case ID_GRID_ITEM_CONTROL_ID:
  515. {
  516. ASSERT(pControl);
  517. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  518. ASSERT(pFrame);
  519. UINT nID = pFrame->ResourceManager()->GetStringID(pItem->GetValue());
  520. pControl->SetID(nID);
  521. pControl->DelayLayoutParent();
  522. OnPropertyChanged(pControl);
  523. if (pControl->GetParent() == NULL) RefreshControlsPane();
  524. if (bRefresh) Refresh();
  525. }
  526. return;
  527. case ID_GRID_ITEM_CONTROL_ICONID:
  528. case ID_GRID_ITEM_ACTION_ICONID:
  529. {
  530. ASSERT(pControl);
  531. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  532. ASSERT(pFrame);
  533. int nID = pFrame->ResourceManager()->GetStringID(pItem->GetValue());
  534. if (nID == 0) nID = -1;
  535. if (pItem->GetID() == ID_GRID_ITEM_CONTROL_ICONID)
  536. pControl->SetIconId(nID);
  537. else
  538. pControl->GetAction()->SetIconId(nID);
  539. pControl->DelayLayoutParent();
  540. OnPropertyChanged(pControl);
  541. if (pControl->GetParent() == NULL) RefreshControlsPane();
  542. if (bRefresh) Refresh();
  543. }
  544. return;
  545. case ID_GRID_ITEM_CONTROL_WIDTH:
  546. pControl->SetWidth(GetNumberValue(pItem));
  547. pControl->DelayLayoutParent();
  548. return;
  549. case ID_GRID_ITEM_CONTROL_HEIGHT:
  550. pControl->SetHeight(GetNumberValue(pItem));
  551. pControl->DelayLayoutParent();
  552. return;
  553. case ID_GRID_ITEM_CONTROL_ITEMDEFAULT:
  554. pControl->SetItemDefault(GetBoolValue(pItem));
  555. pControl->DelayLayoutParent();
  556. return;
  557. case ID_GRID_ITEM_CONTROL_DROPDOWNWIDTH:
  558. if (pControl->GetType() == xtpControlComboBox)
  559. ((CXTPControlComboBox*)pControl)->SetDropDownWidth(GetNumberValue(pItem));
  560. pControl->DelayLayoutParent();
  561. return;
  562. case ID_GRID_ITEM_CONTROL_DROPDOWNSTYLE:
  563. if (pControl->GetType() == xtpControlComboBox)
  564. ((CXTPControlComboBox*)pControl)->SetDropDownListStyle(pItem->GetValue() == lpDropDownStyles[0]);
  565. return;
  566. case ID_GRID_ITEM_CONTROL_READONLY:
  567. if (pControl->GetType() == xtpControlEdit)
  568. ((CXTPControlEdit*)pControl)->SetReadOnly(GetBoolValue(pItem));
  569. return;
  570. case ID_GRID_ITEM_CONTROL_SHOWSPINBUTTONS:
  571. if (pControl->GetType() == xtpControlEdit)
  572. ((CXTPControlEdit*)pControl)->ShowSpinButtons(GetBoolValue(pItem));
  573. pControl->DelayLayoutParent();
  574. return;
  575. case ID_GRID_ITEM_CONTROL_VISIBILITY:
  576. {
  577. CXTPCommandBarsOptions* pOptions = pControl->GetControls()->GetCommandBars()->GetCommandBarsOptions();
  578. if (pItem->GetValue() == lpVisibility[0])
  579. {
  580. pOptions->m_mapHiddenCommands.RemoveKey(pControl->GetID());
  581. } else
  582. {
  583. pOptions->m_mapHiddenCommands.SetAt(pControl->GetID(), TRUE);
  584. }
  585. if (bRefresh) Refresh();
  586. }
  587. return;
  588. }
  589. }
  590. LRESULT CPaneProperties::OnGridNotify(WPARAM wParam, LPARAM lParam)
  591. {
  592. if (wParam == XTP_PGN_INPLACEBUTTONDOWN)
  593. {
  594. CXTPPropertyGridInplaceButton* pButton = (CXTPPropertyGridInplaceButton*)lParam;
  595. CXTPPropertyGridItem* pItem = pButton->GetItem();
  596. switch (pItem->GetID())
  597. {
  598. case ID_GRID_ITEM_CONTROL_LIST:
  599. if (m_pActiveObject && m_pActiveObject->IsKindOf(RUNTIME_CLASS(CXTPControl)))
  600. {
  601. if (((CXTPControl*)m_pActiveObject)->GetType() == xtpControlComboBox)
  602. {
  603. CXTPControlComboBox* pCombo = (CXTPControlComboBox*)((CXTPControl*)m_pActiveObject);
  604. CDialogListEditor ld(pCombo);
  605. ld.DoModal();
  606. return TRUE;
  607. }
  608. }
  609. }
  610. }
  611. if (wParam == XTP_PGN_VERB_CLICK)
  612. {
  613. CXTPPropertyGridVerb* pVerb = (CXTPPropertyGridVerb*)lParam;
  614. if (pVerb->GetID() == 0)
  615. {
  616. if (AfxMessageBox(_T("Are you sure you want to enable Actions? It will modify all controls that were created"), MB_YESNO) != IDYES)
  617. return TRUE;
  618. EnableActions();
  619. }
  620. return TRUE;
  621. }
  622. if (wParam == XTP_PGN_ITEMVALUE_CHANGED)
  623. {
  624. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lParam;
  625. if (m_pActiveObject && pItem)
  626. {
  627. if (m_pActivePane)
  628. {
  629. return m_pActivePane->OnPropertyGridValueChanged(m_pActiveObject, pItem);
  630. }
  631. else if (m_pActiveObject->IsKindOf(RUNTIME_CLASS(CXTPControl)))
  632. {
  633. OnControlValueChanged(pItem);
  634. return TRUE;
  635. }
  636. }
  637. }
  638. return 0;
  639. }
  640. void CPaneProperties::OnPanePropertiesPages()
  641. {
  642. if (m_pActiveCommandBars)
  643. {
  644. GetMainFrame()->GetActiveEmbeddedFrame()->ShowPropertyPage();
  645. }
  646. }
  647. void CPaneProperties::OnUpdatePanePropertiesPages(CCmdUI* pCmdUI)
  648. {
  649. pCmdUI->Enable(m_pActiveCommandBars != NULL);
  650. }