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.

1971 lines
44 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. assoc.cxx
  7. This file contains the definitions of
  8. FILE_ASSOCIATION_DIALOG,
  9. TYPE_CREATOR_LISTBOX,
  10. TYPE_CREATOR_LBI,
  11. EXTENSIONS_COMBOBOX,
  12. EXTENSIONS_LBI
  13. History:
  14. NarenG 12/4/92 Created
  15. */
  16. #define INCL_WINDOWS_GDI
  17. #define INCL_WINDOWS
  18. #define INCL_DOSERRORS
  19. #define INCL_NETERRORS
  20. #define INCL_NETSHARE
  21. #define INCL_NETSERVER
  22. #define INCL_NETCONS
  23. #define INCL_NETLIB
  24. #include <lmui.hxx>
  25. #define INCL_BLT_WINDOW
  26. #define INCL_BLT_DIALOG
  27. #define INCL_BLT_CONTROL
  28. #define INCL_BLT_MISC
  29. #define INCL_BLT_CLIENT
  30. #define INCL_BLT_MSGPOPUP
  31. #define INCL_BLT_SPIN_GROUP
  32. #define INCL_BLT_GROUP
  33. #include <blt.hxx>
  34. #if defined(DEBUG)
  35. static const CHAR szFileName[] = __FILE__;
  36. #define _FILENAME_DEFINED_ONCE szFileName
  37. #endif // DEBUG
  38. #include <uiassert.hxx>
  39. extern "C"
  40. {
  41. #include <afpmgr.h>
  42. #include <search.h>
  43. #include <macfile.h>
  44. //
  45. // Compare routine needed for qsort
  46. //
  47. int __cdecl CompareExtensions(
  48. IN const void * pAfpExtension1,
  49. IN const void * pAfpExtension2
  50. );
  51. }
  52. #include <ellipsis.hxx>
  53. #include <string.hxx>
  54. #include <uitrace.hxx>
  55. #include <dbgstr.hxx>
  56. #include <netname.hxx>
  57. #include "assoc.hxx"
  58. /*******************************************************************
  59. NAME: FILE_ASSOCIATION_DIALOG :: FILE_ASSOCIATION_DIALOG
  60. SYNOPSIS: FILE_ASSOCIATION_DIALOG class constructor.
  61. ENTRY: hWndOwner - The owning window.
  62. hServer - Handle used to make admin
  63. API calls.
  64. pszExtension - File extension of current selection.
  65. EXIT: The object is constructed.
  66. HISTORY:
  67. NarenG 12/4/92 Created
  68. ********************************************************************/
  69. FILE_ASSOCIATION_DIALOG :: FILE_ASSOCIATION_DIALOG(
  70. HWND hWndOwner,
  71. AFP_SERVER_HANDLE hServer,
  72. const TCHAR * pszPath,
  73. BOOL fIsFile )
  74. : DIALOG_WINDOW ( MAKEINTRESOURCE( IDD_FILE_ASSOCIATION_DIALOG ), hWndOwner ),
  75. _hServer( hServer ),
  76. _cbExtensions( this, IDFA_CB_EXTENSIONS, AFP_EXTENSION_LEN ),
  77. _lbTypeCreators( this, IDFA_LB_TYPE_CREATORS, hServer ),
  78. _pbAssociate( this, IDFA_PB_ASSOCIATE ),
  79. _pbAdd( this, IDFA_PB_ADD ),
  80. _pbEdit( this, IDFA_PB_EDIT ),
  81. _pbDelete( this, IDFA_PB_DELETE )
  82. {
  83. //
  84. // Let's make sure everything constructed OK.
  85. //
  86. if( QueryError() != NERR_Success )
  87. {
  88. return;
  89. }
  90. APIERR err;
  91. if ( (( err = _cbExtensions.QueryError() ) != NERR_Success ) ||
  92. (( err = _lbTypeCreators.QueryError() ) != NERR_Success ) ||
  93. (( err = _pbAssociate.QueryError() ) != NERR_Success ) ||
  94. (( err = _pbAdd.QueryError() ) != NERR_Success ) ||
  95. (( err = _pbEdit.QueryError() ) != NERR_Success ) ||
  96. (( err = _pbDelete.QueryError() ) != NERR_Success ))
  97. {
  98. ReportError( err );
  99. return;
  100. }
  101. //
  102. // This may take a while
  103. //
  104. AUTO_CURSOR Cursor;
  105. //
  106. // If a path is supplied and the selection is a file, then extract
  107. // the extension and set the SLE.
  108. //
  109. if ( pszPath != NULL && fIsFile )
  110. {
  111. //
  112. // Extract the extension from the file
  113. //
  114. NLS_STR nlsExtension( pszPath );
  115. if ( (err = nlsExtension.QueryError() ) != NERR_Success )
  116. {
  117. ReportError( err );
  118. return;
  119. }
  120. ISTR istrExtension( nlsExtension );
  121. if ( nlsExtension.strrchr( &istrExtension, TEXT('.') ))
  122. {
  123. const TCHAR * pszExtension =
  124. (nlsExtension.QuerySubStr(++istrExtension))->QueryPch();
  125. _cbExtensions.SetText( pszExtension );
  126. }
  127. }
  128. err = BASE_ELLIPSIS::Init();
  129. if( err != NO_ERROR )
  130. {
  131. ReportError( err );
  132. return;
  133. }
  134. //
  135. // Refresh the dialog and select the type/creator that the current
  136. // extension, if there is one, is associated with.
  137. //
  138. err = RefreshAndSelectTC();
  139. if( err != NO_ERROR )
  140. {
  141. ReportError( AFPERR_TO_STRINGID( err ));
  142. return;
  143. }
  144. _cbExtensions.SelectString();
  145. } // FILE_ASSOCIATION_DIALOG :: FILE_ASSOCIATION_DIALOG
  146. /*******************************************************************
  147. NAME: FILE_ASSOCIATION_DIALOG :: ~FILE_ASSOCIATION_DIALOG
  148. SYNOPSIS: FILE_ASSOCIATION_DIALOG class destructor.
  149. EXIT: The object is destroyed.
  150. HISTORY:
  151. NarenG 12/4/92 Created
  152. ********************************************************************/
  153. FILE_ASSOCIATION_DIALOG :: ~FILE_ASSOCIATION_DIALOG()
  154. {
  155. BASE_ELLIPSIS::Term();
  156. }
  157. /*******************************************************************
  158. NAME: FILE_ASSOCIATION_DIALOG :: QueryHelpContext
  159. SYNOPSIS: This function returns the appropriate help context
  160. value (HC_*) for this particular dialog.
  161. RETURNS: ULONG - The help context for this
  162. dialog.
  163. HISTORY:
  164. NarenG 12/4/92 Created
  165. ********************************************************************/
  166. ULONG FILE_ASSOCIATION_DIALOG :: QueryHelpContext( void )
  167. {
  168. return HC_FILE_ASSOCIATION_DIALOG;
  169. } // FILE_ASSOCIATION_DIALOG:: QueryHelpContext
  170. /*******************************************************************
  171. NAME: FILE_ASSOCIATION_DIALOG :: EnableControls
  172. SYNOPSIS: This function handles the enabling/disabling of
  173. the edit and delete buttons.
  174. RETURNS: none
  175. HISTORY:
  176. NarenG 12/4/92 Created
  177. ********************************************************************/
  178. VOID FILE_ASSOCIATION_DIALOG :: EnableControls( BOOL fEnable )
  179. {
  180. if ( fEnable )
  181. {
  182. _pbDelete.Enable( TRUE );
  183. _pbEdit.Enable( TRUE );
  184. _pbEdit.MakeDefault();
  185. }
  186. else
  187. {
  188. if ( _pbEdit.HasFocus() || _pbDelete.HasFocus() )
  189. {
  190. _lbTypeCreators.ClaimFocus();
  191. }
  192. _pbDelete.Enable( FALSE );
  193. _pbEdit.Enable( FALSE );
  194. }
  195. } // FILE_ASSOCIATION_DIALOG :: EnableControls
  196. /*******************************************************************
  197. NAME: FILE_ASSOCIATION_DIALOG :: SelectTypeCreator
  198. SYNOPSIS: This function will call the SelectTypeCreator member
  199. function of the TYPE_CREATOR_LISTBIX class and
  200. enable/disable the delete and edit buttons appropriately.
  201. RETURNS: none
  202. HISTORY:
  203. NarenG 12/4/92 Created
  204. ********************************************************************/
  205. VOID FILE_ASSOCIATION_DIALOG :: SelectTypeCreator( NLS_STR * pnlsType,
  206. NLS_STR * pnlsCreator )
  207. {
  208. DWORD dwIdSelected = _lbTypeCreators.SelectTypeCreator( pnlsType,
  209. pnlsCreator );
  210. if ( ( dwIdSelected != AFP_DEF_TCID ) && ( dwIdSelected != (DWORD)-1 ) )
  211. {
  212. EnableControls( TRUE );
  213. }
  214. else
  215. {
  216. EnableControls( FALSE );
  217. }
  218. } // FILE_ASSOCIATION_DIALOG :: SelectTypeCreator
  219. /*******************************************************************
  220. NAME: FILE_ASSOCIATION_DIALOG :: SelectTypeCreator
  221. SYNOPSIS: This function will call the SelectTypeCreator member
  222. function of the TYPE_CREATOR_LISTBIX class and
  223. enable/disable the delete and edit buttons appropriately.
  224. RETURNS: none
  225. HISTORY:
  226. NarenG 12/4/92 Created
  227. ********************************************************************/
  228. VOID FILE_ASSOCIATION_DIALOG :: SelectTypeCreator( DWORD dwId )
  229. {
  230. DWORD dwIdSelected = _lbTypeCreators.SelectTypeCreator( dwId );
  231. if ( ( dwIdSelected != AFP_DEF_TCID ) && ( dwIdSelected != (DWORD)-1 ) )
  232. {
  233. EnableControls( TRUE );
  234. }
  235. else
  236. {
  237. EnableControls( FALSE );
  238. }
  239. } // FILE_ASSOCIATION_DIALOG :: SelectTypeCreator
  240. /*******************************************************************
  241. NAME: FILE_ASSOCIATION_DIALOG :: OnCommand
  242. SYNOPSIS: This method is called whenever a WM_COMMAND message
  243. is sent to the dialog procedure.
  244. ENTRY: cid - The control ID from the
  245. generating control.
  246. EXIT: The command has been handled.
  247. RETURNS: BOOL - TRUE if we handled the command.
  248. FALSE if we did not handle
  249. the command.
  250. HISTORY:
  251. NarenG 12/4/92 Created
  252. ********************************************************************/
  253. BOOL FILE_ASSOCIATION_DIALOG :: OnCommand( const CONTROL_EVENT & event )
  254. {
  255. if( event.QueryCid() == _cbExtensions.QueryCid() )
  256. {
  257. //
  258. // The COMBOBOX is trying to tell us something...
  259. //
  260. if( event.QueryCode() == CBN_SELCHANGE )
  261. {
  262. //
  263. // The user changed the selection in the COMBOBOX.
  264. // So set focus on type/creator associated with this extension
  265. //
  266. SelectTypeCreator( _cbExtensions.QueryCurrentItemId() );
  267. _pbAssociate.Enable( TRUE );
  268. }
  269. if( event.QueryCode() == CBN_EDITCHANGE )
  270. {
  271. APIERR err;
  272. NLS_STR nlsItemText;
  273. if ( (( err = nlsItemText.QueryError() ) != NERR_Success ) ||
  274. (( err = _cbExtensions.QueryText( &nlsItemText ))
  275. != NERR_Success))
  276. {
  277. ::MsgPopup( this, err );
  278. return FALSE;
  279. }
  280. if ((nlsItemText.QueryPch() == NULL) || (nlsItemText.strlen() == 0))
  281. {
  282. _pbAssociate.Enable( FALSE );
  283. }
  284. else
  285. {
  286. _pbAssociate.Enable( TRUE );
  287. }
  288. //
  289. // The user typed in something in the SLE. Find out if we have
  290. // a match in the combobox.
  291. //
  292. INT Index = _cbExtensions.FindItemExact( nlsItemText );
  293. DWORD dwId;
  294. if ( Index < 0 )
  295. {
  296. dwId = AFP_DEF_TCID;
  297. }
  298. else
  299. {
  300. _cbExtensions.SetTopIndex( Index );
  301. dwId = _cbExtensions.QueryItemId( Index );
  302. }
  303. SelectTypeCreator( dwId );
  304. }
  305. return TRUE;
  306. }
  307. if( event.QueryCid() == _lbTypeCreators.QueryCid() )
  308. {
  309. if( event.QueryCode() == LBN_SELCHANGE )
  310. {
  311. if ( _lbTypeCreators.QueryItem()->QueryId() == AFP_DEF_TCID )
  312. {
  313. EnableControls( FALSE );
  314. }
  315. else
  316. {
  317. EnableControls( TRUE );
  318. }
  319. }
  320. }
  321. if( event.QueryCid() == _pbAssociate.QueryCid() )
  322. {
  323. //
  324. // This may take a while
  325. //
  326. AUTO_CURSOR Cursor;
  327. //
  328. // The user pressed the Associate button. So associate the currently
  329. // selected Extension with the currently selected type/creator.
  330. //
  331. AFP_TYPE_CREATOR AfpTypeCreator;
  332. AFP_EXTENSION AfpExtension;
  333. DWORD err;
  334. NLS_STR nlsItemText;
  335. if ( (( err = nlsItemText.QueryError() ) != NERR_Success ) ||
  336. (( err = _cbExtensions.QueryText(&nlsItemText) ) != NERR_Success))
  337. {
  338. ::MsgPopup( this, err );
  339. return FALSE;
  340. }
  341. ::wcscpy( AfpExtension.afpe_extension, nlsItemText.QueryPch() );
  342. TYPE_CREATOR_LBI * ptclbi = _lbTypeCreators.QueryItem();
  343. ::wcscpy( AfpTypeCreator.afptc_creator, ptclbi->QueryCreator() );
  344. ::wcscpy( AfpTypeCreator.afptc_type, ptclbi->QueryType() );
  345. err = ::AfpAdminETCMapAssociate( _hServer,
  346. &AfpTypeCreator,
  347. &AfpExtension );
  348. if ( err != NO_ERROR )
  349. {
  350. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  351. }
  352. //
  353. // Refresh the dialog
  354. //
  355. err = RefreshAndSelectTC();
  356. if ( err != NO_ERROR )
  357. {
  358. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  359. return FALSE;
  360. }
  361. return TRUE;
  362. }
  363. if( event.QueryCid() == _pbAdd.QueryCid() )
  364. {
  365. //
  366. // The user pressed the Add button. Bring up dialog to allow user
  367. // to add a type/creator pair
  368. //
  369. return TypeCreatorAddDialog();
  370. }
  371. if( event.QueryCid() == _pbEdit.QueryCid() )
  372. {
  373. //
  374. // The user pressed the Edit button. Bring up dialog to allow user
  375. // to edit a type/creator pair.
  376. //
  377. return TypeCreatorEditDialog();
  378. }
  379. if ( event.QueryCid() == _lbTypeCreators.QueryCid() )
  380. {
  381. if ((event.QueryCode() == LBN_DBLCLK) &&
  382. (_lbTypeCreators.QuerySelCount()>0))
  383. {
  384. //
  385. // The user double-clicked on a type/creator. Bring up dialog to
  386. // allow user to edit a type/creator pair.
  387. //
  388. return TypeCreatorEditDialog();
  389. }
  390. }
  391. if( event.QueryCid() == _pbDelete.QueryCid() )
  392. {
  393. //
  394. // This may take a while
  395. //
  396. AUTO_CURSOR Cursor;
  397. //
  398. // The user pressed the Delete button. Delete the currently
  399. // selected type/creator pair
  400. //
  401. //
  402. // First warn the user.
  403. //
  404. if ( ::MsgPopup( this,
  405. IDS_DELETE_TC_CONFIRM,
  406. MPSEV_WARNING,
  407. MP_YESNO,
  408. MP_YES ) == IDNO )
  409. {
  410. return FALSE;
  411. }
  412. AFP_TYPE_CREATOR AfpTypeCreator;
  413. TYPE_CREATOR_LBI * ptclbi = _lbTypeCreators.QueryItem();
  414. ZeroMemory( &AfpTypeCreator, sizeof( AfpTypeCreator ) );
  415. ::wcscpy( AfpTypeCreator.afptc_creator, ptclbi->QueryCreator() );
  416. ::wcscpy( AfpTypeCreator.afptc_type, ptclbi->QueryType() );
  417. DWORD err = ::AfpAdminETCMapDelete( _hServer, &AfpTypeCreator );
  418. if ( err != NO_ERROR )
  419. {
  420. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  421. }
  422. //
  423. // Refresh the dialog.
  424. //
  425. err = Refresh();
  426. if ( err != NO_ERROR )
  427. {
  428. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  429. return FALSE;
  430. }
  431. return TRUE;
  432. }
  433. return DIALOG_WINDOW::OnCommand( event );
  434. }
  435. /*******************************************************************
  436. NAME: FILE_ASSOCIATION_DIALOG :: TypeCreatorAddDialog
  437. SYNOPSIS: Bring up the dialog to add a type/creator
  438. EXIT:
  439. RETURNS: DWORD - Any errors encountered.
  440. HISTORY:
  441. NarenG 7-Dec-1992 Created
  442. *******************************************************************/
  443. BOOL FILE_ASSOCIATION_DIALOG :: TypeCreatorAddDialog( VOID )
  444. {
  445. NLS_STR nlsType;
  446. NLS_STR nlsCreator;
  447. DWORD err;
  448. BOOL fOK = FALSE;
  449. if ( ( ( err = nlsType.QueryError() ) != NERR_Success ) ||
  450. ( ( err = nlsCreator.QueryError() ) != NERR_Success ) )
  451. {
  452. ::MsgPopup( this, err );
  453. return FALSE;
  454. }
  455. TYPE_CREATOR_ADD * ptcadlg = new TYPE_CREATOR_ADD( QueryHwnd(),
  456. _hServer,
  457. &_lbTypeCreators,
  458. &nlsType,
  459. &nlsCreator );
  460. err = ( ptcadlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  461. : ptcadlg->Process( &fOK );
  462. if ( ptcadlg != NULL )
  463. {
  464. delete ptcadlg;
  465. }
  466. if( err != NERR_Success )
  467. {
  468. MsgPopup( this, AFPERR_TO_STRINGID( err ));
  469. return FALSE;
  470. }
  471. //
  472. // Refresh the dialog
  473. //
  474. err = Refresh();
  475. if ( err != NO_ERROR )
  476. {
  477. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  478. return FALSE;
  479. }
  480. if ( fOK )
  481. {
  482. SelectTypeCreator( &nlsType, &nlsCreator );
  483. }
  484. return TRUE;
  485. }
  486. /*******************************************************************
  487. NAME: FILE_ASSOCIATION_DIALOG :: TypeCreatorEditDialog
  488. SYNOPSIS: Bring up the dialog to add a type/creator
  489. EXIT:
  490. RETURNS: DWORD - Any errors encountered.
  491. HISTORY:
  492. NarenG 7-Dec-1992 Created
  493. *******************************************************************/
  494. BOOL FILE_ASSOCIATION_DIALOG :: TypeCreatorEditDialog( VOID )
  495. {
  496. TYPE_CREATOR_LBI * ptclbi = _lbTypeCreators.QueryItem();
  497. //
  498. // Do not allow editing of the default type/creator
  499. //
  500. if ( ptclbi->QueryId() == AFP_DEF_TCID )
  501. {
  502. return FALSE;
  503. }
  504. TYPE_CREATOR_EDIT * ptcedlg = new TYPE_CREATOR_EDIT( QueryHwnd(),
  505. _hServer,
  506. ptclbi );
  507. DWORD err = ( ptcedlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  508. : ptcedlg->Process();
  509. if( err != NERR_Success )
  510. {
  511. MsgPopup( this, AFPERR_TO_STRINGID( err ));
  512. }
  513. if ( ptcedlg != NULL )
  514. {
  515. delete ptcedlg;
  516. }
  517. //
  518. // Refresh the dialog.
  519. //
  520. err = Refresh();
  521. if ( err != NO_ERROR )
  522. {
  523. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  524. return FALSE;
  525. }
  526. return TRUE;
  527. }
  528. /*******************************************************************
  529. NAME: FILE_ASSOCIATION_DIALOG :: Refresh
  530. SYNOPSIS: Refresh the dialog.
  531. EXIT:
  532. RETURNS: DWORD - Any errors encountered.
  533. HISTORY:
  534. NarenG 7-Dec-1992 Created
  535. ********************************************************************/
  536. DWORD FILE_ASSOCIATION_DIALOG :: Refresh( VOID )
  537. {
  538. //
  539. // Find out the type creator that has the current focus.
  540. //
  541. TYPE_CREATOR_LBI * ptclbi = _lbTypeCreators.QueryItem();
  542. DWORD dwId = ( ptclbi == NULL ) ? AFP_DEF_TCID : ptclbi->QueryId();
  543. //
  544. // Find out the extension that has the current focus
  545. //
  546. APIERR err;
  547. NLS_STR nlsCurrentExtension;
  548. if ( (( err = nlsCurrentExtension.QueryError() ) != NERR_Success ) ||
  549. (( err = _cbExtensions.QueryText( &nlsCurrentExtension ))
  550. != NERR_Success))
  551. {
  552. return err;
  553. }
  554. if ( ( err = Update() ) != NO_ERROR )
  555. {
  556. return err;
  557. }
  558. SelectTypeCreator( dwId );
  559. //
  560. // Set the extension to what it was before
  561. //
  562. if ((nlsCurrentExtension.QueryPch() == NULL) ||
  563. (nlsCurrentExtension.strlen() == 0))
  564. {
  565. _pbAssociate.Enable( FALSE );
  566. }
  567. else
  568. {
  569. _cbExtensions.SetText( nlsCurrentExtension );
  570. _pbAssociate.Enable( TRUE );
  571. }
  572. return NO_ERROR;
  573. }
  574. /*******************************************************************
  575. NAME: FILE_ASSOCIATION_DIALOG :: RefreshAndSelectTC
  576. SYNOPSIS: Refresh the dialog and then select the Type/Creator
  577. item that the current extension is associated with..
  578. EXIT:
  579. RETURNS: DWORD - Any errors encountered.
  580. HISTORY:
  581. NarenG 7-Dec-1992 Created
  582. ********************************************************************/
  583. DWORD FILE_ASSOCIATION_DIALOG :: RefreshAndSelectTC( VOID )
  584. {
  585. APIERR err;
  586. if ( ( err = Refresh() ) != NO_ERROR )
  587. {
  588. return err;
  589. }
  590. //
  591. // Get the Type/creator id that the current extension is associated
  592. // with
  593. //
  594. NLS_STR nlsCurrentExtension;
  595. if ( (( err = nlsCurrentExtension.QueryError() ) != NERR_Success ) ||
  596. (( err = _cbExtensions.QueryText( &nlsCurrentExtension ))
  597. != NERR_Success))
  598. {
  599. return err;
  600. }
  601. INT Index = _cbExtensions.FindItemExact( nlsCurrentExtension );
  602. DWORD dwId = ( Index < 0 ) ? AFP_DEF_TCID
  603. : _cbExtensions.QueryItemId( Index );
  604. SelectTypeCreator( dwId );
  605. return NO_ERROR;
  606. }
  607. /*******************************************************************
  608. NAME: FILE_ASSOCIATION_DIALOG :: Update
  609. SYNOPSIS: Updates the dialog with new date.
  610. EXIT:
  611. RETURNS: DWORD - Any errors encountered.
  612. HISTORY:
  613. NarenG 7-Dec-1992 Created
  614. ********************************************************************/
  615. DWORD FILE_ASSOCIATION_DIALOG :: Update( VOID )
  616. {
  617. APIERR err;
  618. PAFP_ETCMAP_INFO pAfpEtcMapInfo = NULL;
  619. //
  620. // Just to be cool...
  621. //
  622. AUTO_CURSOR Cursor;
  623. //
  624. // This is not a loop
  625. //
  626. do {
  627. //
  628. // Get the new data
  629. //
  630. err = ::AfpAdminETCMapGetInfo( _hServer, (LPBYTE *)&pAfpEtcMapInfo );
  631. if ( err != NO_ERROR )
  632. {
  633. break;
  634. }
  635. //
  636. // Update the extensions COMBOBOX.
  637. //
  638. err = _cbExtensions.Update( pAfpEtcMapInfo->afpetc_num_extensions,
  639. pAfpEtcMapInfo->afpetc_extension );
  640. if ( err != NO_ERROR )
  641. {
  642. break;
  643. }
  644. //
  645. // Update the type/creator listbox
  646. //
  647. err = _lbTypeCreators.Update( pAfpEtcMapInfo->afpetc_num_type_creators,
  648. pAfpEtcMapInfo->afpetc_type_creator );
  649. if ( err != NO_ERROR )
  650. {
  651. break;
  652. }
  653. EnableControls( _lbTypeCreators.QueryCount() > 0 );
  654. } while( FALSE );
  655. if ( pAfpEtcMapInfo != NULL )
  656. {
  657. ::AfpAdminBufferFree( pAfpEtcMapInfo );
  658. }
  659. if ( err != NO_ERROR )
  660. {
  661. //
  662. // There was an error refreshing the dialog
  663. // so nuke everything in the TypeCreator & extension listboxes
  664. // then disable the associate, edit and delete buttons.
  665. //
  666. _lbTypeCreators.DeleteAllItems();
  667. _cbExtensions.DeleteAllItems();
  668. EnableControls( FALSE );
  669. }
  670. return err;
  671. } // FILE_ASSOCIATION_DIALOG :: Update
  672. //
  673. // EXTENSION_COMBOBOX methods.
  674. //
  675. /*******************************************************************
  676. NAME: EXTENSION_COMBOBOX :: EXTENSION_COMBOBOX
  677. SYNOPSIS: EXTENSION_COMBOBOX class constructor.
  678. ENTRY: powOwner - The owning window.
  679. cid - The listbox CID.
  680. sleSize - Max. number of sle chars.
  681. EXIT: The object is constructed.
  682. HISTORY:
  683. NarenG 7-Dec-1992 Created
  684. ********************************************************************/
  685. EXTENSION_COMBOBOX :: EXTENSION_COMBOBOX( OWNER_WINDOW * powOwner,
  686. CID cid,
  687. INT sleSize )
  688. : COMBOBOX( powOwner, cid, sleSize ),
  689. _pExtensions( NULL )
  690. {
  691. //
  692. // Ensure we constructed properly.
  693. //
  694. if( QueryError() != NERR_Success )
  695. {
  696. return;
  697. }
  698. }
  699. /*******************************************************************
  700. NAME: EXTENSION_COMBOBOX :: ~EXTENSION_COMBOBOX
  701. SYNOPSIS: EXTENSION_COMBOBOX class destructor.
  702. ENTRY:
  703. EXIT: The object is destroyed.
  704. HISTORY:
  705. NarenG 7-Dec-1992 Created
  706. ********************************************************************/
  707. EXTENSION_COMBOBOX :: ~EXTENSION_COMBOBOX()
  708. {
  709. //
  710. // Delete cache of sorted extensions
  711. //
  712. if ( _pExtensions != NULL )
  713. {
  714. delete [] _pExtensions;
  715. }
  716. _pExtensions = NULL;
  717. } // FEXTENSION_COMBOBOX :: ~EXTENSION_COMBOBOX
  718. /*******************************************************************
  719. NAME: EXTENSION_COMBOBOX :: Update
  720. SYNOPSIS: Updates the combobox.
  721. EXIT: The combobox is updated.
  722. RETURNS: DWORD - Any errors we encounter.
  723. HISTORY:
  724. NarenG 7-Dec-1992 Created
  725. ********************************************************************/
  726. DWORD EXTENSION_COMBOBOX :: Update( DWORD nExtensions,
  727. PAFP_EXTENSION pAfpExtensions )
  728. {
  729. if ( _pExtensions != NULL )
  730. {
  731. delete [] _pExtensions;
  732. }
  733. //
  734. // Store and sort the extensions list.
  735. //
  736. _pExtensions = new AFP_EXTENSION[nExtensions];
  737. if ( _pExtensions == NULL )
  738. {
  739. return ERROR_NOT_ENOUGH_MEMORY;
  740. }
  741. ::CopyMemory( _pExtensions,
  742. pAfpExtensions,
  743. (UINT)(nExtensions * sizeof(AFP_EXTENSION)));
  744. ::qsort( _pExtensions,
  745. (UINT)nExtensions,
  746. sizeof(AFP_EXTENSION),
  747. ::CompareExtensions );
  748. //
  749. // OK, now update the combobox
  750. //
  751. SetRedraw( FALSE );
  752. DeleteAllItems();
  753. //
  754. // For iterating the associated extensions.
  755. //
  756. PAFP_EXTENSION pExtensionIter = _pExtensions;
  757. //
  758. // Iterate the extensions, adding them to the combobox.
  759. //
  760. DWORD err = NO_ERROR;
  761. while( ( err == NO_ERROR ) && ( nExtensions-- ) )
  762. {
  763. if ( AddItem( pExtensionIter->afpe_extension ) < 0 )
  764. {
  765. err = ERROR_NOT_ENOUGH_MEMORY;
  766. break;
  767. }
  768. pExtensionIter++;
  769. }
  770. SetRedraw( TRUE );
  771. Invalidate( TRUE );
  772. return err;
  773. }
  774. /*******************************************************************
  775. NAME: EXTENSION_COMBOBOX :: QueryCurrentItemId
  776. SYNOPSIS: Will return the Type/Creator id the currently
  777. selected extension item is associated with.
  778. ENTRY: none
  779. EXIT:
  780. RETURNS: Type/Creator id
  781. HISTORY:
  782. NarenG 7-Dec-1992 Created
  783. ********************************************************************/
  784. DWORD EXTENSION_COMBOBOX :: QueryCurrentItemId( VOID ) const
  785. {
  786. return QueryItemId( QueryCurrentItem() );
  787. }
  788. /*******************************************************************
  789. NAME: EXTENSION_COMBOBOX :: QueryItemId
  790. SYNOPSIS: Given and index into the extensions list, this will return
  791. the Type/Creator id associated with the indexed extension.
  792. ENTRY: Index - Index of the extension in the combobox
  793. EXIT:
  794. HISTORY:
  795. NarenG 7-Dec-1992 Created
  796. ********************************************************************/
  797. DWORD EXTENSION_COMBOBOX :: QueryItemId( INT Index ) const
  798. {
  799. if( ( Index < 0 ) || ( Index > QueryCount() ) )
  800. {
  801. return AFP_DEF_TCID;
  802. }
  803. else
  804. {
  805. return _pExtensions[Index].afpe_tcid;
  806. }
  807. }
  808. //
  809. // TYPE_CREATOR_LISTBOX methods.
  810. //
  811. /*******************************************************************
  812. NAME: TYPE_CREATOR_LISTBOX :: TYPE_CREATOR_LISTBOX
  813. SYNOPSIS: TYPE_CREATOR_LISTBOX class constructor.
  814. ENTRY: powOwner - The owning window.
  815. cid - The listbox CID.
  816. hServer - The target server.
  817. EXIT: The object is constructed.
  818. HISTORY:
  819. NarenG 7-Dec-1992 Created
  820. ********************************************************************/
  821. TYPE_CREATOR_LISTBOX :: TYPE_CREATOR_LISTBOX( OWNER_WINDOW * powOwner,
  822. CID cid,
  823. AFP_SERVER_HANDLE hServer )
  824. : BLT_LISTBOX( powOwner, cid ),
  825. _hServer( hServer )
  826. {
  827. //
  828. // Ensure we constructed properly.
  829. //
  830. if( QueryError() != NERR_Success )
  831. {
  832. return;
  833. }
  834. //
  835. // Build our column width table.
  836. //
  837. DISPLAY_TABLE::CalcColumnWidths( _adx,
  838. COLS_FA_LB_TYPE_CREATORS,
  839. powOwner,
  840. cid,
  841. FALSE );
  842. } // TYPE_CREATOR_LISTBOX :: TYPE_CREATOR_LISTBOX
  843. /*******************************************************************
  844. NAME: TYPE_CREATOR_LISTBOX :: ~TYPE_CREATOR_LISTBOX
  845. SYNOPSIS: TYPE_CREATOR_LISTBOX class destructor.
  846. EXIT: The object is destroyed.
  847. HISTORY:
  848. NarenG 7-Dec-1992 Created
  849. ********************************************************************/
  850. TYPE_CREATOR_LISTBOX :: ~TYPE_CREATOR_LISTBOX()
  851. {
  852. //
  853. // This space intentionally left blank.
  854. //
  855. } // TYPE_CREATOR_LISTBOX :: ~TYPE_CREATOR_LISTBOX
  856. /*******************************************************************
  857. NAME: TYPE_CREATOR_LISTBOX :: Update
  858. SYNOPSIS: Fills the listbox.
  859. EXIT:
  860. RETURNS: DWORD - Any errors we encounter.
  861. HISTORY:
  862. NarenG 7-Dec-1992 Created
  863. ********************************************************************/
  864. DWORD TYPE_CREATOR_LISTBOX :: Update( DWORD nTypeCreators,
  865. PAFP_TYPE_CREATOR pAfpTypeCreators )
  866. {
  867. //
  868. // Will be set to point to the default type/creator
  869. //
  870. PAFP_TYPE_CREATOR pDefAfpTypeCreator;
  871. //
  872. // let's nuke everything in the listbox.
  873. //
  874. SetRedraw( FALSE );
  875. DeleteAllItems();
  876. //
  877. // Iterate the volumes adding them to the listbox.
  878. //
  879. DWORD err = NO_ERROR;
  880. while( ( err == NO_ERROR ) && ( nTypeCreators-- ) )
  881. {
  882. //
  883. // If this is the default type/creator, do not add it now. It will
  884. // be added as the first item in the end.
  885. //
  886. if ( pAfpTypeCreators->afptc_id == AFP_DEF_TCID )
  887. {
  888. pDefAfpTypeCreator = pAfpTypeCreators;
  889. }
  890. else
  891. {
  892. TYPE_CREATOR_LBI * ptclbi = new TYPE_CREATOR_LBI(pAfpTypeCreators);
  893. if( AddItem( ptclbi ) < 0 )
  894. {
  895. err = ERROR_NOT_ENOUGH_MEMORY;
  896. }
  897. }
  898. pAfpTypeCreators++;
  899. }
  900. //
  901. // Now add the default if there were no errors.
  902. //
  903. if ( err == NO_ERROR )
  904. {
  905. TYPE_CREATOR_LBI * ptclbi = new TYPE_CREATOR_LBI(pDefAfpTypeCreator);
  906. if ( InsertItemData( 0, ptclbi ) < 0 )
  907. {
  908. err = ERROR_NOT_ENOUGH_MEMORY;
  909. }
  910. }
  911. SetRedraw( TRUE );
  912. Invalidate( TRUE );
  913. return err;
  914. } // TYPE_CREATOR_LISBOX :: Refresh
  915. /*******************************************************************
  916. NAME: TYPE_CREATOR_LISTBOX :: SelectTypeCreator
  917. SYNOPSIS: Given a Type/Creator this procedure will set focus on
  918. that item.
  919. EXIT:
  920. RETURNS: DWORD - Any errors we encounter.
  921. HISTORY:
  922. NarenG 7-Dec-1992 Created
  923. ********************************************************************/
  924. DWORD TYPE_CREATOR_LISTBOX :: SelectTypeCreator( NLS_STR * pnlsType,
  925. NLS_STR * pnlsCreator )
  926. {
  927. INT ItemCount = QueryCount();
  928. INT Index;
  929. TYPE_CREATOR_LBI * ptclbi;
  930. if ( ItemCount == 0 )
  931. {
  932. return (DWORD)-1;
  933. }
  934. for( Index = 0; Index < ItemCount; Index++ )
  935. {
  936. ptclbi = QueryItem( Index );
  937. if ( pnlsType->strcmp( ptclbi->QueryType() ) == 0 )
  938. {
  939. if ( pnlsCreator->strcmp( ptclbi->QueryCreator() ) == 0 )
  940. {
  941. SelectItem( Index );
  942. return ptclbi->QueryId();
  943. }
  944. }
  945. }
  946. SelectItem( 0 );
  947. return AFP_DEF_TCID;
  948. }
  949. /*******************************************************************
  950. NAME: TYPE_CREATOR_LISTBOX :: SelectTypeCreator
  951. SYNOPSIS: Given an extension id, this procedure will set focus on
  952. that item in the type/creator listbox.
  953. EXIT:
  954. RETURNS: DWORD - Any errors we encounter.
  955. HISTORY:
  956. NarenG 7-Dec-1992 Created
  957. ********************************************************************/
  958. DWORD TYPE_CREATOR_LISTBOX :: SelectTypeCreator( DWORD dwId )
  959. {
  960. INT ItemCount = QueryCount();
  961. INT Index;
  962. TYPE_CREATOR_LBI * ptclbi;
  963. if ( ItemCount == 0 )
  964. {
  965. return (DWORD)-1;
  966. }
  967. for( Index = 0; Index < ItemCount; Index++ )
  968. {
  969. ptclbi = QueryItem( Index );
  970. if ( ptclbi->QueryId() == dwId )
  971. {
  972. SelectItem( Index );
  973. return dwId;
  974. }
  975. }
  976. SelectItem( 0 );
  977. return AFP_DEF_TCID;
  978. }
  979. //
  980. // TYPE_CREATOR_LBI methods.
  981. //
  982. /*******************************************************************
  983. NAME: TYPE_CREATOR_LBI :: TYPE_CREATOR_LBI
  984. SYNOPSIS: TYPE_CREATOR_LBI class constructor.
  985. ENTRY: pszVolumeName - The sharepoint name.
  986. pszPath - The path for this sharepoint.
  987. cUses - Number of uses for this share.
  988. EXIT: The object is constructed.
  989. HISTORY:
  990. NarenG 12/4/92 Created
  991. ********************************************************************/
  992. TYPE_CREATOR_LBI :: TYPE_CREATOR_LBI( PAFP_TYPE_CREATOR pAfpTypeCreator )
  993. : _nlsType( pAfpTypeCreator->afptc_type),
  994. _nlsCreator(pAfpTypeCreator->afptc_creator),
  995. _nlsComment(pAfpTypeCreator->afptc_comment),
  996. _dwId( pAfpTypeCreator->afptc_id )
  997. {
  998. //
  999. // Ensure we constructed properly.
  1000. //
  1001. if( QueryError() != NERR_Success )
  1002. {
  1003. return;
  1004. }
  1005. APIERR err;
  1006. if ((( err = _nlsType.QueryError() ) != NERR_Success ) ||
  1007. (( err = _nlsCreator.QueryError() ) != NERR_Success ) ||
  1008. (( err = _nlsComment.QueryError() ) != NERR_Success ) )
  1009. {
  1010. ReportError( err );
  1011. return;
  1012. }
  1013. } // TYPE_CREATOR_LBI :: TYPE_CREATOR_LBI
  1014. /*******************************************************************
  1015. NAME: TYPE_CREATOR_LBI :: ~TYPE_CREATOR_LBI
  1016. SYNOPSIS: TYPE_CREATOR_LBI class destructor.
  1017. EXIT: The object is destroyed.
  1018. HISTORY:
  1019. NarenG 7-Dec-1992 Created
  1020. ********************************************************************/
  1021. TYPE_CREATOR_LBI :: ~TYPE_CREATOR_LBI()
  1022. {
  1023. //
  1024. // Intentionally left blank
  1025. //
  1026. } // TYPE_CREATOR_LBI :: ~TYPE_CREATOR_LBI
  1027. /*******************************************************************
  1028. NAME: TYPE_CREATOR_LBI :: Paint
  1029. SYNOPSIS: Draw an entry in VOLUMES_LISTBOX.
  1030. ENTRY: plb - Pointer to a BLT_LISTBOX.
  1031. hdc - The DC to draw upon.
  1032. prect - Clipping rectangle.
  1033. pGUILTT - GUILTT info.
  1034. EXIT: The item is drawn.
  1035. HISTORY:
  1036. NarenG 7-Dec-1992 Created
  1037. ********************************************************************/
  1038. VOID TYPE_CREATOR_LBI :: Paint( LISTBOX * plb,
  1039. HDC hdc,
  1040. const RECT * prect,
  1041. GUILTT_INFO * pGUILTT ) const
  1042. {
  1043. STR_DTE dteCreator( _nlsCreator.QueryPch() );
  1044. STR_DTE dteType( _nlsType.QueryPch() );
  1045. STR_DTE_ELLIPSIS dteComment(_nlsComment.QueryPch(),plb,ELLIPSIS_RIGHT);
  1046. DISPLAY_TABLE dtab( COLS_FA_LB_TYPE_CREATORS,
  1047. ((TYPE_CREATOR_LISTBOX *)plb)->QueryColumnWidths() );
  1048. dtab[0] = &dteCreator;
  1049. dtab[1] = &dteType;
  1050. dtab[2] = &dteComment;
  1051. dtab.Paint( plb, hdc, prect, pGUILTT );
  1052. } // TYPE_CREATOR_LBI :: Paint
  1053. /*******************************************************************
  1054. NAME: TYPE_CREATOR_LBI :: QueryLeadingChar
  1055. SYNOPSIS: Returns the first character in the resource name.
  1056. This is used for the listbox keyboard interface.
  1057. RETURNS: WCHAR - The first character in the
  1058. resource name.
  1059. HISTORY:
  1060. NarenG 7-Dec-1992 Created
  1061. ********************************************************************/
  1062. WCHAR TYPE_CREATOR_LBI :: QueryLeadingChar( VOID ) const
  1063. {
  1064. ISTR istr( _nlsCreator );
  1065. return _nlsCreator.QueryChar( istr );
  1066. } // TYPE_CREATOR_LBI :: QueryLeadingChar
  1067. /*******************************************************************
  1068. NAME: TYPE_CREATOR_LBI :: Compare
  1069. SYNOPSIS: Compare two BASE_RES_LBI items.
  1070. ENTRY: plbi - The LBI to compare against.
  1071. RETURNS: INT - The result of the compare
  1072. ( <0 , ==0 , >0 ).
  1073. HISTORY:
  1074. NarenG 7-Dec-1992 Created
  1075. ********************************************************************/
  1076. INT TYPE_CREATOR_LBI :: Compare( const LBI * plbi ) const
  1077. {
  1078. INT Result = _nlsCreator._stricmp(
  1079. ((const TYPE_CREATOR_LBI *)plbi)->_nlsCreator );
  1080. if ( Result == 0 )
  1081. {
  1082. return _nlsType._stricmp(
  1083. ((const TYPE_CREATOR_LBI *)plbi)->_nlsType );
  1084. }
  1085. else
  1086. return Result;
  1087. } // TYPE_CREATOR_LBI :: Compare
  1088. /*******************************************************************
  1089. NAME: CompareExtensions
  1090. SYNOPSIS: Compare routine for qsort call.
  1091. ENTRY:
  1092. RETURNS: < 0 if pAfpExtension1 comes before pAfpExtension2
  1093. > 0 if pAfpExtension1 comes before pAfpExtension2
  1094. == 0 if pAfpExtension1 is equal to pAfpExtension2
  1095. HISTORY:
  1096. NarenG 7-Dec-1992 Created
  1097. ********************************************************************/
  1098. int __cdecl
  1099. CompareExtensions(
  1100. IN const void * pAfpExtension1,
  1101. IN const void * pAfpExtension2
  1102. )
  1103. {
  1104. return( ::stricmpf(((PAFP_EXTENSION)pAfpExtension1)->afpe_extension,
  1105. ((PAFP_EXTENSION)pAfpExtension2)->afpe_extension ));
  1106. }
  1107. /*******************************************************************
  1108. NAME: TYPE_CREATOR_ADD :: TYPE_CREATOR_ADD
  1109. SYNOPSIS: TYPE_CREATOR_ADD class constructor.
  1110. ENTRY: hWndOwner - The owning window.
  1111. hServer - Handle used to make admin
  1112. API calls.
  1113. ptclb * - Pointer to the list of type/creators
  1114. EXIT: The object is constructed.
  1115. HISTORY:
  1116. NarenG 12/4/92 Created
  1117. ********************************************************************/
  1118. TYPE_CREATOR_ADD :: TYPE_CREATOR_ADD( HWND hWndOwner,
  1119. AFP_SERVER_HANDLE hServer,
  1120. TYPE_CREATOR_LISTBOX * ptclb,
  1121. NLS_STR * pnlsType,
  1122. NLS_STR * pnlsCreator )
  1123. : DIALOG_WINDOW( MAKEINTRESOURCE(IDD_TYPE_CREATOR_ADD_DIALOG), hWndOwner ),
  1124. _hServer( hServer ),
  1125. _sleComment( this, IDTA_SLE_DESCRIPTION, AFP_ETC_COMMENT_LEN ),
  1126. _cbTypes( this, IDTA_CB_TYPE , AFP_TYPE_LEN ),
  1127. _cbCreators( this, IDTA_CB_CREATOR, AFP_CREATOR_LEN ),
  1128. _pnlsType( pnlsType ),
  1129. _pnlsCreator( pnlsCreator )
  1130. {
  1131. //
  1132. // Let's make sure everything constructed OK.
  1133. //
  1134. if ( QueryError() != NERR_Success )
  1135. {
  1136. return;
  1137. }
  1138. DWORD err;
  1139. if ( (( err = _sleComment.QueryError() ) != NERR_Success ) ||
  1140. (( err = _cbTypes.QueryError() ) != NERR_Success ) ||
  1141. (( err = _cbCreators.QueryError() ) != NERR_Success ))
  1142. {
  1143. ReportError( err );
  1144. return;
  1145. }
  1146. //
  1147. // This may take a while
  1148. //
  1149. AUTO_CURSOR Cursor;
  1150. //
  1151. // Fill up the COMBOBOXes
  1152. //
  1153. DWORD nItems = ptclb->QueryCount();
  1154. DWORD Count;
  1155. for ( Count = 0; Count < nItems; Count++ )
  1156. {
  1157. TYPE_CREATOR_LBI * ptclbi = ptclb->QueryItem( (INT)Count );
  1158. if ( _cbTypes.AddItemIdemp( ptclbi->QueryType() ) < 0 )
  1159. {
  1160. err = ERROR_NOT_ENOUGH_MEMORY;
  1161. break;
  1162. }
  1163. if ( _cbCreators.AddItemIdemp( ptclbi->QueryCreator() ) < 0 )
  1164. {
  1165. err = ERROR_NOT_ENOUGH_MEMORY;
  1166. break;
  1167. }
  1168. }
  1169. if ( err != NERR_Success )
  1170. {
  1171. ReportError( err );
  1172. return;
  1173. }
  1174. _cbCreators.ClaimFocus();
  1175. }
  1176. /*******************************************************************
  1177. NAME: TYPE_CREATOR_ADD :: OnOK
  1178. SYNOPSIS: Gather all information and Add the type creator pair
  1179. ENTRY:
  1180. EXIT:
  1181. RETURNS:
  1182. NOTES:
  1183. HISTORY:
  1184. NarenG 12/14/92 Created
  1185. ********************************************************************/
  1186. BOOL TYPE_CREATOR_ADD :: OnOK( VOID )
  1187. {
  1188. APIERR err;
  1189. NLS_STR nlsType;
  1190. NLS_STR nlsCreator;
  1191. NLS_STR nlsComment;
  1192. //
  1193. // This may take a while
  1194. //
  1195. AUTO_CURSOR Cursor;
  1196. if ( (( err = nlsType.QueryError() ) != NERR_Success ) ||
  1197. (( err = nlsCreator.QueryError() ) != NERR_Success ) ||
  1198. (( err = nlsComment.QueryError() ) != NERR_Success ) ||
  1199. (( err = _cbTypes.QueryText( &nlsType ) ) != NERR_Success ) ||
  1200. (( err = _cbCreators.QueryText( &nlsCreator ) ) != NERR_Success ) ||
  1201. (( err = _sleComment.QueryText( &nlsComment ) ) != NERR_Success ))
  1202. {
  1203. ::MsgPopup( this, err );
  1204. Dismiss( FALSE );
  1205. return FALSE;
  1206. }
  1207. //
  1208. // Validate all the information
  1209. //
  1210. AFP_TYPE_CREATOR AfpTypeCreator;
  1211. if ( nlsCreator.strlen() == 0 )
  1212. {
  1213. ::MsgPopup( this, IDS_NEED_TYPE_CREATOR );
  1214. _cbCreators.ClaimFocus();
  1215. return FALSE;
  1216. }
  1217. if ( nlsType.strlen() == 0 )
  1218. {
  1219. ::MsgPopup( this, IDS_NEED_TYPE_CREATOR );
  1220. _cbTypes.ClaimFocus();
  1221. return FALSE;
  1222. }
  1223. ::wcscpy( AfpTypeCreator.afptc_creator, nlsCreator.QueryPch() );
  1224. ::wcscpy( AfpTypeCreator.afptc_type, nlsType.QueryPch() );
  1225. ::wcscpy( AfpTypeCreator.afptc_comment, nlsComment.QueryPch() );
  1226. err = ::AfpAdminETCMapAdd( _hServer, &AfpTypeCreator );
  1227. if ( err != NO_ERROR )
  1228. {
  1229. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  1230. return FALSE;
  1231. }
  1232. _pnlsType->CopyFrom( nlsType );
  1233. _pnlsCreator->CopyFrom( nlsCreator );
  1234. Dismiss( TRUE );
  1235. return TRUE;
  1236. }
  1237. /*******************************************************************
  1238. NAME: TYPE_CREATOR_ADD :: QueryHelpContext
  1239. SYNOPSIS: This function returns the appropriate help context
  1240. value (HC_*) for this particular dialog.
  1241. RETURNS: ULONG - The help context for this
  1242. dialog.
  1243. HISTORY:
  1244. NarenG 12/4/92 Created
  1245. ********************************************************************/
  1246. ULONG TYPE_CREATOR_ADD :: QueryHelpContext( void )
  1247. {
  1248. return HC_TYPE_CREATOR_ADD;
  1249. } // TYPE_CREATOR_ADD:: QueryHelpContext
  1250. /*******************************************************************
  1251. NAME: TYPE_CREATOR_EDIT :: TYPE_CREATOR_EDIT
  1252. SYNOPSIS: TYPE_CREATOR_EDIT class constructor.
  1253. ENTRY: hWndOwner - The owning window.
  1254. hServer - Handle used to make admin
  1255. API calls.
  1256. ptclbi * - Pointer to the selected type/creator
  1257. EXIT: The object is constructed.
  1258. HISTORY:
  1259. NarenG 12/4/92 Created
  1260. ********************************************************************/
  1261. TYPE_CREATOR_EDIT :: TYPE_CREATOR_EDIT( HWND hWndOwner,
  1262. AFP_SERVER_HANDLE hServer,
  1263. TYPE_CREATOR_LBI * ptclbi )
  1264. : DIALOG_WINDOW( MAKEINTRESOURCE(IDD_TYPE_CREATOR_EDIT_DIALOG), hWndOwner ),
  1265. _hServer( hServer ),
  1266. _sleComment( this, IDTE_SLE_DESCRIPTION, AFP_ETC_COMMENT_LEN ),
  1267. _sltType( this, IDTE_SLE_TYPE ),
  1268. _sltCreator( this, IDTE_SLE_CREATOR )
  1269. {
  1270. //
  1271. // Let's make sure everything constructed OK.
  1272. //
  1273. if ( QueryError() != NERR_Success )
  1274. {
  1275. return;
  1276. }
  1277. DWORD err;
  1278. NLS_STR nlsAmp( TEXT("&") );
  1279. NLS_STR nlsType( ptclbi->QueryType() );
  1280. NLS_STR nlsCreator( ptclbi->QueryCreator() );
  1281. if ( (( err = _sleComment.QueryError() ) != NERR_Success ) ||
  1282. (( err = _sltType.QueryError() ) != NERR_Success ) ||
  1283. (( err = nlsType.QueryError() ) != NERR_Success ) ||
  1284. (( err = nlsCreator.QueryError() ) != NERR_Success ) ||
  1285. (( err = nlsAmp.QueryError() ) != NERR_Success ) ||
  1286. (( err = _sltCreator.QueryError() ) != NERR_Success ))
  1287. {
  1288. ReportError( err );
  1289. return;
  1290. }
  1291. //
  1292. // Add an extra & for every & found in the type and creator,
  1293. // otherwise the character following the & will become a hotkey.
  1294. //
  1295. ISTR istrPosType( nlsType );
  1296. ISTR istrStartType( nlsType );
  1297. while ( nlsType.strstr( &istrPosType, nlsAmp, istrStartType ) )
  1298. {
  1299. nlsType.InsertStr( nlsAmp, ++istrPosType );
  1300. istrStartType = ++istrPosType;
  1301. }
  1302. _sltType.SetText( nlsType );
  1303. ISTR istrPosCreator( nlsCreator );
  1304. ISTR istrStartCreator( nlsCreator );
  1305. while ( nlsCreator.strstr( &istrPosCreator, nlsAmp, istrStartCreator ) )
  1306. {
  1307. nlsCreator.InsertStr( nlsAmp, ++istrPosCreator );
  1308. istrStartCreator = ++istrPosCreator;
  1309. }
  1310. _sltCreator.SetText( nlsCreator );
  1311. _sleComment.SetText( ptclbi->QueryComment() );
  1312. _sleComment.SelectString();
  1313. }
  1314. /*******************************************************************
  1315. NAME: TYPE_CREATOR_EDIT :: OnOK
  1316. SYNOPSIS: Gather all information and set the type/creator information.
  1317. ENTRY:
  1318. EXIT:
  1319. RETURNS:
  1320. NOTES:
  1321. HISTORY:
  1322. NarenG 12/14/92 Created
  1323. ********************************************************************/
  1324. BOOL TYPE_CREATOR_EDIT :: OnOK( VOID )
  1325. {
  1326. APIERR err;
  1327. NLS_STR nlsType;
  1328. NLS_STR nlsCreator;
  1329. NLS_STR nlsComment;
  1330. //
  1331. // This may take a while
  1332. //
  1333. AUTO_CURSOR Cursor;
  1334. if ( (( err = nlsType.QueryError() ) != NERR_Success ) ||
  1335. (( err = nlsCreator.QueryError() ) != NERR_Success ) ||
  1336. (( err = nlsComment.QueryError() ) != NERR_Success ) ||
  1337. (( err = _sltType.QueryText( &nlsType ) ) != NERR_Success ) ||
  1338. (( err = _sltCreator.QueryText( &nlsCreator ) ) != NERR_Success ) ||
  1339. (( err = _sleComment.QueryText( &nlsComment ) ) != NERR_Success ))
  1340. {
  1341. ::MsgPopup( this, err );
  1342. Dismiss( FALSE );
  1343. return FALSE;
  1344. }
  1345. //
  1346. // Validate all the information
  1347. //
  1348. AFP_TYPE_CREATOR AfpTypeCreator;
  1349. ::wcscpy( AfpTypeCreator.afptc_creator, nlsCreator.QueryPch() );
  1350. ::wcscpy( AfpTypeCreator.afptc_type, nlsType.QueryPch() );
  1351. ::wcscpy( AfpTypeCreator.afptc_comment, nlsComment.QueryPch() );
  1352. err = ::AfpAdminETCMapSetInfo( _hServer, &AfpTypeCreator );
  1353. if ( err != NO_ERROR )
  1354. {
  1355. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  1356. Dismiss( FALSE );
  1357. return FALSE;
  1358. }
  1359. Dismiss( TRUE );
  1360. return TRUE;
  1361. }
  1362. /*******************************************************************
  1363. NAME: TYPE_CREATOR_EDIT :: QueryHelpContext
  1364. SYNOPSIS: This function returns the appropriate help context
  1365. value (HC_*) for this particular dialog.
  1366. RETURNS: ULONG - The help context for this
  1367. dialog.
  1368. HISTORY:
  1369. NarenG 12/4/92 Created
  1370. ********************************************************************/
  1371. ULONG TYPE_CREATOR_EDIT :: QueryHelpContext( void )
  1372. {
  1373. return HC_TYPE_CREATOR_EDIT;
  1374. } // TYPE_CREATOR_EDIT:: QueryHelpContext