summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext/textviewer.cc
blob: 22c26aa1b772f83bcb2107bfa319095f71eac385 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
    Copyright (C) 1999 Paul Barton-Davis
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    $Id$
*/

#include <string>
#include <gtkmm2ext/textviewer.h>

#include "pbd/i18n.h"

using namespace std;
using namespace Gtkmm2ext;
using namespace sigc;

TextViewer::TextViewer (size_t xsize, size_t ysize) :
	Gtk::Window (Gtk::WINDOW_TOPLEVEL),
	Transmitter (Transmitter::Info), /* channel arg is irrelevant */
	dismiss (_("Close"))
{
	set_size_request (xsize, ysize);

	set_title ("Text Viewer");
	set_name ("TextViewer");
	set_resizable (true);
	set_border_width (0);

	vbox1.set_homogeneous (false);
	vbox1.set_spacing (0);
	add (vbox1);
	vbox1.show ();

	vbox2.set_homogeneous (false);
	vbox2.set_spacing (10);
	//vbox2.set_border_width (10);

	vbox1.pack_start (vbox2, true, true, 0);
	vbox2.show ();

	vbox2.pack_start (scrollwin, TRUE, TRUE, 0);
	scrollwin.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
	scrollwin.show ();

	etext.set_editable (false);
	etext.set_wrap_mode (Gtk::WRAP_WORD);
	scrollwin.add (etext);
	etext.show ();

	vbox1.pack_start (dismiss, false, false, 0);
	dismiss.show ();

	dismiss.signal_clicked().connect(mem_fun (*this, &TextViewer::signal_released_handler));
}

void
TextViewer::signal_released_handler()
{
	hide();
}

void
TextViewer::scroll_to_bottom ()

{
        Gtk::Adjustment *adj;

 	adj = scrollwin.get_vadjustment();
 	adj->set_value (MAX(0,(adj->get_upper() - adj->get_page_size())));
}

void
TextViewer::deliver ()

{
	char buf[1024];
	Glib::RefPtr<Gtk::TextBuffer> tb (etext.get_buffer());

	while (!eof()) {
		read (buf, sizeof (buf));
		buf[gcount()] = '\0';
		string foo (buf);
		tb->insert (tb->end(), foo);
	}
	scroll_to_bottom ();
	clear ();
}