summaryrefslogtreecommitdiff
path: root/plugins/Popup/src/popup_wnd2.h
blob: b72f2e392075f4e73c0924869ec82d4c4983dd0b (plain)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
Popup Plus plugin for Miranda IM

Copyright	© 2002 Luca Santarelli,
© 2004-2007 Victor Pavlychko
© 2010 MPK
© 2010 Merlin_de

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef __popup_wnd2_h__
#define __popup_wnd2_h__

#define UM_CALLMETHOD (WM_USER+2048)

class PopupAvatar;

#define POPUP_OBJECT_SIGNARURE	0x0B1A11BE

class PopupWnd2 : public MZeroedObject
{
public:
	typedef		LRESULT(PopupWnd2::*MethodPtr)(LPARAM lParam);
	enum		TextType { TT_NONE, TT_UNICODE, TT_MTEXT };

	struct		ActionInfo
	{
		POPUPACTION actionA;
		RECT rc;
		bool hover;

		ActionInfo() : hover(false) {}
	};

	uint32_t		m_signature;

private:
	// style
	COLORREF m_clBack, m_clText, m_clTitle, m_clClock;
	int m_iTimeout;

	// content
	TextType    m_textType;
	wchar_t    *m_lptzTitle, *m_lptzText;
	HText       m_mtTitle, m_mtText;
	bool        m_bTextEmpty, m_bIcoLib;
	HFONT       m_hfnTitle, m_hfnText;
	HICON       m_hIcon;
	HBITMAP     m_hbmAvatar;
	wchar_t     m_time[2 + 1 + 2 + 1];
	ActionInfo* m_actions;
	int         m_actionCount;
	HANDLE      m_hNotification;

	// other data
	Formula::Args m_args;
	MCONTACT    m_hContact, m_hContactPassed;
	WNDPROC     m_PluginWindowProc;
	void       *m_PluginData;

	// the window
	LPTSTR      m_lpzSkin;
	bool        m_customPopup;
	HWND        m_hwnd, m_hwndToolTip;
	bool        m_bPositioned;
	POINT       m_pos;
	SIZE        m_sz;
	MyBitmap   *m_bmpBase, *m_bmp, *m_bmpAnimate;
	PopupAvatar*m_avatar;
	int         m_avatarFrameDelay;
	bool        m_bReshapeWindow;
	bool        m_bIsPinned;

	// show & hide
	bool        m_bFade;
	uint8_t        m_btAlpha0, m_btAlpha1;
	bool        m_bSlide;
	POINT       m_ptPosition0, m_ptPosition1;
	bool        m_bDestroy;
	bool        m_bIsHovered;

	// prevent unwanted clicks
	POINT       m_ptPrevCursor;

	// system
	POPUPOPTIONS *m_options;
	uint32_t       m_lockCount;

	PopupSkin::RenderInfo	m_renderInfo;

	void       fixDefaults();
	void       fixAvatar();
	int        fixActions(POPUPACTION *theActions, int count);
	int        fixActions(POPUPACTION *theActions, int count, int additional);

public:
	PopupWnd2(POPUPDATA2 *ppd, POPUPOPTIONS *theCustomOptions = nullptr, bool renderOnly = false);
	~PopupWnd2();

	void	startThread();

	void	create();
	void	updateLayered(uint8_t opacity);
	SIZE	measure();
	void	update();
	void	animate();

	void	show();
	void	hide();
	void	idle();

	uint32_t	lock()				{ return ++m_lockCount; }
	uint32_t	unlock()			{ return m_lockCount = m_lockCount ? m_lockCount - 1 : 0; }
	bool	isLocked()			{ return m_lockCount != 0; }

	void  setIcon(HICON);

	void	updateData(POPUPDATAW *ppd);
	void	updateData(POPUPDATA2 *ppd);
	void	buildMText();
	void	updateText(wchar_t *text);
	void	updateTitle(wchar_t *title);

	void	updateTimer();

	MyBitmap *getContent()      { return m_bmp; }

	COLORREF getTextColor()     { return m_clText; }
	COLORREF getTitleColor()    { return m_clTitle; }
	COLORREF getClockColor()    { return m_clClock; }
	COLORREF getBackColor()     { return m_clBack; }

