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