diff --git a/po/POTFILES.in b/po/POTFILES.in index cf76b83237..225ff4f4b4 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -177,7 +177,6 @@ src/mathed/formulamacro.C src/mathed/math_hullinset.C src/mathed/math_macrotemplate.C src/mathed/math_nestinset.C -src/mathed/math_parboxinset.C src/mathed/ref_inset.C src/output.C src/output_docbook.C diff --git a/src/ChangeLog b/src/ChangeLog index 29a0121abf..9449533a90 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,10 +1,30 @@ +2004-08-14 Lars Gullik Bjonnes + + * text3.C: use Debug::DEBUG a bit more + + * text.C (leftMargin): try to simplify a tiny bit change var x to + l_margin. Dont output the wide margins always. + (rightMargin): no margin in inner texts + + * rowpainter.h (nestMargin): new func + (changebarMargin): new func + (rightMargin): new func + + * rowpainter.C (paintDepthBar): changebarMargin and nestMargin is + now functions. + (paintLast): ditto + + * factory.C (createInset): modify setDrawFrame + + * cursor.C: use Debug::DEBUG a bit more + 2004-08-14 André Pönitz * coordcache.[Ch]: * Makefile.am: new files to accomodate an 'external' (x,y)-position cache for all insets in (at least partially) visible (top-level) paragraphs. - + * BufferView_pimpl.C: reset external coord cache before every update. This means the coord cache only contains valid entries. diff --git a/src/cursor.C b/src/cursor.C index 947d70b610..2a45dbd4da 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -44,6 +44,7 @@ #include "frontends/LyXView.h" #include +#include #include @@ -96,7 +97,7 @@ namespace { double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); // '<=' in order to take the last possible position // this is important for clicking behind \sum in e.g. '\sum_i a' - lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl; + lyxerr[Debug::DEBUG] << "i: " << i << " d: " << d << " best: " << best_dist << endl; if (d <= best_dist) { best_dist = d; result = it; @@ -197,8 +198,8 @@ void LCursor::dispatch(FuncRequest const & cmd0) FuncRequest cmd = cmd0; LCursor safe = *this; - for ( ; size(); pop()) { - lyxerr << "LCursor::dispatch: cmd: " << cmd0 << endl << *this << endl; + for (; size(); pop()) { + lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: " << cmd0 << endl << *this << endl; BOOST_ASSERT(pos() <= lastpos()); BOOST_ASSERT(idx() <= lastidx()); BOOST_ASSERT(par() <= lastpar()); @@ -1001,7 +1002,7 @@ bool LCursor::goUpDown(bool up) void LCursor::handleFont(string const & font) { - lyxerr << "LCursor::handleFont: " << font << endl; + lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": " << font << endl; string safe; if (selection()) { macroModeClose(); @@ -1150,5 +1151,3 @@ void LCursor::noUpdate() { disp_.update(false); } - - diff --git a/src/factory.C b/src/factory.C index 66ae5f30e5..03a285a3c3 100644 --- a/src/factory.C +++ b/src/factory.C @@ -187,7 +187,7 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd) if (!up) { auto_ptr inset(new InsetCaption(params)); inset->setAutoBreakRows(true); - inset->setDrawFrame(InsetText::LOCKED); + inset->setDrawFrame(true); inset->setFrameColor(LColor::captionframe); return inset.release(); } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 33d652f1b6..853bd8e7a4 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,4 +1,12 @@ +2004-08-14 Lars Gullik Bjonnes + * insettext.[Ch] (setDrawFrame): take a bool, get rid of the + DrawFrame enum. + + * insetcaption.C (InsetCaption): modify call to setDrawFrame + * insetcollapsable.C (InsetCollapsable): ditto + * insetenv.C (InsetEnvironment): ditto + 2004-08-14 André Pönitz * inset.[Ch]: @@ -9,16 +17,16 @@ * insetoptarg.C (latexOptional): if the optional argument contains a ']' enclose it in {curly brackets} - * insettext.C (editXY): - * insettabular.C (editXY): - * insetcollapsable.C (editXY): + * insettext.C (editXY): + * insettabular.C (editXY): + * insetcollapsable.C (editXY): * insetbase.C (editXY): constify * insetcollapsable.C (priv_dispatch): on a mouse press event, do not ask for an update if we did nothing; on a mouse release, make sure that the cursor is moved to the right position; on a mouse release, exit from the inset instead of invoking a - LFUN_FINISHED_RIGHT. + LFUN_FINISHED_RIGHT. * insetbase.C (dispatch): before invoking dispatch, set cursor result to dispatch=update=true. diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index 37e9c4ef9f..cf1d9965b0 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -44,7 +44,7 @@ InsetCaption::InsetCaption(BufferParams const & bp) : InsetText(bp) { setAutoBreakRows(true); - setDrawFrame(InsetText::LOCKED); + setDrawFrame(true); setFrameColor(LColor::captionframe); } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 31c4350b53..f8de8e7f6c 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -55,7 +55,7 @@ InsetCollapsable::InsetCollapsable(BufferParams const & bp, : InsetText(bp), label("Label"), status_(status), openinlined_(false) { setAutoBreakRows(true); - setDrawFrame(InsetText::ALWAYS); + setDrawFrame(true); setFrameColor(LColor::collapsableframe); setInsetName("Collapsable"); setButtonLabel(); @@ -253,16 +253,16 @@ InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) const void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd) { -// lyxerr << "InsetCollapsable::priv_dispatch (begin): cmd: " << cmd -// << " button y: " << button_dim.y2 -// << " coll/inline/open: " << status_ << endl; +// lyxerr << "InsetCollapsable::priv_dispatch (begin): cmd: " << cmd +// << " button y: " << button_dim.y2 +// << " coll/inline/open: " << status_ << endl; switch (cmd.action) { case LFUN_MOUSE_PRESS: if (status_ == Inlined) InsetText::priv_dispatch(cur, cmd); else if (status_ == Open && !hitButton(cmd)) InsetText::priv_dispatch(cur, cmd); - else + else cur.noUpdate(); break; diff --git a/src/insets/insetenv.C b/src/insets/insetenv.C index 6898757a0c..5980ab9aed 100644 --- a/src/insets/insetenv.C +++ b/src/insets/insetenv.C @@ -32,7 +32,7 @@ InsetEnvironment::InsetEnvironment { setInsetName(name); setAutoBreakRows(true); - setDrawFrame(ALWAYS); + setDrawFrame(true); } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index cd751325f5..268d19a599 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -69,7 +69,7 @@ using std::vector; InsetText::InsetText(BufferParams const & bp) - : autoBreakRows_(false), drawFrame_(NEVER), + : autoBreakRows_(false), drawFrame_(false), frame_color_(LColor::insetframe), text_(0) { paragraphs().push_back(Paragraph()); @@ -205,7 +205,7 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const text_.draw(pi, x, y + bv->top_y()); - if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED) + if (drawFrame_) drawFrame(pi.pain, x, y); } @@ -306,7 +306,7 @@ void InsetText::edit(LCursor & cur, bool left) InsetBase * InsetText::editXY(LCursor & cur, int x, int y) const { - lyxerr << "InsetText::edit xy" << endl; + lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << endl; old_par = -1; return text_.editXY(cur, x, y); //sanitizeEmptyText(cur.bv()); @@ -448,9 +448,9 @@ void InsetText::setAutoBreakRows(bool flag) } -void InsetText::setDrawFrame(DrawFrame how) +void InsetText::setDrawFrame(bool flag) { - drawFrame_ = how; + drawFrame_ = flag; } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 09ba688011..a44fadf153 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -38,15 +38,6 @@ class Row; */ class InsetText : public UpdatableInset { public: - /// - enum DrawFrame { - /// - NEVER = 0, - /// - LOCKED, - /// - ALWAYS - }; /// explicit InsetText(BufferParams const &); /// @@ -102,7 +93,7 @@ public: /// bool getAutoBreakRows() const { return autoBreakRows_; } /// - void setDrawFrame(DrawFrame); + void setDrawFrame(bool); /// LColor_color frameColor() const; /// @@ -174,7 +165,7 @@ private: /// bool autoBreakRows_; /// - DrawFrame drawFrame_; + bool drawFrame_; /** We store the LColor::color value as an int to get LColor.h out * of the header file. */ diff --git a/src/rowpainter.C b/src/rowpainter.C index 56fd368fe4..9f970230c3 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -47,9 +47,6 @@ using std::endl; using std::max; using std::string; -extern int NEST_MARGIN; -extern int CHANGEBAR_MARGIN; - namespace { @@ -129,8 +126,10 @@ RowPainter::RowPainter(BufferView const & bv, Painter & pain, //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo // << " pit->y: " << pit_->y // << " row: " << (pars_[pit_].size() ? pars_[pit_].getChar(row_.pos()) : 'X') << endl; + RowMetrics m = text_.computeRowMetrics(pit, row_); x_ = m.x + xo_; + separator_ = m.separator; hfill_ = m.hfill; label_hfill_ = m.label_hfill; @@ -544,11 +543,12 @@ void RowPainter::paintDepthBar() } for (Paragraph::depth_type i = 1; i <= depth; ++i) { - int const w = NEST_MARGIN / 5; - int x = int(w * i + xo_); + int const w = nestMargin() / 5; + int x = xo_ + w * i; // only consider the changebar space if we're drawing outer left if (xo_ == 0) - x += CHANGEBAR_MARGIN; + x += changebarMargin(); + int const h = yo_ + row_.height() - 1 - (i - next_depth - 1) * 3; pain_.line(x, yo_, x, h, LColor::depthbar); @@ -718,7 +718,7 @@ void RowPainter::paintLast() LyXFont const font = getLabelFont(); int const size = int(0.75 * font_metrics::maxAscent(font)); int const y = yo_ + row_.baseline() - size; - int x = is_rtl ? NEST_MARGIN + CHANGEBAR_MARGIN: width_ - size; + int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size; if (width_ - int(row_.width()) <= size) x += (size - width_ + row_.width() + 1) * (is_rtl ? -1 : 1); diff --git a/src/rowpainter.h b/src/rowpainter.h index b3904b27f5..05c5f538ec 100644 --- a/src/rowpainter.h +++ b/src/rowpainter.h @@ -29,4 +29,25 @@ void refreshPar(BufferView const & bv, LyXText const & text, /// paint the rows of a text inset void paintTextInset(LyXText const & text, PainterInfo & pi); +/// some space for drawing the 'nested' markers (in pixel) +inline int nestMargin() +{ + return 15; +} + + +/// margin for changebar +inline int changebarMargin() +{ + return 10; +} + + +/// right margin +inline int rightMargin() +{ + return 30; +} + + #endif // ROWPAINTER_H diff --git a/src/tabular.C b/src/tabular.C index c3da317f2c..0cb7adec7b 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -377,7 +377,9 @@ void LyXTabular::fixCellNums() int cellno = 0; for (int i = 0; i < rows_; ++i) { for (int j = 0; j < columns_; ++j) { - cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED); + // When debugging it can be nice to set + // this to true. + cell_info[i][j].inset.setDrawFrame(false); cell_info[i][j].cellno = cellno++; } cell_info[i].back().right_line = true; diff --git a/src/text.C b/src/text.C index 6c6c06b303..7fe1ce68f5 100644 --- a/src/text.C +++ b/src/text.C @@ -90,14 +90,6 @@ using std::endl; using std::string; -/// some space for drawing the 'nested' markers (in pixel) -extern int const NEST_MARGIN = 20; -/// margin for changebar -extern int const CHANGEBAR_MARGIN = 10; -/// right margin -extern int const RIGHT_MARGIN = 10; - - namespace { int numberOfSeparators(Paragraph const & par, Row const & row) @@ -506,40 +498,26 @@ int LyXText::leftMargin(par_type pit, pos_type pos) const string parindent = layout->parindent; - int x = NEST_MARGIN + CHANGEBAR_MARGIN; + int l_margin = 0; - x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont()); + if (xo_ == 0) + l_margin += changebarMargin(); - // This is the way LyX handles LaTeX-Environments. - // I have had this idea very late, so it seems to be a - // later added hack and this is true - if (pars_[pit].getDepth() == 0) { - if (pars_[pit].layout() == tclass.defaultLayout()) { - // find the previous same level paragraph - if (pit != 0) { - par_type newpit = - depthHook(pit, paragraphs(), pars_[pit].getDepth()); - if (newpit == pit && pars_[newpit].layout()->nextnoindent) - parindent.erase(); + l_margin += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont()); + + if (pars_[pit].getDepth() != 0) { + // find the next level paragraph + par_type newpar = outerHook(pit, pars_); + if (newpar != par_type(pars_.size())) { + if (pars_[newpar].layout()->isEnvironment()) { + l_margin = leftMargin(newpar); + } + if (pars_[pit].layout() == tclass.defaultLayout()) { + if (pars_[newpar].params().noindent()) + parindent.erase(); + else + parindent = pars_[newpar].layout()->parindent; } - } - } else { - // find the next level paragraph - par_type newpar = outerHook(pit, pars_); - - // Make a corresponding row. Need to call leftMargin() - // to check whether it is a sufficent paragraph. - if (newpar != par_type(pars_.size()) - && pars_[newpar].layout()->isEnvironment()) { - x = leftMargin(newpar); - } - - if (newpar != par_type(paragraphs().size()) - && pars_[pit].layout() == tclass.defaultLayout()) { - if (pars_[newpar].params().noindent()) - parindent.erase(); - else - parindent = pars_[newpar].layout()->parindent; } } @@ -547,41 +525,41 @@ int LyXText::leftMargin(par_type pit, pos_type pos) const switch (layout->margintype) { case MARGIN_DYNAMIC: if (!layout->leftmargin.empty()) - x += font_metrics::signedWidth(layout->leftmargin, + l_margin += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()); if (!pars_[pit].getLabelstring().empty()) { - x += font_metrics::signedWidth(layout->labelindent, + l_margin += font_metrics::signedWidth(layout->labelindent, labelfont); - x += font_metrics::width(pars_[pit].getLabelstring(), + l_margin += font_metrics::width(pars_[pit].getLabelstring(), labelfont); - x += font_metrics::width(layout->labelsep, labelfont); + l_margin += font_metrics::width(layout->labelsep, labelfont); } break; case MARGIN_MANUAL: - x += font_metrics::signedWidth(layout->labelindent, labelfont); + l_margin += font_metrics::signedWidth(layout->labelindent, labelfont); // The width of an empty par, even with manual label, should be 0 if (!pars_[pit].empty() && pos >= pars_[pit].beginOfBody()) { if (!pars_[pit].getLabelWidthString().empty()) { - x += font_metrics::width(pars_[pit].getLabelWidthString(), + l_margin += font_metrics::width(pars_[pit].getLabelWidthString(), labelfont); - x += font_metrics::width(layout->labelsep, labelfont); + l_margin += font_metrics::width(layout->labelsep, labelfont); } } break; case MARGIN_STATIC: - x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4 + l_margin += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4 / (pars_[pit].getDepth() + 4); break; case MARGIN_FIRST_DYNAMIC: if (layout->labeltype == LABEL_MANUAL) { if (pos >= pars_[pit].beginOfBody()) { - x += font_metrics::signedWidth(layout->leftmargin, + l_margin += font_metrics::signedWidth(layout->leftmargin, labelfont); } else { - x += font_metrics::signedWidth(layout->labelindent, + l_margin += font_metrics::signedWidth(layout->labelindent, labelfont); } } else if (pos != 0 @@ -589,17 +567,17 @@ int LyXText::leftMargin(par_type pit, pos_type pos) const // theorems (JMarc) || (layout->labeltype == LABEL_STATIC && layout->latextype == LATEX_ENVIRONMENT - && !isFirstInSequence(pit, paragraphs()))) { - x += font_metrics::signedWidth(layout->leftmargin, + && !isFirstInSequence(pit, pars_))) { + l_margin += font_metrics::signedWidth(layout->leftmargin, labelfont); } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT && layout->labeltype != LABEL_BIBLIO && layout->labeltype != LABEL_CENTERED_TOP_ENVIRONMENT) { - x += font_metrics::signedWidth(layout->labelindent, + l_margin += font_metrics::signedWidth(layout->labelindent, labelfont); - x += font_metrics::width(layout->labelsep, labelfont); - x += font_metrics::width(pars_[pit].getLabelstring(), + l_margin += font_metrics::width(layout->labelsep, labelfont); + l_margin += font_metrics::width(pars_[pit].getLabelstring(), labelfont); } break; @@ -617,19 +595,18 @@ int LyXText::leftMargin(par_type pit, pos_type pos) const for ( ; rit != end; ++rit) if (rit->fill() < minfill) minfill = rit->fill(); - x += font_metrics::signedWidth(layout->leftmargin, + l_margin += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()); - x += minfill; + l_margin += minfill; #endif // also wrong, but much shorter. - x += maxwidth_ / 2; + l_margin += maxwidth_ / 2; break; } } - if (!pars_[pit].params().leftIndent().zero()) - x += pars_[pit].params().leftIndent().inPixels(maxwidth_); + l_margin += pars_[pit].params().leftIndent().inPixels(maxwidth_); LyXAlignment align; @@ -645,20 +622,20 @@ int LyXText::leftMargin(par_type pit, pos_type pos) const || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT || (layout->labeltype == LABEL_STATIC && layout->latextype == LATEX_ENVIRONMENT - && !isFirstInSequence(pit, paragraphs()))) + && !isFirstInSequence(pit, pars_))) && align == LYX_ALIGN_BLOCK && !pars_[pit].params().noindent() // in tabulars and ert paragraphs are never indented! - && (pars_[pit].ownerCode() != InsetOld::TABULAR_CODE - && pars_[pit].ownerCode() != InsetOld::ERT_CODE) + && (pars_[pit].ownerCode() != InsetBase::TEXT_CODE + && pars_[pit].ownerCode() != InsetBase::ERT_CODE) && (pars_[pit].layout() != tclass.defaultLayout() || bv()->buffer()->params().paragraph_separation == BufferParams::PARSEP_INDENT)) { - x += font_metrics::signedWidth(parindent, tclass.defaultfont()); + l_margin += font_metrics::signedWidth(parindent, tclass.defaultfont()); } - return x; + return l_margin; } @@ -666,13 +643,20 @@ int LyXText::rightMargin(Paragraph const & par) const { LyXTextClass const & tclass = bv()->buffer()->params().getLyXTextClass(); - return - RIGHT_MARGIN + // We do not want rightmargins on inner texts. + if (bv()->text() != this) + return 0; + + int const r_margin = + ::rightMargin() + font_metrics::signedWidth(tclass.rightmargin(), - tclass.defaultfont()) + tclass.defaultfont()) + font_metrics::signedWidth(par.layout()->rightmargin, - tclass.defaultfont()) + tclass.defaultfont()) * 4 / (par.getDepth() + 4); + + return r_margin; + } diff --git a/src/text3.C b/src/text3.C index adf27cfc27..d07a337b24 100644 --- a/src/text3.C +++ b/src/text3.C @@ -186,7 +186,7 @@ string const freefont2string() // takes absolute x,y coordinates -InsetBase * LyXText::checkInsetHit(int x, int y) const +InsetBase * LyXText::checkInsetHit(int x, int y) const { par_type pit; par_type end; @@ -196,15 +196,17 @@ InsetBase * LyXText::checkInsetHit(int x, int y) const bv()->top_y() - yo_ + bv()->workHeight(), pit, end); - lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl; - lyxerr << " pit: " << pit << " end: " << end << endl; + lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION + << ": x: " << x << " y: " << y + << " pit: " << pit << " end: " << end << endl; for (; pit != end; ++pit) { InsetList::const_iterator iit = pars_[pit].insetlist.begin(); InsetList::const_iterator iend = pars_[pit].insetlist.end(); for (; iit != iend; ++iit) { InsetBase * inset = iit->inset; #if 1 - lyxerr << "examining inset " << inset << endl; + lyxerr[Debug::DEBUG] + << "examining inset " << inset << endl; if (theCoords.insets_.has(inset)) lyxerr << " xo: " << inset->xo() << "..." << inset->xo() + inset->width() @@ -214,12 +216,13 @@ InsetBase * LyXText::checkInsetHit(int x, int y) const lyxerr << " inset has no cached position"; #endif if (inset->covers(x, y)) { - lyxerr << "Hit inset: " << inset << endl; + lyxerr[Debug::DEBUG] + << "Hit inset: " << inset << endl; return inset; } } } - lyxerr << "No inset hit. " << endl; + lyxerr[Debug::DEBUG] << "No inset hit. " << endl; return 0; } @@ -1448,21 +1451,21 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) } case LFUN_FINISHED_LEFT: - lyxerr << "handle LFUN_FINISHED_LEFT:\n" << cur << endl; + lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl; break; case LFUN_FINISHED_RIGHT: - lyxerr << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl; + lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl; ++cur.pos(); break; case LFUN_FINISHED_UP: - lyxerr << "handle LFUN_FINISHED_UP:\n" << cur << endl; + lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl; cursorUp(cur); break; case LFUN_FINISHED_DOWN: - lyxerr << "handle LFUN_FINISHED_DOWN:\n" << cur << endl; + lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl; cursorDown(cur); break;