* BufferView::updateMetrics(): split up the method in two for the SinglePar case.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20563 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-09-28 09:11:24 +00:00
parent e0f7fde3b6
commit 2417d9d911
2 changed files with 48 additions and 40 deletions

View File

@ -1414,9 +1414,45 @@ ViewMetricsInfo const & BufferView::viewMetricsInfo()
} }
// FIXME: We should split-up updateMetrics() for the singlepar case. bool BufferView::singleParUpdate()
{
Text & buftext = buffer_.text();
pit_type const bottom_pit = cursor_.bottom().pit();
TextMetrics & tm = textMetrics(&buftext);
int old_height = tm.parMetrics(bottom_pit).height();
// In Single Paragraph mode, rebreak only
// the (main text, not inset!) paragraph containing the cursor.
// (if this paragraph contains insets etc., rebreaking will
// recursively descend)
tm.redoParagraph(bottom_pit);
ParagraphMetrics const & pm = tm.parMetrics(bottom_pit);
if (pm.height() != old_height)
// Paragraph height has changed so we cannot proceed to
// the singlePar optimisation.
return false;
int y1 = pm.position() - pm.ascent();
int y2 = pm.position() + pm.descent();
metrics_info_ = ViewMetricsInfo(bottom_pit, bottom_pit, y1, y2,
SingleParUpdate, buftext.paragraphs().size());
LYXERR(Debug::PAINTING)
<< BOOST_CURRENT_FUNCTION
<< "\ny1: " << y1
<< " y2: " << y2
<< " pit: " << bottom_pit
<< " singlepar: 1"
<< endl;
return true;
}
void BufferView::updateMetrics(bool singlepar) void BufferView::updateMetrics(bool singlepar)
{ {
if (singlepar && singleParUpdate())
// No need to update the full screen metrics.
return;
Text & buftext = buffer_.text(); Text & buftext = buffer_.text();
pit_type const npit = int(buftext.paragraphs().size()); pit_type const npit = int(buftext.paragraphs().size());
@ -1425,48 +1461,16 @@ void BufferView::updateMetrics(bool singlepar)
offset_ref_ = 0; offset_ref_ = 0;
} }
if (!singlepar) { // Clear out the position cache in case of full screen redraw,
// Clear out the position cache in case of full screen redraw, coord_cache_.clear();
coord_cache_.clear();
// Clear out paragraph metrics to avoid having invalid metrics // Clear out paragraph metrics to avoid having invalid metrics
// in the cache from paragraphs not relayouted below // in the cache from paragraphs not relayouted below
// The complete text metrics will be redone. // The complete text metrics will be redone.
text_metrics_.clear(); text_metrics_.clear();
}
TextMetrics & tm = textMetrics(&buftext); TextMetrics & tm = textMetrics(&buftext);
pit_type const bottom_pit = cursor_.bottom().pit();
// If the paragraph metrics has changed, we can not
// use the singlepar optimisation.
if (singlepar) {
int old_height = tm.parMetrics(bottom_pit).height();
// In Single Paragraph mode, rebreak only
// the (main text, not inset!) paragraph containing the cursor.
// (if this paragraph contains insets etc., rebreaking will
// recursively descend)
tm.redoParagraph(bottom_pit);
ParagraphMetrics const & pm = tm.parMetrics(bottom_pit);
if (pm.height() == old_height) {
// Paragraph height has not changed so we can proceed to
// the singlePar optimisation.
updateOffsetRef();
int y1 = pm.position() - pm.ascent();
int y2 = pm.position() + pm.descent();
metrics_info_ = ViewMetricsInfo(bottom_pit, bottom_pit, y1, y2,
SingleParUpdate, npit);
LYXERR(Debug::PAINTING)
<< BOOST_CURRENT_FUNCTION
<< "\ny1: " << y1
<< " y2: " << y2
<< " pit: " << bottom_pit
<< " singlepar: " << singlepar
<< endl;
return;
}
}
pit_type const pit = anchor_ref_; pit_type const pit = anchor_ref_;
int pit1 = pit; int pit1 = pit;
int pit2 = pit; int pit2 = pit;
@ -1474,6 +1478,7 @@ void BufferView::updateMetrics(bool singlepar)
// Rebreak anchor paragraph. // Rebreak anchor paragraph.
tm.redoParagraph(pit); tm.redoParagraph(pit);
// Take care of anchor offset if case a recentering is needed.
updateOffsetRef(); updateOffsetRef();
int y0 = tm.parMetrics(pit).ascent() - offset_ref_; int y0 = tm.parMetrics(pit).ascent() - offset_ref_;
@ -1520,7 +1525,7 @@ void BufferView::updateMetrics(bool singlepar)
<< " pit1: " << pit1 << " pit1: " << pit1
<< " pit2: " << pit2 << " pit2: " << pit2
<< " npit: " << npit << " npit: " << npit
<< " singlepar: " << singlepar << " singlepar: 0"
<< endl; << endl;
metrics_info_ = ViewMetricsInfo(pit1, pit2, y1, y2, metrics_info_ = ViewMetricsInfo(pit1, pit2, y1, y2,

View File

@ -249,6 +249,9 @@ public:
boost::signal<void(docstring layout)> layoutChanged; boost::signal<void(docstring layout)> layoutChanged;
private: private:
/// Update current paragraph metrics.
/// \return true if no further update is needed.
bool singleParUpdate();
/// ///
bool multiParSel(); bool multiParSel();