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.

514 lines
11 KiB

  1. /*++
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. Module Name:
  4. cpsui.c
  5. Abstract:
  6. This module contains helper functions to be used with common UI
  7. Author:
  8. 03-Nov-1995 Fri 13:24:41 created
  9. [Environment:]
  10. GDI Device Driver - Plotter.
  11. [Notes:]
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. #define DBG_PLOTFILENAME DbgCPSUI
  17. DEFINE_DBGVAR(0);
  18. #define SIZE_OPTTYPE(cOP) (sizeof(OPTPARAM) + ((cOP) * sizeof(OPTPARAM)))
  19. extern HMODULE hPlotUIModule;
  20. static BYTE cTVOP[] = { 2,3,2,3,3,0,0,2,1,1 };
  21. OPDATA OPNoYes[] = {
  22. { 0, IDS_CPSUI_NO, IDI_CPSUI_OFF, 0, 0, 0 },
  23. { 0, IDS_CPSUI_YES, IDI_CPSUI_ON, 0, 0, 0 }
  24. };
  25. static const CHAR szCompstui[] = "compstui.dll";
  26. BOOL
  27. CreateOPTTYPE(
  28. PPRINTERINFO pPI,
  29. POPTITEM pOptItem,
  30. POIDATA pOIData,
  31. UINT cLBCBItem,
  32. PEXTRAINFO pExtraInfo
  33. )
  34. /*++
  35. Routine Description:
  36. This fucntion allocate memory and initialized field for OPTTYPE/OPTPARAM
  37. Arguments:
  38. pOptItem - Pointer to OPTITEM data structure
  39. pOIData - Pointer to the OIDATA structure
  40. Return Value:
  41. Author:
  42. 03-Nov-1995 Fri 13:25:54 created
  43. Revision History:
  44. --*/
  45. {
  46. LPBYTE pbData = NULL;
  47. UINT cOP;
  48. DWORD cbOP;
  49. DWORD cbECB;
  50. DWORD cbExtra;
  51. DWORD cbAlloc;
  52. BYTE Type;
  53. DWORD Flags;
  54. Flags = pOIData->Flags;
  55. ZeroMemory(pOptItem, sizeof(OPTITEM));
  56. pOptItem->cbSize = sizeof(OPTITEM);
  57. pOptItem->Level = pOIData->Level;
  58. pOptItem->Flags = (Flags & ODF_CALLBACK) ? OPTIF_CALLBACK : 0;
  59. if (Flags & ODF_COLLAPSE) {
  60. pOptItem->Flags |= OPTIF_COLLAPSE;
  61. }
  62. pOptItem->pName = (LPTSTR)pOIData->IDSName;
  63. pOptItem->HelpIndex = (DWORD)pOIData->HelpIdx;
  64. pOptItem->DMPubID = pOIData->DMPubID;
  65. if ((Type = pOIData->Type) >= sizeof(cTVOP)) {
  66. pOptItem->Sel = (LONG)pOIData->IconID;
  67. cOP = 0;
  68. } else if (!(cOP = cTVOP[Type])) {
  69. cOP = cLBCBItem;
  70. }
  71. cbOP = (cOP) ? SIZE_OPTTYPE(cOP) : 0;
  72. cbECB = (Flags & ODF_ECB) ? sizeof(EXTCHKBOX) : 0;
  73. cbExtra = (pExtraInfo) ? pExtraInfo->Size : 0;
  74. if (cbAlloc = cbOP + cbECB + cbExtra) {
  75. if (pbData = (LPBYTE)LocalAlloc(LPTR, cbAlloc)) {
  76. POPDATA pOPData;
  77. pOPData = (pOIData->Flags & ODF_CALLCREATEOI) ? NULL :
  78. pOIData->pOPData;
  79. pOptItem->UserData = (DWORD_PTR)pbData;
  80. if (cbECB) {
  81. PEXTCHKBOX pECB;
  82. pOptItem->pExtChkBox =
  83. pECB = (PEXTCHKBOX)pbData;
  84. pbData += cbECB;
  85. pECB->cbSize = sizeof(EXTCHKBOX);
  86. if (pOPData) {
  87. pECB->Flags = pOPData->Flags;
  88. pECB->pTitle = (LPTSTR)pOPData->IDSName;
  89. pECB->IconID = (DWORD)pOPData->IconID;
  90. pECB->pSeparator = (LPTSTR)pOPData->IDSSeparator;
  91. pECB->pCheckedName = (LPTSTR)pOPData->IDSCheckedName;
  92. pOPData++;
  93. }
  94. }
  95. if (cbOP) {
  96. POPTTYPE pOptType;
  97. POPTPARAM pOP;
  98. UINT i;
  99. pOptType = (POPTTYPE)pbData;
  100. pbData += cbOP;
  101. //
  102. // Initialize the OPTITEM
  103. //
  104. pOptItem->pOptType = pOptType;
  105. //
  106. // Initialize the OPTTYPE
  107. //
  108. pOptType->cbSize = sizeof(OPTTYPE);
  109. pOptType->Type = (BYTE)Type;
  110. pOptType->Count = (WORD)cOP;
  111. pOP =
  112. pOptType->pOptParam = (POPTPARAM)(pOptType + 1);
  113. pOptType->Style = pOIData->Style;
  114. for (i = 0; i < cOP; i++, pOP++) {
  115. pOP->cbSize = sizeof(OPTPARAM);
  116. if (pOPData) {
  117. pOP->Flags = (BYTE)(pOPData->Flags & 0xFF);
  118. pOP->Style = (BYTE)(pOPData->Style & 0xFF);
  119. pOP->pData = (LPTSTR)pOPData->IDSName;
  120. pOP->IconID = (DWORD)pOPData->IconID;
  121. pOP->lParam = (LONG)pOPData->sParam;
  122. if (Type == TVOT_PUSHBUTTON) {
  123. (DWORD_PTR)(pOP->pData) += (DWORD_PTR)pPI;
  124. } else {
  125. if (Flags & ODF_INC_IDSNAME) {
  126. (DWORD_PTR)(pOP->pData) += i;
  127. }
  128. if (Flags & ODF_INC_ICONID) {
  129. (DWORD)(pOP->IconID) += i;
  130. }
  131. }
  132. if (!(Flags & ODF_NO_INC_POPDATA)) {
  133. pOPData++;
  134. }
  135. }
  136. }
  137. }
  138. if (pExtraInfo) {
  139. pExtraInfo->pData = (cbExtra) ? pbData : 0;
  140. }
  141. } else {
  142. PLOTERR(("CreateOPTTYPE: LocalAlloc%ld) failed", cbAlloc));
  143. return(FALSE);
  144. }
  145. }
  146. return(TRUE);
  147. }
  148. POPTITEM
  149. FindOptItem(
  150. POPTITEM pOptItem,
  151. UINT cOptItem,
  152. BYTE DMPubID
  153. )
  154. /*++
  155. Routine Description:
  156. This function return the first occurence of the DMPubID
  157. Arguments:
  158. Return Value:
  159. Author:
  160. 16-Nov-1995 Thu 21:01:26 created
  161. Revision History:
  162. --*/
  163. {
  164. while (cOptItem--) {
  165. if (pOptItem->DMPubID == DMPubID) {
  166. return(pOptItem);
  167. }
  168. pOptItem++;
  169. }
  170. PLOTWARN(("FindOptItem: Cannot Find DMPubID=%u", (UINT)DMPubID));
  171. return(NULL);
  172. }
  173. LONG
  174. CallCommonPropertySheetUI(
  175. HWND hWndOwner,
  176. PFNPROPSHEETUI pfnPropSheetUI,
  177. LPARAM lParam,
  178. LPDWORD pResult
  179. )
  180. /*++
  181. Routine Description:
  182. This function dymically load the compstui.dll and call its entry
  183. Arguments:
  184. pfnPropSheetUI - Pointer to callback function
  185. lParam - lParam for the pfnPropSheetUI
  186. pResult - pResult for the CommonPropertySheetUI
  187. Return Value:
  188. LONG - as describe in compstui.h
  189. Author:
  190. 01-Nov-1995 Wed 13:11:19 created
  191. Revision History:
  192. --*/
  193. {
  194. HINSTANCE hInstCompstui;
  195. FARPROC pProc;
  196. LONG Result = ERR_CPSUI_GETLASTERROR;
  197. static const CHAR szCommonPropertySheetUI[] = "CommonPropertySheetUIW";
  198. //
  199. // ONLY need to call the ANSI version of LoadLibrary
  200. //
  201. if ((hInstCompstui = LoadLibraryA(szCompstui)) &&
  202. (pProc = GetProcAddress(hInstCompstui, szCommonPropertySheetUI))) {
  203. Result = (LONG) (*pProc)(hWndOwner, pfnPropSheetUI, lParam, pResult);
  204. }
  205. if (hInstCompstui) {
  206. FreeLibrary(hInstCompstui);
  207. }
  208. return(Result);
  209. }
  210. LONG
  211. DefCommonUIFunc(
  212. PPROPSHEETUI_INFO pPSUIInfo,
  213. LPARAM lParam,
  214. PPRINTERINFO pPI,
  215. LONG_PTR lData
  216. )
  217. /*++
  218. Routine Description:
  219. This is the default processing function for DocumentPropertySheet() and
  220. PrinterPropertySheet()
  221. Arguments:
  222. pPSUIInfo - From the original pfnPropSheetUI(pPSUIInfo, lParam)
  223. lParam - From the original pfnPropSheetUI(pPSUIInfo, lParam)
  224. pPI - Pointer to our instance data
  225. lData - Extra data based on the pPSUIInfo->Reason
  226. Return Value:
  227. LONG Result to be return back from the pfnPropSheetUI()
  228. Author:
  229. 05-Feb-1996 Mon 17:47:51 created
  230. Revision History:
  231. --*/
  232. {
  233. PPROPSHEETUI_INFO_HEADER pPSUIInfoHdr;
  234. LONG Result = -1;
  235. if (pPI) {
  236. switch (pPSUIInfo->Reason) {
  237. case PROPSHEETUI_REASON_INIT:
  238. //
  239. // Default result
  240. //
  241. pPSUIInfo->Result = CPSUI_CANCEL;
  242. pPSUIInfo->UserData = (DWORD_PTR)pPI;
  243. //
  244. // the lData is the return value from the SetupDPOptItems() or
  245. // SetupPPOptItems()
  246. //
  247. if (lData) {
  248. PCOMPROPSHEETUI pCPSUI = pPI->pCPSUI;
  249. pCPSUI->cbSize = sizeof(COMPROPSHEETUI);
  250. pCPSUI->hInstCaller = (HINSTANCE)hPlotUIModule;
  251. pCPSUI->pCallerName = (LPTSTR)IDS_PLOTTER_DRIVER;
  252. pCPSUI->UserData = (DWORD_PTR)pPI;
  253. pCPSUI->pHelpFile = pPI->pHelpFile;
  254. pCPSUI->IconID = GetPlotterIconID(pPI);
  255. pCPSUI->pOptItemName = pPI->PlotDM.dm.dmDeviceName;
  256. pCPSUI->CallerVersion = DRIVER_VERSION;
  257. pCPSUI->OptItemVersion = (WORD)pPI->pPlotGPC->Version;
  258. pCPSUI->pOptItem = pPI->pOptItem;
  259. pCPSUI->cOptItem = pPI->cOptItem;
  260. if (pPI->Flags & PIF_UPDATE_PERMISSION) {
  261. pCPSUI->Flags |= CPSUIF_UPDATE_PERMISSION;
  262. }
  263. if (pPI->hCPSUI = (HANDLE)
  264. pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet,
  265. CPSFUNC_ADD_PCOMPROPSHEETUI,
  266. (LPARAM)pCPSUI,
  267. (LPARAM)&lData)) {
  268. Result = 1;
  269. }
  270. }
  271. break;
  272. case PROPSHEETUI_REASON_GET_INFO_HEADER:
  273. if (pPSUIInfoHdr = (PPROPSHEETUI_INFO_HEADER)lParam) {
  274. pPSUIInfoHdr->Flags = (PSUIHDRF_PROPTITLE |
  275. PSUIHDRF_NOAPPLYNOW);
  276. pPSUIInfoHdr->pTitle = (LPTSTR)lData;
  277. pPSUIInfoHdr->hInst = (HINSTANCE)hPlotUIModule;
  278. pPSUIInfoHdr->IconID = pPI->pCPSUI->IconID;
  279. Result = 1;
  280. }
  281. break;
  282. case PROPSHEETUI_REASON_SET_RESULT:
  283. //
  284. // Save the result and also set the result to the caller.
  285. //
  286. if (pPI->hCPSUI == ((PSETRESULT_INFO)lParam)->hSetResult) {
  287. pPSUIInfo->Result = ((PSETRESULT_INFO)lParam)->Result;
  288. Result = 1;
  289. }
  290. break;
  291. case PROPSHEETUI_REASON_DESTROY:
  292. UnMapPrinter(pPI);
  293. pPSUIInfo->UserData = 0;
  294. Result = 1;
  295. break;
  296. }
  297. }
  298. return(Result);
  299. }