]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlParagraph.C
This file is part of LyX, the document processor.
[lyx.git] / src / frontends / controllers / ControlParagraph.C
1 // -*- C++ -*-
2 /**
3  * \file ControlParagraph.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Edwin Leuven 
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "ControlParagraph.h"
19
20 #include "ButtonControllerBase.h"
21 #include "ViewBase.h"
22
23 #include "buffer.h"
24 #include "BufferView.h"
25 #include "gettext.h"
26 #include "lyxtext.h"
27 #include "ParagraphParameters.h"
28
29 #include "frontends/Liason.h"
30
31 #include "support/LAssert.h"
32
33 using Liason::setMinibuffer;
34
35
36 ControlParagraph::ControlParagraph(LyXView & lv, Dialogs & d)
37         : ControlDialogBD(lv, d), pp_(0), ininset_(false)
38 {}
39
40
41 ControlParagraph::~ControlParagraph()
42 {}
43
44
45 ParagraphParameters & ControlParagraph::params()
46 {
47         lyx::Assert(pp_.get());
48         return *pp_;
49 }
50
51
52 bool ControlParagraph::inInset() const
53 {
54         return ininset_;
55 }
56
57
58 LyXAlignment ControlParagraph::alignPossible() const
59 {
60         return alignpos_;
61 }
62
63
64 void ControlParagraph::apply()
65 {
66         if (!bufferIsAvailable())
67                 return;
68
69         view().apply();
70
71         LyXText * text(bufferview()->getLyXText());
72         text->setParagraph(bufferview(),
73                            pp_->lineTop(),
74                            pp_->lineBottom(),
75                            pp_->pagebreakTop(),
76                            pp_->pagebreakBottom(),
77                            pp_->spaceTop(),
78                            pp_->spaceBottom(),
79                            pp_->spacing(),
80                            pp_->align(),
81                            pp_->labelWidthString(),
82                            pp_->noindent());
83
84         // Actually apply these settings
85         bufferview()->update(text,
86                              BufferView::SELECT |
87                              BufferView::FITCUR |
88                              BufferView::CHANGE);
89
90         buffer()->markDirty();
91
92         setMinibuffer(&lv_, _("Paragraph layout set"));
93 }
94
95
96 void ControlParagraph::setParams()
97 {
98         if (!pp_.get())
99                 pp_.reset(new ParagraphParameters());
100
101         /// get paragraph
102         Paragraph const * par_ = bufferview()->getLyXText()->cursor.par();
103
104         /// Set the paragraph parameters
105         *pp_ = par_->params();
106
107         /// this needs to be done separately
108         pp_->labelWidthString(par_->getLabelWidthString());
109
110         /// alignment
111         LyXLayout_ptr const & layout = par_->layout();
112         if (pp_->align() == LYX_ALIGN_LAYOUT)
113                 pp_->align(layout->align);
114
115         /// is alignment possible
116         alignpos_ = layout->alignpossible;
117
118         /// is paragraph in inset
119         ininset_ = par_->inInset();
120 }
121
122 void ControlParagraph::changedParagraph()
123 {
124         /// get paragraph
125         Paragraph const * p = bufferview()->getLyXText()->cursor.par();
126
127         if (p == 0) // this is wrong as we don't set par_ here! /* || p == par_) */
128                 return;
129
130         // For now, don't bother checking if the params are different.
131         // Will the underlying paragraph accept our changes?
132         Inset * const inset = p->inInset();
133         bool const accept = !(inset && inset->forceDefaultParagraphs(inset));
134         bc().valid(accept);
135 }