Debian Codegraph @

demos/gtk-demo/example_textview.cc

raw
1 /* Text Widget
2 *
3 * The Gtk::TextView widget displays a Gtk::TextBuffer. One Gtk::TextBuffer
4 * can be displayed by multiple Gtk::TextViews. This demo has two views
5 * displaying a single buffer, and shows off the widget's text
6 * formatting features.
7 *
8 */
9
10 #include <gtkmm.h>
11 #include <gtk/gtk.h>
12 #include <iostream> //For std::cout.
13
14 using std::exit;
15
16 class Window_EasterEgg : public Gtk::Window
17 {
18 public:
19 Window_EasterEgg();
20 ~Window_EasterEgg() override;
21
22 protected:
23 virtual void recursive_attach_view(int depth, Gtk::TextView& view, Glib::RefPtr<Gtk::TextChildAnchor> refAnchor);
24
25 //Member widgets:
26 Gtk::TextView* m_pTextView;
27 Gtk::ScrolledWindow m_ScrolledWindow;
28 };
29
30 class Example_TextView : public Gtk::Window
31 {
32 public:
33 Example_TextView();
34 ~Example_TextView() override;
35
36 protected:
37 virtual void create_tags(Glib::RefPtr<Gtk::TextBuffer>& refBuffer);
38 virtual void insert_text(Glib::RefPtr<Gtk::TextBuffer>& refBuffer);
39 virtual void attach_widgets(Gtk::TextView& text_view);
40 virtual bool find_anchor(Gtk::TextBuffer::iterator& iter);
41
42 //Signal handlers:
43 virtual void on_button_clicked();
44
45
46 //Member widgets
47 Gtk::Paned m_VPaned;
48 Gtk::TextView m_View1;
49 Gtk::TextView* m_pView2;
50 Gtk::ScrolledWindow m_ScrolledWindow1, m_ScrolledWindow2;
51
52 Window_EasterEgg m_WindowEasterEgg;
53 };
54
55
56
57
58 //Called by DemoWindow;
59 Gtk::Window* do_textview()
60 {
61 return new Example_TextView();
62 }
63
64 Example_TextView::Example_TextView()
65 : m_VPaned(Gtk::ORIENTATION_VERTICAL)
66 {
67 set_default_size(450, 450);
68 set_title("Text View");
69 set_border_width(0);
70
71 m_VPaned.set_border_width(5);
72 add(m_VPaned);
73
74 /* For convenience, we just use the autocreated buffer from
75 * the first text view; you could also create the buffer
76 * by itself with refBuffer->new(), then later create
77 * a view widget.
78 */
79 Glib::RefPtr<Gtk::TextBuffer> refBuffer = m_View1.get_buffer();
80 m_pView2 = Gtk::make_managed<Gtk::TextView>(refBuffer);
81
82 m_ScrolledWindow1.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
83 m_VPaned.add1(m_ScrolledWindow1);
84 m_ScrolledWindow1.add(m_View1);
85
86 m_ScrolledWindow2.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
87 m_VPaned.add2(m_ScrolledWindow2);
88 m_ScrolledWindow2.add(*m_pView2);
89
90 create_tags(refBuffer);
91 insert_text(refBuffer);
92
93 attach_widgets(m_View1);
94 attach_widgets(*m_pView2);
95
96 show_all();
97 }
98
99 Example_TextView::~Example_TextView()
100 {
101 }
102
103 void Example_TextView::create_tags(Glib::RefPtr<Gtk::TextBuffer>& refBuffer)
104 {
105 /* Create a bunch of tags. Note that it's also possible to
106 * create tags with Gtk::TextTag::create() then add them to the
107 * tag table for the buffer, refBuffer->create_tag() is
108 * just a convenience function. Also note that you don't have
109 * to give tags a name.
110 *
111 * In any real app, another useful optimization would be to create
112 * a Gtk::TextTagTable in advance, and reuse the same tag table for
113 * all the buffers with the same tag set, instead of creating
114 * new copies of the same tags for every buffer.
115 *
116 * Tags are assigned default priorities in order of addition to the
117 * tag table. That is, tags created later that affect the same text
118 * property affected by an earlier tag will override the earlier
119 * tag. You can modify tag priorities with
120 * Gtk::TextTag::set_priority().
121 */
122
123 Glib::RefPtr<Gtk::TextBuffer::Tag> refTag;
124
125 refTag = refBuffer->create_tag("heading");
126 refTag->property_weight() = Pango::WEIGHT_BOLD;
127 refTag->property_size() = 15 * Pango::SCALE;
128
129 refBuffer->create_tag("italic")->property_style() = Pango::STYLE_ITALIC;
130 refBuffer->create_tag("bold")->property_weight() = Pango::WEIGHT_BOLD;
131 refBuffer->create_tag("big")->property_size() = 20 * Pango::SCALE;
132 refBuffer->create_tag("xx-small")->property_scale() = Pango::SCALE_XX_SMALL;
133 refBuffer->create_tag("x-large")->property_scale() = Pango::SCALE_X_LARGE;
134 refBuffer->create_tag("monospace")->property_family() = "monospace";
135 refBuffer->create_tag("blue_foreground")->property_foreground() = "blue";
136 refBuffer->create_tag("red_background")->property_background() = "red";
137
138 refBuffer->create_tag("big_gap_before_line")->property_pixels_above_lines() = 30;
139 refBuffer->create_tag("big_gap_after_line")->property_pixels_below_lines() = 30;
140 refBuffer->create_tag("double_spaced_line")->property_pixels_inside_wrap() = 10;
141 refBuffer->create_tag("not_editable")->property_editable() = FALSE;
142 refBuffer->create_tag("word_wrap")->property_wrap_mode() = Gtk::WRAP_WORD;
143 refBuffer->create_tag("char_wrap")->property_wrap_mode() = Gtk::WRAP_CHAR;
144 refBuffer->create_tag("no_wrap")->property_wrap_mode() = Gtk::WRAP_NONE;
145 refBuffer->create_tag("center")->property_justification() = Gtk::JUSTIFY_CENTER;
146 refBuffer->create_tag("right_justify")->property_justification() = Gtk::JUSTIFY_RIGHT;
147
148 refTag = refBuffer->create_tag("wide_margins");
149 refTag->property_left_margin() = 50;
150 refTag->property_right_margin() = 50;
151
152 refBuffer->create_tag("strikethrough")->property_strikethrough() = true;
153 refBuffer->create_tag("underline")->property_underline() = Pango::UNDERLINE_SINGLE;
154 refBuffer->create_tag("double_underline")->property_underline() = Pango::UNDERLINE_DOUBLE;
155
156 refTag = refBuffer->create_tag("superscript");
157 refTag->property_rise() = 10 * Pango::SCALE; /* 10 pixels */
158 refTag->property_size() = 8 * Pango::SCALE; /* 8 points */
159
160 refTag = refBuffer->create_tag("subscript");
161 refTag->property_rise() = -10 * Pango::SCALE; /* 10 pixels */
162 refTag->property_size() = 8 * Pango::SCALE; /* 8 points */
163
164 refTag = refBuffer->create_tag("rtl_quote");
165 refTag->property_wrap_mode() = Gtk::WRAP_WORD;
166 refTag->property_direction() = Gtk::TEXT_DIR_RTL;
167 refTag->property_indent() = 30;
168 refTag->property_left_margin() = 20;
169 refTag->property_right_margin() = 20;
170 }
171
172 void Example_TextView::insert_text(Glib::RefPtr<Gtk::TextBuffer>& refBuffer)
173 {
174 Glib::RefPtr<Gdk::Pixbuf> refPixbuf;
175 try
176 {
177 refPixbuf = Gdk::Pixbuf::create_from_resource("/textview/gtk-logo-rgb.gif");
178 Glib::RefPtr<Gdk::Pixbuf> refScaled = refPixbuf->scale_simple(32, 32, Gdk::INTERP_BILINEAR);
179 refPixbuf = refScaled;
180 }
181 catch (const Glib::Error& error)
182 {
183 std::cout << "Failed to load image gtk-logo-rgb.gif: " << error.what() << std::endl;
184 }
185
186 /* get start of buffer; each insertion will revalidate the
187 * iterator to point to just after the inserted text.
188 */
189
190 Gtk::TextBuffer::iterator iter = refBuffer->get_iter_at_offset(0);
191
192 iter = refBuffer->insert(iter, "The text widget can display text with all kinds of nifty attributes. It also supports multiple views of the same buffer; this demo is showing the same buffer in two places.\n\n");
193 iter = refBuffer->insert_with_tag(iter, "Font styles. ", "heading");
194 iter = refBuffer->insert(iter, "For example, you can have ");
195 iter = refBuffer->insert_with_tag(iter, "italic", "italic");
196
197 iter = refBuffer->insert(iter, ", ");
198 iter = refBuffer->insert_with_tag(iter, "bold", "bold");
199 iter = refBuffer->insert(iter, ", or ");
200 iter = refBuffer->insert_with_tag(iter, "monospace (typewriter)", "monospace");
201 iter = refBuffer->insert(iter, ", or ");
202 iter = refBuffer->insert_with_tag(iter, "big", "big");
203 iter = refBuffer->insert(iter, " text. ");
204 iter = refBuffer->insert(iter, "It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as ");
205 iter = refBuffer->insert_with_tag(iter, "xx-small", "xx-small");
206 iter = refBuffer->insert(iter, " or ");
207 iter = refBuffer->insert_with_tag(iter, "x-large", "x-large");
208 iter = refBuffer->insert(iter, " to ensure that your program properly adapts if the user changes the default font size.\n\n");
209
210 iter = refBuffer->insert_with_tag(iter, "Colors. ", "heading");
211
212 iter = refBuffer->insert(iter, "Colors such as ");
213 iter = refBuffer->insert_with_tag(iter, "a blue foreground", "blue_foreground");
214 iter = refBuffer->insert(iter, " or ");
215 iter = refBuffer->insert_with_tag(iter, "a red background", "red_background");
216 iter = refBuffer->insert(iter, " or even ");
217
218 {
219 std::vector<Glib::ustring> tag_names;
220
221 tag_names.push_back("blue_foreground");
222 tag_names.push_back("red_background");
223 iter = refBuffer->insert_with_tags_by_name(iter, "a blue foreground on red background", tag_names);
224 }
225
226 iter = refBuffer->insert(iter, " (select that to read it) can be used.\n\n");
227
228 iter = refBuffer->insert_with_tag(iter, "Underline, strikethrough, and rise. ", "heading");
229
230 iter = refBuffer->insert_with_tag(iter, "Strikethrough", "strikethrough");
231 iter = refBuffer->insert(iter, ", ");
232 iter = refBuffer->insert_with_tag(iter, "underline", "underline");
233 iter = refBuffer->insert(iter, ", ");
234 iter = refBuffer->insert_with_tag(iter, "double underline", "double_underline");
235 iter = refBuffer->insert(iter, ", ");
236 iter = refBuffer->insert_with_tag(iter, "superscript", "superscript");
237 iter = refBuffer->insert(iter, ", and ");
238 iter = refBuffer->insert_with_tag(iter, "subscript", "subscript");
239 iter = refBuffer->insert(iter, " are all supported.\n\n");
240
241 iter = refBuffer->insert_with_tag(iter, "Images. ", "heading");
242
243 iter = refBuffer->insert(iter, "The buffer can have images in it: ");
244 if (refPixbuf)
245 {
246 iter = refBuffer->insert_pixbuf(iter, refPixbuf);
247 iter = refBuffer->insert_pixbuf(iter, refPixbuf);
248 iter = refBuffer->insert_pixbuf(iter, refPixbuf);
249 }
250 iter = refBuffer->insert(iter, " for example.\n\n");
251
252 iter = refBuffer->insert_with_tag(iter, "Spacing. ", "heading");
253
254 iter = refBuffer->insert(iter, "You can adjust the amount of space before each line.\n");
255
256 {
257 std::vector<Glib::ustring> tag_names;
258
259 tag_names.push_back("big_gap_before_line");
260 tag_names.push_back("wide_margins");
261 iter = refBuffer->insert_with_tags_by_name(iter,
262 "This line has a whole lot of space before it.\n", tag_names);
263 iter = refBuffer->insert_with_tags_by_name(iter,
264 "You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n", tag_names);
265 }
266
267 {
268 std::vector<Glib::ustring> tag_names;
269
270 tag_names.push_back("double_spaced_line");
271 tag_names.push_back("wide_margins");
272 iter = refBuffer->insert_with_tags_by_name(iter,
273 "You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n",
274 tag_names);
275 }
276
277 iter = refBuffer->insert(iter, "Also note that those lines have extra-wide margins.\n\n");
278
279 iter = refBuffer->insert_with_tag(iter, "Editability. ", "heading");
280
281 iter = refBuffer->insert_with_tag(iter,
282 "This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n",
283 "not_editable");
284
285 iter = refBuffer->insert_with_tag(iter, "Wrapping. ", "heading");
286
287 iter = refBuffer->insert(iter,
288 "This line (and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n");
289
290 iter = refBuffer->insert_with_tag(iter,
291 "This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n",
292 "char_wrap");
293
294 iter = refBuffer->insert_with_tag(iter,
295 "This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n",
296 "no_wrap");
297
298 iter = refBuffer->insert_with_tag(iter, "Justification. ", "heading");
299
300 iter = refBuffer->insert_with_tag(iter, "\nThis line has center justification.\n", "center");
301
302 iter = refBuffer->insert_with_tag(iter, "This line has right justification.\n", "right_justify");
303
304 iter = refBuffer->insert_with_tag(iter,
305 "\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n",
306 "wide_margins");
307
308 iter = refBuffer->insert_with_tag(iter, "Internationalization. ", "heading");
309
310 iter = refBuffer->insert(iter,
311 "You can put all sorts of Unicode text in the buffer.\n\nGerman (Deutsch S\xC3\xBC""d) "
312 "Gr\xC3\xBC\xC3\x9F Gott\nGreek (\xCE\x95\xCE\xBB\xCE\xBB\xCE\xB7\xCE\xBD\xCE\xB9\xCE\xBA"
313 "\xCE\xAC) \xCE\x93\xCE\xB5\xCE\xB9\xCE\xAC \xCF\x83\xCE\xB1\xCF\x82\nHebrew\t\xD7\xA9\xD7"
314 "\x9C\xD7\x95\xD7\x9D\nJapanese (\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E)\n\nThe widget "
315 "properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, "
316 "grapheme boundaries, and so on using the Pango internationalization framework.\n");
317
318 iter = refBuffer->insert(iter, "Here's a word-wrapped quote in a right-to-left language:\n");
319 iter = refBuffer->insert_with_tag(iter,
320 "\xD9\x88\xD9\x82\xD8\xAF \xD8\xA8\xD8\xAF\xD8\xA3 \xD8\xAB\xD9\x84\xD8\xA7\xD8\xAB "
321 "\xD9\x85\xD9\x86 \xD8\xA3\xD9\x83\xD8\xAB\xD8\xB1 \xD8\xA7\xD9\x84\xD9\x85\xD8\xA4"
322 "\xD8\xB3\xD8\xB3\xD8\xA7\xD8\xAA \xD8\xAA\xD9\x82\xD8\xAF\xD9\x85\xD8\xA7 \xD9\x81\xD9\x8A "
323 "\xD8\xB4\xD8\xA8\xD9\x83\xD8\xA9 \xD8\xA7\xD9\x83\xD8\xB3\xD9\x8A\xD9\x88\xD9\x86 \xD8\xA8"
324 "\xD8\xB1\xD8\xA7\xD9\x85\xD8\xAC\xD9\x87\xD8\xA7 \xD9\x83\xD9\x85\xD9\x86\xD8\xB8\xD9\x85"
325 "\xD8\xA7\xD8\xAA \xD9\x84\xD8\xA7 \xD8\xAA\xD8\xB3\xD8\xB9\xD9\x89 \xD9\x84\xD9\x84\xD8\xB1"
326 "\xD8\xA8\xD8\xAD\xD8\x8C \xD8\xAB\xD9\x85 \xD8\xAA\xD8\xAD\xD9\x88\xD9\x84\xD8\xAA \xD9\x81"
327 "\xD9\x8A \xD8\xA7\xD9\x84\xD8\xB3\xD9\x86\xD9\x88\xD8\xA7\xD8\xAA \xD8\xA7\xD9\x84\xD8\xAE"
328 "\xD9\x85\xD8\xB3 \xD8\xA7\xD9\x84\xD9\x85\xD8\xA7\xD8\xB6\xD9\x8A\xD8\xA9 \xD8\xA5\xD9\x84"
329 "\xD9\x89 \xD9\x85\xD8\xA4\xD8\xB3\xD8\xB3\xD8\xA7\xD8\xAA \xD9\x85\xD8\xA7\xD9\x84\xD9\x8A"
330 "\xD8\xA9 \xD9\x85\xD9\x86\xD8\xB8\xD9\x85\xD8\xA9\xD8\x8C \xD9\x88\xD8\xA8\xD8\xA7\xD8\xAA"
331 "\xD8\xAA \xD8\xAC\xD8\xB2\xD8\xA1\xD8\xA7 \xD9\x85\xD9\x86 \xD8\xA7\xD9\x84\xD9\x86\xD8\xB8"
332 "\xD8\xA7\xD9\x85 \xD8\xA7\xD9\x84\xD9\x85\xD8\xA7\xD9\x84\xD9\x8A \xD9\x81\xD9\x8A \xD8\xA8"
333 "\xD9\x84\xD8\xAF\xD8\xA7\xD9\x86\xD9\x87\xD8\xA7\xD8\x8C \xD9\x88\xD9\x84\xD9\x83\xD9\x86"
334 "\xD9\x87\xD8\xA7 \xD8\xAA\xD8\xAA\xD8\xAE\xD8\xB5\xD8\xB5 \xD9\x81\xD9\x8A \xD8\xAE\xD8\xAF"
335 "\xD9\x85\xD8\xA9 \xD9\x82\xD8\xB7\xD8\xA7\xD8\xB9 \xD8\xA7\xD9\x84\xD9\x85\xD8\xB4\xD8\xB1"
336 "\xD9\x88\xD8\xB9\xD8\xA7\xD8\xAA \xD8\xA7\xD9\x84\xD8\xB5\xD8\xBA\xD9\x8A\xD8\xB1\xD8\xA9. "
337 "\xD9\x88\xD8\xA3\xD8\xAD\xD8\xAF \xD8\xA3\xD9\x83\xD8\xAB\xD8\xB1 \xD9\x87\xD8\xB0\xD9\x87 "
338 "\xD8\xA7\xD9\x84\xD9\x85\xD8\xA4\xD8\xB3\xD8\xB3\xD8\xA7\xD8\xAA \xD9\x86\xD8\xAC\xD8\xA7"
339 "\xD8\xAD\xD8\xA7 \xD9\x87\xD9\x88 \xC2\xBB\xD8\xA8\xD8\xA7\xD9\x86\xD9\x83\xD9\x88\xD8\xB3"
340 "\xD9\x88\xD9\x84\xC2\xAB \xD9\x81\xD9\x8A \xD8\xA8\xD9\x88\xD9\x84\xD9\x8A\xD9\x81\xD9\x8A"
341 "\xD8\xA7.\n\n",
342 "rtl_quote");
343
344 iter = refBuffer->insert(iter, "You can put widgets in the buffer: Here's a button: ");
345
346 Glib::RefPtr<Gtk::TextChildAnchor> refAnchor = refBuffer->create_child_anchor(iter);
347 iter = refBuffer->insert(refBuffer->end(), " and a menu: ");
348 refAnchor = refBuffer->create_child_anchor(iter); //TODO: Maybe this should be a method of the Iterator.
349 iter = refBuffer->insert(refBuffer->end(), " and a scale: ");
350 refAnchor = refBuffer->create_child_anchor(iter);
351 iter = refBuffer->insert(refBuffer->end(), " and an animation: ");
352 refAnchor = refBuffer->create_child_anchor(iter);
353 iter = refBuffer->insert(refBuffer->end(), " finally a text entry: ");
354 refAnchor = refBuffer->create_child_anchor(iter);
355 iter = refBuffer->insert(refBuffer->end(), ".\n");
356
357 refBuffer->insert(iter, "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text (doesn't work in GTK 2, but planned), tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such...");
358
359 // Apply word_wrap tag to whole buffer
360 Gtk::TextBuffer::iterator start, end;
361 refBuffer->get_bounds(start, end);
362 refBuffer->apply_tag_by_name("word_wrap", start, end);
363 }
364
365 bool Example_TextView::find_anchor(Gtk::TextBuffer::iterator& iter)
366 {
367 while(++iter)
368 {
369 if(iter.get_child_anchor())
370 return true;
371 }
372 return false;
373 }
374
375 void Example_TextView::attach_widgets(Gtk::TextView& text_view)
376 {
377 Glib::RefPtr<Gtk::TextBuffer> refBuffer = text_view.get_buffer();
378 Gtk::TextBuffer::iterator iter = refBuffer->begin();
379
380 int i = 0;
381 while(find_anchor(iter)) //previously created with create_child_anchor().
382 {
383 Glib::RefPtr<Gtk::TextChildAnchor> refAnchor = iter.get_child_anchor();
384 Gtk::Widget* pWidget = nullptr;
385 if (i == 0)
386 {
387 Gtk::Button* pButton = Gtk::make_managed<Gtk::Button>("Click Me");
388 pButton->signal_clicked().connect(sigc::mem_fun(*this, &Example_TextView::on_button_clicked));
389 pWidget = pButton;
390 }
391 else if (i == 1)
392 {
393 Gtk::ComboBoxText* pCombo = Gtk::make_managed<Gtk::ComboBoxText>();
394 pCombo->append("Option 1");
395 pCombo->append("Option 2");
396 pCombo->append("Option 3");
397
398 pWidget = pCombo;
399 }
400 else if (i == 2)
401 {
402 Gtk::Scale* pHScale = Gtk::make_managed<Gtk::Scale>(Gtk::ORIENTATION_HORIZONTAL);
403 pHScale->set_range(0, 100);
404 pHScale->set_size_request(70, -1);
405
406 pWidget = pHScale;
407 }
408 else if (i == 3)
409 {
410 Gtk::Image* pImage = Gtk::make_managed<Gtk::Image>();
411 pImage->set_from_resource("/textview/floppybuddy.gif");
412 pWidget = pImage;
413 }
414 else if (i == 4)
415 {
416 pWidget = Gtk::make_managed<Gtk::Entry>();
417 }
418 else
419 {
420 pWidget = nullptr;
421 g_assert_not_reached ();
422 }
423
424 if(pWidget)
425 {
426 text_view.add_child_at_anchor(*pWidget, refAnchor);
427 pWidget->show_all();
428 }
429
430 ++i;
431 }
432 }
433
434 void Example_TextView::on_button_clicked()
435 {
436 m_WindowEasterEgg.show_all();
437 }
438
439 Window_EasterEgg::Window_EasterEgg()
440 {
441 set_default_size(300, 400);
442
443 Glib::RefPtr<Gtk::TextBuffer> refBuffer = Gtk::TextBuffer::create();
444 Gtk::TextBuffer::iterator iter = refBuffer->end();
445
446 iter = refBuffer->insert(iter, "This buffer is shared by a set of nested text views.\n Nested view:\n");
447 Glib::RefPtr<Gtk::TextChildAnchor> refAnchor = refBuffer->create_child_anchor(iter);
448 refBuffer->insert(refBuffer->end(), "\nDon't do this in real applications, please.\n");
449
450 m_pTextView = Gtk::make_managed<Gtk::TextView>(refBuffer);
451
452 recursive_attach_view(0, *m_pTextView, refAnchor);
453
454 m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
455 add(m_ScrolledWindow);
456 m_ScrolledWindow.add(*m_pTextView);
457 }
458
459 Window_EasterEgg::~Window_EasterEgg()
460 {
461 }
462
463 void Window_EasterEgg::recursive_attach_view(int depth, Gtk::TextView& view, Glib::RefPtr<Gtk::TextChildAnchor> refAnchor)
464 {
465 if (depth > 4)
466 return;
467
468 Gtk::TextView* pChildView = Gtk::make_managed<Gtk::TextView>(view.get_buffer());
469
470 /* Frame is to add a black border around each child view */
471 Gtk::Frame* pFrame = Gtk::make_managed<Gtk::Frame>();
472
473 pFrame->add(*pChildView);
474
475 view.add_child_at_anchor(*pFrame, refAnchor);
476 recursive_attach_view (depth + 1, *pChildView, refAnchor);
477 }