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/GraphicsConverter.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());
71 // Tell LyX we've got a change, and mark the document dirty,
73 lv_.view()->updateInset(inset(), changed);
77 void ControlGraphics::applyParamsNoInset()
81 // We need these in the file browser.
82 extern string system_lyxdir;
83 extern string user_lyxdir;
86 string const ControlGraphics::Browse(string const & in_name)
88 string const title = _("Select graphics file");
90 // Does user clipart directory exist?
91 string clipdir = AddName (user_lyxdir, "clipart");
92 FileInfo fileInfo(clipdir);
93 if (!(fileInfo.isOK() && fileInfo.isDir()))
94 // No - bail out to system clipart directory
95 clipdir = AddName (system_lyxdir, "clipart");
96 pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
97 pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
98 // Show the file browser dialog
99 return browseRelFile(&lv_, in_name, lv_.buffer()->filePath(),
100 title, "*.*", dir1, dir2);
104 string const ControlGraphics::readBB(string const & file)
106 string const abs_file = MakeAbsPath(file, lv_.buffer()->filePath());
108 string const from = getExtFromContents(abs_file);
109 // Check if we have a Postscript file, then it's easy
110 if (contains(from, "ps"))
111 return readBB_from_PSFile(abs_file);
113 // we don't, so ask the Graphics Cache if it has loaded the file
117 grfx::GCache & gc = grfx::GCache::get();
118 grfx::ImagePtr const image = gc.image(abs_file);
121 width = image->getWidth();
122 height = image->getHeight();
125 return ("0 0 " + tostr(width) + ' ' + tostr(height));
129 bool ControlGraphics::isFilenameValid(string const & fname) const
131 // It may be that the filename is relative.
132 string const name = MakeAbsPath(fname, lv_.buffer()->filePath());
133 return IsFileReadable(name);
141 // These are the strings that are stored in the LyX file and which
142 // correspond to the LaTeX identifiers shown in the comments at the
144 char const * const rorigin_lyx_strs[] = {
146 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
147 "centerTop", "centerBottom", "centerBaseline", // ct cb cB
148 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
150 // These are the strings, corresponding to the above, that the GUI should
151 // use. Note that they can/should be translated.
152 char const * const rorigin_gui_strs[] = {
154 N_("left top"), N_("left bottom"), N_("left baseline"),
155 N_("center top"), N_("center bottom"), N_("center baseline"),
156 N_("right top"), N_("right bottom"), N_("right baseline") };
158 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
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]);