Ejemplo n.º 1
0
TCHAR* DoRtfToTags(char *pszText, SESSION_INFO *si)
{
	if (!pszText)
		return FALSE;

	// create an index of colors in the module and map them to
	// corresponding colors in the RTF color table
	MODULEINFO *mi = pci->MM_FindModule(si->pszModule);
	int *pIndex = (int *)mir_alloc(sizeof(int)*mi->nColorCount);
	for (int i = 0; i < mi->nColorCount; i++)
		pIndex[i] = -1;

	CreateColorMap(pszText, pIndex, si);

	// scan the file for rtf commands and remove or parse them
	char *p1 = strstr(pszText, "\\pard");
	if (p1 == NULL) {
		mir_free(pIndex);
		return FALSE;
	}

	p1 += 5;

	memmove(pszText, p1, mir_strlen(p1) + 1);
	p1 = pszText;

	// iterate through all characters, if rtf control character found then take action
	BOOL bJustRemovedRTF = TRUE;
	BOOL bTextHasStarted = FALSE;
	char InsertThis[50];

	while (*p1 != '\0') {
		InsertThis[0] = 0;
		int iRemoveChars = 0;

		switch (*p1) {
		case '\\':
			if (!memcmp(p1, "\\cf", 3)) { // foreground color
				int iCol;
				iRemoveChars = 3 + ReadInteger(p1 + 3, &iCol);
				bJustRemovedRTF = TRUE;

				// int iInd = RTFColorToIndex(pIndex, iCol, si);
				// if (bTextHasStarted || iInd >= 0)
				//		mir_snprintf(InsertThis, SIZEOF(InsertThis), (iInd >= 0) ? "%%c%02u" : "%%C", iInd);
			}
			else if (!memcmp(p1, "\\highlight", 10)) { //background color
				int iCol;
				iRemoveChars = 10 + ReadInteger(p1 + 10, &iCol);
				bJustRemovedRTF = TRUE;

				// int iInd = RTFColorToIndex(pIndex, iCol, si);
				// if (bTextHasStarted || iInd >= 0)
				//		mir_snprintf(InsertThis, SIZEOF(InsertThis), (iInd >= 0) ? "%%f%02u" : "%%F", iInd);
			}
			else if (!memcmp(p1, "\\lang", 5)) { // language id
				bTextHasStarted = bJustRemovedRTF = TRUE;
				iRemoveChars = 5 + ReadInteger(p1 + 5, NULL);
			}
			else if (!memcmp(p1, "\\par", 4)) { // newline
				bTextHasStarted = bJustRemovedRTF = TRUE;
				iRemoveChars = 4;
				strcpy(InsertThis, "\n");
			}
			else if (!memcmp(p1, "\\line", 5)) { // newline
				bTextHasStarted = bJustRemovedRTF = TRUE;
				iRemoveChars = 5;
				strcpy(InsertThis, "\n");
			}
			else if (!memcmp(p1, "\\bullet", 7)) {
				bTextHasStarted = TRUE;
				bJustRemovedRTF = TRUE;
				iRemoveChars = 7;
				strcpy(InsertThis, "\xE2\x80\xA2");
			}
			else if (!memcmp(p1, "\\b", 2)) { //bold
				bTextHasStarted = bJustRemovedRTF = TRUE;
				iRemoveChars = (p1[2] != '0') ? 2 : 3;
				mir_snprintf(InsertThis, SIZEOF(InsertThis), (p1[2] != '0') ? "%%b" : "%%B");
			}
			else if (!memcmp(p1, "\\i", 2)) { // italics
				bTextHasStarted = bJustRemovedRTF = TRUE;
				iRemoveChars = (p1[2] != '0') ? 2 : 3;
				mir_snprintf(InsertThis, SIZEOF(InsertThis), (p1[2] != '0') ? "%%i" : "%%I");
			}
			else if (!memcmp(p1, "\\uc", 3)) { // number of Unicode chars
				bTextHasStarted = bJustRemovedRTF = TRUE;
				iRemoveChars = 4;
			}
			else if (!memcmp(p1, "\\ul", 3)) { // underlined
				bTextHasStarted = bJustRemovedRTF = TRUE;
				if (p1[3] == 'n')
					iRemoveChars = 7;
				else if (p1[3] == '0')
					iRemoveChars = 4;
				else
					iRemoveChars = 3;
				mir_snprintf(InsertThis, SIZEOF(InsertThis), (p1[3] != '0' && p1[3] != 'n') ? "%%u" : "%%U");
			}
			else if (p1[1] == 'f' && isdigit(p1[2])) { // unicode char
				bTextHasStarted = bJustRemovedRTF = TRUE;
				iRemoveChars = 2 + ReadInteger(p1 + 2, NULL);
			}
			else if (!memcmp(p1, "\\tab", 4)) { // tab
				bTextHasStarted = TRUE;
				bJustRemovedRTF = TRUE;
				iRemoveChars = 4;
				strcpy(InsertThis, " ");
			}
			else if (!memcmp(p1, "\\endash", 7)) {
				bTextHasStarted = TRUE;
				bJustRemovedRTF = TRUE;
				iRemoveChars = 7;
				strcpy(InsertThis, "\xE2\x80\x93");
			}
			else if (!memcmp(p1, "\\emdash", 7)) {
				bTextHasStarted = TRUE;
				bJustRemovedRTF = TRUE;
				iRemoveChars = 7;
				strcpy(InsertThis, "\xE2\x80\x94");
			}
			else if (!memcmp(p1, "\\lquote", 7)) {
				bTextHasStarted = TRUE;
				bJustRemovedRTF = TRUE;
				iRemoveChars = 7;
				strcpy(InsertThis, "\xE2\x80\x98");
			}
			else if (!memcmp(p1, "\\rquote", 7)) {
				bTextHasStarted = TRUE;
				bJustRemovedRTF = TRUE;
				iRemoveChars = 7;
				strcpy(InsertThis, "\xE2\x80\x99");
			}
			else if (!memcmp(p1, "\\ldblquote", 10)) {
				bTextHasStarted = TRUE;
				bJustRemovedRTF = TRUE;
				iRemoveChars = 10;
				strcpy(InsertThis, "\xe2\x80\x9c");
			}
			else if (!memcmp(p1, "\\rdblquote", 10)) {
				bTextHasStarted = TRUE;
				bJustRemovedRTF = TRUE;
				iRemoveChars = 10;
				strcpy(InsertThis, "\xe2\x80\x9d");
			}
			else if (p1[1] == '\\' || p1[1] == '{' || p1[1] == '}') { // escaped characters
				bTextHasStarted = TRUE;
				bJustRemovedRTF = FALSE;
				iRemoveChars = 2;
				mir_snprintf(InsertThis, SIZEOF(InsertThis), "%c", p1[1]);
			}
			else if (p1[1] == '~') { // non-breaking space
				bTextHasStarted = TRUE;
				bJustRemovedRTF = FALSE;
				iRemoveChars = 2;
				strcpy(InsertThis, "\xC2\xA0");
			}
			else if (p1[1] == '\'') { // special character
				char tmp[4], *p3 = tmp;
				bTextHasStarted = TRUE;
				bJustRemovedRTF = FALSE;
				if (p1[2] != ' ' && p1[2] != '\\') {
					*p3++ = p1[2];
					iRemoveChars = 3;
					if (p1[3] != ' ' && p1[3] != '\\') {
						*p3++ = p1[3];
						iRemoveChars++;
					}
					*p3 = 0;
					sscanf(tmp, "%x", InsertThis);
					InsertThis[1] = 0;
				}
				else iRemoveChars = 2;
			}
			else if (bJustRemovedRTF) { // remove unknown RTF command
				int j = 1;
				bJustRemovedRTF = TRUE;
				while (p1[j] != ' ' && p1[j] != '\\' && p1[j] != '\0')
					j++;
				iRemoveChars = j;
			}
			break;

		case '{': // other RTF control characters
		case '}':
			iRemoveChars = 1;
			break;

		case '\r': case '\n':
			bTextHasStarted = TRUE;
			bJustRemovedRTF = FALSE;
			iRemoveChars = 1;
			break;

		case '%': // escape chat -> protocol control character
			bTextHasStarted = TRUE;
			bJustRemovedRTF = FALSE;
			iRemoveChars = 1;
			mir_snprintf(InsertThis, SIZEOF(InsertThis), "%%%%");
			break;
		case ' ': // remove spaces following a RTF command
			if (bJustRemovedRTF)
				iRemoveChars = 1;
			bJustRemovedRTF = FALSE;
			bTextHasStarted = TRUE;
			break;

		default: // other text that should not be touched
			bTextHasStarted = TRUE;
			bJustRemovedRTF = FALSE;
			break;
		}

		// move the memory and paste in new commands instead of the old RTF
		if (InsertThis[0] || iRemoveChars) {
			memmove(p1 + mir_strlen(InsertThis), p1 + iRemoveChars, mir_strlen(p1) - iRemoveChars + 1);
			memcpy(p1, InsertThis, mir_strlen(InsertThis));
			p1 += mir_strlen(InsertThis);
		}
		else p1++;
	}

	mir_free(pIndex);
	return mir_utf8decodeT(pszText);
}
Ejemplo n.º 2
0
void exportModule(HANDLE hContact, char* module, FILE* file)
{
	char tmp[32];
	ModuleSettingLL settinglist;
	struct ModSetLinkLinkItem *setting;

	EnumSettings(hContact,module,&settinglist);

	// print the module header..
	fprintf(file, "\n[%s]", module);
	setting = settinglist.first;
	while(setting)
	{
		DBVARIANT dbv;
		if (!GetSetting(hContact, module, setting->name, &dbv))
		{
			switch (dbv.type)
			{
				case DBVT_BYTE:
					fprintf(file, "\n%s=b%s", setting->name, itoa(dbv.bVal,tmp,10));
					DBFreeVariant(&dbv);
					break;
				case DBVT_WORD:
					fprintf(file, "\n%s=w%s", setting->name, itoa(dbv.wVal,tmp,10));
					DBFreeVariant(&dbv);
					break;
				case DBVT_DWORD:
					fprintf(file, "\n%s=d%s", setting->name, itoa(dbv.dVal,tmp,10));
					DBFreeVariant(&dbv);
					break;
				case DBVT_ASCIIZ:
				case DBVT_UTF8:
						if (strchr(dbv.pszVal, '\r'))
						{
							char *end = StrReplace("\\", "\\\\", dbv.pszVal);
							end = StrReplace("\r", "\\r", end);
							end = StrReplace("\n", "\\n", end);
							fprintf(file, "\n%s=g%s", setting->name, end);
							break;
						}
						if (dbv.type == DBVT_UTF8)
							fprintf(file, "\n%s=u%s", setting->name, dbv.pszVal);
						else
							fprintf(file, "\n%s=s%s", setting->name, dbv.pszVal);
						DBFreeVariant(&dbv);
						break;
				case DBVT_BLOB:
				{
					int j;
					char *data = NULL;
					if (!(data = (char*)mir_alloc( 3*(dbv.cpbVal+1)*sizeof(char)) ))
						break;
					data[0] = '\0';
					for (j=0; j<dbv.cpbVal; j++)
					{
						char tmp[16];
						mir_snprintf(tmp, SIZEOF(tmp), "%02X ", (BYTE)dbv.pbVal[j]);
						strcat(data, tmp);
					}
					fprintf(file,"\n%s=n%s",setting->name , data);
					mir_free(data);
				}
				DBFreeVariant(&dbv);
				break;
			}
		}
		setting = (struct ModSetLinkLinkItem *)setting->next;
	}
	FreeModuleSettingLL(&settinglist);
}
Ejemplo n.º 3
0
bool CMsnProto::MSN_StoreCreateDocument(const TCHAR *sztName, const char *szMimeType, const char *szPicData, bool allowRecurse)
{
    char* reqHdr;
    ezxml_t tbdy;
    char* szName = mir_utf8encodeT(sztName);
    ezxml_t xmlp = storeSoapHdr("CreateDocument", "RoamingIdentityChanged", tbdy, reqHdr);

    ezxml_t hndl = ezxml_add_child(tbdy, "parentHandle", 0);
    ezxml_t node = ezxml_add_child(hndl, "RelationshipName", 0);
    ezxml_set_txt(node, "/UserTiles");

    ezxml_t alias = ezxml_add_child(hndl, "Alias", 0);
    node = ezxml_add_child(alias, "Name", 0);
    ezxml_set_txt(node, mycid);
    node = ezxml_add_child(alias, "NameSpace", 0);
    ezxml_set_txt(node, "MyCidStuff");

    ezxml_t doc = ezxml_add_child(tbdy, "document", 0);
    ezxml_set_attr(doc, "xsi:type", "Photo");
    node = ezxml_add_child(doc, "Name", 0);
    ezxml_set_txt(node, szName);

    doc = ezxml_add_child(doc, "DocumentStreams", 0);
    doc = ezxml_add_child(doc, "DocumentStream", 0);
    ezxml_set_attr(doc, "xsi:type", "PhotoStream");
    node = ezxml_add_child(doc, "DocumentStreamType", 0);

    ezxml_set_txt(node, "UserTileStatic");
    node = ezxml_add_child(doc, "MimeType", 0);
    ezxml_set_txt(node, szMimeType);
    node = ezxml_add_child(doc, "Data", 0);
    ezxml_set_txt(node, szPicData);
    node = ezxml_add_child(doc, "DataSize", 0);
    ezxml_set_txt(node, "0");

    node = ezxml_add_child(tbdy, "relationshipName", 0);
    ezxml_set_txt(node, "Messenger User Tile");

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);
    mir_free(szName);

    unsigned status = 0;
    char *storeUrl = NULL, *tResult = NULL;

    for (int k = 4; --k;)
    {
        mir_free(storeUrl);
        storeUrl = GetStoreHost("CreateDocument");
        tResult = getSslResult(&storeUrl, szData, reqHdr, status);
        if (tResult == NULL) UpdateStoreHost("CreateDocument", NULL);
        else break;
    }

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL)
    {
        UpdateStoreHost("CreateDocument", storeUrl);
        if (status == 200)
        {
            ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult));
            ezxml_t bdy = getSoapResponse(xmlm, "CreateDocument");
            mir_snprintf(photoid, sizeof(photoid), "%s", ezxml_txt(bdy));
            ezxml_free(xmlm);
        }
        else if (status == 500)
        {
            ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult));
            const char* szErr = ezxml_txt(getSoapFault(xmlm, true));
            if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse)
            {
                MSN_GetPassportAuth();
                status = MSN_StoreCreateDocument(sztName, szMimeType, szPicData, false) ? 200 : 500;
            }
            ezxml_free(xmlm);
        }
    }

    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Ejemplo n.º 4
