]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlParagraph.C
Port the tabular dialog to the new scheme based on class Dialog.
[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
15 #include "ControlParagraph.h"
16
17 #include "ButtonControllerBase.h"
18 #include "ViewBase.h"
19
20 #include "buffer.h"
21 #include "BufferView.h"
22 #include "gettext.h"
23 #include "lyxtext.h"
24 #include "ParagraphParameters.h"
25
26 #include "frontends/LyXView.h"
27 #include "support/LAssert.h"
28
29
30 ControlParagraph::ControlParagraph(LyXView & lv, Dialogs & d)
31         : ControlDialogBD(lv, d), pp_(0), ininset_(false)
32 {}
33
34
35 ControlParagraph::~ControlParagraph()
36 {}
37
38
39 ParagraphParameters & ControlParagraph::params()
40 {
41         lyx::Assert(pp_.get());
42         return *pp_;
43 }
44
45
46 bool ControlParagraph::inInset() const
47 {
48         return ininset_;
49 }
50
51
52 LyXAlignment ControlParagraph::alignPossible() const
53 {
54         return alignpossible_;
55 }
56
57
58 LyXAlignment ControlParagraph::alignDefault() const
59 {
60         return aligndefault_;
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         lv_.message(_("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         alignpossible_ = layout->alignpossible;
117
118         /// set default alignment
119         aligndefault_ = layout->align;
120
121         /// is paragraph in inset
122         ininset_ = par_->inInset();
123 }
124
125
126 void ControlParagraph::changedParagraph()
127 {
128         /// get paragraph
129         Paragraph const * p = bufferview()->getLyXText()->cursor.par();
130
131         if (p == 0) // this is wrong as we don't set par_ here! /* || p == par_) */
132                 return;
133
134         // For now, don't bother checking if the params are different.
135         // Will the underlying paragraph accept our changes?
136         Inset * const inset = p->inInset();
137         bool const accept = !(inset && inset->forceDefaultParagraphs(inset));
138         bc().valid(accept);
139 }