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 "BufferView.h"
19 #include "funcrequest.h"
23 #include "graphics/GraphicsCache.h"
24 #include "graphics/GraphicsCacheItem.h"
25 #include "graphics/GraphicsImage.h"
27 #include "insets/insetgraphics.h"
28 #include "insets/insetgraphicsParams.h"
30 #include "support/tostr.h"
31 #include "support/filetools.h"
32 #include "support/FileInfo.h"
33 #include "support/path_defines.h"
35 using namespace lyx::support;
41 // We need these in the file browser.
42 extern string user_lyxdir;
45 ControlGraphics::ControlGraphics(Dialog & parent)
46 : Dialog::Controller(parent)
50 bool ControlGraphics::initialiseParams(string const & data)
52 InsetGraphicsParams params;
53 InsetGraphicsMailer::string2params(data, *kernel().buffer(), params);
54 params_.reset(new InsetGraphicsParams(params));
59 void ControlGraphics::clearParams()
65 void ControlGraphics::dispatchParams()
67 InsetGraphicsParams tmp_params(params());
69 InsetGraphicsMailer::params2string(tmp_params, *kernel().buffer());
70 kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
74 string const ControlGraphics::Browse(string const & in_name)
76 string const title = _("Select graphics file");
78 // Does user clipart directory exist?
79 string clipdir = AddName (user_lyxdir, "clipart");
80 FileInfo fileInfo(clipdir);
81 if (!(fileInfo.isOK() && fileInfo.isDir()))
82 // No - bail out to system clipart directory
83 clipdir = AddName (system_lyxdir(), "clipart");
84 pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
85 pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
86 // Show the file browser dialog
87 return browseRelFile(in_name, kernel().bufferFilepath(),
88 title, "*.*", false, dir1, dir2);
92 string const ControlGraphics::readBB(string const & file)
94 string const abs_file =
95 MakeAbsPath(file, kernel().bufferFilepath());
97 // try to get it from the file, if possible. Zipped files are
98 // unzipped in the readBB_from_PSFile-Function
99 string const bb = readBB_from_PSFile(abs_file);
103 // we don't, so ask the Graphics Cache if it has loaded the file
107 lyx::graphics::Cache & gc = lyx::graphics::Cache::get();
108 if (gc.inCache(abs_file)) {
109 lyx::graphics::Image const * image = gc.item(abs_file)->image();
112 width = image->getWidth();
113 height = image->getHeight();
117 return ("0 0 " + tostr(width) + ' ' + tostr(height));
121 bool ControlGraphics::isFilenameValid(string const & fname) const
123 // It may be that the filename is relative.
124 string const name = MakeAbsPath(fname, kernel().bufferFilepath());
125 return IsFileReadable(name);
133 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
134 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
136 // These are the strings that are stored in the LyX file and which
137 // correspond to the LaTeX identifiers shown in the comments at the
139 char const * const rorigin_lyx_strs[] = {
140 // the LaTeX default is leftBaseline
142 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
143 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
144 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
146 // These are the strings, corresponding to the above, that the GUI should
147 // use. Note that they can/should be translated.
148 char const * const rorigin_gui_strs[] = {
150 N_("Top left"), N_("Bottom left"), N_("Left baseline"),
151 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Center baseline"),
152 N_("Top right"), N_("Bottom right"), N_("Right baseline") };
154 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
159 vector<string> const getBBUnits()
161 return vector<string> (bb_units, bb_units + bb_size);
165 vector<RotationOriginPair> getRotationOriginData()
167 static vector<RotationOriginPair> data;
171 data.resize(rorigin_size);
172 for (lyx::size_type i = 0; i < rorigin_size; ++i) {
173 data[i] = make_pair(_(rorigin_gui_strs[i]),
174 rorigin_lyx_strs[i]);