bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / uiview / viewstat.cxx
blob21aa946afce2033681a95737524dbf03275b6245
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
40 #include <tox.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/app.hxx>
43 #include <view.hxx>
44 #include <wrtsh.hxx>
45 #include <basesh.hxx>
46 #include <uitool.hxx>
47 #include <viewopt.hxx>
48 #include <tablemgr.hxx>
49 #include <pagedesc.hxx>
50 #include <wview.hxx>
51 #include <globdoc.hxx>
52 #include <svl/stritem.hxx>
53 #include <unotools/moduleoptions.hxx>
54 #include <svl/visitem.hxx>
56 #include <cmdid.h>
58 #include <IDocumentRedlineAccess.hxx>
59 #include <doc.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);
71 while(nWhich)
73 switch(nWhich)
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);
81 break;
83 case FN_INSERT_CAPTION:
85 // Captions gibt's fuer Grafiken, OLE-Objekte, Rahmen und Tabellen
86 if( !bGetFrmType )
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);
99 break;
101 case FN_EDIT_FOOTNOTE:
103 if( !m_pWrtShell->GetCurFtn() )
104 rSet.DisableItem(nWhich);
106 break;
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);
114 else
115 rSet.Put(SfxUInt16Item(nWhich, m_pWrtShell->GetPageOffset()));
117 break;
118 case SID_PRINTDOC:
119 case SID_PRINTDOCDIRECT:
120 GetSlotState( nWhich, SfxViewShell::GetInterface(), &rSet );
121 break;
122 case SID_ATTR_PAGE:
123 case SID_ATTR_PAGE_SIZE:
124 case SID_ATTR_PAGE_PAPERBIN:
125 case RES_PAPER_BIN:
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);
132 break;
133 case RES_BACKGROUND:
134 case SID_ATTR_BRUSH:
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);
141 rSet.Put(rBrush);
143 break;
144 case SID_CLEARHISTORY:
146 rSet.Put(SfxBoolItem(nWhich, m_pWrtShell->GetLastUndoInfo(0, 0)));
148 break;
149 case SID_UNDO:
151 // die muss noch nicht vorhanden sein
152 // also lasse sie mal anlegen:
153 if( !m_pShell )
154 SelectShell();
156 const SfxPoolItem* pState = m_pShell->GetSlotState(SID_UNDO);
157 if(pState)
158 rSet.Put(*pState);
159 else
160 rSet.DisableItem(nWhich);
162 break;
163 case FN_INSERT_CTRL:
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);
175 rSet.Put(aImgItem);
177 break;
178 case FN_INSERT_OBJ_CTRL:
179 if(bWeb)
180 rSet.DisableItem(nWhich);
181 else
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);
193 rSet.Put(aImgItem);
195 break;
196 case FN_UPDATE_TOX:
197 if(!m_pWrtShell->GetTOXCount())
198 rSet.DisableItem(nWhich);
199 break;
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);
208 break;
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);
216 #endif
217 break;
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)));
227 break;
228 case SID_ATTR_LANGUAGE:
230 rSet.Put((const SvxLanguageItem&)
231 m_pWrtShell->GetDefault(RES_CHRATR_LANGUAGE), SID_ATTR_LANGUAGE);
233 break;
234 case RES_CHRATR_CJK_LANGUAGE:
235 rSet.Put((const SvxLanguageItem&)
236 m_pWrtShell->GetDefault(RES_CHRATR_CJK_LANGUAGE), RES_CHRATR_CJK_LANGUAGE);
237 break;
238 case RES_CHRATR_CTL_LANGUAGE:
239 rSet.Put((const SvxLanguageItem&)
240 m_pWrtShell->GetDefault(RES_CHRATR_CTL_LANGUAGE), RES_CHRATR_CTL_LANGUAGE);
241 break;
242 case FN_REDLINE_ON:
243 rSet.Put( SfxBoolItem( nWhich, GetDocShell()->IsChangeRecording() ) );
244 break;
245 case FN_REDLINE_PROTECT :
246 rSet.Put( SfxBoolItem( nWhich, GetDocShell()->HasChangeRecordProtection() ) );
247 break;
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 ));
254 break;
255 case SID_GALLERY :
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)));
262 else
263 rSet.DisableItem(nWhich);
265 break;
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);
276 break;
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
283 // "Previous Change"
284 if (0 == m_pWrtShell->GetRedlineCount())
285 rSet.DisableItem(nWhich);
287 break;
289 case SID_THESAURUS:
291 SwWrtShell &rSh = GetWrtShell();
292 if (2 <= rSh.GetCrsrCnt()) // multi selection?
293 rSet.DisableItem(nWhich);
294 else
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);
306 break;
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);
315 else
316 GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
318 break;
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 ));
325 break;
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);
332 break;
333 case SID_VIEW_DATA_SOURCE_BROWSER:
334 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
335 rSet.Put( SfxVisibilityItem( nWhich, sal_False ) );
336 else
337 rSet.Put( SfxBoolItem( nWhich, GetViewFrame()->HasChildWindow( SID_BROWSER ) ) );
338 break;
339 case SID_READONLY_MODE:
340 rSet.Put(SfxBoolItem(nWhich,
341 m_pWrtShell->HasReadonlySel()||GetDocShell()->IsReadOnly()));
342 break;
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);
352 break;
353 case FN_INSERT_FIELD_DATA_ONLY :
354 if(!m_bInMailMerge && !GetViewFrame()->HasChildWindow(nWhich))
355 rSet.DisableItem(nWhich);
356 break;
357 case FN_MAILMERGE_SENDMAIL_CHILDWINDOW:
358 break;
359 case FN_MAILMERGE_CHILDWINDOW:
361 if(!GetMailMergeConfigItem())
362 rSet.DisableItem(nWhich);
364 break;
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 :
375 if( !m_pShell )
376 SelectShell();
377 sal_uInt16 nAlias = 0;
378 bool bDraw = false;
379 if( m_nSelectionType & (nsSelectionType::SEL_DRW_TXT|nsSelectionType::SEL_TXT) )
381 switch( nWhich )
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 );
399 if(pItem)
400 bDraw = true;
403 else
405 switch( nWhich )
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;
417 if(nAlias)
418 GetViewFrame()->GetDispatcher()->QueryState( nAlias, pState );
419 if(pState)
420 rSet.Put(*pState, nWhich);
421 else if(!bDraw)
422 rSet.DisableItem(nWhich);
424 break;
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() )
437 switch(nWhich)
439 case SID_INSERT_DRAW:
440 if ( bWeb )
441 rSet.DisableItem( nWhich );
442 else
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 );
450 rSet.Put(aEnum);
452 break;
454 case SID_SHOW_HIDDEN:
455 case SID_SHOW_FORMS:
456 rSet.DisableItem( nWhich );
457 break;
459 case SID_DRAW_TEXT_MARQUEE:
460 if (::GetHtmlMode(GetDocShell()) & HTMLMODE_SOME_STYLES)
461 rSet.Put( SfxBoolItem(nWhich, m_nDrawSfxId == nWhich));
462 else
463 rSet.DisableItem(nWhich);
464 break;
465 case SID_OBJECT_SELECT:
466 rSet.Put( SfxBoolItem(nWhich, m_nDrawSfxId == nWhich ||
467 m_nFormSfxId == nWhich));
468 break;
470 case SID_FONTWORK_GALLERY_FLOATER :
472 if ( bWeb )
473 rSet.DisableItem( nWhich );
475 break;
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 :
484 if ( bWeb )
485 rSet.DisableItem( nWhich );
486 else
487 rSet.Put(SfxStringItem(nWhich, m_aCurrShapeEnumCommand[ nWhich - SID_DRAWTBX_CS_BASIC ] ));
489 break;
494 sal_Bool SwView::HasUIFeature( sal_uInt32 nFeature )
496 sal_Bool bRet = sal_False;
497 switch(nFeature)
499 case CHILDWIN_LABEL : bRet = m_pWrtShell->IsLabelDoc(); break;
500 case CHILDWIN_MAILMERGE : bRet = 0 != GetMailMergeConfigItem(); break;
502 return bRet;
505 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */