]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/ghelpers.C
GTK Box dialog
[lyx.git] / src / frontends / gtk / ghelpers.C
1 /**
2  * \file ghelpers.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ghelpers.h"
14
15 #include "lyxrc.h"
16 #include "debug.h"
17
18 #include "support/filetools.h"
19 #include "support/path_defines.h"
20
21 using std::string;
22 using std::vector;
23
24 namespace lyx {
25 namespace frontend {
26
27 string const getDefaultUnit()
28 {
29         switch (lyxrc.default_papersize) {
30                 case PAPER_DEFAULT: return "cm";
31                 case PAPER_USLETTER:
32                 case PAPER_LEGALPAPER:
33                 case PAPER_EXECUTIVEPAPER: return "in"; break;
34                 case PAPER_A3PAPER:
35                 case PAPER_A4PAPER:
36                 case PAPER_A5PAPER:
37                 case PAPER_B5PAPER: return "cm"; break;
38         }
39 }
40
41
42 void unitsComboFromLength(Gtk::ComboBox * combo,
43                            Gtk::TreeModelColumn<Glib::ustring> const & stringcol,
44                            LyXLength const & len,
45                            std::string defunit)
46 {
47         string unit = stringFromUnit(len.unit());
48         if (unit.empty())
49                 unit = defunit;
50
51         Gtk::TreeModel::iterator it = combo->get_model()->children().begin();
52         Gtk::TreeModel::iterator end = combo->get_model()->children().end();
53         for (; it != end ; ++it) {
54                 if ((*it)[stringcol] == unit) {
55                         combo->set_active(it);
56                         return;
57                 }
58         }
59
60         // Fallen through, we didn't find the target length!
61         combo->set_active(0);
62         lyxerr << "unitsComboFromLength: couldn't find "
63                 "target unit '" << unit << "'\n";
64 }
65
66
67 vector<string> const buildLengthUnitList()
68 {
69         vector<string> data(unit_name_gui, unit_name_gui + num_units);
70
71         return data;
72 }
73
74
75 string const findGladeFile(string const & name)
76 {
77         // First, search in the installation directories.
78
79         string filename = lyx::support::LibFileSearch("glade", name, "glade");
80
81         if (!filename.empty())
82                 return filename;
83
84         // Second, search in the src tree.
85         string const dir =
86                 lyx::support::AddPath(lyx::support::top_srcdir(),
87                                       "src/frontends/gtk/glade");
88
89         filename = lyx::support::ChangeExtension(name, ".glade");
90         filename = lyx::support::AddName(dir, filename);
91
92         if (!lyx::support::IsFileReadable(filename)) {
93                 lyxerr << "Unable to find glade file \"" << name
94                        << "\". libglade is going to crash..." << std::endl;
95         }
96
97         return filename;
98 }
99
100 } // namespace frontend
101 } // namespace lyx