From b3e8f72f17e9787aa5455977dc5eae05ddecb578 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 27 Mar 2017 14:15:17 +0300 Subject: common code moved to mir_app --- include/m_chat_int.h | 3 +++ libs/win32/mir_app.lib | Bin 117320 -> 117574 bytes libs/win64/mir_app.lib | Bin 112814 -> 113044 bytes plugins/Scriver/src/chat.h | 3 --- plugins/Scriver/src/chat_window.cpp | 43 +++++++++++--------------------- plugins/TabSRMM/src/chat.h | 3 --- plugins/TabSRMM/src/chat_log.cpp | 2 +- plugins/TabSRMM/src/chat_main.cpp | 4 +-- plugins/TabSRMM/src/chat_window.cpp | 22 +---------------- src/core/stdmsg/src/chat_window.cpp | 48 ++++++++++++++---------------------- src/core/stdmsg/src/stdafx.h | 2 -- src/mir_app/src/chat.h | 13 +++++----- src/mir_app/src/chat_opts.cpp | 4 +-- src/mir_app/src/chat_tools.cpp | 20 +++++++++++++++ src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + 16 files changed, 69 insertions(+), 100 deletions(-) diff --git a/include/m_chat_int.h b/include/m_chat_int.h index 8a16ccc3f1..48a2efdf40 100644 --- a/include/m_chat_int.h +++ b/include/m_chat_int.h @@ -394,6 +394,9 @@ EXTERN_C MIR_APP_DLL(BOOL) Chat_DoEventHook(SESSION_INFO *si, int iType, const U EXTERN_C MIR_APP_DLL(UINT) Chat_CreateGCMenu(HWND hwnd, HMENU hMenu, POINT pt, SESSION_INFO *si, const wchar_t *pszUID, const wchar_t *pszWordText); EXTERN_C MIR_APP_DLL(void) Chat_DestroyGCMenu(HMENU hMenu, int iIndex); +// calculates width or height of a string +EXTERN_C MIR_APP_DLL(int) Chat_GetTextPixelSize(const wchar_t *pszText, HFONT hFont, bool bWidth); + // message procedures' stubs EXTERN_C MIR_APP_DLL(LRESULT) CALLBACK stubLogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); EXTERN_C MIR_APP_DLL(LRESULT) CALLBACK stubMessageProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index 050dde2721..3f0764d855 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index f832860c08..af0c97dd46 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/plugins/Scriver/src/chat.h b/plugins/Scriver/src/chat.h index 54de98256a..8d40bbd6f2 100644 --- a/plugins/Scriver/src/chat.h +++ b/plugins/Scriver/src/chat.h @@ -70,9 +70,6 @@ extern GlobalLogSettings g_Settings; void LoadMsgLogBitmaps(void); void FreeMsgLogBitmaps(void); -// window.c -int GetTextPixelSize( wchar_t* pszText, HFONT hFont, BOOL bWidth); - // services.c void ShowRoom(SESSION_INFO *si); diff --git a/plugins/Scriver/src/chat_window.cpp b/plugins/Scriver/src/chat_window.cpp index 0c7398eb55..d431f6a89b 100644 --- a/plugins/Scriver/src/chat_window.cpp +++ b/plugins/Scriver/src/chat_window.cpp @@ -110,31 +110,6 @@ LBL_SkipEnd: } } -int GetTextPixelSize(wchar_t* pszText, HFONT hFont, BOOL bWidth) -{ - if (!pszText || !hFont) - return 0; - - HDC hdc = GetDC(nullptr); - HFONT hOldFont = (HFONT)SelectObject(hdc, hFont); - - RECT rc = { 0 }; - DrawText(hdc, pszText, -1, &rc, DT_CALCRECT); - SelectObject(hdc, hOldFont); - ReleaseDC(nullptr, hdc); - return bWidth ? rc.right - rc.left : rc.bottom - rc.top; -} - -static void __cdecl phase2(void *lParam) -{ - Thread_SetName("Scriver: phase2"); - - SESSION_INFO *si = (SESSION_INFO*)lParam; - Sleep(30); - if (si && si->pDlg) - si->pDlg->RedrawLog2(); -} - void CChatRoomDlg::FixTabIcons() { HICON hIcon; @@ -404,6 +379,16 @@ void CChatRoomDlg::onChange_Message(CCtrlEdit *pEdit) ///////////////////////////////////////////////////////////////////////////////////////// +static void __cdecl phase2(void *lParam) +{ + Thread_SetName("Scriver: phase2"); + + SESSION_INFO *si = (SESSION_INFO*)lParam; + Sleep(30); + if (si && si->pDlg) + si->pDlg->RedrawLog2(); +} + void CChatRoomDlg::RedrawLog() { m_si->LastTime = 0; @@ -517,8 +502,8 @@ void CChatRoomDlg::UpdateOptions() m_message.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); { // nicklist - int ih = GetTextPixelSize(L"AQG_glo'", g_Settings.UserListFont, FALSE); - int ih2 = GetTextPixelSize(L"AQG_glo'", g_Settings.UserListHeadingsFont, FALSE); + int ih = Chat_GetTextPixelSize(L"AQG_glo'", g_Settings.UserListFont, false); + int ih2 = Chat_GetTextPixelSize(L"AQG_glo'", g_Settings.UserListHeadingsFont, false); int height = db_get_b(0, CHAT_MODULE, "NicklistRowDist", 12); int font = ih > ih2 ? ih : ih2; // make sure we have space for icon! @@ -971,8 +956,8 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) if (mis->CtlType == ODT_MENU) return Menu_MeasureItem(lParam); - int ih = GetTextPixelSize(L"AQGgl'", g_Settings.UserListFont, FALSE); - int ih2 = GetTextPixelSize(L"AQGg'", g_Settings.UserListHeadingsFont, FALSE); + int ih = Chat_GetTextPixelSize(L"AQGgl'", g_Settings.UserListFont, false); + int ih2 = Chat_GetTextPixelSize(L"AQGg'", g_Settings.UserListHeadingsFont, false); int font = ih > ih2 ? ih : ih2; int height = db_get_b(0, CHAT_MODULE, "NicklistRowDist", 12); // make sure we have space for icon! diff --git a/plugins/TabSRMM/src/chat.h b/plugins/TabSRMM/src/chat.h index e9f7b1ce0c..a18054cc5e 100644 --- a/plugins/TabSRMM/src/chat.h +++ b/plugins/TabSRMM/src/chat.h @@ -101,9 +101,6 @@ extern TMUCSettings g_Settings; char* Log_CreateRtfHeader(MODULEINFO *mi); char* Log_CreateRTF(LOGSTREAMDATA *streamData); -// window.c -int GetTextPixelSize(wchar_t* pszText, HFONT hFont, bool bWidth); - // options.c enum { FONTSECTION_AUTO, FONTSECTION_IM, FONTSECTION_IP }; void LoadMsgDlgFont(int section, int i, LOGFONT *lf, COLORREF *colour, char *szModule); diff --git a/plugins/TabSRMM/src/chat_log.cpp b/plugins/TabSRMM/src/chat_log.cpp index 78831bd9ac..037d457fd7 100644 --- a/plugins/TabSRMM/src/chat_log.cpp +++ b/plugins/TabSRMM/src/chat_log.cpp @@ -674,7 +674,7 @@ char* Log_CreateRtfHeader(MODULEINFO *mi) szString[0] = 0x28; pci->LoadMsgDlgFont(17, &lf, nullptr); HFONT hFont = CreateFontIndirect(&lf); - int iText = GetTextPixelSize(szString, hFont, true) + 3; + int iText = Chat_GetTextPixelSize(szString, hFont, true) + 3; DeleteObject(hFont); iIndent += (iText * 1440) / pci->logPixelSX; str.AppendFormat("\\tx%u", iIndent); diff --git a/plugins/TabSRMM/src/chat_main.cpp b/plugins/TabSRMM/src/chat_main.cpp index 3961448ba6..d461209b05 100644 --- a/plugins/TabSRMM/src/chat_main.cpp +++ b/plugins/TabSRMM/src/chat_main.cpp @@ -129,8 +129,8 @@ static void OnLoadSettings() pci->LoadMsgDlgFont(5, &lf, nullptr); g_Settings.UserListFonts[CHAT_STATUS_OFFLINE] = CreateFontIndirect(&lf); - int ih = GetTextPixelSize(L"AQGglo", g_Settings.UserListFonts[CHAT_STATUS_NORMAL], false); - int ih2 = GetTextPixelSize(L"AQGglo", g_Settings.UserListFonts[CHAT_STATUS_AWAY], false); + int ih = Chat_GetTextPixelSize(L"AQGglo", g_Settings.UserListFonts[CHAT_STATUS_NORMAL], false); + int ih2 = Chat_GetTextPixelSize(L"AQGglo", g_Settings.UserListFonts[CHAT_STATUS_AWAY], false); g_Settings.iNickListFontHeight = max(M.GetByte(CHAT_MODULE, "NicklistRowDist", 12), (ih > ih2 ? ih : ih2)); for (int i = 0; i < 5; i++) { diff --git a/plugins/TabSRMM/src/chat_window.cpp b/plugins/TabSRMM/src/chat_window.cpp index 70e6fff18a..77574de5a7 100644 --- a/plugins/TabSRMM/src/chat_window.cpp +++ b/plugins/TabSRMM/src/chat_window.cpp @@ -455,26 +455,6 @@ LBL_SkipEnd: return false; } -///////////////////////////////////////////////////////////////////////////////////////// -// calculate the required rectangle for a string using the given font. This is more -// precise than using GetTextExtentPoint...() - -int GetTextPixelSize(wchar_t *pszText, HFONT hFont, bool bWidth) -{ - if (!pszText || !hFont) - return 0; - - HDC hdc = GetDC(nullptr); - HFONT hOldFont = (HFONT)SelectObject(hdc, hFont); - - RECT rc = { 0 }; - DrawText(hdc, pszText, -1, &rc, DT_CALCRECT); - - SelectObject(hdc, hOldFont); - ReleaseDC(nullptr, hdc); - return bWidth ? rc.right - rc.left : rc.bottom - rc.top; -} - static void __cdecl phase2(void * lParam) { Thread_SetName("TabSRMM: phase2"); @@ -915,7 +895,7 @@ void CChatRoomDlg::UpdateStatusBar() return; int x = 12; - x += GetTextPixelSize(mi->ptszModDispName, (HFONT)SendMessage(m_pContainer->hwndStatus, WM_GETFONT, 0, 0), TRUE); + x += Chat_GetTextPixelSize(mi->ptszModDispName, (HFONT)SendMessage(m_pContainer->hwndStatus, WM_GETFONT, 0, 0), true); x += GetSystemMetrics(SM_CXSMICON); wchar_t szFinalStatusBarText[512]; diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp index c0b40134fe..51f5ab8a98 100644 --- a/src/core/stdmsg/src/chat_window.cpp +++ b/src/core/stdmsg/src/chat_window.cpp @@ -26,28 +26,6 @@ static HKL hkl = nullptr; static wchar_t szTrimString[] = L":;,.!?\'\"><()[]- \r\n"; -int GetTextPixelSize(wchar_t *pszText, HFONT hFont, BOOL bWidth) -{ - if (!pszText || !hFont) - return 0; - - HDC hdc = GetDC(nullptr); - HFONT hOldFont = (HFONT)SelectObject(hdc, hFont); - RECT rc = {}; - DrawText(hdc, pszText, -1, &rc, DT_CALCRECT); - SelectObject(hdc, hOldFont); - ReleaseDC(nullptr, hdc); - return bWidth ? rc.right - rc.left : rc.bottom - rc.top; -} - -static void __cdecl phase2(void *lParam) -{ - SESSION_INFO *si = (SESSION_INFO*)lParam; - Sleep(30); - if (si && si->pDlg) - si->pDlg->RedrawLog2(); -} - ///////////////////////////////////////////////////////////////////////////////////////// CChatRoomDlg::CChatRoomDlg(SESSION_INFO *si) : @@ -306,6 +284,16 @@ void CChatRoomDlg::LoadSettings() m_clrInputFG = g_Settings.MessageAreaColor; } +///////////////////////////////////////////////////////////////////////////////////////// + +static void __cdecl phase2(void *lParam) +{ + SESSION_INFO *si = (SESSION_INFO*)lParam; + Sleep(30); + if (si && si->pDlg) + si->pDlg->RedrawLog2(); +} + void CChatRoomDlg::RedrawLog() { m_si->LastTime = 0; @@ -329,6 +317,8 @@ void CChatRoomDlg::RedrawLog() else ClearLog(); } +///////////////////////////////////////////////////////////////////////////////////////// + void CChatRoomDlg::ScrollToBottom() { if ((GetWindowLongPtr(m_log.GetHwnd(), GWL_STYLE) & WS_VSCROLL) == 0) @@ -409,8 +399,8 @@ void CChatRoomDlg::UpdateOptions() m_message.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); // nicklist - int ih = GetTextPixelSize(L"AQGglo", g_Settings.UserListFont, FALSE); - int ih2 = GetTextPixelSize(L"AQGglo", g_Settings.UserListHeadingsFont, FALSE); + int ih = Chat_GetTextPixelSize(L"AQGglo", g_Settings.UserListFont, FALSE); + int ih2 = Chat_GetTextPixelSize(L"AQGglo", g_Settings.UserListHeadingsFont, FALSE); int height = db_get_b(0, CHAT_MODULE, "NicklistRowDist", 12); int font = ih > ih2 ? ih : ih2; @@ -430,7 +420,7 @@ void CChatRoomDlg::UpdateStatusBar() MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); wchar_t *ptszDispName = mi->ptszModDispName; int x = 12; - x += GetTextPixelSize(ptszDispName, (HFONT)SendMessage(m_hwndStatus, WM_GETFONT, 0, 0), TRUE); + x += Chat_GetTextPixelSize(ptszDispName, (HFONT)SendMessage(m_hwndStatus, WM_GETFONT, 0, 0), TRUE); x += GetSystemMetrics(SM_CXSMICON); int iStatusbarParts[2] = { x, -1 }; SendMessage(m_hwndStatus, SB_SETPARTS, 2, (LPARAM)&iStatusbarParts); @@ -478,14 +468,12 @@ void CChatRoomDlg::UpdateTitle() int CChatRoomDlg::Resizer(UTILRESIZECONTROL *urc) { - SESSION_INFO *si = m_si; - RECT rc; bool bControl = db_get_b(0, CHAT_MODULE, "ShowTopButtons", 1) != 0; bool bFormat = db_get_b(0, CHAT_MODULE, "ShowFormatButtons", 1) != 0; bool bToolbar = bFormat || bControl; bool bSend = db_get_b(0, CHAT_MODULE, "ShowSend", 0) != 0; - bool bNick = si->iType != GCW_SERVER && m_bNicklistEnabled; + bool bNick = m_si->iType != GCW_SERVER && m_bNicklistEnabled; switch (urc->wId) { case IDOK: @@ -1049,8 +1037,8 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) if (mis->CtlType == ODT_MENU) return Menu_MeasureItem(lParam); - int ih = GetTextPixelSize(L"AQGgl'", g_Settings.UserListFont, FALSE); - int ih2 = GetTextPixelSize(L"AQGg'", g_Settings.UserListHeadingsFont, FALSE); + int ih = Chat_GetTextPixelSize(L"AQGgl'", g_Settings.UserListFont, FALSE); + int ih2 = Chat_GetTextPixelSize(L"AQGg'", g_Settings.UserListHeadingsFont, FALSE); int font = ih > ih2 ? ih : ih2; int height = db_get_b(0, CHAT_MODULE, "NicklistRowDist", 12); diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h index b0e71e7644..7d7e196839 100644 --- a/src/core/stdmsg/src/stdafx.h +++ b/src/core/stdmsg/src/stdafx.h @@ -129,8 +129,6 @@ void ValidateFilename(wchar_t *filename); char* Log_CreateRtfHeader(MODULEINFO *mi); // window.cpp -int GetTextPixelSize(wchar_t* pszText, HFONT hFont, BOOL bWidth); - SESSION_INFO* SM_GetPrevWindow(SESSION_INFO *si); SESSION_INFO* SM_GetNextWindow(SESSION_INFO *si); diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index 1d2e85c3e9..5f408fb215 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -44,14 +44,14 @@ extern char* pLogIconBmpBits[14]; extern LIST g_arSessions; // log.c -void LoadMsgLogBitmaps(void); -void FreeMsgLogBitmaps(void); -void ValidateFilename (wchar_t *filename); +void LoadMsgLogBitmaps(void); +void FreeMsgLogBitmaps(void); +void ValidateFilename (wchar_t *filename); wchar_t* MakeTimeStamp(wchar_t *pszStamp, time_t time); wchar_t* GetChatLogsFilename(SESSION_INFO *si, time_t tTime); -char* Log_CreateRtfHeader(MODULEINFO *mi); -char* Log_CreateRTF(LOGSTREAMDATA *streamData); -char* Log_SetStyle(int style); +char* Log_CreateRtfHeader(MODULEINFO *mi); +char* Log_CreateRTF(LOGSTREAMDATA *streamData); +char* Log_SetStyle(int style); // chat_manager.cpp BOOL SM_AddEvent(const wchar_t *pszID, const char *pszModule, GCEVENT *gce, bool bIsHighlighted); @@ -98,7 +98,6 @@ void UnloadChatModule(void); // tools.c int DoRtfToTags(CMStringW &pszText, int iNumColors, COLORREF *pColors); -int GetTextPixelSize(wchar_t* pszText, HFONT hFont, BOOL bWidth); wchar_t *RemoveFormatting(const wchar_t* pszText); BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix); int GetColorIndex(const char *pszModule, COLORREF cr); diff --git a/src/mir_app/src/chat_opts.cpp b/src/mir_app/src/chat_opts.cpp index ecbbdd5699..1b31dae8f5 100644 --- a/src/mir_app/src/chat_opts.cpp +++ b/src/mir_app/src/chat_opts.cpp @@ -285,14 +285,14 @@ void SetIndentSize() LOGFONT lf; LoadMsgDlgFont(0, &lf, nullptr); HFONT hFont = CreateFontIndirect(&lf); - int iText = GetTextPixelSize(MakeTimeStamp(g_Settings->pszTimeStamp, time(nullptr)), hFont, TRUE); + int iText = Chat_GetTextPixelSize(MakeTimeStamp(g_Settings->pszTimeStamp, time(nullptr)), hFont, TRUE); DeleteObject(hFont); g_Settings->LogTextIndent = iText * 12 / 10; } else g_Settings->LogTextIndent = 0; } -int GetTextPixelSize(wchar_t* pszText, HFONT hFont, BOOL bWidth) +int Chat_GetTextPixelSize(wchar_t* pszText, HFONT hFont, BOOL bWidth) { if (!pszText || !hFont) return 0; diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index 9b15c27218..2e03698412 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -837,3 +837,23 @@ MIR_APP_DLL(void) Chat_DestroyGCMenu(HMENU hMenu, int iIndex) RemoveMenu(hMenu, iIndex, MF_BYPOSITION); } } + +///////////////////////////////////////////////////////////////////////////////////////// +// calculates the required rectangle for a string using the given font. This is more +// precise than using GetTextExtentPoint...() + +MIR_APP_DLL(int) Chat_GetTextPixelSize(const wchar_t *pszText, HFONT hFont, bool bWidth) +{ + if (!pszText || !hFont) + return 0; + + HDC hdc = GetDC(nullptr); + HFONT hOldFont = (HFONT)SelectObject(hdc, hFont); + + RECT rc = { 0 }; + DrawText(hdc, pszText, -1, &rc, DT_CALCRECT); + + SelectObject(hdc, hOldFont); + ReleaseDC(nullptr, hdc); + return bWidth ? rc.right - rc.left : rc.bottom - rc.top; +} diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index f7fa45ce1d..9e7da2d190 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -443,3 +443,4 @@ Chat_DoEventHook @445 NONAME _stubLogProc@16 @446 NONAME _stubMessageProc@16 @447 NONAME _stubNicklistProc@16 @448 NONAME +Chat_GetTextPixelSize @449 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 0d7fce7403..fd8431c520 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -443,3 +443,4 @@ Chat_DoEventHook @445 NONAME stubLogProc @446 NONAME stubMessageProc @447 NONAME stubNicklistProc @448 NONAME +Chat_GetTextPixelSize @449 NONAME -- cgit v1.2.3