From 570e57d5b9be102355a5c2088bec53b3da248fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Vigna?= Date: Thu, 4 May 2000 08:14:34 +0000 Subject: [PATCH] Commiting my changes till now. Mainly (only?) changes to make text-insets and tabular insets work. After all the complaints about the tabular-save format I redid it completely, have a look ;) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@711 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 34 ++ src/buffer.C | 96 ++-- src/buffer.h | 6 + src/insets/insetfoot.C | 9 +- src/insets/insettabular.C | 414 +++++++++----- src/insets/insettabular.h | 27 +- src/insets/insettext.C | 184 +++--- src/insets/insettext.h | 19 +- src/insets/lyxinset.h | 2 - src/lyxcursor.h | 5 + src/lyxtext.h | 4 + src/paragraph.C | 6 +- src/table.C | 3 +- src/tabular.C | 1122 +++++++++++++++++++++---------------- src/tabular.h | 108 ++-- src/texrow.h | 3 + src/text2.C | 85 ++- 17 files changed, 1323 insertions(+), 804 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9eaa9fa1d6..179ff7afd7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,37 @@ +2000-05-04 Juergen Vigna + + * src/insets/insettext.C: Prepared all for inserting of multiple + paragraphs. Still display stuff to do (alignment and other things), + but I would like to use LyXText to do this when we cleaned out the + table-support stuff. + + * src/insets/insettabular.C: Changed lot of stuff and added lots + of functionality still a lot to do. + + * src/tabular.C: Various functions changed name and moved to be + const functions. Added new Read and Write functions and changed + lots of things so it works good with tabular-insets (also removed + some stuff which is not needed anymore * hacks *). + + * src/lyxcursor.h: added operators == and != which just look if + par and pos are (not) equal. + + * src/buffer.C (latexParagraphs): inserted this function to latex + all paragraphs form par to endpar as then I can use this too for + text-insets. + + * src/text2.C (SetLayout): Changed this to use a cursor this is needed + so that I can call this to from text insets with their own cursor. + + * src/buffer.C (makeLaTeXFile): added the output of one \n after the + output off all paragraphs (because of the fix below)! + + * src/paragraph.C (TeXOnePar): removed output of \n when we are in + the very last paragraph (this could be also the last paragraph of an + inset!) + + * src/texrow.h: added rows() call which returns the count-variable. + 2000-05-03 Jose Abilio Oliveira Matos * lib/lyxrc.example: fix examples for exporting SGML to HTML. diff --git a/src/buffer.C b/src/buffer.C index 1509fb19fb..ff33b4b0b3 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -71,6 +71,7 @@ #include "insets/insetert.h" #include "insets/insetgraphics.h" #include "insets/insetfoot.h" +#include "insets/insettabular.h" #include "support/filetools.h" #include "support/path.h" #include "LaTeX.h" @@ -822,6 +823,13 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par, par->InsertInset(pos, inset); par->SetFont(pos, font); ++pos; + } else if (tmptok == "Tabular") { + Inset * inset = new InsetTabular(this); + inset->Read(lex); + par->InsertChar(pos, LyXParagraph::META_INSET); + par->InsertInset(pos, inset); + par->SetFont(pos, font); + ++pos; } else if (tmptok == "Text") { Inset * inset = new InsetText(this); inset->Read(lex); @@ -2025,6 +2033,52 @@ void Buffer::makeLaTeXFile(string const & fname, texrow.newline(); } + latexParagraphs(ofs, paragraph, 0, texrow); + + // add this just in case after all the paragraphs + ofs << endl; + texrow.newline(); + + if (!lyxrc.language_auto_end && params.language != "default") { + ofs << subst(lyxrc.language_command_end, "$$lang", + params.language) + << endl; + texrow.newline(); + } + + if (!only_body) { + ofs << "\\end{document}\n"; + texrow.newline(); + + lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl; + } else { + lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made." + << endl; + } + + // Just to be sure. (Asger) + texrow.newline(); + + // tex_code_break_column's value is used to decide + // if we are in batchmode or not (within mathed_write() + // in math_write.C) so we must set it to a non-zero + // value when we leave otherwise we save incorrect .lyx files. + tex_code_break_column = lyxrc.ascii_linelen; + + ofs.close(); + if (ofs.fail()) { + lyxerr << "File was not closed properly." << endl; + } + + lyxerr.debug() << "Finished making latex file." << endl; +} + +// +// LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end +// +void Buffer::latexParagraphs(ostream & ofs, LyXParagraph *par, + LyXParagraph *endpar, TexRow & texrow) +{ bool was_title = false; bool already_title = false; #ifdef HAVE_SSTREAM @@ -2035,10 +2089,8 @@ void Buffer::makeLaTeXFile(string const & fname, TexRow ft_texrow; int ftcount = 0; - LyXParagraph * par = paragraph; - // if only_body - while (par) { + while (par != endpar) { #ifndef HAVE_SSTREAM ostrstream ftnote; if (tmpholder) { @@ -2048,7 +2100,7 @@ void Buffer::makeLaTeXFile(string const & fname, } #endif if (par->IsDummy()) - lyxerr[Debug::LATEX] << "Error in MakeLateXFile." + lyxerr[Debug::LATEX] << "Error in latexParagraphs." << endl; LyXLayout const & layout = textclasslist.Style(params.textclass, @@ -2056,7 +2108,7 @@ void Buffer::makeLaTeXFile(string const & fname, if (layout.intitle) { if (already_title) { - lyxerr <<"Error in MakeLatexFile: You" + lyxerr <<"Error in latexParagraphs: You" " should not mix title layouts" " with normal ones." << endl; } else @@ -2114,42 +2166,8 @@ void Buffer::makeLaTeXFile(string const & fname, ofs << "\\maketitle\n"; texrow.newline(); } - - if (!lyxrc.language_auto_end && params.language != "default") { - ofs << subst(lyxrc.language_command_end, "$$lang", - params.language) - << endl; - texrow.newline(); - } - - if (!only_body) { - ofs << "\\end{document}\n"; - texrow.newline(); - - lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl; - } else { - lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made." - << endl; - } - - // Just to be sure. (Asger) - texrow.newline(); - - // tex_code_break_column's value is used to decide - // if we are in batchmode or not (within mathed_write() - // in math_write.C) so we must set it to a non-zero - // value when we leave otherwise we save incorrect .lyx files. - tex_code_break_column = lyxrc.ascii_linelen; - - ofs.close(); - if (ofs.fail()) { - lyxerr << "File was not closed properly." << endl; - } - - lyxerr.debug() << "Finished making latex file." << endl; } - bool Buffer::isLatex() const { return textclasslist.TextClass(params.textclass).outputType() == LATEX; diff --git a/src/buffer.h b/src/buffer.h index 32f669e59a..991d166c78 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -153,6 +153,12 @@ public: void makeLaTeXFile(string const & filename, string const & original_path, bool nice, bool only_body = false); + // + // LaTeX all paragraphs from par to endpar, + // if endpar == 0 then to the end + // + void latexParagraphs(ostream & os, LyXParagraph *par, + LyXParagraph *endpar, TexRow & texrow); /// int runLaTeX(); diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index 4b09114c09..07c8335353 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -54,15 +54,12 @@ char const * InsetFoot::EditMessage() const int InsetFoot::Latex(ostream & os, bool fragile, bool fp) const { - if (fragile) - os << "\\footnote{"; // was footnotemark but that won't work - else - os << "\\footnote{"; + os << "\\footnote{%" << endl; int i = InsetText::Latex(os, fragile, fp); - os << "}"; + os << "}%" << endl; - return i; + return i + 2; } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index c958ec13ef..8e6e8e98dc 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -26,6 +26,7 @@ #include "LaTeXFeatures.h" #include "Painter.h" #include "font.h" +#include "lyxtext.h" #include "insets/insettext.h" const int ADD_TO_HEIGHT = 2; @@ -51,7 +52,7 @@ InsetTabular::InsetTabular(Buffer * buf, int rows, int columns) buffer = buf; cursor_visible = false; cursor.x_fix = -1; - sel_pos_start = sel_pos_end = 0; + actcell = cursor.pos = sel_pos_start = sel_pos_end = 0; no_selection = false; init = true; } @@ -64,7 +65,7 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf) buffer = buf; cursor_visible = false; cursor.x_fix = -1; - sel_pos_start = sel_pos_end = 0; + actcell = cursor.pos = sel_pos_start = sel_pos_end = 0; no_selection = false; init = true; } @@ -72,7 +73,7 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf) InsetTabular::~InsetTabular() { - delete tabular; + delete tabular; } @@ -85,18 +86,31 @@ Inset * InsetTabular::Clone() const void InsetTabular::Write(ostream & os) const { - os << "\\begin_inset Tabular\n"; - tabular->Write(os,false); - os << "\\end_inset\n"; + os << " Tabular" << endl; + tabular->Write(os); } void InsetTabular::Read(LyXLex & lex) { - delete tabular; +// bool old_format = (lex.GetString() == "\\LyXTable"); + string token; -// bool old_format = (lex.GetString() == "\\LyXTabular"); + if (tabular) + delete tabular; tabular = new LyXTabular(lex, buffer); + + lex.nextToken(); + token = lex.GetString(); + while (lex.IsOK() && (token != "\\end_inset")) { + lex.nextToken(); + token = lex.GetString(); + } + if (token != "\\end_inset") { + lex.printError("Missing \\end_inset at this point. " + "Read: `$$Token'"); + } + tabular->SetLongTabular(true); init = true; } @@ -107,7 +121,7 @@ int InsetTabular::ascent(Painter & pain, LyXFont const & font) const calculate_width_of_cells(pain, font); init = false; } - return tabular->AscentOfRow(0); + return tabular->GetAscentOfRow(0); } @@ -117,7 +131,7 @@ int InsetTabular::descent(Painter & pain, LyXFont const & font) const calculate_width_of_cells(pain, font); init = false; } - return tabular->HeightOfTabular() - tabular->AscentOfRow(0); + return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0); } @@ -127,7 +141,7 @@ int InsetTabular::width(Painter & pain, LyXFont const & font) const calculate_width_of_cells(pain, font); init = false; } - return tabular->WidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH); + return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH); } @@ -136,28 +150,64 @@ void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline, { int i, j, cell=0; int nx; + float cx; UpdatableInset::draw(pain,font,baseline,x); - if (top_x != int(x)) { - int ox = top_x; + if ((top_x != int(x)) || (top_baseline != baseline)) { top_x = int(x); - setPos(pain, cursor.x - ox - 2, cursor.y); + top_baseline = baseline; + resetPos(pain); } - top_baseline = baseline; - calculate_width_of_cells(pain, font); for(i=0;irows();++i) { nx = int(x); for(j=0;jcolumns();++j) { + cx = nx + tabular->GetBeginningOfTextInCell(cell); + tabular->GetCellInset(cell)->draw(pain, font, baseline, cx); DrawCellLines(pain, nx, baseline, i, cell); - nx += tabular->WidthOfColumn(cell); + nx += tabular->GetWidthOfColumn(cell); ++cell; } - baseline += tabular->DescentOfRow(i) + tabular->AscentOfRow(i+1) - + tabular->AdditionalHeight(cell+1); + baseline += tabular->GetDescentOfRow(i) + tabular->GetAscentOfRow(i+1) + + tabular->GetAdditionalHeight(cell+1); } } +void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline, + int row, int cell) const +{ + int x2 = x + tabular->GetWidthOfColumn(cell); + bool on_off; + + if (!tabular->TopAlreadyDrawed(cell)) { + on_off = !tabular->TopLine(cell); + pain.line(x, baseline - tabular->GetAscentOfRow(row), + x2, baseline - tabular->GetAscentOfRow(row), + on_off ? LColor::tabularonoffline:LColor::tabularline, + on_off ? Painter::line_onoffdash:Painter::line_solid); + } + on_off = !tabular->BottomLine(cell); + pain.line(x,baseline + tabular->GetDescentOfRow(row), + x2, baseline + tabular->GetDescentOfRow(row), + on_off ? LColor::tabularonoffline:LColor::tabularline, + on_off ? Painter::line_onoffdash:Painter::line_solid); + if (!tabular->LeftAlreadyDrawed(cell)) { + on_off = !tabular->LeftLine(cell); + pain.line(x, baseline - tabular->GetAscentOfRow(row), + x, baseline + tabular->GetDescentOfRow(row), + on_off ? LColor::tabularonoffline:LColor::tabularline, + on_off ? Painter::line_onoffdash:Painter::line_solid); + } + on_off = !tabular->RightLine(cell); + pain.line(x2 - tabular->GetAdditionalWidth(cell), + baseline - tabular->GetAscentOfRow(row), + x2 - tabular->GetAdditionalWidth(cell), + baseline + tabular->GetDescentOfRow(row), + on_off ? LColor::tabularonoffline:LColor::tabularline, + on_off ? Painter::line_onoffdash:Painter::line_solid); +} + + char const * InsetTabular::EditMessage() const { return _("Opened Tabular Inset"); @@ -176,7 +226,10 @@ void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button) sel_pos_start = sel_pos_end = inset_pos = inset_x = inset_y = 0; setPos(bv->painter(), x, y); sel_pos_start = sel_pos_end = cursor.pos; -// bv->text->FinishUndo(); + bv->text->FinishUndo(); + if (InsetHit(bv, x, y)) { + ActivateCellInset(bv, x, y, button); + } UpdateLocal(bv, true); // bv->getOwner()->getPopups().updateFormTabular(); } @@ -184,10 +237,11 @@ void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button) void InsetTabular::InsetUnlock(BufferView * bv) { - if (the_locking_inset) + if (the_locking_inset) { the_locking_inset->InsetUnlock(bv); + the_locking_inset = 0; + } HideInsetCursor(bv); - the_locking_inset = 0; if (hasCharSelection()) { sel_pos_start = sel_pos_end = cursor.pos; UpdateLocal(bv, false); @@ -196,35 +250,57 @@ void InsetTabular::InsetUnlock(BufferView * bv) no_selection = false; } - -bool InsetTabular::LockInsetInInset(UpdatableInset *) -{ - return true; -} - - -bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset, - bool lr) -{ - if (!the_locking_inset) - return false; - if (the_locking_inset == inset) { - the_locking_inset->InsetUnlock(bv); - the_locking_inset = 0; - if (lr) - moveRight(bv); - return true; - } - return the_locking_inset->UnlockInsetInInset(bv, inset, lr); -} - - void InsetTabular::UpdateLocal(BufferView * bv, bool flag) { -// resetPos(); + if (flag) + calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE)); bv->updateInset(this, flag); } +bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset) +{ + lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <GetCellInset(actcell)) { + lyxerr[Debug::INSETS] << "OK" << endl; + the_locking_inset = tabular->GetCellInset(actcell); + resetPos(bv->painter()); + inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell); + inset_y = cursor.y; + inset_pos = cursor.pos; + return true; + } else if (the_locking_inset && (the_locking_inset == inset)) { + if (cursor.pos == inset_pos) { + lyxerr[Debug::INSETS] << "OK" << endl; + resetPos(bv->painter()); + inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell); + inset_y = cursor.y; + } else { + lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl; + } + } else if (the_locking_inset) { + lyxerr[Debug::INSETS] << "MAYBE" << endl; + return the_locking_inset->LockInsetInInset(bv, inset); + } + lyxerr[Debug::INSETS] << "NOT OK" << endl; + return false; +} + +bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset, + bool lr) +{ + if (!the_locking_inset) + return false; + if (the_locking_inset == inset) { + the_locking_inset->InsetUnlock(bv); + the_locking_inset = 0; + if (lr) + moveRight(bv, false); + return true; + } + return the_locking_inset->UnlockInsetInInset(bv, inset, lr); +} bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset) { @@ -237,35 +313,53 @@ bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset) } +int InsetTabular::InsetInInsetY() +{ + if (!the_locking_inset) + return 0; + + return (inset_y + the_locking_inset->InsetInInsetY()); +} + void InsetTabular::InsetButtonRelease(BufferView * bv, int x, int y, int button) { if (the_locking_inset) { - the_locking_inset->InsetButtonRelease(bv, x-inset_x,y-inset_y,button); + the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button); return; } no_selection = false; } -void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int) +void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button) { if (hasCharSelection()) { sel_pos_start = sel_pos_end = 0; UpdateLocal(bv, false); } no_selection = false; - if (the_locking_inset) { - // otherwise only unlock the_locking_inset + + int oldcell = actcell; + + setPos(bv->painter(), x, y); + + bool inset_hit = InsetHit(bv, x, y); + + if ((oldcell == actcell) && the_locking_inset && inset_hit) { + the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button); + return; + } else if (the_locking_inset) { the_locking_inset->InsetUnlock(bv); } -#if 0 - int oldcell = actcell; -#endif - setPos(bv->painter(),x,y); the_locking_inset = 0; sel_pos_start = sel_pos_end = cursor.pos; sel_cell_start = sel_cell_end = actcell; + if (inset_hit && bv->the_locking_inset) { + ActivateCellInset(bv, x, y, button); + the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button); + } + #if 0 if (button == 3) bview->getOwner()->getPopups().showFormTabular(); @@ -319,7 +413,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED) || (result == DISPATCHED_NOUPDATE)) { - resetPos(bv); + resetPos(bv->painter()); return result; } result=DISPATCHED; @@ -335,15 +429,15 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, if (result == DISPATCHED_NOUPDATE) return result; else if (result == DISPATCHED) { - setWidthOfCell(cursor.pos,actcell,actrow); + bool upd = SetCellDimensions(bv->painter(), actcell, actrow); the_locking_inset->ToggleInsetCursor(bv); - UpdateLocal(bv, false); + UpdateLocal(bv, upd); the_locking_inset->ToggleInsetCursor(bv); return result; } else if (result == FINISHED) { if ((action == LFUN_RIGHT) || (action == -1)) { cursor.pos = inset_pos + 1; - resetPos(bv); + resetPos(bv->painter()); } the_locking_inset=0; result = DISPATCHED; @@ -358,7 +452,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, break; // --- Cursor Movements --------------------------------------------- case LFUN_RIGHTSEL: - moveRight(bv); + moveRight(bv, false); sel_pos_end = cursor.pos; UpdateLocal(bv, false); break; @@ -371,12 +465,12 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, sel_pos_start = sel_pos_end = cursor.pos; break; case LFUN_LEFTSEL: - moveLeft(); + moveLeft(bv, false); sel_pos_end = cursor.pos; UpdateLocal(bv, false); break; case LFUN_LEFT: - result= moveLeft(); + result = moveLeft(bv); if (hasCharSelection()) { sel_pos_start = sel_pos_end = cursor.pos; UpdateLocal(bv, false); @@ -476,63 +570,28 @@ void InsetTabular::Validate(LaTeXFeatures & features) const void InsetTabular::calculate_width_of_cells(Painter & pain, LyXFont const & font) const { - int cell = -1; - int maxAsc, maxDesc; - InsetText * inset; + int cell = -1; + int maxAsc, maxDesc; + InsetText * inset; - for(int i = 0; i < tabular->rows(); ++i) { - maxAsc = maxDesc = 0; - for(int j= 0; j < tabular->columns(); ++j) { - if (tabular->IsPartOfMultiColumn(i,j)) - continue; - ++cell; - inset = tabular->GetCellInset(cell); - maxAsc = max(maxAsc, inset->ascent(pain, font)); - maxDesc = max(maxDesc, inset->descent(pain, font)); - tabular->SetWidthOfCell(cell, - inset->width(pain, font)); - } - tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT); - tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT); + for(int i = 0; i < tabular->rows(); ++i) { + maxAsc = maxDesc = 0; + for(int j= 0; j < tabular->columns(); ++j) { + if (tabular->IsPartOfMultiColumn(i,j)) + continue; + ++cell; + inset = tabular->GetCellInset(cell); + maxAsc = max(maxAsc, inset->ascent(pain, font)); + maxDesc = max(maxDesc, inset->descent(pain, font)); + tabular->SetWidthOfCell(cell, inset->width(pain, font)); } + tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT); + tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT); + } } -void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline, - int row, int cell) const -{ - // Juergen, have you thought about drawing the on-off lines in a - // different color (gray of some kind), especially since those - // lines will not be there on the hardcopy anyway. (Lgb) - int x2 = x + tabular->WidthOfColumn(cell); - bool on_off = !tabular->TopLine(cell); - - if (!tabular->TopAlreadyDrawed(cell)) - pain.line(x, baseline - tabular->AscentOfRow(row), - x2, baseline - tabular->AscentOfRow(row), - on_off ? LColor::tabularonoffline:LColor::tabularline, - on_off ? Painter::line_onoffdash:Painter::line_solid); - on_off = !tabular->BottomLine(cell); - pain.line(x,baseline + tabular->DescentOfRow(row), - x2, baseline + tabular->DescentOfRow(row), - on_off ? LColor::tabularonoffline:LColor::tabularline, - on_off ? Painter::line_onoffdash:Painter::line_solid); - on_off = !tabular->LeftLine(cell); - pain.line(x, baseline - tabular->AscentOfRow(row), - x, baseline + tabular->DescentOfRow(row), - on_off ? LColor::tabularonoffline:LColor::tabularline, - on_off ? Painter::line_onoffdash:Painter::line_solid); - on_off = !tabular->RightLine(cell); - pain.line(x2 - tabular->AdditionalWidth(cell), - baseline - tabular->AscentOfRow(row), - x2 - tabular->AdditionalWidth(cell), - baseline + tabular->DescentOfRow(row), - on_off ? LColor::tabularonoffline:LColor::tabularline, - on_off ? Painter::line_onoffdash:Painter::line_solid); -} - - -void InsetTabular::GetCursorPos(int & x, int & y) +void InsetTabular::GetCursorPos(int & x, int & y) const { x = cursor.x-top_x; y = cursor.y; @@ -580,80 +639,120 @@ void InsetTabular::HideInsetCursor(BufferView * bv) } -void InsetTabular::setPos(Painter &, int x, int y) const +void InsetTabular::setPos(Painter & pain, int x, int y) const { cursor.y = cursor.pos = actcell = actrow = actcol = 0; - int ly = tabular->DescentOfRow(actrow); + int ly = tabular->GetDescentOfRow(actrow); // first search the right row while((ly < y) && (actrow < tabular->rows())) { - cursor.y += tabular->DescentOfRow(actrow) + - tabular->AscentOfRow(actrow+1) + - tabular->AdditionalHeight(tabular->GetCellNumber(actcol,actrow+1)); + cursor.y += tabular->GetDescentOfRow(actrow) + + tabular->GetAscentOfRow(actrow+1) + + tabular->GetAdditionalHeight(tabular->GetCellNumber(actcol,actrow+1)); ++actrow; - ly = cursor.y + tabular->DescentOfRow(actrow); + ly = cursor.y + tabular->GetDescentOfRow(actrow); } actcell = tabular->GetCellNumber(actcol, actrow); // now search the right column - int lx = tabular->GetWidthOfCell(actcell); - for(; - !tabular->IsLastCellInRow(actcell) && (lx < x); - ++actcell,lx += tabular->GetWidthOfCell(actcell)) {} - cursor.x = lx - tabular->GetWidthOfCell(actcell) + top_x + 2; + int lx = tabular->GetWidthOfColumn(actcell) - + tabular->GetAdditionalWidth(actcell); + for(; !tabular->IsLastCellInRow(actcell) && (lx < x); + ++actcell,lx += tabular->GetWidthOfColumn(actcell) + + tabular->GetAdditionalWidth(actcell-1)); + cursor.pos = ((actcell+1) * 2) - 1; + resetPos(pain); + if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) { + cursor.x = lx + top_x - 2; + } else { + --cursor.pos; + cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2; + } + resetPos(pain); } -void InsetTabular::resetPos(BufferView * bv) +void InsetTabular::resetPos(Painter & pain) const { actrow = cursor.y = actcol = 0; int cell = 0; for(; (cellIsLastRow(cell); ++cell) { if (tabular->IsLastCellInRow(cell)) { - cursor.y += tabular->DescentOfRow(actrow) + - tabular->AscentOfRow(actrow+1) + - tabular->AdditionalHeight(cell+1); + cursor.y += tabular->GetDescentOfRow(actrow) + + tabular->GetAscentOfRow(actrow+1) + + tabular->GetAdditionalHeight(cell+1); ++actrow; } } for(cell=actcell;!tabular->IsFirstCellInRow(cell);--cell) ; - int lx = tabular->GetWidthOfCell(actcell); + int lx = tabular->GetWidthOfColumn(actcell); for(; (cell < actcell); ++cell) { - lx += tabular->GetWidthOfCell(actcell); + lx += tabular->GetWidthOfColumn(cell); ++actcol; } - cursor.x = lx - tabular->GetWidthOfCell(actcell) + top_x + 2; + cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2; if (cursor.pos % 2) { LyXFont font(LyXFont::ALL_SANE); - cursor.x += tabular->GetCellInset(actcell)->width(bv->painter(),font); + cursor.x += tabular->GetCellInset(actcell)->width(pain,font) + + tabular->GetBeginningOfTextInCell(actcell); } } -void InsetTabular::setWidthOfCell(int, int, int) +bool InsetTabular::SetCellDimensions(Painter & pain, int cell, int row) { + InsetText * inset = tabular->GetCellInset(cell); + LyXFont font(LyXFont::ALL_SANE); + int asc = inset->ascent(pain, font) + ADD_TO_HEIGHT; + int desc = inset->descent(pain, font) + ADD_TO_HEIGHT; + int maxAsc = tabular->GetAscentOfRow(row); + int maxDesc = tabular->GetDescentOfRow(row); + bool ret = tabular->SetWidthOfCell(cell, inset->width(pain, font)); + + if (maxAsc < asc) { + ret = true; + tabular->SetAscentOfRow(row, asc); + } + if (maxDesc < desc) { + ret = true; + tabular->SetDescentOfRow(row, desc); + } + return ret; } -UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv) +UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock) { if (cursor.pos % 2) { // behind the inset ++actcell; if (actcell >= tabular->GetNumberOfCells()) return FINISHED; ++cursor.pos; + } else if (lock) { + if (ActivateCellInset(bv)) + return DISPATCHED; } else { // before the inset ++cursor.pos; } - resetPos(bv); + resetPos(bv->painter()); return DISPATCHED_NOUPDATE; } -UpdatableInset::RESULT InsetTabular::moveLeft() +UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock) { + if (!cursor.pos) + return FINISHED; + --cursor.pos; + if (cursor.pos % 2) { // behind the inset + --actcell; + } else if (lock) { // behind the inset + if (ActivateCellInset(bv, -1, -1)) + return DISPATCHED; + } + resetPos(bv->painter()); return DISPATCHED_NOUPDATE; } @@ -688,7 +787,7 @@ bool InsetTabular::Delete() } -void InsetTabular::SetFont(LyXFont const &) +void InsetTabular::SetFont(BufferView *, LyXFont const &, bool) { } @@ -1036,3 +1135,44 @@ void InsetTabular::TabularFeatures(int, string) void InsetTabular::RemoveTabularRow() { } + +bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button) +{ + // the cursor.pos has to be before the inset so if it isn't now just + // reset the curor pos first! + if (cursor.pos % 2) { // behind the inset + --cursor.pos; + resetPos(bv->painter()); + } + UpdatableInset * inset = + static_cast(tabular->GetCellInset(actcell)); + LyXFont font(LyXFont::ALL_SANE); + if (x < 0) + x = inset->width(bv->painter(), font) + top_x; + if (y < 0) + y = inset->descent(bv->painter(), font); + inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell); + inset_y = cursor.y; + inset->Edit(bv, x-inset_x, y-inset_y, button); + if (!the_locking_inset) + return false; + UpdateLocal(bv, true); + return true; +} + +bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const +{ + InsetText * inset = tabular->GetCellInset(actcell); + int x1 = x + top_x; + + if (cursor.pos % 2) { // behind the inset + return (((x+top_x) < cursor.x) && + ((x+top_x) > (cursor.x - inset->width(bv->painter(), + LyXFont(LyXFont::ALL_SANE))))); + } else { + int x2 = cursor.x + tabular->GetBeginningOfTextInCell(actcell); + return ((x1 > x2) && + (x1 < (x2 + inset->width(bv->painter(), + LyXFont(LyXFont::ALL_SANE))))); + } +} diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index f47b2fee59..9070104ea8 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -88,14 +88,16 @@ public: /// void InsetUnlock(BufferView *); /// - bool LockInsetInInset(UpdatableInset *); + void UpdateLocal(BufferView *, bool flag = true); + /// + bool LockInsetInInset(BufferView *, UpdatableInset *); /// bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr=false); /// - void UpdateLocal(BufferView *, bool flag = true); - /// bool UpdateInsetInInset(BufferView *, Inset *); /// + int InsetInInsetY(); + /// bool display() const { return tabular->IsLongTabular(); } /// void InsetButtonRelease(BufferView *, int, int, int); @@ -120,7 +122,7 @@ public: /// Inset::Code LyxCode() const { return Inset::TABULAR_CODE; } /// - void GetCursorPos(int & x, int & y); + void GetCursorPos(int & x, int & y) const; /// void ToggleInsetCursor(BufferView *); /// @@ -128,7 +130,7 @@ public: /// int GetActCell() { return actcell; } /// - void SetFont(LyXFont const &); + void SetFont(BufferView *, LyXFont const &, bool toggleall = false); /// /// Public structures and variables /// @@ -145,27 +147,32 @@ private: /// void setPos(Painter &, int x, int y) const; /// - void setWidthOfCell(int pos, int cell, int row); + bool SetCellDimensions(Painter & pain, int cell, int row); /// - UpdatableInset::RESULT moveRight(BufferView *); - UpdatableInset::RESULT moveLeft(); + UpdatableInset::RESULT moveRight(BufferView *, bool lock=true); + UpdatableInset::RESULT moveLeft(BufferView *, bool lock=true); UpdatableInset::RESULT moveUp(); UpdatableInset::RESULT moveDown(); bool moveNextCell(); bool movePrevCell(); bool Delete(); /// - void resetPos(BufferView *); + void resetPos(Painter &) const; /// void RemoveTabularRow(); /// bool hasCharSelection() const {return (sel_pos_start != sel_pos_end);} bool hasCellSelection() const {return hasCharSelection() && (sel_cell_start != sel_cell_end);} + /// + bool ActivateCellInset(BufferView *, int x=0, int y=0, int button=0); + /// + bool InsetHit(BufferView * bv, int x, int y) const; + /// /// Private structures and variables /// - UpdatableInset + InsetText * the_locking_inset; Buffer * buffer; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 05fe43508b..b648a2407c 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -53,6 +53,8 @@ #include "lyxcursor.h" #include "CutAndPaste.h" #include "font.h" +#include "minibuffer.h" +#include "toolbar.h" using std::ostream; using std::ifstream; @@ -61,6 +63,7 @@ using std::min; using std::max; extern unsigned char getCurrentTextClass(Buffer *); +extern LyXTextClass::size_type current_layout; InsetText::InsetText(Buffer * buf) @@ -84,7 +87,6 @@ void InsetText::init(Buffer * buf, InsetText const * ins) buffer = buf; cursor_visible = false; cursor.x_fix = -1; - selection_start = selection_end = 0; interline_space = 1; no_selection = false; init_inset = true; @@ -93,14 +95,13 @@ void InsetText::init(Buffer * buf, InsetText const * ins) autoBreakRows = false; xpos = 0.0; if (ins) { - if (par) - delete par; - par = ins->par->Clone(); + SetParagraphData(ins->par); autoBreakRows = ins->autoBreakRows; } par->SetInsetOwner(this); cursor.par = par; cursor.pos = 0; + selection_start_cursor = selection_end_cursor = cursor; } @@ -241,12 +242,12 @@ void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos, return; int s_start, s_end; - if (selection_start > selection_end) { - s_start = selection_end; - s_end = selection_start; + if (selection_start_cursor.pos > selection_end_cursor.pos) { + s_start = selection_end_cursor.pos; + s_end = selection_start_cursor.pos; } else { - s_start = selection_start; - s_end = selection_end; + s_start = selection_start_cursor.pos; + s_end = selection_end_cursor.pos; } if ((s_start > endpos) || (s_end < startpos)) return; @@ -351,11 +352,10 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button) return; } the_locking_inset = 0; - selection_start = selection_end = inset_pos = inset_x = inset_y = 0; -// no_selection = true; + inset_pos = inset_x = inset_y = 0; setPos(bv->painter(), x, y); checkAndActivateInset(bv, x, y, button); - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; current_font = real_current_font = GetFont(par, cursor.pos); bv->text->FinishUndo(); UpdateLocal(bv, true); @@ -368,10 +368,11 @@ void InsetText::InsetUnlock(BufferView * bv) the_locking_inset->InsetUnlock(bv); the_locking_inset = 0; } + HideInsetCursor(bv); lyxerr[Debug::INSETS] << "InsetText::InsetUnlock(" << this << ")" << endl; if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } no_selection = false; @@ -445,7 +446,7 @@ bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset) void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) { if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } no_selection = false; @@ -486,7 +487,7 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) UpdateLocal(bv, true); } } - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; } @@ -521,11 +522,11 @@ void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state) return; } if (!no_selection) { - int old = selection_end; + LyXCursor old = selection_end_cursor; HideInsetCursor(bv); setPos(bv->painter(), x, y); - selection_end = cursor.pos; - if (old != selection_end) + selection_end_cursor = cursor; + if (old != selection_end_cursor) UpdateLocal(bv, false); ShowInsetCursor(bv); } @@ -593,82 +594,82 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous, bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next); cutSelection(); - cursor.pos = selection_start; + cursor = selection_start_cursor; par->InsertChar(cursor.pos,arg[0]); SetCharFont(cursor.pos,current_font); ++cursor.pos; - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, true); break; // --- Cursor Movements --------------------------------------------- case LFUN_RIGHTSEL: bv->text->FinishUndo(); moveRight(bv, false); - selection_end = cursor.pos; + selection_end_cursor = cursor; UpdateLocal(bv, false); break; case LFUN_RIGHT: bv->text->FinishUndo(); result = moveRight(bv); if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } else { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; } break; case LFUN_LEFTSEL: bv->text->FinishUndo(); moveLeft(bv, false); - selection_end = cursor.pos; + selection_end_cursor = cursor; UpdateLocal(bv, false); break; case LFUN_LEFT: bv->text->FinishUndo(); result= moveLeft(bv); if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } else { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; } break; case LFUN_DOWNSEL: bv->text->FinishUndo(); moveDown(bv); - selection_end = cursor.pos; + selection_end_cursor = cursor; UpdateLocal(bv, false); break; case LFUN_DOWN: bv->text->FinishUndo(); result = moveDown(bv); if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } else { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; } break; case LFUN_UPSEL: bv->text->FinishUndo(); moveUp(bv); - selection_end = cursor.pos; + selection_end_cursor = cursor; UpdateLocal(bv, false); break; case LFUN_UP: bv->text->FinishUndo(); result = moveUp(bv); if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } else { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; } break; case LFUN_BACKSPACE: - if (!cursor.pos) { // || par->IsNewline(cursor.pos-1)) { + if (!cursor.pos) { if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } break; @@ -681,17 +682,17 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next); bool ret = true; if (hasSelection()) { - LyXParagraph::size_type i = selection_start; - for (; i < selection_end; ++i) { - par->Erase(selection_start); + LyXParagraph::size_type i = selection_start_cursor.pos; + for (; i < selection_end_cursor.pos; ++i) { + par->Erase(selection_start_cursor.pos); } } else ret = Delete(); if (ret) { // we need update - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, true); } else if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } } @@ -704,10 +705,10 @@ InsetText::LocalDispatch(BufferView * bv, if (cutSelection()) { // we need update - cursor.pos = selection_end = selection_start; + cursor = selection_end_cursor = selection_start_cursor; UpdateLocal(bv, true); } else if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } resetPos(bv->painter()); @@ -716,10 +717,10 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->FinishUndo(); if (copySelection()) { // we need update - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, true); } else if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } break; @@ -729,7 +730,7 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous, bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next); if (pasteSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, true); } } @@ -741,10 +742,10 @@ InsetText::LocalDispatch(BufferView * bv, cursor.x -= SingleWidth(bv->painter(), par, cursor.pos); cursor.x -= SingleWidth(bv->painter(), par, cursor.pos); if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } else { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; } resetPos(bv->painter()); break; @@ -757,10 +758,10 @@ InsetText::LocalDispatch(BufferView * bv, for(; cursor.pos < checkpos; ++cursor.pos) cursor.x += SingleWidth(bv->painter(), par, cursor.pos); if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; UpdateLocal(bv, false); } else { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; } } resetPos(bv->painter()); @@ -782,9 +783,42 @@ InsetText::LocalDispatch(BufferView * bv, SetCharFont(cursor.pos,current_font); UpdateLocal(bv, true); ++cursor.pos; - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; resetPos(bv->painter()); break; + case LFUN_LAYOUT: + { + // Derive layout number from given argument (string) + // and current buffer's textclass (number). */ + LyXTextClassList::ClassList::size_type tclass = + buffer->params.textclass; + pair layout = + textclasslist.NumberOfLayout(tclass, arg); + + // If the entry is obsolete, use the new one instead. + if (layout.first) { + string obs = textclasslist.Style(tclass,layout.second). + obsoleted_by(); + if (!obs.empty()) + layout = textclasslist.NumberOfLayout(tclass, obs); + } + + // see if we found the layout number: + if (!layout.first) { + string msg = string(N_("Layout ")) + arg + N_(" not known"); + + bv->owner()->getMiniBuffer()->Set(msg); + break; + } + + if (current_layout != layout.second) { + bv->text->SetLayout(cursor, selection_start_cursor, + selection_end_cursor, layout.second); + bv->owner()->getToolbar()->combox->select(cursor.par->GetLayout()+1); + UpdateLocal(bv, true); + } + } + break; default: result = UNDISPATCHED; break; @@ -799,9 +833,9 @@ InsetText::LocalDispatch(BufferView * bv, int InsetText::Latex(ostream & os, bool /*fragile*/, bool /*fp*/) const { - TexRow texrow; - int ret = par->SimpleTeXOnePar(os, texrow); - return ret; + TexRow texrow; + buffer->latexParagraphs(os, par, 0, texrow); + return texrow.rows(); } @@ -1048,6 +1082,8 @@ void InsetText::setPos(Painter & pain, int x, int y) const void InsetText::resetPos(Painter & pain) const { + cursor.par = par; + if (!rows.size()) return; @@ -1149,9 +1185,9 @@ bool InsetText::InsertInset(BufferView * bv, Inset * inset) par->InsertChar(cursor.pos, LyXParagraph::META_INSET); par->InsertInset(cursor.pos, inset); if (hasSelection()) { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; } else { - selection_start = selection_end = cursor.pos; + selection_start_cursor = selection_end_cursor = cursor; } UpdateLocal(bv, true); static_cast(inset)->Edit(bv, 0, 0, 0); @@ -1189,12 +1225,12 @@ void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall) } int s_start, s_end; - if (selection_start > selection_end) { - s_start = selection_end; - s_end = selection_start; + if (selection_start_cursor.pos > selection_end_cursor.pos) { + s_start = selection_end_cursor.pos; + s_end = selection_start_cursor.pos; } else { - s_start = selection_start; - s_end = selection_end; + s_start = selection_start_cursor.pos; + s_end = selection_end_cursor.pos; } LyXFont newfont; while(s_start < s_end) { @@ -1427,6 +1463,7 @@ void InsetText::UpdateLocal(BufferView * bv, bool flag) bv->updateInset(this, flag); if (flag) resetPos(bv->painter()); + bv->owner()->getToolbar()->combox->select(cursor.par->GetLayout()+1); } @@ -1439,12 +1476,12 @@ bool InsetText::cutSelection() LyXParagraph * endpar = par; int start, end; - if (selection_start > selection_end) { - start = selection_end; - end = selection_start; + if (selection_start_cursor.pos > selection_end_cursor.pos) { + start = selection_end_cursor.pos; + end = selection_start_cursor.pos; } else { - start = selection_start; - end = selection_end; + start = selection_start_cursor.pos; + end = selection_end_cursor.pos; } return cap.cutSelection(par, &endpar, start, end,buffer->params.textclass); @@ -1459,12 +1496,12 @@ bool InsetText::copySelection() CutAndPaste cap; int start, end; - if (selection_start > selection_end) { - start = selection_end; - end = selection_start; + if (selection_start_cursor.pos > selection_end_cursor.pos) { + start = selection_end_cursor.pos; + end = selection_start_cursor.pos; } else { - start = selection_start; - end = selection_end; + start = selection_start_cursor.pos; + end = selection_end_cursor.pos; } return cap.copySelection(par, par, start, end, buffer->params.textclass); } @@ -1516,3 +1553,12 @@ int InsetText::getMaxTextWidth(Painter & pain, UpdatableInset const * inset, { return getMaxWidth(pain, inset) - x; } + +void InsetText::SetParagraphData(LyXParagraph *p) +{ + if (par) + delete par; + par = p->Clone(); + par->SetInsetOwner(this); + init_inset = true; +} diff --git a/src/insets/insettext.h b/src/insets/insettext.h index bbc558cf5f..b49374fa93 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -34,10 +34,10 @@ class Buffer; */ class InsetText : public UpdatableInset { public: - /// - enum { TEXT_TO_INSET_OFFSET = 1 }; /// - explicit + enum { TEXT_TO_INSET_OFFSET = 1 }; + /// + explicit InsetText(Buffer *); /// InsetText(InsetText const &, Buffer *); @@ -107,6 +107,8 @@ public: void SetFont(BufferView *, LyXFont const &, bool toggleall = false); /// void init(Buffer *, InsetText const * ins = 0); + /// + void SetParagraphData(LyXParagraph *); LyXParagraph * par; @@ -178,7 +180,8 @@ private: bool copySelection(); bool pasteSelection(); /// - bool hasSelection() const { return selection_start != selection_end; } + bool hasSelection() const + { return (selection_start_cursor != selection_end_cursor); } /// void SetCharFont(int pos, LyXFont const & font); /// @@ -197,9 +200,9 @@ private: /// int interline_space; /// - int selection_start; + LyXCursor selection_start_cursor; /// - int selection_end; + LyXCursor selection_end_cursor; /// mutable LyXCursor cursor; /// @@ -241,9 +244,7 @@ private: inset_x = it.inset_x; inset_y = it.inset_y; interline_space = it.interline_space; - selection_start = it.selection_start; - selection_end = it.selection_end; - cursor = it.cursor; + selection_start_cursor = selection_end_cursor = cursor = it.cursor; actrow = it.actrow; no_selection = it.no_selection; the_locking_inset = it.the_locking_inset; // suspect diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index 5f0a7326cf..401884e6d7 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -177,8 +177,6 @@ public: return 0; } /// - virtual void init(BufferView *) {} - /// virtual bool InsertInsetAllowed(Inset *) const { return false; } /// virtual void setInsetName(const char * s) { name = s; } diff --git a/src/lyxcursor.h b/src/lyxcursor.h index 9699f75614..256a130e7d 100644 --- a/src/lyxcursor.h +++ b/src/lyxcursor.h @@ -31,6 +31,11 @@ struct LyXCursor { unsigned long y; /// Row * row; + /// + inline bool operator==(const LyXCursor &a) const + { return (a.par == par) && (a.pos == pos); } + inline bool operator!=(const LyXCursor &a) const + { return (a.par != par) || (a.pos != pos); } }; #endif diff --git a/src/lyxtext.h b/src/lyxtext.h index c500764c22..96f16b0fc6 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -88,6 +88,10 @@ public: /** set layout over selection and make a total rebreak of those paragraphs */ + LyXParagraph * SetLayout(LyXCursor & actual_cursor, + LyXCursor & selection_start, + LyXCursor & selection_end, + LyXTextClass::size_type layout); void SetLayout(LyXTextClass::size_type layout); /// used in setlayout diff --git a/src/paragraph.C b/src/paragraph.C index c8d21d074f..f7c4994512 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -2126,7 +2126,8 @@ LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow, || par->pextra_type != pextra_type)) break; default: - if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE + // we don't need it for the last paragraph!!! + if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && footnotekind != LyXParagraph::FOOTNOTE && footnotekind != LyXParagraph::MARGIN && (table @@ -2168,7 +2169,8 @@ LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow, texrow.newline(); } - if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par && + // we don't need it for the last paragraph!!! + if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par && par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) { os << '\n'; texrow.newline(); diff --git a/src/table.C b/src/table.C index 14482eab50..54812b0306 100644 --- a/src/table.C +++ b/src/table.C @@ -1403,8 +1403,7 @@ int LyXTable::TexEndOfCell(ostream & os, int cell) } } if (nvcell < numberofcells && Linebreaks(nvcell)) { -// !column_info[column_of_cell(nvcell)].p_width.empty()) { - os << "\\parbox{" + os << "\\parbox[t]{" << GetPWidth(nvcell) << "}{\\smallskip{}"; } diff --git a/src/tabular.C b/src/tabular.C index 7639f1c3a0..fc6620344d 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -37,16 +37,15 @@ static int const WIDTH_OF_LINE = 5; LyXTabular::cellstruct::cellstruct(Buffer * buf) { - cellno = 0; //should be initilaized correctly later. - width_of_cell = 0; - multicolumn = LyXTabular::CELL_NORMAL; - alignment = LYX_ALIGN_CENTER; - top_line = true; - bottom_line = false; - rotate = false; - linebreaks = false; - buf ? inset = new InsetText(buf): inset = 0; - + cellno = 0; //should be initilaized correctly later. + width_of_cell = 0; + multicolumn = LyXTabular::CELL_NORMAL; + alignment = LYX_ALIGN_CENTER; + top_line = true; + bottom_line = false; + rotate = false; + linebreaks = false; + inset = new InsetText(buf); } LyXTabular::cellstruct::~cellstruct() @@ -58,24 +57,24 @@ LyXTabular::cellstruct::~cellstruct() LyXTabular::cellstruct & LyXTabular::cellstruct::operator=(cellstruct const & cs) { - cellno = cs.cellno; - width_of_cell = cs.width_of_cell; - multicolumn = cs.multicolumn; - alignment = cs.alignment; - top_line = cs.top_line; - bottom_line = cs.bottom_line; - rotate = cs.rotate; - linebreaks = cs.linebreaks; - return *this; + cellno = cs.cellno; + width_of_cell = cs.width_of_cell; + multicolumn = cs.multicolumn; + alignment = cs.alignment; + top_line = cs.top_line; + bottom_line = cs.bottom_line; + rotate = cs.rotate; + linebreaks = cs.linebreaks; + return *this; } LyXTabular::rowstruct::rowstruct() { - top_line = true; - bottom_line = false; - ascent_of_row = 0; - descent_of_row = 0; - newpage = false; + top_line = true; + bottom_line = false; + ascent_of_row = 0; + descent_of_row = 0; + newpage = false; } // Nothing to do, but gcc 2.7.2.3 wants one... (JMarc) @@ -86,20 +85,20 @@ LyXTabular::rowstruct::~rowstruct() LyXTabular::rowstruct & LyXTabular::rowstruct::operator=(rowstruct const & rs) { - top_line = rs.top_line; - bottom_line = rs.bottom_line; - ascent_of_row = rs.ascent_of_row; - descent_of_row = rs.descent_of_row; - newpage = rs.newpage; - return *this; + top_line = rs.top_line; + bottom_line = rs.bottom_line; + ascent_of_row = rs.ascent_of_row; + descent_of_row = rs.descent_of_row; + newpage = rs.newpage; + return *this; } LyXTabular::columnstruct::columnstruct() { - left_line = true; - right_line = false; - alignment = LYX_ALIGN_CENTER; - width_of_column = 0; + left_line = true; + right_line = false; + alignment = LYX_ALIGN_CENTER; + width_of_column = 0; } LyXTabular::columnstruct::~columnstruct() @@ -109,13 +108,13 @@ LyXTabular::columnstruct::~columnstruct() LyXTabular::columnstruct & LyXTabular::columnstruct::operator=(columnstruct const & cs) { - left_line = cs.left_line; - right_line = cs.right_line; - alignment = cs.alignment; - width_of_column = cs.width_of_column; - p_width = cs.p_width; - align_special = cs.align_special; - return *this; + left_line = cs.left_line; + right_line = cs.right_line; + alignment = cs.alignment; + width_of_column = cs.width_of_column; + p_width = cs.p_width; + align_special = cs.align_special; + return *this; } /* konstruktor */ @@ -136,9 +135,8 @@ LyXTabular::LyXTabular(LyXTabular const & lt, Buffer * buf) LyXTabular::LyXTabular(LyXLex & lex, Buffer *buf) { - istream & is = lex.getStream(); buffer = buf; - Read(is); + Read(lex); } @@ -185,9 +183,9 @@ LyXTabular & LyXTabular::operator=(LyXTabular const & lt) return *this; } -LyXTabular * LyXTabular::Clone() +LyXTabular * LyXTabular::Clone(Buffer * buf) { - LyXTabular * result = new LyXTabular(rows_, columns_); + LyXTabular * result = new LyXTabular(rows_, columns_, buf); int row, column;; for (row = 0; row < rows_; ++row) { @@ -270,7 +268,7 @@ void LyXTabular::AppendRow(int cell) row_info2[i + 1] = row_info[i]; } row_info2[row + 1].top_line = row_info[i].top_line; - cell_info2[row + 1] = new cellstruct[columns_]; + cell_info2[row + 1] = new cellstruct[columns_](buffer); for (i = 0; i < columns_; ++i) { cell_info2[row + 1][i].width_of_cell = 0; cell_info2[row + 1][i] = cell_info2[row][i]; @@ -289,29 +287,29 @@ void LyXTabular::AppendRow(int cell) void LyXTabular::DeleteRow(int cell) { - int row = row_of_cell(cell); - rowstruct * row_info2 = new rowstruct[rows_ - 1]; - cellstruct ** cell_info2 = new cellstruct * [rows_ - 1]; + int row = row_of_cell(cell); + rowstruct * row_info2 = new rowstruct[rows_ - 1]; + cellstruct ** cell_info2 = new cellstruct * [rows_ - 1]; - delete[] cell_info[row]; - int i = 0; - for (; i < row; ++i) { - cell_info2[i] = cell_info[i]; - row_info2[i] = row_info[i]; - } - for (i = row; i < rows_ - 1; ++i) { - cell_info2[i] = cell_info[i + 1]; - row_info2[i] = row_info[i + 1]; - } + delete[] cell_info[row]; + int i = 0; + for (; i < row; ++i) { + cell_info2[i] = cell_info[i]; + row_info2[i] = row_info[i]; + } + for (i = row; i < rows_ - 1; ++i) { + cell_info2[i] = cell_info[i + 1]; + row_info2[i] = row_info[i + 1]; + } - delete[] cell_info; - cell_info = cell_info2; - delete[] row_info; - row_info = row_info2; + delete[] cell_info; + cell_info = cell_info2; + delete[] row_info; + row_info = row_info2; - --rows_; + --rows_; - Reinit(); + Reinit(); } @@ -334,7 +332,7 @@ void LyXTabular::AppendColumn(int cell) for (i = 0; i < rows_; ++i) { cellstruct * tmp = cell_info[i]; - cell_info[i] = new cellstruct[columns_ + 1]; + cell_info[i] = new cellstruct[columns_ + 1](buffer); for (j = 0; j <= column; ++j) { cell_info[i][j] = tmp[j]; } @@ -363,101 +361,101 @@ void LyXTabular::AppendColumn(int cell) void LyXTabular::Reinit() { - int j; + int j; - int i = 0; - for (; i < rows_; ++i) { - for (j = 0; j < columns_; ++j) { - cell_info[i][j].width_of_cell = 0; - } + int i = 0; + for (; i < rows_; ++i) { + for (j = 0; j < columns_; ++j) { + cell_info[i][j].width_of_cell = 0; } + } - for (i = 0; i < columns_; ++i) { - calculate_width_of_column(i); - } - calculate_width_of_tabular(); + for (i = 0; i < columns_; ++i) { + calculate_width_of_column(i); + } + calculate_width_of_tabular(); - set_row_column_number_info(); + set_row_column_number_info(); } void LyXTabular::set_row_column_number_info() { - int c = 0; - int column = 0; - numberofcells = -1; - int row = 0; - for (; row < rows_; ++row) { - for (column = 0; column= numberofcells) @@ -496,108 +494,124 @@ bool LyXTabular::BottomLine(int cell) } -bool LyXTabular::LeftLine(int cell) +bool LyXTabular::LeftLine(int cell) const { - return column_info[column_of_cell(cell)].left_line; + return column_info[column_of_cell(cell)].left_line; } -bool LyXTabular::RightLine(int cell) +bool LyXTabular::RightLine(int cell) const { - return column_info[right_column_of_cell(cell)].right_line; + return column_info[right_column_of_cell(cell)].right_line; } -bool LyXTabular::TopAlreadyDrawed(int cell) +bool LyXTabular::TopAlreadyDrawed(int cell) const { - if (AdditionalHeight(cell)) - return false; - int row = row_of_cell(cell); - if (row > 0){ - int column = column_of_cell(cell); - while (column - && cell_info[row-1][column].multicolumn - == LyXTabular::CELL_PART_OF_MULTICOLUMN) - --column; - if (cell_info[row-1][column].multicolumn - == LyXTabular::CELL_NORMAL) - return row_info[row-1].bottom_line; - else - return cell_info[row-1][column].bottom_line; - } + if (GetAdditionalHeight(cell)) return false; + int row = row_of_cell(cell); + if (row > 0) { + int column = column_of_cell(cell); + --row; + while (column + && cell_info[row][column].multicolumn + == LyXTabular::CELL_PART_OF_MULTICOLUMN) + --column; + if (cell_info[row][column].multicolumn == LyXTabular::CELL_NORMAL) + return row_info[row].bottom_line; + else + return cell_info[row][column].bottom_line; + } + return false; } -bool LyXTabular::VeryLastRow(int cell) -{ - return (row_of_cell(cell) == rows_ - 1); -} - - -int LyXTabular::AdditionalHeight(int cell) +bool LyXTabular::LeftAlreadyDrawed(int cell) const { + int column = column_of_cell(cell); + if (column > 0) { int row = row_of_cell(cell); - if (!row) return 0; - - int top = 1; // bool top = true; ?? - int bottom = 1; // bool bottom = true; ?? - int column; + while (--column && + (cell_info[row][column].multicolumn == + LyXTabular::CELL_PART_OF_MULTICOLUMN)); + if (GetAdditionalWidth(cell_info[row][column].cellno)) + return false; + return column_info[column].right_line; + } + return false; +} - for (column = 0; column < columns_ - 1 && bottom; ++column) { - switch (cell_info[row - 1][column].multicolumn) { - case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN: - bottom = cell_info[row - 1][column].bottom_line; - break; - case LyXTabular::CELL_NORMAL: - bottom = row_info[row - 1].bottom_line; - } + +bool LyXTabular::IsLastRow(int cell) const +{ + return (row_of_cell(cell) == rows_ - 1); +} + + +int LyXTabular::GetAdditionalHeight(int cell) const +{ + int row = row_of_cell(cell); + if (!row) return 0; + + int top = 1; // bool top = true; ?? + int bottom = 1; // bool bottom = true; ?? + int column; + + for (column = 0; column < columns_ - 1 && bottom; ++column) { + switch (cell_info[row - 1][column].multicolumn) { + case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN: + bottom = cell_info[row - 1][column].bottom_line; + break; + case LyXTabular::CELL_NORMAL: + bottom = row_info[row - 1].bottom_line; } - for (column = 0; column < columns_ - 1 && top; ++column) { - switch (cell_info[row][column].multicolumn){ - case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN: - top = cell_info[row][column].top_line; - break; - case LyXTabular::CELL_NORMAL: - top = row_info[row].top_line; - } + } + for (column = 0; column < columns_ - 1 && top; ++column) { + switch (cell_info[row][column].multicolumn){ + case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN: + top = cell_info[row][column].top_line; + break; + case LyXTabular::CELL_NORMAL: + top = row_info[row].top_line; } - if (top && bottom) - return WIDTH_OF_LINE; + } + if (top && bottom) + return WIDTH_OF_LINE; + return 0; +} + + +int LyXTabular::GetAdditionalWidth(int cell) const +{ + // internally already set in SetWidthOfCell + // used to get it back in text.C + int col = right_column_of_cell(cell); + if (col < columns_ - 1 && column_info[col].right_line && + column_info[col+1].left_line) + return WIDTH_OF_LINE; + else return 0; } -int LyXTabular::AdditionalWidth(int cell) -{ - // internally already set in SetWidthOfCell - // used to get it back in text.C - int col = right_column_of_cell(cell); - if (col < columns_ - 1 && column_info[col].right_line && - column_info[col+1].left_line) - return WIDTH_OF_LINE; - else - return 0; -} - - // returns the maximum over all rows -int LyXTabular::WidthOfColumn(int cell) +int LyXTabular::GetWidthOfColumn(int cell) const { - int column1 = column_of_cell(cell); - int column2 = right_column_of_cell(cell); - int result = 0; - int i = column1; - for (; i <= column2; ++i) { - result += column_info[i].width_of_column; - } - return result; + int column1 = column_of_cell(cell); + int column2 = right_column_of_cell(cell); + int result = 0; + int i = column1; + for (; i <= column2; ++i) { + result += column_info[i].width_of_column; + } + return result; } -int LyXTabular::WidthOfTabular() +int LyXTabular::GetWidthOfTabular() const { - return width_of_tabular; + return width_of_tabular; } /* returns 1 if a complete update is necessary, otherwise 0 */ @@ -630,12 +644,12 @@ bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width) void LyXTabular::recalculateMulticolCells(int cell, int new_width) { - int row = row_of_cell(cell); - int column1 = column_of_cell(cell); - int column2 = right_column_of_cell(cell); + int row = row_of_cell(cell); + int column1 = column_of_cell(cell); + int column2 = right_column_of_cell(cell); // first set columns to 0 so we can calculate the right width - int i = column1; + int i = column1; for (; i <= column2; ++i) cell_info[row][i].width_of_cell = 0; for(i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i) @@ -692,8 +706,6 @@ bool LyXTabular::SetAlignment(int cell, char align) bool LyXTabular::SetPWidth(int cell, string width) { if (IsMultiColumn(cell)) { -// if (column_info[column_of_cell(cell)].p_width.empty()) -// column_info[column_of_cell(cell)].p_width = width; cellinfo_of_cell(cell)->p_width = width; } else { column_info[column_of_cell(cell)].p_width = width; @@ -745,99 +757,100 @@ bool LyXTabular::SetBottomLine(int cell, bool line) bool LyXTabular::SetLeftLine(int cell, bool line) { - column_info[column_of_cell(cell)].left_line = line; - return true; + column_info[column_of_cell(cell)].left_line = line; + return true; } bool LyXTabular::SetRightLine(int cell, bool line) { - column_info[right_column_of_cell(cell)].right_line = line; - return true; + column_info[right_column_of_cell(cell)].right_line = line; + return true; } -char LyXTabular::GetAlignment(int cell) +char LyXTabular::GetAlignment(int cell) const { - if (IsMultiColumn(cell)) - return cellinfo_of_cell(cell)->alignment; - else - return column_info[column_of_cell(cell)].alignment; + if (IsMultiColumn(cell)) + return cellinfo_of_cell(cell)->alignment; + else + return column_info[column_of_cell(cell)].alignment; } -string LyXTabular::GetPWidth(int cell) +string LyXTabular::GetPWidth(int cell) const { - if (IsMultiColumn(cell)) - return cellinfo_of_cell(cell)->p_width; - return column_info[column_of_cell(cell)].p_width; + if (IsMultiColumn(cell)) + return cellinfo_of_cell(cell)->p_width; + return column_info[column_of_cell(cell)].p_width; } -string LyXTabular::GetAlignSpecial(int cell, int what) +string LyXTabular::GetAlignSpecial(int cell, int what) const { if (what == SET_SPECIAL_MULTI) return cellinfo_of_cell(cell)->align_special; return column_info[column_of_cell(cell)].align_special; } -int LyXTabular::GetWidthOfCell(int cell) +int LyXTabular::GetWidthOfCell(int cell) const { - int row = row_of_cell(cell); - int column1 = column_of_cell(cell); - int column2 = right_column_of_cell(cell); - int result = 0; - int i = column1; - for (; i <= column2; ++i) { - result += cell_info[row][i].width_of_cell; - } - - result += AdditionalWidth(cell); - - return result; + int row = row_of_cell(cell); + int column1 = column_of_cell(cell); + int column2 = right_column_of_cell(cell); + int result = 0; + int i = column1; + for (; i <= column2; ++i) { + result += cell_info[row][i].width_of_cell; + } + +// result += GetAdditionalWidth(cell); + + return result; } -int LyXTabular::GetBeginningOfTextInCell(int cell) +int LyXTabular::GetBeginningOfTextInCell(int cell) const { - int x = 0; + int x = 0; - switch (GetAlignment(cell)){ - case LYX_ALIGN_CENTER: - x += (WidthOfColumn(cell) - GetWidthOfCell(cell)) / 2; - break; - case LYX_ALIGN_RIGHT: - x += WidthOfColumn(cell) - GetWidthOfCell(cell) + AdditionalWidth(cell); - break; - default: /* LYX_ALIGN_LEFT: nothing :-) */ - break; - } - - // the LaTeX Way :-( - x += WIDTH_OF_LINE; - return x; + switch (GetAlignment(cell)){ + case LYX_ALIGN_CENTER: + x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2; + break; + case LYX_ALIGN_RIGHT: + x += GetWidthOfColumn(cell) - GetWidthOfCell(cell); + // + GetAdditionalWidth(cell); + break; + default: /* LYX_ALIGN_LEFT: nothing :-) */ + break; + } + + // the LaTeX Way :-( + x += WIDTH_OF_LINE; + return x; } -bool LyXTabular::IsFirstCellInRow(int cell) +bool LyXTabular::IsFirstCellInRow(int cell) const { - return (column_of_cell(cell) == 0); + return (column_of_cell(cell) == 0); } -bool LyXTabular::IsLastCellInRow(int cell) +bool LyXTabular::IsLastCellInRow(int cell) const { - return (right_column_of_cell(cell) == (columns_ - 1)); + return (right_column_of_cell(cell) == (columns_ - 1)); } bool LyXTabular::calculate_width_of_column(int column) { - int old_column_width = column_info[column].width_of_column; - int maximum = 0; - - for (int i = 0; i < rows_; ++i) { - maximum = max(cell_info[i][column].width_of_cell, maximum); - } - column_info[column].width_of_column = maximum; - return (column_info[column].width_of_column != old_column_width); + int old_column_width = column_info[column].width_of_column; + int maximum = 0; + + for (int i = 0; i < rows_; ++i) { + maximum = max(cell_info[i][column].width_of_cell, maximum); + } + column_info[column].width_of_column = maximum; + return (column_info[column].width_of_column != old_column_width); } bool LyXTabular::calculate_width_of_column_NMC(int column) @@ -856,10 +869,10 @@ bool LyXTabular::calculate_width_of_column_NMC(int column) void LyXTabular::calculate_width_of_tabular() { - width_of_tabular = 0; - for (int i = 0; i < columns_; ++i) { - width_of_tabular += column_info[i].width_of_column; - } + width_of_tabular = 0; + for (int i = 0; i < columns_; ++i) { + width_of_tabular += column_info[i].width_of_column; + } } @@ -883,181 +896,367 @@ int LyXTabular::column_of_cell(int cell) const } -int LyXTabular::right_column_of_cell(int cell) +int LyXTabular::right_column_of_cell(int cell) const { - int row = row_of_cell(cell); - int column = column_of_cell(cell); - while (column < (columns_ - 1) && - cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN) - ++column; - return column; + int row = row_of_cell(cell); + int column = column_of_cell(cell); + while (column < (columns_ - 1) && + cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN) + ++column; + return column; } -void LyXTabular::Write(ostream & os, bool old_format) +void LyXTabular::Write(ostream & os) const { - if (old_format) { - int i, j; - os << "multicol5\n" - << rows_ << " " << columns_ << " " << is_long_tabular << " " - << rotate << " " << endhead << " " << endfirsthead << " " - << endfoot << " " << endlastfoot << "\n"; - for (i = 0; i < rows_; ++i) { - os << row_info[i].top_line << " " - << row_info[i].bottom_line << " " - << row_info[i].newpage << "\n"; - } - for (i = 0; i < columns_; ++i) { - os << column_info[i].alignment << " " - << column_info[i].left_line << " " - << column_info[i].right_line << " \"" - << VSpace(column_info[i].p_width).asLyXCommand() << "\" \"" - << column_info[i].align_special << "\"\n"; - } + int i, j; - for (i = 0; i < rows_; ++i) { - for (j = 0; j < columns_; ++j) { - os << cell_info[i][j].multicolumn << " " - << cell_info[i][j].alignment << " " - << cell_info[i][j].top_line << " " - << cell_info[i][j].bottom_line << " " - << cell_info[i][j].rotate << " " - << cell_info[i][j].linebreaks << " \"" - << cell_info[i][j].align_special << "\" \"" - << cell_info[i][j].p_width << "\"\n"; + // header line + os << "" << endl; + // global longtable options + os << "" << endl << endl; + for (i = 0; i < rows_; ++i) { + os << "" << endl; + for (j = 0; j < columns_; ++j) { + if (!i) { + os << "" << endl; + } else { + os << "" << endl; + } + os << "" << endl; + os << "\\begin_inset "; + cell_info[i][j].inset->Write(os); + os << "\n\\end_inset " << endl; + os << "" << endl; + os << "" << endl; + } + os << "" << endl; + } + os << "" << endl; +} + +static bool getTokenValue(string const str, const char * token, string & ret) +{ + int pos = str.find(token); + char ch = str[pos+strlen(token)]; + + if ((pos < 0) || (ch != '=')) + return false; + ret.clear(); + pos += strlen(token)+1; + ch = str[pos]; + if ((ch != '"') && (ch != '\'')) { // only read till next space + ret += ch; + ch = ' '; + } + while((pos < int(str.length()-1)) && (str[++pos] != ch)) + ret += str[pos]; + + return true; +} + +static bool getTokenValue(string const str, const char * token, int & num) +{ + string ret; + int pos = str.find(token); + char ch = str[pos+strlen(token)]; + + if ((pos < 0) || (ch != '=')) + return false; + ret.clear(); + pos += strlen(token)+1; + ch = str[pos]; + if ((ch != '"') && (ch != '\'')) { // only read till next space + if (!isdigit(ch)) + return false; + ret += ch; + } + ++pos; + while((pos < int(str.length()-1)) && isdigit(str[pos])) + ret += str[pos++]; + + num = strToInt(ret); + return true; +} + +static bool getTokenValue(string const str, const char * token, bool & flag) +{ + string ret; + int pos = str.find(token); + char ch = str[pos+strlen(token)]; + + if ((pos < 0) || (ch != '=')) + return false; + ret.clear(); + pos += strlen(token)+1; + ch = str[pos]; + if ((ch != '"') && (ch != '\'')) { // only read till next space + if (!isdigit(ch)) + return false; + ret += ch; + } + ++pos; + while((pos < int(str.length()-1)) && isdigit(str[pos])) + ret += str[pos++]; + + flag = strToInt(ret); + return true; +} + +void l_getline(istream & is, string & str) +{ + getline(is, str); + while(str.empty()) + getline(is, str); +} + +void LyXTabular::Read(LyXLex & lex) +{ + string line; + istream & is = lex.getStream(); + + l_getline(is, line); + if (!prefixIs(line, " got" << + line << ")" << endl; + return; + } + (void)getTokenValue(line, "islongtable", is_long_tabular); + (void)getTokenValue(line, "endhead", endhead); + (void)getTokenValue(line, "endfirsthead", endfirsthead); + (void)getTokenValue(line, "endfoot", endfoot); + (void)getTokenValue(line, "endlastfoot", endlastfoot); + int i, j; + for(i = 0; i < rows_; ++i) { + l_getline(is, line); + if (!prefixIs(line, " got" << + line << ")" << endl; + return; + } + (void)getTokenValue(line, "topline", row_info[i].top_line); + (void)getTokenValue(line, "bottomline", row_info[i].bottom_line); + (void)getTokenValue(line, "newpage", row_info[i].newpage); + for (j = 0; j < columns_; ++j) { + l_getline(is,line); + if (!prefixIs(line," got" << + line << ")" << endl; + return; + } + if (!i) { + (void)getTokenValue(line, "alignment", column_info[j].alignment); + (void)getTokenValue(line, "leftline", column_info[j].left_line); + (void)getTokenValue(line, "rightline", column_info[j].right_line); + (void)getTokenValue(line, "width", column_info[j].p_width); + (void)getTokenValue(line, "special", column_info[j].align_special); + } + l_getline(is, line); + if (!prefixIs(line, " got" << + line << ")" << endl; + return; + } + (void)getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn); + (void)getTokenValue(line, "alignment", cell_info[i][j].alignment); + (void)getTokenValue(line, "topline", cell_info[i][j].top_line); + (void)getTokenValue(line, "bottomline", cell_info[i][j].bottom_line); + (void)getTokenValue(line, "rotate", cell_info[i][j].rotate); + (void)getTokenValue(line, "linebreaks", cell_info[i][j].linebreaks); + (void)getTokenValue(line, "width", cell_info[i][j].p_width); + (void)getTokenValue(line, "special", cell_info[i][j].align_special); + l_getline(is, line); + if (prefixIs(line, "\\begin_inset")) { + cell_info[i][j].inset->Read(lex); + l_getline(is, line); + } + if (line != "") { + lyxerr << "Wrong tabular format (expected got" << + line << ")" << endl; + return; + } + l_getline(is, line); + if (line != "") { + lyxerr << "Wrong tabular format (expected got" << + line << ")" << endl; + return; } } - } else { - lyxerr << "New format type not yet implemented!!!\n" << endl; + l_getline(is, line); + if (line != "") { + lyxerr << "Wrong tabular format (expected got" << + line << ")" << endl; + return; + } } + while (line != "") { + l_getline(is, line); + } + set_row_column_number_info(); } - -void LyXTabular::Read(istream & is) +void LyXTabular::OldFormatRead(istream & is, string fl) { - int version; - int i, j; - int rows_arg = 0; - int columns_arg = 0; - int is_long_tabular_arg = false; - int rotate_arg = false; - int a = -1; - int b = -1; - int c = -1; - int d = -1; - int e = 0; - int f = 0; - int g = 0; - int h = 0; + int version; + int i, j; + int rows_arg = 0; + int columns_arg = 0; + int is_long_tabular_arg = false; + int rotate_arg = false; + int a = -1; + int b = -1; + int c = -1; + int d = -1; + int e = 0; + int f = 0; + int g = 0; + int h = 0; - string s; - getline(is, s); - if (s.length() > 8) - version = atoi(s.c_str() + 8); - else - version = 1; - if (version < 5) { - lyxerr << "Tabular format < 5 is not supported anymore\n" - "Get an older version of LyX (< 1.1.x) for conversion!" - << endl; - WriteAlert(_("Warning:"), - _("Tabular format < 5 is not supported anymore\n"), - _("Get an older version of LyX (< 1.1.x) for conversion!")); - if (version > 2) { - is >> rows_arg >> columns_arg >> is_long_tabular_arg - >> rotate_arg >> a >> b >> c >> d; - } else - is >> rows_arg >> columns_arg; - Init(rows_arg, columns_arg); - SetLongTabular(is_long_tabular_arg); - SetRotateTabular(rotate_arg); - string tmp; - for (i = 0; i < rows_; ++i) { - getline(is, tmp); - } - for (i = 0; i < columns_; ++i) { - getline(is, tmp); - } - for (i = 0; i < rows_; ++i) { - for (j = 0; j < columns_; ++j) { - getline(is, tmp); - } - } - set_row_column_number_info(); - return; - } - is >> rows_arg >> columns_arg >> is_long_tabular_arg - >> rotate_arg >> a >> b >> c >> d; + string s; + s = fl; + if (s.length() > 8) + version = atoi(s.c_str() + 8); + else + version = 1; + if (version < 5) { + lyxerr << "Tabular format < 5 is not supported anymore\n" + "Get an older version of LyX (< 1.1.x) for conversion!" + << endl; + WriteAlert(_("Warning:"), + _("Tabular format < 5 is not supported anymore\n"), + _("Get an older version of LyX (< 1.1.x) for conversion!")); + if (version > 2) { + is >> rows_arg >> columns_arg >> is_long_tabular_arg + >> rotate_arg >> a >> b >> c >> d; + } else + is >> rows_arg >> columns_arg; Init(rows_arg, columns_arg); SetLongTabular(is_long_tabular_arg); SetRotateTabular(rotate_arg); - endhead = a; - endfirsthead = b; - endfoot = c; - endlastfoot = d; + string tmp; 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; + getline(is, tmp); } 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(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; + getline(is, tmp); } 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(a); - cell_info[i][j].alignment = static_cast(b); - cell_info[i][j].top_line = static_cast(c); - cell_info[i][j].bottom_line = static_cast(d); -// cell_info[i][j].has_cont_row = static_cast(e); - cell_info[i][j].rotate = static_cast(f); - cell_info[i][j].linebreaks = static_cast(g); - cell_info[i][j].align_special = s1; - cell_info[i][j].p_width = s2; - } + for (j = 0; j < columns_; ++j) { + 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; +// 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(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(a); + cell_info[i][j].alignment = static_cast(b); + cell_info[i][j].top_line = static_cast(c); + cell_info[i][j].bottom_line = static_cast(d); +// cell_info[i][j].has_cont_row = static_cast(e); + cell_info[i][j].rotate = static_cast(f); + cell_info[i][j].linebreaks = static_cast(g); + cell_info[i][j].align_special = s1; + cell_info[i][j].p_width = s2; + } + } + set_row_column_number_info(); } -// cell <0 will tex the preamble +// cell < 0 will tex the preamble // returns the number of printed newlines -int LyXTabular::TexEndOfCell(ostream & os, int cell) +int LyXTabular::TexEndOfCell(ostream & os, int cell) const { int i; int ret = 0; int tmp; // tmp2; int fcell, nvcell; - if (ShouldBeVeryLastCell(cell)) { + if (IsLastCell(cell)) { // the very end at the very beginning - if (Linebreaks(cell)) + if (GetLinebreaks(cell)) os << "\\smallskip{}}"; if (IsMultiColumn(cell)) os << '}'; - if (RotateCell(cell)) { + if (GetRotateCell(cell)) { os << "\n\\end{sideways}"; ++ret; } @@ -1164,18 +1363,18 @@ int LyXTabular::TexEndOfCell(ostream & os, int cell) ++ret; } } - if (RotateCell(0)) { + if (GetRotateCell(0)) { os << "\\begin{sideways}\n"; ++ret; } } else { // usual cells - if (Linebreaks(cell)) + if (GetLinebreaks(cell)) os << "\\smallskip{}}"; if (IsMultiColumn(cell)){ os << '}'; } - if (RotateCell(cell)) { + if (GetRotateCell(cell)) { os << "\n\\end{sideways}"; ++ret; } @@ -1251,9 +1450,8 @@ int LyXTabular::TexEndOfCell(ostream & os, int cell) print_hline = false; // no line below a \\newpage-command } tmp = 0; - if (nvcell < numberofcells - && (cell < GetNumberOfCells() - 1) - && !ShouldBeVeryLastCell(cell)) { + if ((nvcell < numberofcells) && + (cell < GetNumberOfCells() - 1) && !IsLastCell(cell)) { fcell = nvcell; for (i = 0; i < NumberOfCellsInRow(fcell); ++i) { if (TopLine(fcell + i)) @@ -1296,8 +1494,6 @@ int LyXTabular::TexEndOfCell(ostream & os, int cell) bool sflag2 = (row == endhead) || (row == endfirsthead) || (row == endfoot) || (row == endlastfoot); --row; -// sflag2 = IsLongTabular() && (row >= 0) && -// (sflag2 || (row == endhead) || (row == endfirsthead)); row += 2; bool sflag1 = IsLongTabular() && (row != endhead) && (row != endfirsthead) && @@ -1324,14 +1520,14 @@ int LyXTabular::TexEndOfCell(ostream & os, int cell) ++ret; } } - if (nvcell < numberofcells && RotateCell(nvcell)) { + if (nvcell < numberofcells && GetRotateCell(nvcell)) { os << "\\begin{sideways}\n"; ++ret; } } else { os << "&\n"; ++ret; - if (nvcell < numberofcells && RotateCell(nvcell)) { + if (nvcell < numberofcells && GetRotateCell(nvcell)) { os << "\\begin{sideways}\n"; ++ret; } @@ -1370,9 +1566,8 @@ int LyXTabular::TexEndOfCell(ostream & os, int cell) os << "}{"; } } - if (nvcell < numberofcells && Linebreaks(nvcell)) { -// !column_info[column_of_cell(nvcell)].p_width.empty()) { - os << "\\parbox{" + if (nvcell < numberofcells && GetLinebreaks(nvcell)) { + os << "\\parbox[t]{" << GetPWidth(nvcell) << "}{\\smallskip{}"; } @@ -1477,7 +1672,7 @@ int LyXTabular::RoffEndOfCell(ostream & os, int cell) #endif -char const *LyXTabular::getDocBookAlign(int cell, bool isColumn) +char const *LyXTabular::GetDocBookAlign(int cell, bool isColumn) const { int i; if (isColumn) @@ -1524,13 +1719,13 @@ char const *LyXTabular::getDocBookAlign(int cell, bool isColumn) // cell <0 will tex the preamble // returns the number of printed newlines -int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) +int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const { int i; int ret = 0; //int tmp; // tmp2; // unused int nvcell; // fcell; // unused - if (ShouldBeVeryLastCell(cell)) { + if (IsLastCell(cell)) { os << newlineAndDepth(--depth) << "" << newlineAndDepth(--depth) @@ -1559,7 +1754,7 @@ int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) ++ret; for (i = 0; i < columns_; ++i) { os << " 0) return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno; return cell; } -int LyXTabular::GetCellNumber(int column, int row) +int LyXTabular::GetCellNumber(int column, int row) const { if (column >= columns_) column = columns_ - 1; @@ -1836,7 +2022,7 @@ void LyXTabular::SetLinebreaks(int cell, bool what) cellinfo_of_cell(cell)->linebreaks = what; } -bool LyXTabular::Linebreaks(int cell) +bool LyXTabular::GetLinebreaks(int cell) const { if (column_info[column_of_cell(cell)].p_width.empty() && !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty())) @@ -1861,17 +2047,17 @@ void LyXTabular::SetLTHead(int cell, bool first) } } -bool LyXTabular::RowOfLTHead(int cell) +bool LyXTabular::GetRowOfLTHead(int cell) const { if ((endhead+1) > rows_) - endhead = -1; + return false; return (row_of_cell(cell) == endhead); } -bool LyXTabular::RowOfLTFirstHead(int cell) +bool LyXTabular::GetRowOfLTFirstHead(int cell) const { if ((endfirsthead+1) > rows_) - endfirsthead = -1; + return false; return (row_of_cell(cell) == endfirsthead); } @@ -1892,19 +2078,17 @@ void LyXTabular::SetLTFoot(int cell, bool last) } } -bool LyXTabular::RowOfLTFoot(int cell) +bool LyXTabular::GetRowOfLTFoot(int cell) const { - if ((endfoot+1) > rows_) { - endfoot = -1; + if ((endfoot+1) > rows_) return false; - } return (row_of_cell(cell) == endfoot); } -bool LyXTabular::RowOfLTLastFoot(int cell) +bool LyXTabular::GetRowOfLTLastFoot(int cell) const { if ((endlastfoot+1) > rows_) - endlastfoot = -1; + return false; return (row_of_cell(cell) == endlastfoot); } @@ -1913,7 +2097,7 @@ void LyXTabular::SetLTNewPage(int cell, bool what) row_info[row_of_cell(cell)].newpage = what; } -bool LyXTabular::LTNewPage(int cell) +bool LyXTabular::GetLTNewPage(int cell) const { return row_info[row_of_cell(cell)].newpage; } @@ -1932,40 +2116,40 @@ void LyXTabular::SetDescentOfRow(int row, int height) row_info[row].descent_of_row = height; } -int LyXTabular::AscentOfRow(int row) +int LyXTabular::GetAscentOfRow(int row) const { if (row >= rows_) return 0; return row_info[row].ascent_of_row; } -int LyXTabular::DescentOfRow(int row) +int LyXTabular::GetDescentOfRow(int row) const { if (row >= rows_) return 0; return row_info[row].descent_of_row; } -int LyXTabular::HeightOfTabular() +int LyXTabular::GetHeightOfTabular() const { int height, row; for(row=0,height=0;(row= rows_) || (column >= columns_)) return false; return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN); } -int LyXTabular::Latex(ostream &) +int LyXTabular::Latex(ostream &) const { return 0; } diff --git a/src/tabular.h b/src/tabular.h index 4af9255c6c..67876bc567 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -68,50 +68,52 @@ public: }; /* konstruktor */ /// - LyXTabular(int columns_arg, int rows_arg, Buffer *buf = 0); + LyXTabular(int columns_arg, int rows_arg, Buffer *buf); /// /// - LyXTabular(LyXTabular const &, Buffer *buf = 0); + LyXTabular(LyXTabular const &, Buffer *buf); /// explicit - LyXTabular(LyXLex & lex, Buffer *buf = 0); + LyXTabular(LyXLex & lex, Buffer *buf); /// ~LyXTabular(); /// LyXTabular & operator=(LyXTabular const &); /// - LyXTabular * Clone(); + LyXTabular * Clone(Buffer * buf); /// Returns true if there is a topline, returns false if not - bool TopLine(int cell); + bool TopLine(int cell) const; /// Returns true if there is a topline, returns false if not - bool BottomLine(int cell); + bool BottomLine(int cell) const; /// Returns true if there is a topline, returns false if not - bool LeftLine(int cell); + bool LeftLine(int cell) const; /// Returns true if there is a topline, returns false if not - bool RightLine(int cell); + bool RightLine(int cell) const; /// - bool TopAlreadyDrawed(int cell); + bool TopAlreadyDrawed(int cell) const; /// - bool VeryLastRow(int cell); + bool LeftAlreadyDrawed(int cell) const; + /// + bool IsLastRow(int cell) const; /// - int AdditionalHeight(int cell); + int GetAdditionalHeight(int cell) const; /// - int AdditionalWidth(int cell); + int GetAdditionalWidth(int cell) const; /* returns the maximum over all rows */ /// - int WidthOfColumn(int cell); + int GetWidthOfColumn(int cell) const; /// - int WidthOfTabular(); + int GetWidthOfTabular() const; /// - int AscentOfRow(int row); + int GetAscentOfRow(int row) const; /// - int DescentOfRow(int row); + int GetDescentOfRow(int row) const; /// - int HeightOfTabular(); + int GetHeightOfTabular() const; /// void SetAscentOfRow(int row, int height); /// @@ -135,15 +137,15 @@ public: /// bool SetAlignSpecial(int cell, string special, int what); /// - char GetAlignment(int cell); // add approp. signedness + char GetAlignment(int cell) const; // add approp. signedness /// - string GetPWidth(int cell); + string GetPWidth(int cell) const; /// - string GetAlignSpecial(int cell, int what); + string GetAlignSpecial(int cell, int what) const; /// - int GetWidthOfCell(int cell); + int GetWidthOfCell(int cell) const; /// - int GetBeginningOfTextInCell(int cell); + int GetBeginningOfTextInCell(int cell) const; /// void AppendRow(int cell); /// @@ -153,49 +155,51 @@ public: /// void DeleteColumn(int cell); /// - bool IsFirstCellInRow(int cell); + bool IsFirstCellInRow(int cell) const; /// - bool IsLastCellInRow(int cell); + bool IsLastCellInRow(int cell) const; /// - int GetNumberOfCells(); + int GetNumberOfCells() const; /// int AppendCellAfterCell(int append_cell, int question_cell); /// int DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell); /// - int NumberOfCellsInRow(int cell); + int NumberOfCellsInRow(int cell) const; /// void Reinit(); /// void Init(int columns_arg, int rows_arg); /// - void Write(std::ostream &, bool old_format=true); + void Write(std::ostream &) const; /// - void Read(std::istream &); + void Read(LyXLex &); /// - int Latex(std::ostream &); + void OldFormatRead(std::istream &, string); + /// + int Latex(std::ostream &) const; // cell <0 will tex the preamble // returns the number of printed newlines /// - int TexEndOfCell(std::ostream &, int cell); + int TexEndOfCell(std::ostream &, int cell) const; /// - int DocBookEndOfCell(std::ostream &, int cell, int & depth); + int DocBookEndOfCell(std::ostream &, int cell, int & depth) const; #if 0 /// int RoffEndOfCell(std::ostream &, int cell); #endif /// - char const * getDocBookAlign(int cell, bool isColumn = false); + char const * GetDocBookAlign(int cell, bool isColumn = false) const; /// - bool IsMultiColumn(int cell); + bool IsMultiColumn(int cell) const; /// void SetMultiColumn(int cell, int number); /// int UnsetMultiColumn(int cell); // returns number of new cells /// - bool IsPartOfMultiColumn(int row, int column); + bool IsPartOfMultiColumn(int row, int column) const; /// int row_of_cell(int cell) const; /// @@ -203,47 +207,45 @@ public: /// void SetLongTabular(int what); /// - bool IsLongTabular(); + bool IsLongTabular() const; /// void SetRotateTabular(int what); /// - bool RotateTabular(); + bool GetRotateTabular() const; /// void SetRotateCell(int cell, int what); /// - bool RotateCell(int cell); + bool GetRotateCell(int cell) const; /// - bool NeedRotating(); + bool NeedRotating() const; /// - bool ShouldBeVeryLastCell(int cell); + bool IsLastCell(int cell) const; /// - bool IsLastRow(int cell); + int GetCellAbove(int cell) const; /// - int GetCellAbove(int cell); - /// - int GetCellNumber(int column, int row); + int GetCellNumber(int column, int row) const; /// void SetLinebreaks(int cell, bool what); /// - bool Linebreaks(int cell); + bool GetLinebreaks(int cell) const; /// /// Long Tabular Options /// void SetLTHead(int cell, bool first); /// - bool RowOfLTHead(int cell); + bool GetRowOfLTHead(int cell) const; /// - bool RowOfLTFirstHead(int cell); + bool GetRowOfLTFirstHead(int cell) const; /// void SetLTFoot(int cell, bool last); /// - bool RowOfLTFoot(int cell); + bool GetRowOfLTFoot(int cell) const; /// - bool RowOfLTLastFoot(int cell); + bool GetRowOfLTLastFoot(int cell) const; /// void SetLTNewPage(int cell, bool what); /// - bool LTNewPage(int cell); + bool GetLTNewPage(int cell) const; /// InsetText * GetCellInset(int cell) const; /// @@ -255,7 +257,7 @@ private: ////////////////////////////////////////////////////////////////// /// struct cellstruct { /// - cellstruct(Buffer * buf = 0); + cellstruct(Buffer * buf); /// ~cellstruct(); /// @@ -355,16 +357,16 @@ private: ////////////////////////////////////////////////////////////////// void calculate_width_of_tabular(); /// - int right_column_of_cell(int cell); + int right_column_of_cell(int cell) const; /// - cellstruct * cellinfo_of_cell(int cell); + cellstruct * cellinfo_of_cell(int cell) const; /// void delete_column(int column); /// - int cells_in_multicolumn(int cell); + int cells_in_multicolumn(int cell) const; /// int is_long_tabular; /// diff --git a/src/texrow.h b/src/texrow.h index 674d3c58dc..8db0533603 100644 --- a/src/texrow.h +++ b/src/texrow.h @@ -45,6 +45,9 @@ public: /// Appends another TexRow TexRow & operator+= (TexRow const &); + /// Returns the number of rows in this texrow + int rows() { return count; } + private: /// Linked list of items struct RowItem { diff --git a/src/text2.C b/src/text2.C index 07d1a7abf5..4cee34067b 100644 --- a/src/text2.C +++ b/src/text2.C @@ -474,12 +474,78 @@ void LyXText::MakeFontEntriesLayoutSpecific(LyXParagraph * par) } } +LyXParagraph * LyXText::SetLayout(LyXCursor & cur, LyXCursor & sstart_cur, + LyXCursor & send_cur, + LyXTextClass::size_type layout) +{ + LyXParagraph * endpar = send_cur.par->LastPhysicalPar()->Next(); + LyXParagraph * undoendpar = endpar; + + if (endpar && endpar->GetDepth()) { + while (endpar && endpar->GetDepth()) { + endpar = endpar->LastPhysicalPar()->Next(); + undoendpar = endpar; + } + } else if (endpar) { + endpar = endpar->Next(); // because of parindents etc. + } + + SetUndo(Undo::EDIT, + sstart_cur.par->ParFromPos(sstart_cur.pos)->previous, + undoendpar); + + /* ok we have a selection. This is always between sstart_cur + * and sel_end cursor */ + cur = sstart_cur; + + LyXLayout const & lyxlayout = + textclasslist.Style(buffer->params.textclass, layout); + + while (cur.par != send_cur.par) { + if (cur.par->footnoteflag == sstart_cur.par->footnoteflag) { + cur.par->SetLayout(layout); + MakeFontEntriesLayoutSpecific(cur.par); + LyXParagraph* fppar = cur.par->FirstPhysicalPar(); + fppar->added_space_top = lyxlayout.fill_top ? + VSpace(VSpace::VFILL) : VSpace(VSpace::NONE); + fppar->added_space_bottom = lyxlayout.fill_bottom ? + VSpace(VSpace::VFILL) : VSpace(VSpace::NONE); + if (lyxlayout.margintype == MARGIN_MANUAL) + cur.par->SetLabelWidthString(lyxlayout.labelstring()); + if (lyxlayout.labeltype != LABEL_BIBLIO + && fppar->bibkey) { + delete fppar->bibkey; + fppar->bibkey = 0; + } + } + cur.par = cur.par->Next(); + } + if (cur.par->footnoteflag == sstart_cur.par->footnoteflag) { + cur.par->SetLayout(layout); + MakeFontEntriesLayoutSpecific(cur.par); + LyXParagraph* fppar = cur.par->FirstPhysicalPar(); + fppar->added_space_top = lyxlayout.fill_top ? + VSpace(VSpace::VFILL) : VSpace(VSpace::NONE); + fppar->added_space_bottom = lyxlayout.fill_bottom ? + VSpace(VSpace::VFILL) : VSpace(VSpace::NONE); + if (lyxlayout.margintype == MARGIN_MANUAL) + cur.par->SetLabelWidthString(lyxlayout.labelstring()); + if (lyxlayout.labeltype != LABEL_BIBLIO + && fppar->bibkey) { + delete fppar->bibkey; + fppar->bibkey = 0; + } + } + return endpar; +} // set layout over selection and make a total rebreak of those paragraphs void LyXText::SetLayout(LyXTextClass::size_type layout) { - LyXCursor tmpcursor; + LyXCursor + tmpcursor = cursor; /* store the current cursor */ +#ifdef USE_OLD_SET_LAYOUT // if there is no selection just set the layout // of the current paragraph */ if (!selection) { @@ -504,8 +570,6 @@ void LyXText::SetLayout(LyXTextClass::size_type layout) sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous, undoendpar); - tmpcursor = cursor; /* store the current cursor */ - /* ok we have a selection. This is always between sel_start_cursor * and sel_end cursor */ cursor = sel_start_cursor; @@ -550,7 +614,16 @@ void LyXText::SetLayout(LyXTextClass::size_type layout) fppar->bibkey = 0; } } - +#else + // if there is no selection just set the layout + // of the current paragraph */ + if (!selection) { + sel_start_cursor = cursor; // dummy selection + sel_end_cursor = cursor; + } + LyXParagraph * + endpar = SetLayout(cursor, sel_start_cursor, sel_end_cursor, layout); +#endif RedoParagraphs(sel_start_cursor, endpar); // we have to reset the selection, because the @@ -2210,7 +2283,7 @@ void LyXText::CopySelection() DeleteSimpleCutBuffer(); // set the textclass - simple_cut_buffer_textclass = buffer->params->textclass; + simple_cut_buffer_textclass = buffer->params.textclass; // copy behind a space if there is one while (sel_start_cursor.par->Last() > sel_start_cursor.pos @@ -2457,7 +2530,7 @@ void LyXText::PasteSelection() // make sure there is no class difference cap.SwitchLayoutsBetweenClasses(simple_cut_buffer_textclass, - buffer->params->textclass, + buffer->params.textclass, simple_cut_buffer); // make the simple_cut_buffer exactly the same layout than