Esempio n. 1
0
static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
	switch(msg) {
	case WM_INITDIALOG:
		{
			LCID locale;
			hwndSettingsDlg=hwndDlg;
			TranslateDialogDefault(hwndDlg);
			locale=CallService(MS_LANGPACK_GETLOCALE,0,0);
			SendDlgItemMessage(hwndDlg,IDC_ICON_HEADER,STM_SETIMAGE,IMAGE_ICON,(LPARAM)Skin_GetIcon("AutoShutdown_Header"));
			{
				HFONT hBoldFont;
				LOGFONT lf;
				if (GetObject((HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0),sizeof(lf),&lf)) {
					lf.lfWeight=FW_BOLD;
					hBoldFont=CreateFontIndirect(&lf);
				} else hBoldFont=NULL;
				SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,(WPARAM)hBoldFont,FALSE);
			}
			/* read-in watcher flags */
			{
				WORD watcherType=db_get_w(NULL,"AutoShutdown","WatcherFlags",SETTING_WATCHERFLAGS_DEFAULT);
				CheckRadioButton(hwndDlg,IDC_RADIO_STTIME,IDC_RADIO_STCOUNTDOWN,(watcherType&SDWTF_ST_TIME)?IDC_RADIO_STTIME:IDC_RADIO_STCOUNTDOWN);
				CheckDlgButton(hwndDlg,IDC_CHECK_SPECIFICTIME,(watcherType&SDWTF_SPECIFICTIME) != 0 ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hwndDlg,IDC_CHECK_MESSAGE,(watcherType&SDWTF_MESSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hwndDlg,IDC_CHECK_FILETRANSFER,(watcherType&SDWTF_FILETRANSFER) != 0 ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hwndDlg,IDC_CHECK_IDLE,(watcherType&SDWTF_IDLE) != 0 ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hwndDlg,IDC_CHECK_STATUS,(watcherType&SDWTF_STATUS) != 0 ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hwndDlg,IDC_CHECK_CPUUSAGE,(watcherType&SDWTF_CPUUSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED);
			}
			/* read-in countdown val */
			{
				SYSTEMTIME st;
				if (!TimeStampToSystemTime((time_t)db_get_dw(NULL,"AutoShutdown","TimeStamp",SETTING_TIMESTAMP_DEFAULT),&st))
					GetLocalTime(&st);
				DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),GDT_VALID,&st);
				DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),GDT_VALID,&st);
				SendMessage(hwndDlg,M_CHECK_DATETIME,0,0);
			}
			{
				DWORD setting=db_get_dw(NULL,"AutoShutdown","Countdown",SETTING_COUNTDOWN_DEFAULT);
				if (setting<1) setting=SETTING_COUNTDOWN_DEFAULT;
				SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETRANGE,0,MAKELPARAM(UD_MAXVAL,1));
				SendDlgItemMessage(hwndDlg,IDC_EDIT_COUNTDOWN,EM_SETLIMITTEXT,(WPARAM)10,0);
				SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETPOS,0,MAKELPARAM(setting,0));
				SetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,setting,FALSE);
			}
			{
				HWND hwndCombo=GetDlgItem(hwndDlg,IDC_COMBO_COUNTDOWNUNIT);
				DWORD lastUnit=db_get_dw(NULL,"AutoShutdown","CountdownUnit",SETTING_COUNTDOWNUNIT_DEFAULT);
				SendMessage(hwndCombo,CB_SETLOCALE,(WPARAM)locale,0); /* sort order */
				SendMessage(hwndCombo,CB_INITSTORAGE,SIZEOF(unitNames),SIZEOF(unitNames)*16); /* approx. */
				for(int i=0;i<SIZEOF(unitNames);++i) {
					int index=SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)TranslateTS(unitNames[i]));
					if (index != LB_ERR) {
						SendMessage(hwndCombo,CB_SETITEMDATA,index,(LPARAM)unitValues[i]);
						if (i==0 || unitValues[i]==lastUnit) SendMessage(hwndCombo,CB_SETCURSEL,index,0);
					}
				}
			}
			{
				DBVARIANT dbv;
				if (!db_get_ts(NULL,"AutoShutdown","Message",&dbv)) {
					SetDlgItemText(hwndDlg,IDC_EDIT_MESSAGE,dbv.ptszVal);
					mir_free(dbv.ptszVal);
				}
			}
			/* cpuusage threshold */
			{
				BYTE setting=DBGetContactSettingRangedByte(NULL,"AutoShutdown","CpuUsageThreshold",SETTING_CPUUSAGETHRESHOLD_DEFAULT,1,100);
				SendDlgItemMessage(hwndDlg,IDC_SPIN_CPUUSAGE,UDM_SETRANGE,0,MAKELPARAM(100,1));
				SendDlgItemMessage(hwndDlg,IDC_EDIT_CPUUSAGE,EM_SETLIMITTEXT,(WPARAM)3,0);
				SendDlgItemMessage(hwndDlg,IDC_SPIN_CPUUSAGE,UDM_SETPOS,0,MAKELPARAM(setting,0));
				SetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,setting,FALSE);
			}
			/* shutdown types */
			{
				HWND hwndCombo=GetDlgItem(hwndDlg,IDC_COMBO_SHUTDOWNTYPE);
				BYTE lastShutdownType=db_get_b(NULL,"AutoShutdown","ShutdownType",SETTING_SHUTDOWNTYPE_DEFAULT);
				SendMessage(hwndCombo,CB_SETLOCALE,(WPARAM)locale,0); /* sort order */
				SendMessage(hwndCombo,CB_SETEXTENDEDUI,TRUE,0);
				SendMessage(hwndCombo,CB_INITSTORAGE,SDSDT_MAX,SDSDT_MAX*32);
				for(BYTE shutdownType=1;shutdownType<=SDSDT_MAX;++shutdownType)
					if (ServiceIsTypeEnabled(shutdownType,0)) {
						TCHAR *pszText=(TCHAR*)ServiceGetTypeDescription(shutdownType,GSTDF_TCHAR); /* never fails */
						int index=SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)pszText);
						if (index != LB_ERR) {
							SendMessage(hwndCombo,CB_SETITEMDATA,index,(LPARAM)shutdownType);
							if (shutdownType==1 || shutdownType==lastShutdownType) SendMessage(hwndCombo,CB_SETCURSEL,(WPARAM)index,0);
						}
					}
				SendMessage(hwndDlg,M_UPDATE_SHUTDOWNDESC,0,(LPARAM)hwndCombo);
			}
			/* check if proto is installed that supports instant messages and check if a message dialog plugin is installed */
			if (!AnyProtoHasCaps(PF1_IMRECV) || !ServiceExists(MS_MSG_SENDMESSAGE)) { /* no srmessage present? */
				CheckDlgButton(hwndDlg, IDC_CHECK_MESSAGE, BST_UNCHECKED);
				EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_MESSAGE),FALSE);
				EnableWindow(GetDlgItem(hwndDlg,IDC_EDIT_MESSAGE),FALSE);
			}
			/* check if proto is installed that supports file transfers and check if a file transfer dialog is available */
			if (!AnyProtoHasCaps(PF1_FILESEND) && !AnyProtoHasCaps(PF1_FILERECV)) {  /* no srfile present? */
				CheckDlgButton(hwndDlg, IDC_CHECK_FILETRANSFER, BST_UNCHECKED);
				EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_FILETRANSFER),FALSE);
			}
			/* check if cpu usage can be detected */
			if (!PollCpuUsage(DisplayCpuUsageProc,(LPARAM)GetDlgItem(hwndDlg,IDC_TEXT_CURRENTCPU),1800)) {
				CheckDlgButton(hwndDlg, IDC_CHECK_CPUUSAGE, BST_UNCHECKED);
				EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_CPUUSAGE),FALSE);
			}
			SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
			Utils_RestoreWindowPositionNoSize(hwndDlg,NULL,"AutoShutdown","SettingsDlg_");
			return TRUE; /* default focus */
		}
	case WM_DESTROY:
		{
			Utils_SaveWindowPosition(hwndDlg,NULL,"AutoShutdown","SettingsDlg_");
			HICON hIcon=(HICON)SendDlgItemMessage(hwndDlg,IDC_ICON_HEADER,STM_SETIMAGE,IMAGE_ICON,0);
			HFONT hFont=(HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0);
			SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,0,FALSE); /* no return value */
			if (hFont != NULL) DeleteObject(hFont);
			hwndSettingsDlg=NULL;
		}
		return TRUE;

	case WM_CTLCOLORSTATIC:
		switch(GetDlgCtrlID((HWND)lParam)) {
		case IDC_ICON_HEADER:
			SetBkMode((HDC)wParam,TRANSPARENT);
		case IDC_RECT_HEADER:
			/* need to set COLOR_WINDOW manually for Win9x */
			SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW));
			return (BOOL)GetSysColorBrush(COLOR_WINDOW);
		case IDC_TEXT_HEADER:
		case IDC_TEXT_HEADERDESC:
			SetBkMode((HDC)wParam,TRANSPARENT);
			return (BOOL)GetStockObject(NULL_BRUSH);
		}
		break;

	case M_ENABLE_SUBCTLS:
		{
			BOOL checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE) != 0;
			EnableDlgItem(hwndDlg,IDC_EDIT_MESSAGE,checked);
			checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) != 0;
			EnableDlgItem(hwndDlg,IDC_RADIO_STTIME,checked);
			EnableDlgItem(hwndDlg,IDC_RADIO_STCOUNTDOWN,checked);
			checked=(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg,IDC_RADIO_STTIME));
			EnableDlgItem(hwndDlg,IDC_TIME_TIMESTAMP,checked);
			EnableDlgItem(hwndDlg,IDC_DATE_TIMESTAMP,checked);
			checked=(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg,IDC_RADIO_STCOUNTDOWN));
			EnableDlgItem(hwndDlg,IDC_EDIT_COUNTDOWN,checked);
			EnableDlgItem(hwndDlg,IDC_SPIN_COUNTDOWN,checked);
			EnableDlgItem(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,checked);
			checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE) != 0;
			EnableDlgItem(hwndDlg,IDC_URL_IDLE,checked);
			checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE) != 0;
			EnableDlgItem(hwndDlg,IDC_EDIT_CPUUSAGE,checked);
			EnableDlgItem(hwndDlg,IDC_SPIN_CPUUSAGE,checked);
			EnableDlgItem(hwndDlg,IDC_TEXT_PERCENT,checked);
			EnableDlgItem(hwndDlg,IDC_TEXT_CURRENTCPU,checked);
			checked=(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE) ||
				IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_STATUS) ||
				IsDlgButtonChecked(hwndDlg,IDC_CHECK_FILETRANSFER) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE));
			EnableDlgItem(hwndDlg,IDOK,checked);
		}
		return TRUE;
	case M_UPDATE_SHUTDOWNDESC: /* lParam=(LPARAM)(HWND)hwndCombo */
		{
			BYTE shutdownType = (BYTE)SendMessage((HWND)lParam,CB_GETITEMDATA,SendMessage((HWND)lParam,CB_GETCURSEL,0,0),0);
			SetDlgItemText(hwndDlg,IDC_TEXT_SHUTDOWNTYPE,(TCHAR*)ServiceGetTypeDescription(shutdownType,GSTDF_LONGDESC|GSTDF_TCHAR));
		}
		return TRUE;

	case WM_TIMECHANGE: /* system time changed */
		SendMessage(hwndDlg,M_CHECK_DATETIME,0,0);
		return TRUE;

	case M_CHECK_DATETIME:
		{
			SYSTEMTIME st,stBuf;
			time_t timestamp;
			DateTime_GetSystemtime(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),&stBuf);
			DateTime_GetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),&st);
			st.wDay=stBuf.wDay;
			st.wDayOfWeek=stBuf.wDayOfWeek;
			st.wMonth=stBuf.wMonth;
			st.wYear=stBuf.wYear;
			GetLocalTime(&stBuf);
			if (SystemTimeToTimeStamp(&st,&timestamp)) {
				/* set to current date if earlier */
				if (timestamp<time(NULL)) {
					st.wDay=stBuf.wDay;
					st.wDayOfWeek=stBuf.wDayOfWeek;
					st.wMonth=stBuf.wMonth;
					st.wYear=stBuf.wYear;
					if (SystemTimeToTimeStamp(&st,&timestamp)) {
						/* step one day up if still earlier */
						if (timestamp<time(NULL)) {
							timestamp+=24*60*60;
							TimeStampToSystemTime(timestamp,&st);
						}
					}
				}
			}
			DateTime_SetRange(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),GDTR_MIN,&stBuf);
			DateTime_SetRange(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),GDTR_MIN,&stBuf);
			DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),GDT_VALID,&st);
			DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),GDT_VALID,&st);
			return TRUE;
		}
	case WM_NOTIFY:
		switch(((NMHDR*)lParam)->idFrom) {
		case IDC_TIME_TIMESTAMP:
		case IDC_DATE_TIMESTAMP:
			switch(((NMHDR*)lParam)->code) {
			case DTN_CLOSEUP:
			case NM_KILLFOCUS:
				PostMessage(hwndDlg,M_CHECK_DATETIME,0,0);
				return TRUE;
			}
		}
		break;

	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case IDC_CHECK_MESSAGE:
		case IDC_CHECK_FILETRANSFER:
		case IDC_CHECK_IDLE:
		case IDC_CHECK_CPUUSAGE:
		case IDC_CHECK_STATUS:
		case IDC_CHECK_SPECIFICTIME:
		case IDC_RADIO_STTIME:
		case IDC_RADIO_STCOUNTDOWN:
			SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
			return TRUE;

		case IDC_EDIT_COUNTDOWN:
			if (HIWORD(wParam)==EN_KILLFOCUS) {
				if ((int)GetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,NULL,TRUE)<1) {
					SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETPOS,0,MAKELPARAM(1,0));
					SetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,1,FALSE);
				}
				return TRUE;
			}
			break;

		case IDC_EDIT_CPUUSAGE:
			if (HIWORD(wParam)==EN_KILLFOCUS) {
				WORD val=(WORD)GetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,NULL,FALSE);
				if (val<1) val=1;
				else if (val>100) val=100;
				SendDlgItemMessage(hwndDlg,IDC_SPIN_CPUUSAGE,UDM_SETPOS,0,MAKELPARAM(val,0));
				SetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,val,FALSE);
				return TRUE;
			}
			break;

		case IDC_URL_IDLE:
			{	
				OPENOPTIONSDIALOG ood;
				ood.cbSize = sizeof(ood);
				ood.pszGroup = "Status"; /* autotranslated */
				ood.pszPage = "Idle"; /* autotranslated */
				ood.pszTab = NULL;
				Options_Open(&ood);
				return TRUE;
			}

		case IDC_COMBO_SHUTDOWNTYPE:
			if (HIWORD(wParam)==CBN_SELCHANGE)
				SendMessage(hwndDlg,M_UPDATE_SHUTDOWNDESC,0,lParam);
			return TRUE;

		case IDOK: /* save settings and start watcher */
			ShowWindow(hwndDlg,SW_HIDE);
			/* message text */
			{
				HWND hwndEdit=GetDlgItem(hwndDlg,IDC_EDIT_MESSAGE);
				int len=GetWindowTextLength(hwndEdit)+1;
				TCHAR *pszText=(TCHAR*)mir_alloc(len*sizeof(TCHAR));
				if (pszText != NULL && GetWindowText(hwndEdit,pszText,len+1)) {
					TrimString(pszText);
					db_set_ts(NULL,"AutoShutdown","Message",pszText);
				}
				mir_free(pszText); /* does NULL check */
			}
			/* timestamp */
			{
				SYSTEMTIME st;
				time_t timestamp;
				DateTime_GetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),&st); /* time gets synchronized */
				if (!SystemTimeToTimeStamp(&st,&timestamp))
					timestamp=time(NULL);
				db_set_dw(NULL,"AutoShutdown","TimeStamp",(DWORD)timestamp);
			}
			/* shutdown type */
			{
				int index = SendDlgItemMessage(hwndDlg,IDC_COMBO_SHUTDOWNTYPE,CB_GETCURSEL,0,0);
				if (index != LB_ERR) db_set_b(NULL,"AutoShutdown","ShutdownType",(BYTE)SendDlgItemMessage(hwndDlg,IDC_COMBO_SHUTDOWNTYPE,CB_GETITEMDATA,(WPARAM)index,0));
				index=SendDlgItemMessage(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,CB_GETCURSEL,0,0);
				if (index != LB_ERR) db_set_dw(NULL,"AutoShutdown","CountdownUnit",(DWORD)SendDlgItemMessage(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,CB_GETITEMDATA,(WPARAM)index,0));
				db_set_dw(NULL,"AutoShutdown","Countdown",(DWORD)GetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,NULL,FALSE));
				db_set_b(NULL,"AutoShutdown","CpuUsageThreshold",(BYTE)GetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,NULL,FALSE));
			}
			/* watcher type */
			{
				WORD watcherType = (WORD)(IsDlgButtonChecked(hwndDlg,IDC_RADIO_STTIME)?SDWTF_ST_TIME:SDWTF_ST_COUNTDOWN);
				if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME)) watcherType|=SDWTF_SPECIFICTIME;
				if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE)) watcherType|=SDWTF_MESSAGE;
				if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_FILETRANSFER)) watcherType|=SDWTF_FILETRANSFER;
				if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE)) watcherType|=SDWTF_IDLE;
				if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_STATUS)) watcherType|=SDWTF_STATUS;
				if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE)) watcherType|=SDWTF_CPUUSAGE;
				db_set_w(NULL,"AutoShutdown","WatcherFlags",watcherType);
				ServiceStartWatcher(0,watcherType);
			}
			DestroyWindow(hwndDlg);
			return TRUE;
			/* fall through */
		case IDCANCEL: /* WM_CLOSE */
			DestroyWindow(hwndDlg);
			SetShutdownToolbarButton(false);
			SetShutdownMenuItem(false);
			return TRUE;
		}
		break;
	}
	return FALSE;
}
Esempio n. 2
0
INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) 
{
	switch (msg) 
	{
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		// make the buttons flat
		SendMessage(GetDlgItem(hwndDlg,IDC_STEP1), BUTTONSETASFLATBTN, TRUE, 0);
		SendMessage(GetDlgItem(hwndDlg,IDC_STEP2), BUTTONSETASFLATBTN, TRUE, 0);
		SendMessage(GetDlgItem(hwndDlg,IDC_STEP3), BUTTONSETASFLATBTN, TRUE, 0);
		SendMessage(GetDlgItem(hwndDlg,IDC_STEP4), BUTTONSETASFLATBTN, TRUE, 0);

		// set icons
		SendMessage(hwndDlg, WM_SETICON, ICON_BIG,   (LPARAM)LoadIconEx("main", TRUE));
		SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconEx("main", FALSE));

		WindowList_Add(hWindowList, hwndDlg, NULL);
		ShowWindow(hwndDlg, SW_SHOW);
		break;

	case WM_COMMAND:
		switch(LOWORD(wParam)) 
		{
		case IDC_STEP1:
			// update current data
			CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)_T("http://miranda-ng.org/"));
			break;

		case IDC_STEP2: 
			{
				TCHAR szPath[1024];
				GetModuleFileName(GetModuleHandle(NULL), szPath, SIZEOF(szPath));
				TCHAR *chop = _tcsrchr(szPath, '\\');
				*chop = '\0';
				_tcsncat(szPath, _T("\\Plugins\\weather\\"),SIZEOF(szPath));
				_tmkdir(szPath);
				ShellExecute((HWND)lParam, _T("open"), szPath, _T(""), _T(""), SW_SHOW);
				break;
			}

		case IDC_STEP3:
			if (LoadWIData(false))
				MessageBox(NULL, 
					TranslateT("All update data has been reloaded."), 
					TranslateT("Weather Protocol"), MB_OK|MB_ICONINFORMATION);
			break;

		case IDC_STEP4:
			WeatherAdd(0, 0);

		case IDCANCEL:
			// close the info window
			DestroyWindow(hwndDlg);
			break;
		}
		break;

	case WM_CLOSE:
		DestroyWindow(hwndDlg);
		break;

	case WM_DESTROY:
		ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
		ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
		break;
	}
	return FALSE;
}
Esempio n. 3
0
////////////////////////////////////////////////////////////////////////////////////////////
// Proc: Advanced options dialog
static INT_PTR CALLBACK gg_advoptsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	GGPROTO *gg = (GGPROTO *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	DBVARIANT dbv;
	DWORD num;

	switch (msg) {
	case WM_INITDIALOG:
		gg = (GGPROTO *)lParam;
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);

		TranslateDialogDefault(hwndDlg);
		if (!gg->getString(GG_KEY_SERVERHOSTS, &dbv)) {
			SetDlgItemTextA(hwndDlg, IDC_HOST, dbv.pszVal);
			db_free(&dbv);
		}
		else SetDlgItemTextA(hwndDlg, IDC_HOST, GG_KEYDEF_SERVERHOSTS);

		CheckDlgButton(hwndDlg, IDC_KEEPALIVE, gg->getByte(GG_KEY_KEEPALIVE, GG_KEYDEF_KEEPALIVE) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hwndDlg, IDC_SHOWCERRORS, gg->getByte(GG_KEY_SHOWCERRORS, GG_KEYDEF_SHOWCERRORS) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hwndDlg, IDC_ARECONNECT, gg->getByte(GG_KEY_ARECONNECT, GG_KEYDEF_ARECONNECT) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hwndDlg, IDC_MSGACK, gg->getByte(GG_KEY_MSGACK, GG_KEYDEF_MSGACK) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hwndDlg, IDC_MANUALHOST, gg->getByte(GG_KEY_MANUALHOST, GG_KEYDEF_MANUALHOST) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hwndDlg, IDC_SSLCONN, gg->getByte(GG_KEY_SSLCONN, GG_KEYDEF_SSLCONN) ? BST_CHECKED : BST_UNCHECKED);

		EnableWindow(GetDlgItem(hwndDlg, IDC_HOST), IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));
		EnableWindow(GetDlgItem(hwndDlg, IDC_PORT), IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));

		CheckDlgButton(hwndDlg, IDC_DIRECTCONNS, gg->getByte(GG_KEY_DIRECTCONNS, GG_KEYDEF_DIRECTCONNS) ? BST_CHECKED : BST_UNCHECKED);
		if (num = gg->getWord(GG_KEY_DIRECTPORT, GG_KEYDEF_DIRECTPORT))
			SetDlgItemTextA(hwndDlg, IDC_DIRECTPORT, ditoa(num));
		CheckDlgButton(hwndDlg, IDC_FORWARDING, gg->getByte(GG_KEY_FORWARDING, GG_KEYDEF_FORWARDING) ? BST_CHECKED : BST_UNCHECKED);
		if (!gg->getString(GG_KEY_FORWARDHOST, &dbv)) {
			SetDlgItemTextA(hwndDlg, IDC_FORWARDHOST, dbv.pszVal);
			db_free(&dbv);
		}
		if (num = gg->getWord(GG_KEY_FORWARDPORT, GG_KEYDEF_FORWARDPORT))
			SetDlgItemTextA(hwndDlg, IDC_FORWARDPORT, ditoa(num));

		EnableWindow(GetDlgItem(hwndDlg, IDC_DIRECTPORT), IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
		EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDING), IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
		EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDPORT), IsDlgButtonChecked(hwndDlg, IDC_FORWARDING) && IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
		EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDHOST), IsDlgButtonChecked(hwndDlg, IDC_FORWARDING) && IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
		break;

	case WM_COMMAND:
		if ((LOWORD(wParam) == IDC_DIRECTPORT || LOWORD(wParam) == IDC_FORWARDHOST || LOWORD(wParam) == IDC_FORWARDPORT)
			&& (HIWORD(wParam) != EN_CHANGE || (HWND) lParam != GetFocus()))
			return 0;
		switch (LOWORD(wParam)) {
		case IDC_MANUALHOST:
			{
				EnableWindow(GetDlgItem(hwndDlg, IDC_HOST), IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));
				EnableWindow(GetDlgItem(hwndDlg, IDC_PORT), IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));
				ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);
				break;
			}
		case IDC_DIRECTCONNS:
		case IDC_FORWARDING:
			{
				EnableWindow(GetDlgItem(hwndDlg, IDC_DIRECTPORT), IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
				EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDING), IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
				EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDPORT), IsDlgButtonChecked(hwndDlg, IDC_FORWARDING) && IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
				EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDHOST), IsDlgButtonChecked(hwndDlg, IDC_FORWARDING) && IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
				ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);
				break;
			}
		}
		SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR) lParam)->code) {
		case PSN_APPLY:
			{
				char str[512];
				gg->setByte(GG_KEY_KEEPALIVE, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_KEEPALIVE));
				gg->setByte(GG_KEY_SHOWCERRORS, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_SHOWCERRORS));
				gg->setByte(GG_KEY_ARECONNECT, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_ARECONNECT));
				gg->setByte(GG_KEY_MSGACK, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_MSGACK));
				gg->setByte(GG_KEY_MANUALHOST, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));
				gg->setByte(GG_KEY_SSLCONN, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_SSLCONN));

				// Transfer settings
				gg->setByte(GG_KEY_DIRECTCONNS, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
				gg->setByte(GG_KEY_FORWARDING, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_FORWARDING));

				// Write custom servers
				GetDlgItemTextA(hwndDlg, IDC_HOST, str, _countof(str));
				gg->setString(GG_KEY_SERVERHOSTS, str);

				// Write direct port
				GetDlgItemTextA(hwndDlg, IDC_DIRECTPORT, str, _countof(str));
				gg->setWord(GG_KEY_DIRECTPORT, (WORD)atoi(str));
				// Write forwarding host
				GetDlgItemTextA(hwndDlg, IDC_FORWARDHOST, str, _countof(str));
				gg->setString(GG_KEY_FORWARDHOST, str);
				GetDlgItemTextA(hwndDlg, IDC_FORWARDPORT, str, _countof(str));
				gg->setWord(GG_KEY_FORWARDPORT, (WORD)atoi(str));
				break;
			}
		}
		break;
	}
	return FALSE;
}
Esempio n. 4
0
INT_PTR CALLBACK CVkProto::OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	CVkProto *ppro = (CVkProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (uMsg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		ppro = (CVkProto*)lParam;
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);

		SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIconByHandle(ppro->m_hProtoIcon, true));
		SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIconByHandle(ppro->m_hProtoIcon));
		{
			ptrT tszLogin(ppro->getTStringA("Login"));
			if (tszLogin != NULL)
				SetDlgItemText(hwndDlg, IDC_LOGIN, tszLogin);

			ptrT tszPassw(ppro->GetUserStoredPassword());
			if (tszPassw != NULL)
				SetDlgItemText(hwndDlg, IDC_PASSWORD, tszPassw);

			SetDlgItemText(hwndDlg, IDC_GROUPNAME, ppro->getGroup());
		}
		CheckDlgButton(hwndDlg, IDC_DELIVERY, ppro->m_bServerDelivery);
		CheckDlgButton(hwndDlg, IDC_HIDECHATS, ppro->m_bHideChats);
		CheckDlgButton(hwndDlg, IDC_AUTOCLEAN, ppro->getByte("AutoClean", 0));
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_URL:
			CallService(MS_UTILS_OPENURL, 1, (LPARAM)"http://www.vk.com");
			break;

		case IDC_LOGIN:
		case IDC_PASSWORD:
		case IDC_GROUPNAME:
			if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus())
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_DELIVERY:
		case IDC_HIDECHATS:
		case IDC_AUTOCLEAN:
			if (HIWORD(wParam) == BN_CLICKED && (HWND)lParam == GetFocus())
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		}
		break;

	case WM_NOTIFY:
		if (((LPNMHDR)lParam)->code == PSN_APPLY) {
			TCHAR str[128];
			GetDlgItemText(hwndDlg, IDC_LOGIN, str, SIZEOF(str));
			ppro->setTString("Login", str);

			GetDlgItemText(hwndDlg, IDC_GROUPNAME, str, SIZEOF(str));
			if (_tcscmp(ppro->getGroup(), str)) {
				ppro->setGroup(str);
				ppro->setTString("ProtoGroup", str);
			}

			GetDlgItemText(hwndDlg, IDC_PASSWORD, str, SIZEOF(str));
			ptrA szRawPasswd(mir_utf8encodeT(str));
			if (szRawPasswd != NULL)
				ppro->setString("Password", szRawPasswd);

			ppro->m_bServerDelivery = IsDlgButtonChecked(hwndDlg, IDC_DELIVERY) == BST_CHECKED;
			ppro->setByte("ServerDelivery", ppro->m_bServerDelivery);

			ppro->m_bHideChats = IsDlgButtonChecked(hwndDlg, IDC_HIDECHATS) == BST_CHECKED;
			ppro->setByte("HideChats", ppro->m_bHideChats);

			ppro->setByte("AutoClean", IsDlgButtonChecked(hwndDlg, IDC_AUTOCLEAN) == BST_CHECKED);
		}
		break;

	case WM_CLOSE:
		EndDialog(hwndDlg, 0);
		break;

	case WM_DESTROY:
		Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_GETICON, ICON_BIG, 0));
		Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_GETICON, ICON_SMALL, 0));
		break;
	}

	return FALSE;
}
Esempio n. 5
0
static INT_PTR CALLBACK ReadAwayMsgDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			HICON hTitleIcon = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
			SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hTitleIcon);
			SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hTitleIcon);
			Utils_RestoreWindowPosition(hwndDlg, NULL, MOD_NAME, RAMDLGSIZESETTING);
			
			READAWAYMSGDATA *awayData = new READAWAYMSGDATA;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)awayData);
			awayData->hContact = lParam;
			awayData->hAwayMsgEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, UM_RAM_AWAYMSGACK);
			awayData->hSeq = (HANDLE)CallContactService(awayData->hContact, PSS_GETAWAYMSG, 0, 0);
			WindowList_Add(g_hReadWndList, hwndDlg, awayData->hContact);

			TCHAR str[256], format[128];
			TCHAR *contactName = pcli->pfnGetContactDisplayName(awayData->hContact, 0);
			char *szProto = GetContactProto(awayData->hContact);
			TCHAR *status = pcli->pfnGetStatusModeDescription(db_get_w(awayData->hContact, szProto, "Status", ID_STATUS_OFFLINE), 0);
			GetWindowText(hwndDlg, format, _countof(format));
			mir_sntprintf(str, _countof(str), format, status, contactName);
			SetWindowText(hwndDlg, str);
			GetDlgItemText(hwndDlg, IDC_READAWAYMSG_RETRIEVE, format, _countof(format));
			mir_sntprintf(str, _countof(str), format, status);
			SetDlgItemText(hwndDlg, IDC_READAWAYMSG_RETRIEVE, str);
		}
		return true;

	case UM_RAM_AWAYMSGACK: // got away msg
		{
			ACKDATA *ack = (ACKDATA*)lParam;
			READAWAYMSGDATA *awayData = (READAWAYMSGDATA*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			// make sure everything is ok, and this is our ack
			if (ack->hContact != awayData->hContact || ack->type != ACKTYPE_AWAYMSG || ack->hProcess != awayData->hSeq || ack->result != ACKRESULT_SUCCESS)
				break;

			// done with the event
			if (awayData->hAwayMsgEvent) {
				UnhookEvent(awayData->hAwayMsgEvent);
				awayData->hAwayMsgEvent = NULL;
			}
			const TCHAR *ptszStatusMsg = (const TCHAR*)ack->lParam;
			SetDlgItemText(hwndDlg, IDC_READAWAYMSG_MSG, ptszStatusMsg);
			ShowWindow(GetDlgItem(hwndDlg, IDC_READAWAYMSG_RETRIEVE), SW_HIDE);
			ShowWindow(GetDlgItem(hwndDlg, IDC_READAWAYMSG_MSG), SW_SHOW);
			SetDlgItemText(hwndDlg, IDOK, TranslateT("&Close"));
			db_set_ts(awayData->hContact, "CList", "StatusMsg", ptszStatusMsg);
		}
		break;

	case WM_COMMAND:
		switch (HIWORD(wParam)) {
		case BN_CLICKED:
			switch (LOWORD(wParam)) {
			case IDCANCEL:
			case IDOK:
				DestroyWindow(hwndDlg);
				break;
			}
		}
		break;

	case WM_SIZE:
		Utils_ResizeDialog(hwndDlg, g_hInstance, MAKEINTRESOURCEA(IDD_READAWAYMSG), ReadAwayMsgDlgResize);
		break;

	case WM_CLOSE:
		DestroyWindow(hwndDlg);
		break;

	case WM_DESTROY:
		READAWAYMSGDATA *awayData = (READAWAYMSGDATA*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
		if (awayData->hAwayMsgEvent) {
			UnhookEvent(awayData->hAwayMsgEvent);
			awayData->hAwayMsgEvent = NULL;
		}
		delete awayData;
		Utils_SaveWindowPosition(hwndDlg, NULL, MOD_NAME, RAMDLGSIZESETTING);
		WindowList_Remove(g_hReadWndList, hwndDlg);
	}
	return false;
}
Esempio n. 6
0
INT_PTR CALLBACK DlgProcUrlSend(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct UrlSendData* dat = (struct UrlSendData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_URL);
		Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list"));
		Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details"));
		Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View user's history"));
		Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User menu"));

		SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_LIMITTEXT, 450, 0);
		dat = (struct UrlSendData*)mir_alloc(sizeof(struct UrlSendData));
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
		dat->hContact = lParam;
		dat->hAckEvent = NULL;
		dat->hSendId = NULL;
		dat->sendBuffer = NULL;

		WindowList_Add(hUrlWindowList, hwndDlg, dat->hContact);
		{
			TCHAR *str = pcli->pfnGetContactDisplayName(dat->hContact, 0);
			SetDlgItemText(hwndDlg, IDC_NAME, str);
		}

		GetOpenBrowserUrls(hwndDlg, GetDlgItem(hwndDlg, IDC_URLS));
		SendDlgItemMessage(hwndDlg, IDC_URLS, CB_SETCURSEL, 0, 0);
		if (SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETCOUNT, 0, 0))SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_URLS, CBN_SELCHANGE), 0);
		EnableWindow(GetDlgItem(hwndDlg, IDOK), (SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETCURSEL, 0, 0) == CB_ERR)?FALSE:TRUE);
		Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, "SRUrl", "send");
		mir_subclassWindow( GetDlgItem(hwndDlg, IDC_MESSAGE), SendEditSubclassProc);
		mir_subclassWindow( GetWindow(GetDlgItem(hwndDlg, IDC_URLS), GW_CHILD), SendEditSubclassProc);

		// From message dlg
		if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0))
			ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE);

		SendMessage(hwndDlg, DM_UPDATETITLE, 0, 0);
		// From message dlg end
		return TRUE;

	case WM_DDE_DATA:
	case WM_DDE_ACK:
		return DdeMessage(hwndDlg, msg, wParam, lParam);

	case WM_TIMER:
		if (wParam == 0) {
			//ICQ sendurl timed out
			KillTimer(hwndDlg, 0);
			MessageBox(hwndDlg, TranslateT("Send timed out"), _T(""), MB_OK);
			EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE);
			EnableWindow(GetDlgItem(hwndDlg, IDC_URLS), TRUE);
			SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETREADONLY, FALSE, 0);
		}
		break;

	case WM_MEASUREITEM:
		return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam);

	case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
			if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) {
				char *szProto = GetContactProto(dat->hContact);
				if (szProto) {
					HICON hIcon = (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL|PLIF_SMALL, 0);
					if (hIcon) {
						DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL);
						DestroyIcon(hIcon);
		}	}	}	}
		return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam);

	case DM_UPDATETITLE:
		sttUpdateTitle(hwndDlg, dat->hContact);
		break;

	case WM_COMMAND:
		if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact))
			break;

		switch (LOWORD(wParam)) {
		case IDOK:
			{
				char *body, *url;
				int bodySize, urlSize;

				urlSize = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_URLS))+1;
				url = (char*)mir_alloc(urlSize);
				GetDlgItemTextA(hwndDlg, IDC_URLS, url, urlSize);
				if (url[0] == 0) {
					mir_free(url);
					break;
				}
				bodySize = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE))+1;
				body = (char*)mir_alloc(bodySize);
				GetDlgItemTextA(hwndDlg, IDC_MESSAGE, body, bodySize);

				dat->sendBuffer = (char*)mir_realloc(dat->sendBuffer, lstrlenA(url)+lstrlenA(body)+2);
				lstrcpyA(dat->sendBuffer, url);
				lstrcpyA(dat->sendBuffer+lstrlenA(url)+1, body);
				dat->hAckEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_EVENTSENT);
				dat->hSendId = (HANDLE)CallContactService(dat->hContact, PSS_URL, 0, (LPARAM)dat->sendBuffer);
				mir_free(url);
				mir_free(body);

				//create a timeout timer
				SetTimer(hwndDlg, 0, TIMEOUT_URLSEND, NULL);
				EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_URLS), FALSE);
				SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETREADONLY, TRUE, 0);

				return TRUE;
			}

		case IDCANCEL:
			DestroyWindow(hwndDlg);
			return TRUE;

		case IDC_URLS:
			if (HIWORD(wParam) == CBN_SELCHANGE) {
				int i, urlSize;
				char *title;
				i = SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETCURSEL, 0, 0);
				title = (char*)SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETITEMDATA, (WPARAM)i, 0);
				SetDlgItemTextA(hwndDlg, IDC_MESSAGE, title);
				urlSize = SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETLBTEXTLEN, (WPARAM)i, 0);
				EnableWindow(GetDlgItem(hwndDlg, IDOK), (urlSize>0));
			}
			else if (HIWORD(wParam) == CBN_EDITCHANGE) {
				int urlSize = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_URLS));
				EnableWindow(GetDlgItem(hwndDlg, IDOK), (urlSize>0));
			}
			break;
		case IDC_USERMENU:
			{
				RECT rc;
				HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0);
				GetWindowRect(GetDlgItem(hwndDlg, IDC_USERMENU), &rc);
				TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL);
				DestroyMenu(hMenu);
			}
			break;

		case IDC_HISTORY:
			CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0);
			break;

		case IDC_DETAILS:
			CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0);
			break;

		case IDC_ADD:
			ADDCONTACTSTRUCT acs = {0};
			acs.hContact = dat->hContact;
			acs.handleType = HANDLE_CONTACT;
			acs.szProto = 0;
			CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs);

			if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0))
				ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE);
		}
		break;

	case HM_EVENTSENT:
		{
			ACKDATA *ack = (ACKDATA*)lParam;
			if (ack->hProcess != dat->hSendId) break;
			if (ack->hContact != dat->hContact) break;
			if (ack->type != ACKTYPE_URL || ack->result != ACKRESULT_SUCCESS) break;

			DBEVENTINFO dbei = { sizeof(dbei) };
			dbei.eventType = EVENTTYPE_URL;
			dbei.flags = DBEF_SENT;
			dbei.szModule = GetContactProto(dat->hContact);
			dbei.timestamp = time(NULL);
			dbei.cbBlob = (DWORD)(strlen(dat->sendBuffer)+strlen(dat->sendBuffer+strlen(dat->sendBuffer)+1)+2);
			dbei.pBlob = (PBYTE)dat->sendBuffer;
			db_event_add(dat->hContact, &dbei);
			KillTimer(hwndDlg, 0);
			DestroyWindow(hwndDlg);
		}
		break;

	case WM_DESTROY:
		Window_FreeIcon_IcoLib(hwndDlg);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU);

		WindowList_Remove(hUrlWindowList, hwndDlg);
		if (dat->hAckEvent) UnhookEvent(dat->hAckEvent);
		if (dat->sendBuffer != NULL) mir_free(dat->sendBuffer);
		mir_free(dat);
		Utils_SaveWindowPosition(hwndDlg, NULL, "SRUrl", "send");

		for (int i = SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETCOUNT, 0, 0)-1;i>=0;i--)
			mir_free((char*)SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETITEMDATA, i, 0));
		break;
	}

	return FALSE;
}
Esempio n. 7
0
static INT_PTR CALLBACK JabberSearchAdvancedDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	JabberSearchData* dat = (JabberSearchData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			dat = (JabberSearchData *)mir_calloc(sizeof(JabberSearchData));
			dat->ppro = (CJabberProto*)lParam;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);

			/* Server Combo box */
			ptrA jud(dat->ppro->getStringA("Jud"));
			char *szServerName = (jud == NULL) ? "users.jabber.org": jud;
			SetDlgItemTextA(hwndDlg,IDC_SERVER,szServerName);
			SendDlgItemMessageA(hwndDlg,IDC_SERVER,CB_ADDSTRING,0,(LPARAM)szServerName);
			//TO DO: Add Transports here
			int i, transpCount = dat->ppro->m_lstTransports.getCount();
			for (i=0; i < transpCount; i++) {
				TCHAR *szTransp = dat->ppro->m_lstTransports[i];
				if (szTransp)
					JabberSearchAddUrlToRecentCombo(hwndDlg, szTransp);
			}

			for (i=0; i < 10; i++) {
				char key[30];
				mir_snprintf(key, SIZEOF(key), "RecentlySearched_%d", i);
				ptrT szValue( dat->ppro->getTStringA(key));
				if (szValue != NULL)
					JabberSearchAddUrlToRecentCombo(hwndDlg, szValue);
			}

			//TO DO: Add 4 recently used
			dat->lastRequestIq = dat->ppro->SearchRenewFields(hwndDlg,dat);
		}
		return TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDC_SERVER) {
			switch (HIWORD(wParam)) {
			case CBN_SETFOCUS:
				PostMessage(GetParent(hwndDlg),WM_COMMAND, MAKEWPARAM(0,EN_SETFOCUS), (LPARAM)hwndDlg);
				return TRUE;

			case CBN_EDITCHANGE:
				EnableWindow(GetDlgItem(hwndDlg, IDC_GO),TRUE);
				return TRUE;

			case CBN_EDITUPDATE:
				JabberSearchFreeData(hwndDlg, dat);
				EnableWindow(GetDlgItem(hwndDlg, IDC_GO),TRUE);
				return TRUE;

			case CBN_SELENDOK:
				EnableWindow(GetDlgItem(hwndDlg, IDC_GO),TRUE);
				PostMessage(hwndDlg,WM_COMMAND,MAKEWPARAM(IDC_GO,BN_CLICKED),0);
				return TRUE;
			}
		}
		else if (LOWORD(wParam) == IDC_GO && HIWORD(wParam) == BN_CLICKED) {
			dat->ppro->SearchRenewFields(hwndDlg, dat);
			return TRUE;
		}
		break;

	case WM_SIZE:
		{
			//Resize IDC_FRAME to take full size
			RECT rcForm;
			GetWindowRect(hwndDlg,  &rcForm);
			RECT rcFrame;
			GetWindowRect(GetDlgItem(hwndDlg, IDC_FRAME), &rcFrame);
			rcFrame.bottom = rcForm.bottom;
			SetWindowPos(GetDlgItem(hwndDlg,IDC_FRAME),NULL,0,0,rcFrame.right-rcFrame.left,rcFrame.bottom-rcFrame.top,SWP_NOZORDER|SWP_NOMOVE);
			GetWindowRect(GetDlgItem(hwndDlg,IDC_VSCROLL), &rcForm);
			SetWindowPos(GetDlgItem(hwndDlg,IDC_VSCROLL),NULL,0,0,rcForm.right-rcForm.left,rcFrame.bottom-rcFrame.top,SWP_NOZORDER|SWP_NOMOVE);
			JabberSearchRefreshFrameScroll(hwndDlg, dat);
		}
		return TRUE;

	case WM_USER+11:
		{
			dat->fSearchRequestIsXForm=TRUE;
			dat->xNode = (HXML)wParam;
			JabberFormCreateUI(GetDlgItem(hwndDlg, IDC_FRAME), dat->xNode, &dat->CurrentHeight,TRUE);
			ShowWindow(GetDlgItem(hwndDlg, IDC_FRAME), SW_SHOW);
			dat->nJSInfCount=1;
			return TRUE;
		}
	case WM_USER+10:
		{
			Data* MyDat = (Data*)lParam;
			if (MyDat) {
				dat->fSearchRequestIsXForm = (BOOL)wParam;
				dat->CurrentHeight = JabberSearchAddField(hwndDlg,MyDat);
				mir_free(MyDat->Label);
				mir_free(MyDat->Var);
				mir_free(MyDat->defValue);
				free(MyDat);
			}
			else
			{
				JabberSearchRefreshFrameScroll(hwndDlg,dat);
				ScrollWindow(GetDlgItem(hwndDlg, IDC_FRAME), 0, dat->curPos - 0, NULL,  &(dat->frameRect));
				SetScrollPos(GetDlgItem(hwndDlg, IDC_VSCROLL), SB_CTL, 0, FALSE);
				dat->curPos=0;
			}
			return TRUE;
		}
	case WM_MOUSEWHEEL:
		{
			int zDelta = GET_WHEEL_DELTA_WPARAM(wParam);
			if (zDelta) {
				int nScrollLines=0;
				SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0,(void*)&nScrollLines,0);
				for (int i=0; i<(nScrollLines+1)/2; i++)
					SendMessage(hwndDlg,WM_VSCROLL, (zDelta<0)?SB_LINEDOWN:SB_LINEUP,0);
		}	}
		return TRUE;

	case WM_VSCROLL:
		{
			int pos;
			if (dat != NULL) {
				pos = dat->curPos;
				switch (LOWORD(wParam)) {
				case SB_LINEDOWN:
					pos += 10;
					break;
				case SB_LINEUP:
					pos -= 10;
					break;
				case SB_PAGEDOWN:
					pos += (dat->CurrentHeight - 10);
					break;
				case SB_PAGEUP:
					pos -= (dat->CurrentHeight - 10);
					break;
				case SB_THUMBTRACK:
					pos = HIWORD(wParam);
					break;
				}
				if (pos > (dat->CurrentHeight - dat->frameHeight))
					pos = dat->CurrentHeight - dat->frameHeight;
				if (pos < 0)
					pos = 0;
				if (dat->curPos != pos) {
					ScrollWindow(GetDlgItem(hwndDlg, IDC_FRAME), 0, dat->curPos - pos, NULL ,  &(dat->frameRect));
					SetScrollPos(GetDlgItem(hwndDlg, IDC_VSCROLL), SB_CTL, pos, TRUE);
					RECT Invalid=dat->frameRect;
					if (dat->curPos - pos >0)
						Invalid.bottom=Invalid.top+(dat->curPos - pos);
					else
						Invalid.top=Invalid.bottom+(dat->curPos - pos);

					RedrawWindow(GetDlgItem(hwndDlg, IDC_FRAME), NULL, NULL, RDW_UPDATENOW |RDW_ALLCHILDREN);
					dat->curPos = pos;
		}	}	}
		return TRUE;

	case WM_DESTROY:
		JabberSearchFreeData(hwndDlg, dat);
		JabberFormDestroyUI(GetDlgItem(hwndDlg, IDC_FRAME));
		mir_free(dat);
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
		return TRUE;
	}
	return FALSE;
}
Esempio n. 8
0
static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct DetailsData* dat = ( struct DetailsData* )GetWindowLongPtr( hwndDlg, GWLP_USERDATA );

	switch (msg) {
	case WM_INITDIALOG:
	{
		struct DlgProfData * prof = (struct DlgProfData *)lParam;
		PROPSHEETHEADER *psh = prof->psh;
		TranslateDialogDefault(hwndDlg);
		SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hMirandaInst, MAKEINTRESOURCE(IDI_USERDETAILS),IMAGE_ICON,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0));
		SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(hMirandaInst, MAKEINTRESOURCE(IDI_USERDETAILS),IMAGE_ICON,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0));
		dat = (struct DetailsData*)mir_alloc(sizeof(struct DetailsData));
		dat->prof = prof;
		prof->hwndOK = GetDlgItem( hwndDlg, IDOK );
		EnableWindow( prof->hwndOK, FALSE );
		SetWindowLongPtr( hwndDlg, GWLP_USERDATA, (LONG_PTR)dat );

		{
			TCHAR buf[512];
			mir_sntprintf(buf, SIZEOF(buf), _T("%s: %s\n%s"), TranslateT("Miranda Profiles from"), prof->pd->szProfileDir, 
				TranslateT("Select or create your Miranda IM user profile"));
			SetDlgItemText(hwndDlg, IDC_NAME, buf);
		}

		{	OPTIONSDIALOGPAGE *odp;
			int i;
			TCITEM tci;

			dat->currentPage = 0;
			dat->pageCount = psh->nPages;
			dat->opd = ( struct DetailsPageData* )mir_calloc( sizeof( struct DetailsPageData )*dat->pageCount );
			odp = ( OPTIONSDIALOGPAGE* )psh->ppsp;

			tci.mask = TCIF_TEXT;
			for( i=0; i < dat->pageCount; i++ ) {
				dat->opd[i].pTemplate = (DLGTEMPLATE *)LockResource(LoadResource(odp[i].hInstance,FindResourceA(odp[i].hInstance,odp[i].pszTemplate,MAKEINTRESOURCEA(5))));
				dat->opd[i].dlgProc = odp[i].pfnDlgProc;
				dat->opd[i].hInst = odp[i].hInstance;
				dat->opd[i].hwnd = NULL;
				dat->opd[i].changed = 0;
				tci.pszText = ( TCHAR* )odp[i].ptszTitle;
                if (dat->prof->pd->noProfiles || shouldAutoCreate(dat->prof->pd->szProfile))
					dat->currentPage = 1;
				TabCtrl_InsertItem( GetDlgItem(hwndDlg,IDC_TABS), i, &tci );
		}	}

		GetWindowRect(GetDlgItem(hwndDlg,IDC_TABS),&dat->rcDisplay);
		TabCtrl_AdjustRect(GetDlgItem(hwndDlg,IDC_TABS),FALSE,&dat->rcDisplay);
		{
			POINT pt = {0,0};
			ClientToScreen( hwndDlg, &pt );
			OffsetRect( &dat->rcDisplay, -pt.x, -pt.y );
		}

		TabCtrl_SetCurSel( GetDlgItem( hwndDlg, IDC_TABS ), dat->currentPage );
		dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst,dat->opd[dat->currentPage].pTemplate,hwndDlg,dat->opd[dat->currentPage].dlgProc,(LPARAM)dat->prof);
		ThemeDialogBackground( dat->opd[dat->currentPage].hwnd );
		SetWindowPos( dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE );
		{	PSHNOTIFY pshn;
			pshn.hdr.code = PSN_INFOCHANGED;
			pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd;
			pshn.hdr.idFrom = 0;
			pshn.lParam = ( LPARAM )0;
			SendMessage( dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn );
		}
		// service mode combobox
		{
			char **list = GetSeviceModePluginsList();
			if ( !list ) {
				ShowWindow( GetDlgItem(hwndDlg, IDC_SM_LABEL ), FALSE );
				ShowWindow( GetDlgItem(hwndDlg, IDC_SM_COMBO ), FALSE );
			} else {
				int i = 0;
				LRESULT index;
				HWND hwndCombo = GetDlgItem(hwndDlg, IDC_SM_COMBO );
				index = SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)_T("") );
				SendMessage( hwndCombo, CB_SETITEMDATA, index, (LPARAM)-1 );
				SendMessage( hwndCombo, CB_SETCURSEL, 0, 0);
				while ( list[i] ) {
					TCHAR *str = LangPackPcharToTchar( list[i] );
					index = SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)str );
					mir_free(str);
					SendMessage( hwndCombo, CB_SETITEMDATA, index, (LPARAM)i );
					i++;
				}
				mir_free(list);
			}
		}
		ShowWindow( dat->opd[dat->currentPage].hwnd, SW_SHOW );
		return TRUE;
	}
	case WM_CTLCOLORSTATIC:
		switch ( GetDlgCtrlID(( HWND )lParam )) {
		case IDC_WHITERECT:
			SetBkColor(( HDC )wParam, GetSysColor( COLOR_WINDOW ));
			return ( INT_PTR )GetSysColorBrush( COLOR_WINDOW );
		}
		break;

	case PSM_CHANGED:
		dat->opd[dat->currentPage].changed=1;
		return TRUE;

	case PSM_FORCECHANGED:
	{	PSHNOTIFY pshn;
		int i;

		pshn.hdr.code = PSN_INFOCHANGED;
		pshn.hdr.idFrom = 0;
		pshn.lParam = (LPARAM)0;
		for ( i=0; i < dat->pageCount; i++ ) {
			pshn.hdr.hwndFrom = dat->opd[i].hwnd;
			if ( dat->opd[i].hwnd != NULL )
				SendMessage(dat->opd[i].hwnd,WM_NOTIFY,0,(LPARAM)&pshn);
		}
		break;
	}
	case WM_NOTIFY:
		switch(wParam) {
		case IDC_TABS:
			switch(((LPNMHDR)lParam)->code) {
			case TCN_SELCHANGING:
			{	PSHNOTIFY pshn;
				if ( dat->currentPage == -1 || dat->opd[dat->currentPage].hwnd == NULL )
					break;
				pshn.hdr.code = PSN_KILLACTIVE;
				pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd;
				pshn.hdr.idFrom = 0;
				pshn.lParam = 0;
				if ( SendMessage( dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn )) {
					SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, TRUE );
					return TRUE;
				}
				break;
			}
			case TCN_SELCHANGE:
				if ( dat->currentPage != -1 && dat->opd[dat->currentPage].hwnd != NULL )
					ShowWindow( dat->opd[ dat->currentPage ].hwnd, SW_HIDE );

				dat->currentPage = TabCtrl_GetCurSel(GetDlgItem(hwndDlg,IDC_TABS));
				if ( dat->currentPage != -1 ) {
					if ( dat->opd[dat->currentPage].hwnd == NULL ) {
						PSHNOTIFY pshn;
						dat->opd[dat->currentPage].hwnd=CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst,dat->opd[dat->currentPage].pTemplate,hwndDlg,dat->opd[dat->currentPage].dlgProc,(LPARAM)dat->prof);
						ThemeDialogBackground(dat->opd[dat->currentPage].hwnd);
						SetWindowPos(dat->opd[dat->currentPage].hwnd,HWND_TOP,dat->rcDisplay.left,dat->rcDisplay.top,0,0,SWP_NOSIZE);
						pshn.hdr.code=PSN_INFOCHANGED;
						pshn.hdr.hwndFrom=dat->opd[dat->currentPage].hwnd;
						pshn.hdr.idFrom=0;
						pshn.lParam=(LPARAM)0;
						SendMessage(dat->opd[dat->currentPage].hwnd,WM_NOTIFY,0,(LPARAM)&pshn);
					}
					ShowWindow(dat->opd[dat->currentPage].hwnd,SW_SHOW);
				}
				break;
			}
			break;
		}
		break;

	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case IDCANCEL:
			{	int i;
				PSHNOTIFY pshn;
				pshn.hdr.idFrom=0;
				pshn.lParam=0;
				pshn.hdr.code=PSN_RESET;
				for(i=0;i<dat->pageCount;i++) {
					if (dat->opd[i].hwnd==NULL || !dat->opd[i].changed) continue;
					pshn.hdr.hwndFrom=dat->opd[i].hwnd;
					SendMessage(dat->opd[i].hwnd,WM_NOTIFY,0,(LPARAM)&pshn);
				}
				EndDialog(hwndDlg,0);
			}
			break;

		case IDC_REMOVE:
			if (!dat->prof->pd->noProfiles) {
				HWND hwndList = GetDlgItem(dat->opd[0].hwnd, IDC_PROFILELIST);
				DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat->prof);
			}
			break;

		case IDOK:
			{
				int i;
				PSHNOTIFY pshn;
				pshn.hdr.idFrom=0;
				pshn.lParam=(LPARAM)0;
				if ( dat->currentPage != -1 ) {
					pshn.hdr.code = PSN_KILLACTIVE;
					pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd;
					if ( SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn ))
						break;
				}

				pshn.hdr.code=PSN_APPLY;
				for ( i=0; i < dat->pageCount; i++ ) {
					if ( dat->opd[i].hwnd == NULL || !dat->opd[i].changed )
						continue;

					pshn.hdr.hwndFrom = dat->opd[i].hwnd;
					SendMessage( dat->opd[i].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn );
					if ( GetWindowLongPtr( dat->opd[i].hwnd, DWLP_MSGRESULT ) == PSNRET_INVALID_NOCHANGEPAGE) {
						TabCtrl_SetCurSel( GetDlgItem( hwndDlg, IDC_TABS ), i );
						if ( dat->currentPage != -1 )
							ShowWindow( dat->opd[ dat->currentPage ].hwnd, SW_HIDE );
						dat->currentPage = i;
						ShowWindow( dat->opd[dat->currentPage].hwnd, SW_SHOW );
						return 0;
				}	}
				EndDialog(hwndDlg,1);
				break;
		}	}
		break;

	case WM_DESTROY:
		{
			LRESULT curSel = SendDlgItemMessage(hwndDlg,IDC_SM_COMBO,CB_GETCURSEL,0,0);
			if ( curSel != CB_ERR ) {
				int idx = SendDlgItemMessage( hwndDlg, IDC_SM_COMBO, CB_GETITEMDATA, ( WPARAM )curSel, 0 );
				SetServiceModePlugin(idx);
			}
		}
		DestroyIcon(( HICON )SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
		DestroyIcon(( HICON )SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
		DeleteObject( dat->hBoldFont );
		{	int i;
			for ( i=0; i < dat->pageCount; i++ )
				if ( dat->opd[i].hwnd != NULL )
					DestroyWindow( dat->opd[i].hwnd );
		}
		mir_free( dat->opd );
		mir_free( dat );
		break;
	}
	return FALSE;
}
static BOOL CALLBACK TlenUserInfoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		// lParam is hContact
		TranslateDialogDefault(hwndDlg);
		SetWindowLong(hwndDlg, GWL_USERDATA, (LONG)(HANDLE) lParam);

		InitComboBox(GetDlgItem(hwndDlg, IDC_GENDER), tlenFieldGender);
		InitComboBox(GetDlgItem(hwndDlg, IDC_OCCUPATION), tlenFieldOccupation);
		InitComboBox(GetDlgItem(hwndDlg, IDC_LOOKFOR), tlenFieldLookfor);

		SendMessage(hwndDlg, WM_JABBER_REFRESH, 0, 0);
		return TRUE;
	case WM_JABBER_REFRESH:
		{
			DBVARIANT dbv;
			HANDLE hContact;
			char *jid;
			int i;
			JABBER_LIST_ITEM *item;

			JabberLog("refresh");

			SetDlgItemText(hwndDlg, IDC_INFO_JID, "");
			SetDlgItemText(hwndDlg, IDC_SUBSCRIPTION, "");
			SetFocus(GetDlgItem(hwndDlg, IDC_STATIC));
			
			hContact = (HANDLE) GetWindowLong(hwndDlg, GWL_USERDATA);
			if (!DBGetContactSetting(hContact, jabberProtoName, "FirstName", &dbv)) {
				SetDlgItemText(hwndDlg, IDC_FIRSTNAME, dbv.pszVal);
				DBFreeVariant(&dbv);
			} else SetDlgItemText(hwndDlg, IDC_FIRSTNAME, "");
			if (!DBGetContactSetting(hContact, jabberProtoName, "LastName", &dbv)) {
				SetDlgItemText(hwndDlg, IDC_LASTNAME, dbv.pszVal);
				DBFreeVariant(&dbv);
			} else SetDlgItemText(hwndDlg, IDC_LASTNAME, "");
			if (!DBGetContactSetting(hContact, jabberProtoName, "Nick", &dbv)) {
				SetDlgItemText(hwndDlg, IDC_NICKNAME, dbv.pszVal);
				DBFreeVariant(&dbv);
			} else SetDlgItemText(hwndDlg, IDC_NICKNAME, "");
			if (!DBGetContactSetting(hContact, jabberProtoName, "e-mail", &dbv)) {
				SetDlgItemText(hwndDlg, IDC_EMAIL, dbv.pszVal);
				DBFreeVariant(&dbv);
			} else SetDlgItemText(hwndDlg, IDC_EMAIL, "");
			if (!DBGetContactSetting(hContact, jabberProtoName, "Age", &dbv)) {
				SetDlgItemInt(hwndDlg, IDC_AGE, dbv.wVal, FALSE);
				DBFreeVariant(&dbv);
			} else SetDlgItemText(hwndDlg, IDC_AGE, "");
			if (!DBGetContactSetting(hContact, jabberProtoName, "City", &dbv)) {
				SetDlgItemText(hwndDlg, IDC_CITY, dbv.pszVal);
				DBFreeVariant(&dbv);
			} else SetDlgItemText(hwndDlg, IDC_CITY, "");
			if (!DBGetContactSetting(hContact, jabberProtoName, "School", &dbv)) {
				SetDlgItemText(hwndDlg, IDC_SCHOOL, dbv.pszVal);
				DBFreeVariant(&dbv);
			} else SetDlgItemText(hwndDlg, IDC_SCHOOL, "");
			switch (DBGetContactSettingByte(hContact, jabberProtoName, "Gender", '?')) {
				case 'M':
					SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 1, 0);
					SetDlgItemText(hwndDlg, IDC_GENDER_TEXT, Translate(tlenFieldGender[0].name));
					break;
				case 'F':
					SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 2, 0);
					SetDlgItemText(hwndDlg, IDC_GENDER_TEXT, Translate(tlenFieldGender[1].name));
					break;
				default:
					SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 0, 0);
					SetDlgItemText(hwndDlg, IDC_GENDER_TEXT, "");
					break;
			} 
			i = DBGetContactSettingWord(hContact, jabberProtoName, "Occupation", 0);
			if (i>0 && i<13) {
				SetDlgItemText(hwndDlg, IDC_OCCUPATION_TEXT, Translate(tlenFieldOccupation[i-1].name));
				SendDlgItemMessage(hwndDlg, IDC_OCCUPATION, CB_SETCURSEL, i, 0);
			} else {
				SetDlgItemText(hwndDlg, IDC_OCCUPATION_TEXT, "");
				SendDlgItemMessage(hwndDlg, IDC_OCCUPATION, CB_SETCURSEL, 0, 0);
			}
			i = DBGetContactSettingWord(hContact, jabberProtoName, "LookingFor", 0);
			if (i>0 && i<6) {
				SetDlgItemText(hwndDlg, IDC_LOOKFOR_TEXT, Translate(tlenFieldLookfor[i-1].name));
				SendDlgItemMessage(hwndDlg, IDC_LOOKFOR, CB_SETCURSEL, i, 0);
			} else {
				SetDlgItemText(hwndDlg, IDC_LOOKFOR_TEXT, "");
				SendDlgItemMessage(hwndDlg, IDC_LOOKFOR, CB_SETCURSEL, 0, 0);
			}
			i = DBGetContactSettingWord(hContact, jabberProtoName, "VoiceChat", 0);
			CheckDlgButton(hwndDlg, IDC_VOICECONVERSATIONS, i);
			if (!DBGetContactSetting(hContact, jabberProtoName, "jid", &dbv)) {
				jid = JabberTextDecode(dbv.pszVal);
				SetDlgItemText(hwndDlg, IDC_INFO_JID, jid);
				free(jid);
				jid = dbv.pszVal;
				if (jabberOnline) {
					if ((item=JabberListGetItemPtr(LIST_ROSTER, jid)) != NULL) {
						switch (item->subscription) {
						case SUB_BOTH:
							SetDlgItemText(hwndDlg, IDC_SUBSCRIPTION, Translate("both"));
							break;
						case SUB_TO:
							SetDlgItemText(hwndDlg, IDC_SUBSCRIPTION, Translate("to"));
							break;
						case SUB_FROM:
							SetDlgItemText(hwndDlg, IDC_SUBSCRIPTION, Translate("from"));
							break;
						default:
							SetDlgItemText(hwndDlg, IDC_SUBSCRIPTION, Translate("none"));
							break;
						}
					}
					else {
						SetDlgItemText(hwndDlg, IDC_SUBSCRIPTION, Translate("not on roster"));
					}
				}
				DBFreeVariant(&dbv);
			}
		}
		break;
	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_INFOCHANGED:
				{
					HANDLE hContact = (HANDLE) ((LPPSHNOTIFY) lParam)->lParam;
					SendMessage(hwndDlg, WM_JABBER_REFRESH, 0, (LPARAM) hContact);
				}
				break;
			}
			break;
		}
		break;
	case WM_COMMAND:
		if (LOWORD(wParam)==IDC_SAVE && HIWORD(wParam)==BN_CLICKED) {
			char *str = NULL;
			int strSize;
			CCSDATA ccs = {0};
			JabberStringAppend(&str, &strSize, "<iq type='set' id='"JABBER_IQID"%d' to='tuba'><query xmlns='jabber:iq:register'>", JabberSerialNext());
			FetchField(hwndDlg, IDC_FIRSTNAME, "first", &str, &strSize);
			FetchField(hwndDlg, IDC_LASTNAME, "last", &str, &strSize);
			FetchField(hwndDlg, IDC_NICKNAME, "nick", &str, &strSize);
			FetchField(hwndDlg, IDC_EMAIL, "email", &str, &strSize);
			FetchCombo(hwndDlg, IDC_GENDER, "s", &str, &strSize);
			FetchField(hwndDlg, IDC_AGE, "b", &str, &strSize);
			FetchField(hwndDlg, IDC_CITY, "c", &str, &strSize);
			FetchCombo(hwndDlg, IDC_OCCUPATION, "j", &str, &strSize);
			FetchField(hwndDlg, IDC_SCHOOL, "e", &str, &strSize);
			FetchCombo(hwndDlg, IDC_LOOKFOR, "r", &str, &strSize);
			JabberStringAppend(&str, &strSize, "<g>%d</g>", IsDlgButtonChecked(hwndDlg, IDC_VOICECONVERSATIONS) ? 1 : 0);
			JabberStringAppend(&str, &strSize, "</query></iq>");
			JabberLog(str);
			JabberSend(jabberThreadInfo->s, "%s", str);
			free(str);
			JabberGetInfo(0, (LPARAM) &ccs);
		}
		break;
	}
	return FALSE;
}
Esempio n. 10
0
static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct DlgProfData * dat = (struct DlgProfData *)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault( hwndDlg );
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
		dat = (struct DlgProfData *)lParam;
		{
			// fill in the db plugins present
			PLUGIN_DB_ENUM dbe;
			dbe.cbSize = sizeof(dbe);
			dbe.pfnEnumCallback = (int(*)(const char*,void*,LPARAM))FindDbProviders;
			dbe.lParam = (LPARAM)hwndDlg;
			if ( CallService( MS_PLUGINS_ENUMDBPLUGINS, 0, ( LPARAM )&dbe ) == -1 ) {
				// no plugins?!
				EnableWindow( GetDlgItem(hwndDlg, IDC_PROFILEDRIVERS ), FALSE );
				EnableWindow( GetDlgItem(hwndDlg, IDC_PROFILENAME ), FALSE );
				ShowWindow( GetDlgItem(hwndDlg, IDC_NODBDRIVERS ), TRUE );
			}
			// default item
			SendDlgItemMessage(hwndDlg, IDC_PROFILEDRIVERS, CB_SETCURSEL, 0, 0);
		}
		// subclass the profile name box
		{
			HWND hwndProfile = GetDlgItem(hwndDlg, IDC_PROFILENAME);
			WNDPROC proc = (WNDPROC)GetWindowLongPtr(hwndProfile, GWLP_WNDPROC);
			SetWindowLongPtr(hwndProfile,GWLP_USERDATA,(LONG_PTR)proc);
			SetWindowLongPtr(hwndProfile,GWLP_WNDPROC,(LONG_PTR)ProfileNameValidate);
		}

		// decide if there is a default profile name given in the INI and if it should be used
		if (dat->pd->noProfiles || (shouldAutoCreate(dat->pd->szProfile) && _taccess(dat->pd->szProfile, 0))) 
        {
			TCHAR* profile = _tcsrchr(dat->pd->szProfile, '\\');
			if (profile) ++profile;
			else profile = dat->pd->szProfile;

			TCHAR *p = _tcsrchr(profile, '.');
			TCHAR c = 0;
			if (p) { c = *p; *p = 0; } 

			SetDlgItemText(hwndDlg, IDC_PROFILENAME, profile);
			if (c) *p = c;
		}

		// focus on the textbox
		PostMessage( hwndDlg, WM_FOCUSTEXTBOX, 0, 0 );
		return TRUE;

	case WM_FOCUSTEXTBOX:
		SetFocus( GetDlgItem( hwndDlg, IDC_PROFILENAME ));
		break;

	case WM_INPUTCHANGED: // when input in the edit box changes
		SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
		EnableWindow( dat->hwndOK, GetWindowTextLength( GetDlgItem( hwndDlg, IDC_PROFILENAME )) > 0 );
		break;

	case WM_SHOWWINDOW:
		if ( wParam ) {
			SetWindowText( dat->hwndOK, TranslateT("&Create"));
			SendMessage( hwndDlg, WM_INPUTCHANGED, 0, 0 );
		}
		break;

	case WM_NOTIFY:
		{
			NMHDR* hdr = ( NMHDR* )lParam;
			if ( hdr && hdr->code == PSN_APPLY && dat && IsWindowVisible( hwndDlg )) {
				TCHAR szName[MAX_PATH];
				LRESULT curSel = SendDlgItemMessage(hwndDlg,IDC_PROFILEDRIVERS,CB_GETCURSEL,0,0);
				if ( curSel == CB_ERR ) break; // should never happen
				GetDlgItemText(hwndDlg, IDC_PROFILENAME, szName, SIZEOF( szName ));
				if ( szName[0] == 0 )
					break;

				// profile placed in "profile_name" subfolder
				mir_sntprintf( dat->pd->szProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, szName, szName );
				dat->pd->newProfile = 1;
				dat->pd->dblink = (DATABASELINK *)SendDlgItemMessage( hwndDlg, IDC_PROFILEDRIVERS, CB_GETITEMDATA, ( WPARAM )curSel, 0 );

				if ( makeDatabase( dat->pd->szProfile, dat->pd->dblink, hwndDlg ) == 0 ) {
					SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE );
		}	}	}
		break;
	}

	return FALSE;
}
Esempio n. 11
0
static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	DlgProfData* dat = (struct DlgProfData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	HWND hwndList = GetDlgItem(hwndDlg, IDC_PROFILELIST);

	switch (msg) {
	case WM_INITDIALOG:
		{
			HIMAGELIST hImgList;
			LVCOLUMN col;

			TranslateDialogDefault( hwndDlg );

			dat = (DlgProfData*) lParam;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);

			// set columns
			col.mask = LVCF_TEXT | LVCF_WIDTH;
			col.pszText = TranslateT("Profile");
			col.cx=122;
			ListView_InsertColumn( hwndList, 0, &col );

			col.pszText = TranslateT("Driver");
			col.cx=100;
			ListView_InsertColumn( hwndList, 1, &col );

			col.pszText = TranslateT("Size");
			col.cx=60;
			ListView_InsertColumn( hwndList, 2, &col );

			col.pszText = TranslateT("Created");
			col.cx=145;
			ListView_InsertColumn( hwndList, 3, &col );

			col.pszText = TranslateT("Modified");
			col.cx=145;
			ListView_InsertColumn( hwndList, 4, &col );

			// icons
			hImgList = ImageList_Create(16, 16, ILC_MASK | (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16), 2, 1);
			ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_USERDETAILS));
			ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_DELETE));

			// LV will destroy the image list
			SetWindowLongPtr(hwndList, GWL_STYLE, GetWindowLongPtr(hwndList, GWL_STYLE) | LVS_SORTASCENDING);
			ListView_SetImageList(hwndList, hImgList, LVSIL_SMALL);
			ListView_SetExtendedListViewStyle(hwndList,
				ListView_GetExtendedListViewStyle(hwndList) | LVS_EX_DOUBLEBUFFER | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT);

			// find all the profiles
			ProfileEnumData ped = { hwndDlg, dat->pd->szProfile };
			findProfiles(dat->pd->szProfileDir, EnumProfilesForList, (LPARAM)&ped);
			PostMessage(hwndDlg, WM_FOCUSTEXTBOX, 0, 0);

			dat->hFileNotify = FindFirstChangeNotification(dat->pd->szProfileDir, TRUE, 
				FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE);
			if (dat->hFileNotify != INVALID_HANDLE_VALUE) 
				SetTimer(hwndDlg, 0, 1200, NULL);
			return TRUE;
		}

	case WM_DESTROY:
		KillTimer(hwndDlg, 0);
		FindCloseChangeNotification(dat->hFileNotify);
		break;

	case WM_TIMER:
		if (WaitForSingleObject(dat->hFileNotify, 0) == WAIT_OBJECT_0)
		{
			ListView_DeleteAllItems(hwndList);
            ProfileEnumData ped = { hwndDlg, dat->pd->szProfile };
			findProfiles(dat->pd->szProfileDir, EnumProfilesForList, (LPARAM)&ped);
			FindNextChangeNotification(dat->hFileNotify);
		}
		break;

	case WM_FOCUSTEXTBOX:
		SetFocus(hwndList);
        if (dat->pd->szProfile[0] == 0 || ListView_GetSelectedCount(hwndList) == 0)
			ListView_SetItemState(hwndList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
		break;

	case WM_SHOWWINDOW:
		if ( wParam ) 
		{
			SetWindowText(dat->hwndOK, TranslateT("&Run"));
			EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList)==1);
		}
		break;

	case WM_CONTEXTMENU:
		{
			LVHITTESTINFO lvht = {0};
			lvht.pt.x  = GET_X_LPARAM(lParam); 
			lvht.pt.y  = GET_Y_LPARAM(lParam); 
			ScreenToClient(hwndList, &lvht.pt);
			if (ListView_HitTest(hwndList, &lvht) < 0) break;

			lvht.pt.x  = GET_X_LPARAM(lParam); 
			lvht.pt.y  = GET_Y_LPARAM(lParam); 

			HMENU hMenu = CreatePopupMenu();
			AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run"));
			AppendMenu(hMenu, MF_SEPARATOR, 2, NULL);
			AppendMenu(hMenu, MF_STRING, 3, TranslateT("Delete"));
			int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, hwndDlg, NULL);
			switch (index) {
			case 1:
				SendMessage(GetParent(hwndDlg), WM_COMMAND, IDOK, 0);
				break;

			case 3:
				DeleteProfile(hwndList, lvht.iItem, dat);
				break;
			}
			DestroyMenu(hMenu);
			break;
		}


	case WM_NOTIFY:
		{
			LPNMHDR hdr = (LPNMHDR) lParam;
			if (hdr && hdr->code == PSN_INFOCHANGED)
				break;

			if (hdr && hdr->idFrom == IDC_PROFILELIST)
			{
				switch (hdr->code) 
				{
					case LVN_ITEMCHANGED:
						EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1);

					case NM_DBLCLK:
					{
						LVITEM item = {0};
						TCHAR profile[MAX_PATH];

						if (dat == NULL) break;

						item.mask = LVIF_TEXT;
						item.iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL);
						item.pszText = profile;
						item.cchTextMax = SIZEOF(profile);

						if (ListView_GetItem(hwndList, &item)) {
							// profile is placed in "profile_name" subfolder
							TCHAR tmpPath[MAX_PATH];
							mir_sntprintf(tmpPath, SIZEOF(tmpPath), _T("%s\\%s.dat"), dat->pd->szProfileDir, profile);
							HANDLE hFile = CreateFile(tmpPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
							if (hFile == INVALID_HANDLE_VALUE)
								mir_sntprintf(dat->pd->szProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, profile, profile);
							else
								_tcscpy(dat->pd->szProfile, tmpPath);
							CloseHandle(hFile);
							if (hdr->code == NM_DBLCLK) EndDialog(GetParent(hwndDlg), 1);
						}
						return TRUE;
					}	

					case LVN_KEYDOWN:
					{
						LPNMLVKEYDOWN hdrk = (LPNMLVKEYDOWN) lParam;
						if (hdrk->wVKey == VK_DELETE) 
							DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat);
						break;
					}
				}	
			}
			break;
	}	}

	return FALSE;
}
Esempio n. 12
0
INT_PTR CALLBACK MraPopupDlgProcOpts(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	CMraProto *ppro = (CMraProto*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hWndDlg);
		SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
		ppro = (CMraProto*)lParam;
		{
			HWND hWndCombo = GetDlgItem(hWndDlg, IDC_COMBO_POPUP_TYPE);
			SendMessage(hWndCombo, CB_RESETCONTENT, 0, 0);

			for (size_t i = 0; i < POPUPS_TYPES_COUNT; i++) {
				DWORD dwItem = SendMessage(hWndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(lpcwszPopupsTypes[i]));
				SendMessage(hWndCombo, CB_SETITEMDATA, dwItem, i);
			}
			SendMessage(hWndCombo, CB_SETCURSEL, 0, 0);
			SendMessage(hWndDlg, WM_COMMAND, MAKELONG(IDC_COMBO_POPUP_TYPE, CBN_SELCHANGE), 0);
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_COMBO_POPUP_TYPE:
			if (HIWORD(wParam) == CBN_SELCHANGE) {
				BOOL bEnabled, bUseWinColors;
				char szBuff[MAX_PATH];
				DWORD dwType = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_COMBO_POPUP_TYPE);

				bEnabled = GetBit(ppro->getDword("PopupsEventFilter", MRA_DEFAULT_POPUPS_EVENT_FILTER), dwType);
				CheckDlgButton(hWndDlg, IDC_CHK_ENABLE, bEnabled);

				mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%SUseWinColors", lpcwszPopupsTypes[dwType]);
				bUseWinColors = ppro->getByte(szBuff, MRA_DEFAULT_POPUP_USE_WIN_COLORS);
				CheckDlgButton(hWndDlg, IDC_CHK_USE_WIN_COLORS, bUseWinColors);
				EnableWindow(GetDlgItem(hWndDlg, IDC_CHK_USE_WIN_COLORS), bEnabled);

				mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%SColorBack", lpcwszPopupsTypes[dwType]);
				SendDlgItemMessage(hWndDlg, IDC_POPUP_BACKCOLOR, CPM_SETCOLOUR, 0, ppro->getDword(szBuff, MRA_DEFAULT_POPUP_COLOR_BACK));
				EnableWindow(GetDlgItem(hWndDlg, IDC_POPUP_BACKCOLOR), (bEnabled && bUseWinColors == FALSE));

				mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%SColorText", lpcwszPopupsTypes[dwType]);
				SendDlgItemMessage(hWndDlg, IDC_POPUP_TEXTCOLOR, CPM_SETCOLOUR, 0, ppro->getDword(szBuff, MRA_DEFAULT_POPUP_COLOR_TEXT));
				EnableWindow(GetDlgItem(hWndDlg, IDC_POPUP_TEXTCOLOR), (bEnabled && bUseWinColors == FALSE));

				mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%STimeout", lpcwszPopupsTypes[dwType]);
				SetDlgItemInt(hWndDlg, IDC_POPUP_TIMEOUT, ppro->getDword(szBuff, MRA_DEFAULT_POPUP_TIMEOUT), FALSE);
				EnableWindow(GetDlgItem(hWndDlg, IDC_POPUP_TIMEOUT), bEnabled);
			}
			break;

		case IDC_PREVIEW:
			{
				for (size_t i = 0; i < POPUPS_TYPES_COUNT; i++) {
					ppro->MraPopupShowFromAgentW(i, 0, TranslateTS(lpcwszPopupsTypes[i]));
				}
			}
			break;

		case IDC_CHK_ENABLE:
		case IDC_CHK_USE_WIN_COLORS:
			{
				BOOL bEnabled = IsDlgButtonChecked(hWndDlg, IDC_CHK_ENABLE);
				BOOL bUseWinColors = IsDlgButtonChecked(hWndDlg, IDC_CHK_USE_WIN_COLORS);

				EnableWindow(GetDlgItem(hWndDlg, IDC_CHK_USE_WIN_COLORS), bEnabled);
				EnableWindow(GetDlgItem(hWndDlg, IDC_POPUP_BACKCOLOR), (bEnabled && bUseWinColors == FALSE));
				EnableWindow(GetDlgItem(hWndDlg, IDC_POPUP_TEXTCOLOR), (bEnabled && bUseWinColors == FALSE));
				EnableWindow(GetDlgItem(hWndDlg, IDC_POPUP_TIMEOUT), bEnabled);
			}
		default:
			if ((LOWORD(wParam) == IDC_POPUP_TIMEOUT) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
				return FALSE;
			SendMessage(GetParent(hWndDlg), PSM_CHANGED, 0, 0);
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			{
				char szBuff[MAX_PATH];
				DWORD dwType = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_COMBO_POPUP_TYPE);
				DWORD dwPopupsEventFilter = ppro->getDword("PopupsEventFilter", MRA_DEFAULT_POPUPS_EVENT_FILTER);
				if (IsDlgButtonChecked(hWndDlg, IDC_CHK_ENABLE))
					dwPopupsEventFilter |= (1<<dwType);
				else
					dwPopupsEventFilter &= ~(1<<dwType);

				ppro->setDword("PopupsEventFilter", dwPopupsEventFilter);

				mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%SUseWinColors", lpcwszPopupsTypes[dwType]);
				ppro->setByte(szBuff, IsDlgButtonChecked(hWndDlg, IDC_CHK_USE_WIN_COLORS));

				mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%SColorBack", lpcwszPopupsTypes[dwType]);
				ppro->setDword(szBuff, SendDlgItemMessage(hWndDlg, IDC_POPUP_BACKCOLOR, CPM_GETCOLOUR, 0, 0));

				mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%SColorText", lpcwszPopupsTypes[dwType]);
				ppro->setDword(szBuff, SendDlgItemMessage(hWndDlg, IDC_POPUP_TEXTCOLOR, CPM_GETCOLOUR, 0, 0));

				mir_snprintf(szBuff, SIZEOF(szBuff), "PopupType%STimeout", lpcwszPopupsTypes[dwType]);
				ppro->setDword(szBuff, GetDlgItemInt(hWndDlg, IDC_POPUP_TIMEOUT, NULL, FALSE));
			}
			return TRUE;
		}
		break;
	}
	return FALSE;
}
Esempio n. 13
0
// dialog procedure for handling the contact ignore dialog (available from the contact menu
static INT_PTR CALLBACK IgnoreDialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hWnd, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		{
			DWORD dwMask;
			ClcContact *contact = NULL;
			int pCaps;
			HWND hwndAdd;

			hContact = lParam;
			SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)hContact);
			dwMask = cfg::getDword(hContact, "Ignore", "Mask1", 0);
			SendMessage(hWnd, WM_USER + 100, hContact, dwMask);
			SendMessage(hWnd, WM_USER + 120, 0, 0);
			TranslateDialogDefault(hWnd);
			hwndAdd = GetDlgItem(hWnd, IDC_IGN_ADDPERMANENTLY); // CreateWindowEx(0, _T("CLCButtonClass"), _T("FOO"), WS_VISIBLE | BS_PUSHBUTTON | WS_CHILD | WS_TABSTOP, 200, 276, 106, 24, hWnd, (HMENU)IDC_IGN_ADDPERMANENTLY, g_hInst, NULL);
			CustomizeButton(hwndAdd, false, true, false);

			SendMessage(hwndAdd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadSkinnedIcon(SKINICON_OTHER_ADDCONTACT));
			SetWindowText(hwndAdd, TranslateT("Add permanently"));
			EnableWindow(hwndAdd, cfg::getByte(hContact, "CList", "NotOnList", 0));

			hwndAdd = GetDlgItem(hWnd, IDC_DSP_LOADDEFAULT); // CreateWindowEx(0, _T("CLCButtonClass"), _T("FOO"), WS_VISIBLE | BS_PUSHBUTTON | WS_CHILD | WS_TABSTOP, 200, 276, 106, 24, hWnd, (HMENU)IDC_IGN_ADDPERMANENTLY, g_hInst, NULL);
			CustomizeButton(hwndAdd, false, true, false);

			SendMessage(hwndAdd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadSkinnedIcon(SKINICON_OTHER_DELETE));
			SetWindowText(hwndAdd, TranslateT("Revert to default"));
			EnableWindow(hwndAdd, TRUE);

			SendDlgItemMessage(hWnd, IDC_AVATARDISPMODE, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Default (global setting)"));
			SendDlgItemMessage(hWnd, IDC_AVATARDISPMODE, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Show always when available"));
			SendDlgItemMessage(hWnd, IDC_AVATARDISPMODE, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Hide always"));

			SendDlgItemMessage(hWnd, IDC_SECONDLINEMODE, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Default (global setting)"));
			SendDlgItemMessage(hWnd, IDC_SECONDLINEMODE, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Never"));
			SendDlgItemMessage(hWnd, IDC_SECONDLINEMODE, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Always"));
			SendDlgItemMessage(hWnd, IDC_SECONDLINEMODE, CB_INSERTSTRING, -1, (LPARAM)TranslateT("When space is available"));
			SendDlgItemMessage(hWnd, IDC_SECONDLINEMODE, CB_INSERTSTRING, -1, (LPARAM)TranslateT("When needed by status message"));

			if (cfg::clcdat) {
				FindItem(pcli->hwndContactTree, cfg::clcdat, (HANDLE)hContact, &contact, NULL, NULL);
				if (contact && contact->type != CLCIT_CONTACT) {
					DestroyWindow(hWnd);
					return FALSE;
				}
				else {
					TCHAR szTitle[512];
					DWORD dwFlags = cfg::getDword(hContact, "CList", "CLN_Flags", 0);
					BYTE bSecondLine = cfg::getByte(hContact, "CList", "CLN_2ndline", -1);
					DWORD dwXMask = cfg::getDword(hContact, "CList", "CLN_xmask", 0);
					int i = 0;

					mir_sntprintf(szTitle, 512, TranslateT("Contact list display and ignore options for %s"), contact ? contact->szText : (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR));

					SetWindowText(hWnd, szTitle);
					SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadSkinnedIcon(SKINICON_OTHER_MIRANDA));
					pCaps = CallProtoService(contact ? contact->proto : GetContactProto(hContact), PS_GETCAPS, PFLAGNUM_1, 0);
					Utils::enableDlgControl(hWnd, IDC_IGN_ALWAYSONLINE, pCaps & PF1_INVISLIST ? TRUE : FALSE);
					Utils::enableDlgControl(hWnd, IDC_IGN_ALWAYSOFFLINE, pCaps & PF1_VISLIST ? TRUE : FALSE);
					CheckDlgButton(hWnd, IDC_IGN_PRIORITY, cfg::getByte(hContact, "CList", "Priority", 0) ? 1 : 0);
					Utils::enableDlgControl(hWnd, IDC_IGN_PRIORITY, TRUE);
					Utils::enableDlgControl(hWnd, IDC_AVATARDISPMODE, TRUE);
					Utils::enableDlgControl(hWnd, IDC_SECONDLINEMODE, TRUE);
					if (dwFlags & ECF_FORCEAVATAR)
						SendDlgItemMessage(hWnd, IDC_AVATARDISPMODE, CB_SETCURSEL, 1, 0);
					else if (dwFlags & ECF_HIDEAVATAR)
						SendDlgItemMessage(hWnd, IDC_AVATARDISPMODE, CB_SETCURSEL, 2, 0);
					else
						SendDlgItemMessage(hWnd, IDC_AVATARDISPMODE, CB_SETCURSEL, 0, 0);

					if (dwFlags & ECF_FORCEOVERLAY)
						SendDlgItemMessage(hWnd, IDC_OVERLAYICON, BM_SETCHECK, BST_CHECKED, 0);
					else if (dwFlags & ECF_HIDEOVERLAY)
						SendDlgItemMessage(hWnd, IDC_OVERLAYICON, BM_SETCHECK, BST_UNCHECKED, 0);
					else
						SendDlgItemMessage(hWnd, IDC_OVERLAYICON, BM_SETCHECK, BST_INDETERMINATE, 0);

					if (dwFlags & ECF_FORCELOCALTIME)
						SendDlgItemMessage(hWnd, IDC_SHOWLOCALTIME1, BM_SETCHECK, BST_CHECKED, 0);
					else if (dwFlags & ECF_HIDELOCALTIME)
						SendDlgItemMessage(hWnd, IDC_SHOWLOCALTIME1, BM_SETCHECK, BST_UNCHECKED, 0);
					else
						SendDlgItemMessage(hWnd, IDC_SHOWLOCALTIME1, BM_SETCHECK, BST_INDETERMINATE, 0);

					if (bSecondLine == 0xff)
						SendDlgItemMessage(hWnd, IDC_SECONDLINEMODE, CB_SETCURSEL, 0, 0);
					else
						SendDlgItemMessage(hWnd, IDC_SECONDLINEMODE, CB_SETCURSEL, (WPARAM)(bSecondLine + 1), 0);
				}
			}
			WindowList_Add(hWindowListIGN, hWnd, hContact);
			ShowWindow(hWnd, SW_SHOWNORMAL);
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_IGN_PRIORITY:
			SendMessage(pcli->hwndContactTree, CLM_TOGGLEPRIORITYCONTACT, hContact, 0);
			return 0;
		case IDC_IGN_ALL:
			SendMessage(hWnd, WM_USER + 100, hContact, (LPARAM)0xffffffff);
			return 0;
		case IDC_IGN_NONE:
			SendMessage(hWnd, WM_USER + 100, hContact, 0);
			return 0;
		case IDC_IGN_ALWAYSONLINE:
			if (IsDlgButtonChecked(hWnd, IDC_IGN_ALWAYSONLINE))
				CheckDlgButton(hWnd, IDC_IGN_ALWAYSOFFLINE, FALSE);
			break;
		case IDC_IGN_ALWAYSOFFLINE:
			if (IsDlgButtonChecked(hWnd, IDC_IGN_ALWAYSOFFLINE))
				CheckDlgButton(hWnd, IDC_IGN_ALWAYSONLINE, FALSE);
			break;
		case IDC_HIDECONTACT:
			cfg::writeByte(hContact, "CList", "Hidden", (BYTE)(IsDlgButtonChecked(hWnd, IDC_HIDECONTACT) ? 1 : 0));
			break;
		case IDC_IGN_ADDPERMANENTLY:
			{
				ADDCONTACTSTRUCT acs = {0};
				acs.hContact = hContact;
				acs.handleType = HANDLE_CONTACT;
				CallService(MS_ADDCONTACT_SHOW, (WPARAM)hWnd, (LPARAM)&acs);
				Utils::enableDlgControl(hWnd, IDC_IGN_ADDPERMANENTLY, cfg::getByte(hContact, "CList", "NotOnList", 0));
				break;
			}
		case IDC_DSP_LOADDEFAULT:
			{
				int i = 0;

				SendDlgItemMessage(hWnd, IDC_AVATARDISPMODE, CB_SETCURSEL, 0, 0);
				SendDlgItemMessage(hWnd, IDC_SECONDLINEMODE, CB_SETCURSEL, 0, 0);
				SendDlgItemMessage(hWnd, IDC_OVERLAYICON, BM_SETCHECK, BST_INDETERMINATE, 0);
				SendDlgItemMessage(hWnd, IDC_LOCALTIME, BM_SETCHECK, BST_INDETERMINATE, 0);
				break;
			}
		case IDOK:
			{
				DWORD newMask = 0;
				ClcContact *contact = NULL;

				SendMessage(hWnd, WM_USER + 110, 0, (LPARAM)&newMask);
				cfg::writeDword(hContact, "Ignore", "Mask1", newMask);
				SendMessage(hWnd, WM_USER + 130, 0, 0);

				if (cfg::clcdat) {
					LRESULT iSel = SendDlgItemMessage(hWnd, IDC_AVATARDISPMODE, CB_GETCURSEL, 0, 0);
					DWORD dwFlags = cfg::getDword(hContact, "CList", "CLN_Flags", 0), dwXMask = 0;
					LRESULT  checked = 0;
					int i = 0;

					FindItem(pcli->hwndContactTree, cfg::clcdat, (HANDLE)hContact, &contact, NULL, NULL);
					if (iSel != CB_ERR) {
						dwFlags &= ~(ECF_FORCEAVATAR | ECF_HIDEAVATAR);

						if (iSel == 1)
							dwFlags |= ECF_FORCEAVATAR;
						else if (iSel == 2)
							dwFlags |= ECF_HIDEAVATAR;
						if (contact)
							LoadAvatarForContact(contact);
					}

					dwFlags &= ~(ECF_FORCEOVERLAY | ECF_HIDEOVERLAY | ECF_FORCELOCALTIME | ECF_HIDELOCALTIME);

					checked = SendDlgItemMessage(hWnd, IDC_OVERLAYICON, BM_GETCHECK, 0, 0);
					if (checked == BST_CHECKED)
						dwFlags |= ECF_FORCEOVERLAY;
					else if (checked == BST_UNCHECKED)
						dwFlags |= ECF_HIDEOVERLAY;

					checked = SendDlgItemMessage(hWnd, IDC_SHOWLOCALTIME1, BM_GETCHECK, 0, 0);
					if (checked == BST_CHECKED)
						dwFlags |= ECF_FORCELOCALTIME;
					else if (checked == BST_UNCHECKED)
						dwFlags |= ECF_HIDELOCALTIME;

					cfg::writeDword(hContact, "CList", "CLN_Flags", dwFlags);

					if ((iSel = SendDlgItemMessage(hWnd, IDC_SECONDLINEMODE, CB_GETCURSEL, 0, 0)) != CB_ERR) {
						if (iSel == 0) {
							db_unset(hContact, "CList", "CLN_2ndline");
							if (contact)
								contact->bSecondLine = cfg::dat.dualRowMode;
						}
						else {
							db_set_b(hContact, "CList", "CLN_2ndline", (BYTE)(iSel - 1));
							if (contact)
								contact->bSecondLine = (BYTE)(iSel - 1);
						}
					}
					cfg::writeDword(hContact, "CList", "CLN_xmask", dwXMask);
					if (contact) {
						if (contact->pExtra)
							contact->pExtra->dwDFlags = dwFlags;
					}
					else {
						TExtraCache *p = cfg::getCache(hContact, NULL);
						if (p)
							p->dwDFlags = dwFlags;
					}
					cfg::writeByte(hContact, "CList", "Priority", (BYTE)(IsDlgButtonChecked(hWnd, IDC_IGN_PRIORITY) ? 1 : 0));
					pcli->pfnClcBroadcast(CLM_AUTOREBUILD, 0, 0);
				}
			}
		case IDCANCEL:
			DestroyWindow(hWnd);
			break;
		}
		break;
	case WM_USER + 100:	// fill dialog (wParam = hContact, lParam = mask)
		{
			CheckDlgButton(hWnd, IDC_IGN_MSGEVENTS, lParam & (1 << (IGNOREEVENT_MESSAGE - 1)) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hWnd, IDC_IGN_FILEEVENTS, lParam & (1 << (IGNOREEVENT_FILE - 1)) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hWnd, IDC_IGN_URLEVENTS, lParam & (1 << (IGNOREEVENT_URL - 1)) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hWnd, IDC_IGN_AUTH, lParam & (1 << (IGNOREEVENT_AUTHORIZATION - 1)) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hWnd, IDC_IGN_ADD, lParam & (1 << (IGNOREEVENT_YOUWEREADDED - 1)) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hWnd, IDC_IGN_ONLINE, lParam & (1 << (IGNOREEVENT_USERONLINE - 1)) ? BST_CHECKED : BST_UNCHECKED);
			return 0;
		}
	case WM_USER + 110:	// retrieve value
		{
			DWORD *dwNewMask = (DWORD *)lParam, dwMask = 0;

			dwMask = (IsDlgButtonChecked(hWnd, IDC_IGN_MSGEVENTS) ? (1 << (IGNOREEVENT_MESSAGE - 1)) : 0) |
				(IsDlgButtonChecked(hWnd, IDC_IGN_FILEEVENTS) ? (1 << (IGNOREEVENT_FILE - 1)) : 0) |
				(IsDlgButtonChecked(hWnd, IDC_IGN_URLEVENTS) ? (1 << (IGNOREEVENT_URL - 1)) : 0) |
				(IsDlgButtonChecked(hWnd, IDC_IGN_AUTH) ? (1 << (IGNOREEVENT_AUTHORIZATION - 1)) : 0) |
				(IsDlgButtonChecked(hWnd, IDC_IGN_ADD) ? (1 << (IGNOREEVENT_YOUWEREADDED - 1)) : 0) |
				(IsDlgButtonChecked(hWnd, IDC_IGN_ONLINE) ? (1 << (IGNOREEVENT_USERONLINE - 1)) : 0);

			if (dwNewMask)
				*dwNewMask = dwMask;
			return 0;
		}
	case WM_USER + 120:	// set visibility status
		{
			ClcContact *contact = NULL;
			if (FindItem(pcli->hwndContactTree, cfg::clcdat, (HANDLE)hContact, &contact, NULL, NULL)) {
				if (contact) {
					WORD wApparentMode = cfg::getWord(contact->hContact, contact->proto, "ApparentMode", 0);

					CheckDlgButton(hWnd, IDC_IGN_ALWAYSOFFLINE, wApparentMode == ID_STATUS_OFFLINE ? TRUE : FALSE);
					CheckDlgButton(hWnd, IDC_IGN_ALWAYSONLINE, wApparentMode == ID_STATUS_ONLINE ? TRUE : FALSE);
				}
			}
			return 0;
		}
	case WM_USER + 130:	// update apparent mode
		{
			ClcContact *contact = NULL;

			if (FindItem(pcli->hwndContactTree, cfg::clcdat, (HANDLE)hContact, &contact, NULL, NULL)) {
				if (contact) {
					WORD wApparentMode = 0, oldApparentMode = cfg::getWord(hContact, contact->proto, "ApparentMode", 0);

					if (IsDlgButtonChecked(hWnd, IDC_IGN_ALWAYSONLINE))
						wApparentMode = ID_STATUS_ONLINE;
					else if (IsDlgButtonChecked(hWnd, IDC_IGN_ALWAYSOFFLINE))
						wApparentMode = ID_STATUS_OFFLINE;

					//db_set_w(hContact, contact->proto, "ApparentMode", wApparentMode);
					//if (oldApparentMode != wApparentMode)
					CallContactService(hContact, PSS_SETAPPARENTMODE, (WPARAM)wApparentMode, 0);
					SendMessage(hWnd, WM_USER + 120, 0, 0);
				}
			}
			return 0;
		}
	case WM_DESTROY:
		SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
		WindowList_Remove(hWindowListIGN, hWnd);
		break;
	}
	return FALSE;
}
Esempio n. 14
0
BOOL CALLBACK DlgProcKeyBindingsOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{

	switch (msg) {
	case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);
			OldEditProc = (WNDPROC) SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PREVIEW), GWLP_WNDPROC, (LONG_PTR) KeyBindingsEditProc);
			currentTreeItem = NULL;
			loadTempKeyBindings();
			buildTree(GetDlgItem(hwndDlg, IDC_CATEGORYLIST));
			EnableWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE);
			EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), FALSE);
		}
		return TRUE;
	case WM_KEYDOWN:
	case WM_SYSKEYDOWN:
		SendDlgItemMessage(hwndDlg, IDC_PREVIEW, msg, wParam, lParam);
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_ADD:
			if (currentTreeItem->keyBinding != NULL) {
				int i;
				removeTempKeyBinding(currentTreeItem->keyBinding->actionGroupName, modifiers | virtualKey);
				for (i=0; i<5; i++) {
					if (currentTreeItem->keyBinding->tempKey[i] == 0) {
						currentTreeItem->keyBinding->tempKey[i] = modifiers | virtualKey;
						break;
					}
				}
			}
			refreshListBox(hwndDlg);
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		case IDC_DELETE:
			if (currentTreeItem->keyBinding != NULL) {
				int index = SendDlgItemMessage(hwndDlg, IDC_LIST, LB_GETCURSEL, 0, 0);
				if (index != LB_ERR && index <5) {
					if (currentTreeItem->keyBinding->tempKey[index] != 0) {
						int i;
						for (i = index + 1; i < 5; i++) {
							currentTreeItem->keyBinding->tempKey[i-1] = currentTreeItem->keyBinding->tempKey[i];
						}
						currentTreeItem->keyBinding->tempKey[4] = 0;
					}
				}
			}
			refreshListBox(hwndDlg);
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		case IDC_BTN_RESET:
			if (currentTreeItem->keyBinding != NULL) {
				int i;
				for (i = 0; i < 5; i++) {
					removeTempKeyBinding(currentTreeItem->keyBinding->actionGroupName, currentTreeItem->keyBinding->defaultKey[i]);
					currentTreeItem->keyBinding->tempKey[i] = currentTreeItem->keyBinding->defaultKey[i];
				}
			}
			refreshListBox(hwndDlg);
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		case IDC_BTN_UNDO:
			if (currentTreeItem->keyBinding != NULL) {
				int i;
				for (i = 0; i < 5; i++) {
					removeTempKeyBinding(currentTreeItem->keyBinding->actionGroupName, currentTreeItem->keyBinding->key[i]);
					currentTreeItem->keyBinding->tempKey[i] = currentTreeItem->keyBinding->key[i];
				}
			}
			refreshListBox(hwndDlg);
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		case IDC_LIST:
			if (HIWORD(wParam) == LBN_SELCHANGE) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), TRUE);
			}
			break;
		}
		break;
	case WM_NOTIFY:
		if (((LPNMHDR) lParam)->idFrom == IDC_CATEGORYLIST)
		{
			switch(((NMHDR*)lParam)->code) {
			case TVN_SELCHANGEDA:
			case TVN_SELCHANGEDW:
				{
					TVITEM tvi = {0};
					tvi.hItem = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_CATEGORYLIST));
					tvi.mask = TVIF_HANDLE|TVIF_PARAM;
					TreeView_GetItem(GetDlgItem(hwndDlg, IDC_CATEGORYLIST), &tvi);
					currentTreeItem = (TreeItem *) tvi.lParam;
					refreshListBox(hwndDlg);
					break;
				}
			case TVN_DELETEITEMA:
			case TVN_DELETEITEMW:
				{
					TreeItem *treeItem = (TreeItem *)(((LPNMTREEVIEW)lParam)->itemOld.lParam);
					if (treeItem) {
						mir_free(treeItem->paramName);
						mir_free(treeItem);
					}
					break;
				}
			}
		}
		if (((LPNMHDR) lParam)->idFrom == 0 && ((LPNMHDR) lParam)->code == PSN_APPLY ) {
			saveKeyBindings();
		}
		break;
	case WM_DESTROY:
		saveCollapseState(GetDlgItem(hwndDlg, IDC_CATEGORYLIST));

	}
	return FALSE;
}
Esempio n. 15
0
INT_PTR CALLBACK DlgProcSoundUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static HANDLE hContact = NULL;
    switch (msg)
    {
    case WM_INITDIALOG:
    {
        TranslateDialogDefault(hwndDlg);

        hContact = (HANDLE)lParam;
        char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
        HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);

        ListView_SetImageList(hList, GetStatusIconsImgList(szProto), LVSIL_SMALL);
        ListView_SetExtendedListViewStyleEx(hList, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);

        RECT rc = {0};
        GetClientRect(hList, &rc);

        LV_COLUMN lvc = {0};
        lvc.mask = LVCF_WIDTH | LVCF_TEXT;
        lvc.cx = STATUS_COLUMN;
        lvc.pszText = TranslateT("Status");
        ListView_InsertColumn(hList, 0, &lvc);

        lvc.cx = rc.right - STATUS_COLUMN - GetSystemMetrics(SM_CXVSCROLL);
        lvc.pszText = TranslateT("Sound for the status");
        ListView_InsertColumn(hList, 1, &lvc);

        if (szProto)
        {
            DBVARIANT dbv;
            TCHAR buff[MAX_PATH];

            for (int i = ID_STATUS_MAX; i >= ID_STATUS_MIN; i--)
            {
                int flags = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_2, 0);
                if (flags == 0)
                    flags = PF2_ONLINE|PF2_INVISIBLE|PF2_SHORTAWAY|PF2_LONGAWAY|PF2_LIGHTDND|PF2_HEAVYDND|PF2_FREECHAT|PF2_OUTTOLUNCH|PF2_ONTHEPHONE;

                if ((flags & Proto_Status2Flag(i)) || i == ID_STATUS_OFFLINE)
                {
                    LV_ITEM lvi = {0};
                    lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
                    lvi.iItem = 0;
                    lvi.iSubItem = 0;
                    lvi.iImage = Index(i);
                    lvi.lParam = (LPARAM)i;
                    lvi.pszText = TranslateTS(StatusList[Index(i)].lpzStandardText);
                    lvi.iItem = ListView_InsertItem(hList, &lvi);

                    if (!DBGetContactSettingTString(hContact, MODULE, StatusList[Index(i)].lpzSkinSoundName, &dbv))
                    {
                        _tcscpy(buff, dbv.ptszVal);
                        DBFreeVariant(&dbv);
                    }
                    else
                        _tcscpy(buff, TranslateT(DEFAULT_SOUND));

                    ListView_SetItemText(hList, lvi.iItem, 1, buff);
                }
            }

            LV_ITEM lvi = {0};
            lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
            lvi.iItem = 0;
            lvi.iSubItem = 0;
            lvi.iImage = Index(ID_STATUS_MAX) + 1; // additional icon
            lvi.lParam = (LPARAM)ID_STATUS_FROMOFFLINE;
            lvi.pszText = TranslateT("From offline");
            lvi.iItem = ListView_InsertItem(hList, &lvi);

            if (!DBGetContactSettingTString(hContact, MODULE, "UserFromOffline", &dbv))
            {
                _tcscpy(buff, dbv.ptszVal);
                DBFreeVariant(&dbv);
            }
            else
                _tcscpy(buff, TranslateT(DEFAULT_SOUND));

            ListView_SetItemText(hList, lvi.iItem, 1, buff);
        }

        CheckDlgButton(hwndDlg, IDC_CHECK_NOTIFYSOUNDS, DBGetContactSettingByte(hContact, MODULE, "EnableSounds", 1));
        CheckDlgButton(hwndDlg, IDC_CHECK_NOTIFYPOPUPS, DBGetContactSettingByte(hContact, MODULE, "EnablePopups", 1));

        ShowWindow(GetDlgItem(hwndDlg, IDC_INDSNDLIST), opt.UseIndSnd ? SW_SHOW : SW_HIDE);
        ShowWindow(GetDlgItem(hwndDlg, IDC_TEXT_ENABLE_IS), opt.UseIndSnd ? SW_HIDE : SW_SHOW);
        ShowWindow(GetDlgItem(hwndDlg, IDC_CHANGE), opt.UseIndSnd ? SW_SHOW : SW_HIDE);
        ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), opt.UseIndSnd ? SW_SHOW : SW_HIDE);
        ShowWindow(GetDlgItem(hwndDlg, IDC_DELETE), opt.UseIndSnd ? SW_SHOW : SW_HIDE);

        return TRUE;
    }
    case WM_COMMAND:
    {
        switch (LOWORD(wParam))
        {
        case IDC_PREVIEW:
        {
            HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);
            if (ListView_GetSelectionMark(hList) != -1)
                PreviewSound(hList);
            break;
        }
        case IDC_CHANGE:
        {
            HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);
            int iSel = ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_INDSNDLIST), -1, LVNI_SELECTED);
            if (iSel != -1)
            {
                TCHAR stzFilePath[MAX_PATH];
                if (SelectSound(hwndDlg, stzFilePath) != NULL)
                {
                    iSel = -1;
                    while ((iSel = ListView_GetNextItem(hList, iSel, LVNI_SELECTED)) != -1)
                        ListView_SetItemText(hList, iSel, 1, stzFilePath);

                    SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
                }
            }
            break;
        }
        case IDC_DELETE:
        {
            HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);
            if (ListView_GetSelectionMark(hList) != -1)
            {
                if (RemoveSoundFromList(GetDlgItem(hwndDlg, IDC_INDSNDLIST)))
                    SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
            }
            break;
        }
        case IDC_CHECK_NOTIFYSOUNDS:
        {
            DBWriteContactSettingByte(hContact, MODULE, "EnableSounds", IsDlgButtonChecked(hwndDlg, IDC_CHECK_NOTIFYSOUNDS) ? 1 : 0);
            break;
        }
        case IDC_CHECK_NOTIFYPOPUPS:
        {
            DBWriteContactSettingByte(hContact, MODULE, "EnablePopups", IsDlgButtonChecked(hwndDlg, IDC_CHECK_NOTIFYPOPUPS) ? 1 : 0);
            break;
        }
        }
        break;
    }
    case WM_NOTIFY:
    {
        LPNMHDR pParam = (LPNMHDR)lParam;
        if (pParam->code == PSN_APPLY)
        {
            TCHAR buff[MAX_PATH];
            HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);

            LVITEM lvi = {0};
            lvi.mask = LVIF_PARAM;
            //Cycle through the list reading the text associated to each status.
            for (lvi.iItem = ListView_GetItemCount(hList) - 1; lvi.iItem >= 0; lvi.iItem--)
            {
                ListView_GetItem(hList, &lvi);
                ListView_GetItemText(hList, lvi.iItem, 1, buff, SIZEOF(buff));

                if (!_tcscmp(buff, TranslateT(DEFAULT_SOUND)))
                {
                    if (lvi.lParam == ID_STATUS_FROMOFFLINE)
                        DBDeleteContactSetting(hContact, MODULE, "UserFromOffline");
                    else
                        DBDeleteContactSetting(hContact, MODULE, StatusList[Index(lvi.lParam)].lpzSkinSoundName);
                }
                else
                {
                    TCHAR stzSoundPath[MAX_PATH] = { 0 };
                    CallService(MS_UTILS_PATHTORELATIVET, (WPARAM)buff, (LPARAM)stzSoundPath);
                    if (lvi.lParam == ID_STATUS_FROMOFFLINE)
                        DBWriteContactSettingTString(hContact, MODULE, "UserFromOffline", stzSoundPath);
                    else
                        DBWriteContactSettingTString(hContact, MODULE, StatusList[Index(lvi.lParam)].lpzSkinSoundName, stzSoundPath);
                }
            }

            return TRUE;
        }

        int hlpControlID = (int)wParam;
        switch (hlpControlID)
        {
        case IDC_INDSNDLIST:
        {
            if (pParam->code == NM_DBLCLK)
            {
                TCHAR stzFilePath[MAX_PATH];
                if (SelectSound(hwndDlg, stzFilePath) != NULL)
                {
                    int iSel = -1;
                    HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);
                    while ((iSel = ListView_GetNextItem(hList, iSel, LVNI_SELECTED)) != -1)
                        ListView_SetItemText(hList, iSel, 1, stzFilePath);

                    SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
                }
                return TRUE;
            }
            else if (pParam->code == LVN_KEYDOWN)
            {
                LPNMLVKEYDOWN pnkd = (LPNMLVKEYDOWN)lParam;
                if (pnkd->wVKey == VK_DELETE)
                    RemoveSoundFromList(GetDlgItem(hwndDlg, IDC_INDSNDLIST));
            }

            break;
        }
        }
        break;
    }
    }
    return FALSE;
}
Esempio n. 16
0
//=======================================================
//Custom status message windows handling
//=======================================================
static INT_PTR CALLBACK DlgProcSetCustStat(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	DBVARIANT dbv;

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			CYahooProto* ppro = (CYahooProto*)lParam;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);

			SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)ppro->LoadIconEx("yahoo", true));
			SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)ppro->LoadIconEx("yahoo"));

			if (!ppro->getString(YAHOO_CUSTSTATDB, &dbv)) {
				SetDlgItemTextA(hwndDlg, IDC_CUSTSTAT, dbv.pszVal);

				EnableWindow(GetDlgItem(hwndDlg, IDOK), mir_strlen(dbv.pszVal) > 0);
				db_free(&dbv);
			}
			else {
				SetDlgItemTextA(hwndDlg, IDC_CUSTSTAT, "");
				EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
			}

			CheckDlgButton(hwndDlg, IDC_CUSTSTATBUSY, ppro->getByte("BusyCustStat", 0) ? BST_CHECKED : BST_UNCHECKED);
		}
		return TRUE;

	case WM_COMMAND:
		switch (wParam) {
		case IDOK:
			{
				char str[255 + 1];
				CYahooProto* ppro = (CYahooProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

				/* Get String from dialog */
				GetDlgItemTextA(hwndDlg, IDC_CUSTSTAT, str, _countof(str));

				/* Save it for later use */
				ppro->setString(YAHOO_CUSTSTATDB, str);
				ppro->setByte("BusyCustStat", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_CUSTSTATBUSY));

				/* set for Idle/AA */
				if (ppro->m_startMsg) mir_free(ppro->m_startMsg);
				ppro->m_startMsg = mir_strdup(str);

				/* notify Server about status change */
				ppro->set_status(YAHOO_CUSTOM_STATUS, str, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_CUSTSTATBUSY));

				/* change local/miranda status */
				ppro->BroadcastStatus((BYTE)IsDlgButtonChecked(hwndDlg, IDC_CUSTSTATBUSY) ? ID_STATUS_AWAY : ID_STATUS_ONLINE);
			}
		case IDCANCEL:
			DestroyWindow(hwndDlg);
			break;
		}

		if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) {
			if (LOWORD(wParam) == IDC_CUSTSTAT) {
				char str[255 + 1];

				BOOL toSet;

				toSet = GetDlgItemTextA(hwndDlg, IDC_CUSTSTAT, str, _countof(str)) != 0;

				EnableWindow(GetDlgItem(hwndDlg, IDOK), toSet);
			}
		}
		break; /* case WM_COMMAND */

	case WM_CLOSE:
		DestroyWindow(hwndDlg);
		break;

	case WM_DESTROY:
		{
			CYahooProto* ppro = (CYahooProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			ppro->ReleaseIconEx("yahoo", true);
			ppro->ReleaseIconEx("yahoo");
		}
		break;
	}
	return FALSE;
}
Esempio n. 17
0
INT_PTR CALLBACK DlgProcFiltering(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static HANDLE hItemAll;
    switch (msg)
    {
    case WM_INITDIALOG:
    {
        TranslateDialogDefault(hwndDlg);

        HIMAGELIST hImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16 | ILC_MASK, 3, 3);

        ImageList_AddIcon(hImageList, LoadIcon(hInst,MAKEINTRESOURCE(IDI_SOUND)));
        SendDlgItemMessage(hwndDlg,IDC_SOUNDICON,STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_SOUND, ILD_NORMAL), 0);
        ImageList_AddIcon(hImageList, LoadIcon(hInst, MAKEINTRESOURCE(IDI_POPUP)));
        SendDlgItemMessage(hwndDlg, IDC_POPUPICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_POPUP, ILD_NORMAL), 0);
        ImageList_AddIcon(hImageList, LoadIcon(hInst,MAKEINTRESOURCE(IDI_XSTATUS)));
        SendDlgItemMessage(hwndDlg, IDC_XSTATUSICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_XSTATUS, ILD_NORMAL), 0);
        ImageList_AddIcon(hImageList, LoadIcon(hInst,MAKEINTRESOURCE(IDI_LOGGING)));
        SendDlgItemMessage(hwndDlg, IDC_LOGGINGICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_LOGGING, ILD_NORMAL), 0);
        ImageList_AddIcon(hImageList, LoadIcon(hInst,MAKEINTRESOURCE(IDI_DISABLEALL)));
        SendDlgItemMessage(hwndDlg, IDC_DISABLEALLICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_DISABLEALL, ILD_NORMAL), 0);
        ImageList_AddIcon(hImageList, LoadIcon(hInst,MAKEINTRESOURCE(IDI_ENABLEALL)));
        SendDlgItemMessage(hwndDlg, IDC_ENABLEALLICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_ENABLEALL, ILD_NORMAL), 0);

        ImageList_AddIcon(hImageList, LoadSkinnedIcon(SKINICON_OTHER_SMALLDOT));

        SendDlgItemMessage(hwndDlg, IDC_INDSNDLIST, CLM_SETEXTRAIMAGELIST, 0, (LPARAM)hImageList);
        SendDlgItemMessage(hwndDlg, IDC_INDSNDLIST, CLM_SETEXTRACOLUMNS, 6, 0);

        HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);
        ResetListOptions(hList);

        CLCINFOITEM cii = {0};
        cii.cbSize = sizeof(cii);
        cii.flags = CLCIIF_GROUPFONT;
        cii.pszText = TranslateT("** All contacts **");
        hItemAll = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_INDSNDLIST, CLM_ADDINFOITEM, 0, (LPARAM)&cii);

        return TRUE;
    }
    case WM_SETFOCUS:
    {
        SetFocus(GetDlgItem(hwndDlg, IDC_INDSNDLIST));
        break;
    }
    case WM_NOTIFY:
    {
        HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);
        switch(((LPNMHDR)lParam)->idFrom)
        {
        case IDC_INDSNDLIST:
            switch (((LPNMHDR)lParam)->code)
            {
            case CLN_NEWCONTACT:
            case CLN_LISTREBUILT:
                SetAllContactsIcons(hList);
            //fall through
            case CLN_CONTACTMOVED:
                SetGroupsIcons(hList, (HANDLE)SendMessage(hList, CLM_GETNEXTITEM, CLGN_ROOT, 0), hItemAll, NULL);
                break;
            case CLN_OPTIONSCHANGED:
                ResetListOptions(hList);
                break;
            case NM_CLICK:
            {
                NMCLISTCONTROL *nm = (NMCLISTCONTROL*)lParam;
                DWORD hitFlags;

                // Make sure we have an extra column
                if (nm->iColumn == -1) break;

                // Find clicked item
                HANDLE hItem = (HANDLE)SendMessage(hList, CLM_HITTEST, (WPARAM)&hitFlags, MAKELPARAM(nm->pt.x, nm->pt.y));
                if (hItem == NULL) break;
                if(!(hitFlags & CLCHT_ONITEMEXTRA)) break;

                int itemType = SendMessage(hList, CLM_GETITEMTYPE, (WPARAM)hItem, 0);

                // Get image in clicked column
                int image = GetExtraImage(hList, hItem, nm->iColumn);
                if (image == EXTRA_IMAGE_DOT)
                    image = nm->iColumn;
                else if (image >= EXTRA_IMAGE_SOUND && image <= EXTRA_IMAGE_LOGGING)
                    image = EXTRA_IMAGE_DOT;

                // Get item type (contact, group, etc...)
                if (itemType == CLCIT_CONTACT)
                {
                    if (image == EXTRA_IMAGE_DISABLEALL)
                    {
                        for (int i = 0; i < 4; i++)
                            SetExtraImage(hList, hItem, i, EXTRA_IMAGE_DOT);
                    }
                    else if (image == EXTRA_IMAGE_ENABLEALL)
                    {
                        for (int i = 0; i < 4; i++)
                            SetExtraImage(hList, hItem, i, i);
                    }
                    else
                    {
                        SetExtraImage(hList, hItem, nm->iColumn, image);
                    }
                }
                else if (itemType == CLCIT_INFO || itemType == CLCIT_GROUP)
                {
                    if (itemType == CLCIT_GROUP)
                        hItem = (HANDLE)SendMessage(hList, CLM_GETNEXTITEM, CLGN_CHILD, (LPARAM)hItem);

                    if (hItem)
                    {
                        if (image == EXTRA_IMAGE_DISABLEALL)
                        {
                            for (int i = 0; i < 4; i++)
                                SetAllChildrenIcons(hList, hItem, i, EXTRA_IMAGE_DOT);
                        }
                        else if (image == EXTRA_IMAGE_ENABLEALL)
                        {
                            for (int i = 0; i < 4; i++)
                                SetAllChildrenIcons(hList, hItem, i, i);
                        }
                        else
                        {
                            SetAllChildrenIcons(hList, hItem, nm->iColumn, image);
                        }
                    }
                }

                // Update the all/none icons
                SetGroupsIcons(hList, (HANDLE)SendMessage(hList, CLM_GETNEXTITEM, CLGN_ROOT, 0), hItemAll, NULL);
                // Activate Apply button
                SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
                break;
            }
            }
            break;
        case 0:
            switch (((LPNMHDR)lParam)->code)
            {
            case PSN_APPLY:
            {
                HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
                do
                {
                    HANDLE hItem = (HANDLE)SendMessage(hList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
                    if (hItem)
                    {
                        if (GetExtraImage(hList, hItem, EXTRA_IMAGE_SOUND) == EXTRA_IMAGE_SOUND)
                            DBDeleteContactSetting(hContact, MODULE, "EnableSounds");
                        else
                            DBWriteContactSettingByte(hContact, MODULE, "EnableSounds", 0);

                        if (GetExtraImage(hList, hItem, EXTRA_IMAGE_POPUP) == EXTRA_IMAGE_POPUP)
                            DBDeleteContactSetting(hContact, MODULE, "EnablePopups");
                        else
                            DBWriteContactSettingByte(hContact, MODULE, "EnablePopups", 0);

                        if(GetExtraImage(hList, hItem, EXTRA_IMAGE_XSTATUS) == EXTRA_IMAGE_XSTATUS)
                            DBDeleteContactSetting(hContact, MODULE, "EnableXStatusNotify");
                        else
                            DBWriteContactSettingByte(hContact, MODULE, "EnableXStatusNotify", 0);

                        if (GetExtraImage(hList, hItem, EXTRA_IMAGE_LOGGING) == EXTRA_IMAGE_LOGGING)
                            DBDeleteContactSetting(hContact, MODULE, "EnableLogging");
                        else
                            DBWriteContactSettingByte(hContact, MODULE, "EnableLogging", 0);

                    }
                } while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0));

                return TRUE;
            }
            }
            break;
        }
        break;
    }
    case WM_DESTROY:
    {
        HIMAGELIST hImageList = (HIMAGELIST)SendMessage(GetDlgItem(hwndDlg, IDC_INDSNDLIST), CLM_GETEXTRAIMAGELIST, 0, 0);
        for (int i = 0; i < ImageList_GetImageCount(hImageList); i++)
            DestroyIcon(ImageList_GetIcon(hImageList, i, ILD_NORMAL));
        ImageList_Destroy(hImageList);
        break;
    }
    }
    return FALSE;
}
Esempio n. 18
0
static INT_PTR CALLBACK Meta_SelectDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			DBCachedContact *cc = currDb->m_cache->GetCachedContact(lParam);
			if (cc == NULL) {
				DestroyWindow(hwndDlg);
				return TRUE;
			}

			if (cc->IsMeta()) {
				MessageBox(hwndDlg,
							  TranslateT("This contact is a metacontact.\nYou can't add a metacontact to another metacontact.\n\nPlease choose another."),
							  TranslateT("Metacontact conflict"), MB_ICONERROR);
				DestroyWindow(hwndDlg);
				return TRUE;
			}

			if (cc->IsSub()) {
				MessageBox(hwndDlg,
							  TranslateT("This contact is already associated to a metacontact.\nYou cannot add a contact to multiple metacontacts."),
							  TranslateT("Multiple metacontacts"), MB_ICONERROR);
				DestroyWindow(hwndDlg);
				return TRUE;
			}
		}

		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); // user data is contact handle

		SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_ADD));

		// Initialize the graphical part
		CheckDlgButton(hwndDlg, IDC_ONLYAVAIL, BST_CHECKED); // Initially checked; display all metacontacts is only an option
		// Besides, we can check if there is at least one metacontact to add the contact to.
		if (BuildList(GetDlgItem(hwndDlg, IDC_METALIST), FALSE) <= 0) {
			if (MessageBox(hwndDlg, TranslateT(szConvMsg), TranslateT("No suitable metacontact found"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1) == IDYES)
				Meta_Convert(lParam, 0);
			DestroyWindow(hwndDlg);
			return TRUE;
		}
		else {
			// get contact display name from clist
			TCHAR *ptszCDN = cli.pfnGetContactDisplayName(lParam, 0);
			if (!ptszCDN)
				ptszCDN = TranslateT("a contact");

			// ... and set it to the Window title.
			TCHAR buf[256];
			mir_sntprintf(buf, SIZEOF(buf), TranslateT("Adding %s..."), ptszCDN);
			SetWindowText(hwndDlg, buf);
		}
		ShowWindow(hwndDlg, SW_SHOWNORMAL);
		return TRUE;

	case WM_COMMAND:
		if (HIWORD(wParam) == LBN_DBLCLK) // emulate click ok Ok
			wParam = MAKEWPARAM(IDOK, BN_CLICKED);

		if (HIWORD(wParam) != BN_CLICKED)
			break;	// Only clicks of buttons are relevant, let other COMMANDs through

		switch (LOWORD(wParam)) {
			case IDOK:
			{
				int item = SendDlgItemMessage(hwndDlg, IDC_METALIST, LB_GETCURSEL, 0, 0);	// Get the index of the selected metacontact
				if (item == -1)
					return IDOK == MessageBox(hwndDlg, TranslateT("Please select a metacontact"), TranslateT("No metacontact selected"), MB_ICONHAND);

				MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
				MCONTACT hMeta = (MCONTACT)SendMessage(GetDlgItem(hwndDlg, IDC_METALIST), LB_GETITEMDATA, item, 0);
				if (!Meta_Assign(hContact, hMeta, FALSE))
					MessageBox(hwndDlg, TranslateT("Assignment to the metacontact failed."), TranslateT("Assignment failure"), MB_ICONERROR);
			}
			// fall through
		case IDCANCEL:
			DestroyWindow(hwndDlg);
			break;

		case IDC_CHK_SRT:
			SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_METALIST), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_METALIST), GWL_STYLE) ^ LBS_SORT);
			if (BuildList(GetDlgItem(hwndDlg, IDC_METALIST), IsDlgButtonChecked(hwndDlg, IDC_CHK_SRT) ? TRUE : FALSE) <= 0) {
				if (MessageBox(hwndDlg, TranslateT(szConvMsg), TranslateT("No suitable metacontact found"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1) == IDYES)
					Meta_Convert(lParam, 0);
				DestroyWindow(hwndDlg);
				return TRUE;
			}
			break;
		}
		break;

	case WM_DESTROY:
		// Free all allocated memory and return the focus to the CList
		HWND clist = GetParent(hwndDlg);
		Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
		EndDialog(hwndDlg, TRUE);
		SetFocus(clist);
		return TRUE;
	}
	return FALSE;	// All other Message are not handled
}
Esempio n. 19
0
INT_PTR CALLBACK DlgProcUrlRecv(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct UrlRcvData *dat = (struct UrlRcvData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_URL);
		Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list"));
		Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details"));
		Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View user's history"));
		Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User menu"));

		dat = (struct UrlRcvData*)mir_alloc(sizeof(struct UrlRcvData));
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);

		dat->hContact = ((CLISTEVENT*)lParam)->hContact;
		dat->hDbEvent = ((CLISTEVENT*)lParam)->hDbEvent;

		WindowList_Add(hUrlWindowList, hwndDlg, dat->hContact);
		{
			DBEVENTINFO dbei = { sizeof(dbei) };
			dbei.cbBlob = db_event_getBlobSize(dat->hDbEvent);
			dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob);
			db_event_get(dat->hDbEvent, &dbei);
			SetDlgItemTextA(hwndDlg, IDC_URL, (char*)dbei.pBlob);
			SetDlgItemTextA(hwndDlg, IDC_MSG, (char*)dbei.pBlob+lstrlenA((char*)dbei.pBlob)+1);
			mir_free(dbei.pBlob);

			db_event_markRead(dat->hContact, dat->hDbEvent);

			TCHAR *contactName = pcli->pfnGetContactDisplayName(dat->hContact, 0), msg[128];
			mir_sntprintf(msg, SIZEOF(msg), TranslateT("URL from %s"), contactName);
			SetWindowText(hwndDlg, msg);
			SetDlgItemText(hwndDlg, IDC_FROM, contactName);
			SendDlgItemMessage(hwndDlg, IDOK, BUTTONSETARROW, 1, 0);

			TCHAR str[128];
			tmi.printTimeStamp(NULL, dbei.timestamp, _T("t d"), str, SIZEOF(str), 0);
			SetDlgItemText(hwndDlg, IDC_DATE, str);
		}

		// From message dlg
		if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0))
			ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE);

		SendMessage(hwndDlg, DM_UPDATETITLE, 0, 0);
		// From message dlg end

		Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, "SRUrl", "recv");
		return TRUE;

	case WM_MEASUREITEM:
		return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam);

	case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
			if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) {
				char *szProto;

				szProto = GetContactProto(dat->hContact);
				if (szProto) {
					HICON hIcon;

					hIcon = (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL|PLIF_SMALL, 0);
					if (hIcon) {
						DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL);
						DestroyIcon(hIcon);
		}	}	}	}
		return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam);

	case DM_UPDATETITLE:
		sttUpdateTitle(hwndDlg, dat->hContact);
		break;

	case WM_COMMAND:
		if (dat)
			if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact))
				break;
		switch(LOWORD(wParam)) {
		case IDOK:
			{	HMENU hMenu, hSubMenu;
				RECT rc;
				char url[256];

				hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXT));
				hSubMenu = GetSubMenu(hMenu, 6);
				TranslateMenu(hSubMenu);
				GetWindowRect((HWND)lParam, &rc);
				GetDlgItemTextA(hwndDlg, IDC_URL, url, SIZEOF(url));
				switch(TrackPopupMenu(hSubMenu, TPM_RETURNCMD, rc.left, rc.bottom, 0, hwndDlg, NULL)) {
					case IDM_OPENNEW:
						CallService(MS_UTILS_OPENURL, 1, (LPARAM)url);
						break;
					case IDM_OPENEXISTING:
						CallService(MS_UTILS_OPENURL, 0, (LPARAM)url);
						break;
					case IDM_COPYLINK:
					{	HGLOBAL hData;
						if ( !OpenClipboard(hwndDlg)) break;
						EmptyClipboard();
						hData = GlobalAlloc(GMEM_MOVEABLE, lstrlenA(url)+1);
						lstrcpyA((char*)GlobalLock(hData), url);
						GlobalUnlock(hData);
						SetClipboardData(CF_TEXT, hData);
						CloseClipboard();
						break;
					}
				}
                DestroyMenu(hMenu);
			}
			return TRUE;

		case IDC_USERMENU:
			{
				RECT rc;
				HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0);
				GetWindowRect(GetDlgItem(hwndDlg, IDC_USERMENU), &rc);
				TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL);
				DestroyMenu(hMenu);
			}
			break;

		case IDC_HISTORY:
			CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0);
			break;

		case IDC_DETAILS:
			CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0);
			break;

		case IDC_ADD:
			{
				ADDCONTACTSTRUCT acs = {0};
				acs.hContact = dat->hContact;
				acs.handleType = HANDLE_CONTACT;
				CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs);
			}
			if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0)) {
				ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE);
			}
			break;

		case IDC_REPLY:
			CallService(MS_MSG_SENDMESSAGE, (WPARAM)dat->hContact, 0);
			//fall through
		case IDCANCEL:
			DestroyWindow(hwndDlg);
			return TRUE;
		}
		break;

	case WM_DESTROY:
		Window_FreeIcon_IcoLib(hwndDlg);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU);

		WindowList_Remove(hUrlWindowList, hwndDlg);
		mir_free(dat);
		Utils_SaveWindowPosition(hwndDlg, NULL, "SRUrl", "recv");
		break;
	}
	return FALSE;
}
Esempio n. 20
0
INT_PTR CALLBACK DlgProcPopupGeneral(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static bool bDlgInit = false;	// some controls send WM_COMMAND before or during WM_INITDIALOG

	static OPTTREE_OPTION *statusOptions = NULL;
	static int statusOptionsCount = 0;
	if (statusOptions) {
		int index;
		if (OptTree_ProcessMessage(hwnd, msg, wParam, lParam, &index, IDC_STATUSES, statusOptions, statusOptionsCount))
			return TRUE;
	}

	switch (msg) {
	case WM_INITDIALOG:
		// Seconds of delay
		CheckDlgButton(hwnd, IDC_INFINITEDELAY, PopupOptions.InfiniteDelay ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hwnd, IDC_LEAVEHOVERED, PopupOptions.LeaveHovered ? BST_CHECKED : BST_UNCHECKED);
		EnableWindow(GetDlgItem(hwnd, IDC_SECONDS), !PopupOptions.InfiniteDelay);
		EnableWindow(GetDlgItem(hwnd, IDC_SECONDS_STATIC1), !PopupOptions.InfiniteDelay);
		EnableWindow(GetDlgItem(hwnd, IDC_SECONDS_STATIC2), !PopupOptions.InfiniteDelay);
		EnableWindow(GetDlgItem(hwnd, IDC_LEAVEHOVERED), !PopupOptions.InfiniteDelay);
		SetDlgItemInt(hwnd, IDC_SECONDS, PopupOptions.Seconds, FALSE);
		SendDlgItemMessage(hwnd, IDC_SECONDS_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(SETTING_LIFETIME_MAX, SETTING_LIFETIME_MIN));

		// Dynamic Resize
		CheckDlgButton(hwnd, IDC_DYNAMICRESIZE, PopupOptions.DynamicResize ? BST_CHECKED : BST_UNCHECKED);
		SetDlgItemText(hwnd, IDC_USEMAXIMUMWIDTH, PopupOptions.DynamicResize ? LPGENT("Maximum width") : LPGENT("Width"));
		// Minimum Width
		CheckDlgButton(hwnd, IDC_USEMINIMUMWIDTH, PopupOptions.UseMinimumWidth ? BST_CHECKED : BST_UNCHECKED);
		SendDlgItemMessage(hwnd, IDC_MINIMUMWIDTH_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(SETTING_MAXIMUMWIDTH_MAX, SETTING_MINIMUMWIDTH_MIN));
		SetDlgItemInt(hwnd, IDC_MINIMUMWIDTH, PopupOptions.MinimumWidth, FALSE);
		// Maximum Width
		PopupOptions.UseMaximumWidth = PopupOptions.DynamicResize ? PopupOptions.UseMaximumWidth : TRUE;
		CheckDlgButton(hwnd, IDC_USEMAXIMUMWIDTH, PopupOptions.UseMaximumWidth ? BST_CHECKED : BST_UNCHECKED);
		SendDlgItemMessage(hwnd, IDC_MAXIMUMWIDTH_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(SETTING_MAXIMUMWIDTH_MAX, SETTING_MINIMUMWIDTH_MIN));
		SetDlgItemInt(hwnd, IDC_MAXIMUMWIDTH, PopupOptions.MaximumWidth, FALSE);
		// And finally let's enable/disable them.
		EnableWindow(GetDlgItem(hwnd, IDC_USEMINIMUMWIDTH), PopupOptions.DynamicResize);
		EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH), PopupOptions.DynamicResize && PopupOptions.UseMinimumWidth);
		EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH_SPIN), PopupOptions.DynamicResize && PopupOptions.UseMinimumWidth);
		EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH), PopupOptions.UseMaximumWidth);
		EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH_SPIN), PopupOptions.UseMaximumWidth);

		// Position combobox.
		{
			HWND hCtrl = GetDlgItem(hwnd, IDC_WHERE);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upper left corner")), POS_UPPERLEFT);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Lower left corner")), POS_LOWERLEFT);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Lower right corner")), POS_LOWERRIGHT);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upper right corner")), POS_UPPERRIGHT);
			SendDlgItemMessage(hwnd, IDC_WHERE, CB_SETCURSEL, PopupOptions.Position, 0);
		}
		// Configure popup area
		{
			HWND hCtrl = GetDlgItem(hwnd, IDC_CUSTOMPOS);
			SendMessage(hCtrl, BUTTONSETASFLATBTN, TRUE, 0);
			SendMessage(hCtrl, BUTTONADDTOOLTIP, (WPARAM)_T("Popup area"), BATF_TCHAR);
			SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx(IDI_RESIZE));
		}
		// Spreading combobox
		{
			HWND hCtrl = GetDlgItem(hwnd, IDC_LAYOUT);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Horizontal")), SPREADING_HORIZONTAL);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Vertical")), SPREADING_VERTICAL);
			SendDlgItemMessage(hwnd, IDC_LAYOUT, CB_SETCURSEL, PopupOptions.Spreading, 0);
		}
		// miscellaneous
		CheckDlgButton(hwnd, IDC_REORDERPOPUPS, PopupOptions.ReorderPopups ? BST_CHECKED : BST_UNCHECKED);

		// Popup enabled
		CheckDlgButton(hwnd, IDC_POPUPENABLED, PopupOptions.ModuleIsEnabled ? BST_UNCHECKED : BST_CHECKED);
		CheckDlgButton(hwnd, IDC_DISABLEINFS, PopupOptions.DisableWhenFullscreen ? BST_CHECKED : BST_UNCHECKED);
		EnableWindow(GetDlgItem(hwnd, IDC_DISABLEINFS), PopupOptions.ModuleIsEnabled);
		EnableWindow(GetDlgItem(hwnd, IDC_STATUSES), PopupOptions.ModuleIsEnabled);

		// new status options
		{
			int protocolCount = 0;
			PROTOACCOUNT **protocols;
			Proto_EnumAccounts(&protocolCount, &protocols);
			DWORD globalFlags = 0;
			for (int i = 0; i < protocolCount; ++i) {
				if (!protocols[i]->bIsVirtual) {
					DWORD protoFlags = CallProtoService(protocols[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0);
					globalFlags |= protoFlags;
					statusOptionsCount += CountStatusModes(protoFlags);
				}
			}
			statusOptionsCount += CountStatusModes(globalFlags);

			statusOptions = new OPTTREE_OPTION[statusOptionsCount];

			int pos = AddStatusModes(statusOptions, 0, LPGENT("Global Status"), globalFlags);
			for (int i = 0; i < protocolCount; ++i) {
				if (!protocols[i]->bIsVirtual) {
					DWORD protoFlags = CallProtoService(protocols[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0);
					if (!CountStatusModes(protoFlags))
						continue;

					TCHAR prefix[128];
					mir_sntprintf(prefix, _countof(prefix), LPGENT("Protocol Status")_T("/%s"), protocols[i]->tszAccountName);
					pos = AddStatusModes(statusOptions, pos, prefix, protoFlags);
				}
			}

			int index;
			OptTree_ProcessMessage(hwnd, msg, wParam, lParam, &index, IDC_STATUSES, statusOptions, statusOptionsCount);

			for (int i = 0; i < protocolCount; ++i) {
				if (!protocols[i]->bIsVirtual) {
					DWORD protoFlags = CallProtoService(protocols[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0);
					if (!CountStatusModes(protoFlags))
						continue;

					char prefix[128];
					mir_snprintf(prefix, _countof(prefix), "Protocol Status/%s", protocols[i]->szModuleName);

					TCHAR pszSettingName[256];
					mir_sntprintf(pszSettingName, _countof(pszSettingName), LPGENT("Protocol Status")_T("/%s"), protocols[i]->tszAccountName);
					OptTree_SetOptions(hwnd, IDC_STATUSES, statusOptions, statusOptionsCount, db_get_dw(NULL, MODULNAME, prefix, 0), pszSettingName);
				}
			}
			OptTree_SetOptions(hwnd, IDC_STATUSES, statusOptions, statusOptionsCount, db_get_dw(NULL, MODULNAME, "Global Status", 0), LPGENT("Global Status"));
		}

		TranslateDialogDefault(hwnd);	// do it on end of WM_INITDIALOG
		bDlgInit = true;
		return TRUE;

	case WM_COMMAND:
		switch (HIWORD(wParam)) {
		case BN_CLICKED:	// Button controls
			switch (LOWORD(wParam)) {
			case IDC_INFINITEDELAY:
				PopupOptions.InfiniteDelay = !PopupOptions.InfiniteDelay;
				EnableWindow(GetDlgItem(hwnd, IDC_SECONDS), !PopupOptions.InfiniteDelay);
				EnableWindow(GetDlgItem(hwnd, IDC_SECONDS_STATIC1), !PopupOptions.InfiniteDelay);
				EnableWindow(GetDlgItem(hwnd, IDC_SECONDS_STATIC2), !PopupOptions.InfiniteDelay);
				EnableWindow(GetDlgItem(hwnd, IDC_LEAVEHOVERED), !PopupOptions.InfiniteDelay);
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_LEAVEHOVERED:
				PopupOptions.LeaveHovered = !PopupOptions.LeaveHovered;
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_DYNAMICRESIZE:
				PopupOptions.DynamicResize = !PopupOptions.DynamicResize;
				EnableWindow(GetDlgItem(hwnd, IDC_USEMINIMUMWIDTH), PopupOptions.DynamicResize);
				EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH), PopupOptions.DynamicResize && PopupOptions.UseMinimumWidth);
				EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH_SPIN), PopupOptions.DynamicResize && PopupOptions.UseMinimumWidth);
				SetDlgItemText(hwnd, IDC_USEMAXIMUMWIDTH, PopupOptions.DynamicResize ? TranslateT("Maximum width") : TranslateT("Width"));
				if (!PopupOptions.DynamicResize) {
					PopupOptions.UseMaximumWidth = TRUE;
					CheckDlgButton(hwnd, IDC_USEMAXIMUMWIDTH, BST_CHECKED);
					EnableWindow(GetDlgItem(hwnd, IDC_USEMAXIMUMWIDTH), TRUE);
					EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH), TRUE);
					EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH_SPIN), TRUE);
				}
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_USEMINIMUMWIDTH:
				PopupOptions.UseMinimumWidth = !PopupOptions.UseMinimumWidth;
				EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH), PopupOptions.UseMinimumWidth);
				EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH_SPIN), PopupOptions.UseMinimumWidth);
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_USEMAXIMUMWIDTH:
				PopupOptions.UseMaximumWidth = Button_GetCheck((HWND)lParam);
				if (!PopupOptions.DynamicResize) { // ugly - set always on if DynamicResize = off
					CheckDlgButton(hwnd, LOWORD(wParam), BST_CHECKED);
					PopupOptions.UseMaximumWidth = TRUE;
				}
				EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH), PopupOptions.UseMaximumWidth);
				EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH_SPIN), PopupOptions.UseMaximumWidth);
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_CUSTOMPOS:
			{
				RECT rcButton, rcBox;
				HWND hwndBox = CreateDialog(hInst, MAKEINTRESOURCE(IDD_POSITION), NULL, PositionBoxDlgProc);
				GetWindowRect((HWND)lParam, &rcButton);
				GetWindowRect(hwndBox, &rcBox);
				MoveWindow(hwndBox,
					rcButton.right - (rcBox.right - rcBox.left) + 15,
					rcButton.bottom + 3,
					rcBox.right - rcBox.left,
					rcBox.bottom - rcBox.top,
					FALSE);

				SetWindowLongPtr(hwndBox, GWL_EXSTYLE, GetWindowLongPtr(hwndBox, GWL_EXSTYLE) | WS_EX_LAYERED);
				SetLayeredWindowAttributes(hwndBox, NULL, 0, LWA_ALPHA);
				ShowWindow(hwndBox, SW_SHOW);
				for (int i = 0; i <= 255; i += 15) {
					SetLayeredWindowAttributes(hwndBox, NULL, i, LWA_ALPHA);
					UpdateWindow(hwndBox);
					Sleep(1);
				}
				SetWindowLongPtr(hwndBox, GWL_EXSTYLE, GetWindowLongPtr(hwndBox, GWL_EXSTYLE) & ~WS_EX_LAYERED);

				ShowWindow(hwndBox, SW_SHOW);
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
			}
			break;

			case IDC_REORDERPOPUPS:
			{
				PopupOptions.ReorderPopups = !PopupOptions.ReorderPopups;
				PopupOptions.ReorderPopupsWarning = PopupOptions.ReorderPopups ? db_get_b(NULL, MODULNAME, "ReorderPopupsWarning", TRUE) : TRUE;
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
			}
			break;

			case IDC_POPUPENABLED:
			{
				int chk = IsDlgButtonChecked(hwnd, IDC_POPUPENABLED);
				if (PopupOptions.ModuleIsEnabled&&chk || !PopupOptions.ModuleIsEnabled && !chk)
					svcEnableDisableMenuCommand(0, 0);
				EnableWindow(GetDlgItem(hwnd, IDC_STATUSES), PopupOptions.ModuleIsEnabled);
				EnableWindow(GetDlgItem(hwnd, IDC_DISABLEINFS), PopupOptions.ModuleIsEnabled);
			}
			break;

			case IDC_DISABLEINFS:
				PopupOptions.DisableWhenFullscreen = !PopupOptions.DisableWhenFullscreen;
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_PREVIEW:
				PopupPreview();
				break;
			}
			break;

		case CBN_SELCHANGE:		// ComboBox controls
			switch (LOWORD(wParam)) {
				// lParam = Handle to the control
			case IDC_WHERE:
				PopupOptions.Position = ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;
			case IDC_LAYOUT:
				PopupOptions.Spreading = ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;
			}
			break;

		case EN_CHANGE:			// Edit controls change
			if (!bDlgInit) break;
			switch (LOWORD(wParam)) {
				// lParam = Handle to the control
			case IDC_SECONDS:
			{
				int seconds = GetDlgItemInt(hwnd, LOWORD(wParam), NULL, FALSE);
				if (seconds >= SETTING_LIFETIME_MIN &&
					seconds <= SETTING_LIFETIME_MAX &&
					seconds != PopupOptions.Seconds) {
					PopupOptions.Seconds = seconds;
					SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				}
			}
			break;
			case IDC_MINIMUMWIDTH:
			{
				int temp = GetDlgItemInt(hwnd, IDC_MINIMUMWIDTH, NULL, FALSE);
				if (temp >= SETTING_MINIMUMWIDTH_MIN &&
					temp <= SETTING_MAXIMUMWIDTH_MAX &&
					temp != PopupOptions.MinimumWidth) {
					PopupOptions.MinimumWidth = temp;
					SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				}
			}
			break;
			case IDC_MAXIMUMWIDTH:
			{
				int temp = GetDlgItemInt(hwnd, IDC_MAXIMUMWIDTH, NULL, FALSE);
				if (temp >= SETTING_MINIMUMWIDTH_MIN &&
					temp <= SETTING_MAXIMUMWIDTH_MAX &&
					temp != PopupOptions.MaximumWidth) {
					PopupOptions.MaximumWidth = temp;
					SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				}
			}
			break;
			}// end switch(idCtrl)
			break;

		case EN_KILLFOCUS:		// Edit controls lost fokus
			switch (LOWORD(wParam)) {
				// lParam = Handle to the control
			case IDC_SECONDS:
			{
				int seconds = GetDlgItemInt(hwnd, LOWORD(wParam), NULL, FALSE);
				if (seconds > SETTING_LIFETIME_MAX)
					PopupOptions.Seconds = SETTING_LIFETIME_MAX;
				else if (seconds < SETTING_LIFETIME_MIN)
					PopupOptions.Seconds = SETTING_LIFETIME_MIN;
				if (seconds != PopupOptions.Seconds) {
					SetDlgItemInt(hwnd, LOWORD(wParam), PopupOptions.Seconds, FALSE);
					ErrorMSG(SETTING_LIFETIME_MIN, SETTING_LIFETIME_MAX);
					SetFocus((HWND)lParam);
				}
			}
			break;
			case IDC_MINIMUMWIDTH:
			{
				int temp = GetDlgItemInt(hwnd, LOWORD(wParam), NULL, FALSE);
				if (temp < SETTING_MINIMUMWIDTH_MIN)
					PopupOptions.MinimumWidth = SETTING_MINIMUMWIDTH_MIN;
				else if (temp > SETTING_MAXIMUMWIDTH_MAX)
					PopupOptions.MinimumWidth = SETTING_MAXIMUMWIDTH_MAX;
				if (temp != PopupOptions.MinimumWidth) {
					SetDlgItemInt(hwnd, LOWORD(wParam), PopupOptions.MinimumWidth, FALSE);
					ErrorMSG(SETTING_MINIMUMWIDTH_MIN, SETTING_MAXIMUMWIDTH_MAX);
					SetFocus((HWND)lParam);
					break;
				}
				if (temp > PopupOptions.MaximumWidth) {
					PopupOptions.MaximumWidth = min(temp, SETTING_MAXIMUMWIDTH_MAX);
					SetDlgItemInt(hwnd, IDC_MAXIMUMWIDTH, PopupOptions.MaximumWidth, FALSE);
				}
			}
			break;
			case IDC_MAXIMUMWIDTH:
			{
				int temp = GetDlgItemInt(hwnd, LOWORD(wParam), NULL, FALSE);
				if (temp >= SETTING_MAXIMUMWIDTH_MAX)
					PopupOptions.MaximumWidth = SETTING_MAXIMUMWIDTH_MAX;
				else if (temp < SETTING_MINIMUMWIDTH_MIN)
					PopupOptions.MaximumWidth = SETTING_MINIMUMWIDTH_MIN;
				if (temp != PopupOptions.MaximumWidth) {
					SetDlgItemInt(hwnd, LOWORD(wParam), PopupOptions.MaximumWidth, FALSE);
					ErrorMSG(SETTING_MINIMUMWIDTH_MIN, SETTING_MAXIMUMWIDTH_MAX);
					SetFocus((HWND)lParam);
					break;
				}
				if (temp < PopupOptions.MinimumWidth) {
					PopupOptions.MinimumWidth = max(temp, SETTING_MINIMUMWIDTH_MIN);
					SetDlgItemInt(hwnd, IDC_MINIMUMWIDTH, PopupOptions.MinimumWidth, FALSE);
				}
			}
			break;
			}
			break;
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_RESET:
				LoadOption_General();
				return TRUE;

			case PSN_APPLY:
				// Seconds
				db_set_b(NULL, MODULNAME, "InfiniteDelay", PopupOptions.InfiniteDelay);
				db_set_w(NULL, MODULNAME, "Seconds", (WORD)PopupOptions.Seconds);
				db_set_b(NULL, MODULNAME, "LeaveHovered", PopupOptions.LeaveHovered);

				// Dynamic Resize
				db_set_b(NULL, MODULNAME, "DynamicResize", PopupOptions.DynamicResize);
				db_set_b(NULL, MODULNAME, "UseMinimumWidth", PopupOptions.UseMinimumWidth);
				db_set_w(NULL, MODULNAME, "MinimumWidth", PopupOptions.MinimumWidth);
				db_set_b(NULL, MODULNAME, "UseMaximumWidth", PopupOptions.UseMaximumWidth);
				db_set_w(NULL, MODULNAME, "MaximumWidth", PopupOptions.MaximumWidth);

				// Position
				db_set_b(NULL, MODULNAME, "Position", (BYTE)PopupOptions.Position);

				// Configure popup area
				db_set_w(NULL, MODULNAME, "gapTop", (WORD)PopupOptions.gapTop);
				db_set_w(NULL, MODULNAME, "gapBottom", (WORD)PopupOptions.gapBottom);
				db_set_w(NULL, MODULNAME, "gapLeft", (WORD)PopupOptions.gapLeft);
				db_set_w(NULL, MODULNAME, "gapRight", (WORD)PopupOptions.gapRight);
				db_set_w(NULL, MODULNAME, "spacing", (WORD)PopupOptions.spacing);

				// Spreading
				db_set_b(NULL, MODULNAME, "Spreading", (BYTE)PopupOptions.Spreading);

				// miscellaneous
				Check_ReorderPopups(hwnd);	// this save also PopupOptions.ReorderPopups

				// disable When
				db_set_b(NULL, MODULNAME, "DisableWhenFullscreen", PopupOptions.DisableWhenFullscreen);

				// new status options
				{
					int protocolCount;
					PROTOACCOUNT **protocols;
					Proto_EnumAccounts(&protocolCount, &protocols);

					for (int i = 0; i < protocolCount; ++i) {
						if (!protocols[i]->bIsVirtual) {
							char prefix[128];
							mir_snprintf(prefix, _countof(prefix), "Protocol Status/%s", protocols[i]->szModuleName);

							TCHAR pszSettingName[256];
							mir_sntprintf(pszSettingName, _countof(pszSettingName), _T("Protocol Status/%s"), protocols[i]->tszAccountName);
							db_set_dw(NULL, MODULNAME, prefix, OptTree_GetOptions(hwnd, IDC_STATUSES, statusOptions, statusOptionsCount, pszSettingName));
						}
					}
					db_set_dw(NULL, MODULNAME, "Global Status", OptTree_GetOptions(hwnd, IDC_STATUSES, statusOptions, statusOptionsCount, _T("Global Status")));
				}
				return TRUE;
			}
			break;

		case IDC_MINIMUMWIDTH_SPIN:
		{
			LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
			int temp = lpnmud->iPos + lpnmud->iDelta;
			if (temp > PopupOptions.MaximumWidth) {
				PopupOptions.MaximumWidth = min(temp, SETTING_MAXIMUMWIDTH_MAX);
				SetDlgItemInt(hwnd, IDC_MAXIMUMWIDTH, PopupOptions.MaximumWidth, FALSE);
			}
		}
		break;

		case IDC_MAXIMUMWIDTH_SPIN:
		{
			LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
			int temp = lpnmud->iPos + lpnmud->iDelta;
			if (temp < PopupOptions.MinimumWidth) {
				PopupOptions.MinimumWidth = max(temp, SETTING_MINIMUMWIDTH_MIN);
				SetDlgItemInt(hwnd, IDC_MINIMUMWIDTH, PopupOptions.MinimumWidth, FALSE);
			}
		}
		}
		break;

	case WM_DESTROY:
		if (statusOptions) {
			for (int i = 0; i < statusOptionsCount; ++i) {
				mir_free(statusOptions[i].pszOptionName);
				mir_free(statusOptions[i].pszSettingName);
			}
			delete[] statusOptions;
			statusOptions = NULL;
			statusOptionsCount = 0;
			bDlgInit = false;
		}
		break;
	}
	return FALSE;
}
Esempio n. 21
0
INT_PTR CALLBACK VKAccountProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	CVkProto *ppro = (CVkProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (uMsg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		ppro = (CVkProto*)lParam;
		SetWindowLongPtr( hwndDlg, GWLP_USERDATA, lParam );

		SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIconByHandle(ppro->m_hProtoIcon, true));
		SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIconByHandle(ppro->m_hProtoIcon));
		{
			ptrT tszLogin(ppro->getTStringA("Login"));
			if (tszLogin != NULL)
				SetDlgItemText(hwndDlg, IDC_LOGIN, tszLogin);

			ptrT tszPassw(ppro->GetUserStoredPassword());
			if (tszPassw != NULL)
				SetDlgItemText(hwndDlg, IDC_PASSWORD, tszPassw);
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_URL:
			CallService(MS_UTILS_OPENURL, 1, (LPARAM)"http://www.vk.com");
			break;

		case IDC_LOGIN:
		case IDC_PASSWORD:
			if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) {
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			}
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			TCHAR str[128];
			GetDlgItemText(hwndDlg, IDC_LOGIN, str, SIZEOF(str));
			ppro->setTString("Login", str);
			
			GetDlgItemText(hwndDlg, IDC_PASSWORD, str, SIZEOF(str));
			ptrA szRawPasswd( mir_utf8encodeT(str));
			if (szRawPasswd != NULL)
				ppro->setString("Password", szRawPasswd);
		}
		break;

	case WM_CLOSE:
		EndDialog(hwndDlg, 0);
		break;

	case WM_DESTROY:
		Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_GETICON, ICON_BIG, 0));
		Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_GETICON, ICON_SMALL, 0));
		break;
	}

	return FALSE;
}
Esempio n. 22
0
static INT_PTR CALLBACK FtMgrDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct TFtMgrData *dat = (struct TFtMgrData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);

	switch (msg)
	{
	case WM_INITDIALOG:
	{
		TCITEM tci = {0};
		HWND hwndTab = GetDlgItem(hwnd, IDC_TABS);

		TranslateDialogDefault(hwnd);
		Window_SetIcon_IcoLib(hwnd, SKINICON_EVENT_FILE);

		dat = (struct TFtMgrData *)mir_calloc(sizeof(struct TFtMgrData));

		SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat);

		dat->hhkPreshutdown = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwnd, M_PRESHUTDOWN);

		dat->hwndIncoming = CreateDialog(hMirandaInst, MAKEINTRESOURCE(IDD_FTPAGE), hwnd, FtMgrPageDlgProc);
		dat->hwndOutgoing = CreateDialog(hMirandaInst, MAKEINTRESOURCE(IDD_FTPAGE), hwnd, FtMgrPageDlgProc);
		ShowWindow(dat->hwndIncoming, SW_SHOW);

		tci.mask = TCIF_PARAM|TCIF_TEXT;
		tci.pszText = TranslateT("Incoming");
		tci.lParam = (LPARAM)dat->hwndIncoming;
		TabCtrl_InsertItem(hwndTab, 0, &tci);
		tci.pszText = TranslateT("Outgoing");
		tci.lParam = (LPARAM)dat->hwndOutgoing;
		TabCtrl_InsertItem(hwndTab, 1, &tci);

		// Utils_RestoreWindowPosition(hwnd, NULL, "SRFile", "FtMgrDlg_");
		SAVEWINDOWPOS swp;
		swp.hwnd=hwnd; swp.hContact=NULL; swp.szModule="SRFile"; swp.szNamePrefix="FtMgrDlg_";
		CallService(MS_UTILS_RESTOREWINDOWPOSITION, RWPF_NOACTIVATE, (LPARAM)&swp);

		// Fall through to setup initial placement
	}
	case WM_SIZE:
	{
		RECT rc, rcButton;
		HDWP hdwp;
		HWND hwndTab = GetDlgItem(hwnd, IDC_TABS);

		GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rcButton);
		OffsetRect(&rcButton, -rcButton.left, -rcButton.top);

		GetClientRect(hwnd, &rc);
		InflateRect(&rc, -6, -6);

		hdwp = BeginDeferWindowPos(3);

		hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDC_CLEAR), NULL, rc.left, rc.bottom-rcButton.bottom, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
		hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDCANCEL), NULL, rc.right-rcButton.right, rc.bottom-rcButton.bottom, 0, 0, SWP_NOZORDER|SWP_NOSIZE);

		rc.bottom -= rcButton.bottom + 5;

		hdwp = DeferWindowPos(hdwp, hwndTab, NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER);

		EndDeferWindowPos(hdwp);

		GetWindowRect(hwndTab, &rc);
		MapWindowPoints(NULL, hwnd, (LPPOINT)&rc, 2);
		TabCtrl_AdjustRect(hwndTab, FALSE, &rc);
		InflateRect(&rc, -5, -5);

		hdwp = BeginDeferWindowPos(2);

		hdwp = DeferWindowPos(hdwp, dat->hwndIncoming, HWND_TOP, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, 0);
		hdwp = DeferWindowPos(hdwp, dat->hwndOutgoing, HWND_TOP, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, 0);

		EndDeferWindowPos(hdwp);

		break;
	}

	case WM_MOUSEWHEEL:
	{
		if (IsWindowVisible(dat->hwndIncoming)) SendMessage(dat->hwndIncoming, msg, wParam, lParam);
		if (IsWindowVisible(dat->hwndOutgoing)) SendMessage(dat->hwndOutgoing, msg, wParam, lParam);
		break;
	}

	case WM_FT_SELECTPAGE:
	{
		TCITEM tci = {0};
		HWND hwndTab = GetDlgItem(hwnd, IDC_TABS);

		if (TabCtrl_GetCurSel(hwndTab) == (int)wParam) break;

		tci.mask = TCIF_PARAM;

		TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci);
		ShowWindow((HWND)tci.lParam, SW_HIDE);

		TabCtrl_SetCurSel(hwndTab, wParam);

		TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci);
		ShowWindow((HWND)tci.lParam, SW_SHOW);

		break;
	}

	case WM_GETMINMAXINFO:
	{
		LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
		lpmmi->ptMinTrackSize.x = 300;
		lpmmi->ptMinTrackSize.y = 400;
		return 0;
	}

	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
			case IDCANCEL:
				PostMessage(hwnd, WM_CLOSE , 0, 0);
				break;

			case IDC_CLEAR:
				PostMessage(dat->hwndIncoming, WM_FT_CLEANUP, 0, 0);
				PostMessage(dat->hwndOutgoing, WM_FT_CLEANUP, 0, 0);
				break;
		}
		break;

	case WM_NOTIFY:
	{
		switch (((LPNMHDR)lParam)->idFrom)
		{
		case IDC_TABS:
		{
			HWND hwndTab = GetDlgItem(hwnd, IDC_TABS);
			switch (((LPNMHDR)lParam)->code)
			{
			case TCN_SELCHANGING:
			{
				TCITEM tci = {0};
				tci.mask = TCIF_PARAM;
				TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci);
				ShowWindow((HWND)tci.lParam, SW_HIDE);
				break;
			}

			case TCN_SELCHANGE:
			{
				TCITEM tci = {0};
				tci.mask = TCIF_PARAM;
				TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci);
				ShowWindow((HWND)tci.lParam, SW_SHOW);
				break;
			}
			}
			break;
		}
		}
		break;
	}

	case M_PRESHUTDOWN:
		SendMessage(dat->hwndIncoming, M_PRESHUTDOWN, 0, 0);
		SendMessage(dat->hwndOutgoing, M_PRESHUTDOWN, 0, 0);
		DestroyWindow(hwnd);
		break;

	case WM_CLOSE:
		ShowWindow(hwnd, SW_HIDE);
		if (DBGetContactSettingByte(NULL, "SRFile", "AutoClear", 1)) {
			PostMessage(dat->hwndIncoming, WM_FT_CLEANUP, 0, 0);
			PostMessage(dat->hwndOutgoing, WM_FT_CLEANUP, 0, 0);
		}
		return TRUE; /* Disable default IDCANCEL notification */

	case WM_DESTROY:
		UnhookEvent(dat->hhkPreshutdown);
		Window_FreeIcon_IcoLib(hwnd);
		DestroyWindow(dat->hwndIncoming);
		DestroyWindow(dat->hwndOutgoing);
		mir_free(dat);
		SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
		Utils_SaveWindowPosition(hwnd, NULL, "SRFile", "FtMgrDlg_");
		break;

	case WM_ACTIVATE:
	{
		dat->errorState = TBPF_NOPROGRESS;
		wParam = 1;
	} break;
	case WM_SHOWWINDOW:
	{
		if (!wParam) // hiding
		{
			KillTimer(hwnd, 1);
			break;
		}
		lParam = 0;
	}
	case WM_TIMER:
	{
		if (pTaskbarInterface)
		{
			SetTimer(hwnd, 1, 400, NULL);
			if ((lParam == ACKRESULT_FAILED) || (lParam == ACKRESULT_DENIED))
				dat->errorState = TBPF_ERROR;

			TFtProgressData prg = {0};
			SendMessage(dat->hwndIncoming, M_CALCPROGRESS, (WPARAM)&prg, 0);
			SendMessage(dat->hwndOutgoing, M_CALCPROGRESS, (WPARAM)&prg, 0);
			if (dat->errorState)
			{
				pTaskbarInterface->SetProgressState(hwnd, dat->errorState);
				if (!prg.run)
					pTaskbarInterface->SetProgressValue(hwnd, 1, 1);
			} else if (prg.run) 
			{
				pTaskbarInterface->SetProgressState(hwnd, TBPF_NORMAL);
			} else if (prg.init || prg.scan)
			{
				pTaskbarInterface->SetProgressState(hwnd, TBPF_INDETERMINATE);
			} else {
				pTaskbarInterface->SetProgressState(hwnd, TBPF_NOPROGRESS);
				KillTimer(hwnd, 1);
			}

			if (prg.run)
			{
				pTaskbarInterface->SetProgressValue(hwnd, prg.totalProgress, prg.totalBytes);	
			}				

		}
	} break;

	}

	return FALSE;
}
Esempio n. 23
0
static INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	switch (uMsg) {
		case WM_INITDIALOG:
			{
				PROTO_INTERFACE* amui=(PROTO_INTERFACE*)lParam;
				LPSTR m_szModuleName=amui->m_szModuleName;
				CHAR szTemp[MAX_PATH];
				DBVARIANT dbv;
				HANDLE hContact=NULL;

				TranslateDialogDefault(hwndDlg);

				SetWindowLong(hwndDlg,GWL_USERDATA,lParam);

				if (!READC_S2(KEY_BOOTSTRAP,&dbv)) {
					SetDlgItemTextA(hwndDlg,IDC_LUAFILE,dbv.pszVal);
					DBFreeVariant(&dbv);
				} else 
					SetDlgItemTextA(hwndDlg,IDC_LUAFILE,VAL_BOOTSTRAP);

				if (!READC_S2(KEY_UIN,&dbv)) {
					SetDlgItemTextA(hwndDlg,IDC_UIN,dbv.pszVal);
					DBFreeVariant(&dbv);
				}

				SetDlgItemTextA(hwndDlg,IDC_PW,PASSWORDMASK);

				if (!READC_S2(KEY_RECEIVEGCIMAGES,&dbv)) {
					CheckDlgButton(hwndDlg, IDC_GCIMAGES, dbv.bVal==0?BST_UNCHECKED:BST_CHECKED);
					DBFreeVariant(&dbv);
				} else
					CheckDlgButton(hwndDlg, IDC_GCIMAGES, BST_CHECKED);

				WORD wValue;
				if ((wValue=READC_W2(KEY_SERVERPORT))!=0) {
					DBFreeVariant(&dbv);
				} else
					wValue=VAL_SERVERPORT;

				itoa(wValue,szTemp,10);
				SetDlgItemTextA(hwndDlg,IDC_PORT,szTemp);

				CheckDlgButton(hwndDlg, IDC_SHOWCONSOLE, READC_B2(KEY_SHOWCONSOLE)==0?BST_UNCHECKED:BST_CHECKED);
			}
			break;
		case WM_COMMAND:	// When a control is toggled
			switch (LOWORD(wParam)) {
				case IDC_LUAFILE:
				case IDC_UIN:
				case IDC_PW:
					if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
			}

			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;

		case WM_NOTIFY:		// When a notify is sent by Options Dialog (Property Sheet)
			if (((LPNMHDR)lParam)->code==PSN_APPLY) {
				PROTO_INTERFACE* amui=(PROTO_INTERFACE*)GetWindowLong(hwndDlg,GWL_USERDATA);
				LPSTR m_szModuleName=amui->m_szModuleName;
				CHAR szTemp[MAX_PATH];
				HANDLE hContact=NULL;
				DBVARIANT dbv;
				WORD wValue;

				GetDlgItemTextA(hwndDlg,IDC_LUAFILE,szTemp,MAX_PATH);

				if (!*szTemp) {
					MessageBox(hwndDlg,TranslateT("Bootstrap script not provided!"),NULL,MB_ICONERROR);
					// return PSNRET_INVALID;
				} else if (_access(szTemp,0)!=0) {
					MessageBox(hwndDlg,TranslateT("Bootstrap script inaccessible!"),NULL,MB_ICONERROR);
					// return PSNRET_INVALID;
				} else
					WRITEC_S(KEY_BOOTSTRAP,szTemp);

				GetDlgItemTextA(hwndDlg,IDC_UIN,szTemp,MAX_PATH);

				if (!*szTemp) {
					MessageBox(hwndDlg,TranslateT("UIN not provided!"),NULL,MB_ICONERROR);
					// return PSNRET_INVALID;
				} else
					WRITEC_S(KEY_UIN,szTemp);

				GetDlgItemTextA(hwndDlg,IDC_PW,szTemp,MAX_PATH);

				if (!*szTemp || strchr(szTemp,1)) {
					if (!READC_S2(KEY_PW,&dbv)) {
						DBFreeVariant(&dbv);
					} else {
						MessageBox(hwndDlg,TranslateT("Password not provided!"),NULL,MB_ICONERROR);
						// return PSNRET_INVALID;
					}
				} else {
					CallService(MS_DB_CRYPT_ENCODESTRING,sizeof(szTemp),(LPARAM)szTemp);
					WRITEC_S(KEY_PW,szTemp);
				}
				
				WRITEC_B(KEY_RECEIVEGCIMAGES, IsDlgButtonChecked(hwndDlg,IDC_GCIMAGES)?1:0);
				WRITEC_B(KEY_SHOWCONSOLE, IsDlgButtonChecked(hwndDlg,IDC_SHOWCONSOLE)?1:0);

				GetDlgItemTextA(hwndDlg,IDC_PORT,szTemp,MAX_PATH);
				wValue=atoi(szTemp);

				if (wValue==0) wValue=VAL_SERVERPORT;

				WRITEC_W(KEY_SERVERPORT, wValue);

				return PSNRET_NOERROR;
			}
			break;
	}
	return FALSE;
}
Esempio n. 24
0
INT_PTR CALLBACK DlgProcAlarm(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	WindowData *wd = (WindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		Utils_RestoreWindowPositionNoSize(hwndDlg, 0, MODULENAME, "Notify");
		SetFocus(GetDlgItem(hwndDlg, IDC_SNOOZE));

		wd = new WindowData;
		wd->moving = false;
		wd->alarm = nullptr;
		wd->win_num = win_num++;

		if (wd->win_num > 0) {
			RECT r;
			GetWindowRect(hwndDlg, &r);
			r.top += 20;
			r.left += 20;

			SetWindowPos(hwndDlg, nullptr, r.left, r.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
			Utils_SaveWindowPosition(hwndDlg, 0, MODULENAME, "Notify");
		}
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)wd);

		// options
		SendMessage(hwndDlg, WMU_SETOPT, 0, 0);

		// fonts
		SendMessage(hwndDlg, WMU_SETFONTS, 0, 0);
		return FALSE;

	case WMU_REFRESH:
		InvalidateRect(hwndDlg, nullptr, TRUE);
		return TRUE;

	case WM_CTLCOLORSTATIC:
		{
			HDC hdc = (HDC)wParam;
			HWND hwndCtrl = (HWND)lParam;

			if (hBackgroundBrush) {
				if (hTitleFont && GetDlgItem(hwndDlg, IDC_TITLE) == hwndCtrl)
					SetTextColor(hdc, title_font_colour);
				else if (hWindowFont)
					SetTextColor(hdc, window_font_colour);

				SetBkMode(hdc, TRANSPARENT);
				return (INT_PTR)hBackgroundBrush;
			}
		}
		break;

	case WM_CTLCOLORDLG:
		if (hBackgroundBrush)
			return (INT_PTR)hBackgroundBrush;
		break;

	case WMU_SETFONTS:
		// fonts
		if (hWindowFont)
			SendMessage(hwndDlg, WM_SETFONT, (WPARAM)hWindowFont, TRUE);
		if (hTitleFont)
			SendDlgItemMessage(hwndDlg, IDC_TITLE, WM_SETFONT, (WPARAM)hTitleFont, TRUE);

		if (hBackgroundBrush) {
			SetClassLongPtr(hwndDlg, GCLP_HBRBACKGROUND, (LONG_PTR)hBackgroundBrush);
			InvalidateRect(hwndDlg, nullptr, TRUE);
		}
		return TRUE;

	case WMU_SETOPT:
		Options *opt;
		if (lParam)
			opt = (Options*)lParam;
		else
			opt = &options;

		// round corners
		if (opt->aw_roundcorners) {
			HRGN hRgn1;
			RECT r;
			int w = 10;
			GetWindowRect(hwndDlg, &r);
			int h = (r.right - r.left) > (w * 2) ? w : (r.right - r.left);
			int v = (r.bottom - r.top) > (w * 2) ? w : (r.bottom - r.top);
			h = (h < v) ? h : v;
			hRgn1 = CreateRoundRectRgn(0, 0, (r.right - r.left + 1), (r.bottom - r.top + 1), h, h);
			SetWindowRgn(hwndDlg, hRgn1, 1);
		}
		else {
			HRGN hRgn1;
			RECT r;
			int w = 10;
			GetWindowRect(hwndDlg, &r);
			int h = (r.right - r.left) > (w * 2) ? w : (r.right - r.left);
			int v = (r.bottom - r.top) > (w * 2) ? w : (r.bottom - r.top);
			h = (h < v) ? h : v;
			hRgn1 = CreateRectRgn(0, 0, (r.right - r.left + 1), (r.bottom - r.top + 1));
			SetWindowRgn(hwndDlg, hRgn1, 1);
		}
		// transparency

		#ifdef WS_EX_LAYERED 
			SetWindowLongPtr(hwndDlg, GWL_EXSTYLE, GetWindowLongPtr(hwndDlg, GWL_EXSTYLE) | WS_EX_LAYERED);
		#endif
		#ifdef LWA_ALPHA
			SetLayeredWindowAttributes(hwndDlg, RGB(0, 0, 0), (int)((100 - opt->aw_trans) / 100.0 * 255), LWA_ALPHA);
		#endif
		return TRUE;

	case WMU_SETALARM:
		{
			ALARM *data = (ALARM *)lParam;
			SetWindowText(hwndDlg, data->szTitle);
			SetWindowText(GetDlgItem(hwndDlg, IDC_TITLE), data->szTitle);

			SetDlgItemText(hwndDlg, IDC_ED_DESC, data->szDesc);
			wd->alarm = data;

			if (data->action & AAF_SOUND && options.loop_sound) {
				if (data->sound_num <= 3)
					SetTimer(hwndDlg, ID_TIMER_SOUND, SOUND_REPEAT_PERIOD, nullptr);
				else if (data->sound_num == 4)
					SetTimer(hwndDlg, ID_TIMER_SOUND, SPEACH_REPEAT_PERIOD, nullptr);
			}

			HWND hw = GetDlgItem(hwndDlg, IDC_SNOOZE);
			EnableWindow(hw, !(data->flags & ALF_NOSNOOZE));
			ShowWindow(hw, (data->flags & ALF_NOSNOOZE) ? SW_HIDE : SW_SHOWNA);
		}
		return TRUE;

	case WMU_FAKEALARM:
		SetWindowText(hwndDlg, TranslateT("Example alarm"));
		SetDlgItemText(hwndDlg, IDC_TITLE, TranslateT("Example alarm"));
		SetDlgItemText(hwndDlg, IDC_ED_DESC, TranslateT("Some example text. Example, example, example."));
		return TRUE;

	case WM_TIMER:
		if (wParam == ID_TIMER_SOUND && wd) {
			ALARM *data = wd->alarm;
			if (data && data->action & AAF_SOUND) {
				if (data->sound_num <= 3) {
					char buff[128];
					mir_snprintf(buff, "Triggered%d", data->sound_num);
					Skin_PlaySound(buff);
				}
				else if (data->sound_num == 4) {
					if (data->szTitle != nullptr && data->szTitle[0] != '\0') {
						if (ServiceExists("Speak/Say")) {
							CallService("Speak/Say", 0, (LPARAM)data->szTitle);
						}
					}
				}
			}
		}
		return TRUE;

	case WM_MOVE:
		Utils_SaveWindowPosition(hwndDlg, 0, MODULENAME, "Notify");
		break;

	case WMU_ADDSNOOZER:
		if (wd) {
			ALARM *data = wd->alarm;
			if (data) {
				// add snooze minutes to current time
				FILETIME ft;
				GetLocalTime(&data->time);
				SystemTimeToFileTime(&data->time, &ft);

				ULARGE_INTEGER uli;
				uli.LowPart = ft.dwLowDateTime;
				uli.HighPart = ft.dwHighDateTime;

				// there are 10000000 100-nanosecond blocks in a second...
				uli.QuadPart += mult.QuadPart * (int)(wParam);

				ft.dwHighDateTime = uli.HighPart;
				ft.dwLowDateTime = uli.LowPart;

				FileTimeToSystemTime(&ft, &data->time);

				data->occurrence = OC_ONCE;
				data->snoozer = true;
				data->flags = data->flags & ~ALF_NOSTARTUP;

				data->id = next_alarm_id++;

				append_to_list(data);
			}
		}
		return TRUE;

	case WM_COMMAND:
		if (HIWORD(wParam) == BN_CLICKED) {
			switch (LOWORD(wParam)) {
			case IDCANCEL:  // no button - esc pressed
			case IDOK:		// space?
			case IDC_SNOOZE:
				SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)options.snooze_minutes, 0);
				//drop through

			case IDC_DISMISS:
				KillTimer(hwndDlg, ID_TIMER_SOUND);
				if (wd) {
					if (wd->alarm) {
						free_alarm_data(wd->alarm);
						delete wd->alarm;
					}
					delete wd;
				}
				SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);

				win_num--;
				WindowList_Remove(hAlarmWindowList, hwndDlg);
				DestroyWindow(hwndDlg);
				break;

			case IDC_SNOOZELIST:
				POINT pt, pt_rel;
				GetCursorPos(&pt);
				pt_rel = pt;
				ScreenToClient(hwndDlg, &pt_rel);

				HMENU hMenu = CreatePopupMenu();
				MENUITEMINFO mii = { 0 };
				mii.cbSize = sizeof(mii);
				mii.fMask = MIIM_ID | MIIM_STRING;

				#define AddItem(x) \
					mii.wID++; \
					mii.dwTypeData = TranslateW(x); \
					mii.cch = ( UINT )mir_wstrlen(mii.dwTypeData); \
					InsertMenuItem(hMenu, mii.wID, FALSE, &mii);

				AddItem(LPGENW("5 mins"));
				AddItem(LPGENW("15 mins"));
				AddItem(LPGENW("30 mins"));
				AddItem(LPGENW("1 hour"));
				AddItem(LPGENW("1 day"));
				AddItem(LPGENW("1 week"));

				TPMPARAMS tpmp = { 0 };
				tpmp.cbSize = sizeof(tpmp);
				LRESULT ret = (LRESULT)TrackPopupMenuEx(hMenu, TPM_RETURNCMD, pt.x, pt.y, hwndDlg, &tpmp);
				switch (ret) {
					case 0: DestroyMenu(hMenu); return 0; // dismis menu
					case 1: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)5, 0); break;
					case 2: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)15, 0); break;
					case 3: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)30, 0); break;
					case 4: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)60, 0); break;
					case 5: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)(60 * 24), 0); break;
					case 6: SendMessage(hwndDlg, WMU_ADDSNOOZER, (WPARAM)(60 * 24 * 7), 0); break;
				}

				DestroyMenu(hMenu);

				SendMessage(hwndDlg, WM_COMMAND, IDC_DISMISS, 0);
				break;
			}
		}
		return TRUE;

	case WM_MOUSEMOVE:
		if (wParam & MK_LBUTTON) {
			SetCapture(hwndDlg);

			POINT newp;
			newp.x = (short)LOWORD(lParam);
			newp.y = (short)HIWORD(lParam);
			ClientToScreen(hwndDlg, &newp);

			if (!wd->moving)
				wd->moving = true;
			else {
				RECT r;
				GetWindowRect(hwndDlg, &r);

				SetWindowPos(hwndDlg, nullptr, r.left + (newp.x - wd->p.x), r.top + (newp.y - wd->p.y), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
			}
			wd->p.x = newp.x;
			wd->p.y = newp.y;
		}
		else {
			ReleaseCapture();
			wd->moving = false;
		}
		return TRUE;
	}

	return FALSE;
}
Esempio n. 25
0
INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam)
{	
	switch(msg) {
	case WM_INITDIALOG:
		{
			int startupmode,exitmode;
			COMBOBOXINFO cbi={0};
			cbi.cbSize = sizeof(cbi);

			opses_count=0;
			g_opHdlg=hdlg;
			bOptionsInit=TRUE;
			TranslateDialogDefault(hdlg);
			hMarked = Skin_GetIconByHandle(iconList[1].hIcolib);
			hNotMarked = Skin_GetIconByHandle(iconList[2].hIcolib);

			hIcon=(bChecked=IsMarkedUserDefSession(opses_count))?hMarked:hNotMarked;

			SetDlgItemInt(hdlg, IDC_TRACK,ses_limit=db_get_b(0, MODNAME, "TrackCount", 10), FALSE);
			SendDlgItemMessage(hdlg, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(10, 1));
			SendDlgItemMessage(hdlg, IDC_SPIN1, UDM_SETPOS, 0, GetDlgItemInt(hdlg, IDC_TRACK, NULL, FALSE));

			SendDlgItemMessage(hdlg, IDC_OPCLIST, LB_RESETCONTENT, 0, 0);
			SetDlgItemInt(hdlg, IDC_STARTDELAY, db_get_w(NULL, MODNAME, "StartupModeDelay", 1500), FALSE);
			startupmode = db_get_b(NULL, MODNAME, "StartupMode", 3);
			exitmode = db_get_b(NULL, MODNAME, "ShutdownMode", 2);

			g_bExclHidden = db_get_b(NULL, MODNAME, "ExclHidden", 0);
			g_bWarnOnHidden = db_get_b(NULL, MODNAME, "WarnOnHidden", 0);
			g_bOtherWarnings = db_get_b(NULL, MODNAME, "OtherWarnings", 1);
			g_bCrashRecovery = db_get_b(NULL, MODNAME, "CrashRecovery", 0);

			CheckDlgButton(hdlg,IDC_EXCLHIDDEN,g_bExclHidden?BST_CHECKED:BST_UNCHECKED);
			CheckDlgButton(hdlg,IDC_LASTHIDDENWARN,g_bWarnOnHidden?BST_CHECKED:BST_UNCHECKED);
			CheckDlgButton(hdlg,IDC_WARNINGS,g_bOtherWarnings?BST_CHECKED:BST_UNCHECKED);
			CheckDlgButton(hdlg,IDC_CRASHRECOVERY,g_bCrashRecovery?BST_CHECKED:BST_UNCHECKED);


			if (startupmode == 1)
				CheckDlgButton(hdlg,IDC_STARTDIALOG,BST_CHECKED);
			else if (startupmode == 3) {
				CheckDlgButton(hdlg,IDC_STARTDIALOG,BST_CHECKED);
				CheckDlgButton(hdlg,IDC_CHECKLAST,BST_CHECKED);
			}
			else if (startupmode == 2) {
				CheckDlgButton(hdlg,IDC_RLOADLAST,BST_CHECKED);
				EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), FALSE);
			}
			else if (startupmode == 0)	{
				CheckDlgButton(hdlg,IDC_RNOTHING,BST_CHECKED);
				EnableWindow(GetDlgItem(hdlg, IDC_STARTDELAY), FALSE);
				EnableWindow(GetDlgItem(hdlg, IDC_STATICOP), FALSE);
				EnableWindow(GetDlgItem(hdlg, IDC_STATICMS), FALSE);
				EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), FALSE);
			}

			if (exitmode == 0) {
				CheckDlgButton(hdlg,IDC_REXDSAVE,BST_CHECKED);
				EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC1),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC2),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_TRACK),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_SPIN1),FALSE);
			}
			else if (exitmode == 1)
				CheckDlgButton(hdlg,IDC_REXASK,BST_CHECKED);
			else if (exitmode == 2)
				CheckDlgButton(hdlg,IDC_REXSAVE,BST_CHECKED);

			LoadSessionToCombobox (hdlg,1,255,"UserSessionDsc",0);
			if (SendDlgItemMessage(hdlg, IDC_LIST, CB_GETCOUNT, 0, 0)) {
				EnableWindow(GetDlgItem(hdlg,IDC_EDIT),TRUE);
				SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
				if (!OpLoadSessionContacts(0,opses_count))
					EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE);
			}

			GetComboBoxInfo(GetDlgItem(hdlg,IDC_LIST),&cbi);
			mir_subclassWindow(cbi.hwndItem, ComboBoxSubclassProc);

			hComboBoxEdit=cbi.hwndItem;
			hComboBox=cbi.hwndCombo;

			SetWindowPos( hComboBoxEdit, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED );

			bOptionsInit=FALSE;
		}
		break;

	case WM_CTLCOLORLISTBOX:
		switch(GetDlgCtrlID((HWND) lparam)) {
		case IDC_OPCLIST:
			SetBkMode((HDC) wparam, TRANSPARENT);
			return (BOOL) CreateSolidBrush(GetSysColor(COLOR_3DFACE));
		}
		break;

	case WM_NOTIFY:
		switch(((LPNMHDR)lparam)->code) {
		case PSN_APPLY:
			{
				int iDelay=GetDlgItemInt(hdlg, IDC_STARTDELAY,NULL, FALSE);
				db_set_w(0, MODNAME, "StartupModeDelay", (WORD)iDelay);
				db_set_b(0, MODNAME, "TrackCount", (BYTE)(ses_limit=GetDlgItemInt(hdlg, IDC_TRACK,NULL, FALSE)));
				if (IsDlgButtonChecked(hdlg, IDC_REXSAVE))
					db_set_b(NULL, MODNAME, "ShutdownMode", 2);
				else if (IsDlgButtonChecked(hdlg, IDC_REXDSAVE))
					db_set_b(NULL, MODNAME, "ShutdownMode", 0);
				else if (IsDlgButtonChecked(hdlg, IDC_REXASK))
					db_set_b(NULL, MODNAME, "ShutdownMode", 1);

				if (IsDlgButtonChecked(hdlg, IDC_STARTDIALOG)) {
					if (!IsDlgButtonChecked(hdlg, IDC_CHECKLAST))
						db_set_b(NULL, MODNAME, "StartupMode", 1);
					else
						db_set_b(NULL, MODNAME, "StartupMode", 3);
				}
				else if (IsDlgButtonChecked(hdlg, IDC_RLOADLAST))
					db_set_b(NULL, MODNAME, "StartupMode", 2);
				else if (IsDlgButtonChecked(hdlg, IDC_RNOTHING))
					db_set_b(NULL, MODNAME, "StartupMode", 0);

				db_set_b(NULL, MODNAME, "ExclHidden", (BYTE)(IsDlgButtonChecked(hdlg, IDC_EXCLHIDDEN) ? (g_bExclHidden = 1) : (g_bExclHidden = 0)));
				db_set_b(NULL, MODNAME, "WarnOnHidden", (BYTE)(IsDlgButtonChecked(hdlg, IDC_LASTHIDDENWARN) ? (g_bWarnOnHidden = 1) : (g_bWarnOnHidden = 0)));
				db_set_b(NULL, MODNAME, "OtherWarnings", (BYTE)(IsDlgButtonChecked(hdlg, IDC_WARNINGS) ? (g_bOtherWarnings = 1) : (g_bOtherWarnings = 0)));
				db_set_b(NULL, MODNAME, "CrashRecovery", (BYTE)(IsDlgButtonChecked(hdlg, IDC_CRASHRECOVERY) ? (g_bCrashRecovery = 1) : (g_bCrashRecovery = 0)));
			}
			return 1;

		case CLN_CHECKCHANGED:
			if (((LPNMHDR)lparam)->idFrom  == IDC_EMCLIST)
			{
				int iSelection = (int)((NMCLISTCONTROL *)lparam)->hItem;
				MCONTACT hContact = db_find_first();
				for ( ; hContact; hContact = db_find_next(hContact))
					if (SendDlgItemMessage(hdlg, IDC_EMCLIST, CLM_FINDCONTACT, hContact, 0) == iSelection)
						break;
				if (hContact)
					EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE);
				else
					EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE);
			}
		}
		break;

	case WM_COMMAND:
		switch(LOWORD(wparam)) {
		case IDC_LIST:
			switch(HIWORD(wparam)) {
			case CBN_EDITCHANGE:
				EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE);
				bSesssionNameChanged=TRUE;
				break;

			case CBN_SELCHANGE:
				{
					HWND hCombo = GetDlgItem(hdlg, IDC_LIST);
					int index = SendMessage(hCombo, CB_GETCURSEL, 0, 0);
					if (index != CB_ERR) {
						opses_count = SendMessage(hCombo, CB_GETITEMDATA, (WPARAM)index, 0);
						SendDlgItemMessage(hdlg, IDC_OPCLIST, LB_RESETCONTENT, 0, 0);
						if (IsMarkedUserDefSession(opses_count)) {
							hIcon=hMarked;
							bChecked=TRUE;
							RedrawWindow(hComboBoxEdit, NULL, NULL, RDW_INVALIDATE|RDW_NOCHILDREN|RDW_UPDATENOW|RDW_FRAME);
						}
						else {
							hIcon=hNotMarked;
							bChecked=FALSE;
							RedrawWindow(hComboBoxEdit, NULL, NULL, RDW_INVALIDATE|RDW_NOCHILDREN|RDW_UPDATENOW|RDW_FRAME);
						}
						OpLoadSessionContacts(0,opses_count);
						if (!hOpClistControl)
							EnableWindow(GetDlgItem(hdlg,IDC_DEL),TRUE);
						else {
							for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
								SendMessage(hOpClistControl, CLM_SETCHECKMARK, hContact,0);

							for (int i=0 ; session_list_t[i] > 0; i++) {
								MCONTACT hContact = (MCONTACT)SendMessage(hOpClistControl, CLM_FINDCONTACT, (WPARAM)session_list_t[i], 0);
								SendMessage(hOpClistControl, CLM_SETCHECKMARK, hContact, 1);
							}
							EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE);
						}
					}
				}break;
			}break;

		case IDC_EDIT:
			if (!hOpClistControl) {
				ShowWindow(GetDlgItem(hdlg,IDC_OPCLIST),SW_HIDE);
				EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE);
				//EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE);
				SetWindowText(GetDlgItem(hdlg,IDC_EDIT),TranslateT("View"));
				hOpClistControl = CreateWindowEx(WS_EX_STATICEDGE, _T(CLISTCONTROL_CLASS), _T(""),
					WS_TABSTOP |WS_VISIBLE | WS_CHILD , 
					14,198,161,163,hdlg, (HMENU)IDC_EMCLIST, hinstance, 0);

				SetWindowLongPtr(hOpClistControl, GWL_STYLE,
					GetWindowLongPtr(hOpClistControl, GWL_STYLE)|CLS_CHECKBOXES|CLS_HIDEEMPTYGROUPS|CLS_USEGROUPS|CLS_GREYALTERNATE|CLS_GROUPCHECKBOXES);
				SendMessage(hOpClistControl, CLM_SETEXSTYLE, CLS_EX_DISABLEDRAGDROP|CLS_EX_TRACKSELECT, 0);

				SendMessage(hOpClistControl,WM_TIMER,TIMERID_REBUILDAFTER,0);

				for (int i=0 ; session_list_t[i] > 0; i++) {
					HANDLE hItem=(HANDLE)SendMessage(hOpClistControl,CLM_FINDCONTACT, (WPARAM)session_list_t[i], 0);
					SendMessage(hOpClistControl, CLM_SETCHECKMARK, (WPARAM)hItem,1);
				}
			}
			else {
				ShowWindow(GetDlgItem(hdlg,IDC_OPCLIST),SW_SHOWNA);
				EnableWindow(GetDlgItem(hdlg,IDC_DEL),TRUE);
				EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE);
				SetWindowText(GetDlgItem(hdlg,IDC_EDIT),TranslateT("Edit"));
				DestroyWindow(hOpClistControl);
				hOpClistControl=NULL;
			}
			break;

		case IDC_SAVE:
			{
				int i=0;
				for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
					BYTE res =(BYTE)SendMessage(GetDlgItem(hdlg,IDC_EMCLIST), CLM_GETCHECKMARK,
						SendMessage(GetDlgItem(hdlg,IDC_EMCLIST), CLM_FINDCONTACT, hContact, 0), 0);
					if (res) {
						SetSessionMark(hContact,1,'1',opses_count);
						SetInSessionOrder(hContact,1,opses_count,i);
						i++;
					}
					else {
						SetSessionMark(hContact,1,'0',opses_count);
						SetInSessionOrder(hContact,1,opses_count,0);
					}
				}
				if (bSesssionNameChanged) {
					if (GetWindowTextLength(hComboBoxEdit)) {
						TCHAR szUserSessionName[MAX_PATH]={'\0'};
						GetWindowText(hComboBoxEdit, szUserSessionName, SIZEOF(szUserSessionName));
						RenameUserDefSession(opses_count,szUserSessionName);
						SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT ,0,0);
						LoadSessionToCombobox (hdlg,1,255,"UserSessionDsc",0);
					}
					bSesssionNameChanged=FALSE;
				}
				EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE);
			}
			break;

		case IDC_DEL:
			DelUserDefSession(opses_count);

			SendDlgItemMessage(hdlg, IDC_OPCLIST, LB_RESETCONTENT, 0, 0);
			SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0);

			LoadSessionToCombobox (hdlg,1,255,"UserSessionDsc",0);

			opses_count=0;

			if (SendDlgItemMessage(hdlg, IDC_LIST, CB_GETCOUNT, 0, 0)) {
				EnableWindow(GetDlgItem(hdlg,IDC_EDIT),TRUE);
				SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
				if (!OpLoadSessionContacts(0,opses_count))
					EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE);
			}
			else {
				EnableWindow(GetDlgItem(hdlg,IDC_EDIT),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE);
			}
			break;

		case IDC_STARTDIALOG:
			EnableWindow(GetDlgItem(hdlg, IDC_STARTDELAY), TRUE);
			EnableWindow(GetDlgItem(hdlg, IDC_STATICOP), TRUE);
			EnableWindow(GetDlgItem(hdlg, IDC_STATICMS), TRUE);
			EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), TRUE);
			SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
			break;

		case IDC_RLOADLAST:
			EnableWindow(GetDlgItem(hdlg, IDC_STARTDELAY), TRUE);
			EnableWindow(GetDlgItem(hdlg, IDC_STATICOP), TRUE);
			EnableWindow(GetDlgItem(hdlg, IDC_STATICMS), TRUE);
			EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), FALSE);
			SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
			break;

		case IDC_RNOTHING:
			EnableWindow(GetDlgItem(hdlg, IDC_STARTDELAY), FALSE);
			EnableWindow(GetDlgItem(hdlg, IDC_STATICOP), FALSE);
			EnableWindow(GetDlgItem(hdlg, IDC_STATICMS), FALSE);
			EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), FALSE);
			SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
			break;

		case IDC_REXSAVE:
			EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC1),TRUE);
			EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC2),TRUE);
			EnableWindow(GetDlgItem(hdlg,IDC_TRACK),TRUE);
			EnableWindow(GetDlgItem(hdlg,IDC_SPIN1),TRUE);
			SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
			break;

		case IDC_REXDSAVE:
			EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC1),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC2),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_TRACK),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_SPIN1),FALSE);
			SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
			break;

		case IDC_REXASK:
			EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC1),TRUE);
			EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC2),TRUE);
			EnableWindow(GetDlgItem(hdlg,IDC_TRACK),TRUE);
			EnableWindow(GetDlgItem(hdlg,IDC_SPIN1),TRUE);
			SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
			break;
		}

		if (HIWORD(wparam) == CBN_DROPDOWN&&!hOpClistControl) {
			SendMessage(hComboBoxEdit,EM_SETSEL ,0,0);
			SendMessage(hComboBoxEdit,EM_SCROLLCARET ,0,0);
			SendMessage(hComboBoxEdit,WM_KILLFOCUS ,0,0);
			HideCaret(hComboBoxEdit);
		}

		if ((HIWORD(wparam)!=CBN_DROPDOWN)&&(LOWORD(wparam) == IDC_LIST)&&!hOpClistControl) {
			SendMessage(hComboBoxEdit,EM_SCROLLCARET ,0,0);
			HideCaret(hComboBoxEdit);
		}

		if ((LOWORD(wparam) == IDC_STARTDELAY) && (HIWORD(wparam)!=EN_CHANGE || (HWND)lparam != GetFocus()))
			return 0;

		if (lparam&&!bOptionsInit&&(HIWORD(wparam) == BN_CLICKED)&& (GetFocus() == (HWND)lparam)
			&&((LOWORD(wparam) == IDC_CHECKLAST)||((LOWORD(wparam)>=IDC_EXCLHIDDEN)&&(LOWORD(wparam)<=IDC_CRASHRECOVERY))))
			SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);

		return 0;

	case WM_CLOSE:
		EndDialog(hdlg,0);
		return 0;
	}
	return 0;
}
Esempio n. 26
0
static INT_PTR CALLBACK OptionsDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	OptionsPageData *opd;
	OptionsDlgData *dat = (OptionsDlgData*)GetWindowLongPtr(hdlg, GWLP_USERDATA);
	HWND hwndTree = GetDlgItem(hdlg, IDC_PAGETREE);

	switch (message) {
	case WM_CTLCOLORSTATIC:
		switch (GetDlgCtrlID((HWND)lParam)) {
		case IDC_WHITERECT:
		case IDC_KEYWORD_FILTER:
			SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
			return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
		}
		break;

	case WM_INITDIALOG:
		TranslateDialogDefault(hdlg);

		if (!ServiceExists(MS_MODERNOPT_SHOW))
			ShowWindow(GetDlgItem(hdlg, IDC_MODERN), FALSE);

		dat = new OptionsDlgData;
		SetWindowLongPtr(hdlg, GWLP_USERDATA, (LONG_PTR)dat);

		Utils_RestoreWindowPositionNoSize(hdlg, NULL, "Options", "");
		Window_SetIcon_IcoLib(hdlg, SKINICON_OTHER_OPTIONS);
		EnableWindow(GetDlgItem(hdlg, IDC_APPLY), FALSE);
		{
			COMBOBOXINFO cbi;
			cbi.cbSize = sizeof(COMBOBOXINFO);
			GetComboBoxInfo(GetDlgItem(hdlg, IDC_KEYWORD_FILTER), &cbi);
			mir_subclassWindow(cbi.hwndItem, OptionsFilterSubclassProc);

			if (IsAeroMode()) {
				mir_subclassWindow(cbi.hwndCombo, AeroPaintSubclassProc);
				mir_subclassWindow(cbi.hwndItem, AeroPaintSubclassProc);
			}

			PROPSHEETHEADER *psh = (PROPSHEETHEADER*)lParam;
			SetWindowText(hdlg, psh->pszCaption);

			LOGFONT lf;
			dat->hBoldFont = (HFONT)SendDlgItemMessage(hdlg, IDC_APPLY, WM_GETFONT, 0, 0);
			GetObject(dat->hBoldFont, sizeof(lf), &lf);
			lf.lfWeight = FW_BOLD;
			dat->hBoldFont = CreateFontIndirect(&lf);

			dat->hPluginLoad = HookEventMessage(ME_SYSTEM_MODULELOAD, hdlg, HM_MODULELOAD);
			dat->hPluginUnload = HookEventMessage(ME_SYSTEM_MODULEUNLOAD, hdlg, HM_MODULEUNLOAD);
			dat->currentPage = -1;

			ptrT lastPage, lastGroup, lastTab;
			OPENOPTIONSDIALOG *ood = (OPENOPTIONSDIALOG*)psh->pStartPage;
			if (ood->pszPage == NULL) {
				lastPage = db_get_tsa(NULL, "Options", "LastPage");

				if (ood->pszGroup == NULL)
					lastGroup = db_get_tsa(NULL, "Options", "LastGroup");
				else
					lastGroup = mir_a2t(ood->pszGroup);
			}
			else {
				lastPage = mir_a2t(ood->pszPage);
				lastGroup = mir_a2t(ood->pszGroup);
			}

			if (ood->pszTab == NULL)
				lastTab = db_get_tsa(NULL, "Options", "LastTab");
			else
				lastTab = mir_a2t(ood->pszTab);

			OPTIONSDIALOGPAGE *odp = (OPTIONSDIALOGPAGE*)psh->ppsp;
			for (UINT i = 0; i < psh->nPages; i++, odp++) {
				opd = new OptionsPageData(odp);
				if (opd->pDialog == NULL) // smth went wrong
					delete opd;
				else
					dat->arOpd.insert(opd);

				if (!mir_tstrcmp(lastPage, odp->ptszTitle) && !mir_tstrcmp(lastGroup, odp->ptszGroup))
					if ((ood->pszTab == NULL && dat->currentPage == -1) || !mir_tstrcmp(lastTab, odp->ptszTab))
						dat->currentPage = (int)i;
			}

			GetWindowRect(GetDlgItem(hdlg, IDC_STNOPAGE), &dat->rcDisplay);
			MapWindowPoints(NULL, hdlg, (LPPOINT)&dat->rcDisplay, 2);

			// Add an item to count in height
			TCITEM tie;
			tie.mask = TCIF_TEXT | TCIF_IMAGE;
			tie.iImage = -1;
			tie.pszText = _T("X");
			TabCtrl_InsertItem(GetDlgItem(hdlg, IDC_TAB), 0, &tie);

			GetWindowRect(GetDlgItem(hdlg, IDC_TAB), &dat->rcTab);
			MapWindowPoints(NULL, hdlg, (LPPOINT)&dat->rcTab, 2);
			TabCtrl_AdjustRect(GetDlgItem(hdlg, IDC_TAB), FALSE, &dat->rcTab);

			FillFilterCombo(hdlg, dat);
			PostMessage(hdlg, DM_REBUILDPAGETREE, 0, 0);
		}
		return TRUE;

	case DM_REBUILDPAGETREE:
		RebuildPageTree(hdlg, dat);
		break;

	case HM_MODULELOAD:
		LoadOptionsModule(hdlg, dat, (HINSTANCE)lParam);
		break;

	case HM_MODULEUNLOAD:
		UnloadOptionsModule(hdlg, dat, (HINSTANCE)lParam);
		break;

	case PSM_CHANGED:
		EnableWindow(GetDlgItem(hdlg, IDC_APPLY), TRUE);

		opd = dat->getCurrent();
		if (opd)
			opd->changed = 1;

		return TRUE;

	case PSM_GETBOLDFONT:
		SetWindowLongPtr(hdlg, DWLP_MSGRESULT, (LONG_PTR)dat->hBoldFont);
		return TRUE;

	case WM_NOTIFY:
		switch (wParam) {
		case IDC_TAB:
		case IDC_PAGETREE:
			switch (((LPNMHDR)lParam)->code) {
			case TVN_ITEMEXPANDING:
				SetWindowLongPtr(hdlg, DWLP_MSGRESULT, FALSE);
				return TRUE;

			case TCN_SELCHANGING:
			case TVN_SELCHANGING:
				opd = dat->getCurrent();
				if (opd && opd->getHwnd() != NULL) {
					PSHNOTIFY pshn;
					pshn.hdr.code = PSN_KILLACTIVE;
					pshn.hdr.hwndFrom = dat->arOpd[dat->currentPage]->getHwnd();
					pshn.hdr.idFrom = 0;
					pshn.lParam = 0;
					if (SendMessage(dat->arOpd[dat->currentPage]->getHwnd(), WM_NOTIFY, 0, (LPARAM)&pshn)) {
						SetWindowLongPtr(hdlg, DWLP_MSGRESULT, TRUE);
						return TRUE;
					}
				}
				break;

			case TCN_SELCHANGE:
			case TVN_SELCHANGED:
				ShowWindow(GetDlgItem(hdlg, IDC_STNOPAGE), SW_HIDE);

				opd = dat->getCurrent();
				if (opd && opd->getHwnd() != NULL)
					ShowWindow(opd->getHwnd(), SW_HIDE);

				if (wParam != IDC_TAB) {
					TVITEM tvi;
					tvi.hItem = dat->hCurrentPage = TreeView_GetSelection(hwndTree);
					if (tvi.hItem == NULL) {
						ShowWindow(GetDlgItem(hdlg, IDC_TAB), SW_HIDE);
						break;
					}

					tvi.mask = TVIF_HANDLE | TVIF_PARAM;
					TreeView_GetItem(hwndTree, &tvi);
					dat->currentPage = tvi.lParam;
					ShowWindow(GetDlgItem(hdlg, IDC_TAB), SW_HIDE);
				}
				else {
					TCITEM tie;
					tie.mask = TCIF_PARAM;
					TabCtrl_GetItem(GetDlgItem(hdlg, IDC_TAB), TabCtrl_GetCurSel(GetDlgItem(hdlg, IDC_TAB)), &tie);
					dat->currentPage = tie.lParam;

					TVITEM tvi;
					tvi.hItem = dat->hCurrentPage;
					tvi.mask = TVIF_PARAM;
					tvi.lParam = dat->currentPage;
					TreeView_SetItem(hwndTree, &tvi);
				}

				opd = dat->getCurrent();
				if (opd == NULL) {
					ShowWindow(GetDlgItem(hdlg, IDC_STNOPAGE), SW_SHOW);
					break;
				}
				if (opd->getHwnd() == NULL) {
					CreateOptionWindow(opd, hdlg);
					if (opd->flags & ODPF_BOLDGROUPS)
						EnumChildWindows(opd->getHwnd(), BoldGroupTitlesEnumChildren, (LPARAM)dat->hBoldFont);

					RECT rcPage;
					GetClientRect(opd->getHwnd(), &rcPage);
					int w = opd->width = rcPage.right;
					int h = opd->height = rcPage.bottom;

					RECT rc;
					GetWindowRect(opd->getHwnd(), &rc);

					opd->insideTab = IsInsideTab(hdlg, dat, dat->currentPage);
					if (opd->insideTab) {
						SetWindowPos(opd->getHwnd(), HWND_TOP, (dat->rcTab.left + dat->rcTab.right - w) >> 1, dat->rcTab.top, w, h, 0);
						ThemeDialogBackground(opd->getHwnd(), TRUE);
					}
					else {
						SetWindowPos(opd->getHwnd(), HWND_TOP, (dat->rcDisplay.left + dat->rcDisplay.right - w) >> 1, (dat->rcDisplay.top + dat->rcDisplay.bottom - h) >> 1, w, h, 0);
						ThemeDialogBackground(opd->getHwnd(), FALSE);
					}
				}

				if (wParam != IDC_TAB) {
					opd->insideTab = IsInsideTab(hdlg, dat, dat->currentPage);
					if (opd->insideTab) {
						// Make tabbed pane
						int pages = 0, sel = 0;
						HWND hwndTab = GetDlgItem(hdlg, IDC_TAB);
						TabCtrl_DeleteAllItems(hwndTab);

						TCITEM tie;
						tie.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM;
						tie.iImage = -1;
						for (int i = 0; i < dat->arOpd.getCount(); i++) {
							if (!CheckPageShow(hdlg, dat, i))
								continue;

							OptionsPageData *p = dat->arOpd[i];
							if (mir_tstrcmp(opd->ptszTitle, p->ptszTitle) || mir_tstrcmp(opd->ptszGroup, p->ptszGroup))
								continue;

							tie.pszText = TranslateTH(p->hLangpack, p->ptszTab);
							tie.lParam = i;
							TabCtrl_InsertItem(hwndTab, pages, &tie);
							if (!mir_tstrcmp(opd->ptszTab, p->ptszTab))
								sel = pages;
							pages++;
						}
						TabCtrl_SetCurSel(hwndTab, sel);
						ShowWindow(hwndTab, opd->insideTab ? SW_SHOW : SW_HIDE);
					}

					ThemeDialogBackground(opd->getHwnd(), opd->insideTab);
				}

				ShowWindow(opd->getHwnd(), SW_SHOW);
				if (((LPNMTREEVIEW)lParam)->action == TVC_BYMOUSE)
					PostMessage(hdlg, DM_FOCUSPAGE, 0, 0);
				else
					SetFocus(hwndTree);
			}
Esempio n. 27
0
////////////////////////////////////////////////////////////////////////////////////////////
// Proc: General options dialog
static INT_PTR CALLBACK gg_genoptsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	GGPROTO *gg = (GGPROTO *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		{
			DBVARIANT dbv;
			DWORD num;
			GGPROTO *gg = (GGPROTO *)lParam;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);

			TranslateDialogDefault(hwndDlg);
			if (num = gg->getDword(GG_KEY_UIN, 0))
			{
				SetDlgItemTextA(hwndDlg, IDC_UIN, ditoa(num));
				ShowWindow(GetDlgItem(hwndDlg, IDC_CREATEACCOUNT), SW_HIDE);
			}
			else
			{
				ShowWindow(GetDlgItem(hwndDlg, IDC_CHPASS), SW_HIDE);
				ShowWindow(GetDlgItem(hwndDlg, IDC_REMOVEACCOUNT), SW_HIDE);
				ShowWindow(GetDlgItem(hwndDlg, IDC_LOSTPASS), SW_HIDE);
			}
			if (!gg->getString(GG_KEY_PASSWORD, &dbv)) {
				SetDlgItemTextA(hwndDlg, IDC_PASSWORD, dbv.pszVal);
				db_free(&dbv);
			}
			if (!gg->getString(GG_KEY_EMAIL, &dbv)) {
				SetDlgItemTextA(hwndDlg, IDC_EMAIL, dbv.pszVal);
				db_free(&dbv);
			}
			else
			{
				ShowWindow(GetDlgItem(hwndDlg, IDC_LOSTPASS), SW_HIDE);
				ShowWindow(GetDlgItem(hwndDlg, IDC_CHPASS), SW_HIDE);
			}

			CheckDlgButton(hwndDlg, IDC_FRIENDSONLY, gg->getByte(GG_KEY_FRIENDSONLY, GG_KEYDEF_FRIENDSONLY) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_SHOWINVISIBLE, gg->getByte(GG_KEY_SHOWINVISIBLE, GG_KEYDEF_SHOWINVISIBLE) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_LEAVESTATUSMSG, gg->getByte(GG_KEY_LEAVESTATUSMSG, GG_KEYDEF_LEAVESTATUSMSG) ? BST_CHECKED : BST_UNCHECKED);
			if (gg->gc_enabled)
				CheckDlgButton(hwndDlg, IDC_IGNORECONF, gg->getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF) ? BST_CHECKED : BST_UNCHECKED);
			else
			{
				EnableWindow(GetDlgItem(hwndDlg, IDC_IGNORECONF), FALSE);
				CheckDlgButton(hwndDlg, IDC_IGNORECONF, BST_CHECKED);
			}
			CheckDlgButton(hwndDlg, IDC_IMGRECEIVE, gg->getByte(GG_KEY_IMGRECEIVE, GG_KEYDEF_IMGRECEIVE) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_SHOWLINKS, gg->getByte(GG_KEY_SHOWLINKS, GG_KEYDEF_SHOWLINKS) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_ENABLEAVATARS, gg->getByte(GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS) ? BST_CHECKED : BST_UNCHECKED);

			EnableWindow(GetDlgItem(hwndDlg, IDC_LEAVESTATUS), IsDlgButtonChecked(hwndDlg, IDC_LEAVESTATUSMSG));
			EnableWindow(GetDlgItem(hwndDlg, IDC_IMGMETHOD), IsDlgButtonChecked(hwndDlg, IDC_IMGRECEIVE));
			SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)TranslateT("<Last Status>"));	// 0
			SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_ONLINE, 0));
			SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_AWAY, 0));
			SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_DND, 0));
			SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_FREECHAT, 0));
			SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_INVISIBLE, 0));
			switch(gg->getWord(GG_KEY_LEAVESTATUS, GG_KEYDEF_LEAVESTATUS)) {
			case ID_STATUS_ONLINE:
				SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 1, 0);
				break;
			case ID_STATUS_AWAY:
				SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 2, 0);
				break;
			case ID_STATUS_DND:
				SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 3, 0);
				break;
			case ID_STATUS_FREECHAT:
				SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 4, 0);
				break;
			case ID_STATUS_INVISIBLE:
				SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 5, 0);
				break;
			default:
				SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 0, 0);
			}

			SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_ADDSTRING, 0, (LPARAM)TranslateT("System tray icon"));
			SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_ADDSTRING, 0, (LPARAM)TranslateT("Popup window"));
			SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_ADDSTRING, 0, (LPARAM)TranslateT("Message with [img] BBCode"));
			SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_SETCURSEL, gg->getByte(GG_KEY_IMGMETHOD, GG_KEYDEF_IMGMETHOD), 0);
		}
		break;

	case WM_COMMAND:
		if ((LOWORD(wParam) == IDC_UIN || LOWORD(wParam) == IDC_PASSWORD || LOWORD(wParam) == IDC_EMAIL)
			&& (HIWORD(wParam) != EN_CHANGE || (HWND) lParam != GetFocus()))
			return 0;

		switch (LOWORD(wParam)) {
		case IDC_EMAIL:
		case IDC_UIN:
			gg_optsdlgcheck(hwndDlg);
			break;

		case IDC_LEAVESTATUSMSG:
			EnableWindow(GetDlgItem(hwndDlg, IDC_LEAVESTATUS), IsDlgButtonChecked(hwndDlg, IDC_LEAVESTATUSMSG));
			break;

		case IDC_IMGRECEIVE:
			EnableWindow(GetDlgItem(hwndDlg, IDC_IMGMETHOD), IsDlgButtonChecked(hwndDlg, IDC_IMGRECEIVE));
			break;

		case IDC_LOSTPASS:
			{
				char email[128];
				uin_t uin;
				GetDlgItemTextA(hwndDlg, IDC_UIN, email, _countof(email));
				uin = atoi(email);
				GetDlgItemTextA(hwndDlg, IDC_EMAIL, email, _countof(email));
				if (!mir_strlen(email))
					MessageBox(NULL, TranslateT("You need to specify your registration e-mail first."),
					gg->m_tszUserName, MB_OK | MB_ICONEXCLAMATION);
				else if (MessageBox(NULL,
					TranslateT("Your password will be sent to your registration e-mail.\nDo you want to continue?"),
					gg->m_tszUserName,
					MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
					gg->remindpassword(uin, email);
				return FALSE;
			}
		case IDC_CREATEACCOUNT:
		case IDC_REMOVEACCOUNT:
			if (gg->isonline())
			{
				if (MessageBox(
					NULL,
					TranslateT("You should disconnect before making any permanent changes with your account.\nDo you want to disconnect now?"),
					gg->m_tszUserName,
					MB_OKCANCEL | MB_ICONEXCLAMATION) == IDCANCEL)
					break;
				else
					gg->disconnect();
			}
		case IDC_CHPASS:
		case IDC_CHEMAIL:
			{
				// Readup data
				GGUSERUTILDLGDATA dat;
				int ret;
				char pass[128], email[128];
				GetDlgItemTextA(hwndDlg, IDC_UIN, pass, _countof(pass));
				dat.uin = atoi(pass);
				GetDlgItemTextA(hwndDlg, IDC_PASSWORD, pass, _countof(pass));
				GetDlgItemTextA(hwndDlg, IDC_EMAIL, email, _countof(email));
				dat.pass = pass;
				dat.email = email;
				dat.gg = gg;
				if (LOWORD(wParam) == IDC_CREATEACCOUNT)
				{
					dat.mode = GG_USERUTIL_CREATE;
					ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CREATEACCOUNT), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
				}
				else if (LOWORD(wParam) == IDC_CHPASS)
				{
					dat.mode = GG_USERUTIL_PASS;
					ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHPASS), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
				}
				else if (LOWORD(wParam) == IDC_CHEMAIL)
				{
					dat.mode = GG_USERUTIL_EMAIL;
					ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHEMAIL), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
				}
				else
				{
					dat.mode = GG_USERUTIL_REMOVE;
					ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_REMOVEACCOUNT), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
				}

				if (ret == IDOK)
				{
					DBVARIANT dbv;
					DWORD num;
					// Show reload required window
					ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);

					// Update uin
					if (num = gg->getDword(GG_KEY_UIN, 0))
						SetDlgItemTextA(hwndDlg, IDC_UIN, ditoa(num));
					else
						SetDlgItemTextA(hwndDlg, IDC_UIN, "");

					// Update password
					if (!gg->getString(GG_KEY_PASSWORD, &dbv)) {
						SetDlgItemTextA(hwndDlg, IDC_PASSWORD, dbv.pszVal);
						db_free(&dbv);
					}
					else SetDlgItemTextA(hwndDlg, IDC_PASSWORD, "");

					// Update e-mail
					if (!gg->getString(GG_KEY_EMAIL, &dbv)) {
						SetDlgItemTextA(hwndDlg, IDC_EMAIL, dbv.pszVal);
						db_free(&dbv);
					}
					else SetDlgItemTextA(hwndDlg, IDC_EMAIL, "");

					// Update links
					gg_optsdlgcheck(hwndDlg);

					// Remove details
					if (LOWORD(wParam) != IDC_CHPASS && LOWORD(wParam) != IDC_CHEMAIL)
					{
						gg->delSetting(GG_KEY_NICK);
						gg->delSetting(GG_KEY_PD_NICKNAME);
						gg->delSetting(GG_KEY_PD_CITY);
						gg->delSetting(GG_KEY_PD_FIRSTNAME);
						gg->delSetting(GG_KEY_PD_LASTNAME);
						gg->delSetting(GG_KEY_PD_FAMILYNAME);
						gg->delSetting(GG_KEY_PD_FAMILYCITY	);
						gg->delSetting(GG_KEY_PD_AGE);
						gg->delSetting(GG_KEY_PD_BIRTHYEAR);
						gg->delSetting(GG_KEY_PD_GANDER);
					}
				}
			}
			break;
		}
		SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR) lParam)->code) {
		case PSN_APPLY:
			int status_flags = GG_STATUS_FLAG_UNKNOWN;
			char str[128];
			uin_t uin;

			// Write Gadu-Gadu number & password
			GetDlgItemTextA(hwndDlg, IDC_UIN, str, _countof(str));
			uin = atoi(str);
			GetDlgItemTextA(hwndDlg, IDC_PASSWORD, str, _countof(str));
			gg->checknewuser(uin, str);
			gg->setDword(GG_KEY_UIN, uin);
			gg->setString(GG_KEY_PASSWORD, str);

			// Write Gadu-Gadu email
			GetDlgItemTextA(hwndDlg, IDC_EMAIL, str, _countof(str));
			gg->setString(GG_KEY_EMAIL, str);

			// Write checkboxes
			gg->setByte(GG_KEY_FRIENDSONLY, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_FRIENDSONLY));
			gg->setByte(GG_KEY_SHOWINVISIBLE, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_SHOWINVISIBLE));
			gg->setByte(GG_KEY_LEAVESTATUSMSG, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_LEAVESTATUSMSG));
			if (gg->gc_enabled)
				gg->setByte(GG_KEY_IGNORECONF, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_IGNORECONF));
			gg->setByte(GG_KEY_IMGRECEIVE, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_IMGRECEIVE));
			gg->setByte(GG_KEY_SHOWLINKS, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_SHOWLINKS));
			if (IsDlgButtonChecked(hwndDlg, IDC_SHOWLINKS))
				status_flags |= GG_STATUS_FLAG_SPAM;
			gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_genoptsdlgproc", 34, "sess_mutex", 1);
			gg_change_status_flags(gg->sess, status_flags);
			gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_genoptsdlgproc", 34, 1, "sess_mutex", 1);
			gg->setByte(GG_KEY_ENABLEAVATARS, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_ENABLEAVATARS));

			gg->setByte(GG_KEY_IMGMETHOD, (BYTE)SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_GETCURSEL, 0, 0));

			// Write leave status
			switch(SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_GETCURSEL, 0, 0)) {
			case 1:
				gg->setWord(GG_KEY_LEAVESTATUS, ID_STATUS_ONLINE);
				break;
			case 2:
				gg->setWord(GG_KEY_LEAVESTATUS, ID_STATUS_AWAY);
				break;
			case 3:
				gg->setWord(GG_KEY_LEAVESTATUS, ID_STATUS_DND);
				break;
			case 4:
				gg->setWord(GG_KEY_LEAVESTATUS, ID_STATUS_FREECHAT);
				break;
			case 5:
				gg->setWord(GG_KEY_LEAVESTATUS, ID_STATUS_INVISIBLE);
				break;
			default:
				gg->setWord(GG_KEY_LEAVESTATUS, GG_KEYDEF_LEAVESTATUS);
			}
		}
		break;
	}
	return FALSE;
}
Esempio n. 28
0
INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct FileDlgData *dat;

	dat=(struct FileDlgData*)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
	switch (msg) {
	case WM_INITDIALOG: {
		TCHAR *contactName;
		TCHAR szPath[450];
		CLISTEVENT* cle = (CLISTEVENT*)lParam;

		TranslateDialogDefault(hwndDlg);

		dat=(struct FileDlgData*)mir_calloc(sizeof(struct FileDlgData));
		SetWindowLongPtr(hwndDlg,GWLP_USERDATA,(LONG_PTR)dat);
		dat->hContact = cle->hContact;
		dat->hDbEvent = cle->hDbEvent;
		dat->hPreshutdownEvent = HookEventMessage(ME_SYSTEM_PRESHUTDOWN,hwndDlg,M_PRESHUTDOWN);
		dat->dwTicks = GetTickCount();

		EnumChildWindows(hwndDlg,ClipSiblingsChildEnumProc,0);

		Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_FILE);
		Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add Contact Permanently to List"));
		Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View User's Details"));
		Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View User's History"));
		Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User Menu"));

		contactName = cli.pfnGetContactDisplayName( dat->hContact, 0 );
		SetDlgItemText(hwndDlg,IDC_FROM,contactName);
		GetContactReceivedFilesDir(dat->hContact,szPath,SIZEOF(szPath),TRUE);
		SetDlgItemText(hwndDlg,IDC_FILEDIR,szPath);
		{
			int i;
			char idstr[32];
			DBVARIANT dbv;

			if (shAutoComplete)
				shAutoComplete(GetWindow(GetDlgItem(hwndDlg,IDC_FILEDIR),GW_CHILD),1);

			for(i=0;i<MAX_MRU_DIRS;i++) {
				mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d",i);
				if(DBGetContactSettingTString(NULL,"SRFile",idstr,&dbv)) break;
				SendDlgItemMessage(hwndDlg,IDC_FILEDIR,CB_ADDSTRING,0,(LPARAM)dbv.ptszVal);
				DBFreeVariant(&dbv);
			}
		}

		CallService(MS_DB_EVENT_MARKREAD,(WPARAM)dat->hContact,(LPARAM)dat->hDbEvent);
		{
			DBEVENTINFO dbei={0};
			TCHAR datetimestr[64];
			char buf[540];

			dbei.cbSize=sizeof(dbei);
			dbei.cbBlob=CallService(MS_DB_EVENT_GETBLOBSIZE,(WPARAM)dat->hDbEvent,0);
			dbei.pBlob=(PBYTE)mir_alloc(dbei.cbBlob);
			CallService(MS_DB_EVENT_GET,(WPARAM)dat->hDbEvent,(LPARAM)&dbei);
			dat->fs = cle->lParam ? (HANDLE)cle->lParam : (HANDLE)*(PDWORD)dbei.pBlob;
			lstrcpynA(buf, (char*)dbei.pBlob+4, min(dbei.cbBlob+1,SIZEOF(buf)));
			TCHAR* ptszFileName = DbGetEventStringT( &dbei, buf );
			SetDlgItemText(hwndDlg,IDC_FILENAMES,ptszFileName);
			mir_free(ptszFileName);
			lstrcpynA(buf, (char*)dbei.pBlob+4+strlen((char*)dbei.pBlob+4)+1, min((int)(dbei.cbBlob-4-strlen((char*)dbei.pBlob+4)),SIZEOF(buf)));
			TCHAR* ptszDescription = DbGetEventStringT( &dbei, buf );
			SetDlgItemText(hwndDlg,IDC_MSG,ptszDescription);
			mir_free(ptszDescription);
			mir_free(dbei.pBlob);

			tmi.printTimeStamp(NULL, dbei.timestamp, _T("t d"), datetimestr, SIZEOF(datetimestr), 0);
			SetDlgItemText(hwndDlg, IDC_DATE, datetimestr);
		}
		{
			char* szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)dat->hContact, 0);
			if (szProto) {
				CONTACTINFO ci;
				int hasName = 0;
				char buf[128];
				ZeroMemory(&ci,sizeof(ci));

				ci.cbSize = sizeof(ci);
				ci.hContact = dat->hContact;
				ci.szProto = szProto;
				ci.dwFlag = CNF_UNIQUEID;
				if (!CallService(MS_CONTACT_GETCONTACTINFO,0,(LPARAM)&ci)) {
					switch(ci.type) {
					case CNFT_ASCIIZ:
						hasName = 1;
						mir_snprintf(buf, SIZEOF(buf), "%s", ci.pszVal);
						mir_free(ci.pszVal);
						break;
					case CNFT_DWORD:
						hasName = 1;
						mir_snprintf(buf, SIZEOF(buf),"%u",ci.dVal);
						break;
				}	}
				if (hasName)
					SetDlgItemTextA(hwndDlg, IDC_NAME, buf );
				else
					SetDlgItemText(hwndDlg, IDC_NAME, contactName);
		}	}

		if(DBGetContactSettingByte(dat->hContact,"CList","NotOnList",0)) {
			RECT rcBtn1,rcBtn2,rcDateCtrl;
			GetWindowRect(GetDlgItem(hwndDlg,IDC_ADD),&rcBtn1);
			GetWindowRect(GetDlgItem(hwndDlg,IDC_USERMENU),&rcBtn2);
			GetWindowRect(GetDlgItem(hwndDlg,IDC_DATE),&rcDateCtrl);
			SetWindowPos(GetDlgItem(hwndDlg,IDC_DATE),0,0,0,rcDateCtrl.right-rcDateCtrl.left-(rcBtn2.left-rcBtn1.left),rcDateCtrl.bottom-rcDateCtrl.top,SWP_NOZORDER|SWP_NOMOVE);
		}
		else if(DBGetContactSettingByte(NULL,"SRFile","AutoAccept",0)) {
			//don't check auto-min here to fix BUG#647620
			PostMessage(hwndDlg,WM_COMMAND,MAKEWPARAM(IDOK,BN_CLICKED),(LPARAM)GetDlgItem(hwndDlg,IDOK));
		}
		if(!DBGetContactSettingByte(dat->hContact,"CList","NotOnList",0))
			ShowWindow(GetDlgItem(hwndDlg, IDC_ADD),SW_HIDE);
		return TRUE;
	}

	case WM_MEASUREITEM:
		return CallService(MS_CLIST_MENUMEASUREITEM,wParam,lParam);

	case WM_DRAWITEM:
		{	LPDRAWITEMSTRUCT dis=(LPDRAWITEMSTRUCT)lParam;
			if(dis->hwndItem==GetDlgItem(hwndDlg, IDC_PROTOCOL)) {
				char *szProto;

				szProto=(char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)dat->hContact,0);
				if (szProto) {
					HICON hIcon;

					hIcon=(HICON)CallProtoService(szProto,PS_LOADICON,PLI_PROTOCOL|PLIF_SMALL,0);
					if (hIcon) {
						DrawIconEx(dis->hDC,dis->rcItem.left,dis->rcItem.top,hIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0,NULL,DI_NORMAL);
						DestroyIcon(hIcon);
		}	}	}	}
		return CallService(MS_CLIST_MENUDRAWITEM,wParam,lParam);

	case WM_COMMAND:
		if ( CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam),MPCF_CONTACTMENU), (LPARAM)dat->hContact ))
			break;

		switch ( LOWORD( wParam )) {
		case IDC_FILEDIRBROWSE:
			{
				TCHAR szDirName[MAX_PATH],szExistingDirName[MAX_PATH];

				GetDlgItemText(hwndDlg,IDC_FILEDIR,szDirName,SIZEOF(szDirName));
				GetLowestExistingDirName(szDirName,szExistingDirName,SIZEOF(szExistingDirName));
				if(BrowseForFolder(hwndDlg,szExistingDirName))
					SetDlgItemText(hwndDlg,IDC_FILEDIR,szExistingDirName);
			}
            break;

		case IDOK:
			{	//most recently used directories
				TCHAR szRecvDir[MAX_PATH],szDefaultRecvDir[MAX_PATH];
				GetDlgItemText(hwndDlg,IDC_FILEDIR,szRecvDir,SIZEOF(szRecvDir));
				RemoveInvalidPathChars(szRecvDir);
				GetContactReceivedFilesDir(NULL,szDefaultRecvDir,SIZEOF(szDefaultRecvDir),TRUE);
				if(_tcsnicmp(szRecvDir,szDefaultRecvDir,lstrlen(szDefaultRecvDir))) {
					char idstr[32];
					int i;
					DBVARIANT dbv;
					for(i=MAX_MRU_DIRS-2;i>=0;i--) {
						mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d",i);
						if(DBGetContactSettingTString(NULL,"SRFile",idstr,&dbv)) continue;
						mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d",i+1);
						DBWriteContactSettingTString(NULL,"SRFile",idstr,dbv.ptszVal);
						DBFreeVariant(&dbv);
					}
					DBWriteContactSettingTString(NULL,"SRFile",idstr,szRecvDir);
				}
			}
			EnableWindow(GetDlgItem(hwndDlg,IDC_FILENAMES),FALSE);
			EnableWindow(GetDlgItem(hwndDlg,IDC_MSG),FALSE);
			EnableWindow(GetDlgItem(hwndDlg,IDC_FILEDIR),FALSE);
			EnableWindow(GetDlgItem(hwndDlg,IDC_FILEDIRBROWSE),FALSE);

			GetDlgItemText(hwndDlg,IDC_FILEDIR,dat->szSavePath,SIZEOF(dat->szSavePath));
			GetDlgItemText(hwndDlg,IDC_FILE,dat->szFilenames,SIZEOF(dat->szFilenames));
			GetDlgItemText(hwndDlg,IDC_MSG,dat->szMsg,SIZEOF(dat->szMsg));
			dat->hwndTransfer = FtMgr_AddTransfer(dat);
			SetWindowLongPtr( hwndDlg, GWLP_USERDATA, 0);
			//check for auto-minimize here to fix BUG#647620
			if(DBGetContactSettingByte(NULL,"SRFile","AutoAccept",0) && DBGetContactSettingByte(NULL,"SRFile","AutoMin",0)) {
				ShowWindow(hwndDlg,SW_HIDE);
				ShowWindow(hwndDlg,SW_SHOWMINNOACTIVE);
			}
			DestroyWindow(hwndDlg);
            break;

		case IDCANCEL:
			if (dat->fs) CallContactService(dat->hContact,PSS_FILEDENYT,(WPARAM)dat->fs,(LPARAM)TranslateT("Cancelled"));
			dat->fs=NULL; /* the protocol will free the handle */
			DestroyWindow(hwndDlg);
            break;

		case IDC_ADD:
			{	ADDCONTACTSTRUCT acs={0};

				acs.handle=dat->hContact;
				acs.handleType=HANDLE_CONTACT;
				acs.szProto="";
				CallService(MS_ADDCONTACT_SHOW,(WPARAM)hwndDlg,(LPARAM)&acs);
				if(!DBGetContactSettingByte(dat->hContact,"CList","NotOnList",0))
					ShowWindow(GetDlgItem(hwndDlg,IDC_ADD), SW_HIDE);
			}
            break;

		case IDC_USERMENU:
			{	RECT rc;
				HMENU hMenu=(HMENU)CallService(MS_CLIST_MENUBUILDCONTACT,(WPARAM)dat->hContact,0);
				GetWindowRect((HWND)lParam,&rc);
				TrackPopupMenu(hMenu,0,rc.left,rc.bottom,0,hwndDlg,NULL);
				DestroyMenu(hMenu);
			}
			break;

		case IDC_DETAILS:
			CallService(MS_USERINFO_SHOWDIALOG,(WPARAM)dat->hContact,0);
            break;

		case IDC_HISTORY:
			CallService(MS_HISTORY_SHOWCONTACTHISTORY,(WPARAM)dat->hContact,0);
            break;
		}
		break;

	case WM_DESTROY:
		Window_FreeIcon_IcoLib(hwndDlg);
		Button_FreeIcon_IcoLib(hwndDlg,IDC_ADD);
		Button_FreeIcon_IcoLib(hwndDlg,IDC_DETAILS);
		Button_FreeIcon_IcoLib(hwndDlg,IDC_HISTORY);
		Button_FreeIcon_IcoLib(hwndDlg,IDC_USERMENU);

		if ( dat ) FreeFileDlgData( dat );
        break;
	}
	return FALSE;
}
Esempio n. 29
0
////////////////////////////////////////////////////////////////////////////////
// Info Page : Proc
// lParam: 0 if current user (account owner) details, hContact if on list user details
static INT_PTR CALLBACK gg_detailsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct GGDETAILSDLGDATA *dat = (struct GGDETAILSDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch(msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		dat = (struct GGDETAILSDLGDATA *)mir_alloc(sizeof(struct GGDETAILSDLGDATA));
		dat->hContact = lParam;
		dat->disableUpdate = FALSE;
		dat->updating = FALSE;
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
		// Add genders
		if (!dat->hContact)
		{
			SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)_T(""));				// 0
			SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)TranslateT("Female"));	// 1
			SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)TranslateT("Male"));	// 2
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_PARAMCHANGED:
				dat->gg = (GGPROTO *)((LPPSHNOTIFY)lParam)->lParam;
				break;

			case PSN_INFOCHANGED:
				{
					MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
					GGPROTO *gg = dat->gg;
					if (!dat)
						break;

					// Show updated message
					if (dat->updating)
					{
						MessageBox(NULL, TranslateT("Your details has been uploaded to the public directory."),
							gg->m_tszUserName, MB_OK | MB_ICONINFORMATION);
						dat->updating = FALSE;
						break;
					}

					char *szProto = (hContact == NULL) ? gg->m_szModuleName : GetContactProto(hContact);
					if (szProto == NULL)
						break;

					// Disable when updating
					dat->disableUpdate = TRUE;

					SetValue(hwndDlg, IDC_UIN, hContact, szProto, GG_KEY_UIN, 0, hContact != NULL);
					SetValue(hwndDlg, IDC_REALIP, hContact, szProto, GG_KEY_CLIENTIP, SVS_IP, hContact != NULL);
					SetValue(hwndDlg, IDC_PORT, hContact, szProto, GG_KEY_CLIENTPORT, SVS_ZEROISUNSPEC, hContact != NULL);
					SetValue(hwndDlg, IDC_VERSION, hContact, szProto, GG_KEY_CLIENTVERSION, SVS_GGVERSION, hContact != NULL);

					SetValue(hwndDlg, IDC_FIRSTNAME, hContact, szProto, GG_KEY_PD_FIRSTNAME, SVS_NORMAL, hContact != NULL);
					SetValue(hwndDlg, IDC_LASTNAME, hContact, szProto, GG_KEY_PD_LASTNAME, SVS_NORMAL, hContact != NULL);
					SetValue(hwndDlg, IDC_NICKNAME, hContact, szProto, GG_KEY_PD_NICKNAME, SVS_NORMAL, hContact != NULL);
					SetValue(hwndDlg, IDC_BIRTHYEAR, hContact, szProto, GG_KEY_PD_BIRTHYEAR, SVS_ZEROISUNSPEC, hContact != NULL);
					SetValue(hwndDlg, IDC_CITY, hContact, szProto, GG_KEY_PD_CITY, SVS_NORMAL, hContact != NULL);
					SetValue(hwndDlg, IDC_FAMILYNAME, hContact, szProto, GG_KEY_PD_FAMILYNAME, SVS_NORMAL, hContact != NULL);
					SetValue(hwndDlg, IDC_CITYORIGIN, hContact, szProto, GG_KEY_PD_FAMILYCITY	, SVS_NORMAL, hContact != NULL);

					if (hContact)
					{
						SetValue(hwndDlg, IDC_GENDER, hContact, szProto, GG_KEY_PD_GANDER, SVS_GENDER, hContact != NULL);
						SetValue(hwndDlg, IDC_STATUSDESCR, hContact, "CList", GG_KEY_STATUSDESCR, SVS_NORMAL, hContact != NULL);
					}
					else switch((char)db_get_b(hContact, gg->m_szModuleName, GG_KEY_PD_GANDER, (BYTE)'?')) {
					case 'F':
						SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 1, 0);
						break;
					case 'M':
						SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 2, 0);
						break;
					default:
						SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 0, 0);
					}

					// Disable when updating
					dat->disableUpdate = FALSE;
					break;
				}
			}
			break;
		}
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			SendMessage(GetParent(hwndDlg),msg,wParam,lParam);
			break;
		case IDC_NICKNAME:
		case IDC_FIRSTNAME:
		case IDC_LASTNAME:
		case IDC_FAMILYNAME:
		case IDC_CITY:
		case IDC_CITYORIGIN:
		case IDC_BIRTHYEAR:
			if (HIWORD(wParam) == EN_CHANGE) {
				if (!dat || dat->hContact || dat->disableUpdate)
					break;
				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), TRUE);
				break;
			}
		case IDC_GENDER:
			if (HIWORD(wParam) == CBN_SELCHANGE) {
				if (!dat || dat->hContact || dat->disableUpdate)
					break;
				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), TRUE);
				break;
			}
		case IDC_SAVE: // Save current user data
			if (HIWORD(wParam) == BN_CLICKED) {
				if (!dat || dat->hContact || dat->disableUpdate)
					break;
				{
				TCHAR text[256];
				GGPROTO *gg = dat->gg;

				if (!gg->isonline())
				{
					MessageBox(NULL,
						TranslateT("You have to be logged in before you can change your details."),
						gg->m_tszUserName, MB_OK | MB_ICONSTOP);
					break;
				}

				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), FALSE);

				gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_WRITE);

				GetDlgItemText(hwndDlg, IDC_FIRSTNAME, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, T2Utf(text));

				GetDlgItemText(hwndDlg, IDC_LASTNAME, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, T2Utf(text));

				GetDlgItemText(hwndDlg, IDC_NICKNAME, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, T2Utf(text));

				GetDlgItemText(hwndDlg, IDC_CITY, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_CITY, T2Utf(text));

				// Gadu-Gadu Female <-> Male
				switch(SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_GETCURSEL, 0, 0)) {
				case 1:
					gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_FEMALE);
					break;
				case 2:
					gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_MALE);
					break;
				default:
					gg_pubdir50_add(req, GG_PUBDIR50_GENDER, "");
				}

				GetDlgItemText(hwndDlg, IDC_BIRTHYEAR, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, T2Utf(text));

				GetDlgItemText(hwndDlg, IDC_FAMILYNAME, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_FAMILYNAME, T2Utf(text));

				GetDlgItemText(hwndDlg, IDC_CITYORIGIN, text, _countof(text));
				if (mir_tstrlen(text))
					gg_pubdir50_add(req, GG_PUBDIR50_FAMILYCITY, T2Utf(text));

				// Run update
				gg_pubdir50_seq_set(req, GG_SEQ_CHINFO);
				gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_detailsdlgproc", 35, "sess_mutex", 1);
				gg_pubdir50(gg->sess, req);
				gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_genoptsdlgproc", 35, 1, "sess_mutex", 1);
				dat->updating = TRUE;

				gg_pubdir50_free(req);
				}
				break;
			}
		}
		break;

	case WM_DESTROY:
		if (dat) mir_free(dat);
		break;
	}
	return FALSE;
}
Esempio n. 30
0
INT_PTR CALLBACK DlgProcToolBar(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HTREEITEM hti;

	switch (uMsg) {
	case WM_INITDIALOG:
		hToolBarTree = GetDlgItem(hwndDlg, IDC_TOOLBARTREE);
		{
			LONG_PTR style = GetWindowLongPtr(hToolBarTree, GWL_STYLE);
			style ^= TVS_CHECKBOXES;
			SetWindowLongPtr(hToolBarTree, GWL_STYLE, style);
			style |= TVS_CHECKBOXES;
			style |= TVS_NOHSCROLL;
			SetWindowLongPtr(hToolBarTree, GWL_STYLE, style);
		}
		{
			mir_cslock lck(ToolBarCS);
			BuildMenuObjectsTree(hToolBarTree);
		}

		Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, FALSE);
		Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, FALSE);
		Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, FALSE);

		SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(10, 0));
		SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_SETPOS, 0, MAKELONG(PluginConfig.g_iButtonsBarGap, 0));
		TranslateDialogDefault(hwndDlg);
		bOptionsInit = FALSE;
		break;

	case WM_LBUTTONUP:
		if (drag) {
			TreeView_SetInsertMark(hToolBarTree, NULL, 0);
			drag = 0;
			ReleaseCapture();

			TVHITTESTINFO hti;
			hti.pt.x = (short)LOWORD(lParam);
			hti.pt.y = (short)HIWORD(lParam);
			ClientToScreen(hwndDlg, &hti.pt);
			ScreenToClient(hToolBarTree, &hti.pt);
			hti.pt.y -= TreeView_GetItemHeight(hToolBarTree) / 2;
			TreeView_HitTest(hToolBarTree, &hti);
			if (hDragItem == hti.hItem) break;
			if (hti.flags & TVHT_ABOVE)
				hti.hItem = TVI_FIRST;

			TVITEM tvi;
			tvi.mask = TVIF_HANDLE | TVIF_PARAM;
			tvi.hItem = (HTREEITEM)hDragItem;
			TreeView_GetItem(hToolBarTree, &tvi);
			if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT) || (hti.hItem == TVI_FIRST)) {
				TVINSERTSTRUCT tvis;
				TCHAR strbuf[128];
				tvis.item.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE;
				tvis.item.stateMask = 0xFFFFFFFF;
				tvis.item.pszText = strbuf;
				tvis.item.cchTextMax = sizeof(strbuf);
				tvis.item.hItem = (HTREEITEM)hDragItem;
				TreeView_GetItem(hToolBarTree, &tvis.item);
				TreeView_DeleteItem(hToolBarTree, hDragItem);
				tvis.hParent = NULL;
				tvis.hInsertAfter = hti.hItem;
				TreeView_SelectItem(hToolBarTree, TreeView_InsertItem(hToolBarTree, &tvis));
				SendMessage((GetParent(hwndDlg)), PSM_CHANGED, 0, 0);
			}
		}
		break;

	case WM_MOUSEMOVE:
		if (drag) {
			TVHITTESTINFO hti;
			hti.pt.x = (short)LOWORD(lParam);
			hti.pt.y = (short)HIWORD(lParam);
			ClientToScreen(hwndDlg, &hti.pt);
			ScreenToClient(hToolBarTree, &hti.pt);
			TreeView_HitTest(hToolBarTree, &hti);
			if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT)) {
				HTREEITEM it = hti.hItem;
				hti.pt.y -= TreeView_GetItemHeight(hToolBarTree) / 2;
				TreeView_HitTest(hToolBarTree, &hti);
				if (!(hti.flags & TVHT_ABOVE))
					TreeView_SetInsertMark(hToolBarTree, hti.hItem, 1);
				else
					TreeView_SetInsertMark(hToolBarTree, it, 0);
			}
			else {
				if (hti.flags & TVHT_ABOVE) SendMessage(hToolBarTree, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0);
				if (hti.flags & TVHT_BELOW) SendMessage(hToolBarTree, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
				TreeView_SetInsertMark(hToolBarTree, NULL, 0);
			}
		}
		break;

	case WM_COMMAND:
		if (HIWORD(wParam) == BN_CLICKED && GetFocus() == (HWND)lParam && (HWND)lParam != hToolBarTree)
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		if ((HIWORD(wParam) == EN_CHANGE) && ((HWND)lParam == GetFocus()))
			if (!bOptionsInit)
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);

		switch (LOWORD(wParam)) {
		case IDC_BBRESET:
			CallService(MS_DB_MODULE_DELETE, NULL, LPARAM("TabSRMM_Toolbar"));
			CB_HardReInit();
			BuildMenuObjectsTree(hToolBarTree);
			break;

		case IDC_SEPARATOR:
			hti = TreeView_GetSelection(hToolBarTree);
			if (!hti)
				hti = TVI_FIRST;

			CustomButtonData *cbd = new CustomButtonData();
			cbd->bSeparator = cbd->bHidden = cbd->bIMButton = cbd->bLSided = true;
			cbd->dwButtonOrigID = ++dwSepCount;
			cbd->pszModuleName = "Tabsrmm_sep";
			cbd->iButtonWidth = 22;
			cbd->opFlags = BBSF_NTBDESTRUCT;
			LButtonsList.insert(cbd);

			TVINSERTSTRUCT tvis;
			tvis.hParent = NULL;
			tvis.hInsertAfter = hti;
			tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;

			tvis.item.pszText = TranslateT("<Separator>");
			tvis.item.iImage = tvis.item.iSelectedImage = -1;
			tvis.item.lParam = (LPARAM)cbd;
			hti = TreeView_InsertItem(hToolBarTree, &tvis);

			TreeView_SetCheckState(hToolBarTree, hti, (cbd->bIMButton || cbd->bChatButton));
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_RESET:
				CB_ReInitCustomButtons();
				dwSepCount = M.GetDword("TabSRMM_Toolbar", "SeparatorsCount", 0);
				return 1;

			case PSN_APPLY:
				hti = TreeView_GetSelection(hToolBarTree);
				if (hti) {
					TVITEM tvi;
					tvi.mask = TVIF_HANDLE | TVIF_PARAM;
					tvi.hItem = hti;
					TreeView_GetItem(hToolBarTree, &tvi);

					if (tvi.lParam) {
						CustomButtonData *cbd = (CustomButtonData*)tvi.lParam;
						if (cbd) {
							cbd->bIMButton = IsDlgButtonChecked(hwndDlg, IDC_IMCHECK) != 0;
							cbd->bChatButton = IsDlgButtonChecked(hwndDlg, IDC_CHATCHECK) != 0;
							cbd->bCanBeHidden = IsDlgButtonChecked(hwndDlg, IDC_CANBEHIDDEN) != 0;
						}
					}
				}

				SaveTree(hToolBarTree);
				CB_ReInitCustomButtons();
				PluginConfig.g_iButtonsBarGap = (BYTE)SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_GETPOS, 0, 0);

				if (PluginConfig.g_iButtonsBarGap != M.GetByte("ButtonsBarGap", 1))
					M.BroadcastMessageAsync(WM_SIZE, 0, 0);

				db_set_b(0, SRMSGMOD_T, "ButtonsBarGap", PluginConfig.g_iButtonsBarGap);

				BuildMenuObjectsTree((HWND)hToolBarTree);
				Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, FALSE);
				Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, FALSE);
				Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, FALSE);
				return 1;
			}
			break;

		case IDC_TOOLBARTREE:
			switch (((LPNMHDR)lParam)->code) {
			case TVN_BEGINDRAGA:
			case TVN_BEGINDRAGW:
				SetCapture(hwndDlg);
				drag = 1;
				hDragItem = ((LPNMTREEVIEW)lParam)->itemNew.hItem;
				TreeView_SelectItem(hToolBarTree, hDragItem);
				break;

			case TVN_SELCHANGINGA:
			case TVN_SELCHANGINGW:
				hti = TreeView_GetSelection(hToolBarTree);
				if (hti != NULL) {
					TCHAR strbuf[128];

					TVITEM tvi;
					tvi.hItem = hti;
					tvi.pszText = strbuf;
					tvi.cchTextMax = sizeof(strbuf);
					tvi.mask = TVIF_TEXT | TVIF_HANDLE | TVIF_PARAM;
					TreeView_GetItem(hToolBarTree, &tvi);

					if (tvi.lParam == 0 || !TreeView_GetCheckState(hToolBarTree, tvi.hItem) || !_tcscmp(tvi.pszText, MIDDLE_SEPARATOR))
						break;

					CustomButtonData *cbd = (CustomButtonData*)tvi.lParam;
					if (cbd) {
						cbd->opFlags = (IsDlgButtonChecked(hwndDlg, IDC_IMCHECK)) ? BBSF_IMBUTTON : 0;
						cbd->opFlags |= (IsDlgButtonChecked(hwndDlg, IDC_CHATCHECK)) ? BBSF_CHATBUTTON : 0;
						cbd->opFlags |= (IsDlgButtonChecked(hwndDlg, IDC_CANBEHIDDEN)) ? BBSF_CANBEHIDDEN : 0;

						cbd->bIMButton = (IsDlgButtonChecked(hwndDlg, IDC_IMCHECK) ? TRUE : FALSE);
						cbd->bChatButton = (IsDlgButtonChecked(hwndDlg, IDC_CHATCHECK) ? TRUE : FALSE);
						cbd->bCanBeHidden = (IsDlgButtonChecked(hwndDlg, IDC_CANBEHIDDEN) ? TRUE : FALSE);
					}
				}
				break;

			case TVN_SELCHANGEDW:
			case TVN_SELCHANGEDA:
				hti = TreeView_GetSelection(hToolBarTree);
				if (hti != NULL) {
					TCHAR strbuf[128];

					TVITEM tvi;
					tvi.pszText = strbuf;
					tvi.cchTextMax = sizeof(strbuf);
					tvi.mask = TVIF_TEXT | TVIF_HANDLE | TVIF_PARAM;
					tvi.hItem = hti;
					TreeView_GetItem(hToolBarTree, &tvi);

					if (!TreeView_GetCheckState(hToolBarTree, tvi.hItem) || !_tcscmp(tvi.pszText, MIDDLE_SEPARATOR)) {
						Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, FALSE);
						Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, FALSE);
						Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, FALSE);
						break;
					}

					if (tvi.lParam == 0)
						break;

					CustomButtonData *cbd = (CustomButtonData*)tvi.lParam;
					if (cbd) {
						Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, TRUE);
						Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, TRUE);
						Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, TRUE);
						CheckDlgButton(hwndDlg, IDC_IMCHECK, (cbd->bIMButton) ? 1 : 0);
						CheckDlgButton(hwndDlg, IDC_CHATCHECK, (cbd->bChatButton) ? 1 : 0);
						CheckDlgButton(hwndDlg, IDC_CANBEHIDDEN, (cbd->bCanBeHidden) ? 1 : 0);
					}
				}
				break;

			case NM_CLICK:
				TVHITTESTINFO hti = { 0 };
				GetCursorPos(&hti.pt);
				ScreenToClient(hToolBarTree, &hti.pt);
				if (TreeView_HitTest(hToolBarTree, &hti)) {
					if (hti.flags&TVHT_ONITEMSTATEICON) {
						SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
						if (TreeView_GetCheckState(hToolBarTree, hti.hItem)) {
							Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, FALSE);
							Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, FALSE);
							Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, FALSE);
							CheckDlgButton(hwndDlg, IDC_IMCHECK, 1);
						}
						else {
							Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, TRUE);
							Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, TRUE);
							Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, TRUE);
						}
						TreeView_SelectItem(hToolBarTree, hti.hItem);
					}
				}
			}
		}
		break;

	case WM_DESTROY:
		HIMAGELIST hIml = TreeView_GetImageList(GetDlgItem(hwndDlg, IDC_TOOLBARTREE), TVSIL_NORMAL);
		ImageList_Destroy(hIml);
		hIml = TreeView_GetImageList(GetDlgItem(hwndDlg, IDC_TOOLBARTREE), TVSIL_STATE);
		ImageList_Destroy(hIml);
		break;
	}

	return FALSE;
}