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.

1629 lines
42 KiB

  1. //
  2. // cuicand2.cpp - ui frame object for candidate UI
  3. //
  4. #include "private.h"
  5. #include "cuilib.h"
  6. #include "cuicand2.h"
  7. #include "candutil.h"
  8. #ifndef IDUIF_CANDNUMBUTTON
  9. #define IDUIF_CANDNUMBUTTON 0x00000001
  10. #endif
  11. /*=============================================================================*/
  12. /* */
  13. /* C U I F S M A R T M E N U B U T T O N */
  14. /* */
  15. /*=============================================================================*/
  16. //
  17. // CUIFSmartMenuButton
  18. //
  19. /* C U I F S M A R T M E N U B U T T O N */
  20. /*------------------------------------------------------------------------------
  21. Constructor of CUIFSmartMenuButton
  22. ------------------------------------------------------------------------------*/
  23. CUIFSmartMenuButton::CUIFSmartMenuButton( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFButton2( pParent, dwID, prc, dwStyle )
  24. {
  25. m_pUIFScheme = CreateUIFScheme( UIFSCHEME_OFC10TOOLBAR );
  26. Assert( m_pUIFScheme != NULL );
  27. }
  28. /* ~ C U I F S M A R T M E N U B U T T O N */
  29. /*------------------------------------------------------------------------------
  30. Destructor of CUIFSmartMenuButton
  31. ------------------------------------------------------------------------------*/
  32. CUIFSmartMenuButton::~CUIFSmartMenuButton( void )
  33. {
  34. // dispose scheme
  35. delete m_pUIFScheme;
  36. }
  37. /* O N P A I N T */
  38. /*------------------------------------------------------------------------------
  39. Paint procedure of smart menu button object
  40. ------------------------------------------------------------------------------*/
  41. void CUIFSmartMenuButton::OnPaint( HDC hDC )
  42. {
  43. DWORD dwState = 0;
  44. HDC hDCMem;
  45. HBITMAP hBmpMem;
  46. HBITMAP hBmpOld;
  47. SIZE size;
  48. RECT rc;
  49. COLORREF col;
  50. // make draw flag
  51. dwState |= (m_fToggled) ? UIFDCS_SELECTED : 0;
  52. switch (m_dwStatus) {
  53. case UIBUTTON_DOWN: {
  54. dwState |= UIFDCS_MOUSEDOWN;
  55. break;
  56. }
  57. case UIBUTTON_HOVER:
  58. case UIBUTTON_DOWNOUT: {
  59. dwState |= UIFDCS_MOUSEOVER;
  60. break;
  61. }
  62. }
  63. dwState |= (IsEnabled() ? 0 : UIFDCS_DISABLED);
  64. // prepare memory dc
  65. size.cx = GetRectRef().right - GetRectRef().left;
  66. size.cy = GetRectRef().bottom - GetRectRef().top;
  67. hDCMem = CreateCompatibleDC( hDC );
  68. hBmpMem = CreateCompatibleBitmap( hDC, size.cx, size.cy );
  69. hBmpOld = (HBITMAP)SelectObject( hDCMem, hBmpMem );
  70. ::SetRect( &rc, 0, 0, size.cx, size.cy );
  71. // paint background
  72. m_pUIFScheme->DrawCtrlBkgd( hDCMem, &rc, UIFDCF_BUTTON, dwState );
  73. // paint face
  74. if (dwState & UIFDCS_DISABLED) {
  75. col = GetUIFColor( UIFCOLOR_CTRLTEXTDISABLED );
  76. }
  77. else {
  78. col = GetUIFColor( UIFCOLOR_CTRLTEXT );
  79. }
  80. DrawTriangle( hDCMem, &rc, col, UIFDCTF_MENUDROP );
  81. // draw button edge
  82. m_pUIFScheme->DrawCtrlEdge( hDCMem, &rc, UIFDCF_BUTTON, dwState );
  83. //
  84. BitBlt( hDC, GetRectRef().left, GetRectRef().top, size.cx, size.cy, hDCMem, 0, 0, SRCCOPY );
  85. SelectObject( hDCMem, hBmpOld );
  86. if (hBmpMem)
  87. DeleteObject( hBmpMem );
  88. DeleteDC( hDCMem );
  89. }
  90. /*=============================================================================*/
  91. /* */
  92. /* C U I F S M A R T P A G E B U T T O N */
  93. /* */
  94. /*=============================================================================*/
  95. //
  96. // CUIFSmartPageButton
  97. //
  98. /* C U I F S M A R T P A G E B U T T O N */
  99. /*------------------------------------------------------------------------------
  100. Constructor of CUIFSmartPageButton
  101. ------------------------------------------------------------------------------*/
  102. CUIFSmartPageButton::CUIFSmartPageButton( CUIFObject *pParent, const RECT *prc, DWORD dwStyle ) : CUIFButton2( pParent, 0, prc, dwStyle )
  103. {
  104. m_pUIFScheme = CreateUIFScheme( UIFSCHEME_OFC10TOOLBAR );
  105. Assert( m_pUIFScheme != NULL );
  106. }
  107. /* ~ C U I F S M A R T P A G E B U T T O N */
  108. /*------------------------------------------------------------------------------
  109. Destructor of CUIFSmartPageButton
  110. ------------------------------------------------------------------------------*/
  111. CUIFSmartPageButton::~CUIFSmartPageButton( void )
  112. {
  113. // dispose scheme
  114. delete m_pUIFScheme;
  115. }
  116. /* O N P A I N T */
  117. /*------------------------------------------------------------------------------
  118. Paint procedure of smart page button object
  119. ------------------------------------------------------------------------------*/
  120. void CUIFSmartPageButton::OnPaint( HDC hDC )
  121. {
  122. DWORD dwState = 0;
  123. DWORD dwFlag;
  124. HDC hDCMem;
  125. HBITMAP hBmpMem;
  126. HBITMAP hBmpOld;
  127. SIZE size;
  128. RECT rc;
  129. COLORREF col;
  130. // make draw flag
  131. dwState |= (m_fToggled) ? UIFDCS_SELECTED : 0;
  132. switch (m_dwStatus) {
  133. case UIBUTTON_DOWN: {
  134. dwState |= UIFDCS_MOUSEDOWN;
  135. break;
  136. }
  137. case UIBUTTON_HOVER:
  138. case UIBUTTON_DOWNOUT: {
  139. dwState |= UIFDCS_MOUSEOVER;
  140. break;
  141. }
  142. }
  143. dwState |= IsEnabled() ? 0 : UIFDCS_DISABLED;
  144. // prepare memory dc
  145. size.cx = GetRectRef().right - GetRectRef().left;
  146. size.cy = GetRectRef().bottom - GetRectRef().top;
  147. hDCMem = CreateCompatibleDC( hDC );
  148. hBmpMem = CreateCompatibleBitmap( hDC, size.cx, size.cy );
  149. hBmpOld = (HBITMAP)SelectObject( hDCMem, hBmpMem );
  150. ::SetRect( &rc, 0, 0, size.cx, size.cy );
  151. // paint background
  152. m_pUIFScheme->DrawCtrlBkgd( hDCMem, &rc, UIFDCF_BUTTON, dwState );
  153. // paint face
  154. switch (m_dwStyle & UISCROLLBUTTON_DIRMASK) {
  155. case UISCROLLBUTTON_LEFT: {
  156. dwFlag = UIFDCTF_RIGHTTOLEFT;
  157. break;
  158. }
  159. case UISCROLLBUTTON_UP: {
  160. dwFlag = UIFDCTF_BOTTOMTOTOP;
  161. break;
  162. }
  163. case UISCROLLBUTTON_RIGHT: {
  164. dwFlag = UIFDCTF_LEFTTORIGHT;
  165. break;
  166. }
  167. case UISCROLLBUTTON_DOWN: {
  168. dwFlag = UIFDCTF_TOPTOBOTTOM;
  169. break;
  170. }
  171. }
  172. if (dwState & UIFDCS_DISABLED) {
  173. col = GetUIFColor( UIFCOLOR_CTRLTEXTDISABLED );
  174. }
  175. else {
  176. col = GetUIFColor( UIFCOLOR_CTRLTEXT );
  177. }
  178. DrawTriangle( hDCMem, &rc, col, dwFlag );
  179. // draw button edge
  180. m_pUIFScheme->DrawCtrlEdge( hDCMem, &rc, UIFDCF_BUTTON, dwState );
  181. //
  182. BitBlt( hDC, GetRectRef().left, GetRectRef().top, size.cx, size.cy, hDCMem, 0, 0, SRCCOPY );
  183. SelectObject( hDCMem, hBmpOld );
  184. if (hBmpMem)
  185. DeleteObject( hBmpMem );
  186. DeleteDC( hDCMem );
  187. }
  188. /*=============================================================================*/
  189. /* */
  190. /* C U I F R O W B U T T O N */
  191. /* */
  192. /*=============================================================================*/
  193. //
  194. // CUIFRowButton
  195. //
  196. /* C U I F R O W B U T T O N */
  197. /*------------------------------------------------------------------------------
  198. ------------------------------------------------------------------------------*/
  199. CUIFRowButton::CUIFRowButton( CUIFObject *pParent, DWORD dwID, DWORD dwStyle) : CUIFButton2( pParent, dwID, NULL, dwStyle )
  200. {
  201. m_pCandListItem = NULL;
  202. m_hFontInlineComment = NULL;
  203. m_cxInlineCommentPos = -1;
  204. m_fSelected = FALSE;
  205. UpdateText();
  206. }
  207. /* ~ C U I F R O W B U T T O N */
  208. /*------------------------------------------------------------------------------
  209. ------------------------------------------------------------------------------*/
  210. CUIFRowButton::~CUIFRowButton( void )
  211. {
  212. }
  213. /* S E T S T Y L E */
  214. /*------------------------------------------------------------------------------
  215. ------------------------------------------------------------------------------*/
  216. void CUIFRowButton::SetStyle( DWORD dwStyle )
  217. {
  218. CUIFObject::SetStyle( dwStyle );
  219. UpdateText();
  220. }
  221. /* U P D A T E T E X T */
  222. /*------------------------------------------------------------------------------
  223. ------------------------------------------------------------------------------*/
  224. void CUIFRowButton::UpdateText( void )
  225. {
  226. WCHAR pwch[3];
  227. pwch[0] = (WCHAR)'0' + (WORD)(GetID() % 10);
  228. pwch[1] = (WCHAR)' ';
  229. pwch[2] = (WCHAR)'\0';
  230. SetText(pwch);
  231. }
  232. /* O N L B U T T O N D O W N */
  233. /*------------------------------------------------------------------------------
  234. ------------------------------------------------------------------------------*/
  235. void CUIFRowButton::OnLButtonDown( POINT pt )
  236. {
  237. CUIFButton2::OnLButtonDown(pt);
  238. NotifyCommand( UILIST_SELCHANGED, m_pCandListItem->GetIListItem() );
  239. }
  240. /* S E T I N L I N E C O M M E N T F O N T */
  241. /*------------------------------------------------------------------------------
  242. ------------------------------------------------------------------------------*/
  243. void CUIFRowButton::SetInlineCommentFont( HFONT hFont )
  244. {
  245. Assert(hFont != NULL);
  246. m_hFontInlineComment = hFont;
  247. }
  248. /* S E T I N L I N E C O M M E N T P O S */
  249. /*------------------------------------------------------------------------------
  250. ------------------------------------------------------------------------------*/
  251. void CUIFRowButton::SetInlineCommentPos( int cx )
  252. {
  253. m_cxInlineCommentPos = cx;
  254. }
  255. /* S E T C A N D L I S T I T E M */
  256. /*------------------------------------------------------------------------------
  257. ------------------------------------------------------------------------------*/
  258. void CUIFRowButton::SetCandListItem( CCandListItem* pItem )
  259. {
  260. m_pCandListItem = pItem;
  261. }
  262. /* G E T E X T E N T */
  263. /*------------------------------------------------------------------------------
  264. ------------------------------------------------------------------------------*/
  265. void CUIFRowButton::GetExtent(
  266. SIZE *psize)
  267. {
  268. SIZE size;
  269. LPCWSTR psz;
  270. BOOL fHorizontal = (m_dwStyle & UIBUTTON_VCENTER) ? TRUE : FALSE;
  271. Assert(psize);
  272. psize->cx = 0;
  273. psize->cy = 0;
  274. GetTextExtent( m_hFont, GetText(), wcslen( GetText() ), psize, fHorizontal );
  275. if (m_pCandListItem != NULL) {
  276. psz = m_pCandListItem->GetCandidateItem()->GetString();
  277. GetTextExtent( m_hFont, psz, wcslen( psz ), &size, fHorizontal );
  278. psize->cx += size.cx;
  279. psize->cy = max(psize->cy, size.cy);
  280. if ( psz = m_pCandListItem->GetCandidateItem()->GetPrefixString() ) {
  281. GetTextExtent( m_hFont, psz, wcslen( psz ), &size, fHorizontal );
  282. psize->cx += size.cx;
  283. psize->cy = max(psize->cy, size.cy);
  284. }
  285. if ( psz = m_pCandListItem->GetCandidateItem()->GetSuffixString() ) {
  286. GetTextExtent( m_hFont, psz, wcslen( psz ), &size, fHorizontal );
  287. psize->cx += size.cx;
  288. psize->cy = max(psize->cy, size.cy);
  289. }
  290. if ( psz = m_pCandListItem->GetCandidateItem()->GetInlineComment() ) {
  291. GetTextExtent( m_hFontInlineComment, psz, wcslen( psz ), &size, fHorizontal );
  292. psize->cx += size.cx;
  293. if (m_cxInlineCommentPos > 0) {
  294. psize->cx += m_cxInlineCommentPos;
  295. }
  296. psize->cy = max(psize->cy, size.cy);
  297. }
  298. }
  299. Assert(psize->cx);
  300. Assert(psize->cy);
  301. psize->cx += 2; // width of button borders
  302. psize->cy += 2; // height of button borders
  303. }
  304. /* S E L E C T */
  305. /*------------------------------------------------------------------------------
  306. ------------------------------------------------------------------------------*/
  307. void CUIFRowButton::SetSelected( BOOL fSelected )
  308. {
  309. m_fSelected = fSelected;
  310. }
  311. /* O N P A I N T */
  312. /*------------------------------------------------------------------------------
  313. ------------------------------------------------------------------------------*/
  314. void CUIFRowButton::OnPaint( HDC hDC )
  315. {
  316. HFONT hFontOld;
  317. COLORREF colTextOld;
  318. COLORREF colText;
  319. int nBkModeOld;
  320. LPCWSTR psz;
  321. SIZE size;
  322. BOOL fHorizontal = (m_dwStyle & UIBUTTON_VCENTER) ? TRUE : FALSE;
  323. const int ccxMargin = 1;
  324. const int ccyMargin = 1;
  325. POINT ptOrg;
  326. RECT rc;
  327. DWORD dwState = 0;
  328. Assert( m_pCandListItem != NULL );
  329. // make draw flag
  330. dwState |= (m_fToggled) ? UIFDCS_SELECTED : 0;
  331. switch (m_dwStatus) {
  332. case UIBUTTON_DOWN: {
  333. dwState |= UIFDCS_MOUSEDOWN;
  334. break;
  335. }
  336. case UIBUTTON_DOWNOUT: {
  337. dwState |= UIFDCS_MOUSEOVER;
  338. break;
  339. }
  340. }
  341. dwState |= m_fSelected ? UIFDCS_MOUSEOVER : 0;
  342. dwState |= IsEnabled() ? 0 : UIFDCS_DISABLED;
  343. GetRect(&rc);
  344. // paint background
  345. m_pUIFScheme->DrawCtrlBkgd( hDC, &rc, UIFDCF_BUTTON, dwState );
  346. //
  347. // paint index text
  348. //
  349. if (fHorizontal) {
  350. ptOrg.x = GetRectRef().left + ccxMargin;
  351. ptOrg.y = GetRectRef().top + ccyMargin;
  352. }
  353. else {
  354. ptOrg.x = GetRectRef().right - ccxMargin;
  355. ptOrg.y = GetRectRef().top + ccyMargin;
  356. }
  357. colText = GetUIFColor( UIFCOLOR_CTRLTEXT );
  358. colTextOld = SetTextColor( hDC, colText );
  359. nBkModeOld = SetBkMode( hDC, TRANSPARENT );
  360. hFontOld = (HFONT)SelectObject( hDC, m_hFont );
  361. GetTextExtent( m_hFont, GetText(), wcslen( GetText() ), &size, fHorizontal );
  362. if (fHorizontal) {
  363. FLTextOutW( hDC, ptOrg.x + size.cx / 4, ptOrg.y, GetText(), wcslen( GetText() ) );
  364. ptOrg.x += size.cx;
  365. }
  366. else {
  367. FLTextOutW( hDC, ptOrg.x, ptOrg.y + size.cx / 4, GetText(), wcslen( GetText() ) );
  368. ptOrg.y += size.cx;
  369. }
  370. //
  371. // paint prefix string
  372. //
  373. psz = m_pCandListItem->GetCandidateItem()->GetPrefixString();
  374. if (psz != NULL) {
  375. colText = GetUIFColor( UIFCOLOR_CTRLTEXTDISABLED );
  376. SetTextColor( hDC, colText );
  377. FLTextOutW( hDC, ptOrg.x, ptOrg.y, psz, wcslen(psz) );
  378. GetTextExtent( m_hFont, psz, wcslen( psz ), &size, fHorizontal );
  379. if (fHorizontal) {
  380. ptOrg.x += size.cx;
  381. }
  382. else {
  383. ptOrg.y += size.cx;
  384. }
  385. }
  386. //
  387. // paint cand list item string
  388. //
  389. if ( dwState & UIFDCS_MOUSEDOWN ) {
  390. colText = GetUIFColor( UIFCOLOR_MOUSEDOWNTEXT );
  391. }
  392. else if ( dwState & UIFDCS_MOUSEOVER ) {
  393. colText = GetUIFColor( UIFCOLOR_MOUSEOVERTEXT );
  394. }
  395. else if (m_pCandListItem->GetCandidateItem()->GetColor( &colText )) {
  396. }
  397. else {
  398. colText = GetUIFColor( UIFCOLOR_CTRLTEXT );
  399. }
  400. SetTextColor( hDC, colText );
  401. psz = m_pCandListItem->GetCandidateItem()->GetString();
  402. FLTextOutW( hDC, ptOrg.x, ptOrg.y, psz, wcslen(psz) );
  403. GetTextExtent( m_hFont, psz, wcslen( psz ), &size, fHorizontal );
  404. if (fHorizontal) {
  405. ptOrg.x += size.cx;
  406. }
  407. else {
  408. ptOrg.y += size.cx;
  409. }
  410. //
  411. // paint prefix string
  412. //
  413. psz = m_pCandListItem->GetCandidateItem()->GetSuffixString();
  414. if (psz != NULL) {
  415. colText = GetUIFColor( UIFCOLOR_CTRLTEXTDISABLED );
  416. SetTextColor( hDC, colText );
  417. FLTextOutW( hDC, ptOrg.x, ptOrg.y, psz, wcslen(psz) );
  418. GetTextExtent( m_hFont, psz, wcslen( psz ), &size, fHorizontal );
  419. if (fHorizontal) {
  420. ptOrg.x += size.cx;
  421. }
  422. else {
  423. ptOrg.y += size.cx;
  424. }
  425. }
  426. //
  427. // paint cand list item string
  428. //
  429. psz = m_pCandListItem->GetCandidateItem()->GetInlineComment();
  430. if (psz != NULL) {
  431. int cxInlineCommentPos;
  432. int nFontHeight;
  433. SelectObject( hDC, m_hFontInlineComment );
  434. colText = GetUIFColor( UIFCOLOR_CTRLTEXT );
  435. SetTextColor( hDC, colText );
  436. // Don't do things while (m_cxInlineCommentPos < 0)
  437. cxInlineCommentPos = max( m_cxInlineCommentPos, 0 );
  438. // Get the font height.
  439. GetTextExtent( m_hFontInlineComment, L"1", 1, &size, fHorizontal );
  440. nFontHeight = max(size.cx, size.cy);
  441. if (fHorizontal) {
  442. ptOrg.x += cxInlineCommentPos;
  443. ptOrg.y += ( (GetRectRef().bottom - GetRectRef().top) - nFontHeight ) / 2;
  444. FLTextOutW( hDC, ptOrg.x, ptOrg.y, psz, wcslen(psz) );
  445. }
  446. else {
  447. ptOrg.x -= ( (GetRectRef().right - GetRectRef().left) - nFontHeight ) / 2;
  448. ptOrg.y += cxInlineCommentPos;
  449. FLTextOutW( hDC, ptOrg.x, ptOrg.y, psz, wcslen(psz) );
  450. }
  451. }
  452. SetTextColor( hDC, colTextOld );
  453. SetBkMode( hDC, nBkModeOld );
  454. SelectObject( hDC, hFontOld );
  455. // draw button edge
  456. m_pUIFScheme->DrawCtrlEdge( hDC, &rc, UIFDCF_BUTTON, dwState );
  457. }
  458. /*=============================================================================*/
  459. /* */
  460. /* C U I F R O W L I S T */
  461. /* */
  462. /*=============================================================================*/
  463. //
  464. // CUIFRowList
  465. //
  466. /* C U I F R O W L I S T */
  467. /*------------------------------------------------------------------------------
  468. Constructor of CUIFRowList
  469. ------------------------------------------------------------------------------*/
  470. CUIFRowList::CUIFRowList( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFObject( pParent, dwID, prc, dwStyle )
  471. {
  472. m_nItem = 0;
  473. m_pcpCurPage = NULL;
  474. m_iItemSelect = -1;
  475. m_cpPageHead.iPageStart = 0;
  476. m_cpPageHead.nPageSize = 0;
  477. m_cpPageHead.pPrev = NULL;
  478. m_cpPageHead.pNext = NULL;
  479. m_pCandPageUpBtn = NULL;
  480. m_pCandPageDnBtn = NULL;
  481. for (int i = 0; i < NUM_CANDSTR_MAX; i++) {
  482. m_rgpButton[i] = NULL;
  483. }
  484. }
  485. /* ~ C U I F L I S T */
  486. /*------------------------------------------------------------------------------
  487. Destructor of CUIFRowList
  488. ------------------------------------------------------------------------------*/
  489. CUIFRowList::~CUIFRowList( void )
  490. {
  491. CListItemBase *pItem;
  492. while (pItem = m_listItem.GetFirst()) {
  493. m_listItem.Remove(pItem);
  494. delete pItem;
  495. }
  496. ClearPageInfo();
  497. }
  498. /* I N I T I A L I Z E */
  499. /*------------------------------------------------------------------------------
  500. Initialize list object
  501. ------------------------------------------------------------------------------*/
  502. CUIFObject *CUIFRowList::Initialize( void )
  503. {
  504. RECT rc = { 0 };
  505. //
  506. // create candidate page up button
  507. //
  508. m_pCandPageUpBtn = new CUIFSmartPageButton( this, &rc, GetPageUpBtnStyle() );
  509. m_pCandPageUpBtn->Initialize();
  510. AddUIObj( m_pCandPageUpBtn );
  511. //
  512. // create candidate page down button
  513. //
  514. m_pCandPageDnBtn = new CUIFSmartPageButton( this, &rc, GetPageDnBtnStyle() );
  515. m_pCandPageDnBtn->Initialize();
  516. AddUIObj( m_pCandPageDnBtn );
  517. for (int i = 0; i < NUM_CANDSTR_MAX; i++) {
  518. m_rgpButton[i] = new CUIFRowButton( this, 1 + i, GetRowButtonStyle() );
  519. m_rgpButton[i]->Initialize();
  520. AddUIObj( m_rgpButton[i] );
  521. }
  522. return CUIFObject::Initialize();
  523. }
  524. /* S E T S T Y L E */
  525. /*------------------------------------------------------------------------------
  526. ------------------------------------------------------------------------------*/
  527. void CUIFRowList::SetStyle( DWORD dwStyle )
  528. {
  529. RECT rc;
  530. CUIFObject::SetStyle( dwStyle );
  531. // change page button style either
  532. m_pCandPageUpBtn->SetStyle( GetPageUpBtnStyle() );
  533. m_pCandPageDnBtn->SetStyle( GetPageDnBtnStyle() );
  534. for (int i = 0; i < NUM_CANDSTR_MAX; i++) {
  535. m_rgpButton[i]->SetStyle( GetRowButtonStyle() );
  536. }
  537. // set page up button position
  538. GetPageUpBtnRect( &rc );
  539. m_pCandPageUpBtn->SetRect( &rc );
  540. // set page down button position
  541. GetPageDnBtnRect( &rc );
  542. m_pCandPageDnBtn->SetRect( &rc );
  543. // repage
  544. Repage();
  545. // update window
  546. CallOnPaint();
  547. }
  548. /* S E T R E C T */
  549. /*------------------------------------------------------------------------------
  550. ------------------------------------------------------------------------------*/
  551. void CUIFRowList::SetRect( const RECT *prc )
  552. {
  553. RECT rc;
  554. CUIFObject::SetRect( prc );
  555. // set page up button position
  556. GetPageUpBtnRect( &rc );
  557. m_pCandPageUpBtn->SetRect( &rc );
  558. // set page down button position
  559. GetPageDnBtnRect( &rc );
  560. m_pCandPageDnBtn->SetRect( &rc );
  561. // update window
  562. CallOnPaint();
  563. }
  564. /* O N O B J E C T N O T I F Y */
  565. /*------------------------------------------------------------------------------
  566. ------------------------------------------------------------------------------*/
  567. LRESULT CUIFRowList::OnObjectNotify( CUIFObject *pUIObj, DWORD dwCommand, LPARAM lParam )
  568. {
  569. LRESULT lResult = -1;
  570. DWORD dwID = pUIObj->GetID();
  571. if (IDUIF_CANDNUMBUTTON <= dwID && dwID < (DWORD)(IDUIF_CANDNUMBUTTON + NUM_CANDSTR_MAX)) {
  572. switch (dwCommand) {
  573. case UILIST_SELCHANGED: {
  574. SetCurSel( (LONG)(LONG_PTR)(lParam) );
  575. lResult = 0;
  576. break;
  577. }
  578. }
  579. }
  580. else if (pUIObj == m_pCandPageUpBtn) {
  581. switch (dwCommand) {
  582. case UIBUTTON_PRESSED: {
  583. ShiftPage( -1 );
  584. lResult = 0;
  585. break;
  586. }
  587. }
  588. }
  589. else if (pUIObj == m_pCandPageDnBtn) {
  590. switch (dwCommand) {
  591. case UIBUTTON_PRESSED: {
  592. ShiftPage( +1 );
  593. lResult = 0;
  594. break;
  595. }
  596. }
  597. }
  598. if (lResult != 0) {
  599. Assert(m_pParent != NULL);
  600. lResult = m_pParent->OnObjectNotify( pUIObj, dwCommand, lParam );
  601. }
  602. return lResult;
  603. }
  604. /* R E P A G E */
  605. /*------------------------------------------------------------------------------
  606. Refresh the page info link
  607. ------------------------------------------------------------------------------*/
  608. void CUIFRowList::Repage( void )
  609. {
  610. SIZE sizeItem;
  611. BOOL fPageFull;
  612. CANDPAGE *pTrace, *pPageNew;
  613. int nPageLimit, nPageOccupied, nItemOnPage, nItemSize;
  614. CCandListItem *pItem;
  615. BOOL fHorizontal;
  616. ClearPageInfo();
  617. if (IsRectEmpty( &GetRectRef() )) {
  618. return;
  619. }
  620. pItem = (CCandListItem*)m_listItem.GetFirst();
  621. if (pItem == NULL) {
  622. return;
  623. }
  624. nPageOccupied = 0;
  625. nItemOnPage = 0;
  626. fPageFull = FALSE;
  627. pTrace = NULL;
  628. switch (m_dwStyle & UILIST_DIRMASK) {
  629. default:
  630. Assert(FALSE);
  631. case UILIST_HORZTB:
  632. case UILIST_HORZBT: {
  633. fHorizontal = TRUE;
  634. nPageLimit = (GetRectRef().right - GetRectRef().left) - (GetRectRef().bottom - GetRectRef().top) * 2;
  635. break;
  636. }
  637. case UILIST_VERTLR:
  638. case UILIST_VERTRL: {
  639. fHorizontal = FALSE;
  640. nPageLimit = (GetRectRef().bottom - GetRectRef().top) - (GetRectRef().right - GetRectRef().left) * 2;
  641. break;
  642. }
  643. }
  644. //
  645. // Use the object pointed to m_rgpButton[0] for repaging calculation.
  646. //
  647. do {
  648. if (m_rgpButton[nItemOnPage] == NULL) {
  649. ClearPageInfo();
  650. return;
  651. }
  652. m_rgpButton[nItemOnPage]->SetCandListItem( pItem );
  653. m_rgpButton[nItemOnPage]->GetExtent(&sizeItem);
  654. nItemSize = sizeItem.cx;
  655. if ( nPageOccupied + nItemSize > nPageLimit ) {
  656. fPageFull = TRUE;
  657. }
  658. else {
  659. nPageOccupied += nItemSize + HCAND_ITEM_MARGIN;
  660. nItemOnPage++;
  661. // pItem = (CCandListItem*)pItem->GetNext();
  662. int iItem = m_listItem.Find( pItem );
  663. if (0 <= iItem) {
  664. pItem = (CCandListItem*)m_listItem.Get( iItem+1 );
  665. }
  666. else {
  667. pItem = NULL;
  668. }
  669. // Reach the max item limit?
  670. if (nItemOnPage >= NUM_CANDSTR_MAX) {
  671. fPageFull = TRUE;
  672. }
  673. // Reach the end of cand list?
  674. if (pItem == NULL) {
  675. fPageFull = TRUE;
  676. }
  677. }
  678. if (fPageFull) {
  679. //
  680. // Create a new page info node
  681. //
  682. pPageNew = new CANDPAGE;
  683. if (pPageNew == NULL) {
  684. ClearPageInfo();
  685. return;
  686. }
  687. pPageNew->pNext = NULL;
  688. pPageNew->pPrev = pTrace;
  689. if (pTrace != NULL) {
  690. pPageNew->iPageStart = pTrace->iPageStart + pTrace->nPageSize;
  691. pTrace->pNext = pPageNew;
  692. }
  693. else {
  694. pPageNew->iPageStart = 0;
  695. m_cpPageHead.pNext = pPageNew;
  696. }
  697. pPageNew->nPageSize = nItemOnPage;
  698. m_cpPageHead.pPrev = pPageNew;
  699. pTrace = pPageNew;
  700. //
  701. // Restart the accumulation for next page
  702. //
  703. nPageOccupied = 0;
  704. nItemOnPage = 0;
  705. fPageFull = FALSE;
  706. }
  707. } while (pItem != NULL);
  708. m_pcpCurPage = m_cpPageHead.pNext; // Current page is the 1st.
  709. m_iItemSelect = m_pcpCurPage->iPageStart;
  710. // layout current page row buttons position, and page button status
  711. LayoutCurPage();
  712. }
  713. /* S H I F T I T E M */
  714. /*------------------------------------------------------------------------------
  715. shift current item by nItem (+/-)
  716. ------------------------------------------------------------------------------*/
  717. void CUIFRowList::ShiftItem( int nItem )
  718. {
  719. SetCurSel( m_iItemSelect + nItem );
  720. }
  721. /* S H I F T P A G E */
  722. /*------------------------------------------------------------------------------
  723. shift current page by nPage (+/-)
  724. ------------------------------------------------------------------------------*/
  725. void CUIFRowList::ShiftPage( int nPage )
  726. {
  727. CANDPAGE *pPage;
  728. int nPageOffset = nPage;
  729. pPage = m_pcpCurPage;
  730. while (pPage != NULL) {
  731. if (nPageOffset < 0) {
  732. pPage = pPage->pPrev;
  733. nPageOffset++;
  734. }
  735. else if (nPageOffset > 0) {
  736. pPage = pPage->pNext;
  737. nPageOffset--;
  738. }
  739. else {
  740. m_pcpCurPage = pPage;
  741. m_iItemSelect = m_pcpCurPage->iPageStart;
  742. break;
  743. }
  744. }
  745. // layout current page row buttons position, and page button status
  746. LayoutCurPage();
  747. NotifyCommand( UILIST_SELCHANGED, m_iItemSelect );
  748. }
  749. /* G E T P A G E U P B T N R E C T */
  750. /*------------------------------------------------------------------------------
  751. Get page-up button position
  752. ------------------------------------------------------------------------------*/
  753. void CUIFRowList::GetPageUpBtnRect( RECT *prc )
  754. {
  755. Assert( prc != NULL );
  756. GetRect(prc);
  757. switch (m_dwStyle & UILIST_DIRMASK) {
  758. default:
  759. Assert(FALSE);
  760. case UILIST_HORZTB:
  761. case UILIST_HORZBT: {
  762. prc->right -= GetRectRef().bottom - GetRectRef().top;
  763. prc->left = prc->right - (GetRectRef().bottom - GetRectRef().top);
  764. break;
  765. }
  766. case UILIST_VERTLR:
  767. case UILIST_VERTRL: {
  768. prc->bottom -= GetRectRef().right - GetRectRef().left;
  769. prc->top = prc->bottom - (GetRectRef().right - GetRectRef().left);
  770. break;
  771. }
  772. }
  773. }
  774. /* G E T P A G E D O W N B T N R E C T */
  775. /*------------------------------------------------------------------------------
  776. Get page-down button position
  777. ------------------------------------------------------------------------------*/
  778. void CUIFRowList::GetPageDnBtnRect( RECT *prc )
  779. {
  780. Assert( prc != NULL );
  781. GetRect(prc);
  782. switch (m_dwStyle & UILIST_DIRMASK) {
  783. default:
  784. Assert(FALSE);
  785. case UILIST_HORZTB:
  786. case UILIST_HORZBT: {
  787. prc->left = GetRectRef().right - (GetRectRef().bottom - GetRectRef().top);
  788. break;
  789. }
  790. case UILIST_VERTLR:
  791. case UILIST_VERTRL: {
  792. prc->top = GetRectRef().bottom - (GetRectRef().right - GetRectRef().left);
  793. break;
  794. }
  795. }
  796. }
  797. /* S E T F O N T */
  798. /*------------------------------------------------------------------------------
  799. Set font for UI and candidate list
  800. ------------------------------------------------------------------------------*/
  801. void CUIFRowList::SetFont( HFONT hFont )
  802. {
  803. CUIFObject::SetFont( hFont );
  804. // repage
  805. Repage();
  806. // update window
  807. CallOnPaint();
  808. }
  809. /* G E T P A G E U P B T N S T Y L E */
  810. /*------------------------------------------------------------------------------
  811. Get page up button style
  812. ------------------------------------------------------------------------------*/
  813. DWORD CUIFRowList::GetPageUpBtnStyle( void )
  814. {
  815. switch (m_dwStyle) {
  816. default:
  817. Assert(FALSE);
  818. case UILIST_HORZTB:
  819. case UILIST_HORZBT: {
  820. return UISCROLLBUTTON_LEFT;
  821. break;
  822. }
  823. case UILIST_VERTLR:
  824. case UILIST_VERTRL: {
  825. return UISCROLLBUTTON_UP;
  826. }
  827. }
  828. }
  829. /* G E T P A G E D N B T N S T Y L E */
  830. /*------------------------------------------------------------------------------
  831. Get page-down button style
  832. ------------------------------------------------------------------------------*/
  833. DWORD CUIFRowList::GetPageDnBtnStyle( void )
  834. {
  835. switch (m_dwStyle) {
  836. default:
  837. Assert(FALSE);
  838. case UILIST_HORZTB:
  839. case UILIST_HORZBT: {
  840. return UISCROLLBUTTON_RIGHT;
  841. }
  842. case UILIST_VERTLR:
  843. case UILIST_VERTRL: {
  844. return UISCROLLBUTTON_DOWN;
  845. }
  846. }
  847. }
  848. /* G E T R O W B U T T O N S T Y L E */
  849. /*------------------------------------------------------------------------------
  850. Get row button style
  851. ------------------------------------------------------------------------------*/
  852. DWORD CUIFRowList::GetRowButtonStyle( void )
  853. {
  854. switch ( m_dwStyle ) {
  855. default:
  856. Assert(FALSE);
  857. case UILIST_HORZTB:
  858. case UILIST_HORZBT:
  859. return UIBUTTON_PUSH | UIBUTTON_VCENTER | UIBUTTON_LEFT;
  860. case UILIST_VERTLR:
  861. case UILIST_VERTRL:
  862. return UIBUTTON_PUSH | UIBUTTON_CENTER | UIBUTTON_TOP;
  863. }
  864. }
  865. /* C L E A R P A G E I N F O */
  866. /*------------------------------------------------------------------------------
  867. ------------------------------------------------------------------------------*/
  868. void CUIFRowList::ClearPageInfo( void )
  869. {
  870. CANDPAGE *pPage;
  871. while (pPage = m_cpPageHead.pNext) {
  872. m_cpPageHead.pNext = pPage->pNext;
  873. delete pPage;
  874. }
  875. m_cpPageHead.pPrev = NULL;
  876. m_pcpCurPage = NULL;
  877. m_iItemSelect = -1;
  878. }
  879. /* R E L A Y O U T C U R P A G E */
  880. /*------------------------------------------------------------------------------
  881. ------------------------------------------------------------------------------*/
  882. void CUIFRowList::LayoutCurPage( void )
  883. {
  884. int i;
  885. CCandListItem *pItem;
  886. RECT rc;
  887. SIZE size;
  888. if (IsRectEmpty( &GetRectRef() )) {
  889. return;
  890. }
  891. i = 0;
  892. if (m_pcpCurPage != NULL) {
  893. GetRect( &rc );
  894. switch ( m_dwStyle ) {
  895. default:
  896. Assert(FALSE);
  897. case UILIST_HORZTB:
  898. case UILIST_HORZBT:
  899. rc.right = rc.left - HCAND_ITEM_MARGIN;
  900. break;
  901. case UILIST_VERTLR:
  902. case UILIST_VERTRL:
  903. rc.bottom = rc.top - HCAND_ITEM_MARGIN;
  904. break;
  905. }
  906. for (NULL; i < m_pcpCurPage->nPageSize; i++) {
  907. pItem = (CCandListItem*)GetCandItem( m_pcpCurPage->iPageStart + i );
  908. Assert(pItem != NULL);
  909. m_rgpButton[i]->SetCandListItem(pItem);
  910. m_rgpButton[i]->GetExtent( &size );
  911. m_rgpButton[i]->SetSelected( (m_pcpCurPage->iPageStart + i == m_iItemSelect) ? TRUE : FALSE );
  912. switch ( m_dwStyle ) {
  913. default:
  914. Assert(FALSE);
  915. case UILIST_HORZTB:
  916. case UILIST_HORZBT: {
  917. rc.left = rc.right + HCAND_ITEM_MARGIN;
  918. rc.right = rc.left + size.cx;
  919. break;
  920. }
  921. case UILIST_VERTLR:
  922. case UILIST_VERTRL: {
  923. rc.top = rc.bottom + HCAND_ITEM_MARGIN;
  924. rc.bottom = rc.top + size.cx;
  925. break;
  926. }
  927. }
  928. m_rgpButton[i]->SetRect( &rc );
  929. m_rgpButton[i]->Show( TRUE );
  930. }
  931. }
  932. for (NULL; i < NUM_CANDSTR_MAX; i++) {
  933. m_rgpButton[i]->SetSelected( FALSE );
  934. m_rgpButton[i]->Show( FALSE );
  935. }
  936. //
  937. // update paging buttons enable/disable status
  938. //
  939. if (m_pcpCurPage) {
  940. // m_cpPageHead.pPrev is the first page
  941. m_pCandPageUpBtn->Enable( (m_pcpCurPage != m_cpPageHead.pNext) ? TRUE : FALSE );
  942. // m_cpPageHead.pPrev is the last page
  943. m_pCandPageDnBtn->Enable( (m_pcpCurPage != m_cpPageHead.pPrev) ? TRUE : FALSE );
  944. }
  945. else {
  946. m_pCandPageUpBtn->Enable( FALSE );
  947. m_pCandPageDnBtn->Enable( FALSE );
  948. }
  949. // update window
  950. CallOnPaint();
  951. }
  952. /* S E T I N L I N E C O M M E N T F O N T */
  953. /*------------------------------------------------------------------------------
  954. Set font for inline comment
  955. ------------------------------------------------------------------------------*/
  956. void CUIFRowList::SetInlineCommentFont( HFONT hFont )
  957. {
  958. if (hFont == NULL) {
  959. hFont = (HFONT)GetStockObject( DEFAULT_GUI_FONT );
  960. }
  961. for (int i = 0; i < NUM_CANDSTR_MAX; i++) {
  962. if (m_rgpButton[i] != NULL) {
  963. m_rgpButton[i]->SetInlineCommentFont( hFont );
  964. }
  965. }
  966. // repage
  967. Repage();
  968. // update window
  969. CallOnPaint();
  970. }
  971. /* S E T I N L I N E C O M M E N T P O S */
  972. /*------------------------------------------------------------------------------
  973. Set (horizontal) position to draw inline comment
  974. NOTE: if cx has negative value, inline comment will be on the left of item text.
  975. ------------------------------------------------------------------------------*/
  976. void CUIFRowList::SetInlineCommentPos( int cx )
  977. {
  978. for (int i = 0; i < NUM_CANDSTR_MAX; i++) {
  979. if (m_rgpButton[i] != NULL) {
  980. m_rgpButton[i]->SetInlineCommentPos( cx );
  981. }
  982. }
  983. // repage
  984. Repage();
  985. // update window
  986. CallOnPaint();
  987. }
  988. /* S E T I N D E X F O N T */
  989. /*------------------------------------------------------------------------------
  990. Set font for index
  991. ------------------------------------------------------------------------------*/
  992. void CUIFRowList::SetIndexFont( HFONT hFont )
  993. {
  994. }
  995. /* A D D C A N D I T E M */
  996. /*------------------------------------------------------------------------------
  997. ------------------------------------------------------------------------------*/
  998. int CUIFRowList::AddCandItem( CCandListItem *pCandListItem )
  999. {
  1000. int nId = m_nItem;
  1001. m_listItem.Add( pCandListItem );
  1002. m_nItem++;
  1003. return nId;
  1004. }
  1005. /* S E T C A N D L I S T */
  1006. /*------------------------------------------------------------------------------
  1007. Set candidate list
  1008. ------------------------------------------------------------------------------*/
  1009. void CUIFRowList::SetCandList( CCandidateList *pCandList )
  1010. {
  1011. int nCandItem;
  1012. int i;
  1013. CCandidateItem *pCandItem;
  1014. ASSERT( pCandList );
  1015. nCandItem = pCandList->GetItemCount();
  1016. for (i = 0; i < nCandItem; i++) {
  1017. pCandItem = pCandList->GetCandidateItem( i );
  1018. if (pCandItem->IsVisible()) {
  1019. CCandListItem *pCandListItem = new CCandListItem( GetItemCount(), i, pCandItem );
  1020. AddCandItem( pCandListItem );
  1021. }
  1022. }
  1023. // update page info
  1024. Repage();
  1025. // update window
  1026. CallOnPaint();
  1027. return;
  1028. }
  1029. /* S E T C U R S E L */
  1030. /*------------------------------------------------------------------------------
  1031. ------------------------------------------------------------------------------*/
  1032. void CUIFRowList::SetCurSel( int iSelection )
  1033. {
  1034. CANDPAGE *pPage;
  1035. m_iItemSelect = min(iSelection, m_nItem - 1);
  1036. m_iItemSelect = max(0, m_iItemSelect);
  1037. pPage = m_pcpCurPage;
  1038. while (pPage != NULL) {
  1039. if (m_iItemSelect < pPage->iPageStart) {
  1040. pPage = pPage->pPrev;
  1041. }
  1042. else if (m_iItemSelect >= pPage->iPageStart + pPage->nPageSize) {
  1043. pPage = pPage->pNext;
  1044. }
  1045. else {
  1046. m_pcpCurPage = pPage;
  1047. break;
  1048. }
  1049. }
  1050. // layout current page row buttons position, and page button status
  1051. LayoutCurPage();
  1052. NotifyCommand( UILIST_SELCHANGED, m_iItemSelect );
  1053. }
  1054. /* D E L A L L C A N D I T E M */
  1055. /*------------------------------------------------------------------------------
  1056. ------------------------------------------------------------------------------*/
  1057. void CUIFRowList::DelAllCandItem( void )
  1058. {
  1059. CListItemBase *pItem;
  1060. while (pItem = m_listItem.GetFirst()) {
  1061. m_listItem.Remove(pItem);
  1062. delete pItem;
  1063. m_nItem--;
  1064. }
  1065. Assert(!m_nItem);
  1066. m_pcpCurPage = NULL;
  1067. m_iItemSelect = -1;
  1068. // layout current page row buttons position, and page button status
  1069. LayoutCurPage();
  1070. }
  1071. /* G E T C A N D I T E M */
  1072. /*------------------------------------------------------------------------------
  1073. ------------------------------------------------------------------------------*/
  1074. CCandListItem *CUIFRowList::GetCandItem( int nId )
  1075. {
  1076. int nItem;
  1077. int i;
  1078. CListItemBase *pItem;
  1079. nItem = m_listItem.GetCount();
  1080. for (i = 0; i < nItem; i++) {
  1081. pItem = m_listItem.Get( i );
  1082. if (nId == (int)((CCandListItem*)pItem)->GetIListItem()) {
  1083. return (CCandListItem*)pItem;
  1084. }
  1085. }
  1086. return NULL;
  1087. }
  1088. /* G E T C U R S E L */
  1089. /*------------------------------------------------------------------------------
  1090. ------------------------------------------------------------------------------*/
  1091. int CUIFRowList::GetCurSel( void )
  1092. {
  1093. return m_iItemSelect;
  1094. }
  1095. /* G E T T O P I T E M */
  1096. /*------------------------------------------------------------------------------
  1097. ------------------------------------------------------------------------------*/
  1098. int CUIFRowList::GetTopItem( void )
  1099. {
  1100. if (m_pcpCurPage != NULL) {
  1101. return m_pcpCurPage->iPageStart;
  1102. }
  1103. else {
  1104. return -1;
  1105. }
  1106. }
  1107. /* G E T B O T O M I T E M */
  1108. /*------------------------------------------------------------------------------
  1109. ------------------------------------------------------------------------------*/
  1110. int CUIFRowList::GetBottomItem( void )
  1111. {
  1112. if (m_pcpCurPage != NULL) {
  1113. return m_pcpCurPage->iPageStart + m_pcpCurPage->nPageSize;
  1114. }
  1115. else {
  1116. return -1;
  1117. }
  1118. }
  1119. /* I S V I S I B L E */
  1120. /*------------------------------------------------------------------------------
  1121. ------------------------------------------------------------------------------*/
  1122. BOOL CUIFRowList::IsVisible( void )
  1123. {
  1124. return CUIFObject::IsVisible();
  1125. }
  1126. /* G E T R E C T */
  1127. /*------------------------------------------------------------------------------
  1128. ------------------------------------------------------------------------------*/
  1129. void CUIFRowList::GetRect( RECT *prc )
  1130. {
  1131. CUIFObject::GetRect( prc );
  1132. }
  1133. /* G E T I T E M R E C T */
  1134. /*------------------------------------------------------------------------------
  1135. ------------------------------------------------------------------------------*/
  1136. void CUIFRowList::GetItemRect( int iItem, RECT *prc )
  1137. {
  1138. Assert( prc != NULL );
  1139. ::SetRect( prc, 0, 0, 0, 0 );
  1140. if (GetTopItem() <= iItem && iItem <= GetBottomItem()) {
  1141. int iButton = iItem - GetTopItem();
  1142. if ((0 <= iButton && iButton < NUM_CANDSTR_MAX) && m_rgpButton[iButton]->IsVisible()) {
  1143. m_rgpButton[iButton]->GetRect( prc );
  1144. }
  1145. }
  1146. }
  1147. /* G E T I T E M C O U N T */
  1148. /*------------------------------------------------------------------------------
  1149. Returns number of candidate item
  1150. (CUIFCandListBase method)
  1151. ------------------------------------------------------------------------------*/
  1152. int CUIFRowList::GetItemCount( void )
  1153. {
  1154. return m_nItem;
  1155. }
  1156. /* I S I T E M S E L E C T A B L E */
  1157. /*------------------------------------------------------------------------------
  1158. Returns TRUE, if candidate item with given index could be selected.
  1159. Otherwise, returns FALSE.
  1160. (CUIFCandListBase method)
  1161. ------------------------------------------------------------------------------*/
  1162. BOOL CUIFRowList::IsItemSelectable( int iListItem )
  1163. {
  1164. // Satori#3632(Cicero#3413)
  1165. if (m_pcpCurPage == NULL) {
  1166. return FALSE;
  1167. }
  1168. if ( iListItem < m_pcpCurPage->iPageStart ) {
  1169. } else if ((m_pcpCurPage->iPageStart + m_pcpCurPage->nPageSize) <= iListItem) {
  1170. } else {
  1171. return TRUE;
  1172. }
  1173. return FALSE;
  1174. }