Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

589 lines
15 KiB

  1. //
  2. // cuitb.cpp
  3. //
  4. #include "private.h"
  5. #include "cuitb.h"
  6. #include "cuiwnd.h"
  7. #include "cuischem.h"
  8. #include "cmydc.h"
  9. HBRUSH CreateDitherBrush( void );
  10. #if 0
  11. void DrawDownTri(HDC hDC, RECT *prc)
  12. {
  13. static HBITMAP hbmpTri = NULL;
  14. HBITMAP hbmpOld;
  15. HDC hdcMem = CreateCompatibleDC(hDC);
  16. if (!hdcMem)
  17. return;
  18. if (!hbmpTri)
  19. {
  20. HPEN hpen;
  21. HPEN hpenOld;
  22. const static RECT rcBmp = {0, 0, 6, 3};
  23. hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNTEXT));
  24. hbmpTri = CreateCompatibleBitmap(hDC, 5, 3);
  25. hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmpTri);
  26. FillRect( hdcMem, &rcBmp, (HBRUSH)(COLOR_3DFACE + 1) );
  27. hpenOld = (HPEN)SelectObject(hdcMem, hpen);
  28. MoveToEx(hdcMem, 0, 0, NULL);
  29. LineTo(hdcMem, 5, 0);
  30. MoveToEx(hdcMem, 1, 1, NULL);
  31. LineTo(hdcMem, 4, 1);
  32. MoveToEx(hdcMem, 2, 2, NULL);
  33. LineTo(hdcMem, 3, 2);
  34. SelectObject(hdcMem, hpenOld);
  35. DeleteObject(hpen);
  36. }
  37. else
  38. hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmpTri);
  39. BitBlt(hDC,
  40. prc->left + ((prc->right - prc->left) / 2) - 3,
  41. prc->top + ((prc->bottom - prc->top) / 2) - 1,
  42. 5, 3,
  43. hdcMem,
  44. 0, 0, SRCCOPY);
  45. SelectObject(hdcMem, hbmpOld);
  46. DeleteDC(hdcMem);
  47. }
  48. #endif
  49. /*=============================================================================*/
  50. /* */
  51. /* C U I B U T T O N */
  52. /* */
  53. /*=============================================================================*/
  54. /*------------------------------------------------------------------------------
  55. ctor
  56. ------------------------------------------------------------------------------*/
  57. CUIFToolbarButtonElement::CUIFToolbarButtonElement( CUIFToolbarButton *pParent, DWORD dwID, RECT *prc, DWORD dwStyle) : CUIFButton2( pParent, dwID, prc, dwStyle )
  58. {
  59. _pTBButton = pParent;
  60. }
  61. /*------------------------------------------------------------------------------
  62. dtor
  63. ------------------------------------------------------------------------------*/
  64. CUIFToolbarButtonElement::~CUIFToolbarButtonElement( void )
  65. {
  66. Assert(!m_pUIWnd);
  67. }
  68. /*------------------------------------------------------------------------------
  69. OnLButtonUp
  70. ------------------------------------------------------------------------------*/
  71. void CUIFToolbarButtonElement::OnLButtonUp( POINT pt )
  72. {
  73. CUIFButton2::OnLButtonUp(pt);
  74. if (_pTBButton->IsMenuOnly())
  75. _pTBButton->OnShowMenu();
  76. else
  77. _pTBButton->OnLeftClick();
  78. }
  79. /*------------------------------------------------------------------------------
  80. OnRbuttonUp
  81. ------------------------------------------------------------------------------*/
  82. void CUIFToolbarButtonElement::OnRButtonUp( POINT pt )
  83. {
  84. if (!_pTBButton->IsMenuOnly())
  85. _pTBButton->OnRightClick();
  86. CUIFButton2::OnRButtonUp(pt);
  87. }
  88. /*------------------------------------------------------------------------------
  89. OnSetCursor
  90. ------------------------------------------------------------------------------*/
  91. BOOL CUIFToolbarButtonElement::OnSetCursor( UINT uMsg, POINT pt )
  92. {
  93. _pTBButton->OnSetCursor(uMsg, pt);
  94. return FALSE;
  95. }
  96. /*------------------------------------------------------------------------------
  97. OnSetCursor
  98. ------------------------------------------------------------------------------*/
  99. LPCWSTR CUIFToolbarButtonElement::GetToolTip( void )
  100. {
  101. if (_pTBButton)
  102. return _pTBButton->GetToolTip();
  103. return NULL;
  104. }
  105. /*=============================================================================*/
  106. /* */
  107. /* C U I B U T T O N */
  108. /* */
  109. /*=============================================================================*/
  110. /*------------------------------------------------------------------------------
  111. ctor
  112. ------------------------------------------------------------------------------*/
  113. CUIFToolbarMenuButton::CUIFToolbarMenuButton( CUIFToolbarButton *pParent, DWORD dwID, RECT *prc, DWORD dwStyle) : CUIFButton2( pParent, dwID, prc, dwStyle )
  114. {
  115. _pTBButton = pParent;
  116. HFONT hfont = CreateFont(8, 8, 0, 0, 400, FALSE, FALSE, FALSE, SYMBOL_CHARSET, 0, 0, 0, 0, "Marlett");
  117. SetFont(hfont);
  118. SetText(L"u");
  119. }
  120. /*------------------------------------------------------------------------------
  121. dtor
  122. ------------------------------------------------------------------------------*/
  123. CUIFToolbarMenuButton::~CUIFToolbarMenuButton( void )
  124. {
  125. HFONT hfontOld = GetFont();
  126. DeleteObject(hfontOld);
  127. SetFont((HFONT)NULL);
  128. }
  129. #if 0
  130. /*------------------------------------------------------------------------------
  131. OnPaint
  132. ------------------------------------------------------------------------------*/
  133. void CUIFToolbarMenuButton::OnPaint( HDC hDC )
  134. {
  135. BOOL fDownFace;
  136. // erase face at first
  137. FillRect( hDC, &GetRectRef(), (HBRUSH)(COLOR_3DFACE + 1) );
  138. #ifndef UNDER_CE
  139. if (m_fToggled && (m_dwStatus == UIBUTTON_NORMAL || m_dwStatus == UIBUTTON_DOWNOUT)) {
  140. RECT rc;
  141. HBRUSH hBrush = CreateDitherBrush();
  142. COLORREF colTextOld = SetTextColor( hDC, GetSysColor(COLOR_3DFACE) );
  143. COLORREF colBackOld = SetBkColor( hDC, GetSysColor(COLOR_3DHILIGHT) );
  144. rc = GetRectRef();
  145. InflateRect( &rc, -2, -2 );
  146. FillRect( hDC, &rc, hBrush );
  147. SetTextColor( hDC, colTextOld );
  148. SetBkColor( hDC, colBackOld );
  149. DeleteObject( hBrush );
  150. }
  151. #endif /* !UNDER_CE */
  152. // draw face
  153. fDownFace = m_fToggled || (m_dwStatus == UIBUTTON_DOWN);
  154. RECT rcDnArrow;
  155. int nDownPad = fDownFace ? 1 : 0;
  156. rcDnArrow = GetRectRef();
  157. OffsetRect(&rcDnArrow, nDownPad, nDownPad);
  158. DrawDownTri(hDC, &rcDnArrow);
  159. // draw button edge
  160. if (m_fToggled) {
  161. DrawEdgeProc( hDC, &GetRectRef(), TRUE );
  162. } else {
  163. switch (m_dwStatus) {
  164. case UIBUTTON_DOWN: {
  165. DrawEdgeProc( hDC, &GetRectRef(), TRUE );
  166. break;
  167. }
  168. case UIBUTTON_HOVER:
  169. case UIBUTTON_DOWNOUT: {
  170. DrawEdgeProc( hDC, &GetRectRef(), FALSE );
  171. break;
  172. }
  173. }
  174. }
  175. }
  176. #endif
  177. /*------------------------------------------------------------------------------
  178. OnPaint
  179. ------------------------------------------------------------------------------*/
  180. void CUIFToolbarMenuButton::OnLButtonUp( POINT pt )
  181. {
  182. CUIFButton2::OnLButtonUp(pt);
  183. _pTBButton->OnShowMenu();
  184. }
  185. /*------------------------------------------------------------------------------
  186. OnPaint
  187. ------------------------------------------------------------------------------*/
  188. BOOL CUIFToolbarMenuButton::OnSetCursor( UINT uMsg, POINT pt )
  189. {
  190. _pTBButton->OnSetCursor(uMsg, pt);
  191. return FALSE;
  192. }
  193. /*=============================================================================*/
  194. /* */
  195. /* C U I B U T T O N */
  196. /* */
  197. /*=============================================================================*/
  198. /*------------------------------------------------------------------------------
  199. ctor
  200. ------------------------------------------------------------------------------*/
  201. CUIFToolbarButton::CUIFToolbarButton( CUIFObject *pParent, DWORD dwID, RECT *prc, DWORD dwStyle, DWORD dwSBtnStyle, DWORD dwSBtnShowType) : CUIFObject( pParent, dwID, prc, dwStyle )
  202. {
  203. m_dwSBtnStyle = dwSBtnStyle;
  204. m_dwSBtnShowType = dwSBtnShowType;
  205. }
  206. BOOL CUIFToolbarButton::Init()
  207. {
  208. RECT rc;
  209. RECT rcMenuBtn;
  210. rcMenuBtn =
  211. rc = GetRectRef();
  212. if (IsMenuButton())
  213. {
  214. rc.right -= 12;
  215. rcMenuBtn.left = rc.right + 1;
  216. }
  217. _pBtn = new CUIFToolbarButtonElement(this, GetID(), &rc,
  218. UIBUTTON_FITIMAGE |
  219. UIBUTTON_VCENTER |
  220. UIBUTTON_CENTER |
  221. (IsToggle() ? UIBUTTON_TOGGLE : 0) |
  222. (IsVertical() ? UIBUTTON_VERTICAL : 0));
  223. if (!_pBtn)
  224. return FALSE;
  225. _pBtn->Initialize();
  226. AddUIObj( _pBtn );
  227. if (!IsEnabled())
  228. _pBtn->Enable(FALSE);
  229. if (IsMenuButton())
  230. {
  231. _pMenuBtn = new CUIFToolbarMenuButton(this,
  232. 0,
  233. &rcMenuBtn,
  234. UIBUTTON_VCENTER |
  235. UIBUTTON_CENTER |
  236. (IsVertical() ? UIBUTTON_VERTICAL : 0));
  237. if (!_pMenuBtn)
  238. return FALSE;
  239. _pMenuBtn->Initialize();
  240. AddUIObj( _pMenuBtn );
  241. if (!IsEnabled())
  242. _pMenuBtn->Enable(FALSE);
  243. }
  244. return TRUE;
  245. }
  246. /*------------------------------------------------------------------------------
  247. dtor
  248. ------------------------------------------------------------------------------*/
  249. CUIFToolbarButton::~CUIFToolbarButton( void )
  250. {
  251. }
  252. /*------------------------------------------------------------------------------
  253. SetShowType
  254. ------------------------------------------------------------------------------*/
  255. void CUIFToolbarButton::SetShowType(DWORD dwSBtnShowType)
  256. {
  257. m_dwSBtnShowType = dwSBtnShowType;
  258. }
  259. /*------------------------------------------------------------------------------
  260. SetRect
  261. ------------------------------------------------------------------------------*/
  262. void CUIFToolbarButton::SetRect( const RECT *prc )
  263. {
  264. RECT rc;
  265. RECT rcMenuBtn;
  266. CUIFObject::SetRect(prc);
  267. rcMenuBtn =
  268. rc = GetRectRef();
  269. if (IsMenuButton())
  270. {
  271. rc.right -= 12;
  272. rcMenuBtn.left = rc.right + 1;
  273. }
  274. if (_pBtn)
  275. {
  276. _pBtn->SetRect(&rc);
  277. }
  278. if (_pMenuBtn)
  279. {
  280. _pMenuBtn->SetRect(&rcMenuBtn);
  281. }
  282. }
  283. void CUIFToolbarButton::Enable( BOOL fEnable )
  284. {
  285. CUIFObject::Enable(fEnable);
  286. if (_pBtn)
  287. _pBtn->Enable(fEnable);
  288. if (_pMenuBtn)
  289. _pMenuBtn->Enable(fEnable);
  290. }
  291. void CUIFToolbarButton::SetIcon( HICON hIcon )
  292. {
  293. Assert(PtrToInt(_pBtn));
  294. _pBtn->SetIcon(hIcon);
  295. }
  296. HICON CUIFToolbarButton::GetIcon( )
  297. {
  298. Assert(PtrToInt(_pBtn));
  299. return _pBtn->GetIcon();
  300. }
  301. void CUIFToolbarButton::SetBitmap( HBITMAP hBmp )
  302. {
  303. Assert(PtrToInt(_pBtn));
  304. _pBtn->SetBitmap(hBmp);
  305. }
  306. HBITMAP CUIFToolbarButton::GetBitmap( )
  307. {
  308. Assert(PtrToInt(_pBtn));
  309. return _pBtn->GetBitmap();
  310. }
  311. void CUIFToolbarButton::SetBitmapMask( HBITMAP hBmp )
  312. {
  313. Assert(PtrToInt(_pBtn));
  314. _pBtn->SetBitmapMask(hBmp);
  315. }
  316. HBITMAP CUIFToolbarButton::GetBitmapMask( )
  317. {
  318. Assert(PtrToInt(_pBtn));
  319. return _pBtn->GetBitmapMask();
  320. }
  321. void CUIFToolbarButton::SetText( WCHAR *psz)
  322. {
  323. Assert(PtrToInt(_pBtn));
  324. _pBtn->SetText(psz);
  325. }
  326. void CUIFToolbarButton::SetFont( HFONT hFont)
  327. {
  328. Assert(PtrToInt(_pBtn));
  329. _pBtn->SetFont(hFont);
  330. }
  331. void CUIFToolbarButton::SetToolTip( LPCWSTR pwchToolTip )
  332. {
  333. CUIFObject::SetToolTip(pwchToolTip);
  334. if (_pBtn)
  335. _pBtn->SetToolTip(pwchToolTip);
  336. if (_pMenuBtn)
  337. _pMenuBtn->SetToolTip(pwchToolTip);
  338. }
  339. LPCWSTR CUIFToolbarButton::GetToolTip( void )
  340. {
  341. return CUIFObject::GetToolTip();
  342. }
  343. BOOL CUIFToolbarButton::IsMenuOnly()
  344. {
  345. return ((m_dwSBtnStyle & (UITBBUTTON_BUTTON | UITBBUTTON_MENU)) == UITBBUTTON_MENU);
  346. }
  347. BOOL CUIFToolbarButton::IsMenuButton()
  348. {
  349. return ((m_dwSBtnStyle & (UITBBUTTON_BUTTON | UITBBUTTON_MENU)) == (UITBBUTTON_BUTTON | UITBBUTTON_MENU));
  350. }
  351. BOOL CUIFToolbarButton::IsButtonOnly()
  352. {
  353. return ((m_dwSBtnStyle & (UITBBUTTON_BUTTON | UITBBUTTON_MENU)) == (UITBBUTTON_BUTTON));
  354. }
  355. BOOL CUIFToolbarButton::IsToggle()
  356. {
  357. return (m_dwSBtnStyle & UITBBUTTON_TOGGLE) ? TRUE : FALSE;
  358. }
  359. BOOL CUIFToolbarButton::IsVertical()
  360. {
  361. return (m_dwSBtnStyle & UITBBUTTON_VERTICAL) ? TRUE : FALSE;
  362. }
  363. void CUIFToolbarButton::DetachWndObj( void )
  364. {
  365. if (_pBtn)
  366. _pBtn->DetachWndObj();
  367. if (_pMenuBtn)
  368. _pMenuBtn->DetachWndObj();
  369. #ifdef DEBUG
  370. if (m_pUIWnd && m_pUIWnd->GetCaptureObject())
  371. {
  372. Assert(m_pUIWnd->GetCaptureObject() != _pBtn);
  373. Assert(m_pUIWnd->GetCaptureObject() != _pMenuBtn);
  374. Assert(m_pUIWnd->GetCaptureObject() != this);
  375. }
  376. #endif
  377. CUIFObject::DetachWndObj();
  378. }
  379. //////////////////////////////////////////////////////////////////////////////
  380. //
  381. // CUIFSeparator
  382. //
  383. //////////////////////////////////////////////////////////////////////////////
  384. //+---------------------------------------------------------------------------
  385. //
  386. // OnPaint
  387. //
  388. //----------------------------------------------------------------------------
  389. BOOL CUIFSeparator::OnPaintTheme(HDC hDC)
  390. {
  391. BOOL fRet = FALSE;
  392. int iStateID;
  393. iStateID = TS_NORMAL;
  394. if (FAILED(EnsureThemeData( GetUIWnd()->GetWnd())))
  395. goto Exit;
  396. if (FAILED(DrawThemeBackground(hDC, iStateID, &GetRectRef(), 0 )))
  397. goto Exit;
  398. fRet = TRUE;
  399. Exit:
  400. return fRet;
  401. }
  402. //+---------------------------------------------------------------------------
  403. //
  404. // OnPaintNoTheme
  405. //
  406. //----------------------------------------------------------------------------
  407. void CUIFSeparator::OnPaintNoTheme(HDC hDC)
  408. {
  409. CUIFWindow *pWnd = GetUIWnd();
  410. CUIFScheme *pUIFScheme = pWnd->GetUIFScheme();
  411. if (pUIFScheme) {
  412. pUIFScheme->DrawSeparator(hDC, &GetRectRef(), IsVertical());
  413. return;
  414. }
  415. CSolidPen hpenL;
  416. CSolidPen hpenS;
  417. HPEN hpenOld = NULL;
  418. if (!hpenL.Init(GetSysColor(COLOR_3DHILIGHT)))
  419. return;
  420. if (!hpenS.Init(GetSysColor(COLOR_3DSHADOW)))
  421. return;
  422. if (!IsVertical())
  423. {
  424. hpenOld = (HPEN)SelectObject(hDC, (HPEN)hpenS);
  425. MoveToEx(hDC, GetRectRef().left + 1, GetRectRef().top, NULL);
  426. LineTo(hDC, GetRectRef().left + 1, GetRectRef().bottom);
  427. SelectObject(hDC, (HPEN)hpenL);
  428. MoveToEx(hDC, GetRectRef().left + 2, GetRectRef().top, NULL);
  429. LineTo(hDC, GetRectRef().left + 2, GetRectRef().bottom);
  430. }
  431. else
  432. {
  433. hpenOld = (HPEN)SelectObject(hDC, (HPEN)hpenS);
  434. MoveToEx(hDC, GetRectRef().left , GetRectRef().top + 1, NULL);
  435. LineTo(hDC, GetRectRef().right, GetRectRef().top + 1);
  436. SelectObject(hDC, (HPEN)hpenL);
  437. MoveToEx(hDC, GetRectRef().left , GetRectRef().top + 2, NULL);
  438. LineTo(hDC, GetRectRef().right, GetRectRef().top + 2);
  439. }
  440. SelectObject(hDC, hpenOld);
  441. }