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();
36 Cursor const & cur = bv->cursor();
37 // get the innermost tabular inset;
38 // assume that it is "ours"
39 for (int i = cur.depth() - 1; i >= 0; --i)
40 if (cur[i].inset().lyxCode() == Inset::TABULAR_CODE) {
41 active_cell_ = cur[i].idx();
45 InsetTabular tmp(kernel().buffer());
46 InsetTabularMailer::string2params(data, tmp);
47 params_.reset(new Tabular(tmp.tabular));
52 void ControlTabular::clearParams()
55 active_cell_ = Tabular::npos;
59 Tabular::idx_type ControlTabular::getActiveCell() const
65 Tabular const & ControlTabular::tabular() const
67 BOOST_ASSERT(params_.get());
68 return *params_.get();
72 void ControlTabular::set(Tabular::Feature f, string const & arg)
74 string const data = featureAsString(f) + ' ' + arg;
75 kernel().dispatch(FuncRequest(getLfun(), data));
79 bool ControlTabular::useMetricUnits() const
81 return lyxrc.default_papersize > PAPER_USEXECUTIVE;
85 void ControlTabular::toggleTopLine()
87 if (tabular().isMultiColumn(getActiveCell()))
88 set(Tabular::M_TOGGLE_LINE_TOP);
90 set(Tabular::TOGGLE_LINE_TOP);
94 void ControlTabular::toggleBottomLine()
96 if (tabular().isMultiColumn(getActiveCell()))
97 set(Tabular::M_TOGGLE_LINE_BOTTOM);
99 set(Tabular::TOGGLE_LINE_BOTTOM);
103 void ControlTabular::toggleLeftLine()
105 if (tabular().isMultiColumn(getActiveCell()))
106 set(Tabular::M_TOGGLE_LINE_LEFT);
108 set(Tabular::TOGGLE_LINE_LEFT);
112 void ControlTabular::toggleRightLine()
114 if (tabular().isMultiColumn(getActiveCell()))
115 set(Tabular::M_TOGGLE_LINE_RIGHT);
117 set(Tabular::TOGGLE_LINE_RIGHT);
121 void ControlTabular::setSpecial(string const & special)
123 if (tabular().isMultiColumn(getActiveCell()))
124 set(Tabular::SET_SPECIAL_MULTI, special);
126 set(Tabular::SET_SPECIAL_COLUMN, special);
130 void ControlTabular::setWidth(string const & width)
132 if (tabular().isMultiColumn(getActiveCell()))
133 set(Tabular::SET_MPWIDTH, width);
135 set(Tabular::SET_PWIDTH, width);
137 dialog().view().update();
141 void ControlTabular::toggleMultiColumn()
143 set(Tabular::MULTICOLUMN);
144 dialog().view().update();
148 void ControlTabular::rotateTabular(bool yes)
151 set(Tabular::SET_ROTATE_TABULAR);
153 set(Tabular::UNSET_ROTATE_TABULAR);
157 void ControlTabular::rotateCell(bool yes)
160 set(Tabular::SET_ROTATE_CELL);
162 set(Tabular::UNSET_ROTATE_CELL);
166 void ControlTabular::halign(ControlTabular::HALIGN h)
168 Tabular::Feature num = Tabular::ALIGN_LEFT;
169 Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
173 num = Tabular::ALIGN_LEFT;
174 multi_num = Tabular::M_ALIGN_LEFT;
177 num = Tabular::ALIGN_CENTER;
178 multi_num = Tabular::M_ALIGN_CENTER;
181 num = Tabular::ALIGN_RIGHT;
182 multi_num = Tabular::M_ALIGN_RIGHT;
185 num = Tabular::ALIGN_BLOCK;
186 //multi_num: no equivalent
190 if (tabular().isMultiColumn(getActiveCell()))
197 void ControlTabular::valign(ControlTabular::VALIGN v)
199 Tabular::Feature num = Tabular::VALIGN_MIDDLE;
200 Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
204 num = Tabular::VALIGN_TOP;
205 multi_num = Tabular::M_VALIGN_TOP;
208 num = Tabular::VALIGN_MIDDLE;
209 multi_num = Tabular::M_VALIGN_MIDDLE;
212 num = Tabular::VALIGN_BOTTOM;
213 multi_num = Tabular::M_VALIGN_BOTTOM;
217 if (tabular().isMultiColumn(getActiveCell()))
224 void ControlTabular::booktabs(bool yes)
227 set(Tabular::SET_BOOKTABS);
229 set(Tabular::UNSET_BOOKTABS);
233 void ControlTabular::longTabular(bool yes)
236 set(Tabular::SET_LONGTABULAR);
238 set(Tabular::UNSET_LONGTABULAR);
241 } // namespace frontend