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