Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "svx/svdotext.hxx"
21 : #include "svx/svdetc.hxx"
22 : #include "editeng/outlobj.hxx"
23 : #include "svx/svdoutl.hxx"
24 : #include "svx/svdmodel.hxx"
25 : #include "editeng/fhgtitem.hxx"
26 : #include <editeng/eeitem.hxx>
27 : #include <svl/itemset.hxx>
28 : #include <boost/scoped_ptr.hpp>
29 :
30 68350 : SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ )
31 : : mpOutlinerParaObject( pOutlinerParaObject )
32 : , mrObject( rObject )
33 68350 : , mpModel( rObject.GetModel() )
34 136700 : , mbPortionInfoChecked( false )
35 : {
36 : OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)");
37 68350 : }
38 :
39 202226 : SdrText::~SdrText()
40 : {
41 67577 : clearWeak();
42 67577 : delete mpOutlinerParaObject;
43 134649 : }
44 :
45 9 : void SdrText::CheckPortionInfo( SdrOutliner& rOutliner )
46 : {
47 9 : if(!mbPortionInfoChecked)
48 : {
49 : // #i102062# no action when the Outliner is the HitTestOutliner,
50 : // this will remove WrongList info at the OPO
51 8 : if(mpModel && &rOutliner == &mpModel->GetHitTestOutliner())
52 9 : return;
53 :
54 : // TODO: optimization: we could create a BigTextObject
55 8 : mbPortionInfoChecked=true;
56 8 : if(mpOutlinerParaObject!=NULL && rOutliner.ShouldCreateBigTextObject())
57 : {
58 : // #i102062# MemoryLeak closed
59 0 : delete mpOutlinerParaObject;
60 0 : mpOutlinerParaObject = rOutliner.CreateParaObject();
61 : }
62 : }
63 : }
64 :
65 21 : void SdrText::ReformatText()
66 : {
67 21 : mbPortionInfoChecked=false;
68 21 : mpOutlinerParaObject->ClearPortionInfo();
69 21 : }
70 :
71 71 : const SfxItemSet& SdrText::GetItemSet() const
72 : {
73 71 : return const_cast< SdrText* >(this)->GetObjectItemSet();
74 : }
75 :
76 114880 : void SdrText::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
77 : {
78 114880 : if( mpOutlinerParaObject != pTextObject )
79 : {
80 113761 : if( mpModel )
81 : {
82 : // Update HitTestOutliner
83 113761 : const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
84 113761 : if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
85 0 : mpModel->GetHitTestOutliner().SetTextObj( 0 );
86 : }
87 :
88 113761 : delete mpOutlinerParaObject;
89 :
90 113761 : mpOutlinerParaObject = pTextObject;
91 :
92 113761 : mbPortionInfoChecked = false;
93 : }
94 114880 : }
95 :
96 1307510 : OutlinerParaObject* SdrText::GetOutlinerParaObject() const
97 : {
98 1307510 : return mpOutlinerParaObject;
99 : }
100 :
101 : /** returns the current OutlinerParaObject and removes it from this instance */
102 0 : OutlinerParaObject* SdrText::RemoveOutlinerParaObject()
103 : {
104 0 : if( mpModel )
105 : {
106 : // Update HitTestOutliner
107 0 : const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
108 0 : if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
109 0 : mpModel->GetHitTestOutliner().SetTextObj( 0 );
110 : }
111 :
112 0 : OutlinerParaObject* pOPO = mpOutlinerParaObject;
113 :
114 0 : mpOutlinerParaObject = 0;
115 0 : mbPortionInfoChecked = false;
116 :
117 0 : return pOPO;
118 : }
119 :
120 63481 : void SdrText::SetModel( SdrModel* pNewModel )
121 : {
122 63481 : if( pNewModel == mpModel )
123 120529 : return;
124 :
125 6433 : SdrModel* pOldModel = mpModel;
126 6433 : mpModel = pNewModel;
127 :
128 6433 : if( mpOutlinerParaObject && pOldModel!=NULL && pNewModel!=NULL)
129 : {
130 0 : bool bHgtSet = GetObjectItemSet().GetItemState(EE_CHAR_FONTHEIGHT, true) == SfxItemState::SET;
131 :
132 0 : MapUnit aOldUnit(pOldModel->GetScaleUnit());
133 0 : MapUnit aNewUnit(pNewModel->GetScaleUnit());
134 0 : bool bScaleUnitChanged=aNewUnit!=aOldUnit;
135 : // Now move the OutlinerParaObject into a new Pool.
136 : // TODO: We should compare the DefTab and RefDevice of both Models to
137 : // see whether we need to use AutoGrow!
138 0 : sal_uIntPtr nOldFontHgt=pOldModel->GetDefaultFontHeight();
139 0 : sal_uIntPtr nNewFontHgt=pNewModel->GetDefaultFontHeight();
140 0 : bool bDefHgtChanged=nNewFontHgt!=nOldFontHgt;
141 0 : bool bSetHgtItem=bDefHgtChanged && !bHgtSet;
142 0 : if (bSetHgtItem)
143 : {
144 : // fix the value of HeightItem, so
145 : // 1. it remains and
146 : // 2. DoStretchChars gets the right value
147 0 : SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
148 : }
149 : // now use the Outliner, etc. so the above SetAttr can work at all
150 0 : SdrOutliner& rOutliner = mrObject.ImpGetDrawOutliner();
151 0 : rOutliner.SetText(*mpOutlinerParaObject);
152 0 : delete mpOutlinerParaObject;
153 0 : mpOutlinerParaObject=0;
154 0 : if (bScaleUnitChanged)
155 : {
156 0 : Fraction aMetricFactor=GetMapFactor(aOldUnit,aNewUnit).X();
157 :
158 0 : if (bSetHgtItem)
159 : {
160 : // Now correct the frame attribute
161 0 : nOldFontHgt=BigMulDiv(nOldFontHgt,aMetricFactor.GetNumerator(),aMetricFactor.GetDenominator());
162 0 : SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
163 0 : }
164 : }
165 0 : SetOutlinerParaObject(rOutliner.CreateParaObject());
166 0 : mpOutlinerParaObject->ClearPortionInfo();
167 0 : mbPortionInfoChecked=false;
168 0 : rOutliner.Clear();
169 : }
170 : }
171 :
172 4067 : void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode )
173 : {
174 4067 : if( mpModel && !mpOutlinerParaObject )
175 : {
176 2874 : boost::scoped_ptr<Outliner> pOutliner(SdrMakeOutliner(nOutlMode, *mpModel));
177 2874 : if( pOutliner )
178 : {
179 2874 : Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
180 2874 : pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
181 :
182 2874 : pOutliner->SetStyleSheet( 0, GetStyleSheet());
183 2874 : OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject();
184 2874 : SetOutlinerParaObject( pOutlinerParaObject );
185 2874 : }
186 : }
187 4067 : }
188 :
189 71 : const SfxItemSet& SdrText::GetObjectItemSet()
190 : {
191 71 : return mrObject.GetObjectItemSet();
192 : }
193 :
194 0 : void SdrText::SetObjectItem(const SfxPoolItem& rItem)
195 : {
196 0 : mrObject.SetObjectItem( rItem );
197 0 : }
198 :
199 302 : SfxStyleSheet* SdrText::GetStyleSheet() const
200 : {
201 302 : return mrObject.GetStyleSheet();
202 435 : }
203 :
204 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|