Source code of Windows XP (NT5)
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.

1255 lines
34 KiB

  1. /*************************************************
  2. * lctool.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. // Change's Note
  8. //
  9. #include <windows.h> // required for all Windows applications
  10. #include <windowsx.h>
  11. #include <commctrl.h>
  12. #include <htmlhelp.h>
  13. #include "rc.h"
  14. #include "lctool.h"
  15. #include "movelst.h"
  16. #define LC_CLASS _TEXT("LcToolWClass")
  17. #define LC_SUBCLASS _TEXT("LcToolSubWClass")
  18. #define HELPNAME _TEXT("LCTOOL.CHM")
  19. #define X_ITEM_1 40
  20. #define X_ITEM_2 120
  21. #define Y_ITEM_1 10
  22. #define Y_ITEM_2 30
  23. #define Y_ITEM_3 20
  24. #define ALLOCBLOCK 3000
  25. #define STATE_ON 0x8000
  26. #define TOTALSCALE 500
  27. #define LINESHIFT 2
  28. #define PAGESHIFT 10
  29. #ifndef UNICODE
  30. #define lWordBuff iWordBuff
  31. #define lPhraseBuff iPhraseBuff
  32. #define lNext_Seg iNext_Seg
  33. #endif
  34. typedef struct{
  35. WORD wKey;
  36. USHORT uState;
  37. WPARAM wID;
  38. } FUNCKEYBUF, FAR *LPFUNCKEYBUF;
  39. FUNCKEYBUF lpFuncKey[]={
  40. #if defined(DEBUG)
  41. { 'N', CTRL_STATE, IDM_NEW }, // for debug
  42. #endif
  43. //{ 'Z', CTRL_STATE, IDM_UNDO },
  44. //{ 'X', CTRL_STATE, IDM_CUT },
  45. //{ 'C', CTRL_STATE, IDM_COPY },
  46. //{ 'V', CTRL_STATE, IDM_PASTE },
  47. { VK_DELETE, 0, IDM_CLEAR },
  48. { 'D', CTRL_STATE, IDM_DELETEL },
  49. { VK_RETURN, 0, IDM_INSERTL },
  50. { VK_F3, 0, IDM_SNEXT }
  51. };
  52. UINT nFuncKey=sizeof(lpFuncKey)/sizeof(FUNCKEYBUF);
  53. HFONT hFont;
  54. char szAppName[9];
  55. UINT CharWidth;
  56. UINT CharHeight;
  57. UINT line_height;
  58. int nWidth;
  59. int nHeight;
  60. int cxHD0 = 50, cxHD1 = 30, cxHD2 = 200, cyHD;
  61. int cyCaption, cyMenu;
  62. HWND subhWnd;
  63. TCHAR szPhrasestr[MAX_CHAR_NUM];
  64. // Local function prototypes.
  65. BOOL InitApplication(HINSTANCE);
  66. BOOL InitInstance(HINSTANCE, int);
  67. void lcPaint(HWND);
  68. BOOL lcInit(HWND);
  69. void lcResize(HWND hwnd);
  70. BOOL lcTranslateMsg(MSG *);
  71. void lcMoveEditWindow(HWND hwnd, int nOffset);
  72. void lcOrgEditWindow();
  73. void draw_horz_header(HWND hwnd);
  74. void draw_vert_header(HWND hwnd);
  75. void draw_box0(HDC hdc, int, int, int, int);
  76. void draw_box1(HDC hdc, int, int, int, int);
  77. // FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  78. //
  79. // PURPOSE: calls initialization function, processes message loop
  80. //
  81. //
  82. int APIENTRY WinMain(
  83. HINSTANCE hInstance,
  84. HINSTANCE hPrevInstance,
  85. LPSTR lpCmdLine,
  86. int nCmdShow)
  87. {
  88. MSG msg;
  89. // Other instances of app running?
  90. if (hPrevInstance)
  91. {
  92. return FALSE; // Exits if there is another instance
  93. } else {
  94. // Initialize shared things
  95. if (!InitApplication(hInstance))
  96. return FALSE; // Exits if unable to initialize
  97. }
  98. // Perform initializations that apply to a specific instance
  99. if (!InitInstance(hInstance, nCmdShow))
  100. return FALSE;
  101. // Acquire and dispatch messages until a WM_QUIT message is received.
  102. while (GetMessage(&msg, NULL, 0, 0))
  103. {
  104. if(!lcTranslateMsg(&msg)) {
  105. TranslateMessage(&msg);
  106. DispatchMessage(&msg);
  107. }
  108. }
  109. // Returns the value from PostQuitMessage
  110. return (INT)(msg.wParam);
  111. }
  112. BOOL InitApplication(
  113. HINSTANCE hInstance)
  114. {
  115. WNDCLASSEX wc;
  116. hCursorArrow = LoadCursor(NULL,IDC_ARROW);
  117. hCursorWait = LoadCursor(NULL, IDC_WAIT);
  118. // Fill in window class structure with parameters that describe the
  119. // main window.
  120. wc.cbSize = sizeof(WNDCLASSEX);
  121. wc.style = CS_DBLCLKS; //|CS_HREDRAW | CS_VREDRAW; // Class style(s).
  122. wc.lpfnWndProc = (WNDPROC)WndProc; // Window Procedure
  123. wc.cbClsExtra = 0; // No per-class extra data.
  124. wc.cbWndExtra = 0; // No per-window extra data.
  125. wc.hInstance = hInstance; // Owner of this class
  126. wc.hIcon = LoadImage(hInstance,_TEXT("ALogIcon"),
  127. IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
  128. #ifdef UNICODE
  129. wc.hIconSm = NULL;
  130. #else
  131. wc.hIconSm = LoadImage(hInstance,_TEXT("ALogIcon"),
  132. IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
  133. #endif
  134. wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Cursor
  135. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); // Light Gray color
  136. wc.lpszMenuName = _TEXT("LcToolMenu");
  137. wc.lpszClassName =LC_CLASS;
  138. // Register the window class and return FALSE if unsuccesful.
  139. if (!RegisterClassEx(&wc))
  140. {
  141. return FALSE;
  142. }
  143. wc.cbSize = sizeof(WNDCLASSEX);
  144. wc.style = CS_DBLCLKS; //|CS_HREDRAW | CS_VREDRAW; // Class style(s).
  145. wc.lpfnWndProc = (WNDPROC)WndSubProc; // Window Procedure
  146. wc.cbClsExtra = 0; // No per-class extra data.
  147. wc.cbWndExtra = 0; // No per-window extra data.
  148. wc.hInstance = hInstance; // Owner of this class
  149. wc.hIcon = 0;
  150. wc.hIconSm = 0;
  151. wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Cursor
  152. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); // Light Gray color
  153. wc.lpszMenuName = NULL,
  154. wc.lpszClassName = LC_SUBCLASS;
  155. if (!RegisterClassEx(&wc))
  156. {
  157. return FALSE;
  158. }
  159. wc.cbSize = sizeof(WNDCLASSEX);
  160. wc.style = 0;
  161. wc.lpfnWndProc = (WNDPROC)ClassDlgProc;
  162. wc.cbClsExtra = 0; // No per-class extra data.
  163. wc.cbWndExtra = DLGWINDOWEXTRA;
  164. wc.hInstance = hInstance;
  165. wc.hIcon = 0;
  166. wc.hIconSm = 0;
  167. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  168. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  169. wc.lpszMenuName = NULL;
  170. wc.lpszClassName = _TEXT("PrivDlgClass");
  171. if (!RegisterClassEx(&wc))
  172. {
  173. return FALSE;
  174. }
  175. return TRUE;
  176. }
  177. BOOL InitInstance(
  178. HINSTANCE hInstance,
  179. int nCmdShow)
  180. {
  181. HWND hwnd; // Main window handle.
  182. HDC hDC;
  183. TEXTMETRIC tm;
  184. RECT rect;
  185. TCHAR szTitle[MAX_PATH];
  186. TCHAR szFont[MAX_PATH];
  187. HFONT hSysFont;
  188. LOGFONT lfEditFont;
  189. UINT scrollCy, scrollCx;
  190. DWORD style;
  191. LoadString(hInstance, IDS_MAIN_TITLE,szTitle, sizeof(szTitle)/sizeof(TCHAR));
  192. hInst = hInstance; // Store instance handle in our global variable
  193. /* create fixed pitch font as default font */
  194. hSysFont=GetStockObject(SYSTEM_FIXED_FONT);
  195. GetObject(hSysFont, sizeof(LOGFONT), &lfEditFont);
  196. lfEditFont.lfWeight = 400;
  197. lfEditFont.lfHeight = 12;
  198. lfEditFont.lfWidth = lfEditFont.lfHeight/2;
  199. lfEditFont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
  200. LoadString(hInstance, IDS_FONT_NAME,szFont, sizeof(szFont)/sizeof(TCHAR));
  201. lstrcpy(lfEditFont.lfFaceName, szFont);
  202. /* create the logical font */
  203. hFont = CreateFontIndirect(&lfEditFont);
  204. hDC = GetDC(NULL);
  205. SelectObject(hDC, hFont);
  206. GetTextMetrics(hDC, &tm);
  207. ReleaseDC(NULL, hDC);
  208. rect.top = tm.tmHeight ;
  209. rect.left = rect.top;
  210. CharWidth=tm.tmAveCharWidth;
  211. CharHeight=tm.tmHeight + 10;
  212. line_height=CharHeight - 1;
  213. iPage_line=rect.top*22/line_height;
  214. if(iPage_line > MAX_LINE)
  215. iPage_line=MAX_LINE;
  216. nWidth=rect.top*33;
  217. cyCaption = GetSystemMetrics(SM_CYCAPTION);
  218. cyMenu = GetSystemMetrics(SM_CYMENU);
  219. nHeight = line_height * iPage_line + CharHeight + cyCaption + cyMenu + 12; //3;
  220. cxHD1 = MulDiv(CharWidth * 2, 96, 72) * 2; // <== @E02
  221. //cxHD2 = nWidth - cxHD0 - cxHD1 + 1;
  222. cxHD2 = MulDiv(CharWidth * 2, 96, 72) * MAX_CHAR_NUM;
  223. scrollCy = GetSystemMetrics(SM_CYHSCROLL);
  224. #ifndef UNICODE
  225. scrollCy += 2;
  226. #endif
  227. scrollCx = GetSystemMetrics(SM_CXVSCROLL);
  228. // Create a main window for this application instance.
  229. style = (WS_CAPTION | WS_SYSMENU | WS_THICKFRAME |
  230. WS_MINIMIZEBOX | WS_MAXIMIZEBOX); // & (~WS_VSCROLL),
  231. hwnd = CreateWindowEx(
  232. WS_EX_CLIENTEDGE,
  233. LC_CLASS,
  234. szTitle,
  235. style,
  236. rect.left,
  237. rect.top,
  238. nWidth,
  239. nHeight + scrollCy,
  240. HWND_DESKTOP,
  241. NULL,
  242. hInstance,
  243. NULL
  244. );
  245. // If window could not be created, return "failure"
  246. if (!hwnd)
  247. return FALSE;
  248. //InitCommonControls();
  249. hwndMain=hwnd;
  250. hMenu=GetMenu(hwnd);
  251. // Make the window visible; update its client area; and return "success"
  252. ShowWindow(hwnd, nCmdShow); // Show the window
  253. // UpdateWindow(hwnd); // Sends WM_PAINT message
  254. // Reset the search phrase
  255. szPhrasestr[0] = 0;
  256. return TRUE;
  257. }
  258. LRESULT CALLBACK WndProc(
  259. HWND hwnd,
  260. UINT message,
  261. WPARAM wParam,
  262. LPARAM lParam)
  263. {
  264. HWND hwndEdit;
  265. DWORD dw; /* return value from various messages */
  266. UINT EnableOrNot; /* is something currently selected? */
  267. TCHAR szTitle[MAX_PATH];
  268. TCHAR szMsg1[MAX_PATH];
  269. BOOL bResult;
  270. switch (message) {
  271. case WM_COMMAND:
  272. if(HIWORD(wParam) == EN_SETFOCUS) {
  273. lcEditFocusOn(LOWORD(wParam));
  274. break;
  275. }
  276. switch (wParam) {
  277. case IDM_SAVE:
  278. SetCursor(hCursorWait);
  279. #ifdef UNICODE
  280. bResult = lcFSave(hwnd, FALSE);
  281. #else
  282. bResult = lcFSave(hwnd);
  283. #endif
  284. SetCursor(hCursorArrow);
  285. InvalidateRect(hwnd, NULL, TRUE);
  286. draw_vert_header(hwnd);
  287. if (bResult) {
  288. LoadString(hInst, IDS_APPNAME, szMsg1, sizeof(szMsg1));
  289. #ifdef UNICODE
  290. LoadString(hInst, IDS_ACTIVATED, szTitle, sizeof(szTitle));
  291. #else
  292. LoadString(hInst, IDS_WILLBEACTIVATED, szTitle, sizeof(szTitle));
  293. #endif
  294. MessageBox(hwndMain, szTitle, szMsg1, MB_OK | MB_ICONEXCLAMATION);
  295. }
  296. break;
  297. #ifdef UNICODE
  298. case IDM_SAVEAS:
  299. SetCursor(hCursorWait);
  300. bResult = lcFSave(hwnd, TRUE);
  301. SetCursor(hCursorArrow);
  302. InvalidateRect(hwnd, NULL, TRUE);
  303. draw_vert_header(hwnd);
  304. if (bResult) {
  305. LoadString(hInst, IDS_APPNAME, szMsg1, sizeof(szMsg1));
  306. LoadString(hInst, IDS_WILLBEACTIVATED, szTitle, sizeof(szTitle));
  307. MessageBox(hwndMain, szTitle, szMsg1, MB_OK | MB_ICONEXCLAMATION);
  308. }
  309. break;
  310. #endif
  311. case IDM_APPEND: //@D01A
  312. SetCursor(hCursorWait); //@D01A
  313. lcAppend(hwnd); //@D03C
  314. SetCursor(hCursorArrow); //@D01A
  315. break; //@D01A
  316. case IDM_IMPORT:
  317. // Clear all flag first
  318. SetCursor(hCursorWait);
  319. lcImport(hwnd);
  320. SetCursor(hCursorArrow);
  321. InvalidateRect(hwnd, NULL, TRUE);
  322. break;
  323. #ifdef UNICODE
  324. case IDM_EXPORT2BIG5:
  325. SetCursor(hCursorWait);
  326. lcExport(hwnd,FILE_BIG5);
  327. SetCursor(hCursorArrow);
  328. break;
  329. #endif
  330. case IDM_EXPORT:
  331. SetCursor(hCursorWait);
  332. #ifdef UNICODE
  333. lcExport(hwnd,FILE_UNICODE);
  334. #else
  335. lcExport(hwnd);
  336. #endif
  337. SetCursor(hCursorArrow);
  338. break;
  339. case IDM_PRINT:
  340. {
  341. int nRes;
  342. nRes=lcPrint(hwnd);
  343. SetCursor(hCursorArrow);
  344. if(nRes != TRUE)
  345. lcErrMsg(nRes);
  346. }
  347. break;
  348. case IDM_EXIT :
  349. if(!lcQuerySave(hwnd))
  350. break;
  351. DestroyWindow(hwnd);
  352. return (TRUE);
  353. case IDM_UNDO:
  354. PostMessage( GetFocus(), WM_UNDO, 0, 0);
  355. break;
  356. case IDM_CUT:
  357. PostMessage( GetFocus(), WM_CUT, 0, 0);
  358. break;
  359. case IDM_COPY:
  360. PostMessage( GetFocus(), WM_COPY, 0, 0);
  361. break;
  362. case IDM_PASTE:
  363. PostMessage( GetFocus(), WM_PASTE, 0, 0);
  364. break;
  365. case IDM_CLEAR:
  366. PostMessage( GetFocus(), WM_CLEAR, 0, 0);
  367. break;
  368. case IDM_DELETEL:
  369. lcDelLine(hwnd);
  370. lcOrgEditWindow();
  371. break;
  372. case IDM_INSERTL:
  373. lcInsLine(hwnd);
  374. lcOrgEditWindow();
  375. break;
  376. case IDM_SORT:
  377. SetCursor(hCursorWait);
  378. lcSort(hwnd);
  379. SetCursor(hCursorArrow);
  380. lcOrgEditWindow();
  381. InvalidateRect(hwnd, NULL, TRUE);
  382. draw_vert_header(hwnd);
  383. break;
  384. case IDM_GOTO:
  385. lcGoto(hwnd);
  386. lcOrgEditWindow();
  387. SetScrollPos(subhWnd, SB_VERT, yPos, TRUE);
  388. return ((LONG)TRUE);
  389. case IDM_SEARCH:
  390. lcSearch(hwnd, FALSE);
  391. SetScrollPos(subhWnd, SB_VERT, yPos, TRUE);
  392. draw_vert_header(hwndMain);
  393. return ((LONG)TRUE);
  394. case IDM_SNEXT:
  395. lcSearch(hwnd, TRUE);
  396. SetScrollPos(subhWnd, SB_VERT, yPos, TRUE);
  397. draw_vert_header(hwndMain);
  398. return ((LONG)TRUE);
  399. case IDM_CHGSEQ:
  400. lcChangeSequence(hwnd);
  401. InvalidateRect(hwnd, NULL, TRUE);
  402. return ((LONG)TRUE);
  403. case IDM_ABOUT :
  404. LoadString(hInst, IDS_MAIN_TITLE, szTitle, sizeof(szTitle));
  405. ShellAbout(hwnd, szTitle,_TEXT(""), LoadIcon(hInst,_TEXT("ALogIcon")));
  406. return ((LONG)TRUE);
  407. case IDM_HELP :
  408. // if(!WinHelp(hwnd, HELPNAME, HELP_FINDER, 0L))
  409. if ( !HtmlHelp(hwnd, HELPNAME, HH_DISPLAY_TOPIC, 0L) )
  410. lcErrMsg(IDS_ERR_MEMORY);
  411. return ((LONG)TRUE);
  412. case IDM_VSCROLL :
  413. SetScrollPos(subhWnd, SB_VERT, yPos, TRUE);
  414. return ((LONG)TRUE);
  415. }
  416. break;
  417. case WM_INITMENUPOPUP: /* wParam is menu handle */
  418. // Check save file
  419. lcQueryModify(hwnd);
  420. /* Enable the 'Save' option if any modified */
  421. EnableMenuItem((HMENU)wParam, IDM_SAVE,
  422. (UINT)(bSaveFile ? MF_ENABLED : MF_GRAYED));
  423. EnableMenuItem((HMENU)wParam, IDM_SAVEAS,
  424. (UINT)(bSaveFile ? MF_ENABLED : MF_GRAYED));
  425. /* Find out if something is currently selected in the edit box */
  426. hwndEdit=GetFocus();
  427. dw = (DWORD)SendMessage(hwndEdit,EM_GETSEL,0,0L);
  428. EnableOrNot = (UINT)((HIWORD(dw) != LOWORD(dw) ? MF_ENABLED : MF_GRAYED));
  429. /* Enable / disable the Edit menu options appropriately */
  430. EnableMenuItem ((HMENU)wParam, IDM_UNDO ,
  431. (UINT)(SendMessage(hwndEdit,EM_CANUNDO,0,0L) ? MF_ENABLED : MF_GRAYED));
  432. EnableMenuItem ((HMENU)wParam, IDM_CUT , EnableOrNot);
  433. EnableMenuItem ((HMENU)wParam, IDM_COPY , EnableOrNot);
  434. EnableMenuItem ((HMENU)wParam, IDM_PASTE,
  435. (UINT)(IsClipboardFormatAvailable(CF_TEXT) ? MF_ENABLED : MF_GRAYED));
  436. EnableMenuItem ((HMENU)wParam, IDM_CLEAR, EnableOrNot);
  437. break;
  438. case WM_CREATE:
  439. SendMessage (hwnd, WM_SETFONT, (WPARAM)hFont, 0);
  440. if(!lcInit(hwnd))
  441. PostMessage(hwnd, WM_CLOSE, 0, 0);
  442. break;
  443. case WM_SIZE:
  444. nWidth=LOWORD(lParam);
  445. nHeight=HIWORD(lParam);
  446. if (wParam != SIZE_MINIMIZED)
  447. lcResize(hwnd);
  448. return (DefWindowProc(hwnd, message, wParam, lParam));
  449. case WM_PAINT:
  450. lcPaint(hwnd);
  451. break;
  452. case WM_CLOSE:
  453. if(!lcQuerySave(hwnd))
  454. break;
  455. DestroyWindow(hwnd);
  456. break;
  457. case WM_DESTROY:
  458. PostQuitMessage(0);
  459. GlobalUnlock(hWord);
  460. GlobalUnlock(hPhrase);
  461. GlobalFree(hWord);
  462. GlobalFree(hPhrase);
  463. break;
  464. default:
  465. return (DefWindowProc(hwnd, message, wParam, lParam));
  466. }
  467. return TRUE;
  468. }
  469. BOOL lcInit(
  470. HWND hwnd)
  471. {
  472. TCHAR *pszFilterSpec;
  473. TCHAR szStr[MAX_PATH];
  474. UINT i;
  475. DWORD style = WS_VISIBLE | WS_CHILD | ES_LEFT;
  476. RECT rect;
  477. int scrollBarWidth, scrollCy;
  478. // style &= (~WS_BORDER);
  479. scrollBarWidth = GetSystemMetrics(SM_CXVSCROLL);
  480. GetClientRect(hwnd, &rect);
  481. cxHD2 = (rect.right - rect.left) - cxHD0 - cxHD1 + 1;
  482. cyHD = CharHeight - 1;
  483. scrollCy = GetSystemMetrics(SM_CYHSCROLL);
  484. subhWnd=CreateWindowEx(
  485. 0,
  486. LC_SUBCLASS,
  487. NULL,
  488. (style | WS_HSCROLL | WS_VSCROLL), // | WS_BORDER),
  489. cxHD0 + cxHD1 - 1, CharHeight,
  490. cxHD2 + 1, CharHeight + (iPage_line - 1) * line_height + scrollCy,
  491. hwnd,
  492. NULL,
  493. hInst,
  494. NULL
  495. );
  496. // Create EDIT CONTROL
  497. for(i=0; i<iPage_line; i++)
  498. {
  499. hwndWord[i]=CreateWindowEx(
  500. WS_EX_CLIENTEDGE,
  501. _TEXT("EDIT"),
  502. NULL,
  503. style /*|ES_CENTER*/ | WS_BORDER,
  504. cxHD0, CharHeight+i*line_height,
  505. cxHD1 - 1, CharHeight,
  506. hwnd,
  507. (HMENU)UIntToPtr( (IDE_WORD_START+i) ),
  508. hInst,
  509. NULL
  510. );
  511. hwndPhrase[i]=CreateWindowEx(
  512. WS_EX_CLIENTEDGE,
  513. _TEXT("EDIT"),
  514. NULL,
  515. style /*| ES_CENTER | ES_AUTOHSCROLL*/ | WS_BORDER,
  516. -1, i*line_height,
  517. MulDiv(CharWidth * 2, 96, 72) * MAX_CHAR_NUM,
  518. CharHeight,
  519. subhWnd,
  520. (HMENU)UIntToPtr( (IDE_PHRASE_START+i) ),
  521. hInst,
  522. NULL
  523. );
  524. SendMessage(hwndWord[i], EM_SETLIMITTEXT, 2, 0);
  525. SendMessage(hwndPhrase[i], EM_SETLIMITTEXT, MAX_CHAR_NUM-1, 0);
  526. SendMessage(hwndWord[i], WM_SETFONT, (WPARAM)hFont,
  527. MAKELPARAM(TRUE, 0));
  528. SendMessage(hwndPhrase[i], WM_SETFONT, (WPARAM)hFont,
  529. MAKELPARAM(TRUE, 0));
  530. }
  531. hwndFocus=hwndWord[0];
  532. // Allocate global memory
  533. hWord = GlobalAlloc(GMEM_MOVEABLE, ALLOCBLOCK*sizeof(WORDBUF));
  534. if(!hWord) {
  535. lcErrMsg(IDS_ERR_MEMORY_QUIT);
  536. return FALSE;
  537. }
  538. nWordBuffsize = ALLOCBLOCK;
  539. lWordBuff = 0;
  540. lpWord = (LPWORDBUF)GlobalLock(hWord);
  541. if(!lpWord) {
  542. lcErrMsg(IDS_ERR_MEMORY_QUIT);
  543. return FALSE;
  544. }
  545. hPhrase = GlobalAlloc(GMEM_MOVEABLE, ALLOCBLOCK*sizeof(PHRASEBUF));
  546. if(!hPhrase) {
  547. GlobalFree(hWord);
  548. lcErrMsg(IDS_ERR_MEMORY_QUIT);
  549. return FALSE;
  550. }
  551. nPhraseBuffsize = ALLOCBLOCK;
  552. lPhraseBuff = 0;
  553. lpPhrase = (LPPHRASEBUF)GlobalLock(hPhrase);
  554. if(!lpPhrase) {
  555. GlobalFree(hWord);
  556. lcErrMsg(IDS_ERR_MEMORY_QUIT);
  557. return FALSE;
  558. }
  559. iFirstFree=NULL_SEG;
  560. // Read file to memory
  561. SetCursor(hCursorWait);
  562. lcFOpen(hwnd);
  563. SetCursor(hCursorArrow);
  564. if(lWordBuff == 0)
  565. lcInsLine(hwnd);
  566. iDisp_Top=0;
  567. yPos=0;
  568. xPos=0;
  569. bSaveFile=FALSE;
  570. SetScrollRange(subhWnd, SB_VERT, 0, lWordBuff-iPage_line, TRUE);
  571. SetScrollPos(subhWnd, SB_VERT, yPos, TRUE);
  572. SetScrollRange(subhWnd, SB_HORZ, 0, TOTALSCALE, TRUE);
  573. SetScrollPos(subhWnd, SB_HORZ, xPos, TRUE);
  574. lcSetEditText(iDisp_Top, TRUE);
  575. SetFocus(hwndWord[0]);
  576. if(!GetPrinterConfig(hwnd))
  577. lcErrMsg(IDS_PTRCONFIGFAILED);
  578. // Initial filter spec
  579. LoadString (hInst, IDS_FILTERSPEC, szFilterSpec, sizeof(szFilterSpec));
  580. LoadString (hInst, IDS_DEFAULTFILEEXT, szExt, sizeof(szExt));
  581. pszFilterSpec=szFilterSpec;
  582. pszFilterSpec+=lstrlen(pszFilterSpec)+1;
  583. lstrcpy(pszFilterSpec,szExt);
  584. LoadString (hInst, IDS_FILTERSPEC_ALL, szStr, sizeof(szStr));
  585. pszFilterSpec+=lstrlen(pszFilterSpec)+1;
  586. lstrcpy(pszFilterSpec,szStr);
  587. LoadString (hInst, IDS_ALLFILEEXT, szStr, sizeof(szStr));
  588. pszFilterSpec+=lstrlen(pszFilterSpec)+1;
  589. lstrcpy(pszFilterSpec,szStr);
  590. pszFilterSpec+=lstrlen(pszFilterSpec)+1;
  591. *pszFilterSpec=0;
  592. return TRUE;
  593. }
  594. LRESULT CALLBACK WndSubProc(
  595. HWND hwnd,
  596. UINT message,
  597. WPARAM wParam,
  598. LPARAM lParam)
  599. {
  600. int nOffset;
  601. switch (message) {
  602. case WM_CREATE:
  603. SendMessage (hwnd, WM_SETFONT, (WPARAM)hFont, 0);
  604. break;
  605. case WM_SETFOCUS:
  606. if(hwnd != hwndFocus)
  607. SetFocus(hwndFocus);
  608. break;
  609. case WM_VSCROLL:
  610. switch((int)LOWORD(wParam)){
  611. case SB_LINEUP :
  612. lcUp_key(GetFocus());
  613. break;
  614. case SB_LINEDOWN :
  615. lcDown_key(GetFocus());
  616. break;
  617. case SB_PAGEUP :
  618. lcPgUp_key(GetFocus());
  619. break;
  620. case SB_PAGEDOWN :
  621. lcPgDown_key(GetFocus());
  622. break;
  623. case SB_THUMBPOSITION :
  624. yPos=HIWORD(wParam);
  625. if(lWordBuff < iPage_line)
  626. yPos=0;
  627. if(((UINT)yPos) < iPage_line)
  628. yPos=0;
  629. if(!lcSetEditText(yPos, TRUE)) {
  630. yPos=iDisp_Top;
  631. break;
  632. }
  633. iDisp_Top=yPos;
  634. break;
  635. } //switch(wParam)
  636. SetScrollPos(hwnd, SB_VERT, yPos, TRUE);
  637. draw_vert_header(hwndMain);
  638. break;
  639. case WM_HSCROLL:
  640. nOffset = 0;
  641. switch((int)LOWORD(wParam)){
  642. case SB_LINELEFT :
  643. nOffset = -LINESHIFT;
  644. break;
  645. case SB_LINERIGHT :
  646. nOffset = LINESHIFT;
  647. break;
  648. case SB_PAGELEFT :
  649. nOffset = -PAGESHIFT;
  650. break;
  651. case SB_PAGERIGHT :
  652. nOffset = PAGESHIFT;
  653. break;
  654. case SB_THUMBPOSITION :
  655. nOffset=HIWORD(wParam) - xPos;
  656. break;
  657. } //switch(wParam)
  658. if (xPos + nOffset < 0) nOffset = -xPos;
  659. if (xPos + nOffset > TOTALSCALE) nOffset = TOTALSCALE - xPos;
  660. xPos += nOffset;
  661. SetScrollPos(hwnd, SB_HORZ, xPos, TRUE);
  662. lcMoveEditWindow(hwnd, nOffset);
  663. break;
  664. case WM_CLOSE:
  665. DestroyWindow(hwnd);
  666. break;
  667. default:
  668. return (DefWindowProc(hwnd, message, wParam, lParam));
  669. }
  670. return 0;
  671. }
  672. void lcMoveEditWindow(
  673. HWND hwnd, int nOffset)
  674. {
  675. RECT baseRect, rect;
  676. UINT i, nTotalWidth;
  677. GetWindowRect(hwnd, &baseRect);
  678. #ifdef UNICODE
  679. nTotalWidth = MulDiv(CharWidth * 2, 96, 72) * MAX_CHAR_NUM;
  680. #else
  681. nTotalWidth = MulDiv(CharWidth * 2, 72, 96) * MAX_CHAR_NUM;
  682. #endif
  683. for(i=0; i<iPage_line; i++)
  684. {
  685. GetWindowRect(hwndPhrase[i], &rect);
  686. rect.left -= baseRect.left;
  687. rect.top -= baseRect.top;
  688. rect.left -= MulDiv(nTotalWidth, nOffset, TOTALSCALE);
  689. if (rect.left > -1) rect.left = -1;
  690. if (xPos == 0) rect.left = -1;
  691. SetWindowPos(hwndPhrase[i], NULL, rect.left, rect.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  692. }
  693. }
  694. void lcOrgEditWindow()
  695. {
  696. UINT i;
  697. xPos = 0;
  698. SetScrollPos(subhWnd, SB_HORZ, xPos, TRUE);
  699. for(i=0; i<iPage_line; i++)
  700. {
  701. SetWindowPos(hwndPhrase[i], NULL, -1, i*line_height, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  702. }
  703. }
  704. void lcMoveEditWindowByWord(UINT nWords)
  705. {
  706. RECT rect;
  707. UINT i, nTotalWidth, nOffset;
  708. #ifdef UNICODE
  709. nTotalWidth = MulDiv(CharWidth * 2, 96, 72) * MAX_CHAR_NUM;
  710. nOffset = MulDiv(CharWidth, 96, 72) * nWords;
  711. #else
  712. nTotalWidth = MulDiv(CharWidth * 2, 72, 96) * MAX_CHAR_NUM;
  713. nOffset = MulDiv(CharWidth, 72, 96) * nWords;
  714. #endif
  715. for(i=0; i<iPage_line; i++)
  716. {
  717. rect.left = -1;
  718. rect.top = i * line_height;
  719. rect.left -= nOffset;
  720. SetWindowPos(hwndPhrase[i], NULL, rect.left, rect.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  721. }
  722. xPos = MulDiv(nOffset, TOTALSCALE, nTotalWidth);
  723. SetScrollPos(subhWnd, SB_HORZ, xPos, TRUE);
  724. }
  725. void lcResize(
  726. HWND hwnd)
  727. {
  728. UINT i;
  729. DWORD style = WS_VISIBLE | WS_CHILD | ES_LEFT;
  730. RECT rect;
  731. int scrollBarWidth, scrollCy;
  732. int right, bottom;
  733. UINT iPage_line_old = iPage_line;
  734. static BOOL bResizePainted = TRUE;
  735. if (bResizePainted) {
  736. bResizePainted = FALSE;
  737. return;
  738. }
  739. // #53592 10/10/96
  740. /*
  741. for(i=0; i<iPage_line; i++)
  742. {
  743. DestroyWindow(hwndWord[i]);
  744. hwndWord[i] = 0;
  745. DestroyWindow(hwndPhrase[i]);
  746. hwndPhrase[i] = 0;
  747. }
  748. */
  749. iPage_line=nHeight/line_height;
  750. if(iPage_line > MAX_LINE)
  751. iPage_line=MAX_LINE;
  752. // #53592 10/10/96
  753. // Shrink, destroy extra edit control windows
  754. if (iPage_line < iPage_line_old)
  755. {
  756. for(i=iPage_line; i<iPage_line_old; i++)
  757. {
  758. DestroyWindow(hwndWord[i]);
  759. hwndWord[i] = 0;
  760. DestroyWindow(hwndPhrase[i]);
  761. hwndPhrase[i] = 0;
  762. }
  763. }
  764. nHeight = line_height * iPage_line + CharHeight + cyCaption + cyMenu+12 ;
  765. scrollBarWidth = GetSystemMetrics(SM_CXVSCROLL);
  766. scrollCy = GetSystemMetrics(SM_CYHSCROLL);
  767. #ifndef UNICODE
  768. scrollCy += 2;
  769. #endif
  770. right = nWidth + (2 * scrollBarWidth);
  771. bottom = nHeight + scrollCy;
  772. bResizePainted = TRUE;
  773. SetWindowPos(hwnd, NULL, 0, 0, right, bottom, SWP_NOMOVE | SWP_NOZORDER);
  774. GetClientRect(hwnd, &rect);
  775. cxHD2 = (rect.right - rect.left) - cxHD0 - cxHD1 + 1;
  776. right = cxHD2 + 1;
  777. bottom = CharHeight + (iPage_line - 1) * line_height + scrollCy;
  778. SetWindowPos(subhWnd, NULL, 0, 0, right, bottom, SWP_NOMOVE | SWP_NOZORDER);
  779. cyHD = CharHeight - 1;
  780. // #53592 10/10/96
  781. // Create extra EDIT CONTROL if needed
  782. for(i=iPage_line_old; i<iPage_line; i++)
  783. {
  784. hwndWord[i]=CreateWindowEx(
  785. WS_EX_CLIENTEDGE,
  786. _TEXT("EDIT"),
  787. NULL,
  788. style | WS_BORDER,
  789. cxHD0, CharHeight+i*line_height,
  790. cxHD1-1, CharHeight,
  791. hwnd,
  792. (HMENU)UIntToPtr( (IDE_WORD_START+i) ),
  793. hInst,
  794. NULL
  795. );
  796. hwndPhrase[i]=CreateWindowEx(
  797. WS_EX_CLIENTEDGE,
  798. _TEXT("EDIT"),
  799. NULL,
  800. style /*| ES_AUTOHSCROLL*/ | WS_BORDER,
  801. -1, i*line_height,
  802. MulDiv(CharWidth * 2, 96, 72) * MAX_CHAR_NUM,
  803. CharHeight,
  804. subhWnd,
  805. (HMENU)UIntToPtr( (IDE_PHRASE_START+i) ),
  806. hInst,
  807. NULL
  808. );
  809. SendMessage(hwndWord[i], EM_SETLIMITTEXT, 2, 0);
  810. SendMessage(hwndPhrase[i], EM_SETLIMITTEXT, MAX_CHAR_NUM-1, 0);
  811. SendMessage(hwndWord[i],
  812. WM_SETFONT,
  813. (WPARAM)hFont,
  814. MAKELPARAM(TRUE, 0));
  815. SendMessage(hwndPhrase[i],
  816. WM_SETFONT,
  817. (WPARAM)hFont,
  818. MAKELPARAM(TRUE, 0));
  819. }
  820. hwndFocus=hwndWord[0];
  821. SetScrollRange(subhWnd, SB_VERT, 0, lWordBuff-iPage_line, TRUE);
  822. SetScrollPos(subhWnd, SB_VERT, yPos, TRUE);
  823. xPos = 0;
  824. SetScrollRange(subhWnd, SB_HORZ, 0, TOTALSCALE, TRUE);
  825. SetScrollPos(subhWnd, SB_HORZ, xPos, TRUE);
  826. lcSetEditText(iDisp_Top, TRUE);
  827. SetFocus(hwndWord[0]);
  828. }
  829. void draw_horz_header(HWND hwnd)
  830. {
  831. HDC hdc = GetDC(hwnd);
  832. RECT rect, r0, r1, r2;
  833. TCHAR szStr[MAX_PATH];
  834. HFONT hOldFont;
  835. GetClientRect(hwnd, &rect);
  836. SetRect(&r0, 0, 0, cxHD0 - 1, cyHD);
  837. SetRect(&r1, cxHD0, 0, cxHD0 + cxHD1 - 1, cyHD);
  838. SetRect(&r2, cxHD0 + cxHD1, 0, rect.right - 1, cyHD);
  839. draw_box1(hdc, r0.left, r0.top, r0.right - 1, r0.bottom);
  840. draw_box1(hdc, r1.left, r1.top, r1.right, r1.bottom);
  841. draw_box1(hdc, r2.left, r2.top, r2.right, r2.bottom);
  842. SetBkColor(hdc, 0x00c0c0c0); // Set Background color to Light gray
  843. r1.top += ((r1.bottom - r1.top - cyHD + 10) / 2);
  844. r2.top += ((r2.bottom - r2.top - cyHD + 10) / 2);
  845. hOldFont = SelectObject(hdc, hFont);
  846. LoadString(hInst, IDS_MAIN_WORD, szStr, sizeof(szStr)/sizeof(TCHAR));
  847. DrawText(hdc, szStr, lstrlen(szStr), &r1, DT_CENTER | DT_VCENTER);
  848. LoadString(hInst, IDS_MAIN_PHRASE, szStr, sizeof(szStr));
  849. DrawText(hdc, szStr, lstrlen(szStr), &r2, DT_CENTER | DT_VCENTER);
  850. SelectObject(hdc, hOldFont);
  851. ReleaseDC(hwnd, hdc);
  852. }
  853. void draw_vert_header(HWND hwnd)
  854. {
  855. HDC hdc = GetDC(hwnd);
  856. RECT rect, r, r0;
  857. TCHAR szStr[MAX_PATH];
  858. UINT i;
  859. HFONT hOldFont;
  860. GetClientRect(hwnd, &rect);
  861. SetRect(&r0, 0, 0, cxHD0 - 1, cyHD);
  862. SetBkColor(hdc, 0x00c0c0c0); // Set Background color to Light gray
  863. hOldFont = SelectObject(hdc, hFont);
  864. r0.top = r0.bottom + 2;
  865. r0.bottom = r0.top + cyHD - 1;
  866. for(i = 0; i < iPage_line; i++)
  867. {
  868. draw_box1(hdc, r0.left, r0.top, r0.right, r0.bottom);
  869. r = r0;
  870. r.top += ((r.bottom - r.top - cyHD + 10) / 2);
  871. //r.top += ((r.bottom - r.top - cyHD + 5) / 2);
  872. wsprintf(szStr, _TEXT("%d "), iDisp_Top + i + 1);
  873. DrawText(hdc, szStr, lstrlen(szStr), &r, DT_RIGHT);
  874. r0.top = r0.bottom + 1;
  875. r0.bottom = r0.top + cyHD - 1;
  876. }
  877. SelectObject(hdc, hOldFont);
  878. ReleaseDC(hwnd, hdc);
  879. }
  880. void DrawHeader(HWND hwnd)
  881. {
  882. draw_horz_header(hwnd);
  883. draw_vert_header(hwnd);
  884. }
  885. void lcPaint(HWND hwnd)
  886. {
  887. PAINTSTRUCT ps; // paint structure
  888. HDC hDC; // display-context variable
  889. hDC = BeginPaint (hwnd, &ps);
  890. EndPaint(hwnd, &ps);
  891. DrawHeader(hwnd);
  892. }
  893. BOOL lcAllocWord()
  894. {
  895. HANDLE hTemp;
  896. nWordBuffsize += ALLOCBLOCK;
  897. GlobalUnlock(hWord);
  898. hTemp= GlobalReAlloc(hWord, nWordBuffsize*sizeof(WORDBUF),
  899. GMEM_MOVEABLE);
  900. if(hTemp == NULL) {
  901. nWordBuffsize -= ALLOCBLOCK;
  902. lcErrMsg(IDS_ERR_MEMORY);
  903. return FALSE;
  904. }
  905. hWord=hTemp;
  906. lpWord=(LPWORDBUF)GlobalLock(hWord);
  907. if(lpWord == NULL) {
  908. nWordBuffsize -= ALLOCBLOCK;
  909. lcErrMsg(IDS_ERR_MEMORY);
  910. return FALSE;
  911. }
  912. return TRUE;
  913. }
  914. BOOL lcAllocPhrase()
  915. {
  916. HANDLE hTemp;
  917. nPhraseBuffsize += ALLOCBLOCK;
  918. GlobalUnlock(hPhrase);
  919. hTemp= GlobalReAlloc(hPhrase, nPhraseBuffsize*sizeof(PHRASEBUF),
  920. GMEM_MOVEABLE);
  921. if(hTemp == NULL) {
  922. nPhraseBuffsize -= ALLOCBLOCK;
  923. lcErrMsg(IDS_ERR_MEMORY);
  924. return FALSE;
  925. }
  926. hPhrase=hTemp;
  927. lpPhrase=(LPPHRASEBUF)GlobalLock(hPhrase);
  928. if(lpPhrase == NULL) {
  929. nPhraseBuffsize -= ALLOCBLOCK;
  930. lcErrMsg(IDS_ERR_MEMORY);
  931. return FALSE;
  932. }
  933. return TRUE;
  934. }
  935. UINT lcGetSeg(
  936. )
  937. {
  938. LPPHRASEBUF Phrase;
  939. UINT iFree;
  940. if(iFirstFree == NULL_SEG) {
  941. // If Allocated Phrase buffer not enough Reallocate it
  942. if(lPhraseBuff+1 == nPhraseBuffsize)
  943. if(!lcAllocPhrase())
  944. return(NULL_SEG);
  945. lpPhrase[lPhraseBuff].lNext_Seg=NULL_SEG;
  946. return(lPhraseBuff++);
  947. }
  948. iFree=iFirstFree;
  949. Phrase=&lpPhrase[iFirstFree];
  950. iFirstFree=Phrase->lNext_Seg;
  951. Phrase->lNext_Seg=NULL_SEG;
  952. return(iFree);
  953. }
  954. void lcFreeSeg(
  955. UINT iFree)
  956. {
  957. LPPHRASEBUF Phrase;
  958. Phrase=&lpPhrase[iFree];
  959. while(Phrase->lNext_Seg!=NULL_SEG)
  960. Phrase=&lpPhrase[Phrase->lNext_Seg];
  961. Phrase->lNext_Seg=iFirstFree;
  962. iFirstFree=iFree;
  963. }
  964. BOOL lcTranslateMsg(
  965. MSG *msg)
  966. {
  967. USHORT uCtrl;
  968. USHORT uKeyState;
  969. UINT i;
  970. // Process keystroke, for EDIT CONTROL
  971. if(msg->message == WM_CHAR) {
  972. if(msg->wParam == 0x09) { // Tab key
  973. lcTab_key(msg->hwnd);
  974. return TRUE;
  975. }
  976. }
  977. if(msg->message == WM_KEYDOWN) {
  978. uCtrl=GetKeyState(VK_CONTROL);
  979. uKeyState=(uCtrl & STATE_ON) ? CTRL_STATE : 0;
  980. for(i=0; i<nFuncKey; i++) {
  981. if((lpFuncKey[i].uState == uKeyState) &&
  982. (lpFuncKey[i].wKey == msg->wParam)) {
  983. PostMessage( hwndMain, WM_COMMAND, lpFuncKey[i].wID, 0);
  984. return FALSE;
  985. }
  986. }
  987. if(lcKey(msg->hwnd, msg->wParam, uKeyState))
  988. {
  989. draw_vert_header(hwndMain);
  990. return TRUE;
  991. }
  992. }
  993. return FALSE;
  994. }
  995. void draw_box0(HDC hdc, int x1, int y1, int x2, int y2)
  996. {
  997. RECT r = {x1, y1, x2, y2};
  998. HPEN hPen, hOldPen;
  999. HBRUSH hOldBr;
  1000. POINT pt;
  1001. hOldBr = SelectObject(hdc, GetStockObject(LTGRAY_BRUSH));
  1002. hOldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
  1003. Rectangle(hdc, r.left, r.top, r.right, r.bottom);
  1004. SelectObject(hdc, hOldPen);
  1005. SelectObject(hdc, hOldBr);
  1006. hPen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
  1007. if ( hPen )
  1008. {
  1009. hOldPen = SelectObject(hdc, hPen);
  1010. MoveToEx(hdc, r.right, r.top, &pt);
  1011. LineTo(hdc, r.left, r.top);
  1012. LineTo(hdc, r.left, r.bottom);
  1013. SelectObject(hdc, hOldPen);
  1014. DeleteObject(hPen);
  1015. }
  1016. hOldPen = SelectObject(hdc, GetStockObject(WHITE_PEN));
  1017. MoveToEx(hdc, r.right, r.top + 1, &pt);
  1018. LineTo(hdc, r.right, r.bottom);
  1019. LineTo(hdc, r.left + 1, r.bottom);
  1020. SelectObject(hdc, hOldPen);
  1021. }
  1022. void draw_box1(HDC hdc, int x1, int y1, int x2, int y2)
  1023. {
  1024. RECT r = {x1, y1, x2, y2};
  1025. HPEN hPen, hOldPen;
  1026. HBRUSH hOldBr;
  1027. POINT pt;
  1028. hOldBr = SelectObject(hdc, GetStockObject(LTGRAY_BRUSH));
  1029. hOldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
  1030. Rectangle(hdc, r.left, r.top, r.right, r.bottom);
  1031. SelectObject(hdc, hOldPen);
  1032. SelectObject(hdc, hOldBr);
  1033. hOldPen = SelectObject(hdc, GetStockObject(WHITE_PEN));
  1034. MoveToEx(hdc, r.right, r.top, &pt);
  1035. LineTo(hdc, r.left, r.top);
  1036. LineTo(hdc, r.left, r.bottom);
  1037. SelectObject(hdc, hOldPen);
  1038. hPen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
  1039. if ( hPen )
  1040. {
  1041. hOldPen = SelectObject(hdc, hPen);
  1042. MoveToEx(hdc, r.right, r.top + 1, &pt);
  1043. LineTo(hdc, r.right, r.bottom);
  1044. LineTo(hdc, r.left + 1, r.bottom);
  1045. SelectObject(hdc, hOldPen);
  1046. DeleteObject(hPen);
  1047. }
  1048. }