2 * \file ControlGraphics.C
3 * Read the file COPYING
5 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
17 #include "ControlGraphics.h"
19 #include "helper_funcs.h"
22 #include "BufferView.h"
23 #include "converter.h"
27 #include "graphics/GraphicsCache.h"
28 #include "graphics/GraphicsCacheItem.h"
29 #include "graphics/GraphicsImage.h"
31 #include "insets/insetgraphics.h"
32 #include "insets/insetgraphicsParams.h"
34 #include "support/lstrings.h"
35 #include "support/filetools.h"
36 #include "support/FileInfo.h"
42 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
43 : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
47 InsetGraphicsParams const ControlGraphics::getParams(string const &)
49 return InsetGraphicsParams();
53 InsetGraphicsParams const
54 ControlGraphics::getParams(InsetGraphics const & inset)
56 return inset.params();
60 void ControlGraphics::applyParamsToInset()
62 // Set the parameters in the inset, it also returns true if the new
63 // parameters are different from what was in the inset already.
64 bool changed = inset()->setParams(params(), buffer()->filePath());
66 // Tell LyX we've got a change, and mark the document dirty,
68 bufferview()->updateInset(inset(), changed);
72 void ControlGraphics::applyParamsNoInset()
76 // We need these in the file browser.
77 extern string system_lyxdir;
78 extern string user_lyxdir;
81 string const ControlGraphics::Browse(string const & in_name)
83 string const title = _("Select graphics file");
85 // Does user clipart directory exist?
86 string clipdir = AddName (user_lyxdir, "clipart");
87 FileInfo fileInfo(clipdir);
88 if (!(fileInfo.isOK() && fileInfo.isDir()))
89 // No - bail out to system clipart directory
90 clipdir = AddName (system_lyxdir, "clipart");
91 pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
92 pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
93 // Show the file browser dialog
94 return browseRelFile(&lv_, in_name, buffer()->filePath(),
95 title, "*.*", dir1, dir2);
99 string const ControlGraphics::readBB(string const & file)
101 string const abs_file = MakeAbsPath(file, buffer()->filePath());
103 // try to get it from the file, if possible. Zipped files are
104 // unzipped in the readBB_from_PSFile-Function
105 string const bb = readBB_from_PSFile(abs_file);
109 // we don't, so ask the Graphics Cache if it has loaded the file
113 grfx::Cache & gc = grfx::Cache::get();
114 if (gc.inCache(abs_file)) {
115 grfx::Image const * image = gc.item(abs_file)->image();
118 width = image->getWidth();
119 height = image->getHeight();
123 return ("0 0 " + tostr(width) + ' ' + tostr(height));
127 bool ControlGraphics::isFilenameValid(string const & fname) const
129 // It may be that the filename is relative.
130 string const name = MakeAbsPath(fname, buffer()->filePath());
131 return IsFileReadable(name);
139 // These are the strings that are stored in the LyX file and which
140 // correspond to the LaTeX identifiers shown in the comments at the
142 char const * const rorigin_lyx_strs[] = {
143 // the LaTeX default is leftBaseline
144 "leftBaseline", "leftTop", "leftBottom", // lB lt lb
145 "center", "centerBaseline", "centerTop", "centerBottom", // c cB ct cb
146 "rightBaseline", "rightTop", "rightBottom" }; // 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[] = {
151 N_("left baseline"), N_("left top"), N_("left bottom"),
152 N_("center"), N_("center baseline"), N_("center top"), N_("center bottom"),
153 N_("right baseline"), N_("right top"), N_("right bottom") };
155 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
160 vector<RotationOriginPair> getRotationOriginData()
162 static vector<RotationOriginPair> data;
166 data.resize(rorigin_size);
167 for (lyx::size_type i = 0; i < rorigin_size; ++i) {
168 data[i] = make_pair(_(rorigin_gui_strs[i]),
169 rorigin_lyx_strs[i]);