From b9288969ec06caa3d7b1e9d4eb7937c1e029b44f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sun, 3 Mar 2002 20:25:07 +0000 Subject: [PATCH] remove lowercase, better layout handling and some variable renameing git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3648 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/layouts/hollywood.layout | 1 + src/BufferView_pimpl.C | 49 ++++++++++-------- src/buffer.C | 66 ++++++++++++----------- src/bufferlist.C | 3 ++ src/insets/insetcaption.C | 4 +- src/insets/insetcaption.h | 2 +- src/insets/insetcollapsable.C | 8 +-- src/insets/insetcollapsable.h | 2 +- src/insets/insetert.C | 9 ++-- src/insets/insetert.h | 5 +- src/insets/insetfloat.C | 4 +- src/insets/insetfloat.h | 2 +- src/insets/insetfoot.C | 4 +- src/insets/insetfoot.h | 2 +- src/insets/insetfootlike.C | 4 +- src/insets/insetfootlike.h | 2 +- src/insets/insetmarginal.C | 4 +- src/insets/insetmarginal.h | 2 +- src/insets/insetminipage.C | 4 +- src/insets/insetminipage.h | 2 +- src/insets/insetnote.C | 6 +-- src/insets/insetnote.h | 2 +- src/insets/insettabular.C | 21 ++++---- src/insets/insettext.C | 18 ++++--- src/insets/insettext.h | 3 +- src/lyxlayout.C | 18 +++---- src/lyxtext.h | 5 +- src/lyxtextclass.C | 24 +++++---- src/paragraph.C | 2 + src/screen.C | 98 ++++++++++++++++++----------------- src/tabular-old.C | 4 +- src/tabular.C | 66 ++++++++++++----------- src/tabular.h | 20 ++++--- src/text.C | 47 +++++++++++++++++ src/text2.C | 12 +++-- 35 files changed, 308 insertions(+), 217 deletions(-) diff --git a/lib/layouts/hollywood.layout b/lib/layouts/hollywood.layout index 753d981322..10a76d072e 100644 --- a/lib/layouts/hollywood.layout +++ b/lib/layouts/hollywood.layout @@ -34,6 +34,7 @@ DefaultFont Color None EndFont +DefaultStyle Dialogue # Dialogue style definition. Actor dialog Style Dialogue diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index a7afbd8b2a..74dd4ca648 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -214,7 +214,7 @@ void BufferView::Pimpl::buffer(Buffer * b) updateScreen(); updateScrollbar(); } - bv_->text->first = screen_->topCursorVisible(bv_->text); + bv_->text->first_y = screen_->topCursorVisible(bv_->text); owner_->updateMenubar(); owner_->updateToolbar(); // Similarly, buffer-dependent dialogs should be updated or @@ -368,7 +368,7 @@ int BufferView::Pimpl::resizeCurrentBuffer() // remake the inset locking bv_->theLockingInset(the_locking_inset); } - bv_->text->first = screen_->topCursorVisible(bv_->text); + bv_->text->first_y = screen_->topCursorVisible(bv_->text); #if 0 buffer_->resizeInsets(bv_); #endif @@ -408,7 +408,7 @@ void BufferView::Pimpl::updateScrollbar() if (text_height <= work_height) { workarea_.setScrollbarBounds(0.0, 0.0); - current_scrollbar_value = bv_->text->first; + current_scrollbar_value = bv_->text->first_y; workarea_.setScrollbar(current_scrollbar_value, 1.0); return; } @@ -430,9 +430,9 @@ void BufferView::Pimpl::updateScrollbar() workarea_.setScrollbarIncrements(lineh); old_lineh = lineh; } - if (current_scrollbar_value != bv_->text->first + if (current_scrollbar_value != bv_->text->first_y || slider_size != old_slider_size) { - current_scrollbar_value = bv_->text->first; + current_scrollbar_value = bv_->text->first_y; workarea_.setScrollbar(current_scrollbar_value, slider_size); old_slider_size = slider_size; } @@ -462,8 +462,8 @@ void BufferView::Pimpl::scrollCB(double value) LyXText * vbt = bv_->text; int const height = vbt->defaultHeight(); - int const first = static_cast((bv_->text->first + height)); - int const last = static_cast((bv_->text->first + workarea_.height() - height)); + int const first = static_cast((bv_->text->first_y + height)); + int const last = static_cast((bv_->text->first_y + workarea_.height() - height)); if (vbt->cursor.y() < first) vbt->setCursorFromCoordinates(bv_, 0, first); @@ -558,7 +558,7 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state) bv_->theLockingInset()-> insetMotionNotify(bv_, x - start_x, - y - cursor.y() + bv_->text->first, + y - cursor.y() + bv_->text->first_y, state); return; } @@ -571,7 +571,7 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state) screen_->hideCursor(); - bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first); + bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y); if (!bv_->text->selection.set()) update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted @@ -621,7 +621,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos, selection_possible = true; screen_->hideCursor(); - int const screen_first = bv_->text->first; + int const screen_first = bv_->text->first_y; // Middle button press pastes if we have a selection bool paste_internally = false; @@ -941,7 +941,7 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y) if (!screen_.get()) return 0; - int y_tmp = y + text->first; + int y_tmp = y + text->first_y; LyXCursor cursor; text->setCursorFromCoordinates(bv_, cursor, x, y_tmp); @@ -1142,9 +1142,9 @@ void BufferView::Pimpl::cursorPrevious(LyXText * text) if (!text->cursor.row()->previous()) return; - int y = text->first; + int y = text->first_y; if (text->inset_owner) - y += bv_->text->first; + y += bv_->text->first_y; Row * cursorrow = text->cursor.row(); text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y); finishUndo(); @@ -1168,7 +1168,7 @@ void BufferView::Pimpl::cursorNext(LyXText * text) if (!text->cursor.row()->next()) return; - int y = text->first + workarea_.height(); + int y = text->first_y + workarea_.height(); // if (text->inset_owner) // y += bv_->text->first; text->getRowNearY(y); @@ -2743,11 +2743,11 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) break; case LFUN_INSET_TEXT: - insertAndEditInset(new InsetText); + insertAndEditInset(new InsetText(buffer_->params)); break; case LFUN_INSET_ERT: - insertAndEditInset(new InsetERT); + insertAndEditInset(new InsetERT(buffer_->params)); break; case LFUN_INSET_EXTERNAL: @@ -2755,25 +2755,26 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) break; case LFUN_INSET_FOOTNOTE: - insertAndEditInset(new InsetFoot); + insertAndEditInset(new InsetFoot(buffer_->params)); break; case LFUN_INSET_MARGINAL: - insertAndEditInset(new InsetMarginal); + insertAndEditInset(new InsetMarginal(buffer_->params)); break; case LFUN_INSET_MINIPAGE: - insertAndEditInset(new InsetMinipage); + insertAndEditInset(new InsetMinipage(buffer_->params)); break; case LFUN_INSERT_NOTE: - insertAndEditInset(new InsetNote); + insertAndEditInset(new InsetNote(buffer_->params)); break; case LFUN_INSET_FLOAT: // check if the float type exist if (floatList.typeExist(argument)) { - insertAndEditInset(new InsetFloat(argument)); + insertAndEditInset(new InsetFloat(buffer_->params, + argument)); } else { lyxerr << "Non-existent float type: " << argument << endl; @@ -2784,7 +2785,8 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { // check if the float type exist if (floatList.typeExist(argument)) { - InsetFloat * new_inset = new InsetFloat(argument); + InsetFloat * new_inset = + new InsetFloat(buffer_->params, argument); new_inset->wide(true); if (insertInset(new_inset)) new_inset->edit(bv_); @@ -2814,7 +2816,8 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) if (bv_->theLockingInset()) { lyxerr << "Locking inset code: " << static_cast(bv_->theLockingInset()->lyxCode()); - InsetCaption * new_inset = new InsetCaption; + InsetCaption * new_inset = + new InsetCaption(buffer_->params); new_inset->setOwner(bv_->theLockingInset()); new_inset->setAutoBreakRows(true); new_inset->setDrawFrame(0, InsetText::LOCKED); diff --git a/src/buffer.C b/src/buffer.C index 7c12a23684..3355eebfbf 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -405,7 +405,8 @@ void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive) if (!ert_comp.contents.empty()) { lyxerr[Debug::INSETS] << "ERT contents:\n'" << ert_comp.contents << "'" << endl; - Inset * inset = new InsetERT(params.language, ert_comp.contents, true); + Inset * inset = new InsetERT(params, params.language, + ert_comp.contents, true); par->insertInset(pos++, inset, ert_comp.font); ert_comp.contents.erase(); } @@ -462,11 +463,14 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, insertErtContents(par, pos); #endif lex.eatLine(); - string const layoutname = lowercase(lex.getString()); - //lyxerr << "Looking for layout '" - // << layoutname << "'!" << endl; - - //lyxerr << "Result: " << pp.first << "/" << pp.second << endl; + string const layoutname = lex.getString(); + LyXTextClass const & tclass = textclasslist[params.textclass]; + bool hasLayout = tclass.hasLayout(layoutname); + if (!hasLayout) { + lyxerr << "Layout '" << layoutname << "' does not" + << " exist in textclass '" << tclass.name() + << "'." << endl; + } #ifndef NO_COMPABILITY if (compare_no_case(layoutname, "latex") == 0) { @@ -565,28 +569,28 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, stringstream old_float; if (tmptok == "footnote") { - inset = new InsetFoot; + inset = new InsetFoot(params); old_float << "collapsed true\n"; } else if (tmptok == "margin") { - inset = new InsetMarginal; + inset = new InsetMarginal(params); old_float << "collapsed true\n"; } else if (tmptok == "fig") { - inset = new InsetFloat("figure"); + inset = new InsetFloat(params, "figure"); old_float << "placement htbp\n" << "wide false\n" << "collapsed false\n"; } else if (tmptok == "tab") { - inset = new InsetFloat("table"); + inset = new InsetFloat(params, "table"); old_float << "placement htbp\n" << "wide false\n" << "collapsed false\n"; } else if (tmptok == "alg") { - inset = new InsetFloat("algorithm"); + inset = new InsetFloat(params, "algorithm"); old_float << "placement htbp\n" << "wide false\n" << "collapsed false\n"; } else if (tmptok == "wide-fig") { - inset = new InsetFloat("figure"); + inset = new InsetFloat(params, "figure"); //InsetFloat * tmp = new InsetFloat("figure"); //tmp->wide(true); //inset = tmp; @@ -594,7 +598,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, << "wide true\n" << "collapsed false\n"; } else if (tmptok == "wide-tab") { - inset = new InsetFloat("table"); + inset = new InsetFloat(params, "table"); //InsetFloat * tmp = new InsetFloat("table"); //tmp->wide(true); //inset = tmp; @@ -1249,7 +1253,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, p->params().depth(parBeforeMinipage->params().depth()); parBeforeMinipage = p; } - InsetMinipage * mini = new InsetMinipage; + InsetMinipage * mini = new InsetMinipage(params); mini->pos(static_cast(par->params().pextraAlignment())); mini->pageWidth(LyXLength(par->params().pextraWidth())); if (!par->params().pextraWidthp().empty()) { @@ -1330,7 +1334,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, if (!first_par || (first_par == par)) first_par = p; - InsetMinipage * mini = new InsetMinipage; + InsetMinipage * mini = new InsetMinipage(params); mini->pos(static_cast(minipar->params().pextraAlignment())); mini->pageWidth(LyXLength(minipar->params().pextraWidth())); if (!par->params().pextraWidthp().empty()) { @@ -1496,26 +1500,26 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par, true); alreadyread = true; } else if (tmptok == "Note") { - inset = new InsetNote; + inset = new InsetNote(params); } else if (tmptok == "Include") { InsetCommandParams p("Include"); inset = new InsetInclude(p, *this); } else if (tmptok == "ERT") { - inset = new InsetERT; + inset = new InsetERT(params); } else if (tmptok == "Tabular") { inset = new InsetTabular(*this); } else if (tmptok == "Text") { - inset = new InsetText; + inset = new InsetText(params); } else if (tmptok == "Foot") { - inset = new InsetFoot; + inset = new InsetFoot(params); } else if (tmptok == "Marginal") { - inset = new InsetMarginal; + inset = new InsetMarginal(params); } else if (tmptok == "Minipage") { - inset = new InsetMinipage; + inset = new InsetMinipage(params); } else if (tmptok == "Float") { lex.next(); string tmptok = lex.getString(); - inset = new InsetFloat(tmptok); + inset = new InsetFloat(params, tmptok); #if 0 } else if (tmptok == "List") { inset = new InsetList; @@ -1523,7 +1527,7 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par, inset = new InsetList; #endif } else if (tmptok == "Caption") { - inset = new InsetCaption; + inset = new InsetCaption(params); } else if (tmptok == "FloatList") { inset = new InsetFloatList; } @@ -1792,26 +1796,26 @@ string const Buffer::asciiParagraph(Paragraph const * par, #endif // First write the layout - string const & tmp = lowercase(par->layout()); - if (tmp == "itemize") { + string const & tmp = par->layout(); + if (compare_no_case(tmp, "itemize") == 0) { ltype = 1; ltype_depth = depth + 1; - } else if (tmp == "enumerate") { + } else if (compare_no_case(tmp, "enumerate") == 0) { ltype = 2; ltype_depth = depth + 1; - } else if (contains(tmp, "ection")) { + } else if (contains(lowercase(tmp), "ection")) { ltype = 3; ltype_depth = depth + 1; - } else if (contains(tmp, "aragraph")) { + } else if (contains(lowercase(tmp), "aragraph")) { ltype = 4; ltype_depth = depth + 1; - } else if (tmp == "description") { + } else if (compare_no_case(tmp, "description") == 0) { ltype = 5; ltype_depth = depth + 1; - } else if (tmp == "abstract") { + } else if (compare_no_case(tmp, "abstract") == 0) { ltype = 6; ltype_depth = 0; - } else if (tmp == "bibliography") { + } else if (compare_no_case(tmp, "bibliography") == 0) { ltype = 7; ltype_depth = 0; } else { diff --git a/src/bufferlist.C b/src/bufferlist.C index 06ffaf43b1..894f069449 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -31,6 +31,7 @@ #include "LyXView.h" #include "vc-backend.h" #include "TextCache.h" +#include "lyxtextclasslist.h" #include "frontends/Alert.h" @@ -479,9 +480,11 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed) MakeDisplayPath(tname)); // no template, start with empty buffer b->paragraph = new Paragraph; + b->paragraph->layout(textclasslist[b->params.textclass].defaultLayoutName()); } } else { // start with empty buffer b->paragraph = new Paragraph; + b->paragraph->layout(textclasslist[b->params.textclass].defaultLayoutName()); } if (!lyxrc.new_ask_filename && !isNamed) { diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index f1ba9df2de..1b9a601ce2 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -27,8 +27,8 @@ using std::ostream; using std::endl; -InsetCaption::InsetCaption() - : InsetText() +InsetCaption::InsetCaption(BufferParams const & bp) + : InsetText(bp) { setAutoBreakRows(true); setDrawFrame(0, InsetText::LOCKED); diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index 27088e5e64..b97789eb52 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -24,7 +24,7 @@ class InsetCaption : public InsetText { public: /// - InsetCaption(); + InsetCaption(BufferParams const &); /// void write(Buffer const * buf, std::ostream & os) const; /// diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index e4015dd1cf..daa76e4db8 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -38,8 +38,8 @@ using std::max; class LyXText; -InsetCollapsable::InsetCollapsable(bool collapsed) - : UpdatableInset(), collapsed_(collapsed), +InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed) + : UpdatableInset(), collapsed_(collapsed), inset(bp), button_length(0), button_top_y(0), button_bottom_y(0), need_update(NONE), label("Label"), #if 0 @@ -56,8 +56,8 @@ InsetCollapsable::InsetCollapsable(bool collapsed) InsetCollapsable::InsetCollapsable(InsetCollapsable const & in, bool same_id) - : UpdatableInset(in, same_id), collapsed_(in.collapsed_), - framecolor(in.framecolor), labelfont(in.labelfont), + : UpdatableInset(in, same_id), collapsed_(in.collapsed_), + framecolor(in.framecolor), labelfont(in.labelfont), inset(in.inset), button_length(0), button_top_y(0), button_bottom_y(0), need_update(NONE), label(in.label), #if 0 diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 2880a32027..5af2ce5eda 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -42,7 +42,7 @@ public: /// static int const TEXT_TO_BOTTOM_OFFSET = 2; /// inset is initially collapsed if bool = true - InsetCollapsable(bool = false); + InsetCollapsable(BufferParams const &, bool = false); /// InsetCollapsable(InsetCollapsable const & in, bool same_id = false); /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 53ada70eb0..d1f4dbeee2 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -50,8 +50,8 @@ void InsetERT::init() } -InsetERT::InsetERT(bool collapsed) - : InsetCollapsable(collapsed) +InsetERT::InsetERT(BufferParams const & bp, bool collapsed) + : InsetCollapsable(bp, collapsed) { if (collapsed) status_ = Collapsed; @@ -74,8 +74,9 @@ Inset * InsetERT::clone(Buffer const &, bool same_id) const } -InsetERT::InsetERT(Language const * l, string const & contents, bool collapsed) - : InsetCollapsable(collapsed) +InsetERT::InsetERT(BufferParams const & bp, + Language const * l, string const & contents, bool collapsed) + : InsetCollapsable(bp, collapsed) { if (collapsed) status_ = Collapsed; diff --git a/src/insets/insetert.h b/src/insets/insetert.h index f1537267c9..8c9c57ce54 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -41,13 +41,14 @@ public: Inlined }; /// - InsetERT(bool collapsed=false); + InsetERT(BufferParams const &, bool collapsed = false); /// InsetERT(InsetERT const &, bool same_id = false); /// Inset * clone(Buffer const &, bool same_id = false) const; /// - InsetERT(Language const *, string const & contents, bool collapsed); + InsetERT(BufferParams const &, + Language const *, string const & contents, bool collapsed); /// ~InsetERT(); /// diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index e31523429f..40c4ebe947 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -99,8 +99,8 @@ using std::endl; // // Lgb -InsetFloat::InsetFloat(string const & type) - : InsetCollapsable(), wide_(false) +InsetFloat::InsetFloat(BufferParams const & bp, string const & type) + : InsetCollapsable(bp), wide_(false) { string lab(_("float:")); lab += type; diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index 4228886716..b9709328d9 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -27,7 +27,7 @@ class Painter; class InsetFloat : public InsetCollapsable { public: /// - InsetFloat(string const &); + InsetFloat(BufferParams const &, string const &); /// InsetFloat(InsetFloat const &, bool same_id = false); /// diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index a2297b6cd9..5e1d870834 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -27,8 +27,8 @@ using std::ostream; -InsetFoot::InsetFoot() - : InsetFootlike() +InsetFoot::InsetFoot(BufferParams const & bp) + : InsetFootlike(bp) { setLabel(_("foot")); setInsetName("Foot"); diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index 275a69c39e..092f0e7f8f 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -27,7 +27,7 @@ class InsetFoot : public InsetFootlike { public: /// - InsetFoot(); + InsetFoot(BufferParams const &); /// InsetFoot(InsetFoot const &, bool same_id = false); /// diff --git a/src/insets/insetfootlike.C b/src/insets/insetfootlike.C index fcbe711ba7..f401f78bf2 100644 --- a/src/insets/insetfootlike.C +++ b/src/insets/insetfootlike.C @@ -24,8 +24,8 @@ using std::ostream; -InsetFootlike::InsetFootlike() - : InsetCollapsable() +InsetFootlike::InsetFootlike(BufferParams const & bp) + : InsetCollapsable(bp) { LyXFont font(LyXFont::ALL_SANE); font.decSize(); diff --git a/src/insets/insetfootlike.h b/src/insets/insetfootlike.h index 1e678ff909..e721632b21 100644 --- a/src/insets/insetfootlike.h +++ b/src/insets/insetfootlike.h @@ -28,7 +28,7 @@ class InsetFootlike : public InsetCollapsable { public: /// - InsetFootlike(); + InsetFootlike(BufferParams const &); /// InsetFootlike(InsetFootlike const &, bool same_id = false); /// diff --git a/src/insets/insetmarginal.C b/src/insets/insetmarginal.C index 1a0eb1b5be..babd19772f 100644 --- a/src/insets/insetmarginal.C +++ b/src/insets/insetmarginal.C @@ -27,8 +27,8 @@ using std::ostream; -InsetMarginal::InsetMarginal() - : InsetFootlike() +InsetMarginal::InsetMarginal(BufferParams const & bp) + : InsetFootlike(bp) { setLabel(_("margin")); setInsetName("Marginal"); diff --git a/src/insets/insetmarginal.h b/src/insets/insetmarginal.h index 10329a9712..cb7a6fca2f 100644 --- a/src/insets/insetmarginal.h +++ b/src/insets/insetmarginal.h @@ -24,7 +24,7 @@ class InsetMarginal : public InsetFootlike { public: /// - InsetMarginal(); + InsetMarginal(BufferParams const &); /// InsetMarginal(InsetMarginal const &, bool same_id = false); /// diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 9d19468013..b01bd3b858 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -59,8 +59,8 @@ using std::endl; // have to output "" for minipages. // (Lgb) -InsetMinipage::InsetMinipage() - : InsetCollapsable(), pos_(center), +InsetMinipage::InsetMinipage(BufferParams const & bp) + : InsetCollapsable(bp), pos_(center), inner_pos_(inner_center), width_(100, LyXLength::PW) { setLabel(_("minipage")); diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index e46de56167..b58a7b8cf9 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -39,7 +39,7 @@ public: inner_stretch }; /// - InsetMinipage(); + InsetMinipage(BufferParams const &); /// InsetMinipage(InsetMinipage const &, bool same_id = false); /// diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index da3c39bfd6..f8b3598c7d 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -41,8 +41,8 @@ void InsetNote::init() } -InsetNote::InsetNote() - : InsetCollapsable() +InsetNote::InsetNote(BufferParams const & bp) + : InsetCollapsable(bp) { init(); } @@ -64,7 +64,7 @@ Inset * InsetNote::clone(Buffer const &, bool same_id) const // This constructor is used for reading old InsetInfo InsetNote::InsetNote(Buffer const * buf, string const & contents, bool collapsed) - : InsetCollapsable(collapsed) + : InsetCollapsable(buf->params, collapsed) { init(); diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index 5def38e637..ed02318d08 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -24,7 +24,7 @@ class InsetNote : public InsetCollapsable { public: /// - InsetNote(); + InsetNote(BufferParams const &); /// InsetNote(InsetNote const &, bool same_id = false); /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 7f9ae0cf01..ea5ee8aae5 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -135,7 +135,7 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns) rows = 1; if (columns <= 0) columns = 1; - tabular.reset(new LyXTabular(this, rows, columns)); + tabular.reset(new LyXTabular(buf.params, this, rows, columns)); // for now make it always display as display() inset // just for test!!! the_locking_inset = 0; @@ -156,7 +156,8 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf, bool same_id) : UpdatableInset(tab, same_id), buffer(&buf) { - tabular.reset(new LyXTabular(this, *(tab.tabular), same_id)); + tabular.reset(new LyXTabular(buf.params, + this, *(tab.tabular), same_id)); the_locking_inset = 0; old_locking_inset = 0; locked = false; @@ -1037,10 +1038,10 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action, } int column = actcol; unlockInsetInInset(bv, the_locking_inset); - if (bv->text->first + bv->painter().paperHeight() < + if (bv->text->first_y + bv->painter().paperHeight() < (top_baseline + tabular->GetHeightOfTabular())) { - bv->scrollCB(bv->text->first + bv->painter().paperHeight()); + bv->scrollCB(bv->text->first_y + bv->painter().paperHeight()); code = FULL; actcell = tabular->GetCellBelow(first_visible_cell) + column; } else { @@ -1059,7 +1060,7 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action, int column = actcol; unlockInsetInInset(bv, the_locking_inset); if (top_baseline < 0) { - bv->scrollCB(bv->text->first - bv->painter().paperHeight()); + bv->scrollCB(bv->text->first_y - bv->painter().paperHeight()); code = FULL; if (top_baseline > 0) actcell = column; @@ -1148,7 +1149,8 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action, } maxCols = max(cols, maxCols); delete paste_tabular; - paste_tabular = new LyXTabular(this, rows, maxCols); + paste_tabular = new LyXTabular(bv->buffer()->params, + this, rows, maxCols); string::size_type op = 0; int cell = 0; int cells = paste_tabular->GetNumberOfCells(); @@ -1869,13 +1871,13 @@ void InsetTabular::tabularFeatures(BufferView * bv, case LyXTabular::APPEND_ROW: // append the row into the tabular unlockInsetInInset(bv, the_locking_inset); - tabular->AppendRow(actcell); + tabular->AppendRow(bv->buffer()->params, actcell); updateLocal(bv, INIT, true); break; case LyXTabular::APPEND_COLUMN: // append the column into the tabular unlockInsetInInset(bv, the_locking_inset); - tabular->AppendColumn(actcell); + tabular->AppendColumn(bv->buffer()->params, actcell); actcell = tabular->GetCellNumber(row, column); updateLocal(bv, INIT, true); break; @@ -2426,7 +2428,8 @@ bool InsetTabular::copySelection(BufferView * bv) int const rows = sel_row_end - sel_row_start + 1; delete paste_tabular; - paste_tabular = new LyXTabular(this, *tabular); // rows, columns); + paste_tabular = new LyXTabular(bv->buffer()->params, + this, *tabular); // rows, columns); for (int i = 0; i < sel_row_start; ++i) paste_tabular->DeleteRow(0); while (paste_tabular->rows() > rows) diff --git a/src/insets/insettext.C b/src/insets/insettext.C index f22c7cf84e..db840f6b13 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -135,11 +135,13 @@ InsetText::InnerCache::InnerCache(boost::shared_ptr t) } -InsetText::InsetText() +InsetText::InsetText(BufferParams const & bp) : UpdatableInset(), lt(0), in_update(false), do_resize(0), do_reinit(false) { par = new Paragraph; + par->layout(textclasslist[bp.textclass].defaultLayoutName()); + init(); } @@ -445,7 +447,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, } if (y_offset < 0) y_offset = y; - lt->first = first; + lt->first_y = first; if (cleared || (need_update&(INIT|FULL))) { int yf = y_offset; y = 0; @@ -897,7 +899,7 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button) mouse_y = y; int tmp_x = x - drawTextXOffset; - int tmp_y = y + insetAscent - getLyXText(bv)->first; + int tmp_y = y + insetAscent - getLyXText(bv)->first_y; Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y); hideInsetCursor(bv); @@ -1002,7 +1004,7 @@ bool InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button) button); } int tmp_x = x - drawTextXOffset; - int tmp_y = y + insetAscent - getLyXText(bv)->first; + int tmp_y = y + insetAscent - getLyXText(bv)->first_y; Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y); bool ret = false; if (inset) { @@ -1324,7 +1326,7 @@ InsetText::localDispatch(BufferView * bv, // Derive layout number from given argument (string) // and current buffer's textclass (number). */ textclass_type tclass = bv->buffer()->params.textclass; - string layout = lowercase(arg); + string layout = arg; bool hasLayout = textclasslist[tclass].hasLayout(layout); // If the entry is obsolete, use the new one instead. @@ -1333,7 +1335,7 @@ InsetText::localDispatch(BufferView * bv, textclasslist[tclass][layout]. obsoleted_by(); if (!obs.empty()) - layout = lowercase(obs); + layout = obs; } // see if we found the layout number: @@ -2251,7 +2253,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const } if (bv->screen()) { - t->first = bv->screen()->topCursorVisible(t); + t->first_y = bv->screen()->topCursorVisible(t); } if (!owner()) { updateLocal(bv, FULL, false); @@ -2291,7 +2293,7 @@ void InsetText::reinitLyXText() const inset_y = cy(bv) + drawTextYOffset; } if (bv->screen()) { - t->first = bv->screen()->topCursorVisible(t); + t->first_y = bv->screen()->topCursorVisible(t); } if (!owner()) { updateLocal(bv, FULL, false); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 55aea7d4e9..91fe8da05b 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -30,6 +30,7 @@ class Painter; class BufferView; class Buffer; +class BufferParams; class LyXCursor; class LyXText; class LyXScreen; @@ -73,7 +74,7 @@ public: ALWAYS }; /// - InsetText(); + InsetText(BufferParams const &); /// explicit InsetText(InsetText const &, bool same_id = false); diff --git a/src/lyxlayout.C b/src/lyxlayout.C index bc9eda4107..0fd63445cc 100644 --- a/src/lyxlayout.C +++ b/src/lyxlayout.C @@ -180,12 +180,12 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) case LT_COPYSTYLE: // initialize with a known style if (lexrc.next()) { - string const style = lowercase(lexrc.getString()); + string const style = lexrc.getString(); if (tclass.hasLayout(style)) { - string const tmpname = lowercase(name_); + string const tmpname = name_; this->operator=(tclass[style]); - name_ = lowercase(tmpname); + name_ = tmpname; } else { lyxerr << "Cannot copy unknown style `" << style << "'" << endl; LyXTextClass::const_iterator it = tclass.begin(); @@ -203,7 +203,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) case LT_OBSOLETEDBY: // replace with a known style if (lexrc.next()) { - string const style = lowercase(lexrc.getString()); + string const style = lexrc.getString(); if (tclass.hasLayout(style)) { string const tmpname = name_; @@ -736,21 +736,17 @@ void LyXLayout::readSpacing(LyXLex & lexrc) string const & LyXLayout::name() const { - static string name_t; - name_t = lowercase(name_); - return name_t; + return name_; } void LyXLayout::setName(string const & n) { - name_ = lowercase(n); + name_ = n; } string const & LyXLayout::obsoleted_by() const { - static string obsoleted_by_t; - obsoleted_by_t = lowercase(obsoleted_by_); - return obsoleted_by_t; + return obsoleted_by_; } diff --git a/src/lyxtext.h b/src/lyxtext.h index 89ffc10999..18812862ca 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -85,7 +85,7 @@ public: mutable LyXFont real_current_font; /// first visible pixel-row is set from LyXScreen!!! // unsigned is wrong here for text-insets! - int first; + int first_y; /// BufferView * bv_owner; /// @@ -507,9 +507,10 @@ public: private: /// mutable Row * firstrow; + /// mutable Row * lastrow; - + /** Copybuffer for copy environment type. Asger has learned that this should be a buffer-property instead Lgb has learned that 'char' is a lousy type for non-characters diff --git a/src/lyxtextclass.C b/src/lyxtextclass.C index cefc00a93b..7fdb478d96 100644 --- a/src/lyxtextclass.C +++ b/src/lyxtextclass.C @@ -172,14 +172,15 @@ bool LyXTextClass::Read(string const & filename, bool merge) case TC_DEFAULTSTYLE: if (lexrc.next()) { - string const name = subst(lowercase(lexrc.getString()), '_', ' '); + string const name = subst(lexrc.getString(), + '_', ' '); defaultlayout_ = name; } break; case TC_STYLE: if (lexrc.next()) { - string const name = subst(lowercase(lexrc.getString()), + string const name = subst(lexrc.getString(), '_', ' '); if (hasLayout(name)) { LyXLayout & lay = operator[](name); @@ -189,6 +190,13 @@ bool LyXTextClass::Read(string const & filename, bool merge) lay.setName(name); if (!(error = do_readStyle(lexrc, lay))) layoutlist.push_back(lay); + if (defaultlayout_.empty()) { + // We do not have a default + // layout yet, so we choose + // the first layout we + // encounter. + defaultlayout_ = name; + } } } else { @@ -199,7 +207,7 @@ bool LyXTextClass::Read(string const & filename, bool merge) case TC_NOSTYLE: if (lexrc.next()) { - string const style = subst(lowercase(lexrc.getString()), + string const style = subst(lexrc.getString(), '_', ' '); if (!delete_layout(style)) lyxerr << "Cannot delete style `" << style << "'" << endl; @@ -487,7 +495,7 @@ string const & LyXTextClass::rightmargin() const bool LyXTextClass::hasLayout(string const & n) const { - string const name = (n.empty() ? defaultLayoutName() : lowercase(n)); + string const name = (n.empty() ? defaultLayoutName() : n); return find_if(layoutlist.begin(), layoutlist.end(), lyx::compare_memfun(&LyXLayout::name, name)) @@ -500,7 +508,7 @@ LyXLayout const & LyXTextClass::operator[](string const & n) const if (n.empty()) lyxerr << "Operator[] called with empty n" << endl; - string const name = (n.empty() ? defaultLayoutName() : lowercase(n)); + string const name = (n.empty() ? defaultLayoutName() : n); LayoutList::const_iterator cit = find_if(layoutlist.begin(), @@ -525,7 +533,7 @@ LyXLayout & LyXTextClass::operator[](string const & n) if (n.empty()) lyxerr << "Operator[] called with empty n" << endl; - string const name = (n.empty() ? defaultLayoutName() : lowercase(n)); + string const name = (n.empty() ? defaultLayoutName() : n); LayoutList::iterator it = find_if(layoutlist.begin(), @@ -545,10 +553,8 @@ LyXLayout & LyXTextClass::operator[](string const & n) } -bool LyXTextClass::delete_layout(string const & n) +bool LyXTextClass::delete_layout(string const & name) { - string const name = lowercase(n); - if (name == defaultLayoutName()) return false; diff --git a/src/paragraph.C b/src/paragraph.C index e8fb22e4f3..bcc3eb9864 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -859,6 +859,8 @@ void Paragraph::breakParagraph(BufferParams const & bparams, { // create a new paragraph Paragraph * tmp = new Paragraph(this); + tmp->layout(layout()); + // remember to set the inset_owner tmp->setInsetOwner(inInset()); diff --git a/src/screen.C b/src/screen.C index b76facc058..ee6202e324 100644 --- a/src/screen.C +++ b/src/screen.C @@ -115,19 +115,19 @@ void LyXScreen::drawFromTo(LyXText * text, BufferView * bv, int y1, int y2, int y_offset, int x_offset, bool internal) { - int y_text = text->first + y1; + int y_text = text->first_y + y1; // get the first needed row Row * row = text->getRowNearY(y_text); // y_text is now the real beginning of the row - int y = y_text - text->first; + int y = y_text - text->first_y; // y1 is now the real beginning of row on the screen while (row != 0 && y < y2) { LyXText::text_status st = text->status(); text->getVisibleRow(bv, y + y_offset, - x_offset, row, y + text->first); + x_offset, row, y + text->first_y); internal = internal && (st != LyXText::CHANGED_IN_DRAW); while (internal && text->status() == LyXText::CHANGED_IN_DRAW) { if (text->fullRebreak(bv)) { @@ -136,7 +136,7 @@ void LyXScreen::drawFromTo(LyXText * text, BufferView * bv, } text->status(bv, st); text->getVisibleRow(bv, y + y_offset, - x_offset, row, y + text->first); + x_offset, row, y + text->first_y); } y += row->height(); row = row->next(); @@ -156,7 +156,7 @@ void LyXScreen::drawFromTo(LyXText * text, BufferView * bv, void LyXScreen::drawOneRow(LyXText * text, BufferView * bv, Row * row, int y_text, int y_offset, int x_offset) { - int const y = y_text - text->first + y_offset; + int const y = y_text - text->first_y + y_offset; if (((y + row->height()) > 0) && ((y - row->height()) <= static_cast(owner.height()))) { @@ -166,12 +166,12 @@ void LyXScreen::drawOneRow(LyXText * text, BufferView * bv, Row * row, do { bv->text->status(bv, st); text->getVisibleRow(bv, y, x_offset, row, - y + text->first); + y + text->first_y); } while (!text->inset_owner && text->status() == LyXText::CHANGED_IN_DRAW); bv->text->status(bv, st); #else - text->getVisibleRow(bv, y, x_offset, row, y + text->first); + text->getVisibleRow(bv, y, x_offset, row, y + text->first_y); #endif } force_clear = false; @@ -184,16 +184,17 @@ void LyXScreen::draw(LyXText * text, BufferView * bv, unsigned int y) { if (cursor_visible) hideCursor(); - int const old_first = text->first; + int const old_first = text->first_y; bool internal = (text == bv->text); - text->first = y; + text->first_y = y; // is any optimiziation possible? if ((y - old_first) < owner.height() && (old_first - y) < owner.height()) { - if (text->first < old_first) { - drawFromTo(text, bv, 0, old_first - text->first, 0, 0, internal); + if (text->first_y < old_first) { + drawFromTo(text, bv, 0, + old_first - text->first_y, 0, 0, internal); XCopyArea (fl_get_display(), owner.getWin(), owner.getWin(), @@ -201,31 +202,31 @@ void LyXScreen::draw(LyXText * text, BufferView * bv, unsigned int y) owner.xpos(), owner.ypos(), owner.workWidth(), - owner.height() - old_first + text->first, + owner.height() - old_first + text->first_y, owner.xpos(), - owner.ypos() + old_first - text->first + owner.ypos() + old_first - text->first_y ); // expose the area drawn expose(0, 0, owner.workWidth(), - old_first - text->first); + old_first - text->first_y); } else { drawFromTo(text, bv, - owner.height() + old_first - text->first, + owner.height() + old_first - text->first_y, owner.height(), 0, 0, internal); XCopyArea (fl_get_display(), owner.getWin(), owner.getWin(), gc_copy, owner.xpos(), - owner.ypos() + text->first - old_first, + owner.ypos() + text->first_y - old_first, owner.workWidth(), - owner.height() + old_first - text->first, + owner.height() + old_first - text->first_y, owner.xpos(), owner.ypos()); // expose the area drawn - expose(0, owner.height() + old_first - text->first, - owner.workWidth(), text->first - old_first); + expose(0, owner.height() + old_first - text->first_y, + owner.workWidth(), text->first_y - old_first); } } else { // make a dumb new-draw @@ -257,20 +258,20 @@ void LyXScreen::showCursor(LyXText const * text, BufferView const * bv) bool LyXScreen::fitManualCursor(LyXText * text, BufferView * bv, int /*x*/, int y, int asc, int desc) { - int newtop = text->first; + int newtop = text->first_y; - if (y + desc - text->first >= static_cast(owner.height())) + if (y + desc - text->first_y >= static_cast(owner.height())) newtop = y - 3 * owner.height() / 4; // the scroll region must be so big!! - else if (y - asc < static_cast(text->first) - && text->first > 0) { + else if (y - asc < text->first_y + && text->first_y > 0) { newtop = y - owner.height() / 4; } newtop = max(newtop, 0); // can newtop ever be < 0? (Lgb) - if (newtop != static_cast(text->first)) { + if (newtop != text->first_y) { draw(text, bv, newtop); - text->first = newtop; + text->first_y = newtop; return true; } return false; @@ -283,8 +284,8 @@ void LyXScreen::showManualCursor(LyXText const * text, int x, int y, // Update the cursor color. setCursorColor(); - int const y1 = max(y - text->first - asc, 0); - int const y_tmp = min(y - text->first + desc, + int const y1 = max(y - text->first_y - asc, 0); + int const y_tmp = min(y - text->first_y + desc, static_cast(owner.height())); // Secure against very strange situations @@ -386,7 +387,7 @@ void LyXScreen::cursorToggle(BufferView * bv) const /* returns a new top so that the cursor is visible */ unsigned int LyXScreen::topCursorVisible(LyXText const * text) { - int newtop = text->first; + int newtop = text->first_y; Row * row = text->cursor.row(); @@ -395,7 +396,7 @@ unsigned int LyXScreen::topCursorVisible(LyXText const * text) return max(newtop, 0); if (text->cursor.y() - row->baseline() + row->height() - - text->first >= owner.height()) { + - text->first_y >= owner.height()) { if (row->height() < owner.height() && row->height() > owner.height() / 4) { newtop = text->cursor.y() @@ -408,14 +409,14 @@ unsigned int LyXScreen::topCursorVisible(LyXText const * text) } } else if (static_cast((text->cursor.y()) - row->baseline()) < - text->first && text->first > 0) { + text->first_y && text->first_y > 0) { if (row->height() < owner.height() && row->height() > owner.height() / 4) { newtop = text->cursor.y() - row->baseline(); } else { // scroll up newtop = text->cursor.y() - owner.height() / 2; - newtop = min(newtop, int(text->first)); + newtop = min(newtop, text->first_y); } } @@ -431,7 +432,7 @@ bool LyXScreen::fitCursor(LyXText * text, BufferView * bv) { // Is a change necessary? int const newtop = topCursorVisible(text); - bool const result = (newtop != text->first); + bool const result = (newtop != text->first_y); if (result) draw(text, bv, newtop); return result; @@ -444,7 +445,7 @@ void LyXScreen::update(LyXText * text, BufferView * bv, switch (text->status()) { case LyXText::NEED_MORE_REFRESH: { - int const y = max(int(text->refresh_y - text->first), 0); + int const y = max(int(text->refresh_y - text->first_y), 0); drawFromTo(text, bv, y, owner.height(), y_offset, x_offset); text->refresh_y = 0; // otherwise this is called ONLY from BufferView_pimpl(update) @@ -466,7 +467,7 @@ void LyXScreen::update(LyXText * text, BufferView * bv, // or we should see to set this flag accordingly if (text != bv->text) text->status(bv, LyXText::UNCHANGED); - expose(0, text->refresh_y - text->first + y_offset, + expose(0, text->refresh_y - text->first_y + y_offset, owner.workWidth(), text->refresh_row->height()); } } @@ -490,21 +491,21 @@ void LyXScreen::toggleSelection(LyXText * text, BufferView * bv, max(static_cast(text->selection.end.y() - text->selection.end.row()->baseline() + text->selection.end.row()->height()), - text->first), - static_cast(text->first + owner.height())); + text->first_y), + static_cast(text->first_y + owner.height())); int const top = min( max(static_cast(text->selection.start.y() - text->selection.start.row()->baseline()), - text->first), - static_cast(text->first + owner.height())); + text->first_y), + static_cast(text->first_y + owner.height())); if (kill_selection) text->selection.set(false); - drawFromTo(text, bv, top - text->first, bottom - text->first, + drawFromTo(text, bv, top - text->first_y, bottom - text->first_y, y_offset, x_offset); - expose(0, top - text->first, + expose(0, top - text->first_y, owner.workWidth(), - bottom - text->first - (top - text->first)); + bottom - text->first_y - (top - text->first_y)); } @@ -521,13 +522,14 @@ void LyXScreen::toggleToggle(LyXText * text, BufferView * bv, - text->toggle_end_cursor.row()->baseline() + text->toggle_end_cursor.row()->height(); - int const bottom = min(max(bottom_tmp, text->first), - static_cast(text->first + owner.height())); - int const top = min(max(top_tmp, text->first), - static_cast(text->first + owner.height())); + int const bottom = min(max(bottom_tmp, text->first_y), + static_cast(text->first_y + owner.height())); + int const top = min(max(top_tmp, text->first_y), + static_cast(text->first_y + owner.height())); - drawFromTo(text, bv, top - text->first, bottom - text->first, y_offset, + drawFromTo(text, bv, top - text->first_y, + bottom - text->first_y, y_offset, x_offset); - expose(0, top - text->first, owner.workWidth(), - bottom - text->first - (top - text->first)); + expose(0, top - text->first_y, owner.workWidth(), + bottom - text->first_y - (top - text->first_y)); } diff --git a/src/tabular-old.C b/src/tabular-old.C index 1ab944317f..3e06db9a68 100644 --- a/src/tabular-old.C +++ b/src/tabular-old.C @@ -13,7 +13,9 @@ #include #include "tabular.h" +#include "buffer.h" #include "debug.h" + #include "support/lstrings.h" #include "support/textutils.h" @@ -159,7 +161,7 @@ void LyXTabular::ReadOld(Buffer const * buf, istream & is, return; if (!getTokenValue(line, "columns", columns_arg)) return; - Init(rows_arg, columns_arg); + Init(buf->params, rows_arg, columns_arg); l_getline(is, line); if (!prefixIs(line, " got" << diff --git a/src/tabular.C b/src/tabular.C index de046eab70..e72d5ae0b6 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -58,7 +58,8 @@ namespace { /// Define a few methods for the inner structs -LyXTabular::cellstruct::cellstruct() +LyXTabular::cellstruct::cellstruct(BufferParams const & bg) + : inset(bg) { cellno = 0; width_of_cell = 0; @@ -107,20 +108,22 @@ LyXTabular::lttype::lttype() /* konstruktor */ -LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg) +LyXTabular::LyXTabular(BufferParams const & bp, + InsetTabular * inset, int rows_arg, int columns_arg) { owner_ = inset; cur_cell = -1; - Init(rows_arg, columns_arg); + Init(bp, rows_arg, columns_arg); } -LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt, +LyXTabular::LyXTabular(BufferParams const & bp, + InsetTabular * inset, LyXTabular const & lt, bool same_id) { owner_ = inset; cur_cell = -1; - Init(lt.rows_, lt.columns_, <); + Init(bp, lt.rows_, lt.columns_, <); // we really should change again to have InsetText as a pointer // and allocate it then we would not have to do this stuff all // double! @@ -174,9 +177,10 @@ LyXTabular & LyXTabular::operator=(LyXTabular const & lt) } -LyXTabular * LyXTabular::clone(InsetTabular * inset, bool same_id) +LyXTabular * LyXTabular::clone(BufferParams const & bp, + InsetTabular * inset, bool same_id) { - LyXTabular * result = new LyXTabular(inset, *this, same_id); + LyXTabular * result = new LyXTabular(bp, inset, *this, same_id); #if 0 // don't know if this is good but I need to Clone also // the text-insets here, this is for the Undo-facility! @@ -192,13 +196,14 @@ LyXTabular * LyXTabular::clone(InsetTabular * inset, bool same_id) /* activates all lines and sets all widths to 0 */ -void LyXTabular::Init(int rows_arg, int columns_arg, LyXTabular const * lt) +void LyXTabular::Init(BufferParams const & bp, + int rows_arg, int columns_arg, LyXTabular const * lt) { rows_ = rows_arg; columns_ = columns_arg; row_info = row_vector(rows_, rowstruct()); column_info = column_vector(columns_, columnstruct()); - cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct())); + cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp))); if (lt) { operator=(*lt); @@ -232,7 +237,7 @@ void LyXTabular::Init(int rows_arg, int columns_arg, LyXTabular const * lt) } -void LyXTabular::AppendRow(int cell) +void LyXTabular::AppendRow(BufferParams const & bp, int cell) { ++rows_; @@ -241,14 +246,14 @@ void LyXTabular::AppendRow(int cell) row_vector::iterator rit = row_info.begin() + row; row_info.insert(rit, rowstruct()); // now set the values of the row before - row_info[row] = row_info[row+1]; + row_info[row] = row_info[row + 1]; #if 0 cell_vvector::iterator cit = cell_info.begin() + row; - cell_info.insert(cit, vector(columns_, cellstruct())); + cell_info.insert(cit, vector(columns_, cellstruct(bp))); #else cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_, - cellstruct())); + cellstruct(bp))); for (int i = 0; i <= row; ++i) { for (int j = 0; j < columns_; ++j) { @@ -281,17 +286,17 @@ void LyXTabular::DeleteRow(int row) } -void LyXTabular::AppendColumn(int cell) +void LyXTabular::AppendColumn(BufferParams const & bp, int cell) { ++columns_; cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_, - cellstruct())); + cellstruct(bp))); int const column = column_of_cell(cell); column_vector::iterator cit = column_info.begin() + column + 1; column_info.insert(cit, columnstruct()); // set the column values of the column before - column_info[column+1] = column_info[column]; + column_info[column + 1] = column_info[column]; for (int i = 0; i < rows_; ++i) { for (int j = 0; j <= column; ++j) { @@ -1084,7 +1089,7 @@ void LyXTabular::Read(Buffer const * buf, LyXLex & lex) l_getline(is, line); if (!prefixIs(line, "params, lex, line); return; } @@ -1110,7 +1115,7 @@ void LyXTabular::setHeaderFooterRows(int hr, int fhr, int fr, int lfr) row_info[--fhr].endfirsthead = true; row_info[fhr].endhead = false; } - } else if (row_info[fhr-1].endhead) { + } else if (row_info[fhr - 1].endhead) { endfirsthead.empty = true; } else { while((fhr > 0) && !row_info[--fhr].endhead) { @@ -1130,7 +1135,7 @@ void LyXTabular::setHeaderFooterRows(int hr, int fhr, int fr, int lfr) row_info[fr].endfoot = true; row_info[fr].endfirsthead = false; } - } else if (!row_info[fr-1].endhead && !row_info[fr-1].endfirsthead) { + } else if (!row_info[fr - 1].endhead && !row_info[fr - 1].endfirsthead) { while((fr > 0) && !row_info[--fr].endhead && !row_info[fr].endfirsthead) { @@ -1140,25 +1145,27 @@ void LyXTabular::setHeaderFooterRows(int hr, int fhr, int fr, int lfr) } // set lastfooter info if (lfr && (lfr < rows_)) { - if (row_info[lfr].endhead && row_info[lfr-1].endhead) { + if (row_info[lfr].endhead && row_info[lfr - 1].endhead) { while((lfr > 0) && !row_info[--lfr].endhead) { row_info[lfr].endlastfoot = true; row_info[lfr].endhead = false; } } else if (row_info[lfr].endfirsthead && - row_info[lfr-1].endfirsthead) + row_info[lfr - 1].endfirsthead) { while((lfr > 0) && !row_info[--lfr].endfirsthead) { row_info[lfr].endlastfoot = true; row_info[lfr].endfirsthead = false; } - } else if (row_info[lfr].endfoot && row_info[lfr-1].endfoot) { + } else if (row_info[lfr].endfoot + && row_info[lfr - 1].endfoot) { while((lfr > 0) && !row_info[--lfr].endfoot) { row_info[lfr].endlastfoot = true; row_info[lfr].endfoot = false; } - } else if (!row_info[fr-1].endhead && !row_info[fr-1].endfirsthead && - !row_info[fr-1].endfoot) + } else if (!row_info[fr - 1].endhead + && !row_info[fr - 1].endfirsthead && + !row_info[fr - 1].endfoot) { while((lfr > 0) && !row_info[--lfr].endhead && !row_info[lfr].endfirsthead && @@ -1173,7 +1180,7 @@ void LyXTabular::setHeaderFooterRows(int hr, int fhr, int fr, int lfr) } void LyXTabular::ReadNew(Buffer const * buf, istream & is, - LyXLex & lex, string const & l, int const version) + LyXLex & lex, string const & l, int const version) { string line(l); int rows_arg; @@ -1182,7 +1189,7 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is, int columns_arg; if (!getTokenValue(line, "columns", columns_arg)) return; - Init(rows_arg, columns_arg); + Init(buf->params, rows_arg, columns_arg); l_getline(is, line); if (!prefixIs(line, " got" << @@ -1294,7 +1301,8 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is, } -void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) +void LyXTabular::OldFormatRead(BufferParams const & bp, + LyXLex & lex, string const & fl) { int version; int i; @@ -1332,7 +1340,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) >> rotate_arg >> a >> b >> c >> d; } else is >> rows_arg >> columns_arg; - Init(rows_arg, columns_arg); + Init(bp, rows_arg, columns_arg); cont_row_info = vector(rows_arg); SetLongTabular(is_long_tabular_arg); SetRotateTabular(rotate_arg); @@ -1352,7 +1360,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) } else { is >> rows_arg >> columns_arg >> is_long_tabular_arg >> rotate_arg >> a >> b >> c >> d; - Init(rows_arg, columns_arg); + Init(bp, rows_arg, columns_arg); cont_row_info = vector(rows_arg); SetLongTabular(is_long_tabular_arg); SetRotateTabular(rotate_arg); diff --git a/src/tabular.h b/src/tabular.h index 9352f04258..7a03f8fd95 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -178,16 +178,19 @@ public: /* konstruktor */ /// - LyXTabular(InsetTabular *, int columns_arg, int rows_arg); + LyXTabular(BufferParams const &, + InsetTabular *, int columns_arg, int rows_arg); /// - LyXTabular(InsetTabular *, LyXTabular const &, bool same_id = false); + LyXTabular(BufferParams const &, + InsetTabular *, LyXTabular const &, bool same_id = false); /// explicit LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex); /// LyXTabular & operator=(LyXTabular const &); /// - LyXTabular * clone(InsetTabular *, bool same_id = false); + LyXTabular * clone(BufferParams const &, + InsetTabular *, bool same_id = false); /// Returns true if there is a topline, returns false if not bool TopLine(int cell, bool onlycolumn = false) const; @@ -266,11 +269,11 @@ public: /// int GetBeginningOfTextInCell(int cell) const; /// - void AppendRow(int cell); + void AppendRow(BufferParams const &, int cell); /// void DeleteRow(int row); /// - void AppendColumn(int cell); + void AppendColumn(BufferParams const &, int cell); /// void DeleteColumn(int column); /// @@ -290,7 +293,7 @@ public: /// void Read(Buffer const *, LyXLex &); /// - void OldFormatRead(LyXLex &, string const &); + void OldFormatRead(BufferParams const &, LyXLex &, string const &); /// int latex(Buffer const *, std::ostream &, bool, bool) const; /// @@ -398,7 +401,7 @@ private: /// struct cellstruct { /// - cellstruct(); + cellstruct(BufferParams const &); /// int cellno; /// @@ -525,7 +528,8 @@ private: InsetTabular * owner_; /// - void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0); + void Init(BufferParams const &, + int columns_arg, int rows_arg, LyXTabular const * lt = 0); /// void Reinit(bool reset_widths = true); /// diff --git a/src/text.C b/src/text.C index 04152131f3..44c7a81e4f 100644 --- a/src/text.C +++ b/src/text.C @@ -3826,6 +3826,7 @@ Row * LyXText::getRow(Paragraph * par, pos_type pos, int & y) const Row * LyXText::getRowNearY(int & y) const { +#if 1 // If possible we should optimize this method. (Lgb) Row * tmprow = firstrow; int tmpy = 0; @@ -3836,7 +3837,53 @@ Row * LyXText::getRowNearY(int & y) const } y = tmpy; // return the real y + + lyxerr << "returned y = " << y << endl; + return tmprow; +#else + // Search from the current cursor position. + + Row * tmprow = cursor.row(); + int tmpy = cursor.y() - tmprow->baseline(); + + lyxerr << "cursor.y() = " << tmpy << endl; + lyxerr << "tmprow->height() = " << tmprow->height() << endl; + lyxerr << "tmprow->baseline() = " << tmprow->baseline() << endl; + lyxerr << "first = " << first << endl; + lyxerr << "y = " << y << endl; + + if (y < tmpy) { + lyxerr << "up" << endl; +#if 0 + while (tmprow && tmpy - tmprow->height() >= y) { + tmpy -= tmprow->height(); + tmprow = tmprow->previous(); + } +#else + do { + tmpy -= tmprow->height(); + tmprow = tmprow->previous(); + } while (tmprow && tmpy - tmprow->height() >= y); +#endif + } else if (y > tmpy) { + lyxerr << "down" << endl; + + while (tmprow->next() && tmpy + tmprow->height() <= y) { + tmpy += tmprow->height(); + tmprow = tmprow->next(); + } + } else { + lyxerr << "equal" << endl; + } + + y = tmpy; // return the real y + + lyxerr << "returned y = " << y << endl; + + return tmprow; + +#endif } diff --git a/src/text2.C b/src/text2.C index fab6665f65..caed3ece55 100644 --- a/src/text2.C +++ b/src/text2.C @@ -55,7 +55,7 @@ using lyx::pos_type; LyXText::LyXText(BufferView * bv) - : number_of_rows(0), height(0), width(0), first(0), + : number_of_rows(0), height(0), width(0), first_y(0), bv_owner(bv), inset_owner(0), the_locking_inset(0), need_break_row(0), refresh_y(0), refresh_row(0), status_(LyXText::UNCHANGED), firstrow(0), lastrow(0) @@ -63,7 +63,7 @@ LyXText::LyXText(BufferView * bv) LyXText::LyXText(InsetText * inset) - : number_of_rows(0), height(0), width(0), first(0), + : number_of_rows(0), height(0), width(0), first_y(0), bv_owner(0), inset_owner(inset), the_locking_inset(0), need_break_row(0), refresh_y(0), refresh_row(0), status_(LyXText::UNCHANGED), firstrow(0), lastrow(0) @@ -80,16 +80,20 @@ void LyXText::init(BufferView * bview, bool reinit) delete firstrow; firstrow = tmprow; } - lastrow = refresh_row = need_break_row = 0; + + lastrow = 0; + refresh_row = 0; + need_break_row = 0; width = height = 0; copylayouttype.erase(); - number_of_rows = first = refresh_y = 0; + number_of_rows = first_y = refresh_y = 0; status_ = LyXText::UNCHANGED; } else if (firstrow) return; Paragraph * par = ownerParagraph(); current_font = getFont(bview->buffer(), par, 0); + while (par) { insertParagraph(bview, par, lastrow); par = par->next(); -- 2.39.2