]> git.lyx.org Git - features.git/blob - src/frontends/controllers/ControlParagraph.C
* Constify Buffer::getLabelList.
[features.git] / src / frontends / controllers / ControlParagraph.C
1 // -*- C++ -*-
2 /**
3  * \file ControlParagraph.C
4  * Copyright 2002 The LyX Team.
5  * See the file COPYING.
6  *
7  * \author Edwin Leuven <leuven@fee.uva.nl>
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "ControlParagraph.h"
17 #include "ButtonControllerBase.h"
18 #include "ViewBase.h"
19 #include "ParagraphParameters.h"
20 #include "Liason.h"
21 #include "BufferView.h"
22 #include "gettext.h"
23 #include "buffer.h"
24 #include "lyxtext.h"
25 #include "support/LAssert.h"
26 #include "Dialogs.h"
27 #include <boost/bind.hpp>
28
29 using Liason::setMinibuffer;
30
31
32 ControlParagraph::ControlParagraph(LyXView & lv, Dialogs & d)
33         : ControlDialogBD(lv, d), pp_(0), ininset_(false)
34 {
35      d_.updateParagraph.connect(
36              boost::bind(&ControlParagraph::changedParagraph, this));
37
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 }