summaryrefslogtreecommitdiff
path: root/vgui2/dme_controls/filtercombobox.cpp
blob: 24f51c40caf46b88c3d3a278f258eeb622d65d64 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#include "dme_controls/filtercombobox.h"


using namespace vgui;


//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CFilterComboBox::CFilterComboBox( Panel *parent, const char *panelName, int numLines, bool allowEdit ) :
	BaseClass( parent, panelName, numLines, allowEdit )
{
}

//-----------------------------------------------------------------------------
// Purpose: panel lost focus message
//-----------------------------------------------------------------------------
void CFilterComboBox::OnKillFocus()
{
	int nLength = GetTextLength();
	char *pFilterText = (char*)_alloca( (nLength+1) * sizeof(char) );
	GetText( pFilterText, nLength+1 );

	// Remove the existing version in the list
	char pItemText[512];
	int nItemCount = GetItemCount();
	int i;
	for ( i = 0; i < nItemCount; ++i )
	{
		GetItemText( i, pItemText, sizeof(pItemText) );
		if ( !Q_stricmp( pFilterText, pItemText ) )
			break;
	}

	if ( i != nItemCount )
	{
		// Remove the existing copy
		DeleteItem( i );
	}

	AddItem( pFilterText, NULL );

	BaseClass::OnKillFocus( );
}