diff options
Diffstat (limited to 'protocols/Gadu-Gadu/src/sessions.cpp')
-rw-r--r-- | protocols/Gadu-Gadu/src/sessions.cpp | 309 |
1 files changed, 154 insertions, 155 deletions
diff --git a/protocols/Gadu-Gadu/src/sessions.cpp b/protocols/Gadu-Gadu/src/sessions.cpp index 1dedbe005c..52ad6f1efa 100644 --- a/protocols/Gadu-Gadu/src/sessions.cpp +++ b/protocols/Gadu-Gadu/src/sessions.cpp @@ -25,21 +25,20 @@ static void gg_clearsessionslist(HWND hwndDlg)
{
HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
- LV_COLUMN column = {0};
- RECT rc;
- int iWidth;
- if (!hList) return;
+ if (!hList)
+ return;
ListView_DeleteAllItems(hList);
while (ListView_DeleteColumn(hList, 0));
+ LV_COLUMN column = { 0 };
column.mask = LVCF_TEXT;
column.cx = 500;
column.pszText = TranslateT("Client Name");
ListView_InsertColumn(hList, 1, &column);
- column.pszText=TranslateT("IP Address");
+ column.pszText = TranslateT("IP Address");
ListView_InsertColumn(hList, 2, &column);
column.pszText = TranslateT("Login Time");
@@ -48,8 +47,9 @@ static void gg_clearsessionslist(HWND hwndDlg) column.pszText = TranslateT("Action");
ListView_InsertColumn(hList, 4, &column);
+ RECT rc;
GetClientRect(hList, &rc);
- iWidth = rc.right - rc.left;
+ int iWidth = rc.right - rc.left;
ListView_SetColumnWidth(hList, 0, iWidth * 45 / 100);
ListView_SetColumnWidth(hList, 1, iWidth * 20 / 100);
ListView_SetColumnWidth(hList, 2, iWidth * 20 / 100);
@@ -66,15 +66,14 @@ static void ListView_SetItemTextA(HWND hwndLV, int i, int iSubItem, char* pszTex static int gg_insertlistitem(HWND hList, gg_multilogon_id_t* id, const char* clientName, const char* ip, const char* loginTime)
{
- LVITEM item = {0};
- int index;
-
+ LVITEM item = { 0 };
item.iItem = ListView_GetItemCount(hList);
item.mask = LVIF_PARAM;
item.lParam = (LPARAM)id;
- index = ListView_InsertItem(hList, &item);
- if (index < 0) return index;
+ int index = ListView_InsertItem(hList, &item);
+ if (index < 0)
+ return index;
ListView_SetItemTextA(hList, index, 0, (char*)clientName);
ListView_SetItemTextA(hList, index, 1, (char*)ip);
@@ -89,7 +88,8 @@ static void gg_listsessions(GGPROTO* gg, HWND hwndDlg) HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
list_t l;
- if (!hList) return;
+ if (!hList)
+ return;
gg->gg_EnterCriticalSection(&gg->sessions_mutex, "gg_listsessions", 73, "sessions_mutex", 1);
for (l = gg->sessions; l; l = l->next)
@@ -111,13 +111,14 @@ static int sttSessionsDlgResizer(HWND, LPARAM, UTILRESIZECONTROL* urc) {
switch (urc->wId)
{
- case IDC_HEADERBAR:
- return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORX_WIDTH;
- case IDC_SESSIONS:
- return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORY_HEIGHT | RD_ANCHORX_WIDTH;
- case IDC_SIGNOUTALL:
- return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
+ case IDC_HEADERBAR:
+ return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORX_WIDTH;
+ case IDC_SESSIONS:
+ return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORY_HEIGHT | RD_ANCHORX_WIDTH;
+ case IDC_SIGNOUTALL:
+ return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
}
+
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
}
@@ -125,26 +126,24 @@ static BOOL IsOverAction(HWND hwndDlg) {
HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
LVHITTESTINFO hti;
- RECT rc;
- HDC hdc;
- wchar_t szText[256];
- SIZE textSize;
- int textPosX;
-
GetCursorPos(&hti.pt);
ScreenToClient(hList, &hti.pt);
+ RECT rc;
GetClientRect(hList, &rc);
if (!PtInRect(&rc, hti.pt) || ListView_SubItemHitTest(hList, &hti) == -1
|| hti.iSubItem != 3 || !(hti.flags & LVHT_ONITEMLABEL))
return FALSE;
ListView_GetSubItemRect(hList, hti.iItem, hti.iSubItem, LVIR_LABEL, &rc);
+ wchar_t szText[256];
szText[0] = 0;
ListView_GetItemText(hList, hti.iItem, hti.iSubItem, szText, _countof(szText));
- hdc = GetDC(hList);
+ HDC hdc = GetDC(hList);
+ SIZE textSize;
GetTextExtentPoint32(hdc, szText, (int)mir_wstrlen(szText), &textSize);
ReleaseDC(hList, hdc);
- textPosX = rc.left + (((rc.right - rc.left) - textSize.cx) / 2);
+ int textPosX = rc.left + (((rc.right - rc.left) - textSize.cx) / 2);
+
return (hti.pt.x > textPosX && hti.pt.x < textPosX + textSize.cx);
}
@@ -165,7 +164,6 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
{
wchar_t oldTitle[256], newTitle[256];
- HANDLE hProtoAckEvent;
GetWindowText(hwndDlg, oldTitle, _countof(oldTitle));
mir_snwprintf(newTitle, oldTitle, gg->m_tszUserName);
@@ -174,7 +172,7 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w if (hHandCursor == nullptr)
hHandCursor = LoadCursor(nullptr, IDC_HAND);
- hProtoAckEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_PROTOACK);
+ HANDLE hProtoAckEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_PROTOACK);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)hProtoAckEvent);
ListView_SetExtendedListViewStyle(GetDlgItem(hwndDlg, IDC_SESSIONS), LVS_EX_FULLROWSELECT);
@@ -183,18 +181,18 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w }
case HM_PROTOACK:
- {
- ACKDATA* ack = (ACKDATA*)lParam;
- if (!mir_strcmp(ack->szModule, gg->m_szModuleName) && !ack->hContact && ack->type == ACKTYPE_STATUS
- && ack->result == ACKRESULT_SUCCESS && (ack->lParam == ID_STATUS_OFFLINE
+ {
+ ACKDATA* ack = (ACKDATA*)lParam;
+ if (!mir_strcmp(ack->szModule, gg->m_szModuleName) && !ack->hContact && ack->type == ACKTYPE_STATUS
+ && ack->result == ACKRESULT_SUCCESS && (ack->lParam == ID_STATUS_OFFLINE
|| (ack->hProcess == (HANDLE)ID_STATUS_CONNECTING && ack->lParam != ID_STATUS_OFFLINE
- && !ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_SESSIONS)))))
- {
- gg_clearsessionslist(hwndDlg);
- EnableWindow(GetDlgItem(hwndDlg, IDC_SIGNOUTALL), FALSE);
- }
- break;
+ && !ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_SESSIONS)))))
+ {
+ gg_clearsessionslist(hwndDlg);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_SIGNOUTALL), FALSE);
}
+ break;
+ }
case WM_MULTILOGONINFO:
gg_clearsessionslist(hwndDlg);
@@ -205,21 +203,21 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w switch (LOWORD(wParam))
{
case IDC_SIGNOUTALL:
+ {
+ HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
+ LVITEM lvi = { 0 };
+ int iCount = ListView_GetItemCount(hList);
+ lvi.mask = LVIF_PARAM;
+ for (int i = 0; i < iCount; i++)
{
- HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
- LVITEM lvi = {0};
- int iCount = ListView_GetItemCount(hList), i;
- lvi.mask = LVIF_PARAM;
- for (i = 0; i < iCount; i++)
- {
- lvi.iItem = i;
- ListView_GetItem(hList, &lvi);
- gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_sessions_viewdlg", 74, "sess_mutex", 1);
- gg_multilogon_disconnect(gg->sess, *((gg_multilogon_id_t*)lvi.lParam));
- gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_sessions_viewdlg", 74, 1, "sess_mutex", 1);
- }
- break;
+ lvi.iItem = i;
+ ListView_GetItem(hList, &lvi);
+ gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_sessions_viewdlg", 74, "sess_mutex", 1);
+ gg_multilogon_disconnect(gg->sess, *((gg_multilogon_id_t*)lvi.lParam));
+ gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_sessions_viewdlg", 74, 1, "sess_mutex", 1);
}
+ break;
+ }
}
break;
@@ -229,62 +227,62 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w switch (((LPNMHDR)lParam)->code)
{
case NM_CUSTOMDRAW:
+ {
+ LPNMLVCUSTOMDRAW nm = (LPNMLVCUSTOMDRAW)lParam;
+ switch (nm->nmcd.dwDrawStage)
{
- LPNMLVCUSTOMDRAW nm = (LPNMLVCUSTOMDRAW)lParam;
- switch (nm->nmcd.dwDrawStage)
+ case CDDS_PREPAINT:
+ if (ListView_GetItemCount(nm->nmcd.hdr.hwndFrom) == 0)
{
- case CDDS_PREPAINT:
- if (ListView_GetItemCount(nm->nmcd.hdr.hwndFrom) == 0)
- {
- const LPCTSTR szText = gg->isonline()
- ? TranslateT("There are no active concurrent sessions for this account.")
- : TranslateT("You have to be logged in to view concurrent sessions.");
- RECT rc;
- HWND hwndHeader = ListView_GetHeader(nm->nmcd.hdr.hwndFrom);
- GetClientRect(nm->nmcd.hdr.hwndFrom, &rc);
- if (hwndHeader != nullptr) {
- RECT rcHeader;
- GetClientRect(hwndHeader, &rcHeader);
- rc.top += rcHeader.bottom;
- }
- int cbLen = (int)mir_wstrlen(szText);
- SIZE textSize;
- GetTextExtentPoint32(nm->nmcd.hdc, szText, cbLen, &textSize);
- int textPosX = rc.left + (((rc.right - rc.left) - textSize.cx) / 2);
- ExtTextOut(nm->nmcd.hdc, textPosX, rc.top + textSize.cy, ETO_OPAQUE, &rc, szText, cbLen, nullptr);
+ const LPCTSTR szText = gg->isonline()
+ ? TranslateT("There are no active concurrent sessions for this account.")
+ : TranslateT("You have to be logged in to view concurrent sessions.");
+ RECT rc;
+ HWND hwndHeader = ListView_GetHeader(nm->nmcd.hdr.hwndFrom);
+ GetClientRect(nm->nmcd.hdr.hwndFrom, &rc);
+ if (hwndHeader != nullptr) {
+ RECT rcHeader;
+ GetClientRect(hwndHeader, &rcHeader);
+ rc.top += rcHeader.bottom;
}
- // FALL THROUGH
+ int cbLen = (int)mir_wstrlen(szText);
+ SIZE textSize;
+ GetTextExtentPoint32(nm->nmcd.hdc, szText, cbLen, &textSize);
+ int textPosX = rc.left + (((rc.right - rc.left) - textSize.cx) / 2);
+ ExtTextOut(nm->nmcd.hdc, textPosX, rc.top + textSize.cy, ETO_OPAQUE, &rc, szText, cbLen, nullptr);
+ }
+ // FALL THROUGH
- case CDDS_ITEMPREPAINT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT , CDRF_NOTIFYSUBITEMDRAW);
- return TRUE;
+ case CDDS_ITEMPREPAINT:
+ SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYSUBITEMDRAW);
+ return TRUE;
- case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
- {
- RECT rc;
- ListView_GetSubItemRect(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, LVIR_LABEL, &rc);
- if (nm->nmcd.hdr.idFrom == IDC_SESSIONS && nm->iSubItem == 3)
- {
- wchar_t szText[256];
- szText[0] = 0;
- ListView_GetItemText(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, szText, _countof(szText));
- FillRect(nm->nmcd.hdc, &rc, GetSysColorBrush(COLOR_WINDOW));
- SetTextColor(nm->nmcd.hdc, RGB(0, 0, 255));
- DrawText(nm->nmcd.hdc, szText, -1, &rc, DT_END_ELLIPSIS | DT_CENTER | DT_NOPREFIX | DT_SINGLELINE | DT_TOP);
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);
- return TRUE;
- }
- break;
- }
+ case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
+ {
+ RECT rc;
+ ListView_GetSubItemRect(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, LVIR_LABEL, &rc);
+ if (nm->nmcd.hdr.idFrom == IDC_SESSIONS && nm->iSubItem == 3)
+ {
+ wchar_t szText[256];
+ szText[0] = 0;
+ ListView_GetItemText(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, szText, _countof(szText));
+ FillRect(nm->nmcd.hdc, &rc, GetSysColorBrush(COLOR_WINDOW));
+ SetTextColor(nm->nmcd.hdc, RGB(0, 0, 255));
+ DrawText(nm->nmcd.hdc, szText, -1, &rc, DT_END_ELLIPSIS | DT_CENTER | DT_NOPREFIX | DT_SINGLELINE | DT_TOP);
+ SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);
+ return TRUE;
}
break;
}
+ }
+ break;
+ }
case NM_CLICK:
if (IsOverAction(hwndDlg))
{
LPNMITEMACTIVATE nm = (LPNMITEMACTIVATE)lParam;
- LVITEM lvi = {0};
+ LVITEM lvi = { 0 };
lvi.mask = LVIF_PARAM;
lvi.iItem = nm->iItem;
ListView_GetItem(nm->hdr.hwndFrom, &lvi);
@@ -298,63 +296,62 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w break;
case WM_CONTEXTMENU:
- {
- HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
- POINT pt = {(short)LOWORD(lParam), (short)HIWORD(lParam)}, ptDlg = pt;
- LVHITTESTINFO lvhti = {0};
+ {
+ HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
+ POINT pt = { (short)LOWORD(lParam), (short)HIWORD(lParam) }, ptDlg = pt;
+ LVHITTESTINFO lvhti = { 0 };
- ScreenToClient(hwndDlg, &ptDlg);
- if (ChildWindowFromPoint(hwndDlg, ptDlg) == hList)
+ ScreenToClient(hwndDlg, &ptDlg);
+ if (ChildWindowFromPoint(hwndDlg, ptDlg) == hList)
+ {
+ HMENU hMenu;
+
+ lvhti.pt = pt;
+ ScreenToClient(hList, &lvhti.pt);
+ if (ListView_HitTest(hList, &lvhti) == -1) break;
+
+ hMenu = CreatePopupMenu();
+ AppendMenu(hMenu, MFT_STRING, 10001, TranslateT("Copy Text"));
+ AppendMenu(hMenu, MFT_STRING, 10002, TranslateT("Whois"));
+ int iSelection = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, nullptr);
+ switch (iSelection) {
+ case 10001:
{
- HMENU hMenu;
- int iSelection;
-
- lvhti.pt = pt;
- ScreenToClient(hList, &lvhti.pt);
- if (ListView_HitTest(hList, &lvhti) == -1) break;
-
- hMenu = CreatePopupMenu();
- AppendMenu(hMenu, MFT_STRING, 10001, TranslateT("Copy Text"));
- AppendMenu(hMenu, MFT_STRING, 10002, TranslateT("Whois"));
- iSelection = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, nullptr);
- switch (iSelection) {
- case 10001:
- {
- wchar_t szText[512], szClientName[256], szIP[64], szLoginTime[64];
- HGLOBAL hData;
- if (!OpenClipboard(hwndDlg))
- break;
-
- EmptyClipboard();
- szClientName[0] = szIP[0] = szLoginTime[0] = 0;
- ListView_GetItemText(hList, lvhti.iItem, 0, szClientName, _countof(szClientName));
- ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
- ListView_GetItemText(hList, lvhti.iItem, 2, szLoginTime, _countof(szLoginTime));
- mir_snwprintf(szText, L"%s\t%s\t%s", szClientName, szIP, szLoginTime);
- if ((hData = GlobalAlloc(GMEM_MOVEABLE, mir_wstrlen(szText) + 1)) != nullptr)
- {
- mir_wstrcpy((wchar_t*)GlobalLock(hData), szText);
- GlobalUnlock(hData);
- SetClipboardData(CF_TEXT, hData);
- }
- CloseClipboard();
- break;
- }
+ wchar_t szText[512], szClientName[256], szIP[64], szLoginTime[64];
+ HGLOBAL hData;
+ if (!OpenClipboard(hwndDlg))
+ break;
- case 10002:
- {
- wchar_t szUrl[256], szIP[64];
- szIP[0] = 0;
- ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
- mir_snwprintf(szUrl, L"http://whois.domaintools.com/%s", szIP);
- Utils_OpenUrlW(szUrl);
- break;
- }
+ EmptyClipboard();
+ szClientName[0] = szIP[0] = szLoginTime[0] = 0;
+ ListView_GetItemText(hList, lvhti.iItem, 0, szClientName, _countof(szClientName));
+ ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
+ ListView_GetItemText(hList, lvhti.iItem, 2, szLoginTime, _countof(szLoginTime));
+ mir_snwprintf(szText, L"%s\t%s\t%s", szClientName, szIP, szLoginTime);
+ if ((hData = GlobalAlloc(GMEM_MOVEABLE, mir_wstrlen(szText) + 1)) != nullptr)
+ {
+ mir_wstrcpy((wchar_t*)GlobalLock(hData), szText);
+ GlobalUnlock(hData);
+ SetClipboardData(CF_TEXT, hData);
}
- DestroyMenu(hMenu);
+ CloseClipboard();
+ break;
}
- break;
+
+ case 10002:
+ {
+ wchar_t szUrl[256], szIP[64];
+ szIP[0] = 0;
+ ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
+ mir_snwprintf(szUrl, L"http://whois.domaintools.com/%s", szIP);
+ Utils_OpenUrlW(szUrl);
+ break;
+ }
+ }
+ DestroyMenu(hMenu);
}
+ break;
+ }
case WM_GETMINMAXINFO:
((LPMINMAXINFO)lParam)->ptMinTrackSize.x = 620;
@@ -371,7 +368,7 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w SetCursor(hHandCursor);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
- }
+ }
break;
case WM_CLOSE:
@@ -379,13 +376,13 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w break;
case WM_DESTROY:
- {
- HANDLE hProtoAckEvent = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- if (hProtoAckEvent) UnhookEvent(hProtoAckEvent);
- gg->hwndSessionsDlg = nullptr;
- Window_FreeIcon_IcoLib(hwndDlg);
- break;
- }
+ {
+ HANDLE hProtoAckEvent = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ if (hProtoAckEvent) UnhookEvent(hProtoAckEvent);
+ gg->hwndSessionsDlg = nullptr;
+ Window_FreeIcon_IcoLib(hwndDlg);
+ break;
+ }
}
return FALSE;
}
@@ -397,7 +394,9 @@ INT_PTR GGPROTO::sessions_view(WPARAM, LPARAM) SetForegroundWindow(hwndSessionsDlg);
SetFocus(hwndSessionsDlg);
}
- else CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_SESSIONS), nullptr, gg_sessions_viewdlg, (LPARAM)this);
+ else
+ CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_SESSIONS), nullptr, gg_sessions_viewdlg, (LPARAM)this);
+
return 0;
}
@@ -419,7 +418,7 @@ void GGPROTO::sessions_menus_init(HGENMENU hRoot) CMenuItem mi;
mi.flags = CMIF_UNICODE;
mi.root = hRoot;
-
+
mi.pszService = GGS_CONCUR_SESS;
CreateProtoService(mi.pszService, &GGPROTO::sessions_view);
mi.position = 200003;
|