]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/Alert_pimpl.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / gtk / Alert_pimpl.C
1 /**
2  * \file gtk/Alert_pimpl.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 "frontends/Alert.h"
22 #include "frontends/Alert_pimpl.h"
23
24 #include <gtkmm.h>
25
26 using std::string;
27
28
29 namespace {
30
31
32 string translateShortcut(string const & str)
33 {
34         string::size_type i = str.find_first_of("&");
35         if (i == string::npos || i == str.length() - 1)
36                 return str;
37         string tstr = str;
38         tstr[i] = '_';
39         return tstr;
40 }
41
42
43 }
44
45
46 void warning_pimpl(string const &, string const & message)
47 {
48         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
49                                true, Gtk::MESSAGE_WARNING,
50                                Gtk::BUTTONS_CLOSE, true);
51         dlg.run();
52 }
53
54
55 void error_pimpl(string const &, string const & message)
56 {
57         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
58                                true, Gtk::MESSAGE_ERROR,
59                                Gtk::BUTTONS_CLOSE, true);
60         dlg.run();
61 }
62
63
64 void information_pimpl(string const &, string const & message)
65 {
66         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
67                                true, Gtk::MESSAGE_INFO,
68                                Gtk::BUTTONS_CLOSE, true);
69         dlg.run();
70 }
71
72
73 int prompt_pimpl(string const &, string const & question,
74                  int defaultButton, int /*escapeButton*/,
75                  string const & b1, string const & b2, string const & b3)
76 {
77         Glib::ustring gb1 = Glib::locale_to_utf8(translateShortcut(b1));
78         Glib::ustring gb2 = Glib::locale_to_utf8(translateShortcut(b2));
79         Glib::ustring gb3;
80         if (!b3.empty())
81                 gb3 = Glib::locale_to_utf8(translateShortcut(b3));
82         Gtk::MessageDialog dlg(Glib::locale_to_utf8(question),
83                                true, Gtk::MESSAGE_QUESTION,
84                                Gtk::BUTTONS_NONE, true);
85         dlg.add_button(gb1, 0);
86         dlg.add_button(gb2, 1);
87         if (!b3.empty())
88                 dlg.add_button(gb3, 2);
89         dlg.set_default_response(defaultButton);
90         return dlg.run();
91 }
92
93
94 std::pair<bool, string> const askForText_pimpl(string const & msg,
95                                                string const & dflt)
96 {
97         Gtk::MessageDialog dlg(Glib::locale_to_utf8(msg),
98                                true, Gtk::MESSAGE_QUESTION,
99                                Gtk::BUTTONS_OK_CANCEL,
100                                true);
101         Gtk::Entry entry;
102         entry.set_text(Glib::locale_to_utf8(dflt));
103         entry.set_position(-1);
104         entry.show();
105         dlg.get_vbox()->children().push_back(
106                 Gtk::Box_Helpers::Element(entry));
107         int response = dlg.run();
108         if (response == Gtk::RESPONSE_OK) {
109                 string str = Glib::locale_from_utf8(entry.get_text());
110                 return std::make_pair<bool, string>(true, str);
111         }
112         else
113                 return std::make_pair<bool, string>(false, string());
114 }