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.

456 lines
14 KiB

  1. /*++
  2. Copyright (c) 1990-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. printnew.h
  5. Abstract:
  6. This module contains the header information for the Win32
  7. property sheet print common dialogs.
  8. Revision History:
  9. 11-04-97 JulieB Created.
  10. Feb-2000 LazarI major redesign (not to use printui anymore)
  11. --*/
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #ifdef WINNT
  16. //
  17. // Include Files.
  18. //
  19. #include <dlgs.h>
  20. #include <initguid.h>
  21. #include <winprtp.h>
  22. //
  23. // Constant Declarations.
  24. //
  25. //
  26. // Dialog Constants.
  27. //
  28. #define IDD_PRINT_GENERAL 100
  29. #define IDD_PRINT_GENERAL_LARGE 101
  30. #define IDI_COLLATE ico1
  31. #define IDC_PRINTER_LIST 1000
  32. #define IDC_PRINTER_LISTVIEW 1001
  33. #define IDC_PRINT_TO_FILE 1002
  34. #define IDC_FIND_PRINTER 1003
  35. #define IDC_STATUS_TEXT 1004
  36. #define IDC_STATUS 1005
  37. #define IDC_LOCATION_TEXT 1006
  38. #define IDC_LOCATION 1007
  39. #define IDC_COMMENT_TEXT 1008
  40. #define IDC_COMMENT 1009
  41. #define IDC_DRIVER 1010
  42. #define IDC_HIDDEN_TEXT 1011
  43. #define IDC_RANGE_ALL rad1
  44. #define IDC_RANGE_SELECTION rad2
  45. #define IDC_RANGE_CURRENT rad3
  46. #define IDC_RANGE_PAGES rad4
  47. #define IDC_RANGE_EDIT edt1
  48. #define IDC_RANGE_TEXT1 stc1
  49. #define IDC_RANGE_TEXT2 stc2
  50. #define IDC_COPIES edt2
  51. #define IDC_COPIES_TEXT stc3
  52. #define IDC_COLLATE chx1
  53. #define IDC_STATIC -1
  54. //
  55. // Typedef Declarations.
  56. //
  57. typedef struct
  58. {
  59. UINT ApiType;
  60. LPPRINTDLGEX pPD;
  61. DWORD ProcessVersion;
  62. DWORD dwFlags;
  63. UINT FinalResult;
  64. HRESULT hResult;
  65. BOOL fApply;
  66. BOOL fOld;
  67. DWORD dwExtendedError;
  68. HRESULT hrOleInit;
  69. #ifdef UNICODE
  70. LPPRINTDLGEXA pPDA;
  71. BOOL fPrintTemplateAlloc;
  72. #endif
  73. } PRINTINFOEX, *PPRINTINFOEX;
  74. //
  75. // Registry keys.
  76. //
  77. static const TCHAR c_szSettings[] = TEXT("Printers\\Settings");
  78. static const TCHAR c_szViewMode[] = TEXT("ViewMode");
  79. //
  80. // CPrintBrowser Class.
  81. //
  82. class CPrintBrowser : public IShellBrowser,
  83. public ICommDlgBrowser2,
  84. public IPrintDialogCallback,
  85. public IPrintDialogServices
  86. {
  87. public:
  88. // *** IUnknown methods ***
  89. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID *ppvObj);
  90. STDMETHOD_(ULONG, AddRef) (THIS);
  91. STDMETHOD_(ULONG, Release) (THIS);
  92. // *** IOleWindow methods ***
  93. STDMETHOD(GetWindow) (THIS_ HWND *lphwnd);
  94. STDMETHOD(ContextSensitiveHelp) (THIS_ BOOL fEnterMode);
  95. // *** IShellBrowser methods *** (same as IOleInPlaceFrame)
  96. STDMETHOD(InsertMenusSB) (THIS_ HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths);
  97. STDMETHOD(SetMenuSB) (THIS_ HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject);
  98. STDMETHOD(RemoveMenusSB) (THIS_ HMENU hmenuShared);
  99. STDMETHOD(SetStatusTextSB) (THIS_ LPCOLESTR lpszStatusText);
  100. STDMETHOD(EnableModelessSB) (THIS_ BOOL fEnable);
  101. STDMETHOD(TranslateAcceleratorSB) (THIS_ LPMSG lpmsg, WORD wID);
  102. // *** IShellBrowser methods ***
  103. STDMETHOD(BrowseObject) (THIS_ LPCITEMIDLIST pidl, UINT wFlags);
  104. STDMETHOD(GetViewStateStream) (THIS_ DWORD grfMode, LPSTREAM *pStrm);
  105. STDMETHOD(GetControlWindow) (THIS_ UINT id, HWND *lphwnd);
  106. STDMETHOD(SendControlMsg) (THIS_ UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pret);
  107. STDMETHOD(QueryActiveShellView) (THIS_ struct IShellView **ppshv);
  108. STDMETHOD(OnViewWindowActive) (THIS_ struct IShellView *pshv);
  109. STDMETHOD(SetToolbarItems) (THIS_ LPTBBUTTON lpButtons, UINT nButtons, UINT uFlags);
  110. // *** ICommDlgBrowser2 methods ***
  111. STDMETHOD(OnDefaultCommand) (THIS_ struct IShellView *ppshv);
  112. STDMETHOD(OnStateChange) (THIS_ struct IShellView *ppshv, ULONG uChange);
  113. STDMETHOD(IncludeObject) (THIS_ struct IShellView *ppshv, LPCITEMIDLIST lpItem);
  114. STDMETHOD(Notify) (THIS_ struct IShellView *ppshv, DWORD dwNotifyType);
  115. STDMETHOD(GetDefaultMenuText) (THIS_ struct IShellView *ppshv, WCHAR *pszText, INT cchMax);
  116. STDMETHOD(GetViewFlags)(THIS_ DWORD *pdwFlags);
  117. // *** IPrintDialogCallback methods ***
  118. STDMETHOD(InitDone) (THIS);
  119. STDMETHOD(SelectionChange) (THIS);
  120. STDMETHOD(HandleMessage) (THIS_ HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult);
  121. // *** IPrintDialogServices methods ***
  122. STDMETHOD(GetCurrentDevMode) (THIS_ LPDEVMODE pDevMode, UINT *pcbSize);
  123. STDMETHOD(GetCurrentPrinterName) (THIS_ LPTSTR pPrinterName, UINT *pcchSize);
  124. STDMETHOD(GetCurrentPortName) (THIS_ LPTSTR pPortName, UINT *pcchSize);
  125. // *** Our own methods ***
  126. CPrintBrowser(HWND hDlg);
  127. ~CPrintBrowser();
  128. BOOL OnInitDialog(WPARAM wParam, LPARAM lParam);
  129. BOOL OnChildInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam);
  130. VOID OnDestroyMessage();
  131. BOOL OnCommandMessage(WPARAM wParam, LPARAM lParam);
  132. BOOL OnChildCommandMessage(WPARAM wParam, LPARAM lParam);
  133. BOOL OnNotifyMessage(WPARAM wParam, LPNMHDR lpnmhdr);
  134. BOOL OnSelChange();
  135. BOOL OnChangeNotify(LONG lNotification, LPCITEMIDLIST *ppidl);
  136. BOOL OnAccelerator(HWND hwndActivePrint, HWND hwndFocus, HACCEL haccPrint, PMSG pMsg);
  137. VOID OnNoPrinters(HWND hDlg, UINT uID);
  138. VOID OnInitDone();
  139. private:
  140. HRESULT CreatePrintShellView();
  141. UINT GetViewMode();
  142. VOID SetViewMode();
  143. HRESULT CreateHookDialog();
  144. BOOL UpdateStatus(LPCITEMIDLIST pidl);
  145. BOOL SelectSVItem();
  146. BOOL GetCurrentPrinter();
  147. VOID InitPrintToFile();
  148. VOID InitPageRangeGroup();
  149. VOID InitCopiesAndCollate();
  150. BOOL SaveCopiesAndCollateInDevMode(LPDEVMODE pDM, LPTSTR pszPrinter);
  151. BOOL SetCopiesOnApply();
  152. VOID SaveDevMode();
  153. BOOL MergeDevMode(LPTSTR pszPrinterName);
  154. BOOL IsValidPageRange(LPTSTR pszString, UINT *pErrorId);
  155. BOOL ConvertPageRangesToString(LPTSTR pszString, UINT cchLen);
  156. UINT IntegerToString(DWORD Value, LPTSTR pszString, UINT cchLen);
  157. VOID ShowError(HWND hDlg, UINT uCtrlID, UINT uMsgID, ...);
  158. int ShowMessage(HWND hDlg, UINT uCtrlID, UINT uMsgID, UINT uType, BOOL bBeep, ...);
  159. int InternalShowMessage(HWND hDlg, UINT uCtrlID, UINT uMsgID, UINT uType, BOOL bBeep, va_list args);
  160. UINT InsertDevicePage(LPCWSTR pszName, PDEVMODE pDevMode);
  161. UINT RemoveDevicePage();
  162. UINT RemoveAndInsertDevicePage(LPCWSTR pszName, PDEVMODE pDevMode);
  163. BOOL FitViewModeBest(HWND hwndListView);
  164. VOID SelectPrinterItem(LPITEMIDLIST pidlItem);
  165. BOOL IsCurrentPrinter(LPCITEMIDLIST pidl);
  166. BOOL OnRename(LPCITEMIDLIST *ppidl);
  167. //
  168. // The error codes returned by InstallDevMode/UninstallDevMode functions below.
  169. //
  170. enum
  171. {
  172. kSuccess, // Success no error
  173. kError, // General error
  174. kInvalidDevMode, // Invalid devmode specified
  175. kInvalidPrinterName, // Invalid printer name specified
  176. kAccessDenied, // User does not have access to printer
  177. };
  178. //
  179. // These functions maintain the internal devmode, driver UI stuff and
  180. // implement the printui.dll functionality - bPrinterSetup(...).
  181. //
  182. BOOL FindPrinter(HWND hwnd, LPTSTR pszBuffer, UINT cchSize);
  183. BOOL GetInternalPrinterName(LPTSTR pszBuffer, DWORD *pdwSize);
  184. LPDEVMODE GetCurrentDevMode();
  185. BOOL GetDefaultDevMode(HANDLE hPrinter, LPCTSTR pszPrinterName, PDEVMODE *ppDevMode, BOOL bFillWithDefault);
  186. BOOL WrapEnumPrinters(DWORD dwFlags, LPCTSTR pszServer, DWORD dwLevel, PVOID* ppvBuffer, PDWORD pcbBuffer, PDWORD pcPrinters);
  187. BOOL GetUsablePrinter(LPTSTR szPrinterNameBuf, DWORD *pcchBuf);
  188. BOOL GetInternalDevMode(PDEVMODE *ppOutDevMode, LPCTSTR pszPrinter, HANDLE hPrinter, PDEVMODE pInDevMode);
  189. UINT InstallDevMode(LPCTSTR pszPrinterName, PDEVMODE pDevModeToMerge);
  190. UINT UninstallDevMode();
  191. //
  192. // Members start here.
  193. //
  194. UINT cRef; // compobj refcount
  195. HWND hwndDlg; // handle of this dialog
  196. HWND hSubDlg; // handle of the hook dialog
  197. HWND hwndView; // current view window
  198. HWND hwndUpDown; // UpDown Control Window handle;
  199. IShellView *psv; // shell view object
  200. IShellFolderView *psfv; // shell folder view object
  201. IShellFolder2 *psfRoot; // print folder shell folder
  202. LPITEMIDLIST pidlRoot; // pidl for print folder
  203. IPrinterFolder *ppf; // printer folder private interface
  204. HIMAGELIST himl; // system imagelist (small images)
  205. PPRINTINFOEX pPI; // ptr to PRINTINFOEX struct
  206. LPPRINTDLGEX pPD; // caller's PRINTDLGEX struct
  207. IPrintDialogCallback *pCallback; // ptr to app's callback interface
  208. IObjectWithSite *pSite; // ptr to app's SetSite interface
  209. LPDEVMODE pDMInit; // ptr to the initial DEVMODE struct
  210. LPDEVMODE pDMCur; // ptr to the current DEVMODE struct
  211. LPDEVMODE pDMSave; // ptr to the last good DEVMODE struct
  212. UINT cchCurPrinter; // size, in chars, of pszCurPrinter
  213. LPTSTR pszCurPrinter; // ptr to name of current printer
  214. DWORD nCopies; // number of copies
  215. DWORD nMaxCopies; // max number for the "number of copies"
  216. DWORD nPageRanges; // number of page ranges in pPageRange
  217. DWORD nMaxPageRanges; // max number of page ranges allowed
  218. LPPRINTPAGERANGE pPageRanges; // ptr to an array of page range structs
  219. BOOL fCollateRequested; // collate is requested
  220. BOOL fSelChangePending; // we have a selchange message pending
  221. BOOL fFirstSel; // still need to set first selection
  222. BOOL fAPWSelected; // add printer wizard is selected
  223. BOOL fNoAccessPrinterSelected; // a printer we do not have access to is selected
  224. BOOL fDirtyDevmode; // Set if we change the devmode while editing.
  225. BOOL fDevmodeEdit; // devmode editor is open
  226. BOOL fAllowCollate; // whether collation is allowed by the device
  227. UINT nInitDone; // number of CDM_INITDONE messages
  228. UINT nListSep; // number of characters in szListSep
  229. TCHAR szListSep[20]; // list separator
  230. UINT uRegister; // change notify register
  231. TCHAR szScratch[kPrinterBufMax]; // scratch buffer
  232. UINT uDefViewMode; // How the default view mode is mapped
  233. LPDEVMODE pInternalDevMode; // ptr to the internal DEVMODE
  234. TCHAR szPrinter[kPrinterBufMax]; // The internal printer name
  235. HANDLE hPrinter; // The internal printer
  236. };
  237. //
  238. // Context Help IDs.
  239. //
  240. DWORD aPrintExHelpIDs[] =
  241. {
  242. grp1, NO_HELP,
  243. IDC_PRINTER_LISTVIEW, IDH_PRINT_PRINTER_FOLDER,
  244. IDC_STATUS_TEXT, IDH_PRINT_SETUP_DETAILS,
  245. IDC_STATUS, IDH_PRINT_SETUP_DETAILS,
  246. IDC_LOCATION_TEXT, IDH_PRINT_SETUP_DETAILS,
  247. IDC_LOCATION, IDH_PRINT_SETUP_DETAILS,
  248. IDC_COMMENT_TEXT, IDH_PRINT_SETUP_DETAILS,
  249. IDC_COMMENT, IDH_PRINT_SETUP_DETAILS,
  250. IDC_PRINT_TO_FILE, IDH_PRINT_TO_FILE,
  251. IDC_FIND_PRINTER, IDH_PRINT_FIND_PRINTER,
  252. IDC_DRIVER, IDH_PRINT_PREFERENCES,
  253. grp2, NO_HELP,
  254. IDOK, IDH_PRINT_BTN,
  255. 0, 0
  256. };
  257. DWORD aPrintExChildHelpIDs[] =
  258. {
  259. grp1, NO_HELP,
  260. IDC_RANGE_ALL, IDH_PRINT32_RANGE,
  261. IDC_RANGE_SELECTION, IDH_PRINT32_RANGE,
  262. IDC_RANGE_CURRENT, IDH_PRINT32_RANGE,
  263. IDC_RANGE_PAGES, IDH_PRINT32_RANGE,
  264. IDC_RANGE_EDIT, IDH_PRINT32_RANGE,
  265. IDC_RANGE_TEXT1, IDH_PRINT32_RANGE,
  266. IDC_RANGE_TEXT2, IDH_PRINT32_RANGE,
  267. grp2, NO_HELP,
  268. IDC_COPIES, IDH_PRINT_COPIES,
  269. IDC_COPIES_TEXT, IDH_PRINT_COPIES,
  270. IDC_COLLATE, IDH_PRINT_COLLATE,
  271. IDI_COLLATE, IDH_PRINT_COLLATE,
  272. 0, 0
  273. };
  274. //
  275. // Function Prototypes.
  276. //
  277. HRESULT
  278. PrintDlgExX(
  279. PPRINTINFOEX pPI);
  280. HRESULT
  281. Print_ReturnDefault(
  282. PPRINTINFOEX pPI);
  283. BOOL
  284. Print_LoadLibraries();
  285. VOID
  286. Print_UnloadLibraries();
  287. BOOL
  288. Print_LoadIcons();
  289. BOOL
  290. Print_InvokePropertySheets(
  291. PPRINTINFOEX pPI,
  292. LPPRINTDLGEX pPD);
  293. BOOL_PTR
  294. Print_GeneralDlgProc(
  295. HWND hDlg,
  296. UINT uMsg,
  297. WPARAM wParam,
  298. LPARAM lParam);
  299. BOOL_PTR
  300. Print_GeneralChildDlgProc(
  301. HWND hDlg,
  302. UINT uMsg,
  303. WPARAM wParam,
  304. LPARAM lParam);
  305. LRESULT
  306. Print_MessageHookProc(
  307. int nCode,
  308. WPARAM wParam,
  309. LPARAM lParam);
  310. BOOL
  311. Print_InitDialog(
  312. HWND hDlg,
  313. WPARAM wParam,
  314. LPARAM lParam);
  315. HRESULT
  316. Print_ICoCreateInstance(
  317. REFCLSID rclsid,
  318. REFIID riid,
  319. LPVOID *ppv);
  320. BOOL
  321. Print_SaveDevNames(
  322. LPTSTR pCurPrinter,
  323. LPPRINTDLGEX pPD);
  324. VOID
  325. Print_GetPortName(
  326. LPTSTR pCurPrinter,
  327. LPTSTR pBuffer,
  328. int cchBuffer);
  329. HANDLE
  330. Print_GetDevModeWrapper(
  331. LPTSTR pszDeviceName,
  332. HANDLE hDevMode);
  333. BOOL
  334. Print_NewPrintDlg(
  335. PPRINTINFO pPI);
  336. #ifdef UNICODE
  337. HRESULT
  338. ThunkPrintDlgEx(
  339. PPRINTINFOEX pPI,
  340. LPPRINTDLGEXA pPDA);
  341. VOID
  342. FreeThunkPrintDlgEx(
  343. PPRINTINFOEX pPI);
  344. VOID
  345. ThunkPrintDlgExA2W(
  346. PPRINTINFOEX pPI);
  347. VOID
  348. ThunkPrintDlgExW2A(
  349. PPRINTINFOEX pPI);
  350. #endif
  351. #endif // WINNT
  352. #ifdef __cplusplus
  353. }; // extern "C"
  354. #endif