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.

280 lines
5.4 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&)
  124. {
  125. hr = E_OUTOFMEMORY;
  126. }
  127. return hr;
  128. }
  129. BOOL CDlgAdvanced::InitDialog()
  130. {
  131. if(m_bDlgInited) return TRUE;
  132. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  133. VARIANT var;
  134. CString* pStr;
  135. // get the list from dictionary
  136. VariantInit(&var);
  137. HRESULT hr = ::QueryRRASAdminDictionary(&var);
  138. if(hr == S_OK)
  139. {
  140. m_strArrayValue = (SAFEARRAY*)V_ARRAY(&var);
  141. }
  142. else
  143. {
  144. ReportError(hr, IDS_QRY_ERR_RRASADMINDIC, GetSafeHwnd());
  145. }
  146. VariantClear(&var);
  147. // remove the items that is already availabe in general page
  148. CStrArray genPageAttrs;
  149. hr = GetGeneralPageAttributes(genPageAttrs);
  150. if(hr == S_OK)
  151. {
  152. for(int i = 0; i < genPageAttrs.GetSize(); i++)
  153. // find the items in the list and remove it
  154. {
  155. for(int j = 0; j < m_strArrayValue.GetSize(); j++)
  156. {
  157. CString* pGen = NULL;
  158. CString* pAdv = NULL;
  159. pGen = genPageAttrs.GetAt(i);
  160. pAdv = m_strArrayValue.GetAt(j);
  161. ASSERT(pGen && pAdv);
  162. if(pAdv->Find(*pGen) == 0) // found
  163. {
  164. m_strArrayValue.RemoveAt(j);
  165. delete pAdv;
  166. break; // for(int j = )
  167. }
  168. } // for(int j = )
  169. } // for (int i = )
  170. // releases the memory
  171. genPageAttrs.DeleteAll();
  172. }
  173. else
  174. {
  175. ReportError(hr, IDS_QRY_ERR_RRASADMINDIC, GetSafeHwnd());
  176. }
  177. ListView_SetExtendedListViewStyle(m_listCtrl.GetSafeHwnd(),
  178. LVS_EX_FULLROWSELECT);
  179. // Initialize checkbox handling in the list control
  180. m_listCtrl.InstallChecks();
  181. RECT rect;
  182. m_listCtrl.GetClientRect(&rect);
  183. m_listCtrl.InsertColumn(0, _T("Desc"), LVCFMT_LEFT, (rect.right - rect.left - 4));
  184. int cRow = 0;
  185. for(int i = 0; i < m_strArrayValue.GetSize(); i++)
  186. {
  187. // the format: "311:6:601:Description"
  188. // put the discription field on the list control
  189. int cc = 0, j = 0;
  190. pStr = m_strArrayValue.GetAt(i);
  191. ASSERT(pStr);
  192. int length = pStr->GetLength();
  193. while(j < length && cc < 3)
  194. {
  195. if(pStr->GetAt(j++) == _T(':'))
  196. ++cc;
  197. }
  198. if(cc != 3) continue;
  199. cRow = m_listCtrl.InsertItem(0, pStr->Mid(j));
  200. // put index as low word, and the offset as hight word and put the long as data
  201. m_listCtrl.SetItemData(cRow, MAKELONG(i, j));
  202. m_listCtrl.SetCheck(cRow, FALSE);
  203. }
  204. m_bDlgInited = TRUE;
  205. return TRUE; // return TRUE unless you set the focus to a control
  206. // EXCEPTION: OCX Property Pages should return FALSE
  207. }
  208. BOOL CDlgAdvanced::OnInitDialog()
  209. {
  210. CQryDialog::OnInitDialog();
  211. #if 0 // move the code to positionchanging message handler
  212. return InitDialog();
  213. #else
  214. return TRUE;
  215. #endif
  216. }