2002-09-05 14:10:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file ControlGraphics.C
|
2002-09-05 15:14:23 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-03-28 12:59:29 +00:00
|
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
|
* \author Angus Leeming
|
2003-09-07 01:45:40 +00:00
|
|
|
|
* \author Herbert Vo<EFBFBD>
|
2001-03-28 12:59:29 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-03-28 12:59:29 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
#include <config.h>
|
2001-03-28 12:59:29 +00:00
|
|
|
|
|
|
|
|
|
#include "ControlGraphics.h"
|
2002-04-11 17:40:44 +00:00
|
|
|
|
|
|
|
|
|
#include "helper_funcs.h"
|
|
|
|
|
|
2003-03-07 18:44:57 +00:00
|
|
|
|
#include "funcrequest.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "gettext.h"
|
2002-01-30 19:14:09 +00:00
|
|
|
|
#include "lyxrc.h"
|
2001-03-28 12:59:29 +00:00
|
|
|
|
|
2002-04-11 17:40:44 +00:00
|
|
|
|
#include "graphics/GraphicsCache.h"
|
2002-06-28 11:22:56 +00:00
|
|
|
|
#include "graphics/GraphicsCacheItem.h"
|
2002-06-25 15:59:10 +00:00
|
|
|
|
#include "graphics/GraphicsImage.h"
|
2002-04-11 17:40:44 +00:00
|
|
|
|
|
2001-03-28 12:59:29 +00:00
|
|
|
|
#include "insets/insetgraphics.h"
|
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
|
#include "support/convert.h"
|
2004-11-25 11:08:32 +00:00
|
|
|
|
#include "support/filefilterlist.h"
|
2003-09-07 01:45:40 +00:00
|
|
|
|
#include "support/filetools.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
|
#include "support/package.h"
|
2003-09-07 01:45:40 +00:00
|
|
|
|
#include "support/types.h"
|
2002-04-11 17:40:44 +00:00
|
|
|
|
|
2005-01-31 10:42:26 +00:00
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
|
using std::make_pair;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::pair;
|
2002-05-01 09:25:51 +00:00
|
|
|
|
using std::vector;
|
2002-04-12 15:25:11 +00:00
|
|
|
|
|
2005-01-31 10:42:26 +00:00
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
|
using support::addName;
|
2004-05-19 15:11:37 +00:00
|
|
|
|
using support::FileFilterList;
|
2006-04-08 09:09:57 +00:00
|
|
|
|
using support::isFileReadable;
|
2006-04-08 22:31:11 +00:00
|
|
|
|
using support::makeAbsPath;
|
2005-01-10 19:17:43 +00:00
|
|
|
|
using support::package;
|
2004-05-19 15:11:37 +00:00
|
|
|
|
using support::readBB_from_PSFile;
|
|
|
|
|
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
|
2003-03-07 18:44:57 +00:00
|
|
|
|
ControlGraphics::ControlGraphics(Dialog & parent)
|
|
|
|
|
: Dialog::Controller(parent)
|
2002-06-18 15:44:30 +00:00
|
|
|
|
{}
|
2001-03-28 12:59:29 +00:00
|
|
|
|
|
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
|
bool ControlGraphics::initialiseParams(string const & data)
|
2001-03-28 12:59:29 +00:00
|
|
|
|
{
|
2003-03-07 18:44:57 +00:00
|
|
|
|
InsetGraphicsParams params;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
InsetGraphicsMailer::string2params(data, kernel().buffer(), params);
|
2003-03-07 18:44:57 +00:00
|
|
|
|
params_.reset(new InsetGraphicsParams(params));
|
2003-03-14 00:20:42 +00:00
|
|
|
|
return true;
|
2001-03-28 12:59:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-07 18:44:57 +00:00
|
|
|
|
void ControlGraphics::clearParams()
|
2001-03-28 12:59:29 +00:00
|
|
|
|
{
|
2003-03-07 18:44:57 +00:00
|
|
|
|
params_.reset();
|
2001-03-28 12:59:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-07 18:44:57 +00:00
|
|
|
|
void ControlGraphics::dispatchParams()
|
2001-03-28 12:59:29 +00:00
|
|
|
|
{
|
2003-07-18 08:46:00 +00:00
|
|
|
|
InsetGraphicsParams tmp_params(params());
|
2003-07-21 21:51:17 +00:00
|
|
|
|
string const lfun =
|
2003-08-28 07:41:31 +00:00
|
|
|
|
InsetGraphicsMailer::params2string(tmp_params, kernel().buffer());
|
2005-04-26 09:37:52 +00:00
|
|
|
|
kernel().dispatch(FuncRequest(getLfun(), lfun));
|
2001-03-28 12:59:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-09 16:33:20 +00:00
|
|
|
|
docstring const ControlGraphics::browse(docstring const & in_name) const
|
2001-03-30 09:51:46 +00:00
|
|
|
|
{
|
2006-10-09 16:33:20 +00:00
|
|
|
|
docstring const title = _("Select graphics file");
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
// Does user clipart directory exist?
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string clipdir = addName(package().user_support(), "clipart");
|
2005-01-31 10:42:26 +00:00
|
|
|
|
if (!(fs::exists(clipdir) && fs::is_directory(clipdir)))
|
2002-03-21 21:21:28 +00:00
|
|
|
|
// No - bail out to system clipart directory
|
2006-04-08 22:31:11 +00:00
|
|
|
|
clipdir = addName(package().system_support(), "clipart");
|
2006-10-09 16:33:20 +00:00
|
|
|
|
pair<docstring, docstring> dir1(_("Clipart|#C#c"), lyx::from_utf8(clipdir));
|
|
|
|
|
pair<docstring, docstring> dir2(_("Documents|#o#O"), lyx::from_utf8(lyxrc.document_path));
|
2001-03-30 09:51:46 +00:00
|
|
|
|
// Show the file browser dialog
|
2006-10-09 16:33:20 +00:00
|
|
|
|
return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
|
2004-01-08 10:59:51 +00:00
|
|
|
|
title,
|
|
|
|
|
FileFilterList(),
|
|
|
|
|
false, dir1, dir2);
|
2001-03-30 09:51:46 +00:00
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2002-01-29 09:26:24 +00:00
|
|
|
|
|
|
|
|
|
string const ControlGraphics::readBB(string const & file)
|
|
|
|
|
{
|
2003-03-07 18:44:57 +00:00
|
|
|
|
string const abs_file =
|
2006-04-08 22:31:11 +00:00
|
|
|
|
makeAbsPath(file, kernel().bufferFilepath());
|
2002-04-11 17:40:44 +00:00
|
|
|
|
|
2002-07-22 12:36:41 +00:00
|
|
|
|
// try to get it from the file, if possible. Zipped files are
|
|
|
|
|
// unzipped in the readBB_from_PSFile-Function
|
|
|
|
|
string const bb = readBB_from_PSFile(abs_file);
|
|
|
|
|
if (!bb.empty())
|
|
|
|
|
return bb;
|
2002-04-11 17:40:44 +00:00
|
|
|
|
|
|
|
|
|
// we don't, so ask the Graphics Cache if it has loaded the file
|
2002-06-25 15:59:10 +00:00
|
|
|
|
int width = 0;
|
|
|
|
|
int height = 0;
|
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
graphics::Cache & gc = graphics::Cache::get();
|
2002-06-28 11:22:56 +00:00
|
|
|
|
if (gc.inCache(abs_file)) {
|
2004-05-19 15:11:37 +00:00
|
|
|
|
graphics::Image const * image = gc.item(abs_file)->image();
|
2002-06-25 15:59:10 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
if (image) {
|
|
|
|
|
width = image->getWidth();
|
|
|
|
|
height = image->getHeight();
|
|
|
|
|
}
|
2002-06-25 15:59:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
|
2002-01-29 09:26:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-22 15:24:32 +00:00
|
|
|
|
bool ControlGraphics::isFilenameValid(string const & fname) const
|
|
|
|
|
{
|
|
|
|
|
// It may be that the filename is relative.
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string const name = makeAbsPath(fname, kernel().bufferFilepath());
|
2006-04-08 09:09:57 +00:00
|
|
|
|
return isFileReadable(name);
|
2002-03-11 11:17:49 +00:00
|
|
|
|
}
|
2002-05-01 09:25:51 +00:00
|
|
|
|
|
|
|
|
|
|
2004-04-13 10:36:09 +00:00
|
|
|
|
void ControlGraphics::editGraphics()
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(params_.get());
|
|
|
|
|
|
|
|
|
|
dialog().view().apply();
|
|
|
|
|
string const lfun =
|
|
|
|
|
InsetGraphicsMailer::params2string(params(), kernel().buffer());
|
|
|
|
|
kernel().dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-01 09:25:51 +00:00
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2002-11-04 14:53:03 +00:00
|
|
|
|
char const * const bb_units[] = { "bp", "cm", "mm", "in" };
|
|
|
|
|
size_t const bb_size = sizeof(bb_units) / sizeof(char *);
|
|
|
|
|
|
2002-05-01 13:04:35 +00:00
|
|
|
|
// These are the strings that are stored in the LyX file and which
|
|
|
|
|
// correspond to the LaTeX identifiers shown in the comments at the
|
|
|
|
|
// end of each line.
|
|
|
|
|
char const * const rorigin_lyx_strs[] = {
|
2002-07-22 12:36:41 +00:00
|
|
|
|
// the LaTeX default is leftBaseline
|
2002-11-07 00:21:28 +00:00
|
|
|
|
"",
|
2002-09-11 18:37:50 +00:00
|
|
|
|
"leftTop", "leftBottom", "leftBaseline", // lt lb lB
|
|
|
|
|
"center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
|
|
|
|
|
"rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
|
2002-05-01 13:04:35 +00:00
|
|
|
|
|
|
|
|
|
// These are the strings, corresponding to the above, that the GUI should
|
|
|
|
|
// use. Note that they can/should be translated.
|
2002-05-01 09:25:51 +00:00
|
|
|
|
char const * const rorigin_gui_strs[] = {
|
2002-11-07 00:21:28 +00:00
|
|
|
|
N_("Default"),
|
2003-08-14 15:45:09 +00:00
|
|
|
|
N_("Top left"), N_("Bottom left"), N_("Baseline left"),
|
|
|
|
|
N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
|
|
|
|
|
N_("Top right"), N_("Bottom right"), N_("Baseline right") };
|
2002-05-01 09:25:51 +00:00
|
|
|
|
|
2002-05-01 13:15:37 +00:00
|
|
|
|
size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
|
2002-05-01 09:25:51 +00:00
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
2002-11-04 14:53:03 +00:00
|
|
|
|
vector<string> const getBBUnits()
|
|
|
|
|
{
|
2006-04-08 22:31:11 +00:00
|
|
|
|
return vector<string>(bb_units, bb_units + bb_size);
|
2002-11-04 14:53:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-01 09:25:51 +00:00
|
|
|
|
vector<RotationOriginPair> getRotationOriginData()
|
|
|
|
|
{
|
|
|
|
|
static vector<RotationOriginPair> data;
|
|
|
|
|
if (!data.empty())
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
|
|
data.resize(rorigin_size);
|
2004-05-19 15:11:37 +00:00
|
|
|
|
for (size_type i = 0; i < rorigin_size; ++i) {
|
2006-09-09 15:27:44 +00:00
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
data[i] = make_pair(lyx::to_utf8(_(rorigin_gui_strs[i])),
|
2002-06-18 15:44:30 +00:00
|
|
|
|
rorigin_lyx_strs[i]);
|
2002-05-01 09:25:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|