0
void InitFonts() {
	// Fonts
	FontIDT fid = {0};
	fid.cbSize = sizeof(FontIDT);
	lstrcpyn(fid.group, _T(PU_FNT_AND_COLOR), SIZEOF(fid.group));
	strncpy(fid.dbSettingsGroup, PU_FNT_AND_COLOR_DB, SIZEOF(fid.dbSettingsGroup));
	fid.flags = FIDF_DEFAULTVALID;
	fid.deffontsettings.charset = DEFAULT_CHARSET;
	fid.deffontsettings.size = -11;
	lstrcpyn(fid.backgroundGroup, _T(PU_FNT_AND_COLOR), SIZEOF(fid.backgroundGroup));
	lstrcpyn(fid.backgroundName, PU_COL_BACK_NAME, SIZEOF(fid.backgroundName));
	lstrcpyn(fid.deffontsettings.szFace, _T("Tahoma"), SIZEOF(fid.deffontsettings.szFace));

	lstrcpyn(fid.name, _T(PU_FNT_NAME_TITLE), SIZEOF(fid.name));
	mir_snprintf(fid.prefix, sizeof(fid.prefix), PU_FNT_PREFIX, PU_FNT_NAME_TITLE);
	fid.deffontsettings.style  = DBFONTF_BOLD;
	fid.deffontsettings.colour = RGB(0, 0, 0);
	FontRegisterT(&fid);

	lstrcpyn(fid.name, _T(PU_FNT_NAME_CLOCK), SIZEOF(fid.name));
	mir_snprintf(fid.prefix, sizeof(fid.prefix), PU_FNT_PREFIX, PU_FNT_NAME_CLOCK);
	//fid.deffontsettings.style  = DBFONTF_BOLD;
	//fid.deffontsettings.colour = RGB(0, 0, 0);
	FontRegisterT(&fid);

	lstrcpyn(fid.name, _T(PU_FNT_NAME_TEXT), SIZEOF(fid.name));
	mir_snprintf(fid.prefix, sizeof(fid.prefix), PU_FNT_PREFIX, PU_FNT_NAME_TEXT);
	fid.deffontsettings.style  = 0;
	//fid.deffontsettings.colour = RGB(0, 0, 0);
	FontRegisterT(&fid);

	lstrcpyn(fid.name, _T(PU_FNT_NAME_ACTION), SIZEOF(fid.name));
	mir_snprintf(fid.prefix, sizeof(fid.prefix), PU_FNT_PREFIX, PU_FNT_NAME_ACTION);
	fid.flags = FIDF_DEFAULTVALID | FIDF_ALLOWEFFECTS;
	//fid.deffontsettings.style = 0;
	fid.deffontsettings.colour = RGB(0, 0, 255);
	FontRegisterT(&fid);

	lstrcpyn(fid.name, _T(PU_FNT_NAME_HOVERED_ACTION), SIZEOF(fid.name));
	mir_snprintf(fid.prefix, sizeof(fid.prefix), PU_FNT_PREFIX, PU_FNT_NAME_HOVERED_ACTION);
	fid.deffontsettings.style = DBFONTF_UNDERLINE;
	//fid.deffontsettings.colour = RGB(0, 0, 255);
	FontRegisterT(&fid);

	ColourIDT cid = {0};
	cid.cbSize = sizeof(ColourIDT);
	lstrcpyn(cid.group, _T(PU_FNT_AND_COLOR), SIZEOF(cid.group));
	strncpy(cid.dbSettingsGroup, PU_FNT_AND_COLOR_DB, SIZEOF(cid.dbSettingsGroup));

	lstrcpyn(cid.name, PU_COL_BACK_NAME, SIZEOF(cid.name));
	strncpy(cid.setting, PU_COL_BACK_SETTING, SIZEOF(cid.setting));
	cid.defcolour = SETTING_BACKCOLOUR_DEFAULT;
	ColourRegisterT(&cid);

	lstrcpyn(cid.name, PU_COL_AVAT_NAME, SIZEOF(cid.name));
	strncpy(cid.setting, PU_COL_AVAT_SETTING, SIZEOF(cid.setting));
	cid.defcolour = SETTING_TEXTCOLOUR_DEFAULT;
	ColourRegisterT(&cid);

	ReloadFonts();
}
Ejemplo n.º 5
0
static TCHAR *sttGetActiveSkin(MODERNOPTOBJECT *obj)
{
	char svc[128];
	mir_snprintf(svc, SIZEOF(svc), "%s%s", obj->lpzThemeModuleName, TS_SKIN_ACTIVE);
	return ServiceExists(svc) ? (TCHAR *)CallService(svc, 0, 0) : 0;
}
Ejemplo n.º 6
0
void PopupWnd2::show()
{
	if ((m_options->UseEffect || (m_options->UseAnimations && !m_customPopup)) && m_options->FadeIn) {
		IPopupPlusEffect *effect = NULL;
		m_bSlide = m_bFade = false;
		DWORD dwTime, dwTime0 = GetTickCount();
		DWORD dwTime1 = dwTime0 + m_options->FadeIn;
		if (m_options->UseEffect) {
			m_bFade = true;
			m_btAlpha0 = 0;
			m_btAlpha1 = m_options->UseTransparency ? m_options->Alpha : 255;
			updateLayered(m_btAlpha0);

			if (*PopupOptions.Effect) {
				char vfxService[128];
				mir_snprintf(vfxService, "Popup/Vfx/%S", PopupOptions.Effect);
				if (ServiceExists(vfxService))
					if (effect = (IPopupPlusEffect *)CallService(vfxService, 0, 0)) {
						effect->beginEffect(m_bmp->getWidth(), m_bmp->getHeight(), m_btAlpha0, m_btAlpha1, dwTime1 - dwTime0);
						m_bmpAnimate = new MyBitmap(m_bmp->getWidth(), m_bmp->getHeight());
					}
			}
		}
		else {
			updateLayered(m_options->UseTransparency ? m_options->Alpha : 255);
		}
		if (m_options->UseAnimations && !m_customPopup) {
			m_bSlide = true;
			m_ptPosition0 = m_pos;
			m_ptPosition1 = m_pos;
			if (m_options->Position == POS_LOWERLEFT || m_options->Position == POS_UPPERLEFT)
				m_ptPosition0.x -= m_sz.cx + 2 * 5;
			else
				m_ptPosition0.x += m_sz.cx + 2 * 5;
			SetWindowPos(m_hwnd, 0, m_ptPosition0.x, m_ptPosition0.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
		}
		else {
			SetWindowPos(m_hwnd, 0, m_pos.x, m_pos.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
		}
		while ((dwTime = GetTickCount()) < dwTime1) {
			if (m_bFade) {
				if (effect) {
					effect->beginFrame(dwTime - dwTime0);
					m_bmpAnimate->Draw(m_bmp, 0, 0, m_bmp->getWidth(), m_bmp->getHeight());
					for (int row = 0; row < m_bmpAnimate->getHeight(); ++row) {
						unsigned char *pixel = (unsigned char *)m_bmpAnimate->getRow(row);
						for (int col = 0; col < m_bmpAnimate->getWidth(); ++col) {
							WORD alphaLevel = effect->getPixelAlpha(col, row);
							pixel[0] = (pixel[0] * alphaLevel) >> 8;
							pixel[1] = (pixel[1] * alphaLevel) >> 8;
							pixel[2] = (pixel[2] * alphaLevel) >> 8;
							pixel[3] = (pixel[3] * alphaLevel) >> 8;
							pixel += 4;
						}
					}
					effect->endFrame();
					updateLayered(255);
				}
				else {
					updateLayered(m_btAlpha0 + (m_btAlpha1 - m_btAlpha0) * int(dwTime - dwTime0) / m_options->FadeIn);
				}
			}
			if (m_bSlide)
				SetWindowPos(m_hwnd, 0,
					(int)m_ptPosition0.x + ((int)m_ptPosition1.x - (int)m_ptPosition0.x) * int(dwTime - dwTime0) / (int)m_options->FadeIn,
					(int)m_ptPosition0.y + ((int)m_ptPosition1.y - (int)m_ptPosition0.y) * int(dwTime - dwTime0) / (int)m_options->FadeIn,
					0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
			UpdateWindow(m_hwnd);
			Sleep(1);
		}
Ejemplo n.º 7
0
char* ApendSubSetting(char * buf, int size, char *first, char *second)
{
	mir_snprintf(buf, size, "%sFont%s", first, second);
	return buf;
}
Ejemplo n.º 8
0
char* Log_CreateRTF(LOGSTREAMDATA *streamData)
{
	MODULEINFO *mi = ci.MM_FindModule(streamData->si->pszModule);

	// guesstimate amount of memory for the RTF
	size_t bufferEnd = 0, bufferAlloced = streamData->bRedraw ? 1024 * (streamData->si->iEventCount + 2) : 2048;
	char *buffer = (char *)mir_alloc(bufferAlloced);
	buffer[0] = '\0';

	// ### RTF HEADER
	char *header = mi->pszHeader;
	if (header)
		Log_Append(buffer, bufferEnd, bufferAlloced, header);

	// ### RTF BODY (one iteration per event that should be streamed in)
	for (LOGINFO *lin = streamData->lin; lin; lin = lin->prev) {
		// filter
		if (streamData->si->iType == GCW_CHATROOM || streamData->si->iType == GCW_PRIVMESS)
			if (streamData->si->bFilterEnabled && (streamData->si->iLogFilterFlags & lin->iType) == 0)
				continue;

		// create new line, and set font and color
		if (lin->next != NULL)
			Log_Append(buffer, bufferEnd, bufferAlloced, "\\par ");
		Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(0));

		// Insert icon
		if ((lin->iType & g_Settings->dwIconFlags) || lin->bIsHighlighted && (g_Settings->dwIconFlags & GC_EVENT_HIGHLIGHT)) {
			int iIndex = (lin->bIsHighlighted && g_Settings->dwIconFlags & GC_EVENT_HIGHLIGHT) ? ICON_HIGHLIGHT : EventToIcon(lin);
			Log_Append(buffer, bufferEnd, bufferAlloced, "\\f0\\fs14");
			while (bufferAlloced - bufferEnd < logIconBmpSize[0])
				bufferAlloced += 4096;
			buffer = (char *)mir_realloc(buffer, bufferAlloced);
			memcpy(buffer + bufferEnd, pLogIconBmpBits[iIndex], logIconBmpSize[iIndex]);
			bufferEnd += logIconBmpSize[iIndex];
		}

		if (g_Settings->bTimeStampEventColour) {
			LOGFONT &lf = ci.aFonts[0].lf;

			// colored timestamps
			static char szStyle[256];
			if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) {
				int iii = lin->bIsHighlighted ? 16 : (lin->bIsMe ? 2 : 1);
				mir_snprintf(szStyle, _countof(szStyle), "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\fs%u", iii + 1, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / ci.logPixelSY);
				Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle);
			}
			else {
				int iii = lin->bIsHighlighted ? 16 : EventToIndex(lin);
				mir_snprintf(szStyle, _countof(szStyle), "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\fs%u", iii + 1, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / ci.logPixelSY);
				Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle);
			}
		}
		else Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(0));

		if (g_Settings->dwIconFlags)
			Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab ");

		//insert timestamp
		if (g_Settings->bShowTime) {
			TCHAR szTimeStamp[30], szOldTimeStamp[30];

			mir_tstrncpy(szTimeStamp, MakeTimeStamp(g_Settings->pszTimeStamp, lin->time), 30);
			mir_tstrncpy(szOldTimeStamp, MakeTimeStamp(g_Settings->pszTimeStamp, streamData->si->LastTime), 30);
			if (!g_Settings->bShowTimeIfChanged || streamData->si->LastTime == 0 || mir_tstrcmp(szTimeStamp, szOldTimeStamp)) {
				streamData->si->LastTime = lin->time;
				Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, _T("%s"), szTimeStamp);
			}
			Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab ");
		}

		// Insert the nick
		if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) {
			TCHAR pszTemp[300], *p1;

			Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(lin->bIsMe ? 2 : 1));
			mir_tstrncpy(pszTemp, lin->bIsMe ? g_Settings->pszOutgoingNick : g_Settings->pszIncomingNick, 299);
			p1 = _tcsstr(pszTemp, _T("%n"));
			if (p1)
				p1[1] = 's';

			Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, pszTemp, lin->ptszNick);
			Log_Append(buffer, bufferEnd, bufferAlloced, " ");
		}

		// Insert the message
		Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin)));
		streamData->lin = lin;
		AddEventToBuffer(buffer, bufferEnd, bufferAlloced, streamData);
	}

	// ### RTF END
	if (streamData->bRedraw)
		Log_Append(buffer, bufferEnd, bufferAlloced, "\\par}");
	else
		Log_Append(buffer, bufferEnd, bufferAlloced, "}");
	return buffer;
}
Ejemplo n.º 9
0
void LoadMsgLogBitmaps(void)
{
	HBRUSH hBkgBrush = CreateSolidBrush(g_Settings->crLogBackground);

	BITMAPINFOHEADER bih = { 0 };
	bih.biSize = sizeof(bih);
	bih.biBitCount = 24;
	bih.biCompression = BI_RGB;
	bih.biHeight = bih.biWidth = g_Settings->LogIconSize;
	bih.biPlanes = 1;
	int widthBytes = ((bih.biWidth * bih.biBitCount + 31) >> 5) * 4;

	RECT rc;
	rc.top = rc.left = 0;
	rc.right = bih.biWidth;
	rc.bottom = bih.biHeight;

	HDC hdc = GetDC(NULL);
	HBITMAP hBmp = CreateCompatibleBitmap(hdc, bih.biWidth, bih.biHeight);
	HDC hdcMem = CreateCompatibleDC(hdc);
	PBYTE pBmpBits = (PBYTE)mir_alloc(widthBytes * bih.biHeight);
	for (int i = 0; i < _countof(pLogIconBmpBits); i++) {
		size_t size = RTFPICTHEADERMAXSIZE + (bih.biSize + widthBytes * bih.biHeight) * 2;
		pLogIconBmpBits[i] = (char*)mir_alloc(size);
		size_t rtfHeaderSize = mir_snprintf((char *)pLogIconBmpBits[i], size, "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, bih.biWidth, bih.biHeight);

		HICON hIcon = ci.hIcons[i];
		HBITMAP hoBmp = (HBITMAP)SelectObject(hdcMem, hBmp);
		FillRect(hdcMem, &rc, hBkgBrush);
		DrawIconEx(hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, NULL, DI_NORMAL);
		SelectObject(hdcMem, hoBmp);
		GetDIBits(hdc, hBmp, 0, bih.biHeight, pBmpBits, (BITMAPINFO *)& bih, DIB_RGB_COLORS);

		char *szDest = pLogIconBmpBits[i] + rtfHeaderSize;
		bin2hex(&bih, sizeof(bih), szDest); szDest += sizeof(bih) * 2;
		bin2hex(pBmpBits, widthBytes * bih.biHeight, szDest); szDest += widthBytes * bih.biHeight * 2;
		mir_strcpy(szDest, "}");

		logIconBmpSize[i] = size_t(szDest - pLogIconBmpBits[i]) + 1;
	}
	mir_free(pBmpBits);
	DeleteDC(hdcMem);
	DeleteObject(hBmp);
	ReleaseDC(NULL, hdc);
	DeleteObject(hBkgBrush);

	if (ci.logPixelSY == 0) {
		HDC hdc;
		hdc = GetDC(NULL);
		ci.logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY);
		ci.logPixelSX = GetDeviceCaps(hdc, LOGPIXELSX);
		ReleaseDC(NULL, hdc);
	}

	for (int i = 0; i < OPTIONS_FONTCOUNT; i++) {
		LOGFONT &F = ci.aFonts[i].lf;
		mir_snprintf(CHAT_rtfFontsGlobal[i], RTFCACHELINESIZE,
			"\\f%u\\cf%u\\ul0\\highlight0\\b%d\\i%d\\ul%d\\fs%u", i, i + 1,
			F.lfWeight >= FW_BOLD ? 1 : 0, F.lfItalic, F.lfUnderline, 2 * abs(F.lfHeight) * 74 / ci.logPixelSY);
	}
}
Ejemplo n.º 10
0
int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, MCONTACT hContact, bool fIsSendLater)
{
	bool  fAvail = sendLater->isAvail();

	const TCHAR *szNote = 0;

	if (fIsSendLater && dat) {
		if (fAvail)
			szNote = TranslateT("Message successfully queued for later delivery.\nIt will be sent as soon as possible and a popup will inform you about the result.");
		else
			szNote = TranslateT("The send later feature is not available on this protocol.");

		T2Utf utfText(szNote);
		DBEVENTINFO dbei;
		dbei.cbSize = sizeof(dbei);
		dbei.eventType = EVENTTYPE_MESSAGE;
		dbei.flags = DBEF_SENT | DBEF_UTF;
		dbei.szModule = GetContactProto(dat->hContact);
		dbei.timestamp = time(NULL);
		dbei.cbBlob = (int)mir_strlen(utfText) + 1;
		dbei.pBlob = (PBYTE)(char*)utfText;
		StreamInEvents(dat->hwnd, 0, 1, 1, &dbei);
		if (dat->hDbEventFirst == NULL)
			SendMessage(dat->hwnd, DM_REMAKELOG, 0, 0);
		dat->cache->saveHistory(0, 0);
		EnableSendButton(dat, FALSE);
		if (dat->pContainer->hwndActive == dat->hwnd)
			UpdateReadChars(dat);
		SendDlgItemMessage(dat->hwnd, IDC_SAVE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)PluginConfig.g_buttonBarIcons[ICON_BUTTON_CANCEL]);
		SendDlgItemMessage(dat->hwnd, IDC_SAVE, BUTTONADDTOOLTIP, (WPARAM)pszIDCSAVE_close, BATF_TCHAR);
		dat->dwFlags &= ~MWF_SAVEBTN_SAV;

		if (!fAvail)
			return 0;
	}

	if (iJobIndex >= 0 && iJobIndex < NR_SENDJOBS) {
		SendJob *job = &m_jobs[iJobIndex];
		char szKeyName[20];
		TCHAR tszHeader[150];

		if (fIsSendLater) {
			time_t now = time(0);
			TCHAR tszTimestamp[30];
			_tcsftime(tszTimestamp, _countof(tszTimestamp), _T("%Y.%m.%d - %H:%M"), _localtime32((__time32_t *)&now));
			mir_snprintf(szKeyName, "S%d", now);
			mir_sntprintf(tszHeader, TranslateT("\n(Sent delayed. Original timestamp %s)"), tszTimestamp);
		}
		else mir_sntprintf(tszHeader, _T("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));

		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;
	}
	return -1;
}
Ejemplo n.º 11
0
static int Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const TCHAR *fmt, ...)
{
	va_list va;
	int lineLen, textCharsCount = 0;
	TCHAR* line = (TCHAR*)alloca(8001 * sizeof(TCHAR));

	va_start(va, fmt);
	lineLen = mir_vsntprintf(line, 8000, fmt, va);
	if (lineLen < 0) lineLen = 8000;
	line[lineLen] = 0;
	va_end(va);

	lineLen = lineLen * 20 + 8;
	if (cbBufferEnd + lineLen > cbBufferAlloced) {
		cbBufferAlloced += (lineLen + 1024 - lineLen % 1024);
		buffer = (char *)mir_realloc(buffer, cbBufferAlloced);
	}

	char *d = buffer + cbBufferEnd;

	for (; *line; line++, textCharsCount++) {
		if (*line == '\r' && line[1] == '\n') {
			memcpy(d, "\\par ", 5);
			line++;
			d += 5;
		}
		else if (*line == '\n') {
			memcpy(d, "\\line ", 6);
			d += 6;
		}
		else if (*line == '%' && !simpleMode) {
			char szTemp[200];

			szTemp[0] = '\0';
			switch (*++line) {
			case '\0':
			case '%':
				*d++ = '%';
				break;

			case 'c':
			case 'f':
				if (g_Settings->bStripFormat || streamData->bStripFormat)
					line += 2;

				else if (line[1] != '\0' && line[2] != '\0') {
					TCHAR szTemp3[3], c = *line;
					int col;
					szTemp3[0] = line[1];
					szTemp3[1] = line[2];
					szTemp3[2] = '\0';
					line += 2;

					col = _ttoi(szTemp3);
					col += (OPTIONS_FONTCOUNT + 1);
					mir_snprintf(szTemp, (c == 'c') ? "\\cf%u " : "\\highlight%u ", col);
				}
				break;
			case 'C':
			case 'F':
				if (!g_Settings->bStripFormat && !streamData->bStripFormat) {
					int j = streamData->lin->bIsHighlighted ? 16 : EventToIndex(streamData->lin);
					if (*line == 'C')
						mir_snprintf(szTemp, "\\cf%u ", j + 1);
					else
						mir_snprintf(szTemp, "\\highlight0 ");
				}
				break;
			case 'b':
			case 'u':
			case 'i':
				if (!streamData->bStripFormat)
					mir_snprintf(szTemp, (*line == 'u') ? "\\%cl " : "\\%c ", *line);
				break;

			case 'B':
			case 'U':
			case 'I':
				if (!streamData->bStripFormat) {
					mir_snprintf(szTemp, (*line == 'U') ? "\\%cl0 " : "\\%c0 ", *line);
					CharLowerA(szTemp);
				}
				break;

			case 'r':
				if (!streamData->bStripFormat) {
					int index = EventToIndex(streamData->lin);
					mir_snprintf(szTemp, "%s ", Log_SetStyle(index));
				}
				break;
			}

			if (szTemp[0]) {
				size_t iLen = mir_strlen(szTemp);
				memcpy(d, szTemp, iLen);
				d += iLen;
			}
		}
		else if (*line == '\t' && !streamData->bStripFormat) {
			memcpy(d, "\\tab ", 5);
			d += 5;
		}
		else if ((*line == '\\' || *line == '{' || *line == '}') && !streamData->bStripFormat) {
			*d++ = '\\';
			*d++ = (char)*line;
		}
		else if (*line > 0 && *line < 128) {
			*d++ = (char)*line;
		}
		else d += sprintf(d, "\\u%u ?", (WORD)*line); //!!!!!!!!!!!
	}

	cbBufferEnd = (int)(d - buffer);
	return textCharsCount;
}
Ejemplo n.º 12
0
BOOL CALLBACK DlgProcParentWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) 
{
	DWORD ws;
	struct ParentWindowData *dat;
	dat = (struct ParentWindowData *) GetWindowLong(hwndDlg, GWL_USERDATA);
	if (!dat && msg!=WM_INITDIALOG) return FALSE;
	switch (msg) {
	case WM_INITDIALOG:
		{
			struct NewMessageWindowLParam *newData = (struct NewMessageWindowLParam *) lParam;
			dat = (struct ParentWindowData *) malloc(sizeof(struct ParentWindowData));
			dat->hContact = newData->hContact;
			dat->nFlash = 0;
			dat->nFlashMax = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_FLASHCOUNT, SRMSGDEFSET_FLASHCOUNT);
			dat->childrenCount = 0;
			dat->children = NULL;
			dat->hwnd = hwndDlg;
			dat->flags = g_dat->flags;// | SMF_SHOWTITLEBAR;
			dat->mouseLBDown = 0;
			dat->windowWasCascaded = 0;
			dat->hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0, hwndDlg, NULL, g_hInst, NULL);
			{
				int statwidths[4];
				RECT rc;
				SendMessage(dat->hwndStatus, SB_SETMINHEIGHT, GetSystemMetrics(SM_CYSMICON), 0);
				GetWindowRect(dat->hwndStatus, &rc);
				/*
				statwidths[0] = rc.right - rc.left - SB_CHAR_WIDTH - SB_TYPING_WIDTH - SB_SENDING_WIDTH;
				statwidths[1] = rc.right - rc.left - SB_TYPING_WIDTH - SB_SENDING_WIDTH; //rc.right - rc.left - SB_CHAR_WIDTH;
				statwidths[2] = rc.right - rc.left - SB_TYPING_WIDTH; //rc.right - rc.left - SB_CHAR_WIDTH;
				statwidths[3] = -1;
				SendMessage(dat->hwndStatus, SB_SETPARTS, 4, (LPARAM) statwidths);
				*/
				statwidths[0] = rc.right - rc.left - SB_CHAR_WIDTH - SB_TYPING_WIDTH;
				statwidths[1] = rc.right - rc.left - SB_TYPING_WIDTH;
				statwidths[2] = -1;
				SendMessage(dat->hwndStatus, SB_SETPARTS, 3, (LPARAM) statwidths);
			}
			dat->hwndTabs = GetDlgItem(hwndDlg, IDC_TABS);
			dat->hwndActive = NULL;
			SetWindowLong(hwndDlg, GWL_USERDATA, (LONG) dat);
			if (g_dat->hIconList != NULL) {
				TabCtrl_SetImageList(dat->hwndTabs, g_dat->hIconList);
			}
			WindowList_Add(g_dat->hParentWindowList, hwndDlg, 0);
			dat->tabCtrlDat = (struct TabCtrlData *) malloc(sizeof(struct TabCtrlData));
			dat->tabCtrlDat->bDragging = FALSE;
			SetWindowLong(dat->hwndTabs, GWL_USERDATA, (LONG) dat->tabCtrlDat);
			OldTabCtrlProc = (WNDPROC) SetWindowLong(dat->hwndTabs, GWL_WNDPROC, (LONG) TabCtrlProc);
			ws = GetWindowLong(dat->hwndTabs, GWL_STYLE) & ~(TCS_BOTTOM);
			if (dat->flags & SMF_TABSATBOTTOM) {
				ws |= TCS_BOTTOM;
			}
			SetWindowLong(dat->hwndTabs, GWL_STYLE, ws);
			ws = GetWindowLong(hwndDlg, GWL_STYLE) & ~(WS_CAPTION);
			if (dat->flags & SMF_SHOWTITLEBAR) {
				ws |= WS_CAPTION;
				SetWindowLong(hwndDlg, GWL_STYLE, ws);
			} else {
				RECT rc;
				SetWindowLong(hwndDlg, GWL_STYLE, ws);
				GetWindowRect(hwndDlg, &rc);
				SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
							 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER  | SWP_FRAMECHANGED | SWP_NOSENDCHANGING); 
			}
			ws = GetWindowLong(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED;
			ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0;
			SetWindowLong(hwndDlg , GWL_EXSTYLE , ws);
			if (dat->flags & SMF_USETRANSPARENCY) {
   				pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->inactiveAlpha), LWA_ALPHA);
