#include "coordcache.h"
#include "cursor.h"
#include "metricsinfo.h"
-
+#include "UpdateFlags.h"
#include "support/types.h"
#include <boost/utility.hpp>
class ParIterator;
class ViewMetricsInfo;
-namespace Update {
- enum flags {
- FitCursor = 1,
- Force = 2,
- SinglePar = 4,
- MultiParSel = 8
- };
-
-inline flags operator|(flags const f, flags const g)
-{
- return static_cast<flags>(int(f) | int(g));
-}
-
-inline flags operator&(flags const f, flags const g)
-{
- return static_cast<flags>(int(f) & int(g));
-}
-
-} // namespace
-
/// Scrollbar Parameters
struct ScrollbarParameters
{
--- /dev/null
+#ifndef UPDATE_FLAGS_H\r
+#define UPDATE_FLAGS_H\r
+\r
+namespace lyx {\r
+\r
+namespace Update {\r
+ enum flags {\r
+ None = 0,\r
+ FitCursor = 1,\r
+ Force = 2,\r
+ SinglePar = 4,\r
+ MultiParSel = 8\r
+ };\r
+\r
+inline flags operator|(flags const f, flags const g)\r
+{\r
+ return static_cast<flags>(int(f) | int(g));\r
+}\r
+\r
+inline flags operator&(flags const f, flags const g)\r
+{\r
+ return static_cast<flags>(int(f) & int(g));\r
+}\r
+\r
+} // namespace\r
+\r
+} // namespace lyx\r
+#endif\r
// The common case is 'LFUN handled, need update', so make the
// LFUN handler's life easier by assuming this as default value.
// The handler can reset the update and val flags if necessary.
- disp_.update(true);
+ disp_.update(Update::FitCursor | Update::Force);
disp_.dispatched(true);
inset().dispatch(*this, cmd);
if (disp_.dispatched())
if (!disp_.dispatched()) {
lyxerr[Debug::DEBUG] << "RESTORING OLD CURSOR!" << endl;
operator=(safe);
- disp_.update(false);
+ disp_.update(Update::None);
disp_.dispatched(false);
}
}
}
-void LCursor::selHandle(bool sel)
+bool LCursor::selHandle(bool sel)
{
//lyxerr << "LCursor::selHandle" << endl;
if (sel == selection())
- return;
+ return false;
resetAnchor();
selection() = sel;
+ return true;
}
}
-void LCursor::needsUpdate()
+void LCursor::updateFlags(Update::flags f)
{
- disp_.update(true);
+ disp_.update(f);
}
void LCursor::noUpdate()
{
- disp_.update(false);
+ disp_.update(Update::None);
}
/// access start of selection
DocIterator selectionEnd() const;
///
- void selHandle(bool selecting);
+ bool selHandle(bool selecting);
//
docstring selectionAsString(bool label) const;
///
void undispatched();
/// the event was already dispatched
void dispatched();
- /// call update() when done
- void needsUpdate();
+ /// Set which update should be done
+ void updateFlags(Update::flags f);
/**
* don't call update() when done
*
#ifndef DISPATCH_RESULT_H
#define DISPATCH_RESULT_H
+#include "UpdateFlags.h"
+
namespace lyx {
/// Maybe this can go entirely
class DispatchResult {
public:
///
- DispatchResult() : dispatched_(false), update_(false) {}
+ DispatchResult() : dispatched_(false), update_(Update::None) {}
///
- DispatchResult(bool disp, bool upd) : dispatched_(disp), update_(upd) {}
+ DispatchResult(bool disp, Update::flags f) : dispatched_(disp), update_(f) {}
//
bool dispatched() const { return dispatched_; }
///
void dispatched(bool disp) { dispatched_ = disp; }
///
- bool update() const { return update_; }
+ Update::flags update() const { return update_; }
///
- void update(bool up) { update_ = up; }
+ void update(Update::flags f) { update_ = f; }
private:
/// was the event fully dispatched?
bool dispatched_;
/// do we need to redraw the screen afterwards?
- bool update_;
+ Update::flags update_;
};
"assign branch"));
}
// update the bufferview
+ // If we used an LFUN, we would not need that
kernel().bufferview()->update();
}
BufferView & bufferview = *kernel().bufferview();
cap::replaceSelectionWithString(bufferview.cursor(), replacement, true);
kernel().buffer().markDirty();
+ // If we used an LFUN, we would not need that
bufferview.update();
// fix up the count
--count_;
void InsetBase::dispatch(LCursor & cur, FuncRequest & cmd)
{
- cur.needsUpdate();
+ cur.updateFlags(Update::Force | Update::FitCursor);
cur.dispatched();
doDispatch(cur, cmd);
}
scx_ = 0;
}
- cur.needsUpdate();
+ cur.updateFlags(Update::Force | Update::FitCursor);
InsetTabularMailer(*this).updateDialog(&bv);
}
// redraw the screen at the end (first of the two drawing steps).
//This is done unless explicitely requested otherwise
- bool update = true;
- // also do the second redrawing step. Only done if requested.
- bool updateforce = false;
+ Update::flags updateFlags = Update::FitCursor;
FuncStatus const flag = getStatus(cmd);
if (!flag.enabled()) {
lyx_view_->message(str + _(" done."));
} else
writeAs(lyx_view_->buffer());
- update = false;
+ updateFlags = Update::None;
break;
case LFUN_BUFFER_WRITE_AS:
writeAs(lyx_view_->buffer(), argument);
- update = false;
+ updateFlags = Update::None;
break;
case LFUN_BUFFER_RELOAD: {
}
// ideally, the update flag should be set by the insets,
// but this is not possible currently
- updateforce = true;
+ updateFlags = Update::Force | Update::FitCursor;
break;
}
it->dispatch(tmpcur, fr);
}
}
- updateforce = true;
+ updateFlags = Update::Force | Update::FitCursor;
break;
}
buffer->errors("Class Switch");
updateLabels(*buffer);
- updateforce = true;
+ updateFlags = Update::Force | Update::FitCursor;
break;
}
default: {
view()->cursor().dispatch(cmd);
- update = false;
- updateforce |= view()->cursor().result().update();
+ updateFlags = view()->cursor().result().update();
if (!view()->cursor().result().dispatched())
- updateforce |= view()->dispatch(cmd);
+ if (view()->dispatch(cmd))
+ updateFlags = Update::Force | Update::FitCursor;
break;
}
}
// Redraw screen unless explicitly told otherwise.
// This also initializes the position cache for all insets
// in (at least partially) visible top-level paragraphs.
- if (updateforce)
- view()->update(Update::FitCursor | Update::Force);
- else if (update)
- view()->update(Update::FitCursor);
+ bool needSecondUpdate = false;
+ if (updateFlags != Update::None)
+ view()->update(updateFlags);
+ else
+ needSecondUpdate = view()->fitCursor();
- view()->buffer()->changed();
- lyx_view_->updateStatusBar();
+ if (needSecondUpdate || updateFlags != Update::None) {
+ view()->buffer()->changed();
+ lyx_view_->updateStatusBar();
+ }
// if we executed a mutating lfun, mark the buffer as dirty
if (flag.enabled()
}
-void update(LCursor & cur)
-{
- //we don't call update(true, false) directly to save a metrics call
- if (cur.bv().fitCursor())
- cur.bv().update(Update::Force);
-}
-
-
} // anon namespace
case LFUN_BUFFER_BEGIN:
case LFUN_BUFFER_BEGIN_SELECT:
- cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
if (cur.depth() == 1) {
needsUpdate |= cursorTop(cur);
} else {
case LFUN_BUFFER_END:
case LFUN_BUFFER_END_SELECT:
- cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
if (cur.depth() == 1) {
needsUpdate |= cursorBottom(cur);
} else {
case LFUN_CHAR_FORWARD_SELECT:
//lyxerr << BOOST_CURRENT_FUNCTION
// << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
- cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
if (isRTL(cur.paragraph()))
needsUpdate |= cursorLeft(cur);
else
case LFUN_CHAR_BACKWARD:
case LFUN_CHAR_BACKWARD_SELECT:
//lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
- cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
if (isRTL(cur.paragraph()))
needsUpdate |= cursorRight(cur);
else
case LFUN_UP:
case LFUN_UP_SELECT:
- update(cur);
//lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
- cur.selHandle(cmd.action == LFUN_UP_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
needsUpdate |= cursorUp(cur);
+
if (!needsUpdate && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
cur.undispatched();
case LFUN_DOWN:
case LFUN_DOWN_SELECT:
- update(cur);
//lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
- cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
needsUpdate |= cursorDown(cur);
+
if (!needsUpdate && oldTopSlice == cur.top() &&
cur.boundary() == oldBoundary)
{
case LFUN_PARAGRAPH_UP:
case LFUN_PARAGRAPH_UP_SELECT:
- cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
needsUpdate |= cursorUpParagraph(cur);
break;
case LFUN_PARAGRAPH_DOWN:
case LFUN_PARAGRAPH_DOWN_SELECT:
- cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
needsUpdate |= cursorDownParagraph(cur);
break;
case LFUN_SCREEN_UP:
case LFUN_SCREEN_UP_SELECT:
- update(cur);
- cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
if (cur.pit() == 0 && cur.textRow().pos() == 0) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_UP);
case LFUN_SCREEN_DOWN:
case LFUN_SCREEN_DOWN_SELECT:
- update(cur);
- cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
if (cur.pit() == cur.lastpit()
&& cur.textRow().endpos() == cur.lastpos()) {
cur.undispatched();
case LFUN_LINE_BEGIN:
case LFUN_LINE_BEGIN_SELECT:
- update(cur);
- cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
needsUpdate |= cursorHome(cur);
break;
case LFUN_LINE_END:
case LFUN_LINE_END_SELECT:
- update(cur);
- cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
needsUpdate |= cursorEnd(cur);
break;
case LFUN_WORD_FORWARD:
case LFUN_WORD_FORWARD_SELECT:
- cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
if (isRTL(cur.paragraph()))
needsUpdate |= cursorLeftOneWord(cur);
else
case LFUN_WORD_BACKWARD:
case LFUN_WORD_BACKWARD_SELECT:
- cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
+ needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
if (isRTL(cur.paragraph()))
needsUpdate |= cursorRightOneWord(cur);
else
break;
}
+ needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
if (singleParUpdate)
// Inserting characters does not change par height
if (cur.bottom().paragraph().dim().height()
== olddim.height()) {
// if so, update _only_ this paragraph
- cur.bv().update(Update::SinglePar |
- Update::FitCursor |
- Update::MultiParSel);
- cur.noUpdate();
+ cur.updateFlags(Update::SinglePar |
+ Update::FitCursor |
+ Update::MultiParSel);
return;
} else
needsUpdate = true;
&& !cur.selection())
cur.noUpdate();
else
- cur.needsUpdate();
+ cur.updateFlags(Update::Force | Update::FitCursor);
}