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"
31 #include "insets/insetgraphics.h"
32 #include "insets/insetgraphicsParams.h" // need operator!=()
34 #include "support/FileInfo.h" // for FileInfo
35 #include "helper_funcs.h" // for browseFile
36 #include "support/lstrings.h"
37 #include "support/filetools.h" // for AddName
38 #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);
98 // Show the file browser dialog
99 return browseFile(&lv_, in_name, title, pattern, dir1);
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 // ControlGraphics::bbChanged = false;
108 std::ifstream is(file.c_str());
112 if (contains(s,"%%BoundingBox:")) {
114 is >> a >> b >> c >> d;
116 if (s != "%%BoundingBox:")
117 return (s.substr(14)+" "+a+" "+b+" "+c+" ");
119 return (a+" "+b+" "+c+" "+d+" ");
126 void ControlGraphics::help() const
128 lv_.getDialogs()->showFile(i18nLibFileSearch("help","Graphics.hlp"));