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

界面编程

开发平台:

Visual C++

  1. // ExtPopupRichEditCtrl.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "HelpNotes.h"
  5. #include "ExtPopupRichEditCtrl.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CExtDynamicRichEditDoc::CExtDynamicRichEditCntrItem
  13. CExtDynamicRichEditDoc::CExtDynamicRichEditCntrItem::CExtDynamicRichEditCntrItem(
  14. REOBJECT * preo,
  15. CExtDynamicRichEditDoc * pContainer
  16. )
  17. : CRichEditCntrItem(
  18. preo, pContainer
  19. )
  20. {
  21. }
  22. CExtDynamicRichEditDoc::CExtDynamicRichEditCntrItem::~CExtDynamicRichEditCntrItem()
  23. {
  24. }
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CExtDynamicRichEditDoc
  27. IMPLEMENT_DYNCREATE( CExtDynamicRichEditDoc, CRichEditDoc )
  28. BEGIN_MESSAGE_MAP(CExtDynamicRichEditDoc, CRichEditDoc)
  29. //{{AFX_MSG_MAP(CExtDynamicRichEditDoc)
  30. //}}AFX_MSG_MAP
  31. ON_UPDATE_COMMAND_UI( ID_OLE_EDIT_LINKS, CRichEditDoc::OnUpdateEditLinksMenu )
  32. ON_COMMAND( ID_OLE_EDIT_LINKS, CRichEditDoc::OnEditLinks )
  33. ON_UPDATE_COMMAND_UI_RANGE( ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, CRichEditDoc::OnUpdateObjectVerbMenu )
  34. END_MESSAGE_MAP()
  35. CExtDynamicRichEditDoc::CExtDynamicRichEditDoc()
  36. {
  37. }
  38. CExtDynamicRichEditDoc::~CExtDynamicRichEditDoc()
  39. {
  40. }
  41. BOOL CExtDynamicRichEditDoc::CanCloseFrame( CFrameWnd *  pFrame ) 
  42. {
  43. ASSERT_VALID( this );
  44. pFrame;
  45. return TRUE;
  46. }
  47. CRichEditCntrItem * CExtDynamicRichEditDoc::CreateClientItem(
  48. REOBJECT * preo
  49. ) const
  50. {
  51. ASSERT_VALID( this );
  52. return new CExtDynamicRichEditCntrItem( preo, (CExtDynamicRichEditDoc*) this );
  53. }
  54. void CExtDynamicRichEditDoc::OnIdle()
  55. {
  56. ASSERT_VALID( this );
  57. }
  58. BOOL CExtDynamicRichEditDoc::OnNewDocument()
  59. {
  60. ASSERT_VALID( this );
  61. if( !CRichEditDoc::OnNewDocument() )
  62. return FALSE;
  63. CRichEditDoc::DeleteContents();
  64. return TRUE;
  65. }
  66. BOOL CExtDynamicRichEditDoc::SaveModified() 
  67. {
  68. ASSERT_VALID( this );
  69. return TRUE;
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CExtDynamicRichEditView
  73. IMPLEMENT_DYNCREATE( CExtDynamicRichEditView, CRichEditView )
  74. BEGIN_MESSAGE_MAP( CExtDynamicRichEditView, CRichEditView )
  75. //{{AFX_MSG_MAP(CExtDynamicRichEditView)
  76. ON_WM_DESTROY()
  77. ON_WM_CREATE()
  78. //}}AFX_MSG_MAP
  79. END_MESSAGE_MAP()
  80. CExtDynamicRichEditView::CExtDynamicRichEditView()
  81. : m_pDocTemplate( NULL )
  82. {
  83. }
  84. CExtDynamicRichEditView::~CExtDynamicRichEditView()
  85. {
  86. }
  87. void CExtDynamicRichEditView::_DoDestroyWindow()
  88. {
  89. ASSERT_VALID( this );
  90. //COleClientItem * pActiveItem =
  91. // GetDocument()->GetInPlaceActiveItem( this );
  92. // if( pActiveItem != NULL
  93. // && pActiveItem->GetActiveView() == this
  94. // )
  95. // {
  96. // pActiveItem->Deactivate();
  97. // ASSERT( GetDocument()->GetInPlaceActiveItem(this) == NULL );
  98. // }
  99. }
  100. CExtDynamicRichEditDoc * CExtDynamicRichEditView::GetDocument()
  101. {
  102. ASSERT_VALID( this );
  103. return ( (CExtDynamicRichEditDoc*) m_pDocument );
  104. }
  105. int CExtDynamicRichEditView::OnCreate( LPCREATESTRUCT lpCreateStruct ) 
  106. {
  107. ASSERT_VALID( this );
  108. if( CRichEditView::OnCreate(lpCreateStruct) == -1 )
  109. {
  110. ASSERT_VALID( this );
  111. return -1;
  112. }
  113. if( m_pDocTemplate == NULL )
  114. {
  115. m_pDocTemplate =
  116. new CSingleDocTemplate(
  117. IDR_MAINFRAME,
  118. RUNTIME_CLASS( CExtDynamicRichEditDoc ),
  119. RUNTIME_CLASS( CFrameWnd ),
  120. RUNTIME_CLASS( CExtDynamicRichEditView )
  121. );
  122. ASSERT_VALID( m_pDocTemplate );
  123. m_pDocTemplate->SetContainerInfo(
  124. IDR_MAINFRAME
  125. );
  126. ::AfxGetApp()->AddDocTemplate( m_pDocTemplate );
  127. } // if( m_pDocTemplate == NULL )
  128. CDocument * pDocument =
  129. m_pDocTemplate->CreateNewDocument();
  130. ASSERT_VALID( pDocument );
  131. ASSERT( pDocument->GetDocTemplate() == m_pDocTemplate );
  132. pDocument->AddView( this );
  133. ASSERT( m_pDocument == pDocument );
  134. return 0;
  135. }
  136. void CExtDynamicRichEditView::OnDestroy()
  137. {
  138. ASSERT_VALID( this );
  139. CRichEditView::OnDestroy();
  140. _DoDestroyWindow();
  141. if( m_pDocument != NULL )
  142. {
  143. m_pDocument->RemoveView( this );
  144. ASSERT( m_pDocument == NULL );
  145. } // if( m_pDocument != NULL )
  146. }
  147. void CExtDynamicRichEditView::PostNcDestroy() 
  148. {
  149. }
  150. BOOL CExtDynamicRichEditView::PreCreateWindow(CREATESTRUCT& cs)
  151. {
  152. ASSERT_VALID( this );
  153. cs.lpszClass = NULL;
  154. LONG nStylesSaved = cs.style & (WS_POPUP|WS_CHILD);
  155. cs.style &= ~(WS_POPUP);
  156. cs.style |= WS_CHILD;
  157. if( ! CRichEditView::PreCreateWindow(cs) )
  158. {
  159. ASSERT( FALSE );
  160. return FALSE;
  161. }
  162. cs.style &= ~(WS_POPUP|WS_CHILD|WS_BORDER|WS_DLGFRAME);
  163. cs.style |= nStylesSaved;
  164. cs.dwExStyle &= ~(WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME|WS_EX_WINDOWEDGE);
  165. return TRUE;
  166. }
  167. /////////////////////////////////////////////////////////////////////////////
  168. // CExtPopupRichEditView
  169. IMPLEMENT_DYNCREATE( CExtPopupRichEditView, CExtDynamicRichEditView );
  170. CExtPopupRichEditView::CExtPopupRichEditView()
  171. : m_hWndNotify( NULL )
  172. , m_sizeLayout( 0, 0 )
  173. , m_clrBackground( COLORREF(-1L) )
  174. , m_clrBorderLT( COLORREF(-1L) )
  175. , m_clrBorderRB( COLORREF(-1L) )
  176. , m_eST( CExtPopupRichEditView::__EST_POPUP )
  177. {
  178. }
  179. CExtPopupRichEditView::~CExtPopupRichEditView()
  180. {
  181. }
  182. BEGIN_MESSAGE_MAP( CExtPopupRichEditView, CExtDynamicRichEditView )
  183. //{{AFX_MSG_MAP(CExtPopupRichEditView)
  184. ON_WM_NCCALCSIZE()
  185. ON_WM_NCPAINT()
  186. ON_WM_CANCELMODE()
  187. ON_WM_ACTIVATEAPP()
  188. //}}AFX_MSG_MAP
  189. ON_WM_SYSCOLORCHANGE()
  190. __EXT_MFC_SAFE_ON_WM_SETTINGCHANGE()
  191. ON_MESSAGE(WM_DISPLAYCHANGE, OnDisplayChange)
  192. ON_MESSAGE(__ExtMfc_WM_THEMECHANGED, OnThemeChanged)
  193. END_MESSAGE_MAP()
  194. /////////////////////////////////////////////////////////////////////////////
  195. // CExtPopupRichEditView message handlers
  196. void CExtPopupRichEditView::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
  197. {
  198. ASSERT_VALID( this );
  199. // CExtDynamicRichEditView::OnNcCalcSize(bCalcValidRects, lpncsp);
  200. bCalcValidRects;
  201. if( (GetStyle()&WS_VISIBLE) == 0 )
  202. return;
  203. int nShadowSize = OnQueryShadowSize();
  204. CRect rcBorderSizes = OnQueryBorderSizes();
  205. lpncsp->rgrc[0].left += rcBorderSizes.left;
  206. lpncsp->rgrc[0].top += rcBorderSizes.top;
  207. lpncsp->rgrc[0].right -= rcBorderSizes.right + nShadowSize;
  208. lpncsp->rgrc[0].bottom -= rcBorderSizes.bottom + nShadowSize;
  209. }
  210. void CExtPopupRichEditView::OnNcPaint() 
  211. {
  212. ASSERT_VALID( this );
  213. int nShadowSize = OnQueryShadowSize();
  214. CWindowDC dc( this );
  215. CRect rcClient, rcBar;
  216. GetClientRect( rcClient );
  217. ClientToScreen( rcClient );
  218. GetWindowRect( rcBar );
  219. rcClient.OffsetRect( -rcBar.TopLeft() );
  220. rcBar.OffsetRect( -rcBar.TopLeft() );
  221. dc.ExcludeClipRect(rcClient);
  222. CRect rcWnd = rcBar, rcBorders = rcBar;
  223. rcBorders.DeflateRect(
  224. 0,
  225. 0,
  226. nShadowSize,
  227. nShadowSize
  228. );
  229. CExtMemoryDC mdc(
  230. &dc,
  231. &rcBar,
  232. CExtMemoryDC::MDCOPT_RTL_COMPATIBILITY
  233. |CExtMemoryDC::MDCOPT_TO_MEMORY
  234. | CExtMemoryDC::MDCOPT_FILL_BITS
  235. );
  236. mdc.FillSolidRect(
  237. &rcBorders,
  238. ( m_clrBackground == COLORREF(-1L) )
  239. ? ( ::GetSysColor( COLOR_INFOBK ) )
  240. : m_clrBackground
  241. );
  242. OnPaintNcAreaParts(
  243. mdc,
  244. rcWnd,
  245. rcClient,
  246. rcBorders
  247. );
  248. }
  249. bool CExtPopupRichEditView::Activate(
  250. CExtResourceManager::CExtResourceMemoryBuffer & buffer,
  251. const RECT & rcItem,
  252. HWND hWndNotify,
  253. UINT nAlignType,
  254. int nAlignDistance // = 30
  255. )
  256. {
  257. ASSERT_VALID( this );
  258. ASSERT( hWndNotify != NULL && ::IsWindow( hWndNotify ) );
  259. ASSERT(
  260. nAlignType == AFX_IDW_DOCKBAR_TOP
  261. || nAlignType == AFX_IDW_DOCKBAR_BOTTOM
  262. || nAlignType == AFX_IDW_DOCKBAR_LEFT
  263. || nAlignType == AFX_IDW_DOCKBAR_RIGHT
  264. );
  265. ASSERT( nAlignDistance >= 0 );
  266. Deactivate();
  267. if( buffer.IsEmpty() )
  268. return true;
  269. if( ! CreateEx(
  270. WS_EX_TOPMOST,
  271. _T("RICHEDIT"),
  272. NULL,
  273. WS_POPUP|WS_CLIPSIBLINGS|WS_CLIPCHILDREN
  274. | ( g_PaintManager.m_bIsWin2000orLater
  275. ? (WS_EX_NOINHERITLAYOUT)
  276. : 0
  277. )
  278. |ES_LEFT|ES_MULTILINE|ES_READONLY|ES_WANTRETURN
  279. ,
  280. 0, 0, 0, 0,
  281. hWndNotify,
  282. (HMENU)NULL
  283. )
  284. )
  285. {
  286. ASSERT( FALSE );
  287. return false;
  288. }
  289. CRichEditCtrl & wndRichEditCtrl = GetRichEditCtrl();
  290. CHARFORMAT cfDefault;
  291. ::memset( &cfDefault, 0, sizeof(CHARFORMAT) );
  292. cfDefault.cbSize = sizeof(cfDefault);
  293. cfDefault.dwEffects = CFE_PROTECTED; 
  294. cfDefault.dwMask =
  295. CFM_BOLD|CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_PROTECTED|CFM_COLOR;
  296. cfDefault.yHeight = 200;
  297. cfDefault.bCharSet = DEFAULT_CHARSET;
  298. #if _MFC_VER < 0x700
  299. strcpy(
  300. cfDefault.szFaceName,
  301. "Tahoma"
  302. ); 
  303. #else
  304. __EXT_MFC_STRCPY(
  305. cfDefault.szFaceName,
  306. LF_FACESIZE, 
  307. _T("Tahoma")
  308. ); 
  309. #endif
  310. cfDefault.crTextColor = ::GetSysColor( COLOR_INFOTEXT );
  311. wndRichEditCtrl.SetDefaultCharFormat( cfDefault );
  312. wndRichEditCtrl.SetWordCharFormat( cfDefault );
  313. if( m_clrBackground == COLORREF(-1L) )
  314. wndRichEditCtrl.SetBackgroundColor( FALSE, ::GetSysColor( COLOR_INFOBK ) );
  315. else
  316. wndRichEditCtrl.SetBackgroundColor( FALSE, m_clrBackground );
  317. m_hWndNotify = hWndNotify;
  318. CRect _rcItem = rcItem;
  319. if( (::GetWindowLong(hWndNotify,GWL_EXSTYLE)&WS_EX_LAYOUTRTL) != 0 )
  320. __EXT_MFC_SwapLeftRight( _rcItem );
  321. CRect rcWndPreCalc = _rcItem;
  322. ::ClientToScreen( hWndNotify, ((LPPOINT)(&rcWndPreCalc)) );
  323. ::ClientToScreen( hWndNotify, ((LPPOINT)(&rcWndPreCalc))+1 );
  324. CRect rcWndItem = rcWndPreCalc;
  325. CSize sizeItem = rcWndItem.Size();
  326. SetupRTForPlain( buffer );
  327. rcWndPreCalc.right = rcWndPreCalc.left + m_sizeLayout.cx;
  328. rcWndPreCalc.bottom = rcWndPreCalc.top + m_sizeLayout.cy;
  329. int nShadowSize = OnQueryShadowSize();
  330. CRect rcBorderSizes = OnQueryBorderSizes();
  331. rcWndPreCalc.right += rcBorderSizes.left + rcBorderSizes.right + nShadowSize;
  332. rcWndPreCalc.bottom += rcBorderSizes.top + rcBorderSizes.bottom + nShadowSize;
  333. CRect rcSet = rcWndPreCalc;
  334. rcSet.OffsetRect( -rcSet.TopLeft() );
  335. CRect rcWndFinal = rcWndPreCalc;
  336. CExtPaintManager::monitor_parms_t _mp;
  337. CExtPaintManager::stat_GetMonitorParms( _mp, rcWndPreCalc );
  338. CRect rcWorkArea = _mp.m_rcWorkArea; // _mp.m_rcMonitor
  339. bool bRecalcToMaxDistance = false, bStopFlag = false;
  340. UINT nAlignTypeRecalc = nAlignType;
  341. for( int nStep = 0; nStep < 4 && (!bStopFlag); nStep++ )
  342. {
  343. rcWndPreCalc = rcWndFinal;
  344. if( nStep == 3 )
  345. {
  346. bRecalcToMaxDistance = true;
  347. break;
  348. }
  349. switch( nAlignTypeRecalc )
  350. {
  351. case AFX_IDW_DOCKBAR_TOP:
  352. rcWndPreCalc.OffsetRect( 0, -rcWndPreCalc.Height() - nAlignDistance );
  353. if( rcWndPreCalc.top >= rcWorkArea.top )
  354. {
  355. bStopFlag = true;
  356. break;
  357. }
  358. switch( nStep )
  359. {
  360. case 0:
  361. nAlignTypeRecalc = AFX_IDW_DOCKBAR_BOTTOM;
  362. break;
  363. case 1:
  364. nAlignTypeRecalc = AFX_IDW_DOCKBAR_LEFT;
  365. break;
  366. case 2:
  367. nAlignTypeRecalc = AFX_IDW_DOCKBAR_BOTTOM;
  368. break;
  369. }; // switch( nStep )
  370. break;
  371. case AFX_IDW_DOCKBAR_BOTTOM:
  372. rcWndPreCalc.OffsetRect( 0, sizeItem.cy + nAlignDistance );
  373. if( rcWndPreCalc.bottom < rcWorkArea.bottom )
  374. {
  375. bStopFlag = true;
  376. break;
  377. }
  378. switch( nStep )
  379. {
  380. case 0:
  381. nAlignTypeRecalc = AFX_IDW_DOCKBAR_TOP;
  382. break;
  383. case 1:
  384. nAlignTypeRecalc = AFX_IDW_DOCKBAR_LEFT;
  385. break;
  386. case 2:
  387. nAlignTypeRecalc = AFX_IDW_DOCKBAR_RIGHT;
  388. break;
  389. }; // switch( nStep )
  390. break;
  391. case AFX_IDW_DOCKBAR_LEFT:
  392. rcWndPreCalc.OffsetRect( -rcWndPreCalc.Width() - nAlignDistance, 0 );
  393. if( rcWndPreCalc.left >= rcWorkArea.left )
  394. {
  395. bStopFlag = true;
  396. break;
  397. }
  398. switch( nStep )
  399. {
  400. case 0:
  401. nAlignTypeRecalc = AFX_IDW_DOCKBAR_RIGHT;
  402. break;
  403. case 1:
  404. nAlignTypeRecalc = AFX_IDW_DOCKBAR_TOP;
  405. break;
  406. case 2:
  407. nAlignTypeRecalc = AFX_IDW_DOCKBAR_RIGHT;
  408. break;
  409. }; // switch( nStep )
  410. break;
  411. case AFX_IDW_DOCKBAR_RIGHT:
  412. rcWndPreCalc.OffsetRect( sizeItem.cx + nAlignDistance, 0 );
  413. if( rcWndPreCalc.right < rcWorkArea.right )
  414. {
  415. bStopFlag = true;
  416. break;
  417. }
  418. switch( nStep )
  419. {
  420. case 0:
  421. nAlignTypeRecalc = AFX_IDW_DOCKBAR_LEFT;
  422. break;
  423. case 1:
  424. nAlignTypeRecalc = AFX_IDW_DOCKBAR_TOP;
  425. break;
  426. case 2:
  427. nAlignTypeRecalc = AFX_IDW_DOCKBAR_BOTTOM;
  428. break;
  429. }; // switch( nStep )
  430. break;
  431. #ifdef _DEBUG
  432. default:
  433. {
  434. ASSERT( FALSE );
  435. }
  436. break;
  437. #endif // _DEBUG
  438. } // switch( nAlignTypeRecalc )
  439. } // for( int nStep = 0; nStep < 4 && (!bStopFlag); nStep++ )
  440. if( bRecalcToMaxDistance )
  441. {
  442. CRect rcMaxDistance(
  443. rcWndItem.left - rcWorkArea.left,
  444. rcWndItem.top - rcWorkArea.top,
  445. rcWndItem.right - rcWndPreCalc.right,
  446. rcWndItem.bottom - rcWndPreCalc.bottom
  447. );
  448. if( nAlignType == AFX_IDW_DOCKBAR_TOP
  449. || nAlignType == AFX_IDW_DOCKBAR_BOTTOM
  450. )
  451. {
  452. if( rcMaxDistance.top > rcMaxDistance.bottom )
  453. {
  454. rcWndPreCalc.OffsetRect( 0, -rcWndPreCalc.Height() - nAlignDistance );
  455. if( rcWndPreCalc.top < rcWorkArea.top )
  456. rcWndPreCalc.OffsetRect( 0, rcWorkArea.top - rcWndPreCalc.top );
  457. }
  458. else
  459. {
  460. rcWndPreCalc.OffsetRect( 0, sizeItem.cy + nAlignDistance );
  461. if( rcWndPreCalc.bottom > rcWorkArea.bottom )
  462. rcWndPreCalc.OffsetRect( 0, rcWorkArea.bottom - rcWndPreCalc.bottom );
  463. }
  464. }
  465. else
  466. {
  467. if( rcMaxDistance.left > rcMaxDistance.right )
  468. {
  469. rcWndPreCalc.OffsetRect( -rcWndPreCalc.Width() - nAlignDistance, 0 );
  470. if( rcWndPreCalc.left < rcWorkArea.left )
  471. rcWndPreCalc.OffsetRect( rcWorkArea.left - rcWndPreCalc.left, 0 );
  472. }
  473. else
  474. {
  475. rcWndPreCalc.OffsetRect( sizeItem.cx + nAlignDistance, 0 );
  476. if( rcWndPreCalc.right > rcWorkArea.right )
  477. rcWndPreCalc.OffsetRect( rcWorkArea.right - rcWndPreCalc.right, 0 );
  478. }
  479. }
  480. } // if( bRecalcToMaxDistance )
  481. if( rcWndPreCalc.right > rcWorkArea.right )
  482. rcWndPreCalc.OffsetRect( rcWorkArea.right - rcWndPreCalc.right, 0 );
  483. if( rcWndPreCalc.left < rcWorkArea.left )
  484. rcWndPreCalc.OffsetRect( rcWorkArea.left - rcWndPreCalc.left, 0 );
  485. if( rcWndPreCalc.bottom > rcWorkArea.bottom )
  486. rcWndPreCalc.OffsetRect( 0, rcWorkArea.bottom - rcWndPreCalc.bottom );
  487. if( rcWndPreCalc.top < rcWorkArea.top )
  488. rcWndPreCalc.OffsetRect( 0, rcWorkArea.top - rcWndPreCalc.top );
  489. rcWndFinal = rcWndPreCalc;
  490. theApp.m_hWndLastPopup = m_hWnd;
  491. SetWindowPos(
  492. &CWnd::wndTopMost,
  493. rcWndFinal.left,
  494. rcWndFinal.top,
  495. rcWndFinal.Width(),
  496. rcWndFinal.Height(),
  497. SWP_NOOWNERZORDER|SWP_NOACTIVATE
  498. |SWP_SHOWWINDOW|SWP_FRAMECHANGED
  499. );
  500. wndRichEditCtrl.SetRect( &rcSet );
  501. SetWindowPos(
  502. NULL,
  503. 0,
  504. 0,
  505. 0,
  506. 0,
  507. SWP_NOOWNERZORDER|SWP_NOZORDER
  508. |SWP_NOACTIVATE|SWP_FRAMECHANGED
  509. |SWP_NOMOVE|SWP_NOSIZE
  510. );
  511. UpdateWindow();
  512. return true;
  513. }
  514. void CExtPopupRichEditView::Deactivate()
  515. {
  516. ASSERT_VALID( this );
  517. if( GetSafeHwnd() != NULL )
  518. {
  519. ShowWindow( SW_HIDE );
  520. ASSERT( !IsWindowVisible() );
  521. CRect rcWndOld;
  522. GetWindowRect( &rcWndOld );
  523. CWnd * pWndTLP = GetTopLevelParent();
  524. if( pWndTLP != NULL )
  525. {
  526. ASSERT_VALID( pWndTLP );
  527. if( pWndTLP->IsWindowVisible() )
  528. {
  529. CRect rcTLP;
  530. pWndTLP->GetWindowRect( &rcTLP );
  531. if( !rcTLP.IsRectEmpty() )
  532. {
  533. CRect rcIntersection;
  534. if( rcIntersection.IntersectRect(
  535. &rcTLP,
  536. &rcWndOld
  537. )
  538. )
  539. {
  540. pWndTLP->RedrawWindow(
  541. NULL,
  542. NULL,
  543. RDW_ALLCHILDREN|RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ERASENOW
  544. );
  545. }
  546. } // if( !rcTLP.IsRectEmpty() )
  547. } // if( pWndTLP->IsWindowVisible() )
  548. } // if( pWndTLP != NULL )
  549. CWnd * pWnd = CWnd::FromHandlePermanent( m_hWndNotify );
  550. if( pWnd != NULL )
  551. {
  552. CFrameWnd * pDockSite =
  553. DYNAMIC_DOWNCAST( CFrameWnd, pWnd );
  554. if( pDockSite != NULL
  555. && (! pDockSite->IsKindOf(RUNTIME_CLASS(CMiniFrameWnd)) )
  556. )
  557. CExtControlBar::stat_RedrawFloatingFrames( pDockSite );
  558. }
  559. DestroyWindow();
  560. CExtPaintManager::stat_PassPaintMessages();
  561. }
  562. m_hWndNotify = NULL;
  563. }
  564. void CExtPopupRichEditView::LayoutWnd()
  565. {
  566. ASSERT_VALID( this );
  567. CRichEditCtrl & wndRichEditCtrl = GetRichEditCtrl();
  568. wndRichEditCtrl.SetEventMask( ENM_REQUESTRESIZE );
  569. m_sizeLayout.cx = m_sizeLayout.cy = 0;
  570. int nFirst = 0;
  571. int nLast = ::GetSystemMetrics( SM_CXFULLSCREEN );
  572. int nMax = 0;
  573. do
  574. {
  575. int cx = ( nFirst + nLast ) / 2;
  576. CRect rc( 0, 0, cx, 1 );
  577. CRect rcMove = rc;
  578. MoveWindow( &rc );
  579. wndRichEditCtrl.SetRect( &rc );
  580. wndRichEditCtrl.RequestResize();
  581. if( nMax == 0 )
  582. nMax = m_sizeLayout.cy;
  583. if( m_sizeLayout.cy > nMax )
  584. nFirst = cx + 1;
  585. else
  586. nLast = cx - 1;
  587. }
  588. while( nFirst < nLast );
  589. //m_sizeLayout.cx += 4;
  590. }
  591. BOOL CExtPopupRichEditView::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) 
  592. {
  593. ASSERT_VALID( this );
  594. if( message == WM_NOTIFY )
  595. {
  596. REQRESIZE * pRequestResizeData = (REQRESIZE*)lParam;
  597. if( pRequestResizeData->nmhdr.code == EN_REQUESTRESIZE )
  598. {
  599. m_sizeLayout.cx = pRequestResizeData->rc.right - pRequestResizeData->rc.left;
  600. m_sizeLayout.cy = pRequestResizeData->rc.bottom - pRequestResizeData->rc.top;
  601. return TRUE;
  602. } // if( pRequestResizeData->nmhdr.code == EN_REQUESTRESIZE )
  603. } // if( message == WM_NOTIFY )
  604. return CExtDynamicRichEditView::OnChildNotify(message, wParam, lParam, pLResult);
  605. }
  606. void CExtPopupRichEditView::SetupRTForPlain(
  607. CExtResourceManager::CExtResourceMemoryBuffer & buffer
  608. )
  609. {
  610. ASSERT_VALID( this );
  611. try
  612. {
  613. CMemFile f( buffer.GetBuffer(), buffer.GetSize() );
  614. CArchive ar(
  615. &f,
  616. CArchive::load
  617. );
  618. CExtDynamicRichEditDoc * pDoc = GetDocument();
  619. ar.m_pDocument = pDoc;
  620. pDoc->Serialize(ar);
  621. f.Close();
  622. ar.Close();
  623. } // try
  624. catch( CException * pException )
  625. {
  626. ASSERT( FALSE );
  627. pException->Delete();
  628. } // catch( CException * pException )
  629. catch( ... )
  630. {
  631. ASSERT( FALSE );
  632. } // catch( ... )
  633. LayoutWnd();
  634. }
  635. DWORD CALLBACK CExtPopupRichEditView::stat_StreamUploadCallback(
  636.    DWORD dwCookie,
  637.    LPBYTE bBuff,
  638.    LONG nCountIn,
  639.    LONG * p_nCountOut
  640.    )
  641. {
  642. LPCTSTR strText = (LPCTSTR)dwCookie;
  643. (*p_nCountOut) = LONG( _tcslen( strText ) ) * LONG( sizeof(TCHAR) );
  644. if( (*p_nCountOut) > nCountIn )
  645. (*p_nCountOut) = nCountIn;
  646. ::memcpy( bBuff, strText, (*p_nCountOut) );
  647. strText += (*p_nCountOut) / sizeof(TCHAR);
  648. return ( *strText != '' ) ? (DWORD)strText : NULL;
  649. }
  650. LRESULT CExtPopupRichEditView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  651. {
  652. if( message == WM_MOUSEACTIVATE )
  653. return MA_NOACTIVATEANDEAT;
  654. if( __EXT_MFC_WM_MOUSEFIRST <= message && message <= __EXT_MFC_WM_MOUSELAST )
  655. return 0;
  656. if( WM_KEYFIRST <= message && message <= WM_KEYLAST )
  657. return 0;
  658. return CExtDynamicRichEditView::WindowProc(message, wParam, lParam);
  659. }
  660. int CExtPopupRichEditView::OnQueryShadowSize() const
  661. {
  662. ASSERT_VALID( this );
  663. if( m_eST == __EST_POPUP )
  664. {
  665. int nMenuShadowSize = g_PaintManager->GetMenuShadowSize();
  666. return nMenuShadowSize;
  667. }
  668. if( m_eST == __EST_WINHELP )
  669. return 6;
  670. return 0;
  671. }
  672. CRect CExtPopupRichEditView::OnQueryBorderSizes() const
  673. {
  674. ASSERT_VALID( this );
  675. return CRect( 7, 4, 7, 4 );
  676. }
  677. void CExtPopupRichEditView::OnPaintNcAreaParts(
  678. CDC & dc,
  679. CRect rcWnd,
  680. CRect rcClient,
  681. CRect rcBorders
  682. ) const
  683. {
  684. ASSERT_VALID( this );
  685. rcWnd;
  686. rcClient;
  687. if( m_eST == __EST_POPUP )
  688. {
  689. int nShadowSize = OnQueryShadowSize();
  690. CExtWndShadow _shadow;
  691. _shadow.Paint(
  692. NULL,
  693. dc,
  694. rcBorders,
  695. CRect(0,0,0,0),
  696. CRect(0,0,0,0),
  697. (UINT)nShadowSize,
  698. CExtWndShadow::DEF_BRIGHTNESS_MIN,
  699. CExtWndShadow::DEF_BRIGHTNESS_MAX,
  700. false
  701. );
  702. }
  703. else if( m_eST == __EST_WINHELP )
  704. {
  705. int nShadowSize = OnQueryShadowSize();
  706. CBitmap bitmapShadow;
  707. CBrush brushShadow;
  708. static int g_arrBmpPattern[] =
  709. { 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 };
  710. bitmapShadow.CreateBitmap( 8, 8, 1, 1, g_arrBmpPattern );
  711. brushShadow.CreatePatternBrush( &bitmapShadow );
  712. dc.SetBkColor( RGB(255,255,255) );
  713. brushShadow.UnrealizeObject();
  714. CBrush * pbrOld = (CBrush *)
  715. dc.SelectObject( &brushShadow );
  716. dc.PatBlt(
  717. rcBorders.left + nShadowSize,
  718. rcBorders.bottom,
  719. rcBorders.Width(),
  720. nShadowSize,
  721. 0xA000C9
  722. );
  723. dc.PatBlt(
  724. rcBorders.right,
  725. rcBorders.top + nShadowSize,
  726. nShadowSize,
  727. rcBorders.Height(),
  728. 0xA000C9
  729. );
  730. dc.SelectObject( pbrOld );
  731. }
  732. COLORREF clrBorderLT =
  733. ( m_clrBorderLT == COLORREF(-1L) )
  734. ? ( ::GetSysColor( COLOR_3DFACE ) )
  735. : m_clrBorderLT
  736. ;
  737. COLORREF clrBorderRB =
  738. ( m_clrBorderRB == COLORREF(-1L) )
  739. ? ( ::GetSysColor( COLOR_3DDKSHADOW ) )
  740. : m_clrBorderRB
  741. ;
  742. dc.Draw3dRect(
  743. &rcBorders,
  744. clrBorderLT,
  745. clrBorderRB
  746. );
  747. }
  748. void CExtPopupRichEditView::OnCancelMode() 
  749. {
  750. CExtDynamicRichEditView::OnCancelMode();
  751. Deactivate();
  752. }
  753. #if _MFC_VER < 0x700
  754. void CExtPopupRichEditView::OnActivateApp(BOOL bActive, HTASK hTask) 
  755. #else
  756. void CExtPopupRichEditView::OnActivateApp(BOOL bActive, DWORD hTask) 
  757. #endif
  758. {
  759. CExtDynamicRichEditView::OnActivateApp(bActive, hTask);
  760. if( ! bActive )
  761. SendMessage( WM_CANCELMODE );
  762. }
  763. void CExtPopupRichEditView::OnSysColorChange() 
  764. {
  765. ASSERT_VALID( this );
  766. CExtDynamicRichEditView::OnSysColorChange();
  767. SendMessage( WM_CANCELMODE );
  768. }
  769. LRESULT CExtPopupRichEditView::OnDisplayChange( WPARAM wParam, LPARAM lParam )
  770. {
  771. ASSERT_VALID( this );
  772. LRESULT lResult = CExtDynamicRichEditView::OnDisplayChange( wParam, lParam );
  773. SendMessage( WM_CANCELMODE );
  774. return lResult;
  775. }
  776. LRESULT CExtPopupRichEditView::OnThemeChanged( WPARAM wParam, LPARAM lParam )
  777. {
  778. ASSERT_VALID( this );
  779. LRESULT lResult = Default();
  780. g_PaintManager.OnThemeChanged( this, wParam, lParam );
  781. g_CmdManager.OnThemeChanged( g_PaintManager.GetPM(), this, wParam, lParam );
  782. SendMessage( WM_CANCELMODE );
  783. return lResult;
  784. }
  785. void CExtPopupRichEditView::OnSettingChange(UINT uFlags, __EXT_MFC_SAFE_LPCTSTR lpszSection) 
  786. {
  787. ASSERT_VALID( this );
  788. CExtDynamicRichEditView::OnSettingChange(uFlags, lpszSection);
  789. g_PaintManager.OnSettingChange( this, uFlags, lpszSection );
  790. g_CmdManager.OnSettingChange( g_PaintManager.GetPM(), this, uFlags, lpszSection );
  791. SendMessage( WM_CANCELMODE );
  792. }