1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <hintids.hxx>
22 #include <com/sun/star/linguistic2/XThesaurus.hpp>
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <svl/aeitem.hxx>
25 #include <svl/whiter.hxx>
26 #include <svl/cjkoptions.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <sfx2/objitem.hxx>
30 #include <svl/imageitm.hxx>
31 #include <svl/languageoptions.hxx>
32 #include <editeng/protitem.hxx>
33 #include <sfx2/linkmgr.hxx>
34 #include <editeng/langitem.hxx>
35 #include <editeng/brushitem.hxx>
36 #include <sfx2/htmlmode.hxx>
37 #include <editeng/unolingu.hxx>
38 #include <sfx2/msgpool.hxx>
39 #include <swmodule.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/app.hxx>
47 #include <viewopt.hxx>
48 #include <tablemgr.hxx>
49 #include <pagedesc.hxx>
51 #include <globdoc.hxx>
52 #include <svl/stritem.hxx>
53 #include <unotools/moduleoptions.hxx>
54 #include <svl/visitem.hxx>
58 #include <IDocumentRedlineAccess.hxx>
61 using namespace ::com::sun::star
;
63 void SwView::GetState(SfxItemSet
&rSet
)
65 SfxWhichIter
aIter(rSet
);
66 sal_uInt16 nWhich
= aIter
.FirstWhich();
67 sal_uInt16 eFrmType
= FRMTYPE_NONE
;
68 int bGetFrmType
= sal_False
;
69 bool bWeb
= 0 != PTR_CAST(SwWebView
, this);
75 case FN_EDIT_LINK_DLG
:
76 if( m_pWrtShell
->GetLinkManager().GetLinks().empty() )
77 rSet
.DisableItem(nWhich
);
78 else if( m_pWrtShell
->IsSelFrmMode() &&
79 m_pWrtShell
->IsSelObjProtected(FLYPROTECT_CONTENT
))
80 rSet
.DisableItem(nWhich
);
83 case FN_INSERT_CAPTION
:
85 // Captions gibt's fuer Grafiken, OLE-Objekte, Rahmen und Tabellen
87 eFrmType
= m_pWrtShell
->GetFrmType(0,sal_True
), bGetFrmType
= sal_True
;
88 if (! ( ((eFrmType
& FRMTYPE_FLY_ANY
) && m_nSelectionType
!= nsSelectionType::SEL_DRW_TXT
)||
89 m_nSelectionType
& nsSelectionType::SEL_TBL
||
90 m_nSelectionType
& nsSelectionType::SEL_DRW
) )
91 rSet
.DisableItem(nWhich
);
92 else if((m_pWrtShell
->IsObjSelected()||m_pWrtShell
->IsFrmSelected()) &&
93 (m_pWrtShell
->IsSelObjProtected( FLYPROTECT_PARENT
)||
94 m_pWrtShell
->IsSelObjProtected( FLYPROTECT_CONTENT
)))
95 rSet
.DisableItem(nWhich
);
96 else if( m_pWrtShell
->IsTableMode() )
97 rSet
.DisableItem(nWhich
);
101 case FN_EDIT_FOOTNOTE
:
103 if( !m_pWrtShell
->GetCurFtn() )
104 rSet
.DisableItem(nWhich
);
108 case FN_CHANGE_PAGENUM
:
110 sal_uInt16 nType
= m_pWrtShell
->GetFrmType(0,sal_True
);
111 if( ( FRMTYPE_FLY_ANY
| FRMTYPE_HEADER
| FRMTYPE_FOOTER
|
112 FRMTYPE_FOOTNOTE
| FRMTYPE_DRAWOBJ
) & nType
)
113 rSet
.DisableItem(nWhich
);
115 rSet
.Put(SfxUInt16Item(nWhich
, m_pWrtShell
->GetPageOffset()));
119 case SID_PRINTDOCDIRECT
:
120 GetSlotState( nWhich
, SfxViewShell::GetInterface(), &rSet
);
123 case SID_ATTR_PAGE_SIZE
:
124 case SID_ATTR_PAGE_PAPERBIN
:
126 case FN_PARAM_FTN_INFO
:
128 const sal_uInt16 nCurIdx
= m_pWrtShell
->GetCurPageDesc();
129 const SwPageDesc
& rDesc
= m_pWrtShell
->GetPageDesc( nCurIdx
);
130 ::PageDescToItemSet( rDesc
, rSet
);
136 const sal_uInt16 nCurIdx
= m_pWrtShell
->GetCurPageDesc();
137 const SwPageDesc
& rDesc
= m_pWrtShell
->GetPageDesc( nCurIdx
);
138 const SwFrmFmt
& rMaster
= rDesc
.GetMaster();
139 const SvxBrushItem
& rBrush
= (const SvxBrushItem
&)
140 rMaster
.GetFmtAttr(RES_BACKGROUND
, sal_True
);
144 case SID_CLEARHISTORY
:
146 rSet
.Put(SfxBoolItem(nWhich
, m_pWrtShell
->GetLastUndoInfo(0, 0)));
151 // die muss noch nicht vorhanden sein
152 // also lasse sie mal anlegen:
156 const SfxPoolItem
* pState
= m_pShell
->GetSlotState(SID_UNDO
);
160 rSet
.DisableItem(nWhich
);
165 SfxImageItem
aImgItem(nWhich
, bWeb
? SwView::m_nWebInsertCtrlState
: SwView::m_nInsertCtrlState
);
166 SfxSlotPool
& rPool
= SfxSlotPool::GetSlotPool( GetViewFrame() );
167 const SfxSlot
* pSlot
= rPool
.GetSlot( aImgItem
.GetValue() );
168 if(pSlot
&& pSlot
->IsMode( SFX_SLOT_IMAGEROTATION
))
170 if(m_pWrtShell
->IsInVerticalText())
171 aImgItem
.SetRotation(2700);
172 if(m_pWrtShell
->IsInRightToLeftText())
173 aImgItem
.SetMirrored(sal_True
);
178 case FN_INSERT_OBJ_CTRL
:
180 rSet
.DisableItem(nWhich
);
183 SfxImageItem
aImgItem(nWhich
, SwView::m_nInsertObjectCtrlState
);
184 SfxSlotPool
& rPool
= SfxSlotPool::GetSlotPool( GetViewFrame() );
185 const SfxSlot
* pSlot
= rPool
.GetSlot( aImgItem
.GetValue() );
186 if(pSlot
&& pSlot
->IsMode( SFX_SLOT_IMAGEROTATION
))
188 if(m_pWrtShell
->IsInVerticalText())
189 aImgItem
.SetRotation(2700);
190 if(m_pWrtShell
->IsInRightToLeftText())
191 aImgItem
.SetMirrored(sal_True
);
197 if(!m_pWrtShell
->GetTOXCount())
198 rSet
.DisableItem(nWhich
);
200 case FN_EDIT_CURRENT_TOX
:
201 case FN_UPDATE_CUR_TOX
:
203 const SwTOXBase
* pBase
= 0;
204 if(0 == (pBase
= m_pWrtShell
->GetCurTOX()) ||
205 (FN_EDIT_CURRENT_TOX
== nWhich
&& pBase
->IsTOXBaseInReadonly()))
206 rSet
.DisableItem(nWhich
);
209 case SID_TWAIN_SELECT
:
210 case SID_TWAIN_TRANSFER
:
211 #if defined WNT || defined UNX
213 if(!SW_MOD()->GetScannerManager().is())
214 rSet
.DisableItem(nWhich
);
218 case RES_PARATR_TABSTOP
:
219 case SID_ATTR_DEFTABSTOP
:
221 const SvxTabStopItem
& rDefTabs
=
222 (const SvxTabStopItem
&)m_pWrtShell
->
223 GetDefault(RES_PARATR_TABSTOP
);
224 rSet
.Put( SfxUInt16Item( nWhich
,
225 (sal_uInt16
)::GetTabDist(rDefTabs
)));
228 case SID_ATTR_LANGUAGE
:
230 rSet
.Put((const SvxLanguageItem
&)
231 m_pWrtShell
->GetDefault(RES_CHRATR_LANGUAGE
), SID_ATTR_LANGUAGE
);
234 case RES_CHRATR_CJK_LANGUAGE
:
235 rSet
.Put((const SvxLanguageItem
&)
236 m_pWrtShell
->GetDefault(RES_CHRATR_CJK_LANGUAGE
), RES_CHRATR_CJK_LANGUAGE
);
238 case RES_CHRATR_CTL_LANGUAGE
:
239 rSet
.Put((const SvxLanguageItem
&)
240 m_pWrtShell
->GetDefault(RES_CHRATR_CTL_LANGUAGE
), RES_CHRATR_CTL_LANGUAGE
);
243 rSet
.Put( SfxBoolItem( nWhich
, GetDocShell()->IsChangeRecording() ) );
245 case FN_REDLINE_PROTECT
:
246 rSet
.Put( SfxBoolItem( nWhich
, GetDocShell()->HasChangeRecordProtection() ) );
248 case FN_REDLINE_SHOW
:
250 sal_uInt16 nMask
= nsRedlineMode_t::REDLINE_SHOW_INSERT
| nsRedlineMode_t::REDLINE_SHOW_DELETE
;
251 rSet
.Put( SfxBoolItem( nWhich
,
252 (m_pWrtShell
->GetRedlineMode() & nMask
) == nMask
));
256 case SID_AVMEDIA_PLAYER
:
257 case FN_REDLINE_ACCEPT
:
259 SfxViewFrame
* pVFrame
= GetViewFrame();
260 if (pVFrame
->KnowsChildWindow(nWhich
))
261 rSet
.Put(SfxBoolItem( nWhich
, pVFrame
->HasChildWindow(nWhich
)));
263 rSet
.DisableItem(nWhich
);
266 case FN_REDLINE_ACCEPT_DIRECT
:
267 case FN_REDLINE_REJECT_DIRECT
:
269 // If the selection/cursor start position isn't on a redline, disable
270 // accepting/rejecting changes.
271 SwDoc
*pDoc
= m_pWrtShell
->GetDoc();
272 SwPaM
*pCursor
= m_pWrtShell
->GetCrsr();
273 if (0 == pDoc
->GetRedline(*pCursor
->Start(), 0))
274 rSet
.DisableItem(nWhich
);
278 case FN_REDLINE_NEXT_CHANGE
:
279 case FN_REDLINE_PREV_CHANGE
:
281 // Enable change navigation if we have any redlines. Ideally we should disable
282 // "Next Change" if we're at or past the last change, and similarly for
284 if (0 == m_pWrtShell
->GetRedlineCount())
285 rSet
.DisableItem(nWhich
);
291 SwWrtShell
&rSh
= GetWrtShell();
292 if (2 <= rSh
.GetCrsrCnt()) // multi selection?
293 rSet
.DisableItem(nWhich
);
296 LanguageType nLang
= rSh
.GetCurLang();
298 // disable "Thesaurus" (menu entry and key shortcut) if the
299 // language is not supported (by default it is enabled)
300 uno::Reference
< linguistic2::XThesaurus
> xThes( ::GetThesaurus() );
301 if (!xThes
.is() || nLang
== LANGUAGE_NONE
||
302 !xThes
->hasLocale( LanguageTag( nLang
).getLocale() ))
303 rSet
.DisableItem(nWhich
);
307 case SID_HANGUL_HANJA_CONVERSION
:
308 case SID_CHINESE_CONVERSION
:
310 if (!SvtCJKOptions().IsAnyEnabled())
312 GetViewFrame()->GetBindings().SetVisibleState( nWhich
, sal_False
);
313 rSet
.DisableItem(nWhich
);
316 GetViewFrame()->GetBindings().SetVisibleState( nWhich
, sal_True
);
319 case SID_MAIL_SCROLLBODY_PAGEDOWN
:
321 const long nBottom
= m_pWrtShell
->GetDocSize().Height() + DOCUMENTBORDER
;
322 const long nAct
= GetVisArea().Bottom();
323 rSet
.Put(SfxBoolItem(SID_MAIL_SCROLLBODY_PAGEDOWN
, nAct
< nBottom
));
327 case SID_DOCUMENT_COMPARE
:
328 case SID_DOCUMENT_MERGE
:
329 if( GetDocShell()->IsA( SwGlobalDocShell::StaticType() ) ||
330 (SID_DOCUMENT_MERGE
== nWhich
&& m_pWrtShell
->getIDocumentRedlineAccess()->GetRedlinePassword().getLength()))
331 rSet
.DisableItem(nWhich
);
333 case SID_VIEW_DATA_SOURCE_BROWSER
:
334 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE
) )
335 rSet
.Put( SfxVisibilityItem( nWhich
, sal_False
) );
337 rSet
.Put( SfxBoolItem( nWhich
, GetViewFrame()->HasChildWindow( SID_BROWSER
) ) );
339 case SID_READONLY_MODE
:
340 rSet
.Put(SfxBoolItem(nWhich
,
341 m_pWrtShell
->HasReadonlySel()||GetDocShell()->IsReadOnly()));
343 case SID_IMAGE_ORIENTATION
:
345 SfxImageItem
aImageItem(nWhich
);
346 if(m_pWrtShell
->IsInVerticalText())
347 aImageItem
.SetRotation( 2700 );
348 if(m_pWrtShell
->IsInRightToLeftText())
349 aImageItem
.SetMirrored( sal_True
);
350 rSet
.Put(aImageItem
);
353 case FN_INSERT_FIELD_DATA_ONLY
:
354 if(!m_bInMailMerge
&& !GetViewFrame()->HasChildWindow(nWhich
))
355 rSet
.DisableItem(nWhich
);
357 case FN_MAILMERGE_SENDMAIL_CHILDWINDOW
:
359 case FN_MAILMERGE_CHILDWINDOW
:
361 if(!GetMailMergeConfigItem())
362 rSet
.DisableItem(nWhich
);
365 case SID_ALIGN_ANY_LEFT
:
366 case SID_ALIGN_ANY_HCENTER
:
367 case SID_ALIGN_ANY_RIGHT
:
368 case SID_ALIGN_ANY_JUSTIFIED
:
369 case SID_ALIGN_ANY_TOP
:
370 case SID_ALIGN_ANY_VCENTER
:
371 case SID_ALIGN_ANY_BOTTOM
:
372 case SID_ALIGN_ANY_HDEFAULT
:
373 case SID_ALIGN_ANY_VDEFAULT
:
377 sal_uInt16 nAlias
= 0;
379 if( m_nSelectionType
& (nsSelectionType::SEL_DRW_TXT
|nsSelectionType::SEL_TXT
) )
383 case SID_ALIGN_ANY_LEFT
: nAlias
= SID_ATTR_PARA_ADJUST_LEFT
; break;
384 case SID_ALIGN_ANY_HCENTER
: nAlias
= SID_ATTR_PARA_ADJUST_CENTER
; break;
385 case SID_ALIGN_ANY_RIGHT
: nAlias
= SID_ATTR_PARA_ADJUST_RIGHT
; break;
386 case SID_ALIGN_ANY_JUSTIFIED
: nAlias
= SID_ATTR_PARA_ADJUST_BLOCK
; break;
387 case SID_ALIGN_ANY_TOP
: nAlias
= SID_TABLE_VERT_NONE
; break;
388 case SID_ALIGN_ANY_VCENTER
: nAlias
= SID_TABLE_VERT_CENTER
; break;
389 case SID_ALIGN_ANY_BOTTOM
: nAlias
= SID_TABLE_VERT_BOTTOM
; break;
392 else if(m_nSelectionType
& (nsSelectionType::SEL_DRW
))
394 //the draw shell cannot provide a status per item - only one for SID_OBJECT_ALIGN
395 if(nWhich
!= SID_ALIGN_ANY_JUSTIFIED
)
397 const SfxPoolItem
* pItem
= 0;
398 GetViewFrame()->GetDispatcher()->QueryState( SID_OBJECT_ALIGN
, pItem
);
407 case SID_ALIGN_ANY_LEFT
: nAlias
= SID_OBJECT_ALIGN_LEFT
; break;
408 case SID_ALIGN_ANY_HCENTER
: nAlias
= SID_OBJECT_ALIGN_CENTER
; break;
409 case SID_ALIGN_ANY_RIGHT
: nAlias
= SID_OBJECT_ALIGN_RIGHT
; break;
410 case SID_ALIGN_ANY_TOP
: nAlias
= SID_OBJECT_ALIGN_UP
; break;
411 case SID_ALIGN_ANY_VCENTER
: nAlias
= SID_OBJECT_ALIGN_MIDDLE
; break;
412 case SID_ALIGN_ANY_BOTTOM
: nAlias
= SID_OBJECT_ALIGN_DOWN
; break;
415 //these slots are either re-mapped to text or object alignment
416 const SfxPoolItem
* pState
= 0;
418 GetViewFrame()->GetDispatcher()->QueryState( nAlias
, pState
);
420 rSet
.Put(*pState
, nWhich
);
422 rSet
.DisableItem(nWhich
);
426 nWhich
= aIter
.NextWhich();
430 void SwView::GetDrawState(SfxItemSet
&rSet
)
432 SfxWhichIter
aIter(rSet
);
433 bool bWeb
= 0 != PTR_CAST(SwWebView
, this);
435 for( sal_uInt16 nWhich
= aIter
.FirstWhich(); nWhich
;
436 nWhich
= aIter
.NextWhich() )
439 case SID_INSERT_DRAW
:
441 rSet
.DisableItem( nWhich
);
444 SfxAllEnumItem
aEnum(SID_INSERT_DRAW
, m_nDrawSfxId
);
445 if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
447 aEnum
.DisableValue( SID_DRAW_CAPTION_VERTICAL
);
448 aEnum
.DisableValue( SID_DRAW_TEXT_VERTICAL
);
454 case SID_SHOW_HIDDEN
:
456 rSet
.DisableItem( nWhich
);
459 case SID_DRAW_TEXT_MARQUEE
:
460 if (::GetHtmlMode(GetDocShell()) & HTMLMODE_SOME_STYLES
)
461 rSet
.Put( SfxBoolItem(nWhich
, m_nDrawSfxId
== nWhich
));
463 rSet
.DisableItem(nWhich
);
465 case SID_OBJECT_SELECT
:
466 rSet
.Put( SfxBoolItem(nWhich
, m_nDrawSfxId
== nWhich
||
467 m_nFormSfxId
== nWhich
));
470 case SID_FONTWORK_GALLERY_FLOATER
:
473 rSet
.DisableItem( nWhich
);
477 case SID_DRAWTBX_CS_BASIC
:
478 case SID_DRAWTBX_CS_SYMBOL
:
479 case SID_DRAWTBX_CS_ARROW
:
480 case SID_DRAWTBX_CS_FLOWCHART
:
481 case SID_DRAWTBX_CS_CALLOUT
:
482 case SID_DRAWTBX_CS_STAR
:
485 rSet
.DisableItem( nWhich
);
487 rSet
.Put(SfxStringItem(nWhich
, m_aCurrShapeEnumCommand
[ nWhich
- SID_DRAWTBX_CS_BASIC
] ));
494 sal_Bool
SwView::HasUIFeature( sal_uInt32 nFeature
)
496 sal_Bool bRet
= sal_False
;
499 case CHILDWIN_LABEL
: bRet
= m_pWrtShell
->IsLabelDoc(); break;
500 case CHILDWIN_MAILMERGE
: bRet
= 0 != GetMailMergeConfigItem(); break;
505 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */