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.

386 lines
13 KiB

  1. #include "stdafx.h"
  2. #include "netplace.h"
  3. #include "pubwiz.h"
  4. #pragma hdrstop
  5. // add net place wizard (v2)
  6. class CAddNetPlace : IWizardSite, IServiceProvider
  7. {
  8. public:
  9. CAddNetPlace();
  10. ~CAddNetPlace();
  11. void _ShowAddNetPlace();
  12. // IUnknown
  13. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObj);
  14. STDMETHOD_(ULONG,AddRef)(void);
  15. STDMETHOD_(ULONG,Release)(void);
  16. // IWizardSite
  17. STDMETHODIMP GetPreviousPage(HPROPSHEETPAGE *phPage);
  18. STDMETHODIMP GetNextPage(HPROPSHEETPAGE *phPage);
  19. STDMETHODIMP GetCancelledPage(HPROPSHEETPAGE *phPage)
  20. { return E_NOTIMPL; }
  21. // IServiceProvider
  22. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppv);
  23. private:
  24. // dialog handlers
  25. static CAddNetPlace* s_GetANP(HWND hwnd, UINT uMsg, LPARAM lParam);
  26. static INT_PTR s_WelcomeDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  27. { CAddNetPlace *panp = s_GetANP(hwnd, uMsg, lParam); return panp->_WelcomeDlgProc(hwnd, uMsg, wParam, lParam); }
  28. static INT_PTR s_DoneDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  29. { CAddNetPlace *panp = s_GetANP(hwnd, uMsg, lParam); return panp->_DoneDlgProc(hwnd, uMsg, wParam, lParam); }
  30. INT_PTR _WelcomeDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  31. INT_PTR _DoneDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  32. HWND _hwndFrame;
  33. LONG _cRef;
  34. IPublishingWizard *_ppw; // publishing wizard object
  35. IResourceMap *_prm; // our resource map object
  36. CNetworkPlace _np;
  37. };
  38. // Construction/destruction
  39. CAddNetPlace::CAddNetPlace() :
  40. _cRef(1)
  41. {
  42. DllAddRef();
  43. }
  44. CAddNetPlace::~CAddNetPlace()
  45. {
  46. DllRelease();
  47. }
  48. // Reference counting of the object
  49. ULONG CAddNetPlace::AddRef()
  50. {
  51. return InterlockedIncrement(&_cRef);
  52. }
  53. ULONG CAddNetPlace::Release()
  54. {
  55. ASSERT( 0 != _cRef );
  56. ULONG cRef = InterlockedDecrement(&_cRef);
  57. if ( 0 == cRef )
  58. {
  59. delete this;
  60. }
  61. return cRef;
  62. }
  63. HRESULT CAddNetPlace::QueryInterface(REFIID riid, void **ppv)
  64. {
  65. static const QITAB qit[] =
  66. {
  67. QITABENT(CAddNetPlace, IWizardSite), // IID_IWizardSite
  68. QITABENT(CAddNetPlace, IServiceProvider), // IID_IServiceProvider
  69. {0, 0 },
  70. };
  71. return QISearch(this, qit, riid, ppv);
  72. }
  73. // Helper functions
  74. CAddNetPlace* CAddNetPlace::s_GetANP(HWND hwnd, UINT uMsg, LPARAM lParam)
  75. {
  76. if (uMsg == WM_INITDIALOG)
  77. {
  78. PROPSHEETPAGE *ppsp = (PROPSHEETPAGE*)lParam;
  79. SetWindowLongPtr(hwnd, GWLP_USERDATA, ppsp->lParam);
  80. return (CAddNetPlace*)ppsp->lParam;
  81. }
  82. return (CAddNetPlace*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  83. }
  84. // Welcome/Intro dialog
  85. INT_PTR CAddNetPlace::_WelcomeDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  86. {
  87. switch (uMsg)
  88. {
  89. case WM_INITDIALOG:
  90. {
  91. _hwndFrame = GetParent(hwnd);
  92. SendDlgItemMessage(hwnd, IDC_PUB_WELCOME, WM_SETFONT, (WPARAM)GetIntroFont(hwnd), 0);
  93. IXMLDOMNode *pdn;
  94. HRESULT hr = _prm->SelectResourceScope(TEXT("dialog"), TEXT("welcome"), &pdn);
  95. if (SUCCEEDED(hr))
  96. {
  97. TCHAR szBuffer[1024];
  98. _prm->LoadString(pdn, TEXT("caption"), szBuffer, ARRAYSIZE(szBuffer));
  99. SetDlgItemText(hwnd, IDC_PUB_WELCOME, szBuffer);
  100. _prm->LoadString(pdn, TEXT("description"), szBuffer, ARRAYSIZE(szBuffer));
  101. SetDlgItemText(hwnd, IDC_PUB_WELCOMEPROMPT, szBuffer);
  102. pdn->Release();
  103. }
  104. return TRUE;
  105. }
  106. case WM_NOTIFY:
  107. {
  108. LPNMHDR pnmh = (LPNMHDR)lParam;
  109. switch (pnmh->code)
  110. {
  111. case PSN_SETACTIVE:
  112. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_NEXT);
  113. return TRUE;
  114. case PSN_WIZNEXT:
  115. {
  116. HPROPSHEETPAGE hpage;
  117. if (SUCCEEDED(_ppw->GetFirstPage(&hpage)))
  118. {
  119. PropSheet_SetCurSel(GetParent(hwnd), hpage, -1);
  120. }
  121. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, (LPARAM)-1);
  122. return TRUE;
  123. }
  124. }
  125. break;
  126. }
  127. }
  128. return FALSE;
  129. }
  130. // Were done, so lets create the link etc.
  131. INT_PTR CAddNetPlace::_DoneDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  132. {
  133. switch ( uMsg )
  134. {
  135. case WM_INITDIALOG:
  136. SendDlgItemMessage(hwnd, IDC_PUB_DONE, WM_SETFONT, (WPARAM)GetIntroFont(hwnd), 0);
  137. return TRUE;
  138. case WM_NOTIFY:
  139. {
  140. LPNMHDR pnmh = (LPNMHDR)lParam;
  141. switch (pnmh->code)
  142. {
  143. case NM_CLICK:
  144. case NM_RETURN:
  145. if (pnmh->idFrom == IDC_PUB_COMPLETEMSG)
  146. {
  147. _np.CreatePlace(hwnd, TRUE);
  148. return TRUE;
  149. }
  150. break;
  151. case PSN_SETACTIVE:
  152. {
  153. TCHAR szTemp[INTERNET_MAX_URL_LENGTH] = {0};
  154. TCHAR szBuffer[MAX_PATH+INTERNET_MAX_URL_LENGTH];
  155. // using the manifest lets work out where the net place was created to.
  156. IXMLDOMDocument *pdocManifest;
  157. HRESULT hr = _ppw->GetTransferManifest(NULL, &pdocManifest);
  158. if (SUCCEEDED(hr))
  159. {
  160. IXMLDOMNode *pdnUploadInfo;
  161. if (S_OK == pdocManifest->selectSingleNode(XPATH_UPLOADINFO, &pdnUploadInfo))
  162. {
  163. hr = GetURLFromElement(pdnUploadInfo, ELEMENT_TARGET, szTemp, ARRAYSIZE(szTemp));
  164. if (SUCCEEDED(hr))
  165. {
  166. // set the target so that we create the place
  167. _np.SetTarget(NULL, szTemp, NPTF_VALIDATE | NPTF_ALLOWWEBFOLDERS);
  168. IXMLDOMNode *pdnTarget;
  169. hr = pdocManifest->selectSingleNode(XPATH_UPLOADTARGET, &pdnTarget);
  170. if (hr == S_OK)
  171. {
  172. // get the user name (for the FTP case)
  173. if (SUCCEEDED(GetStrFromAttribute(pdnTarget, ATTRIBUTE_USERNAME, szBuffer, ARRAYSIZE(szBuffer))))
  174. _np.SetLoginInfo(szBuffer, NULL);
  175. // lets get the prefered display name, if this is not found then we will default to
  176. // using the name generated by the net places code.
  177. if (SUCCEEDED(GetStrFromAttribute(pdnUploadInfo, ATTRIBUTE_FRIENDLYNAME, szTemp, ARRAYSIZE(szTemp))))
  178. _np.SetName(NULL, szTemp);
  179. pdnTarget->Release();
  180. }
  181. }
  182. pdnUploadInfo->Release();
  183. }
  184. pdocManifest->Release();
  185. }
  186. // lets format up the text for the control.
  187. FormatMessageString(IDS_ANP_SUCCESS, szBuffer, ARRAYSIZE(szBuffer), szTemp);
  188. SetDlgItemText(hwnd, IDC_PUB_COMPLETEMSG, szBuffer);
  189. // lets move the controls accordingly
  190. UINT ctls[] = { IDC_PUB_OPENFILES };
  191. int dy = SizeControlFromText(hwnd, IDC_PUB_COMPLETEMSG, szBuffer);
  192. MoveControls(hwnd, ctls, ARRAYSIZE(ctls), 0, dy);
  193. // default to opening the place when the user closes this wizard.
  194. CheckDlgButton(hwnd, IDC_PUB_OPENFILES, TRUE);
  195. // were done.
  196. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_FINISH);
  197. return TRUE;
  198. }
  199. case PSN_WIZFINISH:
  200. {
  201. _np.CreatePlace(hwnd, (IsDlgButtonChecked(hwnd, IDC_PUB_OPENFILES) == BST_CHECKED));
  202. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, (LPARAM)FALSE);
  203. return TRUE;
  204. }
  205. }
  206. break;
  207. }
  208. }
  209. return FALSE;
  210. }
  211. // IServiceProvider
  212. STDMETHODIMP CAddNetPlace::QueryService(REFGUID guidService, REFIID riid, void **ppv)
  213. {
  214. if (guidService == SID_ResourceMap)
  215. return _prm->QueryInterface(riid, ppv);
  216. *ppv = NULL;
  217. return E_FAIL;
  218. }
  219. // Site object helpers, these allow nagivation back and forward in the wizard
  220. HRESULT CAddNetPlace::GetPreviousPage(HPROPSHEETPAGE *phPage)
  221. {
  222. int i = PropSheet_IdToIndex(_hwndFrame, IDD_PUB_WELCOME);
  223. *phPage = PropSheet_IndexToPage(_hwndFrame, i);
  224. return S_OK;
  225. }
  226. HRESULT CAddNetPlace::GetNextPage(HPROPSHEETPAGE *phPage)
  227. {
  228. int i = PropSheet_IdToIndex(_hwndFrame, IDD_ANP_DONE);
  229. *phPage = PropSheet_IndexToPage(_hwndFrame, i);
  230. return S_OK;
  231. }
  232. // main entry point which shows the wizard
  233. void CAddNetPlace::_ShowAddNetPlace()
  234. {
  235. struct
  236. {
  237. INT idPage;
  238. INT idHeading;
  239. INT idSubHeading;
  240. DWORD dwFlags;
  241. DLGPROC dlgproc;
  242. }
  243. c_wpPages[] =
  244. {
  245. {IDD_PUB_WELCOME, 0, 0, PSP_HIDEHEADER, CAddNetPlace::s_WelcomeDlgProc},
  246. {IDD_ANP_DONE, 0, 0, PSP_HIDEHEADER, CAddNetPlace::s_DoneDlgProc},
  247. };
  248. // create the page array, we add the welcome page and the finished page
  249. // the rest is loaded as an extension to the wizard.
  250. HPROPSHEETPAGE hpages[10] = { 0 };
  251. for (int i = 0; i < ARRAYSIZE(c_wpPages) ; i++ )
  252. {
  253. PROPSHEETPAGE psp = { 0 };
  254. psp.dwSize = SIZEOF(PROPSHEETPAGE);
  255. psp.hInstance = g_hinst;
  256. psp.lParam = (LPARAM)this;
  257. psp.dwFlags = PSP_USETITLE | PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE | c_wpPages[i].dwFlags;
  258. psp.pszTemplate = MAKEINTRESOURCE(c_wpPages[i].idPage);
  259. psp.pfnDlgProc = c_wpPages[i].dlgproc;
  260. psp.pszTitle = MAKEINTRESOURCE(IDS_ANP_CAPTION);
  261. psp.pszHeaderTitle = MAKEINTRESOURCE(c_wpPages[i].idHeading);
  262. psp.pszHeaderSubTitle = MAKEINTRESOURCE(c_wpPages[i].idSubHeading);
  263. hpages[i] = CreatePropertySheetPage(&psp);
  264. }
  265. // create the wizard extension (for publishing) and have it append its
  266. // pages, if that succeeds then lets show the wizard.
  267. HRESULT hr = CResourceMap_Initialize(L"res://netplwiz.dll/xml/resourcemap.xml", &_prm);
  268. if (SUCCEEDED(hr))
  269. {
  270. hr = _prm->LoadResourceMap(TEXT("wizard"), TEXT("AddNetPlace"));
  271. if (SUCCEEDED(hr))
  272. {
  273. hr = CoCreateInstance(CLSID_PublishingWizard, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IPublishingWizard, &_ppw));
  274. if (SUCCEEDED(hr))
  275. {
  276. hr = _ppw->Initialize(NULL, SHPWHF_NOFILESELECTOR|SHPWHF_VALIDATEVIAWEBFOLDERS, TEXT("AddNetPlace"));
  277. if (SUCCEEDED(hr))
  278. {
  279. IUnknown_SetSite(_ppw, SAFECAST(this, IWizardSite*)); // we are the site
  280. UINT nPages;
  281. hr = _ppw->AddPages(&hpages[i], ARRAYSIZE(hpages)-i, &nPages);
  282. if (SUCCEEDED(hr))
  283. {
  284. PROPSHEETHEADER psh = { 0 };
  285. psh.dwSize = SIZEOF(PROPSHEETHEADER);
  286. psh.hInstance = g_hinst;
  287. psh.dwFlags = PSH_WIZARD | PSH_WIZARD97 | PSH_WATERMARK | PSH_STRETCHWATERMARK | PSH_HEADER;
  288. psh.pszbmHeader = MAKEINTRESOURCE(IDB_ANP_BANNER);
  289. psh.pszbmWatermark = MAKEINTRESOURCE(IDB_ANP_WATERMARK);
  290. psh.phpage = hpages;
  291. psh.nPages = i+nPages;
  292. PropertySheetIcon(&psh, MAKEINTRESOURCE(IDI_ADDNETPLACE));
  293. }
  294. IUnknown_SetSite(_ppw, NULL);
  295. }
  296. _ppw->Release();
  297. }
  298. }
  299. _prm->Release();
  300. }
  301. }
  302. // RunDll entry point used by the world to access the Add Net Place wizard.
  303. void APIENTRY AddNetPlaceRunDll(HWND hwndStub, HINSTANCE hAppInstance, LPSTR pszCmdLine, int nCmdShow)
  304. {
  305. if (SUCCEEDED(CoInitialize(NULL)))
  306. {
  307. CAddNetPlace *panp = new CAddNetPlace;
  308. if (panp)
  309. {
  310. panp->_ShowAddNetPlace();
  311. panp->Release();
  312. }
  313. CoUninitialize();
  314. }
  315. }