2004-04-27 12:48:45 +00:00
|
|
|
/**
|
|
|
|
* \file ghelpers.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
2004-11-15 14:02:40 +00:00
|
|
|
* \author John Spray
|
2004-04-27 12:48:45 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2004-11-16 23:18:46 +00:00
|
|
|
// Too hard to make concept checks work with this file
|
2005-01-29 15:09:14 +00:00
|
|
|
#ifdef _GLIBCXX_CONCEPT_CHECKS
|
|
|
|
#undef _GLIBCXX_CONCEPT_CHECKS
|
|
|
|
#endif
|
2004-11-16 23:18:46 +00:00
|
|
|
#ifdef _GLIBCPP_CONCEPT_CHECKS
|
|
|
|
#undef _GLIBCPP_CONCEPT_CHECKS
|
|
|
|
#endif
|
|
|
|
|
2004-04-27 12:48:45 +00:00
|
|
|
#include "ghelpers.h"
|
|
|
|
|
2004-11-14 17:10:04 +00:00
|
|
|
#include "lyxrc.h"
|
2004-11-15 14:02:40 +00:00
|
|
|
#include "funcrequest.h"
|
2004-04-27 12:48:45 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
#include "support/package.h"
|
2004-04-27 12:48:45 +00:00
|
|
|
|
2005-03-11 00:25:56 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2004-04-27 12:48:45 +00:00
|
|
|
using std::string;
|
2004-10-26 09:10:17 +00:00
|
|
|
using std::vector;
|
2004-04-27 12:48:45 +00:00
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2005-03-11 00:25:56 +00:00
|
|
|
string const getLengthFromWidgets(Gtk::Adjustment const & adj, Gtk::ComboBoxText const & combo)
|
|
|
|
{
|
|
|
|
std::ostringstream os;
|
|
|
|
os << adj.get_value();
|
|
|
|
os << combo.get_active_text();
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setWidgetsFromLength(Gtk::Adjustment & adj, Gtk::ComboBoxText & combo, LyXLength const & length)
|
|
|
|
{
|
|
|
|
adj.set_value(length.value());
|
|
|
|
|
|
|
|
string unit = stringFromUnit(length.unit());
|
|
|
|
if (unit.empty())
|
|
|
|
unit = getDefaultUnit();
|
|
|
|
|
|
|
|
comboBoxTextSet(combo,unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void populateUnitCombo(Gtk::ComboBoxText & combo, bool const userelative)
|
|
|
|
{
|
|
|
|
vector<string> units = buildLengthUnitList(userelative);
|
|
|
|
|
|
|
|
vector<string>::const_iterator it = units.begin();
|
|
|
|
vector<string>::const_iterator end = units.end();
|
|
|
|
for(; it != end; ++it)
|
|
|
|
combo.append_text(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int comboBoxTextSet(Gtk::ComboBoxText & combo, Glib::ustring target)
|
|
|
|
{
|
|
|
|
int const children = combo.get_model()->children().size();
|
|
|
|
for (int i = 0; i < children; i++) {
|
|
|
|
combo.set_active(i);
|
|
|
|
if (combo.get_active_text() == target)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-15 14:02:40 +00:00
|
|
|
Gtk::BuiltinStockID getGTKStockIcon(FuncRequest const & func)
|
|
|
|
{
|
|
|
|
switch (func.action) {
|
|
|
|
case LFUN_MENUWRITE: return Gtk::Stock::SAVE;
|
|
|
|
case LFUN_MENUNEW: return Gtk::Stock::NEW;
|
|
|
|
case LFUN_WRITEAS: return Gtk::Stock::SAVE_AS;
|
2005-07-31 20:38:01 +00:00
|
|
|
case LFUN_MENURELOAD: return Gtk::Stock::REVERT_TO_SAVED;
|
2004-11-15 14:02:40 +00:00
|
|
|
case LFUN_CENTER: return Gtk::Stock::JUSTIFY_CENTER;
|
|
|
|
case LFUN_TOCVIEW: return Gtk::Stock::INDEX;
|
|
|
|
case LFUN_CLOSEBUFFER: return Gtk::Stock::CLOSE;
|
|
|
|
case LFUN_QUIT: return Gtk::Stock::QUIT;
|
|
|
|
case LFUN_UNDO: return Gtk::Stock::UNDO;
|
|
|
|
case LFUN_REDO: return Gtk::Stock::REDO;
|
|
|
|
case LFUN_PASTE: return Gtk::Stock::PASTE;
|
|
|
|
case LFUN_PASTESELECTION: return Gtk::Stock::PASTE;
|
|
|
|
case LFUN_CUT: return Gtk::Stock::CUT;
|
|
|
|
case LFUN_COPY: return Gtk::Stock::COPY;
|
|
|
|
case LFUN_BOLD: return Gtk::Stock::BOLD;
|
|
|
|
case LFUN_ITAL: return Gtk::Stock::ITALIC;
|
|
|
|
case LFUN_FILE_OPEN: return Gtk::Stock::OPEN;
|
|
|
|
case LFUN_RECONFIGURE: return Gtk::Stock::REFRESH;
|
|
|
|
case LFUN_DIALOG_SHOW:
|
|
|
|
if (func.argument == "findreplace")
|
|
|
|
return Gtk::Stock::FIND_AND_REPLACE;
|
|
|
|
else if (func.argument == "print")
|
|
|
|
return Gtk::Stock::PRINT;
|
|
|
|
else if (func.argument == "spellchecker")
|
|
|
|
return Gtk::Stock::SPELL_CHECK;
|
|
|
|
else if (func.argument == "prefs")
|
|
|
|
return Gtk::Stock::PREFERENCES;
|
2005-03-20 11:38:58 +00:00
|
|
|
else if (func.argument == "document")
|
|
|
|
return Gtk::Stock::PROPERTIES;
|
2004-11-15 14:02:40 +00:00
|
|
|
else
|
|
|
|
return Gtk::Stock::MISSING_IMAGE;
|
|
|
|
break;
|
|
|
|
default: return Gtk::Stock::MISSING_IMAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-19 20:22:24 +00:00
|
|
|
|
2004-11-14 17:10:04 +00:00
|
|
|
string const getDefaultUnit()
|
|
|
|
{
|
|
|
|
switch (lyxrc.default_papersize) {
|
|
|
|
case PAPER_DEFAULT: return "cm";
|
|
|
|
case PAPER_USLETTER:
|
2005-07-16 16:57:55 +00:00
|
|
|
case PAPER_USLEGAL:
|
|
|
|
case PAPER_USEXECUTIVE: return "in"; break;
|
|
|
|
case PAPER_A3:
|
|
|
|
case PAPER_A4:
|
|
|
|
case PAPER_A5:
|
|
|
|
case PAPER_B5: return "cm"; break;
|
2004-11-14 17:10:04 +00:00
|
|
|
}
|
2004-12-19 20:22:24 +00:00
|
|
|
// shut up compiler
|
|
|
|
return "cm";
|
2004-11-14 17:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void unitsComboFromLength(Gtk::ComboBox * combo,
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> const & stringcol,
|
|
|
|
LyXLength const & len,
|
2005-03-11 00:25:56 +00:00
|
|
|
std::string const & defunit)
|
2004-11-14 17:10:04 +00:00
|
|
|
{
|
|
|
|
string unit = stringFromUnit(len.unit());
|
|
|
|
if (unit.empty())
|
|
|
|
unit = defunit;
|
|
|
|
|
|
|
|
Gtk::TreeModel::iterator it = combo->get_model()->children().begin();
|
|
|
|
Gtk::TreeModel::iterator end = combo->get_model()->children().end();
|
|
|
|
for (; it != end ; ++it) {
|
|
|
|
if ((*it)[stringcol] == unit) {
|
|
|
|
combo->set_active(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallen through, we didn't find the target length!
|
|
|
|
combo->set_active(0);
|
|
|
|
lyxerr << "unitsComboFromLength: couldn't find "
|
|
|
|
"target unit '" << unit << "'\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-11 00:25:56 +00:00
|
|
|
vector<string> const buildLengthUnitList(bool const userelative)
|
2004-11-16 00:20:59 +00:00
|
|
|
{
|
2005-03-11 00:25:56 +00:00
|
|
|
//vector<string> data(unit_name_gui, unit_name_gui + num_units);
|
2004-11-16 00:20:59 +00:00
|
|
|
vector<string> data;
|
2005-03-11 00:25:56 +00:00
|
|
|
if (userelative) {
|
|
|
|
data = vector<string>(unit_name_gui, unit_name_gui + num_units);
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < num_units; ++i) {
|
|
|
|
string str(unit_name_gui[i]);
|
|
|
|
if (str.find("%") == string::npos)
|
|
|
|
data.push_back(unit_name_gui[i]);
|
|
|
|
}
|
2004-11-16 00:20:59 +00:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-27 12:48:45 +00:00
|
|
|
string const findGladeFile(string const & name)
|
|
|
|
{
|
|
|
|
// First, search in the installation directories.
|
|
|
|
|
2004-09-26 13:18:29 +00:00
|
|
|
string filename = lyx::support::LibFileSearch("glade", name, "glade");
|
2004-04-27 12:48:45 +00:00
|
|
|
|
|
|
|
if (!filename.empty())
|
|
|
|
return filename;
|
|
|
|
|
|
|
|
// Second, search in the src tree.
|
|
|
|
string const dir =
|
2005-01-10 19:17:43 +00:00
|
|
|
lyx::support::AddPath(lyx::support::package().top_srcdir(),
|
2004-04-27 12:48:45 +00:00
|
|
|
"src/frontends/gtk/glade");
|
|
|
|
|
|
|
|
filename = lyx::support::ChangeExtension(name, ".glade");
|
|
|
|
filename = lyx::support::AddName(dir, filename);
|
|
|
|
|
|
|
|
if (!lyx::support::IsFileReadable(filename)) {
|
|
|
|
lyxerr << "Unable to find glade file \"" << name
|
|
|
|
<< "\". libglade is going to crash..." << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|