diff options
author | George Hazan <ghazan@miranda.im> | 2020-04-07 10:57:14 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-04-07 10:57:14 +0300 |
commit | 85d2893a7392f3b62671d87944398d155224aeba (patch) | |
tree | 05c0c6ca5a158fb2b93016e91b0006b9f8f4b4c5 /plugins/TabSRMM | |
parent | 7e0750197ca5733ce10de616fc6245603f547077 (diff) |
tabSRMM: container creation should be deferred to allow protocols to handle event creation properly
Diffstat (limited to 'plugins/TabSRMM')
-rw-r--r-- | plugins/TabSRMM/src/container.cpp | 74 | ||||
-rw-r--r-- | plugins/TabSRMM/src/functions.h | 1 | ||||
-rw-r--r-- | plugins/TabSRMM/src/hotkeyhandler.cpp | 4 | ||||
-rw-r--r-- | plugins/TabSRMM/src/mim.cpp | 55 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgs.h | 1 |
5 files changed, 83 insertions, 52 deletions
diff --git a/plugins/TabSRMM/src/container.cpp b/plugins/TabSRMM/src/container.cpp index eed9366ed2..3185e9f700 100644 --- a/plugins/TabSRMM/src/container.cpp +++ b/plugins/TabSRMM/src/container.cpp @@ -2225,6 +2225,80 @@ int TSAPI ActivateTabFromHWND(HWND hwndTab, HWND hwnd) /////////////////////////////////////////////////////////////////////////////////////////
+void TSAPI AutoCreateWindow(MCONTACT hContact, MEVENT hDbEvent)
+{
+ wchar_t szName[CONTAINER_NAMELEN + 1];
+ GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN);
+
+ bool bAllowAutoCreate = false;
+ bool bAutoCreate = M.GetBool("autotabs", true);
+ bool bAutoPopup = M.GetBool(SRMSGSET_AUTOPOPUP, SRMSGDEFSET_AUTOPOPUP);
+ bool bAutoContainer = M.GetBool("autocontainer", true);
+
+ DWORD dwStatusMask = M.GetDword("autopopupmask", -1);
+ if (dwStatusMask == -1)
+ bAllowAutoCreate = true;
+ else {
+ char *szProto = Proto_GetBaseAccountName(hContact);
+ if (szProto && !mir_strcmp(szProto, META_PROTO))
+ szProto = Proto_GetBaseAccountName(db_mc_getSrmmSub(hContact));
+
+ if (szProto) {
+ int dwStatus = Proto_GetStatus(szProto);
+ if (dwStatus == 0 || dwStatus <= ID_STATUS_OFFLINE || ((1 << (dwStatus - ID_STATUS_ONLINE)) & dwStatusMask)) // should never happen, but...
+ bAllowAutoCreate = true;
+ }
+ }
+
+ if (bAllowAutoCreate && (bAutoPopup || bAutoCreate)) {
+ if (bAutoPopup) {
+ TContainerData *pContainer = FindContainerByName(szName);
+ if (pContainer == nullptr)
+ pContainer = CreateContainer(szName, 0, hContact);
+ if (pContainer)
+ CreateNewTabForContact(pContainer, hContact, true, true, false);
+ return;
+ }
+
+ bool bPopup = M.GetByte("cpopup", 0) != 0;
+ TContainerData *pContainer = FindContainerByName(szName);
+ if (pContainer != nullptr)
+ if (M.GetByte("limittabs", 0) && !wcsncmp(pContainer->m_wszName, L"default", 6))
+ pContainer = FindMatchingContainer(L"default");
+
+ if (pContainer == nullptr && bAutoContainer)
+ pContainer = CreateContainer(szName, CNT_CREATEFLAG_MINIMIZED, hContact);
+
+ if (pContainer != nullptr)
+ CreateNewTabForContact(pContainer, hContact, false, bPopup, true, hDbEvent);
+ return;
+ }
+
+ // no window created, simply add an unread event to contact list
+ DBEVENTINFO dbei = {};
+ db_event_get(hDbEvent, &dbei);
+
+ if (!(dbei.flags & DBEF_READ)) {
+ AddUnreadContact(hContact);
+
+ wchar_t toolTip[256];
+ mir_snwprintf(toolTip, TranslateT("Message from %s"), Clist_GetContactDisplayName(hContact));
+
+ CLISTEVENT cle = {};
+ cle.hContact = hContact;
+ cle.hDbEvent = hDbEvent;
+ cle.flags = CLEF_UNICODE;
+ cle.hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE);
+ cle.pszService = MS_MSG_READMESSAGE;
+ cle.szTooltip.w = toolTip;
+ g_clistApi.pfnAddEvent(&cle);
+
+ tabSRMM_ShowPopup(hContact, hDbEvent, dbei.eventType, 0, nullptr, nullptr, dbei.szModule);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
HMENU TSAPI BuildContainerMenu()
{
if (PluginConfig.g_hMenuContainer != nullptr) {
diff --git a/plugins/TabSRMM/src/functions.h b/plugins/TabSRMM/src/functions.h index 9f7a4d850d..d2ecbf6a5c 100644 --- a/plugins/TabSRMM/src/functions.h +++ b/plugins/TabSRMM/src/functions.h @@ -70,6 +70,7 @@ int TSAPI GetTabItemFromMouse(HWND hwndTab, POINT *pt); void TSAPI CloseOtherTabs(HWND hwndTab, CMsgDialog &dat);
int TSAPI ActivateTabFromHWND(HWND hwndTab, HWND hwnd);
+void TSAPI AutoCreateWindow(MCONTACT, MEVENT);
void TSAPI CloseAllContainers();
void TSAPI DeleteContainer(int iIndex);
void TSAPI RenameContainer(int iIndex, const wchar_t *newName);
diff --git a/plugins/TabSRMM/src/hotkeyhandler.cpp b/plugins/TabSRMM/src/hotkeyhandler.cpp index c669828673..2cf4330eb0 100644 --- a/plugins/TabSRMM/src/hotkeyhandler.cpp +++ b/plugins/TabSRMM/src/hotkeyhandler.cpp @@ -232,6 +232,10 @@ LONG_PTR CALLBACK HotkeyHandlerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP }
break;
+ case DM_CREATECONTAINER:
+ AutoCreateWindow(wParam, lParam);
+ break;
+
case DM_DOCREATETAB:
{
HWND hWnd = Srmm_FindWindow(lParam);
diff --git a/plugins/TabSRMM/src/mim.cpp b/plugins/TabSRMM/src/mim.cpp index 3b7c5845c6..b7c3b14ee0 100644 --- a/plugins/TabSRMM/src/mim.cpp +++ b/plugins/TabSRMM/src/mim.cpp @@ -391,8 +391,6 @@ int CMimAPI::DispatchNewEvent(WPARAM hContact, LPARAM hDbEvent) int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) { - wchar_t szName[CONTAINER_NAMELEN + 1]; - DBEVENTINFO dbei = {}; db_event_get(hDbEvent, &dbei); @@ -407,11 +405,9 @@ int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) g_clistApi.pfnRemoveEvent(hContact, 1); - bool bAllowAutoCreate = false; bool bAutoPopup = M.GetBool(SRMSGSET_AUTOPOPUP, SRMSGDEFSET_AUTOPOPUP); bool bAutoCreate = M.GetBool("autotabs", true); bool bAutoContainer = M.GetBool("autocontainer", true); - DWORD dwStatusMask = M.GetDword("autopopupmask", -1); if (hwnd) { TContainerData *pTargetContainer = nullptr; @@ -422,6 +418,8 @@ int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) WINDOWPLACEMENT wp = { 0 }; wp.length = sizeof(wp); GetWindowPlacement(pTargetContainer->m_hwnd, &wp); + + wchar_t szName[CONTAINER_NAMELEN + 1]; GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN); if (bAutoPopup || bAutoCreate) { @@ -467,54 +465,7 @@ int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) if (nen_options.iNoAutoPopup) goto nowindowcreate; - GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN); - - if (dwStatusMask == -1) - bAllowAutoCreate = true; - else { - char *szProto = Proto_GetBaseAccountName(hContact); - if (szProto && !mir_strcmp(szProto, META_PROTO)) - szProto = Proto_GetBaseAccountName(db_mc_getSrmmSub(hContact)); - - if (szProto) { - int dwStatus = Proto_GetStatus(szProto); - if (dwStatus == 0 || dwStatus <= ID_STATUS_OFFLINE || ((1 << (dwStatus - ID_STATUS_ONLINE)) & dwStatusMask)) // should never happen, but... - bAllowAutoCreate = true; - } - } - - if (bAllowAutoCreate && (bAutoPopup || bAutoCreate)) { - if (bAutoPopup) { - TContainerData *pContainer = FindContainerByName(szName); - if (pContainer == nullptr) - pContainer = CreateContainer(szName, FALSE, hContact); - if (pContainer) - CreateNewTabForContact(pContainer, hContact, true, true, false); - return 0; - } - - bool bActivate = false, bPopup = M.GetByte("cpopup", 0) != 0; - TContainerData *pContainer = FindContainerByName(szName); - if (pContainer != nullptr) { - if (M.GetByte("limittabs", 0) && !wcsncmp(pContainer->m_wszName, L"default", 6)) { - if ((pContainer = FindMatchingContainer(L"default")) != nullptr) { - CreateNewTabForContact(pContainer, hContact, bActivate, bPopup, true, hDbEvent); - return 0; - } - } - else { - CreateNewTabForContact(pContainer, hContact, bActivate, bPopup, true, hDbEvent); - return 0; - } - } - if (bAutoContainer) { - if ((pContainer = CreateContainer(szName, CNT_CREATEFLAG_MINIMIZED, hContact)) != nullptr) { // 2 means create minimized, don't popup... - CreateNewTabForContact(pContainer, hContact, bActivate, bPopup, true, hDbEvent); - SendMessageW(pContainer->m_hwnd, WM_SIZE, 0, 0); - } - return 0; - } - } + PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_CREATECONTAINER, hContact, hDbEvent); nowindowcreate: // for tray support, we add the event to the tray menu. otherwise we send it back to diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index 886c2f166b..339e4cbd36 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -750,6 +750,7 @@ struct TIconDescW #define DM_UPDATELASTMESSAGE (TM_USER+22)
#define DM_STATUSICONCHANGE (TM_USER+25)
+#define DM_CREATECONTAINER (TM_USER+26)
#define DM_QUERYLASTUNREAD (TM_USER+28)
#define DM_UPDATEPICLAYOUT (TM_USER+30)
#define DM_QUERYCONTAINER (TM_USER+31)
|