+2000-03-08 Juergen Vigna <jug@sad.it>
+
+ * src/insets/lyxinset.h: added owner call which tells us if
+ this inset is inside another inset. Changed also the return-type
+ of Editable to an enum so it tells clearer what the return-value is.
+
+ * src/insets/insettext.C (computeTextRows): fixed computing of
+ textinsets which split automatically on more rows.
+
+ * src/insets/insetert.[Ch]: changed this to be of BaseType
+ InsetCollapsable.
+
+ * src/insets/insetfoot.[Ch]: added footnote inset
+
+ * src/insets/insetcollapsable.[Ch]: added this BaseClass for
+ collapsable insets (like footnote, ert, ...)
+
2000-03-08 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/lyxdraw.h: remvoe file
src/insets/inseterror.C
src/insets/inseterror.h
src/insets/insetert.C
+src/insets/insetert.h
+src/insets/insetfoot.C
src/insets/insetinclude.C
src/insets/insetindex.C
src/insets/insetinfo.C
updateScrollbar();
// Single left click in math inset?
- if (inset_hit != 0 && inset_hit->Editable() == 2) {
+ if (inset_hit != 0 && inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
// Highly editable inset, like math
selection_possible = false;
owner_->updateLayoutChoice();
N_("Toggle font underline"), Noop },
{ LFUN_FOOTMELT, "footnote-insert", N_("Insert Footnote"),
Noop },
+ { LFUN_INSET_FOOTNOTE, "footnote-inset-insert",
+ N_("Insert Footnote"), Noop },
{ LFUN_RIGHTSEL, "forward-select", N_("Select next char"),
ReadOnly },
{ LFUN_HFILL, "hfill-insert",
#include "insets/insettext.h"
#include "insets/insetert.h"
#include "insets/insetgraphics.h"
+#include "insets/insetfoot.h"
#include "support/filetools.h"
#include "support/path.h"
#include "LaTeX.h"
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
+ } else if (tmptok == "Foot") {
+ inset = new InsetFoot(this);
+ inset->Read(lex);
+ par->InsertChar(pos, LyXParagraph::META_INSET);
+ par->InsertInset(pos, inset);
+ par->SetFont(pos, font);
+ ++pos;
} else if (tmptok == "GRAPHICS") {
inset = new InsetGraphics;
//inset->Read(lex);
LFUN_INSET_TEXT, // Jug 20000214
LFUN_INSET_ERT, // Jug 20000218
LFUN_INSERT_GRAPHICS, // Lgb 20000226
+ LFUN_INSET_FOOTNOTE, // Jug 20000307
LFUN_LASTACTION /* this marks the end of the table */
};
inset.C \
insetbib.C \
insetbib.h \
+ insetcollapsable.C \
+ insetcollapsable.h \
insetcommand.C \
insetcommand.h \
inseterror.C \
inseterror.h \
insetert.C \
insetert.h \
+ insetfoot.C \
+ insetfoot.h \
insetgraphics.C \
insetgraphics.h \
insetinclude.C \
}
-unsigned char InsetFig::Editable() const
+Inset::EDITABLE InsetFig::Editable() const
{
- return 1;
+ return IS_EDITABLE;
}
///
void Edit(BufferView *, int, int, unsigned int);
///
- unsigned char Editable() const;
+ EDITABLE Editable() const;
///
bool Deletable() const;
///
#include "debug.h"
#include "BufferView.h"
#include "support/lstrings.h"
+#include "Painter.h"
/* Insets default methods */
}
-unsigned char Inset::Editable() const
+Inset::EDITABLE Inset::Editable() const
{
- return 0;
+ return NOT_EDITABLE;
}
// An updatable inset is highly editable by definition
-unsigned char UpdatableInset::Editable() const
+Inset::EDITABLE UpdatableInset::Editable() const
{
- return 2; // and what does "2" siginify? (Lgb)
+ return HIGHLY_EDITABLE;
}
#endif
return UNDISPATCHED;
}
+
+int UpdatableInset::getMaxWidth(Painter & pain) const
+{
+ if (owner_)
+ return owner_->getMaxWidth(pain);
+ return pain.paperWidth();
+}
+
///
void Edit(BufferView *, int x, int y, unsigned int button);
///
- unsigned char Editable() const {
- return 1;
+ EDITABLE Editable() const {
+ return IS_EDITABLE;
}
///
struct Holder {
///
void Edit(BufferView *, int x, int y, unsigned int button);
///
- unsigned char Editable() const {
- return 1;
+ EDITABLE Editable() const {
+ return IS_EDITABLE;
}
/// A user can't neither insert nor delete this inset
bool Deletable() const {
///
string getKeys(char delim);
///
- unsigned char Editable() const {
- return 1;
+ EDITABLE Editable() const {
+ return IS_EDITABLE;
}
///
bool addDatabase(string const &);
--- /dev/null
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright (C) 1998 The LyX Team.
+ *
+ *======================================================*/
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "insetcollapsable.h"
+#include "gettext.h"
+#include "lyxfont.h"
+#include "BufferView.h"
+#include "Painter.h"
+
+
+InsetCollapsable::InsetCollapsable(Buffer * bf): InsetText(bf)
+{
+ collapsed = true;
+ label = "Label";
+ autocolapse = true;
+ autoBreakRows = true;
+ framecolor = LColor::footnoteframe;
+ widthOffset = 7;
+}
+
+
+Inset * InsetCollapsable::Clone()
+{
+ Inset * result = new InsetCollapsable(buffer);
+ return result;
+}
+
+int InsetCollapsable::ascent_collapsed(Painter & pain, LyXFont const &) const
+{
+ int width = 0, ascent = 0, descent = 0;
+ pain.buttonText(0, 0, label.c_str(), labelfont, false,
+ width, ascent, descent);
+ return ascent;
+}
+
+
+int InsetCollapsable::descent_collapsed(Painter & pain, LyXFont const &) const
+{
+ int width = 0, ascent = 0, descent = 0;
+ pain.buttonText(0, 0, label.c_str(), labelfont, false,
+ width, ascent, descent);
+ return descent;
+}
+
+
+int InsetCollapsable::width_collapsed(Painter & pain, LyXFont const &) const
+{
+ int width, ascent, descent;
+ pain.buttonText(TEXT_TO_INSET_OFFSET, 0, label.c_str(), labelfont, false,
+ width, ascent, descent);
+ return width + (2*TEXT_TO_INSET_OFFSET);
+}
+
+
+int InsetCollapsable::ascent(Painter & pain, LyXFont const & font) const
+{
+ if (collapsed)
+ return ascent_collapsed(pain, font);
+ else
+ return InsetText::ascent(pain, font) + TEXT_TO_TOP_OFFSET;
+}
+
+
+int InsetCollapsable::descent(Painter & pain, LyXFont const & font) const
+{
+ if (collapsed)
+ return descent_collapsed(pain, font);
+ else
+ return InsetText::descent(pain, font) + TEXT_TO_BOTTOM_OFFSET;
+}
+
+
+int InsetCollapsable::width(Painter & pain, LyXFont const & font) const
+{
+ if (collapsed)
+ return width_collapsed(pain, font);
+
+ return getMaxWidth(pain);
+}
+
+
+void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const &,
+ int baseline, float & x) const
+{
+ int width = 0;
+ pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, baseline,
+ label.c_str(), labelfont, true, width);
+ x += width + (2 * TEXT_TO_INSET_OFFSET);
+}
+
+
+void InsetCollapsable::draw(Painter & pain, LyXFont const & f,
+ int baseline, float & x) const
+{
+ if (collapsed) {
+ draw_collapsed(pain, f, baseline, x);
+ return;
+ }
+ top_x = int(x);
+ top_baseline = baseline;
+ draw_collapsed(pain, f, baseline, x);
+ button_x = int(x - top_x);
+
+ maxWidth = getMaxWidth(pain) - button_x;
+ x += 2;
+ int
+ w = maxWidth - widthOffset,
+ h = ascent(pain,f) + descent(pain,f);
+
+ pain.rectangle(int(x), baseline - ascent(pain, f), w, h, framecolor);
+
+ x += 4;
+ top_x = int(x - top_x);
+ InsetText::draw(pain, f, baseline, x);
+}
+
+
+void InsetCollapsable::Edit(BufferView *bv, int x, int y, unsigned int button)
+{
+ if (collapsed) {
+ collapsed = false;
+ UpdateLocal(bv, true);
+ InsetText::Edit(bv, 0, 0, button);
+ } else if (button && (x < button_x) &&
+ (y < (labelfont.maxDescent()+labelfont.maxAscent()))) {
+ collapsed = true;
+ UpdateLocal(bv, false);
+ bv->unlockInset(this);
+ } else {
+ InsetText::Edit(bv, x-top_x, y, button);
+ }
+}
+
+
+Inset::EDITABLE InsetCollapsable::Editable() const
+{
+ if (collapsed)
+ return IS_EDITABLE;
+ return HIGHLY_EDITABLE;
+}
+
+void InsetCollapsable::InsetUnlock(BufferView *bv)
+{
+ if (autocolapse) {
+ collapsed = true;
+ }
+ InsetText::InsetUnlock(bv);
+ UpdateLocal(bv, true);
+}
+
+
+void InsetCollapsable::UpdateLocal(BufferView *bv, bool flag)
+{
+ maxWidth = getMaxWidth(bv->getPainter()) -
+ width_collapsed(bv->getPainter(), labelfont);
+ InsetText::UpdateLocal(bv, flag);
+}
+
+
+void InsetCollapsable::InsetButtonPress(BufferView *bv,int x,int y,int button)
+{
+ if ((x < button_x) &&
+ (y < (labelfont.maxDescent()+labelfont.maxAscent()))) {
+ collapsed = true;
+ UpdateLocal(bv, false);
+ bv->unlockInset(this);
+ } else if (x >= button_x) {
+ InsetText::InsetButtonPress(bv, x-top_x, y, button);
+ }
+}
+
+
+void InsetCollapsable::InsetButtonRelease(BufferView *bv, int x, int y, int button)
+{
+ if (x >= button_x)
+ InsetText::InsetButtonRelease(bv, x-top_x, y, button);
+}
+
+
+void InsetCollapsable::InsetMotionNotify(BufferView *bv, int x, int y, int button)
+{
+ if (x >= button_x)
+ InsetText::InsetMotionNotify(bv, x-top_x, y, button);
+}
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright (C) 2000 The LyX Team.
+ *
+ *======================================================
+ */
+
+
+#ifndef INSETCOLLAPSABLE_H
+#define INSETCOLLAPSABLE_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "insettext.h"
+#include "lyxfont.h"
+#include "LColor.h"
+
+
+class Painter;
+
+/** A colapsable text inset
+
+*/
+class InsetCollapsable : public InsetText {
+public:
+ ///
+ static int const TEXT_TO_TOP_OFFSET = 2;
+ ///
+ static int const TEXT_TO_BOTTOM_OFFSET = 2;
+ ///
+ InsetCollapsable(Buffer *);
+ ///
+ ~InsetCollapsable() {}
+ ///
+ Inset * InsetCollapsable::Clone();
+ ///
+ int ascent(Painter &, LyXFont const &) const;
+ ///
+ int descent(Painter &, LyXFont const &) const;
+ ///
+ int width(Painter &, LyXFont const & f) const;
+ ///
+ void draw(Painter & pain, const LyXFont &, int , float &) const;
+ ///
+ void Edit(BufferView *, int, int, unsigned int);
+ ///
+ EDITABLE Editable() const;
+ ///
+ void InsetUnlock(BufferView *);
+ ///
+ bool display() const { return (!collapsed); }
+ ///
+ void InsetButtonRelease(BufferView *, int, int, int);
+ ///
+ void InsetButtonPress(BufferView *, int, int, int);
+ ///
+ void InsetMotionNotify(BufferView *, int, int, int);
+ ///
+ void setLabel(string const & l) { label = l; }
+ ///
+ void setLabelFont(LyXFont & f) { labelfont = f; }
+ ///
+ void setAutoCollapse(bool f) { autocolapse = f; }
+
+protected:
+ ///
+ int ascent_collapsed(Painter &, LyXFont const &) const;
+ ///
+ int descent_collapsed(Painter &, LyXFont const &) const;
+ ///
+ int width_collapsed(Painter &, LyXFont const & f) const;
+ ///
+ void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
+ ///
+ void UpdateLocal(BufferView *, bool);
+
+ ///
+ bool collapsed;
+ ///
+ LColor::color framecolor;
+
+private:
+ ///
+ string label;
+ ///
+ LyXFont labelfont;
+ ///
+ bool autocolapse;
+ ///
+ mutable int
+ top_baseline, top_x,
+ button_x;
+};
+
+#endif
}
-unsigned char InsetError::Editable() const
+Inset::EDITABLE InsetError::Editable() const
{
- return 1;
+ return IS_EDITABLE;
}
///
void Edit(BufferView *, int x, int y, unsigned int button);
///
- unsigned char Editable() const;
+ EDITABLE Editable() const;
///
Inset * Clone() const;
///
#include "gettext.h"
#include "lyxfont.h"
#include "Painter.h"
-#include "lyx_gui_misc.h"
+#include "buffer.h"
+//#include "lyx_gui_misc.h"
InsetERT::InsetERT(Buffer * bf)
- : InsetText(bf)
+ : InsetCollapsable(bf)
{
- closed = true;
- nomotion = false;
- autoBreakRows = true;
+ setLabel(_("ERT"));
+ LyXFont font(LyXFont::ALL_SANE);
+ font.setLatex (LyXFont::ON);
+ real_current_font = current_font = font;
+ LyXFont labelfont(LyXFont::ALL_SANE);
+ labelfont.decSize();
+ labelfont.decSize();
+ labelfont.setColor(LColor::ert);
+ setLabelFont(labelfont);
+ setAutoCollapse(false);
}
WriteParagraphData(os);
}
-
-int InsetERT::ascent_closed(Painter & pain, LyXFont const & f) const
-{
- int width, ascent, descent;
- LyXFont font(LyXFont::ALL_SANE);
- font.setSize(f.size());
- font.decSize();
- font.decSize();
- pain.buttonText(0, 0, _("ERT"), font, false, width, ascent, descent);
- return ascent;
-}
-
-
-int InsetERT::descent_closed(Painter & pain, LyXFont const & f) const
-{
- int width, ascent, descent;
- LyXFont font(LyXFont::ALL_SANE);
- font.setSize(f.size());
- font.decSize();
- font.decSize();
- pain.buttonText(0, 0, _("ERT"), font, false, width, ascent, descent);
- return descent;
-}
-
-
-int InsetERT::width_closed(Painter & pain, LyXFont const & f) const
-{
- int width, ascent, descent;
- LyXFont font(LyXFont::ALL_SANE);
- font.setSize(f.size());
- font.decSize();
- font.decSize();
- pain.buttonText(TEXT_TO_INSET_OFFSET, 0, _("ERT"), font, false,
- width, ascent, descent);
- return width + (2*TEXT_TO_INSET_OFFSET);
-}
-
-
-int InsetERT::ascent(Painter & pain, LyXFont const & font) const
-{
- if (closed)
- return ascent_closed(pain, font);
- else
- return InsetText::ascent(pain, font);
-}
-
-
-int InsetERT::descent(Painter & pain, LyXFont const & font) const
-{
-
- if (closed)
- return descent_closed(pain, font);
- else
- return InsetText::descent(pain, font);
-}
-
-
-int InsetERT::width(Painter & pain, LyXFont const & font) const
-{
- if (closed)
- return width_closed(pain, font);
- else
- return InsetText::width(pain, font);
-}
-
-
-void InsetERT::draw_closed(Painter & pain, LyXFont const & f,
- int baseline, float & x) const
-{
- LyXFont font(LyXFont::ALL_SANE);
- font.setSize(f.size());
- font.decSize();
- font.decSize();
- font.setColor(LColor::ert);
- int width;
- pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, baseline,
- _("ERT"), font, true, width);
- x += width + (2 * TEXT_TO_INSET_OFFSET);
-}
-
-
-void InsetERT::draw(Painter & pain, LyXFont const & f,
- int baseline, float & x) const
-{
- if (closed) {
- top_x = int(x);
- top_baseline = baseline;
- draw_closed(pain, f, baseline, x);
- } else {
- InsetText::draw(pain, f, baseline, x);
- }
-// resetPos(bv);
-}
-
-
-void InsetERT::InsetButtonRelease(BufferView * bv, int x, int y, int button)
-{
- nomotion = false;
- InsetText::InsetButtonRelease(bv, x, y, button);
-}
-
-
-void InsetERT::InsetButtonPress(BufferView * bv, int x, int y, int button)
-{
- nomotion = false;
- InsetText::InsetButtonPress(bv, x, y, button);
-}
-
-
-void InsetERT::InsetMotionNotify(BufferView * bv, int x, int y, int button)
-{
- if (nomotion)
- return;
- InsetText::InsetMotionNotify(bv, x, y, button);
-}
-
-
-void InsetERT::Edit(BufferView * bv, int x, int y, unsigned int button)
-{
- closed = false;
- nomotion = true;
- LyXFont font(LyXFont::ALL_SANE);
- font.setLatex (LyXFont::ON);
- InsetText::Edit(bv, (x > (width_closed(bv->getPainter(),font)-5) ?
- width(bv->getPainter(), font) : 0), y, button);
- real_current_font = current_font = font;
- bv->updateInset(this, false);
-}
-
-
-void InsetERT::InsetUnlock(BufferView * bv)
-{
- closed = true;
- InsetText::InsetUnlock(bv);
- bv->updateInset(this, false);
-}
-
-
-bool InsetERT::InsertInset(Inset *)
+bool InsetERT::InsertInset(BufferView *, Inset *)
{
return false;
}
-void InsetERT::SetFont(LyXFont const &, bool)
+void InsetERT::SetFont(BufferView *, LyXFont const &, bool)
{
WriteAlert(_("Impossible Operation!"),
_("Not permitted to change font-types inside ERT-insets!"),
#pragma interface
#endif
-#include "insettext.h"
+#include "insetcollapsable.h"
class Painter;
To write full ert (including styles and other insets) in a given
space.
*/
-class InsetERT : public InsetText {
+class InsetERT : public InsetCollapsable {
public:
///
InsetERT(Buffer *);
///
- // InsetERT(InsetERT const &, Buffer *);
- ///
~InsetERT() {}
///
Inset * Clone() const;
///
- // void Read(LyXLex &);
- ///
void Write(ostream &) const;
///
- int ascent(Painter &, LyXFont const &) const;
- ///
- int descent(Painter &, LyXFont const &) const;
- ///
- int width(Painter &, LyXFont const & f) const;
- ///
- void draw(Painter & pain, const LyXFont &, int , float &) const;
- ///
- //LString EditMessage() const;
- ///
- void InsetButtonRelease(BufferView *, int, int, int);
- ///
- void InsetButtonPress(BufferView *, int, int, int);
+ const char * EditMessage() const { return _("Opened ERT Inset");}
///
- void InsetMotionNotify(BufferView *, int, int, int);
+ bool InsertInset(BufferView *, Inset *);
///
- void Edit(BufferView *, int, int, unsigned int);
+ void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
///
- void InsetUnlock(BufferView *);
- ///
- bool InsertInset(Inset *);
- ///
- void SetFont(LyXFont const &, bool toggleall);
-
-protected:
- ///
- int ascent_closed(Painter &, LyXFont const &) const;
- ///
- int descent_closed(Painter &, LyXFont const &) const;
- ///
- int width_closed(Painter &, LyXFont const & f) const;
- ///
- void draw_closed(Painter & pain, LyXFont const &, int , float &) const;
-
-private:
- ///
- bool closed;
- ///
- bool nomotion;
};
#endif
--- /dev/null
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright (C) 1998 The LyX Team.
+ *
+ *======================================================*/
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "insetfoot.h"
+#include "gettext.h"
+#include "lyxfont.h"
+#include "BufferView.h"
+#include "lyxscreen.h"
+#include "Painter.h"
+
+
+InsetFoot::InsetFoot(Buffer * bf): InsetCollapsable(bf)
+{
+ setLabel(_("foot"));
+ LyXFont font(LyXFont::ALL_SANE);
+ font.decSize();
+ font.decSize();
+ font.setColor(LColor::footnote);
+ setLabelFont(font);
+ setAutoCollapse(false);
+}
+
+
+InsetFoot * InsetFoot::Clone() const
+{
+ InsetFoot * result = new InsetFoot(buffer);
+ return result;
+}
+
+
+const char * InsetFoot::EditMessage() const
+{
+ return _("Opened Footnote Inset");
+}
+
+#ifndef USE_OSTREAM_ONLY
+int InsetFoot::Latex(string & l, signed char fragile) const
+{
+ int i;
+
+ if (fragile)
+ l += "\\footnotetext{";
+ else
+ l += "\\footnote{";
+
+ i = InsetText::Latex(l, fragile);
+ l += "}";
+
+ return i;
+}
+#endif
+
+int InsetFoot::Latex(ostream & os, signed char fragile) const
+{
+ int i;
+
+ if (fragile)
+ os << "\\footnotetext{";
+ else
+ os << "\\footnote{";
+
+ i = InsetText::Latex(os, fragile);
+ os << "}";
+
+ return i;
+}
+
+void InsetFoot::Write(ostream & os) const
+{
+ os << "Foot\n";
+ os << "\ncollapsed ";
+ if (display())
+ os << "false";
+ else
+ os << "true";
+ os << "\n";
+ WriteParagraphData(os);
+}
+
+void InsetFoot::Read(LyXLex & lex)
+{
+ if (lex.IsOK()) {
+ string token, tmptok;
+
+ lex.next();
+ token = lex.GetString();
+ if (token == "collapsed") {
+ lex.next();
+ collapsed = lex.GetBool();
+ }
+ }
+ InsetText::Read(lex);
+}
+
+bool InsetFoot::InsertInset(BufferView *bv, Inset * inset)
+{
+ if ((inset->LyxCode() == Inset::FOOT_CODE) ||
+ (inset->LyxCode() == Inset::MARGIN_CODE)) {
+ return false;
+ }
+ return InsetText::InsertInset(bv, inset);
+}
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright (C) 1998 The LyX Team.
+ *
+ *======================================================
+ */
+// The pristine updatable inset: Text
+
+
+#ifndef INSETFOOT_H
+#define INSETFOOT_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "insetcollapsable.h"
+
+
+class Painter;
+
+/** The footnote inset
+
+*/
+class InsetFoot : public InsetCollapsable {
+public:
+ ///
+ InsetFoot(Buffer *);
+ ///
+ ~InsetFoot() {}
+ ///
+ InsetFoot * InsetFoot::Clone() const;
+ ///
+ Inset::Code LyxCode() const { return Inset::FOOT_CODE; }
+#ifndef USE_OSTREAM_ONLY
+ ///
+ int Latex(string &, signed char) const;
+#endif
+ ///
+ int Latex(ostream &, signed char) const;
+ ///
+ void Write(ostream &) const;
+ ///
+ void Read(LyXLex &);
+ ///
+ const char * EditMessage() const;
+ ///
+ bool InsertInset(BufferView *, Inset * inset);
+};
+
+#endif
}
-unsigned char InsetGraphics::Editable() const
+Inset::EDITABLE InsetGraphics::Editable() const
{
- return 1;
+ return IS_EDITABLE;
}
///
void Edit(BufferView *, int, int, unsigned int);
///
- unsigned char Editable() const;
+ EDITABLE Editable() const;
///
void Write(ostream &) const;
///
///
void Edit(BufferView *, int x, int y, unsigned int button);
///
- unsigned char Editable() const
+ EDITABLE Editable() const
{
- return 1;
+ return IS_EDITABLE;
}
/// With lyx3 we won't overload these 3 methods
void Write(ostream &) const;
///
void Edit(BufferView *, int, int, unsigned int);
///
- unsigned char Editable() const
+ EDITABLE Editable() const
{
- return 1;
+ return IS_EDITABLE;
}
///
string getScreenLabel() const;
///
void Edit(BufferView *, int, int, unsigned int) {}
///
- unsigned char Editable() const{
- return 1;
+ EDITABLE Editable() const{
+ return IS_EDITABLE;
}
/// WHY is clone missing? (Lgb)
///
#endif
-unsigned char InsetInfo::Editable() const
+Inset::EDITABLE InsetInfo::Editable() const
{
- return 1;
+ return IS_EDITABLE;
}
///
void Edit(BufferView *, int, int, unsigned int);
///
- unsigned char Editable() const;
+ EDITABLE Editable() const;
///
Inset::Code LyxCode() const;
///
///
string getScreenLabel() const { return getContents(); }
///
- unsigned char Editable() const { return 0; }
+ EDITABLE Editable() const { return NOT_EDITABLE; }
///
int Latex(ostream &, signed char fragile) const;
#ifndef USE_OSTREAM_ONLY
string getScreenLabel() const { return _("List of Algorithms"); }
///
- unsigned char Editable() const {
- return 0; // not yet
+ EDITABLE Editable() const {
+ return NOT_EDITABLE; // not yet
}
///
bool display() const { return true; }
string getScreenLabel() const { return _("List of Figures"); }
///
- unsigned char Editable() const {
- return 0; // not yet
+ EDITABLE Editable() const {
+ return NOT_EDITABLE; // not yet
}
///
bool display() const { return true; }
string getScreenLabel() const { return _("List of Tables"); }
///
- unsigned char Editable() const {
- return 0; // not yet
+ EDITABLE Editable() const {
+ return NOT_EDITABLE; // not yet
}
///
bool display() const { return true; }
///
void Edit(BufferView *, int, int, unsigned int);
///
- unsigned char Editable() const {
- return 1;
+ EDITABLE Editable() const {
+ return IS_EDITABLE;
}
///
Inset::Code LyxCode() const { return Inset::PARENT_CODE; }
///
void Edit(BufferView *, int, int, unsigned int);
///
- unsigned char Editable() const {
- return 1;
+ EDITABLE Editable() const {
+ return IS_EDITABLE;
}
///
bool display() const { return false; }
interline_space = 1;
no_selection = false;
init_inset = true;
- maxAscent = maxDescent = insetWidth = 0;
+ maxAscent = maxDescent = insetWidth = widthOffset = 0;
autoBreakRows = false;
+ xpos = 0.0;
}
interline_space = 1;
no_selection = false;
init_inset = true;
- maxAscent = maxDescent = insetWidth = 0;
+ maxAscent = maxDescent = insetWidth = widthOffset = 0;
autoBreakRows = false;
+ xpos = 0.0;
}
int InsetText::ascent(Painter & pain, LyXFont const & font) const
{
if (init_inset) {
- computeTextRows(pain);
+ computeTextRows(pain, xpos);
init_inset = false;
}
if (maxAscent)
int InsetText::descent(Painter & pain, LyXFont const & font) const
{
if (init_inset) {
- computeTextRows(pain);
+ computeTextRows(pain, xpos);
init_inset = false;
}
if (maxDescent)
int InsetText::width(Painter & pain, LyXFont const &) const
{
if (init_inset) {
- computeTextRows(pain);
+ computeTextRows(pain, xpos);
init_inset = false;
}
return insetWidth;
}
-int InsetText::getMaxWidth(UpdatableInset * inset) const
-{
- if (!the_locking_inset) {
- lyxerr << "Text: No locking inset in this inset.\n";
- return 0;
- }
-
- if (the_locking_inset == inset)
- return maxWidth;
-
- return the_locking_inset->getMaxWidth(inset);
-}
-
-
void InsetText::draw(Painter & pain, LyXFont const & f,
int baseline, float & x) const
{
-// if (init_inset) {
- computeTextRows(pain, x);
-// init_inset = false;
-// }
+ xpos = x;
+ computeTextRows(pain, x);
UpdatableInset::draw(pain, f, baseline, x);
bool do_reset_pos = (x != top_x) || (baseline != top_baseline);
HideInsetCursor(bv);
if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
}
the_locking_inset = 0;
no_selection = false;
return the_locking_inset->UpdateInsetInInset(bv, inset);
float x = inset_x;
inset->draw(bv->getPainter(), real_current_font, inset_y, x);
- bv->updateInset(this, true);
+ UpdateLocal(bv, true);
return true;
}
{
if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
}
no_selection = false;
if (the_locking_inset) {
setPos(bv, x, y, false);
selection_end = actpos;
if (old != selection_end)
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
}
no_selection = false;
}
result = the_locking_inset->LocalDispatch(bv, action, arg);
if (result == DISPATCHED) {
the_locking_inset->ToggleInsetCursor(bv);
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
the_locking_inset->ToggleInsetCursor(bv);
return result;
} else if (result == FINISHED) {
case -1:
par->InsertChar(actpos,arg[0]);
par->SetFont(actpos,real_current_font);
- computeTextRows(bv->getPainter());
- bv->updateInset(this, true);
+ UpdateLocal(bv, true);
++actpos;
selection_start = selection_end = actpos;
resetPos(bv);
case LFUN_RIGHTSEL:
moveRight(bv, false);
selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
break;
case LFUN_RIGHT:
result= DISPATCH_RESULT(moveRight(bv));
if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
} else {
selection_start = selection_end = actpos;
}
case LFUN_LEFTSEL:
moveLeft(bv, false);
selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
break;
case LFUN_LEFT:
result= DISPATCH_RESULT(moveLeft(bv));
if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
} else {
selection_start = selection_end = actpos;
}
case LFUN_DOWNSEL:
moveDown(bv, false);
selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
break;
case LFUN_DOWN:
result= DISPATCH_RESULT(moveDown(bv));
if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
} else {
selection_start = selection_end = actpos;
}
case LFUN_UPSEL:
moveUp(bv, false);
selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
break;
case LFUN_UP:
result= DISPATCH_RESULT(moveUp(bv));
if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
} else {
selection_start = selection_end = actpos;
}
if (!actpos || par->IsNewline(actpos-1)) {
if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
}
break;
}
case LFUN_DELETE:
if (Delete()) { // we need update
selection_start = selection_end = actpos;
- computeTextRows(bv->getPainter());
- bv->updateInset(this, true);
+ UpdateLocal(bv, true);
} else if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
}
break;
case LFUN_HOME:
cx -= SingleWidth(bv->getPainter(), par, actpos);
if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
} else {
selection_start = selection_end = actpos;
}
cx += SingleWidth(bv->getPainter(), par, actpos);
if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
} else {
selection_start = selection_end = actpos;
}
InsertInset(bv, new InsetFormula);
if (hasSelection()) {
selection_start = selection_end = actpos;
- bv->updateInset(this, false);
+ UpdateLocal(bv, false);
} else {
selection_start = selection_end = actpos;
}
bool InsetText::InsertInset(BufferView * bv, Inset * inset)
{
+ if (inset->Editable() == Inset::IS_EDITABLE) {
+ UpdatableInset *i = (UpdatableInset *)inset;
+ i->setOwner((UpdatableInset *)this);
+ }
par->InsertChar(actpos, LyXParagraph::META_INSET);
par->InsertInset(actpos, inset);
- computeTextRows(bv->getPainter());
- bv->updateInset(this, true);
+ UpdateLocal(bv, true);
the_locking_inset = static_cast<UpdatableInset*>(inset);
inset_x = cx - top_x;
inset_y = cy;
SetCharFont(s_start, newfont);
++s_start;
}
- computeTextRows(bv->getPainter());
- bv->updateInset(this, true);
+ UpdateLocal(bv, true);
}
}
-// Ok, Jürgen. Here is my small secret message to you. As you can see I
-// played a bit witht he Textinset. (But only through the InsetERT so far).
-// As you can see below I have changed the code to use max/min instead of
-// the if < construct, imo this makes it faster and easier to read. I have
-// also changed rows[rows.size() - 1] to rows.back() makes it clearer that
-// we speak about the last element in the vector. I added a second arg to
-// to this func as well. This makes it possible to take the position of the
-// inset into account when drawing the inset, this is especially needed when
-// the ERT inset is first in a paragraph. I am not sure, but this might have
-// made short ERT (less than one line, just a couple of words) draw
-// incorrectly. You should perhaps have a look yourselves at this.
-// Also (phu...) I use pain to get at paperWidth().
-// This is beginning to look like a very nice Inset (speaking of the ERT
-// inset that is), but in afterthought, do we really need it? Wouldn't a
-// non dynamic inset working in the same way as the floats be more usefull
-// and easier to work with? Jean-Marc has already aired this thought.
-// I tested also a bit on the raw insettext, it seems that it can't break
-// over several lines properly. Other than that it seems to create the basis
-// for insetfloat, insetmarginal and insetfoot just fine. How about a
-// updatable inset that does not open, unless you click on it? uff... I just
-// ramble on. Feel free to remove my comments after you have read them.
-// Lgb
void InsetText::computeTextRows(Painter & pain, float x) const
{
int p,
if (rows.size())
rows.clear();
- //rows.erase(rows.begin(),rows.end());
int width = wordAscent = wordDescent = 0;
insetWidth = maxAscent = maxDescent = 0;
row.asc = 0;
insetWidth += SingleWidth(pain, par, p);
SingleHeight(pain, par, p, asc, desc);
maxAscent = max(maxAscent, asc);
- //if (asc > maxAscent)
- //maxAscent = asc;
maxDescent = max(maxDescent, desc);
- //if (desc > maxDescent)
- //maxDescent = desc;
}
rows[0].asc = maxAscent;
rows[0].desc = maxDescent;
int cw, lastWordWidth = 0;
- //maxWidth = buffer->getUser()->paperWidth();
- maxWidth = pain.paperWidth();
+ maxWidth = UpdatableInset::getMaxWidth(pain) - widthOffset;
for(p = 0; p < par->Last(); ++p) {
cw = SingleWidth(pain, par, p);
width += cw;
lastWordWidth += cw;
SingleHeight(pain, par, p, asc, desc);
wordAscent = max(wordAscent, asc);
- //if (asc > wordAscent)
- // wordAscent = asc;
wordDescent = max(wordDescent, desc);
- //if (desc > wordDescent)
- // wordDescent = desc;
Inset const * inset = 0;
if (((p + 1) < par->Last()) &&
(par->GetChar(p + 1)==LyXParagraph::META_INSET))
inset = par->GetInset(p + 1);
if (inset && inset->display()) {
- if (!is_first_word_in_row && (width >= maxWidth - x)) {
+ if (!is_first_word_in_row && (width >= (maxWidth - x))) {
// we have to split also the row above
rows.back().asc = oasc;
rows.back().desc = odesc;
oasc = wordAscent;
odesc = wordDescent;
insetWidth = max(insetWidth, owidth);
- //if (insetWidth < owidth)
- // insetWidth = owidth;
width = lastWordWidth;
lastWordWidth = 0;
} else {
oasc = max(oasc, wordAscent);
- //if (oasc < wordAscent)
- //oasc = wordAscent;
odesc = max(odesc, wordDescent);
- //if (odesc < wordDescent)
- //odesc = wordDescent;
}
rows.back().asc = oasc;
rows.back().desc = odesc;
oasc = odesc = width = lastWordWidth = 0;
is_first_word_in_row = true;
wordAscent = wordDescent = 0;
- x = 0.0;
+// x = 0.0;
continue;
} else if (par->IsSeparator(p)) {
if (width >= maxWidth - x) {
oasc = wordAscent;
odesc = wordDescent;
insetWidth = max(insetWidth, owidth);
- //if (insetWidth < owidth)
- //insetWidth = owidth;
width = lastWordWidth;
}
wordAscent = wordDescent = lastWordWidth = 0;
nwp = p + 1;
- x = 0.0;
+// x = 0.0;
continue;
}
owidth = width;
oasc = max(oasc, wordAscent);
- //if (oasc < wordAscent)
- //oasc = wordAscent;
odesc = max(odesc, wordDescent);
- //if (odesc < wordDescent)
- //odesc = wordDescent;
wordAscent = wordDescent = lastWordWidth = 0;
nwp = p + 1;
is_first_word_in_row = false;
}
- x = 0.0;
}
// if we have some data in the paragraph we have ascent/descent
if (p) {
- if (width >= maxWidth) {
+ if (width >= (maxWidth - x)) {
// assign upper row
rows.back().asc = oasc;
rows.back().desc = odesc;
rows.push_back(row);
rows.back().asc = wordAscent;
rows.back().desc = wordDescent;
- insetWidth = max(insetWidth, owidth);
- //if (insetWidth < owidth)
- //insetWidth = owidth;
- width -= owidth;
- insetWidth = max(insetWidth, width);
- //if (insetWidth < width)
- //insetWidth = width;
+ width -= lastWordWidth;
} else {
// assign last row data
- oasc = max(oasc, wordAscent);
- //if (oasc < wordAscent)
- //oasc = wordAscent;
- odesc = min(odesc, wordDescent);
- //if (odesc < wordDescent)
- //odesc = wordDescent;
- rows.back().asc = oasc;
- rows.back().desc = odesc;
+// width = lastWordWidth;
+// lastWordWidth = 0;
+ rows.back().asc = max(oasc, wordAscent);
+ rows.back().desc = max(odesc, wordDescent);
}
}
+ insetWidth = max(insetWidth, width);
// alocate a dummy row for the endpos
row.pos = par->Last();
rows.push_back(row);
for (RowList::size_type i = 1; i < rows.size() - 1; ++i) {
maxDescent += rows[i].asc + rows[i].desc + interline_space;
}
- lyxerr << "Rows: " << rows.size() << endl;
#if 0
if (the_locking_inset) {
computeBaselines(top_baseline);
rows[i].asc + interline_space;
}
}
+
+void InsetText::UpdateLocal(BufferView *bv, bool flag)
+{
+ init_inset = flag;
+ bv->updateInset(this, flag);
+}
#include "lyxinset.h"
#include "lyxparagraph.h"
#include "LString.h"
-#include "buffer.h"
+//#include "buffer.h"
class Painter;
class BufferView;
+class Buffer;
/** A text inset is like a TeX box
///
int width(Painter &, LyXFont const & f) const;
///
- int getMaxWidth(UpdatableInset *) const;
- ///
void draw(Painter & pain, LyXFont const &, int , float &) const;
///
char const * EditMessage() const;
///
bool UnlockInsetInInset(BufferView *, Inset *, bool lr = false);
///
- //void UpdateLocal(bool flag=true);
- ///
bool UpdateInsetInInset(BufferView *, Inset *);
///
void InsetButtonRelease(BufferView *, int, int, int);
LyXParagraph * par;
protected:
+ ///
+ void UpdateLocal(BufferView *, bool);
///
void WriteParagraphData(ostream &) const;
///
int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
///
LyXFont GetFont(LyXParagraph * par, int pos) const;
- ///
+
Buffer * buffer;
///
LyXFont current_font;
///
mutable int insetWidth;
///
+ int widthOffset;
+ ///
bool autoBreakRows;
private:
///
bool no_selection;
///
+ mutable float xpos;
+ ///
mutable bool init_inset;
///
UpdatableInset * the_locking_inset;
/// On edit, we open the TOC pop-up
void Edit(BufferView * bv, int, int, unsigned int);
///
- unsigned char Editable() const {
- return 1;
+ EDITABLE Editable() const {
+ return IS_EDITABLE;
}
///
bool display() const { return true; }
///
void Edit(BufferView *, int, int, unsigned int);
///
- unsigned char Editable() const {
- return 1;
+ EDITABLE Editable() const {
+ return IS_EDITABLE;
}
///
const char * EditMessage() const {return _("Opened Url");}
///
TEXT_CODE,
///
- SPECIALCHAR_CODE
+ FOOT_CODE,
+ ///
+ MARGIN_CODE,
+ ///
+ SPECIALCHAR_CODE,
+ };
+
+ enum EDITABLE {
+ NOT_EDITABLE = 0,
+ IS_EDITABLE,
+ HIGHLY_EDITABLE
};
///
///
virtual void Edit(BufferView *, int x, int y, unsigned int button);
///
- virtual unsigned char Editable() const;
+ virtual EDITABLE Editable() const;
///
virtual bool AutoDelete() const;
///
}
///
- UpdatableInset() { scx = mx_scx = 0; }
+ UpdatableInset() {
+ scx = mx_scx = 0;
+ owner_ = 0;
+ }
///
//virtual ~UpdatableInset() {}
///
- virtual unsigned char Editable() const;
+ virtual EDITABLE Editable() const;
/// may call ToggleLockedInsetCursor
virtual void ToggleInsetCursor(BufferView *);
///
virtual bool isCursorVisible() const { return cursor_visible; }
///
- virtual int getMaxWidth(UpdatableInset *) const { return -1; }
+ virtual int getMaxWidth(Painter & pain) const;
+ ///
+ virtual void setOwner(UpdatableInset * inset) { owner_ = inset; }
+ ///
+ virtual UpdatableInset * owner() { return owner_; }
+
protected:
///
// virtual void UpdateLocal(bool flag=true);
///
int mx_scx;
mutable int scx;
+ ///
+ UpdatableInset * owner_;
+
};
#endif
#include "insets/insettext.h"
#include "insets/insetert.h"
#include "insets/insetgraphics.h"
+#include "insets/insetfoot.h"
#include "mathed/formulamacro.h"
#include "toolbar.h"
#include "spellchecker.h" // RVDK_PATCH_5
&& tmptext->cursor.par->GetChar(tmptext->cursor.pos)
== LyXParagraph::META_INSET
&& tmptext->cursor.par->GetInset(tmptext->cursor.pos)
- && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
+ && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE){
Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
setMessage(tmpinset->EditMessage());
tmpinset->Edit(owner->view(), 0, 0, 0);
&& txt->cursor.par->GetChar(txt->cursor.pos)
== LyXParagraph::META_INSET
&& txt->cursor.par->GetInset(txt->cursor.pos)
- && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
+ && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
setMessage(tmpinset->EditMessage());
tmpinset->Edit(owner->view(),
owner->view()->insertInset(new_inset);
new_inset->Edit(owner->view(), 0, 0, 0);
}
+ case LFUN_INSET_FOOTNOTE:
+ {
+ InsetFoot * new_inset = new InsetFoot(owner->buffer());
+ owner->view()->insertInset(new_inset);
+ new_inset->Edit(owner->view(), 0, 0, 0);
+ }
break;
// --- lyxserver commands ----------------------------
&& cursor.par->GetInset(cursor.pos)->Editable()) {
owner_->owner()->getMiniBuffer()
->Set(cursor.par->GetInset(cursor.pos)->EditMessage());
- if (cursor.par->GetInset(cursor.pos)->Editable() != 2)
+ if (cursor.par->GetInset(cursor.pos)->Editable() != Inset::HIGHLY_EDITABLE)
SetCursorParUndo();
cursor.par->GetInset(cursor.pos)->Edit(owner_, 0, 0, 0);
} else {