1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
7 * Copyright (C) 1995-1998 The LyX Team.
9 *======================================================*/
14 #pragma implementation
17 #include "definitions.h"
18 #include "insetlatex.h"
21 // $Id: insetlatex.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $
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 $";
27 /* Latex. Used to insert Latex-Code automatically */
30 InsetLatex::InsetLatex()
35 InsetLatex::InsetLatex(LString const & string)
41 InsetLatex::~InsetLatex()
46 int InsetLatex::Ascent(LyXFont const &font) const
48 return font.maxAscent() + 1;
52 int InsetLatex::Descent(LyXFont const &font) const
54 return font.maxDescent() + 1;
58 int InsetLatex::Width(LyXFont const &font) const
60 return 6 + font.stringWidth(contents);
64 void InsetLatex::Draw(LyXFont font, LyXScreen &scr,
65 int baseline, float &x)
67 // Latex-insets are always LaTeX, so just correct the font */
68 font.setLatex(LyXFont::ON);
70 // Draw it as a box with the LaTeX text
73 //scr.drawFilledRectangle(int(x), baseline - Ascent(font) + 1,
74 // Width(font)-2, Ascent(font) + Descent(font)-2,
76 scr.fillRectangle(gc_lighted, int(x), baseline - Ascent(font) +1 ,
77 Width(font) - 2, Ascent(font) + Descent(font) -2);
79 //scr.drawRectangle(int(x), baseline - Ascent(font) + 1,
80 // Width(font)-2, Ascent(font)+Descent(font)-2,
82 scr.drawRectangle(gc_foot,int(x), baseline - Ascent(font) + 1,
83 Width(font)-2, Ascent(font)+Descent(font)-2);
85 scr.drawString(font, contents, baseline, int(x+2));
90 void InsetLatex::Write(FILE *file)
92 fprintf(file, "Latex %s\n", contents.c_str());
96 void InsetLatex::Read(LyXLex &lex)
98 FILE *file = lex.getFile();
102 while (!feof(file) && (c = fgetc(file)) != '\n') {
111 int InsetLatex::Latex(FILE *file, signed char /*fragile*/)
113 fprintf(file, "%s", contents.c_str());
118 int InsetLatex::Latex(LString &file, signed char /*fragile*/)
125 int InsetLatex::Linuxdoc(LString &file)
132 int InsetLatex::DocBook(LString &file)
139 bool InsetLatex::Deletable() const
145 Inset* InsetLatex::Clone()
147 InsetLatex *result = new InsetLatex(contents);
152 Inset::Code InsetLatex::LyxCode() const
154 if (contents == "\\tableofcontents") return Inset::TOC_CODE;
155 return Inset::NO_CODE;