Exemple #1
0
INT_PTR SendMessageCommand_W(WPARAM wParam, LPARAM lParam)
{
	HWND hwnd;
	char *szProto;
	struct TNewWindowData newData = {
		0
	};
	struct TContainerData *pContainer = 0;
	int isSplit = 1;

	/*
	 * make sure that only the main UI thread will handle window creation
     */
	if (GetCurrentThreadId() != PluginConfig.dwThreadID) {
		if (lParam) {
			unsigned iLen = lstrlenW((wchar_t *)lParam);
			wchar_t *tszText = (wchar_t *)malloc((iLen + 1) * sizeof(wchar_t));
			wcsncpy(tszText, (wchar_t *)lParam, iLen + 1);
			tszText[iLen] = 0;
			PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SENDMESSAGECOMMANDW, wParam, (LPARAM)tszText);
		} else
			PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SENDMESSAGECOMMANDW, wParam, 0);
		return 0;
	}

	/* does the HCONTACT's protocol support IM messages? */
	szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0);
	if (szProto) {
		if (!CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND)
			return 0;
	} else {
		/* unknown contact */
		return 0;
	}

	if (hwnd = M->FindWindow((HANDLE) wParam)) {
		if (lParam) {
			HWND hEdit;
			hEdit = GetDlgItem(hwnd, IDC_MESSAGE);
			SendMessage(hEdit, EM_SETSEL, -1, SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0));
			SendMessage(hEdit, EM_REPLACESEL, FALSE, (LPARAM)(TCHAR *) lParam);
		}
		SendMessage(hwnd, DM_ACTIVATEME, 0, (LPARAM) 0);
	} else {
		TCHAR szName[CONTAINER_NAMELEN + 1];

		GetContainerNameForContact((HANDLE) wParam, szName, CONTAINER_NAMELEN);
		pContainer = FindContainerByName(szName);
		if (pContainer == NULL)
			pContainer = CreateContainer(szName, FALSE, (HANDLE)wParam);
		CreateNewTabForContact(pContainer, (HANDLE) wParam, 1, (const char *)lParam, TRUE, TRUE, FALSE, 0);
	}
	return 0;
}
Exemple #2
0
INT_PTR SendMessageCommand(WPARAM hContact, LPARAM lParam)
{
	TNewWindowData newData = { 0 };
	int isSplit = 1;

	if (GetCurrentThreadId() != PluginConfig.dwThreadID) {
		if (lParam) {
			unsigned iLen = lstrlenA((char *)lParam);
			char *szText = (char *)mir_alloc(iLen + 1);
			strncpy(szText, (char *)lParam, iLen + 1);
			szText[iLen] = 0;
			PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SENDMESSAGECOMMAND, hContact, (LPARAM)szText);
		} else
			PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SENDMESSAGECOMMAND, hContact, 0);
		return 0;
	}

	/* does the MCONTACT's protocol support IM messages? */
	char *szProto = GetContactProto(hContact);
	if (szProto) {
		if (!CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND)
			return 0;
	} else {
		/* unknown contact */
		return 0;
	}
	
	HWND hwnd = M.FindWindow(hContact);
	if (hwnd) {
		if (lParam) {
			HWND hEdit = GetDlgItem(hwnd, IDC_MESSAGE);
			SendMessage(hEdit, EM_SETSEL, -1, SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0));
			SendMessageA(hEdit, EM_REPLACESEL, FALSE, (LPARAM)(char *) lParam);
		}
		SendMessage(hwnd, DM_ACTIVATEME, 0, 0);          // ask the message window about its parent...
	}
	else {
		TCHAR szName[CONTAINER_NAMELEN + 1];
		GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN);
		TContainerData *pContainer = FindContainerByName(szName);
		if (pContainer == NULL)
			pContainer = CreateContainer(szName, FALSE, hContact);
		if (pContainer)
			CreateNewTabForContact(pContainer, hContact, 0, (const char *) lParam, TRUE, TRUE, FALSE, 0);
	}
	return 0;
}
Exemple #3
0
static INT_PTR ReadMessageCommand(WPARAM, LPARAM lParam)
{
	MCONTACT hContact = ((CLISTEVENT *) lParam)->hContact;

	HWND hwndExisting = M.FindWindow(hContact);
	if (hwndExisting != 0)
		SendMessage(hwndExisting, DM_ACTIVATEME, 0, 0);
	else {
		TCHAR szName[CONTAINER_NAMELEN + 1];
		GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN);
		TContainerData *pContainer = FindContainerByName(szName);
		if (pContainer == NULL)
			pContainer = CreateContainer(szName, FALSE, hContact);
		if (pContainer)
			CreateNewTabForContact(pContainer, hContact, 0, NULL, TRUE, TRUE, FALSE, 0);
	}
	return 0;
}
Exemple #4
0
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);
			PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SENDMESSAGECOMMANDW, hContact, (LPARAM)tszText);
		}
		else PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SENDMESSAGECOMMANDW, hContact, 0);
		return 0;
	}

	// does the MCONTACT's protocol support IM messages?
	char *szProto = GetContactProto(hContact);
	if (szProto == NULL)
		return 0; // unknown contact
	if (!CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND)
		return 0;

	HWND hwnd = M.FindWindow(hContact);
	if (hwnd) {
		if (pszMsg) {
			HWND hEdit = GetDlgItem(hwnd, IDC_MESSAGE);
			SendMessage(hEdit, EM_SETSEL, -1, GetWindowTextLength(hEdit));
			if (isWchar)
				SendMessageW(hEdit, EM_REPLACESEL, FALSE, (LPARAM)pszMsg);
			else
				SendMessageA(hEdit, EM_REPLACESEL, FALSE, (LPARAM)pszMsg);
		}
		SendMessage(hwnd, DM_ACTIVATEME, 0, 0);
	}
	else {
		TCHAR szName[CONTAINER_NAMELEN + 1];
		GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN);

		TContainerData *pContainer = FindContainerByName(szName);
		if (pContainer == NULL)
			pContainer = CreateContainer(szName, FALSE, hContact);
		if (pContainer)
			CreateNewTabForContact(pContainer, hContact, isWchar, pszMsg, TRUE, TRUE, FALSE, 0);
	}
	return 0;
}
Exemple #5
0
void ShowRoom(SESSION_INFO *si, WPARAM wp, BOOL bSetForeground)
{
	if (si == NULL)
		return;

	if (si->hWnd != NULL) {
		ActivateExistingTab(si->pContainer, si->hWnd);
		return;
	}

	TCHAR szName[CONTAINER_NAMELEN + 2]; szName[0] = 0;
	TContainerData *pContainer = si->pContainer;
	if (pContainer == NULL) {
		GetContainerNameForContact(si->hContact, szName, CONTAINER_NAMELEN);
		if (!g_Settings.bOpenInDefault && !_tcscmp(szName, _T("default")))
			_tcsncpy(szName, _T("Chat Rooms"), CONTAINER_NAMELEN);
		szName[CONTAINER_NAMELEN] = 0;
		pContainer = FindContainerByName(szName);
	}
	if (pContainer == NULL)
		pContainer = CreateContainer(szName, FALSE, si->hContact);
	if (pContainer)
		si->hWnd = CreateNewRoom(pContainer, si, TRUE, TRUE, FALSE);
}
Exemple #6
0
int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM lParam)
{
	TCHAR szName[CONTAINER_NAMELEN + 1];

	HANDLE hDbEvent = (HANDLE)lParam;
	DBEVENTINFO dbei = { sizeof(dbei) };
	db_event_get(hDbEvent, &dbei);

	HWND hwnd = M.FindWindow(hContact);
	if (hwnd == NULL)
		hwnd = M.FindWindow(db_event_getContact(hDbEvent));

	BOOL isCustomEvent = IsCustomEvent(dbei.eventType);
	BOOL isShownCustomEvent = DbEventIsForMsgWindow(&dbei);
	if (dbei.markedRead() || (isCustomEvent && !isShownCustomEvent))
		return 0;

	CallServiceSync(MS_CLIST_REMOVEEVENT, hContact, 1);

	bool bAllowAutoCreate = false;
	bool bAutoPopup = M.GetByte(SRMSGSET_AUTOPOPUP, SRMSGDEFSET_AUTOPOPUP) != 0;
	bool bAutoCreate = M.GetByte("autotabs", 1) != 0;
	bool bAutoContainer = M.GetByte("autocontainer", 1) != 0;
	DWORD dwStatusMask = M.GetDword("autopopupmask", -1);

	if (hwnd) {
		TContainerData *pTargetContainer = 0;
		SendMessage(hwnd, DM_QUERYCONTAINER, 0, (LPARAM)&pTargetContainer);
		if (pTargetContainer == NULL || !PluginConfig.m_HideOnClose || IsWindowVisible(pTargetContainer->hwnd))
			return 0;

		WINDOWPLACEMENT wp = { 0 };
		wp.length = sizeof(wp);
		GetWindowPlacement(pTargetContainer->hwnd, &wp);
		GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN);

		if (bAutoPopup || bAutoCreate) {
			if (bAutoPopup) {
				if (wp.showCmd == SW_SHOWMAXIMIZED)
					ShowWindow(pTargetContainer->hwnd, SW_SHOWMAXIMIZED);
				else
					ShowWindow(pTargetContainer->hwnd, SW_SHOWNOACTIVATE);
				return 0;
			}

			TContainerData *pContainer = FindContainerByName(szName);
			if (pContainer != NULL) {
				if (bAutoContainer) {
					ShowWindow(pTargetContainer->hwnd, SW_SHOWMINNOACTIVE);
					return 0;
				}
				goto nowindowcreate;
			}
			else if (bAutoContainer) {
				ShowWindow(pTargetContainer->hwnd, SW_SHOWMINNOACTIVE);
				return 0;
			}
		}
	}
	else {
		switch (dbei.eventType) {
		case EVENTTYPE_AUTHREQUEST:
		case EVENTTYPE_ADDED:
			return 0;

		case EVENTTYPE_FILE:
			tabSRMM_ShowPopup(hContact, hDbEvent, dbei.eventType, 0, 0, 0, dbei.szModule, 0);
			return 0;
		}
	}

	// if no window is open, we are not interested in anything else but unread message events
	// new message 
	if (!nen_options.iNoSounds)
		SkinPlaySound("AlertMsg");

	if (nen_options.iNoAutoPopup)
		goto nowindowcreate;

	GetContainerNameForContact(hContact, szName, CONTAINER_NAMELEN);

	if (dwStatusMask == -1)
		bAllowAutoCreate = true;
	else {
		char *szProto = GetContactProto(hContact);
		if (szProto && !strcmp(szProto, META_PROTO))
			szProto = GetContactProto(db_mc_getSrmmSub(hContact));

		if (szProto) {
			DWORD dwStatus = (DWORD)CallProtoService(szProto, PS_GETSTATUS, 0, 0);
			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 == NULL)
				pContainer = CreateContainer(szName, FALSE, hContact);
			if (pContainer)
				CreateNewTabForContact(pContainer, hContact, 0, NULL, TRUE, TRUE, FALSE, 0);
			return 0;
		}

		bool bActivate = false, bPopup = M.GetByte("cpopup", 0) != 0;
		TContainerData *pContainer = FindContainerByName(szName);
		if (pContainer != NULL) {
			if (M.GetByte("limittabs", 0) && !wcsncmp(pContainer->szName, L"default", 6)) {
				if ((pContainer = FindMatchingContainer(L"default", hContact)) != NULL) {
					CreateNewTabForContact(pContainer, hContact, 0, NULL, bActivate, bPopup, TRUE, hDbEvent);
					return 0;
				}
			}
			else {
				CreateNewTabForContact(pContainer, hContact, 0, NULL, bActivate, bPopup, TRUE, hDbEvent);
				return 0;
			}
		}
		if (bAutoContainer) {
			if ((pContainer = CreateContainer(szName, CNT_CREATEFLAG_MINIMIZED, hContact)) != NULL) { // 2 means create minimized, don't popup...
				CreateNewTabForContact(pContainer, hContact, 0, NULL, bActivate, bPopup, TRUE, hDbEvent);
				SendMessageW(pContainer->hwnd, WM_SIZE, 0, 0);
			}
			return 0;
		}
	}

	// for tray support, we add the event to the tray menu. otherwise we send it back to
	// the contact list for flashing
