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.

582 lines
16 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and29 product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // cpgen.c - conference properties general dialog box
  24. ////
  25. #include "winlocal.h"
  26. #include "res.h"
  27. #include "wnd.h"
  28. #include "DlgBase.h"
  29. #include "confprop.h"
  30. #include "cpgen.h"
  31. #include "confinfo.h"
  32. #include "ThreadPub.h"
  33. ////
  34. // private
  35. ////
  36. extern HINSTANCE g_hInstLib;
  37. #define NAME_MAXLEN 64
  38. #define DESCRIPTION_MAXLEN 256
  39. #define OWNER_MAXLEN 64
  40. static LRESULT ConfPropGeneral_DlgProcEx(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  41. static BOOL ConfPropGeneral_OnInitDialog(HWND hwndDlg, HWND hwndFocus, LPARAM lParam);
  42. static BOOL ConfPropGeneral_OnCommand(HWND hwndDlg, UINT id, HWND hwndCtl, UINT code);
  43. static int ConfPropGeneral_OnNotify(HWND hwndDlg, UINT idFrom, LPNMHDR lpnmhdr);
  44. #define ConfPropGeneral_DefProc(hwnd, msg, wParam, lParam) \
  45. DefDlgProcEx(hwnd, msg, wParam, lParam, &g_bDefDlgEx)
  46. static BOOL ConfPropGeneral_UpdateData(HWND hwndDlg, BOOL bSaveAndValidate);
  47. static void ConfPropGeneral_SetDateTimeFormats( HWND hwndDlg );
  48. DWORD WINAPI ThreadMDHCPScopeEnum( LPVOID pParam );
  49. void ShowScopeInfo( HWND hwndDlg, int nShow, bool bInit );
  50. static BOOL g_bDefDlgEx = FALSE;
  51. ////
  52. // public
  53. ////
  54. int DLLEXPORT WINAPI ConfPropGeneral_DoModal(HWND hwndOwner, DWORD dwUser)
  55. {
  56. return DialogBoxParam(g_hInstLib, MAKEINTRESOURCE(IDD_CONFPROP_GENERAL),
  57. hwndOwner, ConfPropGeneral_DlgProc, (LPARAM) dwUser);
  58. }
  59. INT_PTR DLLEXPORT CALLBACK ConfPropGeneral_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  60. {
  61. CheckDefDlgRecursion(&g_bDefDlgEx);
  62. return SetDlgMsgResult(hwndDlg, uMsg, ConfPropGeneral_DlgProcEx(hwndDlg, uMsg, wParam, lParam));
  63. }
  64. ////
  65. // private
  66. ////
  67. void EnableOkBtn( HWND hWnd, bool bEnable )
  68. {
  69. while ( hWnd )
  70. {
  71. HWND hWndOk = GetDlgItem( hWnd, IDOK );
  72. if ( hWndOk )
  73. {
  74. EnableWindow( hWndOk, bEnable );
  75. break;
  76. }
  77. hWnd = GetParent( hWnd );
  78. }
  79. }
  80. static LRESULT ConfPropGeneral_DlgProcEx(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  81. {
  82. LRESULT lRet = 0;
  83. switch (uMsg)
  84. {
  85. HANDLE_MSG(hwndDlg, WM_INITDIALOG, ConfPropGeneral_OnInitDialog);
  86. case WM_COMMAND:
  87. if ( (lRet = HANDLE_WM_COMMAND(hwndDlg, wParam, lParam, ConfPropGeneral_OnCommand)) != 0 )
  88. return lRet;
  89. break;
  90. case WM_NOTIFY:
  91. if ( (lRet = HANDLE_WM_NOTIFY(hwndDlg, wParam, lParam, ConfPropGeneral_OnNotify)) != 0 )
  92. return lRet;
  93. break;
  94. case WM_HELP: return GeneralOnHelp( hwndDlg, wParam, lParam );
  95. case WM_CONTEXTMENU: return GeneralOnContextMenu( hwndDlg, wParam, lParam );
  96. case WM_SETTINGCHANGE:
  97. ConfPropGeneral_SetDateTimeFormats( hwndDlg );
  98. // do default processing as well
  99. break;
  100. }
  101. return ConfPropGeneral_DefProc(hwndDlg, uMsg, wParam, lParam);
  102. }
  103. static BOOL ConfPropGeneral_OnInitDialog(HWND hwndDlg, HWND hwndFocus, LPARAM lParam)
  104. {
  105. //_ASSERT( lParam && ((LPPROPSHEETPAGE) lParam)->lParam );
  106. //
  107. // We have to verify the arguments
  108. //
  109. if( NULL == ((LPPROPSHEETPAGE)lParam) )
  110. {
  111. return TRUE;
  112. }
  113. LPCONFPROP lpConfProp = (LPCONFPROP) ((LPPROPSHEETPAGE) lParam)->lParam;
  114. //
  115. // Validates lpConfProp
  116. //
  117. if( IsBadReadPtr( lpConfProp, sizeof( CONFPROP) ) )
  118. {
  119. return TRUE;
  120. }
  121. SetWindowLongPtr( hwndDlg, GWLP_USERDATA, (LONG_PTR) lpConfProp );
  122. // Reset content of listbox if necessary
  123. ConfPropGeneral_UpdateData( hwndDlg, FALSE );
  124. if ( lpConfProp->ConfInfo.IsNewConference() )
  125. ShowScopeInfo( hwndDlg, SW_SHOW, true );
  126. //WndCenterWindow( GetParent(hwndDlg), NULL, 0, 0 );
  127. return TRUE; // let Windows decide who gets focus
  128. }
  129. static BOOL ConfPropGeneral_OnCommand(HWND hwndDlg, UINT id, HWND hwndCtl, UINT code)
  130. {
  131. BOOL bRet = false;
  132. HWND hwndName = GetDlgItem(hwndDlg, IDC_EDIT_NAME);
  133. switch (id)
  134. {
  135. case IDC_EDIT_NAME:
  136. if (code == EN_CHANGE)
  137. EnableOkBtn( hwndDlg, (bool) (Edit_GetTextLength(hwndName) != 0) );
  138. break;
  139. default:
  140. break;
  141. }
  142. return bRet;
  143. }
  144. static int ConfPropGeneral_OnNotify(HWND hwndDlg, UINT idFrom, LPNMHDR lpnmhdr)
  145. {
  146. switch (lpnmhdr->code)
  147. {
  148. // page about to be activated and made visible, so initialize page
  149. //
  150. case PSN_SETACTIVE:
  151. return 0; // ok
  152. // return -1; // activate previous or next page
  153. // return MAKEINTRESOURCE(id); // activate specific page
  154. break;
  155. // page about to lose activation, so validate page
  156. //
  157. case PSN_KILLACTIVE:
  158. return FALSE; // ok
  159. // return TRUE; // not ok
  160. break;
  161. // ok or apply button pushed, so apply properties to object
  162. //
  163. case PSN_APPLY:
  164. return ConfPropGeneral_UpdateData( hwndDlg, TRUE );
  165. break;
  166. // cancel button pushed
  167. //
  168. case PSN_QUERYCANCEL:
  169. return FALSE; // ok
  170. // return TRUE; // not ok
  171. break;
  172. // page about to be destroyed after cancel button pushed
  173. //
  174. case PSN_RESET:
  175. return FALSE; // return value ignored
  176. break;
  177. // help button pushed
  178. //
  179. case PSN_HELP:
  180. // WinHelp(...); // $FIXUP - need to handle this
  181. return FALSE; // return value ignored
  182. break;
  183. case DTN_DATETIMECHANGE:
  184. // If this is not a new conference, post a message explaining that
  185. // the scope information will need to be re-selected
  186. if ( IsWindow(hwndDlg) )
  187. {
  188. LPCONFPROP lpConfProp = (LPCONFPROP) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  189. //
  190. // We have to verify the lpConfProp
  191. //
  192. if( NULL == lpConfProp )
  193. {
  194. break;
  195. }
  196. if ( !lpConfProp->ConfInfo.m_bDateTimeChange )
  197. {
  198. lpConfProp->ConfInfo.m_bDateTimeChange = true;
  199. if ( !lpConfProp->ConfInfo.m_bNewConference )
  200. {
  201. // We send the notification again even if the source is the combo
  202. // and show MessageBox at that time
  203. //MessageBox(hwndDlg, String(g_hInstLib, IDS_CONFPROP_DATECHANGE_MDHCP), NULL, MB_OK | MB_ICONINFORMATION );
  204. ShowScopeInfo( hwndDlg, SW_SHOW, true );
  205. PostMessage(hwndDlg, WM_NOTIFY, idFrom, (LPARAM)lpnmhdr);
  206. }
  207. }
  208. else
  209. {
  210. //Here is the second notification
  211. //I show here the Error message
  212. if ( !lpConfProp->ConfInfo.m_bNewConference )
  213. {
  214. if(!lpConfProp->ConfInfo.m_bDateChangeMessage)
  215. {
  216. lpConfProp->ConfInfo.m_bDateChangeMessage = true;
  217. MessageBox(hwndDlg, String(g_hInstLib, IDS_CONFPROP_DATECHANGE_MDHCP), NULL, MB_OK | MB_ICONINFORMATION );
  218. }
  219. }
  220. }
  221. }
  222. break;
  223. default:
  224. break;
  225. }
  226. return FALSE;
  227. }
  228. static void ConfPropGeneral_SetDateTimeFormats( HWND hwndDlg )
  229. {
  230. HWND hwndDTPStartDate = GetDlgItem(hwndDlg, IDC_DTP_STARTDATE);
  231. HWND hwndDTPStartTime = GetDlgItem(hwndDlg, IDC_DTP_STARTTIME);
  232. HWND hwndDTPStopDate = GetDlgItem(hwndDlg, IDC_DTP_STOPDATE);
  233. HWND hwndDTPStopTime = GetDlgItem(hwndDlg, IDC_DTP_STOPTIME);
  234. // conference start time
  235. TCHAR szFormat[255];
  236. GetLocaleInfo( LOCALE_USER_DEFAULT,
  237. LOCALE_SSHORTDATE,
  238. szFormat,
  239. ARRAYSIZE(szFormat) );
  240. DateTime_SetFormat(hwndDTPStartDate, szFormat );
  241. DateTime_SetFormat( hwndDTPStopDate, szFormat );
  242. // conference stop time
  243. GetLocaleInfo( LOCALE_USER_DEFAULT,
  244. LOCALE_STIMEFORMAT,
  245. szFormat,
  246. ARRAYSIZE(szFormat) );
  247. DateTime_SetFormat( hwndDTPStopTime, szFormat );
  248. DateTime_SetFormat(hwndDTPStartTime, szFormat );
  249. }
  250. static int ConfPropGeneral_UpdateData(HWND hwndDlg, BOOL bSaveAndValidate)
  251. {
  252. HRESULT hr = S_OK;
  253. LPCONFPROP lpConfProp;
  254. HWND hwndName = GetDlgItem(hwndDlg, IDC_EDIT_NAME);
  255. HWND hwndDescription = GetDlgItem(hwndDlg, IDC_EDIT_DESCRIPTION);
  256. HWND hwndOwner = GetDlgItem(hwndDlg, IDC_EDIT_OWNER);
  257. HWND hwndDTPStartDate = GetDlgItem(hwndDlg, IDC_DTP_STARTDATE);
  258. HWND hwndDTPStartTime = GetDlgItem(hwndDlg, IDC_DTP_STARTTIME);
  259. HWND hwndDTPStopDate = GetDlgItem(hwndDlg, IDC_DTP_STOPDATE);
  260. HWND hwndDTPStopTime = GetDlgItem(hwndDlg, IDC_DTP_STOPTIME);
  261. BSTR bstrName = NULL;
  262. BSTR bstrDescription = NULL;
  263. BSTR bstrOwner = NULL;
  264. TCHAR szName[NAME_MAXLEN + 1];
  265. TCHAR szDescription[DESCRIPTION_MAXLEN + 1] = _T("");
  266. TCHAR szOwner[OWNER_MAXLEN + 1] = _T("");
  267. SYSTEMTIME st;
  268. USHORT nYear;
  269. BYTE nMonth, nDay, nHour, nMinute;
  270. USES_CONVERSION;
  271. _ASSERT( IsWindow(hwndDlg) );
  272. lpConfProp = (LPCONFPROP) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  273. //
  274. // We have to verify lpConfProp
  275. //
  276. if( NULL == lpConfProp )
  277. {
  278. return PSNRET_INVALID_NOCHANGEPAGE;
  279. }
  280. if (!bSaveAndValidate) // initialization
  281. {
  282. // conference name
  283. //
  284. Edit_LimitText(hwndName, NAME_MAXLEN);
  285. lpConfProp->ConfInfo.get_Name(&bstrName);
  286. if (bstrName == NULL)
  287. {
  288. // Make up a default name for the conference
  289. CComBSTR bstrTemp(L"");
  290. if( bstrTemp.m_str == NULL )
  291. {
  292. // E_OUTOFMEMORY
  293. _tcsncpy( szName, _T(""), NAME_MAXLEN );
  294. }
  295. else
  296. {
  297. lpConfProp->ConfInfo.GetPrimaryUser( &bstrTemp );
  298. bstrTemp.Append( String(g_hInstLib, IDS_CONFPROP_UNTITLED_DEFAULT_APPEND) );
  299. _tcsncpy( szName, OLE2CT(bstrTemp), NAME_MAXLEN );
  300. }
  301. }
  302. else
  303. {
  304. _tcsncpy( szName, OLE2CT(bstrName), NAME_MAXLEN );
  305. }
  306. Edit_SetText(hwndName, szName);
  307. // Don't allow name to be editted if this is an existing conference
  308. if ( !lpConfProp->ConfInfo.IsNewConference() )
  309. EnableWindow( hwndName, false );
  310. // conference description
  311. //
  312. Edit_LimitText(hwndDescription, DESCRIPTION_MAXLEN);
  313. lpConfProp->ConfInfo.get_Description(&bstrDescription);
  314. if (bstrDescription )
  315. _tcsncpy(szDescription, OLE2CT(bstrDescription), DESCRIPTION_MAXLEN);
  316. Edit_SetText(hwndDescription, szDescription);
  317. // conference owner
  318. //
  319. Edit_LimitText(hwndOwner, OWNER_MAXLEN);
  320. lpConfProp->ConfInfo.get_Originator(&bstrOwner);
  321. if (bstrOwner )
  322. _tcsncpy(szOwner, OLE2CT(bstrOwner), OWNER_MAXLEN);
  323. Edit_SetText(hwndOwner, szOwner);
  324. ConfPropGeneral_SetDateTimeFormats( hwndDlg );
  325. lpConfProp->ConfInfo.GetStartTime(&nYear, &nMonth, &nDay, &nHour, &nMinute);
  326. st.wYear = nYear;
  327. st.wMonth = nMonth;
  328. st.wDayOfWeek = 0;
  329. st.wDay = nDay;
  330. st.wHour = nHour;
  331. st.wMinute = nMinute;
  332. st.wSecond = 0;
  333. st.wMilliseconds = 0;
  334. DateTime_SetSystemtime( hwndDTPStartDate, GDT_VALID, &st );
  335. DateTime_SetSystemtime( hwndDTPStartTime, GDT_VALID, &st );
  336. lpConfProp->ConfInfo.GetStopTime(&nYear, &nMonth, &nDay, &nHour, &nMinute);
  337. st.wYear = nYear;
  338. st.wMonth = nMonth;
  339. st.wDayOfWeek = 0;
  340. st.wDay = nDay;
  341. st.wHour = nHour;
  342. st.wMinute = nMinute;
  343. st.wSecond = 0;
  344. st.wMilliseconds = 0;
  345. DateTime_SetSystemtime( hwndDTPStopDate, GDT_VALID, &st );
  346. DateTime_SetSystemtime( hwndDTPStopTime, GDT_VALID, &st );
  347. }
  348. else // if (bSaveAndValidate)
  349. {
  350. // conference name
  351. //
  352. //
  353. // We have to initialize szName
  354. //
  355. szName[0] = (TCHAR)0;
  356. Edit_GetText(hwndName, szName, NAME_MAXLEN+1);
  357. bstrName = SysAllocString(T2COLE(szName));
  358. //
  359. // We have to verify the allocation and
  360. // initialize the szName
  361. //
  362. if( IsBadStringPtr( bstrName, (UINT)-1) )
  363. {
  364. return PSNRET_INVALID_NOCHANGEPAGE;
  365. }
  366. if ( !*szName )
  367. {
  368. // improper name
  369. MessageBox(hwndDlg, String(g_hInstLib, IDS_CONFPROP_NONAME), NULL, MB_OK | MB_ICONEXCLAMATION);
  370. }
  371. else
  372. {
  373. lpConfProp->ConfInfo.put_Name(bstrName);
  374. }
  375. // conference description
  376. //
  377. Edit_GetText(hwndDescription, szDescription, DESCRIPTION_MAXLEN);
  378. bstrDescription = SysAllocString(T2COLE(szDescription));
  379. //
  380. // We have to validate the allocation
  381. //
  382. if( IsBadStringPtr( bstrDescription, (UINT)-1) )
  383. {
  384. SysFreeString(bstrName);
  385. return PSNRET_INVALID_NOCHANGEPAGE;
  386. }
  387. lpConfProp->ConfInfo.put_Description(bstrDescription);
  388. // conference start time
  389. //
  390. if ( DateTime_GetSystemtime(hwndDTPStartDate, &st) == GDT_VALID )
  391. {
  392. nYear = (UINT) st.wYear;
  393. nMonth = (BYTE) st.wMonth;
  394. nDay = (BYTE) st.wDay;
  395. if ( DateTime_GetSystemtime(hwndDTPStartTime, &st) == GDT_VALID )
  396. {
  397. nHour = (BYTE) st.wHour;
  398. nMinute = (BYTE) st.wMinute;
  399. lpConfProp->ConfInfo.SetStartTime(nYear, nMonth, nDay, nHour, nMinute);
  400. }
  401. }
  402. // conference stop time
  403. //
  404. if ( DateTime_GetSystemtime(hwndDTPStopDate, &st) == GDT_VALID )
  405. {
  406. nYear = (UINT) st.wYear;
  407. nMonth = (BYTE) st.wMonth;
  408. nDay = (BYTE) st.wDay;
  409. if ( DateTime_GetSystemtime(hwndDTPStopTime, &st) == GDT_VALID )
  410. {
  411. nHour = (BYTE) st.wHour;
  412. nMinute = (BYTE) st.wMinute;
  413. lpConfProp->ConfInfo.SetStopTime(nYear, nMonth, nDay, nHour, nMinute);
  414. }
  415. }
  416. // MDHCP info
  417. HWND hWndLst = GetDlgItem(hwndDlg, IDC_LST_SCOPE );
  418. if ( hWndLst )
  419. {
  420. int nSel = SendMessage(hWndLst, LB_GETCURSEL, 0, 0);
  421. lpConfProp->ConfInfo.m_bUserSelected = (nSel != LB_ERR);
  422. lpConfProp->ConfInfo.m_lScopeID = SendMessage( hWndLst, LB_GETITEMDATA, nSel, 0 );
  423. }
  424. DWORD dwError;
  425. hr = lpConfProp->ConfInfo.CommitGeneral( dwError );
  426. if ( hr != S_OK )
  427. {
  428. //get proper message
  429. UINT uId = IDS_CONFPROP_INVALIDTIME + dwError - 1;
  430. MessageBox(hwndDlg, String(g_hInstLib, uId), NULL, MB_OK | MB_ICONEXCLAMATION );
  431. }
  432. }
  433. SysFreeString(bstrName);
  434. SysFreeString(bstrDescription);
  435. SysFreeString(bstrOwner);
  436. return (hr == S_OK) ? PSNRET_NOERROR : PSNRET_INVALID_NOCHANGEPAGE;
  437. }
  438. //////////////////////////////////////////////////////////////////
  439. // This is the thread that goes out and enumerates the scopes
  440. //
  441. DWORD WINAPI ThreadMDHCPScopeEnum( LPVOID pParam )
  442. {
  443. ATLTRACE(_T(".enter.ThreadMDHCPScopeEnum().\n"));
  444. HWND hWndDlg = (HWND) pParam;
  445. if ( !IsWindow(hWndDlg) ) return E_ABORT;
  446. HRESULT hr = CoInitializeEx( NULL, COINIT_MULTITHREADED | COINIT_SPEED_OVER_MEMORY );
  447. if ( SUCCEEDED(hr) )
  448. {
  449. HWND hWndList = GetDlgItem(hWndDlg, IDC_LST_SCOPE );
  450. CConfInfo::PopulateListWithMDHCPScopeDescriptions( hWndList );
  451. CoUninitialize();
  452. }
  453. ATLTRACE(_T(".exit.ThreadMDHCPScopeEnum(%ld).\n"), hr);
  454. return hr;
  455. }
  456. void ShowScopeInfo( HWND hwndDlg, int nShow, bool bInit )
  457. {
  458. HWND hWndFrm = GetDlgItem( hwndDlg, IDC_FRM_SCOPE );
  459. HWND hWndLbl = GetDlgItem( hwndDlg, IDC_LBL_SCOPE );
  460. HWND hWndLst = GetDlgItem( hwndDlg, IDC_LST_SCOPE );
  461. if ( hWndFrm ) ShowWindow( hWndFrm, nShow );
  462. if ( hWndLbl ) ShowWindow( hWndLbl, nShow );
  463. if ( hWndLst )
  464. {
  465. ShowWindow( hWndLst, nShow );
  466. if ( bInit )
  467. {
  468. EnableWindow( hWndLst, FALSE );
  469. SendMessage( hWndLst, LB_RESETCONTENT, 0, 0 );
  470. SendMessage( hWndLst, LB_ADDSTRING, 0, (LPARAM) String(g_hInstLib, IDS_CONFPROP_ENUMERATING_SCOPES) );
  471. DWORD dwID;
  472. HANDLE hThread = CreateThread( NULL, 0, ThreadMDHCPScopeEnum, (void *) hwndDlg, NULL, &dwID );
  473. if ( hThread ) CloseHandle( hThread );
  474. }
  475. }
  476. }