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
15 #include "ControlGraphics.h"
17 #include "helper_funcs.h"
20 #include "BufferView.h"
21 #include "funcrequest.h"
25 #include "graphics/GraphicsCache.h"
26 #include "graphics/GraphicsCacheItem.h"
27 #include "graphics/GraphicsImage.h"
29 #include "insets/insetgraphics.h"
30 #include "insets/insetgraphicsParams.h"
32 #include "support/lstrings.h"
33 #include "support/filetools.h"
34 #include "support/FileInfo.h"
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 InsetGraphicsParams params;
53 InsetGraphicsMailer::string2params(data, params);
54 params_.reset(new InsetGraphicsParams(params));
59 void ControlGraphics::clearParams()
65 void ControlGraphics::dispatchParams()
67 string const lfun = InsetGraphicsMailer::params2string(params());
68 kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
72 string const ControlGraphics::Browse(string const & in_name)
74 string const title = _("Select graphics file");
76 // Does user clipart directory exist?
77 string clipdir = AddName (user_lyxdir, "clipart");
78 FileInfo fileInfo(clipdir);
79 if (!(fileInfo.isOK() && fileInfo.isDir()))
80 // No - bail out to system clipart directory
81 clipdir = AddName (system_lyxdir, "clipart");
82 pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
83 pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
84 // Show the file browser dialog
85 return browseRelFile(in_name, kernel().buffer()->filePath(),
86 title, "*.*", false, dir1, dir2);
90 string const ControlGraphics::readBB(string const & file)
92 string const abs_file =
93 MakeAbsPath(file, kernel().buffer()->filePath());
95 // try to get it from the file, if possible. Zipped files are
96 // unzipped in the readBB_from_PSFile-Function
97 string const bb = readBB_from_PSFile(abs_file);
101 // we don't, so ask the Graphics Cache if it has loaded the file
105 grfx::Cache & gc = grfx::Cache::get();
106 if (gc.inCache(abs_file)) {
107 grfx::Image const * image = gc.item(abs_file)->image();
110 width = image->getWidth();
111 height = image->getHeight();
115 return ("0 0 " + tostr(width) + ' ' + tostr(height));
119 bool ControlGraphics::isFilenameValid(string const & fname) const
121 // It may be that the filename is relative.
122 string const name = MakeAbsPath(fname, kernel().buffer()->filePath());
123 return IsFileReadable(name);
131 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
132 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
134 // These are the strings that are stored in the LyX file and which
135 // correspond to the LaTeX identifiers shown in the comments at the
137 char const * const rorigin_lyx_strs[] = {
138 // the LaTeX default is leftBaseline
140 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
141 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
142 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
144 // These are the strings, corresponding to the above, that the GUI should
145 // use. Note that they can/should be translated.
146 char const * const rorigin_gui_strs[] = {
148 N_("Top left"), N_("Bottom left"), N_("Left baseline"),
149 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Center baseline"),
150 N_("Top right"), N_("Bottom right"), N_("Right baseline") };
152 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
157 vector<string> const getBBUnits()
159 return vector<string> (bb_units, bb_units + bb_size);
163 vector<RotationOriginPair> getRotationOriginData()
165 static vector<RotationOriginPair> data;
169 data.resize(rorigin_size);
170 for (lyx::size_type i = 0; i < rorigin_size; ++i) {
171 data[i] = make_pair(_(rorigin_gui_strs[i]),
172 rorigin_lyx_strs[i]);