summaryrefslogtreecommitdiff
path: root/plugins/Popup/src/common.h
blob: 402f9ec4b0eb217655ec438aefe982c56e361c09 (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
/*
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 COMMON_H
#define COMMON_H

void PopupPreview();

#define MAX_POPUPS 48

#define DB_READ_SUCCESS		0
#define DB_READ_FAIL		-1

//===== Definitions =====
#define LIGHTEN   24
#define DARKEN    64

inline void GetBmpSize(HBITMAP hbm, SIZE *sz)
{
	GetBitmapDimensionEx(hbm, sz);
}

inline void DebugMsg(LPTSTR msg){
	if (PopupOptions.debug){
		MessageBox(NULL, msg, _T("debug"), MB_OK);
	}
}

//===== Percentile to Byte and viceversa =====
inline int Byte2Percentile(int vByte) { return (vByte*100)/255; }
inline int Percentile2Byte(int vPerc) { return (vPerc*255)/100; }

//===== Strings & MirandaDB ==================
inline char *db_get_s(MCONTACT hContact, const char *ModuleName, const char *SettingName, const char *Default)
{
	DBVARIANT dbv;
	db_get(hContact, ModuleName, SettingName, &dbv);

	char *result = 0;
	if (dbv.type == DBVT_ASCIIZ)
		result = mir_strdup(dbv.pszVal);
	else if (Default)
		result = mir_strdup(Default);

	db_free(&dbv);
	return result;
}

inline INT_PTR DBGetContactSettingStringX(MCONTACT hContact, const char *ModuleName, const char *SettingName, const char *Default, const int retType)
{
	INT_PTR ret = NULL;

	DBVARIANT dbv;
	BOOL result = db_get_s(hContact, ModuleName, SettingName, &dbv, retType);

	switch(retType) {
	case DBVT_ASCIIZ:
		ret = (INT_PTR)mir_strdup(result ? Default : dbv.pszVal);
		break;
	case DBVT_WCHAR:
		if (!result)
			ret = (INT_PTR)mir_wstrdup(dbv.pwszVal);
		else
			ret = (INT_PTR)mir_a2u(Default);
		break;
	}
	if (!result)
		db_free(&dbv);
	return ret;
}

inline void AddTooltipTranslated(HWND hwndToolTip, HWND hwnd, int id, RECT rc, char *text)
{

		TOOLINFO ti = {0};
		ti.cbSize = sizeof(TOOLINFO);

		ti.hwnd = hwnd;
		ti.uId = id;
		SendMessage(hwndToolTip, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);

		LPWSTR wtext = mir_a2u(text);

		ti.uFlags = TTF_SUBCLASS;
		ti.hwnd = hwnd;
		ti.uId = id;
		ti.hinst = hInst;
		ti.lpszText = TranslateW(wtext);
		ti.rect = rc;
		SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);

		mir_free(wtext);

}

#endif //COMMON_H