1 /**********************************************************************
2 *
3 * FreeDoko a Doppelkopf-Game
4 *
5 * Copyright (C) 2001 – 2018 by Diether Knof and Borg Enders
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You can find this license in the file 'gpl.txt'.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 * Contact:
24 * Diether Knof dknof@posteo.de
25 *
26 *********************************************************************/
27
28 #include "constants.h"
29
30 #ifdef USE_UI_GTKMM
31
32 #include "first_run.h"
33
34 #include "ui.h"
35
36 #include <gtkmm/image.h>
37 #include <gtkmm/scrolledwindow.h>
38 #include <gtkmm/textview.h>
39 #include <gtkmm/texttag.h>
40
41 namespace UI_GTKMM_NS {
42
43 /** constructor
44 **
45 ** @param parent the parent object
46 ** @param message the message for the first run
47 **/
FirstRun(Base * const parent,string message)48 FirstRun::FirstRun(Base* const parent,
49 string message) :
50 Base(parent),
51 Dialog("FreeDoko – " + _("Window::first run")),
52 message_(std::move(message))
53 {
54 this->ui->add_window(*this);
55 this->signal_realize().connect(sigc::mem_fun(*this,
56 &FirstRun::init));
57 this->set_icon(this->ui->icon);
58
59 this->set_default_size(static_cast<int>(this->ui->logo->get_width() * 1.5),
60 static_cast<int>(this->ui->logo->get_height() * 2.5));
61 #ifdef POSTPONED
62 this->get_window()->set_decorations(Gdk::DECOR_BORDER
63 | Gdk::DECOR_RESIZEH
64 | Gdk::DECOR_TITLE
65 | Gdk::DECOR_MENU);
66 #endif
67
68 } // FirstRun::FirstRun(Base* parent, string message)
69
70 /** destructor
71 **/
72 FirstRun::~FirstRun() = default;
73
74 /** initializes the window
75 **/
76 void
init()77 FirstRun::init()
78 {
79 add_close_button(*this);
80
81 { // the image
82 auto image = Gtk::manage(new Gtk::Image(parent->ui->logo));
83 this->get_content_area()->pack_start(*image, Gtk::PACK_SHRINK);
84 } // the image
85 { // the text
86 auto text = Gtk::manage(new Gtk::TextView());
87 auto text_buffer = text->get_buffer();
88 {
89 auto tag_title = text_buffer->create_tag("title");
90 //tag_title->set_property("weight", Pango::WEIGHT_BOLD);
91 tag_title->set_property("scale", Pango::SCALE_X_LARGE);
92 tag_title->set_property("justification", Gtk::JUSTIFY_CENTER);
93
94 auto tag_endline = text_buffer->create_tag("endline");
95 tag_endline->set_property("style", Pango::STYLE_ITALIC);
96 tag_endline->set_property("justification", Gtk::JUSTIFY_CENTER);
97
98 }
99 Glib::ustring message_text = this->message_;
100 size_t pos = 0;
101 { // title
102 size_t const title_pos = message_text.find("\n\n") ;
103 if (title_pos == message_text.find("\n")) {
104 // found the title!
105
106 text_buffer->insert_with_tag(text_buffer->begin(),
107 "\n" +
108 Glib::ustring(message_text,
109 0, title_pos + 2),
110 "title");
111 pos = title_pos + 2;
112 } // if (title found)
113 } // title
114 { // end line
115 auto const end_pos = message_text.rfind("\n\n") ;
116 if (end_pos == message_text.rfind("\n") - 1) {
117 // found the end line!
118
119 text_buffer->insert(text_buffer->end(),
120 Glib::ustring(message_text,
121 pos,
122 end_pos - pos + 1));
123 text_buffer->insert_with_tag(text_buffer->end(),
124 Glib::ustring(message_text,
125 end_pos + 1),
126 "endline");
127 } else { // if !(end line found)
128 text_buffer->insert(text_buffer->end(),
129 Glib::ustring(message_text, pos));
130 } // if !(end line found)
131 } // end line
132
133
134 auto text_window = Gtk::manage(new Gtk::ScrolledWindow());
135 text_window->add(*text);
136 text_window->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
137 text->set_editable(false);
138 text->set_wrap_mode(Gtk::WRAP_WORD);
139 text->set_cursor_visible(false);
140
141 this->get_content_area()->pack_start(*text_window);
142 } // the text
143
144 this->show_all_children();
145 } // FirstRun::FirstRun(Base* parent, string message)
146
147
148 } // namespace UI_GTKMM_NS
149
150 #endif // #ifdef USE_UI_GTKMM
151