xref: /AOO41X/main/chart2/source/controller/main/DrawCommandDispatch.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 
31 #include "DrawCommandDispatch.hxx"
32 #include "DrawCommandDispatch.hrc"
33 #include "ChartController.hxx"
34 #include "DrawViewWrapper.hxx"
35 #include "chartview/DrawModelWrapper.hxx"
36 #include "macros.hxx"
37 
38 #include <vos/mutex.hxx>
39 #include <vcl/svapp.hxx>
40 #include <svl/itempool.hxx>
41 #include <editeng/adjitem.hxx>
42 #include <svx/dialogs.hrc>
43 #include <svx/dialmgr.hxx>
44 #include <svx/fmmodel.hxx>
45 #include <svx/gallery.hxx>
46 #include <svx/svdoashp.hxx>
47 #include <svx/svdocapt.hxx>
48 #include <svx/svdopath.hxx>
49 #include <svx/svdpage.hxx>
50 #include <svx/unoapi.hxx>
51 #include <svx/xlnedit.hxx>
52 #include <svx/xlnedwit.hxx>
53 #include <svx/xlnwtit.hxx>
54 #include <svx/xtable.hxx>
55 #include <basegfx/polygon/b2dpolygon.hxx>
56 
57 #include <boost/bind.hpp>
58 
59 using namespace ::com::sun::star;
60 using namespace ::com::sun::star::frame;
61 
62 using ::com::sun::star::uno::Reference;
63 using ::com::sun::star::uno::Sequence;
64 
65 
66 //.............................................................................
67 namespace
68 {
69 //.............................................................................
70 
71     // comparing two PropertyValue instances
72     struct PropertyValueCompare : public ::std::binary_function< beans::PropertyValue, ::rtl::OUString, bool >
73     {
74 	    bool operator() ( const beans::PropertyValue& rPropValue, const ::rtl::OUString& rName ) const
75 	    {
76 		    return rPropValue.Name.equals( rName );
77 	    }
78         bool operator() ( const ::rtl::OUString& rName, const beans::PropertyValue& rPropValue ) const
79 	    {
80 		    return rName.equals( rPropValue.Name );
81 	    }
82     };
83 
84 //.............................................................................
85 } // anonymous namespace
86 //.............................................................................
87 
88 
89 //.............................................................................
90 namespace chart
91 {
92 //.............................................................................
93 
94 DrawCommandDispatch::DrawCommandDispatch( const Reference< uno::XComponentContext >& rxContext,
95     ChartController* pController )
96     :FeatureCommandDispatchBase( rxContext )
97     ,m_pChartController( pController )
98 {
99 }
100 
101 DrawCommandDispatch::~DrawCommandDispatch()
102 {
103 }
104 
105 void DrawCommandDispatch::initialize()
106 {
107     FeatureCommandDispatchBase::initialize();
108 }
109 
110 bool DrawCommandDispatch::isFeatureSupported( const ::rtl::OUString& rCommandURL )
111 {
112     sal_uInt16 nFeatureId = 0;
113     ::rtl::OUString aBaseCommand;
114     ::rtl::OUString aCustomShapeType;
115     return parseCommandURL( rCommandURL, &nFeatureId, &aBaseCommand, &aCustomShapeType );
116 }
117 
118 ::basegfx::B2DPolyPolygon getPolygon( sal_uInt16 nResId, SdrModel& rModel )
119 {
120     ::basegfx::B2DPolyPolygon aReturn;
121     XLineEndList* pLineEndList = rModel.GetLineEndList();
122     if ( pLineEndList )
123     {
124         String aName( SVX_RES( nResId ) );
125         long nCount = pLineEndList->Count();
126         for ( long nIndex = 0; nIndex < nCount; ++nIndex )
127         {
128             XLineEndEntry* pEntry = pLineEndList->GetLineEnd( nIndex );
129             if ( pEntry->GetName() == aName )
130             {
131 				aReturn = pEntry->GetLineEnd();
132 				break;
133 			}
134 		}
135 	}
136 	return aReturn;
137 }
138 
139 void DrawCommandDispatch::setAttributes( SdrObject* pObj )
140 {
141     if ( m_pChartController )
142     {
143         DrawModelWrapper* pDrawModelWrapper = m_pChartController->GetDrawModelWrapper();
144         DrawViewWrapper* pDrawViewWrapper = m_pChartController->GetDrawViewWrapper();
145         if ( pDrawModelWrapper && pDrawViewWrapper && pDrawViewWrapper->GetCurrentObjIdentifier() == OBJ_CUSTOMSHAPE )
146         {
147             sal_Bool bAttributesAppliedFromGallery = sal_False;
148             if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
149             {
150                 ::std::vector< ::rtl::OUString > aObjList;
151                 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
152                 {
153                     for ( sal_uInt16 i = 0; i < aObjList.size(); ++i )
154                     {
155                         if ( aObjList[ i ].equalsIgnoreAsciiCase( m_aCustomShapeType ) )
156                         {
157                             FmFormModel aModel;
158                             SfxItemPool& rPool = aModel.GetItemPool();
159                             rPool.FreezeIdRanges();
160                             if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aModel ) )
161                             {
162                                 const SdrObject* pSourceObj = aModel.GetPage( 0 )->GetObj( 0 );
163                                 if ( pSourceObj )
164                                 {
165                                     const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
166                                     SfxItemSet aDest( pObj->GetModel()->GetItemPool(),          // ranges from SdrAttrObj
167                                         SDRATTR_START, SDRATTR_SHADOW_LAST,
168                                         SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
169                                         SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
170                                         // Graphic Attributes
171                                         SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
172                                         // 3d Properties
173                                         SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
174                                         // CustomShape properties
175                                         SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
176                                         // range from SdrTextObj
177                                         EE_ITEMS_START, EE_ITEMS_END,
178                                         // end
179                                         0, 0);
180                                     aDest.Set( rSource );
181                                     pObj->SetMergedItemSet( aDest );
182                                     sal_Int32 nAngle = pSourceObj->GetRotateAngle();
183                                     if ( nAngle )
184                                     {
185                                         double a = nAngle * F_PI18000;
186                                         pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
187                                     }
188                                     bAttributesAppliedFromGallery = sal_True;
189                                 }
190                             }
191                             break;
192                         }
193                     }
194                 }
195             }
196             if ( !bAttributesAppliedFromGallery )
197             {
198                 pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, 0 ) );
199                 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
200                 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
201                 pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
202                 ( dynamic_cast< SdrObjCustomShape* >( pObj ) )->MergeDefaultAttributes( &m_aCustomShapeType );
203             }
204         }
205     }
206 }
207 
208 void DrawCommandDispatch::setLineEnds( SfxItemSet& rAttr )
209 {
210     if ( m_nFeatureId == COMMAND_ID_LINE_ARROW_END && m_pChartController )
211     {
212         DrawModelWrapper* pDrawModelWrapper = m_pChartController->GetDrawModelWrapper();
213         DrawViewWrapper* pDrawViewWrapper = m_pChartController->GetDrawViewWrapper();
214         if ( pDrawModelWrapper && pDrawViewWrapper )
215         {
216             ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, pDrawModelWrapper->getSdrModel() ) );
217             if ( !aArrow.count() )
218             {
219                 ::basegfx::B2DPolygon aNewArrow;
220                 aNewArrow.append( ::basegfx::B2DPoint( 10.0, 0.0 ) );
221                 aNewArrow.append( ::basegfx::B2DPoint( 0.0, 30.0) );
222                 aNewArrow.append( ::basegfx::B2DPoint( 20.0, 30.0 ) );
223                 aNewArrow.setClosed( true );
224                 aArrow.append( aNewArrow );
225             }
226 
227             SfxItemSet aSet( pDrawViewWrapper->GetModel()->GetItemPool() );
228             pDrawViewWrapper->GetAttributes( aSet );
229 
230             long nWidth = 300; // (1/100th mm)
231             if ( aSet.GetItemState( XATTR_LINEWIDTH ) != SFX_ITEM_DONTCARE )
232             {
233                 long nValue = ( ( const XLineWidthItem& ) aSet.Get( XATTR_LINEWIDTH ) ).GetValue();
234                 if ( nValue > 0 )
235                 {
236                     nWidth = nValue * 3;
237                 }
238             }
239 
240             rAttr.Put( XLineEndItem( SVX_RESSTR( RID_SVXSTR_ARROW ), aArrow ) );
241             rAttr.Put( XLineEndWidthItem( nWidth ) );
242         }
243     }
244 }
245 
246 // WeakComponentImplHelperBase
247 void DrawCommandDispatch::disposing()
248 {
249 }
250 
251 // XEventListener
252 void DrawCommandDispatch::disposing( const lang::EventObject& /* Source */ )
253     throw (uno::RuntimeException)
254 {
255 }
256 
257 FeatureState DrawCommandDispatch::getState( const ::rtl::OUString& rCommand )
258 {
259     FeatureState aReturn;
260     aReturn.bEnabled = false;
261     aReturn.aState <<= false;
262 
263     sal_uInt16 nFeatureId = 0;
264     ::rtl::OUString aBaseCommand;
265     ::rtl::OUString aCustomShapeType;
266     if ( parseCommandURL( rCommand, &nFeatureId, &aBaseCommand, &aCustomShapeType ) )
267     {
268         switch ( nFeatureId )
269         {
270             case COMMAND_ID_OBJECT_SELECT:
271             case COMMAND_ID_DRAW_LINE:
272             case COMMAND_ID_LINE_ARROW_END:
273             case COMMAND_ID_DRAW_RECT:
274             case COMMAND_ID_DRAW_ELLIPSE:
275             case COMMAND_ID_DRAW_FREELINE_NOFILL:
276             case COMMAND_ID_DRAW_TEXT:
277             case COMMAND_ID_DRAW_CAPTION:
278             case COMMAND_ID_DRAWTBX_CS_BASIC:
279             case COMMAND_ID_DRAWTBX_CS_SYMBOL:
280             case COMMAND_ID_DRAWTBX_CS_ARROW:
281             case COMMAND_ID_DRAWTBX_CS_FLOWCHART:
282             case COMMAND_ID_DRAWTBX_CS_CALLOUT:
283             case COMMAND_ID_DRAWTBX_CS_STAR:
284                 {
285                     aReturn.bEnabled = true;
286                     aReturn.aState <<= false;
287                 }
288                 break;
289             default:
290                 {
291                     aReturn.bEnabled = false;
292                     aReturn.aState <<= false;
293                 }
294                 break;
295         }
296     }
297 
298     return aReturn;
299 }
300 
301 void DrawCommandDispatch::execute( const ::rtl::OUString& rCommand, const Sequence< beans::PropertyValue>& rArgs )
302 {
303     (void)rArgs;
304 
305     ChartDrawMode eDrawMode = CHARTDRAW_SELECT;
306     SdrObjKind eKind = OBJ_NONE;
307     bool bCreate = false;
308 
309     sal_uInt16 nFeatureId = 0;
310     ::rtl::OUString aBaseCommand;
311     ::rtl::OUString aCustomShapeType;
312     if ( parseCommandURL( rCommand, &nFeatureId, &aBaseCommand, &aCustomShapeType ) )
313     {
314         m_nFeatureId = nFeatureId;
315         m_aCustomShapeType = aCustomShapeType;
316 
317         switch ( nFeatureId )
318         {
319             case COMMAND_ID_OBJECT_SELECT:
320                 {
321                     eDrawMode = CHARTDRAW_SELECT;
322                     eKind = OBJ_NONE;
323                 }
324                 break;
325             case COMMAND_ID_DRAW_LINE:
326             case COMMAND_ID_LINE_ARROW_END:
327                 {
328                     eDrawMode = CHARTDRAW_INSERT;
329                     eKind = OBJ_LINE;
330                 }
331                 break;
332             case COMMAND_ID_DRAW_RECT:
333                 {
334                     eDrawMode = CHARTDRAW_INSERT;
335                     eKind = OBJ_RECT;
336                 }
337                 break;
338             case COMMAND_ID_DRAW_ELLIPSE:
339                 {
340                     eDrawMode = CHARTDRAW_INSERT;
341                     eKind = OBJ_CIRC;
342                 }
343                 break;
344             case COMMAND_ID_DRAW_FREELINE_NOFILL:
345                 {
346                     eDrawMode = CHARTDRAW_INSERT;
347                     eKind = OBJ_FREELINE;
348                 }
349                 break;
350             case COMMAND_ID_DRAW_TEXT:
351                 {
352                     eDrawMode = CHARTDRAW_INSERT;
353                     eKind = OBJ_TEXT;
354                     bCreate = true;
355                 }
356                 break;
357             case COMMAND_ID_DRAW_CAPTION:
358                 {
359                     eDrawMode = CHARTDRAW_INSERT;
360                     eKind = OBJ_CAPTION;
361                 }
362                 break;
363             case COMMAND_ID_DRAWTBX_CS_BASIC:
364             case COMMAND_ID_DRAWTBX_CS_SYMBOL:
365             case COMMAND_ID_DRAWTBX_CS_ARROW:
366             case COMMAND_ID_DRAWTBX_CS_FLOWCHART:
367             case COMMAND_ID_DRAWTBX_CS_CALLOUT:
368             case COMMAND_ID_DRAWTBX_CS_STAR:
369                 {
370                     eDrawMode = CHARTDRAW_INSERT;
371                     eKind = OBJ_CUSTOMSHAPE;
372                 }
373                 break;
374             default:
375                 {
376                     eDrawMode = CHARTDRAW_SELECT;
377                     eKind = OBJ_NONE;
378                 }
379                 break;
380         }
381 
382         if ( m_pChartController )
383         {
384             DrawViewWrapper* pDrawViewWrapper = m_pChartController->GetDrawViewWrapper();
385             if ( pDrawViewWrapper )
386             {
387                 ::vos::OGuard aGuard( Application::GetSolarMutex() );
388                 m_pChartController->setDrawMode( eDrawMode );
389                 setInsertObj( sal::static_int_cast< sal_uInt16 >( eKind ) );
390                 if ( bCreate )
391                 {
392                     pDrawViewWrapper->SetCreateMode();
393                 }
394 
395                 const ::rtl::OUString sKeyModifier( C2U( "KeyModifier" ) );
396                 const beans::PropertyValue* pIter = rArgs.getConstArray();
397                 const beans::PropertyValue* pEnd  = pIter + rArgs.getLength();
398                 const beans::PropertyValue* pKeyModifier = ::std::find_if(
399                     pIter, pEnd, ::std::bind2nd( PropertyValueCompare(), boost::cref( sKeyModifier ) ) );
400                 sal_Int16 nKeyModifier = 0;
401                 if ( pKeyModifier && ( pKeyModifier->Value >>= nKeyModifier ) && nKeyModifier == KEY_MOD1 )
402                 {
403                     if ( eDrawMode == CHARTDRAW_INSERT )
404                     {
405                         SdrObject* pObj = createDefaultObject( nFeatureId );
406                         if ( pObj )
407                         {
408                             SdrPageView* pPageView = pDrawViewWrapper->GetSdrPageView();
409                             pDrawViewWrapper->InsertObjectAtView( pObj, *pPageView );
410                             Reference< drawing::XShape > xShape( pObj->getUnoShape(), uno::UNO_QUERY );
411                             if ( xShape.is() )
412                             {
413                                 m_pChartController->m_aSelection.setSelection( xShape );
414                                 m_pChartController->m_aSelection.applySelection( pDrawViewWrapper );
415                             }
416                             if ( nFeatureId == SID_DRAW_TEXT )
417                             {
418                                 m_pChartController->StartTextEdit();
419                             }
420                         }
421                     }
422                 }
423             }
424         }
425     }
426 }
427 
428 void DrawCommandDispatch::describeSupportedFeatures()
429 {
430     implDescribeSupportedFeature( ".uno:SelectObject",      COMMAND_ID_OBJECT_SELECT,           CommandGroup::INSERT );
431     implDescribeSupportedFeature( ".uno:Line",              COMMAND_ID_DRAW_LINE,               CommandGroup::INSERT );
432     implDescribeSupportedFeature( ".uno:LineArrowEnd",      COMMAND_ID_LINE_ARROW_END,          CommandGroup::INSERT );
433     implDescribeSupportedFeature( ".uno:Rect",              COMMAND_ID_DRAW_RECT,               CommandGroup::INSERT );
434     implDescribeSupportedFeature( ".uno:Ellipse",           COMMAND_ID_DRAW_ELLIPSE,            CommandGroup::INSERT );
435     implDescribeSupportedFeature( ".uno:Freeline_Unfilled", COMMAND_ID_DRAW_FREELINE_NOFILL,    CommandGroup::INSERT );
436     implDescribeSupportedFeature( ".uno:DrawText",          COMMAND_ID_DRAW_TEXT,               CommandGroup::INSERT );
437     implDescribeSupportedFeature( ".uno:DrawCaption",       COMMAND_ID_DRAW_CAPTION,            CommandGroup::INSERT );
438     implDescribeSupportedFeature( ".uno:BasicShapes",       COMMAND_ID_DRAWTBX_CS_BASIC,        CommandGroup::INSERT );
439     implDescribeSupportedFeature( ".uno:SymbolShapes",      COMMAND_ID_DRAWTBX_CS_SYMBOL,       CommandGroup::INSERT );
440     implDescribeSupportedFeature( ".uno:ArrowShapes",       COMMAND_ID_DRAWTBX_CS_ARROW,        CommandGroup::INSERT );
441     implDescribeSupportedFeature( ".uno:FlowChartShapes",   COMMAND_ID_DRAWTBX_CS_FLOWCHART,    CommandGroup::INSERT );
442     implDescribeSupportedFeature( ".uno:CalloutShapes",     COMMAND_ID_DRAWTBX_CS_CALLOUT,      CommandGroup::INSERT );
443     implDescribeSupportedFeature( ".uno:StarShapes",        COMMAND_ID_DRAWTBX_CS_STAR,         CommandGroup::INSERT );
444 }
445 
446 void DrawCommandDispatch::setInsertObj( sal_uInt16 eObj )
447 {
448     DrawViewWrapper* pDrawViewWrapper = ( m_pChartController ? m_pChartController->GetDrawViewWrapper() : NULL );
449     if ( pDrawViewWrapper )
450     {
451         pDrawViewWrapper->SetCurrentObj( eObj /*, Inventor */);
452     }
453 }
454 
455 SdrObject* DrawCommandDispatch::createDefaultObject( const sal_uInt16 nID )
456 {
457     SdrObject* pObj = NULL;
458     DrawViewWrapper* pDrawViewWrapper = ( m_pChartController ? m_pChartController->GetDrawViewWrapper() : NULL );
459     DrawModelWrapper* pDrawModelWrapper = ( m_pChartController ? m_pChartController->GetDrawModelWrapper() : NULL );
460 
461     if ( pDrawViewWrapper && pDrawModelWrapper )
462     {
463         Reference< drawing::XDrawPage > xDrawPage( pDrawModelWrapper->getMainDrawPage() );
464         SdrPage* pPage = GetSdrPageFromXDrawPage( xDrawPage );
465         if ( pPage )
466         {
467             ::vos::OGuard aGuard( Application::GetSolarMutex() );
468             pObj = SdrObjFactory::MakeNewObject( pDrawViewWrapper->GetCurrentObjInventor(),
469                 pDrawViewWrapper->GetCurrentObjIdentifier(), pPage );
470             if ( pObj )
471             {
472                 long nDefaultObjectSizeWidth = 4000;
473                 long nDefaultObjectSizeHeight = 2500;
474                 Size aObjectSize( nDefaultObjectSizeWidth, nDefaultObjectSizeHeight );
475                 Rectangle aPageRect( Rectangle( Point( 0, 0 ), pPage->GetSize() ) );
476                 Point aObjectPos = aPageRect.Center();
477                 aObjectPos.X() -= aObjectSize.Width() / 2;
478                 aObjectPos.Y() -= aObjectSize.Height() / 2;
479                 Rectangle aRect( aObjectPos, aObjectSize );
480 
481                 switch ( nID )
482                 {
483                     case COMMAND_ID_DRAW_LINE:
484                     case COMMAND_ID_LINE_ARROW_END:
485                         {
486                             if ( pObj->ISA( SdrPathObj ) )
487                             {
488                                 Point aStart = aRect.TopLeft();
489                                 Point aEnd = aRect.BottomRight();
490                                 sal_Int32 nYMiddle( ( aRect.Top() + aRect.Bottom() ) / 2 );
491                                 basegfx::B2DPolygon aPoly;
492                                 aPoly.append( basegfx::B2DPoint( aStart.X(), nYMiddle ) );
493                                 aPoly.append( basegfx::B2DPoint( aEnd.X(), nYMiddle ) );
494                                 ( dynamic_cast< SdrPathObj* >( pObj ) )->SetPathPoly( basegfx::B2DPolyPolygon( aPoly ) );
495                                 SfxItemSet aSet( pDrawModelWrapper->GetItemPool() );
496                                 setLineEnds( aSet );
497                                 pObj->SetMergedItemSet( aSet );
498                             }
499                         }
500                         break;
501                     case COMMAND_ID_DRAW_FREELINE_NOFILL:
502                         {
503                             if ( pObj->ISA( SdrPathObj ) )
504                             {
505                                 basegfx::B2DPolygon aInnerPoly;
506                                 aInnerPoly.append( basegfx::B2DPoint( aRect.Left(), aRect.Bottom() ) );
507                                 aInnerPoly.appendBezierSegment(
508                                     basegfx::B2DPoint( aRect.Left(), aRect.Top() ),
509                                     basegfx::B2DPoint( aRect.Center().X(), aRect.Top() ),
510                                     basegfx::B2DPoint( aRect.Center().X(), aRect.Center().Y() ) );
511                                 aInnerPoly.appendBezierSegment(
512                                     basegfx::B2DPoint( aRect.Center().X(), aRect.Bottom() ),
513                                     basegfx::B2DPoint( aRect.Right(), aRect.Bottom() ),
514                                     basegfx::B2DPoint( aRect.Right(), aRect.Top() ) );
515                                 basegfx::B2DPolyPolygon aPoly;
516                                 aPoly.append( aInnerPoly );
517                                 ( dynamic_cast< SdrPathObj* >( pObj ) )->SetPathPoly( aPoly );
518                             }
519                         }
520                         break;
521                     case COMMAND_ID_DRAW_TEXT:
522                     case COMMAND_ID_DRAW_TEXT_VERTICAL:
523                         {
524                             if ( pObj->ISA( SdrTextObj ) )
525                             {
526                                 SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
527                                 if ( pTextObj )
528                                 {
529                                     pTextObj->SetLogicRect( aRect );
530                                     sal_Bool bVertical = ( nID == SID_DRAW_TEXT_VERTICAL );
531                                     pTextObj->SetVerticalWriting( bVertical );
532                                     if ( bVertical )
533                                     {
534                                         SfxItemSet aSet( pDrawModelWrapper->GetItemPool() );
535                                         aSet.Put( SdrTextAutoGrowWidthItem( sal_True ) );
536                                         aSet.Put( SdrTextAutoGrowHeightItem( sal_False ) );
537                                         aSet.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_TOP ) );
538                                         aSet.Put( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_RIGHT ) );
539                                         pTextObj->SetMergedItemSet( aSet );
540                                     }
541                                 }
542                             }
543                         }
544                         break;
545                     case COMMAND_ID_DRAW_CAPTION:
546                     case COMMAND_ID_DRAW_CAPTION_VERTICAL:
547                         {
548                             if ( pObj->ISA( SdrCaptionObj ) )
549                             {
550                                 sal_Bool bIsVertical( SID_DRAW_CAPTION_VERTICAL == nID );
551                                 SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
552                                 if ( pTextObj )
553                                 {
554                                     pTextObj->SetVerticalWriting( bIsVertical );
555                                 }
556                                 if ( bIsVertical )
557                                 {
558                                     SfxItemSet aSet( pObj->GetMergedItemSet() );
559                                     aSet.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
560                                     aSet.Put( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_RIGHT ) );
561                                     pObj->SetMergedItemSet( aSet );
562                                 }
563                                 SdrCaptionObj* pCaptionObj = dynamic_cast< SdrCaptionObj* >( pObj );
564                                 if ( pCaptionObj )
565                                 {
566 					                pCaptionObj->SetLogicRect( aRect );
567 					                pCaptionObj->SetTailPos(
568                                         aRect.TopLeft() - Point( aRect.GetWidth() / 2, aRect.GetHeight() / 2 ) );
569                                 }
570                             }
571                         }
572                         break;
573                     default:
574                         {
575                             pObj->SetLogicRect( aRect );
576                             SfxItemSet aSet( pDrawModelWrapper->GetItemPool() );
577                             setAttributes( pObj );
578                             pObj->SetMergedItemSet( aSet );
579                         }
580                         break;
581                 }
582             }
583         }
584     }
585 
586     return pObj;
587 }
588 
589 bool DrawCommandDispatch::parseCommandURL( const ::rtl::OUString& rCommandURL, sal_uInt16* pnFeatureId,
590     ::rtl::OUString* pBaseCommand, ::rtl::OUString* pCustomShapeType )
591 {
592     bool bFound = true;
593     sal_uInt16 nFeatureId = 0;
594     ::rtl::OUString aBaseCommand;
595     ::rtl::OUString aType;
596 
597     sal_Int32 nIndex = 1;
598     ::rtl::OUString aToken = rCommandURL.getToken( 0, '.', nIndex );
599     if ( nIndex == -1 || !aToken.getLength() )
600     {
601         aBaseCommand = rCommandURL;
602         SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( aBaseCommand );
603         if ( aIter != m_aSupportedFeatures.end() )
604         {
605             nFeatureId = aIter->second.nFeatureId;
606 
607             switch ( nFeatureId )
608             {
609                 case COMMAND_ID_DRAWTBX_CS_BASIC:
610                     {
611                         aType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "diamond" ) );
612                     }
613                     break;
614                 case COMMAND_ID_DRAWTBX_CS_SYMBOL:
615                     {
616                         aType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "smiley" ) );
617                     }
618                     break;
619                 case COMMAND_ID_DRAWTBX_CS_ARROW:
620                     {
621                         aType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "left-right-arrow" ) );
622                     }
623                     break;
624                 case COMMAND_ID_DRAWTBX_CS_FLOWCHART:
625                     {
626                         aType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "flowchart-internal-storage" ) );
627                     }
628                     break;
629                 case COMMAND_ID_DRAWTBX_CS_CALLOUT:
630                     {
631                         aType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "round-rectangular-callout" ) );
632                     }
633                     break;
634                 case COMMAND_ID_DRAWTBX_CS_STAR:
635                     {
636                         aType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "star5" ) );
637                     }
638                     break;
639                 default:
640                     {
641                     }
642                     break;
643             }
644         }
645         else
646         {
647             bFound = false;
648         }
649     }
650     else
651     {
652         aBaseCommand = rCommandURL.copy( 0, nIndex - 1 );
653         SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( aBaseCommand );
654         if ( aIter != m_aSupportedFeatures.end() )
655         {
656             nFeatureId = aIter->second.nFeatureId;
657             aType = rCommandURL.getToken( 0, '.', nIndex );
658         }
659         else
660         {
661             bFound = false;
662         }
663     }
664 
665     *pnFeatureId = nFeatureId;
666     *pBaseCommand = aBaseCommand;
667     *pCustomShapeType = aType;
668 
669     return bFound;
670 }
671 
672 //.............................................................................
673 } //  namespace chart
674 //.............................................................................
675