Counter Strike : Global Offensive Source Code
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.

197 lines
4.1 KiB

  1. //====== Copyright c 1996-2009, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef DLGLISTMANAGE_H
  7. #define DLGLISTMANAGE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. enum ListFontType_t
  12. {
  13. LISTFONT_NORMAL,
  14. LISTFONT_DUPLICATE,
  15. LISTFONT_BOLD
  16. };
  17. class IDlgListManageBrowse
  18. {
  19. public:
  20. virtual bool HandleBrowse( CStringList &lstResult ) = 0;
  21. };
  22. class CColorListBox : public CListBox
  23. {
  24. public:
  25. CColorListBox( void ) { }
  26. void AddItemText( const char *lpszText, ListFontType_t type )
  27. {
  28. int nIndex = AddString( lpszText );
  29. if( CB_ERR != nIndex )
  30. {
  31. SetItemData( nIndex, type );
  32. }
  33. }
  34. void CreateFonts( CDC *pDC )
  35. {
  36. if ( m_NormalFont.m_hObject == NULL )
  37. {
  38. // Describe a 16-point truetype font of normal weight
  39. LOGFONT lf;
  40. memset(&lf, 0, sizeof(lf));
  41. lf.lfHeight = 16;
  42. lf.lfWeight = FW_NORMAL;
  43. lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
  44. if (!m_NormalFont.CreateFontIndirect(&lf))
  45. return;
  46. }
  47. // Create a bold font
  48. if ( m_BoldFont.m_hObject == NULL )
  49. {
  50. if ( m_NormalFont.m_hObject )
  51. {
  52. LOGFONT LogFont;
  53. m_NormalFont.GetLogFont(&LogFont);
  54. LogFont.lfWeight = FW_BOLD;
  55. m_BoldFont.CreateFontIndirect(&LogFont);
  56. }
  57. }
  58. }
  59. virtual void DrawItem( LPDRAWITEMSTRUCT lpDIS )
  60. {
  61. CDC dc;
  62. CRect rcItem(lpDIS->rcItem);
  63. UINT nIndex = lpDIS->itemID;
  64. COLORREF rgbBkgnd = ::GetSysColor( (lpDIS->itemState & ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_WINDOW);
  65. dc.Attach( lpDIS->hDC );
  66. // Blah
  67. CreateFonts( &dc );
  68. CBrush br( rgbBkgnd );
  69. dc.FillRect( rcItem, &br );
  70. if( lpDIS->itemState & ODS_FOCUS )
  71. {
  72. dc.DrawFocusRect( rcItem );
  73. }
  74. if ( nIndex != (UINT)-1 )
  75. {
  76. // The text color is stored as the item data.
  77. ListFontType_t type = (ListFontType_t) GetItemData( nIndex );
  78. CString str;
  79. GetText( nIndex, str );
  80. dc.SetBkColor( rgbBkgnd );
  81. dc.SetTextColor( RGB(0,0,0) );
  82. CFont* pOldFont = NULL;
  83. if ( type == LISTFONT_BOLD )
  84. {
  85. pOldFont = dc.SelectObject( &m_BoldFont );
  86. }
  87. else
  88. {
  89. pOldFont = dc.SelectObject( &m_NormalFont );
  90. if ( type == LISTFONT_DUPLICATE )
  91. {
  92. // TODO: We don't color this anymore!
  93. // dc.SetTextColor(RGB(255,0,0));
  94. }
  95. }
  96. dc.TextOut(rcItem.left + 2, rcItem.top + 2, str);
  97. dc.SelectObject(pOldFont);
  98. }
  99. dc.Detach();
  100. }
  101. virtual void MeasureItem( LPMEASUREITEMSTRUCT lpMIS )
  102. {
  103. // Set the item height. Get the DC, select the font for the
  104. // list box, and compute the average height.
  105. CClientDC dc(this);
  106. TEXTMETRIC tm;
  107. CFont* pFont = GetFont();
  108. CFont* pOldFont = dc.SelectObject(pFont);
  109. dc.GetTextMetrics(&tm);
  110. dc.SelectObject(pOldFont);
  111. lpMIS->itemHeight = tm.tmHeight + 4;
  112. }
  113. private:
  114. CFont m_BoldFont;
  115. CFont m_NormalFont;
  116. };
  117. class CDlgListManage : public CDialog
  118. {
  119. // Construction
  120. public:
  121. CDlgListManage( CWnd* pParent = NULL, IDlgListManageBrowse *pBrowseImpl = NULL, const CMapObjectList *pObjectList = NULL ); // standard constructor
  122. // Dialog Data
  123. enum { IDD = IDD_MANAGE_LIST_DIALOG };
  124. void SaveScriptChanges( void );
  125. protected:
  126. virtual BOOL OnInitDialog();
  127. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  128. void OnSize(UINT nType, int cx, int cy);
  129. void OnGetMinMaxInfo(MINMAXINFO* lpMMI);
  130. void OnBrowse();
  131. DECLARE_MESSAGE_MAP()
  132. protected:
  133. CRect m_rcDialog;
  134. void PopulateScriptList( void );
  135. void UpdateScriptChanges( void );
  136. struct ResizeInfo_t
  137. {
  138. enum {
  139. RI_WIDTH = 1 << 0,
  140. RI_HEIGHT = 1 << 1,
  141. RI_LEFT = 1 << 2,
  142. RI_TOP = 1 << 3,
  143. // Combinations
  144. RI_WIDTH_AND_HEIGHT = RI_WIDTH | RI_HEIGHT,
  145. RI_TOP_AND_LEFT = RI_TOP | RI_LEFT
  146. };
  147. int flags;
  148. CRect rc;
  149. };
  150. CMap< int, int, ResizeInfo_t, ResizeInfo_t > m_ctlInfo;
  151. IDlgListManageBrowse *m_pBrowseImpl;
  152. CColorListBox m_ScriptList;
  153. const CMapObjectList *m_pObjectList;
  154. CUtlVector<CString> m_vAdditions;
  155. CUtlVector<CString> m_vSubtractions;
  156. public:
  157. afx_msg void OnBnClickedScriptListAdd();
  158. afx_msg void OnBnClickedScriptListRemove();
  159. afx_msg void OnBnClickedScriptListEdit();
  160. };
  161. #endif // #ifndef DLGLISTMANAGE_H