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.

851 lines
15 KiB

  1. // Copyright (c) 1985 - 1999, Microsoft Corporation
  2. /*--------------------------------------------------------------------------*/
  3. /* Constants */
  4. /*--------------------------------------------------------------------------*/
  5. #if DBG==1
  6. //#define DEBUG_MODE
  7. //#define DEBUG_PRINT
  8. //#define DEBUG_INFO
  9. #endif
  10. /*
  11. * Resource defines
  12. */
  13. #define WINDOWMENU 1
  14. #define ID_CONSOLEIME_ICON 2
  15. /*
  16. * Menu ID's
  17. */
  18. #define MM_ABOUT 8001
  19. #define MM_EXIT 8002
  20. #define MM_ACCESS_VIOLATION 8003
  21. /* String Table Defines */
  22. #define errTitle 0
  23. #define IDS_MENUNAME 12
  24. #define IDS_APPNAME 13
  25. #define IDS_CLASSNAME 14
  26. #define IDS_TITLE 15
  27. #define IDS_LAST 15 // Put New Strings Before this one
  28. #ifdef DEBUG_PRINT
  29. #define DBGPRINT(_params_) DbgPrint _params_
  30. #else
  31. #define DBGPRINT(_params_)
  32. #endif
  33. #define CONSOLE_INITIAL_TABLE 10
  34. #define CONSOLE_CONSOLE_TABLE_INCREMENT 5
  35. #define HKL_INITIAL_TABLE 1
  36. #define HKL_TABLE_INCREMENT 1
  37. #define CVMAX 2048
  38. #define NUMMAX 100
  39. #define CMAX 160
  40. #define MAXROW 1
  41. #define MAXCOL 80
  42. #define FIRSTROW 0
  43. #define FIRSTCOL 0
  44. #define LASTROW (MAXROW-1)
  45. #define LASTCOL (MAXCOL-1)
  46. #define TABSTOP 8
  47. #define MAX_LISTCAND 32
  48. #define MAX_CHARS_PER_LINE 10
  49. #define MAX_COMP_STRING_LEN 10
  50. #define DEFAULT_CAND_NUM_PER_PAGE 5
  51. #define X_INDENT 10
  52. #define Y_INDENT 10
  53. #define DELIMITERWIDTH 3 // 1:xxx 2:xxx
  54. #define DEFAULTCANDTABLE 100
  55. #define DISPCHANGELIMIT 188
  56. #define CODEDISPLEN 7 // '[F040] '
  57. #define DEFAULT_TEMP_WIDTH 80
  58. #define KEY_TOGGLED 0x01
  59. #define MaxBufSize 256
  60. #define KBDLAYOUT TEXT("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts")
  61. #define KBDLAYOUTTEXT TEXT("layout text")
  62. #define KBDSEPALATER TEXT("\\")
  63. #define LANG_ID_TAIWAN MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_TRADITIONAL) // 0x0404
  64. #define LANG_ID_JAPAN MAKELANGID(LANG_JAPANESE,SUBLANG_DEFAULT) // 0x0411
  65. #define LANG_ID_KOREA MAKELANGID(LANG_KOREAN,SUBLANG_DEFAULT) // 0x0412
  66. #define LANG_ID_PRC MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED) // 0x0804
  67. typedef struct _HKL_TABLE {
  68. HKL hkl;
  69. DWORD dwConversion;
  70. } HKL_TABLE, *LPHKL_TABLE;
  71. typedef struct _CONSOLE_TABLE {
  72. /*
  73. * Console Information
  74. */
  75. HANDLE hConsole; // Handle of Console
  76. HWND hWndCon; // Window handle of Console
  77. COORD ScreenBufferSize; // Screen Buffer Size of Console
  78. /*
  79. * IMM/IME Basic Information
  80. */
  81. HKL hklActive;
  82. HIMC hIMC_Current; // Handle of Input Context for current
  83. HIMC hIMC_Original; // Handle of Input Context for original
  84. BOOL fOpen; // Open flag
  85. DWORD dwConversion; // Conversion mode
  86. DWORD dwSentence; // Sentence mode
  87. WORD ConsoleCP;
  88. WORD ConsoleOutputCP;
  89. WCHAR LayoutName[MaxBufSize];
  90. WCHAR GuideLine[10];
  91. /*
  92. * IMM/IME Composition String Information
  93. */
  94. BOOL fInComposition; // Flag of in compositionning.
  95. LPCONIME_UICOMPMESSAGE lpCompStrMem;
  96. WORD CompAttrColor[8];
  97. /*
  98. * IMM/IME Candidate Information
  99. */
  100. BOOL fInCandidate; // Flag of in candidating
  101. LPCANDIDATELIST lpCandListMem[ MAX_LISTCAND ];
  102. LPCONIME_CANDMESSAGE SystemLine;
  103. DWORD SystemLineSize;
  104. DWORD CandListMemAllocSize[ MAX_LISTCAND ];
  105. DWORD CandOff;
  106. DWORD CandMax;
  107. LPDWORD CandSep;
  108. DWORD CandSepAllocSize;
  109. BOOL fNestCandidate;
  110. DWORD ImmGetProperty;
  111. /*
  112. * misc
  113. */
  114. BOOL Enable;
  115. BOOL LateRemove;
  116. INT hklListMax;
  117. LPHKL_TABLE lphklList;
  118. #ifdef DEBUG_MODE
  119. DWORD ImeCandNum;
  120. DWORD CandidateCount;
  121. HWND hListCand[ MAX_LISTCAND ];
  122. WCHAR DispBuf[CMAX];
  123. #endif
  124. } CONSOLE_TABLE, *PCONSOLE_TABLE;
  125. #define IPHK_HOTKEY 0x0001 //
  126. #define IPHK_PROCESSBYIME 0x0002 //
  127. #define IPHK_CHECKCTRL 0x0004 //
  128. #define IS_IME_KBDLAYOUT(hkl) ((HIWORD(HandleToUlong(hkl)) & 0xf000) == 0xe000)
  129. #define HKL_TO_LANGID(hkl) (LOWORD(HandleToUlong(hkl)))
  130. DWORD
  131. ImmCallImeConsoleIME(
  132. HWND hWnd,
  133. UINT Message,
  134. WPARAM wParam,
  135. LPARAM lParam,
  136. PUINT puVKey
  137. );
  138. BOOL
  139. ImmTranslateMessage(
  140. HWND hwnd,
  141. UINT message,
  142. WPARAM wParam,
  143. LPARAM lParam
  144. );
  145. BOOL
  146. ImmSetActiveContextConsoleIME(
  147. HWND hWnd,
  148. BOOL fFlag
  149. );
  150. #define UNICODE_BACKSPACE ((WCHAR)0x08)
  151. #define UNICODE_BACKSPACE2 ((WCHAR)0x25d8)
  152. #define UNICODE_CARRIAGERETURN ((WCHAR)0x0d)
  153. #define UNICODE_LINEFEED ((WCHAR)0x0a)
  154. #define UNICODE_BELL ((WCHAR)0x07)
  155. #define UNICODE_TAB ((WCHAR)0x09)
  156. #define UNICODE_SPACE ((WCHAR)0x20)
  157. #define UNICODE_ZERO ((WCHAR)'0')
  158. #define UNICODE_SLASH ((WCHAR)'/')
  159. #define UNICODE_COLON ((WCHAR)':')
  160. #define UNICODE_LEFT ((WCHAR)'[')
  161. #define UNICODE_RIGHT ((WCHAR)']')
  162. #define UNICODE_HEXBASE ((WCHAR)'7')
  163. #define JAPAN_CODEPAGE 932
  164. #define PRC_CODEPAGE 936
  165. #define KOREA_CODEPAGE 949
  166. #define TAIWAN_CODEPAGE 950
  167. #define PRCCOMPWIDTH 10
  168. #define MODEDISP_NONE 0
  169. #define MODEDISP_PLAURAL 1
  170. #define MODEDISP_SINGLE 2
  171. #define MODEDISP_AUTO 3
  172. #define MODEDISP_PHRASE 4
  173. // for Japanese
  174. #define IMECModeRomanLen 4
  175. #define IMECModeKanaLen 4
  176. #define IMECModeAHANLen 3
  177. #define IMECModeAZENLen 2
  178. #define IMECModeHHANLen 3
  179. #define IMECModeHZENLen 2
  180. #define IMECModeKHANLen 3
  181. #define IMECModeKZENLen 2
  182. // for CHT /Taiwan
  183. #define IMECModeFullShapeLen 1
  184. #define IMECModeHalfShapeLen 1
  185. #define IMECModeKeyboardLen 2
  186. #define IMECModeSymbolLen 2
  187. #define IMECGuideLen 5
  188. #define IMECNameLength 4
  189. /*****************************************************
  190. * Function definition
  191. *****************************************************/
  192. //
  193. // CONIME.C
  194. //
  195. BOOL
  196. InitConsoleIME(
  197. HINSTANCE hInstance
  198. );
  199. LRESULT FAR PASCAL
  200. WndProc(
  201. HWND hWnd,
  202. UINT Message,
  203. WPARAM wParam,
  204. LPARAM lParam
  205. );
  206. VOID
  207. ExitList(
  208. HWND hWnd
  209. );
  210. BOOL
  211. InsertConsole(
  212. HWND hWnd,
  213. HANDLE hConsole,
  214. HWND hWndConsole
  215. );
  216. BOOL
  217. GrowConsoleTable(
  218. VOID
  219. );
  220. PCONSOLE_TABLE
  221. SearchConsole(
  222. HANDLE hConsole
  223. );
  224. BOOL
  225. RemoveConsole(
  226. HWND hwnd,
  227. HANDLE hConsole
  228. );
  229. BOOL
  230. RemoveConsoleWorker(
  231. HWND hwnd,
  232. PCONSOLE_TABLE ConTbl
  233. );
  234. BOOL
  235. InsertNewConsole(
  236. HWND hWnd,
  237. HANDLE hConsole,
  238. HWND hWndConsole
  239. );
  240. BOOL
  241. ConsoleSetFocus(
  242. HWND hWnd,
  243. HANDLE hConsole,
  244. HKL hKL
  245. );
  246. BOOL
  247. ConsoleKillFocus(
  248. HWND hWnd,
  249. HANDLE hConsole
  250. );
  251. BOOL
  252. ConsoleScreenBufferSize(
  253. HWND hWnd,
  254. HANDLE hConsolewParam,
  255. COORD ScreenBufferSize
  256. );
  257. BOOL
  258. ConImeInputLangchangeRequest(
  259. HWND hWnd,
  260. HANDLE hConsole,
  261. HKL hkl,
  262. int Direction
  263. );
  264. BOOL
  265. ConImeInputLangchange(
  266. HWND hWnd,
  267. HANDLE hConsole,
  268. HKL hkl
  269. );
  270. LRESULT
  271. ConsoleImeSendMessage(
  272. HWND hWndConsoleIME,
  273. WPARAM wParam,
  274. LPARAM lParam
  275. );
  276. BOOL
  277. InputLangchange(
  278. HWND hWnd,
  279. DWORD CharSet,
  280. HKL hkl );
  281. #ifdef DEBUG_MODE
  282. VOID
  283. DisplayConvInformation(
  284. HWND hWnd
  285. );
  286. VOID
  287. DisplayInformation(
  288. HWND hWnd,
  289. HANDLE hConsole
  290. );
  291. VOID
  292. RealReDraw(
  293. HDC r_hdc
  294. );
  295. VOID
  296. ReDraw(
  297. HWND hWnd
  298. );
  299. #endif
  300. //
  301. // CONSUBS.C
  302. //
  303. INT
  304. Create(
  305. HWND hWnd
  306. );
  307. void
  308. ImeUIStartComposition(
  309. HWND hwnd
  310. );
  311. void
  312. ImeUIEndComposition(
  313. HWND hwnd
  314. );
  315. void
  316. ImeUIComposition(
  317. HWND hwnd,
  318. WPARAM wParam,
  319. LPARAM CompFlag
  320. );
  321. void
  322. DisplayCompString(
  323. HWND hwnd,
  324. int Length,
  325. PWCHAR CharBuf,
  326. PUCHAR AttrBuf
  327. );
  328. void
  329. DisplayResultString(
  330. HWND hwnd,
  331. LPWSTR lpStr
  332. );
  333. BOOL
  334. ImeUINotify(
  335. HWND hwnd,
  336. WPARAM wParam,
  337. LPARAM lParam
  338. );
  339. BOOL
  340. IsUnicodeFullWidth(
  341. IN WCHAR wch
  342. );
  343. BOOL
  344. ImeUIOpenStatusWindow(
  345. HWND hwnd
  346. );
  347. BOOL
  348. ImeUIChangeCandidate(
  349. HWND hwnd,
  350. DWORD lParam
  351. );
  352. BOOL
  353. ImeUISetOpenStatus(
  354. HWND hwnd
  355. );
  356. BOOL
  357. ImeUISetConversionMode(
  358. HWND hwnd
  359. );
  360. BOOL
  361. ImeUIGuideLine(
  362. HWND hwnd
  363. );
  364. DWORD
  365. GetNLSMode(
  366. HWND hWnd,
  367. HANDLE hConsole
  368. );
  369. BOOL
  370. SetNLSMode(
  371. HWND hWnd,
  372. HANDLE hConsole,
  373. DWORD fdwConversion
  374. );
  375. VOID
  376. CopyDataProcess(
  377. HWND hWnd,
  378. PCOPYDATASTRUCT CopyData
  379. );
  380. BOOL
  381. ImeSysPropertyWindow(
  382. HWND hWnd,
  383. WPARAM wParam,
  384. LPARAM lParam
  385. );
  386. //
  387. // IMEFULL.C
  388. //
  389. VOID
  390. ImeOpenClose(
  391. HWND hWnd,
  392. BOOL fFlag
  393. );
  394. VOID
  395. VirtualKeyHandler(
  396. HWND hWnd,
  397. UINT wParam,
  398. UINT lParam
  399. );
  400. VOID
  401. CharHandlerFromConsole(
  402. HWND hWnd,
  403. UINT Message,
  404. ULONG wParam,
  405. ULONG lParam
  406. );
  407. VOID
  408. CharHandlerToConsole(
  409. HWND hWnd,
  410. UINT Message,
  411. ULONG wParam,
  412. ULONG lParam
  413. );
  414. #ifdef DEBUG_MODE
  415. VOID
  416. ImeUIMoveCandWin(
  417. HWND hwnd
  418. );
  419. #endif
  420. BOOL
  421. IsDBCSTrailByte(
  422. char *base,
  423. char *p
  424. );
  425. #ifdef DEBUG_MODE
  426. VOID
  427. ResetCaret(
  428. HWND hWnd
  429. );
  430. BOOL
  431. MoveCaret(
  432. HWND hwnd
  433. );
  434. #endif
  435. #ifdef DEBUG_MODE
  436. VOID
  437. StoreChar(
  438. HWND hWnd,
  439. WORD ch,
  440. UCHAR atr
  441. );
  442. #endif
  443. BOOL
  444. ConsoleCodepageChange(
  445. HWND hWnd,
  446. HANDLE hConsole,
  447. BOOL Output,
  448. WORD CodePage
  449. );
  450. //LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  451. //L L
  452. //L COUNTRY.C L
  453. //L L
  454. //LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  455. BOOL
  456. ConimeHotkey(
  457. HWND hWnd,
  458. HANDLE hConsole,
  459. DWORD HotkeyID
  460. );
  461. BOOL
  462. GetIMEName(
  463. PCONSOLE_TABLE ConTbl
  464. );
  465. BOOL
  466. GetOpenStatusByCodepage(
  467. HIMC hIMC,
  468. PCONSOLE_TABLE ConTbl
  469. );
  470. BOOL
  471. ImeUIMakeInfoString(
  472. PCONSOLE_TABLE ConTbl,
  473. LPCONIME_UIMODEINFO lpModeInfo
  474. );
  475. BOOL
  476. MakeInfoStringJapan(
  477. PCONSOLE_TABLE ConTbl,
  478. LPCONIME_UIMODEINFO lpModeInfo
  479. );
  480. BOOL
  481. MakeInfoStringTaiwan(
  482. PCONSOLE_TABLE ConTbl,
  483. LPCONIME_UIMODEINFO lpModeInfo
  484. );
  485. DWORD
  486. MakeStatusStrTaiwan1(
  487. PCONSOLE_TABLE ConTbl,
  488. LPCONIME_UIMODEINFO lpModeInfo,
  489. DWORD ModeInfoPtr
  490. );
  491. DWORD
  492. MakeStatusStrTaiwan2(
  493. PCONSOLE_TABLE ConTbl,
  494. LPCONIME_UIMODEINFO lpModeInfo,
  495. DWORD ModeInfoPtr
  496. );
  497. DWORD
  498. IncludeCompositionT(
  499. PCONSOLE_TABLE ConTbl,
  500. LPCONIME_UIMODEINFO lpModeInfo,
  501. DWORD ModeInfoPtr
  502. );
  503. DWORD
  504. IncludeCandidateT(
  505. PCONSOLE_TABLE ConTbl,
  506. LPCONIME_UIMODEINFO lpModeInfo,
  507. DWORD ModeInfoPtr
  508. );
  509. DWORD
  510. DispLenStructedUnicode(
  511. PCHAR_INFO lpString,
  512. DWORD SrcLength
  513. );
  514. BOOL
  515. MakeInfoStringPRC(
  516. PCONSOLE_TABLE ConTbl,
  517. LPCONIME_UIMODEINFO lpModeInfo
  518. );
  519. DWORD
  520. MakeStatusStrPRC1(
  521. PCONSOLE_TABLE ConTbl,
  522. LPCONIME_UIMODEINFO lpModeInfo,
  523. DWORD ModeInfoPtr
  524. );
  525. DWORD
  526. MakeStatusStrPRC2(
  527. PCONSOLE_TABLE ConTbl,
  528. LPCONIME_UIMODEINFO lpModeInfo,
  529. DWORD ModeInfoPtr
  530. );
  531. DWORD
  532. IncludeCompositionP(
  533. PCONSOLE_TABLE ConTbl,
  534. LPCONIME_UIMODEINFO lpModeInfo,
  535. DWORD ModeInfoPtr
  536. );
  537. DWORD
  538. IncludeCandidateP(
  539. PCONSOLE_TABLE ConTbl,
  540. LPCONIME_UIMODEINFO lpModeInfo,
  541. DWORD ModeInfoPtr
  542. );
  543. BOOL
  544. MakeInfoStringKorea(
  545. PCONSOLE_TABLE ConTbl,
  546. LPCONIME_UIMODEINFO lpModeInfo
  547. );
  548. //LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  549. //L L
  550. //L COUNTRY2.C L
  551. //L L
  552. //LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  553. BOOL
  554. ImeUIOpenCandidate(
  555. HWND hwnd,
  556. DWORD lParam,
  557. BOOL OpenFlag
  558. );
  559. BOOL
  560. OpenCandidateJapan(
  561. HWND hwnd,
  562. HIMC hIMC,
  563. PCONSOLE_TABLE ConTbl,
  564. DWORD CandList,
  565. BOOL OpenFlag
  566. );
  567. BOOL
  568. OpenCandidateTaiwan(
  569. HWND hwnd,
  570. HIMC hIMC ,
  571. PCONSOLE_TABLE ConTbl,
  572. DWORD CandList,
  573. BOOL OpenFlag
  574. );
  575. BOOL
  576. OpenCandidatePRC(
  577. HWND hwnd,
  578. HIMC hIMC ,
  579. PCONSOLE_TABLE ConTbl,
  580. DWORD CandList,
  581. BOOL OpenFlag
  582. );
  583. BOOL
  584. OpenCandidateKorea(
  585. HWND hwnd,
  586. HIMC hIMC ,
  587. PCONSOLE_TABLE ConTbl,
  588. DWORD CandList,
  589. BOOL OpenFlag
  590. );
  591. DWORD
  592. DispLenUnicode(
  593. LPWSTR lpString
  594. );
  595. DWORD
  596. GetSystemLineJ(
  597. LPCANDIDATELIST lpCandList ,
  598. LPWSTR String,
  599. LPSTR Attr,
  600. DWORD dwLength,
  601. DWORD CountDispWidth,
  602. PCONSOLE_TABLE FocusedConsole,
  603. BOOL EnableCodePoint
  604. );
  605. DWORD
  606. GetSystemLineT(
  607. LPCANDIDATELIST lpCandList ,
  608. LPWSTR String,
  609. LPSTR Attr,
  610. DWORD dwLength,
  611. DWORD CountDispWidth,
  612. PCONSOLE_TABLE FocusedConsole
  613. );
  614. DWORD
  615. GetSystemLineP(
  616. LPCANDIDATELIST lpCandList ,
  617. LPWSTR String,
  618. LPSTR Attr,
  619. DWORD dwLength,
  620. DWORD CountDispWidth,
  621. PCONSOLE_TABLE FocusedConsole
  622. );
  623. VOID
  624. NumString(
  625. LPWSTR StrToWrite,
  626. DWORD NumToDisp,
  627. DWORD CountDispWidth
  628. );
  629. BOOL
  630. ImeUICloseCandidate(
  631. HWND hwnd,
  632. DWORD lParam
  633. );
  634. BOOL
  635. CloseCandidateJapan(
  636. HWND hwnd,
  637. HIMC hIMC,
  638. PCONSOLE_TABLE ConTbl,
  639. DWORD CandList
  640. );
  641. BOOL
  642. CloseCandidateTaiwan(
  643. HWND hwnd,
  644. HIMC hIMC,
  645. PCONSOLE_TABLE ConTbl,
  646. DWORD CandList
  647. );
  648. BOOL
  649. CloseCandidatePRC(
  650. HWND hwnd,
  651. HIMC hIMC,
  652. PCONSOLE_TABLE ConTbl,
  653. DWORD CandList
  654. );
  655. BOOL
  656. CloseCandidateKorea(
  657. HWND hwnd,
  658. HIMC hIMC,
  659. PCONSOLE_TABLE ConTbl,
  660. DWORD CandList
  661. );
  662. //LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  663. //L L
  664. //L COUNTRY3.C L
  665. //L L
  666. //LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  667. void
  668. GetCompositionStr(
  669. HWND hwnd,
  670. LPARAM CompFlag,
  671. WPARAM CompChar
  672. );
  673. void
  674. GetCompStrJapan(
  675. HWND hwnd,
  676. PCONSOLE_TABLE ConTbl,
  677. LPARAM CompFlag
  678. );
  679. void
  680. GetCompStrTaiwan(
  681. HWND hwnd,
  682. PCONSOLE_TABLE ConTbl,
  683. LPARAM CompFlag
  684. );
  685. void
  686. GetCompStrPRC(
  687. HWND hwnd,
  688. PCONSOLE_TABLE ConTbl,
  689. LPARAM CompFlag
  690. );
  691. void
  692. GetCompStrKorea(
  693. HWND hwnd,
  694. PCONSOLE_TABLE ConTbl,
  695. LPARAM CompFlag,
  696. WPARAM CompChar
  697. );
  698. VOID
  699. ReDisplayCompositionStr (
  700. HWND hwnd
  701. );
  702. VOID
  703. ReDisplayCompStrJapan(
  704. HWND hwnd,
  705. PCONSOLE_TABLE ConTbl
  706. );
  707. VOID
  708. ReDisplayCompStrTaiwan(
  709. HWND hwnd,
  710. PCONSOLE_TABLE ConTbl
  711. );
  712. VOID
  713. ReDisplayCompStrPRC(
  714. HWND hwnd,
  715. PCONSOLE_TABLE ConTbl
  716. );
  717. VOID
  718. ReDisplayCompStrKorea(
  719. HWND hwnd,
  720. PCONSOLE_TABLE ConTbl
  721. );