Пример #1
0
void
DeckLibraryTab::OnTreeKeyDown (wxTreeEvent &event)
{
    wxKeyEvent oKeyEvent = event.GetKeyEvent ();

    if (m_bNoEvents || !m_pTree) return;
    switch (oKeyEvent.GetKeyCode ()) {
        // Keys to delete cards
    case WXK_BACK: // backspace
    case WXK_DELETE: // delete
        DeleteBranch (m_pTree->GetSelection ());
        break;
    case WXK_F5:
        LessOfAnItem (m_pTree->GetSelection (), 5);
        break;
    case WXK_F6:
        LessOfAnItem (m_pTree->GetSelection (), 1);
        break;
    case WXK_F7:
        MoreOfAnItem (m_pTree->GetSelection (), 1);
        break;
    case WXK_F8:
        MoreOfAnItem (m_pTree->GetSelection (), 5);
        break;
    default:
        //	   wxString sMessage = "Pressed key #";
        //	   sMessage << oKeyEvent.GetKeyCode ();
        //	   wxLogMessage (sMessage);
        //	   event.Skip ();
        break;
    }
}
Пример #2
0
wxArrayLong *
DeckLibraryTab::DeleteBranch (wxTreeItemId oItemId, bool bFirstCall)
{
    wxArrayLong *pRefArray = new wxArrayLong (), *pOtherArray;
    long lCardRef = (long) &oItemId;
    wxTreeItemIdValue cookie;
    MyTreeItemData *pData;

    m_bNoEvents = TRUE;

    if (!oItemId.IsOk ()) {
        wxLogError (wxT ("DeleteBranch : Bad Item ID"));
        return NULL;
    }

    // For foolproofness, we don't allow deleting the whole tree this way
    //if (oItemId == m_oRootId)
    //{
//	  Update();
//	  return NULL;
    //}

    pData = (MyTreeItemData *) m_pTree->GetItemData (oItemId);

    if (pData != NULL) {
        lCardRef = pData->GetValue ();
        if (lCardRef >= 0) {
            // Remember the card to remove, actual deleting will be later
            pRefArray->Add (lCardRef);
        }
    }

    // Recursively process the children
    wxTreeItemId oChildId = m_pTree->GetFirstChild (oItemId, cookie);
    while (oChildId.IsOk ()) {
        pOtherArray = DeleteBranch (oChildId, FALSE);
        if (pOtherArray != NULL) {
            WX_APPEND_ARRAY (*pRefArray, *pOtherArray);
            delete pOtherArray;
        }
        oChildId = m_pTree->GetNextChild (oItemId, cookie);
    }

    // after all the recursive processing has taken place,
    // update the view
    if (bFirstCall) {
        // Actually delete the cards
        for (unsigned int i = 0; i < pRefArray->Count (); i++) {
            m_pModel->DelFromLibrary (pRefArray->Item (i), -1, FALSE);
        }

        m_bNoEvents = FALSE;
        Update ();
        delete pRefArray;
        return NULL;
    }
    return pRefArray;
}
Пример #3
0
void
DeckLibraryTab::OnPopupRemoveAll (wxCommandEvent& WXUNUSED (event))
{
    wxTreeItemId oSelectedId;

    if (m_bNoEvents || !m_pTree) {
        return;
    }

    oSelectedId = m_pTree->GetSelection();
    DeleteBranch(oSelectedId);
}
Пример #4
0
	//vRebuild: the rects (leaf node) the should be reinsert
	//Return if the node o should be deleted
	bool remove(RtreeNode *o, const Rec &rec, std::vector<Rec> &vRebuild, RtreeBranch *branch)
	{
		assert(o);
		if (o->level == 0)
		{
			assert(o->count == 1);
			if (rec == o->branch[0].mbr)
			{
				if (branch)
					branch->mbr.init();
				Destroy(o);
				return true;
			}
			return false;
		}
		int i = 0;
		while (i < o->count)
		{
			if (!RecOverlap(&rec, &o->branch[i].mbr))
			{
				++i;
				continue;
			}
			if (!remove(o->branch[i].child, rec, vRebuild, &o->branch[i]))
			{
				++i;
				continue;
			}
			DeleteBranch(o, i);
		}
		if (o->count < M / 2 && o != R_root->rnode)
		{
			enumLeaf(o, vRebuild);
			Destroy(o);
			if (branch)
				branch->mbr.init();
			return true;
		}
		if (branch)
			branch->mbr = CoverRec(o);
		return false;
	}