]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GAboutlyx.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / gtk / GAboutlyx.C
1 /**
2  * \file GAboutlyx.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Huang Ying
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "ControlAboutlyx.h"
22 #include "GAboutlyx.h"
23 #include "ghelpers.h"
24 #include "version.h"
25
26 #include "support/filetools.h" // LibFileSearch
27
28 #include <libglademm.h>
29
30 #include <sstream>
31
32 using lyx::support::libFileSearch;
33
34 using std::ostringstream;
35 using std::string;
36
37 namespace lyx {
38 namespace frontend {
39
40 namespace {
41
42 enum TranslateState {NORMAL, BEGIN, IN_AT, IN_BOLD, IN_ITALIC};
43
44
45 Glib::ustring translateMarkup(Glib::ustring const & lyxMarkup)
46 {
47         Glib::ustring::const_iterator it = lyxMarkup.begin();
48         Glib::ustring pangoMarkup;
49         TranslateState state = BEGIN;
50         for (; it != lyxMarkup.end(); it++) {
51                 switch (state) {
52                 case BEGIN:
53                         switch (*it) {
54                         case '@':
55                                 state = IN_AT;
56                                 break;
57                         case '\n':
58                                 state = BEGIN;
59                                 pangoMarkup.push_back('\n');
60                                 break;
61                         default:
62                                 state = NORMAL;
63                                 pangoMarkup.push_back(*it);
64                                 break;
65                         }
66                         break;
67                 case IN_AT:
68                         switch (*it) {
69                         case 'b':
70                                 state = IN_BOLD;
71                                 pangoMarkup += "<b>";
72                                 break;
73                         case 'i':
74                                 state = IN_ITALIC;
75                                 pangoMarkup += "<i>";
76                                 break;
77                         case '\n':
78                                 state = BEGIN;
79                                 pangoMarkup.push_back('@');
80                                 pangoMarkup.push_back('\n');
81                                 break;
82                         default:
83                                 state = NORMAL;
84                                 pangoMarkup.push_back('@');
85                                 pangoMarkup.push_back(*it);
86                         }
87                         break;
88                 case IN_BOLD:
89                         switch (*it) {
90                         case '\n':
91                                 state = BEGIN;
92                                 pangoMarkup += "</b>\n";
93                                 break;
94                         default:
95                                 pangoMarkup.push_back(*it);
96                         }
97                         break;
98                 case IN_ITALIC:
99                         switch (*it) {
100                         case '\n':
101                                 state = BEGIN;
102                                 pangoMarkup += "</i>\n";
103                                 break;
104                         default:
105                                 pangoMarkup.push_back(*it);
106                         }
107                         break;
108                 case NORMAL:
109                         switch (*it) {
110                         case '\n':
111                                 state = BEGIN;
112                                 pangoMarkup.push_back('\n');
113                                 break;
114                         default:
115                                 pangoMarkup.push_back(*it);
116                         }
117                 }
118                 switch (*it) {
119                 case '&':
120                         pangoMarkup += "amp;";
121                         break;
122                 case '<':
123                         pangoMarkup.erase(--(pangoMarkup.end()));
124                         pangoMarkup += "&lt;";
125                         break;
126                 case '>':
127                         pangoMarkup.erase(--(pangoMarkup.end()));
128                         pangoMarkup += "&gt;";
129                         break;
130                 default:
131                         break;
132                 }
133         }
134         switch (state) {
135         case IN_AT:
136                 pangoMarkup.push_back('@');
137                 break;
138         case IN_ITALIC:
139                 pangoMarkup += "</i>";
140                 break;
141         case IN_BOLD:
142                 pangoMarkup += "</b>";
143                 break;
144         default:
145                 break;
146         }
147         return pangoMarkup;
148 }
149
150
151 }
152
153
154 GAboutlyx::GAboutlyx(Dialog & parent)
155         : GViewCB<ControlAboutlyx, GViewGladeB>(parent, "About LyX")
156 {
157 }
158
159
160 void GAboutlyx::doBuild()
161 {
162         string const gladeName = findGladeFile("aboutlyx");
163         xml_ = Gnome::Glade::Xml::create(gladeName);
164
165         Gtk::AboutDialog *dialog;
166         xml_->get_widget("dialog", dialog);
167
168         dialog->set_version(Glib::ustring(PACKAGE_VERSION));
169
170         std::ostringstream ls;
171         ls << controller().getCopyright() << "\n\n"
172            << controller().getLicense() << "\n\n"
173            << controller().getDisclaimer();
174         dialog->set_license (ls.str());
175
176         string const filename = libFileSearch("images", "banner", "ppm");
177         Glib::RefPtr<Gdk::Pixbuf> logo = Gdk::Pixbuf::create_from_file(filename);
178         Glib::RefPtr<Gdk::Pixbuf> logo_scaled = logo->scale_simple(
179                 logo->get_width() / 2,
180                 logo->get_height() / 2,
181                 Gdk::INTERP_BILINEAR);
182         dialog->set_logo(logo_scaled);
183
184         // Total crack - find and hide the built in Credits button
185         // that glade helpfully puts there for us.
186         Glib::List_Iterator<Gtk::Box_Helpers::Child> it =
187                 dialog->get_action_area()->children().begin();
188         Glib::List_Iterator<Gtk::Box_Helpers::Child> const end =
189                 dialog->get_action_area()->children().end();
190         for (; it != end; ++it) {
191                 Gtk::Button * button = (Gtk::Button*)(it->get_widget());
192                 // The close button is a stock ID which we can reliably test for
193                 // The license button has no icon
194                 // What's left is the credits button
195                 if (button->get_label() != "gtk-close" && button->get_image())
196                         button->hide();
197         }
198
199         // FIXME UNICODE
200         Gtk::Button &authorbutton = *Gtk::manage(
201                 new Gtk::Button(lyx::to_utf8(_("C_redits")), true));
202         authorbutton.set_image(*Gtk::manage(
203                 new Gtk::Image(Gtk::Stock::ABOUT, Gtk::ICON_SIZE_BUTTON)));
204         dialog->get_action_area()->pack_end(authorbutton);
205         dialog->get_action_area()->reorder_child(authorbutton, 0);
206         authorbutton.signal_clicked().connect(
207                 sigc::mem_fun(*this, &GAboutlyx::showAuthors));
208         authorbutton.show();
209         xml_->get_widget("AuthorsDialog", authordialog_);
210         Gtk::Label *authorlabel;
211         xml_->get_widget("Authors", authorlabel);
212         std::ostringstream crs;
213         controller().getCredits(crs);
214         authorlabel->set_markup(translateMarkup(
215                 Glib::convert(crs.str(), "UTF-8", "ISO-8859-1")));
216 }
217
218
219 void GAboutlyx::showAuthors()
220 {
221         authordialog_->run();
222         authordialog_->hide();
223 }
224
225
226 } // namespace frontend
227 } // namespace lyx