+2000-05-17 Juergen Vigna <jug@sad.it>
+
+ * src/BufferView2.C (removeAutoInsets): fixed use of AutoDeleteInsets
+ which was wrong if the removing caused removing of rows!
+
+ * src/lyxlex_pimpl.C (next, nextToken): insert support for pushToken.
+ (pushToken): new function.
+
+ * src/text2.C (CutSelection): fix problem discovered with purify
+
2000-05-17 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/debug.C (showTags): enlarge the first column, now that we
{
LyXParagraph * par = buffer()->paragraph;
- LyXCursor cursor = text->cursor;
- LyXCursor tmpcursor = cursor;
- cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
- cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
+ LyXCursor tmpcursor = text->cursor;
+ LyXCursor cursor;
bool a = false;
while (par) {
+ // this has to be done before the delete
+ text->SetCursor(cursor, par, 0);
if (par->AutoDeleteInsets()){
a = true;
if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
- // this is possible now, since SetCursor takes
- // care about footnotes
- text->SetCursorIntern(par, 0);
- text->RedoParagraphs(text->cursor,
- text->cursor.par->Next());
+ text->RedoParagraphs(cursor,
+ cursor.par->Next());
text->FullRebreak();
}
}
par = par->next;
}
// avoid forbidden cursor positions caused by error removing
- if (cursor.pos > cursor.par->Last())
- cursor.pos = cursor.par->Last();
- text->SetCursorIntern(cursor.par, cursor.pos);
+ if (tmpcursor.pos > tmpcursor.par->Last())
+ tmpcursor.pos = tmpcursor.par->Last();
+ text->SetCursorIntern(tmpcursor.par, tmpcursor.pos);
return a;
}
par->SetFont(pos, font);
++pos;
} else if (token == "\\LyXTable") {
+#ifdef USE_TABULAR_INSETS
+ Inset * inset = new InsetTabular(this);
+ inset->Read(lex);
+ par->InsertChar(pos, LyXParagraph::META_INSET);
+ par->InsertInset(pos, inset);
+ par->SetFont(pos, font);
+ ++pos;
+#else
par->table = new LyXTable(lex);
+#endif
} else if (token == "\\hfill") {
par->InsertChar(pos, LyXParagraph::META_HFILL);
par->SetFont(pos, font);
LyXLayout const & style =
textclasslist.Style(users->buffer()->params.textclass,
par->layout);
- par->AutoDeleteInsets();
+#warning please check if this call is really needed!!!
+// par->AutoDeleteInsets();
// treat <toc> as a special case for compatibility with old code
if (par->GetChar(0) == LyXParagraph::META_INSET) {
LyXLayout const & style =
textclasslist.Style(users->buffer()->params.textclass,
par->layout);
- par->AutoDeleteInsets();
+#warning please check if this call is really needed!!!
+// par->AutoDeleteInsets();
// environment tag closing
for( ; depth > par->depth; --depth) {
button_length = width_collapsed(pain, labelfont) + 2;
button_top_y = -ascent_collapsed(pain, f);
button_bottom_y = descent_collapsed(pain, f);
+ top_x = int(x);
+ top_baseline = baseline;
if (collapsed) {
draw_collapsed(pain, f, baseline, x);
return;
}
- int top_x = int(x);
-
draw_collapsed(pain, f, baseline, x);
x -= TEXT_TO_INSET_OFFSET;
///
static int const TEXT_TO_BOTTOM_OFFSET = 2;
///
- explicit
+ explicit
InsetCollapsable(Buffer *);
///
~InsetCollapsable() {}
bool collapsed;
///
LColor::color framecolor;
+ ///
+ LyXFont labelfont;
private:
///
string label;
///
- LyXFont labelfont;
- ///
bool autocollapse;
///
mutable int
LyXFont font(LyXFont::ALL_SANE);
font.setLatex (LyXFont::ON);
real_current_font = current_font = font;
- LyXFont labelfont(LyXFont::ALL_SANE);
+ labelfont = LyXFont(LyXFont::ALL_SANE);
labelfont.decSize();
labelfont.decSize();
labelfont.setColor(LColor::ert);
- setLabelFont(labelfont);
setAutoCollapse(false);
setInsetName("ERT");
}
return true;
}
-LyXFont InsetFoot::GetDrawFont(LyXParagraph * par, int pos) const
+LyXFont InsetFoot::GetDrawFont(LyXParagraph * p, int pos) const
{
- LyXFont fn = InsetCollapsable::GetDrawFont(par, pos);
+ LyXFont fn = InsetCollapsable::GetDrawFont(p, pos);
fn.decSize();
fn.decSize();
return fn;
void InsetTabular::Read(LyXLex & lex)
{
-// bool old_format = (lex.GetString() == "\\LyXTable");
+ bool old_format = (lex.GetString() == "\\LyXTable");
string token;
if (tabular)
delete tabular;
tabular = new LyXTabular(this, lex);
+ init_inset = true;
+
+ if (old_format)
+ return;
+
lex.nextToken();
token = lex.GetString();
while (lex.IsOK() && (token != "\\end_inset")) {
lex.printError("Missing \\end_inset at this point. "
"Read: `$$Token'");
}
- init_inset = true;
}
{
int
i,
- sel_pos_start,
- sel_pos_end,
+ sel_start,
+ sel_end,
setLines = 0,
setAlign = LYX_ALIGN_LEFT,
lineSet;
}
if (hasCellSelection()) {
if (sel_cell_start > sel_cell_end) {
- sel_pos_start = sel_cell_end;
- sel_pos_end = sel_cell_start;
+ sel_start = sel_cell_end;
+ sel_end = sel_cell_start;
} else {
- sel_pos_start = sel_cell_start;
- sel_pos_end = sel_cell_end;
+ sel_start = sel_cell_start;
+ sel_end = sel_cell_end;
}
} else
- sel_pos_start = sel_pos_end = actcell;
+ sel_start = sel_end = actcell;
switch (feature) {
case LyXTabular::SET_PWIDTH:
{
}
case LyXTabular::TOGGLE_LINE_TOP:
lineSet = !tabular->TopLine(actcell);
- for(i=sel_pos_start; i<=sel_pos_end; ++i)
+ for(i=sel_start; i<=sel_end; ++i)
tabular->SetTopLine(i,lineSet);
UpdateLocal(bv, true);
break;
case LyXTabular::TOGGLE_LINE_BOTTOM:
lineSet = !tabular->BottomLine(actcell);
- for(i=sel_pos_start; i<=sel_pos_end; ++i)
+ for(i=sel_start; i<=sel_end; ++i)
tabular->SetBottomLine(i,lineSet);
UpdateLocal(bv, true);
break;
case LyXTabular::TOGGLE_LINE_LEFT:
lineSet = !tabular->LeftLine(actcell);
- for(i=sel_pos_start; i<=sel_pos_end; ++i)
+ for(i=sel_start; i<=sel_end; ++i)
tabular->SetLeftLine(i,lineSet);
UpdateLocal(bv, true);
break;
case LyXTabular::TOGGLE_LINE_RIGHT:
lineSet = !tabular->RightLine(actcell);
- for(i=sel_pos_start; i<=sel_pos_end; ++i)
+ for(i=sel_start; i<=sel_end; ++i)
tabular->SetRightLine(i,lineSet);
UpdateLocal(bv, true);
break;
case LyXTabular::ALIGN_LEFT:
case LyXTabular::ALIGN_RIGHT:
case LyXTabular::ALIGN_CENTER:
- for(i=sel_pos_start; i<=sel_pos_end; ++i)
+ for(i=sel_start; i<=sel_end; ++i)
tabular->SetAlignment(i,setAlign);
UpdateLocal(bv, true);
break;
case LyXTabular::MULTICOLUMN:
{
- if (tabular->row_of_cell(sel_pos_start) !=
- tabular->row_of_cell(sel_pos_end)) {
+ if (tabular->row_of_cell(sel_start) !=
+ tabular->row_of_cell(sel_end)) {
WriteAlert(_("Impossible Operation!"),
_("Multicolumns can only be horizontally."),
_("Sorry."));
int
s_start, s_end;
- if (sel_pos_start > sel_pos_end) {
- s_start = sel_pos_end;
- s_end = sel_pos_start;
+ if (sel_start > sel_end) {
+ s_start = sel_end;
+ s_end = sel_start;
} else {
- s_start = sel_pos_start;
- s_end = sel_pos_end;
+ s_start = sel_start;
+ s_end = sel_end;
}
tabular->SetMultiColumn(s_start, s_end);
cursor.pos = s_start;
case LyXTabular::SET_ALL_LINES:
setLines = 1;
case LyXTabular::UNSET_ALL_LINES:
- for(i=sel_pos_start; i<=sel_pos_end; ++i)
+ for(i=sel_start; i<=sel_end; ++i)
tabular->SetAllLines(i, setLines);
UpdateLocal(bv, true);
break;
tabular->SetRotateTabular(false);
break;
case LyXTabular::SET_ROTATE_CELL:
- for(i=sel_pos_start; i<=sel_pos_end; ++i)
+ for(i=sel_start; i<=sel_end; ++i)
tabular->SetRotateCell(i,true);
break;
case LyXTabular::UNSET_ROTATE_CELL:
- for(i=sel_pos_start; i<=sel_pos_end; ++i)
+ for(i=sel_start; i<=sel_end; ++i)
tabular->SetRotateCell(i,false);
break;
case LyXTabular::SET_LINEBREAKS:
what = !tabular->GetLinebreaks(actcell);
- for(i=sel_pos_start; i<=sel_pos_end; ++i)
+ for(i=sel_start; i<=sel_end; ++i)
tabular->SetLinebreaks(i,what);
break;
case LyXTabular::SET_LTFIRSTHEAD:
// Returns the width of a character at a certain spot
-int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
+int InsetText::SingleWidth(Painter & pain, LyXParagraph * p, int pos) const
{
- LyXFont font = GetDrawFont(par, pos);
- char c = par->GetChar(pos);
+ LyXFont font = GetDrawFont(p, pos);
+ char c = p->GetChar(pos);
if (IsPrintable(c)) {
return lyxfont::width(c, font);
} else if (c == LyXParagraph::META_INSET) {
- Inset const * tmpinset = par->GetInset(pos);
+ Inset const * tmpinset = p->GetInset(pos);
if (tmpinset)
return tmpinset->width(pain, font);
else
// Returns the width of a character at a certain spot
-void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
+void InsetText::SingleHeight(Painter & pain, LyXParagraph * p,int pos,
int & asc, int & desc) const
{
- LyXFont font = GetDrawFont(par, pos);
- char c = par->GetChar(pos);
+ LyXFont font = GetDrawFont(p, pos);
+ char c = p->GetChar(pos);
asc = desc = 0;
if (c == LyXParagraph::META_INSET) {
- Inset const * tmpinset=par->GetInset(pos);
+ Inset const * tmpinset=p->GetInset(pos);
if (tmpinset) {
asc = tmpinset->ascent(pain, font);
desc = tmpinset->descent(pain, font);
// smaller. (Asger)
// If position is -1, we get the layout font of the paragraph.
// If position is -2, we get the font of the manual label of the paragraph.
-LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
+LyXFont InsetText::GetFont(LyXParagraph * p, int pos) const
{
- char par_depth = par->GetDepth();
+ char par_depth = p->GetDepth();
LyXLayout const & layout =
- textclasslist.Style(buffer->params.textclass, par->GetLayout());
+ textclasslist.Style(buffer->params.textclass, p->GetLayout());
// We specialize the 95% common case:
- if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
+ if (p->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
if (pos >= 0) {
// 95% goes here
if (layout.labeltype == LABEL_MANUAL
- && pos < BeginningOfMainBody(par)) {
+ && pos < BeginningOfMainBody(p)) {
// 1% goes here
- return par->GetFontSettings(pos).realize(layout.reslabelfont);
+ return p->GetFontSettings(pos).realize(layout.reslabelfont);
} else
- return par->GetFontSettings(pos).realize(layout.resfont);
+ return p->GetFontSettings(pos).realize(layout.resfont);
} else {
// 5% goes here.
// process layoutfont for pos == -1 and labelfont for pos < -1
if (pos >= 0){
// 95% goes here
- if (pos < BeginningOfMainBody(par)) {
+ if (pos < BeginningOfMainBody(p)) {
// 1% goes here
layoutfont = layout.labelfont;
} else {
// 99% goes here
layoutfont = layout.font;
}
- tmpfont = par->GetFontSettings(pos);
+ tmpfont = p->GetFontSettings(pos);
tmpfont.realize(layoutfont);
} else{
// 5% goes here.
// Resolve against environment font information
//if (par->GetDepth()){ // already in while condition
- while (par && par_depth && !tmpfont.resolved()) {
- par = par->DepthHook(par_depth - 1);
- if (par) {
+ while (p && par_depth && !tmpfont.resolved()) {
+ p = p->DepthHook(par_depth - 1);
+ if (p) {
tmpfont.realize(textclasslist.Style(buffer->params.textclass,
- par->GetLayout()).font);
- par_depth = par->GetDepth();
+ p->GetLayout()).font);
+ par_depth = p->GetDepth();
}
}
tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
// the font for drawing may be different from the real font
-LyXFont InsetText::GetDrawFont(LyXParagraph * par, int pos) const
+LyXFont InsetText::GetDrawFont(LyXParagraph * p, int pos) const
{
- return GetFont(par, pos);
+ return GetFont(p, pos);
}
-int InsetText::BeginningOfMainBody(LyXParagraph * par) const
+int InsetText::BeginningOfMainBody(LyXParagraph * p) const
{
if (textclasslist.Style(buffer->params.textclass,
- par->GetLayout()).labeltype != LABEL_MANUAL)
- return 0;
+ p->GetLayout()).labeltype != LABEL_MANUAL)
+ return 0;
else
- return par->BeginningOfMainBody();
+ return p->BeginningOfMainBody();
}
}
+void LyXLex::pushToken(string const & pt)
+{
+ pimpl_->pushToken(pt);
+}
+
+
int LyXLex::FindToken(char const * str[])
{
int i = -1;
split a word if it contains a backslash.
*/
bool nextToken();
+ /// Push a token, that next token got from lyxlex.
+ void pushToken(string const &);
///
int GetLineNo() const;
bool LyXLex::Pimpl::next(bool esc /* = false */)
{
+ if (!pushTok.empty()) {
+ pushTok.copy(buff, string::npos);
+ buff[pushTok.length()] = '\0';
+ pushTok.erase();
+ return true;
+ }
if (!esc) {
unsigned char c = 0; // getc() returns an int
char cc = 0;
bool LyXLex::Pimpl::nextToken()
{
+ if (!pushTok.empty()) {
+ pushTok.copy(buff, string::npos);
+ buff[pushTok.length()] = '\0';
+ pushTok.erase();
+ return true;
+ }
+
status = 0;
while (is && !status) {
unsigned char c = 0;
buff[0] = '\0';
return false;
}
+
+
+void LyXLex::Pimpl::pushToken(string const & pt)
+{
+ pushTok = pt;
+}
bool nextToken();
+ void pushToken(string const &);
+
/// fb__ is only used to open files, the stream is accessed through is
std::filebuf fb__;
/// the stream that we use.
pushed_table * pushed;
///
int lineno;
+ ///
+ string pushTok;
};
#endif
#include "vspace.h"
#include "layout.h"
#include "lyx_gui_misc.h"
+#include "buffer.h"
#include "support/lstrings.h"
#include "support/lyxmanip.h"
#include "insets/insettabular.h"
l_getline(is, line);
if (!prefixIs(line, "<LyXTabular ")) {
- OldFormatRead(is, line);
+ OldFormatRead(lex, line);
return;
}
}
-void LyXTabular::OldFormatRead(istream & is, string fl)
+void LyXTabular::OldFormatRead(LyXLex & lex, string fl)
{
int version;
int i, j;
int g = 0;
int h = 0;
+ istream & is = lex.getStream();
string s;
s = fl;
if (s.length() > 8)
version = atoi(s.c_str() + 8);
else
version = 1;
+
+ int * cont_row_info;
+
if (version < 5) {
lyxerr << "Tabular format < 5 is not supported anymore\n"
"Get an older version of LyX (< 1.1.x) for conversion!"
getline(is, tmp);
}
}
- set_row_column_number_info();
- return;
- }
- is >> rows_arg >> columns_arg >> is_long_tabular_arg
- >> rotate_arg >> a >> b >> c >> d;
- Init(rows_arg, columns_arg);
- SetLongTabular(is_long_tabular_arg);
- SetRotateTabular(rotate_arg);
- endhead = a;
- endfirsthead = b;
- endfoot = c;
- endlastfoot = d;
- for (i = 0; i < rows_; ++i) {
- a = b = c = d = e = f = g = h = 0;
- is >> a >> b >> c >> d;
- row_info[i].top_line = a;
- row_info[i].bottom_line = b;
+ } else {
+ is >> rows_arg >> columns_arg >> is_long_tabular_arg
+ >> rotate_arg >> a >> b >> c >> d;
+ Init(rows_arg, columns_arg);
+ SetLongTabular(is_long_tabular_arg);
+ SetRotateTabular(rotate_arg);
+ endhead = a;
+ endfirsthead = b;
+ endfoot = c;
+ endlastfoot = d;
+ for (i = 0; i < rows_; ++i) {
+ a = b = c = d = e = f = g = h = 0;
+ is >> a >> b >> c >> d;
+ row_info[i].top_line = a;
+ row_info[i].bottom_line = b;
// row_info[i].is_cont_row = c;
- row_info[i].newpage = d;
- }
- for (i = 0; i < columns_; ++i) {
- string s1;
- string s2;
- is >> a >> b >> c;
- char ch; // skip '"'
- is >> ch;
- getline(is, s1, '"');
- is >> ch; // skip '"'
- getline(is, s2, '"');
- column_info[i].alignment = static_cast<char>(a);
- column_info[i].left_line = b;
- column_info[i].right_line = c;
- column_info[i].p_width = s1;
- column_info[i].align_special = s2;
- }
- for (i = 0; i < rows_; ++i) {
- for (j = 0; j < columns_; ++j) {
+ row_info[i].newpage = d;
+ }
+ for (i = 0; i < columns_; ++i) {
string s1;
string s2;
- is >> a >> b >> c >> d >> e >> f >> g;
- char ch;
- is >> ch; // skip '"'
+ is >> a >> b >> c;
+ char ch; // skip '"'
+ is >> ch;
getline(is, s1, '"');
is >> ch; // skip '"'
getline(is, s2, '"');
- cell_info[i][j].multicolumn = static_cast<char>(a);
- cell_info[i][j].alignment = static_cast<char>(b);
- cell_info[i][j].top_line = static_cast<char>(c);
- cell_info[i][j].bottom_line = static_cast<char>(d);
+ column_info[i].alignment = static_cast<char>(a);
+ column_info[i].left_line = b;
+ column_info[i].right_line = c;
+ column_info[i].p_width = s1;
+ column_info[i].align_special = s2;
+ }
+ for (i = 0; i < rows_; ++i) {
+ for (j = 0; j < columns_; ++j) {
+ string s1;
+ string s2;
+ is >> a >> b >> c >> d >> e >> f >> g;
+ char ch;
+ is >> ch; // skip '"'
+ getline(is, s1, '"');
+ is >> ch; // skip '"'
+ getline(is, s2, '"');
+ cell_info[i][j].multicolumn = static_cast<char>(a);
+ cell_info[i][j].alignment = static_cast<char>(b);
+ cell_info[i][j].top_line = static_cast<char>(c);
+ cell_info[i][j].bottom_line = static_cast<char>(d);
// cell_info[i][j].has_cont_row = static_cast<bool>(e);
- cell_info[i][j].rotate = static_cast<bool>(f);
- cell_info[i][j].linebreaks = static_cast<bool>(g);
- cell_info[i][j].align_special = s1;
- cell_info[i][j].p_width = s2;
+ cell_info[i][j].rotate = static_cast<bool>(f);
+ cell_info[i][j].linebreaks = static_cast<bool>(g);
+ cell_info[i][j].align_special = s1;
+ cell_info[i][j].p_width = s2;
+ }
}
}
set_row_column_number_info();
+ LyXParagraph * par = new LyXParagraph;
+ LyXParagraph * return_par = 0;
+ LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
+ LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
+ string token, tmptok;
+ int pos = 0;
+ char depth = 0;
+ LyXFont font(LyXFont::ALL_INHERIT);
+
+ while (lex.IsOK()) {
+ lex.nextToken();
+ token = lex.GetString();
+ if (token.empty())
+ continue;
+ if ((token == "\\layout") || (token == "\\end_float")) {
+ lex.pushToken(token);
+ break;
+ }
+ if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par,
+ return_par,
+ token, pos,
+ depth, font,
+ footnoteflag,
+ footnotekind))
+ {
+ // the_end read
+ lex.pushToken(token);
+ break;
+ }
+ if (return_par) {
+ lex.printError("New Paragraph allocated! This should not happen!");
+ lex.pushToken(token);
+ delete par;
+ par = return_par;
+ break;
+ }
+ }
+ // now we have the par we should fill the insets with this!
+ int cell = 0;
+ InsetText *inset = GetCellInset(cell);
+
+ for(int i=0; i < par->Last(); ++i) {
+ if (par->IsNewline(i)) {
+ ++cell;
+ if (cell > GetNumberOfCells()) {
+ lyxerr << "Some error in reading old table format occured!" <<
+ endl << "Terminating when reading cell[" << cell << "]!" <<
+ endl;
+ return;
+ }
+ inset = GetCellInset(cell);
+ continue;
+ }
+ par->CopyIntoMinibuffer(i);
+ inset->par->InsertFromMinibuffer(inset->par->Last());
+ }
}
ret += TeXCellPreamble(os, cell);
ret += GetCellInset(cell)->Latex(os, fragile, fp);
ret += TeXCellPostamble(os, cell);
- if (j < (columns_ - 1)) { // not last cell in row
+ if (!IsLastCellInRow(cell)) { // not last cell in row
os << "&" << endl;
++ret;
}
///
void Read(LyXLex &);
///
- void OldFormatRead(std::istream &, string);
+ void OldFormatRead(LyXLex &, string);
///
/// helper function for Latex returns number of newlines
///
cursor.par = sel_end_cursor.par = endpar;
cursor.pos = sel_end_cursor.pos;
}
- endpar = sel_end_cursor.par->Next();
+ endpar = endpar->Next();
// sometimes necessary
if (doclear)