update dev300-m58
[ooovba.git] / sd / source / ui / view / drviewsf.cxx
blob8e1a0b55d2805fd899c177660fe394e5d8a31c3a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drviewsf.cxx,v $
10 * $Revision: 1.24 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "DrawViewShell.hxx"
35 #include <com/sun/star/form/FormButtonType.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
38 #ifndef _SVXIDS_HRC
39 #include <svx/svxids.hrc>
40 #endif
41 #ifndef _GLOBL3D_HXX
42 #include <svx/globl3d.hxx>
43 #endif
44 #include <svx/hlnkitem.hxx>
45 #include <svx/eeitem.hxx>
46 #ifndef _FLDITEM_HXX
47 #include <svx/flditem.hxx>
48 #endif
49 #include <sfx2/viewfrm.hxx>
50 #include <svtools/whiter.hxx>
51 #include <svtools/eitem.hxx>
52 #include <svtools/itempool.hxx>
53 #include <sfx2/tplpitem.hxx>
54 #ifndef _BINDING_HXX //autogen
55 #include <sfx2/bindings.hxx>
56 #endif
57 #include <sfx2/app.hxx>
58 #include <sfx2/templdlg.hxx>
59 #include <svx/xdef.hxx>
60 #include <svx/svddef.hxx>
61 #include <svx/fmglob.hxx>
62 #include <svx/svdouno.hxx>
63 #include <tools/urlobj.hxx>
64 #include <svx/fmshell.hxx>
65 #include <sfx2/topfrm.hxx>
66 #include <svtools/cjkoptions.hxx>
68 #ifndef SD_FRAME_VIEW
69 #include "FrameView.hxx"
70 #endif
71 #include "Outliner.hxx"
72 #include "app.hrc"
74 #include "app.hxx"
75 #include "stlsheet.hxx"
76 #include "drawview.hxx"
77 #include "drawdoc.hxx"
78 #include "Window.hxx"
79 #include "ViewShellBase.hxx"
80 #include "FormShellManager.hxx"
81 #include "cfgids.hxx"
82 #include "anminfo.hxx"
84 using ::rtl::OUString;
85 using namespace ::com::sun::star;
87 namespace sd {
89 /*************************************************************************
91 |* Status von Controller-SfxSlots setzen
93 \************************************************************************/
95 void DrawViewShell::GetCtrlState(SfxItemSet &rSet)
97 if (rSet.GetItemState(SID_RELOAD) != SFX_ITEM_UNKNOWN)
99 // "Letzte Version" vom SFx en/disablen lassen
100 GetViewFrame()->GetSlotState (SID_RELOAD, NULL, &rSet);
103 if (SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_HYPERLINK_GETLINK))
105 SvxHyperlinkItem aHLinkItem;
107 OutlinerView* pOLV = mpDrawView->GetTextEditOutlinerView();
109 if (pOLV)
111 bool bField = false;
112 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
113 if (pFieldItem)
115 ESelection aSel = pOLV->GetSelection();
116 if ( abs( aSel.nEndPos - aSel.nStartPos ) == 1 )
118 const SvxFieldData* pField = pFieldItem->GetField();
119 if (pField->ISA(SvxURLField))
121 aHLinkItem.SetName(((const SvxURLField*) pField)->GetRepresentation());
122 aHLinkItem.SetURL(((const SvxURLField*) pField)->GetURL());
123 aHLinkItem.SetTargetFrame(((const SvxURLField*) pField)->GetTargetFrame());
124 bField = true;
128 if (!bField)
130 // use selected text as name for urls
131 String sReturn = pOLV->GetSelected();
132 sReturn.Erase(255);
133 sReturn.EraseTrailingChars();
134 aHLinkItem.SetName(sReturn);
137 else
139 if (mpDrawView->GetMarkedObjectList().GetMarkCount() > 0)
141 bool bFound = false;
143 SdrObject* pMarkedObj = mpDrawView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
144 if( pMarkedObj && (FmFormInventor == pMarkedObj->GetObjInventor()) )
146 SdrUnoObj* pUnoCtrl = dynamic_cast< SdrUnoObj* >( pMarkedObj );
148 if(pUnoCtrl) try
150 uno::Reference< awt::XControlModel > xControlModel( pUnoCtrl->GetUnoControlModel(), uno::UNO_QUERY_THROW );
151 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
152 uno::Reference< beans::XPropertySetInfo > xPropInfo( xPropSet->getPropertySetInfo(), uno::UNO_QUERY_THROW );
154 form::FormButtonType eButtonType = form::FormButtonType_URL;
155 const OUString sButtonType( RTL_CONSTASCII_USTRINGPARAM( "ButtonType" ) );
156 if(xPropInfo->hasPropertyByName( sButtonType ) && (xPropSet->getPropertyValue( sButtonType ) >>= eButtonType ) )
158 OUString aString;
160 // Label
161 const OUString sLabel( RTL_CONSTASCII_USTRINGPARAM( "Label" ) );
162 if(xPropInfo->hasPropertyByName(sLabel))
164 if( xPropSet->getPropertyValue(sLabel) >>= aString )
165 aHLinkItem.SetName(String( aString ));
168 // URL
169 const OUString sTargetURL(RTL_CONSTASCII_USTRINGPARAM( "TargetURL" ));
170 if(xPropInfo->hasPropertyByName(sTargetURL))
172 if( xPropSet->getPropertyValue(sTargetURL) >>= aString )
173 aHLinkItem.SetURL(String( aString ));
176 // Target
177 const OUString sTargetFrame( RTL_CONSTASCII_USTRINGPARAM( "TargetFrame" ) );
178 if(xPropInfo->hasPropertyByName(sTargetFrame) )
180 if( xPropSet->getPropertyValue(sTargetFrame) >>= aString )
181 aHLinkItem.SetTargetFrame(String( aString ));
184 aHLinkItem.SetInsertMode(HLINK_BUTTON);
185 bFound = true;
188 catch( uno::Exception& )
193 // try interaction link
194 if( !bFound && pMarkedObj )
196 SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pMarkedObj);
197 if( pInfo && (pInfo->meClickAction == presentation::ClickAction_DOCUMENT) )
198 aHLinkItem.SetURL( pInfo->GetBookmark());
199 aHLinkItem.SetInsertMode(HLINK_BUTTON);
204 rSet.Put(aHLinkItem);
206 rSet.Put( SfxBoolItem( SID_READONLY_MODE, mbReadOnly ) );
208 // Ausgabequalitaet
209 if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_OUTPUT_QUALITY_COLOR ) ||
210 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_OUTPUT_QUALITY_GRAYSCALE ) ||
211 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_OUTPUT_QUALITY_BLACKWHITE ) ||
212 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_OUTPUT_QUALITY_CONTRAST ) )
214 const ULONG nMode = (sal_Int32)GetActiveWindow()->GetDrawMode();
215 rSet.Put( SfxBoolItem( SID_OUTPUT_QUALITY_COLOR, (BOOL)((ULONG)OUTPUT_DRAWMODE_COLOR == nMode) ) );
216 rSet.Put( SfxBoolItem( SID_OUTPUT_QUALITY_GRAYSCALE, (BOOL)((ULONG)OUTPUT_DRAWMODE_GRAYSCALE == nMode) ) );
217 rSet.Put( SfxBoolItem( SID_OUTPUT_QUALITY_BLACKWHITE, (BOOL)((ULONG)OUTPUT_DRAWMODE_BLACKWHITE == nMode) ) );
218 rSet.Put( SfxBoolItem( SID_OUTPUT_QUALITY_CONTRAST, (BOOL)((ULONG)OUTPUT_DRAWMODE_CONTRAST == nMode) ) );
221 if ( SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_MAIL_SCROLLBODY_PAGEDOWN) )
223 rSet.Put( SfxBoolItem( SID_MAIL_SCROLLBODY_PAGEDOWN, TRUE ) );
226 if ( SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_ATTR_YEAR2000) )
228 FmFormShell* pFormShell = GetViewShellBase().GetFormShellManager()->GetFormShell();
229 if (pFormShell != NULL)
231 UINT16 nState = 0;
232 if (pFormShell->GetY2KState(nState))
233 rSet.Put( SfxUInt16Item( SID_ATTR_YEAR2000, nState ) );
234 else
235 rSet.DisableItem( SID_ATTR_YEAR2000 );
239 if ( !GetView()->GetTextEditOutliner() )
241 SvtCJKOptions aCJKOptions;
242 if( !aCJKOptions.IsChangeCaseMapEnabled() )
244 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_HALFWIDTH, sal_False );
245 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_FULLWIDTH, sal_False );
246 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_HIRAGANA, sal_False );
247 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_KATAGANA, sal_False );
249 else
251 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_HALFWIDTH, sal_True );
252 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_FULLWIDTH, sal_True );
253 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_HIRAGANA, sal_True );
254 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_KATAGANA, sal_True );
257 rSet.DisableItem( SID_TRANSLITERATE_UPPER );
258 rSet.DisableItem( SID_TRANSLITERATE_LOWER );
259 rSet.DisableItem( SID_TRANSLITERATE_HALFWIDTH );
260 rSet.DisableItem( SID_TRANSLITERATE_FULLWIDTH );
261 rSet.DisableItem( SID_TRANSLITERATE_HIRAGANA );
262 rSet.DisableItem( SID_TRANSLITERATE_KATAGANA );
264 else
266 SvtCJKOptions aCJKOptions;
267 if( !aCJKOptions.IsChangeCaseMapEnabled() )
269 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_HALFWIDTH, sal_False );
270 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_FULLWIDTH, sal_False );
271 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_HIRAGANA, sal_False );
272 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_KATAGANA, sal_False );
273 rSet.DisableItem( SID_TRANSLITERATE_HALFWIDTH );
274 rSet.DisableItem( SID_TRANSLITERATE_FULLWIDTH );
275 rSet.DisableItem( SID_TRANSLITERATE_HIRAGANA );
276 rSet.DisableItem( SID_TRANSLITERATE_KATAGANA );
278 else
280 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_HALFWIDTH, sal_True );
281 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_FULLWIDTH, sal_True );
282 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_HIRAGANA, sal_True );
283 GetViewFrame()->GetBindings().SetVisibleState( SID_TRANSLITERATE_KATAGANA, sal_True );
289 /*************************************************************************
291 |* Status der Attribut-Items
293 \************************************************************************/
295 void DrawViewShell::GetAttrState( SfxItemSet& rSet )
297 SfxWhichIter aIter( rSet );
298 USHORT nWhich = aIter.FirstWhich();
300 BOOL bAttr = FALSE;
301 SfxAllItemSet aAllSet( *rSet.GetPool() );
303 while ( nWhich )
305 USHORT nSlotId = SfxItemPool::IsWhich(nWhich)
306 ? GetPool().GetSlotId(nWhich)
307 : nWhich;
308 switch ( nSlotId )
310 case SID_ATTR_FILL_STYLE:
311 case SID_ATTR_FILL_COLOR:
312 case SID_ATTR_FILL_GRADIENT:
313 case SID_ATTR_FILL_HATCH:
314 case SID_ATTR_FILL_BITMAP:
315 case SID_ATTR_FILL_SHADOW:
316 case SID_ATTR_LINE_STYLE:
317 case SID_ATTR_LINE_DASH:
318 case SID_ATTR_LINE_WIDTH:
319 case SID_ATTR_LINE_COLOR:
320 case SID_ATTR_TEXT_FITTOSIZE:
322 bAttr = TRUE;
324 break;
326 case SID_HYPHENATION:
328 SfxItemSet aAttrs( GetDoc()->GetPool() );
329 mpDrawView->GetAttributes( aAttrs );
330 if( aAttrs.GetItemState( EE_PARA_HYPHENATE ) >= SFX_ITEM_AVAILABLE )
332 BOOL bValue = ( (const SfxBoolItem&) aAttrs.Get( EE_PARA_HYPHENATE ) ).GetValue();
333 rSet.Put( SfxBoolItem( SID_HYPHENATION, bValue ) );
336 break;
338 case SID_STYLE_FAMILY2:
339 case SID_STYLE_FAMILY3:
340 case SID_STYLE_FAMILY5:
341 case SID_STYLE_APPLY: // StyleControl
343 SfxStyleSheet* pStyleSheet = mpDrawView->GetStyleSheet();
344 if( pStyleSheet )
346 if( nSlotId != SID_STYLE_APPLY && !mpDrawView->AreObjectsMarked() )
348 SfxTemplateItem aTmpItem( nWhich, String() );
349 aAllSet.Put( aTmpItem, aTmpItem.Which() );
351 else
353 if (pStyleSheet->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE)
354 pStyleSheet = ((SdStyleSheet*)pStyleSheet)->GetPseudoStyleSheet();
356 if( pStyleSheet )
358 SfxStyleFamily eFamily = pStyleSheet->GetFamily();
360 if ((eFamily == SD_STYLE_FAMILY_GRAPHICS && nSlotId == SID_STYLE_FAMILY2) ||
361 (eFamily == SD_STYLE_FAMILY_CELL && nSlotId == SID_STYLE_FAMILY3) ||
362 (eFamily == SD_STYLE_FAMILY_PSEUDO && nSlotId == SID_STYLE_FAMILY5))
364 SfxTemplateItem aTmpItem ( nWhich, pStyleSheet->GetName() );
365 aAllSet.Put( aTmpItem, aTmpItem.Which() );
367 else
369 SfxTemplateItem aTmpItem(nWhich, String());
370 aAllSet.Put(aTmpItem,aTmpItem.Which() );
375 else
376 { SfxTemplateItem aItem( nWhich, String() );
377 aAllSet.Put( aItem, aItem.Which() );
378 // rSet.DisableItem( nWhich );
381 break;
383 case SID_SET_DEFAULT:
385 if( !mpDrawView->GetMarkedObjectList().GetMarkCount() ||
386 ( !mpDrawView->IsTextEdit() && !mpDrawView->GetStyleSheet() )
388 rSet.DisableItem( nWhich );
390 break;
392 case SID_STYLE_WATERCAN:
394 ISfxTemplateCommon* pTemplateCommon = SFX_APP()->GetCurrentTemplateCommon(GetViewFrame()->GetBindings());
395 if (pTemplateCommon && pTemplateCommon->GetActualFamily() == SD_STYLE_FAMILY_PSEUDO)
396 rSet.Put(SfxBoolItem(nWhich,FALSE));
397 else
399 SfxBoolItem aItem(nWhich, SD_MOD()->GetWaterCan());
400 aAllSet.Put( aItem, aItem.Which());
403 break;
405 case SID_STYLE_NEW:
407 ISfxTemplateCommon* pTemplateCommon = SFX_APP()->GetCurrentTemplateCommon(GetViewFrame()->GetBindings());
408 if (pTemplateCommon && pTemplateCommon->GetActualFamily() == SD_STYLE_FAMILY_PSEUDO)
409 rSet.DisableItem(nWhich);
411 break;
413 case SID_STYLE_DRAGHIERARCHIE:
415 ISfxTemplateCommon* pTemplateCommon = SFX_APP()->GetCurrentTemplateCommon(GetViewFrame()->GetBindings());
416 if (pTemplateCommon && pTemplateCommon->GetActualFamily() == SD_STYLE_FAMILY_PSEUDO)
417 rSet.DisableItem(nWhich);
419 break;
421 case SID_STYLE_NEW_BY_EXAMPLE:
423 // PseudoStyleSheets koennen nicht 'by Example' erzeugt werden;
424 // normale StyleSheets brauchen dafuer ein selektiertes Objekt
425 ISfxTemplateCommon* pTemplCommon = SFX_APP()->GetCurrentTemplateCommon(GetViewFrame()->GetBindings());
426 if (pTemplCommon)
428 if (pTemplCommon->GetActualFamily() == SD_STYLE_FAMILY_PSEUDO)
430 rSet.DisableItem(nWhich);
432 else if (pTemplCommon->GetActualFamily() == SD_STYLE_FAMILY_GRAPHICS)
434 if (!mpDrawView->AreObjectsMarked())
436 rSet.DisableItem(nWhich);
440 // falls (noch) kein Gestalter da ist, muessen wir uns auf den
441 // View-Zustand zurueckziehen; eine aktuell eingestellte Familie
442 // kann nicht beruecksichtigt werden
443 else
445 if (!mpDrawView->AreObjectsMarked())
447 rSet.DisableItem(nWhich);
452 break;
454 case SID_STYLE_UPDATE_BY_EXAMPLE:
456 if (!mpDrawView->AreObjectsMarked())
458 rSet.DisableItem(nWhich);
461 break;
463 nWhich = aIter.NextWhich();
466 SfxItemSet* pSet = NULL;
468 if( bAttr )
470 pSet = new SfxItemSet( GetDoc()->GetPool() );
471 mpDrawView->GetAttributes( *pSet );
472 rSet.Put( *pSet, FALSE );
475 rSet.Put( aAllSet, FALSE );
477 // Flaechen und/oder Linienattribute wurden geaendert
478 if( bAttr && pSet )
480 // Wenn die View selektierte Objekte besitzt, muessen entspr. Items
481 // von SFX_ITEM_DEFAULT (_ON) auf SFX_ITEM_DISABLED geaendert werden
482 if( mpDrawView->AreObjectsMarked() )
484 SfxWhichIter aNewIter( *pSet, XATTR_LINE_FIRST, XATTR_FILL_LAST );
485 nWhich = aNewIter.FirstWhich();
486 while( nWhich )
488 if( SFX_ITEM_DEFAULT == pSet->GetItemState( nWhich ) )
490 rSet.ClearItem( nWhich );
491 rSet.DisableItem( nWhich );
493 nWhich = aNewIter.NextWhich();
496 delete pSet;
499 // const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
500 // ULONG nMarkCount = rMarkList.GetMarkCount();
501 // BOOL bDisabled = FALSE;
503 // for (ULONG i = 0;
504 // i < nMarkCount && !bDisabled && i < 50; i++)
505 // {
506 // SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
508 // if (pObj->GetObjInventor() == E3dInventor)
509 // {
510 // bDisabled = TRUE;
511 // rSet.ClearItem(SDRATTR_SHADOW);
512 // rSet.DisableItem(SDRATTR_SHADOW);
513 // }
514 // }
518 /*************************************************************************
520 |* Text der Selektion zurueckgeben
522 \************************************************************************/
524 String DrawViewShell::GetSelectionText(BOOL bCompleteWords)
526 String aStrSelection;
527 ::Outliner* pOl = mpDrawView->GetTextEditOutliner();
528 OutlinerView* pOlView = mpDrawView->GetTextEditOutlinerView();
530 if (pOl && pOlView)
532 if (bCompleteWords)
534 ESelection aSel = pOlView->GetSelection();
535 String aStrCurrentDelimiters = pOl->GetWordDelimiters();
537 pOl->SetWordDelimiters( String( RTL_CONSTASCII_USTRINGPARAM( " .,;\"'" )));
538 aStrSelection = pOl->GetWord( aSel.nEndPara, aSel.nEndPos );
539 pOl->SetWordDelimiters( aStrCurrentDelimiters );
541 else
543 aStrSelection = pOlView->GetSelected();
547 return (aStrSelection);
550 /*************************************************************************
552 |* Ist etwas selektiert?
554 \************************************************************************/
556 BOOL DrawViewShell::HasSelection(BOOL bText) const
558 BOOL bReturn = FALSE;
560 if (bText)
562 OutlinerView* pOlView = mpDrawView->GetTextEditOutlinerView();
564 if (pOlView && pOlView->GetSelected().Len() != 0)
566 bReturn = TRUE;
569 else if (mpDrawView->GetMarkedObjectList().GetMarkCount() != 0)
571 bReturn = TRUE;
574 return bReturn;
577 } // end of namespace sd