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