Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3544 lines
130 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. hTokEditDlgWnd = CreateDialog(hInst,
  1070. TEXT("RLEdit"),
  1071. hWnd,
  1072. TokEditDlgProc);
  1073. #endif
  1074. }
  1075. // Get token info from listbox, and place in token struct
  1076. hMem = (HGLOBAL)SendMessage( hListWnd,
  1077. LB_GETITEMDATA,
  1078. (WPARAM)wIndex,
  1079. (LPARAM)0);
  1080. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  1081. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  1082. lMtkPointer = lpTokData->lMtkPointer;
  1083. szBuffer = (LPTSTR)FALLOC( MEMSIZE( lstrlen( lpstrToken) + 1));
  1084. lstrcpy( szBuffer, lpstrToken);
  1085. GlobalUnlock( lpTokData->hToken );
  1086. GlobalUnlock( hMem);
  1087. ParseBufToTok(szBuffer, &tok);
  1088. RLFREE( szBuffer);
  1089. // Now get the token name
  1090. // Its either a string, or ordinal number
  1091. if (tok.szName[0]) {
  1092. lstrcpy( szName, tok.szName);
  1093. } else {
  1094. #ifdef UNICODE
  1095. _itoa(tok.wName, szTmpBuf, 10);
  1096. _MBSTOWCS( szName,
  1097. szTmpBuf,
  1098. WCHARSIN( sizeof( szName)),
  1099. ACHARSIN( strlen(szTmpBuf) + 1));
  1100. #else
  1101. _itoa(tok.wName, szName, 10);
  1102. #endif
  1103. }
  1104. // Now get the token id
  1105. #ifdef UNICODE
  1106. _itoa(tok.wID, szTmpBuf, 10);
  1107. _MBSTOWCS( szID,
  1108. szTmpBuf,
  1109. WCHARSIN( sizeof( szID)),
  1110. ACHARSIN( strlen(szTmpBuf) + 1));
  1111. #else
  1112. _itoa(tok.wID, szID, 10);
  1113. #endif
  1114. if ( tok.wType <= 16 || tok.wType == ID_RT_DLGINIT ) {
  1115. LoadString(hInst,
  1116. IDS_RESOURCENAMES+tok.wType,
  1117. szResIDStr,
  1118. TCHARSIN( sizeof( szResIDStr)));
  1119. } else {
  1120. #ifdef UNICODE
  1121. _itoa(tok.wType, szTmpBuf, 10);
  1122. _MBSTOWCS(szResIDStr,
  1123. szTmpBuf,
  1124. WCHARSIN( sizeof( szResIDStr)),
  1125. ACHARSIN( strlen(szTmpBuf) + 1));
  1126. #else
  1127. _itoa(tok.wType, szResIDStr, 10);
  1128. #endif
  1129. }
  1130. // Now insert token info in TokEdit Dialog Box
  1131. SetDlgItemText(hTokEditDlgWnd,
  1132. IDD_TOKTYPE,
  1133. (LPTSTR) szResIDStr);
  1134. SetDlgItemText(hTokEditDlgWnd,
  1135. IDD_TOKNAME,
  1136. (LPTSTR) szName);
  1137. SetDlgItemText(hTokEditDlgWnd,
  1138. IDD_TOKID,
  1139. (LPTSTR) szID);
  1140. SetDlgItemText(hTokEditDlgWnd,
  1141. IDD_TOKCURTRANS,
  1142. (LPTSTR) tok.szText);
  1143. SetDlgItemText(hTokEditDlgWnd,
  1144. IDD_TOKPREVTRANS,
  1145. (LPTSTR) tok.szText);
  1146. CheckDlgButton(hTokEditDlgWnd, IDD_DIRTY, 0);
  1147. if (tok.wReserved & ST_READONLY) {
  1148. CheckDlgButton(hTokEditDlgWnd, IDD_READONLY, 1);
  1149. EnableWindow(GetDlgItem(hTokEditDlgWnd,
  1150. IDD_TOKCURTRANS),
  1151. FALSE);
  1152. SetFocus(GetDlgItem(hTokEditDlgWnd, IDCANCEL));
  1153. } else {
  1154. CheckDlgButton(hTokEditDlgWnd, IDD_READONLY, 0);
  1155. EnableWindow(GetDlgItem(hTokEditDlgWnd,
  1156. IDD_TOKCURTRANS),
  1157. TRUE);
  1158. }
  1159. // we did not find anything in the delta info,
  1160. // so we need to read it from the master token.
  1161. GetTextFromMTK(hTokEditDlgWnd, &tok, lMtkPointer );
  1162. RLFREE( tok.szText);
  1163. // Disable OK button.
  1164. // User must enter text before it is enabled
  1165. hCtl = GetDlgItem(hTokEditDlgWnd, IDOK);
  1166. SendMessage( hMainWnd,
  1167. WM_TRANSLATE,
  1168. (LPARAM)0,
  1169. (LPARAM)0);
  1170. EnableWindow(hCtl, FALSE);
  1171. SetActiveWindow(hTokEditDlgWnd);
  1172. wIndex = (UINT)SendMessage( hListWnd,
  1173. LB_GETCURSEL,
  1174. (WPARAM)0,
  1175. (LPARAM)0);
  1176. return TRUE;
  1177. }
  1178. // let these messages fall through,
  1179. default:
  1180. break;
  1181. }
  1182. }
  1183. default:
  1184. return FALSE;
  1185. }
  1186. break; // WM_COMMAND Case
  1187. } // Main List Box Switch
  1188. return FALSE;
  1189. }
  1190. /**
  1191. * Function: DoMenuCommand.
  1192. * Processes the Menu Command messages.
  1193. *
  1194. * Errors Codes:
  1195. * TRUE. Message processed.
  1196. * FALSE. Message not processed.
  1197. *
  1198. * History:
  1199. * 01/92. Implemented. TerryRu.
  1200. *
  1201. **/
  1202. INT_PTR DoMenuCommand(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  1203. {
  1204. static BOOL fListBox = FALSE;
  1205. TCHAR sz[256]=TEXT("");
  1206. #ifndef RLWIN32
  1207. WNDPROC lpNewDlg, lpViewDlg;
  1208. #endif
  1209. int rc;
  1210. LPTOKDATA lpTokData;
  1211. long lMtkPointer;
  1212. // Commands entered from the application menu, or child windows.
  1213. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  1214. case IDM_P_NEW:
  1215. fEditing = FALSE; //... We are *not* editing an existing .PRJ
  1216. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1217. CHAR szFile[MAXFILENAME] = "";
  1218. if ( GetFileNameFromBrowse( hWnd,
  1219. gProj.szPRJ,
  1220. MAXFILENAME,
  1221. szSaveDlgTitle,
  1222. szFilterSpec,
  1223. "PRJ")) {
  1224. strcpy( szFile, gProj.szPRJ);
  1225. } else {
  1226. break; // user cancelled
  1227. }
  1228. #ifdef RLWIN32
  1229. if ( DialogBox( hInst, TEXT("PROJECT"), hWnd, NewDlgProc) == IDOK )
  1230. #else
  1231. //lpNewDlg = MakeProcInstance(NewDlgProc, hInst);
  1232. //
  1233. //if ( DialogBox( hInst, TEXT("PROJECT"), hWnd, lpNewDlg) == IDOK )
  1234. if ( DialogBox( hInst, TEXT("PROJECT"), hWnd, NewDlgProc) == IDOK )
  1235. #endif
  1236. {
  1237. sprintf( szDHW, "%s - %s", szAppName, szFile);
  1238. SetWindowTextA( hWnd, szDHW);
  1239. gbNewProject = TRUE;
  1240. gProj.szTokDate[0] = 0;
  1241. strcpy( gProj.szPRJ, szFile);
  1242. fPrjChanges = TRUE;
  1243. SendMessage( hWnd, WM_READMPJDATA, (WPARAM)0, (LPARAM)0);
  1244. }
  1245. gbNewProject = FALSE;
  1246. #ifndef RLWIN32
  1247. //FreeProcInstance(lpNewDlg);
  1248. #endif
  1249. break;
  1250. }
  1251. case IDM_P_EDIT:
  1252. fEditing = TRUE; //... We *are* editing an existing .PRJ
  1253. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1254. CHAR szOldMpj[ MAXFILENAME];
  1255. // Save old Master Project name
  1256. lstrcpyA( szOldMpj, gProj.szMpj);
  1257. #ifdef RLWIN32
  1258. if ( DialogBox( hInst, TEXT("PROJECT"), hWnd, NewDlgProc) == IDOK )
  1259. #else
  1260. //lpNewDlg = MakeProcInstance(NewDlgProc, hInst);
  1261. //
  1262. //if ( DialogBox( hInst, TEXT("PROJECT"), hWnd, lpNewDlg) == IDOK )
  1263. if ( DialogBox( hInst, TEXT("PROJECT"), hWnd, NewDlgProc) == IDOK )
  1264. #endif
  1265. {
  1266. fPrjChanges = TRUE;
  1267. // Still same Master Project referenced?
  1268. if ( lstrcmpiA( szOldMpj, gProj.szMpj) != 0 ) {
  1269. gbNewProject = TRUE; // No
  1270. gProj.szTokDate[0] = 0;
  1271. SendMessage( hWnd, WM_READMPJDATA, (WPARAM)0, (LPARAM)0);
  1272. }
  1273. }
  1274. gbNewProject = FALSE;
  1275. #ifndef RLWIN32
  1276. //FreeProcInstance(lpNewDlg);
  1277. #endif
  1278. break;
  1279. }
  1280. case IDM_P_OPEN:
  1281. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1282. szTempFileName[0] = 0;
  1283. if ( GetFileNameFromBrowse( hWnd,
  1284. szTempFileName,
  1285. MAXFILENAME,
  1286. szOpenDlgTitle,
  1287. szFilterSpec,
  1288. "PRJ") ) {
  1289. if ( GetProjectData( szTempFileName,
  1290. NULL,
  1291. NULL,
  1292. FALSE,
  1293. FALSE) == SUCCESS ) {
  1294. SendMessage( hWnd, WM_READMPJDATA, (WPARAM)0, (LPARAM)0);
  1295. sprintf( szDHW, "%s - %s", szAppName, szTempFileName);
  1296. SetWindowTextA( hMainWnd, szDHW);
  1297. strcpy( gProj.szPRJ, szTempFileName);
  1298. SendMessage( hMainWnd, WM_LOADTOKENS, (WPARAM)0, (LPARAM)0);
  1299. }
  1300. }
  1301. }
  1302. break;
  1303. case IDM_P_VIEW:
  1304. #ifdef RLWIN32
  1305. DialogBox(hInst, TEXT("VIEWPROJECT"), hWnd, ViewDlgProc);
  1306. #else
  1307. //lpViewDlg = (WNDPROC) MakeProcInstance((WNDPROC)ViewDlgProc, hInst);
  1308. //DialogBox(hInst, TEXT("VIEWPROJECT"), hWnd, lpViewDlg);
  1309. DialogBox(hInst, TEXT("VIEWPROJECT"), hWnd, ViewDlgProc);
  1310. #endif
  1311. break;
  1312. case IDM_P_CLOSE:
  1313. {
  1314. HMENU hMenu;
  1315. hMenu=GetMenu(hWnd);
  1316. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1317. int i;
  1318. // Remove file name from window title
  1319. SetWindowTextA(hMainWnd, szAppName);
  1320. // Hide token list since it's going to be empty
  1321. ShowWindow(hListWnd, SW_HIDE);
  1322. // Remove the current token list
  1323. SendMessage( hListWnd, LB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
  1324. CleanDeltaList();
  1325. // Force Repaint of status Window
  1326. InvalidateRect(hStatusWnd, NULL, TRUE);
  1327. EnableMenuItem(hMenu, IDM_P_CLOSE, MF_GRAYED|MF_BYCOMMAND);
  1328. EnableMenuItem(hMenu, IDM_P_VIEW, MF_GRAYED|MF_BYCOMMAND);
  1329. EnableMenuItem(hMenu, IDM_P_EDIT, MF_GRAYED|MF_BYCOMMAND);
  1330. EnableMenuItem(hMenu, IDM_P_SAVE, MF_GRAYED|MF_BYCOMMAND);
  1331. EnableMenuItem(hMenu, IDM_E_FIND, MF_GRAYED|MF_BYCOMMAND);
  1332. EnableMenuItem(hMenu, IDM_E_FINDUP, MF_GRAYED|MF_BYCOMMAND);
  1333. EnableMenuItem(hMenu, IDM_E_FINDDOWN, MF_GRAYED|MF_BYCOMMAND);
  1334. EnableMenuItem(hMenu, IDM_E_REVIEW, MF_GRAYED|MF_BYCOMMAND);
  1335. EnableMenuItem(hMenu, IDM_E_ALLREVIEW, MF_GRAYED|MF_BYCOMMAND);
  1336. EnableMenuItem(hMenu, IDM_E_COPY, MF_GRAYED|MF_BYCOMMAND);
  1337. EnableMenuItem(hMenu, IDM_E_COPYTOKEN, MF_GRAYED|MF_BYCOMMAND);
  1338. EnableMenuItem(hMenu, IDM_E_PASTE, MF_GRAYED|MF_BYCOMMAND);
  1339. EnableMenuItem(hMenu, IDM_O_GENERATE, MF_GRAYED|MF_BYCOMMAND);
  1340. for (i = IDM_FIRST_EDIT; i <= IDM_LAST_EDIT;i++) {
  1341. EnableMenuItem(hMenu, i, MF_GRAYED|MF_BYCOMMAND);
  1342. }
  1343. }
  1344. break;
  1345. }
  1346. case IDM_P_SAVE:
  1347. if (fTokChanges || fPrjChanges) {
  1348. CHAR szPrjName[MAXFILENAME];
  1349. strcpy(szPrjName, gProj.szPRJ);
  1350. if ( SendMessage(hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1351. GetProjectData( szPrjName, NULL, NULL, FALSE, FALSE);
  1352. }
  1353. } else {
  1354. LoadString( hInst,
  1355. IDS_NOCHANGESYET,
  1356. sz,
  1357. TCHARSIN( sizeof( sz)));
  1358. MessageBox( hWnd,
  1359. sz,
  1360. tszAppName,
  1361. MB_ICONHAND | MB_OK);
  1362. }
  1363. break;
  1364. case IDM_P_EXIT:
  1365. SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0);
  1366. PostMessage( hMainWnd, WM_CLOSE, (WPARAM)0, (LPARAM)0);
  1367. break;
  1368. case IDM_E_COPYTOKEN:
  1369. {
  1370. HANDLE hStringMem;
  1371. LPTSTR lpString;
  1372. int nIndex = 0;
  1373. int nLength = 0;
  1374. LPTSTR lpstrToken;
  1375. // Is anything selected in the listbox
  1376. if ( (nIndex = (int)SendMessage( hListWnd,
  1377. LB_GETCURSEL,
  1378. (WPARAM)0,
  1379. (LPARAM)0)) != LB_ERR ) {
  1380. HGLOBAL hMem = (HGLOBAL)SendMessage( hListWnd,
  1381. LB_GETITEMDATA,
  1382. (WPARAM)nIndex,
  1383. (LPARAM)0);
  1384. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  1385. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  1386. nLength = lstrlen(lpstrToken);
  1387. // Allocate memory for the string
  1388. if ( (hStringMem = GlobalAlloc(GHND,
  1389. (DWORD) MEMSIZE(nLength + 1))) != NULL ) {
  1390. if ( (lpString = (LPTSTR)GlobalLock(hStringMem)) != NULL ) {
  1391. // Get the selected text
  1392. lstrcpy( lpString, lpstrToken);
  1393. GlobalUnlock( lpTokData->hToken );
  1394. GlobalUnlock( hMem);
  1395. // Unlock the block
  1396. GlobalUnlock( hStringMem);
  1397. // Open the Clipboard and clear its contents
  1398. OpenClipboard( hWnd);
  1399. EmptyClipboard();
  1400. // Give the Clipboard the text data
  1401. #if defined(UNICODE)
  1402. SetClipboardData( CF_UNICODETEXT, hStringMem);
  1403. #else // not UNICODE
  1404. SetClipboardData( CF_TEXT, hStringMem);
  1405. #endif // UNICODE
  1406. CloseClipboard();
  1407. hStringMem = NULL;
  1408. } else {
  1409. GlobalUnlock( lpTokData->hToken );
  1410. GlobalUnlock( hMem);
  1411. LoadString( hInst,
  1412. IDS_ERR_NO_MEMORY,
  1413. sz,
  1414. TCHARSIN( sizeof( sz)));
  1415. MessageBox( hWnd,
  1416. sz,
  1417. tszAppName,
  1418. MB_ICONHAND | MB_OK);
  1419. }
  1420. } else {
  1421. GlobalUnlock( lpTokData->hToken );
  1422. GlobalUnlock( hMem);
  1423. LoadString( hInst,
  1424. IDS_ERR_NO_MEMORY,
  1425. sz,
  1426. TCHARSIN( sizeof(sz)));
  1427. MessageBox( hWnd,
  1428. sz,
  1429. tszAppName,
  1430. MB_ICONHAND | MB_OK);
  1431. }
  1432. }
  1433. break;
  1434. }
  1435. case IDM_E_COPY:
  1436. {
  1437. HANDLE hStringMem;
  1438. LPTSTR lpString;
  1439. int nIndex = 0;
  1440. int nLength = 0;
  1441. int nActual = 0;
  1442. TOKEN tok;
  1443. LPTSTR lpstrToken;
  1444. // Is anything selected in the listbox
  1445. if ( (nIndex = (int)SendMessage( hListWnd,
  1446. LB_GETCURSEL,
  1447. (WPARAM)0,
  1448. (LPARAM)0)) != LB_ERR ) {
  1449. HGLOBAL hMem = (HGLOBAL)SendMessage( hListWnd,
  1450. LB_GETITEMDATA,
  1451. (WPARAM)nIndex,
  1452. (LPARAM)0);
  1453. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  1454. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  1455. lstrcpy( szString, lpstrToken);
  1456. GlobalUnlock( lpTokData->hToken );
  1457. GlobalUnlock( hMem);
  1458. ParseBufToTok( szString, &tok);
  1459. nLength = lstrlen( tok.szText);
  1460. // Allocate memory for the string
  1461. if ( (hStringMem =
  1462. GlobalAlloc( GHND, (DWORD)MEMSIZE( nLength + 1))) != NULL ) {
  1463. if ( (lpString =
  1464. (LPTSTR)GlobalLock( hStringMem)) != NULL) {
  1465. // Get the selected text
  1466. #ifdef RLWIN32
  1467. lstrcpy( lpString, tok.szText);
  1468. #else
  1469. _fstrcpy( lpString, tok.szText);
  1470. #endif
  1471. // Unlock the block
  1472. GlobalUnlock(hStringMem);
  1473. // Open the Clipboard and clear its contents
  1474. OpenClipboard( hWnd);
  1475. EmptyClipboard();
  1476. // Give the Clipboard the text data
  1477. #if defined(UNICODE)
  1478. SetClipboardData(CF_UNICODETEXT, hStringMem);
  1479. #else // not UNICODE
  1480. SetClipboardData( CF_TEXT, hStringMem);
  1481. #endif // UNICODE
  1482. CloseClipboard();
  1483. hStringMem = NULL;
  1484. } else {
  1485. LoadString( hInst,
  1486. IDS_ERR_NO_MEMORY,
  1487. sz,
  1488. TCHARSIN( sizeof( sz)));
  1489. MessageBox( hWnd,
  1490. sz,
  1491. tszAppName,
  1492. MB_ICONHAND | MB_OK);
  1493. }
  1494. } else {
  1495. LoadString( hInst,
  1496. IDS_ERR_NO_MEMORY,
  1497. sz,
  1498. TCHARSIN( sizeof( sz)));
  1499. MessageBox( hWnd,
  1500. sz,
  1501. tszAppName,
  1502. MB_ICONHAND | MB_OK);
  1503. }
  1504. RLFREE( tok.szText);
  1505. }
  1506. break;
  1507. }
  1508. case IDM_E_PASTE:
  1509. {
  1510. HANDLE hClipMem = NULL;
  1511. LPTSTR lpClipMem = NULL;
  1512. HGLOBAL hMem = NULL;
  1513. TCHAR *szString;
  1514. int nIndex = 0;
  1515. TOKEN tok;
  1516. LPTSTR lpstrToken;
  1517. if ( OpenClipboard( hWnd) ) {
  1518. #if defined(UNICODE)
  1519. if (IsClipboardFormatAvailable(CF_UNICODETEXT)
  1520. || IsClipboardFormatAvailable(CF_OEMTEXT))
  1521. #else // not UNICODE
  1522. if ( IsClipboardFormatAvailable( CF_TEXT)
  1523. || IsClipboardFormatAvailable( CF_OEMTEXT))
  1524. #endif // UNICODE
  1525. {
  1526. // Check for current position and change that token's text
  1527. nIndex = (int)SendMessage( hListWnd,
  1528. LB_GETCURSEL,
  1529. (WPARAM)0,
  1530. (LPARAM)0);
  1531. if (nIndex == LB_ERR) {
  1532. #if defined(UNICODE)
  1533. //if no select, just ignore
  1534. break;
  1535. #else // not UNICODE
  1536. nIndex = -1;
  1537. #endif // UNICODE
  1538. }
  1539. #if defined(UNICODE)
  1540. hClipMem = GetClipboardData(CF_UNICODETEXT);
  1541. #else // not UNICODE
  1542. hClipMem = GetClipboardData( CF_TEXT);
  1543. #endif // UNICODE
  1544. lpClipMem = (LPTSTR)GlobalLock( hClipMem);
  1545. hMem = (HGLOBAL)SendMessage( hListWnd,
  1546. LB_GETITEMDATA,
  1547. (WPARAM)nIndex,
  1548. (LPARAM)0);
  1549. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  1550. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  1551. if ( lpstrToken ) {
  1552. #if defined(UNICODE)
  1553. szString = (TCHAR *)FALLOC(
  1554. MEMSIZE(lstrlen(lpstrToken)+1) );
  1555. #else // not UNICODE
  1556. szString = (TCHAR *)
  1557. FALLOC( lstrlen( lpstrToken) + 1);
  1558. #endif // UNICODE
  1559. lstrcpy( szString, lpstrToken);
  1560. GlobalUnlock( lpTokData->hToken );
  1561. lMtkPointer = lpTokData->lMtkPointer; //Save
  1562. GlobalUnlock( hMem);
  1563. // copy the string to the token
  1564. ParseBufToTok(szString, &tok);
  1565. RLFREE( szString);
  1566. RLFREE( tok.szText);
  1567. tok.szText = (TCHAR *)
  1568. FALLOC( MEMSIZE( lstrlen( lpClipMem) + 1));
  1569. #ifdef RLWIN32
  1570. lstrcpy( tok.szText, lpClipMem);
  1571. #else
  1572. _fstrcpy(tok.szText, lpClipMem);
  1573. #endif
  1574. GlobalUnlock(hClipMem);
  1575. szString = (TCHAR *)
  1576. FALLOC( MEMSIZE( TokenToTextSize( &tok)));
  1577. ParseTokToBuf(szString, &tok);
  1578. RLFREE( tok.szText);
  1579. // Paste the text
  1580. SendMessage( hListWnd,
  1581. WM_SETREDRAW,
  1582. (WPARAM)FALSE,
  1583. (LPARAM)0);
  1584. SendMessage( hListWnd,
  1585. LB_DELETESTRING,
  1586. (WPARAM)nIndex,
  1587. (LPARAM)0);
  1588. hMem = GlobalAlloc( GMEM_MOVEABLE, sizeof(TOKDATA) );
  1589. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  1590. lpTokData->hToken = GlobalAlloc
  1591. ( GMEM_MOVEABLE, MEMSIZE(lstrlen(szString)+1) );
  1592. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  1593. lstrcpy( lpstrToken, szString);
  1594. RLFREE( szString);
  1595. GlobalUnlock( lpTokData->hToken );
  1596. lpTokData->lMtkPointer = lMtkPointer;
  1597. GlobalUnlock( hMem);
  1598. SendMessage( hListWnd,
  1599. LB_INSERTSTRING,
  1600. (WPARAM)nIndex,
  1601. (LPARAM)hMem);
  1602. SendMessage( hListWnd,
  1603. LB_SETCURSEL,
  1604. (WPARAM)nIndex,
  1605. (LPARAM)0);
  1606. fTokChanges = TRUE; // Set Dirty Flag
  1607. }
  1608. SendMessage( hListWnd,
  1609. WM_SETREDRAW,
  1610. (WPARAM)TRUE,
  1611. (LPARAM)0);
  1612. InvalidateRect(hListWnd, FALSE, TRUE);
  1613. // Close the Clipboard
  1614. CloseClipboard();
  1615. SetFocus(hListWnd);
  1616. }
  1617. }
  1618. CloseClipboard();
  1619. break;
  1620. }
  1621. case IDM_E_FINDDOWN:
  1622. if (fSearchStarted) {
  1623. if (!DoTokenSearchForRledit(szSearchType,
  1624. szSearchText,
  1625. wSearchStatus,
  1626. wSearchStatusMask,
  1627. 0,
  1628. TRUE)) {
  1629. TCHAR sz1[80], sz2[80];
  1630. LoadString( hInst,
  1631. IDS_FIND_TOKEN,
  1632. sz1,
  1633. TCHARSIN( sizeof( sz1)));
  1634. LoadString( hInst,
  1635. IDS_TOKEN_NOT_FOUND,
  1636. sz2,
  1637. TCHARSIN( sizeof( sz2)));
  1638. MessageBox( hWnd,
  1639. sz2,
  1640. sz1,
  1641. MB_ICONINFORMATION | MB_OK);
  1642. }
  1643. break;
  1644. }
  1645. case IDM_E_FINDUP:
  1646. if (fSearchStarted) {
  1647. if (!DoTokenSearchForRledit(szSearchType,
  1648. szSearchText,
  1649. wSearchStatus,
  1650. wSearchStatusMask,
  1651. 1,
  1652. TRUE)) {
  1653. TCHAR sz1[80], sz2[80];
  1654. LoadString( hInst,
  1655. IDS_FIND_TOKEN,
  1656. sz1,
  1657. TCHARSIN( sizeof( sz1)));
  1658. LoadString( hInst,
  1659. IDS_TOKEN_NOT_FOUND,
  1660. sz2,
  1661. TCHARSIN( sizeof( sz2)));
  1662. MessageBox( hWnd,
  1663. sz2,
  1664. sz1,
  1665. MB_ICONINFORMATION | MB_OK);
  1666. }
  1667. break;
  1668. }
  1669. case IDM_E_FIND:
  1670. {
  1671. #ifndef RLWIN32
  1672. //WNDPROC lpfnTOKFINDMsgProc;
  1673. //
  1674. //lpfnTOKFINDMsgProc = MakeProcInstance( (WNDPROC)TOKFINDMsgProc,
  1675. // hInst);
  1676. //
  1677. //if ( DialogBox( hInst, TEXT("TOKFIND"), hWnd, lpfnTOKFINDMsgProc) == -1)
  1678. if ( DialogBox( hInst, TEXT("TOKFIND"), hWnd, TOKFINDMsgProc) == -1)
  1679. #else
  1680. if ( DialogBox( hInst, TEXT("TOKFIND"), hWnd, TOKFINDMsgProc) == -1)
  1681. #endif
  1682. {
  1683. #ifndef DBCS
  1684. // 'Token Not Found' is strange because user selected cancel
  1685. TCHAR sz1[80], sz2[80];
  1686. LoadString( hInst,
  1687. IDS_FIND_TOKEN,
  1688. sz1,
  1689. TCHARSIN( sizeof( sz1)));
  1690. LoadString( hInst,
  1691. IDS_TOKEN_NOT_FOUND,
  1692. sz2,
  1693. TCHARSIN( sizeof( sz2)));
  1694. MessageBox( hWnd,
  1695. sz2,
  1696. sz1,
  1697. MB_ICONINFORMATION | MB_OK);
  1698. #endif //DBCS
  1699. }
  1700. #ifndef RLWIN32
  1701. FreeProcInstance( lpfnTOKFINDMsgProc);
  1702. #endif
  1703. return TRUE;
  1704. }
  1705. case IDM_E_REVIEW:
  1706. {
  1707. int wSaveSelection;
  1708. nUpdateMode = 1;
  1709. // set listbox selection to begining of the token list
  1710. wSaveSelection = (UINT)SendMessage( hListWnd,
  1711. LB_GETCURSEL,
  1712. (WPARAM)0,
  1713. (LPARAM)0);
  1714. // Selection for REVIEW starts with the user-selected line, (PW)
  1715. // not at the top of the token list. (PW)
  1716. // SendMessage(hListWnd, LB_SETCURSEL, 0, 0L); (PW)
  1717. if ( DoTokenSearchForRledit( NULL,
  1718. NULL,
  1719. ST_TRANSLATED | ST_DIRTY,
  1720. ST_TRANSLATED | ST_DIRTY,
  1721. FALSE,
  1722. FALSE) ) {
  1723. #ifdef RLWIN16
  1724. LONG lListParam;
  1725. lListParam = MAKELONG(NULL, LBN_DBLCLK);
  1726. SendMessage( hMainWnd,
  1727. WM_COMMAND,
  1728. (WPARAM)IDC_LIST,
  1729. (LPARAM)lListParam);
  1730. #else
  1731. SendMessage( hMainWnd,
  1732. WM_COMMAND,
  1733. MAKEWPARAM( IDC_LIST, LBN_DBLCLK),
  1734. (LPARAM)0);
  1735. #endif
  1736. }
  1737. break;
  1738. }
  1739. case IDM_E_ALLREVIEW:
  1740. {
  1741. UINT wListParam;
  1742. UINT wIndex, wcTokens;
  1743. wIndex = (UINT)SendMessage( hListWnd, LB_GETCURSEL, 0, 0L);
  1744. wcTokens = (UINT)SendMessage( hListWnd, LB_GETCOUNT, 0, 0L );
  1745. if ( wcTokens == wIndex )
  1746. break;
  1747. nUpdateMode = 2;
  1748. SendMessage( hListWnd, LB_SETCURSEL, wIndex, 0L);
  1749. wListParam = (UINT) MAKELONG(IDC_LIST, LBN_DBLCLK);
  1750. SendMessage(hMainWnd, WM_COMMAND, wListParam, (LPARAM)0);
  1751. break;
  1752. }
  1753. case IDM_O_GENERATE:
  1754. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1755. HCURSOR hOldCursor;
  1756. hOldCursor = SetCursor( hHourGlass);
  1757. rc = GenerateImageFile( gProj.szBld,
  1758. gMstr.szSrc,
  1759. gProj.szTok,
  1760. gMstr.szRdfs,
  1761. 0);
  1762. SetCursor( hOldCursor);
  1763. }
  1764. break;
  1765. case IDM_H_CONTENTS:
  1766. {
  1767. OFSTRUCT Of = { 0, 0, 0, 0, 0, ""};
  1768. if ( OpenFile( gszHelpFile, &Of, OF_EXIST) == HFILE_ERROR ) {
  1769. LoadString( hInst, IDS_ERR_NO_HELP, sz, TCHARSIN( sizeof( sz)));
  1770. MessageBox( hWnd, sz, NULL, MB_OK);
  1771. } else {
  1772. WinHelpA( hWnd, gszHelpFile, HELP_KEY, (DWORD_PTR)(LPSTR)"RLEdit");
  1773. }
  1774. break;
  1775. }
  1776. case IDM_H_ABOUT:
  1777. {
  1778. #ifndef RLWIN32
  1779. //WNDPROC lpProcAbout;
  1780. //lpProcAbout = MakeProcInstance(About, hInst);
  1781. //DialogBox(hInst, TEXT("ABOUT"), hWnd, lpProcAbout);
  1782. //FreeProcInstance(lpProcAbout);
  1783. DialogBox(hInst, TEXT("ABOUT"), hWnd, About);
  1784. #else
  1785. DialogBox(hInst, TEXT("ABOUT"), hWnd, About);
  1786. #endif
  1787. break;
  1788. }
  1789. break;
  1790. default:
  1791. if (wParam <= IDM_LAST_EDIT && wParam >= IDM_FIRST_EDIT) {
  1792. // USER IS INVOKING AN EDITOR
  1793. CHAR szEditor[MAXFILENAME] = "";
  1794. if ( LoadStrIntoAnsiBuf(hInst, (UINT)wParam, szEditor, sizeof(szEditor))) {
  1795. if ( SendMessage( hWnd, WM_SAVEPROJECT, (WPARAM)0, (LPARAM)0) ) {
  1796. HCURSOR hOldCursor;
  1797. hOldCursor = SetCursor(hHourGlass);
  1798. MyGetTempFileName(0, "RES", 0, szTempRes);
  1799. fInThirdPartyEditer = TRUE;
  1800. if (gProj.fSourceEXE) {
  1801. // we need to first extract the .RES from the .EXE
  1802. CHAR sz[MAXFILENAME] = "";
  1803. MyGetTempFileName(0, "RES", 0, sz);
  1804. ExtractResFromExe32A( gMstr. szSrc, sz, 0);
  1805. GenerateRESfromRESandTOKandRDFs( szTempRes,
  1806. sz,
  1807. gProj.szTok,
  1808. gMstr.szRdfs,
  1809. ID_RT_DIALOG);
  1810. remove(sz);
  1811. } else {
  1812. GenerateRESfromRESandTOKandRDFs( szTempRes,
  1813. gMstr.szSrc,
  1814. gProj.szTok,
  1815. gMstr.szRdfs,
  1816. ID_RT_DIALOG);
  1817. }
  1818. SetCursor( hOldCursor);
  1819. ExecResEditor( hWnd, szEditor, szTempRes, "");
  1820. }
  1821. }
  1822. }
  1823. break; // default
  1824. }
  1825. return FALSE;
  1826. }
  1827. #ifdef RLWIN16
  1828. static int ExecResEditor(HWND hWnd, CHAR *szEditor, CHAR *szFile, CHAR *szArgs)
  1829. {
  1830. CHAR szExecCmd[256];
  1831. int RetCode;
  1832. // generate command line
  1833. lstrcpy( szExecCmd, szEditor);
  1834. lstrcat( szExecCmd, " ");
  1835. lstrcat( szExecCmd, szArgs);
  1836. lstrcat( szExecCmd, " ");
  1837. lstrcat( szExecCmd, szFile);
  1838. lpfnWatchTask = MakeProcInstance(WatchTask, hInst);
  1839. NotifyRegister(NULL, (LPFNNOTIFYCALLBACK)lpfnWatchTask, NF_NORMAL);
  1840. fWatchEditor = TRUE;
  1841. // exec resource editor
  1842. RetCode = WinExec(szExecCmd, SW_SHOWNORMAL);
  1843. if (RetCode > 31) {
  1844. // successful execution
  1845. ShowWindow(hWnd, SW_HIDE);
  1846. } else {
  1847. // unsuccessful execution
  1848. CHAR sz[80];
  1849. NotifyUnRegister(NULL);
  1850. FreeProcInstance(lpfnWatchTask);
  1851. remove(szFile);
  1852. fInThirdPartyEditer = FALSE;
  1853. SendMessage( hWnd, WM_LOADTOKENS, (WPARAM)0, (LPARAM)0);
  1854. LoadString( hInst, IDS_GENERALFAILURE, sz, TCHARSIN( sizeof( sz)));
  1855. MessageBox( hWnd, sz, tszAppName, MB_OK);
  1856. }
  1857. return RetCode;
  1858. }
  1859. #endif
  1860. #ifdef RLWIN32
  1861. static int ExecResEditor(HWND hWnd, CHAR *szEditor, CHAR *szFile, CHAR *szArgs)
  1862. {
  1863. TCHAR wszExecCmd[256];
  1864. CHAR szExecCmd[256];
  1865. DWORD dwRetCode = 0;
  1866. DWORD dwExitCode = 0;
  1867. BOOL fSuccess = FALSE;
  1868. BOOL fExit = FALSE;
  1869. PROCESS_INFORMATION ProcessInfo;
  1870. STARTUPINFO StartupInfo;
  1871. StartupInfo.cb = sizeof(STARTUPINFO);
  1872. StartupInfo.lpReserved = NULL;
  1873. StartupInfo.lpDesktop = NULL;
  1874. StartupInfo.lpTitle = TEXT("Resize Dialogs");
  1875. StartupInfo.dwX = 0L;
  1876. StartupInfo.dwY = 0L;
  1877. StartupInfo.dwXSize = 0L;
  1878. StartupInfo.dwYSize = 0L;
  1879. StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
  1880. StartupInfo.wShowWindow = SW_SHOWDEFAULT;
  1881. StartupInfo.lpReserved2 = NULL;
  1882. StartupInfo.cbReserved2 = 0;
  1883. // generate command line
  1884. strcpy(szExecCmd, szEditor);
  1885. strcat(szExecCmd, " ");
  1886. strcat(szExecCmd, szArgs);
  1887. strcat(szExecCmd, " ");
  1888. strcat(szExecCmd, szFile);
  1889. #ifdef UNICODE
  1890. _MBSTOWCS( wszExecCmd,
  1891. szExecCmd,
  1892. WCHARSIN( sizeof( wszExecCmd)),
  1893. ACHARSIN( strlen(szExecCmd) + 1));
  1894. #else
  1895. strcpy(wszExecCmd, szExecCmd);
  1896. #endif
  1897. fSuccess = CreateProcess( (LPTSTR) NULL,
  1898. wszExecCmd,
  1899. NULL,
  1900. NULL,
  1901. FALSE,
  1902. NORMAL_PRIORITY_CLASS,
  1903. NULL,
  1904. NULL,
  1905. &StartupInfo,
  1906. &ProcessInfo); /* try to create a process */
  1907. if ( fSuccess ) {
  1908. // wait for the editor to complete */
  1909. dwRetCode = WaitForSingleObject( ProcessInfo.hProcess, 0xFFFFFFFF) ;
  1910. if ( ! dwRetCode ) {
  1911. // editor terminated, check exit code
  1912. fExit = GetExitCodeProcess( ProcessInfo.hProcess, &dwExitCode) ;
  1913. } else {
  1914. fExit = FALSE;
  1915. }
  1916. // close the editor object handles
  1917. CloseHandle( ProcessInfo.hThread) ;
  1918. CloseHandle( ProcessInfo.hProcess) ;
  1919. if ( fExit ) {
  1920. // successful execution
  1921. ShowWindow(hWnd, SW_HIDE);
  1922. SendMessage(hMainWnd, WM_EDITER_CLOSED, 0, 0);
  1923. } else {
  1924. // unsuccessful execution
  1925. remove( szFile);
  1926. fInThirdPartyEditer = FALSE;
  1927. SendMessage( hWnd, WM_LOADTOKENS, (WPARAM)0, (LPARAM)0);
  1928. LoadStrIntoAnsiBuf( hInst, IDS_GENERALFAILURE, szDHW, DHWSIZE);
  1929. MessageBoxA( hWnd, szDHW, szEditor, MB_ICONSTOP|MB_OK);
  1930. }
  1931. } else {
  1932. CHAR szText[ 80] = "";
  1933. LPSTR pszMsg = szText;
  1934. dwRetCode = GetLastError();
  1935. if ( dwRetCode == ERROR_PATH_NOT_FOUND ) {
  1936. pszMsg = ", Path not found.";
  1937. } else if ( dwRetCode == ERROR_FILE_NOT_FOUND ) {
  1938. OFSTRUCT Of = { 0, 0, 0, 0, 0, ""};
  1939. sprintf( szText,
  1940. ", File \"%s\" not found.",
  1941. OpenFile( szFile, &Of, OF_EXIST) != HFILE_ERROR
  1942. ? szEditor
  1943. : szFile);
  1944. }
  1945. sprintf( szDHW,
  1946. "Command \"%s\" failed.\nSystem error code = %d%s",
  1947. szExecCmd,
  1948. dwRetCode,
  1949. pszMsg);
  1950. MessageBoxA( hWnd, szDHW, szAppName, MB_ICONEXCLAMATION|MB_OK);
  1951. fExit = FALSE;
  1952. }
  1953. return ( fExit);
  1954. }
  1955. #endif
  1956. /**
  1957. * Function: WatchTask
  1958. * A callback function installed by a NotifyRegister function.
  1959. * This function is installed by the dialog editer command and is used
  1960. * to tell RLEDIT when the dialog editer has been closed by the user.
  1961. *
  1962. * To use this function, set fWatchEditor to TRUE and install this
  1963. * callback function by using NotifyRegister. The next task initiated
  1964. * (in our case via a WinExec call) will be watched for termination.
  1965. *
  1966. * When WatchTask sees that the task being watched has terminated it
  1967. * posts a WM_EDITER_CLOSED message to RLEDITs main window.
  1968. *
  1969. * History:
  1970. * 2/92, implemented SteveBl
  1971. */
  1972. #ifdef RLWIN16
  1973. BOOL PASCAL _loadds WatchTask(WORD wID, DWORD dwData)
  1974. {
  1975. static HTASK htWatchedTask;
  1976. static BOOL fWatching = FALSE;
  1977. switch (wID) {
  1978. case NFY_STARTTASK:
  1979. if (fWatchEditor) {
  1980. htWatchedTask = GetCurrentTask();
  1981. fWatching = TRUE;
  1982. fWatchEditor = FALSE;
  1983. }
  1984. break;
  1985. case NFY_EXITTASK:
  1986. if (fWatching) {
  1987. if (GetCurrentTask() == htWatchedTask) {
  1988. PostMessage(hMainWnd, WM_EDITER_CLOSED, 0, 0);
  1989. fWatching = FALSE;
  1990. }
  1991. }
  1992. break;
  1993. }
  1994. return FALSE;
  1995. }
  1996. #endif
  1997. /**
  1998. *
  1999. *
  2000. * Function: TokEditDlgProc
  2001. * Procedure for the edit mode dialog window. Loads the selected token
  2002. * info into the window, and allows the user to change the token text.
  2003. * Once the edit is complete, the procedure sends a message to the
  2004. * list box windows to update the current token info.
  2005. *
  2006. *
  2007. * Arguments:
  2008. *
  2009. * Returns: NA.
  2010. *
  2011. * Errors Codes:
  2012. * TRUE, carry out edit, and update token list box.
  2013. * FALSE, cancel edit.
  2014. *
  2015. * History:
  2016. *
  2017. *
  2018. **/
  2019. INT_PTR CALLBACK TokEditDlgProc(
  2020. HWND hDlg,
  2021. UINT wMsg,
  2022. WPARAM wParam,
  2023. LPARAM lParam)
  2024. {
  2025. HWND hCtl = NULL;
  2026. HWND hParentWnd = NULL;
  2027. UINT static wcTokens = 0;
  2028. UINT wNotifyCode = 0;
  2029. UINT wIndex = 0;
  2030. #ifdef RLWIN16
  2031. LONG lListParam = 0;
  2032. #endif
  2033. switch ( wMsg ) {
  2034. case WM_INITDIALOG:
  2035. cwCenter( hDlg, 0);
  2036. wcTokens = (UINT)SendMessage( hListWnd,
  2037. LB_GETCOUNT,
  2038. (WPARAM)0,
  2039. (LPARAM)0);
  2040. wcTokens--;
  2041. // only allow skip button if in update mode
  2042. if ( ! nUpdateMode ) {
  2043. if ( (hCtl = GetDlgItem( hDlg, IDD_SKIP)) ) {
  2044. EnableWindow( hCtl, FALSE);
  2045. }
  2046. } else {
  2047. if ( (hCtl = GetDlgItem( hDlg, IDD_SKIP)) ) {
  2048. EnableWindow( hCtl, TRUE);
  2049. }
  2050. }
  2051. // disallow auto translate if we don't have a glossary file
  2052. if ( *gProj.szGlo == '\0' ) {
  2053. hCtl = GetDlgItem( hDlg, IDD_TRANSLATE);
  2054. EnableWindow( hCtl, FALSE);
  2055. hCtl = GetDlgItem( hDlg, IDD_ADD);
  2056. EnableWindow( hCtl, FALSE);
  2057. }
  2058. return ( TRUE);
  2059. case WM_COMMAND:
  2060. switch ( GET_WM_COMMAND_ID( wParam, lParam) ) {
  2061. case IDD_TOKCURTRANS:
  2062. wNotifyCode = GET_WM_COMMAND_CMD( wParam, lParam);
  2063. hCtl = GET_WM_COMMAND_HWND( wParam, lParam);
  2064. if ( wNotifyCode == EN_CHANGE ) {
  2065. if ( hCtl = GetDlgItem( hDlg, IDOK) ) {
  2066. EnableWindow( hCtl, TRUE);
  2067. }
  2068. }
  2069. break;
  2070. case IDD_ADD:
  2071. {
  2072. TCHAR *szUntranslated = NULL;
  2073. TCHAR *szTranslated = NULL;
  2074. TCHAR *sz = NULL;
  2075. TCHAR szMask[80] = TEXT("");
  2076. HWND hDlgItem = NULL;
  2077. int cCurTextLen = 0;
  2078. int cTotalTextLen = 80;
  2079. hDlgItem = GetDlgItem( hDlg, IDD_TOKCURTEXT);
  2080. cCurTextLen = GetWindowTextLength( hDlgItem);
  2081. cTotalTextLen += cCurTextLen;
  2082. szUntranslated = (TCHAR *)FALLOC( MEMSIZE( cCurTextLen + 1));
  2083. GetDlgItemText( hDlg,
  2084. IDD_TOKCURTEXT,
  2085. szUntranslated,
  2086. cCurTextLen + 1);
  2087. hDlgItem = GetDlgItem( hDlg, IDD_TOKCURTRANS);
  2088. cCurTextLen = GetWindowTextLength( hDlgItem);
  2089. cTotalTextLen += cCurTextLen;
  2090. szTranslated = (TCHAR *)FALLOC( MEMSIZE( cCurTextLen + 1));
  2091. GetDlgItemText( hDlg,
  2092. IDD_TOKCURTRANS,
  2093. szTranslated,
  2094. cCurTextLen + 1);
  2095. LoadString( hInst,
  2096. IDS_ADDGLOSS,
  2097. szMask,
  2098. TCHARSIN( sizeof(szMask)));
  2099. sz = (TCHAR *)FALLOC( MEMSIZE( cTotalTextLen + 1));
  2100. wsprintf( sz, szMask, szTranslated, szUntranslated);
  2101. if ( MessageBox( hDlg,
  2102. sz,
  2103. tszAppName,
  2104. MB_ICONQUESTION | MB_YESNO) == IDYES) {
  2105. HCURSOR hOldCursor = SetCursor( hHourGlass);
  2106. AddTranslation( szUntranslated,
  2107. szTranslated,
  2108. lFilePointer);
  2109. TransString( szUntranslated,
  2110. szTranslated,
  2111. &pTransList,
  2112. lFilePointer);
  2113. SetCursor( hOldCursor);
  2114. }
  2115. RLFREE( sz);
  2116. RLFREE( szUntranslated);
  2117. RLFREE( szTranslated);
  2118. break;
  2119. }
  2120. case IDD_UNTRANSLATE:
  2121. {
  2122. int cTextLen = 0;
  2123. TCHAR *sz = NULL;
  2124. HWND hDlgItem = NULL;
  2125. hDlgItem = GetDlgItem( hDlg, IDD_TOKCURTEXT);
  2126. cTextLen = GetWindowTextLength( hDlgItem);
  2127. sz = (TCHAR *)FALLOC( MEMSIZE( cTextLen + 1));
  2128. GetDlgItemText( hDlg,
  2129. IDD_TOKCURTEXT,
  2130. sz,
  2131. cTextLen + 1);
  2132. SetDlgItemText( hDlg, IDD_TOKCURTRANS, sz);
  2133. RLFREE( sz);
  2134. break;
  2135. }
  2136. case IDD_TRANSLATE:
  2137. // Get next thing in the translation list
  2138. if ( pTransList ) {
  2139. pTransList = pTransList->pNext;
  2140. SetDlgItemText( hDlg, IDD_TOKCURTRANS, pTransList->sz);
  2141. }
  2142. break;
  2143. case IDD_SKIP:
  2144. wIndex = (UINT)SendMessage( hListWnd,
  2145. LB_GETCURSEL,
  2146. (LPARAM)0,
  2147. (LPARAM)0);
  2148. if ( nUpdateMode == 2 && wIndex < wcTokens ) {
  2149. wIndex++;
  2150. SendMessage( hListWnd, LB_SETCURSEL, wIndex, 0L );
  2151. SendMessage( hMainWnd,
  2152. WM_COMMAND,
  2153. MAKEWPARAM( IDC_LIST, LBN_DBLCLK),
  2154. (LPARAM)0);
  2155. return ( TRUE );
  2156. } else if ( nUpdateMode == 1 && (wIndex < wcTokens) ) {
  2157. wIndex++;
  2158. SendMessage( hListWnd,
  2159. LB_SETCURSEL,
  2160. (WPARAM)wIndex,
  2161. (LPARAM)0);
  2162. if ( DoTokenSearchForRledit( NULL,
  2163. NULL,
  2164. ST_TRANSLATED | ST_DIRTY,
  2165. ST_TRANSLATED | ST_DIRTY,
  2166. FALSE,
  2167. FALSE) ) {
  2168. // go into edit mode
  2169. wIndex = (UINT)SendMessage( hListWnd,
  2170. LB_GETCURSEL,
  2171. (WPARAM)0,
  2172. (LPARAM)0);
  2173. #ifdef RLWIN16
  2174. SendMessage( hMainWnd,
  2175. WM_COMMAND,
  2176. IDC_LIST,
  2177. MAKELONG( NULL, LBN_DBLCLK));
  2178. #else
  2179. SendMessage( hMainWnd,
  2180. WM_COMMAND,
  2181. MAKEWPARAM( IDC_LIST, LBN_DBLCLK),
  2182. (LPARAM)0);
  2183. #endif
  2184. return TRUE;
  2185. }
  2186. }
  2187. nUpdateMode = 0;
  2188. // remove edit dialog box
  2189. DestroyWindow( hDlg);
  2190. #ifndef RLWIN32
  2191. //FreeProcInstance( (FARPROC)lpTokEditDlg);
  2192. #endif
  2193. hTokEditDlgWnd = 0;
  2194. break;
  2195. case IDD_READONLY:
  2196. if ( IsDlgButtonChecked( hDlg, IDD_READONLY) ) {
  2197. EnableWindow( GetDlgItem( hDlg, IDD_TOKCURTRANS), FALSE);
  2198. } else {
  2199. EnableWindow( GetDlgItem( hDlg, IDD_TOKCURTRANS), TRUE);
  2200. }
  2201. break;
  2202. case IDOK:
  2203. {
  2204. int cTokenTextLen = 0;
  2205. TCHAR *szTokTextBuf = NULL;
  2206. HWND hDlgItem = NULL;
  2207. wIndex = (UINT)SendMessage( hListWnd,
  2208. LB_GETCURSEL,
  2209. (WPARAM)0,
  2210. (LPARAM)0);
  2211. fTokChanges = TRUE;
  2212. // set flag to show token list has changed
  2213. // Extract String from IDD_TOKTEXT edit control
  2214. hDlgItem = GetDlgItem( hDlg, IDD_TOKCURTRANS);
  2215. cTokenTextLen = GetWindowTextLength( hDlgItem);
  2216. szTokTextBuf = (TCHAR *)FALLOC( MEMSIZE( cTokenTextLen + 1));
  2217. GetDlgItemText( hDlg,
  2218. IDD_TOKCURTRANS,
  2219. szTokTextBuf,
  2220. cTokenTextLen+1);
  2221. hParentWnd = GetParent( hDlg);
  2222. SendMessage( hParentWnd,
  2223. WM_TOKEDIT,
  2224. (WPARAM)((IsDlgButtonChecked( hDlg, IDD_READONLY)
  2225. ? ST_READONLY : 0)
  2226. | (IsDlgButtonChecked( hDlg, IDD_DIRTY)
  2227. ? ST_DIRTY : 0)),
  2228. (LPARAM)szTokTextBuf);
  2229. RLFREE( szTokTextBuf);
  2230. // Exit, or goto to next changed token if in update mode
  2231. if ( nUpdateMode == 2 && wIndex < wcTokens ) {
  2232. wIndex++;
  2233. SendMessage( hListWnd, LB_SETCURSEL, wIndex, 0L );
  2234. SendMessage( hMainWnd,
  2235. WM_COMMAND,
  2236. MAKEWPARAM( IDC_LIST, LBN_DBLCLK),
  2237. (LPARAM)0);
  2238. return ( TRUE );
  2239. } else if ( nUpdateMode == 1 && (wIndex < wcTokens) ) {
  2240. wIndex++;
  2241. SendMessage( hListWnd,
  2242. LB_SETCURSEL,
  2243. (WPARAM)wIndex,
  2244. (LPARAM)0);
  2245. if ( DoTokenSearchForRledit( NULL,
  2246. NULL,
  2247. ST_TRANSLATED | ST_DIRTY,
  2248. ST_TRANSLATED | ST_DIRTY,
  2249. FALSE,
  2250. FALSE) ) {
  2251. // go into edit mode
  2252. #ifdef RLWIN16
  2253. lListParam = MAKELONG(NULL, LBN_DBLCLK);
  2254. SendMessage( hMainWnd,
  2255. WM_COMMAND,
  2256. IDC_LIST,
  2257. lListParam);
  2258. #else
  2259. SendMessage( hMainWnd,
  2260. WM_COMMAND,
  2261. MAKEWPARAM(IDC_LIST, LBN_DBLCLK),
  2262. (LPARAM)0);
  2263. #endif
  2264. return ( TRUE);
  2265. }
  2266. }
  2267. }
  2268. // fall through to IDCANCEL
  2269. case IDCANCEL:
  2270. nUpdateMode = 0;
  2271. // remove edit dialog box
  2272. DestroyWindow( hDlg);
  2273. #ifndef RLWIN32
  2274. //FreeProcInstance( lpTokEditDlg);
  2275. #endif
  2276. hTokEditDlgWnd = 0;
  2277. break;
  2278. } // GET_WM_COMMAND_ID
  2279. return ( TRUE);
  2280. default:
  2281. if ( (hCtl = GetDlgItem(hDlg, IDOK)) ) {
  2282. EnableWindow( hCtl, TRUE);
  2283. }
  2284. return ( FALSE);
  2285. } // Main Switch
  2286. }
  2287. /**
  2288. *
  2289. * Function: TOKFINDMsgProc
  2290. *
  2291. * Arguments:
  2292. *
  2293. * Returns:
  2294. * NA.
  2295. *
  2296. * Errors Codes:
  2297. *
  2298. * History:
  2299. *
  2300. **/
  2301. //#ifdef RLWIN32
  2302. //BOOL CALLBACK TOKFINDMsgProc(HWND hWndDlg, UINT wMsg, UINT wParam, LONG lParam)
  2303. //#else
  2304. INT_PTR CALLBACK TOKFINDMsgProc(
  2305. HWND hWndDlg,
  2306. UINT wMsg,
  2307. WPARAM wParam,
  2308. LPARAM lParam)
  2309. //#endif
  2310. {
  2311. HWND hCtl;
  2312. int rgiTokenTypes[]=
  2313. {
  2314. ID_RT_MENU,
  2315. ID_RT_DIALOG,
  2316. ID_RT_STRING,
  2317. ID_RT_ACCELERATORS,
  2318. ID_RT_RCDATA,
  2319. ID_RT_ERRTABLE,
  2320. ID_RT_NAMETABLE,
  2321. ID_RT_VERSION,
  2322. ID_RT_DLGINIT
  2323. };
  2324. TCHAR szTokenType[20] = TEXT("");
  2325. WORD i;
  2326. DWORD rc;
  2327. switch (wMsg) {
  2328. case WM_INITDIALOG:
  2329. CheckDlgButton(hWndDlg, IDD_READONLY, 2);
  2330. CheckDlgButton(hWndDlg, IDD_DIRTY, 2);
  2331. CheckDlgButton(hWndDlg, IDD_FINDDOWN, 1);
  2332. hCtl = GetDlgItem(hWndDlg, IDD_TYPELST);
  2333. for (i = 0; i < sizeof(rgiTokenTypes)/sizeof(int); i ++) {
  2334. LoadString( hInst,
  2335. IDS_RESOURCENAMES + rgiTokenTypes[i],
  2336. szTokenType,
  2337. TCHARSIN( sizeof( szTokenType)));
  2338. SendMessage( hCtl,
  2339. CB_ADDSTRING,
  2340. (WPARAM)0,
  2341. (LPARAM)szTokenType);
  2342. }
  2343. return TRUE;
  2344. break;
  2345. case WM_COMMAND:
  2346. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  2347. case IDOK: /* Button text: "Okay" */
  2348. GetDlgItemText(hWndDlg, IDD_TYPELST, szSearchType, 40);
  2349. GetDlgItemText(hWndDlg, IDD_FINDTOK, szSearchText, 256);
  2350. wSearchStatus = ST_TRANSLATED;
  2351. wSearchStatusMask = ST_TRANSLATED ;
  2352. switch (IsDlgButtonChecked(hWndDlg, IDD_READONLY)) {
  2353. case 1:
  2354. wSearchStatus |= ST_READONLY;
  2355. case 0:
  2356. wSearchStatusMask |= ST_READONLY;
  2357. }
  2358. switch (IsDlgButtonChecked(hWndDlg, IDD_DIRTY)) {
  2359. case 1:
  2360. wSearchStatus |= ST_DIRTY;
  2361. case 0:
  2362. wSearchStatusMask |= ST_DIRTY;
  2363. }
  2364. fSearchStarted = TRUE;
  2365. fSearchDirection = IsDlgButtonChecked(hWndDlg, IDD_FINDUP);
  2366. EndDialog( hWndDlg,
  2367. DoTokenSearchForRledit( szSearchType,
  2368. szSearchText,
  2369. wSearchStatus,
  2370. wSearchStatusMask,
  2371. fSearchDirection,
  2372. FALSE));
  2373. return TRUE;
  2374. case IDCANCEL:
  2375. /* and dismiss the dialog window returning FALSE */
  2376. EndDialog( hWndDlg, -1);
  2377. return TRUE;
  2378. }
  2379. break; /* End of WM_COMMAND */
  2380. default:
  2381. return FALSE;
  2382. }
  2383. return FALSE;
  2384. }
  2385. /**
  2386. * Function: NewDlgProc
  2387. * Procedure for the new project dialog window.
  2388. *
  2389. * Arguments:
  2390. *
  2391. * Returns: NA.
  2392. *
  2393. * Errors Codes:
  2394. * TRUE, carry out edit, and update token list box.
  2395. * FALSE, cancel edit.
  2396. *
  2397. * History:
  2398. **/
  2399. static CHAR szPrompt[80] = "";
  2400. static CHAR *szFSpec = NULL;
  2401. static CHAR *szExt = NULL;
  2402. static int iLastBox = IDD_MPJ;
  2403. INT_PTR CALLBACK NewDlgProc( HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  2404. {
  2405. static PROJDATA OldProj;
  2406. static CHAR szNewFileName[ MAXFILENAME] = "";
  2407. switch ( wMsg ) {
  2408. case WM_INITDIALOG:
  2409. {
  2410. int nSel = 0;
  2411. LPTSTR pszLangName = NULL;
  2412. // Save the old .PRJ
  2413. CopyMemory( &OldProj, &gProj, sizeof( PROJDATA));
  2414. if ( (pszLangName = GetLangName( (WORD)(PRIMARYLANGID( gMstr.wLanguageID)),
  2415. (WORD)(SUBLANGID( gMstr.wLanguageID)))) == NULL ) {
  2416. SetDlgItemText( hDlg, IDD_MSTR_LANG_NAME, TEXT("UNKNOWN"));
  2417. } else {
  2418. SetDlgItemText( hDlg, IDD_MSTR_LANG_NAME, pszLangName);
  2419. }
  2420. FillListAndSetLang( hDlg,
  2421. IDD_PROJ_LANG_NAME,
  2422. &gProj.wLanguageID,
  2423. NULL);
  2424. if ( gProj.uCodePage == CP_ACP )
  2425. gProj.uCodePage = GetACP();
  2426. else if ( gProj.uCodePage == CP_OEMCP )
  2427. gProj.uCodePage = GetOEMCP();
  2428. if ( ! IsValidCodePage( gProj.uCodePage) ) {
  2429. static TCHAR szMsg[ 256];
  2430. CHAR *pszCP[1];
  2431. pszCP[0] = UlongToPtr(gProj.uCodePage);
  2432. LoadString( hInst, IDS_NOCPXTABLE, szMsg, 256);
  2433. FormatMessage( FORMAT_MESSAGE_FROM_STRING
  2434. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  2435. szMsg,
  2436. 0,
  2437. 0,
  2438. (LPTSTR)szDHW,
  2439. DHWSIZE/sizeof(TCHAR),
  2440. (va_list *)pszCP);
  2441. MessageBox( hDlg, (LPCTSTR)szDHW, tszAppName, MB_ICONHAND|MB_OK);
  2442. }
  2443. SetDlgItemInt( hDlg, IDD_PROJ_TOK_CP, gProj.uCodePage, FALSE);
  2444. if ( fEditing ) {
  2445. SetDlgItemTextA( hDlg, IDD_MPJ, gProj.szMpj);
  2446. SetDlgItemTextA( hDlg, IDD_TOK, gProj.szTok);
  2447. SetDlgItemTextA( hDlg, IDD_BUILTRES, gProj.szBld);
  2448. SetDlgItemTextA( hDlg, IDD_GLOSS, gProj.szGlo);
  2449. } else {
  2450. // fill in suggested name for the token file
  2451. SetDlgItemTextA( hDlg, IDD_TOK, ".TOK");
  2452. SetDlgItemTextA( hDlg, IDD_BUILTRES, ".EXE");
  2453. SetDlgItemTextA( hDlg, IDD_GLOSS, ".TXT");
  2454. iLastBox = IDD_MPJ;
  2455. PostMessage( hDlg, WM_COMMAND, IDD_BROWSE, 0);
  2456. }
  2457. CheckRadioButton( hDlg,
  2458. IDC_REPLACE,
  2459. IDC_APPEND,
  2460. gfReplace ? IDC_REPLACE : IDC_APPEND);
  2461. return TRUE;
  2462. }
  2463. case WM_COMMAND:
  2464. switch ( GET_WM_COMMAND_ID( wParam, lParam) ) {
  2465. case IDD_MPJ:
  2466. case IDD_TOK:
  2467. case IDD_BUILTRES:
  2468. case IDD_GLOSS:
  2469. iLastBox = GET_WM_COMMAND_ID( wParam, lParam);
  2470. break;
  2471. case IDD_BROWSE:
  2472. {
  2473. switch ( iLastBox ) {
  2474. case IDD_MPJ:
  2475. szFSpec = szMPJFilterSpec;
  2476. szExt = "MPJ";
  2477. LoadStrIntoAnsiBuf( hInst,
  2478. IDS_MPJ,
  2479. szPrompt,
  2480. sizeof( szPrompt));
  2481. break;
  2482. case IDD_BUILTRES:
  2483. szFSpec = szExeResFilterSpec;
  2484. szExt = "EXE";
  2485. LoadStrIntoAnsiBuf( hInst,
  2486. IDS_RES_BLD,
  2487. szPrompt,
  2488. sizeof( szPrompt));
  2489. break;
  2490. case IDD_TOK:
  2491. szFSpec = szTokFilterSpec;
  2492. szExt = "TOK";
  2493. LoadStrIntoAnsiBuf( hInst,
  2494. IDS_TOK,
  2495. szPrompt,
  2496. sizeof( szPrompt));
  2497. break;
  2498. case IDD_GLOSS:
  2499. szFSpec = szGlossFilterSpec;
  2500. szExt ="TXT";
  2501. LoadStrIntoAnsiBuf( hInst,
  2502. IDS_GLOSS,
  2503. szPrompt,
  2504. sizeof( szPrompt));
  2505. break;
  2506. } // END switch ( iLastBox )
  2507. if ( GetFileNameFromBrowse( hDlg,
  2508. szNewFileName,
  2509. MAXFILENAME,
  2510. szPrompt,
  2511. szFSpec,
  2512. szExt) ) {
  2513. SetDlgItemTextA( hDlg, iLastBox, szNewFileName);
  2514. SetNames( hDlg, iLastBox, szNewFileName);
  2515. }
  2516. break;
  2517. } // END case IDD_BROWSE:
  2518. case IDC_REPLACE:
  2519. case IDC_APPEND:
  2520. CheckRadioButton( hDlg,
  2521. IDC_REPLACE,
  2522. IDC_APPEND,
  2523. GET_WM_COMMAND_ID( wParam, lParam));
  2524. break;
  2525. case IDD_PROJ_LANG_NAME:
  2526. if ( GET_WM_COMMAND_CMD( wParam, lParam) == CBN_SELENDOK ) {
  2527. //... Get the selected language name
  2528. //... then set the appropriate lang id vals
  2529. INT_PTR nSel = SendDlgItemMessage( hDlg,
  2530. IDD_PROJ_LANG_NAME,
  2531. CB_GETCURSEL,
  2532. (WPARAM)0,
  2533. (LPARAM)0);
  2534. if ( nSel != CB_ERR
  2535. && SendDlgItemMessage( hDlg,
  2536. IDD_PROJ_LANG_NAME,
  2537. CB_GETLBTEXT,
  2538. (WPARAM)nSel,
  2539. (LPARAM)(LPTSTR)szDHW) != CB_ERR ) {
  2540. WORD wPri = 0;
  2541. WORD wSub = 0;
  2542. if ( GetLangIDs( (LPTSTR)szDHW, &wPri, &wSub) ) {
  2543. gProj.wLanguageID = MAKELANGID( wPri, wSub);
  2544. }
  2545. }
  2546. }
  2547. break;
  2548. case IDOK:
  2549. {
  2550. PROJDATA stProject =
  2551. { "", "", "", "", "", "",
  2552. CP_ACP,
  2553. MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US),
  2554. FALSE,
  2555. FALSE
  2556. };
  2557. BOOL fTranslated = FALSE;
  2558. UINT uCP = GetDlgItemInt( hDlg,
  2559. IDD_TOK_CP,
  2560. &fTranslated,
  2561. FALSE);
  2562. if ( uCP == CP_ACP )
  2563. uCP = GetACP();
  2564. else if ( uCP == CP_OEMCP )
  2565. uCP = GetOEMCP();
  2566. if ( IsValidCodePage( uCP) ) {
  2567. gProj.uCodePage = uCP;
  2568. } else {
  2569. static TCHAR szMsg[ 256];
  2570. CHAR *pszCP[1];
  2571. pszCP[0] = UlongToPtr(uCP);
  2572. LoadString( hInst, IDS_NOCPXTABLE, szMsg, 256);
  2573. FormatMessage( FORMAT_MESSAGE_FROM_STRING
  2574. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  2575. szMsg,
  2576. 0,
  2577. 0,
  2578. (LPTSTR)szDHW,
  2579. DHWSIZE/sizeof(TCHAR),
  2580. (va_list *)pszCP);
  2581. MessageBox( hDlg, (LPCTSTR)szDHW, tszAppName, MB_ICONHAND|MB_OK);
  2582. SetDlgItemInt( hDlg, IDD_TOK_CP, gProj.uCodePage, FALSE);
  2583. return ( TRUE);
  2584. }
  2585. GetDlgItemTextA( hDlg, IDD_MPJ, stProject.szMpj, MAXFILENAME);
  2586. GetDlgItemTextA( hDlg, IDD_BUILTRES, stProject.szBld, MAXFILENAME);
  2587. GetDlgItemTextA( hDlg, IDD_TOK, stProject.szTok, MAXFILENAME);
  2588. GetDlgItemTextA( hDlg, IDD_GLOSS, stProject.szGlo, MAXFILENAME);
  2589. //Why don't allow the partial path?
  2590. if ( stProject.szMpj[0]
  2591. && stProject.szBld[0]
  2592. && stProject.szTok[0] ) {
  2593. _fullpath( gProj.szMpj,
  2594. stProject.szMpj,
  2595. sizeof( gProj.szMpj));
  2596. _fullpath( gProj.szBld,
  2597. stProject.szBld,
  2598. sizeof( gProj.szBld));
  2599. _fullpath( gProj.szTok,
  2600. stProject.szTok,
  2601. sizeof( gProj.szTok));
  2602. if ( stProject.szGlo[0] != '\0' ) {
  2603. _fullpath( gProj.szGlo,
  2604. stProject.szGlo,
  2605. sizeof( gProj.szGlo));
  2606. }
  2607. gfReplace = IsDlgButtonChecked( hDlg, IDC_REPLACE);
  2608. EndDialog( hDlg, TRUE);
  2609. return ( TRUE);
  2610. } else {
  2611. break;
  2612. }
  2613. } // END case ID_OK:
  2614. case IDCANCEL:
  2615. CopyMemory( &gProj, &OldProj, sizeof( PROJDATA));
  2616. EndDialog( hDlg, FALSE);
  2617. return ( TRUE);
  2618. } // END switch ( GET_WM_COMMAND_ID( wParam, lParam) )
  2619. break;
  2620. } // END switch ( wMsg )
  2621. return ( FALSE);
  2622. }
  2623. /**
  2624. * Function: ViewDlgProc
  2625. * Procedure for the View project dialog window.
  2626. *
  2627. * Arguments:
  2628. *
  2629. * Returns: NA.
  2630. *
  2631. * Errors Codes:
  2632. * TRUE, carry out edit, and update token list box.
  2633. * FALSE, cancel edit.
  2634. *
  2635. * History:
  2636. **/
  2637. INT_PTR CALLBACK ViewDlgProc( HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  2638. {
  2639. static int iLastBox = IDD_MPJ;
  2640. switch (wMsg) {
  2641. case WM_INITDIALOG:
  2642. {
  2643. LPTSTR pszLangName = NULL;
  2644. if ( (pszLangName = GetLangName( (WORD)(PRIMARYLANGID( gMstr.wLanguageID)),
  2645. (WORD)(SUBLANGID( gMstr.wLanguageID)))) == NULL ) {
  2646. sprintf( szDHW, "Unknown LANGID %#06hx", gMstr.wLanguageID);
  2647. SetDlgItemTextA( hDlg, IDD_MSTR_LANG_NAME, szDHW);
  2648. } else {
  2649. SetDlgItemText( hDlg, IDD_MSTR_LANG_NAME, pszLangName);
  2650. }
  2651. if ( (pszLangName = GetLangName( (WORD)(PRIMARYLANGID( gProj.wLanguageID)),
  2652. (WORD)(SUBLANGID( gProj.wLanguageID)))) == NULL ) {
  2653. sprintf( szDHW, "Unknown LANGID %#06hx", gProj.wLanguageID);
  2654. SetDlgItemTextA( hDlg, IDD_PROJ_LANG_NAME, szDHW);
  2655. } else {
  2656. SetDlgItemText( hDlg, IDD_PROJ_LANG_NAME, pszLangName);
  2657. }
  2658. SetDlgItemTextA( hDlg, IDD_VIEW_SOURCERES, gMstr.szSrc);
  2659. SetDlgItemTextA( hDlg, IDD_VIEW_MTK, gMstr.szMtk);
  2660. SetDlgItemTextA( hDlg, IDD_VIEW_RDFS, gMstr.szRdfs);
  2661. SetDlgItemTextA( hDlg, IDD_VIEW_MPJ, gProj.szMpj);
  2662. SetDlgItemTextA( hDlg, IDD_VIEW_TOK, gProj.szTok);
  2663. SetDlgItemTextA( hDlg, IDD_VIEW_TARGETRES, gProj.szBld);
  2664. SetDlgItemTextA( hDlg, IDD_VIEW_GLOSSTRANS, gProj.szGlo);
  2665. if ( gProj.uCodePage == CP_ACP )
  2666. gProj.uCodePage = GetACP();
  2667. else if ( gProj.uCodePage == CP_OEMCP )
  2668. gProj.uCodePage = GetOEMCP();
  2669. SetDlgItemInt( hDlg, IDD_PROJ_TOK_CP, gProj.uCodePage, FALSE);
  2670. LoadString( hInst,
  2671. gfReplace ? IDS_WILLREPLACE : IDS_WILLAPPEND,
  2672. (LPTSTR)szDHW,
  2673. TCHARSIN( DHWSIZE));
  2674. SetDlgItemText( hDlg, IDC_APPENDREPLACE, (LPTSTR)szDHW);
  2675. return TRUE;
  2676. }
  2677. case WM_COMMAND:
  2678. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  2679. case IDOK:
  2680. EndDialog(hDlg, TRUE);
  2681. return TRUE;
  2682. }
  2683. }
  2684. return FALSE;
  2685. }
  2686. /**
  2687. * Function:
  2688. *
  2689. * Arguments:
  2690. *
  2691. * Returns:
  2692. *
  2693. * Errors Codes:
  2694. *
  2695. * History:
  2696. **/
  2697. static void DrawLBItem(LPDRAWITEMSTRUCT lpdis)
  2698. {
  2699. LPRECT lprc = (LPRECT) &(lpdis->rcItem);
  2700. DWORD rgbOldText = 0;
  2701. DWORD rgbOldBack = 0;
  2702. HBRUSH hBrush;
  2703. static DWORD rgbHighlightText;
  2704. static DWORD rgbHighlightBack;
  2705. static HBRUSH hBrushHilite = NULL;
  2706. static HBRUSH hBrushNormal = NULL;
  2707. static DWORD rgbDirtyText;
  2708. static DWORD rgbBackColor;
  2709. static DWORD rgbCleanText;
  2710. static DWORD rgbReadOnlyText;
  2711. TCHAR *szToken;
  2712. TOKEN tok;
  2713. LPTSTR lpstrToken;
  2714. LPTOKDATA lpTokData;
  2715. if (lpdis->itemAction & ODA_FOCUS) {
  2716. DrawFocusRect(lpdis->hDC, (CONST RECT *)lprc);
  2717. } else {
  2718. HANDLE hMem = (HANDLE)SendMessage( lpdis->hwndItem,
  2719. LB_GETITEMDATA,
  2720. (WPARAM)lpdis->itemID,
  2721. (LPARAM)0);
  2722. lpTokData = (LPTOKDATA)GlobalLock( hMem );
  2723. lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken );
  2724. szToken = (TCHAR *)FALLOC( MEMSIZE( lstrlen( lpstrToken) + 1));
  2725. lstrcpy( szToken, lpstrToken);
  2726. GlobalUnlock( lpTokData->hToken );
  2727. GlobalUnlock( hMem);
  2728. ParseBufToTok(szToken, &tok);
  2729. RLFREE( szToken);
  2730. if (lpdis->itemState & ODS_SELECTED) {
  2731. if (!hBrushHilite) {
  2732. rgbHighlightText = GetSysColor(COLOR_HIGHLIGHTTEXT);
  2733. rgbHighlightBack = GetSysColor(COLOR_HIGHLIGHT);
  2734. hBrushHilite = CreateSolidBrush(rgbHighlightBack);
  2735. }
  2736. GenStatusLine(&tok);
  2737. rgbOldText = SetTextColor(lpdis->hDC, rgbHighlightText);
  2738. rgbOldBack = SetBkColor(lpdis->hDC, rgbHighlightBack);
  2739. hBrush = hBrushHilite;
  2740. } else {
  2741. if (!hBrushNormal) {
  2742. rgbDirtyText = RGB(255, 0, 0);
  2743. rgbBackColor = RGB(192, 192, 192);
  2744. rgbCleanText = RGB(0, 0, 0);
  2745. rgbReadOnlyText = RGB(127, 127, 127);
  2746. hBrushNormal = CreateSolidBrush(rgbBackColor);
  2747. }
  2748. if (tok.wReserved & ST_READONLY) {
  2749. rgbOldText = SetTextColor(lpdis->hDC, rgbReadOnlyText);
  2750. } else {
  2751. if (tok.wReserved & ST_DIRTY) {
  2752. rgbOldText = SetTextColor(lpdis->hDC, rgbDirtyText);
  2753. } else {
  2754. rgbOldText = SetTextColor(lpdis->hDC, rgbCleanText);
  2755. }
  2756. }
  2757. rgbOldBack = SetBkColor(lpdis->hDC, rgbBackColor);
  2758. hBrush = hBrushNormal;
  2759. }
  2760. FillRect(lpdis->hDC, (CONST RECT *)lprc, hBrush);
  2761. DrawText(lpdis->hDC,
  2762. tok.szText,
  2763. STRINGSIZE(lstrlen(tok.szText)),
  2764. lprc,
  2765. DT_LEFT|DT_NOPREFIX);
  2766. RLFREE( tok.szText);
  2767. if (rgbOldText) {
  2768. SetTextColor(lpdis->hDC, rgbOldText);
  2769. }
  2770. if (rgbOldBack) {
  2771. SetBkColor(lpdis->hDC, rgbOldBack);
  2772. }
  2773. if (lpdis->itemState & ODS_FOCUS) {
  2774. DrawFocusRect(lpdis->hDC, (CONST RECT *)lprc);
  2775. }
  2776. }
  2777. }
  2778. /**********************************************************************
  2779. *FUNCTION: SaveTokList(HWND, FILE *fpTokFile) *
  2780. * *
  2781. *PURPOSE: Save current Token List *
  2782. * *
  2783. *COMMENTS: *
  2784. * *
  2785. *This saves the current contents of the Token List, and changes *
  2786. *fTokChanges to indicate that the list has not been changed since the *
  2787. *last save. *
  2788. **********************************************************************/
  2789. static BOOL SaveTokList(HWND hWnd, FILE *fpTokFile)
  2790. {
  2791. HCURSOR hSaveCursor;
  2792. BOOL bSuccess = TRUE;
  2793. int IOStatus;
  2794. UINT cTokens;
  2795. UINT cCurrentTok = 0;
  2796. CHAR *szTokBuf = NULL;
  2797. LPTSTR lpstrToken = NULL;
  2798. HGLOBAL hMem = NULL;
  2799. LPTOKDATA lpTokData;
  2800. // Set the cursor to an hourglass during the file transfer
  2801. hSaveCursor = SetCursor(hHourGlass);
  2802. // Find number of tokens in the list
  2803. cTokens = (UINT)SendMessage( hListWnd, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
  2804. if ( cTokens != LB_ERR ) {
  2805. for (cCurrentTok = 0; bSuccess && (cCurrentTok < cTokens); cCurrentTok++) {
  2806. int nLen1 = 0;
  2807. int nLen2 = 0;
  2808. // Get each token from list
  2809. hMem = (HGLOBAL)SendMessage( hListWnd,
  2810. LB_GETITEMDATA,
  2811. (WPARAM)cCurrentTok,
  2812. (LPARAM)0);
  2813. if ( ! (lpTokData = (LPTOKDATA)GlobalLock(hMem)) ) {
  2814. continue;
  2815. }
  2816. if ( (lpstrToken = (LPTSTR)GlobalLock( lpTokData->hToken)) ) {
  2817. szTokBuf = (CHAR *)FALLOC( (nLen2 = MEMSIZE( (nLen1 = lstrlen(lpstrToken)+1))));
  2818. #ifdef UNICODE
  2819. _WCSTOMBS( szTokBuf, lpstrToken, nLen2, nLen1);
  2820. #else
  2821. lstrcpy(szTokBuf, lpstrToken);
  2822. #endif
  2823. GlobalUnlock( lpTokData->hToken );
  2824. GlobalUnlock( hMem);
  2825. IOStatus = fprintf(fpTokFile, "%s\n", szTokBuf);
  2826. if ( IOStatus != (int) strlen(szTokBuf) + 1 ) {
  2827. TCHAR szTmpBuf[256];
  2828. LoadString( hInst,
  2829. IDS_FILESAVEERR,
  2830. szTmpBuf,
  2831. TCHARSIN( sizeof(szTmpBuf)));
  2832. MessageBox( hWnd,
  2833. szTmpBuf,
  2834. tszAppName,
  2835. MB_OK | MB_ICONHAND);
  2836. bSuccess = FALSE;
  2837. }
  2838. RLFREE( szTokBuf);
  2839. }
  2840. }
  2841. }
  2842. // restore cursor
  2843. SetCursor(hSaveCursor);
  2844. return (bSuccess);
  2845. }
  2846. /**
  2847. * Function: CleanDeltaList
  2848. * frees the pTokenDeltaInfo list
  2849. */
  2850. static void CleanDeltaList(void)
  2851. {
  2852. TOKENDELTAINFO FAR *pTokNode;
  2853. while (pTokNode = pTokenDeltaInfo) {
  2854. pTokenDeltaInfo = pTokNode->pNextTokenDelta;
  2855. RLFREE( pTokNode->DeltaToken.szText);
  2856. RLFREE( pTokNode);
  2857. }
  2858. }
  2859. /*
  2860. * About -- message processor for about box
  2861. *
  2862. */
  2863. //#ifdef RLWIN32
  2864. //
  2865. //BOOL CALLBACK About(
  2866. //
  2867. //HWND hDlg,
  2868. //UINT message,
  2869. //WPARAM wParam,
  2870. //LPARAM lParam)
  2871. //
  2872. //#else
  2873. //
  2874. INT_PTR CALLBACK About(
  2875. HWND hDlg,
  2876. UINT message,
  2877. WPARAM wParam,
  2878. LPARAM lParam)
  2879. //
  2880. //#endif
  2881. {
  2882. switch ( message ) {
  2883. case WM_INITDIALOG:
  2884. {
  2885. WORD wRC = SUCCESS;
  2886. CHAR szModName[ MAXFILENAME];
  2887. GetModuleFileNameA( hInst, szModName, sizeof( szModName));
  2888. if ( (wRC = GetCopyright( szModName,
  2889. szDHW,
  2890. DHWSIZE)) == SUCCESS ) {
  2891. SetDlgItemTextA( hDlg, IDC_COPYRIGHT, szDHW);
  2892. } else {
  2893. ShowErr( wRC, NULL, NULL);
  2894. }
  2895. }
  2896. break;
  2897. case WM_COMMAND:
  2898. if ((wParam == IDOK) || (wParam == IDCANCEL)) {
  2899. EndDialog(hDlg, TRUE);
  2900. }
  2901. break;
  2902. default:
  2903. return ( FALSE);
  2904. }
  2905. return ( TRUE);
  2906. }
  2907. //...................................................................
  2908. int RLMessageBoxA(
  2909. LPCSTR pszMsgText)
  2910. {
  2911. return ( MessageBoxA( NULL, pszMsgText, szAppName, MB_ICONHAND|MB_OK));
  2912. }
  2913. //...................................................................
  2914. void Usage()
  2915. {
  2916. return;
  2917. }
  2918. //...................................................................
  2919. void DoExit( int nErrCode)
  2920. {
  2921. ExitProcess( (UINT)nErrCode);
  2922. }
  2923. //...................................................................
  2924. static void SetNames( HWND hDlg, int iLastBox, LPSTR szNewFile)
  2925. {
  2926. static CHAR szDrive[ _MAX_DRIVE] = "";
  2927. static CHAR szDir[ _MAX_DIR] = "";
  2928. static CHAR szName[ _MAX_FNAME] = "";
  2929. static CHAR szExt[ _MAX_EXT] = "";
  2930. static CHAR szOldFileName[ MAXFILENAME];
  2931. if ( iLastBox == IDD_MPJ ) {
  2932. lstrcpyA( gProj.szMpj, szNewFile);
  2933. if ( ! fEditing && GetMasterProjectData( gProj.szMpj,
  2934. NULL,
  2935. NULL,
  2936. FALSE) == SUCCESS ) {
  2937. // Suggest a name for the target file
  2938. GetDlgItemTextA( hDlg, IDD_BUILTRES, szOldFileName, MAXFILENAME);
  2939. if ( szOldFileName[0] == '\0' || szOldFileName[0] == '.' ) {
  2940. _splitpath( gProj.szPRJ, szDrive, szDir, szName, szExt);
  2941. sprintf( gProj.szBld, "%s%s", szDrive, szDir);
  2942. _splitpath( gMstr.szSrc, szDrive, szDir, szName, szExt);
  2943. sprintf( &gProj.szBld[ lstrlenA( gProj.szBld)],
  2944. "%s%s",
  2945. szName,
  2946. szExt);
  2947. SetDlgItemTextA( hDlg, IDD_BUILTRES, gProj.szBld);
  2948. }
  2949. } else {
  2950. return;
  2951. }
  2952. }
  2953. if ( iLastBox == IDD_BUILTRES ) {
  2954. lstrcpyA( gProj.szBld, szNewFile);
  2955. }
  2956. if ( ! fEditing && (iLastBox == IDD_MPJ || iLastBox == IDD_BUILTRES) ) {
  2957. // Suggest a name for the project token file
  2958. GetDlgItemTextA( hDlg, IDD_TOK, szOldFileName, MAXFILENAME);
  2959. if ( szOldFileName[0] == '\0' || szOldFileName[0] == '.' ) {
  2960. _splitpath( gProj.szPRJ, szDrive, szDir, szName, szExt);
  2961. sprintf( gProj.szTok, "%s%s%s.%s", szDrive, szDir, szName, "TOK");
  2962. SetDlgItemTextA( hDlg, IDD_TOK, gProj.szTok);
  2963. }
  2964. // Suggest a name for the glossary file
  2965. GetDlgItemTextA( hDlg, IDD_GLOSS, szOldFileName, MAXFILENAME);
  2966. if ( szOldFileName[0] == '\0' || szOldFileName[0] == '.' ) {
  2967. _splitpath( gProj.szPRJ, szDrive, szDir, szName, szExt);
  2968. sprintf( gProj.szGlo, "%s%s%s.%s", szDrive, szDir, szName, "TXT");
  2969. SetDlgItemTextA( hDlg, IDD_GLOSS, gProj.szGlo);
  2970. }
  2971. }
  2972. if ( iLastBox == IDD_TOK ) {
  2973. lstrcpyA( gProj.szTok, szNewFile);
  2974. }
  2975. if ( iLastBox == IDD_GLOSS ) {
  2976. lstrcpyA( gProj.szGlo, szNewFile);
  2977. }
  2978. }