]> git.lyx.org Git - lyx.git/blob - src/insets/InsetHFill.cpp
Cleanup Hfill metrics and painting. InsetHFill is now treated almost like any other...
[lyx.git] / src / insets / InsetHFill.cpp
1 /**
2  * \file InsetHFill.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 "InsetHFill.h"
14
15 #include "MetricsInfo.h"
16
17 #include "frontends/Painter.h"
18
19 #include "support/gettext.h"
20
21 #include <ostream>
22
23
24 namespace lyx {
25
26
27 InsetHFill::InsetHFill()
28         : InsetCommand(InsetCommandParams(HFILL_CODE), std::string())
29 {}
30
31
32 CommandInfo const * InsetHFill::findInfo(std::string const & /* cmdName */)
33 {
34         static const char * const paramnames[] = {""};
35         static const CommandInfo info = {0, paramnames, 0};
36         return &info;
37 }
38
39
40 Inset * InsetHFill::clone() const
41 {
42         return new InsetHFill;
43 }
44
45
46 void InsetHFill::metrics(MetricsInfo &, Dimension & dim) const
47 {
48         // The metrics for this inset are calculated externally in
49         // \c TextMetrics::computeRowMetrics. Those are dummy value:
50         dim = Dimension(10, 10, 10);
51 }
52
53
54 void InsetHFill::draw(PainterInfo & pi, int x, int y) const
55 {
56         Dimension const dim = Inset::dimension(*pi.base.bv);
57         x += 1;
58
59         int const y0 = y + dim.des;
60         int const y1 = y - dim.asc;
61
62         pi.pain.line(x, y1, x, y0, Color_added_space);
63         if (dim.wid == 0)
64                 // The HFill is not expanded.
65                 return;
66
67         int const x1 = x + dim.wid;
68
69         pi.pain.line(x, y, x1, y, Color_added_space,
70                 frontend::Painter::line_onoffdash);
71         pi.pain.line(x1, y1, x1, y0, Color_added_space);
72 }
73
74
75 docstring const InsetHFill::getScreenLabel(Buffer const &) const
76 {
77         return _("Horizontal Fill");
78 }
79
80
81 int InsetHFill::plaintext(Buffer const &, odocstream & os,
82                           OutputParams const &) const
83 {
84         os << "     ";
85         return 5;
86 }
87
88
89 int InsetHFill::docbook(Buffer const &, odocstream & os,
90                         OutputParams const &) const
91 {
92         os << '\n';
93         return 0;
94 }
95
96
97 void InsetHFill::write(Buffer const &, std::ostream & os) const
98 {
99         os << "\n\\hfill\n";
100 }
101
102
103 bool InsetHFill::isSpace() const
104 {
105         return true;
106 }
107
108
109 } // namespace lyx