Ejemplo n.º 1
0
void MyFrame::OnCountRec(wxCommandEvent& WXUNUSED(event))
{
    wxTreeItemId item = m_treeCtrl->GetSelection();

    CHECK_ITEM( item );

    int i = m_treeCtrl->GetChildrenCount( item );

    wxLogMessage(wxT("%d children"), i);
}
Ejemplo n.º 2
0
/*
 * ut_lookup is simple test function that should validate all possible
 * lookup cases. Saying "all possible cases" I mean that given function
 * should generate 100% coverage of ttree_lookup code.
 */
UTEST_FUNCTION(ut_lookup, args)
{
    Ttree tree;
    TtreeNode *tnode;
    int num_keys, num_items, ret, i;
    struct balance_info binfo;
    struct item *item;

    num_keys = utest_get_arg(args, 0, INT);
    num_items = utest_get_arg(args, 1, INT);
    UTEST_ASSERT(num_items >= 1);

    ret = ttree_init(&tree, num_keys, true, __cmpfunc, struct item, key);
    UTEST_ASSERT(ret >= 0);
    for (i = 0; i < (num_items / 2); i++) {
        item = alloc_item(i);
        UTEST_ASSERT(ttree_insert(&tree, item) == 0);
        item = alloc_item(num_items - i - 1);
        UTEST_ASSERT(ttree_insert(&tree, item) == 0);
    }

    check_tree_balance(&tree, &binfo);
    if (binfo.balance != TREE_BALANCED) {
        UTEST_FAILED("Tree is unbalanced on a node %p BFC = %d, %s\n",
                     binfo.tnode, binfo.tnode->bfc,
                     balance_name(binfo.balance));
    }

    /*
     * Just an example of how to browse the tree keys
     * in a sorted order: from the smallest one to the greatest one.
     * The following cycle runs from the smallest key to the greatest
     * one and checks that an item by given key can be successfully found.
     */
    tnode = ttree_node_leftmost(tree.root);
    while (tnode) {
        tnode_for_each_index(tnode, i) {
            ret = *(int *)tnode_key(tnode, i);
            item = (struct item *)ttree_lookup(&tree, &ret, NULL);
            CHECK_ITEM(item, ret);
        }

        tnode = tnode->successor;
    }
Ejemplo n.º 3
0
void MyFrame::OnHighlight(wxCommandEvent& WXUNUSED(event))
{
    wxTreeItemId id = m_treeCtrl->GetSelection();

    CHECK_ITEM( id );

    wxRect r;
    if ( !m_treeCtrl->GetBoundingRect(id, r, true /* text, not full row */) )
    {
        wxLogMessage(_T("Failed to get bounding item rect"));
        return;
    }

    wxClientDC dc(m_treeCtrl);
    dc.SetBrush(*wxRED);
    dc.SetPen(*wxTRANSPARENT_PEN);
    dc.DrawRectangle(r);
    m_treeCtrl->Update();
}
Ejemplo n.º 4
0
static void check_node(test_nodes* pnodes, const char* str) {
#define CHECK_ITEM(item1, item2, name) if ((item1) != (item2))	strcat(name_tmp, name);
	static char name_tmp[2048] = {0};
	CHECK_ITEM(pnodes->pNodeThis->GetParent(), pnodes->pNodeParent, "\n\t[parent]");
	CHECK_ITEM(pnodes->pNodeThis->GetNext(), pnodes->pNodeNext, "\n\t[next]");
	CHECK_ITEM(pnodes->pNodeThis->GetPrev(), pnodes->pNodePrev, "\n\t[prev]");
	CHECK_ITEM(pnodes->pNodeThis->GetNextSibling(), pnodes->pNodeNextSibling, "\n\t[nextsibling]");
	CHECK_ITEM(pnodes->pNodeThis->GetPrevSibling(), pnodes->pNodePrevSibling, "\n\t[prevsibling]");
	CHECK_ITEM(pnodes->pNodeThis->GetFirstChild(), pnodes->pNodeFirstChild, "\n\t[firstchild]");
	CHECK_ITEM(pnodes->pNodeThis->GetLastChild(), pnodes->pNodeLastChild, "\n\t[lastchild]");
	if (name_tmp[0]) {
		printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
		printf("\nNode conflict <%s>:%s", str, name_tmp);
		pnodes->dump_node();
		CPPUNIT_ASSERT(false);
	}
#undef CHECK_ITEM
}
Ejemplo n.º 5
0
void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event))
{
    wxTreeItemId item = m_treeCtrl->GetSelection();

    CHECK_ITEM( item );

    // old code - now we edit in place
#if 0
    static wxString s_text;
    s_text = wxGetTextFromUser(wxT("New name: "), wxT("Tree sample question"),
            s_text, this);
    if ( !s_text.empty() )
    {
        m_treeCtrl->SetItemText(item, s_text);
    }
#endif // 0

    // TODO demonstrate creating a custom edit control...
    (void)m_treeCtrl->EditLabel(item);
}