From 1f0d3a4fb7c71ba0e44c72a3a8ee86fdac8887d2 Mon Sep 17 00:00:00 2001 From: villa Date: Thu, 13 Apr 1995 07:45:30 +0000 Subject: [PATCH] Aggiunti 'bookmarks' a printapp, printer e viswin, con generazione automatica del menu Indice git-svn-id: svn://10.65.10.50/trunk@1245 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/printapp.cpp | 274 ++++++++++++++++++++++--------------------- include/printapp.h | 10 ++ include/printer.cpp | 25 +++- include/printer.h | 25 +++- include/viswin.cpp | 143 +++++++++++++++++++++- include/viswin.h | 2 + 6 files changed, 335 insertions(+), 144 deletions(-) diff --git a/include/printapp.cpp b/include/printapp.cpp index 7fa0868ab..becfdaf76 100755 --- a/include/printapp.cpp +++ b/include/printapp.cpp @@ -1,4 +1,4 @@ -// $Id: printapp.cpp,v 1.20 1995-04-12 15:44:43 alex Exp $ +// $Id: printapp.cpp,v 1.21 1995-04-13 07:45:10 villa Exp $ #include #include @@ -176,9 +176,14 @@ link_item *TPrint_application::_look_print_node (link_item * head, int logicnum) return NULL; } +int TPrint_application::set_bookmark(const char* txt, int father) +{ + return printer().set_bookmark(txt, father); +} + void TPrint_application::add_file (const char *tab, int from) { - add_file (TTable ::name2log (tab), from); + add_file(TTable::name2log (tab), from); } void TPrint_application::add_file (int file, int from) @@ -414,7 +419,7 @@ void TPrint_application::reset_print () _print_defined = FALSE; } -void TPrint_application::set_header (int r, const char *fmt,...) +void TPrint_application::set_header (int r, const char *fmt, ...) { CHECK (r >= 1, "Header rows start at 1"); va_list vl; @@ -422,12 +427,12 @@ void TPrint_application::set_header (int r, const char *fmt,...) vsprintf (__tmp_string, fmt, vl); va_end (vl); - TPrintrow *pp = (TPrintrow *) _header.objptr (r - 1); + TPrintrow *pp = (TPrintrow *)_header.objptr(r - 1); if (!pp) - { - pp = new TPrintrow; - _header.add (pp, r - 1); - } + { + pp = new TPrintrow; + _header.add (pp, r - 1); + } pp->put (__tmp_string); } @@ -440,10 +445,10 @@ void TPrint_application::set_footer (int r, const char *fmt,...) va_end (vl); TPrintrow *pp = (TPrintrow *) _footer.objptr (r - 1); if (pp == NULL) - { - pp = new TPrintrow; - _footer.add (pp, r - 1); - } + { + pp = new TPrintrow; + _footer.add (pp, r - 1); + } pp->put (__tmp_string); } @@ -463,10 +468,10 @@ void TPrint_application::fill_page (int from) { from--; for (int i = (from == -1 ? _maxrow : from); i <= printer().formlen (); i++) - { - reset_row (i); - set_row (i, ""); - } + { + reset_row (i); + set_row (i, ""); + } } void TPrint_application::merge_export_file(const char* file, bool header, bool direct) @@ -511,27 +516,27 @@ void TPrint_application::set_row (int r, const char *frmt,...) // parse format string while ((ch = *fmt++) != '\0') - { - if (ch == '@') + { + if (ch == '@') { // check for pending string if (strind) - { - strbuf[strind] = '\0'; - _rows.add (new _PrintfTok (_currow, strbuf)); - strind = 0; - } + { + strbuf[strind] = '\0'; + _rows.add (new _PrintfTok (_currow, strbuf)); + strind = 0; + } ch = *fmt++; if (isdigit (ch)) - { - int i = 0; - digbuf[i++] = ch; - while (isdigit (ch = *fmt++)) - digbuf[i++] = ch; - digbuf[i] = '\0'; - size = atoi (digbuf); - flags |= PAD_FLAG; - if (ch == '.') + { + int i = 0; + digbuf[i++] = ch; + while (isdigit (ch = *fmt++)) + digbuf[i++] = ch; + digbuf[i] = '\0'; + size = atoi (digbuf); + flags |= PAD_FLAG; + if (ch == '.') { // decimal size follows i = 0; @@ -543,7 +548,7 @@ void TPrint_application::set_row (int r, const char *frmt,...) flags |= DEC_FLAG; // ch = *fmt++; } - else if (ch == ',') + else if (ch == ',') { // aligment spec follows align = (ch = *fmt++); @@ -552,95 +557,95 @@ void TPrint_application::set_row (int r, const char *frmt,...) flags |= ALIGN_FLAG; ch = *fmt++; } - } + } switch (ch) - { - // modifiers - case 'l': - case 'L': - flags |= LONG_FLAG; - ch = *fmt++; - break; - case 'p': - case 'P': - flags |= PICTURE_FLAG; - ch = *fmt++; - break; - } + { + // modifiers + case 'l': + case 'L': + flags |= LONG_FLAG; + ch = *fmt++; + break; + case 'p': + case 'P': + flags |= PICTURE_FLAG; + ch = *fmt++; + break; + } switch (ch) - { - // codes - case '@': - _rows.add (new _PrintfTok (_currow, "@")); - break; - case 'b': - case 'i': - case 'u': - case 'r': - { - char *xxxx = new char[2]; + { + // codes + case '@': + _rows.add (new _PrintfTok (_currow, "@")); + break; + case 'b': + case 'i': + case 'u': + case 'r': + { + char *xxxx = new char[2]; xxxx[0] = ch; xxxx[1] = '\0'; _rows.add (new _FieldTok (_currow, xxxx, FONT_FLAG)); - } - break; - case 'g': - case 'j': - { + } + break; + case 'g': + case 'j': + { const char *xxx = format ("%c %d", ch, size); char *xxxx = new char[strlen (xxx) + 1]; strcpy (xxxx, xxx); _rows.add (new _FieldTok (_currow, xxxx, JUMP_FLAG)); - } - break; - case 'T': - flags |= IGNORE_FILL; - case 't': - flags |= TRANS_FLAG; - break; - case 'D': - flags |= IGNORE_FILL; - case 'd': - flags |= DATE_FLAG; - break; - case 'F': - flags |= IGNORE_FILL; - case 'f': - flags |= BOOLEAN_FLAG; - break; - case 'S': - flags |= IGNORE_FILL; - case 's': - flags |= STRING_FLAG; - break; - case 'C': - flags |= IGNORE_FILL; - case 'c': - flags |= RECNO_FLAG; - break; - case 'N': - flags |= IGNORE_FILL; - case 'n': - flags |= NUMBER_FLAG; - break; - default: - CHECK (0, "TPrint_application::set_row: invalid @ code"); - break; - } + } + break; + case 'T': + flags |= IGNORE_FILL; + case 't': + flags |= TRANS_FLAG; + break; + case 'D': + flags |= IGNORE_FILL; + case 'd': + flags |= DATE_FLAG; + break; + case 'F': + flags |= IGNORE_FILL; + case 'f': + flags |= BOOLEAN_FLAG; + break; + case 'S': + flags |= IGNORE_FILL; + case 's': + flags |= STRING_FLAG; + break; + case 'C': + flags |= IGNORE_FILL; + case 'c': + flags |= RECNO_FLAG; + break; + case 'N': + flags |= IGNORE_FILL; + case 'n': + flags |= NUMBER_FLAG; + break; + default: + CHECK (0, "TPrint_application::set_row: invalid @ code"); + break; + } if (flags & NUMBER_FLAG || flags & DATE_FLAG || flags & TRANS_FLAG || flags & BOOLEAN_FLAG || flags & STRING_FLAG) - { - char *xxx = va_arg (params, char *); - _rows.add (new _FieldTok (_currow, xxx, + { + char *xxx = va_arg (params, char *); + _rows.add (new _FieldTok (_currow, xxx, flags, align, size, dec)); - } + } flags = 0x0000; align = 'l'; } - else + else { TString t; switch (ch) @@ -729,7 +734,7 @@ void TPrint_application::set_row (int r, const char *frmt,...) { // no format specifications // use default picture - q = rrr->string (_picture); + q = rrr->string(_picture); } else { @@ -758,7 +763,6 @@ void TPrint_application::set_row (int r, const char *frmt,...) } break; case '\n': // ignore - break; default: // add to string @@ -870,46 +874,46 @@ bool TPrint_application::print_tree (link_item * head) { bool go = TRUE; while (head) - { - head->_cnt = 0; - if (_cur->is_first_match (head->_logicnum)) + { + head->_cnt = 0; + if (_cur->is_first_match (head->_logicnum)) { do - { - if (!preprocess_print (head->_logicnum, head->_cnt)) - break; - do + { + if (!preprocess_print (head->_logicnum, head->_cnt)) + break; + do { // set print rows according to current file if (_force_setpage || _cur_file != head->_logicnum || !_print_defined) - { - reset_print (); - set_page(head->_logicnum, head->_cnt); - _cur_file = head->_logicnum; - } + { + reset_print (); + set_page(head->_logicnum, head->_cnt); + _cur_file = head->_logicnum; + } int cnt2 = 0; do - { - if (!preprocess_page (head->_logicnum, cnt2)) - break; - go = print_one (head->_logicnum); - if (go && head->_son) - go = print_tree (head->_son); - } + { + if (!preprocess_page (head->_logicnum, cnt2)) + break; + go = print_one (head->_logicnum); + if (go && head->_son) + go = print_tree (head->_son); + } while (go && postprocess_page (head->_logicnum, cnt2++) == REPEAT_PAGE); } - while (go && _cur->next_match (head->_logicnum)); - } + while (go && _cur->next_match (head->_logicnum)); + } while (go && postprocess_print (head->_logicnum, head->_cnt++) == REPEAT_PAGE); } - if (!go) - break; - go = TRUE; - head = head->_brother; - } + if (!go) + break; + go = TRUE; + head = head->_brother; + } return go; } @@ -1226,7 +1230,7 @@ bool TPrint_application::print_one (int file) for (i = 0; i <= /*_maxrow*/ last; i++) { TPrintrow *pr = (TPrintrow *) & rw[i]; - if (!(printer().print (*pr))) + if (!(printer().print(*pr))) break; } if (_auto_ff && _maxrow < printer().formlen ()) @@ -1251,9 +1255,9 @@ bool TPrint_application::menu(MENU_TAG m) return xvt_test_menu_tag (BAR_ITEM (2)); } -bool TPrint_application::create () +bool TPrint_application::create() { - TApplication ::create (); + TApplication::create(); printer().setfooterhandler (_pp_footer); printer().setheaderhandler (_pp_header); printer().setlinkhandler (_pp_link); diff --git a/include/printapp.h b/include/printapp.h index 69cc2edc1..abb5b2c28 100755 --- a/include/printapp.h +++ b/include/printapp.h @@ -330,6 +330,16 @@ public: void set_translation(int lognum, const char* field, const char* from, const char* to); + // -------------------------------------------------------- + // bookmarks for viswin + // -------------------------------------------------------- + // Aggiungere 'bookmarks' causa la comparsa del menu + // 'Indice' nella viswin, con la lista dei bookmark inseriti; + // questi possono essere legati ad albero n-ario specificando + // il bookmark padre, in tal caso il menu sara' gerarchico a + // sua volta. Prossima release di XVT il menu indice sara' + // pop-up nella finestra + int set_bookmark(const char* txt, int father = -1); // -------------------------------------------------------- // hypertext interface for viswin diff --git a/include/printer.cpp b/include/printer.cpp index 88ddfd4cd..4cb492ad5 100755 --- a/include/printer.cpp +++ b/include/printer.cpp @@ -967,7 +967,7 @@ bool TPrinter::printrow(TPrintrow* rowtoprint) if (_printertype == screenvis) { if (!_vf->frozen ()) - _vf->add_line (rw); + _vf->add_line(rw); else _frozen = TRUE; return TRUE; @@ -1450,6 +1450,26 @@ void TPrinter::merge_export_file(const char* file, bool header) } } + +int TPrinter::set_bookmark(const char* txt, int father) +{ + if (_printertype == screenvis) + { + BkDef* bkd = new BkDef; + + bkd->_row = (_currentrow + ((_currentpage - 1)*_formlen)) - 1; + bkd->_father_id = father; + bkd->_id = _bookmarks.items() + 1; + bkd->_txt = txt; + + _bookmarks.add(bkd); + + return _bookmarks.items(); + } + return 0; +} + + void TPrinter::close () { const bool isfirstpage = (_currentpage == 1 && _frompage == 0) || @@ -1472,7 +1492,8 @@ void TPrinter::close () const KEY key = _vf->run (); if (_vf->is_open ()) _vf->close_modal (); delete _vf; - freeze (FALSE); + freeze (FALSE); + _bookmarks.destroy(); _vf = NULL; if (key == K_CTRL+'S') diff --git a/include/printer.h b/include/printer.h index b95203955..10b479332 100755 --- a/include/printer.h +++ b/include/printer.h @@ -99,6 +99,19 @@ public: }; +class BkDef : public TObject +{ +public: + int _id; + int _father_id; + TString _txt; + long _row; + + BkDef() {} + virtual ~BkDef() {} +}; + + class TPrinter; typedef void (*PRINTSECTIONHANDLER)(TPrinter& printer); @@ -142,8 +155,10 @@ class TPrinter : public TObject TDate _date; // printing date TFilename _printerfile; // filename for printing on file TArray _linksdescr; + TArray _bookmarks; // bookmarks bool _multiple_link; // + TString_array _background; TString_array _image_names; @@ -161,7 +176,7 @@ class TPrinter : public TObject int _horz_offset; int _dots_per_line; - void _get_windows_printer_names(TToken_string& t); + void _get_windows_printer_names(TToken_string& t); bool _multiple_copies; bool _export_header; @@ -227,8 +242,9 @@ public: void resetheader(); void resetfooter(); void setbackground(const char* bg); - TString_array& image_names() { return _image_names; } - TString_array& getbgdesc() { return _background; } + TString_array& image_names() { return _image_names; } + TString_array& getbgdesc() { return _background; } + TArray& get_bookmarks() { return _bookmarks; } bool frozen() { return _frozen; } void freeze(bool b = TRUE) { _frozen = b; } int n_copies() { return _ncopies; } @@ -287,6 +303,9 @@ public: int get_dots_per_line() const { return _dots_per_line; } bool isgraphics() const { return _isgraphics; } int get_char_size() const { return _ch_size; } + + // bookmarks + int set_bookmark(const char* txt, int father = -1); }; diff --git a/include/viswin.cpp b/include/viswin.cpp index 48993b4d7..925797e85 100755 --- a/include/viswin.cpp +++ b/include/viswin.cpp @@ -55,6 +55,30 @@ const long E_ADDLINE = 488L; HIDDEN bool in_update; +class _BkMenuItem : public TObject +{ +public: + + TString _txt; + TArray* _arr; + int _id; // per comodita' + + _BkMenuItem(const char* t = "") + { _txt = t; _arr = NULL; } + virtual ~_BkMenuItem() + { if (_arr != NULL) delete _arr; } +}; + +class _BkMenuDesc : public TObject +{ +public: + + TString_array _menu; + int _father_id; + _BkMenuDesc() {} + virtual ~_BkMenuDesc() {} +}; + int TViswin::tabx(int x) const { HIDDEN long w = 0L; @@ -84,6 +108,104 @@ void TViswin::enable_menu_item(MENU_TAG item, bool on) xvt_menu_update(win()); } +HIDDEN _BkMenuItem* find_menu_node(TArray& tree, int id) +{ + _BkMenuItem* fnd = NULL; + + for (int m = 0; m < tree.items(); m++) + { + _BkMenuItem& bkit = (_BkMenuItem&) tree[m]; + + if (bkit._id == id) + return &bkit; + + else if (bkit._arr != NULL) + { + if ((fnd = find_menu_node(*(bkit._arr), id)) != NULL) + break; + } + } + return fnd; +} + +HIDDEN void build_menu_tree(TArray& flat, TArray& tree, int level) +{ + // find ID in flat array + _BkMenuDesc* bds = NULL; + + for (int i = 0; i < flat.items(); i++) + { + _BkMenuDesc& bdss = (_BkMenuDesc&)flat[i]; + if (bdss._father_id == 1000 + level) + { + bds = &bdss; + break; + } + } + if (bds == NULL) + { + bds = new _BkMenuDesc; + bds->_father_id = 1000 + level; + flat.add(bds); + } + + for (i = 0; i < tree.items(); i++) + { + _BkMenuItem& bki = (_BkMenuItem&)tree[i]; + bds->_menu.add(bki._txt); + if (bki._arr != NULL) + build_menu_tree(flat, *(bki._arr), bki._id); + } +} + +void TViswin::build_index_menu() +{ + // builds bk_menu tree and index menu + TArray bk_tree; + TToken_string tt(128); + + // build tree + for (int i = 0; i < _bookmarks->items(); i++) + { + BkDef& bkd = (BkDef&)(*_bookmarks)[i]; + + tt = format("%d", bkd._id + 1000); + tt.add(bkd._txt); + + _BkMenuItem* bkit = new _BkMenuItem((const char*)tt); + bkit->_id = bkd._id; + + int father_id = bkd._father_id == -1 ? 0 : bkd._father_id; + if (father_id == 0) // toplevel + bk_tree.add(bkit); + else + { + _BkMenuItem* father = find_menu_node(bk_tree, father_id); + if (father != NULL) + { + if (father->_arr == NULL) + father->_arr = new TArray(4); + father->_arr->add(bkit); + } + } + } + + // build menu + if (bk_tree.items() > 0) + { + TString_array top(1); top.add("1000|Indice"); + add_menu(top); + } + + TArray flat(4); + build_menu_tree(flat, bk_tree, 0); + + for (i = 0; i < flat.items(); i++) + { + _BkMenuDesc& bds = (_BkMenuDesc&)flat[i]; + add_menu(bds._menu, bds._father_id); + } +} void TViswin::exec_link() { @@ -1021,8 +1143,15 @@ void TViswin::handler (WINDOW win, EVENT * ep) _textcolumns = TEXTCOLUMNS; autoscroll (TRUE); break; - case E_COMMAND: - switch(ep->v.cmd.tag) + case E_COMMAND: + if (ep->v.cmd.tag > 1000 && ep->v.cmd.tag < 2000) + { + // bookmark + int index = ep->v.cmd.tag - 1001; + BkDef& bds = (BkDef&)(*_bookmarks)[index]; + goto_pos(bds._row, 0l); + } + else switch(ep->v.cmd.tag) { case M_EDIT_CLIPBOARD: // interrompi dispatch_e_char(win, K_ESC); @@ -1975,6 +2104,9 @@ void TViswin::close_print () enable_menu_item(M_EDIT_CLIPBOARD, FALSE); xvt_enable_control(_print_button, TRUE); enable_menu_item(M_EDIT_SEL_ALL, TRUE); + // build bookmark menu tree + if (_bookmarks->items() > 0) + build_index_menu(); } force_update (); } @@ -2233,7 +2365,9 @@ TViswin::TViswin(const char *fname, _links = _toplevel ? &(main_app().printer().links()) : &(_brwfld->_links); _multiple = _toplevel ? (main_app().printer ().ismultiplelink()) : - (_brwfld->is_multiple_link()); + (_brwfld->is_multiple_link()); + _bookmarks = &(main_app().printer().get_bookmarks()); + _bg = _toplevel ? &(main_app().printer().getbgdesc()) : _brwfld->get_bg_desc(); _formlen = _toplevel ? main_app().printer().formlen() : maxalt; _linkID = -1; @@ -2246,7 +2380,8 @@ TViswin::TViswin(const char *fname, char b = *(t.get (2)); t.restart(); _txt.set_hotspots(f, b); - } + } + _hotspots = &(_txt.hotspots()); main_app().end_wait(); diff --git a/include/viswin.h b/include/viswin.h index 5e9f60811..763035fe1 100755 --- a/include/viswin.h +++ b/include/viswin.h @@ -72,6 +72,7 @@ class TViswin : public TScroll_window TArray* _links; // admitted links TArray* _hotspots; // hotspots + TArray* _bookmarks; // bookmarks bool need_paint_sel(bool smart = TRUE); @@ -130,6 +131,7 @@ protected: void display_link(long, long, long, const char*); void freeze() { _frozen = TRUE; } void exec_link(); + void build_index_menu(); protected: void scroll_error(long x, long y);