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.

479 lines
10 KiB

  1. /************************************************************************
  2. Copyright (c) Microsoft Corporation 1997-1999
  3. All rights reserved
  4. ***************************************************************************/
  5. //
  6. // GROUPS.CPP - Handles the "IntelliMirror Group" IDD_PROP_GROUPS tab
  7. //
  8. #include "pch.h"
  9. #ifdef INTELLIMIRROR_GROUPS
  10. #include "cservice.h"
  11. #include "cgroup.h"
  12. #include "groups.h"
  13. DEFINE_MODULE("IMADMUI")
  14. DEFINE_THISCLASS("CGroupsTab")
  15. #define THISCLASS CGroupsTab
  16. #define LPTHISCLASS LPCGroupsTab
  17. #define NUM_COLUMNS 4
  18. #define MAX_ITEMLEN 20
  19. #define BITMAP_WIDTH 16
  20. #define BITMAP_HEIGHT 16
  21. #define LG_BITMAP_WIDTH 32
  22. #define LG_BITMAP_HEIGHT 32
  23. DWORD aGroupHelpMap[] = { NULL, NULL };
  24. //
  25. // CreateInstance()
  26. //
  27. LPVOID
  28. CGroupsTab_CreateInstance( void )
  29. {
  30. TraceFunc( "CGroupsTab_CreateInstance()\n" );
  31. LPTHISCLASS lpcc = new THISCLASS( );
  32. HRESULT hr = THR( lpcc->Init( ) );
  33. if ( hr )
  34. {
  35. delete lpcc;
  36. RETURN(NULL);
  37. }
  38. RETURN((LPVOID) lpcc);
  39. }
  40. //
  41. // Constructor
  42. //
  43. THISCLASS::THISCLASS( )
  44. {
  45. TraceClsFunc( "CGroupsTab()\n" );
  46. InterlockIncrement( g_cObjects );
  47. TraceFuncExit();
  48. }
  49. //
  50. // Init()
  51. //
  52. STDMETHODIMP
  53. THISCLASS::Init( )
  54. {
  55. HRESULT hr = S_OK;
  56. TraceClsFunc( "Init()\n" );
  57. HRETURN(hr);
  58. }
  59. //
  60. // Destructor
  61. //
  62. THISCLASS::~THISCLASS( )
  63. {
  64. TraceClsFunc( "~CGroupsTab()\n" );
  65. if ( _punk )
  66. _punk->Release( );
  67. InterlockDecrement( g_cObjects );
  68. TraceFuncExit();
  69. };
  70. // *************************************************************************
  71. //
  72. // ITab
  73. //
  74. // *************************************************************************
  75. STDMETHODIMP
  76. THISCLASS::AddPages(
  77. LPFNADDPROPSHEETPAGE lpfnAddPage,
  78. LPARAM lParam,
  79. LPUNKNOWN punk )
  80. {
  81. TraceClsFunc( "AddPages( )\n" );
  82. HRESULT hr = S_OK;
  83. PROPSHEETPAGE psp;
  84. HPROPSHEETPAGE hpage;
  85. psp.dwSize = sizeof(psp);
  86. psp.dwFlags = PSP_USEREFPARENT | PSP_USECALLBACK;
  87. psp.hInstance = (HINSTANCE) g_hInstance;
  88. psp.pszTemplate = MAKEINTRESOURCE(IDD_PROP_GROUPS);
  89. psp.pcRefParent = (UINT *) &g_cObjects;
  90. psp.pfnCallback = (LPFNPSPCALLBACK) PropSheetPageProc;
  91. psp.pfnDlgProc = PropSheetDlgProc;
  92. psp.lParam = (LPARAM) this;
  93. hpage = CreatePropertySheetPage( &psp );
  94. if ( hpage )
  95. {
  96. if ( !lpfnAddPage( hpage, lParam ) )
  97. {
  98. DestroyPropertySheetPage( hpage );
  99. hr = E_FAIL;
  100. goto Error;
  101. }
  102. }
  103. punk->AddRef( ); // matching Release in the destructor
  104. _punk = punk;
  105. Error:
  106. HRETURN(hr);
  107. }
  108. //
  109. // ReplacePage()
  110. //
  111. STDMETHODIMP
  112. THISCLASS::ReplacePage(
  113. UINT uPageID,
  114. LPFNADDPROPSHEETPAGE lpfnReplaceWith,
  115. LPARAM lParam,
  116. LPUNKNOWN punk )
  117. {
  118. TraceClsFunc( "ReplacePage( ) *** NOT_IMPLEMENTED ***\n" );
  119. HRETURN(E_NOTIMPL);
  120. }
  121. //
  122. // QueryInformation( )
  123. //
  124. STDMETHODIMP
  125. THISCLASS::QueryInformation(
  126. LPWSTR pszAttribute,
  127. LPWSTR * pszResult )
  128. {
  129. TraceClsFunc( "QueryInformation( )\n" );
  130. HRETURN(E_NOTIMPL);
  131. }
  132. //
  133. // AllowActivation( )
  134. //
  135. STDMETHODIMP
  136. THISCLASS::AllowActivation(
  137. BOOL * pfAllow )
  138. {
  139. TraceClsFunc( "AllowActivation( )\n" );
  140. HRETURN(E_NOTIMPL);
  141. }
  142. // ************************************************************************
  143. //
  144. // Property Sheet Functions
  145. //
  146. // ************************************************************************
  147. //
  148. // _InitDialog( )
  149. //
  150. HRESULT
  151. THISCLASS::_InitDialog(
  152. HWND hDlg,
  153. LPARAM lParam )
  154. {
  155. TraceClsFunc( "_InitDialog( )\n" );
  156. HRESULT hr = S_OK;
  157. LPSERVICE ps = NULL;
  158. ULONG cFetched;
  159. HWND hwnd = GetDlgItem( _hDlg, IDC_L_GROUPS );
  160. HICON hIcon; // handle to an icon
  161. int index; // index used in for loops
  162. int iSubItem; // index into column header string table
  163. LV_COLUMN lvC; // list view column structure
  164. LV_ITEM lvI; // list view item structure
  165. WCHAR szText [MAX_PATH]; // place to store some text
  166. IEnumSAPs * penum = NULL;
  167. HIMAGELIST hSmall, hLarge; // handles to image lists for small and large icons
  168. _hDlg = hDlg;
  169. SetWindowLong( _hDlg, GWL_USERDATA, (LPARAM) this );
  170. _fChanged = TRUE; // prevent Apply button from coming on
  171. // Initialize the list view icons
  172. hSmall = ImageList_Create ( BITMAP_WIDTH, BITMAP_HEIGHT, FALSE, 3, 0 );
  173. hLarge = ImageList_Create ( LG_BITMAP_WIDTH, LG_BITMAP_HEIGHT, FALSE, 3, 0 );
  174. hIcon = LoadIcon ( g_hInstance, MAKEINTRESOURCE( IDI_COMPUTER ) );
  175. if (( ImageList_AddIcon( hSmall, hIcon ) == -1) ||
  176. ( ImageList_AddIcon( hLarge, hIcon ) == -1))
  177. {
  178. hr = THR( E_FAIL );
  179. goto Error;
  180. }
  181. // Associate the image lists with the list view control.
  182. ListView_SetImageList( hwnd, hSmall, LVSIL_SMALL );
  183. ListView_SetImageList( hwnd, hLarge, LVSIL_NORMAL );
  184. // Initialize the columns
  185. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  186. lvC.fmt = LVCFMT_LEFT; // left-align column
  187. lvC.cx = 75; // width of column in pixels
  188. lvC.pszText = szText;
  189. // Add the columns.
  190. for ( index = 0; index < NUM_COLUMNS; index++ )
  191. {
  192. DWORD dw;
  193. dw = LoadString( g_hInstance, IDS_COLUMN1 + index, szText, ARRAYSIZE ( szText ) );
  194. Assert(dw);
  195. lvC.iSubItem = index;
  196. if ( ListView_InsertColumn( hwnd, index, &lvC ) == -1 )
  197. {
  198. hr = THR( E_FAIL );
  199. goto Error;
  200. }
  201. }
  202. // Finally, add the actual items to the control.
  203. lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  204. lvI.state = 0;
  205. lvI.stateMask = 0;
  206. hr = THR( _punk->QueryInterface( IID_IEnumSAPs, (void**) &penum ) );
  207. if (hr)
  208. goto Error;
  209. index = 0;
  210. while( ( hr = penum->Next( 1, &ps, &cFetched ) ) == S_OK )
  211. {
  212. LPWSTR pszServerName;
  213. hr = THR( ps->GetServerDN( &pszServerName ) );
  214. if (hr)
  215. goto Error;
  216. ps->Release( );
  217. ps = NULL;
  218. // The parent window is responsible for storing the text.
  219. // The list view control will send an LVN_GETDISPINFO
  220. // when it needs the text to display.
  221. lvI.pszText = pszServerName;
  222. lvI.iItem = index;
  223. lvI.iSubItem = 0;
  224. lvI.cchTextMax = MAX_ITEMLEN;
  225. lvI.iImage = 0;
  226. lvI.lParam = NULL; // DEADISSUE: Ifdef'd out. BUGBUG: should point to a SAPNODE,
  227. if ( ListView_InsertItem( hwnd, &lvI) == -1 )
  228. {
  229. hr = THR( E_FAIL );
  230. goto Error;
  231. }
  232. for ( iSubItem = 1; iSubItem < NUM_COLUMNS; iSubItem++ )
  233. {
  234. ListView_SetItemText( hwnd, index, iSubItem, pszServerName );
  235. }
  236. }
  237. // hr should equal S_FALSE
  238. if ( hr != S_FALSE )
  239. {
  240. THR(hr);
  241. goto Error;
  242. }
  243. hr = S_OK;
  244. Cleanup:
  245. if ( ps )
  246. ps->Release( );
  247. if ( penum )
  248. penum->Release( );
  249. _fChanged = FALSE;
  250. HRETURN(hr);
  251. Error:
  252. switch (hr) {
  253. case S_OK:
  254. break;
  255. default:
  256. MessageBoxFromHResult( NULL, IDS_ERROR_OPENNINGGROUPOBJECT, hr );
  257. break;
  258. }
  259. goto Cleanup;
  260. }
  261. //
  262. // _OnCommand( )
  263. //
  264. BOOL
  265. THISCLASS::_OnCommand( WPARAM wParam, LPARAM lParam )
  266. {
  267. TraceClsFunc( "_OnCommand( " );
  268. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  269. HRESULT hr;
  270. BOOL fChanged = FALSE;
  271. BOOL fResult = FALSE;
  272. HWND hwndCtl = (HWND) lParam;
  273. switch( LOWORD(wParam) )
  274. {
  275. case 0:
  276. //dummy;
  277. default:
  278. hr = S_FALSE;
  279. break;
  280. }
  281. if ( fChanged )
  282. {
  283. if ( !_fChanged )
  284. {
  285. _fChanged = TRUE;
  286. SendMessage( GetParent( _hDlg ), PSM_CHANGED, 0, 0 );
  287. }
  288. }
  289. RETURN(fResult);
  290. }
  291. //
  292. // _OnNotify( )
  293. //
  294. INT
  295. THISCLASS::_OnNotify(
  296. WPARAM wParam,
  297. LPARAM lParam )
  298. {
  299. TraceClsFunc( "_OnNotify( " );
  300. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  301. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  302. switch( lpnmhdr->code )
  303. {
  304. case PSN_APPLY:
  305. TraceMsg( TF_WM, TEXT("WM_NOTIFY: PSN_APPLY\n"));
  306. AssertMsg( 0, "Need to implement this." );
  307. SetWindowLong( _hDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE );
  308. _fChanged = FALSE;
  309. RETURN(TRUE);
  310. case LVN_GETDISPINFO:
  311. break;
  312. default:
  313. break;
  314. }
  315. RETURN(FALSE);
  316. }
  317. //
  318. // PropSheetDlgProc()
  319. //
  320. INT_PTR CALLBACK
  321. THISCLASS::PropSheetDlgProc(
  322. HWND hDlg,
  323. UINT uMsg,
  324. WPARAM wParam,
  325. LPARAM lParam )
  326. {
  327. //TraceMsg( TEXT("PropSheetDlgProc(") );
  328. //TraceMsg( TF_FUNC, TEXT(" hDlg = 0x%08x, uMsg = 0x%08x, wParam = 0x%08x, lParam = 0x%08x )\n"),
  329. // hDlg, uMsg, wParam, lParam );
  330. LPTHISCLASS pcc = (LPTHISCLASS) GetWindowLong( hDlg, GWL_USERDATA );
  331. if ( uMsg == WM_INITDIALOG )
  332. {
  333. TraceMsg( TF_WM, TEXT("WM_INITDIALOG\n"));
  334. LPPROPSHEETPAGE psp = (LPPROPSHEETPAGE) lParam;
  335. pcc = (LPTHISCLASS) psp->lParam;
  336. pcc->_InitDialog( hDlg, lParam );
  337. }
  338. if (pcc)
  339. {
  340. Assert( hDlg == pcc->_hDlg );
  341. switch ( uMsg )
  342. {
  343. case WM_NOTIFY:
  344. return pcc->_OnNotify( wParam, lParam );
  345. case WM_COMMAND:
  346. TraceMsg( TF_WM, TEXT("WM_COMMAND\n") );
  347. return pcc->_OnCommand( wParam, lParam );
  348. case WM_HELP:// F1
  349. {
  350. LPHELPINFO phelp = (LPHELPINFO) lParam;
  351. WinHelp( (HWND) phelp->hItemHandle, g_cszHelpFile, HELP_WM_HELP, (DWORD_PTR) &aGroupHelpMap );
  352. }
  353. break;
  354. case WM_CONTEXTMENU: // right mouse click
  355. WinHelp((HWND) wParam, g_cszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR) &aGroupHelpMap );
  356. break;
  357. }
  358. }
  359. return FALSE;
  360. }
  361. //
  362. // PropSheetPageProc()
  363. //
  364. UINT CALLBACK
  365. THISCLASS::PropSheetPageProc(
  366. HWND hwnd,
  367. UINT uMsg,
  368. LPPROPSHEETPAGE ppsp )
  369. {
  370. TraceClsFunc( "PropSheetPageProc( " );
  371. TraceMsg( TF_FUNC, TEXT("hwnd = 0x%08x, uMsg = 0x%08x, ppsp= 0x%08x )\n"),
  372. hwnd, uMsg, ppsp );
  373. switch ( uMsg )
  374. {
  375. case PSPCB_CREATE:
  376. RETURN(TRUE); // create it
  377. break;
  378. case PSPCB_RELEASE:
  379. LPTHISCLASS pcc = (LPTHISCLASS) ppsp->lParam;
  380. delete pcc;
  381. break;
  382. }
  383. RETURN(FALSE);
  384. }
  385. #endif