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.

1517 lines
38 KiB

  1. //
  2. // candext.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include "mscandui.h"
  7. #include "candext.h"
  8. #include "candui.h"
  9. /*============================================================================*/
  10. /* */
  11. /* C C A N D U I E X T E N S I O N */
  12. /* */
  13. /*============================================================================*/
  14. /* C C A N D U I E X T E N S I O N */
  15. /*------------------------------------------------------------------------------
  16. Constructor of CCandUIExtension
  17. ------------------------------------------------------------------------------*/
  18. CCandUIExtension::CCandUIExtension( CCandUIExtensionMgr *pExtensionMgr, LONG id )
  19. {
  20. m_pExtensionMgr = pExtensionMgr;
  21. m_flags.fAllowEnable = FALSE;
  22. m_flags.fAllowDisable = FALSE;
  23. m_flags.fAllowIsEnabled = FALSE;
  24. m_flags.fAllowShow = FALSE;
  25. m_flags.fAllowHide = FALSE;
  26. m_flags.fAllowIsVisible = FALSE;
  27. m_flags.fAllowSetPosition = FALSE;
  28. m_flags.fAllowGetPosition = FALSE;
  29. m_flags.fAllowGetSize = FALSE;
  30. m_flags.fAllowSetSize = FALSE;
  31. m_flags.fAllowGetSize = FALSE;
  32. m_flags.fAllowSetFont = FALSE;
  33. m_flags.fAllowGetFont = FALSE;
  34. m_flags.fAllowSetText = FALSE;
  35. m_flags.fAllowGetText = FALSE;
  36. m_flags.fAllowSetToolTip = FALSE;
  37. m_flags.fAllowGetToolTip = FALSE;
  38. m_propID.Set( id );
  39. m_propEnabled.Set( TRUE );
  40. m_propVisible.Set( TRUE );
  41. m_propFont.Set( NULL );
  42. m_propText.Set( NULL );
  43. m_propToolTip.Set( NULL );
  44. }
  45. /* ~ C C A N D U I E X T E N S I O N */
  46. /*------------------------------------------------------------------------------
  47. Denstructor of CCandUIExtension
  48. ------------------------------------------------------------------------------*/
  49. CCandUIExtension::~CCandUIExtension( void )
  50. {
  51. }
  52. /* G E T I D */
  53. /*------------------------------------------------------------------------------
  54. ------------------------------------------------------------------------------*/
  55. HRESULT CCandUIExtension::GetID( LONG *pid )
  56. {
  57. return m_propID.Get( pid );
  58. }
  59. /* E N A B L E */
  60. /*------------------------------------------------------------------------------
  61. ------------------------------------------------------------------------------*/
  62. HRESULT CCandUIExtension::Enable( void )
  63. {
  64. HRESULT hr;
  65. if (!m_flags.fAllowEnable) {
  66. return E_FAIL;
  67. }
  68. hr = m_propEnabled.Set( TRUE );
  69. if (hr == S_OK) {
  70. GetExtensionMgr()->NotifyExtensionUpdate( this );
  71. }
  72. return (SUCCEEDED(hr) ? S_OK : hr);
  73. }
  74. /* D I S A B L E */
  75. /*------------------------------------------------------------------------------
  76. ------------------------------------------------------------------------------*/
  77. HRESULT CCandUIExtension::Disable( void )
  78. {
  79. HRESULT hr;
  80. if (!m_flags.fAllowDisable) {
  81. return E_FAIL;
  82. }
  83. hr = m_propEnabled.Set( FALSE );
  84. if (hr == S_OK) {
  85. GetExtensionMgr()->NotifyExtensionUpdate( this );
  86. }
  87. return (SUCCEEDED(hr) ? S_OK : hr);
  88. }
  89. /* I S E N A B L E D */
  90. /*------------------------------------------------------------------------------
  91. ------------------------------------------------------------------------------*/
  92. HRESULT CCandUIExtension::IsEnabled( BOOL *pfEnabled )
  93. {
  94. if (!m_flags.fAllowIsEnabled) {
  95. return E_FAIL;
  96. }
  97. return m_propEnabled.Get( pfEnabled );
  98. }
  99. /* S E T P O S I T I O N */
  100. /*------------------------------------------------------------------------------
  101. ------------------------------------------------------------------------------*/
  102. HRESULT CCandUIExtension::SetPosition( POINT *pptPos )
  103. {
  104. HRESULT hr;
  105. if (!m_flags.fAllowSetPosition) {
  106. return E_FAIL;
  107. }
  108. hr = m_propPos.Set( pptPos );
  109. if (hr == S_OK) {
  110. GetExtensionMgr()->NotifyExtensionUpdate( this );
  111. }
  112. return (SUCCEEDED(hr) ? S_OK : hr);
  113. }
  114. /* G E T P O S I T I O N */
  115. /*------------------------------------------------------------------------------
  116. ------------------------------------------------------------------------------*/
  117. HRESULT CCandUIExtension::GetPosition( POINT *pptPos )
  118. {
  119. if (!m_flags.fAllowGetPosition) {
  120. return E_FAIL;
  121. }
  122. return m_propPos.Get( pptPos );
  123. }
  124. /* S E T S I Z E */
  125. /*------------------------------------------------------------------------------
  126. ------------------------------------------------------------------------------*/
  127. HRESULT CCandUIExtension::SetSize( SIZE *psize )
  128. {
  129. HRESULT hr;
  130. if (!m_flags.fAllowSetSize) {
  131. return E_FAIL;
  132. }
  133. hr = m_propSize.Set( psize );
  134. if (hr == S_OK) {
  135. GetExtensionMgr()->NotifyExtensionUpdate( this );
  136. }
  137. return (SUCCEEDED(hr) ? S_OK : hr);
  138. }
  139. /* G E T S I Z E */
  140. /*------------------------------------------------------------------------------
  141. ------------------------------------------------------------------------------*/
  142. HRESULT CCandUIExtension::GetSize( SIZE *psize )
  143. {
  144. if (!m_flags.fAllowGetSize) {
  145. return E_FAIL;
  146. }
  147. return m_propSize.Get( psize );
  148. }
  149. /* S H O W */
  150. /*------------------------------------------------------------------------------
  151. ------------------------------------------------------------------------------*/
  152. HRESULT CCandUIExtension::Show( void )
  153. {
  154. HRESULT hr;
  155. if (!m_flags.fAllowShow) {
  156. return E_FAIL;
  157. }
  158. hr = m_propVisible.Set( TRUE );
  159. if (hr == S_OK) {
  160. GetExtensionMgr()->NotifyExtensionUpdate( this );
  161. }
  162. return (SUCCEEDED(hr) ? S_OK : hr);
  163. }
  164. /* H I D E */
  165. /*------------------------------------------------------------------------------
  166. ------------------------------------------------------------------------------*/
  167. HRESULT CCandUIExtension::Hide( void )
  168. {
  169. HRESULT hr;
  170. if (!m_flags.fAllowHide) {
  171. return E_FAIL;
  172. }
  173. hr = m_propVisible.Set( FALSE );
  174. if (hr == S_OK) {
  175. GetExtensionMgr()->NotifyExtensionUpdate( this );
  176. }
  177. return (SUCCEEDED(hr) ? S_OK : hr);
  178. }
  179. /* I S V I S I B L E */
  180. /*------------------------------------------------------------------------------
  181. ------------------------------------------------------------------------------*/
  182. HRESULT CCandUIExtension::IsVisible( BOOL *pfVisible )
  183. {
  184. if (!m_flags.fAllowIsVisible) {
  185. return E_FAIL;
  186. }
  187. return m_propVisible.Get( pfVisible );
  188. }
  189. /* S E T F O N T */
  190. /*------------------------------------------------------------------------------
  191. ------------------------------------------------------------------------------*/
  192. HRESULT CCandUIExtension::SetFont( LOGFONTW *plf )
  193. {
  194. HRESULT hr;
  195. if (!m_flags.fAllowSetFont) {
  196. return E_FAIL;
  197. }
  198. hr = m_propFont.Set( plf );
  199. if (hr == S_OK) {
  200. GetExtensionMgr()->NotifyExtensionUpdate( this );
  201. }
  202. return (SUCCEEDED(hr) ? S_OK : hr);
  203. }
  204. /* G E T F O N T */
  205. /*------------------------------------------------------------------------------
  206. ------------------------------------------------------------------------------*/
  207. HRESULT CCandUIExtension::GetFont( LOGFONTW *plf )
  208. {
  209. if (!m_flags.fAllowGetFont) {
  210. return E_FAIL;
  211. }
  212. return m_propFont.Get( plf );
  213. }
  214. /* S E T T E X T */
  215. /*------------------------------------------------------------------------------
  216. ------------------------------------------------------------------------------*/
  217. HRESULT CCandUIExtension::SetText( BSTR bstr )
  218. {
  219. HRESULT hr;
  220. if (!m_flags.fAllowSetText) {
  221. return E_FAIL;
  222. }
  223. hr = m_propText.Set( bstr );
  224. if (hr == S_OK) {
  225. GetExtensionMgr()->NotifyExtensionUpdate( this );
  226. }
  227. return (SUCCEEDED(hr) ? S_OK : hr);
  228. }
  229. /* G E T T E X T */
  230. /*------------------------------------------------------------------------------
  231. ------------------------------------------------------------------------------*/
  232. HRESULT CCandUIExtension::GetText( BSTR *pbstr )
  233. {
  234. if (!m_flags.fAllowGetText) {
  235. return E_FAIL;
  236. }
  237. return m_propText.Get( pbstr );
  238. }
  239. /* S E T T O O L T I P S T R I N G */
  240. /*------------------------------------------------------------------------------
  241. ------------------------------------------------------------------------------*/
  242. HRESULT CCandUIExtension::SetToolTipString( BSTR bstr )
  243. {
  244. HRESULT hr;
  245. if (!m_flags.fAllowSetToolTip) {
  246. return E_FAIL;
  247. }
  248. hr = m_propToolTip.Set( bstr );
  249. if (hr == S_OK) {
  250. GetExtensionMgr()->NotifyExtensionUpdate( this );
  251. }
  252. return (SUCCEEDED(hr) ? S_OK : hr);
  253. }
  254. /* G E T T O O L T I P S T R I N G */
  255. /*------------------------------------------------------------------------------
  256. ------------------------------------------------------------------------------*/
  257. HRESULT CCandUIExtension::GetToolTipString( BSTR *pbstr )
  258. {
  259. if (!m_flags.fAllowGetToolTip) {
  260. return E_FAIL;
  261. }
  262. return m_propToolTip.Get( pbstr );
  263. }
  264. /* G E T I D */
  265. /*------------------------------------------------------------------------------
  266. ------------------------------------------------------------------------------*/
  267. LONG CCandUIExtension::GetID( void )
  268. {
  269. return m_propID.Get();
  270. }
  271. /* I S E N A B L E D */
  272. /*------------------------------------------------------------------------------
  273. ------------------------------------------------------------------------------*/
  274. BOOL CCandUIExtension::IsEnabled( void )
  275. {
  276. return m_propEnabled.Get();
  277. }
  278. /* I S V I S I B L E */
  279. /*------------------------------------------------------------------------------
  280. ------------------------------------------------------------------------------*/
  281. BOOL CCandUIExtension::IsVisible( void )
  282. {
  283. return m_propVisible.Get();
  284. }
  285. /* G E T F O N T */
  286. /*------------------------------------------------------------------------------
  287. ------------------------------------------------------------------------------*/
  288. HFONT CCandUIExtension::GetFont( void )
  289. {
  290. return m_propFont.Get();
  291. }
  292. /* G E T T E X T */
  293. /*------------------------------------------------------------------------------
  294. ------------------------------------------------------------------------------*/
  295. LPCWSTR CCandUIExtension::GetText( void )
  296. {
  297. return m_propText.Get();
  298. }
  299. /* G E T T O O L T I P S T R I N G */
  300. /*------------------------------------------------------------------------------
  301. ------------------------------------------------------------------------------*/
  302. LPCWSTR CCandUIExtension::GetToolTipString( void )
  303. {
  304. return m_propToolTip.Get();
  305. }
  306. /*============================================================================*/
  307. /* */
  308. /* C E X T E N S I O N B U T T O N */
  309. /* */
  310. /*============================================================================*/
  311. /* C E X T E N S I O N B U T T O N */
  312. /*------------------------------------------------------------------------------
  313. Constructor of CExtensionButton
  314. ------------------------------------------------------------------------------*/
  315. CExtensionButton::CExtensionButton( CCandUIExtensionMgr *pExtMgr, LONG id ) : CCandUIExtension( pExtMgr, id )
  316. {
  317. SIZE size;
  318. m_flags.fAllowEnable = TRUE;
  319. m_flags.fAllowDisable = TRUE;
  320. m_flags.fAllowIsEnabled = TRUE;
  321. m_flags.fAllowShow = FALSE;
  322. m_flags.fAllowHide = FALSE;
  323. m_flags.fAllowIsVisible = FALSE;
  324. m_flags.fAllowSetPosition = FALSE;
  325. m_flags.fAllowGetPosition = FALSE;
  326. m_flags.fAllowSetSize = FALSE;
  327. m_flags.fAllowGetSize = TRUE;
  328. m_flags.fAllowSetFont = FALSE;
  329. m_flags.fAllowGetFont = FALSE;
  330. m_flags.fAllowSetText = FALSE;
  331. m_flags.fAllowGetText = FALSE;
  332. m_flags.fAllowSetToolTip = TRUE;
  333. m_flags.fAllowGetToolTip = TRUE;
  334. size.cx = 16 + 2;
  335. size.cy = 16 + 2;
  336. m_propEnabled.Set( TRUE );
  337. m_propVisible.Set( TRUE );
  338. m_propFont.Set( NULL );
  339. m_propText.Set( NULL );
  340. m_propToolTip.Set( NULL );
  341. m_propSize.Set( &size );
  342. m_flagsEx.fAllowSetToggleState = FALSE;
  343. m_flagsEx.fAllowGetToggleState = FALSE;
  344. m_flagsEx.fAllowSetIcon = TRUE;
  345. m_flagsEx.fAllowSetBitmap = TRUE;
  346. m_propToggled.Set( FALSE );
  347. m_hIcon = NULL;
  348. m_hBitmap = NULL;
  349. m_pSink = NULL;
  350. }
  351. /* ~ C E X T E N S I O N B U T T O N */
  352. /*------------------------------------------------------------------------------
  353. Destructor of CExtensionButton
  354. ------------------------------------------------------------------------------*/
  355. CExtensionButton::~CExtensionButton( void )
  356. {
  357. if (m_pSink != NULL) {
  358. m_pSink->Release();
  359. }
  360. }
  361. /* S E T I C O N */
  362. /*------------------------------------------------------------------------------
  363. ------------------------------------------------------------------------------*/
  364. HRESULT CExtensionButton::SetIcon( HICON hIcon )
  365. {
  366. if (!m_flagsEx.fAllowSetIcon) {
  367. return E_FAIL;
  368. }
  369. if (hIcon == NULL) {
  370. return E_INVALIDARG;
  371. }
  372. m_hBitmap = NULL;
  373. m_hIcon = hIcon;
  374. GetExtensionMgr()->NotifyExtensionUpdate( this );
  375. return S_OK;
  376. }
  377. /* S E T B I T M A P */
  378. /*------------------------------------------------------------------------------
  379. ------------------------------------------------------------------------------*/
  380. HRESULT CExtensionButton::SetBitmap( HBITMAP hBitmap )
  381. {
  382. if (!m_flagsEx.fAllowSetBitmap) {
  383. return E_FAIL;
  384. }
  385. if (hBitmap == NULL) {
  386. return E_INVALIDARG;
  387. }
  388. m_hIcon = NULL;
  389. m_hBitmap = hBitmap;
  390. GetExtensionMgr()->NotifyExtensionUpdate( this );
  391. return S_OK;
  392. }
  393. /* G E T T O G G L E S T A T E */
  394. /*------------------------------------------------------------------------------
  395. ------------------------------------------------------------------------------*/
  396. HRESULT CExtensionButton::GetToggleState( BOOL *pfToggled )
  397. {
  398. if (!m_flagsEx.fAllowGetToggleState) {
  399. return E_FAIL;
  400. }
  401. return m_propToggled.Get( pfToggled );
  402. }
  403. /* S E T T O G G L E S T A T E */
  404. /*------------------------------------------------------------------------------
  405. ------------------------------------------------------------------------------*/
  406. HRESULT CExtensionButton::SetToggleState( BOOL fToggle )
  407. {
  408. HRESULT hr;
  409. if (!m_flagsEx.fAllowSetToggleState) {
  410. return E_FAIL;
  411. }
  412. hr = m_propToggled.Set( fToggle );
  413. if (hr == S_OK) {
  414. GetExtensionMgr()->NotifyExtensionUpdate( this );
  415. }
  416. return (SUCCEEDED(hr) ? S_OK : hr);
  417. }
  418. /* G E T I C O N */
  419. /*------------------------------------------------------------------------------
  420. ------------------------------------------------------------------------------*/
  421. HICON CExtensionButton::GetIcon( void )
  422. {
  423. return m_hIcon;
  424. }
  425. /* G E T B I T M A P */
  426. /*------------------------------------------------------------------------------
  427. ------------------------------------------------------------------------------*/
  428. HBITMAP CExtensionButton::GetBitmap( void )
  429. {
  430. return m_hBitmap;
  431. }
  432. /* I S T O G G L E D */
  433. /*------------------------------------------------------------------------------
  434. ------------------------------------------------------------------------------*/
  435. BOOL CExtensionButton::IsToggled( void )
  436. {
  437. return m_propToggled.Get();
  438. }
  439. /*============================================================================*/
  440. /* */
  441. /* C E X T E N S I O N S P A C E */
  442. /* */
  443. /*============================================================================*/
  444. /* C E X T E N S I O N S P A C E */
  445. /*------------------------------------------------------------------------------
  446. Constructor of CExtensionSpace
  447. ------------------------------------------------------------------------------*/
  448. CExtensionSpace::CExtensionSpace( CCandUIExtensionMgr *pExtMgr, LONG id ) : CCandUIExtension( pExtMgr, id )
  449. {
  450. m_flags.fAllowEnable = FALSE;
  451. m_flags.fAllowDisable = FALSE;
  452. m_flags.fAllowIsEnabled = FALSE;
  453. m_flags.fAllowShow = FALSE;
  454. m_flags.fAllowHide = FALSE;
  455. m_flags.fAllowIsVisible = FALSE;
  456. m_flags.fAllowSetPosition = FALSE;
  457. m_flags.fAllowGetPosition = FALSE;
  458. m_flags.fAllowSetSize = TRUE;
  459. m_flags.fAllowGetSize = TRUE;
  460. m_flags.fAllowSetFont = FALSE;
  461. m_flags.fAllowGetFont = FALSE;
  462. m_flags.fAllowSetText = FALSE;
  463. m_flags.fAllowGetText = FALSE;
  464. m_flags.fAllowSetToolTip = FALSE;
  465. m_flags.fAllowGetToolTip = FALSE;
  466. m_propEnabled.Set( TRUE );
  467. m_propVisible.Set( TRUE );
  468. m_propFont.Set( NULL );
  469. m_propText.Set( NULL );
  470. m_propToolTip.Set( NULL );
  471. }
  472. /* ~ C E X T E N S I O N S P A C E */
  473. /*------------------------------------------------------------------------------
  474. Destructor of CExtensionSpace
  475. ------------------------------------------------------------------------------*/
  476. CExtensionSpace::~CExtensionSpace( void )
  477. {
  478. }
  479. /* C R E A T E I N T E R F A C E O B J E C T */
  480. /*------------------------------------------------------------------------------
  481. ------------------------------------------------------------------------------*/
  482. HRESULT CExtensionSpace::CreateInterfaceObject( REFIID riid, void **ppvObj )
  483. {
  484. CCandUIExtSpace *pObject;
  485. HRESULT hr;
  486. pObject = new CCandUIExtSpace( GetExtensionMgr()->GetCandidateUI(), this );
  487. if (pObject == NULL) {
  488. return E_OUTOFMEMORY;
  489. }
  490. hr = pObject->QueryInterface( riid, ppvObj );
  491. pObject->Release();
  492. return hr;
  493. }
  494. /* N O T I F Y E X T E N S I O N E V E N T */
  495. /*------------------------------------------------------------------------------
  496. ------------------------------------------------------------------------------*/
  497. HRESULT CExtensionSpace::NotifyExtensionEvent( DWORD dwCommand, LPARAM lParam )
  498. {
  499. return S_OK;
  500. }
  501. /* C R E A T E U I O B J E C T */
  502. /*------------------------------------------------------------------------------
  503. ------------------------------------------------------------------------------*/
  504. CUIFObject *CExtensionSpace::CreateUIObject( CUIFObject *pParent, DWORD dwID, const RECT *prc )
  505. {
  506. return NULL;
  507. }
  508. /* U P D A T E O B J P R O P */
  509. /*------------------------------------------------------------------------------
  510. ------------------------------------------------------------------------------*/
  511. void CExtensionSpace::UpdateObjProp( CUIFObject *pUIObject )
  512. {
  513. }
  514. /* U P D A T E E X T P R O P */
  515. /*------------------------------------------------------------------------------
  516. ------------------------------------------------------------------------------*/
  517. void CExtensionSpace::UpdateExtProp( CUIFObject *pUIObject )
  518. {
  519. }
  520. /*============================================================================*/
  521. /* */
  522. /* C E X T E N S I O N P U S H B U T T O N */
  523. /* */
  524. /*============================================================================*/
  525. /* C E X T E N S I O N P U S H B U T T O N */
  526. /*------------------------------------------------------------------------------
  527. Constructor of CExtensionPushButton
  528. ------------------------------------------------------------------------------*/
  529. CExtensionPushButton::CExtensionPushButton( CCandUIExtensionMgr *pExtMgr, LONG id ) : CExtensionButton( pExtMgr, id )
  530. {
  531. m_flagsEx.fAllowSetToggleState = FALSE;
  532. m_flagsEx.fAllowGetToggleState = FALSE;
  533. m_flagsEx.fAllowSetIcon = TRUE;
  534. m_flagsEx.fAllowSetBitmap = TRUE;
  535. }
  536. /* ~ C E X T E N S I O N P U S H B U T T O N */
  537. /*------------------------------------------------------------------------------
  538. Destructor of CExtensionPushButton
  539. ------------------------------------------------------------------------------*/
  540. CExtensionPushButton::~CExtensionPushButton( void )
  541. {
  542. }
  543. /* C R E A T E I N T E R F A C E O B J E C T */
  544. /*------------------------------------------------------------------------------
  545. ------------------------------------------------------------------------------*/
  546. HRESULT CExtensionPushButton::CreateInterfaceObject( REFIID riid, void **ppvObj )
  547. {
  548. CCandUIExtPushButton *pObject;
  549. HRESULT hr;
  550. pObject = new CCandUIExtPushButton( GetExtensionMgr()->GetCandidateUI(), this );
  551. if (pObject == NULL) {
  552. return E_OUTOFMEMORY;
  553. }
  554. hr = pObject->QueryInterface( riid, ppvObj );
  555. pObject->Release();
  556. return hr;
  557. }
  558. /* N O T I F Y E X T E N S I O N E V E N T */
  559. /*------------------------------------------------------------------------------
  560. ------------------------------------------------------------------------------*/
  561. HRESULT CExtensionPushButton::NotifyExtensionEvent( DWORD dwCommand, LPARAM lParam )
  562. {
  563. if (m_pSink != NULL) {
  564. m_pSink->OnButtonPushed( GetID() );
  565. }
  566. return S_OK;
  567. }
  568. /* C R E A T E U I O B J E C T */
  569. /*------------------------------------------------------------------------------
  570. ------------------------------------------------------------------------------*/
  571. CUIFObject *CExtensionPushButton::CreateUIObject( CUIFObject *pParent, DWORD dwID, const RECT *prc )
  572. {
  573. Assert( pParent != NULL );
  574. Assert( prc != NULL );
  575. return new CUIFButton2( pParent, dwID, prc, UIBUTTON_PUSH );
  576. }
  577. /* U P D A T E O B J P R O P */
  578. /*------------------------------------------------------------------------------
  579. ------------------------------------------------------------------------------*/
  580. void CExtensionPushButton::UpdateObjProp( CUIFObject *pUIObject )
  581. {
  582. CUIFButton *pButton = (CUIFButton *)pUIObject;
  583. Assert( pButton != NULL );
  584. // button face
  585. if (GetIcon() != NULL) {
  586. pButton->SetIcon( GetIcon() );
  587. }
  588. else if (GetBitmap() != NULL) {
  589. pButton->SetBitmap( GetBitmap() );
  590. }
  591. // tooltip
  592. pButton->SetToolTip( GetToolTipString() );
  593. }
  594. /* U P D A T E E X T P R O P */
  595. /*------------------------------------------------------------------------------
  596. ------------------------------------------------------------------------------*/
  597. void CExtensionPushButton::UpdateExtProp( CUIFObject *pUIObject )
  598. {
  599. }
  600. /*============================================================================*/
  601. /* */
  602. /* C E X T E N S I O N T O G G L E B U T T O N */
  603. /* */
  604. /*============================================================================*/
  605. /* C E X T E N S I O N T O G G L E B U T T O N */
  606. /*------------------------------------------------------------------------------
  607. Constructor of CExtensionToggleButton
  608. ------------------------------------------------------------------------------*/
  609. CExtensionToggleButton::CExtensionToggleButton( CCandUIExtensionMgr *pExtMgr, LONG id ) : CExtensionButton( pExtMgr, id )
  610. {
  611. m_flagsEx.fAllowSetToggleState = TRUE;
  612. m_flagsEx.fAllowGetToggleState = TRUE;
  613. m_flagsEx.fAllowSetIcon = TRUE;
  614. m_flagsEx.fAllowSetBitmap = TRUE;
  615. }
  616. /* ~ C E X T E N S I O N T O G G L E B U T T O N */
  617. /*------------------------------------------------------------------------------
  618. Destructor of CExtensionToggleButton
  619. ------------------------------------------------------------------------------*/
  620. CExtensionToggleButton::~CExtensionToggleButton( void )
  621. {
  622. }
  623. /* C R E A T E I N T E R F A C E O B J E C T */
  624. /*------------------------------------------------------------------------------
  625. ------------------------------------------------------------------------------*/
  626. HRESULT CExtensionToggleButton::CreateInterfaceObject( REFIID riid, void **ppvObj )
  627. {
  628. CCandUIExtToggleButton *pObject;
  629. HRESULT hr;
  630. pObject = new CCandUIExtToggleButton( GetExtensionMgr()->GetCandidateUI(), this );
  631. if (pObject == NULL) {
  632. return E_OUTOFMEMORY;
  633. }
  634. hr = pObject->QueryInterface( riid, ppvObj );
  635. pObject->Release();
  636. return hr;
  637. }
  638. /* N O T I F Y E X T E N S I O N E V E N T */
  639. /*------------------------------------------------------------------------------
  640. ------------------------------------------------------------------------------*/
  641. HRESULT CExtensionToggleButton::NotifyExtensionEvent( DWORD dwCommand, LPARAM lParam )
  642. {
  643. if (m_pSink != NULL) {
  644. m_pSink->OnButtonPushed( GetID() );
  645. }
  646. return S_OK;
  647. }
  648. /* C R E A T E U I O B J E C T */
  649. /*------------------------------------------------------------------------------
  650. ------------------------------------------------------------------------------*/
  651. CUIFObject *CExtensionToggleButton::CreateUIObject( CUIFObject *pParent, DWORD dwID, const RECT *prc )
  652. {
  653. Assert( pParent != NULL );
  654. Assert( prc != NULL );
  655. return new CUIFButton2( pParent, dwID, prc, UIBUTTON_TOGGLE );
  656. }
  657. /* U P D A T E O B J P R O P */
  658. /*------------------------------------------------------------------------------
  659. ------------------------------------------------------------------------------*/
  660. void CExtensionToggleButton::UpdateObjProp( CUIFObject *pUIObject )
  661. {
  662. CUIFButton *pButton = (CUIFButton *)pUIObject;
  663. Assert( pButton != NULL );
  664. // button face
  665. if (GetIcon() != NULL) {
  666. pButton->SetIcon( GetIcon() );
  667. }
  668. else if (GetBitmap() != NULL) {
  669. pButton->SetBitmap( GetBitmap() );
  670. }
  671. // toggle state
  672. pButton->SetToggleState( IsToggled() );
  673. // tooltip
  674. pButton->SetToolTip( GetToolTipString() );
  675. }
  676. /* U P D A T E E X T P R O P */
  677. /*------------------------------------------------------------------------------
  678. ------------------------------------------------------------------------------*/
  679. void CExtensionToggleButton::UpdateExtProp( CUIFObject *pUIObject )
  680. {
  681. CUIFButton *pButton = (CUIFButton *)pUIObject;
  682. Assert( pButton != NULL );
  683. // toggle state
  684. m_propToggled.Set( pButton->GetToggleState() );
  685. }
  686. /*============================================================================*/
  687. /* */
  688. /* C C A N D U I E X T E N S I O N M G R */
  689. /* */
  690. /*============================================================================*/
  691. /* C C A N D U I E X T E N S I O N M G R */
  692. /*------------------------------------------------------------------------------
  693. ------------------------------------------------------------------------------*/
  694. CCandUIExtensionMgr::CCandUIExtensionMgr( void )
  695. {
  696. int i;
  697. m_pCandUI = NULL;
  698. for (i = 0; i < CANDUIEXTENSIONSINK_MAX; i++) {
  699. m_rgSink[i] = NULL;
  700. }
  701. }
  702. /* ~ C C A N D U I E X T E N S I O N M G R */
  703. /*------------------------------------------------------------------------------
  704. ------------------------------------------------------------------------------*/
  705. CCandUIExtensionMgr::~CCandUIExtensionMgr( void )
  706. {
  707. Uninitialize();
  708. }
  709. /* I N I T I A L I Z E */
  710. /*------------------------------------------------------------------------------
  711. ------------------------------------------------------------------------------*/
  712. HRESULT CCandUIExtensionMgr::Initialize( CCandidateUI *pCandUI )
  713. {
  714. m_pCandUI = pCandUI;
  715. #if defined(DEBUG) || defined(_DEBUG)
  716. // check all reference object are unregistered
  717. for (int i = 0; i < CANDUIEXTENSIONSINK_MAX; i++) {
  718. Assert( m_rgSink[i] == NULL );
  719. }
  720. #endif
  721. return S_OK;
  722. }
  723. /* U N I N I T I A L I Z E */
  724. /*------------------------------------------------------------------------------
  725. ------------------------------------------------------------------------------*/
  726. HRESULT CCandUIExtensionMgr::Uninitialize( void )
  727. {
  728. CCandUIExtension *pExtension;
  729. while (pExtension = m_pExtensionList.GetFirst()) {
  730. m_pExtensionList.Remove( pExtension );
  731. delete pExtension;
  732. }
  733. #if defined(DEBUG) || defined(_DEBUG)
  734. // check all reference object are unregistered
  735. for (int i = 0; i < CANDUIEXTENSIONSINK_MAX; i++) {
  736. Assert( m_rgSink[i] == NULL );
  737. }
  738. #endif
  739. return S_OK;
  740. }
  741. /* A D V I S E E V E N T S I N K */
  742. /*------------------------------------------------------------------------------
  743. ------------------------------------------------------------------------------*/
  744. HRESULT CCandUIExtensionMgr::AdviseEventSink( CCandUIExtensionEventSink *pSink )
  745. {
  746. int i;
  747. for (i = 0; i < CANDUIEXTENSIONSINK_MAX; i++) {
  748. if (m_rgSink[i] == NULL) {
  749. m_rgSink[i] = pSink;
  750. return S_OK;
  751. }
  752. }
  753. Assert( FALSE );
  754. return E_FAIL;
  755. }
  756. /* U N A D V I S E E V E N T S I N K */
  757. /*------------------------------------------------------------------------------
  758. ------------------------------------------------------------------------------*/
  759. HRESULT CCandUIExtensionMgr::UnadviseEventSink( CCandUIExtensionEventSink *pSink )
  760. {
  761. int i;
  762. for (i = 0; i < CANDUIEXTENSIONSINK_MAX; i++) {
  763. if (m_rgSink[i] == pSink) {
  764. m_rgSink[i] = NULL;
  765. return S_OK;
  766. }
  767. }
  768. Assert( FALSE );
  769. return E_FAIL;
  770. }
  771. /* N O T I F Y E X T E N S I O N A D D */
  772. /*------------------------------------------------------------------------------
  773. ------------------------------------------------------------------------------*/
  774. void CCandUIExtensionMgr::NotifyExtensionAdd( LONG iExtension )
  775. {
  776. int i;
  777. for (i = 0; i < CANDUIEXTENSIONSINK_MAX; i++) {
  778. if (m_rgSink[i] != NULL) {
  779. m_rgSink[i]->OnExtensionAdd( iExtension );
  780. }
  781. }
  782. }
  783. /* N O T I F Y E X T E N S I O N D E L E T E */
  784. /*------------------------------------------------------------------------------
  785. ------------------------------------------------------------------------------*/
  786. void CCandUIExtensionMgr::NotifyExtensionDelete( LONG iExtension )
  787. {
  788. int i;
  789. for (i = 0; i < CANDUIEXTENSIONSINK_MAX; i++) {
  790. if (m_rgSink[i] != NULL) {
  791. m_rgSink[i]->OnExtensionDeleted( iExtension );
  792. }
  793. }
  794. }
  795. /* N O T I F Y E X T E N S I O N U P D A T E */
  796. /*------------------------------------------------------------------------------
  797. ------------------------------------------------------------------------------*/
  798. void CCandUIExtensionMgr::NotifyExtensionUpdate( CCandUIExtension *pExtension )
  799. {
  800. LONG i;
  801. LONG iExtension;
  802. iExtension = IndexOfExtension( pExtension );
  803. if (iExtension == -1) {
  804. // extension has not been added yet.
  805. // do not send notify
  806. return;
  807. }
  808. for (i = 0; i < CANDUIEXTENSIONSINK_MAX; i++) {
  809. if (m_rgSink[i] != NULL) {
  810. m_rgSink[i]->OnExtensionUpdated( iExtension );
  811. }
  812. }
  813. }
  814. /* G E T E X T E N S I O N N U M */
  815. /*------------------------------------------------------------------------------
  816. ------------------------------------------------------------------------------*/
  817. LONG CCandUIExtensionMgr::GetExtensionNum( void )
  818. {
  819. return m_pExtensionList.GetCount();
  820. }
  821. /* G E T E X T E N S I O N */
  822. /*------------------------------------------------------------------------------
  823. ------------------------------------------------------------------------------*/
  824. CCandUIExtension *CCandUIExtensionMgr::GetExtension( LONG iExtension )
  825. {
  826. return m_pExtensionList.Get( iExtension );
  827. }
  828. /* F I N D E X T E N S I O N */
  829. /*------------------------------------------------------------------------------
  830. ------------------------------------------------------------------------------*/
  831. CCandUIExtension *CCandUIExtensionMgr::FindExtension( LONG id )
  832. {
  833. int nExt;
  834. int i;
  835. CCandUIExtension *pExtension;
  836. nExt = m_pExtensionList.GetCount();
  837. for (i = 0; i < nExt; i++) {
  838. pExtension = m_pExtensionList.Get( i );
  839. if (pExtension->GetID() == id) {
  840. return pExtension;
  841. }
  842. }
  843. return NULL;
  844. }
  845. /* A D D E X T O B J E C T */
  846. /*------------------------------------------------------------------------------
  847. ------------------------------------------------------------------------------*/
  848. HRESULT CCandUIExtensionMgr::AddExtObject( LONG id, REFIID riid, void **ppvObj )
  849. {
  850. CCandUIExtension *pExtension;
  851. if (ppvObj == NULL) {
  852. return E_INVALIDARG;
  853. }
  854. // create extension
  855. pExtension = NULL;
  856. if (IsEqualGUID( riid, IID_ITfCandUIExtSpace )) {
  857. pExtension = new CExtensionSpace( this, id );
  858. }
  859. else if (IsEqualGUID( riid, IID_ITfCandUIExtPushButton )) {
  860. pExtension = new CExtensionPushButton( this, id );
  861. }
  862. else if (IsEqualGUID( riid, IID_ITfCandUIExtToggleButton )) {
  863. pExtension = new CExtensionToggleButton( this, id );
  864. }
  865. else {
  866. return E_INVALIDARG;
  867. }
  868. if (pExtension == NULL) {
  869. return E_OUTOFMEMORY;
  870. }
  871. // create interface object
  872. if (FAILED(pExtension->CreateInterfaceObject( riid, ppvObj ))) {
  873. delete pExtension;
  874. return E_FAIL;
  875. }
  876. // add extension to list
  877. m_pExtensionList.Add( pExtension );
  878. NotifyExtensionAdd( IndexOfExtension( pExtension ) );
  879. return S_OK;
  880. }
  881. /* G E T E X T O B J E C T */
  882. /*------------------------------------------------------------------------------
  883. ------------------------------------------------------------------------------*/
  884. HRESULT CCandUIExtensionMgr::GetExtObject( LONG id, REFIID riid, void **ppvObj )
  885. {
  886. CCandUIExtension *pExtension;
  887. if (ppvObj == NULL) {
  888. return E_INVALIDARG;
  889. }
  890. // find extension
  891. pExtension = FindExtension( id );
  892. if (pExtension == NULL) {
  893. return E_FAIL;
  894. }
  895. // create interface object
  896. return pExtension->CreateInterfaceObject( riid, ppvObj );
  897. }
  898. /* D E L E T E E X T O B J E C T */
  899. /*------------------------------------------------------------------------------
  900. ------------------------------------------------------------------------------*/
  901. HRESULT CCandUIExtensionMgr::DeleteExtObject( LONG id )
  902. {
  903. CCandUIExtension *pExtension;
  904. LONG iExtension;
  905. // find extension
  906. pExtension = FindExtension( id );
  907. if (pExtension == NULL) {
  908. return E_FAIL;
  909. }
  910. // remove from list and delete
  911. iExtension = IndexOfExtension( pExtension );
  912. m_pExtensionList.Remove( pExtension );
  913. delete pExtension;
  914. // send notify
  915. NotifyExtensionDelete( iExtension );
  916. return S_OK;
  917. }
  918. /* C R E A T E U I O B J E C T */
  919. /*------------------------------------------------------------------------------
  920. ------------------------------------------------------------------------------*/
  921. CUIFObject *CCandUIExtensionMgr::CreateUIObject( LONG iExtension, CUIFObject *pParent, DWORD dwID, const RECT *prc )
  922. {
  923. CCandUIExtension *pExtension = GetExtension( iExtension );
  924. if (pExtension != NULL) {
  925. return pExtension->CreateUIObject( pParent, dwID, prc );
  926. }
  927. else {
  928. return NULL;
  929. }
  930. }
  931. /* U P D A T E O B J P R O P */
  932. /*------------------------------------------------------------------------------
  933. ------------------------------------------------------------------------------*/
  934. void CCandUIExtensionMgr::UpdateObjProp( LONG iExtension, CUIFObject *pUIObject )
  935. {
  936. CCandUIExtension *pExtension = GetExtension( iExtension );
  937. if (pExtension != NULL) {
  938. pExtension->UpdateObjProp( pUIObject );
  939. }
  940. }
  941. /* U P D A T E E X T P R O P */
  942. /*------------------------------------------------------------------------------
  943. ------------------------------------------------------------------------------*/
  944. void CCandUIExtensionMgr::UpdateExtProp( LONG iExtension, CUIFObject *pUIObject )
  945. {
  946. CCandUIExtension *pExtension = GetExtension( iExtension );
  947. if (pExtension != NULL) {
  948. pExtension->UpdateExtProp( pUIObject );
  949. }
  950. }
  951. /* I N D E X O F E X T E N S I O N */
  952. /*------------------------------------------------------------------------------
  953. ------------------------------------------------------------------------------*/
  954. LONG CCandUIExtensionMgr::IndexOfExtension( CCandUIExtension *pExtension )
  955. {
  956. return m_pExtensionList.Find( pExtension );
  957. }
  958. /*============================================================================*/
  959. /* */
  960. /* C C A N D U I E X T E N S I O N E V E N T S I N K */
  961. /* */
  962. /*============================================================================*/
  963. /* C C A N D U I E X T E N S I O N E V E N T S I N K */
  964. /*------------------------------------------------------------------------------
  965. ------------------------------------------------------------------------------*/
  966. CCandUIExtensionEventSink::CCandUIExtensionEventSink( void )
  967. {
  968. m_pExtensionMgr = NULL;
  969. }
  970. /* ~ C C A N D U I E X T E N S I O N E V E N T S I N K */
  971. /*------------------------------------------------------------------------------
  972. ------------------------------------------------------------------------------*/
  973. CCandUIExtensionEventSink::~CCandUIExtensionEventSink( void )
  974. {
  975. Assert( m_pExtensionMgr == NULL );
  976. if (m_pExtensionMgr != NULL) {
  977. DoneEventSink();
  978. }
  979. }
  980. /* I N I T E V E N T S I N K */
  981. /*------------------------------------------------------------------------------
  982. ------------------------------------------------------------------------------*/
  983. HRESULT CCandUIExtensionEventSink::InitEventSink( CCandUIExtensionMgr *pExtensionMgr )
  984. {
  985. Assert( pExtensionMgr != NULL );
  986. Assert( m_pExtensionMgr == NULL );
  987. if (pExtensionMgr == NULL) {
  988. return E_INVALIDARG;
  989. }
  990. m_pExtensionMgr = pExtensionMgr;
  991. return m_pExtensionMgr->AdviseEventSink( this );
  992. }
  993. /* D O N E E V E N T S I N K */
  994. /*------------------------------------------------------------------------------
  995. ------------------------------------------------------------------------------*/
  996. HRESULT CCandUIExtensionEventSink::DoneEventSink( void )
  997. {
  998. HRESULT hr;
  999. Assert( m_pExtensionMgr != NULL );
  1000. if (m_pExtensionMgr == NULL) {
  1001. return E_FAIL;
  1002. }
  1003. hr = m_pExtensionMgr->UnadviseEventSink( this );
  1004. m_pExtensionMgr = NULL;
  1005. return hr;
  1006. }