diff options
author | George Hazan <ghazan@miranda.im> | 2017-03-25 14:11:24 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-03-25 14:11:24 +0300 |
commit | 855ca62463d7cfc011228da38fadcd3c2b70fe8b (patch) | |
tree | 45bc4fab69dbce0d078278cbb66ecbeacae2ecaa | |
parent | 19bf42ce996ea933dfbb234034ff317a7edd3bf0 (diff) |
code cleaning
-rw-r--r-- | plugins/TabSRMM/src/msgdialog.cpp | 4 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgdlgutils.cpp | 40 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgs.cpp | 28 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgs.h | 3 | ||||
-rw-r--r-- | plugins/TabSRMM/src/sendqueue.cpp | 153 | ||||
-rw-r--r-- | plugins/TabSRMM/src/sendqueue.h | 11 | ||||
-rw-r--r-- | plugins/TabSRMM/src/utils.cpp | 6 |
7 files changed, 114 insertions, 131 deletions
diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index 5089dfaca3..fedb3d4aab 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -792,7 +792,7 @@ void CSrmmWindow::OnInitDialog() if (tszSavedMsg != 0) {
SETTEXTEX stx = { ST_DEFAULT, 1200 };
m_message.SendMsg(EM_SETTEXTEX, (WPARAM)&stx, tszSavedMsg);
- SendQueue::UpdateSaveAndSendButton(this);
+ UpdateSaveAndSendButton();
if (m_pContainer->m_hwndActive == m_hwnd)
UpdateReadChars();
}
@@ -1297,7 +1297,7 @@ void CSrmmWindow::onChange_Message(CCtrlEdit*) m_dwFlags |= MWF_NEEDHISTORYSAVE;
m_dwLastActivity = GetTickCount();
m_pContainer->dwLastActivity = m_dwLastActivity;
- SendQueue::UpdateSaveAndSendButton(this);
+ UpdateSaveAndSendButton();
if (!(GetKeyState(VK_CONTROL) & 0x8000)) {
m_nLastTyping = GetTickCount();
if (GetWindowTextLength(m_message.GetHwnd())) {
diff --git a/plugins/TabSRMM/src/msgdlgutils.cpp b/plugins/TabSRMM/src/msgdlgutils.cpp index 74a02425a0..2f16a2a7cc 100644 --- a/plugins/TabSRMM/src/msgdlgutils.cpp +++ b/plugins/TabSRMM/src/msgdlgutils.cpp @@ -438,6 +438,33 @@ void CTabBaseDlg::UpdateReadChars() const InvalidateRect(m_pContainer->hwndStatus, nullptr, FALSE);
}
+void CTabBaseDlg::UpdateSaveAndSendButton()
+{
+ GETTEXTLENGTHEX gtxl = { 0 };
+ gtxl.codepage = CP_UTF8;
+ gtxl.flags = GTL_DEFAULT | GTL_PRECISE | GTL_NUMBYTES;
+
+ int len = SendDlgItemMessage(m_hwnd, IDC_SRMM_MESSAGE, EM_GETTEXTLENGTHEX, (WPARAM)>xl, 0);
+ if (len && GetSendButtonState(m_hwnd) == PBS_DISABLED)
+ EnableSendButton(true);
+ else if (len == 0 && GetSendButtonState(m_hwnd) != PBS_DISABLED)
+ EnableSendButton(false);
+
+ if (len) { // looks complex but avoids flickering on the button while typing.
+ if (!(m_dwFlags & MWF_SAVEBTN_SAV)) {
+ SendDlgItemMessage(m_hwnd, IDC_SAVE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)PluginConfig.g_buttonBarIcons[ICON_BUTTON_SAVE]);
+ SendDlgItemMessage(m_hwnd, IDC_SAVE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Save and close session"), BATF_UNICODE);
+ m_dwFlags |= MWF_SAVEBTN_SAV;
+ }
+ }
+ else {
+ SendDlgItemMessage(m_hwnd, IDC_SAVE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)PluginConfig.g_buttonBarIcons[ICON_BUTTON_CANCEL]);
+ SendDlgItemMessage(m_hwnd, IDC_SAVE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Close session"), BATF_UNICODE);
+ m_dwFlags &= ~MWF_SAVEBTN_SAV;
+ }
+ m_textLen = len;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// update all status bar fields and force a redraw of the status bar.
@@ -1600,11 +1627,9 @@ HICON CTabBaseDlg::GetXStatusIcon() const LRESULT TSAPI GetSendButtonState(HWND hwnd)
{
HWND hwndIDok = GetDlgItem(hwnd, IDOK);
-
if (hwndIDok)
- return(SendMessage(hwndIDok, BUTTONGETSTATEID, TRUE, 0));
- else
- return 0;
+ return SendMessage(hwndIDok, BUTTONGETSTATEID, TRUE, 0);
+ return 0;
}
void CTabBaseDlg::EnableSendButton(bool bMode) const
@@ -1617,6 +1642,13 @@ void CTabBaseDlg::EnableSendButton(bool bMode) const SendMessage(hwndOK, BUTTONSETASNORMAL, bMode, 0);
}
+void CTabBaseDlg::EnableSending(bool bMode) const
+{
+ m_message.SendMsg(EM_SETREADONLY, !bMode, 0);
+ Utils::enableDlgControl(m_hwnd, IDC_CLIST, bMode);
+ EnableSendButton(bMode);
+}
+
void CTabBaseDlg::SendNudge() const
{
if (ProtoServiceExists(m_cache->getActiveProto(), PS_SEND_NUDGE) && ServiceExists(MS_NUDGE_SEND))
diff --git a/plugins/TabSRMM/src/msgs.cpp b/plugins/TabSRMM/src/msgs.cpp index cf07478788..a348800445 100644 --- a/plugins/TabSRMM/src/msgs.cpp +++ b/plugins/TabSRMM/src/msgs.cpp @@ -309,6 +309,32 @@ INT_PTR CTabBaseDlg::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) return CSrmmBaseDialog::DlgProc(msg, wParam, lParam);
}
+void CTabBaseDlg::NotifyDeliveryFailure() const
+{
+ if (M.GetByte("adv_noErrorPopups", 0))
+ return;
+
+ if (CallService(MS_POPUP_QUERY, PUQS_GETSTATUS, 0) != 1)
+ return;
+
+ POPUPDATAT ppd = { 0 };
+ ppd.lchContact = m_hContact;
+ wcsncpy_s(ppd.lptzContactName, m_cache->getNick(), _TRUNCATE);
+ wcsncpy_s(ppd.lptzText, TranslateT("A message delivery has failed.\nClick to open the message window."), _TRUNCATE);
+
+ if (!(BOOL)M.GetByte(MODULE, OPT_COLDEFAULT_ERR, TRUE)) {
+ ppd.colorText = (COLORREF)M.GetDword(MODULE, OPT_COLTEXT_ERR, DEFAULT_COLTEXT);
+ ppd.colorBack = (COLORREF)M.GetDword(MODULE, OPT_COLBACK_ERR, DEFAULT_COLBACK);
+ }
+ else ppd.colorText = ppd.colorBack = 0;
+
+ ppd.PluginWindowProc = Utils::PopupDlgProcError;
+ ppd.lchIcon = PluginConfig.g_iconErr;
+ ppd.PluginData = 0;
+ ppd.iSeconds = (int)M.GetDword(MODULE, OPT_DELAY_ERR, (DWORD)DEFAULT_DELAY);
+ PUAddPopupT(&ppd);
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// service function. Sets a status bar text for a contact
@@ -473,7 +499,7 @@ INT_PTR SendMessageCommand_Worker(MCONTACT hContact, LPCSTR pszMsg, bool isWchar // make sure that only the main UI thread will handle window creation
if (GetCurrentThreadId() != PluginConfig.dwThreadID) {
if (pszMsg) {
- wchar_t *tszText = (isWchar) ? mir_wstrdup((WCHAR*)pszMsg) : mir_a2u(pszMsg);
+ wchar_t *tszText = (isWchar) ? mir_wstrdup((wchar_t*)pszMsg) : mir_a2u(pszMsg);
PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SENDMESSAGECOMMANDW, hContact, (LPARAM)tszText);
}
else PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SENDMESSAGECOMMANDW, hContact, 0);
diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index c42a1b1be7..1b3c4987d3 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -407,6 +407,7 @@ public: BOOL DoRtfToTags(CMStringW &pszText, int iNumColors, COLORREF *pColors) const;
void DrawStatusIcons(HDC hDC, const RECT &rc, int gap);
void EnableSendButton(bool bMode) const;
+ void EnableSending(bool bMode) const;
void FlashOnClist(MEVENT hEvent, DBEVENTINFO *dbei);
void FlashTab(bool bInvertMode);
bool GetAvatarVisibility();
@@ -421,6 +422,7 @@ public: void KbdState(bool &isShift, bool &isControl, bool &isAlt);
int LoadLocalFlags();
void LoadSplitter();
+ void NotifyDeliveryFailure() const;
void PlayIncomingSound() const;
void SendHBitmapAsFile(HBITMAP hbmp) const;
void SaveSplitter();
@@ -430,6 +432,7 @@ public: void ShowPicture(bool showNewPic);
void StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend, DBEVENTINFO *dbei_s);
void UpdateReadChars() const;
+ void UpdateSaveAndSendButton();
int MsgWindowDrawHandler(WPARAM wParam, LPARAM lParam);
int MsgWindowUpdateMenu(HMENU submenu, int menuID);
diff --git a/plugins/TabSRMM/src/sendqueue.cpp b/plugins/TabSRMM/src/sendqueue.cpp index e061cd51b8..3af62c305b 100644 --- a/plugins/TabSRMM/src/sendqueue.cpp +++ b/plugins/TabSRMM/src/sendqueue.cpp @@ -107,7 +107,7 @@ entry_found: ::SetDlgItemText(hwndDlg, IDC_SRMM_MESSAGE, L""); ::SetFocus(GetDlgItem(hwndDlg, IDC_SRMM_MESSAGE)); - UpdateSaveAndSendButton(dat); + dat->UpdateSaveAndSendButton(); sendQueued(dat, iFound); return 0; } @@ -365,22 +365,6 @@ void SendQueue::logError(CTabBaseDlg *dat, int iSendJobIndex, const wchar_t *szE } ///////////////////////////////////////////////////////////////////////////////////////// -// enable or disable the sending controls in the given window -// ) input area -// ) multisend contact list instance -// ) send button - -void SendQueue::EnableSending(const CTabBaseDlg *dat, bool bMode) -{ - if (dat) { - HWND hwndDlg = dat->GetHwnd(); - ::SendDlgItemMessage(hwndDlg, IDC_SRMM_MESSAGE, EM_SETREADONLY, !bMode, 0); - Utils::enableDlgControl(hwndDlg, IDC_CLIST, bMode); - dat->EnableSendButton(bMode); - } -} - -///////////////////////////////////////////////////////////////////////////////////////// // show or hide the error control button bar on top of the window void SendQueue::showErrorControls(CTabBaseDlg *dat, const int showCmd) const @@ -408,87 +392,30 @@ void SendQueue::showErrorControls(CTabBaseDlg *dat, const int showCmd) const SendMessage(hwndDlg, WM_SIZE, 0, 0); dat->DM_ScrollToBottom(0, 1); if (m_jobs[0].hContact != 0) - EnableSending(dat, TRUE); + dat->EnableSending(TRUE); } -void SendQueue::recallFailed(const CTabBaseDlg *dat, int iEntry) const +void SendQueue::recallFailed(CTabBaseDlg *dat, int iEntry) const { if (dat == nullptr) return; int iLen = GetWindowTextLength(GetDlgItem(dat->GetHwnd(), IDC_SRMM_MESSAGE)); - NotifyDeliveryFailure(dat); + dat->NotifyDeliveryFailure(); if (iLen != 0) return; // message area is empty, so we can recall the failed message... SETTEXTEX stx = { ST_DEFAULT, CP_UTF8 }; SendDlgItemMessage(dat->GetHwnd(), IDC_SRMM_MESSAGE, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)m_jobs[iEntry].szSendBuffer); - UpdateSaveAndSendButton(const_cast<CTabBaseDlg *>(dat)); - SendDlgItemMessage(dat->GetHwnd(), IDC_SRMM_MESSAGE, EM_SETSEL, (WPARAM)-1, (LPARAM)-1); -} - -void SendQueue::UpdateSaveAndSendButton(CTabBaseDlg *dat) -{ - if (dat) { - HWND hwndDlg = dat->GetHwnd(); - - GETTEXTLENGTHEX gtxl = { 0 }; - gtxl.codepage = CP_UTF8; - gtxl.flags = GTL_DEFAULT | GTL_PRECISE | GTL_NUMBYTES; - - int len = SendDlgItemMessage(hwndDlg, IDC_SRMM_MESSAGE, EM_GETTEXTLENGTHEX, (WPARAM)>xl, 0); - if (len && GetSendButtonState(hwndDlg) == PBS_DISABLED) - dat->EnableSendButton(TRUE); - else if (len == 0 && GetSendButtonState(hwndDlg) != PBS_DISABLED) - dat->EnableSendButton(FALSE); - - if (len) { // looks complex but avoids flickering on the button while typing. - if (!(dat->m_dwFlags & MWF_SAVEBTN_SAV)) { - SendDlgItemMessage(hwndDlg, IDC_SAVE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)PluginConfig.g_buttonBarIcons[ICON_BUTTON_SAVE]); - SendDlgItemMessage(hwndDlg, IDC_SAVE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Save and close session"), BATF_UNICODE); - dat->m_dwFlags |= MWF_SAVEBTN_SAV; - } - } - else { - SendDlgItemMessage(hwndDlg, IDC_SAVE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)PluginConfig.g_buttonBarIcons[ICON_BUTTON_CANCEL]); - SendDlgItemMessage(hwndDlg, IDC_SAVE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Close session"), BATF_UNICODE); - dat->m_dwFlags &= ~MWF_SAVEBTN_SAV; - } - dat->m_textLen = len; - } -} - -void SendQueue::NotifyDeliveryFailure(const CTabBaseDlg *dat) -{ - if (M.GetByte("adv_noErrorPopups", 0)) - return; - - if (CallService(MS_POPUP_QUERY, PUQS_GETSTATUS, 0) != 1) - return; - - POPUPDATAT ppd = { 0 }; - ppd.lchContact = dat->m_hContact; - wcsncpy_s(ppd.lptzContactName, dat->m_cache->getNick(), _TRUNCATE); - wcsncpy_s(ppd.lptzText, TranslateT("A message delivery has failed.\nClick to open the message window."), _TRUNCATE); - - if (!(BOOL)M.GetByte(MODULE, OPT_COLDEFAULT_ERR, TRUE)) { - ppd.colorText = (COLORREF)M.GetDword(MODULE, OPT_COLTEXT_ERR, DEFAULT_COLTEXT); - ppd.colorBack = (COLORREF)M.GetDword(MODULE, OPT_COLBACK_ERR, DEFAULT_COLBACK); - } - else ppd.colorText = ppd.colorBack = 0; - - ppd.PluginWindowProc = Utils::PopupDlgProcError; - ppd.lchIcon = PluginConfig.g_iconErr; - ppd.PluginData = 0; - ppd.iSeconds = (int)M.GetDword(MODULE, OPT_DELAY_ERR, (DWORD)DEFAULT_DELAY); - PUAddPopupT(&ppd); + dat->UpdateSaveAndSendButton(); + SendDlgItemMessage(dat->GetHwnd(), IDC_SRMM_MESSAGE, EM_SETSEL, -1, -1); } ///////////////////////////////////////////////////////////////////////////////////////// // searches string for characters typical for RTL text(hebrew and other RTL languages -int SendQueue::RTL_Detect(const WCHAR *pszwText) +int SendQueue::RTL_Detect(const wchar_t *pszwText) { size_t iLen = mir_wstrlen(pszwText); @@ -666,41 +593,41 @@ int SendQueue::doSendLater(int iJobIndex, CTabBaseDlg *dat, MCONTACT hContact, b return 0; } - if (iJobIndex >= 0 && iJobIndex < NR_SENDJOBS) { - SendJob *job = &m_jobs[iJobIndex]; - char szKeyName[20]; - wchar_t tszHeader[150]; - - if (fIsSendLater) { - time_t now = time(0); - wchar_t tszTimestamp[30]; - wcsftime(tszTimestamp, _countof(tszTimestamp), L"%Y.%m.%d - %H:%M", _localtime32((__time32_t *)&now)); - mir_snprintf(szKeyName, "S%d", now); - mir_snwprintf(tszHeader, TranslateT("\n(Sent delayed. Original timestamp %s)"), tszTimestamp); - } - else mir_snwprintf(tszHeader, L"M%d|", time(0)); + if (iJobIndex < 0 || iJobIndex >= NR_SENDJOBS) + return -1; + + SendJob *job = &m_jobs[iJobIndex]; + char szKeyName[20]; + wchar_t tszHeader[150]; + + if (fIsSendLater) { + time_t now = time(0); + wchar_t tszTimestamp[30]; + wcsftime(tszTimestamp, _countof(tszTimestamp), L"%Y.%m.%d - %H:%M", _localtime32((__time32_t *)&now)); + mir_snprintf(szKeyName, "S%d", now); + mir_snwprintf(tszHeader, TranslateT("\n(Sent delayed. Original timestamp %s)"), tszTimestamp); + } + else mir_snwprintf(tszHeader, L"M%d|", time(0)); - T2Utf utf_header(tszHeader); - size_t required = mir_strlen(utf_header) + mir_strlen(job->szSendBuffer) + 10; - char *tszMsg = reinterpret_cast<char *>(mir_alloc(required)); + T2Utf utf_header(tszHeader); + size_t required = mir_strlen(utf_header) + mir_strlen(job->szSendBuffer) + 10; + char *tszMsg = reinterpret_cast<char *>(mir_alloc(required)); - if (fIsSendLater) { - mir_snprintf(tszMsg, required, "%s%s", job->szSendBuffer, utf_header); - db_set_s(hContact ? hContact : job->hContact, "SendLater", szKeyName, tszMsg); - } - else { - mir_snprintf(tszMsg, required, "%s%s", utf_header, job->szSendBuffer); - sendLater->addJob(tszMsg, hContact); - } - mir_free(tszMsg); + if (fIsSendLater) { + mir_snprintf(tszMsg, required, "%s%s", job->szSendBuffer, utf_header); + db_set_s(hContact ? hContact : job->hContact, "SendLater", szKeyName, tszMsg); + } + else { + mir_snprintf(tszMsg, required, "%s%s", utf_header, job->szSendBuffer); + sendLater->addJob(tszMsg, hContact); + } + mir_free(tszMsg); - if (fIsSendLater) { - int iCount = db_get_dw(hContact ? hContact : job->hContact, "SendLater", "count", 0); - iCount++; - db_set_dw(hContact ? hContact : job->hContact, "SendLater", "count", iCount); - sendLater->addContact(hContact ? hContact : job->hContact); - } - return iJobIndex; + if (fIsSendLater) { + int iCount = db_get_dw(hContact ? hContact : job->hContact, "SendLater", "count", 0); + iCount++; + db_set_dw(hContact ? hContact : job->hContact, "SendLater", "count", iCount); + sendLater->addContact(hContact ? hContact : job->hContact); } - return -1; + return iJobIndex; } diff --git a/plugins/TabSRMM/src/sendqueue.h b/plugins/TabSRMM/src/sendqueue.h index cfd653cb7a..603ced7c2b 100644 --- a/plugins/TabSRMM/src/sendqueue.h +++ b/plugins/TabSRMM/src/sendqueue.h @@ -92,19 +92,14 @@ public: size_t getSendLength(const int iEntry);
void checkQueue(const CTabBaseDlg *dat) const;
void logError(CTabBaseDlg *dat, int iSendJobIndex, const wchar_t *szErrMsg) const;
- void recallFailed(const CTabBaseDlg *dat, int iEntry) const;
+ void recallFailed(CTabBaseDlg *dat, int iEntry) const;
void showErrorControls(CTabBaseDlg *dat, const int showCmd) const;
int ackMessage(CTabBaseDlg *dat, WPARAM wParam, LPARAM lParam);
int doSendLater(int iIndex, CTabBaseDlg *dat, MCONTACT hContact = 0, bool fIsSendLater = true);
- /*
- * static members
- */
+
+ // static members
static int TSAPI RTL_Detect(const wchar_t *pszwText);
- static int TSAPI GetProtoIconFromList(const char *szProto, int iStatus);
static LRESULT TSAPI WarnPendingJobs(unsigned int uNrMessages);
- static void TSAPI NotifyDeliveryFailure(const CTabBaseDlg *dat);
- static void TSAPI UpdateSaveAndSendButton(CTabBaseDlg *dat);
- static void TSAPI EnableSending(const CTabBaseDlg *dat, bool bMode);
private:
SendJob m_jobs[NR_SENDJOBS];
diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp index d9dec206a3..d75ca8664e 100644 --- a/plugins/TabSRMM/src/utils.cpp +++ b/plugins/TabSRMM/src/utils.cpp @@ -346,10 +346,10 @@ char* Utils::FilterEventMarkers(char *szText) return szText;
}
-WCHAR* Utils::FilterEventMarkers(WCHAR *wszText)
+wchar_t* Utils::FilterEventMarkers(wchar_t *wszText)
{
- for (WCHAR *p = wcsstr(wszText, L"~-+"); p != nullptr; p = wcsstr(p, L"~-+")) {
- WCHAR *pEnd = wcsstr(p + 3, L"+-~");
+ for (wchar_t *p = wcsstr(wszText, L"~-+"); p != nullptr; p = wcsstr(p, L"~-+")) {
+ wchar_t *pEnd = wcsstr(p + 3, L"+-~");
if (pEnd == nullptr)
break;
|