]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlParagraph.C
ws fixes, formatting and some other small changes
[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/LyXView.h"
30
31 #include "support/LAssert.h"
32
33
34 ControlParagraph::ControlParagraph(LyXView & lv, Dialogs & d)
35         : ControlDialogBD(lv, d), pp_(0), ininset_(false)
36 {}
37
38
39 ControlParagraph::~ControlParagraph()
40 {}
41
42
43 ParagraphParameters & ControlParagraph::params()
44 {
45         lyx::Assert(pp_.get());
46         return *pp_;
47 }
48
49
50 bool ControlParagraph::inInset() const
51 {
52         return ininset_;
53 }
54
55
56 LyXAlignment ControlParagraph::alignPossible() const
57 {
58         return alignpos_;
59 }
60
61
62 void ControlParagraph::apply()
63 {
64         if (!bufferIsAvailable())
65                 return;
66
67         view().apply();
68
69         LyXText * text(bufferview()->getLyXText());
70         text->setParagraph(bufferview(),
71                            pp_->lineTop(),
72                            pp_->lineBottom(),
73                            pp_->pagebreakTop(),
74                            pp_->pagebreakBottom(),
75                            pp_->spaceTop(),
76                            pp_->spaceBottom(),
77                            pp_->spacing(),
78                            pp_->align(),
79                            pp_->labelWidthString(),
80                            pp_->noindent());
81
82         // Actually apply these settings
83         bufferview()->update(text,
84                              BufferView::SELECT |
85                              BufferView::FITCUR |
86                              BufferView::CHANGE);
87
88         buffer()->markDirty();
89
90         lv_.message(_("Paragraph layout set"));
91 }
92
93
94 void ControlParagraph::setParams()
95 {
96         if (!pp_.get())
97                 pp_.reset(new ParagraphParameters());
98
99         /// get paragraph
100         Paragraph const * par_ = bufferview()->getLyXText()->cursor.par();
101
102         /// Set the paragraph parameters
103         *pp_ = par_->params();
104
105         /// this needs to be done separately
106         pp_->labelWidthString(par_->getLabelWidthString());
107
108         /// alignment
109         LyXLayout_ptr const & layout = par_->layout();
110         if (pp_->align() == LYX_ALIGN_LAYOUT)
111                 pp_->align(layout->align);
112
113         /// is alignment possible
114         alignpos_ = layout->alignpossible;
115
116         /// is paragraph in inset
117         ininset_ = par_->inInset();
118 }
119
120
121 void ControlParagraph::changedParagraph()
122 {
123         /// get paragraph
124         Paragraph const * p = bufferview()->getLyXText()->cursor.par();
125
126         if (p == 0) // this is wrong as we don't set par_ here! /* || p == par_) */
127                 return;
128
129         // For now, don't bother checking if the params are different.
130         // Will the underlying paragraph accept our changes?
131         Inset * const inset = p->inInset();
132         bool const accept = !(inset && inset->forceDefaultParagraphs(inset));
133         bc().valid(accept);
134 }