//				RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
			}

			//SetWindowPos(dat->hwndTabs, 0, 0, -10, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
			if (!(dat->flags & SMF_SHOWSTATUSBAR)) {
				ShowWindow(dat->hwndStatus, SW_HIDE);
			}
			if (dat->flags & SMF_USETABS) {
				if (ScriverRestoreWindowPosition(hwndDlg, NULL, SRMMMOD, "", 0, SW_HIDE)) {
					SetWindowPos(hwndDlg, 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE  | SWP_HIDEWINDOW);
				}
			} else {
				int savePerContact = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT);
				if (ScriverRestoreWindowPosition(hwndDlg, savePerContact ? dat->hContact : NULL, SRMMMOD, "", 0, SW_HIDE)) {
				//if (Utils_RestoreWindowPosition(GetParent(hwndDlg), savePerContact ? dat->hContact : NULL, SRMMMOD, "")) {
					if (savePerContact) {
						if (ScriverRestoreWindowPosition(hwndDlg, NULL, SRMMMOD, "", RWPF_NOSIZE, SW_HIDE))
					//	if (Utils_RestoreWindowPositionNoMove(GetParent(hwndDlg), NULL, SRMMMOD, ""))
						SetWindowPos(GetParent(hwndDlg), 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE);
					}
					else
						SetWindowPos(hwndDlg, 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE);
				}
				if (!savePerContact && DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_CASCADE, SRMSGDEFSET_CASCADE))
					WindowList_Broadcast(g_dat->hParentWindowList, DM_CASCADENEWWINDOW, (WPARAM) hwndDlg, (LPARAM) & dat->windowWasCascaded);
			}
		}
		return TRUE;
	case WM_GETMINMAXINFO:
	{
		MINMAXINFO *mmi = (MINMAXINFO *) lParam;
		SIZE size;
		GetMinimunWindowSize(dat, &size);
		mmi->ptMinTrackSize.x = size.cx;
		mmi->ptMinTrackSize.y = size.cy;
		return FALSE;
	}

	case WM_SIZE:
		if (wParam == SIZE_MINIMIZED) {
			dat->bMinimized = 1;

		} 
		if (IsIconic(hwndDlg))	{
			MoveWindow(dat->hwndActive, dat->childRect.left, dat->childRect.top, dat->childRect.right-dat->childRect.left, dat->childRect.bottom - dat->childRect.top, TRUE);
		} else {
//		}
//		if (!IsIconic(hwndDlg)) {
			int i;
			RECT rc, rcStatus, rcChild, rcWindow;
			SIZE size;
			dat->bMinimized = 0;
			GetClientRect(hwndDlg, &rc);
			GetWindowRect(hwndDlg, &rcWindow);
			rcStatus.top = rcStatus.bottom = 0;
			if (dat->flags & SMF_SHOWSTATUSBAR) {
				int statwidths[4];
				GetWindowRect(dat->hwndStatus, &rcStatus);
				statwidths[0] = rc.right - rc.left - SB_CHAR_WIDTH - SB_TYPING_WIDTH;
				statwidths[1] = rc.right - rc.left - SB_TYPING_WIDTH;
				statwidths[2] = -1;
				SendMessage(dat->hwndStatus, SB_SETPARTS, 3, (LPARAM) statwidths);
				SendMessage(dat->hwndStatus, WM_SIZE, 0, 0);
			}
			MoveWindow(dat->hwndTabs, 0, 2, (rc.right - rc.left), (rc.bottom - rc.top) - (rcStatus.bottom - rcStatus.top) - 2,	FALSE); 
			RedrawWindow(dat->hwndTabs, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE);
			GetMinimunWindowSize(dat, &size);
			if ((rcWindow.bottom-rcWindow.top) < size.cy || (rcWindow.right-rcWindow.left) < size.cx) {
				if ((rcWindow.bottom-rcWindow.top) < size.cy) {
					rcWindow.bottom = rcWindow.top + size.cy;
				} 
				if ((rcWindow.right-rcWindow.left) < size.cx) {
					rcWindow.right = rcWindow.left + size.cx;
				}
				MoveWindow(hwndDlg, rcWindow.left, rcWindow.top, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top,	TRUE); 
			}
			GetChildWindowRect(dat, &rcChild);
			memcpy(&dat->childRect, &rcChild, sizeof(RECT));
			for (i=0;i<dat->childrenCount;i++) {
				if (dat->children[i] == dat->hwndActive) {
					MoveWindow(dat->children[i], rcChild.left, rcChild.top, rcChild.right-rcChild.left, rcChild.bottom - rcChild.top, TRUE);
					RedrawWindow(GetDlgItem(dat->children[i], IDC_LOG), NULL, NULL, RDW_INVALIDATE);
				} 
			}
			if (dat->flags & SMF_SHOWSTATUSBAR) {
				RedrawWindow(dat->hwndStatus, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
			}
		}
		return FALSE;
	case WM_SETFOCUS:
		SetFocus(dat->hwndActive);
		return TRUE;
	case WM_CLOSE:
		DestroyWindow(hwndDlg);
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			//DestroyWindow(hwndDlg);
			return TRUE;
		}
	case WM_NOTIFY: 
		{
			NMHDR* pNMHDR = (NMHDR*) lParam;
			if (pNMHDR->hwndFrom == dat->hwndTabs) {
				switch (pNMHDR->code) {
				case TCN_SELCHANGE:
					{
						TCITEM tci = {0};
						int iSel = TabCtrl_GetCurSel(dat->hwndTabs);
						tci.mask = TCIF_PARAM;
						if (TabCtrl_GetItem(dat->hwndTabs, iSel, &tci)) {
							struct MessageWindowData * mdat = (struct MessageWindowData *) tci.lParam;
							ActivateChild(dat, mdat->hwnd);
						}
					}
					break;
				case NM_RCLICK:
					{
						TCHITTESTINFO thinfo;
						int tabId, x, y;
						GetCursorPos(&thinfo.pt);
						x = thinfo.pt.x; 
						y = thinfo.pt.y;
						ScreenToClient(dat->hwndTabs, &thinfo.pt);
						tabId = TabCtrl_HitTest(dat->hwndTabs, &thinfo);
						if (tabId != -1) {
							struct MessageWindowData * mwd = GetChildFromTab(dat->hwndTabs, tabId);
							//CallService(MS_USERINFO_SHOWDIALOG, (WPARAM) mwd->hContact, 0);
							HMENU hMenu = (HMENU) CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM) mwd->hContact, 0);
							TrackPopupMenu(hMenu, 0, x, y, 0, mwd->hwnd, NULL);
							DestroyMenu(hMenu);
						}
					}
					break;
				}
			} else if (pNMHDR->hwndFrom == dat->hwndStatus)  {
				switch (pNMHDR->code) {
				case NM_CLICK:
					{
						NMMOUSE *nm=(NMMOUSE*)lParam;
						RECT rc;
						SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc);
						if (nm->pt.x >= rc.left) 
							SendMessage(dat->hwndActive, DM_SWITCHUNICODE, 0, 0);
					}
				}
				break;
			}
		}
		break;
	case WM_DROPFILES:
		SendMessage(dat->hwndActive, WM_DROPFILES, wParam, lParam);
		break;
	case WM_TIMER:
		if (wParam == TIMERID_FLASHWND) {
			if ((dat->nFlash > dat->nFlashMax)) {// || ((GetActiveWindow() == hwndDlg) && (GetForegroundWindow() == hwndDlg))) {
				KillTimer(hwndDlg, TIMERID_FLASHWND);
				FlashWindow(hwndDlg, FALSE);
			} else if (dat->nFlash < dat->nFlashMax) {
				FlashWindow(hwndDlg, TRUE);
				dat->nFlash++;
			}
		}
		break;
	case WM_CONTEXTMENU:
	{
		if (dat->hwndStatus && dat->hwndStatus == (HWND) wParam) {
			RECT rc;
			POINT pt, pt2;
			GetCursorPos(&pt);
			pt2.x = pt.x;
			pt2.y = pt.y;
			ScreenToClient(dat->hwndStatus, &pt);
			SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc);
			if (pt.x >= rc.left && dat->hwndActive != NULL) {
				int codePage = (int) SendMessage(dat->hwndActive, DM_GETCODEPAGE, 0, 0);
				int i, iSel;
				for(i = 0; i < GetMenuItemCount(g_dat->hMenuANSIEncoding); i++) {
					CheckMenuItem (g_dat->hMenuANSIEncoding, i, MF_BYPOSITION | MF_UNCHECKED);
				}
				if(codePage == CP_ACP) {
					CheckMenuItem(g_dat->hMenuANSIEncoding, 0, MF_BYPOSITION | MF_CHECKED);
				} else {
					CheckMenuItem(g_dat->hMenuANSIEncoding, codePage, MF_BYCOMMAND | MF_CHECKED);
				}
				iSel = TrackPopupMenu(g_dat->hMenuANSIEncoding, TPM_RETURNCMD, pt2.x, pt2.y, 0, hwndDlg, NULL);
				if (iSel >= 500) {
					if (iSel == 500) iSel = CP_ACP;
					SendMessage(dat->hwndActive, DM_SETCODEPAGE, 0, iSel);
				}
			}
			else 
				SendMessage(dat->hwndActive, WM_CONTEXTMENU, (WPARAM)hwndDlg, 0);
		}
		break;
	}
	case WM_ACTIVATE:
		if (LOWORD(wParam) == WA_INACTIVE) {
			ws = GetWindowLong(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED;
			ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0;
			SetWindowLong(hwndDlg , GWL_EXSTYLE , ws);
			if (dat->flags & SMF_USETRANSPARENCY) {
   				pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->inactiveAlpha), LWA_ALPHA);
//				RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
			}
		}
		if (LOWORD(wParam) != WA_ACTIVE)
			break;
	case WM_MOUSEACTIVATE:
		if (KillTimer(hwndDlg, TIMERID_FLASHWND)) {
			FlashWindow(hwndDlg, FALSE);
			dat->nFlash = 0;
		}
		ws = GetWindowLong(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED;
		ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0;
		SetWindowLong(hwndDlg , GWL_EXSTYLE , ws);
		if (dat->flags & SMF_USETRANSPARENCY) {
   			pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->activeAlpha), LWA_ALPHA);
//				RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
		}
		SendMessage(dat->hwndActive, WM_ACTIVATE, WA_ACTIVE, 0);
		break;
	case WM_LBUTTONDOWN:
		dat->mouseLBDown = 1;
		GetCursorPos(&dat->mouseLBDownPos);
		SetCapture(hwndDlg);
		break;
	case WM_LBUTTONUP:
		dat->mouseLBDown = 0;
		ReleaseCapture();
		break;
	case WM_MOUSEMOVE:
		if (dat->mouseLBDown) { 
			POINT pt;
			RECT  rc;
			GetCursorPos(&pt);
			GetWindowRect(hwndDlg, &rc);
			SetWindowPos(hwndDlg, 0, rc.left - (dat->mouseLBDownPos.x - pt.x), rc.top - (dat->mouseLBDownPos.y - pt.y), 0, 0, SWP_NOZORDER | SWP_NOSIZE);
			dat->mouseLBDownPos = pt;
		}
		break;
	case WM_DESTROY:
		{
			g_dat->hParent = NULL;
			SetWindowLong(hwndDlg, GWL_USERDATA, 0);
			WindowList_Remove(g_dat->hParentWindowList, hwndDlg);
			if (dat->children!=NULL) free (dat->children);
			free(dat->tabCtrlDat);
			free(dat);
			if (dat->flags & SMF_USETABS) {
				WINDOWPLACEMENT wp = { 0 };
				wp.length = sizeof(wp);
				GetWindowPlacement(hwndDlg, &wp);
				DBWriteContactSettingDword(NULL, SRMMMOD, "x", wp.rcNormalPosition.left);
				DBWriteContactSettingDword(NULL, SRMMMOD, "y", wp.rcNormalPosition.top);
				DBWriteContactSettingDword(NULL, SRMMMOD, "width", wp.rcNormalPosition.right - wp.rcNormalPosition.left);
				DBWriteContactSettingDword(NULL, SRMMMOD, "height", wp.rcNormalPosition.bottom - wp.rcNormalPosition.top);
			} else {
				WINDOWPLACEMENT wp = { 0 };
				HANDLE hContact;
				if (DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT))
					hContact = dat->hContact;
				else
					hContact = NULL;
				wp.length = sizeof(wp);
				GetWindowPlacement(hwndDlg, &wp);
				if (!dat->windowWasCascaded) {
					DBWriteContactSettingDword(hContact, SRMMMOD, "x", wp.rcNormalPosition.left);
					DBWriteContactSettingDword(hContact, SRMMMOD, "y", wp.rcNormalPosition.top);
				}
				DBWriteContactSettingDword(hContact, SRMMMOD, "width", wp.rcNormalPosition.right - wp.rcNormalPosition.left);
				DBWriteContactSettingDword(hContact, SRMMMOD, "height", wp.rcNormalPosition.bottom - wp.rcNormalPosition.top);
			}

		}
		break;
	case DM_ERRORDECIDED:
		break;
	case DM_STARTFLASHING:
		if (GetActiveWindow() != hwndDlg || GetForegroundWindow() != hwndDlg) {
			dat->nFlash = 0;
			SetTimer(hwndDlg, TIMERID_FLASHWND, TIMEOUT_FLASHWND, NULL);
		}
		break;
	case DM_REMOVECHILD:
		{
			RemoveChild(dat, (HWND) lParam);
			if (dat->childrenCount == 0) {
				DestroyWindow(hwndDlg);
			} else {
			}
		}
		return TRUE;
	case DM_ADDCHILD:
		{
			struct MessageWindowData * mdat = (struct MessageWindowData *) lParam;
			AddChild(dat, mdat);
		}
		return TRUE;
	case DM_ACTIVATECHILD:
		if((HWND) lParam != dat->hwndActive) {
			ActivateChild(dat, (HWND) lParam);
		}
		return TRUE;
	case DM_ACTIVATEPREV:
		ActivatePrevChild(dat, (HWND) lParam);
		return TRUE;
	case DM_ACTIVATENEXT:
		ActivateNextChild(dat, (HWND) lParam);
		return TRUE;
	case DM_SENDMESSAGE:
		{
			int i;
			for (i=0;i<dat->childrenCount;i++) {
				SendMessage(dat->children[i], DM_SENDMESSAGE, wParam, lParam);
			}
		}
		break;
	case DM_OPTIONSAPPLIED:
		{
			RECT rc;
			dat->flags = g_dat->flags;
			if (!(dat->flags & SMF_SHOWSTATUSBAR)) {
				ShowWindow(dat->hwndStatus, SW_HIDE);
			} else {
				ShowWindow(dat->hwndStatus, SW_SHOW);
			}
			ws = GetWindowLong(hwndDlg, GWL_STYLE) & ~(WS_CAPTION);
			if (dat->flags & SMF_SHOWTITLEBAR) {
				ws |= WS_CAPTION;
			} 
			SetWindowLong(hwndDlg, GWL_STYLE, ws);

			ws = GetWindowLong(hwndDlg, GWL_EXSTYLE)& ~WS_EX_LAYERED;
			ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0;
			SetWindowLong(hwndDlg , GWL_EXSTYLE , ws);
			if (dat->flags & SMF_USETRANSPARENCY) {
   				pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->inactiveAlpha), LWA_ALPHA);
