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

544 lines
15 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991, 1992 **/
  4. /*****************************************************************/
  5. /*
  6. * mprbrows.hxx
  7. *
  8. * History:
  9. * Yi-HsinS 09-Nov-1992 Created
  10. * Yi-HsinS 01-Mar-1993 Added support for multithreading
  11. *
  12. */
  13. #ifndef _MPRBROWS_HXX_
  14. #define _MPRBROWS_HXX_
  15. extern "C" {
  16. #include <mpr.h>
  17. }
  18. #include <mprdev.hxx>
  19. #include <fontedit.hxx> // get SLE_FONT
  20. #include <hierlb.hxx> // get HIER_LISTBOX
  21. #include <mrucombo.hxx> // get MRUCOMBO
  22. #include <mprthred.hxx> // get MPR_ENUM_THREAD
  23. class MPR_HIER_LISTBOX;
  24. class MPR_LBI_CACHE;
  25. /*************************************************************************
  26. NAME: MPR_LBI
  27. SYNOPSIS: Hierarchical listbox LBI
  28. INTERFACE:
  29. PARENT: HIER_LBI
  30. USES: NLS_STR
  31. CAVEATS:
  32. NOTES:
  33. HISTORY:
  34. Johnl 21-Jan-1992 Commented, cleaned up
  35. beng 22-Apr-1992 Change in LBI::Paint protocol
  36. Yi-HsinS 09-Nov-1992 Added _fRefreshNeeded and methods
  37. **************************************************************************/
  38. class MPR_LBI : public HIER_LBI
  39. {
  40. private:
  41. NETRESOURCE _netres;
  42. NLS_STR _nlsDisplayName; // Name formatted by the provider
  43. BOOL _fRefreshNeeded;
  44. protected:
  45. virtual VOID Paint( LISTBOX * plb, HDC hdc, const RECT * prect,
  46. GUILTT_INFO * pGUILTT ) const ;
  47. virtual WCHAR QueryLeadingChar() const;
  48. public:
  49. MPR_LBI( LPNETRESOURCE lpnetresource );
  50. ~MPR_LBI();
  51. LPNETRESOURCE QueryLPNETRESOURCE( void )
  52. { return &_netres; }
  53. const TCHAR * QueryRemoteName( void ) const
  54. { return _netres.lpRemoteName; }
  55. const TCHAR * QueryLocalName( void ) const
  56. { return _netres.lpLocalName; }
  57. const TCHAR * QueryComment( void ) const
  58. { return _netres.lpComment ; }
  59. const TCHAR * QueryDisplayName( void ) const
  60. { return _nlsDisplayName.QueryPch() ; }
  61. const DWORD QueryDisplayType( void ) const
  62. { return _netres.dwDisplayType ; }
  63. UINT QueryType( void ) const
  64. { return _netres.dwType; }
  65. BOOL IsSearchDialogSupported( void ) const ;
  66. BOOL IsContainer( void ) const ;
  67. BOOL IsConnectable( void ) const ;
  68. BOOL IsProvider( VOID ) const;
  69. BOOL IsRefreshNeeded( VOID ) const
  70. { return _fRefreshNeeded; }
  71. VOID SetRefreshNeeded( BOOL fRefreshNeeded )
  72. { _fRefreshNeeded = fRefreshNeeded; }
  73. virtual INT Compare( const LBI * plbi ) const;
  74. }; // class MPR_LBI
  75. /*************************************************************************
  76. NAME: MPR_HIER_LISTBOX
  77. SYNOPSIS: MPR specific hierarchical list box. Contains the providers
  78. and containers/connections.
  79. INTERFACE:
  80. PARENT: HIER_LISTBOX
  81. USES: DISPLAY_MAP
  82. CAVEATS:
  83. NOTES:
  84. HISTORY:
  85. Johnl 21-Jan-1992 Commented, cleaned up
  86. Yi-HsinS 09-Nov-1992 Added FindItem, FindNextProvider
  87. **************************************************************************/
  88. class MPR_HIER_LISTBOX : public HIER_LISTBOX
  89. {
  90. private:
  91. DISPLAY_MAP _dmapGeneric ; // ie unexpanded
  92. DISPLAY_MAP _dmapGenericExpanded ;
  93. DISPLAY_MAP _dmapGenericNoExpand ; // cannot expand
  94. DISPLAY_MAP _dmapProvider ; // ie unexpanded
  95. DISPLAY_MAP _dmapProviderExpanded ;
  96. DISPLAY_MAP _dmapDomain ; // ie unexpanded
  97. DISPLAY_MAP _dmapDomainExpanded ;
  98. DISPLAY_MAP _dmapDomainNoExpand ; // cannot expand
  99. DISPLAY_MAP _dmapServer ; // ie unexpanded
  100. DISPLAY_MAP _dmapServerExpanded ;
  101. DISPLAY_MAP _dmapServerNoExpand ; // cannot expand
  102. DISPLAY_MAP _dmapShare ; // ie unexpanded
  103. DISPLAY_MAP _dmapShareExpanded ;
  104. DISPLAY_MAP _dmapShareNoExpand ; // cannot expand
  105. DISPLAY_MAP _dmapFile ; // ie unexpanded
  106. DISPLAY_MAP _dmapFileExpanded ;
  107. DISPLAY_MAP _dmapFileNoExpand ; // cannot expand
  108. DISPLAY_MAP _dmapTree ; // ie unexpanded
  109. DISPLAY_MAP _dmapTreeExpanded ;
  110. DISPLAY_MAP _dmapTreeNoExpand ; // cannot expand
  111. DISPLAY_MAP _dmapGroup ; // ie unexpanded
  112. DISPLAY_MAP _dmapGroupExpanded ;
  113. DISPLAY_MAP _dmapGroupNoExpand ; // cannot expand
  114. /* This is the column width table. When an LBI is requested to be painted,
  115. * it copies this table then adjusts the fields appropriately
  116. * depending on the indentation level of the LBI.
  117. */
  118. UINT _adxColumns[4] ;
  119. //
  120. // Set by CalcMaxHorizontalExtent, contains the number of pels in the
  121. // offset of the deepest (most indented) node. Need to adjust
  122. // container column width with this so the comments will line up.
  123. //
  124. UINT _nMaxPelIndent ;
  125. /* Indicates whether we are listing printers or drives
  126. */
  127. UINT _uiType;
  128. /* The average character width
  129. */
  130. INT _nAveCharWidth;
  131. protected:
  132. virtual APIERR AddChildren( HIER_LBI * phlbi );
  133. void SetMaxPelIndent( UINT nMaxPelIndent )
  134. { _nMaxPelIndent = nMaxPelIndent ; }
  135. public:
  136. MPR_HIER_LISTBOX( OWNER_WINDOW * powin, CID cid, UINT uiType );
  137. ~MPR_HIER_LISTBOX() ;
  138. /* Enumerates the network resources in this listbox using the
  139. * parameters (suitable for passing to WNetOpenEnum) and enumerating
  140. * them under the passed LBI.
  141. */
  142. DISPLAY_MAP * QueryDisplayMap( BOOL fIsContainer,
  143. BOOL fIsExpanded,
  144. DWORD dwDisplayType,
  145. BOOL fIsProvider) ;
  146. UINT * QueryColWidthArray( void )
  147. { return _adxColumns ; }
  148. UINT QueryType( VOID ) const
  149. { return _uiType; }
  150. /* Find an item that is on the given indentation level
  151. * and matches the string.
  152. */
  153. INT FindItem( const TCHAR *psz, INT nLevel );
  154. /* Find the next top-level item ( provider) starting from the given index
  155. */
  156. INT FindNextProvider( INT iStart );
  157. /* Return the average char width
  158. */
  159. INT QueryAveCharWidth( VOID ) const
  160. { return _nAveCharWidth; }
  161. void CalcMaxHorizontalExtent( void ) ;
  162. UINT QueryMaxPelIndent( void ) const
  163. { return _nMaxPelIndent ; }
  164. }; // class MPR_HIER_LISTBOX
  165. /*************************************************************************
  166. NAME: MPR_BROWSE_BASE
  167. SYNOPSIS: Base MPR dialog class
  168. INTERFACE:
  169. PARENT: DIALOG_WINDOW
  170. USES: SLT, BLT_LISTBOX, MPR_HIER_LISTBOX
  171. CAVEATS:
  172. NOTES:
  173. HISTORY:
  174. Johnl 21-Jan-1992 Commented, cleaned up, broke into hierarchy
  175. to support separate connection dialogs
  176. Yi-HsinS 09-Nov-1992 Added support for expanding logon domain at
  177. startup
  178. **************************************************************************/
  179. class MPR_BROWSE_BASE : public DIALOG_WINDOW
  180. {
  181. private:
  182. SLT _sltShowLBTitle ;
  183. MPR_HIER_LISTBOX _mprhlbShow; // Server/provider browser
  184. CHECKBOX _boxExpandDomain;
  185. SLE_FONT _sleGetInfo; // Always disabled
  186. PUSH_BUTTON _buttonOK ;
  187. PUSH_BUTTON _buttonSearch ;
  188. // Indicates whether we are listing printers or drives
  189. UINT _uiType;
  190. // Second thread object to retrieve the data
  191. MPR_ENUM_THREAD *_pMprEnumThread;
  192. // Are there any providers that support SearchDialog?
  193. BOOL _fSearchDialogUsed ;
  194. // The name of the Provider to expand
  195. NLS_STR _nlsProviderToExpand;
  196. // The domain the workstation is in
  197. NLS_STR _nlsWkstaDomain;
  198. // help related stuff if passed in
  199. NLS_STR _nlsHelpFile ;
  200. DWORD _nHelpContext ;
  201. //
  202. // As an optimization, the last connectable resource selected by the user
  203. // from the resource listbox is stored here, thus
  204. // when DoConnect is called, the provider information can be provided
  205. // (useful when connecting to non-primary provider). The
  206. // _nlsLastNetPath member must match the resource being connected to,
  207. // else NULL is used for the provider.
  208. //
  209. NLS_STR _nlsLastProvider ;
  210. NLS_STR _nlsLastNetPath ;
  211. protected:
  212. virtual const TCHAR *QueryHelpFile( ULONG nHelpContext );
  213. UINT QueryType( void ) const
  214. { return _uiType ; }
  215. virtual BOOL OnOK( void ) ;
  216. virtual BOOL OnCommand( const CONTROL_EVENT & event );
  217. virtual BOOL OnUserMessage( const EVENT & event );
  218. virtual BOOL MayRun( VOID );
  219. MPR_HIER_LISTBOX * QueryShowLB( void )
  220. { return &_mprhlbShow ; }
  221. PUSH_BUTTON * QueryOKButton( void )
  222. { return &_buttonOK ; }
  223. virtual VOID SetFocusToNetPath( VOID ) = 0;
  224. virtual VOID SetNetPathString( const TCHAR *pszPath ) = 0;
  225. virtual VOID ClearNetPathString( VOID ) = 0;
  226. virtual APIERR OnShowResourcesChange( BOOL fEnumChildren = FALSE );
  227. VOID SetLastProviderInfo( const TCHAR * pszProvider,
  228. const TCHAR * pszNetPath )
  229. { _nlsLastProvider = pszProvider ; _nlsLastNetPath = pszNetPath ; }
  230. const TCHAR * QueryLastProvider( VOID )
  231. { return _nlsLastProvider.QueryPch() ; }
  232. const TCHAR * QueryLastNetPath( VOID )
  233. { return _nlsLastNetPath.QueryPch() ; }
  234. /* Get the user's logged on domain
  235. */
  236. APIERR QueryWkstaDomain( NLS_STR *pnlsWkstaDomain );
  237. /* Get the name of provider to expand
  238. */
  239. APIERR QueryProviderToExpand( NLS_STR *pnlsProvider, BOOL *pfIsNT );
  240. /* Expand the item given
  241. */
  242. BOOL Expand( const TCHAR *psz,
  243. INT nLevel,
  244. MPR_LBI_CACHE *pcache,
  245. BOOL fTopIndex = FALSE );
  246. /* Get and expand the logon domain in the listbox if needed
  247. */
  248. APIERR InitializeLbShow( VOID );
  249. /*
  250. * Return the supplied helpfile name if any
  251. */
  252. const TCHAR *QuerySuppliedHelpFile( VOID )
  253. { return _nlsHelpFile.QueryPch() ; }
  254. /*
  255. * Return the supplied help context if any
  256. */
  257. DWORD QuerySuppliedHelpContext( VOID )
  258. { return _nHelpContext ; }
  259. /*
  260. * call a provider's search dialog
  261. */
  262. void CallSearchDialog( MPR_LBI *pmprlbi ) ;
  263. /*
  264. * Show search dialog on double click if the provider does not support
  265. * WNNC_ENUM_GLOBAL but supports search dialog
  266. */
  267. BOOL ShowSearchDialogOnDoubleClick( MPR_LBI *pmprlbi );
  268. /*
  269. * Enable and show the listbox
  270. */
  271. VOID ShowMprListbox( BOOL fShow );
  272. /*
  273. * check and set the ExpandDomain bit in user profile
  274. */
  275. BOOL IsExpandDomain( VOID );
  276. BOOL SetExpandDomain(BOOL fSave);
  277. /* Protected constructor so only leaf nodes can be constructed.
  278. */
  279. MPR_BROWSE_BASE( const TCHAR *pszDialogName,
  280. HWND hwndOwner,
  281. DEVICE_TYPE devType,
  282. TCHAR *pszHelpFile,
  283. DWORD nHelpIndex) ;
  284. ~MPR_BROWSE_BASE();
  285. }; // class MPR_BROWSE_BASE
  286. /*************************************************************************
  287. NAME: MPR_BROWSE_DIALOG
  288. SYNOPSIS:
  289. INTERFACE:
  290. PARENT: DIALOG_WINDOW
  291. USES:
  292. CAVEATS:
  293. NOTES:
  294. HISTORY:
  295. Yi-HsinS 09-Nov-1992 Created
  296. **************************************************************************/
  297. class MPR_BROWSE_DIALOG : public MPR_BROWSE_BASE
  298. {
  299. private:
  300. SLE _sleNetPath;
  301. NLS_STR *_pnlsPath;
  302. PFUNC_VALIDATION_CALLBACK _pfuncValidation;
  303. protected:
  304. virtual ULONG QueryHelpContext( VOID );
  305. virtual BOOL OnOK( VOID );
  306. public:
  307. MPR_BROWSE_DIALOG( HWND hwndOwner,
  308. DEVICE_TYPE devType,
  309. TCHAR *pszHelpFIle,
  310. DWORD nHelpIndex,
  311. NLS_STR *pnlsPath,
  312. PFUNC_VALIDATION_CALLBACK pfuncValidation );
  313. ~MPR_BROWSE_DIALOG();
  314. virtual VOID SetFocusToNetPath( VOID )
  315. { _sleNetPath.ClaimFocus(); }
  316. virtual VOID SetNetPathString( const TCHAR *pszPath )
  317. { _sleNetPath.SetText( pszPath ); }
  318. virtual VOID ClearNetPathString( VOID )
  319. { _sleNetPath.ClearText(); }
  320. };
  321. /*************************************************************************
  322. NAME: MPR_LBI_CACHE
  323. SYNOPSIS: Simple container class for storing and sorting MPR_LBIs
  324. PARENT: BASE
  325. NOTES: Ownership of the LBI's memory is transferred to here, then
  326. to the listbox.
  327. HISTORY:
  328. Johnl 27-Jan-1993 Created
  329. YiHsinS 01-Mar-1993 Added FindItem, DeleteAllItems
  330. **************************************************************************/
  331. class MPR_LBI_CACHE : public BASE
  332. {
  333. private:
  334. INT _cItems ; // Items in array
  335. INT _cMaxItems ; // Size of array
  336. BUFFER _buffArray ; // Memory for the array
  337. static int __cdecl CompareLbis( const void * p0,
  338. const void * p1 ) ;
  339. public:
  340. MPR_LBI_CACHE( INT cInitialItems = 100 ) ;
  341. ~MPR_LBI_CACHE() ;
  342. //
  343. // Behaves just like LISTBOX::AddItem
  344. //
  345. APIERR AppendItem( MPR_LBI * plbi ) ;
  346. INT FindItem( const TCHAR *psz ) ;
  347. VOID DeleteAllItems( VOID );
  348. void Sort( void ) ;
  349. INT QueryCount( void ) const
  350. { return _cItems ; }
  351. MPR_LBI * * QueryPtr( void )
  352. { return (MPR_LBI**) _buffArray.QueryPtr() ; }
  353. } ;
  354. /* The following are support for multithreading.
  355. * WM_LB_FILLED is the message sent by the worker thread to the dialog.
  356. * MPR_RETURN_CACHE is the structure sent by the worker thread that
  357. * contains the data needed.
  358. */
  359. #define WM_LB_FILLED (WM_USER + 118)
  360. typedef struct {
  361. MPR_LBI_CACHE *pcacheDomain; // Contains the list of domains
  362. MPR_LBI_CACHE *pcacheServer; // Contains the list of servers
  363. } MPR_RETURN_CACHE;
  364. /* Worker routine that does the actual enumeration. ( WNetOpenEnum,
  365. * WNetEnumResource ). Result are either added into the listbox
  366. * ( if pmprlb is not NULL ) or returned in a buffer MPR_LBI_CACHE
  367. * ( if pmprlb is NULL ).
  368. */
  369. APIERR EnumerateShow( HWND hwndOwner,
  370. UINT uiScope,
  371. UINT uiType,
  372. UINT uiUsage,
  373. LPNETRESOURCE lpNetResource,
  374. MPR_LBI *pmprlbi,
  375. MPR_HIER_LISTBOX *pmprlb,
  376. BOOL fDeleteChildren = FALSE,
  377. BOOL *pfSearchDialogUsed = NULL,
  378. MPR_LBI_CACHE **ppmprlbicache = NULL );
  379. #endif // _MPRBROWS_HXX_