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.

319 lines
12 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: SCANEXT.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/17/1999
  12. *
  13. * DESCRIPTION:
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "wia.h"
  19. #include "resource.h"
  20. #include "wiauiext.h"
  21. #include "wiadefui.h"
  22. #include "ppscan.h"
  23. #include "ppattach.h"
  24. extern HINSTANCE g_hInstance;
  25. /*****************************************************************************
  26. CWiaDefaultUI::Initialize
  27. Called by the shell when the user invokes context menu or property sheet for
  28. one of our items.
  29. ******************************************************************************/
  30. STDMETHODIMP CWiaDefaultUI::Initialize( LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY hkeyProgID )
  31. {
  32. WIA_PUSHFUNCTION(TEXT("CWiaDefaultUI::Initialize"));
  33. if (!lpdobj)
  34. {
  35. return(E_INVALIDARG);
  36. }
  37. FORMATETC fmt;
  38. STGMEDIUM stgm = {0};
  39. fmt.cfFormat = static_cast<CLIPFORMAT>(RegisterClipboardFormat(CFSTR_WIAITEMPTR));
  40. fmt.dwAspect = DVASPECT_CONTENT;
  41. fmt.lindex = -1;
  42. fmt.ptd = NULL;
  43. fmt.tymed = TYMED_ISTREAM;
  44. HRESULT hr = lpdobj->GetData(&fmt, &stgm);
  45. if (SUCCEEDED(hr))
  46. {
  47. WIA_ASSERT(stgm.tymed == TYMED_ISTREAM);
  48. hr = CoUnmarshalInterface(stgm.pstm, IID_IWiaItem, reinterpret_cast<LPVOID*>(&m_pItem));
  49. ReleaseStgMedium(&stgm);
  50. }
  51. if (FAILED(hr))
  52. {
  53. WIA_PRINTHRESULT((hr,TEXT("Unable to get IWiaItem interface")));
  54. }
  55. InitCommonControls();
  56. return hr;
  57. }
  58. static UINT PropPageCallback (HWND hwnd, UINT uMsg, PROPSHEETPAGE *psp)
  59. {
  60. switch (uMsg)
  61. {
  62. case PSPCB_ADDREF:
  63. DllAddRef();
  64. break;
  65. case PSPCB_RELEASE:
  66. DllRelease();
  67. break;
  68. case PSPCB_CREATE:
  69. default:
  70. break;
  71. }
  72. return TRUE;
  73. }
  74. //
  75. // IDD_ATTACHMENTS
  76. //
  77. /*****************************************************************************
  78. CWiaDefaultUI::AddPages
  79. Called by the shell to get our property pages.
  80. ******************************************************************************/
  81. STDMETHODIMP CWiaDefaultUI::AddPages( LPFNADDPROPSHEETPAGE lpfnAddPropSheetPage, LPARAM lParam )
  82. {
  83. WIA_PUSHFUNCTION(TEXT("CWiaDefaultUI::AddPages"));
  84. //
  85. // Make sure we have valid arguments
  86. //
  87. if (!lpfnAddPropSheetPage)
  88. {
  89. return E_INVALIDARG;
  90. }
  91. //
  92. // Assume success
  93. //
  94. HRESULT hr = S_OK;
  95. //
  96. // Make sure we have a valid item. Note that this item will be NULL for multiple selections in the shell.
  97. //
  98. if (m_pItem)
  99. {
  100. //
  101. // Get the item type (we probably don't want to display these pages for root items)
  102. //
  103. LONG lItemType;
  104. hr = m_pItem->GetItemType (&lItemType);
  105. if (SUCCEEDED(hr))
  106. {
  107. //
  108. // Get the root item so we can find out what kind of device this is
  109. //
  110. CComPtr<IWiaItem> pRootItem;
  111. hr = m_pItem->GetRootItem(&pRootItem);
  112. if (SUCCEEDED(hr))
  113. {
  114. //
  115. // Get the device type
  116. //
  117. LONG nDeviceType=0;
  118. if (PropStorageHelpers::GetProperty( pRootItem, WIA_DIP_DEV_TYPE, nDeviceType ))
  119. {
  120. //
  121. // If this is a scanner, add the scanner page
  122. //
  123. if (StiDeviceTypeScanner == GET_STIDEVICE_TYPE(nDeviceType))
  124. {
  125. //
  126. // Get the property that determines whether or not we should suppress this page
  127. // Ignore the return value, because if it doesn't implement it, nSuppressPropertyPages
  128. // will still be 0, and the default is to display the property page
  129. //
  130. LONG nSuppressPropertyPages = 0;
  131. PropStorageHelpers::GetProperty( m_pItem, WIA_IPA_SUPPRESS_PROPERTY_PAGE, nSuppressPropertyPages );
  132. if ((nSuppressPropertyPages & WIA_PROPPAGE_SCANNER_ITEM_GENERAL) == 0)
  133. {
  134. //
  135. // register the brightness contrast control.
  136. //
  137. CBrightnessContrast::RegisterClass(g_hInstance);
  138. //
  139. // Make sure this is not a root item
  140. //
  141. if ((lItemType & WiaItemTypeRoot) == 0)
  142. {
  143. //
  144. // Get the title
  145. //
  146. TCHAR szTitle[MAX_PATH];
  147. LoadString( g_hInstance, IDD_SCAPROP_TITLE, szTitle, MAX_PATH );
  148. //
  149. // Prepare the scanner property page
  150. //
  151. PROPSHEETPAGE psp[1] = {0};
  152. psp[0].dwSize = sizeof(psp[0]);
  153. psp[0].dwFlags = PSP_USECALLBACK | PSP_USETITLE;
  154. psp[0].hInstance = g_hInstance;
  155. psp[0].pszTemplate = MAKEINTRESOURCE(IDD_NEW_SCANPROP);
  156. psp[0].pfnDlgProc = CScannerCommonPropertyPage::DialogProc;
  157. psp[0].lParam = reinterpret_cast<LPARAM>(Item());
  158. psp[0].pszTitle = szTitle;
  159. psp[0].pfnCallback = PropPageCallback;
  160. WiaUiUtil::PreparePropertyPageForFusion(&psp[0]);
  161. //
  162. // Create the property page
  163. //
  164. HPROPSHEETPAGE hPropSheetPage = CreatePropertySheetPage(psp+0);
  165. if (hPropSheetPage)
  166. {
  167. //
  168. // Add the property page
  169. //
  170. if (!lpfnAddPropSheetPage( hPropSheetPage, lParam ))
  171. {
  172. DestroyPropertySheetPage(hPropSheetPage);
  173. hr = E_FAIL;
  174. }
  175. }
  176. else
  177. {
  178. WIA_ERROR((TEXT("CreatePropertySheetPage returned NULL!")));
  179. hr = E_FAIL;
  180. }
  181. }
  182. else
  183. {
  184. WIA_TRACE((TEXT("This was a root item")));
  185. hr = S_OK;
  186. }
  187. }
  188. else
  189. {
  190. WIA_TRACE((TEXT("nSuppressPropertyPages (%08X) contained WIA_PROPPAGE_SCANNER_ITEM_GENERAL (%08X)"), nSuppressPropertyPages, WIA_PROPPAGE_SCANNER_ITEM_GENERAL ));
  191. hr = S_OK;
  192. }
  193. }
  194. CComPtr<IWiaAnnotationHelpers> pWiaAnnotationHelpers;
  195. if (SUCCEEDED(CoCreateInstance( CLSID_WiaDefaultUi, NULL,CLSCTX_INPROC_SERVER, IID_IWiaAnnotationHelpers,(void**)&pWiaAnnotationHelpers )))
  196. {
  197. CAnnotationType AnnotationType = AnnotationNone;
  198. if (SUCCEEDED(pWiaAnnotationHelpers->GetAnnotationType( m_pItem, AnnotationType )))
  199. {
  200. if (AnnotationNone != AnnotationType)
  201. {
  202. //
  203. // Add the attachments page
  204. //
  205. if ((lItemType & WiaItemTypeRoot) == 0)
  206. {
  207. //
  208. // Get the title
  209. //
  210. TCHAR szTitle[MAX_PATH];
  211. LoadString( g_hInstance, IDD_ATTACHMENTSPROP_TITLE, szTitle, MAX_PATH );
  212. //
  213. // Prepare the attachments property page
  214. //
  215. PROPSHEETPAGE psp[1] = {0};
  216. psp[0].dwSize = sizeof(psp[0]);
  217. psp[0].dwFlags = PSP_USECALLBACK | PSP_USETITLE;
  218. psp[0].hInstance = g_hInstance;
  219. psp[0].pszTemplate = MAKEINTRESOURCE(IDD_ATTACHMENTS);
  220. psp[0].pfnDlgProc = CAttachmentCommonPropertyPage::DialogProc;
  221. psp[0].lParam = reinterpret_cast<LPARAM>(Item());
  222. psp[0].pszTitle = szTitle;
  223. psp[0].pfnCallback = PropPageCallback;
  224. WiaUiUtil::PreparePropertyPageForFusion(&psp[0]);
  225. //
  226. // Create the property page
  227. //
  228. HPROPSHEETPAGE hPropSheetPage = CreatePropertySheetPage(psp+0);
  229. if (hPropSheetPage)
  230. {
  231. //
  232. // Add the property page
  233. //
  234. if (!lpfnAddPropSheetPage( hPropSheetPage, lParam ))
  235. {
  236. DestroyPropertySheetPage(hPropSheetPage);
  237. hr = E_FAIL;
  238. }
  239. }
  240. else
  241. {
  242. WIA_ERROR((TEXT("CreatePropertySheetPage returned NULL!")));
  243. hr = E_FAIL;
  244. }
  245. }
  246. else
  247. {
  248. WIA_TRACE((TEXT("This is a root item")));
  249. }
  250. }
  251. else
  252. {
  253. WIA_TRACE((TEXT("pWiaAnnotationHelpers->GetAnnotationType returned AnnotationNone")));
  254. }
  255. }
  256. else
  257. {
  258. WIA_TRACE((TEXT("pWiaAnnotationHelpers->GetAnnotationType failed")));
  259. }
  260. }
  261. else
  262. {
  263. WIA_TRACE((TEXT("Couldn't create the annotation helpers")));
  264. }
  265. }
  266. else
  267. {
  268. WIA_TRACE((TEXT("GetProperty on WIA_DIP_DEV_TYPE failed")));
  269. hr = E_FAIL;
  270. }
  271. }
  272. else
  273. {
  274. WIA_TRACE((TEXT("GetRootItem failed")));
  275. }
  276. }
  277. else
  278. {
  279. WIA_TRACE((TEXT("GetItemType failed")));
  280. }
  281. }
  282. else
  283. {
  284. WIA_TRACE((TEXT("m_pItem was NULL")));
  285. }
  286. if (FAILED(hr))
  287. {
  288. WIA_PRINTHRESULT((hr,TEXT("CWiaDefaultUI::AddPages failed")));
  289. }
  290. return hr;
  291. }