aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/client/game_controls/mouseoverhtmlbutton.h
blob: e3800832c3911a384723542989b0ee74403d8349 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef MOUSEOVERHTMLBUTTON_H
#define MOUSEOVERHTMLBUTTON_H
#ifdef _WIN32
#pragma once
#endif


//-----------------------------------------------------------------------------
// Purpose: Triggers a new html page when the mouse goes over the button
//-----------------------------------------------------------------------------
class MouseOverHTMLButton : public vgui::Button
{
public:
	MouseOverHTMLButton(vgui::Panel *parent, const char *panelName, vgui::HTML *html, const char *page) :
					Button( parent, panelName, "MouseOverHTMLButton")
	{
		m_pHTML = html;
		m_iClass = 0;
		m_iIndex = -1;
		m_bAddShortCut = true;
		if ( page )
		{
			Q_strncpy( m_sPage, page, sizeof( m_sPage ) );
		}
		else
		{
			memset(m_sPage, 0x0, sizeof( m_sPage ) );
		}
	}

	void SetClass(int pClass, int index) { m_iClass = pClass; m_iIndex = index;}
	int GetClass() { return m_iClass; }
	
	void SetAddHotKey( bool state ) { m_bAddShortCut = state; }

	void SetPage( const char *page )
	{
		if ( page )
		{
			Q_strncpy( m_sPage, page, sizeof( m_sPage ) );
		}
		else
		{
			memset(m_sPage, 0x0, sizeof( m_sPage ) );
		}
	}

	void SetHTML( vgui::HTML *html) 
	{
		m_pHTML = html;
	}


private:

	virtual void OnCursorEntered() 
	{
		Button::OnCursorEntered();
		if ( m_pHTML && strlen(m_sPage) > 0 )
		{
			m_pHTML->OpenURL(m_sPage);
		}
	}

	virtual void SetText(const char *text)
	{
		if ( m_iIndex != -1 )
		{
			wchar_t newText[ 128 ];
			wchar_t localizeText[ 128 ];
			wchar_t *ansiLocal;
			if ( text[0] == '#' && ( ansiLocal = g_pVGuiLocalize->Find( text ) ) )
			{
				// wcsncpy will crash if ansiLocal is null... *sigh*
				wcsncpy(localizeText, ansiLocal, sizeof(localizeText)/sizeof(wchar_t));
			}
			else
			{
				g_pVGuiLocalize->ConvertANSIToUnicode( text, localizeText, sizeof( localizeText ) );
			}

			if ( m_bAddShortCut )
			{
#ifdef WIN32
				_snwprintf( newText, sizeof( newText )/ sizeof( wchar_t ), L"&%i %s", m_iIndex, localizeText);
#else
				_snwprintf( newText, sizeof( newText )/ sizeof( wchar_t ), L"&%i %S", m_iIndex, localizeText);
#endif

			}
			else
			{
				memcpy( newText, localizeText, sizeof( newText ) );
			}

			Button::SetText( newText );
		}
		else
		{
			Button::SetText( text );
		}
	}

	vgui::HTML *m_pHTML;
	char m_sPage[ 255 ];
	int m_iClass;
	int m_iIndex;
	bool m_bAddShortCut;
};


#endif // MOUSEOVERHTMLBUTTON_H