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.

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