]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Alert_pimpl.C
xforms alert fixes
[lyx.git] / src / frontends / xforms / Alert_pimpl.C
1 /**
2  * \file xforms/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 John Levon
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13
14 #include "Alert.h"
15 #include "Alert_pimpl.h"
16 #include "forms_gettext.h"
17 #include "gettext.h"
18 #include "xforms_helpers.h"
19
20 #include <algorithm>
21 #include <boost/tuple/tuple.hpp>
22 #include FORMS_H_LOCATION
23
24 using std::pair;
25 using std::make_pair;
26 using std::endl;
27
28 void alert_pimpl(string const & s1, string const & s2, string const & s3)
29 {
30         fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
31         fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
32 }
33
34
35 int prompt_pimpl(string const &, string const & question,
36            int default_button,
37            string const & b1, string const & b2, string const & b3)
38 {
39         string b1label, b1sc;
40         string b2label, b2sc;
41         string b3label, b3sc;
42         boost::tie(b1label, b1sc) = parse_shortcut(b1);
43         boost::tie(b2label, b2sc) = parse_shortcut(b2);
44         boost::tie(b3label, b3sc) = parse_shortcut(b3);
45         lyxerr  << "Parsed " << b1 << " as " << b1label << " and " << b1sc << endl;
46
47         if (b3.empty()) {
48                 fl_set_choices_shortcut(b1sc.c_str(), b2sc.c_str(), "");
49                 return fl_show_choices(question.c_str(),
50                         2, b1label.c_str(), b2label.c_str(), "", default_button + 1) - 1;
51         } else {
52                 fl_set_choices_shortcut(b1sc.c_str(), b2sc.c_str(), b3sc.c_str());
53                 return fl_show_choices(question.c_str(),
54                         3, b1label.c_str(), b2label.c_str(), b3label.c_str(),
55                         default_button + 1) - 1;
56         }
57 }
58
59
60 pair<bool, string> const askForText_pimpl(string const & msg, string const & dflt)
61 {
62         fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")).c_str());
63         fl_set_resource("flInput.ok.label", idex(_("OK|^M")).c_str());
64         fl_set_resource("flInput.clear.label", idex(_("Clear|#C")).c_str());
65         char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
66         if (tmp != 0)
67                 return make_pair<bool, string>(true, string(tmp));
68         else
69                 return make_pair<bool, string>(false, string());
70 }