#include "InsetMathGrid.h"
#include "MathData.h"
-#include "MathMLStream.h"
#include "MathStream.h"
#include "BufferView.h"
#include <sstream>
-using lyx::support::bformat;
+
+namespace lyx {
+
+using support::bformat;
using std::endl;
using std::max;
using std::auto_ptr;
using std::istream;
using std::istringstream;
-using std::ostringstream;
using std::vector;
///
virtual string const inset2string(Buffer const &) const
{
- ostringstream data;
+ odocstringstream data;
//data << name() << " active_cell " << inset.getActCell() << '\n';
- data << name() << " active_cell " << 0 << '\n';
+ data << from_utf8(name()) << " active_cell " << 0 << '\n';
WriteStream ws(data);
inset_.write(ws);
- return data.str();
+ return to_utf8(data.str());
}
protected:
namespace {
-string verboseHLine(int n)
+docstring verboseHLine(int n)
{
- string res;
+ docstring res;
for (int i = 0; i < n; ++i)
res += "\\hline";
if (n)
//////////////////////////////////////////////////////////////
-InsetMathGrid::InsetMathGrid(char v, string const & h)
+InsetMathGrid::InsetMathGrid(char v, docstring const & h)
: InsetMathNest(guessColumns(h)),
rowinfo_(2),
colinfo_(guessColumns(h) + 1),
}
-InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, string const & h)
+InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, docstring const & h)
: InsetMathNest(m * n),
rowinfo_(n + 1),
colinfo_(m + 1),
}
-void InsetMathGrid::halign(string const & hh)
+void InsetMathGrid::halign(docstring const & hh)
{
col_type col = 0;
- for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
- char c = *it;
+ for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
+ char_type c = *it;
if (c == '|') {
colinfo_[col].lines_++;
} else if (col >= ncols()) {
// Only '|' is allowed in the last dummy column
break;
} else if (c == 'c' || c == 'l' || c == 'r') {
- colinfo_[col].align_ = c;
+ colinfo_[col].align_ = (char)c;
++col;
colinfo_[col].lines_ = 0;
} else {
}
-InsetMathGrid::col_type InsetMathGrid::guessColumns(string const & hh) const
+InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const
{
col_type col = 0;
- for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
+ for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
if (*it == 'c' || *it == 'l' || *it == 'r')
++col;
// let's have at least one column, even if we did not recognize its
}
-string InsetMathGrid::halign() const
+docstring InsetMathGrid::halign() const
{
- string res;
+ docstring res;
for (col_type col = 0; col < ncols(); ++col) {
- res += string(colinfo_[col].lines_, '|');
+ res += docstring(colinfo_[col].lines_, '|');
res += colinfo_[col].align_;
}
- return res + string(colinfo_[ncols()].lines_, '|');
+ return res + docstring(colinfo_[ncols()].lines_, '|');
}
}
-string InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) const
+docstring InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) const
{
- string eol;
+ docstring eol;
if (!rowinfo_[row].crskip_.zero())
- eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
+ eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
// make sure an upcoming '[' does not break anything
if (row + 1 < nrows()) {
// only add \\ if necessary
if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !emptyline))
- return string();
+ return docstring();
return (fragile ? "\\protect\\\\" : "\\\\") + eol;
}
-string InsetMathGrid::eocString(col_type col, col_type lastcol) const
+docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
{
if (col + 1 == lastcol)
- return string();
- return " & ";
+ return docstring();
+ return from_ascii(" & ");
}
}
-void InsetMathGrid::mathmlize(MathMLStream & os) const
+void InsetMathGrid::mathmlize(MathStream & os) const
{
os << MTag("mtable");
for (row_type row = 0; row < nrows(); ++row) {
void InsetMathGrid::write(WriteStream & os) const
{
- string eol;
+ docstring eol;
for (row_type row = 0; row < nrows(); ++row) {
os << verboseHLine(rowinfo_[row].lines_);
// don't write & and empty cells at end of line
if (!emptyline && row + 1 < nrows())
os << "\n";
}
- string const s = verboseHLine(rowinfo_[nrows()].lines_);
+ docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
if (!s.empty()) {
if (eol.empty()) {
if (os.fragile())
case LFUN_TABULAR_FEATURE: {
recordUndoInset(cur);
- //lyxerr << "handling tabular-feature " << lyx::to_utf8(cmd.argument()) << endl;
- istringstream is(lyx::to_utf8(cmd.argument()));
+ //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
+ istringstream is(to_utf8(cmd.argument()));
string s;
is >> s;
if (s == "valign-top")
case LFUN_PASTE: {
cur.message(_("Paste"));
- lyx::cap::replaceSelection(cur);
- istringstream is(lyx::to_utf8(cmd.argument()));
+ cap::replaceSelection(cur);
+ istringstream is(to_utf8(cmd.argument()));
int n = 0;
is >> n;
InsetMathGrid grid(1, 1);
// FIXME UNICODE
mathed_parse_normal(grid,
- lyx::to_utf8(lyx::cap::getSelection(cur.buffer(), n)));
+ to_utf8(lyx::cap::getSelection(cur.buffer(), n)));
if (grid.nargs() == 1) {
// single cell/part of cell
recordUndo(cur);
{
switch (cmd.action) {
case LFUN_TABULAR_FEATURE: {
- string const s = lyx::to_utf8(cmd.argument());
+ string const s = to_utf8(cmd.argument());
if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
status.enabled(false);
- status.message(lyx::from_utf8(N_("Only one row")));
+ status.message(from_utf8(N_("Only one row")));
return true;
}
if (ncols() <= 1 &&
(s == "delete-column" || s == "swap-column")) {
status.enabled(false);
- status.message(lyx::from_utf8(N_("Only one column")));
+ status.message(from_utf8(N_("Only one column")));
return true;
}
if ((rowinfo_[cur.row()].lines_ == 0 &&
(rowinfo_[cur.row() + 1].lines_ == 0 &&
s == "delete-hline-below")) {
status.enabled(false);
- status.message(lyx::from_utf8(N_("No hline to delete")));
+ status.message(from_utf8(N_("No hline to delete")));
return true;
}
(colinfo_[cur.col() + 1].lines_ == 0 &&
s == "delete-vline-right")) {
status.enabled(false);
- status.message(lyx::from_utf8(N_("No vline to delete")));
+ status.message(from_utf8(N_("No vline to delete")));
return true;
}
if (s == "valign-top" || s == "valign-middle" ||
else {
status.enabled(false);
status.message(bformat(
- lyx::from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
+ from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
}
status.setOnOff(s == "align-left" && halign(cur.col()) == 'l'
status.enable(false);
break;
}
- if (!lyx::support::contains("tcb", cmd.argument()[0])) {
+ if (!support::contains("tcb", cmd.argument()[0])) {
status.enable(false);
break;
}
return InsetMathNest::getStatus(cur, cmd, status);
}
}
+
+
+} // namespace lyx