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 "insets/InsetTabular.h"
26 ControlTabular::ControlTabular(Dialog & parent)
27 : Dialog::Controller(parent), active_cell_(Tabular::npos)
31 bool ControlTabular::initialiseParams(string const & data)
33 // try to get the current cell
34 BufferView const * const bv = kernel().bufferview();
35 InsetTabular const * current_inset = 0;
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 current_inset = static_cast<InsetTabular const *>(&cur[i].inset());
43 active_cell_ = cur[i].idx();
48 if (current_inset && data.empty()) {
49 params_.reset(new Tabular(current_inset->tabular));
53 InsetTabular tmp(kernel().buffer());
54 InsetTabularMailer::string2params(data, tmp);
55 params_.reset(new Tabular(tmp.tabular));
60 void ControlTabular::clearParams()
63 active_cell_ = Tabular::npos;
67 Tabular::idx_type ControlTabular::getActiveCell() const
73 Tabular const & ControlTabular::tabular() const
75 BOOST_ASSERT(params_.get());
76 return *params_.get();
80 void ControlTabular::set(Tabular::Feature f, string const & arg)
82 string const data = featureAsString(f) + ' ' + arg;
83 kernel().dispatch(FuncRequest(getLfun(), data));
87 bool ControlTabular::useMetricUnits() const
89 return lyxrc.default_papersize > PAPER_USEXECUTIVE;
93 void ControlTabular::toggleTopLine()
95 if (tabular().isMultiColumn(getActiveCell()))
96 set(Tabular::M_TOGGLE_LINE_TOP);
98 set(Tabular::TOGGLE_LINE_TOP);
102 void ControlTabular::toggleBottomLine()
104 if (tabular().isMultiColumn(getActiveCell()))
105 set(Tabular::M_TOGGLE_LINE_BOTTOM);
107 set(Tabular::TOGGLE_LINE_BOTTOM);
111 void ControlTabular::toggleLeftLine()
113 if (tabular().isMultiColumn(getActiveCell()))
114 set(Tabular::M_TOGGLE_LINE_LEFT);
116 set(Tabular::TOGGLE_LINE_LEFT);
120 void ControlTabular::toggleRightLine()
122 if (tabular().isMultiColumn(getActiveCell()))
123 set(Tabular::M_TOGGLE_LINE_RIGHT);
125 set(Tabular::TOGGLE_LINE_RIGHT);
129 void ControlTabular::setSpecial(string const & special)
131 if (tabular().isMultiColumn(getActiveCell()))
132 set(Tabular::SET_SPECIAL_MULTI, special);
134 set(Tabular::SET_SPECIAL_COLUMN, special);
138 void ControlTabular::setWidth(string const & width)
140 if (tabular().isMultiColumn(getActiveCell()))
141 set(Tabular::SET_MPWIDTH, width);
143 set(Tabular::SET_PWIDTH, width);
145 dialog().view().update();
149 void ControlTabular::toggleMultiColumn()
151 set(Tabular::MULTICOLUMN);
152 dialog().view().update();
156 void ControlTabular::rotateTabular(bool yes)
159 set(Tabular::SET_ROTATE_TABULAR);
161 set(Tabular::UNSET_ROTATE_TABULAR);
165 void ControlTabular::rotateCell(bool yes)
168 set(Tabular::SET_ROTATE_CELL);
170 set(Tabular::UNSET_ROTATE_CELL);
174 void ControlTabular::halign(ControlTabular::HALIGN h)
176 Tabular::Feature num = Tabular::ALIGN_LEFT;
177 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
181 num = Tabular::ALIGN_LEFT;
182 multi_num = Tabular::M_ALIGN_LEFT;
185 num = Tabular::ALIGN_CENTER;
186 multi_num = Tabular::M_ALIGN_CENTER;
189 num = Tabular::ALIGN_RIGHT;
190 multi_num = Tabular::M_ALIGN_RIGHT;
193 num = Tabular::ALIGN_BLOCK;
194 //multi_num: no equivalent
198 if (tabular().isMultiColumn(getActiveCell()))
205 void ControlTabular::valign(ControlTabular::VALIGN v)
207 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
208 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
212 num = Tabular::VALIGN_TOP;
213 multi_num = Tabular::M_VALIGN_TOP;
216 num = Tabular::VALIGN_MIDDLE;
217 multi_num = Tabular::M_VALIGN_MIDDLE;
220 num = Tabular::VALIGN_BOTTOM;
221 multi_num = Tabular::M_VALIGN_BOTTOM;
225 if (tabular().isMultiColumn(getActiveCell()))
232 void ControlTabular::booktabs(bool yes)
235 set(Tabular::SET_BOOKTABS);
237 set(Tabular::UNSET_BOOKTABS);
241 void ControlTabular::longTabular(bool yes)
244 set(Tabular::SET_LONGTABULAR);
246 set(Tabular::UNSET_LONGTABULAR);
249 } // namespace frontend