summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-03-27 14:15:17 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-03-27 14:15:17 +0300
commitb3e8f72f17e9787aa5455977dc5eae05ddecb578 (patch)
tree0fb22846efd334599b9a8a774153e98aca3c97cb /src
parent54928843e7fcd6d42be6d8d5d1127830fda97eca (diff)
common code moved to mir_app
Diffstat (limited to 'src')
-rw-r--r--src/core/stdmsg/src/chat_window.cpp48
-rw-r--r--src/core/stdmsg/src/stdafx.h2
-rw-r--r--src/mir_app/src/chat.h13
-rw-r--r--src/mir_app/src/chat_opts.cpp4
-rw-r--r--src/mir_app/src/chat_tools.cpp20
-rw-r--r--src/mir_app/src/mir_app.def1
-rw-r--r--src/mir_app/src/mir_app64.def1
7 files changed, 48 insertions, 41 deletions
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<SESSION_INFO> 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