Sync with trunk (r48545)
[reactos.git] / dll / win32 / netshell / lanconnectui.c
1 #include <precomp.h>
2
3 /// CLASSID
4 /// {7007ACC5-3202-11D1-AAD2-00805FC1270E}
5 /// open network properties and wlan properties
6
7 typedef enum
8 {
9 NET_TYPE_CLIENT = 1,
10 NET_TYPE_SERVICE = 2,
11 NET_TYPE_PROTOCOL = 3
12 }NET_TYPE;
13
14 typedef struct
15 {
16 NET_TYPE Type;
17 DWORD dwCharacteristics;
18 LPWSTR szHelp;
19 INetCfgComponent *pNCfgComp;
20 UINT NumPropDialogOpen;
21 }NET_ITEM, *PNET_ITEM;
22
23 typedef struct
24 {
25 INetConnectionPropertyUi2 *lpVtbl;
26 INetLanConnectionUiInfo * lpLanConUiInfoVtbl;
27 INetConnectionConnectUi * lpNetConnectionConnectUi;
28 INetConnection * pCon;
29 INetCfgLock *NCfgLock;
30 INetCfg * pNCfg;
31 NETCON_PROPERTIES * pProperties;
32 LONG ref;
33 }INetConnectionPropertyUiImpl, *LPINetConnectionPropertyUiImpl;
34
35 static __inline LPINetConnectionPropertyUiImpl impl_from_NetLanConnectionUiInfo(INetLanConnectionUiInfo *iface)
36 {
37 return (LPINetConnectionPropertyUiImpl)((char *)iface - FIELD_OFFSET(INetConnectionPropertyUiImpl, lpLanConUiInfoVtbl));
38 }
39
40 static __inline LPINetConnectionPropertyUiImpl impl_from_NetConnectionConnectUi(INetConnectionConnectUi *iface)
41 {
42 return (LPINetConnectionPropertyUiImpl)((char *)iface - FIELD_OFFSET(INetConnectionPropertyUiImpl, lpNetConnectionConnectUi));
43 }
44
45
46 HPROPSHEETPAGE
47 InitializePropertySheetPage(LPWSTR resname, DLGPROC dlgproc, LPARAM lParam, LPWSTR szTitle)
48 {
49 PROPSHEETPAGEW ppage;
50
51 memset(&ppage, 0x0, sizeof(PROPSHEETPAGEW));
52 ppage.dwSize = sizeof(PROPSHEETPAGEW);
53 ppage.dwFlags = PSP_DEFAULT;
54 ppage.u.pszTemplate = resname;
55 ppage.pfnDlgProc = dlgproc;
56 ppage.lParam = lParam;
57 ppage.hInstance = netshell_hInstance;
58 if (szTitle)
59 {
60 ppage.dwFlags |= PSP_USETITLE;
61 ppage.pszTitle = szTitle;
62 }
63 return CreatePropertySheetPageW(&ppage);
64 }
65
66 VOID
67 AddItemToListView(HWND hDlgCtrl, PNET_ITEM pItem, LPWSTR szName, BOOL bChecked)
68 {
69 LVITEMW lvItem;
70
71 ZeroMemory(&lvItem, sizeof(lvItem));
72 lvItem.mask = LVIF_TEXT | LVIF_PARAM;
73 lvItem.pszText = szName;
74 lvItem.lParam = (LPARAM)pItem;
75 lvItem.iItem = ListView_GetItemCount(hDlgCtrl);
76 lvItem.iItem = SendMessageW(hDlgCtrl, LVM_INSERTITEMW, 0, (LPARAM)&lvItem);
77 ListView_SetCheckState(hDlgCtrl, lvItem.iItem, bChecked);
78 }
79
80 BOOL
81 GetINetCfgComponent(INetCfg * pNCfg, INetConnectionPropertyUiImpl * This, INetCfgComponent ** pOut)
82 {
83 LPWSTR pName;
84 HRESULT hr;
85 INetCfgComponent * pNCg;
86 ULONG Fetched;
87 IEnumNetCfgComponent * pEnumCfg;
88
89 hr = INetCfg_EnumComponents(pNCfg, &GUID_DEVCLASS_NET, &pEnumCfg);
90 if (FAILED(hr))
91 {
92 return FALSE;
93 }
94
95 while(IEnumNetCfgComponent_Next(pEnumCfg, 1, &pNCg, &Fetched) == S_OK)
96 {
97 hr = INetCfgComponent_GetDisplayName(pNCg, &pName);
98 if (SUCCEEDED(hr))
99 {
100 if (!_wcsicmp(pName, This->pProperties->pszwDeviceName))
101 {
102 *pOut = pNCg;
103 IEnumNetCfgComponent_Release(pEnumCfg);
104 return TRUE;
105 }
106 CoTaskMemFree(pName);
107 }
108 INetCfgComponent_Release(pNCg);
109 }
110 IEnumNetCfgComponent_Release(pEnumCfg);
111 return FALSE;
112 }
113
114 VOID
115 EnumComponents(HWND hDlgCtrl, INetConnectionPropertyUiImpl * This, INetCfg * pNCfg, const GUID * CompGuid, UINT Type)
116 {
117 HRESULT hr;
118 IEnumNetCfgComponent * pENetCfg;
119 INetCfgComponent *pNCfgComp, *pAdapterCfgComp;
120 INetCfgComponentBindings * pCompBind;
121 ULONG Num;
122 DWORD dwCharacteristics;
123 LPOLESTR pDisplayName, pHelpText;
124 PNET_ITEM pItem;
125 BOOL bChecked;
126
127 hr = INetCfg_EnumComponents(pNCfg, CompGuid, &pENetCfg);
128 if (FAILED(hr))
129 {
130 INetCfg_Release(pNCfg);
131 return;
132 }
133 while(IEnumNetCfgComponent_Next(pENetCfg, 1, &pNCfgComp, &Num) == S_OK)
134 {
135 hr = INetCfgComponent_GetCharacteristics(pNCfgComp, &dwCharacteristics);
136 if (SUCCEEDED(hr) && (dwCharacteristics & NCF_HIDDEN))
137 {
138 INetCfgComponent_Release(pNCfgComp);
139 continue;
140 }
141 pDisplayName = NULL;
142 pHelpText = NULL;
143 hr = INetCfgComponent_GetDisplayName(pNCfgComp, &pDisplayName);
144 hr = INetCfgComponent_GetHelpText(pNCfgComp, &pHelpText);
145 bChecked = TRUE; //ReactOS hack
146 hr = INetCfgComponent_QueryInterface(pNCfgComp, &IID_INetCfgComponentBindings, (LPVOID*)&pCompBind);
147 if (SUCCEEDED(hr))
148 {
149 if (GetINetCfgComponent(pNCfg, This, &pAdapterCfgComp))
150 {
151 hr = INetCfgComponentBindings_IsBoundTo(pCompBind, pAdapterCfgComp);
152 if (hr == S_OK)
153 bChecked = TRUE;
154 else
155 bChecked = FALSE;
156 INetCfgComponent_Release(pAdapterCfgComp);
157 INetCfgComponentBindings_Release(pCompBind);
158 }
159 }
160 pItem = CoTaskMemAlloc(sizeof(NET_ITEM));
161 if (!pItem)
162 continue;
163 pItem->dwCharacteristics = dwCharacteristics;
164 pItem->szHelp = pHelpText;
165 pItem->Type = Type;
166 pItem->pNCfgComp = pNCfgComp;
167 pItem->NumPropDialogOpen = 0;
168
169
170 AddItemToListView(hDlgCtrl, pItem, pDisplayName, bChecked);
171 CoTaskMemFree(pDisplayName);
172 }
173 IEnumNetCfgComponent_Release(pENetCfg);
174 }
175
176
177 VOID
178 InitializeLANPropertiesUIDlg(HWND hwndDlg, INetConnectionPropertyUiImpl * This)
179 {
180 HRESULT hr;
181 INetCfg * pNCfg;
182 INetCfgLock * pNCfgLock;
183 HWND hDlgCtrl = GetDlgItem(hwndDlg, IDC_COMPONENTSLIST);
184 LVCOLUMNW lc;
185 RECT rc;
186 DWORD dwStyle;
187 LPWSTR pDisplayName;
188 LVITEMW li;
189
190 SendDlgItemMessageW(hwndDlg, IDC_NETCARDNAME, WM_SETTEXT, 0, (LPARAM)This->pProperties->pszwDeviceName);
191 if (This->pProperties->dwCharacter & NCCF_SHOW_ICON)
192 {
193 /* check show item on taskbar*/
194 SendDlgItemMessageW(hwndDlg, IDC_SHOWTASKBAR, BM_SETCHECK, BST_CHECKED, 0);
195 }
196 if (This->pProperties->dwCharacter & NCCF_NOTIFY_DISCONNECTED)
197 {
198 /* check notify item */
199 SendDlgItemMessageW(hwndDlg, IDC_NOTIFYNOCONNECTION, BM_SETCHECK, BST_CHECKED, 0);
200 }
201
202 memset(&lc, 0, sizeof(LV_COLUMN));
203 lc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_FMT;
204 lc.fmt = LVCFMT_FIXED_WIDTH;
205 if (GetClientRect(hDlgCtrl, &rc))
206 {
207 lc.mask |= LVCF_WIDTH;
208 lc.cx = rc.right - rc.left;
209 }
210 lc.pszText = L"";
211 (void)SendMessageW(hDlgCtrl, LVM_INSERTCOLUMNW, 0, (LPARAM)&lc);
212 dwStyle = (DWORD) SendMessage(hDlgCtrl, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
213 dwStyle = dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES;
214 SendMessage(hDlgCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
215
216
217
218 hr = CoCreateInstance(&CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, &IID_INetCfg, (LPVOID*)&pNCfg);
219 if (FAILED(hr))
220 return;
221
222 hr = INetCfgLock_QueryInterface(pNCfg, &IID_INetCfgLock, (LPVOID*)&pNCfgLock);
223 hr = INetCfgLock_AcquireWriteLock(pNCfgLock, 100, L"", &pDisplayName);
224 if (hr == S_FALSE)
225 {
226 CoTaskMemFree(pDisplayName);
227 return;
228 }
229
230 This->NCfgLock = pNCfgLock;
231 hr = INetCfg_Initialize(pNCfg, NULL);
232 if (FAILED(hr))
233 {
234 INetCfg_Release(pNCfg);
235 return;
236 }
237
238 EnumComponents(hDlgCtrl, This, pNCfg, &GUID_DEVCLASS_NETCLIENT, NET_TYPE_CLIENT);
239 EnumComponents(hDlgCtrl, This, pNCfg, &GUID_DEVCLASS_NETSERVICE, NET_TYPE_SERVICE);
240 EnumComponents(hDlgCtrl, This, pNCfg, &GUID_DEVCLASS_NETTRANS, NET_TYPE_PROTOCOL);
241 This->pNCfg = pNCfg;
242
243 ZeroMemory(&li, sizeof(li));
244 li.mask = LVIF_STATE;
245 li.stateMask = (UINT)-1;
246 li.state = LVIS_FOCUSED|LVIS_SELECTED;
247 (void)SendMessageW(hDlgCtrl, LVM_SETITEMW, 0, (LPARAM)&li);
248 }
249
250 VOID
251 ShowNetworkComponentProperties(
252 HWND hwndDlg,
253 INetConnectionPropertyUiImpl * This)
254 {
255 LVITEMW lvItem;
256 HWND hDlgCtrl;
257 UINT Index, Count;
258 HRESULT hr;
259 INetCfgComponent * pNCfgComp;
260 PNET_ITEM pItem;
261
262 hDlgCtrl = GetDlgItem(hwndDlg, IDC_COMPONENTSLIST);
263 Count = ListView_GetItemCount(hDlgCtrl);
264 if (!Count)
265 return;
266
267 ZeroMemory(&lvItem, sizeof(LVITEMW));
268 lvItem.mask = LVIF_PARAM | LVIF_STATE;
269 lvItem.stateMask = (UINT)-1;
270 for (Index = 0; Index < Count; Index++)
271 {
272 lvItem.iItem = Index;
273 if (SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&lvItem))
274 {
275 if (lvItem.state & LVIS_SELECTED)
276 break;
277 }
278 }
279
280 if (!(lvItem.state & LVIS_SELECTED))
281 {
282 return;
283 }
284
285 pItem = (PNET_ITEM)lvItem.lParam;
286 pNCfgComp = (INetCfgComponent*) pItem->pNCfgComp;
287 hr = INetCfgComponent_RaisePropertyUi(pNCfgComp, GetParent(hwndDlg), NCRP_QUERY_PROPERTY_UI, (IUnknown*)This);
288 if (SUCCEEDED(hr))
289 {
290 hr = INetCfgComponent_RaisePropertyUi(pNCfgComp, GetParent(hwndDlg), NCRP_SHOW_PROPERTY_UI, (IUnknown*)This);
291 }
292 }
293
294
295 INT_PTR
296 CALLBACK
297 LANPropertiesUIDlg(
298 HWND hwndDlg,
299 UINT uMsg,
300 WPARAM wParam,
301 LPARAM lParam
302 )
303 {
304 PROPSHEETPAGE *page;
305 LPNMLISTVIEW lppl;
306 LVITEMW li;
307 PNET_ITEM pItem;
308 INetConnectionPropertyUiImpl * This;
309 LPPSHNOTIFY lppsn;
310 DWORD dwShowIcon;
311 HRESULT hr;
312 WCHAR szKey[200];
313 LPOLESTR pStr;
314 HKEY hKey;
315
316 switch(uMsg)
317 {
318 case WM_INITDIALOG:
319 page = (PROPSHEETPAGE*)lParam;
320 This = (INetConnectionPropertyUiImpl*)page->lParam;
321 InitializeLANPropertiesUIDlg(hwndDlg, This);
322 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)This);
323 return TRUE;
324 case WM_NOTIFY:
325 lppl = (LPNMLISTVIEW) lParam;
326 lppsn = (LPPSHNOTIFY) lParam;
327 if (lppsn->hdr.code == PSN_APPLY)
328 {
329 This = (INetConnectionPropertyUiImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER);
330 if (This->pNCfg)
331 {
332 hr = INetCfg_Apply(This->pNCfg);
333 if (FAILED(hr))
334 return PSNRET_INVALID;
335 }
336
337 if (SendDlgItemMessageW(hwndDlg, IDC_SHOWTASKBAR, BM_GETCHECK, 0, 0) == BST_CHECKED)
338 dwShowIcon = 1;
339 else
340 dwShowIcon = 0;
341
342
343 if (StringFromCLSID(&This->pProperties->guidId, &pStr) == ERROR_SUCCESS)
344 {
345 swprintf(szKey, L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", pStr);
346 CoTaskMemFree(pStr);
347 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szKey, 0, KEY_WRITE, &hKey) == ERROR_SUCCESS)
348 {
349 RegSetValueExW(hKey, L"ShowIcon", 0, REG_DWORD, (LPBYTE)&dwShowIcon, sizeof(DWORD));
350 RegCloseKey(hKey);
351 }
352 }
353
354 return PSNRET_NOERROR;
355 }
356 #if 0
357 else if (lppsn->hdr.code == PSN_CANCEL)
358 {
359 This = (INetConnectionPropertyUiImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER);
360 if (This->pNCfg)
361 {
362 hr = INetCfg_Cancel(This->pNCfg);
363 if (SUCCEEDED(hr))
364 return PSNRET_NOERROR;
365 else
366 return PSNRET_INVALID;
367 }
368 return PSNRET_NOERROR;
369 }
370 #endif
371 if (lppl->hdr.code == LVN_ITEMCHANGING)
372 {
373 ZeroMemory(&li, sizeof(li));
374 li.mask = LVIF_PARAM;
375 li.iItem = lppl->iItem;
376 if (!SendMessageW(lppl->hdr.hwndFrom, LVM_GETITEMW, 0, (LPARAM)&li))
377 return TRUE;
378
379 pItem = (PNET_ITEM)li.lParam;
380 if (!pItem)
381 return TRUE;
382
383 if (!(lppl->uOldState & LVIS_FOCUSED) && (lppl->uNewState & LVIS_FOCUSED))
384 {
385 /* new focused item */
386 if (pItem->dwCharacteristics & NCF_NOT_USER_REMOVABLE)
387 EnableWindow(GetDlgItem(hwndDlg, IDC_UNINSTALL), FALSE);
388 else
389 EnableWindow(GetDlgItem(hwndDlg, IDC_UNINSTALL), TRUE);
390
391 if (pItem->dwCharacteristics & NCF_HAS_UI)
392 EnableWindow(GetDlgItem(hwndDlg, IDC_PROPERTIES), TRUE);
393 else
394 EnableWindow(GetDlgItem(hwndDlg, IDC_PROPERTIES), FALSE);
395
396 SendDlgItemMessageW(hwndDlg, IDC_DESCRIPTION, WM_SETTEXT, 0, (LPARAM)pItem->szHelp);
397 }
398 }
399 break;
400 case WM_COMMAND:
401 if (LOWORD(wParam) == IDC_PROPERTIES)
402 {
403 This = (INetConnectionPropertyUiImpl*) GetWindowLongPtr(hwndDlg, DWLP_USER);
404 ShowNetworkComponentProperties(hwndDlg, This);
405 return FALSE;
406 }
407 break;
408 }
409 return FALSE;
410 }
411
412 static
413 HRESULT
414 WINAPI
415 INetConnectionPropertyUi2_fnQueryInterface(
416 INetConnectionPropertyUi2 * iface,
417 REFIID iid,
418 LPVOID * ppvObj)
419 {
420 LPOLESTR pStr;
421 INetConnectionPropertyUiImpl * This = (INetConnectionPropertyUiImpl*)iface;
422 *ppvObj = NULL;
423
424 if (IsEqualIID (iid, &IID_IUnknown) ||
425 IsEqualIID (iid, &IID_INetConnectionPropertyUi) ||
426 IsEqualIID (iid, &IID_INetConnectionPropertyUi2))
427 {
428 *ppvObj = This;
429 IUnknown_AddRef(iface);
430 return S_OK;
431 }
432 else if (IsEqualIID(iid, &IID_INetLanConnectionUiInfo))
433 {
434 *ppvObj = &This->lpLanConUiInfoVtbl;
435 IUnknown_AddRef(iface);
436 return S_OK;
437 }
438 else if (IsEqualIID(iid, &IID_INetConnectionConnectUi))
439 {
440 *ppvObj = &This->lpNetConnectionConnectUi;
441 IUnknown_AddRef(iface);
442 return S_OK;
443 }
444
445 StringFromCLSID(iid, &pStr);
446 MessageBoxW(NULL, pStr, L"INetConnectionPropertyUi_fnQueryInterface", MB_OK);
447 CoTaskMemFree(pStr);
448 return E_NOINTERFACE;
449 }
450
451 static
452 ULONG
453 WINAPI
454 INetConnectionPropertyUi2_fnAddRef(
455 INetConnectionPropertyUi2 * iface)
456 {
457 INetConnectionPropertyUiImpl * This = (INetConnectionPropertyUiImpl*)iface;
458 ULONG refCount = InterlockedIncrement(&This->ref);
459
460 return refCount;
461 }
462
463 static
464 ULONG
465 WINAPI
466 INetConnectionPropertyUi2_fnRelease(
467 INetConnectionPropertyUi2 * iface)
468 {
469 INetConnectionPropertyUiImpl * This = (INetConnectionPropertyUiImpl*)iface;
470 ULONG refCount = InterlockedDecrement(&This->ref);
471
472 if (!refCount)
473 {
474 if (This->pNCfg)
475 {
476 INetCfg_Uninitialize(This->pNCfg);
477 INetCfg_Release(This->pNCfg);
478 }
479 if (This->NCfgLock)
480 {
481 INetCfgLock_Release(This->NCfgLock);
482 }
483 if (This->pProperties)
484 {
485 NcFreeNetconProperties(This->pProperties);
486 }
487 CoTaskMemFree (This);
488 }
489 return refCount;
490 }
491
492 static
493 HRESULT
494 WINAPI
495 INetConnectionPropertyUi2_fnSetConnection(
496 INetConnectionPropertyUi2 * iface,
497 INetConnection *pCon)
498 {
499 INetConnectionPropertyUiImpl * This = (INetConnectionPropertyUiImpl*)iface;
500
501 if (!pCon)
502 return E_POINTER;
503
504 if (This->pCon)
505 INetConnection_Release(This->pCon);
506
507 This->pCon = pCon;
508 INetConnection_AddRef(This->pCon);
509 return S_OK;
510 }
511
512 static
513 HRESULT
514 WINAPI
515 INetConnectionPropertyUi2_fnAddPages(
516 INetConnectionPropertyUi2 * iface,
517 HWND hwndParent,
518 LPFNADDPROPSHEETPAGE pfnAddPage,
519 LPARAM lParam)
520 {
521 HPROPSHEETPAGE hProp;
522 BOOL ret;
523 HRESULT hr = E_FAIL;
524 INITCOMMONCONTROLSEX initEx;
525 INetConnectionPropertyUiImpl * This = (INetConnectionPropertyUiImpl*)iface;
526
527
528 initEx.dwSize = sizeof(initEx);
529 initEx.dwICC = ICC_LISTVIEW_CLASSES;
530 if(!InitCommonControlsEx(&initEx))
531 return E_FAIL;
532
533 hr = INetConnection_GetProperties(This->pCon, &This->pProperties);
534 if (FAILED(hr))
535 return hr;
536
537 hProp = InitializePropertySheetPage(MAKEINTRESOURCEW(IDD_NETPROPERTIES), LANPropertiesUIDlg, (LPARAM)This, This->pProperties->pszwName);
538 if (hProp)
539 {
540 ret = (*pfnAddPage)(hProp, lParam);
541 if (ret)
542 {
543 hr = NOERROR;
544 }
545 else
546 {
547 DestroyPropertySheetPage(hProp);
548 }
549 }
550 return hr;
551 }
552
553 static
554 HRESULT
555 WINAPI
556 INetConnectionPropertyUi2_fnGetIcon(
557 INetConnectionPropertyUi2 * iface,
558 DWORD dwSize,
559 HICON *phIcon)
560 {
561 return E_NOTIMPL;
562 }
563
564 static const INetConnectionPropertyUi2Vtbl vt_NetConnectionPropertyUi =
565 {
566 INetConnectionPropertyUi2_fnQueryInterface,
567 INetConnectionPropertyUi2_fnAddRef,
568 INetConnectionPropertyUi2_fnRelease,
569 INetConnectionPropertyUi2_fnSetConnection,
570 INetConnectionPropertyUi2_fnAddPages,
571 INetConnectionPropertyUi2_fnGetIcon,
572 };
573
574 static
575 HRESULT
576 WINAPI
577 INetLanConnectionUiInfo_fnQueryInterface(
578 INetLanConnectionUiInfo * iface,
579 REFIID iid,
580 LPVOID * ppvObj)
581 {
582 INetConnectionPropertyUiImpl * This = impl_from_NetLanConnectionUiInfo(iface);
583 return INetConnectionPropertyUi_QueryInterface((INetConnectionPropertyUi*)This, iid, ppvObj);
584 }
585
586 static
587 ULONG
588 WINAPI
589 INetLanConnectionUiInfo_fnAddRef(
590 INetLanConnectionUiInfo * iface)
591 {
592 INetConnectionPropertyUiImpl * This = impl_from_NetLanConnectionUiInfo(iface);
593 return INetConnectionPropertyUi_AddRef((INetConnectionPropertyUi*)This);
594 }
595
596 static
597 ULONG
598 WINAPI
599 INetLanConnectionUiInfo_fnRelease(
600 INetLanConnectionUiInfo * iface)
601 {
602 INetConnectionPropertyUiImpl * This = impl_from_NetLanConnectionUiInfo(iface);
603 return INetConnectionPropertyUi_Release((INetConnectionPropertyUi*)This);
604 }
605
606 static
607 HRESULT
608 WINAPI
609 INetLanConnectionUiInfo_fnGetDeviceGuid(
610 INetLanConnectionUiInfo * iface,
611 GUID * pGuid)
612 {
613 INetConnectionPropertyUiImpl * This = impl_from_NetLanConnectionUiInfo(iface);
614 CopyMemory(pGuid, &This->pProperties->guidId, sizeof(GUID));
615 return S_OK;
616 }
617
618 static const INetLanConnectionUiInfoVtbl vt_NetLanConnectionUiInfo =
619 {
620 INetLanConnectionUiInfo_fnQueryInterface,
621 INetLanConnectionUiInfo_fnAddRef,
622 INetLanConnectionUiInfo_fnRelease,
623 INetLanConnectionUiInfo_fnGetDeviceGuid,
624 };
625
626 static
627 HRESULT
628 WINAPI
629 INetConnectionConnectUi_fnQueryInterface(
630 INetConnectionConnectUi * iface,
631 REFIID iid,
632 LPVOID * ppvObj)
633 {
634 INetConnectionPropertyUiImpl * This = impl_from_NetConnectionConnectUi(iface);
635 return INetConnectionPropertyUi_QueryInterface((INetConnectionPropertyUi*)This, iid, ppvObj);
636 }
637
638 static
639 ULONG
640 WINAPI
641 INetConnectionConnectUi_fnAddRef(
642 INetConnectionConnectUi * iface)
643 {
644 INetConnectionPropertyUiImpl * This = impl_from_NetConnectionConnectUi(iface);
645 return INetConnectionPropertyUi_AddRef((INetConnectionPropertyUi*)This);
646 }
647
648 static
649 ULONG
650 WINAPI
651 INetConnectionConnectUi_fnRelease(
652 INetConnectionConnectUi * iface)
653 {
654 INetConnectionPropertyUiImpl * This = impl_from_NetConnectionConnectUi(iface);
655 return INetConnectionPropertyUi_Release((INetConnectionPropertyUi*)This);
656 }
657
658 static
659 HRESULT
660 WINAPI
661 INetConnectionConnectUi_fnSetConnection(
662 INetConnectionConnectUi * iface,
663 INetConnection* pCon)
664 {
665 INetConnectionPropertyUiImpl * This = impl_from_NetConnectionConnectUi(iface);
666 if (This->pCon)
667 INetConnection_Release(This->pCon);
668
669 if (!pCon)
670 return E_POINTER;
671
672 This->pCon = pCon;
673 INetConnection_AddRef(pCon);
674 return S_OK;
675 }
676
677 static
678 HRESULT
679 WINAPI
680 INetConnectionConnectUi_fnConnect(
681 INetConnectionConnectUi * iface,
682 HWND hwndParent,
683 DWORD dwFlags)
684 {
685 INetConnectionPropertyUiImpl * This = impl_from_NetConnectionConnectUi(iface);
686
687 if (!This->pCon)
688 return E_POINTER; //FIXME
689
690
691 if (dwFlags & NCUC_NO_UI)
692 {
693 return INetConnection_Connect(This->pCon);
694 }
695
696 return E_FAIL;
697 }
698
699 static
700 HRESULT
701 WINAPI
702 INetConnectionConnectUi_fnDisconnect(
703 INetConnectionConnectUi * iface,
704 HWND hwndParent,
705 DWORD dwFlags)
706 {
707 WCHAR szBuffer[100];
708 swprintf(szBuffer, L"INetConnectionConnectUi_fnDisconnect flags %x\n", dwFlags);
709 MessageBoxW(NULL, szBuffer, NULL, MB_OK);
710
711 return S_OK;
712 }
713
714
715 static const INetConnectionConnectUiVtbl vt_NetConnectionConnectUi =
716 {
717 INetConnectionConnectUi_fnQueryInterface,
718 INetConnectionConnectUi_fnAddRef,
719 INetConnectionConnectUi_fnRelease,
720 INetConnectionConnectUi_fnSetConnection,
721 INetConnectionConnectUi_fnConnect,
722 INetConnectionConnectUi_fnDisconnect,
723
724 };
725
726
727
728 HRESULT WINAPI LanConnectUI_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
729 {
730 INetConnectionPropertyUiImpl * This;
731
732 if (!ppv)
733 return E_POINTER;
734
735 if (pUnkOuter)
736 return CLASS_E_NOAGGREGATION;
737
738 This = (INetConnectionPropertyUiImpl *) CoTaskMemAlloc(sizeof (INetConnectionPropertyUiImpl));
739 if (!This)
740 return E_OUTOFMEMORY;
741
742 This->ref = 1;
743 This->pCon = NULL;
744 This->pNCfg = NULL;
745 This->NCfgLock = NULL;
746 This->pProperties = NULL;
747 This->lpVtbl = (INetConnectionPropertyUi2*)&vt_NetConnectionPropertyUi;
748 This->lpLanConUiInfoVtbl = (INetLanConnectionUiInfo*)&vt_NetLanConnectionUiInfo;
749 This->lpNetConnectionConnectUi = (INetConnectionConnectUi*)&vt_NetConnectionConnectUi;
750
751 if (!SUCCEEDED (INetConnectionPropertyUi2_fnQueryInterface ((INetConnectionPropertyUi2*)This, riid, ppv)))
752 {
753 IUnknown_Release((IUnknown*)This);
754 return E_NOINTERFACE;
755 }
756
757 IUnknown_Release((IUnknown*)This);
758 return S_OK;
759 }