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.

406 lines
13 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-2002.
  5. //
  6. // File: SchedBas.cpp
  7. //
  8. // Contents:
  9. //
  10. //----------------------------------------------------------------------------
  11. // SchedBas.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "log.h"
  15. #include <schedule.h>
  16. #include "SchedBas.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. //****************************************************************************
  23. //
  24. // ReplaceFrameWithControl ()
  25. //
  26. // Use the a dialog control to set the size of the Schedule Matrix.
  27. //
  28. // HISTORY
  29. // 17-Jul-97 t-danm Copied from sample written by Scott Walker.
  30. //
  31. //****************************************************************************
  32. void ReplaceFrameWithControl (CWnd *pWnd, UINT nFrameID, CWnd *pControl,
  33. BOOL bAssignFrameIDToControl)
  34. {
  35. CWnd *pFrame;
  36. CRect rect;
  37. // FUTURE-2002/02/18-artm Document that pWnd and pControl cannot be NULL.
  38. ASSERT (pWnd != NULL);
  39. ASSERT (pControl != NULL);
  40. // Get the frame control
  41. pFrame = pWnd->GetDlgItem (nFrameID);
  42. // FUTURE-2002/02/18-artm Document that pFrame cannot be NULL.
  43. ASSERT (pFrame != NULL);
  44. // Get the frame rect
  45. pFrame->GetClientRect (&rect);
  46. pFrame->ClientToScreen (&rect);
  47. pWnd->ScreenToClient (&rect);
  48. // Set the control on the frame
  49. pControl->SetWindowPos (pFrame, rect.left, rect.top, rect.Width (), rect.Height (),
  50. SWP_SHOWWINDOW);
  51. // set the control font to match the dialog font
  52. pControl->SetFont (pWnd->GetFont ());
  53. // hide the placeholder frame
  54. pFrame->ShowWindow (SW_HIDE);
  55. if (bAssignFrameIDToControl)
  56. pControl->SetDlgCtrlID ( nFrameID );
  57. } // ReplaceFrameWithControl
  58. /////////////////////////////////////////////////////////////////////////////
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CLogOnHoursDlg dialog
  61. void CLegendCell::Init (CWnd* pParent, UINT nCtrlID, CScheduleMatrix* pMatrix, UINT nPercentage)
  62. {
  63. // FUTURE-2002/02/18-artm Document that pParent and pMatrix cannot be NULL.
  64. ASSERT (pParent && pMatrix );
  65. m_pMatrix = pMatrix;
  66. m_nPercentage = nPercentage;
  67. // ISSUE-2002/02/18-artm Ignoring return value from SubclassDlgItem in release build.
  68. // subclass the window so that we get paint notifications
  69. VERIFY ( SubclassDlgItem ( nCtrlID, pParent ) );
  70. // Resize the legend cell to have the same interior size as the cells
  71. // in the schedule matrix
  72. CSize size = pMatrix->GetCellSize ();
  73. SetWindowPos ( NULL, 0, 0, size.cx+1, size.cy+1,
  74. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER );
  75. }
  76. void CLegendCell::OnPaint ()
  77. {
  78. if (NULL == m_pMatrix)
  79. {
  80. ASSERT (0);
  81. return;
  82. }
  83. CRect rect;
  84. GetClientRect (rect);
  85. PAINTSTRUCT paintStruct;
  86. CDC *pdc = BeginPaint ( &paintStruct );
  87. m_pMatrix->DrawCell (
  88. pdc,
  89. rect,
  90. m_nPercentage,
  91. FALSE,
  92. m_pMatrix->GetBackColor (0,0),
  93. m_pMatrix->GetForeColor (0,0),
  94. m_pMatrix->GetBlendColor (0,0)
  95. );
  96. EndPaint (&paintStruct);
  97. }
  98. BEGIN_MESSAGE_MAP(CLegendCell, CStatic)
  99. //{{AFX_MSG_MAP(CLegendCell)
  100. ON_WM_PAINT ()
  101. //}}AFX_MSG_MAP
  102. END_MESSAGE_MAP()
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CScheduleBaseDlg dialog
  105. CScheduleBaseDlg::CScheduleBaseDlg(UINT nIDTemplate, bool bAddDaylightBias, CWnd* pParent /*=NULL*/)
  106. : CDialog(nIDTemplate, pParent),
  107. m_bSystemTimeChanged (false),
  108. m_dwFlags (0),
  109. m_bAddDaylightBias (bAddDaylightBias),
  110. m_nFirstDayOfWeek (::GetFirstDayOfWeek ()),
  111. m_cbArray (0)
  112. {
  113. EnableAutomation();
  114. //{{AFX_DATA_INIT(CScheduleBaseDlg)
  115. // NOTE: the ClassWizard will add member initialization here
  116. //}}AFX_DATA_INIT
  117. }
  118. void CScheduleBaseDlg::OnFinalRelease()
  119. {
  120. // When the last reference for an automation object is released
  121. // OnFinalRelease is called. The base class will automatically
  122. // deletes the object. Add additional cleanup required for your
  123. // object before calling the base class.
  124. CDialog::OnFinalRelease();
  125. }
  126. void CScheduleBaseDlg::DoDataExchange(CDataExchange* pDX)
  127. {
  128. CDialog::DoDataExchange(pDX);
  129. //{{AFX_DATA_MAP(CScheduleBaseDlg)
  130. // NOTE: the ClassWizard will add DDX and DDV calls here
  131. //}}AFX_DATA_MAP
  132. }
  133. BEGIN_MESSAGE_MAP(CScheduleBaseDlg, CDialog)
  134. //{{AFX_MSG_MAP(CScheduleBaseDlg)
  135. //}}AFX_MSG_MAP
  136. ON_MN_SELCHANGE (IDC_SCHEDULE_MATRIX, OnSelChange)
  137. ON_WM_TIMECHANGE()
  138. ON_MESSAGE (BASEDLGMSG_GETIDD, OnGetIDD)
  139. END_MESSAGE_MAP()
  140. BEGIN_DISPATCH_MAP(CScheduleBaseDlg, CDialog)
  141. //{{AFX_DISPATCH_MAP(CScheduleBaseDlg)
  142. // NOTE - the ClassWizard will add and remove mapping macros here.
  143. //}}AFX_DISPATCH_MAP
  144. END_DISPATCH_MAP()
  145. // Note: we add support for IID_IScheduleBaseDlg to support typesafe binding
  146. // from VBA. This IID must match the GUID that is attached to the
  147. // dispinterface in the .ODL file.
  148. // {701CFB38-AEF8-11D1-9864-00C04FB94F17}
  149. static const IID IID_IScheduleBaseDlg =
  150. { 0x701cfb38, 0xaef8, 0x11d1, { 0x98, 0x64, 0x0, 0xc0, 0x4f, 0xb9, 0x4f, 0x17 } };
  151. BEGIN_INTERFACE_MAP(CScheduleBaseDlg, CDialog)
  152. INTERFACE_PART(CScheduleBaseDlg, IID_IScheduleBaseDlg, Dispatch)
  153. END_INTERFACE_MAP()
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CScheduleBaseDlg message handlers
  156. BOOL CScheduleBaseDlg::OnInitDialog()
  157. {
  158. _TRACE (1, L"Entering CScheduleBaseDlg::OnInitDialog\n");
  159. CDialog::OnInitDialog();
  160. CRect rect (0,0,0,0);
  161. // Set up the weekly matrix and slap it on the dialog.
  162. BOOL bRet = m_schedulematrix.Create (L"WeeklyMatrix", rect, this, IDC_SCHEDULE_MATRIX);
  163. if ( !bRet )
  164. {
  165. DWORD dwErr = GetLastError ();
  166. _TRACE (0, L"CScheduleMatrix::Create () failed: 0x%x\n", dwErr);
  167. }
  168. ::ReplaceFrameWithControl (this, IDC_STATIC_LOGON_MATRIX, &m_schedulematrix, FALSE);
  169. // Set the blending color for the whole matrix
  170. m_schedulematrix.SetBlendColor (c_crBlendColor, 0, 0, 24, 7);
  171. m_schedulematrix.SetForeColor (c_crBlendColor, 0, 0, 24, 7);
  172. SetWindowText (m_szTitle);
  173. InitMatrix ();
  174. UpdateUI ();
  175. if ( m_dwFlags & SCHED_FLAG_READ_ONLY )
  176. {
  177. // Change the Cancel button to Close
  178. CString strClose;
  179. // FUTURE-2002/02/18-artm Check the return value from LoadString() in release build.
  180. // NOTICE-2002/02/18-artm CString can throw out of memory exception.
  181. // There's no good way to handle exception at this level, so caller will be
  182. // responsible.
  183. VERIFY (strClose.LoadString (IDS_CLOSE));
  184. GetDlgItem (IDCANCEL)->SetWindowText (strClose);
  185. // Hide the OK button
  186. GetDlgItem (IDOK)->ShowWindow (SW_HIDE);
  187. }
  188. _TRACE (-1, L"Leaving CScheduleBaseDlg::OnInitDialog\n");
  189. return TRUE; // return TRUE unless you set the focus to a control
  190. // EXCEPTION: OCX Property Pages should return FALSE
  191. }
  192. void CScheduleBaseDlg::SetTitle(LPCTSTR pszTitle)
  193. {
  194. // NOTICE-NTRAID#NTBUG9-547381-2002/02/18-artm String class handles NULL.
  195. // String class easily handles null pointer.
  196. m_szTitle = pszTitle;
  197. }
  198. void CScheduleBaseDlg::OnSelChange ()
  199. {
  200. UpdateUI ();
  201. }
  202. void CScheduleBaseDlg::UpdateUI ()
  203. {
  204. CString strDescr;
  205. m_schedulematrix.GetSelDescription (OUT strDescr);
  206. // FUTURE-2002/02/18-artm Check return value of SetDlgItemText().
  207. SetDlgItemText (IDC_STATIC_DESCRIPTION, strDescr);
  208. UpdateButtons ();
  209. }
  210. /////////////////////////////////////////////////////////////////////
  211. // InitMatrix2 ()
  212. //
  213. // Initialize the schedule matrix with an array of values
  214. // representing replication frequencies.
  215. //
  216. // INTERFACE NOTES
  217. // Each byte of rgbData represent one hour. The first day of
  218. // the week is Sunday and the last day is Saturday.
  219. //
  220. void CScheduleBaseDlg::InitMatrix2 (const BYTE rgbData[])
  221. {
  222. // NTRAID#NTBUG9-547765-2002/02/18-artm No way to validate rgbData under current interface.
  223. //
  224. // There is no way to check that rgbData is the correct length w/out
  225. // passing in a length parameter. Also, there should be check that
  226. // rgbData is not NULL.
  227. ASSERT (rgbData);
  228. ASSERT ( m_cbArray == 7*24);
  229. if ( m_cbArray != 7*24 )
  230. return;
  231. bool bMatrixAllSelected = true;
  232. bool bMatrixAllClear = true;
  233. const BYTE * pbData = rgbData;
  234. size_t nIndex = 0;
  235. for (int iDayOfWeek = 0; iDayOfWeek < 7 && nIndex < m_cbArray; iDayOfWeek++)
  236. {
  237. for (int iHour = 0; iHour < 24 && nIndex < m_cbArray; iHour++)
  238. {
  239. if (!*pbData)
  240. bMatrixAllSelected = false;
  241. else
  242. bMatrixAllClear = false;
  243. m_schedulematrix.SetPercentage (GetPercentageToSet (*pbData) , iHour, iDayOfWeek);
  244. pbData++;
  245. nIndex++;
  246. } // for
  247. } // for
  248. // If the whole matrix is selected, then set the selection to the whole matrix
  249. if ( bMatrixAllSelected || bMatrixAllClear )
  250. m_schedulematrix.SetSel (0, 0, 24, 7);
  251. else
  252. m_schedulematrix.SetSel (0, 0, 1, 1);
  253. } // InitMatrix2 ()
  254. /////////////////////////////////////////////////////////////////////
  255. // GetByteArray ()
  256. //
  257. // Get an array of bytes from the schedule matrix. Each byte
  258. // is a boolean value representing one hour of logon access to a user.
  259. //
  260. // INTERFACE NOTES
  261. // Same as SetLogonByteArray ().
  262. //
  263. void CScheduleBaseDlg::GetByteArray (OUT BYTE rgbData[], const size_t cbArray)
  264. {
  265. // NTRAID#NTBUG9-547765-2002/02/18-artm No way to validate rgbData as written.
  266. //
  267. // Need a size parameter to verify correct size of rgbData, esp.
  268. // since caller is taking responsibility for allocating array.
  269. // Also, need to check that rgbData is not NULL.
  270. ASSERT (rgbData);
  271. BYTE * pbData = rgbData;
  272. size_t nIndex = 0;
  273. for (int iDayOfWeek = 0; iDayOfWeek < 7 && nIndex < cbArray; iDayOfWeek++)
  274. {
  275. for (int iHour = 0; iHour < 24 && nIndex < cbArray; iHour++)
  276. {
  277. *pbData = GetMatrixPercentage (iHour, iDayOfWeek);
  278. pbData++;
  279. nIndex++;
  280. } // for
  281. } // for
  282. } // GetByteArray ()
  283. // If the system time or time zone has changed prompt the user to close and reopen
  284. // the dialog. Otherwise, if the dialog data was saved, data could be corrupted.
  285. // Disable all controls.
  286. void CScheduleBaseDlg::OnTimeChange()
  287. {
  288. if ( !m_bSystemTimeChanged )
  289. {
  290. m_bSystemTimeChanged = true;
  291. CString caption;
  292. CString text;
  293. // FUTURE-2002/02/18-artm Check return value of LoadString().
  294. // NOTICE-2002/02/18-artm CString can throw out of memory exceptions.
  295. //
  296. // No good way to handle exceptions at this level; caller is responsible
  297. // for handling any out of memory exceptions.
  298. VERIFY (caption.LoadString (IDS_ACTIVE_DIRECTORY_MANAGER));
  299. VERIFY (text.LoadString (IDS_TIMECHANGE));
  300. MessageBox (text, caption, MB_ICONINFORMATION | MB_OK);
  301. GetDlgItem (IDCANCEL)->SetFocus ();
  302. GetDlgItem (IDOK)->EnableWindow (FALSE);
  303. m_schedulematrix.EnableWindow (FALSE);
  304. TimeChange ();
  305. }
  306. }
  307. void CScheduleBaseDlg::SetFlags(DWORD dwFlags)
  308. {
  309. m_dwFlags = dwFlags;
  310. }
  311. DWORD CScheduleBaseDlg::GetFlags() const
  312. {
  313. return m_dwFlags;
  314. }
  315. LRESULT CScheduleBaseDlg::OnGetIDD (WPARAM /*wParam*/, LPARAM /*lParam*/)
  316. {
  317. return GetIDD ();
  318. }
  319. void CScheduleBaseDlg::OnOK ()
  320. {
  321. if ( m_nFirstDayOfWeek == ::GetFirstDayOfWeek () )
  322. {
  323. CDialog::OnOK ();
  324. }
  325. else
  326. {
  327. CString caption;
  328. CString text;
  329. // FUTURE-2002/02/18-artm Check return value of LoadString().
  330. // NOTICE-2002/02/18-artm CString can throw out of memory exceptions.
  331. //
  332. // No good way to handle exceptions at this level; caller is responsible
  333. // for handling any out of memory exceptions.
  334. VERIFY (caption.LoadString (IDS_ACTIVE_DIRECTORY_MANAGER));
  335. VERIFY (text.LoadString (IDS_LOCALECHANGE));
  336. MessageBox (text, caption, MB_ICONINFORMATION | MB_OK);
  337. GetDlgItem (IDCANCEL)->SetFocus ();
  338. }
  339. }