//				RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
			}

			ws = GetWindowLong(dat->hwndTabs, GWL_STYLE) & ~(TCS_BOTTOM);
			if (dat->flags & SMF_TABSATBOTTOM) {
				ws |= TCS_BOTTOM;
			} 
			SetWindowLong(dat->hwndTabs, GWL_STYLE, ws);
			RedrawWindow(dat->hwndTabs, NULL, NULL, RDW_INVALIDATE);
			GetWindowRect(hwndDlg, &rc);
			SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top, 
                        SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
			SendMessage(hwndDlg, WM_SIZE, 0, 0);
			//RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
			break;
		}
	case DM_UPDATETITLE:
		{
			struct MessageWindowData * mdat = (struct MessageWindowData *) lParam;
			TCITEM tci;
			int tabId;
			char newtitle[256], oldtitle[256];
			char *szStatus, *contactName, *pszNewTitleEnd;
			TCHAR *tContactName;
			if (mdat && mdat->hwnd == dat->hwndActive) {
				pszNewTitleEnd = "Message Session";
				if (mdat->hContact) {
					if (mdat->szProto) {
						CONTACTINFO ci;
						char buf[128];
						int statusIcon = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_STATUSICON, SRMSGDEFSET_STATUSICON);

						buf[0] = 0;
						mdat->wStatus = DBGetContactSettingWord(mdat->hContact, mdat->szProto, "Status", ID_STATUS_OFFLINE);
						contactName = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) mdat->hContact, 0);
						ZeroMemory(&ci, sizeof(ci));
						ci.cbSize = sizeof(ci);
						ci.hContact = mdat->hContact;
						ci.szProto = mdat->szProto;
						ci.dwFlag = CNF_UNIQUEID;
						if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) {
							switch (ci.type) {
							case CNFT_ASCIIZ:
								mir_snprintf(buf, sizeof(buf), "%s", ci.pszVal);
								miranda_sys_free(ci.pszVal);
								break;
							case CNFT_DWORD:
								mir_snprintf(buf, sizeof(buf), "%u", ci.dVal);
								break;
							}
						}
						szStatus = (char *) CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, mdat->szProto == NULL ? ID_STATUS_OFFLINE : DBGetContactSettingWord(mdat->hContact, mdat->szProto, "Status", ID_STATUS_OFFLINE), 0);
						if (statusIcon)
							mir_snprintf(newtitle, sizeof(newtitle), "%s - %s", contactName, Translate(pszNewTitleEnd));
						else
							mir_snprintf(newtitle, sizeof(newtitle), "%s (%s): %s", contactName, szStatus, Translate(pszNewTitleEnd));

					}
				}
				else
					lstrcpynA(newtitle, pszNewTitleEnd, sizeof(newtitle));
				GetWindowTextA(hwndDlg, oldtitle, sizeof(oldtitle));
				if (lstrcmpA(newtitle, oldtitle)) { //swt() flickers even if the title hasn't actually changed
					SetWindowTextA(hwndDlg, newtitle);
					//SendMessage(hwndDlg, WM_SIZE, 0, 0);
				}
			}
			tabId = GetTabFromHWND(dat, mdat->hwnd);
			tContactName = GetTabName(mdat->hContact);
			tci.mask = TCIF_TEXT;
			tci.pszText = tContactName;
			TabCtrl_SetItem(dat->hwndTabs, tabId, &tci);
			free(tContactName);
			break;
		}
	case DM_UPDATEWINICON:
		{
			struct MessageWindowData * mdat = (struct MessageWindowData *) lParam;
			if (mdat) {
				if (mdat->szProto) {
					int i, icoIdx = 0;
					WORD wStatus;
					wStatus = DBGetContactSettingWord(mdat->hContact, mdat->szProto, "Status", ID_STATUS_OFFLINE);
					if (mdat->hwnd == dat->hwndActive) {
						if (DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_STATUSICON, SRMSGDEFSET_STATUSICON)) {
							if (mdat->showTyping && (dat->flags&SMF_SHOWTYPINGWIN)) {
								SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) g_dat->hIcons[SMF_ICON_TYPING]);
							} else if (mdat->showUnread && (GetActiveWindow() != hwndDlg || GetForegroundWindow() != hwndDlg)) {
								SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadSkinnedIcon(SKINICON_EVENT_MESSAGE));	
							} else {
								SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadSkinnedProtoIcon(mdat->szProto, wStatus));
							}
						} else {
							SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadSkinnedIcon(SKINICON_EVENT_MESSAGE));
						}
					}
					icoIdx = 0;
					for (i = 0; i < g_dat->protoNum; i++) {
						if (!strcmp(g_dat->protoNames[i], mdat->szProto)) {
							icoIdx = wStatus - ID_STATUS_OFFLINE + (ID_STATUS_OUTTOLUNCH - ID_STATUS_OFFLINE + 1) * (i +1) + 2;
							break;
						}
					}
					if (mdat->hwnd != dat->hwndActive) {
						if (mdat->showTyping) {
							icoIdx = 1;
						} else if (mdat->showUnread & 1) {
							icoIdx = 0;
						}
					}
					i = GetTabFromHWND(dat, mdat->hwnd);
					if (i>=0) {
						TCITEM tci;
						tci.mask = TCIF_IMAGE;
						tci.iImage = icoIdx;
						TabCtrl_SetItem(dat->hwndTabs, i, &tci);
					}
				} 
			} 
			break;
		}
	case DM_UPDATESTATUSBAR:
		break;
	case DM_SWITCHSTATUSBAR:
		dat->flags ^= SMF_SHOWSTATUSBAR;
		if (!(dat->flags & SMF_SHOWSTATUSBAR)) {
			ShowWindow(dat->hwndStatus, SW_HIDE);
		} else {
			ShowWindow(dat->hwndStatus, SW_SHOW);
		}
		SendMessage(hwndDlg, WM_SIZE, 0, 0);
		break;
	case DM_SWITCHTOOLBAR:
		{
			int i;
			dat->flags ^= SMF_SHOWBTNS;
			for (i=0;i<dat->childrenCount;i++) {
				SendMessage(dat->children[i], DM_SWITCHTOOLBAR, 0, 0);
			}
			SendMessage(hwndDlg, WM_SIZE, 0, 0);
		}
		break;
	case DM_SWITCHTITLEBAR:
		{
			RECT rc;
			dat->flags ^= SMF_SHOWTITLEBAR;
			ws = GetWindowLong(hwndDlg, GWL_STYLE) & ~(WS_CAPTION);
			if (dat->flags & SMF_SHOWTITLEBAR) {
				ws |= WS_CAPTION;
			} 
			SetWindowLong(hwndDlg, GWL_STYLE, ws);
			GetWindowRect(hwndDlg, &rc);
			SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
                         SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER  | SWP_FRAMECHANGED | SWP_NOSENDCHANGING); 
