1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "insetlatex.h"
20 /* Latex. Used to insert Latex-Code automatically */
23 InsetLatex::InsetLatex()
28 InsetLatex::InsetLatex(string const & string)
34 InsetLatex::~InsetLatex()
39 int InsetLatex::Ascent(LyXFont const & font) const
41 return font.maxAscent() + 1;
45 int InsetLatex::Descent(LyXFont const & font) const
47 return font.maxDescent() + 1;
51 int InsetLatex::Width(LyXFont const & font) const
53 return 6 + font.stringWidth(contents);
57 void InsetLatex::Draw(LyXFont font, LyXScreen & scr,
58 int baseline, float & x)
60 // Latex-insets are always LaTeX, so just correct the font */
61 font.setLatex(LyXFont::ON);
63 // Draw it as a box with the LaTeX text
66 scr.fillRectangle(gc_lighted, int(x), baseline - Ascent(font) +1 ,
67 Width(font) - 2, Ascent(font) + Descent(font) -2);
69 scr.drawRectangle(gc_foot, int(x), baseline - Ascent(font) + 1,
70 Width(font)-2, Ascent(font)+Descent(font)-2);
72 scr.drawString(font, contents, baseline, int(x+2));
77 void InsetLatex::Write(FILE * file)
79 fprintf(file, "Latex %s\n", contents.c_str());
83 void InsetLatex::Read(Buffer const *, LyXLex & lex)
85 FILE * file = lex.getFile();
88 while (!feof(file) && (c = fgetc(file)) != '\n') {
95 int InsetLatex::Latex(FILE * file, signed char /*fragile*/, bool /*fs*/)
97 fprintf(file, "%s", contents.c_str());
102 int InsetLatex::Latex(string & file, signed char /*fragile*/, bool /*fs*/)
109 int InsetLatex::Ascii(string & file)
116 int InsetLatex::Linuxdoc(string & file)
123 int InsetLatex::DocBook(string & file)
130 bool InsetLatex::Deletable() const
136 InsetLatex * InsetLatex::Clone() const
138 InsetLatex * result = new InsetLatex(contents);
143 Inset::Code InsetLatex::LyxCode() const
145 if (contents == "\\tableofcontents") return Inset::TOC_CODE;
146 return Inset::NO_CODE;