DlgSelectByName.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // DlgSelectByName.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "DlgSelectByName.h"
  16. #ifdef _DEBUG
  17. #undef new
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CDlgSelectByName dialog
  24. #define ENTITYPROPERTY(thisptr, offset, type) (*((type *)(((UBYTE *)thisptr)+offset)))
  25. CDlgSelectByName::CDlgSelectByName( CWorldEditorDoc *pDoc, CWnd* pParent /*=NULL*/)
  26. : CDialog(CDlgSelectByName::IDD, pParent)
  27. {
  28. //{{AFX_DATA_INIT(CDlgSelectByName)
  29. // NOTE: the ClassWizard will add member initialization here
  30. //}}AFX_DATA_INIT
  31. ASSERT( pDoc != NULL);
  32. m_pDoc = pDoc;
  33. }
  34. void CDlgSelectByName::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CDialog::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CDlgSelectByName)
  38. DDX_Control(pDX, IDC_ENTITY_LIST, m_ListBox);
  39. //}}AFX_DATA_MAP
  40. // if dialog gives data
  41. if( pDX->m_bSaveAndValidate)
  42. {
  43. // loop all list box's entries
  44. for( INDEX i=0; i<m_ListBox.GetCount(); i++)
  45. {
  46. // obtain entity ptr
  47. CEntity &penEntity = *((CEntity *) m_ListBox.GetItemData( i));
  48. // if entity was selected
  49. if( m_pDoc->m_selEntitySelection.IsSelected( penEntity))
  50. {
  51. // and check box is now not checked
  52. if( m_ListBox.GetCheck( i) == 0)
  53. {
  54. // deselect entity
  55. m_pDoc->m_selEntitySelection.Deselect( penEntity);
  56. }
  57. }
  58. else
  59. // else if entity was not selected
  60. {
  61. // and check box is now checked
  62. if( m_ListBox.GetCheck( i) == 1)
  63. {
  64. // select entity
  65. m_pDoc->m_selEntitySelection.Select( penEntity);
  66. }
  67. }
  68. }
  69. }
  70. }
  71. BEGIN_MESSAGE_MAP(CDlgSelectByName, CDialog)
  72. //{{AFX_MSG_MAP(CDlgSelectByName)
  73. ON_BN_CLICKED(ID_DESELECT_ALL, OnDeselectAll)
  74. ON_BN_CLICKED(ID_SELECT_ALL, OnSelectAll)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CDlgSelectByName message handlers
  79. BOOL CDlgSelectByName::OnInitDialog()
  80. {
  81. CDialog::OnInitDialog();
  82. ASSERT( m_pDoc != NULL);
  83. // for all entities in world
  84. FOREACHINDYNAMICCONTAINER(m_pDoc->m_woWorld.wo_cenEntities, CEntity, iten)
  85. {
  86. CTString strEntityName = iten->GetDescription();
  87. // and it has name property defined
  88. if( strEntityName != "")
  89. {
  90. // add it to list box
  91. INDEX iListEntry = m_ListBox.AddString( CString(strEntityName));
  92. // set item's data as ptr to current entity
  93. m_ListBox.SetItemData( iListEntry, (ULONG)(&*iten));
  94. // if current entity is selected
  95. if( iten->IsSelected( ENF_SELECTED))
  96. {
  97. // set check to on
  98. m_ListBox.SetCheck( iListEntry, 1);
  99. }
  100. // if entity is not selected
  101. else
  102. {
  103. // set check to off
  104. m_ListBox.SetCheck( iListEntry, 0);
  105. }
  106. }
  107. }
  108. return TRUE; // return TRUE unless you set the focus to a control
  109. // EXCEPTION: OCX Property Pages should return FALSE
  110. }
  111. void CDlgSelectByName::OnDeselectAll()
  112. {
  113. // loop all list box's entries
  114. for( INDEX i=0; i<m_ListBox.GetCount(); i++)
  115. {
  116. // slect check box
  117. m_ListBox.SetCheck( i, 0);
  118. }
  119. m_ListBox.Invalidate();
  120. }
  121. void CDlgSelectByName::OnSelectAll()
  122. {
  123. // loop all list box's entries
  124. for( INDEX i=0; i<m_ListBox.GetCount(); i++)
  125. {
  126. // slect check box
  127. m_ListBox.SetCheck( i, 1);
  128. }
  129. m_ListBox.Invalidate();
  130. }