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