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.

472 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. openfiles.cxx
  7. Open Files Dialog
  8. FILE HISTORY:
  9. chuckc 30-Sep-1991 Created
  10. Yi-HsinS 31-Dec-1991 Unicode Work
  11. */
  12. #define INCL_WINDOWS_GDI
  13. #define INCL_WINDOWS
  14. #define INCL_DOSERRORS
  15. #define INCL_NETERRORS
  16. #define INCL_NETCONS
  17. #define INCL_NETLIB
  18. #define INCL_NETFILE
  19. #define INCL_NETSERVER
  20. #define _WINNETWK_
  21. #include <lmui.hxx>
  22. #undef _WINNETWK_
  23. extern "C"
  24. {
  25. #include <helpnums.h>
  26. #include <opens.h>
  27. #include <winlocal.h>
  28. }
  29. #define INCL_BLT_WINDOW
  30. #define INCL_BLT_CONTROL
  31. #define INCL_BLT_DIALOG
  32. #define INCL_BLT_MSGPOPUP
  33. #define INCL_BLT_MISC
  34. #include <blt.hxx>
  35. #include <string.hxx>
  36. #include <uibuffer.hxx>
  37. #include <uitrace.hxx>
  38. #include <strnumer.hxx>
  39. #include <netname.hxx>
  40. #include <aprompt.hxx>
  41. #include <opens.hxx>
  42. /*******************************************************************
  43. NAME: DisplayOpenFiles
  44. SYNOPSIS: This internal function is called when the user hits
  45. the Open Files button from the properties dialog.
  46. ENTRY: hwndParent - Handle to parent window
  47. wSelectType - What type of selection the user has in the
  48. File manager.
  49. pszResourceName - Name of the resource we are trying to edit
  50. (should be fully qualified).
  51. EXIT:
  52. RETURNS: NERR_Success if successful, appropriate error code otherwise
  53. (we will display any errors that occur).
  54. NOTES:
  55. HISTORY:
  56. Chuckc 30-Sep-1991 Created
  57. ********************************************************************/
  58. APIERR DisplayOpenFiles( HWND hwndParent,
  59. WORD wSelectType,
  60. const TCHAR * pszResourceName )
  61. {
  62. APIERR err ;
  63. BOOL fNT = TRUE ;
  64. NLS_STR nlsServer ;
  65. NLS_STR nlsLocalPath ;
  66. SERVER_WITH_PASSWORD_PROMPT *pServerWithPrompt = NULL ;
  67. // wSelectType is currently not used.
  68. UNREFERENCED(wSelectType) ;
  69. DBGEOL( "#" << pszResourceName << "#" );
  70. TCHAR *p = ::strrchrf(pszResourceName,TCH(' ')) ;
  71. if (p)
  72. *p = TCH('\0') ;
  73. // create a NET_NAME object to analize the name
  74. NET_NAME netName(pszResourceName) ;
  75. err = netName.QueryError() ;
  76. // is it local?
  77. BOOL fIsLocal ;
  78. if (err == NERR_Success)
  79. fIsLocal = netName.IsLocal(&err) ;
  80. // better error mapping if device is something we cannot deal with
  81. if (err==NERR_InvalidDevice)
  82. err = ERROR_NOT_SUPPORTED ;
  83. // get server name
  84. if (err == NERR_Success)
  85. err = netName.QueryComputerName(&nlsServer) ;
  86. if (err == NERR_Success)
  87. err = nlsServer.QueryError() ;
  88. // check if is NT server. at same time, prompt for passwd if need
  89. if (err == NERR_Success)
  90. {
  91. pServerWithPrompt =
  92. new SERVER_WITH_PASSWORD_PROMPT (nlsServer.QueryPch(),
  93. hwndParent,
  94. HC_UI_SHELL_BASE );
  95. err = (pServerWithPrompt == NULL) ?
  96. ERROR_NOT_ENOUGH_MEMORY :
  97. pServerWithPrompt->QueryError() ;
  98. if (err == NERR_Success)
  99. {
  100. if ( !(err = pServerWithPrompt->GetInfo()) )
  101. fNT = pServerWithPrompt->IsNT() ;
  102. else
  103. {
  104. if (err == ERROR_INVALID_LEVEL)
  105. err = ERROR_NOT_SUPPORTED ;
  106. else if (err == IERR_USER_CLICKED_CANCEL)
  107. // if user cancelled, we carry on as far as we can
  108. err = NERR_Success ;
  109. }
  110. }
  111. }
  112. // get local name
  113. if (err == NERR_Success)
  114. err = netName.QueryLocalPath(&nlsLocalPath) ;
  115. if (err == NERR_Success)
  116. err = nlsLocalPath.QueryError() ;
  117. // if we fail at any point above, bag out here
  118. if (err != NERR_Success)
  119. {
  120. delete pServerWithPrompt ;
  121. MsgPopup(hwndParent, err);
  122. return(err) ;
  123. }
  124. // if local drive and not on NT, barf!
  125. if (fIsLocal && !fNT)
  126. {
  127. delete pServerWithPrompt ;
  128. MsgPopup(hwndParent, IDS_NOT_SHAREABLE);
  129. return(NERR_Success) ;
  130. }
  131. // we know path passed in must be x:\foo, so lets just make sure
  132. UIASSERT (nlsServer.strlen() > 0) ;
  133. UIASSERT (nlsLocalPath.strlen() > 0) ;
  134. // create dialog
  135. OPENFILES_DIALOG *pOpenFiles = new OPENFILES_DIALOG (hwndParent,
  136. pszResourceName,
  137. nlsServer.QueryPch(),
  138. nlsLocalPath.QueryPch()) ;
  139. if (pOpenFiles == NULL)
  140. err = ERROR_NOT_ENOUGH_MEMORY ;
  141. if (err == NERR_Success)
  142. err = pOpenFiles->QueryError() ;
  143. if (err == NERR_Success)
  144. err = pOpenFiles->Process() ;
  145. if (err != NERR_Success)
  146. MsgPopup(hwndParent, err) ;
  147. delete pServerWithPrompt ;
  148. delete pOpenFiles ;
  149. return(err) ;
  150. }
  151. /*******************************************************************
  152. NAME: OPENFILES_DIALOG::OPENFILES_DIALOG
  153. SYNOPSIS: constructor for open files dialog
  154. ENTRY:
  155. EXIT:
  156. NOTES:
  157. HISTORY:
  158. chuckc 30-Sep-1991 created
  159. ********************************************************************/
  160. OPENFILES_DIALOG::OPENFILES_DIALOG ( HWND hDlg,
  161. const TCHAR *pszFile,
  162. const TCHAR *pszServer,
  163. const TCHAR *pszBasePath)
  164. : OPEN_DIALOG_BASE( hDlg,
  165. OPENFILES_DLG,
  166. IDD_OF_OPENCOUNT,
  167. IDD_OF_LOCKCOUNT,
  168. IDD_OF_CLOSE,
  169. IDD_OF_CLOSEALL,
  170. pszServer,
  171. pszBasePath,
  172. &_lbFiles),
  173. _slePath(this,IDD_OF_PATH),
  174. _lbFiles( this, IDD_OF_LBOX, pszServer, pszBasePath )
  175. {
  176. // usual check for OK-ness
  177. if (QueryError() != NERR_Success)
  178. return ;
  179. // set the path in the read only SLE.
  180. _slePath.SetText(pszFile) ;
  181. // set the rest of the info
  182. Refresh() ;
  183. // put focus in listbox if anything there, else on OK button
  184. if (_lbFiles.QueryCount() > 0)
  185. _lbFiles.ClaimFocus() ;
  186. else
  187. SetFocus(IDOK) ;
  188. }
  189. /*******************************************************************
  190. NAME: QueryHelpContext
  191. SYNOPSIS: The usual query method for finding out the help context.
  192. RETURNS: Help Context
  193. NOTES:
  194. HISTORY:
  195. Chuckc 30-Sep-1991 Created
  196. ********************************************************************/
  197. ULONG OPENFILES_DIALOG::QueryHelpContext ( void )
  198. {
  199. return HC_OPENFILES;
  200. }
  201. /*******************************************************************
  202. NAME: OPENFILES_LBI::Paint
  203. SYNOPSIS: standard paint method for the OpenFiles LBI
  204. ENTRY:
  205. EXIT:
  206. NOTES:
  207. HISTORY:
  208. chuckc 30-Sep-1991 stolen from server manager, hierarchicalized
  209. and converted to use QueryColumnWidths
  210. beng 22-Apr-1992 Change to LBI::Paint
  211. ********************************************************************/
  212. VOID OPENFILES_LBI :: Paint( LISTBOX *plb,
  213. HDC hdc,
  214. const RECT *prect,
  215. GUILTT_INFO *pGUILTT ) const
  216. {
  217. STR_DTE dteUserName( _nlsUserName.QueryPch() );
  218. STR_DTE dteAccess( _nlsAccess.QueryPch() );
  219. STR_DTE dteLocks( _nlsLocks.QueryPch() );
  220. STR_DTE dteFileID( _nlsID.QueryPch() ) ;
  221. DISPLAY_TABLE dtab( 4, ((OPENFILES_LBOX *)plb)->QueryColumnWidths() );
  222. dtab[0] = &dteUserName;
  223. dtab[1] = &dteAccess;
  224. dtab[2] = &dteLocks;
  225. dtab[3] = &dteFileID;
  226. dtab.Paint( plb, hdc, prect, pGUILTT );
  227. } // OPENFILES_LBI :: Paint
  228. /*******************************************************************
  229. NAME: OPENFILES_LBI::Compare
  230. SYNOPSIS: standard compare method for the OpenFiles LBI
  231. ENTRY:
  232. EXIT:
  233. NOTES:
  234. HISTORY:
  235. chuckc 30-Sep-1991 stolen from server manager
  236. ********************************************************************/
  237. INT OPENFILES_LBI::Compare( const LBI * plbi ) const
  238. {
  239. const NLS_STR * pnls = &(((const OPENFILES_LBI *)plbi)->_nlsUserName);
  240. // no need check above, since error will be returned here as well
  241. return (_nlsUserName._stricmp( *pnls ) ) ;
  242. }
  243. /*******************************************************************
  244. NAME: OPENFILES_LBI::OPENFILES_LBI
  245. SYNOPSIS: constructor for the OpenFiles LBI
  246. ENTRY:
  247. EXIT:
  248. NOTES:
  249. HISTORY:
  250. chuckc 30-Sep-1991 stolen from server manager, hierarchicalized,
  251. and converted to use QueryColumnWidths
  252. beng 06-Apr-1992 Removed wsprintf
  253. ********************************************************************/
  254. OPENFILES_LBI::OPENFILES_LBI( const TCHAR *pszUserName,
  255. const TCHAR *pszPath,
  256. UINT uPermissions,
  257. ULONG cLocks,
  258. ULONG ulFileID)
  259. :OPEN_LBI_BASE( pszUserName,
  260. pszPath,
  261. uPermissions,
  262. cLocks,
  263. ulFileID),
  264. _nlsID(ulFileID)
  265. {
  266. // usual check
  267. if( QueryError() != NERR_Success )
  268. return;
  269. APIERR err ;
  270. if ((err = _nlsID.QueryError()) != NERR_Success)
  271. {
  272. ReportError(err) ;
  273. return ;
  274. }
  275. }
  276. /*******************************************************************
  277. NAME: OPENFILES_LBI::~OPENFILES_LBI
  278. SYNOPSIS: destructor for the OpenFiles LBI
  279. ENTRY:
  280. EXIT:
  281. NOTES:
  282. HISTORY:
  283. chuckc 30-Sep-1991 stolen from server manager, hierarchicalized,
  284. and converted to use QueryColumnWidths
  285. ********************************************************************/
  286. OPENFILES_LBI::~OPENFILES_LBI()
  287. {
  288. ; // nothing more to do
  289. }
  290. /*******************************************************************
  291. NAME: OPENFILES_LBOX::OPENFILES_LBOX
  292. SYNOPSIS: constructor for the OpenFiles LBOX
  293. ENTRY:
  294. EXIT:
  295. NOTES:
  296. HISTORY:
  297. chuckc 30-Sep-1991 stolen from server manager, hierarchicalized,
  298. and converted to use QueryColumnWidths
  299. ********************************************************************/
  300. OPENFILES_LBOX::OPENFILES_LBOX( OWNER_WINDOW *powOwner,
  301. CID cid,
  302. const NLS_STR &nlsServer,
  303. const NLS_STR &nlsBasePath )
  304. : OPEN_LBOX_BASE( powOwner,
  305. cid,
  306. nlsServer,
  307. nlsBasePath )
  308. {
  309. if (QueryError() != NERR_Success)
  310. return ;
  311. //
  312. // Build the column width table to be used by
  313. // OPEN_LBI_BASE :: Paint().
  314. //
  315. DISPLAY_TABLE::CalcColumnWidths( _adx, 4, powOwner, cid, FALSE );
  316. }
  317. /*******************************************************************
  318. NAME: OPENFILES_LBOX::~OPENFILES_LBOX
  319. SYNOPSIS: destructor for the OpenFiles LBOX
  320. ENTRY:
  321. EXIT:
  322. NOTES:
  323. HISTORY:
  324. chuckc 30-Sep-1991 stolen from server manager, hierarchicalized,
  325. and converted to use QueryColumnWidths
  326. ********************************************************************/
  327. OPENFILES_LBOX::~OPENFILES_LBOX()
  328. {
  329. ; // nothing more to do
  330. }
  331. /*******************************************************************
  332. NAME: OPENFILES_LBOX::CreateFileEntry
  333. SYNOPSIS: creates a file lbi entry suitable for this
  334. particular subclass.
  335. ENTRY:
  336. EXIT:
  337. NOTES: virtual method used by parent class.
  338. HISTORY:
  339. chuckc 30-Sep-1991 created
  340. ********************************************************************/
  341. OPEN_LBI_BASE *OPENFILES_LBOX::CreateFileEntry(const FILE3_ENUM_OBJ *pfi3)
  342. {
  343. return
  344. new OPENFILES_LBI(pfi3->QueryUserName(),
  345. pfi3->QueryPathName(),
  346. pfi3->QueryPermissions(),
  347. pfi3->QueryNumLocks(),
  348. pfi3->QueryFileId()) ;
  349. }