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;
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));
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();
// 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.
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);
- }
}
}
}
}
-}; // namespace bv_funcs
+} // namespace bv_funcs
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_
+
+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
#include "updatableinset.h"
#include "BufferView.h"
+#include "debug.h"
#include "gettext.h"
+#include "lyxtext.h"
#include "LColor.h"
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();
{
return i && i->editable() == InsetOld::HIGHLY_EDITABLE;
}
+
+
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?
}
-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";
/// 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; }
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;
}
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;
}
-bool InsetERT::insertInset(BufferView *, InsetOld *)
-{
- return false;
-}
-
-
void InsetERT::updateStatus(bool swap) const
{
if (status_ != Inlined) {
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);
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:
///
std::string const editMessage() const;
///
- bool insertInset(BufferView *, InsetOld *);
- ///
bool insetAllowed(InsetOld::Code code) const;
///
int latex(Buffer const &, std::ostream &,
}
-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)
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"));
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) {
break;
case LFUN_NEXT: {
- if (hs)
+ if (hasSelection())
clearSelection();
int column = actcol;
if (bv->top_y() + bv->painter().paperHeight()
}
case LFUN_PRIOR: {
- if (hs)
+ if (hasSelection())
clearSelection();
int column = actcol;
if (yo_ < 0) {
result = DispatchResult(false);
break;
}
- if (hs)
+ if (hasSelection())
clearSelection();
}
break;
if (!the_locking_inset)
return false;
updateLocal(bv);
- return the_locking_inset;
+ return true;
}
///
void updateLocal(BufferView *) const;
///
- bool insertInset(BufferView *, InsetOld *);
- ///
bool insetAllowed(InsetOld::Code code) const;
///
bool isTextInset() const { return true; }
///
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;
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
if (!owner())
x += scroll();
- y += bv->top_y() - text_.firstRow()->ascent_of_text();
+ y += bv->top_y() - text_.ascent();
text_.draw(pi, x, y);
}
-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,
/// FIXME, document
void getCursorPos(int & x, int & y) const;
///
- bool insertInset(BufferView *, InsetOld *);
- ///
bool insetAllowed(InsetOld::Code) const;
///
void setFont(BufferView *, LyXFont 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)
#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:
///
///
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; }
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;
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); }
/// 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;
}
return the_end_read;
}
+
+
+int LyXText::ascent() const
+{
+ return firstRow()->ascent_of_text();
+}
+
+
+int LyXText::descent() const
+{
+ return height - firstRow()->ascent_of_text();
+}
+
}
-
InsetOld * LyXText::checkInsetHit(int x, int y)
{
ParagraphList::iterator pit;