*
* LyX, The Document Processor
*
- * Copyright (C) 1998 The LyX Team.
+ * Copyright 1998 The LyX Team.
*
*======================================================*/
#include "insetert.h"
#include "gettext.h"
#include "lyxfont.h"
-#include "Painter.h"
+#include "buffer.h"
+#include "insets/insettext.h"
+#include "support/LOstream.h"
#include "lyx_gui_misc.h"
+using std::ostream;
-InsetERT::InsetERT(Buffer * bf): InsetText(bf)
+InsetERT::InsetERT() : InsetCollapsable()
{
- closed = true;
- nomotion = false;
-}
-
-
-InsetERT * InsetERT::Clone() const
-{
- InsetERT * result = new InsetERT(buffer);
- return result;
-}
-
-
-void InsetERT::Write(ostream & os) const
-{
- os << "ERT\n";
- 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);
+ setLabel(_("ERT"));
+ LyXFont font(LyXFont::ALL_SANE);
+ font.setLatex (LyXFont::ON);
+ labelfont = LyXFont(LyXFont::ALL_SANE);
+ labelfont.decSize();
+ labelfont.decSize();
+ labelfont.setColor(LColor::ert);
+ setAutoCollapse(false);
+ setInsetName("ERT");
}
-void InsetERT::draw_closed(Painter & pain, LyXFont const & f,
- int baseline, float & x) const
+void InsetERT::Write(Buffer const * buf, ostream & os) 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);
+ os << getInsetName() << "\n";
+ InsetCollapsable::Write(buf, os);
}
-void InsetERT::draw(Painter & pain, LyXFont const & f, int baseline, float & x) const
+Inset * InsetERT::Clone(Buffer const &) 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);
-}
+ InsetERT * result = new InsetERT;
+ result->inset->init(inset);
-
-void InsetERT::InsetButtonRelease(BufferView * bv, int x, int y, int button)
-{
- nomotion = false;
- InsetText::InsetButtonRelease(bv, x, y, button);
+ result->collapsed = collapsed;
+ return result;
}
-void InsetERT::InsetButtonPress(BufferView * bv, int x, int y, int button)
+string const InsetERT::EditMessage() const
{
- nomotion = false;
- InsetText::InsetButtonPress(bv, x, y, button);
+ return _("Opened ERT Inset");
}
-void InsetERT::InsetMotionNotify(BufferView * bv, int x, int y, int button)
+void InsetERT::SetFont(BufferView *, LyXFont const &, bool)
{
- if (nomotion)
- return;
- InsetText::InsetMotionNotify(bv, x, y, button);
+ WriteAlert(_("Impossible Operation!"),
+ _("Not permitted to change font-types inside ERT-insets!"),
+ _("Sorry."));
}
void InsetERT::Edit(BufferView * bv, int x, int y, unsigned int button)
{
- closed = false;
- nomotion = true;
+ InsetCollapsable::Edit(bv, x, y, button);
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 *)
-{
- return false;
-}
-
-
-void InsetERT::SetFont(LyXFont const &, bool)
-{
- WriteAlert(_("Impossible Operation!"),
- _("Not permitted to change font-types inside ERT-insets!"),
- _("Sorry."));
}