summaryrefslogtreecommitdiff
path: root/vgui2/dme_controls/BaseAttributeChoicePanel.cpp
blob: 3440a7f2c3878aeb598de671b404f6bf03d94e8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//=============================================================================//

#include "dme_controls/BaseAttributeChoicePanel.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/ComboBox.h"
#include "datamodel/dmelement.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"


using namespace vgui;


//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CBaseAttributeChoicePanel::CBaseAttributeChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
	BaseClass( parent, info ), m_pData( 0 )
{
	SetDropEnabled( false );
	m_pData = new vgui::ComboBox( this, "AttributeValue", 10, false );
	m_pData->SetEnabled( !HasFlag( FATTRIB_READONLY ) );
	m_pData->AddActionSignalTarget( this );
}


//-----------------------------------------------------------------------------
// Called after the constructor is finished
//-----------------------------------------------------------------------------
void CBaseAttributeChoicePanel::PostConstructor()
{
	BaseClass::PostConstructor();
	PopulateComboBox( m_pData );
	Refresh();
}


void CBaseAttributeChoicePanel::ApplySchemeSettings( IScheme *pScheme )
{
	BaseClass::ApplySchemeSettings( pScheme );
	HFont font = pScheme->GetFont( "DmePropertyVerySmall", IsProportional() );
	m_pData->SetFont(font);
}

vgui::Panel *CBaseAttributeChoicePanel::GetDataPanel()
{
	return static_cast< vgui::Panel * >( m_pData );
}


//-----------------------------------------------------------------------------
// Called when it is time to set the attribute from the combo box state
//-----------------------------------------------------------------------------
void CBaseAttributeChoicePanel::Apply( )
{
	KeyValues *kv = m_pData->GetActiveItemUserData();
	SetAttributeFromComboBox( m_pData, kv );
}


//-----------------------------------------------------------------------------
// Called when it is time to set the combo box from the attribute 
//-----------------------------------------------------------------------------
void CBaseAttributeChoicePanel::Refresh()
{
	SetComboBoxFromAttribute( m_pData );
}


//-----------------------------------------------------------------------------
// Called when the text in the panel changes 
//-----------------------------------------------------------------------------
void CBaseAttributeChoicePanel::OnTextChanged( Panel *panel )
{
	if ( IsAutoApply() )
	{
		Apply();
	}
	else
	{
		SetDirty(true);
	}
}