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/FileInfo.h"
29 #include "support/filetools.h"
30 #include "support/path_defines.h"
31 #include "support/tostr.h"
32 #include "support/types.h"
34 using namespace lyx::support;
42 ControlGraphics::ControlGraphics(Dialog & parent)
43 : Dialog::Controller(parent)
47 bool ControlGraphics::initialiseParams(string const & data)
49 InsetGraphicsParams params;
50 InsetGraphicsMailer::string2params(data, kernel().buffer(), params);
51 params_.reset(new InsetGraphicsParams(params));
56 void ControlGraphics::clearParams()
62 void ControlGraphics::dispatchParams()
64 InsetGraphicsParams tmp_params(params());
66 InsetGraphicsMailer::params2string(tmp_params, kernel().buffer());
67 kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
71 string const ControlGraphics::Browse(string const & in_name)
73 string const title = _("Select graphics file");
75 // Does user clipart directory exist?
76 string clipdir = AddName (user_lyxdir(), "clipart");
77 FileInfo fileInfo(clipdir);
78 if (!(fileInfo.isOK() && fileInfo.isDir()))
79 // No - bail out to system clipart directory
80 clipdir = AddName (system_lyxdir(), "clipart");
81 pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
82 pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
83 // Show the file browser dialog
84 return browseRelFile(in_name, kernel().bufferFilepath(),
85 title, "*.*", false, dir1, dir2);
89 string const ControlGraphics::readBB(string const & file)
91 string const abs_file =
92 MakeAbsPath(file, kernel().bufferFilepath());
94 // try to get it from the file, if possible. Zipped files are
95 // unzipped in the readBB_from_PSFile-Function
96 string const bb = readBB_from_PSFile(abs_file);
100 // we don't, so ask the Graphics Cache if it has loaded the file
104 lyx::graphics::Cache & gc = lyx::graphics::Cache::get();
105 if (gc.inCache(abs_file)) {
106 lyx::graphics::Image const * image = gc.item(abs_file)->image();
109 width = image->getWidth();
110 height = image->getHeight();
114 return ("0 0 " + tostr(width) + ' ' + tostr(height));
118 bool ControlGraphics::isFilenameValid(string const & fname) const
120 // It may be that the filename is relative.
121 string const name = MakeAbsPath(fname, kernel().bufferFilepath());
122 return IsFileReadable(name);
130 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
131 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
133 // These are the strings that are stored in the LyX file and which
134 // correspond to the LaTeX identifiers shown in the comments at the
136 char const * const rorigin_lyx_strs[] = {
137 // the LaTeX default is leftBaseline
139 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
140 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
141 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
143 // These are the strings, corresponding to the above, that the GUI should
144 // use. Note that they can/should be translated.
145 char const * const rorigin_gui_strs[] = {
147 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
148 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
149 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
151 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
156 vector<string> const getBBUnits()
158 return vector<string> (bb_units, bb_units + bb_size);
162 vector<RotationOriginPair> getRotationOriginData()
164 static vector<RotationOriginPair> data;
168 data.resize(rorigin_size);
169 for (lyx::size_type i = 0; i < rorigin_size; ++i) {
170 data[i] = make_pair(_(rorigin_gui_strs[i]),
171 rorigin_lyx_strs[i]);