summaryrefslogtreecommitdiff
path: root/plugins/WhenWasIt/src/utils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-11-25 12:54:45 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-11-25 12:54:45 +0000
commitbd8a04455d9c991c15df2287e091abe4ba054efb (patch)
tree6af5485d60feef741669eb545a6378e7c209ab59 /plugins/WhenWasIt/src/utils.cpp
parent7fdce14cd488e25e8e32e34098fbe9f5cb3021b7 (diff)
typed stub for MS_PROTO_GETCONTACTBASEPROTO
git-svn-id: http://svn.miranda-ng.org/main/trunk@2480 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/WhenWasIt/src/utils.cpp')
-rw-r--r--plugins/WhenWasIt/src/utils.cpp209
1 files changed, 66 insertions, 143 deletions
diff --git a/plugins/WhenWasIt/src/utils.cpp b/plugins/WhenWasIt/src/utils.cpp
index 96a86ee8be..9d59dd9067 100644
--- a/plugins/WhenWasIt/src/utils.cpp
+++ b/plugins/WhenWasIt/src/utils.cpp
@@ -37,7 +37,7 @@ int Log(char *format, ...)
va_list vararg;
int tBytes;
FILE *fout = fopen(LOG_FILE, "at");
- if (!fout)
+ if ( !fout)
{
// MessageBox(0, "can't open file", NULL, MB_OK);
return -1;
@@ -159,161 +159,94 @@ int GetStringFromDatabase(char *szSettingName, char *szError, char *szResult, si
#pragma warning (disable: 4312)
TCHAR *GetContactName(HANDLE hContact, char *szProto)
{
- CONTACTINFO ctInfo;
- int ret;
- char proto[200];
-
- ZeroMemory((void *) &ctInfo, sizeof(ctInfo));
- ctInfo.cbSize = sizeof(ctInfo);
- if (szProto)
- {
- ctInfo.szProto = szProto;
- }
- else{
- GetContactProtocol(hContact, proto, sizeof(proto));
- ctInfo.szProto = proto;
- }
- ctInfo.dwFlag = CNF_DISPLAY;
-
- ctInfo.dwFlag += CNF_UNICODE;
-
+ CONTACTINFO ctInfo = { sizeof(ctInfo) };
+ ctInfo.szProto = (szProto) ? szProto : GetContactProto(hContact);
+ ctInfo.dwFlag = CNF_DISPLAY | CNF_UNICODE;
ctInfo.hContact = hContact;
//_debug_message("retrieving contact name for %d", hContact);
- ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
+ int ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
//_debug_message(" contact name %s", ctInfo.pszVal);
TCHAR *buffer;
- if (!ret)
- {
+ if ( !ret)
buffer = _tcsdup(ctInfo.pszVal);
- }
+
mir_free(ctInfo.pszVal);
if (ret)
- {
return NULL;
- }
return buffer;
}
-#pragma warning (default: 4312)
-
-#pragma warning (disable: 4312)
-void GetContactProtocol(HANDLE hContact, char *szProto, int size)
-{
- GetStringFromDatabase(hContact, "Protocol", "p", NULL, szProto, size);
-}
-#pragma warning (default: 4312)
-#pragma warning (disable: 4312)
TCHAR *GetContactID(HANDLE hContact)
{
- char protocol[256];
- GetContactProtocol(hContact, protocol, sizeof(protocol));
-
- return GetContactID(hContact, protocol);
+ return GetContactID(hContact, GetContactProto(hContact));
}
TCHAR *GetContactID(HANDLE hContact, char *szProto)
{
- CONTACTINFO ctInfo;
- int ret;
-
- ZeroMemory((void *) &ctInfo, sizeof(ctInfo));
- ctInfo.cbSize = sizeof(ctInfo);
+ CONTACTINFO ctInfo = { sizeof(ctInfo) };
ctInfo.szProto = szProto;
- ctInfo.dwFlag = CNF_UNIQUEID;
-
- ctInfo.dwFlag |= CNF_UNICODE;
-
+ ctInfo.dwFlag = CNF_UNIQUEID | CNF_UNICODE;
ctInfo.hContact = hContact;
- ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
+ int ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo);
TCHAR *buffer;
- if (!ret)
- {
- TCHAR tmp[16];
- switch (ctInfo.type)
- {
- case CNFT_BYTE:
- {
- _stprintf(tmp, _T("%d"), ctInfo.bVal);
- buffer = _tcsdup(tmp);
-
- break;
- }
-
- case CNFT_WORD:
- {
- _stprintf(tmp, _T("%d"), ctInfo.wVal);
- buffer = _tcsdup(tmp);
-
- break;
- }
-
- case CNFT_DWORD:
- {
- _stprintf(tmp, _T("%ld"), ctInfo.dVal);
- buffer = _tcsdup(tmp);
-
- break;
- }
-
- case CNFT_ASCIIZ:
- default:
- {
- buffer = _tcsdup(ctInfo.pszVal);
-
- break;
- }
- }
-
-
+ if ( !ret) {
+ TCHAR tmp[16];
+ switch (ctInfo.type) {
+ case CNFT_BYTE:
+ _stprintf(tmp, _T("%d"), ctInfo.bVal);
+ buffer = _tcsdup(tmp);
+ break;
+
+ case CNFT_WORD:
+ _stprintf(tmp, _T("%d"), ctInfo.wVal);
+ buffer = _tcsdup(tmp);
+ break;
+
+ case CNFT_DWORD:
+ _stprintf(tmp, _T("%ld"), ctInfo.dVal);
+ buffer = _tcsdup(tmp);
+ break;
+
+ default:
+ buffer = _tcsdup(ctInfo.pszVal);
+ break;
}
+ }
+
mir_free(ctInfo.pszVal);
- if (!ret)
- {
- return buffer;
- }
- else{
- return NULL;
- }
+ return (!ret) ? buffer : NULL;
}
-#pragma warning (default: 4312)
-#pragma warning (disable: 4312)
HANDLE GetContactFromID(TCHAR *szID, char *szProto)
{
HANDLE hContact = db_find_first();
TCHAR *szHandle;
- char cProtocol[256];
int found = 0;
- while (hContact)
- {
- GetContactProtocol(hContact, cProtocol, sizeof(cProtocol));
- szHandle = GetContactID(hContact, cProtocol);
- if ((szHandle) && (_tcsicmp(szHandle, szID) == 0) && (_stricmp(szProto, cProtocol) == 0))
- {
- found = 1;
- }
- if (szHandle) free(szHandle);
-
- if (found)
- {
- break;
- }
- hContact = db_find_next(hContact);
- }
+ while (hContact) {
+ char *szProto = GetContactProto(hContact);
+ szHandle = GetContactID(hContact, szProto);
+ if (szHandle && !_tcsicmp(szHandle, szID) && !_stricmp(szProto, szProto))
+ found = 1;
+
+ if (szHandle)
+ free(szHandle);
+
+ if (found)
+ break;
+
+ hContact = db_find_next(hContact);
+ }
return hContact;
}
-#pragma warning (default: 4312)
-#pragma warning (disable: 4312)
HANDLE GetContactFromID(TCHAR *szID, wchar_t *szProto)
{
char protocol[1024];
WideCharToMultiByte(CP_ACP, 0, szProto, -1, protocol, sizeof(protocol), NULL, NULL);
return GetContactFromID(szID, protocol);
}
-#pragma warning (default: 4312)
void ScreenToClient(HWND hWnd, LPRECT rect)
{
@@ -331,37 +264,31 @@ void ScreenToClient(HWND hWnd, LPRECT rect)
void AnchorMoveWindow(HWND window, const WINDOWPOS *parentPos, int anchors)
{
- RECT rParent;
- RECT rChild;
-
if (parentPos->flags & SWP_NOSIZE)
- {
- return;
- }
+ return;
+
+ RECT rParent;
GetWindowRect(parentPos->hwnd, &rParent);
- rChild = AnchorCalcPos(window, &rParent, parentPos, anchors);
+
+ RECT rChild = AnchorCalcPos(window, &rParent, parentPos, anchors);
MoveWindow(window, rChild.left, rChild.top, rChild.right - rChild.left, rChild.bottom - rChild.top, FALSE);
}
RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, int anchors)
{
RECT rChild;
- RECT rTmp;
-
GetWindowRect(window, &rChild);
ScreenToClient(parentPos->hwnd, &rChild);
int cx = rParent->right - rParent->left;
int cy = rParent->bottom - rParent->top;
if ((cx == parentPos->cx) && (cy == parentPos->cy))
- {
- return rChild;
- }
+ return rChild;
+
if (parentPos->flags & SWP_NOSIZE)
- {
- return rChild;
- }
+ return rChild;
+ RECT rTmp;
rTmp.left = parentPos->x - rParent->left;
rTmp.right = (parentPos->x + parentPos->cx) - rParent->right;
rTmp.bottom = (parentPos->y + parentPos->cy) - rParent->bottom;
@@ -374,20 +301,16 @@ RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos,
rChild.bottom += cy;
//expanded the window accordingly, now we need to enforce the anchors
if ((anchors & ANCHOR_LEFT) && (!(anchors & ANCHOR_RIGHT)))
- {
- rChild.right -= cx;
- }
+ rChild.right -= cx;
+
if ((anchors & ANCHOR_TOP) && (!(anchors & ANCHOR_BOTTOM)))
- {
- rChild.bottom -= cy;
- }
+ rChild.bottom -= cy;
+
if ((anchors & ANCHOR_RIGHT) && (!(anchors & ANCHOR_LEFT)))
- {
- rChild.left += cx;
- }
+ rChild.left += cx;
+
if ((anchors & ANCHOR_BOTTOM) && (!(anchors & ANCHOR_TOP)))
- {
- rChild.top += cy;
- }
+ rChild.top += cy;
+
return rChild;
} \ No newline at end of file