]> git.lyx.org Git - lyx.git/blob - src/insets/insetlatex.C
the runlatex merge
[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.fillRectangle(gc_lighted, int(x), baseline - Ascent(font) +1 ,
68                           Width(font) - 2, Ascent(font) + Descent(font) -2);
69         
70         scr.drawRectangle(gc_foot,int(x), baseline - Ascent(font) + 1,
71                           Width(font)-2, Ascent(font)+Descent(font)-2);
72         
73         scr.drawString(font, contents, baseline, int(x+2));
74         x +=  Width(font) - 1;
75 }
76
77
78 void InsetLatex::Write(FILE * file)
79 {
80         fprintf(file, "Latex %s\n", contents.c_str());
81 }
82
83
84 void InsetLatex::Read(LyXLex & lex)
85 {
86         FILE * file = lex.getFile();
87         char c = 0;
88         string tmp;
89         while (!feof(file) && (c = fgetc(file)) != '\n') {
90                 tmp += char(c);
91         }
92         contents = tmp;
93 }
94
95
96 int InsetLatex::Latex(FILE * file, signed char /*fragile*/)
97 {
98         fprintf(file, "%s", contents.c_str());
99         return 0;
100 }
101
102
103 int InsetLatex::Latex(string & file, signed char /*fragile*/)
104 {
105         file += contents;
106         return 0;
107 }
108
109
110 int InsetLatex::Linuxdoc(string & file)
111 {
112         file += contents;
113         return 0;
114 }
115
116
117 int InsetLatex::DocBook(string & file)
118 {
119         file += contents;
120         return 0;
121 }
122
123
124 bool InsetLatex::Deletable() const
125 {
126         return false;
127 }
128
129
130 Inset * InsetLatex::Clone()
131 {
132         InsetLatex * result = new InsetLatex(contents);
133         return result;
134 }
135
136
137 Inset::Code InsetLatex::LyxCode() const
138 {
139         if (contents == "\\tableofcontents") return Inset::TOC_CODE;
140         return Inset::NO_CODE;
141 }