* inset.h:

* insetert.[Ch]:
	* insettabular.[Ch]:
	* insettext.[Ch]: remove unused insetInset()

	* insetert.C: disable some  LFUNs

	* insettoc.[Ch]: metrics() and draw() of InsetButton is enough.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8221 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-12-10 09:45:32 +00:00
parent aa2056f050
commit 153ac7500c
21 changed files with 116 additions and 148 deletions

View File

@ -750,13 +750,13 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
Buffer::inset_iterator beg = b->inset_iterator_begin();
Buffer::inset_iterator end = b->inset_iterator_end();
bool cursorPar_seen = false;
bool cursor_par_seen = false;
for (; beg != end; ++beg) {
if (beg.getPar() == text->cursorPar()) {
cursorPar_seen = true;
cursor_par_seen = true;
}
if (cursorPar_seen) {
if (cursor_par_seen) {
if (beg.getPar() == text->cursorPar()
&& beg.getPos() >= text->cursor.pos()) {
break;
@ -871,21 +871,25 @@ namespace {
InsetOld * insetFromCoords(BufferView * bv, int x, int y)
{
lyxerr << "insetFromCoords" << endl;
LyXText * text = bv->text();
InsetOld * inset = 0;
theTempCursor = LCursor(bv);
while (true) {
InsetOld * inset_hit = text->checkInsetHit(x, y);
InsetOld * const inset_hit = text->checkInsetHit(x, y);
if (!inset_hit) {
lyxerr << "no further inset hit" << endl;
break;
}
inset = inset_hit;
if (!inset_hit->descendable()) {
if (!inset->descendable()) {
lyxerr << "not descendable" << endl;
break;
}
text = inset_hit->getText(0);
int const cell = inset->getCell(x, y);
if (cell == -1)
break;
text = inset_hit->getText(cell);
lyxerr << "Hit inset: " << inset << " at x: " << x
<< " text: " << text << " y: " << y << endl;
theTempCursor.push(static_cast<UpdatableInset*>(inset));
@ -1255,16 +1259,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
{
#ifdef LOCK
// if we are in a locking inset we should try to insert the
// inset there otherwise this is a illegal function now
if (bv_->theLockingInset()) {
if (bv_->theLockingInset()->insetAllowed(inset))
return bv_->theLockingInset()->insertInset(bv_, inset);
return false;
}
#endif
// not quite sure if we want this...
bv_->text()->recUndo(bv_->text()->cursor.par());
freezeUndo();

View File

@ -248,7 +248,7 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
// this new max depth level so that subsequent
// paragraphs are aligned correctly to this paragraph
// at level 0.
if ((int(tmpbuf->params().depth()) + depth_delta) < 0)
if (int(tmpbuf->params().depth()) + depth_delta < 0)
depth_delta = 0;
// Set the right depth so that we are not too deep or shallow.
@ -265,17 +265,8 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
tmpbuf->setInsetOwner(pit->inInset());
for (pos_type i = 0; i < tmpbuf->size(); ++i) {
if (tmpbuf->getChar(i) == Paragraph::META_INSET) {
if (!pit->insetAllowed(tmpbuf->getInset(i)->lyxCode())) {
if (!pit->insetAllowed(tmpbuf->getInset(i)->lyxCode()))
tmpbuf->erase(i--);
}
} else {
LyXFont f1 = tmpbuf->getFont(buffer.params(), i, outerFont(pit, pars));
LyXFont f2 = f1;
if (!pit->checkInsertChar(f1)) {
tmpbuf->erase(i--);
} else if (f1 != f2) {
tmpbuf->setFont(i, f1);
}
}
}
}

View File

@ -309,4 +309,4 @@ void put_selection_at(BufferView * bv, PosIterator const & cur,
}
}; // namespace bv_funcs
} // namespace bv_funcs

View File

@ -35,6 +35,7 @@ using std::endl;
std::ostream & operator<<(std::ostream & os, CursorItem const & item)
{
os << " inset: " << item.inset_
<< " code: " << item.inset_->lyxCode()
<< " text: " << item.text()
// << " par: " << item.par_
// << " pos: " << item.pos_

View File

@ -1,3 +1,15 @@
2003-12-10 André Pönitz <poenitz@gmx.net>
* inset.h:
* insetert.[Ch]:
* insettabular.[Ch]:
* insettext.[Ch]: remove unused insetInset()
* insetert.C: disable some LFUNs
* insettoc.[Ch]: metrics() and draw() of InsetButton is enough.
2003-12-04 Martin Vermeer <martin.vermee@hut.fi>
* insetcharstyle.[Ch]: Conglomerate-style CharStyles

View File

@ -17,7 +17,9 @@
#include "updatableinset.h"
#include "BufferView.h"
#include "debug.h"
#include "gettext.h"
#include "lyxtext.h"
#include "LColor.h"
@ -114,6 +116,30 @@ int InsetOld::scroll(bool recursive) const
return 0;
}
int InsetOld::getCell(int x, int y) const
{
for (int i = 0, n = numParagraphs(); i < n; ++i) {
LyXText * text = getText(i);
//lyxerr << "### text: " << text << " i: " << i
// << " xo: " << text->xo_ << "..." << text->xo_ + text->width
// << " yo: " << text->yo_
// << " yo: " << text->yo_ - text->ascent() << "..."
// << text->yo_ + text->descent()
// << std::endl;
if (x >= text->xo_
&& x <= text->xo_ + text->width
&& y >= text->yo_
&& y <= text->yo_ + text->height)
{
lyxerr << "### found text # " << i << std::endl;
return i;
}
}
return -1;
}
bool isEditableInset(InsetOld const * i)
{
return i && i->editable();
@ -124,3 +150,5 @@ bool isHighlyEditableInset(InsetOld const * i)
{
return i && i->editable() == InsetOld::HIGHLY_EDITABLE;
}

View File

@ -226,6 +226,8 @@ public:
virtual LyXText * getText(int /*num*/) const { return 0; }
///
virtual int numParagraphs() const { return 0; }
/// returns cell covering position (x,y), -1 if none exists
virtual int getCell(int x, int y) const;
/// used to toggle insets
// is the inset open?

View File

@ -65,17 +65,6 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & in)
}
bool InsetCollapsable::insertInset(BufferView * bv, InsetOld * in)
{
if (!insetAllowed(in->lyxCode())) {
lyxerr << "InsetCollapsable::InsertInset: "
"Unable to insert inset." << endl;
return false;
}
return inset.insertInset(bv, in);
}
void InsetCollapsable::write(Buffer const & buf, ostream & os) const
{
os << "collapsed " << (status_ == Collapsed ? "true" : "false") << "\n";

View File

@ -61,8 +61,6 @@ public:
/// can we go further down on mouse click?
bool descendable() const;
///
bool insertInset(BufferView *, InsetOld * inset);
///
bool insetAllowed(InsetOld::Code code) const;
///
bool isTextInset() const { return true; }

View File

@ -85,11 +85,6 @@ InsetERT::InsetERT(BufferParams const & bp,
status_ = collapsed ? Collapsed : Open;
LyXFont font(LyXFont::ALL_INHERIT, l);
#ifdef SET_HARD_FONT
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
font.setColor(LColor::latex);
#endif
string::const_iterator cit = contents.begin();
string::const_iterator end = contents.end();
pos_type pos = 0;
@ -137,21 +132,6 @@ void InsetERT::read(Buffer const & buf, LyXLex & lex)
}
inset.read(buf, lex);
#ifdef SET_HARD_FONT
LyXFont font(LyXFont::ALL_INHERIT, latex_language);
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
font.setColor(LColor::latex);
ParagraphList::iterator pit = inset.paragraphs().begin();
ParagraphList::iterator pend = inset.paragraphs().end();
for (; pit != pend; ++pit) {
pos_type siz = pit->size();
for (pos_type i = 0; i < siz; ++i) {
pit->setFont(i, font);
}
}
#endif
if (!token_found) {
if (isOpen())
status_ = Open;
@ -218,12 +198,6 @@ string const InsetERT::editMessage() const
}
bool InsetERT::insertInset(BufferView *, InsetOld *)
{
return false;
}
void InsetERT::updateStatus(bool swap) const
{
if (status_ != Inlined) {
@ -396,17 +370,8 @@ void InsetERT::edit(BufferView * bv, bool left)
DispatchResult
InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
{
BufferView * bv = cmd.view();
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetERTMailer::string2params(cmd.argument, status_);
setButtonLabel();
bv->update();
return DispatchResult(true, true);
}
case LFUN_MOUSE_PRESS:
lfunMousePress(cmd);
return DispatchResult(true, true);
@ -419,8 +384,26 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
lfunMouseRelease(cmd);
return DispatchResult(true, true);
case LFUN_INSET_MODIFY:
InsetERTMailer::string2params(cmd.argument, status_);
setButtonLabel();
return DispatchResult(true, true);
case LFUN_LAYOUT:
bv->owner()->setLayout(inset.paragraphs().begin()->layout()->name());
case LFUN_BOLD:
case LFUN_CODE:
case LFUN_DEFAULT:
case LFUN_EMPH:
case LFUN_FREEFONT_APPLY:
case LFUN_FREEFONT_UPDATE:
case LFUN_NOUN:
case LFUN_ROMAN:
case LFUN_SANS:
case LFUN_FRAK:
case LFUN_ITAL:
case LFUN_FONT_SIZE:
case LFUN_FONT_STATE:
case LFUN_UNDERLINE:
return DispatchResult(true);
default:

View File

@ -49,8 +49,6 @@ public:
///
std::string const editMessage() const;
///
bool insertInset(BufferView *, InsetOld *);
///
bool insetAllowed(InsetOld::Code code) const;
///
int latex(Buffer const &, std::ostream &,

View File

@ -388,12 +388,6 @@ void InsetTabular::updateLocal(BufferView * bv) const
}
bool InsetTabular::insertInset(BufferView * bv, InsetOld * inset)
{
return the_locking_inset && the_locking_inset->insertInset(bv, inset);
}
void InsetTabular::lfunMousePress(FuncRequest const & cmd)
{
if (hasSelection() && cmd.button() == mouse_button::button3)
@ -404,10 +398,15 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
BufferView * bv = cmd.view();
the_locking_inset = 0;
setPos(bv, cmd.x, cmd.y);
clearSelection();
the_locking_inset = 0;
int cell = getCell(cmd.x + xo_, cmd.y + yo_);
lyxerr << "# InsetTabular::lfunMousePress cell: " << cell << endl;
if (cell == -1) {
} else {
the_locking_inset = 0;
setPos(bv, cmd.x, cmd.y);
clearSelection();
the_locking_inset = 0;
}
if (cmd.button() == mouse_button::button2)
dispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
@ -481,12 +480,11 @@ void InsetTabular::edit(BufferView * bv, int x, int y)
DispatchResult
InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
{
lyxerr << "InsetTabular::dispatch: " << cmd << endl;
lyxerr << "# InsetTabular::dispatch: " << cmd << endl;
// We need to save the value of the_locking_inset as the call to
// the_locking_inset->localDispatch might unlock it.
DispatchResult result(true, true);
BufferView * bv = cmd.view();
bool hs = hasSelection();
BufferView * bv = cmd.view();
switch (cmd.action) {
@ -616,7 +614,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
break;
case LFUN_NEXT: {
if (hs)
if (hasSelection())
clearSelection();
int column = actcol;
if (bv->top_y() + bv->painter().paperHeight()
@ -632,7 +630,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
}
case LFUN_PRIOR: {
if (hs)
if (hasSelection())
clearSelection();
int column = actcol;
if (yo_ < 0) {
@ -845,7 +843,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
result = DispatchResult(false);
break;
}
if (hs)
if (hasSelection())
clearSelection();
}
break;
@ -1594,7 +1592,7 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, bool behind)
if (!the_locking_inset)
return false;
updateLocal(bv);
return the_locking_inset;
return true;
}

View File

@ -80,8 +80,6 @@ public:
///
void updateLocal(BufferView *) const;
///
bool insertInset(BufferView *, InsetOld *);
///
bool insetAllowed(InsetOld::Code code) const;
///
bool isTextInset() const { return true; }
@ -149,14 +147,8 @@ public:
///
void addPreview(lyx::graphics::PreviewLoader &) const;
//
// Public structures and variables
///
mutable LyXTabular tabular;
/// are some cells selected ?
bool hasSelection() const { return has_selection; }
///
Buffer const & buffer() const;
@ -168,6 +160,12 @@ public:
void edit(BufferView * bv, int, int);
/// can we go further down on mouse click?
bool descendable() const { return true; }
//
// Public structures and variables
///
mutable LyXTabular tabular;
protected:
///
virtual

View File

@ -207,7 +207,7 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
if (!owner())
x += scroll();
y += bv->top_y() - text_.firstRow()->ascent_of_text();
y += bv->top_y() - text_.ascent();
text_.draw(pi, x, y);
@ -393,16 +393,6 @@ void InsetText::getCursorPos(int & x, int & y) const
}
bool InsetText::insertInset(BufferView * bv, InsetOld * inset)
{
inset->setOwner(this);
text_.insertInset(inset);
updateLocal(bv);
#warning should we mark the buffer dirty?
return true;
}
bool InsetText::insetAllowed(InsetOld::Code code) const
{
// in_insetAllowed is a really gross hack,

View File

@ -90,8 +90,6 @@ public:
/// FIXME, document
void getCursorPos(int & x, int & y) const;
///
bool insertInset(BufferView *, InsetOld *);
///
bool insetAllowed(InsetOld::Code) const;
///
void setFont(BufferView *, LyXFont const &,

View File

@ -58,22 +58,6 @@ InsetOld::Code InsetTOC::lyxCode() const
}
void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetCommand::metrics(mi, dim);
int const x1 = (mi.base.textwidth - dim.wid) / 2;
button().setBox(Box(x1, x1 + dim.wid, -dim.asc, dim.des));
dim.wid = mi.base.textwidth;
dim_ = dim;
}
void InsetTOC::draw(PainterInfo & pi, int, int y) const
{
InsetCommand::draw(pi, button().box().x1, y);
}
DispatchResult
InsetTOC::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos)

View File

@ -12,14 +12,10 @@
#ifndef INSET_TOC_H
#define INSET_TOC_H
#include "insetcommand.h"
class MetricsInfo;
/** Used to insert table of contents
*/
/// Used to insert table of contents and similar lists
class InsetTOC : public InsetCommand {
public:
///
@ -29,10 +25,6 @@ public:
///
std::auto_ptr<InsetBase> clone() const;
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
std::string const getScreenLabel(Buffer const &) const;
///
EDITABLE editable() const { return IS_EDITABLE; }

View File

@ -23,9 +23,6 @@
class UpdatableInset : public InsetOld {
public:
/// check if the font of the char we want inserting is correct
/// and modify it if it is not.
virtual bool checkInsertChar(LyXFont &) { return true; }
///
virtual EDITABLE editable() const;
@ -33,8 +30,6 @@ public:
virtual void getCursorPos(int &, int &) const {}
/// return the cursor dim
virtual void getCursorDim(int &, int &) const;
///
virtual bool insertInset(BufferView *, InsetOld *) { return false; }
// We need this method to not clobber the real method in Inset
int scroll(bool recursive = true) const
{ return InsetOld::scroll(recursive); }

View File

@ -395,6 +395,11 @@ public:
/// returns whether we've seen our usual 'end' marker
bool read(Buffer const & buf, LyXLex & lex);
///
int ascent() const;
///
int descent() const;
public:
///
int height;

View File

@ -1844,3 +1844,16 @@ bool LyXText::read(Buffer const & buf, LyXLex & lex)
}
return the_end_read;
}
int LyXText::ascent() const
{
return firstRow()->ascent_of_text();
}
int LyXText::descent() const
{
return height - firstRow()->ascent_of_text();
}

View File

@ -252,7 +252,6 @@ string const freefont2string()
}
InsetOld * LyXText::checkInsetHit(int x, int y)
{
ParagraphList::iterator pit;