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

对话框与窗口

开发平台:

Visual C++

  1. // PaneToolbars.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 "PaneToolbars.h"
  23. #include "DialogNewToolbar.h"
  24. #include "PropertyItemFlags.h"
  25. #include "MainFrm.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. class CFloatingPopupBar : public CXTPToolBar
  32. {
  33. DECLARE_XTP_COMMANDBAR(CFloatingPopupBar)
  34. public:
  35. CFloatingPopupBar()
  36. {
  37. m_bBuiltIn = FALSE;
  38. m_barType = xtpBarTypePopup;
  39. SetWidth(0);
  40. }
  41. };
  42. IMPLEMENT_XTP_COMMANDBAR(CFloatingPopupBar, CXTPToolBar);
  43. LRESULT CPaneToolbars::CToolbarsTree::WindowProc(UINT message,WPARAM wParam,LPARAM lParam)
  44. {
  45. switch (message)
  46. {
  47. case WM_NCPAINT:
  48. {
  49. CTreeCtrl::WindowProc(message, wParam, lParam);
  50. CRect rc;
  51. GetWindowRect(&rc);
  52. CWindowDC dc(this);
  53. rc.OffsetRect(-rc.TopLeft());
  54. COLORREF clr = GetStaticFrameColor();
  55. dc.Draw3dRect(rc, clr, clr);
  56. return TRUE;
  57. }
  58. }
  59. return CTreeCtrl::WindowProc(message, wParam, lParam);
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CPaneToolbars
  63. CPaneToolbars::CPaneToolbars()
  64. {
  65. m_bLockSelected = FALSE;
  66. }
  67. CPaneToolbars::~CPaneToolbars()
  68. {
  69. }
  70. BEGIN_MESSAGE_MAP(CPaneToolbars, CWnd)
  71. //{{AFX_MSG_MAP(CPaneToolbars)
  72. ON_WM_CREATE()
  73. ON_WM_SIZE()
  74. ON_WM_SETFOCUS()
  75. ON_COMMAND(ID_PANETOOLBARS_ADD, OnPanetoolbarsAdd)
  76. ON_COMMAND(ID_PANETOOLBARS_ADDMENU, OnPanetoolbarsAddMenu)
  77. ON_UPDATE_COMMAND_UI(ID_PANETOOLBARS_ADD, OnUpdatePanetoolbarsAdd)
  78. ON_UPDATE_COMMAND_UI(ID_PANETOOLBARS_DELETE, OnUpdatePanetoolbarsDelete)
  79. ON_COMMAND(ID_PANETOOLBARS_DELETE, OnPanetoolbarsDelete)
  80. //}}AFX_MSG_MAP
  81. ON_NOTIFY(TVN_SELCHANGED, AFX_IDW_PANE_FIRST, OnTreeSelChanged)
  82. ON_NOTIFY(NM_SETFOCUS, AFX_IDW_PANE_FIRST, OnTreeSetFocus)
  83. END_MESSAGE_MAP()
  84. int CPaneToolbars::BuildToolbarsTree(HTREEITEM hItem, CXTPCommandBar* pCommandBar, BOOL bCheck)
  85. {
  86. BOOL bToolbar = pCommandBar->GetType() != xtpBarTypePopup;
  87. int nImageIndex = bToolbar? 0: 1;
  88. HTREEITEM hItemChild = 0;
  89. int nTotalCount = 1;
  90. CString strTitle = pCommandBar->GetTitle();
  91. if (strTitle.IsEmpty()) strTitle = _T("[Untitled]");
  92. if (bCheck)
  93. {
  94. hItemChild = (HTREEITEM)pCommandBar->GetCommandBarData();
  95. TVITEM item;
  96. item.hItem = hItemChild;
  97. item.mask = TVIF_PARAM;
  98. if (hItemChild != 0 && m_wndTreeCtrl.SendMessage(TVM_GETITEM, 0, (LPARAM)&item) &&
  99. (DWORD_PTR)item.lParam == (DWORD_PTR)pCommandBar)
  100. {
  101. if (m_wndTreeCtrl.GetItemText(hItemChild) != strTitle)
  102. {
  103. m_wndTreeCtrl.SetItemText(hItemChild, strTitle);
  104. }
  105. } else
  106. return 0;
  107. } else
  108. {
  109. hItemChild = m_wndTreeCtrl.InsertItem(strTitle, nImageIndex, nImageIndex, hItem);
  110. m_wndTreeCtrl.SetItemData(hItemChild, (DWORD_PTR)pCommandBar);
  111. pCommandBar->SetCommandBarData((DWORD_PTR)hItemChild);
  112. }
  113. for (int i = 0; i < pCommandBar->GetControlCount(); i++)
  114. {
  115. CXTPControl* pControl = pCommandBar->GetControl(i);
  116. CXTPCommandBar* pPopupBar = pControl->GetCommandBar();
  117. if (pControl == NULL || pControl->GetID() == XTP_ID_TOOLBAR_EXPAND || pPopupBar == NULL)
  118. continue;
  119. int nCount = BuildToolbarsTree(hItemChild, pPopupBar, bCheck);
  120. if (bCheck && nCount == 0)
  121. return 0;
  122. nTotalCount += nCount;
  123. }
  124. if (!bCheck) m_wndTreeCtrl.Expand (hItemChild, TVE_EXPAND);
  125. return nTotalCount;
  126. }
  127. void CPaneToolbars::Refresh()
  128. {
  129. if (!AfxGetMainWnd())
  130. return;
  131. if (!m_wndTreeCtrl.GetSafeHwnd())
  132. return;
  133. CXTPCommandBars* pCommandBars = ((CMainFrame*)AfxGetMainWnd())->GetActiveCommandBars();
  134. m_pActiveCommandBars = pCommandBars;
  135. if (!pCommandBars || pCommandBars->GetCount() == 0)
  136. {
  137. m_bLockSelected = TRUE;
  138. m_wndTreeCtrl.DeleteAllItems();
  139. m_bLockSelected = FALSE;
  140. return;
  141. }
  142. int nTotalCount = 0, i;
  143. for (i = 0; i < pCommandBars->GetCount(); i++)
  144. {
  145. CXTPToolBar* pCommandBar = pCommandBars->GetAt(i);
  146. if (!pCommandBar->IsBuiltIn())
  147. continue;
  148. int nCount = BuildToolbarsTree(TVI_ROOT, pCommandBar, TRUE);
  149. if (nCount == 0)
  150. {
  151. nTotalCount = 0;
  152. break;
  153. }
  154. nTotalCount += nCount;
  155. }
  156. for (i = 0; i < pCommandBars->GetContextMenus()->GetCount(); i++)
  157. {
  158. CXTPCommandBar* pCommandBar = pCommandBars->GetContextMenus()->GetAt(i);
  159. int nCount = BuildToolbarsTree(TVI_ROOT, pCommandBar, TRUE);
  160. if (nCount == 0)
  161. {
  162. nTotalCount = 0;
  163. break;
  164. }
  165. nTotalCount += nCount;
  166. }
  167. if (nTotalCount != (int)m_wndTreeCtrl.GetCount())
  168. {
  169. nTotalCount = 0;
  170. }
  171. if (nTotalCount == 0)
  172. {
  173. m_wndTreeCtrl.LockWindowUpdate();
  174. m_bLockSelected = TRUE;
  175. m_wndTreeCtrl.DeleteAllItems();
  176. for (i = 0; i < pCommandBars->GetCount(); i++)
  177. {
  178. CXTPToolBar* pCommandBar = pCommandBars->GetAt(i);
  179. if (!pCommandBar->IsBuiltIn())
  180. continue;
  181. BuildToolbarsTree(TVI_ROOT, pCommandBar, FALSE);
  182. }
  183. for (i = 0; i < pCommandBars->GetContextMenus()->GetCount(); i++)
  184. {
  185. CXTPCommandBar* pCommandBar = pCommandBars->GetContextMenus()->GetAt(i);
  186.  BuildToolbarsTree(TVI_ROOT, pCommandBar, FALSE);
  187. }
  188. m_wndTreeCtrl.UnlockWindowUpdate();
  189. ((CMainFrame*)AfxGetMainWnd())->m_pActivePane = NULL;
  190. ((CMainFrame*)AfxGetMainWnd())->RefreshPanes();
  191. m_bLockSelected = FALSE;
  192. }
  193. }
  194. /////////////////////////////////////////////////////////////////////////////
  195. // CPaneToolbars message handlers
  196. int CPaneToolbars::OnCreate(LPCREATESTRUCT lpCreateStruct)
  197. {
  198. if (CWnd::OnCreate(lpCreateStruct) == -1)
  199. return -1;
  200. XTPImageManager()->SetMaskColor(RGB(0, 0xFF, 0));
  201. VERIFY(m_wndToolBar.CreateToolBar(WS_VISIBLE|WS_CHILD|CBRS_TOOLTIPS, this));
  202. VERIFY(m_wndToolBar.LoadToolBar(IDR_PANE_TOOLBARS));
  203. m_ilTreeIcons.Create(16, 16, ILC_MASK|ILC_COLOR24, 0, 1);
  204. CBitmap bmp;
  205. bmp.LoadBitmap(IDB_PANE_TOOLBARS_ICONS);
  206. m_ilTreeIcons.Add(&bmp, RGB(0, 255, 0));
  207. if (!m_wndTreeCtrl.Create(WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_VISIBLE|TVS_HASLINES|
  208. TVS_LINESATROOT|TVS_HASBUTTONS|TVS_SHOWSELALWAYS, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST))
  209. {
  210. TRACE0("Failed to create view windown");
  211. return -1;
  212. }
  213. m_wndTreeCtrl.ModifyStyleEx(0, WS_EX_STATICEDGE);
  214. m_wndTreeCtrl.SetImageList(&m_ilTreeIcons, TVSIL_NORMAL);
  215. Refresh();
  216. return 0;
  217. }
  218. void CPaneToolbars::OnSize(UINT nType, int cx, int cy)
  219. {
  220. CWnd::OnSize(nType, cx, cy);
  221. CSize sz(0);
  222. if (m_wndToolBar.GetSafeHwnd())
  223. {
  224. sz = m_wndToolBar.CalcDockingLayout(cx, /*LM_HIDEWRAP|*/ LM_HORZDOCK|LM_HORZ | LM_COMMIT);
  225. m_wndToolBar.MoveWindow(0, 0, cx, sz.cy);
  226. m_wndToolBar.Invalidate(FALSE);
  227. }
  228. if (m_wndTreeCtrl.GetSafeHwnd())
  229. {
  230. m_wndTreeCtrl.MoveWindow(0, sz.cy, cx, cy - sz.cy);
  231. }
  232. }
  233. void CPaneToolbars::OnSetFocus(CWnd*)
  234. {
  235. m_wndTreeCtrl.SetFocus();
  236. }
  237. void CPaneToolbars::OnPanetoolbarsAdd()
  238. {
  239. CDialogNewToolbar dt(TRUE);
  240. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  241. if (!pFrame)
  242. return;
  243. if (dt.DoModal() == IDOK)
  244. {
  245. CXTPToolBar* pCommandBar = (CXTPToolBar*)pFrame->GetCommandBars()->Add(dt.m_strCaption, xtpBarTop);
  246. pCommandBar->SetBarID(pFrame->ResourceManager()->GetStringID(dt.m_strId));
  247. Refresh();
  248. HTREEITEM hItem = (HTREEITEM)pCommandBar->GetCommandBarData();
  249. m_wndTreeCtrl.SelectItem(hItem);
  250. }
  251. }
  252. void CPaneToolbars::ShowContextMenu(HTREEITEM hItem)
  253. {
  254. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  255. if (!pFrame)
  256. return;
  257. CXTPCommandBars* pCommandBars = pFrame->GetCommandBars();
  258. CXTPCommandBar* pSelectedBar = (CXTPCommandBar*)m_wndTreeCtrl.GetItemData(hItem);
  259. pFrame->CommitContextMenu();
  260. if (!pSelectedBar->IsPopupBar() || !((CXTPPopupBar*)pSelectedBar)->IsContextMenu())
  261. return;
  262. CXTPPopupBar* pPopupBar = (CXTPPopupBar*)pSelectedBar;
  263. CXTPToolBar* pContextMenu = (CXTPToolBar*)pCommandBars->Add(pPopupBar->GetTitle(), xtpBarTop, RUNTIME_CLASS(CFloatingPopupBar));
  264. if (!pContextMenu)
  265. {
  266. TRACE0("Failed to create toolbarn");
  267. return;
  268. }
  269. CXTPControls* pControls = pPopupBar->GetControls()->Duplicate();
  270. pContextMenu->SetControls(pControls);
  271. pContextMenu->SetBarID(pPopupBar->GetBarID());
  272. pContextMenu->SetCustomizeDialogPresent(FALSE);
  273. pContextMenu->SetPosition(xtpBarFloating);
  274. pContextMenu->EnableDocking(xtpFlagFloating);
  275. pContextMenu->OnRecalcLayout();
  276. CXTPWindowRect rcContext(pContextMenu);
  277. CXTPWindowRect rcParent(pFrame);
  278. CPoint pt = pFrame->m_ptContextMenu;
  279. if (pt == CPoint(0, 0))
  280. pt = CPoint(rcParent.right, rcParent.top);
  281. pContextMenu->MoveWindow(pt.x, pt.y, rcContext.Width(), rcContext.Height());
  282. pContextMenu->SetCommandBarData((DWORD_PTR)pPopupBar);
  283. pContextMenu->OnUpdateCmdUI();
  284. pFrame->m_pContextMenu = pContextMenu;
  285. }
  286. void CPaneToolbars::OnPanetoolbarsAddMenu()
  287. {
  288. CDialogNewToolbar dt(FALSE);
  289. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  290. if (!pFrame)
  291. return;
  292. if (dt.DoModal() == IDOK)
  293. {
  294. pFrame->CommitContextMenu();
  295. CXTPCommandBars* pCommandBars = pFrame->GetCommandBars();
  296. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(pCommandBars);
  297. pPopupBar->SetTitle(dt.m_strCaption);
  298. pPopupBar->SetBarID(pFrame->ResourceManager()->GetStringID(dt.m_strId));
  299. pFrame->GetCommandBars()->GetContextMenus()->Add(pPopupBar);
  300. Refresh();
  301. HTREEITEM hItem = (HTREEITEM)pPopupBar->GetCommandBarData();
  302. m_wndTreeCtrl.SelectItem(hItem);
  303. //ShowContextMenu(hItem);
  304. }
  305. }
  306. void CPaneToolbars::OnUpdatePanetoolbarsAdd(CCmdUI* pCmdUI)
  307. {
  308. pCmdUI->Enable(m_pActiveCommandBars != NULL);
  309. }
  310. void CPaneToolbars::RefreshItem(HTREEITEM hItem)
  311. {
  312. ((CMainFrame*)AfxGetMainWnd())->m_pActivePane = this;
  313. ((CMainFrame*)AfxGetMainWnd())->RefreshPanes();
  314. }
  315. void CPaneToolbars::OnTreeSelChanged(NMHDR* pNMHDR, LRESULT* pResult)
  316. {
  317. NMTREEVIEW* pNMTreeView = (NMTREEVIEW *)pNMHDR;
  318. if (m_bLockSelected)
  319. return;
  320. RefreshItem(pNMTreeView->itemNew.hItem);
  321. ShowContextMenu(m_wndTreeCtrl.GetSelectedItem());
  322. *pResult = 0;
  323. }
  324. void CPaneToolbars::OnTreeSetFocus(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
  325. {
  326. HTREEITEM hItem = m_wndTreeCtrl.GetSelectedItem();
  327. if (hItem) RefreshItem(hItem);
  328. }
  329. void CPaneToolbars::OnUpdatePanetoolbarsDelete(CCmdUI* pCmdUI)
  330. {
  331. HTREEITEM hItem = m_wndTreeCtrl.GetSelectedItem();
  332. if (hItem)
  333. {
  334. CXTPCommandBar* pCommandBar = (CXTPCommandBar*)m_wndTreeCtrl.GetItemData(hItem);
  335. pCmdUI->Enable(((pCommandBar->GetType() == xtpBarTypeNormal) && (pCommandBar->GetPosition() != xtpBarPopup))
  336. || (pCommandBar->IsPopupBar() && ((CXTPPopupBar*)pCommandBar)->IsContextMenu()));
  337. }
  338. else
  339. {
  340. pCmdUI->Enable(FALSE);
  341. }
  342. }
  343. void CPaneToolbars::OnPanetoolbarsDelete()
  344. {
  345. HTREEITEM hItem = m_wndTreeCtrl.GetSelectedItem();
  346. if (hItem)
  347. {
  348. CXTPCommandBar* pCommandBar = (CXTPCommandBar*)m_wndTreeCtrl.GetItemData(hItem);
  349. if (pCommandBar->IsPopupBar() && ((CXTPPopupBar*)pCommandBar)->IsContextMenu())
  350. {
  351. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  352. if (!pFrame)
  353. return;
  354. pFrame->CommitContextMenu();
  355. ((CMainFrame*)AfxGetMainWnd())->m_pActivePane = NULL;
  356. m_pActiveCommandBars->SetDragControl(NULL);
  357. pCommandBar->GetCommandBars()->GetContextMenus()->Remove(pCommandBar);
  358. Refresh();
  359. }
  360. else if ((pCommandBar->GetType() == xtpBarTypeNormal) && (pCommandBar->GetPosition() != xtpBarPopup))
  361. {
  362. ((CMainFrame*)AfxGetMainWnd())->m_pActivePane = NULL;
  363. m_pActiveCommandBars->SetDragControl(NULL);
  364. pCommandBar->GetCommandBars()->Remove((CXTPToolBar*)pCommandBar);
  365. Refresh();
  366. }
  367. }
  368. }
  369. void CPaneToolbars::FillConstraintsToolbarsID(CXTPPropertyGridItem* pItem)
  370. {
  371. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  372. CXTPCommandBars* pCommandBars = GetMainFrame()->GetActiveCommandBars();
  373. ASSERT(pCommandBars);
  374. for (int i = 0; i < pCommandBars->GetCount(); i++)
  375. {
  376. CXTPCommandBar* pCommandBar = pCommandBars->GetAt(i);
  377. if (pCommandBar->GetType() == xtpBarTypeNormal)
  378. {
  379. pItem->GetConstraints()->AddConstraint(pFrame->ResourceManager()->GetStringID(pCommandBar->GetBarID()));
  380. }
  381. }
  382. }
  383. CObject* CPaneToolbars::RefreshPropertyGrid(CXTPPropertyGrid* pPropertyGrid) 
  384. {
  385. LPCTSTR lpStyles[] = {_T("xtpButtonAutomatic"), _T("xtpButtonCaption"), _T("xtpButtonIcon"), _T("xtpButtonIconAndCaption"), _T("xtpButtonIconAndCaptionBelow"), _T("xtpButtonCaptionAndDescription") };
  386. HTREEITEM hItem = m_wndTreeCtrl.GetSelectedItem();
  387. if (!hItem)
  388. return NULL;
  389. CXTPCommandBar* pCommandBar = (CXTPCommandBar*)m_wndTreeCtrl.GetItemData(hItem);
  390. if (!pCommandBar)
  391. return NULL;
  392. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, pCommandBar);
  393. CXTPPopupBar* pPopupBar = DYNAMIC_DOWNCAST(CXTPPopupBar, pCommandBar);
  394. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  395. if (!pFrame)
  396. return NULL;
  397. CXTPPropertyGridItem* pCategoryAppearance = pPropertyGrid->AddCategory(ID_GRID_CATEGORY_APPEARANCE);
  398. CXTPPropertyGridItem* pCategoryBehavior = pPropertyGrid->AddCategory(ID_GRID_CATEGORY_BEHAVIOR);
  399. pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_COMMANDBAR_TITLE, pCommandBar->GetTitle()));
  400. CString strID = pFrame->ResourceManager()->GetStringID(pCommandBar->GetBarID());
  401. CXTPPropertyGridItem* pItemCommandBarId = pCategoryAppearance->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_COMMANDBAR_ID, strID));
  402. pItemCommandBarId->SetReadOnly(TRUE);
  403. CXTPPropertyGridItem* pItemCommandBarVisible = pCategoryBehavior->AddChildItem(
  404. new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_VISIBLE, pToolBar? pToolBar->IsVisible(): TRUE));
  405. if (!pCommandBar->IsKindOf(RUNTIME_CLASS(CXTPToolBar))) pItemCommandBarVisible->SetReadOnly(TRUE);
  406. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_CUSTOMIZABLE, pCommandBar->IsCustomizable()));
  407. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_ANIMATION, pCommandBar->IsAnimationEnabled()));
  408. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_SHOWGRIPPER, pCommandBar->GetShowGripper()));
  409. {
  410. CXTPPropertyGridItem* pItemCommandBarStyle = pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemEnum(ID_GRID_ITEM_COMMANDBAR_DEFAULTBUTTONSTYLE, pCommandBar->GetDefaultButtonStyle()));
  411. CXTPPropertyGridItemConstraints* pConstraints = pItemCommandBarStyle->GetConstraints();
  412. for (int i = 0; i < _countof(lpStyles); i++)
  413. pConstraints->AddConstraint(lpStyles[i], i);
  414. }
  415. if (pToolBar)
  416. {
  417. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_CLOSEABLE, pToolBar->IsCloseable()));
  418. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_CONTEXTMENUPRESENT, pToolBar->IsContextMenuPresent()));
  419. pCategoryBehavior->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_CUSTOMIZEDIALOGPRESENT, pToolBar->IsCustomizeDialogPresent()));
  420. }
  421. if (pCommandBar->IsKindOf(RUNTIME_CLASS(CXTPPopupBar)))
  422. {
  423. CString strCaption;
  424. UINT nID;
  425. int nWidth;
  426. BOOL bTearOff = pPopupBar->IsTearOffPopup(strCaption, nID, nWidth);
  427. CXTPPropertyGridItem* pItemCommandBarTearOff = pCategoryBehavior->AddChildItem(
  428. new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_TEAROFF, bTearOff));
  429. if (bTearOff)
  430. {
  431. CString strID = pFrame->ResourceManager()->GetStringID(nID);
  432. pItemCommandBarTearOff->AddChildItem(new CXTPPropertyGridItem(ID_GRID_ITEM_COMMANDBAR_TEAROFF_CAPTION, strCaption));
  433. CXTPPropertyGridItem* pItemCommandBarTearOffId = pItemCommandBarTearOff->AddChildItem(
  434. new CXTPPropertyGridItem(ID_GRID_ITEM_COMMANDBAR_TEAROFF_ID, strID));
  435. pItemCommandBarTearOffId->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  436. FillConstraintsToolbarsID(pItemCommandBarTearOffId);
  437. pItemCommandBarTearOff->AddChildItem(new CXTPPropertyGridItemNumber(ID_GRID_ITEM_COMMANDBAR_TEAROFF_WIDTH, nWidth));
  438. pItemCommandBarTearOff->Expand();
  439. }
  440. CXTPPropertyGridItem* pItemPopupToolBar = pCategoryAppearance->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_POPUPTOOLBAR, pCommandBar->GetType() !=xtpBarTypePopup));
  441. if (pCommandBar->GetType() != xtpBarTypePopup)
  442. {
  443. pItemPopupToolBar->AddChildItem(new CXTPPropertyGridItemNumber(ID_GRID_ITEM_COMMANDBAR_WIDTH, pCommandBar->GetWidth()));
  444. }
  445. if (pCommandBar->GetType() == xtpBarTypePopup)
  446. {
  447. pCategoryAppearance->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_DOUBLEGRIPPER, ((CXTPPopupBar*)pCommandBar)->IsDoubleGripper()));
  448. }
  449. }
  450. ///if (pCommandBar->GetType() != xtpBarTypePopup)
  451. {
  452. CSize sz = pCommandBar->GetIconSize();
  453. pCategoryAppearance->AddChildItem(new CXTPPropertyGridItemSize(ID_GRID_ITEM_COMMANDBAR_ICON_SIZE, sz));
  454. }
  455. if (pCommandBar->GetType() != xtpBarTypePopup)
  456. {
  457. CSize sz = pCommandBar->GetButtonSize();
  458. pCategoryAppearance->AddChildItem(new CXTPPropertyGridItemSize(ID_GRID_ITEM_COMMANDBAR_BUTTON_SIZE, sz));
  459. }
  460. if (pCommandBar->GetType() != xtpBarTypePopup)
  461. {
  462. pCategoryAppearance->AddChildItem(new CXTPPropertyGridItemBool(ID_GRID_ITEM_COMMANDBAR_TEXTBELOWICONS, pCommandBar->IsTextBelowIcons()));
  463. }
  464. if (pCommandBar->IsKindOf(RUNTIME_CLASS(CXTPToolBar)))
  465. {
  466. pCategoryBehavior->AddChildItem(new CPropertyGridItemDockingFlags(ID_GRID_ITEM_COMMANDBAR_FLAGS, pCommandBar->GetFlags()));
  467. pCategoryBehavior->AddChildItem(new CPropertyGridItemStretchFlags(ID_GRID_ITEM_COMMANDBAR_STRETCH, pCommandBar->GetFlags()));
  468. }
  469. pCategoryAppearance->Expand();
  470. pCategoryBehavior->Expand();
  471. return pCommandBar;
  472. }
  473. BOOL CPaneToolbars::OnPropertyGridValueChanged(CObject* pActiveObject, CXTPPropertyGridItem* pItem)
  474. {
  475. CXTPCommandBar* pCommandBar = DYNAMIC_DOWNCAST(CXTPCommandBar, pActiveObject);
  476. if (!pCommandBar)
  477. return FALSE;
  478. switch (pItem->GetID())
  479. {
  480. case ID_GRID_ITEM_COMMANDBAR_TITLE:
  481. pCommandBar->SetTitle(pItem->GetValue());
  482. Refresh();
  483. return TRUE;
  484. case  ID_GRID_ITEM_COMMANDBAR_ICON_SIZE:
  485. {
  486. CSize sz = ((CXTPPropertyGridItemSize*)pItem)->GetSize();
  487. pCommandBar->SetIconSize(sz);
  488. pCommandBar->DelayLayout();
  489. GetMainFrame()->RefreshPanes(TRUE);
  490. }
  491. return TRUE;
  492. case  ID_GRID_ITEM_COMMANDBAR_BUTTON_SIZE:
  493. {
  494. CSize sz = ((CXTPPropertyGridItemSize*)pItem)->GetSize();
  495. pCommandBar->SetButtonSize(sz);
  496. pCommandBar->DelayLayout();
  497. GetMainFrame()->RefreshPanes(TRUE);
  498. }
  499. return TRUE;
  500. case ID_GRID_ITEM_COMMANDBAR_TEXTBELOWICONS:
  501. pCommandBar->ShowTextBelowIcons(GetBoolValue(pItem));
  502. return TRUE;
  503. case ID_GRID_ITEM_COMMANDBAR_VISIBLE:
  504. pCommandBar->SetVisible(GetBoolValue(pItem));
  505. Refresh();
  506. return TRUE;
  507. case ID_GRID_ITEM_COMMANDBAR_CUSTOMIZABLE:
  508. pCommandBar->EnableCustomization(GetBoolValue(pItem));
  509. Refresh();
  510. return TRUE;
  511. case ID_GRID_ITEM_COMMANDBAR_ANIMATION:
  512. pCommandBar->EnableAnimation(GetBoolValue(pItem));
  513. return TRUE;
  514. case ID_GRID_ITEM_COMMANDBAR_SHOWGRIPPER:
  515. pCommandBar->SetShowGripper(GetBoolValue(pItem));
  516. pCommandBar->OnRecalcLayout();
  517. return TRUE;
  518. case ID_GRID_ITEM_COMMANDBAR_DEFAULTBUTTONSTYLE:
  519. pCommandBar->SetDefaultButtonStyle((XTPButtonStyle)GetEnumValue(pItem));
  520. pCommandBar->OnRecalcLayout();
  521. return TRUE;
  522. case ID_GRID_ITEM_COMMANDBAR_CLOSEABLE:
  523. ((CXTPToolBar*)pCommandBar)->SetCloseable(GetBoolValue(pItem));
  524. return TRUE;
  525. case ID_GRID_ITEM_COMMANDBAR_CONTEXTMENUPRESENT:
  526. ((CXTPToolBar*)pCommandBar)->SetContextMenuPresent(GetBoolValue(pItem));
  527. return TRUE;
  528. case ID_GRID_ITEM_COMMANDBAR_CUSTOMIZEDIALOGPRESENT:
  529. ((CXTPToolBar*)pCommandBar)->SetCustomizeDialogPresent(GetBoolValue(pItem));
  530. return TRUE;
  531. case ID_GRID_ITEM_COMMANDBAR_STRETCH:
  532. case ID_GRID_ITEM_COMMANDBAR_FLAGS:
  533. {
  534. DWORD dwMask = pItem->GetID() == ID_GRID_ITEM_COMMANDBAR_STRETCH? xtpFlagHideWrap|xtpFlagStretched: xtpFlagAlignAny|xtpFlagFloating;
  535. DWORD dwFalgs = (pCommandBar->GetFlags() & ~dwMask) | GetFlagsValue(pItem);
  536. ((CXTPToolBar*)pCommandBar)->EnableDocking(dwFalgs);
  537. pCommandBar->DelayLayout();
  538. Refresh();
  539. }
  540. return TRUE;
  541. case ID_GRID_ITEM_COMMANDBAR_POPUPTOOLBAR:
  542. ((CXTPPopupBar*)pCommandBar)->SetPopupToolBar(GetBoolValue(pItem));
  543. pCommandBar->DelayLayout();
  544. Refresh();
  545. ((CMainFrame*)AfxGetMainWnd())->m_paneProperties.Refresh(this);
  546. return TRUE;
  547. case ID_GRID_ITEM_COMMANDBAR_WIDTH:
  548. pCommandBar->SetWidth(GetNumberValue(pItem));
  549. pCommandBar->DelayLayout();
  550. Refresh();
  551. return TRUE;
  552. case  ID_GRID_ITEM_COMMANDBAR_DOUBLEGRIPPER:
  553. {
  554. CXTPPopupBar* pPopupBar = DYNAMIC_DOWNCAST(CXTPPopupBar, pCommandBar);
  555. ASSERT(pPopupBar);
  556. pPopupBar->SetDoubleGripper(GetBoolValue(pItem));
  557. break;
  558. }
  559. case ID_GRID_ITEM_COMMANDBAR_TEAROFF:
  560. {
  561. CXTPPopupBar* pPopupBar = DYNAMIC_DOWNCAST(CXTPPopupBar, pCommandBar);
  562. ASSERT(pPopupBar);
  563. if (GetBoolValue(pItem))
  564. {
  565. CString strCaption;
  566. UINT nID;
  567. int nWidth;
  568. pPopupBar->IsTearOffPopup(strCaption, nID, nWidth);
  569. if (nID == 0)
  570. {
  571. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  572. ASSERT(pFrame);
  573. nID = pFrame->ResourceManager()->GetStringID(_T("IDR_UNTITLED"));
  574. pPopupBar->SetTearOffPopup(_T("Untitled"), nID);
  575. }
  576. else  pPopupBar->SetTearOffPopup(strCaption, nID, nWidth);
  577. }
  578. else
  579. {
  580. pPopupBar->SetTearOffPopup(_T(""), 0);
  581. }
  582. ((CMainFrame*)AfxGetMainWnd())->m_paneProperties.Refresh(this);
  583. }
  584. return TRUE;
  585. case ID_GRID_ITEM_COMMANDBAR_TEAROFF_ID:
  586. {
  587. CEmbeddedFrame* pFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  588. ASSERT(pFrame);
  589. CXTPPopupBar* pPopupBar = DYNAMIC_DOWNCAST(CXTPPopupBar, pCommandBar);
  590. ASSERT(pPopupBar);
  591. CString strCaption;
  592. UINT nID;
  593. int nWidth;
  594. pPopupBar->IsTearOffPopup(strCaption, nID, nWidth);
  595. pPopupBar->SetTearOffPopup(strCaption, pFrame->ResourceManager()->GetStringID(pItem->GetValue()), nWidth);
  596. }
  597. return TRUE;
  598. case ID_GRID_ITEM_COMMANDBAR_TEAROFF_CAPTION:
  599. {
  600. CXTPPopupBar* pPopupBar = DYNAMIC_DOWNCAST(CXTPPopupBar, pCommandBar);
  601. ASSERT(pPopupBar);
  602. CString strCaption;
  603. UINT nID;
  604. int nWidth;
  605. pPopupBar->IsTearOffPopup(strCaption, nID, nWidth);
  606. pPopupBar->SetTearOffPopup(pItem->GetValue(), nID, nWidth);
  607. }
  608. return TRUE;
  609. case ID_GRID_ITEM_COMMANDBAR_TEAROFF_WIDTH:
  610. {
  611. CXTPPopupBar* pPopupBar = DYNAMIC_DOWNCAST(CXTPPopupBar, pCommandBar);
  612. ASSERT(pPopupBar);
  613. CString strCaption;
  614. UINT nID;
  615. int nWidth;
  616. pPopupBar->IsTearOffPopup(strCaption, nID, nWidth);
  617. pPopupBar->SetTearOffPopup(strCaption, nID, GetNumberValue(pItem));
  618. }
  619. return TRUE;
  620. }
  621. return FALSE;
  622. }