enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / gtkmm2ext / textviewer.cc
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.
7
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.
12
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.
16
17     $Id$
18 */
19
20 #include <string>
21 #include <gtkmm2ext/textviewer.h>
22
23 #include "pbd/i18n.h"
24
25 using namespace std;
26 using namespace Gtkmm2ext;
27 using namespace sigc;
28
29 TextViewer::TextViewer (size_t xsize, size_t ysize) :
30         Gtk::Window (Gtk::WINDOW_TOPLEVEL),
31         Transmitter (Transmitter::Info), /* channel arg is irrelevant */
32         dismiss (_("Close"))
33 {
34         set_size_request (xsize, ysize);
35
36         set_title ("Text Viewer");
37         set_name ("TextViewer");
38         set_resizable (true);
39         set_border_width (0);
40
41         vbox1.set_homogeneous (false);
42         vbox1.set_spacing (0);
43         add (vbox1);
44         vbox1.show ();
45
46         vbox2.set_homogeneous (false);
47         vbox2.set_spacing (10);
48         //vbox2.set_border_width (10);
49
50         vbox1.pack_start (vbox2, true, true, 0);
51         vbox2.show ();
52
53         vbox2.pack_start (scrollwin, TRUE, TRUE, 0);
54         scrollwin.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
55         scrollwin.show ();
56
57         etext.set_editable (false);
58         etext.set_wrap_mode (Gtk::WRAP_WORD);
59         scrollwin.add (etext);
60         etext.show ();
61
62         vbox1.pack_start (dismiss, false, false, 0);
63         dismiss.show ();
64
65         dismiss.signal_clicked().connect(mem_fun (*this, &TextViewer::signal_released_handler));
66 }
67
68 void
69 TextViewer::signal_released_handler()
70 {
71         hide();
72 }
73
74 void
75 TextViewer::scroll_to_bottom ()
76
77 {
78         Gtk::Adjustment *adj;
79
80         adj = scrollwin.get_vadjustment();
81         adj->set_value (MAX(0,(adj->get_upper() - adj->get_page_size())));
82 }
83
84 void
85 TextViewer::deliver ()
86
87 {
88         char buf[1024];
89         Glib::RefPtr<Gtk::TextBuffer> tb (etext.get_buffer());
90
91         while (!eof()) {
92                 read (buf, sizeof (buf));
93                 buf[gcount()] = '\0';
94                 string foo (buf);
95                 tb->insert (tb->end(), foo);
96         }
97         scroll_to_bottom ();
98         clear ();
99 }