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.

400 lines
10 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. CThemeContextActivator activator;
  170. ASSERT( m_pScope ); // initialized??
  171. SchemaObject * pClass = NULL;
  172. BOOL fModified = FALSE;
  173. //
  174. // Start the common select dialog box.
  175. //
  176. CSchmMgmtSelect dlgSelectDialog( m_pScope, m_stType, &pClass );
  177. //
  178. // When this returns, the class schema object pointer
  179. // will be filled into pClass.
  180. //
  181. if ( IDOK == dlgSelectDialog.DoModal() && pClass != NULL )
  182. {
  183. //
  184. // If it is not already present, add and select it.
  185. // If it is already present, just select it.
  186. //
  187. int iItem = FindStringExact( -1, pClass->ldapDisplayName );
  188. if (LB_ERR == iItem)
  189. {
  190. iItem = FindStringExact( -1, pClass->oid );
  191. if ( LB_ERR == iItem )
  192. {
  193. iItem = AddString( pClass->ldapDisplayName );
  194. ASSERT( LB_ERR != iItem );
  195. CString * pstr = new CString( pClass->oid );
  196. ASSERT( pstr );
  197. m_stringList.AddTail( pstr );
  198. VERIFY( LB_ERR != SetItemDataPtr( iItem, static_cast<void *>(pstr) ) );
  199. SetModified();
  200. fModified = TRUE;
  201. }
  202. }
  203. iItem = SetCurSel( iItem );
  204. ASSERT( LB_ERR != iItem );
  205. OnSelChange();
  206. }
  207. return fModified;
  208. }
  209. BOOL CSchemaObjectsListBox::RemoveListBoxItem( void )
  210. {
  211. ASSERT(m_pScope);
  212. int i = GetCurSel();
  213. ASSERT( LB_ERR != i );
  214. if( LB_ERR != i )
  215. {
  216. // if there is an oid string allocated, delete it.
  217. CString * pstr = reinterpret_cast<CString *>( GetItemDataPtr( i ) );
  218. ASSERT( INVALID_POINTER != pstr );
  219. if( pstr && INVALID_POINTER != pstr )
  220. {
  221. ASSERT( m_stringList.Find( pstr ) );
  222. m_stringList.RemoveAt( m_stringList.Find(pstr) );
  223. delete pstr;
  224. }
  225. VERIFY( LB_ERR != DeleteString( i ) );
  226. int nElems = GetCount();
  227. ASSERT( LB_ERR != nElems );
  228. if( nElems > 0 )
  229. { // if not last item, move forward, otherwise, go to last.
  230. VERIFY( LB_ERR != SetCurSel( i < nElems ? i : nElems - 1 ) );
  231. }
  232. SetModified();
  233. OnSelChange();
  234. return TRUE;
  235. }
  236. else
  237. {
  238. ASSERT( FALSE ); // remove btn should've been disabled
  239. OnSelChange();
  240. return FALSE;
  241. }
  242. }
  243. void CSchemaObjectsListBox::OnSelChange( void )
  244. {
  245. ASSERT(m_pScope);
  246. ASSERT( GetParent() );
  247. int iItemSelected = GetCurSel();
  248. BOOL fEnableRemove = (LB_ERR != iItemSelected);
  249. if (fEnableRemove && m_pstrlistUnremovable)
  250. {
  251. // determine if object is in the exception list
  252. CString strItemSelected;
  253. GetText( iItemSelected, strItemSelected );
  254. // here the case sensitive search is enough
  255. // only items from the DS are added, no user input
  256. if ( m_pstrlistUnremovable->Find( strItemSelected ) )
  257. {
  258. fEnableRemove = FALSE;
  259. }
  260. // if we have a warning control, show/hide it.
  261. if( m_nUnableToDeleteID )
  262. {
  263. ASSERT( GetParent()->GetDlgItem( m_nUnableToDeleteID ) );
  264. GetParent()->GetDlgItem( m_nUnableToDeleteID )->ShowWindow( !fEnableRemove );
  265. }
  266. }
  267. if( m_nRemoveBtnID )
  268. {
  269. // NTRAID#NTBUG9-477267-2001/10/19-lucios
  270. CWnd *remove = GetParent()->GetDlgItem( m_nRemoveBtnID );
  271. ASSERT(remove != NULL);
  272. if(fEnableRemove) remove->EnableWindow(true);
  273. else
  274. {
  275. // so that we don't disable the current
  276. // focused window
  277. if (GetFocus()==remove)
  278. {
  279. CDialog *father=(CDialog*)remove->GetParent();
  280. ASSERT(father != NULL);
  281. CWnd *prev=father->GetNextDlgTabItem(remove,true);
  282. ASSERT(prev != NULL);
  283. father->GotoDlgCtrl(prev);
  284. }
  285. remove->EnableWindow(false);
  286. }
  287. }
  288. }