xref: /aoo41x/main/sw/source/ui/uiview/viewstat.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include <hintids.hxx>
32 #include <com/sun/star/linguistic2/XThesaurus.hpp>
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <svl/aeitem.hxx>
35 #include <svl/whiter.hxx>
36 #include <svl/cjkoptions.hxx>
37 
38 #include <sfx2/viewfrm.hxx>
39 #include <sfx2/objitem.hxx>
40 #include <svl/imageitm.hxx>
41 #include <svl/languageoptions.hxx>
42 #include <editeng/protitem.hxx>
43 #include <sfx2/linkmgr.hxx>
44 #include <editeng/langitem.hxx>
45 #include <editeng/brshitem.hxx>
46 #include <svx/htmlmode.hxx>
47 #include <editeng/unolingu.hxx>
48 #include <sfx2/msgpool.hxx>
49 #include <swmodule.hxx>
50 #include <tox.hxx>
51 #include <sfx2/dispatch.hxx>
52 #include <sfx2/app.hxx>
53 #include <view.hxx>
54 #include <wrtsh.hxx>
55 #include <basesh.hxx>
56 #include <uitool.hxx>
57 #include <viewopt.hxx>
58 #include <tablemgr.hxx>
59 #include <pagedesc.hxx>
60 #include <wview.hxx>
61 #include <globdoc.hxx>
62 #include <svl/stritem.hxx>
63 #include <unotools/moduleoptions.hxx>
64 #include <svl/visitem.hxx>
65 
66 #include <cmdid.h>
67 
68 #include <IDocumentRedlineAccess.hxx>
69 
70 using namespace ::com::sun::star;
71 
72 /*--------------------------------------------------------------------
73 	Beschreibung:
74  --------------------------------------------------------------------*/
75 
76 void SwView::GetState(SfxItemSet &rSet)
77 {
78 	SfxWhichIter aIter(rSet);
79 	sal_uInt16 nWhich = aIter.FirstWhich();
80 	sal_uInt16 eFrmType = FRMTYPE_NONE;
81 	int bGetFrmType = sal_False;
82 	sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
83 
84 	while(nWhich)
85 	{
86 		switch(nWhich)
87 		{
88 			case FN_EDIT_LINK_DLG:
89 				if( !pWrtShell->GetLinkManager().GetLinks().Count()	)
90 					rSet.DisableItem(nWhich);
91 				else if( pWrtShell->IsSelFrmMode() &&
92 							pWrtShell->IsSelObjProtected(FLYPROTECT_CONTENT))
93 						rSet.DisableItem(nWhich);
94 				break;
95 
96 			case FN_INSERT_CAPTION:
97 			{
98 				// Captions gibt's fuer Grafiken, OLE-Objekte, Rahmen und Tabellen
99 				if( !bGetFrmType )
100 					eFrmType = pWrtShell->GetFrmType(0,sal_True), bGetFrmType = sal_True;
101 				if (! ( ((eFrmType & FRMTYPE_FLY_ANY) && nSelectionType != nsSelectionType::SEL_DRW_TXT)||
102 						nSelectionType & nsSelectionType::SEL_TBL ||
103 						nSelectionType & nsSelectionType::SEL_DRW) )
104 					rSet.DisableItem(nWhich);
105                 else if((pWrtShell->IsObjSelected()||pWrtShell->IsFrmSelected()) &&
106                         (pWrtShell->IsSelObjProtected( FLYPROTECT_PARENT)||
107                             pWrtShell->IsSelObjProtected( FLYPROTECT_CONTENT )))
108                     rSet.DisableItem(nWhich);
109                 else if( pWrtShell->IsTableMode() )
110 					rSet.DisableItem(nWhich);
111 			}
112 			break;
113 
114 			case FN_EDIT_FOOTNOTE:
115 			{
116 				if( !pWrtShell->GetCurFtn() )
117 					rSet.DisableItem(nWhich);
118 			}
119 			break;
120 
121 			case FN_CHANGE_PAGENUM:
122 			{
123 				sal_uInt16 nType = pWrtShell->GetFrmType(0,sal_True);
124 				if( ( FRMTYPE_FLY_ANY | FRMTYPE_HEADER | FRMTYPE_FOOTER |
125 					  FRMTYPE_FOOTNOTE | FRMTYPE_DRAWOBJ ) & nType )
126 					rSet.DisableItem(nWhich);
127 				else
128 					rSet.Put(SfxUInt16Item(nWhich, pWrtShell->GetPageOffset()));
129 			}
130 			break;
131 			case SID_PRINTDOC:
132 			case SID_PRINTDOCDIRECT:
133 				GetSlotState( nWhich, SfxViewShell::GetInterface(),	&rSet );
134 			break;
135 			case SID_ATTR_PAGE:
136 			case SID_ATTR_PAGE_SIZE:
137 			case SID_ATTR_PAGE_PAPERBIN:
138 			case RES_PAPER_BIN:
139 			case FN_PARAM_FTN_INFO:
140 			{
141 				const sal_uInt16 nCurIdx = pWrtShell->GetCurPageDesc();
142 				const SwPageDesc& rDesc = pWrtShell->GetPageDesc( nCurIdx );
143 				::PageDescToItemSet( rDesc, rSet);
144 			}
145 			break;
146 			case RES_BACKGROUND:
147 			case SID_ATTR_BRUSH:
148 			{
149 				const sal_uInt16 nCurIdx = pWrtShell->GetCurPageDesc();
150 				const SwPageDesc& rDesc = pWrtShell->GetPageDesc( nCurIdx );
151 				const SwFrmFmt& rMaster = rDesc.GetMaster();
152 				const SvxBrushItem& rBrush = (const SvxBrushItem&)
153                                     rMaster.GetFmtAttr(RES_BACKGROUND, sal_True);
154 				rSet.Put(rBrush);
155 			}
156 			break;
157 			case SID_CLEARHISTORY:
158 			{
159                 rSet.Put(SfxBoolItem(nWhich, pWrtShell->GetLastUndoInfo(0, 0)));
160 			}
161 			break;
162 			case SID_UNDO:
163 			{
164 				//JP 21.07.98: Bug 53429 - die muss noch nicht vorhanden sein
165 				// 				also lasse sie mal anlegen:
166 				if( !pShell )
167 					SelectShell();
168 
169 				const SfxPoolItem* pState = pShell->GetSlotState(SID_UNDO);
170 				if(pState)
171 					rSet.Put(*pState);
172 				else
173 					rSet.DisableItem(nWhich);
174 			}
175 			break;
176 			case FN_INSERT_CTRL:
177             {
178                 SfxImageItem aImgItem(nWhich, bWeb ? SwView::nWebInsertCtrlState : SwView::nInsertCtrlState);
179                 SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( GetViewFrame() );
180                 const SfxSlot* pSlot = rPool.GetSlot( aImgItem.GetValue() );
181                 if(pSlot && pSlot->IsMode( SFX_SLOT_IMAGEROTATION ))
182                 {
183                     if(pWrtShell->IsInVerticalText())
184                         aImgItem.SetRotation(2700);
185                     if(pWrtShell->IsInRightToLeftText())
186                         aImgItem.SetMirrored(sal_True);
187                 }
188                 rSet.Put(aImgItem);
189             }
190             break;
191 			case FN_INSERT_OBJ_CTRL:
192 			if(bWeb)
193 				rSet.DisableItem(nWhich);
194 			else
195             {
196                 SfxImageItem aImgItem(nWhich, SwView::nInsertObjectCtrlState);
197                 SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( GetViewFrame() );
198                 const SfxSlot* pSlot = rPool.GetSlot( aImgItem.GetValue() );
199                 if(pSlot && pSlot->IsMode( SFX_SLOT_IMAGEROTATION ))
200                 {
201                     if(pWrtShell->IsInVerticalText())
202                         aImgItem.SetRotation(2700);
203                     if(pWrtShell->IsInRightToLeftText())
204                         aImgItem.SetMirrored(sal_True);
205                 }
206                 rSet.Put(aImgItem);
207             }
208 			break;
209 			case FN_UPDATE_TOX:
210 				if(!pWrtShell->GetTOXCount())
211 					rSet.DisableItem(nWhich);
212 			break;
213 			case FN_EDIT_CURRENT_TOX:
214 			case FN_UPDATE_CUR_TOX:
215             {
216                 const SwTOXBase* pBase = 0;
217                 if(0 == (pBase = pWrtShell->GetCurTOX()) ||
218                     (FN_EDIT_CURRENT_TOX == nWhich && pBase->IsTOXBaseInReadonly()))
219 					rSet.DisableItem(nWhich);
220             }
221             break;
222 			case SID_TWAIN_SELECT:
223 			case SID_TWAIN_TRANSFER:
224 #if defined WNT || defined UNX
225 			{
226 				if(!SW_MOD()->GetScannerManager().is())
227 					rSet.DisableItem(nWhich);
228 			}
229 #endif
230 			break;
231 			case RES_PARATR_TABSTOP:
232 			case SID_ATTR_DEFTABSTOP:
233 			{
234 				const SvxTabStopItem& rDefTabs =
235 					(const SvxTabStopItem&)pWrtShell->
236 										GetDefault(RES_PARATR_TABSTOP);
237 				rSet.Put( SfxUInt16Item( nWhich,
238 												(sal_uInt16)::GetTabDist(rDefTabs)));
239 			}
240 			break;
241 			case SID_ATTR_LANGUAGE:
242 			{
243 				rSet.Put((const SvxLanguageItem&)
244 					pWrtShell->GetDefault(RES_CHRATR_LANGUAGE), SID_ATTR_LANGUAGE);
245 			}
246 			break;
247 			case RES_CHRATR_CJK_LANGUAGE:
248 				rSet.Put((const SvxLanguageItem&)
249 					pWrtShell->GetDefault(RES_CHRATR_CJK_LANGUAGE), RES_CHRATR_CJK_LANGUAGE);
250 			break;
251 			case RES_CHRATR_CTL_LANGUAGE:
252 				rSet.Put((const SvxLanguageItem&)
253 					pWrtShell->GetDefault(RES_CHRATR_CTL_LANGUAGE), RES_CHRATR_CTL_LANGUAGE);
254 			break;
255             case FN_HYPHENATE_OPT_DLG:
256 			{
257 				sal_Bool bCheck = sal_False;
258 
259 				if (pWrtShell->GetSelectionType() & (nsSelectionType::SEL_DRW_TXT|nsSelectionType::SEL_DRW))
260 					bCheck = IsDrawTextHyphenate();
261 				rSet.Put(SfxBoolItem(nWhich, bCheck));
262 			}
263 			break;
264             case FN_REDLINE_ON:
265                 rSet.Put( SfxBoolItem( nWhich, GetDocShell()->IsChangeRecording() ) );
266             break;
267             case FN_REDLINE_PROTECT :
268                 rSet.Put( SfxBoolItem( nWhich, GetDocShell()->HasChangeRecordProtection() ) );
269             break;
270             case FN_REDLINE_SHOW:
271 			{
272 				sal_uInt16 nMask = nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE;
273 				rSet.Put( SfxBoolItem( nWhich,
274 					(pWrtShell->GetRedlineMode() & nMask) == nMask ));
275 			}
276 			break;
277             case SID_GALLERY :
278             case SID_AVMEDIA_PLAYER :
279             case FN_REDLINE_ACCEPT :
280 			{
281 				SfxViewFrame* pVFrame = GetViewFrame();
282 				if (pVFrame->KnowsChildWindow(nWhich))
283 					rSet.Put(SfxBoolItem( nWhich, pVFrame->HasChildWindow(nWhich)));
284 				else
285 					rSet.DisableItem(nWhich);
286 			}
287 			break;
288             case FN_REDLINE_ACCEPT_DIRECT:
289             case FN_REDLINE_REJECT_DIRECT:
290             {
291                 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_REDLINE );
292                 Point aCrsrPos = pWrtShell->GetCrsrDocPos( sal_True );
293                 if( !pWrtShell->GetContentAtPos( aCrsrPos, aCntntAtPos ) )
294                     rSet.DisableItem( nWhich );
295             }
296             break;
297             case SID_THESAURUS:
298 			{
299 				SwWrtShell  &rSh = GetWrtShell();
300 				if (2 <= rSh.GetCrsrCnt())	// multi selection?
301 					rSet.DisableItem(nWhich);
302 				else
303 				{
304 					LanguageType nLang = rSh.GetCurLang();
305 
306 					// disable "Thesaurus" (menu entry and key shortcut) if the
307 					// language is not supported (by default it is enabled)
308 					uno::Reference< linguistic2::XThesaurus >  xThes( ::GetThesaurus() );
309 					if (!xThes.is() || nLang == LANGUAGE_NONE ||
310 						!xThes->hasLocale( SvxCreateLocale( nLang ) ))
311 						rSet.DisableItem(nWhich);
312 				}
313 			}
314 			break;
315             case SID_HANGUL_HANJA_CONVERSION:
316             case SID_CHINESE_CONVERSION:
317             {
318                 if (!SvtCJKOptions().IsAnyEnabled())
319                 {
320                     GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_False );
321                     rSet.DisableItem(nWhich);
322                 }
323                 else
324                     GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
325             }
326             break;
327 			case SID_MAIL_SCROLLBODY_PAGEDOWN:
328 				{
329                     const long nBottom = pWrtShell->GetDocSize().Height() + DOCUMENTBORDER;
330                     const long nAct = GetVisArea().Bottom();
331 					rSet.Put(SfxBoolItem(SID_MAIL_SCROLLBODY_PAGEDOWN, nAct < nBottom ));
332 				}
333 				break;
334 
335 			case SID_DOCUMENT_COMPARE:
336 			case SID_DOCUMENT_MERGE:
337 				if( GetDocShell()->IsA( SwGlobalDocShell::StaticType() ) ||
338 //					pWrtShell->IsAnySectionInDoc( sal_True, sal_True, sal_True )||
339                     (SID_DOCUMENT_MERGE == nWhich && pWrtShell->getIDocumentRedlineAccess()->GetRedlinePassword().getLength()))
340 					rSet.DisableItem(nWhich);
341 			break;
342             case  SID_VIEW_DATA_SOURCE_BROWSER:
343                 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
344                     rSet.Put( SfxVisibilityItem( nWhich, sal_False ) );
345                 else
346                     rSet.Put( SfxBoolItem( nWhich, GetViewFrame()->HasChildWindow( SID_BROWSER ) ) );
347             break;
348             case SID_READONLY_MODE:
349                 rSet.Put(SfxBoolItem(nWhich,
350                     pWrtShell->HasReadonlySel()||GetDocShell()->IsReadOnly()));
351             break;
352             case SID_IMAGE_ORIENTATION:
353             {
354                 SfxImageItem aImageItem(nWhich);
355                 if(pWrtShell->IsInVerticalText())
356                     aImageItem.SetRotation( 2700 );
357                 if(pWrtShell->IsInRightToLeftText())
358                     aImageItem.SetMirrored( sal_True );
359                 rSet.Put(aImageItem);
360             }
361             break;
362             case FN_INSERT_FIELD_DATA_ONLY :
363                 if(!bInMailMerge && !GetViewFrame()->HasChildWindow(nWhich))
364                     rSet.DisableItem(nWhich);
365             break;
366             case FN_MAILMERGE_SENDMAIL_CHILDWINDOW:
367             break;
368             case FN_MAILMERGE_CHILDWINDOW:
369             {
370                 if(!GetMailMergeConfigItem())
371                     rSet.DisableItem(nWhich);
372             }
373             break;
374             case SID_ALIGN_ANY_LEFT :
375             case SID_ALIGN_ANY_HCENTER  :
376             case SID_ALIGN_ANY_RIGHT    :
377             case SID_ALIGN_ANY_JUSTIFIED:
378             case SID_ALIGN_ANY_TOP      :
379             case SID_ALIGN_ANY_VCENTER  :
380             case SID_ALIGN_ANY_BOTTOM   :
381             case SID_ALIGN_ANY_HDEFAULT :
382             case SID_ALIGN_ANY_VDEFAULT :
383             {
384                 if( !pShell )
385                     SelectShell();
386                 sal_uInt16 nAlias = 0;
387                 bool bDraw = false;
388                 if( nSelectionType & (nsSelectionType::SEL_DRW_TXT|nsSelectionType::SEL_TXT) )
389                 {
390                     switch( nWhich )
391                     {
392                         case SID_ALIGN_ANY_LEFT :       nAlias = SID_ATTR_PARA_ADJUST_LEFT; break;
393                         case SID_ALIGN_ANY_HCENTER  :   nAlias = SID_ATTR_PARA_ADJUST_CENTER; break;
394                         case SID_ALIGN_ANY_RIGHT    :   nAlias = SID_ATTR_PARA_ADJUST_RIGHT; break;
395                         case SID_ALIGN_ANY_JUSTIFIED:   nAlias = SID_ATTR_PARA_ADJUST_BLOCK; break;
396                         case SID_ALIGN_ANY_TOP      :   nAlias = FN_TABLE_VERT_NONE; break;
397                         case SID_ALIGN_ANY_VCENTER  :   nAlias = FN_TABLE_VERT_CENTER; break;
398                         case SID_ALIGN_ANY_BOTTOM   :   nAlias = FN_TABLE_VERT_BOTTOM; break;
399                     }
400                 }
401                 else if(nSelectionType & (nsSelectionType::SEL_DRW))
402                 {
403                     //the draw shell cannot provide a status per item - only one for SID_OBJECT_ALIGN
404                     if(nWhich != SID_ALIGN_ANY_JUSTIFIED)
405                     {
406                         const SfxPoolItem* pItem = 0;
407                         GetViewFrame()->GetDispatcher()->QueryState( SID_OBJECT_ALIGN, pItem );
408                         if(pItem)
409                             bDraw = true;
410                     }
411                 }
412                 else
413                 {
414                     switch( nWhich )
415                     {
416                         case SID_ALIGN_ANY_LEFT :       nAlias = SID_OBJECT_ALIGN_LEFT    ; break;
417                         case SID_ALIGN_ANY_HCENTER  :   nAlias = SID_OBJECT_ALIGN_CENTER ; break;
418                         case SID_ALIGN_ANY_RIGHT    :   nAlias = SID_OBJECT_ALIGN_RIGHT  ; break;
419                         case SID_ALIGN_ANY_TOP      :   nAlias = SID_OBJECT_ALIGN_UP     ;  break;
420                         case SID_ALIGN_ANY_VCENTER  :   nAlias = SID_OBJECT_ALIGN_MIDDLE ;  break;
421                         case SID_ALIGN_ANY_BOTTOM   :   nAlias = SID_OBJECT_ALIGN_DOWN    ; break;
422                     }
423                 }
424                 //these slots are either re-mapped to text or object alignment
425                 const SfxPoolItem* pState = 0;
426                 if(nAlias)
427                     GetViewFrame()->GetDispatcher()->QueryState( nAlias, pState );
428                 if(pState)
429                     rSet.Put(*pState, nWhich);
430                 else if(!bDraw)
431                     rSet.DisableItem(nWhich);
432             }
433             break;
434         }
435         nWhich = aIter.NextWhich();
436 	}
437 }
438 
439 
440 /*--------------------------------------------------------------------
441 	Beschreibung:
442  --------------------------------------------------------------------*/
443 
444 void SwView::GetDrawState(SfxItemSet &rSet)
445 {
446 	SfxWhichIter aIter(rSet);
447 	sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
448 
449 	for( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich;
450 											nWhich = aIter.NextWhich() )
451 		switch(nWhich)
452 		{
453 		case SID_INSERT_DRAW:
454             if ( bWeb )
455                 rSet.DisableItem( nWhich );
456 			else
457 			{
458                 SfxAllEnumItem aEnum(SID_INSERT_DRAW, nDrawSfxId);
459 				if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
460 				{
461 					aEnum.DisableValue( SID_DRAW_CAPTION_VERTICAL );
462 					aEnum.DisableValue( SID_DRAW_TEXT_VERTICAL );
463 				}
464 				rSet.Put(aEnum);
465 			}
466 			break;
467 
468 		case SID_SHOW_HIDDEN:
469 		case SID_SHOW_FORMS:
470 			rSet.DisableItem( nWhich );
471 			// rSet.Put( SfxBoolItem(nWhich,sal_True ));
472 			break;
473 
474 		case SID_DRAW_TEXT_MARQUEE:
475 			if (::GetHtmlMode(GetDocShell()) & HTMLMODE_SOME_STYLES)
476 				rSet.Put( SfxBoolItem(nWhich, nDrawSfxId == nWhich));
477 			else
478 				rSet.DisableItem(nWhich);
479 			break;
480 		case SID_OBJECT_SELECT:
481 			rSet.Put( SfxBoolItem(nWhich, nDrawSfxId == nWhich ||
482 										  nFormSfxId == nWhich));
483 			break;
484 
485 		case SID_FONTWORK_GALLERY_FLOATER :
486 		{
487 			if ( bWeb )
488 				rSet.DisableItem( nWhich );
489 		}
490 		break;
491 
492 		case SID_DRAWTBX_CS_BASIC :
493 		case SID_DRAWTBX_CS_SYMBOL :
494 		case SID_DRAWTBX_CS_ARROW :
495 		case SID_DRAWTBX_CS_FLOWCHART :
496 		case SID_DRAWTBX_CS_CALLOUT :
497 		case SID_DRAWTBX_CS_STAR :
498 		{
499 			if ( bWeb )
500 				rSet.DisableItem( nWhich );
501 			else
502 				rSet.Put(SfxStringItem(nWhich, aCurrShapeEnumCommand[ nWhich - SID_DRAWTBX_CS_BASIC ] ));
503 		}
504 		break;
505 
506 		}
507 }
508 
509 /*--------------------------------------------------------------------
510 	Beschreibung:
511  --------------------------------------------------------------------*/
512 
513 sal_Bool SwView::HasUIFeature( sal_uInt32 nFeature )
514 {
515     sal_Bool bRet = sal_False;
516     switch(nFeature)
517     {
518         case CHILDWIN_LABEL     : bRet = pWrtShell->IsLabelDoc(); break;
519         case CHILDWIN_MAILMERGE : bRet = 0 != GetMailMergeConfigItem(); break;
520     }
521     return bRet;
522 }
523 
524