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.

382 lines
9.5 KiB

  1. //
  2. // select.cpp : Implementation of the common select dialog.
  3. //
  4. // Cory West <[email protected]>
  5. // Copyright (c) Microsoft Corporation 1997
  6. //
  7. #include "stdafx.h"
  8. #include "macros.h"
  9. USE_HANDLE_MACROS("SCHMMGMT(compdata.cpp)")
  10. #include "schmutil.h"
  11. #include "cache.h"
  12. #include "select.h"
  13. #include "resource.h"
  14. const DWORD CSchmMgmtSelect::help_map[] =
  15. {
  16. IDC_SCHEMA_LIST, IDH_SCHEMA_LIST,
  17. 0,0
  18. };
  19. BEGIN_MESSAGE_MAP(CSchmMgmtSelect, CDialog)
  20. ON_MESSAGE(WM_HELP, OnHelp)
  21. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp)
  22. ON_LBN_DBLCLK(IDC_SCHEMA_LIST, OnDblclk)
  23. END_MESSAGE_MAP()
  24. CSchmMgmtSelect::CSchmMgmtSelect(
  25. ComponentData *pScope,
  26. SELECT_TYPE st,
  27. SchemaObject **pSchemaObject
  28. ) :
  29. CDialog(IDD_SCHEMA_SELECT, NULL),
  30. fDialogLoaded( FALSE ),
  31. SelectType( st ),
  32. pSchemaTarget( pSchemaObject ),
  33. pScopeControl( pScope )
  34. {
  35. ASSERT( NULL != pScopeControl );
  36. }
  37. CSchmMgmtSelect::~CSchmMgmtSelect()
  38. { ; }
  39. void
  40. CSchmMgmtSelect::DoDataExchange(
  41. CDataExchange *pDX
  42. ) {
  43. HWND hSelect;
  44. SchemaObject *pObject, *pHead;
  45. LRESULT strIndex;
  46. WPARAM wStrIndex;
  47. CDialog::DoDataExchange( pDX );
  48. hSelect = ::GetDlgItem( m_hWnd, IDC_SCHEMA_LIST );
  49. if ( !pDX->m_bSaveAndValidate &&
  50. !fDialogLoaded ) {
  51. //
  52. // Load the select box.
  53. //
  54. if ( hSelect != NULL ) {
  55. ::SendMessage( hSelect, LB_RESETCONTENT, 0, 0 );
  56. if ( SelectType == SELECT_CLASSES ||
  57. SelectType == SELECT_AUX_CLASSES) {
  58. //
  59. // Insert the sorted classes.
  60. //
  61. pObject = pScopeControl->g_SchemaCache.pSortedClasses;
  62. ASSERT( pObject != NULL );
  63. pHead = pObject;
  64. if( pHead )
  65. {
  66. do {
  67. // if not defunct & if selecting only Aux, is this an aux class.
  68. if ( pObject->isDefunct == FALSE &&
  69. ( SelectType != SELECT_AUX_CLASSES ||
  70. pObject->dwClassType == 0 ||
  71. pObject->dwClassType == 3 )
  72. ) {
  73. strIndex = ::SendMessage( hSelect, LB_ADDSTRING, 0,
  74. reinterpret_cast<LPARAM>( (LPCTSTR)pObject->ldapDisplayName) );
  75. if ( ( strIndex != LB_ERR ) &&
  76. ( strIndex != LB_ERRSPACE ) ) {
  77. //
  78. // The insert was successful. Associate the pointer.
  79. //
  80. wStrIndex = strIndex;
  81. ::SendMessage( hSelect, LB_SETITEMDATA, wStrIndex,
  82. reinterpret_cast<LPARAM>( pObject ) );
  83. }
  84. }
  85. pObject = pObject->pSortedListFlink;
  86. } while ( pObject != pHead );
  87. }
  88. } else {
  89. //
  90. // Insert the sorted attributes.
  91. //
  92. pObject = pScopeControl->g_SchemaCache.pSortedAttribs;
  93. ASSERT( pObject != NULL );
  94. pHead = pObject;
  95. do {
  96. if ( pObject->isDefunct == FALSE ) {
  97. strIndex = ::SendMessage( hSelect, LB_ADDSTRING, 0,
  98. reinterpret_cast<LPARAM>( (LPCTSTR)pObject->ldapDisplayName ) );
  99. if ( ( strIndex != LB_ERR ) &&
  100. ( strIndex != LB_ERRSPACE ) ) {
  101. //
  102. // The insert was successful. Associate the pointer.
  103. //
  104. wStrIndex = strIndex;
  105. ::SendMessage( hSelect, LB_SETITEMDATA, wStrIndex,
  106. reinterpret_cast<LPARAM>( pObject ) );
  107. }
  108. }
  109. pObject = pObject->pSortedListFlink;
  110. } while ( pObject != pHead );
  111. }
  112. ::SendMessage( hSelect, LB_SETCURSEL, 0, 0 );
  113. }
  114. fDialogLoaded = TRUE;
  115. }
  116. //
  117. // Figure out which one was selected.
  118. //
  119. if ( pSchemaTarget ) {
  120. strIndex = ::SendMessage( hSelect, LB_GETCURSEL, 0, 0 );
  121. *pSchemaTarget = reinterpret_cast<SchemaObject*>(
  122. ::SendMessage( hSelect, LB_GETITEMDATA, strIndex, 0 ) );
  123. }
  124. return;
  125. }
  126. void CSchmMgmtSelect::OnDblclk()
  127. {
  128. OnOK();
  129. }
  130. CSchemaObjectsListBox::CSchemaObjectsListBox() :
  131. m_pScope ( NULL ),
  132. m_stType ( SELECT_CLASSES ),
  133. m_nRemoveBtnID ( 0 ),
  134. m_pstrlistUnremovable ( NULL ),
  135. m_nUnableToDeleteID ( 0 ),
  136. m_fModified ( FALSE )
  137. {
  138. }
  139. CSchemaObjectsListBox::~CSchemaObjectsListBox()
  140. {
  141. POSITION pos = m_stringList.GetHeadPosition();
  142. while( pos != NULL )
  143. {
  144. delete m_stringList.GetNext( pos );
  145. }
  146. m_stringList.RemoveAll();
  147. }
  148. void CSchemaObjectsListBox::InitType(
  149. ComponentData * pScope,
  150. SELECT_TYPE stType, /* = SELECT_CLASSES*/
  151. int nRemoveBtnID, /* = 0*/
  152. CStringList * pstrlistUnremovable, /* = NULL*/
  153. int nUnableToDeleteID) /* = 0*/
  154. {
  155. ASSERT( pScope );
  156. // if nUnableToDeleteID is present, pstrlistUnremovable cannot be NULL
  157. ASSERT( nUnableToDeleteID ? NULL != pstrlistUnremovable : TRUE );
  158. m_pScope = pScope;
  159. m_stType = stType;
  160. m_nRemoveBtnID = nRemoveBtnID;
  161. m_pstrlistUnremovable = pstrlistUnremovable;
  162. m_nUnableToDeleteID = nUnableToDeleteID;
  163. }
  164. //
  165. // Add a new object to the listbox.
  166. //
  167. BOOL CSchemaObjectsListBox::AddNewObjectToList( void )
  168. {
  169. ASSERT( m_pScope ); // initialized??
  170. SchemaObject * pClass = NULL;
  171. BOOL fModified = FALSE;
  172. //
  173. // Start the common select dialog box.
  174. //
  175. CSchmMgmtSelect dlgSelectDialog( m_pScope, m_stType, &pClass );
  176. //
  177. // When this returns, the class schema object pointer
  178. // will be filled into pClass.
  179. //
  180. if ( IDOK == dlgSelectDialog.DoModal() && pClass != NULL )
  181. {
  182. //
  183. // If it is not already present, add and select it.
  184. // If it is already present, just select it.
  185. //
  186. int iItem = FindStringExact( -1, pClass->ldapDisplayName );
  187. if (LB_ERR == iItem)
  188. {
  189. iItem = FindStringExact( -1, pClass->oid );
  190. if ( LB_ERR == iItem )
  191. {
  192. iItem = AddString( pClass->ldapDisplayName );
  193. ASSERT( LB_ERR != iItem );
  194. CString * pstr = new CString( pClass->oid );
  195. ASSERT( pstr );
  196. m_stringList.AddTail( pstr );
  197. VERIFY( LB_ERR != SetItemDataPtr( iItem, static_cast<void *>(pstr) ) );
  198. SetModified();
  199. fModified = TRUE;
  200. }
  201. }
  202. iItem = SetCurSel( iItem );
  203. ASSERT( LB_ERR != iItem );
  204. OnSelChange();
  205. }
  206. return fModified;
  207. }
  208. BOOL CSchemaObjectsListBox::RemoveListBoxItem( void )
  209. {
  210. ASSERT(m_pScope);
  211. int i = GetCurSel();
  212. ASSERT( LB_ERR != i );
  213. if( LB_ERR != i )
  214. {
  215. // if there is an oid string allocated, delete it.
  216. CString * pstr = reinterpret_cast<CString *>( GetItemDataPtr( i ) );
  217. ASSERT( INVALID_POINTER != pstr );
  218. if( pstr && INVALID_POINTER != pstr )
  219. {
  220. ASSERT( m_stringList.Find( pstr ) );
  221. m_stringList.RemoveAt( m_stringList.Find(pstr) );
  222. delete pstr;
  223. }
  224. VERIFY( LB_ERR != DeleteString( i ) );
  225. int nElems = GetCount();
  226. ASSERT( LB_ERR != nElems );
  227. if( nElems > 0 )
  228. { // if not last item, move forward, otherwise, go to last.
  229. VERIFY( LB_ERR != SetCurSel( i < nElems ? i : nElems - 1 ) );
  230. }
  231. SetModified();
  232. OnSelChange();
  233. return TRUE;
  234. }
  235. else
  236. {
  237. ASSERT( FALSE ); // remove btn should've been disabled
  238. OnSelChange();
  239. return FALSE;
  240. }
  241. }
  242. void CSchemaObjectsListBox::OnSelChange( void )
  243. {
  244. ASSERT(m_pScope);
  245. ASSERT( GetParent() );
  246. int iItemSelected = GetCurSel();
  247. BOOL fEnableRemove = (LB_ERR != iItemSelected);
  248. if (fEnableRemove && m_pstrlistUnremovable)
  249. {
  250. // determine if object is in the exception list
  251. CString strItemSelected;
  252. GetText( iItemSelected, strItemSelected );
  253. // here the case sensitive search is enough
  254. // only items from the DS are added, no user input
  255. if ( m_pstrlistUnremovable->Find( strItemSelected ) )
  256. {
  257. fEnableRemove = FALSE;
  258. }
  259. // if we have a warning control, show/hide it.
  260. if( m_nUnableToDeleteID )
  261. {
  262. ASSERT( GetParent()->GetDlgItem( m_nUnableToDeleteID ) );
  263. GetParent()->GetDlgItem( m_nUnableToDeleteID )->ShowWindow( !fEnableRemove );
  264. }
  265. }
  266. if( m_nRemoveBtnID )
  267. {
  268. ASSERT( GetParent()->GetDlgItem( m_nRemoveBtnID ) );
  269. GetParent()->GetDlgItem( m_nRemoveBtnID )->EnableWindow( fEnableRemove );
  270. }
  271. }