CSGDesitnationCombo.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. // CSGDesitnationCombo.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "CSGDesitnationCombo.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. // CCSGDesitnationCombo
  24. CCSGDesitnationCombo::CCSGDesitnationCombo()
  25. {
  26. // set dummy document ptr
  27. m_pLastDoc = (CWorldEditorDoc *) 0x12345678;
  28. }
  29. CCSGDesitnationCombo::~CCSGDesitnationCombo()
  30. {
  31. }
  32. BEGIN_MESSAGE_MAP(CCSGDesitnationCombo, CComboBox)
  33. //{{AFX_MSG_MAP(CCSGDesitnationCombo)
  34. ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
  35. ON_CONTROL_REFLECT(CBN_DROPDOWN, OnDropdown)
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CCSGDesitnationCombo message handlers
  40. BOOL CCSGDesitnationCombo::OnIdle(LONG lCount)
  41. {
  42. // get document ptr
  43. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  44. // if document ptr has changed
  45. // or if document was closed (pDoc == NULL and pLastDoc != NULL)
  46. // or if document was changed from last OnIdle, refresh CSG destination combo box
  47. if( (m_pLastDoc != pDoc) ||
  48. ((pDoc == NULL) && (m_pLastDoc != NULL)) ||
  49. ((pDoc != NULL) && !pDoc->m_chDocument.IsUpToDate( m_udComboEntries)) )
  50. {
  51. CEntity *penPreviouslySelectedEntity = NULL;
  52. INDEX iCurrentSelection = GetCurSel();
  53. if( iCurrentSelection != CB_ERR)
  54. {
  55. penPreviouslySelectedEntity = (CEntity *) GetItemData( iCurrentSelection);
  56. }
  57. // remove all combo entries
  58. ResetContent();
  59. // select entry one by default
  60. INDEX iSelectedEntryByName = -1;
  61. INDEX iSelectedEntryByPtr = -1;
  62. // if document doesn't exist
  63. if( pDoc == NULL)
  64. {
  65. AddString( L"None Available");
  66. }
  67. // if document exists
  68. else
  69. {
  70. // for all of the world's entities
  71. FOREACHINDYNAMICCONTAINER(pDoc->m_woWorld.wo_cenEntities, CEntity, iten)
  72. {
  73. // if the entity is brush
  74. CEntity::RenderType rt = iten->GetRenderType();
  75. if (rt==CEntity::RT_BRUSH || rt==CEntity::RT_FIELDBRUSH)
  76. {
  77. CTString strEntityName = iten->GetName();
  78. // and it has name property defined
  79. if( strEntityName != "")
  80. {
  81. // add it to CSG destination combo
  82. INDEX iComboEntry = AddString( CString(strEntityName));
  83. // set item's data as ptr to current entity
  84. SetItemData( iComboEntry, (ULONG)(&*iten));
  85. // try to select previously selected combo entry
  86. if( strEntityName == m_strLastSelectedName)
  87. {
  88. iSelectedEntryByName = iComboEntry;
  89. }
  90. if( &iten.Current() == penPreviouslySelectedEntity)
  91. {
  92. iSelectedEntryByPtr = iComboEntry;
  93. }
  94. }
  95. }
  96. }
  97. ASSERT( (GetCount() != CB_ERR) && (GetCount() != 0) );
  98. }
  99. if( iSelectedEntryByPtr != -1) SetCurSel( iSelectedEntryByPtr);
  100. else if( iSelectedEntryByName != -1) SetCurSel( iSelectedEntryByName);
  101. else SetCurSel( 0);
  102. m_udComboEntries.MarkUpdated();
  103. m_pLastDoc = pDoc;
  104. }
  105. return TRUE;
  106. }
  107. void CCSGDesitnationCombo::SelectBrushEntity( CEntity *penBrush)
  108. {
  109. // loop all entries in combo box
  110. for( INDEX i=0; i<GetCount(); i++)
  111. {
  112. // if this is searched brush entity
  113. if( ((CEntity *) GetItemData( i)) == penBrush)
  114. {
  115. // select it
  116. SetCurSel( i);
  117. m_strLastSelectedName = penBrush->GetName();
  118. break;
  119. }
  120. }
  121. }
  122. CEntity *CCSGDesitnationCombo::GetSelectedBrushEntity(void)
  123. {
  124. // assure valid brush entity ptr
  125. OnIdle( 0);
  126. INDEX iCurrentSelection = GetCurSel();
  127. if( iCurrentSelection == CB_ERR)
  128. {
  129. return NULL;
  130. }
  131. return (CEntity *) GetItemData( iCurrentSelection);
  132. }
  133. void CCSGDesitnationCombo::OnSelchange()
  134. {
  135. CEntity *penSelected = GetSelectedBrushEntity();
  136. if( penSelected != NULL)
  137. {
  138. m_strLastSelectedName = penSelected->GetName();
  139. }
  140. }
  141. void CCSGDesitnationCombo::OnDropdown()
  142. {
  143. INDEX ctItems = GetCount();
  144. if( ctItems == CB_ERR) return;
  145. CRect rectCombo;
  146. GetWindowRect( &rectCombo);
  147. PIX pixScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
  148. PIX pixMaxHeight = pixScreenHeight - rectCombo.top;
  149. CWnd *pwndParent = GetParent();
  150. if( pwndParent == NULL) return;
  151. pwndParent->ScreenToClient( &rectCombo);
  152. PIX pixNewHeight = GetItemHeight(0)*(ctItems+2);
  153. rectCombo.bottom = rectCombo.top + ClampUp( pixNewHeight, pixMaxHeight);
  154. MoveWindow( rectCombo);
  155. }