diff options
author | George Hazan <ghazan@miranda.im> | 2017-03-21 21:22:34 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-03-21 21:22:34 +0300 |
commit | 216654c005d6b363c91ee3dfbff2203bab4e06c1 (patch) | |
tree | cd38e82811875d56c38415479a77b71dcd418e27 /src/core/stdmsg | |
parent | 7104a25fa975b8b70fcab6e499efe91bc1a9313c (diff) |
common chat hotkeys processing code moved to mir_app
Diffstat (limited to 'src/core/stdmsg')
-rw-r--r-- | src/core/stdmsg/src/chat_manager.cpp | 2 | ||||
-rw-r--r-- | src/core/stdmsg/src/chat_util.cpp | 45 | ||||
-rw-r--r-- | src/core/stdmsg/src/chat_window.cpp | 166 | ||||
-rw-r--r-- | src/core/stdmsg/src/msgoptions.cpp | 13 | ||||
-rw-r--r-- | src/core/stdmsg/src/stdafx.h | 5 |
5 files changed, 21 insertions, 210 deletions
diff --git a/src/core/stdmsg/src/chat_manager.cpp b/src/core/stdmsg/src/chat_manager.cpp index bd9d3cacb8..dded4667bc 100644 --- a/src/core/stdmsg/src/chat_manager.cpp +++ b/src/core/stdmsg/src/chat_manager.cpp @@ -133,7 +133,7 @@ static void OnLoadSettings() DeleteObject(g_Settings.MessageAreaFont); LOGFONT lf; - LoadMessageFont(&lf, &g_Settings.MessageAreaColor); + LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, &lf, &g_Settings.MessageAreaColor); g_Settings.MessageAreaFont = CreateFontIndirect(&lf); g_Settings.iX = db_get_dw(NULL, CHAT_MODULE, "roomx", -1); diff --git a/src/core/stdmsg/src/chat_util.cpp b/src/core/stdmsg/src/chat_util.cpp index d163e2e83a..e1ee1b2f96 100644 --- a/src/core/stdmsg/src/chat_util.cpp +++ b/src/core/stdmsg/src/chat_util.cpp @@ -142,45 +142,6 @@ char* Message_GetFromStream(HWND hwndDlg, SESSION_INFO *si) ///////////////////////////////////////////////////////////////////////////////////////// -bool LoadMessageFont(LOGFONT *lf, COLORREF *colour) -{ - char str[32]; - int i = 8; // MSGFONTID_MESSAGEAREA - - if (colour) { - mir_snprintf(str, "SRMFont%dCol", i); - *colour = db_get_dw(NULL, "SRMM", str, 0); - } - if (lf) { - mir_snprintf(str, "SRMFont%dSize", i); - lf->lfHeight = (char)db_get_b(NULL, "SRMM", str, -12); - lf->lfWidth = 0; - lf->lfEscapement = 0; - lf->lfOrientation = 0; - mir_snprintf(str, "SRMFont%dSty", i); - int style = db_get_b(NULL, "SRMM", str, 0); - lf->lfWeight = style & DBFONTF_BOLD ? FW_BOLD : FW_NORMAL; - lf->lfItalic = style & DBFONTF_ITALIC ? 1 : 0; - lf->lfUnderline = 0; - lf->lfStrikeOut = 0; - lf->lfOutPrecision = OUT_DEFAULT_PRECIS; - lf->lfClipPrecision = CLIP_DEFAULT_PRECIS; - lf->lfQuality = DEFAULT_QUALITY; - lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; - mir_snprintf(str, "SRMFont%d", i); - - ptrW wszFontFace(db_get_wsa(NULL, "SRMM", str)); - if (wszFontFace == nullptr) - mir_wstrcpy(lf->lfFaceName, L"Arial"); - else - mir_wstrncpy(lf->lfFaceName, wszFontFace, _countof(lf->lfFaceName)); - - mir_snprintf(str, "SRMFont%dSet", i); - lf->lfCharSet = db_get_b(NULL, "SRMM", str, DEFAULT_CHARSET); - } - return true; -} - int GetRichTextLength(HWND hwnd) { GETTEXTLENGTHEX gtl; @@ -212,13 +173,11 @@ int GetColorIndex(const char* pszModule, COLORREF cr) void CheckColorsInModule(const char* pszModule) { MODULEINFO *pMod = pci->MM_FindModule(pszModule); - int i = 0; - COLORREF crBG = (COLORREF)db_get_dw(NULL, CHAT_MODULE, "ColorMessageBG", GetSysColor(COLOR_WINDOW)); - if (!pMod) return; - for (i = 0; i < pMod->nColorCount; i++) { + COLORREF crBG = (COLORREF)db_get_dw(NULL, CHAT_MODULE, "ColorMessageBG", GetSysColor(COLOR_WINDOW)); + for (int i = 0; i < pMod->nColorCount; i++) { if (pMod->crColors[i] == g_Settings.MessageAreaColor || pMod->crColors[i] == crBG) { if (pMod->crColors[i] == RGB(255, 255, 255)) pMod->crColors[i]--; diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp index 73816dc2ac..5fdab6eb00 100644 --- a/src/core/stdmsg/src/chat_window.cpp +++ b/src/core/stdmsg/src/chat_window.cpp @@ -91,7 +91,7 @@ LBL_CalcBottom: return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; } -static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK CChatRoomDlg::MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { MESSAGESUBDATA *dat = (MESSAGESUBDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA); HWND hwndDlg = GetParent(hwnd); @@ -207,7 +207,7 @@ static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, if (g_Settings.bTabsEnable) SendMessage(hwndDlg, GC_SWITCHTAB, 0, (int)wParam - (int)VK_NUMPAD1); - if (wParam == VK_TAB && !isCtrl && !isShift) { //tab-autocomplete + if (wParam == VK_TAB && !isCtrl && !isShift) { // tab-autocomplete wchar_t *pszText = nullptr; LRESULT lResult = (LRESULT)SendMessage(hwnd, EM_GETSEL, 0, 0); @@ -269,80 +269,26 @@ static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, dat->szTabSave[0] = '\0'; } - if (wParam == VK_F4 && isCtrl && !isAlt) { // ctrl-F4 (close tab) - pDlg->CloseTab(); - return TRUE; - } - - if (wParam == VK_ESCAPE && !isCtrl && !isAlt) { // Esc (close tab) - pDlg->CloseTab(); - return TRUE; - } - - if (wParam == 0x49 && isCtrl && !isAlt) { // ctrl-i (italics) - CheckDlgButton(hwndDlg, IDC_SRMM_ITALICS, IsDlgButtonChecked(hwndDlg, IDC_SRMM_ITALICS) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_ITALICS, 0), 0); + if (pDlg->ProcessHotkeys(wParam)) return TRUE; - } - - if (wParam == 0x42 && isCtrl && !isAlt) { // ctrl-b (bold) - CheckDlgButton(hwndDlg, IDC_SRMM_BOLD, IsDlgButtonChecked(hwndDlg, IDC_SRMM_BOLD) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_BOLD, 0), 0); - return TRUE; - } - - if (wParam == 0x55 && isCtrl && !isAlt) { // ctrl-u (paste clean text) - CheckDlgButton(hwndDlg, IDC_SRMM_UNDERLINE, IsDlgButtonChecked(hwndDlg, IDC_SRMM_UNDERLINE) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_UNDERLINE, 0), 0); - return TRUE; - } - - if (wParam == 0x4b && isCtrl && !isAlt) { // ctrl-k (paste clean text) - CheckDlgButton(hwndDlg, IDC_SRMM_COLOR, IsDlgButtonChecked(hwndDlg, IDC_SRMM_COLOR) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_COLOR, 0), 0); - return TRUE; - } - - if (wParam == VK_SPACE && isCtrl && !isAlt) { // ctrl-space (paste clean text) - CheckDlgButton(hwndDlg, IDC_SRMM_BKGCOLOR, BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SRMM_COLOR, BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SRMM_BOLD, BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SRMM_UNDERLINE, BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SRMM_ITALICS, BST_UNCHECKED); - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_BKGCOLOR, 0), 0); - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_COLOR, 0), 0); - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_BOLD, 0), 0); - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_UNDERLINE, 0), 0); - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_ITALICS, 0), 0); - return TRUE; - } - - if (wParam == 0x4c && isCtrl && !isAlt) { // ctrl-l (paste clean text) - CheckDlgButton(hwndDlg, IDC_SRMM_BKGCOLOR, IsDlgButtonChecked(hwndDlg, IDC_SRMM_BKGCOLOR) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED); - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_BKGCOLOR, 0), 0); - return TRUE; - } if (wParam == 0x46 && isCtrl && !isAlt) { // ctrl-f (paste clean text) - if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_SRMM_FILTER))) - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SRMM_FILTER, 0), 0); + pDlg->onClick_Filter(&pDlg->m_btnFilter); return TRUE; } if (wParam == 0x4e && isCtrl && !isAlt) { // ctrl-n (nicklist) - if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_SHOWNICKLIST))) - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SHOWNICKLIST, 0), 0); + pDlg->onClick_NickList(&pDlg->m_btnNickList); return TRUE; } if (wParam == 0x48 && isCtrl && !isAlt) { // ctrl-h (history) - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_HISTORY, 0), 0); + pDlg->onClick_History(&pDlg->m_btnHistory); return TRUE; } if (wParam == 0x4f && isCtrl && !isAlt) { // ctrl-o (options) - if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHANMGR))) - SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_CHANMGR, 0), 0); + pDlg->onClick_Options(&pDlg->m_btnChannelMgr); return TRUE; } @@ -480,76 +426,7 @@ static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MBUTTONUP: - { - CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); - cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_BACKCOLOR | CFM_COLOR; - SendMessage(hwnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); - - MODULEINFO *pmi = pci->MM_FindModule(dat->si->pszModule); - if (pmi == nullptr) - break; - - if (pmi->bColor) { - int index = GetColorIndex(dat->si->pszModule, cf.crTextColor); - UINT u = IsDlgButtonChecked(hwndDlg, IDC_SRMM_COLOR); - - if (index >= 0) { - pDlg->m_bFGSet = true; - pDlg->m_iFG = index; - } - - if (u == BST_UNCHECKED && cf.crTextColor != g_Settings.MessageAreaColor) - CheckDlgButton(hwndDlg, IDC_SRMM_COLOR, BST_CHECKED); - else if (u == BST_CHECKED && cf.crTextColor == g_Settings.MessageAreaColor) - CheckDlgButton(hwndDlg, IDC_SRMM_COLOR, BST_UNCHECKED); - } - - if (pmi->bBkgColor) { - int index = GetColorIndex(dat->si->pszModule, cf.crBackColor); - COLORREF crB = (COLORREF)db_get_dw(0, CHAT_MODULE, "ColorMessageBG", GetSysColor(COLOR_WINDOW)); - UINT u = IsDlgButtonChecked(hwndDlg, IDC_SRMM_BKGCOLOR); - - if (index >= 0) { - pDlg->m_bBGSet = TRUE; - pDlg->m_iBG = index; - } - if (u == BST_UNCHECKED && cf.crBackColor != crB) - CheckDlgButton(hwndDlg, IDC_SRMM_BKGCOLOR, BST_CHECKED); - else if (u == BST_CHECKED && cf.crBackColor == crB) - CheckDlgButton(hwndDlg, IDC_SRMM_BKGCOLOR, BST_UNCHECKED); - } - - if (pmi->bBold) { - UINT u = IsDlgButtonChecked(hwndDlg, IDC_SRMM_BOLD); - UINT u2 = cf.dwEffects; - u2 &= CFE_BOLD; - if (u == BST_UNCHECKED && u2) - CheckDlgButton(hwndDlg, IDC_SRMM_BOLD, BST_CHECKED); - else if (u == BST_CHECKED && u2 == 0) - CheckDlgButton(hwndDlg, IDC_SRMM_BOLD, BST_UNCHECKED); - } - - if (pmi->bItalics) { - UINT u = IsDlgButtonChecked(hwndDlg, IDC_SRMM_ITALICS); - UINT u2 = cf.dwEffects; - u2 &= CFE_ITALIC; - if (u == BST_UNCHECKED && u2) - CheckDlgButton(hwndDlg, IDC_SRMM_ITALICS, BST_CHECKED); - else if (u == BST_CHECKED && u2 == 0) - CheckDlgButton(hwndDlg, IDC_SRMM_ITALICS, BST_UNCHECKED); - } - - if (pmi->bUnderline) { - UINT u = IsDlgButtonChecked(hwndDlg, IDC_SRMM_UNDERLINE); - UINT u2 = cf.dwEffects; - u2 &= CFE_UNDERLINE; - if (u == BST_UNCHECKED && u2) - CheckDlgButton(hwndDlg, IDC_SRMM_UNDERLINE, BST_CHECKED); - else if (u == BST_CHECKED && u2 == 0) - CheckDlgButton(hwndDlg, IDC_SRMM_UNDERLINE, BST_UNCHECKED); - } - } + pDlg->RefreshButtonStatus(); break; case WM_DESTROY: @@ -832,10 +709,6 @@ CChatRoomDlg::CChatRoomDlg(SESSION_INFO *si) : m_autoClose = 0; m_forceResizable = true; - m_btnBold.OnClick = Callback(this, &CChatRoomDlg::onClick_Bold); - m_btnItalic.OnClick = Callback(this, &CChatRoomDlg::onClick_Bold); - m_btnUnderline.OnClick = Callback(this, &CChatRoomDlg::onClick_Bold); - m_btnOk.OnClick = Callback(this, &CChatRoomDlg::onClick_Ok); m_btnFilter.OnClick = Callback(this, &CChatRoomDlg::onClick_Filter); @@ -926,23 +799,6 @@ void CChatRoomDlg::OnDestroy() NotifyLocalWinEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_CLOSE); } -void CChatRoomDlg::onClick_Bold(CCtrlButton *pButton) -{ - if (!pButton->Enabled()) - return; - - CHARFORMAT2 cf; - cf.cbSize = sizeof(CHARFORMAT2); - cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE; - cf.dwEffects = 0; - switch (pButton->GetCtrlId()) { - case IDC_SRMM_BOLD: cf.dwEffects |= CFE_BOLD; break; - case IDC_SRMM_ITALICS: cf.dwEffects |= CFE_ITALIC; break; - case IDC_SRMM_UNDERLINE: cf.dwEffects |= CFE_UNDERLINE; break; - } - m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); -} - void CChatRoomDlg::onClick_Filter(CCtrlButton *pButton) { if (!pButton->Enabled()) @@ -1144,7 +1000,7 @@ void CChatRoomDlg::CloseTab() void CChatRoomDlg::LoadSettings() { m_clrInputBG = db_get_dw(0, CHAT_MODULE, "ColorMessageBG", GetSysColor(COLOR_WINDOW)); - LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, nullptr, &m_clrInputFG); + m_clrInputFG = g_Settings.MessageAreaColor; } void CChatRoomDlg::RedrawLog() @@ -1243,9 +1099,9 @@ void CChatRoomDlg::UpdateOptions() cf.dwMask = CFM_COLOR | CFM_BOLD | CFM_UNDERLINE | CFM_BACKCOLOR; cf.dwEffects = 0; cf.crTextColor = g_Settings.MessageAreaColor; - cf.crBackColor = db_get_dw(0, CHAT_MODULE, "ColorMessageBG", GetSysColor(COLOR_WINDOW)); + cf.crBackColor = m_clrInputBG; - m_message.SendMsg(EM_SETBKGNDCOLOR, 0, db_get_dw(0, CHAT_MODULE, "ColorMessageBG", GetSysColor(COLOR_WINDOW))); + m_message.SendMsg(EM_SETBKGNDCOLOR, 0, m_clrInputBG); m_message.SendMsg(WM_SETFONT, (WPARAM)g_Settings.MessageAreaFont, MAKELPARAM(TRUE, 0)); m_message.SendMsg(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); diff --git a/src/core/stdmsg/src/msgoptions.cpp b/src/core/stdmsg/src/msgoptions.cpp index ad7f93fa7c..75467c6d18 100644 --- a/src/core/stdmsg/src/msgoptions.cpp +++ b/src/core/stdmsg/src/msgoptions.cpp @@ -82,13 +82,12 @@ bool LoadMsgDlgFont(int i, LOGFONT* lf, COLORREF * colour) lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
mir_snprintf(str, "SRMFont%d", i);
- DBVARIANT dbv;
- if (db_get_ws(NULL, SRMMMOD, str, &dbv))
- wcsncpy(lf->lfFaceName, fontOptionsList[i].szDefFace, _countof(lf->lfFaceName)-1);
- else {
- mir_wstrncpy(lf->lfFaceName, dbv.ptszVal, _countof(lf->lfFaceName));
- db_free(&dbv);
- }
+ ptrW wszFontFace(db_get_wsa(NULL, SRMMMOD, str));
+ if (wszFontFace == nullptr)
+ wcsncpy_s(lf->lfFaceName, fontOptionsList[i].szDefFace, _TRUNCATE);
+ else
+ mir_wstrncpy(lf->lfFaceName, wszFontFace, _countof(lf->lfFaceName));
+
mir_snprintf(str, "SRMFont%dSet", i);
lf->lfCharSet = db_get_b(NULL, SRMMMOD, str, MsgDlgGetFontDefaultCharset(lf->lfFaceName));
}
diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h index ec0d18a764..c665cbb2b8 100644 --- a/src/core/stdmsg/src/stdafx.h +++ b/src/core/stdmsg/src/stdafx.h @@ -127,7 +127,6 @@ void Unload_ChatModule(void); void Load_ChatModule(void);
// log.cpp
-void Log_StreamInEvent(HWND hwndDlg, LOGINFO *lin, SESSION_INFO *si, BOOL bRedraw);
void ValidateFilename(wchar_t *filename);
char* Log_CreateRtfHeader(MODULEINFO *mi);
@@ -151,7 +150,6 @@ void CheckColorsInModule(const char* pszModule); int GetRichTextLength(HWND hwnd);
UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText);
void DestroyGCMenu(HMENU *hMenu, int iIndex);
-bool LoadMessageFont(LOGFONT *lf, COLORREF *colour);
void SetButtonsPos(HWND hwndDlg, bool bIsChat);
int RestoreWindowPosition(HWND hwnd, MCONTACT hContact, bool bHide);
@@ -212,6 +210,7 @@ class CChatRoomDlg : public CSrmmBaseDialog friend struct CTabbedWindow;
static INT_PTR CALLBACK FilterWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ static LRESULT CALLBACK MessageSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK NicklistSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
HWND m_hwndStatus;
@@ -251,8 +250,6 @@ public: virtual void UpdateStatusBar() override;
virtual void UpdateTitle() override;
- void onClick_Bold(CCtrlButton*);
-
void onClick_Ok(CCtrlButton*);
void onClick_Filter(CCtrlButton*);
|