1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
10 * \file ControlGraphics.C
11 * \author Angus Leeming <a.leeming@ic.ac.uk>
12 * \author Herbert Voss <voss@perce.de>
19 #pragma implementation
23 #include "ButtonControllerBase.h"
24 #include "ControlGraphics.h"
25 #include "ControlInset.tmpl"
32 #include "insets/insetgraphics.h"
33 #include "insets/insetgraphicsParams.h" // need operator!=()
35 #include "support/FileInfo.h" // for FileInfo
36 #include "helper_funcs.h" // for browseFile
37 #include "support/lstrings.h"
38 #include "support/filetools.h" // for AddName
39 #include "BufferView.h"
45 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
46 : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
48 d_.showGraphics.connect(SigC::slot(this, &ControlGraphics::showInset));
52 InsetGraphicsParams const ControlGraphics::getParams(string const &)
54 return InsetGraphicsParams();
58 InsetGraphicsParams const
59 ControlGraphics::getParams(InsetGraphics const & inset)
61 return inset.getParams();
65 void ControlGraphics::applyParamsToInset()
67 // Set the parameters in the inset, it also returns true if the new
68 // parameters are different from what was in the inset already.
69 bool changed = inset()->setParams(params());
70 // Tell LyX we've got a change, and mark the document dirty,
72 lv_.view()->updateInset(inset(), changed);
76 void ControlGraphics::applyParamsNoInset()
80 // We need these in the file browser.
81 extern string system_lyxdir;
82 extern string user_lyxdir;
84 string const ControlGraphics::Browse(string const & in_name)
86 string const title = N_("Graphics");
87 // FIXME: currently we need the second '|' to prevent mis-interpretation
88 string const pattern = "*.(ps|eps|png|jpeg|jpg|gif|gz)|";
90 // Does user clipart directory exist?
91 string clipdir = AddName (user_lyxdir, "clipart");
92 FileInfo fileInfo(clipdir);
93 if (!(fileInfo.isOK() && fileInfo.isDir()))
94 // No - bail out to system clipart directory
95 clipdir = AddName (system_lyxdir, "clipart");
96 pair<string, string> dir1(N_("Clipart|#C#c"), clipdir);
97 pair<string, string> dir2(N_("Documents|#o#O"), string(lyxrc.document_path));
98 // Show the file browser dialog
99 return browseFile(&lv_, in_name, title, pattern, dir1, dir2);
102 string const ControlGraphics::readBB(string const & file)
104 // in a file it's an entry like %%BoundingBox:23 45 321 345
105 // the first number can following without a space, so we have
106 // to check a bit more.
107 // on the other hand some plot programs write the bb at the
108 // end of the file. Than we have in the header a
109 // %%BoundingBox: (atend)
110 // In this case we must check until the end.
111 std::ifstream is(file.c_str());
112 if (!contains(getExtFromContents(file),"ps")) // bb exists?
117 if (contains(s,"%%BoundingBox:")) {
119 is >> a >> b >> c >> d;
120 if (is && !contains(a,"atend")) { // bb at the end?
121 if (s != "%%BoundingBox:")
122 return (s.substr(14)+" "+a+" "+b+" "+c+" ");
124 return (a+" "+b+" "+c+" "+d+" ");
131 void ControlGraphics::help() const
133 lv_.getDialogs()->showFile(i18nLibFileSearch("help","Graphics.hlp"));