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