We do not even have to fake any length here, just using the 'natural' width of the label does not make things worse.
Would be nice if we had a 'desire width' field for InsetButton at some point of time, though... Andre'
Index: paragraph_funcs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.C,v retrieving revision 1.44 diff -u -p -r1.44 paragraph_funcs.C --- paragraph_funcs.C 29 May 2003 01:13:16 -0000 1.44 +++ paragraph_funcs.C 2 Jun 2003 17:20:58 -0000 @@ -34,11 +34,9 @@ #include "insets/insethfill.h" #include "insets/inseterror.h" #include "insets/insetnewline.h" - -extern string bibitemWidest(Buffer const *); +#include "frontends/font_metrics.h" using lyx::pos_type; -//using lyx::layout_type; using std::endl; using std::ostream; @@ -311,6 +309,40 @@ TeXDeeper(Buffer const * buf, return par; } + +namespace { + +string const bibitemWidest(Buffer const * buffer) +{ + int w = 0; + // Does look like a hack? It is! (but will change at 0.13) + // And now we are at 1.4.0 .. (Andre) + + InsetBibitem const * bitem = 0; + LyXFont font; + + ParagraphList::const_iterator it = buffer->paragraphs.begin(); + ParagraphList::const_iterator end = buffer->paragraphs.end(); + + for (; it != end; ++it) { + if (it->bibitem()) { + int const wx = + font_metrics::width(it->bibitem()->getBibLabel(), + font); + if (wx > w) { + w = wx; + bitem = it->bibitem(); + } + } + } + + if (bitem && !bitem->getBibLabel().empty()) + return bitem->getBibLabel(); + + return "99"; +} + +} ParagraphList::iterator TeXEnvironment(Buffer const * buf, Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.365 diff -u -p -r1.365 text.C --- text.C 28 May 2003 16:36:53 -0000 1.365 +++ text.C 2 Jun 2003 17:20:59 -0000 @@ -57,8 +57,6 @@ extern int const CHANGEBAR_MARGIN = 10; /// left margin extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN; -extern int bibitemMaxWidth(BufferView *, LyXFont const &); - BufferView * LyXText::bv() { @@ -705,9 +703,6 @@ int LyXText::leftMargin(Row const & row) BufferParams::PARSEP_INDENT)) { x += font_metrics::signedWidth(parindent, tclass.defaultfont()); - } else if (layout->labeltype == LABEL_BIBLIO) { - // ale970405 Right width for bibitems - x += bibitemMaxWidth(bv(), tclass.defaultfont()); } } Index: text3.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v retrieving revision 1.79 diff -u -p -r1.79 text3.C --- text3.C 2 Jun 2003 14:19:29 -0000 1.79 +++ text3.C 2 Jun 2003 17:20:59 -0000 @@ -48,7 +48,6 @@ using std::vector; using lyx::pos_type; extern string current_layout; -extern int bibitemMaxWidth(BufferView *, LyXFont const &); // the selection possible is needed, that only motion events are // used, where the bottom press event was on the drawing area too Index: insets/insetbibitem.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbibitem.C,v retrieving revision 1.14 diff -u -p -r1.14 insetbibitem.C --- insets/insetbibitem.C 28 May 2003 06:47:15 -0000 1.14 +++ insets/insetbibitem.C 2 Jun 2003 17:21:00 -0000 @@ -7,6 +7,7 @@ * * Full author contact details are available in file CREDITS */ + #include <config.h> #include "insetbibitem.h" @@ -15,8 +16,6 @@ #include "funcrequest.h" #include "lyxlex.h" -#include "frontends/font_metrics.h" - #include "support/tostr.h" #include "support/lstrings.h" @@ -143,52 +142,3 @@ string const InsetBibitem::getScreenLabe return getContents() + " [" + getBibLabel() + ']'; } - -// ale070405 This function maybe shouldn't be here. We'll fix this at 0.13. -int bibitemMaxWidth(BufferView * bv, LyXFont const & font) -{ - int w = 0; - // Ha, now we are mainly at 1.2.0 and it is still here (Jug) - // Does look like a hack? It is! (but will change at 0.13) - ParagraphList::iterator it = bv->buffer()->paragraphs.begin(); - ParagraphList::iterator end = bv->buffer()->paragraphs.end(); - for (; it != end; ++it) { - if (it->bibitem()) { - int const wx = it->bibitem()->width(bv, font); - if (wx > w) - w = wx; - } - } - return w; -} - - -// ale070405 -string const bibitemWidest(Buffer const * buffer) -{ - int w = 0; - // Does look like a hack? It is! (but will change at 0.13) - - InsetBibitem const * bitem = 0; - LyXFont font; - - ParagraphList::const_iterator it = buffer->paragraphs.begin(); - ParagraphList::const_iterator end = buffer->paragraphs.end(); - - for (; it != end; ++it) { - if (it->bibitem()) { - int const wx = - font_metrics::width(it->bibitem()->getBibLabel(), - font); - if (wx > w) { - w = wx; - bitem = it->bibitem(); - } - } - } - - if (bitem && !bitem->getBibLabel().empty()) - return bitem->getBibLabel(); - - return "99"; -}