gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
TextView.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16 */
17 #ifndef TEXTVIEW_H_
18 #define TEXTVIEW_H_
19 
20 #include "Container.H"
21 #include <string>
22 #include <sstream>
23 
29 class TextView : public Container {
30 public:
33  TextView(void){
34  widget=gtk_text_view_new (); // create the entry box
35  }
36 
48  void setFont(PangoFontDescription *pangoFontDescription){
49  if (pangoFontDescription)
50  gtk_widget_modify_font(widget,pangoFontDescription);
51  }
52 
55  void connectBufferChangedSignal(GCallback callBack, void *data){
56  //g_signal_connect(widget, "insert-at-cursor", callBack, data);
57  GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(widget));
58  g_signal_connect(GTK_WIDGET(buffer), "changed", callBack, data);
59  }
60 
64  void setText(string &text){
65  setText(text.c_str());
66  }
67 
71  void setText(const char *text){
72  GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
73  gtk_text_buffer_set_text(buffer,text,-1);
74 // gtk_widget_queue_draw(widget);
75  }
76 
80  string getText(void){
81  string text;
82  GtkTextIter start, end;
83  bool includeInvisible=true;
84  char *text_;
85  GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
86  gtk_text_buffer_get_bounds (buffer, &start, &end);
87  text_ = gtk_text_buffer_get_text(buffer, &start, &end, includeInvisible);
88  text=text_;
89  g_free(text_);
90  return text;
91  }
92 
97  TextView &operator<<(string &text){
98  setText(text);
99  return *this;
100  }
101 
106  TextView &operator<<(const char *text){
107  setText(text);
108  return *this;
109  }
110 
115  TextView &operator>>(string &text){
116  text=getText();
117  return *this;
118  }
119 
124  TextView &operator>>(int &num){
125  string text=getText();
126  int isHex=(text.find("0x")==string::npos)?-1:text.find("0x")+2;
127 
128  if (isHex!=-1){
129  istringstream iss(text.substr(isHex,text.size()-isHex));
130  iss>>hex>>num;
131  } else {
132  istringstream iss(text);
133  iss>>num;
134  }
135 
136  return *this;
137  }
138 
143  TextView &operator>>(long &num){
144  string text=getText();
145  int isHex=(text.find("0x")==string::npos)?-1:text.find("0x")+2;
146 
147  if (isHex!=-1){
148  istringstream iss(text.substr(isHex,text.size()-isHex));
149  iss>>hex>>num;
150  } else {
151  istringstream iss(text);
152  iss>>num;
153  }
154 
155  return *this;
156  }
157 
163  template<typename TYPE>
164  TextView &operator>>(TYPE &var){
165  string text=getText();
166 
167  istringstream iss(text);
168  iss>>var;
169  return *this;
170  }
171 };
172 
173 #endif // TEXTVIEW_H_
TextView & operator>>(string &text)
Definition: TextView.H:115
TextView & operator>>(TYPE &var)
Definition: TextView.H:164
string getText(void)
Definition: TextView.H:80
void setFont(PangoFontDescription *pangoFontDescription)
Definition: TextView.H:48
GtkWidget * widget
The container based widget.
Definition: Widget.H:33
TextView & operator<<(string &text)
Definition: TextView.H:97
TextView & operator>>(int &num)
Definition: TextView.H:124
void setText(const char *text)
Definition: TextView.H:71
void setText(string &text)
Definition: TextView.H:64
void connectBufferChangedSignal(GCallback callBack, void *data)
Definition: TextView.H:55
TextView & operator>>(long &num)
Definition: TextView.H:143
TextView & operator<<(const char *text)
Definition: TextView.H:106
TextView(void)
Definition: TextView.H:33
gtkIOStream: /tmp/gtkiostream/include/TextView.H Source File
GTK+ IOStream  Beta