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