Exemple #1
0
int GetStringFromDatabase(MCONTACT hContact, char *szModule, char *szSettingName, WCHAR *szError, WCHAR *szResult, int count)
{
	DBVARIANT dbv = {0};
	int res = 1;
	int len;
	dbv.type = DBVT_WCHAR;
	if ( db_get_s(hContact, szModule, szSettingName, &dbv, 0) == 0) {
		res = 0;
		if (dbv.type != DBVT_WCHAR)
			MultiByteToWideChar(CP_ACP, 0, dbv.pszVal, -1, szResult, count);
		else {
			int tmp = (int)mir_wstrlen(dbv.pwszVal);
			len = (tmp < count - 1) ? tmp : count - 1;
			wcsncpy(szResult, dbv.pwszVal, len);
			szResult[len] = L'\0';
		}
		mir_free(dbv.pwszVal);
	}
	else {
		res = 1;
		if (szError) {
			int tmp = (int)mir_wstrlen(szError);
			len = (tmp < count - 1) ? tmp : count - 1;
			wcsncpy(szResult, szError, len);
			szResult[len] = L'\0';
		}
		else szResult[0] = L'\0';
	}
	return res;
}
HKL GetLayoutOfText(LPCTSTR ptszInText)
{
	HKL hklCurLay = hklLayouts[0];
	LPTSTR ptszKeybBuff = ptszLayStrings[0];
	DWORD dwMaxSymbols = 0, dwTemp = 0;

	for (DWORD j = 0; j < mir_wstrlen(ptszInText); j++)
		if (wcschr(ptszKeybBuff, ptszInText[j]) != nullptr)
			++dwMaxSymbols;

	for (DWORD i = 1; i < bLayNum; i++) {
		ptszKeybBuff = ptszLayStrings[i];
		DWORD dwCountSymbols = 0;
			
		for (DWORD j = 0; j<mir_wstrlen(ptszInText); j++)
			if (wcschr(ptszKeybBuff, ptszInText[j]) != nullptr)
				++dwCountSymbols;
		
		if (dwCountSymbols == dwMaxSymbols)
			dwTemp = dwCountSymbols;
		else if (dwCountSymbols>dwMaxSymbols) {
			dwMaxSymbols = dwCountSymbols;
			hklCurLay = hklLayouts[i];
		}
	}

	if (dwMaxSymbols == dwTemp)
		hklCurLay = GetKeyboardLayout(0);
	
	return hklCurLay;
}
LPTSTR ChangeTextLayout(LPCTSTR ptszInText, HKL hklCurLay, HKL hklToLay, BOOL TwoWay)
{
	LPTSTR ptszOutText = (LPTSTR)mir_alloc(MaxTextSize*sizeof(wchar_t));
	mir_wstrcpy(ptszOutText, ptszInText);

	if (hklCurLay == nullptr || hklToLay == nullptr)
		return ptszOutText;

	LPTSTR ptszKeybCur = GetLayoutString(hklCurLay);
	LPTSTR ptszKeybNext = GetLayoutString(hklToLay);
	if (ptszKeybCur == nullptr || ptszKeybNext == nullptr)
		return ptszOutText;

	for (DWORD i = 0; i < mir_wstrlen(ptszInText); i++) {
		BOOL Found = FALSE;
		for (DWORD j = 0; j < mir_wstrlen(ptszKeybCur) && !Found; j++)
		if (ptszKeybCur[j] == ptszInText[i]) {
			Found = TRUE;
			if (mir_wstrlen(ptszKeybNext) >= j)
				ptszOutText[i] = ptszKeybNext[j];
		}

		if (TwoWay && !Found)
		for (DWORD j = 0; j < mir_wstrlen(ptszKeybNext) && !Found; j++)
		if (ptszKeybNext[j] == ptszInText[i]) {
			Found = TRUE;
			if (mir_wstrlen(ptszKeybCur) >= j)
				ptszOutText[i] = ptszKeybCur[j];
		}
	}
	return ptszOutText;
}
void RemoveTag(wchar_t *to, wchar_t *tag)
{
	wchar_t *st = to;
	int len = (int)mir_wstrlen(tag);
	int lastsize = (int)mir_wstrlen(to) + 1;
	while (st = wcsstr(st, tag)) {
		lastsize -= len;
		memmove((void*)st, (void*)(st + len), (lastsize)*sizeof(wchar_t));
	}
}
Exemple #5
0
void ShowError(wchar_t *msg) {
	wchar_t buffer[512];
	ErrorDisplay disp = options.err_method;
	// funny logic :) ... try to avoid message boxes
	// if want popups but no popups, try baloons
	if(disp == ED_POP && !options.bHavePopups)
		disp = ED_BAL;

	mir_snwprintf(buffer, L"%s Error", _A2W(MODULENAME));

	wchar_t *message;
	switch (disp) {
	case ED_POP:
		{
			int size = int(mir_wstrlen(msg) + 515);
			message = new wchar_t[size]; // newline and null terminator
			mir_snwprintf(message, size, L"%s\r\n%s", buffer, msg);
			PUShowMessageT(message, SM_WARNING);
			delete[] message;
		}
		break;
	case ED_MB:
		MessageBox(nullptr, msg, buffer, MB_OK | MB_ICONERROR);
		break;
	case ED_BAL:
		Clist_TrayNotifyW(MODULENAME, buffer, msg, NIIF_ERROR, 10000);
		break;
	}
}
bool DeleteDirectory(LPCTSTR lpszDir, bool noRecycleBin = true)
{
	size_t len = mir_wstrlen(lpszDir);
	wchar_t *pszFrom = new wchar_t[len + 2];
	wcscpy_s(pszFrom, len + 2, lpszDir);
	pszFrom[len] = 0;
	pszFrom[len + 1] = 0;

	SHFILEOPSTRUCT fileop;
	fileop.hwnd = nullptr;    // no status display
	fileop.wFunc = FO_DELETE;  // delete operation
	fileop.pFrom = pszFrom;  // source file name as double null terminated string
	fileop.pTo = nullptr;    // no destination needed
	fileop.fFlags = FOF_NOCONFIRMATION | FOF_SILENT;  // do not prompt the user

	if (!noRecycleBin)
		fileop.fFlags |= FOF_ALLOWUNDO;

	fileop.fAnyOperationsAborted = FALSE;
	fileop.lpszProgressTitle = nullptr;
	fileop.hNameMappings = nullptr;

	int ret = SHFileOperation(&fileop);
	delete[] pszFrom;
	return (ret == 0);
}
Exemple #7
0
void RTL_DetectAndSet(ClcContact *contact, MCONTACT hContact)
{
	WORD infoTypeC2[12];
	TCHAR *szText;
	TExtraCache *p;

	memset(infoTypeC2, 0, sizeof(infoTypeC2));

	if (contact == NULL) {
		szText = pcli->pfnGetContactDisplayName(hContact, 0);
		p = cfg::getCache(hContact, NULL);
	}
	else {
		szText = contact->szText;
		p = contact->pExtra;
	}
	if (p) {
		int iLen = min((int)mir_wstrlen(szText), 10);
		GetStringTypeW(CT_CTYPE2, szText, iLen, infoTypeC2);
		p->dwCFlags &= ~ECF_RTLNICK;
		for (int i = 0; i < 10; i++) {
			if (infoTypeC2[i] == C2_RIGHTTOLEFT) {
				p->dwCFlags |= ECF_RTLNICK;
				return;
			}
		}
	}
}
Exemple #8
0
void CSAMWindow::checkFieldLimit(WORD action, WORD item)
{
	BOOL type = (item == IDC_MESSAGE) ? TRUE : FALSE;
	unsigned int limit = type ? EXTRASTATUS_MESSAGE_LIMIT : EXTRASTATUS_TITLE_LIMIT;

	if (action == EN_CHANGE)
	{
		wchar_t* ptszInputText = (wchar_t*)mir_alloc((limit + 8) * sizeof(wchar_t));

		GetDlgItemText(m_handle, item, ptszInputText, limit + 8);

		if (mir_wstrlen(ptszInputText) > limit)
		{
			wchar_t tszPopupTip[MAX_PATH];
			EDITBALLOONTIP ebt = { 0 };
			ebt.cbStruct = sizeof(ebt);
			ebt.pszTitle = TranslateT("Warning");
			mir_snwprintf(tszPopupTip, TranslateT("This field doesn't accept string longer than %d characters. The string will be truncated."), limit);
			ebt.pszText = tszPopupTip;
			ebt.ttiIcon = TTI_WARNING;
			SendDlgItemMessage(m_handle, item, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt);

			wchar_t* ptszOutputText = (wchar_t*)mir_alloc((limit + 1) * sizeof(wchar_t));
			GetDlgItemText(m_handle, item, ptszOutputText, limit + 1);
			SetDlgItemText(m_handle, item, ptszOutputText);
			mir_free(ptszOutputText);
		}
		mir_free(ptszInputText);
	}
}
Exemple #9
0
/*
*	WildCompareW
*	Compare 'name' string with 'mask' strings.
*	Masks can contain '*' or '?' wild symbols
*	Asterics '*' symbol covers 'empty' symbol too e.g WildCompare("Tst","T*st*"), returns TRUE
*	In order to handle situation 'at least one any sybol' use "?*" combination:
*	e.g WildCompare("Tst","T?*st*"), returns FALSE, but both WildCompare("Test","T?*st*") and
*	WildCompare("Teeest","T?*st*") return TRUE.
*
*	Function is case sensitive! so convert input or modify func to use _qtoupper()
*
*	Mask can contain several submasks. In this case each submask (including first)
*	should start from '|' e.g: "|first*submask|second*mask".
*
*	Dec 25, 2006 by FYR:
*	Added Exception to masks: the mask "|^mask3|mask2|mask1" means:
*	if NOT according to mask 3 AND (mask1 OR mask2)
*	EXCEPTION should be BEFORE main mask:
*		IF Exception match - the comparing stops as FALSE
*		IF Exception does not match - comparing continue
*		IF Mask match - comparing stops as TRUE
*		IF Mask does not not match comparing continue
*/
BOOL __fastcall WildCompareW(LPWSTR wszName, LPWSTR wszMask)
{
	if (wszMask == NULL)
		return NULL;

	if (*wszMask != L'|')
		return wildcmpw(wszName, wszMask);

	size_t s = 1, e = 1;
	LPWSTR wszTemp = (LPWSTR)_alloca(mir_wstrlen(wszMask) * sizeof(WCHAR) + sizeof(WCHAR));
	BOOL bExcept;

	while (wszMask[e] != L'\0')
	{
		s = e;
		while (wszMask[e] != L'\0' && wszMask[e] != L'|') e++;

		// exception mask
		bExcept = (*(wszMask + s) == L'^');
		if (bExcept) s++;

		memcpy(wszTemp, wszMask + s, (e - s) * sizeof(WCHAR));
		wszTemp[e - s] = L'\0';

		if (wildcmpw(wszName, wszTemp))
			return !bExcept;

		if (wszMask[e] != L'\0')
			e++;
		else
			return FALSE;
	}
	return FALSE;
}
Exemple #10
0
void ShowPopup(const wchar_t* line1, const wchar_t* line2, int timeout, const MCONTACT hContact) {
	if(Miranda_IsTerminated()) return;

	if ( !options.bHavePopups) {	
		wchar_t title[256];
		mir_snwprintf(title, L"%s Message", _A2W(MODULENAME));

		if(line1 && line2) {
			int size = int(mir_wstrlen(line1) + mir_wstrlen(line2) + 3);
			wchar_t *message = new wchar_t[size]; // newline and null terminator
			mir_snwprintf(message, size, L"%s\r\n%s", line1, line2);
			MessageBox( nullptr, message, title, MB_OK | MB_ICONINFORMATION );
			delete[] message;
		} else if(line1) {
			MessageBox( nullptr, line1, title, MB_OK | MB_ICONINFORMATION );
		} else if(line2) {
			MessageBox( nullptr, line2, title, MB_OK | MB_ICONINFORMATION );
		}
		return;
	}

	POPUPDATAT ppd = {0};
	//memset((void *)&ppd, 0, sizeof(POPUPDATAT));

	ppd.lchContact = hContact;
	ppd.lchIcon = nullptr;

	if(line1 && line2) {
		wcsncpy( ppd.lptzContactName, line1, MAX_CONTACTNAME-1 );
		wcsncpy( ppd.lptzText, line2, MAX_SECONDLINE-1 );
	} else if(line1)
		wcsncpy( ppd.lptzText, line1, MAX_SECONDLINE-1 );
	else if(line2)
		wcsncpy( ppd.lptzText, line2, MAX_SECONDLINE-1 );

	ppd.iSeconds = timeout;

	ppd.PluginWindowProc = nullptr;
	ppd.PluginData = nullptr;

	PUAddPopupT(&ppd);

}
LPTSTR ChangeTextCase(LPCTSTR ptszInText)
{
	LPTSTR ptszOutText = (LPTSTR)mir_alloc(MaxTextSize*sizeof(wchar_t));
	mir_wstrcpy(ptszOutText, ptszInText);

	for (DWORD i = 0; i < mir_wstrlen(ptszInText); i++) {
		CharUpperBuff(&ptszOutText[i], 1);
		if (ptszOutText[i] == ptszInText[i])
			CharLowerBuff(&ptszOutText[i], 1);
	}
	return ptszOutText;
}
Exemple #12
0
static int DrawTextUtf(HDC hDC, char *text, LPRECT lpRect, UINT uFormat, LPSIZE lpSize)
{
	int res;

	WCHAR *tmp = make_unicode_string(text);
	res = DrawTextW(hDC, tmp, -1, lpRect, uFormat);
	if (lpSize)
		GetTextExtentPoint32W(hDC, tmp, (int)mir_wstrlen(tmp), lpSize);
	SAFE_FREE((void**)&tmp);

	return res;
}
Exemple #13
0
void trimW(wchar_t *str) {
    int len = (int)mir_wstrlen(str), pos;
    // trim whitespace (e.g. from OTR detection)
    for (pos = len - 1; pos >= 0; pos--) {
        if (str[pos] == L' ' || str[pos] == L'\t' || str[pos] == L'\r' || str[pos] == L'\n') str[pos] = 0;
        else break;
    }

    // remove tabs
    for (pos = len - 1; pos >= 0; pos--)
        if (str[pos] == L'\t') str[pos] = L' ';
}
BOOL CopyTextToClipboard(LPTSTR ptszText)
{
	if (!OpenClipboard(nullptr))
		return FALSE;

	EmptyClipboard(); 
	HGLOBAL hCopy = GlobalAlloc(GMEM_MOVEABLE, (mir_wstrlen(ptszText) + 1)*sizeof(wchar_t));
	mir_wstrcpy((wchar_t*)GlobalLock(hCopy), ptszText);
	GlobalUnlock(hCopy);
	SetClipboardData(CF_UNICODETEXT, hCopy);
	CloseClipboard();
	return TRUE;
}
static int EventArea_DrawWorker(HWND hWnd, HDC hDC)
{
	RECT rc;
	GetClientRect(hWnd, &rc);

	if (g_CluiData.fDisableSkinEngine)
		sttDrawEventAreaBackground(hWnd, hDC, &rc);
	else
		SkinDrawGlyph(hDC, &rc, &rc, "Main,ID=EventArea");

	HFONT hOldFont = g_clcPainter.ChangeToFont(hDC, nullptr, FONTID_EVENTAREA, nullptr);
	SetBkMode(hDC, TRANSPARENT);

	int iCount = GetMenuItemCount(g_CluiData.hMenuNotify);
	rc.left += 26;
	if (g_CluiData.hUpdateContact != 0) {
		wchar_t *szName = Clist_GetContactDisplayName(g_CluiData.hUpdateContact);
		int iIcon = Clist_GetContactIcon(g_CluiData.hUpdateContact);

		ske_ImageList_DrawEx(g_himlCListClc, iIcon, hDC, rc.left, (rc.bottom + rc.top - GetSystemMetrics(SM_CYSMICON)) / 2, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), CLR_NONE, CLR_NONE, ILD_NORMAL);
		rc.left += 18;
		ske_DrawText(hDC, szName, -1, &rc, DT_VCENTER | DT_SINGLELINE);
		ske_ImageList_DrawEx(g_himlCListClc, (int)g_CluiData.iIconNotify, hDC, 4, (rc.bottom + rc.top - 16) / 2, 16, 16, CLR_NONE, CLR_NONE, ILD_NORMAL);
	}
	else if (iCount > 0) {
		MENUITEMINFO mii = { 0 };
		mii.cbSize = sizeof(mii);
		mii.fMask = MIIM_DATA;
		GetMenuItemInfo(g_CluiData.hMenuNotify, iCount - 1, TRUE, &mii);

		NotifyMenuItemExData *nmi = (struct NotifyMenuItemExData *) mii.dwItemData;
		wchar_t *szName = Clist_GetContactDisplayName(nmi->hContact);
		int iIcon = Clist_GetContactIcon(nmi->hContact);
		ske_ImageList_DrawEx(g_himlCListClc, iIcon, hDC, rc.left, (rc.bottom + rc.top - GetSystemMetrics(SM_CYSMICON)) / 2, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), CLR_NONE, CLR_NONE, ILD_NORMAL);
		rc.left += 18;
		ske_ImageList_DrawEx(g_himlCListClc, nmi->iIcon, hDC, 4, (rc.bottom + rc.top) / 2 - 8, 16, 16, CLR_NONE, CLR_NONE, ILD_NORMAL);
		ske_DrawText(hDC, szName, -1, &rc, DT_VCENTER | DT_SINGLELINE);
	}
	else {
		HICON hIcon = (HICON)LoadImage(g_hMirApp, MAKEINTRESOURCE(IDI_BLANK), IMAGE_ICON, 16, 16, 0);
		wchar_t *ptszEvents = TranslateT("No events");
		ske_DrawText(hDC, ptszEvents, (int)mir_wstrlen(ptszEvents), &rc, DT_VCENTER | DT_SINGLELINE);
		ske_DrawIconEx(hDC, 4, (rc.bottom + rc.top - 16) / 2, hIcon, 16, 16, 0, nullptr, DI_NORMAL | DI_COMPAT);
		DestroyIcon(hIcon);
	}

	ske_ResetTextEffect(hDC);
	SelectObject(hDC, hOldFont);
	return 0;
}
Exemple #16
0
int luaM_toucs2(lua_State *L)
{
	const char* value = luaL_checkstring(L, 1);

	ptrW unicode(mir_utf8decodeW(value));
	size_t length = mir_wstrlen(unicode) * sizeof(wchar_t);

	ptrA string((char*)mir_calloc(length + 1));
	memcpy(string, unicode, length);

	lua_pushlstring(L, string, length + 1);

	return 1;
}
Exemple #17
0
WCHAR* multiReplaceW(const WCHAR *value, const WCHAR *search, const WCHAR *replace, int cs)
{
	int slen = (int)mir_wstrlen(search);
	int rlen = (int)mir_wstrlen(replace);
	int vlen = (int)mir_wstrlen(value);
	int ci = slen ? cs : 1; // on empty string strstr() returns full string while StrStrI() returns NULL 
	// let's try to calculate maximum length for result string
	int newlen = (!slen) ? rlen + 1 : ( ( rlen <= slen ) ? vlen + 1 :  vlen * rlen / slen + 1 );
	
	WCHAR *head;
	WCHAR *in = (WCHAR*)value;
	WCHAR *out = (WCHAR*)mir_alloc(newlen * sizeof(WCHAR));
	out[0] = 0;

	while (head = ci ? wcsstr(in, search) : StrStrIW(in, search)) {
		if (head != in)
			mir_wstrncat(out, in, head - in + 1);
		in = head + slen;
		mir_wstrcat(out, replace);
	}
	
	mir_wstrcat(out, in);
	return out;
}
Exemple #18
0
void CToxOptionsMultimedia::EnumDevices(CCtrlCombo &combo, IMMDeviceEnumerator *pEnumerator, EDataFlow dataFlow, const char* setting)
{
	LPWSTR pwszDefID = NULL;
	ptrW wszDefID(m_proto->getWStringA(setting));
	if (wszDefID != NULL)
	{
		size_t len = mir_wstrlen(wszDefID) + 1;
		pwszDefID = (LPWSTR)CoTaskMemAlloc(len*2);
		mir_wstrncpy(pwszDefID, wszDefID, len);
	}
	else
	{
		CComPtr<IMMDevice> pDevice = NULL;
		if (FAILED(pEnumerator->GetDefaultAudioEndpoint(dataFlow, eConsole, &pDevice))) return;
		if (FAILED(pDevice->GetId(&pwszDefID))) return;
	}

	CComPtr<IMMDeviceCollection> pDevices = NULL;
	EXIT_ON_ERROR(pEnumerator->EnumAudioEndpoints(dataFlow, DEVICE_STATE_ACTIVE, &pDevices));

	UINT count;
	EXIT_ON_ERROR(pDevices->GetCount(&count));

	for (UINT i = 0; i < count; i++)
	{
		CComPtr<IMMDevice> pDevice = NULL;
		EXIT_ON_ERROR(pDevices->Item(i, &pDevice));

		CComPtr<IPropertyStore> pProperties = NULL;
		EXIT_ON_ERROR(pDevice->OpenPropertyStore(STGM_READ, &pProperties));

		PROPVARIANT varName;
		PropVariantInit(&varName);
		EXIT_ON_ERROR(pProperties->GetValue(PKEY_Device_FriendlyName, &varName));

		LPWSTR pwszID = NULL;
		EXIT_ON_ERROR(pDevice->GetId(&pwszID));
		combo.InsertString(varName.pwszVal, i, (LPARAM)mir_wstrdup(pwszID));
		if (mir_wstrcmpi(pwszID, pwszDefID) == 0)
			combo.SetCurSel(i);
		CoTaskMemFree(pwszID);

		PropVariantClear(&varName);
	}

Exit:
	CoTaskMemFree(pwszDefID);
}
void CSmileyString::AddListeningToIcon(ClcData *dat, wchar_t *szText)
{
	iMaxSmileyHeight = 0;
	DestroySmileyList();

	if (szText == nullptr)
		return;

	int text_size = (int)mir_wstrlen(szText);

	plText = List_Create(0, 1);

	// Add Icon
	{
		ClcContactTextPiece *piece = (ClcContactTextPiece *)mir_alloc(sizeof(ClcContactTextPiece));
		piece->type = TEXT_PIECE_TYPE_SMILEY;
		piece->len = 0;
		piece->smiley = g_hListeningToIcon;
		piece->smiley_width = 16;
		piece->smiley_height = 16;

		ICONINFO icon;
		if (GetIconInfo(piece->smiley, &icon)) {
			BITMAP bm;
			if (GetObject(icon.hbmColor, sizeof(BITMAP), &bm)) {
				piece->smiley_width = bm.bmWidth;
				piece->smiley_height = bm.bmHeight;
			}

			DeleteObject(icon.hbmMask);
			DeleteObject(icon.hbmColor);
		}

		dat->text_smiley_height = max(piece->smiley_height, dat->text_smiley_height);
		iMaxSmileyHeight = max(piece->smiley_height, iMaxSmileyHeight);

		List_Insert(plText, piece, plText->realCount);
	}

	// Add text
	{
		ClcContactTextPiece *piece = (ClcContactTextPiece *)mir_alloc(sizeof(ClcContactTextPiece));
		piece->type = TEXT_PIECE_TYPE_TEXT;
		piece->start_pos = 0;
		piece->len = text_size;
		List_Insert(plText, piece, plText->realCount);
	}
}
Exemple #20
0
BOOL CSWindow::itemPassedFilter(ListItem< StatusItem >* li)
{
	wchar_t filter[MAX_PATH];
	GetDlgItemText(m_handle, IDC_FILTER_FIELD, filter, _countof(filter));

	if (mir_wstrlen(filter))
	{
		wchar_t title[EXTRASTATUS_TITLE_LIMIT], message[EXTRASTATUS_MESSAGE_LIMIT];
		mir_wstrcpy(title, li->m_item->m_tszTitle); mir_wstrcpy(message, li->m_item->m_tszMessage);
		if (strpos(wcslwr(title), wcslwr(filter)) == -1)
			if (strpos(wcslwr(message), wcslwr(filter)) == -1)
				return FALSE;
	}

	return TRUE;
}
Exemple #21
0
DWORD WriteStringToFileW(HANDLE File, WCHAR *Source)
{
	DWORD Length, WrittenBytes;
	WCHAR null = (WCHAR)0;

	if ((Source == NULL) || !(Length = (DWORD)mir_wstrlen(Source)))
	{
		if (!WriteFile(File, &null, sizeof(WCHAR), &WrittenBytes, NULL))
		{
			CloseHandle(File);
			return EACC_SYSTEM;
		}
	}
	else if (!WriteFile(File, Source, (Length + 1)*sizeof(WCHAR), &WrittenBytes, NULL))
		return EACC_SYSTEM;
	return 0;
}
Exemple #22
0
void RTL_DetectGroupName(ClcContact *group)
{
	WORD infoTypeC2[12];

	group->isRtl = 0;

	if (group->szText) {
		int iLen = min((int)mir_wstrlen(group->szText), 10);
		GetStringTypeW(CT_CTYPE2, group->szText, iLen, infoTypeC2);
		for (int i = 0; i < 10; i++) {
			if (infoTypeC2[i] == C2_RIGHTTOLEFT) {
				group->isRtl = 1;
				return;
			}
		}
	}
}
Exemple #23
0
int BmpFilterSaveBitmap(HBITMAP hBmp, const wchar_t *ptszFile, int flags)
{
	wchar_t tszFilename[MAX_PATH];
	if (!PathToAbsoluteW(ptszFile, tszFilename))
		wcsncpy_s(tszFilename, ptszFile, _TRUNCATE);

	if (mir_wstrlen(tszFilename) <= 4)
		return -1;

	IMGSRVC_INFO i = { 0 };
	i.cbSize = sizeof(IMGSRVC_INFO);
	i.pwszName = tszFilename;
	i.hbm = hBmp;
	i.dwMask = IMGI_HBITMAP;
	i.fif = FIF_UNKNOWN;
	return !Image_Save(&i, flags);
}
Exemple #24
0
void* IEView::getSelection(IEVIEWEVENT *event)
{
	mir_free(selectedText);
	selectedText = getSelection();
	if (mir_wstrlen(selectedText) == 0)
		return NULL;

	if (event->dwFlags & IEEF_NO_UNICODE) {
		int cp = CP_ACP;
		if (event->cbSize >= IEVIEWEVENT_SIZE_V2)
			cp = event->codepage;

		char *str = mir_t2a_cp(selectedText, cp);
		mir_free(selectedText);
		selectedText = (BSTR)str;
	}
	return (void*)selectedText;
}
Exemple #25
0
int SendQueue::RTL_Detect(const WCHAR *pszwText)
{
	int i, n = 0;
	size_t iLen = mir_wstrlen(pszwText);

	WORD *infoTypeC2 = (WORD*)mir_calloc(sizeof(WORD) * (iLen + 2));
	if (infoTypeC2 == NULL)
		return 0;

	GetStringTypeW(CT_CTYPE2, pszwText, (int)iLen, infoTypeC2);

	for (i = 0; i < iLen; i++)
		if (infoTypeC2[i] == C2_RIGHTTOLEFT)
			n++;

	mir_free(infoTypeC2);
	return(n >= 2 ? 1 : 0);
}
Exemple #26
0
/**
 * name:	CLineBuffer::operator +
 * desc:	appends the specified unicode string to the class's _pVal member
 * param:	wszVal	-	string to add
 *
 * return:	length of the string, added
 **/
