ImproveMathEquationEditor/Baseline AlignmentEquations/UI improvement

Back to Baseline alignment for equations

UI for Baseline recalculation
The most important thing we need to implement is the possibility to align formula if it was misaligned by user or got from older document without right alignment.

arranging the formula
If we want to retrieve baseline from Starmath it needs to be calculated, ie we need to arrange the formula and possibly parse it before. This is not a problem, once we get to pointer on SmDocShell of the formula we can call these methods and then call SwFEShell::SetBaselineFromSm.


 * 1) When object is selected we get to the svt::EmbeddedObjectReference using SwFEShell::GetOLEObject
 * 2) Usually when we make a change to the equation the SmDocShell is called by SfxShell::CallExec, I'll leave this stage for someone or myslef once I understand how to add options to right click menu for ole objects.
 * 3) Now is the part, when we want to call something in Sm to arrange the formula although no changes has been done to it. We need to make sure that SfxInPlaceClient::notifyEvent is called afterwards, because here is called method SwOleClient::FormatChagned that will make sure the baseline is set. (We also need to change the anchor and vertical position to 'From Bottom' (VertOrientation::NONE) )
 * In fact we don't need to rearrange it if it already was before and if we make sure that the baseline retrieved is the one for this formula, which might not be trivial. To make sure we should probably call SmDocShell::ArrangeFormula, it checks whether it isn't arranged already, so it won't rearrange it if not needed.

So to make sure that the baseline is retrieved precisely from the right formula we have to investigate how is it done. In SmModel::_getPropertyValues the SmDocShell is got by calling SfxBaseModel::   void AlignAllFormulas;    void AlignAllFormulas;ectShell and it has pointer to that shell stored in m_pData. So we have to have the right SmModel called. It's derived from comphelper::PropertySetHelper which is derived from beans::XPropertySet for which is called getPropertyValues inside SetBaselineFromSm. Therefore we are sure that the right SmDocShell is called. Now if we call method SetBaselineFromSm for not arranged formula SmDocShell won't have pTree (node tree). So the only thing we have to make sure, is that when retrieving baseline for not arranged formulas SmModel::_getPropertyValues checks whether there is pTree and if it's not it will arrange the formula.

Now we can call SeBaselineFromSm any time and so implementing UI in Writer is easy, we have to just set the anchor to AsChar change the vertical orientation and call SetBaselineFromSm for the formula that should be aligned. Then there can be option to search for all formulas and call method to align it.

aligning the formulas
So, I created two methods for aligning formulas:

void SwFEShell::SetBaselineToBaseline( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& xObj, BOOL bSetAnchor = FALSE )

this one takes the object reference and bSetAnchor which determines whether also object with anchor not 'as char' will have anchor changed to 'as char' and aligned

void SwFEShell::AlignAllFormulas

this method finds all formulas and aligns them using SetBaselineToBaseline

problem with repainting formulas
When I implemented new method AlignAllFormulas I got to a problem, which was that not all the formulas were repainted, ie the position was changed as a value, but the line was not formatted. Once I typed some letter to a line where the formulas still weren't repainted, they got to the right place since typing a letter to a line formats it.

Formatting lines and all the stuff around is done in EndAllAction, which was executed, but somehow didn't align all objects. I did some tracing, trying to find the cause, but the process is fairly complicated. The only thing I found out was that in SwLayAction::FormatCntnt layact.cxx:2313 where the SwObjectFormatter should be called is condition IsAgain that happens to be false. It's written above in a comment "No format, if action flag  is set or action is interrupted."

Implementing some other method I used it to align all selected (highlighted) formulas, which the same way called EndAllAction, this time all formulas got aligned, becasue the  was true, not sure where exactly is the problem though.


 * Solved... I needed to invalidate the position of frame, which could be expected, but firstly I invalidated everything I could see and nothing happened because I didn't notice that I can invalidate the position specifically. So I traced a bit more than needed, but it's done which is the main thing.