From 16f9494a423cc707e0809b83868d7aece6ca6d01 Mon Sep 17 00:00:00 2001 From: villa Date: Tue, 3 Jan 1995 16:44:27 +0000 Subject: [PATCH] Viswin se possibile ancora piu' extrafiga Aggiunte ricerche, menu, etc. anche a text git-svn-id: svn://10.65.10.50/trunk@818 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/default.url | 34 +++++--- include/text.cpp | 12 ++- include/text.h | 3 +- include/urldefid.h | 16 ++-- include/viswin.cpp | 185 +++++++++++++++++++++++++++++++++++--------- include/viswin.h | 14 +++- include/window.cpp | 6 +- 7 files changed, 202 insertions(+), 68 deletions(-) diff --git a/include/default.url b/include/default.url index 3112af6ad..ea547daea 100755 --- a/include/default.url +++ b/include/default.url @@ -25,16 +25,32 @@ MENU MENU_FILE ITEM (M_FILE+11) "I~nformazioni" ITEM M_FILE_QUIT "~Fine" -MENU MENU_EDIT - ITEM M_EDIT_INSERT "~Inserisci" - ITEM M_EDIT_MODIFY "~Aggiorna" - ITEM M_EDIT_DELETE "~Cancella" - ITEM M_EDIT_SHOW "~Visualizza" - ITEM M_EDIT_SEARCH "C~erca" DISABLED +MENUBAR VISWIN_BAR + +MENU VISWIN_BAR + SUBMENU MENU_VISWIN "~Visualizzazione" + SUBMENU M_EDIT "~Edit" + +MENU MENU_VISWIN + ITEM M_EDIT_CLIPBOARD "Interrompi\tESC" + ITEM M_EDIT_CUT "Collega...\tAlt+C" DISABLED + ITEM M_EDIT_PASTE "Esporta...\tAlt+E" + ITEM M_EDIT_SEL_ALL "Stampa... \tAlt+S" DISABLED + SEPARATOR + ITEM M_FONT "Mostra righelli" CHECKABLE + ITEM M_STYLE "Mostra bottoni" CHECKABLE + SEPARATOR + ITEM M_EDIT_QUIT "Chiudi\tESC+ESC" + +MENU M_EDIT + ITEM M_EDIT_COPY "~Copia" DISABLED + ITEM M_EDIT_CLEAR "~Annulla" DISABLED + SEPARATOR + ITEM M_EDIT_SEARCH "Cerca...\tF8" + ITEM M_EDIT_DELETE "Cerca il prossimo\tF9" DISABLED + SEPARATOR + ITEM M_EDIT_UNDO "~Ridisegna" -MENU MENU_ALT_EDIT - ITEM M_EDIT_EDIT "~Aggiorna" - ITEM M_EDIT_SEARCH "C~erca" DISABLED ACCEL MENU_FILE "f" ALT diff --git a/include/text.cpp b/include/text.cpp index 07d22eece..fb4c8c1f4 100755 --- a/include/text.cpp +++ b/include/text.cpp @@ -214,12 +214,18 @@ const char *TTextfile::line(long j, long pos, int howmuch) } -long TTextfile::search(const char* txt, int& ret, long from, bool down) +long TTextfile::search(const char* txt, int& ret, long from, bool down, + bool casesens) { - TString256 lin; + TString256 lin; TString80 text(txt); + if (!casesens) + text.lower(); + for (long i = from; down ? (i < lines()) : (i >= 0); down ? i++ : i--) { - lin = line(i); + lin = line(i); + if (!casesens) + lin.lower(); if ((ret = lin.find(txt)) != -1) return i; } diff --git a/include/text.h b/include/text.h index 5da16c523..ea504647e 100755 --- a/include/text.h +++ b/include/text.h @@ -109,7 +109,8 @@ public: // search and replace (una riga per volta, rispetta i formati) // txt = text to search; pos = int to put the char position in; // from = where to start; down = FALSE == up - long search (const char* txt, int& pos, long from = 0, bool down = TRUE); + long search (const char* txt, int& pos, long from = 0, + bool down = TRUE, bool casesens = FALSE); // replace txt=txt in line=line at pos=pos for len=len int replace(long line, const char* txt, int pos = 0, int len = -1); diff --git a/include/urldefid.h b/include/urldefid.h index 003fa9ffb..1994c6bf9 100755 --- a/include/urldefid.h +++ b/include/urldefid.h @@ -14,18 +14,14 @@ #define MENU_BAR(i) (10000+i) #define BAR_ITEM(i) (5000+100*i) #define MENU_ITEM(i) (30000+i) +#define VISWIN_BAR (7000) -#define MENU_FILE 1100 -#define MENU_EDIT 1200 -#define MENU_ALT_EDIT 1300 +#define MENU_VISWIN 7100 +#define MENU_FILE BAR_ITEM(0) -#define M_EDIT_INSERT 1201 -#define M_EDIT_MODIFY 1202 -#define M_EDIT_DELETE 1203 -#define M_EDIT_SHOW 1204 -#define M_EDIT_SEARCH 1205 - -#define M_EDIT_EDIT 1301 +#define M_EDIT_SEARCH (M_EDIT+8) +#define M_EDIT_DELETE (M_EDIT+9) +#define M_EDIT_QUIT (M_EDIT+10) #if XVT_OS == XVT_OS_WIN diff --git a/include/viswin.cpp b/include/viswin.cpp index 1a2bdd815..ea66ef8c8 100755 --- a/include/viswin.cpp +++ b/include/viswin.cpp @@ -21,7 +21,7 @@ extern "C" } #endif -#define BUTTONROW_SIZE (_toplevel ? 3 : 0) +#define BUTTONROW_SIZE (_showbuts ? 3 : 0) #define X_OFFSET (_rulers ? 6 : 1) #define Y_OFFSET (_rulers ? 1 : 0) #define TEXTROWS (rows() - Y_OFFSET - BUTTONROW_SIZE) @@ -58,6 +58,19 @@ const long E_ADDLINE = 488L; const long E_ADDLINE_ONSCREEN = 467L; +void TViswin::check_menu_item(MENU_TAG item, bool on) +{ + win_menu_check(win(), item, on); + win_update_menu_bar(win()); +} + +void TViswin::enable_menu_item(MENU_TAG item, bool on) +{ + win_menu_enable(win(), item, on); + win_update_menu_bar(win()); +} + + void TViswin::exec_link() { if (_linkID != -1) @@ -117,8 +130,11 @@ void TViswin::display_link (long y, long x1, long x2, const char *d) #if XVT_OS == XVT_OS_WIN xvt_statbar_set(d); #endif - if (_link_button != -1) xvt_enable_control (_link_button, TRUE); - + if (_link_button != -1) + { + if (_showbuts) xvt_enable_control (_link_button, TRUE); + if (_toplevel) enable_menu_item(M_EDIT_CUT, TRUE); + } if (!_toplevel && !_inside_linkexec) { // chiama l'handler per maschere con FALSE come terzo parametro @@ -141,7 +157,11 @@ void TViswin::erase_link (long y, long x1, long x2) xvt_statbar_set (""); xvt_statbar_refresh (); #endif - if (_link_button != -1) xvt_enable_control (_link_button, FALSE); + if (_link_button != -1) + { + if (_showbuts) xvt_enable_control (_link_button, FALSE); + if (_toplevel) enable_menu_item(M_EDIT_CUT, FALSE); + } } } @@ -363,10 +383,8 @@ WINDOW TViswin::add_button (short id, const char *caption) } void TViswin::repos_buttons () -{ - - if (!_toplevel) return; - +{ + if (!_toplevel) return; for (int buttons = 0; _button[buttons] != NULL_WIN; buttons++) if (buttons == MAXBUT - 1) { @@ -405,10 +423,11 @@ void TViswin::repos_buttons () void TViswin::open () { set_scroll_max (MAXLEN, _txt.lines () <= _textrows ? _txt.lines () : _txt.lines () - _textrows); - repos_buttons (); - TScroll_window ::open (); + repos_buttons(); + TScroll_window::open(); + show_buttons(_showbuts); _need_update = TRUE; - force_update (); + force_update (); } // prints the window contents @@ -769,7 +788,8 @@ void TViswin::paint_point (bool erase) void TViswin::paint_header () { if (!_rulers) - return; + return; + set_mode (M_COPY); set_opaque_text (TRUE); set_color (FOREGROUND, BACKGROUND); @@ -796,7 +816,7 @@ void TViswin::paint_selection () for (long l = p1.y; l <= p2.y; l++) { int top, left, right; - top = (int) (l - origin().y + 1); + top = (int) (l - origin().y + Y_OFFSET); if (top > 0 && top <= _textrows) { left = p1.y == l ? (int)(p1.x-origin().x + (long)X_OFFSET) : X_OFFSET; @@ -851,7 +871,7 @@ void TViswin::update () erase_point (); autoscroll (FALSE); set_mode (M_COPY); - if (_toplevel) + if (_showbuts) { set_brush (BACKGROUND); bar ((X_OFFSET-1), rows()-BUTTONROW_SIZE, columns()+1, rows() + 1); @@ -875,13 +895,13 @@ void TViswin::update () // xvt_draw_rect(win(), r1, COLOR_WHITE, COLOR_GRAY, 2); // xvt_draw_rect(win(), r2, COLOR_WHITE, COLOR_GRAY, 2); } - if (_toplevel) + if (_showbuts) bar ((X_OFFSET -1), rows()-BUTTONROW_SIZE, columns() + 1, rows() + 1); - if (_toplevel && _isopen) + if (_showbuts && _isopen) paint_waitbar (FALSE); #if XVT_OS == XVT_OS_WIN -else if (_toplevel) +else if (_showbuts) cpb_win_picture_draw_at (win(), _modpic, 4, 4 + (int) (rows () - (long)BUTTONROW_SIZE) * CHARY); #endif @@ -945,6 +965,53 @@ void TViswin::handler (WINDOW win, EVENT * ep) _textrows = TEXTROWS; _textcolumns = TEXTCOLUMNS; autoscroll (TRUE); + break; + case E_COMMAND: + switch(ep->v.cmd.tag) + { + case M_EDIT_CLIPBOARD: // interrompi + dispatch_e_char(win, K_ESC); + break; + case M_EDIT_CUT: // collega + dispatch_e_char(win, CTRL_C); + break; + case M_EDIT_PASTE: // esporta + dispatch_e_char(win, CTRL_E); + break; + case M_EDIT_SEL_ALL: // stampa + dispatch_e_char(win, CTRL_S); + break; + case M_FONT: // mostra righelli + show_rulers(!_rulers); + check_menu_item(M_FONT, _rulers); + break; + case M_STYLE: // mostra bottoni + show_buttons(!_showbuts); + check_menu_item(M_STYLE, _showbuts); + break; + case M_EDIT_QUIT: // chiudi +#if XVT_OS == XVT_OS_WIN + xvt_statbar_set (""); + xvt_statbar_refresh (); +#endif + stop_run (K_ENTER); + break; + case M_EDIT_COPY: // copia + // ??? + break; + case M_EDIT_CLEAR: // annulla selezione + dispatch_e_char(win,K_ENTER); + break; + case M_EDIT_SEARCH: // cerca + find(); + break; + case M_EDIT_DELETE: // cerca il prossimo + find_next(); + break; + case M_EDIT_UNDO: // ridisegna + refresh(); + break; + } break; case E_CONTROL: if (ep->v.ctl.ci.type == WC_PUSHBUTTON) @@ -985,7 +1052,7 @@ void TViswin::handler (WINDOW win, EVENT * ep) } else if (ep->v.timer.id == _wtimer) { - if (_toplevel) paint_waitbar (); + if (_showbuts) paint_waitbar (); kill_timer (_wtimer); if (_isopen) _wtimer = set_timer (win, 150l); @@ -1873,11 +1940,15 @@ void TViswin::close_print () { _isopen = FALSE; kill_timer (_wtimer); - _need_update = TRUE; + _need_update = TRUE; + if (_toplevel) + { + win_set_menu_text(win(), M_EDIT_QUIT, "Chiudi\tESC"); + enable_menu_item(M_EDIT_CLIPBOARD, FALSE); + } force_update (); } - void TViswin::goto_end() { goto_pos(0l, _txt.lines () - _textrows); @@ -1912,9 +1983,9 @@ void TViswin::refresh() force_update(); } -long TViswin::search(const char* txt, int& pos, long from, bool down) +long TViswin::search(const char* txt, int& pos, long from, bool down, bool cs) { - return _txt.search(txt,pos,from,down); + return _txt.search(txt,pos,from,down, cs); } int TViswin::replace(long l, const char* txt, int pos, int len) @@ -1933,17 +2004,17 @@ void TViswin::find() TMask m("bagn005"); m.set(F_STRING, _txt_to_find); - m.set(F_DIRECT, _down_dir ? "U" : "D"); + m.set(F_DIRECT, _down_dir ? "D" : "U"); m.set(F_CASE, _case_sensitive ? "X" : ""); if (m.run() == K_ENTER) { _txt_to_find = m.get(F_STRING); - _down_dir = m.get_bool(F_DIRECT); - _case_sensitive = m.get_bool(F_CASE); + _down_dir = m.get(F_DIRECT) == "D"; + _case_sensitive = !(m.get_bool(F_CASE)); int x; - long l = search(_txt_to_find, x, _point.y, _down_dir); + long l = search(_txt_to_find, x, _point.y, _down_dir, _case_sensitive); if (l == -1l) { _last_found.y = -1l; @@ -1956,6 +2027,7 @@ void TViswin::find() _last_found.y = l; } } + if (_toplevel) enable_menu_item(M_EDIT_DELETE, TRUE); } void TViswin::find_next() @@ -1966,7 +2038,8 @@ void TViswin::find_next() beep(); else { - long l = search(_txt_to_find, x, _point.y+(_down_dir ? 1l : -1l), _down_dir); + long l = search(_txt_to_find, x, _point.y+(_down_dir ? 1l : -1l), + _down_dir, _case_sensitive); if (l == -1) beep(); else @@ -1974,6 +2047,29 @@ void TViswin::find_next() } } +void TViswin::show_rulers (bool on) +{ + _rulers = on; + autoscroll (FALSE); + _textrows = TEXTROWS; + _textcolumns = TEXTCOLUMNS; + autoscroll (TRUE); + refresh(); +} + +void TViswin::show_buttons(bool on) +{ + _showbuts = on; + autoscroll (FALSE); + _textrows = TEXTROWS; + _textcolumns = TEXTCOLUMNS; + autoscroll (TRUE); + + for (int i = 0; i < _buttons; i++) + if (_button[i] != NULL_WIN) + show_window(_button[i],on); + refresh(); +} TViswin::TViswin(const char *fname, const char *title, @@ -1982,7 +2078,7 @@ TViswin::TViswin(const char *fname, bool linkbutton, int x, int y, int height, int width, - bool rulers, + bool rulers, // overridden by config parms WINDOW parent, TBrowsefile_field* brwfld): _filename (fname), _txt (fname, BUFFERSIZE), _islink (linkbutton), _isedit (editbutton), @@ -1991,7 +2087,8 @@ TViswin::TViswin(const char *fname, _link_displayed (FALSE), _point_displayed (FALSE), _selecting (FALSE), _scrolling (FALSE), _selflag (FALSE), _need_update (TRUE), _need_scroll (none), _multiple (FALSE), _rulers(rulers), _txt_to_find(64), - _frozen (FALSE), _brwfld(brwfld), _link_button(-1), _down_dir(TRUE) + _frozen (FALSE), _brwfld(brwfld), _link_button(-1), + _down_dir(TRUE), _showbuts(FALSE) { if (title == NULL) title = (fname ? fname : "Anteprima di stampa"); @@ -2009,7 +2106,15 @@ TViswin::TViswin(const char *fname, parent = TASK_WIN; _toplevel = parent == TASK_WIN; - + + if (_toplevel) + { + // load info from config on buttons and rulers + TConfig cnf (CONFIG_GENERAL, "Visualizzazione"); + _showbuts = cnf.get("Bottoni",NULL,-1,"X") == "X"; + _rulers = cnf.get("Righelli",NULL,-1,"X") == "X"; + } + const int larg = 76; const int alt = 20; @@ -2037,10 +2142,20 @@ TViswin::TViswin(const char *fname, } WIN_TYPE rt = _toplevel ? W_DOC : W_PLAIN; - create (x, y, maxlarg, maxalt, title, flags, rt, parent); + create (x, y, maxlarg, maxalt, title, flags, rt, parent, + _toplevel ? VISWIN_BAR : 0); set_opaque_text (TRUE); set_font (FF_FIXED); + if (_toplevel) + { + enable_menu_item(M_FONT, TRUE); + enable_menu_item(M_STYLE, TRUE); + check_menu_item(M_FONT, _rulers); + check_menu_item(M_STYLE, _showbuts); + enable_menu_item(M_EDIT_SEL_ALL, FALSE); + } + if (_txt.lines() > 0l) set_scroll_max (MAXLEN - 1, _txt.lines () <= _textrows ? _txt.lines () : _txt.lines () - _textrows); @@ -2061,23 +2176,19 @@ TViswin::TViswin(const char *fname, { _link_button = add_button (DLG_LINK, DLG_LINK_TITLE); _buttons++; - xvt_enable_control (_link_button, FALSE); + xvt_enable_control(_link_button, FALSE); } if (_isprint) { add_button (DLG_PRINT, DLG_PRINT_TITLE); _buttons++; } - - //#if XVT_OS == XVT_OS_SCOUNIX - // maximize(); - // #endif } else _buttons = 0; _curbut = 0; - if (_isopen) + if (_isopen && _showbuts) _wtimer = set_timer(win(), 150l); _point.set (0, 0); diff --git a/include/viswin.h b/include/viswin.h index e63b56644..1df7e7c13 100755 --- a/include/viswin.h +++ b/include/viswin.h @@ -87,7 +87,8 @@ class TViswin : public TScroll_window bool _isbackground; bool _frozen; bool _toplevel; - bool _rulers; + bool _rulers; + bool _showbuts; bool _inside_linkexec; // viene istanziato soltanto se e' usata come controllo BROWSEFILE @@ -133,6 +134,9 @@ protected: virtual void update(); virtual void handler(WINDOW win, EVENT* ep); + void check_menu_item(MENU_TAG item, bool on = TRUE); + void enable_menu_item(MENU_TAG item, bool on = TRUE); + public: // gestione "collegamenti": vengono passati il testo completo, @@ -143,17 +147,21 @@ public: void close_print(); bool frozen() { return _frozen; } void abort_print(); - long lines() { return _txt.lines(); } + long lines() { return _txt.lines(); } void goto_end(); void goto_top(); void goto_pos(long r, long c, bool moveorigin = TRUE); void refresh(); + void show_rulers (bool on = TRUE); + void show_buttons(bool on = TRUE); + void add_line(const char* l); // non_interactive search and replace - long search (const char* txt, int& pos, long from = 0, bool down = TRUE); + long search (const char* txt, int& pos, long from = 0, + bool down = TRUE, bool casesens = FALSE); int replace(long line, const char* txt, int pos = 0, int len = -1); // interactive search diff --git a/include/window.cpp b/include/window.cpp index d1c7f307e..5f154b7bf 100755 --- a/include/window.cpp +++ b/include/window.cpp @@ -75,9 +75,6 @@ HIDDEN void xvt_menu_enable(MENU_ITEM* m, bool on) switch(m->tag) { case M_FILE: - case MENU_FILE: - case MENU_EDIT: - case MENU_ALT_EDIT: if (m->child) xvt_menu_enable(m->child, on); break; @@ -89,7 +86,6 @@ HIDDEN void xvt_menu_enable(MENU_ITEM* m, bool on) case M_FILE_PRINT: case M_FILE_PG_SETUP: case (M_FILE+11): - case M_EDIT_SEARCH: break; // Leave them as they are default: win_menu_enable(TASK_WIN, m->tag, on); @@ -199,7 +195,7 @@ WINDOW TWindow::create(short x, short y, short dx, short dy, const char* title, long flags, WIN_TYPE wt, WINDOW parent, int menu) { - flags |= WSF_NO_MENUBAR; + if (menu == 0) flags |= WSF_NO_MENUBAR; if (parent == NULL_WIN) parent = TASK_WIN; if (parent == TASK_WIN) flags |= WSF_INVISIBLE;