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.

3535 lines
126 KiB

  1. // INCLUSION PREVENTION DEFINITIONS
  2. #define NOMETAFILE
  3. #define NOMINMAX
  4. #define NOSOUND
  5. #define NOPROFILER
  6. #define NODEFERWINDOWPOS
  7. #define NODRIVERS
  8. #define NOCOMM
  9. #define NOBITMAP
  10. #define NOSCROLL
  11. #define NOWINOFFSETS
  12. #define NOWH
  13. #define NORASTEROPS
  14. #define NOOEMRESOURCE
  15. #define NOGDICAPMASKS
  16. #define NOKEYSTATES
  17. #define NOSYSCOMMANDS
  18. #define NOATOM
  19. #define NOLOGERROR
  20. #define NOSYSTEMPARAMSINFO
  21. // WINDOWS includes
  22. #include <windows.h>
  23. #include <windowsx.h>
  24. #ifdef RLWIN16
  25. //#include <toolhelp.h>
  26. #endif
  27. #include <shellapi.h>
  28. #include <commdlg.h>
  29. // CRT includes
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. // RL TOOLS SET includes
  33. #include "windefs.h"
  34. #include "toklist.h"
  35. #include "RESTOK.H"
  36. #include "RLEDIT.H"
  37. #include "update.h"
  38. #include "custres.h"
  39. #include "exe2res.h"
  40. #include "exeNTres.h"
  41. #include "commbase.h"
  42. #include "wincomon.h"
  43. #include "resread.h"
  44. #include "projdata.h"
  45. #include "showerrs.h"
  46. #include "resource.h"
  47. // Global Variables:
  48. static CHAR * gszHelpFile = "rltools.hlp";
  49. extern MSTRDATA gMstr;
  50. extern PROJDATA gProj;
  51. extern BOOL bRLGui;
  52. #ifdef RLWIN32
  53. HINSTANCE hInst; /* Instance of the main window */
  54. #else
  55. HWND hInst; /* Instance of the main window */
  56. #endif
  57. int nUpdateMode = 0;
  58. BOOL fCodePageGiven = FALSE; //... Set to TRUE if -p arg given
  59. HWND hMainWnd; // handle to main window
  60. HWND hListWnd; // handle to tok list window
  61. HWND hStatusWnd; // handle to status windows
  62. CHAR szFileTitle[MAXFILENAME] = ""; // holds base name of latest opened file
  63. CHAR szCustFilterSpec[MAXCUSTFILTER] = "";
  64. extern CHAR szDHW[]; //... used in debug strings
  65. extern BOOL fInThirdPartyEditer;
  66. extern BOOL gfReplace;
  67. static TCHAR szSearchType[80] = TEXT("");
  68. static TCHAR szSearchText[4096] = TEXT("");
  69. static WORD wSearchStatus = 0;
  70. static WORD wSearchStatusMask = 0;
  71. static BOOL fSearchDirection;
  72. static BOOL fSearchStarted = FALSE;
  73. #ifndef UNICODE
  74. BOOL PASCAL _loadds WatchTask(WORD wID, DWORD dwData);
  75. #endif
  76. #ifdef RLWIN16
  77. static FARPROC lpfnWatchTask = NULL;
  78. #endif
  79. static void CleanDeltaList(void);
  80. static int ExecResEditor(HWND, CHAR *, CHAR *, CHAR *);
  81. static void DrawLBItem(LPDRAWITEMSTRUCT lpdis);
  82. static void SetNames( HWND hDlg, int iLastBox, LPSTR szNewFile);
  83. // File IO vars
  84. static OPENFILENAMEA ofn;
  85. static CHAR szFilterSpec [60] = "";
  86. static CHAR szPRJFilterSpec [60] = "";
  87. static CHAR szResFilterSpec [60] = "";
  88. static CHAR szExeFilterSpec [60] = "";
  89. static CHAR szDllFilterSpec [60] = "";
  90. static CHAR szExeResFilterSpec [180] = "";
  91. static CHAR szTokFilterSpec [60] = "";
  92. static CHAR szMPJFilterSpec [60] = "";
  93. static CHAR szGlossFilterSpec[60] = "";
  94. static CHAR szTempFileName[MAXFILENAME] = "";
  95. static CHAR szFileName[MAXFILENAME] = ""; // holds full name of latest opened file
  96. static TCHAR szString[256] = TEXT(""); // variable to load resource strings
  97. static TCHAR tszAppName[100] = TEXT("");
  98. static CHAR szAppName[100] = "";
  99. static TCHAR szClassName[]=TEXT("RLEditClass");
  100. static TCHAR szStatusClass[]=TEXT("RLEditStatus");
  101. static BOOL gbNewProject = FALSE; // indicates to prompt for auto translate
  102. static BOOL fTokChanges = FALSE; // set to true when toke file is out of date
  103. static BOOL fTokFile = FALSE;
  104. static BOOL fEditing = FALSE;
  105. static BOOL fPrjChanges = FALSE;
  106. static BOOL fMPJOutOfDate = FALSE;
  107. static BOOL fPRJOutOfDate = FALSE;
  108. static CHAR szOpenDlgTitle[80] = ""; // title of File open dialog
  109. static CHAR szSaveDlgTitle[80] = ""; // title of File saveas dialog
  110. // linked list of token deta info
  111. static TOKENDELTAINFO FAR *pTokenDeltaInfo = NULL;
  112. static LONG lFilePointer[30]= {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  113. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  114. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  115. // circular doubly linked list of translations
  116. static TRANSLIST *pTransList = NULL;
  117. // Window vars
  118. static BOOL fWatchEditor;
  119. static CHAR szTempRes[MAXFILENAME] = ""; // temp file for resource editor
  120. // set true if a resource editer has been launched
  121. static HCURSOR hHourGlass; /* handle to hourglass cursor */
  122. static HCURSOR hSaveCursor; /* current cursor handle */
  123. static HACCEL hAccTable;
  124. static RECT Rect; /* dimension of the client window */
  125. static int cyChildHeight; /* height of status windows */
  126. // NOTIMPLEMENTED is a macro that displays a "Not implemented" dialog
  127. #define NOTIMPLEMENTED {TCHAR sz[80];\
  128. LoadString( hInst, \
  129. IDS_NOT_IMPLEMENTED, \
  130. sz, TCHARSIN( sizeof(sz)));\
  131. MessageBox(hMainWnd, sz, tszAppName, \
  132. MB_ICONEXCLAMATION | MB_OK);}
  133. // Edit Tok Dialog
  134. #ifndef RLWIN32
  135. static DLGPROC lpTokEditDlg;
  136. #endif
  137. static HWND hTokEditDlgWnd = 0;
  138. /**
  139. *
  140. *
  141. * Function: InitApplication
  142. * Regsiters the main window, which is a list box composed of tokens
  143. * read from the token file. Also register the status window.
  144. *
  145. *
  146. * Arguments:
  147. * hInstance, instance handle of program in memory.
  148. *
  149. * Returns:
  150. *
  151. * Errors Codes:
  152. * TRUE, windows registered correctly.
  153. * FALSE, error during register of one of the windows.
  154. *
  155. * History:
  156. * 9/91, Implemented. TerryRu
  157. *
  158. *
  159. **/
  160. BOOL InitApplication(HINSTANCE hInstance)
  161. {
  162. WNDCLASS wc;
  163. CHAR sz[60] = "";
  164. CHAR sztFilterSpec[120] = "";
  165. LoadStrIntoAnsiBuf(hInstance, IDS_PRJSPEC, sz, sizeof(sz));
  166. szFilterSpecFromSz1Sz2(szFilterSpec, sz, "*.PRJ");
  167. szFilterSpecFromSz1Sz2(szPRJFilterSpec, sz, "*.PRJ");
  168. LoadStrIntoAnsiBuf(hInstance, IDS_RESSPEC, sz, sizeof(sz));
  169. szFilterSpecFromSz1Sz2(szResFilterSpec, sz, "*.RES");
  170. LoadStrIntoAnsiBuf(hInstance, IDS_EXESPEC, sz, sizeof(sz));
  171. szFilterSpecFromSz1Sz2(szExeFilterSpec, sz, "*.EXE");
  172. LoadStrIntoAnsiBuf(hInstance, IDS_DLLSPEC, sz, sizeof(sz));
  173. szFilterSpecFromSz1Sz2(szDllFilterSpec, sz, "*.DLL");
  174. CatSzFilterSpecs(sztFilterSpec, szExeFilterSpec, szDllFilterSpec);
  175. CatSzFilterSpecs(szExeResFilterSpec, sztFilterSpec, szResFilterSpec);
  176. LoadStrIntoAnsiBuf(hInstance, IDS_TOKSPEC, sz, sizeof(sz));
  177. szFilterSpecFromSz1Sz2(szTokFilterSpec, sz, "*.TOK");
  178. LoadStrIntoAnsiBuf(hInstance, IDS_MPJSPEC, sz, sizeof(sz));
  179. szFilterSpecFromSz1Sz2(szMPJFilterSpec, sz, "*.MPJ");
  180. LoadStrIntoAnsiBuf(hInstance, IDS_GLOSSSPEC, sz, sizeof(sz));
  181. szFilterSpecFromSz1Sz2(szGlossFilterSpec, sz, "*.TXT");
  182. LoadStrIntoAnsiBuf(hInstance,
  183. IDS_OPENTITLE,
  184. szOpenDlgTitle,
  185. sizeof(szOpenDlgTitle));
  186. LoadStrIntoAnsiBuf(hInstance,
  187. IDS_SAVETITLE,
  188. szSaveDlgTitle,
  189. sizeof(szSaveDlgTitle));
  190. wc.style = 0;
  191. wc.lpfnWndProc = StatusWndProc;
  192. wc.cbClsExtra = 0;
  193. wc.cbWndExtra = 0;
  194. wc.hInstance = hInstance;
  195. wc.hIcon = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION);
  196. wc.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
  197. wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  198. wc.lpszMenuName = NULL;
  199. wc.lpszClassName = szStatusClass;
  200. if (! RegisterClass((CONST WNDCLASS *)&wc)) {
  201. return (FALSE);
  202. }
  203. wc.style = 0;
  204. wc.lpfnWndProc = MainWndProc;
  205. wc.cbClsExtra = 0;
  206. wc.cbWndExtra = 0;
  207. wc.hInstance = hInstance;
  208. wc.hIcon = LoadIcon(hInstance, TEXT("RLEditIcon"));
  209. wc.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
  210. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  211. wc.lpszMenuName = TEXT("RLEdit");
  212. wc.lpszClassName = szClassName;
  213. if (!RegisterClass((CONST WNDCLASS *)&wc)) {
  214. return (FALSE);
  215. }
  216. // Windows register return sucessfully
  217. return (TRUE);
  218. }
  219. /**
  220. *
  221. *
  222. * Function: InitInstance
  223. * Creates the main, and status windows for the program.
  224. * The status window is sized according to the main window
  225. * size. InitInstance also loads the acclerator table, and prepares
  226. * the global openfilename structure for later use.
  227. *
  228. *
  229. * Errors Codes:
  230. * TRUE, windows created correctly.
  231. * FALSE, error on create windows calls.
  232. *
  233. * History:
  234. * 9/11, Implemented TerryRu
  235. *
  236. *
  237. **/
  238. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  239. {
  240. RECT Rect = { 0,0,0,0};
  241. hAccTable = LoadAccelerators(hInst, TEXT("RLEdit"));
  242. hMainWnd = CreateWindow(szClassName,
  243. tszAppName,
  244. WS_OVERLAPPEDWINDOW,
  245. CW_USEDEFAULT,
  246. CW_USEDEFAULT,
  247. CW_USEDEFAULT,
  248. CW_USEDEFAULT,
  249. (HWND) NULL,
  250. (HMENU) NULL,
  251. hInstance,
  252. (LPVOID) NULL);
  253. if (!hMainWnd) { // clean up after errors.
  254. return ( FALSE);
  255. }
  256. DragAcceptFiles(hMainWnd, TRUE);
  257. GetClientRect(hMainWnd, (LPRECT) &Rect);
  258. // Create a child list box window
  259. hListWnd = CreateWindow(TEXT("LISTBOX"),
  260. NULL,
  261. WS_CHILD |
  262. LBS_WANTKEYBOARDINPUT |
  263. LBS_NOTIFY | LBS_NOINTEGRALHEIGHT |
  264. LBS_OWNERDRAWFIXED | WS_VSCROLL |
  265. WS_HSCROLL | WS_BORDER,
  266. 0,
  267. 0,
  268. (Rect.right-Rect.left),
  269. (Rect.bottom-Rect.top),
  270. hMainWnd,
  271. (HMENU)IDC_LIST, // Child control i.d.
  272. hInstance,
  273. NULL);
  274. if (!hListWnd) { // clean up after errors.
  275. DeleteObject((HGDIOBJ)hMainWnd);
  276. return ( FALSE);
  277. }
  278. // Creat a child status window
  279. hStatusWnd = CreateWindow(szStatusClass,
  280. NULL,
  281. WS_CHILD | WS_BORDER | WS_VISIBLE,
  282. 0, 0, 0, 0,
  283. hMainWnd,
  284. NULL,
  285. hInstance,
  286. NULL);
  287. if (! hStatusWnd) { // clean up after errors.
  288. DeleteObject((HGDIOBJ)hListWnd);
  289. DeleteObject((HGDIOBJ)hMainWnd);
  290. return ( FALSE);
  291. }
  292. hHourGlass = LoadCursor((HINSTANCE) NULL, IDC_WAIT);
  293. // Fill in non-variant fields of OPENFILENAMEA struct.
  294. ofn.lStructSize = sizeof( OPENFILENAMEA);
  295. ofn.hwndOwner = hMainWnd;
  296. ofn.lpstrFilter = szFilterSpec;
  297. ofn.lpstrCustomFilter = szCustFilterSpec;
  298. ofn.nMaxCustFilter = MAXCUSTFILTER;
  299. ofn.nFilterIndex = 1;
  300. ofn.lpstrFile = szFileName;
  301. ofn.nMaxFile = sizeof( szFileName);
  302. ofn.lpstrInitialDir = NULL;
  303. ofn.lpstrFileTitle = szFileTitle;
  304. ofn.nMaxFileTitle = sizeof( szFileTitle);
  305. ofn.lpstrTitle = NULL;
  306. ofn.lpstrDefExt = "PRJ";
  307. ofn.Flags = 0;
  308. ShowWindow(hMainWnd, nCmdShow);
  309. UpdateWindow(hMainWnd);
  310. return ( TRUE);
  311. }
  312. /**
  313. *
  314. *
  315. * Function: WinMain
  316. * Calls the intialization functions, to register, and create the
  317. * application windows. Once the windows are created, the program
  318. * enters the GetMessage loop.
  319. *
  320. *
  321. * Arguements:
  322. * hInstace, handle for this instance
  323. * hPrevInstanc, handle for possible previous instances
  324. * lpszCmdLine, LONG pointer to exec command line.
  325. * nCmdShow, code for main window display.
  326. *
  327. *
  328. * Errors Codes:
  329. * IDS_ERR_REGISTER_CLASS, error on windows register
  330. * IDS_ERR_CREATE_WINDOW, error on create windows
  331. * otherwise, status of last command.
  332. *
  333. * History:
  334. *
  335. *
  336. **/
  337. INT WINAPI WinMain(HINSTANCE hInstance,
  338. HINSTANCE hPrevInstance,
  339. LPSTR lpszCmdLine,
  340. int nCmdShow)
  341. {
  342. MSG msg;
  343. HWND FirstWnd = NULL;
  344. HWND FirstChildWnd = NULL;
  345. WORD wRC = SUCCESS;
  346. bRLGui = TRUE; //... used in rlcommon.lib
  347. if (FirstWnd = FindWindow(szClassName, NULL)) { // checking for previous instance
  348. FirstChildWnd = GetLastActivePopup(FirstWnd);
  349. BringWindowToTop(FirstWnd);
  350. ShowWindow(FirstWnd, SW_SHOWNORMAL);
  351. if (FirstWnd != FirstChildWnd) {
  352. BringWindowToTop(FirstChildWnd);
  353. }
  354. return (FALSE);
  355. }
  356. hInst = hInstance;
  357. GetModuleFileNameA( hInst, szDHW, DHWSIZE);
  358. GetInternalName( szDHW, szAppName, sizeof( szAppName));
  359. szFileName[0] = '\0';
  360. lFilePointer[0] = (LONG)-1;
  361. #ifdef UNICODE
  362. _MBSTOWCS( tszAppName,
  363. szAppName,
  364. WCHARSIN( sizeof( tszAppName)),
  365. ACHARSIN( strlen( szAppName) + 1));
  366. #else
  367. strcpy( tszAppName, szAppName);
  368. #endif
  369. // register window classes if first instance of application
  370. if ( ! hPrevInstance ) {
  371. if ( ! InitApplication( hInstance) ) {
  372. /* Registering one of the windows failed */
  373. LoadString( hInst,
  374. IDS_ERR_REGISTER_CLASS,
  375. szString,
  376. TCHARSIN( sizeof( szString)));
  377. MessageBox( NULL, szString, NULL, MB_ICONEXCLAMATION);
  378. return IDS_ERR_REGISTER_CLASS;
  379. }
  380. }
  381. // Create windows for this instance of application
  382. if ( ! InitInstance(hInstance, nCmdShow) ) {
  383. LoadString( hInst,
  384. IDS_ERR_CREATE_WINDOW,
  385. szString,
  386. TCHARSIN( sizeof(szString)));
  387. MessageBox( NULL, szString, NULL, MB_ICONEXCLAMATION);
  388. return IDS_ERR_CREATE_WINDOW;
  389. }
  390. // Main Message Loop
  391. while ( GetMessage( &msg, NULL, 0, 0) ) {
  392. if ( hTokEditDlgWnd ) {
  393. if ( IsDialogMessage( hTokEditDlgWnd, &msg)) {
  394. continue;
  395. }
  396. }
  397. if ( TranslateAccelerator( hMainWnd, hAccTable, &msg) ) {
  398. continue;
  399. }
  400. TranslateMessage( (CONST MSG *)&msg);
  401. DispatchMessage( (CONST MSG *)&msg);
  402. }
  403. return (INT)msg.wParam;
  404. }
  405. /**
  406. * Function: MainWndProc
  407. * Process the windows messages for the main window of the application.
  408. * All user inputs go through this window procedure.
  409. * See cases in the switch table for a description of each message type.
  410. *
  411. *
  412. * Arguments:
  413. *
  414. * Returns:
  415. *
  416. * Errors Codes:
  417. *
  418. * History:
  419. *
  420. **/
  421. INT_PTR APIENTRY MainWndProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  422. {
  423. // if it's a list box message process it in DoListBoxCommand
  424. if ( fInThirdPartyEditer ) { //... only process messages sent by the editor
  425. switch (wMsg) {
  426. case WM_EDITER_CLOSED:
  427. {
  428. CHAR szDlgToks[MAXFILENAME] = "";
  429. static WORD wSavedIndex;
  430. #ifdef RLWIN16
  431. NotifyUnRegister( NULL);
  432. FreeProcInstance( lpfnWatchTask);
  433. #endif
  434. ShowWindow(hWnd, SW_SHOW);
  435. {
  436. TCHAR tsz[80] = TEXT("");
  437. LoadString( hInst,
  438. IDS_REBUILD_TOKENS,
  439. tsz,
  440. TCHARSIN( sizeof(tsz)));
  441. if ( MessageBox( hWnd,
  442. tsz,
  443. tszAppName,
  444. MB_ICONQUESTION | MB_YESNO) == IDYES) {
  445. HCURSOR hOldCursor;
  446. BOOL bUpdated = FALSE;
  447. hOldCursor = SetCursor(hHourGlass);
  448. LoadCustResDescriptions(gMstr.szRdfs);
  449. // szTempRes returned from resource editor
  450. MyGetTempFileName(0, "TOK", 0, szDlgToks);
  451. GenerateTokFile(szDlgToks, szTempRes, &bUpdated, 0);
  452. InsDlgToks(gProj.szTok,
  453. szDlgToks,
  454. ID_RT_DIALOG);
  455. remove(szDlgToks);
  456. ClearResourceDescriptions();
  457. // gProj.szTok, now contains the latest tokens
  458. SetCursor(hOldCursor);
  459. //Rledit doesn't save when changed tokens by Dialog Editor.
  460. fTokChanges = TRUE;
  461. }
  462. }
  463. fInThirdPartyEditer = FALSE;
  464. remove(szTempRes);
  465. // UNDONE - delete all temp files with the same root in case
  466. // the editor created additional files like DLGs and RCs.
  467. // (DLGEDIT does this.)
  468. // For now I'm just going to tack a .DLG
  469. // at the end of the file name
  470. // and delete it.
  471. {
  472. int i;
  473. for (i = strlen(szTempRes);
  474. i > 0 && szTempRes[i]!='.'; i--) {
  475. }
  476. if (szTempRes[i] == '.') {
  477. szTempRes[++i]='D';
  478. szTempRes[++i]='L';
  479. szTempRes[++i]='G';
  480. szTempRes[++i]='\0';
  481. remove(szTempRes);
  482. }
  483. }
  484. wSavedIndex = (UINT)SendMessage( hListWnd,
  485. LB_GETCURSEL,
  486. (WPARAM)0,
  487. (LPARAM)0);
  488. SendMessage( hWnd, WM_LOADTOKENS, (WPARAM)0, (LPARAM)0);
  489. SendMessage( hListWnd,
  490. LB_SETCURSEL,
  491. (WPARAM)wSavedIndex,
  492. (LPARAM)0);
  493. }
  494. return ( DefWindowProc( hWnd, wMsg, wParam, lParam));
  495. }
  496. }
  497. // Not a third party edit command.
  498. DoListBoxCommand (hWnd, wMsg, wParam, lParam);
  499. switch (wMsg) {
  500. case WM_DROPFILES:
  501. {
  502. CHAR sz[MAXFILENAME] = "";
  503. DragQueryFileA( (HDROP) wParam, 0, sz, MAXFILENAME);
  504. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0)) {
  505. GetProjectData( sz, NULL, NULL, FALSE, FALSE);
  506. }
  507. DragFinish( (HDROP) wParam);
  508. return ( TRUE);
  509. }
  510. case WM_COMMAND:
  511. if (DoMenuCommand(hWnd, wMsg, wParam, lParam)) {
  512. return TRUE;
  513. }
  514. break;
  515. case WM_CLOSE:
  516. SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0);
  517. DestroyWindow(hMainWnd);
  518. DestroyWindow(hListWnd);
  519. DestroyWindow(hStatusWnd);
  520. _fcloseall();
  521. FreeLangList();
  522. #ifdef _DEBUG
  523. {
  524. FILE *pLeakList = fopen( "C:\\LEAKLIST.TXT", "wt");
  525. FreeMemList( pLeakList);
  526. fclose( pLeakList);
  527. }
  528. #endif // _DEBUG
  529. break;
  530. case WM_CREATE:
  531. {
  532. HDC hdc;
  533. int cyBorder;
  534. TEXTMETRIC tm;
  535. hdc = GetDC (hWnd);
  536. GetTextMetrics(hdc, &tm);
  537. ReleaseDC(hWnd, hdc);
  538. cyBorder = GetSystemMetrics(SM_CYBORDER);
  539. cyChildHeight = tm.tmHeight + 6 + cyBorder * 2;
  540. break;
  541. }
  542. case WM_DESTROY:
  543. WinHelpA(hWnd, gszHelpFile, HELP_QUIT, (DWORD)0);
  544. // remove translation list
  545. if (pTransList) {
  546. // so we can find the end of the list
  547. pTransList->pPrev->pNext = NULL;
  548. }
  549. while (pTransList) {
  550. TRANSLIST *pTemp;
  551. pTemp = pTransList;
  552. pTransList = pTemp->pNext;
  553. RLFREE( pTemp->sz);
  554. RLFREE( pTemp);
  555. }
  556. PostQuitMessage(0);
  557. break;
  558. case WM_INITMENU:
  559. // Enable or Disable the Paste menu item
  560. // based on available Clipboard Text data
  561. if (wParam == (WPARAM) GetMenu(hMainWnd)) {
  562. if (OpenClipboard(hWnd)) {
  563. #if defined(UNICODE)
  564. if ((IsClipboardFormatAvailable(CF_UNICODETEXT)
  565. || IsClipboardFormatAvailable(CF_OEMTEXT)) && fTokFile)
  566. #else // not UNICODE
  567. if ((IsClipboardFormatAvailable(CF_TEXT)
  568. || IsClipboardFormatAvailable(CF_OEMTEXT)) && fTokFile)
  569. #endif // UNICODE
  570. {
  571. EnableMenuItem((HMENU) wParam, IDM_E_PASTE, MF_ENABLED);
  572. } else {
  573. EnableMenuItem((HMENU)wParam, IDM_E_PASTE, MF_GRAYED);
  574. }
  575. CloseClipboard();
  576. return (TRUE);
  577. }
  578. }
  579. break;
  580. case WM_QUERYENDSESSION:
  581. /* message: to end the session? */
  582. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  583. return TRUE;
  584. } else {
  585. return FALSE;
  586. }
  587. case WM_SETFOCUS:
  588. SetFocus (hListWnd);
  589. break;
  590. case WM_DRAWITEM:
  591. DrawLBItem((LPDRAWITEMSTRUCT) lParam);
  592. break;
  593. case WM_DELETEITEM:
  594. {
  595. HGLOBAL hTokData;
  596. LPTOKDATA lpTokData;
  597. hTokData = ((HGLOBAL)((LPDELETEITEMSTRUCT)lParam)->itemData);
  598. if ( hTokData ) {
  599. lpTokData = (LPTOKDATA)GlobalLock( hTokData );
  600. GlobalFree( lpTokData->hToken );
  601. GlobalUnlock( hTokData );
  602. GlobalFree( hTokData );
  603. }
  604. }
  605. break;
  606. case WM_SIZE:
  607. {
  608. int cxWidth;
  609. int cyHeight;
  610. int xChild;
  611. int yChild;
  612. cxWidth = LOWORD(lParam);
  613. cyHeight = HIWORD(lParam);
  614. xChild = 0;
  615. yChild = cyHeight - cyChildHeight + 1;
  616. MoveWindow(hListWnd, 0, 0, cxWidth, yChild, TRUE);
  617. MoveWindow(hStatusWnd, xChild, yChild, cxWidth, cyChildHeight, TRUE);
  618. break;
  619. }
  620. case WM_READMPJDATA:
  621. {
  622. OFSTRUCT Of = { 0, 0, 0, 0, 0, ""};
  623. if ( OpenFile( gProj.szMpj, &Of, OF_EXIST) == HFILE_ERROR ) {
  624. // file doesn't exist
  625. LoadStrIntoAnsiBuf( hInst, IDS_MPJERR, szDHW, DHWSIZE);
  626. MessageBoxA( hWnd,
  627. gProj.szMpj,
  628. szDHW,
  629. MB_ICONSTOP | MB_OK);
  630. } else if ( GetMasterProjectData( gProj.szMpj,
  631. NULL,
  632. NULL,
  633. FALSE) == SUCCESS ) {
  634. OFSTRUCT Of = { 0, 0, 0, 0, 0, ""};
  635. gProj.fSourceEXE = IsExe( gMstr.szSrc);
  636. gProj.fTargetEXE = (!IsRes( gProj.szBld));
  637. if ( gProj.fTargetEXE && !gProj.fSourceEXE ) {
  638. int i = lstrlenA( gProj.szBld) - 3;
  639. LoadStrIntoAnsiBuf( hInst,
  640. IDS_RLE_CANTSAVEASEXE,
  641. szDHW,
  642. DHWSIZE);
  643. lstrcpyA( gProj.szBld+i, "RES");
  644. MessageBoxA( hWnd,
  645. szDHW,
  646. gProj.szBld,
  647. MB_ICONHAND|MB_OK);
  648. gProj.fTargetEXE = FALSE;
  649. }
  650. SzDateFromFileName( szDHW, gMstr.szSrc);
  651. fMPJOutOfDate = FALSE;
  652. if ( OpenFile( gProj.szTok, &Of, OF_EXIST) == HFILE_ERROR ) {
  653. // file doesn't exist, create it
  654. Update( gMstr.szMtk, gProj.szTok);
  655. lstrcpyA( gProj.szTokDate,
  656. gMstr.szMpjLastRealUpdate);
  657. fPrjChanges = TRUE;
  658. fPRJOutOfDate = FALSE;
  659. } else {
  660. if ( lstrcmpA( gMstr.szMpjLastRealUpdate,
  661. gProj.szTokDate) ) {
  662. HCURSOR hOldCursor;
  663. fPRJOutOfDate = TRUE;
  664. hOldCursor = SetCursor( hHourGlass);
  665. Update( gMstr.szMtk, gProj.szTok);
  666. SetCursor( hOldCursor);
  667. lstrcpyA( gProj.szTokDate,
  668. gMstr.szMpjLastRealUpdate);
  669. fPrjChanges = TRUE;
  670. fPRJOutOfDate = FALSE;
  671. } else {
  672. fPRJOutOfDate = FALSE;
  673. }
  674. }
  675. // New code to do auto-translate
  676. SendMessage( hWnd, WM_LOADTOKENS, (WPARAM)0, (LPARAM)0);
  677. if ( gProj.szGlo[0] // file name given exists?
  678. && OpenFile( gProj.szGlo, &Of, OF_EXIST) != HFILE_ERROR ) { // Yes
  679. HCURSOR hOldCursor = SetCursor( hHourGlass);
  680. MakeGlossIndex( lFilePointer);
  681. SetCursor( hOldCursor);
  682. }
  683. } //... END case WM_READMPJDATA
  684. } //... END switch (wMsg)
  685. break;
  686. case WM_LOADTOKENS:
  687. {
  688. HMENU hMenu = NULL;
  689. FILE *f = NULL;
  690. // Remove the current token list
  691. SendMessage( hListWnd, LB_RESETCONTENT, (LPARAM)0, (LPARAM)0);
  692. CleanDeltaList();
  693. // Hide token list, while we add new tokens
  694. ShowWindow(hListWnd, SW_HIDE);
  695. if (f = FOPEN(gProj.szTok, "rt")) {
  696. HCURSOR hOldCursor;
  697. hOldCursor = SetCursor(hHourGlass);
  698. // Insert tokens from token file into the list box
  699. {
  700. FILE *fm;
  701. if ( !(fm = fopen((CHAR *)gMstr.szMtk,"rt")) )
  702. return TRUE;
  703. pTokenDeltaInfo = InsertTokMtkList(f, fm );
  704. FCLOSE( fm );
  705. }
  706. FCLOSE(f);
  707. // Make list box visible
  708. ShowWindow(hListWnd, SW_SHOW);
  709. hMenu=GetMenu(hWnd);
  710. EnableMenuItem(hMenu, IDM_P_CLOSE, MF_ENABLED|MF_BYCOMMAND);
  711. EnableMenuItem(hMenu, IDM_P_VIEW, MF_ENABLED|MF_BYCOMMAND);
  712. EnableMenuItem(hMenu, IDM_P_EDIT, MF_ENABLED|MF_BYCOMMAND);
  713. EnableMenuItem(hMenu, IDM_P_SAVE, MF_ENABLED|MF_BYCOMMAND);
  714. EnableMenuItem(hMenu, IDM_E_FIND, MF_ENABLED|MF_BYCOMMAND);
  715. EnableMenuItem(hMenu, IDM_E_FINDUP, MF_ENABLED|MF_BYCOMMAND);
  716. EnableMenuItem(hMenu, IDM_E_FINDDOWN, MF_ENABLED|MF_BYCOMMAND);
  717. EnableMenuItem(hMenu, IDM_E_REVIEW, MF_ENABLED|MF_BYCOMMAND);
  718. EnableMenuItem(hMenu, IDM_E_ALLREVIEW, MF_ENABLED|MF_BYCOMMAND);
  719. EnableMenuItem(hMenu, IDM_E_COPY, MF_ENABLED|MF_BYCOMMAND);
  720. EnableMenuItem(hMenu, IDM_E_COPYTOKEN, MF_ENABLED|MF_BYCOMMAND);
  721. EnableMenuItem(hMenu, IDM_E_PASTE, MF_ENABLED|MF_BYCOMMAND);
  722. if ((!fMPJOutOfDate) && (!fPRJOutOfDate)) {
  723. int i;
  724. EnableMenuItem(hMenu, IDM_O_GENERATE, MF_ENABLED|MF_BYCOMMAND);
  725. for (i = IDM_FIRST_EDIT; i <= IDM_LAST_EDIT;i++) {
  726. EnableMenuItem(hMenu, i, MF_ENABLED|MF_BYCOMMAND);
  727. }
  728. }
  729. fTokFile = TRUE;
  730. fTokChanges = FALSE;
  731. SetCursor(hOldCursor);
  732. }
  733. return TRUE;
  734. }
  735. break;
  736. case WM_SAVEPROJECT:
  737. {
  738. HCURSOR hOldCursor;
  739. hOldCursor = SetCursor( hHourGlass);
  740. _fcloseall();
  741. if ( fPrjChanges ) {
  742. // Generate PRJ file
  743. if ( PutProjectData( gProj.szPRJ) != SUCCESS ) {
  744. SetCursor( hOldCursor);
  745. LoadStrIntoAnsiBuf (hInst, IDS_FILESAVEERR, szDHW, DHWSIZE);
  746. MessageBoxA( hWnd,szDHW, gProj.szPRJ, MB_ICONHAND | MB_OK);
  747. return FALSE;
  748. }
  749. fPrjChanges = FALSE;
  750. }
  751. fTokFile = FALSE;
  752. if (fTokChanges) {
  753. FILE *f = FOPEN( gProj.szTok, "wt");
  754. if ( f ) {
  755. SaveTokList(hWnd, f);
  756. FCLOSE(f);
  757. fTokChanges = FALSE;
  758. } else {
  759. SetCursor( hOldCursor);
  760. LoadStrIntoAnsiBuf(hInst, IDS_FILESAVEERR, szDHW, DHWSIZE);
  761. MessageBoxA( hWnd,
  762. szDHW,
  763. gProj.szTok,
  764. MB_ICONHAND | MB_OK);
  765. return FALSE;
  766. }
  767. }
  768. SetCursor( hOldCursor);
  769. return TRUE; // everything saved ok
  770. }
  771. default:
  772. break;
  773. }
  774. return ( DefWindowProc(hWnd, wMsg, wParam, lParam));
  775. }
  776. static void GetTextFromMTK( HWND hWnd, TOKEN *pTok, long lMtkPointer )
  777. {
  778. FILE *fp = FOPEN( gMstr.szMtk, "rt");
  779. if ( fp ) {
  780. TOKEN cTok, ccTok;
  781. BOOL fFound;
  782. pTok->wReserved = 0;
  783. if ( lMtkPointer >= 0 ) {
  784. fseek( fp, lMtkPointer, SEEK_SET);
  785. if ( !GetToken(fp,&cTok) ) {
  786. fFound = ((cTok.wType == pTok->wType)
  787. && (cTok.wName == pTok->wName)
  788. && (cTok.wID == pTok->wID)
  789. && (cTok.wFlag == pTok->wFlag)
  790. && (lstrcmp((TCHAR *)cTok.szName,
  791. (TCHAR *)pTok->szName) == 0));
  792. if ( fFound ) {
  793. // any changed old token
  794. SetDlgItemText( hWnd,
  795. IDD_TOKCURTEXT,
  796. (LPTSTR)cTok.szText);
  797. if ( ! GetToken( fp,&ccTok) ) {
  798. fFound = ((cTok.wType == ccTok.wType)
  799. && (cTok.wName == ccTok.wName)
  800. && (cTok.wID == ccTok.wID)
  801. && (cTok.wFlag == ccTok.wFlag)
  802. && (lstrcmp((TCHAR *)cTok.szName,
  803. (TCHAR *)ccTok.szName) == 0)
  804. && (cTok.wReserved & ST_CHANGED) );
  805. if ( fFound ) {
  806. SetDlgItemText( hWnd, IDD_TOKPREVTEXT, (LPTSTR)ccTok.szText);
  807. } else {
  808. // should this ever happen??
  809. SetDlgItemText( hWnd, IDD_TOKPREVTEXT, (LPTSTR)TEXT(""));
  810. }
  811. } else {
  812. // should this ever happen??
  813. SetDlgItemText( hWnd, IDD_TOKPREVTEXT, (LPTSTR)TEXT(""));
  814. }
  815. FCLOSE( fp);
  816. return;
  817. }
  818. }
  819. }
  820. pTok->wReserved = 0;
  821. if (FindToken(fp, pTok, 0)) {
  822. // any changed old token
  823. SetDlgItemText(hWnd, IDD_TOKCURTEXT, (LPTSTR)pTok->szText);
  824. } else {
  825. SetDlgItemText(hWnd, IDD_TOKCURTEXT, (LPTSTR)TEXT(""));
  826. }
  827. pTok->wReserved = ST_CHANGED;
  828. if (FindToken(fp, pTok, ST_CHANGED)) { // any old token
  829. SetDlgItemText(hWnd, IDD_TOKPREVTEXT, (LPTSTR)pTok->szText);
  830. } else {
  831. // should this ever happen??
  832. SetDlgItemText(hWnd, IDD_TOKPREVTEXT, (LPTSTR)TEXT(""));
  833. }
  834. FCLOSE(fp);
  835. }
  836. }
  837. /**
  838. * Function: DoListBoxCommand
  839. * Processes the messages sent to the list box. If the message is
  840. * not reconized as a list box message, it is ignored and not processed.
  841. * As the user scrolls through the tokens WM_UPDSTATLINE messages are
  842. * sent to the status window to indicate the current selected token.
  843. * The list box goes into Edit Mode by pressing the enter key, or
  844. * by double clicking on the list box. After the edit is done, a WM_TOKEDIT
  845. * message is sent back to the list box to update the token. The
  846. * list box uses control ID IDC_LIST.
  847. *
  848. * Arguments:
  849. * wMsg List Box message ID
  850. * wParam Either IDC_LIST, or VK_RETURN depending on wMsg
  851. * lParam LPTSTR to selected token during WM_TOKEDIT message.
  852. *
  853. * Returns:
  854. *
  855. * Errors Codes:
  856. * TRUE. Message processed.
  857. * FALSE. Message not processed.
  858. *
  859. * History:
  860. * 01/92 Implemented. TerryRu.
  861. * 01/92 Fixed problem with DblClick, and Enter processing. TerryRu.
  862. *
  863. **/
  864. INT_PTR DoListBoxCommand(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  865. {
  866. TOKEN tok; // structure to hold token read from token list
  867. TCHAR szName[32] = TEXT(""); // buffer to hold token name
  868. CHAR szTmpBuf[32] = ""; // buffer to hold token name
  869. TCHAR szID[7] = TEXT(""); // buffer to hold token id
  870. TCHAR sz[256] = TEXT(""); // buffer to hold messages
  871. static UINT wIndex;
  872. LONG lListParam = 0L;
  873. HWND hCtl = NULL;
  874. HGLOBAL hMem = NULL;
  875. LPTSTR lpstrToken = NULL;
  876. LPTOKDATA lpTokData;
  877. LONG lMtkPointer;
  878. // this is the WM_COMMAND
  879. switch (wMsg) {
  880. case WM_VIEW:
  881. {
  882. TCHAR *szBuffer;
  883. // Message sent by TOkEdigDlgProc to fill IDD_TOKCURTEXT
  884. // and IDD_TOKPREVTEXT fields in dialog box
  885. hMem = (HGLOBAL)SendMessage( hListWnd,
  886. LB_GETITEMDATA,
  887. (WPARAM)wIndex,
  888. (LPARAM)0);
  889. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  890. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  891. lMtkPointer = lpTokData->lMtkPointer;
  892. szBuffer = (TCHAR *)FALLOC( MEMSIZE( lstrlen( lpstrToken) + 1));
  893. lstrcpy( szBuffer, lpstrToken);
  894. GlobalUnlock( lpTokData->hToken );
  895. GlobalUnlock( hMem);
  896. ParseBufToTok( szBuffer, &tok);
  897. RLFREE( szBuffer);
  898. GetTextFromMTK(hTokEditDlgWnd, &tok, lMtkPointer );
  899. RLFREE( tok.szText);
  900. return TRUE;
  901. }
  902. case WM_TRANSLATE:
  903. {
  904. // Message sent by TokEditDlgProc to build a translation list
  905. HWND hDlgItem = NULL;
  906. int cTextLen = 0;
  907. TCHAR *szKey = NULL;
  908. TCHAR *szText = NULL;
  909. hDlgItem = GetDlgItem( hTokEditDlgWnd, IDD_TOKCURTEXT);
  910. cTextLen = GetWindowTextLength( hDlgItem);
  911. szKey = (TCHAR *)FALLOC( MEMSIZE( cTextLen + 1));
  912. szKey[0] = 0;
  913. GetDlgItemText( hTokEditDlgWnd,
  914. IDD_TOKCURTEXT,
  915. szKey,
  916. cTextLen + 1);
  917. hDlgItem = GetDlgItem( hTokEditDlgWnd, IDD_TOKCURTRANS);
  918. cTextLen = GetWindowTextLength( hDlgItem);
  919. szText = (TCHAR *)FALLOC( MEMSIZE( cTextLen + 1));
  920. *szText = 0;
  921. GetDlgItemText( hTokEditDlgWnd,
  922. IDD_TOKCURTRANS,
  923. szText,
  924. cTextLen + 1);
  925. TransString( szKey, szText, &pTransList, lFilePointer);
  926. RLFREE( szKey);
  927. RLFREE( szText);
  928. break;
  929. }
  930. case WM_TOKEDIT:
  931. {
  932. TCHAR *szBuffer;
  933. int cTextLen;
  934. // Message sent by TokEditDlgProc to
  935. // indicate change in the token text.
  936. // Response to the message by inserting
  937. // new token text into list box
  938. // Insert the selected token into token struct
  939. hMem = (HGLOBAL)SendMessage( hListWnd,
  940. LB_GETITEMDATA,
  941. (WPARAM)wIndex,
  942. (LPARAM)0);
  943. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  944. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  945. cTextLen = lstrlen( lpstrToken);
  946. szBuffer = (TCHAR *)FALLOC( MEMSIZE( cTextLen + 1));
  947. lstrcpy( szBuffer, lpstrToken);
  948. lMtkPointer = lpTokData->lMtkPointer;
  949. GlobalUnlock( lpTokData->hToken );
  950. GlobalUnlock( hMem);
  951. ParseBufToTok( szBuffer, &tok);
  952. RLFREE( szBuffer);
  953. RLFREE( tok.szText);
  954. // Copy new token text from edit box into the token struct
  955. cTextLen = lstrlen( (LPTSTR)lParam);
  956. tok.szText = (TCHAR *)FALLOC( MEMSIZE( cTextLen + 1));
  957. lstrcpy( tok.szText, (LPTSTR)lParam);
  958. // Mark token as clean
  959. #ifdef RLWIN32
  960. tok.wReserved = (WORD) ST_TRANSLATED | (WORD) wParam;
  961. #else
  962. tok.wReserved = ST_TRANSLATED | (WORD) wParam;
  963. #endif
  964. // should we clean up the delta token information??
  965. szBuffer = (TCHAR *)FALLOC( MEMSIZE( TokenToTextSize( &tok)));
  966. ParseTokToBuf( szBuffer, &tok);
  967. RLFREE( tok.szText);
  968. // Now remove old token
  969. SendMessage( hListWnd, WM_SETREDRAW, (WPARAM)FALSE, (LPARAM)0);
  970. SendMessage( hListWnd, LB_DELETESTRING, (WPARAM)wIndex, (LPARAM)0);
  971. // Replacing with the new token
  972. hMem = GlobalAlloc( GMEM_MOVEABLE, sizeof(TOKDATA) );
  973. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  974. lpTokData->hToken = GlobalAlloc(GMEM_MOVEABLE,
  975. MEMSIZE(lstrlen((TCHAR *)szBuffer)+1));
  976. lpstrToken = (LPTSTR) GlobalLock( lpTokData->hToken );
  977. lstrcpy((TCHAR *)lpstrToken, (TCHAR *)szBuffer);
  978. GlobalUnlock( lpTokData->hToken );
  979. lpTokData->lMtkPointer = lMtkPointer; //MtkPointer
  980. GlobalUnlock( hMem);
  981. RLFREE( szBuffer);
  982. SendMessage( hListWnd,
  983. LB_INSERTSTRING,
  984. (WPARAM)wIndex,
  985. (LPARAM)hMem);
  986. // Now put focus back on the current string
  987. SendMessage( hListWnd, LB_SETCURSEL, (WPARAM)wIndex, (LPARAM)0);
  988. SendMessage( hListWnd, WM_SETREDRAW, (WPARAM)TRUE, (LPARAM)0);
  989. InvalidateRect(hListWnd, NULL, TRUE);
  990. return TRUE;
  991. }
  992. case WM_CHARTOITEM:
  993. case WM_VKEYTOITEM:
  994. {
  995. #ifdef RLWIN16
  996. LONG lListParam = 0;
  997. #endif
  998. // Messages sent to list box when keys are depressed.
  999. // Check for Return key pressed.
  1000. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  1001. case VK_RETURN:
  1002. #ifdef RLWIN16
  1003. lListParam = (LONG) MAKELONG(NULL, LBN_DBLCLK);
  1004. SendMessage(hMainWnd, WM_COMMAND, IDC_LIST, lListParam);
  1005. #else
  1006. SendMessage( hMainWnd,
  1007. WM_COMMAND,
  1008. MAKEWPARAM( IDC_LIST, LBN_DBLCLK),
  1009. (LPARAM)0);
  1010. #endif
  1011. return TRUE;
  1012. default:
  1013. break;
  1014. }
  1015. break;
  1016. }
  1017. case WM_COMMAND:
  1018. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  1019. case IDC_LIST:
  1020. {
  1021. /*
  1022. *
  1023. * This is where we process the list box messages.
  1024. * The TokEditDlgProc is used to
  1025. * edit the token selected in LBS_DBLCLK message
  1026. *
  1027. */
  1028. switch (GET_WM_COMMAND_CMD(wParam, lParam)) {
  1029. case (UINT) LBN_ERRSPACE:
  1030. LoadString( hInst,
  1031. IDS_ERR_NO_MEMORY,
  1032. sz,
  1033. TCHARSIN( sizeof( sz)));
  1034. MessageBox( hWnd,
  1035. sz,
  1036. tszAppName,
  1037. MB_ICONHAND | MB_OK);
  1038. return TRUE;
  1039. case LBN_DBLCLK:
  1040. {
  1041. LPTSTR CurText = NULL;
  1042. LPTSTR PreText = NULL;
  1043. TCHAR szResIDStr[20] = TEXT("");
  1044. TCHAR *szBuffer;
  1045. wIndex = (UINT)SendMessage( hListWnd,
  1046. LB_GETCURSEL,
  1047. (WPARAM)0,
  1048. (LPARAM)0);
  1049. if (wIndex == (UINT) -1) {
  1050. return TRUE;
  1051. }
  1052. // double click, or Return entered,
  1053. // go into token edit mode.
  1054. if (!hTokEditDlgWnd) {
  1055. // set up modaless dialog box to edit token
  1056. #ifdef RLWIN32
  1057. hTokEditDlgWnd = CreateDialog(hInst,
  1058. TEXT("RLEdit"),
  1059. hWnd,
  1060. TokEditDlgProc);
  1061. #else
  1062. lpTokEditDlg =
  1063. (DLGPROC) MakeProcInstance(TokEditDlgProc,
  1064. hInst);
  1065. hTokEditDlgWnd = CreateDialog(hInst,
  1066. TEXT("RLEdit"),
  1067. hWnd,
  1068. lpTokEditDlg);
  1069. #endif
  1070. }
  1071. // Get token info from listbox, and place in token struct
  1072. hMem = (HGLOBAL)SendMessage( hListWnd,
  1073. LB_GETITEMDATA,
  1074. (WPARAM)wIndex,
  1075. (LPARAM)0);
  1076. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  1077. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  1078. lMtkPointer = lpTokData->lMtkPointer;
  1079. szBuffer = (LPTSTR)FALLOC( MEMSIZE( lstrlen( lpstrToken) + 1));
  1080. lstrcpy( szBuffer, lpstrToken);
  1081. GlobalUnlock( lpTokData->hToken );
  1082. GlobalUnlock( hMem);
  1083. ParseBufToTok(szBuffer, &tok);
  1084. RLFREE( szBuffer);
  1085. // Now get the token name
  1086. // Its either a string, or ordinal number
  1087. if (tok.szName[0]) {
  1088. lstrcpy( szName, tok.szName);
  1089. } else {
  1090. #ifdef UNICODE
  1091. _itoa(tok.wName, szTmpBuf, 10);
  1092. _MBSTOWCS( szName,
  1093. szTmpBuf,
  1094. WCHARSIN( sizeof( szName)),
  1095. ACHARSIN( strlen(szTmpBuf) + 1));
  1096. #else
  1097. _itoa(tok.wName, szName, 10);
  1098. #endif
  1099. }
  1100. // Now get the token id
  1101. #ifdef UNICODE
  1102. _itoa(tok.wID, szTmpBuf, 10);
  1103. _MBSTOWCS( szID,
  1104. szTmpBuf,
  1105. WCHARSIN( sizeof( szID)),
  1106. ACHARSIN( strlen(szTmpBuf) + 1));
  1107. #else
  1108. _itoa(tok.wID, szID, 10);
  1109. #endif
  1110. if ( tok.wType <= 16 || tok.wType == ID_RT_DLGINIT ) {
  1111. LoadString(hInst,
  1112. IDS_RESOURCENAMES+tok.wType,
  1113. szResIDStr,
  1114. TCHARSIN( sizeof( szResIDStr)));
  1115. } else {
  1116. #ifdef UNICODE
  1117. _itoa(tok.wType, szTmpBuf, 10);
  1118. _MBSTOWCS(szResIDStr,
  1119. szTmpBuf,
  1120. WCHARSIN( sizeof( szResIDStr)),
  1121. ACHARSIN( strlen(szTmpBuf) + 1));
  1122. #else
  1123. _itoa(tok.wType, szResIDStr, 10);
  1124. #endif
  1125. }
  1126. // Now insert token info in TokEdit Dialog Box
  1127. SetDlgItemText(hTokEditDlgWnd,
  1128. IDD_TOKTYPE,
  1129. (LPTSTR) szResIDStr);
  1130. SetDlgItemText(hTokEditDlgWnd,
  1131. IDD_TOKNAME,
  1132. (LPTSTR) szName);
  1133. SetDlgItemText(hTokEditDlgWnd,
  1134. IDD_TOKID,
  1135. (LPTSTR) szID);
  1136. SetDlgItemText(hTokEditDlgWnd,
  1137. IDD_TOKCURTRANS,
  1138. (LPTSTR) tok.szText);
  1139. SetDlgItemText(hTokEditDlgWnd,
  1140. IDD_TOKPREVTRANS,
  1141. (LPTSTR) tok.szText);
  1142. CheckDlgButton(hTokEditDlgWnd, IDD_DIRTY, 0);
  1143. if (tok.wReserved & ST_READONLY) {
  1144. CheckDlgButton(hTokEditDlgWnd, IDD_READONLY, 1);
  1145. EnableWindow(GetDlgItem(hTokEditDlgWnd,
  1146. IDD_TOKCURTRANS),
  1147. FALSE);
  1148. SetFocus(GetDlgItem(hTokEditDlgWnd, IDCANCEL));
  1149. } else {
  1150. CheckDlgButton(hTokEditDlgWnd, IDD_READONLY, 0);
  1151. EnableWindow(GetDlgItem(hTokEditDlgWnd,
  1152. IDD_TOKCURTRANS),
  1153. TRUE);
  1154. }
  1155. // we did not find anything in the delta info,
  1156. // so we need to read it from the master token.
  1157. GetTextFromMTK(hTokEditDlgWnd, &tok, lMtkPointer );
  1158. RLFREE( tok.szText);
  1159. // Disable OK button.
  1160. // User must enter text before it is enabled
  1161. hCtl = GetDlgItem(hTokEditDlgWnd, IDOK);
  1162. SendMessage( hMainWnd,
  1163. WM_TRANSLATE,
  1164. (LPARAM)0,
  1165. (LPARAM)0);
  1166. EnableWindow(hCtl, FALSE);
  1167. SetActiveWindow(hTokEditDlgWnd);
  1168. wIndex = (UINT)SendMessage( hListWnd,
  1169. LB_GETCURSEL,
  1170. (WPARAM)0,
  1171. (LPARAM)0);
  1172. return TRUE;
  1173. }
  1174. // let these messages fall through,
  1175. default:
  1176. break;
  1177. }
  1178. }
  1179. default:
  1180. return FALSE;
  1181. }
  1182. break; // WM_COMMAND Case
  1183. } // Main List Box Switch
  1184. return FALSE;
  1185. }
  1186. /**
  1187. * Function: DoMenuCommand.
  1188. * Processes the Menu Command messages.
  1189. *
  1190. * Errors Codes:
  1191. * TRUE. Message processed.
  1192. * FALSE. Message not processed.
  1193. *
  1194. * History:
  1195. * 01/92. Implemented. TerryRu.
  1196. *
  1197. **/
  1198. INT_PTR DoMenuCommand(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  1199. {
  1200. static BOOL fListBox = FALSE;
  1201. TCHAR sz[256]=TEXT("");
  1202. #ifndef RLWIN32
  1203. WNDPROC lpNewDlg, lpViewDlg;
  1204. #endif
  1205. int rc;
  1206. LPTOKDATA lpTokData;
  1207. long lMtkPointer;
  1208. // Commands entered from the application menu, or child windows.
  1209. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  1210. case IDM_P_NEW:
  1211. fEditing = FALSE; //... We are *not* editing an existing .PRJ
  1212. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1213. CHAR szFile[MAXFILENAME] = "";
  1214. if ( GetFileNameFromBrowse( hWnd,
  1215. gProj.szPRJ,
  1216. MAXFILENAME,
  1217. szSaveDlgTitle,
  1218. szFilterSpec,
  1219. "PRJ")) {
  1220. strcpy( szFile, gProj.szPRJ);
  1221. } else {
  1222. break; // user cancelled
  1223. }
  1224. #ifdef RLWIN32
  1225. if ( DialogBox( hInst, TEXT("PROJECT"), hWnd, NewDlgProc) == IDOK )
  1226. #else
  1227. lpNewDlg = MakeProcInstance(NewDlgProc, hInst);
  1228. if ( DialogBox( hInst, TEXT("PROJECT"), hWnd, lpNewDlg) == IDOK )
  1229. #endif
  1230. {
  1231. sprintf( szDHW, "%s - %s", szAppName, szFile);
  1232. SetWindowTextA( hWnd, szDHW);
  1233. gbNewProject = TRUE;
  1234. gProj.szTokDate[0] = 0;
  1235. strcpy( gProj.szPRJ, szFile);
  1236. fPrjChanges = TRUE;
  1237. SendMessage( hWnd, WM_READMPJDATA, (WPARAM)0, (LPARAM)0);
  1238. }
  1239. gbNewProject = FALSE;
  1240. #ifndef RLWIN32
  1241. FreeProcInstance(lpNewDlg);
  1242. #endif
  1243. break;
  1244. }
  1245. case IDM_P_EDIT:
  1246. fEditing = TRUE; //... We *are* editing an existing .PRJ
  1247. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1248. CHAR szOldMpj[ MAXFILENAME];
  1249. // Save old Master Project name
  1250. lstrcpyA( szOldMpj, gProj.szMpj);
  1251. #ifdef RLWIN32
  1252. if ( DialogBox( hInst, TEXT("PROJECT"), hWnd, NewDlgProc) == IDOK )
  1253. #else
  1254. lpNewDlg = MakeProcInstance(NewDlgProc, hInst);
  1255. if ( DialogBox( hInst, TEXT("PROJECT"), hWnd, lpNewDlg) == IDOK )
  1256. #endif
  1257. {
  1258. fPrjChanges = TRUE;
  1259. // Still same Master Project referenced?
  1260. if ( lstrcmpiA( szOldMpj, gProj.szMpj) != 0 ) {
  1261. gbNewProject = TRUE; // No
  1262. gProj.szTokDate[0] = 0;
  1263. SendMessage( hWnd, WM_READMPJDATA, (WPARAM)0, (LPARAM)0);
  1264. }
  1265. }
  1266. gbNewProject = FALSE;
  1267. #ifndef RLWIN32
  1268. FreeProcInstance(lpNewDlg);
  1269. #endif
  1270. break;
  1271. }
  1272. case IDM_P_OPEN:
  1273. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1274. szTempFileName[0] = 0;
  1275. if ( GetFileNameFromBrowse( hWnd,
  1276. szTempFileName,
  1277. MAXFILENAME,
  1278. szOpenDlgTitle,
  1279. szFilterSpec,
  1280. "PRJ") ) {
  1281. if ( GetProjectData( szTempFileName,
  1282. NULL,
  1283. NULL,
  1284. FALSE,
  1285. FALSE) == SUCCESS ) {
  1286. SendMessage( hWnd, WM_READMPJDATA, (WPARAM)0, (LPARAM)0);
  1287. sprintf( szDHW, "%s - %s", szAppName, szTempFileName);
  1288. SetWindowTextA( hMainWnd, szDHW);
  1289. strcpy( gProj.szPRJ, szTempFileName);
  1290. SendMessage( hMainWnd, WM_LOADTOKENS, (WPARAM)0, (LPARAM)0);
  1291. }
  1292. }
  1293. }
  1294. break;
  1295. case IDM_P_VIEW:
  1296. #ifdef RLWIN32
  1297. DialogBox(hInst, TEXT("VIEWPROJECT"), hWnd, ViewDlgProc);
  1298. #else
  1299. lpViewDlg = (WNDPROC) MakeProcInstance((WNDPROC)ViewDlgProc, hInst);
  1300. DialogBox(hInst, TEXT("VIEWPROJECT"), hWnd, lpViewDlg);
  1301. #endif
  1302. break;
  1303. case IDM_P_CLOSE:
  1304. {
  1305. HMENU hMenu;
  1306. hMenu=GetMenu(hWnd);
  1307. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1308. int i;
  1309. // Remove file name from window title
  1310. SetWindowTextA(hMainWnd, szAppName);
  1311. // Hide token list since it's going to be empty
  1312. ShowWindow(hListWnd, SW_HIDE);
  1313. // Remove the current token list
  1314. SendMessage( hListWnd, LB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
  1315. CleanDeltaList();
  1316. // Force Repaint of status Window
  1317. InvalidateRect(hStatusWnd, NULL, TRUE);
  1318. EnableMenuItem(hMenu, IDM_P_CLOSE, MF_GRAYED|MF_BYCOMMAND);
  1319. EnableMenuItem(hMenu, IDM_P_VIEW, MF_GRAYED|MF_BYCOMMAND);
  1320. EnableMenuItem(hMenu, IDM_P_EDIT, MF_GRAYED|MF_BYCOMMAND);
  1321. EnableMenuItem(hMenu, IDM_P_SAVE, MF_GRAYED|MF_BYCOMMAND);
  1322. EnableMenuItem(hMenu, IDM_E_FIND, MF_GRAYED|MF_BYCOMMAND);
  1323. EnableMenuItem(hMenu, IDM_E_FINDUP, MF_GRAYED|MF_BYCOMMAND);
  1324. EnableMenuItem(hMenu, IDM_E_FINDDOWN, MF_GRAYED|MF_BYCOMMAND);
  1325. EnableMenuItem(hMenu, IDM_E_REVIEW, MF_GRAYED|MF_BYCOMMAND);
  1326. EnableMenuItem(hMenu, IDM_E_ALLREVIEW, MF_GRAYED|MF_BYCOMMAND);
  1327. EnableMenuItem(hMenu, IDM_E_COPY, MF_GRAYED|MF_BYCOMMAND);
  1328. EnableMenuItem(hMenu, IDM_E_COPYTOKEN, MF_GRAYED|MF_BYCOMMAND);
  1329. EnableMenuItem(hMenu, IDM_E_PASTE, MF_GRAYED|MF_BYCOMMAND);
  1330. EnableMenuItem(hMenu, IDM_O_GENERATE, MF_GRAYED|MF_BYCOMMAND);
  1331. for (i = IDM_FIRST_EDIT; i <= IDM_LAST_EDIT;i++) {
  1332. EnableMenuItem(hMenu, i, MF_GRAYED|MF_BYCOMMAND);
  1333. }
  1334. }
  1335. break;
  1336. }
  1337. case IDM_P_SAVE:
  1338. if (fTokChanges || fPrjChanges) {
  1339. CHAR szPrjName[MAXFILENAME];
  1340. strcpy(szPrjName, gProj.szPRJ);
  1341. if ( SendMessage(hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1342. GetProjectData( szPrjName, NULL, NULL, FALSE, FALSE);
  1343. }
  1344. } else {
  1345. LoadString( hInst,
  1346. IDS_NOCHANGESYET,
  1347. sz,
  1348. TCHARSIN( sizeof( sz)));
  1349. MessageBox( hWnd,
  1350. sz,
  1351. tszAppName,
  1352. MB_ICONHAND | MB_OK);
  1353. }
  1354. break;
  1355. case IDM_P_EXIT:
  1356. SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0);
  1357. PostMessage( hMainWnd, WM_CLOSE, (WPARAM)0, (LPARAM)0);
  1358. break;
  1359. case IDM_E_COPYTOKEN:
  1360. {
  1361. HANDLE hStringMem;
  1362. LPTSTR lpString;
  1363. int nIndex = 0;
  1364. int nLength = 0;
  1365. LPTSTR lpstrToken;
  1366. // Is anything selected in the listbox
  1367. if ( (nIndex = (int)SendMessage( hListWnd,
  1368. LB_GETCURSEL,
  1369. (WPARAM)0,
  1370. (LPARAM)0)) != LB_ERR ) {
  1371. HGLOBAL hMem = (HGLOBAL)SendMessage( hListWnd,
  1372. LB_GETITEMDATA,
  1373. (WPARAM)nIndex,
  1374. (LPARAM)0);
  1375. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  1376. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  1377. nLength = lstrlen(lpstrToken);
  1378. // Allocate memory for the string
  1379. if ( (hStringMem = GlobalAlloc(GHND,
  1380. (DWORD) MEMSIZE(nLength + 1))) != NULL ) {
  1381. if ( (lpString = (LPTSTR)GlobalLock(hStringMem)) != NULL ) {
  1382. // Get the selected text
  1383. lstrcpy( lpString, lpstrToken);
  1384. GlobalUnlock( lpTokData->hToken );
  1385. GlobalUnlock( hMem);
  1386. // Unlock the block
  1387. GlobalUnlock( hStringMem);
  1388. // Open the Clipboard and clear its contents
  1389. OpenClipboard( hWnd);
  1390. EmptyClipboard();
  1391. // Give the Clipboard the text data
  1392. #if defined(UNICODE)
  1393. SetClipboardData( CF_UNICODETEXT, hStringMem);
  1394. #else // not UNICODE
  1395. SetClipboardData( CF_TEXT, hStringMem);
  1396. #endif // UNICODE
  1397. CloseClipboard();
  1398. hStringMem = NULL;
  1399. } else {
  1400. GlobalUnlock( lpTokData->hToken );
  1401. GlobalUnlock( hMem);
  1402. LoadString( hInst,
  1403. IDS_ERR_NO_MEMORY,
  1404. sz,
  1405. TCHARSIN( sizeof( sz)));
  1406. MessageBox( hWnd,
  1407. sz,
  1408. tszAppName,
  1409. MB_ICONHAND | MB_OK);
  1410. }
  1411. } else {
  1412. GlobalUnlock( lpTokData->hToken );
  1413. GlobalUnlock( hMem);
  1414. LoadString( hInst,
  1415. IDS_ERR_NO_MEMORY,
  1416. sz,
  1417. TCHARSIN( sizeof(sz)));
  1418. MessageBox( hWnd,
  1419. sz,
  1420. tszAppName,
  1421. MB_ICONHAND | MB_OK);
  1422. }
  1423. }
  1424. break;
  1425. }
  1426. case IDM_E_COPY:
  1427. {
  1428. HANDLE hStringMem;
  1429. LPTSTR lpString;
  1430. int nIndex = 0;
  1431. int nLength = 0;
  1432. int nActual = 0;
  1433. TOKEN tok;
  1434. LPTSTR lpstrToken;
  1435. // Is anything selected in the listbox
  1436. if ( (nIndex = (int)SendMessage( hListWnd,
  1437. LB_GETCURSEL,
  1438. (WPARAM)0,
  1439. (LPARAM)0)) != LB_ERR ) {
  1440. HGLOBAL hMem = (HGLOBAL)SendMessage( hListWnd,
  1441. LB_GETITEMDATA,
  1442. (WPARAM)nIndex,
  1443. (LPARAM)0);
  1444. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  1445. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  1446. lstrcpy( szString, lpstrToken);
  1447. GlobalUnlock( lpTokData->hToken );
  1448. GlobalUnlock( hMem);
  1449. ParseBufToTok( szString, &tok);
  1450. nLength = lstrlen( tok.szText);
  1451. // Allocate memory for the string
  1452. if ( (hStringMem =
  1453. GlobalAlloc( GHND, (DWORD)MEMSIZE( nLength + 1))) != NULL ) {
  1454. if ( (lpString =
  1455. (LPTSTR)GlobalLock( hStringMem)) != NULL) {
  1456. // Get the selected text
  1457. #ifdef RLWIN32
  1458. lstrcpy( lpString, tok.szText);
  1459. #else
  1460. _fstrcpy( lpString, tok.szText);
  1461. #endif
  1462. // Unlock the block
  1463. GlobalUnlock(hStringMem);
  1464. // Open the Clipboard and clear its contents
  1465. OpenClipboard( hWnd);
  1466. EmptyClipboard();
  1467. // Give the Clipboard the text data
  1468. #if defined(UNICODE)
  1469. SetClipboardData(CF_UNICODETEXT, hStringMem);
  1470. #else // not UNICODE
  1471. SetClipboardData( CF_TEXT, hStringMem);
  1472. #endif // UNICODE
  1473. CloseClipboard();
  1474. hStringMem = NULL;
  1475. } else {
  1476. LoadString( hInst,
  1477. IDS_ERR_NO_MEMORY,
  1478. sz,
  1479. TCHARSIN( sizeof( sz)));
  1480. MessageBox( hWnd,
  1481. sz,
  1482. tszAppName,
  1483. MB_ICONHAND | MB_OK);
  1484. }
  1485. } else {
  1486. LoadString( hInst,
  1487. IDS_ERR_NO_MEMORY,
  1488. sz,
  1489. TCHARSIN( sizeof( sz)));
  1490. MessageBox( hWnd,
  1491. sz,
  1492. tszAppName,
  1493. MB_ICONHAND | MB_OK);
  1494. }
  1495. RLFREE( tok.szText);
  1496. }
  1497. break;
  1498. }
  1499. case IDM_E_PASTE:
  1500. {
  1501. HANDLE hClipMem = NULL;
  1502. LPTSTR lpClipMem = NULL;
  1503. HGLOBAL hMem = NULL;
  1504. TCHAR *szString;
  1505. int nIndex = 0;
  1506. TOKEN tok;
  1507. LPTSTR lpstrToken;
  1508. if ( OpenClipboard( hWnd) ) {
  1509. #if defined(UNICODE)
  1510. if (IsClipboardFormatAvailable(CF_UNICODETEXT)
  1511. || IsClipboardFormatAvailable(CF_OEMTEXT))
  1512. #else // not UNICODE
  1513. if ( IsClipboardFormatAvailable( CF_TEXT)
  1514. || IsClipboardFormatAvailable( CF_OEMTEXT))
  1515. #endif // UNICODE
  1516. {
  1517. // Check for current position and change that token's text
  1518. nIndex = (int)SendMessage( hListWnd,
  1519. LB_GETCURSEL,
  1520. (WPARAM)0,
  1521. (LPARAM)0);
  1522. if (nIndex == LB_ERR) {
  1523. #if defined(UNICODE)
  1524. //if no select, just ignore
  1525. break;
  1526. #else // not UNICODE
  1527. nIndex = -1;
  1528. #endif // UNICODE
  1529. }
  1530. #if defined(UNICODE)
  1531. hClipMem = GetClipboardData(CF_UNICODETEXT);
  1532. #else // not UNICODE
  1533. hClipMem = GetClipboardData( CF_TEXT);
  1534. #endif // UNICODE
  1535. lpClipMem = (LPTSTR)GlobalLock( hClipMem);
  1536. hMem = (HGLOBAL)SendMessage( hListWnd,
  1537. LB_GETITEMDATA,
  1538. (WPARAM)nIndex,
  1539. (LPARAM)0);
  1540. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  1541. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  1542. if ( lpstrToken ) {
  1543. #if defined(UNICODE)
  1544. szString = (TCHAR *)FALLOC(
  1545. MEMSIZE(lstrlen(lpstrToken)+1) );
  1546. #else // not UNICODE
  1547. szString = (TCHAR *)
  1548. FALLOC( lstrlen( lpstrToken) + 1);
  1549. #endif // UNICODE
  1550. lstrcpy( szString, lpstrToken);
  1551. GlobalUnlock( lpTokData->hToken );
  1552. lMtkPointer = lpTokData->lMtkPointer; //Save
  1553. GlobalUnlock( hMem);
  1554. // copy the string to the token
  1555. ParseBufToTok(szString, &tok);
  1556. RLFREE( szString);
  1557. RLFREE( tok.szText);
  1558. tok.szText = (TCHAR *)
  1559. FALLOC( MEMSIZE( lstrlen( lpClipMem) + 1));
  1560. #ifdef RLWIN32
  1561. lstrcpy( tok.szText, lpClipMem);
  1562. #else
  1563. _fstrcpy(tok.szText, lpClipMem);
  1564. #endif
  1565. GlobalUnlock(hClipMem);
  1566. szString = (TCHAR *)
  1567. FALLOC( MEMSIZE( TokenToTextSize( &tok)));
  1568. ParseTokToBuf(szString, &tok);
  1569. RLFREE( tok.szText);
  1570. // Paste the text
  1571. SendMessage( hListWnd,
  1572. WM_SETREDRAW,
  1573. (WPARAM)FALSE,
  1574. (LPARAM)0);
  1575. SendMessage( hListWnd,
  1576. LB_DELETESTRING,
  1577. (WPARAM)nIndex,
  1578. (LPARAM)0);
  1579. hMem = GlobalAlloc( GMEM_MOVEABLE, sizeof(TOKDATA) );
  1580. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  1581. lpTokData->hToken = GlobalAlloc
  1582. ( GMEM_MOVEABLE, MEMSIZE(lstrlen(szString)+1) );
  1583. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  1584. lstrcpy( lpstrToken, szString);
  1585. RLFREE( szString);
  1586. GlobalUnlock( lpTokData->hToken );
  1587. lpTokData->lMtkPointer = lMtkPointer;
  1588. GlobalUnlock( hMem);
  1589. SendMessage( hListWnd,
  1590. LB_INSERTSTRING,
  1591. (WPARAM)nIndex,
  1592. (LPARAM)hMem);
  1593. SendMessage( hListWnd,
  1594. LB_SETCURSEL,
  1595. (WPARAM)nIndex,
  1596. (LPARAM)0);
  1597. fTokChanges = TRUE; // Set Dirty Flag
  1598. }
  1599. SendMessage( hListWnd,
  1600. WM_SETREDRAW,
  1601. (WPARAM)TRUE,
  1602. (LPARAM)0);
  1603. InvalidateRect(hListWnd, FALSE, TRUE);
  1604. // Close the Clipboard
  1605. CloseClipboard();
  1606. SetFocus(hListWnd);
  1607. }
  1608. }
  1609. CloseClipboard();
  1610. break;
  1611. }
  1612. case IDM_E_FINDDOWN:
  1613. if (fSearchStarted) {
  1614. if (!DoTokenSearchForRledit(szSearchType,
  1615. szSearchText,
  1616. wSearchStatus,
  1617. wSearchStatusMask,
  1618. 0,
  1619. TRUE)) {
  1620. TCHAR sz1[80], sz2[80];
  1621. LoadString( hInst,
  1622. IDS_FIND_TOKEN,
  1623. sz1,
  1624. TCHARSIN( sizeof( sz1)));
  1625. LoadString( hInst,
  1626. IDS_TOKEN_NOT_FOUND,
  1627. sz2,
  1628. TCHARSIN( sizeof( sz2)));
  1629. MessageBox( hWnd,
  1630. sz2,
  1631. sz1,
  1632. MB_ICONINFORMATION | MB_OK);
  1633. }
  1634. break;
  1635. }
  1636. case IDM_E_FINDUP:
  1637. if (fSearchStarted) {
  1638. if (!DoTokenSearchForRledit(szSearchType,
  1639. szSearchText,
  1640. wSearchStatus,
  1641. wSearchStatusMask,
  1642. 1,
  1643. TRUE)) {
  1644. TCHAR sz1[80], sz2[80];
  1645. LoadString( hInst,
  1646. IDS_FIND_TOKEN,
  1647. sz1,
  1648. TCHARSIN( sizeof( sz1)));
  1649. LoadString( hInst,
  1650. IDS_TOKEN_NOT_FOUND,
  1651. sz2,
  1652. TCHARSIN( sizeof( sz2)));
  1653. MessageBox( hWnd,
  1654. sz2,
  1655. sz1,
  1656. MB_ICONINFORMATION | MB_OK);
  1657. }
  1658. break;
  1659. }
  1660. case IDM_E_FIND:
  1661. {
  1662. #ifndef RLWIN32
  1663. WNDPROC lpfnTOKFINDMsgProc;
  1664. lpfnTOKFINDMsgProc = MakeProcInstance( (WNDPROC)TOKFINDMsgProc,
  1665. hInst);
  1666. if ( DialogBox( hInst, TEXT("TOKFIND"), hWnd, lpfnTOKFINDMsgProc) == -1)
  1667. #else
  1668. if ( DialogBox( hInst, TEXT("TOKFIND"), hWnd, TOKFINDMsgProc) == -1)
  1669. #endif
  1670. {
  1671. #ifndef DBCS
  1672. // 'Token Not Found' is strange because user selected cancel
  1673. TCHAR sz1[80], sz2[80];
  1674. LoadString( hInst,
  1675. IDS_FIND_TOKEN,
  1676. sz1,
  1677. TCHARSIN( sizeof( sz1)));
  1678. LoadString( hInst,
  1679. IDS_TOKEN_NOT_FOUND,
  1680. sz2,
  1681. TCHARSIN( sizeof( sz2)));
  1682. MessageBox( hWnd,
  1683. sz2,
  1684. sz1,
  1685. MB_ICONINFORMATION | MB_OK);
  1686. #endif //DBCS
  1687. }
  1688. #ifndef RLWIN32
  1689. FreeProcInstance( lpfnTOKFINDMsgProc);
  1690. #endif
  1691. return TRUE;
  1692. }
  1693. case IDM_E_REVIEW:
  1694. {
  1695. int wSaveSelection;
  1696. nUpdateMode = 1;
  1697. // set listbox selection to begining of the token list
  1698. wSaveSelection = (UINT)SendMessage( hListWnd,
  1699. LB_GETCURSEL,
  1700. (WPARAM)0,
  1701. (LPARAM)0);
  1702. // Selection for REVIEW starts with the user-selected line, (PW)
  1703. // not at the top of the token list. (PW)
  1704. // SendMessage(hListWnd, LB_SETCURSEL, 0, 0L); (PW)
  1705. if ( DoTokenSearchForRledit( NULL,
  1706. NULL,
  1707. ST_TRANSLATED | ST_DIRTY,
  1708. ST_TRANSLATED | ST_DIRTY,
  1709. FALSE,
  1710. FALSE) ) {
  1711. #ifdef RLWIN16
  1712. LONG lListParam;
  1713. lListParam = MAKELONG(NULL, LBN_DBLCLK);
  1714. SendMessage( hMainWnd,
  1715. WM_COMMAND,
  1716. (WPARAM)IDC_LIST,
  1717. (LPARAM)lListParam);
  1718. #else
  1719. SendMessage( hMainWnd,
  1720. WM_COMMAND,
  1721. MAKEWPARAM( IDC_LIST, LBN_DBLCLK),
  1722. (LPARAM)0);
  1723. #endif
  1724. }
  1725. break;
  1726. }
  1727. case IDM_E_ALLREVIEW:
  1728. {
  1729. UINT wListParam;
  1730. UINT wIndex, wcTokens;
  1731. wIndex = (UINT)SendMessage( hListWnd, LB_GETCURSEL, 0, 0L);
  1732. wcTokens = (UINT)SendMessage( hListWnd, LB_GETCOUNT, 0, 0L );
  1733. if ( wcTokens == wIndex )
  1734. break;
  1735. nUpdateMode = 2;
  1736. SendMessage( hListWnd, LB_SETCURSEL, wIndex, 0L);
  1737. wListParam = (UINT) MAKELONG(IDC_LIST, LBN_DBLCLK);
  1738. SendMessage(hMainWnd, WM_COMMAND, wListParam, (LPARAM)0);
  1739. break;
  1740. }
  1741. case IDM_O_GENERATE:
  1742. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1743. HCURSOR hOldCursor;
  1744. hOldCursor = SetCursor( hHourGlass);
  1745. rc = GenerateImageFile( gProj.szBld,
  1746. gMstr.szSrc,
  1747. gProj.szTok,
  1748. gMstr.szRdfs,
  1749. 0);
  1750. SetCursor( hOldCursor);
  1751. }
  1752. break;
  1753. case IDM_H_CONTENTS:
  1754. {
  1755. OFSTRUCT Of = { 0, 0, 0, 0, 0, ""};
  1756. if ( OpenFile( gszHelpFile, &Of, OF_EXIST) == HFILE_ERROR ) {
  1757. LoadString( hInst, IDS_ERR_NO_HELP, sz, TCHARSIN( sizeof( sz)));
  1758. MessageBox( hWnd, sz, NULL, MB_OK);
  1759. } else {
  1760. WinHelpA( hWnd, gszHelpFile, HELP_KEY, (DWORD_PTR)(LPSTR)"RLEdit");
  1761. }
  1762. break;
  1763. }
  1764. case IDM_H_ABOUT:
  1765. {
  1766. #ifndef RLWIN32
  1767. WNDPROC lpProcAbout;
  1768. lpProcAbout = MakeProcInstance(About, hInst);
  1769. DialogBox(hInst, TEXT("ABOUT"), hWnd, lpProcAbout);
  1770. FreeProcInstance(lpProcAbout);
  1771. #else
  1772. DialogBox(hInst, TEXT("ABOUT"), hWnd, About);
  1773. #endif
  1774. break;
  1775. }
  1776. break;
  1777. default:
  1778. if (wParam <= IDM_LAST_EDIT && wParam >= IDM_FIRST_EDIT) {
  1779. // USER IS INVOKING AN EDITOR
  1780. CHAR szEditor[MAXFILENAME] = "";
  1781. if ( LoadStrIntoAnsiBuf(hInst, (UINT)wParam, szEditor, sizeof(szEditor))) {
  1782. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1783. HCURSOR hOldCursor;
  1784. hOldCursor = SetCursor(hHourGlass);
  1785. MyGetTempFileName(0, "RES", 0, szTempRes);
  1786. fInThirdPartyEditer = TRUE;
  1787. if (gProj.fSourceEXE) {
  1788. // we need to first extract the .RES from the .EXE
  1789. CHAR sz[MAXFILENAME] = "";
  1790. MyGetTempFileName(0, "RES", 0, sz);
  1791. ExtractResFromExe32A( gMstr. szSrc, sz, 0);
  1792. GenerateRESfromRESandTOKandRDFs( szTempRes,
  1793. sz,
  1794. gProj.szTok,
  1795. gMstr.szRdfs,
  1796. ID_RT_DIALOG);
  1797. remove(sz);
  1798. } else {
  1799. GenerateRESfromRESandTOKandRDFs( szTempRes,
  1800. gMstr.szSrc,
  1801. gProj.szTok,
  1802. gMstr.szRdfs,
  1803. ID_RT_DIALOG);
  1804. }
  1805. SetCursor( hOldCursor);
  1806. ExecResEditor( hWnd, szEditor, szTempRes, "");
  1807. }
  1808. }
  1809. }
  1810. break; // default
  1811. }
  1812. return FALSE;
  1813. }
  1814. #ifdef RLWIN16
  1815. static int ExecResEditor(HWND hWnd, CHAR *szEditor, CHAR *szFile, CHAR *szArgs)
  1816. {
  1817. CHAR szExecCmd[256];
  1818. int RetCode;
  1819. // generate command line
  1820. lstrcpy( szExecCmd, szEditor);
  1821. lstrcat( szExecCmd, " ");
  1822. lstrcat( szExecCmd, szArgs);
  1823. lstrcat( szExecCmd, " ");
  1824. lstrcat( szExecCmd, szFile);
  1825. lpfnWatchTask = MakeProcInstance(WatchTask, hInst);
  1826. NotifyRegister(NULL, (LPFNNOTIFYCALLBACK)lpfnWatchTask, NF_NORMAL);
  1827. fWatchEditor = TRUE;
  1828. // exec resource editor
  1829. RetCode = WinExec(szExecCmd, SW_SHOWNORMAL);
  1830. if (RetCode > 31) {
  1831. // successful execution
  1832. ShowWindow(hWnd, SW_HIDE);
  1833. } else {
  1834. // unsuccessful execution
  1835. CHAR sz[80];
  1836. NotifyUnRegister(NULL);
  1837. FreeProcInstance(lpfnWatchTask);
  1838. remove(szFile);
  1839. fInThirdPartyEditer = FALSE;
  1840. SendMessage( hWnd, WM_LOADTOKENS, (WPARAM)0, (LPARAM)0);
  1841. LoadString( hInst, IDS_GENERALFAILURE, sz, TCHARSIN( sizeof( sz)));
  1842. MessageBox( hWnd, sz, tszAppName, MB_OK);
  1843. }
  1844. return RetCode;
  1845. }
  1846. #endif
  1847. #ifdef RLWIN32
  1848. static int ExecResEditor(HWND hWnd, CHAR *szEditor, CHAR *szFile, CHAR *szArgs)
  1849. {
  1850. TCHAR wszExecCmd[256];
  1851. CHAR szExecCmd[256];
  1852. DWORD dwRetCode = 0;
  1853. DWORD dwExitCode = 0;
  1854. BOOL fSuccess = FALSE;
  1855. BOOL fExit = FALSE;
  1856. PROCESS_INFORMATION ProcessInfo;
  1857. STARTUPINFO StartupInfo;
  1858. StartupInfo.cb = sizeof(STARTUPINFO);
  1859. StartupInfo.lpReserved = NULL;
  1860. StartupInfo.lpDesktop = NULL;
  1861. StartupInfo.lpTitle = TEXT("Resize Dialogs");
  1862. StartupInfo.dwX = 0L;
  1863. StartupInfo.dwY = 0L;
  1864. StartupInfo.dwXSize = 0L;
  1865. StartupInfo.dwYSize = 0L;
  1866. StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
  1867. StartupInfo.wShowWindow = SW_SHOWDEFAULT;
  1868. StartupInfo.lpReserved2 = NULL;
  1869. StartupInfo.cbReserved2 = 0;
  1870. // generate command line
  1871. strcpy(szExecCmd, szEditor);
  1872. strcat(szExecCmd, " ");
  1873. strcat(szExecCmd, szArgs);
  1874. strcat(szExecCmd, " ");
  1875. strcat(szExecCmd, szFile);
  1876. #ifdef UNICODE
  1877. _MBSTOWCS( wszExecCmd,
  1878. szExecCmd,
  1879. WCHARSIN( sizeof( wszExecCmd)),
  1880. ACHARSIN( strlen(szExecCmd) + 1));
  1881. #else
  1882. strcpy(wszExecCmd, szExecCmd);
  1883. #endif
  1884. fSuccess = CreateProcess( (LPTSTR) NULL,
  1885. wszExecCmd,
  1886. NULL,
  1887. NULL,
  1888. FALSE,
  1889. NORMAL_PRIORITY_CLASS,
  1890. NULL,
  1891. NULL,
  1892. &StartupInfo,
  1893. &ProcessInfo); /* try to create a process */
  1894. if ( fSuccess ) {
  1895. // wait for the editor to complete */
  1896. dwRetCode = WaitForSingleObject( ProcessInfo.hProcess, 0xFFFFFFFF) ;
  1897. if ( ! dwRetCode ) {
  1898. // editor terminated, check exit code
  1899. fExit = GetExitCodeProcess( ProcessInfo.hProcess, &dwExitCode) ;
  1900. } else {
  1901. fExit = FALSE;
  1902. }
  1903. // close the editor object handles
  1904. CloseHandle( ProcessInfo.hThread) ;
  1905. CloseHandle( ProcessInfo.hProcess) ;
  1906. if ( fExit ) {
  1907. // successful execution
  1908. ShowWindow(hWnd, SW_HIDE);
  1909. SendMessage(hMainWnd, WM_EDITER_CLOSED, 0, 0);
  1910. } else {
  1911. // unsuccessful execution
  1912. remove( szFile);
  1913. fInThirdPartyEditer = FALSE;
  1914. SendMessage( hWnd, WM_LOADTOKENS, (WPARAM)0, (LPARAM)0);
  1915. LoadStrIntoAnsiBuf( hInst, IDS_GENERALFAILURE, szDHW, DHWSIZE);
  1916. MessageBoxA( hWnd, szDHW, szEditor, MB_ICONSTOP|MB_OK);
  1917. }
  1918. } else {
  1919. CHAR szText[ 80] = "";
  1920. LPSTR pszMsg = szText;
  1921. dwRetCode = GetLastError();
  1922. if ( dwRetCode == ERROR_PATH_NOT_FOUND ) {
  1923. pszMsg = ", Path not found.";
  1924. } else if ( dwRetCode == ERROR_FILE_NOT_FOUND ) {
  1925. OFSTRUCT Of = { 0, 0, 0, 0, 0, ""};
  1926. sprintf( szText,
  1927. ", File \"%s\" not found.",
  1928. OpenFile( szFile, &Of, OF_EXIST) != HFILE_ERROR
  1929. ? szEditor
  1930. : szFile);
  1931. }
  1932. sprintf( szDHW,
  1933. "Command \"%s\" failed.\nSystem error code = %d%s",
  1934. szExecCmd,
  1935. dwRetCode,
  1936. pszMsg);
  1937. MessageBoxA( hWnd, szDHW, szAppName, MB_ICONEXCLAMATION|MB_OK);
  1938. fExit = FALSE;
  1939. }
  1940. return ( fExit);
  1941. }
  1942. #endif
  1943. /**
  1944. * Function: WatchTask
  1945. * A callback function installed by a NotifyRegister function.
  1946. * This function is installed by the dialog editer command and is used
  1947. * to tell RLEDIT when the dialog editer has been closed by the user.
  1948. *
  1949. * To use this function, set fWatchEditor to TRUE and install this
  1950. * callback function by using NotifyRegister. The next task initiated
  1951. * (in our case via a WinExec call) will be watched for termination.
  1952. *
  1953. * When WatchTask sees that the task being watched has terminated it
  1954. * posts a WM_EDITER_CLOSED message to RLEDITs main window.
  1955. *
  1956. * History:
  1957. * 2/92, implemented SteveBl
  1958. */
  1959. #ifdef RLWIN16
  1960. BOOL PASCAL _loadds WatchTask(WORD wID, DWORD dwData)
  1961. {
  1962. static HTASK htWatchedTask;
  1963. static BOOL fWatching = FALSE;
  1964. switch (wID) {
  1965. case NFY_STARTTASK:
  1966. if (fWatchEditor) {
  1967. htWatchedTask = GetCurrentTask();
  1968. fWatching = TRUE;
  1969. fWatchEditor = FALSE;
  1970. }
  1971. break;
  1972. case NFY_EXITTASK:
  1973. if (fWatching) {
  1974. if (GetCurrentTask() == htWatchedTask) {
  1975. PostMessage(hMainWnd, WM_EDITER_CLOSED, 0, 0);
  1976. fWatching = FALSE;
  1977. }
  1978. }
  1979. break;
  1980. }
  1981. return FALSE;
  1982. }
  1983. #endif
  1984. /**
  1985. *
  1986. *
  1987. * Function: TokEditDlgProc
  1988. * Procedure for the edit mode dialog window. Loads the selected token
  1989. * info into the window, and allows the user to change the token text.
  1990. * Once the edit is complete, the procedure sends a message to the
  1991. * list box windows to update the current token info.
  1992. *
  1993. *
  1994. * Arguments:
  1995. *
  1996. * Returns: NA.
  1997. *
  1998. * Errors Codes:
  1999. * TRUE, carry out edit, and update token list box.
  2000. * FALSE, cancel edit.
  2001. *
  2002. * History:
  2003. *
  2004. *
  2005. **/
  2006. INT_PTR CALLBACK TokEditDlgProc(
  2007. HWND hDlg,
  2008. UINT wMsg,
  2009. WPARAM wParam,
  2010. LPARAM lParam)
  2011. {
  2012. HWND hCtl = NULL;
  2013. HWND hParentWnd = NULL;
  2014. UINT static wcTokens = 0;
  2015. UINT wNotifyCode = 0;
  2016. UINT wIndex = 0;
  2017. #ifdef RLWIN16
  2018. LONG lListParam = 0;
  2019. #endif
  2020. switch ( wMsg ) {
  2021. case WM_INITDIALOG:
  2022. cwCenter( hDlg, 0);
  2023. wcTokens = (UINT)SendMessage( hListWnd,
  2024. LB_GETCOUNT,
  2025. (WPARAM)0,
  2026. (LPARAM)0);
  2027. wcTokens--;
  2028. // only allow skip button if in update mode
  2029. if ( ! nUpdateMode ) {
  2030. if ( (hCtl = GetDlgItem( hDlg, IDD_SKIP)) ) {
  2031. EnableWindow( hCtl, FALSE);
  2032. }
  2033. } else {
  2034. if ( (hCtl = GetDlgItem( hDlg, IDD_SKIP)) ) {
  2035. EnableWindow( hCtl, TRUE);
  2036. }
  2037. }
  2038. // disallow auto translate if we don't have a glossary file
  2039. if ( *gProj.szGlo == '\0' ) {
  2040. hCtl = GetDlgItem( hDlg, IDD_TRANSLATE);
  2041. EnableWindow( hCtl, FALSE);
  2042. hCtl = GetDlgItem( hDlg, IDD_ADD);
  2043. EnableWindow( hCtl, FALSE);
  2044. }
  2045. return ( TRUE);
  2046. case WM_COMMAND:
  2047. switch ( GET_WM_COMMAND_ID( wParam, lParam) ) {
  2048. case IDD_TOKCURTRANS:
  2049. wNotifyCode = GET_WM_COMMAND_CMD( wParam, lParam);
  2050. hCtl = GET_WM_COMMAND_HWND( wParam, lParam);
  2051. if ( wNotifyCode == EN_CHANGE ) {
  2052. if ( hCtl = GetDlgItem( hDlg, IDOK) ) {
  2053. EnableWindow( hCtl, TRUE);
  2054. }
  2055. }
  2056. break;
  2057. case IDD_ADD:
  2058. {
  2059. TCHAR *szUntranslated = NULL;
  2060. TCHAR *szTranslated = NULL;
  2061. TCHAR *sz = NULL;
  2062. TCHAR szMask[80] = TEXT("");
  2063. HWND hDlgItem = NULL;
  2064. int cCurTextLen = 0;
  2065. int cTotalTextLen = 80;
  2066. hDlgItem = GetDlgItem( hDlg, IDD_TOKCURTEXT);
  2067. cCurTextLen = GetWindowTextLength( hDlgItem);
  2068. cTotalTextLen += cCurTextLen;
  2069. szUntranslated = (TCHAR *)FALLOC( MEMSIZE( cCurTextLen + 1));
  2070. GetDlgItemText( hDlg,
  2071. IDD_TOKCURTEXT,
  2072. szUntranslated,
  2073. cCurTextLen + 1);
  2074. hDlgItem = GetDlgItem( hDlg, IDD_TOKCURTRANS);
  2075. cCurTextLen = GetWindowTextLength( hDlgItem);
  2076. cTotalTextLen += cCurTextLen;
  2077. szTranslated = (TCHAR *)FALLOC( MEMSIZE( cCurTextLen + 1));
  2078. GetDlgItemText( hDlg,
  2079. IDD_TOKCURTRANS,
  2080. szTranslated,
  2081. cCurTextLen + 1);
  2082. LoadString( hInst,
  2083. IDS_ADDGLOSS,
  2084. szMask,
  2085. TCHARSIN( sizeof(szMask)));
  2086. sz = (TCHAR *)FALLOC( MEMSIZE( cTotalTextLen + 1));
  2087. wsprintf( sz, szMask, szTranslated, szUntranslated);
  2088. if ( MessageBox( hDlg,
  2089. sz,
  2090. tszAppName,
  2091. MB_ICONQUESTION | MB_YESNO) == IDYES) {
  2092. HCURSOR hOldCursor = SetCursor( hHourGlass);
  2093. AddTranslation( szUntranslated,
  2094. szTranslated,
  2095. lFilePointer);
  2096. TransString( szUntranslated,
  2097. szTranslated,
  2098. &pTransList,
  2099. lFilePointer);
  2100. SetCursor( hOldCursor);
  2101. }
  2102. RLFREE( sz);
  2103. RLFREE( szUntranslated);
  2104. RLFREE( szTranslated);
  2105. break;
  2106. }
  2107. case IDD_UNTRANSLATE:
  2108. {
  2109. int cTextLen = 0;
  2110. TCHAR *sz = NULL;
  2111. HWND hDlgItem = NULL;
  2112. hDlgItem = GetDlgItem( hDlg, IDD_TOKCURTEXT);
  2113. cTextLen = GetWindowTextLength( hDlgItem);
  2114. sz = (TCHAR *)FALLOC( MEMSIZE( cTextLen + 1));
  2115. GetDlgItemText( hDlg,
  2116. IDD_TOKCURTEXT,
  2117. sz,
  2118. cTextLen + 1);
  2119. SetDlgItemText( hDlg, IDD_TOKCURTRANS, sz);
  2120. RLFREE( sz);
  2121. break;
  2122. }
  2123. case IDD_TRANSLATE:
  2124. // Get next thing in the translation list
  2125. if ( pTransList ) {
  2126. pTransList = pTransList->pNext;
  2127. SetDlgItemText( hDlg, IDD_TOKCURTRANS, pTransList->sz);
  2128. }
  2129. break;
  2130. case IDD_SKIP:
  2131. wIndex = (UINT)SendMessage( hListWnd,
  2132. LB_GETCURSEL,
  2133. (LPARAM)0,
  2134. (LPARAM)0);
  2135. if ( nUpdateMode == 2 && wIndex < wcTokens ) {
  2136. wIndex++;
  2137. SendMessage( hListWnd, LB_SETCURSEL, wIndex, 0L );
  2138. SendMessage( hMainWnd,
  2139. WM_COMMAND,
  2140. MAKEWPARAM( IDC_LIST, LBN_DBLCLK),
  2141. (LPARAM)0);
  2142. return ( TRUE );
  2143. } else if ( nUpdateMode == 1 && (wIndex < wcTokens) ) {
  2144. wIndex++;
  2145. SendMessage( hListWnd,
  2146. LB_SETCURSEL,
  2147. (WPARAM)wIndex,
  2148. (LPARAM)0);
  2149. if ( DoTokenSearchForRledit( NULL,
  2150. NULL,
  2151. ST_TRANSLATED | ST_DIRTY,
  2152. ST_TRANSLATED | ST_DIRTY,
  2153. FALSE,
  2154. FALSE) ) {
  2155. // go into edit mode
  2156. wIndex = (UINT)SendMessage( hListWnd,
  2157. LB_GETCURSEL,
  2158. (WPARAM)0,
  2159. (LPARAM)0);
  2160. #ifdef RLWIN16
  2161. SendMessage( hMainWnd,
  2162. WM_COMMAND,
  2163. IDC_LIST,
  2164. MAKELONG( NULL, LBN_DBLCLK));
  2165. #else
  2166. SendMessage( hMainWnd,
  2167. WM_COMMAND,
  2168. MAKEWPARAM( IDC_LIST, LBN_DBLCLK),
  2169. (LPARAM)0);
  2170. #endif
  2171. return TRUE;
  2172. }
  2173. }
  2174. nUpdateMode = 0;
  2175. // remove edit dialog box
  2176. DestroyWindow( hDlg);
  2177. #ifndef RLWIN32
  2178. FreeProcInstance( (FARPROC)lpTokEditDlg);
  2179. #endif
  2180. hTokEditDlgWnd = 0;
  2181. break;
  2182. case IDD_READONLY:
  2183. if ( IsDlgButtonChecked( hDlg, IDD_READONLY) ) {
  2184. EnableWindow( GetDlgItem( hDlg, IDD_TOKCURTRANS), FALSE);
  2185. } else {
  2186. EnableWindow( GetDlgItem( hDlg, IDD_TOKCURTRANS), TRUE);
  2187. }
  2188. break;
  2189. case IDOK:
  2190. {
  2191. int cTokenTextLen = 0;
  2192. TCHAR *szTokTextBuf = NULL;
  2193. HWND hDlgItem = NULL;
  2194. wIndex = (UINT)SendMessage( hListWnd,
  2195. LB_GETCURSEL,
  2196. (WPARAM)0,
  2197. (LPARAM)0);
  2198. fTokChanges = TRUE;
  2199. // set flag to show token list has changed
  2200. // Extract String from IDD_TOKTEXT edit control
  2201. hDlgItem = GetDlgItem( hDlg, IDD_TOKCURTRANS);
  2202. cTokenTextLen = GetWindowTextLength( hDlgItem);
  2203. szTokTextBuf = (TCHAR *)FALLOC( MEMSIZE( cTokenTextLen + 1));
  2204. GetDlgItemText( hDlg,
  2205. IDD_TOKCURTRANS,
  2206. szTokTextBuf,
  2207. cTokenTextLen+1);
  2208. hParentWnd = GetParent( hDlg);
  2209. SendMessage( hParentWnd,
  2210. WM_TOKEDIT,
  2211. (WPARAM)((IsDlgButtonChecked( hDlg, IDD_READONLY)
  2212. ? ST_READONLY : 0)
  2213. | (IsDlgButtonChecked( hDlg, IDD_DIRTY)
  2214. ? ST_DIRTY : 0)),
  2215. (LPARAM)szTokTextBuf);
  2216. RLFREE( szTokTextBuf);
  2217. // Exit, or goto to next changed token if in update mode
  2218. if ( nUpdateMode == 2 && wIndex < wcTokens ) {
  2219. wIndex++;
  2220. SendMessage( hListWnd, LB_SETCURSEL, wIndex, 0L );
  2221. SendMessage( hMainWnd,
  2222. WM_COMMAND,
  2223. MAKEWPARAM( IDC_LIST, LBN_DBLCLK),
  2224. (LPARAM)0);
  2225. return ( TRUE );
  2226. } else if ( nUpdateMode == 1 && (wIndex < wcTokens) ) {
  2227. wIndex++;
  2228. SendMessage( hListWnd,
  2229. LB_SETCURSEL,
  2230. (WPARAM)wIndex,
  2231. (LPARAM)0);
  2232. if ( DoTokenSearchForRledit( NULL,
  2233. NULL,
  2234. ST_TRANSLATED | ST_DIRTY,
  2235. ST_TRANSLATED | ST_DIRTY,
  2236. FALSE,
  2237. FALSE) ) {
  2238. // go into edit mode
  2239. #ifdef RLWIN16
  2240. lListParam = MAKELONG(NULL, LBN_DBLCLK);
  2241. SendMessage( hMainWnd,
  2242. WM_COMMAND,
  2243. IDC_LIST,
  2244. lListParam);
  2245. #else
  2246. SendMessage( hMainWnd,
  2247. WM_COMMAND,
  2248. MAKEWPARAM(IDC_LIST, LBN_DBLCLK),
  2249. (LPARAM)0);
  2250. #endif
  2251. return ( TRUE);
  2252. }
  2253. }
  2254. }
  2255. // fall through to IDCANCEL
  2256. case IDCANCEL:
  2257. nUpdateMode = 0;
  2258. // remove edit dialog box
  2259. DestroyWindow( hDlg);
  2260. #ifndef RLWIN32
  2261. FreeProcInstance( lpTokEditDlg);
  2262. #endif
  2263. hTokEditDlgWnd = 0;
  2264. break;
  2265. } // GET_WM_COMMAND_ID
  2266. return ( TRUE);
  2267. default:
  2268. if ( (hCtl = GetDlgItem(hDlg, IDOK)) ) {
  2269. EnableWindow( hCtl, TRUE);
  2270. }
  2271. return ( FALSE);
  2272. } // Main Switch
  2273. }
  2274. /**
  2275. *
  2276. * Function: TOKFINDMsgProc
  2277. *
  2278. * Arguments:
  2279. *
  2280. * Returns:
  2281. * NA.
  2282. *
  2283. * Errors Codes:
  2284. *
  2285. * History:
  2286. *
  2287. **/
  2288. //#ifdef RLWIN32
  2289. //BOOL CALLBACK TOKFINDMsgProc(HWND hWndDlg, UINT wMsg, UINT wParam, LONG lParam)
  2290. //#else
  2291. INT_PTR CALLBACK TOKFINDMsgProc(
  2292. HWND hWndDlg,
  2293. UINT wMsg,
  2294. WPARAM wParam,
  2295. LPARAM lParam)
  2296. //#endif
  2297. {
  2298. HWND hCtl;
  2299. int rgiTokenTypes[]=
  2300. {
  2301. ID_RT_MENU,
  2302. ID_RT_DIALOG,
  2303. ID_RT_STRING,
  2304. ID_RT_ACCELERATORS,
  2305. ID_RT_RCDATA,
  2306. ID_RT_ERRTABLE,
  2307. ID_RT_NAMETABLE,
  2308. ID_RT_VERSION,
  2309. ID_RT_DLGINIT
  2310. };
  2311. TCHAR szTokenType[20] = TEXT("");
  2312. WORD i;
  2313. DWORD rc;
  2314. switch (wMsg) {
  2315. case WM_INITDIALOG:
  2316. CheckDlgButton(hWndDlg, IDD_READONLY, 2);
  2317. CheckDlgButton(hWndDlg, IDD_DIRTY, 2);
  2318. CheckDlgButton(hWndDlg, IDD_FINDDOWN, 1);
  2319. hCtl = GetDlgItem(hWndDlg, IDD_TYPELST);
  2320. for (i = 0; i < sizeof(rgiTokenTypes)/sizeof(int); i ++) {
  2321. LoadString( hInst,
  2322. IDS_RESOURCENAMES + rgiTokenTypes[i],
  2323. szTokenType,
  2324. TCHARSIN( sizeof( szTokenType)));
  2325. SendMessage( hCtl,
  2326. CB_ADDSTRING,
  2327. (WPARAM)0,
  2328. (LPARAM)szTokenType);
  2329. }
  2330. return TRUE;
  2331. break;
  2332. case WM_COMMAND:
  2333. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  2334. case IDOK: /* Button text: "Okay" */
  2335. GetDlgItemText(hWndDlg, IDD_TYPELST, szSearchType, 40);
  2336. GetDlgItemText(hWndDlg, IDD_FINDTOK, szSearchText, 256);
  2337. wSearchStatus = ST_TRANSLATED;
  2338. wSearchStatusMask = ST_TRANSLATED ;
  2339. switch (IsDlgButtonChecked(hWndDlg, IDD_READONLY)) {
  2340. case 1:
  2341. wSearchStatus |= ST_READONLY;
  2342. case 0:
  2343. wSearchStatusMask |= ST_READONLY;
  2344. }
  2345. switch (IsDlgButtonChecked(hWndDlg, IDD_DIRTY)) {
  2346. case 1:
  2347. wSearchStatus |= ST_DIRTY;
  2348. case 0:
  2349. wSearchStatusMask |= ST_DIRTY;
  2350. }
  2351. fSearchStarted = TRUE;
  2352. fSearchDirection = IsDlgButtonChecked(hWndDlg, IDD_FINDUP);
  2353. EndDialog( hWndDlg,
  2354. DoTokenSearchForRledit( szSearchType,
  2355. szSearchText,
  2356. wSearchStatus,
  2357. wSearchStatusMask,
  2358. fSearchDirection,
  2359. FALSE));
  2360. return TRUE;
  2361. case IDCANCEL:
  2362. /* and dismiss the dialog window returning FALSE */
  2363. EndDialog( hWndDlg, -1);
  2364. return TRUE;
  2365. }
  2366. break; /* End of WM_COMMAND */
  2367. default:
  2368. return FALSE;
  2369. }
  2370. return FALSE;
  2371. }
  2372. /**
  2373. * Function: NewDlgProc
  2374. * Procedure for the new project dialog window.
  2375. *
  2376. * Arguments:
  2377. *
  2378. * Returns: NA.
  2379. *
  2380. * Errors Codes:
  2381. * TRUE, carry out edit, and update token list box.
  2382. * FALSE, cancel edit.
  2383. *
  2384. * History:
  2385. **/
  2386. static CHAR szPrompt[80] = "";
  2387. static CHAR *szFSpec = NULL;
  2388. static CHAR *szExt = NULL;
  2389. static int iLastBox = IDD_MPJ;
  2390. INT_PTR CALLBACK NewDlgProc( HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  2391. {
  2392. static PROJDATA OldProj;
  2393. static CHAR szNewFileName[ MAXFILENAME] = "";
  2394. switch ( wMsg ) {
  2395. case WM_INITDIALOG:
  2396. {
  2397. int nSel = 0;
  2398. LPTSTR pszLangName = NULL;
  2399. // Save the old .PRJ
  2400. CopyMemory( &OldProj, &gProj, sizeof( PROJDATA));
  2401. if ( (pszLangName = GetLangName( (WORD)(PRIMARYLANGID( gMstr.wLanguageID)),
  2402. (WORD)(SUBLANGID( gMstr.wLanguageID)))) == NULL ) {
  2403. SetDlgItemText( hDlg, IDD_MSTR_LANG_NAME, TEXT("UNKNOWN"));
  2404. } else {
  2405. SetDlgItemText( hDlg, IDD_MSTR_LANG_NAME, pszLangName);
  2406. }
  2407. FillListAndSetLang( hDlg,
  2408. IDD_PROJ_LANG_NAME,
  2409. &gProj.wLanguageID,
  2410. NULL);
  2411. if ( gProj.uCodePage == CP_ACP )
  2412. gProj.uCodePage = GetACP();
  2413. else if ( gProj.uCodePage == CP_OEMCP )
  2414. gProj.uCodePage = GetOEMCP();
  2415. if ( ! IsValidCodePage( gProj.uCodePage) ) {
  2416. static TCHAR szMsg[ 256];
  2417. CHAR *pszCP[1];
  2418. pszCP[0] = UlongToPtr(gProj.uCodePage);
  2419. LoadString( hInst, IDS_NOCPXTABLE, szMsg, 256);
  2420. FormatMessage( FORMAT_MESSAGE_FROM_STRING
  2421. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  2422. szMsg,
  2423. 0,
  2424. 0,
  2425. (LPTSTR)szDHW,
  2426. DHWSIZE/sizeof(TCHAR),
  2427. (va_list *)pszCP);
  2428. MessageBox( hDlg, (LPCTSTR)szDHW, tszAppName, MB_ICONHAND|MB_OK);
  2429. }
  2430. SetDlgItemInt( hDlg, IDD_PROJ_TOK_CP, gProj.uCodePage, FALSE);
  2431. if ( fEditing ) {
  2432. SetDlgItemTextA( hDlg, IDD_MPJ, gProj.szMpj);
  2433. SetDlgItemTextA( hDlg, IDD_TOK, gProj.szTok);
  2434. SetDlgItemTextA( hDlg, IDD_BUILTRES, gProj.szBld);
  2435. SetDlgItemTextA( hDlg, IDD_GLOSS, gProj.szGlo);
  2436. } else {
  2437. // fill in suggested name for the token file
  2438. SetDlgItemTextA( hDlg, IDD_TOK, ".TOK");
  2439. SetDlgItemTextA( hDlg, IDD_BUILTRES, ".EXE");
  2440. SetDlgItemTextA( hDlg, IDD_GLOSS, ".TXT");
  2441. iLastBox = IDD_MPJ;
  2442. PostMessage( hDlg, WM_COMMAND, IDD_BROWSE, 0);
  2443. }
  2444. CheckRadioButton( hDlg,
  2445. IDC_REPLACE,
  2446. IDC_APPEND,
  2447. gfReplace ? IDC_REPLACE : IDC_APPEND);
  2448. return TRUE;
  2449. }
  2450. case WM_COMMAND:
  2451. switch ( GET_WM_COMMAND_ID( wParam, lParam) ) {
  2452. case IDD_MPJ:
  2453. case IDD_TOK:
  2454. case IDD_BUILTRES:
  2455. case IDD_GLOSS:
  2456. iLastBox = GET_WM_COMMAND_ID( wParam, lParam);
  2457. break;
  2458. case IDD_BROWSE:
  2459. {
  2460. switch ( iLastBox ) {
  2461. case IDD_MPJ:
  2462. szFSpec = szMPJFilterSpec;
  2463. szExt = "MPJ";
  2464. LoadStrIntoAnsiBuf( hInst,
  2465. IDS_MPJ,
  2466. szPrompt,
  2467. sizeof( szPrompt));
  2468. break;
  2469. case IDD_BUILTRES:
  2470. szFSpec = szExeResFilterSpec;
  2471. szExt = "EXE";
  2472. LoadStrIntoAnsiBuf( hInst,
  2473. IDS_RES_BLD,
  2474. szPrompt,
  2475. sizeof( szPrompt));
  2476. break;
  2477. case IDD_TOK:
  2478. szFSpec = szTokFilterSpec;
  2479. szExt = "TOK";
  2480. LoadStrIntoAnsiBuf( hInst,
  2481. IDS_TOK,
  2482. szPrompt,
  2483. sizeof( szPrompt));
  2484. break;
  2485. case IDD_GLOSS:
  2486. szFSpec = szGlossFilterSpec;
  2487. szExt ="TXT";
  2488. LoadStrIntoAnsiBuf( hInst,
  2489. IDS_GLOSS,
  2490. szPrompt,
  2491. sizeof( szPrompt));
  2492. break;
  2493. } // END switch ( iLastBox )
  2494. if ( GetFileNameFromBrowse( hDlg,
  2495. szNewFileName,
  2496. MAXFILENAME,
  2497. szPrompt,
  2498. szFSpec,
  2499. szExt) ) {
  2500. SetDlgItemTextA( hDlg, iLastBox, szNewFileName);
  2501. SetNames( hDlg, iLastBox, szNewFileName);
  2502. }
  2503. break;
  2504. } // END case IDD_BROWSE:
  2505. case IDC_REPLACE:
  2506. case IDC_APPEND:
  2507. CheckRadioButton( hDlg,
  2508. IDC_REPLACE,
  2509. IDC_APPEND,
  2510. GET_WM_COMMAND_ID( wParam, lParam));
  2511. break;
  2512. case IDD_PROJ_LANG_NAME:
  2513. if ( GET_WM_COMMAND_CMD( wParam, lParam) == CBN_SELENDOK ) {
  2514. //... Get the selected language name
  2515. //... then set the appropriate lang id vals
  2516. INT_PTR nSel = SendDlgItemMessage( hDlg,
  2517. IDD_PROJ_LANG_NAME,
  2518. CB_GETCURSEL,
  2519. (WPARAM)0,
  2520. (LPARAM)0);
  2521. if ( nSel != CB_ERR
  2522. && SendDlgItemMessage( hDlg,
  2523. IDD_PROJ_LANG_NAME,
  2524. CB_GETLBTEXT,
  2525. (WPARAM)nSel,
  2526. (LPARAM)(LPTSTR)szDHW) != CB_ERR ) {
  2527. WORD wPri = 0;
  2528. WORD wSub = 0;
  2529. if ( GetLangIDs( (LPTSTR)szDHW, &wPri, &wSub) ) {
  2530. gProj.wLanguageID = MAKELANGID( wPri, wSub);
  2531. }
  2532. }
  2533. }
  2534. break;
  2535. case IDOK:
  2536. {
  2537. PROJDATA stProject =
  2538. { "", "", "", "", "", "",
  2539. CP_ACP,
  2540. MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US),
  2541. FALSE,
  2542. FALSE
  2543. };
  2544. BOOL fTranslated = FALSE;
  2545. UINT uCP = GetDlgItemInt( hDlg,
  2546. IDD_TOK_CP,
  2547. &fTranslated,
  2548. FALSE);
  2549. if ( uCP == CP_ACP )
  2550. uCP = GetACP();
  2551. else if ( uCP == CP_OEMCP )
  2552. uCP = GetOEMCP();
  2553. if ( IsValidCodePage( uCP) ) {
  2554. gProj.uCodePage = uCP;
  2555. } else {
  2556. static TCHAR szMsg[ 256];
  2557. CHAR *pszCP[1];
  2558. pszCP[0] = UlongToPtr(uCP);
  2559. LoadString( hInst, IDS_NOCPXTABLE, szMsg, 256);
  2560. FormatMessage( FORMAT_MESSAGE_FROM_STRING
  2561. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  2562. szMsg,
  2563. 0,
  2564. 0,
  2565. (LPTSTR)szDHW,
  2566. DHWSIZE/sizeof(TCHAR),
  2567. (va_list *)pszCP);
  2568. MessageBox( hDlg, (LPCTSTR)szDHW, tszAppName, MB_ICONHAND|MB_OK);
  2569. SetDlgItemInt( hDlg, IDD_TOK_CP, gProj.uCodePage, FALSE);
  2570. return ( TRUE);
  2571. }
  2572. GetDlgItemTextA( hDlg, IDD_MPJ, stProject.szMpj, MAXFILENAME);
  2573. GetDlgItemTextA( hDlg, IDD_BUILTRES, stProject.szBld, MAXFILENAME);
  2574. GetDlgItemTextA( hDlg, IDD_TOK, stProject.szTok, MAXFILENAME);
  2575. GetDlgItemTextA( hDlg, IDD_GLOSS, stProject.szGlo, MAXFILENAME);
  2576. //Why don't allow the partial path?
  2577. if ( stProject.szMpj[0]
  2578. && stProject.szBld[0]
  2579. && stProject.szTok[0] ) {
  2580. _fullpath( gProj.szMpj,
  2581. stProject.szMpj,
  2582. sizeof( gProj.szMpj));
  2583. _fullpath( gProj.szBld,
  2584. stProject.szBld,
  2585. sizeof( gProj.szBld));
  2586. _fullpath( gProj.szTok,
  2587. stProject.szTok,
  2588. sizeof( gProj.szTok));
  2589. if ( stProject.szGlo[0] != '\0' ) {
  2590. _fullpath( gProj.szGlo,
  2591. stProject.szGlo,
  2592. sizeof( gProj.szGlo));
  2593. }
  2594. gfReplace = IsDlgButtonChecked( hDlg, IDC_REPLACE);
  2595. EndDialog( hDlg, TRUE);
  2596. return ( TRUE);
  2597. } else {
  2598. break;
  2599. }
  2600. } // END case ID_OK:
  2601. case IDCANCEL:
  2602. CopyMemory( &gProj, &OldProj, sizeof( PROJDATA));
  2603. EndDialog( hDlg, FALSE);
  2604. return ( TRUE);
  2605. } // END switch ( GET_WM_COMMAND_ID( wParam, lParam) )
  2606. break;
  2607. } // END switch ( wMsg )
  2608. return ( FALSE);
  2609. }
  2610. /**
  2611. * Function: ViewDlgProc
  2612. * Procedure for the View project dialog window.
  2613. *
  2614. * Arguments:
  2615. *
  2616. * Returns: NA.
  2617. *
  2618. * Errors Codes:
  2619. * TRUE, carry out edit, and update token list box.
  2620. * FALSE, cancel edit.
  2621. *
  2622. * History:
  2623. **/
  2624. INT_PTR CALLBACK ViewDlgProc( HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  2625. {
  2626. static int iLastBox = IDD_MPJ;
  2627. switch (wMsg) {
  2628. case WM_INITDIALOG:
  2629. {
  2630. LPTSTR pszLangName = NULL;
  2631. if ( (pszLangName = GetLangName( (WORD)(PRIMARYLANGID( gMstr.wLanguageID)),
  2632. (WORD)(SUBLANGID( gMstr.wLanguageID)))) == NULL ) {
  2633. sprintf( szDHW, "Unknown LANGID %#06hx", gMstr.wLanguageID);
  2634. SetDlgItemTextA( hDlg, IDD_MSTR_LANG_NAME, szDHW);
  2635. } else {
  2636. SetDlgItemText( hDlg, IDD_MSTR_LANG_NAME, pszLangName);
  2637. }
  2638. if ( (pszLangName = GetLangName( (WORD)(PRIMARYLANGID( gProj.wLanguageID)),
  2639. (WORD)(SUBLANGID( gProj.wLanguageID)))) == NULL ) {
  2640. sprintf( szDHW, "Unknown LANGID %#06hx", gProj.wLanguageID);
  2641. SetDlgItemTextA( hDlg, IDD_PROJ_LANG_NAME, szDHW);
  2642. } else {
  2643. SetDlgItemText( hDlg, IDD_PROJ_LANG_NAME, pszLangName);
  2644. }
  2645. SetDlgItemTextA( hDlg, IDD_VIEW_SOURCERES, gMstr.szSrc);
  2646. SetDlgItemTextA( hDlg, IDD_VIEW_MTK, gMstr.szMtk);
  2647. SetDlgItemTextA( hDlg, IDD_VIEW_RDFS, gMstr.szRdfs);
  2648. SetDlgItemTextA( hDlg, IDD_VIEW_MPJ, gProj.szMpj);
  2649. SetDlgItemTextA( hDlg, IDD_VIEW_TOK, gProj.szTok);
  2650. SetDlgItemTextA( hDlg, IDD_VIEW_TARGETRES, gProj.szBld);
  2651. SetDlgItemTextA( hDlg, IDD_VIEW_GLOSSTRANS, gProj.szGlo);
  2652. if ( gProj.uCodePage == CP_ACP )
  2653. gProj.uCodePage = GetACP();
  2654. else if ( gProj.uCodePage == CP_OEMCP )
  2655. gProj.uCodePage = GetOEMCP();
  2656. SetDlgItemInt( hDlg, IDD_PROJ_TOK_CP, gProj.uCodePage, FALSE);
  2657. LoadString( hInst,
  2658. gfReplace ? IDS_WILLREPLACE : IDS_WILLAPPEND,
  2659. (LPTSTR)szDHW,
  2660. TCHARSIN( DHWSIZE));
  2661. SetDlgItemText( hDlg, IDC_APPENDREPLACE, (LPTSTR)szDHW);
  2662. return TRUE;
  2663. }
  2664. case WM_COMMAND:
  2665. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  2666. case IDOK:
  2667. EndDialog(hDlg, TRUE);
  2668. return TRUE;
  2669. }
  2670. }
  2671. return FALSE;
  2672. }
  2673. /**
  2674. * Function:
  2675. *
  2676. * Arguments:
  2677. *
  2678. * Returns:
  2679. *
  2680. * Errors Codes:
  2681. *
  2682. * History:
  2683. **/
  2684. static void DrawLBItem(LPDRAWITEMSTRUCT lpdis)
  2685. {
  2686. LPRECT lprc = (LPRECT) &(lpdis->rcItem);
  2687. DWORD rgbOldText = 0;
  2688. DWORD rgbOldBack = 0;
  2689. HBRUSH hBrush;
  2690. static DWORD rgbHighlightText;
  2691. static DWORD rgbHighlightBack;
  2692. static HBRUSH hBrushHilite = NULL;
  2693. static HBRUSH hBrushNormal = NULL;
  2694. static DWORD rgbDirtyText;
  2695. static DWORD rgbBackColor;
  2696. static DWORD rgbCleanText;
  2697. static DWORD rgbReadOnlyText;
  2698. TCHAR *szToken;
  2699. TOKEN tok;
  2700. LPTSTR lpstrToken;
  2701. LPTOKDATA lpTokData;
  2702. if (lpdis->itemAction & ODA_FOCUS) {
  2703. DrawFocusRect(lpdis->hDC, (CONST RECT *)lprc);
  2704. } else {
  2705. HANDLE hMem = (HANDLE)SendMessage( lpdis->hwndItem,
  2706. LB_GETITEMDATA,
  2707. (WPARAM)lpdis->itemID,
  2708. (LPARAM)0);
  2709. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  2710. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  2711. szToken = (TCHAR *)FALLOC( MEMSIZE( lstrlen( lpstrToken) + 1));
  2712. lstrcpy( szToken, lpstrToken);
  2713. GlobalUnlock( lpTokData->hToken );
  2714. GlobalUnlock( hMem);
  2715. ParseBufToTok(szToken, &tok);
  2716. RLFREE( szToken);
  2717. if (lpdis->itemState & ODS_SELECTED) {
  2718. if (!hBrushHilite) {
  2719. rgbHighlightText = GetSysColor(COLOR_HIGHLIGHTTEXT);
  2720. rgbHighlightBack = GetSysColor(COLOR_HIGHLIGHT);
  2721. hBrushHilite = CreateSolidBrush(rgbHighlightBack);
  2722. }
  2723. GenStatusLine(&tok);
  2724. rgbOldText = SetTextColor(lpdis->hDC, rgbHighlightText);
  2725. rgbOldBack = SetBkColor(lpdis->hDC, rgbHighlightBack);
  2726. hBrush = hBrushHilite;
  2727. } else {
  2728. if (!hBrushNormal) {
  2729. rgbDirtyText = RGB(255, 0, 0);
  2730. rgbBackColor = RGB(192, 192, 192);
  2731. rgbCleanText = RGB(0, 0, 0);
  2732. rgbReadOnlyText = RGB(127, 127, 127);
  2733. hBrushNormal = CreateSolidBrush(rgbBackColor);
  2734. }
  2735. if (tok.wReserved & ST_READONLY) {
  2736. rgbOldText = SetTextColor(lpdis->hDC, rgbReadOnlyText);
  2737. } else {
  2738. if (tok.wReserved & ST_DIRTY) {
  2739. rgbOldText = SetTextColor(lpdis->hDC, rgbDirtyText);
  2740. } else {
  2741. rgbOldText = SetTextColor(lpdis->hDC, rgbCleanText);
  2742. }
  2743. }
  2744. rgbOldBack = SetBkColor(lpdis->hDC, rgbBackColor);
  2745. hBrush = hBrushNormal;
  2746. }
  2747. FillRect(lpdis->hDC, (CONST RECT *)lprc, hBrush);
  2748. DrawText(lpdis->hDC,
  2749. tok.szText,
  2750. STRINGSIZE(lstrlen(tok.szText)),
  2751. lprc,
  2752. DT_LEFT|DT_NOPREFIX);
  2753. RLFREE( tok.szText);
  2754. if (rgbOldText) {
  2755. SetTextColor(lpdis->hDC, rgbOldText);
  2756. }
  2757. if (rgbOldBack) {
  2758. SetBkColor(lpdis->hDC, rgbOldBack);
  2759. }
  2760. if (lpdis->itemState & ODS_FOCUS) {
  2761. DrawFocusRect(lpdis->hDC, (CONST RECT *)lprc);
  2762. }
  2763. }
  2764. }
  2765. /**********************************************************************
  2766. *FUNCTION: SaveTokList(HWND, FILE *fpTokFile) *
  2767. * *
  2768. *PURPOSE: Save current Token List *
  2769. * *
  2770. *COMMENTS: *
  2771. * *
  2772. *This saves the current contents of the Token List, and changes *
  2773. *fTokChanges to indicate that the list has not been changed since the *
  2774. *last save. *
  2775. **********************************************************************/
  2776. static BOOL SaveTokList(HWND hWnd, FILE *fpTokFile)
  2777. {
  2778. HCURSOR hSaveCursor;
  2779. BOOL bSuccess = TRUE;
  2780. int IOStatus;
  2781. UINT cTokens;
  2782. UINT cCurrentTok = 0;
  2783. CHAR *szTokBuf = NULL;
  2784. LPTSTR lpstrToken = NULL;
  2785. HGLOBAL hMem = NULL;
  2786. LPTOKDATA lpTokData;
  2787. // Set the cursor to an hourglass during the file transfer
  2788. hSaveCursor = SetCursor(hHourGlass);
  2789. // Find number of tokens in the list
  2790. cTokens = (UINT)SendMessage( hListWnd, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
  2791. if ( cTokens != LB_ERR ) {
  2792. for (cCurrentTok = 0; bSuccess && (cCurrentTok < cTokens); cCurrentTok++) {
  2793. int nLen1 = 0;
  2794. int nLen2 = 0;
  2795. // Get each token from list
  2796. hMem = (HGLOBAL)SendMessage( hListWnd,
  2797. LB_GETITEMDATA,
  2798. (WPARAM)cCurrentTok,
  2799. (LPARAM)0);
  2800. if ( ! (lpTokData = (LPTOKDATA)GlobalLock(hMem)) ) {
  2801. continue;
  2802. }
  2803. if ( (lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken)) ) {
  2804. szTokBuf = (CHAR *)FALLOC( (nLen2 = MEMSIZE( (nLen1 = lstrlen(lpstrToken)+1))));
  2805. #ifdef UNICODE
  2806. _WCSTOMBS( szTokBuf, lpstrToken, nLen2, nLen1);
  2807. #else
  2808. lstrcpy(szTokBuf, lpstrToken);
  2809. #endif
  2810. GlobalUnlock( lpTokData->hToken );
  2811. GlobalUnlock( hMem);
  2812. IOStatus = fprintf(fpTokFile, "%s\n", szTokBuf);
  2813. if ( IOStatus != (int) strlen(szTokBuf) + 1 ) {
  2814. TCHAR szTmpBuf[256];
  2815. LoadString( hInst,
  2816. IDS_FILESAVEERR,
  2817. szTmpBuf,
  2818. TCHARSIN( sizeof(szTmpBuf)));
  2819. MessageBox( hWnd,
  2820. szTmpBuf,
  2821. tszAppName,
  2822. MB_OK | MB_ICONHAND);
  2823. bSuccess = FALSE;
  2824. }
  2825. RLFREE( szTokBuf);
  2826. }
  2827. }
  2828. }
  2829. // restore cursor
  2830. SetCursor(hSaveCursor);
  2831. return (bSuccess);
  2832. }
  2833. /**
  2834. * Function: CleanDeltaList
  2835. * frees the pTokenDeltaInfo list
  2836. */
  2837. static void CleanDeltaList(void)
  2838. {
  2839. TOKENDELTAINFO FAR *pTokNode;
  2840. while (pTokNode = pTokenDeltaInfo) {
  2841. pTokenDeltaInfo = pTokNode->pNextTokenDelta;
  2842. RLFREE( pTokNode->DeltaToken.szText);
  2843. RLFREE( pTokNode);
  2844. }
  2845. }
  2846. /*
  2847. * About -- message processor for about box
  2848. *
  2849. */
  2850. //#ifdef RLWIN32
  2851. //
  2852. //BOOL CALLBACK About(
  2853. //
  2854. //HWND hDlg,
  2855. //UINT message,
  2856. //WPARAM wParam,
  2857. //LPARAM lParam)
  2858. //
  2859. //#else
  2860. //
  2861. INT_PTR CALLBACK About(
  2862. HWND hDlg,
  2863. UINT message,
  2864. WPARAM wParam,
  2865. LPARAM lParam)
  2866. //
  2867. //#endif
  2868. {
  2869. switch ( message ) {
  2870. case WM_INITDIALOG:
  2871. {
  2872. WORD wRC = SUCCESS;
  2873. CHAR szModName[ MAXFILENAME];
  2874. GetModuleFileNameA( hInst, szModName, sizeof( szModName));
  2875. if ( (wRC = GetCopyright( szModName,
  2876. szDHW,
  2877. DHWSIZE)) == SUCCESS ) {
  2878. SetDlgItemTextA( hDlg, IDC_COPYRIGHT, szDHW);
  2879. } else {
  2880. ShowErr( wRC, NULL, NULL);
  2881. }
  2882. }
  2883. break;
  2884. case WM_COMMAND:
  2885. if ((wParam == IDOK) || (wParam == IDCANCEL)) {
  2886. EndDialog(hDlg, TRUE);
  2887. }
  2888. break;
  2889. default:
  2890. return ( FALSE);
  2891. }
  2892. return ( TRUE);
  2893. }
  2894. //...................................................................
  2895. int RLMessageBoxA(
  2896. LPCSTR pszMsgText)
  2897. {
  2898. return ( MessageBoxA( NULL, pszMsgText, szAppName, MB_ICONHAND|MB_OK));
  2899. }
  2900. //...................................................................
  2901. void Usage()
  2902. {
  2903. return;
  2904. }
  2905. //...................................................................
  2906. void DoExit( int nErrCode)
  2907. {
  2908. ExitProcess( (UINT)nErrCode);
  2909. }
  2910. //...................................................................
  2911. static void SetNames( HWND hDlg, int iLastBox, LPSTR szNewFile)
  2912. {
  2913. static CHAR szDrive[ _MAX_DRIVE] = "";
  2914. static CHAR szDir[ _MAX_DIR] = "";
  2915. static CHAR szName[ _MAX_FNAME] = "";
  2916. static CHAR szExt[ _MAX_EXT] = "";
  2917. static CHAR szOldFileName[ MAXFILENAME];
  2918. if ( iLastBox == IDD_MPJ ) {
  2919. lstrcpyA( gProj.szMpj, szNewFile);
  2920. if ( ! fEditing && GetMasterProjectData( gProj.szMpj,
  2921. NULL,
  2922. NULL,
  2923. FALSE) == SUCCESS ) {
  2924. // Suggest a name for the target file
  2925. GetDlgItemTextA( hDlg, IDD_BUILTRES, szOldFileName, MAXFILENAME);
  2926. if ( szOldFileName[0] == '\0' || szOldFileName[0] == '.' ) {
  2927. _splitpath( gProj.szPRJ, szDrive, szDir, szName, szExt);
  2928. sprintf( gProj.szBld, "%s%s", szDrive, szDir);
  2929. _splitpath( gMstr.szSrc, szDrive, szDir, szName, szExt);
  2930. sprintf( &gProj.szBld[ lstrlenA( gProj.szBld)],
  2931. "%s%s",
  2932. szName,
  2933. szExt);
  2934. SetDlgItemTextA( hDlg, IDD_BUILTRES, gProj.szBld);
  2935. }
  2936. } else {
  2937. return;
  2938. }
  2939. }
  2940. if ( iLastBox == IDD_BUILTRES ) {
  2941. lstrcpyA( gProj.szBld, szNewFile);
  2942. }
  2943. if ( ! fEditing && (iLastBox == IDD_MPJ || iLastBox == IDD_BUILTRES) ) {
  2944. // Suggest a name for the project token file
  2945. GetDlgItemTextA( hDlg, IDD_TOK, szOldFileName, MAXFILENAME);
  2946. if ( szOldFileName[0] == '\0' || szOldFileName[0] == '.' ) {
  2947. _splitpath( gProj.szPRJ, szDrive, szDir, szName, szExt);
  2948. sprintf( gProj.szTok, "%s%s%s.%s", szDrive, szDir, szName, "TOK");
  2949. SetDlgItemTextA( hDlg, IDD_TOK, gProj.szTok);
  2950. }
  2951. // Suggest a name for the glossary file
  2952. GetDlgItemTextA( hDlg, IDD_GLOSS, szOldFileName, MAXFILENAME);
  2953. if ( szOldFileName[0] == '\0' || szOldFileName[0] == '.' ) {
  2954. _splitpath( gProj.szPRJ, szDrive, szDir, szName, szExt);
  2955. sprintf( gProj.szGlo, "%s%s%s.%s", szDrive, szDir, szName, "TXT");
  2956. SetDlgItemTextA( hDlg, IDD_GLOSS, gProj.szGlo);
  2957. }
  2958. }
  2959. if ( iLastBox == IDD_TOK ) {
  2960. lstrcpyA( gProj.szTok, szNewFile);
  2961. }
  2962. if ( iLastBox == IDD_GLOSS ) {
  2963. lstrcpyA( gProj.szGlo, szNewFile);
  2964. }
  2965. }