]> git.lyx.org Git - lyx.git/blob - src/insets/InsetNewpage.cpp
This should be the last of the commits refactoring the InsetLayout code.
[lyx.git] / src / insets / InsetNewpage.cpp
1 /**
2  * \file InsetNewpage.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetNewpage.h"
14
15 #include "Text.h"
16 #include "MetricsInfo.h"
17 #include "OutputParams.h"
18 #include "TextMetrics.h"
19
20 #include "frontends/FontMetrics.h"
21 #include "frontends/Painter.h"
22
23 #include "support/debug.h"
24 #include "support/docstring.h"
25 #include "support/docstream.h"
26 #include "support/gettext.h"
27
28 using namespace std;
29
30 namespace lyx {
31
32 void InsetNewpage::read(Buffer const &, Lexer &)
33 {
34         /* Nothing to read */
35 }
36
37
38 void InsetNewpage::write(Buffer const &, ostream & os) const
39 {
40         os << "\n" << getCmdName() << '\n';
41 }
42
43
44 void InsetNewpage::metrics(MetricsInfo & mi, Dimension & dim) const
45 {
46         dim.asc = defaultRowHeight();
47         dim.des = defaultRowHeight();
48         dim.wid = mi.base.textwidth;
49         // Cache the inset dimension. 
50         setDimCache(mi, dim);
51 }
52
53
54 void InsetNewpage::draw(PainterInfo & pi, int x, int y) const
55 {
56         using frontend::Painter;
57
58         FontInfo font;
59         font.setColor(ColorName());
60         font.decSize();
61
62         Dimension const dim = dimension(*pi.base.bv);
63
64         int w = 0;
65         int a = 0;
66         int d = 0;
67         theFontMetrics(font).rectText(insetLabel(), w, a, d);
68
69         int const text_start = int(x + (dim.wid - w) / 2);
70         int const text_end = text_start + w;
71
72         pi.pain.rectText(text_start, y + d, insetLabel(), font,
73                 Color_none, Color_none);
74
75         pi.pain.line(x, y, text_start, y,
76                    ColorName(), Painter::line_onoffdash);
77         pi.pain.line(text_end, y, int(x + dim.wid), y,
78                    ColorName(), Painter::line_onoffdash);
79 }
80
81
82 int InsetNewpage::latex(Buffer const &, odocstream & os,
83                           OutputParams const &) const
84 {
85         os << from_ascii(getCmdName()) << "{}";
86         return 0;
87 }
88
89
90 int InsetNewpage::plaintext(Buffer const &, odocstream & os,
91                               OutputParams const &) const
92 {
93         os << '\n';
94         return PLAINTEXT_NEWLINE;
95 }
96
97
98 int InsetNewpage::docbook(Buffer const &, odocstream & os,
99                             OutputParams const &) const
100 {
101         os << '\n';
102         return 0;
103 }
104
105
106 } // namespace lyx