diff options
author | Tomaž Vajngerl <quikee@gmail.com> | 2013-05-20 08:22:50 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2013-05-20 08:23:36 +0200 |
commit | 784e472aa24d2f2cb9c240b91af4a184c6fcb949 (patch) | |
tree | 420bc3d32c86c43ae8a9054cba4c82052bad989b /starmath | |
parent | 5ef0015704ca67a8f9ffd8f4ae207be355da7f3e (diff) |
Math: Use shared_ptr in ElementsDockingWindow
Change-Id: Id31765f0c2f47cd2ebe830a8b42a9397d6eeffae
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/ElementsDockingWindow.hxx | 42 | ||||
-rw-r--r-- | starmath/inc/node.hxx | 1 | ||||
-rw-r--r-- | starmath/source/ElementsDockingWindow.cxx | 34 |
3 files changed, 40 insertions, 37 deletions
diff --git a/starmath/inc/ElementsDockingWindow.hxx b/starmath/inc/ElementsDockingWindow.hxx index 48fc51bf8052..c338bdaf6ca9 100644 --- a/starmath/inc/ElementsDockingWindow.hxx +++ b/starmath/inc/ElementsDockingWindow.hxx @@ -19,34 +19,33 @@ #ifndef _ELEMENTSDOCKINGWINDOW_HXX_ #define _ELEMENTSDOCKINGWINDOW_HXX_ -#include <sfx2/ctrlitem.hxx> #include <sfx2/dockwin.hxx> -#include <vcl/toolbox.hxx> -#include <vcl/fixed.hxx> -#include <vcl/group.hxx> -#include <vcl/graph.hxx> - #include <svx/dlgctrl.hxx> + #include <document.hxx> +#include <node.hxx> class SmElement { - SmNode* mpNode; - OUString maText; + SmNodePointer mpNode; + OUString maText; public: - SmElement(SmNode* pNode, OUString aText); + Point mBoxLocation; + Size mBoxSize; + + SmElement(SmNodePointer pNode, OUString aText); virtual ~SmElement(); - SmNode* getNode(); - OUString getText() { return maText; } + SmNodePointer getNode(); + OUString getText() + { + return maText; + } virtual bool isSeparator() { return false; } - - Point mBoxLocation; - Size mBoxSize; }; class SmElementSeparator : public SmElement @@ -79,13 +78,16 @@ class SmElementsControl : public Control virtual void MouseButtonDown(const MouseEvent& rMEvt); virtual void MouseMove( const MouseEvent& rMEvt ); - SmDocShell* mpDocShell; - SmFormat maFormat; - sal_uInt16 maCurrentSetId; - SmElement* mpCurrentElement; + typedef boost::shared_ptr<SmElement> SmElementPointer; + typedef std::vector< SmElementPointer > SmElementList; + + SmDocShell* mpDocShell; + SmFormat maFormat; + sal_uInt16 maCurrentSetId; + SmElement* mpCurrentElement; - std::vector<SmElement*> maElementList; - Size maMaxElementDimensions; + SmElementList maElementList; + Size maMaxElementDimensions; void addElement(OUString aElementVisual, OUString aElementSource); diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx index 8d4bc8c15630..b1640a338e56 100644 --- a/starmath/inc/node.hxx +++ b/starmath/inc/node.hxx @@ -57,6 +57,7 @@ class SmDocShell; class SmNode; class SmStructureNode; +typedef boost::shared_ptr<SmNode> SmNodePointer; typedef std::vector< SmNode * > SmNodeArray; typedef std::vector< SmStructureNode * > SmStructureNodeArray; diff --git a/starmath/source/ElementsDockingWindow.cxx b/starmath/source/ElementsDockingWindow.cxx index c2c530ababeb..7be18ca27920 100644 --- a/starmath/source/ElementsDockingWindow.cxx +++ b/starmath/source/ElementsDockingWindow.cxx @@ -18,11 +18,10 @@ */ #include <ElementsDockingWindow.hxx> + #include <starmath.hrc> #include <smmod.hxx> #include <config.hxx> - -#include <node.hxx> #include <view.hxx> #include <visitors.hxx> @@ -32,7 +31,7 @@ SV_DECL_REF(SmDocShell) SV_IMPL_REF(SmDocShell) -SmElement::SmElement(SmNode* pNode, OUString aText) : +SmElement::SmElement(SmNodePointer pNode, OUString aText) : mpNode(pNode), maText(aText) {} @@ -40,15 +39,15 @@ SmElement::SmElement(SmNode* pNode, OUString aText) : SmElement::~SmElement() {} -SmElementSeparator::SmElementSeparator() : - SmElement(NULL, OUString()) -{} - -SmNode* SmElement::getNode() +SmNodePointer SmElement::getNode() { return mpNode; } +SmElementSeparator::SmElementSeparator() : + SmElement(SmNodePointer(), OUString()) +{} + ////////////////////////////////// const sal_uInt16 SmElementsControl::aUnaryBinaryOperatorsList[] = @@ -203,7 +202,7 @@ void SmElementsControl::Paint(const Rectangle&) for (sal_uInt16 i = 0; i < maElementList.size() ; i++) { - SmElement* element = maElementList[i]; + SmElement* element = maElementList[i].get(); if (element->isSeparator()) { x = 0; @@ -235,7 +234,7 @@ void SmElementsControl::Paint(const Rectangle&) } Point location(x + ((boxX-aSizePixel.Width())/2), y + ((boxY-aSizePixel.Height())/2)); - SmDrawingVisitor(*this, PixelToLogic(location), element->getNode()); + SmDrawingVisitor(*this, PixelToLogic(location), element->getNode().get()); element->mBoxLocation = Point(x,y); element->mBoxSize = Size(boxX, boxY); @@ -254,7 +253,7 @@ void SmElementsControl::MouseMove( const MouseEvent& rMouseEvent ) { for (sal_uInt16 i = 0; i < maElementList.size() ; i++) { - SmElement* element = maElementList[i]; + SmElement* element = maElementList[i].get(); Rectangle rect(element->mBoxLocation, element->mBoxSize); if (rect.IsInside(rMouseEvent.GetPosPixel())) { @@ -280,7 +279,7 @@ void SmElementsControl::MouseButtonDown(const MouseEvent& rMouseEvent) { for (sal_uInt16 i = 0; i < maElementList.size() ; i++) { - SmElement* element = maElementList[i]; + SmElement* element = maElementList[i].get(); Rectangle rect(element->mBoxLocation, element->mBoxSize); if (rect.IsInside(rMouseEvent.GetPosPixel())) { @@ -297,13 +296,14 @@ void SmElementsControl::MouseButtonDown(const MouseEvent& rMouseEvent) void SmElementsControl::addSeparator() { - SmElement* pElement = new SmElementSeparator(); + SmElementPointer pElement(new SmElementSeparator()); maElementList.push_back(pElement); } void SmElementsControl::addElement(OUString aElementVisual, OUString aElementSource) { - SmNode* pNode = SmParser().ParseExpression(aElementVisual); + SmNodePointer pNode(SmParser().ParseExpression(aElementVisual)); + pNode->Prepare(maFormat, *mpDocShell); pNode->SetSize(Fraction(10,8)); pNode->Arrange(*this, maFormat); @@ -317,7 +317,7 @@ void SmElementsControl::addElement(OUString aElementVisual, OUString aElementSou maMaxElementDimensions.Height() = aSizePixel.Height(); } - SmElement* pElement = new SmElement(pNode, aElementSource); + SmElementPointer pElement(new SmElement(pNode, aElementSource)); maElementList.push_back(pElement); } @@ -328,9 +328,9 @@ void SmElementsControl::setElementSetId(sal_uInt16 aSetId) build(); } -void SmElementsControl::addElements(const sal_uInt16 aElementsArray[], sal_uInt16 size) +void SmElementsControl::addElements(const sal_uInt16 aElementsArray[], sal_uInt16 aElementsArraySize) { - for (sal_uInt16 i = 0; i < size ; i++) + for (sal_uInt16 i = 0; i < aElementsArraySize ; i++) { sal_uInt16 aElementId = aElementsArray[i]; if (aElementId == 0xFFFF) { |