Repository navigation
Expand file tree
/
Copy pathPopup.h
More file actions
117 lines (94 loc) · 2.35 KB
/
Copy pathPopup.h
File metadata and controls
117 lines (94 loc) · 2.35 KB
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
/// \file
/// \author Matthew Allen (fret@memecode.com)
/// \brief A popup window
#pragma once
#include "lgi/common/Layout.h"
#if defined(LGI_CARBON) || defined(__GTK_H__) || defined(HAIKU)
#define LGI_POPUP_LWINDOW 1
#else
#define LGI_POPUP_LWINDOW 0
#endif
#if LGI_COCOA
ObjCWrapper(NSPanel, OsPanel)
#endif
/// A popup window: closes when the user clicks off-window.
class LgiClass LPopup :
#if LGI_POPUP_LWINDOW
public LWindow
#else
public LView
#endif
{
friend class _QPopup;
friend class LWindow;
friend class LDropDown;
friend class LMouseHook;
friend class LMouseHookPrivate;
friend class LView;
static LArray<LPopup*> CurrentPopups;
protected:
LPopup(LView *owner, bool nativeFocus);
class LPopupPrivate *d;
bool Cancelled = false;
LView *Owner = NULL;
uint64 Start = 0;
LRect ScreenPos;
#if LGI_COCOA
OsPanel Panel;
#endif
public:
LPopup(LView *owner);
~LPopup();
const char *GetClass() override { return "LPopup"; }
#if LGI_COCOA
OsPanel Handle() { return Panel; }
LRect &GetPos() override;
bool SetPos(LRect &r, bool repaint = false) override;
#endif
/// Sets whether the popup should take the focus when it's shown.
/// The default is 'true'
void TakeFocus(bool Take);
bool GetCancelled() { return Cancelled; }
bool Attach(LViewI *p) override;
void Visible(bool i) override;
bool Visible() override;
LMessage::Result OnEvent(LMessage *Msg) override;
};
/// Drop down menu, UI widget for opening a popup.
class LgiClass LDropDown : public LLayout
{
friend class LPopup;
LPopup *Popup;
public:
LDropDown(int Id, int x, int y, int cx, int cy, LPopup *popup);
~LDropDown();
// Properties
bool IsOpen();
void SetPopup(LPopup *popup);
LPopup *GetPopup();
// Window events
void OnFocus(bool f) override;
void OnPaint(LSurface *pDC) override;
bool OnKey(LKey &k) override;
void OnMouseClick(LMouse &m) override;
int OnNotify(LViewI *c, const LNotification &n) override;
// Override
virtual void Activate();
virtual void OnPopupClose() {}
};
/// Mouse hook grabs mouse events from the OS
class LPopup;
class LMouseHook
{
class LMouseHookPrivate *d;
public:
LMouseHook();
~LMouseHook();
void RegisterPopup(LPopup *p);
void UnregisterPopup(LPopup *p);
bool OnViewKey(LView *v, LKey &k);
void TrackClick(LView *v);
#ifdef WIN32
static LRESULT CALLBACK MouseProc(int Code, WPARAM a, LPARAM b);
#endif
};