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