X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finset.C;h=6f7fc7d1c73236e198b85b15ba312e182b8a902c;hb=c5c7a9e56854dea886977f8e11cbfe31d8a7464f;hp=2bf343027453b510098879d6886e3b6c7a6bdf21;hpb=33868acd2c62d5d5393962bdc3bf1351cf8434c8;p=lyx.git diff --git a/src/insets/inset.C b/src/insets/inset.C index 2bf3430274..6f7fc7d1c7 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -1,186 +1,174 @@ -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX Team. +/** + * \file inset.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * ====================================================== */ + * \author Alejandro Aguilar Sierra + * \author Jürgen Vigna + * \author Lars Gullik Bjønnes + * \author Matthias Ettrich + * + * Full author contact details are available in file CREDITS. + */ #include -#ifdef __GNUG__ -#pragma implementation "lyxinset.h" -#endif +#include "inset.h" +#include "updatableinset.h" -#include "lyxinset.h" -#include "debug.h" #include "BufferView.h" -#include "support/lstrings.h" -#include "Painter.h" +#include "gettext.h" -using std::endl; -/* Insets default methods */ +// Initialization of the counter for the inset id's, +unsigned int InsetOld::inset_id = 0; -bool Inset::Deletable() const -{ - return true; -} +InsetOld::InsetOld() + : InsetBase(), + top_x(0), top_baseline(0), scx(0), + id_(inset_id++), owner_(0), + background_color_(LColor::inherit) +{} -bool Inset::DirectWrite() const -{ - return false; -} +InsetOld::InsetOld(InsetOld const & in) + : InsetBase(), + top_x(0), top_baseline(0), scx(0), + id_(in.id_), owner_(0), + name_(in.name_), background_color_(in.background_color_) +{} -Inset::EDITABLE Inset::Editable() const +bool InsetOld::directWrite() const { - return NOT_EDITABLE; + return false; } -bool Inset::IsTextInset() const -{ - return ((LyxCode() == TEXT_CODE) || - (LyxCode() == ERT_CODE) || - (LyxCode() == FOOT_CODE) || - (LyxCode() == MARGIN_CODE)); -} -void Inset::Validate(LaTeXFeatures &) const +InsetOld::EDITABLE InsetOld::editable() const { + return NOT_EDITABLE; } -bool Inset::AutoDelete() const +bool InsetOld::autoDelete() const { - return false; + return false; } -void Inset::Edit(BufferView *, int, int, unsigned int) +#if 0 +LyXFont const InsetOld::convertFont(LyXFont const & font) const { +#if 1 + return font; +#else + return LyXFont(font); +#endif } +#endif -LyXFont Inset::ConvertFont(LyXFont font) +string const InsetOld::editMessage() const { - return font; + return _("Opened inset"); } -char const * Inset::EditMessage() const +LyXText * InsetOld::getLyXText(BufferView const * bv, bool /*recursive*/) const { - return _("Opened inset"); + if (owner()) + return owner()->getLyXText(bv, false); + else + return bv->text; } - /* some stuff for inset locking */ -void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button) +void InsetOld::setBackgroundColor(LColor::color color) { - lyxerr.debug() << "Inset Button Press x=" << x - << ", y=" << y << ", button=" << button << endl; + background_color_ = color; } -void UpdatableInset::InsetButtonRelease(BufferView *, int x, int y, int button) +LColor::color InsetOld::backgroundColor() const { - lyxerr.debug() << "Inset Button Release x=" << x - << ", y=" << y << ", button=" << button << endl; + if (background_color_ == LColor::inherit) { + if (owner()) + return owner()->backgroundColor(); + else + return LColor::background; + } else + return background_color_; } -void UpdatableInset::InsetKeyPress(XKeyEvent *) +int InsetOld::id() const { - lyxerr.debug() << "Inset Keypress" << endl; + return id_; } - -void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state) +void InsetOld::id(int id_arg) { - lyxerr.debug() << "Inset Motion Notify x=" << x - << ", y=" << y << ", state=" << state << endl; + id_ = id_arg; } +void InsetOld::setFont(BufferView *, LyXFont const &, bool, bool) +{} + -void UpdatableInset::InsetUnlock(BufferView *) +bool InsetOld::forceDefaultParagraphs(InsetOld const * inset) const { - lyxerr.debug() << "Inset Unlock" << endl; + if (owner()) + return owner()->forceDefaultParagraphs(inset); + return false; } - -// An updatable inset is highly editable by definition -Inset::EDITABLE UpdatableInset::Editable() const +int InsetOld::latexTextWidth(BufferView * bv) const { - return HIGHLY_EDITABLE; + if (owner()) + return (owner()->latexTextWidth(bv)); + return bv->workWidth(); } -void UpdatableInset::ToggleInsetCursor(BufferView *) +int InsetOld::ascent() const { + return dim_.asc; } -void UpdatableInset::ShowInsetCursor(BufferView *) -{ -} -void UpdatableInset::HideInsetCursor(BufferView *) +int InsetOld::descent() const { + return dim_.des; } -void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int) +int InsetOld::width() const { - LyXFont font; - - scx = 0; - - mx_scx = abs((width(bv->painter(), font) - bv->paperWidth()) / 2); + return dim_.wid; } -void UpdatableInset::draw(Painter &, LyXFont const &, - int baseline, float & x) const +bool InsetOld::insetAllowed(InsetOld * in) const { - if (scx) x += float(scx); - top_x = int(x); - top_baseline = baseline; + return insetAllowed(in->lyxCode()); } -void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool ) +bool InsetOld::checkInsertChar(LyXFont &) { + return false; } -/// An updatable inset could handle lyx editing commands -#ifdef SCROLL_INSET -UpdatableInset::RESULT -UpdatableInset::LocalDispatch(BufferView *, - int action, string const & arg) -#else -UpdatableInset::RESULT -UpdatableInset::LocalDispatch(BufferView *, int, string const &) -#endif +bool isEditableInset(InsetOld const * i) { -#ifdef SCROLL_INSET - if (action==LFUN_SCROLL_INSET) - { - float xx; - sscanf(arg.c_str(), "%f", &xx); - scroll(xx); - - return DISPATCHED; - } -#endif - return UNDISPATCHED; + return i && i->editable(); } -int UpdatableInset::getMaxWidth(Painter & pain, UpdatableInset const *inset) const + +bool isHighlyEditableInset(InsetOld const * i) { - if (owner()) - return static_cast(owner())->getMaxWidth(pain, inset); - return pain.paperWidth(); + return i && i->editable() == InsetOld::HIGHLY_EDITABLE; } +