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