1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
10 * \file ControlGraphics.C
11 * \author Angus Leeming <a.leeming@ic.ac.uk>
12 * \author Herbert Voss <voss@perce.de>
18 #pragma implementation
21 #include "ControlGraphics.h"
23 #include "helper_funcs.h"
25 #include "converter.h"
27 #include "BufferView.h"
29 #include "frontends/LyXView.h"
33 #include "graphics/GraphicsCache.h"
34 #include "graphics/GraphicsCacheItem.h"
35 #include "graphics/GraphicsImage.h"
37 #include "insets/insetgraphics.h"
38 #include "insets/insetgraphicsParams.h"
40 #include "support/lstrings.h"
41 #include "support/filetools.h"
42 #include "support/FileInfo.h"
48 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
49 : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
53 InsetGraphicsParams const ControlGraphics::getParams(string const &)
55 return InsetGraphicsParams();
59 InsetGraphicsParams const
60 ControlGraphics::getParams(InsetGraphics const & inset)
62 return inset.params();
66 void ControlGraphics::applyParamsToInset()
68 // Set the parameters in the inset, it also returns true if the new
69 // parameters are different from what was in the inset already.
70 bool changed = inset()->setParams(params(), lv_.buffer()->filePath());
72 // Tell LyX we've got a change, and mark the document dirty,
74 lv_.view()->updateInset(inset(), changed);
78 void ControlGraphics::applyParamsNoInset()
82 // We need these in the file browser.
83 extern string system_lyxdir;
84 extern string user_lyxdir;
87 string const ControlGraphics::Browse(string const & in_name)
89 string const title = _("Select graphics file");
91 // Does user clipart directory exist?
92 string clipdir = AddName (user_lyxdir, "clipart");
93 FileInfo fileInfo(clipdir);
94 if (!(fileInfo.isOK() && fileInfo.isDir()))
95 // No - bail out to system clipart directory
96 clipdir = AddName (system_lyxdir, "clipart");
97 pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
98 pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
99 // Show the file browser dialog
100 return browseRelFile(&lv_, in_name, lv_.buffer()->filePath(),
101 title, "*.*", dir1, dir2);
105 string const ControlGraphics::readBB(string const & file)
107 string const abs_file = MakeAbsPath(file, lv_.buffer()->filePath());
109 // try to get it from the file, if possible. Zipped files are
110 // unzipped in the readBB_from_PSFile-Function
111 string const bb = readBB_from_PSFile(abs_file);
115 // we don't, so ask the Graphics Cache if it has loaded the file
119 grfx::Cache & gc = grfx::Cache::get();
120 if (gc.inCache(abs_file)) {
121 grfx::Image const * image = gc.item(abs_file)->image();
124 width = image->getWidth();
125 height = image->getHeight();
129 return ("0 0 " + tostr(width) + ' ' + tostr(height));
133 bool ControlGraphics::isFilenameValid(string const & fname) const
135 // It may be that the filename is relative.
136 string const name = MakeAbsPath(fname, lv_.buffer()->filePath());
137 return IsFileReadable(name);
145 // These are the strings that are stored in the LyX file and which
146 // correspond to the LaTeX identifiers shown in the comments at the
148 char const * const rorigin_lyx_strs[] = {
149 // the LaTeX default is leftBaseline
151 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
152 "centerTop", "centerBottom", "centerBaseline", // ct cb cB
153 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
155 // These are the strings, corresponding to the above, that the GUI should
156 // use. Note that they can/should be translated.
157 char const * const rorigin_gui_strs[] = {
159 N_("left top"), N_("left bottom"), N_("left baseline"),
160 N_("center top"), N_("center bottom"), N_("center baseline"),
161 N_("right top"), N_("right bottom"), N_("right baseline") };
163 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
168 vector<RotationOriginPair> getRotationOriginData()
170 static vector<RotationOriginPair> data;
174 data.resize(rorigin_size);
175 for (lyx::size_type i = 0; i < rorigin_size; ++i) {
176 data[i] = make_pair(_(rorigin_gui_strs[i]),
177 rorigin_lyx_strs[i]);