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.

1710 lines
43 KiB

  1. /**************************************************/
  2. /* */
  3. /* */
  4. /* EUDC Character List ( Japan, China, Korea) */
  5. /* */
  6. /* */
  7. /* Copyright (c) 1997-1999 Microsoft Corporation. */
  8. /**************************************************/
  9. #include "stdafx.h"
  10. #include "eudcedit.h"
  11. #include "eudclist.h"
  12. #include "util.h"
  13. #define STRSAFE_LIB
  14. #include <strsafe.h>
  15. #ifdef BUILD_ON_WINNT
  16. #include "extfunc.h"
  17. #endif // BUILD_ON_WINNT
  18. /* Matrics of Characterlist */
  19. #define NUM_CHAR 16 // Row of matrics
  20. #define NUM_LINE 6 // Line of matrics
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char BASED_CODE THIS_FILE[] = __FILE__;
  24. #endif
  25. IMPLEMENT_DYNCREATE( CEudcList, CEdit)
  26. BEGIN_MESSAGE_MAP( CEudcList, CEdit)
  27. //{{AFX_MSG_MAP( CEudcList)
  28. ON_WM_PAINT()
  29. ON_WM_VSCROLL()
  30. ON_WM_LBUTTONDOWN()
  31. ON_WM_LBUTTONDBLCLK()
  32. ON_WM_SETCURSOR()
  33. ON_WM_KEYDOWN()
  34. ON_WM_SETFOCUS()
  35. ON_WM_KILLFOCUS()
  36. ON_WM_RBUTTONUP()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. #ifdef BUILD_ON_WINNT
  40. static CRect rcColumnHead[NUM_CHAR];
  41. #endif //BUILD_ON_WINNT
  42. static CRect rcEditChar[NUM_LINE][NUM_CHAR];
  43. static CRect rcEditCode[NUM_LINE];
  44. static BYTE ViewCode[NUM_LINE];
  45. static BOOL bHasGlyph;
  46. #define EUDCCODEBASE ((unsigned short)0xe000)
  47. /****************************************/
  48. /* */
  49. /* Default Constructor */
  50. /* */
  51. /****************************************/
  52. CEudcList::CEudcList()
  53. {
  54. // Initialize parameter( Japan, China and Korea)
  55. SetInitEUDCCodeRange( CountryInfo.CurrentRange);
  56. FocusFlag = FALSE;
  57. }
  58. /****************************************/
  59. /* */
  60. /* Set coderange of EUDC */
  61. /* */
  62. /****************************************/
  63. void
  64. CEudcList::SetInitEUDCCodeRange(
  65. int nIndex)
  66. {
  67. if ( (nIndex >= ARRAYLEN(CountryInfo.sRange)) || (nIndex >= ARRAYLEN(CountryInfo.eRange)))
  68. {
  69. return;
  70. }
  71. m_Index = nIndex;
  72. EUDC_SCode = CountryInfo.sRange[m_Index];
  73. EUDC_ECode = CountryInfo.eRange[m_Index];
  74. EUDC_EView =(CountryInfo.eRange[m_Index] & 0xfff0) -(0x10*(NUM_LINE-1));
  75. if( SelectEUDC.m_Code[0] != '\0'){
  76. SelectCode = (WORD)Mytcstol(SelectEUDC.m_Code, (TCHAR **)0, 16);
  77. EUDC_SView = (WORD)Mytcstol(SelectEUDC.m_Code, (TCHAR **)0, 16);
  78. EUDC_SView &= 0xfff0;
  79. if( EUDC_EView <= EUDC_SView)
  80. EUDC_SView = EUDC_EView;
  81. }else{
  82. EUDC_SView = CountryInfo.sRange[m_Index] & 0xfff0;
  83. SelectCode = EUDC_SCode;
  84. }
  85. #ifdef BUILD_ON_WINNT
  86. //In case of CHS, each range will have a different trail byte range
  87. //after user selects a new range, we have to correct them with
  88. //sOrigTralByte and eOrigTralByte and form new trail byte range.
  89. if (CountryInfo.LangID == EUDC_CHS && !CountryInfo.bUnicodeMode)
  90. CorrectTrailByteRange(m_Index);
  91. #endif // BUILD_ON_WINNT
  92. LButtonPt.x = LButtonPt.y = 0;
  93. ScrlBarPos = (short)GetBarPosition( EUDC_SView);
  94. this->SetScrollPos( SB_VERT, ScrlBarPos, TRUE);
  95. }
  96. /****************************************/
  97. /* */
  98. /* Set coderange of EUDC */
  99. /* */
  100. /****************************************/
  101. void
  102. CEudcList::SetEUDCCodeRange(
  103. int nIndex)
  104. {
  105. if ( (nIndex >= ARRAYLEN(CountryInfo.sRange)) || (nIndex >= ARRAYLEN(CountryInfo.eRange)))
  106. {
  107. return;
  108. }
  109. m_Index = nIndex;
  110. EUDC_SView = CountryInfo.sRange[m_Index] & 0xfff0;
  111. EUDC_EView =(CountryInfo.eRange[m_Index] & 0xfff0) -(0x10*(NUM_LINE-1));
  112. EUDC_SCode = CountryInfo.sRange[m_Index];
  113. EUDC_ECode = CountryInfo.eRange[m_Index];
  114. #ifdef BUILD_ON_WINNT
  115. //In case of CHS, each range will have a different trail byte range
  116. //after user selects a new range, we have to correct them with
  117. //sOrigTralByte and eOrigTralByte and form new trail byte range.
  118. if (CountryInfo.LangID == EUDC_CHS && !CountryInfo.bUnicodeMode)
  119. CorrectTrailByteRange(m_Index);
  120. #endif // BUILD_ON_WINNT
  121. SelectCode = (WORD)EUDC_SCode;
  122. LButtonPt.x = LButtonPt.y = 0;
  123. ScrlBarPos = (short)0;
  124. this->SetScrollPos( SB_VERT, ScrlBarPos, TRUE);
  125. }
  126. /****************************************/
  127. /* */
  128. /* Destructor */
  129. /* */
  130. /****************************************/
  131. CEudcList::~CEudcList()
  132. {
  133. SysFFont.DeleteObject();
  134. EUDCFont.DeleteObject();
  135. }
  136. /****************************************/
  137. /* */
  138. /* Correct it if code is illegal */
  139. /* */
  140. /****************************************/
  141. WORD
  142. CEudcList::CorrectEUDCCode(
  143. WORD Code,
  144. BOOL UporDown)
  145. {
  146. COUNTRYINFO Info;
  147. WORD wCode;
  148. BYTE LByte, HByte;
  149. int TralPos = 0;
  150. LByte = LOBYTE( Code);
  151. HByte = HIBYTE( Code);
  152. Info = CountryInfo;
  153. //decide code falls in which trail byte range
  154. for( int i = 0; i < Info.nTralByte; i++){
  155. if( LByte >= (Info.sTralByte[i] & 0xf0) &&
  156. LByte <= (Info.eTralByte[i] & 0xf0)){
  157. goto RET;
  158. }else if( LByte < (Info.sTralByte[i] & 0xf0)){
  159. TralPos = i;
  160. break;
  161. }else TralPos = i+1;
  162. }
  163. #ifdef BUILD_ON_WINNT
  164. // If we are going up on the code range, make the code in the first
  165. // first line of next valid trailbyte. Otherwise make the code in
  166. // the last line the preivous valid range.
  167. if( UporDown){
  168. if( TralPos == Info.nTralByte){
  169. TralPos =0;
  170. HByte += 0x1;
  171. }
  172. LByte = Info.sTralByte[TralPos] & 0xf0;
  173. }else{
  174. if( TralPos ==0 ){
  175. HByte -= 0x1;
  176. TralPos = Info.nTralByte;
  177. }
  178. LByte = Info.eTralByte[TralPos-1] & 0xf0;
  179. }
  180. #else
  181. if( UporDown)
  182. if( TralPos == Info.nTralByte){
  183. LByte = (Info.sTralByte[0] & 0xf0);
  184. HByte += 0x1;
  185. }else LByte = (Info.sTralByte[TralPos] & 0xf0);
  186. else{
  187. if( !TralPos){
  188. LByte = (Info.eTralByte[Info.nTralByte-1] & 0xf0);
  189. HByte -= 0x1;
  190. }else LByte = (Info.eTralByte[TralPos-1] & 0xf0);
  191. }
  192. #endif // BUILD_ON_WINNT
  193. RET:
  194. wCode = MAKEWORD( LByte, HByte);
  195. return wCode;
  196. }
  197. /****************************************/
  198. /* */
  199. /* Get position of scrollbar */
  200. /* */
  201. /****************************************/
  202. #ifdef BUILD_ON_WINNT
  203. int
  204. CEudcList::GetBarPosition(
  205. WORD Code)
  206. {
  207. COUNTRYINFO Info;
  208. WORD NumPage=0, NumCode=0;
  209. BYTE Space[MAX_LEADBYTES];
  210. int TotalSpace=0,TralPos=0;
  211. int Err;
  212. BOOL ValidCode=FALSE;
  213. Info = CountryInfo;
  214. NumPage = HIBYTE( Code) - HIBYTE( EUDC_SCode);
  215. // Calculate each code space block for each trail byte range
  216. // and decide how many of each we count.
  217. /* space before first trailbyte range */
  218. Space[0] = ( Info.sTralByte[0] & 0xf0);
  219. for( int i = 1; i < Info.nTralByte; i++){
  220. Space[i] = (( Info.sTralByte[i] & 0xf0)
  221. - ( Info.eTralByte[i-1] & 0xf0) - 0x10);
  222. }
  223. /* space after last trailbyte range */
  224. Space[i] = (0xff - Info.eTralByte[Info.nTralByte-1]) & 0xf0;
  225. for (i = 0; i < Info.nTralByte; i++)
  226. if( LOBYTE( Code) >= (Info.sTralByte[i] & 0xf0) &&
  227. LOBYTE( Code) <= (Info.eTralByte[i] & 0xff)){
  228. ValidCode=TRUE; //within our trail byte range.
  229. TralPos=i;
  230. break;
  231. }
  232. if (!ValidCode)
  233. return(0); //not within our trail byte range.
  234. for (i = 0; i < Info.nTralByte; i++){
  235. if (Info.sTralByte[TralPos] > LOBYTE( EUDC_SCode )){
  236. if((Info.sTralByte[i]) > LOBYTE(EUDC_SCode) && i <= TralPos)
  237. TotalSpace += Space[i] * (NumPage + 1);
  238. else
  239. TotalSpace += Space[i] * NumPage ;
  240. }else{
  241. if((Info.sTralByte[i] & 0xf0) < LOBYTE(EUDC_SCode) && i > TralPos)
  242. TotalSpace += Space[i] * (NumPage - 1);
  243. else
  244. TotalSpace += Space[i] * NumPage ;
  245. }
  246. }
  247. TotalSpace += Space[i] * NumPage;
  248. Err = EUDC_SCode & 0x000f;
  249. NumCode = Code - EUDC_SCode - TotalSpace + Err;
  250. return( NumCode /NUM_CHAR);
  251. }
  252. #else
  253. int
  254. CEudcList::GetBarPosition(
  255. WORD Code)
  256. {
  257. COUNTRYINFO Info;
  258. WORD NumPage, NumCode;
  259. BYTE Space[MAX_LEADBYTES];
  260. int LoSpace, HiSpace;
  261. int Err;
  262. Info = CountryInfo;
  263. NumPage = HIBYTE( Code) - HIBYTE( EUDC_SCode);
  264. Space[0] = ( Info.sTralByte[0] & 0xf0);
  265. Space[1] = 0x00;
  266. for( int i = 1; i < Info.nTralByte; i++){
  267. Space[i] = (( Info.sTralByte[i] & 0xf0)
  268. - ( Info.eTralByte[i-1] & 0xf0) - 0x10);
  269. }
  270. for( i = 0; i < Info.nTralByte; i++){
  271. if( LOBYTE( Code) >= (Info.sTralByte[i] & 0xf0) &&
  272. LOBYTE( Code) <= (Info.eTralByte[i] & 0xff)){
  273. if( LOBYTE( EUDC_SCode) > Info.sTralByte[0]){
  274. LoSpace = ( Space[0] * NumPage);
  275. HiSpace = ( Space[1] * (i + NumPage - 1));
  276. }else{
  277. LoSpace = ( Space[0] * NumPage);
  278. HiSpace = ( Space[1] * (i + NumPage));
  279. }
  280. Err = EUDC_SCode & 0x000f;
  281. NumCode = Code - EUDC_SCode - LoSpace - HiSpace + Err;
  282. break;
  283. }
  284. }
  285. return( NumCode /NUM_CHAR);
  286. }
  287. #endif // BUILD_ON_WINNT
  288. /****************************************/
  289. /* */
  290. /* Calculate bar pos from code */
  291. /* */
  292. /****************************************/
  293. WORD
  294. CEudcList::GetCodeScrPos(
  295. int Pos)
  296. {
  297. WORD i;
  298. WORD Code = 0;
  299. WORD NumLine = 0;
  300. WORD PNumLine = 0;
  301. if( !Pos)
  302. return( EUDC_SCode & 0xfff0);
  303. #ifdef BUILD_ON_WINNT
  304. // we dont't need to go through each char, instead we can examine each
  305. // line to make this faster
  306. for( i = EUDC_SCode; i <= EUDC_ECode; i+= NUM_CHAR){
  307. #else
  308. for( i = EUDC_SCode; i <= EUDC_ECode; ++i){
  309. #endif // BUILD_ON_WINNT
  310. NumLine = (WORD)GetBarPosition( i);
  311. if( NumLine >= Pos){
  312. NumLine = PNumLine;
  313. break;
  314. }
  315. PNumLine = NumLine;
  316. }
  317. Code = i;
  318. Pos -= NumLine;
  319. Code &= 0xfff0;
  320. return Code;
  321. }
  322. #define FIX_SPACE 6
  323. #define LINEWIDTH 4
  324. /****************************************/
  325. /* */
  326. /* Calcurate character size */
  327. /* */
  328. /****************************************/
  329. void
  330. CEudcList::CalcCharSize()
  331. {
  332. TCHAR Dummy[] = TEXT("FA40");
  333. int Sx;
  334. int OldMode;
  335. CClientDC dc( this);
  336. this->GetClientRect( &EditListRect);
  337. OldMode = dc.SetMapMode( MM_TEXT);
  338. CFont *OldFont = dc.SelectObject( &SysFFont);
  339. GetTextExtentPoint32( dc.GetSafeHdc(), Dummy, 4, &FixSize);
  340. FixSize.cx += FIX_SPACE;
  341. dc.SelectObject( OldFont);
  342. CharSize.cy = ( EditListRect.Height()
  343. - (NUM_LINE-1)*LINEWIDTH - 2) / NUM_LINE;
  344. CharSize.cx = ( EditListRect.Width()
  345. - FixSize.cx - 2 - (NUM_CHAR*LINEWIDTH)) / NUM_CHAR;
  346. for( int i = 0; i < NUM_LINE; i++){
  347. rcEditCode[i].left = 1;
  348. rcEditCode[i].top = 1 + i*( CharSize.cy + LINEWIDTH);
  349. rcEditCode[i].right = rcEditCode[i].left + FixSize.cx;
  350. rcEditCode[i].bottom = rcEditCode[i].top + CharSize.cy;
  351. Sx = rcEditCode[i].right + LINEWIDTH;
  352. for( int j = 0; j < NUM_CHAR; j++){
  353. rcEditChar[i][j].left = Sx +j*(CharSize.cx+LINEWIDTH);
  354. rcEditChar[i][j].top = rcEditCode[i].top;
  355. rcEditChar[i][j].right = rcEditChar[i][j].left
  356. + CharSize.cx;
  357. rcEditChar[i][j].bottom = rcEditChar[i][j].top
  358. + CharSize.cy;
  359. }
  360. }
  361. #ifdef BUILD_ON_WINNT
  362. for( int j = 0; j < NUM_CHAR; j++){
  363. rcColumnHead[j].left = Sx +j*(CharSize.cx+LINEWIDTH);
  364. rcColumnHead[j].top = 1;
  365. rcColumnHead[j].right = rcColumnHead[j].left + CharSize.cx;
  366. rcColumnHead[j].bottom = 1 + FixSize.cy;
  367. }
  368. #endif //BUILD_ON_WINNT
  369. dc.SetMapMode( MM_TEXT);
  370. }
  371. /****************************************/
  372. /* */
  373. /* MESSAGE "WM_PAINT" */
  374. /* */
  375. /****************************************/
  376. void
  377. CEudcList::OnPaint()
  378. {
  379. register int i, j, k;
  380. WORD Code;
  381. CFont *OldFont;
  382. BYTE Glyph[800];
  383. BOOL bGlyph = FALSE;
  384. HRESULT hresult;
  385. CPaintDC dc( this);
  386. int BottomCode = GetBarPosition((WORD)EUDC_EView);
  387. SetScrollRange( SB_VERT, 0, BottomCode, FALSE);
  388. this->SetScrollPos( SB_VERT, ScrlBarPos, TRUE);
  389. Code = EUDC_SView;
  390. int OldMapMode = dc.SetMapMode( MM_TEXT);
  391. dc.SetViewportOrg( 0, 0);
  392. OldFont = dc.SelectObject( &SysFFont);
  393. //
  394. // access *.euf to set bits in the array (800 * 8 = 6400)
  395. // to indicate a char has a glyph
  396. //
  397. bGlyph = GetGlyph(SelectEUDC.m_File, Glyph);
  398. for( i = 0; i < NUM_LINE; i++){
  399. BYTE CodeArray[10];
  400. int xOffset, yOffset;
  401. // Check character code
  402. dc.SelectObject( &SysFFont);
  403. Code = CorrectEUDCCode( Code, TRUE);
  404. //*STRSAFE* wsprintf((LPTSTR)CodeArray, TEXT("%04X"), Code);
  405. hresult = StringCbPrintf((LPTSTR)CodeArray , sizeof(CodeArray), TEXT("%04X"), Code);
  406. if (!SUCCEEDED(hresult))
  407. {
  408. return ;
  409. }
  410. dc.SetBkColor( COLOR_FACE);
  411. dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); // COLOR_BLACK);
  412. if( rcEditChar[i][0].Height() > FixSize.cy){
  413. yOffset = ( rcEditChar[i][0].Height() - FixSize.cy) /2;
  414. }else yOffset = 0;
  415. ExtTextOut( dc.GetSafeHdc(), rcEditCode[i].left,
  416. rcEditCode[i].top + yOffset,
  417. ETO_OPAQUE, &rcEditCode[i],
  418. (LPCTSTR)CodeArray, 4, NULL);
  419. dc.SelectObject( &EUDCFont);
  420. for( j = 0; j < NUM_CHAR; j++,Code++){
  421. BYTE sOffset;
  422. CSize cSize;
  423. BOOL flg;
  424. int wLength;
  425. //
  426. // see if the character has a glyph
  427. //
  428. bHasGlyph = TRUE;
  429. if(bGlyph == TRUE)
  430. {
  431. WORD wIndex;
  432. if (CountryInfo.bUnicodeMode)
  433. wIndex = Code - EUDCCODEBASE;
  434. else
  435. {
  436. CHAR pchar[3];
  437. WCHAR wpchar[2];
  438. pchar[0] = HIBYTE(Code);
  439. pchar[1] = LOBYTE(Code);
  440. pchar[2] = 0;
  441. MultiByteToWideChar(CP_ACP, 0, pchar, 2, wpchar, 1);
  442. wIndex = wpchar[0] - EUDCCODEBASE;
  443. }
  444. if((Glyph[wIndex>>3] & (0x80>>(wIndex%8))) == 0)
  445. bHasGlyph = FALSE;
  446. }
  447. //fix for FontIsLinked
  448. else
  449. bHasGlyph = FALSE;
  450. //
  451. flg = FALSE;
  452. sOffset = LOBYTE( Code);
  453. for( k = 0; k < CountryInfo.nTralByte; k++){
  454. if( sOffset >= CountryInfo.sTralByte[k] &&
  455. sOffset <= CountryInfo.eTralByte[k]){
  456. flg = TRUE;
  457. }
  458. }
  459. if((Code < CountryInfo.sRange[cRange])
  460. ||(Code > CountryInfo.eRange[cRange]))
  461. flg = FALSE;
  462. if( !flg) continue;
  463. if (CountryInfo.bUnicodeMode){
  464. CodeArray[1] = HIBYTE(Code);
  465. CodeArray[0] = LOBYTE(Code);
  466. wLength = 1;
  467. }
  468. else{
  469. CodeArray[0] = HIBYTE(Code);
  470. CodeArray[1] = LOBYTE(Code);
  471. wLength = 2;
  472. }
  473. CodeArray[2] = (BYTE)'\0';
  474. BOOL PtIn;
  475. if(( rcEditChar[i][j].PtInRect( LButtonPt) ||
  476. SelectCode == Code) && wLength != 0){
  477. TCHAR CodeNum[10];
  478. // If character is selected by left clickking ,
  479. // Put it on dialog.
  480. PtIn = TRUE;
  481. SelectCode = Code;
  482. dc.SetBkColor(COLOR_FACE);
  483. dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); // COLOR_BLACK);
  484. //*STRSAFE* wsprintf(CodeNum, TEXT("%04X"),Code);
  485. hresult = StringCchPrintf(CodeNum , ARRAYLEN(CodeNum), TEXT("%04X"),Code);
  486. if (!SUCCEEDED(hresult))
  487. {
  488. return ;
  489. }
  490. GetParent()->SetDlgItemText(IDC_CODECUST,CodeNum);
  491. if (CountryInfo.bUnicodeMode)
  492. {
  493. //*STRSAFE* lstrcpyW((WCHAR *)ViewCode, (WCHAR *)CodeArray);
  494. hresult = StringCbCopyW((WCHAR *)ViewCode, sizeof(ViewCode), (WCHAR *)CodeArray);
  495. if (!SUCCEEDED(hresult))
  496. {
  497. return ;
  498. }
  499. }
  500. else
  501. {
  502. //*STRSAFE* lstrcpyA((CHAR *)ViewCode, (CHAR *)CodeArray);
  503. hresult = StringCbCopyA((CHAR *)ViewCode, sizeof(ViewCode), (CHAR *)CodeArray);
  504. if (!SUCCEEDED(hresult))
  505. {
  506. return ;
  507. }
  508. }
  509. GetParent()->SendMessage( WM_VIEWUPDATE, 0, 0);
  510. }else{
  511. PtIn = FALSE;
  512. dc.SetBkColor( COLOR_FACE);
  513. dc.SetTextColor( GetSysColor(COLOR_WINDOWTEXT)); //COLOR_BLACK);
  514. }
  515. if (CountryInfo.bUnicodeMode)
  516. GetTextExtentPoint32W( dc.GetSafeHdc(), (LPCWSTR)CodeArray, wLength, &cSize);
  517. else
  518. GetTextExtentPoint32A( dc.GetSafeHdc(), (LPCSTR)CodeArray, wLength, &cSize);
  519. if( rcEditChar[i][j].Width() > cSize.cx){
  520. xOffset = rcEditChar[i][j].Width() - cSize.cx;
  521. xOffset /= 2;
  522. }else xOffset = 0;
  523. if( rcEditChar[i][j].Height() > cSize.cy){
  524. yOffset = rcEditChar[i][j].Height() - cSize.cy;
  525. yOffset /= 2;
  526. }else yOffset = 0;
  527. if(bHasGlyph == TRUE)
  528. {
  529. if (CountryInfo.bUnicodeMode)
  530. {
  531. #ifdef UNICODE
  532. ExtTextOutW(dc.GetSafeHdc(),rcEditChar[i][j].left + xOffset,
  533. rcEditChar[i][j].top + yOffset, ETO_OPAQUE,
  534. &rcEditChar[i][j], (LPCWSTR)CodeArray, wLength, NULL);
  535. #else
  536. CHAR ViewTmp[2];
  537. wLength = WideCharToMultiByte(CP_ACP, 0, (LPWSTR) CodeArray, 1, ViewTmp, 2, NULL, NULL);
  538. ExtTextOutA(dc.GetSafeHdc(),rcEditChar[i][j].left + xOffset,
  539. rcEditChar[i][j].top + yOffset, ETO_OPAQUE,
  540. &rcEditChar[i][j], (LPCSTR)ViewTmp, wLength, NULL);
  541. #endif
  542. }
  543. else
  544. {
  545. ExtTextOutA(dc.GetSafeHdc(), rcEditChar[i][j].left + xOffset,
  546. rcEditChar[i][j].top + yOffset, ETO_OPAQUE,
  547. &rcEditChar[i][j], (LPCSTR)CodeArray,
  548. wLength, NULL);
  549. }
  550. }
  551. DrawConcave( &dc, rcEditChar[i][j], PtIn);
  552. }
  553. }
  554. dc.SetMapMode( OldMapMode);
  555. dc.SelectObject( OldFont);
  556. LButtonPt.x = LButtonPt.y = 0;
  557. }
  558. /****************************************/
  559. /* */
  560. /* MESSAGE "WM_VSCROLL" */
  561. /* */
  562. /****************************************/
  563. void
  564. CEudcList::OnVScroll(
  565. UINT nSBCode,
  566. UINT nPos,
  567. CScrollBar* pScrollBar)
  568. {
  569. int MoveScr;
  570. BOOL ThumbTrkFlag;
  571. BOOL ThumbPosFlag;
  572. MoveScr = 0;
  573. ThumbTrkFlag = FALSE;
  574. ThumbPosFlag = FALSE;
  575. BarRange = GetBarPosition((WORD)EUDC_EView);
  576. SetScrollRange( SB_VERT, 0, BarRange, FALSE);
  577. switch( nSBCode)
  578. {
  579. case SB_LINEDOWN:
  580. if(( EUDC_SView + NUM_CHAR) <= EUDC_EView){
  581. MoveScr = 0 - (CharSize.cy + LINEWIDTH);
  582. EUDC_SView += NUM_CHAR;
  583. EUDC_SView = CorrectEUDCCode(EUDC_SView,TRUE);
  584. ScrlBarPos = (short)GetBarPosition( EUDC_SView);
  585. }
  586. break;
  587. case SB_LINEUP:
  588. if(( EUDC_SView - NUM_CHAR) >= ( EUDC_SCode & 0xfff0)){
  589. MoveScr = CharSize.cy + LINEWIDTH;
  590. EUDC_SView -= NUM_CHAR;
  591. EUDC_SView = CorrectEUDCCode(EUDC_SView,FALSE);
  592. ScrlBarPos = (short)GetBarPosition( EUDC_SView);
  593. }
  594. break;
  595. case SB_PAGEDOWN:
  596. if(( EUDC_SView + NUM_CHAR*NUM_LINE) <= EUDC_EView){
  597. MoveScr = ( 0-(CharSize.cy+LINEWIDTH))*NUM_LINE;
  598. ScrlBarPos = (short)GetBarPosition( EUDC_SView);
  599. ScrlBarPos += NUM_LINE;
  600. EUDC_SView = GetCodeScrPos( ScrlBarPos);
  601. }else{
  602. MoveScr = ( 0-(CharSize.cy+LINEWIDTH))*NUM_LINE;
  603. EUDC_SView = EUDC_EView;
  604. ScrlBarPos = (short)GetBarPosition( EUDC_SView);
  605. }
  606. break;
  607. case SB_PAGEUP:
  608. if(( EUDC_SView - NUM_CHAR*NUM_LINE)
  609. >= ( EUDC_SCode & 0xfff0)){
  610. MoveScr = (CharSize.cy + LINEWIDTH)*NUM_LINE;
  611. ScrlBarPos = (short)GetBarPosition( EUDC_SView);
  612. ScrlBarPos -= NUM_LINE;
  613. EUDC_SView = GetCodeScrPos( ScrlBarPos);
  614. }else{
  615. MoveScr = (CharSize.cy + LINEWIDTH)*NUM_LINE;
  616. EUDC_SView = (EUDC_SCode & 0xfff0);
  617. ScrlBarPos = (short)GetBarPosition( EUDC_SView);
  618. }
  619. break;
  620. case SB_TOP:
  621. EUDC_SView = ( EUDC_SCode & 0xfff0);
  622. ScrlBarPos = 0;
  623. break;
  624. case SB_BOTTOM:
  625. EUDC_SView = EUDC_EView;
  626. ScrlBarPos = (short)BarRange;
  627. break;
  628. case SB_THUMBPOSITION:
  629. ThumbPosFlag = TRUE;
  630. ScrlBarPos = (short)nPos;
  631. EUDC_SView = GetCodeScrPos( nPos);
  632. break;
  633. case SB_THUMBTRACK:
  634. ThumbTrkFlag = TRUE;
  635. break;
  636. default:
  637. break;
  638. }
  639. if( abs( MoveScr) < (CharSize.cy + LINEWIDTH)*NUM_LINE &&
  640. abs( MoveScr) > 0 && !ThumbTrkFlag){
  641. CRect ScrllRect;
  642. CRect ClintRect;
  643. GetClientRect( &ClintRect);
  644. ScrllRect.CopyRect( &ClintRect);
  645. if( MoveScr < 0){
  646. ClintRect.top = 0 - MoveScr;
  647. this->ScrollWindow( 0, MoveScr, &ClintRect, NULL);
  648. ScrllRect.top = ( 0 - MoveScr)*(NUM_LINE-1);
  649. }else{
  650. ClintRect.top = LINEWIDTH;
  651. ClintRect.bottom = MoveScr*(NUM_LINE - 1);
  652. this->ScrollWindow( 0, MoveScr, &ClintRect, NULL);
  653. ScrllRect.top = 0;
  654. ScrllRect.bottom = ScrllRect.top + MoveScr;
  655. }
  656. this->InvalidateRect( &ScrllRect, FALSE);
  657. }else if(!ThumbTrkFlag && ( MoveScr || ThumbPosFlag)){
  658. this->Invalidate( TRUE);
  659. }
  660. this->SetScrollPos( SB_VERT, ScrlBarPos, TRUE);
  661. }
  662. /****************************************/
  663. /* */
  664. /* MESSAGE "WM_LBUTTONDOWN" */
  665. /* */
  666. /****************************************/
  667. void
  668. CEudcList::OnLButtonDown(
  669. UINT nFlags,
  670. CPoint point)
  671. {
  672. CRect test;
  673. BOOL PtIn;
  674. unsigned int i, j;
  675. PtIn = FALSE;
  676. this->SetFocus();
  677. for( i = 0; i < NUM_LINE; i++){
  678. for( j = 0; j < NUM_CHAR; j++){
  679. if( rcEditChar[i][j].PtInRect( point)){
  680. if( IsCorrectChar( i, j))
  681. PtIn = TRUE;
  682. break;
  683. }
  684. }
  685. }
  686. if( !PtIn){
  687. MessageBeep((UINT)-1);
  688. return;
  689. }
  690. LButtonPt = point;
  691. SearchSelectPosition();
  692. SelectCode = 0;
  693. for( i = 0; i < NUM_LINE; i++){
  694. for( j = 0; j < NUM_CHAR; j++){
  695. if( rcEditChar[i][j].PtInRect( LButtonPt)){
  696. test.SetRect( rcEditChar[i][j].left - 2,
  697. rcEditChar[i][j].top - 2,
  698. rcEditChar[i][j].right + 2,
  699. rcEditChar[i][j].bottom + 2);
  700. this->InvalidateRect( &test, FALSE);
  701. break;
  702. }
  703. }
  704. }
  705. this->UpdateWindow();
  706. }
  707. /****************************************/
  708. /* */
  709. /* MESSAGE "WM_LBUTTONDBLCLK" */
  710. /* */
  711. /****************************************/
  712. void
  713. CEudcList::OnLButtonDblClk(
  714. UINT nFlags,
  715. CPoint point)
  716. {
  717. BOOL PtIn;
  718. unsigned int i, j;
  719. LButtonPt = point;
  720. this->Invalidate( FALSE);
  721. this->UpdateWindow();
  722. PtIn = FALSE;
  723. this->SetFocus();
  724. for( i = 0; i < NUM_LINE; i++){
  725. for( j = 0; j < NUM_CHAR; j++){
  726. if( rcEditChar[i][j].PtInRect( point)){
  727. if( IsCorrectChar( i, j))
  728. PtIn = TRUE;
  729. break;
  730. }
  731. }
  732. }
  733. if( !PtIn){
  734. MessageBeep((UINT)-1);
  735. return;
  736. }else{
  737. GetParent()->PostMessage( WM_COMMAND, IDOK, 0L);
  738. }
  739. }
  740. /****************************************/
  741. /* */
  742. /* MESSAGE "WM_SETCURSOR" */
  743. /* */
  744. /****************************************/
  745. BOOL
  746. CEudcList::OnSetCursor(
  747. CWnd* pWnd,
  748. UINT nHitTest,
  749. UINT message)
  750. {
  751. ::SetCursor( AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  752. return TRUE;
  753. }
  754. /****************************************/
  755. /* */
  756. /* Draw ConcaveRectangle */
  757. /* */
  758. /****************************************/
  759. void
  760. CEudcList::DrawConcave(
  761. CDC *dc,
  762. CRect rect,
  763. BOOL PtIn)
  764. {
  765. CBrush ConBrush, *OldBrush;
  766. CRect Rt, Rf;
  767. if (!dc)
  768. {
  769. return;
  770. }
  771. Rt.SetRect( rect.left-1, rect.top-1, rect.right+1, rect.bottom+1);
  772. Rf.CopyRect( &rect);
  773. if( !PtIn){
  774. ConBrush.CreateSolidBrush( COLOR_HLIGHT);
  775. OldBrush = dc->SelectObject( &ConBrush);
  776. dc->PatBlt( Rt.left, Rt.top, Rt.Width(), 1, PATCOPY);
  777. dc->PatBlt( Rt.left, Rt.top, 1, Rt.Height(), PATCOPY);
  778. dc->SelectObject( OldBrush);
  779. ConBrush.DeleteObject();
  780. ConBrush.CreateSolidBrush( COLOR_SHADOW);
  781. OldBrush = dc->SelectObject( &ConBrush);
  782. dc->PatBlt( Rt.left, Rt.bottom, Rt.Width(), 1, PATCOPY);
  783. dc->PatBlt( Rt.right, Rt.top, 1, Rt.Height()+1, PATCOPY);
  784. dc->SelectObject( OldBrush);
  785. ConBrush.DeleteObject();
  786. if( FocusFlag){
  787. CBrush fBrush;
  788. CPen fPen, *OldPen;
  789. fBrush.CreateStockObject( NULL_BRUSH);
  790. fPen.CreatePen( PS_SOLID, 1, COLOR_FACE);
  791. OldBrush = dc->SelectObject( &fBrush);
  792. OldPen = dc->SelectObject( &fPen);
  793. dc->Rectangle( &Rf);
  794. dc->SelectObject( OldBrush);
  795. dc->SelectObject( OldPen);
  796. fBrush.DeleteObject();
  797. fPen.DeleteObject();
  798. }
  799. }else{
  800. ConBrush.CreateSolidBrush( COLOR_SHADOW);
  801. OldBrush = dc->SelectObject( &ConBrush);
  802. dc->PatBlt( Rt.left, Rt.top, Rt.Width(), 1, PATCOPY);
  803. dc->PatBlt( Rt.left, Rt.top, 1, Rt.Height(), PATCOPY);
  804. dc->SelectObject( OldBrush);
  805. ConBrush.DeleteObject();
  806. ConBrush.CreateSolidBrush( COLOR_HLIGHT);
  807. OldBrush = dc->SelectObject( &ConBrush);
  808. dc->PatBlt( Rt.left, Rt.bottom, Rt.Width(), 1, PATCOPY);
  809. dc->PatBlt( Rt.right, Rt.top, 1, Rt.Height()+1, PATCOPY);
  810. dc->SelectObject( OldBrush);
  811. ConBrush.DeleteObject();
  812. if( FocusFlag){
  813. CBrush fBrush;
  814. CPen fPen, *OldPen;
  815. fBrush.CreateStockObject( NULL_BRUSH);
  816. fPen.CreatePen( PS_SOLID, 1, COLOR_SHADOW);
  817. OldBrush = dc->SelectObject( &fBrush);
  818. OldPen = dc->SelectObject( &fPen);
  819. dc->Rectangle( &Rf);
  820. dc->SelectObject( OldBrush);
  821. dc->SelectObject( OldPen);
  822. fBrush.DeleteObject();
  823. fPen.DeleteObject();
  824. }
  825. }
  826. }
  827. /****************************************/
  828. /* */
  829. /* MESSAGE "WM_KEYDOWN" */
  830. /* */
  831. /****************************************/
  832. void
  833. CEudcList::OnKeyDown(
  834. UINT nChar,
  835. UINT nRepCnt,
  836. UINT nFlags)
  837. {
  838. int sPos;
  839. int ePos;
  840. #ifdef BUILD_ON_WINNT
  841. int i;
  842. WORD TmpCode;
  843. #endif // BUILD_ON_WINNT
  844. if( nChar == VK_DOWN || nChar == VK_UP ||
  845. nChar == VK_RIGHT || nChar == VK_LEFT){
  846. sPos = GetBarPosition( EUDC_SView);
  847. ePos = GetBarPosition( SelectCode);
  848. if( ePos - sPos >= NUM_LINE || ePos < sPos){
  849. EUDC_SView = SelectCode & 0xfff0;
  850. ScrlBarPos = (short)GetBarPosition( EUDC_SView);
  851. this->Invalidate(FALSE);
  852. this->UpdateWindow();
  853. }
  854. switch( nChar){
  855. case VK_DOWN:
  856. if( SelectCode + NUM_CHAR > EUDC_ECode)
  857. break;
  858. #ifdef BUILD_ON_WINNT
  859. TmpCode = SelectCode + NUM_CHAR;
  860. TmpCode = CorrectEUDCCodeKey( TmpCode, NUM_CHAR, TRUE);
  861. sPos = GetBarPosition( EUDC_SView);
  862. ePos = GetBarPosition( TmpCode);
  863. for (i=0;i <= ePos - sPos - NUM_LINE; i++){
  864. #else
  865. if( ePos - sPos >= NUM_LINE - 1){
  866. #endif // BUILD_ON_WINNT
  867. this->SendMessage( WM_VSCROLL, SB_LINEDOWN, 0);
  868. }
  869. SearchSelectPosition();
  870. SelectCode += NUM_CHAR;
  871. SelectCode = CorrectEUDCCodeKey( SelectCode,
  872. NUM_CHAR, TRUE);
  873. SearchSelectPosition();
  874. this->UpdateWindow();
  875. break;
  876. case VK_UP:
  877. if( SelectCode - NUM_CHAR < EUDC_SCode)
  878. break;
  879. #ifdef BUILD_ON_WINNT
  880. TmpCode = SelectCode - NUM_CHAR;
  881. TmpCode = CorrectEUDCCodeKey( TmpCode, NUM_CHAR, FALSE);
  882. sPos = GetBarPosition( EUDC_SView);
  883. ePos = GetBarPosition( TmpCode);
  884. for ( i=0; i < sPos - ePos; i++){
  885. #else
  886. if( SelectCode - NUM_CHAR < EUDC_SView){
  887. #endif // BUILD_ON_WINNT
  888. this->SendMessage( WM_VSCROLL, SB_LINEUP, 0);
  889. }
  890. SearchSelectPosition();
  891. SelectCode -= NUM_CHAR;
  892. SelectCode = CorrectEUDCCodeKey( SelectCode,
  893. NUM_CHAR, FALSE);
  894. SearchSelectPosition();
  895. this->UpdateWindow();
  896. break;
  897. case VK_LEFT:
  898. if( SelectCode - 1 < EUDC_SCode)
  899. break;
  900. #ifdef BUILD_ON_WINNT
  901. TmpCode = SelectCode - 1;
  902. TmpCode = CorrectEUDCCodeKey( TmpCode, 1, FALSE);
  903. sPos = GetBarPosition( EUDC_SView);
  904. ePos = GetBarPosition( TmpCode);
  905. if( ePos < sPos){
  906. #else
  907. if( SelectCode - 1 < EUDC_SView){
  908. #endif // BUILD_ON_WINNT
  909. this->SendMessage( WM_VSCROLL, SB_LINEUP, 0);
  910. }
  911. SearchSelectPosition();
  912. SelectCode--;
  913. SelectCode = CorrectEUDCCodeKey( SelectCode, 1, FALSE);
  914. SearchSelectPosition();
  915. this->UpdateWindow();
  916. break;
  917. case VK_RIGHT:
  918. #ifdef BUILD_ON_WINNT
  919. // Move to above...
  920. #else
  921. WORD TmpCode;
  922. #endif // BUILD_ON_WINNT
  923. if( SelectCode + 1 > EUDC_ECode)
  924. break;
  925. TmpCode = SelectCode + 1;
  926. TmpCode = CorrectEUDCCodeKey( TmpCode, 1, TRUE);
  927. sPos = GetBarPosition( EUDC_SView);
  928. ePos = GetBarPosition( TmpCode);
  929. if( ePos - sPos >= NUM_LINE){
  930. this->SendMessage( WM_VSCROLL, SB_LINEDOWN, 0);
  931. }
  932. SearchSelectPosition();
  933. SelectCode++;
  934. SelectCode = CorrectEUDCCodeKey( SelectCode, 1, TRUE);
  935. SearchSelectPosition();
  936. this->UpdateWindow();
  937. break;
  938. }
  939. }else CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
  940. }
  941. /****************************************/
  942. /* */
  943. /* MESSAGE "WM_SETFOCUS" */
  944. /* */
  945. /****************************************/
  946. void
  947. CEudcList::OnSetFocus(
  948. CWnd* pOldWnd)
  949. {
  950. CEdit::OnSetFocus(pOldWnd);
  951. FocusFlag = TRUE;
  952. SearchSelectPosition();
  953. this->UpdateWindow();
  954. ::HideCaret( NULL);
  955. // DestroyCaret();
  956. }
  957. /****************************************/
  958. /* */
  959. /* Search select posistion */
  960. /* */
  961. /****************************************/
  962. void
  963. CEudcList::SearchSelectPosition()
  964. {
  965. CRect test;
  966. int sViewPt, sCodePt;
  967. unsigned int i, j;
  968. sViewPt = GetBarPosition( EUDC_SView);
  969. sCodePt = GetBarPosition( SelectCode);
  970. #ifdef BUILD_ON_WINNT
  971. // the new view does not contain previsouly selected char,
  972. // we don't need to redraw the concave.
  973. if (sCodePt < sViewPt || sCodePt > sViewPt+NUM_LINE)
  974. return;
  975. #endif
  976. i = (unsigned int)(sCodePt - sViewPt);
  977. j = (unsigned int)(SelectCode & 0x000f);
  978. test.SetRect( rcEditChar[i][j].left - 2,
  979. rcEditChar[i][j].top - 2,
  980. rcEditChar[i][j].right + 2,
  981. rcEditChar[i][j].bottom + 2);
  982. this->InvalidateRect( &test, FALSE);
  983. }
  984. /****************************************/
  985. /* */
  986. /* Correct it if code is illegal */
  987. /* */
  988. /****************************************/
  989. #ifdef BUILD_ON_WINNT
  990. WORD
  991. CEudcList::CorrectEUDCCodeKey(
  992. WORD Code,
  993. int MovePt,
  994. BOOL UporDown)
  995. {
  996. COUNTRYINFO Info;
  997. WORD wCode;
  998. BYTE LByte, HByte, Tmp0;
  999. int TralPos = 0;
  1000. LByte = LOBYTE( Code);
  1001. HByte = HIBYTE( Code);
  1002. Info = CountryInfo;
  1003. for( int i = 0; i < Info.nTralByte; i++){
  1004. if( LByte >= Info.sTralByte[i] && LByte <= Info.eTralByte[i]){
  1005. goto RET;
  1006. }else if( LByte < Info.sTralByte[i]){
  1007. /* decide which range of starting trailbyte we are less than */
  1008. TralPos = i;
  1009. break;
  1010. }else TralPos = i+1;
  1011. }
  1012. if( UporDown){ //code increasing
  1013. if( TralPos == Info.nTralByte){ //greater than last eTrailByte
  1014. HByte += 0x1; //same as less than next sTraiByte
  1015. TralPos=0;
  1016. }
  1017. if( MovePt < NUM_CHAR){ //
  1018. LByte = Info.sTralByte[TralPos];
  1019. }else{
  1020. Tmp0 = LByte & 0x0f;
  1021. LByte = Info.sTralByte[TralPos] & 0xf0;
  1022. LByte |= Tmp0;
  1023. if (LByte < Info.sTralByte[TralPos])
  1024. LByte += NUM_CHAR;
  1025. }
  1026. }else{
  1027. if( TralPos == 0){ //greater than last eTrailByte
  1028. TralPos = Info.nTralByte;
  1029. HByte -= 0x1;
  1030. }
  1031. if( MovePt < NUM_CHAR){
  1032. LByte = Info.eTralByte[TralPos-1];
  1033. }else{
  1034. Tmp0 = LByte & 0x0f;
  1035. LByte = Info.eTralByte[TralPos-1] & 0xf0;
  1036. LByte |= Tmp0;
  1037. if (LByte > Info.eTralByte[TralPos-1])
  1038. LByte -= NUM_CHAR;
  1039. }
  1040. }
  1041. RET:
  1042. wCode = MAKEWORD( LByte, HByte);
  1043. return wCode;
  1044. }
  1045. #else
  1046. WORD
  1047. CEudcList::CorrectEUDCCodeKey(
  1048. WORD Code,
  1049. int MovePt,
  1050. BOOL UporDown)
  1051. {
  1052. COUNTRYINFO Info;
  1053. WORD wCode;
  1054. BYTE LByte, HByte;
  1055. int TralPos = 0;
  1056. LByte = LOBYTE( Code);
  1057. HByte = HIBYTE( Code);
  1058. Info = CountryInfo;
  1059. for( int i = 0; i < Info.nTralByte; i++){
  1060. if( LByte >= Info.sTralByte[i] && LByte <= Info.eTralByte[i]){
  1061. goto RET;
  1062. }else if( LByte < Info.sTralByte[i]){
  1063. TralPos = i;
  1064. break;
  1065. }else TralPos = i+1;
  1066. }
  1067. if( UporDown)
  1068. if( TralPos == Info.nTralByte){
  1069. if( MovePt < NUM_CHAR){
  1070. LByte = Info.sTralByte[0];
  1071. HByte += 0x1;
  1072. }else{
  1073. LByte = Info.eTralByte[Info.nTralByte - 1];
  1074. }
  1075. }else if( MovePt < NUM_CHAR){
  1076. LByte = Info.sTralByte[TralPos];
  1077. }else{
  1078. if( TralPos){
  1079. BYTE Tmp1;
  1080. BYTE Tmp2;
  1081. Tmp1 = Info.eTralByte[TralPos-1] & 0xf0;
  1082. Tmp2 = LByte & 0xf0;
  1083. if( Tmp1 == Tmp2){
  1084. LByte = Info.eTralByte[TralPos-1];
  1085. }else{
  1086. Tmp1 = LByte & 0x0f;
  1087. LByte = Info.sTralByte[TralPos] & 0xf0;
  1088. LByte |= Tmp1;
  1089. }
  1090. }else{
  1091. LByte += (Info.sTralByte[0] & 0xf0);
  1092. }
  1093. }
  1094. else{
  1095. if( !TralPos){
  1096. if( MovePt < NUM_CHAR){
  1097. LByte = Info.eTralByte[Info.nTralByte - 1];
  1098. HByte -= 0x1;
  1099. }else{
  1100. BYTE Tmp;
  1101. Tmp = LByte & 0x0f;
  1102. LByte = Info.eTralByte[Info.nTralByte - 1]&0xf0;
  1103. LByte |= Tmp;
  1104. HByte -= 0x1;
  1105. if( LByte > Info.eTralByte[Info.nTralByte-1]){
  1106. LByte = Info.eTralByte[Info.nTralByte-1];
  1107. }
  1108. }
  1109. }else{
  1110. BYTE Tmp;
  1111. Tmp = LByte & 0x0f;
  1112. LByte = Info.eTralByte[TralPos-1] & 0xf0;
  1113. LByte |= Tmp;
  1114. if( LByte > Info.eTralByte[TralPos-1])
  1115. LByte = Info.eTralByte[TralPos-1];
  1116. }
  1117. }
  1118. RET:
  1119. wCode = MAKEWORD( LByte, HByte);
  1120. return wCode;
  1121. }
  1122. #endif // BUILD_ON_WINNT
  1123. /****************************************/
  1124. /* */
  1125. /* Whether correct or not? */
  1126. /* */
  1127. /****************************************/
  1128. BOOL
  1129. CEudcList::IsCorrectChar(
  1130. UINT i,
  1131. UINT j)
  1132. {
  1133. int sViewPt;
  1134. WORD wCode;
  1135. BYTE sOffset;
  1136. BOOL flg;
  1137. flg = FALSE;
  1138. BarRange = GetBarPosition((WORD)EUDC_EView);
  1139. sViewPt = GetBarPosition( EUDC_SView);
  1140. wCode = GetCodeScrPos( sViewPt + i);
  1141. wCode |= j;
  1142. sOffset = LOBYTE( wCode);
  1143. for( int k = 0; k < CountryInfo.nTralByte; k++){
  1144. if( sOffset >= CountryInfo.sTralByte[k] &&
  1145. sOffset <= CountryInfo.eTralByte[k]){
  1146. flg = TRUE;
  1147. }
  1148. }
  1149. return flg;
  1150. }
  1151. /****************************************/
  1152. /* */
  1153. /* MESSAGE "WM_KILLFOCUS" */
  1154. /* */
  1155. /****************************************/
  1156. void
  1157. CEudcList::OnKillFocus(
  1158. CWnd* pNewWnd)
  1159. {
  1160. FocusFlag = FALSE;
  1161. SearchSelectPosition();
  1162. this->UpdateWindow();
  1163. CEdit::OnKillFocus( pNewWnd);
  1164. ::HideCaret( NULL);
  1165. }
  1166. /****************************************/
  1167. /* */
  1168. /* MESSAGE "WM_RBUTTONUP" */
  1169. /* */
  1170. /****************************************/
  1171. void
  1172. CEudcList::OnRButtonUp(
  1173. UINT nFlags,
  1174. CPoint point)
  1175. {
  1176. GetParent()->SendMessage( WM_CONTEXTMENU, (WPARAM)this->GetSafeHwnd(), 0);
  1177. }
  1178. BEGIN_MESSAGE_MAP( CViewEdit, CEdit)
  1179. //{{AFX_MSG_MAP( CViewEdit)
  1180. ON_WM_PAINT()
  1181. ON_WM_SETCURSOR()
  1182. ON_WM_SETFOCUS()
  1183. ON_WM_KILLFOCUS()
  1184. ON_WM_LBUTTONDOWN()
  1185. ON_WM_LBUTTONDBLCLK()
  1186. ON_WM_RBUTTONUP()
  1187. //}}AFX_MSG_MAP
  1188. END_MESSAGE_MAP()
  1189. /****************************************/
  1190. /* */
  1191. /* Default Constructor */
  1192. /* */
  1193. /****************************************/
  1194. CViewEdit::CViewEdit()
  1195. {
  1196. }
  1197. /****************************************/
  1198. /* */
  1199. /* Destructor */
  1200. /* */
  1201. /****************************************/
  1202. CViewEdit::~CViewEdit()
  1203. {
  1204. //fix for 261529
  1205. EUDCFont.DeleteObject();
  1206. }
  1207. /****************************************/
  1208. /* */
  1209. /* MESSAGE "WM_PAINT" */
  1210. /* */
  1211. /****************************************/
  1212. void
  1213. CViewEdit::OnPaint()
  1214. {
  1215. LOGFONT LogFont;
  1216. CFont ViewFont, *OldFont;
  1217. CSize cSize;
  1218. CRect ViewRect;
  1219. int xOffset, yOffset;
  1220. CPaintDC dc( this);
  1221. GetClientRect( &ViewRect);
  1222. DrawConcave( &dc, ViewRect);
  1223. if(bHasGlyph == FALSE) return;
  1224. memset( &LogFont, 0, sizeof( LogFont));
  1225. //fix for 261529
  1226. EUDCFont.GetLogFont(&LogFont);
  1227. if( ViewRect.Width() >= ViewRect.Height())
  1228. LogFont.lfHeight = ViewRect.Height() - 10;
  1229. else LogFont.lfHeight = ViewRect.Width() - 10;
  1230. if( !ViewFont.CreateFontIndirect( &LogFont))
  1231. return;
  1232. OldFont = dc.SelectObject( &ViewFont);
  1233. #ifdef BUILD_ON_WINNT
  1234. if (CountryInfo.bUnicodeMode)
  1235. GetTextExtentPoint32W(dc.GetSafeHdc(), (LPCWSTR)ViewCode, 1, &cSize);
  1236. else
  1237. #endif //BUILD_ON_WINNT
  1238. GetTextExtentPoint32A(dc.GetSafeHdc(), (LPCSTR)ViewCode, 2, &cSize);
  1239. if( ViewRect.Width() > cSize.cx){
  1240. xOffset = ViewRect.Width() - cSize.cx;
  1241. xOffset /= 2;
  1242. }else xOffset = 0;
  1243. if( ViewRect.Height() > cSize.cy){
  1244. yOffset = ViewRect.Height() - cSize.cy;
  1245. yOffset /= 2;
  1246. }else yOffset = 0;
  1247. dc.SetBkColor( COLOR_FACE);
  1248. dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); // COLOR_BLACK);
  1249. if (CountryInfo.bUnicodeMode)
  1250. {
  1251. #ifdef UNICODE
  1252. ExtTextOutW(dc.GetSafeHdc(), xOffset, yOffset, ETO_OPAQUE,
  1253. &ViewRect, (LPCWSTR)ViewCode, 1, NULL);
  1254. #else
  1255. CHAR ViewTmp[2];
  1256. WideCharToMultiByte(CP_ACP, 0, (LPWSTR) ViewCode, 1, ViewTmp, 2, NULL, NULL);
  1257. ExtTextOutA(dc.GetSafeHdc(), xOffset, yOffset, ETO_OPAQUE,
  1258. &ViewRect, (LPCSTR)ViewTmp, 2, NULL);
  1259. #endif
  1260. }
  1261. else
  1262. {
  1263. ExtTextOutA(dc.GetSafeHdc(), xOffset, yOffset, ETO_OPAQUE,
  1264. &ViewRect, (LPCSTR)ViewCode, 2, NULL);
  1265. }
  1266. dc.SelectObject( OldFont);
  1267. ViewFont.DeleteObject();
  1268. }
  1269. /****************************************/
  1270. /* */
  1271. /* Draw Concave Rect */
  1272. /* */
  1273. /****************************************/
  1274. void
  1275. CViewEdit::DrawConcave(
  1276. CDC *dc,
  1277. CRect rect)
  1278. {
  1279. CBrush ConBrush, *OldBrush;
  1280. CRect Rt;
  1281. if (!dc)
  1282. {
  1283. return;
  1284. }
  1285. Rt.SetRect( rect.left-1, rect.top-1, rect.right, rect.bottom);
  1286. ConBrush.CreateSolidBrush(COLOR_FACE);
  1287. OldBrush = dc->SelectObject( &ConBrush);
  1288. dc->PatBlt( Rt.left, Rt.top, Rt.right, Rt.bottom, PATCOPY);
  1289. dc->SelectObject( OldBrush);
  1290. ConBrush.DeleteObject();
  1291. ConBrush.CreateSolidBrush( COLOR_HLIGHT);
  1292. OldBrush = dc->SelectObject( &ConBrush);
  1293. dc->PatBlt( Rt.left, Rt.top, Rt.Width(), 1, PATCOPY);
  1294. dc->PatBlt( Rt.left, Rt.top, 1, Rt.Height(), PATCOPY);
  1295. dc->SelectObject( OldBrush);
  1296. ConBrush.DeleteObject();
  1297. ConBrush.CreateSolidBrush( COLOR_SHADOW);
  1298. OldBrush = dc->SelectObject( &ConBrush);
  1299. dc->PatBlt( Rt.left, Rt.bottom, Rt.Width(), 1, PATCOPY);
  1300. dc->PatBlt( Rt.right, Rt.top, 1, Rt.Height()+1, PATCOPY);
  1301. dc->SelectObject( OldBrush);
  1302. ConBrush.DeleteObject();
  1303. }
  1304. BEGIN_MESSAGE_MAP( CCustomListFrame, CStatic)
  1305. //{{AFX_MSG_MAP( CCustomListFrame)
  1306. ON_WM_PAINT()
  1307. //}}AFX_MSG_MAP
  1308. END_MESSAGE_MAP()
  1309. /****************************************/
  1310. /* */
  1311. /* Default Constructor */
  1312. /* */
  1313. /****************************************/
  1314. CCustomListFrame::CCustomListFrame()
  1315. {
  1316. }
  1317. /****************************************/
  1318. /* */
  1319. /* Destructor */
  1320. /* */
  1321. /****************************************/
  1322. CCustomListFrame::~CCustomListFrame()
  1323. {
  1324. }
  1325. /****************************************/
  1326. /* */
  1327. /* MESSAGE "WM_PAINT" */
  1328. /* */
  1329. /****************************************/
  1330. void
  1331. CCustomListFrame::OnPaint()
  1332. {
  1333. CRect FrameRect;
  1334. CPaintDC dc( this);
  1335. this->GetClientRect( &FrameRect);
  1336. this->DrawConcave( &dc, FrameRect);
  1337. }
  1338. /****************************************/
  1339. /* */
  1340. /* Draw Concave Rect */
  1341. /* */
  1342. /****************************************/
  1343. void
  1344. CCustomListFrame::DrawConcave(
  1345. CDC *dc,
  1346. CRect rect)
  1347. {
  1348. CBrush ConBrush, *OldBrush;
  1349. CRect Rt;
  1350. if (!dc)
  1351. {
  1352. return;
  1353. }
  1354. Rt.SetRect( rect.left-1, rect.top-1, rect.right, rect.bottom);
  1355. ConBrush.CreateSolidBrush( COLOR_HLIGHT);
  1356. OldBrush = dc->SelectObject( &ConBrush);
  1357. dc->PatBlt( Rt.left, Rt.top, Rt.Width(), 1, PATCOPY);
  1358. dc->PatBlt( Rt.left, Rt.top, 1, Rt.Height(), PATCOPY);
  1359. dc->SelectObject( OldBrush);
  1360. ConBrush.DeleteObject();
  1361. ConBrush.CreateSolidBrush( COLOR_SHADOW);
  1362. OldBrush = dc->SelectObject( &ConBrush);
  1363. dc->PatBlt( Rt.left, Rt.bottom, Rt.Width(), 1, PATCOPY);
  1364. dc->PatBlt( Rt.right, Rt.top, 1, Rt.Height()+1, PATCOPY);
  1365. dc->SelectObject( OldBrush);
  1366. ConBrush.DeleteObject();
  1367. }
  1368. BEGIN_MESSAGE_MAP( CCustomInfoFrame, CStatic)
  1369. //{{AFX_MSG_MAP( CCustomInfoFrame)
  1370. ON_WM_PAINT()
  1371. //}}AFX_MSG_MAP
  1372. END_MESSAGE_MAP()
  1373. /****************************************/
  1374. /* */
  1375. /* Default Constructor */
  1376. /* */
  1377. /****************************************/
  1378. CCustomInfoFrame::CCustomInfoFrame()
  1379. {
  1380. }
  1381. /****************************************/
  1382. /* */
  1383. /* Destructor */
  1384. /* */
  1385. /****************************************/
  1386. CCustomInfoFrame::~CCustomInfoFrame()
  1387. {
  1388. }
  1389. /****************************************/
  1390. /* */
  1391. /* MESSAGE "WM_PAINT" */
  1392. /* */
  1393. /****************************************/
  1394. void
  1395. CCustomInfoFrame::OnPaint()
  1396. {
  1397. CRect FrameRect;
  1398. CPaintDC dc( this);
  1399. this->GetClientRect( &FrameRect);
  1400. this->DrawConcave( &dc, FrameRect);
  1401. }
  1402. /****************************************/
  1403. /* */
  1404. /* Draw Concave Rect */
  1405. /* */
  1406. /****************************************/
  1407. void
  1408. CCustomInfoFrame::DrawConcave(
  1409. CDC *dc,
  1410. CRect rect)
  1411. {
  1412. CBrush ConBrush, *OldBrush;
  1413. CRect Rt;
  1414. if (!dc)
  1415. {
  1416. return;
  1417. }
  1418. Rt.SetRect( rect.left-1, rect.top-1, rect.right, rect.bottom);
  1419. ConBrush.CreateSolidBrush( COLOR_SHADOW);
  1420. OldBrush = dc->SelectObject( &ConBrush);
  1421. dc->PatBlt( Rt.left, Rt.top, Rt.Width(), 1, PATCOPY);
  1422. dc->PatBlt( Rt.left, Rt.top, 1, Rt.Height(), PATCOPY);
  1423. dc->SelectObject( OldBrush);
  1424. ConBrush.DeleteObject();
  1425. ConBrush.CreateSolidBrush( COLOR_HLIGHT);
  1426. OldBrush = dc->SelectObject( &ConBrush);
  1427. dc->PatBlt( Rt.left, Rt.bottom, Rt.Width(), 1, PATCOPY);
  1428. dc->PatBlt( Rt.right, Rt.top, 1, Rt.Height()+1, PATCOPY);
  1429. dc->SelectObject( OldBrush);
  1430. ConBrush.DeleteObject();
  1431. }
  1432. BOOL CViewEdit::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  1433. {
  1434. ::SetCursor( AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  1435. return TRUE;
  1436. }
  1437. void CViewEdit::OnSetFocus(CWnd* pOldWnd)
  1438. {
  1439. CEdit::OnSetFocus(pOldWnd);
  1440. ::HideCaret( NULL);
  1441. }
  1442. void CViewEdit::OnKillFocus(CWnd* pNewWnd)
  1443. {
  1444. CEdit::OnKillFocus(pNewWnd);
  1445. ::HideCaret( NULL);
  1446. }
  1447. void CViewEdit::OnLButtonDown(UINT nFlags, CPoint point)
  1448. {
  1449. }
  1450. void CViewEdit::OnLButtonDblClk(UINT nFlags, CPoint point)
  1451. {
  1452. }
  1453. void CViewEdit::OnRButtonUp(UINT nFlags, CPoint point)
  1454. {
  1455. GetParent()->SendMessage( WM_CONTEXTMENU, (WPARAM)this->GetSafeHwnd(), 0);
  1456. }
  1457. #ifdef BUILD_ON_WINNT
  1458. BEGIN_MESSAGE_MAP( CColumnHeading, CWnd)
  1459. //{{AFX_MSG_MAP( CColumnHeading)
  1460. ON_WM_PAINT()
  1461. //}}AFX_MSG_MAP
  1462. END_MESSAGE_MAP()
  1463. /****************************************/
  1464. /* */
  1465. /* Default Constructor */
  1466. /* */
  1467. /****************************************/
  1468. CColumnHeading::CColumnHeading()
  1469. {
  1470. }
  1471. /****************************************/
  1472. /* */
  1473. /* Destructor */
  1474. /* */
  1475. /****************************************/
  1476. CColumnHeading::~CColumnHeading()
  1477. {
  1478. SysFFont.DeleteObject();
  1479. }
  1480. /****************************************/
  1481. /* */
  1482. /* MESSAGE "WM_PAINT" */
  1483. /* */
  1484. /****************************************/
  1485. void
  1486. CColumnHeading::OnPaint()
  1487. {
  1488. // column heading support
  1489. CPaintDC dc( this);
  1490. TCHAR ColumnHead[2];
  1491. CSize cSize;
  1492. int j,xOffset;
  1493. HRESULT hresult;
  1494. dc.SetMapMode( MM_TEXT);
  1495. dc.SelectObject( &SysFFont);
  1496. dc.SetBkColor( COLOR_FACE);
  1497. dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); // COLOR_BLACK);
  1498. for( j = 0; j < NUM_CHAR; j++){
  1499. //*STRSAFE* wsprintf(ColumnHead, TEXT("%X"), j);
  1500. hresult = StringCchPrintf(ColumnHead , ARRAYLEN(ColumnHead), TEXT("%X"), j);
  1501. if (!SUCCEEDED(hresult))
  1502. {
  1503. return ;
  1504. }
  1505. GetTextExtentPoint32(dc.GetSafeHdc(),
  1506. ColumnHead, 1, &cSize);
  1507. if( rcColumnHead[j].Width() > cSize.cx){
  1508. xOffset = rcColumnHead[j].Width() - cSize.cx;
  1509. xOffset /= 2;
  1510. }else
  1511. xOffset= 0;
  1512. dc.ExtTextOut( rcColumnHead[j].left + xOffset,
  1513. rcColumnHead[j].top,
  1514. ETO_OPAQUE, &rcColumnHead[j],
  1515. ColumnHead, 1, NULL);
  1516. }
  1517. }
  1518. #endif //BUILD_ON_WINNT