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.

281 lines
5.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1998
  6. //
  7. // File: dlgadv.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // DlgAdv.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "DlgAdv.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CDlgAdvanced dialog
  21. CDlgAdvanced::CDlgAdvanced(CWnd* pParent /*=NULL*/)
  22. : CQryDialog(CDlgAdvanced::IDD, pParent)
  23. {
  24. Init();
  25. }
  26. void CDlgAdvanced::Init()
  27. {
  28. //{{AFX_DATA_INIT(CDlgAdvanced)
  29. //}}AFX_DATA_INIT
  30. m_bDlgInited = FALSE;
  31. }
  32. CDlgAdvanced::~CDlgAdvanced()
  33. {
  34. m_strArrayValue.DeleteAll();
  35. }
  36. void CDlgAdvanced::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CQryDialog::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CDlgAdvanced)
  40. DDX_Control(pDX, IDC_QRY_LIST_VALUES, m_listCtrl);
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CDlgAdvanced, CQryDialog)
  44. //{{AFX_MSG_MAP(CDlgAdvanced)
  45. ON_BN_CLICKED(IDC_QRY_BUTTON_CLEARALL, OnButtonClearall)
  46. ON_BN_CLICKED(IDC_QRY_BUTTON_SELECTALL, OnButtonSelectall)
  47. ON_WM_WINDOWPOSCHANGING()
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CDlgAdvanced message handlers
  52. void CDlgAdvanced::OnButtonClearall()
  53. {
  54. int count = m_listCtrl.GetItemCount();
  55. while(count-- > 0)
  56. {
  57. m_listCtrl.SetCheck(count, FALSE);
  58. }
  59. }
  60. void CDlgAdvanced::OnButtonSelectall()
  61. {
  62. int count = m_listCtrl.GetItemCount();
  63. while(count-- > 0)
  64. {
  65. m_listCtrl.SetCheck(count, TRUE);
  66. }
  67. }
  68. void CDlgAdvanced::OnWindowPosChanging( WINDOWPOS* lpwndpos )
  69. {
  70. if ( lpwndpos->flags & SWP_SHOWWINDOW )
  71. {
  72. if(!m_bDlgInited)
  73. InitDialog();
  74. }
  75. CQryDialog::OnWindowPosChanging(lpwndpos);
  76. }
  77. // Query handle will call these functions through page proc
  78. HRESULT CDlgAdvanced::GetQueryParams(LPDSQUERYPARAMS* ppDsQueryParams)
  79. {
  80. HRESULT hr = S_OK;
  81. int count = m_listCtrl.GetItemCount();
  82. int index, j;
  83. CString str;
  84. CString *pStr;
  85. CString subFilters;
  86. int subCount = 0;
  87. CString filter;
  88. LPWSTR pQuery;
  89. USES_CONVERSION;
  90. try{
  91. while(count-- > 0)
  92. {
  93. if(m_listCtrl.GetCheck(count))
  94. {
  95. int nData = m_listCtrl.GetItemData(count);
  96. j = HIWORD(nData);
  97. index = LOWORD(nData);
  98. pStr = m_strArrayValue.GetAt(index);
  99. str = pStr->Left(j - 1);
  100. subFilters += FILTER_PREFIX;
  101. subFilters += ATTR_NAME_RRASATTRIBUTE;
  102. subFilters += _T("=");
  103. subFilters += str;
  104. subFilters += FILTER_POSTFIX;
  105. subCount ++;
  106. }
  107. }
  108. if(subCount) // any
  109. {
  110. if(subCount > 1)
  111. {
  112. filter = FILTER_PREFIX;
  113. filter += _T("|");
  114. filter += subFilters;
  115. filter += FILTER_POSTFIX;
  116. pQuery = T2W((LPTSTR)(LPCTSTR)filter);
  117. }
  118. else
  119. pQuery = T2W((LPTSTR)(LPCTSTR)subFilters);
  120. hr = ::BuildQueryParams(ppDsQueryParams, pQuery);
  121. }
  122. }
  123. catch(CMemoryException* pException)
  124. {
  125. pException->Delete();
  126. hr = E_OUTOFMEMORY;
  127. }
  128. return hr;
  129. }
  130. BOOL CDlgAdvanced::InitDialog()
  131. {
  132. if(m_bDlgInited) return TRUE;
  133. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  134. VARIANT var;
  135. CString* pStr;
  136. // get the list from dictionary
  137. VariantInit(&var);
  138. HRESULT hr = ::QueryRRASAdminDictionary(&var);
  139. if(hr == S_OK)
  140. {
  141. m_strArrayValue = (SAFEARRAY*)V_ARRAY(&var);
  142. }
  143. else
  144. {
  145. ReportError(hr, IDS_QRY_ERR_RRASADMINDIC, GetSafeHwnd());
  146. }
  147. VariantClear(&var);
  148. // remove the items that is already availabe in general page
  149. CStrArray genPageAttrs;
  150. hr = GetGeneralPageAttributes(genPageAttrs);
  151. if(hr == S_OK)
  152. {
  153. for(int i = 0; i < genPageAttrs.GetSize(); i++)
  154. // find the items in the list and remove it
  155. {
  156. for(int j = 0; j < m_strArrayValue.GetSize(); j++)
  157. {
  158. CString* pGen = NULL;
  159. CString* pAdv = NULL;
  160. pGen = genPageAttrs.GetAt(i);
  161. pAdv = m_strArrayValue.GetAt(j);
  162. ASSERT(pGen && pAdv);
  163. if(pAdv->Find(*pGen) == 0) // found
  164. {
  165. m_strArrayValue.RemoveAt(j);
  166. delete pAdv;
  167. break; // for(int j = )
  168. }
  169. } // for(int j = )
  170. } // for (int i = )
  171. // releases the memory
  172. genPageAttrs.DeleteAll();
  173. }
  174. else
  175. {
  176. ReportError(hr, IDS_QRY_ERR_RRASADMINDIC, GetSafeHwnd());
  177. }
  178. ListView_SetExtendedListViewStyle(m_listCtrl.GetSafeHwnd(),
  179. LVS_EX_FULLROWSELECT);
  180. // Initialize checkbox handling in the list control
  181. m_listCtrl.InstallChecks();
  182. RECT rect;
  183. m_listCtrl.GetClientRect(&rect);
  184. m_listCtrl.InsertColumn(0, _T("Desc"), LVCFMT_LEFT, (rect.right - rect.left - 4));
  185. int cRow = 0;
  186. for(int i = 0; i < m_strArrayValue.GetSize(); i++)
  187. {
  188. // the format: "311:6:601:Description"
  189. // put the discription field on the list control
  190. int cc = 0, j = 0;
  191. pStr = m_strArrayValue.GetAt(i);
  192. ASSERT(pStr);
  193. int length = pStr->GetLength();
  194. while(j < length && cc < 3)
  195. {
  196. if(pStr->GetAt(j++) == _T(':'))
  197. ++cc;
  198. }
  199. if(cc != 3) continue;
  200. cRow = m_listCtrl.InsertItem(0, pStr->Mid(j));
  201. // put index as low word, and the offset as hight word and put the long as data
  202. m_listCtrl.SetItemData(cRow, MAKELONG(i, j));
  203. m_listCtrl.SetCheck(cRow, FALSE);
  204. }
  205. m_bDlgInited = TRUE;
  206. return TRUE; // return TRUE unless you set the focus to a control
  207. // EXCEPTION: OCX Property Pages should return FALSE
  208. }
  209. BOOL CDlgAdvanced::OnInitDialog()
  210. {
  211. CQryDialog::OnInitDialog();
  212. #if 0 // move the code to positionchanging message handler
  213. return InitDialog();
  214. #else
  215. return TRUE;
  216. #endif
  217. }