diff --git a/include/campo.aut b/include/campo.aut index 417baa127..03451e03b 100755 --- a/include/campo.aut +++ b/include/campo.aut @@ -1,4 +1,4 @@ -ba Base +ba Base 74 75 76 @@ -6,7 +6,7 @@ ba Base iv Gestione IVA se Contabilita' Semplificata cg Contabilita' Generale -st Gestione studi +ci Contabilita' Industriale mi Modello IVA 11 ai Archiviazione Immagini ce Cespiti diff --git a/include/modaut.h b/include/modaut.h index d7302551b..7421adb5c 100755 --- a/include/modaut.h +++ b/include/modaut.h @@ -9,7 +9,7 @@ #define GIAUT 5 #define SEAUT 6 #define CGAUT 7 -#define STAUT 8 +#define CIAUT 8 #define MIAUT 9 #define AIAUT 10 #define CEAUT 11 diff --git a/include/tree.cpp b/include/tree.cpp index b2f6f0091..502ac2a3c 100755 --- a/include/tree.cpp +++ b/include/tree.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -15,22 +15,22 @@ HIDDEN bool callback_compare_node(TTree& node, void* jolly, word when) } HIDDEN bool callback_expand_node(TTree& node, void* jolly, word when) -{ +{ if (when == SCAN_PRE_ORDER) node.expand(); return false; } HIDDEN bool callback_find_father(TTree& node, void* jolly, word when) -{ +{ TString_array& father_and_son = *(TString_array*)jolly; TString myself; node.curr_id(myself); - + if (when == SCAN_PRE_ORDER) { if (myself == father_and_son.row(1)) father_and_son.add(myself, 0); - } + } else { if (father_and_son.objptr(0)) @@ -39,20 +39,20 @@ HIDDEN bool callback_find_father(TTree& node, void* jolly, word when) return true; } } - + return false; } HIDDEN bool callback_find_brother(TTree& node, void* jolly, word when) -{ +{ TString_array& brother_and_sister = *(TString_array*)jolly; TString myself; node.curr_id(myself); - + if (when == SCAN_PRE_ORDER) { if (myself == brother_and_sister.row(1)) brother_and_sister.add(myself, 0); - } + } else { if (brother_and_sister.objptr(0)) @@ -69,11 +69,11 @@ HIDDEN bool callback_find_brother(TTree& node, void* jolly, word when) /////////////////////////////////////////////////////////// bool TTree::scan_depth_first(NODE_HANDLER nh, void* jolly, word flags) -{ +{ if ((flags & 0x7) == 0) flags |= SCAN_PRE_ORDER; - - bool test_myself = true; + + bool test_myself = true; if ((flags & SCAN_IGNORING_LEAVES) && !has_son()) test_myself = false; @@ -82,18 +82,18 @@ bool TTree::scan_depth_first(NODE_HANDLER nh, void* jolly, word flags) if (test_myself) { - if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER)) + 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); + goto_node(myself); } - if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) + if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) return true; } @@ -101,30 +101,30 @@ bool TTree::scan_depth_first(NODE_HANDLER nh, void* jolly, word flags) { if (scan_depth_first(nh, jolly, flags)) return true; - goto_node(myself); + goto_node(myself); } - + if (test_myself) { - if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER)) + if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER)) return true; } - + return false; } bool TTree::scan_breadth_first(NODE_HANDLER nh, void* jolly, word flags) -{ +{ if ((flags & 0x7) == 0) flags |= SCAN_PRE_ORDER; - bool test_myself = true; + bool test_myself = 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)) + if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER)) return true; } @@ -135,22 +135,22 @@ bool TTree::scan_breadth_first(NODE_HANDLER nh, void* jolly, word flags) { if (scan_breadth_first(nh, jolly, flags)) return true; - goto_node(myself); + goto_node(myself); } - + if (test_myself) { - if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) + if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) return true; - + const bool stop = (flags & SCAN_IGNORING_UNEXPANDED) && !expanded(); 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)) + goto_node(myself); + } + if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER)) return true; } @@ -183,9 +183,9 @@ bool TTree::goto_father() { TString_array father_and_son; father_and_son.add(myself, 1); - ok = scan_breadth_first(callback_find_father, &father_and_son, + ok = scan_breadth_first(callback_find_father, &father_and_son, SCAN_PRE_ORDER | SCAN_IN_ORDER); - } + } if (!ok) goto_node(myself); return ok; @@ -208,7 +208,7 @@ bool TTree::goto_lbrother() { TString_array brother_and_sister; brother_and_sister.add(myself, 1); - ok = scan_depth_first(callback_find_brother, &brother_and_sister, + ok = scan_depth_first(callback_find_brother, &brother_and_sister, SCAN_PRE_ORDER | SCAN_POST_ORDER); } if (!ok) @@ -235,15 +235,15 @@ bool TTree::has_son() const } bool TTree::expanded() const -{ - TString str; +{ + TString str; curr_id(str); bool yes = _expanded.is_key(str); return yes; } bool TTree::expand() -{ +{ bool ok = enabled() && has_son(); if (ok) { @@ -256,7 +256,7 @@ bool TTree::expand() } bool TTree::shrink() -{ +{ TString str; curr_id(str); bool ok = _expanded.is_key(str); @@ -266,16 +266,16 @@ bool TTree::shrink() } bool TTree::expand_all() -{ +{ bool ok = goto_root(); if (ok) scan_breadth_first(callback_expand_node, NULL); - return ok; + return ok; } bool TTree::shrink_all() -{ - _expanded.destroy(); +{ + _expanded.destroy(); return goto_root(); } @@ -284,7 +284,7 @@ TImage* TTree::get_res_image(short bmp_id) const { TImage* bmp = (TImage*)_image.objptr(bmp_id); if (bmp == NULL) - { + { bmp = new TImage(bmp_id); if (bmp->ok()) { @@ -295,15 +295,15 @@ TImage* TTree::get_res_image(short bmp_id) const { delete bmp; bmp = NULL; - } + } } return bmp; } TImage* TTree::image(bool selected) const -{ +{ short bmp_id = BMP_FILE; - if (has_son()) + if (has_son()) bmp_id = selected ? BMP_DIRDN : BMP_DIR; return get_res_image(bmp_id); } @@ -314,28 +314,28 @@ TImage* TTree::image(bool selected) const /////////////////////////////////////////////////////////// bool TBidirectional_tree::scan_depth_first(NODE_HANDLER nh, void* jolly, word flags) -{ +{ if ((flags & 0x7) == 0) flags |= SCAN_PRE_ORDER; bool test_myself = 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)) + 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_father(); - } + goto_father(); + } - if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) + if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) return true; } @@ -343,64 +343,64 @@ bool TBidirectional_tree::scan_depth_first(NODE_HANDLER nh, void* jolly, word fl { if (scan_depth_first(nh, jolly, flags)) return true; - goto_lbrother(); + goto_lbrother(); } - + if (test_myself) { - if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER)) + if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER)) return true; } - + return false; } bool TBidirectional_tree::scan_breadth_first(NODE_HANDLER nh, void* jolly, word flags) -{ +{ if ((flags & 0x7) == 0) flags |= SCAN_PRE_ORDER; bool test_myself = 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)) + if ((flags & SCAN_PRE_ORDER) && nh(*this, jolly, SCAN_PRE_ORDER)) return true; } - + if (goto_rbrother()) { if (scan_breadth_first(nh, jolly, flags)) return true; - goto_lbrother(); + goto_lbrother(); } - + if (test_myself) { - if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) + if ((flags & SCAN_IN_ORDER) && nh(*this, jolly, SCAN_IN_ORDER)) return true; 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)) + goto_father(); + } + if ((flags & SCAN_POST_ORDER) && nh(*this, jolly, SCAN_POST_ORDER)) return true; } - + return false; } bool TBidirectional_tree::goto_node(const TString &id) -{ +{ bool ok = goto_root(); if (ok && id.not_empty()) ok = scan_breadth_first(callback_compare_node, (void *)&id); - return ok; + return ok; } /////////////////////////////////////////////////////////// @@ -435,11 +435,11 @@ void TObject_tree::node2id(const TObject* node, TString& id) const } bool TObject_tree::goto_node(const TString& node) -{ +{ void* p = NULL; if (node.not_empty()) { -#ifdef DBG_TREE +#ifdef DBG_TREE if (!_expanded.is_key(node)) // Usa l'assoc array per testare i nodi validi! { NFCHECK("Invalid node: %s", (const char*)node); @@ -495,19 +495,19 @@ bool TObject_tree::set_object(TObject* obj) { if (_current) { -#ifdef DBG_TREE +#ifdef DBG_TREE TString str; curr_id(str); _expanded.add(str); // Usa l'assoc array per memorizzare i nodi validi! -#endif +#endif if (_current->_obj) delete _current->_obj; - _current->_obj = obj; + _current->_obj = obj; } return _current != NULL; } bool TObject_tree::set_object(const TObject& obj) -{ +{ bool ok = false; if (_current) { @@ -516,21 +516,21 @@ bool TObject_tree::set_object(const TObject& obj) if (!ok) delete ptr; } - return ok; + return ok; } bool TObject_tree::create_root() { if (!has_root()) _root = _current = new TTree_node; - return goto_root(); + return goto_root(); } bool TObject_tree::add_son(TObject* obj) { bool ok = false; if (_root) - { + { TTree_node*& curson = _current->_son; TTree_node* newson = new TTree_node; newson->_father = _current; @@ -551,15 +551,15 @@ bool TObject_tree::add_son(TObject* obj) } bool TObject_tree::add_son(const TObject& obj) -{ +{ TObject* ptr = obj.dup(); bool ok = add_son(ptr); if (!ok) delete ptr; return ok; -} +} bool TObject_tree::add_brother(TObject* obj) -{ +{ bool ok = false; if (goto_father()) ok = add_son(obj); @@ -569,18 +569,18 @@ bool TObject_tree::add_brother(TObject* obj) } bool TObject_tree::add_brother(const TObject& obj) -{ +{ TObject* ptr = obj.dup(); bool ok = add_brother(ptr); if (!ok) delete ptr; return ok; -} +} bool TObject_tree::add_rbrother(TObject* obj) -{ +{ bool ok = false; if (has_father()) - { + { TTree_node* newbrother = new TTree_node; newbrother->_father = _current->_father; newbrother->_lbrother = _current; @@ -598,29 +598,29 @@ bool TObject_tree::add_rbrother(TObject* obj) } bool TObject_tree::add_rbrother(const TObject& obj) -{ +{ TObject* ptr = obj.dup(); bool ok = add_rbrother(ptr); if (!ok) delete ptr; return ok; -} +} bool TObject_tree::add_lbrother(TObject* obj) -{ +{ bool ok = false; if (has_father()) - { + { if (_current->_lbrother == NULL) ok = add_brother(obj); else - { + { TTree_node* newbrother = new TTree_node; newbrother->_father = _current->_father; newbrother->_rbrother = _current; newbrother->_lbrother = _current->_lbrother; _current->_lbrother = newbrother; ok = goto_lbrother(); - } + } } else ok = create_root(); @@ -630,18 +630,18 @@ bool TObject_tree::add_lbrother(TObject* obj) } bool TObject_tree::add_lbrother(const TObject& obj) -{ +{ TObject* ptr = obj.dup(); bool ok = add_lbrother(ptr); if (!ok) delete ptr; return ok; -} +} bool TObject_tree::kill_node() { bool ok = false; if (_current) - { + { TTree_node* cur = _current; while (goto_firstson()) { @@ -651,38 +651,38 @@ bool TObject_tree::kill_node() if (_current->_lbrother) { _current->_lbrother->_rbrother = _current->_rbrother; - } + } else { if (_current->_father) _current->_father->_son = _current->_rbrother; - } + } if (_current->_rbrother) _current->_rbrother->_lbrother = _current->_lbrother; #ifdef DBG_TREE TString id; curr_id(id); _expanded.remove(id); -#endif +#endif TTree_node* to_be_killed = _current; if (_current == _root) _root = NULL; - + if (_current->_rbrother) - _current = _current->_rbrother; - else + _current = _current->_rbrother; + else { if (_current->_lbrother) - _current = _current->_lbrother; + _current = _current->_lbrother; else - _current = _current->_father; + _current = _current->_father; } delete to_be_killed; - ok = true; + ok = true; } return ok; } @@ -704,7 +704,7 @@ TObject_tree::~TObject_tree() { if (goto_root()) kill_node(); -} +} /////////////////////////////////////////////////////////// // TString_tree @@ -713,11 +713,11 @@ TObject_tree::~TObject_tree() bool TString_tree::get_description(TString& str) const { const TString* obj = (const TString*)curr_node(); - if (obj) + if (obj) str = *obj; else str.cut(0); - return obj != NULL; + return obj != NULL; } /////////////////////////////////////////////////////////// @@ -735,29 +735,29 @@ public: long _plusx; long _startx; long _endx; - + const TNode_info& operator =(const TNode_info& ni) - { + { _valid = ni._valid; _enabled = ni._enabled; _expanded = ni._expanded; _expandable = ni._expandable; - _id = ni._id; - _plusx = ni._plusx; - _startx = ni._startx; - _endx = ni._endx; + _id = ni._id; + _plusx = ni._plusx; + _startx = ni._startx; + _endx = ni._endx; return ni; } - + virtual int compare(const TSortable& s) const - { + { const TNode_info& ni = (const TNode_info&)s; return _id.compare(ni._id); } - + virtual bool ok() const { return _valid; } void reset() { _valid = false; } - + TNode_info() : _valid(false) { } virtual ~TNode_info() { } }; @@ -770,13 +770,13 @@ public: int last() const; int find(const TNode_info& ni) const; TNode_info& operator[](int index); - const TNode_info& operator[](int index) const + const TNode_info& operator[](int index) const { return (const TNode_info&)_data[index]; } void reset(); }; TNode_info& TNode_info_array::operator[](int index) -{ +{ CHECKD(index >= 0, "Bad index ", index); TNode_info* ni = (TNode_info*)_data.objptr(index); if (ni == NULL) @@ -806,7 +806,7 @@ int TNode_info_array::find(const TNode_info& ni) const { int i; for (i = last(); i >= 0; i = _data.pred(i)) - { + { if (((TNode_info*)_data.objptr(i))->compare(ni) == 0) break; } @@ -821,7 +821,7 @@ int TNode_info_array::find(const TNode_info& ni) const #include class TTree_window : public TField_window -{ +{ TTree* _tree; bool _hide_leaves; long _first_line; // Prima riga disegnata @@ -847,11 +847,11 @@ protected: // Internal use void update_header(); void draw_plus_minus(); void draw_text(int x, int y, const TString& str); - + int info2index(const TNode_info& ni) const; bool index2info(long index, TNode_info& ni); - -public: + +public: TTree* tree() const { return _tree; } void set_tree(TTree* tree) { _tree = tree; _first_line = -1; } void hide_leaves(bool yes) { _hide_leaves = yes; } @@ -862,7 +862,7 @@ public: - TTree_window(int x, int y, int dx, int dy, + TTree_window(int x, int y, int dx, int dy, WINDOW parent, TTree_field* owner); virtual ~TTree_window() { } }; @@ -872,7 +872,7 @@ bool TTree_window::_tree_locked = false; const int TABX = 3; struct TUpdate_info -{ +{ TTree_window* _win; TToken_string _str; long _x, _y; @@ -890,7 +890,7 @@ PNT TTree_window::log2dev(long x, long y) const y += _headlines; if (autoscrolling()) - { + { if (_pixmap) { x -= origin().x * CHARX; @@ -900,7 +900,7 @@ PNT TTree_window::log2dev(long x, long y) const { x -= origin().x; y -= origin().y; - } + } } PNT pnt; pnt.h = (int)x; pnt.v = (int)y; @@ -910,17 +910,17 @@ PNT TTree_window::log2dev(long x, long y) const pnt.h *= CHARX; pnt.v *= _row_height; } - + return pnt; } TPoint TTree_window::dev2log(const PNT& dp) const { PNT p = dp; - + if (_headlines > 0) p.v -= _headlines * _row_height; - + TPoint pnt(_pixmap ? p.h : p.h/CHARX, _pixmap ? p.v : p.v/_row_height); return pnt; } @@ -934,18 +934,18 @@ void TTree_window::draw_text(int x, int y, const TString& str) const TString& mid = str.sub(start, pos); if (!mid.blank()) stringat(x + start, y, mid); - start = pos+2; + start = pos+2; } } bool TTree_window::callback_draw_node(TTree& node, void* jolly, word when) { TUpdate_info* ui = (TUpdate_info*)jolly; - + if (when == SCAN_PRE_ORDER) { - if (ui->_y >= ui->_firsty && ui->_y <= ui->_lasty) - { + if (ui->_y >= ui->_firsty && ui->_y <= ui->_lasty) + { node.curr_id(ui->_str); const bool is_selected = ui->_str == ui->_curr_info->_id; const bool is_enabled = node.enabled(); @@ -959,21 +959,21 @@ bool TTree_window::callback_draw_node(TTree& node, void* jolly, word when) ui->_win->set_color(is_enabled ? NORMAL_COLOR : DISABLED_COLOR, NORMAL_BACK_COLOR); ui->_win->draw_text(int(ui->_x+2), int(ui->_y), ui->_str); } - + const int ry = int(ui->_y - ui->_firsty); int by; - + for (by = ry-1; by >= 0; by--) { long rx = (*ui->_node_info)[by]._startx; if (rx < ui->_x) break; - } - + } + const PNT p = ui->_win->log2dev(ui->_x, ui->_y); const WINDOW win = ui->_win->win(); ui->_win->set_pen(DISABLED_COLOR); - + const int rh = ui->_win->row_height(); PNT q; @@ -982,10 +982,10 @@ bool TTree_window::callback_draw_node(TTree& node, void* jolly, word when) q.h -= TABX*CHARX - 3*CHARX/2; xvt_dwin_draw_line(win, q); q.v = (by+1+ui->_headlines)*rh; - + xvt_dwin_draw_line(win, q); - - TImage* bmp = node.image(is_selected); + + TImage* bmp = node.image(is_selected); if (bmp) { const int x = p.h; @@ -993,7 +993,7 @@ bool TTree_window::callback_draw_node(TTree& node, void* jolly, word when) if (is_enabled) bmp->draw(win, x, y); else - { + { TImage dis(*bmp); for (int j = dis.height()-1; j >= 0; j--) for (int i = dis.width() - (j&1 ? 2 : 1); i >= 0; i-=2) @@ -1001,7 +1001,7 @@ bool TTree_window::callback_draw_node(TTree& node, void* jolly, word when) dis.draw(win, x, y); } } - + TNode_info& ni = (*ui->_node_info)[ry]; node.curr_id(ni._id); ni._valid = true; @@ -1018,35 +1018,35 @@ bool TTree_window::callback_draw_node(TTree& node, void* jolly, word when) { ni._plusx = 0; ni._expanded = false; - } - } + } + } ui->_y++; - + ui->_x += TABX; if (ui->_x > ui->_jolly) ui->_jolly = ui->_x; } else if (when == SCAN_IN_ORDER) - { + { ui->_x -= TABX; if (ui->_y > ui->_lasty) return true; - } - + } + return false; } void TTree_window::draw_plus_minus() -{ +{ const long firsty = origin().y; const int last_drawn = _node_info.last(); for (int i = last_drawn; i >= 0; i--) { TNode_info& ni = _node_info[i]; if (ni._plusx > 0) - { + { if (ni._expanded) - { + { bool spudorato = i == last_drawn; // Falso espandibile if (!spudorato) { @@ -1054,20 +1054,20 @@ void TTree_window::draw_plus_minus() spudorato = nni._startx <= ni._startx; } if (spudorato) - { + { ni._expandable = false; ni._expanded = false; ni._plusx = 0; continue; } } - + WINDOW w = win(); PNT r = log2dev(ni._plusx, firsty + i); r.v += _row_height/2; r.h += CHARX/2; - - RCT rct; + + RCT rct; rct.left = r.h - 4; rct.top = r.v - 4; rct.right = r.h + 5; @@ -1075,27 +1075,27 @@ void TTree_window::draw_plus_minus() set_pen(NORMAL_COLOR); set_brush(NORMAL_BACK_COLOR); xvt_dwin_draw_rect(w, &rct); - - PNT f, t; + + PNT f, t; f.h = rct.left+2; f.v = r.v; - t.h = rct.right+-2; t.v = r.v; + t.h = rct.right+-2; t.v = r.v; xvt_dwin_draw_set_pos(w, f); xvt_dwin_draw_line(w, t); - + if (!ni._expanded) { f.h = r.h; f.v = rct.top+2; - t.h = r.h; t.v = rct.bottom-2; + t.h = r.h; t.v = rct.bottom-2; xvt_dwin_draw_set_pos(w, f); xvt_dwin_draw_line(w, t); } - } + } } } -void TTree_window::set_header(const char* head) -{ - _header = head; +void TTree_window::set_header(const char* head) +{ + _header = head; _headlines = _header.items(); } @@ -1117,15 +1117,15 @@ void TTree_window::update_header() } void TTree_window::update() -{ +{ TField_window::update(); if (_tree == NULL) return; - + update_header(); - - TUpdate_info ui; + + TUpdate_info ui; ui._win = this; ui._x = 0; ui._y = 0; @@ -1135,7 +1135,7 @@ void TTree_window::update() ui._headlines = _headlines; ui._node_info = &_node_info; ui._curr_info = &_curr_info; - + bool ok = false; if (_first_line > 0) { @@ -1143,38 +1143,38 @@ void TTree_window::update() TNode_info ni; if (index2info(index, ni)) { - ok = _tree->goto_node(ni._id); + ok = _tree->goto_node(ni._id); ui._x = ni._startx; ui._y = ui._firsty; - } - } + } + } if (!ok) { ok = _tree->goto_root(); - if (!ok) + if (!ok) return; } - + _node_info.reset(); set_opaque_text(true); - + word flags = SCAN_PRE_ORDER | SCAN_IN_ORDER | SCAN_IGNORING_UNEXPANDED; if (_hide_leaves) flags |= SCAN_IGNORING_LEAVES; - + _tree->scan_depth_first(callback_draw_node, &ui, flags); while (ui._y < ui._lasty) { if (_tree->goto_father()) - { + { ui._x -= TABX; if (_tree->goto_rbrother()) _tree->scan_depth_first(callback_draw_node, &ui, flags); - } + } else - break; - } + break; + } draw_plus_minus(); - + set_scroll_max(ui._jolly+columns(), ui._y); _first_line = ui._firsty; } @@ -1196,47 +1196,47 @@ bool TTree_window::goto_selected() return ok; } -void TTree_window::set_row_height(int rh) -{ +void TTree_window::set_row_height(int rh) +{ if (rh <= 0) rh = CHARY+2; - _row_height = rh; + _row_height = rh; } int TTree_window::info2index(const TNode_info& info) const -{ +{ return _node_info.find(info); } bool TTree_window::index2info(long index, TNode_info& ni) -{ +{ bool ok = false; const int last = _node_info.last(); if (index == -1) - { + { if (index2info(0, ni) && _tree->goto_node(ni._id)) - { + { ok = _tree->goto_lbrother(); if (!ok) { ok = _tree->goto_father(); ni._startx -= TABX; - } + } if (ok) _tree->curr_id(ni._id); } } else - if (index == last+1 && last >= 0) + if (index == last+1 && last >= 0) { if (index2info(last, ni) && _tree->goto_node(ni._id)) - { + { ok = _tree->expanded() && _tree->goto_firstson(); if (ok && _hide_leaves && !_tree->has_son()) - { + { _tree->goto_node(ni._id); // Ritorno al padre perche' ignoro le foglie ok = false; - } + } if (!ok) { ok = _tree->goto_rbrother(); @@ -1245,8 +1245,8 @@ bool TTree_window::index2info(long index, TNode_info& ni) if (ok) { _tree->curr_id(ni._id); - } - } + } + } } else if (index >= 0 && index <= last) { @@ -1254,8 +1254,8 @@ bool TTree_window::index2info(long index, TNode_info& ni) ok = info.ok(); if (ok) ni = info; - } - + } + return ok; } @@ -1268,32 +1268,32 @@ bool TTree_window::on_key(KEY key) { if (_tree->goto_node(_curr_info._id) && !_tree->expanded() && _tree->has_son()) - key = K_ENTER; - else + key = K_ENTER; + else key = K_DOWN; } if (key == K_LEFT) { - if (_tree->goto_node(_curr_info._id) && + if (_tree->goto_node(_curr_info._id) && _tree->expanded()) - key = K_ENTER; - else + key = K_ENTER; + else key = K_UP; } if (key == K_UP || key == K_DOWN) - { - _tree_locked = true; + { + _tree_locked = true; int index = info2index(_curr_info); - if (key == K_UP) + if (key == K_UP) index--; - else + else index++; - + bool ok = false; - bool scroll = false; - + bool scroll = false; + TNode_info ni; if (index2info(index, ni)) { @@ -1305,8 +1305,8 @@ bool TTree_window::on_key(KEY key) const int index = key == K_UP ? 0 : _node_info.last(); ok = index2info(index, ni) && _tree->goto_node(ni._id); } - - if (ok && _curr_info != ni) + + if (ok && _curr_info != ni) { _tree->curr_id(_curr_info._id); owner().on_key(K_SPACE); @@ -1314,65 +1314,65 @@ bool TTree_window::on_key(KEY key) { force_update(); do_events(); - } - } - + } + } + _tree_locked = false; if (!scroll) return true; } - + if (key == K_ENTER) - { + { _tree_locked = true; if (_tree->goto_node(_curr_info._id)) - { + { if (_tree->has_son()) { bool ok; if (_tree->expanded()) ok = _tree->shrink(); - else + else ok = _tree->expand(); - if (ok) + if (ok) { force_update(); do_events(); // Make sure of being well positioned after the redraw!!! - _tree->goto_node(_curr_info._id); + _tree->goto_node(_curr_info._id); } } owner().on_key(K_CTRL + K_SPACE); } _tree_locked = false; } - + return TField_window::on_key(key); } void TTree_window::handler(WINDOW win, EVENT* ep) -{ - switch(ep->type) +{ + switch(ep->type) { case E_MOUSE_DBL: case E_MOUSE_DOWN: if (_tree && !_tree_locked) - { + { _tree_locked = true; const TPoint lp = dev2log(ep->v.mouse.where); const int c = (int)lp.x; const int r = (int)lp.y; - + TNode_info ni; bool ok = index2info(r, ni); - 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)) - { + { if (c == ni._plusx || (ni._expandable && ep->type == E_MOUSE_DBL && c <= ni._plusx+3)) - { + { if (_tree->expanded()) ok = _tree->shrink(); - else + else ok = _tree->expand(); if (ok) { @@ -1386,15 +1386,15 @@ void TTree_window::handler(WINDOW win, EVENT* ep) if (ep->type == E_MOUSE_DBL) key += K_CTRL; // Double click selection owner().on_key(key); - } + } if (ok) { _curr_info = ni; force_update(); - } - } + } + } _tree_locked = false; - } + } break; default: TField_window::handler(win, ep); @@ -1402,11 +1402,11 @@ void TTree_window::handler(WINDOW win, EVENT* ep) } } -TTree_window::TTree_window(int x, int y, int dx, int dy, - WINDOW parent, TTree_field* owner) - : TField_window(x, y, dx, dy, parent, owner), _tree(NULL), +TTree_window::TTree_window(int x, int y, int dx, int dy, + WINDOW parent, TTree_field* owner) + : TField_window(x, y, dx, dy, parent, owner), _tree(NULL), _hide_leaves(false), _headlines(0) -{ +{ set_row_height(-1); // Compute default row height } @@ -1426,13 +1426,13 @@ bool TTree_field::is_kind_of(word cid) const #define tree_win() ((TTree_window&)win()) -TTree* TTree_field::tree() const -{ +TTree* TTree_field::tree() const +{ return tree_win().tree(); } -void TTree_field::set_tree(TTree* tree) -{ +void TTree_field::set_tree(TTree* tree) +{ tree_win().set_tree(tree); tree_win().select_current(); }