]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/ghelpers.C
The package reworking.
[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  * \author John Spray
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 // Too hard to make concept checks work with this file
15 #ifdef _GLIBCPP_CONCEPT_CHECKS
16 #undef _GLIBCPP_CONCEPT_CHECKS
17 #endif
18
19 #include "ghelpers.h"
20
21 #include "lyxrc.h"
22 #include "funcrequest.h"
23 #include "debug.h"
24
25 #include "support/filetools.h"
26 #include "support/package.h"
27
28 using std::string;
29 using std::vector;
30
31 namespace lyx {
32 namespace frontend {
33
34 Gtk::BuiltinStockID getGTKStockIcon(FuncRequest const & func)
35 {
36         switch (func.action) {
37
38                 case LFUN_MENUWRITE: return Gtk::Stock::SAVE;
39                 case LFUN_MENUNEW: return Gtk::Stock::NEW;
40                 case LFUN_WRITEAS: return Gtk::Stock::SAVE_AS;
41
42                 case LFUN_CENTER: return Gtk::Stock::JUSTIFY_CENTER;
43                 case LFUN_TOCVIEW: return Gtk::Stock::INDEX;
44                 case LFUN_CLOSEBUFFER: return Gtk::Stock::CLOSE;
45                 case LFUN_QUIT: return Gtk::Stock::QUIT;
46                 case LFUN_UNDO: return Gtk::Stock::UNDO;
47                 case LFUN_REDO: return Gtk::Stock::REDO;
48                 case LFUN_PASTE: return Gtk::Stock::PASTE;
49                 case LFUN_PASTESELECTION: return Gtk::Stock::PASTE;
50                 case LFUN_CUT: return Gtk::Stock::CUT;
51                 case LFUN_COPY: return Gtk::Stock::COPY;
52                 case LFUN_BOLD: return Gtk::Stock::BOLD;
53                 case LFUN_ITAL: return Gtk::Stock::ITALIC;
54                 case LFUN_FILE_OPEN: return Gtk::Stock::OPEN;
55                 case LFUN_RECONFIGURE: return Gtk::Stock::REFRESH;
56                 case LFUN_DIALOG_SHOW:
57                         if (func.argument == "findreplace")
58                                 return Gtk::Stock::FIND_AND_REPLACE;
59                         else if (func.argument == "print")
60                                 return Gtk::Stock::PRINT;
61                         else if (func.argument == "spellchecker")
62                                 return Gtk::Stock::SPELL_CHECK;
63                         else if (func.argument == "prefs")
64                                 return Gtk::Stock::PREFERENCES;
65                         else
66                                 return Gtk::Stock::MISSING_IMAGE;
67                         break;
68                 default: return Gtk::Stock::MISSING_IMAGE;
69         }
70 }
71
72
73 string const getDefaultUnit()
74 {
75         switch (lyxrc.default_papersize) {
76                 case PAPER_DEFAULT: return "cm";
77                 case PAPER_USLETTER:
78                 case PAPER_LEGALPAPER:
79                 case PAPER_EXECUTIVEPAPER: return "in"; break;
80                 case PAPER_A3PAPER:
81                 case PAPER_A4PAPER:
82                 case PAPER_A5PAPER:
83                 case PAPER_B5PAPER: return "cm"; break;
84         }
85         // shut up compiler
86         return "cm";
87 }
88
89
90 void unitsComboFromLength(Gtk::ComboBox * combo,
91                            Gtk::TreeModelColumn<Glib::ustring> const & stringcol,
92                            LyXLength const & len,
93                            std::string defunit)
94 {
95         string unit = stringFromUnit(len.unit());
96         if (unit.empty())
97                 unit = defunit;
98
99         Gtk::TreeModel::iterator it = combo->get_model()->children().begin();
100         Gtk::TreeModel::iterator end = combo->get_model()->children().end();
101         for (; it != end ; ++it) {
102                 if ((*it)[stringcol] == unit) {
103                         combo->set_active(it);
104                         return;
105                 }
106         }
107
108         // Fallen through, we didn't find the target length!
109         combo->set_active(0);
110         lyxerr << "unitsComboFromLength: couldn't find "
111                 "target unit '" << unit << "'\n";
112 }
113
114
115 vector<string> const buildLengthUnitList()
116 {
117         vector<string> data(unit_name_gui, unit_name_gui + num_units);
118
119         return data;
120 }
121
122
123 vector<string> const buildLengthNoRelUnitList()
124 {
125         vector<string> data;
126         for (int i = 0; i < num_units; ++i) {
127                 string str(unit_name_gui[i]);
128                 if (str.find("%") == string::npos)
129                         data.push_back(unit_name_gui[i]);
130         }
131
132         return data;
133 }
134
135
136 string const findGladeFile(string const & name)
137 {
138         // First, search in the installation directories.
139
140         string filename = lyx::support::LibFileSearch("glade", name, "glade");
141
142         if (!filename.empty())
143                 return filename;
144
145         // Second, search in the src tree.
146         string const dir =
147                 lyx::support::AddPath(lyx::support::package().top_srcdir(),
148                                       "src/frontends/gtk/glade");
149
150         filename = lyx::support::ChangeExtension(name, ".glade");
151         filename = lyx::support::AddName(dir, filename);
152
153         if (!lyx::support::IsFileReadable(filename)) {
154                 lyxerr << "Unable to find glade file \"" << name
155                        << "\". libglade is going to crash..." << std::endl;
156         }
157
158         return filename;
159 }
160
161 } // namespace frontend
162 } // namespace lyx