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.

1424 lines
35 KiB

  1. //
  2. // candmgr.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include "mscandui.h"
  7. #include "candmgr.h"
  8. #include "candutil.h"
  9. /*============================================================================*/
  10. /* */
  11. /* C C A N D I D A T E I T E M */
  12. /* */
  13. /*============================================================================*/
  14. /* C C A N D I D A T E I T E M */
  15. /*------------------------------------------------------------------------------
  16. Constructor of CCandidateItem
  17. ------------------------------------------------------------------------------*/
  18. CCandidateItem::CCandidateItem( int iCandItem, ITfCandidateString *pCandStr )
  19. {
  20. ITfCandidateStringFlag *pCandStrFlag;
  21. ITfCandidateStringInlineComment *pCandStrInlineComment;
  22. ITfCandidateStringPopupComment *pCandStrPopupComment;
  23. ITfCandidateStringColor *pCandStrColor;
  24. ITfCandidateStringFixture *pCandStrFixture;
  25. ITfCandidateStringIcon *pCandStrIcon;
  26. BSTR bstr;
  27. DWORD dwFlag;
  28. BOOL fHasFlag;
  29. Assert( pCandStr != NULL );
  30. m_iCandItemOrg = iCandItem;
  31. m_pCandStr = pCandStr;
  32. m_pCandStr->AddRef();
  33. m_nIndex = 0;
  34. m_bstr = NULL;
  35. m_bstrInlineComment = NULL;
  36. m_bstrPopupComment = NULL;
  37. m_dwPopupCommentGroupID = 0;
  38. m_fHasColor = FALSE;
  39. m_cr = RGB( 0, 0, 0 );
  40. m_bstrPrefix = NULL;
  41. m_bstrSuffix = NULL;
  42. m_hIcon = NULL;
  43. m_fVisible = TRUE;
  44. m_fPopupCommentVisible = FALSE;
  45. //
  46. // get candidate string information
  47. //
  48. // index
  49. m_pCandStr->GetIndex( &m_nIndex );
  50. // candidate string
  51. if (m_pCandStr->GetString( &bstr ) == S_OK && bstr != NULL) {
  52. m_bstr = SysAllocString( bstr );
  53. SysFreeString( bstr );
  54. }
  55. // flag
  56. fHasFlag = FALSE;
  57. if (m_pCandStr->QueryInterface( IID_ITfCandidateStringFlag, (void **)&pCandStrFlag ) == S_OK) {
  58. fHasFlag = (pCandStrFlag->GetFlag( &dwFlag) == S_OK);
  59. pCandStrFlag->Release();
  60. }
  61. // inline comment
  62. if (!fHasFlag || (dwFlag & CANDUISTR_HASINLINECOMMENT) != 0) {
  63. if (m_pCandStr->QueryInterface( IID_ITfCandidateStringInlineComment, (void **)&pCandStrInlineComment ) == S_OK) {
  64. if (pCandStrInlineComment->GetInlineCommentString( &bstr ) == S_OK && bstr != NULL) {
  65. m_bstrInlineComment = SysAllocString( bstr );
  66. SysFreeString( bstr );
  67. }
  68. pCandStrInlineComment->Release();
  69. }
  70. }
  71. // popup comment
  72. if (!fHasFlag || (dwFlag & CANDUISTR_HASPOPUPCOMMENT) != 0) {
  73. if (m_pCandStr->QueryInterface( IID_ITfCandidateStringPopupComment, (void **)&pCandStrPopupComment ) == S_OK) {
  74. DWORD dwGroupID;
  75. if (pCandStrPopupComment->GetPopupCommentString( &bstr ) == S_OK && bstr != NULL) {
  76. m_bstrPopupComment = SysAllocString( bstr );
  77. SysFreeString( bstr );
  78. }
  79. if (pCandStrPopupComment->GetPopupCommentGroupID( &dwGroupID ) == S_OK) {
  80. m_dwPopupCommentGroupID = dwGroupID;
  81. }
  82. pCandStrPopupComment->Release();
  83. }
  84. }
  85. // color
  86. if (!fHasFlag || (dwFlag & CANDUISTR_HASCOLOR) != 0) {
  87. if (m_pCandStr->QueryInterface( IID_ITfCandidateStringColor, (void **)&pCandStrColor ) == S_OK) {
  88. CANDUICOLOR col;
  89. if (pCandStrColor->GetColor( &col ) == S_OK) {
  90. switch (col.type) {
  91. case CANDUICOL_DEFAULT:
  92. default: {
  93. break;
  94. }
  95. case CANDUICOL_SYSTEM: {
  96. m_fHasColor = TRUE;
  97. m_cr = GetSysColor( col.nIndex );
  98. break;
  99. }
  100. case CANDUICOL_COLORREF: {
  101. m_fHasColor = TRUE;
  102. m_cr = col.cr;
  103. break;
  104. }
  105. }
  106. }
  107. pCandStrColor->Release();
  108. }
  109. }
  110. // prefix/suffix string
  111. if (!fHasFlag || (dwFlag & CANDUISTR_HASFIXTURE) != 0) {
  112. if (m_pCandStr->QueryInterface( IID_ITfCandidateStringFixture, (void **)&pCandStrFixture ) == S_OK) {
  113. if (pCandStrFixture->GetPrefixString( &bstr ) == S_OK && bstr != NULL) {
  114. m_bstrPrefix = SysAllocString( bstr );
  115. SysFreeString( bstr );
  116. }
  117. if (pCandStrFixture->GetSuffixString( &bstr ) == S_OK && bstr != NULL) {
  118. m_bstrSuffix = SysAllocString( bstr );
  119. SysFreeString( bstr );
  120. }
  121. pCandStrFixture->Release();
  122. }
  123. }
  124. // icon
  125. if (!fHasFlag || (dwFlag & CANDUISTR_HASICON) != 0) {
  126. if (m_pCandStr->QueryInterface( IID_ITfCandidateStringIcon, (void **)&pCandStrIcon ) == S_OK) {
  127. HICON hIcon = NULL;
  128. if (pCandStrIcon->GetIcon( &hIcon ) == S_OK && hIcon != NULL) {
  129. m_hIcon = hIcon;
  130. }
  131. pCandStrIcon->Release();
  132. }
  133. }
  134. }
  135. /* ~ C C A N D I D A T E I T E M */
  136. /*------------------------------------------------------------------------------
  137. Destructor of CCandidateItem
  138. ------------------------------------------------------------------------------*/
  139. CCandidateItem::~CCandidateItem( void )
  140. {
  141. // dispose buffers
  142. if (m_bstr != NULL) {
  143. SysFreeString( m_bstr );
  144. }
  145. if (m_bstrInlineComment != NULL) {
  146. SysFreeString( m_bstrInlineComment );
  147. }
  148. if (m_bstrPopupComment != NULL) {
  149. SysFreeString( m_bstrPopupComment );
  150. }
  151. if (m_bstrPrefix != NULL) {
  152. SysFreeString( m_bstrPrefix );
  153. }
  154. if (m_bstrSuffix != NULL) {
  155. SysFreeString( m_bstrSuffix );
  156. }
  157. // release candidate string
  158. m_pCandStr->Release();
  159. }
  160. /* G E T I C A N D I T E M O R G */
  161. /*------------------------------------------------------------------------------
  162. Get index of candidat item
  163. NOTE: this is index of candidate item in candidate list
  164. (use to identify original index of candidate item)
  165. ------------------------------------------------------------------------------*/
  166. int CCandidateItem::GetICandItemOrg( void )
  167. {
  168. return m_iCandItemOrg;
  169. }
  170. /* G E T I N D E X */
  171. /*------------------------------------------------------------------------------
  172. Get index of item
  173. NOTE: this is index of candidate item stored in candidate string
  174. (use to specify candidate item to client in notification)
  175. ------------------------------------------------------------------------------*/
  176. ULONG CCandidateItem::GetIndex( void )
  177. {
  178. return m_nIndex;
  179. }
  180. /* G E T S T R I N G */
  181. /*------------------------------------------------------------------------------
  182. Get candidate string of item
  183. ------------------------------------------------------------------------------*/
  184. LPCWSTR CCandidateItem::GetString( void )
  185. {
  186. return m_bstr;
  187. }
  188. /* G E T I N L I N E C O M M E N T */
  189. /*------------------------------------------------------------------------------
  190. Get inline comment
  191. ------------------------------------------------------------------------------*/
  192. LPCWSTR CCandidateItem::GetInlineComment( void )
  193. {
  194. return m_bstrInlineComment;
  195. }
  196. /* G E T P O P U P C O M M E N T */
  197. /*------------------------------------------------------------------------------
  198. Get popup comment
  199. ------------------------------------------------------------------------------*/
  200. LPCWSTR CCandidateItem::GetPopupComment( void )
  201. {
  202. return m_bstrPopupComment;
  203. }
  204. /* G E T P O P U P C O M M E N T G R O U P I D */
  205. /*------------------------------------------------------------------------------
  206. ------------------------------------------------------------------------------*/
  207. DWORD CCandidateItem::GetPopupCommentGroupID( void )
  208. {
  209. return m_dwPopupCommentGroupID;
  210. }
  211. /* G E T C O L O R */
  212. /*------------------------------------------------------------------------------
  213. Get color
  214. ------------------------------------------------------------------------------*/
  215. BOOL CCandidateItem::GetColor( COLORREF *pcr )
  216. {
  217. Assert( pcr != NULL );
  218. if (m_fHasColor) {
  219. *pcr = m_cr;
  220. return TRUE;
  221. }
  222. return FALSE;
  223. }
  224. /* G E T P R E F I X S T R I N G */
  225. /*------------------------------------------------------------------------------
  226. Get prefix string
  227. ------------------------------------------------------------------------------*/
  228. LPCWSTR CCandidateItem::GetPrefixString( void )
  229. {
  230. return m_bstrPrefix;
  231. }
  232. /* G E T S U F F I X S T R I N G */
  233. /*------------------------------------------------------------------------------
  234. Get suffix string
  235. ------------------------------------------------------------------------------*/
  236. LPCWSTR CCandidateItem::GetSuffixString( void )
  237. {
  238. return m_bstrSuffix;
  239. }
  240. /* G E T I C O N */
  241. /*------------------------------------------------------------------------------
  242. Get icon
  243. ------------------------------------------------------------------------------*/
  244. HICON CCandidateItem::GetIcon( void )
  245. {
  246. return m_hIcon;
  247. }
  248. /* S E T V I S I B L E S T A T E */
  249. /*------------------------------------------------------------------------------
  250. Set visible status
  251. ------------------------------------------------------------------------------*/
  252. void CCandidateItem::SetVisibleState( BOOL fVisible )
  253. {
  254. m_fVisible = fVisible;
  255. }
  256. /* I S V I S I B L E */
  257. /*------------------------------------------------------------------------------
  258. Get visible status
  259. Returns TRUE when the item is visible, FALSE when invisible.
  260. ------------------------------------------------------------------------------*/
  261. BOOL CCandidateItem::IsVisible( void )
  262. {
  263. return m_fVisible;
  264. }
  265. /* S E T P O P U P C O M M E N T S T A T E */
  266. /*------------------------------------------------------------------------------
  267. Set popup comment status
  268. ------------------------------------------------------------------------------*/
  269. void CCandidateItem::SetPopupCommentState( BOOL fVisible )
  270. {
  271. m_fPopupCommentVisible = fVisible;
  272. }
  273. /* I S P O P U P C O M M E N T V I S I B L E */
  274. /*------------------------------------------------------------------------------
  275. Get visible status of popup comment
  276. Returns TRUE when the popup comment of item is visible, FALSE when invisible.
  277. ------------------------------------------------------------------------------*/
  278. BOOL CCandidateItem::IsPopupCommentVisible( void )
  279. {
  280. return m_fPopupCommentVisible;
  281. }
  282. /*============================================================================*/
  283. /* */
  284. /* C C A N D I D A T E L I S T */
  285. /* */
  286. /*============================================================================*/
  287. /* C C A N D I D A T E L I S T */
  288. /*------------------------------------------------------------------------------
  289. Constructor of CCandidateList
  290. ------------------------------------------------------------------------------*/
  291. CCandidateList::CCandidateList( CCandListMgr *pCandListMgr, ITfCandidateList *pCandList )
  292. {
  293. Assert( pCandListMgr != NULL );
  294. Assert( pCandList != NULL );
  295. m_pCandListMgr = pCandListMgr;
  296. m_pOptionsList = NULL;
  297. m_pCandList = pCandList;
  298. m_rgCandItem = NULL;
  299. m_nCandItem = 0;
  300. m_pExtraCandItem = NULL;
  301. m_bstrTip = NULL;
  302. m_fRawData = FALSE;
  303. m_bstrRawData = NULL;
  304. m_hbmpRawData = NULL;
  305. m_hemfRawData = NULL;
  306. m_nIndexRawData = 0;
  307. m_fIndexRawData = FALSE;
  308. m_iItemSel = ICANDITEM_NULL;
  309. //
  310. if (m_pCandList != NULL) {
  311. m_pCandList->AddRef();
  312. }
  313. }
  314. CCandidateList::CCandidateList( CCandListMgr *pCandListMgr, ITfOptionsCandidateList *pCandList )
  315. {
  316. Assert( pCandListMgr != NULL );
  317. Assert( pCandList != NULL );
  318. m_pCandListMgr = pCandListMgr;
  319. m_pOptionsList = pCandList;
  320. m_pCandList = NULL;
  321. m_rgCandItem = NULL;
  322. m_nCandItem = 0;
  323. m_pExtraCandItem = NULL;
  324. m_bstrTip = NULL;
  325. m_fRawData = FALSE;
  326. m_bstrRawData = NULL;
  327. m_hbmpRawData = NULL;
  328. m_hemfRawData = NULL;
  329. m_nIndexRawData = 0;
  330. m_fIndexRawData = FALSE;
  331. m_iItemSel = ICANDITEM_NULL;
  332. //
  333. if (m_pOptionsList != NULL) {
  334. m_pOptionsList->AddRef();
  335. }
  336. }
  337. /* ~ C C A N D I D A T E L I S T */
  338. /*------------------------------------------------------------------------------
  339. Destructor of CCandidateList
  340. ------------------------------------------------------------------------------*/
  341. CCandidateList::~CCandidateList( void )
  342. {
  343. Uninitialize();
  344. if (m_pCandList != NULL) {
  345. m_pCandList->Release();
  346. }
  347. if (m_pOptionsList != NULL) {
  348. m_pOptionsList->Release();
  349. }
  350. }
  351. /* I N I T I A L I Z E */
  352. /*------------------------------------------------------------------------------
  353. Initialize CandidateList
  354. ------------------------------------------------------------------------------*/
  355. HRESULT CCandidateList::Initialize( void )
  356. {
  357. ITfCandidateListExtraCandidate *pCandListExtraCand;
  358. ITfCandidateListTip *pCandListTip;
  359. ITfCandidateListRawData *pCandListRawData;
  360. ITfCandidateString *pCandStr;
  361. ULONG nCandItem;
  362. ULONG i;
  363. if (m_pCandList == NULL &&
  364. m_pOptionsList == NULL) {
  365. return E_INVALIDARG;
  366. }
  367. //
  368. //
  369. //
  370. Assert( m_rgCandItem == NULL );
  371. Assert( m_nCandItem == 0 );
  372. //
  373. // build options item list (if present)
  374. //
  375. if (m_pOptionsList) {
  376. m_nCandItem = 0;
  377. m_pOptionsList->GetOptionsCandidateNum( &nCandItem );
  378. if (nCandItem != 0) {
  379. m_rgCandItem = new CCandidateItem*[ nCandItem ];
  380. if (m_rgCandItem == NULL)
  381. return E_OUTOFMEMORY;
  382. for (i = 0; i < nCandItem; i++) {
  383. if (SUCCEEDED(m_pOptionsList->GetOptionsCandidate( i, &pCandStr ))) {
  384. m_rgCandItem[m_nCandItem] = new CCandidateItem( m_nCandItem, pCandStr );;
  385. m_nCandItem++;
  386. pCandStr->Release();
  387. }
  388. }
  389. }
  390. }
  391. //
  392. // build candidate item list
  393. //
  394. if (m_pCandList) {
  395. m_nCandItem = 0;
  396. m_pCandList->GetCandidateNum( &nCandItem );
  397. if (nCandItem != 0) {
  398. m_rgCandItem = new CCandidateItem*[ nCandItem ];
  399. if (m_rgCandItem == NULL)
  400. return E_OUTOFMEMORY;
  401. for (i = 0; i < nCandItem; i++) {
  402. if (SUCCEEDED(m_pCandList->GetCandidate( i, &pCandStr ))) {
  403. m_rgCandItem[m_nCandItem] = new CCandidateItem( m_nCandItem, pCandStr );;
  404. m_nCandItem++;
  405. pCandStr->Release();
  406. }
  407. }
  408. }
  409. //
  410. // get extended information of candidate list
  411. //
  412. // extra item
  413. if (m_pCandList->QueryInterface( IID_ITfCandidateListExtraCandidate, (void **)&pCandListExtraCand ) == S_OK) {
  414. if (pCandListExtraCand->GetExtraCandidate( &pCandStr ) == S_OK) {
  415. m_pExtraCandItem = new CCandidateItem( ICANDITEM_EXTRA, pCandStr );
  416. pCandStr->Release();
  417. }
  418. pCandListExtraCand->Release();
  419. }
  420. // tip string
  421. if (m_pCandList->QueryInterface( IID_ITfCandidateListTip, (void **)&pCandListTip ) == S_OK) {
  422. BSTR bstr;
  423. if (pCandListTip->GetTipString( &bstr ) == S_OK) {
  424. m_bstrTip = SysAllocString( bstr );
  425. SysFreeString( bstr );
  426. }
  427. pCandListTip->Release();
  428. }
  429. // raw data
  430. if (m_pCandList->QueryInterface( IID_ITfCandidateListRawData, (void **)&pCandListRawData ) == S_OK) {
  431. CANDUIRAWDATA RawData;
  432. // raw data
  433. if (pCandListRawData->GetRawData( &RawData ) == S_OK) {
  434. m_fRawData = TRUE;
  435. m_kRawData = RawData.type;
  436. switch (RawData.type) {
  437. case CANDUIRDT_STRING: {
  438. m_bstrRawData = SysAllocString( RawData.bstr );
  439. SysFreeString( RawData.bstr );
  440. break;
  441. }
  442. case CANDUIRDT_BITMAP: {
  443. m_hbmpRawData = RawData.hbmp;
  444. break;
  445. }
  446. case CANDUIRDT_METAFILE: {
  447. m_hemfRawData = RawData.hemf;
  448. break;
  449. }
  450. }
  451. }
  452. // raw data index
  453. if (pCandListRawData->GetRawDataIndex( &m_nIndexRawData ) == S_OK) {
  454. m_fIndexRawData = TRUE;
  455. }
  456. pCandListRawData->Release();
  457. }
  458. }
  459. // initialize selection
  460. if (m_pOptionsList)
  461. {
  462. m_iItemSel = ICANDITEM_NULL;
  463. }
  464. else
  465. {
  466. m_iItemSel = 0;
  467. }
  468. return S_OK;
  469. }
  470. /* U N I N I T I A L I Z E */
  471. /*------------------------------------------------------------------------------
  472. ------------------------------------------------------------------------------*/
  473. HRESULT CCandidateList::Uninitialize( void )
  474. {
  475. int i;
  476. if (m_rgCandItem == NULL) {
  477. Assert( m_nCandItem == 0 );
  478. }
  479. // dispose canditem objects
  480. for (i = 0; i < m_nCandItem; i++) {
  481. delete m_rgCandItem[i];
  482. }
  483. // dispose canditem list
  484. if (m_rgCandItem != NULL) {
  485. delete m_rgCandItem;
  486. m_rgCandItem = NULL;
  487. }
  488. m_nCandItem = 0;
  489. // dispose extra item
  490. if (m_pExtraCandItem != NULL) {
  491. delete m_pExtraCandItem;
  492. m_pExtraCandItem = NULL;
  493. }
  494. // dispose tip
  495. if (m_bstrTip != NULL) {
  496. SysFreeString( m_bstrTip );
  497. m_bstrTip = NULL;
  498. }
  499. // dispose raw data
  500. m_fRawData = FALSE;
  501. if (m_bstrRawData != NULL) {
  502. SysFreeString( m_bstrRawData );
  503. }
  504. m_bstrRawData = NULL;
  505. m_hbmpRawData = NULL;
  506. m_hemfRawData = NULL;
  507. m_nIndexRawData = 0;
  508. m_fIndexRawData = FALSE;
  509. return S_OK;
  510. }
  511. /* G E T I T E M C O U N T */
  512. /*------------------------------------------------------------------------------
  513. Get count of candidate item object
  514. ------------------------------------------------------------------------------*/
  515. int CCandidateList::GetItemCount( void )
  516. {
  517. return m_nCandItem;
  518. }
  519. /* G E T C A N D I D A T E I T E M */
  520. /*------------------------------------------------------------------------------
  521. Get candidate item object
  522. ------------------------------------------------------------------------------*/
  523. CCandidateItem *CCandidateList::GetCandidateItem( int iItem )
  524. {
  525. if (0 <= iItem && iItem < m_nCandItem) {
  526. return m_rgCandItem[ iItem ];
  527. }
  528. else if (iItem == ICANDITEM_EXTRA) {
  529. return m_pExtraCandItem;
  530. }
  531. return NULL;
  532. }
  533. /* S W A P C A N D I D A T E I T E M */
  534. /*------------------------------------------------------------------------------
  535. Swap two candidate items
  536. NOTE: Only used from CCandFnSort.
  537. NOTE: Do not send SetSelection notification here. It resets filtering
  538. string and makes conflict filtering state.
  539. ------------------------------------------------------------------------------*/
  540. void CCandidateList::SwapCandidateItem( int iItem1, int iItem2 )
  541. {
  542. if ((iItem1 != iItem2) && (0 <= iItem1 && iItem1 <= m_nCandItem) && (0 <= iItem2 && iItem2 <= m_nCandItem)) {
  543. CCandidateItem *pCandItem1;
  544. CCandidateItem *pCandItem2;
  545. int iItemSel;
  546. // swap items
  547. pCandItem1 = m_rgCandItem[ iItem1 ];
  548. pCandItem2 = m_rgCandItem[ iItem2 ];
  549. m_rgCandItem[ iItem1 ] = pCandItem2;
  550. m_rgCandItem[ iItem2 ] = pCandItem1;
  551. // check selection
  552. iItemSel = GetSelection();
  553. if (iItemSel == iItem1) {
  554. CCandidateList::SetSelection( iItem2 );
  555. }
  556. else if (iItemSel == iItem2) {
  557. CCandidateList::SetSelection( iItem1 );
  558. }
  559. }
  560. }
  561. /* G E T E X T R A C A N D I T E M */
  562. /*------------------------------------------------------------------------------
  563. ------------------------------------------------------------------------------*/
  564. CCandidateItem *CCandidateList::GetExtraCandItem( void )
  565. {
  566. return m_pExtraCandItem;
  567. }
  568. /* G E T E X T R A C A N D I T E M */
  569. /*------------------------------------------------------------------------------
  570. ------------------------------------------------------------------------------*/
  571. ULONG CCandidateList::GetExtraCandIndex( void )
  572. {
  573. if (m_pExtraCandItem == NULL) {
  574. return 0;
  575. }
  576. return m_pExtraCandItem->GetIndex();
  577. }
  578. /* G E T T I P S T R I N G */
  579. /*------------------------------------------------------------------------------
  580. ------------------------------------------------------------------------------*/
  581. LPCWSTR CCandidateList::GetTipString( void )
  582. {
  583. return m_bstrTip;
  584. }
  585. /* F H A S R A W D A T A */
  586. /*------------------------------------------------------------------------------
  587. Returns TRUE when CandidateList has raw data
  588. ------------------------------------------------------------------------------*/
  589. BOOL CCandidateList::FHasRawData( void )
  590. {
  591. return m_fRawData;
  592. }
  593. /* G E T R A W D A T A T Y P E */
  594. /*------------------------------------------------------------------------------
  595. Get raw data type
  596. ------------------------------------------------------------------------------*/
  597. CANDUIRAWDATATYPE CCandidateList::GetRawDataType( void )
  598. {
  599. return m_kRawData;
  600. }
  601. /* G E T R A W D A T A S T R I N G */
  602. /*------------------------------------------------------------------------------
  603. Get raw data string
  604. ------------------------------------------------------------------------------*/
  605. LPCWSTR CCandidateList::GetRawDataString( void )
  606. {
  607. return m_bstrRawData;
  608. }
  609. /* G E T R A W D A T A B I T M A P */
  610. /*------------------------------------------------------------------------------
  611. Get raw data bitmap
  612. ------------------------------------------------------------------------------*/
  613. HBITMAP CCandidateList::GetRawDataBitmap( void )
  614. {
  615. return m_hbmpRawData;
  616. }
  617. /* G E T R A W D A T A M E T A F I L E */
  618. /*------------------------------------------------------------------------------
  619. Get raw data metafile
  620. ------------------------------------------------------------------------------*/
  621. HENHMETAFILE CCandidateList::GetRawDataMetafile( void )
  622. {
  623. return m_hemfRawData;
  624. }
  625. /* G E T R A W D A T A I N D E X */
  626. /*------------------------------------------------------------------------------
  627. ------------------------------------------------------------------------------*/
  628. ULONG CCandidateList::GetRawDataIndex( void )
  629. {
  630. return m_nIndexRawData;
  631. }
  632. /* F R A W D A T A S E L E C T A B L E */
  633. /*------------------------------------------------------------------------------
  634. ------------------------------------------------------------------------------*/
  635. BOOL CCandidateList::FRawDataSelectable( void )
  636. {
  637. return (m_fRawData && m_fIndexRawData);
  638. }
  639. /* S E T S E L E C T I O N */
  640. /*------------------------------------------------------------------------------
  641. ------------------------------------------------------------------------------*/
  642. void CCandidateList::SetSelection( int iItem )
  643. {
  644. m_iItemSel = iItem;
  645. }
  646. /* G E T S E L E C T I O N */
  647. /*------------------------------------------------------------------------------
  648. ------------------------------------------------------------------------------*/
  649. int CCandidateList::GetSelection( void )
  650. {
  651. return m_iItemSel;
  652. }
  653. /* M A P I I T E M T O I N D E X */
  654. /*------------------------------------------------------------------------------
  655. ------------------------------------------------------------------------------*/
  656. HRESULT CCandidateList::MapIItemToIndex( int iItem, ULONG *pnIndex )
  657. {
  658. Assert( pnIndex != NULL );
  659. if (0 <= iItem && iItem < m_nCandItem) {
  660. *pnIndex = m_rgCandItem[ iItem ]->GetIndex();
  661. return S_OK;
  662. }
  663. return E_FAIL;
  664. }
  665. /* M A P I N D E X T O I I T E M */
  666. /*------------------------------------------------------------------------------
  667. ------------------------------------------------------------------------------*/
  668. HRESULT CCandidateList::MapIndexToIItem( ULONG nIndex, int *piItem )
  669. {
  670. int iItem;
  671. for (iItem = 0; iItem < m_nCandItem; iItem++) {
  672. if (m_rgCandItem[ iItem ]->GetIndex() == nIndex) {
  673. *piItem = iItem;
  674. return S_OK;
  675. }
  676. }
  677. return E_FAIL;
  678. }
  679. /*============================================================================*/
  680. /* */
  681. /* C C A N D L I S T M G R */
  682. /* */
  683. /*============================================================================*/
  684. /* C C A N D L I S T M G R */
  685. /*------------------------------------------------------------------------------
  686. Constructor of CCandListMgr
  687. ------------------------------------------------------------------------------*/
  688. CCandListMgr::CCandListMgr( void )
  689. {
  690. int i;
  691. m_pCandUI = NULL;
  692. m_pCandListObj = NULL;
  693. m_pOptionsListObj = NULL;
  694. for (i = 0; i < CANDLISTSINK_MAX; i++) {
  695. m_rgCandListSink[i] = NULL;
  696. }
  697. }
  698. /* ~ C C A N D L I S T M G R */
  699. /*------------------------------------------------------------------------------
  700. Destructor of CCandListMgr
  701. ------------------------------------------------------------------------------*/
  702. CCandListMgr::~CCandListMgr( void )
  703. {
  704. Uninitialize();
  705. }
  706. /* I N I T I A L I Z E */
  707. /*------------------------------------------------------------------------------
  708. ------------------------------------------------------------------------------*/
  709. HRESULT CCandListMgr::Initialize( CCandidateUI *pCandUI )
  710. {
  711. m_pCandUI = pCandUI;
  712. #if defined(DEBUG) || defined(_DEBUG)
  713. // check all reference object are unregistered
  714. for (int i = 0; i < CANDLISTSINK_MAX; i++) {
  715. Assert( m_rgCandListSink[i] == NULL );
  716. }
  717. #endif
  718. return S_OK;
  719. }
  720. /* U N I N I T I A L I Z E */
  721. /*------------------------------------------------------------------------------
  722. ------------------------------------------------------------------------------*/
  723. HRESULT CCandListMgr::Uninitialize( void )
  724. {
  725. if (m_pOptionsListObj != NULL) {
  726. delete m_pOptionsListObj;
  727. m_pOptionsListObj = NULL;
  728. }
  729. if (m_pCandListObj != NULL) {
  730. delete m_pCandListObj;
  731. m_pCandListObj = NULL;
  732. }
  733. #if defined(DEBUG) || defined(_DEBUG)
  734. // check all reference object are unregistered
  735. for (int i = 0; i < CANDLISTSINK_MAX; i++) {
  736. Assert( m_rgCandListSink[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. Register event sink
  744. ------------------------------------------------------------------------------*/
  745. HRESULT CCandListMgr::AdviseEventSink( CCandListEventSink *pSink )
  746. {
  747. int i;
  748. for (i = 0; i < CANDLISTSINK_MAX; i++) {
  749. if (m_rgCandListSink[i] == NULL) {
  750. m_rgCandListSink[i] = pSink;
  751. return S_OK;
  752. }
  753. }
  754. Assert( FALSE );
  755. return E_FAIL;
  756. }
  757. /* U N A D V I S E E V E N T S I N K */
  758. /*------------------------------------------------------------------------------
  759. Unregister event sink
  760. ------------------------------------------------------------------------------*/
  761. HRESULT CCandListMgr::UnadviseEventSink( CCandListEventSink *pSink )
  762. {
  763. int i;
  764. for (i = 0; i < CANDLISTSINK_MAX; i++) {
  765. if (m_rgCandListSink[i] == pSink) {
  766. m_rgCandListSink[i] = NULL;
  767. return S_OK;
  768. }
  769. }
  770. Assert( FALSE );
  771. return E_FAIL;
  772. }
  773. /* N O T I F Y S E T C A N D L I S T */
  774. /*------------------------------------------------------------------------------
  775. Notify to candidate functions that candidate list has been set
  776. ------------------------------------------------------------------------------*/
  777. void CCandListMgr::NotifySetCandList( void )
  778. {
  779. int i;
  780. for (i = 0; i < CANDLISTSINK_MAX; i++) {
  781. if (m_rgCandListSink[i] != NULL) {
  782. m_rgCandListSink[i]->OnSetCandidateList();
  783. }
  784. }
  785. }
  786. /* N O T I F Y C L E A R C A N D L I S T */
  787. /*------------------------------------------------------------------------------
  788. Notify to candidate functions that candidate list has been cleared
  789. ------------------------------------------------------------------------------*/
  790. void CCandListMgr::NotifyClearCandList( void )
  791. {
  792. int i;
  793. for (i = 0; i < CANDLISTSINK_MAX; i++) {
  794. if (m_rgCandListSink[i] != NULL) {
  795. m_rgCandListSink[i]->OnClearCandidateList();
  796. }
  797. }
  798. }
  799. /* N O T I F Y C A N D I T E M U P D A T E */
  800. /*------------------------------------------------------------------------------
  801. Notify to candidate functions that candidate item has been updated
  802. ------------------------------------------------------------------------------*/
  803. void CCandListMgr::NotifyCandItemUpdate( CCandListEventSink *pSink )
  804. {
  805. int i;
  806. for (i = 0; i < CANDLISTSINK_MAX; i++) {
  807. if (m_rgCandListSink[i] != NULL && m_rgCandListSink[i] != pSink) {
  808. m_rgCandListSink[i]->OnCandItemUpdate();
  809. }
  810. }
  811. }
  812. /* N O T I F Y S E L E C T I O N C H A N G E D */
  813. /*------------------------------------------------------------------------------
  814. Notify to candidate functions that selection has been changed
  815. ------------------------------------------------------------------------------*/
  816. void CCandListMgr::NotifySelectionChanged( CCandListEventSink *pSink )
  817. {
  818. int i;
  819. for (i = 0; i < CANDLISTSINK_MAX; i++) {
  820. if (m_rgCandListSink[i] != NULL && m_rgCandListSink[i] != pSink) {
  821. m_rgCandListSink[i]->OnSelectionChanged();
  822. }
  823. }
  824. }
  825. /* S E T O P T I O N S E L E C T I O N */
  826. /*------------------------------------------------------------------------------
  827. SetSelection
  828. ------------------------------------------------------------------------------*/
  829. HRESULT CCandListMgr::SetOptionSelection( int iItem, CCandListEventSink *pSink )
  830. {
  831. CCandidateItem *pCandItem;
  832. Assert( GetCandList() != NULL );
  833. // check if item is valid and visible
  834. pCandItem = GetOptionsList()->GetCandidateItem( iItem );
  835. if (pCandItem == NULL || !pCandItem->IsVisible()) {
  836. return E_FAIL;
  837. }
  838. GetOptionsList()->SetSelection( iItem );
  839. // NotifySelectionChanged( pSink );
  840. return S_OK;
  841. }
  842. /* S E T S E L E C T I O N */
  843. /*------------------------------------------------------------------------------
  844. SetSelection
  845. ------------------------------------------------------------------------------*/
  846. HRESULT CCandListMgr::SetSelection( int iItem, CCandListEventSink *pSink )
  847. {
  848. CCandidateItem *pCandItem;
  849. Assert( GetCandList() != NULL );
  850. // check if item is valid and visible
  851. pCandItem = GetCandList()->GetCandidateItem( iItem );
  852. if (pCandItem == NULL || !pCandItem->IsVisible()) {
  853. return E_FAIL;
  854. }
  855. GetCandList()->SetSelection( iItem );
  856. NotifySelectionChanged( pSink );
  857. return S_OK;
  858. }
  859. /* S E T C A N D I D A T E L I S T */
  860. /*------------------------------------------------------------------------------
  861. Set candidate list
  862. ------------------------------------------------------------------------------*/
  863. HRESULT CCandListMgr::SetCandidateList( ITfCandidateList *pCandList )
  864. {
  865. HRESULT hr;
  866. if ((m_pCandListObj != NULL) || (m_pOptionsListObj !=NULL)) {
  867. return E_FAIL;
  868. }
  869. // create candidate list object
  870. m_pCandListObj = new CCandidateList( this, pCandList );
  871. if (m_pCandListObj == NULL) {
  872. return E_OUTOFMEMORY;
  873. }
  874. hr = m_pCandListObj->Initialize();
  875. if (FAILED(hr)) {
  876. delete m_pCandListObj;
  877. m_pCandListObj = NULL;
  878. }
  879. CComPtr<ITfOptionsCandidateList> cpOptionsList;
  880. if (pCandList && pCandList->QueryInterface(IID_ITfOptionsCandidateList, (void **)&cpOptionsList) == S_OK) {
  881. m_pOptionsListObj = new CCandidateList( this, cpOptionsList);
  882. if (m_pOptionsListObj == NULL) {
  883. return E_OUTOFMEMORY;
  884. }
  885. hr = m_pOptionsListObj->Initialize();
  886. if (FAILED(hr)) {
  887. delete m_pOptionsListObj;
  888. m_pOptionsListObj = NULL;
  889. }
  890. }
  891. // send notification
  892. NotifySetCandList();
  893. return hr;
  894. }
  895. /* G E T O P T I O N S L I S T */
  896. /*------------------------------------------------------------------------------
  897. Get candidate list
  898. ------------------------------------------------------------------------------*/
  899. HRESULT CCandListMgr::GetOptionsCandidateList( ITfOptionsCandidateList **ppCandList )
  900. {
  901. if (ppCandList == NULL) {
  902. return E_INVALIDARG;
  903. }
  904. if (GetOptionsList() == NULL) {
  905. return E_FAIL;
  906. }
  907. *ppCandList = GetOptionsList()->GetOptionsCandidateList();
  908. (*ppCandList)->AddRef();
  909. return S_OK;
  910. }
  911. /* G E T C A N D I D A T E L I S T */
  912. /*------------------------------------------------------------------------------
  913. Get candidate list
  914. ------------------------------------------------------------------------------*/
  915. HRESULT CCandListMgr::GetCandidateList( ITfCandidateList **ppCandList )
  916. {
  917. if (ppCandList == NULL) {
  918. return E_INVALIDARG;
  919. }
  920. if (GetCandList() == NULL) {
  921. return E_FAIL;
  922. }
  923. *ppCandList = GetCandList()->GetCandidateList();
  924. (*ppCandList)->AddRef();
  925. return S_OK;
  926. }
  927. /* C L E A R C A N D I D A T E L I S T */
  928. /*------------------------------------------------------------------------------
  929. Clear candidate list
  930. ------------------------------------------------------------------------------*/
  931. HRESULT CCandListMgr::ClearCandiateList( void )
  932. {
  933. HRESULT hr = S_OK;
  934. if ((m_pCandListObj == NULL) && (NULL == m_pOptionsListObj)) {
  935. return S_OK;
  936. }
  937. // dispose candidate list object
  938. if (m_pCandListObj) {
  939. hr = m_pCandListObj->Uninitialize();
  940. delete m_pCandListObj;
  941. m_pCandListObj = NULL;
  942. }
  943. if ((S_OK == hr) && m_pOptionsListObj) {
  944. // disponse options list object if any
  945. hr = m_pOptionsListObj->Uninitialize();
  946. delete m_pOptionsListObj;
  947. m_pOptionsListObj = NULL;
  948. }
  949. if (hr == S_OK) {
  950. // send notification
  951. NotifyClearCandList();
  952. }
  953. return hr;
  954. }
  955. /*============================================================================*/
  956. /* */
  957. /* C C A N D U I S T Y L E E V E N T S I N K */
  958. /* */
  959. /*============================================================================*/
  960. /* C C A N D U I S T Y L E E V E N T S I N K */
  961. /*------------------------------------------------------------------------------
  962. Constructor of CCandListEventSink
  963. ------------------------------------------------------------------------------*/
  964. CCandListEventSink::CCandListEventSink( void )
  965. {
  966. m_pCandListMgr = NULL;
  967. }
  968. /* ~ C C A N D U I S T Y L E E V E N T S I N K */
  969. /*------------------------------------------------------------------------------
  970. Destructor of CCandListEventSink
  971. ------------------------------------------------------------------------------*/
  972. CCandListEventSink::~CCandListEventSink( void )
  973. {
  974. Assert( m_pCandListMgr == NULL );
  975. if (m_pCandListMgr != NULL) {
  976. DoneEventSink();
  977. }
  978. }
  979. /* I N I T E V E N T S I N K */
  980. /*------------------------------------------------------------------------------
  981. Register candidate UI style event sink
  982. ------------------------------------------------------------------------------*/
  983. HRESULT CCandListEventSink::InitEventSink( CCandListMgr *pCandListMgr )
  984. {
  985. Assert( pCandListMgr != NULL );
  986. Assert( m_pCandListMgr == NULL );
  987. if (pCandListMgr == NULL) {
  988. return E_FAIL;
  989. }
  990. m_pCandListMgr = pCandListMgr;
  991. return m_pCandListMgr->AdviseEventSink( this );
  992. }
  993. /* D O N E E V E N T S I N K */
  994. /*------------------------------------------------------------------------------
  995. Unregister candidate UI style event sink
  996. ------------------------------------------------------------------------------*/
  997. HRESULT CCandListEventSink::DoneEventSink( void )
  998. {
  999. HRESULT hr;
  1000. Assert( m_pCandListMgr != NULL );
  1001. if (m_pCandListMgr == NULL) {
  1002. return E_FAIL;
  1003. }
  1004. hr = m_pCandListMgr->UnadviseEventSink( this );
  1005. m_pCandListMgr = NULL;
  1006. return hr;
  1007. }