3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
14 // Too hard to make concept checks work with this file
15 #ifdef _GLIBCXX_CONCEPT_CHECKS
16 #undef _GLIBCXX_CONCEPT_CHECKS
18 #ifdef _GLIBCPP_CONCEPT_CHECKS
19 #undef _GLIBCPP_CONCEPT_CHECKS
25 #include "funcrequest.h"
28 #include "support/filetools.h"
29 #include "support/package.h"
39 string const getLengthFromWidgets(Gtk::Adjustment const & adj, Gtk::ComboBoxText const & combo)
41 std::ostringstream os;
42 os << adj.get_value();
43 os << combo.get_active_text();
48 void setWidgetsFromLength(Gtk::Adjustment & adj, Gtk::ComboBoxText & combo, LyXLength const & length)
50 adj.set_value(length.value());
52 string unit = stringFromUnit(length.unit());
54 unit = getDefaultUnit();
56 comboBoxTextSet(combo,unit);
60 void populateUnitCombo(Gtk::ComboBoxText & combo, bool const userelative)
62 vector<string> units = buildLengthUnitList(userelative);
64 vector<string>::const_iterator it = units.begin();
65 vector<string>::const_iterator end = units.end();
66 for(; it != end; ++it)
67 combo.append_text(*it);
71 int comboBoxTextSet(Gtk::ComboBoxText & combo, Glib::ustring target)
73 int const children = combo.get_model()->children().size();
74 for (int i = 0; i < children; i++) {
76 if (combo.get_active_text() == target)
83 Gtk::BuiltinStockID getGTKStockIcon(FuncRequest const & func)
85 switch (func.action) {
86 case LFUN_MENUWRITE: return Gtk::Stock::SAVE;
87 case LFUN_MENUNEW: return Gtk::Stock::NEW;
88 case LFUN_WRITEAS: return Gtk::Stock::SAVE_AS;
89 case LFUN_CENTER: return Gtk::Stock::JUSTIFY_CENTER;
90 case LFUN_TOCVIEW: return Gtk::Stock::INDEX;
91 case LFUN_CLOSEBUFFER: return Gtk::Stock::CLOSE;
92 case LFUN_QUIT: return Gtk::Stock::QUIT;
93 case LFUN_UNDO: return Gtk::Stock::UNDO;
94 case LFUN_REDO: return Gtk::Stock::REDO;
95 case LFUN_PASTE: return Gtk::Stock::PASTE;
96 case LFUN_PASTESELECTION: return Gtk::Stock::PASTE;
97 case LFUN_CUT: return Gtk::Stock::CUT;
98 case LFUN_COPY: return Gtk::Stock::COPY;
99 case LFUN_BOLD: return Gtk::Stock::BOLD;
100 case LFUN_ITAL: return Gtk::Stock::ITALIC;
101 case LFUN_FILE_OPEN: return Gtk::Stock::OPEN;
102 case LFUN_RECONFIGURE: return Gtk::Stock::REFRESH;
103 case LFUN_DIALOG_SHOW:
104 if (func.argument == "findreplace")
105 return Gtk::Stock::FIND_AND_REPLACE;
106 else if (func.argument == "print")
107 return Gtk::Stock::PRINT;
108 else if (func.argument == "spellchecker")
109 return Gtk::Stock::SPELL_CHECK;
110 else if (func.argument == "prefs")
111 return Gtk::Stock::PREFERENCES;
113 return Gtk::Stock::MISSING_IMAGE;
115 default: return Gtk::Stock::MISSING_IMAGE;
120 string const getDefaultUnit()
122 switch (lyxrc.default_papersize) {
123 case PAPER_DEFAULT: return "cm";
125 case PAPER_LEGALPAPER:
126 case PAPER_EXECUTIVEPAPER: return "in"; break;
130 case PAPER_B5PAPER: return "cm"; break;
137 void unitsComboFromLength(Gtk::ComboBox * combo,
138 Gtk::TreeModelColumn<Glib::ustring> const & stringcol,
139 LyXLength const & len,
140 std::string const & defunit)
142 string unit = stringFromUnit(len.unit());
146 Gtk::TreeModel::iterator it = combo->get_model()->children().begin();
147 Gtk::TreeModel::iterator end = combo->get_model()->children().end();
148 for (; it != end ; ++it) {
149 if ((*it)[stringcol] == unit) {
150 combo->set_active(it);
155 // Fallen through, we didn't find the target length!
156 combo->set_active(0);
157 lyxerr << "unitsComboFromLength: couldn't find "
158 "target unit '" << unit << "'\n";
162 vector<string> const buildLengthUnitList(bool const userelative)
164 //vector<string> data(unit_name_gui, unit_name_gui + num_units);
167 data = vector<string>(unit_name_gui, unit_name_gui + num_units);
169 for (int i = 0; i < num_units; ++i) {
170 string str(unit_name_gui[i]);
171 if (str.find("%") == string::npos)
172 data.push_back(unit_name_gui[i]);
179 string const findGladeFile(string const & name)
181 // First, search in the installation directories.
183 string filename = lyx::support::LibFileSearch("glade", name, "glade");
185 if (!filename.empty())
188 // Second, search in the src tree.
190 lyx::support::AddPath(lyx::support::package().top_srcdir(),
191 "src/frontends/gtk/glade");
193 filename = lyx::support::ChangeExtension(name, ".glade");
194 filename = lyx::support::AddName(dir, filename);
196 if (!lyx::support::IsFileReadable(filename)) {
197 lyxerr << "Unable to find glade file \"" << name
198 << "\". libglade is going to crash..." << std::endl;
204 } // namespace frontend