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