]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlTabular.C
Use Buffer const reference in most placees possible.
[lyx.git] / src / frontends / controllers / ControlTabular.C
1 /**
2  * \file ControlTabular.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlTabular.h"
14 #include "funcrequest.h"
15 #include "lyxrc.h"
16 #include "insets/insettabular.h"
17 #include "support/LAssert.h"
18
19 using namespace lyx::support;
20
21
22 ControlTabular::ControlTabular(Dialog & parent)
23         : Dialog::Controller(parent), active_cell_(-1)
24 {}
25
26
27 bool ControlTabular::initialiseParams(string const & data)
28 {
29         Buffer & buffer = kernel().buffer();
30
31         InsetTabular tmp(buffer);
32         int cell = InsetTabularMailer::string2params(data, tmp);
33         if (cell != -1) {
34                 params_.reset(new LyXTabular(tmp.tabular));
35                 active_cell_ = cell;
36         }
37         return true;
38 }
39
40
41 void ControlTabular::clearParams()
42 {
43         params_.reset();
44         active_cell_ = -1;
45 }
46
47
48 int ControlTabular::getActiveCell() const
49 {
50         return active_cell_;
51 }
52
53
54 LyXTabular const & ControlTabular::tabular() const
55 {
56         Assert(params_.get());
57         return *params_.get();
58 }
59
60
61 void ControlTabular::set(LyXTabular::Feature f, string const & arg)
62 {
63         string const data = featureAsString(f) + ' ' + arg;
64         kernel().dispatch(FuncRequest(LFUN_TABULAR_FEATURE, data));
65 }
66
67
68 bool ControlTabular::useMetricUnits() const
69 {
70         return lyxrc.default_papersize > PAPER_EXECUTIVEPAPER;
71 }
72
73
74 void ControlTabular::toggleTopLine()
75 {
76         if (tabular().isMultiColumn(getActiveCell()))
77                 set(LyXTabular::M_TOGGLE_LINE_TOP);
78         else
79                 set(LyXTabular::TOGGLE_LINE_TOP);
80 }
81
82
83 void ControlTabular::toggleBottomLine()
84 {
85         if (tabular().isMultiColumn(getActiveCell()))
86                 set(LyXTabular::M_TOGGLE_LINE_BOTTOM);
87         else
88                 set(LyXTabular::TOGGLE_LINE_BOTTOM);
89 }
90
91
92 void ControlTabular::toggleLeftLine()
93 {
94         if (tabular().isMultiColumn(getActiveCell()))
95                 set(LyXTabular::M_TOGGLE_LINE_LEFT);
96         else
97                 set(LyXTabular::TOGGLE_LINE_LEFT);
98 }
99
100
101 void ControlTabular::toggleRightLine()
102 {
103         if (tabular().isMultiColumn(getActiveCell()))
104                 set(LyXTabular::M_TOGGLE_LINE_RIGHT);
105         else
106                 set(LyXTabular::TOGGLE_LINE_RIGHT);
107 }
108
109
110 void ControlTabular::setSpecial(string const & special)
111 {
112         if (tabular().isMultiColumn(getActiveCell()))
113                 set(LyXTabular::SET_SPECIAL_MULTI, special);
114         else
115                 set(LyXTabular::SET_SPECIAL_COLUMN, special);
116 }
117
118
119 void ControlTabular::setWidth(string const & width)
120 {
121         if (tabular().isMultiColumn(getActiveCell()))
122                 set(LyXTabular::SET_MPWIDTH, width);
123         else
124                 set(LyXTabular::SET_PWIDTH, width);
125
126         dialog().view().update();
127 }
128
129
130 void ControlTabular::toggleMultiColumn()
131 {
132         set(LyXTabular::MULTICOLUMN);
133         dialog().view().update();
134 }
135
136
137 void ControlTabular::rotateTabular(bool yes)
138 {
139         if (yes)
140                 set(LyXTabular::SET_ROTATE_TABULAR);
141         else
142                 set(LyXTabular::UNSET_ROTATE_TABULAR);
143 }
144
145
146 void ControlTabular::rotateCell(bool yes)
147 {
148         if (yes)
149                 set(LyXTabular::SET_ROTATE_CELL);
150         else
151                 set(LyXTabular::UNSET_ROTATE_CELL);
152 }
153
154
155 void ControlTabular::halign(ControlTabular::HALIGN h)
156 {
157         LyXTabular::Feature num = LyXTabular::ALIGN_LEFT;
158         LyXTabular::Feature multi_num = LyXTabular::M_ALIGN_LEFT;
159
160         switch (h) {
161                 case LEFT:
162                         num = LyXTabular::ALIGN_LEFT;
163                         multi_num = LyXTabular::M_ALIGN_LEFT;
164                         break;
165                 case CENTER:
166                         num = LyXTabular::ALIGN_CENTER;
167                         multi_num = LyXTabular::M_ALIGN_CENTER;
168                         break;
169                 case RIGHT:
170                         num = LyXTabular::ALIGN_RIGHT;
171                         multi_num = LyXTabular::M_ALIGN_RIGHT;
172                         break;
173                 case BLOCK:
174                         num = LyXTabular::ALIGN_BLOCK;
175                         //multi_num: no equivalent
176                         break;
177         }
178
179         if (tabular().isMultiColumn(getActiveCell()))
180                 set(multi_num);
181         else
182                 set(num);
183 }
184
185
186 void ControlTabular::valign(ControlTabular::VALIGN v)
187 {
188         LyXTabular::Feature num = LyXTabular::VALIGN_MIDDLE;
189         LyXTabular::Feature multi_num = LyXTabular::M_VALIGN_MIDDLE;
190
191         switch (v) {
192                 case TOP:
193                         num = LyXTabular::VALIGN_TOP;
194                         multi_num = LyXTabular::M_VALIGN_TOP;
195                         break;
196                 case MIDDLE:
197                         num = LyXTabular::VALIGN_MIDDLE;
198                         multi_num = LyXTabular::M_VALIGN_MIDDLE;
199                         break;
200                 case BOTTOM:
201                         num = LyXTabular::VALIGN_BOTTOM;
202                         multi_num = LyXTabular::M_VALIGN_BOTTOM;
203                         break;
204         }
205
206         if (tabular().isMultiColumn(getActiveCell()))
207                 set(multi_num);
208         else
209                 set(num);
210 }
211
212
213 void ControlTabular::longTabular(bool yes)
214 {
215         if (yes)
216                 set(LyXTabular::SET_LONGTABULAR);
217         else
218                 set(LyXTabular::UNSET_LONGTABULAR);
219 }