2001-03-28 12:59:29 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2002-01-29 09:26:24 +00:00
|
|
|
#include <fstream>
|
2001-03-28 12:59:29 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-04-26 18:40:38 +00:00
|
|
|
#include "ViewBase.h"
|
|
|
|
#include "ButtonControllerBase.h"
|
2001-03-28 12:59:29 +00:00
|
|
|
#include "ControlGraphics.h"
|
2002-01-16 14:47:58 +00:00
|
|
|
#include "ControlInset.tmpl"
|
2001-03-28 12:59:29 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "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
|
|
|
|
|
|
|
#include "insets/insetgraphics.h"
|
2001-04-26 18:40:38 +00:00
|
|
|
#include "insets/insetgraphicsParams.h" // need operator!=()
|
2001-03-28 12:59:29 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "support/FileInfo.h" // for FileInfo
|
|
|
|
#include "helper_funcs.h" // for browseFile
|
2002-01-29 09:26:24 +00:00
|
|
|
#include "support/lstrings.h"
|
2002-02-16 12:39:47 +00:00
|
|
|
#include "support/filetools.h" // for AddName, zippedFile
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
using std::pair;
|
|
|
|
using std::make_pair;
|
2002-01-29 09:26:24 +00:00
|
|
|
using std::ifstream;
|
|
|
|
|
2001-03-28 12:59:29 +00:00
|
|
|
ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
|
|
|
|
: ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
|
|
|
|
{
|
|
|
|
d_.showGraphics.connect(SigC::slot(this, &ControlGraphics::showInset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
bool changed = inset()->setParams(params());
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
string const ControlGraphics::Browse(string const & in_name)
|
|
|
|
{
|
2002-01-14 23:31:23 +00:00
|
|
|
string const title = N_("Graphics");
|
2001-03-30 09:51:46 +00:00
|
|
|
// FIXME: currently we need the second '|' to prevent mis-interpretation
|
2002-01-29 09:26:24 +00:00
|
|
|
string const pattern = "*.(ps|eps|png|jpeg|jpg|gif|gz)|";
|
2001-03-30 09:51:46 +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-01-13 15:01:25 +00:00
|
|
|
pair<string, string> dir1(N_("Clipart|#C#c"), clipdir);
|
2002-01-30 19:14:09 +00:00
|
|
|
pair<string, string> dir2(N_("Documents|#o#O"), string(lyxrc.document_path));
|
2001-03-30 09:51:46 +00:00
|
|
|
// Show the file browser dialog
|
2002-01-30 19:14:09 +00:00
|
|
|
return browseFile(&lv_, in_name, title, pattern, dir1, dir2);
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
2002-01-29 09:26:24 +00:00
|
|
|
|
|
|
|
string const ControlGraphics::readBB(string const & file)
|
|
|
|
{
|
|
|
|
// in a file it's an entry like %%BoundingBox:23 45 321 345
|
|
|
|
// the first number can following without a space, so we have
|
|
|
|
// to check a bit more.
|
2002-02-01 09:57:44 +00:00
|
|
|
// on the other hand some plot programs write the bb at the
|
|
|
|
// end of the file. Than we have in the header a
|
|
|
|
// %%BoundingBox: (atend)
|
|
|
|
// In this case we must check until the end.
|
2002-02-07 19:37:34 +00:00
|
|
|
string file_ = file;
|
|
|
|
if (zippedFile(file_))
|
|
|
|
file_ = unzipFile(file_);
|
|
|
|
std::ifstream is(file_.c_str());
|
|
|
|
if (!contains(getExtFromContents(file_),"ps")) // bb exists?
|
2002-02-01 09:57:44 +00:00
|
|
|
return string();
|
|
|
|
while (is) {
|
2002-01-29 09:26:24 +00:00
|
|
|
string s;
|
|
|
|
is >> s;
|
|
|
|
if (contains(s,"%%BoundingBox:")) {
|
|
|
|
string a, b, c, d;
|
|
|
|
is >> a >> b >> c >> d;
|
2002-02-01 09:57:44 +00:00
|
|
|
if (is && !contains(a,"atend")) { // bb at the end?
|
2002-01-29 09:26:24 +00:00
|
|
|
if (s != "%%BoundingBox:")
|
|
|
|
return (s.substr(14)+" "+a+" "+b+" "+c+" ");
|
|
|
|
else
|
|
|
|
return (a+" "+b+" "+c+" "+d+" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|