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