2001-03-28 12:59:29 +00:00
|
|
|
/* This file is part of
|
2002-03-21 21:21:28 +00:00
|
|
|
* ======================================================
|
2001-03-28 12:59:29 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* \file ControlGraphics.C
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
2002-01-29 09:26:24 +00:00
|
|
|
* \author Herbert Voss <voss@perce.de>
|
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
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
2002-03-21 21:21:28 +00:00
|
|
|
#endif
|
2001-03-28 12:59:29 +00:00
|
|
|
|
|
|
|
#include "ControlGraphics.h"
|
2002-04-11 17:40:44 +00:00
|
|
|
|
|
|
|
#include "helper_funcs.h"
|
|
|
|
|
2002-04-19 09:17:05 +00:00
|
|
|
#include "converter.h"
|
2001-03-28 12:59:29 +00:00
|
|
|
#include "buffer.h"
|
2002-03-22 15:24:32 +00:00
|
|
|
#include "BufferView.h"
|
2001-03-28 12:59:29 +00:00
|
|
|
#include "Dialogs.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
#include "frontends/LyXView.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
|
|
|
|
2002-01-29 09:26:24 +00:00
|
|
|
#include "support/lstrings.h"
|
2002-04-11 17:40:44 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/FileInfo.h"
|
|
|
|
|
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
|
|
|
|
2001-03-28 12:59:29 +00:00
|
|
|
ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
|
|
|
|
: ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
|
2002-06-18 15:44:30 +00:00
|
|
|
{}
|
2001-03-28 12:59:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
InsetGraphicsParams const ControlGraphics::getParams(string const &)
|
|
|
|
{
|
|
|
|
return InsetGraphicsParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetGraphicsParams const
|
|
|
|
ControlGraphics::getParams(InsetGraphics const & inset)
|
|
|
|
{
|
2002-02-27 09:59:52 +00:00
|
|
|
return inset.params();
|
2001-03-28 12:59:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlGraphics::applyParamsToInset()
|
|
|
|
{
|
|
|
|
// Set the parameters in the inset, it also returns true if the new
|
|
|
|
// parameters are different from what was in the inset already.
|
2002-03-22 16:37:52 +00:00
|
|
|
bool changed = inset()->setParams(params(), lv_.buffer()->filePath());
|
2001-03-28 12:59:29 +00:00
|
|
|
// Tell LyX we've got a change, and mark the document dirty,
|
|
|
|
// if it changed.
|
|
|
|
lv_.view()->updateInset(inset(), changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlGraphics::applyParamsNoInset()
|
|
|
|
{}
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
// We need these in the file browser.
|
|
|
|
extern string system_lyxdir;
|
|
|
|
extern string user_lyxdir;
|
2002-03-21 21:21:28 +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?
|
|
|
|
string clipdir = AddName (user_lyxdir, "clipart");
|
|
|
|
FileInfo fileInfo(clipdir);
|
|
|
|
if (!(fileInfo.isOK() && fileInfo.isDir()))
|
|
|
|
// No - bail out to system clipart directory
|
|
|
|
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
|
2002-03-22 15:24:32 +00:00
|
|
|
return browseRelFile(&lv_, in_name, lv_.buffer()->filePath(),
|
2002-06-18 20:47:49 +00:00
|
|
|
title, "*.*", 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)
|
|
|
|
{
|
2002-04-11 17:40:44 +00:00
|
|
|
string const abs_file = MakeAbsPath(file, lv_.buffer()->filePath());
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
string const from = getExtFromContents(abs_file);
|
2002-04-11 17:40:44 +00:00
|
|
|
// Check if we have a Postscript file, then it's easy
|
|
|
|
if (contains(from, "ps"))
|
|
|
|
return readBB_from_PSFile(abs_file);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
grfx::Cache & gc = grfx::Cache::get();
|
|
|
|
if (gc.inCache(abs_file)) {
|
|
|
|
grfx::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.
|
|
|
|
string const name = MakeAbsPath(fname, lv_.buffer()->filePath());
|
|
|
|
return IsFileReadable(name);
|
2002-03-11 11:17:49 +00:00
|
|
|
}
|
2002-05-01 09:25:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace frnt {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
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[] = {
|
|
|
|
"center", // c
|
|
|
|
"leftTop", "leftBottom", "leftBaseline", // lt lb lB
|
|
|
|
"centerTop", "centerBottom", "centerBaseline", // ct cb cB
|
|
|
|
"rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
|
|
|
|
|
|
|
|
// 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[] = {
|
|
|
|
N_("center"),
|
|
|
|
N_("left top"), N_("left bottom"), N_("left baseline"),
|
|
|
|
N_("center top"), N_("center bottom"), N_("center baseline"),
|
|
|
|
N_("right top"), N_("right bottom"), N_("right baseline") };
|
|
|
|
|
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-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
|