Example #1
0
static int CListIconsChanged(WPARAM, LPARAM)
{
	int i, j;

	for (i=0; i < SIZEOF(statusModeList); i++)
		ImageList_ReplaceIcon_IconLibLoaded(hCListImages, i + 1, LoadSkinIcon(skinIconStatusList[i]));
	ImageList_ReplaceIcon_IconLibLoaded(hCListImages, IMAGE_GROUPOPEN, LoadSkinIcon(SKINICON_OTHER_GROUPOPEN));
	ImageList_ReplaceIcon_IconLibLoaded(hCListImages, IMAGE_GROUPSHUT, LoadSkinIcon(SKINICON_OTHER_GROUPSHUT));
	for (i=0; i < protoIconIndex.getCount(); i++)
		for (j = 0; j < SIZEOF(statusModeList); j++)
			ImageList_ReplaceIcon_IconLibLoaded(hCListImages, protoIconIndex[i].iIconBase + j, LoadSkinProtoIcon(protoIconIndex[i].szProto, statusModeList[j]));
	cli.pfnTrayIconIconsChanged();
	cli.pfnInvalidateRect(cli.hwndContactList, NULL, TRUE);
	return 0;
}
Example #2
0
static INT_PTR sttLoadSkinIcon( WPARAM wParam, LPARAM lParam )
{
	switch (lParam)
	{
	case 0:
		return (INT_PTR)LoadSkinIcon( wParam );

	case 1:
		return (INT_PTR)GetSkinIconHandle( wParam );

	case 2:
		return (INT_PTR)LoadSkinIcon( wParam, true );
	}

	return 0;
}
Example #3
0
void Button_SetIcon_IcoLib(HWND hwndDlg, int itemId, int iconId, const char* tooltip)
{
	HWND hWnd = GetDlgItem( hwndDlg, itemId );
	SendMessage( hWnd, BM_SETIMAGE, IMAGE_ICON, ( LPARAM )LoadSkinIcon( iconId ));
	SendMessage( hWnd, BUTTONSETASFLATBTN, 0, 0 );
	SendMessage( hWnd, BUTTONADDTOOLTIP, (WPARAM)tooltip, 0);
}
Example #4
0
int ImageList_AddIcon_IconLibLoaded(HIMAGELIST hIml, int iconId)
{
	HICON hIcon = LoadSkinIcon( iconId );
	int res = ImageList_AddIcon(hIml, hIcon);
	IconLib_ReleaseIcon(hIcon,0);
	return res;
}
Example #5
0
static INT_PTR DbEventGetIcon( WPARAM wParam, LPARAM lParam )
{
	DBEVENTINFO* dbei = ( DBEVENTINFO* )lParam;
	HICON icon = NULL;
	DBEVENTTYPEDESCR* et = ( DBEVENTTYPEDESCR* )DbEventTypeGet( ( WPARAM )dbei->szModule, ( LPARAM )dbei->eventType );

	if ( et && ServiceExists( et->iconService )) {
		icon = ( HICON )CallService( et->iconService, wParam, lParam );
		if ( icon )
			return ( INT_PTR )icon;
	}
	if ( et && et->eventIcon )
		icon = ( HICON )CallService( MS_SKIN2_GETICONBYHANDLE, 0, ( LPARAM )et->eventIcon );
	if ( !icon ) {
		char szName[100];
		mir_snprintf( szName, sizeof( szName ), "eventicon_%s%d", dbei->szModule, dbei->eventType );
		icon = ( HICON )CallService( MS_SKIN2_GETICON, 0, ( LPARAM )szName );
	}

	if ( !icon )
	{
		switch( dbei->eventType ) {
		case EVENTTYPE_URL:
			icon = LoadSkinIcon( SKINICON_EVENT_URL );
			break;

		case EVENTTYPE_FILE:
			icon = LoadSkinIcon( SKINICON_EVENT_FILE );
			break;

		default: // EVENTTYPE_MESSAGE and unknown types
			icon = LoadSkinIcon( SKINICON_EVENT_MESSAGE );
			break;
		}
	}

  if ( wParam & LR_SHARED )
    return ( INT_PTR )icon;
  else
    return ( INT_PTR )CopyIcon( icon );
}
Example #6
0
void Window_SetIcon_IcoLib(HWND hWnd, int iconId)
{
	SendMessage(hWnd, WM_SETICON, ICON_BIG,   ( LPARAM )LoadSkinIcon( iconId, true ));
	SendMessage(hWnd, WM_SETICON, ICON_SMALL, ( LPARAM )LoadSkinIcon( iconId ));
}
Example #7
0
static int AuthEventAdded(WPARAM, LPARAM lParam)
{
	TCHAR szUid[128] = _T("");
	TCHAR szTooltip[256];
	const HANDLE hDbEvent = (HANDLE)lParam;

	DBEVENTINFO dbei = { sizeof(dbei) };
	db_event_get((HANDLE)lParam, &dbei);
	if (dbei.flags & (DBEF_SENT | DBEF_READ) || (dbei.eventType != EVENTTYPE_AUTHREQUEST && dbei.eventType != EVENTTYPE_ADDED))
		return 0;

	dbei.cbBlob = db_event_getBlobSize(hDbEvent);
	dbei.pBlob = (PBYTE)alloca(dbei.cbBlob);
	db_event_get(hDbEvent, &dbei);

	HANDLE hContact = DbGetAuthEventContact(&dbei);

	CLISTEVENT cli = {0};
	cli.cbSize = sizeof(cli);
	cli.hContact = hContact;
	cli.ptszTooltip = szTooltip;
	cli.flags = CLEF_TCHAR;
	cli.lParam = lParam;
	cli.hDbEvent = hDbEvent;

	CONTACTINFO ci = {0};
	ci.cbSize = sizeof(ci);
	ci.hContact = hContact;
	ci.szProto = GetContactProto(hContact);
	ci.dwFlag = CNF_UNIQUEID | CNF_TCHAR;
	if ( !CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
		switch (ci.type) {
		case CNFT_ASCIIZ:
			mir_sntprintf(szUid, SIZEOF(szUid), _T("%s"), ci.pszVal);
			mir_free(ci.pszVal);
			break;

		case CNFT_DWORD:
			mir_sntprintf(szUid, SIZEOF(szUid), _T("%u"), ci.dVal);
			break;
		}
	}

	if (dbei.eventType == EVENTTYPE_AUTHREQUEST) {
		SkinPlaySound("AuthRequest");
		if (szUid[0])
			mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("%s requests authorization"), szUid);
		else
			mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("%u requests authorization"), *(PDWORD)dbei.pBlob);

		cli.hIcon = LoadSkinIcon(SKINICON_AUTH_REQUEST);
		cli.pszService = MS_AUTH_SHOWREQUEST;
		CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cli);
	}
	else if (dbei.eventType == EVENTTYPE_ADDED) {
		SkinPlaySound("AddedEvent");
		if (szUid[0])
			mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("%s added you to their contact list"), szUid);
		else
			mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("%u added you to their contact list"), *(PDWORD)dbei.pBlob);

		cli.hIcon = LoadSkinIcon(SKINICON_AUTH_ADD);
		cli.pszService = MS_AUTH_SHOWADDED;
		CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cli);
	}
	return 0;
}
Example #8
0
void RebuildMenuOrder(void)
{
	BYTE bHideStatusMenu = db_get_b(NULL, "CLUI", "DontHideStatusMenu", 0); // cool perversion, though

	//clear statusmenu
	RecursiveDeleteMenu(hStatusMenu);

	//status menu
	if (hStatusMenuObject != 0) {
		CallService(MO_REMOVEMENUOBJECT, (WPARAM)hStatusMenuObject, 0);
		mir_free(hStatusMainMenuHandles);
		mir_free(hStatusMenuHandles);
	}

	hStatusMenuObject = MO_CreateMenuObject("StatusMenu", LPGEN("Status menu"), "StatusMenuCheckService", "StatusMenuExecService");
	MO_SetOptionsMenuObject(hStatusMenuObject, OPT_MENUOBJECT_SET_FREE_SERVICE, (INT_PTR)"CLISTMENUS/FreeOwnerDataStatusMenu");

	hStatusMainMenuHandles = (PMO_IntMenuItem*)mir_calloc(SIZEOF(statusModeList) * sizeof(PMO_IntMenuItem*));
	hStatusMainMenuHandlesCnt = SIZEOF(statusModeList);

	hStatusMenuHandles = (tStatusMenuHandles*)mir_calloc(sizeof(tStatusMenuHandles)*accounts.getCount());
	hStatusMenuHandlesCnt = accounts.getCount();

	FreeMenuProtos();

	for (int s = 0; s < accounts.getCount(); s++) {
		int i = cli.pfnGetAccountIndexByPos(s);
		if (i == -1)
			continue;

		PROTOACCOUNT *pa = accounts[i];
		int pos = 0;
		if (!bHideStatusMenu && !cli.pfnGetProtocolVisibility(pa->szModuleName))
			continue;

		DWORD flags = pa->ppro->GetCaps(PFLAGNUM_2, 0) & ~pa->ppro->GetCaps(PFLAGNUM_5, 0);
		HICON ic;
		TCHAR tbuf[256];

		//adding root
		TMO_MenuItem tmi = { 0 };
		tmi.cbSize = sizeof(tmi);
		tmi.flags = CMIF_TCHAR | CMIF_ROOTHANDLE | CMIF_KEEPUNTRANSLATED;
		tmi.position = pos++;
		tmi.hIcon = ic = (HICON)CallProtoServiceInt(NULL, pa->szModuleName, PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0);

		if (Proto_IsAccountLocked(pa) && cli.bDisplayLocked) {
			mir_sntprintf(tbuf, SIZEOF(tbuf), TranslateT("%s (locked)"), pa->tszAccountName);
			tmi.ptszName = tbuf;
		}
		else tmi.ptszName = pa->tszAccountName;

		//owner data
		StatusMenuExecParam *smep = (StatusMenuExecParam*)mir_calloc(sizeof(StatusMenuExecParam));
		smep->proto = mir_strdup(pa->szModuleName);
		tmi.ownerdata = smep;

		PMO_IntMenuItem rootmenu = MO_AddNewMenuItem(hStatusMenuObject, &tmi);

		memset(&tmi, 0, sizeof(tmi));
		tmi.cbSize = sizeof(tmi);
		tmi.flags = CMIF_TCHAR | CMIF_ROOTHANDLE | CMIF_KEEPUNTRANSLATED;
		tmi.root = rootmenu;
		tmi.position = pos++;
		tmi.hIcon = ic;

		//owner data
		smep = (StatusMenuExecParam*)mir_calloc(sizeof(StatusMenuExecParam));
		smep->proto = mir_strdup(pa->szModuleName);
		tmi.ownerdata = smep;

		if (Proto_IsAccountLocked(pa))
			tmi.flags |= CMIF_CHECKED;

		if ((tmi.flags & CMIF_CHECKED) && cli.bDisplayLocked) {
			mir_sntprintf(tbuf, SIZEOF(tbuf), TranslateT("%s (locked)"), pa->tszAccountName);
			tmi.ptszName = tbuf;
		}
		else tmi.ptszName = pa->tszAccountName;

		PMO_IntMenuItem menuHandle = MO_AddNewMenuItem(hStatusMenuObject, &tmi);
		((StatusMenuExecParam*)tmi.ownerdata)->protoindex = (int)menuHandle;
		MO_ModifyMenuItem(menuHandle, &tmi);

		cli.menuProtos = (MenuProto*)mir_realloc(cli.menuProtos, sizeof(MenuProto)*(cli.menuProtoCount + 1));
		memset(&(cli.menuProtos[cli.menuProtoCount]), 0, sizeof(MenuProto));
		cli.menuProtos[cli.menuProtoCount].pMenu = rootmenu;
		cli.menuProtos[cli.menuProtoCount].szProto = mir_strdup(pa->szModuleName);

		cli.menuProtoCount++;

		char buf[256];
		mir_snprintf(buf, SIZEOF(buf), "RootProtocolIcon_%s", pa->szModuleName);
		MO_SetOptionsMenuItem(menuHandle, OPT_MENUITEMSETUNIQNAME, (INT_PTR)buf);

		DestroyIcon(ic);
		pos += 500000;

		for (int j = 0; j < SIZEOF(statusModeList); j++) {
			if (!(flags & statusModePf2List[j]))
				continue;

			// adding
			memset(&tmi, 0, sizeof(tmi));
			tmi.cbSize = sizeof(tmi);
			tmi.flags = CMIF_ROOTHANDLE | CMIF_TCHAR;
			if (statusModeList[j] == ID_STATUS_OFFLINE)
				tmi.flags |= CMIF_CHECKED;
			tmi.root = rootmenu;
			tmi.position = pos++;
			tmi.ptszName = cli.pfnGetStatusModeDescription(statusModeList[j], GSMDF_UNTRANSLATED);
			tmi.hIcon = LoadSkinProtoIcon(pa->szModuleName, statusModeList[j]);

			// owner data
			StatusMenuExecParam *smep = (StatusMenuExecParam*)mir_calloc(sizeof(StatusMenuExecParam));
			smep->custom = FALSE;
			smep->status = statusModeList[j];
			smep->protoindex = i;
			smep->proto = mir_strdup(pa->szModuleName);
			tmi.ownerdata = smep;

			hStatusMenuHandles[i].protoindex = i;
			hStatusMenuHandles[i].protostatus[j] = statusModeList[j];
			hStatusMenuHandles[i].menuhandle[j] = MO_AddNewMenuItem(hStatusMenuObject, &tmi);

			char buf[256];
			mir_snprintf(buf, SIZEOF(buf), "ProtocolIcon_%s_%s", pa->szModuleName, tmi.pszName);
			MO_SetOptionsMenuItem(hStatusMenuHandles[i].menuhandle[j], OPT_MENUITEMSETUNIQNAME, (INT_PTR)buf);

			IcoLib_ReleaseIcon(tmi.hIcon, 0);
		}
	}

	NotifyEventHooks(cli.hPreBuildStatusMenuEvent, 0, 0);
	int pos = 200000;

	// add to root menu
	for (int j = 0; j < SIZEOF(statusModeList); j++) {
		for (int i = 0; i < accounts.getCount(); i++) {
			PROTOACCOUNT *pa = accounts[i];
			if (!bHideStatusMenu && !cli.pfnGetProtocolVisibility(pa->szModuleName))
				continue;

			DWORD flags = pa->ppro->GetCaps(PFLAGNUM_2, 0) & ~pa->ppro->GetCaps(PFLAGNUM_5, 0);
			if (!(flags & statusModePf2List[j]))
				continue;

			TMO_MenuItem tmi = { sizeof(tmi) };
			tmi.flags = CMIF_ROOTHANDLE | CMIF_TCHAR;
			if (statusModeList[j] == ID_STATUS_OFFLINE)
				tmi.flags |= CMIF_CHECKED;

			tmi.hIcon = LoadSkinIcon(skinIconStatusList[j]);
			tmi.position = pos++;
			tmi.hotKey = MAKELPARAM(MOD_CONTROL, '0' + j);

			//owner data
			StatusMenuExecParam *smep = (StatusMenuExecParam*)mir_calloc(sizeof(StatusMenuExecParam));
			smep->status = statusModeList[j];
			tmi.ownerdata = smep;
			{
				TCHAR buf[256], hotkeyName[100];
				WORD hotKey = GetHotkeyValue(statusHotkeys[j]);
				HotkeyToName(hotkeyName, SIZEOF(hotkeyName), HIBYTE(hotKey), LOBYTE(hotKey));
				mir_sntprintf(buf, SIZEOF(buf), _T("%s\t%s"),
					cli.pfnGetStatusModeDescription(statusModeList[j], 0), hotkeyName);
				tmi.ptszName = buf;
				tmi.hotKey = MAKELONG(HIBYTE(hotKey), LOBYTE(hotKey));
				hStatusMainMenuHandles[j] = MO_AddNewMenuItem(hStatusMenuObject, &tmi);
			}

			char buf[256];
			mir_snprintf(buf, SIZEOF(buf), "Root2ProtocolIcon_%s_%s", pa->szModuleName, tmi.pszName);
			MO_SetOptionsMenuItem(hStatusMainMenuHandles[j], OPT_MENUITEMSETUNIQNAME, (INT_PTR)buf);

			IcoLib_ReleaseIcon(tmi.hIcon, 0);
			break;
		}
	}

	BuildStatusMenu(0, 0);
}
Example #9
0
INT_PTR CALLBACK ContactDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg) {
		case WM_INITDIALOG:
			SetWindowLongPtr(hwndDlg,GWLP_USERDATA,(LONG_PTR)lParam);
			if(hEmailFont) DeleteObject(hEmailFont);
			{	LOGFONT lf;
				hEmailFont=(HFONT)SendDlgItemMessage(hwndDlg,IDC_EMAILS,WM_GETFONT,0,0);
				GetObject(hEmailFont,sizeof(lf),&lf);
				lf.lfUnderline=1;
				hEmailFont=CreateFontIndirect(&lf);
			}
			if(hHandCursor==NULL) {
				if(IsWinVer2000Plus()) hHandCursor=LoadCursor(NULL,IDC_HAND);
				else hHandCursor=LoadCursor(hMirandaInst,MAKEINTRESOURCE(IDC_HYPERLINKHAND));
			}
			TranslateDialogDefault(hwndDlg);
			{	LVCOLUMN lvc;
				RECT rc;
				GetClientRect(GetDlgItem(hwndDlg,IDC_EMAILS),&rc);
				rc.right-=GetSystemMetrics(SM_CXVSCROLL);
				lvc.mask=LVCF_WIDTH;
				ListView_SetExtendedListViewStyleEx(GetDlgItem(hwndDlg,IDC_EMAILS), LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
				ListView_SetExtendedListViewStyleEx(GetDlgItem(hwndDlg,IDC_PHONES), LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
				lvc.cx=rc.right/4;
				ListView_InsertColumn(GetDlgItem(hwndDlg,IDC_EMAILS),0,&lvc);
				ListView_InsertColumn(GetDlgItem(hwndDlg,IDC_PHONES),0,&lvc);
				lvc.cx=rc.right-rc.right/4-40;
				ListView_InsertColumn(GetDlgItem(hwndDlg,IDC_EMAILS),1,&lvc);
				lvc.cx=rc.right-rc.right/4-90;
				ListView_InsertColumn(GetDlgItem(hwndDlg,IDC_PHONES),1,&lvc);
				lvc.cx=50;
				ListView_InsertColumn(GetDlgItem(hwndDlg,IDC_PHONES),2,&lvc);
				lvc.cx=20;
				ListView_InsertColumn(GetDlgItem(hwndDlg,IDC_EMAILS),2,&lvc);
				ListView_InsertColumn(GetDlgItem(hwndDlg,IDC_EMAILS),3,&lvc);
				ListView_InsertColumn(GetDlgItem(hwndDlg,IDC_PHONES),3,&lvc);
				ListView_InsertColumn(GetDlgItem(hwndDlg,IDC_PHONES),4,&lvc);
			}
			break;
		case M_REMAKELISTS:
			{	char *szProto;
			LVITEM lvi;
			int i;
			char idstr[33];
			TCHAR idstr2[33];
			DBVARIANT dbv;
			HANDLE hContact=(HANDLE)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);

			if (hContact != NULL) {
				szProto=(char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)hContact,0);
				if (szProto==NULL) break;
				//e-mails
				ListView_DeleteAllItems(GetDlgItem(hwndDlg,IDC_EMAILS));
				lvi.mask=LVIF_TEXT|LVIF_PARAM;
				lvi.lParam=(LPARAM)(-1);
				lvi.iSubItem=0;
				lvi.iItem=0;
				for(i=-1;;i++) {
					if(i==-1) {
						if(DBGetContactSettingTString(hContact,szProto,"e-mail",&dbv))
							continue;
						lvi.pszText=TranslateT("Primary");
					}
					else {
						mir_snprintf(idstr, SIZEOF(idstr), "e-mail%d", i );
						if(DBGetContactSettingTString(hContact,szProto,idstr,&dbv))
							break;
						lvi.pszText=idstr2;
						mir_sntprintf(idstr2, SIZEOF(idstr2), _T("%d"),i+2);
					}
					ListView_InsertItem(GetDlgItem(hwndDlg,IDC_EMAILS),&lvi);
					ListView_SetItemText(GetDlgItem(hwndDlg,IDC_EMAILS),lvi.iItem,1,dbv.ptszVal);
					DBFreeVariant(&dbv);
					lvi.iItem++;
				}
				lvi.iSubItem=0;
				for(i=0;;i++) {
					lvi.lParam=i;
					mir_snprintf(idstr, SIZEOF(idstr), "Mye-mail%d",i);
					if(DBGetContactSettingTString(hContact,"UserInfo",idstr,&dbv))
						break;
					lvi.pszText=idstr2;
					mir_sntprintf(idstr2, SIZEOF(idstr2), TranslateT("Custom %d"),i+1);
					ListView_InsertItem(GetDlgItem(hwndDlg,IDC_EMAILS),&lvi);
					ListView_SetItemText(GetDlgItem(hwndDlg,IDC_EMAILS),lvi.iItem,1,dbv.ptszVal);
					DBFreeVariant(&dbv);
					lvi.iItem++;
				}
				lvi.mask=LVIF_PARAM;
				lvi.lParam=(LPARAM)(-2);
				ListView_InsertItem(GetDlgItem(hwndDlg,IDC_EMAILS),&lvi);
				//phones
				ListView_DeleteAllItems(GetDlgItem(hwndDlg,IDC_PHONES));
				lvi.mask=LVIF_TEXT|LVIF_PARAM;
				lvi.lParam=(LPARAM)(-1);
				lvi.iSubItem=0;
				lvi.iItem=0;
				if(!DBGetContactSettingTString(hContact,szProto,"Phone",&dbv)) {
					lvi.pszText=TranslateT("Primary");
					ListView_InsertItem(GetDlgItem(hwndDlg,IDC_PHONES),&lvi);
					ListView_SetItemText(GetDlgItem(hwndDlg,IDC_PHONES),lvi.iItem,1,dbv.ptszVal);
					DBFreeVariant(&dbv);
					lvi.iItem++;
				}
				if(!DBGetContactSettingTString(hContact,szProto,"Fax",&dbv)) {
					lvi.pszText=TranslateT("Fax");
					ListView_InsertItem(GetDlgItem(hwndDlg,IDC_PHONES),&lvi);
					ListView_SetItemText(GetDlgItem(hwndDlg,IDC_PHONES),lvi.iItem,1,dbv.ptszVal);
					DBFreeVariant(&dbv);
					lvi.iItem++;
				}
				if(!DBGetContactSettingTString(hContact,szProto,"Cellular",&dbv)) {
					lvi.pszText=TranslateT("Mobile");
					ListView_InsertItem(GetDlgItem(hwndDlg,IDC_PHONES),&lvi);
					if(lstrlenA(dbv.pszVal)>4 && !lstrcmpA(dbv.pszVal+lstrlenA(dbv.pszVal)-4," SMS")) {
						ListView_SetItemText(GetDlgItem(hwndDlg,IDC_PHONES),lvi.iItem,2,_T("y"));
						dbv.ptszVal[lstrlen(dbv.ptszVal)-4]='\0';
					}
					ListView_SetItemText(GetDlgItem(hwndDlg,IDC_PHONES),lvi.iItem,1,dbv.ptszVal);
					DBFreeVariant(&dbv);
					lvi.iItem++;
				}
				if(!DBGetContactSettingTString(hContact,szProto,"CompanyPhone",&dbv)) {
					lvi.pszText=TranslateT("Work Phone");
					ListView_InsertItem(GetDlgItem(hwndDlg,IDC_PHONES),&lvi);
					ListView_SetItemText(GetDlgItem(hwndDlg,IDC_PHONES),lvi.iItem,1,dbv.ptszVal);
					DBFreeVariant(&dbv);
					lvi.iItem++;
				}
				if(!DBGetContactSettingTString(hContact,szProto,"CompanyFax",&dbv)) {
					lvi.pszText=TranslateT("Work Fax");
					ListView_InsertItem(GetDlgItem(hwndDlg,IDC_PHONES),&lvi);
					ListView_SetItemText(GetDlgItem(hwndDlg,IDC_PHONES),lvi.iItem,1,dbv.ptszVal);
					DBFreeVariant(&dbv);
					lvi.iItem++;
				}
				lvi.iSubItem=0;
				for(i=0;;i++) {
					lvi.lParam=i;
					mir_snprintf(idstr, SIZEOF(idstr), "MyPhone%d",i);
					if(DBGetContactSettingTString(hContact,"UserInfo",idstr,&dbv))
						break;
					lvi.pszText=idstr2;
					mir_sntprintf(idstr2, SIZEOF(idstr2), TranslateT("Custom %d"),i+1);
					ListView_InsertItem(GetDlgItem(hwndDlg,IDC_PHONES),&lvi);
					if(lstrlen(dbv.ptszVal)>4 && !lstrcmp(dbv.ptszVal+lstrlen(dbv.ptszVal)-4,_T(" SMS"))) {
						ListView_SetItemText(GetDlgItem(hwndDlg,IDC_PHONES),lvi.iItem,2,_T("y"));
						dbv.ptszVal[lstrlen(dbv.ptszVal)-4]='\0';
					}
					ListView_SetItemText(GetDlgItem(hwndDlg,IDC_PHONES),lvi.iItem,1,dbv.ptszVal);
					DBFreeVariant(&dbv);
					lvi.iItem++;
				}
				lvi.mask=LVIF_PARAM;
				lvi.lParam=(LPARAM)(-2);
				ListView_InsertItem(GetDlgItem(hwndDlg,IDC_PHONES),&lvi);
			}
			break;
		}
		case WM_NOTIFY:
			switch (((LPNMHDR)lParam)->idFrom) {
				case 0:
					switch (((LPNMHDR)lParam)->code) {
						case PSN_INFOCHANGED:
							SendMessage(hwndDlg,M_REMAKELISTS,0,0);
							break;
					}
					break;
				case IDC_EMAILS:
				case IDC_PHONES:
					switch (((LPNMHDR)lParam)->code) {
						case NM_CUSTOMDRAW:
						{	NMLVCUSTOMDRAW *nm=(NMLVCUSTOMDRAW*)lParam;
							switch(nm->nmcd.dwDrawStage) {
								case CDDS_PREPAINT:
								case CDDS_ITEMPREPAINT:
									SetWindowLongPtr(hwndDlg,DWLP_MSGRESULT,CDRF_NOTIFYSUBITEMDRAW);
									return TRUE;
								case CDDS_SUBITEM|CDDS_ITEMPREPAINT:
								{
									RECT rc;
									ListView_GetSubItemRect(nm->nmcd.hdr.hwndFrom,nm->nmcd.dwItemSpec,nm->iSubItem,LVIR_LABEL,&rc);
									if(nm->iSubItem==1 && nm->nmcd.hdr.idFrom==IDC_EMAILS) {
										HFONT hoFont;
										TCHAR szText[256] = {0};
										ListView_GetItemText(nm->nmcd.hdr.hwndFrom,nm->nmcd.dwItemSpec,nm->iSubItem,szText,SIZEOF(szText));
										hoFont=(HFONT)SelectObject(nm->nmcd.hdc,hEmailFont);
										SetTextColor(nm->nmcd.hdc,RGB(0,0,255));
										DrawText(nm->nmcd.hdc,szText,-1,&rc,DT_END_ELLIPSIS|DT_LEFT|DT_NOPREFIX|DT_SINGLELINE|DT_TOP);
										SelectObject(nm->nmcd.hdc,hoFont);
										SetWindowLongPtr(hwndDlg,DWLP_MSGRESULT,CDRF_SKIPDEFAULT);
										return TRUE;
									}

									HICON hIcon = NULL;
									if(nm->nmcd.lItemlParam==(LPARAM)(-2) && nm->iSubItem-3==(nm->nmcd.hdr.idFrom==IDC_PHONES))
										hIcon = LoadSkinIcon( SKINICON_OTHER_ADDCONTACT );
									else if(nm->iSubItem>1 && nm->nmcd.lItemlParam!=(LPARAM)(-1) && nm->nmcd.lItemlParam!=(LPARAM)(-2)) {
										static int iconResources[3]={SKINICON_OTHER_RENAME,SKINICON_OTHER_DELETE};
										if(nm->iSubItem==2 && nm->nmcd.hdr.idFrom==IDC_PHONES) {
											TCHAR szText[2];
											ListView_GetItemText(nm->nmcd.hdr.hwndFrom,nm->nmcd.dwItemSpec,nm->iSubItem,szText,SIZEOF(szText));
											if(szText[0]) hIcon = LoadSkinIcon( SKINICON_OTHER_SMS );
										}
										else hIcon = LoadSkinIcon( iconResources[nm->iSubItem-3+(nm->nmcd.hdr.idFrom==IDC_EMAILS)] );
									}
									else break;
									DrawIconEx(nm->nmcd.hdc,(rc.left+rc.right-GetSystemMetrics(SM_CXSMICON))/2,(rc.top+rc.bottom-GetSystemMetrics(SM_CYSMICON))/2,hIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0,NULL,DI_NORMAL);
									IconLib_ReleaseIcon(hIcon, 0);
									SetWindowLongPtr(hwndDlg,DWLP_MSGRESULT,CDRF_SKIPDEFAULT);
									return TRUE;
								}
							}
							break;
						}
						case NM_CLICK:
						{	NMLISTVIEW *nm=(NMLISTVIEW*)lParam;
							LVITEM lvi;
							TCHAR szEmail[256];
							HANDLE hContact=(HANDLE)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
							char *szIdTemplate=nm->hdr.idFrom==IDC_PHONES?"MyPhone%d":"Mye-mail%d";
							LVHITTESTINFO hti;

							if(IsOverEmail(hwndDlg,szEmail,SIZEOF(szEmail))) {
								TCHAR szExec[264];
								mir_sntprintf(szExec, SIZEOF(szExec), _T("mailto:%s"), szEmail);
								ShellExecute(hwndDlg,_T("open"),szExec,NULL,NULL,SW_SHOW);
								break;
							}
							if(nm->iSubItem<2) break;
							hti.pt.x=(short)LOWORD(GetMessagePos());
							hti.pt.y=(short)HIWORD(GetMessagePos());
							ScreenToClient(nm->hdr.hwndFrom,&hti.pt);
							if(ListView_SubItemHitTest(nm->hdr.hwndFrom,&hti)==-1) break;
							lvi.mask=LVIF_PARAM;
							lvi.iItem=hti.iItem;
							lvi.iSubItem=0;
							ListView_GetItem(nm->hdr.hwndFrom,&lvi);
							if(lvi.lParam==(LPARAM)(-1)) break;
							if(lvi.lParam==(LPARAM)(-2)) {
								if(hti.iSubItem-3==(nm->hdr.idFrom==IDC_PHONES)) {
									//add
									char szNewData[256]="",idstr[33];
									int i;
									DBVARIANT dbv;
									if(IDOK!=DialogBoxParam(hMirandaInst,MAKEINTRESOURCE(nm->hdr.idFrom==IDC_PHONES?IDD_ADDPHONE:IDD_ADDEMAIL),hwndDlg,nm->hdr.idFrom==IDC_PHONES?EditUserPhoneDlgProc:EditUserEmailDlgProc,(LPARAM)szNewData))
										break;
									for(i=0;;i++) {
										mir_snprintf(idstr, SIZEOF(idstr), szIdTemplate,i);
										if(DBGetContactSettingString(hContact,"UserInfo",idstr,&dbv)) break;
										DBFreeVariant(&dbv);
									}
									DBWriteContactSettingString(hContact,"UserInfo",idstr,szNewData);
									SendMessage(hwndDlg,M_REMAKELISTS,0,0);
								}
							}
							else {
								if(hti.iSubItem-3==(nm->hdr.idFrom==IDC_PHONES)) {
									//delete
									int i;
									char idstr[33];
									DBVARIANT dbv;
									for(i=lvi.lParam;;i++) {
										mir_snprintf(idstr, SIZEOF(idstr), szIdTemplate,i+1);
										if(DBGetContactSettingString(hContact,"UserInfo",idstr,&dbv)) break;
										mir_snprintf(idstr, SIZEOF(idstr), szIdTemplate,i);
										DBWriteContactSettingString(hContact,"UserInfo",idstr,dbv.pszVal);
										DBFreeVariant(&dbv);
									}
									mir_snprintf(idstr, SIZEOF(idstr), szIdTemplate,i);
									DBDeleteContactSetting(hContact,"UserInfo",idstr);
									SendMessage(hwndDlg,M_REMAKELISTS,0,0);
								}
								else if(hti.iSubItem-2==(nm->hdr.idFrom==IDC_PHONES)) {
									//edit
									char szText[256],idstr[33];
									DBVARIANT dbv;
									mir_snprintf(idstr, SIZEOF(idstr), szIdTemplate,lvi.lParam);
									if(DBGetContactSettingString(hContact,"UserInfo",idstr,&dbv)) break;
									lstrcpynA(szText,dbv.pszVal,SIZEOF(szText));
									DBFreeVariant(&dbv);
									if(IDOK!=DialogBoxParam(hMirandaInst,MAKEINTRESOURCE(nm->hdr.idFrom==IDC_PHONES?IDD_ADDPHONE:IDD_ADDEMAIL),hwndDlg,nm->hdr.idFrom==IDC_PHONES?EditUserPhoneDlgProc:EditUserEmailDlgProc,(LPARAM)szText))
										break;
									DBWriteContactSettingString(hContact,"UserInfo",idstr,szText);
									SendMessage(hwndDlg,M_REMAKELISTS,0,0);
								}
							}
							break;
						}
					}
					break;
			}
			break;
		case WM_SETCURSOR:
			if(LOWORD(lParam)!=HTCLIENT) break;
			if(GetForegroundWindow()==GetParent(hwndDlg)) {
				POINT pt;
				GetCursorPos(&pt);
				ScreenToClient(hwndDlg,&pt);
//				SetFocus(ChildWindowFromPoint(hwndDlg,pt));	  //ugly hack because listviews ignore their first click
			}
			if(IsOverEmail(hwndDlg,NULL,0)) {
				SetCursor(hHandCursor);
				SetWindowLongPtr(hwndDlg,DWLP_MSGRESULT,TRUE);
				return TRUE;
			}
			break;
		case WM_COMMAND:
			switch(LOWORD(wParam)) {
				case IDCANCEL:
					SendMessage(GetParent(hwndDlg),msg,wParam,lParam);
					break;
			}
			break;
	}
	return FALSE;
}
Example #10
0
static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg,  WPARAM wParam, LPARAM lParam)
{
	MButtonCtrl* bct =  (MButtonCtrl *)GetWindowLongPtr(hwndDlg, 0);
	switch(msg) {
	case WM_NCCREATE:
		SetWindowLongPtr(hwndDlg, GWL_STYLE, GetWindowLongPtr(hwndDlg, GWL_STYLE) | BS_OWNERDRAW);
		bct = ( MButtonCtrl* )mir_calloc(sizeof(MButtonCtrl));
		if (bct==NULL) return FALSE;
		bct->hwnd = hwndDlg;
		bct->stateId = PBS_NORMAL;
		bct->hFont = ( HFONT )GetStockObject(DEFAULT_GUI_FONT);
		LoadTheme(bct);
		if (SUCCEEDED(CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, 
			IID_IAccPropServices, (void**)&bct->pAccPropServices))) 
		{
			// Annotating the Role of this object to be PushButton
			SetHwndPropInt(bct, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_ROLE, ROLE_SYSTEM_PUSHBUTTON);
		} 
		else 
			bct->pAccPropServices = NULL;
		SetWindowLongPtr(hwndDlg, 0, (LONG_PTR)bct);
		if (((CREATESTRUCT *)lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *)lParam)->lpszName);
		return TRUE;

	case WM_DESTROY:
		if (bct) {
			if (bct->pAccPropServices) {
				bct->pAccPropServices->Release();
				bct->pAccPropServices = NULL;
			}
			if (bct->hwndToolTips) {
				TOOLINFO ti = {0};
				ti.cbSize = sizeof(ti);
				ti.uFlags = TTF_IDISHWND;
				ti.hwnd = bct->hwnd;
				ti.uId = (UINT_PTR)bct->hwnd;
				if (SendMessage(bct->hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) {
					SendMessage(bct->hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti);
				}
				if ( SendMessage(bct->hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0 ) {
					int idx;
					TTooltips tt;
					tt.ThreadId = GetCurrentThreadId();
			        
                    EnterCriticalSection(&csTips);
					if ( List_GetIndex( &lToolTips, &tt, &idx ) ) {
						mir_free( lToolTips.items[idx] );
						List_Remove( &lToolTips, idx );
						DestroyWindow( bct->hwndToolTips );
					}
			        LeaveCriticalSection(&csTips);
					
                    bct->hwndToolTips = NULL;
				}
			}
			if (bct->arrow) IconLib_ReleaseIcon(bct->arrow, 0);
			DestroyTheme(bct);
		}
		break;	// DONT! fall thru

    case WM_NCDESTROY:
		mir_free(bct);
        break;

	case WM_SETTEXT:
		bct->cHot = 0;
		if ( lParam != 0 ) {
			TCHAR *tmp = ( TCHAR* )lParam;
			while (*tmp) {
				if (*tmp=='&' && *(tmp+1)) {
					bct->cHot = _tolower(*(tmp+1));
					break;
				}
				tmp++;
			}
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;

	case WM_KEYUP:
		if (bct->stateId!=PBS_DISABLED && wParam == VK_SPACE) {
			if (bct->pushBtn) {
				if (bct->pbState) {
					bct->pbState = 0;
					bct->stateId = PBS_NORMAL;
				}
				else {
					bct->pbState = 1;
					bct->stateId = PBS_PRESSED;
				}
				InvalidateRect(bct->hwnd, NULL, TRUE);
			}
			SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
			return 0;
		}
		break;

	case WM_SYSKEYUP:
		if (bct->stateId!=PBS_DISABLED && bct->cHot && bct->cHot == tolower((int)wParam)) {
			if (bct->pushBtn) {
				if (bct->pbState) {
					bct->pbState = 0;
					bct->stateId = PBS_NORMAL;
				}
				else {
					bct->pbState = 1;
					bct->stateId = PBS_PRESSED;
				}
				InvalidateRect(bct->hwnd, NULL, TRUE);
			}
			SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
			return 0;
		}
		break;

	case WM_THEMECHANGED:
		// themed changed, reload theme object
		LoadTheme(bct);
		InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
		break;

	case WM_SETFONT: // remember the font so we can use it later
		bct->hFont = (HFONT)wParam; // maybe we should redraw?
		break;

	case WM_NCPAINT:
	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		HDC hdcPaint;

		hdcPaint = BeginPaint(hwndDlg, &ps);
		if (hdcPaint) {
			PaintWorker(bct, hdcPaint);
			EndPaint(hwndDlg, &ps);
		}
		break;
	}
	case BM_SETIMAGE:
	{
		HGDIOBJ hnd = NULL;
		if (bct->hIcon) hnd = bct->hIcon;
		else if (bct->hBitmap) hnd = bct->hBitmap;

		if (wParam == IMAGE_ICON) {
			bct->hIcon = (HICON)lParam;
			bct->hBitmap = NULL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		else if (wParam == IMAGE_BITMAP) {
			bct->hBitmap = (HBITMAP)lParam;
			bct->hIcon = NULL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		return (LRESULT)hnd;
	}
	case BM_GETIMAGE:
		if (bct->hIcon) return (LRESULT)bct->hIcon;
		else if (bct->hBitmap) return (LRESULT)bct->hBitmap;
		else return 0;
	case BM_SETCHECK:
		if (!bct->pushBtn) break;
		if (wParam == BST_CHECKED) {
			bct->pbState = 1;
               bct->stateId = PBS_PRESSED;
		}
		else if (wParam == BST_UNCHECKED) {
			bct->pbState = 0;
               bct->stateId = PBS_NORMAL;
		}
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BM_GETCHECK:
		if (bct->pushBtn) {
			return bct->pbState?BST_CHECKED:BST_UNCHECKED;
		}
		return 0;
	case BUTTONSETARROW: // turn arrow on/off
		if (wParam) {
			if (!bct->arrow) {
				bct->arrow = LoadSkinIcon(SKINICON_OTHER_DOWNARROW);
				SetHwndPropInt(bct, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_ROLE, ROLE_SYSTEM_BUTTONDROPDOWN);
			}
		}
		else {
			if (bct->arrow) {
				IconLib_ReleaseIcon(bct->arrow, 0);
				bct->arrow = NULL;
				SetHwndPropInt(bct, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_ROLE, ROLE_SYSTEM_PUSHBUTTON);
			}
		}
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BUTTONSETDEFAULT:
		bct->defbutton = wParam?1:0;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BUTTONSETASPUSHBTN:
		bct->pushBtn = 1;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BUTTONSETASFLATBTN:
		bct->flatBtn = 1;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BUTTONADDTOOLTIP:
		if ( wParam ) {
			TOOLINFO ti = {0};
			if ( !bct->hwndToolTips ) {
				int idx;
				TTooltips tt;
				tt.ThreadId = GetCurrentThreadId();
			    
                EnterCriticalSection(&csTips);
				if ( List_GetIndex( &lToolTips, &tt, &idx )) {
					bct->hwndToolTips = ((TTooltips*)lToolTips.items[idx])->hwnd;
				} else {
					TTooltips *ptt = ( TTooltips* )mir_alloc( sizeof(TTooltips) );
					ptt->ThreadId = tt.ThreadId;
					ptt->hwnd = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), TTS_ALWAYSTIP, 0, 0, 0, 0, NULL, NULL, hMirandaInst, NULL);
					List_Insert( &lToolTips, ptt, idx );
					bct->hwndToolTips = ptt->hwnd;
				}
    			LeaveCriticalSection(&csTips);
			}
			ti.cbSize = sizeof(ti);
			ti.uFlags = TTF_IDISHWND;
			ti.hwnd = bct->hwnd;
			ti.uId = (UINT_PTR)bct->hwnd;
			if (SendMessage(bct->hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti))
				SendMessage(bct->hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti);
			ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;
			ti.uId = (UINT_PTR)bct->hwnd;
			#if defined( _UNICODE )
				if ( lParam & BATF_UNICODE )
					ti.lpszText = mir_wstrdup( TranslateW(( WCHAR* )wParam ));
				else
					ti.lpszText = LangPackPcharToTchar(( char* )wParam );
			#else
				ti.lpszText = Translate(( char* )wParam );
			#endif
			if (bct->pAccPropServices) {
				wchar_t *tmpstr = mir_t2u(ti.lpszText);
				bct->pAccPropServices->SetHwndPropStr(bct->hwnd, OBJID_CLIENT, 
					CHILDID_SELF, PROPID_ACC_DESCRIPTION, tmpstr);
				mir_free(tmpstr);
			}
			SendMessage( bct->hwndToolTips, TTM_ADDTOOL, 0, (LPARAM)&ti);
			#if defined( _UNICODE )
				mir_free( ti.lpszText );
			#endif
		}
		break;
	case WM_SETFOCUS: // set keybord focus and redraw
		bct->focus = 1;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;

	case WM_KILLFOCUS: // kill focus and redraw
		bct->focus = 0;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;

	case WM_WINDOWPOSCHANGED:
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;

	case WM_ENABLE: // windows tells us to enable/disable
		bct->stateId = wParam?PBS_NORMAL:PBS_DISABLED;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;

	case WM_MOUSELEAVE: // faked by the WM_TIMER
		if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
			bct->stateId = PBS_NORMAL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;

	case WM_LBUTTONDOWN:
		if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
			bct->stateId = PBS_PRESSED;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;

	case WM_LBUTTONUP:
    {
        int showClick = 0;
		if (bct->pushBtn) {
			if (bct->pbState) bct->pbState = 0;
			else bct->pbState = 1;
		}
		if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
            if (bct->stateId==PBS_PRESSED)
                showClick = 1;
			if (msg==WM_LBUTTONUP) bct->stateId = PBS_HOT;
			else bct->stateId = PBS_NORMAL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
        if (showClick) // Tell your daddy you got clicked.
            SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
		break;
    }
	case WM_MOUSEMOVE:
		if (bct->stateId == PBS_NORMAL) {
			bct->stateId = PBS_HOT;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		// Call timer, used to start cheesy TrackMouseEvent faker
		SetTimer(hwndDlg,BUTTON_POLLID,BUTTON_POLLDELAY,NULL);
		break;
	case WM_TIMER: // use a timer to check if they have did a mouseout
		if (wParam == BUTTON_POLLID) {
			RECT rc;
			POINT pt;
			GetWindowRect(hwndDlg,&rc);
			GetCursorPos(&pt);
			if(!PtInRect(&rc,pt)) { // mouse must be gone, trigger mouse leave
				PostMessage(hwndDlg,WM_MOUSELEAVE,0,0L);
				KillTimer(hwndDlg,BUTTON_POLLID);
		}	}
		break;

	case WM_ERASEBKGND:
		return 1;
	}
	return DefWindowProc(hwndDlg, msg, wParam, lParam);
}