xref: /AOO41X/main/sd/source/ui/presenter/PresenterTextView.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "precompiled_sd.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "PresenterTextView.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
33*cdf0e10cSrcweir #include <cppcanvas/vclfactory.hxx>
34*cdf0e10cSrcweir #include <svl/itempool.hxx>
35*cdf0e10cSrcweir #include <svl/itemset.hxx>
36*cdf0e10cSrcweir #include <unotools/linguprops.hxx>
37*cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
38*cdf0e10cSrcweir #include <editeng/colritem.hxx>
39*cdf0e10cSrcweir #include <editeng/editeng.hxx>
40*cdf0e10cSrcweir #include <editeng/editstat.hxx>
41*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
42*cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
43*cdf0e10cSrcweir #include <editeng/fontitem.hxx>
44*cdf0e10cSrcweir #include <svx/xflclit.hxx>
45*cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
46*cdf0e10cSrcweir #include <vcl/svapp.hxx>
47*cdf0e10cSrcweir #include <vcl/virdev.hxx>
48*cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/rendering/XSpriteCanvas.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/util/Color.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hpp>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir using namespace ::com::sun::star;
56*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
57*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
58*cdf0e10cSrcweir using ::rtl::OUString;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir namespace sd { namespace presenter {
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir //===== Service ===============================================================
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir Reference<XInterface> SAL_CALL PresenterTextViewService_createInstance (
65*cdf0e10cSrcweir     const Reference<XComponentContext>& rxContext)
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     return Reference<XInterface>(static_cast<XWeak*>(new PresenterTextView(rxContext)));
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir ::rtl::OUString PresenterTextViewService_getImplementationName (void) throw(RuntimeException)
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir     return OUString::createFromAscii("com.sun.star.comp.Draw.PresenterTextView");
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL PresenterTextViewService_getSupportedServiceNames (void)
82*cdf0e10cSrcweir     throw (RuntimeException)
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir 	static const ::rtl::OUString sServiceName(
85*cdf0e10cSrcweir         ::rtl::OUString::createFromAscii("com.sun.star.drawing.PresenterTextView"));
86*cdf0e10cSrcweir 	return Sequence<rtl::OUString>(&sServiceName, 1);
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir //===== PresenterTextView::Implementation =====================================
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir class PresenterTextView::Implementation
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir public:
96*cdf0e10cSrcweir     const OUString msTextPropertyName;
97*cdf0e10cSrcweir     const OUString msBitmapPropertyName;
98*cdf0e10cSrcweir     const OUString msSizePropertyName;
99*cdf0e10cSrcweir     const OUString msBackgroundColorPropertyName;
100*cdf0e10cSrcweir     const OUString msTextColorPropertyName;
101*cdf0e10cSrcweir     const OUString msFontDescriptorPropertyName;
102*cdf0e10cSrcweir     const OUString msTopPropertyName;
103*cdf0e10cSrcweir     const OUString msTopRelativePropertyName;
104*cdf0e10cSrcweir     const OUString msTotalHeightPropertyName;
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     Implementation (void);
107*cdf0e10cSrcweir     ~Implementation (void);
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     void SetCanvas (const cppcanvas::CanvasSharedPtr& rCanvas);
110*cdf0e10cSrcweir     void SetSize (const Size aSize);
111*cdf0e10cSrcweir     void SetBackgroundColor (const Color aColor);
112*cdf0e10cSrcweir     void SetTextColor (const Color aColor);
113*cdf0e10cSrcweir     void SetFontDescriptor (const awt::FontDescriptor& rFontDescriptor);
114*cdf0e10cSrcweir     sal_Int32 GetTop (void) const;
115*cdf0e10cSrcweir     void SetTop (const sal_Int32 nTop);
116*cdf0e10cSrcweir     void SetText (const OUString& Text);
117*cdf0e10cSrcweir     sal_Int32 ParseDistance (const OUString& rsDistance) const;
118*cdf0e10cSrcweir     Reference<rendering::XBitmap> GetBitmap (void);
119*cdf0e10cSrcweir     sal_Int32 GetTotalHeight (void);
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir private:
122*cdf0e10cSrcweir     Reference<rendering::XBitmap> mxBitmap;
123*cdf0e10cSrcweir     cppcanvas::CanvasSharedPtr mpCanvas;
124*cdf0e10cSrcweir     VirtualDevice* mpOutputDevice;
125*cdf0e10cSrcweir     EditEngine* mpEditEngine;
126*cdf0e10cSrcweir     SfxItemPool* mpEditEngineItemPool;
127*cdf0e10cSrcweir     Size maSize;
128*cdf0e10cSrcweir     Color maBackgroundColor;
129*cdf0e10cSrcweir     Color maTextColor;
130*cdf0e10cSrcweir     String msText;
131*cdf0e10cSrcweir     sal_Int32 mnTop;
132*cdf0e10cSrcweir     sal_Int32 mnTotalHeight;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     EditEngine * GetEditEngine (void);
135*cdf0e10cSrcweir     EditEngine* CreateEditEngine (void);
136*cdf0e10cSrcweir     void CheckTop (void);
137*cdf0e10cSrcweir };
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir //===== PresenterTextView =====================================================
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir PresenterTextView::PresenterTextView (const Reference<XComponentContext>& rxContext)
145*cdf0e10cSrcweir     : PresenterTextViewInterfaceBase(),
146*cdf0e10cSrcweir       mpImplementation(new Implementation())
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir     (void)rxContext;
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir PresenterTextView::~PresenterTextView (void)
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir void SAL_CALL PresenterTextView::disposing (void)
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     mpImplementation.reset();
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir //----- XInitialization -------------------------------------------------------
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir void SAL_CALL PresenterTextView::initialize (const Sequence<Any>& rArguments)
172*cdf0e10cSrcweir     throw (Exception, RuntimeException)
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir     ThrowIfDisposed();
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     if (rArguments.getLength() == 1)
177*cdf0e10cSrcweir     {
178*cdf0e10cSrcweir         try
179*cdf0e10cSrcweir         {
180*cdf0e10cSrcweir             Reference<rendering::XBitmapCanvas> xCanvas (rArguments[0], UNO_QUERY_THROW);
181*cdf0e10cSrcweir             if (xCanvas.is())
182*cdf0e10cSrcweir             {
183*cdf0e10cSrcweir                 mpImplementation->SetCanvas(
184*cdf0e10cSrcweir                     cppcanvas::VCLFactory::getInstance().createCanvas(xCanvas));
185*cdf0e10cSrcweir             }
186*cdf0e10cSrcweir         }
187*cdf0e10cSrcweir         catch (RuntimeException&)
188*cdf0e10cSrcweir         {
189*cdf0e10cSrcweir             throw;
190*cdf0e10cSrcweir         }
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir     else
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir         throw RuntimeException(
195*cdf0e10cSrcweir             OUString::createFromAscii("PresenterTextView: invalid number of arguments"),
196*cdf0e10cSrcweir                 static_cast<XWeak*>(this));
197*cdf0e10cSrcweir     }
198*cdf0e10cSrcweir }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir //-----------------------------------------------------------------------------
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir Any PresenterTextView::GetPropertyValue (const OUString& rsPropertyName)
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     ThrowIfDisposed();
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir     if (rsPropertyName == mpImplementation->msBitmapPropertyName)
210*cdf0e10cSrcweir     {
211*cdf0e10cSrcweir         return Any(mpImplementation->GetBitmap());
212*cdf0e10cSrcweir     }
213*cdf0e10cSrcweir     else if (rsPropertyName == mpImplementation->msTopPropertyName)
214*cdf0e10cSrcweir     {
215*cdf0e10cSrcweir         return Any(mpImplementation->GetTop());
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir     else if (rsPropertyName == mpImplementation->msTotalHeightPropertyName)
218*cdf0e10cSrcweir     {
219*cdf0e10cSrcweir         return Any(mpImplementation->GetTotalHeight());
220*cdf0e10cSrcweir     }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir     return Any();
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir Any PresenterTextView::SetPropertyValue (
229*cdf0e10cSrcweir     const ::rtl::OUString& rsPropertyName,
230*cdf0e10cSrcweir     const css::uno::Any& rValue)
231*cdf0e10cSrcweir {
232*cdf0e10cSrcweir     ThrowIfDisposed();
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     Any aOldValue;
235*cdf0e10cSrcweir     if (rsPropertyName == mpImplementation->msTextPropertyName)
236*cdf0e10cSrcweir     {
237*cdf0e10cSrcweir         OUString sText;
238*cdf0e10cSrcweir         if (rValue >>= sText)
239*cdf0e10cSrcweir             mpImplementation->SetText(sText);
240*cdf0e10cSrcweir     }
241*cdf0e10cSrcweir     else if (rsPropertyName == mpImplementation->msSizePropertyName)
242*cdf0e10cSrcweir     {
243*cdf0e10cSrcweir         awt::Size aSize;
244*cdf0e10cSrcweir         if (rValue >>= aSize)
245*cdf0e10cSrcweir             mpImplementation->SetSize(Size(aSize.Width,aSize.Height));
246*cdf0e10cSrcweir     }
247*cdf0e10cSrcweir     else if (rsPropertyName == mpImplementation->msBackgroundColorPropertyName)
248*cdf0e10cSrcweir     {
249*cdf0e10cSrcweir         util::Color aColor = util::Color();
250*cdf0e10cSrcweir         if (rValue >>= aColor)
251*cdf0e10cSrcweir             mpImplementation->SetBackgroundColor(Color(aColor));
252*cdf0e10cSrcweir     }
253*cdf0e10cSrcweir     else if (rsPropertyName == mpImplementation->msTextColorPropertyName)
254*cdf0e10cSrcweir     {
255*cdf0e10cSrcweir         util::Color aColor = util::Color();
256*cdf0e10cSrcweir         if (rValue >>= aColor)
257*cdf0e10cSrcweir             mpImplementation->SetTextColor(Color(aColor));
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir     else if (rsPropertyName == mpImplementation->msFontDescriptorPropertyName)
260*cdf0e10cSrcweir     {
261*cdf0e10cSrcweir         awt::FontDescriptor aFontDescriptor;
262*cdf0e10cSrcweir         if (rValue >>= aFontDescriptor)
263*cdf0e10cSrcweir             mpImplementation->SetFontDescriptor(aFontDescriptor);
264*cdf0e10cSrcweir     }
265*cdf0e10cSrcweir     else if (rsPropertyName == mpImplementation->msTopPropertyName)
266*cdf0e10cSrcweir     {
267*cdf0e10cSrcweir         sal_Int32 nTop = 0;
268*cdf0e10cSrcweir         if (rValue >>= nTop)
269*cdf0e10cSrcweir             mpImplementation->SetTop(nTop);
270*cdf0e10cSrcweir     }
271*cdf0e10cSrcweir     else if (rsPropertyName == mpImplementation->msTopRelativePropertyName)
272*cdf0e10cSrcweir     {
273*cdf0e10cSrcweir         OUString sDistance;
274*cdf0e10cSrcweir         if (rValue >>= sDistance)
275*cdf0e10cSrcweir             mpImplementation->SetTop(
276*cdf0e10cSrcweir                 mpImplementation->GetTop()
277*cdf0e10cSrcweir                     + mpImplementation->ParseDistance(sDistance));
278*cdf0e10cSrcweir     }
279*cdf0e10cSrcweir     return aOldValue;
280*cdf0e10cSrcweir }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir void PresenterTextView::ThrowIfDisposed (void)
286*cdf0e10cSrcweir     throw (::com::sun::star::lang::DisposedException)
287*cdf0e10cSrcweir {
288*cdf0e10cSrcweir 	if (PresenterTextViewInterfaceBase::rBHelper.bDisposed
289*cdf0e10cSrcweir         || PresenterTextViewInterfaceBase::rBHelper.bInDispose
290*cdf0e10cSrcweir         || mpImplementation.get()==NULL)
291*cdf0e10cSrcweir 	{
292*cdf0e10cSrcweir         throw lang::DisposedException (
293*cdf0e10cSrcweir             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
294*cdf0e10cSrcweir                 "PresenterTextView object has already been disposed")),
295*cdf0e10cSrcweir             static_cast<uno::XWeak*>(this));
296*cdf0e10cSrcweir     }
297*cdf0e10cSrcweir }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir //===== PresenterTextView::Implementation =====================================
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir PresenterTextView::Implementation::Implementation (void)
305*cdf0e10cSrcweir     : msTextPropertyName(OUString::createFromAscii("Text")),
306*cdf0e10cSrcweir       msBitmapPropertyName(OUString::createFromAscii("Bitmap")),
307*cdf0e10cSrcweir       msSizePropertyName(OUString::createFromAscii("Size")),
308*cdf0e10cSrcweir       msBackgroundColorPropertyName(OUString::createFromAscii("BackgroundColor")),
309*cdf0e10cSrcweir       msTextColorPropertyName(OUString::createFromAscii("TextColor")),
310*cdf0e10cSrcweir       msFontDescriptorPropertyName(OUString::createFromAscii("FontDescriptor")),
311*cdf0e10cSrcweir       msTopPropertyName(OUString::createFromAscii("Top")),
312*cdf0e10cSrcweir       msTopRelativePropertyName(OUString::createFromAscii("RelativeTop")),
313*cdf0e10cSrcweir       msTotalHeightPropertyName(OUString::createFromAscii("TotalHeight")),
314*cdf0e10cSrcweir       mxBitmap(),
315*cdf0e10cSrcweir       mpCanvas(),
316*cdf0e10cSrcweir       mpOutputDevice(new VirtualDevice(*Application::GetDefaultDevice(), 0, 0)),
317*cdf0e10cSrcweir       mpEditEngine(NULL),
318*cdf0e10cSrcweir       mpEditEngineItemPool(EditEngine::CreatePool()),
319*cdf0e10cSrcweir       maSize(100,100),
320*cdf0e10cSrcweir       maBackgroundColor(0xffffffff),
321*cdf0e10cSrcweir       maTextColor(0x00000000),
322*cdf0e10cSrcweir       msText(),
323*cdf0e10cSrcweir       mnTop(0),
324*cdf0e10cSrcweir       mnTotalHeight(-1)
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir 	mpOutputDevice->SetMapMode(MAP_PIXEL);
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     GetEditEngine();
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir PresenterTextView::Implementation::~Implementation (void)
335*cdf0e10cSrcweir {
336*cdf0e10cSrcweir     delete mpEditEngine;
337*cdf0e10cSrcweir     SfxItemPool::Free(mpEditEngineItemPool);
338*cdf0e10cSrcweir     delete mpOutputDevice;
339*cdf0e10cSrcweir }
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir EditEngine * PresenterTextView::Implementation::GetEditEngine (void)
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir     if (mpEditEngine == NULL)
347*cdf0e10cSrcweir         mpEditEngine = CreateEditEngine ();
348*cdf0e10cSrcweir     return mpEditEngine;
349*cdf0e10cSrcweir }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir EditEngine* PresenterTextView::Implementation::CreateEditEngine (void)
355*cdf0e10cSrcweir {
356*cdf0e10cSrcweir     EditEngine* pEditEngine = mpEditEngine;
357*cdf0e10cSrcweir 	if (pEditEngine == NULL)
358*cdf0e10cSrcweir 	{
359*cdf0e10cSrcweir         //
360*cdf0e10cSrcweir         // set fonts to be used
361*cdf0e10cSrcweir         //
362*cdf0e10cSrcweir         SvtLinguOptions aOpt;
363*cdf0e10cSrcweir         SvtLinguConfig().GetOptions( aOpt );
364*cdf0e10cSrcweir         //
365*cdf0e10cSrcweir         struct FontDta {
366*cdf0e10cSrcweir             sal_Int16       nFallbackLang;
367*cdf0e10cSrcweir             sal_Int16       nLang;
368*cdf0e10cSrcweir             sal_uInt16      nFontType;
369*cdf0e10cSrcweir             sal_uInt16      nFontInfoId;
370*cdf0e10cSrcweir             } aTable[3] =
371*cdf0e10cSrcweir         {
372*cdf0e10cSrcweir             // info to get western font to be used
373*cdf0e10cSrcweir             {   LANGUAGE_ENGLISH_US,    LANGUAGE_NONE,
374*cdf0e10cSrcweir                 DEFAULTFONT_SERIF,      EE_CHAR_FONTINFO },
375*cdf0e10cSrcweir             // info to get CJK font to be used
376*cdf0e10cSrcweir             {   LANGUAGE_JAPANESE,      LANGUAGE_NONE,
377*cdf0e10cSrcweir                 DEFAULTFONT_CJK_TEXT,   EE_CHAR_FONTINFO_CJK },
378*cdf0e10cSrcweir             // info to get CTL font to be used
379*cdf0e10cSrcweir             {   LANGUAGE_ARABIC_SAUDI_ARABIA,  LANGUAGE_NONE,
380*cdf0e10cSrcweir                 DEFAULTFONT_CTL_TEXT,   EE_CHAR_FONTINFO_CTL }
381*cdf0e10cSrcweir         };
382*cdf0e10cSrcweir         aTable[0].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN);
383*cdf0e10cSrcweir         aTable[1].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN);
384*cdf0e10cSrcweir         aTable[2].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
385*cdf0e10cSrcweir         //
386*cdf0e10cSrcweir         for (int i = 0;  i < 3;  ++i)
387*cdf0e10cSrcweir         {
388*cdf0e10cSrcweir             const FontDta &rFntDta = aTable[i];
389*cdf0e10cSrcweir             LanguageType nLang = (LANGUAGE_NONE == rFntDta.nLang) ?
390*cdf0e10cSrcweir                 rFntDta.nFallbackLang : rFntDta.nLang;
391*cdf0e10cSrcweir             Font aFont = Application::GetDefaultDevice()->GetDefaultFont(
392*cdf0e10cSrcweir                 rFntDta.nFontType, nLang, DEFAULTFONT_FLAGS_ONLYONE);
393*cdf0e10cSrcweir             mpEditEngineItemPool->SetPoolDefaultItem(
394*cdf0e10cSrcweir                 SvxFontItem(
395*cdf0e10cSrcweir                     aFont.GetFamily(),
396*cdf0e10cSrcweir                     aFont.GetName(),
397*cdf0e10cSrcweir                     aFont.GetStyleName(),
398*cdf0e10cSrcweir                     aFont.GetPitch(),
399*cdf0e10cSrcweir                     aFont.GetCharSet(),
400*cdf0e10cSrcweir                     rFntDta.nFontInfoId));
401*cdf0e10cSrcweir         }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 		pEditEngine = new EditEngine (mpEditEngineItemPool);
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 		pEditEngine->EnableUndo (sal_True);
407*cdf0e10cSrcweir 		pEditEngine->SetDefTab (sal_uInt16(
408*cdf0e10cSrcweir 			Application::GetDefaultDevice()->GetTextWidth(
409*cdf0e10cSrcweir                 UniString::CreateFromAscii("XXXX"))));
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 		pEditEngine->SetControlWord(
412*cdf0e10cSrcweir 				(pEditEngine->GetControlWord()
413*cdf0e10cSrcweir                     | EE_CNTRL_AUTOINDENTING) &
414*cdf0e10cSrcweir 				(~EE_CNTRL_UNDOATTRIBS) &
415*cdf0e10cSrcweir 				(~EE_CNTRL_PASTESPECIAL));
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 		pEditEngine->SetWordDelimiters (
418*cdf0e10cSrcweir             UniString::CreateFromAscii(" .=+-*/(){}[];\""));
419*cdf0e10cSrcweir 		pEditEngine->SetRefMapMode (MAP_PIXEL);
420*cdf0e10cSrcweir 		pEditEngine->SetPaperSize (Size(800, 0));
421*cdf0e10cSrcweir 		pEditEngine->EraseVirtualDevice();
422*cdf0e10cSrcweir 		pEditEngine->ClearModifyFlag();
423*cdf0e10cSrcweir 	}
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 	return pEditEngine;
426*cdf0e10cSrcweir }
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir void PresenterTextView::Implementation::SetCanvas (const cppcanvas::CanvasSharedPtr& rpCanvas)
432*cdf0e10cSrcweir {
433*cdf0e10cSrcweir     mpCanvas = rpCanvas;
434*cdf0e10cSrcweir     mxBitmap = NULL;
435*cdf0e10cSrcweir }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir void PresenterTextView::Implementation::SetSize (const Size aSize)
441*cdf0e10cSrcweir {
442*cdf0e10cSrcweir     DBG_ASSERT(mpEditEngine!=NULL, "EditEngine missing");
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir     maSize = aSize;
445*cdf0e10cSrcweir     mpEditEngine->SetPaperSize(maSize);
446*cdf0e10cSrcweir     mnTotalHeight = -1;
447*cdf0e10cSrcweir     mxBitmap = NULL;
448*cdf0e10cSrcweir }
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir void PresenterTextView::Implementation::SetBackgroundColor (const Color aColor)
454*cdf0e10cSrcweir {
455*cdf0e10cSrcweir     maBackgroundColor = aColor;
456*cdf0e10cSrcweir     mxBitmap = NULL;
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir     DBG_ASSERT(mpEditEngine!=NULL, "EditEngine missing");
459*cdf0e10cSrcweir     DBG_ASSERT(mpEditEngineItemPool!=NULL, "EditEngineItemPool missing");
460*cdf0e10cSrcweir     mpEditEngine->SetBackgroundColor(aColor);
461*cdf0e10cSrcweir     mpEditEngine->EnableAutoColor(sal_False);
462*cdf0e10cSrcweir     mpEditEngine->ForceAutoColor(sal_False);
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir void PresenterTextView::Implementation::SetTextColor (const Color aColor)
469*cdf0e10cSrcweir {
470*cdf0e10cSrcweir     maTextColor = aColor;
471*cdf0e10cSrcweir     mxBitmap = NULL;
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir     DBG_ASSERT(mpEditEngineItemPool!=NULL, "EditEngineItemPool missing");
474*cdf0e10cSrcweir     mpEditEngineItemPool->SetPoolDefaultItem(SvxColorItem(aColor, EE_CHAR_COLOR));
475*cdf0e10cSrcweir }
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir void PresenterTextView::Implementation::SetFontDescriptor (
481*cdf0e10cSrcweir     const awt::FontDescriptor& rFontDescriptor)
482*cdf0e10cSrcweir {
483*cdf0e10cSrcweir     mxBitmap = NULL;
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir     DBG_ASSERT(mpEditEngineItemPool!=NULL, "EditEngineItemPool missing");
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir     const sal_Int32 nFontHeight = rFontDescriptor.Height;
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir     SvxFontHeightItem aFontHeight(
490*cdf0e10cSrcweir         Application::GetDefaultDevice()->LogicToPixel(
491*cdf0e10cSrcweir             Size(0, nFontHeight), MapMode (MAP_POINT)).Height(),
492*cdf0e10cSrcweir         100,
493*cdf0e10cSrcweir         EE_CHAR_FONTHEIGHT);
494*cdf0e10cSrcweir     mpEditEngineItemPool->SetPoolDefaultItem( aFontHeight);
495*cdf0e10cSrcweir     aFontHeight.SetWhich (EE_CHAR_FONTHEIGHT_CJK);
496*cdf0e10cSrcweir     mpEditEngineItemPool->SetPoolDefaultItem( aFontHeight);
497*cdf0e10cSrcweir     aFontHeight.SetWhich (EE_CHAR_FONTHEIGHT_CTL);
498*cdf0e10cSrcweir     mpEditEngineItemPool->SetPoolDefaultItem( aFontHeight);
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir     SvxFontItem aSvxFontItem (EE_CHAR_FONTINFO);
501*cdf0e10cSrcweir     aSvxFontItem.SetFamilyName( rFontDescriptor.Name );
502*cdf0e10cSrcweir     mpEditEngineItemPool->SetPoolDefaultItem(aSvxFontItem);
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir     mnTotalHeight = -1;
505*cdf0e10cSrcweir     mxBitmap = NULL;
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir     CheckTop();
508*cdf0e10cSrcweir     mnTotalHeight = -1;
509*cdf0e10cSrcweir }
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir sal_Int32 PresenterTextView::Implementation::GetTop (void) const
515*cdf0e10cSrcweir {
516*cdf0e10cSrcweir     return mnTop;
517*cdf0e10cSrcweir }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir void PresenterTextView::Implementation::SetTop (const sal_Int32 nTop)
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir     if (nTop == mnTop)
525*cdf0e10cSrcweir         return;
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir     mnTop = nTop;
528*cdf0e10cSrcweir     mxBitmap = NULL;
529*cdf0e10cSrcweir     CheckTop();
530*cdf0e10cSrcweir }
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir void PresenterTextView::Implementation::SetText (const OUString& rText)
536*cdf0e10cSrcweir {
537*cdf0e10cSrcweir     DBG_ASSERT(mpEditEngine!=NULL, "EditEngine missing");
538*cdf0e10cSrcweir     msText = rText;
539*cdf0e10cSrcweir     mpEditEngine->SetPaperSize(maSize);
540*cdf0e10cSrcweir     mnTotalHeight = -1;
541*cdf0e10cSrcweir     mxBitmap = NULL;
542*cdf0e10cSrcweir }
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir sal_Int32 PresenterTextView::Implementation::ParseDistance (const OUString& rsDistance) const
548*cdf0e10cSrcweir {
549*cdf0e10cSrcweir     DBG_ASSERT(mpEditEngine!=NULL, "EditEngine missing");
550*cdf0e10cSrcweir     sal_Int32 nDistance (0);
551*cdf0e10cSrcweir     if (rsDistance.endsWithAsciiL("px", 2))
552*cdf0e10cSrcweir     {
553*cdf0e10cSrcweir         nDistance = rsDistance.copy(0,rsDistance.getLength()-2).toInt32();
554*cdf0e10cSrcweir     }
555*cdf0e10cSrcweir     else if (rsDistance.endsWithAsciiL("l", 1))
556*cdf0e10cSrcweir     {
557*cdf0e10cSrcweir         const sal_Int32 nLines (rsDistance.copy(0,rsDistance.getLength()-1).toInt32());
558*cdf0e10cSrcweir         // Take the height of the first line as the height of every line.
559*cdf0e10cSrcweir         const sal_uInt32 nFirstLineHeight (mpEditEngine->GetLineHeight(0,0));
560*cdf0e10cSrcweir         nDistance = nFirstLineHeight * nLines;
561*cdf0e10cSrcweir     }
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir     return nDistance;
564*cdf0e10cSrcweir }
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir Reference<rendering::XBitmap> PresenterTextView::Implementation::GetBitmap (void)
570*cdf0e10cSrcweir {
571*cdf0e10cSrcweir     DBG_ASSERT(mpEditEngine!=NULL, "EditEngine missing");
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir     if ( ! mxBitmap.is())
574*cdf0e10cSrcweir     {
575*cdf0e10cSrcweir         if (mpOutputDevice != NULL)
576*cdf0e10cSrcweir             delete mpOutputDevice;
577*cdf0e10cSrcweir         mpOutputDevice = new VirtualDevice(*Application::GetDefaultDevice(), 0, 0);
578*cdf0e10cSrcweir         mpOutputDevice->SetMapMode(MAP_PIXEL);
579*cdf0e10cSrcweir         mpOutputDevice->SetOutputSizePixel(maSize, sal_True);
580*cdf0e10cSrcweir         mpOutputDevice->SetLineColor();
581*cdf0e10cSrcweir         mpOutputDevice->SetFillColor();
582*cdf0e10cSrcweir         mpOutputDevice->SetBackground(Wallpaper());
583*cdf0e10cSrcweir         mpOutputDevice->Erase();
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir         MapMode aMapMode (mpOutputDevice->GetMapMode());
586*cdf0e10cSrcweir         aMapMode.SetOrigin(Point(0,0));
587*cdf0e10cSrcweir         mpOutputDevice->SetMapMode(aMapMode);
588*cdf0e10cSrcweir         const Rectangle aWindowBox (Point(0,0), maSize);
589*cdf0e10cSrcweir         mpOutputDevice->DrawRect(aWindowBox);
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir         mpEditEngine->Clear();
592*cdf0e10cSrcweir         mpEditEngine->SetText(msText);
593*cdf0e10cSrcweir         mpEditEngine->SetPaperSize(maSize);
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir         mpEditEngine->Draw(mpOutputDevice, aWindowBox, Point(0,mnTop));
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir         const BitmapEx aBitmap (mpOutputDevice->GetBitmapEx(Point(0,0), maSize));
598*cdf0e10cSrcweir         mxBitmap = cppcanvas::VCLFactory::getInstance().createBitmap(
599*cdf0e10cSrcweir             mpCanvas,
600*cdf0e10cSrcweir             aBitmap
601*cdf0e10cSrcweir             )->getUNOBitmap();
602*cdf0e10cSrcweir     }
603*cdf0e10cSrcweir     return mxBitmap;
604*cdf0e10cSrcweir }
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir sal_Int32 PresenterTextView::Implementation::GetTotalHeight (void)
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir     DBG_ASSERT(mpEditEngine!=NULL, "EditEngine missing");
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir     if (mnTotalHeight < 0)
614*cdf0e10cSrcweir     {
615*cdf0e10cSrcweir         if ( ! mxBitmap.is())
616*cdf0e10cSrcweir             GetBitmap();
617*cdf0e10cSrcweir         mnTotalHeight = mpEditEngine->GetTextHeight();
618*cdf0e10cSrcweir     }
619*cdf0e10cSrcweir     return mnTotalHeight;
620*cdf0e10cSrcweir }
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir void PresenterTextView::Implementation::CheckTop (void)
626*cdf0e10cSrcweir {
627*cdf0e10cSrcweir     DBG_ASSERT(mpEditEngine!=NULL, "EditEngine missing");
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir     if (mnTotalHeight < 0)
630*cdf0e10cSrcweir         mnTotalHeight = mpEditEngine->GetTextHeight();
631*cdf0e10cSrcweir     if (mpEditEngine!=NULL && mnTop >= mnTotalHeight)
632*cdf0e10cSrcweir         mnTop = mnTotalHeight - mpEditEngine->GetLineHeight(0,0);
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir     if (mnTotalHeight < maSize.Height())
635*cdf0e10cSrcweir         mnTop = 0;
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir     if (mnTotalHeight - mnTop < maSize.Height())
638*cdf0e10cSrcweir         mnTop = mnTotalHeight - maSize.Height();
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir     if (mnTop < 0)
641*cdf0e10cSrcweir         mnTop = 0;
642*cdf0e10cSrcweir }
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir } } // end of namespace ::sd::presenter
646