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.

5788 lines
147 KiB

  1. //
  2. // wcand.cpp
  3. //
  4. #include "private.h"
  5. #include "wcand.h"
  6. #include "globals.h"
  7. #include "res.h"
  8. #include "candutil.h"
  9. #include "candui.h"
  10. #include "wpopup.h"
  11. #include "candmenu.h"
  12. #include "cuishadw.h"
  13. #define NUM_CANDSTR_MAX 9
  14. // UI object IDs
  15. #define IDUIF_CANDNUMBUTTON 0x00000001
  16. #define IDUIF_CANDIDATELIST 0x00000010
  17. #define IDUIF_CANDIDATEMENU 0x00000011
  18. #define IDUIF_RAWDATA 0x00000012
  19. #define IDUIF_EXTCANDIDATELIST 0x00000013
  20. #define IDUIF_OPTIONSLIST 0x00000014
  21. #define IDUIF_BORDERLEFT 0x00000020
  22. #define IDUIF_BORDERBOTTOM 0x00000021
  23. #define IDUIF_BORDERRAWDATA 0x00000022
  24. #define IDUIF_BORDER 0x00000023
  25. #define IDUIF_CAPTION 0x00000024
  26. #define IDUIF_BORDEREXTRACAND 0x00000025
  27. #define IDUIF_CANDTIPBTN 0x00000026
  28. #define IDUIF_BORDEROPTIONSCAND 0x00000027
  29. #define IDUIF_EXTENDED 0x10000000
  30. #define IDTIMER_POPUPCOMMENT_SELECT 0x6749
  31. #define IDTIMER_POPUPCOMMENT_HOVER 0x674a
  32. #define IDTIMER_MENU_HOVER 0x674b
  33. // The menu hover timer is used by the options list object to emulate menu items
  34. // much more closely. Otherwise there may be a 1 second pause before they lose
  35. // highlighting when the standard cuilib mouseout timer kicks in to detect the
  36. // mouse leave event. It is set to 50ms currently and this causes the menus to
  37. // behave identically to normal menu items. It *only* affects the options menu
  38. // items - everything else gets the existing 1 second timer.
  39. #define CX_COMMENTWINDOW 200
  40. /* C C A N D U I O B J E C T P A R E N T */
  41. /*------------------------------------------------------------------------------
  42. ------------------------------------------------------------------------------*/
  43. CCandUIObjectParent::CCandUIObjectParent( void )
  44. {
  45. m_pUIObjectMgr = NULL;
  46. }
  47. /* ~ C C A N D U I O B J E C T P A R E N T */
  48. /*------------------------------------------------------------------------------
  49. ------------------------------------------------------------------------------*/
  50. CCandUIObjectParent::~CCandUIObjectParent( void )
  51. {
  52. Uninitialize();
  53. }
  54. /* I N T I I A L I Z E */
  55. /*------------------------------------------------------------------------------
  56. ------------------------------------------------------------------------------*/
  57. HRESULT CCandUIObjectParent::Initialize( CCandUIObjectMgr *pUIObjectMgr )
  58. {
  59. Assert( pUIObjectMgr );
  60. m_pUIObjectMgr = pUIObjectMgr;
  61. m_pUIObjectMgr->SetUIObjectParent( this );
  62. return S_OK;
  63. }
  64. /* U N I N I T I A L I Z E */
  65. /*------------------------------------------------------------------------------
  66. ------------------------------------------------------------------------------*/
  67. HRESULT CCandUIObjectParent::Uninitialize( void )
  68. {
  69. if (m_pUIObjectMgr != NULL) {
  70. m_pUIObjectMgr->SetUIObjectParent( NULL );
  71. m_pUIObjectMgr = NULL;
  72. }
  73. return S_OK;
  74. }
  75. /* N O T I F Y U I O B J E C T E V E N T */
  76. /*------------------------------------------------------------------------------
  77. ------------------------------------------------------------------------------*/
  78. void CCandUIObjectParent::NotifyUIObjectEvent( CANDUIOBJECT obj, CANDUIOBJECTEVENT event )
  79. {
  80. if (m_pUIObjectMgr != NULL) {
  81. m_pUIObjectMgr->NotifyUIObjectEvent( obj, event );
  82. }
  83. }
  84. /*============================================================================*/
  85. /* */
  86. /* C C A N D W I N D O W B A S E */
  87. /* */
  88. /*============================================================================*/
  89. /* C C A N D W I N D O W B A S E */
  90. /*------------------------------------------------------------------------------
  91. Constructor of CCandWindowBase
  92. ------------------------------------------------------------------------------*/
  93. CCandWindowBase::CCandWindowBase( CCandidateUI *pCandUI, DWORD dwStyle ) : CUIFWindow( g_hInst, dwStyle | UIWINDOW_HASTOOLTIP | UIWINDOW_HASSHADOW )
  94. {
  95. int cxyIconMenuSize;
  96. m_cRef = 1;
  97. m_pCandUI = pCandUI;
  98. m_pCandAcc = NULL;
  99. m_pCandMenuBtn = NULL;
  100. m_pCandMenu = NULL;
  101. m_fCandMenuOpen = FALSE;
  102. m_nExtUIObj = 0;
  103. m_pCandRawData = NULL;
  104. m_fHasRawData = FALSE;
  105. m_fTargetClipped = FALSE;
  106. m_fOnSelectionChanged = FALSE;
  107. ::SetRect( &m_rcTarget, 0, 0, 0, 0 );
  108. // initialize event sinks
  109. CCandListEventSink::InitEventSink( m_pCandUI->GetCandListMgr() );
  110. CCandUIPropertyEventSink::InitEventSink( m_pCandUI->GetPropertyMgr() );
  111. CCandUIExtensionEventSink::InitEventSink( m_pCandUI->GetExtensionMgr() );
  112. // initialize resources
  113. cxyIconMenuSize = GetMenuIconSize();
  114. m_hIconMenu = (HICON)LoadImage( g_hInst, MAKEINTRESOURCE(IDI_ICONMENU), IMAGE_ICON, cxyIconMenuSize, cxyIconMenuSize, 0 );
  115. m_hIconPopupOn = (HICON)LoadImage( g_hInst, MAKEINTRESOURCE(IDI_ICONPOPUPON), IMAGE_ICON, 16, 16, LR_LOADMAP3DCOLORS );
  116. m_hIconPopupOff = (HICON)LoadImage( g_hInst, MAKEINTRESOURCE(IDI_ICONPOPUPOFF), IMAGE_ICON, 16, 16, LR_LOADMAP3DCOLORS );
  117. m_hIconCandTipOn = (HICON)LoadImage( g_hInst, MAKEINTRESOURCE(IDI_ICONTIPON), IMAGE_ICON, cxyIconMenuSize, cxyIconMenuSize, 0 );
  118. m_hIconCandTipOff = (HICON)LoadImage( g_hInst, MAKEINTRESOURCE(IDI_ICONTIPOFF), IMAGE_ICON, cxyIconMenuSize, cxyIconMenuSize, 0 );
  119. // initialize accessibility object
  120. m_pCandAcc = new CCandAccessible( this );
  121. // initialize as object parent
  122. CCandUIObjectParent::Initialize( m_pCandUI->GetUIObjectMgr() );
  123. m_pCandUI->AddRef();
  124. }
  125. /* ~ C C A N D W I N D O W B A S E */
  126. /*------------------------------------------------------------------------------
  127. Destructor of CCandWindowBase
  128. ------------------------------------------------------------------------------*/
  129. CCandWindowBase::~CCandWindowBase()
  130. {
  131. // uninitialize as object parent
  132. CCandUIObjectParent::Uninitialize();
  133. // dispose resources
  134. DestroyIcon( m_hIconMenu );
  135. DestroyIcon( m_hIconPopupOn );
  136. DestroyIcon( m_hIconPopupOff );
  137. DestroyIcon( m_hIconCandTipOn );
  138. DestroyIcon( m_hIconCandTipOff );
  139. //
  140. CCandUIExtensionEventSink::DoneEventSink();
  141. CCandUIPropertyEventSink::DoneEventSink();
  142. CCandListEventSink::DoneEventSink();
  143. if (m_pCandAcc != NULL) {
  144. m_pCandAcc->Release();
  145. m_pCandAcc = NULL;
  146. }
  147. m_pCandUI->Release();
  148. }
  149. /* A D D R E F */
  150. /*------------------------------------------------------------------------------
  151. Increment reference count
  152. (local method)
  153. ------------------------------------------------------------------------------*/
  154. ULONG CCandWindowBase::AddRef( void )
  155. {
  156. m_cRef++;
  157. return m_cRef;
  158. }
  159. /* R E L E A S E */
  160. /*------------------------------------------------------------------------------
  161. Decrement reference count and release object
  162. (local method)
  163. ------------------------------------------------------------------------------*/
  164. ULONG CCandWindowBase::Release( void )
  165. {
  166. m_cRef--;
  167. if (0 < m_cRef) {
  168. return m_cRef;
  169. }
  170. delete this;
  171. return 0;
  172. }
  173. /* O N S E T C A N D I D A T E L I S T */
  174. /*------------------------------------------------------------------------------
  175. Callback function on SetCandidateList
  176. (CCandListEventSink method)
  177. NOTE: Do not update candidate item in the callback functios
  178. ------------------------------------------------------------------------------*/
  179. void CCandWindowBase::OnSetCandidateList( void )
  180. {
  181. Assert( FInitialized() );
  182. SetCandidateListProc();
  183. LayoutWindow();
  184. SetSelectionProc();
  185. }
  186. /* O N C L E A R C A N D I D A T E L I S T */
  187. /*------------------------------------------------------------------------------
  188. Callback function on ClearCandidateList
  189. (CCandListEventSink method)
  190. NOTE: Do not update candidate item in the callback functios
  191. ------------------------------------------------------------------------------*/
  192. void CCandWindowBase::OnClearCandidateList( void )
  193. {
  194. Assert( FInitialized() );
  195. ClearCandidateListProc();
  196. }
  197. /* O N C A N D I T E M U P D A T E */
  198. /*------------------------------------------------------------------------------
  199. Callback function of candiate item has been updated
  200. (CCandListEventSink method)
  201. NOTE: Do not update candidate item in the callback functios
  202. ------------------------------------------------------------------------------*/
  203. void CCandWindowBase::OnCandItemUpdate( void )
  204. {
  205. Assert( FInitialized() );
  206. SetCandidateListProc();
  207. SetSelectionProc();
  208. }
  209. /* O N S E L E C T I O N C H A N G E D */
  210. /*------------------------------------------------------------------------------
  211. Callback function of candiate selection has been changed
  212. (CCandListEventSink method)
  213. NOTE: Do not update candidate item in the callback functios
  214. ------------------------------------------------------------------------------*/
  215. void CCandWindowBase::OnSelectionChanged( void )
  216. {
  217. Assert( FInitialized() );
  218. Assert( !m_fOnSelectionChanged );
  219. m_fOnSelectionChanged = TRUE;
  220. SetSelectionProc();
  221. m_fOnSelectionChanged = FALSE;
  222. }
  223. /* O N P R O P E R T Y U P D A T E D */
  224. /*------------------------------------------------------------------------------
  225. Callback function on update CandiateUI property
  226. (CCandUIPropertyEventSink method)
  227. ------------------------------------------------------------------------------*/
  228. void CCandWindowBase::OnPropertyUpdated( CANDUIPROPERTY prop, CANDUIPROPERTYEVENT event )
  229. {
  230. Assert( FInitialized() );
  231. switch (prop) {
  232. case CANDUIPROP_CANDWINDOW: {
  233. if (event == CANDUIPROPEV_UPDATEVISIBLESTATE) {
  234. Show( GetPropertyMgr()->GetCandWindowProp()->IsVisible() );
  235. }
  236. else if (event == CANDUIPROPEV_UPDATEPOSITION) {
  237. POINT pt;
  238. GetPropertyMgr()->GetCandWindowProp()->GetPosition( &pt );
  239. SetWindowPos( pt );
  240. }
  241. else {
  242. LayoutWindow();
  243. }
  244. break;
  245. }
  246. case CANDUIPROP_TOOLTIP: {
  247. CUIFToolTip *pWndToolTip = GetToolTipWnd();
  248. CUIFBalloonWindow *pWndCandTip = GetCandTipWindowObj();
  249. if (pWndToolTip != NULL) {
  250. pWndToolTip->SetFont( GetPropertyMgr()->GetToolTipProp()->GetFont() );
  251. pWndToolTip->Enable( GetPropertyMgr()->GetToolTipProp()->IsEnabled() );
  252. }
  253. if (pWndCandTip != NULL) {
  254. pWndCandTip->SetFont( GetPropertyMgr()->GetToolTipProp()->GetFont() );
  255. }
  256. break;
  257. }
  258. default: {
  259. LayoutWindow();
  260. break;
  261. }
  262. }
  263. }
  264. /* O N E X T E N S I O N A D D */
  265. /*------------------------------------------------------------------------------
  266. Callback function on create extension
  267. (CCandUIExtensionEventSink method)
  268. ------------------------------------------------------------------------------*/
  269. void CCandWindowBase::OnExtensionAdd( LONG iExtension )
  270. {
  271. // NOTE: need to rebuild all UI objects to match index correctly
  272. DeleteExtensionObjects();
  273. CreateExtensionObjects();
  274. LayoutWindow();
  275. }
  276. /* O N E X T E N S I O N D E L E T E D */
  277. /*------------------------------------------------------------------------------
  278. Callback function on delete extension
  279. (CCandUIExtensionEventSink method)
  280. ------------------------------------------------------------------------------*/
  281. void CCandWindowBase::OnExtensionDeleted( LONG iExtension )
  282. {
  283. // NOTE: need to rebuild all UI objects to match index correctly
  284. DeleteExtensionObjects();
  285. CreateExtensionObjects();
  286. LayoutWindow();
  287. }
  288. /* O N E X T E N S I O N U P D A T E D */
  289. /*------------------------------------------------------------------------------
  290. Callback function on update extension
  291. (CCandUIExtensionEventSink method)
  292. ------------------------------------------------------------------------------*/
  293. void CCandWindowBase::OnExtensionUpdated( LONG iExtension )
  294. {
  295. SetExtensionObjectProps();
  296. LayoutWindow();
  297. }
  298. /* G E T C L A S S N A M E */
  299. /*------------------------------------------------------------------------------
  300. (CUIFWindow method)
  301. ------------------------------------------------------------------------------*/
  302. LPCTSTR CCandWindowBase::GetClassName( void )
  303. {
  304. return _T( WNDCLASS_CANDWND );
  305. }
  306. /* G E T W N D T I T L E */
  307. /*------------------------------------------------------------------------------
  308. (CUIFWindow method)
  309. ------------------------------------------------------------------------------*/
  310. LPCTSTR CCandWindowBase::GetWndTitle( void )
  311. {
  312. return _T( WNDTITLE_CANDWND );
  313. }
  314. /* I N I T I A L I Z E */
  315. /*------------------------------------------------------------------------------
  316. Initialize UI objects
  317. ------------------------------------------------------------------------------*/
  318. CUIFObject *CCandWindowBase::Initialize( void )
  319. {
  320. //
  321. // Here register candidate window class.
  322. //
  323. WNDCLASSEX WndClass;
  324. LPCTSTR pszClassName = GetClassName();
  325. memset(&WndClass, 0, sizeof(WndClass));
  326. WndClass.cbSize = sizeof(WndClass);
  327. WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_IME;
  328. WndClass.lpfnWndProc = WindowProcedure;
  329. WndClass.cbClsExtra = 0;
  330. WndClass.cbWndExtra = 8;
  331. WndClass.hInstance = g_hInst;
  332. WndClass.hIcon = NULL;
  333. WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  334. WndClass.hbrBackground = NULL;
  335. WndClass.lpszMenuName = NULL;
  336. WndClass.lpszClassName = pszClassName;
  337. WndClass.hIconSm = NULL;
  338. RegisterClassEx(&WndClass);
  339. CUIFObject *pUIObjRet;
  340. CUIFToolTip *pWndToolTip;
  341. // call CUIFWindow::Initialize() to create tooltip window
  342. pUIObjRet = CUIFWindow::Initialize();
  343. // set tooltip font
  344. pWndToolTip = GetToolTipWnd();
  345. if (GetToolTipWnd() != NULL) {
  346. pWndToolTip->SetFont( GetPropertyMgr()->GetToolTipProp()->GetFont() );
  347. pWndToolTip->Enable( GetPropertyMgr()->GetToolTipProp()->IsEnabled() );
  348. }
  349. return pUIObjRet;
  350. }
  351. /* S H O W */
  352. /*------------------------------------------------------------------------------
  353. ------------------------------------------------------------------------------*/
  354. void CCandWindowBase::Show( BOOL fShow )
  355. {
  356. if (!fShow && (m_pCandMenu != NULL)) {
  357. m_pCandMenu->ClosePopup();
  358. }
  359. CUIFWindow::Show( fShow );
  360. }
  361. /* O N C R E A T E */
  362. /*------------------------------------------------------------------------------
  363. ------------------------------------------------------------------------------*/
  364. void CCandWindowBase::OnCreate( HWND hWnd )
  365. {
  366. SetProp( hWnd, (LPCTSTR)GlobalAddAtom(_T("MicrosoftTabletPenServiceProperty")), (HANDLE)1 );
  367. if (m_pCandAcc != NULL) {
  368. m_pCandAcc->SetWindow( hWnd );
  369. }
  370. NotifyUIObjectEvent( CANDUIOBJ_CANDWINDOW, CANDUIOBJEV_CREATED );
  371. }
  372. /* O N D E S T R O Y */
  373. /*------------------------------------------------------------------------------
  374. ------------------------------------------------------------------------------*/
  375. void CCandWindowBase::OnDestroy( HWND hWnd )
  376. {
  377. NotifyUIObjectEvent( CANDUIOBJ_CANDWINDOW, CANDUIOBJEV_DESTROYED );
  378. //
  379. NotifyWinEvent( EVENT_OBJECT_DESTROY );
  380. if (m_pCandAcc != NULL) {
  381. m_pCandAcc->ClearAccItem();
  382. m_pCandAcc->SetWindow( NULL );
  383. }
  384. }
  385. /* O N N C D E S T R O Y */
  386. /*------------------------------------------------------------------------------
  387. on n c destroy
  388. ------------------------------------------------------------------------------*/
  389. void CCandWindowBase::OnNCDestroy( HWND hWnd )
  390. {
  391. RemoveProp( hWnd, (LPCTSTR)GlobalAddAtom(_T("MicrosoftTabletPenServiceProperty")) );
  392. }
  393. /* O N S Y S C O L O R C H A N G E */
  394. /*------------------------------------------------------------------------------
  395. (CUIFWindow method)
  396. ------------------------------------------------------------------------------*/
  397. void CCandWindowBase::OnSysColorChange()
  398. {
  399. int cxyIconMenuSize;
  400. // reload menu button icon
  401. DestroyIcon( m_hIconMenu );
  402. DestroyIcon( m_hIconCandTipOn );
  403. DestroyIcon( m_hIconCandTipOff );
  404. cxyIconMenuSize = GetMenuIconSize();
  405. m_hIconMenu = (HICON)LoadImage( g_hInst, MAKEINTRESOURCE(IDI_ICONMENU), IMAGE_ICON, cxyIconMenuSize, cxyIconMenuSize, 0 );
  406. m_hIconCandTipOn = (HICON)LoadImage( g_hInst, MAKEINTRESOURCE(IDI_ICONTIPON), IMAGE_ICON, cxyIconMenuSize, cxyIconMenuSize, 0 );
  407. m_hIconCandTipOff = (HICON)LoadImage( g_hInst, MAKEINTRESOURCE(IDI_ICONTIPOFF), IMAGE_ICON, cxyIconMenuSize, cxyIconMenuSize, 0 );
  408. if (m_pCandMenuBtn) {
  409. m_pCandMenuBtn->SetIcon( m_hIconMenu );
  410. }
  411. // re-layout objects
  412. LayoutWindow();
  413. }
  414. /* O N S H O W W I N D O W */
  415. /*------------------------------------------------------------------------------
  416. ------------------------------------------------------------------------------*/
  417. LRESULT CCandWindowBase::OnShowWindow( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  418. {
  419. // MSAA support
  420. if (wParam) {
  421. NotifyWinEvent( EVENT_OBJECT_SHOW );
  422. // REVIEW: KOJIW: Unless we send notify EVENT_OBJECT_FOCUS, we never
  423. // receive WM_GETOBJECT message. Why???
  424. NotifyWinEvent( EVENT_OBJECT_FOCUS );
  425. }
  426. else {
  427. NotifyWinEvent( EVENT_OBJECT_HIDE );
  428. }
  429. return CUIFWindow::OnShowWindow( hWnd, uMsg, wParam, lParam );
  430. }
  431. /* O N W I N D O W P O S C H A N G E D */
  432. /*------------------------------------------------------------------------------
  433. ------------------------------------------------------------------------------*/
  434. LRESULT CCandWindowBase::OnWindowPosChanged( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  435. {
  436. LRESULT lResult = CUIFWindow::OnWindowPosChanged( hWnd, uMsg, wParam, lParam );
  437. NotifyUIObjectEvent( CANDUIOBJ_CANDWINDOW, CANDUIOBJEV_UPDATED );
  438. return lResult;
  439. }
  440. /* O N G E T O B J E C T */
  441. /*------------------------------------------------------------------------------
  442. ------------------------------------------------------------------------------*/
  443. LRESULT CCandWindowBase::OnGetObject( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  444. {
  445. LRESULT lResult = 0;
  446. switch (lParam) {
  447. //-----------------------------------------------------
  448. // We process the OBJID_CLIENT object identifier;
  449. // this is the client area of our application
  450. // window.
  451. //-----------------------------------------------------
  452. case OBJID_CLIENT: {
  453. HRESULT hr;
  454. if (m_pCandAcc == NULL) {
  455. lResult = (LRESULT)E_OUTOFMEMORY;
  456. break;
  457. }
  458. if (!m_pCandAcc->FInitialized()) {
  459. //-----------------------------------------------------
  460. // Initialize our Accessible object. If the
  461. // initialization fails, delete the Accessible
  462. // object and return the failure code.
  463. //-----------------------------------------------------
  464. hr = m_pCandAcc->Initialize();
  465. if (FAILED( hr )) {
  466. m_pCandAcc->Release();
  467. m_pCandAcc = NULL;
  468. lResult = (LRESULT)hr;
  469. break;
  470. }
  471. //-----------------------------------------------------
  472. // Send an EVENT_OBJECT_CREATE WinEvent for the
  473. // creation of the Accessible object for the
  474. // client area.
  475. //-----------------------------------------------------
  476. NotifyWinEvent( EVENT_OBJECT_CREATE );
  477. }
  478. //-----------------------------------------------------
  479. // Call LresultFromObject() to create reference to
  480. // our Accessible object that MSAA will marshal to
  481. // the client.
  482. //-----------------------------------------------------
  483. lResult = m_pCandAcc->CreateRefToAccObj( wParam );
  484. break;
  485. }
  486. default: {
  487. lResult = (LRESULT)0L;
  488. }
  489. }
  490. return lResult;
  491. }
  492. /* O N O B J E C T N O T I F Y */
  493. /*------------------------------------------------------------------------------
  494. (CUIFWindow method)
  495. ------------------------------------------------------------------------------*/
  496. LRESULT CCandWindowBase::OnObjectNotify( CUIFObject *pUIObj, DWORD dwCommand, LPARAM lParam )
  497. {
  498. DWORD dwID = pUIObj->GetID();
  499. // candidate num buttons
  500. if (IDUIF_CANDNUMBUTTON <= dwID && dwID < (IDUIF_CANDNUMBUTTON + NUM_CANDSTR_MAX)) {
  501. int iListItem = GetUIListObj()->GetTopItem() + (dwID - 1);
  502. if (SelectItemProc( iListItem )) {
  503. CompleteCandidate();
  504. }
  505. }
  506. // candidate menu button
  507. else if (dwID == IDUIF_CANDIDATEMENU) {
  508. if (m_pCandMenuBtn->GetToggleState()) {
  509. OpenCandidateMenu();
  510. }
  511. }
  512. // candidate list
  513. else if (dwID == IDUIF_CANDIDATELIST) {
  514. switch (dwCommand) {
  515. case UILIST_SELECTED: {
  516. CompleteCandidate();
  517. break;
  518. }
  519. case UILIST_SELCHANGED: {
  520. SelectCandidate();
  521. break;
  522. }
  523. }
  524. }
  525. // options candidate list
  526. else if (dwID == IDUIF_OPTIONSLIST) {
  527. switch (dwCommand) {
  528. case UILIST_SELECTED: {
  529. CompleteOptionCandidate();
  530. break;
  531. }
  532. case UILIST_SELCHANGED: {
  533. SelectCandidate();
  534. break;
  535. }
  536. }
  537. }
  538. // candidate rawdata
  539. else if (dwID == IDUIF_RAWDATA) {
  540. switch (dwCommand) {
  541. case UICANDRAWDATA_CLICKED: {
  542. if (GetCandListMgr()->GetCandList()->FRawDataSelectable()) {
  543. m_pCandUI->NotifyCompleteRawData();
  544. }
  545. break;
  546. }
  547. }
  548. }
  549. // extended UI objects
  550. else if (IDUIF_EXTENDED <= dwID && dwID < (DWORD)(IDUIF_EXTENDED + GetExtensionMgr()->GetExtensionNum())) {
  551. LONG iExtension = dwID - IDUIF_EXTENDED;
  552. GetExtensionMgr()->UpdateExtProp( iExtension, pUIObj );
  553. m_pCandUI->NotifyExtensionEvent( iExtension, dwCommand, lParam );
  554. }
  555. return 0;
  556. }
  557. /* O N U S E R */
  558. /*------------------------------------------------------------------------------
  559. ------------------------------------------------------------------------------*/
  560. void CCandWindowBase::OnUser(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  561. {
  562. if (uMsg == WM_USER) {
  563. ProcessCommand( (CANDUICOMMAND)wParam, (int)lParam );
  564. }
  565. }
  566. /* I N I T C A N D I D A T E L I S T */
  567. /*------------------------------------------------------------------------------
  568. Initialize candidate list data in candidate window
  569. ------------------------------------------------------------------------------*/
  570. void CCandWindowBase::InitCandidateList( void )
  571. {
  572. // set candidate list data
  573. SetCandidateListProc();
  574. // prepare to layout window
  575. // NOTE: Call it only once when initializing.
  576. PrepareLayout();
  577. // layout ui objects
  578. LayoutWindow();
  579. // set the selection
  580. SetSelectionProc();
  581. }
  582. /* P R O C E S S C O M M A N D */
  583. /*------------------------------------------------------------------------------
  584. Process candidate commands
  585. Return value:
  586. S_OK : command processed successfully
  587. S_FALSE : command has not processed but not error
  588. E_FAIL : command is failed
  589. ------------------------------------------------------------------------------*/
  590. HRESULT CCandWindowBase::ProcessCommand( CANDUICOMMAND cmd, INT iParam )
  591. {
  592. HRESULT hr = E_FAIL;
  593. AddRef();
  594. switch (MapCommand( cmd )) {
  595. case CANDUICMD_NONE: {
  596. hr = E_FAIL;
  597. break;
  598. }
  599. case CANDUICMD_NOP: {
  600. // no operation
  601. hr = S_OK;
  602. break;
  603. }
  604. case CANDUICMD_COMPLETE: {
  605. CompleteCandidate();
  606. hr = S_OK;
  607. break;
  608. }
  609. case CANDUICMD_CANCEL: {
  610. CancelCandidate();
  611. hr = S_OK;
  612. break;
  613. }
  614. case CANDUICMD_MOVESELNEXT: {
  615. SelectItemNext();
  616. hr = S_OK;
  617. break;
  618. }
  619. case CANDUICMD_MOVESELPREV: {
  620. SelectItemPrev();
  621. hr = S_OK;
  622. break;
  623. }
  624. case CANDUICMD_MOVESELPREVPG: {
  625. SelectPagePrev();
  626. hr = S_OK;
  627. break;
  628. }
  629. case CANDUICMD_MOVESELNEXTPG: {
  630. SelectPageNext();
  631. hr = S_OK;
  632. break;
  633. }
  634. case CANDUICMD_MOVESELFIRST: {
  635. SelectItemTop();
  636. hr = S_OK;
  637. break;
  638. }
  639. case CANDUICMD_MOVESELLAST: {
  640. SelectItemEnd();
  641. hr = S_OK;
  642. break;
  643. }
  644. case CANDUICMD_SELECTITEM: {
  645. if (SelectItemProc( iParam )) {
  646. CompleteCandidate();
  647. hr = S_OK;
  648. }
  649. else {
  650. hr = S_FALSE;
  651. }
  652. break;
  653. }
  654. case CANDUICMD_SELECTLINE: {
  655. if (SelectItemProc( GetUIListObj()->GetTopItem() + iParam - 1 )) {
  656. CompleteCandidate();
  657. hr = S_OK;
  658. }
  659. else {
  660. hr = S_FALSE;
  661. }
  662. break;
  663. }
  664. case CANDUICMD_OPENCANDMENU: {
  665. if (!FCandMenuOpen()) {
  666. OpenCandidateMenu();
  667. hr = S_OK;
  668. }
  669. else {
  670. hr = S_FALSE;
  671. }
  672. break;
  673. }
  674. case CANDUICMD_SELECTRAWDATA: {
  675. Assert( GetCandListMgr()->GetCandList() != NULL );
  676. // not eat key when rawdata is not selectable
  677. if (GetCandListMgr()->GetCandList()->FRawDataSelectable()) {
  678. hr = m_pCandUI->NotifyCompleteRawData();
  679. }
  680. else {
  681. hr = E_FAIL;
  682. }
  683. break;
  684. }
  685. case CANDUICMD_SELECTEXTRACAND: {
  686. Assert( GetCandListMgr()->GetCandList() != NULL );
  687. // not eat key when rawdata is not selectable
  688. if (GetCandListMgr()->GetCandList()->GetExtraCandItem() != NULL) {
  689. hr = m_pCandUI->NotifyCompleteExtraCand();
  690. }
  691. else {
  692. hr = S_FALSE;
  693. }
  694. break;
  695. }
  696. default: {
  697. // unknown command has come
  698. Assert( FALSE );
  699. break;
  700. }
  701. }
  702. Release();
  703. return hr;
  704. }
  705. /* I S I N D E X V A L I D */
  706. /*------------------------------------------------------------------------------
  707. is index valid
  708. ------------------------------------------------------------------------------*/
  709. HRESULT CCandWindowBase::IsIndexValid( int i, BOOL *pfValid )
  710. {
  711. Assert( pfValid != NULL );
  712. *pfValid = FALSE;
  713. if (GetUIListObj() == NULL) {
  714. return E_FAIL;
  715. }
  716. int iListItem = GetUIListObj()->GetTopItem() + i - 1;
  717. *pfValid = GetUIListObj()->IsItemSelectable( iListItem );
  718. return S_OK;
  719. }
  720. /* D E S T R O Y W N D */
  721. /*------------------------------------------------------------------------------
  722. Destroy candidate window
  723. ------------------------------------------------------------------------------*/
  724. void CCandWindowBase::DestroyWnd( void )
  725. {
  726. if (m_pCandMenu != NULL) {
  727. m_pCandMenu->ClosePopup();
  728. }
  729. DestroyWindow( GetWnd() );
  730. }
  731. /* U P D A T E A L L W I N D O W */
  732. /*------------------------------------------------------------------------------
  733. ------------------------------------------------------------------------------*/
  734. void CCandWindowBase::UpdateAllWindow( void )
  735. {
  736. UpdateWindow();
  737. }
  738. /* O P E N C A N D I D A T E M E N U */
  739. /*------------------------------------------------------------------------------
  740. ------------------------------------------------------------------------------*/
  741. void CCandWindowBase::OpenCandidateMenu( void )
  742. {
  743. CMenuButtonProperty *pMenuBtnProp;
  744. UINT uiCmd;
  745. RECT rc;
  746. POINT pt;
  747. BOOL fNotify = FALSE;
  748. // sanity check
  749. if (m_pCandMenuBtn == NULL) {
  750. return;
  751. }
  752. // do not open menu when button is not enabled and visible
  753. if (!m_pCandMenuBtn->IsEnabled() || !m_pCandMenuBtn->IsVisible()) {
  754. return;
  755. }
  756. pMenuBtnProp = GetPropertyMgr()->GetMenuButtonProp();
  757. Assert( pMenuBtnProp != NULL );
  758. Assert( pMenuBtnProp->IsEnabled() );
  759. Assert( pMenuBtnProp->GetEventSink() );
  760. if ( pMenuBtnProp->GetEventSink() == NULL ) {
  761. return;
  762. }
  763. // calc position to display
  764. m_pCandMenuBtn->GetRect( &rc );
  765. ClientToScreen( m_hWnd, (POINT*)&rc.left );
  766. ClientToScreen( m_hWnd, (POINT*)&rc.right );
  767. pt.x = rc.left;
  768. pt.y = rc.bottom;
  769. // pushdown the menu button
  770. AddRef();
  771. Assert( m_pCandMenuBtn->GetToggleState() );
  772. m_pCandMenuBtn->SetToggleState( TRUE );
  773. m_fCandMenuOpen = TRUE;
  774. // create and popup menu
  775. UpdateWindow();
  776. m_pCandMenu = new CCandMenu( g_hInst );
  777. if (m_pCandMenu != NULL) {
  778. if (pMenuBtnProp->GetEventSink()->InitMenu( m_pCandMenu ) == S_OK) {
  779. uiCmd = m_pCandMenu->ShowPopup( this, pt, &rc );
  780. fNotify = TRUE;
  781. }
  782. m_pCandMenu->Release();
  783. m_pCandMenu = NULL;
  784. }
  785. // restore the menu button
  786. m_fCandMenuOpen = FALSE;
  787. m_pCandMenuBtn->SetToggleState( FALSE );
  788. //
  789. //
  790. //
  791. if (fNotify) {
  792. pMenuBtnProp->GetEventSink()->OnMenuCommand( uiCmd );
  793. }
  794. Release();
  795. }
  796. /* F C A N D M E N U O P E N */
  797. /*------------------------------------------------------------------------------
  798. ------------------------------------------------------------------------------*/
  799. BOOL CCandWindowBase::FCandMenuOpen( void )
  800. {
  801. return m_fCandMenuOpen;
  802. }
  803. /* G E T C A N D M E N U */
  804. /*------------------------------------------------------------------------------
  805. ------------------------------------------------------------------------------*/
  806. CCandMenu *CCandWindowBase::GetCandMenu( void )
  807. {
  808. return m_pCandMenu;
  809. }
  810. /* G E T I C O N M E N U */
  811. /*------------------------------------------------------------------------------
  812. ------------------------------------------------------------------------------*/
  813. HICON CCandWindowBase::GetIconMenu( void )
  814. {
  815. return m_hIconMenu;
  816. }
  817. /* G E T I C O N P O P U P O N */
  818. /*------------------------------------------------------------------------------
  819. ------------------------------------------------------------------------------*/
  820. HICON CCandWindowBase::GetIconPopupOn( void )
  821. {
  822. return m_hIconPopupOn;
  823. }
  824. /* G E T I C O N P O P U P O F F */
  825. /*------------------------------------------------------------------------------
  826. ------------------------------------------------------------------------------*/
  827. HICON CCandWindowBase::GetIconPopupOff( void )
  828. {
  829. return m_hIconPopupOff;
  830. }
  831. /* F I N D U I O B J E C T */
  832. /*------------------------------------------------------------------------------
  833. Find UI object which has an ID
  834. When no UI object found, returns NULL.
  835. ------------------------------------------------------------------------------*/
  836. CUIFObject *CCandWindowBase::FindUIObject( DWORD dwID )
  837. {
  838. int nChild;
  839. int i;
  840. nChild = m_ChildList.GetCount();
  841. for (i = 0; i < nChild; i++) {
  842. CUIFObject *pUIObj = m_ChildList.Get( i );
  843. Assert( pUIObj );
  844. if (pUIObj->GetID() == dwID) {
  845. return pUIObj;
  846. }
  847. }
  848. return NULL;
  849. }
  850. /* O P T I O N I T E M F R O M L I S T I T E M */
  851. /*------------------------------------------------------------------------------
  852. Get index of options candidate item in candidate list data
  853. from index of item in UIList object
  854. ------------------------------------------------------------------------------*/
  855. int CCandWindowBase::OptionItemFromListItem( int iListItem )
  856. {
  857. CUIFCandListBase *pUIListObj = GetUIOptionsListObj();
  858. CCandListItem *pListItem;
  859. pListItem = pUIListObj->GetCandItem( iListItem );
  860. return (pListItem != NULL) ? pListItem->GetICandItem() : ICANDITEM_NULL;
  861. }
  862. /* C A N D I T E M F R O M L I S T I T E M */
  863. /*------------------------------------------------------------------------------
  864. Get index of candidate item in candidate list data
  865. from index of item in UIList object
  866. ------------------------------------------------------------------------------*/
  867. int CCandWindowBase::CandItemFromListItem( int iListItem )
  868. {
  869. CUIFCandListBase *pUIListObj = GetUIListObj();
  870. CCandListItem *pListItem;
  871. pListItem = pUIListObj->GetCandItem( iListItem );
  872. return (pListItem != NULL) ? pListItem->GetICandItem() : ICANDITEM_NULL;
  873. }
  874. /* L I S T I T E M F R O M C A N D I T E M */
  875. /*------------------------------------------------------------------------------
  876. Get index of item in UIList object
  877. from index of candidate item in candidate list data
  878. ------------------------------------------------------------------------------*/
  879. int CCandWindowBase::ListItemFromCandItem( int iCandItem )
  880. {
  881. CUIFCandListBase *pUIListObj = GetUIListObj();
  882. int iListItem;
  883. int nListItem;
  884. nListItem = pUIListObj->GetItemCount();
  885. for (iListItem = 0; iListItem < nListItem; iListItem++) {
  886. CCandListItem *pListItem = pUIListObj->GetCandItem( iListItem );
  887. if (pListItem != NULL && pListItem->GetICandItem() == iCandItem) {
  888. return iListItem;
  889. }
  890. }
  891. return -1; /* not found */
  892. }
  893. /* O N M E N U O P E N E D */
  894. /*------------------------------------------------------------------------------
  895. ------------------------------------------------------------------------------*/
  896. void CCandWindowBase::OnMenuOpened( void )
  897. {
  898. }
  899. /* O N M E N U C L O S E D */
  900. /*------------------------------------------------------------------------------
  901. ------------------------------------------------------------------------------*/
  902. void CCandWindowBase::OnMenuClosed( void )
  903. {
  904. }
  905. /* S E T C A N D I D A T E L I S T P R O C */
  906. /*------------------------------------------------------------------------------
  907. Set candidate list
  908. ------------------------------------------------------------------------------*/
  909. void CCandWindowBase::SetCandidateListProc( void )
  910. {
  911. CUIFCandListBase *pUIListObj = GetUIListObj();
  912. CUIFCandListBase *pUIOptionsListObj = GetUIOptionsListObj();
  913. CCandidateList *pCandList;
  914. CCandidateList *pOptionsList;
  915. int i;
  916. int nListItem;
  917. pCandList = GetCandListMgr()->GetCandList();
  918. Assert( pCandList != NULL );
  919. pOptionsList = GetCandListMgr()->GetOptionsList();
  920. Assert( pOptionsList != NULL);
  921. // reset list item
  922. pUIListObj->DelAllCandItem();
  923. pUIListObj->SetCandList(pCandList);
  924. // reset options list item
  925. if (pOptionsList)
  926. {
  927. pUIOptionsListObj->DelAllCandItem();
  928. pUIOptionsListObj->SetCandList(pOptionsList);
  929. pUIOptionsListObj->SetCurSel(-1);
  930. }
  931. // rawdata
  932. m_fHasRawData = pCandList->FHasRawData();
  933. if (m_fHasRawData) {
  934. switch (pCandList->GetRawDataType()) {
  935. case CANDUIRDT_STRING: {
  936. m_pCandRawData->SetText( pCandList->GetRawDataString() );
  937. break;
  938. }
  939. case CANDUIRDT_BITMAP: {
  940. m_pCandRawData->SetBitmap( pCandList->GetRawDataBitmap() );
  941. break;
  942. }
  943. case CANDUIRDT_METAFILE: {
  944. m_pCandRawData->SetMetaFile( pCandList->GetRawDataMetafile() );
  945. break;
  946. }
  947. }
  948. }
  949. // enable/disable candidate number button
  950. nListItem = pUIListObj->GetItemCount();
  951. for (i = 0; i < NUM_CANDSTR_MAX; i++) {
  952. CUIFObject *pUIObj = FindUIObject( IDUIF_CANDNUMBUTTON + i );
  953. if (pUIObj != NULL) {
  954. pUIObj->Enable( i < nListItem );
  955. }
  956. }
  957. // update window
  958. if (m_hWnd != NULL) {
  959. InvalidateRect( m_hWnd, NULL, TRUE );
  960. }
  961. }
  962. /* C L E A R C A N D I D A T E L I S T P R O C */
  963. /*------------------------------------------------------------------------------
  964. Clear candidte list
  965. ------------------------------------------------------------------------------*/
  966. void CCandWindowBase::ClearCandidateListProc( void )
  967. {
  968. GetUIListObj()->DelAllCandItem();
  969. }
  970. /* S E T S E L E C T I O N P R O C */
  971. /*------------------------------------------------------------------------------
  972. Set selection
  973. ------------------------------------------------------------------------------*/
  974. void CCandWindowBase::SetSelectionProc( void )
  975. {
  976. int iCandItem;
  977. int iListItem;
  978. Assert( GetCandListMgr()->GetCandList() != NULL );
  979. iCandItem = GetCandListMgr()->GetCandList()->GetSelection();
  980. iListItem = ListItemFromCandItem( iCandItem );
  981. SelectItemProc( iListItem );
  982. }
  983. /* S E L E C T I T E M P R O C */
  984. /*------------------------------------------------------------------------------
  985. Select item procedure
  986. ------------------------------------------------------------------------------*/
  987. BOOL CCandWindowBase::SelectItemProc( int iListItem )
  988. {
  989. if (GetUIListObj()->IsItemSelectable( iListItem )) {
  990. GetUIListObj()->SetCurSel( iListItem );
  991. return TRUE;
  992. }
  993. return FALSE;
  994. }
  995. /* S E L E C T I T E M T O P */
  996. /*------------------------------------------------------------------------------
  997. ------------------------------------------------------------------------------*/
  998. void CCandWindowBase::SelectItemTop( void )
  999. {
  1000. SelectItemProc( 0 );
  1001. }
  1002. /* S E L E C T I T E M E N D */
  1003. /*------------------------------------------------------------------------------
  1004. ------------------------------------------------------------------------------*/
  1005. void CCandWindowBase::SelectItemEnd( void )
  1006. {
  1007. SelectItemProc( GetUIListObj()->GetItemCount() - 1 );
  1008. }
  1009. /* S E L E C T C A N D I D A T E */
  1010. /*------------------------------------------------------------------------------
  1011. ------------------------------------------------------------------------------*/
  1012. HRESULT CCandWindowBase::SelectOptionCandidate( void )
  1013. {
  1014. int iListItem;
  1015. int iCandItem;
  1016. iListItem = GetUIOptionsListObj()->GetCurSel();
  1017. iCandItem = OptionItemFromListItem( iListItem );
  1018. // NOTE: KOJIW: do not set selection again when the selection in listbox
  1019. // is changed by selection update notification...
  1020. if (m_fOnSelectionChanged) {
  1021. return S_OK;
  1022. }
  1023. GetCandListMgr()->SetOptionSelection( iCandItem, this );
  1024. // We do not want to send a selection notification for options.
  1025. return S_OK;
  1026. }
  1027. /* S E L E C T C A N D I D A T E */
  1028. /*------------------------------------------------------------------------------
  1029. ------------------------------------------------------------------------------*/
  1030. HRESULT CCandWindowBase::SelectCandidate( void )
  1031. {
  1032. int iListItem;
  1033. int iCandItem;
  1034. iListItem = GetUIListObj()->GetCurSel();
  1035. iCandItem = CandItemFromListItem( iListItem );
  1036. // NOTE: KOJIW: do not set selection again when the selection in listbox
  1037. // is changed by selection update notification...
  1038. if (m_fOnSelectionChanged) {
  1039. return S_OK;
  1040. }
  1041. GetCandListMgr()->SetSelection( iCandItem, this );
  1042. return m_pCandUI->NotifySelectCand( iCandItem );
  1043. }
  1044. /* C O M P L E T E O P T I O N C A N D I D A T E */
  1045. /*------------------------------------------------------------------------------
  1046. ------------------------------------------------------------------------------*/
  1047. HRESULT CCandWindowBase::CompleteOptionCandidate( void )
  1048. {
  1049. int iCandItem;
  1050. int iListItem;
  1051. iListItem = GetUIOptionsListObj()->GetCurSel();
  1052. iCandItem = OptionItemFromListItem( iListItem );
  1053. return m_pCandUI->NotifyCompleteOption( iCandItem );
  1054. }
  1055. /* C O M P L E T E C A N D I D A T E */
  1056. /*------------------------------------------------------------------------------
  1057. ------------------------------------------------------------------------------*/
  1058. HRESULT CCandWindowBase::CompleteCandidate( void )
  1059. {
  1060. int iCandItem;
  1061. int iListItem;
  1062. iListItem = GetUIListObj()->GetCurSel();
  1063. iCandItem = CandItemFromListItem( iListItem );
  1064. return m_pCandUI->NotifyCompleteCand( iCandItem );
  1065. }
  1066. /* C A N C E L C A N D I D A T E */
  1067. /*------------------------------------------------------------------------------
  1068. ------------------------------------------------------------------------------*/
  1069. HRESULT CCandWindowBase::CancelCandidate( void )
  1070. {
  1071. return m_pCandUI->NotifyCancelCand();
  1072. }
  1073. /* G E T M E N U I C O N S I Z E */
  1074. /*------------------------------------------------------------------------------
  1075. ------------------------------------------------------------------------------*/
  1076. int CCandWindowBase::GetMenuIconSize( void )
  1077. {
  1078. const int iIconResSize = 12; // icon size in resource
  1079. const int iDefBtnSize = 14; // button size of default
  1080. int iIconSize;
  1081. SIZE size;
  1082. // reload menu button icon
  1083. size.cx = GetSystemMetrics( SM_CXVSCROLL );
  1084. size.cy = GetSystemMetrics( SM_CYHSCROLL );
  1085. iIconSize = min( size.cx, size.cy ) - 2;
  1086. iIconSize = iIconSize * iIconResSize / iDefBtnSize;
  1087. return iIconSize;
  1088. }
  1089. /* C R E A T E E X T E N S I O N O B J E C T S */
  1090. /*------------------------------------------------------------------------------
  1091. ------------------------------------------------------------------------------*/
  1092. void CCandWindowBase::CreateExtensionObjects( void )
  1093. {
  1094. LONG nExtension;
  1095. LONG i;
  1096. Assert( m_nExtUIObj == 0 );
  1097. nExtension = GetExtensionMgr()->GetExtensionNum();
  1098. m_nExtUIObj = 0;
  1099. for (i = 0; i < nExtension; i++) {
  1100. CUIFObject *pUIObj = NULL;
  1101. RECT rc = {0};
  1102. pUIObj = GetExtensionMgr()->CreateUIObject( i, this, IDUIF_EXTENDED + i, &rc );
  1103. if (pUIObj != NULL) {
  1104. pUIObj->Initialize();
  1105. GetExtensionMgr()->UpdateObjProp( i, pUIObj );
  1106. AddUIObj( pUIObj );
  1107. m_nExtUIObj++;
  1108. }
  1109. }
  1110. }
  1111. /* D E L E T E E X T E N S I O N O B J E C T S */
  1112. /*------------------------------------------------------------------------------
  1113. ------------------------------------------------------------------------------*/
  1114. void CCandWindowBase::DeleteExtensionObjects( void )
  1115. {
  1116. LONG nExtension;
  1117. LONG i;
  1118. nExtension = GetExtensionMgr()->GetExtensionNum();
  1119. for (i = 0; i < nExtension; i++) {
  1120. CUIFObject *pUIObj = FindUIObject( IDUIF_EXTENDED + i );
  1121. if (pUIObj != NULL) {
  1122. RemoveUIObj( pUIObj );
  1123. delete pUIObj;
  1124. m_nExtUIObj--;
  1125. }
  1126. }
  1127. Assert( m_nExtUIObj == 0 );
  1128. m_nExtUIObj = 0;
  1129. }
  1130. /* S E T E X T E N S I O N O B J E C T P R O P S */
  1131. /*------------------------------------------------------------------------------
  1132. ------------------------------------------------------------------------------*/
  1133. void CCandWindowBase::SetExtensionObjectProps( void )
  1134. {
  1135. LONG nExtension;
  1136. LONG i;
  1137. nExtension = GetExtensionMgr()->GetExtensionNum();
  1138. for (i = 0; i < nExtension; i++) {
  1139. CUIFObject *pUIObj = FindUIObject( IDUIF_EXTENDED + i );
  1140. if (pUIObj != NULL) {
  1141. GetExtensionMgr()->UpdateObjProp( i, pUIObj );
  1142. }
  1143. }
  1144. }
  1145. /*============================================================================*/
  1146. /* */
  1147. /* C C A N D W I N D O W */
  1148. /* */
  1149. /*============================================================================*/
  1150. /* C C A N D W I N D O W */
  1151. /*------------------------------------------------------------------------------
  1152. Constructor of CCandWindow
  1153. ------------------------------------------------------------------------------*/
  1154. CCandWindow::CCandWindow( CCandidateUI *pCandUI, DWORD dwStyle ) : CCandWindowBase( pCandUI, dwStyle | UIWINDOW_TOPMOST | UIWINDOW_TOOLWINDOW | UIWINDOW_OFC10MENU )
  1155. {
  1156. m_pOptionsListUIObj = NULL;
  1157. m_pListUIObj = NULL;
  1158. m_pExtListUIObj = NULL;
  1159. m_pWndFrame = NULL;
  1160. m_pCaptionObj = NULL;
  1161. m_cxWndOffset = 0;
  1162. m_cyWndOffset = 0;
  1163. m_nItemShow = 1;
  1164. m_pCommentWnd = NULL;
  1165. m_fCommentWndOpen = FALSE;
  1166. m_iItemAttensionSelect = -1;
  1167. m_iItemAttensionHover = -1;
  1168. m_pCandTipWnd = NULL;
  1169. m_pCandTipBtn = NULL;
  1170. m_fCandTipWndOpen = FALSE;
  1171. }
  1172. /* ~ C C A N D W I N D O W */
  1173. /*------------------------------------------------------------------------------
  1174. Destructor of CCandWindow
  1175. ------------------------------------------------------------------------------*/
  1176. CCandWindow::~CCandWindow()
  1177. {
  1178. //
  1179. // Notify UI object destroy
  1180. //
  1181. NotifyUIObjectEvent( CANDUIOBJ_OPTIONSLISTBOX, CANDUIOBJEV_DESTROYED );
  1182. NotifyUIObjectEvent( CANDUIOBJ_CANDLISTBOX, CANDUIOBJEV_DESTROYED );
  1183. NotifyUIObjectEvent( CANDUIOBJ_CANDCAPTION, CANDUIOBJEV_DESTROYED );
  1184. NotifyUIObjectEvent( CANDUIOBJ_MENUBUTTON, CANDUIOBJEV_DESTROYED );
  1185. NotifyUIObjectEvent( CANDUIOBJ_EXTRACANDIDATE, CANDUIOBJEV_DESTROYED );
  1186. NotifyUIObjectEvent( CANDUIOBJ_CANDRAWDATA, CANDUIOBJEV_DESTROYED );
  1187. NotifyUIObjectEvent( CANDUIOBJ_CANDTIPBUTTON, CANDUIOBJEV_DESTROYED );
  1188. if (m_pCommentWnd) {
  1189. delete m_pCommentWnd;
  1190. }
  1191. if (m_pCandTipWnd) {
  1192. delete m_pCandTipWnd;
  1193. }
  1194. }
  1195. /* C R E A T E W N D */
  1196. /*------------------------------------------------------------------------------
  1197. ------------------------------------------------------------------------------*/
  1198. HWND CCandWindow::CreateWnd( HWND hWndParent )
  1199. {
  1200. HWND hWnd = CCandWindowBase::CreateWnd( hWndParent );
  1201. Assert( GetCandListMgr()->GetCandList() != NULL );
  1202. // make timer to popup comment window
  1203. SetAttensionBySelect( GetCandListMgr()->GetCandList()->GetSelection() );
  1204. return hWnd;
  1205. }
  1206. /* S H O W */
  1207. /*------------------------------------------------------------------------------
  1208. ------------------------------------------------------------------------------*/
  1209. void CCandWindow::Show( BOOL fShow )
  1210. {
  1211. if (m_fCommentWndOpen) {
  1212. m_pCommentWnd->Show( fShow );
  1213. }
  1214. if (fShow) {
  1215. if (m_fCandTipWndOpen) {
  1216. OpenCandTipWindow();
  1217. }
  1218. }
  1219. else {
  1220. if (m_fCandTipWndOpen) {
  1221. CloseCandTipWindow();
  1222. }
  1223. }
  1224. CCandWindowBase::Show( fShow );
  1225. }
  1226. /* I N I T I A L I Z E */
  1227. /*------------------------------------------------------------------------------
  1228. Initialize UI objects
  1229. ------------------------------------------------------------------------------*/
  1230. CUIFObject *CCandWindow::Initialize( void )
  1231. {
  1232. RECT rc = {0};
  1233. #ifdef NEVER
  1234. CUIFButton *pButton;
  1235. #endif
  1236. CUIFBorder *pBorder;
  1237. //
  1238. // create window frame
  1239. //
  1240. m_pWndFrame = new CUIFWndFrame( this, &rc, UIWNDFRAME_THIN | UIWNDFRAME_NORESIZE );
  1241. if (m_pWndFrame != NULL) {
  1242. m_pWndFrame->Initialize();
  1243. AddUIObj( m_pWndFrame );
  1244. }
  1245. #ifdef NEVER
  1246. if (!FHasStyle( UIWINDOW_OFFICENEWLOOK )) {
  1247. int i;
  1248. //
  1249. // create candidate num buttons
  1250. //
  1251. for (i = 0; i < NUM_CANDSTR_MAX; i++) {
  1252. WCHAR szNum[2];
  1253. pButton = new CUIFButton( this, IDUIF_CANDNUMBUTTON + i, &rc, UIBUTTON_CENTER | UIBUTTON_VCENTER );
  1254. if (pButton)
  1255. {
  1256. pButton->Initialize();
  1257. szNum[0] = L'1' + i;
  1258. szNum[1] = L'\0';
  1259. pButton->SetText( szNum );
  1260. AddUIObj( pButton );
  1261. }
  1262. }
  1263. //
  1264. // create border
  1265. //
  1266. pBorder = new CUIFBorder( this, IDUIF_BORDERLEFT, &rc, UIBORDER_VERT );
  1267. pBorder->Initialize();
  1268. AddUIObj( pBorder );
  1269. }
  1270. #endif
  1271. //
  1272. // create options candidate list
  1273. //
  1274. m_pOptionsListUIObj = new CUIFCandList( this, IDUIF_OPTIONSLIST, &rc, UILIST_HORZTB );
  1275. if (m_pOptionsListUIObj != NULL) {
  1276. m_pOptionsListUIObj->Initialize();
  1277. AddUIObj( m_pOptionsListUIObj );
  1278. // m_pOptionsListUIObj->SetIconPopupComment( m_hIconPopupOn, m_hIconPopupOff );
  1279. }
  1280. //
  1281. // create options candidate list border
  1282. //
  1283. pBorder = new CUIFCandBorder( this, IDUIF_BORDEROPTIONSCAND, &rc, UIBORDER_HORZ );
  1284. if (pBorder != NULL) {
  1285. pBorder->Initialize();
  1286. AddUIObj( pBorder );
  1287. }
  1288. //
  1289. // create candidate list
  1290. //
  1291. m_pListUIObj = new CUIFCandList( this, IDUIF_CANDIDATELIST, &rc, UILIST_HORZTB );
  1292. if (m_pListUIObj != NULL) {
  1293. m_pListUIObj->Initialize();
  1294. AddUIObj( m_pListUIObj );
  1295. m_pListUIObj->SetIconPopupComment( m_hIconPopupOn, m_hIconPopupOff );
  1296. }
  1297. //
  1298. // create extra candidate list
  1299. //
  1300. m_pExtListUIObj = new CUIFExtCandList( this, IDUIF_EXTCANDIDATELIST, &rc, UILIST_HORZTB );
  1301. if (m_pExtListUIObj != NULL) {
  1302. m_pExtListUIObj->Initialize();
  1303. AddUIObj( m_pExtListUIObj );
  1304. }
  1305. //
  1306. // create extra candidate list border
  1307. //
  1308. pBorder = new CUIFCandBorder( this, IDUIF_BORDEREXTRACAND, &rc, UIBORDER_HORZ );
  1309. if (pBorder != NULL) {
  1310. pBorder->Initialize();
  1311. AddUIObj( pBorder );
  1312. }
  1313. //
  1314. // create candidate menu button
  1315. //
  1316. m_pCandMenuBtn = new CUIFCandMenuButton( this, IDUIF_CANDIDATEMENU, &rc, UIBUTTON_TOGGLE | UIBUTTON_CENTER | UIBUTTON_VCENTER );
  1317. if (m_pCandMenuBtn != NULL) {
  1318. m_pCandMenuBtn->Initialize();
  1319. AddUIObj( m_pCandMenuBtn );
  1320. if (m_pCandAcc != NULL) {
  1321. m_pCandAcc->AddAccItem( (CUIFCandMenuButton*)m_pCandMenuBtn );
  1322. }
  1323. m_pCandMenuBtn->SetIcon( m_hIconMenu );
  1324. }
  1325. //
  1326. // create raw data border
  1327. //
  1328. pBorder = new CUIFCandBorder( this, IDUIF_BORDERRAWDATA, &rc, UIBORDER_HORZ );
  1329. if (pBorder != NULL) {
  1330. pBorder->Initialize();
  1331. AddUIObj( pBorder );
  1332. }
  1333. //
  1334. // creare raw data statics
  1335. //
  1336. m_pCandRawData = new CUIFCandRawData( this, IDUIF_RAWDATA, &rc, UICANDRAWDATA_HORZTB );
  1337. if (m_pCandRawData != NULL) {
  1338. m_pCandRawData->Initialize();
  1339. AddUIObj( m_pCandRawData );
  1340. }
  1341. //
  1342. // create extension border
  1343. //
  1344. pBorder = new CUIFCandBorder( this, IDUIF_BORDERBOTTOM, &rc, UIBORDER_HORZ );
  1345. if (pBorder != NULL) {
  1346. pBorder->Initialize();
  1347. AddUIObj( pBorder );
  1348. }
  1349. //
  1350. // create extension items
  1351. //
  1352. if (0 < GetExtensionMgr()->GetExtensionNum()) {
  1353. CreateExtensionObjects();
  1354. }
  1355. //
  1356. // create caption
  1357. //
  1358. m_pCaptionObj = new CUIFWndCaption( this, IDUIF_CAPTION, &rc, UIWNDCAPTION_INACTIVE );
  1359. if (m_pCaptionObj != NULL) {
  1360. m_pCaptionObj->Initialize();
  1361. AddUIObj( m_pCaptionObj );
  1362. }
  1363. //
  1364. //
  1365. //
  1366. m_pCandTipBtn = new CUIFButton2( this, IDUIF_CANDTIPBTN, &rc, UIBUTTON_CENTER | UIBUTTON_VCENTER );
  1367. if (m_pCandTipBtn != NULL) {
  1368. m_pCandTipBtn->Initialize();
  1369. AddUIObj( m_pCandTipBtn );
  1370. m_pCandTipBtn->SetIcon( m_hIconCandTipOff );
  1371. }
  1372. //
  1373. // create candidate tip window
  1374. //
  1375. m_pCandTipWnd = new CUIFBalloonWindow( g_hInst, 0 );
  1376. if (m_pCandTipWnd) {
  1377. m_pCandTipWnd->Initialize();
  1378. m_pCandTipWnd->SetFont( GetPropertyMgr()->GetToolTipProp()->GetFont() );
  1379. }
  1380. //
  1381. // create poupup window
  1382. //
  1383. m_pCommentWnd = new CPopupCommentWindow( this, m_pCandUI );
  1384. if (m_pCommentWnd != NULL) {
  1385. m_pCommentWnd->Initialize();
  1386. }
  1387. //
  1388. // Initialize accessibility item
  1389. //
  1390. if (m_pCandAcc != NULL) {
  1391. m_pListUIObj->InitAccItems( m_pCandAcc );
  1392. }
  1393. //
  1394. // Notify UI object creation
  1395. //
  1396. NotifyUIObjectEvent( CANDUIOBJ_OPTIONSLISTBOX, CANDUIOBJEV_CREATED );
  1397. NotifyUIObjectEvent( CANDUIOBJ_CANDLISTBOX, CANDUIOBJEV_CREATED );
  1398. NotifyUIObjectEvent( CANDUIOBJ_CANDCAPTION, CANDUIOBJEV_CREATED );
  1399. NotifyUIObjectEvent( CANDUIOBJ_MENUBUTTON, CANDUIOBJEV_CREATED );
  1400. NotifyUIObjectEvent( CANDUIOBJ_EXTRACANDIDATE, CANDUIOBJEV_CREATED );
  1401. NotifyUIObjectEvent( CANDUIOBJ_CANDRAWDATA, CANDUIOBJEV_CREATED );
  1402. NotifyUIObjectEvent( CANDUIOBJ_CANDTIPBUTTON, CANDUIOBJEV_CREATED );
  1403. return CCandWindowBase::Initialize();
  1404. }
  1405. /* G E T W N D S T Y L E */
  1406. /*------------------------------------------------------------------------------
  1407. ------------------------------------------------------------------------------*/
  1408. DWORD CCandWindow::GetWndStyle( void )
  1409. {
  1410. return CCandWindowBase::GetWndStyle() & ~WS_BORDER;
  1411. }
  1412. /* O N T I M E R */
  1413. /*------------------------------------------------------------------------------
  1414. ------------------------------------------------------------------------------*/
  1415. void CCandWindow::OnTimer( UINT uiTimerID )
  1416. {
  1417. if (uiTimerID == IDTIMER_POPUPCOMMENT_SELECT || uiTimerID == IDTIMER_POPUPCOMMENT_HOVER) {
  1418. int iItem;
  1419. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_SELECT );
  1420. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_HOVER );
  1421. iItem = (uiTimerID == IDTIMER_POPUPCOMMENT_SELECT) ? m_iItemAttensionSelect : m_iItemAttensionHover;
  1422. OpenCommentWindow( iItem );
  1423. }
  1424. else if (uiTimerID == IDTIMER_MENU_HOVER) {
  1425. // Check mouse position.
  1426. POINT pt;
  1427. RECT rc;
  1428. GetCursorPos(&pt);
  1429. ScreenToClient(m_hWnd, &pt);
  1430. m_pOptionsListUIObj->GetRect(&rc);
  1431. pt.x -= rc.left;
  1432. pt.y -= rc.top;
  1433. if (pt.x < 0 || pt.y < 0 || pt.x > (rc.right - rc.left) || pt.y > (rc.bottom - rc.top))
  1434. {
  1435. KillTimer(m_hWnd, IDTIMER_MENU_HOVER);
  1436. // Send messages that Cicero does on the mouse monitoring timer to trigger correct behavior and
  1437. // unselect the menu item.
  1438. SetObjectPointed( NULL, pt );
  1439. OnMouseOutFromWindow( pt );
  1440. }
  1441. else
  1442. {
  1443. SetTimer(m_hWnd, IDTIMER_MENU_HOVER, 50, NULL);
  1444. }
  1445. }
  1446. }
  1447. /* O N S Y S C O L O R C H A N G E */
  1448. /*------------------------------------------------------------------------------
  1449. (CUIFWindow method)
  1450. ------------------------------------------------------------------------------*/
  1451. void CCandWindow::OnSysColorChange()
  1452. {
  1453. CCandWindowBase::OnSysColorChange();
  1454. if (m_pCandTipBtn) {
  1455. m_pCandTipBtn->SetIcon( m_fCandTipWndOpen ? m_hIconCandTipOn : m_hIconCandTipOff );
  1456. }
  1457. }
  1458. /* O N O B J E C T N O T I F Y */
  1459. /*------------------------------------------------------------------------------
  1460. ------------------------------------------------------------------------------*/
  1461. LRESULT CCandWindow::OnObjectNotify( CUIFObject *pUIObj, DWORD dwCommand, LPARAM lParam )
  1462. {
  1463. // check hovering item
  1464. if (pUIObj->GetID() == IDUIF_OPTIONSLIST) {
  1465. if (dwCommand == UICANDLIST_HOVERITEM) {
  1466. int iCandItem = OptionItemFromListItem( (int)lParam );
  1467. SetOptionsAttensionByHover( iCandItem );
  1468. }
  1469. }
  1470. else if (pUIObj->GetID() == IDUIF_CANDIDATELIST) {
  1471. if (dwCommand == UICANDLIST_HOVERITEM) {
  1472. int iCandItem = CandItemFromListItem( (int)lParam );
  1473. SetAttensionByHover( iCandItem );
  1474. }
  1475. else if (dwCommand == UILIST_SELCHANGED) {
  1476. int iCandItem = CandItemFromListItem( (int)lParam );
  1477. SetAttensionBySelect( iCandItem );
  1478. }
  1479. }
  1480. else if (pUIObj->GetID() == IDUIF_EXTCANDIDATELIST) {
  1481. if (dwCommand == UILIST_SELECTED) {
  1482. m_pCandUI->NotifyCompleteExtraCand();
  1483. return 0;
  1484. }
  1485. }
  1486. else if (pUIObj->GetID() == IDUIF_CANDTIPBTN) {
  1487. if (m_fCandTipWndOpen) {
  1488. CloseCandTipWindow();
  1489. m_fCandTipWndOpen = FALSE;
  1490. }
  1491. else {
  1492. OpenCandTipWindow();
  1493. m_fCandTipWndOpen = TRUE;
  1494. }
  1495. m_pCandTipBtn->SetIcon( m_fCandTipWndOpen ? m_hIconCandTipOn : m_hIconCandTipOff );
  1496. }
  1497. return CCandWindowBase::OnObjectNotify( pUIObj, dwCommand, lParam );
  1498. }
  1499. /* S E T T A R G E T R E C T */
  1500. /*------------------------------------------------------------------------------
  1501. ------------------------------------------------------------------------------*/
  1502. void CCandWindow::SetTargetRect( RECT *prc, BOOL fClipped )
  1503. {
  1504. SIZE sizeWnd;
  1505. sizeWnd.cx = _nWidth;
  1506. sizeWnd.cy = _nHeight;
  1507. if (IsShadowEnabled() && m_pWndShadow) {
  1508. SIZE sizeShadow;
  1509. m_pWndShadow->GetShift( &sizeShadow );
  1510. sizeWnd.cx += sizeShadow.cx;
  1511. sizeWnd.cy += sizeShadow.cy;
  1512. }
  1513. m_rcTarget = *prc;
  1514. m_fTargetClipped = fClipped;
  1515. if (m_hWnd != NULL) {
  1516. RECT rc;
  1517. // move window here...
  1518. switch (GetPropertyMgr()->GetCandWindowProp()->GetUIDirection()) {
  1519. default:
  1520. case CANDUIDIR_TOPTOBOTTOM: {
  1521. CalcWindowRect( &rc, &m_rcTarget, sizeWnd.cx, sizeWnd.cy, m_cxWndOffset, m_cyWndOffset, ALIGN_LEFT, LOCATE_BELLOW );
  1522. break;
  1523. }
  1524. case CANDUIDIR_BOTTOMTOTOP: {
  1525. CalcWindowRect( &rc, &m_rcTarget, sizeWnd.cx, sizeWnd.cy, m_cxWndOffset, m_cyWndOffset, ALIGN_RIGHT, LOCATE_ABOVE );
  1526. break;
  1527. }
  1528. case CANDUIDIR_RIGHTTOLEFT: {
  1529. CalcWindowRect( &rc, &m_rcTarget, sizeWnd.cx, sizeWnd.cy, m_cxWndOffset, m_cyWndOffset, LOCATE_LEFT, ALIGN_TOP );
  1530. break;
  1531. }
  1532. case CANDUIDIR_LEFTTORIGHT: {
  1533. CalcWindowRect( &rc, &m_rcTarget, sizeWnd.cx, sizeWnd.cy, m_cxWndOffset, m_cyWndOffset, LOCATE_RIGHT, ALIGN_BOTTOM );
  1534. break;
  1535. }
  1536. }
  1537. if (rc.left != _xWnd || rc.top != _yWnd) {
  1538. Move( rc.left, rc.top, -1, -1 );
  1539. //
  1540. if (m_pCommentWnd != NULL) {
  1541. m_pCommentWnd->OnCandWindowMove( TRUE );
  1542. }
  1543. if (m_pCandTipWnd != NULL) {
  1544. MoveCandTipWindow();
  1545. }
  1546. }
  1547. }
  1548. }
  1549. /* S E T W I N D O W P O S */
  1550. /*------------------------------------------------------------------------------
  1551. ------------------------------------------------------------------------------*/
  1552. void CCandWindow::SetWindowPos( POINT pt )
  1553. {
  1554. if (m_hWnd != NULL) {
  1555. RECT rc;
  1556. rc.left = pt.x;
  1557. rc.top = pt.y;
  1558. rc.right = pt.x + _nWidth;
  1559. rc.bottom = pt.y + _nHeight;
  1560. AdjustWindowRect( NULL, &rc, &pt, FALSE );
  1561. if (rc.left != _xWnd || rc.top != _yWnd) {
  1562. Move( rc.left, rc.top, -1, -1 );
  1563. //
  1564. if (m_pCommentWnd != NULL) {
  1565. m_pCommentWnd->OnCandWindowMove( TRUE );
  1566. }
  1567. if (m_pCandTipWnd != NULL) {
  1568. MoveCandTipWindow();
  1569. }
  1570. }
  1571. }
  1572. }
  1573. /* P R E P A R E L A Y O U T */
  1574. /*------------------------------------------------------------------------------
  1575. Prepare to layout window
  1576. NOTE: This method will be called just once after created (not called when
  1577. candidate list has updated)
  1578. ------------------------------------------------------------------------------*/
  1579. void CCandWindow::PrepareLayout( void )
  1580. {
  1581. // determine lines of options list ui object
  1582. m_nOptionsItemShow = m_pOptionsListUIObj->GetCount();
  1583. // determine lines of list ui object
  1584. if (GetPropertyMgr()->GetCandListBoxProp()->GetHeight() == -1) {
  1585. m_nItemShow = min( m_pListUIObj->GetCount(), NUM_CANDSTR_MAX );
  1586. m_nItemShow = max( m_nItemShow, 1 );
  1587. }
  1588. else {
  1589. m_nItemShow = GetPropertyMgr()->GetCandListBoxProp()->GetHeight();
  1590. }
  1591. Assert((1 <= m_nItemShow) && (m_nItemShow <= 9));
  1592. // determine candtip window open status
  1593. m_fCandTipWndOpen = (GetCandListMgr()->GetCandList()->GetTipString() != NULL);
  1594. }
  1595. /* L A Y O U T W I N D O W */
  1596. /*------------------------------------------------------------------------------
  1597. Layout window
  1598. ------------------------------------------------------------------------------*/
  1599. void CCandWindow::LayoutWindow( void )
  1600. {
  1601. HDC hDC = GetDC( m_hWnd );
  1602. int nChild;
  1603. int i;
  1604. CUIFObject *pUIObj;
  1605. // metrics
  1606. SIZE sizeMetText;
  1607. SIZE sizeMetCaptionText;
  1608. SIZE sizeMetCandItem;
  1609. #ifdef NEVER
  1610. SIZE sizeMetCandNum;
  1611. #endif
  1612. SIZE sizeMetSmButton;
  1613. SIZE sizeMetScroll;
  1614. SIZE sizeMetBorder;
  1615. #ifdef NEVER
  1616. SIZE sizeMetMargin;
  1617. #endif
  1618. SIZE sizeMetWndFrame;
  1619. SIZE sizeCaptionObj = {0};
  1620. SIZE sizeExtCandListObj = {0};
  1621. SIZE sizeExtCandListBdr = {0};
  1622. SIZE sizeOptionsListObj = {0};
  1623. SIZE sizeOptionsListBdr = {0};
  1624. SIZE sizeCandListObj = {0};
  1625. SIZE sizeRawDataObj = {0};
  1626. SIZE sizeRawDataBdr = {0};
  1627. SIZE sizeCandListArea = {0};
  1628. SIZE sizeExtensionArea = {0};
  1629. SIZE sizeWindow = {0};
  1630. RECT rcClient = {0};
  1631. RECT rcWindow = {0};
  1632. RECT rcCaptionObj = {0};
  1633. RECT rcOptionsListBdr = {0};
  1634. RECT rcCandListArea = {0};
  1635. RECT rcExtensionArea = {0};
  1636. RECT rcExtCandListObj = {0};
  1637. RECT rcExtCandListBdr = {0};
  1638. RECT rcOptionsListObj = {0};
  1639. RECT rcCandListObj = {0};
  1640. RECT rcRawDataObj = {0};
  1641. RECT rcRawDataBdr = {0};
  1642. int cxMax = 0;
  1643. int cxMaxCandString = 0;
  1644. int cxMaxInlineComment = 0;
  1645. int cxInlineCommentPos = 0;
  1646. int cxyExtraTopSpace = 0;
  1647. int cxyExtraBottomSpace = 0;
  1648. DWORD dwListStyle;
  1649. DWORD dwBdrStyle;
  1650. CANDUIUIDIRECTION uidir = GetPropertyMgr()->GetCandWindowProp()->GetUIDirection();
  1651. #ifdef NEVER
  1652. BOOL fShowNumber = !FHasStyle( UIWINDOW_OFFICENEWLOOK );
  1653. #endif
  1654. BOOL fShowCaption = GetPropertyMgr()->GetWindowCaptionProp()->IsVisible();
  1655. BOOL fShowCandTip = (GetCandListMgr()->GetCandList() != NULL) ? (GetCandListMgr()->GetCandList()->GetTipString() != NULL) : FALSE;
  1656. HFONT hFontUI = (HFONT)GetStockObject( DEFAULT_GUI_FONT );
  1657. HFONT hFontCandidateList = GetPropertyMgr()->GetCandStringProp()->GetFont();
  1658. HFONT hFontInlineComment = GetPropertyMgr()->GetInlineCommentProp()->GetFont();
  1659. HFONT hFontIndex = GetPropertyMgr()->GetCandIndexProp()->GetFont();
  1660. HFONT hFontCaption = GetPropertyMgr()->GetWindowCaptionProp()->GetFont();
  1661. BOOL fHasExtension = (0 < GetExtensionMgr()->GetExtensionNum());
  1662. BOOL fShowExtCandList = FALSE;
  1663. BOOL fShowOptionsCandList = FALSE;
  1664. BOOL fHasPopupComment = FALSE;
  1665. Assert( 1 <= m_nItemShow );
  1666. //
  1667. // set font of UI object
  1668. //
  1669. nChild = m_ChildList.GetCount();
  1670. for (i = 0; i < nChild; i++) {
  1671. CUIFObject *pUIObjTmp = m_ChildList.Get( i );
  1672. Assert( pUIObjTmp != NULL );
  1673. if (pUIObjTmp == m_pListUIObj) {
  1674. m_pListUIObj->SetFont( hFontCandidateList );
  1675. m_pListUIObj->SetInlineCommentFont( hFontInlineComment );
  1676. m_pListUIObj->SetIndexFont( hFontIndex );
  1677. }
  1678. else if (pUIObjTmp == m_pOptionsListUIObj) {
  1679. m_pOptionsListUIObj->SetFont( hFontCandidateList );
  1680. m_pOptionsListUIObj->SetInlineCommentFont( hFontInlineComment );
  1681. m_pOptionsListUIObj->SetIndexFont( hFontIndex );
  1682. }
  1683. else if (pUIObjTmp == m_pExtListUIObj) {
  1684. m_pExtListUIObj->SetFont( hFontCandidateList );
  1685. m_pExtListUIObj->SetInlineCommentFont( hFontInlineComment );
  1686. m_pExtListUIObj->SetIndexFont( hFontIndex );
  1687. }
  1688. else if (pUIObjTmp == m_pCaptionObj) {
  1689. pUIObjTmp->SetFont( hFontCaption );
  1690. }
  1691. else {
  1692. pUIObjTmp->SetFont( hFontUI );
  1693. }
  1694. }
  1695. //
  1696. // calculate metrics
  1697. //
  1698. // window frame
  1699. sizeMetWndFrame.cx = 0;
  1700. sizeMetWndFrame.cy = 0;
  1701. if (m_pWndFrame != NULL) {
  1702. m_pWndFrame->GetFrameSize( &sizeMetWndFrame );
  1703. }
  1704. // candidate item
  1705. sizeMetText.cx = GetFontHeightOfFont( hDC, hFontCandidateList );
  1706. sizeMetText.cy = GetFontHeightOfFont( hDC, hFontCandidateList );
  1707. sizeMetCandItem.cx = sizeMetText.cy * 4;
  1708. sizeMetCandItem.cy = m_pUIFScheme->CyMenuItem( sizeMetText.cy );
  1709. // Options list.
  1710. if (m_pOptionsListUIObj != NULL) {
  1711. HFONT hFontOld = (HFONT)GetCurrentObject( hDC, OBJ_FONT );
  1712. int nItem = m_pOptionsListUIObj->GetCount();
  1713. LPCWSTR psz;
  1714. SIZE size;
  1715. CCandidateItem *pOptionsItem;
  1716. fShowOptionsCandList = (0 < nItem);
  1717. // get candidate string width
  1718. SelectObject( hDC, hFontCandidateList );
  1719. for (i = 0; i < nItem; i++) {
  1720. pOptionsItem = m_pOptionsListUIObj->GetCandidateItem( i );
  1721. // can't really do anything if this is null
  1722. //
  1723. if ( !pOptionsItem )
  1724. continue;
  1725. psz = pOptionsItem->GetString();
  1726. if (psz != NULL) {
  1727. SIZE sizeT;
  1728. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &size );
  1729. if (pOptionsItem->GetIcon() != NULL) {
  1730. size.cx += sizeMetCandItem.cy;
  1731. }
  1732. if (psz = pOptionsItem->GetPrefixString()) {
  1733. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &sizeT );
  1734. size.cx += sizeT.cx;
  1735. }
  1736. if (psz = pOptionsItem->GetSuffixString()) {
  1737. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &sizeT );
  1738. size.cx += sizeT.cx;
  1739. }
  1740. cxMaxCandString = max( cxMaxCandString, size.cx );
  1741. // check if it has popup comment
  1742. if (pOptionsItem->GetPopupComment() != NULL) {
  1743. fHasPopupComment = TRUE;
  1744. }
  1745. }
  1746. }
  1747. // get inline comment width
  1748. SelectObject( hDC, hFontInlineComment );
  1749. for (i = 0; i < nItem; i++) {
  1750. pOptionsItem = m_pOptionsListUIObj->GetCandidateItem( i );
  1751. if (pOptionsItem) {
  1752. psz = pOptionsItem->GetInlineComment();
  1753. if (psz != NULL) {
  1754. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &size );
  1755. cxMaxInlineComment = max( cxMaxInlineComment, size.cx );
  1756. }
  1757. }
  1758. }
  1759. SelectObject( hDC, hFontOld );
  1760. }
  1761. // Main candidate list.
  1762. if (m_pListUIObj != NULL) {
  1763. HFONT hFontOld = (HFONT)GetCurrentObject( hDC, OBJ_FONT );
  1764. int nItem = m_pListUIObj->GetCount();
  1765. LPCWSTR psz;
  1766. SIZE size;
  1767. CCandidateItem *pCandItem;
  1768. // get candidate string width
  1769. SelectObject( hDC, hFontCandidateList );
  1770. for (i = 0; i < nItem; i++) {
  1771. pCandItem = m_pListUIObj->GetCandidateItem( i );
  1772. // can't really do anything if this is null
  1773. //
  1774. if ( !pCandItem )
  1775. continue;
  1776. psz = pCandItem->GetString();
  1777. if (psz != NULL) {
  1778. SIZE sizeT;
  1779. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &size );
  1780. if (pCandItem->GetIcon() != NULL) {
  1781. size.cx += sizeMetCandItem.cy;
  1782. }
  1783. if (psz = pCandItem->GetPrefixString()) {
  1784. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &sizeT );
  1785. size.cx += sizeT.cx;
  1786. }
  1787. if (psz = pCandItem->GetSuffixString()) {
  1788. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &sizeT );
  1789. size.cx += sizeT.cx;
  1790. }
  1791. cxMaxCandString = max( cxMaxCandString, size.cx );
  1792. // check if it has popup comment
  1793. if (pCandItem->GetPopupComment() != NULL) {
  1794. fHasPopupComment = TRUE;
  1795. }
  1796. }
  1797. }
  1798. // get inline comment width
  1799. SelectObject( hDC, hFontInlineComment );
  1800. for (i = 0; i < nItem; i++) {
  1801. pCandItem = m_pListUIObj->GetCandidateItem( i );
  1802. if (pCandItem) {
  1803. psz = pCandItem->GetInlineComment();
  1804. if (psz != NULL) {
  1805. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &size );
  1806. cxMaxInlineComment = max( cxMaxInlineComment, size.cx );
  1807. }
  1808. }
  1809. }
  1810. SelectObject( hDC, hFontOld );
  1811. }
  1812. // extra candidate item
  1813. if (m_pExtListUIObj != NULL) {
  1814. HFONT hFontOld = (HFONT)GetCurrentObject( hDC, OBJ_FONT );
  1815. int nItem = m_pExtListUIObj->GetCount();
  1816. LPCWSTR psz;
  1817. SIZE size;
  1818. CCandidateItem *pCandItem;
  1819. fShowExtCandList = (0 < nItem);
  1820. Assert( nItem <= 1 );
  1821. // get candidate string width
  1822. SelectObject( hDC, hFontCandidateList );
  1823. for (i = 0; i < nItem; i++) {
  1824. pCandItem = m_pExtListUIObj->GetCandidateItem( i );
  1825. // can't really do anything if this is null
  1826. //
  1827. if ( !pCandItem )
  1828. continue;
  1829. psz = pCandItem->GetString();
  1830. if (psz != NULL) {
  1831. SIZE sizeT;
  1832. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &size );
  1833. if (pCandItem->GetIcon() != NULL) {
  1834. size.cx += sizeMetCandItem.cy;
  1835. }
  1836. if (psz = pCandItem->GetPrefixString()) {
  1837. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &sizeT );
  1838. size.cx += sizeT.cx;
  1839. }
  1840. if (psz = pCandItem->GetSuffixString()) {
  1841. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &sizeT );
  1842. size.cx += sizeT.cx;
  1843. }
  1844. cxMaxCandString = max( cxMaxCandString, size.cx );
  1845. // check if it has popup comment
  1846. if (pCandItem->GetPopupComment() != NULL) {
  1847. fHasPopupComment = TRUE;
  1848. }
  1849. }
  1850. }
  1851. // get inline comment width
  1852. SelectObject( hDC, hFontInlineComment );
  1853. for (i = 0; i < nItem; i++) {
  1854. pCandItem = m_pExtListUIObj->GetCandidateItem( i );
  1855. if (pCandItem) {
  1856. psz = pCandItem->GetInlineComment();
  1857. if (psz != NULL) {
  1858. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &size );
  1859. cxMaxInlineComment = max( cxMaxInlineComment, size.cx );
  1860. }
  1861. }
  1862. }
  1863. SelectObject( hDC, hFontOld );
  1864. }
  1865. // calc width of candidate item and inline comment
  1866. if (0 < cxMaxInlineComment) {
  1867. int cxT = (cxMaxCandString + sizeMetText.cy / 2 + cxMaxInlineComment);
  1868. cxT += 8 /* margen at left */ + (fHasPopupComment ? sizeMetText.cy / 2 + sizeMetCandItem.cy : 0) + 8 /* margin at right */;
  1869. cxInlineCommentPos = cxMaxCandString + sizeMetText.cy / 2;
  1870. sizeMetCandItem.cx = max( sizeMetCandItem.cx, cxT );
  1871. }
  1872. else {
  1873. int cxT = cxMaxCandString;
  1874. cxT += 8 /* margen at left */ + (fHasPopupComment ? sizeMetText.cy / 2 + sizeMetCandItem.cy : 0) + 8 /* margin at right */;
  1875. cxInlineCommentPos = 0;
  1876. sizeMetCandItem.cx = max( sizeMetCandItem.cx, cxT );
  1877. }
  1878. #ifdef NEVER
  1879. // number button
  1880. sizeMetCandNum.cx = sizeMetCandItem.cy;
  1881. sizeMetCandNum.cy = sizeMetCandItem.cy;
  1882. #endif
  1883. // scrollbar
  1884. sizeMetScroll.cx = GetSystemMetrics( SM_CXVSCROLL );
  1885. sizeMetScroll.cy = GetSystemMetrics( SM_CYHSCROLL );
  1886. // candidate menu button
  1887. switch (uidir) {
  1888. default:
  1889. case CANDUIDIR_TOPTOBOTTOM:
  1890. case CANDUIDIR_BOTTOMTOTOP: {
  1891. sizeMetSmButton.cx = sizeMetSmButton.cy = sizeMetScroll.cx;
  1892. break;
  1893. }
  1894. case CANDUIDIR_RIGHTTOLEFT:
  1895. case CANDUIDIR_LEFTTORIGHT: {
  1896. sizeMetSmButton.cx = sizeMetSmButton.cy = sizeMetScroll.cy;
  1897. break;
  1898. }
  1899. }
  1900. // caption text
  1901. if (m_pCaptionObj != NULL) {
  1902. HFONT hFontOld = (HFONT)SelectObject( hDC, hFontCaption );
  1903. LPCWSTR psz;
  1904. SIZE size;
  1905. psz = GetPropertyMgr()->GetWindowCaptionProp()->GetText();
  1906. if (psz != NULL) {
  1907. FLGetTextExtentPoint32( hDC, psz, wcslen(psz), &size );
  1908. }
  1909. else {
  1910. FLGetTextExtentPoint32( hDC, L" ", 1, &size );
  1911. }
  1912. sizeMetCaptionText.cx = size.cx;
  1913. sizeMetCaptionText.cy = size.cy;
  1914. SelectObject( hDC, hFontOld);
  1915. }
  1916. // border
  1917. sizeMetBorder.cx = 3;
  1918. sizeMetBorder.cy = 3;
  1919. #ifdef NEVER
  1920. // object margin
  1921. sizeMetMargin.cx = 1;
  1922. sizeMetMargin.cy = 1;
  1923. #endif
  1924. //
  1925. // calculate sizes of objects
  1926. //
  1927. // caption
  1928. sizeCaptionObj.cx = 0;
  1929. sizeCaptionObj.cy = 0;
  1930. if (fShowCaption) {
  1931. sizeCaptionObj.cx = sizeMetCaptionText.cx + 16;
  1932. sizeCaptionObj.cy = sizeMetCaptionText.cy + 2;
  1933. }
  1934. // extra candidate list
  1935. sizeExtCandListObj.cx = 0;
  1936. sizeExtCandListObj.cy = 0;
  1937. sizeExtCandListBdr.cx = 0;
  1938. sizeExtCandListBdr.cy = 0;
  1939. if (fShowExtCandList) {
  1940. switch (uidir) {
  1941. default:
  1942. case CANDUIDIR_TOPTOBOTTOM:
  1943. case CANDUIDIR_BOTTOMTOTOP: {
  1944. sizeExtCandListObj.cx = sizeMetCandItem.cx + sizeMetScroll.cx + sizeMetCandItem.cy + 4;
  1945. sizeExtCandListObj.cy = sizeMetCandItem.cy;
  1946. sizeExtCandListBdr.cx = sizeExtCandListObj.cx;
  1947. sizeExtCandListBdr.cy = sizeMetBorder.cy;
  1948. break;
  1949. }
  1950. case CANDUIDIR_RIGHTTOLEFT:
  1951. case CANDUIDIR_LEFTTORIGHT: {
  1952. sizeExtCandListObj.cx = sizeMetCandItem.cy;
  1953. sizeExtCandListObj.cy = sizeMetCandItem.cx + sizeMetScroll.cx + sizeMetCandItem.cy + 4;
  1954. sizeExtCandListBdr.cx = sizeMetBorder.cx;
  1955. sizeExtCandListBdr.cy = sizeExtCandListObj.cy;
  1956. break;
  1957. }
  1958. }
  1959. }
  1960. // Options candidate list
  1961. #ifdef NEVER
  1962. if (FHasStyle( UIWINDOW_OFFICENEWLOOK )) {
  1963. #endif
  1964. switch (uidir) {
  1965. default:
  1966. case CANDUIDIR_TOPTOBOTTOM:
  1967. case CANDUIDIR_BOTTOMTOTOP: {
  1968. sizeOptionsListObj.cx = sizeMetCandItem.cx + sizeMetScroll.cx + sizeMetCandItem.cy + 4;
  1969. sizeOptionsListObj.cy = sizeMetCandItem.cy * m_nOptionsItemShow;
  1970. sizeOptionsListBdr.cx = sizeOptionsListObj.cx;
  1971. sizeOptionsListBdr.cy = fShowOptionsCandList ? sizeMetBorder.cy : 0;
  1972. break;
  1973. }
  1974. case CANDUIDIR_RIGHTTOLEFT:
  1975. case CANDUIDIR_LEFTTORIGHT: {
  1976. sizeOptionsListObj.cx = sizeMetCandItem.cy * m_nOptionsItemShow;
  1977. sizeOptionsListObj.cy = sizeMetCandItem.cx + sizeMetScroll.cy + sizeMetCandItem.cy + 4;
  1978. sizeOptionsListBdr.cx = fShowOptionsCandList ? sizeMetBorder.cx : 0;
  1979. sizeOptionsListBdr.cy = sizeOptionsListObj.cy;
  1980. break;
  1981. }
  1982. }
  1983. #ifdef NEVER
  1984. }
  1985. else {
  1986. switch (uidir) {
  1987. default:
  1988. case CANDUIDIR_TOPTOBOTTOM:
  1989. case CANDUIDIR_BOTTOMTOTOP: {
  1990. sizeOptionsListObj.cx = sizeMetCandItem.cx + sizeMetScroll.cx;
  1991. sizeOptionsListObj.cy = sizeMetCandItem.cy * m_nOptionsItemShow;
  1992. sizeOptionsListBdr.cx = sizeOptionsListObj.cx;
  1993. sizeOptionsListBdr.cy = sizeMetBorder.cy;
  1994. m_cxWndOffset = -(sizeMetWndFrame.cx + (fShowNumber ? sizeMetCandNum.cx + sizeMetMargin.cx + sizeMetBorder.cx + sizeMetMargin.cx : 0));
  1995. m_cyWndOffset = 0;
  1996. break;
  1997. }
  1998. case CANDUIDIR_RIGHTTOLEFT:
  1999. case CANDUIDIR_LEFTTORIGHT: {
  2000. sizeOptionsListObj.cx = sizeMetCandItem.cy * m_nOptionsItemShow;
  2001. sizeOptionsListObj.cy = sizeMetCandItem.cx + sizeMetScroll.cy;
  2002. sizeOptionsListBdr.cx = sizeMetBorder.cx;
  2003. sizeOptionsListBdr.cy = sizeOptionsListObj.cy;
  2004. m_cxWndOffset = 0;
  2005. m_cyWndOffset = -(sizeMetWndFrame.cy + (fShowNumber ? sizeMetCandNum.cy + sizeMetMargin.cy + sizeMetBorder.cy + sizeMetMargin.cy : 0));
  2006. break;
  2007. }
  2008. }
  2009. }
  2010. #endif
  2011. // candidate list
  2012. #ifdef NEVER
  2013. if (FHasStyle( UIWINDOW_OFFICENEWLOOK )) {
  2014. #endif
  2015. switch (uidir) {
  2016. default:
  2017. case CANDUIDIR_TOPTOBOTTOM:
  2018. case CANDUIDIR_BOTTOMTOTOP: {
  2019. sizeCandListObj.cx = sizeMetCandItem.cx + sizeMetScroll.cx + sizeMetCandItem.cy + 4;
  2020. sizeCandListObj.cy = sizeMetCandItem.cy * m_nItemShow;
  2021. break;
  2022. }
  2023. case CANDUIDIR_RIGHTTOLEFT:
  2024. case CANDUIDIR_LEFTTORIGHT: {
  2025. sizeCandListObj.cx = sizeMetCandItem.cy * m_nItemShow;
  2026. sizeCandListObj.cy = sizeMetCandItem.cx + sizeMetScroll.cy + sizeMetCandItem.cy + 4;
  2027. break;
  2028. }
  2029. }
  2030. #ifdef NEVER
  2031. }
  2032. else {
  2033. switch (uidir) {
  2034. default:
  2035. case CANDUIDIR_TOPTOBOTTOM:
  2036. case CANDUIDIR_BOTTOMTOTOP: {
  2037. sizeCandListObj.cx = sizeMetCandItem.cx + sizeMetScroll.cx;
  2038. sizeCandListObj.cy = sizeMetCandItem.cy * m_nItemShow;
  2039. m_cxWndOffset = -(sizeMetWndFrame.cx + (fShowNumber ? sizeMetCandNum.cx + sizeMetMargin.cx + sizeMetBorder.cx + sizeMetMargin.cx : 0));
  2040. m_cyWndOffset = 0;
  2041. break;
  2042. }
  2043. case CANDUIDIR_RIGHTTOLEFT:
  2044. case CANDUIDIR_LEFTTORIGHT: {
  2045. sizeCandListObj.cx = sizeMetCandItem.cy * m_nItemShow;
  2046. sizeCandListObj.cy = sizeMetCandItem.cx + sizeMetScroll.cy;
  2047. m_cxWndOffset = 0;
  2048. m_cyWndOffset = -(sizeMetWndFrame.cy + (fShowNumber ? sizeMetCandNum.cy + sizeMetMargin.cy + sizeMetBorder.cy + sizeMetMargin.cy : 0));
  2049. break;
  2050. }
  2051. }
  2052. }
  2053. #endif
  2054. // raw data
  2055. sizeRawDataObj.cx = 0;
  2056. sizeRawDataObj.cy = 0;
  2057. sizeRawDataBdr.cx = 0;
  2058. sizeRawDataBdr.cy = 0;
  2059. if (m_fHasRawData) {
  2060. switch (uidir) {
  2061. default:
  2062. case CANDUIDIR_TOPTOBOTTOM:
  2063. case CANDUIDIR_BOTTOMTOTOP: {
  2064. sizeRawDataObj.cx = sizeCandListObj.cx + 2;
  2065. sizeRawDataObj.cy = sizeMetText.cy * 3 / 2;
  2066. sizeRawDataBdr.cx = sizeRawDataObj.cx;
  2067. sizeRawDataBdr.cy = sizeMetBorder.cy;
  2068. break;
  2069. }
  2070. case CANDUIDIR_RIGHTTOLEFT:
  2071. case CANDUIDIR_LEFTTORIGHT: {
  2072. sizeRawDataObj.cx = sizeMetText.cy * 3 / 2;
  2073. sizeRawDataObj.cy = sizeCandListObj.cy + 2;
  2074. sizeRawDataBdr.cx = sizeMetBorder.cx;
  2075. sizeRawDataBdr.cy = sizeRawDataObj.cy;
  2076. break;
  2077. }
  2078. }
  2079. }
  2080. //
  2081. // calc offsets
  2082. //
  2083. #ifdef NEVER
  2084. if (FHasStyle( UIWINDOW_OFFICENEWLOOK )) {
  2085. #endif
  2086. switch (uidir) {
  2087. default:
  2088. case CANDUIDIR_TOPTOBOTTOM: {
  2089. m_cxWndOffset = -(sizeMetWndFrame.cx + sizeMetCandItem.cy + 4 + 8);
  2090. m_cyWndOffset = 0;
  2091. break;
  2092. }
  2093. case CANDUIDIR_BOTTOMTOTOP: {
  2094. m_cxWndOffset = +(sizeMetWndFrame.cx + sizeMetScroll.cx + 4);
  2095. m_cyWndOffset = 0;
  2096. break;
  2097. }
  2098. case CANDUIDIR_RIGHTTOLEFT: {
  2099. m_cxWndOffset = 0;
  2100. m_cyWndOffset = -(sizeMetWndFrame.cy + sizeMetCandItem.cy + 4 + 8);
  2101. break;
  2102. }
  2103. case CANDUIDIR_LEFTTORIGHT: {
  2104. m_cxWndOffset = 0;
  2105. m_cyWndOffset = +(sizeMetWndFrame.cy + sizeMetScroll.cy + 4);
  2106. break;
  2107. }
  2108. }
  2109. #ifdef NEVER
  2110. }
  2111. else {
  2112. switch (uidir) {
  2113. default:
  2114. case CANDUIDIR_TOPTOBOTTOM:
  2115. case CANDUIDIR_BOTTOMTOTOP: {
  2116. m_cxWndOffset = -(sizeMetWndFrame.cx + (fShowNumber ? sizeMetCandNum.cx + sizeMetMargin.cx + sizeMetBorder.cx + sizeMetMargin.cx : 0));
  2117. m_cyWndOffset = 0;
  2118. break;
  2119. }
  2120. case CANDUIDIR_RIGHTTOLEFT:
  2121. case CANDUIDIR_LEFTTORIGHT: {
  2122. m_cxWndOffset = 0;
  2123. m_cyWndOffset = -(sizeMetWndFrame.cy + (fShowNumber ? sizeMetCandNum.cy + sizeMetMargin.cy + sizeMetBorder.cy + sizeMetMargin.cy : 0));
  2124. break;
  2125. }
  2126. }
  2127. }
  2128. #endif
  2129. //
  2130. // calculate sizes of areas
  2131. //
  2132. // candlist area
  2133. #ifdef NEVER
  2134. if (FHasStyle( UIWINDOW_OFFICENEWLOOK )) {
  2135. #endif
  2136. switch (uidir) {
  2137. default:
  2138. case CANDUIDIR_TOPTOBOTTOM:
  2139. case CANDUIDIR_BOTTOMTOTOP: {
  2140. // candidate list
  2141. sizeCandListArea.cx = sizeCandListObj.cx;
  2142. sizeCandListArea.cy = sizeCandListObj.cy;
  2143. // options candidate list
  2144. sizeCandListArea.cx = max( sizeCandListArea.cx, sizeOptionsListObj.cx );
  2145. sizeCandListArea.cy += sizeOptionsListObj.cy + sizeOptionsListBdr.cy;
  2146. // extra candidate list
  2147. sizeCandListArea.cx = max( sizeCandListArea.cx, sizeExtCandListObj.cx );
  2148. sizeCandListArea.cy += sizeExtCandListObj.cy + sizeExtCandListBdr.cy;
  2149. // raw data
  2150. sizeCandListArea.cx = max( sizeCandListArea.cx, sizeRawDataObj.cx );
  2151. sizeCandListArea.cy += sizeRawDataObj.cy + sizeRawDataBdr.cy;
  2152. break;
  2153. }
  2154. case CANDUIDIR_RIGHTTOLEFT:
  2155. case CANDUIDIR_LEFTTORIGHT: {
  2156. // candidate list
  2157. sizeCandListArea.cx = sizeCandListObj.cx;
  2158. sizeCandListArea.cy = sizeCandListObj.cy;
  2159. // options candidate list
  2160. sizeCandListArea.cx += sizeOptionsListObj.cx + sizeOptionsListBdr.cx;
  2161. sizeCandListArea.cy = max( sizeCandListArea.cy, sizeOptionsListObj.cy );
  2162. // extra candidate list
  2163. sizeCandListArea.cx += sizeExtCandListObj.cx + sizeExtCandListBdr.cx;
  2164. sizeCandListArea.cy = max( sizeCandListArea.cy, sizeExtCandListObj.cy );
  2165. // raw data
  2166. sizeCandListArea.cx += sizeRawDataObj.cx + sizeRawDataBdr.cx;
  2167. sizeCandListArea.cy = max( sizeCandListArea.cy, sizeRawDataObj.cy );
  2168. break;
  2169. }
  2170. }
  2171. #ifdef NEVER
  2172. }
  2173. else {
  2174. sizeCandListArea.cx = sizeCandListObj.cx; /* be adjusted later */
  2175. sizeCandListArea.cy = sizeCandListObj.cy; /* be adjusted later */
  2176. if (fShowNumber) {
  2177. switch (uidir) {
  2178. default:
  2179. case CANDUIDIR_TOPTOBOTTOM:
  2180. case CANDUIDIR_BOTTOMTOTOP: {
  2181. sizeCandListArea.cx += sizeMetCandNum.cx + sizeMetMargin.cx + sizeMetBorder.cx + sizeMetMargin.cx;
  2182. break;
  2183. }
  2184. case CANDUIDIR_RIGHTTOLEFT:
  2185. case CANDUIDIR_LEFTTORIGHT: {
  2186. sizeCandListArea.cy += sizeMetCandNum.cy + sizeMetMargin.cy + sizeMetBorder.cy + sizeMetMargin.cy;
  2187. break;
  2188. }
  2189. }
  2190. }
  2191. }
  2192. #endif
  2193. // extension area
  2194. sizeExtensionArea.cx = 0;
  2195. sizeExtensionArea.cy = 0;
  2196. if (fHasExtension) {
  2197. SIZE size;
  2198. LONG nExtension;
  2199. LONG iExtension;
  2200. nExtension = GetExtensionMgr()->GetExtensionNum();
  2201. for (iExtension = 0; iExtension < nExtension; iExtension++) {
  2202. CCandUIExtension *pExtension = GetExtensionMgr()->GetExtension( iExtension );
  2203. pExtension->GetSize( &size );
  2204. sizeExtensionArea.cx += size.cx;
  2205. sizeExtensionArea.cy = max( sizeExtensionArea.cy, size.cy );
  2206. }
  2207. if (0 < nExtension) {
  2208. sizeExtensionArea.cx += 2;
  2209. sizeExtensionArea.cy += sizeMetBorder.cy;
  2210. }
  2211. }
  2212. //
  2213. // adjust object/area size
  2214. //
  2215. // max width
  2216. cxMax = sizeCaptionObj.cx;
  2217. cxMax = max( cxMax, sizeCandListArea.cx );
  2218. cxMax = max( cxMax, sizeExtensionArea.cx );
  2219. // size of areas
  2220. sizeCaptionObj.cx = cxMax;
  2221. sizeCandListArea.cx = cxMax;
  2222. sizeExtensionArea.cx = cxMax;
  2223. // objects in candidate list areas
  2224. switch (uidir) {
  2225. default:
  2226. case CANDUIDIR_TOPTOBOTTOM:
  2227. case CANDUIDIR_BOTTOMTOTOP: {
  2228. sizeExtCandListObj.cx = sizeCandListArea.cx;
  2229. sizeExtCandListBdr.cx = sizeCandListArea.cx;
  2230. sizeOptionsListObj.cx = sizeCandListArea.cx;
  2231. sizeOptionsListBdr.cx = sizeCandListArea.cx;
  2232. sizeCandListObj.cx = sizeCandListArea.cx;
  2233. sizeRawDataObj.cx = sizeCandListArea.cx;
  2234. sizeRawDataBdr.cx = sizeCandListArea.cx;
  2235. break;
  2236. }
  2237. case CANDUIDIR_RIGHTTOLEFT:
  2238. case CANDUIDIR_LEFTTORIGHT: {
  2239. sizeExtCandListObj.cy = sizeCandListArea.cy;
  2240. sizeExtCandListBdr.cy = sizeCandListArea.cy;
  2241. sizeOptionsListObj.cy = sizeCandListArea.cy;
  2242. sizeOptionsListBdr.cy = sizeCandListArea.cy;
  2243. sizeCandListObj.cy = sizeCandListArea.cy;
  2244. sizeRawDataObj.cy = sizeCandListArea.cy;
  2245. sizeRawDataBdr.cy = sizeCandListArea.cy;
  2246. break;
  2247. }
  2248. }
  2249. //
  2250. // calculate window size, client area
  2251. //
  2252. switch (uidir) {
  2253. default:
  2254. case CANDUIDIR_TOPTOBOTTOM:
  2255. case CANDUIDIR_BOTTOMTOTOP: {
  2256. // window size
  2257. sizeWindow.cx = sizeMetWndFrame.cx * 2 + cxMax;
  2258. sizeWindow.cy = sizeMetWndFrame.cy * 2 + sizeCaptionObj.cy + sizeCandListArea.cy + sizeExtensionArea.cy;
  2259. // margin at top and bottom
  2260. sizeWindow.cy += 2;
  2261. // client area
  2262. rcClient.left = sizeMetWndFrame.cx;
  2263. rcClient.top = sizeMetWndFrame.cy + 1;
  2264. rcClient.right = sizeWindow.cx - sizeMetWndFrame.cx;
  2265. rcClient.bottom = sizeWindow.cy - sizeMetWndFrame.cy - 1;
  2266. break;
  2267. }
  2268. case CANDUIDIR_RIGHTTOLEFT:
  2269. case CANDUIDIR_LEFTTORIGHT: {
  2270. // window size
  2271. sizeWindow.cx = sizeMetWndFrame.cx * 2 + cxMax;
  2272. sizeWindow.cy = sizeMetWndFrame.cy * 2 + sizeCaptionObj.cy + sizeCandListArea.cy + sizeExtensionArea.cy;
  2273. // margin at top and bottom
  2274. sizeWindow.cx += 2;
  2275. // client area
  2276. rcClient.left = sizeMetWndFrame.cx + 1;
  2277. rcClient.top = sizeMetWndFrame.cy;
  2278. rcClient.right = sizeWindow.cx - sizeMetWndFrame.cx + 1;
  2279. rcClient.bottom = sizeWindow.cy - sizeMetWndFrame.cy;
  2280. break;
  2281. }
  2282. }
  2283. //
  2284. // calculate area/object rects
  2285. //
  2286. // caption
  2287. rcCaptionObj.left = rcClient.left;
  2288. rcCaptionObj.top = rcClient.top;
  2289. rcCaptionObj.right = rcCaptionObj.left + sizeCaptionObj.cx;
  2290. rcCaptionObj.bottom = rcCaptionObj.top + sizeCaptionObj.cy;
  2291. // candidate list area
  2292. rcCandListArea.left = rcClient.left;
  2293. rcCandListArea.top = rcCaptionObj.bottom;
  2294. rcCandListArea.right = rcCandListArea.left + sizeCandListArea.cx;
  2295. rcCandListArea.bottom = rcCandListArea.top + sizeCandListArea.cy;
  2296. // extension area
  2297. rcExtensionArea.left = rcClient.left;
  2298. rcExtensionArea.top = rcCandListArea.bottom;
  2299. rcExtensionArea.right = rcExtensionArea.left + sizeExtensionArea.cx;
  2300. rcExtensionArea.bottom = rcExtensionArea.top + sizeExtensionArea.cy;
  2301. //
  2302. // calculate object rects in candidate list area
  2303. //
  2304. switch (uidir) {
  2305. default:
  2306. case CANDUIDIR_TOPTOBOTTOM: {
  2307. int py = rcCandListArea.top;
  2308. // extra candidate list
  2309. rcExtCandListObj.left = rcCandListArea.left;
  2310. rcExtCandListObj.top = py;
  2311. rcExtCandListObj.right = rcExtCandListObj.left + sizeExtCandListObj.cx;
  2312. rcExtCandListObj.bottom = rcExtCandListObj.top + sizeExtCandListObj.cy;
  2313. py = rcExtCandListObj.bottom;
  2314. rcExtCandListBdr.left = rcCandListArea.left;
  2315. rcExtCandListBdr.top = py;
  2316. rcExtCandListBdr.right = rcExtCandListBdr.left + sizeExtCandListBdr.cx;
  2317. rcExtCandListBdr.bottom = rcExtCandListBdr.top + sizeExtCandListBdr.cy;
  2318. py = rcExtCandListBdr.bottom;
  2319. // candidate list
  2320. rcCandListObj.left = rcCandListArea.left;
  2321. rcCandListObj.top = py;
  2322. rcCandListObj.right = rcCandListObj.left + sizeCandListObj.cx;
  2323. rcCandListObj.bottom = rcCandListObj.top + sizeCandListObj.cy;
  2324. py = rcCandListObj.bottom;
  2325. // rawdata
  2326. rcRawDataBdr.left = rcCandListArea.left;
  2327. rcRawDataBdr.top = py;
  2328. rcRawDataBdr.right = rcRawDataBdr.left + sizeRawDataBdr.cx;
  2329. rcRawDataBdr.bottom = rcRawDataBdr.top + sizeRawDataBdr.cy;
  2330. py = rcRawDataBdr.bottom;
  2331. rcRawDataObj.left = rcCandListArea.left;
  2332. rcRawDataObj.top = py;
  2333. rcRawDataObj.right = rcRawDataObj.left + sizeRawDataObj.cx;
  2334. rcRawDataObj.bottom = rcRawDataObj.top + sizeRawDataObj.cy;
  2335. py = rcRawDataObj.bottom;
  2336. // options candidate list
  2337. rcOptionsListBdr.left = rcCandListArea.left;
  2338. rcOptionsListBdr.top = py;
  2339. rcOptionsListBdr.right = rcOptionsListBdr.left + sizeOptionsListBdr.cx;
  2340. rcOptionsListBdr.bottom = rcOptionsListBdr.top + sizeOptionsListBdr.cy;
  2341. py = rcOptionsListBdr.bottom;
  2342. rcOptionsListObj.left = rcCandListArea.left;
  2343. rcOptionsListObj.top = py;
  2344. rcOptionsListObj.right = rcOptionsListObj.left + sizeOptionsListObj.cx;
  2345. rcOptionsListObj.bottom = rcOptionsListObj.top + sizeOptionsListObj.cy;
  2346. py = rcOptionsListObj.bottom;
  2347. break;
  2348. }
  2349. case CANDUIDIR_BOTTOMTOTOP: {
  2350. int py = rcCandListArea.top;
  2351. // options candidate list
  2352. rcOptionsListObj.left = rcCandListArea.left;
  2353. rcOptionsListObj.top = py;
  2354. rcOptionsListObj.right = rcOptionsListObj.left + sizeOptionsListObj.cx;
  2355. rcOptionsListObj.bottom = rcOptionsListObj.top + sizeOptionsListObj.cy;
  2356. py = rcOptionsListObj.bottom;
  2357. rcOptionsListBdr.left = rcCandListArea.left;
  2358. rcOptionsListBdr.top = py;
  2359. rcOptionsListBdr.right = rcOptionsListBdr.left + sizeOptionsListBdr.cx;
  2360. rcOptionsListBdr.bottom = rcOptionsListBdr.top + sizeOptionsListBdr.cy;
  2361. py = rcOptionsListBdr.bottom;
  2362. // rawdata
  2363. rcRawDataObj.left = rcCandListArea.left;
  2364. rcRawDataObj.top = py;
  2365. rcRawDataObj.right = rcRawDataObj.left + sizeRawDataObj.cx;
  2366. rcRawDataObj.bottom = rcRawDataObj.top + sizeRawDataObj.cy;
  2367. py = rcRawDataObj.bottom;
  2368. rcRawDataBdr.left = rcCandListArea.left;
  2369. rcRawDataBdr.top = py;
  2370. rcRawDataBdr.right = rcRawDataBdr.left + sizeRawDataBdr.cx;
  2371. rcRawDataBdr.bottom = rcRawDataBdr.top + sizeRawDataBdr.cy;
  2372. py = rcRawDataBdr.bottom;
  2373. // candidate list
  2374. rcCandListObj.left = rcCandListArea.left;
  2375. rcCandListObj.top = py;
  2376. rcCandListObj.right = rcCandListObj.left + sizeCandListObj.cx;
  2377. rcCandListObj.bottom = rcCandListObj.top + sizeCandListObj.cy;
  2378. py = rcCandListObj.bottom;
  2379. // extra candidate list
  2380. rcExtCandListBdr.left = rcCandListArea.left;
  2381. rcExtCandListBdr.top = py;
  2382. rcExtCandListBdr.right = rcExtCandListBdr.left + sizeExtCandListBdr.cx;
  2383. rcExtCandListBdr.bottom = rcExtCandListBdr.top + sizeExtCandListBdr.cy;
  2384. py = rcExtCandListBdr.bottom;
  2385. rcExtCandListObj.left = rcCandListArea.left;
  2386. rcExtCandListObj.top = py;
  2387. rcExtCandListObj.right = rcExtCandListObj.left + sizeExtCandListObj.cx;
  2388. rcExtCandListObj.bottom = rcExtCandListObj.top + sizeExtCandListObj.cy;
  2389. py = rcExtCandListObj.bottom;
  2390. break;
  2391. }
  2392. case CANDUIDIR_RIGHTTOLEFT: {
  2393. int px = rcCandListArea.right;
  2394. // extra candidate list
  2395. rcExtCandListObj.left = px - sizeExtCandListObj.cx;
  2396. rcExtCandListObj.top = rcCandListArea.top;
  2397. rcExtCandListObj.right = rcExtCandListObj.left + sizeExtCandListObj.cx;
  2398. rcExtCandListObj.bottom = rcExtCandListObj.top + sizeExtCandListObj.cy;
  2399. px = rcExtCandListObj.left;
  2400. rcExtCandListBdr.left = px - sizeExtCandListBdr.cx;
  2401. rcExtCandListBdr.top = rcCandListArea.top;
  2402. rcExtCandListBdr.right = rcExtCandListBdr.left + sizeExtCandListBdr.cx;
  2403. rcExtCandListBdr.bottom = rcExtCandListBdr.top + sizeExtCandListBdr.cy;
  2404. px = rcExtCandListBdr.left;
  2405. // candidate list
  2406. rcCandListObj.left = px - sizeCandListObj.cx;
  2407. rcCandListObj.top = rcCandListArea.top;
  2408. rcCandListObj.right = rcCandListObj.left + sizeCandListObj.cx;
  2409. rcCandListObj.bottom = rcCandListObj.top + sizeCandListObj.cy;
  2410. px = rcCandListObj.left;
  2411. // rawdata
  2412. rcRawDataBdr.left = px - sizeRawDataBdr.cx;
  2413. rcRawDataBdr.top = rcCandListArea.top;
  2414. rcRawDataBdr.right = rcRawDataBdr.left + sizeRawDataBdr.cx;
  2415. rcRawDataBdr.bottom = rcRawDataBdr.top + sizeRawDataBdr.cy;
  2416. px = rcRawDataBdr.left;
  2417. rcRawDataObj.left = px - sizeRawDataObj.cx;
  2418. rcRawDataObj.top = rcCandListArea.top;
  2419. rcRawDataObj.right = rcRawDataObj.left + sizeRawDataObj.cx;
  2420. rcRawDataObj.bottom = rcRawDataObj.top + sizeRawDataObj.cy;
  2421. px = rcRawDataObj.left;
  2422. // options candidate list
  2423. rcOptionsListBdr.left = px - sizeOptionsListBdr.cx;
  2424. rcOptionsListBdr.top = rcCandListArea.top;
  2425. rcOptionsListBdr.right = rcOptionsListBdr.left + sizeOptionsListBdr.cx;
  2426. rcOptionsListBdr.bottom = rcOptionsListBdr.top + sizeOptionsListBdr.cy;
  2427. px = rcOptionsListBdr.left;
  2428. rcOptionsListObj.left = px - sizeOptionsListObj.cx;
  2429. rcOptionsListObj.top = rcCandListArea.top;
  2430. rcOptionsListObj.right = rcOptionsListObj.left + sizeOptionsListObj.cx;
  2431. rcOptionsListObj.bottom = rcOptionsListObj.top + sizeOptionsListObj.cy;
  2432. px = rcOptionsListObj.left;
  2433. break;
  2434. }
  2435. case CANDUIDIR_LEFTTORIGHT: {
  2436. int px = rcCandListArea.left;
  2437. // extra candidate list
  2438. rcExtCandListObj.left = px;
  2439. rcExtCandListObj.top = rcCandListArea.top;
  2440. rcExtCandListObj.right = rcExtCandListObj.left + sizeExtCandListObj.cx;
  2441. rcExtCandListObj.bottom = rcExtCandListObj.top + sizeExtCandListObj.cy;
  2442. px = rcExtCandListObj.right;
  2443. rcExtCandListBdr.left = px;
  2444. rcExtCandListBdr.top = rcCandListArea.top;
  2445. rcExtCandListBdr.right = rcExtCandListBdr.left + sizeExtCandListBdr.cx;
  2446. rcExtCandListBdr.bottom = rcExtCandListBdr.top + sizeExtCandListBdr.cy;
  2447. px = rcExtCandListBdr.right;
  2448. // candidate list
  2449. rcCandListObj.left = px;
  2450. rcCandListObj.top = rcCandListArea.top;
  2451. rcCandListObj.right = rcCandListObj.left + sizeCandListObj.cx;
  2452. rcCandListObj.bottom = rcCandListObj.top + sizeCandListObj.cy;
  2453. px = rcCandListObj.right;
  2454. // rawdata
  2455. rcRawDataBdr.left = px;
  2456. rcRawDataBdr.top = rcCandListArea.top;
  2457. rcRawDataBdr.right = rcRawDataBdr.left + sizeRawDataBdr.cx;
  2458. rcRawDataBdr.bottom = rcRawDataBdr.top + sizeRawDataBdr.cy;
  2459. px = rcRawDataBdr.right;
  2460. rcRawDataObj.left = px;
  2461. rcRawDataObj.top = rcCandListArea.top;
  2462. rcRawDataObj.right = rcRawDataObj.left + sizeRawDataObj.cx;
  2463. rcRawDataObj.bottom = rcRawDataObj.top + sizeRawDataObj.cy;
  2464. px = rcRawDataObj.right;
  2465. // options candidate list
  2466. rcOptionsListBdr.left = px;
  2467. rcOptionsListBdr.top = rcCandListArea.top;
  2468. rcOptionsListBdr.right = rcOptionsListBdr.left + sizeOptionsListBdr.cx;
  2469. rcOptionsListBdr.bottom = rcOptionsListBdr.top + sizeOptionsListBdr.cy;
  2470. px = rcOptionsListBdr.right;
  2471. rcOptionsListObj.left = px;
  2472. rcOptionsListObj.top = rcCandListArea.top;
  2473. rcOptionsListObj.right = rcOptionsListObj.left + sizeOptionsListObj.cx;
  2474. rcOptionsListObj.bottom = rcOptionsListObj.top + sizeOptionsListObj.cy;
  2475. px = rcOptionsListObj.right;
  2476. break;
  2477. }
  2478. }
  2479. //
  2480. // change window position and size
  2481. //
  2482. // window position
  2483. SIZE sizeTotal = sizeWindow;
  2484. if (IsShadowEnabled() && m_pWndShadow) {
  2485. SIZE sizeShadow;
  2486. m_pWndShadow->GetShift( &sizeShadow );
  2487. sizeTotal.cx += sizeShadow.cx;
  2488. sizeTotal.cy += sizeShadow.cy;
  2489. }
  2490. switch (uidir) {
  2491. default:
  2492. case CANDUIDIR_TOPTOBOTTOM: {
  2493. CalcWindowRect( &rcWindow, &m_rcTarget, sizeTotal.cx, sizeTotal.cy, m_cxWndOffset, m_cyWndOffset, ALIGN_LEFT, LOCATE_BELLOW );
  2494. break;
  2495. }
  2496. case CANDUIDIR_BOTTOMTOTOP: {
  2497. CalcWindowRect( &rcWindow, &m_rcTarget, sizeTotal.cx, sizeTotal.cy, m_cxWndOffset, m_cyWndOffset, ALIGN_RIGHT, LOCATE_ABOVE );
  2498. break;
  2499. }
  2500. case CANDUIDIR_RIGHTTOLEFT: {
  2501. CalcWindowRect( &rcWindow, &m_rcTarget, sizeTotal.cx, sizeTotal.cy, m_cxWndOffset, m_cyWndOffset, LOCATE_LEFT, ALIGN_TOP );
  2502. break;
  2503. }
  2504. case CANDUIDIR_LEFTTORIGHT: {
  2505. CalcWindowRect( &rcWindow, &m_rcTarget, sizeTotal.cx, sizeTotal.cy, m_cxWndOffset, m_cyWndOffset, LOCATE_RIGHT, ALIGN_BOTTOM );
  2506. break;
  2507. }
  2508. }
  2509. // rcWindow now include the shadow size. restore to original size
  2510. rcWindow.right = rcWindow.left + sizeWindow.cx;
  2511. rcWindow.bottom = rcWindow.top + sizeWindow.cy;
  2512. Move( rcWindow.left, rcWindow.top, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top );
  2513. // layout window frame
  2514. if (m_pWndFrame != NULL) {
  2515. RECT rc;
  2516. rc.left = 0;
  2517. rc.top = 0;
  2518. rc.right = rcWindow.right - rcWindow.left;
  2519. rc.bottom = rcWindow.bottom - rcWindow.top;
  2520. m_pWndFrame->SetRect( &rc );
  2521. m_pWndFrame->Show( TRUE );
  2522. }
  2523. //
  2524. // misc
  2525. //
  2526. // list/border style
  2527. switch (uidir) {
  2528. default:
  2529. case CANDUIDIR_TOPTOBOTTOM: {
  2530. dwListStyle = UILIST_HORZTB;
  2531. dwBdrStyle = UIBORDER_HORZ;
  2532. break;
  2533. }
  2534. case CANDUIDIR_BOTTOMTOTOP: {
  2535. dwListStyle = UILIST_HORZBT;
  2536. dwBdrStyle = UIBORDER_HORZ;
  2537. break;
  2538. }
  2539. case CANDUIDIR_RIGHTTOLEFT: {
  2540. dwListStyle = UILIST_VERTRL;
  2541. dwBdrStyle = UIBORDER_VERT;
  2542. break;
  2543. }
  2544. case CANDUIDIR_LEFTTORIGHT: {
  2545. dwListStyle = UILIST_VERTLR;
  2546. dwBdrStyle = UIBORDER_VERT;
  2547. break;
  2548. }
  2549. }
  2550. //
  2551. // layout objects
  2552. //
  2553. // caption
  2554. if (m_pCaptionObj != NULL) {
  2555. m_pCaptionObj->SetRect( &rcCaptionObj );
  2556. m_pCaptionObj->Show( fShowCaption );
  2557. m_pCaptionObj->SetText( GetPropertyMgr()->GetWindowCaptionProp()->GetText() );
  2558. }
  2559. // extra candidate list object
  2560. if (m_pExtListUIObj != NULL) {
  2561. m_pExtListUIObj->SetStyle( dwListStyle );
  2562. m_pExtListUIObj->SetLineHeight( sizeMetCandItem.cy );
  2563. m_pExtListUIObj->SetInlineCommentPos( cxInlineCommentPos );
  2564. m_pExtListUIObj->SetRect( &rcExtCandListObj );
  2565. m_pExtListUIObj->Show( fShowExtCandList );
  2566. }
  2567. // extra candidate list border
  2568. pUIObj = FindUIObject( IDUIF_BORDEREXTRACAND );
  2569. if (pUIObj != NULL) {
  2570. pUIObj->SetStyle( dwBdrStyle );
  2571. pUIObj->SetRect( &rcExtCandListBdr );
  2572. pUIObj->Show( fShowExtCandList );
  2573. }
  2574. // candidate menu button
  2575. if (m_pCandMenuBtn != NULL) {
  2576. RECT rc;
  2577. BOOL fExtraSpace = GetPropertyMgr()->GetMenuButtonProp()->IsVisible();
  2578. switch (uidir) {
  2579. default:
  2580. case CANDUIDIR_TOPTOBOTTOM: {
  2581. rc.left = rcCandListObj.right - sizeMetSmButton.cx;
  2582. rc.top = rcCandListObj.bottom - sizeMetSmButton.cy;
  2583. rc.right = rc.left + sizeMetSmButton.cx;
  2584. rc.bottom = rc.top + sizeMetSmButton.cy;
  2585. cxyExtraBottomSpace = (fExtraSpace ? sizeMetSmButton.cy : 0);
  2586. break;
  2587. }
  2588. case CANDUIDIR_BOTTOMTOTOP: {
  2589. rc.left = rcCandListObj.right - sizeMetSmButton.cx;
  2590. rc.top = rcCandListObj.top;
  2591. rc.right = rc.left + sizeMetSmButton.cx;
  2592. rc.bottom = rc.top + sizeMetSmButton.cy;
  2593. cxyExtraTopSpace = (fExtraSpace ? sizeMetSmButton.cy : 0);
  2594. break;
  2595. }
  2596. case CANDUIDIR_RIGHTTOLEFT: {
  2597. rc.left = rcCandListObj.left;
  2598. rc.top = rcCandListObj.bottom - sizeMetSmButton.cy;
  2599. rc.right = rc.left + sizeMetSmButton.cx;
  2600. rc.bottom = rc.top + sizeMetSmButton.cy;
  2601. cxyExtraBottomSpace = (fExtraSpace ? sizeMetSmButton.cx : 0);
  2602. break;
  2603. }
  2604. case CANDUIDIR_LEFTTORIGHT: {
  2605. rc.left = rcCandListObj.right - sizeMetSmButton.cx;
  2606. rc.top = rcCandListObj.bottom - sizeMetSmButton.cy;
  2607. rc.right = rc.left + sizeMetSmButton.cx;
  2608. rc.bottom = rc.top + sizeMetSmButton.cy;
  2609. cxyExtraTopSpace = (fExtraSpace ? sizeMetSmButton.cx : 0);
  2610. break;
  2611. }
  2612. }
  2613. m_pCandMenuBtn->SetRect( &rc );
  2614. m_pCandMenuBtn->Show( GetPropertyMgr()->GetMenuButtonProp()->IsVisible() );
  2615. m_pCandMenuBtn->Enable( GetPropertyMgr()->GetMenuButtonProp()->IsEnabled() );
  2616. m_pCandMenuBtn->SetToolTip( GetPropertyMgr()->GetMenuButtonProp()->GetToolTipString() );
  2617. }
  2618. // layout candidate tip button
  2619. if (m_pCandTipBtn != NULL) {
  2620. RECT rc;
  2621. BOOL fExtraSpace = FALSE;
  2622. if (m_pExtListUIObj && m_pExtListUIObj->IsVisible()) {
  2623. m_pExtListUIObj->GetRect( &rc );
  2624. }
  2625. else {
  2626. rc = rcCandListObj;
  2627. fExtraSpace = fShowCandTip;
  2628. }
  2629. switch (uidir) {
  2630. default:
  2631. case CANDUIDIR_TOPTOBOTTOM: {
  2632. rc.left = rc.right - sizeMetSmButton.cx;
  2633. rc.top = rc.top;
  2634. rc.right = rc.left + sizeMetSmButton.cx;
  2635. rc.bottom = rc.top + sizeMetSmButton.cy;
  2636. cxyExtraTopSpace = (fExtraSpace ? sizeMetSmButton.cy : 0);
  2637. break;
  2638. }
  2639. case CANDUIDIR_BOTTOMTOTOP: {
  2640. rc.left = rc.right - sizeMetSmButton.cx;
  2641. rc.top = rc.bottom - sizeMetSmButton.cy;
  2642. rc.right = rc.left + sizeMetSmButton.cx;
  2643. rc.bottom = rc.top + sizeMetSmButton.cy;
  2644. cxyExtraBottomSpace = (fExtraSpace ? sizeMetSmButton.cy : 0);
  2645. break;
  2646. }
  2647. case CANDUIDIR_RIGHTTOLEFT: {
  2648. rc.left = rc.right - sizeMetSmButton.cx;
  2649. rc.top = rc.bottom - sizeMetSmButton.cy;
  2650. rc.right = rc.left + sizeMetSmButton.cx;
  2651. rc.bottom = rc.top + sizeMetSmButton.cy;
  2652. cxyExtraTopSpace = (fExtraSpace ? sizeMetSmButton.cy : 0);
  2653. break;
  2654. }
  2655. case CANDUIDIR_LEFTTORIGHT: {
  2656. rc.left = rc.left;
  2657. rc.top = rc.bottom - sizeMetSmButton.cy;
  2658. rc.right = rc.left + sizeMetSmButton.cx;
  2659. rc.bottom = rc.top + sizeMetSmButton.cy;
  2660. cxyExtraBottomSpace = (fExtraSpace ? sizeMetSmButton.cy : 0);
  2661. break;
  2662. }
  2663. }
  2664. m_pCandTipBtn->SetRect( &rc );
  2665. m_pCandTipBtn->SetIcon( m_fCandTipWndOpen ? m_hIconCandTipOn : m_hIconCandTipOff );
  2666. m_pCandTipBtn->Show( fShowCandTip );
  2667. m_pCandTipBtn->Enable( TRUE );
  2668. // m_pCandTipBtn->SetToolTip( GetPropertyMgr()->GetMenuButtonProp()->GetToolTipString() );
  2669. }
  2670. // candidate list
  2671. if (m_pListUIObj != NULL) {
  2672. m_pListUIObj->SetStyle( dwListStyle );
  2673. m_pListUIObj->SetLineHeight( sizeMetCandItem.cy );
  2674. m_pListUIObj->SetInlineCommentPos( cxInlineCommentPos );
  2675. m_pListUIObj->SetRect( &rcCandListObj );
  2676. m_pListUIObj->SetExtraTopSpace( cxyExtraTopSpace );
  2677. m_pListUIObj->SetExtraBottomSpace( cxyExtraBottomSpace );
  2678. }
  2679. // rawdata object
  2680. if (m_pCandRawData != NULL) {
  2681. DWORD dwStyle;
  2682. RECT rc;
  2683. rc = rcRawDataObj;
  2684. switch (uidir) {
  2685. default:
  2686. case CANDUIDIR_TOPTOBOTTOM: {
  2687. dwStyle = UICANDRAWDATA_HORZTB;
  2688. InflateRect( &rc, -1, 0 );
  2689. break;
  2690. }
  2691. case CANDUIDIR_BOTTOMTOTOP: {
  2692. dwStyle = UICANDRAWDATA_HORZBT;
  2693. InflateRect( &rc, -1, 0 );
  2694. break;
  2695. }
  2696. case CANDUIDIR_RIGHTTOLEFT: {
  2697. dwStyle = UICANDRAWDATA_VERTRL;
  2698. InflateRect( &rc, 0, -1 );
  2699. break;
  2700. }
  2701. case CANDUIDIR_LEFTTORIGHT: {
  2702. dwStyle = UICANDRAWDATA_VERTLR;
  2703. InflateRect( &rc, 0, -1 );
  2704. break;
  2705. }
  2706. }
  2707. m_pCandRawData->SetStyle( dwStyle );
  2708. m_pCandRawData->SetRect( &rc );
  2709. m_pCandRawData->Show( m_fHasRawData );
  2710. }
  2711. // rawdata border
  2712. pUIObj = FindUIObject( IDUIF_BORDERRAWDATA );
  2713. if (pUIObj != NULL) {
  2714. pUIObj->SetStyle( dwBdrStyle );
  2715. pUIObj->SetRect( &rcRawDataBdr );
  2716. pUIObj->Show( m_fHasRawData );
  2717. }
  2718. // options candidate list border
  2719. pUIObj = FindUIObject( IDUIF_BORDEROPTIONSCAND );
  2720. if (pUIObj != NULL) {
  2721. pUIObj->SetStyle( dwBdrStyle );
  2722. pUIObj->SetRect( &rcOptionsListBdr );
  2723. pUIObj->Show( fShowOptionsCandList );
  2724. }
  2725. // options candidate list
  2726. if (m_pOptionsListUIObj != NULL) {
  2727. m_pOptionsListUIObj->SetStyle( dwListStyle | UILIST_ICONSNOTNUMBERS );
  2728. m_pOptionsListUIObj->SetLineHeight( sizeMetCandItem.cy );
  2729. m_pOptionsListUIObj->SetInlineCommentPos( cxInlineCommentPos );
  2730. m_pOptionsListUIObj->SetRect( &rcOptionsListObj );
  2731. m_pOptionsListUIObj->SetExtraTopSpace( cxyExtraTopSpace );
  2732. m_pOptionsListUIObj->SetExtraBottomSpace( cxyExtraBottomSpace );
  2733. }
  2734. // extension area border
  2735. pUIObj = FindUIObject( IDUIF_BORDERBOTTOM );
  2736. if (pUIObj != NULL) {
  2737. RECT rc;
  2738. rc.left = rcExtensionArea.left;
  2739. rc.top = rcExtensionArea.top;
  2740. rc.right = rcExtensionArea.right;
  2741. rc.bottom = rc.top + sizeMetBorder.cy;
  2742. pUIObj->SetRect( &rc );
  2743. pUIObj->Show( fHasExtension );
  2744. }
  2745. // extension objects
  2746. if (fHasExtension) {
  2747. SIZE size;
  2748. LONG nExtension;
  2749. LONG iExtension;
  2750. POINT pt;
  2751. RECT rc;
  2752. pt.x = rcExtensionArea.left + 1;
  2753. pt.y = rcExtensionArea.top + sizeMetBorder.cy;
  2754. nExtension = GetExtensionMgr()->GetExtensionNum();
  2755. for (iExtension = 0; iExtension < nExtension; iExtension++) {
  2756. CCandUIExtension *pExtension = GetExtensionMgr()->GetExtension( iExtension );
  2757. CUIFObject *pUIObjExt;
  2758. pExtension->GetSize( &size );
  2759. rc.left = pt.x;
  2760. rc.top = pt.y;
  2761. rc.right = rc.left + size.cx;
  2762. rc.bottom = rc.top + size.cy;
  2763. pUIObjExt = FindUIObject( IDUIF_EXTENDED + iExtension );
  2764. if (pUIObjExt != NULL) {
  2765. pUIObjExt->SetRect( &rc );
  2766. }
  2767. pt.x += size.cx;
  2768. }
  2769. }
  2770. #ifdef NEVER
  2771. // layout candidate num buttons and border
  2772. if (fShowNumber) {
  2773. RECT rc;
  2774. DWORD dwStyle;
  2775. // buttons
  2776. for (i = 0; i < NUM_CANDSTR_MAX; i++) {
  2777. switch (uidir) {
  2778. default:
  2779. case CANDUIDIR_TOPTOBOTTOM:
  2780. case CANDUIDIR_BOTTOMTOTOP: { /* NOTE: KOJIW: unconfirmed */
  2781. rc.left = rcCandListArea.left;
  2782. rc.top = rcCandListArea.top + sizeMetCandNum.cy * i;
  2783. rc.right = rc.left + sizeMetCandNum.cx;
  2784. rc.bottom = rc.top + sizeMetCandNum.cy;
  2785. break;
  2786. }
  2787. case CANDUIDIR_RIGHTTOLEFT:
  2788. case CANDUIDIR_LEFTTORIGHT: { /* NOTE: KOJIW: unconfirmed */
  2789. rc.left = rcCandListArea.right - sizeMetCandNum.cy * (i+1);
  2790. rc.top = rcCandListArea.top;
  2791. rc.right = rc.left + sizeMetCandNum.cx;
  2792. rc.bottom = rc.top + sizeMetCandNum.cy;
  2793. break;
  2794. }
  2795. }
  2796. pUIObj = FindUIObject( IDUIF_CANDNUMBUTTON + i );
  2797. if (pUIObj != NULL) {
  2798. pUIObj->Show( (i < m_nItemShow) );
  2799. pUIObj->SetRect( &rc );
  2800. }
  2801. }
  2802. // border
  2803. switch (uidir) {
  2804. default:
  2805. case CANDUIDIR_TOPTOBOTTOM:
  2806. case CANDUIDIR_BOTTOMTOTOP: { /* NOTE: KOJIW: unconfirmed */
  2807. rc.left = rcCandListArea.left + sizeMetCandNum.cx + sizeMetMargin.cx;
  2808. rc.top = rcCandListArea.top;
  2809. rc.right = rc.left + sizeMetBorder.cx;
  2810. rc.bottom = rcCandListArea.bottom;
  2811. dwStyle = UIBORDER_VERT;
  2812. break;
  2813. }
  2814. case CANDUIDIR_RIGHTTOLEFT:
  2815. case CANDUIDIR_LEFTTORIGHT: { /* NOTE: KOJIW: unconfirmed */
  2816. rc.left = rcCandListArea.left;
  2817. rc.top = rcCandListArea.top + sizeMetCandNum.cy + sizeMetMargin.cy;
  2818. rc.right = rcCandListArea.right;
  2819. rc.bottom = rc.top + sizeMetBorder.cy;
  2820. dwStyle = UIBORDER_HORZ;
  2821. break;
  2822. }
  2823. }
  2824. pUIObj = FindUIObject( IDUIF_BORDERLEFT );
  2825. if (pUIObj != NULL) {
  2826. pUIObj->Show( TRUE );
  2827. pUIObj->SetStyle( dwStyle );
  2828. pUIObj->SetRect( &rc );
  2829. }
  2830. }
  2831. else {
  2832. // buttons
  2833. for (i = 0; i < NUM_CANDSTR_MAX; i++) {
  2834. pUIObj = FindUIObject( IDUIF_CANDNUMBUTTON + i );
  2835. if (pUIObj != NULL) {
  2836. pUIObj->Show( FALSE );
  2837. }
  2838. }
  2839. // border
  2840. pUIObj = FindUIObject( IDUIF_BORDERLEFT );
  2841. if (pUIObj != NULL) {
  2842. pUIObj->Show( FALSE );
  2843. }
  2844. }
  2845. #endif
  2846. //
  2847. // Notify UI object update
  2848. //
  2849. NotifyUIObjectEvent( CANDUIOBJ_OPTIONSLISTBOX, CANDUIOBJEV_UPDATED );
  2850. NotifyUIObjectEvent( CANDUIOBJ_CANDLISTBOX, CANDUIOBJEV_UPDATED );
  2851. NotifyUIObjectEvent( CANDUIOBJ_CANDCAPTION, CANDUIOBJEV_UPDATED );
  2852. NotifyUIObjectEvent( CANDUIOBJ_MENUBUTTON, CANDUIOBJEV_UPDATED );
  2853. NotifyUIObjectEvent( CANDUIOBJ_EXTRACANDIDATE, CANDUIOBJEV_UPDATED );
  2854. NotifyUIObjectEvent( CANDUIOBJ_CANDRAWDATA, CANDUIOBJEV_UPDATED );
  2855. NotifyUIObjectEvent( CANDUIOBJ_CANDTIPBUTTON, CANDUIOBJEV_UPDATED );
  2856. //
  2857. if (m_pCandTipWnd != NULL) {
  2858. MoveCandTipWindow();
  2859. }
  2860. ReleaseDC( m_hWnd, hDC );
  2861. }
  2862. /* S E L E C T I T E M N E X T */
  2863. /*------------------------------------------------------------------------------
  2864. ------------------------------------------------------------------------------*/
  2865. void CCandWindow::SelectItemNext( void )
  2866. {
  2867. int iCurSel = m_pListUIObj->GetSelection();
  2868. int iVisTop = m_pListUIObj->GetTop();
  2869. int iVisBtm = m_pListUIObj->GetBottom();
  2870. int iSelMax = m_pListUIObj->GetCount() - 1;
  2871. int iSelNew = iCurSel + 1;
  2872. if (iSelMax < iSelNew) {
  2873. ScrollToTop();
  2874. iSelNew = 0;
  2875. }
  2876. else if (iVisBtm < iSelNew) {
  2877. ScrollPageNext();
  2878. }
  2879. SelectItemProc( iSelNew );
  2880. }
  2881. /* S E L E C T I T E M P R E V */
  2882. /*------------------------------------------------------------------------------
  2883. ------------------------------------------------------------------------------*/
  2884. void CCandWindow::SelectItemPrev( void )
  2885. {
  2886. int iCurSel = m_pListUIObj->GetSelection();
  2887. int iVisTop = m_pListUIObj->GetTop();
  2888. int iVisBtm = m_pListUIObj->GetBottom();
  2889. int iSelMax = m_pListUIObj->GetItemCount() - 1;
  2890. int iSelNew = iCurSel - 1;
  2891. if (iSelNew < 0) {
  2892. ScrollToEnd();
  2893. iSelNew = iSelMax;
  2894. }
  2895. else if (iSelNew < iVisTop) {
  2896. ScrollPagePrev();
  2897. }
  2898. SelectItemProc( iSelNew );
  2899. }
  2900. /* S E L E C T P A G E N E X T */
  2901. /*------------------------------------------------------------------------------
  2902. ------------------------------------------------------------------------------*/
  2903. void CCandWindow::SelectPageNext( void )
  2904. {
  2905. int iCurSel = m_pListUIObj->GetSelection();
  2906. int iVisTop = m_pListUIObj->GetTop();
  2907. int iVisBtm = m_pListUIObj->GetBottom();
  2908. int iSelMax = m_pListUIObj->GetItemCount() - 1;
  2909. int iItemPage = m_pListUIObj->GetVisibleCount();
  2910. if (iCurSel == iSelMax) {
  2911. SelectItemTop();
  2912. }
  2913. else {
  2914. int iSelNew;
  2915. if (iCurSel == iVisBtm) {
  2916. iSelNew = min( iCurSel + iItemPage, iSelMax );
  2917. }
  2918. else {
  2919. iSelNew = iVisBtm;
  2920. }
  2921. SelectItemProc( iSelNew );
  2922. }
  2923. }
  2924. /* S E L E C T P A G E P R E V */
  2925. /*------------------------------------------------------------------------------
  2926. ------------------------------------------------------------------------------*/
  2927. void CCandWindow::SelectPagePrev( void )
  2928. {
  2929. int iCurSel = m_pListUIObj->GetSelection();
  2930. int iVisTop = m_pListUIObj->GetTop();
  2931. int iVisBtm = m_pListUIObj->GetBottom();
  2932. int iSelMax = m_pListUIObj->GetItemCount() - 1;
  2933. int iItemPage = m_pListUIObj->GetVisibleCount();
  2934. if (iCurSel == 0) {
  2935. SelectItemEnd();
  2936. }
  2937. else {
  2938. int iSelNew;
  2939. if (iCurSel == iVisTop) {
  2940. iSelNew = max( 0, iCurSel - iItemPage );
  2941. }
  2942. else {
  2943. iSelNew = iVisTop;
  2944. }
  2945. SelectItemProc( iSelNew );
  2946. }
  2947. }
  2948. /* M A P C O M M A N D */
  2949. /*------------------------------------------------------------------------------
  2950. Map directional command to undirectional command
  2951. (CUIFWindowBase method)
  2952. ------------------------------------------------------------------------------*/
  2953. CANDUICOMMAND CCandWindow::MapCommand( CANDUICOMMAND cmd )
  2954. {
  2955. CANDUIUIDIRECTION uidir = GetPropertyMgr()->GetCandWindowProp()->GetUIDirection();
  2956. switch (cmd) {
  2957. case CANDUICMD_MOVESELUP: {
  2958. switch (uidir) {
  2959. default:
  2960. case CANDUIDIR_TOPTOBOTTOM: {
  2961. cmd = CANDUICMD_MOVESELPREV;
  2962. break;
  2963. }
  2964. case CANDUIDIR_BOTTOMTOTOP: {
  2965. cmd = CANDUICMD_MOVESELNEXT;
  2966. break;
  2967. }
  2968. case CANDUIDIR_RIGHTTOLEFT:
  2969. case CANDUIDIR_LEFTTORIGHT: {
  2970. cmd = CANDUICMD_NONE;
  2971. break;
  2972. }
  2973. }
  2974. break;
  2975. }
  2976. case CANDUICMD_MOVESELDOWN: {
  2977. switch (uidir) {
  2978. default:
  2979. case CANDUIDIR_TOPTOBOTTOM: {
  2980. cmd = CANDUICMD_MOVESELNEXT;
  2981. break;
  2982. }
  2983. case CANDUIDIR_BOTTOMTOTOP: {
  2984. cmd = CANDUICMD_MOVESELPREV;
  2985. break;
  2986. }
  2987. case CANDUIDIR_RIGHTTOLEFT:
  2988. case CANDUIDIR_LEFTTORIGHT: {
  2989. cmd = CANDUICMD_NONE;
  2990. break;
  2991. }
  2992. }
  2993. break;
  2994. }
  2995. case CANDUICMD_MOVESELLEFT: {
  2996. switch (uidir) {
  2997. default:
  2998. case CANDUIDIR_TOPTOBOTTOM:
  2999. case CANDUIDIR_BOTTOMTOTOP: {
  3000. cmd = CANDUICMD_NONE;
  3001. break;
  3002. }
  3003. case CANDUIDIR_RIGHTTOLEFT: {
  3004. cmd = CANDUICMD_MOVESELNEXT;
  3005. break;
  3006. }
  3007. case CANDUIDIR_LEFTTORIGHT: {
  3008. cmd = CANDUICMD_MOVESELPREV;
  3009. break;
  3010. }
  3011. }
  3012. break;
  3013. }
  3014. case CANDUICMD_MOVESELRIGHT: {
  3015. switch (uidir) {
  3016. default:
  3017. case CANDUIDIR_TOPTOBOTTOM:
  3018. case CANDUIDIR_BOTTOMTOTOP: {
  3019. cmd = CANDUICMD_NONE;
  3020. break;
  3021. }
  3022. case CANDUIDIR_RIGHTTOLEFT: {
  3023. cmd = CANDUICMD_MOVESELPREV;
  3024. break;
  3025. }
  3026. case CANDUIDIR_LEFTTORIGHT: {
  3027. cmd = CANDUICMD_MOVESELNEXT;
  3028. break;
  3029. }
  3030. }
  3031. break;
  3032. }
  3033. }
  3034. return cmd;
  3035. }
  3036. /* U P D A T E A L L W I N D O W */
  3037. /*------------------------------------------------------------------------------
  3038. ------------------------------------------------------------------------------*/
  3039. void CCandWindow::UpdateAllWindow( void )
  3040. {
  3041. CCandWindowBase::UpdateAllWindow();
  3042. if (m_pCommentWnd != NULL) {
  3043. m_pCommentWnd->UpdateWindow();
  3044. }
  3045. }
  3046. /* G E T C A N D W I N D O W O B J */
  3047. /*------------------------------------------------------------------------------
  3048. (CCandUIObjectParent method)
  3049. ------------------------------------------------------------------------------*/
  3050. CCandWindowBase *CCandWindow::GetCandWindowObj( void )
  3051. {
  3052. return this;
  3053. }
  3054. /* G E T P O P U P C O M M E N T W I N D O W O B J */
  3055. /*------------------------------------------------------------------------------
  3056. (CCandUIObjectParent method)
  3057. ------------------------------------------------------------------------------*/
  3058. CPopupCommentWindow *CCandWindow::GetPopupCommentWindowObj( void )
  3059. {
  3060. return m_pCommentWnd;
  3061. }
  3062. /* G E T O P T I O N S L I S T B O X O B J */
  3063. /*------------------------------------------------------------------------------
  3064. (CCandUIObjectParent method)
  3065. ------------------------------------------------------------------------------*/
  3066. CUIFCandListBase *CCandWindow::GetOptionsListBoxObj( void )
  3067. {
  3068. return m_pOptionsListUIObj;
  3069. }
  3070. /* G E T C A N D L I S T B O X O B J */
  3071. /*------------------------------------------------------------------------------
  3072. (CCandUIObjectParent method)
  3073. ------------------------------------------------------------------------------*/
  3074. CUIFCandListBase *CCandWindow::GetCandListBoxObj( void )
  3075. {
  3076. return m_pListUIObj;
  3077. }
  3078. /* G E T C A P T I O N O B J */
  3079. /*------------------------------------------------------------------------------
  3080. (CCandUIObjectParent method)
  3081. ------------------------------------------------------------------------------*/
  3082. CUIFWndCaption *CCandWindow::GetCaptionObj( void )
  3083. {
  3084. return m_pCaptionObj;
  3085. }
  3086. /* G E T M E N U B U T T O N O B J */
  3087. /*------------------------------------------------------------------------------
  3088. (CCandUIObjectParent method)
  3089. ------------------------------------------------------------------------------*/
  3090. CUIFButton *CCandWindow::GetMenuButtonObj( void )
  3091. {
  3092. return m_pCandMenuBtn;
  3093. }
  3094. /* G E T E X T R A C A N D I D A T E O B J */
  3095. /*------------------------------------------------------------------------------
  3096. (CCandUIObjectParent method)
  3097. ------------------------------------------------------------------------------*/
  3098. CUIFCandListBase *CCandWindow::GetExtraCandidateObj( void )
  3099. {
  3100. return m_pExtListUIObj;
  3101. }
  3102. /* G E T C A N D R A W D A T A O B J */
  3103. /*------------------------------------------------------------------------------
  3104. (CCandUIObjectParent method)
  3105. ------------------------------------------------------------------------------*/
  3106. CUIFCandRawData *CCandWindow::GetCandRawDataObj( void )
  3107. {
  3108. return m_pCandRawData;
  3109. }
  3110. /* G E T C A N D T I P W I N D O W O B J */
  3111. /*------------------------------------------------------------------------------
  3112. (CCandUIObjectParent method)
  3113. ------------------------------------------------------------------------------*/
  3114. CUIFBalloonWindow *CCandWindow::GetCandTipWindowObj( void )
  3115. {
  3116. return m_pCandTipWnd;
  3117. }
  3118. /* G E T C A N D T I P B U T T O N O B J */
  3119. /*------------------------------------------------------------------------------
  3120. (CCandUIObjectParent method)
  3121. ------------------------------------------------------------------------------*/
  3122. CUIFButton *CCandWindow::GetCandTipButtonObj( void )
  3123. {
  3124. return m_pCandTipBtn;
  3125. }
  3126. /* S C R O L L P A G E N E X T */
  3127. /*------------------------------------------------------------------------------
  3128. ------------------------------------------------------------------------------*/
  3129. void CCandWindow::ScrollPageNext( void )
  3130. {
  3131. int iCurSel = m_pListUIObj->GetSelection();
  3132. int iVisTop = m_pListUIObj->GetTop();
  3133. int iVisBtm = m_pListUIObj->GetBottom();
  3134. int iSelMax = m_pListUIObj->GetItemCount() - 1;
  3135. int iItemPage = m_pListUIObj->GetVisibleCount();
  3136. int iTopNew = iVisTop + iItemPage;
  3137. if (iSelMax - iItemPage < iTopNew) {
  3138. ScrollToEnd();
  3139. }
  3140. else {
  3141. m_pListUIObj->SetTop( iTopNew, TRUE );
  3142. }
  3143. }
  3144. /* S C R O L L P A G E P R E V */
  3145. /*------------------------------------------------------------------------------
  3146. ------------------------------------------------------------------------------*/
  3147. void CCandWindow::ScrollPagePrev( void )
  3148. {
  3149. int iCurSel = m_pListUIObj->GetSelection();
  3150. int iVisTop = m_pListUIObj->GetTop();
  3151. int iVisBtm = m_pListUIObj->GetBottom();
  3152. int iSelMax = m_pListUIObj->GetItemCount() - 1;
  3153. int iItemPage = m_pListUIObj->GetVisibleCount();
  3154. int iTopNew = iVisTop - iItemPage;
  3155. if (iTopNew < 0) {
  3156. ScrollToTop();
  3157. }
  3158. else {
  3159. m_pListUIObj->SetTop( iTopNew, TRUE );
  3160. }
  3161. }
  3162. /* S C R O L L T O T O P */
  3163. /*------------------------------------------------------------------------------
  3164. ------------------------------------------------------------------------------*/
  3165. void CCandWindow::ScrollToTop( void )
  3166. {
  3167. m_pListUIObj->SetTop( 0, TRUE );
  3168. }
  3169. /* S C R O L L T O E N D */
  3170. /*------------------------------------------------------------------------------
  3171. ------------------------------------------------------------------------------*/
  3172. void CCandWindow::ScrollToEnd( void )
  3173. {
  3174. int iSelMax = m_pListUIObj->GetItemCount() - 1;
  3175. int iItemPage = m_pListUIObj->GetVisibleCount();
  3176. m_pListUIObj->SetTop( iSelMax - iItemPage + 1, TRUE );
  3177. }
  3178. /* O N C O M M E N T W I N D O W M O V E D */
  3179. /*------------------------------------------------------------------------------
  3180. ------------------------------------------------------------------------------*/
  3181. void CCandWindow::OnCommentWindowMoved( void )
  3182. {
  3183. NotifyUIObjectEvent( CANDUIOBJ_POPUPCOMMENTWINDOW, CANDUIOBJEV_UPDATED );
  3184. }
  3185. /* O N C O M M E N T S E L E C T E D */
  3186. /*------------------------------------------------------------------------------
  3187. ------------------------------------------------------------------------------*/
  3188. void CCandWindow::OnCommentSelected( int iCandItem )
  3189. {
  3190. m_pCandUI->NotifyCompleteCand( iCandItem );
  3191. }
  3192. /* O N C O M M E N T C L O S E */
  3193. /*------------------------------------------------------------------------------
  3194. ------------------------------------------------------------------------------*/
  3195. void CCandWindow::OnCommentClose( void )
  3196. {
  3197. CloseCommentWindow();
  3198. }
  3199. /* O N M E N U O P E N E D */
  3200. /*------------------------------------------------------------------------------
  3201. ------------------------------------------------------------------------------*/
  3202. void CCandWindow::OnMenuOpened( void )
  3203. {
  3204. if (m_pCommentWnd != NULL) {
  3205. m_pCommentWnd->OnCandWindowMove( FALSE );
  3206. }
  3207. }
  3208. /* O N M E N U C L O S E D */
  3209. /*------------------------------------------------------------------------------
  3210. ------------------------------------------------------------------------------*/
  3211. void CCandWindow::OnMenuClosed( void )
  3212. {
  3213. if (m_pCommentWnd != NULL) {
  3214. m_pCommentWnd->OnCandWindowMove( FALSE );
  3215. }
  3216. }
  3217. /* S E T C A N D I D A T E L I S T P R O C */
  3218. /*------------------------------------------------------------------------------
  3219. Set candidate list
  3220. ------------------------------------------------------------------------------*/
  3221. void CCandWindow::SetCandidateListProc( void )
  3222. {
  3223. CCandidateList *pCandList;
  3224. CCandidateItem *pCandItem;
  3225. pCandList = GetCandListMgr()->GetCandList();
  3226. Assert( pCandList != NULL );
  3227. // reset list item
  3228. if (m_pExtListUIObj) {
  3229. m_pExtListUIObj->DelAllCandItem();
  3230. pCandItem = pCandList->GetExtraCandItem();
  3231. if (pCandItem != NULL) {
  3232. if (pCandItem->IsVisible()) {
  3233. CCandListItem *pCandListItem = new CCandListItem( m_pExtListUIObj->GetItemCount(), ICANDITEM_EXTRA, pCandItem );
  3234. m_pExtListUIObj->AddCandItem( pCandListItem );
  3235. }
  3236. m_pExtListUIObj->ClearSelection( FALSE );
  3237. m_pExtListUIObj->SetStartIndex( 0 );
  3238. }
  3239. }
  3240. CCandWindowBase::SetCandidateListProc();
  3241. }
  3242. /* C L E A R C A N D I D A T E L I S T P R O C */
  3243. /*------------------------------------------------------------------------------
  3244. Clear candidte list
  3245. ------------------------------------------------------------------------------*/
  3246. void CCandWindow::ClearCandidateListProc( void )
  3247. {
  3248. if (m_pExtListUIObj) {
  3249. m_pExtListUIObj->DelAllCandItem();
  3250. }
  3251. CCandWindowBase::ClearCandidateListProc();
  3252. }
  3253. /* S E T A T T E N S I O N */
  3254. /*------------------------------------------------------------------------------
  3255. ------------------------------------------------------------------------------*/
  3256. void CCandWindow::SetAttensionBySelect( int iItem )
  3257. {
  3258. CCandidateList *pCandList;
  3259. CCandidateItem *pCandItem;
  3260. BOOL fHasPopupComment;
  3261. // Satori#3928
  3262. // do nothing when candidate list is already cleared
  3263. if (GetCandListMgr()->GetCandList() == NULL) {
  3264. m_iItemAttensionSelect = -1;
  3265. m_iItemAttensionHover = -1;
  3266. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_SELECT );
  3267. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_HOVER );
  3268. return;
  3269. }
  3270. m_iItemAttensionSelect = iItem;
  3271. // check if item has popup comment
  3272. pCandList = GetCandListMgr()->GetCandList();
  3273. Assert( pCandList != NULL );
  3274. pCandItem = pCandList->GetCandidateItem( m_iItemAttensionSelect );
  3275. fHasPopupComment = (pCandItem != NULL && pCandItem->GetPopupComment() != NULL);
  3276. //
  3277. if (m_fCommentWndOpen) {
  3278. if (fHasPopupComment) {
  3279. // update comment window contents
  3280. SetCommentStatus( iItem );
  3281. }
  3282. else {
  3283. // close comment window
  3284. CloseCommentWindow();
  3285. }
  3286. }
  3287. else {
  3288. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_SELECT );
  3289. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_HOVER );
  3290. // make timer to wait to open comment
  3291. if (fHasPopupComment) {
  3292. if (IsWindow(m_hWnd)) {
  3293. SetTimer( m_hWnd, IDTIMER_POPUPCOMMENT_SELECT, GetPropertyMgr()->GetPopupCommentWindowProp()->GetDelayTime(), NULL );
  3294. }
  3295. }
  3296. }
  3297. }
  3298. /* S E T A T T E N S I O N */
  3299. /*------------------------------------------------------------------------------
  3300. ------------------------------------------------------------------------------*/
  3301. void CCandWindow::SetOptionsAttensionByHover( int iItem )
  3302. {
  3303. CCandidateList *pCandList;
  3304. CCandidateItem *pCandItem;
  3305. BOOL fHasPopupComment;
  3306. // Satori#3928
  3307. // do nothing when candidate list is already cleared
  3308. if (GetCandListMgr()->GetOptionsList() == NULL) {
  3309. m_iItemAttensionSelect = -1;
  3310. m_iItemAttensionHover = -1;
  3311. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_SELECT );
  3312. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_HOVER );
  3313. return;
  3314. }
  3315. m_iItemAttensionHover = iItem;
  3316. // check if item has popup comment
  3317. pCandList = GetCandListMgr()->GetOptionsList();
  3318. Assert( pCandList != NULL );
  3319. pCandItem = pCandList->GetCandidateItem( m_iItemAttensionHover );
  3320. fHasPopupComment = (pCandItem != NULL && pCandItem->GetPopupComment() != NULL);
  3321. //
  3322. if (m_fCommentWndOpen) {
  3323. if (fHasPopupComment) {
  3324. // update comment window contents
  3325. SetCommentStatus( iItem );
  3326. }
  3327. }
  3328. else {
  3329. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_HOVER );
  3330. // make timer to wait to open comment
  3331. if (fHasPopupComment) {
  3332. if (IsWindow(m_hWnd)) {
  3333. SetTimer( m_hWnd, IDTIMER_POPUPCOMMENT_HOVER, GetPropertyMgr()->GetPopupCommentWindowProp()->GetDelayTime(), NULL );
  3334. }
  3335. }
  3336. }
  3337. if (iItem != -1)
  3338. {
  3339. SetTimer(m_hWnd, IDTIMER_MENU_HOVER, 50, NULL);
  3340. }
  3341. else
  3342. {
  3343. KillTimer( m_hWnd, IDTIMER_MENU_HOVER);
  3344. }
  3345. GetUIOptionsListObj()->SetCurSel(iItem);
  3346. }
  3347. /* S E T A T T E N S I O N */
  3348. /*------------------------------------------------------------------------------
  3349. ------------------------------------------------------------------------------*/
  3350. void CCandWindow::SetAttensionByHover( int iItem )
  3351. {
  3352. CCandidateList *pCandList;
  3353. CCandidateItem *pCandItem;
  3354. BOOL fHasPopupComment;
  3355. // Satori#3928
  3356. // do nothing when candidate list is already cleared
  3357. if (GetCandListMgr()->GetCandList() == NULL) {
  3358. m_iItemAttensionSelect = -1;
  3359. m_iItemAttensionHover = -1;
  3360. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_SELECT );
  3361. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_HOVER );
  3362. return;
  3363. }
  3364. m_iItemAttensionHover = iItem;
  3365. // check if item has popup comment
  3366. pCandList = GetCandListMgr()->GetCandList();
  3367. Assert( pCandList != NULL );
  3368. pCandItem = pCandList->GetCandidateItem( m_iItemAttensionHover );
  3369. fHasPopupComment = (pCandItem != NULL && pCandItem->GetPopupComment() != NULL);
  3370. //
  3371. if (m_fCommentWndOpen) {
  3372. if (fHasPopupComment) {
  3373. // update comment window contents
  3374. SetCommentStatus( iItem );
  3375. }
  3376. }
  3377. else {
  3378. KillTimer( m_hWnd, IDTIMER_POPUPCOMMENT_HOVER );
  3379. // make timer to wait to open comment
  3380. if (fHasPopupComment) {
  3381. if (IsWindow(m_hWnd)) {
  3382. SetTimer( m_hWnd, IDTIMER_POPUPCOMMENT_HOVER, GetPropertyMgr()->GetPopupCommentWindowProp()->GetDelayTime(), NULL );
  3383. }
  3384. }
  3385. }
  3386. }
  3387. /* O P E N C O M M E N T W I N D O W */
  3388. /*------------------------------------------------------------------------------
  3389. ------------------------------------------------------------------------------*/
  3390. void CCandWindow::OpenCommentWindow( int iItem )
  3391. {
  3392. if (m_pCommentWnd->GetWnd() == NULL) {
  3393. Assert( !m_fCommentWndOpen );
  3394. // create comment window
  3395. m_pCommentWnd->CreateWnd( m_hWnd );
  3396. m_pCommentWnd->Move( 0, 0, CX_COMMENTWINDOW, 0 );
  3397. m_pCommentWnd->OnCandWindowMove( TRUE );
  3398. NotifyUIObjectEvent( CANDUIOBJ_POPUPCOMMENTWINDOW, CANDUIOBJEV_CREATED );
  3399. }
  3400. SetCommentStatus( iItem );
  3401. if (!m_fCommentWndOpen) {
  3402. m_pCommentWnd->Show( TRUE );
  3403. m_fCommentWndOpen = TRUE;
  3404. }
  3405. }
  3406. /* C L O S E C O M M E N T W I N D O W */
  3407. /*------------------------------------------------------------------------------
  3408. ------------------------------------------------------------------------------*/
  3409. void CCandWindow::CloseCommentWindow( void )
  3410. {
  3411. if (m_fCommentWndOpen) {
  3412. Assert( m_pCommentWnd->GetWnd() != NULL );
  3413. m_pCommentWnd->Show( FALSE );
  3414. ClearCommentStatus();
  3415. }
  3416. m_fCommentWndOpen = FALSE;
  3417. if (m_pCommentWnd->GetWnd() != NULL) {
  3418. m_pCommentWnd->DestroyWnd();
  3419. NotifyUIObjectEvent( CANDUIOBJ_POPUPCOMMENTWINDOW, CANDUIOBJEV_DESTROYED );
  3420. }
  3421. }
  3422. /* S E T C O M M E N T S T A T U S */
  3423. /*------------------------------------------------------------------------------
  3424. ------------------------------------------------------------------------------*/
  3425. void CCandWindow::SetCommentStatus( int iItem )
  3426. {
  3427. CCandidateList *pCandList;
  3428. CCandidateItem *pCandItem;
  3429. int i;
  3430. int nItem;
  3431. DWORD dwGroupID = 0;
  3432. // get comment group id
  3433. pCandList = GetCandListMgr()->GetCandList();
  3434. Assert( pCandList != NULL );
  3435. pCandItem = pCandList->GetCandidateItem( iItem );
  3436. if (pCandItem == NULL) {
  3437. Assert( FALSE );
  3438. ClearCommentStatus();
  3439. }
  3440. else {
  3441. dwGroupID = pCandItem->GetPopupCommentGroupID();
  3442. }
  3443. // show popup comment in same group
  3444. nItem = pCandList->GetItemCount();
  3445. for (i = 0; i < nItem; i++) {
  3446. pCandItem = pCandList->GetCandidateItem( i );
  3447. if (pCandItem != NULL) {
  3448. BOOL fMatch = ((pCandItem->GetPopupCommentGroupID() & dwGroupID) != 0);
  3449. pCandItem->SetPopupCommentState( fMatch );
  3450. }
  3451. }
  3452. // repaint list box and notify
  3453. if (m_pListUIObj != NULL) {
  3454. m_pListUIObj->CallOnPaint();
  3455. UpdateWindow();
  3456. }
  3457. GetCandListMgr()->NotifyCandItemUpdate( this );
  3458. }
  3459. /* C L E A R C O M M E N T S T A T U S */
  3460. /*------------------------------------------------------------------------------
  3461. ------------------------------------------------------------------------------*/
  3462. void CCandWindow::ClearCommentStatus( void )
  3463. {
  3464. CCandidateList *pCandList;
  3465. CCandidateItem *pCandItem;
  3466. int i;
  3467. int nItem;
  3468. pCandList = GetCandListMgr()->GetCandList();
  3469. Assert( pCandList != NULL );
  3470. // hide all popup comment
  3471. nItem = pCandList->GetItemCount();
  3472. for (i = 0; i < nItem; i++) {
  3473. pCandItem = pCandList->GetCandidateItem( i );
  3474. if (pCandItem != NULL) {
  3475. pCandItem->SetPopupCommentState( FALSE );
  3476. }
  3477. }
  3478. // repaint list box and notify
  3479. if (m_pListUIObj != NULL) {
  3480. m_pListUIObj->CallOnPaint();
  3481. UpdateWindow();
  3482. }
  3483. GetCandListMgr()->NotifyCandItemUpdate( this );
  3484. }
  3485. /* O P E N C A N D T I P W I N D O W */
  3486. /*------------------------------------------------------------------------------
  3487. ------------------------------------------------------------------------------*/
  3488. void CCandWindow::OpenCandTipWindow( void )
  3489. {
  3490. if (GetCandListMgr()->GetCandList() == NULL) {
  3491. return;
  3492. }
  3493. if (m_pCandTipWnd->GetWnd() == NULL) {
  3494. m_pCandTipWnd->CreateWnd( m_hWnd );
  3495. NotifyUIObjectEvent( CANDUIOBJ_CANDTIPWINDOW, CANDUIOBJEV_CREATED );
  3496. }
  3497. m_pCandTipWnd->SetText( GetCandListMgr()->GetCandList()->GetTipString() );
  3498. ShowCandTipWindow( TRUE );
  3499. //
  3500. if (m_pCommentWnd != NULL) {
  3501. m_pCommentWnd->OnCandWindowMove( FALSE );
  3502. }
  3503. }
  3504. /* C L O S E C A N D T I P W I N D O W */
  3505. /*------------------------------------------------------------------------------
  3506. ------------------------------------------------------------------------------*/
  3507. void CCandWindow::CloseCandTipWindow( void )
  3508. {
  3509. if (m_pCandTipWnd->GetWnd() != NULL) {
  3510. DestroyWindow( m_pCandTipWnd->GetWnd() );
  3511. NotifyUIObjectEvent( CANDUIOBJ_CANDTIPWINDOW, CANDUIOBJEV_DESTROYED );
  3512. }
  3513. //
  3514. if (m_pCommentWnd != NULL) {
  3515. m_pCommentWnd->OnCandWindowMove( FALSE );
  3516. }
  3517. }
  3518. /* M O V E C A N D T I P W I N D O W */
  3519. /*------------------------------------------------------------------------------
  3520. ------------------------------------------------------------------------------*/
  3521. void CCandWindow::MoveCandTipWindow( void )
  3522. {
  3523. RECT rcWnd;
  3524. RECT rcBtn;
  3525. POINT pt;
  3526. BALLOONWNDPOS pos;
  3527. BALLOONWNDALIGN align;
  3528. if (m_pCandTipWnd->GetWnd() == NULL) {
  3529. return;
  3530. }
  3531. GetWindowRect( GetWnd(), &rcWnd );
  3532. m_pCandTipBtn->GetRect( &rcBtn );
  3533. pt.x = rcWnd.left + (rcBtn.left + rcBtn.right) / 2;
  3534. pt.y = rcWnd.top + (rcBtn.top + rcBtn.bottom) / 2;
  3535. switch (GetPropertyMgr()->GetCandWindowProp()->GetUIDirection()) {
  3536. default:
  3537. case CANDUIDIR_TOPTOBOTTOM: {
  3538. pos = BALLOONPOS_RIGHT;
  3539. align = BALLOONALIGN_TOP;
  3540. break;
  3541. }
  3542. case CANDUIDIR_BOTTOMTOTOP: {
  3543. pos = BALLOONPOS_RIGHT;
  3544. align = BALLOONALIGN_BOTTOM;
  3545. break;
  3546. }
  3547. case CANDUIDIR_RIGHTTOLEFT: {
  3548. pos = BALLOONPOS_BELLOW;
  3549. align = BALLOONALIGN_RIGHT;
  3550. break;
  3551. }
  3552. case CANDUIDIR_LEFTTORIGHT: {
  3553. pos = BALLOONPOS_BELLOW;
  3554. align = BALLOONALIGN_LEFT;
  3555. break;
  3556. }
  3557. }
  3558. m_pCandTipWnd->SetBalloonPos( pos );
  3559. m_pCandTipWnd->SetBalloonAlign( align );
  3560. m_pCandTipWnd->SetExcludeRect( &rcWnd );
  3561. m_pCandTipWnd->SetTargetPos( pt );
  3562. NotifyUIObjectEvent( CANDUIOBJ_CANDTIPWINDOW, CANDUIOBJEV_UPDATED );
  3563. }
  3564. /* S H O W C A N D T I P W I N D O W */
  3565. /*------------------------------------------------------------------------------
  3566. ------------------------------------------------------------------------------*/
  3567. void CCandWindow::ShowCandTipWindow( BOOL fShow )
  3568. {
  3569. if (m_pCandTipWnd->GetWnd() == NULL) {
  3570. return;
  3571. }
  3572. if (fShow) {
  3573. MoveCandTipWindow();
  3574. m_pCandTipWnd->Show( TRUE );
  3575. }
  3576. else {
  3577. m_pCandTipWnd->Show( FALSE );
  3578. }
  3579. }
  3580. /*============================================================================*/
  3581. /* */
  3582. /* C C H S C A N D W I N D O W */
  3583. /* */
  3584. /*============================================================================*/
  3585. /* C C H S C A N D W I N D O W */
  3586. /*------------------------------------------------------------------------------
  3587. Constructor of CChsCandWindow
  3588. ------------------------------------------------------------------------------*/
  3589. CChsCandWindow::CChsCandWindow( CCandidateUI *pCandUIEx, DWORD dwStyle ) : CCandWindowBase( pCandUIEx, dwStyle | UIWINDOW_TOPMOST | UIWINDOW_TOOLWINDOW | UIWINDOW_OFC10MENU )
  3590. {
  3591. m_pListUIObj = NULL;
  3592. }
  3593. /* ~ C C H S C A N D W I N D O W */
  3594. /*------------------------------------------------------------------------------
  3595. Destructor of CChsCandWindow
  3596. ------------------------------------------------------------------------------*/
  3597. CChsCandWindow::~CChsCandWindow()
  3598. {
  3599. //
  3600. // Notify UI object destroy
  3601. //
  3602. NotifyUIObjectEvent( CANDUIOBJ_CANDLISTBOX, CANDUIOBJEV_DESTROYED );
  3603. NotifyUIObjectEvent( CANDUIOBJ_MENUBUTTON, CANDUIOBJEV_DESTROYED );
  3604. NotifyUIObjectEvent( CANDUIOBJ_CANDRAWDATA, CANDUIOBJEV_DESTROYED );
  3605. }
  3606. /* I N I T U I O B J E C T S */
  3607. /*------------------------------------------------------------------------------
  3608. Create UI objects
  3609. ------------------------------------------------------------------------------*/
  3610. CUIFObject *CChsCandWindow::Initialize( void )
  3611. {
  3612. RECT rc = {0};
  3613. CUIFBorder *pBorder;
  3614. //
  3615. // create border
  3616. //
  3617. pBorder = new CUIFBorder( this, IDUIF_BORDER, &rc, UIBORDER_VERT );
  3618. if(pBorder)
  3619. {
  3620. pBorder->Initialize();
  3621. AddUIObj( pBorder );
  3622. }
  3623. //
  3624. // create candidate list
  3625. //
  3626. m_pListUIObj = new CUIFRowList( this, IDUIF_CANDIDATELIST, &rc, UILIST_HORZTB );
  3627. if (m_pListUIObj)
  3628. {
  3629. m_pListUIObj->Initialize();
  3630. AddUIObj( m_pListUIObj );
  3631. }
  3632. //
  3633. // create candidate menu button
  3634. //
  3635. m_pCandMenuBtn = new CUIFSmartMenuButton( this, IDUIF_CANDIDATEMENU, &rc, UIBUTTON_TOGGLE );
  3636. if (m_pCandMenuBtn)
  3637. {
  3638. m_pCandMenuBtn->Initialize();
  3639. AddUIObj( m_pCandMenuBtn );
  3640. m_pCandMenuBtn->SetIcon( m_hIconMenu );
  3641. }
  3642. //
  3643. // create raw data statics
  3644. //
  3645. m_pCandRawData = new CUIFCandRawData( this, IDUIF_RAWDATA, &rc, UICANDRAWDATA_HORZTB );
  3646. if (m_pCandRawData)
  3647. {
  3648. m_pCandRawData->Initialize();
  3649. AddUIObj( m_pCandRawData );
  3650. }
  3651. //
  3652. // add extensions
  3653. //
  3654. CreateExtensionObjects();
  3655. //
  3656. // Notify UI object creation
  3657. //
  3658. NotifyUIObjectEvent( CANDUIOBJ_CANDLISTBOX, CANDUIOBJEV_CREATED );
  3659. NotifyUIObjectEvent( CANDUIOBJ_MENUBUTTON, CANDUIOBJEV_CREATED );
  3660. NotifyUIObjectEvent( CANDUIOBJ_CANDRAWDATA, CANDUIOBJEV_CREATED );
  3661. return CCandWindowBase::Initialize();
  3662. }
  3663. /* L A Y O U T W I N D O W */
  3664. /*------------------------------------------------------------------------------
  3665. Layout window
  3666. ------------------------------------------------------------------------------*/
  3667. void CChsCandWindow::LayoutWindow( void )
  3668. {
  3669. HDC hDC = GetDC( m_hWnd );
  3670. RECT rc;
  3671. DWORD dwStyle;
  3672. CUIFObject *pUIObj;
  3673. SIZE size;
  3674. LONG nExtension;
  3675. HFONT hFontUI = GetPropertyMgr()->GetCandIndexProp()->GetFont();
  3676. HFONT hFontCandidateList = GetPropertyMgr()->GetCandStringProp()->GetFont();
  3677. BOOL fHorizontal = ((GetPropertyMgr()->GetCandWindowProp()->GetUIDirection() == CANDUIDIR_RIGHTTOLEFT) || (GetPropertyMgr()->GetCandWindowProp()->GetUIDirection() == CANDUIDIR_LEFTTORIGHT)) ? FALSE : TRUE;
  3678. // calc metrics
  3679. int cyText;
  3680. int cxObjectMargin = 1;
  3681. int cyObjectMargin = 1;
  3682. int cxBorder = 2; // border width of vertical border
  3683. int cyBorder = 2; // border height of horizontal border
  3684. int cxCandRow;
  3685. int cyCandRow;
  3686. int cxMenuBtn;
  3687. int cyMenuBtn;
  3688. int cxStatus = 0;
  3689. int cyStatus = 0;
  3690. int cxWindow = 0;
  3691. int cyWindow = 0;
  3692. GetTextExtent( hFontCandidateList, L"1", 1, &size, fHorizontal );
  3693. cyText = max(size.cx, size.cy);
  3694. cxMenuBtn = cyText / 2;
  3695. cyMenuBtn = cyText / 2;
  3696. //
  3697. // font settings
  3698. //
  3699. int nChild = m_ChildList.GetCount();
  3700. for (int i = 0; i < nChild; i++) {
  3701. CUIFObject *pUIObjTmp = m_ChildList.Get( i );
  3702. Assert( pUIObjTmp != NULL );
  3703. if (pUIObjTmp != m_pListUIObj) {
  3704. pUIObjTmp->SetFont( hFontUI );
  3705. }
  3706. else {
  3707. m_pListUIObj->SetFont( hFontCandidateList );
  3708. m_pListUIObj->SetInlineCommentFont( GetPropertyMgr()->GetInlineCommentProp()->GetFont() );
  3709. m_pListUIObj->SetIndexFont( GetPropertyMgr()->GetCandIndexProp()->GetFont() );
  3710. }
  3711. }
  3712. //
  3713. // calculate the size of candidate row
  3714. //
  3715. if (fHorizontal)
  3716. {
  3717. cyCandRow = cyBorder + cyText;
  3718. cxCandRow = ( cxBorder + cyText + cyText + HCAND_ITEM_MARGIN ) * NUM_CANDSTR_MAX + cyCandRow * 2;
  3719. }
  3720. else
  3721. {
  3722. cxCandRow = cxBorder + cyText;
  3723. cyCandRow = ( cyBorder + cyText + cyText + HCAND_ITEM_MARGIN ) * NUM_CANDSTR_MAX + cxCandRow * 2;
  3724. }
  3725. //
  3726. // calculate the size of status area
  3727. //
  3728. // extension items
  3729. nExtension = GetExtensionMgr()->GetExtensionNum();
  3730. if (0 < nExtension) {
  3731. LONG i;
  3732. for (i = 0; i < nExtension; i++) {
  3733. CCandUIExtension *pExtension = GetExtensionMgr()->GetExtension( i );
  3734. pExtension->GetSize( &size );
  3735. if (fHorizontal) {
  3736. cxStatus += size.cx + cxBorder;
  3737. cyStatus = max( cyStatus, size.cy + cxBorder );
  3738. }
  3739. else {
  3740. cxStatus = max( cxStatus, size.cx + cxBorder );
  3741. cyStatus += size.cy + cxBorder;
  3742. }
  3743. }
  3744. if (fHorizontal) {
  3745. cyStatus += cyObjectMargin + cyBorder + cyObjectMargin;
  3746. }
  3747. else {
  3748. cxStatus += cxObjectMargin + cxBorder + cxObjectMargin;
  3749. }
  3750. }
  3751. else if (m_fHasRawData) {
  3752. if (fHorizontal) {
  3753. cxStatus = cxCandRow;
  3754. cyStatus = GetSystemMetrics( SM_CXHSCROLL ) + cyObjectMargin + cyBorder + cyObjectMargin;
  3755. }
  3756. else {
  3757. cxStatus = GetSystemMetrics( SM_CXHSCROLL ) + cxObjectMargin + cxBorder + cxObjectMargin;
  3758. cyStatus = cyCandRow;
  3759. }
  3760. }
  3761. else {
  3762. }
  3763. //
  3764. // calculate window size, considering margins/border size
  3765. //
  3766. if (fHorizontal) {
  3767. cxWindow = max( cxBorder + cxMenuBtn + cxCandRow, cxStatus );
  3768. cyWindow = cyCandRow + cyStatus;
  3769. rc.left = m_rcTarget.left;
  3770. rc.top = m_rcTarget.bottom;
  3771. }
  3772. else {
  3773. cxWindow = cxCandRow + cxStatus;
  3774. cyWindow = max( cxBorder + cyMenuBtn + cyCandRow, cyStatus );
  3775. rc.left = m_rcTarget.left - cxWindow;
  3776. rc.top = m_rcTarget.top;
  3777. }
  3778. //
  3779. // change window position and size
  3780. //
  3781. rc.right = rc.left + cxWindow + cxBorder;
  3782. rc.bottom = rc.top + cyWindow + cyBorder;
  3783. Move( rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top );
  3784. //
  3785. // layout candidate menu button
  3786. // (uses rc of window. do this after layouting window)
  3787. //
  3788. if (fHorizontal) {
  3789. rc.left = 0;
  3790. rc.top = 0;
  3791. rc.right = cxMenuBtn + cxBorder;
  3792. rc.bottom = cyCandRow;
  3793. }
  3794. else {
  3795. rc.right = cxWindow;
  3796. rc.top = 0;
  3797. rc.left = rc.right - cxCandRow;
  3798. rc.bottom = cyMenuBtn + cyBorder;
  3799. }
  3800. if (m_pCandMenuBtn != NULL) {
  3801. m_pCandMenuBtn->SetRect( &rc );
  3802. m_pCandMenuBtn->Show( TRUE );
  3803. m_pCandMenuBtn->Enable( GetPropertyMgr()->GetMenuButtonProp()->IsEnabled() );
  3804. m_pCandMenuBtn->SetToolTip( GetPropertyMgr()->GetMenuButtonProp()->GetToolTipString() );
  3805. }
  3806. //
  3807. // layout candidate row
  3808. // (uses rc of window. do this after layouting candidate menu button )
  3809. if (fHorizontal) {
  3810. rc.left = rc.right;
  3811. rc.right = rc.left + cxCandRow;
  3812. dwStyle = UILIST_HORZTB;
  3813. }
  3814. else {
  3815. rc.top = rc.bottom;
  3816. rc.bottom = rc.top + cyCandRow;
  3817. dwStyle = UILIST_VERTRL;
  3818. }
  3819. if (m_pListUIObj != NULL) {
  3820. m_pListUIObj->SetRect( &rc );
  3821. m_pListUIObj->SetStyle( dwStyle );
  3822. m_pListUIObj->Show( TRUE );
  3823. }
  3824. //
  3825. // layout extensions
  3826. //
  3827. pUIObj = FindUIObject( IDUIF_BORDER );
  3828. if ((0 < nExtension) || m_fHasRawData) {
  3829. //
  3830. // layout border
  3831. //
  3832. if (fHorizontal) {
  3833. rc.left = 0;
  3834. rc.top = cyCandRow + cyObjectMargin;
  3835. rc.right = cxWindow;
  3836. rc.bottom = rc.top + cyBorder;
  3837. dwStyle = UIBORDER_HORZ;
  3838. }
  3839. else {
  3840. rc.right = cxStatus - cyObjectMargin;
  3841. rc.left = rc.right - cxBorder;
  3842. rc.top = 0;
  3843. rc.bottom = cyWindow;
  3844. dwStyle = UIBORDER_VERT;
  3845. }
  3846. if (pUIObj != NULL) {
  3847. pUIObj->SetStyle( dwStyle );
  3848. pUIObj->SetRect( &rc );
  3849. pUIObj->Show( TRUE );
  3850. }
  3851. } else {
  3852. if (pUIObj != NULL) {
  3853. pUIObj->Show( FALSE );
  3854. }
  3855. }
  3856. if (0 < nExtension) {
  3857. LONG i;
  3858. // layout rawdata object
  3859. if (m_fHasRawData) {
  3860. if (fHorizontal) {
  3861. rc.left = 0;
  3862. rc.top = cyCandRow + cyObjectMargin + cyBorder + cyObjectMargin;
  3863. rc.right = cxWindow - cxStatus;
  3864. rc.bottom = cyWindow;
  3865. dwStyle = UICANDRAWDATA_HORZTB;
  3866. }
  3867. else {
  3868. rc.left = 0;
  3869. rc.top = 0;
  3870. rc.right = cxStatus - cyObjectMargin - cyBorder - cyObjectMargin;
  3871. rc.bottom = cyWindow - cyStatus;
  3872. dwStyle = UICANDRAWDATA_VERTRL;
  3873. }
  3874. Assert(m_pCandRawData != NULL);
  3875. m_pCandRawData->SetStyle( dwStyle );
  3876. m_pCandRawData->SetRect( &rc );
  3877. m_pCandRawData->Show( TRUE );
  3878. } else {
  3879. m_pCandRawData->Show( FALSE );
  3880. }
  3881. //
  3882. // layout extension items
  3883. //
  3884. if (fHorizontal) {
  3885. rc.left = cxWindow - cxStatus;
  3886. rc.top = cyCandRow + cyObjectMargin + cyBorder + cyObjectMargin;
  3887. rc.right = rc.left;
  3888. rc.bottom = cyWindow;
  3889. }
  3890. else {
  3891. rc.left = 0;
  3892. rc.top = cyWindow - cyStatus;
  3893. rc.right = cxStatus - cyObjectMargin - cyBorder - cyObjectMargin;
  3894. rc.bottom = rc.top;
  3895. }
  3896. for (i = 0; i < nExtension; i++) {
  3897. CCandUIExtension *pExtension = GetExtensionMgr()->GetExtension( i );
  3898. CUIFObject *pUIObjExt = FindUIObject( IDUIF_EXTENDED + i );
  3899. pExtension->GetSize( &size );
  3900. if (fHorizontal) {
  3901. rc.left = rc.right;
  3902. rc.top = rc.top;
  3903. rc.right = rc.right + size.cx + cxBorder;
  3904. rc.bottom = rc.top + size.cy + cyBorder;
  3905. }
  3906. else {
  3907. rc.left = rc.left;
  3908. rc.top = rc.bottom;
  3909. rc.right = rc.left + size.cx + cxBorder;
  3910. rc.bottom = rc.bottom + size.cy + cxBorder;
  3911. }
  3912. if (pUIObjExt != NULL) {
  3913. pUIObjExt->SetRect( &rc );
  3914. }
  3915. }
  3916. }
  3917. else {
  3918. // layout rawdata object
  3919. if (m_fHasRawData) {
  3920. if (fHorizontal) {
  3921. rc.left = 0;
  3922. rc.top = cyCandRow + cyObjectMargin + cyBorder + cyObjectMargin;
  3923. rc.right = cxWindow;
  3924. rc.bottom = cyWindow;
  3925. dwStyle = UICANDRAWDATA_HORZTB;
  3926. }
  3927. else {
  3928. rc.left = 0;
  3929. rc.top = 0;
  3930. rc.right = cxStatus - cyObjectMargin - cyBorder - cyObjectMargin;
  3931. rc.bottom = cyWindow;
  3932. dwStyle = UICANDRAWDATA_VERTRL;
  3933. }
  3934. Assert(m_pCandRawData != NULL);
  3935. m_pCandRawData->SetStyle( dwStyle );
  3936. m_pCandRawData->SetRect( &rc );
  3937. m_pCandRawData->Show( TRUE );
  3938. } else {
  3939. m_pCandRawData->Show( FALSE );
  3940. }
  3941. }
  3942. //
  3943. // Notify UI object update
  3944. //
  3945. NotifyUIObjectEvent( CANDUIOBJ_CANDLISTBOX, CANDUIOBJEV_UPDATED );
  3946. NotifyUIObjectEvent( CANDUIOBJ_MENUBUTTON, CANDUIOBJEV_UPDATED );
  3947. NotifyUIObjectEvent( CANDUIOBJ_CANDRAWDATA, CANDUIOBJEV_UPDATED );
  3948. ReleaseDC( m_hWnd, hDC );
  3949. }
  3950. /* S E L E C T I T E M N E X T */
  3951. /*------------------------------------------------------------------------------
  3952. ------------------------------------------------------------------------------*/
  3953. void CChsCandWindow::SelectItemNext( void )
  3954. {
  3955. ((CUIFRowList*)m_pListUIObj)->ShiftItem( 1 );
  3956. }
  3957. /* S E L E C T I T E M P R E V */
  3958. /*------------------------------------------------------------------------------
  3959. ------------------------------------------------------------------------------*/
  3960. void CChsCandWindow::SelectItemPrev( void )
  3961. {
  3962. ((CUIFRowList*)m_pListUIObj)->ShiftItem( -1 );
  3963. }
  3964. /* S E L E C T P A G E N E X T */
  3965. /*------------------------------------------------------------------------------
  3966. ------------------------------------------------------------------------------*/
  3967. void CChsCandWindow::SelectPageNext( void )
  3968. {
  3969. ((CUIFRowList*)m_pListUIObj)->ShiftPage( 1 );
  3970. }
  3971. /* S E L E C T P A G E P R E V */
  3972. /*------------------------------------------------------------------------------
  3973. ------------------------------------------------------------------------------*/
  3974. void CChsCandWindow::SelectPagePrev( void )
  3975. {
  3976. ((CUIFRowList*)m_pListUIObj)->ShiftPage( -1 );
  3977. }
  3978. /* M A P C O M M A N D */
  3979. /*------------------------------------------------------------------------------
  3980. Map directional command to undirectional command
  3981. (CUIFWindowBase method)
  3982. ------------------------------------------------------------------------------*/
  3983. CANDUICOMMAND CChsCandWindow::MapCommand( CANDUICOMMAND cmd )
  3984. {
  3985. BOOL fVertical = (GetPropertyMgr()->GetCandWindowProp()->GetUIDirection() == CANDUIDIR_RIGHTTOLEFT)
  3986. || (GetPropertyMgr()->GetCandWindowProp()->GetUIDirection() == CANDUIDIR_LEFTTORIGHT);
  3987. switch (cmd) {
  3988. case CANDUICMD_MOVESELUP: {
  3989. cmd = (fVertical ? CANDUICMD_MOVESELPREV : CANDUICMD_NONE);
  3990. break;
  3991. }
  3992. case CANDUICMD_MOVESELDOWN: {
  3993. cmd = (fVertical ? CANDUICMD_MOVESELNEXT : CANDUICMD_NONE);
  3994. break;
  3995. }
  3996. case CANDUICMD_MOVESELLEFT: {
  3997. cmd = (fVertical ? CANDUICMD_NONE : CANDUICMD_MOVESELPREV);
  3998. break;
  3999. }
  4000. case CANDUICMD_MOVESELRIGHT: {
  4001. cmd = (fVertical ? CANDUICMD_NONE : CANDUICMD_MOVESELNEXT);
  4002. break;
  4003. }
  4004. }
  4005. return cmd;
  4006. }
  4007. /* G E T C A N D W I N D O W O B J */
  4008. /*------------------------------------------------------------------------------
  4009. (CCandUIObjectParent method)
  4010. ------------------------------------------------------------------------------*/
  4011. CCandWindowBase *CChsCandWindow::GetCandWindowObj( void )
  4012. {
  4013. return this;
  4014. }
  4015. /* G E T P O P U P C O M M E N T W I N D O W O B J */
  4016. /*------------------------------------------------------------------------------
  4017. (CCandUIObjectParent method)
  4018. ------------------------------------------------------------------------------*/
  4019. CPopupCommentWindow *CChsCandWindow::GetPopupCommentWindowObj( void )
  4020. {
  4021. return NULL;
  4022. }
  4023. /* G E T O P T I O N S L I S T B O X O B J */
  4024. /*------------------------------------------------------------------------------
  4025. (CCandUIObjectParent method)
  4026. ------------------------------------------------------------------------------*/
  4027. CUIFCandListBase *CChsCandWindow::GetOptionsListBoxObj( void )
  4028. {
  4029. return NULL;
  4030. }
  4031. /* G E T C A N D L I S T B O X O B J */
  4032. /*------------------------------------------------------------------------------
  4033. (CCandUIObjectParent method)
  4034. ------------------------------------------------------------------------------*/
  4035. CUIFCandListBase *CChsCandWindow::GetCandListBoxObj( void )
  4036. {
  4037. return m_pListUIObj;
  4038. }
  4039. /* G E T C A P T I O N O B J */
  4040. /*------------------------------------------------------------------------------
  4041. (CCandUIObjectParent method)
  4042. ------------------------------------------------------------------------------*/
  4043. CUIFWndCaption *CChsCandWindow::GetCaptionObj( void )
  4044. {
  4045. return NULL;
  4046. }
  4047. /* G E T M E N U B U T T O N O B J */
  4048. /*------------------------------------------------------------------------------
  4049. (CCandUIObjectParent method)
  4050. ------------------------------------------------------------------------------*/
  4051. CUIFButton *CChsCandWindow::GetMenuButtonObj( void )
  4052. {
  4053. return m_pCandMenuBtn;
  4054. }
  4055. /* G E T E X T R A C A N D I D A T E O B J */
  4056. /*------------------------------------------------------------------------------
  4057. (CCandUIObjectParent method)
  4058. ------------------------------------------------------------------------------*/
  4059. CUIFCandListBase *CChsCandWindow::GetExtraCandidateObj( void )
  4060. {
  4061. return NULL;
  4062. }
  4063. /* G E T C A N D R A W D A T A O B J */
  4064. /*------------------------------------------------------------------------------
  4065. (CCandUIObjectParent method)
  4066. ------------------------------------------------------------------------------*/
  4067. CUIFCandRawData *CChsCandWindow::GetCandRawDataObj( void )
  4068. {
  4069. return m_pCandRawData;
  4070. }
  4071. /* G E T C A N D T I P W I N D O W O B J */
  4072. /*------------------------------------------------------------------------------
  4073. (CCandUIObjectParent method)
  4074. ------------------------------------------------------------------------------*/
  4075. CUIFBalloonWindow *CChsCandWindow::GetCandTipWindowObj( void )
  4076. {
  4077. return NULL;
  4078. }
  4079. /* G E T C A N D T I P B U T T O N O B J */
  4080. /*------------------------------------------------------------------------------
  4081. (CCandUIObjectParent method)
  4082. ------------------------------------------------------------------------------*/
  4083. CUIFButton *CChsCandWindow::GetCandTipButtonObj( void )
  4084. {
  4085. return NULL;
  4086. }
  4087. /* S E T T A R G E T R E C T */
  4088. /*------------------------------------------------------------------------------
  4089. ------------------------------------------------------------------------------*/
  4090. void CChsCandWindow::SetTargetRect( RECT *prc, BOOL fClipped )
  4091. {
  4092. m_rcTarget = *prc;
  4093. m_fTargetClipped = fClipped;
  4094. if (m_hWnd != NULL) {
  4095. int nLeft;
  4096. int nTop;
  4097. // move window here...
  4098. switch (GetPropertyMgr()->GetCandWindowProp()->GetUIDirection()) {
  4099. default:
  4100. case CANDUIDIR_TOPTOBOTTOM:
  4101. case CANDUIDIR_BOTTOMTOTOP: {
  4102. nLeft = m_rcTarget.left;
  4103. nTop = m_rcTarget.bottom;
  4104. break;
  4105. }
  4106. case CANDUIDIR_RIGHTTOLEFT:
  4107. case CANDUIDIR_LEFTTORIGHT: {
  4108. nLeft = m_rcTarget.left - _nWidth;
  4109. nTop = m_rcTarget.top;
  4110. break;
  4111. }
  4112. }
  4113. Move( nLeft, nTop, -1, -1 );
  4114. }
  4115. }
  4116. /* S E T W I N D O W P O S */
  4117. /*------------------------------------------------------------------------------
  4118. ------------------------------------------------------------------------------*/
  4119. void CChsCandWindow::SetWindowPos( POINT pt )
  4120. {
  4121. if (m_hWnd != NULL) {
  4122. Move( pt.x, pt.y, -1, -1 );
  4123. }
  4124. }
  4125. /*============================================================================*/
  4126. /* */
  4127. /* C C A N D U I O B J E C T M G R */
  4128. /* */
  4129. /*============================================================================*/
  4130. /* C C A N D U I O B J E C T M G R */
  4131. /*------------------------------------------------------------------------------
  4132. ------------------------------------------------------------------------------*/
  4133. CCandUIObjectMgr::CCandUIObjectMgr( void )
  4134. {
  4135. int i;
  4136. m_pCandUI = NULL;
  4137. m_pUIObjectParent = NULL;
  4138. for (i = 0; i < CANDUIOBJSINK_MAX; i++) {
  4139. m_rgSink[i] = NULL;
  4140. }
  4141. }
  4142. /* ~ C C A N D U I O B J E C T M G R */
  4143. /*------------------------------------------------------------------------------
  4144. ------------------------------------------------------------------------------*/
  4145. CCandUIObjectMgr::~CCandUIObjectMgr( void )
  4146. {
  4147. Uninitialize();
  4148. }
  4149. /* I N I T I A L I Z E */
  4150. /*------------------------------------------------------------------------------
  4151. ------------------------------------------------------------------------------*/
  4152. HRESULT CCandUIObjectMgr::Initialize( CCandidateUI *pCandUI )
  4153. {
  4154. m_pCandUI = pCandUI;
  4155. m_pUIObjectParent = NULL;
  4156. #if defined(DEBUG) || defined(_DEBUG)
  4157. // check all reference object are unregistered
  4158. for (int i = 0; i < CANDUIOBJSINK_MAX; i++) {
  4159. Assert( m_rgSink[i] == NULL );
  4160. }
  4161. #endif
  4162. return S_OK;
  4163. }
  4164. /* U N I N I T I A L I Z E */
  4165. /*------------------------------------------------------------------------------
  4166. ------------------------------------------------------------------------------*/
  4167. HRESULT CCandUIObjectMgr::Uninitialize( void )
  4168. {
  4169. m_pCandUI = NULL;
  4170. m_pUIObjectParent = NULL;
  4171. #if defined(DEBUG) || defined(_DEBUG)
  4172. // check all reference object are unregistered
  4173. for (int i = 0; i < CANDUIOBJSINK_MAX; i++) {
  4174. Assert( m_rgSink[i] == NULL );
  4175. }
  4176. #endif
  4177. return S_OK;
  4178. }
  4179. /* A D V I S E E V E N T S I N K */
  4180. /*------------------------------------------------------------------------------
  4181. ------------------------------------------------------------------------------*/
  4182. HRESULT CCandUIObjectMgr::AdviseEventSink( CCandUIObjectEventSink *pSink )
  4183. {
  4184. int i;
  4185. for (i = 0; i < CANDUIOBJSINK_MAX; i++) {
  4186. if (m_rgSink[i] == NULL) {
  4187. m_rgSink[i] = pSink;
  4188. return S_OK;
  4189. }
  4190. }
  4191. Assert( FALSE );
  4192. return E_FAIL;
  4193. }
  4194. /* U N A D V I S E E V E N T S I N K */
  4195. /*------------------------------------------------------------------------------
  4196. ------------------------------------------------------------------------------*/
  4197. HRESULT CCandUIObjectMgr::UnadviseEventSink( CCandUIObjectEventSink *pSink )
  4198. {
  4199. int i;
  4200. for (i = 0; i < CANDUIOBJSINK_MAX; i++) {
  4201. if (m_rgSink[i] == pSink) {
  4202. m_rgSink[i] = NULL;
  4203. return S_OK;
  4204. }
  4205. }
  4206. Assert( FALSE );
  4207. return E_FAIL;
  4208. }
  4209. /* N O T I F Y U I O B J E C T E V E N T */
  4210. /*------------------------------------------------------------------------------
  4211. ------------------------------------------------------------------------------*/
  4212. void CCandUIObjectMgr::NotifyUIObjectEvent( CANDUIOBJECT obj, CANDUIOBJECTEVENT event )
  4213. {
  4214. int i;
  4215. for (i = 0; i < CANDUIOBJSINK_MAX; i++) {
  4216. if (m_rgSink[i] != NULL) {
  4217. m_rgSink[i]->OnObjectEvent( obj, event );
  4218. }
  4219. }
  4220. }
  4221. /*============================================================================*/
  4222. /* */
  4223. /* C C A N D U I P R O P E R T Y E V E N T S I N K */
  4224. /* */
  4225. /*============================================================================*/
  4226. /* C C A N D U I O B J E C T E V E N T S I N K */
  4227. /*------------------------------------------------------------------------------
  4228. ------------------------------------------------------------------------------*/
  4229. CCandUIObjectEventSink::CCandUIObjectEventSink( void )
  4230. {
  4231. m_pObjectMgr = NULL;
  4232. }
  4233. /* ~ C C A N D U I O B J E C T E V E N T S I N K */
  4234. /*------------------------------------------------------------------------------
  4235. ------------------------------------------------------------------------------*/
  4236. CCandUIObjectEventSink::~CCandUIObjectEventSink( void )
  4237. {
  4238. Assert( m_pObjectMgr == NULL );
  4239. if (m_pObjectMgr != NULL) {
  4240. DoneEventSink();
  4241. }
  4242. }
  4243. /* I N I T E V E N T S I N K */
  4244. /*------------------------------------------------------------------------------
  4245. ------------------------------------------------------------------------------*/
  4246. HRESULT CCandUIObjectEventSink::InitEventSink( CCandUIObjectMgr *pObjectMgr )
  4247. {
  4248. Assert( pObjectMgr != NULL );
  4249. Assert( m_pObjectMgr == NULL );
  4250. if (pObjectMgr == NULL) {
  4251. return E_INVALIDARG;
  4252. }
  4253. m_pObjectMgr = pObjectMgr;
  4254. return m_pObjectMgr->AdviseEventSink( this );
  4255. }
  4256. /* D O N E E V E N T S I N K */
  4257. /*------------------------------------------------------------------------------
  4258. ------------------------------------------------------------------------------*/
  4259. HRESULT CCandUIObjectEventSink::DoneEventSink( void )
  4260. {
  4261. HRESULT hr;
  4262. Assert( m_pObjectMgr != NULL );
  4263. if (m_pObjectMgr == NULL) {
  4264. return E_FAIL;
  4265. }
  4266. hr = m_pObjectMgr->UnadviseEventSink( this );
  4267. m_pObjectMgr = NULL;
  4268. return hr;
  4269. }