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