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 <leeming@lyx.org>
12 * \author Herbert Voss <voss@perce.de>
18 #pragma implementation
21 #include "ControlGraphics.h"
23 #include "helper_funcs.h"
26 #include "BufferView.h"
27 #include "converter.h"
31 #include "graphics/GraphicsCache.h"
32 #include "graphics/GraphicsCacheItem.h"
33 #include "graphics/GraphicsImage.h"
35 #include "insets/insetgraphics.h"
36 #include "insets/insetgraphicsParams.h"
38 #include "support/lstrings.h"
39 #include "support/filetools.h"
40 #include "support/FileInfo.h"
46 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
47 : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
51 InsetGraphicsParams const ControlGraphics::getParams(string const &)
53 return InsetGraphicsParams();
57 InsetGraphicsParams const
58 ControlGraphics::getParams(InsetGraphics const & inset)
60 return inset.params();
64 void ControlGraphics::applyParamsToInset()
66 // Set the parameters in the inset, it also returns true if the new
67 // parameters are different from what was in the inset already.
68 bool changed = inset()->setParams(params(), buffer()->filePath());
70 // Tell LyX we've got a change, and mark the document dirty,
72 bufferview()->updateInset(inset(), changed);
76 void ControlGraphics::applyParamsNoInset()
80 // We need these in the file browser.
81 extern string system_lyxdir;
82 extern string user_lyxdir;
85 string const ControlGraphics::Browse(string const & in_name)
87 string const title = _("Select graphics file");
89 // Does user clipart directory exist?
90 string clipdir = AddName (user_lyxdir, "clipart");
91 FileInfo fileInfo(clipdir);
92 if (!(fileInfo.isOK() && fileInfo.isDir()))
93 // No - bail out to system clipart directory
94 clipdir = AddName (system_lyxdir, "clipart");
95 pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
96 pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
97 // Show the file browser dialog
98 return browseRelFile(&lv_, in_name, buffer()->filePath(),
99 title, "*.*", dir1, dir2);
103 string const ControlGraphics::readBB(string const & file)
105 string const abs_file = MakeAbsPath(file, buffer()->filePath());
107 // try to get it from the file, if possible. Zipped files are
108 // unzipped in the readBB_from_PSFile-Function
109 string const bb = readBB_from_PSFile(abs_file);
113 // we don't, so ask the Graphics Cache if it has loaded the file
117 grfx::Cache & gc = grfx::Cache::get();
118 if (gc.inCache(abs_file)) {
119 grfx::Image const * image = gc.item(abs_file)->image();
122 width = image->getWidth();
123 height = image->getHeight();
127 return ("0 0 " + tostr(width) + ' ' + tostr(height));
131 bool ControlGraphics::isFilenameValid(string const & fname) const
133 // It may be that the filename is relative.
134 string const name = MakeAbsPath(fname, buffer()->filePath());
135 return IsFileReadable(name);
143 // These are the strings that are stored in the LyX file and which
144 // correspond to the LaTeX identifiers shown in the comments at the
146 char const * const rorigin_lyx_strs[] = {
147 // the LaTeX default is leftBaseline
149 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
150 "centerTop", "centerBottom", "centerBaseline", // ct cb cB
151 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
153 // These are the strings, corresponding to the above, that the GUI should
154 // use. Note that they can/should be translated.
155 char const * const rorigin_gui_strs[] = {
157 N_("left top"), N_("left bottom"), N_("left baseline"),
158 N_("center top"), N_("center bottom"), N_("center baseline"),
159 N_("right top"), N_("right bottom"), N_("right baseline") };
161 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
166 vector<RotationOriginPair> getRotationOriginData()
168 static vector<RotationOriginPair> data;
172 data.resize(rorigin_size);
173 for (lyx::size_type i = 0; i < rorigin_size; ++i) {
174 data[i] = make_pair(_(rorigin_gui_strs[i]),
175 rorigin_lyx_strs[i]);