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
This commit is contained in:
villa 1995-04-13 07:45:30 +00:00
parent 5bb4ea1e2d
commit 1f0d3a4fb7
6 changed files with 335 additions and 144 deletions

View File

@ -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 <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
@ -176,9 +176,14 @@ link_item *TPrint_application::_look_print_node (link_item * head, int logicnum)
return NULL; 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) 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) void TPrint_application::add_file (int file, int from)
@ -414,7 +419,7 @@ void TPrint_application::reset_print ()
_print_defined = FALSE; _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"); CHECK (r >= 1, "Header rows start at 1");
va_list vl; va_list vl;
@ -422,7 +427,7 @@ void TPrint_application::set_header (int r, const char *fmt,...)
vsprintf (__tmp_string, fmt, vl); vsprintf (__tmp_string, fmt, vl);
va_end (vl); va_end (vl);
TPrintrow *pp = (TPrintrow *) _header.objptr (r - 1); TPrintrow *pp = (TPrintrow *)_header.objptr(r - 1);
if (!pp) if (!pp)
{ {
pp = new TPrintrow; pp = new TPrintrow;
@ -729,7 +734,7 @@ void TPrint_application::set_row (int r, const char *frmt,...)
{ {
// no format specifications // no format specifications
// use default picture // use default picture
q = rrr->string (_picture); q = rrr->string(_picture);
} }
else else
{ {
@ -758,7 +763,6 @@ void TPrint_application::set_row (int r, const char *frmt,...)
} }
break; break;
case '\n': // ignore case '\n': // ignore
break; break;
default: default:
// add to string // add to string
@ -1226,7 +1230,7 @@ bool TPrint_application::print_one (int file)
for (i = 0; i <= /*_maxrow*/ last; i++) for (i = 0; i <= /*_maxrow*/ last; i++)
{ {
TPrintrow *pr = (TPrintrow *) & rw[i]; TPrintrow *pr = (TPrintrow *) & rw[i];
if (!(printer().print (*pr))) if (!(printer().print(*pr)))
break; break;
} }
if (_auto_ff && _maxrow < printer().formlen ()) 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)); 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().setfooterhandler (_pp_footer);
printer().setheaderhandler (_pp_header); printer().setheaderhandler (_pp_header);
printer().setlinkhandler (_pp_link); printer().setlinkhandler (_pp_link);

View File