nowindowcreate:
	if (!(dbei.flags & DBEF_READ)) {
		UpdateTrayMenu(0, 0, dbei.szModule, NULL, hContact, 1);
		if (!nen_options.bTraySupport) {
			TCHAR toolTip[256], *contactName;

			CLISTEVENT cle = { sizeof(cle) };
			cle.hContact = hContact;
			cle.hDbEvent = hDbEvent;
			cle.flags = CLEF_TCHAR;
			cle.hIcon = LoadSkinnedIcon(SKINICON_EVENT_MESSAGE);
			cle.pszService = "SRMsg/ReadMessage";
			contactName = pcli->pfnGetContactDisplayName(hContact, 0);
			mir_sntprintf(toolTip, SIZEOF(toolTip), TranslateT("Message from %s"), contactName);
			cle.ptszTooltip = toolTip;
			CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle);
		}
		tabSRMM_ShowPopup(hContact, hDbEvent, dbei.eventType, 0, 0, 0, dbei.szModule, 0);
	}
	return 0;
}
Exemple #7
0
int CMimAPI::MessageEventAdded(WPARAM wParam, LPARAM lParam)
{
	HWND hwnd;
	CLISTEVENT cle;
	DBEVENTINFO dbei;
	BYTE bAutoPopup = FALSE, bAutoCreate = FALSE, bAutoContainer = FALSE, bAllowAutoCreate = 0;
	struct TContainerData *pContainer = 0;
	TCHAR szName[CONTAINER_NAMELEN + 1];
	DWORD dwStatusMask = 0;
	struct TWindowData *mwdat=NULL;

	ZeroMemory(&dbei, sizeof(dbei));
	dbei.cbSize = sizeof(dbei);
	dbei.cbBlob = 0;
	CallService(MS_DB_EVENT_GET, lParam, (LPARAM) & dbei);

	hwnd = M->FindWindow((HANDLE) wParam);

	if (dbei.flags & DBEF_SENT || !(dbei.eventType == EVENTTYPE_MESSAGE || dbei.eventType == EVENTTYPE_FILE) || dbei.flags & DBEF_READ)
		return 0;

	CallServiceSync(MS_CLIST_REMOVEEVENT, wParam, (LPARAM) 1);
		//MaD: hide on close mod, simulating standard behavior for hidden container
	if (hwnd) {
		struct TContainerData *pTargetContainer = 0;
		WINDOWPLACEMENT wp={0};
		wp.length = sizeof(wp);
		SendMessage(hwnd, DM_QUERYCONTAINER, 0, (LPARAM)&pTargetContainer);

		if(pTargetContainer && PluginConfig.m_HideOnClose && !IsWindowVisible(pTargetContainer->hwnd))	{
			GetWindowPlacement(pTargetContainer->hwnd, &wp);
			GetContainerNameForContact((HANDLE) wParam, szName, CONTAINER_NAMELEN);

			bAutoPopup = M->GetByte(SRMSGSET_AUTOPOPUP, SRMSGDEFSET_AUTOPOPUP);
			bAutoCreate = M->GetByte("autotabs", 1);
			bAutoContainer = M->GetByte("autocontainer", 1);
			dwStatusMask = M->GetDword("autopopupmask", -1);

			bAllowAutoCreate = FALSE;

			if (bAutoPopup || bAutoCreate) {
				BOOL bActivate = TRUE, bPopup = TRUE;
				if(bAutoPopup) {
					if(wp.showCmd == SW_SHOWMAXIMIZED)
						ShowWindow(pTargetContainer->hwnd, SW_SHOWMAXIMIZED);
					else
						ShowWindow(pTargetContainer->hwnd, SW_SHOWNOACTIVATE);
					return 0;
				}
				else {
					bActivate = FALSE;
					bPopup = (BOOL) M->GetByte("cpopup", 0);
					pContainer = FindContainerByName(szName);
					if (pContainer != NULL) {
						if(bAutoContainer) {
							ShowWindow(pTargetContainer->hwnd, SW_SHOWMINNOACTIVE);
							return 0;
						}
						else goto nowindowcreate;
					}
					else {
						if(bAutoContainer) {
							ShowWindow(pTargetContainer->hwnd, SW_SHOWMINNOACTIVE);
							return 0;
						}
					}
				}
			}
		}
		else
			return 0;
	} else {
		if(dbei.eventType == EVENTTYPE_FILE) {
			tabSRMM_ShowPopup(wParam, lParam, dbei.eventType, 0, 0, 0, dbei.szModule, 0);
			return(0);
		}
	}

	/*
	 * if no window is open, we are not interested in anything else but unread message events
	 */

	/* new message */
	if (!nen_options.iNoSounds)
		SkinPlaySound("AlertMsg");

	if (nen_options.iNoAutoPopup)
		goto nowindowcreate;

	GetContainerNameForContact((HANDLE) wParam, szName, CONTAINER_NAMELEN);

	bAutoPopup = M->GetByte(SRMSGSET_AUTOPOPUP, SRMSGDEFSET_AUTOPOPUP);
	bAutoCreate = M->GetByte("autotabs", 1);
	bAutoContainer = M->GetByte("autocontainer", 1);
	dwStatusMask = M->GetDword("autopopupmask", -1);

	bAllowAutoCreate = FALSE;

	if (dwStatusMask == -1)
		bAllowAutoCreate = TRUE;
	else {
		char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)wParam, 0);
		DWORD dwStatus = 0;

		if (PluginConfig.g_MetaContactsAvail && szProto && !strcmp(szProto, (char *)CallService(MS_MC_GETPROTOCOLNAME, 0, 0))) {
			HANDLE hSubconttact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, wParam, 0);

			szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hSubconttact, 0);
		}
		if (szProto) {
			dwStatus = (DWORD)CallProtoService(szProto, PS_GETSTATUS, 0, 0);
			if (dwStatus == 0 || dwStatus <= ID_STATUS_OFFLINE || ((1 << (dwStatus - ID_STATUS_ONLINE)) & dwStatusMask))           // should never happen, but...
				bAllowAutoCreate = TRUE;
		}
	}
	if (bAllowAutoCreate && (bAutoPopup || bAutoCreate)) {
		BOOL bActivate = TRUE, bPopup = TRUE;
		if (bAutoPopup) {
			bActivate = bPopup = TRUE;
			if ((pContainer = FindContainerByName(szName)) == NULL)
				pContainer = CreateContainer(szName, FALSE, (HANDLE)wParam);
			CreateNewTabForContact(pContainer, (HANDLE) wParam, 0, NULL, bActivate, bPopup, FALSE, 0);
			return 0;
		} else {
			bActivate = FALSE;
			bPopup = (BOOL) M->GetByte("cpopup", 0);
			pContainer = FindContainerByName(szName);
			if (pContainer != NULL) {
				//if ((IsIconic(pContainer->hwnd)) && PluginConfig.haveAutoSwitch())
				//	pContainer->dwFlags |= CNT_DEFERREDTABSELECT;
				if (M->GetByte("limittabs", 0) &&  !wcsncmp(pContainer->szName, L"default", 6)) {
					if ((pContainer = FindMatchingContainer(L"default", (HANDLE)wParam)) != NULL) {
						CreateNewTabForContact(pContainer, (HANDLE) wParam, 0, NULL, bActivate, bPopup, TRUE, (HANDLE)lParam);
						return 0;
					} else if (bAutoContainer) {
						pContainer = CreateContainer(szName, CNT_CREATEFLAG_MINIMIZED, (HANDLE)wParam);         // 2 means create minimized, don't popup...
						CreateNewTabForContact(pContainer, (HANDLE) wParam,  0, NULL, bActivate, bPopup, TRUE, (HANDLE)lParam);
						SendMessageW(pContainer->hwnd, WM_SIZE, 0, 0);
						return 0;
					}
				} else {
					CreateNewTabForContact(pContainer, (HANDLE) wParam, 0, NULL, bActivate, bPopup, TRUE, (HANDLE)lParam);
					return 0;
				}

			} else {
				if (bAutoContainer) {
					pContainer = CreateContainer(szName, CNT_CREATEFLAG_MINIMIZED, (HANDLE)wParam);         // 2 means create minimized, don't popup...
					CreateNewTabForContact(pContainer, (HANDLE) wParam,  0, NULL, bActivate, bPopup, TRUE, (HANDLE)lParam);
					SendMessageW(pContainer->hwnd, WM_SIZE, 0, 0);
					return 0;
				}
			}
		}
	}

	/*
	 * for tray support, we add the event to the tray menu. otherwise we send it back to
	 * the contact list for flashing
	 */
nowindowcreate:
	if (!(dbei.flags & DBEF_READ)) {
		UpdateTrayMenu(0, 0, dbei.szModule, NULL, (HANDLE)wParam, 1);
		if (!nen_options.bTraySupport) {
			TCHAR toolTip[256], *contactName;
			ZeroMemory(&cle, sizeof(cle));
			cle.cbSize = sizeof(cle);
			cle.hContact = (HANDLE) wParam;
			cle.hDbEvent = (HANDLE) lParam;
			cle.flags = CLEF_TCHAR;
			cle.hIcon = LoadSkinnedIcon(SKINICON_EVENT_MESSAGE);
			cle.pszService = "SRMsg/ReadMessage";
			contactName = (TCHAR*) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, wParam, GCDNF_TCHAR);
			mir_sntprintf(toolTip, SIZEOF(toolTip), CTranslator::get(CTranslator::GEN_MSG_TTITLE), contactName);
			cle.ptszTooltip = toolTip;
			CallService(MS_CLIST_ADDEVENT, 0, (LPARAM) & cle);
		}
		tabSRMM_ShowPopup(wParam, lParam, dbei.eventType, 0, 0, 0, dbei.szModule, 0);
	}
	return 0;
}