On Wed, 2006-05-03 at 22:05 +0200, Lars Gullik Bjønnes wrote: > Martin Vermeer <[EMAIL PROTECTED]> writes: > > | The attached was posted on bugzilla to fix the problem when people press > | Enter before or after an inset (inside float) in the hope of getting a > | caption in the right place. It is an incomplete fix but will work for > | the most common use cases, including the one Uwe described. > | > | BTW shouldn't we be moving to insetcaption? There these problems will > | probably be much easier to address, and the code base becomes cleaner. > > Sure. If you can resurrect it and make it work, I'll be happy.
Attached the first piece... get insetcaption working on-screen again. If no objection, this goes in presently. Should not have any functional effects at present, with insetcaption disabled... - Martin
Index: insetcaption.C
===================================================================
--- insetcaption.C (revision 13790)
+++ insetcaption.C (working copy)
@@ -16,6 +16,7 @@
#include "buffer.h"
#include "bufferparams.h"
+#include "cursor.h"
#include "BufferView.h"
#include "Floating.h"
#include "FloatList.h"
@@ -78,6 +79,32 @@ string const InsetCaption::editMessage()
}
+void InsetCaption::cursorPos
+ (CursorSlice const & sl, bool boundary, int & x, int & y) const
+{
+ InsetText::cursorPos(sl, boundary, x, y);
+ x += labelwidth_;
+}
+
+
+void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+ mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
+ labelwidth_ = font_metrics::width(label, mi.base.font);
+ dim.wid = labelwidth_;
+ Dimension textdim;
+ InsetText::metrics(mi, textdim);
+ dim.des = std::max(dim.des - textdim.asc + dim.asc, textdim.des);
+ dim.asc = textdim.asc;
+ dim.wid += textdim.wid;
+ dim.asc += TEXT_TO_INSET_OFFSET;
+ dim.des += TEXT_TO_INSET_OFFSET;
+ dim.wid += 2 * TEXT_TO_INSET_OFFSET;
+ mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
+ dim_ = dim;
+}
+
+
void InsetCaption::draw(PainterInfo & pi, int x, int y) const
{
// We must draw the label, we should get the label string
@@ -114,10 +141,25 @@ void InsetCaption::draw(PainterInfo & pi
string const num = "#";
// Generate the label
- string const label = bformat("%1$s %2$s:", _(fl), num);
- int const w = font_metrics::width(label, pi.base.font);
+ label = bformat("%1$s %2$s:", _(fl), num);
+ labelwidth_ = font_metrics::width(label, pi.base.font);
pi.pain.text(x, y, label, pi.base.font);
- InsetText::draw(pi, x + w, y);
+ InsetText::draw(pi, x + labelwidth_, y);
+ setPosCache(pi, x, y);
+}
+
+
+void InsetCaption::edit(LCursor & cur, bool left)
+{
+ cur.push(*this);
+ InsetText::edit(cur, left);
+}
+
+
+InsetBase * InsetCaption::editXY(LCursor & cur, int x, int y)
+{
+ cur.push(*this);
+ return InsetText::editXY(cur, x, y);
}
Index: insetcaption.h
===================================================================
--- insetcaption.h (revision 13790)
+++ insetcaption.h (working copy)
@@ -28,12 +28,23 @@ public:
///
virtual bool display() const;
///
+ virtual bool neverIndent() const { return true; }
+ ///
virtual InsetBase::Code lyxCode() const;
///
virtual std::string const editMessage() const;
///
+ virtual void cursorPos
+ (CursorSlice const & sl, bool boundary, int & x, int & y) const;
+ ///
+ virtual void metrics(MetricsInfo & mi, Dimension & dim) const;
+ ///
virtual void draw(PainterInfo & pi, int x, int y) const;
///
+ virtual void edit(LCursor & cur, bool left);
+ ///
+ virtual InsetBase * editXY(LCursor & cur, int x, int y);
+ ///
virtual int latex(Buffer const & buf, std::ostream & os,
OutputParams const &) const;
///
@@ -45,6 +56,10 @@ public:
private:
///
virtual std::auto_ptr<InsetBase> doClone() const;
+ ///
+ mutable std::string label;
+ ///
+ mutable int labelwidth_;
};
signature.asc
Description: This is a digitally signed message part
