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