//			SendMessage(hwndDlg, WM_SIZE, 0, 0);
			RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
		}
		break;
	case DM_CASCADENEWWINDOW:
		if ((HWND) wParam == hwndDlg)
			break;
		{
			RECT rcThis, rcNew;
			GetWindowRect(hwndDlg, &rcThis);
			GetWindowRect((HWND) wParam, &rcNew);
			if (abs(rcThis.left - rcNew.left) < 3 && abs(rcThis.top - rcNew.top) < 3) {
				int offset = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME);
				SetWindowPos((HWND) wParam, 0, rcNew.left + offset, rcNew.top + offset, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
				*(int *) lParam = 1;
			}
		}
		break;
	//case DM_MESSAGESENDING:
	//	dat->messagesInProgress += wParam ? -1 : 1;
	//	if (dat->messagesInProgress < 0) dat->messagesInProgress = 0;
	//	break;
	}
	return FALSE;
}
Ejemplo n.º 13
0
MIR_APP_DLL(HICON) Skin_LoadProtoIcon(const char *szProto, int status, bool big)
{
	char iconName[MAX_PATH];
	INT_PTR caps2;
	if (szProto == NULL)
		caps2 = -1;
	else if ((caps2 = CallProtoServiceInt(NULL, szProto, PS_GETCAPS, PFLAGNUM_2, 0)) == CALLSERVICE_NOTFOUND)
		caps2 = 0;

	if (IsStatusConnecting(status)) {
		mir_snprintf(iconName, "%s%d", mainIconsFmt, 7);
		return IcoLib_GetIcon(iconName, big);
	}

	int statusIndx = -1;
	for (int i = 0; i < _countof(statusIcons); i++)
		if (statusIcons[i].id == status) {
			statusIndx = i;
			break;
		}

	if (statusIndx == -1)
		return NULL;

	if (!szProto) {
		// Only return a protocol specific icon if there is only one protocol
		// Otherwise return the global icon. This affects the global status menu mainly.
		if (accounts.getCount() == 1) {
			// format: core_status_%proto%statusindex
			mir_snprintf(iconName, "%s%s%d", statusIconsFmt, szProto, statusIndx);

			HICON hIcon = IcoLib_GetIcon(iconName, big);
			if (hIcon)
				return hIcon;
		}

		// format: core_status_%s%d
		mir_snprintf(iconName, "%s%s%d", statusIconsFmt, GLOBAL_PROTO_NAME, statusIndx);
		return IcoLib_GetIcon(iconName, big);
	}

	// format: core_status_%s%d
	mir_snprintf(iconName, "%s%s%d", statusIconsFmt, szProto, statusIndx);
	HICON hIcon = IcoLib_GetIcon(iconName, big);
	if (hIcon == NULL && (caps2 == 0 || (caps2 & statusIcons[statusIndx].pf2))) {
		PROTOACCOUNT *pa = Proto_GetAccount(szProto);
		if (pa) {
			TCHAR szPath[MAX_PATH], szFullPath[MAX_PATH], *str;
			GetModuleFileName(NULL, szPath, _countof(szPath));

			// Queried protocol isn't in list, adding
			TCHAR tszSection[MAX_PATH];
			mir_sntprintf(tszSection, _T(PROTOCOLS_PREFIX)_T("/%s"), pa->tszAccountName);

			SKINICONDESC sid = { 0 };
			sid.section.t = tszSection;
			sid.flags = SIDF_ALL_TCHAR;

			str = _tcsrchr(szPath, '\\');
			if (str != NULL)
				*str = 0;
			mir_sntprintf(szFullPath, _T("%s\\Icons\\proto_%S.dll"), szPath, pa->szProtoName);
			if (GetFileAttributes(szFullPath) != INVALID_FILE_ATTRIBUTES)
				sid.defaultFile.t = szFullPath;
			else {
				mir_sntprintf(szFullPath, _T("%s\\Plugins\\%S.dll"), szPath, szProto);
				if (int(ExtractIconEx(szFullPath, statusIcons[statusIndx].resource_id, NULL, &hIcon, 1)) > 0) {
					DestroyIcon(hIcon);
					sid.defaultFile.t = szFullPath;
					hIcon = NULL;
				}

				if (sid.defaultFile.a == NULL) {
					if (str != NULL)
						*str = '\\';
					sid.defaultFile.t = szPath;
				}
			}

			// Add global icons to list
			int lowidx, highidx;
			if (caps2 == 0)
				lowidx = statusIndx, highidx = statusIndx + 1;
			else
				lowidx = 0, highidx = _countof(statusIcons);

			for (int i = lowidx; i < highidx; i++) {
				if (caps2 == 0 || (caps2 & statusIcons[i].pf2)) {
					// format: core_%s%d
					mir_snprintf(iconName, "%s%s%d", statusIconsFmt, szProto, i);
					sid.pszName = iconName;
					sid.description.t = cli.pfnGetStatusModeDescription(statusIcons[i].id, 0);
					sid.iDefaultIndex = statusIcons[i].resource_id;
					IcoLib_AddIcon(&sid, 0);
				}
			}
		}

		// format: core_status_%s%d
		mir_snprintf(iconName, "%s%s%d", statusIconsFmt, szProto, statusIndx);
		hIcon = IcoLib_GetIcon(iconName, big);
		if (hIcon)
			return hIcon;
	}

	if (hIcon == NULL) {
		mir_snprintf(iconName, "%s%s%d", statusIconsFmt, GLOBAL_PROTO_NAME, statusIndx);
		hIcon = IcoLib_GetIcon(iconName, big);
	}

	return hIcon;
}
Ejemplo n.º 14
0
INT_PTR CALLBACK DlgProcSBarOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	StatusBarProtocolOptions *dat = (StatusBarProtocolOptions *)GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_STATUSBAR_PROTO_LIST), GWLP_USERDATA);
	BOOL perProto = IsDlgButtonChecked(hwndDlg, IDC_STATUSBAR_PER_PROTO);
	HWND hwndComboBox = GetDlgItem(hwndDlg, IDC_STATUSBAR_PROTO_LIST);
	int curSelProto = SendMessage(hwndComboBox, CB_GETITEMDATA, SendMessage(hwndComboBox, CB_GETCURSEL, 0, 0), NULL) - 1; //first entry is the combo box is a constant.
	if (curSelProto < 0)
		perProto = FALSE;

	switch (msg) {
	case WM_INITDIALOG:
		perProto = (BOOL)db_get_b(NULL, "CLUI", "SBarPerProto", SETTING_SBARPERPROTO_DEFAULT);

		TranslateDialogDefault(hwndDlg);

		CheckDlgButton(hwndDlg, IDC_SHOWSBAR, db_get_b(NULL, "CLUI", "ShowSBar", SETTING_SHOWSBAR_DEFAULT) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hwndDlg, IDC_STATUSBAR_PER_PROTO, perProto ? BST_CHECKED : BST_UNCHECKED);
		{
			// populate per-proto list box.
			char *szName;
			char buf[256];
			int count;

			SendMessage(hwndComboBox, CB_RESETCONTENT, 0, 0);

			PROTOACCOUNT **accs;
			ProtoEnumAccounts(&count, &accs);

			dat = (StatusBarProtocolOptions *)mir_alloc(sizeof(StatusBarProtocolOptions) * count);
			SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_STATUSBAR_PROTO_LIST), GWLP_USERDATA, (LONG_PTR)dat);

			SendMessage(hwndComboBox, CB_ADDSTRING, 0, (LPARAM)TranslateT("<<Global>>"));
			SendMessage(hwndComboBox, CB_SETITEMDATA, 0, 0);

			for (int i = 0; i < count; i++) {
				szName = accs[i]->szModuleName;
				dat[i].szName = szName;

				DWORD dwNewId = SendMessage(hwndComboBox, CB_ADDSTRING, 0, (LPARAM)accs[i]->tszAccountName);
				SendMessage(hwndComboBox, CB_SETITEMDATA, dwNewId, (LPARAM)i + 1);

				mir_snprintf(buf, SIZEOF(buf), "SBarAccountIsCustom_%s", szName);
				dat[i].AccountIsCustomized = db_get_b(NULL, "CLUI", buf, SETTING_SBARACCOUNTISCUSTOM_DEFAULT);

				mir_snprintf(buf, SIZEOF(buf), "HideAccount_%s", szName);
				dat[i].HideAccount = db_get_b(NULL, "CLUI", buf, SETTING_SBARHIDEACCOUNT_DEFAULT);

				mir_snprintf(buf, SIZEOF(buf), "SBarShow_%s", szName);
				dat[i].SBarShow = db_get_b(NULL, "CLUI", buf, SETTING_SBARSHOW_DEFAULT);

				mir_snprintf(buf, SIZEOF(buf), "SBarRightClk_%s", szName);
				dat[i].SBarRightClk = db_get_b(NULL, "CLUI", buf, SETTING_SBARRIGHTCLK_DEFAULT);

				mir_snprintf(buf, SIZEOF(buf), "ShowUnreadEmails_%s", szName);
				dat[i].ShowUnreadEmails = db_get_b(NULL, "CLUI", buf, SETTING_SHOWUNREADEMAILS_DEFAULT);

				mir_snprintf(buf, SIZEOF(buf), "ShowXStatus_%s", szName);
				dat[i].ShowXStatus = db_get_b(NULL, "CLUI", buf, SETTING_SHOWXSTATUS_DEFAULT);

				mir_snprintf(buf, SIZEOF(buf), "UseConnectingIcon_%s", szName);
				dat[i].UseConnectingIcon = db_get_b(NULL, "CLUI", buf, SETTING_USECONNECTINGICON_DEFAULT);

				mir_snprintf(buf, SIZEOF(buf), "PaddingLeft_%s", szName);
				dat[i].PaddingLeft = db_get_dw(NULL, "CLUI", buf, SETTING_PADDINGLEFT_DEFAULT);

				mir_snprintf(buf, SIZEOF(buf), "PaddingRight_%s", szName);
				dat[i].PaddingRight = db_get_dw(NULL, "CLUI", buf, SETTING_PADDINGRIGHT_DEFAULT);
			}

			if (count)
				SendMessage(hwndComboBox, CB_SETCURSEL, 0, 0);
		}

		_GlobalOptions.AccountIsCustomized = TRUE;
		_GlobalOptions.SBarRightClk = db_get_b(NULL, "CLUI", "SBarRightClk", SETTING_SBARRIGHTCLK_DEFAULT);
		_GlobalOptions.ShowUnreadEmails = db_get_b(NULL, "CLUI", "ShowUnreadEmails", SETTING_SHOWUNREADEMAILS_DEFAULT);
		_GlobalOptions.ShowXStatus = db_get_b(NULL, "CLUI", "ShowXStatus", SETTING_SHOWXSTATUS_DEFAULT);
		_GlobalOptions.UseConnectingIcon = db_get_b(NULL, "CLUI", "UseConnectingIcon", SETTING_USECONNECTINGICON_DEFAULT);
		_GlobalOptions.SBarShow = db_get_b(NULL, "CLUI", "SBarShow", SETTING_SBARSHOW_DEFAULT);

		CheckDlgButton(hwndDlg, IDC_EQUALSECTIONS, db_get_b(NULL, "CLUI", "EqualSections", SETTING_EQUALSECTIONS_DEFAULT) ? BST_CHECKED : BST_UNCHECKED);

		SendDlgItemMessage(hwndDlg, IDC_MULTI_SPIN, UDM_SETRANGE, 0, MAKELONG(50, 0));
		SendDlgItemMessage(hwndDlg, IDC_MULTI_SPIN, UDM_SETPOS, 0, MAKELONG(db_get_b(NULL, "CLUI", "StatusBarProtosPerLine", SETTING_PROTOSPERLINE_DEFAULT), 0));

		SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN, UDM_SETRANGE, 0, MAKELONG(50, 0));
		SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN, UDM_SETPOS, 0, MAKELONG(db_get_dw(NULL, "CLUI", "LeftOffset", SETTING_LEFTOFFSET_DEFAULT), 0));

		SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN2, UDM_SETRANGE, 0, MAKELONG(50, 0));
		SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN2, UDM_SETPOS, 0, MAKELONG(db_get_dw(NULL, "CLUI", "RightOffset", SETTING_RIGHTOFFSET_DEFAULT), 0));

		SendDlgItemMessage(hwndDlg, IDC_SBAR_BORDER_TOP_SPIN, UDM_SETRANGE, 0, MAKELONG(50, 0));
		SendDlgItemMessage(hwndDlg, IDC_SBAR_BORDER_TOP_SPIN, UDM_SETPOS, 0, MAKELONG(db_get_dw(NULL, "CLUI", "TopOffset", SETTING_TOPOFFSET_DEFAULT), 0));

		SendDlgItemMessage(hwndDlg, IDC_SBAR_BORDER_BOTTOM_SPIN, UDM_SETRANGE, 0, MAKELONG(50, 0));
		SendDlgItemMessage(hwndDlg, IDC_SBAR_BORDER_BOTTOM_SPIN, UDM_SETPOS, 0, MAKELONG(db_get_dw(NULL, "CLUI", "BottomOffset", SETTING_BOTTOMOFFSET_DEFAULT), 0));

		SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN3, UDM_SETRANGE, 0, MAKELONG(50, 0));
		SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN3, UDM_SETPOS, 0, MAKELONG(db_get_dw(NULL, "CLUI", "SpaceBetween", SETTING_SPACEBETWEEN_DEFAULT), 2));

		{
			TCHAR *align[] = { LPGENT("Left"), LPGENT("Center"), LPGENT("Right") };
			for (int i = 0; i < SIZEOF(align); i++)
				SendDlgItemMessage(hwndDlg, IDC_SBAR_HORIZ_ALIGN, CB_ADDSTRING, 0, (LPARAM)TranslateTS(align[i]));
			SendDlgItemMessage(hwndDlg, IDC_SBAR_HORIZ_ALIGN, CB_SETCURSEL, db_get_b(NULL, "CLUI", "Align", SETTING_ALIGN_DEFAULT), 0);
		}

		{
			TCHAR *align[] = { LPGENT("Top"), LPGENT("Center"), LPGENT("Bottom") };
			for (int i = 0; i < SIZEOF(align); i++)
				SendDlgItemMessage(hwndDlg, IDC_SBAR_VERT_ALIGN, CB_ADDSTRING, 0, (LPARAM)TranslateTS(align[i]));
			SendDlgItemMessage(hwndDlg, IDC_SBAR_VERT_ALIGN, CB_SETCURSEL, db_get_b(NULL, "CLUI", "VAlign", SETTING_VALIGN_DEFAULT), 0);
		}

		{
			int en = IsDlgButtonChecked(hwndDlg, IDC_SHOWSBAR);
			int en_icons = IsDlgButtonChecked(hwndDlg, IDC_SHOWICON);

			EnableWindow(GetDlgItem(hwndDlg, IDC_EQUALSECTIONS), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_OFFSETSPIN), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_OFFSETICON), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_OFFSETSPIN2), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_OFFSETICON2), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_OFFSETSPIN3), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_OFFSETICON3), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_MULTI_COUNT), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_MULTI_SPIN), en);

			EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWICON), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWPROTO), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWSTATUS), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_RIGHTSTATUS), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_RIGHTMIRANDA), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_USECONNECTINGICON), en && en_icons);
			EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWXSTATUSNAME), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWXSTATUS), en && en_icons);
			EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWBOTH), en && en_icons && IsDlgButtonChecked(hwndDlg, IDC_SHOWXSTATUS) && !IsDlgButtonChecked(hwndDlg, IDC_SHOWNORMAL));
			EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWNORMAL), en && en_icons && IsDlgButtonChecked(hwndDlg, IDC_SHOWXSTATUS) && !IsDlgButtonChecked(hwndDlg, IDC_SHOWBOTH));
			EnableWindow(GetDlgItem(hwndDlg, IDC_TRANSPARENTOVERLAY), en && en_icons && IsDlgButtonChecked(hwndDlg, IDC_SHOWXSTATUS) && IsDlgButtonChecked(hwndDlg, IDC_SHOWNORMAL) && !IsDlgButtonChecked(hwndDlg, IDC_SHOWBOTH));
			EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWUNREADEMAIL), en);

			EnableWindow(GetDlgItem(hwndDlg, IDC_OFFSETICON_LEFT), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_OFFSETSPIN_LEFT), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_OFFSETICON_RIGHT), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_OFFSETSPIN_RIGHT), en);


			EnableWindow(GetDlgItem(hwndDlg, IDC_STATUSBAR_PER_PROTO), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_STATUSBAR_PROTO_LIST), en && IsDlgButtonChecked(hwndDlg, IDC_STATUSBAR_PER_PROTO));
			EnableWindow(GetDlgItem(hwndDlg, IDC_SBAR_USE_ACCOUNT_SETTINGS), FALSE);
		}

		UpdateStatusBarOptionsDisplay(hwndDlg);
		return TRUE;

	case WM_USER + 1:


	case WM_COMMAND:
		if ((LOWORD(wParam) == IDC_SBAR_VERT_ALIGN || (LOWORD(wParam) == IDC_SBAR_HORIZ_ALIGN) && HIWORD(wParam) == CBN_SELCHANGE))
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
		else if (LOWORD(wParam) == IDC_SHOWSBAR) {
			int en = IsDlgButtonChecked(hwndDlg,IDC_SHOWSBAR);
			int en_icons = IsDlgButtonChecked(hwndDlg,IDC_SHOWICON );
			EnableWindow(GetDlgItem(hwndDlg,IDC_SHOWICON),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_SHOWPROTO),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_SHOWSTATUS),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_RIGHTSTATUS),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_RIGHTMIRANDA),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_EQUALSECTIONS),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_USECONNECTINGICON),en && en_icons);
			EnableWindow(GetDlgItem(hwndDlg,IDC_OFFSETSPIN),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_OFFSETICON),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_OFFSETSPIN2),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_OFFSETICON2),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_OFFSETSPIN3),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_OFFSETICON3),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_SBAR_BORDER_TOP),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_SBAR_BORDER_TOP_SPIN),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_SBAR_BORDER_BOTTOM),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_SBAR_BORDER_BOTTOM_SPIN),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_SBAR_HORIZ_ALIGN),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_SHOWXSTATUSNAME),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_SHOWXSTATUS),en && en_icons);
			EnableWindow(GetDlgItem(hwndDlg,IDC_SHOWUNREADEMAIL),en);

			EnableWindow(GetDlgItem(hwndDlg,IDC_MULTI_COUNT),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_MULTI_SPIN),en);

			EnableWindow(GetDlgItem(hwndDlg,IDC_STATUSBAR_PER_PROTO),en);
			EnableWindow(GetDlgItem(hwndDlg,IDC_STATUSBAR_PROTO_LIST),en && IsDlgButtonChecked(hwndDlg,IDC_STATUSBAR_PER_PROTO));
			EnableWindow(GetDlgItem(hwndDlg,IDC_SBAR_USE_ACCOUNT_SETTINGS),en && IsDlgButtonChecked(hwndDlg,IDC_STATUSBAR_PER_PROTO));

			UpdateStatusBarOptionsDisplay(hwndDlg);

			SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
		}
		else if (LOWORD(wParam) == IDC_STATUSBAR_PER_PROTO) {
			int en = IsDlgButtonChecked(hwndDlg, IDC_STATUSBAR_PER_PROTO);
			EnableWindow(GetDlgItem(hwndDlg, IDC_STATUSBAR_PROTO_LIST), en);
			EnableWindow(GetDlgItem(hwndDlg, IDC_SBAR_HIDE_ACCOUNT_COMPLETELY), en && perProto);
			EnableWindow(GetDlgItem(hwndDlg, IDC_SBAR_USE_ACCOUNT_SETTINGS), en);

			UpdateStatusBarOptionsDisplay(hwndDlg);

			SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
		}
		else if (LOWORD(wParam) == IDC_SHOWXSTATUS ||
			LOWORD(wParam) == IDC_SHOWBOTH ||
			LOWORD(wParam) == IDC_SHOWNORMAL ||
			LOWORD(wParam) == IDC_TRANSPARENTOVERLAY ||
			LOWORD(wParam) == IDC_SHOWXSTATUSNAME)
			UpdateXStatusIconOptions(hwndDlg, perProto, dat, curSelProto);
		else if (LOWORD(wParam) == IDC_SBAR_USE_ACCOUNT_SETTINGS) {
			if (perProto) {
				dat[curSelProto].AccountIsCustomized = IsDlgButtonChecked(hwndDlg, IDC_SBAR_USE_ACCOUNT_SETTINGS);
				UpdateStatusBarOptionsDisplay(hwndDlg);
			}
		}
		else if (LOWORD(wParam) == IDC_SBAR_HIDE_ACCOUNT_COMPLETELY) {
			if (perProto)
				dat[curSelProto].HideAccount = IsDlgButtonChecked(hwndDlg, IDC_SBAR_HIDE_ACCOUNT_COMPLETELY);
		}
		else if (LOWORD(wParam) == IDC_USECONNECTINGICON) {
			if (perProto)
				dat[curSelProto].UseConnectingIcon = IsDlgButtonChecked(hwndDlg, IDC_USECONNECTINGICON);
			else
				_GlobalOptions.UseConnectingIcon = IsDlgButtonChecked(hwndDlg, IDC_USECONNECTINGICON);
		}
		else if (LOWORD(wParam) == IDC_SHOWUNREADEMAIL) {
			if (perProto)
				dat[curSelProto].ShowUnreadEmails = IsDlgButtonChecked(hwndDlg, IDC_SHOWUNREADEMAIL);
			else
				_GlobalOptions.ShowUnreadEmails = IsDlgButtonChecked(hwndDlg, IDC_SHOWUNREADEMAIL);
		}
		else if (LOWORD(wParam) == IDC_SHOWICON || LOWORD(wParam) == IDC_SHOWPROTO || LOWORD(wParam) == IDC_SHOWSTATUS) {
			BYTE val = (IsDlgButtonChecked(hwndDlg, IDC_SHOWICON) ? 1 : 0) |
				(IsDlgButtonChecked(hwndDlg, IDC_SHOWPROTO) ? 2 : 0) |
				(IsDlgButtonChecked(hwndDlg, IDC_SHOWSTATUS) ? 4 : 0);
			if (perProto)
				dat[curSelProto].SBarShow = val;
			else
				_GlobalOptions.SBarShow = val;

			UpdateStatusBarOptionsDisplay(hwndDlg);
		}
		else if (LOWORD(wParam) == IDC_RIGHTSTATUS || LOWORD(wParam) == IDC_RIGHTMIRANDA) {
			if (perProto)
				dat[curSelProto].SBarRightClk = IsDlgButtonChecked(hwndDlg, IDC_RIGHTMIRANDA);
			else
				_GlobalOptions.SBarRightClk = IsDlgButtonChecked(hwndDlg, IDC_RIGHTMIRANDA);
		}
		else if (LOWORD(wParam) == IDC_OFFSETICON_LEFT) {
			if (perProto)
				dat[curSelProto].PaddingLeft = (DWORD)SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN_LEFT, UDM_GETPOS, 0, 0);
			else
				_GlobalOptions.PaddingLeft = (DWORD)SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN_LEFT, UDM_GETPOS, 0, 0);
		}
		else if (LOWORD(wParam) == IDC_OFFSETICON_RIGHT) {
			if (perProto)
				dat[curSelProto].PaddingRight = (DWORD)SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN_RIGHT, UDM_GETPOS, 0, 0);
			else
				_GlobalOptions.PaddingRight = (DWORD)SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN_RIGHT, UDM_GETPOS, 0, 0);
		}
		else if ((LOWORD(wParam) == IDC_MULTI_COUNT || LOWORD(wParam) == IDC_OFFSETICON || LOWORD(wParam) == IDC_OFFSETICON2
			|| LOWORD(wParam) == IDC_OFFSETICON3 || LOWORD(wParam) == IDC_SBAR_BORDER_BOTTOM || LOWORD(wParam) == IDC_SBAR_BORDER_TOP)
			&& (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
			return 0; // dont make apply enabled during buddy set crap
		else if (LOWORD(wParam) == IDC_STATUSBAR_PROTO_LIST) {
			UpdateStatusBarOptionsDisplay(hwndDlg);
			return 0;
		}
		SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
		break;
	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			{
				int count = db_get_dw(0, "Protocols", "ProtoCount", -1);
				db_set_b(NULL, "CLUI", "SBarPerProto", IsDlgButtonChecked(hwndDlg, IDC_STATUSBAR_PER_PROTO));

				for (int i = 0; i < count; i++) {
					StatusBarProtocolOptions sbpo = dat[i];
					char *defProto = sbpo.szName;

					char settingBuf[256];
					mir_snprintf(settingBuf, SIZEOF(settingBuf), "SBarAccountIsCustom_%s", defProto);
					db_set_b(NULL, "CLUI", settingBuf, (BYTE)sbpo.AccountIsCustomized);

					mir_snprintf(settingBuf, SIZEOF(settingBuf), "HideAccount_%s", defProto);
					db_set_b(NULL, "CLUI", settingBuf, (BYTE)sbpo.HideAccount);

					mir_snprintf(settingBuf, SIZEOF(settingBuf), "SBarShow_%s", defProto);
					db_set_b(NULL, "CLUI", settingBuf, (BYTE)sbpo.SBarShow);
					mir_snprintf(settingBuf, SIZEOF(settingBuf), "SBarRightClk_%s", defProto);
					db_set_b(NULL, "CLUI", settingBuf, (BYTE)sbpo.SBarRightClk);
					mir_snprintf(settingBuf, SIZEOF(settingBuf), "UseConnectingIcon_%s", defProto);
					db_set_b(NULL, "CLUI", settingBuf, (BYTE)sbpo.UseConnectingIcon);
					mir_snprintf(settingBuf, SIZEOF(settingBuf), "ShowUnreadEmails_%s", defProto);
					db_set_b(NULL, "CLUI", settingBuf, (BYTE)sbpo.ShowUnreadEmails);
					mir_snprintf(settingBuf, SIZEOF(settingBuf), "ShowXStatus_%s", defProto);
					db_set_b(NULL, "CLUI", settingBuf, sbpo.ShowXStatus);
					mir_snprintf(settingBuf, SIZEOF(settingBuf), "PaddingLeft_%s", defProto);
					db_set_dw(NULL, "CLUI", settingBuf, sbpo.PaddingLeft);
					mir_snprintf(settingBuf, SIZEOF(settingBuf), "PaddingRight_%s", defProto);
					db_set_dw(NULL, "CLUI", settingBuf, sbpo.PaddingRight);
				}

				db_set_b(NULL, "CLUI", "SBarShow", (BYTE)_GlobalOptions.SBarShow);
				db_set_b(NULL, "CLUI", "SBarRightClk", (BYTE)_GlobalOptions.SBarRightClk);
				db_set_b(NULL, "CLUI", "UseConnectingIcon", (BYTE)_GlobalOptions.UseConnectingIcon);
				db_set_b(NULL, "CLUI", "ShowUnreadEmails", (BYTE)_GlobalOptions.ShowUnreadEmails);
				db_set_b(NULL, "CLUI", "ShowXStatus", _GlobalOptions.ShowXStatus);
				db_set_dw(NULL, "CLUI", "PaddingLeft", _GlobalOptions.PaddingLeft);
				db_set_dw(NULL, "CLUI", "PaddingRight", _GlobalOptions.PaddingRight);


				db_set_b(NULL, "CLUI", "StatusBarProtosPerLine", (BYTE)SendDlgItemMessage(hwndDlg, IDC_MULTI_SPIN, UDM_GETPOS, 0, 0));
				db_set_b(NULL, "CLUI", "EqualSections", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_EQUALSECTIONS));
				db_set_b(NULL, "CLUI", "Align", (BYTE)SendDlgItemMessage(hwndDlg, IDC_SBAR_HORIZ_ALIGN, CB_GETCURSEL, 0, 0));
				db_set_b(NULL, "CLUI", "VAlign", (BYTE)SendDlgItemMessage(hwndDlg, IDC_SBAR_VERT_ALIGN, CB_GETCURSEL, 0, 0));
				db_set_dw(NULL, "CLUI", "LeftOffset", (DWORD)SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN, UDM_GETPOS, 0, 0));
				db_set_dw(NULL, "CLUI", "RightOffset", (DWORD)SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN2, UDM_GETPOS, 0, 0));
				db_set_dw(NULL, "CLUI", "TopOffset", (DWORD)SendDlgItemMessage(hwndDlg, IDC_SBAR_BORDER_TOP_SPIN, UDM_GETPOS, 0, 0));
				db_set_dw(NULL, "CLUI", "BottomOffset", (DWORD)SendDlgItemMessage(hwndDlg, IDC_SBAR_BORDER_BOTTOM_SPIN, UDM_GETPOS, 0, 0));
				db_set_dw(NULL, "CLUI", "SpaceBetween", (DWORD)SendDlgItemMessage(hwndDlg, IDC_OFFSETSPIN3, UDM_GETPOS, 0, 0));
				db_set_b(NULL, "CLUI", "ShowSBar", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SHOWSBAR));

				LoadStatusBarData();
				cliCluiProtocolStatusChanged(0, 0);
				return TRUE;
			}
		}
		break;

	case WM_DESTROY:
		mir_free(dat);
		break;
	}
	return FALSE;
}
Ejemplo n.º 15
0
static INT_PTR CALLBACK DlgProcMsnOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
    case WM_INITDIALOG:
        TranslateDialogDefault(hwndDlg);
        {
            SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
            CMsnProto* proto = (CMsnProto*)lParam;

            SetDlgItemTextA(hwndDlg, IDC_HANDLE, proto->MyOptions.szEmail);

            char tBuffer[MAX_PATH];
            if (!db_get_static(NULL, proto->m_szModuleName, "Password", tBuffer, sizeof(tBuffer))) {
                tBuffer[16] = 0;
                SetDlgItemTextA(hwndDlg, IDC_PASSWORD, tBuffer);
            }
            SendDlgItemMessage(hwndDlg, IDC_PASSWORD, EM_SETLIMITTEXT, 16, 0);

            HWND wnd = GetDlgItem(hwndDlg, IDC_HANDLE2);
            DBVARIANT dbv;
            if (!proto->getTString("Nick", &dbv)) {
                SetWindowText(wnd, dbv.ptszVal);
                db_free(&dbv);
            }
            EnableWindow(wnd, proto->msnLoggedIn);
            EnableWindow(GetDlgItem(hwndDlg, IDC_MOBILESEND), proto->msnLoggedIn &&
                         proto->getByte("MobileEnabled", 0) && proto->getByte("MobileAllowed", 0));

            CheckDlgButton(hwndDlg, IDC_MOBILESEND, proto->getByte("MobileAllowed", 0) ? BST_CHECKED : BST_UNCHECKED);
            CheckDlgButton(hwndDlg, IDC_SENDFONTINFO, proto->getByte("SendFontInfo", 1) ? BST_CHECKED : BST_UNCHECKED);
            CheckDlgButton(hwndDlg, IDC_MANAGEGROUPS, proto->getByte("ManageServer", 1) ? BST_CHECKED : BST_UNCHECKED);

            int tValue = proto->getByte("RunMailerOnHotmail", 0);
            CheckDlgButton(hwndDlg, IDC_RUN_APP_ON_HOTMAIL, tValue ? BST_CHECKED : BST_UNCHECKED);
            EnableWindow(GetDlgItem(hwndDlg, IDC_MAILER_APP), tValue);
            EnableWindow(GetDlgItem(hwndDlg, IDC_ENTER_MAILER_APP), tValue);

            if (!db_get_static(NULL, proto->m_szModuleName, "MailerPath", tBuffer, sizeof(tBuffer)))
                SetDlgItemTextA(hwndDlg, IDC_MAILER_APP, tBuffer);

            if (!proto->msnLoggedIn) {
                EnableWindow(GetDlgItem(hwndDlg, IDC_MANAGEGROUPS), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_DISABLE_ANOTHER_CONTACTS), FALSE);
            }
            else CheckDlgButton(hwndDlg, IDC_DISABLE_ANOTHER_CONTACTS, proto->msnOtherContactsBlocked ? BST_CHECKED : BST_UNCHECKED);
        }
        return TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDC_NEWMSNACCOUNTLINK) {
            Utils_OpenUrl("https://signup.live.com");
            return TRUE;
        }

        if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) {
            switch (LOWORD(wParam)) {
            case IDC_HANDLE:
            case IDC_PASSWORD:
            case IDC_HANDLE2:
            case IDC_GATEWAYSERVER:
            case IDC_YOURHOST:
            case IDC_DIRECTSERVER:
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
            }
        }

        if (HIWORD(wParam) == BN_CLICKED) {
            switch (LOWORD(wParam)) {
            case IDC_SENDFONTINFO:
            case IDC_DISABLE_ANOTHER_CONTACTS:
            case IDC_MOBILESEND:
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
                break;

            case IDC_MANAGEGROUPS:
                if (IsDlgButtonChecked(hwndDlg, IDC_MANAGEGROUPS)) {
                    if (IDYES == MessageBox(hwndDlg,
                                            TranslateT("Server groups import may change your contact list layout after next login. Do you want to upload your groups to the server?"),
                                            TranslateT("MSN Protocol"), MB_YESNOCANCEL)) {
                        CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
                        proto->MSN_UploadServerGroups(NULL);
                    }
                }
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
                break;

            case IDC_RUN_APP_ON_HOTMAIL:
            {
                BOOL tIsChosen = IsDlgButtonChecked(hwndDlg, IDC_RUN_APP_ON_HOTMAIL);
                EnableWindow(GetDlgItem(hwndDlg, IDC_MAILER_APP), tIsChosen);
                EnableWindow(GetDlgItem(hwndDlg, IDC_ENTER_MAILER_APP), tIsChosen);
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
            }
            break;

            case IDC_ENTER_MAILER_APP:
                char szFile[MAX_PATH + 2];
                {
                    HWND tEditField = GetDlgItem(hwndDlg, IDC_MAILER_APP);

                    GetWindowTextA(tEditField, szFile, _countof(szFile));

                    size_t tSelectLen = 0;

                    if (szFile[0] == '\"') {
                        char* p = strchr(szFile + 1, '\"');
                        if (p != NULL) {
                            *p = '\0';
                            memmove(szFile, szFile + 1, mir_strlen(szFile));
                            tSelectLen += 2;
                            goto LBL_Continue;
                        }
                    }

                    char* p = strchr(szFile, ' ');
                    if (p != NULL) *p = '\0';
LBL_Continue:
                    tSelectLen += mir_strlen(szFile);

                    OPENFILENAMEA ofn = { 0 };
                    ofn.lStructSize = sizeof(ofn);
                    ofn.hwndOwner = hwndDlg;
                    ofn.nMaxFile = _countof(szFile);
                    ofn.lpstrFile = szFile;
                    ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
                    if (GetOpenFileNameA(&ofn) != TRUE)
                        break;

                    if (strchr(szFile, ' ') != NULL) {
                        char tmpBuf[MAX_PATH + 2];
                        mir_snprintf(tmpBuf, _countof(tmpBuf), "\"%s\"", szFile);
                        mir_strcpy(szFile, tmpBuf);
                    }

                    SendMessage(tEditField, EM_SETSEL, 0, tSelectLen);
                    SendMessageA(tEditField, EM_REPLACESEL, TRUE, LPARAM(szFile));
                    SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
                }
            }
        }
        break;

    case WM_NOTIFY:
        if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY) {
            bool reconnectRequired = false;
            TCHAR screenStr[MAX_PATH];
            char  password[100], szEmail[MSN_MAX_EMAIL_LEN];
            DBVARIANT dbv;

            CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

            GetDlgItemTextA(hwndDlg, IDC_HANDLE, szEmail, _countof(szEmail));
            if (mir_strcmp(_strlwr(szEmail), proto->MyOptions.szEmail)) {
                reconnectRequired = true;
                mir_strcpy(proto->MyOptions.szEmail, szEmail);
                proto->setString("e-mail", szEmail);
                proto->setString("wlid", szEmail);
                proto->setDword("netId", (proto->MyOptions.netId = proto->GetMyNetID()));
            }

            GetDlgItemTextA(hwndDlg, IDC_PASSWORD, password, _countof(password));
            if (!proto->getString("Password", &dbv)) {
                if (mir_strcmp(password, dbv.pszVal)) {
                    reconnectRequired = true;
                    proto->setString("Password", password);
                }
                db_free(&dbv);
            }
            else {
                reconnectRequired = true;
                proto->setString("Password", password);
            }

#ifdef OBSOLETE
            GetDlgItemText(hwndDlg, IDC_HANDLE2, screenStr, _countof(screenStr));
            if (!proto->getTString("Nick", &dbv)) {
                if (mir_tstrcmp(dbv.ptszVal, screenStr))
                    proto->MSN_SendNickname(screenStr);
                db_free(&dbv);
            }
            else proto->MSN_SendNickname(screenStr);

            BYTE mblsnd = IsDlgButtonChecked(hwndDlg, IDC_MOBILESEND) == BST_CHECKED;
            if (mblsnd != proto->getByte("MobileAllowed", 0)) {
                proto->msnNsThread->sendPacket("PRP", "MOB %c", mblsnd ? 'Y' : 'N');
                proto->MSN_SetServerStatus(proto->m_iStatus);
            }

            unsigned tValue = IsDlgButtonChecked(hwndDlg, IDC_DISABLE_ANOTHER_CONTACTS);
            if (tValue != proto->msnOtherContactsBlocked && proto->msnLoggedIn) {
                proto->msnOtherContactsBlocked = tValue;
                proto->msnNsThread->sendPacket("BLP", tValue ? "BL" : "AL");
                proto->MSN_ABUpdateAttr(NULL, "MSN.IM.BLP", tValue ? "0" : "1");
                break;
            }
#endif

            proto->setByte("SendFontInfo", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SENDFONTINFO));
            proto->setByte("RunMailerOnHotmail", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_RUN_APP_ON_HOTMAIL));
            proto->setByte("ManageServer", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_MANAGEGROUPS));

            GetDlgItemText(hwndDlg, IDC_MAILER_APP, screenStr, _countof(screenStr));
            proto->setTString("MailerPath", screenStr);

            if (reconnectRequired && proto->msnLoggedIn)
                MessageBox(hwndDlg,
                           TranslateT("The changes you have made require you to reconnect to the MSN Messenger network before they take effect"),
                           TranslateT("MSN Options"), MB_OK);

            proto->LoadOptions();
            return TRUE;
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 16
0
static bool LoadMind(const TCHAR* filename, int &line)
{
	TCHAR* fullname = GetFullName(filename);
	HCURSOR newCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
	HCURSOR oldCur = SetCursor(newCur);
	#ifdef DEBUG_LOAD_TIME
	unsigned __int64 t = __rdtsc();
	#endif
	Mind* mind = new Mind();
	line = -1;
	try {
		mind->Load(fullname);
	}
	catch (Mind::CorruptedMind c) {
		line = c.line;
		delete mind;
		if (fullname != filename)
			delete[] fullname;
		SetCursor(oldCur);
		return false;
	}
	catch (...) {
		delete mind;
		if (fullname != filename)
			delete[] fullname;
		SetCursor(oldCur);
		return false;
	}
	if (fullname != filename)
		delete[] fullname;

	#ifdef DEBUG_LOAD_TIME
	t = __rdtsc() - t;
	char dest[101];
	mir_snprintf(dest, "%I64d ticks\n", t / 3200000);
	MessageBoxA(NULL, dest, NULL, 0);
	//exit(0);
	#endif
	SetCursor(oldCur);
	HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(IDR_SMILES), _T("SMILES"));
	if (!hRes) {
		delete mind;
		return false;
	}
	DWORD size = SizeofResource(hInst, hRes);
	if (!size) {
		delete mind;
		return false;
	}
	HGLOBAL hGlob = LoadResource(hInst, hRes);
	if (!hGlob) {
		delete mind;
		return false;
	}
	void *data = LockResource(hGlob);
	if (!data) {
		FreeResource(hGlob);
		delete mind;
		return false;
	}
	bool res = true;
	try {
		mind->LoadSmiles(data, size);
	}
	catch (...) {
		res = false;
	}
	UnlockResource(data);
	FreeResource(hGlob);
	if (!res) {
		delete mind;
		return false;
	}
	delete bot;
	bot = new TalkBot(*mind);
	delete mind;
	UpdateEngine();
	return true;
}
Ejemplo n.º 17
0
static void EmailOnClick(Info *info, const char *text)
{
	char cmd[1024];
	mir_snprintf(cmd, MAX_REGS(cmd), "mailto:%s", text);
	ShellExecute(NULL, "open", cmd, NULL, NULL, SW_SHOW);
}
Ejemplo n.º 18
0
UINT CDropbox::RequestAcceessTokenAsync(void *owner, void* param)
{
	HWND hwndDlg = (HWND)param;
	CDropbox *instance = (CDropbox*)owner;

	EnableWindow(GetDlgItem(hwndDlg, IDC_AUTHORIZE), FALSE);
	SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("in process..."));

	if (instance->HasAccessToken())
		instance->DestroyAcceessToken();

	char requestToken[128];
	GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, requestToken, SIZEOF(requestToken));

	char data[1024];
	mir_snprintf(
		data,
		SIZEOF(data),
		"grant_type=authorization_code&code=%s",
		requestToken);

	HttpRequest *request = new HttpRequest(instance->hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/oauth2/token");
	request->AddBasicAuthHeader(DROPBOX_API_KEY, DROPBOX_API_SECRET);
	request->AddHeader("Content-Type", "application/x-www-form-urlencoded");
	request->pData = mir_strdup(data);
	request->dataLength = (int)strlen(data);

	mir_ptr<NETLIBHTTPREQUEST> response(request->Send());

	delete request;

	MCONTACT hContact = instance->GetDefaultContact();

	if (response)
	{
		JSONROOT root(response->pData);
		if (root)
		{
			if (response->resultCode == HTTP_STATUS_OK)
			{
				JSONNODE *node = json_get(root, "access_token");
				ptrA access_token = ptrA(mir_u2a(json_as_string(node)));
				db_set_s(NULL, MODULE, "TokenSecret", access_token);

				if (hContact)
				{
					if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
						db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE);
				}

				instance->RequestAccountInfo();

				if (hwndDlg)
					SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you have been authorized"));
				/*else
					ShowNotification(TranslateT("you have been authorized"), MB_ICONINFORMATION);*/
			}
			else
			{
				JSONNODE *node = json_get(root, "error_description");
				ptrW error_description(json_as_string(node));

				if (hwndDlg)
					SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, error_description);
				/*else
					ShowNotification((wchar_t*)error_description, MB_ICONERROR);*/
			}
		}
	}
	else
	{
		if (hwndDlg)
			SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond"));

		HandleHttpResponseError(instance->hNetlibUser, response);
	}

	SetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, "");

	return 0;
}
Ejemplo n.º 19
0
int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC)
{
	int iconHeight = GetSystemMetrics(SM_CYSMICON)+2;
	int i;

	// Count visible protos
	RECT rc;
	GetClientRect(hWnd, &rc);
	if (g_CluiData.fDisableSkinEngine) {
		if (g_StatusBarData.bkUseWinColors && xpt_IsThemed(g_StatusBarData.hTheme))
			xpt_DrawTheme(g_StatusBarData.hTheme, hWnd, hDC, 0, 0, &rc, &rc);
		else
			DrawBackGround(hWnd, hDC, g_StatusBarData.hBmpBackground, g_StatusBarData.bkColour, g_StatusBarData.backgroundBmpUse);
	}
	else SkinDrawGlyph(hDC, &rc, &rc, "Main,ID=StatusBar"); //TBD

	g_StatusBarData.nProtosPerLine = db_get_b(NULL, "CLUI", "StatusBarProtosPerLine", SETTING_PROTOSPERLINE_DEFAULT);
	HFONT hOldFont = g_clcPainter.ChangeToFont(hDC, NULL, FONTID_STATUSBAR_PROTONAME, NULL);

	SIZE textSize = { 0 };
	GetTextExtentPoint32A(hDC, " ", 1, &textSize);
	int spaceWidth = textSize.cx;
	int textY = rc.top + ((rc.bottom - rc.top - textSize.cy) >> 1);
	int iconY = rc.top + ((rc.bottom - rc.top - GetSystemMetrics(SM_CXSMICON)) >> 1);

	ProtosData.destroy();

	int protoCount;
	PROTOACCOUNT **accs;
	ProtoEnumAccounts(&protoCount, &accs);
	if (protoCount == 0)
		return 0;

	int iProtoInStatusMenu = 0;
	for (int j = 0; j < protoCount; j++) {
		int i = pcli->pfnGetAccountIndexByPos(j);
		if (i == -1)
			continue;

		char *szProto = accs[i]->szModuleName;
		if (!pcli->pfnGetProtocolVisibility(szProto))
			continue;

		char buf[256];
		mir_snprintf(buf, SIZEOF(buf), "SBarAccountIsCustom_%s", szProto);

		ProtoItemData *p = NULL;

		if (g_StatusBarData.perProtoConfig && db_get_b(NULL, "CLUI", buf, SETTING_SBARACCOUNTISCUSTOM_DEFAULT)) {
			mir_snprintf(buf, SIZEOF(buf), "HideAccount_%s", szProto);
			if (db_get_b(NULL, "CLUI", buf, SETTING_SBARHIDEACCOUNT_DEFAULT)) {
				iProtoInStatusMenu++;
				continue;
			}

			mir_snprintf(buf, SIZEOF(buf), "SBarShow_%s", szProto);

			BYTE showOps = db_get_b(NULL, "CLUI", buf, SETTING_SBARSHOW_DEFAULT);
			p = new ProtoItemData;
			p->bShowProtoIcon = (showOps & 1) != 0;
			p->bShowProtoName = (showOps & 2) != 0;
			p->bShowStatusName = (showOps & 4) != 0;

			mir_snprintf(buf, SIZEOF(buf), "ShowXStatus_%s", szProto);
			p->xStatusMode = db_get_b(NULL, "CLUI", buf, SETTING_SBARSHOW_DEFAULT);

			mir_snprintf(buf, SIZEOF(buf), "UseConnectingIcon_%s", szProto);
			p->bConnectingIcon = db_get_b(NULL, "CLUI", buf, SETTING_USECONNECTINGICON_DEFAULT) != 0;

			mir_snprintf(buf, SIZEOF(buf), "ShowUnreadEmails_%s", szProto);
			p->bShowProtoEmails = db_get_b(NULL, "CLUI", buf, SETTING_SHOWUNREADEMAILS_DEFAULT) != 0;

			mir_snprintf(buf, SIZEOF(buf), "SBarRightClk_%s", szProto);
			p->SBarRightClk = db_get_b(NULL, "CLUI", buf, SETTING_SBARRIGHTCLK_DEFAULT) != 0;

			mir_snprintf(buf, SIZEOF(buf), "PaddingLeft_%s", szProto);
			p->PaddingLeft = db_get_dw(NULL, "CLUI", buf, SETTING_PADDINGLEFT_DEFAULT);

			mir_snprintf(buf, SIZEOF(buf), "PaddingRight_%s", szProto);
			p->PaddingRight = db_get_dw(NULL, "CLUI", buf, SETTING_PADDINGRIGHT_DEFAULT);
		}
		else {
			p = new ProtoItemData;
			p->bShowProtoIcon = g_StatusBarData.bShowProtoIcon;
			p->bShowProtoName = g_StatusBarData.bShowProtoName;
			p->bShowStatusName = g_StatusBarData.bShowStatusName;
			p->xStatusMode = g_StatusBarData.xStatusMode;
			p->bConnectingIcon = g_StatusBarData.bConnectingIcon;
			p->bShowProtoEmails = g_StatusBarData.bShowProtoEmails;
			p->SBarRightClk = 0;
			p->PaddingLeft = 0;
			p->PaddingRight = 0;
		}

		p->iProtoStatus = CallProtoService(szProto, PS_GETSTATUS, 0, 0);

		if (p->iProtoStatus > ID_STATUS_OFFLINE)
			if (p->bShowProtoEmails == 1 && ProtoServiceExists(szProto, PS_GETUNREADEMAILCOUNT)) {
				int nEmails = (int)ProtoCallService(szProto, PS_GETUNREADEMAILCOUNT, 0, 0);
				if (nEmails > 0) {
					char buf[40];
					mir_snprintf(buf, SIZEOF(buf), "[%d]", nEmails);
					p->szProtoEMailCount = mir_strdup(buf);
				}
			}

		p->tszProtoHumanName = mir_tstrdup(accs[i]->tszAccountName);
		p->szAccountName = mir_strdup(szProto);
		p->szProtoName = mir_strdup(accs[i]->szProtoName);
		p->tszProtoStatusText = mir_tstrdup(pcli->pfnGetStatusModeDescription(p->iProtoStatus, 0));
		p->iProtoPos = iProtoInStatusMenu++;

		p->bIsDimmed = 0;
		if (g_CluiData.bFilterEffective & CLVM_FILTER_PROTOS) {
			char szTemp[2048];
			mir_snprintf(szTemp, SIZEOF(szTemp), "%s|", p->szAccountName);
			p->bIsDimmed = strstr(g_CluiData.protoFilter, szTemp) ? 0 : 1;
		}

		ProtosData.insert(p);
	}

	if (ProtosData.getCount() == 0)
		return 0;

	//START MULTILINE HERE 
	int orig_protoCount = protoCount;
	int orig_visProtoCount = ProtosData.getCount();
	int protosperline = 0;

	if (g_StatusBarData.nProtosPerLine)
		protosperline = g_StatusBarData.nProtosPerLine;
	else if (orig_visProtoCount)
		protosperline = orig_visProtoCount;
	else if (protoCount) {
		protosperline = protoCount;
		orig_visProtoCount = protoCount;
	}
	else {
		protosperline = 1;
		orig_visProtoCount = 1;
	}
	protosperline = min(protosperline, orig_visProtoCount);

	int linecount = protosperline ? (orig_visProtoCount + (protosperline - 1)) / protosperline : 1; //divide with rounding to up
	for (int line = 0; line < linecount; line++) {
		int rowheight = max(textSize.cy + 2, iconHeight);
		protoCount = min(protosperline, (orig_protoCount - line*protosperline));
		int visProtoCount = min(protosperline, (orig_visProtoCount - line*protosperline));
		GetClientRect(hWnd, &rc);

		rc.top += g_StatusBarData.rectBorders.top;
		rc.bottom -= g_StatusBarData.rectBorders.bottom;

		int aligndx = 0, maxwidth = 0, xstatus = 0, SumWidth = 0;

		int height = (rowheight*linecount);
		if (height > (rc.bottom - rc.top)) {
			rowheight = (rc.bottom - rc.top) / linecount;
			height = (rowheight*linecount);
		}

		int rowsdy = ((rc.bottom - rc.top) - height) / 2;
		if (rowheight*(line)+rowsdy < rc.top - rowheight) continue;
		if (rowheight*(line + 1) + rowsdy>rc.bottom + rowheight)
			break;

		if (g_StatusBarData.VAlign == 0) { //top
			rc.bottom = rc.top + rowheight*(line + 1);
			rc.top = rc.top + rowheight*line + 1;
		}
		else if (g_StatusBarData.VAlign == 1) { //center
			rc.bottom = rc.top + rowsdy + rowheight*(line + 1);
			rc.top = rc.top + rowsdy + rowheight*line + 1;
		}
		else if (g_StatusBarData.VAlign == 2) { //bottom
			rc.top = rc.bottom - (rowheight*(linecount - line));
			rc.bottom = rc.bottom - (rowheight*(linecount - line - 1) + 1);
		}

		textY = rc.top + (((rc.bottom - rc.top) - textSize.cy) / 2);
		iconY = rc.top + (((rc.bottom - rc.top) - iconHeight) / 2);

		//Code for each line
		DWORD sw;
		int rectwidth = rc.right - rc.left - g_StatusBarData.rectBorders.left - g_StatusBarData.rectBorders.right;
		if (visProtoCount > 1)
			sw = (rectwidth - (g_StatusBarData.extraspace*(visProtoCount - 1))) / visProtoCount;
		else
			sw = rectwidth;

		int *ProtoWidth = (int*)mir_alloc(sizeof(int)*visProtoCount);
		for (i = 0; i < visProtoCount; i++) {
			ProtoItemData &p = ProtosData[line*protosperline + i];

			DWORD w = p.PaddingLeft;
			w += p.PaddingRight;

			if (p.bShowProtoIcon) {
				w += GetSystemMetrics(SM_CXSMICON) + 1;

				p.extraIcon = NULL;
				if ((p.xStatusMode & 8) && p.iProtoStatus > ID_STATUS_OFFLINE) {
					TCHAR str[512];
					CUSTOM_STATUS cs = { sizeof(cs) };
					cs.flags = CSSF_MASK_NAME | CSSF_TCHAR;
					cs.ptszName = str;
					if (CallProtoService(p.szAccountName, PS_GETCUSTOMSTATUSEX, 0, (LPARAM)&cs) == 0)
						p.tszProtoXStatus = mir_tstrdup(str);
				}

				if ((p.xStatusMode & 3)) {
					if (p.iProtoStatus > ID_STATUS_OFFLINE) {
						if (ProtoServiceExists(p.szAccountName, PS_GETCUSTOMSTATUSICON))
							p.extraIcon = (HICON)ProtoCallService(p.szAccountName, PS_GETCUSTOMSTATUSICON, 0, 0);
						if (p.extraIcon && (p.xStatusMode & 3) == 3)
							w += GetSystemMetrics(SM_CXSMICON) + 1;
					}
				}
			}

			SIZE textSize;
			if (p.bShowProtoName) {
				GetTextExtentPoint32(hDC, p.tszProtoHumanName, lstrlen(p.tszProtoHumanName), &textSize);
				w += textSize.cx + 3 + spaceWidth;
			}

			if (p.bShowProtoEmails && p.szProtoEMailCount) {
				GetTextExtentPoint32A(hDC, p.szProtoEMailCount, lstrlenA(p.szProtoEMailCount), &textSize);
				w += textSize.cx + 3 + spaceWidth;
			}

			if (p.bShowStatusName) {
				GetTextExtentPoint32(hDC, p.tszProtoStatusText, lstrlen(p.tszProtoStatusText), &textSize);
				w += textSize.cx + 3 + spaceWidth;
			}

			if ((p.xStatusMode & 8) && p.tszProtoXStatus) {
				GetTextExtentPoint32(hDC, p.tszProtoXStatus, lstrlen(p.tszProtoXStatus), &textSize);
				w += textSize.cx + 3 + spaceWidth;
			}

			if (p.bShowProtoName || (p.bShowProtoEmails && p.szProtoEMailCount) || p.bShowStatusName || ((p.xStatusMode & 8) && p.tszProtoXStatus))
				w -= spaceWidth;

			p.fullWidth = w;
			if (g_StatusBarData.sameWidth) {
				ProtoWidth[i] = sw;
				SumWidth += w;
			}
			else {
				ProtoWidth[i] = w;
				SumWidth += w;
			}
		}

		// Reposition rects
		for (i = 0; i < visProtoCount; i++)
			if (ProtoWidth[i] > maxwidth)
				maxwidth = ProtoWidth[i];

		if (g_StatusBarData.sameWidth) {
			for (i = 0; i < visProtoCount; i++)
				ProtoWidth[i] = maxwidth;
			SumWidth = maxwidth * visProtoCount;
		}
		SumWidth += (visProtoCount - 1) * (g_StatusBarData.extraspace + 1);

		if (SumWidth > rectwidth) {
			float f = (float)rectwidth / SumWidth;
			SumWidth = 0;
			for (i = 0; i < visProtoCount; i++) {
				ProtoWidth[i] = (int)((float)ProtoWidth[i] * f);
				SumWidth += ProtoWidth[i];
			}
			SumWidth += (visProtoCount - 1)*(g_StatusBarData.extraspace + 1);
		}

		if (g_StatusBarData.Align == 1) //center
			aligndx = (rectwidth - SumWidth) >> 1;
		else if (g_StatusBarData.Align == 2) //right
			aligndx = (rectwidth - SumWidth);

		// Draw in rects
		RECT r = rc;
		r.left += g_StatusBarData.rectBorders.left + aligndx;
		for (i = 0; i < visProtoCount; i++) {
			ProtoItemData& p = ProtosData[line*protosperline + i];
			HRGN rgn;
			HICON hIcon = NULL;
			HICON hxIcon = NULL;
			BOOL NeedDestroy = FALSE;
			int x = r.left;
			x += p.PaddingLeft;
			r.right = r.left + ProtoWidth[i];

			if (p.bShowProtoIcon) {
				if (p.iProtoStatus > ID_STATUS_OFFLINE && (p.xStatusMode & 3) > 0) {
					if (ProtoServiceExists(p.szAccountName, PS_GETCUSTOMSTATUSICON)) {
						hxIcon = p.extraIcon;
						if (hxIcon) {
							if ((p.xStatusMode & 3) == 2) {
								hIcon = GetMainStatusOverlay(p.iProtoStatus);
								NeedDestroy = TRUE;
							}
							else if ((p.xStatusMode & 3) == 1) {
								hIcon = hxIcon;
								NeedDestroy = TRUE;
								hxIcon = NULL;
							}
						}
					}
				}

				if (hIcon == NULL && (hxIcon == NULL || ((p.xStatusMode & 3) == 3))) {
					if ((p.bConnectingIcon == 1) && p.iProtoStatus >= ID_STATUS_CONNECTING && p.iProtoStatus <= ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES) {
						hIcon = (HICON)CLUI_GetConnectingIconService((WPARAM)p.szAccountName, 0);
						if (hIcon)
							NeedDestroy = TRUE;
						else
							hIcon = LoadSkinnedProtoIcon(p.szAccountName, p.iProtoStatus);
					}
					else hIcon = LoadSkinnedProtoIcon(p.szAccountName, p.iProtoStatus);
				}

				rgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);

				if (g_StatusBarData.sameWidth) {
					int fw = p.fullWidth;
					int rw = r.right - r.left;
					if (g_StatusBarData.Align == 1)
						x = r.left + ((rw - fw) / 2);
					else if (g_StatusBarData.Align == 2)
						x = r.left + ((rw - fw));
					else
						x = r.left;
				}

				SelectClipRgn(hDC, rgn);
				p.bDoubleIcons = false;

				DWORD dim = p.bIsDimmed ? ((64 << 24) | 0x80) : 0;

				if ((p.xStatusMode & 3) == 3) {
					if (hIcon)
						mod_DrawIconEx_helper(hDC, x, iconY, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL | dim);
					if (hxIcon) {
						mod_DrawIconEx_helper(hDC, x + GetSystemMetrics(SM_CXSMICON) + 1, iconY, hxIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL | dim);
						x += GetSystemMetrics(SM_CXSMICON) + 1;
					}
					p.bDoubleIcons = hIcon && hxIcon;
				}
				else {
					if (hxIcon)
						mod_DrawIconEx_helper(hDC, x, iconY, hxIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL | dim);
					if (hIcon)
						mod_DrawIconEx_helper(hDC, x, iconY, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL | ((hxIcon && (p.xStatusMode & 4)) ? (192 << 24) : 0) | dim);
				}

				if (hxIcon || hIcon) { /* TODO g_StatusBarData.bDrawLockOverlay  options to draw locked proto*/
					if (db_get_b(NULL, p.szAccountName, "LockMainStatus", 0)) {
						HICON hLockOverlay = LoadSkinnedIcon(SKINICON_OTHER_STATUS_LOCKED);
						if (hLockOverlay != NULL) {
							mod_DrawIconEx_helper(hDC, x, iconY, hLockOverlay, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL | dim);
							Skin_ReleaseIcon(hLockOverlay);
						}
					}
				}
				if (hxIcon) DestroyIcon_protect(hxIcon);
				if (NeedDestroy) DestroyIcon_protect(hIcon);
				else Skin_ReleaseIcon(hIcon);
				x += GetSystemMetrics(SM_CXSMICON) + 1;
			}

			if (p.bShowProtoName) {
				SIZE textSize;
				RECT rt = r;
				rt.left = x + (spaceWidth >> 1);
				rt.top = textY;
				ske_DrawText(hDC, p.tszProtoHumanName, lstrlen(p.tszProtoHumanName), &rt, 0);

				if ((p.bShowProtoEmails && p.szProtoEMailCount != NULL) || p.bShowStatusName || ((p.xStatusMode & 8) && p.tszProtoXStatus)) {
					GetTextExtentPoint32(hDC, p.tszProtoHumanName, lstrlen(p.tszProtoHumanName), &textSize);
					x += textSize.cx + 3;
				}
			}

			if (p.bShowProtoEmails && p.szProtoEMailCount != NULL) {
				SIZE textSize;
				RECT rt = r;
				rt.left = x + (spaceWidth >> 1);
				rt.top = textY;
				ske_DrawTextA(hDC, p.szProtoEMailCount, lstrlenA(p.szProtoEMailCount), &rt, 0);
				if (p.bShowStatusName || ((p.xStatusMode & 8) && p.tszProtoXStatus)) {
					GetTextExtentPoint32A(hDC, p.szProtoEMailCount, lstrlenA(p.szProtoEMailCount), &textSize);
					x += textSize.cx + 3;
				}
			}
Ejemplo n.º 20
0
static int BuildTree(HWND hwndDlg,int MenuObjectId, BOOL bReread)
{
	char menuItemName[256],MenuNameItems[256];
	char buf[256];

	FreeTreeData( hwndDlg );
	TreeView_DeleteAllItems(GetDlgItem(hwndDlg,IDC_MENUITEMS));

	int menupos = GetMenuObjbyId( MenuObjectId );
	if ( menupos == -1 )
		return FALSE;

	TIntMenuObject* pimo = g_menus[menupos];
	if ( pimo->m_items.first == NULL )
		return FALSE;

	mir_snprintf( MenuNameItems, sizeof(MenuNameItems), "%s_Items", pimo->Name );

	int count = 0;
	{	
		for ( PMO_IntMenuItem p = pimo->m_items.first; p != NULL; p = p->next )
			if ( p->mi.root == ( HGENMENU )-1 || p->mi.root == NULL )
				count++;
	}

	lpMenuItemOptData *PDar = ( lpMenuItemOptData* )mir_alloc( sizeof( lpMenuItemOptData )*count );

	count = 0;
	{
		for ( PMO_IntMenuItem p = pimo->m_items.first; p != NULL; p = p->next ) {
			if ( p->mi.root != ( HGENMENU )-1 && p->mi.root != NULL )
				continue;

			MenuItemOptData *PD = ( MenuItemOptData* )mir_calloc( sizeof( MenuItemOptData ));
			GetMenuItemName( p, menuItemName, sizeof( menuItemName ));
			{
				DBVARIANT dbv;
				mir_snprintf(buf, SIZEOF(buf), "%s_name", menuItemName);

				if ( !DBGetContactSettingTString( NULL, MenuNameItems, buf, &dbv )) {
					PD->name = mir_tstrdup( dbv.ptszVal );
					DBFreeVariant( &dbv );
				}
				else PD->name = mir_tstrdup( p->mi.ptszName );
			}

			PD->pimi = p;
			PD->defname = mir_tstrdup( p->mi.ptszName );

			mir_snprintf( buf, SIZEOF(buf), "%s_visible", menuItemName );
			PD->show = DBGetContactSettingByte( NULL, MenuNameItems, buf, 1 );

			if ( bReread ) {
				mir_snprintf( buf, SIZEOF(buf), "%s_pos", menuItemName );
				PD->pos = DBGetContactSettingDword( NULL, MenuNameItems, buf, 1 );
			}
			else PD->pos = ( PD->pimi ) ? PD->pimi->originalPosition : 0;

			PD->id = p->iCommand;

			if ( p->UniqName )
				PD->uniqname = mir_strdup( p->UniqName );

			PDar[ count ] = PD;
			count++;
	}	}

	qsort( PDar, count, sizeof( lpMenuItemOptData ), sortfunc );

	SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, FALSE, 0);
	int lastpos = 0;
	bool first = TRUE;

	TVINSERTSTRUCT tvis;
	tvis.hParent = NULL;
	tvis.hInsertAfter = TVI_LAST;
	tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
	for ( int i=0; i < count; i++ ) {
		if ( PDar[i]->pos - lastpos >= SEPARATORPOSITIONINTERVAL ) {
			MenuItemOptData *PD = ( MenuItemOptData* )mir_calloc( sizeof( MenuItemOptData ));
			PD->id = -1;
			PD->name = mir_tstrdup( STR_SEPARATOR );
			PD->pos = PDar[i]->pos - 1;
			PD->show = TRUE;

			tvis.item.lParam = ( LPARAM )PD;
			tvis.item.pszText = PD->name;
			tvis.item.iImage = tvis.item.iSelectedImage = PD->show;
			SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis);
		}

		tvis.item.lParam = ( LPARAM )PDar[i];
		tvis.item.pszText = PDar[i]->name;
		tvis.item.iImage = tvis.item.iSelectedImage = PDar[i]->show;
		
		HTREEITEM hti = (HTREEITEM)SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis);
		if ( first ) {
			TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),hti);
			first=FALSE;
		}

		lastpos = PDar[i]->pos;
	}

	SendDlgItemMessage( hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, TRUE, 0 );
	mir_free( PDar );
	ShowWindow( GetDlgItem( hwndDlg, IDC_NOTSUPPORTWARNING ),( pimo->m_bUseUserDefinedItems ) ? SW_HIDE : SW_SHOW );
	EnableWindow( GetDlgItem( hwndDlg, IDC_MENUITEMS ), pimo->m_bUseUserDefinedItems );
	EnableWindow( GetDlgItem( hwndDlg, IDC_INSERTSEPARATOR ), pimo->m_bUseUserDefinedItems );
	return 1;
}
Ejemplo n.º 21
0
static void GetIconName(char *buffer, int bufferSize, int icon) {
	const char *sufixes[]= {
		"PROTO", "MAIL", "MUC", "CHATS", "GRANT", "REQUEST", "VOICE", "MICROPHONE", "SPEAKER"
	};
	mir_snprintf(buffer, bufferSize, "%s_%s", jabberProtoName, sufixes[icon]);
}
Ejemplo n.º 22
0
// get the value of the data using the start, end strings
// UpdateData = the WIDATAITEM struct containing start, end, unit
// Data = the string containing weather data obtained from UpdateData
// global var. used: szInfo = the downloaded string
void GetDataValue(WIDATAITEM *UpdateData, char *Data, char** szData) 
{
	char last = 0, current, *start, *end;
	unsigned startloc = 0, endloc = 0, respos = 0;
	BOOL tag = FALSE, symb = FALSE;
	char *szInfo = *szData;

	Data[0] = 0;
	// parse the data if available
	if (UpdateData->Start[0] == 0 && UpdateData->End[0] == 0) return;
	start = szInfo;
	// the start string must be found
	if (UpdateData->Start[0] != 0) {
		start = strstr(szInfo, UpdateData->Start);
		if (start != NULL) {
			// set the starting location for getting data
			start += strlen(UpdateData->Start);
			szInfo = start;
		}
	}
	// the end string must be found too
	if (UpdateData->End[0] != 0)
		end = strstr(szInfo, UpdateData->End);
	else end = strstr(szInfo, " ");
	if (end != NULL) {
		// set the ending location
		startloc = 0;
		endloc = end - szInfo;
		end += strlen(UpdateData->End);
		last = '\n';
	}
	// ignore if not both of the string found - this prevent crashes
	if (start != NULL && end != NULL) 
	{
		// begin reading the data from start location to end location
		// remove all HTML tag in between, as well as leading space, ending space,
		// multiple spaces, tabs, and return key
		while (startloc < endloc) 
		{
			if (szInfo[startloc] == '<')	tag = TRUE;
			else if (szInfo[startloc] == '&' &&
				(szInfo[startloc+1] == ';' || szInfo[startloc+2] == ';' || szInfo[startloc+3] == ';' || 
				szInfo[startloc+4] == ';' || szInfo[startloc+5] == ';' || szInfo[startloc+6] == ';'))
				symb = TRUE;
			else if (szInfo[startloc] == '>')	tag = FALSE;
			else if (szInfo[startloc] == ';')	symb = FALSE;
			else {
				if (!tag && !symb) {
					current = szInfo[startloc];
					if (current == '\n' || current == '\t' || current == '	' || current == '\r')
						current = ' ';
					if (current != ' ' || last != ' ') {
						if (last != '\n' && (respos != 0 || (respos == 0 && last != ' ')))
							Data[respos++] = last;
						last = current;
					}
				}
			}
			++startloc;
			// prevent crashes if the string go over maximun length -> generate an error
			if (respos >= MAX_DATA_LEN) {
				if (opt.ShowWarnings && UpdateData->Name[0] != 0 && strcmp(UpdateData->Name, "Ignore")) {
					mir_snprintf(Data, MAX_DATA_LEN, Translate("Error when obtaining data: %s"), UpdateData->Name);
					WPShowMessage(Data, SM_WARNING);
				}
				strncpy(Data, Translate("<Error>"), MAX_DATA_LEN);
				last = ' ';
				respos = MAX_DATA_LEN - 1;
				break;
			}
		}

		// get the last character
		if (last != ' ') 
			Data[respos++] = last;

		// null terminate the string
		Data[respos] = 0;

		// write raw data for debug
		Netlib_Logf(hNetlibUser, "%s: %s", UpdateData->Name, Data);

		// convert the unit
		ConvertDataValue(UpdateData, Data);

		// remove the string before the data from szInfo
		szInfo = end;
	}
	*szData = szInfo;
}
Ejemplo n.º 23
0
static void sttApplySkin(MODERNOPTOBJECT *obj, TCHAR *fn)
{
	char svc[128];
	mir_snprintf(svc, SIZEOF(svc), "%s%s", obj->lpzThemeModuleName, TS_SKIN_APPLY);
	CallService(svc, NULL, (LPARAM)fn);
}
Ejemplo n.º 24
0
void CMimAPI::timerMsg(const char *szMsg)
{
	mir_snprintf(m_timerMsg, 256, "%s: %d ticks = %f msec", szMsg, (int)(m_tStop - m_tStart), 1000 * ((double)(m_tStop - m_tStart) * m_dFreq));
	_DebugTraceA(m_timerMsg);
}
Ejemplo n.º 25
0
void CIcqProto::handleServUINSettings(int nPort, serverthread_info *info)
{
	setUserInfo();

	/* SNAC 3,4: Tell server who's on our list (deprecated) */
	/* SNAC 3,15: Try to add unauthorised contacts to temporary list */
	sendEntireListServ(ICQ_BUDDY_FAMILY, ICQ_USER_ADDTOTEMPLIST, BUL_ALLCONTACTS);

	if (m_iDesiredStatus == ID_STATUS_INVISIBLE) {
		/* Tell server who's on our visible list (deprecated) */
		if (!m_bSsiEnabled)
			sendEntireListServ(ICQ_BOS_FAMILY, ICQ_CLI_ADDVISIBLE, BUL_VISIBLE);
		else
			updateServVisibilityCode(3);
	}

	if (m_iDesiredStatus != ID_STATUS_INVISIBLE) {
		/* Tell server who's on our invisible list (deprecated) */
		if (!m_bSsiEnabled)
			sendEntireListServ(ICQ_BOS_FAMILY, ICQ_CLI_ADDINVISIBLE, BUL_INVISIBLE);
		else
			updateServVisibilityCode(4);
	}

	// SNAC 1,1E: Set status
	icq_packet packet;
	{
		DWORD dwDirectCookie = rand() ^ (rand() << 16);

		// Get status
		WORD wStatus = MirandaStatusToIcq(m_iDesiredStatus);

		// Get status note & mood
		char *szStatusNote = PrepareStatusNote(m_iDesiredStatus);
		BYTE bXStatus = getContactXStatus(NULL);
		char szMoodData[32];

		// prepare mood id
		if (m_bMoodsEnabled && bXStatus && moodXStatus[bXStatus - 1] != -1)
			mir_snprintf(szMoodData, "icqmood%d", moodXStatus[bXStatus - 1]);
		else
			szMoodData[0] = '\0';

		//! Tricky code, this ensures that the status note will be saved to the directory
		SetStatusNote(szStatusNote, m_bGatewayMode ? 5000 : 2500, TRUE);

		size_t wStatusNoteLen = mir_strlen(szStatusNote);
		size_t wStatusMoodLen = mir_strlen(szMoodData);
		size_t wSessionDataLen = (wStatusNoteLen ? wStatusNoteLen + 4 : 0) + 4 + wStatusMoodLen + 4;

		serverPacketInit(&packet, 71 + (wSessionDataLen ? wSessionDataLen + 4 : 0));
		packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_SET_STATUS);
		packDWord(&packet, 0x00060004);             // TLV 6: Status mode and security flags
		packWord(&packet, GetMyStatusFlags());      // Status flags
		packWord(&packet, wStatus);                 // Status
		packTLVWord(&packet, 0x0008, 0x0A06);       // TLV 8: Independent Status Messages
		packDWord(&packet, 0x000c0025);             // TLV C: Direct connection info
		packDWord(&packet, getDword("RealIP", 0));
		packDWord(&packet, nPort);
		packByte(&packet, DC_TYPE);                 // TCP/FLAG firewall settings
		packWord(&packet, ICQ_VERSION);
		packDWord(&packet, dwDirectCookie);         // DC Cookie
		packDWord(&packet, WEBFRONTPORT);           // Web front port
		packDWord(&packet, CLIENTFEATURES);         // Client features
		packDWord(&packet, 0x7fffffff);             // Abused timestamp
		packDWord(&packet, ICQ_PLUG_VERSION);       // Abused timestamp
		if (ServiceExists("SecureIM/IsContactSecured"))
			packDWord(&packet, 0x5AFEC0DE);           // SecureIM Abuse
		else
			packDWord(&packet, 0x00000000);           // Timestamp
		packWord(&packet, 0x0000);                  // Unknown
		packTLVWord(&packet, 0x001F, 0x0000);

		if (wSessionDataLen) { // Pack session data
			packWord(&packet, 0x1D);                  // TLV 1D
			packWord(&packet, WORD(wSessionDataLen));       // TLV length
			packWord(&packet, 0x02);                  // Item Type
			if (wStatusNoteLen) {
				packWord(&packet, 0x400 | WORD(wStatusNoteLen + 4)); // Flags + Item Length
				packWord(&packet, WORD(wStatusNoteLen));      // Text Length
				packBuffer(&packet, (LPBYTE)szStatusNote, wStatusNoteLen);
				packWord(&packet, 0);                   // Encoding not specified (utf-8 is default)
			}
			else
				packWord(&packet, 0);                   // Flags + Item Length
			packWord(&packet, 0x0E);                  // Item Type
			packWord(&packet, WORD(wStatusMoodLen));        // Flags + Item Length
			if (wStatusMoodLen)
				packBuffer(&packet, (LPBYTE)szMoodData, wStatusMoodLen); // Mood

			// Save current status note & mood
			db_set_utf(NULL, m_szModuleName, DBSETTING_STATUS_NOTE, szStatusNote);
			setString(DBSETTING_STATUS_MOOD, szMoodData);
		}
		// Release memory
		SAFE_FREE(&szStatusNote);

		sendServPacket(&packet);
	}

	/* SNAC 1,11 */
	serverPacketInit(&packet, 14);
	packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_SET_IDLE);
	packDWord(&packet, 0x00000000);

	sendServPacket(&packet);
	m_bIdleAllow = 0;

	// Change status
	SetCurrentStatus(m_iDesiredStatus);

	// Finish Login sequence
	serverPacketInit(&packet, 98);
	packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_READY);
	packDWord(&packet, 0x00220001); // imitate ICQ 6 behaviour
	packDWord(&packet, 0x0110164f);
	packDWord(&packet, 0x00010004);
	packDWord(&packet, 0x0110164f);
	packDWord(&packet, 0x00130004);
	packDWord(&packet, 0x0110164f);
	packDWord(&packet, 0x00020001);
	packDWord(&packet, 0x0110164f);
	packDWord(&packet, 0x00030001);
	packDWord(&packet, 0x0110164f);
	packDWord(&packet, 0x00150001);
	packDWord(&packet, 0x0110164f);
	packDWord(&packet, 0x00040001);
	packDWord(&packet, 0x0110164f);
	packDWord(&packet, 0x00060001);
	packDWord(&packet, 0x0110164f);
	packDWord(&packet, 0x00090001);
	packDWord(&packet, 0x0110164f);
	packDWord(&packet, 0x000A0001);
	packDWord(&packet, 0x0110164f);
	packDWord(&packet, 0x000B0001);
	packDWord(&packet, 0x0110164f);

	sendServPacket(&packet);

	debugLogA(" *** Yeehah, login sequence complete");

	// login sequence is complete enter logged-in mode
	info->bLoggedIn = true;
	m_bConnectionLost = false;

	// enable auto info-update routine
	icq_EnableUserLookup(true);

	if (!info->isMigrating) {
		// Get Offline Messages Reqeust
		cookie_offline_messages *ack = (cookie_offline_messages*)SAFE_MALLOC(sizeof(cookie_offline_messages));
		if (ack) {
			DWORD dwCookie = AllocateCookie(CKT_OFFLINEMESSAGE, ICQ_MSG_CLI_REQ_OFFLINE, 0, ack);

			serverPacketInit(&packet, 10);
			packFNACHeader(&packet, ICQ_MSG_FAMILY, ICQ_MSG_CLI_REQ_OFFLINE, 0, dwCookie);

			sendServPacket(&packet);
		}
		else icq_LogMessage(LOG_WARNING, LPGEN("Failed to request offline messages. They may be received next time you log in."));

		// Update our information from the server
		sendOwnerInfoRequest();

		// Request info updates on all contacts
		icq_RescanInfoUpdate();

		// Start sending Keep-Alive packets
		StartKeepAlive(info);

		if (m_bAvatarsEnabled) { // Send SNAC 1,4 - request avatar family 0x10 connection
			icq_requestnewfamily(ICQ_AVATAR_FAMILY, &CIcqProto::StartAvatarThread);

			m_avatarsConnectionPending = TRUE;
			debugLogA("Requesting Avatar family entry point.");
		}

		// Set last xstatus
		updateServerCustomStatus(TRUE);
	}
	info->isMigrating = false;

	if (m_bAimEnabled) {
		char **szAwayMsg = NULL;
		mir_cslock l(m_modeMsgsMutex);

		szAwayMsg = MirandaStatusToAwayMsg(m_iStatus);
		if (szAwayMsg)
			icq_sendSetAimAwayMsgServ(*szAwayMsg);
	}
}
Ejemplo n.º 26
0
HICON LoadIconEx(const char* name, bool big)
{
    char szSettingName[100];
    mir_snprintf(szSettingName, _countof(szSettingName), "MSN_%s", name);
    return IcoLib_GetIcon(szSettingName, big);
}
Ejemplo n.º 27
0
bool CMsnProto::MSN_StoreGetProfile(bool allowRecurse)
{
    char* reqHdr;
    ezxml_t tbdy;
    ezxml_t xmlp = storeSoapHdr("GetProfile", "Initial", tbdy, reqHdr);

    ezxml_t prohndl = ezxml_add_child(tbdy, "profileHandle", 0);

    ezxml_t alias = ezxml_add_child(prohndl, "Alias", 0);
    ezxml_t node = ezxml_add_child(alias, "Name", 0);
    ezxml_set_txt(node, mycid);
    node = ezxml_add_child(alias, "NameSpace", 0);
    ezxml_set_txt(node, "MyCidStuff");

    node = ezxml_add_child(prohndl, "RelationshipName", 0);
    ezxml_set_txt(node, "MyProfile");

    ezxml_t proattr = ezxml_add_child(tbdy, "profileAttributes", 0);
    node = ezxml_add_child(proattr, "ResourceID", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(proattr, "DateModified", 0);
    ezxml_set_txt(node, "true");

    ezxml_t exproattr = ezxml_add_child(proattr, "ExpressionProfileAttributes", 0);
    node = ezxml_add_child(exproattr, "ResourceID", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "DateModified", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "DisplayName", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "DisplayNameLastModified", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "PersonalStatus", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "PersonalStatusLastModified", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "StaticUserTilePublicURL", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "Photo", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "Flags", 0);
    ezxml_set_txt(node, "true");

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);

    unsigned status = 0;
    char *storeUrl = NULL, *tResult = NULL;

    for (int k = 4; --k;)
    {
        mir_free(storeUrl);
        storeUrl = GetStoreHost("GetProfile");
        tResult = getSslResult(&storeUrl, szData, reqHdr, status);
        if (tResult == NULL) UpdateStoreHost("GetProfile", NULL);
        else break;
    }

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL)
    {
        if (status == 200)
        {
            ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult));
            ezxml_t body = getSoapResponse(xmlm, "GetProfile");

            UpdateStoreHost("GetProfile", body ? storeUrl : NULL);

            mir_snprintf(proresid, sizeof(proresid), "%s", ezxml_txt(ezxml_child(body, "ResourceID")));

            ezxml_t expr = ezxml_child(body, "ExpressionProfile");
            if (expr == NULL)
            {
                MSN_StoreShareItem(proresid);
                MSN_SharingMyProfile();
                if (allowRecurse) MSN_StoreGetProfile(false);
            }
            else
            {
                const char* szNick = ezxml_txt(ezxml_child(expr, "DisplayName"));
                setStringUtf(NULL, "Nick", (char*)szNick);

                const char* szStatus = ezxml_txt(ezxml_child(expr, "PersonalStatus"));
                replaceStr(msnLastStatusMsg, szStatus);

                mir_snprintf(expresid, sizeof(expresid), "%s", ezxml_txt(ezxml_child(expr, "ResourceID")));

                ezxml_t photo = ezxml_child(expr, "Photo");
                mir_snprintf(photoid, sizeof(photoid), "%s", ezxml_txt(ezxml_child(photo, "ResourceID")));

                ezxml_t docstr = ezxml_get(photo, "DocumentStreams", 0, "DocumentStream", -1);
                while (docstr)
                {
                    const char *docname = ezxml_txt(ezxml_child(docstr, "DocumentStreamName"));
                    if (!strcmp(docname, "UserTileStatic"))
                    {
                        getMyAvatarFile(ezxml_txt(ezxml_child(docstr, "PreAuthURL")), _T("miranda_avatar.tmp"));
                        break;
                    }
                    docstr = ezxml_next(docstr);
                }
            }
            ezxml_free(xmlm);
        }
        else if (status == 500 && allowRecurse)
        {
            ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult));
            const char* szErr = ezxml_txt(getSoapFault(xmlm, true));
            if (strcmp(szErr, "PassportAuthFail") == 0)
            {
                MSN_GetPassportAuth();
                MSN_StoreGetProfile(false);
            }
            else
            {
                MSN_StoreCreateProfile();
                if (MSN_StoreGetProfile(false)) status = 200;
            }
            ezxml_free(xmlm);
        }
        else
            UpdateStoreHost("GetProfile", NULL);

    }
    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Ejemplo n.º 28
