]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/Alert_pimpl.C
3233be9c9b5e38d7e3118028ae9280acc3347d50
[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 & title, 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.set_title(title);
52         dlg.run();
53 }
54
55
56 void error_pimpl(string const & title, string const & message)
57 {
58         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
59                                true, Gtk::MESSAGE_ERROR,
60                                Gtk::BUTTONS_CLOSE, true);
61         dlg.set_title(title);
62         dlg.run();
63 }
64
65
66 void information_pimpl(string const & title, string const & message)
67 {
68         Gtk::MessageDialog dlg(Glib::locale_to_utf8(message),
69                                true, Gtk::MESSAGE_INFO,
70                                Gtk::BUTTONS_CLOSE, true);
71         dlg.set_title(title);
72         dlg.run();
73 }
74
75
76 int prompt_pimpl(string const & title, string const & question,
77                  int defaultButton, int /*escapeButton*/,
78                  string const & b1, string const & b2, string const & b3)
79 {
80         Glib::ustring gb1 = Glib::locale_to_utf8(translateShortcut(b1));
81         Glib::ustring gb2 = Glib::locale_to_utf8(translateShortcut(b2));
82         Glib::ustring gb3;
83         if (!b3.empty())
84                 gb3 = Glib::locale_to_utf8(translateShortcut(b3));
85         Gtk::MessageDialog dlg(Glib::locale_to_utf8(question),
86                                true, Gtk::MESSAGE_QUESTION,
87                                Gtk::BUTTONS_NONE, true);
88         dlg.set_title(title);
89         dlg.add_button(gb1, 0);
90         dlg.add_button(gb2, 1);
91         if (!b3.empty())
92                 dlg.add_button(gb3, 2);
93         dlg.set_default_response(defaultButton);
94         return dlg.run();
95 }
96
97
98 std::pair<bool, string> const askForText_pimpl(string const & msg,
99                                                string const & dflt)
100 {
101         Gtk::MessageDialog dlg(Glib::locale_to_utf8(msg),
102                                true, Gtk::MESSAGE_QUESTION,
103                                Gtk::BUTTONS_OK_CANCEL,
104                                true);
105         Gtk::Entry entry;
106         entry.set_text(Glib::locale_to_utf8(dflt));
107         entry.set_position(-1);
108         entry.show();
109         dlg.get_vbox()->children().push_back(
110                 Gtk::Box_Helpers::Element(entry));
111         int response = dlg.run();
112         if (response == Gtk::RESPONSE_OK) {
113                 string str = Glib::locale_from_utf8(entry.get_text());
114                 return std::make_pair<bool, string>(true, str);
115         }
116         else
117                 return std::make_pair<bool, string>(false, string());
118 }