On Thu, Oct 09, 2003 at 10:53:51PM +0000, Angus Leeming wrote:
> André, how does InsetFormula know when it is being edited? 

The current idiom is to test for

  mathcursor && mathcursor->formula() == SomeInsetFormulaBasePointer

Far from nice, though.

> Is the test below correct?
> 
> void InsetFormula::draw(PainterInfo & pi, int x, int y) const
> {
>       // The previews are updated/drawn only when we're not editing the inset.
>       bool const editing_inset = mathcursor && mathcursor->formula() == this;

This one? Yes.

> I'm trying to reduce the number of wasted cycles by only initiating the
> creation of the preview once we leave the inset. At the moment previewReady
> is called on every key draw event, but my own tree now has:
> 
>       bool use_preview = !editing_inset;
>       if (use_preview) {
>               Buffer const * b_ptr = pi.base.bv ? pi.base.bv->buffer() : 0;
>               use_preview = b_ptr && preview_->previewReady(*b_ptr);
>       }
> 
> which prevents us from checking the preview whilst we're editing the inset.

Should be ok.

> Further,
>       bool PreviewedInset::previewReady() const;
> does too much at the moment. Not only does it return whether the preview
> is ready to be displayed, but it also initiates the creation of the preview.
> I'd like to split that into two functions,
>       // No side effects
>       bool PreviewedInset::previewReady() const;
>       // Initiate the generation of the preview.
>       void PreviewedInset::update(string const & latex_snippet);
> which seems much cleaner.

Good.

> My question is, where should I call PreviewedInset::update from? 
> >From InsetFormula::draw or from InsetFormula::metrics? At the moment
> it is effectively invoked from metrics (since we ask previewReady()? 
> from both functions).
> 
> I have the feeling, however, that 'metrics' should be a lean and mean
> function so 'draw' is the best place from which to call
> PreviewedInset::update.

There should be 1:1 metrics/draw relation in theory and I don't think we
are too far of right now in practice. In fact, I hope to save a few
calls to metrics at one point of time. So I don't think it really
matters where you put it.

Andre'

Reply via email to