From 9832b02f72a26c28e65ef4f281c16e684618d2b8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 31 Mar 2014 14:37:06 +0000 Subject: - fixes #638 (Message window position no longer remembered correctly in StdMsg) - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@8806 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/core/stdmsg/src/cmdlist.cpp | 55 +-- src/core/stdmsg/src/msgdialog.cpp | 792 ++++++++++++++++++------------------ src/core/stdmsg/src/msglog.cpp | 361 ++++++++-------- src/core/stdmsg/src/msgoptions.cpp | 120 +++--- src/core/stdmsg/src/msgs.cpp | 40 +- src/core/stdmsg/src/msgs.h | 2 +- src/core/stdmsg/src/msgtimedout.cpp | 17 +- src/core/stdmsg/src/richutil.cpp | 171 ++++---- src/core/stdmsg/src/statusicon.cpp | 2 +- 9 files changed, 745 insertions(+), 815 deletions(-) (limited to 'src') diff --git a/src/core/stdmsg/src/cmdlist.cpp b/src/core/stdmsg/src/cmdlist.cpp index c861f12585..8e1f61365a 100644 --- a/src/core/stdmsg/src/cmdlist.cpp +++ b/src/core/stdmsg/src/cmdlist.cpp @@ -29,21 +29,19 @@ void MessageFailureProcess(TMsgQueue *item, const char* err); static VOID CALLBACK MsgTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { - int i, ntl = 0; LIST arTimedOut(1); - - EnterCriticalSection(&csMsgQueue); - - for (i = msgQueue.getCount()-1; i >= 0; i--) { - TMsgQueue *item = msgQueue[i]; - if (dwTime - item->ts > g_dat.msgTimeout) { - arTimedOut.insert(item); - msgQueue.remove(i); + { + mir_cslock lck(csMsgQueue); + for (int i = msgQueue.getCount() - 1; i >= 0; i--) { + TMsgQueue *item = msgQueue[i]; + if (dwTime - item->ts > g_dat.msgTimeout) { + arTimedOut.insert(item); + msgQueue.remove(i); + } } } - LeaveCriticalSection(&csMsgQueue); - for (i = 0; i < arTimedOut.getCount(); ++i) + for (int i = 0; i < arTimedOut.getCount(); ++i) MessageFailureProcess(arTimedOut[i], LPGEN("The message send timed out.")); } @@ -56,25 +54,19 @@ void msgQueue_add(MCONTACT hContact, int id, const TCHAR* szMsg, HANDLE hDbEvent item->hDbEvent = hDbEvent; item->ts = GetTickCount(); - EnterCriticalSection(&csMsgQueue); + mir_cslock lck(csMsgQueue); if (!msgQueue.getCount() && !timerId) timerId = SetTimer(NULL, 0, 5000, MsgTimer); msgQueue.insert(item); - LeaveCriticalSection(&csMsgQueue); - } void msgQueue_processack(MCONTACT hContact, int id, BOOL success, const char* szErr) { - int i; - TMsgQueue* item = NULL; - MCONTACT hMeta = db_mc_getMeta(hContact); - EnterCriticalSection(&csMsgQueue); - - for (i = 0; i < msgQueue.getCount(); i++) { - item = msgQueue[i]; + mir_cslockfull lck(csMsgQueue); + for (int i = 0; i < msgQueue.getCount(); i++) { + TMsgQueue *item = msgQueue[i]; if ((item->hContact == hContact || item->hContact == hMeta) && item->id == id) { msgQueue.remove(i); i--; @@ -82,18 +74,15 @@ void msgQueue_processack(MCONTACT hContact, int id, BOOL success, const char* sz KillTimer(NULL, timerId); timerId = 0; } - break; - } - item = NULL; - } - LeaveCriticalSection(&csMsgQueue); + lck.unlock(); - if (item) { - if (success) { - mir_free(item->szMsg); - mir_free(item); + if (success) { + mir_free(item->szMsg); + mir_free(item); + } + else MessageFailureProcess(item, szErr); + break; } - else MessageFailureProcess(item, szErr); } } @@ -104,8 +93,6 @@ void msgQueue_init(void) void msgQueue_destroy(void) { - EnterCriticalSection(&csMsgQueue); - for (int i = 0; i < msgQueue.getCount(); i++) { TMsgQueue *item = msgQueue[i]; mir_free(item->szMsg); @@ -113,7 +100,5 @@ void msgQueue_destroy(void) } msgQueue.destroy(); - LeaveCriticalSection(&csMsgQueue); - DeleteCriticalSection(&csMsgQueue); } diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index f58357338c..2ae13f2707 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -60,21 +60,21 @@ static void NotifyLocalWinEvent(MCONTACT hContact, HWND hwnd, unsigned int type) static BOOL IsUtfSendAvailable(MCONTACT hContact) { - char* szProto = GetContactProto(hContact); - if ( szProto == NULL ) + char *szProto = GetContactProto(hContact); + if (szProto == NULL) return FALSE; - return ( CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDUTF ) ? TRUE : FALSE; + return (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDUTF) ? TRUE : FALSE; } static int RTL_Detect(const TCHAR *ptszText) { int iLen = (int)_tcslen(ptszText); - WORD *infoTypeC2 = (WORD*)alloca(sizeof(WORD) * (iLen + 2)); + WORD *infoTypeC2 = (WORD*)alloca(sizeof(WORD)* (iLen + 2)); GetStringTypeEx(LOCALE_USER_DEFAULT, CT_CTYPE2, ptszText, iLen, infoTypeC2); for (int i = 0; i < iLen; i++) - if(infoTypeC2[i] == C2_RIGHTTOLEFT) + if (infoTypeC2[i] == C2_RIGHTTOLEFT) return 1; return 0; @@ -95,7 +95,7 @@ HANDLE SendMessageDirect(const TCHAR *szMsg, MCONTACT hContact, char *szProto) if (IsUtfSendAvailable(hContact)) { flags |= PREF_UTF; sendBuffer = mir_utf8encodeT(szMsg); - if ( !sendBuffer || !sendBuffer[0]) { + if (!sendBuffer || !sendBuffer[0]) { mir_free(sendBuffer); return NULL; } @@ -104,13 +104,13 @@ HANDLE SendMessageDirect(const TCHAR *szMsg, MCONTACT hContact, char *szProto) else { flags |= PREF_TCHAR; sendBuffer = mir_t2a(szMsg); - if ( !sendBuffer || !sendBuffer[0]) { + if (!sendBuffer || !sendBuffer[0]) { mir_free(sendBuffer); return NULL; } bufSize = (int)strlen(sendBuffer) + 1; - size_t bufSizeT = (_tcslen(szMsg) + 1) * sizeof(TCHAR) ; + size_t bufSizeT = (_tcslen(szMsg) + 1) * sizeof(TCHAR); sendBuffer = (char*)mir_realloc(sendBuffer, bufSizeT + bufSize); memcpy((TCHAR*)&sendBuffer[bufSize], szMsg, bufSizeT); bufSize += (int)bufSizeT; @@ -138,26 +138,28 @@ HANDLE SendMessageDirect(const TCHAR *szMsg, MCONTACT hContact, char *szProto) return hNewEvent; } -static void AddToFileList(TCHAR ***pppFiles,int *totalCount,const TCHAR* szFilename) +static void AddToFileList(TCHAR ***pppFiles, int *totalCount, const TCHAR* szFilename) { - *pppFiles=(TCHAR**)mir_realloc(*pppFiles,(++*totalCount+1)*sizeof(TCHAR*)); + *pppFiles = (TCHAR**)mir_realloc(*pppFiles, (++*totalCount + 1)*sizeof(TCHAR*)); (*pppFiles)[*totalCount] = NULL; - (*pppFiles)[*totalCount-1] = mir_tstrdup( szFilename ); + (*pppFiles)[*totalCount - 1] = mir_tstrdup(szFilename); - if ( GetFileAttributes(szFilename) & FILE_ATTRIBUTE_DIRECTORY ) { + if (GetFileAttributes(szFilename) & FILE_ATTRIBUTE_DIRECTORY) { WIN32_FIND_DATA fd; HANDLE hFind; TCHAR szPath[MAX_PATH]; mir_sntprintf(szPath, SIZEOF(szPath), _T("%s\\*"), szFilename); - if (( hFind = FindFirstFile( szPath, &fd )) != INVALID_HANDLE_VALUE ) { + if ((hFind = FindFirstFile(szPath, &fd)) != INVALID_HANDLE_VALUE) { do { - if ( !_tcscmp(fd.cFileName,_T(".")) || !_tcscmp(fd.cFileName,_T(".."))) continue; + if (!_tcscmp(fd.cFileName, _T(".")) || !_tcscmp(fd.cFileName, _T(".."))) continue; mir_sntprintf(szPath, SIZEOF(szPath), _T("%s\\%s"), szFilename, fd.cFileName); - AddToFileList(pppFiles,totalCount,szPath); + AddToFileList(pppFiles, totalCount, szPath); } - while( FindNextFile( hFind,&fd )); - FindClose( hFind ); -} } } + while (FindNextFile(hFind, &fd)); + FindClose(hFind); + } + } +} static void ShowMultipleControls(HWND hwndDlg, const UINT * controls, int cControls, int state) { @@ -172,7 +174,7 @@ static void UpdateReadChars(HWND hwndDlg, HWND hwndStatus) int len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE)); mir_sntprintf(buf, SIZEOF(buf), _T("%d"), len); - SendMessage(hwndStatus, SB_SETTEXT, 1, (LPARAM) buf); + SendMessage(hwndStatus, SB_SETTEXT, 1, (LPARAM)buf); } } @@ -186,7 +188,7 @@ static void ShowTime(SrmmWindowData *dat) unsigned i = (g_dat.flags & SMF_SHOWREADCHAR) ? 2 : 1; tmi.printDateTime(dat->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); - SendMessage(dat->hwndStatus, SB_SETTEXT, i, (LPARAM) buf); + SendMessage(dat->hwndStatus, SB_SETTEXT, i, (LPARAM)buf); dat->wMinute = st.wMinute; } } @@ -211,7 +213,7 @@ static void SetupStatusBar(HWND hwndDlg, SrmmWindowData *dat) statwidths[i++] = cx - icons_width; statwidths[i++] = -1; - SendMessage(dat->hwndStatus, SB_SETPARTS, i, (LPARAM) statwidths); + SendMessage(dat->hwndStatus, SB_SETPARTS, i, (LPARAM)statwidths); UpdateReadChars(hwndDlg, dat->hwndStatus); ShowTime(dat); @@ -222,7 +224,7 @@ static void SetDialogToType(HWND hwndDlg) { SrmmWindowData *dat; - dat = (SrmmWindowData *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + dat = (SrmmWindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); if (dat->hContact) ShowMultipleControls(hwndDlg, infoLineControls, SIZEOF(infoLineControls), (g_dat.flags&SMF_SHOWINFO) ? SW_SHOW : SW_HIDE); else @@ -230,13 +232,13 @@ static void SetDialogToType(HWND hwndDlg) if (dat->hContact) { ShowMultipleControls(hwndDlg, buttonLineControls, SIZEOF(buttonLineControls), (g_dat.flags&SMF_SHOWBTNS) ? SW_SHOW : SW_HIDE); - if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0)) + if (!db_get_b(dat->hContact, "CList", "NotOnList", 0)) ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE); } else ShowMultipleControls(hwndDlg, buttonLineControls, SIZEOF(buttonLineControls), SW_HIDE); ShowMultipleControls(hwndDlg, sendControls, SIZEOF(sendControls), SW_SHOW); - if ( !dat->hwndStatus) { + if (!dat->hwndStatus) { int grip = (GetWindowLongPtr(hwndDlg, GWL_STYLE) & WS_THICKFRAME) ? SBARS_SIZEGRIP : 0; dat->hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | grip, 0, 0, 0, 0, hwndDlg, NULL, g_hInst, NULL); SendMessage(dat->hwndStatus, SB_SETMINHEIGHT, GetSystemMetrics(SM_CYSMICON), 0); @@ -268,7 +270,7 @@ static void SetEditorText(HWND hwnd, const TCHAR* txt) static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - SrmmWindowData *pdat = (SrmmWindowData *)GetWindowLongPtr(GetParent(hwnd),GWLP_USERDATA); + SrmmWindowData *pdat = (SrmmWindowData *)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); struct MsgEditSubclassData *dat = (struct MsgEditSubclassData *) GetWindowLongPtr(hwnd, GWLP_USERDATA); switch (msg) { @@ -278,7 +280,7 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wPar case EM_SUBCLASSED: dat = (struct MsgEditSubclassData *) mir_alloc(sizeof(struct MsgEditSubclassData)); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) dat); + SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat); dat->lastEnterTime = 0; return 0; @@ -299,8 +301,8 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wPar case WM_KEYDOWN: if (wParam == VK_RETURN) { - if ( !(GetKeyState(VK_SHIFT) & 0x8000) && - ((GetKeyState(VK_CONTROL) & 0x8000) != 0) != ((g_dat.flags & SMF_SENDONENTER) != 0)) { + if (!(GetKeyState(VK_SHIFT) & 0x8000) && + ((GetKeyState(VK_CONTROL) & 0x8000) != 0) != ((g_dat.flags & SMF_SENDONENTER) != 0)) { PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); return 0; } @@ -318,16 +320,16 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wPar else dat->lastEnterTime = 0; if (((wParam == VK_INSERT && (GetKeyState(VK_SHIFT) & 0x8000)) || (wParam == 'V' && (GetKeyState(VK_CONTROL) & 0x8000))) && - !(GetKeyState(VK_MENU) & 0x8000)) { // ctrl-v (paste clean text) + !(GetKeyState(VK_MENU) & 0x8000)) { // ctrl-v (paste clean text) SendMessage(hwnd, WM_PASTE, 0, 0); return 0; } if (wParam == VK_UP && (GetKeyState(VK_CONTROL) & 0x8000) && - ((g_dat.flags & (SMF_AUTOCLOSE | SMF_CTRLSUPPORT)) == SMF_CTRLSUPPORT)) { + ((g_dat.flags & (SMF_AUTOCLOSE | SMF_CTRLSUPPORT)) == SMF_CTRLSUPPORT)) { if (pdat->cmdList.getCount()) { if (pdat->cmdListInd < 0) { - pdat->cmdListInd = pdat->cmdList.getCount()-1; + pdat->cmdListInd = pdat->cmdList.getCount() - 1; SetEditorText(hwnd, pdat->cmdList[pdat->cmdListInd]); } else if (pdat->cmdListInd > 0) { @@ -340,13 +342,13 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wPar } if (wParam == VK_DOWN && (GetKeyState(VK_CONTROL) & 0x8000) && - ((g_dat.flags & (SMF_AUTOCLOSE | SMF_CTRLSUPPORT)) == SMF_CTRLSUPPORT)) { + ((g_dat.flags & (SMF_AUTOCLOSE | SMF_CTRLSUPPORT)) == SMF_CTRLSUPPORT)) { if (pdat->cmdList.getCount() && pdat->cmdListInd >= 0) { - if (pdat->cmdListInd < (pdat->cmdList.getCount()-1)) + if (pdat->cmdListInd < (pdat->cmdList.getCount() - 1)) SetEditorText(hwnd, pdat->cmdList[++pdat->cmdListInd]); else { pdat->cmdListInd = -1; - SetEditorText(hwnd, pdat->cmdList[pdat->cmdList.getCount()-1]); + SetEditorText(hwnd, pdat->cmdList[pdat->cmdList.getCount() - 1]); } } @@ -372,105 +374,105 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wPar break; case WM_CONTEXTMENU: - { - HMENU hMenu; - CHARRANGE sel; - static const CHARRANGE all = {0, -1}; - - MessageWindowPopupData mwpd = {0}; - mwpd.cbSize = sizeof(mwpd); - mwpd.uType = MSG_WINDOWPOPUP_SHOWING; - mwpd.uFlags = MSG_WINDOWPOPUP_INPUT; - mwpd.hContact = pdat->hContact; - mwpd.hwnd = hwnd; - - hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT)); - - mwpd.hMenu = GetSubMenu(hMenu, 2); - TranslateMenu(mwpd.hMenu); - - SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); - if (sel.cpMin == sel.cpMax) { - EnableMenuItem(mwpd.hMenu, IDM_CUT, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(mwpd.hMenu, IDM_COPY, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(mwpd.hMenu, IDM_DELETE, MF_BYCOMMAND | MF_GRAYED); - } - if ( !SendMessage(hwnd, EM_CANUNDO, 0, 0)) - EnableMenuItem(mwpd.hMenu, IDM_UNDO, MF_BYCOMMAND | MF_GRAYED); + { + HMENU hMenu; + CHARRANGE sel; + static const CHARRANGE all = { 0, -1 }; + + MessageWindowPopupData mwpd = { 0 }; + mwpd.cbSize = sizeof(mwpd); + mwpd.uType = MSG_WINDOWPOPUP_SHOWING; + mwpd.uFlags = MSG_WINDOWPOPUP_INPUT; + mwpd.hContact = pdat->hContact; + mwpd.hwnd = hwnd; + + hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT)); + + mwpd.hMenu = GetSubMenu(hMenu, 2); + TranslateMenu(mwpd.hMenu); + + SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); + if (sel.cpMin == sel.cpMax) { + EnableMenuItem(mwpd.hMenu, IDM_CUT, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(mwpd.hMenu, IDM_COPY, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(mwpd.hMenu, IDM_DELETE, MF_BYCOMMAND | MF_GRAYED); + } + if (!SendMessage(hwnd, EM_CANUNDO, 0, 0)) + EnableMenuItem(mwpd.hMenu, IDM_UNDO, MF_BYCOMMAND | MF_GRAYED); - if ( !SendMessage(hwnd, EM_CANREDO, 0, 0)) - EnableMenuItem(mwpd.hMenu, IDM_REDO, MF_BYCOMMAND | MF_GRAYED); + if (!SendMessage(hwnd, EM_CANREDO, 0, 0)) + EnableMenuItem(mwpd.hMenu, IDM_REDO, MF_BYCOMMAND | MF_GRAYED); - if ( !SendMessage(hwnd, EM_CANPASTE, 0, 0)) { - if ( !IsClipboardFormatAvailable(CF_HDROP)) - EnableMenuItem(mwpd.hMenu, IDM_PASTE, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(mwpd.hMenu, IDM_PASTESEND, MF_BYCOMMAND | MF_GRAYED); - } + if (!SendMessage(hwnd, EM_CANPASTE, 0, 0)) { + if (!IsClipboardFormatAvailable(CF_HDROP)) + EnableMenuItem(mwpd.hMenu, IDM_PASTE, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(mwpd.hMenu, IDM_PASTESEND, MF_BYCOMMAND | MF_GRAYED); + } - if (lParam == 0xFFFFFFFF) { - SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&mwpd.pt, (LPARAM)sel.cpMax); - ClientToScreen(hwnd, &mwpd.pt); - } - else { - mwpd.pt.x = GET_X_LPARAM(lParam); - mwpd.pt.y = GET_Y_LPARAM(lParam); - } + if (lParam == 0xFFFFFFFF) { + SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&mwpd.pt, (LPARAM)sel.cpMax); + ClientToScreen(hwnd, &mwpd.pt); + } + else { + mwpd.pt.x = GET_X_LPARAM(lParam); + mwpd.pt.y = GET_Y_LPARAM(lParam); + } - // First notification - NotifyEventHooks(hHookWinPopup, 0, (LPARAM)&mwpd); + // First notification + NotifyEventHooks(hHookWinPopup, 0, (LPARAM)&mwpd); - // Someone added items? - if (GetMenuItemCount(mwpd.hMenu) > 0) { - SetCursor(LoadCursor(NULL, IDC_ARROW)); - mwpd.selection = TrackPopupMenu(mwpd.hMenu, TPM_RETURNCMD, mwpd.pt.x, mwpd.pt.y, 0, hwnd, NULL); - } + // Someone added items? + if (GetMenuItemCount(mwpd.hMenu) > 0) { + SetCursor(LoadCursor(NULL, IDC_ARROW)); + mwpd.selection = TrackPopupMenu(mwpd.hMenu, TPM_RETURNCMD, mwpd.pt.x, mwpd.pt.y, 0, hwnd, NULL); + } - // Second notification - mwpd.uType = MSG_WINDOWPOPUP_SELECTED; - NotifyEventHooks(hHookWinPopup, 0, (LPARAM)&mwpd); + // Second notification + mwpd.uType = MSG_WINDOWPOPUP_SELECTED; + NotifyEventHooks(hHookWinPopup, 0, (LPARAM)&mwpd); - switch (mwpd.selection) { - case IDM_UNDO: - SendMessage(hwnd, WM_UNDO, 0, 0); - break; + switch (mwpd.selection) { + case IDM_UNDO: + SendMessage(hwnd, WM_UNDO, 0, 0); + break; - case IDM_REDO: - SendMessage(hwnd, EM_REDO, 0, 0); - break; + case IDM_REDO: + SendMessage(hwnd, EM_REDO, 0, 0); + break; - case IDM_CUT: - SendMessage(hwnd, WM_CUT, 0, 0); - break; + case IDM_CUT: + SendMessage(hwnd, WM_CUT, 0, 0); + break; - case IDM_COPY: - SendMessage(hwnd, WM_COPY, 0, 0); - break; + case IDM_COPY: + SendMessage(hwnd, WM_COPY, 0, 0); + break; - case IDM_PASTE: - SendMessage(hwnd, WM_PASTE, 0, 0); - break; + case IDM_PASTE: + SendMessage(hwnd, WM_PASTE, 0, 0); + break; - case IDM_PASTESEND: - SendMessage(hwnd, EM_PASTESPECIAL, CF_TEXT, 0); - PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); - break; + case IDM_PASTESEND: + SendMessage(hwnd, EM_PASTESPECIAL, CF_TEXT, 0); + PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); + break; - case IDM_DELETE: - SendMessage(hwnd, EM_REPLACESEL, TRUE, 0); - break; + case IDM_DELETE: + SendMessage(hwnd, EM_REPLACESEL, TRUE, 0); + break; - case IDM_SELECTALL: - SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&all); - break; + case IDM_SELECTALL: + SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&all); + break; - case IDM_CLEAR: - SetWindowText(hwnd, _T( "" )); - break; - } - DestroyMenu(hMenu); - return 0; + case IDM_CLEAR: + SetWindowText(hwnd, _T("")); + break; } + DestroyMenu(hMenu); + return 0; + } case WM_PASTE: if (IsClipboardFormatAvailable(CF_HDROP)) { @@ -493,18 +495,18 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wPar static LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - SrmmWindowData *pdat = (SrmmWindowData *)GetWindowLongPtr(GetParent(hwnd),GWLP_USERDATA); + SrmmWindowData *pdat = (SrmmWindowData *)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); switch (msg) { case WM_NCHITTEST: return HTCLIENT; case WM_SETCURSOR: - { - RECT rc; - GetClientRect(hwnd, &rc); - SetCursor(rc.right > rc.bottom ? hCurSplitNS : hCurSplitWE); - } + { + RECT rc; + GetClientRect(hwnd, &rc); + SetCursor(rc.right > rc.bottom ? hCurSplitNS : hCurSplitWE); + } return TRUE; case WM_LBUTTONDOWN: @@ -515,7 +517,7 @@ static LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, if (GetCapture() == hwnd) { RECT rc; GetClientRect(hwnd, &rc); - SendMessage(GetParent(hwnd), DM_SPLITTERMOVED, rc.right > rc.bottom ? (short) HIWORD(GetMessagePos()) + rc.bottom / 2 : (short) LOWORD(GetMessagePos()) + rc.right / 2, (LPARAM) hwnd); + SendMessage(GetParent(hwnd), DM_SPLITTERMOVED, rc.right > rc.bottom ? (short)HIWORD(GetMessagePos()) + rc.bottom / 2 : (short)LOWORD(GetMessagePos()) + rc.right / 2, (LPARAM)hwnd); } return 0; @@ -528,9 +530,9 @@ static LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, static int MessageDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL * urc) { - SrmmWindowData *dat = (SrmmWindowData *) lParam; + SrmmWindowData *dat = (SrmmWindowData *)lParam; - if ( !(g_dat.flags & SMF_SHOWINFO) && !(g_dat.flags & SMF_SHOWBTNS)) { + if (!(g_dat.flags & SMF_SHOWINFO) && !(g_dat.flags & SMF_SHOWBTNS)) { for (int i = 0; i < SIZEOF(buttonLineControls); i++) if (buttonLineControls[i] == urc->wId) OffsetRect(&urc->rcItem, 0, -dat->lineHeight); @@ -538,25 +540,25 @@ static int MessageDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL * switch (urc->wId) { case IDC_NAME: - { - HWND h = GetDlgItem(hwndDlg, IDC_NAME); - int len = GetWindowTextLength(h); - if (len > 0) { - TCHAR buf[256]; - GetWindowText(h, buf, SIZEOF(buf)); - - HDC hdc = GetDC(h); - HFONT hFont = (HFONT)SelectObject(hdc, (HFONT) SendMessage(GetDlgItem(hwndDlg, IDOK), WM_GETFONT, 0, 0)); - - SIZE textSize; - GetTextExtentPoint32(hdc, buf, lstrlen(buf), &textSize); - urc->rcItem.right = urc->rcItem.left + textSize.cx + 10; - if ((g_dat.flags&SMF_SHOWBTNS) && urc->rcItem.right > urc->dlgNewSize.cx - dat->nLabelRight) - urc->rcItem.right = urc->dlgNewSize.cx - dat->nLabelRight; - SelectObject(hdc, hFont); - ReleaseDC(h, hdc); - } + { + HWND h = GetDlgItem(hwndDlg, IDC_NAME); + int len = GetWindowTextLength(h); + if (len > 0) { + TCHAR buf[256]; + GetWindowText(h, buf, SIZEOF(buf)); + + HDC hdc = GetDC(h); + HFONT hFont = (HFONT)SelectObject(hdc, (HFONT)SendMessage(GetDlgItem(hwndDlg, IDOK), WM_GETFONT, 0, 0)); + + SIZE textSize; + GetTextExtentPoint32(hdc, buf, lstrlen(buf), &textSize); + urc->rcItem.right = urc->rcItem.left + textSize.cx + 10; + if ((g_dat.flags&SMF_SHOWBTNS) && urc->rcItem.right > urc->dlgNewSize.cx - dat->nLabelRight) + urc->rcItem.right = urc->dlgNewSize.cx - dat->nLabelRight; + SelectObject(hdc, hFont); + ReleaseDC(h, hdc); } + } case IDC_PROTOCOL: return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; @@ -567,7 +569,7 @@ static int MessageDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL * return RD_ANCHORX_RIGHT | RD_ANCHORY_TOP; case IDC_LOG: - if ( !(g_dat.flags&SMF_SHOWINFO) && !(g_dat.flags&SMF_SHOWBTNS)) + if (!(g_dat.flags&SMF_SHOWINFO) && !(g_dat.flags&SMF_SHOWBTNS)) urc->rcItem.top -= dat->lineHeight; urc->rcItem.bottom -= dat->splitterPos - dat->originalSplitterPos; return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT; @@ -578,13 +580,13 @@ static int MessageDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL * return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM; case IDC_MESSAGE: - if ( !(g_dat.flags & SMF_SENDBTN)) + if (!(g_dat.flags & SMF_SENDBTN)) urc->rcItem.right = urc->dlgNewSize.cx - urc->rcItem.left; if ((g_dat.flags & SMF_AVATAR) && dat->avatarPic) - urc->rcItem.left = dat->avatarWidth+4; + urc->rcItem.left = dat->avatarWidth + 4; urc->rcItem.top -= dat->splitterPos - dat->originalSplitterPos; - if ( !(g_dat.flags & SMF_SENDBTN)) + if (!(g_dat.flags & SMF_SENDBTN)) return RD_ANCHORX_CUSTOM | RD_ANCHORY_BOTTOM; return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM; @@ -594,9 +596,9 @@ static int MessageDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL * return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM; case IDC_AVATAR: - urc->rcItem.top=urc->rcItem.bottom-(dat->avatarHeight + 2); - urc->rcItem.right=urc->rcItem.left+(dat->avatarWidth + 2); - return RD_ANCHORX_LEFT|RD_ANCHORY_BOTTOM; + urc->rcItem.top = urc->rcItem.bottom - (dat->avatarHeight + 2); + urc->rcItem.right = urc->rcItem.left + (dat->avatarWidth + 2); + return RD_ANCHORX_LEFT | RD_ANCHORY_BOTTOM; } return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; } @@ -605,7 +607,7 @@ void ShowAvatar(HWND hwndDlg, SrmmWindowData *dat) { if (g_dat.flags & SMF_AVATAR) { AVATARCACHEENTRY *ace = (AVATARCACHEENTRY *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)dat->hContact, 0); - if (ace && (INT_PTR)ace != CALLSERVICE_NOTFOUND && (ace->dwFlags & AVS_BITMAP_VALID) && !(ace->dwFlags & AVS_HIDEONCLIST)) + if (ace && (INT_PTR)ace != CALLSERVICE_NOTFOUND && (ace->dwFlags & AVS_BITMAP_VALID) && !(ace->dwFlags & AVS_HIDEONCLIST)) dat->avatarPic = ace->hbmPic; else dat->avatarPic = NULL; @@ -618,7 +620,7 @@ void ShowAvatar(HWND hwndDlg, SrmmWindowData *dat) static void NotifyTyping(SrmmWindowData *dat, int mode) { - if ( !dat->hContact) + if (!dat->hContact) return; // Don't send to protocols who don't support typing // Don't send to users who are unchecked in the typing notification options @@ -626,17 +628,17 @@ static void NotifyTyping(SrmmWindowData *dat, int mode) // Don't send to users who are not visible and // Don't send to users who are not on the visible list when you are in invisible mode. - if ( !db_get_b(dat->hContact, SRMMMOD, SRMSGSET_TYPING, db_get_b(NULL, SRMMMOD, SRMSGSET_TYPINGNEW, SRMSGDEFSET_TYPINGNEW))) + if (!db_get_b(dat->hContact, SRMMMOD, SRMSGSET_TYPING, db_get_b(NULL, SRMMMOD, SRMSGSET_TYPINGNEW, SRMSGDEFSET_TYPINGNEW))) return; - if ( !dat->szProto) + if (!dat->szProto) return; DWORD protoStatus = CallProtoService(dat->szProto, PS_GETSTATUS, 0, 0); DWORD protoCaps = CallProtoService(dat->szProto, PS_GETCAPS, PFLAGNUM_1, 0); DWORD typeCaps = CallProtoService(dat->szProto, PS_GETCAPS, PFLAGNUM_4, 0); - if ( !(typeCaps & PF4_SUPPORTTYPING)) + if (!(typeCaps & PF4_SUPPORTTYPING)) return; if (protoStatus < ID_STATUS_ONLINE) @@ -648,20 +650,20 @@ static void NotifyTyping(SrmmWindowData *dat, int mode) if (protoCaps & PF1_INVISLIST && protoStatus == ID_STATUS_INVISIBLE && db_get_w(dat->hContact, dat->szProto, "ApparentMode", 0) != ID_STATUS_ONLINE) return; - if ( !(g_dat.flags & SMF_TYPINGUNKNOWN) && db_get_b(dat->hContact, "CList", "NotOnList", 0)) + if (!(g_dat.flags & SMF_TYPINGUNKNOWN) && db_get_b(dat->hContact, "CList", "NotOnList", 0)) return; // End user check dat->nTypeMode = mode; - CallService(MS_PROTO_SELFISTYPING, (WPARAM) dat->hContact, dat->nTypeMode); + CallService(MS_PROTO_SELFISTYPING, (WPARAM)dat->hContact, dat->nTypeMode); } void Button_SetIcon_IcoLib(HWND hwndDlg, int itemId, int iconId, const char* tooltip) { - HWND hWnd = GetDlgItem( hwndDlg, itemId ); - SendMessage( hWnd, BM_SETIMAGE, IMAGE_ICON, ( LPARAM )LoadSkinnedIcon( iconId )); - SendMessage( hWnd, BUTTONSETASFLATBTN, TRUE, 0 ); - SendMessage( hWnd, BUTTONADDTOOLTIP, (WPARAM)tooltip, 0); + HWND hWnd = GetDlgItem(hwndDlg, itemId); + SendMessage(hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadSkinnedIcon(iconId)); + SendMessage(hWnd, BUTTONSETASFLATBTN, TRUE, 0); + SendMessage(hWnd, BUTTONADDTOOLTIP, (WPARAM)tooltip, 0); } void Button_FreeIcon_IcoLib(HWND hwndDlg, int itemId) @@ -677,13 +679,13 @@ void Window_FreeIcon_IcoLib(HWND hwndDlg) INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - SrmmWindowData *dat = (SrmmWindowData *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + SrmmWindowData *dat = (SrmmWindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); { NewMessageWindowLParam *newData = (NewMessageWindowLParam *)lParam; - TranslateDialogDefault(hwndDlg); dat = new SrmmWindowData(); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); @@ -748,16 +750,17 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP EnableWindow(GetDlgItem(hwndDlg, IDC_PROTOCOL), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_AVATAR), FALSE); + SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETOLECALLBACK, 0, (LPARAM)& reOleCallback); SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS | ENM_LINK | ENM_SCROLL); - /* duh, how come we didnt use this from the start? */ SendDlgItemMessage(hwndDlg, IDC_LOG, EM_AUTOURLDETECT, TRUE, 0); + if (dat->hContact && dat->szProto) { - int nMax; - nMax = CallProtoService(dat->szProto, PS_GETCAPS, PFLAG_MAXLENOFMESSAGE, (LPARAM)dat->hContact); + int nMax = CallProtoService(dat->szProto, PS_GETCAPS, PFLAG_MAXLENOFMESSAGE, (LPARAM)dat->hContact); if (nMax) SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_LIMITTEXT, (WPARAM)nMax, 0); - /* get around a lame bug in the Windows template resource code where richedits are limited to 0x7FFF */ + + // get around a lame bug in the Windows template resource code where richedits are limited to 0x7FFF SendDlgItemMessage(hwndDlg, IDC_LOG, EM_LIMITTEXT, (WPARAM) sizeof(TCHAR)* 0x7FFFFFFF, 0); } @@ -771,23 +774,20 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP dat->hDbEventFirst = db_event_firstUnread(dat->hContact); switch (historyMode) { case LOADHISTORY_COUNT: - { + for (int i = db_get_w(NULL, SRMMMOD, SRMSGSET_LOADCOUNT, SRMSGDEFSET_LOADCOUNT); i--;) { HANDLE hPrevEvent; - DBEVENTINFO dbei = { sizeof(dbei) }; - for (int i = db_get_w(NULL, SRMMMOD, SRMSGSET_LOADCOUNT, SRMSGDEFSET_LOADCOUNT); i--;) { - if (dat->hDbEventFirst == NULL) - hPrevEvent = db_event_last(dat->hContact); - else - hPrevEvent = db_event_prev(dat->hContact, dat->hDbEventFirst); - if (hPrevEvent == NULL) - break; + if (dat->hDbEventFirst == NULL) + hPrevEvent = db_event_last(dat->hContact); + else + hPrevEvent = db_event_prev(dat->hContact, dat->hDbEventFirst); + if (hPrevEvent == NULL) + break; - dbei.cbBlob = 0; - dat->hDbEventFirst = hPrevEvent; - db_event_get(hPrevEvent, &dbei); - if (!DbEventIsShown(&dbei, dat)) - i++; - } + DBEVENTINFO dbei = { sizeof(dbei) }; + dat->hDbEventFirst = hPrevEvent; + db_event_get(hPrevEvent, &dbei); + if (!DbEventIsShown(&dbei, dat)) + i++; } break; @@ -829,7 +829,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP break; } } - while (hdbEvent = db_event_prev(dat->hContact, hdbEvent)); + while (hdbEvent = db_event_prev(dat->hContact, hdbEvent)); } SendMessage(hwndDlg, DM_OPTIONSAPPLIED, 1, 0); @@ -837,7 +837,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP //restore saved msg if any... if (dat->hContact) { DBVARIANT dbv; - if ( !db_get_ts(dat->hContact, SRMSGMOD, DBSAVEDMSG, &dbv)) { + if (!db_get_ts(dat->hContact, SRMSGMOD, DBSAVEDMSG, &dbv)) { if (dbv.ptszVal[0]) { SetDlgItemText(hwndDlg, IDC_MESSAGE, dbv.ptszVal); EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE); @@ -874,11 +874,11 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP SendMessage(hwndDlg, DM_GETAVATAR, 0, 0); NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_OPEN); - return FALSE; } + return FALSE; case WM_CONTEXTMENU: - if (dat->hwndStatus && dat->hwndStatus == (HWND) wParam) { + if (dat->hwndStatus && dat->hwndStatus == (HWND)wParam) { POINT pt, pt2; GetCursorPos(&pt); pt2.x = pt.x; pt2.y = pt.y; @@ -912,7 +912,8 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP AddToFileList(&ppFiles, &totalCount, szFilename); } CallServiceSync(MS_FILE_SENDSPECIFICFILEST, (WPARAM)dat->hContact, (LPARAM)ppFiles); - for (i = 0; ppFiles[i]; i++) mir_free(ppFiles[i]); + for (i = 0; ppFiles[i]; i++) + mir_free(ppFiles[i]); mir_free(ppFiles); } break; @@ -956,7 +957,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP RECT rc; GetWindowRect(GetDlgItem(hwndDlg, IDC_MESSAGE), &rc); if (rc.bottom - rc.top < dat->minEditBoxSize.cy) - SendMessage(hwndDlg, DM_SPLITTERMOVED, rc.top-(rc.bottom-rc.top-dat->minEditBoxSize.cy-4), (LPARAM) GetDlgItem(hwndDlg, IDC_SPLITTER)); + SendMessage(hwndDlg, DM_SPLITTERMOVED, rc.top - (rc.bottom - rc.top - dat->minEditBoxSize.cy - 4), (LPARAM)GetDlgItem(hwndDlg, IDC_SPLITTER)); SendMessage(hwndDlg, WM_SIZE, 0, 0); } @@ -982,13 +983,13 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if (dat->szProto) { WORD wStatus = db_get_w(dat->hContact, dat->szProto, "Status", ID_STATUS_OFFLINE); - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) LoadSkinnedProtoIconBig(dat->szProto, wStatus)); - SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) LoadSkinnedProtoIcon(dat->szProto, wStatus)); + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadSkinnedProtoIconBig(dat->szProto, wStatus)); + SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadSkinnedProtoIcon(dat->szProto, wStatus)); break; } } - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) LoadSkinnedIconBig(SKINICON_EVENT_MESSAGE)); - SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) LoadSkinnedIcon(SKINICON_EVENT_MESSAGE)); + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadSkinnedIconBig(SKINICON_EVENT_MESSAGE)); + SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadSkinnedIcon(SKINICON_EVENT_MESSAGE)); break; case DM_USERNAMETOCLIP: @@ -1030,11 +1031,11 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP tmi.printTimeStamp(NULL, dat->lastMessage, _T("d"), date, SIZEOF(date), 0); tmi.printTimeStamp(NULL, dat->lastMessage, _T("t"), time, SIZEOF(time), 0); mir_sntprintf(fmt, SIZEOF(fmt), TranslateT("Last message received on %s at %s."), date, time); - SendMessage(dat->hwndStatus, SB_SETTEXT, 0, (LPARAM) fmt); + SendMessage(dat->hwndStatus, SB_SETTEXT, 0, (LPARAM)fmt); } - else SendMessage(dat->hwndStatus, SB_SETTEXT, 0, (LPARAM) _T("")); + else SendMessage(dat->hwndStatus, SB_SETTEXT, 0, (LPARAM)_T("")); - SendMessage(dat->hwndStatus, SB_SETICON, 0, (LPARAM) NULL); + SendMessage(dat->hwndStatus, SB_SETICON, 0, (LPARAM)NULL); break; case DM_OPTIONSAPPLIED: @@ -1052,7 +1053,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP dat->limitAvatarH = 0; if (CallProtoService(dat->szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_AVATARS) dat->limitAvatarH = db_get_b(NULL, SRMMMOD, SRMSGSET_LIMITAVHEIGHT, SRMSGDEFSET_LIMITAVHEIGHT) ? - db_get_dw(NULL, SRMMMOD, SRMSGSET_AVHEIGHT, SRMSGDEFSET_AVHEIGHT) : 0; + db_get_dw(NULL, SRMMMOD, SRMSGSET_AVHEIGHT, SRMSGDEFSET_AVHEIGHT) : 0; if (!wParam) SendMessage(hwndDlg, DM_GETAVATAR, 0, 0); @@ -1061,17 +1062,17 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP { HFONT hFont; LOGFONT lf; - CHARFORMAT cf = {0}; - hFont = (HFONT) SendDlgItemMessage(hwndDlg, IDC_MESSAGE, WM_GETFONT, 0, 0); - if (hFont != NULL && hFont != (HFONT) SendDlgItemMessage(hwndDlg, IDOK, WM_GETFONT, 0, 0)) + CHARFORMAT cf = { 0 }; + hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_MESSAGE, WM_GETFONT, 0, 0); + if (hFont != NULL && hFont != (HFONT)SendDlgItemMessage(hwndDlg, IDOK, WM_GETFONT, 0, 0)) DeleteObject(hFont); LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, &lf, &cf.crTextColor); hFont = CreateFontIndirect(&lf); - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, WM_SETFONT, (WPARAM) hFont, MAKELPARAM(TRUE, 0)); + SendDlgItemMessage(hwndDlg, IDC_MESSAGE, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_COLOR; - SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (WPARAM) &cf); + SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (WPARAM)&cf); } // configure message history for proper RTL formatting @@ -1086,7 +1087,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETPARAFORMAT, 0, (LPARAM)&pf2); pf2.wEffects = 0; SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETPARAFORMAT, 0, (LPARAM)&pf2); - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETLANGOPTIONS, 0, (LPARAM) SendDlgItemMessage(hwndDlg, IDC_LOG, EM_GETLANGOPTIONS, 0, 0) & ~IMF_AUTOKEYBOARD); + SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETLANGOPTIONS, 0, (LPARAM)SendDlgItemMessage(hwndDlg, IDC_LOG, EM_GETLANGOPTIONS, 0, 0) & ~IMF_AUTOKEYBOARD); } SendMessage(hwndDlg, DM_REMAKELOG, 0, 0); SendMessage(hwndDlg, DM_UPDATEWINICON, 0, 0); @@ -1096,7 +1097,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP { TCHAR newtitle[256], oldtitle[256], *szStatus; TCHAR *contactName, *pszNewTitleEnd; - DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) wParam; + DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)wParam; pszNewTitleEnd = _T("Message Session"); if (dat->hContact) { @@ -1108,12 +1109,12 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP contactName = pcli->pfnGetContactDisplayName(dat->hContact, 0); if (strcmp(dat->szProto, "MetaContacts")) { - CONTACTINFO ci = {0}; + CONTACTINFO ci = { 0 }; ci.cbSize = sizeof(ci); ci.hContact = dat->hContact; ci.szProto = dat->szProto; ci.dwFlag = CNF_DISPLAYUID | CNF_TCHAR; - if ( !CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) { + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) { switch (ci.type) { case CNFT_ASCIIZ: mir_sntprintf(buf, SIZEOF(buf), _T("%s"), (TCHAR*)ci.pszVal); @@ -1136,7 +1137,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP else mir_sntprintf(newtitle, SIZEOF(newtitle), _T("%s (%s): %s"), contactName, szStatus, TranslateTS(pszNewTitleEnd)); - if ( !cws || (!strcmp(cws->szModule, dat->szProto) && !strcmp(cws->szSetting, "Status"))) { + if (!cws || (!strcmp(cws->szModule, dat->szProto) && !strcmp(cws->szSetting, "Status"))) { InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOCOL), NULL, TRUE); if (statusIcon) SendMessage(hwndDlg, DM_UPDATEWINICON, 0, 0); @@ -1148,12 +1149,12 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP else lstrcpyn(newtitle, pszNewTitleEnd, SIZEOF(newtitle)); GetWindowText(hwndDlg, oldtitle, SIZEOF(oldtitle)); - if ( _tcscmp(newtitle, oldtitle )) { //swt() flickers even if the title hasn't actually changed + if (_tcscmp(newtitle, oldtitle)) { //swt() flickers even if the title hasn't actually changed SetWindowText(hwndDlg, newtitle); SendMessage(hwndDlg, WM_SIZE, 0, 0); } - break; } + break; case DM_NEWTIMEZONE: dat->hTimeZone = tmi.createByContact(dat->hContact, 0, TZF_KNOWNONLY); @@ -1179,11 +1180,11 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if ((HWND)wParam != hwndDlg) { RECT rcThis, rcNew; GetWindowRect(hwndDlg, &rcThis); - GetWindowRect((HWND) wParam, &rcNew); + GetWindowRect((HWND)wParam, &rcNew); if (abs(rcThis.left - rcNew.left) < 3 && abs(rcThis.top - rcNew.top) < 3) { int offset = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME); - SetWindowPos((HWND) wParam, 0, rcNew.left + offset, rcNew.top + offset, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE); - *(int *) lParam = 1; + SetWindowPos((HWND)wParam, 0, rcNew.left + offset, rcNew.top + offset, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE); + *(int *)lParam = 1; } } break; @@ -1202,29 +1203,26 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP case WM_GETMINMAXINFO: { - MINMAXINFO* mmi = (MINMAXINFO *) lParam; + MINMAXINFO* mmi = (MINMAXINFO *)lParam; RECT rcWindow, rcLog; GetWindowRect(hwndDlg, &rcWindow); GetWindowRect(GetDlgItem(hwndDlg, IDC_LOG), &rcLog); mmi->ptMinTrackSize.x = rcWindow.right - rcWindow.left - ((rcLog.right - rcLog.left) - dat->minEditBoxSize.cx); mmi->ptMinTrackSize.y = rcWindow.bottom - rcWindow.top - ((rcLog.bottom - rcLog.top) - dat->minEditBoxSize.cy); - return 0; } + return 0; case WM_SIZE: - { + if (!IsIconic(hwndDlg)) { BOOL bottomScroll = TRUE; - if (IsIconic(hwndDlg)) - break; - if (dat->hwndStatus) { SendMessage(dat->hwndStatus, WM_SIZE, 0, 0); SetupStatusBar(hwndDlg, dat); } - if ( GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_STYLE) & WS_VSCROLL) { - SCROLLINFO si = {0}; + if (GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_STYLE) & WS_VSCROLL) { + SCROLLINFO si = { 0 }; si.cbSize = sizeof(si); si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; GetScrollInfo(GetDlgItem(hwndDlg, IDC_LOG), SB_VERT, &si); @@ -1234,10 +1232,10 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP UTILRESIZEDIALOG urd = { sizeof(urd) }; urd.hInstance = g_hInst; urd.hwndDlg = hwndDlg; - urd.lParam = (LPARAM) dat; + urd.lParam = (LPARAM)dat; urd.lpTemplate = MAKEINTRESOURCEA(IDD_MSG); urd.pfnResizer = MessageDialogResize; - CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM) & urd); + CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)& urd); // The statusbar sometimes draws over these 2 controls so // redraw them @@ -1250,11 +1248,11 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if (bottomScroll) PostMessage(hwndDlg, DM_SCROLLLOGTOBOTTOM, 0, 0); - break; } + break; case DM_SPLITTERMOVED: - if ((HWND) lParam == GetDlgItem(hwndDlg, IDC_SPLITTER)) { + if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SPLITTER)) { HWND hwndLog = GetDlgItem(hwndDlg, IDC_LOG); RECT rc, rcLog; @@ -1290,7 +1288,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP { HWND hwndLog = GetDlgItem(hwndDlg, IDC_LOG); if (GetWindowLongPtr(hwndLog, GWL_STYLE) & WS_VSCROLL) { - SCROLLINFO si = {0}; + SCROLLINFO si = { 0 }; si.cbSize = sizeof(si); si.fMask = SIF_PAGE | SIF_RANGE; GetScrollInfo(hwndLog, SB_VERT, &si); @@ -1317,7 +1315,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP else SkinPlaySound("RecvMsgInactive"); } - if (( dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei)) && dat->hwndStatus && !(dbei.flags & DBEF_SENT)) { + if ((dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei)) && dat->hwndStatus && !(dbei.flags & DBEF_SENT)) { dat->lastMessage = dbei.timestamp; SendMessage(hwndDlg, DM_UPDATELASTMESSAGE, 0, 0); } @@ -1326,11 +1324,11 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP else SendMessage(hwndDlg, DM_REMAKELOG, 0, 0); - if ( !(dbei.flags & DBEF_SENT)) { + if (!(dbei.flags & DBEF_SENT)) { if (GetActiveWindow() == hwndDlg && GetForegroundWindow() == hwndDlg) { HWND hwndLog = GetDlgItem(hwndDlg, IDC_LOG); if (GetWindowLongPtr(hwndLog, GWL_STYLE) & WS_VSCROLL) { - SCROLLINFO si = {0}; + SCROLLINFO si = { 0 }; si.cbSize = sizeof(si); si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; GetScrollInfo(hwndLog, SB_VERT, &si); @@ -1386,11 +1384,11 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP mir_sntprintf(szBuf, SIZEOF(szBuf), TranslateT("%s is typing a message..."), szContactName); dat->nTypeSecs--; - SendMessage(dat->hwndStatus, SB_SETTEXT, 0, (LPARAM) szBuf); - SendMessage(dat->hwndStatus, SB_SETICON, 0, (LPARAM) hTyping); + SendMessage(dat->hwndStatus, SB_SETTEXT, 0, (LPARAM)szBuf); + SendMessage(dat->hwndStatus, SB_SETICON, 0, (LPARAM)hTyping); if ((g_dat.flags & SMF_SHOWTYPINGWIN) && GetForegroundWindow() != hwndDlg) { HICON hIcon = (HICON)SendMessage(hwndDlg, WM_GETICON, ICON_SMALL, 0); - SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hTyping ); + SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hTyping); Skin_ReleaseIcon(hIcon); } dat->showTyping = 1; @@ -1401,7 +1399,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP case WM_MEASUREITEM: { - LPMEASUREITEMSTRUCT mis = (LPMEASUREITEMSTRUCT) lParam; + LPMEASUREITEMSTRUCT mis = (LPMEASUREITEMSTRUCT)lParam; if (mis->CtlType == ODT_MENU) return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); } @@ -1409,20 +1407,20 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP case WM_DRAWITEM: { - LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT) lParam; + LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; if (dis->CtlType == ODT_MENU) return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); - else if (dis->hwndItem == dat->hwndStatus) { + if (dis->hwndItem == dat->hwndStatus) { DrawStatusIcons(dat->hContact, dis->hDC, dis->rcItem, 2); return TRUE; } - else if (dis->CtlID == IDC_PROTOCOL) { + if (dis->CtlID == IDC_PROTOCOL) { if (dat->szProto) { int dwStatus = db_get_w(dat->hContact, dat->szProto, "Status", ID_STATUS_OFFLINE); HICON hIcon = LoadSkinnedProtoIcon(dat->szProto, dwStatus); if (hIcon) { if (db_get_dw(dat->hContact, dat->szProto, "IdleTS", 0)) { - HIMAGELIST hImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 1, 0); + HIMAGELIST hImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 1, 0); ImageList_AddIcon(hImageList, hIcon); ImageList_DrawEx(hImageList, 0, dis->hDC, dis->rcItem.left, dis->rcItem.top, 0, 0, CLR_NONE, CLR_NONE, ILD_SELECTED); ImageList_Destroy(hImageList); @@ -1435,10 +1433,10 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP } } else if (dis->CtlID == IDC_AVATAR && dat->avatarPic && (g_dat.flags & SMF_AVATAR)) { - HPEN hPen = CreatePen(PS_SOLID, 1, RGB(0,0,0)); + HPEN hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); HPEN hOldPen = (HPEN)SelectObject(dis->hDC, hPen); Rectangle(dis->hDC, 0, 0, dat->avatarWidth, dat->avatarHeight); - SelectObject(dis->hDC,hOldPen); + SelectObject(dis->hDC, hOldPen); DeleteObject(hPen); BITMAP bminfo; @@ -1448,10 +1446,10 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP HBITMAP hbmMem = (HBITMAP)SelectObject(hdcMem, dat->avatarPic); SetStretchBltMode(dis->hDC, HALFTONE); - StretchBlt(dis->hDC, 1, 1, dat->avatarWidth-2, dat->avatarHeight-2, hdcMem, 0, 0, - bminfo.bmWidth, bminfo.bmHeight, SRCCOPY); + StretchBlt(dis->hDC, 1, 1, dat->avatarWidth - 2, dat->avatarHeight - 2, hdcMem, 0, 0, + bminfo.bmWidth, bminfo.bmHeight, SRCCOPY); - SelectObject(hdcMem,hbmMem); + SelectObject(hdcMem, hbmMem); DeleteDC(hdcMem); return TRUE; } @@ -1459,7 +1457,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP break; case WM_COMMAND: - if ( !lParam && CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM) dat->hContact)) + if (!lParam && CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) break; switch (LOWORD(wParam)) { @@ -1508,7 +1506,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP SendMessage(hwndDlg, DM_USERNAMETOCLIP, 0, 0); else { RECT rc; - HMENU hMenu = (HMENU) CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM) dat->hContact, 0); + HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); GetWindowRect(GetDlgItem(hwndDlg, LOWORD(wParam)), &rc); TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); DestroyMenu(hMenu); @@ -1516,11 +1514,11 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP break; case IDC_HISTORY: - CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM) dat->hContact, 0); + CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0); break; case IDC_DETAILS: - CallService(MS_USERINFO_SHOWDIALOG, (WPARAM) dat->hContact, 0); + CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0); break; case IDC_ADD: @@ -1529,9 +1527,9 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP acs.hContact = dat->hContact; acs.handleType = HANDLE_CONTACT; acs.szProto = 0; - CallService(MS_ADDCONTACT_SHOW, (WPARAM) hwndDlg, (LPARAM) & acs); + CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)& acs); } - if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0)) + if (!db_get_b(dat->hContact, "CList", "NotOnList", 0)) ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE); break; @@ -1540,7 +1538,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP int len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE)); UpdateReadChars(hwndDlg, dat->hwndStatus); EnableWindow(GetDlgItem(hwndDlg, IDOK), len != 0); - if ( !(GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_SHIFT) & 0x8000)) { + if (!(GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_SHIFT) & 0x8000)) { dat->nLastTyping = GetTickCount(); if (len) { if (dat->nTypeMode == PROTOTYPE_SELFTYPING_OFF) @@ -1555,84 +1553,83 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP break; case WM_NOTIFY: - if (dat && ((LPNMHDR) lParam)->hwndFrom == dat->hwndStatus) { - if (((LPNMHDR) lParam)->code == NM_CLICK || ((LPNMHDR) lParam)->code == NM_RCLICK) { - NMMOUSE *nm = (NMMOUSE *) lParam; + if (dat && ((LPNMHDR)lParam)->hwndFrom == dat->hwndStatus) { + if (((LPNMHDR)lParam)->code == NM_CLICK || ((LPNMHDR)lParam)->code == NM_RCLICK) { + NMMOUSE *nm = (NMMOUSE *)lParam; RECT rc; SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc); if (nm->pt.x >= rc.left) - CheckIconClick(dat->hContact, dat->hwndStatus, nm->pt, rc, 2, ((LPNMHDR) lParam)->code == NM_RCLICK ? MBCF_RIGHTBUTTON : 0); + CheckIconClick(dat->hContact, dat->hwndStatus, nm->pt, rc, 2, ((LPNMHDR)lParam)->code == NM_RCLICK ? MBCF_RIGHTBUTTON : 0); return TRUE; } } - switch (((LPNMHDR) lParam)->idFrom) { + switch (((LPNMHDR)lParam)->idFrom) { case IDC_LOG: - switch (((LPNMHDR) lParam)->code) { + switch (((LPNMHDR)lParam)->code) { case EN_MSGFILTER: - switch (((MSGFILTER *) lParam)->msg) { + switch (((MSGFILTER *)lParam)->msg) { case WM_LBUTTONDOWN: { HCURSOR hCur = GetCursor(); if (hCur == LoadCursor(NULL, IDC_SIZENS) || hCur == LoadCursor(NULL, IDC_SIZEWE) - || hCur == LoadCursor(NULL, IDC_SIZENESW) || hCur == LoadCursor(NULL, IDC_SIZENWSE)) - { + || hCur == LoadCursor(NULL, IDC_SIZENESW) || hCur == LoadCursor(NULL, IDC_SIZENWSE)) { SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); return TRUE; } - break; } + break; + case WM_MOUSEMOVE: { HCURSOR hCur = GetCursor(); if (hCur == LoadCursor(NULL, IDC_SIZENS) || hCur == LoadCursor(NULL, IDC_SIZEWE) - || hCur == LoadCursor(NULL, IDC_SIZENESW) || hCur == LoadCursor(NULL, IDC_SIZENWSE)) - SetCursor(LoadCursor(NULL, IDC_ARROW)); - break; + || hCur == LoadCursor(NULL, IDC_SIZENESW) || hCur == LoadCursor(NULL, IDC_SIZENWSE)) + SetCursor(LoadCursor(NULL, IDC_ARROW)); } - case WM_RBUTTONUP: - { - POINT pt; - CHARRANGE sel, all = { 0, -1 }; - HMENU hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT)); - HMENU hSubMenu = GetSubMenu(hMenu, 0); - TranslateMenu(hSubMenu); - SendMessage(((NMHDR *) lParam)->hwndFrom, EM_EXGETSEL, 0, (LPARAM) & sel); - if (sel.cpMin == sel.cpMax) - EnableMenuItem(hSubMenu, IDM_COPY, MF_BYCOMMAND | MF_GRAYED); - pt.x = (short) LOWORD(((ENLINK *) lParam)->lParam); - pt.y = (short) HIWORD(((ENLINK *) lParam)->lParam); - ClientToScreen(((NMHDR *) lParam)->hwndFrom, &pt); + break; - switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL)) { - case IDM_COPY: - SendMessage(((NMHDR *) lParam)->hwndFrom, WM_COPY, 0, 0); - break; - case IDM_COPYALL: - SendMessage(((NMHDR *) lParam)->hwndFrom, EM_EXSETSEL, 0, (LPARAM) & all); - SendMessage(((NMHDR *) lParam)->hwndFrom, WM_COPY, 0, 0); - SendMessage(((NMHDR *) lParam)->hwndFrom, EM_EXSETSEL, 0, (LPARAM) & sel); - break; - case IDM_SELECTALL: - SendMessage(((NMHDR *) lParam)->hwndFrom, EM_EXSETSEL, 0, (LPARAM) & all); - break; - case IDM_CLEAR: - SetDlgItemText(hwndDlg, IDC_LOG, _T("")); - dat->hDbEventFirst = NULL; - break; - } - DestroyMenu(hSubMenu); - DestroyMenu(hMenu); - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); - return TRUE; + case WM_RBUTTONUP: + POINT pt; + CHARRANGE sel, all = { 0, -1 }; + HMENU hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT)); + HMENU hSubMenu = GetSubMenu(hMenu, 0); + TranslateMenu(hSubMenu); + SendMessage(((NMHDR *)lParam)->hwndFrom, EM_EXGETSEL, 0, (LPARAM)& sel); + if (sel.cpMin == sel.cpMax) + EnableMenuItem(hSubMenu, IDM_COPY, MF_BYCOMMAND | MF_GRAYED); + pt.x = (short)LOWORD(((ENLINK *)lParam)->lParam); + pt.y = (short)HIWORD(((ENLINK *)lParam)->lParam); + ClientToScreen(((NMHDR *)lParam)->hwndFrom, &pt); + + switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL)) { + case IDM_COPY: + SendMessage(((NMHDR *)lParam)->hwndFrom, WM_COPY, 0, 0); + break; + case IDM_COPYALL: + SendMessage(((NMHDR *)lParam)->hwndFrom, EM_EXSETSEL, 0, (LPARAM)& all); + SendMessage(((NMHDR *)lParam)->hwndFrom, WM_COPY, 0, 0); + SendMessage(((NMHDR *)lParam)->hwndFrom, EM_EXSETSEL, 0, (LPARAM)& sel); + break; + case IDM_SELECTALL: + SendMessage(((NMHDR *)lParam)->hwndFrom, EM_EXSETSEL, 0, (LPARAM)& all); + break; + case IDM_CLEAR: + SetDlgItemText(hwndDlg, IDC_LOG, _T("")); + dat->hDbEventFirst = NULL; + break; } + DestroyMenu(hSubMenu); + DestroyMenu(hMenu); + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); + return TRUE; } break; case EN_VSCROLL: if (LOWORD(wParam) == IDC_LOG && GetWindowLongPtr((HWND)lParam, GWL_STYLE) & WS_VSCROLL) { - SCROLLINFO si = {0}; + SCROLLINFO si = { 0 }; si.cbSize = sizeof(si); si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; GetScrollInfo((HWND)lParam, SB_VERT, &si); @@ -1643,7 +1640,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP break; case EN_LINK: - switch (((ENLINK *) lParam)->msg) { + switch (((ENLINK *)lParam)->msg) { case WM_SETCURSOR: SetCursor(hCurHyperlinkHand); SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); @@ -1651,57 +1648,55 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP case WM_RBUTTONDOWN: case WM_LBUTTONUP: - { - CHARRANGE sel; - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_EXGETSEL, 0, (LPARAM) & sel); - if (sel.cpMin != sel.cpMax) - break; + CHARRANGE sel; + SendDlgItemMessage(hwndDlg, IDC_LOG, EM_EXGETSEL, 0, (LPARAM)& sel); + if (sel.cpMin != sel.cpMax) + break; - TEXTRANGE tr; - tr.chrg = ((ENLINK *)lParam)->chrg; - tr.lpstrText = (TCHAR*)_alloca((tr.chrg.cpMax - tr.chrg.cpMin + 8) * sizeof(TCHAR)); - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_GETTEXTRANGE, 0, (LPARAM) & tr); - if (_tcschr(tr.lpstrText, '@') != NULL && _tcschr(tr.lpstrText, ':') == NULL && _tcschr(tr.lpstrText, '/') == NULL) { - memmove(tr.lpstrText + 7, tr.lpstrText, (tr.chrg.cpMax - tr.chrg.cpMin + 1) * sizeof(TCHAR)); - memcpy(tr.lpstrText, _T("mailto:"), 7 * sizeof(TCHAR)); - } + TEXTRANGE tr; + tr.chrg = ((ENLINK *)lParam)->chrg; + tr.lpstrText = (TCHAR*)_alloca((tr.chrg.cpMax - tr.chrg.cpMin + 8) * sizeof(TCHAR)); + SendDlgItemMessage(hwndDlg, IDC_LOG, EM_GETTEXTRANGE, 0, (LPARAM)& tr); + if (_tcschr(tr.lpstrText, '@') != NULL && _tcschr(tr.lpstrText, ':') == NULL && _tcschr(tr.lpstrText, '/') == NULL) { + memmove(tr.lpstrText + 7, tr.lpstrText, (tr.chrg.cpMax - tr.chrg.cpMin + 1) * sizeof(TCHAR)); + memcpy(tr.lpstrText, _T("mailto:"), 7 * sizeof(TCHAR)); + } - if (((ENLINK *)lParam)->msg == WM_RBUTTONDOWN) { - POINT pt; - HMENU hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT)); - HMENU hSubMenu = GetSubMenu(hMenu, 1); - TranslateMenu(hSubMenu); - pt.x = (short) LOWORD(((ENLINK *) lParam)->lParam); - pt.y = (short) HIWORD(((ENLINK *) lParam)->lParam); - ClientToScreen(((NMHDR *) lParam)->hwndFrom, &pt); - - switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL)) { - case IDM_OPENLINK: - ShellExecute(NULL, _T("open"), tr.lpstrText, NULL, NULL, SW_SHOW); - break; + if (((ENLINK *)lParam)->msg == WM_RBUTTONDOWN) { + POINT pt; + HMENU hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT)); + HMENU hSubMenu = GetSubMenu(hMenu, 1); + TranslateMenu(hSubMenu); + pt.x = (short)LOWORD(((ENLINK *)lParam)->lParam); + pt.y = (short)HIWORD(((ENLINK *)lParam)->lParam); + ClientToScreen(((NMHDR *)lParam)->hwndFrom, &pt); - case IDM_COPYLINK: - if (OpenClipboard(hwndDlg)) { - HGLOBAL hData; - EmptyClipboard(); - hData = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(tr.lpstrText) + 1) * sizeof(TCHAR)); - _tcscpy((TCHAR*)GlobalLock(hData), tr.lpstrText); - GlobalUnlock(hData); - SetClipboardData(CF_UNICODETEXT, hData); - CloseClipboard(); - } - break; - } + switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL)) { + case IDM_OPENLINK: + ShellExecute(NULL, _T("open"), tr.lpstrText, NULL, NULL, SW_SHOW); + break; - DestroyMenu(hMenu); - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); - return TRUE; + case IDM_COPYLINK: + if (OpenClipboard(hwndDlg)) { + HGLOBAL hData; + EmptyClipboard(); + hData = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(tr.lpstrText) + 1) * sizeof(TCHAR)); + _tcscpy((TCHAR*)GlobalLock(hData), tr.lpstrText); + GlobalUnlock(hData); + SetClipboardData(CF_UNICODETEXT, hData); + CloseClipboard(); + } + break; } - ShellExecute(NULL, _T("open"), tr.lpstrText, NULL, NULL, SW_SHOW); - SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); - break; + DestroyMenu(hMenu); + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); + return TRUE; } + + ShellExecute(NULL, _T("open"), tr.lpstrText, NULL, NULL, SW_SHOW); + SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); + break; } } } @@ -1716,67 +1711,66 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP break; case WM_DESTROY: - if (!dat) return 0; - NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_CLOSING); - //save string from the editor - if (dat->hContact) { - TCHAR* msg; - int len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE)) + 1; - msg = (TCHAR*)alloca(sizeof(TCHAR)* len); - GetDlgItemText(hwndDlg, IDC_MESSAGE, msg, len); - if (msg[0]) - db_set_ts(dat->hContact, SRMSGMOD, DBSAVEDMSG, msg); - else - db_unset(dat->hContact, SRMSGMOD, DBSAVEDMSG); - } - KillTimer(hwndDlg, TIMERID_TYPE); - if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON) - NotifyTyping(dat, PROTOTYPE_SELFTYPING_OFF); + if (dat) { + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_CLOSING); - if (dat->hBkgBrush) - DeleteObject(dat->hBkgBrush); - if (dat->hwndStatus) - DestroyWindow(dat->hwndStatus); - - for (int i = 0; i < dat->cmdList.getCount(); i++) - mir_free(dat->cmdList[i]); - dat->cmdList.destroy(); - - WindowList_Remove(g_dat.hMessageWindowList, hwndDlg); - db_set_dw(db_get_b(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT) ? dat->hContact : NULL, SRMMMOD, "splitterPos", dat->splitterPos); - - HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_MESSAGE, WM_GETFONT, 0, 0); - if (hFont != NULL && hFont != (HFONT)SendDlgItemMessage(hwndDlg, IDOK, WM_GETFONT, 0, 0)) - DeleteObject(hFont); - - MCONTACT hContact; - if (db_get_b(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT)) - hContact = dat->hContact; - else - hContact = NULL; - - WINDOWPLACEMENT wp = { 0 }; - wp.length = sizeof(wp); - GetWindowPlacement(hwndDlg, &wp); - if (!dat->windowWasCascaded) { - db_set_dw(hContact, SRMMMOD, "x", wp.rcNormalPosition.left); - db_set_dw(hContact, SRMMMOD, "y", wp.rcNormalPosition.top); + bool bSavePerContact = db_get_b(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT) != 0; + + // save string from the editor + if (dat->hContact) { + TCHAR* msg; + int len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE)) + 1; + msg = (TCHAR*)alloca(sizeof(TCHAR)* len); + GetDlgItemText(hwndDlg, IDC_MESSAGE, msg, len); + if (msg[0]) + db_set_ts(dat->hContact, SRMSGMOD, DBSAVEDMSG, msg); + else + db_unset(dat->hContact, SRMSGMOD, DBSAVEDMSG); + } + KillTimer(hwndDlg, TIMERID_TYPE); + if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON) + NotifyTyping(dat, PROTOTYPE_SELFTYPING_OFF); + + if (dat->hBkgBrush) + DeleteObject(dat->hBkgBrush); + if (dat->hwndStatus) + DestroyWindow(dat->hwndStatus); + + for (int i = 0; i < dat->cmdList.getCount(); i++) + mir_free(dat->cmdList[i]); + dat->cmdList.destroy(); + + WindowList_Remove(g_dat.hMessageWindowList, hwndDlg); + db_set_dw(bSavePerContact ? dat->hContact : NULL, SRMMMOD, "splitterPos", dat->splitterPos); + + HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_MESSAGE, WM_GETFONT, 0, 0); + if (hFont != NULL && hFont != (HFONT)SendDlgItemMessage(hwndDlg, IDOK, WM_GETFONT, 0, 0)) + DeleteObject(hFont); + + MCONTACT hContact = (bSavePerContact) ? dat->hContact : NULL; + + WINDOWPLACEMENT wp = { sizeof(wp) }; + GetWindowPlacement(hwndDlg, &wp); + if (!dat->windowWasCascaded) { + db_set_dw(hContact, SRMMMOD, "x", wp.rcNormalPosition.left); + db_set_dw(hContact, SRMMMOD, "y", wp.rcNormalPosition.top); + } + db_set_dw(hContact, SRMMMOD, "width", wp.rcNormalPosition.right - wp.rcNormalPosition.left); + db_set_dw(hContact, SRMMMOD, "height", wp.rcNormalPosition.bottom - wp.rcNormalPosition.top); + + NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_CLOSE); + if (dat->hContact && db_get_b(NULL, SRMMMOD, SRMSGSET_DELTEMP, SRMSGDEFSET_DELTEMP)) + if (db_get_b(dat->hContact, "CList", "NotOnList", 0)) + CallService(MS_DB_CONTACT_DELETE, (WPARAM)dat->hContact, 0); + + Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD); + Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS); + Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY); + Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU); + Window_FreeIcon_IcoLib(hwndDlg); + delete dat; } - db_set_dw(hContact, SRMMMOD, "width", wp.rcNormalPosition.right - wp.rcNormalPosition.left); - db_set_dw(hContact, SRMMMOD, "height", wp.rcNormalPosition.bottom - wp.rcNormalPosition.top); - - NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_CLOSE); - if (dat->hContact&&db_get_b(NULL, SRMMMOD, SRMSGSET_DELTEMP, SRMSGDEFSET_DELTEMP)) - if (db_get_b(dat->hContact, "CList", "NotOnList", 0)) - CallService(MS_DB_CONTACT_DELETE, (WPARAM)dat->hContact, 0); - - Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD); - Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS); - Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY); - Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU); - Window_FreeIcon_IcoLib(hwndDlg); - delete dat; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); break; } return FALSE; diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index 866b808102..b5c4d6c1fa 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -78,20 +78,17 @@ static int AppendToBufferWithRTF(char **buffer, int *cbBufferEnd, int *cbBufferA return 0; lineLen = (int)_tcslen(line) * 9 + 8; - if (*cbBufferEnd + lineLen > *cbBufferAlloced) - { + if (*cbBufferEnd + lineLen > *cbBufferAlloced) { cbBufferAlloced[0] += (lineLen + 1024 - lineLen % 1024); - *buffer = (char *) mir_realloc(*buffer, *cbBufferAlloced); + *buffer = (char *)mir_realloc(*buffer, *cbBufferAlloced); } d = *buffer + *cbBufferEnd; strcpy(d, "{\\uc1 "); d += 6; - for (; *line; line++, textCharsCount++) - { - if (*line == '\r' && line[1] == '\n') - { + for (; *line; line++, textCharsCount++) { + if (*line == '\r' && line[1] == '\n') { memcpy(d, "\\par ", 5); line++; d += 5; @@ -100,26 +97,20 @@ static int AppendToBufferWithRTF(char **buffer, int *cbBufferEnd, int *cbBufferA memcpy(d, "\\par ", 5); d += 5; } - else if (*line == '\t') - { + else if (*line == '\t') { memcpy(d, "\\tab ", 5); d += 5; } - else if (*line == '\\' || *line == '{' || *line == '}') - { + else if (*line == '\\' || *line == '{' || *line == '}') { *d++ = '\\'; - *d++ = (char) *line; + *d++ = (char)*line; } - else if (*line == '[' && (g_dat.flags & SMF_SHOWFORMAT)) - { + else if (*line == '[' && (g_dat.flags & SMF_SHOWFORMAT)) { int i, found = 0; - for (i = 0; i < SIZEOF(bbcodes); ++i) - { - if (line[1] == bbcodes[i][1]) - { + for (i = 0; i < SIZEOF(bbcodes); ++i) { + if (line[1] == bbcodes[i][1]) { size_t lenb = _tcslen(bbcodes[i]); - if (!_tcsnicmp(line, bbcodes[i], lenb)) - { + if (!_tcsnicmp(line, bbcodes[i], lenb)) { size_t len = strlen(bbcodefmt[i]); memcpy(d, bbcodefmt[i], len); d += len; @@ -129,18 +120,14 @@ static int AppendToBufferWithRTF(char **buffer, int *cbBufferEnd, int *cbBufferA } } } - if (!found) - { - if (!_tcsnicmp(line, _T("[url"), 4)) - { + if (!found) { + if (!_tcsnicmp(line, _T("[url"), 4)) { TCHAR* tag = _tcschr(line + 4, ']'); - if (tag) - { + if (tag) { TCHAR *tagu = (line[4] == '=') ? line + 5 : tag + 1; TCHAR *tage = _tcsstr(tag, _T("[/url]")); if (!tage) tage = _tcsstr(tag, _T("[/URL]")); - if (tage) - { + if (tage) { *tag = 0; *tage = 0; d += sprintf(d, "{\\field{\\*\\fldinst HYPERLINK \"%s\"}{\\fldrslt %s}}", mir_t2a(tagu), mir_t2a(tag + 1)); //!!!!!!!!!! @@ -149,35 +136,31 @@ static int AppendToBufferWithRTF(char **buffer, int *cbBufferEnd, int *cbBufferA } } } - else if (!_tcsnicmp(line, _T("[color="), 7)) - { + else if (!_tcsnicmp(line, _T("[color="), 7)) { TCHAR* tag = _tcschr(line + 7, ']'); - if (tag) - { + if (tag) { line = tag; found = 1; } } - else if (!_tcsnicmp(line, _T("[/color]"), 8)) - { + else if (!_tcsnicmp(line, _T("[/color]"), 8)) { line += 7; found = 1; } } - if (!found) - { - if (*line < 128) *d++ = (char) *line; + if (!found) { + if (*line < 128) *d++ = (char)*line; else d += sprintf(d, "\\u%d ?", *line); //!!!!!!!!!! } } - else if (*line < 128) *d++ = (char) *line; + else if (*line < 128) *d++ = (char)*line; else d += sprintf(d, "\\u%d ?", *line); //!!!!!!!!!! } *(d++) = '}'; *d = 0; - *cbBufferEnd = (int) (d - *buffer); + *cbBufferEnd = (int)(d - *buffer); return textCharsCount; } @@ -197,7 +180,7 @@ static char *CreateRTFHeader(SrmmWindowData *dat) ReleaseDC(NULL, hdc); bufferEnd = 0; bufferAlloced = 1024; - buffer = (char *) mir_alloc(bufferAlloced); + buffer = (char *)mir_alloc(bufferAlloced); buffer[0] = '\0'; AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl"); @@ -226,7 +209,7 @@ static char *CreateRTFTail(SrmmWindowData *dat) bufferEnd = 0; bufferAlloced = 1024; - buffer = (char *) mir_alloc(bufferAlloced); + buffer = (char *)mir_alloc(bufferAlloced); buffer[0] = '\0'; AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "}"); return buffer; @@ -245,19 +228,19 @@ static char *SetToStyle(int style) int DbEventIsForMsgWindow(DBEVENTINFO *dbei) { - DBEVENTTYPEDESCR *et = ( DBEVENTTYPEDESCR* )CallService(MS_DB_EVENT_GETTYPE, ( WPARAM )dbei->szModule, ( LPARAM )dbei->eventType ); + DBEVENTTYPEDESCR *et = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType); return et && (et->flags & DETF_MSGWINDOW); } int DbEventIsShown(DBEVENTINFO * dbei, SrmmWindowData *dat) { switch (dbei->eventType) { - case EVENTTYPE_MESSAGE: - return 1; - case EVENTTYPE_JABBER_CHATSTATES: - case EVENTTYPE_JABBER_PRESENCE: - case EVENTTYPE_FILE: - return (dbei->flags & DBEF_READ) == 0; + case EVENTTYPE_MESSAGE: + return 1; + case EVENTTYPE_JABBER_CHATSTATES: + case EVENTTYPE_JABBER_PRESENCE: + case EVENTTYPE_FILE: + return (dbei->flags & DBEF_READ) == 0; } return DbEventIsForMsgWindow(dbei); } @@ -274,7 +257,7 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE if (dbei.cbBlob == -1) return NULL; - dbei.pBlob = (PBYTE) mir_alloc(dbei.cbBlob); + dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); db_event_get(hDbEvent, &dbei); if (!DbEventIsShown(&dbei, dat)) { mir_free(dbei.pBlob); @@ -282,14 +265,14 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE } if (!(dbei.flags & DBEF_SENT) && (dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei))) { db_event_markRead(hContact, hDbEvent); - CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM) hDbEvent); + CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM)hDbEvent); } else if (dbei.eventType == EVENTTYPE_JABBER_CHATSTATES || dbei.eventType == EVENTTYPE_JABBER_PRESENCE) { db_event_markRead(hContact, hDbEvent); } bufferEnd = 0; bufferAlloced = 1024; - buffer = (char *) mir_alloc(bufferAlloced); + buffer = (char *)mir_alloc(bufferAlloced); buffer[0] = '\0'; if (!dat->bIsAutoRTL && !streamData->isEmpty) @@ -304,7 +287,7 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE streamData->isEmpty = 0; if (dat->bIsAutoRTL) { - if(dbei.flags & DBEF_RTL) + if (dbei.flags & DBEF_RTL) AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrch\\rtlch"); else AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlch\\ltrch"); @@ -331,7 +314,7 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\f0\\fs14"); while (bufferAlloced - bufferEnd < logIconBmpSize[i]) bufferAlloced += 1024; - buffer = (char *) mir_realloc(buffer, bufferAlloced); + buffer = (char *)mir_realloc(buffer, bufferAlloced); CopyMemory(buffer + bufferEnd, pLogIconBmpBits[i], logIconBmpSize[i]); bufferEnd += logIconBmpSize[i]; } @@ -354,13 +337,13 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE if (!(g_dat.flags & SMF_HIDENAMES) && dbei.eventType != EVENTTYPE_JABBER_CHATSTATES && dbei.eventType != EVENTTYPE_JABBER_PRESENCE) { TCHAR* szName; - CONTACTINFO ci = {0}; + CONTACTINFO ci = { 0 }; if (dbei.flags & DBEF_SENT) { ci.cbSize = sizeof(ci); ci.szProto = dbei.szModule; ci.dwFlag = CNF_DISPLAY | CNF_TCHAR; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) { + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) { // CNF_DISPLAY always returns a string type szName = ci.pszVal; } @@ -378,71 +361,67 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s :", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON)); switch (dbei.eventType) { - default: - case EVENTTYPE_MESSAGE: - { - TCHAR* msg = DbGetEventTextT( &dbei, CP_ACP ); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYMSG : MSGFONTID_YOURMSG)); - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, msg); + TCHAR *msg, *szName; + default: + case EVENTTYPE_MESSAGE: + msg = DbGetEventTextT(&dbei, CP_ACP); + AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYMSG : MSGFONTID_YOURMSG)); + AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, msg); + mir_free(msg); + break; + + case EVENTTYPE_JABBER_CHATSTATES: + case EVENTTYPE_JABBER_PRESENCE: + if (dbei.flags & DBEF_SENT) { + CONTACTINFO ci = { sizeof(ci) }; + ci.hContact = NULL; + ci.szProto = dbei.szModule; + ci.dwFlag = CNF_DISPLAY | CNF_TCHAR; - mir_free(msg); - break; + // CNF_DISPLAY always returns a string type + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) + szName = NEWTSTR_ALLOCA(ci.pszVal); + else + szName = _T(""); + + mir_free(ci.pszVal); } - case EVENTTYPE_JABBER_CHATSTATES: - case EVENTTYPE_JABBER_PRESENCE: - { - TCHAR *msg, *szName; - CONTACTINFO ci = {0}; - - if (dbei.flags & DBEF_SENT) { - ci.cbSize = sizeof(ci); - ci.hContact = NULL; - ci.szProto = dbei.szModule; - ci.dwFlag = CNF_DISPLAY | CNF_TCHAR; - - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) { - // CNF_DISPLAY always returns a string type - szName = ci.pszVal; - } - } - else szName = pcli->pfnGetContactDisplayName(hContact, 0); + else szName = pcli->pfnGetContactDisplayName(hContact, 0); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(MSGFONTID_NOTICE)); - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, szName); - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, _T(" ")); + AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(MSGFONTID_NOTICE)); + AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, szName); + AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, _T(" ")); - msg = DbGetEventTextT( &dbei, CP_ACP ); - if ( msg ) { - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, msg); - mir_free( msg ); - } - mir_free(ci.pszVal); - break; + msg = DbGetEventTextT(&dbei, CP_ACP); + if (msg) { + AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, msg); + mir_free(msg); } - case EVENTTYPE_FILE: - { - char* filename = (char*)dbei.pBlob + sizeof(DWORD); - char* descr = filename + strlen( filename ) + 1; - TCHAR* ptszFileName = DbGetEventStringT( &dbei, filename ); - - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(MSGFONTID_NOTICE)); - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, - (dbei.flags & DBEF_SENT) ? TranslateT("File sent") : TranslateT("File received")); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, ": "); - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, ptszFileName); - mir_free( ptszFileName ); - - if ( *descr != 0 ) { - TCHAR* ptszDescr = DbGetEventStringT( &dbei, descr ); - AppendToBuffer( &buffer, &bufferEnd, &bufferAlloced, " (" ); - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, ptszDescr); - AppendToBuffer( &buffer, &bufferEnd, &bufferAlloced, ")" ); - mir_free( ptszDescr ); - } - break; - } } + break; + + case EVENTTYPE_FILE: + char* filename = (char*)dbei.pBlob + sizeof(DWORD); + char* descr = filename + strlen(filename) + 1; + TCHAR* ptszFileName = DbGetEventStringT(&dbei, filename); + + AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(MSGFONTID_NOTICE)); + AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, + (dbei.flags & DBEF_SENT) ? TranslateT("File sent") : TranslateT("File received")); + AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, ": "); + AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, ptszFileName); + mir_free(ptszFileName); + + if (*descr != 0) { + TCHAR* ptszDescr = DbGetEventStringT(&dbei, descr); + AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " ("); + AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, ptszDescr); + AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, ")"); + mir_free(ptszDescr); + } + break; + } - if(dat->bIsAutoRTL) + if (dat->bIsAutoRTL) AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\par"); mir_free(dbei.pBlob); @@ -453,51 +432,46 @@ static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG { struct LogStreamData *dat = (struct LogStreamData *) dwCookie; - if (dat->buffer == NULL) - { + if (dat->buffer == NULL) { dat->bufferOffset = 0; - switch (dat->stage) - { - case STREAMSTAGE_HEADER: - dat->buffer = CreateRTFHeader(dat->dlgDat); - dat->stage = STREAMSTAGE_EVENTS; - break; - - case STREAMSTAGE_EVENTS: - if (dat->eventsToInsert) - { - do - { - dat->buffer = CreateRTFFromDbEvent(dat->dlgDat, dat->hContact, dat->hDbEvent, dat); - if (dat->buffer) - dat->hDbEventLast = dat->hDbEvent; - dat->hDbEvent = db_event_next(dat->hContact, dat->hDbEvent); - if (--dat->eventsToInsert == 0) - break; - } while (dat->buffer == NULL && dat->hDbEvent); + switch (dat->stage) { + case STREAMSTAGE_HEADER: + dat->buffer = CreateRTFHeader(dat->dlgDat); + dat->stage = STREAMSTAGE_EVENTS; + break; + + case STREAMSTAGE_EVENTS: + if (dat->eventsToInsert) { + do { + dat->buffer = CreateRTFFromDbEvent(dat->dlgDat, dat->hContact, dat->hDbEvent, dat); if (dat->buffer) - { - dat->isEmpty = 0; + dat->hDbEventLast = dat->hDbEvent; + dat->hDbEvent = db_event_next(dat->hContact, dat->hDbEvent); + if (--dat->eventsToInsert == 0) break; - } } - dat->stage = STREAMSTAGE_TAIL; - //fall through - case STREAMSTAGE_TAIL: - dat->buffer = CreateRTFTail(dat->dlgDat); - dat->stage = STREAMSTAGE_STOP; - break; - case STREAMSTAGE_STOP: - *pcb = 0; - return 0; + while (dat->buffer == NULL && dat->hDbEvent); + if (dat->buffer) { + dat->isEmpty = 0; + break; + } + } + dat->stage = STREAMSTAGE_TAIL; + //fall through + case STREAMSTAGE_TAIL: + dat->buffer = CreateRTFTail(dat->dlgDat); + dat->stage = STREAMSTAGE_STOP; + break; + case STREAMSTAGE_STOP: + *pcb = 0; + return 0; } dat->bufferLen = (int)strlen(dat->buffer); } *pcb = min(cb, dat->bufferLen - dat->bufferOffset); CopyMemory(pbBuff, dat->buffer + dat->bufferOffset, *pcb); dat->bufferOffset += *pcb; - if (dat->bufferOffset == dat->bufferLen) - { + if (dat->bufferOffset == dat->bufferLen) { mir_free(dat->buffer); dat->buffer = NULL; } @@ -506,8 +480,8 @@ static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG void StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAppend) { - EDITSTREAM stream = {0}; - struct LogStreamData streamData = {0}; + EDITSTREAM stream = { 0 }; + struct LogStreamData streamData = { 0 }; SrmmWindowData *dat = (SrmmWindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); CHARRANGE oldSel, sel; POINT scrollPos; @@ -516,7 +490,7 @@ void StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAppend) HWND hwndLog = GetDlgItem(hwndDlg, IDC_LOG); SendMessage(hwndLog, WM_SETREDRAW, FALSE, 0); - SendMessage(hwndLog, EM_EXGETSEL, 0, (LPARAM) & oldSel); + SendMessage(hwndLog, EM_EXGETSEL, 0, (LPARAM)& oldSel); streamData.hContact = dat->hContact; streamData.hDbEvent = hDbEventFirst; streamData.dlgDat = dat; @@ -525,44 +499,38 @@ void StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAppend) stream.pfnCallback = LogStreamInEvents; stream.dwCookie = (DWORD_PTR)&streamData; - if (!streamData.isEmpty) - { + if (!streamData.isEmpty) { bottomScroll = (GetFocus() != hwndLog); - if (bottomScroll && (GetWindowLongPtr(hwndLog, GWL_STYLE) & WS_VSCROLL)) - { - SCROLLINFO si = {0}; + if (bottomScroll && (GetWindowLongPtr(hwndLog, GWL_STYLE) & WS_VSCROLL)) { + SCROLLINFO si = { 0 }; si.cbSize = sizeof(si); si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; GetScrollInfo(hwndLog, SB_VERT, &si); bottomScroll = (si.nPos + (int)si.nPage) >= si.nMax; } if (!bottomScroll) - SendMessage(hwndLog, EM_GETSCROLLPOS, 0, (LPARAM) & scrollPos); + SendMessage(hwndLog, EM_GETSCROLLPOS, 0, (LPARAM)& scrollPos); } - if (fAppend) - { + if (fAppend) { sel.cpMin = sel.cpMax = -1; - SendMessage(hwndLog, EM_EXSETSEL, 0, (LPARAM) & sel); + SendMessage(hwndLog, EM_EXSETSEL, 0, (LPARAM)& sel); } strcpy(szSep2, fAppend ? "\\par\\sl0" : "\\sl1000"); strcpy(szSep2_RTL, fAppend ? "\\rtlpar\\rtlmark\\par\\sl1000" : "\\sl1000"); - SendMessage(hwndLog, EM_STREAMIN, fAppend ? SFF_SELECTION | SF_RTF : SF_RTF, (LPARAM) & stream); - if (bottomScroll) - { + SendMessage(hwndLog, EM_STREAMIN, fAppend ? SFF_SELECTION | SF_RTF : SF_RTF, (LPARAM)& stream); + if (bottomScroll) { sel.cpMin = sel.cpMax = -1; - SendMessage(hwndLog, EM_EXSETSEL, 0, (LPARAM) & sel); - if (GetWindowLongPtr(hwndLog, GWL_STYLE) & WS_VSCROLL) - { + SendMessage(hwndLog, EM_EXSETSEL, 0, (LPARAM)& sel); + if (GetWindowLongPtr(hwndLog, GWL_STYLE) & WS_VSCROLL) { SendMessage(hwndDlg, DM_SCROLLLOGTOBOTTOM, 0, 0); PostMessage(hwndDlg, DM_SCROLLLOGTOBOTTOM, 0, 0); } } - else - { - SendMessage(hwndLog, EM_EXSETSEL, 0, (LPARAM) & oldSel); - SendMessage(hwndLog, EM_SETSCROLLPOS, 0, (LPARAM) & scrollPos); + else { + SendMessage(hwndLog, EM_EXSETSEL, 0, (LPARAM)& oldSel); + SendMessage(hwndLog, EM_SETSCROLLPOS, 0, (LPARAM)& scrollPos); } SendMessage(hwndLog, WM_SETREDRAW, TRUE, 0); @@ -575,52 +543,45 @@ void StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAppend) #define RTFPICTHEADERMAXSIZE 78 void LoadMsgLogIcons(void) { - HICON hIcon; - HBITMAP hBmp, hoBmp; - HDC hdc, hdcMem; - BITMAPINFOHEADER bih = { 0 }; - int widthBytes, i; - RECT rc; - HBRUSH hBkgBrush; - int rtfHeaderSize; - PBYTE pBmpBits; + HBRUSH hBkgBrush = CreateSolidBrush(db_get_dw(NULL, SRMMMOD, SRMSGSET_BKGCOLOUR, SRMSGDEFSET_BKGCOLOUR)); - hBkgBrush = CreateSolidBrush(db_get_dw(NULL, SRMMMOD, SRMSGSET_BKGCOLOUR, SRMSGDEFSET_BKGCOLOUR)); - bih.biSize = sizeof(bih); + BITMAPINFOHEADER bih = { sizeof(bih) }; bih.biBitCount = 24; bih.biCompression = BI_RGB; bih.biHeight = 10; bih.biPlanes = 1; bih.biWidth = 10; - widthBytes = ((bih.biWidth * bih.biBitCount + 31) >> 5) * 4; + int widthBytes = ((bih.biWidth * bih.biBitCount + 31) >> 5) * 4; + + RECT rc; rc.top = rc.left = 0; rc.right = bih.biWidth; rc.bottom = bih.biHeight; - hdc = GetDC(NULL); - hBmp = CreateCompatibleBitmap(hdc, bih.biWidth, bih.biHeight); - hdcMem = CreateCompatibleDC(hdc); - pBmpBits = (PBYTE) mir_alloc(widthBytes * bih.biHeight); - for (i = 0; i < SIZEOF(pLogIconBmpBits); i++) { - hIcon = Skin_GetIconByHandle(iconList[i].hIcolib); + HDC hdc = GetDC(NULL); + HBITMAP hBmp = CreateCompatibleBitmap(hdc, bih.biWidth, bih.biHeight); + HDC hdcMem = CreateCompatibleDC(hdc); + PBYTE pBmpBits = (PBYTE)mir_alloc(widthBytes * bih.biHeight); + + for (int i = 0; i < SIZEOF(pLogIconBmpBits); i++) { + HICON hIcon = Skin_GetIconByHandle(iconList[i].hIcolib); size_t size = RTFPICTHEADERMAXSIZE + (bih.biSize + widthBytes * bih.biHeight) * 2; - pLogIconBmpBits[i] = (PBYTE) mir_alloc(size); + pLogIconBmpBits[i] = (PBYTE)mir_alloc(size); //I can't seem to get binary mode working. No matter. - rtfHeaderSize = mir_snprintf((char*)pLogIconBmpBits[i], size, "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, bih.biWidth, bih.biHeight); - hoBmp = (HBITMAP) SelectObject(hdcMem, hBmp); + int rtfHeaderSize = mir_snprintf((char*)pLogIconBmpBits[i], size, "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, bih.biWidth, bih.biHeight); + HBITMAP hoBmp = (HBITMAP)SelectObject(hdcMem, hBmp); FillRect(hdcMem, &rc, hBkgBrush); DrawIconEx(hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, NULL, DI_NORMAL); Skin_ReleaseIcon(hIcon); SelectObject(hdcMem, hoBmp); - GetDIBits(hdc, hBmp, 0, bih.biHeight, pBmpBits, (BITMAPINFO *) & bih, DIB_RGB_COLORS); - { - int n; - for (n = 0; n < sizeof(BITMAPINFOHEADER); n++) - sprintf((char*)pLogIconBmpBits[i] + rtfHeaderSize + n * 2, "%02X", ((PBYTE) & bih)[n]); //!!!!!!!!!!!!! - for (n = 0; n < widthBytes * bih.biHeight; n += 4) - sprintf((char*)pLogIconBmpBits[i] + rtfHeaderSize + (bih.biSize + n) * 2, "%02X%02X%02X%02X", pBmpBits[n], pBmpBits[n + 1], pBmpBits[n + 2], pBmpBits[n + 3]); //!!!!!!!!!!!!! - } + GetDIBits(hdc, hBmp, 0, bih.biHeight, pBmpBits, (BITMAPINFO *)& bih, DIB_RGB_COLORS); + + for (int n = 0; n < sizeof(BITMAPINFOHEADER); n++) + sprintf((char*)pLogIconBmpBits[i] + rtfHeaderSize + n * 2, "%02X", ((PBYTE)& bih)[n]); //!!!!!!!!!!!!! + for (int n = 0; n < widthBytes * bih.biHeight; n += 4) + sprintf((char*)pLogIconBmpBits[i] + rtfHeaderSize + (bih.biSize + n) * 2, "%02X%02X%02X%02X", pBmpBits[n], pBmpBits[n + 1], pBmpBits[n + 2], pBmpBits[n + 3]); //!!!!!!!!!!!!! + logIconBmpSize[i] = rtfHeaderSize + (bih.biSize + widthBytes * bih.biHeight) * 2 + 1; pLogIconBmpBits[i][logIconBmpSize[i] - 1] = '}'; } diff --git a/src/core/stdmsg/src/msgoptions.cpp b/src/core/stdmsg/src/msgoptions.cpp index c57d10abfd..5d687b3705 100644 --- a/src/core/stdmsg/src/msgoptions.cpp +++ b/src/core/stdmsg/src/msgoptions.cpp @@ -64,7 +64,7 @@ bool LoadMsgDlgFont(int i, LOGFONT* lf, COLORREF * colour) } if (lf) { mir_snprintf(str, SIZEOF(str), "SRMFont%dSize", i); - lf->lfHeight = (char) db_get_b(NULL, SRMMMOD, str, fontOptionsList[i].defSize); + lf->lfHeight = (char)db_get_b(NULL, SRMMMOD, str, fontOptionsList[i].defSize); lf->lfWidth = 0; lf->lfEscapement = 0; lf->lfOrientation = 0; @@ -81,7 +81,7 @@ bool LoadMsgDlgFont(int i, LOGFONT* lf, COLORREF * colour) mir_snprintf(str, SIZEOF(str), "SRMFont%d", i); DBVARIANT dbv; - if ( db_get_ts(NULL, SRMMMOD, str, &dbv)) + if (db_get_ts(NULL, SRMMMOD, str, &dbv)) _tcscpy(lf->lfFaceName, fontOptionsList[i].szDefFace); else { lstrcpyn(lf->lfFaceName, dbv.ptszVal, SIZEOF(lf->lfFaceName)); @@ -93,13 +93,13 @@ bool LoadMsgDlgFont(int i, LOGFONT* lf, COLORREF * colour) return true; } -void RegisterSRMMFonts( void ) +void RegisterSRMMFonts(void) { char idstr[10]; FontIDT fontid = { sizeof(fontid) }; fontid.flags = FIDF_ALLOWREREGISTER | FIDF_DEFAULTVALID; - for (int i=0; i < SIZEOF(fontOptionsList); i++) { + for (int i = 0; i < SIZEOF(fontOptionsList); i++) { strcpy(fontid.dbSettingsGroup, SRMMMOD); _tcscpy(fontid.group, LPGENT("Message log")); _tcscpy(fontid.name, fontOptionsList[i].szDescr); @@ -131,21 +131,21 @@ void RegisterSRMMFonts( void ) struct CheckBoxValues_t { - DWORD style; - TCHAR* szDescr; + DWORD style; + TCHAR* szDescr; } static const statusValues[] = { - { MODEF_OFFLINE, LPGENT("Offline") }, - { PF2_ONLINE, LPGENT("Online") }, - { PF2_SHORTAWAY, LPGENT("Away") }, - { PF2_LONGAWAY, LPGENT("NA") }, - { PF2_LIGHTDND, LPGENT("Occupied") }, - { PF2_HEAVYDND, LPGENT("DND") }, - { PF2_FREECHAT, LPGENT("Free for chat") }, - { PF2_INVISIBLE, LPGENT("Invisible") }, - { PF2_OUTTOLUNCH, LPGENT("Out to lunch") }, - { PF2_ONTHEPHONE, LPGENT("On the phone") } + { MODEF_OFFLINE, LPGENT("Offline") }, + { PF2_ONLINE, LPGENT("Online") }, + { PF2_SHORTAWAY, LPGENT("Away") }, + { PF2_LONGAWAY, LPGENT("NA") }, + { PF2_LIGHTDND, LPGENT("Occupied") }, + { PF2_HEAVYDND, LPGENT("DND") }, + { PF2_FREECHAT, LPGENT("Free for chat") }, + { PF2_INVISIBLE, LPGENT("Invisible") }, + { PF2_OUTTOLUNCH, LPGENT("Out to lunch") }, + { PF2_ONTHEPHONE, LPGENT("On the phone") } }; static void FillCheckBoxTree(HWND hwndTree, const struct CheckBoxValues_t *values, int nValues, DWORD style) @@ -159,23 +159,24 @@ static void FillCheckBoxTree(HWND hwndTree, const struct CheckBoxValues_t *value tvis.item.pszText = TranslateTS(values[i].szDescr); tvis.item.stateMask = TVIS_STATEIMAGEMASK; tvis.item.state = INDEXTOSTATEIMAGEMASK((style & tvis.item.lParam) != 0 ? 2 : 1); - TreeView_InsertItem( hwndTree, &tvis ); -} } + TreeView_InsertItem(hwndTree, &tvis); + } +} static DWORD MakeCheckBoxTreeFlags(HWND hwndTree) { - DWORD flags = 0; - TVITEM tvi; - - tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_STATE; - tvi.hItem = TreeView_GetRoot(hwndTree); - while (tvi.hItem) { - TreeView_GetItem(hwndTree, &tvi); - if (((tvi.state & TVIS_STATEIMAGEMASK) >> 12 == 2)) - flags |= tvi.lParam; - tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem); - } - return flags; + DWORD flags = 0; + TVITEM tvi; + + tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_STATE; + tvi.hItem = TreeView_GetRoot(hwndTree); + while (tvi.hItem) { + TreeView_GetItem(hwndTree, &tvi); + if (((tvi.state & TVIS_STATEIMAGEMASK) >> 12 == 2)) + flags |= tvi.lParam; + tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem); + } + return flags; } static INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) @@ -265,15 +266,15 @@ static INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LP hti.pt.y = (short)HIWORD(GetMessagePos()); ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt); if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) - if (hti.flags & TVHT_ONITEMSTATEICON) { - TVITEM tvi; - tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE; - tvi.hItem = hti.hItem; - TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi); - tvi.iImage = tvi.iSelectedImage = tvi.iImage == 1 ? 2 : 1; - TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } + if (hti.flags & TVHT_ONITEMSTATEICON) { + TVITEM tvi; + tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + tvi.hItem = hti.hItem; + TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi); + tvi.iImage = tvi.iSelectedImage = tvi.iImage == 1 ? 2 : 1; + TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } } break; case 0: @@ -418,13 +419,13 @@ static INT_PTR CALLBACK DlgProcLogOptions(HWND hwndDlg, UINT msg, WPARAM wParam, static void ResetCList(HWND hwndDlg) { if (CallService(MS_CLUI_GETCAPS, 0, 0) & CLUIF_DISABLEGROUPS && !db_get_b(NULL, "CList", "UseGroups", SETTING_USEGROUPS_DEFAULT)) - SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETUSEGROUPS, (WPARAM) FALSE, 0); + SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETUSEGROUPS, (WPARAM)FALSE, 0); else - SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETUSEGROUPS, (WPARAM) TRUE, 0); + SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETUSEGROUPS, (WPARAM)TRUE, 0); SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETHIDEEMPTYGROUPS, 1, 0); SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETGREYOUTFLAGS, 0, 0); SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETLEFTMARGIN, 2, 0); - SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETBKBITMAP, 0, (LPARAM) (HBITMAP) NULL); + SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETBKBITMAP, 0, (LPARAM)(HBITMAP)NULL); SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETBKCOLOR, GetSysColor(COLOR_WINDOW), 0); SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETINDENT, 10, 0); for (int i = 0; i <= FONTID_MAX; i++) @@ -435,30 +436,30 @@ static void RebuildList(HWND hwndDlg, HANDLE hItemNew, HANDLE hItemUnknown) { BYTE defType = db_get_b(NULL, SRMMMOD, SRMSGSET_TYPINGNEW, SRMSGDEFSET_TYPINGNEW); if (hItemNew && defType) - SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM) hItemNew, 1); + SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItemNew, 1); if (hItemUnknown && db_get_b(NULL, SRMMMOD, SRMSGSET_TYPINGUNKNOWN, SRMSGDEFSET_TYPINGUNKNOWN)) - SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM) hItemUnknown, 1); + SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItemUnknown, 1); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem && db_get_b(hContact, SRMMMOD, SRMSGSET_TYPING, defType)) - SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM) hItem, 1); + SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETCHECKMARK, (WPARAM)hItem, 1); } } static void SaveList(HWND hwndDlg, HANDLE hItemNew, HANDLE hItemUnknown) { if (hItemNew) - db_set_b(NULL, SRMMMOD, SRMSGSET_TYPINGNEW, (BYTE) (SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM) hItemNew, 0) ? 1 : 0)); + db_set_b(NULL, SRMMMOD, SRMSGSET_TYPINGNEW, (BYTE)(SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItemNew, 0) ? 1 : 0)); if (hItemUnknown) - db_set_b(NULL, SRMMMOD, SRMSGSET_TYPINGUNKNOWN, (BYTE) (SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM) hItemUnknown, 0) ? 1 : 0)); + db_set_b(NULL, SRMMMOD, SRMSGSET_TYPINGUNKNOWN, (BYTE)(SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItemUnknown, 0) ? 1 : 0)); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); if (hItem) - db_set_b(hContact, SRMMMOD, SRMSGSET_TYPING, (BYTE) (SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM) hItem, 0) ? 1 : 0)); + db_set_b(hContact, SRMMMOD, SRMSGSET_TYPING, (BYTE)(SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETCHECKMARK, (WPARAM)hItem, 0) ? 1 : 0)); } } @@ -473,9 +474,9 @@ static INT_PTR CALLBACK DlgProcTypeOptions(HWND hwndDlg, UINT msg, WPARAM wParam CLCINFOITEM cii = { sizeof(cii) }; cii.flags = CLCIIF_GROUPFONT | CLCIIF_CHECKBOX; cii.pszText = TranslateT("** New contacts **"); - hItemNew = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_ADDINFOITEM, 0, (LPARAM) & cii); + hItemNew = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_ADDINFOITEM, 0, (LPARAM)& cii); cii.pszText = TranslateT("** Unknown contacts **"); - hItemUnknown = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_ADDINFOITEM, 0, (LPARAM) & cii); + hItemUnknown = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_ADDINFOITEM, 0, (LPARAM)& cii); } SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE) | (CLS_SHOWHIDDEN) | (CLS_NOHIDEOFFLINE)); ResetCList(hwndDlg); @@ -519,7 +520,7 @@ static INT_PTR CALLBACK DlgProcTypeOptions(HWND hwndDlg, UINT msg, WPARAM wParam EnableWindow(GetDlgItem(hwndDlg, IDC_TYPETRAY), IsDlgButtonChecked(hwndDlg, IDC_SHOWNOTIFY)); EnableWindow(GetDlgItem(hwndDlg, IDC_NOTIFYTRAY), IsDlgButtonChecked(hwndDlg, IDC_SHOWNOTIFY)); EnableWindow(GetDlgItem(hwndDlg, IDC_NOTIFYBALLOON), IsDlgButtonChecked(hwndDlg, IDC_SHOWNOTIFY) - && ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)); + && ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)); //fall-thru case IDC_TYPEWIN: case IDC_NOTIFYTRAY: @@ -530,9 +531,9 @@ static INT_PTR CALLBACK DlgProcTypeOptions(HWND hwndDlg, UINT msg, WPARAM wParam break; case WM_NOTIFY: - switch (((NMHDR *) lParam)->idFrom) { + switch (((NMHDR *)lParam)->idFrom) { case IDC_CLIST: - switch (((NMHDR *) lParam)->code) { + switch (((NMHDR *)lParam)->code) { case CLN_OPTIONSCHANGED: ResetCList(hwndDlg); break; @@ -542,17 +543,16 @@ static INT_PTR CALLBACK DlgProcTypeOptions(HWND hwndDlg, UINT msg, WPARAM wParam } break; case 0: - switch (((LPNMHDR) lParam)->code) { + switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: SaveList(hwndDlg, hItemNew, hItemUnknown); - db_set_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPING, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_SHOWNOTIFY)); - db_set_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPINGWIN, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_TYPEWIN)); - db_set_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPINGNOWIN, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_TYPETRAY)); - db_set_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPINGCLIST, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_NOTIFYTRAY)); + db_set_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPING, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SHOWNOTIFY)); + db_set_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPINGWIN, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_TYPEWIN)); + db_set_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPINGNOWIN, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_TYPETRAY)); + db_set_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPINGCLIST, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_NOTIFYTRAY)); ReloadGlobals(); WindowList_Broadcast(g_dat.hMessageWindowList, DM_OPTIONSAPPLIED, 0, 0); } - break; } break; } @@ -592,7 +592,7 @@ static int ModernOptInitialise(WPARAM wParam, LPARAM lParam) }; MODERNOPTOBJECT obj = { sizeof(obj) }; - obj.dwFlags = MODEROPT_FLG_TCHAR|MODEROPT_FLG_NORESIZE; + obj.dwFlags = MODEROPT_FLG_TCHAR | MODEROPT_FLG_NORESIZE; obj.hIcon = LoadSkinnedIcon(SKINICON_EVENT_MESSAGE); obj.hInstance = g_hInst; obj.iSection = MODERNOPT_PAGE_MSGS; diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index f240323924..0aa012ecf5 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -145,7 +145,7 @@ static INT_PTR SendMessageCommand(WPARAM wParam, LPARAM lParam) static INT_PTR ReadMessageCommand(WPARAM wParam, LPARAM lParam) { - CLISTEVENT *cle = (CLISTEVENT *) lParam; + CLISTEVENT *cle = (CLISTEVENT *)lParam; if (cle) SendMessageCmd(cle->hContact, NULL, 0); @@ -173,14 +173,14 @@ static int TypingMessage(WPARAM hContact, LPARAM lParam) tn.dwInfoFlags = NIIF_INFO; tn.dwInfoFlags |= NIIF_INTERN_UNICODE; tn.uTimeout = 1000 * 4; - CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM) & tn); + CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)& tn); } else { CLISTEVENT cle = { sizeof(cle) }; cle.hContact = hContact; cle.hDbEvent = (HANDLE)1; cle.flags = CLEF_ONLYAFEW | CLEF_TCHAR; - cle.hIcon = LoadSkinnedIcon( SKINICON_OTHER_TYPING ); + cle.hIcon = LoadSkinnedIcon(SKINICON_OTHER_TYPING); cle.pszService = "SRMsg/ReadMessage"; cle.ptszTooltip = szTip; CallServiceSync(MS_CLIST_REMOVEEVENT, hContact, 1); @@ -198,14 +198,14 @@ static int MessageSettingChanged(WPARAM hContact, LPARAM lParam) return 0; if (!strcmp(cws->szModule, "CList")) - WindowList_Broadcast(g_dat.hMessageWindowList, DM_UPDATETITLE, (WPARAM) cws, 0); + WindowList_Broadcast(g_dat.hMessageWindowList, DM_UPDATETITLE, (WPARAM)cws, 0); else if (hContact) { if (cws->szSetting && !strcmp(cws->szSetting, "Timezone")) - WindowList_Broadcast(g_dat.hMessageWindowList, DM_NEWTIMEZONE, (WPARAM) cws, 0); + WindowList_Broadcast(g_dat.hMessageWindowList, DM_NEWTIMEZONE, (WPARAM)cws, 0); else { char *szProto = GetContactProto(hContact); if (szProto && !strcmp(cws->szModule, szProto)) - WindowList_Broadcast(g_dat.hMessageWindowList, DM_UPDATETITLE, (WPARAM) cws, 0); + WindowList_Broadcast(g_dat.hMessageWindowList, DM_UPDATETITLE, (WPARAM)cws, 0); } } return 0; @@ -236,8 +236,8 @@ static void RestoreUnreadMessageAlerts(void) for (HANDLE hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { bool autoPopup = false; dbei.cbBlob = 0; - db_event_get( hDbEvent, &dbei); - if (!(dbei.flags & (DBEF_SENT | DBEF_READ)) && ( dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei))) { + db_event_get(hDbEvent, &dbei); + if (!(dbei.flags & (DBEF_SENT | DBEF_READ)) && (dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei))) { int windowAlreadyExists = WindowList_Find(g_dat.hMessageWindowList, hContact) != NULL; if (windowAlreadyExists) continue; @@ -247,25 +247,25 @@ static void RestoreUnreadMessageAlerts(void) autoPopup = true; if (autoPopup && !windowAlreadyExists) { - NewMessageWindowLParam newData = {0}; + NewMessageWindowLParam newData = { 0 }; newData.hContact = hContact; newData.noActivate = db_get_b(NULL, SRMMMOD, SRMSGSET_DONOTSTEALFOCUS, SRMSGDEFSET_DONOTSTEALFOCUS); - CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSG), NULL, DlgProcMessage, (LPARAM) & newData); + CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSG), NULL, DlgProcMessage, (LPARAM)& newData); } else { cle.hContact = hContact; cle.hDbEvent = hDbEvent; mir_sntprintf(toolTip, SIZEOF(toolTip), TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); - CallService(MS_CLIST_ADDEVENT, 0, (LPARAM) & cle); + CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)& cle); } } } } } -void RegisterSRMMFonts( void ); +void RegisterSRMMFonts(void); -static int FontsChanged(WPARAM wParam,LPARAM lParam) +static int FontsChanged(WPARAM wParam, LPARAM lParam) { WindowList_Broadcast(g_dat.hMessageWindowList, DM_OPTIONSAPPLIED, 0, 0); return 0; @@ -279,7 +279,7 @@ static int SplitmsgModulesLoaded(WPARAM, LPARAM) CLISTMENUITEM mi = { sizeof(mi) }; mi.position = -2000090000; mi.flags = CMIF_DEFAULT; - mi.icolibItem = LoadSkinnedIconHandle( SKINICON_EVENT_MESSAGE ); + mi.icolibItem = LoadSkinnedIconHandle(SKINICON_EVENT_MESSAGE); mi.pszName = LPGEN("&Message"); mi.pszService = MS_MSG_SENDMESSAGE; hMsgMenuItem = Menu_AddContactMenuItem(&mi); @@ -315,8 +315,8 @@ static int PrebuildContactMenu(WPARAM hContact, LPARAM lParam) char *szProto = GetContactProto(hContact); if (szProto) { // leave this menu item hidden for chats - if ( !db_get_b( hContact, szProto, "ChatRoom", 0 )) - if ( CallProtoService( szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND ) + if (!db_get_b(hContact, szProto, "ChatRoom", 0)) + if (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND) bEnabled = true; } @@ -327,7 +327,7 @@ static int PrebuildContactMenu(WPARAM hContact, LPARAM lParam) static INT_PTR GetWindowAPI(WPARAM wParam, LPARAM lParam) { - return PLUGIN_MAKE_VERSION(0,0,0,4); + return PLUGIN_MAKE_VERSION(0, 0, 0, 4); } static INT_PTR GetWindowClass(WPARAM wParam, LPARAM lParam) @@ -360,7 +360,7 @@ static INT_PTR GetWindowData(WPARAM wParam, LPARAM lParam) if (mwid->cbSize != sizeof(MessageWindowInputData) || mwd->cbSize != sizeof(SrmmWindowData)) return 1; if (mwid->hContact == NULL) return 1; if (mwid->uFlags != MSG_WINDOW_UFLAG_MSG_BOTH) return 1; - + HWND hwnd = WindowList_Find(g_dat.hMessageWindowList, mwid->hContact); mwd->uFlags = MSG_WINDOW_UFLAG_MSG_BOTH; mwd->hwndWindow = hwnd; @@ -402,7 +402,7 @@ int LoadSendRecvMessageModule(void) CreateServiceFunction(MS_MSG_SETSTATUSTEXT, SetStatusText); CreateServiceFunction("SRMsg/ReadMessage", ReadMessageCommand); - hHookWinEvt = CreateHookableEvent(ME_MSG_WINDOWEVENT); + hHookWinEvt = CreateHookableEvent(ME_MSG_WINDOWEVENT); hHookWinPopup = CreateHookableEvent(ME_MSG_WINDOWPOPUP); hHookWinWrite = CreateHookableEvent(ME_MSG_PRECREATEEVENT); @@ -412,7 +412,7 @@ int LoadSendRecvMessageModule(void) SkinAddNewSoundEx("SendMsg", LPGEN("Instant messages"), LPGEN("Outgoing")); SkinAddNewSoundEx("SendError", LPGEN("Instant messages"), LPGEN("Message send error")); SkinAddNewSoundEx("TNStart", LPGEN("Instant messages"), LPGEN("Contact started typing")); - SkinAddNewSoundEx("TNStop", LPGEN("Instant messages"), LPGEN("Contact stopped typing")); + SkinAddNewSoundEx("TNStop", LPGEN("Instant messages"), LPGEN("Contact stopped typing")); hCurSplitNS = LoadCursor(NULL, IDC_SIZENS); hCurSplitWE = LoadCursor(NULL, IDC_SIZEWE); diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index 21357908ac..135afd3b3d 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -33,7 +33,7 @@ struct NewMessageWindowLParam int noActivate; }; -struct SrmmWindowData +struct SrmmWindowData : public MZeroedObject { SrmmWindowData() : cmdList(20) diff --git a/src/core/stdmsg/src/msgtimedout.cpp b/src/core/stdmsg/src/msgtimedout.cpp index b42875447f..ec298727b2 100644 --- a/src/core/stdmsg/src/msgtimedout.cpp +++ b/src/core/stdmsg/src/msgtimedout.cpp @@ -22,11 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h" #include "msgs.h" -typedef struct +struct ErrorDlgParam { const char *szMsg; TMsgQueue *item; -} ErrorDlgParam; +}; INT_PTR SendMessageCmd(MCONTACT hContact, char* msg, int isWchar); @@ -34,22 +34,19 @@ INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar { TMsgQueue *item = (TMsgQueue*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch (msg) - { + switch (msg) { case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); { RECT rc, rcParent; - ErrorDlgParam *param = (ErrorDlgParam *) lParam; + ErrorDlgParam *param = (ErrorDlgParam *)lParam; item = param->item; - TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)item); if (!param->szMsg || !param->szMsg[0]) SetDlgItemText(hwndDlg, IDC_ERRORTEXT, TranslateT("An unknown error has occurred.")); - else - { + else { TCHAR* ptszError = (TCHAR*)CallService(MS_LANGPACK_PCHARTOTCHAR, 0, (LPARAM)param->szMsg); SetDlgItemText(hwndDlg, IDC_ERRORTEXT, ptszError); mir_free(ptszError); @@ -100,5 +97,5 @@ void MessageFailureProcess(TMsgQueue *item, const char* err) SkinPlaySound("SendError"); ErrorDlgParam param = { err, item }; - CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSGSENDERROR), hwnd, ErrorDlgProc, (LPARAM) ¶m); + CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSGSENDERROR), hwnd, ErrorDlgProc, (LPARAM)¶m); } diff --git a/src/core/stdmsg/src/richutil.cpp b/src/core/stdmsg/src/richutil.cpp index b91097efa2..1b1925478c 100644 --- a/src/core/stdmsg/src/richutil.cpp +++ b/src/core/stdmsg/src/richutil.cpp @@ -68,20 +68,18 @@ void RichUtil_Unload(void) int RichUtil_SubClass(HWND hwndEdit) { - if (IsWindow(hwndEdit)) - { + if (IsWindow(hwndEdit)) { int idx; TRichUtil *ru = (TRichUtil*)mir_calloc(sizeof(TRichUtil)); ru->hwnd = hwndEdit; ru->hasUglyBorder = 0; - - EnterCriticalSection(&csRich); - if (!List_GetIndex(&sListInt, ru, &idx)) - List_Insert(&sListInt, ru, idx); - LeaveCriticalSection(&csRich); - + { + mir_cslock lck(csRich); + if (!List_GetIndex(&sListInt, ru, &idx)) + List_Insert(&sListInt, ru, idx); + } mir_subclassWindow(ru->hwnd, RichUtil_Proc); RichUtil_ClearUglyBorder(ru); return 1; @@ -92,102 +90,98 @@ int RichUtil_SubClass(HWND hwndEdit) static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { TRichUtil *ru; - - EnterCriticalSection(&csRich); - ru = (TRichUtil *)List_Find(&sListInt, (TRichUtil*)&hwnd); - LeaveCriticalSection(&csRich); + { + mir_cslock lck(csRich); + ru = (TRichUtil *)List_Find(&sListInt, (TRichUtil*)&hwnd); + } if (ru == NULL) return 0; - switch(msg) { + switch (msg) { case WM_CHAR: { HWND hwndMsg = GetDlgItem(GetParent(hwnd), IDC_MESSAGE); - if (hwndMsg != hwnd) - { + if (hwndMsg != hwnd) { SetFocus(hwndMsg); SendMessage(hwndMsg, WM_CHAR, wParam, lParam); } - break; } + break; case WM_THEMECHANGED: case WM_STYLECHANGED: - { - RichUtil_ClearUglyBorder(ru); - break; - } + RichUtil_ClearUglyBorder(ru); + break; case WM_NCPAINT: - { - LRESULT ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); - if (ru->hasUglyBorder && IsThemeActive()) - { - HANDLE hTheme = OpenThemeData(ru->hwnd, L"EDIT"); - if (hTheme) - { - RECT rcBorder; - RECT rcClient; - int nState; - HDC hdc = GetWindowDC(ru->hwnd); - LONG style = GetWindowLongPtr(hwnd, GWL_STYLE); - - GetWindowRect(hwnd, &rcBorder); - rcBorder.right -= rcBorder.left; rcBorder.bottom -= rcBorder.top; - rcBorder.left = rcBorder.top = 0; - CopyRect(&rcClient, &rcBorder); - rcClient.left += ru->rect.left; - rcClient.top += ru->rect.top; - rcClient.right -= ru->rect.right; - rcClient.bottom -= ru->rect.bottom; - ExcludeClipRect(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); - - if (IsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL)) - DrawThemeParentBackground(hwnd, hdc, &rcBorder); - - if (style & WS_DISABLED) - nState = ETS_DISABLED; - else if (style & ES_READONLY) - nState = ETS_READONLY; - else - nState = ETS_NORMAL; - - DrawThemeBackground(hTheme, hdc, EP_EDITTEXT, nState, &rcBorder, NULL); - CloseThemeData(hTheme); - ReleaseDC(hwnd, hdc); - return 0; - } + { + LRESULT ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); + if (ru->hasUglyBorder && IsThemeActive()) { + HANDLE hTheme = OpenThemeData(ru->hwnd, L"EDIT"); + if (hTheme) { + RECT rcBorder; + RECT rcClient; + int nState; + HDC hdc = GetWindowDC(ru->hwnd); + LONG style = GetWindowLongPtr(hwnd, GWL_STYLE); + + GetWindowRect(hwnd, &rcBorder); + rcBorder.right -= rcBorder.left; rcBorder.bottom -= rcBorder.top; + rcBorder.left = rcBorder.top = 0; + CopyRect(&rcClient, &rcBorder); + rcClient.left += ru->rect.left; + rcClient.top += ru->rect.top; + rcClient.right -= ru->rect.right; + rcClient.bottom -= ru->rect.bottom; + ExcludeClipRect(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); + + if (IsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL)) + DrawThemeParentBackground(hwnd, hdc, &rcBorder); + + if (style & WS_DISABLED) + nState = ETS_DISABLED; + else if (style & ES_READONLY) + nState = ETS_READONLY; + else + nState = ETS_NORMAL; + + DrawThemeBackground(hTheme, hdc, EP_EDITTEXT, nState, &rcBorder, NULL); + CloseThemeData(hTheme); + ReleaseDC(hwnd, hdc); + return 0; } - return ret; } + return ret; + } + case WM_NCCALCSIZE: - { - LRESULT ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); - NCCALCSIZE_PARAMS *ncsParam = (NCCALCSIZE_PARAMS*)lParam; - - if (ru->hasUglyBorder && IsThemeActive()) { - HANDLE hTheme = OpenThemeData(hwnd, L"EDIT"); - if (hTheme) { - RECT rcClient ={0}; - HDC hdc = GetDC(GetParent(hwnd)); - - if (GetThemeBackgroundContentRect(hTheme, hdc, EP_EDITTEXT, ETS_NORMAL, &ncsParam->rgrc[0], &rcClient) == S_OK) { - ru->rect.left = rcClient.left-ncsParam->rgrc[0].left; - ru->rect.top = rcClient.top-ncsParam->rgrc[0].top; - ru->rect.right = ncsParam->rgrc[0].right-rcClient.right; - ru->rect.bottom = ncsParam->rgrc[0].bottom-rcClient.bottom; - ncsParam->rgrc[0] = rcClient; - - CloseThemeData(hTheme); - ReleaseDC(GetParent(hwnd), hdc); - return WVR_REDRAW; - } - ReleaseDC(GetParent(hwnd), hdc); + { + LRESULT ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); + NCCALCSIZE_PARAMS *ncsParam = (NCCALCSIZE_PARAMS*)lParam; + + if (ru->hasUglyBorder && IsThemeActive()) { + HANDLE hTheme = OpenThemeData(hwnd, L"EDIT"); + if (hTheme) { + RECT rcClient = { 0 }; + HDC hdc = GetDC(GetParent(hwnd)); + + if (GetThemeBackgroundContentRect(hTheme, hdc, EP_EDITTEXT, ETS_NORMAL, &ncsParam->rgrc[0], &rcClient) == S_OK) { + ru->rect.left = rcClient.left - ncsParam->rgrc[0].left; + ru->rect.top = rcClient.top - ncsParam->rgrc[0].top; + ru->rect.right = ncsParam->rgrc[0].right - rcClient.right; + ru->rect.bottom = ncsParam->rgrc[0].bottom - rcClient.bottom; + ncsParam->rgrc[0] = rcClient; + CloseThemeData(hTheme); + ReleaseDC(GetParent(hwnd), hdc); + return WVR_REDRAW; } + ReleaseDC(GetParent(hwnd), hdc); + CloseThemeData(hTheme); } - return ret; } + return ret; + } case WM_ENABLE: RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOCHILDREN | RDW_UPDATENOW | RDW_FRAME); @@ -198,11 +192,10 @@ static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case WM_NCDESTROY: LRESULT ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); - - EnterCriticalSection(&csRich); - List_RemovePtr(&sListInt, ru); - LeaveCriticalSection(&csRich); - + { + mir_cslock lck(csRich); + List_RemovePtr(&sListInt, ru); + } mir_free(ru); return ret; } @@ -211,11 +204,11 @@ static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM static void RichUtil_ClearUglyBorder(TRichUtil *ru) { - if (IsThemeActive() && GetWindowLongPtr(ru->hwnd, GWL_EXSTYLE) & WS_EX_CLIENTEDGE) - { + if (IsThemeActive() && GetWindowLongPtr(ru->hwnd, GWL_EXSTYLE) & WS_EX_CLIENTEDGE) { ru->hasUglyBorder = 1; SetWindowLongPtr(ru->hwnd, GWL_EXSTYLE, GetWindowLongPtr(ru->hwnd, GWL_EXSTYLE) ^ WS_EX_CLIENTEDGE); } + // Redraw window since the style may have changed SetWindowPos(ru->hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); RedrawWindow(ru->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOCHILDREN | RDW_UPDATENOW | RDW_FRAME); diff --git a/src/core/stdmsg/src/statusicon.cpp b/src/core/stdmsg/src/statusicon.cpp index 6e5e530bc7..24b09d1a6d 100644 --- a/src/core/stdmsg/src/statusicon.cpp +++ b/src/core/stdmsg/src/statusicon.cpp @@ -90,7 +90,7 @@ int DeinitStatusIcons() int GetStatusIconsCount(MCONTACT hContact) { int nIcon = 0; - while ( Srmm_GetNthIcon(hContact, nIcon) != NULL) + while (Srmm_GetNthIcon(hContact, nIcon) != NULL) nIcon++; return nIcon; } -- cgit v1.2.3