merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / uiview / viewstat.cxx
blob9800c1ed63e519de3def03f52c67a95b76f6669b
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: viewstat.cxx,v $
10 * $Revision: 1.42 $
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>
52 #include <tox.hxx>
53 #include <sfx2/dispatch.hxx>
54 #include <sfx2/app.hxx>
55 #ifndef _VIEW_HXX
56 #include <view.hxx>
57 #endif
58 #include <wrtsh.hxx>
59 #ifndef _BASESH_HXX
60 #include <basesh.hxx>
61 #endif
62 #include <uitool.hxx>
63 #include <viewopt.hxx>
64 #include <tablemgr.hxx>
65 #include <pagedesc.hxx>
66 #ifndef _WVIEW_HXX
67 #include <wview.hxx>
68 #endif
69 #include <globdoc.hxx>
70 #include <svtools/stritem.hxx>
71 #include <svtools/moduleoptions.hxx>
72 #include <svtools/visitem.hxx>
74 #ifndef _CMDID_H
75 #include <cmdid.h>
76 #endif
78 #include <IDocumentRedlineAccess.hxx>
80 using namespace ::com::sun::star;
82 /*--------------------------------------------------------------------
83 Beschreibung:
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);
94 while(nWhich)
96 switch(nWhich)
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);
104 break;
106 case FN_INSERT_CAPTION:
108 // Captions gibt's fuer Grafiken, OLE-Objekte, Rahmen und Tabellen
109 if( !bGetFrmType )
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);
122 break;
124 case FN_EDIT_FOOTNOTE:
126 if( !pWrtShell->GetCurFtn() )
127 rSet.DisableItem(nWhich);
129 break;
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);
137 else
138 rSet.Put(SfxUInt16Item(nWhich, pWrtShell->GetPageOffset()));
140 break;
141 case SID_PRINTDOC:
142 case SID_PRINTDOCDIRECT:
143 GetSlotState( nWhich, SfxViewShell::GetInterface(), &rSet );
144 break;
145 case SID_ATTR_PAGE:
146 case SID_ATTR_PAGE_SIZE:
147 case SID_ATTR_PAGE_PAPERBIN:
148 case RES_PAPER_BIN:
149 case FN_PARAM_FTN_INFO:
151 const sal_uInt16 nCurIdx = pWrtShell->GetCurPageDesc();
152 const SwPageDesc& rDesc = pWrtShell->GetPageDesc( nCurIdx );
153 ::PageDescToItemSet( rDesc, rSet);
155 break;
156 case RES_BACKGROUND:
157 case SID_ATTR_BRUSH:
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);
164 rSet.Put(rBrush);
166 break;
167 case SID_CLEARHISTORY:
169 rSet.Put(SfxBoolItem(nWhich, pWrtShell->GetUndoIds() != UNDO_EMPTY));
171 break;
172 case SID_UNDO:
174 //JP 21.07.98: Bug 53429 - die muss noch nicht vorhanden sein
175 // also lasse sie mal anlegen:
176 if( !pShell )
177 SelectShell();
179 const SfxPoolItem* pState = pShell->GetSlotState(SID_UNDO);
180 if(pState)
181 rSet.Put(*pState);
182 else
183 rSet.DisableItem(nWhich);
185 break;
186 case FN_INSERT_CTRL:
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);
198 rSet.Put(aImgItem);
200 break;
201 case FN_INSERT_OBJ_CTRL:
202 if(bWeb)
203 rSet.DisableItem(nWhich);
204 else
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);
216 rSet.Put(aImgItem);
218 break;
219 case FN_UPDATE_TOX:
220 if(!pWrtShell->GetTOXCount())
221 rSet.DisableItem(nWhich);
222 break;
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);
231 break;
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);
239 #endif
240 break;
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)));
250 break;
251 case SID_ATTR_LANGUAGE:
253 rSet.Put((const SvxLanguageItem&)
254 pWrtShell->GetDefault(RES_CHRATR_LANGUAGE), SID_ATTR_LANGUAGE);
256 break;
257 case RES_CHRATR_CJK_LANGUAGE:
258 rSet.Put((const SvxLanguageItem&)
259 pWrtShell->GetDefault(RES_CHRATR_CJK_LANGUAGE), RES_CHRATR_CJK_LANGUAGE);
260 break;
261 case RES_CHRATR_CTL_LANGUAGE:
262 rSet.Put((const SvxLanguageItem&)
263 pWrtShell->GetDefault(RES_CHRATR_CTL_LANGUAGE), RES_CHRATR_CTL_LANGUAGE);
264 break;
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));
273 break;
274 case FN_REDLINE_ON:
275 rSet.Put( SfxBoolItem( nWhich, (pWrtShell->GetRedlineMode() & nsRedlineMode_t::REDLINE_ON) != 0 ) );
276 break;
277 case FN_REDLINE_PROTECT :
279 rSet.Put( SfxBoolItem( nWhich, pWrtShell->getIDocumentRedlineAccess()->GetRedlinePassword().getLength() > 0 ) );
281 break;
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 ));
288 break;
289 case SID_GALLERY :
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)));
296 else
297 rSet.DisableItem(nWhich);
299 break;
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 );
308 break;
309 case FN_THESAURUS_DLG:
311 SwWrtShell &rSh = GetWrtShell();
312 if (2 <= rSh.GetCrsrCnt()) // multi selection?
313 rSet.DisableItem(nWhich);
314 else
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);
326 break;
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);
335 else
336 GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
338 break;
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 ));
345 break;
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);
353 break;
354 case SID_VIEW_DATA_SOURCE_BROWSER:
355 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
356 rSet.Put( SfxVisibilityItem( nWhich, sal_False ) );
357 else
358 rSet.Put( SfxBoolItem( nWhich, GetViewFrame()->HasChildWindow( SID_BROWSER ) ) );
359 break;
360 case SID_READONLY_MODE:
361 rSet.Put(SfxBoolItem(nWhich,
362 pWrtShell->HasReadonlySel()||GetDocShell()->IsReadOnly()));
363 break;
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);
373 break;
374 case FN_INSERT_FIELD_DATA_ONLY :
375 if(!bInMailMerge && !GetViewFrame()->HasChildWindow(nWhich))
376 rSet.DisableItem(nWhich);
377 break;
378 case FN_MAILMERGE_SENDMAIL_CHILDWINDOW:
379 break;
380 case FN_MAILMERGE_CHILDWINDOW:
382 if(!GetMailMergeConfigItem())
383 rSet.DisableItem(nWhich);
385 break;
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 :
396 if( !pShell )
397 SelectShell();
398 USHORT nAlias = 0;
399 bool bDraw = false;
400 if( nSelectionType & (nsSelectionType::SEL_DRW_TXT|nsSelectionType::SEL_TXT) )
402 switch( nWhich )
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 );
420 if(pItem)
421 bDraw = true;
424 else
426 switch( nWhich )
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;
438 if(nAlias)
439 GetViewFrame()->GetDispatcher()->QueryState( nAlias, pState );
440 if(pState)
441 rSet.Put(*pState, nWhich);
442 else if(!bDraw)
443 rSet.DisableItem(nWhich);
445 break;
447 nWhich = aIter.NextWhich();
452 /*--------------------------------------------------------------------
453 Beschreibung:
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() )
463 switch(nWhich)
465 case SID_INSERT_DRAW:
466 if ( bWeb )
467 rSet.DisableItem( nWhich );
468 else
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 );
476 rSet.Put(aEnum);
478 break;
480 case SID_SHOW_HIDDEN:
481 case SID_SHOW_FORMS:
482 rSet.DisableItem( nWhich );
483 // rSet.Put( SfxBoolItem(nWhich,sal_True ));
484 break;
486 case SID_DRAW_TEXT_MARQUEE:
487 if (::GetHtmlMode(GetDocShell()) & HTMLMODE_SOME_STYLES)
488 rSet.Put( SfxBoolItem(nWhich, nDrawSfxId == nWhich));
489 else
490 rSet.DisableItem(nWhich);
491 break;
492 case SID_OBJECT_SELECT:
493 rSet.Put( SfxBoolItem(nWhich, nDrawSfxId == nWhich ||
494 nFormSfxId == nWhich));
495 break;
497 case SID_FONTWORK_GALLERY_FLOATER :
499 if ( bWeb )
500 rSet.DisableItem( nWhich );
502 break;
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 :
511 if ( bWeb )
512 rSet.DisableItem( nWhich );
513 else
514 rSet.Put(SfxStringItem(nWhich, aCurrShapeEnumCommand[ nWhich - SID_DRAWTBX_CS_BASIC ] ));
516 break;
521 /*--------------------------------------------------------------------
522 Beschreibung:
523 --------------------------------------------------------------------*/
525 sal_Bool SwView::HasUIFeature( sal_uInt32 nFeature )
527 sal_Bool bRet = sal_False;
528 switch(nFeature)
530 case CHILDWIN_LABEL : bRet = pWrtShell->IsLabelDoc(); break;
531 case CHILDWIN_MAILMERGE : bRet = 0 != GetMailMergeConfigItem(); break;
533 return bRet;