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