From 83bf1b335e6650b1df77dc712e5a39d4141f8db0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 14 Apr 2020 14:49:31 +0300 Subject: Popup+ received MTextControl support back, based on library instead of services --- plugins/Popup/Popup.vcxproj | 5 +++ plugins/Popup/src/config.h | 6 ++- plugins/Popup/src/history.cpp | 1 + plugins/Popup/src/main.cpp | 7 +++ plugins/Popup/src/opt_skins.cpp | 14 +++++- plugins/Popup/src/popup_wnd2.cpp | 35 +++++++++++++-- plugins/Popup/src/popup_wnd2.h | 12 +++-- plugins/Popup/src/skin.cpp | 96 ++++++++++++++++++++++++++-------------- plugins/Popup/src/stdafx.h | 1 + plugins/Popup/src/version.h | 2 +- 10 files changed, 135 insertions(+), 44 deletions(-) (limited to 'plugins/Popup') diff --git a/plugins/Popup/Popup.vcxproj b/plugins/Popup/Popup.vcxproj index 168b8eb95e..7413813a34 100644 --- a/plugins/Popup/Popup.vcxproj +++ b/plugins/Popup/Popup.vcxproj @@ -18,6 +18,11 @@ x64 + + + {e26d2311-c164-48cf-ba24-5ceda873d1b2} + + PopupPlus {726460C7-E1F1-4C37-B64F-DA8A8DD26D70} diff --git a/plugins/Popup/src/config.h b/plugins/Popup/src/config.h index 31c196daf0..888b7624f5 100644 --- a/plugins/Popup/src/config.h +++ b/plugins/Popup/src/config.h @@ -51,7 +51,6 @@ typedef struct tagPOPUPOPTIONS { BYTE DisableWhenFullscreen; //others BYTE debug; - //==Page Skins==== LPTSTR SkinPack; BYTE DisplayTime; @@ -59,7 +58,7 @@ typedef struct tagPOPUPOPTIONS { BYTE EnableFreeformShadows; BYTE EnableAeroGlass; BYTE UseWinColors; - + BYTE UseMText; //==Page Actions==== DWORD actions; //Mouse Override @@ -130,6 +129,9 @@ extern HANDLE hSemaphore; extern BOOL closing; extern HANDLE folderId; +extern HANDLE htuText; +extern HANDLE htuTitle; + extern BOOL gbPopupLoaded; extern BOOL gbHppInstalled; diff --git a/plugins/Popup/src/history.cpp b/plugins/Popup/src/history.cpp index 23c3706984..d079bc1ac4 100644 --- a/plugins/Popup/src/history.cpp +++ b/plugins/Popup/src/history.cpp @@ -234,6 +234,7 @@ static INT_PTR CALLBACK HistoryDlgProc(HWND hwnd, UINT msg, WPARAM, LPARAM lPara POPUPDATA2 *ppd = arPopupHistory[lpdis->itemID]; wndPreview = new PopupWnd2(ppd, &customOptions, true); + wndPreview->buildMText(); wndPreview->update(); ListBox_SetItemData(hwndLog, lpdis->itemID, wndPreview); diff --git a/plugins/Popup/src/main.cpp b/plugins/Popup/src/main.cpp index 0e21debb84..88d87f9df9 100644 --- a/plugins/Popup/src/main.cpp +++ b/plugins/Popup/src/main.cpp @@ -48,6 +48,9 @@ HMODULE hDwmapiDll = nullptr; GLOBAL_WND_CLASSES g_wndClass = { 0 }; +HANDLE htuText; +HANDLE htuTitle; + HGENMENU hMenuRoot; HGENMENU hMenuItem; HGENMENU hMenuItemHistory; @@ -218,6 +221,10 @@ static int ModulesLoaded(WPARAM, LPARAM) gbHppInstalled = ServiceExists(MS_HPP_GETVERSION) && ServiceExists(MS_HPP_EG_WINDOW) && (CallService(MS_HPP_GETVERSION, 0, 0) >= PLUGIN_MAKE_VERSION(1, 5, 0, 112)); + // check if MText plugin is installed + htuText = MTextRegister("Popup Plus/Text", MTEXT_FANCY_DEFAULT); + htuTitle = MTextRegister("Popup Plus/Title", MTEXT_FANCY_DEFAULT); + // check if OptionLoaded if (!OptionLoaded) LoadOptions(); diff --git a/plugins/Popup/src/opt_skins.cpp b/plugins/Popup/src/opt_skins.cpp index 953d0e5dca..43267d16b4 100644 --- a/plugins/Popup/src/opt_skins.cpp +++ b/plugins/Popup/src/opt_skins.cpp @@ -72,6 +72,7 @@ static void updatePreviewImage(HWND hwndBox) if (wndPreview) delete wndPreview; wndPreview = new PopupWnd2(&ppd, &customOptions, true); + wndPreview->buildMText(); wndPreview->update(); gPreviewOk = true; @@ -191,7 +192,8 @@ static LPTSTR mainOption[] = { LPGENW("Drop shadow effect"), LPGENW("Drop shadow effect") L"/" LPGENW("non rectangular"), LPGENW("Enable Aero Glass (Vista+)"), - LPGENW("Use Windows colors") }; + LPGENW("Use Windows colors"), + LPGENW("Use advanced text render") }; int SkinOptionList_AddMain(OPTTREE_OPTION* &options, int *OptionsCount, int pos, DWORD *dwGlobalOptions) { @@ -219,6 +221,11 @@ int SkinOptionList_AddMain(OPTTREE_OPTION* &options, int *OptionsCount, int pos, *dwGlobalOptions |= PopupOptions.UseWinColors ? (1 << i) : 0; bCheck = PopupOptions.UseWinColors; break; + case 5: + if (!(htuText&&htuTitle)) continue; + *dwGlobalOptions |= PopupOptions.UseMText ? (1 << i) : 0; + bCheck = PopupOptions.UseMText; + break; } *OptionsCount += 1; options = (OPTTREE_OPTION*)mir_realloc(options, sizeof(OPTTREE_OPTION)*(*OptionsCount)); @@ -280,6 +287,7 @@ void LoadOption_Skins() { PopupOptions.EnableFreeformShadows = g_plugin.getByte("EnableShadowRegion", 1); PopupOptions.EnableAeroGlass = g_plugin.getByte("EnableAeroGlass", 1); PopupOptions.UseWinColors = g_plugin.getByte("UseWinColors", FALSE); + PopupOptions.UseMText = g_plugin.getByte("UseMText", TRUE); } INT_PTR CALLBACK DlgProcPopSkinsOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) @@ -316,6 +324,9 @@ INT_PTR CALLBACK DlgProcPopSkinsOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR case (1 << 4) : PopupOptions.UseWinColors = skinOptions[index].bState; break; + case (1 << 5) : + PopupOptions.UseMText = skinOptions[index].bState; + break; } } updatePreviewImage(GetDlgItem(hwndDlg, IDC_PREVIEWBOX)); @@ -465,6 +476,7 @@ INT_PTR CALLBACK DlgProcPopSkinsOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR g_plugin.setByte("EnableShadowRegion", PopupOptions.EnableFreeformShadows); g_plugin.setByte("EnableAeroGlass", PopupOptions.EnableAeroGlass); g_plugin.setByte("UseWinColors", PopupOptions.UseWinColors); + g_plugin.setByte("UseMText", PopupOptions.UseMText); }// end PSN_APPLY: return TRUE; }// switch (((LPNMHDR)lParam)->code) diff --git a/plugins/Popup/src/popup_wnd2.cpp b/plugins/Popup/src/popup_wnd2.cpp index bcf82433a2..3c0d1a96c3 100644 --- a/plugins/Popup/src/popup_wnd2.cpp +++ b/plugins/Popup/src/popup_wnd2.cpp @@ -132,6 +132,9 @@ PopupWnd2::~PopupWnd2() delete m_bmpAnimate; delete m_avatar; delete[]m_actions; + + if (m_mtText) MTextDestroy(m_mtText); + if (m_mtTitle) MTextDestroy(m_mtTitle); } void PopupWnd2::startThread() @@ -680,6 +683,8 @@ void PopupWnd2::updateData(POPUPDATAW *ppd) fixDefaults(); fixActions(ppd->lpActions, ppd->actionCount); + + if (m_textType == TT_MTEXT) buildMText(); } void PopupWnd2::updateData(POPUPDATA2 *ppd) @@ -721,20 +726,43 @@ void PopupWnd2::updateData(POPUPDATA2 *ppd) fixDefaults(); fixActions(ppd->lpActions, ppd->actionCount); + + if (m_textType == TT_MTEXT) buildMText(); +} + +void PopupWnd2::buildMText() +{ + if (!(htuText && htuTitle && PopupOptions.UseMText)) + return; + + if (m_mtText) MTextDestroy(m_mtText); + if (m_mtTitle) MTextDestroy(m_mtTitle); + m_mtText = m_mtTitle = nullptr; + + if (m_lptzText && m_lptzTitle) { + m_textType = TT_MTEXT; + m_mtText = MTextCreateW(htuText, m_lptzText); + m_mtTitle = MTextCreateW(htuTitle, m_lptzTitle); + } } void PopupWnd2::updateText(wchar_t *text) { - if (m_lptzText) + if (m_lptzText) { replaceStrW(m_lptzText, text); - + if (m_textType == TT_MTEXT) + buildMText(); + } m_bTextEmpty = ::isTextEmpty(m_lptzText); } void PopupWnd2::updateTitle(wchar_t *title) { - if (m_lptzTitle) + if (m_lptzTitle) { replaceStrW(m_lptzTitle, title); + if (m_textType == TT_MTEXT) + buildMText(); + } } void PopupWnd2::updateTimer() @@ -1209,6 +1237,7 @@ void WindowThread(void *arg) CoInitialize(nullptr); // we may need OLE in this thread for smiley substitution PopupWnd2 *wnd = (PopupWnd2 *)arg; + wnd->buildMText(); wnd->create(); PostMessage(wnd->getHwnd(), UM_INITPOPUP, 0, 0); diff --git a/plugins/Popup/src/popup_wnd2.h b/plugins/Popup/src/popup_wnd2.h index 407ebd622d..45b940fbb6 100644 --- a/plugins/Popup/src/popup_wnd2.h +++ b/plugins/Popup/src/popup_wnd2.h @@ -34,7 +34,7 @@ class PopupWnd2 : public MZeroedObject { public: typedef LRESULT(PopupWnd2::*MethodPtr)(LPARAM lParam); - enum TextType { TT_NONE, TT_UNICODE }; + enum TextType { TT_NONE, TT_UNICODE, TT_MTEXT }; struct ActionInfo { @@ -55,6 +55,7 @@ private: // content TextType m_textType; wchar_t *m_lptzTitle, *m_lptzText; + HANDLE m_mtTitle, m_mtText; bool m_bTextEmpty, m_bIcoLib; HFONT m_hfnTitle, m_hfnText; HICON m_hIcon; @@ -129,6 +130,7 @@ public: void updateData(POPUPDATAW *ppd); void updateData(POPUPDATA2 *ppd); + void buildMText(); void updateText(wchar_t *text); void updateTitle(wchar_t *title); @@ -144,13 +146,15 @@ public: bool isTextEmpty() { return m_bTextEmpty; } bool isIcolib() { return m_bIcoLib; } TextType getTextType() { return m_textType; } - wchar_t *getText() { return m_lptzText; } - wchar_t *getTitle() { return m_lptzTitle; } + wchar_t *getText() { return m_lptzText; } + HANDLE getTextM() { return m_mtText; } + wchar_t *getTitle() { return m_lptzTitle; } + HANDLE getTitleM() { return m_mtTitle; } int getActionCount() { return m_actionCount; } ActionInfo *getActions() { return m_actions; } - wchar_t *getTime() { return m_time; } + wchar_t *getTime() { return m_time; } HICON getIcon() { return m_hIcon; } MCONTACT getContact() { return m_hContact; } MCONTACT getContactPassed() { return m_hContactPassed; } diff --git a/plugins/Popup/src/skin.cpp b/plugins/Popup/src/skin.cpp index 3510733dfb..9c045ec41b 100644 --- a/plugins/Popup/src/skin.cpp +++ b/plugins/Popup/src/skin.cpp @@ -235,13 +235,19 @@ void PopupSkin::measure(HDC hdc, PopupWnd2 *wnd, int maxw, POPUPOPTIONS *options szNew.cx = szNew.cy = 0; else { HFONT hFntSave = (HFONT)SelectObject(hdc, fonts.text); - if (wnd->getTextType() == PopupWnd2::TT_UNICODE) { - RECT rc; - SetRect(&rc, 0, 0, szNew.cx, 0); - DrawTextEx(hdc, wnd->getText(), (int)mir_wstrlen(wnd->getText()), &rc, - DT_CALCRECT | DT_EXPANDTABS | DT_LEFT | DT_NOPREFIX | DT_TOP | DT_WORDBREAK/*|DT_RTLREADING*/, nullptr); - szNew.cx = rc.right; - szNew.cy = rc.bottom; + switch (wnd->getTextType()) { + case PopupWnd2::TT_UNICODE: + { + RECT rc; SetRect(&rc, 0, 0, szNew.cx, 0); + DrawTextEx(hdc, wnd->getText(), (int)mir_wstrlen(wnd->getText()), &rc, + DT_CALCRECT | DT_EXPANDTABS | DT_LEFT | DT_NOPREFIX | DT_TOP | DT_WORDBREAK/*|DT_RTLREADING*/, nullptr); + szNew.cx = rc.right; + szNew.cy = rc.bottom; + } + break; + case PopupWnd2::TT_MTEXT: + MTextMeasure(hdc, &szNew, wnd->getTextM()); + break; } SelectObject(hdc, hFntSave); } @@ -272,12 +278,19 @@ void PopupSkin::measure(HDC hdc, PopupWnd2 *wnd, int maxw, POPUPOPTIONS *options wnd->getRenderInfo()->titlew = tmp ? tmp : (maxw - head->fx.eval(wnd->getArgs()) - STYLE_SZ_CLOCK); szNew.cx = wnd->getRenderInfo()->titlew; HFONT hFntSave = (HFONT)SelectObject(hdc, fonts.title); - if (wnd->getTextType() == PopupWnd2::TT_UNICODE) { - RECT rc; SetRect(&rc, 0, 0, szNew.cx, 0); - DrawTextEx(hdc, wnd->getTitle(), (int)mir_wstrlen(wnd->getTitle()), &rc, - DT_CALCRECT | DT_EXPANDTABS | DT_LEFT | DT_NOPREFIX | DT_TOP | DT_WORDBREAK/*|DT_RTLREADING*/, nullptr); - szNew.cx = rc.right; - szNew.cy = rc.bottom; + switch (wnd->getTextType()) { + case PopupWnd2::TT_UNICODE: + { + RECT rc; SetRect(&rc, 0, 0, szNew.cx, 0); + DrawTextEx(hdc, wnd->getTitle(), (int)mir_wstrlen(wnd->getTitle()), &rc, + DT_CALCRECT | DT_EXPANDTABS | DT_LEFT | DT_NOPREFIX | DT_TOP | DT_WORDBREAK/*|DT_RTLREADING*/, nullptr); + szNew.cx = rc.right; + szNew.cy = rc.bottom; + } + break; + case PopupWnd2::TT_MTEXT: + MTextMeasure(hdc, &szNew, wnd->getTitleM()); + break; } SelectObject(hdc, hFntSave); @@ -487,19 +500,26 @@ void PopupSkin::display(MyBitmap *bmp, PopupWnd2 *wnd, POPUPOPTIONS *options, DW pt.x + wnd->getRenderInfo()->realtextw, pt.y + wnd->getRenderInfo()->texth); - if ((drawFlags & DF_STATIC) && !wnd->isTextEmpty()) { + if ((drawFlags&DF_STATIC) && !wnd->isTextEmpty()) { HFONT hFntSave = (HFONT)SelectObject(hdc, fonts.text); bmp->saveAlpha(); - if (wnd->getTextType() == PopupWnd2::TT_UNICODE) { - RECT rc; SetRect(&rc, pt.x, pt.y, pt.x + sz.cx, pt.y + sz.cy); - DrawTextEx(hdc, wnd->getText(), (int)mir_wstrlen(wnd->getText()), &rc, - DT_EXPANDTABS | DT_LEFT | DT_NOPREFIX | DT_TOP | DT_WORDBREAK/*|DT_RTLREADING*/, nullptr); + switch (wnd->getTextType()) { + case PopupWnd2::TT_UNICODE: + { + RECT rc; SetRect(&rc, pt.x, pt.y, pt.x + sz.cx, pt.y + sz.cy); + DrawTextEx(hdc, wnd->getText(), (int)mir_wstrlen(wnd->getText()), &rc, + DT_EXPANDTABS | DT_LEFT | DT_NOPREFIX | DT_TOP | DT_WORDBREAK/*|DT_RTLREADING*/, nullptr); + } + break; + case PopupWnd2::TT_MTEXT: + MTextDisplay(hdc, pt, sz, wnd->getTextM()); + break; } SelectObject(hdc, hFntSave); bmp->restoreAlpha(); } - if (!actionsRendered && (drawFlags & DF_ANIMATE)) { + if (!actionsRendered && (drawFlags&DF_ANIMATE)) { int textAreaWidth = head->fw.eval(wnd->getArgs()); if (textAreaWidth <= 0) textAreaWidth = wnd->getRenderInfo()->realtextw; @@ -522,23 +542,33 @@ void PopupSkin::display(MyBitmap *bmp, PopupWnd2 *wnd, POPUPOPTIONS *options, DW SetTextColor(hdc, head->textColor); else SetTextColor(hdc, wnd->getTitleColor()); + { + bmp->saveAlpha(); + POINT pt; + pt.x = head->fx.eval(wnd->getArgs()); + pt.y = head->fy.eval(wnd->getArgs()); + sz.cx = wnd->getRenderInfo()->titlew; + sz.cy = 1000; - bmp->saveAlpha(); - POINT pt; - pt.x = head->fx.eval(wnd->getArgs()); - pt.y = head->fy.eval(wnd->getArgs()); - sz.cx = wnd->getRenderInfo()->titlew; - sz.cy = 1000; + switch (wnd->getTextType()) { + case PopupWnd2::TT_UNICODE: + { + HFONT hFntSave = (HFONT)SelectObject(hdc, fonts.title); + RECT rc; SetRect(&rc, pt.x, pt.y, pt.x + sz.cx, pt.y + sz.cy); + DrawTextEx(hdc, wnd->getTitle(), (int)mir_wstrlen(wnd->getTitle()), &rc, + DT_EXPANDTABS | DT_LEFT | DT_NOPREFIX | DT_TOP | DT_WORDBREAK/*|DT_RTLREADING*/, nullptr); + SelectObject(hdc, hFntSave); + } + break; + case PopupWnd2::TT_MTEXT: + HFONT hFntSave = (HFONT)SelectObject(hdc, fonts.title); + MTextDisplay(hdc, pt, sz, wnd->getTitleM()); + SelectObject(hdc, hFntSave); + break; + } - if (wnd->getTextType() == PopupWnd2::TT_UNICODE) { - HFONT hFntSave = (HFONT)SelectObject(hdc, fonts.title); - RECT rc; SetRect(&rc, pt.x, pt.y, pt.x + sz.cx, pt.y + sz.cy); - DrawTextEx(hdc, wnd->getTitle(), (int)mir_wstrlen(wnd->getTitle()), &rc, - DT_EXPANDTABS | DT_LEFT | DT_NOPREFIX | DT_TOP | DT_WORDBREAK/*|DT_RTLREADING*/, nullptr); - SelectObject(hdc, hFntSave); + bmp->restoreAlpha(); } - - bmp->restoreAlpha(); break; case ST_ICON: diff --git a/plugins/Popup/src/stdafx.h b/plugins/Popup/src/stdafx.h index ca1f23ef9c..c469b6501a 100644 --- a/plugins/Popup/src/stdafx.h +++ b/plugins/Popup/src/stdafx.h @@ -88,6 +88,7 @@ https://miranda-ng.org/distr/ #include #include #include +#include #include #include diff --git a/plugins/Popup/src/version.h b/plugins/Popup/src/version.h index 1ccf97b413..450918c248 100644 --- a/plugins/Popup/src/version.h +++ b/plugins/Popup/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 2 #define __MINOR_VERSION 1 #define __RELEASE_NUM 1 -#define __BUILD_NUM 16 +#define __BUILD_NUM 17 #include -- cgit v1.2.3