2 * \file ControlTabular.cpp
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_(Tabular::npos)
32 bool ControlTabular::initialiseParams(string const & data)
34 // try to get the current cell
35 BufferView const * const bv = kernel().bufferview();
37 Cursor 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() == Inset::TABULAR_CODE) {
42 active_cell_ = cur[i].idx();
46 InsetTabular tmp(kernel().buffer());
47 InsetTabularMailer::string2params(data, tmp);
48 params_.reset(new Tabular(tmp.tabular));
53 void ControlTabular::clearParams()
56 active_cell_ = Tabular::npos;
60 Tabular::idx_type ControlTabular::getActiveCell() const
66 Tabular const & ControlTabular::tabular() const
68 BOOST_ASSERT(params_.get());
69 return *params_.get();
73 void ControlTabular::set(Tabular::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(Tabular::M_TOGGLE_LINE_TOP);
91 set(Tabular::TOGGLE_LINE_TOP);
95 void ControlTabular::toggleBottomLine()
97 if (tabular().isMultiColumn(getActiveCell()))
98 set(Tabular::M_TOGGLE_LINE_BOTTOM);
100 set(Tabular::TOGGLE_LINE_BOTTOM);
104 void ControlTabular::toggleLeftLine()
106 if (tabular().isMultiColumn(getActiveCell()))
107 set(Tabular::M_TOGGLE_LINE_LEFT);
109 set(Tabular::TOGGLE_LINE_LEFT);
113 void ControlTabular::toggleRightLine()
115 if (tabular().isMultiColumn(getActiveCell()))
116 set(Tabular::M_TOGGLE_LINE_RIGHT);
118 set(Tabular::TOGGLE_LINE_RIGHT);
122 void ControlTabular::setSpecial(string const & special)
124 if (tabular().isMultiColumn(getActiveCell()))
125 set(Tabular::SET_SPECIAL_MULTI, special);
127 set(Tabular::SET_SPECIAL_COLUMN, special);
131 void ControlTabular::setWidth(string const & width)
133 if (tabular().isMultiColumn(getActiveCell()))
134 set(Tabular::SET_MPWIDTH, width);
136 set(Tabular::SET_PWIDTH, width);
138 dialog().view().update();
142 void ControlTabular::toggleMultiColumn()
144 set(Tabular::MULTICOLUMN);
145 dialog().view().update();
149 void ControlTabular::rotateTabular(bool yes)
152 set(Tabular::SET_ROTATE_TABULAR);
154 set(Tabular::UNSET_ROTATE_TABULAR);
158 void ControlTabular::rotateCell(bool yes)
161 set(Tabular::SET_ROTATE_CELL);
163 set(Tabular::UNSET_ROTATE_CELL);
167 void ControlTabular::halign(ControlTabular::HALIGN h)
169 Tabular::Feature num = Tabular::ALIGN_LEFT;
170 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
174 num = Tabular::ALIGN_LEFT;
175 multi_num = Tabular::M_ALIGN_LEFT;
178 num = Tabular::ALIGN_CENTER;
179 multi_num = Tabular::M_ALIGN_CENTER;
182 num = Tabular::ALIGN_RIGHT;
183 multi_num = Tabular::M_ALIGN_RIGHT;
186 num = Tabular::ALIGN_BLOCK;
187 //multi_num: no equivalent
191 if (tabular().isMultiColumn(getActiveCell()))
198 void ControlTabular::valign(ControlTabular::VALIGN v)
200 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
201 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
205 num = Tabular::VALIGN_TOP;
206 multi_num = Tabular::M_VALIGN_TOP;
209 num = Tabular::VALIGN_MIDDLE;
210 multi_num = Tabular::M_VALIGN_MIDDLE;
213 num = Tabular::VALIGN_BOTTOM;
214 multi_num = Tabular::M_VALIGN_BOTTOM;
218 if (tabular().isMultiColumn(getActiveCell()))
225 void ControlTabular::booktabs(bool yes)
228 set(Tabular::SET_BOOKTABS);
230 set(Tabular::UNSET_BOOKTABS);
234 void ControlTabular::longTabular(bool yes)
237 set(Tabular::SET_LONGTABULAR);
239 set(Tabular::UNSET_LONGTABULAR);
242 } // namespace frontend