some nicer margins and some small cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8925 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2004-08-14 15:55:22 +00:00
parent 5a153a4961
commit d20f0af816
15 changed files with 149 additions and 122 deletions

View File

@ -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

View File

@ -1,10 +1,30 @@
2004-08-14 Lars Gullik Bjonnes <larsbj@lyx.org>
* 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 <poenitz@gmx.net>
* 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.

View File

@ -44,6 +44,7 @@
#include "frontends/LyXView.h"
#include <boost/assert.hpp>
#include <boost/current_function.hpp>
#include <sstream>
@ -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);
}

View File

@ -187,7 +187,7 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
if (!up) {
auto_ptr<InsetCaption> inset(new InsetCaption(params));
inset->setAutoBreakRows(true);
inset->setDrawFrame(InsetText::LOCKED);
inset->setDrawFrame(true);
inset->setFrameColor(LColor::captionframe);
return inset.release();
}

View File

@ -1,4 +1,12 @@
2004-08-14 Lars Gullik Bjonnes <larsbj@lyx.org>
* 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 <poenitz@gmx.net>
* 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.

View File

@ -44,7 +44,7 @@ InsetCaption::InsetCaption(BufferParams const & bp)
: InsetText(bp)
{
setAutoBreakRows(true);
setDrawFrame(InsetText::LOCKED);
setDrawFrame(true);
setFrameColor(LColor::captionframe);
}

View File

@ -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;

View File

@ -32,7 +32,7 @@ InsetEnvironment::InsetEnvironment
{
setInsetName(name);
setAutoBreakRows(true);
setDrawFrame(ALWAYS);
setDrawFrame(true);
}

View File

@ -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;
}

View File

@ -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.
*/

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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;