2 * \file ControlGraphics.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
14 #include "ControlGraphics.h"
16 #include "helper_funcs.h"
18 #include "funcrequest.h"
22 #include "graphics/GraphicsCache.h"
23 #include "graphics/GraphicsCacheItem.h"
24 #include "graphics/GraphicsImage.h"
26 #include "insets/insetgraphics.h"
28 #include "support/convert.h"
29 #include "support/filefilterlist.h"
30 #include "support/filetools.h"
31 #include "support/package.h"
32 #include "support/types.h"
34 #include <boost/filesystem/operations.hpp>
41 namespace fs = boost::filesystem;
45 using support::addName;
46 using support::FileFilterList;
47 using support::FileName;
48 using support::isFileReadable;
49 using support::makeAbsPath;
50 using support::package;
51 using support::readBB_from_PSFile;
56 ControlGraphics::ControlGraphics(Dialog & parent)
57 : Dialog::Controller(parent)
61 bool ControlGraphics::initialiseParams(string const & data)
63 InsetGraphicsParams params;
64 InsetGraphicsMailer::string2params(data, kernel().buffer(), params);
65 params_.reset(new InsetGraphicsParams(params));
70 void ControlGraphics::clearParams()
76 void ControlGraphics::dispatchParams()
78 InsetGraphicsParams tmp_params(params());
80 InsetGraphicsMailer::params2string(tmp_params, kernel().buffer());
81 kernel().dispatch(FuncRequest(getLfun(), lfun));
85 docstring const ControlGraphics::browse(docstring const & in_name) const
87 docstring const title = _("Select graphics file");
89 // Does user clipart directory exist?
90 string clipdir = addName(package().user_support(), "clipart");
91 if (!(fs::exists(clipdir) && fs::is_directory(clipdir)))
92 // No - bail out to system clipart directory
93 clipdir = addName(package().system_support(), "clipart");
94 pair<docstring, docstring> dir1(_("Clipart|#C#c"), lyx::from_utf8(clipdir));
95 pair<docstring, docstring> dir2(_("Documents|#o#O"), lyx::from_utf8(lyxrc.document_path));
96 // Show the file browser dialog
97 return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
104 string const ControlGraphics::readBB(string const & file)
106 FileName const abs_file(makeAbsPath(file, kernel().bufferFilepath()));
108 // try to get it from the file, if possible. Zipped files are
109 // unzipped in the readBB_from_PSFile-Function
110 string const bb = readBB_from_PSFile(abs_file);
114 // we don't, so ask the Graphics Cache if it has loaded the file
118 graphics::Cache & gc = graphics::Cache::get();
119 if (gc.inCache(abs_file)) {
120 graphics::Image const * image = gc.item(abs_file)->image();
123 width = image->getWidth();
124 height = image->getHeight();
128 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
132 bool ControlGraphics::isFilenameValid(string const & fname) const
134 // It may be that the filename is relative.
135 FileName const name(makeAbsPath(fname, kernel().bufferFilepath()));
136 return isFileReadable(name);
140 void ControlGraphics::editGraphics()
142 BOOST_ASSERT(params_.get());
144 dialog().view().apply();
146 InsetGraphicsMailer::params2string(params(), kernel().buffer());
147 kernel().dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
153 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
154 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
156 // These are the strings that are stored in the LyX file and which
157 // correspond to the LaTeX identifiers shown in the comments at the
159 char const * const rorigin_lyx_strs[] = {
160 // the LaTeX default is leftBaseline
162 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
163 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
164 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
166 // These are the strings, corresponding to the above, that the GUI should
167 // use. Note that they can/should be translated.
168 char const * const rorigin_gui_strs[] = {
170 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
171 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
172 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
174 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
179 vector<string> const getBBUnits()
181 return vector<string>(bb_units, bb_units + bb_size);
185 vector<RotationOriginPair> getRotationOriginData()
187 static vector<RotationOriginPair> data;
191 data.resize(rorigin_size);
192 for (size_type i = 0; i < rorigin_size; ++i) {
194 data[i] = make_pair(lyx::to_utf8(_(rorigin_gui_strs[i])),
195 rorigin_lyx_strs[i]);
201 } // namespace frontend