1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewstat.cxx,v $
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_sw.hxx"
33 #include <hintids.hxx>
34 #include <com/sun/star/linguistic2/XThesaurus.hpp>
35 #include <com/sun/star/uno/Sequence.hxx>
36 #include <svtools/aeitem.hxx>
37 #include <svtools/whiter.hxx>
38 #include <svtools/cjkoptions.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <sfx2/objitem.hxx>
42 #include <svtools/imageitm.hxx>
43 #include <svtools/languageoptions.hxx>
44 #include <svx/protitem.hxx>
45 #include <svx/linkmgr.hxx>
46 #include <svx/langitem.hxx>
47 #include <svx/brshitem.hxx>
48 #include <svx/htmlmode.hxx>
49 #include <svx/unolingu.hxx>
50 #include <sfx2/msgpool.hxx>
51 #include <swmodule.hxx>
53 #include <sfx2/dispatch.hxx>
54 #include <sfx2/app.hxx>
63 #include <viewopt.hxx>
64 #include <tablemgr.hxx>
65 #include <pagedesc.hxx>
69 #include <globdoc.hxx>
70 #include <svtools/stritem.hxx>
71 #include <svtools/moduleoptions.hxx>
72 #include <svtools/visitem.hxx>
78 #include <IDocumentRedlineAccess.hxx>
80 using namespace ::com::sun::star
;
82 /*--------------------------------------------------------------------
84 --------------------------------------------------------------------*/
86 void SwView::GetState(SfxItemSet
&rSet
)
88 SfxWhichIter
aIter(rSet
);
89 sal_uInt16 nWhich
= aIter
.FirstWhich();
90 sal_uInt16 eFrmType
= FRMTYPE_NONE
;
91 int bGetFrmType
= sal_False
;
92 sal_Bool bWeb
= 0 != PTR_CAST(SwWebView
, this);
98 case FN_EDIT_LINK_DLG
:
99 if( !pWrtShell
->GetLinkManager().GetLinks().Count() )
100 rSet
.DisableItem(nWhich
);
101 else if( pWrtShell
->IsSelFrmMode() &&
102 pWrtShell
->IsSelObjProtected(FLYPROTECT_CONTENT
))
103 rSet
.DisableItem(nWhich
);
106 case FN_INSERT_CAPTION
:
108 // Captions gibt's fuer Grafiken, OLE-Objekte, Rahmen und Tabellen
110 eFrmType
= pWrtShell
->GetFrmType(0,sal_True
), bGetFrmType
= sal_True
;
111 if (! ( ((eFrmType
& FRMTYPE_FLY_ANY
) && nSelectionType
!= nsSelectionType::SEL_DRW_TXT
)||
112 nSelectionType
& nsSelectionType::SEL_TBL
||
113 nSelectionType
& nsSelectionType::SEL_DRW
) )
114 rSet
.DisableItem(nWhich
);
115 else if((pWrtShell
->IsObjSelected()||pWrtShell
->IsFrmSelected()) &&
116 (pWrtShell
->IsSelObjProtected( FLYPROTECT_PARENT
)||
117 pWrtShell
->IsSelObjProtected( FLYPROTECT_CONTENT
)))
118 rSet
.DisableItem(nWhich
);
119 else if( pWrtShell
->IsTableMode() )
120 rSet
.DisableItem(nWhich
);
124 case FN_EDIT_FOOTNOTE
:
126 if( !pWrtShell
->GetCurFtn() )
127 rSet
.DisableItem(nWhich
);
131 case FN_CHANGE_PAGENUM
:
133 sal_uInt16 nType
= pWrtShell
->GetFrmType(0,sal_True
);
134 if( ( FRMTYPE_FLY_ANY
| FRMTYPE_HEADER
| FRMTYPE_FOOTER
|
135 FRMTYPE_FOOTNOTE
| FRMTYPE_DRAWOBJ
) & nType
)
136 rSet
.DisableItem(nWhich
);
138 rSet
.Put(SfxUInt16Item(nWhich
, pWrtShell
->GetPageOffset()));
142 case SID_PRINTDOCDIRECT
:
143 GetSlotState( nWhich
, SfxViewShell::GetInterface(), &rSet
);
146 case SID_ATTR_PAGE_SIZE
:
147 case SID_ATTR_PAGE_PAPERBIN
:
149 case FN_PARAM_FTN_INFO
:
151 const sal_uInt16 nCurIdx
= pWrtShell
->GetCurPageDesc();
152 const SwPageDesc
& rDesc
= pWrtShell
->GetPageDesc( nCurIdx
);
153 ::PageDescToItemSet( rDesc
, rSet
);
159 const sal_uInt16 nCurIdx
= pWrtShell
->GetCurPageDesc();
160 const SwPageDesc
& rDesc
= pWrtShell
->GetPageDesc( nCurIdx
);
161 const SwFrmFmt
& rMaster
= rDesc
.GetMaster();
162 const SvxBrushItem
& rBrush
= (const SvxBrushItem
&)
163 rMaster
.GetFmtAttr(RES_BACKGROUND
, sal_True
);
167 case SID_CLEARHISTORY
:
169 rSet
.Put(SfxBoolItem(nWhich
, pWrtShell
->GetUndoIds() != UNDO_EMPTY
));
174 //JP 21.07.98: Bug 53429 - die muss noch nicht vorhanden sein
175 // also lasse sie mal anlegen:
179 const SfxPoolItem
* pState
= pShell
->GetSlotState(SID_UNDO
);
183 rSet
.DisableItem(nWhich
);
188 SfxImageItem
aImgItem(nWhich
, bWeb
? SwView::nWebInsertCtrlState
: SwView::nInsertCtrlState
);
189 SfxSlotPool
& rPool
= SfxSlotPool::GetSlotPool( GetViewFrame() );
190 const SfxSlot
* pSlot
= rPool
.GetSlot( aImgItem
.GetValue() );
191 if(pSlot
&& pSlot
->IsMode( SFX_SLOT_IMAGEROTATION
))
193 if(pWrtShell
->IsInVerticalText())
194 aImgItem
.SetRotation(2700);
195 if(pWrtShell
->IsInRightToLeftText())
196 aImgItem
.SetMirrored(TRUE
);
201 case FN_INSERT_OBJ_CTRL
:
203 rSet
.DisableItem(nWhich
);
206 SfxImageItem
aImgItem(nWhich
, SwView::nInsertObjectCtrlState
);
207 SfxSlotPool
& rPool
= SfxSlotPool::GetSlotPool( GetViewFrame() );
208 const SfxSlot
* pSlot
= rPool
.GetSlot( aImgItem
.GetValue() );
209 if(pSlot
&& pSlot
->IsMode( SFX_SLOT_IMAGEROTATION
))
211 if(pWrtShell
->IsInVerticalText())
212 aImgItem
.SetRotation(2700);
213 if(pWrtShell
->IsInRightToLeftText())
214 aImgItem
.SetMirrored(TRUE
);
220 if(!pWrtShell
->GetTOXCount())
221 rSet
.DisableItem(nWhich
);
223 case FN_EDIT_CURRENT_TOX
:
224 case FN_UPDATE_CUR_TOX
:
226 const SwTOXBase
* pBase
= 0;
227 if(0 == (pBase
= pWrtShell
->GetCurTOX()) ||
228 (FN_EDIT_CURRENT_TOX
== nWhich
&& pBase
->IsTOXBaseInReadonly()))
229 rSet
.DisableItem(nWhich
);
232 case SID_TWAIN_SELECT
:
233 case SID_TWAIN_TRANSFER
:
234 #if defined WIN || defined WNT || defined UNX
236 if(!SW_MOD()->GetScannerManager().is())
237 rSet
.DisableItem(nWhich
);
241 case RES_PARATR_TABSTOP
:
242 case SID_ATTR_DEFTABSTOP
:
244 const SvxTabStopItem
& rDefTabs
=
245 (const SvxTabStopItem
&)pWrtShell
->
246 GetDefault(RES_PARATR_TABSTOP
);
247 rSet
.Put( SfxUInt16Item( nWhich
,
248 (sal_uInt16
)::GetTabDist(rDefTabs
)));
251 case SID_ATTR_LANGUAGE
:
253 rSet
.Put((const SvxLanguageItem
&)
254 pWrtShell
->GetDefault(RES_CHRATR_LANGUAGE
), SID_ATTR_LANGUAGE
);
257 case RES_CHRATR_CJK_LANGUAGE
:
258 rSet
.Put((const SvxLanguageItem
&)
259 pWrtShell
->GetDefault(RES_CHRATR_CJK_LANGUAGE
), RES_CHRATR_CJK_LANGUAGE
);
261 case RES_CHRATR_CTL_LANGUAGE
:
262 rSet
.Put((const SvxLanguageItem
&)
263 pWrtShell
->GetDefault(RES_CHRATR_CTL_LANGUAGE
), RES_CHRATR_CTL_LANGUAGE
);
265 case FN_HYPHENATE_OPT_DLG
:
267 sal_Bool bCheck
= sal_False
;
269 if (pWrtShell
->GetSelectionType() & (nsSelectionType::SEL_DRW_TXT
|nsSelectionType::SEL_DRW
))
270 bCheck
= IsDrawTextHyphenate();
271 rSet
.Put(SfxBoolItem(nWhich
, bCheck
));
275 rSet
.Put( SfxBoolItem( nWhich
, (pWrtShell
->GetRedlineMode() & nsRedlineMode_t::REDLINE_ON
) != 0 ) );
277 case FN_REDLINE_PROTECT
:
279 rSet
.Put( SfxBoolItem( nWhich
, pWrtShell
->getIDocumentRedlineAccess()->GetRedlinePassword().getLength() > 0 ) );
282 case FN_REDLINE_SHOW
:
284 sal_uInt16 nMask
= nsRedlineMode_t::REDLINE_SHOW_INSERT
| nsRedlineMode_t::REDLINE_SHOW_DELETE
;
285 rSet
.Put( SfxBoolItem( nWhich
,
286 (pWrtShell
->GetRedlineMode() & nMask
) == nMask
));
290 case SID_AVMEDIA_PLAYER
:
291 case FN_REDLINE_ACCEPT
:
293 SfxViewFrame
* pVFrame
= GetViewFrame();
294 if (pVFrame
->KnowsChildWindow(nWhich
))
295 rSet
.Put(SfxBoolItem( nWhich
, pVFrame
->HasChildWindow(nWhich
)));
297 rSet
.DisableItem(nWhich
);
300 case FN_REDLINE_ACCEPT_DIRECT
:
301 case FN_REDLINE_REJECT_DIRECT
:
303 SwContentAtPos
aCntntAtPos( SwContentAtPos::SW_REDLINE
);
304 Point aCrsrPos
= pWrtShell
->GetCrsrDocPos( sal_True
);
305 if( !pWrtShell
->GetContentAtPos( aCrsrPos
, aCntntAtPos
) )
306 rSet
.DisableItem( nWhich
);
309 case FN_THESAURUS_DLG
:
311 SwWrtShell
&rSh
= GetWrtShell();
312 if (2 <= rSh
.GetCrsrCnt()) // multi selection?
313 rSet
.DisableItem(nWhich
);
316 LanguageType nLang
= rSh
.GetCurLang();
318 // disable "Thesaurus" (menu entry and key shortcut) if the
319 // language is not supported (by default it is enabled)
320 uno::Reference
< linguistic2::XThesaurus
> xThes( ::GetThesaurus() );
321 if (!xThes
.is() || nLang
== LANGUAGE_NONE
||
322 !xThes
->hasLocale( SvxCreateLocale( nLang
) ))
323 rSet
.DisableItem(nWhich
);
327 case SID_HANGUL_HANJA_CONVERSION
:
328 case SID_CHINESE_CONVERSION
:
330 if (!SvtCJKOptions().IsAnyEnabled())
332 GetViewFrame()->GetBindings().SetVisibleState( nWhich
, sal_False
);
333 rSet
.DisableItem(nWhich
);
336 GetViewFrame()->GetBindings().SetVisibleState( nWhich
, sal_True
);
339 case SID_MAIL_SCROLLBODY_PAGEDOWN
:
341 const long nBottom
= pWrtShell
->GetDocSize().Height() + DOCUMENTBORDER
;
342 const long nAct
= GetVisArea().Bottom();
343 rSet
.Put(SfxBoolItem(SID_MAIL_SCROLLBODY_PAGEDOWN
, nAct
< nBottom
));
347 case SID_DOCUMENT_COMPARE
:
348 case SID_DOCUMENT_MERGE
:
349 if( GetDocShell()->IsA( SwGlobalDocShell::StaticType() ) ||
350 // pWrtShell->IsAnySectionInDoc( sal_True, sal_True, sal_True )||
351 (SID_DOCUMENT_MERGE
== nWhich
&& pWrtShell
->getIDocumentRedlineAccess()->GetRedlinePassword().getLength()))
352 rSet
.DisableItem(nWhich
);
354 case SID_VIEW_DATA_SOURCE_BROWSER
:
355 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE
) )
356 rSet
.Put( SfxVisibilityItem( nWhich
, sal_False
) );
358 rSet
.Put( SfxBoolItem( nWhich
, GetViewFrame()->HasChildWindow( SID_BROWSER
) ) );
360 case SID_READONLY_MODE
:
361 rSet
.Put(SfxBoolItem(nWhich
,
362 pWrtShell
->HasReadonlySel()||GetDocShell()->IsReadOnly()));
364 case SID_IMAGE_ORIENTATION
:
366 SfxImageItem
aImageItem(nWhich
);
367 if(pWrtShell
->IsInVerticalText())
368 aImageItem
.SetRotation( 2700 );
369 if(pWrtShell
->IsInRightToLeftText())
370 aImageItem
.SetMirrored( TRUE
);
371 rSet
.Put(aImageItem
);
374 case FN_INSERT_FIELD_DATA_ONLY
:
375 if(!bInMailMerge
&& !GetViewFrame()->HasChildWindow(nWhich
))
376 rSet
.DisableItem(nWhich
);
378 case FN_MAILMERGE_SENDMAIL_CHILDWINDOW
:
380 case FN_MAILMERGE_CHILDWINDOW
:
382 if(!GetMailMergeConfigItem())
383 rSet
.DisableItem(nWhich
);
386 case SID_ALIGN_ANY_LEFT
:
387 case SID_ALIGN_ANY_HCENTER
:
388 case SID_ALIGN_ANY_RIGHT
:
389 case SID_ALIGN_ANY_JUSTIFIED
:
390 case SID_ALIGN_ANY_TOP
:
391 case SID_ALIGN_ANY_VCENTER
:
392 case SID_ALIGN_ANY_BOTTOM
:
393 case SID_ALIGN_ANY_HDEFAULT
:
394 case SID_ALIGN_ANY_VDEFAULT
:
400 if( nSelectionType
& (nsSelectionType::SEL_DRW_TXT
|nsSelectionType::SEL_TXT
) )
404 case SID_ALIGN_ANY_LEFT
: nAlias
= SID_ATTR_PARA_ADJUST_LEFT
; break;
405 case SID_ALIGN_ANY_HCENTER
: nAlias
= SID_ATTR_PARA_ADJUST_CENTER
; break;
406 case SID_ALIGN_ANY_RIGHT
: nAlias
= SID_ATTR_PARA_ADJUST_RIGHT
; break;
407 case SID_ALIGN_ANY_JUSTIFIED
: nAlias
= SID_ATTR_PARA_ADJUST_BLOCK
; break;
408 case SID_ALIGN_ANY_TOP
: nAlias
= FN_TABLE_VERT_NONE
; break;
409 case SID_ALIGN_ANY_VCENTER
: nAlias
= FN_TABLE_VERT_CENTER
; break;
410 case SID_ALIGN_ANY_BOTTOM
: nAlias
= FN_TABLE_VERT_BOTTOM
; break;
413 else if(nSelectionType
& (nsSelectionType::SEL_DRW
))
415 //the draw shell cannot provide a status per item - only one for SID_OBJECT_ALIGN
416 if(nWhich
!= SID_ALIGN_ANY_JUSTIFIED
)
418 const SfxPoolItem
* pItem
= 0;
419 GetViewFrame()->GetDispatcher()->QueryState( SID_OBJECT_ALIGN
, pItem
);
428 case SID_ALIGN_ANY_LEFT
: nAlias
= SID_OBJECT_ALIGN_LEFT
; break;
429 case SID_ALIGN_ANY_HCENTER
: nAlias
= SID_OBJECT_ALIGN_CENTER
; break;
430 case SID_ALIGN_ANY_RIGHT
: nAlias
= SID_OBJECT_ALIGN_RIGHT
; break;
431 case SID_ALIGN_ANY_TOP
: nAlias
= SID_OBJECT_ALIGN_UP
; break;
432 case SID_ALIGN_ANY_VCENTER
: nAlias
= SID_OBJECT_ALIGN_MIDDLE
; break;
433 case SID_ALIGN_ANY_BOTTOM
: nAlias
= SID_OBJECT_ALIGN_DOWN
; break;
436 //these slots are either re-mapped to text or object alignment
437 const SfxPoolItem
* pState
= 0;
439 GetViewFrame()->GetDispatcher()->QueryState( nAlias
, pState
);
441 rSet
.Put(*pState
, nWhich
);
443 rSet
.DisableItem(nWhich
);
447 nWhich
= aIter
.NextWhich();
452 /*--------------------------------------------------------------------
454 --------------------------------------------------------------------*/
456 void SwView::GetDrawState(SfxItemSet
&rSet
)
458 SfxWhichIter
aIter(rSet
);
459 sal_Bool bWeb
= 0 != PTR_CAST(SwWebView
, this);
461 for( sal_uInt16 nWhich
= aIter
.FirstWhich(); nWhich
;
462 nWhich
= aIter
.NextWhich() )
465 case SID_INSERT_DRAW
:
467 rSet
.DisableItem( nWhich
);
470 SfxAllEnumItem
aEnum(SID_INSERT_DRAW
, nDrawSfxId
);
471 if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
473 aEnum
.DisableValue( SID_DRAW_CAPTION_VERTICAL
);
474 aEnum
.DisableValue( SID_DRAW_TEXT_VERTICAL
);
480 case SID_SHOW_HIDDEN
:
482 rSet
.DisableItem( nWhich
);
483 // rSet.Put( SfxBoolItem(nWhich,sal_True ));
486 case SID_DRAW_TEXT_MARQUEE
:
487 if (::GetHtmlMode(GetDocShell()) & HTMLMODE_SOME_STYLES
)
488 rSet
.Put( SfxBoolItem(nWhich
, nDrawSfxId
== nWhich
));
490 rSet
.DisableItem(nWhich
);
492 case SID_OBJECT_SELECT
:
493 rSet
.Put( SfxBoolItem(nWhich
, nDrawSfxId
== nWhich
||
494 nFormSfxId
== nWhich
));
497 case SID_FONTWORK_GALLERY_FLOATER
:
500 rSet
.DisableItem( nWhich
);
504 case SID_DRAWTBX_CS_BASIC
:
505 case SID_DRAWTBX_CS_SYMBOL
:
506 case SID_DRAWTBX_CS_ARROW
:
507 case SID_DRAWTBX_CS_FLOWCHART
:
508 case SID_DRAWTBX_CS_CALLOUT
:
509 case SID_DRAWTBX_CS_STAR
:
512 rSet
.DisableItem( nWhich
);
514 rSet
.Put(SfxStringItem(nWhich
, aCurrShapeEnumCommand
[ nWhich
- SID_DRAWTBX_CS_BASIC
] ));
521 /*--------------------------------------------------------------------
523 --------------------------------------------------------------------*/
525 sal_Bool
SwView::HasUIFeature( sal_uInt32 nFeature
)
527 sal_Bool bRet
= sal_False
;
530 case CHILDWIN_LABEL
: bRet
= pWrtShell
->IsLabelDoc(); break;
531 case CHILDWIN_MAILMERGE
: bRet
= 0 != GetMailMergeConfigItem(); break;