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 "definitions.h"
18 #include "insetlatex.h"
21 /* Latex. Used to insert Latex-Code automatically */
24 InsetLatex::InsetLatex()
29 InsetLatex::InsetLatex(string const & string)
35 InsetLatex::~InsetLatex()
40 int InsetLatex::Ascent(LyXFont const &font) const
42 return font.maxAscent() + 1;
46 int InsetLatex::Descent(LyXFont const &font) const
48 return font.maxDescent() + 1;
52 int InsetLatex::Width(LyXFont const &font) const
54 return 6 + font.stringWidth(contents);
58 void InsetLatex::Draw(LyXFont font, LyXScreen &scr,
59 int baseline, float &x)
61 // Latex-insets are always LaTeX, so just correct the font */
62 font.setLatex(LyXFont::ON);
64 // Draw it as a box with the LaTeX text
67 //scr.drawFilledRectangle(int(x), baseline - Ascent(font) + 1,
68 // Width(font)-2, Ascent(font) + Descent(font)-2,
70 scr.fillRectangle(gc_lighted, int(x), baseline - Ascent(font) +1 ,
71 Width(font) - 2, Ascent(font) + Descent(font) -2);
73 //scr.drawRectangle(int(x), baseline - Ascent(font) + 1,
74 // Width(font)-2, Ascent(font)+Descent(font)-2,
76 scr.drawRectangle(gc_foot,int(x), baseline - Ascent(font) + 1,
77 Width(font)-2, Ascent(font)+Descent(font)-2);
79 scr.drawString(font, contents, baseline, int(x+2));
84 void InsetLatex::Write(FILE *file)
86 fprintf(file, "Latex %s\n", contents.c_str());
90 void InsetLatex::Read(LyXLex &lex)
92 FILE *file = lex.getFile();
96 while (!feof(file) && (c = fgetc(file)) != '\n') {
105 int InsetLatex::Latex(FILE *file, signed char /*fragile*/)
107 fprintf(file, "%s", contents.c_str());
112 int InsetLatex::Latex(string &file, signed char /*fragile*/)
119 int InsetLatex::Linuxdoc(string &file)
126 int InsetLatex::DocBook(string &file)
133 bool InsetLatex::Deletable() const
139 Inset* InsetLatex::Clone()
141 InsetLatex *result = new InsetLatex(contents);
146 Inset::Code InsetLatex::LyxCode() const
148 if (contents == "\\tableofcontents") return Inset::TOC_CODE;
149 return Inset::NO_CODE;