0
void  ReleaseIconEx(const char* name, bool big)
{
    char szSettingName[100];
    mir_snprintf(szSettingName, _countof(szSettingName), "MSN_%s", name);
    IcoLib_Release(szSettingName, big);
}
Ejemplo n.º 29
0
static void PaintWorker(TBBUTTONDATA *bct, HDC hdcPaint, POINT *pOffset)
{
	if (!hdcPaint)
		return;  //early exit

	POINT offset;
	if (pOffset)
		offset = *pOffset;
	else
		offset.x = offset.y = 0;

	RECT rcClient;
	GetClientRect(bct->hwnd, &rcClient);
	int width = rcClient.right - rcClient.left;
	int height = rcClient.bottom - rcClient.top;

	HBITMAP hbmMem = NULL;
	HBITMAP hbmOld = NULL;
	HDC hdcMem = pOffset ? hdcPaint : CreateCompatibleDC(hdcPaint);
	HFONT hOldFont = (HFONT)SelectObject(hdcMem, bct->hFont);
	if (!pOffset) {
		hbmMem = ske_CreateDIB32(width, height);
		hbmOld = (HBITMAP)SelectObject(hdcMem, hbmMem);
	}
	else OffsetRect(&rcClient, offset.x, offset.y);

	if (!g_CluiData.fDisableSkinEngine) {
		char szRequest[128];
		/* painting */
		mir_snprintf(szRequest, "Button,ID=%s,Hovered=%s,Pressed=%s,Focused=%s",
			bct->szButtonID,				// ID		
			b2str(bct->stateId == PBS_HOT),	// Hovered
			b2str(bct->stateId == PBS_PRESSED || bct->bIsPushed == TRUE),	// Pressed
			b2str(bct->bFocused));		// Focused

		SkinDrawGlyph(hdcMem, &rcClient, &rcClient, szRequest);
	}
	else if (xpt_IsThemed(bct->hThemeToolbar)) {
		RECT *rc = &rcClient;
		int state = IsWindowEnabled(bct->hwnd) ? /*(bct->stateId == PBS_PRESSED || bct->bIsPushed == TRUE) ? PBS_PRESSED :*/ (bct->stateId == PBS_NORMAL && bct->bIsDefault ? PBS_DEFAULTED : bct->stateId) : PBS_DISABLED;
		xpt_DrawTheme(bct->hThemeToolbar, bct->hwnd, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), rc, rc);
	}
	else {
		HBRUSH hbr = NULL;

		if (bct->stateId == PBS_PRESSED || bct->stateId == PBS_HOT)
			hbr = GetSysColorBrush(COLOR_3DLIGHT);
		else {
			RECT btnRect;
			POINT pt = { 0 };
			int ret;
			HWND hwndParent = GetParent(bct->hwnd);
			HDC dc = CreateCompatibleDC(NULL);
			HBITMAP memBM, oldBM;
			GetWindowRect(hwndParent, &btnRect);
			memBM = ske_CreateDIB32(btnRect.right - btnRect.left, btnRect.bottom - btnRect.top);
			oldBM = (HBITMAP)SelectObject(dc, memBM);
			ret = SendMessage(hwndParent, WM_ERASEBKGND, (WPARAM)dc, 0);
			GetWindowRect(bct->hwnd, &btnRect);
			ClientToScreen(hwndParent, &pt);
			OffsetRect(&btnRect, -pt.x, -pt.y);
			if (ret)
				BitBlt(hdcMem, 0, 0, btnRect.right - btnRect.left, btnRect.bottom - btnRect.top, dc, btnRect.left, btnRect.top, SRCCOPY);
			oldBM = (HBITMAP)SelectObject(dc, oldBM);
			DeleteObject(memBM);
			DeleteDC(dc);
			if (!ret) { //WM_ERASEBKG return false need to paint
				HDC pdc = GetDC(hwndParent);
				HBRUSH oldBrush = (HBRUSH)GetCurrentObject(pdc, OBJ_BRUSH);
				hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)pdc, (LPARAM)hwndParent);
				SelectObject(pdc, oldBrush);
				ReleaseDC(hwndParent, pdc);
			}
		}
		if (hbr) {
			FillRect(hdcMem, &rcClient, hbr);
			DeleteObject(hbr);
		}
		if (bct->stateId == PBS_HOT || bct->bFocused) {
			if (bct->bIsPushed)
				DrawEdge(hdcMem, &rcClient, EDGE_ETCHED, BF_RECT | BF_SOFT);
			else
				DrawEdge(hdcMem, &rcClient, BDR_RAISEDOUTER, BF_RECT | BF_SOFT | BF_FLAT);
		}
		else if (bct->stateId == PBS_PRESSED)
			DrawEdge(hdcMem, &rcClient, BDR_SUNKENOUTER, BF_RECT | BF_SOFT);
	}

	RECT  rcTemp = rcClient;  //content rect
	bool  bPressed = (bct->stateId == PBS_PRESSED || bct->bIsPushed == TRUE);
	bool  bHasText = (bct->szText[0] != '\0');

	/* formatter */
	if (!g_CluiData.fDisableSkinEngine) {
		/* correct rect according to rcMargins */

		rcTemp.left += bct->rcMargins.left;
		rcTemp.top += bct->rcMargins.top;
		rcTemp.bottom -= bct->rcMargins.bottom;
		rcTemp.right -= bct->rcMargins.right;
	}

	/* reposition button items */
	RECT rcIcon = rcTemp, rcText = rcTemp;
	if (bct->hIcon) {
		if (bHasText) {
			rcIcon.right = rcIcon.left + 16; /* CXSM_ICON */
			rcText.left = rcIcon.right + 2;
		}
		else {
			rcIcon.left += (rcIcon.right - rcIcon.left) / 2 - 8;
			rcIcon.right = rcIcon.left + 16;
		}
	}

	/*	Check sizes*/
	if (bct->hIcon && (rcIcon.right > rcTemp.right || rcIcon.bottom > rcTemp.bottom || rcIcon.left < rcTemp.left || rcIcon.top < rcTemp.top))
		bct->hIcon = NULL;

	if (bHasText && (rcText.right > rcTemp.right || rcText.bottom > rcTemp.bottom || rcText.left < rcTemp.left || rcText.top < rcTemp.top))
		bHasText = FALSE;

	if (bct->hIcon) {
		/* center icon vertically */
		rcIcon.top += (rcClient.bottom - rcClient.top) / 2 - 8; /* CYSM_ICON/2 */
		rcIcon.bottom = rcIcon.top + 16; /* CYSM_ICON */
		/* draw it */
		ske_DrawIconEx(hdcMem, rcIcon.left + bPressed, rcIcon.top + bPressed, bct->hIcon, 16, 16, 0, NULL, DI_NORMAL);
	}

	if (bHasText) {
		BOOL bCentered = TRUE;
		SetBkMode(hdcMem, TRANSPARENT);
		if (bct->nFontID >= 0)
			g_clcPainter.ChangeToFont(hdcMem, NULL, bct->nFontID, NULL);

		RECT TextRequiredRect = rcText;
		ske_DrawText(hdcMem, bct->szText, -1, &TextRequiredRect, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_SINGLELINE);
		if (TextRequiredRect.right - TextRequiredRect.left > rcText.right - rcText.left)
			bCentered = FALSE;

		ske_DrawText(hdcMem, bct->szText, -1, &rcText, (bCentered ? DT_CENTER : 0) | DT_VCENTER | DT_SINGLELINE);
		ske_ResetTextEffect(hdcMem);
	}
	if (!pOffset)
		BitBlt(hdcPaint, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY);

	// better to use try/finally but looks like last one is Microsoft specific
	SelectObject(hdcMem, hOldFont);
	if (!pOffset) {
		SelectObject(hdcMem, hbmOld);
		DeleteObject(hbmMem);
		DeleteDC(hdcMem);
	}
}
Ejemplo n.º 30
0
bool MakeZip(TCHAR *tszSource, TCHAR *tszDest, TCHAR *dbname, HWND progress_dialog)
{
    bool ret = false;
    HANDLE hSrc;
    zipFile hZip;
    SYSTEMTIME st;
    WIN32_FILE_ATTRIBUTE_DATA fad = { 0 };
    zip_fileinfo fi = { 0 };
    HWND hProgBar;
    DWORD dwRead;
    MSG msg;
    char buf[(256 * 1024)];	// 256 KB
    DWORDLONG dwSrcFileSize, dwTotalBytes = 0;

    ptrA szSourceName(mir_u2a(dbname));
    ptrT tszDestPath(DoubleSlash(tszDest));

    hSrc = CreateFile(tszSource, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hSrc == INVALID_HANDLE_VALUE)
        return ret;
    if (GetFileAttributesEx(tszSource, GetFileExInfoStandard, &fad) == FALSE)
        goto err_out;
    dwSrcFileSize = ((DWORDLONG)fad.nFileSizeLow | (((DWORDLONG)fad.nFileSizeHigh) << 32));
    if (dwSrcFileSize == 0) /* Prevent division by zero error. */
        goto err_out;
    FileTimeToLocalFileTime(&fad.ftLastWriteTime, &fad.ftLastWriteTime);
    FileTimeToSystemTime(&fad.ftLastWriteTime, &st);
    hZip = zipOpen2_64(tszDestPath, APPEND_STATUS_CREATE, NULL, NULL);
    if (hZip == NULL)
        goto err_out;
    fi.tmz_date.tm_sec = st.wSecond;
    fi.tmz_date.tm_min = st.wMinute;
    fi.tmz_date.tm_hour = st.wHour;
    fi.tmz_date.tm_mday = st.wDay;
    fi.tmz_date.tm_mon = (st.wMonth - 1);
    fi.tmz_date.tm_year = st.wYear;

    if (zipOpenNewFileInZip(hZip, szSourceName, &fi, NULL, 0, NULL, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION) == ZIP_OK) {
        hProgBar = GetDlgItem(progress_dialog, IDC_PROGRESS);
        while (GetWindowLongPtr(progress_dialog, GWLP_USERDATA) != 1) {
            if (!ReadFile(hSrc, buf, sizeof(buf), &dwRead, NULL))
                break;
            if (dwRead == 0) { // EOF
                ret = true;
                break;
            }
            if (zipWriteInFileInZip(hZip, buf, dwRead) != ZIP_OK)
                break;
            dwTotalBytes += dwRead;
            SendMessage(hProgBar, PBM_SETPOS, (WPARAM)((100 * dwTotalBytes) / dwSrcFileSize), 0);
            while (PeekMessage(&msg, progress_dialog, 0, 0, PM_REMOVE) != 0) {
                if (progress_dialog == NULL || !IsDialogMessage(progress_dialog, &msg)) { /* Wine fix. */
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
            }
        }
        zipCloseFileInZip(hZip);
    }
    if (ret) {
        mir_snprintf(buf, "%s\r\n%s %s %d.%d.%d.%d\r\n",
                     Translate("Miranda NG database"), Translate("Created by:"),
                     __PLUGIN_NAME, __MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM);
    }
    else {
        buf[0] = 0;
    }
    zipClose(hZip, buf);

err_out:
    CloseHandle(hSrc);

    return ret;
}