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