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

对话框与窗口

开发平台:

Visual C++

  1. // XTPRibbonSystemButton.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME RIBBON 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 "Resource.h"
  22. #include "Common/XTPOffice2007Image.h"
  23. #include "Common/XTPIntel80Helpers.h"
  24. #include "Common/XTPVc50Helpers.h"
  25. #include "CommandBars/XTPCommandBars.h"
  26. #include "CommandBars/XTPControlExt.h"
  27. #include "XTPRibbonSystemButton.h"
  28. #include "XTPRibbonBar.h"
  29. #include "XTPRibbonTheme.h"
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. IMPLEMENT_XTP_CONTROL(CXTPRibbonControlSystemButton, CXTPControlPopup)
  36. CXTPRibbonControlSystemButton::CXTPRibbonControlSystemButton()
  37. {
  38. SetFlags(xtpFlagNoMovable | xtpFlagManualUpdate);
  39. }
  40. void CXTPRibbonControlSystemButton::Draw(CDC* pDC)
  41. {
  42. ((CXTPRibbonBar*)GetParent())->GetRibbonPaintManager()->DrawRibbonFrameSystemButton(pDC, this, GetRect());
  43. }
  44. BOOL CXTPRibbonControlSystemButton::OnLButtonDblClk(CPoint /*point*/)
  45. {
  46. GetParent()->GetCommandBars()->ClosePopups();
  47. GetParent()->GetSite()->SendMessage(WM_SYSCOMMAND, SC_CLOSE | HTSYSMENU, 0);
  48. return TRUE;
  49. }
  50. void CXTPRibbonControlSystemButton::AdjustExcludeRect(CRect& rc, BOOL bVertical)
  51. {
  52. CXTPRibbonBar* pRibbonBar = DYNAMIC_DOWNCAST(CXTPRibbonBar, GetParent());
  53. if (!pRibbonBar)
  54. {
  55. CXTPControlPopup::AdjustExcludeRect(rc, bVertical);
  56. return;
  57. }
  58. if (pRibbonBar->IsCaptionVisible() && pRibbonBar->IsTabsVisible() &&
  59. DYNAMIC_DOWNCAST(CXTPRibbonSystemPopupBar, GetCommandBar()))
  60. {
  61. rc.bottom -= 18;
  62. return;
  63. }
  64. //rc.bottom -= 20;
  65. CXTPControlPopup::AdjustExcludeRect(rc, bVertical);
  66. }
  67. //////////////////////////////////////////////////////////////////////////
  68. IMPLEMENT_XTP_COMMANDBAR(CXTPRibbonSystemPopupBar, CXTPPopupBar)
  69. BEGIN_MESSAGE_MAP(CXTPRibbonSystemPopupBar, CXTPPopupBar)
  70. ON_WM_NCHITTEST_EX()
  71. END_MESSAGE_MAP()
  72. CXTPRibbonSystemPopupBar::CXTPRibbonSystemPopupBar()
  73. {
  74. m_rcBorders.SetRect(6, 18, 6, 29);
  75. SetShowGripper(FALSE);
  76. }
  77. CRect CXTPRibbonSystemPopupBar::GetBorders()
  78. {
  79. return m_rcBorders;
  80. }
  81. void CXTPRibbonSystemPopupBar::FillCommandBarEntry(CDC* pDC)
  82. {
  83. CXTPClientRect rc(this);
  84. CXTPOffice2007Theme* pPaintManager = (CXTPOffice2007Theme*)GetPaintManager();
  85. CXTPOffice2007Image* pImage = pPaintManager->LoadImage(_T("RIBBONSYSTEMMENU"));
  86. if (!pImage)
  87. return;
  88. pImage->DrawImage(pDC, rc, pImage->GetSource(), m_rcBorders, COLORREF_NULL);
  89. if (!DYNAMIC_DOWNCAST(CXTPRibbonControlSystemButton, m_pControlPopup))
  90. return;
  91. CXTPRibbonBar* pRibbonBar = DYNAMIC_DOWNCAST(CXTPRibbonBar, m_pControlPopup->GetParent());
  92. if (!pRibbonBar)
  93. return;
  94. CRect rcPopup = m_pControlPopup->GetRect();
  95. m_pControlPopup->GetParent()->ClientToScreen(rcPopup);
  96. ScreenToClient(rcPopup);
  97. if (pRibbonBar->IsCaptionVisible() && CRect().IntersectRect(rcPopup, rc))
  98. {
  99. ((CXTPRibbonTheme*)pPaintManager)->DrawRibbonFrameSystemButton(pDC, m_pControlPopup, rcPopup);
  100. }
  101. for (int i = 0; i < GetControlCount(); i++)
  102. {
  103. CXTPControl* pControl = GetControl(i);
  104. if (pControl && pControl->GetWrap())
  105. {
  106. CRect rcRow = pControl->GetRowRect();
  107. pDC->FillSolidRect(rcRow, pPaintManager->GetImages()->GetImageColor(_T("Ribbon"), _T("RecentFileListBackground")));
  108. break;
  109. }
  110. }
  111. }
  112. LRESULT CXTPRibbonSystemPopupBar::OnNcHitTest(CPoint point)
  113. {
  114. if (!DYNAMIC_DOWNCAST(CXTPRibbonControlSystemButton, m_pControlPopup))
  115. return CXTPPopupBar::OnNcHitTest(point);
  116. CRect rcPopup = m_pControlPopup->GetRect();
  117. m_pControlPopup->GetParent()->ClientToScreen(rcPopup);
  118. if (rcPopup.PtInRect(point))
  119. return HTTRANSPARENT;
  120. return CXTPPopupBar::OnNcHitTest(point);
  121. }
  122. CSize CXTPRibbonSystemPopupBar::CalcDynamicLayout(int nLength, DWORD dwMode)
  123. {
  124. CArray<CXTPControl*, CXTPControl*> arrButtons;
  125. int i;
  126. for (i = 0; i < GetControlCount(); i++)
  127. {
  128. CXTPControl* pControl = GetControl(i);
  129. if (pControl && pControl->IsKindOf(RUNTIME_CLASS(CXTPRibbonControlSystemPopupBarButton)))
  130. {
  131. arrButtons.Add(pControl);
  132. pControl->SetHideFlag(xtpHideDockingPosition, TRUE);
  133. }
  134. }
  135. CSize sz = CXTPPopupBar::CalcDynamicLayout(nLength, dwMode);
  136. if (arrButtons.GetSize() == 0)
  137. return sz;
  138. CClientDC dc(this);
  139. CXTPFontDC font(&dc, GetPaintManager()->GetCommandBarFont(this));
  140. int nRight = sz.cx - m_rcBorders.right + 1;
  141. for (i = (int)arrButtons.GetSize() - 1; i >= 0; i--)
  142. {
  143. CXTPControl* pControl = arrButtons[i];
  144. pControl->SetHideFlag(xtpHideDockingPosition, FALSE);
  145. CSize szControl = pControl->GetSize(&dc);
  146. pControl->SetRect(CRect(nRight - szControl.cx, sz.cy - m_rcBorders.bottom + 4, nRight, sz.cy - 3));
  147. nRight -= szControl.cx + 6;
  148. }
  149. return sz;
  150. }
  151. //////////////////////////////////////////////////////////////////////////
  152. // CXTPRibbonControlSystemPopupBarButton
  153. IMPLEMENT_XTP_CONTROL(CXTPRibbonControlSystemPopupBarButton, CXTPControlButton)
  154. CXTPRibbonControlSystemPopupBarButton::CXTPRibbonControlSystemPopupBarButton()
  155. {
  156. }
  157. BOOL CXTPRibbonControlSystemPopupBarButton::IsSystemPopupButton() const
  158. {
  159. return m_pParent && m_pParent->IsKindOf(RUNTIME_CLASS(CXTPRibbonSystemPopupBar));
  160. }
  161. BOOL CXTPRibbonControlSystemPopupBarButton::IsTransparent() const
  162. {
  163. if (IsSystemPopupButton())
  164. return TRUE;
  165. return CXTPControlButton::IsTransparent();
  166. }
  167. void CXTPRibbonControlSystemPopupBarButton::Draw(CDC* pDC)
  168. {
  169. if (IsSystemPopupButton())
  170. {
  171. CXTPOffice2007Theme* pPaintManager = (CXTPOffice2007Theme*)GetPaintManager();
  172. CXTPOffice2007Image* pImage = pPaintManager->LoadImage(_T("RIBBONSYSTEMMENUBUTTON"));
  173. if (pImage)
  174. {
  175. pImage->DrawImage(pDC, GetRect(), pImage->GetSource(GetSelected() ? 1 : 0, 2), CRect(2, 2, 2, 2), 0xFF00FF);
  176. }
  177. GetPaintManager()->DrawControlToolBarParent(pDC, this, TRUE);
  178. }
  179. else
  180. {
  181. CXTPControlButton::Draw(pDC);
  182. }
  183. }
  184. CSize CXTPRibbonControlSystemPopupBarButton::GetSize(CDC* pDC)
  185. {
  186. if (IsSystemPopupButton())
  187. return GetPaintManager()->DrawControlToolBarParent(pDC, this, FALSE);
  188. return CXTPControlButton::GetSize(pDC);
  189. }
  190. CSize CXTPRibbonControlSystemPopupBarButton::GetButtonSize() const
  191. {
  192. return CSize(22, 22);
  193. }
  194. CSize CXTPRibbonControlSystemPopupBarButton::GetIconSize() const
  195. {
  196. return CSize(16, 16);
  197. }
  198. //////////////////////////////////////////////////////////////////////////
  199. // CXTPControlRecentFileList
  200. IMPLEMENT_XTP_CONTROL(CXTPRibbonControlSystemPopupBarListItem, CXTPControlButton)
  201. CXTPRibbonControlSystemPopupBarListItem::CXTPRibbonControlSystemPopupBarListItem()
  202. {
  203. m_nWidth = 300;
  204. m_nHeight = 21;
  205. m_bAlignShortcut = FALSE;
  206. }
  207. CSize CXTPRibbonControlSystemPopupBarListItem::GetSize(CDC* /*pDC*/)
  208. {
  209. return CSize(m_nWidth, m_nHeight);
  210. }
  211. void CXTPRibbonControlSystemPopupBarListItem::Draw(CDC* pDC)
  212. {
  213. CXTPPaintManager* pPaintManager = (CXTPPaintManager*)GetPaintManager();
  214. pPaintManager->DrawControlEntry(pDC, this);
  215. COLORREF clrText = pPaintManager->GetControlTextColor(this);
  216. pDC->SetTextColor(clrText);
  217. pDC->SetBkMode (TRANSPARENT);
  218. CRect rc(GetRect());
  219. CRect rcText(rc.left + 7, rc.top, rc.right, rc.bottom);
  220. CString strText(GetCaption());
  221. if (m_bAlignShortcut)
  222. {
  223. if (strText.GetLength() > 2 && strText[0] == _T('&') && strText[2] == _T(' '))
  224. {
  225. pDC->DrawText(strText.Left(2), &rcText, DT_SINGLELINE | DT_VCENTER);
  226. DELETE_S(strText, 0, 3);
  227. }
  228. rcText.left += pDC->GetTextExtent(_T("0"), 1).cx + 7;
  229. }
  230. pDC->DrawText(strText, &rcText, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
  231. }
  232. IMPLEMENT_XTP_CONTROL(CXTPRibbonControlSystemPopupBarListCaption, CXTPControl)
  233. CXTPRibbonControlSystemPopupBarListCaption::CXTPRibbonControlSystemPopupBarListCaption()
  234. {
  235. SetFlags(xtpFlagManualUpdate | xtpFlagSkipFocus | xtpFlagNoMovable | xtpFlagWrapRow);
  236. m_nWidth = 300;
  237. m_nHeight = 27;
  238. }
  239. CSize CXTPRibbonControlSystemPopupBarListCaption::GetSize(CDC* /*pDC*/)
  240. {
  241. return CSize(m_nWidth, m_nHeight);
  242. }
  243. void CXTPRibbonControlSystemPopupBarListCaption::Draw(CDC* pDC)
  244. {
  245. CXTPOffice2007Theme* pPaintManager = (CXTPOffice2007Theme*)GetPaintManager();
  246. CXTPFontDC dont(pDC, pPaintManager->GetRegularBoldFont());
  247. COLORREF clrText = pPaintManager->GetControlTextColor(this);
  248. pDC->SetTextColor(clrText);
  249. pDC->SetBkMode (TRANSPARENT);
  250. CRect rc(GetRect());
  251. CRect rcText(rc.left + 7, rc.top + 4, rc.right, rc.bottom - 5);
  252. pDC->DrawText(GetCaption(), &rcText, DT_SINGLELINE | DT_TOP);
  253. pPaintManager->HorizontalLine(pDC, rc.left, rc.bottom - 6, rc.right,
  254. pPaintManager->GetImages()->GetImageColor(_T("Ribbon"), _T("RecentFileListEdgeShadow")));
  255. pPaintManager->HorizontalLine(pDC, rc.left, rc.bottom - 5, rc.right,
  256. pPaintManager->GetImages()->GetImageColor(_T("Ribbon"), _T("RecentFileListEdgeHighLight")));
  257. }
  258. IMPLEMENT_XTP_CONTROL(CXTPRibbonControlSystemRecentFileList, CXTPRibbonControlSystemPopupBarListCaption)
  259. CXTPRibbonControlSystemRecentFileList::CXTPRibbonControlSystemRecentFileList()
  260. {
  261. }
  262. CRecentFileList* CXTPRibbonControlSystemRecentFileList::GetRecentFileList()
  263. {
  264. USES_PROTECTED_ACCESS(CXTPRibbonControlSystemRecentFileList, CWinApp, CRecentFileList*, m_pRecentFileList)
  265. return PROTECTED_ACCESS(CWinApp, AfxGetApp(), m_pRecentFileList);
  266. }
  267. int CXTPRibbonControlSystemRecentFileList::GetFirstMruID()
  268. {
  269. return ID_FILE_MRU_FILE1;
  270. }
  271. UINT AFXAPI AfxGetFileTitle(LPCTSTR lpszPathName, LPTSTR lpszTitle, UINT nMax);
  272. CString CXTPRibbonControlSystemRecentFileList::ConstructCaption(const CString& lpszTitle, int nIndex)
  273. {
  274. CString strTemp;
  275. // double up any '&' characters so they are not underlined
  276. LPCTSTR lpszSrc = lpszTitle;
  277. LPTSTR lpszDest = strTemp.GetBuffer(lpszTitle.GetLength() * 2);
  278. while (*lpszSrc != 0)
  279. {
  280. if (*lpszSrc == '&')
  281. *lpszDest++ = '&';
  282. if (_istlead(*lpszSrc))
  283. *lpszDest++ = *lpszSrc++;
  284. *lpszDest++ = *lpszSrc++;
  285. }
  286. *lpszDest = 0;
  287. strTemp.ReleaseBuffer();
  288. CString strTitle;
  289. if (nIndex == 0)
  290. return strTemp;
  291. if (nIndex < 10)
  292. {
  293. strTitle.Format(_T("&%i %s"), nIndex, (LPCTSTR)strTemp);
  294. }
  295. else
  296. {
  297. strTitle = strTemp;
  298. }
  299. return strTitle;
  300. }
  301. class CXTPRibbonControlSystemRecentFileList::CControlFileItem : public CXTPRibbonControlSystemPopupBarListItem
  302. {
  303. public:
  304. CControlFileItem()
  305. {
  306. m_bAlignShortcut = TRUE;
  307. }
  308. };
  309. void CXTPRibbonControlSystemRecentFileList::OnCalcDynamicSize(DWORD /*dwMode*/)
  310. {
  311. CRecentFileList* pRecentFileList = GetRecentFileList();
  312. if (!pRecentFileList)
  313. return;
  314. ASSERT(pRecentFileList->m_arrNames != NULL);
  315. if (!pRecentFileList->m_arrNames)
  316. return;
  317. while (m_nIndex + 1 < m_pControls->GetCount())
  318. {
  319. CXTPControl* pControl = m_pControls->GetAt(m_nIndex + 1);
  320. if (pControl->GetID() >= GetFirstMruID() && pControl->GetID() <= GetFirstMruID() + pRecentFileList->m_nSize)
  321. {
  322. m_pControls->Remove(pControl);
  323. }
  324. else break;
  325. }
  326. if (m_pParent->IsCustomizeMode())
  327. {
  328. m_dwHideFlags = 0;
  329. SetEnabled(TRUE);
  330. return;
  331. }
  332. CString strName;
  333. for (int iMRU = 0; iMRU < pRecentFileList->m_nSize; iMRU++)
  334. {
  335. if (pRecentFileList->m_arrNames[iMRU].IsEmpty())
  336. break;
  337. // copy file name only since directories are same
  338. AfxGetFileTitle(pRecentFileList->m_arrNames[iMRU], strName.GetBuffer(_MAX_PATH), _MAX_PATH);
  339. strName.ReleaseBuffer();
  340. CXTPControl* pControl = m_pControls->Add(new CControlFileItem(), iMRU + GetFirstMruID(), _T(""), m_nIndex + iMRU + 1 , TRUE);
  341. pControl->SetCaption(ConstructCaption(strName, iMRU + 1));
  342. pControl->SetFlags(xtpFlagManualUpdate|xtpFlagShowPopupBarTip);
  343. pControl->SetTooltip(pRecentFileList->m_arrNames[iMRU]);
  344. pControl->SetDescription(NULL);
  345. }
  346. }
  347. BOOL CXTPRibbonControlSystemRecentFileList::IsCustomizeDragOverAvail(CXTPCommandBar* pCommandBar, CPoint /*point*/, DROPEFFECT& dropEffect)
  348. {
  349. if (pCommandBar->GetType() != xtpBarTypePopup)
  350. {
  351. dropEffect = DROPEFFECT_NONE;
  352. return FALSE;
  353. }
  354. return TRUE;
  355. }
  356. //////////////////////////////////////////////////////////////////////////
  357. // CXTPRibbonSystemPopupBarPage
  358. IMPLEMENT_XTP_COMMANDBAR(CXTPRibbonSystemPopupBarPage, CXTPPopupBar)
  359. CXTPRibbonSystemPopupBarPage::CXTPRibbonSystemPopupBarPage()
  360. {
  361. }
  362. CSize CXTPRibbonSystemPopupBarPage::CalcDynamicLayout(int nLength, DWORD dwMode)
  363. {
  364. CSize sz = CXTPPopupBar::CalcDynamicLayout(nLength, dwMode);
  365. if (!m_pControlPopup->GetParent()->IsKindOf(RUNTIME_CLASS(CXTPRibbonSystemPopupBar)))
  366. return sz;
  367. CXTPRibbonSystemPopupBar* pParent = ((CXTPRibbonSystemPopupBar*)m_pControlPopup->GetParent());
  368. int nHeight = CXTPClientRect(pParent).Height() - (pParent->GetBorders().top + pParent->GetBorders().bottom) - 2;
  369. if (nHeight > sz.cy)
  370. sz.cy = nHeight;
  371. return sz;
  372. }
  373. void CXTPRibbonSystemPopupBarPage::AdjustExcludeRect(CRect& rc, BOOL bVertical)
  374. {
  375. if (!m_pControlPopup->GetParent()->IsKindOf(RUNTIME_CLASS(CXTPRibbonSystemPopupBar)))
  376. {
  377. CXTPPopupBar::AdjustExcludeRect(rc, bVertical);
  378. return;
  379. }
  380. rc.top = ((CXTPRibbonSystemPopupBar*)m_pControlPopup->GetParent())->GetBorders().top + 1;
  381. rc.right += 1;
  382. }