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

对话框与窗口

开发平台:

Visual C++

  1. // XTColorPopup.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME CONTROLS 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 "Common/XTPDrawHelpers.h"
  22. #include "Common/XTPWinThemeWrapper.h"
  23. #include "Common/XTPColorManager.h"
  24. #include "Common/XTPSystemHelpers.h"
  25. #include "Common/XTPHookManager.h"
  26. #include "Resource.h"
  27. #include "XTDefines.h"
  28. #include "XTColorSelectorCtrl.h"
  29. #include "XTColorPopup.h"
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CXTColorPopup
  37. CXTColorPopup::CXTColorPopup(BOOL bAutoDelete/*= FALSE*/, LPARAM callerParam /*= 0*/)
  38. : m_callerParam(callerParam)
  39. {
  40. m_bAutoDelete = bAutoDelete;
  41. m_bDisplayShadow = TRUE;
  42. m_pShadowManager = new CXTPShadowManager();
  43. }
  44. CXTColorPopup::~CXTColorPopup()
  45. {
  46. CMDTARGET_RELEASE(m_pShadowManager);
  47. }
  48. BEGIN_MESSAGE_MAP(CXTColorPopup, CXTColorSelectorCtrl)
  49. //{{AFX_MSG_MAP(CXTColorPopup)
  50. ON_WM_ACTIVATE()
  51. ON_WM_DESTROY()
  52. ON_WM_CREATE()
  53. ON_WM_KILLFOCUS()
  54. ON_WM_LBUTTONDOWN()
  55. ON_WM_NCPAINT()
  56. ON_WM_NCCALCSIZE()
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CXTColorPopup message handlers
  61. BOOL CXTColorPopup::Create(CRect& rect, CWnd* pParentWnd, DWORD dwPopup, COLORREF clrColor,
  62. COLORREF clrDefault/*= CLR_DEFAULT*/)
  63. {
  64. BOOL bOfficeTheme = GetTheme()->GetTheme() != xtThemeDefault;
  65. if (bOfficeTheme)
  66. {
  67. SetBorders(4, 4, 6, 6);
  68. }
  69. else
  70. {
  71. SetBorders(4, 4, 10, 10);
  72. }
  73. m_rcExclude = rect;
  74. return CXTColorSelectorCtrl::Create(rect, pParentWnd, dwPopup | WS_POPUP, clrColor, clrDefault);
  75. }
  76. void CXTColorPopup::PostNcDestroy()
  77. {
  78. CXTPMouseMonitor::SetupHook(NULL);
  79. if (m_bAutoDelete)
  80. {
  81. delete this;
  82. }
  83. }
  84. void CXTColorPopup::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
  85. {
  86. CWnd::OnActivate(nState, pWndOther, bMinimized);
  87. // If we lose activation (other than to the color dialog) post
  88. // a close message...
  89. if (nState == WA_INACTIVE && !IsColorDlgVisible())
  90. {
  91. PostMessage(WM_CLOSE);
  92. }
  93. }
  94. void CXTColorPopup::OnDestroy()
  95. {
  96. CWnd::OnDestroy();
  97. // Inform the parent that we are closing up.
  98. m_pParentWnd->SendMessage(CPN_XT_CLOSEUP,
  99. (WPARAM)m_clrColor, m_callerParam);
  100. }
  101. int CXTColorPopup::OnCreate(LPCREATESTRUCT lpCreateStruct)
  102. {
  103. if (CXTColorSelectorCtrl::OnCreate(lpCreateStruct) == -1)
  104. return -1;
  105. BOOL bOfficeTheme = GetTheme()->GetTheme() != xtThemeDefault;
  106. if (bOfficeTheme)
  107. {
  108. ModifyStyle(WS_DLGFRAME | WS_THICKFRAME | WS_BORDER, 0, SWP_FRAMECHANGED);
  109. ModifyStyleEx(WS_EX_STATICEDGE | WS_EX_WINDOWEDGE | WS_EX_DLGMODALFRAME, 0, SWP_FRAMECHANGED);
  110. }
  111. else
  112. {
  113. ModifyStyle(0, WS_DLGFRAME, SWP_FRAMECHANGED);
  114. }
  115. CRect rcWork = XTPMultiMonitor()->GetWorkArea(m_rcWnd);
  116. CSize size = m_rcWnd.Size();
  117. // move right
  118. if (m_rcWnd.left < rcWork.left)
  119. {
  120. m_rcWnd.left = rcWork.left;
  121. m_rcWnd.right = m_rcWnd.left + size.cx;
  122. }
  123. // move left
  124. else if (m_rcWnd.right > rcWork.right)
  125. {
  126. m_rcWnd.right = rcWork.right;
  127. m_rcWnd.left = m_rcWnd.right - size.cx;
  128. }
  129. // move up
  130. if (m_rcWnd.bottom > rcWork.bottom)
  131. {
  132. if (m_rcExclude.IsRectEmpty())
  133. m_rcWnd.bottom = rcWork.top;
  134. else
  135. m_rcWnd.bottom = m_rcExclude.top;
  136. m_rcWnd.top = m_rcWnd.bottom - size.cy;
  137. }
  138. SetFocus();
  139. SetWindowLongPtr(m_hWnd, GWLP_HWNDPARENT, 0);
  140. ModifyStyle(WS_CHILD, WS_POPUP);
  141. SetWindowLongPtr(m_hWnd, GWLP_HWNDPARENT, (LONG_PTR)m_pParentWnd->m_hWnd);
  142. SetWindowPos(&CWnd::wndTop, m_rcWnd.left, m_rcWnd.top, m_rcWnd.Width(), m_rcWnd.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  143. if (bOfficeTheme && m_bDisplayShadow)
  144. {
  145. m_pShadowManager->SetShadowOptions(xtpShadowOfficeAlpha);
  146. m_pShadowManager->SetShadow(this);
  147. }
  148. CXTPMouseMonitor::SetupHook(this);
  149. m_pParentWnd->SendMessage(CPN_XT_DROPDOWN,
  150. (WPARAM)m_clrColor, m_callerParam);
  151. return 0;
  152. }
  153. // Adds a window to send color picker notifications to.
  154. void CXTColorPopup::AddListener(HWND hwndListener)
  155. {
  156. m_listeners.Add(hwndListener);
  157. }
  158. void CXTColorPopup::EndSelection(int nCurSel)
  159. {
  160. CXTPMouseMonitor::SetupHook(NULL);
  161. OnEndSelection(nCurSel, m_callerParam);
  162. PostMessage(WM_CLOSE);
  163. }
  164. void CXTColorPopup::OnKillFocus(CWnd* pNewWnd)
  165. {
  166. CWnd::OnKillFocus(pNewWnd);
  167. if (!m_pColorDlg)
  168. {
  169. EndSelection(-1);
  170. }
  171. }
  172. void CXTColorPopup::OnLButtonDown(UINT nFlags, CPoint point)
  173. {
  174. CRect rc;
  175. GetClientRect(&rc);
  176. if (!rc.PtInRect(point) && !IsColorDlgVisible())
  177. {
  178. EndSelection(-1);
  179. return;
  180. }
  181. CXTColorSelectorCtrl::OnLButtonDown(nFlags, point);
  182. }
  183. void CXTColorPopup::OnNcPaint()
  184. {
  185. BOOL bOfficeTheme = GetTheme()->GetTheme() != xtThemeDefault;
  186. if (bOfficeTheme)
  187. {
  188. CWindowDC dc(this);
  189. const COLORREF clrFrame = GetXtremeColor(XPCOLOR_MENUBAR_BORDER);
  190. CRect rc;
  191. GetWindowRect(&rc);
  192. int cx = rc.Width(); // for right border is exclusive
  193. int cy = rc.Height() ; // see above
  194. dc.Draw3dRect(0, 0, cx, cy, clrFrame, clrFrame);
  195. }
  196. else
  197. {
  198. Default();
  199. }
  200. }
  201. void CXTColorPopup::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  202. {
  203. BOOL bOfficeTheme = GetTheme()->GetTheme() != xtThemeDefault;
  204. if (bOfficeTheme)
  205. {
  206. // adjust non-client area for border space
  207. lpncsp->rgrc[0].left += 1;
  208. lpncsp->rgrc[0].top += 1;
  209. lpncsp->rgrc[0].right += -1;
  210. lpncsp->rgrc[0].bottom += -1;
  211. }
  212. else
  213. {
  214. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  215. }
  216. }