PagePopupMenus.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:30k
源码类别:

界面编程

开发平台:

Visual C++

  1. // PagePopupMenus.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "profuis_controls.h"
  5. #include "PagePopupMenus.h"
  6. #include <Resources/Resource.h>
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPagePopupMenus dialog
  14. CPagePopupMenus::CPagePopupMenus(CWnd* pParent /*=NULL*/)
  15. : CPageBase(CPagePopupMenus::IDD, pParent)
  16. , m_bInitComplete( false )
  17. {
  18. //{{AFX_DATA_INIT(CPagePopupMenus)
  19. // NOTE: the ClassWizard will add member initialization here
  20. //}}AFX_DATA_INIT
  21. }
  22. void CPagePopupMenus::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CPageBase::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CPagePopupMenus)
  26. DDX_Control(pDX, IDC_CHECK_USE_ACCELERATED_MENU_SCROLLING, m_checkUseAcceleratedMenuScrolling);
  27. DDX_Control(pDX, IDC_EDIT_INCREASE_PERCENT, m_editIncreasePercent);
  28. DDX_Control(pDX, IDC_EDIT_INCREASE_STEP, m_editIncreaseStep);
  29. DDX_Control(pDX, IDC_EDIT_LONG_COUNT_OF_ITEMS, m_editCountOfItems);
  30. DDX_Control(pDX, IDC_EDIT_MAX_PIXELS_PER_STEP, m_editMaxPixelsPerStep);
  31. DDX_Control(pDX, IDC_SPIN_INCREASE_PERCENT, m_spinIncreasePercent);
  32. DDX_Control(pDX, IDC_SPIN_INCREASE_STEP, m_spinIncreaseStep);
  33. DDX_Control(pDX, IDC_SPIN_LONG_COUNT_OF_ITEMS, m_spinCountOfItems);
  34. DDX_Control(pDX, IDC_SPIN_MAX_PIXELS_PER_STEP, m_spinMaxPixelsPerStep);
  35. DDX_Control(pDX, IDC_STATIC_INCREASE_PERCENT, m_labelIncreasePercent);
  36. DDX_Control(pDX, IDC_STATIC_INCREASE_STEP, m_labelIncreaseStep);
  37. DDX_Control(pDX, IDC_STATIC_LONG_COUNT_OF_ITEMS, m_labelCountOfItems);
  38. DDX_Control(pDX, IDC_STATIC_MAX_PIXELS_PER_STEP, m_labelMaxPixelsPerStep);
  39. DDX_Control(pDX, IDC_STATIC_LONG_SUB_MENU_SETTINGS, m_groupBoxLongSubMenuSettings);
  40. DDX_Control(pDX, IDC_STATIC1, m_Static1);
  41. DDX_Control(pDX, IDC_CHECK_MENU_WITH_SHADOWS, m_chkMenuWithShadows);
  42. DDX_Control(pDX, IDC_CHECK_MENU_ANIMATION, m_chkMenuAnimation);
  43. DDX_Control(pDX, IDC_CHECK_PALETTE_WITH_CUSTOM_DRAWN_BACKGROUND, m_chkPaletteWithCustomDrawnBackground);
  44. DDX_Control(pDX, IDC_STATIC_MENU_ANIMATION, m_groupBoxMenuAnimation);
  45. DDX_Control(pDX, IDC_MENU_ANIMATION, m_MenuAnimation);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CPagePopupMenus, CPageBase)
  49. //{{AFX_MSG_MAP(CPagePopupMenus)
  50. ON_CBN_SELENDOK(IDC_MENU_ANIMATION, OnSelendokMenuAnimation)
  51. ON_BN_CLICKED(IDC_CHECK_MENU_ANIMATION, OnCheckMenuAnimation)
  52. ON_BN_CLICKED(IDC_CHECK_MENU_WITH_SHADOWS, OnCheckMenuWithShadows)
  53. ON_WM_CONTEXTMENU()
  54. ON_BN_CLICKED(IDC_CHECK_USE_ACCELERATED_MENU_SCROLLING, OnCheckUseAcceleratedMenuScrolling)
  55. ON_EN_CHANGE(IDC_EDIT_INCREASE_PERCENT, OnChangeEditIncreasePercent)
  56. ON_EN_CHANGE(IDC_EDIT_INCREASE_STEP, OnChangeEditIncreaseStep)
  57. ON_EN_CHANGE(IDC_EDIT_MAX_PIXELS_PER_STEP, OnChangeEditMaxPixelsPerStep)
  58. //}}AFX_MSG_MAP
  59. ON_REGISTERED_MESSAGE(
  60. CExtPopupMenuWnd::g_nMsgPrepareMenu,
  61. OnExtMenuPrepare
  62. )
  63. ON_REGISTERED_MESSAGE(
  64. CExtPopupMenuWnd::g_nMsgPopupDrawBackground,
  65. OnExtMenuDrawBackground
  66. )
  67. ON_REGISTERED_MESSAGE(
  68. CExtPopupMenuWnd::g_nMsgPopupDrawItem,
  69. OnDrawPopupMenuItem
  70. )
  71. ON_REGISTERED_MESSAGE(
  72. CExtPopupMenuWnd::g_nMsgPopupDrawLeftArea,
  73. OnDrawPopupLeftArea
  74. )
  75. #if (!defined __EXT_MFC_NO_DATE_PICKER)
  76. ON_REGISTERED_MESSAGE(CExtDatePickerWnd::g_nMsgSelectionNotification, OnMsgSelectionNotification)
  77. #endif // #if (!defined __EXT_MFC_NO_DATE_PICKER)
  78. // color popup menu
  79. ON_REGISTERED_MESSAGE(
  80. CExtPopupColorMenuWnd::g_nMsgNotifyColorChangedFinally,
  81. OnColorChangedFinally
  82. )
  83. ON_REGISTERED_MESSAGE(
  84. CExtPopupColorMenuWnd::g_nMsgNotifyCustColor,
  85. OnColorSelectCustom
  86. )
  87. ON_COMMAND( IDC_MENU_ITEM_RARELY1, OnMenuRarelyItem1 )
  88. ON_UPDATE_COMMAND_UI( IDC_MENU_ITEM_RARELY1, OnUpdateMenuRarelyItem1 )
  89. ON_COMMAND( IDC_MENU_ITEM_RARELY2, OnMenuRarelyItem2 )
  90. ON_UPDATE_COMMAND_UI( IDC_MENU_ITEM_RARELY2, OnUpdateMenuRarelyItem2 )
  91. ON_COMMAND( IDC_MENU_ITEM_RARELY3, OnMenuRarelyItem3 )
  92. ON_UPDATE_COMMAND_UI( IDC_MENU_ITEM_RARELY3, OnUpdateMenuRarelyItem3 )
  93. END_MESSAGE_MAP()
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CPagePopupMenus message handlers
  96. BOOL CPagePopupMenus::OnInitDialog() 
  97. {
  98. CPageBase::OnInitDialog();
  99. m_Static1.SetFontBold( true );
  100. m_chkPaletteWithCustomDrawnBackground.SetCheck( 1 );
  101. AddAnchor( IDC_STATIC1, CSize(50,0), CSize(50,0) );
  102. m_groupBoxMenuAnimation.SetStyle( CExtGroupBox::STYLE_FLAT );
  103. m_groupBoxLongSubMenuSettings.SetStyle( CExtGroupBox::STYLE_FLAT );
  104. m_chkMenuWithShadows.SetCheck( BST_CHECKED );
  105. OnCheckMenuWithShadows();
  106. m_chkMenuAnimation.SetCheck( BST_CHECKED );
  107. OnCheckMenuAnimation();
  108. int nIndex = -1, nInitSel = -1;
  109. nIndex = m_MenuAnimation.AddString( _T("(none)") );
  110. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_NONE );
  111. nIndex = m_MenuAnimation.AddString( _T("Random select") );
  112. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_RANDOM);
  113. nIndex = m_MenuAnimation.AddString( _T("Roll") );
  114. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_ROLL);
  115. nIndex = m_MenuAnimation.AddString( _T("Slide") );
  116. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_SLIDE);
  117. nInitSel = nIndex = m_MenuAnimation.AddString( _T("Fade") );
  118. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_FADE);
  119. nIndex = m_MenuAnimation.AddString( _T("Roll and stretch") );
  120. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_ROLL_AND_STRETCH);
  121. nIndex = m_MenuAnimation.AddString( _T("Slide and stretch") );
  122. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_SLIDE_AND_STRETCH);
  123. nIndex = m_MenuAnimation.AddString( _T("Noise") );
  124. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_NOISE);
  125. nIndex = m_MenuAnimation.AddString( _T("Boxes") );
  126. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_BOXES);
  127. nIndex = m_MenuAnimation.AddString( _T("Circles") );
  128. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_CIRCLES);
  129. nIndex = m_MenuAnimation.AddString( _T("Holes") );
  130. m_MenuAnimation.SetItemData( nIndex, CExtPopupMenuWnd::__AT_HOLES);
  131. m_editCountOfItems.SetWindowText( _T("100") );
  132. CString strTmp;
  133. strTmp.Format( _T("%d"), CExtPopupMenuWnd::g_nAcceleratedIncreasePercent );
  134. m_editIncreasePercent.SetWindowText( LPCTSTR(strTmp) );
  135. strTmp.Format( _T("%d"), CExtPopupMenuWnd::g_nAcceleratedIncreaseStep );
  136. m_editIncreaseStep.SetWindowText( LPCTSTR(strTmp) );
  137. strTmp.Format( _T("%d"), CExtPopupMenuWnd::g_nAcceleratedPixelsPerStepMax );
  138. m_editMaxPixelsPerStep.SetWindowText( LPCTSTR(strTmp) );
  139. m_MenuAnimation.SetCurSel( nInitSel );
  140. m_bInitComplete = true;
  141. return TRUE;  // return TRUE unless you set the focus to a control
  142.               // EXCEPTION: OCX Property Pages should return FALSE
  143. }
  144. void CPagePopupMenus::OnSelendokMenuAnimation() 
  145. {
  146. int nCurSel = m_MenuAnimation.GetCurSel();
  147. CExtPopupMenuWnd::g_DefAnimationType =
  148. (CExtPopupMenuWnd::e_animation_type_t)m_MenuAnimation.GetItemData( nCurSel );
  149. }
  150. void CPagePopupMenus::OnCheckMenuAnimation() 
  151. {
  152. CExtPopupMenuWnd::g_bMenuExpandAnimation =
  153. m_chkMenuAnimation.GetCheck() ?
  154. true : false;
  155. }
  156. void CPagePopupMenus::OnCheckMenuWithShadows() 
  157. {
  158. CExtPopupMenuWnd::g_bMenuWithShadows =
  159. m_chkMenuWithShadows.GetCheck() ?
  160. true : false;
  161. }
  162. void CPagePopupMenus::OnContextMenu(CWnd* pWnd, CPoint point) 
  163. {
  164. pWnd;
  165. CMenu _menu;
  166. if( _menu.GetSafeHmenu() == NULL )
  167. {
  168. if( !_menu.LoadMenu(IDR_POPUP_MENU) )
  169. {
  170. ASSERT( FALSE );
  171. return;
  172. }
  173. }
  174. CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
  175. pPopup->SetLeftAreaWidth( 30 );
  176. pPopup->UpdateFromMenu(
  177. GetSafeHwnd(),
  178. &_menu
  179. );
  180. // MAKING "About" menu item default
  181. INT nDefaultItemPos =
  182. pPopup->ItemFindPosForCmdID(ID_APP_ABOUT);
  183. if( nDefaultItemPos >= 0 )
  184. pPopup->ItemDefaultSet(nDefaultItemPos);
  185. INT nReplacePos =
  186. pPopup->ItemFindPosForCmdID( ID_COLOR_CTRL_8X5 );
  187. if( nReplacePos >= 0 )
  188. {
  189. CExtPopupColorMenuWnd * pColorPopup = new CExtPopupColorMenuWnd;
  190. pColorPopup->m_lParamCookie = LPARAM( ID_COLOR_CTRL_8X5 );
  191. pColorPopup->m_hWndNotifyColorChanged = GetSafeHwnd();
  192. pColorPopup->m_clrDefault = COLORREF(-1);
  193. //pColorPopup->m_clrInitial = ;
  194. VERIFY(
  195. pPopup->ItemInsertSpecPopup(
  196. pColorPopup,
  197. nReplacePos + 1,
  198. pPopup->ItemGetText(nReplacePos),
  199. pPopup->ItemGetIcon(nReplacePos)
  200. )
  201. );
  202. pPopup->ItemSetDisplayed( nReplacePos + 1, true );
  203. VERIFY( pPopup->ItemRemove(nReplacePos) );
  204. // // set check mark on popup item
  205. // pPopup->ItemGetInfo(nReplacePos).Check( true );
  206. } // if( nReplacePos >= 0 )
  207. nReplacePos =
  208. pPopup->ItemFindPosForCmdID( ID_COLOR_CTRL_8X2 );
  209. if( nReplacePos >= 0 )
  210. {
  211. CExtPopupColorMenuWnd * pColorPopup = new CExtPopupColorMenuWnd;
  212. pColorPopup->m_lParamCookie = LPARAM( ID_COLOR_CTRL_8X2 );
  213. pColorPopup->m_hWndNotifyColorChanged = GetSafeHwnd();
  214. pColorPopup->m_clrDefault = COLORREF(-1);
  215. pColorPopup->SetColors8x2();
  216. VERIFY(
  217. pPopup->ItemInsertSpecPopup(
  218. pColorPopup,
  219. nReplacePos + 1,
  220. pPopup->ItemGetText(nReplacePos),
  221. pPopup->ItemGetIcon(nReplacePos)
  222. )
  223. );
  224. pPopup->ItemSetDisplayed( nReplacePos + 1, true );
  225. VERIFY( pPopup->ItemRemove(nReplacePos) );
  226. } // if( nReplacePos >= 0 )
  227. nReplacePos =
  228. pPopup->ItemFindPosForCmdID( ID_COLOR_CTRL_GRAYSCALE );
  229. if( nReplacePos >= 0 )
  230. {
  231. CExtPopupColorMenuWnd * pColorPopup = new CExtPopupColorMenuWnd;
  232. pColorPopup->m_lParamCookie = LPARAM( ID_COLOR_CTRL_GRAYSCALE );
  233. pColorPopup->m_hWndNotifyColorChanged = GetSafeHwnd();
  234. pColorPopup->m_clrDefault = COLORREF(-1);
  235. pColorPopup->RemoveAllColors();
  236. int nGrayColors = 16;
  237. pColorPopup->SetColorsInRow( nGrayColors );
  238. pColorPopup->m_sizeColorItemCell.cy *= 2;
  239. for( int nColorIndex = 0; nColorIndex < nGrayColors; nColorIndex++ )
  240. {
  241. double f = double( nColorIndex ) / double( nGrayColors - 1 );
  242. COLORREF clr = CExtBitmap::stat_HLStoRGB( 0.0, f, 0.0 );
  243. int n = GetRValue(clr);
  244. CExtSafeString str;
  245. str.Format(
  246. _T("#%02X%02X%02X"),
  247. n,
  248. n,
  249. n
  250. );
  251. pColorPopup->AddColor(
  252. new CExtPopupColorMenuWnd::COLORREF_TABLE_ENTRY(
  253. 0,
  254. clr,
  255. str
  256. )
  257. );
  258. }
  259. VERIFY(
  260. pPopup->ItemInsertSpecPopup(
  261. pColorPopup,
  262. nReplacePos + 1,
  263. pPopup->ItemGetText(nReplacePos),
  264. pPopup->ItemGetIcon(nReplacePos)
  265. )
  266. );
  267. pPopup->ItemSetDisplayed( nReplacePos + 1, true );
  268. VERIFY( pPopup->ItemRemove(nReplacePos) );
  269. } // if( nReplacePos >= 0 )
  270. nReplacePos =
  271. pPopup->ItemFindPosForCmdID( ID_COLOR_CTRL_HLS );
  272. if( nReplacePos >= 0 )
  273. {
  274. CExtPopupColorMenuWnd * pColorPopup = new CExtPopupColorMenuWnd;
  275. pColorPopup->m_lParamCookie = LPARAM( ID_COLOR_CTRL_HLS );
  276. pColorPopup->m_hWndNotifyColorChanged = GetSafeHwnd();
  277. pColorPopup->m_clrDefault = COLORREF(-1);
  278. pColorPopup->RemoveAllColors();
  279. int nStepsHue = 12;
  280. int nStepsSat = 8;
  281. pColorPopup->m_sizeColorItemCell.cx = 14;
  282. pColorPopup->m_sizeColorItemCell.cy = 12;
  283. pColorPopup->m_sizeColorItemSpaces.cx = 1;
  284. pColorPopup->m_sizeColorItemSpaces.cy = 1;
  285. pColorPopup->SetColorsInRow( nStepsHue );
  286. for( int nSat = 0; nSat < nStepsSat; nSat++ )
  287. {
  288. double fSat = 1.0 - double( nSat ) / double( nStepsSat );
  289. for( int nHue = 0; nHue < nStepsHue; nHue++ )
  290. {
  291. double fHue = double( nHue ) / double( nStepsHue );
  292. COLORREF clr = CExtBitmap::stat_HLStoRGB( fHue, 0.5, fSat );
  293. CExtSafeString str;
  294. str.Format(
  295. _T("#%02X%02X%02X"),
  296. GetRValue(clr),
  297. GetGValue(clr),
  298. GetBValue(clr)
  299. );
  300. pColorPopup->AddColor(
  301. new CExtPopupColorMenuWnd::COLORREF_TABLE_ENTRY(
  302. 0,
  303. clr,
  304. str
  305. )
  306. );
  307. }
  308. }
  309. VERIFY(
  310. pPopup->ItemInsertSpecPopup(
  311. pColorPopup,
  312. nReplacePos + 1,
  313. pPopup->ItemGetText(nReplacePos),
  314. pPopup->ItemGetIcon(nReplacePos)
  315. )
  316. );
  317. pPopup->ItemSetDisplayed( nReplacePos + 1, true );
  318. VERIFY( pPopup->ItemRemove(nReplacePos) );
  319. } // if( nReplacePos >= 0 )
  320. #if (!defined __EXT_MFC_NO_DATE_PICKER)
  321. nReplacePos =
  322. pPopup->ItemFindPosForCmdID(ID_DATE_PICKER_CTRL);
  323. if( nReplacePos >= 0 )
  324. {
  325. CExtPopupControlMenuWnd::g_bControlMenuWithShadows = true;
  326. CExtPopupDatePickerMenuWnd * pDatePickerPopup = 
  327. new CExtPopupDatePickerMenuWnd(
  328. 0L,
  329. CSize(1,1),
  330. WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN,
  331. __EDPWS_DEFAULT|__EDPWS_MULTIPLE_SELECTION
  332. );
  333. VERIFY(
  334. pPopup->ItemInsertSpecPopup(
  335. pDatePickerPopup,
  336. nReplacePos + 1,
  337. pPopup->ItemGetText(nReplacePos),
  338. pPopup->ItemGetIcon(nReplacePos)
  339. )
  340. );
  341. pPopup->ItemSetDisplayed( nReplacePos + 1, true );
  342. VERIFY( pPopup->ItemRemove(nReplacePos) );
  343. } // if( nReplacePos >= 0 )
  344. #endif // #if (!defined __EXT_MFC_NO_DATE_PICKER)
  345. if( ! pPopup->ItemInsert(
  346. UINT(CExtPopupMenuWnd::TYPE_POPUP),
  347. -1,
  348. _T("Long sub-menu")
  349. )
  350. )
  351. {
  352. ASSERT( FALSE );
  353. delete pPopup;
  354. }
  355. CExtPopupMenuWnd * pLongSubMenu =
  356. pPopup->ItemGetPopup(
  357. pPopup->ItemGetCount() - 1
  358. );
  359. ASSERT_VALID( pLongSubMenu );
  360. CString strCountOfItems;
  361. m_editCountOfItems.GetWindowText( strCountOfItems );
  362. INT nIongIndex, nLongCount;
  363. nLongCount = INT( _ttol( LPCTSTR( strCountOfItems ) ) );
  364. if( nLongCount < 0 )
  365. {
  366. nLongCount = 0;
  367. strCountOfItems.Format( _T("%d"), nLongCount );
  368. m_editCountOfItems.SetWindowText( LPCTSTR(strCountOfItems) );
  369. } // if( nLongCount < 0 )
  370. else if( nLongCount > 400 )
  371. {
  372. nLongCount = 400;
  373. strCountOfItems.Format( _T("%d"), nLongCount );
  374. m_editCountOfItems.SetWindowText( LPCTSTR(strCountOfItems) );
  375. } // else if( nLongCount > 400 )
  376. for( nIongIndex = 0; nIongIndex < nLongCount; nIongIndex++ )
  377. {
  378. UINT nCmdID = UINT(nIongIndex)+UINT(14*1000);
  379. CString strLongCommandName;
  380. strLongCommandName.Format(
  381. _T("Item %d"),
  382. nIongIndex + 1
  383. );
  384. pLongSubMenu->ItemInsertCommand(
  385. nCmdID,
  386. -1,
  387. LPCTSTR(strLongCommandName)
  388. );
  389. } // for( nIongIndex = 0; nIongIndex < nLongCount; nIongIndex++ )
  390. if( ! pPopup->TrackPopupMenu( TPMX_OWNERDRAW_FIXED, point.x, point.y ) )
  391. delete pPopup;
  392. }
  393. //////////////////////////////////////////////////////////////////////////
  394. //////////////////////////////////////////////////////////////////////////
  395. LRESULT CPagePopupMenus::OnDrawPopupLeftArea(WPARAM wParam, LPARAM lParam)
  396. {
  397. wParam;
  398. CExtPopupMenuWnd::DRAWLEFTAREADATA * pDrawLeftAreaData =
  399. reinterpret_cast < CExtPopupMenuWnd::DRAWLEFTAREADATA * > ( lParam );
  400. ASSERT( pDrawLeftAreaData != NULL );
  401. ASSERT( pDrawLeftAreaData->m_pPopup != NULL );
  402. if( (pDrawLeftAreaData->m_pPopup->TrackFlagsGet()&TPMX_PALETTE) != 0 )
  403. return 0;
  404. // get draw DC
  405. CDC & dc = *( (CDC *) *pDrawLeftAreaData );
  406. CRect rcItem = LPCRECT(*pDrawLeftAreaData);
  407. CExtPaintManager::stat_PaintGradientRect(
  408. dc,
  409. &rcItem,
  410. dc.GetNearestColor( RGB( 0, 0, 0 ) ),
  411. dc.GetNearestColor( RGB( 100, 100, 255 ) ),
  412. true
  413. );
  414. LOGFONT lf;
  415. ::memset(&lf,0,sizeof(LOGFONT));
  416. g_PaintManager->m_FontNormalVertX.GetLogFont( &lf );
  417. lf.lfHeight = -18;
  418. lf.lfWidth = 0;
  419. lf.lfWeight = 900;
  420. __EXT_MFC_STRCPY( lf.lfFaceName, LF_FACESIZE, _T("Times New Roman") );
  421. CFont font;
  422. VERIFY(
  423. font.CreateFontIndirect(&lf)
  424. );
  425. CFont * pOldFont = dc.SelectObject( &font );
  426. INT nOldBkMode = dc.SetBkMode( TRANSPARENT );
  427. COLORREF clrOldText = dc.SetTextColor( RGB( 0, 0, 0 ) );
  428. static CString sTitle( _T("Prof-UIS") );
  429. CPoint ptText( rcItem.left+4, rcItem.bottom-5 );
  430. dc.DrawState(
  431. ptText, rcItem.Size(), (LPCTSTR)sTitle,
  432. DSS_NORMAL,  TRUE, 0, (CBrush*)NULL
  433. );
  434. dc.SetTextColor( RGB( 255, 255, 255 ) );
  435. ptText.Offset( -1, -2 );
  436. dc.DrawState(
  437. ptText, rcItem.Size(), (LPCTSTR)sTitle,
  438. DSS_NORMAL,  TRUE, 0, (CBrush*)NULL
  439. );
  440. const int nIconMetric = 24;
  441. HICON hIcon = (HICON)
  442. ::LoadImage(
  443. ::AfxGetInstanceHandle(),
  444. MAKEINTRESOURCE(IDI_ICON_FOR_POPUP_MENU),
  445. IMAGE_ICON,
  446. nIconMetric,
  447. nIconMetric,
  448. 0
  449. );
  450. if( hIcon != NULL )
  451. {
  452. int nOffset = (rcItem.Width() - nIconMetric) / 2;
  453. VERIFY(
  454. ::DrawIconEx(
  455. dc.GetSafeHdc(),
  456. rcItem.left + nOffset,
  457. rcItem.top + nOffset,
  458. hIcon,
  459. nIconMetric,
  460. nIconMetric,
  461. 0,
  462. (HBRUSH)NULL,
  463. DI_NORMAL
  464. )
  465. );
  466. VERIFY( DestroyIcon( hIcon ) );
  467. }
  468. dc.SetBkMode( nOldBkMode );
  469. dc.SetTextColor( clrOldText );
  470. dc.SelectObject( pOldFont );
  471. return (!0);
  472. }
  473. //////////////////////////////////////////////////////////////////////////
  474. LRESULT CPagePopupMenus::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam)
  475. {
  476. lParam;
  477. CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
  478. reinterpret_cast
  479. < CExtPopupMenuWnd::MsgPrepareMenuData_t * >
  480. ( wParam );
  481. ASSERT( pData != NULL );
  482. CExtPopupMenuWnd * pPopup = pData->m_pPopup;
  483. ASSERT( pPopup != NULL );
  484. pData->m_bMenuChanged = true;
  485. INT nReplacePos =
  486. pPopup->ItemFindPosForCmdID( ID_PALETTE_MENU );
  487. if( nReplacePos >= 0 )
  488. {
  489. pPopup->ItemRemove( nReplacePos );
  490. CExtPopupMenuWnd * pPalettePopup = new CExtPopupMenuWnd;
  491. pPopup->ItemInsertSpecPopup(
  492. pPalettePopup,
  493. nReplacePos,
  494. g_CmdManager->CmdGetPtr(
  495. g_CmdManager->ProfileNameFromWnd( m_hWnd ),
  496. ID_PALETTE_MENU
  497. )->m_sMenuText
  498. );
  499. pPalettePopup->TrackFlagsSet(
  500. pPalettePopup->TrackFlagsGet()
  501. | TPMX_PALETTE
  502. );
  503. if( m_chkPaletteWithCustomDrawnBackground.GetCheck() != 0 )
  504. pPalettePopup->SetLeftAreaWidth( 10 );
  505. pPalettePopup->ItemInsertCommand(
  506. 1,
  507. -1,
  508. _T("Palette 6 x 2:")
  509. );
  510. INT nLastPos = pPalettePopup->ItemGetCount() - 1;
  511. pPalettePopup->ItemEnabledSet( nLastPos, false );
  512. pPalettePopup->ItemEnabledAppearanceSet( nLastPos );
  513. pPalettePopup->ItemBoldSet( nLastPos );
  514. pPalettePopup->ItemPaletteRowWrapSet( nLastPos );
  515. CExtBitmap _bmp;
  516. VERIFY( _bmp.LoadBMP_Resource( MAKEINTRESOURCE(IDB_PAINT_PALETTE) ) );
  517. INT nRow, nColumn;
  518. static const INT nRowCountPaint = 2, nColumnCountPaint = 6;
  519. static const COLORREF clrTransparentPaint = RGB(255,0,255);
  520. static const CSize _sizeBitmapPartPaint(16,16);
  521. for( nRow = 0; nRow < nRowCountPaint; nRow ++ )
  522. {
  523. for( nColumn = 0; nColumn < nColumnCountPaint; nColumn ++ )
  524. {
  525. CPoint ptBitmapOffset(
  526. nRow * nColumnCountPaint * _sizeBitmapPartPaint.cx
  527. + nColumn * _sizeBitmapPartPaint.cx,
  528. 0
  529. );
  530. CRect rcBitmapPart(
  531. ptBitmapOffset,
  532. _sizeBitmapPartPaint
  533. );
  534. CExtCmdIcon _icon;
  535. _icon.m_bmpNormal.FromBitmap(
  536. _bmp,
  537. &rcBitmapPart
  538. );
  539. ASSERT( ! _icon.IsEmpty() );
  540. _icon.m_bmpNormal.AlphaColor( clrTransparentPaint, RGB(0,0,0), 0 );
  541. pPalettePopup->ItemInsertCommand(
  542. 3 + nRow*nColumnCountPaint + nColumn,
  543. -1,
  544. NULL,
  545. NULL,
  546. _icon
  547. );
  548. if( nColumn == (nColumnCountPaint-1) )
  549. pPalettePopup->ItemPaletteRowWrapSet(
  550. pPalettePopup->ItemGetCount() - 1
  551. );
  552. } // for( nColumn = 0; nColumn < nColumnCountPaint; nColumn ++ )
  553. } // for( nRow = 0; nRow < nRowCountPaint; nRow ++ )
  554. pPalettePopup->ItemInsert();
  555. pPalettePopup->ItemInsertCommand(
  556. 2,
  557. -1,
  558. _T("Palette 6 x 7:")
  559. );
  560. nLastPos = pPalettePopup->ItemGetCount() - 1;
  561. pPalettePopup->ItemEnabledSet( nLastPos, false );
  562. pPalettePopup->ItemEnabledAppearanceSet( nLastPos );
  563. pPalettePopup->ItemBoldSet( nLastPos );
  564. pPalettePopup->ItemPaletteRowWrapSet( nLastPos );
  565. VERIFY( _bmp.LoadBMP_Resource( MAKEINTRESOURCE(IDB_EXT_CUSTOM_TB_IMAGES) ) );
  566. static const INT nRowCountCustom = 7, nColumnCountCustom = 6;
  567. static const COLORREF clrTransparentCustom = RGB(255,0,255);
  568. static const CSize _sizeBitmapPartCustom(16,16);
  569. for( nRow = 0; nRow < nRowCountCustom; nRow ++ )
  570. {
  571. for( nColumn = 0; nColumn < nColumnCountCustom; nColumn ++ )
  572. {
  573. CPoint ptBitmapOffset(
  574. nRow * nColumnCountCustom * _sizeBitmapPartCustom.cx
  575. + nColumn * _sizeBitmapPartCustom.cx,
  576. 0
  577. );
  578. CRect rcBitmapPart(
  579. ptBitmapOffset,
  580. _sizeBitmapPartCustom
  581. );
  582. CExtCmdIcon _icon;
  583. _icon.m_bmpNormal.FromBitmap(
  584. _bmp,
  585. &rcBitmapPart
  586. );
  587. ASSERT( ! _icon.IsEmpty() );
  588. _icon.m_bmpNormal.AlphaColor( clrTransparentCustom, RGB(0,0,0), 0 );
  589. pPalettePopup->ItemInsertCommand(
  590. 3 + nRow*nColumnCountCustom + nColumn,
  591. -1,
  592. NULL,
  593. NULL,
  594. _icon
  595. );
  596. if( nColumn == (nColumnCountCustom-1) )
  597. pPalettePopup->ItemPaletteRowWrapSet(
  598. pPalettePopup->ItemGetCount() - 1
  599. );
  600. } // for( nColumn = 0; nColumn < nColumnCountCustom; nColumn ++ )
  601. } // for( nRow = 0; nRow < nRowCountCustom; nRow ++ )
  602. } // if( nReplacePos >= 0 )
  603. return TRUE;
  604. }
  605. LRESULT CPagePopupMenus::OnExtMenuDrawBackground(WPARAM wParam, LPARAM lParam)
  606. {
  607. wParam;
  608. CExtPopupMenuWnd::DRAWBACKGROUNDDATA * pData =
  609. reinterpret_cast
  610. < CExtPopupMenuWnd::DRAWBACKGROUNDDATA * >
  611. ( lParam );
  612. ASSERT( pData != NULL );
  613. CExtPopupMenuWnd * pPopup = pData->m_pPopup;
  614. ASSERT( pPopup != NULL );
  615. if( (pPopup->TrackFlagsGet()&TPMX_PALETTE) == 0 )
  616. return 0;
  617. if( m_chkPaletteWithCustomDrawnBackground.GetCheck() == 0 )
  618. return 0;
  619. // tell pop-up menu to not paint default menu background
  620. pData->m_bCustomBackgroundDrawn = true;
  621. // now we can render more funny background
  622. CRect rcBackground( pData->m_rcBackground );
  623. CRect rcMB = pData->m_pPopup->OnQueryMenuBorderMetrics();
  624. rcBackground.DeflateRect(
  625. rcMB.left,
  626. rcMB.top,
  627. rcMB.right,
  628. rcMB.bottom
  629. );
  630. COLORREF clrLight =
  631. g_PaintManager->GetColor( COLOR_3DHILIGHT );
  632. pData->m_DC.FillSolidRect(
  633. &rcBackground,
  634. clrLight
  635. );
  636. if( ::GetDeviceCaps( pData->m_DC.m_hDC, BITSPIXEL ) <= 8 )
  637. return 0;
  638. COLORREF clrDark =
  639. g_PaintManager->GetColor( COLOR_3DFACE );
  640. COLORREF clrDarker =
  641. g_PaintManager->GetColor( COLOR_3DDKSHADOW );
  642. int nItemIndex, nItemCount = pPopup->ItemGetCount();
  643. bool bNewRow = true, bFirstRow = true, bCaptionRow = false;
  644. CRect rcRow( rcBackground );
  645. for( nItemIndex = 0; nItemIndex < nItemCount; nItemIndex ++ )
  646. {
  647. CRect rcItem;
  648. pPopup->_GetItemRect( nItemIndex, rcItem, true );
  649. if( pPopup->ItemBoldGet( nItemIndex ) )
  650. bCaptionRow = true;
  651. if( bNewRow )
  652. {
  653. bNewRow = false;
  654. rcRow.top = rcItem.top;
  655. rcRow.bottom = rcItem.bottom;
  656. }
  657. else
  658. {
  659. rcRow.top = min( rcRow.top, rcItem.top );
  660. rcRow.bottom = max( rcRow.bottom, rcItem.bottom );
  661. }
  662. if( nItemIndex == (nItemCount - 1)
  663. || pPopup->ItemPaletteRowWrapGet( nItemIndex )
  664. )
  665. {
  666. if( bFirstRow )
  667. rcRow.top = rcBackground.top;
  668. if( nItemIndex == (nItemCount - 1) )
  669. rcRow.bottom = rcBackground.bottom;
  670. if( ! bCaptionRow )
  671. {
  672. CExtPaintManager::stat_PaintGradientRect(
  673. pData->m_DC,
  674. &rcRow,
  675. clrLight,
  676. clrDark,
  677. true
  678. );
  679. CRect rcTopLine(
  680. rcRow.left,
  681. rcRow.top,
  682. rcRow.right,
  683. rcRow.top + 1
  684. );
  685. static const SIZE g_sizeCurl = { 9, 9 };
  686. CRect rcRowCurl( rcRow.TopLeft(), g_sizeCurl );
  687. POINT points[3];
  688. points[0].x = rcRowCurl.left;
  689. points[0].y = rcRowCurl.bottom;
  690. points[1].x = rcRowCurl.right;
  691. points[1].y = rcRowCurl.top;
  692. points[2].x = rcRowCurl.right;
  693. points[2].y = rcRowCurl.bottom;
  694. CRgn _rgn;
  695. if( _rgn.CreatePolygonRgn(
  696. points,
  697. 3,
  698. ALTERNATE
  699. )
  700. )
  701. {
  702. pData->m_DC.FillSolidRect(
  703. &rcRowCurl,
  704. clrLight
  705. );
  706. pData->m_DC.SelectClipRgn( &_rgn );
  707. CExtPaintManager::stat_PaintGradientRect(
  708. pData->m_DC,
  709. &rcRowCurl,
  710. clrDarker,
  711. clrDark,
  712. true
  713. );
  714. pData->m_DC.SelectClipRgn( NULL );
  715. rcTopLine.left = rcRowCurl.right;
  716. }
  717. CExtPaintManager::stat_PaintGradientRect(
  718. pData->m_DC,
  719. &rcTopLine,
  720. clrDark,
  721. clrDarker,
  722. false
  723. );
  724. }
  725. bNewRow = true;
  726. bFirstRow = false;
  727. bCaptionRow = false;
  728. }
  729. }
  730. return 0;
  731. }
  732. LRESULT CPagePopupMenus::OnDrawPopupMenuItem(WPARAM wParam, LPARAM lParam)
  733. {
  734. wParam;
  735. CExtPopupMenuWnd::DRAWITEMDATA * pDrawItemData =
  736. reinterpret_cast < CExtPopupMenuWnd::DRAWITEMDATA * > ( lParam );
  737. ASSERT( pDrawItemData != NULL );
  738. UINT nCmdID = pDrawItemData->GetCmdID();
  739. if( nCmdID != ID_OWNERDRAW_ITEM )
  740. return 0; // default painting
  741. // paint default menu item background
  742. pDrawItemData->PaintDefaultBk();
  743. // paint some staff in a little bit rect
  744. CRect rcItem = LPCRECT(*pDrawItemData);
  745. rcItem.DeflateRect( 10, 1, 10, 4 );
  746. LPCTSTR sItemText = __EXT_MFC_SAFE_LPCTSTR( *pDrawItemData );
  747. INT nItemTextLen = INT( _tcslen( sItemText ) );
  748. // get draw DC
  749. CDC & dc = *( (CDC *) *pDrawItemData );
  750. CExtWndShadow _shadow;
  751. _shadow.Paint(
  752. NULL,
  753. dc, rcItem, CRect(0,0,0,0), CRect(0,0,0,0),
  754. 3,
  755. CExtWndShadow::DEF_BRIGHTNESS_MIN,
  756. CExtWndShadow::DEF_BRIGHTNESS_MAX,
  757. false
  758. );
  759. CExtPaintManager::stat_PaintGradientRect(
  760. dc,
  761. &rcItem,
  762. dc.GetNearestColor( RGB( 255, 0, 0 ) ),
  763. dc.GetNearestColor( RGB( 0, 0, 255 ) ),
  764. false
  765. );
  766. INT nOldBkMode = dc.SetBkMode( TRANSPARENT );
  767. COLORREF clrOldText = dc.SetTextColor( RGB( 0, 0, 0 ) );
  768. CFont * pOldFont = dc.SelectObject( &g_PaintManager->m_FontBold );
  769. rcItem.OffsetRect( 2, 1 );
  770. dc.DrawText(
  771. sItemText, nItemTextLen, &rcItem, 
  772. DT_VCENTER | DT_END_ELLIPSIS | DT_SINGLELINE | DT_CENTER 
  773. );
  774. clrOldText = dc.SetTextColor( RGB( 255, 255, 255 ) );
  775. rcItem.OffsetRect( -2, -1 );
  776. dc.DrawText(
  777. sItemText, nItemTextLen, &rcItem, 
  778. DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_END_ELLIPSIS
  779. );
  780. dc.SelectObject( pOldFont );
  781. dc.SetBkMode( nOldBkMode );
  782. dc.SetTextColor( clrOldText );
  783. return !0;
  784. }
  785. //////////////////////////////////////////////////////////////////////////
  786. LRESULT CPagePopupMenus::OnMsgSelectionNotification( WPARAM wParam, LPARAM lParam )
  787. {
  788. wParam;
  789. lParam;
  790. #if (!defined __EXT_MFC_NO_DATE_PICKER)
  791. const CExtDatePickerWnd::SELECTION_NOTIFICATION * pSN =
  792. CExtDatePickerWnd::SELECTION_NOTIFICATION::FromWPARAM( wParam );
  793. if( !pSN->m_bFinalSelectionChanging )
  794. return 0L;
  795. CString strMsg, strMsgAll,
  796. strDtBegin( pSN->m_dtBegin.Format() ),
  797. strDtEnd( pSN->m_dtEnd.Format() );
  798. strMsg.Format(
  799. _T("The date selected: %s"),
  800. strDtBegin
  801. );
  802. if( pSN->m_dtBegin != pSN->m_dtEnd ){
  803. strMsg += _T(" - ");
  804. strMsg += strDtEnd;
  805. }
  806. strMsg += _T("rn");
  807. TRACE( strMsg );
  808. #endif // #if (!defined __EXT_MFC_NO_DATE_PICKER)
  809. return 0L;
  810. }
  811. //////////////////////////////////////////////////////////////////////////
  812. LRESULT CPagePopupMenus::OnColorChangedFinally(WPARAM wParam, LPARAM lParam)
  813. {
  814. switch( lParam )
  815. {
  816. case ID_COLOR_CTRL_8X5:
  817. case ID_COLOR_CTRL_8X2:
  818. case ID_COLOR_CTRL_GRAYSCALE:
  819. case ID_COLOR_CTRL_HLS:
  820. {
  821. COLORREF clrColorCtrl = COLORREF(wParam);
  822. if( clrColorCtrl == COLORREF(-1) )
  823. AfxMessageBox(_T("Default Color"));
  824. else
  825. {
  826. CString sColor;
  827. sColor.Format(
  828. _T( "RGB color is 0x%02X%02X%02X" ),
  829. INT( GetRValue(clrColorCtrl) ),
  830. INT( GetGValue(clrColorCtrl) ),
  831. INT( GetBValue(clrColorCtrl) )
  832. );
  833. AfxMessageBox( sColor );
  834. }
  835. }
  836. break;
  837. default:
  838. break;
  839. } // switch( lParam )
  840. return 0;
  841. }
  842. //////////////////////////////////////////////////////////////////////////
  843. LRESULT CPagePopupMenus::OnColorSelectCustom(WPARAM wParam, LPARAM lParam)
  844. {
  845. wParam;
  846. if( lParam == ID_COLOR_CTRL_8X5
  847. || lParam == ID_COLOR_CTRL_8X2
  848. || lParam == ID_COLOR_CTRL_GRAYSCALE
  849. || lParam == ID_COLOR_CTRL_HLS
  850. )
  851. {
  852. COLORREF clrNew;
  853. CExtColorDlg dlgColor;
  854. dlgColor.m_strSection = _T("ColorDialog");
  855. dlgColor.m_strEntryDialogPosition = _T("Position");
  856. dlgColor.m_strEntryColorModelSelection = _T("ColorModel");
  857. if( dlgColor.DoModal() != IDOK )
  858. return 0;
  859. clrNew = dlgColor.m_clrNew;
  860. OnColorChangedFinally( (WPARAM)clrNew, lParam );
  861. }
  862. return 0;
  863. }
  864. void CPagePopupMenus::OnCheckUseAcceleratedMenuScrolling() 
  865. {
  866. CExtPopupMenuWnd::g_bUseAcceleratedMenuScrolling =
  867. m_checkUseAcceleratedMenuScrolling.GetCheck()
  868. ? true : false;
  869. BOOL bEnable =
  870. CExtPopupMenuWnd::g_bUseAcceleratedMenuScrolling
  871. ? TRUE : FALSE;
  872. static const UINT arrIDs[] =
  873. {
  874. IDC_STATIC_INCREASE_PERCENT,
  875. IDC_EDIT_INCREASE_PERCENT,
  876. IDC_SPIN_INCREASE_PERCENT,
  877. IDC_STATIC_INCREASE_STEP,
  878. IDC_EDIT_INCREASE_STEP,
  879. IDC_SPIN_INCREASE_STEP,
  880. IDC_STATIC_MAX_PIXELS_PER_STEP,
  881. IDC_EDIT_MAX_PIXELS_PER_STEP,
  882. IDC_SPIN_MAX_PIXELS_PER_STEP,
  883. };
  884. INT nIndex, nCount = sizeof(arrIDs)/sizeof(arrIDs[0]);
  885. for( nIndex = 0; nIndex < nCount; nIndex++ )
  886. {
  887. UINT nID = arrIDs[nIndex];
  888. CWnd * pWnd = GetDlgItem( nID );
  889. ASSERT_VALID( pWnd );
  890. pWnd->EnableWindow( bEnable );
  891. } // for( nIndex = 0; nIndex < nCount; nIndex++ )
  892. }
  893. void CPagePopupMenus::OnChangeEditIncreasePercent() 
  894. {
  895. if( m_editIncreasePercent.GetSafeHwnd() == NULL )
  896. return;
  897. CString strTmp;
  898. m_editIncreasePercent.GetWindowText( strTmp );
  899. }
  900. void CPagePopupMenus::OnChangeEditIncreaseStep() 
  901. {
  902. if( m_editIncreaseStep.GetSafeHwnd() == NULL )
  903. return;
  904. CString strTmp;
  905. m_editIncreaseStep.GetWindowText( strTmp );
  906. }
  907. void CPagePopupMenus::OnChangeEditMaxPixelsPerStep() 
  908. {
  909. if( m_editMaxPixelsPerStep.GetSafeHwnd() == NULL )
  910. return;
  911. CString strTmp;
  912. m_editMaxPixelsPerStep.GetWindowText( strTmp );
  913. }
  914. void CPagePopupMenus::OnMenuRarelyItem1()
  915. {
  916. ::AfxMessageBox( _T("CPagePopupMenus::OnMenuRarelyItem1()") );
  917. }
  918. void CPagePopupMenus::OnUpdateMenuRarelyItem1( CCmdUI * pCmdUI )
  919. {
  920. pCmdUI->Enable();
  921. }
  922. void CPagePopupMenus::OnMenuRarelyItem2()
  923. {
  924. ::AfxMessageBox( _T("CPagePopupMenus::OnMenuRarelyItem2()") );
  925. }
  926. void CPagePopupMenus::OnUpdateMenuRarelyItem2( CCmdUI * pCmdUI )
  927. {
  928. pCmdUI->Enable();
  929. }
  930. void CPagePopupMenus::OnMenuRarelyItem3()
  931. {
  932. ::AfxMessageBox( _T("CPagePopupMenus::OnMenuRarelyItem3()") );
  933. }
  934. void CPagePopupMenus::OnUpdateMenuRarelyItem3( CCmdUI * pCmdUI )
  935. {
  936. pCmdUI->Enable();
  937. }