summaryrefslogtreecommitdiff
path: root/public/panorama/controls/contextmenu.h
blob: bbb54511cfc9222fc398d2d776ea156b37cd9d36 (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
//=========== Copyright Valve Corporation, All rights reserved. ===============//
//
// Purpose: 
//=============================================================================//

#ifndef CONTEXTMENU_H
#define CONTEXTMENU_H

#ifdef _WIN32
#pragma once
#endif

#include "panorama/controls/panel2d.h"

DECLARE_PANEL_EVENT1( ContextMenuEvent, const char * )
DECLARE_PANEL_EVENT1( ContextMenuEventDirect, panorama::IUIEvent * );

namespace panorama 
{

//-----------------------------------------------------------------------------
// Purpose: Helper class to derive from for creating context menus
//-----------------------------------------------------------------------------
class CContextMenu : public panorama::CPanel2D
{
	DECLARE_PANEL2D( CContextMenu, panorama::CPanel2D );

public:
	CContextMenu( CPanel2D *pParent, const char *pchName, CPanel2D *pEventParent );
	CContextMenu( IUIWindow *pParent, const char *pchName, CPanel2D *pEventParent );
	virtual ~CContextMenu();
	virtual bool OnClick( IUIPanel *pPanel, const panorama::MouseData_t &code );

	void SetMenuTarget( const CPanelPtr< IUIPanel >& targetPanelPtr );

	void CalculatePosition() { m_bReposition = true; InvalidateSizeAndPosition(); }

protected:
	CPanel2D *GetEventParent() { return m_pEventParent; }

private:
	void Initialize( CPanel2D *pEventParent );

	void OnLayoutTraverse( float flFinalWidth, float flFinalHeight );

	bool OnFireEvent( const panorama::CPanelPtr< panorama::IUIPanel > &ptrPanel, const char *pchEventText );
	bool OnFireEvent( const panorama::CPanelPtr< panorama::IUIPanel > &ptrPanel, IUIEvent *pEvent );
	bool OnCancelled( const panorama::CPanelPtr< panorama::IUIPanel > &pPanel, panorama::EPanelEventSource_t eSource );

	CPanel2D *m_pEventParent;
	CPanelPtr< IUIPanel > m_pMenuTarget;
	double m_flCreateTime;
	bool m_bReposition;
};


//-----------------------------------------------------------------------------
// Purpose: Helper class for simple context menus that doesn't require derivation
//-----------------------------------------------------------------------------
class CSimpleContextMenu : public panorama::CContextMenu
{
	DECLARE_PANEL2D( CSimpleContextMenu, panorama::CContextMenu );

public:
	CSimpleContextMenu( CPanel2D *pParent, const char *pchName, CPanel2D *pEventParent  );
	CSimpleContextMenu( IUIWindow *pParent, const char *pchName, CPanel2D *pEventParent  );
	virtual ~CSimpleContextMenu();

	void AddMenuItem( const char *pchLabelText, const char *pchEventText );
	void AddMenuItemEvent( const char *pchLabel, IUIEvent *pEvent );

private:

};

} // namespace panorama

#endif // CONTEXTMENU_H