diff options
-rw-r--r-- | plugins/AVS/src/acc.cpp | 563 | ||||
-rw-r--r-- | plugins/AVS/src/cache.cpp | 100 | ||||
-rw-r--r-- | plugins/AVS/src/commonheaders.h | 1 | ||||
-rw-r--r-- | plugins/AVS/src/image_utils.cpp | 452 | ||||
-rw-r--r-- | plugins/AVS/src/image_utils.h | 4 | ||||
-rw-r--r-- | plugins/AVS/src/main.cpp | 73 | ||||
-rw-r--r-- | plugins/AVS/src/options.cpp | 532 | ||||
-rw-r--r-- | plugins/AVS/src/poll.cpp | 49 | ||||
-rw-r--r-- | plugins/AVS/src/services.cpp | 369 | ||||
-rw-r--r-- | plugins/AVS/src/utils.cpp | 324 | ||||
-rw-r--r-- | plugins/AVS/src/version.h | 2 |
11 files changed, 1058 insertions, 1411 deletions
diff --git a/plugins/AVS/src/acc.cpp b/plugins/AVS/src/acc.cpp index ea9a39e6fb..35551f2e0f 100644 --- a/plugins/AVS/src/acc.cpp +++ b/plugins/AVS/src/acc.cpp @@ -78,20 +78,18 @@ typedef struct void ResizeFlash(HWND hwnd, ACCData* data)
{
- if ((data->hContact != NULL || data->proto[0] != '\0') && ServiceExists(MS_FAVATAR_RESIZE))
- {
+ if ((data->hContact != NULL || data->proto[0] != '\0') && ServiceExists(MS_FAVATAR_RESIZE)) {
RECT rc;
GetClientRect(hwnd, &rc);
- if (data->borderColor != -1 || data->avatarBorderColor != -1)
- {
- rc.left ++;
+ if (data->borderColor != -1 || data->avatarBorderColor != -1) {
+ rc.left++;
rc.right -= 2;
- rc.top ++;
+ rc.top++;
rc.bottom -= 2;
}
- FLASHAVATAR fa = {0};
+ FLASHAVATAR fa = { 0 };
fa.hContact = data->hContact;
fa.cProto = data->proto;
fa.hParentWindow = hwnd;
@@ -103,10 +101,8 @@ void ResizeFlash(HWND hwnd, ACCData* data) void SetBkgFlash(HWND hwnd, ACCData* data)
{
- if ((data->hContact != NULL || data->proto[0] != '\0')
- && ServiceExists(MS_FAVATAR_SETBKCOLOR))
- {
- FLASHAVATAR fa = {0};
+ if ((data->hContact != NULL || data->proto[0] != '\0') && ServiceExists(MS_FAVATAR_SETBKCOLOR)) {
+ FLASHAVATAR fa = { 0 };
fa.hContact = data->hContact;
fa.cProto = data->proto;
fa.hParentWindow = hwnd;
@@ -115,7 +111,7 @@ void SetBkgFlash(HWND hwnd, ACCData* data) if (data->bkgColor != -1)
CallService(MS_FAVATAR_SETBKCOLOR, (WPARAM)&fa, (LPARAM)data->bkgColor);
else
- CallService(MS_FAVATAR_SETBKCOLOR, (WPARAM)&fa, (LPARAM)RGB(255,255,255));
+ CallService(MS_FAVATAR_SETBKCOLOR, (WPARAM)&fa, (LPARAM)RGB(255, 255, 255));
}
}
@@ -124,9 +120,8 @@ void DestroyFlash(HWND hwnd, ACCData* data) if (!data->showingFlash)
return;
- if ((data->hContact != NULL || data->proto[0] != '\0') && ServiceExists(MS_FAVATAR_DESTROY))
- {
- FLASHAVATAR fa = {0};
+ if ((data->hContact != NULL || data->proto[0] != '\0') && ServiceExists(MS_FAVATAR_DESTROY)) {
+ FLASHAVATAR fa = { 0 };
fa.hContact = data->hContact;
fa.cProto = data->proto;
fa.hParentWindow = hwnd;
@@ -143,17 +138,13 @@ void StartFlash(HWND hwnd, ACCData* data) return;
int format;
- if (data->hContact != NULL)
- {
+ if (data->hContact != NULL) {
format = db_get_w(data->hContact, "ContactPhoto", "Format", 0);
}
- else if (data->proto[0] != '\0')
- {
+ else if (data->proto[0] != '\0') {
protoPicCacheEntry *ace = NULL;
- for (int i = 0; i < g_MyAvatars.getCount(); i++)
- {
- if (!lstrcmpA(data->proto, g_MyAvatars[i].szProtoname))
- {
+ for (int i = 0; i < g_MyAvatars.getCount(); i++) {
+ if (!lstrcmpA(data->proto, g_MyAvatars[i].szProtoname)) {
ace = &g_MyAvatars[i];
break;
}
@@ -164,13 +155,12 @@ void StartFlash(HWND hwnd, ACCData* data) else
format = 0;
}
- else
- return;
+ else return;
if (format != PA_FORMAT_XML && format != PA_FORMAT_SWF)
return;
- FLASHAVATAR fa = {0};
+ FLASHAVATAR fa = { 0 };
fa.hContact = data->hContact;
fa.cProto = data->proto;
fa.hParentWindow = hwnd;
@@ -216,18 +206,14 @@ ERR: return FALSE;
}
-void AnimatedGifDispodeFrame(ACCData* data)
+void AnimatedGifDispodeFrame(ACCData *data)
{
- if (data->ag.frame.disposal_method == GIF_DISPOSAL_PREVIOUS)
- {
+ if (data->ag.frame.disposal_method == GIF_DISPOSAL_PREVIOUS) {
// TODO
}
- else if (data->ag.frame.disposal_method == GIF_DISPOSAL_BACKGROUND)
- {
- for (int y = 0; y < data->ag.frame.height; y++)
- {
- RGBQUAD *scanline = (RGBQUAD *) fei->FI_GetScanLine(data->ag.dib,
- data->ag.logicalHeight - (y + data->ag.frame.top) - 1) + data->ag.frame.left;
+ else if (data->ag.frame.disposal_method == GIF_DISPOSAL_BACKGROUND) {
+ for (int y = 0; y < data->ag.frame.height; y++) {
+ RGBQUAD *scanline = (RGBQUAD*)fei->FI_GetScanLine(data->ag.dib, data->ag.logicalHeight - (y + data->ag.frame.top) - 1) + data->ag.frame.left;
for (int x = 0; x < data->ag.frame.width; x++)
*scanline++ = data->ag.background;
}
@@ -238,8 +224,7 @@ void AnimatedGifMountFrame(ACCData* data, int page) {
data->ag.frame.num = page;
- if (data->ag.hbms[page] != NULL)
- {
+ if (data->ag.hbms[page] != NULL) {
data->ag.frame.disposal_method = GIF_DISPOSAL_LEAVE;
return;
}
@@ -269,20 +254,19 @@ void AnimatedGifMountFrame(ACCData* data, int page) else
data->ag.frame.disposal_method = 0;
- data->ag.frame.width = fei->FI_GetWidth(dib);
+ data->ag.frame.width = fei->FI_GetWidth(dib);
data->ag.frame.height = fei->FI_GetHeight(dib);
-
//decode page
int palSize = fei->FI_GetColorsUsed(dib);
RGBQUAD *pal = fei->FI_GetPalette(dib);
bool have_transparent = false;
int transparent_color = -1;
- if ( fei->FI_IsTransparent(dib)) {
+ if (fei->FI_IsTransparent(dib)) {
int count = fei->FI_GetTransparencyCount(dib);
BYTE *table = fei->FI_GetTransparencyTable(dib);
- for ( int i = 0; i < count; i++ ) {
- if ( table[i] == 0 ) {
+ for (int i = 0; i < count; i++) {
+ if (table[i] == 0) {
have_transparent = true;
transparent_color = i;
break;
@@ -291,11 +275,11 @@ void AnimatedGifMountFrame(ACCData* data, int page) }
//copy page data into logical buffer, with full alpha opaqueness
- for ( int y = 0; y < data->ag.frame.height; y++ ) {
- RGBQUAD *scanline = (RGBQUAD *)fei->FI_GetScanLine(data->ag.dib, data->ag.logicalHeight - (y + data->ag.frame.top) - 1) + data->ag.frame.left;
+ for (int y = 0; y < data->ag.frame.height; y++) {
+ RGBQUAD *scanline = (RGBQUAD*)fei->FI_GetScanLine(data->ag.dib, data->ag.logicalHeight - (y + data->ag.frame.top) - 1) + data->ag.frame.left;
BYTE *pageline = fei->FI_GetScanLine(dib, data->ag.frame.height - y - 1);
- for ( int x = 0; x < data->ag.frame.width; x++ ) {
- if ( !have_transparent || *pageline != transparent_color ) {
+ for (int x = 0; x < data->ag.frame.width; x++) {
+ if (!have_transparent || *pageline != transparent_color) {
*scanline = pal[*pageline];
scanline->rgbReserved = 255;
}
@@ -311,14 +295,12 @@ void AnimatedGifMountFrame(ACCData* data, int page) void AnimatedGifDeleteTmpValues(ACCData* data)
{
- if (data->ag.multi != NULL)
- {
+ if (data->ag.multi != NULL) {
fei->FI_CloseMultiBitmap(data->ag.multi, 0);
data->ag.multi = NULL;
}
- if (data->ag.dib != NULL)
- {
+ if (data->ag.dib != NULL) {
fei->FI_Unload(data->ag.dib);
data->ag.dib = NULL;
}
@@ -331,8 +313,7 @@ void DestroyAnimatedGif(HWND hwnd, ACCData* data) AnimatedGifDeleteTmpValues(data);
- if (data->ag.hbms != NULL)
- {
+ if (data->ag.hbms != NULL) {
for (int i = 0; i < data->ag.frameCount; i++)
if (data->ag.hbms[i] != NULL)
DeleteObject(data->ag.hbms[i]);
@@ -341,8 +322,7 @@ void DestroyAnimatedGif(HWND hwnd, ACCData* data) data->ag.hbms = NULL;
}
- if (data->ag.times != NULL)
- {
+ if (data->ag.times != NULL) {
free(data->ag.times);
data->ag.times = NULL;
}
@@ -355,13 +335,11 @@ void StartAnimatedGif(HWND hwnd, ACCData* data) if (fei == NULL)
return;
- int x, y;
AVATARCACHEENTRY *ace = NULL;
-
if (data->hContact != NULL)
- ace = (AVATARCACHEENTRY *) GetAvatarBitmap((WPARAM) data->hContact, 0);
+ ace = (AVATARCACHEENTRY*)GetAvatarBitmap(data->hContact, 0);
else
- ace = (AVATARCACHEENTRY *) GetMyAvatar(0, (LPARAM) data->proto);
+ ace = (AVATARCACHEENTRY*)GetMyAvatar(0, (LPARAM)data->proto);
if (ace == NULL)
return;
@@ -385,23 +363,22 @@ void StartAnimatedGif(HWND hwnd, ACCData* data) if (!AnimatedGifGetData(data))
goto ERR;
- //allocate entire logical area
+ // allocate entire logical area
data->ag.dib = fei->FI_Allocate(data->ag.logicalWidth, data->ag.logicalHeight, 32, 0, 0, 0);
if (data->ag.dib == NULL)
goto ERR;
- //fill with background color to start
- for (y = 0; y < data->ag.logicalHeight; y++)
- {
- RGBQUAD *scanline = (RGBQUAD *) fei->FI_GetScanLine(data->ag.dib, y);
- for (x = 0; x < data->ag.logicalWidth; x++)
+ // fill with background color to start
+ for (int y = 0; y < data->ag.logicalHeight; y++) {
+ RGBQUAD *scanline = (RGBQUAD*)fei->FI_GetScanLine(data->ag.dib, y);
+ for (int x = 0; x < data->ag.logicalWidth; x++)
*scanline++ = data->ag.background;
}
- data->ag.hbms = (HBITMAP *) malloc(sizeof(HBITMAP) * data->ag.frameCount);
+ data->ag.hbms = (HBITMAP *)malloc(sizeof(HBITMAP) * data->ag.frameCount);
memset(data->ag.hbms, 0, sizeof(HBITMAP) * data->ag.frameCount);
- data->ag.times = (int *) malloc(sizeof(int) * data->ag.frameCount);
+ data->ag.times = (int *)malloc(sizeof(int) * data->ag.frameCount);
memset(data->ag.times, 0, sizeof(int) * data->ag.frameCount);
AnimatedGifMountFrame(data, 0);
@@ -430,21 +407,17 @@ void StartAnimation(HWND hwnd, ACCData* data) BOOL ScreenToClient(HWND hWnd, LPRECT lpRect)
{
- BOOL ret;
-
POINT pt;
-
pt.x = lpRect->left;
pt.y = lpRect->top;
- ret = ScreenToClient(hWnd, &pt);
-
- if (!ret) return ret;
+ BOOL ret = ScreenToClient(hWnd, &pt);
+ if (!ret)
+ return ret;
lpRect->left = pt.x;
lpRect->top = pt.y;
-
pt.x = lpRect->right;
pt.y = lpRect->bottom;
@@ -452,15 +425,13 @@ BOOL ScreenToClient(HWND hWnd, LPRECT lpRect) lpRect->right = pt.x;
lpRect->bottom = pt.y;
-
return ret;
}
static void Invalidate(HWND hwnd)
{
- ACCData* data = (ACCData *) GetWindowLongPtr(hwnd, 0);
- if (data->bkgColor == -1)
- {
+ ACCData *data = (ACCData*)GetWindowLongPtr(hwnd, 0);
+ if (data->bkgColor == -1) {
HWND parent = GetParent(hwnd);
RECT rc;
GetWindowRect(hwnd, &rc);
@@ -472,12 +443,12 @@ static void Invalidate(HWND hwnd) static void NotifyAvatarChange(HWND hwnd)
{
- PSHNOTIFY pshn = {0};
+ PSHNOTIFY pshn = { 0 };
pshn.hdr.idFrom = GetDlgCtrlID(hwnd);
pshn.hdr.hwndFrom = hwnd;
pshn.hdr.code = NM_AVATAR_CHANGED;
pshn.lParam = 0;
- SendMessage(GetParent(hwnd), WM_NOTIFY, 0, (LPARAM) &pshn);
+ SendMessage(GetParent(hwnd), WM_NOTIFY, 0, (LPARAM)&pshn);
}
static void DrawText(HDC hdc, HFONT hFont, const RECT &rc, const TCHAR *text)
@@ -493,157 +464,141 @@ static void DrawText(HDC hdc, HFONT hFont, const RECT &rc, const TCHAR *text) // Calc text size
RECT tr_ret = tr;
- DrawText(hdc, text, -1, &tr_ret,
- DT_WORDBREAK | DT_NOPREFIX | DT_CENTER | DT_CALCRECT);
+ DrawText(hdc, text, -1, &tr_ret, DT_WORDBREAK | DT_NOPREFIX | DT_CENTER | DT_CALCRECT);
// Calc needed size
tr.top += ((tr.bottom - tr.top) - (tr_ret.bottom - tr_ret.top)) / 2;
tr.bottom = tr.top + (tr_ret.bottom - tr_ret.top);
- DrawText(hdc, text, -1, &tr,
- DT_WORDBREAK | DT_NOPREFIX | DT_CENTER);
+ DrawText(hdc, text, -1, &tr, DT_WORDBREAK | DT_NOPREFIX | DT_CENTER);
SelectObject(hdc, oldFont);
}
-static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
- ACCData* data = (ACCData *) GetWindowLongPtr(hwnd, 0);
- switch(msg)
- {
- case WM_NCCREATE:
- {
- SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | BS_OWNERDRAW);
- SetWindowLongPtr(hwnd, GWL_EXSTYLE, GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_TRANSPARENT);
-
- data = (ACCData*) mir_alloc(sizeof(ACCData));
- if (data == NULL)
- return FALSE;
- SetWindowLongPtr(hwnd, 0, (LONG_PTR)data);
-
- ZeroMemory(data, sizeof(ACCData));
- data->hHook = HookEventMessage(ME_AV_AVATARCHANGED, hwnd, DM_AVATARCHANGED);
- data->hHookMy = HookEventMessage(ME_AV_MYAVATARCHANGED, hwnd, DM_MYAVATARCHANGED);
- data->hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
- data->borderColor = -1;
- data->bkgColor = -1;
- data->avatarBorderColor = -1;
- data->respectHidden = TRUE;
- data->showingFlash = FALSE;
- data->resizeIfSmaller = TRUE;
- data->showingAnimatedGif = FALSE;
- data->fAero = FALSE;
-
- return TRUE;
- }
- case WM_NCDESTROY:
- {
- DestroyAnimation(hwnd, data);
- if (data)
- {
- UnhookEvent(data->hHook);
- UnhookEvent(data->hHookMy);
- mir_free(data);
- }
- SetWindowLongPtr(hwnd, 0, (LONG_PTR)NULL);
- break;
- }
- case WM_SETFONT:
- {
- data->hFont = (HFONT)wParam;
- Invalidate(hwnd);
- break;
+static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ ACCData *data = (ACCData*)GetWindowLongPtr(hwnd, 0);
+
+ switch (msg) {
+ case WM_NCCREATE:
+ SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | BS_OWNERDRAW);
+ SetWindowLongPtr(hwnd, GWL_EXSTYLE, GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_TRANSPARENT);
+
+ data = (ACCData*)mir_alloc(sizeof(ACCData));
+ if (data == NULL)
+ return FALSE;
+ SetWindowLongPtr(hwnd, 0, (LONG_PTR)data);
+
+ ZeroMemory(data, sizeof(ACCData));
+ data->hHook = HookEventMessage(ME_AV_AVATARCHANGED, hwnd, DM_AVATARCHANGED);
+ data->hHookMy = HookEventMessage(ME_AV_MYAVATARCHANGED, hwnd, DM_MYAVATARCHANGED);
+ data->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+ data->borderColor = -1;
+ data->bkgColor = -1;
+ data->avatarBorderColor = -1;
+ data->respectHidden = TRUE;
+ data->showingFlash = FALSE;
+ data->resizeIfSmaller = TRUE;
+ data->showingAnimatedGif = FALSE;
+ data->fAero = FALSE;
+ return TRUE;
+
+ case WM_NCDESTROY:
+ DestroyAnimation(hwnd, data);
+ if (data) {
+ UnhookEvent(data->hHook);
+ UnhookEvent(data->hHookMy);
+ mir_free(data);
}
- case AVATAR_SETCONTACT:
- {
- DestroyAnimation(hwnd, data);
+ SetWindowLongPtr(hwnd, 0, (LONG_PTR)NULL);
+ break;
- data->hContact = lParam;
- if (lParam == NULL)
- data->proto[0] = '\0';
- else
- lstrcpynA(data->proto, GetContactProto(data->hContact), sizeof(data->proto));
+ case WM_SETFONT:
+ data->hFont = (HFONT)wParam;
+ Invalidate(hwnd);
+ break;
- StartAnimation(hwnd, data);
+ case AVATAR_SETCONTACT:
+ DestroyAnimation(hwnd, data);
- NotifyAvatarChange(hwnd);
- Invalidate(hwnd);
- return TRUE;
- }
- case AVATAR_SETPROTOCOL:
- {
- DestroyAnimation(hwnd, data);
-
- data->hContact = NULL;
- if (lParam == NULL)
- data->proto[0] = '\0';
- else
- lstrcpynA(data->proto, (char *) lParam, sizeof(data->proto));
+ data->hContact = lParam;
+ if (lParam == NULL)
+ data->proto[0] = '\0';
+ else
+ lstrcpynA(data->proto, GetContactProto(data->hContact), sizeof(data->proto));
- StartAnimation(hwnd, data);
+ StartAnimation(hwnd, data);
- NotifyAvatarChange(hwnd);
- Invalidate(hwnd);
- return TRUE;
- }
- case AVATAR_SETBKGCOLOR:
- {
- data->bkgColor = (COLORREF) lParam;
- if (data->showingFlash)
- SetBkgFlash(hwnd, data);
- NotifyAvatarChange(hwnd);
- Invalidate(hwnd);
- return TRUE;
- }
- case AVATAR_SETBORDERCOLOR:
- {
- data->borderColor = (COLORREF) lParam;
- if (data->showingFlash)
- ResizeFlash(hwnd, data);
- NotifyAvatarChange(hwnd);
- Invalidate(hwnd);
- return TRUE;
- }
- case AVATAR_SETAVATARBORDERCOLOR:
- {
- data->avatarBorderColor = (COLORREF) lParam;
- if (data->showingFlash)
- ResizeFlash(hwnd, data);
- NotifyAvatarChange(hwnd);
- Invalidate(hwnd);
- return TRUE;
- }
- case AVATAR_SETAVATARROUNDCORNERRADIUS:
- {
- data->avatarRoundCornerRadius = (int) lParam;
- NotifyAvatarChange(hwnd);
- Invalidate(hwnd);
- return TRUE;
- }
- case AVATAR_SETNOAVATARTEXT:
- {
- lstrcpyn(data->noAvatarText, TranslateTS((TCHAR*) lParam), SIZEOF(data->noAvatarText));
- Invalidate(hwnd);
- return TRUE;
- }
- case AVATAR_RESPECTHIDDEN:
- {
- data->respectHidden = (BOOL) lParam;
- NotifyAvatarChange(hwnd);
- Invalidate(hwnd);
- return TRUE;
- }
- case AVATAR_SETRESIZEIFSMALLER:
- {
- data->resizeIfSmaller = (BOOL) lParam;
- NotifyAvatarChange(hwnd);
- Invalidate(hwnd);
- return TRUE;
- }
+ NotifyAvatarChange(hwnd);
+ Invalidate(hwnd);
+ return TRUE;
- case AVATAR_SETAEROCOMPATDRAWING:
- data->fAero = lParam;
- return(TRUE);
+ case AVATAR_SETPROTOCOL:
+ DestroyAnimation(hwnd, data);
- case AVATAR_GETUSEDSPACE:
+ data->hContact = NULL;
+ if (lParam == NULL)
+ data->proto[0] = '\0';
+ else
+ lstrcpynA(data->proto, (char *)lParam, sizeof(data->proto));
+
+ StartAnimation(hwnd, data);
+
+ NotifyAvatarChange(hwnd);
+ Invalidate(hwnd);
+ return TRUE;
+
+ case AVATAR_SETBKGCOLOR:
+ data->bkgColor = (COLORREF)lParam;
+ if (data->showingFlash)
+ SetBkgFlash(hwnd, data);
+ NotifyAvatarChange(hwnd);
+ Invalidate(hwnd);
+ return TRUE;
+
+ case AVATAR_SETBORDERCOLOR:
+ data->borderColor = (COLORREF)lParam;
+ if (data->showingFlash)
+ ResizeFlash(hwnd, data);
+ NotifyAvatarChange(hwnd);
+ Invalidate(hwnd);
+ return TRUE;
+
+ case AVATAR_SETAVATARBORDERCOLOR:
+ data->avatarBorderColor = (COLORREF)lParam;
+ if (data->showingFlash)
+ ResizeFlash(hwnd, data);
+ NotifyAvatarChange(hwnd);
+ Invalidate(hwnd);
+ return TRUE;
+
+ case AVATAR_SETAVATARROUNDCORNERRADIUS:
+ data->avatarRoundCornerRadius = (int)lParam;
+ NotifyAvatarChange(hwnd);
+ Invalidate(hwnd);
+ return TRUE;
+
+ case AVATAR_SETNOAVATARTEXT:
+ lstrcpyn(data->noAvatarText, TranslateTS((TCHAR*)lParam), SIZEOF(data->noAvatarText));
+ Invalidate(hwnd);
+ return TRUE;
+
+ case AVATAR_RESPECTHIDDEN:
+ data->respectHidden = (BOOL)lParam;
+ NotifyAvatarChange(hwnd);
+ Invalidate(hwnd);
+ return TRUE;
+
+ case AVATAR_SETRESIZEIFSMALLER:
+ data->resizeIfSmaller = (BOOL)lParam;
+ NotifyAvatarChange(hwnd);
+ Invalidate(hwnd);
+ return TRUE;
+
+ case AVATAR_SETAEROCOMPATDRAWING:
+ data->fAero = lParam;
+ return(TRUE);
+
+ case AVATAR_GETUSEDSPACE:
{
int *width = (int *)wParam;
int *height = (int *)lParam;
@@ -652,16 +607,14 @@ static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l GetClientRect(hwnd, &rc);
// Get avatar
- if (data->showingFlash && ServiceExists(MS_FAVATAR_GETINFO))
- {
- FLASHAVATAR fa = {0};
+ if (data->showingFlash && ServiceExists(MS_FAVATAR_GETINFO)) {
+ FLASHAVATAR fa = { 0 };
fa.hContact = data->hContact;
fa.cProto = data->proto;
fa.hParentWindow = hwnd;
fa.id = 1675;
CallService(MS_FAVATAR_GETINFO, (WPARAM)&fa, 0);
- if (fa.hWindow != NULL)
- {
+ if (fa.hWindow != NULL) {
*width = rc.right - rc.left;
*height = rc.bottom - rc.top;
return TRUE;
@@ -670,13 +623,12 @@ static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l avatarCacheEntry *ace;
if (data->hContact == NULL)
- ace = (avatarCacheEntry *) CallService(MS_AV_GETMYAVATAR, 0, (LPARAM) data->proto);
+ ace = (avatarCacheEntry *)CallService(MS_AV_GETMYAVATAR, 0, (LPARAM)data->proto);
else
- ace = (avatarCacheEntry *) CallService(MS_AV_GETAVATARBITMAP, (WPARAM) data->hContact, 0);
+ ace = (avatarCacheEntry *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)data->hContact, 0);
if (ace == NULL || ace->bmHeight == 0 || ace->bmWidth == 0
- || (data->respectHidden && (ace->dwFlags & AVS_HIDEONCLIST)))
- {
+ || (data->respectHidden && (ace->dwFlags & AVS_HIDEONCLIST))) {
*width = 0;
*height = 0;
return TRUE;
@@ -686,52 +638,45 @@ static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l int targetWidth = rc.right - rc.left;
int targetHeight = rc.bottom - rc.top;
- if (!data->resizeIfSmaller && ace->bmHeight <= targetHeight && ace->bmWidth <= targetWidth)
- {
+ if (!data->resizeIfSmaller && ace->bmHeight <= targetHeight && ace->bmWidth <= targetWidth) {
*height = ace->bmHeight;
*width = ace->bmWidth;
}
- else if (ace->bmHeight > ace->bmWidth)
- {
+ else if (ace->bmHeight > ace->bmWidth) {
float dScale = targetHeight / (float)ace->bmHeight;
*height = targetHeight;
- *width = (int) (ace->bmWidth * dScale);
+ *width = (int)(ace->bmWidth * dScale);
}
- else
- {
+ else {
float dScale = targetWidth / (float)ace->bmWidth;
- *height = (int) (ace->bmHeight * dScale);
+ *height = (int)(ace->bmHeight * dScale);
*width = targetWidth;
}
-
- return TRUE;
}
- case DM_AVATARCHANGED:
- {
- if (data->hContact == wParam)
- {
- DestroyAnimation(hwnd, data);
- StartAnimation(hwnd, data);
+ return TRUE;
- NotifyAvatarChange(hwnd);
- Invalidate(hwnd);
- }
- break;
+ case DM_AVATARCHANGED:
+ if (data->hContact == wParam) {
+ DestroyAnimation(hwnd, data);
+ StartAnimation(hwnd, data);
+
+ NotifyAvatarChange(hwnd);
+ Invalidate(hwnd);
}
- case DM_MYAVATARCHANGED:
- {
- if (data->hContact == NULL && strcmp(data->proto, (char*) wParam) == 0)
- {
- DestroyAnimation(hwnd, data);
- StartAnimation(hwnd, data);
+ break;
- NotifyAvatarChange(hwnd);
- Invalidate(hwnd);
- }
- break;
+ case DM_MYAVATARCHANGED:
+ if (data->hContact == NULL && strcmp(data->proto, (char*)wParam) == 0) {
+ DestroyAnimation(hwnd, data);
+ StartAnimation(hwnd, data);
+
+ NotifyAvatarChange(hwnd);
+ Invalidate(hwnd);
}
- case WM_NCPAINT:
- case WM_PAINT:
+ break;
+
+ case WM_NCPAINT:
+ case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
@@ -745,27 +690,23 @@ static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l GetClientRect(hwnd, &rc);
// Draw background
- if (data->bkgColor != -1)
- {
+ if (data->bkgColor != -1) {
HBRUSH hbrush = CreateSolidBrush(data->bkgColor);
FillRect(hdc, &rc, hbrush);
DeleteObject(hbrush);
}
if (data->hContact == NULL && data->proto[0] == '\0'
- && db_get_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1))
- {
+ && db_get_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1)) {
DrawText(hdc, data->hFont, rc, TranslateT("Protocols have different avatars"));
}
// Has a flash avatar
- else if (data->showingFlash)
- {
+ else if (data->showingFlash) {
// Don't draw
// Draw control border if needed
- if (data->borderColor == -1 && data->avatarBorderColor != -1)
- {
+ if (data->borderColor == -1 && data->avatarBorderColor != -1) {
HBRUSH hbrush = CreateSolidBrush(data->avatarBorderColor);
FrameRect(hdc, &rc, hbrush);
DeleteObject(hbrush);
@@ -774,10 +715,9 @@ static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l // Has an animated gif
// Has a "normal" image
- else
- {
+ else {
// Draw avatar
- AVATARDRAWREQUEST avdrq = {0};
+ AVATARDRAWREQUEST avdrq = { 0 };
avdrq.cbSize = sizeof(avdrq);
avdrq.rcDraw = rc;
avdrq.hContact = data->hContact;
@@ -794,13 +734,11 @@ static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l avdrq.radius = data->avatarRoundCornerRadius;
INT_PTR ret;
- if (data->showingAnimatedGif)
- {
+ if (data->showingAnimatedGif) {
InternalDrawAvatar(&avdrq, data->ag.hbms[data->ag.frame.num], data->ag.logicalWidth, data->ag.logicalHeight, 0);
ret = 1;
- if (!data->ag.started)
- {
+ if (!data->ag.started) {
SetTimer(hwnd, 0, data->ag.times[data->ag.frame.num], NULL);
data->ag.started = TRUE;
}
@@ -813,8 +751,7 @@ static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l }
// Draw control border
- if (data->borderColor != -1)
- {
+ if (data->borderColor != -1) {
HBRUSH hbrush = CreateSolidBrush(data->borderColor);
FrameRect(hdc, &rc, hbrush);
DeleteObject(hbrush);
@@ -823,79 +760,73 @@ static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l SetBkMode(hdc, oldBkMode);
EndPaint(hwnd, &ps);
- return TRUE;
}
- case WM_ERASEBKGND:
+ return TRUE;
+
+ case WM_ERASEBKGND:
{
- HDC hdc = (HDC) wParam;
+ HDC hdc = (HDC)wParam;
RECT rc;
GetClientRect(hwnd, &rc);
// Draw background
- if (data->bkgColor != -1)
- {
+ if (data->bkgColor != -1) {
HBRUSH hbrush = CreateSolidBrush(data->bkgColor);
FillRect(hdc, &rc, hbrush);
DeleteObject(hbrush);
}
// Draw control border
- if (data->borderColor != -1)
- {
+ if (data->borderColor != -1) {
HBRUSH hbrush = CreateSolidBrush(data->borderColor);
FrameRect(hdc, &rc, hbrush);
DeleteObject(hbrush);
}
-
- return TRUE;
}
- case WM_SIZE:
- {
- if (data->showingFlash)
- ResizeFlash(hwnd, data);
- InvalidateRect(hwnd, NULL, TRUE);
- break;
- }
- case WM_TIMER:
- {
- if (wParam != 0)
- break;
- KillTimer(hwnd, 0);
+ return TRUE;
- if (!data->showingAnimatedGif)
- break;
+ case WM_SIZE:
+ if (data->showingFlash)
+ ResizeFlash(hwnd, data);
+ InvalidateRect(hwnd, NULL, TRUE);
+ break;
- AnimatedGifDispodeFrame(data);
+ case WM_TIMER:
+ if (wParam != 0)
+ break;
+ KillTimer(hwnd, 0);
- int frame = data->ag.frame.num + 1;
- if (frame >= data->ag.frameCount)
- {
- // Don't need fi data no more
- AnimatedGifDeleteTmpValues(data);
- frame = 0;
- }
- AnimatedGifMountFrame(data, frame);
+ if (!data->showingAnimatedGif)
+ break;
- data->ag.started = FALSE;
- InvalidateRect(hwnd, NULL, FALSE);
+ AnimatedGifDispodeFrame(data);
- break;
+ int frame = data->ag.frame.num + 1;
+ if (frame >= data->ag.frameCount) {
+ // Don't need fi data no more
+ AnimatedGifDeleteTmpValues(data);
+ frame = 0;
}
+ AnimatedGifMountFrame(data, frame);
+
+ data->ag.started = FALSE;
+ InvalidateRect(hwnd, NULL, FALSE);
+
+ break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
-
int LoadACC()
{
- WNDCLASSEX wc = {0};
- wc.cbSize = sizeof(wc);
- wc.lpszClassName = AVATAR_CONTROL_CLASS;
- wc.lpfnWndProc = ACCWndProc;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.cbWndExtra = sizeof(ACCData*);
- wc.hbrBackground = 0;
- wc.style = CS_GLOBALCLASS;
+ WNDCLASSEX wc = { 0 };
+ wc.cbSize = sizeof(wc);
+ wc.lpszClassName = AVATAR_CONTROL_CLASS;
+ wc.lpfnWndProc = ACCWndProc;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.cbWndExtra = sizeof(ACCData*);
+ wc.hbrBackground = 0;
+ wc.style = CS_GLOBALCLASS;
RegisterClassEx(&wc);
return 0;
}
diff --git a/plugins/AVS/src/cache.cpp b/plugins/AVS/src/cache.cpp index e12d979091..ead84e1aa8 100644 --- a/plugins/AVS/src/cache.cpp +++ b/plugins/AVS/src/cache.cpp @@ -23,12 +23,10 @@ static int g_maxBlock = 0, g_curBlock = 0; static CacheNode **g_cacheBlocks = NULL;
static CacheNode *g_Cache = 0;
-static CRITICAL_SECTION cachecs, alloccs;
+static mir_cs alloccs, cachecs;
-/*
- * allocate a cache block and add it to the list of blocks
- * does not link the new block with the old block(s) - caller needs to do this
- */
+// allocate a cache block and add it to the list of blocks
+// does not link the new block with the old block(s) - caller needs to do this
static CacheNode* AllocCacheBlock()
{
@@ -42,7 +40,6 @@ static CacheNode* AllocCacheBlock() g_Cache = allocedBlock;
// add it to the list of blocks
-
if (g_curBlock == g_maxBlock) {
g_maxBlock += 10;
g_cacheBlocks = (CacheNode**)realloc(g_cacheBlocks, g_maxBlock * sizeof(CacheNode*));
@@ -54,8 +51,6 @@ static CacheNode* AllocCacheBlock() void InitCache(void)
{
- InitializeCriticalSection(&cachecs);
- InitializeCriticalSection(&alloccs);
AllocCacheBlock();
}
@@ -68,20 +63,14 @@ void UnloadCache(void) for (int i = 0; i < g_curBlock; i++)
free(g_cacheBlocks[i]);
free(g_cacheBlocks);
-
- DeleteCriticalSection(&alloccs);
- DeleteCriticalSection(&cachecs);
}
-/*
- * link a new cache block with the already existing chain of blocks
- */
+// link a new cache block with the already existing chain of blocks
static CacheNode* AddToList(CacheNode *node)
{
CacheNode *pCurrent = g_Cache;
-
- while(pCurrent->pNextNode != 0)
+ while (pCurrent->pNextNode != 0)
pCurrent = pCurrent->pNextNode;
pCurrent->pNextNode = node;
@@ -100,7 +89,7 @@ CacheNode* FindAvatarInCache(MCONTACT hContact, BOOL add, BOOL findAny) mir_cslock lck(cachecs);
CacheNode *cc = g_Cache, *foundNode = NULL;
- while(cc) {
+ while (cc) {
if (cc->ace.hContact == hContact) {
cc->ace.t_lastAccess = time(NULL);
foundNode = cc->loaded || findAny ? cc : NULL;
@@ -132,14 +121,12 @@ CacheNode* FindAvatarInCache(MCONTACT hContact, BOOL add, BOOL findAny) return NULL;
}
-/*
- * output a notification message.
- * may accept a hContact to include the contacts nickname in the notification message...
- * the actual message is using printf() rules for formatting and passing the arguments...
- *
- * can display the message either as systray notification (baloon popup) or using the
- * popup plugin.
- */
+// output a notification message.
+// may accept a hContact to include the contacts nickname in the notification message...
+// the actual message is using printf() rules for formatting and passing the arguments...
+//
+// can display the message either as systray notification (baloon popup) or using the
+// popup plugin.
void NotifyMetaAware(MCONTACT hContact, CacheNode *node = NULL, AVATARCACHEENTRY *ace = (AVATARCACHEENTRY*)-1)
{
@@ -159,7 +146,7 @@ void NotifyMetaAware(MCONTACT hContact, CacheNode *node = NULL, AVATARCACHEENTRY // Fire the event for avatar history
node->dwFlags &= ~AVH_MUSTNOTIFY;
if (node->ace.szFilename[0] != '\0') {
- CONTACTAVATARCHANGEDNOTIFICATION cacn = {0};
+ CONTACTAVATARCHANGEDNOTIFICATION cacn = { 0 };
cacn.cbSize = sizeof(CONTACTAVATARCHANGEDNOTIFICATION);
cacn.hContact = hContact;
cacn.format = node->pa_format;
@@ -191,10 +178,10 @@ void NotifyMetaAware(MCONTACT hContact, CacheNode *node = NULL, AVATARCACHEENTRY }
}
-
// Just delete an avatar from cache
// An cache entry is never deleted. What is deleted is the image handle inside it
// This is done this way to keep track of which avatars avs have to keep track
+
void DeleteAvatarFromCache(MCONTACT hContact, BOOL forever)
{
if (g_shutDown)
@@ -233,11 +220,9 @@ int SetAvatarAttribute(MCONTACT hContact, DWORD attrib, int mode) return 0;
}
-/*
- * this thread scans the cache and handles nodes which have mustLoad set to > 0 (must be loaded/reloaded) or
- * nodes where mustLoad is < 0 (must be deleted).
- * its waken up by the event and tries to lock the cache only when absolutely necessary.
- */
+// this thread scans the cache and handles nodes which have mustLoad set to > 0 (must be loaded/reloaded) or
+// nodes where mustLoad is < 0 (must be deleted).
+// its waken up by the event and tries to lock the cache only when absolutely necessary.
void PicLoader(LPVOID param)
{
@@ -273,23 +258,23 @@ void PicLoader(LPVOID param) if (result == 1 && ace_temp.hbmPic != 0) { // Loaded
HBITMAP oldPic = node->ace.hbmPic;
-
- EnterCriticalSection(&cachecs);
- CopyMemory(&node->ace, &ace_temp, sizeof(AVATARCACHEENTRY));
- node->loaded = TRUE;
- LeaveCriticalSection(&cachecs);
+ {
+ mir_cslock l(cachecs);
+ CopyMemory(&node->ace, &ace_temp, sizeof(AVATARCACHEENTRY));
+ node->loaded = TRUE;
+ }
if (oldPic)
DeleteObject(oldPic);
NotifyMetaAware(node->ace.hContact, node);
}
else if (result == 0 || result == -3) { // Has no avatar
HBITMAP oldPic = node->ace.hbmPic;
-
- EnterCriticalSection(&cachecs);
- CopyMemory(&node->ace, &ace_temp, sizeof(AVATARCACHEENTRY));
- node->loaded = FALSE;
- node->mustLoad = 0;
- LeaveCriticalSection(&cachecs);
+ {
+ mir_cslock l(cachecs);
+ CopyMemory(&node->ace, &ace_temp, sizeof(AVATARCACHEENTRY));
+ node->loaded = FALSE;
+ node->mustLoad = 0;
+ }
if (oldPic)
DeleteObject(oldPic);
NotifyMetaAware(node->ace.hContact, node);
@@ -299,28 +284,27 @@ void PicLoader(LPVOID param) }
else if (node->mustLoad < 0 && node->ace.hContact) { // delete this picture
MCONTACT hContact = node->ace.hContact;
- EnterCriticalSection(&cachecs);
- node->mustLoad = 0;
- node->loaded = 0;
- if (node->ace.hbmPic)
- DeleteObject(node->ace.hbmPic);
- ZeroMemory(&node->ace, sizeof(AVATARCACHEENTRY));
- if (node->dwFlags & AVS_DELETENODEFOREVER)
- node->dwFlags &= ~AVS_DELETENODEFOREVER;
- else
- node->ace.hContact = hContact;
-
- LeaveCriticalSection(&cachecs);
+ {
+ mir_cslock l(cachecs);
+ node->mustLoad = 0;
+ node->loaded = 0;
+ if (node->ace.hbmPic)
+ DeleteObject(node->ace.hbmPic);
+ ZeroMemory(&node->ace, sizeof(AVATARCACHEENTRY));
+ if (node->dwFlags & AVS_DELETENODEFOREVER)
+ node->dwFlags &= ~AVS_DELETENODEFOREVER;
+ else
+ node->ace.hContact = hContact;
+ }
NotifyMetaAware(hContact, node, (AVATARCACHEENTRY *)GetProtoDefaultAvatar(hContact));
}
+
// protect this by changes from the cache block allocator as it can cause inconsistencies while working
// on allocating a new block.
- EnterCriticalSection(&alloccs);
+ mir_cslock all(alloccs); // protect memory block allocation
node = node->pNextNode;
- LeaveCriticalSection(&alloccs);
}
WaitForSingleObject(hLoaderEvent, INFINITE);
- //_DebugTrace(0, "pic loader awake...");
ResetEvent(hLoaderEvent);
}
}
diff --git a/plugins/AVS/src/commonheaders.h b/plugins/AVS/src/commonheaders.h index 87f8044d8d..a84d746d3a 100644 --- a/plugins/AVS/src/commonheaders.h +++ b/plugins/AVS/src/commonheaders.h @@ -44,6 +44,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <m_metacontacts.h>
#include <m_avatarhistory.h>
#include <m_flash.h>
+#include <m_clistint.h>
#include "resource.h"
#include "version.h"
diff --git a/plugins/AVS/src/image_utils.cpp b/plugins/AVS/src/image_utils.cpp index 3a2fa368af..ece646fd63 100644 --- a/plugins/AVS/src/image_utils.cpp +++ b/plugins/AVS/src/image_utils.cpp @@ -1,9 +1,6 @@ #include "commonheaders.h"
#include "image_utils.h"
-extern int _DebugTrace(const char *fmt, ...);
-extern int _DebugTrace(MCONTACT hContact, const char *fmt, ...);
-
#define GET_PIXEL(__P__, __X__, __Y__) ( __P__ + width * 4 * (__Y__) + 4 * (__X__))
// Make a bitmap all transparent, but only if it is a 32bpp
@@ -26,11 +23,11 @@ void MakeBmpTransparent(HBITMAP hBitmap) }
// Resize /////////////////////////////////////////////////////////////////////////////////////////
-
// Returns a copy of the bitmap with the size especified
// wParam = ResizeBitmap *
// lParam = NULL
-INT_PTR BmpFilterResizeBitmap(WPARAM wParam,LPARAM lParam)
+
+INT_PTR BmpFilterResizeBitmap(WPARAM wParam, LPARAM lParam)
{
// Call freeiamge service (is here only for backward compatibility)
return CallService(MS_IMG_RESIZE, wParam, lParam);
@@ -38,22 +35,16 @@ INT_PTR BmpFilterResizeBitmap(WPARAM wParam,LPARAM lParam) HBITMAP CopyBitmapTo32(HBITMAP hBitmap)
{
- BITMAPINFO RGB32BitsBITMAPINFO;
- BYTE * ptPixels;
- HBITMAP hDirectBitmap;
-
BITMAP bmp;
- DWORD dwLen;
- BYTE *p;
-
GetObject(hBitmap, sizeof(bmp), &bmp);
- dwLen = bmp.bmWidth * bmp.bmHeight * 4;
- p = (BYTE *)malloc(dwLen);
+ DWORD dwLen = bmp.bmWidth * bmp.bmHeight * 4;
+ BYTE *p = (BYTE *)malloc(dwLen);
if (p == NULL)
return NULL;
// Create bitmap
+ BITMAPINFO RGB32BitsBITMAPINFO;
ZeroMemory(&RGB32BitsBITMAPINFO, sizeof(BITMAPINFO));
RGB32BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RGB32BitsBITMAPINFO.bmiHeader.biWidth = bmp.bmWidth;
@@ -61,23 +52,16 @@ HBITMAP CopyBitmapTo32(HBITMAP hBitmap) RGB32BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB32BitsBITMAPINFO.bmiHeader.biBitCount = 32;
- hDirectBitmap = CreateDIBSection(NULL,
- (BITMAPINFO *)&RGB32BitsBITMAPINFO,
- DIB_RGB_COLORS,
- (void **)&ptPixels,
- NULL, 0);
+ BYTE *ptPixels;
+ HBITMAP hDirectBitmap = CreateDIBSection(NULL, (BITMAPINFO *)&RGB32BitsBITMAPINFO, DIB_RGB_COLORS, (void **)&ptPixels, NULL, 0);
// Copy data
- if (bmp.bmBitsPixel != 32)
- {
- HDC hdcOrig, hdcDest;
- HBITMAP oldOrig, oldDest;
-
- hdcOrig = CreateCompatibleDC(NULL);
- oldOrig = (HBITMAP) SelectObject(hdcOrig, hBitmap);
+ if (bmp.bmBitsPixel != 32) {
+ HDC hdcOrig = CreateCompatibleDC(NULL);
+ HBITMAP oldOrig = (HBITMAP)SelectObject(hdcOrig, hBitmap);
- hdcDest = CreateCompatibleDC(NULL);
- oldDest = (HBITMAP) SelectObject(hdcDest, hDirectBitmap);
+ HDC hdcDest = CreateCompatibleDC(NULL);
+ HBITMAP oldDest = (HBITMAP)SelectObject(hdcDest, hDirectBitmap);
BitBlt(hdcDest, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcOrig, 0, 0, SRCCOPY);
@@ -89,8 +73,7 @@ HBITMAP CopyBitmapTo32(HBITMAP hBitmap) // Set alpha
fei->FI_CorrectBitmap32Alpha(hDirectBitmap, FALSE);
}
- else
- {
+ else {
GetBitmapBits(hBitmap, dwLen, p);
SetBitmapBits(hDirectBitmap, dwLen, p);
}
@@ -103,39 +86,28 @@ HBITMAP CopyBitmapTo32(HBITMAP hBitmap) HBITMAP CreateBitmap32(int cx, int cy)
{
BITMAPINFO RGB32BitsBITMAPINFO;
- UINT * ptPixels;
- HBITMAP DirectBitmap;
-
- ZeroMemory(&RGB32BitsBITMAPINFO,sizeof(BITMAPINFO));
- RGB32BitsBITMAPINFO.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
- RGB32BitsBITMAPINFO.bmiHeader.biWidth=cx;//bm.bmWidth;
- RGB32BitsBITMAPINFO.bmiHeader.biHeight=cy;//bm.bmHeight;
- RGB32BitsBITMAPINFO.bmiHeader.biPlanes=1;
- RGB32BitsBITMAPINFO.bmiHeader.biBitCount=32;
-
- DirectBitmap = CreateDIBSection(NULL,
- (BITMAPINFO *)&RGB32BitsBITMAPINFO,
- DIB_RGB_COLORS,
- (void **)&ptPixels,
- NULL, 0);
- return DirectBitmap;
+ ZeroMemory(&RGB32BitsBITMAPINFO, sizeof(BITMAPINFO));
+ RGB32BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ RGB32BitsBITMAPINFO.bmiHeader.biWidth = cx;//bm.bmWidth;
+ RGB32BitsBITMAPINFO.bmiHeader.biHeight = cy;//bm.bmHeight;
+ RGB32BitsBITMAPINFO.bmiHeader.biPlanes = 1;
+ RGB32BitsBITMAPINFO.bmiHeader.biBitCount = 32;
+
+ UINT *ptPixels;
+ return CreateDIBSection(NULL, (BITMAPINFO *)&RGB32BitsBITMAPINFO, DIB_RGB_COLORS, (void **)&ptPixels, NULL, 0);
}
// Set the color of points that are transparent
void SetTranspBkgColor(HBITMAP hBitmap, COLORREF color)
{
BITMAP bmp;
- DWORD dwLen;
- BYTE *p;
- int x, y;
-
GetObject(hBitmap, sizeof(bmp), &bmp);
if (bmp.bmBitsPixel != 32)
return;
- dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
- p = (BYTE *)malloc(dwLen);
+ DWORD dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
+ BYTE *p = (BYTE *)malloc(dwLen);
if (p == NULL)
return;
memset(p, 0, dwLen);
@@ -143,13 +115,11 @@ void SetTranspBkgColor(HBITMAP hBitmap, COLORREF color) GetBitmapBits(hBitmap, dwLen, p);
bool changed = false;
- for (y = 0; y < bmp.bmHeight; ++y) {
+ for (int y = 0; y < bmp.bmHeight; ++y) {
BYTE *px = p + bmp.bmWidth * 4 * y;
- for (x = 0; x < bmp.bmWidth; ++x)
- {
- if (px[3] == 0)
- {
+ for (int x = 0; x < bmp.bmWidth; ++x) {
+ if (px[3] == 0) {
px[0] = GetBValue(color);
px[1] = GetGValue(color);
px[2] = GetRValue(color);
@@ -172,52 +142,47 @@ void SetHIMETRICtoDP(HDC hdc, SIZE* sz) {
POINT pt;
int nMapMode = GetMapMode(hdc);
- if ( nMapMode < MM_ISOTROPIC && nMapMode != MM_TEXT )
- {
+ if (nMapMode < MM_ISOTROPIC && nMapMode != MM_TEXT) {
// when using a constrained map mode, map against physical inch
- SetMapMode(hdc,MM_HIMETRIC);
+ SetMapMode(hdc, MM_HIMETRIC);
pt.x = sz->cx;
pt.y = sz->cy;
- LPtoDP(hdc,&pt,1);
+ LPtoDP(hdc, &pt, 1);
sz->cx = pt.x;
sz->cy = pt.y;
SetMapMode(hdc, nMapMode);
}
- else
- {
+ else {
// map against logical inch for non-constrained mapping modes
int cxPerInch, cyPerInch;
- cxPerInch = GetDeviceCaps(hdc,LOGPIXELSX);
- cyPerInch = GetDeviceCaps(hdc,LOGPIXELSY);
+ cxPerInch = GetDeviceCaps(hdc, LOGPIXELSX);
+ cyPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
sz->cx = MulDiv(sz->cx, cxPerInch, HIMETRIC_INCH);
sz->cy = MulDiv(sz->cy, cyPerInch, HIMETRIC_INCH);
}
pt.x = sz->cx;
pt.y = sz->cy;
- DPtoLP(hdc,&pt,1);
+ DPtoLP(hdc, &pt, 1);
sz->cx = pt.x;
sz->cy = pt.y;
}
-INT_PTR BmpFilterLoadBitmap32(WPARAM wParam,LPARAM lParam)
+INT_PTR BmpFilterLoadBitmap32(WPARAM wParam, LPARAM lParam)
{
- FIBITMAP *dib32 = NULL;
-
if (fei == NULL)
return 0;
- FIBITMAP *dib = (FIBITMAP *)CallService(MS_IMG_LOAD, lParam, IMGL_RETURNDIB|IMGL_TCHAR);
-
+ FIBITMAP *dib = (FIBITMAP *)CallService(MS_IMG_LOAD, lParam, IMGL_RETURNDIB | IMGL_TCHAR);
if (dib == NULL)
return 0;
+ FIBITMAP *dib32 = NULL;
if (fei->FI_GetBPP(dib) != 32) {
dib32 = fei->FI_ConvertTo32Bits(dib);
fei->FI_Unload(dib);
}
- else
- dib32 = dib;
+ else dib32 = dib;
if (dib32) {
if (fei->FI_IsTransparent(dib32)) {
@@ -252,62 +217,62 @@ static HWND hwndClui = 0; int BmpFilterSaveBitmap(HBITMAP hBmp, char *szFile, int flags)
{
- IMGSRVC_INFO i = {0};
+ IMGSRVC_INFO i = { 0 };
i.cbSize = sizeof(IMGSRVC_INFO);
i.szName = szFile;
i.hbm = hBmp;
i.dwMask = IMGI_HBITMAP;
i.fif = FIF_UNKNOWN;
- return !CallService(MS_IMG_SAVE, (WPARAM) &i, MAKELONG(0, flags));
+ return !CallService(MS_IMG_SAVE, (WPARAM)&i, MAKELONG(0, flags));
}
int BmpFilterSaveBitmapW(HBITMAP hBmp, wchar_t *wszFile, int flags)
{
- IMGSRVC_INFO i = {0};
+ IMGSRVC_INFO i = { 0 };
i.cbSize = sizeof(IMGSRVC_INFO);
i.wszName = wszFile;
i.hbm = hBmp;
i.dwMask = IMGI_HBITMAP;
i.fif = FIF_UNKNOWN;
- return !CallService(MS_IMG_SAVE, (WPARAM) &i, MAKELONG(IMGL_WCHAR, flags));
+ return !CallService(MS_IMG_SAVE, (WPARAM)&i, MAKELONG(IMGL_WCHAR, flags));
}
// Save an HBITMAP to an image
// wParam = HBITMAP
// lParam = filename
-INT_PTR BmpFilterSaveBitmap(WPARAM wParam,LPARAM lParam)
+INT_PTR BmpFilterSaveBitmap(WPARAM wParam, LPARAM lParam)
{
- if ( fei == NULL )
+ if (fei == NULL)
return -1;
const char *szFile = (const char*)lParam;
char szFilename[MAX_PATH];
- if ( !PathToAbsolute(szFile, szFilename))
+ if (!PathToAbsolute(szFile, szFilename))
mir_snprintf(szFilename, SIZEOF(szFilename), "%s", szFile);
- int filenameLen = lstrlenA( szFilename );
- if ( filenameLen > 4 )
- return BmpFilterSaveBitmap(( HBITMAP )wParam, szFilename, 0);
+ int filenameLen = lstrlenA(szFilename);
+ if (filenameLen > 4)
+ return BmpFilterSaveBitmap((HBITMAP)wParam, szFilename, 0);
return -1;
}
-INT_PTR BmpFilterSaveBitmapW(WPARAM wParam,LPARAM lParam)
+INT_PTR BmpFilterSaveBitmapW(WPARAM wParam, LPARAM lParam)
{
- if ( fei == NULL )
+ if (fei == NULL)
return -1;
const wchar_t *wszFile = (const wchar_t *)lParam;
wchar_t wszFilename[MAX_PATH];
- if ( !PathToAbsoluteW(wszFile, wszFilename))
+ if (!PathToAbsoluteW(wszFile, wszFilename))
mir_sntprintf(wszFilename, SIZEOF(wszFilename), _T("%s"), wszFile);
- int filenameLen = lstrlenW( wszFilename );
- if ( filenameLen > 4 )
- return BmpFilterSaveBitmapW(( HBITMAP )wParam, wszFilename, 0 );
+ int filenameLen = lstrlenW(wszFilename);
+ if (filenameLen > 4)
+ return BmpFilterSaveBitmapW((HBITMAP)wParam, wszFilename, 0);
return -1;
}
@@ -317,33 +282,26 @@ INT_PTR BmpFilterSaveBitmapW(WPARAM wParam,LPARAM lParam) // lParam = PA_FORMAT_* // image format
// kept for compatibilty - with freeimage we can save all common formats
-INT_PTR BmpFilterCanSaveBitmap(WPARAM wParam,LPARAM lParam)
+INT_PTR BmpFilterCanSaveBitmap(WPARAM wParam, LPARAM lParam)
{
return 1;
}
-
// Other utilities ////////////////////////////////////////////////////////////////////////////////
-
static BOOL ColorsAreTheSame(int colorDiff, BYTE *px1, BYTE *px2)
{
return abs(px1[0] - px2[0]) <= colorDiff
- && abs(px1[1] - px2[1]) <= colorDiff
- && abs(px1[2] - px2[2]) <= colorDiff;
+ && abs(px1[1] - px2[1]) <= colorDiff
+ && abs(px1[2] - px2[2]) <= colorDiff;
}
-
void AddToStack(int *stack, int *topPos, int x, int y)
{
- int i;
-
// Already is in stack?
- for (i = 0 ; i < *topPos ; i += 2)
- {
- if (stack[i] == x && stack[i+1] == y)
+ for (int i = 0; i < *topPos; i += 2)
+ if (stack[i] == x && stack[i + 1] == y)
return;
- }
stack[*topPos] = x;
(*topPos)++;
@@ -352,15 +310,12 @@ void AddToStack(int *stack, int *topPos, int x, int y) (*topPos)++;
}
-
BOOL GetColorForPoint(int colorDiff, BYTE *p, int width, int height,
- int x0, int y0, int x1, int y1, int x2, int y2, BOOL *foundBkg, BYTE colors[][3])
+ int x0, int y0, int x1, int y1, int x2, int y2, BOOL *foundBkg, BYTE colors[][3])
{
- BYTE *px1, *px2, *px3;
-
- px1 = GET_PIXEL(p, x0,y0);
- px2 = GET_PIXEL(p, x1,y1);
- px3 = GET_PIXEL(p, x2,y2);
+ BYTE *px1 = GET_PIXEL(p, x0, y0);
+ BYTE *px2 = GET_PIXEL(p, x1, y1);
+ BYTE *px3 = GET_PIXEL(p, x2, y2);
// If any of the corners have transparency, forget about it
// Not using != 255 because some MSN bmps have 254 in some positions
@@ -368,15 +323,11 @@ BOOL GetColorForPoint(int colorDiff, BYTE *p, int width, int height, return FALSE;
// See if is the same color
- if (ColorsAreTheSame(colorDiff, px1, px2) && ColorsAreTheSame(colorDiff, px3, px2))
- {
+ if (ColorsAreTheSame(colorDiff, px1, px2) && ColorsAreTheSame(colorDiff, px3, px2)) {
*foundBkg = TRUE;
memmove(colors, px1, 3);
}
- else
- {
- *foundBkg = FALSE;
- }
+ else *foundBkg = FALSE;
return TRUE;
}
@@ -385,13 +336,10 @@ BOOL GetColorForPoint(int colorDiff, BYTE *p, int width, int height, DWORD GetImgHash(HBITMAP hBitmap)
{
BITMAP bmp;
- DWORD dwLen;
- WORD *p;
-
GetObject(hBitmap, sizeof(bmp), &bmp);
- dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
- p = (WORD *)malloc(dwLen);
+ DWORD dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
+ WORD *p = (WORD *)malloc(dwLen);
if (p == NULL)
return 0;
memset(p, 0, dwLen);
@@ -399,7 +347,7 @@ DWORD GetImgHash(HBITMAP hBitmap) GetBitmapBits(hBitmap, dwLen, p);
DWORD ret = 0;
- for (DWORD i = 0 ; i < dwLen/2 ; i++)
+ for (DWORD i = 0; i < dwLen / 2; i++)
ret += p[i];
free(p);
@@ -414,7 +362,6 @@ HBITMAP MakeGrayscale(MCONTACT hContact, HBITMAP hBitmap) {
if (hBitmap) {
FIBITMAP *dib = fei->FI_CreateDIBFromHBITMAP(hBitmap);
-
if (dib) {
FIBITMAP *dib_new = fei->FI_ConvertToGreyscale(dib);
fei->FI_Unload(dib);
@@ -435,153 +382,126 @@ HBITMAP MakeGrayscale(MCONTACT hContact, HBITMAP hBitmap) */
BOOL MakeTransparentBkg(MCONTACT hContact, HBITMAP *hBitmap)
{
- BYTE *p = NULL;
- DWORD dwLen;
- int width, height, i, j;
- BITMAP bmp;
- BYTE colors[8][3];
- BOOL foundBkg[8];
- BYTE *px1;
- int count, maxCount, selectedColor;
- HBITMAP hBmpTmp;
- int colorDiff;
+ int i, j;
+ BITMAP bmp;
GetObject(*hBitmap, sizeof(bmp), &bmp);
- width = bmp.bmWidth;
- height = bmp.bmHeight;
- colorDiff = db_get_w(hContact, "ContactPhoto", "TranspBkgColorDiff",
- db_get_w(0, AVS_MODULE, "TranspBkgColorDiff", 10));
+ int width = bmp.bmWidth;
+ int height = bmp.bmHeight;
+ int colorDiff = db_get_w(hContact, "ContactPhoto", "TranspBkgColorDiff", db_get_w(0, AVS_MODULE, "TranspBkgColorDiff", 10));
// Min 5x5 to easy things in loop
if (width <= 4 || height <= 4)
return FALSE;
- dwLen = width * height * 4;
- p = (BYTE *)malloc(dwLen);
+ DWORD dwLen = width * height * 4;
+ BYTE *p = (BYTE *)malloc(dwLen);
if (p == NULL)
- {
return FALSE;
- }
+ HBITMAP hBmpTmp;
if (bmp.bmBitsPixel == 32)
- {
hBmpTmp = *hBitmap;
- }
- else
- {
- // Convert to 32 bpp
+ else // Convert to 32 bpp
hBmpTmp = CopyBitmapTo32(*hBitmap);
- }
GetBitmapBits(hBmpTmp, dwLen, p);
// **** Get corner colors
// Top left
- if (!GetColorForPoint(colorDiff, p, width, height,
- 0, 0, 0, 1, 1, 0, &foundBkg[0], &colors[0]))
- {
- if (hBmpTmp != *hBitmap) DeleteObject(hBmpTmp);
+ BYTE colors[8][3];
+ BOOL foundBkg[8];
+ if (!GetColorForPoint(colorDiff, p, width, height, 0, 0, 0, 1, 1, 0, &foundBkg[0], &colors[0])) {
+ if (hBmpTmp != *hBitmap)
+ DeleteObject(hBmpTmp);
free(p);
return FALSE;
}
// Top center
- if (!GetColorForPoint(colorDiff, p, width, height,
- width/2, 0, width/2-1, 0, width/2+1, 0, &foundBkg[1], &colors[1]))
- {
- if (hBmpTmp != *hBitmap) DeleteObject(hBmpTmp);
+ if (!GetColorForPoint(colorDiff, p, width, height, width / 2, 0, width / 2 - 1, 0, width / 2 + 1, 0, &foundBkg[1], &colors[1])) {
+ if (hBmpTmp != *hBitmap)
+ DeleteObject(hBmpTmp);
free(p);
return FALSE;
}
// Top Right
if (!GetColorForPoint(colorDiff, p, width, height,
- width-1, 0, width-1, 1, width-2, 0, &foundBkg[2], &colors[2]))
- {
- if (hBmpTmp != *hBitmap) DeleteObject(hBmpTmp);
+ width - 1, 0, width - 1, 1, width - 2, 0, &foundBkg[2], &colors[2])) {
+ if (hBmpTmp != *hBitmap)
+ DeleteObject(hBmpTmp);
free(p);
return FALSE;
}
// Center left
- if (!GetColorForPoint(colorDiff, p, width, height,
- 0, height/2, 0, height/2-1, 0, height/2+1, &foundBkg[3], &colors[3]))
- {
- if (hBmpTmp != *hBitmap) DeleteObject(hBmpTmp);
+ if (!GetColorForPoint(colorDiff, p, width, height, 0, height / 2, 0, height / 2 - 1, 0, height / 2 + 1, &foundBkg[3], &colors[3])) {
+ if (hBmpTmp != *hBitmap)
+ DeleteObject(hBmpTmp);
free(p);
return FALSE;
}
// Center left
- if (!GetColorForPoint(colorDiff, p, width, height,
- width-1, height/2, width-1, height/2-1, width-1, height/2+1, &foundBkg[4], &colors[4]))
- {
- if (hBmpTmp != *hBitmap) DeleteObject(hBmpTmp);
+ if (!GetColorForPoint(colorDiff, p, width, height, width - 1, height / 2, width - 1, height / 2 - 1, width - 1, height / 2 + 1, &foundBkg[4], &colors[4])) {
+ if (hBmpTmp != *hBitmap)
+ DeleteObject(hBmpTmp);
free(p);
return FALSE;
}
// Bottom left
- if (!GetColorForPoint(colorDiff, p, width, height,
- 0, height-1, 0, height-2, 1, height-1, &foundBkg[5], &colors[5]))
- {
- if (hBmpTmp != *hBitmap) DeleteObject(hBmpTmp);
+ if (!GetColorForPoint(colorDiff, p, width, height, 0, height - 1, 0, height - 2, 1, height - 1, &foundBkg[5], &colors[5])) {
+ if (hBmpTmp != *hBitmap)
+ DeleteObject(hBmpTmp);
free(p);
return FALSE;
}
// Bottom center
- if (!GetColorForPoint(colorDiff, p, width, height,
- width/2, height-1, width/2-1, height-1, width/2+1, height-1, &foundBkg[6], &colors[6]))
- {
- if (hBmpTmp != *hBitmap) DeleteObject(hBmpTmp);
+ if (!GetColorForPoint(colorDiff, p, width, height, width / 2, height - 1, width / 2 - 1, height - 1, width / 2 + 1, height - 1, &foundBkg[6], &colors[6])) {
+ if (hBmpTmp != *hBitmap)
+ DeleteObject(hBmpTmp);
free(p);
return FALSE;
}
// Bottom Right
- if (!GetColorForPoint(colorDiff, p, width, height,
- width-1, height-1, width-1, height-2, width-2, height-1, &foundBkg[7], &colors[7]))
- {
- if (hBmpTmp != *hBitmap) DeleteObject(hBmpTmp);
+ if (!GetColorForPoint(colorDiff, p, width, height, width - 1, height - 1, width - 1, height - 2, width - 2, height - 1, &foundBkg[7], &colors[7])) {
+ if (hBmpTmp != *hBitmap)
+ DeleteObject(hBmpTmp);
free(p);
return FALSE;
}
// **** X corners have to have the same color
- count = 0;
- for (i = 0 ; i < 8 ; i++)
- {
+ int count = 0;
+ for (i = 0; i < 8; i++)
if (foundBkg[i])
count++;
- }
- if (count < db_get_w(hContact, "ContactPhoto", "TranspBkgNumPoints",
- db_get_w(0, AVS_MODULE, "TranspBkgNumPoints", 5)))
- {
- if (hBmpTmp != *hBitmap) DeleteObject(hBmpTmp);
+ if (count < db_get_w(hContact, "ContactPhoto", "TranspBkgNumPoints", db_get_w(0, AVS_MODULE, "TranspBkgNumPoints", 5))) {
+ if (hBmpTmp != *hBitmap)
+ DeleteObject(hBmpTmp);
free(p);
return FALSE;
}
// Ok, X corners at least have a color, lets compare then
- maxCount = 0;
- for (i = 0 ; i < 8 ; i++)
- {
- if (foundBkg[i])
- {
+ int maxCount = 0, selectedColor;
+ for (i = 0; i < 8; i++) {
+ if (foundBkg[i]) {
count = 0;
- for (j = 0 ; j < 8 ; j++)
- {
- if (foundBkg[j] && ColorsAreTheSame(colorDiff, (BYTE *) &colors[i], (BYTE *) &colors[j]))
+ for (j = 0; j < 8; j++) {
+ if (foundBkg[j] && ColorsAreTheSame(colorDiff, (BYTE *)&colors[i], (BYTE *)&colors[j]))
count++;
}
- if (count > maxCount)
- {
+ if (count > maxCount) {
maxCount = count;
selectedColor = i;
}
@@ -589,8 +509,7 @@ BOOL MakeTransparentBkg(MCONTACT hContact, HBITMAP *hBitmap) }
if (maxCount < db_get_w(hContact, "ContactPhoto", "TranspBkgNumPoints",
- db_get_w(0, AVS_MODULE, "TranspBkgNumPoints", 5)))
- {
+ db_get_w(0, AVS_MODULE, "TranspBkgNumPoints", 5))) {
// Not enought corners with the same color
if (hBmpTmp != *hBitmap) DeleteObject(hBmpTmp);
free(p);
@@ -600,14 +519,11 @@ BOOL MakeTransparentBkg(MCONTACT hContact, HBITMAP *hBitmap) // Get bkg color as mean of colors
{
int bkgColor[3];
-
bkgColor[0] = 0;
bkgColor[1] = 0;
bkgColor[2] = 0;
- for (i = 0 ; i < 8 ; i++)
- {
- if (foundBkg[i] && ColorsAreTheSame(colorDiff, (BYTE *) &colors[i], (BYTE *) &colors[selectedColor]))
- {
+ for (i = 0; i < 8; i++) {
+ if (foundBkg[i] && ColorsAreTheSame(colorDiff, (BYTE *)&colors[i], (BYTE *)&colors[selectedColor])) {
bkgColor[0] += colors[i][0];
bkgColor[1] += colors[i][1];
bkgColor[2] += colors[i][2];
@@ -623,9 +539,7 @@ BOOL MakeTransparentBkg(MCONTACT hContact, HBITMAP *hBitmap) }
// **** Set alpha for the background color, from the borders
-
- if (hBmpTmp != *hBitmap)
- {
+ if (hBmpTmp != *hBitmap) {
DeleteObject(*hBitmap);
*hBitmap = hBmpTmp;
@@ -634,92 +548,76 @@ BOOL MakeTransparentBkg(MCONTACT hContact, HBITMAP *hBitmap) GetBitmapBits(*hBitmap, dwLen, p);
}
- {
- // Set alpha from borders
- int x, y;
- int topPos = 0;
- int curPos = 0;
- int *stack = (int *)malloc(width * height * 2 * sizeof(int));
- bool transpProportional = (db_get_b(NULL, AVS_MODULE, "MakeTransparencyProportionalToColorDiff", 0) != 0);
-
- if (stack == NULL)
- {
- free(p);
- return FALSE;
- }
+ // Set alpha from borders
+ bool transpProportional = (db_get_b(NULL, AVS_MODULE, "MakeTransparencyProportionalToColorDiff", 0) != 0);
- // Put four corners
- AddToStack(stack, &topPos, 0, 0);
- AddToStack(stack, &topPos, width/2, 0);
- AddToStack(stack, &topPos, width-1, 0);
- AddToStack(stack, &topPos, 0, height/2);
- AddToStack(stack, &topPos, width-1, height/2);
- AddToStack(stack, &topPos, 0, height-1);
- AddToStack(stack, &topPos, width/2, height-1);
- AddToStack(stack, &topPos, width-1, height-1);
-
- while(curPos < topPos)
- {
- // Get pos
- x = stack[curPos]; curPos++;
- y = stack[curPos]; curPos++;
-
- // Get pixel
- px1 = GET_PIXEL(p, x, y);
-
- // It won't change the transparency if one exists
- // (This avoid an endless loop too)
- // Not using == 255 because some MSN bmps have 254 in some positions
- if (px1[3] >= 253)
- {
- if (ColorsAreTheSame(colorDiff, px1, (BYTE *) &colors[selectedColor]))
- {
- if (transpProportional)
- {
- px1[3] = min(252,
- (abs(px1[0] - colors[selectedColor][0])
- + abs(px1[1] - colors[selectedColor][1])
- + abs(px1[2] - colors[selectedColor][2])) / 3);
- }
- else
- {
- px1[3] = 0;
- }
-
- // Add 4 neighbours
-
- if (x + 1 < width)
- AddToStack(stack, &topPos, x + 1, y);
-
- if (x - 1 >= 0)
- AddToStack(stack, &topPos, x - 1, y);
-
- if (y + 1 < height)
- AddToStack(stack, &topPos, x, y + 1);
-
- if (y - 1 >= 0)
- AddToStack(stack, &topPos, x, y - 1);
- }
+ int *stack = (int *)malloc(width * height * 2 * sizeof(int));
+ if (stack == NULL) {
+ free(p);
+ return FALSE;
+ }
+
+ // Put four corners
+ int topPos = 0;
+ AddToStack(stack, &topPos, 0, 0);
+ AddToStack(stack, &topPos, width / 2, 0);
+ AddToStack(stack, &topPos, width - 1, 0);
+ AddToStack(stack, &topPos, 0, height / 2);
+ AddToStack(stack, &topPos, width - 1, height / 2);
+ AddToStack(stack, &topPos, 0, height - 1);
+ AddToStack(stack, &topPos, width / 2, height - 1);
+ AddToStack(stack, &topPos, width - 1, height - 1);
+
+ int curPos = 0;
+ while (curPos < topPos) {
+ // Get pos
+ int x = stack[curPos]; curPos++;
+ int y = stack[curPos]; curPos++;
+
+ // Get pixel
+ BYTE *px1 = GET_PIXEL(p, x, y);
+
+ // It won't change the transparency if one exists
+ // (This avoid an endless loop too)
+ // Not using == 255 because some MSN bmps have 254 in some positions
+ if (px1[3] >= 253) {
+ if (ColorsAreTheSame(colorDiff, px1, (BYTE *)&colors[selectedColor])) {
+ px1[3] = (transpProportional) ? min(252,
+ (abs(px1[0] - colors[selectedColor][0])
+ + abs(px1[1] - colors[selectedColor][1])
+ + abs(px1[2] - colors[selectedColor][2])) / 3) : 0;
+
+ // Add 4 neighbours
+ if (x + 1 < width)
+ AddToStack(stack, &topPos, x + 1, y);
+
+ if (x - 1 >= 0)
+ AddToStack(stack, &topPos, x - 1, y);
+
+ if (y + 1 < height)
+ AddToStack(stack, &topPos, x, y + 1);
+
+ if (y - 1 >= 0)
+ AddToStack(stack, &topPos, x, y - 1);
}
}
-
- free(stack);
}
- dwLen = SetBitmapBits(*hBitmap, dwLen, p);
- free(p);
+ free(stack);
+ SetBitmapBits(*hBitmap, dwLen, p);
+ free(p);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Other utils
-int SaveAvatar( const char* protocol, const TCHAR* tszFileName )
+int SaveAvatar(const char* protocol, const TCHAR* tszFileName)
{
- INT_PTR result = CallProtoService(protocol, PS_SETMYAVATART, 0, ( LPARAM )tszFileName);
- if ( result == CALLSERVICE_NOTFOUND )
+ INT_PTR result = CallProtoService(protocol, PS_SETMYAVATART, 0, (LPARAM)tszFileName);
+ if (result == CALLSERVICE_NOTFOUND)
result = CallProtoService(protocol, PS_SETMYAVATAR, 0, (LPARAM)(char*)_T2A(tszFileName));
-
+
return result;
}
diff --git a/plugins/AVS/src/image_utils.h b/plugins/AVS/src/image_utils.h index 77ff831719..1807e20132 100644 --- a/plugins/AVS/src/image_utils.h +++ b/plugins/AVS/src/image_utils.h @@ -41,10 +41,6 @@ BOOL MakeTransparentBkg(MCONTACT hContact, HBITMAP *hBitmap); HBITMAP MakeGrayscale(MCONTACT hContact, HBITMAP hBitmap);
DWORD GetImgHash(HBITMAP hBitmap);
-int AVS_pathIsAbsolute(const TCHAR *path);
-size_t AVS_pathToRelative(const TCHAR *sPrc, TCHAR *pOut);
-size_t AVS_pathToAbsolute(const TCHAR *pSrc, TCHAR *pOut);
-
int SaveAvatar( const char* protocol, const TCHAR* tszFileName );
#endif // __IMAGE_UTILS_H__
diff --git a/plugins/AVS/src/main.cpp b/plugins/AVS/src/main.cpp index 5bda47f423..d921c7fb30 100644 --- a/plugins/AVS/src/main.cpp +++ b/plugins/AVS/src/main.cpp @@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
+CLIST_INTERFACE *pcli;
+
HINSTANCE g_hInst = 0;
HICON g_hIcon = 0;
bool g_shutDown = false;
@@ -79,13 +81,13 @@ PLUGININFOEX pluginInfoEx = { static TCHAR* getJGMailID(char *szProto)
{
- static TCHAR szJID[MAX_PATH+1]; szJID[0] = '\0';
+ static TCHAR szJID[MAX_PATH + 1]; szJID[0] = '\0';
DBVARIANT dbva, dbvb;
- if ( db_get_ts(NULL, szProto, "LoginName", &dbva))
+ if (db_get_ts(NULL, szProto, "LoginName", &dbva))
return szJID;
- if ( db_get_ts(NULL, szProto, "LoginServer", &dbvb)) {
+ if (db_get_ts(NULL, szProto, "LoginServer", &dbvb)) {
db_free(&dbva);
return szJID;
}
@@ -104,10 +106,10 @@ static int ProtocolAck(WPARAM wParam, LPARAM lParam) if (ack->hProcess == NULL)
ProcessAvatarInfo(ack->hContact, GAIR_NOAVATAR, NULL, ack->szModule);
else
- ProcessAvatarInfo(ack->hContact, GAIR_SUCCESS, (PROTO_AVATAR_INFORMATIONT *) ack->hProcess, ack->szModule);
+ ProcessAvatarInfo(ack->hContact, GAIR_SUCCESS, (PROTO_AVATAR_INFORMATIONT *)ack->hProcess, ack->szModule);
}
else if (ack->result == ACKRESULT_FAILED) {
- ProcessAvatarInfo(ack->hContact, GAIR_FAILED, (PROTO_AVATAR_INFORMATIONT *) ack->hProcess, ack->szModule);
+ ProcessAvatarInfo(ack->hContact, GAIR_FAILED, (PROTO_AVATAR_INFORMATIONT *)ack->hProcess, ack->szModule);
}
else if (ack->result == ACKRESULT_STATUS) {
char *szProto = GetContactProto(ack->hContact);
@@ -175,11 +177,11 @@ static void LoadProtoInfo(PROTOCOLDESCRIPTOR *proto) static void LoadAccountInfo(PROTOACCOUNT *acc)
{
protoPicCacheEntry *pce = new protoPicCacheEntry;
- if ( CreateAvatarInCache(0, pce, acc->szModuleName) != 1)
+ if (CreateAvatarInCache(0, pce, acc->szModuleName) != 1)
db_unset(0, PPICT_MODULE, acc->szModuleName);
- pce->szProtoname = mir_strdup( acc->szModuleName);
- pce->tszAccName = mir_tstrdup( acc->tszAccountName);
+ pce->szProtoname = mir_strdup(acc->szModuleName);
+ pce->tszAccName = mir_tstrdup(acc->tszAccountName);
g_ProtoPictures.insert(pce);
pce = new protoPicCacheEntry;
@@ -193,21 +195,21 @@ static int OnAccChanged(WPARAM wParam, LPARAM lParam) {
PROTOACCOUNT *pa = (PROTOACCOUNT*)lParam;
- switch( wParam ) {
+ switch (wParam) {
case PRAC_ADDED:
LoadAccountInfo(pa);
break;
case PRAC_REMOVED:
- {
- int idx;
- protoPicCacheEntry tmp;
- tmp.szProtoname = mir_strdup(pa->szModuleName);
- if ((idx = g_ProtoPictures.getIndex( &tmp )) != -1)
- g_ProtoPictures.remove( idx );
- if ((idx = g_MyAvatars.getIndex( &tmp )) != -1)
- g_MyAvatars.remove( idx );
- }
+ {
+ int idx;
+ protoPicCacheEntry tmp;
+ tmp.szProtoname = mir_strdup(pa->szModuleName);
+ if ((idx = g_ProtoPictures.getIndex(&tmp)) != -1)
+ g_ProtoPictures.remove(idx);
+ if ((idx = g_MyAvatars.getIndex(&tmp)) != -1)
+ g_MyAvatars.remove(idx);
+ }
break;
}
@@ -216,7 +218,7 @@ static int OnAccChanged(WPARAM wParam, LPARAM lParam) static int ContactSettingChanged(WPARAM hContact, LPARAM lParam)
{
- DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) lParam;
+ DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam;
if (cws == NULL || g_shutDown)
return 0;
@@ -252,7 +254,7 @@ void InternalDrawAvatar(AVATARDRAWREQUEST *r, HBITMAP hbm, LONG bmWidth, LONG bm HRGN rgn = 0, oldRgn = 0;
int targetWidth = r->rcDraw.right - r->rcDraw.left;
int targetHeight = r->rcDraw.bottom - r->rcDraw.top;
- BLENDFUNCTION bf = {0};
+ BLENDFUNCTION bf = { 0 };
hdcAvatar = CreateCompatibleDC(r->hTargetDC);
hbmMem = (HBITMAP)SelectObject(hdcAvatar, hbm);
@@ -264,12 +266,12 @@ void InternalDrawAvatar(AVATARDRAWREQUEST *r, HBITMAP hbm, LONG bmWidth, LONG bm else if (bmHeight >= bmWidth) {
dScale = targetHeight / (float)bmHeight;
newHeight = targetHeight;
- newWidth = (int) (bmWidth * dScale);
+ newWidth = (int)(bmWidth * dScale);
}
else {
dScale = targetWidth / (float)bmWidth;
newWidth = targetWidth;
- newHeight = (int) (bmHeight * dScale);
+ newHeight = (int)(bmHeight * dScale);
}
topoffset = targetHeight > newHeight ? (targetHeight - newHeight) / 2 : 0;
@@ -277,10 +279,9 @@ void InternalDrawAvatar(AVATARDRAWREQUEST *r, HBITMAP hbm, LONG bmWidth, LONG bm // create the region for the avatar border - use the same region for clipping, if needed.
- oldRgn = CreateRectRgn(0,0,1,1);
+ oldRgn = CreateRectRgn(0, 0, 1, 1);
- if (GetClipRgn(r->hTargetDC, oldRgn) != 1)
- {
+ if (GetClipRgn(r->hTargetDC, oldRgn) != 1) {
DeleteObject(oldRgn);
oldRgn = NULL;
}
@@ -304,10 +305,12 @@ void InternalDrawAvatar(AVATARDRAWREQUEST *r, HBITMAP hbm, LONG bmWidth, LONG bm GdiAlphaBlend(
r->hTargetDC, r->rcDraw.left + leftoffset, r->rcDraw.top + topoffset, newWidth, newHeight,
hdcAvatar, 0, 0, bmWidth, bmHeight, bf);
- } else {
+ }
+ else {
if (bf.SourceConstantAlpha == 255 && bf.AlphaFormat == 0 && !(r->dwFlags & AVDRQ_FORCEALPHA) && !(r->dwFlags & AVDRQ_AERO)) {
StretchBlt(r->hTargetDC, r->rcDraw.left + leftoffset, r->rcDraw.top + topoffset, newWidth, newHeight, hdcAvatar, 0, 0, bmWidth, bmHeight, SRCCOPY);
- } else {
+ }
+ else {
/*
* get around SUCKY AlphaBlend() rescaling quality...
*/
@@ -350,13 +353,13 @@ void InternalDrawAvatar(AVATARDRAWREQUEST *r, HBITMAP hbm, LONG bmWidth, LONG bm static int ModulesLoaded(WPARAM wParam, LPARAM lParam)
{
int i;
- DBVARIANT dbv = {0};
+ DBVARIANT dbv = { 0 };
TCHAR szEventName[100];
int result = 0;
mir_sntprintf(szEventName, 100, _T("avs_loaderthread_%d"), GetCurrentThreadId());
hLoaderEvent = CreateEvent(NULL, TRUE, FALSE, szEventName);
- SetThreadPriority( mir_forkthread(PicLoader, 0), THREAD_PRIORITY_IDLE);
+ SetThreadPriority(mir_forkthread(PicLoader, 0), THREAD_PRIORITY_IDLE);
// Folders plugin support
hMyAvatarsFolder = FoldersRegisterCustomPathT(LPGEN("Avatars"), LPGEN("My Avatars"), MIRANDA_USERDATAT _T("\\Avatars"));
@@ -373,10 +376,10 @@ static int ModulesLoaded(WPARAM wParam, LPARAM lParam) PROTOCOLDESCRIPTOR** proto;
int protoCount;
CallService(MS_PROTO_ENUMPROTOS, (WPARAM)&protoCount, (LPARAM)&proto);
- for (i=0; i < protoCount; i++ )
- LoadProtoInfo( proto[i] );
- for (i=0; i < accCount; i++)
- LoadAccountInfo( accs[i] );
+ for (i = 0; i < protoCount; i++)
+ LoadProtoInfo(proto[i]);
+ for (i = 0; i < accCount; i++)
+ LoadAccountInfo(accs[i]);
}
// Load global avatar
@@ -411,8 +414,7 @@ static int LoadAvatarModule() InitCache();
InitPolls();
- lstrcpyn(g_szDataPath, VARST(_T("%miranda_userdata%")), SIZEOF(g_szDataPath)-1);
- g_szDataPath[MAX_PATH - 1] = 0;
+ _tcsncpy_s(g_szDataPath, SIZEOF(g_szDataPath), VARST(_T("%miranda_userdata%\\")), _TRUNCATE);
_tcslwr(g_szDataPath);
return 0;
}
@@ -431,6 +433,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX * MirandaPluginInfoEx(DWORD mirand extern "C" int __declspec(dllexport) Load(void)
{
mir_getLP(&pluginInfoEx);
+ mir_getCLI();
INT_PTR result = CALLSERVICE_NOTFOUND;
if (ServiceExists(MS_IMG_GETINTERFACE))
diff --git a/plugins/AVS/src/options.cpp b/plugins/AVS/src/options.cpp index c09947bc8f..aabdfa1479 100644 --- a/plugins/AVS/src/options.cpp +++ b/plugins/AVS/src/options.cpp @@ -40,7 +40,8 @@ extern BOOL ScreenToClient(HWND hWnd, LPRECT lpRect); static BOOL dialoginit = TRUE;
-struct WindowData {
+struct WindowData
+{
MCONTACT hContact;
HANDLE hHook;
};
@@ -49,25 +50,25 @@ static void RemoveProtoPic(const char *szProto) {
db_unset(NULL, PPICT_MODULE, szProto);
- if ( szProto == NULL )
+ if (szProto == NULL)
return;
- if ( !lstrcmpA(AVS_DEFAULT, szProto )) {
+ if (!lstrcmpA(AVS_DEFAULT, szProto)) {
for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
- protoPicCacheEntry& p = g_ProtoPictures[i];
+ protoPicCacheEntry &p = g_ProtoPictures[i];
if (p.szProtoname == NULL)
continue;
p.clear();
- CreateAvatarInCache(0, &p, ( char* )p.szProtoname);
+ CreateAvatarInCache(0, &p, (char*)p.szProtoname);
NotifyEventHooks(hEventChanged, 0, (LPARAM)&p);
}
return;
}
if (strstr(szProto, "Global avatar for")) {
- char szProtoname[MAX_PATH] = {0};
- lstrcpynA(szProtoname, szProto, lstrlenA(szProto)- lstrlenA("accounts"));
+ char szProtoname[MAX_PATH] = { 0 };
+ lstrcpynA(szProtoname, szProto, lstrlenA(szProto) - lstrlenA("accounts"));
lstrcpyA(szProtoname, strrchr(szProtoname, ' ') + 1);
for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
protoPicCacheEntry& p = g_ProtoPictures[i];
@@ -81,8 +82,8 @@ static void RemoveProtoPic(const char *szProto) continue;
p.clear();
- CreateAvatarInCache(0, &p, ( char* )p.szProtoname);
- NotifyEventHooks( hEventChanged, 0, (LPARAM)&p );
+ CreateAvatarInCache(0, &p, (char*)p.szProtoname);
+ NotifyEventHooks(hEventChanged, 0, (LPARAM)&p);
}
}
return;
@@ -90,9 +91,9 @@ static void RemoveProtoPic(const char *szProto) for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
protoPicCacheEntry& p = g_ProtoPictures[i];
- if ( !lstrcmpA( p.szProtoname, szProto )) {
+ if (!lstrcmpA(p.szProtoname, szProto)) {
p.clear();
- NotifyEventHooks( hEventChanged, 0, (LPARAM)&p );
+ NotifyEventHooks(hEventChanged, 0, (LPARAM)&p);
}
}
}
@@ -100,48 +101,47 @@ static void RemoveProtoPic(const char *szProto) static void SetProtoPic(char *szProto)
{
TCHAR FileName[MAX_PATH];
- OPENFILENAME ofn={0};
+ OPENFILENAME ofn = { 0 };
TCHAR filter[256];
filter[0] = '\0';
- CallService(MS_UTILS_GETBITMAPFILTERSTRINGST, SIZEOF(filter), ( LPARAM )filter);
+ CallService(MS_UTILS_GETBITMAPFILTERSTRINGST, SIZEOF(filter), (LPARAM)filter);
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
ofn.lpstrFilter = filter;
- ofn.hwndOwner=0;
+ ofn.hwndOwner = 0;
ofn.lpstrFile = FileName;
ofn.nMaxFile = MAX_PATH;
ofn.nMaxFileTitle = MAX_PATH;
- ofn.Flags=OFN_HIDEREADONLY;
+ ofn.Flags = OFN_HIDEREADONLY;
ofn.lpstrInitialDir = _T(".");
*FileName = '\0';
ofn.lpstrDefExt = _T("");
- if ( GetOpenFileName( &ofn )) {
- HANDLE hFile;
-
- if ((hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)
+ if (GetOpenFileName(&ofn)) {
+ HANDLE hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (hFile == INVALID_HANDLE_VALUE)
return;
CloseHandle(hFile);
TCHAR szNewPath[MAX_PATH];
- AVS_pathToRelative(FileName, szNewPath);
+ PathToRelativeT(FileName, szNewPath, g_szDataPath);
db_set_ts(NULL, PPICT_MODULE, szProto, szNewPath);
if (!lstrcmpA(AVS_DEFAULT, szProto)) {
- for ( int i = 0; i < g_ProtoPictures.getCount(); i++ ) {
+ for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
protoPicCacheEntry& p = g_ProtoPictures[i];
if (lstrlenA(p.szProtoname) != 0) {
if (p.hbmPic == 0) {
- CreateAvatarInCache(0, &p, ( char* )szProto);
+ CreateAvatarInCache(0, &p, (char*)szProto);
NotifyEventHooks(hEventChanged, 0, (LPARAM)&p);
}
}
}
}
else if (strstr(szProto, "Global avatar for")) {
- char szProtoname[MAX_PATH] = {0};
- lstrcpynA(szProtoname, szProto, lstrlenA(szProto)- lstrlenA("accounts"));
+ char szProtoname[MAX_PATH] = { 0 };
+ lstrcpynA(szProtoname, szProto, lstrlenA(szProto) - lstrlenA("accounts"));
lstrcpyA(szProtoname, strrchr(szProtoname, ' ') + 1);
for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
PROTOACCOUNT* pdescr = (PROTOACCOUNT*)CallService(MS_PROTO_GETACCOUNT, 0, (LPARAM)g_ProtoPictures[i].szProtoname);
@@ -152,7 +152,7 @@ static void SetProtoPic(char *szProto) protoPicCacheEntry& p = g_ProtoPictures[i];
if (lstrlenA(p.szProtoname) != 0) {
if (p.hbmPic == 0) {
- CreateAvatarInCache(0, &p, ( char* )szProto);
+ CreateAvatarInCache(0, &p, (char*)szProto);
NotifyEventHooks(hEventChanged, 0, (LPARAM)&p);
}
}
@@ -162,15 +162,15 @@ static void SetProtoPic(char *szProto) else {
for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
protoPicCacheEntry& p = g_ProtoPictures[i];
- if ( lstrlenA(p.szProtoname) == 0)
+ if (lstrlenA(p.szProtoname) == 0)
break;
if (!strcmp(p.szProtoname, szProto) && lstrlenA(p.szProtoname) == lstrlenA(szProto)) {
if (p.hbmPic != 0)
DeleteObject(p.hbmPic);
ZeroMemory(&p, sizeof(avatarCacheEntry));
- CreateAvatarInCache(0, &p, ( char* )szProto);
- NotifyEventHooks(hEventChanged, 0, (LPARAM)&p );
+ CreateAvatarInCache(0, &p, (char*)szProto);
+ NotifyEventHooks(hEventChanged, 0, (LPARAM)&p);
break;
}
}
@@ -211,35 +211,36 @@ static INT_PTR CALLBACK DlgProcOptionsAvatars(HWND hwndDlg, UINT msg, WPARAM wPa case WM_COMMAND:
if ((LOWORD(wParam) == IDC_BKG_NUM_POINTS || LOWORD(wParam) == IDC_BKG_COLOR_DIFFERENCE)
- && (HIWORD(wParam) != EN_CHANGE || (HWND) lParam != GetFocus()))
- return FALSE;
+ && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
+ return FALSE;
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
case WM_NOTIFY:
- switch (((LPNMHDR) lParam)->idFrom) {
+ switch (((LPNMHDR)lParam)->idFrom) {
case IDC_MAKE_TRANSPARENT_BKG:
- {
- BOOL transp_enabled = IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSPARENT_BKG);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_L), transp_enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_SPIN), transp_enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), transp_enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), transp_enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), transp_enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), transp_enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL), transp_enabled);
- break;
- }
+ {
+ BOOL transp_enabled = IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSPARENT_BKG);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_L), transp_enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_SPIN), transp_enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), transp_enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), transp_enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), transp_enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), transp_enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL), transp_enabled);
+ break;
+ }
case 0:
- switch (((LPNMHDR) lParam)->code) {
+ switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
db_set_b(NULL, AVS_MODULE, "warnings", IsDlgButtonChecked(hwndDlg, IDC_SHOWWARNINGS) ? 1 : 0);
db_set_b(NULL, AVS_MODULE, "MakeGrayscale", IsDlgButtonChecked(hwndDlg, IDC_MAKE_GRAYSCALE) ? 1 : 0);
db_set_b(NULL, AVS_MODULE, "MakeTransparentBkg", IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSPARENT_BKG) ? 1 : 0);
db_set_b(NULL, AVS_MODULE, "MakeTransparencyProportionalToColorDiff", IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL) ? 1 : 0);
- db_set_w(NULL, AVS_MODULE, "TranspBkgNumPoints", (WORD) SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_GETPOS, 0, 0));
- db_set_w(NULL, AVS_MODULE, "TranspBkgColorDiff", (WORD) SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_GETPOS, 0, 0));
- } }
+ db_set_w(NULL, AVS_MODULE, "TranspBkgNumPoints", (WORD)SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_GETPOS, 0, 0));
+ db_set_w(NULL, AVS_MODULE, "TranspBkgColorDiff", (WORD)SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_GETPOS, 0, 0));
+ }
+ }
break;
}
return FALSE;
@@ -263,13 +264,14 @@ static INT_PTR CALLBACK DlgProcOptionsOwn(HWND hwndDlg, UINT msg, WPARAM wParam, break;
case WM_NOTIFY:
- switch (((LPNMHDR) lParam)->idFrom) {
+ switch (((LPNMHDR)lParam)->idFrom) {
case 0:
- switch (((LPNMHDR) lParam)->code) {
+ switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
db_set_b(NULL, AVS_MODULE, "MakeMyAvatarsTransparent", IsDlgButtonChecked(hwndDlg, IDC_MAKE_MY_AVATARS_TRANSP) ? 1 : 0);
db_set_b(NULL, AVS_MODULE, "SetAllwaysMakeSquare", IsDlgButtonChecked(hwndDlg, IDC_SET_MAKE_SQUARE) ? 1 : 0);
- } }
+ }
+ }
break;
}
return FALSE;
@@ -280,11 +282,11 @@ static char* GetProtoFromList(HWND hwndDlg, int iItem) LVITEM item;
item.mask = LVIF_PARAM;
item.iItem = iItem;
- if ( !ListView_GetItem( GetDlgItem(hwndDlg, IDC_PROTOCOLS), &item ))
+ if (!ListView_GetItem(GetDlgItem(hwndDlg, IDC_PROTOCOLS), &item))
return NULL;
- protoPicCacheEntry *pce = ( protoPicCacheEntry* )item.lParam;
- return ( pce == NULL ) ? NULL : pce->szProtoname;
+ protoPicCacheEntry *pce = (protoPicCacheEntry*)item.lParam;
+ return (pce == NULL) ? NULL : pce->szProtoname;
}
static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -295,64 +297,58 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar switch (msg) {
case WM_INITDIALOG:
- {
- LVITEM item = {0};
- LVCOLUMN lvc = {0};
- int newItem = 0;
+ dialoginit = TRUE;
+ TranslateDialogDefault(hwndDlg);
- dialoginit = TRUE;
- TranslateDialogDefault(hwndDlg);
- ListView_SetExtendedListViewStyle(hwndList, LVS_EX_CHECKBOXES);
+ ListView_SetExtendedListViewStyle(hwndList, LVS_EX_CHECKBOXES);
+ {
+ LVCOLUMN lvc = { 0 };
lvc.mask = LVCF_FMT;
lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT;
ListView_InsertColumn(hwndList, 0, &lvc);
+ LVITEM item = { 0 };
item.mask = LVIF_TEXT | LVIF_PARAM;
item.iItem = 1000;
- for (int i = 0; i < g_ProtoPictures.getCount(); i++ ) {
- item.lParam = ( LPARAM )&g_ProtoPictures[i];
+ for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
+ item.lParam = (LPARAM)&g_ProtoPictures[i];
item.pszText = g_ProtoPictures[i].tszAccName;
- newItem = ListView_InsertItem(hwndList, &item);
+ int newItem = ListView_InsertItem(hwndList, &item);
if (newItem >= 0)
ListView_SetCheckState(hwndList, newItem,
- db_get_b(NULL, AVS_MODULE, g_ProtoPictures[i].szProtoname, 1) ? TRUE : FALSE);
+ db_get_b(NULL, AVS_MODULE, g_ProtoPictures[i].szProtoname, 1) ? TRUE : FALSE);
}
ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);
ListView_Arrange(hwndList, LVA_ALIGNLEFT | LVA_ALIGNTOP);
EnableWindow(hwndChoosePic, FALSE);
EnableWindow(hwndRemovePic, FALSE);
-
- dialoginit = FALSE;
}
+ dialoginit = FALSE;
return TRUE;
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case IDC_SETPROTOPIC:
case IDC_REMOVEPROTOPIC:
- {
- int iItem = ListView_GetSelectionMark(hwndList);
- char* szProto = GetProtoFromList(hwndDlg, iItem);
- if ( szProto ) {
- if (LOWORD(wParam) == IDC_SETPROTOPIC)
- SetProtoPic( szProto );
- else
- RemoveProtoPic( szProto );
-
- NMHDR nm = { hwndList, IDC_PROTOCOLS, NM_CLICK };
- SendMessage(hwndDlg, WM_NOTIFY, 0, (LPARAM)&nm);
- }
- break;
+ int iItem = ListView_GetSelectionMark(hwndList);
+ char* szProto = GetProtoFromList(hwndDlg, iItem);
+ if (szProto) {
+ if (LOWORD(wParam) == IDC_SETPROTOPIC)
+ SetProtoPic(szProto);
+ else
+ RemoveProtoPic(szProto);
+
+ NMHDR nm = { hwndList, IDC_PROTOCOLS, NM_CLICK };
+ SendMessage(hwndDlg, WM_NOTIFY, 0, (LPARAM)&nm);
}
}
break;
case WM_DRAWITEM:
{
- LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT) lParam;
-
+ LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
if (dis->CtlType == ODT_BUTTON && dis->CtlID == IDC_PROTOPIC) {
- AVATARDRAWREQUEST avdrq = {0};
+ AVATARDRAWREQUEST avdrq = { 0 };
avdrq.cbSize = sizeof(avdrq);
avdrq.hTargetDC = dis->hDC;
avdrq.dwFlags |= AVDRQ_PROTOPICT;
@@ -360,23 +356,24 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar GetClientRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), &avdrq.rcDraw);
CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq);
}
- return TRUE;
}
+ return TRUE;
case WM_NOTIFY:
if (dialoginit)
break;
- switch (((LPNMHDR) lParam)->idFrom) {
+ switch (((LPNMHDR)lParam)->idFrom) {
case IDC_PROTOCOLS:
- switch (((LPNMHDR) lParam)->code) {
+ switch (((LPNMHDR)lParam)->code) {
case LVN_KEYDOWN:
{
NMLVKEYDOWN* ptkd = (NMLVKEYDOWN*)lParam;
- if (ptkd&&ptkd->wVKey==VK_SPACE&&ListView_GetSelectedCount(ptkd->hdr.hwndFrom)==1)
+ if (ptkd&&ptkd->wVKey == VK_SPACE&&ListView_GetSelectedCount(ptkd->hdr.hwndFrom) == 1)
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
break;
+
case LVN_ITEMCHANGED:
{
NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;
@@ -384,38 +381,36 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
break;
+
case NM_CLICK:
- {
- EnableWindow(hwndChoosePic, TRUE);
- EnableWindow(hwndRemovePic, TRUE);
-
- int iItem = ListView_GetSelectionMark(hwndList);
- g_selectedProto = GetProtoFromList(hwndDlg, iItem);
- if ( g_selectedProto ) {
- DBVARIANT dbv;
- if ( !db_get_ts(NULL, PPICT_MODULE, g_selectedProto, &dbv)) {
- if ( !AVS_pathIsAbsolute( VARST(dbv.ptszVal))) {
- TCHAR szFinalPath[MAX_PATH];
- mir_sntprintf(szFinalPath, SIZEOF(szFinalPath), _T("%%miranda_path%%\\%s"), dbv.ptszVal);
- SetDlgItemText(hwndDlg, IDC_PROTOAVATARNAME, szFinalPath);
- }
- else SetDlgItemText(hwndDlg, IDC_PROTOAVATARNAME, dbv.ptszVal);
-
- InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), NULL, TRUE);
- db_free(&dbv);
- }
- else {
- SetWindowText(GetDlgItem(hwndDlg, IDC_PROTOAVATARNAME), _T(""));
- InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), NULL, TRUE);
+ EnableWindow(hwndChoosePic, TRUE);
+ EnableWindow(hwndRemovePic, TRUE);
+
+ int iItem = ListView_GetSelectionMark(hwndList);
+ g_selectedProto = GetProtoFromList(hwndDlg, iItem);
+ if (g_selectedProto) {
+ DBVARIANT dbv;
+ if (!db_get_ts(NULL, PPICT_MODULE, g_selectedProto, &dbv)) {
+ if (!PathIsAbsoluteT(VARST(dbv.ptszVal))) {
+ TCHAR szFinalPath[MAX_PATH];
+ mir_sntprintf(szFinalPath, SIZEOF(szFinalPath), _T("%%miranda_path%%\\%s"), dbv.ptszVal);
+ SetDlgItemText(hwndDlg, IDC_PROTOAVATARNAME, szFinalPath);
}
+ else SetDlgItemText(hwndDlg, IDC_PROTOAVATARNAME, dbv.ptszVal);
+
+ InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), NULL, TRUE);
+ db_free(&dbv);
+ }
+ else {
+ SetWindowText(GetDlgItem(hwndDlg, IDC_PROTOAVATARNAME), _T(""));
+ InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), NULL, TRUE);
}
- break;
}
}
break;
case 0:
- if (((LPNMHDR) lParam)->code == PSN_APPLY) {
+ if (((LPNMHDR)lParam)->code == PSN_APPLY) {
for (int i = 0; i < ListView_GetItemCount(hwndList); i++) {
char *szProto = GetProtoFromList(hwndDlg, i);
@@ -463,13 +458,13 @@ static void SaveTransparentData(HWND hwndDlg, MCONTACT hContact) else
db_set_b(hContact, "ContactPhoto", "MakeTransparentBkg", transp);
- WORD tmp = (WORD) SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_GETPOS, 0, 0);
+ WORD tmp = (WORD)SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_GETPOS, 0, 0);
if (db_get_w(0, AVS_MODULE, "TranspBkgNumPoints", 5) == tmp)
db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints");
else
db_set_w(hContact, "ContactPhoto", "TranspBkgNumPoints", tmp);
- tmp = (WORD) SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_GETPOS, 0, 0);
+ tmp = (WORD)SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_GETPOS, 0, 0);
if (db_get_w(0, AVS_MODULE, "TranspBkgColorDiff", 10) == tmp)
db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff");
else
@@ -488,49 +483,44 @@ static void SaveTransparentData(HWND hwndDlg, MCONTACT hContact, BOOL locked) INT_PTR CALLBACK DlgProcAvatarOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
MCONTACT hContact;
- struct WindowData *dat = (struct WindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ WindowData *dat = (WindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
if (dat)
hContact = dat->hContact;
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
- {
- TCHAR szTitle[512];
- TCHAR *szNick = NULL;
- struct WindowData *dat = (struct WindowData *)malloc(sizeof(struct WindowData));
-
- if (dat)
- dat->hContact = lParam;
+ dat = (WindowData*)malloc(sizeof(WindowData));
+ if (dat)
+ dat->hContact = lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
- hContact = lParam;
- TranslateDialogDefault(hwndDlg);
- if (hContact) {
- szNick = (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR);
- mir_sntprintf(szTitle, 500, TranslateT("Set avatar options for %s"), szNick);
- SetWindowText(hwndDlg, szTitle);
- }
- SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0);
- ShowWindow(hwndDlg, SW_SHOWNORMAL);
- InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), NULL, FALSE);
- CheckDlgButton(hwndDlg, IDC_PROTECTAVATAR, db_get_b(hContact, "ContactPhoto", "Locked", 0) ? TRUE : FALSE);
- CheckDlgButton(hwndDlg, IDC_HIDEAVATAR, db_get_b(hContact, "ContactPhoto", "Hidden", 0) ? TRUE : FALSE);
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
+ hContact = lParam;
+ TranslateDialogDefault(hwndDlg);
+ if (hContact) {
+ TCHAR szTitle[512];
+ mir_sntprintf(szTitle, 500, TranslateT("Set avatar options for %s"), pcli->pfnGetContactDisplayName(hContact, 0));
+ SetWindowText(hwndDlg, szTitle);
+ }
+ SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0);
+ ShowWindow(hwndDlg, SW_SHOWNORMAL);
+ InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), NULL, FALSE);
+ CheckDlgButton(hwndDlg, IDC_PROTECTAVATAR, db_get_b(hContact, "ContactPhoto", "Locked", 0) ? TRUE : FALSE);
+ CheckDlgButton(hwndDlg, IDC_HIDEAVATAR, db_get_b(hContact, "ContactPhoto", "Hidden", 0) ? TRUE : FALSE);
- SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), 0);
- SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETRANGE, 0, MAKELONG(8, 2));
+ SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), 0);
+ SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETRANGE, 0, MAKELONG(8, 2));
- SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), 0);
- SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0));
+ SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), 0);
+ SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0));
- LoadTransparentData(hwndDlg, GetContactThatHaveTheAvatar(hContact));
- dat->hHook = HookEventMessage(ME_AV_AVATARCHANGED, hwndDlg, DM_AVATARCHANGED);
- SendMessage(hwndDlg, WM_SETICON, IMAGE_ICON, (LPARAM)g_hIcon);
- }
+ LoadTransparentData(hwndDlg, GetContactThatHaveTheAvatar(hContact));
+ dat->hHook = HookEventMessage(ME_AV_AVATARCHANGED, hwndDlg, DM_AVATARCHANGED);
+ SendMessage(hwndDlg, WM_SETICON, IMAGE_ICON, (LPARAM)g_hIcon);
return TRUE;
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case ID_USE_DEFAULTS:
hContact = GetContactThatHaveTheAvatar(hContact);
@@ -553,9 +543,8 @@ INT_PTR CALLBACK DlgProcAvatarOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPA if (!locked && db_get_b(hContact, "ContactPhoto", "NeedUpdate", 0))
QueueAdd(hContact);
-
- // Continue to the cancel handle
}
+ // Continue to the cancel handle
case IDCANCEL:
DestroyWindow(hwndDlg);
@@ -576,7 +565,7 @@ INT_PTR CALLBACK DlgProcAvatarOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPA case IDC_BKG_NUM_POINTS:
case IDC_BKG_COLOR_DIFFERENCE:
- if (HIWORD(wParam)!=EN_CHANGE || (HWND)lParam!=GetFocus())
+ if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())
break;
case IDC_MAKETRANSPBKG:
@@ -594,61 +583,56 @@ INT_PTR CALLBACK DlgProcAvatarOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPA break;
case IDC_RESET:
+ ProtectAvatar(hContact, 0);
+ if (MessageBox(0, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) {
+ DBVARIANT dbv = { 0 };
+ if (!db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
+ DeleteFile(dbv.ptszVal);
+ db_free(&dbv);
+ }
+ }
+ db_unset(hContact, "ContactPhoto", "Locked");
+ db_unset(hContact, "ContactPhoto", "Backup");
+ db_unset(hContact, "ContactPhoto", "RFile");
+ db_unset(hContact, "ContactPhoto", "File");
+ db_unset(hContact, "ContactPhoto", "Format");
{
char *szProto = GetContactProto(hContact);
- DBVARIANT dbv = {0};
-
- ProtectAvatar(hContact, 0);
- if (MessageBox(0, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) {
- if ( !db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
- DeleteFile(dbv.ptszVal);
- db_free(&dbv);
- }
- }
- db_unset(hContact, "ContactPhoto", "Locked");
- db_unset(hContact, "ContactPhoto", "Backup");
- db_unset(hContact, "ContactPhoto", "RFile");
- db_unset(hContact, "ContactPhoto", "File");
- db_unset(hContact, "ContactPhoto", "Format");
db_unset(hContact, szProto, "AvatarHash");
db_unset(hContact, szProto, "AvatarSaved");
DeleteAvatarFromCache(hContact, FALSE);
QueueAdd(hContact);
-
DestroyWindow(hwndDlg);
}
break;
case IDC_DELETE:
- {
- DBVARIANT dbv = {0};
+ if (MessageBox(0, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) {
+ DBVARIANT dbv = { 0 };
ProtectAvatar(hContact, 0);
- if (MessageBox(0, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) {
- if ( !db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
- DeleteFile(dbv.ptszVal);
- db_free(&dbv);
- }
+ if (!db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
+ DeleteFile(dbv.ptszVal);
+ db_free(&dbv);
}
- db_unset(hContact, "ContactPhoto", "Locked");
- db_unset(hContact, "ContactPhoto", "Backup");
- db_unset(hContact, "ContactPhoto", "RFile");
- db_unset(hContact, "ContactPhoto", "File");
- db_unset(hContact, "ContactPhoto", "Format");
- DeleteAvatarFromCache(hContact, FALSE);
- SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0);
- InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), NULL, TRUE);
- break;
}
+ db_unset(hContact, "ContactPhoto", "Locked");
+ db_unset(hContact, "ContactPhoto", "Backup");
+ db_unset(hContact, "ContactPhoto", "RFile");
+ db_unset(hContact, "ContactPhoto", "File");
+ db_unset(hContact, "ContactPhoto", "Format");
+ DeleteAvatarFromCache(hContact, FALSE);
+ SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0);
+ InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), NULL, TRUE);
+ break;
}
break;
case WM_DRAWITEM:
{
- LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT) lParam;
-
+ LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
if (dis->CtlType == ODT_BUTTON && dis->CtlID == IDC_PROTOPIC) {
- AVATARDRAWREQUEST avdrq = {0};
+ AVATARDRAWREQUEST avdrq = { 0 };
GetClientRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), &avdrq.rcDraw);
FillRect(dis->hDC, &avdrq.rcDraw, GetSysColorBrush(COLOR_BTNFACE));
@@ -659,8 +643,7 @@ INT_PTR CALLBACK DlgProcAvatarOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPA avdrq.dwFlags |= AVDRQ_DRAWBORDER;
avdrq.clrBorder = GetSysColor(COLOR_BTNTEXT);
avdrq.radius = 6;
- if (!CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq))
- {
+ if (!CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq)) {
// Get text rectangle
RECT rc = avdrq.rcDraw;
rc.top += 10;
@@ -671,43 +654,44 @@ INT_PTR CALLBACK DlgProcAvatarOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPA // Calc text size
RECT rc_ret = rc;
DrawText(dis->hDC, TranslateT("Contact has no avatar"), -1, &rc_ret,
- DT_WORDBREAK | DT_NOPREFIX | DT_CENTER | DT_CALCRECT);
+ DT_WORDBREAK | DT_NOPREFIX | DT_CENTER | DT_CALCRECT);
// Calc needed size
rc.top += ((rc.bottom - rc.top) - (rc_ret.bottom - rc_ret.top)) / 2;
rc.bottom = rc.top + (rc_ret.bottom - rc_ret.top);
DrawText(dis->hDC, TranslateT("Contact has no avatar"), -1, &rc,
- DT_WORDBREAK | DT_NOPREFIX | DT_CENTER);
+ DT_WORDBREAK | DT_NOPREFIX | DT_CENTER);
}
FrameRect(dis->hDC, &avdrq.rcDraw, GetSysColorBrush(COLOR_BTNSHADOW));
}
- return TRUE;
}
+ return TRUE;
+
case DM_SETAVATARNAME:
{
TCHAR szFinalName[MAX_PATH];
- DBVARIANT dbv = {0};
+ DBVARIANT dbv = { 0 };
BYTE is_locked = db_get_b(hContact, "ContactPhoto", "Locked", 0);
szFinalName[0] = 0;
if (is_locked && !db_get_ts(hContact, "ContactPhoto", "Backup", &dbv)) {
- AVS_pathToAbsolute(dbv.ptszVal, szFinalName);
+ PathToAbsoluteT(dbv.ptszVal, szFinalName, g_szDataPath);
db_free(&dbv);
}
- else if ( !db_get_ts(hContact, "ContactPhoto", "RFile", &dbv)) {
- AVS_pathToAbsolute(dbv.ptszVal, szFinalName);
+ else if (!db_get_ts(hContact, "ContactPhoto", "RFile", &dbv)) {
+ PathToAbsoluteT(dbv.ptszVal, szFinalName, g_szDataPath);
db_free(&dbv);
}
- else if ( !db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
- AVS_pathToAbsolute(dbv.ptszVal, szFinalName);
+ else if (!db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
+ PathToAbsoluteT(dbv.ptszVal, szFinalName, g_szDataPath);
db_free(&dbv);
}
szFinalName[MAX_PATH - 1] = 0;
SetDlgItemText(hwndDlg, IDC_AVATARNAME, szFinalName);
- break;
}
+ break;
case DM_REALODAVATAR:
SaveTransparentData(hwndDlg, hContact, IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR));
@@ -760,25 +744,24 @@ int OptInit(WPARAM wParam, LPARAM lParam) static INT_PTR CALLBACK DlgProcAvatarUserInfo(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
MCONTACT hContact;
- struct WindowData *dat = (struct WindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ WindowData *dat = (WindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
if (dat)
hContact = dat->hContact;
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
+ dat = (WindowData*) malloc(sizeof(WindowData));
+ if (dat == NULL)
+ return FALSE;
+ dat->hContact = lParam;
{
- dat = (struct WindowData *) malloc(sizeof(struct WindowData));
- if (dat == NULL)
- return FALSE;
- dat->hContact = lParam;
-
HWND protopic = GetDlgItem(hwndDlg, IDC_PROTOPIC);
- SendMessage(protopic, AVATAR_SETCONTACT, 0, (LPARAM) dat->hContact);
- SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM) GetSysColor(COLOR_BTNSHADOW));
- SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM) LPGENT("Contact has no avatar"));
- SendMessage(protopic, AVATAR_RESPECTHIDDEN, 0, (LPARAM) FALSE);
- SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM) FALSE);
+ SendMessage(protopic, AVATAR_SETCONTACT, 0, (LPARAM)dat->hContact);
+ SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNSHADOW));
+ SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENT("Contact has no avatar"));
+ SendMessage(protopic, AVATAR_RESPECTHIDDEN, 0, (LPARAM)FALSE);
+ SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM)FALSE);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
hContact = lParam;
@@ -798,7 +781,7 @@ static INT_PTR CALLBACK DlgProcAvatarUserInfo(HWND hwndDlg, UINT msg, WPARAM wPa break;
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case ID_USE_DEFAULTS:
hContact = GetContactThatHaveTheAvatar(hContact);
@@ -823,21 +806,22 @@ static INT_PTR CALLBACK DlgProcAvatarUserInfo(HWND hwndDlg, UINT msg, WPARAM wPa SetAvatarAttribute(hContact, AVS_HIDEONCLIST, hidden);
if (hidden != db_get_b(hContact, "ContactPhoto", "Hidden", 0))
db_set_b(hContact, "ContactPhoto", "Hidden", hidden);
- break;
}
+ break;
case IDC_PROTECTAVATAR:
{
BOOL locked = IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR);
SaveTransparentData(hwndDlg, hContact, locked);
ProtectAvatar(hContact, locked ? 1 : 0);
-
- break;
}
+ break;
+
case IDC_BKG_NUM_POINTS:
case IDC_BKG_COLOR_DIFFERENCE:
- if (HIWORD(wParam)!=EN_CHANGE || (HWND)lParam!=GetFocus())
+ if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())
break;
+
case IDC_MAKETRANSPBKG:
{
BOOL enable = IsDlgButtonChecked(hwndDlg, IDC_MAKETRANSPBKG);
@@ -847,54 +831,50 @@ static INT_PTR CALLBACK DlgProcAvatarUserInfo(HWND hwndDlg, UINT msg, WPARAM wPa EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), enable);
EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), enable);
EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), enable);
-
- SendMessage(hwndDlg, DM_REALODAVATAR, 0, 0);
- break;
}
+ SendMessage(hwndDlg, DM_REALODAVATAR, 0, 0);
+ break;
case IDC_RESET:
+ ProtectAvatar(hContact, 0);
+ if (MessageBox(0, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) {
+ DBVARIANT dbv = { 0 };
+ if (!db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
+ DeleteFile(dbv.ptszVal);
+ db_free(&dbv);
+ }
+ }
+ db_unset(hContact, "ContactPhoto", "Locked");
+ db_unset(hContact, "ContactPhoto", "Backup");
+ db_unset(hContact, "ContactPhoto", "RFile");
+ db_unset(hContact, "ContactPhoto", "File");
+ db_unset(hContact, "ContactPhoto", "Format");
{
char *szProto = GetContactProto(hContact);
- DBVARIANT dbv = {0};
-
- ProtectAvatar(hContact, 0);
- if (MessageBox(0, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) {
- if ( !db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
- DeleteFile(dbv.ptszVal);
- db_free(&dbv);
- }
- }
- db_unset(hContact, "ContactPhoto", "Locked");
- db_unset(hContact, "ContactPhoto", "Backup");
- db_unset(hContact, "ContactPhoto", "RFile");
- db_unset(hContact, "ContactPhoto", "File");
- db_unset(hContact, "ContactPhoto", "Format");
db_unset(hContact, szProto, "AvatarHash");
db_unset(hContact, szProto, "AvatarSaved");
DeleteAvatarFromCache(hContact, FALSE);
QueueAdd(hContact);
- break;
}
- case IDC_DELETE:
- {
- DBVARIANT dbv = {0};
+ break;
- ProtectAvatar(hContact, 0);
- if (MessageBox(0, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) {
- if ( !db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
- DeleteFile(dbv.ptszVal);
- db_free(&dbv);
- }
+ case IDC_DELETE:
+ ProtectAvatar(hContact, 0);
+ if (MessageBox(0, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) {
+ DBVARIANT dbv = { 0 };
+ if (!db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
+ DeleteFile(dbv.ptszVal);
+ db_free(&dbv);
}
- db_unset(hContact, "ContactPhoto", "Locked");
- db_unset(hContact, "ContactPhoto", "Backup");
- db_unset(hContact, "ContactPhoto", "RFile");
- db_unset(hContact, "ContactPhoto", "File");
- db_unset(hContact, "ContactPhoto", "Format");
- DeleteAvatarFromCache(hContact, FALSE);
- SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0);
- break;
}
+ db_unset(hContact, "ContactPhoto", "Locked");
+ db_unset(hContact, "ContactPhoto", "Backup");
+ db_unset(hContact, "ContactPhoto", "RFile");
+ db_unset(hContact, "ContactPhoto", "File");
+ db_unset(hContact, "ContactPhoto", "Format");
+ DeleteAvatarFromCache(hContact, FALSE);
+ SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0);
+ break;
}
break;
@@ -923,11 +903,11 @@ static char* GetSelectedProtocol(HWND hwndDlg) return NULL;
// Get protocol name
- LVITEM item = {0};
+ LVITEM item = { 0 };
item.mask = LVIF_PARAM;
item.iItem = iItem;
SendMessage(hwndList, LVM_GETITEMA, 0, (LPARAM)&item);
- return ( char* ) item.lParam;
+ return (char*)item.lParam;
}
static void EnableDisableControls(HWND hwndDlg, char *proto)
@@ -946,8 +926,8 @@ static void EnableDisableControls(HWND hwndDlg, char *proto) EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE), TRUE);
int width, height;
- SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM) &width, (LPARAM) &height);
- EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), (LPARAM) width != 0 || height != 0);
+ SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM)&width, (LPARAM)&height);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), (LPARAM)width != 0 || height != 0);
}
}
}
@@ -958,8 +938,8 @@ static void EnableDisableControls(HWND hwndDlg, char *proto) EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), TRUE);
else {
int width, height;
- SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM) &width, (LPARAM) &height);
- EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), (LPARAM) width != 0 || height != 0);
+ SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM)&width, (LPARAM)&height);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), (LPARAM)width != 0 || height != 0);
}
}
}
@@ -991,12 +971,11 @@ static void EnableDisableProtocols(HWND hwndDlg, BOOL init) }
char * proto = GetSelectedProtocol(hwndDlg);
- if (proto == NULL)
- {
+ if (proto == NULL) {
ListView_SetItemState(hwndList, 0, LVIS_FOCUSED | LVIS_SELECTED, 0x0F);
}
else {
- SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, (LPARAM) proto);
+ SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, (LPARAM)proto);
EnableDisableControls(hwndDlg, proto);
}
}
@@ -1017,14 +996,14 @@ static void EnableDisableProtocols(HWND hwndDlg, BOOL init) static INT_PTR CALLBACK DlgProcAvatarProtoInfo(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
HWND protopic = GetDlgItem(hwndDlg, IDC_PROTOPIC);
- SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM) GetSysColor(COLOR_BTNSHADOW));
- SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM) LPGENT("No avatar"));
- SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM) FALSE);
+ SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNSHADOW));
+ SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENT("No avatar"));
+ SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM)FALSE);
HWND hwndList = GetDlgItem(hwndDlg, IDC_PROTOCOLS);
ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_SUBITEMIMAGES);
@@ -1032,12 +1011,12 @@ static INT_PTR CALLBACK DlgProcAvatarProtoInfo(HWND hwndDlg, UINT msg, WPARAM wP HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0);
ListView_SetImageList(hwndList, hIml, LVSIL_SMALL);
- LVCOLUMN lvc = {0};
+ LVCOLUMN lvc = { 0 };
lvc.mask = LVCF_FMT;
lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT;
ListView_InsertColumn(hwndList, 0, &lvc);
- LVITEM item = {0};
+ LVITEM item = { 0 };
item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
item.iItem = 1000;
@@ -1045,15 +1024,15 @@ static INT_PTR CALLBACK DlgProcAvatarProtoInfo(HWND hwndDlg, UINT msg, WPARAM wP PROTOACCOUNT **accs;
int count, num = 0;
- ProtoEnumAccounts( &count, &accs );
+ ProtoEnumAccounts(&count, &accs);
for (int i = 0; i < count; i++) {
- if ( !ProtoServiceExists( accs[i]->szModuleName, PS_GETMYAVATAR))
+ if (!ProtoServiceExists(accs[i]->szModuleName, PS_GETMYAVATAR))
continue;
- if ( !Proto_IsAvatarsEnabled( accs[i]->szModuleName ))
+ if (!Proto_IsAvatarsEnabled(accs[i]->szModuleName))
continue;
- ImageList_AddIcon(hIml, LoadSkinnedProtoIcon( accs[i]->szModuleName, ID_STATUS_ONLINE));
+ ImageList_AddIcon(hIml, LoadSkinnedProtoIcon(accs[i]->szModuleName, ID_STATUS_ONLINE));
item.pszText = accs[i]->tszAccountName;
item.iImage = num;
item.lParam = (LPARAM)accs[i]->szModuleName;
@@ -1073,35 +1052,30 @@ static INT_PTR CALLBACK DlgProcAvatarProtoInfo(HWND hwndDlg, UINT msg, WPARAM wP case WM_NOTIFY:
{
- LPNMHDR nm = (LPNMHDR) lParam;
- switch(nm->idFrom) {
+ LPNMHDR nm = (LPNMHDR)lParam;
+ switch (nm->idFrom) {
case IDC_PROTOCOLS:
switch (nm->code) {
case LVN_ITEMCHANGED:
- {
- LPNMLISTVIEW li = (LPNMLISTVIEW) nm;
- if (li->uNewState & LVIS_SELECTED)
- {
- SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, li->lParam);
- EnableDisableControls(hwndDlg, ( char* ) li->lParam);
- }
+ LPNMLISTVIEW li = (LPNMLISTVIEW)nm;
+ if (li->uNewState & LVIS_SELECTED) {
+ SendDlgItemMessage(hwndDlg, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, li->lParam);
+ EnableDisableControls(hwndDlg, (char*)li->lParam);
}
- break;
}
break;
case IDC_PROTOPIC:
- switch (nm->code) {
- case NM_AVATAR_CHANGED:
+ if (nm->code == NM_AVATAR_CHANGED) {
EnableDisableControls(hwndDlg, GetSelectedProtocol(hwndDlg));
break;
}
- break;
}
- break;
}
+ break;
+
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case IDC_CHANGE:
if (!IsDlgButtonChecked(hwndDlg, IDC_PER_PROTO))
avSetMyAvatar(NULL, NULL);
@@ -1123,7 +1097,7 @@ static INT_PTR CALLBACK DlgProcAvatarProtoInfo(HWND hwndDlg, UINT msg, WPARAM wP break;
char description[256];
- CallProtoService(proto, PS_GETNAME, SIZEOF(description),(LPARAM) description);
+ CallProtoService(proto, PS_GETNAME, SIZEOF(description), (LPARAM)description);
TCHAR *descr = mir_a2t(description);
if (MessageBox(hwndDlg, TranslateT("Are you sure you want to remove your avatar?"), descr, MB_YESNO) == IDYES)
avSetMyAvatar(proto, _T(""));
diff --git a/plugins/AVS/src/poll.cpp b/plugins/AVS/src/poll.cpp index bb52ee316f..08c3170edc 100644 --- a/plugins/AVS/src/poll.cpp +++ b/plugins/AVS/src/poll.cpp @@ -51,11 +51,6 @@ int Proto_GetDelayAfterFail(const char *proto); BOOL Proto_IsFetchingWhenProtoNotVisibleAllowed(const char *proto);
BOOL Proto_IsFetchingWhenContactOfflineAllowed(const char *proto);
-#ifdef _DEBUG
-int _DebugTrace(const char *fmt, ...);
-int _DebugTrace(MCONTACT hContact, const char *fmt, ...);
-#endif
-
// Functions ////////////////////////////////////////////////////////////////////////////
// Items with higher priority at end
@@ -68,7 +63,7 @@ static OBJLIST<QueueItem> queue(20, QueueSortItems); static CRITICAL_SECTION cs;
static int waitTime;
-void InitPolls()
+void InitPolls()
{
waitTime = REQUEST_WAIT_TIME;
InitializeCriticalSection(&cs);
@@ -77,7 +72,7 @@ void InitPolls() mir_forkthread(RequestThread, NULL);
}
-void UninitPolls()
+void UninitPolls()
{
DeleteCriticalSection(&cs);
queue.destroy();
@@ -116,7 +111,7 @@ static void QueueRemove(MCONTACT hContact) {
mir_cslock lck(cs);
- for (int i = queue.getCount()-1 ; i >= 0 ; i-- ) {
+ for (int i = queue.getCount() - 1; i >= 0; i--) {
QueueItem& item = queue[i];
if (item.hContact == hContact)
queue.remove(i);
@@ -131,7 +126,7 @@ static void QueueAdd(MCONTACT hContact, int waitTime) mir_cslock lck(cs);
// Only add if not exists yet
- for (int i = queue.getCount()-1; i >= 0; i--)
+ for (int i = queue.getCount() - 1; i >= 0; i--)
if (queue[i].hContact == hContact)
return;
@@ -163,17 +158,15 @@ void ProcessAvatarInfo(MCONTACT hContact, int type, PROTO_AVATAR_INFORMATIONT *p db_set_ts(hContact, "ContactPhoto", "File", pai->filename);
db_set_w(hContact, "ContactPhoto", "Format", pai->format);
- if (pai->format == PA_FORMAT_PNG || pai->format == PA_FORMAT_JPEG
- || pai->format == PA_FORMAT_ICON || pai->format == PA_FORMAT_BMP
- || pai->format == PA_FORMAT_GIF) {
+ if (pai->format == PA_FORMAT_PNG || pai->format == PA_FORMAT_JPEG
+ || pai->format == PA_FORMAT_ICON || pai->format == PA_FORMAT_BMP
+ || pai->format == PA_FORMAT_GIF) {
// We can load it!
MakePathRelative(hContact, pai->filename);
ChangeAvatar(hContact, TRUE, TRUE, pai->format);
}
- else {
- // As we can't load it, notify but don't load
+ else // As we can't load it, notify but don't load
ChangeAvatar(hContact, FALSE, TRUE, pai->format);
- }
}
else if (type == GAIR_NOAVATAR) {
db_unset(hContact, "ContactPhoto", "NeedUpdate");
@@ -210,20 +203,20 @@ int FetchAvatarFor(MCONTACT hContact, char *szProto) if (szProto != NULL && PollProtocolCanHaveAvatar(szProto) && PollContactCanHaveAvatar(hContact, szProto)) {
// Can have avatar, but must request it?
- if ((g_AvatarHistoryAvail && CallService(MS_AVATARHISTORY_ENABLED, hContact, 0))
- || (PollCheckProtocol(szProto) && PollCheckContact(hContact, szProto)))
+ if ((g_AvatarHistoryAvail && CallService(MS_AVATARHISTORY_ENABLED, hContact, 0)) ||
+ (PollCheckProtocol(szProto) && PollCheckContact(hContact, szProto)))
{
// Request it
- PROTO_AVATAR_INFORMATIONT pai_s = {0};
+ PROTO_AVATAR_INFORMATIONT pai_s = { 0 };
pai_s.cbSize = sizeof(pai_s);
pai_s.hContact = hContact;
INT_PTR res = CallProtoService(szProto, PS_GETAVATARINFOT, GAIF_FORCE, (LPARAM)&pai_s);
if (res == CALLSERVICE_NOTFOUND) {
- PROTO_AVATAR_INFORMATION pai = {0};
+ PROTO_AVATAR_INFORMATION pai = { 0 };
pai.cbSize = sizeof(pai);
pai.hContact = hContact;
res = CallProtoService(szProto, PS_GETAVATARINFO, GAIF_FORCE, (LPARAM)&pai);
- MultiByteToWideChar( CP_ACP, 0, pai.filename, -1, pai_s.filename, SIZEOF(pai_s.filename));
+ MultiByteToWideChar(CP_ACP, 0, pai.filename, -1, pai_s.filename, SIZEOF(pai_s.filename));
pai_s.format = pai.format;
}
@@ -240,7 +233,7 @@ static void RequestThread(void *vParam) while (!g_shutDown) {
EnterCriticalSection(&cs);
- if ( queue.getCount() == 0 ) {
+ if (queue.getCount() == 0) {
// No items, so suspend thread
LeaveCriticalSection(&cs);
mir_sleep(POOL_DELAY);
@@ -248,7 +241,7 @@ static void RequestThread(void *vParam) }
// Take a look at first item
- QueueItem& qi = queue[ queue.getCount()-1 ];
+ QueueItem& qi = queue[queue.getCount() - 1];
if (qi.check_time > GetTickCount()) {
// Not time to request yet, wait...
LeaveCriticalSection(&cs);
@@ -258,17 +251,17 @@ static void RequestThread(void *vParam) // Will request this item
MCONTACT hContact = qi.hContact;
- queue.remove( queue.getCount()-1 );
+ queue.remove(queue.getCount() - 1);
QueueRemove(hContact);
LeaveCriticalSection(&cs);
if (FetchAvatarFor(hContact) == GAIR_WAITFOR) {
// Mark to not request this contact avatar for more 30 min
- {
- mir_cslock lock(cs);
- QueueRemove(hContact);
- QueueAdd(hContact, REQUEST_WAITFOR_WAIT_TIME);
- }
+ {
+ mir_cslock lock(cs);
+ QueueRemove(hContact);
+ QueueAdd(hContact, REQUEST_WAITFOR_WAIT_TIME);
+ }
// Wait a little until requesting again
mir_sleep(REQUEST_DELAY);
diff --git a/plugins/AVS/src/services.cpp b/plugins/AVS/src/services.cpp index 7c9354ea06..24d4579e6b 100644 --- a/plugins/AVS/src/services.cpp +++ b/plugins/AVS/src/services.cpp @@ -67,28 +67,29 @@ INT_PTR ProtectAvatar(WPARAM hContact, LPARAM lParam) * image filename (will be checked for existance, though)
*/
-struct OpenFileSubclassData {
+struct OpenFileSubclassData
+{
BYTE *locking_request;
BYTE setView;
};
UINT_PTR CALLBACK OpenFileSubclass(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- OpenFileSubclassData *data= (OpenFileSubclassData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ OpenFileSubclassData *data = (OpenFileSubclassData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
- {
- OPENFILENAME *ofn = (OPENFILENAME *)lParam;
+ {
+ OPENFILENAME *ofn = (OPENFILENAME *)lParam;
- data = (OpenFileSubclassData *) malloc(sizeof(OpenFileSubclassData));
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data);
- data->locking_request = (BYTE *)ofn->lCustData;
- data->setView = TRUE;
+ data = (OpenFileSubclassData *)malloc(sizeof(OpenFileSubclassData));
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data);
+ data->locking_request = (BYTE *)ofn->lCustData;
+ data->setView = TRUE;
- TranslateDialogDefault(hwnd);
- CheckDlgButton(hwnd, IDC_PROTECTAVATAR, *(data->locking_request));
- }
+ TranslateDialogDefault(hwnd);
+ CheckDlgButton(hwnd, IDC_PROTECTAVATAR, *(data->locking_request));
+ }
break;
case WM_COMMAND:
@@ -99,7 +100,7 @@ UINT_PTR CALLBACK OpenFileSubclass(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP case WM_NOTIFY:
if (data->setView) {
HWND hwndParent = GetParent(hwnd);
- HWND hwndLv = FindWindowEx(hwndParent, NULL, _T("SHELLDLL_DefView"), NULL) ;
+ HWND hwndLv = FindWindowEx(hwndParent, NULL, _T("SHELLDLL_DefView"), NULL);
if (hwndLv != NULL) {
SendMessage(hwndLv, WM_COMMAND, SHVIEW_THUMBNAIL, 0);
data->setView = FALSE;
@@ -129,12 +130,12 @@ static INT_PTR avSetAvatar(MCONTACT hContact, TCHAR *tszPath) is_locked = db_get_b(hContact, "ContactPhoto", "Locked", 0);
- if ( tszPath == NULL ) {
- OPENFILENAME ofn = {0};
+ if (tszPath == NULL) {
+ OPENFILENAME ofn = { 0 };
TCHAR filter[256];
filter[0] = '\0';
- CallService(MS_UTILS_GETBITMAPFILTERSTRINGST, SIZEOF(filter), ( LPARAM )filter);
+ CallService(MS_UTILS_GETBITMAPFILTERSTRINGST, SIZEOF(filter), (LPARAM)filter);
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = 0;
@@ -172,7 +173,7 @@ static INT_PTR avSetAvatar(MCONTACT hContact, TCHAR *tszPath) CloseHandle(hFile);
- AVS_pathToRelative(szFinalName, szBackupName);
+ PathToRelativeT(szFinalName, szBackupName, g_szDataPath);
db_set_ts(hContact, "ContactPhoto", "Backup", szBackupName);
db_set_b(hContact, "ContactPhoto", "Locked", is_locked);
@@ -200,7 +201,7 @@ INT_PTR SetAvatarW(WPARAM wParam, LPARAM lParam) static INT_PTR CanSetMyAvatar(WPARAM wParam, LPARAM lParam)
{
- char *protocol = (char *) wParam;
+ char *protocol = (char *)wParam;
if (protocol == NULL || fei == NULL)
return 0;
@@ -219,40 +220,36 @@ static int InternalRemoveMyAvatar(char *protocol) // Remove avatar
int ret = 0;
- if (protocol != NULL)
- {
- if ( ProtoServiceExists(protocol, PS_SETMYAVATAR))
+ if (protocol != NULL) {
+ if (ProtoServiceExists(protocol, PS_SETMYAVATAR))
ret = SaveAvatar(protocol, NULL);
else
ret = -3;
- if (ret == 0)
- {
+ if (ret == 0) {
// Has global avatar?
- DBVARIANT dbv = {0};
- if ( !db_get_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", &dbv)) {
+ DBVARIANT dbv = { 0 };
+ if (!db_get_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", &dbv)) {
db_free(&dbv);
db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1);
DeleteGlobalUserAvatar();
}
}
}
- else
- {
+ else {
PROTOACCOUNT **accs;
- int i,count;
+ int i, count;
- ProtoEnumAccounts( &count, &accs );
- for (i = 0; i < count; i++)
- {
- if ( !ProtoServiceExists( accs[i]->szModuleName, PS_SETMYAVATAR))
+ ProtoEnumAccounts(&count, &accs);
+ for (i = 0; i < count; i++) {
+ if (!ProtoServiceExists(accs[i]->szModuleName, PS_SETMYAVATAR))
continue;
- if (!Proto_IsAvatarsEnabled( accs[i]->szModuleName ))
+ if (!Proto_IsAvatarsEnabled(accs[i]->szModuleName))
continue;
// Found a protocol
- int retTmp = SaveAvatar( accs[i]->szModuleName, NULL);
+ int retTmp = SaveAvatar(accs[i]->szModuleName, NULL);
if (retTmp != 0)
ret = retTmp;
}
@@ -267,7 +264,7 @@ static int InternalRemoveMyAvatar(char *protocol) SetIgnoreNotify(protocol, FALSE);
- ReportMyAvatarChanged(WPARAM((protocol == NULL ) ? "" : protocol), 0);
+ ReportMyAvatarChanged(WPARAM((protocol == NULL) ? "" : protocol), 0);
return ret;
}
@@ -276,60 +273,58 @@ static void FilterGetStrings(TCHAR *filter, int bytesLeft, BOOL xml, BOOL swf) TCHAR *pfilter;
int wParam = bytesLeft;
- lstrcpyn(filter, TranslateT("All Files"), bytesLeft); bytesLeft-=lstrlen(filter);
+ lstrcpyn(filter, TranslateT("All Files"), bytesLeft); bytesLeft -= lstrlen(filter);
_tcsncat(filter, _T(" (*.bmp;*.jpg;*.gif;*.png"), bytesLeft);
if (swf) _tcscat(filter, _T(";*.swf"));
if (xml) _tcscat(filter, _T(";*.xml"));
_tcscat(filter, _T(")"));
- pfilter=filter+lstrlen(filter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter = filter + lstrlen(filter) + 1; bytesLeft = wParam - (pfilter - filter);
lstrcpyn(pfilter, _T("*.BMP;*.RLE;*.JPG;*.JPEG;*.GIF;*.PNG"), bytesLeft);
if (swf) _tcscat(pfilter, _T(";*.SWF"));
if (xml) _tcscat(pfilter, _T(";*.XML"));
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
- lstrcpyn(pfilter, TranslateT("Windows Bitmaps"), bytesLeft); bytesLeft-=lstrlen(pfilter);
+ lstrcpyn(pfilter, TranslateT("Windows Bitmaps"), bytesLeft); bytesLeft -= lstrlen(pfilter);
_tcsncat(pfilter, _T(" (*.bmp;*.rle)"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
lstrcpyn(pfilter, _T("*.BMP;*.RLE"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
- lstrcpyn(pfilter,TranslateT("JPEG Bitmaps"),bytesLeft); bytesLeft-=lstrlen(pfilter);
+ lstrcpyn(pfilter, TranslateT("JPEG Bitmaps"), bytesLeft); bytesLeft -= lstrlen(pfilter);
_tcsncat(pfilter, _T(" (*.jpg;*.jpeg)"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
lstrcpyn(pfilter, _T("*.JPG;*.JPEG"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
- lstrcpyn(pfilter,TranslateT("GIF Bitmaps"),bytesLeft); bytesLeft-=lstrlen(pfilter);
+ lstrcpyn(pfilter, TranslateT("GIF Bitmaps"), bytesLeft); bytesLeft -= lstrlen(pfilter);
_tcsncat(pfilter, _T(" (*.gif)"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
lstrcpyn(pfilter, _T("*.GIF"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
- lstrcpyn(pfilter,TranslateT("PNG Bitmaps"), bytesLeft); bytesLeft-=lstrlen(pfilter);
+ lstrcpyn(pfilter, TranslateT("PNG Bitmaps"), bytesLeft); bytesLeft -= lstrlen(pfilter);
_tcsncat(pfilter, _T(" (*.png)"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
lstrcpyn(pfilter, _T("*.PNG"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
- if (swf)
- {
- lstrcpyn(pfilter,TranslateT("Flash Animations"), bytesLeft); bytesLeft-=lstrlen(pfilter);
+ if (swf) {
+ lstrcpyn(pfilter, TranslateT("Flash Animations"), bytesLeft); bytesLeft -= lstrlen(pfilter);
_tcsncat(pfilter, _T(" (*.swf)"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
lstrcpyn(pfilter, _T("*.SWF"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
}
- if (xml)
- {
- lstrcpyn(pfilter, TranslateT("XML Files"), bytesLeft); bytesLeft-=lstrlen(pfilter);
+ if (xml) {
+ lstrcpyn(pfilter, TranslateT("XML Files"), bytesLeft); bytesLeft -= lstrlen(pfilter);
_tcsncat(pfilter, _T(" (*.xml)"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
lstrcpyn(pfilter, _T("*.XML"), bytesLeft);
- pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
+ pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter);
}
- if (bytesLeft) *pfilter='\0';
+ if (bytesLeft) *pfilter = '\0';
}
/*
@@ -337,59 +332,58 @@ static void FilterGetStrings(TCHAR *filter, int bytesLeft, BOOL xml, BOOL swf) */
static UINT_PTR CALLBACK SetMyAvatarHookProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
- {
- hwndSetMyAvatar = hwnd;
+ {
+ hwndSetMyAvatar = hwnd;
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
- OPENFILENAME *ofn = (OPENFILENAME *)lParam;
- SetMyAvatarHookData *data = (SetMyAvatarHookData *) ofn->lCustData;
- data->thumbnail = TRUE;
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
+ OPENFILENAME *ofn = (OPENFILENAME *)lParam;
+ SetMyAvatarHookData *data = (SetMyAvatarHookData *)ofn->lCustData;
+ data->thumbnail = TRUE;
- SetWindowText(GetDlgItem(hwnd, IDC_MAKE_SQUARE), TranslateT("Make the avatar square"));
- SetWindowText(GetDlgItem(hwnd, IDC_GROW), TranslateT("Grow avatar to fit max allowed protocol size"));
+ SetWindowText(GetDlgItem(hwnd, IDC_MAKE_SQUARE), TranslateT("Make the avatar square"));
+ SetWindowText(GetDlgItem(hwnd, IDC_GROW), TranslateT("Grow avatar to fit max allowed protocol size"));
- CheckDlgButton(hwnd, IDC_MAKE_SQUARE, data->square ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwnd, IDC_GROW, data->grow ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwnd, IDC_MAKE_SQUARE, data->square ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwnd, IDC_GROW, data->grow ? BST_CHECKED : BST_UNCHECKED);
- if (data->protocol != NULL && (Proto_AvatarImageProportion(data->protocol) & PIP_SQUARE))
- EnableWindow(GetDlgItem(hwnd, IDC_MAKE_SQUARE), FALSE);
- }
+ if (data->protocol != NULL && (Proto_AvatarImageProportion(data->protocol) & PIP_SQUARE))
+ EnableWindow(GetDlgItem(hwnd, IDC_MAKE_SQUARE), FALSE);
+ }
break;
case WM_NOTIFY:
- {
- OPENFILENAME *ofn = (OPENFILENAME *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- SetMyAvatarHookData *data = (SetMyAvatarHookData *) ofn->lCustData;
- if (data->thumbnail)
- {
- HWND hwndParent = GetParent(hwnd);
- HWND hwndLv = FindWindowEx(hwndParent, NULL, _T("SHELLDLL_DefView"), NULL) ;
- if (hwndLv != NULL)
- {
- SendMessage(hwndLv, WM_COMMAND, SHVIEW_THUMBNAIL, 0);
- data->thumbnail = FALSE;
- }
+ {
+ OPENFILENAME *ofn = (OPENFILENAME *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ SetMyAvatarHookData *data = (SetMyAvatarHookData *)ofn->lCustData;
+ if (data->thumbnail) {
+ HWND hwndParent = GetParent(hwnd);
+ HWND hwndLv = FindWindowEx(hwndParent, NULL, _T("SHELLDLL_DefView"), NULL);
+ if (hwndLv != NULL) {
+ SendMessage(hwndLv, WM_COMMAND, SHVIEW_THUMBNAIL, 0);
+ data->thumbnail = FALSE;
}
- break;
}
+ break;
+ }
case WM_DESTROY:
- {
- OPENFILENAME *ofn = (OPENFILENAME *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- SetMyAvatarHookData *data = (SetMyAvatarHookData *) ofn->lCustData;
- data->square = IsDlgButtonChecked(hwnd, IDC_MAKE_SQUARE);
- data->grow = IsDlgButtonChecked(hwnd, IDC_GROW);
-
- hwndSetMyAvatar = NULL;
- break;
- }
+ {
+ OPENFILENAME *ofn = (OPENFILENAME *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ SetMyAvatarHookData *data = (SetMyAvatarHookData *)ofn->lCustData;
+ data->square = IsDlgButtonChecked(hwnd, IDC_MAKE_SQUARE);
+ data->grow = IsDlgButtonChecked(hwnd, IDC_GROW);
+
+ hwndSetMyAvatar = NULL;
+ break;
+ }
}
return 0;
}
-struct SaveProtocolData {
+struct SaveProtocolData
+{
DWORD max_size;
TCHAR image_file_name[MAX_PATH];
BOOL saved;
@@ -402,11 +396,11 @@ struct SaveProtocolData { void SaveImage(SaveProtocolData &d, char *protocol, int format)
{
- if ( !Proto_IsAvatarFormatSupported(protocol, format))
+ if (!Proto_IsAvatarFormatSupported(protocol, format))
return;
mir_sntprintf(d.image_file_name, SIZEOF(d.image_file_name), _T("%s%s"), d.temp_file, ProtoGetAvatarExtension(format));
- if ( BmpFilterSaveBitmapT(d.hBmpProto, d.image_file_name, format == PA_FORMAT_JPEG ? JPEG_QUALITYSUPERB : 0))
+ if (BmpFilterSaveBitmapT(d.hBmpProto, d.image_file_name, format == PA_FORMAT_JPEG ? JPEG_QUALITYSUPERB : 0))
return;
if (d.max_size != 0 && GetFileSize(d.image_file_name) > d.max_size) {
@@ -434,16 +428,14 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam // If is swf or xml, just set it
- if (originalFormat == PA_FORMAT_SWF)
- {
+ if (originalFormat == PA_FORMAT_SWF) {
if (!Proto_IsAvatarFormatSupported(protocol, PA_FORMAT_SWF))
return -1;
return SaveAvatar(protocol, originalFilename);
}
- if (originalFormat == PA_FORMAT_XML)
- {
+ if (originalFormat == PA_FORMAT_XML) {
if (!Proto_IsAvatarFormatSupported(protocol, PA_FORMAT_XML))
return -1;
@@ -451,9 +443,9 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam }
// Get protocol info
- SaveProtocolData d = {0};
+ SaveProtocolData d = { 0 };
- d.max_size = (DWORD) Proto_GetAvatarMaxFileSize(protocol);
+ d.max_size = (DWORD)Proto_GetAvatarMaxFileSize(protocol);
Proto_GetAvatarMaxSize(protocol, &d.width, &d.height);
int orig_width = d.width;
@@ -472,12 +464,11 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam rb.max_height = d.height;
rb.max_width = d.width;
rb.fit = (grow ? 0 : RESIZEBITMAP_FLAG_DONT_GROW)
- | (square ? RESIZEBITMAP_MAKE_SQUARE : RESIZEBITMAP_KEEP_PROPORTIONS);
+ | (square ? RESIZEBITMAP_MAKE_SQUARE : RESIZEBITMAP_KEEP_PROPORTIONS);
- d.hBmpProto = (HBITMAP) BmpFilterResizeBitmap((WPARAM)&rb, 0);
+ d.hBmpProto = (HBITMAP)BmpFilterResizeBitmap((WPARAM)&rb, 0);
- if (d.hBmpProto == NULL)
- {
+ if (d.hBmpProto == NULL) {
if (d.temp_file[0] != '\0')
DeleteFile(d.temp_file);
return -1;
@@ -485,9 +476,8 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam // Check if can use original image
if (d.hBmpProto == hBmp
- && Proto_IsAvatarFormatSupported(protocol, originalFormat)
- && (d.max_size == 0 || GetFileSize(originalFilename) < d.max_size))
- {
+ && Proto_IsAvatarFormatSupported(protocol, originalFormat)
+ && (d.max_size == 0 || GetFileSize(originalFilename) < d.max_size)) {
if (d.temp_file[0] != '\0')
DeleteFile(d.temp_file);
@@ -496,12 +486,10 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam }
// Create a temporary file (if was not created already)
- if (d.temp_file[0] == '\0')
- {
+ if (d.temp_file[0] == '\0') {
d.temp_file[0] = '\0';
if (GetTempPath(MAX_PATH, d.temp_file) == 0
- || GetTempFileName(d.temp_file, _T("mir_av_"), 0, d.temp_file) == 0)
- {
+ || GetTempFileName(d.temp_file, _T("mir_av_"), 0, d.temp_file) == 0) {
DeleteObject(d.hBmpProto);
return -1;
}
@@ -526,8 +514,7 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam SaveImage(d, protocol, PA_FORMAT_BMP);
num_tries++;
- if (!d.saved && d.need_smaller_size && num_tries < 4)
- {
+ if (!d.saved && d.need_smaller_size && num_tries < 4) {
// Cleanup
if (d.hBmpProto != hBmp)
DeleteObject(d.hBmpProto);
@@ -537,18 +524,17 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam d.height = orig_height * (4 - num_tries) / 4;
}
- } while(!d.saved && d.need_smaller_size && num_tries < 4);
+ }
+ while (!d.saved && d.need_smaller_size && num_tries < 4);
int ret;
- if (d.saved)
- {
+ if (d.saved) {
// Call proto service
ret = SaveAvatar(protocol, d.image_file_name);
DeleteFile(d.image_file_name);
}
- else
- {
+ else {
ret = -1;
}
@@ -575,20 +561,17 @@ static int InternalSetMyAvatar(char *protocol, TCHAR *szFinalName, SetMyAvatarHo HBITMAP hBmp = NULL;
- if (format == PA_FORMAT_SWF)
- {
+ if (format == PA_FORMAT_SWF) {
if (!allAcceptSWF)
return -4;
}
- else if (format == PA_FORMAT_XML)
- {
+ else if (format == PA_FORMAT_XML) {
if (!allAcceptXML)
return -4;
}
- else
- {
+ else {
// Try to open if is not a flash or XML
- hBmp = (HBITMAP) CallService(MS_IMG_LOAD, (WPARAM) szFinalName, IMGL_TCHAR);
+ hBmp = (HBITMAP)CallService(MS_IMG_LOAD, (WPARAM)szFinalName, IMGL_TCHAR);
if (hBmp == NULL)
return -4;
}
@@ -596,103 +579,88 @@ static int InternalSetMyAvatar(char *protocol, TCHAR *szFinalName, SetMyAvatarHo SetIgnoreNotify(protocol, TRUE);
int ret = 0;
- if (protocol != NULL)
- {
+ if (protocol != NULL) {
ret = SetProtoMyAvatar(protocol, hBmp, szFinalName, format, data.square, data.grow);
- if (ret == 0)
- {
+ if (ret == 0) {
DeleteGlobalUserAvatar();
db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1);
}
}
- else
- {
+ else {
PROTOACCOUNT **accs;
- int i,count;
+ int i, count;
- ProtoEnumAccounts( &count, &accs );
- for (i = 0; i < count; i++)
- {
- if ( !ProtoServiceExists( accs[i]->szModuleName, PS_SETMYAVATAR))
+ ProtoEnumAccounts(&count, &accs);
+ for (i = 0; i < count; i++) {
+ if (!ProtoServiceExists(accs[i]->szModuleName, PS_SETMYAVATAR))
continue;
- if ( !Proto_IsAvatarsEnabled( accs[i]->szModuleName ))
+ if (!Proto_IsAvatarsEnabled(accs[i]->szModuleName))
continue;
- int retTmp = SetProtoMyAvatar( accs[i]->szModuleName, hBmp, szFinalName, format, data.square, data.grow);
+ int retTmp = SetProtoMyAvatar(accs[i]->szModuleName, hBmp, szFinalName, format, data.square, data.grow);
if (retTmp != 0)
ret = retTmp;
}
DeleteGlobalUserAvatar();
- if (ret)
- {
+ if (ret) {
db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1);
}
- else
- {
+ else {
// Copy avatar file to store as global one
TCHAR globalFile[1024];
BOOL saved = TRUE;
- if (FoldersGetCustomPathT(hGlobalAvatarFolder, globalFile, SIZEOF(globalFile), _T("")))
- {
- mir_sntprintf(globalFile, SIZEOF(globalFile), _T("%s\\%s"), g_szDataPath, _T("GlobalAvatar"));
+ if (FoldersGetCustomPathT(hGlobalAvatarFolder, globalFile, SIZEOF(globalFile), _T(""))) {
+ mir_sntprintf(globalFile, SIZEOF(globalFile), _T("%s%s"), g_szDataPath, _T("GlobalAvatar"));
CreateDirectory(globalFile, NULL);
}
TCHAR *ext = _tcsrchr(szFinalName, _T('.')); // Can't be NULL here
- if (format == PA_FORMAT_XML || format == PA_FORMAT_SWF)
- {
+ if (format == PA_FORMAT_XML || format == PA_FORMAT_SWF) {
mir_sntprintf(globalFile, SIZEOF(globalFile), _T("%s\\my_global_avatar%s"), globalFile, ext);
CopyFile(szFinalName, globalFile, FALSE);
}
- else
- {
+ else {
// Resize (to avoid too big avatars)
- ResizeBitmap rb = {0};
+ ResizeBitmap rb = { 0 };
rb.size = sizeof(ResizeBitmap);
rb.hBmp = hBmp;
rb.max_height = 300;
rb.max_width = 300;
rb.fit = (data.grow ? 0 : RESIZEBITMAP_FLAG_DONT_GROW)
- | (data.square ? RESIZEBITMAP_MAKE_SQUARE : RESIZEBITMAP_KEEP_PROPORTIONS);
+ | (data.square ? RESIZEBITMAP_MAKE_SQUARE : RESIZEBITMAP_KEEP_PROPORTIONS);
- HBITMAP hBmpTmp = (HBITMAP) BmpFilterResizeBitmap((WPARAM)&rb, 0);
+ HBITMAP hBmpTmp = (HBITMAP)BmpFilterResizeBitmap((WPARAM)&rb, 0);
// Check if need to resize
- if (hBmpTmp == hBmp || hBmpTmp == NULL)
- {
+ if (hBmpTmp == hBmp || hBmpTmp == NULL) {
// Use original image
mir_sntprintf(globalFile, SIZEOF(globalFile), _T("%s\\my_global_avatar%s"), globalFile, ext);
CopyFile(szFinalName, globalFile, FALSE);
}
- else
- {
+ else {
// Save as PNG
mir_sntprintf(globalFile, SIZEOF(globalFile), _T("%s\\my_global_avatar.png"), globalFile);
- if (BmpFilterSaveBitmap((WPARAM) hBmpTmp, (LPARAM) globalFile))
+ if (BmpFilterSaveBitmap((WPARAM)hBmpTmp, (LPARAM)globalFile))
saved = FALSE;
DeleteObject(hBmpTmp);
}
}
- if (saved)
- {
+ if (saved) {
TCHAR relFile[1024];
- if (AVS_pathToRelative(globalFile, relFile))
+ if (PathToRelativeT(globalFile, relFile, g_szDataPath))
db_set_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", relFile);
else
db_set_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", globalFile);
db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 0);
}
- else
- {
- db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1);
- }
+ else db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1);
}
}
@@ -704,7 +672,7 @@ static int InternalSetMyAvatar(char *protocol, TCHAR *szFinalName, SetMyAvatarHo return ret;
}
-INT_PTR avSetMyAvatar( char* protocol, TCHAR* tszPath )
+INT_PTR avSetMyAvatar(char* protocol, TCHAR* tszPath)
{
TCHAR FileName[MAX_PATH];
TCHAR *szFinalName = NULL;
@@ -725,41 +693,38 @@ INT_PTR avSetMyAvatar( char* protocol, TCHAR* tszPath ) SetMyAvatarHookData data = { 0 };
// Check for XML and SWF
- if (protocol == NULL)
- {
+ if (protocol == NULL) {
allAcceptXML = TRUE;
allAcceptSWF = TRUE;
PROTOACCOUNT **accs;
- int i,count;
+ int i, count;
- ProtoEnumAccounts( &count, &accs );
- for (i = 0; i < count; i++)
- {
- if ( !ProtoServiceExists( accs[i]->szModuleName, PS_SETMYAVATAR))
+ ProtoEnumAccounts(&count, &accs);
+ for (i = 0; i < count; i++) {
+ if (!ProtoServiceExists(accs[i]->szModuleName, PS_SETMYAVATAR))
continue;
- if ( !Proto_IsAvatarsEnabled( accs[i]->szModuleName ))
+ if (!Proto_IsAvatarsEnabled(accs[i]->szModuleName))
continue;
- allAcceptXML = allAcceptXML && Proto_IsAvatarFormatSupported( accs[i]->szModuleName, PA_FORMAT_XML);
- allAcceptSWF = allAcceptSWF && Proto_IsAvatarFormatSupported( accs[i]->szModuleName, PA_FORMAT_SWF);
+ allAcceptXML = allAcceptXML && Proto_IsAvatarFormatSupported(accs[i]->szModuleName, PA_FORMAT_XML);
+ allAcceptSWF = allAcceptSWF && Proto_IsAvatarFormatSupported(accs[i]->szModuleName, PA_FORMAT_SWF);
}
data.square = db_get_b(0, AVS_MODULE, "SetAllwaysMakeSquare", 0);
}
- else
- {
+ else {
allAcceptXML = Proto_IsAvatarFormatSupported(protocol, PA_FORMAT_XML);
allAcceptSWF = Proto_IsAvatarFormatSupported(protocol, PA_FORMAT_SWF);
data.protocol = protocol;
data.square = (Proto_AvatarImageProportion(protocol) & PIP_SQUARE)
- || db_get_b(0, AVS_MODULE, "SetAllwaysMakeSquare", 0);
+ || db_get_b(0, AVS_MODULE, "SetAllwaysMakeSquare", 0);
}
if (tszPath == NULL) {
- OPENFILENAME ofn = {0};
+ OPENFILENAME ofn = { 0 };
TCHAR filter[512];
TCHAR inipath[1024];
@@ -780,7 +745,7 @@ INT_PTR avSetMyAvatar( char* protocol, TCHAR* tszPath ) ofn.lpstrInitialDir = inipath;
ofn.lpTemplateName = MAKEINTRESOURCE(IDD_SET_OWN_SUBCLASS);
ofn.lpfnHook = SetMyAvatarHookProc;
- ofn.lCustData = (LPARAM) &data;
+ ofn.lCustData = (LPARAM)&data;
*FileName = '\0';
ofn.lpstrDefExt = _T("");
@@ -789,8 +754,7 @@ INT_PTR avSetMyAvatar( char* protocol, TCHAR* tszPath ) TCHAR title[256];
if (protocol == NULL)
mir_sntprintf(title, SIZEOF(title), TranslateT("Set My Avatar"));
- else
- {
+ else {
TCHAR* prototmp = mir_a2t(protocol);
mir_sntprintf(title, SIZEOF(title), TranslateT("Set My Avatar for %s"), prototmp);
mir_free(prototmp);
@@ -802,27 +766,23 @@ INT_PTR avSetMyAvatar( char* protocol, TCHAR* tszPath ) else
return 1;
}
- else
- szFinalName = (TCHAR *)tszPath;
-
- /*
- * filename is now set, check it and perform all needed action
- */
+ else szFinalName = (TCHAR*)tszPath;
+ // filename is now set, check it and perform all needed action
if (szFinalName[0] == '\0')
return InternalRemoveMyAvatar(protocol);
return InternalSetMyAvatar(protocol, szFinalName, data, allAcceptXML, allAcceptSWF);
}
-static INT_PTR SetMyAvatar( WPARAM wParam, LPARAM lParam )
+static INT_PTR SetMyAvatar(WPARAM wParam, LPARAM lParam)
{
- return avSetMyAvatar(( char* )wParam, _A2T(( const char* )lParam ));
+ return avSetMyAvatar((char*)wParam, _A2T((const char*)lParam));
}
-static INT_PTR SetMyAvatarW( WPARAM wParam, LPARAM lParam )
+static INT_PTR SetMyAvatarW(WPARAM wParam, LPARAM lParam)
{
- return avSetMyAvatar(( char* )wParam, ( TCHAR* )lParam );
+ return avSetMyAvatar((char*)wParam, (TCHAR*)lParam);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -840,9 +800,9 @@ static INT_PTR ContactOptions(WPARAM wParam, LPARAM lParam) INT_PTR DrawAvatarPicture(WPARAM wParam, LPARAM lParam)
{
- AVATARDRAWREQUEST *r = (AVATARDRAWREQUEST *)lParam;
AVATARCACHEENTRY *ace = NULL;
+ AVATARDRAWREQUEST *r = (AVATARDRAWREQUEST*)lParam;
if (fei == NULL || r == NULL || IsBadReadPtr((void *)r, sizeof(AVATARDRAWREQUEST)))
return 0;
@@ -855,7 +815,7 @@ INT_PTR DrawAvatarPicture(WPARAM wParam, LPARAM lParam) for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
protoPicCacheEntry& p = g_ProtoPictures[i];
- if ( !lstrcmpA(p.szProtoname, r->szProto) && lstrlenA(r->szProto) == lstrlenA(p.szProtoname) && p.hbmPic != 0) {
+ if (!lstrcmpA(p.szProtoname, r->szProto) && lstrlenA(r->szProto) == lstrlenA(p.szProtoname) && p.hbmPic != 0) {
ace = (AVATARCACHEENTRY *)&g_ProtoPictures[i];
break;
}
@@ -870,8 +830,7 @@ INT_PTR DrawAvatarPicture(WPARAM wParam, LPARAM lParam) ace = (AVATARCACHEENTRY *)GetMyAvatar(0, (LPARAM)r->szProto);
}
- else
- ace = (AVATARCACHEENTRY *)GetAvatarBitmap((WPARAM)r->hContact, 0);
+ else ace = (AVATARCACHEENTRY *)GetAvatarBitmap((WPARAM)r->hContact, 0);
if (ace && (!(r->dwFlags & AVDRQ_RESPECTHIDDEN) || !(ace->dwFlags & AVS_HIDEONCLIST))) {
ace->t_lastAccess = time(NULL);
@@ -917,9 +876,9 @@ static void ReloadMyAvatar(LPVOID lpParam) if (szProto[0] == 0) {
// Notify to all possibles
if (lstrcmpA(myAvatarProto, szProto)) {
- if (!ProtoServiceExists( myAvatarProto, PS_SETMYAVATAR))
+ if (!ProtoServiceExists(myAvatarProto, PS_SETMYAVATAR))
continue;
- if (!Proto_IsAvatarsEnabled( myAvatarProto ))
+ if (!Proto_IsAvatarsEnabled(myAvatarProto))
continue;
}
@@ -949,7 +908,7 @@ INT_PTR ReportMyAvatarChanged(WPARAM wParam, LPARAM lParam) if (g_MyAvatars[i].dwFlags & AVS_IGNORENOTIFY)
continue;
- if ( !lstrcmpA(g_MyAvatars[i].szProtoname, proto)) {
+ if (!lstrcmpA(g_MyAvatars[i].szProtoname, proto)) {
LPVOID lpParam = (void *)malloc(lstrlenA(g_MyAvatars[i].szProtoname) + 2);
strcpy((char *)lpParam, g_MyAvatars[i].szProtoname);
mir_forkthread(ReloadMyAvatar, lpParam);
diff --git a/plugins/AVS/src/utils.cpp b/plugins/AVS/src/utils.cpp index f1a1809be5..a57bf998f0 100644 --- a/plugins/AVS/src/utils.cpp +++ b/plugins/AVS/src/utils.cpp @@ -19,112 +19,22 @@ Boston, MA 02111-1307, USA. #include "commonheaders.h"
-#ifdef _DEBUG
-
-int _DebugTrace(const char *fmt, ...)
-{
- char debug[2048];
- int ibsize = 2047;
- va_list va;
- va_start(va, fmt);
-
- mir_snprintf(debug, SIZEOF(debug) - 10, " ***** AVS [%08d] [ID:%04x]: ", GetTickCount(), GetCurrentThreadId());
- OutputDebugStringA(debug);
- mir_vsnprintf(debug, ibsize, fmt, va);
- OutputDebugStringA(debug);
- OutputDebugStringA(" ***** \n");
-
- return 0;
-}
-
-int _DebugTrace(MCONTACT hContact, const char *fmt, ...)
-{
- char text[1024];
- size_t len;
- va_list va;
-
- char *name = NULL;
- char *proto = NULL;
- if (hContact != NULL)
- {
- name = (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, 0);
- proto = GetContactProto(hContact);
- }
-
- mir_snprintf(text, SIZEOF(text) - 10, " ***** AVS [%08d] [ID:%04x]: [%08d - %s - %s] ",
- GetTickCount(), GetCurrentThreadId(), hContact, proto == NULL ? "" : proto, name == NULL ? "" : name);
- len = strlen(text);
-
- va_start(va, fmt);
- mir_vsnprintf(&text[len], SIZEOF(text) - len, fmt, va);
- va_end(va);
-
- OutputDebugStringA(text);
- OutputDebugStringA(" ***** \n");
-
- return 0;
-}
-
-#endif
-
void mir_sleep(int time)
{
if (!g_shutDown)
WaitForSingleObject(hShutdownEvent, time);
}
-/*
- * path utilities (make avatar paths relative to *PROFILE* directory, not miranda directory.
- * taken and modified from core services
- */
-
-int AVS_pathIsAbsolute(const TCHAR *path)
-{
- if (!path || !(lstrlen(path) > 2))
- return 0;
- if ((path[1]==':'&&path[2]=='\\')||(path[0]=='\\'&&path[1]=='\\')) return 1;
- return 0;
-}
-
-size_t AVS_pathToRelative(const TCHAR *pSrc, TCHAR *pOut)
-{
- if (!pSrc || !*pSrc || _tcslen(pSrc) > MAX_PATH) return 0;
- if (!AVS_pathIsAbsolute( pSrc ))
- lstrcpyn(pOut, pSrc, MAX_PATH);
- else {
- TCHAR szTmp[MAX_PATH];
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T("%s"), pSrc);
- _tcslwr(szTmp);
- if (_tcsstr(szTmp, g_szDataPath))
- lstrcpyn(pOut, pSrc + _tcslen(g_szDataPath) + 1, MAX_PATH);
- else
- lstrcpyn(pOut, pSrc, MAX_PATH);
- }
- return _tcslen(pOut);
-}
-
-size_t AVS_pathToAbsolute(const TCHAR *pSrc, TCHAR *pOut)
-{
- if (!pSrc || !lstrlen(pSrc) || lstrlen(pSrc) > MAX_PATH)
- return 0;
-
- if (AVS_pathIsAbsolute(pSrc) || !_istalnum(pSrc[0]))
- lstrcpyn(pOut, pSrc, MAX_PATH);
- else
- mir_sntprintf(pOut, MAX_PATH, _T("%s\\%s"), g_szDataPath, pSrc, MAX_PATH);
- return lstrlen(pOut);
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// convert the avatar image path to a relative one...
+// given: contact handle, path to image
-/*
- * convert the avatar image path to a relative one...
- * given: contact handle, path to image
- */
void MakePathRelative(MCONTACT hContact, TCHAR *path)
{
TCHAR szFinalPath[MAX_PATH];
szFinalPath[0] = '\0';
- size_t result = AVS_pathToRelative(path, szFinalPath);
+ size_t result = PathToRelativeT(path, szFinalPath, g_szDataPath);
if (result && szFinalPath[0] != '\0') {
db_set_ts(hContact, "ContactPhoto", "RFile", szFinalPath);
if (!db_get_b(hContact, "ContactPhoto", "Locked", 0))
@@ -132,25 +42,26 @@ void MakePathRelative(MCONTACT hContact, TCHAR *path) }
}
-/*
- * convert the avatar image path to a relative one...
- * given: contact handle
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// convert the avatar image path to a relative one...
+// given: contact handle
void MakePathRelative(MCONTACT hContact)
{
DBVARIANT dbv;
- if ( !db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
+ if (!db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
MakePathRelative(hContact, dbv.ptszVal);
db_free(&dbv);
}
}
+/////////////////////////////////////////////////////////////////////////////////////////
// create the avatar in cache
// returns 0 if not created (no avatar), iIndex otherwise, -2 if has to request avatar, -3 if avatar too big
+
int CreateAvatarInCache(MCONTACT hContact, avatarCacheEntry *ace, char *szProto)
{
- DBVARIANT dbv = {0};
+ DBVARIANT dbv = { 0 };
char *szExt = NULL;
TCHAR tszFilename[MAX_PATH];
HANDLE hFile = INVALID_HANDLE_VALUE;
@@ -171,30 +82,30 @@ int CreateAvatarInCache(MCONTACT hContact, avatarCacheEntry *ace, char *szProto) return -1;
if (db_get_b(hContact, "ContactPhoto", "Locked", 0)
- && !db_get_ts(hContact, "ContactPhoto", "Backup", &dbv)) {
- AVS_pathToAbsolute(dbv.ptszVal, tszFilename);
- db_free(&dbv);
+ && !db_get_ts(hContact, "ContactPhoto", "Backup", &dbv)) {
+ PathToAbsoluteT(dbv.ptszVal, tszFilename, g_szDataPath);
+ db_free(&dbv);
}
- else if ( !db_get_ts(hContact, "ContactPhoto", "RFile", &dbv)) {
- AVS_pathToAbsolute(dbv.ptszVal, tszFilename);
+ else if (!db_get_ts(hContact, "ContactPhoto", "RFile", &dbv)) {
+ PathToAbsoluteT(dbv.ptszVal, tszFilename, g_szDataPath);
db_free(&dbv);
}
- else if ( !db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
- AVS_pathToAbsolute(dbv.ptszVal, tszFilename);
+ else if (!db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
+ PathToAbsoluteT(dbv.ptszVal, tszFilename, g_szDataPath);
db_free(&dbv);
}
else return -2;
}
else {
if (hContact == 0) { // create a protocol picture in the proto picture cache
- if ( !db_get_ts(NULL, PPICT_MODULE, szProto, &dbv)) {
- AVS_pathToAbsolute(dbv.ptszVal, tszFilename);
+ if (!db_get_ts(NULL, PPICT_MODULE, szProto, &dbv)) {
+ PathToAbsoluteT(dbv.ptszVal, tszFilename, g_szDataPath);
db_free(&dbv);
}
else {
if (lstrcmpA(szProto, AVS_DEFAULT)) {
- if ( !db_get_ts(NULL, PPICT_MODULE, AVS_DEFAULT, &dbv)) {
- AVS_pathToAbsolute(dbv.ptszVal, tszFilename);
+ if (!db_get_ts(NULL, PPICT_MODULE, AVS_DEFAULT, &dbv)) {
+ PathToAbsoluteT(dbv.ptszVal, tszFilename, g_szDataPath);
db_free(&dbv);
}
@@ -204,44 +115,45 @@ int CreateAvatarInCache(MCONTACT hContact, avatarCacheEntry *ace, char *szProto) return -1;
char key[MAX_PATH];
mir_snprintf(key, SIZEOF(key), "Global avatar for %s accounts", pdescr->szProtoName);
- if ( !db_get_ts(NULL, PPICT_MODULE, key, &dbv)) {
- AVS_pathToAbsolute(dbv.ptszVal, tszFilename);
+ if (!db_get_ts(NULL, PPICT_MODULE, key, &dbv)) {
+ PathToAbsoluteT(dbv.ptszVal, tszFilename, g_szDataPath);
db_free(&dbv);
}
}
}
}
}
- else if (hContact == (MCONTACT)-1) { // create own picture - note, own avatars are not on demand, they are loaded once at
+ else if (hContact == (MCONTACT)-1) {
+ // create own picture - note, own avatars are not on demand, they are loaded once at
// startup and everytime they are changed.
if (szProto[0] == '\0') {
// Global avatar
- if ( db_get_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", &dbv))
+ if (db_get_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", &dbv))
return -10;
- AVS_pathToAbsolute(dbv.ptszVal, tszFilename);
+ PathToAbsoluteT(dbv.ptszVal, tszFilename, g_szDataPath);
db_free(&dbv);
}
- else if ( ProtoServiceExists(szProto, PS_GETMYAVATART)) {
+ else if (ProtoServiceExists(szProto, PS_GETMYAVATART)) {
if (CallProtoService(szProto, PS_GETMYAVATART, (WPARAM)tszFilename, (LPARAM)MAX_PATH))
tszFilename[0] = '\0';
}
- else if ( ProtoServiceExists(szProto, PS_GETMYAVATAR)) {
- char szFileName[ MAX_PATH ];
+ else if (ProtoServiceExists(szProto, PS_GETMYAVATAR)) {
+ char szFileName[MAX_PATH];
if (CallProtoService(szProto, PS_GETMYAVATAR, (WPARAM)szFileName, (LPARAM)MAX_PATH))
tszFilename[0] = '\0';
else
- MultiByteToWideChar( CP_ACP, 0, szFileName, -1, tszFilename, SIZEOF(tszFilename));
+ MultiByteToWideChar(CP_ACP, 0, szFileName, -1, tszFilename, SIZEOF(tszFilename));
}
- else if ( !db_get_ts(NULL, szProto, "AvatarFile", &dbv)) {
- AVS_pathToAbsolute(dbv.ptszVal, tszFilename);
+ else if (!db_get_ts(NULL, szProto, "AvatarFile", &dbv)) {
+ PathToAbsoluteT(dbv.ptszVal, tszFilename, g_szDataPath);
db_free(&dbv);
}
else return -1;
}
}
- if ( lstrlen(tszFilename) < 4)
+ if (lstrlen(tszFilename) < 4)
return -1;
_tcsncpy_s(tszFilename, VARST(tszFilename), _TRUNCATE);
@@ -251,91 +163,88 @@ int CreateAvatarInCache(MCONTACT hContact, avatarCacheEntry *ace, char *szProto) CloseHandle(hFile);
WPARAM isTransparentImage = 0;
- ace->hbmPic = (HBITMAP) BmpFilterLoadBitmap32((WPARAM)&isTransparentImage, (LPARAM)tszFilename);
+ ace->hbmPic = (HBITMAP)BmpFilterLoadBitmap32((WPARAM)&isTransparentImage, (LPARAM)tszFilename);
ace->dwFlags = 0;
ace->bmHeight = 0;
ace->bmWidth = 0;
ace->lpDIBSection = NULL;
_tcsncpy(ace->szFilename, tszFilename, MAX_PATH);
ace->szFilename[MAX_PATH - 1] = 0;
- if (ace->hbmPic != 0) {
- BITMAP bminfo;
-
- GetObject(ace->hbmPic, sizeof(bminfo), &bminfo);
-
- ace->cbSize = sizeof(avatarCacheEntry);
- ace->dwFlags = AVS_BITMAP_VALID;
- if (hContact != NULL && db_get_b(hContact, "ContactPhoto", "Hidden", 0))
- ace->dwFlags |= AVS_HIDEONCLIST;
- ace->hContact = hContact;
- ace->bmHeight = bminfo.bmHeight;
- ace->bmWidth = bminfo.bmWidth;
-
- BOOL noTransparency = db_get_b(0, AVS_MODULE, "RemoveAllTransparency", 0);
-
- // Calc image hash
- if (hContact != 0 && hContact != (MCONTACT)-1) {
- // Have to reset settings? -> do it if image changed
- DWORD imgHash = GetImgHash(ace->hbmPic);
- if (imgHash != db_get_dw(hContact, "ContactPhoto", "ImageHash", 0)) {
- db_unset(hContact, "ContactPhoto", "MakeTransparentBkg");
- db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints");
- db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff");
-
- db_set_dw(hContact, "ContactPhoto", "ImageHash", imgHash);
- }
+ if (ace->hbmPic == 0)
+ return -1;
- // Make transparent?
- if (!noTransparency && !isTransparentImage
+ BITMAP bminfo;
+ GetObject(ace->hbmPic, sizeof(bminfo), &bminfo);
+
+ ace->cbSize = sizeof(avatarCacheEntry);
+ ace->dwFlags = AVS_BITMAP_VALID;
+ if (hContact != NULL && db_get_b(hContact, "ContactPhoto", "Hidden", 0))
+ ace->dwFlags |= AVS_HIDEONCLIST;
+ ace->hContact = hContact;
+ ace->bmHeight = bminfo.bmHeight;
+ ace->bmWidth = bminfo.bmWidth;
+
+ BOOL noTransparency = db_get_b(0, AVS_MODULE, "RemoveAllTransparency", 0);
+
+ // Calc image hash
+ if (hContact != 0 && hContact != (MCONTACT)-1) {
+ // Have to reset settings? -> do it if image changed
+ DWORD imgHash = GetImgHash(ace->hbmPic);
+ if (imgHash != db_get_dw(hContact, "ContactPhoto", "ImageHash", 0)) {
+ db_unset(hContact, "ContactPhoto", "MakeTransparentBkg");
+ db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints");
+ db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff");
+
+ db_set_dw(hContact, "ContactPhoto", "ImageHash", imgHash);
+ }
+
+ // Make transparent?
+ if (!noTransparency && !isTransparentImage
&& db_get_b(hContact, "ContactPhoto", "MakeTransparentBkg",
- db_get_b(0, AVS_MODULE, "MakeTransparentBkg", 0)))
- {
- if (MakeTransparentBkg(hContact, &ace->hbmPic)) {
- ace->dwFlags |= AVS_CUSTOMTRANSPBKG | AVS_HASTRANSPARENCY;
- GetObject(ace->hbmPic, sizeof(bminfo), &bminfo);
- isTransparentImage = TRUE;
- }
+ db_get_b(0, AVS_MODULE, "MakeTransparentBkg", 0))) {
+ if (MakeTransparentBkg(hContact, &ace->hbmPic)) {
+ ace->dwFlags |= AVS_CUSTOMTRANSPBKG | AVS_HASTRANSPARENCY;
+ GetObject(ace->hbmPic, sizeof(bminfo), &bminfo);
+ isTransparentImage = TRUE;
}
}
- else if (hContact == (MCONTACT)-1) { // My avatars
- if (!noTransparency && !isTransparentImage
+ }
+ else if (hContact == (MCONTACT)-1) { // My avatars
+ if (!noTransparency && !isTransparentImage
&& db_get_b(0, AVS_MODULE, "MakeTransparentBkg", 0)
- && db_get_b(0, AVS_MODULE, "MakeMyAvatarsTransparent", 0))
- {
- if (MakeTransparentBkg(0, &ace->hbmPic)) {
- ace->dwFlags |= AVS_CUSTOMTRANSPBKG | AVS_HASTRANSPARENCY;
- GetObject(ace->hbmPic, sizeof(bminfo), &bminfo);
- isTransparentImage = TRUE;
- }
+ && db_get_b(0, AVS_MODULE, "MakeMyAvatarsTransparent", 0)) {
+ if (MakeTransparentBkg(0, &ace->hbmPic)) {
+ ace->dwFlags |= AVS_CUSTOMTRANSPBKG | AVS_HASTRANSPARENCY;
+ GetObject(ace->hbmPic, sizeof(bminfo), &bminfo);
+ isTransparentImage = TRUE;
}
}
+ }
- if (db_get_b(0, AVS_MODULE, "MakeGrayscale", 0))
- ace->hbmPic = MakeGrayscale(hContact, ace->hbmPic);
-
- if (noTransparency) {
- fei->FI_CorrectBitmap32Alpha(ace->hbmPic, TRUE);
- isTransparentImage = FALSE;
- }
+ if (db_get_b(0, AVS_MODULE, "MakeGrayscale", 0))
+ ace->hbmPic = MakeGrayscale(hContact, ace->hbmPic);
- if (bminfo.bmBitsPixel == 32 && isTransparentImage) {
- if (fei->FI_Premultiply(ace->hbmPic))
- ace->dwFlags |= AVS_HASTRANSPARENCY;
+ if (noTransparency) {
+ fei->FI_CorrectBitmap32Alpha(ace->hbmPic, TRUE);
+ isTransparentImage = FALSE;
+ }
- ace->dwFlags |= AVS_PREMULTIPLIED;
- }
+ if (bminfo.bmBitsPixel == 32 && isTransparentImage) {
+ if (fei->FI_Premultiply(ace->hbmPic))
+ ace->dwFlags |= AVS_HASTRANSPARENCY;
- if (szProto) {
- protoPicCacheEntry *pAce = (protoPicCacheEntry *)ace;
- if (hContact == 0)
- pAce->dwFlags |= AVS_PROTOPIC;
- else if (hContact == (MCONTACT)-1)
- pAce->dwFlags |= AVS_OWNAVATAR;
- }
+ ace->dwFlags |= AVS_PREMULTIPLIED;
+ }
- return 1;
+ if (szProto) {
+ protoPicCacheEntry *pAce = (protoPicCacheEntry *)ace;
+ if (hContact == 0)
+ pAce->dwFlags |= AVS_PROTOPIC;
+ else if (hContact == (MCONTACT)-1)
+ pAce->dwFlags |= AVS_OWNAVATAR;
}
- return -1;
+
+ return 1;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -346,21 +255,20 @@ int CreateAvatarInCache(MCONTACT hContact, avatarCacheEntry *ace, char *szProto) int GetFileHash(TCHAR* filename)
{
- HANDLE hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ HANDLE hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return 0;
int remainder = 0;
char data[1024];
DWORD dwRead;
- do
- {
+ do {
// Read file chunk
dwRead = 0;
ReadFile(hFile, data, 1024, &dwRead, NULL);
/* loop through each byte of data */
- for (int byte = 0; byte < (int) dwRead; ++byte) {
+ for (int byte = 0; byte < (int)dwRead; ++byte) {
/* store the next byte into the remainder */
remainder ^= (data[byte] << (WIDTH - 8));
/* calculate for all 8 bits in the byte */
@@ -373,7 +281,7 @@ int GetFileHash(TCHAR* filename) }
}
}
- while(dwRead == 1024);
+ while (dwRead == 1024);
CloseHandle(hFile);
@@ -402,7 +310,7 @@ void protoPicCacheEntry::clear() BOOL Proto_IsAvatarsEnabled(const char *proto)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
+ if (ProtoServiceExists(proto, PS_GETAVATARCAPS))
return CallProtoService(proto, PS_GETAVATARCAPS, AF_ENABLED, 0);
return TRUE;
@@ -410,7 +318,7 @@ BOOL Proto_IsAvatarsEnabled(const char *proto) BOOL Proto_IsAvatarFormatSupported(const char *proto, int format)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
+ if (ProtoServiceExists(proto, PS_GETAVATARCAPS))
return CallProtoService(proto, PS_GETAVATARCAPS, AF_FORMATSUPPORTED, format);
if (format >= PA_FORMAT_SWF)
@@ -421,7 +329,7 @@ BOOL Proto_IsAvatarFormatSupported(const char *proto, int format) int Proto_AvatarImageProportion(const char *proto)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
+ if (ProtoServiceExists(proto, PS_GETAVATARCAPS))
return CallProtoService(proto, PS_GETAVATARCAPS, AF_PROPORTION, 0);
return 0;
@@ -429,9 +337,9 @@ int Proto_AvatarImageProportion(const char *proto) void Proto_GetAvatarMaxSize(const char *proto, int *width, int *height)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS)) {
+ if (ProtoServiceExists(proto, PS_GETAVATARCAPS)) {
POINT maxSize;
- CallProtoService(proto, PS_GETAVATARCAPS, AF_MAXSIZE, (LPARAM) &maxSize);
+ CallProtoService(proto, PS_GETAVATARCAPS, AF_MAXSIZE, (LPARAM)&maxSize);
*width = maxSize.y;
*height = maxSize.x;
}
@@ -453,7 +361,7 @@ void Proto_GetAvatarMaxSize(const char *proto, int *width, int *height) BOOL Proto_NeedDelaysForAvatars(const char *proto)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
+ if (ProtoServiceExists(proto, PS_GETAVATARCAPS))
return CallProtoService(proto, PS_GETAVATARCAPS, AF_DONTNEEDDELAYS, 0) <= 0;
return TRUE;
@@ -461,7 +369,7 @@ BOOL Proto_NeedDelaysForAvatars(const char *proto) int Proto_GetAvatarMaxFileSize(const char *proto)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
+ if (ProtoServiceExists(proto, PS_GETAVATARCAPS))
return CallProtoService(proto, PS_GETAVATARCAPS, AF_MAXFILESIZE, 0);
return 0;
@@ -469,7 +377,7 @@ int Proto_GetAvatarMaxFileSize(const char *proto) int Proto_GetDelayAfterFail(const char *proto)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
+ if (ProtoServiceExists(proto, PS_GETAVATARCAPS))
return CallProtoService(proto, PS_GETAVATARCAPS, AF_DELAYAFTERFAIL, 0);
return 0;
@@ -477,7 +385,7 @@ int Proto_GetDelayAfterFail(const char *proto) BOOL Proto_IsFetchingWhenProtoNotVisibleAllowed(const char *proto)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
+ if (ProtoServiceExists(proto, PS_GETAVATARCAPS))
return CallProtoService(proto, PS_GETAVATARCAPS, AF_FETCHIFPROTONOTVISIBLE, 0);
return FALSE;
@@ -485,7 +393,7 @@ BOOL Proto_IsFetchingWhenProtoNotVisibleAllowed(const char *proto) BOOL Proto_IsFetchingWhenContactOfflineAllowed(const char *proto)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
+ if (ProtoServiceExists(proto, PS_GETAVATARCAPS))
return CallProtoService(proto, PS_GETAVATARCAPS, AF_FETCHIFCONTACTOFFLINE, 0);
return FALSE;
@@ -499,7 +407,7 @@ protoPicCacheEntry *GetProtoDefaultAvatar(MCONTACT hContact) if (szProto) {
for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
protoPicCacheEntry& p = g_ProtoPictures[i];
- if ( !lstrcmpA(p.szProtoname, szProto) && p.hbmPic != NULL)
+ if (!lstrcmpA(p.szProtoname, szProto) && p.hbmPic != NULL)
return &g_ProtoPictures[i];
}
}
@@ -541,12 +449,12 @@ int ChangeAvatar(MCONTACT hContact, BOOL fLoad, BOOL fNotifyHist, int pa_format) void DeleteGlobalUserAvatar()
{
- DBVARIANT dbv = {0};
+ DBVARIANT dbv = { 0 };
if (db_get_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", &dbv))
return;
TCHAR szFilename[MAX_PATH];
- AVS_pathToAbsolute(dbv.ptszVal, szFilename);
+ PathToAbsoluteT(dbv.ptszVal, szFilename, g_szDataPath);
db_free(&dbv);
DeleteFile(szFilename);
@@ -570,5 +478,5 @@ void SetIgnoreNotify(char *protocol, BOOL ignore) DWORD GetFileSize(TCHAR *szFilename)
{
struct _stat info;
- return ( _tstat(szFilename, &info) == -1) ? 0 : info.st_size;
+ return (_tstat(szFilename, &info) == -1) ? 0 : info.st_size;
}
diff --git a/plugins/AVS/src/version.h b/plugins/AVS/src/version.h index ff7c3d5f2d..466fcb6aa4 100644 --- a/plugins/AVS/src/version.h +++ b/plugins/AVS/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 95
#define __RELEASE_NUM 2
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>
|