when tabbing between track/bus name fields, skip rec-enabled tracks to avoid an annoy...
[ardour2.git] / libs / gtkmm2ext / textviewer.cc
blob8c89b845b7c4aceb41c207ec461d127626368cbd
1 /*
2 Copyright (C) 1999 Paul Barton-Davis
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 $Id$
20 #include <string>
21 #include <fstream>
23 #include <gtkmm2ext/textviewer.h>
25 #include "i18n.h"
27 using namespace std;
28 using namespace Gtkmm2ext;
29 using namespace sigc;
31 TextViewer::TextViewer (size_t xsize, size_t ysize) :
32 Gtk::Window (Gtk::WINDOW_TOPLEVEL),
33 Transmitter (Transmitter::Info), /* channel arg is irrelevant */
34 dismiss (_("Close"))
36 set_size_request (xsize, ysize);
38 set_title ("Text Viewer");
39 set_name ("TextViewer");
40 set_resizable (true);
41 set_border_width (0);
43 vbox1.set_homogeneous (false);
44 vbox1.set_spacing (0);
45 add (vbox1);
46 vbox1.show ();
48 vbox2.set_homogeneous (false);
49 vbox2.set_spacing (10);
50 //vbox2.set_border_width (10);
52 vbox1.pack_start (vbox2, true, true, 0);
53 vbox2.show ();
55 vbox2.pack_start (scrollwin, TRUE, TRUE, 0);
56 scrollwin.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
57 scrollwin.show ();
59 etext.set_editable (false);
60 etext.set_wrap_mode (Gtk::WRAP_WORD);
61 scrollwin.add (etext);
62 etext.show ();
64 vbox1.pack_start (dismiss, false, false, 0);
65 dismiss.show ();
67 dismiss.signal_clicked().connect(mem_fun (*this, &TextViewer::signal_released_handler));
70 void
71 TextViewer::signal_released_handler()
73 hide();
76 void
77 TextViewer::insert_file (const string &path)
80 char buf[1024];
81 ifstream f (path.c_str());
83 if (!f) {
84 return;
87 Glib::RefPtr<Gtk::TextBuffer> tb (etext.get_buffer());
89 tb->begin_user_action();
90 while (f) {
91 f.read (buf, sizeof (buf));
93 if (f.gcount()) {
94 buf[f.gcount()] = '\0';
95 string foo (buf);
96 tb->insert (tb->end(), foo);
99 tb->end_user_action();
102 void
103 TextViewer::scroll_to_bottom ()
106 Gtk::Adjustment *adj;
108 adj = scrollwin.get_vadjustment();
109 adj->set_value (MAX(0,(adj->get_upper() - adj->get_page_size())));
112 void
113 TextViewer::deliver ()
116 char buf[1024];
117 Glib::RefPtr<Gtk::TextBuffer> tb (etext.get_buffer());
119 while (!eof()) {
120 read (buf, sizeof (buf));
121 buf[gcount()] = '\0';
122 string foo (buf);
123 tb->insert (tb->end(), foo);
125 scroll_to_bottom ();
126 clear ();