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.

645 lines
16 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1990 - 1999
  3. All rights reserved
  4. Module Name:
  5. browse.hxx
  6. Abstract:
  7. Header file for browse for pinter dialog
  8. Author:
  9. Dave Snipp (DaveSn) 15 Mar 1991
  10. Steve Kiraly (SteveKi) 1 May 1998
  11. Environment:
  12. User Mode Win32
  13. Revision History:
  14. 1 May 1998 move from winspoo.drv to printui.dll
  15. --*/
  16. #ifndef _BROWSE_HXX_
  17. #define _BROWSE_HXX_
  18. /*
  19. * IDs passed to WinHelp:
  20. */
  21. #define IDH_PRT_CTP_PRINTER 76000 // Printer
  22. #define IDH_PRT_CTP_SHARED_PRINTERS 76010 // Shared Printers
  23. #define IDH_PRT_CTP_EXPAND_DEFAULT 76020 // Expand by Default checkbox
  24. #define IDH_PRT_CTP_DESCRIPTION 76030 // Printer Info group--Description
  25. #define IDH_PRT_CTP_STATUS 76040 // Printer Info group--Status
  26. #define IDH_PRT_CTP_DOCS_WAITING 76050 // Printer Info group--Documents Waiting
  27. #define IDH_NOHELP ((DWORD)-1) // Disables Help for a control (for help compiles)
  28. /* Space for 21x16 status bitmaps:
  29. */
  30. #define STATUS_BITMAP_WIDTH 21
  31. #define STATUS_BITMAP_HEIGHT 16
  32. #define STATUS_BITMAP_MARGIN 4 /* (either side) */
  33. #define STATUS_BITMAP_SPACE ( STATUS_BITMAP_WIDTH + ( 2 * STATUS_BITMAP_MARGIN ) )
  34. #define PRINTER_STATUS_UNKNOWN 8000
  35. #define BM_IND_CONNECTTO_DOMPLUS 0
  36. #define BM_IND_CONNECTTO_DOMEXPAND ( 2 * STATUS_BITMAP_HEIGHT )
  37. #define BROWSE_THREAD_ENUM_OBJECTS 1
  38. #define BROWSE_THREAD_GET_PRINTER 2
  39. #define BROWSE_THREAD_TERMINATE 4
  40. #define BROWSE_THREAD_DELETE 8
  41. #define WM_ENUM_OBJECTS_COMPLETE WM_APP+0x10
  42. #define WM_GET_PRINTER_COMPLETE WM_APP+0x11
  43. #define WM_GET_PRINTER_ERROR WM_APP+0x12
  44. #define WM_QUIT_BROWSE WM_APP+0x14
  45. #define EMPTY_CONTAINER (PCONNECTTO_OBJECT)(-1)
  46. #define BACKGROUND 0x0000FF00 // bright green
  47. #define BACKGROUNDSEL 0x00FF00FF // bright magenta
  48. #define BUTTONFACE 0x00C0C0C0 // bright grey
  49. #define BUTTONSHADOW 0x00808080 // dark grey
  50. #define SPOOLER_VERSION 3
  51. //
  52. // Define some constants to make parameters to CreateEvent a tad less obscure:
  53. //
  54. #define EVENT_RESET_MANUAL TRUE
  55. #define EVENT_RESET_AUTOMATIC FALSE
  56. #define EVENT_INITIAL_STATE_SIGNALED TRUE
  57. #define EVENT_INITIAL_STATE_NOT_SIGNALED FALSE
  58. #define OUTPUT_BUFFER_LENGTH 512
  59. #define COLUMN_SEPARATOR_WIDTH 4
  60. #define COLUMN_WIDTH 180
  61. #define BROWSE_STATUS_INITIAL 0x00000001
  62. #define BROWSE_STATUS_EXPAND 0x00000002
  63. #define GET_BROWSE_DLG_DATA(hwnd) \
  64. reinterpret_cast<PBROWSE_DLG_DATA>(GetWindowLongPtr(hwnd, GWLP_USERDATA))
  65. #define SET_BROWSE_DLG_DATA(hwnd, pBrowseDlgData) \
  66. SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<ULONG_PTR>(pBrowseDlgData))
  67. #define GET_CONNECTTO_DATA( hwnd ) (GET_BROWSE_DLG_DATA( hwnd ))->pConnectToData
  68. #define ADDCOMBOSTRING(hwnd, id, string) \
  69. SendDlgItemMessage(hwnd, id, CB_ADDSTRING, 0, (LONG)string)
  70. #define INSERTCOMBOSTRING(hwnd, id, i, string) \
  71. SendDlgItemMessage(hwnd, id, CB_INSERTSTRING, i, (LONG)string)
  72. #define SETCOMBOSELECT(hwnd, id, i) \
  73. SendDlgItemMessage(hwnd, id, CB_SETCURSEL, (WPARAM)i, 0L)
  74. #define GETCOMBOSELECT(hwnd, id) \
  75. SendDlgItemMessage(hwnd, id, CB_GETCURSEL, 0, 0L)
  76. #define GETCOMBOTEXT(hwnd, id, i, string) \
  77. SendDlgItemMessage(hwnd, id, CB_GETLBTEXT, (WPARAM)i, (LONG)string)
  78. #define SETLISTCOUNT(hwnd, Count) \
  79. SendDlgItemMessage(hwnd, IDD_BROWSE_SELECT_LB, LB_SETCOUNT, Count, 0)
  80. #define GETLISTCOUNT(hwnd) \
  81. SendDlgItemMessage(hwnd, IDD_BROWSE_SELECT_LB, LB_GETCOUNT, 0, 0)
  82. #define SETLISTSEL(hwnd, Sel) \
  83. SendDlgItemMessage(hwnd, IDD_BROWSE_SELECT_LB, LB_SETCURSEL, Sel, 0)
  84. #define GETLISTSEL(hwnd) \
  85. SendDlgItemMessage(hwnd, IDD_BROWSE_SELECT_LB, LB_GETCURSEL, 0, 0)
  86. #define ENABLE_LIST(hwnd) \
  87. EnableWindow( GetDlgItem( hwnd, IDD_BROWSE_SELECT_LB ), TRUE )
  88. #define DISABLE_LIST(hwnd) \
  89. EnableWindow( GetDlgItem( hwnd, IDD_BROWSE_SELECT_LB ), FALSE )
  90. #define ENTER_CRITICAL( pBrowseDlgData ) \
  91. pBrowseDlgData->csLock.Lock()
  92. #define LEAVE_CRITICAL( pBrowseDlgData ) \
  93. pBrowseDlgData->csLock.Unlock()
  94. /* The following macros are used for communication between the main GUI thread
  95. * and the browsing thread.
  96. * They are implemented as macros and defined here for ease of comprehension.
  97. */
  98. /* SEND_BROWSE_THREAD_REQUEST
  99. *
  100. * The main thread calls this when it wants the browse thread to do browse
  101. * for something. If the browse thread is currently browsing, it will not
  102. * fulfil this request until it returns and waits on the Event again by
  103. * calling RECEIVE_BROWSE_THREAD_REQUEST.
  104. */
  105. #if DBG
  106. #define SEND_BROWSE_THREAD_REQUEST(pBrowseDlgData, ReqId, pEnumName, pEnumObj) \
  107. ASSERT( pBrowseDlgData->csLock.bInside() ); \
  108. (pBrowseDlgData)->RequestId = ReqId; \
  109. (pBrowseDlgData)->pEnumerateName = pEnumName; \
  110. (pBrowseDlgData)->pEnumerateObject = pEnumObj; \
  111. SetEvent( (pBrowseDlgData)->Request )
  112. #else
  113. #define SEND_BROWSE_THREAD_REQUEST(pBrowseDlgData, ReqId, pEnumName, pEnumObj) \
  114. (pBrowseDlgData)->RequestId = ReqId; \
  115. (pBrowseDlgData)->pEnumerateName = pEnumName; \
  116. (pBrowseDlgData)->pEnumerateObject = pEnumObj; \
  117. SetEvent( (pBrowseDlgData)->Request )
  118. #endif /* DBG */
  119. /* RECEIVE_BROWSE_THREAD_REQUEST
  120. *
  121. * The browse thread calls this when it is idle and waiting for a request.
  122. */
  123. #define RECEIVE_BROWSE_THREAD_REQUEST(pBrowseDlgData, ReqId, pEnumName, pEnumObj) \
  124. WaitForSingleObject( (pBrowseDlgData)->Request, INFINITE ), \
  125. ENTER_CRITICAL( pBrowseDlgData ), \
  126. ReqId = (pBrowseDlgData)->RequestId, \
  127. pEnumName = (pBrowseDlgData)->pEnumerateName, \
  128. pEnumObj = (pBrowseDlgData)->pEnumerateObject, \
  129. LEAVE_CRITICAL( pBrowseDlgData )
  130. /* SEND_BROWSE_THREAD_REQUEST_COMPLETE
  131. *
  132. * When the browse thread returns with the browse data, it sets the
  133. * RequestComplete event. This is waited on by the main window thread
  134. * when it calls MsgWaitForMultipleObjects in its main message loop.
  135. */
  136. #define SEND_BROWSE_THREAD_REQUEST_COMPLETE(pBrowseDlgData, message, wP, lP) \
  137. (pBrowseDlgData)->Message = message, \
  138. (pBrowseDlgData)->wParam = (WPARAM)wP, \
  139. (pBrowseDlgData)->lParam = (LPARAM)lP, \
  140. SetEvent( (pBrowseDlgData)->RequestComplete ); \
  141. PostMessage( pBrowseDlgData->hwndDialog, pBrowseDlgData->Message, 0, (LPARAM)pBrowseDlgData)
  142. typedef struct _CONNECTTO_OBJECT
  143. {
  144. PPRINTER_INFO_1 pPrinterInfo; // Points to an array returned by EnumPrinters
  145. struct _CONNECTTO_OBJECT *pSubObject; // Result of enumerating on this object
  146. DWORD cSubObjects; // Number of objects found
  147. DWORD cbPrinterInfo; // Size of buffer containing enumerated objects
  148. } CONNECTTO_OBJECT, *PCONNECTTO_OBJECT;
  149. struct BROWSE_DLG_DATA : public MRefCom
  150. {
  151. /* These fields are referenced only by the main thread:
  152. */
  153. DWORD Status;
  154. DWORD cExpandObjects;
  155. DWORD ExpandSelection;
  156. DWORD dwExtent;
  157. /* These fields may be referenced by either thread,
  158. * so access must be serialized by the critical section:
  159. */
  160. PCONNECTTO_OBJECT pConnectToData;
  161. HANDLE Request; /* Set when main thread has written request */
  162. DWORD RequestId; /* BROWSE_THREAD_* */
  163. LPTSTR pEnumerateName; /* Name of object to get, if appropriate */
  164. PVOID pEnumerateObject; /* Buffer appropriate to RequestId */
  165. HANDLE RequestComplete; /* Set when browse thread has returned data */
  166. DWORD Message; /* Message to post to main dialog windows */
  167. WPARAM wParam;
  168. LPARAM lParam;
  169. /* This is for printer info, and will be freed by the browse thread:
  170. */
  171. LPPRINTER_INFO_2 pPrinterInfo;
  172. DWORD cbPrinterInfo;
  173. // critical section lock
  174. CCSLock csLock;
  175. HWND hwndParent;
  176. HANDLE hPrinter;
  177. DWORD Flags;
  178. HWND hwndDialog;
  179. BOOL _bValid;
  180. HCURSOR hcursorArrow;
  181. HCURSOR hcursorWait;
  182. /*
  183. * For leveraging the code to be used with
  184. * property page
  185. */
  186. IPageSwitch *pPageSwitchController;
  187. BOOL bInPropertyPage;
  188. BROWSE_DLG_DATA(
  189. VOID
  190. );
  191. ~BROWSE_DLG_DATA(
  192. VOID
  193. );
  194. BOOL
  195. bValid(
  196. VOID
  197. );
  198. VOID
  199. vRefZeroed(
  200. VOID
  201. );
  202. BOOL
  203. bInitializeBrowseThread(
  204. HWND hWnd
  205. );
  206. };
  207. typedef BROWSE_DLG_DATA *PBROWSE_DLG_DATA;
  208. struct SPLSETUP_DATA
  209. {
  210. // ntprint.dll module
  211. HINSTANCE hModule;
  212. // driver info
  213. HDEVINFO hDevInfo;
  214. PPSETUP_LOCAL_DATA pSetupLocalData;
  215. // ntprint.dll exported functions
  216. pfPSetupCreatePrinterDeviceInfoList pfnCreatePrinterDeviceInfoList;
  217. pfPSetupDestroyPrinterDeviceInfoList pfnDestroyPrinterDeviceInfoList;
  218. pfPSetupSelectDriver pfnSelectDriver;
  219. pfPSetupGetSelectedDriverInfo pfnGetSelectedDriverInfo;
  220. pfPSetupDestroySelectedDriverInfo pfnDestroySelectedDriverInfo;
  221. pfPSetupInstallPrinterDriver pfnInstallPrinterDriver;
  222. pfPSetupThisPlatform pfnThisPlatform;
  223. pfPSetupDriverInfoFromName pfnDriverInfoFromName;
  224. pfPSetupGetPathToSearch pfnGetPathToSearch;
  225. pfPSetupBuildDriversFromPath pfnBuildDriversFromPath;
  226. pfPSetupIsDriverInstalled pfnIsDriverInstalled;
  227. pfPSetupGetLocalDataField pfnGetLocalDataField;
  228. pfPSetupFreeDrvField pfnFreeDrvField;
  229. pfPSetupProcessPrinterAdded pfnProcessPrinterAdded;
  230. pfPSetupFindMappedDriver pfnFindMappedDriver;
  231. pfPSetupInstallInboxDriverSilently pfnInstallInboxDriverSilently;
  232. pfPSetupFreeMem pfnFreeMem;
  233. // is the structure valid
  234. BOOL bValid;
  235. BOOL bDriverAdded;
  236. DWORD dwLastError;
  237. SPLSETUP_DATA(
  238. VOID
  239. );
  240. ~SPLSETUP_DATA(
  241. VOID
  242. );
  243. VOID
  244. FreeDriverInfo(
  245. VOID
  246. );
  247. BOOL
  248. LoadDriverInfo(
  249. IN HWND hwnd,
  250. IN LPWSTR pszDriver
  251. );
  252. BOOL
  253. LoadKnownDriverInfo(
  254. IN HWND hwnd,
  255. IN LPWSTR pszDriver
  256. );
  257. VOID
  258. ReportErrorMessage(
  259. IN HWND hwnd
  260. );
  261. };
  262. DWORD
  263. EnumConnectToObjects(
  264. PBROWSE_DLG_DATA pBrowseDlgData,
  265. PCONNECTTO_OBJECT pConnectToParent,
  266. LPTSTR pParentName
  267. );
  268. DWORD
  269. FreeConnectToObjects(
  270. IN PCONNECTTO_OBJECT pFirstConnectToObject,
  271. IN DWORD cThisLevelObjects,
  272. IN DWORD cbPrinterInfo
  273. );
  274. VOID
  275. BrowseThread(
  276. PBROWSE_DLG_DATA pBrowseDlgData
  277. );
  278. BOOL APIENTRY
  279. InstallDriverDialog(
  280. HWND hWnd,
  281. UINT usMsg,
  282. WPARAM wParam,
  283. LONG lParam
  284. );
  285. BOOL APIENTRY
  286. NetworkPasswordDialog(
  287. HWND hWnd,
  288. UINT usMsg,
  289. WPARAM wParam,
  290. LONG lParam
  291. );
  292. LPTSTR
  293. AllocDlgItemText(
  294. HWND hwnd,
  295. INT id
  296. );
  297. LPTSTR
  298. GetErrorString(
  299. DWORD Error
  300. );
  301. DWORD
  302. ReportFailure(
  303. HWND hwndParent,
  304. DWORD idTitle,
  305. DWORD idDefaultError
  306. );
  307. HANDLE
  308. AddPrinterConnectionUI(
  309. HWND hwnd,
  310. LPCTSTR pszPrinter,
  311. PBOOL pbAdded
  312. );
  313. LPTSTR
  314. AllocSplStr(
  315. LPCTSTR pStr
  316. );
  317. BOOL
  318. FreeSplStr(
  319. LPTSTR pStr
  320. );
  321. LPVOID
  322. AllocSplMem(
  323. DWORD cb
  324. );
  325. BOOL
  326. FreeSplMem(
  327. LPVOID pMem
  328. );
  329. LPVOID
  330. ReallocSplMem(
  331. LPVOID pOldMem,
  332. DWORD cbOld,
  333. DWORD cbNew
  334. );
  335. BOOL
  336. PreDialog(
  337. HWND hwndDialog,
  338. PBROWSE_DLG_DATA pBrowseDlgData
  339. );
  340. VOID
  341. PostDialog(
  342. PBROWSE_DLG_DATA pBrowseDlgData
  343. );
  344. BOOL
  345. SetDevMode(
  346. HANDLE hPrinter
  347. );
  348. BOOL
  349. ConnectToInitDialog(
  350. HWND hWnd,
  351. PBROWSE_DLG_DATA pBrowseDlgData
  352. );
  353. VOID ConnectToMeasureItem( HWND hwnd, LPMEASUREITEMSTRUCT pmis );
  354. BOOL ConnectToDrawItem( HWND hwnd, LPDRAWITEMSTRUCT pdis );
  355. LONG ConnectToCharToItem( HWND hWnd, WORD Key );
  356. VOID ConnectToSysColorChange( );
  357. VOID ConnectToDestroy( HWND hWnd );
  358. VOID ConnectToSelectLbSelChange( HWND hWnd );
  359. VOID ConnectToSelectLbDblClk( HWND hwnd, HWND hwndListbox );
  360. VOID ConnectToMouseMove( HWND hWnd, LONG x, LONG y );
  361. BOOL ConnectToSetCursor( HWND hWnd );
  362. VOID ConnectToEnumObjectsComplete( HWND hWnd, PCONNECTTO_OBJECT pConnectToObject );
  363. VOID ConnectToGetPrinterComplete( HWND hWnd, LPTSTR pPrinterName,
  364. PPRINTER_INFO_2 pPrinter, DWORD Error );
  365. BOOL ConnectToOK( HWND hWnd, BOOL ForceClose );
  366. BOOL ConnectToCancel( HWND hWnd );
  367. VOID SetCursorShape( HWND hWnd );
  368. BOOL PrinterExists( HANDLE hPrinter, PDWORD pAttributes, LPWSTR* ppszDriver, LPWSTR* ppszPrinterName );
  369. HANDLE
  370. CreateLocalPrinter(
  371. IN LPCTSTR pPrinterName,
  372. IN LPCTSTR pDriverName,
  373. IN LPCTSTR pPortName,
  374. IN BOOL bMasqPrinter,
  375. IN DEVMODE *pDevMode OPTIONAL
  376. );
  377. BOOL
  378. AddKnownDriver(
  379. IN SPLSETUP_DATA *pSplSetupData,
  380. IN HWND hwnd,
  381. IN LPWSTR pszDriver,
  382. IN BOOL bSamePlatform
  383. );
  384. BOOL
  385. AddDriver(
  386. IN SPLSETUP_DATA *pSplSetupData,
  387. IN HWND hwnd,
  388. IN LPWSTR pszDriver,
  389. IN BOOL bPromptUser,
  390. OUT LPWSTR *ppszDriverOut
  391. );
  392. PCONNECTTO_OBJECT
  393. GetConnectToObject(
  394. IN PCONNECTTO_OBJECT pFirstConnectToObject,
  395. IN DWORD cThisLevelObjects,
  396. IN DWORD Index,
  397. IN PCONNECTTO_OBJECT pFindObject,
  398. OUT PDWORD pObjectsFound,
  399. OUT PDWORD pDepth
  400. );
  401. PCONNECTTO_OBJECT
  402. GetDefaultExpand(
  403. IN PCONNECTTO_OBJECT pFirstConnectToObject,
  404. IN DWORD cThisLevelObjects,
  405. OUT PDWORD pIndex
  406. );
  407. BOOL
  408. ToggleExpandConnectToObject(
  409. HWND hwnd,
  410. PCONNECTTO_OBJECT pConnectToObject
  411. );
  412. BOOL
  413. UpdateList(
  414. HWND hwnd,
  415. INT Increment
  416. );
  417. LPBYTE
  418. GetPrinterInfo(
  419. IN DWORD Flags,
  420. IN LPTSTR Name,
  421. IN DWORD Level,
  422. IN LPBYTE pPrinters,
  423. OUT LPDWORD pcbPrinters,
  424. OUT LPDWORD pcReturned,
  425. OUT LPDWORD pcbNeeded OPTIONAL,
  426. OUT LPDWORD pError OPTIONAL
  427. );
  428. BOOL
  429. SetInfoFields(
  430. HWND hWnd,
  431. LPPRINTER_INFO_2 pPrinter
  432. );
  433. VOID DrawLine( HDC hDC, LPRECT pRect, LPTSTR pStr, BOOL bInvert );
  434. VOID DrawLineWithTabs( HDC hDC, LPRECT pRect, LPTSTR pStr, BOOL bInvert );
  435. BOOL DisplayStatusIcon( HDC hdc, PRECT prect, int xBase, int yBase, BOOL Highlight );
  436. BOOL LoadBitmaps();
  437. BOOL FixupBitmapColours( );
  438. VOID FreeBitmaps();
  439. BOOL GetRegShowLogonDomainFlag( );
  440. BOOL SetRegShowLogonDomainFlag( BOOL ShowLogonDomain );
  441. VOID
  442. UpdateError(
  443. HWND hwnd,
  444. DWORD Error
  445. );
  446. LRESULT
  447. WINAPI
  448. ConnectToDlg(
  449. HWND hWnd,
  450. UINT usMsg,
  451. WPARAM wParam,
  452. LPARAM lParam
  453. );
  454. /******************************************************
  455. * *
  456. * Browse for printer property page stuff *
  457. * *
  458. ******************************************************/
  459. //
  460. // The dialog procedure for the property page created above
  461. //
  462. LRESULT
  463. WINAPI
  464. ConnectToPropertyPage(
  465. IN HWND hWnd,
  466. IN UINT usMsg,
  467. IN WPARAM wParam,
  468. IN LPARAM lParam
  469. );
  470. //
  471. // Handle wizard back notification
  472. //
  473. BOOL
  474. PropertyPageWizardBack(
  475. IN HWND hWnd
  476. );
  477. //
  478. // Handle successful printer connection page
  479. //
  480. BOOL
  481. HandleSuccessfulPrinterConnection(
  482. IN HWND hWnd,
  483. IN PBROWSE_DLG_DATA pBrowseDlgData
  484. );
  485. LPWSTR
  486. GetArch(
  487. IN HANDLE hServer
  488. );
  489. HANDLE
  490. CreateRedirectedPrinter(
  491. IN PCWSTR pszPrinterIn
  492. );
  493. VOID
  494. BuildMasqPrinterName(
  495. IN PPRINTER_INFO_2 pPrinter,
  496. OUT PWSTR *ppszPrinterName
  497. );
  498. BOOL
  499. BuildNTPrinterName(
  500. IN PRINTER_INFO_2 *pPrinter,
  501. OUT PWSTR *ppszPrinterName
  502. );
  503. HRESULT
  504. IsNTServer(
  505. IN PCWSTR pszServerName
  506. );
  507. BOOL
  508. CreateLocalPort(
  509. IN PCWSTR pszPortName
  510. );
  511. BOOL
  512. AddPrinterConnectionAndPrompt(
  513. IN HWND hWnd,
  514. IN PCWSTR pszPrinterName,
  515. OUT BOOL *pbUserDenied,
  516. OUT TString *pstrNewName
  517. );
  518. #endif // _BROWSE_HXX_