Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2645 lines
70 KiB

  1. /****************************************************************************
  2. *
  3. * Microsoft Confidential
  4. * Copyright (c) Microsoft Corporation 1994
  5. * All rights reserved
  6. *
  7. * This module handles the File Association UI
  8. *
  9. ***************************************************************************/
  10. #include "inetcplp.h"
  11. #include "mluisupp.h"
  12. #include <unistd.h>
  13. // For definition of FTA_OpenIsSafe
  14. // the file class's open verb may be safely invoked for downloaded files
  15. #include "../inc/filetype.h"
  16. // Macros required for default button processing
  17. #define REMOVE_DEF_BORDER(hDlg, cntrl ) \
  18. SendMessage( hDlg, DM_SETDEFID, -1, 0 ); \
  19. SendDlgItemMessage( hDlg, cntrl, BM_SETSTYLE, BS_PUSHBUTTON, TRUE ); \
  20. #define SET_DEF_BORDER(hDlg, cntrl ) \
  21. SendMessage( hDlg, DM_SETDEFID, cntrl, 0 ); \
  22. SendDlgItemMessage( hDlg, cntrl, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE ); \
  23. // Editing modes
  24. #define NORMAL 0x00
  25. #define ADDING 0x01
  26. #define UPDATING 0x02
  27. // Association status
  28. #define NEW 0x01
  29. #define UPD 0x02
  30. #define UNM 0x03
  31. #define LocalRealloc(a, b) LocalReAlloc(a, b, LMEM_MOVEABLE)
  32. static TCHAR g_szDefaultIcon[] = TEXT("shell32.dll,3");
  33. static TCHAR g_szIEUnix[] = TEXT("IEUNIX");
  34. static TCHAR g_szIEUnixEntry[] = TEXT("IEUNIX Specific entry");
  35. static TCHAR g_szEditFlags[] = TEXT("EditFlags");
  36. static TCHAR g_szDocClass[] = TEXT("DocClass");
  37. static TCHAR g_szMimeKey[] = TEXT("MIME\\Database\\Content Type");
  38. static TCHAR g_szCmndSubKey[] = TEXT("Shell\\Open\\Command");
  39. static TCHAR g_szPolicySubKey[] = REGSTR_PATH_INETCPL_RESTRICTIONS;
  40. static TCHAR g_szPolicyName[] = TEXT("Mappings");
  41. int SwitchToAddMode( HWND hDlg );
  42. int SwitchToNrmlMode( HWND hDlg );
  43. BOOL CALLBACK EnterAssocDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  44. BOOL IsAssocEnabled()
  45. {
  46. HKEY hKey = NULL;
  47. LONG lResult = RegOpenKey(HKEY_CURRENT_USER, g_szPolicySubKey, &hKey);
  48. if( lResult == ERROR_SUCCESS )
  49. {
  50. // Get then size first
  51. DWORD dwPolicy, dwType, dwSize = sizeof(DWORD);
  52. if (RegQueryValueEx( hKey, g_szPolicyName, NULL, &dwType, (LPBYTE)&dwPolicy, &dwSize ) == ERROR_SUCCESS )
  53. {
  54. if( dwPolicy )
  55. {
  56. RegCloseKey( hKey );
  57. return FALSE;
  58. }
  59. }
  60. RegCloseKey( hKey );
  61. }
  62. return TRUE;
  63. }
  64. /*
  65. ** AddStringToComboBox()
  66. **
  67. ** Adds a string to a combo box. Does not check to see if the string has
  68. ** already been added.
  69. **
  70. ** Arguments:
  71. **
  72. ** Returns:
  73. **
  74. ** Side Effects: none
  75. */
  76. BOOL AddStringToComboBox(HWND hwndComboBox, LPCTSTR pcsz)
  77. {
  78. BOOL bResult;
  79. LONG lAddStringResult;
  80. lAddStringResult = SendMessage(hwndComboBox, CB_ADDSTRING, 0, (LPARAM)pcsz);
  81. bResult = (lAddStringResult != CB_ERR &&
  82. lAddStringResult != CB_ERRSPACE);
  83. return(bResult);
  84. }
  85. /*
  86. ** SafeAddStringToComboBox()
  87. **
  88. ** Adds a string to a combo box. Checks to see if the string has already been
  89. ** added.
  90. **
  91. ** Arguments:
  92. **
  93. ** Returns:
  94. **
  95. ** Side Effects: none
  96. */
  97. BOOL SafeAddStringToComboBox(HWND hwndComboBox, LPCTSTR pcsz)
  98. {
  99. BOOL bResult;
  100. if (SendMessage(hwndComboBox, CB_FINDSTRINGEXACT, 0, (LPARAM)pcsz) == CB_ERR)
  101. bResult = AddStringToComboBox(hwndComboBox, pcsz);
  102. else
  103. {
  104. bResult = TRUE;
  105. }
  106. return(bResult);
  107. }
  108. typedef struct ASSOCIATION
  109. {
  110. HWND hDlg;
  111. int mode;
  112. BOOL fInternalChange;
  113. BOOL fChanged;
  114. } ASSOCINFO, * LPASSOCTABINFO;
  115. typedef struct ENTERASSOC
  116. {
  117. LPASSOCTABINFO pgti;
  118. TCHAR *pszAssoc;
  119. } ENTERASSOC, * LPENTERASSOC;
  120. #define PGTI_FROM_HDLG( hDlg ) \
  121. ((LPASSOCTABINFO)GetWindowLong(hDlg, DWL_USER)) \
  122. #define PGTI_FROM_PARENT_HDLG( hDlg ) \
  123. ((LPASSOCTABINFO)GetWindowLong(GetParent(hDlg), DWL_USER)) \
  124. class CMime
  125. {
  126. public:
  127. TCHAR * m_mime;
  128. TCHAR * m_exts;
  129. CMime( TCHAR * name );
  130. ~CMime();
  131. // Operations defined for Asscociation
  132. };
  133. CMime::CMime( TCHAR * name )
  134. {
  135. m_mime = (TCHAR *) LocalAlloc( LPTR, (lstrlen(name) + 1)*sizeof(TCHAR) );
  136. StrCpy( m_mime, name );
  137. m_exts = NULL;
  138. }
  139. CMime::~CMime()
  140. {
  141. if( m_mime ) LocalFree( m_mime );
  142. if( m_exts ) LocalFree( m_exts );
  143. }
  144. HDPA mimeList = NULL;
  145. BOOL FreeExtensions( HDPA dpa )
  146. {
  147. if( dpa == (HDPA)NULL ) return FALSE;
  148. int count = DPA_GetPtrCount( dpa );
  149. for(int i=0; i<count; i++ )
  150. {
  151. LPTSTR ptr = (LPTSTR)DPA_FastGetPtr( dpa, i );
  152. if(ptr) LocalFree(ptr);
  153. }
  154. DPA_Destroy( dpa );
  155. return TRUE;
  156. }
  157. class CAssoc
  158. {
  159. public:
  160. TCHAR * m_type; // File Type class
  161. TCHAR * m_desc; // File TYpe Description
  162. TCHAR * m_mime; // File Type Mime
  163. TCHAR * m_cmnd; // Shell/open/command
  164. BOOL m_safe; // protected or not
  165. DWORD m_edit; // EditFlags value
  166. UINT m_stat; // Status
  167. HDPA m_exts; // Dynamic array for extensions
  168. CAssoc( TCHAR * name );
  169. ~CAssoc();
  170. // Operations defined for Asscociation
  171. Load();
  172. Save();
  173. Print();
  174. Delete();
  175. // Some helper functions
  176. HDPA GetExtsOfAssoc( );
  177. LPTSTR GetDescOfAssoc( );
  178. LPTSTR GetMimeOfAssoc( );
  179. LPTSTR GetCmndOfAssoc( );
  180. DWORD GetEditOfAssoc( );
  181. };
  182. // Some Helper Function Prototypes
  183. BOOL FAR PASCAL InitAssocDialog(HWND hDlg, CAssoc * current = NULL);
  184. void HandleSelChange( LPASSOCTABINFO pgti , BOOL bChangeAppl = TRUE);
  185. TCHAR * EatSpaces( TCHAR * str );
  186. TCHAR * ChopSpaces( TCHAR * str );
  187. TCHAR * DuplicateString( TCHAR * str );
  188. CAssoc * GetCurrentAssoc( HWND hDlg );
  189. // Member function definitions for CAssoc.
  190. CAssoc::CAssoc( TCHAR * name )
  191. {
  192. m_type = (TCHAR *) LocalAlloc( LPTR, (lstrlen(name) + 1)*sizeof(TCHAR) );
  193. StrCpy( m_type, name );
  194. m_desc = NULL;
  195. m_mime = NULL;
  196. m_cmnd = NULL;
  197. m_stat = NEW ;
  198. m_safe = TRUE; // Internal Assoc, Dont mess with this
  199. m_exts = NULL;
  200. m_edit = 0;
  201. }
  202. CAssoc::~CAssoc()
  203. {
  204. if( m_type ) LocalFree( m_type );
  205. if( m_desc ) LocalFree( m_desc );
  206. if( m_mime ) LocalFree( m_mime );
  207. if( m_cmnd ) LocalFree( m_cmnd );
  208. if( m_exts ) FreeExtensions( m_exts );
  209. }
  210. CAssoc::Load()
  211. {
  212. if(m_type)
  213. {
  214. TCHAR * ptr = NULL;
  215. m_exts = GetExtsOfAssoc();
  216. m_edit = GetEditOfAssoc();
  217. if ((ptr = GetDescOfAssoc( )) != NULL)
  218. {
  219. m_desc = (TCHAR *)LocalAlloc( LPTR, (lstrlen(ptr) + 1)*sizeof(TCHAR));
  220. StrCpy( m_desc, ptr );
  221. ptr = NULL;
  222. }
  223. else
  224. // Each type must have a description. (Required)
  225. return FALSE;
  226. if ((ptr = GetMimeOfAssoc()) != NULL)
  227. {
  228. m_mime = (TCHAR *)LocalAlloc( LPTR, (lstrlen(ptr) + 1)*sizeof(TCHAR));
  229. StrCpy( m_mime, ptr );
  230. ptr = NULL;
  231. }
  232. if ((ptr = GetCmndOfAssoc()) != NULL)
  233. {
  234. m_cmnd = (TCHAR *)LocalAlloc( LPTR, (lstrlen(ptr) + 1)*sizeof(TCHAR));
  235. StrCpy( m_cmnd, ptr );
  236. ptr = NULL;
  237. }
  238. m_stat = UNM;
  239. m_safe = FALSE;
  240. }
  241. return TRUE;
  242. }
  243. CAssoc::Save()
  244. {
  245. if( m_safe ) return TRUE;
  246. if( m_stat != UPD ) return TRUE;
  247. // Create a Key for DocType in HKEY_CLASSES_ROOT
  248. // [doctype
  249. // (--reg-val-- "Description")
  250. // [defaulticon
  251. // (reg-val "shell32.dll,3")
  252. // ]
  253. // [shell
  254. // [open
  255. // [command
  256. // (--reg-val-- "Command" )
  257. // ]
  258. // ]
  259. // ]
  260. // ]
  261. HKEY hKey1, hKey2, hKey3, hKey4;
  262. LONG lResult = RegOpenKeyEx(
  263. HKEY_CLASSES_ROOT,
  264. m_type,
  265. 0,
  266. KEY_QUERY_VALUE|KEY_WRITE,
  267. &hKey1);
  268. if (lResult != ERROR_SUCCESS)
  269. {
  270. lResult = RegCreateKey(
  271. HKEY_CLASSES_ROOT,
  272. m_type,
  273. &hKey1);
  274. }
  275. if (lResult == ERROR_SUCCESS)
  276. {
  277. DWORD dwType = REG_SZ;
  278. DWORD dwLen = (lstrlen(m_desc)+1)*sizeof(TCHAR);
  279. RegSetValue( hKey1, NULL, dwType, m_desc, dwLen );
  280. // Add IEUNIX tag to this entry
  281. dwLen = (lstrlen(g_szIEUnixEntry)+1)*sizeof(TCHAR);
  282. RegSetValueEx( hKey1, g_szIEUnix, 0,
  283. dwType, (LPBYTE)g_szIEUnixEntry, dwLen );
  284. // Add Edit flags to this entry
  285. DWORD value = m_edit;
  286. RegSetValueEx( hKey1, g_szEditFlags, 0,
  287. REG_DWORD, (LPBYTE)(&value), sizeof(DWORD) );
  288. HKEY hKey2;
  289. RegDeleteKey( hKey1, TEXT("defaulticon" ) );
  290. lResult = RegCreateKey(
  291. hKey1,
  292. TEXT("defaulticon"),
  293. &hKey2);
  294. if(lResult == ERROR_SUCCESS)
  295. {
  296. DWORD dwType = REG_SZ;
  297. DWORD dwLen = (lstrlen(g_szDefaultIcon)+1)*sizeof(TCHAR);
  298. RegSetValue( hKey2, NULL, dwType, g_szDefaultIcon, dwLen );
  299. RegCloseKey( hKey2);
  300. }
  301. RegDeleteKey( hKey1, g_szCmndSubKey );
  302. lResult = RegOpenKeyEx(
  303. hKey1,
  304. TEXT("shell"),
  305. 0,
  306. KEY_QUERY_VALUE| KEY_WRITE,
  307. &hKey2);
  308. if(lResult != ERROR_SUCCESS)
  309. {
  310. lResult = RegCreateKey(
  311. hKey1,
  312. TEXT("shell"),
  313. &hKey2);
  314. }
  315. if(lResult == ERROR_SUCCESS)
  316. {
  317. lResult = RegOpenKeyEx(
  318. hKey2,
  319. TEXT("open"),
  320. 0,
  321. KEY_QUERY_VALUE| KEY_WRITE,
  322. &hKey3);
  323. if( lResult != ERROR_SUCCESS )
  324. {
  325. lResult = RegCreateKey(
  326. hKey2,
  327. TEXT("open"),
  328. &hKey3);
  329. }
  330. if( lResult == ERROR_SUCCESS )
  331. {
  332. lResult = RegOpenKeyEx(
  333. hKey3,
  334. TEXT("command"),
  335. 0,
  336. KEY_QUERY_VALUE| KEY_WRITE,
  337. &hKey4);
  338. if( lResult != ERROR_SUCCESS )
  339. {
  340. lResult = RegCreateKey(
  341. hKey3,
  342. TEXT("command"),
  343. &hKey4);
  344. }
  345. if( lResult == ERROR_SUCCESS )
  346. {
  347. DWORD dwType = REG_SZ;
  348. DWORD dwLen = (lstrlen(m_cmnd)+1)*sizeof(TCHAR);
  349. RegSetValue( hKey4, NULL, dwType, m_cmnd, dwLen );
  350. RegCloseKey( hKey4);
  351. }
  352. RegCloseKey(hKey3);
  353. }
  354. RegCloseKey(hKey2);
  355. }
  356. RegCloseKey(hKey1);
  357. }
  358. // Add mime type to the mimetype data base if it doesn't exist
  359. LPTSTR mimeKey = (LPTSTR)LocalAlloc( LPTR, (lstrlen(m_mime)+lstrlen(g_szMimeKey) + 3)*sizeof(TCHAR));
  360. if(mimeKey && m_mime)
  361. {
  362. StrCpy( mimeKey, g_szMimeKey );
  363. StrCat( mimeKey, TEXT("\\") );
  364. StrCat( mimeKey, m_mime );
  365. lResult = RegOpenKeyEx(
  366. HKEY_CLASSES_ROOT,
  367. mimeKey,
  368. 0,
  369. KEY_QUERY_VALUE| KEY_WRITE,
  370. &hKey1);
  371. if(lResult != ERROR_SUCCESS)
  372. {
  373. lResult = RegCreateKey(
  374. HKEY_CLASSES_ROOT,
  375. mimeKey,
  376. &hKey1);
  377. if(lResult == ERROR_SUCCESS && m_exts)
  378. {
  379. int count = DPA_GetPtrCount( m_exts );
  380. if(count > 0 )
  381. {
  382. LPTSTR firstExt = (LPTSTR)DPA_FastGetPtr( m_exts, 0 );
  383. RegSetValueEx( hKey1, TEXT("extension"), NULL,
  384. REG_SZ, (LPBYTE)firstExt, (lstrlen(firstExt)+1)*sizeof(TCHAR) );
  385. }
  386. RegCloseKey( hKey1 );
  387. }
  388. }
  389. else
  390. {
  391. RegCloseKey( hKey1 );
  392. }
  393. }
  394. if(mimeKey)
  395. LocalFree(mimeKey);
  396. // Add extention/document type association
  397. // [.ext
  398. // (--reg-val-- "Application")
  399. // (content.type "mimetype" )
  400. // ]
  401. // First remove all the extensions for the current assoc from the
  402. // registry.
  403. HDPA prevExts = GetExtsOfAssoc();
  404. if( prevExts )
  405. {
  406. int extCount = DPA_GetPtrCount( prevExts );
  407. for( int i=0; i< extCount; i++ )
  408. RegDeleteKey( HKEY_CLASSES_ROOT, (LPTSTR)DPA_FastGetPtr( prevExts, i ) );
  409. FreeExtensions( prevExts );
  410. }
  411. if( m_exts )
  412. {
  413. int count = DPA_GetPtrCount( m_exts );
  414. for( int i=0; i<count; i++ )
  415. {
  416. LPTSTR ptr = (LPTSTR)DPA_FastGetPtr( m_exts, i );
  417. if( ptr && *ptr == TEXT('.') )
  418. {
  419. lResult = RegOpenKeyEx(
  420. HKEY_CLASSES_ROOT,
  421. ptr,
  422. 0,
  423. KEY_QUERY_VALUE| KEY_WRITE,
  424. &hKey1);
  425. if( lResult != ERROR_SUCCESS )
  426. {
  427. lResult = RegCreateKey(
  428. HKEY_CLASSES_ROOT,
  429. ptr,
  430. &hKey1);
  431. }
  432. if( lResult == ERROR_SUCCESS )
  433. {
  434. DWORD dwType = REG_SZ;
  435. DWORD dwLen = (lstrlen(m_type)+1)*sizeof(TCHAR);
  436. RegSetValue( hKey1, NULL, dwType, m_type, dwLen );
  437. EatSpaces(m_mime );
  438. dwLen = lstrlen(m_mime);
  439. if(m_mime && (dwLen=lstrlen(m_mime))>0)
  440. RegSetValueEx( hKey1, TEXT("Content Type"), 0,
  441. dwType, (LPBYTE)m_mime, (dwLen+1)*sizeof(TCHAR) );
  442. // Add IEUNIX tag to this entry
  443. dwLen = (lstrlen(g_szIEUnixEntry)+1)*sizeof(TCHAR);
  444. RegSetValueEx( hKey1, g_szIEUnix, 0,
  445. dwType, (LPBYTE)g_szIEUnixEntry, dwLen );
  446. RegCloseKey( hKey1);
  447. hKey1 = NULL;
  448. }
  449. }
  450. }
  451. }
  452. else
  453. return FALSE;
  454. return TRUE;
  455. }
  456. CAssoc::Delete()
  457. {
  458. HKEY hKey;
  459. // Don't touch the safe keys
  460. if( m_safe ) return FALSE;
  461. // Delete Application from HKEY_CLASSES_ROOT
  462. EatSpaces(m_type);
  463. if(m_type && *m_type)
  464. {
  465. // NT restrictions
  466. TCHAR * key = (TCHAR *)LocalAlloc(LPTR, (lstrlen(m_type) + 200)*sizeof(TCHAR) ) ;
  467. if(!key) return FALSE;
  468. StrCpy( key, m_type );
  469. StrCat( key, TEXT("\\defaulticon") );
  470. RegDeleteKey(HKEY_CLASSES_ROOT, key);
  471. StrCpy( key, m_type );
  472. StrCat( key, TEXT("\\") );
  473. StrCat( key, g_szCmndSubKey );
  474. RegDeleteKey(HKEY_CLASSES_ROOT, key);
  475. StrCpy( key, m_type );
  476. StrCat( key, TEXT("\\shell\\open") );
  477. RegDeleteKey(HKEY_CLASSES_ROOT, key);
  478. StrCpy( key, m_type );
  479. StrCat( key, TEXT("\\shell") );
  480. RegDeleteKey(HKEY_CLASSES_ROOT, key);
  481. RegDeleteKey(HKEY_CLASSES_ROOT, m_type);
  482. LocalFree( key );
  483. }
  484. else
  485. return FALSE;
  486. // Delete Extensions from HKEY_CLASSES_ROOT
  487. if( m_exts )
  488. {
  489. int count = DPA_GetPtrCount( m_exts );
  490. for( int i=0; i<count; i++ )
  491. {
  492. LPTSTR ptr = (LPTSTR)DPA_FastGetPtr( m_exts, i );
  493. if( ptr && *ptr == TEXT('.') )
  494. {
  495. RegDeleteKey(HKEY_CLASSES_ROOT, ptr);
  496. }
  497. }
  498. }
  499. else
  500. return FALSE;
  501. return TRUE;
  502. }
  503. CAssoc::Print()
  504. {
  505. #ifndef UNICODE
  506. if( m_type ) printf( m_type );
  507. printf(",");
  508. if( m_desc ) printf( m_desc );
  509. printf(",");
  510. if( m_mime ) printf( m_mime );
  511. printf(",");
  512. if( m_cmnd ) printf( m_cmnd );
  513. if( m_exts )
  514. {
  515. int count = DPA_GetPtrCount( m_exts );
  516. for( int i=0; i<count; i++ )
  517. {
  518. LPTSTR ptr = (LPTSTR)DPA_FastGetPtr( m_exts, i );
  519. if( ptr && *ptr == TEXT('.') )
  520. {
  521. printf("%s;", ptr );
  522. }
  523. }
  524. }
  525. printf("\n");
  526. #endif
  527. return TRUE;
  528. }
  529. HDPA CAssoc::GetExtsOfAssoc()
  530. {
  531. TCHAR buffer[MAX_PATH];
  532. DWORD index = 0;
  533. DWORD type = REG_SZ;
  534. long dwLen = MAX_PATH;
  535. DWORD dwLen2 = MAX_PATH;
  536. HDPA exts = DPA_Create(4);
  537. *buffer = TEXT('\0');
  538. if( !m_type ) return NULL;
  539. TCHAR * key = (TCHAR *)LocalAlloc( LPTR, (MAX_PATH+1)*sizeof(TCHAR) );
  540. TCHAR * value = (TCHAR *)LocalAlloc( LPTR, (MAX_PATH+1)*sizeof(TCHAR) );
  541. if( !key || !value ) goto EXIT;
  542. while( RegEnumKey( HKEY_CLASSES_ROOT, index, key, MAX_PATH ) != ERROR_NO_MORE_ITEMS )
  543. {
  544. if( *key == TEXT('.') )
  545. {
  546. HKEY hKey = NULL;
  547. LONG lResult = RegOpenKeyEx(
  548. HKEY_CLASSES_ROOT,
  549. key,
  550. 0,
  551. KEY_QUERY_VALUE,
  552. &hKey);
  553. if( lResult == ERROR_SUCCESS )
  554. {
  555. // Get then size first
  556. dwLen = (MAX_PATH+1)*sizeof(TCHAR);
  557. if (RegQueryValue( hKey, NULL, value, &dwLen )
  558. == ERROR_SUCCESS )
  559. {
  560. if( !StrCmpIC( value, m_type ) )
  561. {
  562. DPA_InsertPtr( exts, 0x7FFF, (LPVOID)DuplicateString(key) );
  563. }
  564. }
  565. RegCloseKey( hKey );
  566. }
  567. }
  568. index++;
  569. }
  570. EXIT:
  571. if( key )
  572. LocalFree( key );
  573. if( value)
  574. LocalFree( value );
  575. return exts;
  576. }
  577. LPTSTR CAssoc::GetDescOfAssoc()
  578. {
  579. HKEY hKey;
  580. static TCHAR buffer[MAX_PATH];
  581. DWORD type = REG_SZ;
  582. DWORD dwLen = sizeof(buffer);
  583. *buffer = TEXT('\0');
  584. if( !m_type ) return NULL;
  585. LONG lResult = RegOpenKeyEx(
  586. HKEY_CLASSES_ROOT,
  587. m_type,
  588. 0,
  589. KEY_QUERY_VALUE | KEY_READ,
  590. &hKey);
  591. if (lResult == ERROR_SUCCESS)
  592. {
  593. lResult = RegQueryValueEx(
  594. hKey,
  595. NULL,
  596. NULL,
  597. (LPDWORD) &type,
  598. (LPBYTE) buffer,
  599. (LPDWORD) &dwLen);
  600. RegCloseKey( hKey );
  601. if( lResult == ERROR_SUCCESS )
  602. {
  603. return buffer;
  604. }
  605. }
  606. return NULL;
  607. }
  608. DWORD CAssoc::GetEditOfAssoc()
  609. {
  610. HKEY hKey;
  611. DWORD buffer = 0;
  612. DWORD type = REG_DWORD;
  613. DWORD dwLen = sizeof(buffer);
  614. if( !m_type ) return NULL;
  615. LONG lResult = RegOpenKeyEx(
  616. HKEY_CLASSES_ROOT,
  617. m_type,
  618. 0,
  619. KEY_QUERY_VALUE | KEY_READ,
  620. &hKey);
  621. if (lResult == ERROR_SUCCESS)
  622. {
  623. lResult = RegQueryValueEx(
  624. hKey,
  625. g_szEditFlags,
  626. NULL,
  627. (LPDWORD) &type,
  628. (LPBYTE) &buffer,
  629. (LPDWORD) &dwLen);
  630. RegCloseKey( hKey );
  631. if( lResult == ERROR_SUCCESS )
  632. {
  633. return buffer;
  634. }
  635. }
  636. return 0;
  637. }
  638. LPTSTR CAssoc::GetMimeOfAssoc()
  639. {
  640. HKEY hKey;
  641. static TCHAR buffer[MAX_PATH];
  642. DWORD type = REG_SZ;
  643. DWORD dwLen = sizeof(buffer);
  644. *buffer = TEXT('\0');
  645. if( !m_type || !m_exts ) return NULL;
  646. int count = DPA_GetPtrCount( m_exts );
  647. for( int i=0; i< count; i++ )
  648. {
  649. LPTSTR str = (LPTSTR)DPA_FastGetPtr( m_exts, i );
  650. if( !str ) continue;
  651. LONG lResult = RegOpenKeyEx(
  652. HKEY_CLASSES_ROOT,
  653. str,
  654. 0,
  655. KEY_QUERY_VALUE | KEY_READ,
  656. &hKey);
  657. if (lResult == ERROR_SUCCESS)
  658. {
  659. lResult = RegQueryValueEx(
  660. hKey,
  661. TEXT("Content Type"),
  662. NULL,
  663. (LPDWORD) &type,
  664. (LPBYTE) buffer,
  665. (LPDWORD) &dwLen);
  666. RegCloseKey( hKey );
  667. if( lResult == ERROR_SUCCESS )
  668. {
  669. return buffer;
  670. }
  671. }
  672. }
  673. return NULL;
  674. }
  675. LPTSTR CAssoc::GetCmndOfAssoc()
  676. {
  677. HKEY hKey;
  678. static TCHAR buffer [MAX_PATH];
  679. TCHAR keyName[MAX_PATH+40];
  680. DWORD type = REG_SZ;
  681. DWORD dwLen = sizeof(buffer);
  682. *buffer = TEXT('\0');
  683. if( !m_type ) return NULL;
  684. StrCpy( keyName, m_type );
  685. StrCat( keyName, TEXT("\\") );
  686. StrCat( keyName, g_szCmndSubKey );
  687. LONG lResult = RegOpenKeyEx(
  688. HKEY_CLASSES_ROOT,
  689. keyName,
  690. 0,
  691. KEY_QUERY_VALUE | KEY_READ,
  692. &hKey);
  693. if (lResult == ERROR_SUCCESS)
  694. {
  695. lResult = RegQueryValueEx(
  696. hKey,
  697. NULL,
  698. NULL,
  699. (LPDWORD) &type,
  700. (LPBYTE) buffer,
  701. (LPDWORD) &dwLen);
  702. RegCloseKey( hKey );
  703. if( lResult == ERROR_SUCCESS )
  704. {
  705. return buffer;
  706. }
  707. }
  708. return NULL;
  709. }
  710. HDPA assocList = (HDPA)NULL;
  711. HDPA assocDelList = (HDPA)NULL;
  712. SetEditLimits(HWND hDlg )
  713. {
  714. SendMessage(GetDlgItem( hDlg, IDC_DOC_TYPE ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0);
  715. SendMessage(GetDlgItem( hDlg, IDC_DOC_MIME ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0);
  716. SendMessage(GetDlgItem( hDlg, IDC_DOC_EXTS ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0);
  717. SendMessage(GetDlgItem( hDlg, IDC_DOC_DESC ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0);
  718. SendMessage(GetDlgItem( hDlg, IDC_DOC_CMND ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0);
  719. return TRUE;
  720. }
  721. TCHAR *DuplicateString( TCHAR *orig )
  722. {
  723. TCHAR * newStr;
  724. if( !orig ) return NULL;
  725. newStr = (TCHAR *)LocalAlloc( LPTR, (lstrlen(orig) + 1)*sizeof(TCHAR));
  726. if(newStr) StrCpy( newStr, orig );
  727. return newStr;
  728. }
  729. TCHAR * EatSpaces( TCHAR * str )
  730. {
  731. if( !str ) return NULL;
  732. TCHAR *ptr = str, *tmpStr = DuplicateString( str );
  733. TCHAR *tmpPtr = tmpStr;
  734. while( *tmpStr )
  735. {
  736. if(*tmpStr == TEXT(' ') || *tmpStr == TEXT('\t') ||
  737. *tmpStr == TEXT('\n') || *tmpStr == TEXT('\r') ||
  738. // Remove special characters.
  739. (int)(*tmpStr) >= 127)
  740. tmpStr++;
  741. else
  742. *ptr++ = *tmpStr++;
  743. }
  744. *ptr = TEXT('\0');
  745. LocalFree( tmpPtr );
  746. return str;
  747. }
  748. TCHAR * ChopSpaces( TCHAR * str )
  749. {
  750. if( !str ) return NULL;
  751. TCHAR *ptr = str;
  752. while( *ptr &&
  753. (*ptr == TEXT(' ') || *ptr == TEXT('\t')) ||
  754. (*ptr == TEXT('\n') || *ptr == TEXT('\r'))
  755. ) ptr++;
  756. TCHAR *tmpStr = DuplicateString( ptr );
  757. TCHAR *tmpPtr = tmpStr + lstrlen(tmpStr);
  758. tmpPtr--;
  759. while( tmpPtr>= tmpStr &&
  760. (*tmpPtr == TEXT(' ') || *tmpPtr == TEXT('\t')) ||
  761. (*tmpPtr == TEXT('\n') || *tmpPtr == TEXT('\r'))
  762. ) tmpPtr--;
  763. tmpPtr++;
  764. *tmpPtr = TEXT('\0');
  765. StrCpy( str, tmpStr );
  766. LocalFree( tmpStr );
  767. return str;
  768. }
  769. BOOL FreeAssociations( )
  770. {
  771. if( assocList == (HDPA)NULL ) return FALSE;
  772. int assocCount = DPA_GetPtrCount( assocList );
  773. for(int i=0; i<assocCount; i++ )
  774. {
  775. CAssoc * ptr = (CAssoc *)DPA_FastGetPtr( assocList, i );
  776. if(ptr) delete ptr;
  777. }
  778. DPA_Destroy( assocList );
  779. assocList = (HDPA)NULL;
  780. return TRUE;
  781. }
  782. BOOL LoadAssociations( )
  783. {
  784. HKEY hKey;
  785. int index = 0;
  786. DWORD dwLen = MAX_PATH;
  787. if(assocList)
  788. FreeAssociations();
  789. if((assocList = DPA_Create(4)) == (HDPA)NULL )
  790. return FALSE;
  791. TCHAR * buffer = (TCHAR *)LocalAlloc( LPTR, (MAX_PATH+1)*sizeof(TCHAR) );
  792. TCHAR * tmpKey = (TCHAR *)LocalAlloc( LPTR, (MAX_PATH+MAX_PATH+2)*sizeof(TCHAR) );
  793. while( buffer && tmpKey )
  794. {
  795. dwLen = (MAX_PATH+sizeof(g_szCmndSubKey)+2)*sizeof(TCHAR);
  796. if( RegEnumKeyEx( HKEY_CLASSES_ROOT, index, buffer, &dwLen,
  797. NULL, NULL, NULL, NULL )
  798. == ERROR_NO_MORE_ITEMS ) break;
  799. {
  800. // Skip Extensions and *.
  801. if( *buffer == TEXT('.') || *buffer == TEXT('*'))
  802. {
  803. index++;
  804. continue;
  805. }
  806. CAssoc * ptr = NULL;
  807. StrCpy( tmpKey, buffer );
  808. StrCat( tmpKey, TEXT("\\"));
  809. StrCat( tmpKey, g_szCmndSubKey);
  810. LONG lResult = RegOpenKeyEx(
  811. HKEY_CLASSES_ROOT,
  812. tmpKey,
  813. 0,
  814. KEY_QUERY_VALUE | KEY_READ,
  815. &hKey);
  816. if( lResult == ERROR_SUCCESS )
  817. {
  818. ptr=new CAssoc(buffer);
  819. if( ptr->Load() == TRUE )
  820. DPA_InsertPtr( assocList, 0x7FFF, (LPVOID)ptr);
  821. else
  822. {
  823. delete ptr;
  824. ptr = NULL;
  825. }
  826. RegCloseKey( hKey );
  827. }
  828. // Check if this association needs to be protected.
  829. // - uses DDE
  830. // - has clsid
  831. // - has protected key.
  832. if(ptr)
  833. {
  834. StrCpy(tmpKey, buffer);
  835. StrCat(tmpKey, TEXT("\\shell\\open\\ddeexec") );
  836. // wnsprintf(tmpKey, ARRAYSIZE(tmpKey), TEXT("%s\\shell\\open\\ddeexec"), buffer);
  837. lResult = RegOpenKeyEx(
  838. HKEY_CLASSES_ROOT,
  839. tmpKey,
  840. 0,
  841. KEY_QUERY_VALUE | KEY_READ,
  842. &hKey);
  843. if( lResult == ERROR_SUCCESS )
  844. {
  845. ptr->m_safe = TRUE;
  846. RegCloseKey( hKey );
  847. goto Cont;
  848. }
  849. StrCpy(tmpKey, buffer);
  850. StrCat(tmpKey, TEXT("\\clsid") );
  851. //wnsprintf(tmpKey, ARRAYSIZE(tmpKey), TEXT("%s\\clsid"), buffer);
  852. lResult = RegOpenKeyEx(
  853. HKEY_CLASSES_ROOT,
  854. tmpKey,
  855. 0,
  856. KEY_QUERY_VALUE | KEY_READ,
  857. &hKey);
  858. if( lResult == ERROR_SUCCESS )
  859. {
  860. ptr->m_safe = TRUE;
  861. RegCloseKey( hKey );
  862. goto Cont;
  863. }
  864. StrCpy(tmpKey, buffer);
  865. StrCat(tmpKey, TEXT("\\protected") );
  866. // wnsprintf(tmpKey, ARRAYSIZE(tmpKey), TEXT("%s\\protected"), buffer);
  867. lResult = RegOpenKeyEx(
  868. HKEY_CLASSES_ROOT,
  869. tmpKey,
  870. 0,
  871. KEY_QUERY_VALUE | KEY_READ,
  872. &hKey);
  873. if( lResult == ERROR_SUCCESS )
  874. {
  875. ptr->m_safe = TRUE;
  876. RegCloseKey( hKey );
  877. }
  878. }
  879. Cont:
  880. index++;
  881. }
  882. }
  883. if( tmpKey ) LocalFree( tmpKey );
  884. if( buffer ) LocalFree( buffer );
  885. return TRUE;
  886. }
  887. BOOL FreeMimeTypes( )
  888. {
  889. if( mimeList == NULL ) return FALSE;
  890. int mimeCount = DPA_GetPtrCount( mimeList );
  891. for(int i=0; i<mimeCount; i++ )
  892. {
  893. CMime * ptr = (CMime *)DPA_FastGetPtr( mimeList, i );
  894. if(ptr) delete ptr;
  895. }
  896. DPA_Destroy( mimeList );
  897. mimeList = (HDPA)NULL;
  898. return TRUE;
  899. }
  900. BOOL LoadMimeTypes( )
  901. {
  902. HKEY hKeyMime, hKey;
  903. int index = 0;
  904. DWORD dwLen = MAX_PATH;
  905. if(mimeList) FreeMimeTypes();
  906. if((mimeList = DPA_Create(4)) == (HDPA)NULL) return FALSE;
  907. // TODO : Get Max length of the key from registry and use it
  908. // instead of MAX_PATH.
  909. TCHAR * buffer = (TCHAR *)LocalAlloc( LPTR, (MAX_PATH+1)*sizeof(TCHAR) );
  910. LONG lResult = RegOpenKeyEx(
  911. HKEY_CLASSES_ROOT,
  912. g_szMimeKey,
  913. 0,
  914. KEY_QUERY_VALUE | KEY_READ,
  915. &hKeyMime);
  916. if( lResult == ERROR_SUCCESS )
  917. {
  918. while( buffer )
  919. {
  920. dwLen = MAXPATH;
  921. if( RegEnumKeyEx( hKeyMime, index, buffer, &dwLen,
  922. NULL, NULL, NULL, NULL )
  923. == ERROR_NO_MORE_ITEMS ) break;
  924. {
  925. CMime * ptr = new CMime( buffer );
  926. lResult = RegOpenKeyEx(
  927. hKeyMime,
  928. buffer,
  929. 0,
  930. KEY_QUERY_VALUE | KEY_READ,
  931. &hKey);
  932. if( lResult == ERROR_SUCCESS )
  933. {
  934. dwLen = MAX_PATH;
  935. if (RegQueryValue( hKey, TEXT("extension"), buffer, (long *)&dwLen )
  936. == ERROR_SUCCESS )
  937. {
  938. ptr->m_exts = (TCHAR *)LocalAlloc( LPTR, (dwLen+1)*sizeof(TCHAR));
  939. StrCpy(ptr->m_exts, buffer);
  940. }
  941. RegCloseKey( hKey );
  942. }
  943. DPA_InsertPtr(mimeList, 0x7FFF, (LPVOID)ptr);
  944. index++;
  945. }
  946. }
  947. RegCloseKey( hKeyMime );
  948. }
  949. if( buffer ) LocalFree( buffer );
  950. return TRUE;
  951. }
  952. BOOL PrintAssociations()
  953. {
  954. printf("Listing Associations:\n");
  955. if( !assocList ) return FALSE;
  956. int assocCount = DPA_GetPtrCount( assocList );
  957. for(int i=0; i<assocCount; i++ )
  958. {
  959. CAssoc * ptr = (CAssoc *)DPA_FastGetPtr( assocList, i );
  960. ptr->Print();
  961. }
  962. return TRUE;
  963. }
  964. BOOL FindCommand(HWND hDlg)
  965. {
  966. TCHAR szFile[MAX_PATH] = TEXT("");
  967. TCHAR szFilter[5];
  968. OPENFILENAME ofn;
  969. HWND hCmnd = GetDlgItem(hDlg, IDC_DOC_CMND );
  970. memset((void*)&szFilter, 0, 5*sizeof(TCHAR));
  971. szFilter[0] = TCHAR('*');
  972. szFilter[2] = TCHAR('*');
  973. memset((void*)&ofn, 0, sizeof(ofn));
  974. ofn.lpstrFilter = szFilter;
  975. ofn.lStructSize = sizeof(ofn);
  976. ofn.hwndOwner = hDlg;
  977. ofn.lpstrFile = szFile;
  978. ofn.nMaxFile = MAX_PATH;
  979. ofn.lpstrInitialDir = NULL;
  980. ofn.Flags = OFN_HIDEREADONLY|OFN_CREATEPROMPT;
  981. if (GetOpenFileName(&ofn))
  982. {
  983. SendMessage(hCmnd, EM_SETSEL, 0, -1);
  984. SendMessage(hCmnd, EM_REPLACESEL, 0, (LPARAM)szFile);
  985. }
  986. return TRUE;
  987. }
  988. int FindIndex(LPTSTR doc)
  989. {
  990. if( ! assocList ) return -1;
  991. int assocCount = DPA_GetPtrCount( assocList );
  992. for(int i = 0; i< assocCount;i++ )
  993. {
  994. CAssoc * ptr = (CAssoc *)DPA_FastGetPtr( assocList, i );
  995. if( !StrCmp(doc, ptr->m_type ) )
  996. return i;
  997. }
  998. return -1;
  999. }
  1000. HDPA CreateDPAForExts( TCHAR * strPassed, int * error, CAssoc * existing)
  1001. {
  1002. HKEY hKey;
  1003. int bFound = 0;
  1004. HDPA hdpaExts = NULL;
  1005. // Check for existing associations not created by IEUNIX
  1006. // [.ext
  1007. // (--reg-val-- "Application")
  1008. // (content.type "mimetype" )
  1009. // (g_szIEUnix "g_szIEUnixTag" )
  1010. // ]
  1011. EatSpaces(strPassed);
  1012. if(strPassed && *strPassed)
  1013. {
  1014. TCHAR *strExt = DuplicateString( strPassed );
  1015. TCHAR *pos, *ptr = strExt;
  1016. BOOL bCont = TRUE;
  1017. while(bCont && *ptr)
  1018. {
  1019. pos = StrChr(ptr, TEXT(';'));
  1020. if(pos)
  1021. {
  1022. bCont = ( *pos == TEXT(';') )? TRUE : FALSE;
  1023. *pos = TEXT('\0');
  1024. }
  1025. else
  1026. {
  1027. bCont = FALSE;
  1028. }
  1029. if( !hdpaExts ) hdpaExts = DPA_Create(4);
  1030. DPA_InsertPtr( hdpaExts, 0x7FFF, (LPVOID)DuplicateString( ptr ) );
  1031. if(*ptr == TEXT('.') && *(ptr+1) )
  1032. {
  1033. int assocCount, extCount;
  1034. assocCount = DPA_GetPtrCount( assocList );
  1035. for( int i = 0; i< assocCount; i++ )
  1036. {
  1037. CAssoc * pAssoc = (CAssoc*)DPA_FastGetPtr( assocList, i );
  1038. if( pAssoc->m_exts == NULL || pAssoc == existing ) continue;
  1039. extCount = DPA_GetPtrCount(pAssoc->m_exts) ;
  1040. for(int j=0;j<extCount;j++ )
  1041. {
  1042. if( !StrCmpI(ptr, (LPTSTR)DPA_FastGetPtr( pAssoc->m_exts, j ) ) )
  1043. {
  1044. bFound = IDS_ERROR_EXTS_ALREADY_EXISTS;
  1045. break;
  1046. }
  1047. }
  1048. if( bFound ) break;
  1049. }
  1050. }
  1051. else
  1052. {
  1053. // Extension must start with a '.'
  1054. bFound = IDS_ERROR_NOT_AN_EXT;
  1055. break;
  1056. }
  1057. ptr = pos+1;
  1058. }
  1059. if(strExt) LocalFree(strExt);
  1060. }
  1061. else
  1062. bFound = IDS_ERROR_MISSING_EXTS;
  1063. *error = bFound;
  1064. // Error occured while checking extensions
  1065. if( bFound )
  1066. {
  1067. if(hdpaExts) FreeExtensions( hdpaExts );
  1068. return NULL;
  1069. }
  1070. return hdpaExts;
  1071. }
  1072. // Following functions are called in response to the
  1073. // actions performed on the associations.
  1074. AssocDel( HWND hDlg )
  1075. {
  1076. int index = 0;
  1077. int lbindex = 0;
  1078. HWND lb = GetDlgItem( hDlg, IDC_DOC_LIST );
  1079. if( (lbindex = SendMessage( lb, LB_GETCURSEL, 0, 0 ) )!= LB_ERR )
  1080. {
  1081. LPTSTR str = (LPTSTR)SendMessage(lb, LB_GETITEMDATA, lbindex, 0 );
  1082. if(str)
  1083. {
  1084. if( (index = FindIndex( str ) ) != -1 )
  1085. {
  1086. CAssoc * ptr = (CAssoc *)DPA_FastGetPtr( assocList, index );
  1087. TCHAR question[MAX_PATH];
  1088. wnsprintf( question, ARRAYSIZE(question), TEXT("Are you Sure you want to delete '%s'?"), ptr->m_desc );
  1089. if( MessageBox( GetParent(hDlg), question, TEXT("Delete Association"), MB_YESNO ) == IDYES )
  1090. {
  1091. CAssoc *pAssoc = (CAssoc *)DPA_DeletePtr( assocList, index );
  1092. // Add to List of deleted entries
  1093. if( assocDelList == NULL ) assocDelList = DPA_Create(4);
  1094. if( assocDelList != NULL ) DPA_InsertPtr( assocDelList, 0x7FFF, pAssoc );
  1095. SendMessage( lb, LB_DELETESTRING, lbindex, 0 );
  1096. InitAssocDialog( hDlg );
  1097. SwitchToNrmlMode( hDlg );
  1098. PropSheet_Changed(GetParent(hDlg),hDlg);
  1099. LocalFree( str );
  1100. }
  1101. }
  1102. }
  1103. }
  1104. return TRUE;
  1105. }
  1106. #ifdef 0
  1107. AssocUpd( HWND hDlg )
  1108. {
  1109. BOOL bFound = FALSE;
  1110. TCHAR szTemp [1024];
  1111. TCHAR szTitle [80];
  1112. CAssoc *ptr = NULL;
  1113. TCHAR *str;
  1114. int index, len;
  1115. HDPA hdpaExts = NULL;
  1116. HWND lb = GetDlgItem( hDlg, IDC_DOC_LIST );
  1117. HWND exts = GetDlgItem( hDlg, IDC_DOC_EXTS );
  1118. HWND desc = GetDlgItem( hDlg, IDC_DOC_DESC );
  1119. HWND mime = GetDlgItem( hDlg, IDC_DOC_MIME );
  1120. HWND cmnd = GetDlgItem( hDlg, IDC_DOC_CMND );
  1121. MLLoadString(IDS_ERROR_REGISTRY_TITLE, szTitle, sizeof(szTitle));
  1122. // Get the pointer to existing associations.
  1123. if(PGTI_FROM_HDLG(hDlg)->mode == UPDATING)
  1124. {
  1125. ptr = GetCurrentAssoc( hDlg );
  1126. }
  1127. //Check for Description
  1128. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXTLENGTH, 0, 0 );
  1129. if( len > 0 )
  1130. {
  1131. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1132. SendMessage(GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXT, len+1, (LPARAM)str );
  1133. ChopSpaces( str );
  1134. if( *str == TEXT('\0') )
  1135. {
  1136. LocalFree(str);
  1137. MLLoadString(IDS_ERROR_MISSING_DESC, szTemp, sizeof(szTemp));
  1138. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1139. SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) );
  1140. return FALSE;
  1141. }
  1142. int assocCount = DPA_GetPtrCount( assocList );
  1143. for( int i= 0; i<assocCount; i++ )
  1144. {
  1145. CAssoc * pAssoc ;
  1146. if((pAssoc= (CAssoc *)DPA_FastGetPtr( assocList, i )) == ptr ) continue;
  1147. if( StrCmpI( str, pAssoc->m_cmnd ) == NULL )
  1148. {
  1149. LocalFree(str);
  1150. MLLoadString(IDS_ERROR_DESC_ALREADY_EXISTS, szTemp, sizeof(szTemp));
  1151. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1152. SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) );
  1153. return FALSE;
  1154. }
  1155. }
  1156. LocalFree(str);
  1157. }
  1158. else
  1159. {
  1160. MLLoadString(IDS_ERROR_MISSING_DESC, szTemp, sizeof(szTemp));
  1161. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1162. SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) );
  1163. return FALSE;
  1164. }
  1165. //Check for MIME
  1166. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXTLENGTH, 0, 0 );
  1167. if( len > 0 )
  1168. {
  1169. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1170. SendMessage(GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXT, len+1, (LPARAM)str );
  1171. ChopSpaces( str );
  1172. if( *str != TEXT('\0') )
  1173. {
  1174. if( !StrChr( str, TEXT('/') ) )
  1175. {
  1176. LocalFree(str);
  1177. MLLoadString(IDS_ERROR_INVALID_MIME, szTemp, sizeof(szTemp));
  1178. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1179. SetFocus( GetDlgItem(hDlg, IDC_DOC_MIME) );
  1180. return FALSE;
  1181. }
  1182. }
  1183. LocalFree(str);
  1184. }
  1185. //Check for command line
  1186. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXTLENGTH, 0, 0 );
  1187. if( len > 0 )
  1188. {
  1189. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1190. SendMessage(GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXT, len+1, (LPARAM)str );
  1191. ChopSpaces( str );
  1192. if( *str == TEXT('\0') )
  1193. {
  1194. LocalFree(str);
  1195. MLLoadString(IDS_ERROR_MISSING_CMND, szTemp, sizeof(szTemp));
  1196. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1197. SetFocus( GetDlgItem(hDlg, IDC_DOC_CMND) );
  1198. return FALSE;
  1199. }
  1200. LocalFree(str);
  1201. }
  1202. else
  1203. {
  1204. MLLoadString(IDS_ERROR_MISSING_CMND, szTemp, sizeof(szTemp));
  1205. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1206. SetFocus( GetDlgItem(hDlg, IDC_DOC_CMND) );
  1207. return FALSE;
  1208. }
  1209. // Check for extensions.
  1210. // User entered may already have associations in the
  1211. // registry.
  1212. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_EXTS), WM_GETTEXTLENGTH, 0, 0 );
  1213. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1214. SendMessage(GetDlgItem(hDlg, IDC_DOC_EXTS), WM_GETTEXT, len+1, (LPARAM)str );
  1215. int error;
  1216. if(!(hdpaExts = CreateDPAForExts(EatSpaces(str), &error, ptr)))
  1217. {
  1218. LocalFree( str );
  1219. MLLoadString(error, szTemp, sizeof(szTemp));
  1220. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1221. SetFocus( GetDlgItem(hDlg, IDC_DOC_EXTS) );
  1222. return FALSE;
  1223. }
  1224. LocalFree( str );
  1225. // Check and Add CAssoc if we are inserting a new entry.
  1226. if(PGTI_FROM_HDLG(hDlg)->mode == ADDING)
  1227. {
  1228. LPTSTR firstExt = (LPTSTR)DPA_FastGetPtr( hdpaExts, 0 );
  1229. int len = lstrlen( firstExt ) + lstrlen(g_szDocClass) + 1;
  1230. str = (TCHAR *)LocalAlloc( LPTR, len*sizeof(TCHAR) );
  1231. StrCpy( str, firstExt+1 );
  1232. StrCat( str, g_szDocClass );
  1233. ptr = new CAssoc( str );
  1234. ptr->m_safe = FALSE; // Since we are adding this entry.
  1235. DPA_InsertPtr( assocList, 0x7FFF, ptr );
  1236. LocalFree( str );
  1237. }
  1238. // We are not able to add or retrieve Assoc from the List
  1239. if( ptr == NULL || ptr->m_safe == TRUE )
  1240. {
  1241. FreeExtensions( hdpaExts );
  1242. return FALSE;
  1243. }
  1244. // Start replacing components of the Associations.
  1245. // Replace Extensions
  1246. if(ptr->m_exts) FreeExtensions( ptr->m_exts );
  1247. ptr->m_exts = hdpaExts;
  1248. // Replace mime type
  1249. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXTLENGTH, 0, 0 );
  1250. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1251. SendMessage(GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXT, len+1, (LPARAM)str );
  1252. if( ptr->m_mime ) LocalFree( ptr->m_mime );
  1253. ptr->m_mime = EatSpaces(str);
  1254. // Replace Description
  1255. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXTLENGTH, 0, 0 );
  1256. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1257. SendMessage(GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXT, len+1, (LPARAM)str );
  1258. if( ptr->m_desc ) LocalFree( ptr->m_desc);
  1259. ptr->m_desc = ChopSpaces(str);
  1260. // Replace Command Line
  1261. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXTLENGTH, 0, 0 );
  1262. str = (TCHAR *)LocalAlloc( LPTR, (len+4)*sizeof(TCHAR) );
  1263. SendMessage(GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXT, len+1, (LPARAM)str );
  1264. if( ptr->m_cmnd ) LocalFree( ptr->m_cmnd );
  1265. ptr->m_cmnd = ChopSpaces(str);
  1266. if (ptr->m_stat == NEW)
  1267. if (!StrStr(ptr->m_cmnd, TEXT("%1")))
  1268. lstrcat(ptr->m_cmnd, TEXT(" %1"));
  1269. {
  1270. DWORD dwCurChar;
  1271. BOOL bPath = FALSE;
  1272. for (dwCurChar = 0; dwCurChar < lstrlen(ptr->m_cmnd); dwCurChar++)
  1273. {
  1274. if (ptr->m_cmnd[dwCurChar] == TEXT('/'))
  1275. {
  1276. bPath = TRUE;
  1277. }
  1278. if (ptr->m_cmnd[dwCurChar] == TEXT(' '))
  1279. {
  1280. break;
  1281. }
  1282. }
  1283. if (bPath) // if it's file name with no path we assume it's in the user's PATH
  1284. {
  1285. CHAR szExeFile[MAX_PATH];
  1286. TCHAR szWarning[MAX_PATH + 128];
  1287. #ifndef UNICODE
  1288. lstrcpyn(szExeFile, ptr->m_cmnd, dwCurChar + 1);
  1289. #else
  1290. WCHAR wszExeFile[MAX_PATH];
  1291. lstrcpyn(wszExeFile, ptr->m_cmnd, dwCurChar + 1);
  1292. SHUnicodeToAnsi(wszExeFile, szExeFile, ARRAYSIZE(szExeFile));
  1293. #endif
  1294. if (access(szExeFile, X_OK) != 0)
  1295. {
  1296. #ifndef UNICODE
  1297. wsprintf(szWarning, TEXT("File %s is not an executable file."), szExeFile);
  1298. #else
  1299. wsprintf(szWarning, TEXT("File %s is not an executable file."), wszExeFile);
  1300. #endif
  1301. MessageBox( GetParent(hDlg), szWarning, TEXT("Warning"), MB_OK);
  1302. }
  1303. }
  1304. }
  1305. if (Button_GetCheck(GetDlgItem(hDlg, IDC_ASSOC_EDIT)) != BST_UNCHECKED)
  1306. ptr->m_edit &= (~FTA_OpenIsSafe );
  1307. else
  1308. ptr->m_edit |= FTA_OpenIsSafe;
  1309. ptr->m_stat = UPD;
  1310. InitAssocDialog( hDlg, ptr );
  1311. SwitchToNrmlMode( hDlg);
  1312. // SetFocus to Ok button again
  1313. SetFocus( GetDlgItem(GetParent( hDlg ), IDOK ) );
  1314. PropSheet_Changed(GetParent(hDlg),hDlg);
  1315. return TRUE;
  1316. }
  1317. AssocAdd( HWND hDlg)
  1318. {
  1319. SwitchToAddMode( hDlg );
  1320. PropSheet_Changed(GetParent(hDlg),hDlg);
  1321. return TRUE;
  1322. }
  1323. #endif // 0
  1324. CAssoc * GetCurrentAssoc( HWND hDlg )
  1325. {
  1326. int index = 0;
  1327. HWND lb = GetDlgItem( hDlg, IDC_DOC_LIST );
  1328. if( (index = SendMessage( lb, LB_GETCURSEL, 0, 0 ) )!= LB_ERR )
  1329. {
  1330. TCHAR * str = (LPTSTR)SendMessage( lb, LB_GETITEMDATA, index, 0 );
  1331. if(!str) return NULL;
  1332. if(str && *str)
  1333. {
  1334. if( (index = FindIndex( str ) ) != -1 )
  1335. {
  1336. CAssoc * ptr = (CAssoc *)DPA_FastGetPtr( assocList, index );
  1337. return ptr;
  1338. }
  1339. }
  1340. }
  1341. return NULL;
  1342. }
  1343. SwitchToNrmlMode( HWND hDlg )
  1344. {
  1345. PGTI_FROM_HDLG(hDlg)->mode = NORMAL;
  1346. EnableWindow(GetDlgItem(hDlg,IDC_DOC_DESC), FALSE );
  1347. EnableWindow(GetDlgItem(hDlg,IDC_DOC_EXTS), FALSE );
  1348. EnableWindow(GetDlgItem(hDlg,IDC_DOC_MIME), FALSE );
  1349. EnableWindow(GetDlgItem(hDlg,IDC_DOC_CMND), FALSE );
  1350. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_EDIT), FALSE );
  1351. if (IsAssocEnabled())
  1352. {
  1353. CAssoc *pAssoc = GetCurrentAssoc( hDlg );
  1354. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_ADD), TRUE );
  1355. if( pAssoc )
  1356. {
  1357. if( pAssoc->m_safe )
  1358. {
  1359. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), FALSE);
  1360. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_UPD), FALSE );
  1361. }
  1362. else
  1363. {
  1364. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), TRUE );
  1365. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_UPD), TRUE );
  1366. }
  1367. }
  1368. }
  1369. else
  1370. {
  1371. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), FALSE);
  1372. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_UPD), FALSE );
  1373. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_ADD), FALSE );
  1374. }
  1375. REMOVE_DEF_BORDER(hDlg, IDC_ASSOC_ADD );
  1376. REMOVE_DEF_BORDER(hDlg, IDC_ASSOC_UPD );
  1377. REMOVE_DEF_BORDER(hDlg, IDC_ASSOC_DEL );
  1378. SET_DEF_BORDER( GetParent(hDlg), IDOK );
  1379. return TRUE;
  1380. }
  1381. SwitchToAddMode( HWND hDlg )
  1382. {
  1383. PGTI_FROM_HDLG(hDlg)->mode = ADDING;
  1384. LPASSOCTABINFO pgti = (LPASSOCTABINFO)GetWindowLong(hDlg, DWL_USER);
  1385. // Remove Selection from Listbox.
  1386. SendMessage( GetDlgItem(hDlg, IDC_DOC_LIST), LB_SETCURSEL,
  1387. (WPARAM)-1, 0);
  1388. pgti->fInternalChange = TRUE;
  1389. // Clear all the fields
  1390. SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_SETTEXT,
  1391. 0, LPARAM( TEXT("")) );
  1392. SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_SETTEXT,
  1393. 0, LPARAM( TEXT("")) );
  1394. SendMessage( GetDlgItem(hDlg, IDC_DOC_EXTS), WM_SETTEXT,
  1395. 0, LPARAM( TEXT("")) );
  1396. SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_SETTEXT,
  1397. 0, LPARAM( TEXT("")) );
  1398. // Default value
  1399. Button_SetCheck( GetDlgItem( hDlg, IDC_ASSOC_EDIT), TRUE );
  1400. pgti->fInternalChange = FALSE;
  1401. // Enable all edit windows
  1402. EnableWindow(GetDlgItem(hDlg,IDC_DOC_DESC), TRUE);
  1403. EnableWindow(GetDlgItem(hDlg,IDC_DOC_MIME), TRUE);
  1404. EnableWindow(GetDlgItem(hDlg,IDC_DOC_EXTS), TRUE);
  1405. EnableWindow(GetDlgItem(hDlg,IDC_DOC_CMND), TRUE);
  1406. EnableWindow(GetDlgItem(hDlg,IDC_BROWSE ), TRUE);
  1407. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_EDIT ), TRUE);
  1408. // Enable Add option
  1409. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_ADD), FALSE);
  1410. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_UPD), TRUE );
  1411. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), FALSE);
  1412. // Remove Default Border
  1413. REMOVE_DEF_BORDER( GetParent(hDlg), IDOK );
  1414. REMOVE_DEF_BORDER( hDlg, IDC_ASSOC_ADD);
  1415. REMOVE_DEF_BORDER( hDlg, IDC_ASSOC_DEL);
  1416. SET_DEF_BORDER( hDlg, IDC_ASSOC_UPD );
  1417. SetFocus( GetDlgItem( hDlg, IDC_ASSOC_UPD ) );
  1418. return TRUE;
  1419. }
  1420. SwitchToUpdMode( HWND hDlg )
  1421. {
  1422. if(PGTI_FROM_HDLG(hDlg)->mode != NORMAL )
  1423. return FALSE;
  1424. PGTI_FROM_HDLG(hDlg)->mode = UPDATING;
  1425. // Enable Upd option
  1426. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_ADD), TRUE );
  1427. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_UPD), TRUE );
  1428. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), TRUE );
  1429. // Remove Default Border
  1430. REMOVE_DEF_BORDER( GetParent(hDlg), IDOK );
  1431. REMOVE_DEF_BORDER( hDlg, IDC_ASSOC_ADD);
  1432. REMOVE_DEF_BORDER( hDlg, IDC_ASSOC_DEL);
  1433. SET_DEF_BORDER( hDlg, IDC_ASSOC_UPD);
  1434. return TRUE;
  1435. }
  1436. void ListBoxResetContents(HWND listBox)
  1437. {
  1438. int count = SendMessage( listBox, LB_GETCOUNT, 0, 0 );
  1439. for( int i= 0; i< count; i++ )
  1440. {
  1441. LPSTR data = (LPSTR)SendMessage( listBox, LB_GETITEMDATA, i, 0 );
  1442. if( data ) LocalFree( data );
  1443. }
  1444. SendMessage( listBox, LB_RESETCONTENT, 0, 0 );
  1445. }
  1446. BOOL FAR PASCAL InitAssocDialog(HWND hDlg, CAssoc * current)
  1447. {
  1448. HRESULT hr = E_FAIL;
  1449. HKEY hKey;
  1450. HWND listBox = GetDlgItem( hDlg, IDC_DOC_LIST );
  1451. TCHAR * displayString;
  1452. // Allocate memory for a structure which will hold all the info
  1453. // gathered from this page
  1454. //
  1455. LPASSOCTABINFO pgti = (LPASSOCTABINFO)GetWindowLong(hDlg, DWL_USER);
  1456. pgti->fInternalChange = FALSE;
  1457. ListBoxResetContents( listBox );
  1458. if( assocList == NULL ) return FALSE;
  1459. int assocCount = DPA_GetPtrCount( assocList );
  1460. for(int i = 0; i< assocCount; i++ )
  1461. {
  1462. CAssoc * ptr = (CAssoc *)DPA_FastGetPtr( assocList, i );
  1463. int index = SendMessage( listBox, LB_ADDSTRING, 0, (LPARAM)ptr->m_desc );
  1464. SendMessage( listBox, LB_SETITEMDATA, index, (LPARAM)DuplicateString( ptr->m_type ) );
  1465. }
  1466. if( i>0 )
  1467. SendMessage( listBox, LB_SETCURSEL, 0, 0 );
  1468. else
  1469. {
  1470. SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_SETTEXT,
  1471. 0, LPARAM( TEXT("")) );
  1472. SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_SETTEXT,
  1473. 0, LPARAM( TEXT("")) );
  1474. SendMessage( GetDlgItem(hDlg, IDC_DOC_EXTS), WM_SETTEXT,
  1475. 0, LPARAM( TEXT("")) );
  1476. SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_SETTEXT,
  1477. 0, LPARAM( TEXT("")) );
  1478. // Default value
  1479. Button_SetCheck( GetDlgItem( hDlg, IDC_ASSOC_EDIT), TRUE );
  1480. }
  1481. // Add Strings to Mimetype dialog
  1482. int mimeCount = 0;
  1483. if( mimeList && (mimeCount = DPA_GetPtrCount(mimeList)))
  1484. {
  1485. for(i=0; i< mimeCount; i++)
  1486. {
  1487. CMime * ptr = (CMime *)DPA_FastGetPtr( mimeList , i );
  1488. SafeAddStringToComboBox( GetDlgItem(hDlg, IDC_DOC_MIME) , ptr->m_mime) ;
  1489. }
  1490. }
  1491. if( current )
  1492. SendMessage( listBox, LB_SELECTSTRING, -1, (LPARAM)current->m_desc );
  1493. HandleSelChange( pgti );
  1494. SwitchToNrmlMode( hDlg );
  1495. if( IsAssocEnabled() && i > 0 )
  1496. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), TRUE);
  1497. else
  1498. EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), FALSE);
  1499. return TRUE;
  1500. }
  1501. void HandleSelChange( LPASSOCTABINFO pgti, BOOL bApplChange )
  1502. {
  1503. int index = 0;
  1504. HWND hDlg = pgti->hDlg;
  1505. TCHAR str[MAX_PATH] = TEXT("");
  1506. if( hDlg == NULL ) return;
  1507. HWND exts = GetDlgItem( hDlg, IDC_DOC_EXTS );
  1508. HWND desc = GetDlgItem( hDlg, IDC_DOC_DESC );
  1509. HWND mime = GetDlgItem( hDlg, IDC_DOC_MIME );
  1510. HWND cmnd = GetDlgItem( hDlg, IDC_DOC_CMND );
  1511. HWND brws = GetDlgItem( hDlg, IDC_BROWSE );
  1512. HWND edit = GetDlgItem( hDlg, IDC_ASSOC_EDIT );
  1513. CAssoc * ptr = GetCurrentAssoc( hDlg );
  1514. if(ptr)
  1515. {
  1516. SendMessage( desc, WM_SETTEXT, 0, (LPARAM)ptr->m_desc );
  1517. SendMessage( mime, WM_SETTEXT, 0, (LPARAM)ptr->m_mime );
  1518. SendMessage( cmnd, WM_SETTEXT, 0, (LPARAM)ptr->m_cmnd );
  1519. // Create Extension List
  1520. if( ptr->m_exts )
  1521. {
  1522. int i, count = DPA_GetPtrCount( ptr->m_exts );
  1523. for(i=0;i<count;i++)
  1524. {
  1525. StrCat( str, (LPTSTR)DPA_FastGetPtr( ptr->m_exts, i ) );
  1526. StrCat( str, TEXT(";") );
  1527. }
  1528. SendMessage( exts, WM_SETTEXT, 0, (LPARAM)str );
  1529. }
  1530. Button_SetCheck( GetDlgItem( hDlg, IDC_ASSOC_EDIT), !(ptr->m_edit & FTA_OpenIsSafe) );
  1531. EnableWindow( desc, !(ptr->m_safe) );
  1532. EnableWindow( exts, !(ptr->m_safe) );
  1533. EnableWindow( mime, !(ptr->m_safe) );
  1534. EnableWindow( cmnd, !(ptr->m_safe) );
  1535. EnableWindow( brws, !(ptr->m_safe) );
  1536. EnableWindow( edit, !(ptr->m_safe) );
  1537. pgti->fInternalChange = FALSE;
  1538. // Change back to the NORMAL mode if not coming from
  1539. // edit.
  1540. SwitchToNrmlMode( hDlg );
  1541. }
  1542. }
  1543. BOOL AssocOnCommand(LPASSOCTABINFO pgti, UINT id, UINT nCmd)
  1544. {
  1545. switch (id)
  1546. {
  1547. case IDC_BROWSE:
  1548. switch (nCmd )
  1549. {
  1550. case BN_CLICKED:
  1551. {
  1552. FindCommand( pgti->hDlg );
  1553. break;
  1554. }
  1555. }
  1556. break;
  1557. case IDC_ASSOC_ADD:
  1558. switch (nCmd )
  1559. {
  1560. case BN_CLICKED:
  1561. {
  1562. ENTERASSOC enter;
  1563. enter.pgti = pgti;
  1564. enter.pszAssoc = NULL;
  1565. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_ENTER_ASSOC),
  1566. pgti->hDlg, EnterAssocDlgProc, (LPARAM) &enter);
  1567. InitAssocDialog( pgti->hDlg, GetCurrentAssoc( pgti->hDlg ) );
  1568. SwitchToNrmlMode( pgti->hDlg);
  1569. // SetFocus to Ok button again
  1570. SetFocus( GetDlgItem(GetParent( pgti->hDlg ), IDOK ) );
  1571. if (pgti->fChanged)
  1572. {
  1573. pgti->fChanged = FALSE;
  1574. PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg);
  1575. }
  1576. //AssocAdd( pgti->hDlg );
  1577. break;
  1578. }
  1579. }
  1580. break;
  1581. case IDC_ASSOC_UPD:
  1582. switch (nCmd )
  1583. {
  1584. case BN_CLICKED:
  1585. {
  1586. HWND lb = GetDlgItem( pgti->hDlg, IDC_DOC_LIST );
  1587. int index;
  1588. if( (index = SendMessage( lb, LB_GETCURSEL, 0, 0 ) )!= LB_ERR )
  1589. {
  1590. TCHAR * str = (LPTSTR)SendMessage( lb, LB_GETITEMDATA, index, 0 );
  1591. ENTERASSOC enter;
  1592. if(!str) return FALSE;
  1593. enter.pgti = pgti;
  1594. enter.pszAssoc = str;
  1595. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_ENTER_ASSOC),
  1596. pgti->hDlg, EnterAssocDlgProc, (LPARAM) &enter);
  1597. InitAssocDialog( pgti->hDlg, GetCurrentAssoc( pgti->hDlg ) );
  1598. SwitchToNrmlMode( pgti->hDlg);
  1599. // SetFocus to Ok button again
  1600. SetFocus( GetDlgItem(GetParent( pgti->hDlg ), IDOK ) );
  1601. if (pgti->fChanged)
  1602. {
  1603. pgti->fChanged = FALSE;
  1604. PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg);
  1605. }
  1606. }
  1607. //AssocUpd( pgti->hDlg );
  1608. break;
  1609. }
  1610. }
  1611. break;
  1612. case IDC_ASSOC_DEL:
  1613. switch (nCmd )
  1614. {
  1615. case BN_CLICKED:
  1616. {
  1617. AssocDel( pgti->hDlg );
  1618. break;
  1619. }
  1620. }
  1621. break;
  1622. case IDC_DOC_LIST:
  1623. switch (nCmd )
  1624. {
  1625. case LBN_SELCHANGE:
  1626. HandleSelChange( pgti );
  1627. break;
  1628. case LBN_DBLCLK:
  1629. {
  1630. HWND lb = GetDlgItem( pgti->hDlg, IDC_DOC_LIST );
  1631. int index;
  1632. if( (index = SendMessage( lb, LB_GETCURSEL, 0, 0 ) )!= LB_ERR )
  1633. {
  1634. TCHAR * str = (LPTSTR)SendMessage( lb, LB_GETITEMDATA, index, 0 );
  1635. ENTERASSOC enter;
  1636. CAssoc *pAssoc = GetCurrentAssoc( pgti->hDlg );
  1637. if(!IsAssocEnabled() || pAssoc->m_safe || !str) return FALSE;
  1638. enter.pgti = pgti;
  1639. enter.pszAssoc = str;
  1640. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_ENTER_ASSOC),
  1641. pgti->hDlg, EnterAssocDlgProc, (LPARAM) &enter);
  1642. InitAssocDialog( pgti->hDlg, GetCurrentAssoc( pgti->hDlg ) );
  1643. SwitchToNrmlMode( pgti->hDlg);
  1644. // SetFocus to Ok button again
  1645. SetFocus( GetDlgItem(GetParent( pgti->hDlg ), IDOK ) );
  1646. if (pgti->fChanged)
  1647. {
  1648. pgti->fChanged = FALSE;
  1649. PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg);
  1650. }
  1651. }
  1652. //AssocUpd( pgti->hDlg );
  1653. break;
  1654. }
  1655. }
  1656. break;
  1657. #ifdef 0
  1658. case IDC_DOC_MIME:
  1659. switch (nCmd)
  1660. {
  1661. case CBN_SELCHANGE:
  1662. case CBN_EDITCHANGE:
  1663. if (!pgti->fInternalChange)
  1664. {
  1665. pgti->fChanged = TRUE;
  1666. SwitchToUpdMode( pgti->hDlg );
  1667. }
  1668. break;
  1669. }
  1670. break;
  1671. case IDC_ASSOC_EDIT:
  1672. switch (nCmd )
  1673. {
  1674. case BN_CLICKED:
  1675. {
  1676. if (!pgti->fInternalChange)
  1677. {
  1678. pgti->fChanged = TRUE;
  1679. SwitchToUpdMode( pgti->hDlg );
  1680. }
  1681. break;
  1682. }
  1683. }
  1684. break;
  1685. case IDC_DOC_TYPE:
  1686. case IDC_DOC_EXTS:
  1687. case IDC_DOC_DESC:
  1688. case IDC_DOC_CMND:
  1689. switch (nCmd)
  1690. {
  1691. case EN_CHANGE:
  1692. if (!pgti->fInternalChange)
  1693. {
  1694. pgti->fChanged = TRUE;
  1695. SwitchToUpdMode( pgti->hDlg );
  1696. }
  1697. break;
  1698. case EN_SETFOCUS:
  1699. if ( pgti->mode == ADDING)
  1700. {
  1701. SET_DEF_BORDER( pgti->hDlg, IDC_ASSOC_UPD );
  1702. break;
  1703. }
  1704. }
  1705. break;
  1706. #endif //0
  1707. }
  1708. return FALSE;
  1709. }
  1710. void AssocApply(HWND hDlg)
  1711. {
  1712. // Delete the associations removed by the user.
  1713. if( assocDelList )
  1714. {
  1715. int count = DPA_GetPtrCount( assocDelList );
  1716. for(int i=0;i<count;i++)
  1717. {
  1718. CAssoc * pAssoc = (CAssoc *)DPA_FastGetPtr( assocDelList, i );
  1719. if(pAssoc)
  1720. {
  1721. pAssoc->Delete();
  1722. delete pAssoc;
  1723. }
  1724. }
  1725. DPA_Destroy( assocDelList );
  1726. assocDelList = NULL;
  1727. }
  1728. // Save the currently changed associations.
  1729. if( assocList )
  1730. {
  1731. int count = DPA_GetPtrCount( assocList );
  1732. for(int i=0;i<count;i++)
  1733. {
  1734. CAssoc * pAssoc = (CAssoc *)DPA_FastGetPtr( assocList, i );
  1735. if(pAssoc)
  1736. {
  1737. pAssoc->Save();
  1738. }
  1739. }
  1740. }
  1741. }
  1742. /****************************************************************************
  1743. *
  1744. * AssocDlgProc
  1745. *
  1746. *
  1747. ***************************************************************************/
  1748. BOOL CALLBACK AssocDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1749. {
  1750. // get our tab info structure
  1751. LPASSOCTABINFO pgti;
  1752. if (uMsg == WM_INITDIALOG)
  1753. {
  1754. // Set Limits for edit fields
  1755. SetEditLimits( hDlg );
  1756. // Allocate memory for a structure which will hold all the info
  1757. // gathered from this page
  1758. //
  1759. LPASSOCTABINFO pgti = (LPASSOCTABINFO)LocalAlloc(LPTR, sizeof(ASSOCINFO));
  1760. if (!pgti)
  1761. {
  1762. EndDialog(hDlg, 0);
  1763. return FALSE;
  1764. }
  1765. pgti->hDlg = hDlg;
  1766. pgti->mode = NORMAL;
  1767. pgti->fInternalChange = FALSE;
  1768. SetWindowLong(hDlg, DWL_USER, (LPARAM)pgti);
  1769. // Create an association array from registry
  1770. LoadAssociations();
  1771. LoadMimeTypes();
  1772. // Initailize dialog
  1773. if( InitAssocDialog(hDlg) )
  1774. {
  1775. HandleSelChange(pgti);
  1776. return TRUE;
  1777. }
  1778. else
  1779. {
  1780. TCHAR szTitle[MAX_PATH];
  1781. MLLoadString(IDS_ERROR_REGISTRY_TITLE, szTitle, sizeof(szTitle));
  1782. MessageBox( GetParent(hDlg), TEXT("Cannot read associations from registry."), szTitle, MB_OK );
  1783. return FALSE;
  1784. }
  1785. }
  1786. else
  1787. pgti = (LPASSOCTABINFO)GetWindowLong(hDlg, DWL_USER);
  1788. if (!pgti)
  1789. return FALSE;
  1790. switch (uMsg)
  1791. {
  1792. case WM_NOTIFY:
  1793. {
  1794. NMHDR *lpnm = (NMHDR *) lParam;
  1795. switch (lpnm->code)
  1796. {
  1797. case PSN_QUERYCANCEL:
  1798. case PSN_KILLACTIVE:
  1799. case PSN_RESET:
  1800. SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
  1801. return TRUE;
  1802. case PSN_APPLY:
  1803. AssocApply(hDlg);
  1804. break;
  1805. }
  1806. break;
  1807. }
  1808. case WM_COMMAND:
  1809. AssocOnCommand(pgti, LOWORD(wParam), HIWORD(wParam));
  1810. break;
  1811. case WM_HELP: // F1
  1812. //ResWinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  1813. // HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1814. break;
  1815. case WM_CONTEXTMENU: // right mouse click
  1816. //ResWinHelp( (HWND) wParam, IDS_HELPFILE,
  1817. // HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1818. break;
  1819. case WM_DESTROY:
  1820. #if 0
  1821. RemoveDefaultDialogFont(hDlg);
  1822. #endif
  1823. if (pgti)
  1824. LocalFree(pgti);
  1825. // Remove Associated data items for the listbos items.
  1826. ListBoxResetContents( GetDlgItem( hDlg, IDC_DOC_LIST ) );
  1827. // Delete registry information
  1828. FreeAssociations();
  1829. FreeMimeTypes();
  1830. SetWindowLong(hDlg, DWL_USER, (LONG)NULL); // make sure we don't re-enter
  1831. break;
  1832. }
  1833. return FALSE;
  1834. }
  1835. BOOL AssocEnter( HWND hDlg )
  1836. {
  1837. LPASSOCTABINFO pgti = ((LPENTERASSOC)GetWindowLong(hDlg, DWL_USER))->pgti;
  1838. BOOL bFound = FALSE;
  1839. TCHAR szTemp [1024];
  1840. TCHAR szTitle [80];
  1841. CAssoc *ptr = NULL;
  1842. TCHAR *str;
  1843. int index, len;
  1844. HDPA hdpaExts = NULL;
  1845. HWND exts = GetDlgItem( hDlg, IDC_DOC_EXTS );
  1846. HWND desc = GetDlgItem( hDlg, IDC_DOC_DESC );
  1847. HWND mime = GetDlgItem( hDlg, IDC_DOC_MIME );
  1848. HWND cmnd = GetDlgItem( hDlg, IDC_DOC_CMND );
  1849. MLLoadString(IDS_ERROR_REGISTRY_TITLE, szTitle, sizeof(szTitle));
  1850. // Get the pointer to existing associations.
  1851. if(GetWindowLong(hDlg, DWL_USER))
  1852. {
  1853. TCHAR *pszAssoc = ((LPENTERASSOC)GetWindowLong(hDlg, DWL_USER))->pszAssoc;
  1854. if(pszAssoc && *pszAssoc)
  1855. if( (index = FindIndex( pszAssoc ) ) != -1 )
  1856. ptr = (CAssoc *)DPA_FastGetPtr( assocList, index );
  1857. }
  1858. //Check for Description
  1859. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXTLENGTH, 0, 0 );
  1860. if( len > 0 )
  1861. {
  1862. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1863. SendMessage(GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXT, len+1, (LPARAM)str );
  1864. ChopSpaces( str );
  1865. if( *str == TEXT('\0') )
  1866. {
  1867. LocalFree(str);
  1868. MLLoadString(IDS_ERROR_MISSING_DESC, szTemp, sizeof(szTemp));
  1869. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1870. SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) );
  1871. return FALSE;
  1872. }
  1873. int assocCount = DPA_GetPtrCount( assocList );
  1874. for( int i= 0; i<assocCount; i++ )
  1875. {
  1876. CAssoc * pAssoc ;
  1877. if((pAssoc= (CAssoc *)DPA_FastGetPtr( assocList, i )) == ptr ) continue;
  1878. if( StrCmpI( str, pAssoc->m_cmnd ) == NULL )
  1879. {
  1880. LocalFree(str);
  1881. MLLoadString(IDS_ERROR_DESC_ALREADY_EXISTS, szTemp, sizeof(szTemp));
  1882. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1883. SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) );
  1884. return FALSE;
  1885. }
  1886. }
  1887. LocalFree(str);
  1888. }
  1889. else
  1890. {
  1891. MLLoadString(IDS_ERROR_MISSING_DESC, szTemp, sizeof(szTemp));
  1892. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1893. SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) );
  1894. return FALSE;
  1895. }
  1896. //Check for MIME
  1897. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXTLENGTH, 0, 0 );
  1898. if( len > 0 )
  1899. {
  1900. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1901. SendMessage(GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXT, len+1, (LPARAM)str );
  1902. ChopSpaces( str );
  1903. if( *str != TEXT('\0') )
  1904. {
  1905. if( !StrChr( str, TEXT('/') ) )
  1906. {
  1907. LocalFree(str);
  1908. MLLoadString(IDS_ERROR_INVALID_MIME, szTemp, sizeof(szTemp));
  1909. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1910. SetFocus( GetDlgItem(hDlg, IDC_DOC_MIME) );
  1911. return FALSE;
  1912. }
  1913. }
  1914. LocalFree(str);
  1915. }
  1916. //Check for command line
  1917. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXTLENGTH, 0, 0 );
  1918. if( len > 0 )
  1919. {
  1920. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1921. SendMessage(GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXT, len+1, (LPARAM)str );
  1922. ChopSpaces( str );
  1923. if( *str == TEXT('\0') )
  1924. {
  1925. LocalFree(str);
  1926. MLLoadString(IDS_ERROR_MISSING_CMND, szTemp, sizeof(szTemp));
  1927. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1928. SetFocus( GetDlgItem(hDlg, IDC_DOC_CMND) );
  1929. return FALSE;
  1930. }
  1931. LocalFree(str);
  1932. }
  1933. else
  1934. {
  1935. MLLoadString(IDS_ERROR_MISSING_CMND, szTemp, sizeof(szTemp));
  1936. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1937. SetFocus( GetDlgItem(hDlg, IDC_DOC_CMND) );
  1938. return FALSE;
  1939. }
  1940. // Check for extensions.
  1941. // User entered may already have associations in the
  1942. // registry.
  1943. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_EXTS), WM_GETTEXTLENGTH, 0, 0 );
  1944. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1945. SendMessage(GetDlgItem(hDlg, IDC_DOC_EXTS), WM_GETTEXT, len+1, (LPARAM)str );
  1946. int error;
  1947. if(!(hdpaExts = CreateDPAForExts(EatSpaces(str), &error, ptr)))
  1948. {
  1949. LocalFree( str );
  1950. MLLoadString(error, szTemp, sizeof(szTemp));
  1951. MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK);
  1952. SetFocus( GetDlgItem(hDlg, IDC_DOC_EXTS) );
  1953. return FALSE;
  1954. }
  1955. LocalFree( str );
  1956. // Check and Add CAssoc if we are inserting a new entry.
  1957. if(!((LPENTERASSOC)GetWindowLong(hDlg, DWL_USER))->pszAssoc)
  1958. {
  1959. LPTSTR firstExt = (LPTSTR)DPA_FastGetPtr( hdpaExts, 0 );
  1960. int len = lstrlen( firstExt ) + lstrlen(g_szDocClass) + 1;
  1961. str = (TCHAR *)LocalAlloc( LPTR, len*sizeof(TCHAR) );
  1962. StrCpy( str, firstExt+1 );
  1963. StrCat( str, g_szDocClass );
  1964. ptr = new CAssoc( str );
  1965. ptr->m_safe = FALSE; // Since we are adding this entry.
  1966. DPA_InsertPtr( assocList, 0x7FFF, ptr );
  1967. LocalFree( str );
  1968. }
  1969. // We are not able to add or retrieve Assoc from the List
  1970. if( ptr == NULL || ptr->m_safe == TRUE )
  1971. {
  1972. FreeExtensions( hdpaExts );
  1973. return FALSE;
  1974. }
  1975. // Start replacing components of the Associations.
  1976. // Replace Extensions
  1977. if(ptr->m_exts) FreeExtensions( ptr->m_exts );
  1978. ptr->m_exts = hdpaExts;
  1979. // Replace mime type
  1980. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXTLENGTH, 0, 0 );
  1981. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1982. SendMessage(GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXT, len+1, (LPARAM)str );
  1983. if( ptr->m_mime ) LocalFree( ptr->m_mime );
  1984. ptr->m_mime = EatSpaces(str);
  1985. // Replace Description
  1986. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXTLENGTH, 0, 0 );
  1987. str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) );
  1988. SendMessage(GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXT, len+1, (LPARAM)str );
  1989. if( ptr->m_desc ) LocalFree( ptr->m_desc);
  1990. ptr->m_desc = ChopSpaces(str);
  1991. // Replace Command Line
  1992. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXTLENGTH, 0, 0 );
  1993. str = (TCHAR *)LocalAlloc( LPTR, (len+4)*sizeof(TCHAR) );
  1994. SendMessage(GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXT, len+1, (LPARAM)str );
  1995. if( ptr->m_cmnd ) LocalFree( ptr->m_cmnd );
  1996. ptr->m_cmnd = ChopSpaces(str);
  1997. if (ptr->m_stat == NEW)
  1998. if (!StrStr(ptr->m_cmnd, TEXT("%1")))
  1999. lstrcat(ptr->m_cmnd, TEXT(" %1"));
  2000. {
  2001. DWORD dwCurChar;
  2002. BOOL bPath = FALSE;
  2003. for (dwCurChar = 0; dwCurChar < lstrlen(ptr->m_cmnd); dwCurChar++)
  2004. {
  2005. if (ptr->m_cmnd[dwCurChar] == TEXT('/'))
  2006. {
  2007. bPath = TRUE;
  2008. }
  2009. if (ptr->m_cmnd[dwCurChar] == TEXT(' '))
  2010. {
  2011. break;
  2012. }
  2013. }
  2014. if (bPath) // if it's file name with no path we assume it's in the user's PATH
  2015. {
  2016. CHAR szExeFile[MAX_PATH];
  2017. TCHAR szWarning[MAX_PATH + 128];
  2018. #ifndef UNICODE
  2019. lstrcpyn(szExeFile, ptr->m_cmnd, dwCurChar + 1);
  2020. #else
  2021. WCHAR wszExeFile[MAX_PATH];
  2022. lstrcpyn(wszExeFile, ptr->m_cmnd, dwCurChar + 1);
  2023. SHUnicodeToAnsi(wszExeFile, szExeFile, ARRAYSIZE(szExeFile));
  2024. #endif
  2025. if (access(szExeFile, X_OK) != 0)
  2026. {
  2027. #ifndef UNICODE
  2028. wsprintf(szWarning, TEXT("File %s is not an executable file."), szExeFile);
  2029. #else
  2030. wsprintf(szWarning, TEXT("File %s is not an executable file."), wszExeFile);
  2031. #endif
  2032. MessageBox( GetParent(hDlg), szWarning, TEXT("Warning"), MB_OK);
  2033. }
  2034. }
  2035. }
  2036. if (Button_GetCheck(GetDlgItem(hDlg, IDC_ASSOC_EDIT)) != BST_UNCHECKED)
  2037. ptr->m_edit &= (~FTA_OpenIsSafe );
  2038. else
  2039. ptr->m_edit |= FTA_OpenIsSafe;
  2040. ptr->m_stat = UPD;
  2041. pgti->fChanged = TRUE;
  2042. return TRUE;
  2043. }
  2044. BOOL FAR PASCAL InitEnterAssocDialog(HWND hDlg, LPENTERASSOC penter)
  2045. {
  2046. LPASSOCTABINFO pgti = penter->pgti;
  2047. int index = 0;
  2048. HWND hDlgParent = pgti->hDlg;
  2049. TCHAR str[MAX_PATH] = TEXT("");
  2050. if( hDlg == NULL ) return;
  2051. HWND exts = GetDlgItem( hDlg, IDC_DOC_EXTS );
  2052. HWND desc = GetDlgItem( hDlg, IDC_DOC_DESC );
  2053. HWND mime = GetDlgItem( hDlg, IDC_DOC_MIME );
  2054. HWND cmnd = GetDlgItem( hDlg, IDC_DOC_CMND );
  2055. HWND brws = GetDlgItem( hDlg, IDC_BROWSE );
  2056. HWND edit = GetDlgItem( hDlg, IDC_ASSOC_EDIT );
  2057. CAssoc * ptr = NULL;
  2058. if(penter->pszAssoc && *(penter->pszAssoc))
  2059. if( (index = FindIndex( penter->pszAssoc ) ) != -1 )
  2060. ptr = (CAssoc *)DPA_FastGetPtr( assocList, index );
  2061. if(ptr)
  2062. {
  2063. SendMessage( desc, WM_SETTEXT, 0, (LPARAM)ptr->m_desc );
  2064. SendMessage( mime, WM_SETTEXT, 0, (LPARAM)ptr->m_mime );
  2065. SendMessage( cmnd, WM_SETTEXT, 0, (LPARAM)ptr->m_cmnd );
  2066. // Create Extension List
  2067. if( ptr->m_exts )
  2068. {
  2069. int i, count = DPA_GetPtrCount( ptr->m_exts );
  2070. for(i=0;i<count;i++)
  2071. {
  2072. StrCat( str, (LPTSTR)DPA_FastGetPtr( ptr->m_exts, i ) );
  2073. StrCat( str, TEXT(";") );
  2074. }
  2075. SendMessage( exts, WM_SETTEXT, 0, (LPARAM)str );
  2076. }
  2077. Button_SetCheck( GetDlgItem( hDlg, IDC_ASSOC_EDIT), !(ptr->m_edit & FTA_OpenIsSafe) );
  2078. EnableWindow( desc, !(ptr->m_safe) );
  2079. EnableWindow( exts, !(ptr->m_safe) );
  2080. EnableWindow( mime, !(ptr->m_safe) );
  2081. EnableWindow( cmnd, !(ptr->m_safe) );
  2082. EnableWindow( brws, !(ptr->m_safe) );
  2083. EnableWindow( edit, !(ptr->m_safe) );
  2084. pgti->fInternalChange = FALSE;
  2085. }
  2086. SetWindowLong(hDlg, DWL_USER, (LPARAM)penter);
  2087. int mimeCount = 0;
  2088. if( mimeList && (mimeCount = DPA_GetPtrCount(mimeList)))
  2089. {
  2090. for(int i=0; i< mimeCount; i++)
  2091. {
  2092. CMime * ptr = (CMime *)DPA_FastGetPtr( mimeList , i );
  2093. SafeAddStringToComboBox( GetDlgItem(hDlg, IDC_DOC_MIME) , ptr->m_mime) ;
  2094. }
  2095. }
  2096. }
  2097. BOOL EnterAssocOnCommand(HWND hDlg, UINT id, UINT nCmd, BOOL *pbChanged)
  2098. {
  2099. switch (id)
  2100. {
  2101. case IDC_BROWSE:
  2102. switch (nCmd )
  2103. {
  2104. case BN_CLICKED:
  2105. {
  2106. FindCommand( hDlg );
  2107. break;
  2108. }
  2109. }
  2110. break;
  2111. case IDOK:
  2112. switch (nCmd )
  2113. {
  2114. case BN_CLICKED:
  2115. {
  2116. SwitchToUpdMode(GetParent(hDlg));
  2117. if (!*pbChanged || AssocEnter(hDlg))
  2118. return EndDialog(hDlg, 0);
  2119. else
  2120. break;
  2121. }
  2122. }
  2123. break;
  2124. case IDCANCEL:
  2125. switch (nCmd )
  2126. {
  2127. case BN_CLICKED:
  2128. {
  2129. return EndDialog(hDlg, 0);
  2130. }
  2131. }
  2132. break;
  2133. case IDC_DOC_MIME:
  2134. switch (nCmd)
  2135. {
  2136. case CBN_SELCHANGE:
  2137. case CBN_EDITCHANGE:
  2138. if (!*pbChanged)
  2139. {
  2140. *pbChanged = TRUE;
  2141. }
  2142. break;
  2143. }
  2144. break;
  2145. case IDC_ASSOC_EDIT:
  2146. switch (nCmd )
  2147. {
  2148. case BN_CLICKED:
  2149. {
  2150. if (!*pbChanged)
  2151. {
  2152. *pbChanged = TRUE;
  2153. }
  2154. break;
  2155. }
  2156. }
  2157. break;
  2158. case IDC_DOC_TYPE:
  2159. case IDC_DOC_EXTS:
  2160. case IDC_DOC_DESC:
  2161. case IDC_DOC_CMND:
  2162. switch (nCmd)
  2163. {
  2164. case EN_CHANGE:
  2165. if (!*pbChanged)
  2166. {
  2167. *pbChanged = TRUE;
  2168. }
  2169. break;
  2170. }
  2171. break;
  2172. }
  2173. return FALSE;
  2174. }
  2175. BOOL CALLBACK EnterAssocDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2176. {
  2177. static BOOL bChanged;
  2178. if (uMsg == WM_INITDIALOG)
  2179. {
  2180. SendMessage(GetDlgItem( hDlg, IDC_DOC_MIME ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0);
  2181. SendMessage(GetDlgItem( hDlg, IDC_DOC_EXTS ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0);
  2182. SendMessage(GetDlgItem( hDlg, IDC_DOC_DESC ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0);
  2183. SendMessage(GetDlgItem( hDlg, IDC_DOC_CMND ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0);
  2184. InitEnterAssocDialog(hDlg, (LPENTERASSOC)lParam);
  2185. bChanged = FALSE;
  2186. }
  2187. switch (uMsg)
  2188. {
  2189. case WM_COMMAND:
  2190. return EnterAssocOnCommand(hDlg, LOWORD(wParam), HIWORD(wParam), &bChanged);
  2191. break;
  2192. }
  2193. return FALSE;
  2194. }