size_t CLineBuffer::operator + (const WCHAR *wszVal)
{
	if (wszVal) {
		size_t cbLength = mir_wstrlen(wszVal);
		CHAR* szVal = mir_u2a(wszVal);

		if (szVal) {
			size_t cbLength = mir_strlen(szVal);

			if (_resizeBuf(cbLength)) {
				memcpy(_pVal + _cbUsed, szVal, cbLength);
				_cbUsed += cbLength;
				return	cbLength;
			}
		}
	}
	return 0;
}
Exemple #27
0
void DebugLogW(HANDLE File,const WCHAR *fmt,...)
{
	WCHAR *str;
	char tids[32];
	va_list vararg;
	int strsize;
	DWORD Written;

	va_start(vararg,fmt);
	str=(WCHAR *)malloc((strsize=65536)*sizeof(WCHAR));
	mir_snprintf(tids, "[%x]",GetCurrentThreadId());
	while(mir_vsnwprintf(str, strsize, fmt, vararg)==-1)
		str=(WCHAR *)realloc(str,(strsize+=65536)*sizeof(WCHAR));
	va_end(vararg);
	EnterCriticalSection(&FileAccessCS);
	WriteFile(File,tids,(DWORD)mir_strlen(tids),&Written,NULL);
	WriteFile(File,str,(DWORD)mir_wstrlen(str)*sizeof(WCHAR),&Written,NULL);
	LeaveCriticalSection(&FileAccessCS);
	free(str);
}
LPTSTR GeTStringFromStreamData(EditStreamData *esd)
{
	DWORD i, k;

	LPTSTR ptszOutText = (LPTSTR)mir_alloc(MaxTextSize*sizeof(wchar_t));
	LPTSTR ptszTemp = (wchar_t*)esd->pbBuff;
	
	for (i = k = 0; i < mir_wstrlen(ptszTemp); i++) {
		if ((ptszTemp[i] == 0x0A) || (ptszTemp[i] == 0x2028))
			ptszOutText[k++] = 0x0D;
		else if (ptszTemp[i] == 0x0D) {
			ptszOutText[k++] = 0x0D;
			if (ptszTemp[i + 1] == 0x0A) i++;
		}
		else ptszOutText[k++] = ptszTemp[i];
	}

	ptszOutText[k] = 0;
	return ptszOutText;
}
LPTSTR GenerateLayoutString(HKL hklLayout)
{
	BYTE bState[256] = {0};

	LPTSTR ptszLayStr = (LPTSTR)mir_alloc(100 * sizeof(wchar_t));
	LPTSTR ptszTemp = (LPTSTR)mir_alloc(3 * sizeof(wchar_t));
	ptszTemp[0] = 0;

	DWORD i;
	for (i = 0; i < mir_wstrlen(ptszKeybEng); i++) {
		SHORT shVirtualKey = VkKeyScanEx(ptszKeybEng[i], hklEng);
		UINT iScanCode = MapVirtualKeyEx(shVirtualKey & 0x00FF, 0, hklEng);

		for (DWORD j = 0; j < 256; j++)
			bState[j] = 0;

		if (shVirtualKey & 0x0100) bState[VK_SHIFT] = 0x80;
		if (shVirtualKey & 0x0200) bState[VK_CONTROL] = 0x80;
		if (shVirtualKey & 0x0400) bState[VK_MENU] = 0x80;

		shVirtualKey = MapVirtualKeyEx(iScanCode, 1, hklLayout);
		bState[shVirtualKey & 0x00FF] = 0x80;

		int iRes = ToUnicodeEx(shVirtualKey, iScanCode, bState, ptszTemp, 3, 0, hklLayout);
		// Защита от дэд-кеев
		if (iRes < 0)
			ToUnicodeEx(shVirtualKey, iScanCode, bState, ptszTemp, 3, 0, hklLayout);

		// Если нам вернули нулевой символ, или не вернули ничего, то присвоим "звоночек"
		if (ptszTemp[0] == 0)
			ptszLayStr[i] = 3;
		else
			ptszLayStr[i] = ptszTemp[0];
	}
	ptszLayStr[i] = 0;

	mir_free(ptszTemp);
	return ptszLayStr;
}
Exemple #30
0
static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
	switch(msg)  {
	case WM_CHAR:
		if (wParam == 1 && GetKeyState(VK_CONTROL) & 0x8000) 
		{	// ctrl-a
			SendMessage(hwnd, EM_SETSEL, 0, -1);
			return 0;
		}

		if (wParam == 26 && GetKeyState(VK_CONTROL) & 0x8000) 
		{	// ctrl-z
			SendMessage(hwnd, EM_UNDO, 0, 0);
			return 0;
		}

		if (wParam == 127 && GetKeyState(VK_CONTROL) & 0x8000) 
		{	// ctrl-backspace
			DWORD start, end;
			WCHAR text[1024];

			SendMessage(hwnd, EM_GETSEL, (WPARAM) & end, (LPARAM) (PDWORD) NULL);
			SendMessage(hwnd, WM_KEYDOWN, VK_LEFT, 0);
			SendMessage(hwnd, EM_GETSEL, (WPARAM) & start, (LPARAM) (PDWORD) NULL);
			GetWindowText(hwnd, text, _countof(text));
			memmove(text + start, text + end, sizeof(WCHAR) * (mir_wstrlen(text) + 1 - end));
			SetWindowText(hwnd, text);
			SendMessage(hwnd, EM_SETSEL, start, start);
			SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hwnd), EN_CHANGE), (LPARAM) hwnd);
			return 0;
		}
		break;
	}

	return mir_callNextSubclass(hwnd, MessageEditSubclassProc, msg, wParam, lParam);
}