int RTFConcatenator::CollectCallback(HTREEITEM item, struct tree_node_t *node, void *cargo) { RTFConcatenator *that = (RTFConcatenator *)cargo; struct guide_nodedata_t *data = (struct guide_nodedata_t *)tree_get_data(node); ASSERT(node); ASSERT(cargo); ASSERT(item); // position cursor at end and clear selection HWND hWnd = that->m_hWnd; ::SendMessage(hWnd, EM_SETSEL, (WPARAM)-1, (LPARAM)-1); // get heading level int level = 0; // 0 => no other top nodes struct tree_node_t *node2 = node; while (tree_get_parent(node2) != that->m_pTopNode) { level++; node2 = tree_get_parent(node2); } // append heading rtf text CStringA heading = that->m_TemplateHelper.GetHeading( that->m_HeadingCounter.GetHeadingNumber(node), level, data->title, that->m_bLastTextEmpty, data->color, data->bgcolor); SETTEXTEX tex; tex.codepage = CP_ACP; // ??? tex.flags = ST_SELECTION; LRESULT lr = ::SendMessage(hWnd, EM_SETTEXTEX, (WPARAM)&tex, (LPARAM)(const char *)heading); ASSERT(lr > 0); // check the number of characters in the text SetRTF(that->m_hZeroCheckWnd, data->text, false); LRESULT nChars = ::SendMessage(that->m_hZeroCheckWnd, WM_GETTEXTLENGTH, 0, 0); if (nChars > 0) { // append rtf text (only if some text is really present) if (data->text[0] != 0 && strcmp(theEmptyRTFText, data->text) != 0) //theEmptyRTFText != data->text) ::SendMessage(hWnd, EM_SETTEXTEX, (WPARAM)&tex, (LPARAM)data->text); } that->m_bLastTextEmpty = (nChars == 0); // continue return 0; }
int main() //@ requires emp; //@ ensures emp; { struct node *node0 = create_tree(); struct node *node = node0; node = tree_add_left(node); node = tree_add_right(node); node = tree_get_parent(node); node = tree_add_left(node); node = tree_get_parent(node); node = tree_get_parent(node); //@ assert(node == node0); tree_dispose(node); return 0; }
node * tree_get_parent(node *s,node *obj){ node *p; if(s == NULL){ return NULL; } if(s->lchild == obj || s->rchild == obj) return s; p = tree_get_parent(s->lchild,obj); if(p){ return p; } p = tree_get_parent(s->rchild,obj); if(p){ return p; } }
void RTFConcatenator::CollectRecurse(struct wintree_t *pWinTree, HTREEITEM hItem) { ASSERT(pWinTree); ASSERT(hItem); // set top node m_pTopNode = tree_get_parent(wintree_get_node_from_item(pWinTree, hItem)); // make headings m_HeadingCounter.CollectRecurse(pWinTree, hItem); wintree_traverse_subtree(pWinTree, hItem, CollectCallback, this); }
void RTFConcatenator::CollectOne(struct wintree_t *pWinTree, HTREEITEM hItem) { ASSERT(pWinTree); ASSERT(hItem); // set top node m_pTopNode = tree_get_parent(wintree_get_node_from_item(pWinTree, hItem)); // make headings m_HeadingCounter.CollectOne(pWinTree, hItem); struct tree_node_t *node = wintree_get_node_from_item(pWinTree, hItem); ASSERT(node); CollectCallback(hItem, node, this); }
CStringA HeadingCounter::GetHeadingNumber(struct tree_node_t *node) { CStringA result; char tmp[1024]; // collect the numbers as a string (in reverse order) MapValue value; while (m_Map.Lookup(node, value)) { result.Insert(0, _itoa(value.m_nSelfNumber, tmp, 10)); result.Insert(0, "."); node = tree_get_parent(node); } // remove the leading '.' ASSERT(result.IsEmpty() == false); if (!result.IsEmpty()) result.Delete(0); return result; }
int HeadingCounter::HeadingCallback(HTREEITEM item, struct tree_node_t *node, void *cargo) { HeadingCounter *that = (HeadingCounter *)cargo; struct tree_node_t *parent = tree_get_parent(node); MapValue parentValue; UINT selfNumber; if (that->m_Map.Lookup(parent, parentValue)) { selfNumber = ++parentValue.m_nChildCounter; that->m_Map[parent] = parentValue; } else { selfNumber = ++that->m_nTopLevelCounter; } MapValue nodeValue = { selfNumber, 0 }; that->m_Map[node] = nodeValue; return 0; }