	bool     isTextEmpty()      { return m_bTextEmpty; }
	bool     isIcolib()         { return m_bIcoLib; }
	TextType getTextType()      { return m_textType; }
	wchar_t *getText()          { return m_lptzText; }
	HText    getTextM()         { return m_mtText; }
	wchar_t *getTitle()         { return m_lptzTitle; }
	HText    getTitleM()        { return m_mtTitle; }

	int      getActionCount()   { return m_actionCount; }
	ActionInfo *getActions()    { return m_actions; }

	wchar_t *getTime()          { return m_time; }
	HICON    getIcon()          { return m_hIcon; }
	MCONTACT getContact()       { return m_hContact; }
	MCONTACT getContactPassed() { return m_hContactPassed; }
	int      getTimeout()       { return m_iTimeout; }
	HWND     getHwnd()          { return m_hwnd; }
	void    *getData()          { return m_PluginData; }

	PopupAvatar *getAvatar()    { return m_avatar; }

	Formula::Args *getArgs()    { return &m_args; }

	PopupSkin::RenderInfo *getRenderInfo() { return &m_renderInfo; }

	SIZE   getSize()            { return m_sz; }
	void   setSize(SIZE sz)
	{
		this->m_sz = sz;
		if (m_hwnd)
		{
			SetWindowPos(m_hwnd, nullptr, 0, 0, sz.cx, sz.cy, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING);
			if (!m_customPopup)
				PopupThreadUpdateWindow(this);
		}
	}
	bool	isPositioned()        { return m_bPositioned; }
	POINT	getPosition()         { return m_pos; }
	POINT	getRealPosition()     { return POINT(); }
	void	setPosition(POINT pt)
	{
		m_bPositioned = true;
		m_pos = pt;
		if (m_bSlide)
			m_ptPosition1 = pt;
		else
			SetWindowPos(m_hwnd, nullptr, pt.x, pt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING);
	}

	// Thread-related methods
	void	callMethodAsync(MethodPtr method, LPARAM lParam)
	{
		// we can't pass MethodPtr via WPARAM because it's size can differ! well, it's still 4 bytes on msvc but
		// on gcc we will get 8 bytes...
		MethodPtr *method_copy = new MethodPtr; *method_copy = method;
		PostMessage(m_hwnd, UM_CALLMETHOD, (WPARAM)method_copy, (LPARAM)lParam);
	}
	void	callMethodSync(MethodPtr method, LPARAM lParam)
	{
		// we can't pass MethodPtr via WPARAM because it's size can differ! well, it's still 4 bytes on msvc but
		// on gcc we will get 8 bytes...
		MethodPtr *method_copy = new MethodPtr; *method_copy = method;
		SendMessage(m_hwnd, UM_CALLMETHOD, (WPARAM)method_copy, (LPARAM)lParam);
	}

	LRESULT m_updateData_POPUPDATAW_V2(LPARAM arg)	{ updateData((POPUPDATAW *)arg); update(); return 0; }
	LRESULT m_updateData_POPUPDATA2(LPARAM arg)		{ updateData((POPUPDATA2 *)arg); update(); return 0; }
	LRESULT m_updateText(LPARAM arg)				{ updateText((wchar_t *)arg); update(); return 0; }
	LRESULT m_updateTitle(LPARAM arg)				{ updateTitle((wchar_t *)arg); update(); return 0; }
	LRESULT m_show(LPARAM)						{ show(); return 0; }
	LRESULT m_hide(LPARAM)						{ hide(); return 0; }

	// window related stuff
	LRESULT CALLBACK WindowProc(UINT, WPARAM, LPARAM);
	static LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);

	// window creation flag
	volatile bool m_bWindowCreated;
};

bool LoadPopupWnd2();
void UnloadPopupWnd2();

static inline bool IsValidPopupObject(PopupWnd2 *wnd)
{
	bool res = false;
	__try
	{
		if (wnd->m_signature == POPUP_OBJECT_SIGNARURE)
			res = true;
	}
	__except (EXCEPTION_EXECUTE_HANDLER)
	{
		res = false;
	}
	return res;
}

#endif // __popup_wnd2_h__