2 * \file ControlTabular.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "BufferView.h"
14 #include "ControlTabular.h"
16 #include "funcrequest.h"
18 #include "paragraph.h"
19 #include "insets/insettabular.h"
27 ControlTabular::ControlTabular(Dialog & parent)
28 : Dialog::Controller(parent), active_cell_(LyXTabular::npos)
32 bool ControlTabular::initialiseParams(string const & data)
34 // try to get the current cell
35 BufferView const * const bv = kernel().bufferview();
37 LCursor const & cur = bv->cursor();
38 // get the innermost tabular inset;
39 // assume that it is "ours"
40 for (int i = cur.depth() - 1; i >= 0; --i)
41 if (cur[i].inset().lyxCode() == InsetBase::TABULAR_CODE) {
42 active_cell_ = cur[i].idx();
46 InsetTabular tmp(kernel().buffer());
47 InsetTabularMailer::string2params(data, tmp);
48 params_.reset(new LyXTabular(tmp.tabular));
53 void ControlTabular::clearParams()
56 active_cell_ = LyXTabular::npos;
60 LyXTabular::idx_type ControlTabular::getActiveCell() const
66 LyXTabular const & ControlTabular::tabular() const
68 BOOST_ASSERT(params_.get());
69 return *params_.get();
73 void ControlTabular::set(LyXTabular::Feature f, string const & arg)
75 string const data = featureAsString(f) + ' ' + arg;
76 kernel().dispatch(FuncRequest(getLfun(), data));
80 bool ControlTabular::useMetricUnits() const
82 return lyxrc.default_papersize > PAPER_USEXECUTIVE;
86 void ControlTabular::toggleTopLine()
88 if (tabular().isMultiColumn(getActiveCell()))
89 set(LyXTabular::M_TOGGLE_LINE_TOP);
91 set(LyXTabular::TOGGLE_LINE_TOP);
95 void ControlTabular::toggleBottomLine()
97 if (tabular().isMultiColumn(getActiveCell()))
98 set(LyXTabular::M_TOGGLE_LINE_BOTTOM);
100 set(LyXTabular::TOGGLE_LINE_BOTTOM);
104 void ControlTabular::toggleLeftLine()
106 if (tabular().isMultiColumn(getActiveCell()))
107 set(LyXTabular::M_TOGGLE_LINE_LEFT);
109 set(LyXTabular::TOGGLE_LINE_LEFT);
113 void ControlTabular::toggleRightLine()
115 if (tabular().isMultiColumn(getActiveCell()))
116 set(LyXTabular::M_TOGGLE_LINE_RIGHT);
118 set(LyXTabular::TOGGLE_LINE_RIGHT);
122 void ControlTabular::setSpecial(string const & special)
124 if (tabular().isMultiColumn(getActiveCell()))
125 set(LyXTabular::SET_SPECIAL_MULTI, special);
127 set(LyXTabular::SET_SPECIAL_COLUMN, special);
131 void ControlTabular::setWidth(string const & width)
133 if (tabular().isMultiColumn(getActiveCell()))
134 set(LyXTabular::SET_MPWIDTH, width);
136 set(LyXTabular::SET_PWIDTH, width);
138 dialog().view().update();
142 void ControlTabular::toggleMultiColumn()
144 set(LyXTabular::MULTICOLUMN);
145 dialog().view().update();
149 void ControlTabular::rotateTabular(bool yes)
152 set(LyXTabular::SET_ROTATE_TABULAR);
154 set(LyXTabular::UNSET_ROTATE_TABULAR);
158 void ControlTabular::rotateCell(bool yes)
161 set(LyXTabular::SET_ROTATE_CELL);
163 set(LyXTabular::UNSET_ROTATE_CELL);
167 void ControlTabular::halign(ControlTabular::HALIGN h)
169 LyXTabular::Feature num = LyXTabular::ALIGN_LEFT;
170 LyXTabular::Feature multi_num = LyXTabular::M_ALIGN_LEFT;
174 num = LyXTabular::ALIGN_LEFT;
175 multi_num = LyXTabular::M_ALIGN_LEFT;
178 num = LyXTabular::ALIGN_CENTER;
179 multi_num = LyXTabular::M_ALIGN_CENTER;
182 num = LyXTabular::ALIGN_RIGHT;
183 multi_num = LyXTabular::M_ALIGN_RIGHT;
186 num = LyXTabular::ALIGN_BLOCK;
187 //multi_num: no equivalent
191 if (tabular().isMultiColumn(getActiveCell()))
198 void ControlTabular::valign(ControlTabular::VALIGN v)
200 LyXTabular::Feature num = LyXTabular::VALIGN_MIDDLE;
201 LyXTabular::Feature multi_num = LyXTabular::M_VALIGN_MIDDLE;
205 num = LyXTabular::VALIGN_TOP;
206 multi_num = LyXTabular::M_VALIGN_TOP;
209 num = LyXTabular::VALIGN_MIDDLE;
210 multi_num = LyXTabular::M_VALIGN_MIDDLE;
213 num = LyXTabular::VALIGN_BOTTOM;
214 multi_num = LyXTabular::M_VALIGN_BOTTOM;
218 if (tabular().isMultiColumn(getActiveCell()))
225 void ControlTabular::booktabs(bool yes)
228 set(LyXTabular::SET_BOOKTABS);
230 set(LyXTabular::UNSET_BOOKTABS);
234 void ControlTabular::longTabular(bool yes)
237 set(LyXTabular::SET_LONGTABULAR);
239 set(LyXTabular::UNSET_LONGTABULAR);
242 } // namespace frontend