]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
prepare for 1.1.6pre2
[lyx.git] / src / insets / insetgraphics.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 the LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef INSET_GRAPHICS_H
13 #define INSET_GRAPHICS_H
14
15
16 #ifdef __GNUG__
17 #pragma interface
18 #endif 
19
20 #include "insets/lyxinset.h"
21 #include "insets/insetgraphicsParams.h"
22 #include "graphics/GraphicsCacheItem.h"
23
24 #include "LaTeXFeatures.h"
25
26 // We need a signal here to hide an active dialog when we are deleted.
27 #include "sigc++/signal_system.h"
28 #ifdef SIGC_CXX_NAMESPACES
29 using SigC::Signal0;
30 using SigC::slot;
31 using SigC::Object;
32 #endif 
33
34 class Dialogs;
35 class LyXImage;
36
37 ///
38 #ifdef SIGC_CXX_NAMESPACES
39 class InsetGraphics : public Inset, public SigC::Object
40 #else
41 class InsetGraphics : public Inset, public Object
42 #endif
43 {
44 public:
45         ///
46         InsetGraphics();
47         ///
48         ~InsetGraphics();
49         ///
50         int ascent(BufferView *, LyXFont const &) const;
51         ///
52         int descent(BufferView *, LyXFont const &) const;
53         ///
54         int width(BufferView *, LyXFont const &) const;
55         ///
56         bool display() const { return true; }
57         ///
58         void draw(BufferView *, LyXFont const &, int, float &, bool) const;
59         ///
60         void Edit(BufferView *, int, int, unsigned int);
61         ///
62         EDITABLE Editable() const;
63         ///
64         void Write(Buffer const *, std::ostream &) const;
65         ///
66         void Read(Buffer const *, LyXLex & lex);
67
68         /** returns the number of rows (\n's) of generated tex code.
69          #fragile == true# means, that the inset should take care about
70          fragile commands by adding a #\protect# before.
71          */
72         int Latex(Buffer const *, std::ostream &,
73                   bool fragile, bool free_spc) const;
74         ///
75         int Ascii(Buffer const *, std::ostream &, int linelen) const;
76         ///
77         int Linuxdoc(Buffer const *, std::ostream &) const;
78         ///
79         int DocBook(Buffer const *, std::ostream &) const;
80
81         /** Tell LyX what the latex features you need i.e. what latex packages
82             you need to be included.
83          */
84         void Validate(LaTeXFeatures & features) const;
85
86         /// returns LyX code associated with the inset. Used for TOC, ...)
87         Inset::Code LyxCode() const { return Inset::GRAPHICS_CODE; }
88
89         ///
90         Inset * Clone(Buffer const &) const;
91
92         /** Set the inset parameters, used by the GUIndependent dialog.
93             Return true of new params are different from what was so far.
94         */
95         bool setParams(InsetGraphicsParams const & params);
96
97         /// Get the inset parameters, used by the GUIndependent dialog.
98         InsetGraphicsParams getParams() const;
99
100         /** This signal is connected by our dialog and called when the inset
101             is deleted.
102         */
103         Signal0 <void> hide;
104 private:
105         /// Update the inset after parameter change.
106         void updateInset() const;
107         /// Get the status message, depends on the image loading status.
108         char const * statusMessage() const;
109
110         /// The graphics cache handle.
111         mutable GraphicsCacheItem * cacheHandle;
112
113         /// The pixmap
114         mutable LyXImage * pixmap;
115         /// is the pixmap initialized?
116         mutable bool pixmapInitialized;
117
118         InsetGraphicsParams params;
119
120         // Baruch Even (baruch.even@writeme.com) 2000-07-17
121         // This was the intended way however it is not flexible enough and
122         // only provides for LaTeX output.
123 #ifdef IG_OLDPARAMS
124         // We need variables to store the size of the boundingbox and
125         // to store a pointer to the pixmap in.. The question is if
126         // these should be in a "pixmap" class.
127         // We also need to have variables about rotation and scaling,
128         // width and height. in effect all the paramters that
129         // \includegraphics can handle. (the graphix.sty package)
130
131         /** The "bounding box" of the graphics image. Its value field
132             must contain four dimensions, separated by spaces.  */
133         BoundingBox bb;
134         /** The bounding box above is used for display and file both.
135             But we need this variable below to know if we shall use the
136             bounding box in the LaTex command or not. (i.e. if the user
137             has manually set the bb.) */
138         bool use_bb;
139
140         /** When a graphics file is parsed we first check for BoundingBox
141             and then for HiResBoundingBox, and set hiresbb depending on this.
142             This key makes LaTeX search for %%HiResBoundingBox comments
143             instead of the normal %%BoundingBox. Some applications use
144             this to specify more precise bounding boxes, becase the numbers
145             can normally only have integer values. It is a Boolean, either
146             "true" or "false". */
147         bool hiresbb;
148
149         /** This key takes four arguments (like bb), but in this case the
150             origin is taken with respect to the bounding box specified in
151             the file. So to view a 20 bp square at the lower left-hand corner
152             of the picture, specify viewport=0 0 20 20. */
153         BoundingBox viewport;
154
155         /** Similar to the viewport key, but the four dimensions correspond
156             to the amount of space to be trimmed (cut off) at the left-hand
157             side, bottom, right-hand side and top of the included graphics. */
158         BoundingBox trim;
159
160         /// Natural height of figure
161         LyXLength natheight;
162
163         /// Natural width of figure.
164         LyXLength natwidth;
165
166         /// Rotation angle (in degrees, counterclockwise).
167         float angle;
168
169         /** Origin for rotation, similar to the origin parameter of
170             the \rotatebox command described on p.46 and Fig. 2.2 on p.46. */
171         Origin origin;
172
173         /// Required width (the width of the image is scaled to that value).
174         LyXLength g_width;
175
176         /// Required height (the height of the image is scaled to that value).
177         LyXLength g_height;
178
179         /** Required total height (the total height of the image is scaled
180             to that value). This key should be used instead of height if
181             images are rotated over 90 degrees, since the height can
182             disappear (and become the depth) and LaTeX will have difficulties
183             satisfying the user's request. */
184         LyXLength totalheight;
185
186         /** Boolean variable that can have the values "true" and "false"
187             (se above for defaults). When true, specifying both width and
188             height parameters does not distort the picture, but the image
189             is scaled so that neither of the width of height exceeds the
190             given dimensions. */
191         bool keepaspectratio;
192
193         /// Scale factor
194         float scale;
195
196         /** Clip the graphic to the bounding box. It is a Boolean, either
197             "true" or "false". */
198         bool clip;
199
200         /// Locally switch to draft mode. A Boolean valued key, like clip.
201         bool draft;
202
203         /// The graphics type.
204         string type;
205
206         /// The file extension of the file containing the image data.
207         string ext;
208
209         /// The file extension of the file "read" by LaTeX.
210         string read;
211
212         /// Any command to be applied to the file.
213         string command;
214 #endif 
215 };
216
217 #endif