]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlParagraph.C
Forward declare ParagraphParameters in ControlParagraph.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 "ViewBase.h"
17 #include "ButtonControllerBase.h"
18 #include "ControlParagraph.h"
19 #include "ParagraphParameters.h"
20 #include "Dialogs.h"
21 #include "Liason.h"
22 #include "LyXView.h"
23 #include "BufferView.h"
24 #include "gettext.h"
25 #include "buffer.h"
26 #include "lyxtext.h"
27 #include "lyxtextclasslist.h"
28 #include "support/LAssert.h"
29
30 #include <boost/bind.hpp>
31
32 using Liason::setMinibuffer;
33
34
35 ControlParagraph::ControlParagraph(LyXView & lv, Dialogs & d)
36         : ControlDialogBD(lv, d), pp_(0), ininset_(false)
37 {
38         d_.showParagraph = boost::bind(&ControlParagraph::show, this);
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(),
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         LyXTextClass const & tclass =
113                 textclasslist[lv_.view()->buffer()->params.textclass];
114         if (pp_->align() == LYX_ALIGN_LAYOUT)
115                 pp_->align(tclass[par_->layout()].align);
116
117         /// is alignment possible
118         alignpos_ = tclass[par_->layout()].alignpossible;
119
120         /// is paragraph in inset
121         ininset_ = par_->inInset();
122 }