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.

214 lines
6.0 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. AddPropSheetPage(m_HardwarePage, (LPARAM)this);
  90. //
  91. // Add any extra pages that the extensions want in there.
  92. //
  93. if (hpsxa) {
  94. IRINFO((_T("Adding prop sheet extensions...")));
  95. added = SHAddFromPropSheetExtArray(hpsxa,
  96. AddPropSheetPage,
  97. (LPARAM)this );
  98. IRINFO((_T("Added %x prop sheet pages."), added));
  99. }
  100. //
  101. // sanity check so that we won't be in infinite loop.
  102. //
  103. if ((iSelectPage >= psh.nPages) ) {
  104. //
  105. // start page is out of range.
  106. //
  107. psh.nStartPage = 0;
  108. }
  109. ::PropertySheet(&psh);
  110. if (hpsxa) {
  111. //
  112. // Unload any of our extensions
  113. //
  114. SHDestroyPropSheetExtArray(hpsxa);
  115. }
  116. LinkWindow_UnregisterClass(hInstance);
  117. }
  118. /////////////////////////////////////////////////////////////////////////////
  119. // IrPropSheet
  120. IrPropSheet::IrPropSheet(HINSTANCE hInst, UINT nIDCaption, HWND hParent, UINT iSelectPage) :
  121. hInstance(hInst),
  122. m_FileTransferPage(hInst, hParent),
  123. m_ImageTransferPage(hInst, hParent),
  124. m_HardwarePage(hInst, hParent)
  125. {
  126. TCHAR buf[MAX_PATH];
  127. IRINFO((_T("IrPropSheet::IrPropSheet")));
  128. ::LoadString(hInstance, nIDCaption, buf, MAX_PATH);
  129. PropertySheet(buf, hParent, iSelectPage);
  130. }
  131. IrPropSheet::IrPropSheet(HINSTANCE hInst, LPCTSTR pszCaption, HWND hParent, UINT iSelectPage) :
  132. hInstance(hInst), m_FileTransferPage(hInst, hParent),
  133. m_ImageTransferPage(hInst, hParent), m_HardwarePage(hInst, hParent)
  134. {
  135. IRINFO((_T("IrPropSheet::IrPropSheet")));
  136. PropertySheet(pszCaption, hParent, iSelectPage);
  137. }
  138. IrPropSheet::~IrPropSheet()
  139. {
  140. }
  141. ////////////////////////////////////////////////////////////////////////
  142. // Function that checks if the IrDA protocol is supported on the
  143. // machine or not. If not, then CPlApplet returns FALSE when it gets
  144. // the CPL_INIT message, thus preventing the control panel from
  145. // displaying the applet.
  146. ////////////////////////////////////////////////////////////////////////
  147. BOOL IrPropSheet::IsIrDASupported (void)
  148. {
  149. WORD wVersionRequested;
  150. WSADATA wsaData;
  151. int err;
  152. BOOL retVal = FALSE;
  153. SOCKET sock;
  154. IRINFO((_T("IrPropSheet::IsIrDASupported")));
  155. wVersionRequested = MAKEWORD( 1, 1 );
  156. err = WSAStartup( wVersionRequested, &wsaData );
  157. if ( err != 0 )
  158. return FALSE; //a usable WinSock DLL could not be found
  159. if ( LOBYTE( wsaData.wVersion ) != 1 ||
  160. HIBYTE( wsaData.wVersion ) != 1 ) {
  161. WSACleanup(); //the WinSock DLL is not acceptable.
  162. IRINFO((_T("Winsock DLL not acceptable")));
  163. return FALSE;
  164. }
  165. //The WinSock DLL is acceptable. Proceed.
  166. sock = socket (AF_IRDA, SOCK_STREAM, 0);
  167. if (INVALID_SOCKET != sock) //BUGBUG: need to explicitly check for WSAEAFNOSUPPORT
  168. {
  169. closesocket(sock);
  170. retVal = TRUE;
  171. }
  172. IRINFO((_T("Irda supported = %x"), retVal));
  173. //cleanup before leaving
  174. WSACleanup();
  175. return retVal;
  176. }