Beispiel #1
0
// call with list_cs locked
void read_ping_addresses()
{
	PINGADDRESS pa;
	pa.index = 0;

	list_items.clear();
	while (read_ping_address(pa))
	{
		list_items.push_back(pa);
		++pa.index;
	}
}
// call with list_cs locked
void read_ping_addresses() {
	HANDLE hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDFIRST, 0, 0 );
	PINGADDRESS pa;

	list_items.clear();
	while ( hContact != NULL ) {
		char *proto = ( char* )CallService( MS_PROTO_GETCONTACTBASEPROTO, ( WPARAM )hContact,0 );
		if ( proto && lstrcmp( PROTO, proto) == 0) {
			pa.hContact = hContact;
			read_ping_address(pa);
			list_items.push_back(pa);
		}

		hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDNEXT,( WPARAM )hContact, 0 );
	}	
	std::sort(list_items.begin(), list_items.end(), SAscendingSort());
}
Beispiel #3
0
// ping hosts list window
static INT_PTR CALLBACK DlgProcOpts2(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch ( msg ) {
	case WM_INITDIALOG: 
			TranslateDialogDefault( hwndDlg );

			Lock(&data_list_cs, "init options dialog");
			temp_list = data_list;
			Unlock(&data_list_cs);

			for (pinglist_it i = temp_list.begin(); i != temp_list.end(); ++i)
			{
				int index = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)i->pszLabel);
				SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, index, (LPARAM)&(*i));
			}
		return TRUE;

	case WM_COMMAND:
		if (HIWORD( wParam ) == LBN_SELCHANGE && LOWORD(wParam) == IDC_LST_DEST)
		{
			int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
			if(sel != LB_ERR)
			{
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), TRUE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), TRUE);

				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel > 0));
				int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel < count - 1));
			}
		}

		if ( HIWORD( wParam ) == BN_CLICKED )
		{
			switch( LOWORD( wParam ))
			{
			case IDC_BTN_DESTEDIT:
			{
				int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
				if (sel != LB_ERR)
				{
					PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel, 0);
					PINGADDRESS temp = *item;
					if (Edit(hwndDlg, temp))
					{
						*item = temp;
						SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel, 0);
						SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel, (LPARAM)item->pszLabel);
						SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel, (LPARAM)item);
						SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)sel, 0);

						EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), TRUE);
						EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), TRUE);
						EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), sel > 0);
						int count = SendDlgItemMessage(hwndDlg, IDC_BTN_DESTDOWN, LB_GETCOUNT, 0, 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel < count - 1));

						SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
					}
				}
			}
				break;
			case IDC_BTN_DESTADD:

				memset(&add_edit_addr,0,sizeof(add_edit_addr));
				add_edit_addr.cbSize = sizeof(add_edit_addr);
				add_edit_addr.port = -1;
				add_edit_addr.set_status = ID_STATUS_ONLINE;
				add_edit_addr.get_status = ID_STATUS_OFFLINE;
				add_edit_addr.status = PS_NOTRESPONDING;
				add_edit_addr.item_id = 0;
				add_edit_addr.index = (int)temp_list.size();

				if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, DlgProcDestEdit) == IDOK)
				{
					temp_list.push_back(add_edit_addr);

					int index = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)add_edit_addr.pszLabel);
					SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)index, 0);
					SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)index, (LPARAM)&(temp_list.back()));

					EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), TRUE);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), TRUE);

					int sel = (int)temp_list.size() - 1;
					EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel > 0));
					int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel < count - 1));

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

				break;
			case IDC_BTN_DESTREM:
			{
				int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
				if(sel != LB_ERR) {
					PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel, 0);
					SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel, 0);
					temp_list.remove(*item);
				}

				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), FALSE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), FALSE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), FALSE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), FALSE);

				SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
				RefreshWindow(0, 0);
				break;
			}
			case IDC_BTN_DESTDOWN:
				{
					int sel2 = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
					if(sel2 != LB_ERR) {
						PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2, 0),
							*item2 = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2 + 1, 0);
						if(item && item2)
						{
							add_edit_addr = *item;
							*item = *item2;
							*item2 = add_edit_addr;

							// keep indexes the same, as they're used for sorting the binary tree
							int index = item->index, index2 = item2->index;						
							item->index = index2;
							item2->index = index;

							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel2, (LPARAM)0);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)item->pszLabel);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel2, (LPARAM)item);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)(sel2 + 1), (LPARAM)0);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)(sel2 + 1), (LPARAM)item2->pszLabel);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)(sel2 + 1), (LPARAM)item2);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)(sel2 + 1), 0);

							EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel2 + 1 > 0));
							int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
							EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel2 + 1 < count - 1));

							SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
						}
					}
				}
				break;
			case IDC_BTN_DESTUP:
				{
					int sel2 = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
					if(sel2 != LB_ERR) {
						PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2, 0),
							*item2 = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2 - 1, 0);

						if (item && item2)
						{
							add_edit_addr = *item;
							*item = *item2;
							*item2 = add_edit_addr;

							// keep indexes the same, as they're used for sorting the binary tree
							int index = item->index, index2 = item2->index;						
							item->index = index2;
							item2->index = index;

							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel2, (LPARAM)0);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)item->pszLabel);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel2, (LPARAM)item);

							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)(sel2 - 1), (LPARAM)0);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)(sel2 - 1), (LPARAM)item2->pszLabel);
							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)(sel2 - 1), (LPARAM)item2);

							SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)(sel2 - 1), 0);

							EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel2 - 1 > 0));
							int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
							EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel2 - 1 < count - 1));

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

				break;
			}
		}
		if(LOWORD(wParam) == IDC_BGCOL
			|| LOWORD(wParam) == IDC_SP_INDENT || LOWORD(wParam) == IDC_SP_ROWHEIGHT)
		{
			SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
		}
		break;

	case WM_NOTIFY:
		if (((LPNMHDR)lParam)->code == PSN_APPLY )
		{
			CallService(PLUG "/SetAndSavePingList", (WPARAM)&temp_list, 0);
			CallService(PLUG "/GetPingList", 0, (LPARAM)&temp_list);
			// the following will be affected due to list rebuild event
			//if(hWakeEvent) SetEvent(hWakeEvent);
			return TRUE;
		}
		break;

	}
	return FALSE;
}
// ping destinations list window
static BOOL CALLBACK DlgProcOpts2(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND hw;
	int sel;

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

			Lock(&data_list_cs, "init options dialog");
			temp_list = data_list;
			Unlock(&data_list_cs);

			hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
			for(PINGLIST::iterator i = temp_list.begin(); i != temp_list.end(); i++) {
				//int index = 
					SendMessage(hw, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)i->pszLabel);
			}

		}
		return TRUE;

	case WM_COMMAND:
		if (HIWORD( wParam ) == LBN_SELCHANGE && LOWORD(wParam) == IDC_LST_DEST) {
			hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
			sel = SendMessage(hw, LB_GETCURSEL, 0, 0);
			if(sel != LB_ERR) {
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTREM);
				EnableWindow(hw, TRUE);
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT);
				EnableWindow(hw, TRUE);

				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
				EnableWindow(hw, (sel > 0));
				hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
				int count = SendMessage(hw, LB_GETCOUNT, 0, 0);
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
				EnableWindow(hw, (sel < count - 1));
			}
		}

		if ( HIWORD( wParam ) == BN_CLICKED ) {
			switch( LOWORD( wParam )) {
			case IDC_BTN_DESTEDIT:
				hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
				sel = SendMessage(hw, LB_GETCURSEL, 0, 0);
				if(sel != LB_ERR) {
					add_edit_addr = temp_list[sel];
					
					if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, DlgProcDestEdit) == IDOK) {

						temp_list[sel] = add_edit_addr;
						SendMessage(hw, LB_DELETESTRING, (WPARAM)sel, (LPARAM)0);
						SendMessage(hw, LB_INSERTSTRING, (WPARAM)sel, (LPARAM)temp_list[sel].pszLabel);
						SendMessage(hw, LB_SETCURSEL, (WPARAM)sel, 0);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTREM);
						EnableWindow(hw, TRUE);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT);
						EnableWindow(hw, TRUE);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
						EnableWindow(hw, TRUE);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
						EnableWindow(hw, TRUE);
	
						SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
					}
				}
				break;
			case IDC_BTN_DESTADD:

				memset(&add_edit_addr,0,sizeof(add_edit_addr));
				add_edit_addr.cbSize = sizeof(add_edit_addr);
				add_edit_addr.port = -1;
				add_edit_addr.set_status = ID_STATUS_ONLINE;
				add_edit_addr.get_status = ID_STATUS_OFFLINE;
				add_edit_addr.status = options.nrstatus;

				if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, DlgProcDestEdit) == IDOK) {

					temp_list.push_back(add_edit_addr);

					hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
					int index = SendMessage(hw, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)add_edit_addr.pszLabel);
					hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
					SendMessage(hw, LB_SETCURSEL, (WPARAM)index, 0);

					hw = GetDlgItem(hwndDlg, IDC_BTN_DESTREM);
					EnableWindow(hw, TRUE);
					hw = GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT);
					EnableWindow(hw, TRUE);

					sel = temp_list.size() - 1;
					hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
					EnableWindow(hw, (sel > 0));
					hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
					int count = SendMessage(hw, LB_GETCOUNT, 0, 0);
					hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
					EnableWindow(hw, (sel < count - 1));
					
					SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
				}

				break;
			case IDC_BTN_DESTREM:
				hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
				sel = SendMessage(hw, LB_GETCURSEL, 0, 0);
				if(sel != LB_ERR) {
					SendMessage(hw, LB_DELETESTRING, (WPARAM)sel, 0);
					PINGLIST::iterator i = temp_list.begin();
					while(sel > 0 && i != temp_list.end()) {
						sel--;
						i++;
					}
					if(i != temp_list.end())
						temp_list.erase(i);
				}

				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTREM);
				EnableWindow(hw, FALSE);
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT);
				EnableWindow(hw, FALSE);
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
				EnableWindow(hw, FALSE);
				hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
				EnableWindow(hw, FALSE);

				SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
				break;
			case IDC_BTN_DESTDOWN:
				{
					hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
					int sel2 = SendMessage(hw, LB_GETCURSEL, 0, 0);
					if(sel2 != LB_ERR) {
						add_edit_addr = temp_list[sel2];					
						temp_list[sel2] = temp_list[sel2 + 1];					
						temp_list[sel2 + 1] = add_edit_addr;

						SendMessage(hw, LB_DELETESTRING, (WPARAM)sel2, (LPARAM)0);
						SendMessage(hw, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)temp_list[sel2].pszLabel);
						SendMessage(hw, LB_DELETESTRING, (WPARAM)(sel2 + 1), (LPARAM)0);
						SendMessage(hw, LB_INSERTSTRING, (WPARAM)(sel2 + 1), (LPARAM)temp_list[sel2 + 1].pszLabel);
						SendMessage(hw, LB_SETCURSEL, (WPARAM)(sel2 + 1), 0);

						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
						EnableWindow(hw, (sel2 + 1 > 0));
						hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
						int count = SendMessage(hw, LB_GETCOUNT, 0, 0);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
						EnableWindow(hw, (sel2 + 1 < count - 1));

						SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
					}				
				}
				break;
			case IDC_BTN_DESTUP:
				{
					hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
					int sel2 = SendMessage(hw, LB_GETCURSEL, 0, 0);
					if(sel2 != LB_ERR) {
						add_edit_addr = temp_list[sel2 - 1];					
						temp_list[sel2 - 1] = temp_list[sel2];					
						temp_list[sel2] = add_edit_addr;

						SendMessage(hw, LB_DELETESTRING, (WPARAM)sel2, (LPARAM)0);
						SendMessage(hw, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)temp_list[sel2].pszLabel);

						SendMessage(hw, LB_DELETESTRING, (WPARAM)(sel2 - 1), (LPARAM)0);
						SendMessage(hw, LB_INSERTSTRING, (WPARAM)(sel2 - 1), (LPARAM)temp_list[sel2 - 1].pszLabel);

						SendMessage(hw, LB_SETCURSEL, (WPARAM)(sel2 - 1), 0);

						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTUP);
						EnableWindow(hw, (sel2 - 1 > 0));
						hw = GetDlgItem(hwndDlg, IDC_LST_DEST);
						int count = SendMessage(hw, LB_GETCOUNT, 0, 0);
						hw = GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN);
						EnableWindow(hw, (sel2 - 1 < count - 1));
		
						SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
					}				
				}

				break;
			}
		}
		break;

	case WM_NOTIFY:
		if (((LPNMHDR)lParam)->code == (unsigned)PSN_APPLY ) {
			CallService(PROTO "/SetAndSavePingList", (WPARAM)&temp_list, 0);
			CallService(PROTO "/GetPingList", 0, (LPARAM)&temp_list);
			// the following will be affected due to list rebuild event
			//if(hWakeEvent) SetEvent(hWakeEvent);
			return TRUE;
		}
		break;

	}
	return FALSE;
}