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