summaryrefslogtreecommitdiff
path: root/src/mir_app
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/mir_app
parent54928843e7fcd6d42be6d8d5d1127830fda97eca (diff)
common code moved to mir_app
Diffstat (limited to 'src/mir_app')
-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
5 files changed, 30 insertions, 9 deletions
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