]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlParagraph.cpp
next one
[lyx.git] / src / frontends / controllers / ControlParagraph.cpp
1 /**
2  * \file ControlParagraph.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "ControlParagraph.h"
15 #include "Buffer.h"
16 #include "BufferParams.h"
17 #include "BufferView.h"
18 #include "Cursor.h"
19 #include "FuncRequest.h"
20 #include "Lexer.h"
21 #include "Paragraph.h"
22 #include "ParagraphParameters.h"
23
24 #include <sstream>
25
26 using std::istringstream;
27 using std::ostringstream;
28 using std::string;
29
30 namespace lyx {
31 namespace frontend {
32
33 ControlParagraph::ControlParagraph(Dialog & parent)
34         : Controller(parent)
35 {}
36
37
38 ParagraphParameters & ControlParagraph::params()
39 {
40         if (haveMulitParSelection()) {
41                 multiparsel_ = ParagraphParameters();
42                 // FIXME: It would be nice to initialise the parameters that
43                 // are common to all paragraphs.
44                 return multiparsel_;
45         }
46
47         return bufferview()->cursor().innerParagraph().params();
48 }
49
50
51 ParagraphParameters const & ControlParagraph::params() const
52 {
53         return bufferview()->cursor().innerParagraph().params();
54 }
55
56
57 void ControlParagraph::dispatchParams()
58 {
59         if (haveMulitParSelection()) {
60                 ostringstream data;
61                 multiparsel_.write(data);
62                 FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
63                 dispatch(fr);
64                 return;
65         }
66
67         bufferview()->updateMetrics(false);
68         bufferview()->buffer().changed();
69 }
70
71
72 bool ControlParagraph::haveMulitParSelection()
73 {
74         Cursor cur = bufferview()->cursor();
75         return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
76 }
77
78         
79 bool ControlParagraph::canIndent() const
80 {
81         return buffer().params().paragraph_separation ==
82                 BufferParams::PARSEP_INDENT;
83 }
84
85
86 LyXAlignment ControlParagraph::alignPossible() const
87 {
88         return bufferview()->cursor().innerParagraph().layout()->alignpossible;
89 }
90
91
92 LyXAlignment ControlParagraph::alignDefault() const
93 {
94         return bufferview()->cursor().innerParagraph().layout()->align;
95 }
96
97 } // namespace frontend
98 } // namespace lyx