]> git.lyx.org Git - lyx.git/blob - src/insets/insetlatex.C
5dbce1539056d240e5d8130fdd10ff19fdfa4183
[lyx.git] / src / insets / insetlatex.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-1999 The LyX Team.
8  *
9  *======================================================*/
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "definitions.h"
18 #include "insetlatex.h"
19 #include "lyxdraw.h"
20
21 /* Latex. Used to insert Latex-Code automatically */
22
23
24 InsetLatex::InsetLatex()
25 {
26 }
27
28
29 InsetLatex::InsetLatex(string const & string)
30         : contents(string)
31 {
32 }
33
34
35 InsetLatex::~InsetLatex()
36 {
37 }
38
39
40 int InsetLatex::Ascent(LyXFont const &font) const
41 {
42         return font.maxAscent() + 1;
43 }
44
45
46 int InsetLatex::Descent(LyXFont const &font) const
47 {
48         return font.maxDescent() + 1;
49 }
50
51
52 int InsetLatex::Width(LyXFont const &font) const
53 {
54         return 6 + font.stringWidth(contents);
55 }
56
57
58 void InsetLatex::Draw(LyXFont font, LyXScreen &scr,
59                       int baseline, float &x)
60 {
61         // Latex-insets are always LaTeX, so just correct the font */ 
62         font.setLatex(LyXFont::ON);
63
64         // Draw it as a box with the LaTeX text
65         x += 1;
66
67         //scr.drawFilledRectangle(int(x), baseline - Ascent(font) + 1,
68         //           Width(font)-2, Ascent(font) + Descent(font)-2,
69         //           FL_GRAY80);
70         scr.fillRectangle(gc_lighted, int(x), baseline - Ascent(font) +1 ,
71                           Width(font) - 2, Ascent(font) + Descent(font) -2);
72         
73         //scr.drawRectangle(int(x), baseline - Ascent(font) + 1,
74         //           Width(font)-2, Ascent(font)+Descent(font)-2,
75         //           FL_RED);
76         scr.drawRectangle(gc_foot,int(x), baseline - Ascent(font) + 1,
77                           Width(font)-2, Ascent(font)+Descent(font)-2);
78         
79         scr.drawString(font, contents, baseline, int(x+2));
80         x +=  Width(font) - 1;
81 }
82
83
84 void InsetLatex::Write(FILE *file)
85 {
86         fprintf(file, "Latex %s\n", contents.c_str());
87 }
88
89
90 void InsetLatex::Read(LyXLex &lex)
91 {
92         FILE *file = lex.getFile();
93         int i = 0;
94         char c='\0';
95         char tmp[100];
96         while (!feof(file) && (c = fgetc(file)) != '\n') {
97                 tmp[i]=c;
98                 i++;
99         }
100         tmp[i]='\0';
101         contents = tmp;
102 }
103
104
105 int InsetLatex::Latex(FILE *file, signed char /*fragile*/)
106 {
107         fprintf(file, "%s", contents.c_str());
108         return 0;
109 }
110
111
112 int InsetLatex::Latex(string &file, signed char /*fragile*/)
113 {
114         file += contents;
115         return 0;
116 }
117
118
119 int InsetLatex::Linuxdoc(string &file)
120 {
121         file += contents;
122         return 0;
123 }
124
125
126 int InsetLatex::DocBook(string &file)
127 {
128         file += contents;
129         return 0;
130 }
131
132
133 bool InsetLatex::Deletable() const
134 {
135         return false;
136 }
137
138
139 Inset* InsetLatex::Clone()
140 {
141         InsetLatex *result = new InsetLatex(contents);
142         return result;
143 }
144
145
146 Inset::Code InsetLatex::LyxCode() const
147 {
148         if (contents == "\\tableofcontents") return Inset::TOC_CODE;
149         return Inset::NO_CODE;
150 }