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"
34 using namespace lyx::support;
40 // We need these in the file browser.
41 extern string system_lyxdir;
42 extern string user_lyxdir;
45 ControlGraphics::ControlGraphics(Dialog & parent)
46 : Dialog::Controller(parent)
50 bool ControlGraphics::initialiseParams(string const & data)
52 string const bufpath = kernel().bufferFilepath();
53 InsetGraphicsParams params;
54 InsetGraphicsMailer::string2params(data, bufpath, params);
55 params_.reset(new InsetGraphicsParams(params));
60 void ControlGraphics::clearParams()
66 void ControlGraphics::dispatchParams()
68 string const buffer_path = kernel().bufferFilepath();
69 InsetGraphicsParams tmp_params(params());
71 InsetGraphicsMailer::params2string(tmp_params, buffer_path);
72 kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
76 string const ControlGraphics::Browse(string const & in_name)
78 string const title = _("Select graphics file");
80 // Does user clipart directory exist?
81 string clipdir = AddName (user_lyxdir, "clipart");
82 FileInfo fileInfo(clipdir);
83 if (!(fileInfo.isOK() && fileInfo.isDir()))
84 // No - bail out to system clipart directory
85 clipdir = AddName (system_lyxdir, "clipart");
86 pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
87 pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
88 // Show the file browser dialog
89 return browseRelFile(in_name, kernel().bufferFilepath(),
90 title, "*.*", false, dir1, dir2);
94 string const ControlGraphics::readBB(string const & file)
96 string const abs_file =
97 MakeAbsPath(file, kernel().bufferFilepath());
99 // try to get it from the file, if possible. Zipped files are
100 // unzipped in the readBB_from_PSFile-Function
101 string const bb = readBB_from_PSFile(abs_file);
105 // we don't, so ask the Graphics Cache if it has loaded the file
109 lyx::graphics::Cache & gc = lyx::graphics::Cache::get();
110 if (gc.inCache(abs_file)) {
111 lyx::graphics::Image const * image = gc.item(abs_file)->image();
114 width = image->getWidth();
115 height = image->getHeight();
119 return ("0 0 " + tostr(width) + ' ' + tostr(height));
123 bool ControlGraphics::isFilenameValid(string const & fname) const
125 // It may be that the filename is relative.
126 string const name = MakeAbsPath(fname, kernel().bufferFilepath());
127 return IsFileReadable(name);
135 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
136 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
138 // These are the strings that are stored in the LyX file and which
139 // correspond to the LaTeX identifiers shown in the comments at the
141 char const * const rorigin_lyx_strs[] = {
142 // the LaTeX default is leftBaseline
144 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
145 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
146 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
148 // These are the strings, corresponding to the above, that the GUI should
149 // use. Note that they can/should be translated.
150 char const * const rorigin_gui_strs[] = {
152 N_("Top left"), N_("Bottom left"), N_("Left baseline"),
153 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Center baseline"),
154 N_("Top right"), N_("Bottom right"), N_("Right baseline") };
156 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
161 vector<string> const getBBUnits()
163 return vector<string> (bb_units, bb_units + bb_size);
167 vector<RotationOriginPair> getRotationOriginData()
169 static vector<RotationOriginPair> data;
173 data.resize(rorigin_size);
174 for (lyx::size_type i = 0; i < rorigin_size; ++i) {
175 data[i] = make_pair(_(rorigin_gui_strs[i]),
176 rorigin_lyx_strs[i]);