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.

174 lines
4.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "client_pch.h"
  7. #include "vgui_helpers.h"
  8. #include <vgui_controls/TreeView.h>
  9. #include <vgui_controls/ListPanel.h>
  10. #include <vgui/ILocalize.h>
  11. #include <vgui/ISystem.h>
  12. #include "keyvalues.h"
  13. #include "convar.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. CConVarCheckButton::CConVarCheckButton( vgui::Panel *parent, const char *panelName, const char *text ) :
  17. vgui::CheckButton( parent, panelName, text )
  18. {
  19. m_pConVar = NULL;
  20. }
  21. void CConVarCheckButton::SetConVar( ConVar *pVar )
  22. {
  23. m_pConVar = pVar;
  24. SetSelected( m_pConVar->GetBool() );
  25. }
  26. void CConVarCheckButton::SetSelected( bool state )
  27. {
  28. BaseClass::SetSelected( state );
  29. m_pConVar->SetValue( state );
  30. }
  31. void IncrementalUpdateTree_R(
  32. vgui::TreeView *pTree,
  33. int iCurTreeNode,
  34. KeyValues *pValues,
  35. bool &bChanges,
  36. UpdateItemStateFn fn )
  37. {
  38. // Add new items.
  39. int iCurChild = 0;
  40. int nChildren = pTree->GetNumChildren( iCurTreeNode );
  41. KeyValues *pSub = pValues->GetFirstSubKey();
  42. while ( iCurChild < nChildren || pSub )
  43. {
  44. // The items in the tree are keyed by the panel pointer.
  45. if ( pSub )
  46. {
  47. const char *pSubText = pSub->GetString( "Text", NULL );
  48. if ( pSubText )
  49. {
  50. if ( iCurChild < nChildren )
  51. {
  52. // Compare the items here.
  53. int iChildItemId = pTree->GetChild( iCurTreeNode, iCurChild );
  54. if ( fn( pTree, iChildItemId, pSub ) )
  55. bChanges = true;
  56. IncrementalUpdateTree_R( pTree, iChildItemId, pSub, bChanges, fn );
  57. }
  58. else
  59. {
  60. // This means that the KeyValues has an extra node..
  61. bChanges = true;
  62. int iChildItemId = pTree->AddItem( pSub, iCurTreeNode );
  63. if ( fn( pTree, iChildItemId, pSub ) )
  64. bChanges = true;
  65. IncrementalUpdateTree_R( pTree, iChildItemId, pSub, bChanges, fn );
  66. }
  67. ++iCurChild;
  68. }
  69. pSub = pSub->GetNextKey();
  70. }
  71. else
  72. {
  73. // This means that the tree view has extra ones at the end. Get rid of them.
  74. int iChildItemId = pTree->GetChild( iCurTreeNode, iCurChild );
  75. --nChildren;
  76. bChanges = true;
  77. // HACK: I put a hack in there so if you give a negative number for the item, it'll
  78. // delete the panels immediately. This gets around a bug in the TreeView where the
  79. // panels don't always get deleted when using MarkPanelForDeletion.
  80. pTree->RemoveItem( -iChildItemId, false );
  81. }
  82. }
  83. }
  84. bool IncrementalUpdateTree(
  85. vgui::TreeView *pTree,
  86. KeyValues *pValues,
  87. UpdateItemStateFn fn,
  88. int iRoot )
  89. {
  90. if ( iRoot == -1 )
  91. {
  92. iRoot = pTree->GetRootItemIndex();
  93. if ( iRoot == -1 )
  94. {
  95. // Add a root if there isn't one yet.
  96. KeyValues *pTempValues = new KeyValues( "" );
  97. pTempValues->SetString( "Text", "" );
  98. iRoot = pTree->AddItem( pTempValues, iRoot );
  99. pTempValues->deleteThis();
  100. }
  101. }
  102. bool bChanges = false;
  103. IncrementalUpdateTree_R( pTree, iRoot, pValues, bChanges, fn );
  104. return bChanges;
  105. }
  106. void CopyListPanelToClipboard( vgui::ListPanel *pListPanel )
  107. {
  108. CUtlVector<char> textBuf;
  109. // Write the headers.
  110. int nColumns = pListPanel->GetNumColumnHeaders();
  111. for ( int i=0; i < nColumns; i++ )
  112. {
  113. if ( i != 0 )
  114. textBuf.AddToTail( '\t' );
  115. char tempText[512];
  116. if ( !pListPanel->GetColumnHeaderText( i, tempText, sizeof( tempText ) ) )
  117. Error( "GetColumHeaderText( %d ) failed", i );
  118. textBuf.AddMultipleToTail( strlen( tempText ), tempText );
  119. }
  120. textBuf.AddToTail( '\n' );
  121. // Now write the rows.
  122. int iCur = pListPanel->FirstItem();
  123. while ( iCur != pListPanel->InvalidItemID() )
  124. {
  125. // Write the columns for this row.
  126. for ( int i=0; i < nColumns; i++ )
  127. {
  128. if ( i != 0 )
  129. textBuf.AddToTail( '\t' );
  130. wchar_t tempTextWC[512];
  131. char tempText[512];
  132. pListPanel->GetCellText( iCur, i, tempTextWC, sizeof( tempTextWC ) );
  133. g_pVGuiLocalize->ConvertUnicodeToANSI( tempTextWC, tempText, sizeof( tempText ) );
  134. textBuf.AddMultipleToTail( strlen( tempText ), tempText );
  135. }
  136. textBuf.AddToTail( '\n' );
  137. iCur = pListPanel->NextItem( iCur );
  138. }
  139. textBuf.AddToTail( 0 );
  140. // Set the clipboard text.
  141. vgui::system()->SetClipboardText( textBuf.Base(), textBuf.Count() );
  142. }