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"
36 #include "insets/insetgraphics.h"
37 #include "insets/insetgraphicsParams.h"
39 #include "support/lstrings.h"
40 #include "support/filetools.h"
41 #include "support/FileInfo.h"
47 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
48 : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
52 InsetGraphicsParams const ControlGraphics::getParams(string const &)
54 return InsetGraphicsParams();
58 InsetGraphicsParams const
59 ControlGraphics::getParams(InsetGraphics const & inset)
61 return inset.params();
65 void ControlGraphics::applyParamsToInset()
67 // Set the parameters in the inset, it also returns true if the new
68 // parameters are different from what was in the inset already.
69 bool changed = inset()->setParams(params(), lv_.buffer()->filePath());
70 // Tell LyX we've got a change, and mark the document dirty,
72 lv_.view()->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, lv_.buffer()->filePath(),
99 title, "*.*", dir1, dir2);
103 string const ControlGraphics::readBB(string const & file)
105 string const abs_file = MakeAbsPath(file, lv_.buffer()->filePath());
107 string const from = getExtFromContents(abs_file);
108 // Check if we have a Postscript file, then it's easy
109 if (contains(from, "ps"))
110 return readBB_from_PSFile(abs_file);
112 // we don't, so ask the Graphics Cache if it has loaded the file
113 grfx::GCache & gc = grfx::GCache::get();
115 tostr(gc.raw_width(abs_file)) + ' ' +
116 tostr(gc.raw_height(abs_file)));
120 bool ControlGraphics::isFilenameValid(string const & fname) const
122 // It may be that the filename is relative.
123 string const name = MakeAbsPath(fname, lv_.buffer()->filePath());
124 return IsFileReadable(name);
132 // These are the strings that are stored in the LyX file and which
133 // correspond to the LaTeX identifiers shown in the comments at the
135 char const * const rorigin_lyx_strs[] = {
137 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
138 "centerTop", "centerBottom", "centerBaseline", // ct cb cB
139 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
141 // These are the strings, corresponding to the above, that the GUI should
142 // use. Note that they can/should be translated.
143 char const * const rorigin_gui_strs[] = {
145 N_("left top"), N_("left bottom"), N_("left baseline"),
146 N_("center top"), N_("center bottom"), N_("center baseline"),
147 N_("right top"), N_("right bottom"), N_("right baseline") };
149 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
154 vector<RotationOriginPair> getRotationOriginData()
156 static vector<RotationOriginPair> data;
160 data.resize(rorigin_size);
161 for (lyx::size_type i = 0; i < rorigin_size; ++i) {
162 data[i] = make_pair(_(rorigin_gui_strs[i]),
163 rorigin_lyx_strs[i]);