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.
23 #include <gtkmm2ext/textviewer.h>
28 using namespace Gtkmm2ext
;
31 TextViewer::TextViewer (size_t xsize
, size_t ysize
) :
32 Gtk::Window (Gtk::WINDOW_TOPLEVEL
),
33 Transmitter (Transmitter::Info
), /* channel arg is irrelevant */
36 set_size_request (xsize
, ysize
);
38 set_title ("Text Viewer");
39 set_name ("TextViewer");
43 vbox1
.set_homogeneous (false);
44 vbox1
.set_spacing (0);
48 vbox2
.set_homogeneous (false);
49 vbox2
.set_spacing (10);
50 //vbox2.set_border_width (10);
52 vbox1
.pack_start (vbox2
, true, true, 0);
55 vbox2
.pack_start (scrollwin
, TRUE
, TRUE
, 0);
56 scrollwin
.set_policy (Gtk::POLICY_NEVER
, Gtk::POLICY_ALWAYS
);
59 etext
.set_editable (false);
60 etext
.set_wrap_mode (Gtk::WRAP_WORD
);
61 scrollwin
.add (etext
);
64 vbox1
.pack_start (dismiss
, false, false, 0);
67 dismiss
.signal_clicked().connect(mem_fun (*this, &TextViewer::signal_released_handler
));
71 TextViewer::signal_released_handler()
77 TextViewer::insert_file (const string
&path
)
81 ifstream
f (path
.c_str());
87 Glib::RefPtr
<Gtk::TextBuffer
> tb (etext
.get_buffer());
89 tb
->begin_user_action();
91 f
.read (buf
, sizeof (buf
));
94 buf
[f
.gcount()] = '\0';
96 tb
->insert (tb
->end(), foo
);
99 tb
->end_user_action();
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())));
113 TextViewer::deliver ()
117 Glib::RefPtr
<Gtk::TextBuffer
> tb (etext
.get_buffer());
120 read (buf
, sizeof (buf
));
121 buf
[gcount()] = '\0';
123 tb
->insert (tb
->end(), foo
);