Modificato metodo TTree::image e corretto disegno alberi autunnali

git-svn-id: svn://10.65.10.50/trunk@6199 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1998-02-16 16:31:24 +00:00
parent 78144a59db
commit a177471ae5
2 changed files with 152 additions and 80 deletions

View File

@ -72,28 +72,32 @@ HIDDEN bool callback_find_brother(TTree& node, void* jolly, word when)
bool TTree::scan_depth_first(NODE_HANDLER nh, void* jolly, word flags) bool TTree::scan_depth_first(NODE_HANDLER nh, void* jolly, word flags)
{ {
if ((flags & SCAN_IGNORING_LEAVES) && !has_son())
return FALSE;
if ((flags & 0x7) == 0); if ((flags & 0x7) == 0);
flags |= SCAN_PRE_ORDER; flags |= SCAN_PRE_ORDER;
bool test_myself = TRUE;
if ((flags & SCAN_IGNORING_LEAVES) && !has_son())
test_myself = FALSE;
if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER))
return TRUE;
TString myself; TString myself;
curr_id(myself); curr_id(myself);
const bool stop = (flags & SCAN_IGNORING_UNEXPANDED) && !expanded(); if (test_myself)
if (!stop && goto_firstson())
{ {
if (scan_depth_first(nh, jolly, flags)) if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER))
return TRUE;
const bool stop = (flags & SCAN_IGNORING_UNEXPANDED) && !expanded();
if (!stop && goto_firstson())
{
if (scan_depth_first(nh, jolly, flags))
return TRUE;
goto_node(myself);
}
if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER))
return TRUE; return TRUE;
goto_node(myself);
} }
if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER))
return TRUE;
if (goto_rbrother()) if (goto_rbrother())
{ {
@ -102,23 +106,30 @@ bool TTree::scan_depth_first(NODE_HANDLER nh, void* jolly, word flags)
goto_node(myself); goto_node(myself);
} }
if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER)) if (test_myself)
return TRUE; {
if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER))
return TRUE;
}
return FALSE; return FALSE;
} }
bool TTree::scan_breadth_first(NODE_HANDLER nh, void* jolly, word flags) bool TTree::scan_breadth_first(NODE_HANDLER nh, void* jolly, word flags)
{ {
if ((flags & SCAN_IGNORING_LEAVES) && !has_son())
return FALSE;
if ((flags & 0x7) == 0); if ((flags & 0x7) == 0);
flags |= SCAN_PRE_ORDER; flags |= SCAN_PRE_ORDER;
if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER)) bool test_myself = TRUE;
return TRUE; if ((flags & SCAN_IGNORING_LEAVES) && !has_son())
test_myself = FALSE;
if (test_myself)
{
if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER))
return TRUE;
}
TString myself; TString myself;
curr_id(myself); curr_id(myself);
@ -129,19 +140,21 @@ bool TTree::scan_breadth_first(NODE_HANDLER nh, void* jolly, word flags)
goto_node(myself); goto_node(myself);
} }
if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) if (test_myself)
return TRUE;
const bool stop = (flags & SCAN_IGNORING_UNEXPANDED) && !expanded();
if (!stop && goto_firstson())
{ {
if (scan_breadth_first(nh, jolly, flags)) if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER))
return TRUE; return TRUE;
goto_node(myself);
}
if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER)) const bool stop = (flags & SCAN_IGNORING_UNEXPANDED) && !expanded();
return TRUE; if (!stop && goto_firstson())
{
if (scan_breadth_first(nh, jolly, flags))
return TRUE;
goto_node(myself);
}
if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER))
return TRUE;
}
return FALSE; return FALSE;
} }
@ -267,11 +280,11 @@ TImage* TTree::get_res_image(short bmp_id) const
return bmp; return bmp;
} }
TImage* TTree::image() const TImage* TTree::image(bool selected) const
{ {
short bmp_id = BMP_FILE; short bmp_id = BMP_FILE;
if (has_son()) if (has_son())
bmp_id = expanded() ? BMP_DIRDN : BMP_DIR; bmp_id = selected ? BMP_DIRDN : BMP_DIR;
return get_res_image(bmp_id); return get_res_image(bmp_id);
} }
@ -282,25 +295,29 @@ TImage* TTree::image() const
bool TBidirectional_tree::scan_depth_first(NODE_HANDLER nh, void* jolly, word flags) bool TBidirectional_tree::scan_depth_first(NODE_HANDLER nh, void* jolly, word flags)
{ {
if ((flags & SCAN_IGNORING_LEAVES) && !has_son())
return FALSE;
if ((flags & 0x7) == 0); if ((flags & 0x7) == 0);
flags |= SCAN_PRE_ORDER; flags |= SCAN_PRE_ORDER;
if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER)) bool test_myself = TRUE;
return TRUE; if ((flags & SCAN_IGNORING_LEAVES) && !has_son())
test_myself = FALSE;
const bool stop = (flags & SCAN_IGNORING_UNEXPANDED) && !expanded();
if (!stop && goto_firstson()) if (test_myself)
{ {
if (scan_depth_first(nh, jolly, flags)) if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER))
return TRUE; return TRUE;
goto_father();
} const bool stop = (flags & SCAN_IGNORING_UNEXPANDED) && !expanded();
if (!stop && goto_firstson())
if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) {
return TRUE; if (scan_depth_first(nh, jolly, flags))
return TRUE;
goto_father();
}
if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER))
return TRUE;
}
if (goto_rbrother()) if (goto_rbrother())
{ {
@ -309,22 +326,29 @@ bool TBidirectional_tree::scan_depth_first(NODE_HANDLER nh, void* jolly, word fl
goto_lbrother(); goto_lbrother();
} }
if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER)) if (test_myself)
return TRUE; {
if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER))
return TRUE;
}
return FALSE; return FALSE;
} }
bool TBidirectional_tree::scan_breadth_first(NODE_HANDLER nh, void* jolly, word flags) bool TBidirectional_tree::scan_breadth_first(NODE_HANDLER nh, void* jolly, word flags)
{ {
if ((flags & SCAN_IGNORING_LEAVES) && !has_son())
return FALSE;
if ((flags & 0x7) == 0); if ((flags & 0x7) == 0);
flags |= SCAN_PRE_ORDER; flags |= SCAN_PRE_ORDER;
if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER)) bool test_myself = TRUE;
return TRUE; if ((flags & SCAN_IGNORING_LEAVES) && !has_son())
test_myself = FALSE;
if (test_myself)
{
if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER))
return TRUE;
}
if (goto_rbrother()) if (goto_rbrother())
{ {
@ -333,20 +357,21 @@ bool TBidirectional_tree::scan_breadth_first(NODE_HANDLER nh, void* jolly, word
goto_lbrother(); goto_lbrother();
} }
if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) if (test_myself)
return TRUE;
const bool stop = (flags & SCAN_IGNORING_UNEXPANDED) && !expanded();
if (!stop && goto_firstson())
{ {
if (scan_breadth_first(nh, jolly, flags)) if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER))
return TRUE; return TRUE;
goto_father(); const bool stop = (flags & SCAN_IGNORING_UNEXPANDED) && !expanded();
} if (!stop && goto_firstson())
{
if (scan_breadth_first(nh, jolly, flags))
return TRUE;
goto_father();
}
if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER))
return TRUE;
}
if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER))
return TRUE;
return FALSE; return FALSE;
} }
@ -680,6 +705,7 @@ public:
long _plusx; long _plusx;
long _startx; long _startx;
long _endx; long _endx;
bool _expandable;
bool _expanded; bool _expanded;
const TNode_info& operator =(const TNode_info& ni) const TNode_info& operator =(const TNode_info& ni)
@ -689,6 +715,7 @@ public:
_endx = ni._endx; _endx = ni._endx;
_plusx = ni._plusx; _plusx = ni._plusx;
_expanded = ni._expanded; _expanded = ni._expanded;
_expandable = ni._expandable;
return ni; return ni;
} }
@ -850,16 +877,25 @@ bool TTree_window::callback_draw_node(TTree& node, void* jolly, word when)
q.v = (by+1)*CHARY; q.v = (by+1)*CHARY;
xvt_dwin_draw_line(win, q); xvt_dwin_draw_line(win, q);
TImage* bmp = node.image(); TImage* bmp = node.image(is_selected);
if (bmp) if (bmp)
bmp->draw(win, p.h, p.v + (CHARY - bmp->height()) / 2); bmp->draw(win, p.h, p.v + (CHARY - bmp->height()) / 2);
TNode_info& ni = (*ui->_node_info)[ry]; TNode_info& ni = (*ui->_node_info)[ry];
node.curr_id(ni._id); node.curr_id(ni._id);
ni._startx = ui->_x; ni._startx = ui->_x;
ni._endx = ui->_x + text_len + 2; ni._endx = ui->_x + text_len + 2;
ni._plusx = node.has_son() ? ui->_x - TABX + 1 : 0; ni._expandable = node.has_son();
ni._expanded = ni._plusx > 0 ? node.expanded() : FALSE; if (ni._expandable)
{
ni._plusx = ui->_x - TABX + 1;
ni._expanded = node.expanded();
}
else
{
ni._plusx = 0;
ni._expanded = FALSE;
}
} }
ui->_y++; ui->_y++;
@ -878,11 +914,29 @@ bool TTree_window::callback_draw_node(TTree& node, void* jolly, word when)
void TTree_window::draw_plus_minus() void TTree_window::draw_plus_minus()
{ {
const long firsty = origin().y; const long firsty = origin().y;
for (int i = _node_info.last(); i >= 0; i--) const int last_drawn = _node_info.last();
for (int i = last_drawn; i >= 0; i--)
{ {
const TNode_info& ni = _node_info[i]; TNode_info& ni = _node_info[i];
if (ni._plusx > 0) if (ni._plusx > 0)
{ {
if (ni._expanded)
{
bool spudorato = i == last_drawn; // Falso espandibile
if (!spudorato)
{
const TNode_info& nni = _node_info[i+1];
spudorato = nni._startx <= ni._startx;
}
if (spudorato)
{
ni._expandable = FALSE;
ni._expanded = FALSE;
ni._plusx = 0;
continue;
}
}
WINDOW w = win(); WINDOW w = win();
PNT r = log2dev(ni._plusx, firsty + i); PNT r = log2dev(ni._plusx, firsty + i);
r.v += CHARY/2; r.v += CHARY/2;
@ -1023,7 +1077,10 @@ bool TTree_window::index2info(long index, TNode_info& ni)
bool TTree_window::on_key(KEY key) bool TTree_window::on_key(KEY key)
{ {
if (_tree && (key == K_UP || key == K_DOWN)) if (_tree == NULL)
return FALSE;
if (key == K_UP || key == K_DOWN)
{ {
int index = info2index(_curr_info); int index = info2index(_curr_info);
if (key == K_UP) if (key == K_UP)
@ -1055,6 +1112,21 @@ bool TTree_window::on_key(KEY key)
if (!scroll) if (!scroll)
return TRUE; return TRUE;
} }
if (key == K_ENTER)
{
if (_curr_info._expandable && _tree->goto_node(_curr_info._id))
{
bool ok;
if (_curr_info._expanded)
ok = _tree->expand();
else
ok = _tree->shrink();
if (ok)
force_update();
}
}
return TField_window::on_key(key); return TField_window::on_key(key);
} }
@ -1062,8 +1134,8 @@ void TTree_window::handler(WINDOW win, EVENT* ep)
{ {
switch(ep->type) switch(ep->type)
{ {
case E_MOUSE_DOWN:
case E_MOUSE_DBL: case E_MOUSE_DBL:
case E_MOUSE_DOWN:
if (_tree) if (_tree)
{ {
const int c = ep->v.mouse.where.h / CHARX; const int c = ep->v.mouse.where.h / CHARX;
@ -1073,7 +1145,7 @@ void TTree_window::handler(WINDOW win, EVENT* ep)
if (ok && (c == ni._plusx || (c >= ni._startx && c < ni._endx)) && if (ok && (c == ni._plusx || (c >= ni._startx && c < ni._endx)) &&
_tree->goto_node(ni._id)) _tree->goto_node(ni._id))
{ {
if (ep->type == E_MOUSE_DBL || c == ni._plusx) if (c == ni._plusx || (ni._expandable && ep->type == E_MOUSE_DBL))
{ {
if (_tree->expanded()) if (_tree->expanded())
ok = _tree->shrink(); ok = _tree->shrink();

View File

@ -24,7 +24,7 @@ protected:
TAssoc_array _expanded; TAssoc_array _expanded;
TArray _image; TArray _image;
TImage* get_res_image(short id) const; // helper for get_image TImage* get_res_image(short id) const; // helper for image(bool)
protected: protected:
virtual void node2id(const TObject* node, TString& id) const pure; virtual void node2id(const TObject* node, TString& id) const pure;
@ -62,7 +62,7 @@ public:
virtual bool expanded() const; virtual bool expanded() const;
virtual bool shrunk() const { return !expanded(); } virtual bool shrunk() const { return !expanded(); }
virtual bool expand_all(); virtual bool expand_all();
virtual TImage* image() const; virtual TImage* image(bool selected) const;
virtual bool scan_depth_first(NODE_HANDLER nh, void* jolly, word flags = SCAN_PRE_ORDER); virtual bool scan_depth_first(NODE_HANDLER nh, void* jolly, word flags = SCAN_PRE_ORDER);
virtual bool scan_breadth_first(NODE_HANDLER nh, void* jolly, word flags = SCAN_PRE_ORDER); virtual bool scan_breadth_first(NODE_HANDLER nh, void* jolly, word flags = SCAN_PRE_ORDER);