@ -330,6 +330,16 @@ public:
void set_translation(int lognum, const char* field, void set_translation(int lognum, const char* field,
const char* from, const char* to); 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 // hypertext interface for viswin

View File

@ -967,7 +967,7 @@ bool TPrinter::printrow(TPrintrow* rowtoprint)
if (_printertype == screenvis) if (_printertype == screenvis)
{ {
if (!_vf->frozen ()) if (!_vf->frozen ())
_vf->add_line (rw); _vf->add_line(rw);
else else
_frozen = TRUE; _frozen = TRUE;
return 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 () void TPrinter::close ()
{ {
const bool isfirstpage = (_currentpage == 1 && _frompage == 0) || const bool isfirstpage = (_currentpage == 1 && _frompage == 0) ||
@ -1473,6 +1493,7 @@ void TPrinter::close ()
if (_vf->is_open ()) _vf->close_modal (); if (_vf->is_open ()) _vf->close_modal ();
delete _vf; delete _vf;
freeze (FALSE); freeze (FALSE);
_bookmarks.destroy();
_vf = NULL; _vf = NULL;
if (key == K_CTRL+'S') if (key == K_CTRL+'S')

View File

@ -99,6 +99,19 @@ public:
}; };
class BkDef : public TObject
{
public:
int _id;
int _father_id;
TString _txt;
long _row;
BkDef() {}
virtual ~BkDef() {}
};
class TPrinter; class TPrinter;
typedef void (*PRINTSECTIONHANDLER)(TPrinter& printer); typedef void (*PRINTSECTIONHANDLER)(TPrinter& printer);
@ -142,8 +155,10 @@ class TPrinter : public TObject
TDate _date; // printing date TDate _date; // printing date
TFilename _printerfile; // filename for printing on file TFilename _printerfile; // filename for printing on file
TArray _linksdescr; TArray _linksdescr;
TArray _bookmarks; // bookmarks
bool _multiple_link; // bool _multiple_link; //
TString_array _background; TString_array _background;
TString_array _image_names; TString_array _image_names;
@ -229,6 +244,7 @@ public:
void setbackground(const char* bg); void setbackground(const char* bg);
TString_array& image_names() { return _image_names; } TString_array& image_names() { return _image_names; }
TString_array& getbgdesc() { return _background; } TString_array& getbgdesc() { return _background; }
TArray& get_bookmarks() { return _bookmarks; }
bool frozen() { return _frozen; } bool frozen() { return _frozen; }
void freeze(bool b = TRUE) { _frozen = b; } void freeze(bool b = TRUE) { _frozen = b; }
int n_copies() { return _ncopies; } int n_copies() { return _ncopies; }
@ -287,6 +303,9 @@ public:
int get_dots_per_line() const { return _dots_per_line; } int get_dots_per_line() const { return _dots_per_line; }
bool isgraphics() const { return _isgraphics; } bool isgraphics() const { return _isgraphics; }
int get_char_size() const { return _ch_size; } int get_char_size() const { return _ch_size; }
// bookmarks
int set_bookmark(const char* txt, int father = -1);
}; };

View File

@ -55,6 +55,30 @@ const long E_ADDLINE = 488L;
HIDDEN bool in_update; 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 int TViswin::tabx(int x) const
{ {
HIDDEN long w = 0L; HIDDEN long w = 0L;
@ -84,6 +108,104 @@ void TViswin::enable_menu_item(MENU_TAG item, bool on)
xvt_menu_update(win()); 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() void TViswin::exec_link()
{ {
@ -1022,7 +1144,14 @@ void TViswin::handler (WINDOW win, EVENT * ep)
autoscroll (TRUE); autoscroll (TRUE);
break; break;
case E_COMMAND: case E_COMMAND:
switch(ep->v.cmd.tag) 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 case M_EDIT_CLIPBOARD: // interrompi
dispatch_e_char(win, K_ESC); dispatch_e_char(win, K_ESC);
@ -1975,6 +2104,9 @@ void TViswin::close_print ()
enable_menu_item(M_EDIT_CLIPBOARD, FALSE); enable_menu_item(M_EDIT_CLIPBOARD, FALSE);
xvt_enable_control(_print_button, TRUE); xvt_enable_control(_print_button, TRUE);
enable_menu_item(M_EDIT_SEL_ALL, TRUE); enable_menu_item(M_EDIT_SEL_ALL, TRUE);
// build bookmark menu tree
if (_bookmarks->items() > 0)
build_index_menu();
} }
force_update (); force_update ();
} }
@ -2234,6 +2366,8 @@ TViswin::TViswin(const char *fname,
_links = _toplevel ? &(main_app().printer().links()) : &(_brwfld->_links); _links = _toplevel ? &(main_app().printer().links()) : &(_brwfld->_links);
_multiple = _toplevel ? (main_app().printer ().ismultiplelink()) : _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(); _bg = _toplevel ? &(main_app().printer().getbgdesc()) : _brwfld->get_bg_desc();
_formlen = _toplevel ? main_app().printer().formlen() : maxalt; _formlen = _toplevel ? main_app().printer().formlen() : maxalt;
_linkID = -1; _linkID = -1;
@ -2247,6 +2381,7 @@ TViswin::TViswin(const char *fname,
t.restart(); t.restart();
_txt.set_hotspots(f, b); _txt.set_hotspots(f, b);
} }
_hotspots = &(_txt.hotspots()); _hotspots = &(_txt.hotspots());
main_app().end_wait(); main_app().end_wait();

View File

@ -72,6 +72,7 @@ class TViswin : public TScroll_window
TArray* _links; // admitted links TArray* _links; // admitted links
TArray* _hotspots; // hotspots TArray* _hotspots; // hotspots
TArray* _bookmarks; // bookmarks
bool need_paint_sel(bool smart = TRUE); bool need_paint_sel(bool smart = TRUE);
@ -130,6 +131,7 @@ protected:
void display_link(long, long, long, const char*); void display_link(long, long, long, const char*);
void freeze() { _frozen = TRUE; } void freeze() { _frozen = TRUE; }
void exec_link(); void exec_link();
void build_index_menu();
protected: protected:
void scroll_error(long x, long y); void scroll_error(long x, long y);