]> git.lyx.org Git - features.git/blob - src/frontends/controllers/ControlGraphics.C
Remove all unnecessary #includes from header files.
[features.git] / src / frontends / controllers / ControlGraphics.C
1 /**
2  * \file ControlGraphics.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Herbert Voß
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "ControlGraphics.h"
15
16 #include "helper_funcs.h"
17
18 #include "funcrequest.h"
19 #include "gettext.h"
20 #include "lyxrc.h"
21
22 #include "graphics/GraphicsCache.h"
23 #include "graphics/GraphicsCacheItem.h"
24 #include "graphics/GraphicsImage.h"
25
26 #include "insets/insetgraphics.h"
27
28 #include "support/FileInfo.h"
29 #include "support/filetools.h"
30 #include "support/path_defines.h"
31 #include "support/tostr.h"
32 #include "support/types.h"
33
34 using namespace lyx::support;
35
36 using std::pair;
37 using std::make_pair;
38 using std::vector;
39
40
41 ControlGraphics::ControlGraphics(Dialog & parent)
42         : Dialog::Controller(parent)
43 {}
44
45
46 bool ControlGraphics::initialiseParams(string const & data)
47 {
48         InsetGraphicsParams params;
49         InsetGraphicsMailer::string2params(data, kernel().buffer(), params);
50         params_.reset(new InsetGraphicsParams(params));
51         return true;
52 }
53
54
55 void ControlGraphics::clearParams()
56 {
57         params_.reset();
58 }
59
60
61 void ControlGraphics::dispatchParams()
62 {
63         InsetGraphicsParams tmp_params(params());
64         string const lfun =
65                 InsetGraphicsMailer::params2string(tmp_params, kernel().buffer());
66         kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
67 }
68
69
70 string const ControlGraphics::Browse(string const & in_name)
71 {
72         string const title = _("Select graphics file");
73
74         // Does user clipart directory exist?
75         string clipdir = AddName (user_lyxdir(), "clipart");
76         FileInfo fileInfo(clipdir);
77         if (!(fileInfo.isOK() && fileInfo.isDir()))
78                 // No - bail out to system clipart directory
79                 clipdir = AddName (system_lyxdir(), "clipart");
80         pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
81         pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
82         // Show the file browser dialog
83         return browseRelFile(in_name, kernel().bufferFilepath(),
84                              title, "*.*", false, dir1, dir2);
85 }
86
87
88 string const ControlGraphics::readBB(string const & file)
89 {
90         string const abs_file =
91                 MakeAbsPath(file, kernel().bufferFilepath());
92
93         // try to get it from the file, if possible. Zipped files are
94         // unzipped in the readBB_from_PSFile-Function
95         string const bb = readBB_from_PSFile(abs_file);
96         if (!bb.empty())
97                 return bb;
98
99         // we don't, so ask the Graphics Cache if it has loaded the file
100         int width = 0;
101         int height = 0;
102
103         lyx::graphics::Cache & gc = lyx::graphics::Cache::get();
104         if (gc.inCache(abs_file)) {
105                 lyx::graphics::Image const * image = gc.item(abs_file)->image();
106
107                 if (image) {
108                         width  = image->getWidth();
109                         height = image->getHeight();
110                 }
111         }
112
113         return ("0 0 " + tostr(width) + ' ' + tostr(height));
114 }
115
116
117 bool ControlGraphics::isFilenameValid(string const & fname) const
118 {
119         // It may be that the filename is relative.
120         string const name = MakeAbsPath(fname, kernel().bufferFilepath());
121         return IsFileReadable(name);
122 }
123
124
125 namespace frnt {
126
127 namespace {
128
129 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
130 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
131
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
134 // end of each line.
135 char const * const rorigin_lyx_strs[] = {
136         // the LaTeX default is leftBaseline
137         "",
138         "leftTop",  "leftBottom", "leftBaseline", // lt lb lB
139         "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
140         "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
141
142 // These are the strings, corresponding to the above, that the GUI should
143 // use. Note that they can/should be translated.
144 char const * const rorigin_gui_strs[] = {
145         N_("Default"),
146         N_("Top left"), N_("Bottom left"), N_("Baseline left"),
147         N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
148         N_("Top right"), N_("Bottom right"), N_("Baseline right") };
149
150 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
151
152 } // namespace anon
153
154
155 vector<string> const getBBUnits()
156 {
157         return vector<string> (bb_units, bb_units + bb_size);
158 }
159
160
161 vector<RotationOriginPair> getRotationOriginData()
162 {
163         static vector<RotationOriginPair> data;
164         if (!data.empty())
165                 return data;
166
167         data.resize(rorigin_size);
168         for (lyx::size_type i = 0; i < rorigin_size; ++i) {
169                 data[i] = make_pair(_(rorigin_gui_strs[i]),
170                                     rorigin_lyx_strs[i]);
171         }
172
173         return data;
174 }
175
176 } // namespace frnt