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
|
|
|
|
* \author Herbert Voss
|
2001-03-28 12:59:29 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +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"
|
|
|
|
|
2002-03-22 15:24:32 +00:00
|
|
|
#include "BufferView.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"
|
2002-04-11 17:40:44 +00:00
|
|
|
#include "insets/insetgraphicsParams.h"
|
2001-03-28 12:59:29 +00:00
|
|
|
|
2003-05-13 14:36:24 +00:00
|
|
|
#include "support/tostr.h"
|
2002-04-11 17:40:44 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/FileInfo.h"
|
2003-07-27 21:04:02 +00:00
|
|
|
#include "support/path_defines.h"
|
2002-04-11 17:40:44 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
using std::pair;
|
|
|
|
using std::make_pair;
|
2002-05-01 09:25:51 +00:00
|
|
|
using std::vector;
|
2002-04-12 15:25:11 +00:00
|
|
|
|
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-07-23 09:54:21 +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-07-23 09:54:21 +00:00
|
|
|
InsetGraphicsMailer::params2string(tmp_params, *kernel().buffer());
|
2003-03-07 18:44:57 +00:00
|
|
|
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
|
2001-03-28 12:59:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
string const ControlGraphics::Browse(string const & in_name)
|
|
|
|
{
|
2002-04-08 16:47:50 +00:00
|
|
|
string 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?
|
2003-07-27 22:13:29 +00:00
|
|
|
string clipdir = AddName (user_lyxdir(), "clipart");
|
2002-03-21 21:21:28 +00:00
|
|
|
FileInfo fileInfo(clipdir);
|
|
|
|
if (!(fileInfo.isOK() && fileInfo.isDir()))
|
|
|
|
// No - bail out to system clipart directory
|
2003-07-27 21:04:02 +00:00
|
|
|
clipdir = AddName (system_lyxdir(), "clipart");
|
2002-04-08 16:47:50 +00:00
|
|
|
pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
|
|
|
|
pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
|
2001-03-30 09:51:46 +00:00
|
|
|
// Show the file browser dialog
|
2003-07-23 09:07:28 +00:00
|
|
|
return browseRelFile(in_name, kernel().bufferFilepath(),
|
2002-11-17 08:32:09 +00:00
|
|
|
title, "*.*", 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 =
|
2003-07-23 09:07:28 +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;
|
|
|
|
|
2003-07-21 21:30:57 +00:00
|
|
|
lyx::graphics::Cache & gc = lyx::graphics::Cache::get();
|
2002-06-28 11:22:56 +00:00
|
|
|
if (gc.inCache(abs_file)) {
|
2003-07-21 21:30:57 +00:00
|
|
|
lyx::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
|
|
|
}
|
|
|
|
|
|
|
|
return ("0 0 " + tostr(width) + ' ' + tostr(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.
|
2003-07-23 09:07:28 +00:00
|
|
|
string const name = MakeAbsPath(fname, kernel().bufferFilepath());
|
2002-03-22 15:24:32 +00:00
|
|
|
return IsFileReadable(name);
|
2002-03-11 11:17:49 +00:00
|
|
|
}
|
2002-05-01 09:25:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace frnt {
|
|
|
|
|
|
|
|
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"),
|
2002-09-11 18:37:50 +00:00
|
|
|
N_("Top left"), N_("Bottom left"), N_("Left baseline"),
|
|
|
|
N_("Center"), N_("Top center"), N_("Bottom center"), N_("Center baseline"),
|
|
|
|
N_("Top right"), N_("Bottom right"), N_("Right baseline") };
|
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()
|
|
|
|
{
|
|
|
|
return vector<string> (bb_units, bb_units + bb_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-01 09:25:51 +00:00
|
|
|
vector<RotationOriginPair> getRotationOriginData()
|
|
|
|
{
|
|
|
|
static vector<RotationOriginPair> data;
|
|
|
|
if (!data.empty())
|
|
|
|
return data;
|
|
|
|
|
|
|
|
data.resize(rorigin_size);
|
|
|
|
for (lyx::size_type i = 0; i < rorigin_size; ++i) {
|
2002-06-18 15:44:30 +00:00
|
|
|
data[i] = make_pair(_(rorigin_gui_strs[i]),
|
|
|
|
rorigin_lyx_strs[i]);
|
2002-05-01 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frnt
|