#include "Intl.h"
#include "Language.h"
#include "LayoutFile.h"
-#include "Lexer.h"
#include "LyX.h"
#include "LyXAction.h"
#include "lyxfind.h"
#include "support/gettext.h"
#include "support/lassert.h"
#include "support/Length.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/types.h"
Private(BufferView & bv) :
update_strategy_(FullScreenUpdate),
update_flags_(Update::Force),
- cursor_(bv), anchor_pit_(0), anchor_ypos_(0),
+ cursor_(bv), anchor_pit_(0), anchor_ypos_(10000),
wh_(0), inlineCompletionUniqueChars_(0),
last_inset_(nullptr), mouse_position_cache_(),
gui_(nullptr), bookmark_edit_position_(-1),
frontend::CaretGeometry caret_geometry_;
///
bool mouse_selecting_ = false;
+ /// Reference value for statistics (essentially subtract this from the actual value to see relative counts)
+ /// (words/chars/chars no blanks)
+ int stats_ref_value_w_ = 0;
+ int stats_ref_value_c_ = 0;
+ int stats_ref_value_nb_ = 0;
+ bool stats_update_trigger_ = false;
+
};
updateMetrics(true);
// metrics is done, full drawing is necessary now
flags = (flags & ~Update::Force) | Update::ForceDraw;
- } else if (flags & Update::ForceDraw)
+ }
+ /* If a single paragraph update has been requested and we are not
+ * already repainting all, check whether this update changes the
+ * paragraph metrics. If it does, then compute all metrics (in
+ * case the paragraph is in an inset)
+ *
+ * We handle this before FitCursor because the later will require
+ * correct metrics at cursor position.
+ */
+ else if ((flags & Update::SinglePar) && !(flags & Update::ForceDraw)) {
+ if (!singleParUpdate())
+ updateMetrics(true);
+ }
+ else if (flags & Update::ForceDraw)
// This will compute only the needed metrics and update positions.
updateMetrics(false);
- // Detect whether we can only repaint a single paragraph (if we
- // are not already redrawing all).
- // We handle this before FitCursor because the later will require
- // correct metrics at cursor position.
- if (!(flags & Update::ForceDraw)
- && (flags & Update::SinglePar)
- && !singleParUpdate())
- updateMetrics(true);
-
// Then make sure that the screen contains the cursor if needed
if (flags & Update::FitCursor) {
if (needsFitCursor()) {
// First try to make the selection start visible
// (which is just the cursor when there is no selection)
scrollToCursor(d->cursor_.selectionBegin(), SCROLL_VISIBLE);
- // Metrics have to be recomputed (maybe again)
- updateMetrics(true);
+ // Metrics have to be updated
+ updateMetrics(false);
// Is the cursor visible? (only useful if cursor is at end of selection)
if (needsFitCursor()) {
// then try to make cursor visible instead
scrollToCursor(d->cursor_, SCROLL_VISIBLE);
// Metrics have to be recomputed (maybe again)
- updateMetrics(true);
+ updateMetrics(false);
}
}
- flags = flags & ~Update::FitCursor;
+ flags = (flags & ~Update::FitCursor) | Update::ForceDraw;
}
// Add flags to the the update flags. These will be reset to None
bool update)
{
if (scrollToCursor(dit, how) && update)
- processUpdateFlags(Update::Force);
+ processUpdateFlags(Update::ForceDraw);
}
flag.setEnabled(cur.selection());
break;
+ case LFUN_STATISTICS_REFERENCE_CLAMP: {
+ // disable optitem reset if clamp not used
+ if (cmd.argument() == "reset" && d->stats_ref_value_c_ == 0) {
+ flag.setEnabled(false);
+ break;
+ }
+ flag.setEnabled(true);
+ break;
+
+ }
+
default:
return false;
}
}
break;
+ case LFUN_STATISTICS_REFERENCE_CLAMP: {
+ d->stats_update_trigger_ = true;
+ if (cmd.argument() == "reset") {
+ d->stats_ref_value_w_ = d->stats_ref_value_c_ = d->stats_ref_value_nb_ = 0;
+ break;
+ }
+
+ DocIterator from, to;
+ from = doc_iterator_begin(&buffer_);
+ to = doc_iterator_end(&buffer_);
+ buffer_.updateStatistics(from, to);
+
+ d->stats_ref_value_w_ = buffer_.wordCount();
+ d->stats_ref_value_c_ = buffer_.charCount(true);
+ d->stats_ref_value_nb_ = buffer_.charCount(false);
+ break;
+ }
+
+
case LFUN_SCREEN_UP:
case LFUN_SCREEN_DOWN: {
Point p = getPos(cur);
void BufferView::resize(int width, int height)
{
- // Update from work area
- width_ = width;
height_ = height;
+ // Update metrics only if width has changed
+ if (width != width_) {
+ width_ = width;
- // Clear the paragraph height cache.
- d->par_height_.clear();
- // Redo the metrics.
- updateMetrics();
+ // Clear the paragraph height cache.
+ d->par_height_.clear();
+ // Redo the metrics.
+ updateMetrics(true);
+ }
+ // metrics is OK, full drawing is necessary now
+ d->update_flags_ = (d->update_flags_ & ~Update::Force) | Update::ForceDraw;
+ d->update_strategy_ = FullScreenUpdate;
}
}
+int BufferView::stats_ref_value_w() const
+{
+ return d->stats_ref_value_w_;
+}
+
+
+int BufferView::stats_ref_value_c() const
+{
+ return d->stats_ref_value_c_;
+}
+
+
+int BufferView::stats_ref_value_nb() const
+{
+ return d->stats_ref_value_nb_;
+}
+
+
void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
{
//lyxerr << "[ cmd0 " << cmd0 << "]" << endl;
// LFUN_FILE_OPEN generated by drag-and-drop.
FuncRequest cmd = cmd0;
- Cursor old = cursor();
- Cursor cur(*this);
- cur.push(buffer_.inset());
- cur.selection(d->cursor_.selection());
-
// Either the inset under the cursor or the
// surrounding Text will handle this event.
return;
}
+ Cursor old = cursor();
+ Cursor cur(*this);
+ cur.push(buffer_.inset());
+ cur.selection(d->cursor_.selection());
+
// Build temporary cursor.
Inset * inset = d->text_metrics_[&buffer_.text()].editXY(cur, cmd.x(), cmd.y());
if (inset) {
if (!ready())
return;
+ //LYXERR0("updateMetrics " << _v_(force));
+
Text & buftext = buffer_.text();
pit_type const lastpit = int(buftext.paragraphs().size()) - 1;
/* FIXME: do we want that? It avoids potential issues with old
* paragraphs that should have been recomputed but have not, at
- * the price of potential extra metrics computaiton. I do not
+ * the price of potential extra metrics computation. I do not
* think that the performance gain is high, so that for now the
* extra paragraphs are removed
*/
// Draw everything.
tm.draw(pi, 0, y);
- // and possibly grey out below
+ break;
+ }
+
+ // Possibly grey out below
+ if (d->update_strategy_ != NoScreenUpdate) {
pair<pit_type, ParagraphMetrics const *> lastpm = tm.last();
int const y2 = lastpm.second->bottom();
? Color_background : Color_bottomarea;
pain.fillRectangle(0, y2, width_, height_ - y2, color);
}
- break;
}
+
LYXERR(Debug::PAINTING, (pain.isNull() ? "\t\t --- END NODRAW ---"
: "\t\t *** END DRAWING ***"));
return d->clickable_inset_;
}
+
+bool BufferView::stats_update_trigger()
+{
+ if (d->stats_update_trigger_) {
+ d->stats_update_trigger_ = false;
+ return true;
+ }
+ return false;
+}
+
} // namespace lyx