Exemple #1
0
void CMySuperGrid::_DeleteAll()
{
	DeleteAll();//call CSuperGridCtrl::DeleteAll();

	//add some new data
	CItemInfo* lp = new CItemInfo();
	lp->SetImage(4);
	//add item text
	lp->SetItemText(_T("New data"));
	//Create root item
	CTreeItem * pRoot = InsertRootItem(lp);//previous we call CreateTreeCtrl(lp)
	if( pRoot == NULL )
		return;
	//insert items	
	int nCol = GetNumCol();
	for(int i=0; i < nCol; i++)
	{
		CItemInfo* lpItemInfo = new CItemInfo();
		CString strItem;
		strItem.Format(_T("Item %d"),i);
		//add items text
		lpItemInfo->SetItemText(strItem);
		//add subitem text
		for(int y=0;y < nCol-1; y++) 
		{
			CString str;
			str.Format(_T("subItem %d of %s"),y,lpItemInfo->GetItemText());
			lpItemInfo->AddSubItemText(str);
			lpItemInfo->AddSubItemText(str);
		}
		//insert the iteminfo with ParentPtr
		CTreeItem* pParent = InsertItem(pRoot, lpItemInfo);
		//other nodes
		if(i%nCol)
		{
			CTreeItem* pParent1=NULL;
			CTreeItem* pParent2=NULL;
			for(int x=0; x < nCol; x++)
			{
				CItemInfo* lpItemInfo = new CItemInfo();
				CString strItem;
				strItem.Format(_T("Item %d"),x);
				lpItemInfo->SetItemText(strItem);
				for(int z=0; z < nCol-1; z++) 
				{
					CString str;
					str.Format(_T("subItem %d of %s"),z, lpItemInfo->GetItemText());
					lpItemInfo->AddSubItemText(str);
				}
				pParent1 = InsertItem(pParent, lpItemInfo);
				
			}
		}
	}
	//expand one level
	Expand(pRoot, 0 /*listview index 0*/); 
	UINT uflag = LVIS_SELECTED | LVIS_FOCUSED;
	SetItemState(0, uflag, uflag);


}
Exemple #2
0
void CListCtrlEx::select_all()
{
	for (int i = 0; i < GetItemCount(); i++)
		SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
}
void CustomVirtListCtrl<T,L>::SelectNone()
{
	for (long i = 0; i < GetItemCount() ; i++ ) {
		SetItemState( i, wxLIST_STATE_DONTCARE, -1 );
	}
}
void wxWebUpdateListCtrl::RebuildPackageList(wxWebUpdateListCtrlFilter filter)
{
    // remove old contents
    DeleteAllItems();

    int idx = 0;        // could go out of synch with 'i' because
                        // some packages could not be added to the list....
    for (int i=0; i < (int)m_arrRemotePackages.GetCount(); i++, idx++) {

        wxWebUpdatePackage &curr = m_arrRemotePackages[i];
        wxLogAdvMsg(wxS("wxWebUpdateListCtrl::RebuildPackageList - Adding the '") +
            curr.GetName() + wxS("' package..."));


        // set the properties for the first column (NAME)
        // ----------------------------------------------
        InsertItem(idx, curr.GetName());



        // set the properties for the second column (LATEST VERSION)
        // ---------------------------------------------------------
        SetItem(idx, 1, curr.GetLatestVersion());



        // set the properties for the third column (LOCAL VERSION)
        // -------------------------------------------------------

        SetLocalVersionFor(idx, curr);

        // tocheck will be TRUE for outdated items:
        wxWebUpdateCheckFlag f = CompareVersion(curr);
        bool tocheck = (f == wxWUCF_OUTOFDATE || f == wxWUCF_NOTINSTALLED);

        if (IsToDiscard(filter, idx, curr, f)) {

            DeleteItem(idx);
            idx--;
            continue;           // continue with next package
        }



        // set the properties for the fourth column (SIZE)
        // -----------------------------------------------

        // we'll leave the task of updating this field to the
        // wxSizeCacherThread that has been launched by wxWebUpdateDlg
        unsigned long bytesize = 0;
        wxWebUpdateDownload &d = curr.GetDownload();
        if (d.IsDownloadSizeCached())
            bytesize = d.GetDownloadSize();
        SetItem(idx, 3, wxGetSizeStr(bytesize));



        // set the properties for the fifth column (IMPORTANCE)
        // ----------------------------------------------------
        switch (curr.GetImportance()) {
        case wxWUPI_HIGH:
            SetItem(idx, 4, _("high!"));
            Check(idx, tocheck);
            break;
        case wxWUPI_NORMAL:
            SetItem(idx, 4, _("normal"));
            Check(idx, tocheck);
            break;
        case wxWUPI_LOW:
            SetItem(idx, 4, _("low"));
            Check(idx, FALSE);
            break;
        default:
            wxASSERT_MSG(0, wxS("Invalid package !"));
        }


        // set the properties for the sixth column (REQUIRES)
        // ----------------------------------------------------

        wxString str(curr.GetPrerequisites());
        SetItem(idx, 5, str.IsEmpty() ? _("none") : str.c_str());


        // set as item data the index in our remote package array
        SetItemData(idx, i);
    }

    // select the first item of the list
    if (GetItemCount() > 0)
        SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
}
void CMuleListCtrl::OnChar(wxKeyEvent& evt)
{
	int key = evt.GetKeyCode();
	if (key == 0) {
		// We prefer GetKeyCode() to GetUnicodeKey(), in order to work
		// around a bug in the GetUnicodeKey(), that causes values to
		// be returned untranslated. This means for instance, that if
		// shift and '1' is pressed, the result is '1' rather than '!'
		// (as it should be on my keyboard). This has been reported:
		// http://sourceforge.net/tracker/index.php?func=detail&aid=1864810&group_id=9863&atid=109863
		key = evt.GetUnicodeKey();
	} else if (key >= WXK_START) {
		// wxKeycodes are ignored, as they signify events such as the 'home'
		// button. Unicoded chars are not checked as there is an overlap valid
		// chars and the wx keycodes.
		evt.Skip();
		return;
	}

	// We wish to avoid handling shortcuts, with the exception of 'select-all'.
	if (evt.AltDown() || evt.ControlDown() || evt.MetaDown()) {
		if (evt.CmdDown() && (evt.GetKeyCode() == 0x01)) {
			// Ctrl+a (Command+a on Mac) was pressed, select all items
			for (int i = 0; i < GetItemCount(); ++i) {
				SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
			}
		}

		evt.Skip();
		return;
	} else if (m_tts_time + 1500u < GetTickCount()) {
		m_tts_text.Clear();
	}

	m_tts_time = GetTickCount();
	m_tts_text.Append(wxTolower(key));

	// May happen if the subclass does not forward deletion events.
	// Or rather when single-char-repeated (see below) wraps around, so don't assert.
	if (m_tts_item >= GetItemCount()) {
		m_tts_item = -1;
	}

	unsigned next = (m_tts_item == -1) ? 0 : m_tts_item;
	for (unsigned i = 0, count = GetItemCount(); i < count; ++i) {
		wxString text = GetTTSText((next + i) % count).MakeLower();

		if (text.StartsWith(m_tts_text)) {
			ClearSelection();

			m_tts_item = (next + i) % count;
			SetItemState(m_tts_item, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED,
					wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
			EnsureVisible(m_tts_item);

			return;
		}
	}

	if (m_tts_item != -1) {
		// Crop the string so that it matches the old item (avoid typos).
		wxString text = GetTTSText(m_tts_item).MakeLower();

		// If the last key didn't result in a hit, then we skip the event.
		if (!text.StartsWith(m_tts_text)) {
			if ((m_tts_text.Length() == 2) && (m_tts_text[0] == m_tts_text[1])) {
				// Special case, single-char, repeated. This allows toggeling
				// between items starting with a specific letter.
				m_tts_text.Clear();
				// Increment, so the next will be selected (or wrap around).
				m_tts_item++;
				OnChar(evt);
			} else {
				m_tts_text.RemoveLast();
				evt.Skip(true);
			}
		}
	} else {
		evt.Skip(true);
	}
}
void CClientListCtrl::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	//		make sure window is active
	//
	GetParentFrame()->ActivateFrame();

	///////////////////////////////
	// See ContextMenuRules.txt for order of menu commands!

	//		create an empty context menu
	//
	CP4Menu popMenu;
	popMenu.CreatePopupMenu();

 	int	index;
    SetIndexAndPoint( index, point );

	// Can always create a new client
	popMenu.AppendMenu( stringsON, ID_CLIENTSPEC_NEW );

	// Only offer edit if no other client is selected
	if ( index == -1 || GetSelectedItemText() == GET_P4REGPTR()->GetP4Client() )
		popMenu.AppendMenu( stringsON, ID_CLIENT_EDITMY );

	if( index != -1 )
	{
		// Make sure item gets selected
		SetItemState( index, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED );
			
		popMenu.AppendMenu( stringsON, ID_CLIENT_DESCRIBE ); //or client edit if user is the owner
		popMenu.AppendMenu( stringsON, ID_CLIENT_DELETE );

		popMenu.AppendMenu( MF_SEPARATOR );

		// Can only switch to a client if its not my current client
		if ( GetSelectedItemText() != GET_P4REGPTR()->GetP4Client() )
			popMenu.AppendMenu( stringsON, ID_CLIENTSPEC_SWITCH );
		else	// can only set as default if it is my current client
			popMenu.AppendMenu( stringsON, ID_SETDEFCLIENT );

		popMenu.AppendMenu( stringsON, ID_CLIENT_TEMPLATE );
		if (GET_P4REGPTR()->LocalCliTemplateSw())
		{
			popMenu.AppendMenu( MF_SEPARATOR );
			popMenu.AppendMenu( stringsON, ID_CLIENT_USEASLOCALTEMPLATE, LoadStringResource(IDS_CLIENT_USEASLOCALTEMPLATE) );
			popMenu.AppendMenu( stringsON, ID_CLIENT_CLEARLOCALTEMPLATE, LoadStringResource(IDS_CLIENT_CLEARLOCALTEMPLATE) );
		}
	}
	popMenu.AppendMenu( MF_SEPARATOR );
	popMenu.AppendMenu( stringsON, ID_FILTERCLIENTS, LoadStringResource(IDS_FILTERCLIENTS) );
	popMenu.AppendMenu( stringsON, ID_CLEARCLIENTFILTER, LoadStringResource(IDS_CLEARCLIENTFILTER) );
	popMenu.AppendMenu( MF_SEPARATOR );
	CString txt = GetSelectedItemText();
	if (txt.IsEmpty())
		txt = GET_P4REGPTR()->GetP4Client( );
	txt = LoadStringResource(IDS_CHGS_BY_CLIENT) + txt;
	txt = TruncateString(txt, 50);
	popMenu.AppendMenu( stringsON, ID_CHGS_BY_CLIENT, txt );
	popMenu.AppendMenu( stringsON, ID_VIEW_UPDATE, LoadStringResource(IDS_REFRESH) );

	MainFrame()->AddToolsToContextMenu(&popMenu);

	//		put up the menu 
	//
	popMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd( ) );
}
Exemple #7
0
void MyListCtrl::OnListKeyDown(wxListEvent& event)
{
    long item;

    if ( !wxGetKeyState(WXK_SHIFT) )
    {
        LogEvent(event, wxT("OnListKeyDown"));
        event.Skip();
        return;
    }

    switch ( event.GetKeyCode() )
    {
        case 'C': // colorize
            {
                wxListItem info;
                info.m_itemId = event.GetIndex();
                if ( info.m_itemId == -1 )
                {
                    // no item
                    break;
                }

                GetItem(info);

                wxListItemAttr *attr = info.GetAttributes();
                if ( !attr || !attr->HasTextColour() )
                {
                    info.SetTextColour(*wxCYAN);

                    SetItem(info);

                    RefreshItem(info.m_itemId);
                }
            }
            break;

        case 'N': // next
            item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
            if ( item++ == GetItemCount() - 1 )
            {
                item = 0;
            }

            wxLogMessage(wxT("Focusing item %ld"), item);

            SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
            EnsureVisible(item);
            break;

        case 'R': // show bounding rectangle
            {
                item = event.GetIndex();
                wxRect r;
                if ( !GetItemRect(item, r) )
                {
                    wxLogError(wxT("Failed to retrieve rect of item %ld"), item);
                    break;
                }

                wxLogMessage(wxT("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
                             item, r.x, r.y, r.x + r.width, r.y + r.height);
            }
            break;

        case '1': // show sub item bounding rectangle for the given column
        case '2': // (and icon/label rectangle if Shift/Ctrl is pressed)
        case '3':
        case '4': // this column is invalid but we want to test it too
            if ( InReportView() )
            {
                int subItem = event.GetKeyCode() - '1';
                item = event.GetIndex();
                wxRect r;

                int code = wxLIST_RECT_BOUNDS;
                if ( wxGetKeyState(WXK_SHIFT) )
                    code = wxLIST_RECT_ICON;
                else if ( wxGetKeyState(WXK_CONTROL) )
                    code = wxLIST_RECT_LABEL;

                if ( !GetSubItemRect(item, subItem, r, code) )
                {
                    wxLogError(wxT("Failed to retrieve rect of item %ld column %d"), item, subItem + 1);
                    break;
                }

                wxLogMessage(wxT("Bounding rect of item %ld column %d is (%d, %d)-(%d, %d)"),
                             item, subItem + 1,
                             r.x, r.y, r.x + r.width, r.y + r.height);
            }
            break;

        case 'U': // update
            if ( !IsVirtual() )
                break;

            if ( m_updated != -1 )
                RefreshItem(m_updated);

            m_updated = event.GetIndex();
            if ( m_updated != -1 )
            {
                // we won't see changes to this item as it's selected, update
                // the next one (or the first one if we're on the last item)
                if ( ++m_updated == GetItemCount() )
                    m_updated = 0;

                wxLogMessage("Updating colour of the item %ld", m_updated);
                RefreshItem(m_updated);
            }
            break;

        case 'D': // delete
            item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
            while ( item != -1 )
            {
                DeleteItem(item);

                wxLogMessage(wxT("Item %ld deleted"), item);

                // -1 because the indices were shifted by DeleteItem()
                item = GetNextItem(item - 1,
                                   wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
            }
            break;

        case 'I': // insert
            if ( GetWindowStyle() & wxLC_REPORT )
            {
                if ( GetWindowStyle() & wxLC_VIRTUAL )
                {
                    SetItemCount(GetItemCount() + 1);
                }
                else // !virtual
                {
                    InsertItemInReportView(event.GetIndex());
                }
            }
            //else: fall through

        default:
            LogEvent(event, wxT("OnListKeyDown"));

            event.Skip();
    }
}
void KUIMulStatusTree::TravelSiblingAndParent(HTREEITEM hItem, int nCheck)
{
    HTREEITEM hNextSiblingItem = NULL;
    HTREEITEM hPrevSiblingItem = NULL;
    HTREEITEM hParentItem = NULL;

    HWND hParent = GetParent();
    UINT nState  = 0;

    //查找父节点,没有就结束
    hParentItem = GetParentItem(hItem);

    int nRetCode = false;

    if(hParentItem != NULL)
    {
        int nState = nCheck;//设初始值,防止没有兄弟节点时出错

        //查找当前节点下面的兄弟节点的状态
        hNextSiblingItem = GetNextSiblingItem(hItem);

        while(hNextSiblingItem != NULL)
        {
            nRetCode = GetCheck(hNextSiblingItem, nState);

            if(nState != nCheck && nRetCode)
                break;
            else 
                hNextSiblingItem = GetNextSiblingItem(hNextSiblingItem);
        }

        if( nCheck == nState)
        {
            //查找当前节点上面的兄弟节点的状态
            hPrevSiblingItem = GetPrevSiblingItem(hItem);

            while(hPrevSiblingItem != NULL)
            {
                nRetCode = GetCheck(hPrevSiblingItem, nState);

                if(nState != nCheck && nRetCode)
                    break;
                else 
                    hPrevSiblingItem = GetPrevSiblingItem(hPrevSiblingItem);
            }
        }

        if( nCheck == nState || nState == 0)
        {
            nRetCode = GetCheck( hParentItem, nState);

            if( nState != 0)
            {
                //如果状态一致,则父节点的状态与当前节点的状态一致
                nState = GetItemState(hParentItem, TVIS_STATEIMAGEMASK);
                if (nState != INDEXTOSTATEIMAGEMASK(nCheck))
                {        
                    SetItemState(hParentItem, INDEXTOSTATEIMAGEMASK(nCheck), TVIS_STATEIMAGEMASK);
                    if (hParent != NULL)
                    {
                       // ::SendMessage(hParent, WM_KAN_NOTIFY_TREE_CHECKED_CHANGE, (WPARAM)hParentItem, (LPARAM)nCheck);
                    }
                }

            }
            //再递归处理父节点的兄弟节点和其父节点

            TravelSiblingAndParent(hParentItem, nCheck);
        }
        else
        {
            //状态不一致,则当前节点的父节点、父节点的父节点……状态均为第三态
            hParentItem = GetParentItem(hItem);

            while(hParentItem != NULL)
            {
                nRetCode = GetCheck(hParentItem, nState);

                if(nState !=0)
                {
                    nState = GetItemState(hParentItem, TVIS_STATEIMAGEMASK);
                    SetItemState(hParentItem, INDEXTOSTATEIMAGEMASK(EM_TVIS_INDETERMINING), TVIS_STATEIMAGEMASK);
                    if (hParent != NULL)
                    {
                        //::SendMessage(hParent, WM_KAN_NOTIFY_TREE_CHECKED_CHANGE, (WPARAM)hParentItem, (LPARAM)EM_TVIS_INDETERMINING);
                    }
                }

                hParentItem = GetParentItem(hParentItem);
            }
        }
    }	
}
void CQueueViewFailed::OnRequeueSelected(wxCommandEvent& event)
{
#ifndef __WXMSW__
	// GetNextItem is O(n) if nothing is selected, GetSelectedItemCount() is O(1)
	if (!GetSelectedItemCount())
		return;
#endif

	bool failedToRequeueAll = false;
	std::list<CQueueItem*> selectedItems;
	long item = -1;
	long skipTo = -1;
	while (true)
	{
		item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
		if (item == -1)
			break;
		SetItemState(item, 0, wxLIST_STATE_SELECTED);
		if (item < skipTo)
			continue;

		CQueueItem* pItem = GetQueueItem(item);
		if (pItem->GetType() == QueueItemType_Server)
			skipTo = item + pItem->GetChildrenCount(true) + 1;
		selectedItems.push_back(GetQueueItem(item));
	}

	if (selectedItems.empty())
		return;

	CQueueViewBase* pQueueView = m_pQueue->GetQueueView();

	while (!selectedItems.empty())
	{
		CQueueItem* pItem = selectedItems.front();
		selectedItems.pop_front();

		if (pItem->GetType() == QueueItemType_Server)
		{
			CServerItem* pOldServerItem = (CServerItem*)pItem;
			CServerItem* pServerItem = pQueueView->CreateServerItem(pOldServerItem->GetServer());

			unsigned int childrenCount = pOldServerItem->GetChildrenCount(false);
			for (unsigned int i = 0; i < childrenCount; i++)
			{
				CFileItem* pFileItem = (CFileItem*)pItem->GetChild(i, false);
				pFileItem->m_errorCount = 0;
				pFileItem->m_statusMessage.Clear();

				if (!pFileItem->Download() && !wxFileName::FileExists(pFileItem->GetLocalFile()))
				{
					failedToRequeueAll = true;
					RemoveItem(pItem, true, false, false);
					continue;
				}

				if (pFileItem->m_edit == CEditHandler::remote)
				{
					CEditHandler* pEditHandler = CEditHandler::Get();
					if (!pEditHandler)
					{
						failedToRequeueAll = true;
						delete pFileItem;
						continue;
					}
					wxFileName fn(pFileItem->GetLocalFile());
					enum CEditHandler::fileState state = pEditHandler->GetFileState(CEditHandler::remote, fn.GetFullName());
					if (state == CEditHandler::unknown)
					{
						wxASSERT(pFileItem->Download());
						if (!pEditHandler->AddFile(CEditHandler::remote, fn.GetFullName(), pFileItem->GetRemotePath(), pServerItem->GetServer()))
						{
							failedToRequeueAll = true;
							delete pFileItem;
							continue;
						}
					}
					else if (state == CEditHandler::upload_and_remove_failed)
					{
						wxASSERT(!pFileItem->Download());
						if (!pEditHandler->UploadFile(pFileItem->m_edit, fn.GetFullName(), true))
							failedToRequeueAll = true;
						delete pFileItem;
						continue;
					}
					else
					{
						failedToRequeueAll = true;
						delete pFileItem;
						continue;
					}
				}

				pFileItem->SetParent(pServerItem);
				pQueueView->InsertItem(pServerItem, pFileItem);
			}

			m_fileCount -= childrenCount;
			m_itemCount -= childrenCount + 1;
			pOldServerItem->DetachChildren();
			delete pOldServerItem;

			std::vector<CServerItem*>::iterator iter;
			for (iter = m_serverList.begin(); iter != m_serverList.end(); iter++)
			{
				if (*iter == pOldServerItem)
					break;
			}
			if (iter != m_serverList.end())
				m_serverList.erase(iter);

			if (!pServerItem->GetChildrenCount(false))
			{
				pQueueView->CommitChanges();
				pQueueView->RemoveItem(pServerItem, true, true, true);
			}
		}
		else
		{
			CFileItem* pFileItem = (CFileItem*)pItem;
			pFileItem->m_errorCount = 0;
			pFileItem->m_statusMessage.Clear();

			if (!pFileItem->Download() && !wxFileName::FileExists(pFileItem->GetLocalFile()))
			{
				failedToRequeueAll = true;
				RemoveItem(pItem, true, false, false);
				continue;
			}

			CServerItem* pOldServerItem = (CServerItem*)pItem->GetTopLevelItem();
			CServerItem* pServerItem = pQueueView->CreateServerItem(pOldServerItem->GetServer());
			RemoveItem(pItem, false, false, false);

			if (pFileItem->m_edit == CEditHandler::remote)
			{
				CEditHandler* pEditHandler = CEditHandler::Get();
				if (!pEditHandler)
				{
					if (!pServerItem->GetChildrenCount(false))
					{
						pQueueView->CommitChanges();
						pQueueView->RemoveItem(pServerItem, true, true, true);
					}

					failedToRequeueAll = true;
					delete pItem;
					continue;
				}
				wxFileName fn(pFileItem->GetLocalFile());
				enum CEditHandler::fileState state = pEditHandler->GetFileState(CEditHandler::remote, fn.GetFullName());
				if (state == CEditHandler::unknown)
				{
					wxASSERT(pFileItem->Download());
					if (!pEditHandler->AddFile(CEditHandler::remote, fn.GetFullName(), pFileItem->GetRemotePath(), pServerItem->GetServer()))
					{
						if (!pServerItem->GetChildrenCount(false))
						{
							pQueueView->CommitChanges();
							pQueueView->RemoveItem(pServerItem, true, true, true);
						}

						failedToRequeueAll = true;
						delete pItem;
						continue;
					}
				}
				else if (state == CEditHandler::upload_and_remove_failed)
				{
					wxASSERT(!pFileItem->Download());
					if (!pEditHandler->UploadFile(pFileItem->m_edit, fn.GetFullName(), true))
						failedToRequeueAll = true;

					if (!pServerItem->GetChildrenCount(false))
					{
						pQueueView->CommitChanges();
						pQueueView->RemoveItem(pServerItem, true, true, true);
					}

					delete pItem;
					continue;
				}
				else
				{
					if (!pServerItem->GetChildrenCount(false))
					{
						pQueueView->CommitChanges();
						pQueueView->RemoveItem(pServerItem, true, true, true);
					}

					failedToRequeueAll = true;
					delete pItem;
					continue;
				}
			}

			pItem->SetParent(pServerItem);
			pQueueView->InsertItem(pServerItem, pItem);
		}
	}
	m_fileCountChanged = true;

	pQueueView->CommitChanges();

	DisplayNumberQueuedFiles();
	SaveSetItemCount(m_itemCount);
	RefreshListOnly();

	if (!m_itemCount && m_pQueue->GetQueueView()->GetItemCount())
		m_pQueue->SetSelection(0);

	if (failedToRequeueAll)
		wxMessageBox(_("Not all items could be requeued for viewing / editing."));
}
BOOL CFriendListCtrl::OnCommand(WPARAM wParam, LPARAM /*lParam*/)
{
	wParam = LOWORD(wParam);

	CFriend* cur_friend = NULL;
	int iSel = GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
	if (iSel != -1) 
		cur_friend = (CFriend*)GetItemData(iSel);
	
	switch (wParam)
	{
		case MP_MESSAGE:
			if (cur_friend)
			{
				theApp.emuledlg->chatwnd->StartSession(cur_friend->GetClientForChatSession());
			}
			break;
		case MP_REMOVEFRIEND:
			if (cur_friend)
			{
				theApp.friendlist->RemoveFriend(cur_friend);
				// auto select next item after deleted one.
				if (iSel < GetItemCount()) {
					SetSelectionMark(iSel);
					SetItemState(iSel, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
				}
				theApp.emuledlg->chatwnd->UpdateSelectedFriendMsgDetails();
			}
			break;
		case MP_ADDFRIEND:{
			CAddFriend dialog2; 
			dialog2.DoModal();
			break;
		}
		case MP_DETAIL:
		case MPG_ALTENTER:
		case IDA_ENTER:
			if (cur_friend)
				ShowFriendDetails(cur_friend);
			break;
		case MP_SHOWLIST:
			if (cur_friend)
			{
				if (cur_friend->GetLinkedClient(true))
					cur_friend->GetLinkedClient()->RequestSharedFileList();
				else
				{
					CUpDownClient* newclient = new CUpDownClient(0, cur_friend->m_nLastUsedPort, cur_friend->m_dwLastUsedIP, 0, 0, true);
					newclient->SetUserName(cur_friend->m_strName);
					//Xman Code Improvement don't search new generated clients in lists
					/*
					theApp.clientlist->AddClient(newclient);
					*/
					theApp.clientlist->AddClient(newclient,true);
					//Xman end
					newclient->RequestSharedFileList();
				}
			}
			break;
		case MP_FRIENDSLOT:
			if (cur_friend)
			{
				bool bIsAlready = cur_friend->GetFriendSlot();
				theApp.friendlist->RemoveAllFriendSlots();
				if (!bIsAlready)
				{ //Xman
					cur_friend->SetFriendSlot(true);
					//Xman friend visualization
					UpdateFriend(iSel,cur_friend);
					//Xman end
				} //Xman
			}
			break;
		// - show requested files (sivka/Xman)
		case MP_LIST_REQUESTED_FILES:
			{ 
				if (cur_friend && cur_friend->GetLinkedClient())
				{
					cur_friend->GetLinkedClient()->ShowRequestedFiles(); 
				}
				break;
			}
		//Xman end
		// MORPH START - Added by Commander, Friendlinks [emulEspaa] - added by zz_fly
		case MP_PASTE:
		{
			CString link = theApp.CopyTextFromClipboard();
			link.Trim();
			if ( link.IsEmpty() )
				break;
			try{
				CED2KLink* pLink = CED2KLink::CreateLinkFromUrl(link);
		
				if (pLink && pLink->GetKind() == CED2KLink::kFriend )
				{
					// Better with dynamic_cast, but no RTTI enabled in the project
					CED2KFriendLink* pFriendLink = static_cast<CED2KFriendLink*>(pLink);
					uchar userHash[16];
					pFriendLink->GetUserHash(userHash);

					if ( ! theApp.friendlist->IsAlreadyFriend(userHash) )
						theApp.friendlist->AddFriend(userHash, 0U, 0U, 0U, 0U, pFriendLink->GetUserName(), 1U);
					else
					{
						CString msg;
						msg.Format(GetResString(IDS_USER_ALREADY_FRIEND), pFriendLink->GetUserName());
						AddLogLine(true, msg);
					}
				}
				if(pLink) delete pLink; //zz_fly :: memleak :: thanks DolphinX
			}
			catch(CString strError){
				AfxMessageBox(strError);
			}
		}
			break;
        case MP_GETFRIENDED2KLINK:
		{
			CString sCompleteLink;
			if ( cur_friend && cur_friend->HasUserhash() )
			{
				CString sLink;
				CED2KFriendLink friendLink(cur_friend->m_strName, cur_friend->m_abyUserhash);
				friendLink.GetLink(sLink);
				if ( !sCompleteLink.IsEmpty() )
					sCompleteLink.Append(_T("\r\n"));
				sCompleteLink.Append(sLink);
			}

			if ( !sCompleteLink.IsEmpty() )
				theApp.CopyTextToClipboard(sCompleteLink);
		}
			break;
		case MP_GETHTMLFRIENDED2KLINK:
		{
			CString sCompleteLink;
			
			if ( cur_friend && cur_friend->HasUserhash() )
			{
				CString sLink;
				CED2KFriendLink friendLink(cur_friend->m_strName, cur_friend->m_abyUserhash);
				friendLink.GetLink(sLink);
				sLink = _T("<a href=\"") + sLink + _T("\">") + StripInvalidFilenameChars(cur_friend->m_strName) + _T("</a>");
				if ( !sCompleteLink.IsEmpty() )
					sCompleteLink.Append(_T("\r\n"));
				sCompleteLink.Append(sLink);
			}
			
			if ( !sCompleteLink.IsEmpty() )
				theApp.CopyTextToClipboard(sCompleteLink);
		}
			break;
		// MORPH END - Added by Commander, Friendlinks [emulEspaa]

		case MP_FIND:
			OnFindStart();
			break;
	}
	return true;
}
void CSourcesListBox::UpdateSel( size_t index )
{

	///HACK///
	static bool bInFunction = false;
	if(	bInFunction )
		return;
	bInFunction = true;
    wxBusyCursor  busycursor;
	if((index == (size_t)-2) || (index == (size_t)-4))
	{	// IF -2, this is used to protect playlists from being accidently changed
		// if -4 we actually want to change ciew(not only selection)

		bInFunction = (index == (size_t)-4); // HACK!!,
        m_CurSel = FindInSources(wxT( "" ),MUSIK_SOURCES_LIBRARY);
        SuppressListItemStateEvents( (index == (size_t)-4) ) ;
		SetItemState( m_CurSel, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
        SuppressListItemStateEvents(false);
		bInFunction = false;
		return;
    }
	if(index == (size_t)-3)
	{	//select now playing
		bInFunction = false;// HACK!!, this leads to recursive execution of this function (	call of SetItemState() will generate an event)
        int sel = FindInSources(wxT( "Now Playing" ),MUSIK_SOURCES_NOW_PLAYING);
		SetItemState( sel, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
		return;
    }

	//--- save std playlist. if deleting, no need to worry ---//
	int nLastSel = m_CurSel;
	if ( !m_Deleting )
	{
		if ( GetType( nLastSel ) == MUSIK_SOURCES_PLAYLIST_STANDARD )
			RewriteStdPlaylist();
	}
	
	m_CurSel = index;
	int nSelType = GetSelType();

	if ( m_CurSel == -1 )
	{
		SetItemState( nLastSel, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
		m_CurSel = nLastSel;
	}

	//--- library selected ---//
	else if ( nSelType == MUSIK_SOURCES_LIBRARY )
	{
		g_ActivityAreaCtrl->UpdateSel( g_ActivityAreaCtrl->GetParentBox() );
		g_MusikFrame->ShowActivityArea( wxGetApp().Prefs.bShowActivities );
		g_PlaylistBox->ShowSearchBox(true);
	}

	else 
	{
		g_MusikFrame->ShowActivityArea( false );
		g_PlaylistBox->ShowSearchBox(false);
		//--- standard playlist selected ---//
		if (m_CurSel != -1 && nSelType == MUSIK_SOURCES_PLAYLIST_STANDARD )
		{
			LoadStdPlaylist( GetItemText( m_CurSel ), g_thePlaylist );
		}

		//--- dynamic playlist selected ---//
		else if (  m_CurSel != -1 && nSelType == MUSIK_SOURCES_PLAYLIST_DYNAMIC )
		{
			wxString sQuery = LoadDynPlaylist( GetItemText( m_CurSel ) );
			RealizeDynPlaylist(sQuery,g_thePlaylist);
		}
		else if ( m_CurSel != -1 && nSelType == MUSIK_SOURCES_NETSTREAM )
		{
			MusikSongIdArray urlids;
            wxString sDummy;
			LoadNetStream(GetItemText( m_CurSel ), sDummy,&urlids);
			g_thePlaylist = urlids;
		}
		else if ( m_CurSel != -1 && nSelType == MUSIK_SOURCES_NOW_PLAYING )
		{
			g_PlaylistBox->SetPlaylist( &wxGetApp().Player.GetPlaylist());
			g_PlaylistBox->PlaylistCtrl().EnsureVisible(wxGetApp().Player.GetCurIndex());
			bInFunction = false;
			return;
		}
		//--- update ui with new list ---//
		g_PlaylistBox->SetPlaylist(&g_thePlaylist);
	}
	bInFunction = false;
}
Exemple #12
0
void CTreeCtrlEx::SetCheck(HTREEITEM hItem, BOOL bCheck)
{
	SetItemState (hItem, INDEXTOSTATEIMAGEMASK ((bCheck ? 2 : 1)), TVIS_STATEIMAGEMASK);
}
BOOL COXNetBrowseTree::CreateChildren(HTREEITEM hParentItem, NETRESOURCE* pParentNetResources)
// --- In  : hParentItem : Node of which the children nodes have to be created
//			 pParentNetResources : Net resource of this parent node
// --- Out : 
// --- Returns :
// --- Effect : Computes the netresources of the children and creates the child nodes
{
	HANDLE hEnum = NULL;
	DWORD dwScope = pParentNetResources == NULL ? m_nResourceScope : pParentNetResources->dwScope;
	DWORD nResult = WNetOpenEnum(
		dwScope,				// scope of enumeration 
		RESOURCETYPE_ANY,		// resource types to list 
		0,						// resource usage to list 
		pParentNetResources,	// pointer to resource structure 
		&hEnum);				// pointer to enumeration handle buffer 
	if (nResult != NO_ERROR)
	{
		TRACE2("COXNetBrowseTree::CreateChildren : WNetOpenEnum failed with error code %i == 0x%X\n",
			nResult, nResult);
		ReportNetError(nResult, pParentNetResources == NULL ? NULL : pParentNetResources->lpRemoteName);
		return FALSE;
	}

	DWORD nCurrentCount(0);
	DWORD nCurrentSkipCount(0);
	/* =============================================================================== */	

	// The problem with the WNetEnumResoiurce fuction is that allthough you use 
	// 0xFFFFFFFF as requested resource count (this means everything) the function
	// does NOT return ERROR_MORE_DATA if the buffer is too small.  It only returns
	// this value if the buffer supplied is too small even for one value, in this
	// case the space needed to hold the first resource found in the enumeration
	// Normally the size of this resource should be sizeof(NETRESOURCE) which is 
	// 32 bytes but experience learned that this fluctuates between 32 bytes and 
	// more than 1000 bytes.  This is probably due to the fact that WNetEnumResource
	// also needs allocated memory for the strings inside the NETRESOURCE struct.
	// This leads to the conclusion that we cannot calculate with certainty the size
	// of the buffer we need for a certain number of resources.  The most robust
	// solution to this problem is to request a absolute number of resources, make
	// an serious and realistic estimation of the maximum amount of memory needed
	// to hold ALL requested resources and then test to see whether you have retrieved
	// all requested resources.  If this is TRUE then again enumerate the resources
	// to determine whether there aren't any left and so on until the returned
	// number of resources is smaller than the requested number.  This last remark
	// explains why we need to be sure that the requested number of resources 
	// allways fit in the amount of memory we allocated for the buffer.  We could 
	// alocated a very big buffer but we prefer the loop.

	// Also note that we don't use NETRESOURCE* pRes = new NETRESOURCE[Count]
	// because the array allocated will be an array of structs of size sizeof(NETRESOURCE)
	// and that's just not correct to  hold one netresource. That's why we use
	// GlobalAlloc.

	// USERS WHO WANT TO TUNE THE PERFORMANCE OF THIS FUNCTION CAN PLAY WITH THE 
	// NUMBER OF NETRESOURCES VIA THE nCOUNT VARIABLE AND WITH THE SIZE OF THE 
	// ALLOCATED BUFFER VIA THE nBUFFERSIZE VARIABLE BUT KEEP THE REMARKS ABOVE
	// IN MIND.
	/* =============================================================================== */
	// Start with a reasonable buffer size
	DWORD nCount = 5;
	DWORD nBufferSize = 5000;
	LPNETRESOURCE rgpNetResources = (LPNETRESOURCE)GlobalAlloc(GPTR, nBufferSize);

	while (TRUE)
	{
		DWORD nTempCount = nCount;
		DWORD nTempBufferSize = nBufferSize;
		memset(rgpNetResources, 0, nBufferSize);
		DWORD nResult2 = WNetEnumResource(
			hEnum,					// handle to enumeration 
			&nTempCount,				// pointer to entries to list 
			(LPVOID)rgpNetResources, // pointer to buffer for results 
			&nTempBufferSize);			// pointer to buffer size variable 
		TRACE2("COXNetBrowseTree::WNetEnumResource : Number of Netresources (%i), in buffersize (0x%X)\n", nTempCount, nTempBufferSize);

		if ((nResult2 != NO_ERROR) && (nResult2 != ERROR_NO_MORE_ITEMS) &&
			(nResult2 != ERROR_MORE_DATA))
		{
			TRACE2("COXNetBrowseTree::CreateChildren : WNetEnumResource failed with error code %i == 0x%X\n",
				nResult2, nResult2);
			ReportNetError(nResult2, pParentNetResources == NULL ? NULL : pParentNetResources->lpRemoteName);
			// ... Cleanup the handle and memeory allocated
			VERIFY(WNetCloseEnum(hEnum) == NO_ERROR);
			GlobalFree((HGLOBAL)rgpNetResources);
			return FALSE;
		}

		if (nResult2 == ERROR_NO_MORE_ITEMS)
			nTempCount = 0;

		// Loop the requested number of NetResources and make tree item nodes
		{
			HTREEITEM hNewItem;
			NETRESOURCE* pSourceNetResource = NULL;
			NETRESOURCE* pCopyNetResource = NULL;
			DWORD nIndex;
			DWORD nSkipCount = 0;
			for (nIndex = 0; nIndex < nTempCount; nIndex++)
			{
				pSourceNetResource  = &rgpNetResources[nIndex];

				// Check special case for disks and printers
				if ((pSourceNetResource->dwType == RESOURCETYPE_DISK) && !m_bShowDisks)
				{
					// Skip this item
					nSkipCount++;
					continue;
				}
				if ((pSourceNetResource->dwType == RESOURCETYPE_PRINT) && !m_bShowPrinters)
				{
					// Skip this item
					nSkipCount++;
					continue;
				}

				// ... Create a new item
				hNewItem = InsertResourceItem(pSourceNetResource, hParentItem);
				if (hNewItem  == NULL)
				{
					TRACE0("COXNetBrowseTree::InsertResourceItem returned NULL\n");
					// Skip this item
					nSkipCount++;
					continue;
				}

				// Add a copy to the map
				// ... Should not yet be in map
#ifdef _DEBUG
				NETRESOURCE* pCheckNetResource = NULL;
				ASSERT(!m_resourceMap.Lookup(hNewItem, pCheckNetResource));
#endif // _DEBUG
				pCopyNetResource = new NETRESOURCE;
				// ... Copy the struct itself
				memcpy(pCopyNetResource, pSourceNetResource, sizeof(NETRESOURCE));
				// ... Make a copy of all the string members
				if (pSourceNetResource->lpLocalName != NULL)
				{
					size_t len = _tcslen(pSourceNetResource->lpLocalName) + 1;
					pCopyNetResource->lpLocalName = new TCHAR[len];
					UTBStr::tcscpy(pCopyNetResource->lpLocalName, len, pSourceNetResource->lpLocalName);
				}
				else
				{
					pCopyNetResource->lpLocalName = new TCHAR[1];
					*pCopyNetResource->lpLocalName = _T('\0');
				}

				if (pSourceNetResource->lpRemoteName != NULL)
				{
					size_t len = _tcslen(pSourceNetResource->lpRemoteName) + 1;
					pCopyNetResource->lpRemoteName = new TCHAR[len];
					UTBStr::tcscpy(pCopyNetResource->lpRemoteName, len, pSourceNetResource->lpRemoteName);
				}
				else
				{
					pCopyNetResource->lpRemoteName = new TCHAR[1];
					*pCopyNetResource->lpRemoteName = _T('\0');
				}

				if (pSourceNetResource->lpComment != NULL)
				{
					size_t len = _tcslen(pSourceNetResource->lpComment) + 1;
					pCopyNetResource->lpComment = new TCHAR[len];
					UTBStr::tcscpy(pCopyNetResource->lpComment, len, pSourceNetResource->lpComment);
				}
				else
				{
					pCopyNetResource->lpComment = new TCHAR[1];
					*pCopyNetResource->lpComment = _T('\0');
				}

				if (pSourceNetResource->lpProvider != NULL)
				{
					size_t len = _tcslen(pSourceNetResource->lpProvider) + 1;
					pCopyNetResource->lpProvider = new TCHAR[len];
					UTBStr::tcscpy(pCopyNetResource->lpProvider, len, pSourceNetResource->lpProvider);
				}
				else
				{
					pCopyNetResource->lpProvider = new TCHAR[1];
					*pCopyNetResource->lpProvider = _T('\0');
				}

				// ... Add to map
				m_resourceMap.SetAt(hNewItem, pCopyNetResource);
			}

			// we need to keep track of the real number of nodes because we 
			// need it to set the correct treeitem number for the parent node
			nCurrentCount += nTempCount;
			nCurrentSkipCount += nSkipCount;

			if (hParentItem != NULL)
			{
				// Mark the parent node as expanded at least once
				VERIFY(SetItemState(hParentItem, TVIS_EXPANDEDONCE, TVIS_EXPANDEDONCE));

				// Set the number of child items to the correct value
				TV_ITEM item;
				item.hItem = hParentItem;
				item.mask = TVIF_CHILDREN;
				ASSERT(nSkipCount <= nTempCount);
				item.cChildren = nCurrentCount - nCurrentSkipCount;
				VERIFY(SetItem(&item));
			}
		}

		if (nResult2 == ERROR_MORE_DATA  || nTempCount == nCount)
			// Possibly there is more data to retrieve
		{
			nTempCount = nCount;
			continue;
		}
		else
			// There was no error and there isn't anymore data to retrieve
			break;
	}

	// Cleanup the handle and allocated memory
	VERIFY(WNetCloseEnum(hEnum) == NO_ERROR);
	GlobalFree((HGLOBAL)rgpNetResources);
	return TRUE;
}
Exemple #14
0
void CGameListCtrl::OnRightClick(wxMouseEvent& event)
{
	// Focus the clicked item.
	int flags;
	long item = HitTest(event.GetPosition(), flags);
	if (item != wxNOT_FOUND)
	{
		if (GetItemState(item, wxLIST_STATE_SELECTED) != wxLIST_STATE_SELECTED)
		{
			UnselectAll();
			SetItemState(item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
		}
		SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
	}
	if (GetSelectedItemCount() == 1)
	{
		const GameListItem* selected_iso = GetSelectedISO();
		if (selected_iso)
		{
			wxMenu popupMenu;
			DiscIO::IVolume::EPlatform platform = selected_iso->GetPlatform();

			if (platform != DiscIO::IVolume::ELF_DOL)
			{
				popupMenu.Append(IDM_PROPERTIES, _("&Properties"));
				popupMenu.Append(IDM_GAME_WIKI, _("&Wiki"));
				popupMenu.AppendSeparator();
			}
			if (platform == DiscIO::IVolume::WII_DISC || platform == DiscIO::IVolume::WII_WAD)
			{
				popupMenu.Append(IDM_OPEN_SAVE_FOLDER, _("Open Wii &save folder"));
				popupMenu.Append(IDM_EXPORT_SAVE, _("Export Wii save (Experimental)"));
			}
			popupMenu.Append(IDM_OPEN_CONTAINING_FOLDER, _("Open &containing folder"));

			if (platform != DiscIO::IVolume::ELF_DOL)
				popupMenu.AppendCheckItem(IDM_SET_DEFAULT_ISO, _("Set as &default ISO"));

			// First we have to decide a starting value when we append it
			if (platform == SConfig::GetInstance().m_strDefaultISO)
				popupMenu.FindItem(IDM_SET_DEFAULT_ISO)->Check();

			popupMenu.AppendSeparator();
			popupMenu.Append(IDM_DELETE_ISO, _("&Delete File..."));

			if (platform == DiscIO::IVolume::GAMECUBE_DISC || platform == DiscIO::IVolume::WII_DISC)
			{
				if (selected_iso->GetBlobType() == DiscIO::BlobType::GCZ)
					popupMenu.Append(IDM_COMPRESS_ISO, _("Decompress ISO..."));
				else if (selected_iso->GetBlobType() == DiscIO::BlobType::PLAIN)
					popupMenu.Append(IDM_COMPRESS_ISO, _("Compress ISO..."));

				wxMenuItem* changeDiscItem = popupMenu.Append(IDM_LIST_CHANGE_DISC, _("Change &Disc"));
				changeDiscItem->Enable(Core::IsRunning());
			}

			if (platform == DiscIO::IVolume::WII_WAD)
				popupMenu.Append(IDM_LIST_INSTALL_WAD, _("Install to Wii Menu"));

			PopupMenu(&popupMenu);
		}
	}
	else if (GetSelectedItemCount() > 1)
	{
		wxMenu popupMenu;
		popupMenu.Append(IDM_DELETE_ISO, _("&Delete selected ISOs..."));
		popupMenu.AppendSeparator();
		popupMenu.Append(IDM_MULTI_COMPRESS_ISO, _("Compress selected ISOs..."));
		popupMenu.Append(IDM_MULTI_DECOMPRESS_ISO, _("Decompress selected ISOs..."));
		PopupMenu(&popupMenu);
	}
}
void CDrivesList::SelectItem(CDriveItem *item)
{
	int i= FindListItem(item);
	SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
}
Exemple #16
0
//取消选中一行
BOOL CMyCListCtrl::SMT_CancelSelectRow( int nIndex)
{		
    return SetItemState(nIndex, 0, LVIS_SELECTED|LVIS_FOCUSED);	
}
Exemple #17
0
void wxListCtrlEx::HandlePrefixSearch(wxChar character)
{
	wxASSERT(character);

	// Keyboard navigation within items
	wxDateTime now = wxDateTime::UNow();
	if (m_prefixSearch_lastKeyPress.IsValid())
	{
		wxTimeSpan span = now - m_prefixSearch_lastKeyPress;
		if (span.GetSeconds() >= 1)
			m_prefixSearch_prefix = _T("");
	}
	m_prefixSearch_lastKeyPress = now;

	wxString newPrefix = m_prefixSearch_prefix + character;

	int item;
#ifndef __WXMSW__
	// GetNextItem is O(n) if nothing is selected, GetSelectedItemCount() is O(1)
	if (!GetSelectedItemCount())
		item = -1;
	else
#endif
	{
		item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
	}

	bool beep = false;
	if (item != -1)
	{
		wxString text = GetItemText(item, 0);
		if (text.Length() >= m_prefixSearch_prefix.Length() && !m_prefixSearch_prefix.CmpNoCase(text.Left(m_prefixSearch_prefix.Length())))
			beep = true;
	}
	else if (m_prefixSearch_prefix.empty())
		beep = true;

	int start = item;
	if (start < 0)
		start = 0;

	int newPos = FindItemWithPrefix(newPrefix, start);

	if (newPos == -1 && (m_prefixSearch_prefix.Len() == 1 && m_prefixSearch_prefix[0] == character) && item != -1 && beep) {
		// Search the next item that starts with the same letter
		newPrefix = m_prefixSearch_prefix;
		newPos = FindItemWithPrefix(newPrefix, item + 1);
	}

	m_prefixSearch_prefix = newPrefix;
	if (newPos == -1)
	{
		if (beep)
			wxBell();
		return;
	}

	while (item != -1)
	{
		SetItemState(item, 0, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
		item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
	}
	SetItemState(newPos, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);

#ifdef __WXMSW__
	// SetItemState does not move the selection mark, that is the item from
	// which a multiple selection starts (e.g. shift+up/down)
	HWND hWnd = (HWND)GetHandle();
	::SendMessage(hWnd, LVM_SETSELECTIONMARK, 0, newPos);
#endif

	EnsureVisible(newPos);
}
Exemple #18
0
void CBOINCListCtrl::SelectRow(int row, bool setSelected) {
    SetItemState(row,  setSelected ? wxLIST_STATE_SELECTED : 0, wxLIST_STATE_SELECTED);
}
LRESULT CClientListCtrl::OnP4EndSpecEdit( WPARAM wParam, LPARAM lParam )
{
	CCmd_EditSpec *pCmd= (CCmd_EditSpec *) wParam;
	BOOL chainedCommand = FALSE;
	BOOL need2Refresh = FALSE;

	if (lParam != IDCANCEL && lParam != IDABORT)
	{
		// Get the Sync flag
		int syncAfter = SYNC_DONT;
		BOOL bHasChgs = TRUE;
		if (m_PrevNbrCli < 1)
		{
			int key= pCmd->HaveServerLock() ? pCmd->GetServerKey() : 0;
			CCmd_Changes *pCmd2= new CCmd_Changes;
			pCmd2->Init( m_hWnd, RUN_SYNC, key ? HOLD_LOCK : LOSE_LOCK, key);
			if( pCmd2->Run(SUBMITTED_CHANGES, FALSE, NULL, 1) )
			{
				if (!pCmd2->GetChanges()->GetCount())
					bHasChgs = FALSE;
			}
			delete pCmd2;
		}
		if (m_isNew && !GET_P4REGPTR()->DontShowYouHaveCr8NewClient() && bHasChgs)
		{
			BOOL b;
			switch(MsgBox(IDS_YOU_HAVE_CREATED_NEW_CLIENT,
						MB_ICONEXCLAMATION | MB_DEFBUTTON1, 0, this, &b))
			{
			case IDC_BUTTON1:
				syncAfter = SYNC_HEAD;
				break;
			case IDC_BUTTON2:
				syncAfter = SYNC_DONT;
				break;
			}
			GET_P4REGPTR()->SetDontShowYouHaveCr8NewClient(b);
		}
		else if ((pCmd->IsSyncAfter() || pCmd->IsAutoUpdateSpec())
			  && !GET_P4REGPTR()->DontShowYouHaveChgClientView() && bHasChgs)
		{
			BOOL b;
			switch(MsgBox(pCmd->IsAutoUpdateSpec() ? IDS_DOYOUWANTOTSYNCYOURNEWCLIENT 
												   : IDS_YOU_HAVE_CHANGED_CLIENTS_VIEW,
												   MB_ICONQUESTION | MB_DEFBUTTON1, 0, this, 
												   pCmd->IsAutoUpdateSpec() ? NULL : &b))
			{
			case IDC_BUTTON1:
				syncAfter = SYNC_HEAD;
				break;
			case IDC_BUTTON2:
				syncAfter = pCmd->IsAutoUpdateSpec() ? SYNC_DONT : SYNC_HAVE;
				break;
			case IDC_BUTTON3:
				syncAfter = SYNC_DONT;
				break;
			}
			if (!pCmd->IsAutoUpdateSpec())
				GET_P4REGPTR()->SetDontShowYouHaveChgClientView(b);
		}

		BOOL bDeld = FALSE;
		if (m_UpdateState == LIST_UPDATED)
		{
			// we have to set 'index' again in case client's name got changed
			int index= FindInList(m_pNewSpec->GetClientName());
			int ixAll= FindInListAll(m_pNewSpec->GetClientName());
			if (ixAll == -1)	// not in either list
			{
				ASSERT(index == -1);
				CString curclient = GET_P4REGPTR()->GetP4Client();
				CString defclient = GET_P4REGPTR()->GetP4Client(TRUE);
				InsertClient(m_pNewSpec, GetItemCount(), &curclient, &defclient);
			}
			else if (index > -1)	// in both lists
			{
				ASSERT(ixAll > -1);
				if (MainFrame()->IsClientFilteredOut(m_pNewSpec))	// should it no longer be shown?
				{
					need2Refresh = TRUE;
					delete m_pNewSpec;
				}
				else
				{
					UpdateClient(m_pNewSpec, index);
					UpdateClientAll(m_pNewSpec, ixAll);
				}
			}
			else	// not in visible list; is in list of all
			{
				if (MainFrame()->IsClientFilteredOut(m_pNewSpec))	// should it now be shown?
					need2Refresh = TRUE;
				else
					UpdateClientAll(m_pNewSpec, ixAll);
				if (pCmd->IsAutoUpdateSpec())
					m_OldClient = m_pNewSpec->GetClientName();
				delete m_pNewSpec;
				bDeld = TRUE;
			}
			ReSort();
			if (pCmd->IsAutoUpdateSpec() || pCmd->IsSpecForceSwitch())
			{
				if (bDeld)
					need2Refresh = TRUE;
				else
				{
					int i = FindInList(m_OldClient = m_pNewSpec->GetClientName());
					if (i < 0)	
						i = 0;
					SetItemState(i, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
					EnsureVisible(i, FALSE);
				}
				m_Active = _T("@");			// force switch to new client
			}
		}
		else
			if ( m_pNewSpec ) delete m_pNewSpec;

		int key= pCmd->HaveServerLock() ? pCmd->GetServerKey() : 0;
		if( m_Active == m_saveclientnew )	// active-client == saved new client name
			m_OldClient = m_saveclientnew;	//   means they decided to edit the current client
		if( m_Active != m_OldClient )		// If current client is not now the client when this
		{									//   all started, switch to the new current client
			if (GET_P4REGPTR()->GetExpandFlag() == 1)
				GET_P4REGPTR()->AddMRUPcuPath(MainFrame()->GetCurrentItemPath());
			m_Active = m_OldClient;
			GET_P4REGPTR()->SetP4Client( m_Active, TRUE, FALSE, FALSE);
			MainFrame()->UpdateCaption( );
			if (syncAfter)
				chainedCommand = SyncAfter(key, syncAfter);
        }
		else if( syncAfter || GET_P4REGPTR()->GetClearAndReload()
				|| AfxMessageBox(IDS_YOU_HAVE_UPDATED_YOUR_CLIENT_WORKSPACE__CLEAR_AND_RELOAD, 
								MB_YESNO |MB_ICONQUESTION ) == IDYES )
		{
			if (syncAfter)
				chainedCommand = SyncAfter(key, syncAfter);
			else
			{
				int key= pCmd->HaveServerLock() ? pCmd->GetServerKey() : 0;
				MainFrame()->UpdateDepotandChangeViews(REDRILL, key);
				chainedCommand=TRUE;
			}
		}
		if (GET_SERVERLEVEL() >= 22)
			TheApp()->Set_m_ClientSubOpts(TheApp()->GetClientSpecField( _T("SubmitOptions"), pCmd->GetSpecOut()));
    }
	else
	{
		if ( m_pNewSpec )
			delete m_pNewSpec;
		if (lParam == IDCANCEL && pCmd->GetIsRequestingNew())
		{
			m_Active = pCmd->GetOldClient();	// switch back to the previous client
			GET_P4REGPTR()->SetP4Client( m_Active, TRUE, FALSE, FALSE);
			MainFrame()->UpdateCaption( );
		}
	}

	if (lParam != IDABORT)
	{
		MainFrame()->ClearStatus();
		if (!chainedCommand && pCmd->HaveServerLock())
			pCmd->ReleaseServerLock();
		CDialog *dlg = (CDialog *)pCmd->GetSpecSheet();
		dlg->DestroyWindow();
	}
	delete pCmd;
	m_EditInProgress = FALSE;

	if (need2Refresh && !chainedCommand)
		OnViewUpdate();

	if (TheApp()->m_RunClientWizOnly && !chainedCommand)
		::PostMessage(MainFrame()->m_hWnd, WM_COMMAND, ID_APP_EXIT, 0);
	return 0;
}
void CLibraryFolderCtrl::Update(CLibraryFolder* pFolder, HTREEITEM hFolder, HTREEITEM hParent, DWORD nUpdateCookie, BOOL bRecurse)
{
	if ( ! hFolder )
	{
		DWORD dwStyle = INDEXTOOVERLAYMASK( pFolder->IsShared() ? 0 : SHI_OVERLAY_LOCKED );

		if ( pFolder->m_sPath.CompareNoCase( Settings.Downloads.CompletePath ) == 0 ) dwStyle |= TVIS_BOLD;

		if ( m_bMultiSelect && GetFirstSelectedItem() == NULL ) dwStyle |= TVIS_SELECTED;
		if ( pFolder->m_bExpanded ) dwStyle |= TVIS_EXPANDED;

		CString strName = pFolder->m_sName;

		if ( pFolder->m_pParent == NULL )
		{
			if ( pFolder->m_sPath[1] == _T(':') )
				strName += _T("  (") + pFolder->m_sPath.Left( 1 ) + _T(":)");
			else if ( pFolder->m_sPath[1] == _T('\\') )
				strName += _T("  (") + pFolder->m_sPath.Mid( 2, pFolder->m_sPath.Find( L'\\', 3 ) - 2 ) + _T(")");

			dwStyle |= TVIS_EXPANDED;
		}

		hFolder = InsertItem( TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_STATE,
			strName, SHI_FOLDER_CLOSED, SHI_FOLDER_CLOSED, dwStyle,
			TVIS_EXPANDED|TVIS_SELECTED|TVIS_OVERLAYMASK, (LPARAM)pFolder, hParent, TVI_SORT );
	}
	else
	{
		DWORD dwMask  = TVIS_OVERLAYMASK|TVIS_BOLD;
		DWORD dwStyle = INDEXTOOVERLAYMASK( pFolder->IsShared() ? 0 : SHI_OVERLAY_LOCKED );

		if ( pFolder->m_sPath.CompareNoCase( Settings.Downloads.CompletePath ) == 0 ) dwStyle |= TVIS_BOLD;

		DWORD dwExisting = GetItemState( hFolder, dwMask ) & dwMask;

		if ( dwExisting != dwStyle ) SetItemState( hFolder, dwStyle, dwMask );
	}

	if ( nUpdateCookie )
	{
		if ( bRecurse || ( GetItemState( hFolder, TVIS_SELECTED ) & TVIS_SELECTED ) )
		{
			pFolder->m_nSelectCookie = nUpdateCookie;
			bRecurse |= ( GetItemState( hFolder, TVIS_EXPANDED ) & TVIS_EXPANDED ) == 0;
		}
	}

	CList< CLibraryFolder* > pAlready;

	for ( HTREEITEM hItem = GetChildItem( hFolder ) ; hItem ; )
	{
		HTREEITEM hNext = GetNextSiblingItem( hItem );

		CLibraryFolder* pChild = (CLibraryFolder*)GetItemData( hItem );

		if ( pFolder->CheckFolder( pChild ) )
		{
			Update( pChild, hItem, NULL, nUpdateCookie, bRecurse );
			pAlready.AddTail( pChild );
		}
		else
		{
			DeleteItem( hItem );
		}

		hItem = hNext;
	}

	for ( POSITION pos = pFolder->GetFolderIterator() ; pos ; )
	{
		CLibraryFolder* pChild = pFolder->GetNextFolder( pos );

		if ( pAlready.Find( pChild ) == NULL )
			Update( pChild, NULL, hFolder, nUpdateCookie, bRecurse );
	}

	int nOldImage1, nOldImage2;
	GetItemImage( hFolder, nOldImage1, nOldImage2 );

	int nImage = ItemHasChildren( hFolder ) && ( GetItemState( hFolder, TVIS_EXPANDED ) & TVIS_EXPANDED );
	nImage = nImage ? SHI_FOLDER_OPEN : SHI_FOLDER_CLOSED;
	if ( nOldImage1 != nImage ) SetItemImage( hFolder, nImage, nImage );
}
Exemple #21
0
void CTreeCtrlEx::SetItemBold(HTREEITEM hItem, BOOL bBold)
{
	SetItemState(hItem, bBold ? TVIS_BOLD: 0, TVIS_BOLD);
}
void CLibraryFolderCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
	UINT nItemFlags = 0;
	HTREEITEM hItem = HitTest( point, &nItemFlags );

	if ( nItemFlags == TVHT_ONITEMBUTTON )
	{
		CTreeCtrl::OnLButtonDown( nFlags, point );
		return;
	}

	if ( ( nFlags & MK_CONTROL ) && m_bMultiSelect )
	{
		if ( hItem )
		{
			UINT nNewState = GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED ?
				0 : TVIS_SELECTED;

			SetItemState( hItem, nNewState, TVIS_SELECTED );
			m_hFirstSelected = NULL;
			NotifySelectionChanged();
		}
	}
	else if ( ( nFlags & MK_SHIFT ) && m_bMultiSelect )
	{
		hItem = HitTest( point );

		if ( ! m_hFirstSelected )
			m_hFirstSelected = GetFirstSelectedItem();

		if ( hItem )
			SetItemState( hItem, TVIS_SELECTED, TVIS_SELECTED );

		if ( m_hFirstSelected )
			SelectItems( m_hFirstSelected, hItem );

		NotifySelectionChanged();
	}
	else
	{
		BOOL bChanged = FALSE;
		BOOL bSelected = hItem && ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED );

		if ( ! bSelected || ( nFlags & MK_RBUTTON ) == 0 )
		{
			if ( m_bFirstClick && hItem != GetRootItem() )
				Select( hItem, TVGN_CARET );

			bChanged = ClearSelection( hItem );
			m_hFirstSelected = NULL;
		}

		if ( hItem && ! bSelected )
		{
			SetItemState( hItem, TVIS_SELECTED, TVIS_SELECTED );
			bChanged = TRUE;
		}

		if ( bChanged )
			NotifySelectionChanged();
	}

	m_bFirstClick = FALSE;

	SetFocus();
}
Exemple #23
0
void CMuleListCtrl::SortList()
{
	if (!IsSorting() && (m_sort_func && GetColumnCount())) {

		m_isSorting = true;

		MuleSortData sortdata(m_sort_orders, m_sort_func);

		// In many cases control already has correct order, and sorting causes nasty flickering.
		// Make one pass through it to check if sorting is necessary at all.
		int nrItems = GetItemCount();
		bool clean = true;
		long lastItemdata = 0;
		if (nrItems > 1) {
			lastItemdata = GetItemData(0);
		}
		for (int i = 1; i < nrItems; i++) {
			long nextItemdata = GetItemData(i);
			if (SortProc(lastItemdata, nextItemdata, (long int)&sortdata) > 0) {
				// ok - we need to sort
				clean = false;
				break;
			}
			lastItemdata = nextItemdata;
		}
		if (clean) {
			// no need to sort
			m_isSorting = false;
			return;
		}

		// Positions are likely to be invalid after sorting.
		ResetTTS();

		// Store the current selected items
		ItemDataList selectedItems = GetSelectedItems();
		// Store the focused item
		long pos = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED );
		wxUIntPtr focused = (pos == -1) ? 0 : GetItemData(pos);

		SortItems(SortProc, (long int)&sortdata);

		// Re-select the selected items.
		for (unsigned i = 0; i < selectedItems.size(); ++i) {
			long it_pos = FindItem(-1, selectedItems[i]);
			if (it_pos != -1) {
				SetItemState(it_pos, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
			}
		}

		// Set focus on item if any was focused
		if (focused) {
			long it_pos = FindItem(-1, focused);
			if (it_pos != -1) {
				SetItemState(it_pos, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
			}
		}

		m_isSorting = false;
	}
}
bool CPageNavigator::SelectPage(int nPage, bool bSetState)
{
	if (!m_hWnd || !m_pAGDoc)
		return false;

	int nPages = m_pAGDoc->GetNumPages();
	if (nPage < 0 || nPage >= nPages)
		return false;

	if (m_nPage == nPage)
		return false;

	// Reset the image of the old selected page
	if (m_nPage >= 0)
	{
		LV_ITEM lvItem;
		::ZeroMemory(&lvItem, sizeof(lvItem));
		lvItem.mask = LVIF_IMAGE;
		lvItem.iItem = m_nPage;
		GetItem(&lvItem);
		if (lvItem.iImage >= nPages)
		{
			lvItem.mask = LVIF_IMAGE;
			lvItem.iImage -= nPages;
			SetItem(&lvItem);
		}
	}

	m_nPage = nPage;

	// Set the image of the newly selected page
	if (m_nPage >= 0)
	{
		LV_ITEM lvItem;
		::ZeroMemory(&lvItem, sizeof(lvItem));
		lvItem.mask = LVIF_IMAGE;
		lvItem.iItem = m_nPage;
		GetItem(&lvItem);
		if (lvItem.iImage < nPages)
		{
			lvItem.mask = LVIF_IMAGE;
			lvItem.iImage += nPages;
			SetItem(&lvItem);
		}
	}

	// Set the page name into the static label control
	CString strPageName;
	CAGPage* pPage = m_pAGDoc->GetPage(m_nPage);
	if (pPage)
		pPage->GetPageName(strPageName);

	if (::IsWindow(m_LabelPage.m_hWnd))
		m_LabelPage.SetText(strPageName);

	// Scroll the page into position, if necessary
	EnsureIconVisible(m_nPage);

	// Select the list control item
	if (bSetState)
		SetItemState(m_nPage, LVIS_SELECTED, LVIS_SELECTED|LVIS_FOCUSED);

	// Show or hide the next/prev buttons as necessary
	bool bNormalCard = m_bIsCard && (nPages <= 4);
	int nCmdShowPrev = (bNormalCard ? SW_HIDE : (nPage <= 0 ? SW_HIDE : SW_SHOW));
	int nCmdShowNext = (bNormalCard ? SW_HIDE : (nPage >= nPages - 1 ? SW_HIDE : SW_SHOW));
	::ShowWindow(m_hWndPrevButton, nCmdShowPrev);
	::ShowWindow(m_hWndNextButton, nCmdShowNext);

	return true;
}
Exemple #25
0
void CGameListCtrl::OnRightClick(wxMouseEvent& event)
{
    // Focus the clicked item.
    int flags;
    long item = HitTest(event.GetPosition(), flags);
    if (item != wxNOT_FOUND)
    {
        if (GetItemState(item, wxLIST_STATE_SELECTED) != wxLIST_STATE_SELECTED)
        {
            UnselectAll();
            SetItemState(item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
        }
        SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
    }
    if (GetSelectedItemCount() == 1)
    {
        const GameListItem *selected_iso = GetSelectedISO();
        if (selected_iso)
        {
            wxMenu* popupMenu = new wxMenu;
            popupMenu->Append(IDM_PROPERTIES, _("&Properties"));
            popupMenu->Append(IDM_GAMEWIKI, _("&Wiki"));
            popupMenu->AppendSeparator();

            if (selected_iso->GetPlatform() != GameListItem::GAMECUBE_DISC)
            {
                popupMenu->Append(IDM_OPENSAVEFOLDER, _("Open Wii &save folder"));
                popupMenu->Append(IDM_EXPORTSAVE, _("Export Wii save (Experimental)"));
            }
            popupMenu->Append(IDM_OPENCONTAININGFOLDER, _("Open &containing folder"));
            popupMenu->AppendCheckItem(IDM_SETDEFAULTGCM, _("Set as &default ISO"));

            // First we have to decide a starting value when we append it
            if (selected_iso->GetFileName() == SConfig::GetInstance().
                    m_LocalCoreStartupParameter.m_strDefaultGCM)
                popupMenu->FindItem(IDM_SETDEFAULTGCM)->Check();

            popupMenu->AppendSeparator();
            popupMenu->Append(IDM_DELETEGCM, _("&Delete ISO..."));

            if (selected_iso->GetPlatform() != GameListItem::WII_WAD)
            {
                if (selected_iso->IsCompressed())
                    popupMenu->Append(IDM_COMPRESSGCM, _("Decompress ISO..."));
                else if (selected_iso->GetFileName().substr(selected_iso->GetFileName().find_last_of(".")) != ".ciso" &&
                         selected_iso->GetFileName().substr(selected_iso->GetFileName().find_last_of(".")) != ".wbfs")
                    popupMenu->Append(IDM_COMPRESSGCM, _("Compress ISO..."));
            }
            else
            {
                popupMenu->Append(IDM_LIST_INSTALLWAD, _("Install to Wii Menu"));
            }
            if (selected_iso->GetPlatform() == GameListItem::GAMECUBE_DISC ||
                    selected_iso->GetPlatform() == GameListItem::WII_DISC)
            {
                wxMenuItem* changeDiscItem = popupMenu->Append(IDM_LIST_CHANGEDISC, _("Change &Disc"));
                changeDiscItem->Enable(Core::IsRunning());
            }

            PopupMenu(popupMenu);
        }
    }
    else if (GetSelectedItemCount() > 1)
    {
        wxMenu* popupMenu = new wxMenu;
        popupMenu->Append(IDM_DELETEGCM, _("&Delete selected ISOs..."));
        popupMenu->AppendSeparator();
        popupMenu->Append(IDM_MULTICOMPRESSGCM, _("Compress selected ISOs..."));
        popupMenu->Append(IDM_MULTIDECOMPRESSGCM, _("Decompress selected ISOs..."));
        PopupMenu(popupMenu);
    }
}
void CQueueViewFailed::OnRequeueSelected(wxCommandEvent&)
{
#ifndef __WXMSW__
	// GetNextItem is O(n) if nothing is selected, GetSelectedItemCount() is O(1)
	if (!GetSelectedItemCount())
		return;
#endif

	bool failedToRequeueAll = false;
	std::list<CQueueItem*> selectedItems;
	long item = -1;
	long skipTo = -1;
	for (;;) {
		item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
		if (item == -1)
			break;
		SetItemState(item, 0, wxLIST_STATE_SELECTED);
		if (item < skipTo)
			continue;

		CQueueItem* pItem = GetQueueItem(item);
		if (pItem->GetType() == QueueItemType::Server)
			skipTo = item + pItem->GetChildrenCount(true) + 1;
		selectedItems.push_back(GetQueueItem(item));
	}

	if (selectedItems.empty())
		return;

	CQueueView* pQueueView = m_pQueue->GetQueueView();

	while (!selectedItems.empty()) {
		CQueueItem* pItem = selectedItems.front();
		selectedItems.pop_front();

		if (pItem->GetType() == QueueItemType::Server) {
			CServerItem* pServerItem = (CServerItem*)pItem;
			failedToRequeueAll |= !RequeueServerItem(pServerItem);
		}
		else {
			CFileItem* pFileItem = (CFileItem*)pItem;

			CServerItem* pOldServerItem = (CServerItem*)pItem->GetTopLevelItem();
			CServerItem* pServerItem = pQueueView->CreateServerItem(pOldServerItem->GetServer());
			RemoveItem(pItem, false, false, false);

			failedToRequeueAll |= !RequeueFileItem(pFileItem, pServerItem);

			if (!pServerItem->GetChildrenCount(false)) {
				pQueueView->CommitChanges();
				pQueueView->RemoveItem(pServerItem, true, true, true);
			}
		}
	}
	m_fileCountChanged = true;

	pQueueView->CommitChanges();

	if (pQueueView->IsActive())
		pQueueView->AdvanceQueue(false);

	DisplayNumberQueuedFiles();
	SaveSetItemCount(m_itemCount);
	RefreshListOnly();

	if (!m_itemCount && m_pQueue->GetQueueView()->GetItemCount())
		m_pQueue->SetSelection(0);

	if (failedToRequeueAll)
		wxMessageBoxEx(_("Not all items could be requeued for transfer."));
}
void CustomVirtListCtrl<T,L>::SelectAll()
{
	for (long i = 0; i < GetItemCount() ; i++ ) {
		SetItemState( i, wxLIST_STATE_SELECTED, -1  );
	}
}
void CQueueViewFailed::OnRemoveSelected(wxCommandEvent&)
{
#ifndef __WXMSW__
	// GetNextItem is O(n) if nothing is selected, GetSelectedItemCount() is O(1)
	if (!GetSelectedItemCount())
		return;
#endif

	std::list<CQueueItem*> selectedItems;
	long item = -1;
	for (;;)
	{
		item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
		if (item == -1)
			break;

		selectedItems.push_front(GetQueueItem(item));
		SetItemState(item, 0, wxLIST_STATE_SELECTED);
	}

	CEditHandler* pEditHandler = CEditHandler::Get();

	while (!selectedItems.empty())
	{
		CQueueItem* pItem = selectedItems.front();
		selectedItems.pop_front();

		CQueueItem* pTopLevelItem = pItem->GetTopLevelItem();

		if (pItem->GetType() == QueueItemType::Server)
		{
			CServerItem* pServerItem = (CServerItem*)pItem;
			if (pEditHandler && pEditHandler->GetFileCount(CEditHandler::remote, CEditHandler::upload_and_remove_failed, &pServerItem->GetServer()))
				pEditHandler->RemoveAll(CEditHandler::upload_and_remove_failed, &pServerItem->GetServer());
		}
		else if (pItem->GetType() == QueueItemType::File)
		{
			CFileItem* pFileItem = (CFileItem*)pItem;
			if (pFileItem->m_edit == CEditHandler::remote && pEditHandler)
			{
				if (pFileItem->m_edit == CEditHandler::local)
				{
					wxString fullPath(pFileItem->GetLocalPath().GetPath() + pFileItem->GetLocalFile());
					enum CEditHandler::fileState state = pEditHandler->GetFileState(fullPath);
					if (state == CEditHandler::upload_and_remove_failed)
						pEditHandler->Remove(fullPath);
				}
				else
				{
					CServerItem* pServerItem = (CServerItem*)pFileItem->GetTopLevelItem();
					enum CEditHandler::fileState state = pEditHandler->GetFileState(pFileItem->GetRemoteFile(), pFileItem->GetRemotePath(), pServerItem->GetServer());
					if (state == CEditHandler::upload_and_remove_failed)
						pEditHandler->Remove(pFileItem->GetRemoteFile(), pFileItem->GetRemotePath(), pServerItem->GetServer());
				}
			}
		}

		if (!pTopLevelItem->GetChild(1))
		{
			// Parent will get deleted
			// If next selected item is parent, remove it from list
			if (!selectedItems.empty() && selectedItems.front() == pTopLevelItem)
				selectedItems.pop_front();
		}
		RemoveItem(pItem, true, false, false);
	}
	DisplayNumberQueuedFiles();
	SaveSetItemCount(m_itemCount);
	RefreshListOnly();

	if (!m_itemCount && m_pQueue->GetQueueView()->GetItemCount())
		m_pQueue->SetSelection(0);
}
Exemple #29
0
/*******************************************************************************
  Function Name  : OnKeyDown
  Input(s)       : nChar, nRepCnt, nFlags
  Output         : -
  Functionality  : Handle the case of VK_ADD CTRL + NumPlus (Auto size all columns).
  Member of      : CRxMsgList
  Author(s)      : Arunkumar K
  Date Created   : 20-05-2010
  Modifications  : 14-09-2010, ArunKumar K,
                   Added new Handlers for VK_PRIOR, VK_NEXT, VK_END, VK_HOME.
                   15-07-2010, ArunKumar K,
                   Added new Handlers for VK_UP, VK_DOWN.
                   13-07-2010, ArunKumar K,
                   Added new Handlers for VK_LEFT, VK_RIGHT, VK_RETURN.
*******************************************************************************/
void CRxMsgList::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    switch(nChar)
    {
        case VK_ADD:    // CTRL + NumPlus (Auto size all columns)
        {
            if (GetKeyState(VK_CONTROL) < 0)
            {
                // Special handling to avoid showing "hidden" columns
                SetColumnWidthAuto(-1);
                return;
            }
        }
        break;
        case VK_UP:
        {
            BOOL bInterpret = FALSE;
            ::SendMessage( m_hParent, WM_GET_INTERPRET_STATE, (WPARAM)&bInterpret, 0);
            if(bInterpret)
            {
                INT nItem = GetNextItem(-1, LVNI_SELECTED);
                if (nItem != -1)
                {
                    GetParent()->SendMessage(WM_GET_NEXT_PREV_MSG_INDEX, (WPARAM)false, (LPARAM)&nItem);
                    SetItemState(nItem-1,LVIS_SELECTED , LVIS_SELECTED );
                    return;
                }
            }
            break;
        }
        case VK_DOWN:
        {
            BOOL bInterpret = FALSE;
            ::SendMessage( m_hParent, WM_GET_INTERPRET_STATE, (WPARAM)&bInterpret, 0);
            if(bInterpret)
            {
                INT nItem = GetNextItem(-1, LVNI_SELECTED);
                if (nItem != -1)
                {
                    GetParent()->SendMessage(WM_GET_NEXT_PREV_MSG_INDEX, (WPARAM)true, (LPARAM)&nItem);
                    SetItemState(nItem+1,LVIS_SELECTED , LVIS_SELECTED );
                    return;
                }
            }
            break;
        }
        case VK_LEFT:
        {
            INT nItem = GetNextItem(-1, LVNI_SELECTED);
            if (nItem != -1)
            {
                GetParent()->SendMessage(WM_EXPAND_COLLAPSE_MSG, nItem, TREESTATE_COLLAPSE);
                SetItemState(nItem,LVIS_SELECTED , LVIS_SELECTED );
                return;
            }
            break;
        }
        case VK_RIGHT:
        {
            INT nItem = GetNextItem(-1, LVNI_SELECTED);
            if (nItem != -1)
            {
                GetParent()->SendMessage(WM_EXPAND_COLLAPSE_MSG, nItem, TREESTATE_EXPAND);
                SetItemState(nItem,LVIS_SELECTED , LVIS_SELECTED );
                return;
            }
            break;
        }
        case VK_RETURN:
        {
            INT nItem = GetNextItem(-1, LVNI_SELECTED);
            if (nItem != -1)
            {
                GetParent()->SendMessage(WM_EXPAND_COLLAPSE_MSG, nItem, TREESTATE_TOGGLE);
            }
            break;
        }
        case VK_PRIOR:
        case VK_NEXT:
        case VK_END:
        case VK_HOME:
        {
            BOOL bInterpret = FALSE;
            ::SendMessage( m_hParent, WM_GET_INTERPRET_STATE, (WPARAM)&bInterpret, 0);
            if ( bInterpret )
            {
                AfxBeginThread(UpDateThread, (LPVOID)this);
            }
        }
    }
    CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CChatSelector::ProcessMessage(CUpDownClient* pSender, const CString &strIncomingMessage)
{
	CString	strMessage = strIncomingMessage;
	int		iCurPos = 0;

	strMessage.MakeLower();

//	Ban spammers
	if ( g_App.m_pPrefs->IsCounterMeasures() &&
		( strMessage.Find(_T("di-emule")) >= 0
		|| strMessage.Find(_T("emule fx")) >= 0
		|| strMessage.Find(_T("zambor")) >= 0
		|| strMessage.Find(_T("fastest emule ever")) >= 0
		|| strMessage.Find(_T("robot from riaa")) >= 0
		|| strMessage.Find(_T("ketamine")) >= 0
		|| strMessage.Find(_T("http://www.chez.com/theworld/")) >= 0
		|| strMessage.Find(_T("http://fullspeed.to/mison")) >= 0 ) )
	{
		AddDebugLogLine(RGB_LOG_DIMMED_TXT _T("Anti-leechermods: Client %s has been banned because of spamming"), pSender->GetClientNameWithSoftware());
		pSender->Ban(BAN_CLIENT_SPAMMING);
		return;
	}

	CString	strResToken, strFilter = g_App.m_pPrefs->GetMessageFilter();

	strFilter.MakeLower();
	for (;;)
	{
		strResToken = strFilter.Tokenize(_T("|"), iCurPos);
		if (strResToken.IsEmpty())
			break;
		if (strMessage.Find(strResToken) >= 0)
		{
			AddDebugLogLine(RGB_LOG_DIMMED_TXT _T("Filtered message '%s' from client %s"), strIncomingMessage, pSender->GetClientNameWithSoftware());
			return;
		}
	}

	CChatItem	*pChatItem = GetItemByClient(pSender);
	bool		bIsNewChatWindow = false;

	if (pChatItem == NULL)
	{
		if (GetItemCount() >= 50)
		{
			AddDebugLogLine(RGB_LOG_WARNING_TXT _T("Instant Messaging: Messages limit reached"));
			return;
		}

		if (g_App.m_pPrefs->GetAcceptMessagesFrom() == 4) //no messages
			return;

		if ((g_App.m_pPrefs->GetAcceptMessagesFrom() == 2) && !pSender->IsFriend()) //only friends
			return;

		if ((g_App.m_pPrefs->GetAcceptMessagesFrom() == 3) && !pSender->IsFriend()) //log non friends
		{
			AddLogLine(false, GetResString(IDS_IM_MSGFROMCHAT) + _T(" %s: %s"), pSender->GetUserName(), strIncomingMessage);
			pSender->SetChatState(MS_NONE);
			return;
		}

		pChatItem = StartSession(pSender);
		if (pChatItem == NULL)
			return;
		bIsNewChatWindow = true;
	}
	COleDateTime	timelog(COleDateTime::GetCurrentTime());

	strMessage.Format(_T("%s (%s): "), pSender->GetUserName(), timelog.Format(_T("%c")));
	pChatItem->m_pLog->AppendText(strMessage, RGB(50, 200, 250));
	pChatItem->m_pLog->AppendText(strIncomingMessage + _T('\n'));

	if (g_App.m_pPrefs->GetAwayState())
	{
		if ((::GetTickCount() - pChatItem->m_pClient->GetAwayMessageResendCount()) > 3000)
		{ //send again only if 3 secs from last away message
			SendAwayMessage(pChatItem);
			pChatItem->m_pClient->SetAwayMessageResendCount(::GetTickCount());
		}
	}

	if ((iCurPos = GetTabByClient(pSender)) != GetCurSel())
		SetItemState(iCurPos, TCIS_HIGHLIGHTED, TCIS_HIGHLIGHTED);
	if (!g_App.m_pPrefs->GetAwayState())
	{
		BOOL	bVisible = ::IsWindowVisible(::GetParent(m_hWnd));

	//	Show statusbar indicator if Messages window isn't active or our application isn't topmost one
		if (!bVisible || (g_App.m_pMDlg->m_hWnd != ::GetForegroundWindow()))
		{
			pChatItem->m_bNotify = true;
		//	Send Notification is required
			if ( ( g_App.m_pPrefs->GetUseChatNotifier() &&
				(bIsNewChatWindow || g_App.m_pPrefs->GetNotifierPopsEveryChatMsg()) ) )
			{
				strMessage.Format(_T("%s %s:'%s'\n"), GetResString(IDS_TBN_NEWCHATMSG), pSender->GetUserName(), strIncomingMessage);
				g_App.m_pMDlg->SendMail(strMessage, true, g_App.m_pPrefs->IsSMTPInfoEnabled());
				g_App.m_pMDlg->ShowNotifier(strMessage, TBN_CHAT, false, true);
			}
		}
	}
}