summaryrefslogtreecommitdiff
path: root/plugins/Popup/src/common.h
blob: 5319bc236d992b93306f330ca12c17f76bcc9f26 (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
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
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.

===============================================================================

File name      : $HeadURL: http://svn.miranda.im/mainrepo/popup/trunk/src/common.h $
Revision       : $Revision: 1622 $
Last change on : $Date: 2010-06-23 23:32:21 +0300 (Ср, 23 июн 2010) $
Last change by : $Author: Merlin_de $

===============================================================================
*/

#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);
	}
}

/* not used
inline void  GetDCBmpSize(HDC hdc, SIZE *sz)
{
	BITMAP bmp;
	GetObject(GetCurrentObject(hdc, OBJ_BITMAP), sizeof(bmp), &bmp);
	sz->cx = bmp.bmWidth;
	sz->cy = bmp.bmHeight;
}

inline HBITMAP myLoadBitmap(LPCTSTR fn)
{
	HBITMAP res = (HBITMAP)LoadImage(NULL, fn, IMAGE_BITMAP, LR_DEFAULTSIZE, LR_DEFAULTSIZE, LR_LOADFROMFILE);
	
	BITMAPFILEHEADER bfh;
	BITMAPINFOHEADER bih;
	FILE *f = _tfopen (fn, _T("rb"));
	fread(&bfh, sizeof(bfh), 1, f);
	fread(&bih, sizeof(bih), 1, f);
	fclose(f);
	SetBitmapDimensionEx(res, bih.biWidth, bih.biHeight, NULL);

	return res;
}
*/

//===== 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 *DBGetContactSettingString(HANDLE hContact, const char *ModuleName, const char *SettingName, const char *Default)
{
	DBVARIANT dbv;
	DBCONTACTGETSETTING dbcgs;
	dbcgs.szModule = ModuleName;
	dbcgs.pValue = &dbv;
	dbcgs.szSetting = SettingName;

	CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)hContact, (LPARAM)&dbcgs);

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

	CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
	return result;
}

inline INT_PTR DBGetContactSettingStringX(HANDLE hContact, const char *ModuleName, const char *SettingName, const char *Default, const int retType)
{
	INT_PTR ret = NULL;
	BOOL result = 0;
	DBVARIANT dbv;
	DBCONTACTGETSETTING dbcgs;
	dbcgs.szModule = ModuleName;
	dbcgs.szSetting = SettingName;
	dbcgs.pValue = &dbv;
	dbv.type=(BYTE)retType;

	result = CallService(MS_DB_CONTACT_GETSETTING_STR, (WPARAM)hContact, (LPARAM)&dbcgs);

	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;
		default:
			break;
	}
	if (!result)
		CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
	return ret;
}

/* not used

inline void SetWindowTextTraslated(HWND hwnd, const char *text)
{
	if (!(hwnd && text)) return;
	if (g_popup.isOsUnicode && IsWindowUnicode(hwnd) && MySetWindowTextW)
	{
		UINT codepage = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
		int size = MultiByteToWideChar(codepage, 0, text, lstrlenA(text), 0, 0);
		WCHAR *wtext = new WCHAR[size+1];
		MultiByteToWideChar(codepage, 0, text, lstrlenA(text), wtext, size+1); wtext[size]=0;
		MySetWindowTextW(hwnd, TranslateW(wtext));
		delete [] wtext;
	} else
	{
		SetWindowTextA(hwnd, Translate(text));
	}
}

*/
/*/dedrecatet (tricky thing to minimize memory fragmentation)
inline wchar_t* a2u( char* src )
{
	int codepage = CallService( MS_LANGPACK_GETCODEPAGE, 0, 0 );

	int cbLen = MultiByteToWideChar( codepage, 0, src, -1, NULL, 0 );
	wchar_t* result = ( wchar_t* )mir_alloc( sizeof( wchar_t )*(cbLen+1));
	if ( result == NULL )
		return NULL;

	MultiByteToWideChar( codepage, 0, src, -1, result, cbLen );
	result[ cbLen ] = 0;
	return result;
}

#define nb_a2u_init()	\
	int nb_a2u_codepage = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);	\
	int nb_a2u_len = 0;	\

#define nb_a2u(dst, src)	\
	bool dst##_free = false;	\
	WCHAR *dst = NULL;	\
	nb_a2u_len = MultiByteToWideChar(nb_a2u_codepage, 0, src, -1, NULL, 0);	\
	__try	\
	{	\
		dst = (WCHAR *)_alloca(sizeof(WCHAR)*(nb_a2u_len+1));	\
	}	\
	__except( EXCEPTION_EXECUTE_HANDLER )	\
	{	\
		dst = (WCHAR *)mir_alloc(sizeof(WCHAR)*(nb_a2u_len+1));	\
		dst##_free = true;	\
	}	\
	MultiByteToWideChar(nb_a2u_codepage, 0, src, -1, dst, nb_a2u_len);	\
	dst[nb_a2u_len] = 0;

#define nb_a2u_free(dst)	\
	if (dst##_free)	\
		mir_free(dst);
*/

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);

}

/* not used
inline UINT getCodepageFromCharset(BYTE charset)
{
	switch (charset)
	{
		case ANSI_CHARSET:			return 1252;
		case BALTIC_CHARSET:		return 1257;
		case CHINESEBIG5_CHARSET:	return 950;
		case DEFAULT_CHARSET:		return CP_ACP;
		case EASTEUROPE_CHARSET:	return 1250;
		case GB2312_CHARSET:		return 936;
		case GREEK_CHARSET:			return 1253;
		case HANGUL_CHARSET:		return 949;
		case MAC_CHARSET:			return CP_MACCP;
		case OEM_CHARSET:			return CP_OEMCP;
		case RUSSIAN_CHARSET:		return 1251;
		case SHIFTJIS_CHARSET:		return 932;
//		case SYMBOL_CHARSET:		return ;
		case TURKISH_CHARSET:		return 1254;
		case VIETNAMESE_CHARSET:	return 1258;
		case JOHAB_CHARSET:			return 1361;
		case ARABIC_CHARSET:		return 1256;
		case HEBREW_CHARSET:		return 1255;
		default:					return CP_ACP;
	}
}
*/

#endif //COMMON_H