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.

262 lines
7.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: irpropsheet.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // IrPropSheet.cpp : implementation file
  11. //
  12. #include "precomp.hxx"
  13. #include "irpropsheet.h"
  14. #include "debug.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. const UINT IRPROPSHEET_MAX_PAGES = 3;
  21. BOOL CALLBACK IrPropSheet::AddPropSheetPage(
  22. HPROPSHEETPAGE hpage,
  23. LPARAM lParam)
  24. {
  25. IrPropSheet *irprop = (IrPropSheet*) lParam;
  26. PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)&(irprop->psh);
  27. IRINFO((_T("IrPropSheet::AddPropSheetPage")));
  28. if (hpage && (ppsh->nPages < MAX_PAGES))
  29. {
  30. ppsh->phpage[ppsh->nPages++] = hpage;
  31. return (TRUE);
  32. }
  33. return (FALSE);
  34. }
  35. void IrPropSheet::PropertySheet(LPCTSTR pszCaption, HWND hParent, UINT iSelectPage)
  36. {
  37. HPSXA hpsxa;
  38. UINT added;
  39. BOOL isIrdaSupported = IsIrDASupported();
  40. INITCOMMONCONTROLSEX icc = { 0 };
  41. icc.dwSize = sizeof(icc);
  42. icc.dwICC = ICC_WIN95_CLASSES;
  43. InitCommonControlsEx(&icc);
  44. LinkWindow_RegisterClass();
  45. IRINFO((_T("IrPropSheet::PropertySheet")));
  46. //
  47. // Property page init
  48. //
  49. ZeroMemory(&psh, sizeof(psh));
  50. psh.hwndParent = hParent;
  51. psh.dwSize = sizeof(psh);
  52. psh.dwFlags = PSH_USECALLBACK;
  53. psh.hInstance = hInstance;
  54. psh.pszCaption = pszCaption;
  55. psh.nPages = 0;
  56. psh.phpage = hp;
  57. psh.nStartPage = iSelectPage;
  58. //
  59. // Check for any installed extensions.
  60. //
  61. hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, sc_szRegWireless, 8);
  62. //
  63. // Add the file transfer page, giving the extensions a chance to replace it.
  64. //
  65. if ((!hpsxa ||
  66. !SHReplaceFromPropSheetExtArray(hpsxa,
  67. CPLPAGE_FILE_XFER,
  68. AddPropSheetPage,
  69. (LPARAM)this)) &&
  70. isIrdaSupported) {
  71. IRINFO((_T("Adding infrared page...")));
  72. AddPropSheetPage(m_FileTransferPage, (LPARAM)this);
  73. }
  74. //
  75. // Add the image transfer page, giving the extensions a chance to replace it.
  76. //
  77. if ((!hpsxa ||
  78. !SHReplaceFromPropSheetExtArray(hpsxa,
  79. CPLPAGE_IMAGE_XFER,
  80. AddPropSheetPage,
  81. (LPARAM)this)) &&
  82. isIrdaSupported) {
  83. IRINFO((_T("Adding image page...")));
  84. AddPropSheetPage(m_ImageTransferPage, (LPARAM)this);
  85. }
  86. //
  87. // Extensions are not allowed to extend the hardware page
  88. //
  89. #if 0
  90. //
  91. // Add the hardware page, giving the extensions a chance to replace it.
  92. //
  93. if (!hpsxa ||
  94. !SHReplaceFromPropSheetExtArray(hpsxa,
  95. CPLPAGE_HARDWARE,
  96. AddPropSheetPage,
  97. (LPARAM)this)) {
  98. IRINFO((_T("Adding hardware page...")));
  99. AddPropSheetPage(m_HardwarePage, (LPARAM)this);
  100. }
  101. #else
  102. AddPropSheetPage(m_HardwarePage, (LPARAM)this);
  103. #endif
  104. //
  105. // Add any extra pages that the extensions want in there.
  106. //
  107. if (hpsxa) {
  108. IRINFO((_T("Adding prop sheet extensions...")));
  109. added = SHAddFromPropSheetExtArray(hpsxa,
  110. AddPropSheetPage,
  111. (LPARAM)this );
  112. IRINFO((_T("Added %x prop sheet pages."), added));
  113. }
  114. //sanity check so that we won't be in infinite loop.
  115. if (iSelectPage >= psh.nPages) {
  116. // start page is out of range.
  117. psh.nStartPage = -1;
  118. }
  119. ::PropertySheet(&psh);
  120. if (hpsxa) {
  121. //
  122. // Unload any of our extensions
  123. //
  124. SHDestroyPropSheetExtArray(hpsxa);
  125. }
  126. LinkWindow_UnregisterClass(hInstance);
  127. }
  128. /////////////////////////////////////////////////////////////////////////////
  129. // IrPropSheet
  130. IrPropSheet::IrPropSheet(HINSTANCE hInst, UINT nIDCaption, HWND hParent, UINT iSelectPage) :
  131. hInstance(hInst),
  132. m_FileTransferPage(hInst, hParent),
  133. m_ImageTransferPage(hInst, hParent),
  134. m_HardwarePage(hInst, hParent)
  135. {
  136. TCHAR buf[MAX_PATH];
  137. IRINFO((_T("IrPropSheet::IrPropSheet")));
  138. ::LoadString(hInstance, nIDCaption, buf, MAX_PATH);
  139. PropertySheet(buf, hParent, iSelectPage);
  140. }
  141. IrPropSheet::IrPropSheet(HINSTANCE hInst, LPCTSTR pszCaption, HWND hParent, UINT iSelectPage) :
  142. hInstance(hInst), m_FileTransferPage(hInst, hParent),
  143. m_ImageTransferPage(hInst, hParent), m_HardwarePage(hInst, hParent)
  144. {
  145. IRINFO((_T("IrPropSheet::IrPropSheet")));
  146. PropertySheet(pszCaption, hParent, iSelectPage);
  147. }
  148. IrPropSheet::~IrPropSheet()
  149. {
  150. }
  151. ////////////////////////////////////////////////////////////////////////
  152. // Function that checks if the IrDA protocol is supported on the
  153. // machine or not. If not, then CPlApplet returns FALSE when it gets
  154. // the CPL_INIT message, thus preventing the control panel from
  155. // displaying the applet.
  156. ////////////////////////////////////////////////////////////////////////
  157. BOOL IrPropSheet::IsIrDASupported (void)
  158. {
  159. WORD wVersionRequested;
  160. WSADATA wsaData;
  161. int err;
  162. BOOL retVal = FALSE;
  163. SOCKET sock;
  164. IRINFO((_T("IrPropSheet::IsIrDASupported")));
  165. wVersionRequested = MAKEWORD( 1, 1 );
  166. err = WSAStartup( wVersionRequested, &wsaData );
  167. if ( err != 0 )
  168. return FALSE; //a usable WinSock DLL could not be found
  169. if ( LOBYTE( wsaData.wVersion ) != 1 ||
  170. HIBYTE( wsaData.wVersion ) != 1 ) {
  171. WSACleanup(); //the WinSock DLL is not acceptable.
  172. IRINFO((_T("Winsock DLL not acceptable")));
  173. return FALSE;
  174. }
  175. //The WinSock DLL is acceptable. Proceed.
  176. sock = socket (AF_IRDA, SOCK_STREAM, 0);
  177. if (INVALID_SOCKET != sock) //BUGBUG: need to explicitly check for WSAEAFNOSUPPORT
  178. {
  179. closesocket(sock);
  180. retVal = TRUE;
  181. }
  182. IRINFO((_T("Irda supported = %x"), retVal));
  183. //cleanup before leaving
  184. WSACleanup();
  185. return retVal;
  186. }
  187. /*
  188. INT_PTR IrPropSheet::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
  189. {
  190. if (msg == g_uIPMsg) {
  191. return OnInterProcessMsg (wParam, lParam);
  192. } else if (msg == WM_INITDIALOG) {
  193. return OnInitDialog(hDlg);
  194. }
  195. return FALSE;
  196. }
  197. */
  198. /*
  199. int CALLBACK IrPropSheet::OnInitDialog()
  200. {
  201. g_hwndPropSheet = hDlg;
  202. DWORD dwStyle = ::GetWindowLongPtr(hDlg, GWL_EXSTYLE);
  203. DWORD dwNewStyle = dwStyle | WS_EX_CONTEXTHELP;
  204. ::SetWindowLongPtr(hDlg, GWL_EXSTYLE, dwNewStyle);
  205. return bResult;
  206. }
  207. //
  208. // Function to handle inter-process communication(the g_uIPMsg)
  209. // Input:
  210. // wParam -- contain IPMSG_ command
  211. // lParam -- contain command's extra parameters.
  212. // Output:
  213. // depends on command. -1 if the command failed.
  214. //
  215. LRESULT IrPropSheet::OnInterProcessMsg (WPARAM wParam, LPARAM lParam)
  216. {
  217. if (IPMSG_REQUESTSIGNATURE == lParam)
  218. {
  219. if (IPMSG_SIGNATURECHECK == wParam)
  220. return (LRESULT)IPMSG_REPLYSIGNATURE;
  221. }
  222. return (LRESULT)-1;
  223. } */