1 /*
2 Copyright (C) 2002 Kai Sterker <kai.sterker@gmail.com>
3 Part of the Adonthell Project <http://adonthell.nongnu.org>
4
5 Dlgedit is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 Dlgedit is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Dlgedit. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20 * @file gui_edit.cc
21 *
22 * @author Kai Sterker
23 * @brief Wrapper around the gtkeditor widget.
24 */
25
26 #include <pango/pango-font.h>
27 #include "gui_edit.h"
28
29 // ctor
GuiEdit(GtkWidget * container)30 GuiEdit::GuiEdit (GtkWidget *container)
31 {
32 // let the editor be scrollable
33 GtkWidget *scrolled = gtk_scrolled_window_new (0, 0);
34 gtk_container_add (GTK_CONTAINER (container), scrolled);
35 gtk_container_set_border_width (GTK_CONTAINER (scrolled), 4);
36 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
37 gtk_widget_show (scrolled);
38
39 // create the editor
40 entry = gtk_text_buffer_new (NULL);
41 view = gtk_text_view_new_with_buffer (entry);
42 gtk_container_add (GTK_CONTAINER (scrolled), view);
43 gtk_widget_set_can_default(view, TRUE);
44 gtk_text_view_set_editable (GTK_TEXT_VIEW(view), TRUE);
45 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
46 gtk_widget_show (view);
47
48 // use a fixed size font
49 PangoFontDescription *font_desc = pango_font_description_from_string ("Fixed Monospace 12");
50 gtk_widget_modify_font (view, font_desc);
51 pango_font_description_free (font_desc);
52 }
53
54 // dtor
~GuiEdit()55 GuiEdit::~GuiEdit ()
56 {
57 }
58
59 // set the entry's text
setText(const std::string & text)60 void GuiEdit::setText (const std::string &text)
61 {
62 gtk_text_buffer_set_text (entry, text.c_str (), -1);
63 }
64
65 // return the entry's text
getText()66 std::string GuiEdit::getText ()
67 {
68 GtkTextIter start, end;
69 gtk_text_buffer_get_bounds (entry, &start, &end);
70
71 gchar *tmp = gtk_text_buffer_get_text (entry, &start, &end, TRUE);
72 std::string text (tmp);
73 g_free (tmp);
74
75 return text;
76 }
77