update credits
[LibreOffice.git] / sw / source / ui / shells / basesh.cxx
blob05ce67dd15434260de66d4b2c858decc20c0ebb8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sot/factory.hxx>
22 #include <hintids.hxx>
23 #include <svl/urihelper.hxx>
24 #include <svl/languageoptions.hxx>
26 #include <svx/svxids.hrc>
27 #include <sfx2/linkmgr.hxx>
28 #include <sfx2/htmlmode.hxx>
29 #include <svx/imapdlg.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/request.hxx>
34 #include <svl/whiter.hxx>
35 #include <svl/visitem.hxx>
36 #include <sfx2/objitem.hxx>
37 #include <vcl/graphicfilter.hxx>
38 #include <svx/gallery.hxx>
39 #include <editeng/langitem.hxx>
40 #include <svx/clipfmtitem.hxx>
41 #include <svx/contdlg.hxx>
42 #include <vcl/graph.hxx>
43 #include <svl/slstitm.hxx>
44 #include <vcl/msgbox.hxx>
45 #include <svl/ptitem.hxx>
46 #include <svl/itemiter.hxx>
47 #include <svl/stritem.hxx>
48 #include <editeng/colritem.hxx>
49 #include <editeng/shaditem.hxx>
50 #include <editeng/boxitem.hxx>
51 #include <svl/srchitem.hxx>
52 #include <editeng/ulspitem.hxx>
53 #include <editeng/lrspitem.hxx>
54 #include <editeng/brushitem.hxx>
55 #include <editeng/opaqitem.hxx>
56 #include <editeng/sizeitem.hxx>
57 #include <svx/flagsdef.hxx>
58 #include <editeng/scripttypeitem.hxx>
59 #include <sfx2/objface.hxx>
60 #include <fmturl.hxx>
61 #include <fmthdft.hxx>
62 #include <fmtclds.hxx>
63 #include <docsh.hxx>
64 #include <wrtsh.hxx>
65 #include <view.hxx>
66 #include <swmodule.hxx>
67 #include <swundo.hxx>
68 #include <fldbas.hxx>
69 #include <uitool.hxx>
70 #include <basesh.hxx>
71 #include <viewopt.hxx>
72 #include <fontcfg.hxx>
73 #include <docstat.hxx>
74 #include <usrfld.hxx>
75 #include <expfld.hxx>
76 #include <fldmgr.hxx>
77 #include <frmmgr.hxx>
78 #include <tablemgr.hxx>
79 #include <mdiexp.hxx>
80 #include <swdtflvr.hxx>
81 #include <pagedesc.hxx>
82 #include <convert.hxx>
83 #include <fmtcol.hxx>
84 #include <edtwin.hxx>
85 #include <tblafmt.hxx>
86 #include <caption.hxx>
87 #include <swwait.hxx>
88 #include <cmdid.h>
89 #include <globals.hrc>
90 #include <shells.hrc>
91 #include <statstr.hrc>
92 #include <globals.h>
93 #include <unotxdoc.hxx>
94 #include <crsskip.hxx>
95 #include <fmtinfmt.hxx>
96 #include <doc.hxx>
98 #include "swabstdlg.hxx"
99 #include "dialog.hrc"
100 #include "fldui.hrc"
101 #include "table.hrc"
102 #include <modcfg.hxx>
103 #include <instable.hxx>
104 #include <svx/fmshell.hxx> // for FN_XFORMS_DESIGN_MODE
105 #include <SwRewriter.hxx>
106 #include <comcore.hrc>
108 #include <unomid.h>
110 FlyMode SwBaseShell::eFrameMode = FLY_DRAG_END;
112 // These variables keep the state of Gallery (slot SID_GALLERY_BG_BRUSH)
113 // detected by GetGalleryState() for the subsequent ExecuteGallery() call.
115 static sal_uInt8 nParagraphPos;
116 static sal_uInt8 nGraphicPos;
117 static sal_uInt8 nOlePos;
118 static sal_uInt8 nFramePos;
119 static sal_uInt8 nTablePos;
120 static sal_uInt8 nTableRowPos;
121 static sal_uInt8 nTableCellPos;
122 static sal_uInt8 nPagePos;
123 static sal_uInt8 nHeaderPos;
124 static sal_uInt8 nFooterPos;
126 #define SwBaseShell
127 #include <sfx2/msg.hxx>
128 #include "swslots.hxx"
130 #define SWCONTOURDLG(rView) ( (SvxContourDlg*) ( rView.GetViewFrame()->GetChildWindow( \
131 SvxContourDlgChildWindow::GetChildWindowId() )-> \
132 GetWindow() ) )
134 #define SWIMAPDLG(rView) ( (SvxIMapDlg*) ( rView.GetViewFrame()->GetChildWindow( \
135 SvxIMapDlgChildWindow::GetChildWindowId() )-> \
136 GetWindow() ) )
139 using namespace ::com::sun::star;
140 using namespace ::com::sun::star::uno;
141 using namespace ::com::sun::star::frame;
142 using namespace ::com::sun::star::lang;
144 SFX_IMPL_INTERFACE(SwBaseShell, SfxShell, SW_RES(0))
146 SFX_CHILDWINDOW_REGISTRATION(SvxIMapDlgChildWindow::GetChildWindowId());
147 SFX_CHILDWINDOW_REGISTRATION(SvxContourDlgChildWindow::GetChildWindowId());
150 TYPEINIT1(SwBaseShell,SfxShell)
152 static void lcl_UpdateIMapDlg( SwWrtShell& rSh )
154 Graphic aGrf( rSh.GetIMapGraphic() );
155 GraphicType nGrfType = aGrf.GetType();
156 void* pEditObj = GRAPHIC_NONE != nGrfType && GRAPHIC_DEFAULT != nGrfType
157 ? rSh.GetIMapInventor() : 0;
158 TargetList* pList = new TargetList;
159 rSh.GetView().GetViewFrame()->GetTopFrame().GetTargetList(*pList);
161 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
162 rSh.GetFlyFrmAttr( aSet );
163 const SwFmtURL &rURL = (SwFmtURL&)aSet.Get( RES_URL );
164 SvxIMapDlgChildWindow::UpdateIMapDlg(
165 aGrf, rURL.GetMap(), pList, pEditObj );
167 for ( size_t i = 0, n = pList->size(); i < n; ++i )
168 delete pList->at( i );
169 delete pList;
172 static bool lcl_UpdateContourDlg( SwWrtShell &rSh, int nSel )
174 Graphic aGraf( rSh.GetIMapGraphic() );
175 GraphicType nGrfType = aGraf.GetType();
176 bool bRet = GRAPHIC_NONE != nGrfType && GRAPHIC_DEFAULT != nGrfType;
177 if( bRet )
179 String aGrfName;
180 if ( nSel & nsSelectionType::SEL_GRF )
181 rSh.GetGrfNms( &aGrfName, 0 );
183 SvxContourDlg *pDlg = SWCONTOURDLG(rSh.GetView());
184 pDlg->Update( aGraf, aGrfName.Len() > 0,
185 rSh.GetGraphicPolygon(), rSh.GetIMapInventor() );
187 return bRet;
190 void SwBaseShell::ExecDelete(SfxRequest &rReq)
192 SwWrtShell &rSh = GetShell();
193 SwEditWin& rTmpEditWin = GetView().GetEditWin();
194 switch(rReq.GetSlot())
196 case SID_DELETE:
197 rSh.DelRight();
198 break;
200 case FN_BACKSPACE:
202 if( rSh.IsNoNum() )
204 rSh.SttCrsrMove();
205 sal_Bool bLeft = rSh.Left( CRSR_SKIP_CHARS, sal_True, 1, sal_False );
206 if( bLeft )
208 rSh.DelLeft();
210 else
211 // JP 15.07.96: If it no longer goes forward, cancel
212 // the numbering. For example at the beginning
213 // of a doc, frame, table or an area.
214 rSh.DelNumRules();
216 rSh.EndCrsrMove();
217 break;
220 // otherwise call DelLeft
221 case FN_SHIFT_BACKSPACE:
222 rSh.DelLeft();
223 break;
224 default:
225 OSL_FAIL("wrong Dispatcher");
226 return;
228 rReq.Done();
230 //#i42732# - notify the edit window that from now on we do not use the input language
231 rTmpEditWin.SetUseInputLanguage( sal_False );
234 void SwBaseShell::ExecClpbrd(SfxRequest &rReq)
236 // Attention: At risk of suicide!
237 // After paste, paste special the shell can be destroy.
239 SwWrtShell &rSh = GetShell();
240 sal_uInt16 nId = rReq.GetSlot();
241 bool bIgnore = false;
242 switch( nId )
244 case SID_CUT:
245 case SID_COPY:
246 rView.GetEditWin().FlushInBuffer();
247 if ( rSh.HasSelection() )
249 SwTransferable* pTransfer = new SwTransferable( rSh );
250 /*??*/ uno::Reference< datatransfer::XTransferable > xRef( pTransfer );
252 if ( nId == SID_CUT && !rSh.IsSelObjProtected(FLYPROTECT_CONTENT|FLYPROTECT_PARENT) )
253 pTransfer->Cut();
254 else
256 const sal_Bool bLockedView = rSh.IsViewLocked();
257 rSh.LockView( sal_True ); //lock visible section
258 pTransfer->Copy();
259 rSh.LockView( bLockedView );
261 break;
263 return;
265 case SID_PASTE:
267 TransferableDataHelper aDataHelper(
268 TransferableDataHelper::CreateFromSystemClipboard(
269 &rSh.GetView().GetEditWin() ) );
271 if( aDataHelper.GetXTransferable().is() &&
272 SwTransferable::IsPaste( rSh, aDataHelper ))
274 // Temporary variables, because the shell could already be
275 // destroyed after the paste.
276 SwView* pView = &rView;
277 SwTransferable::Paste( rSh, aDataHelper );
278 if( rSh.IsFrmSelected() || rSh.IsObjSelected() )
279 rSh.EnterSelFrmMode();
280 pView->AttrChangedNotify( &rSh );
282 else
283 return;
285 break;
287 case SID_CLIPBOARD_FORMAT_ITEMS:
289 const SfxItemSet* pArgs = rReq.GetArgs();
290 const SfxPoolItem* pFmt;
291 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nId, sal_False, &pFmt ) )
293 TransferableDataHelper aDataHelper(
294 TransferableDataHelper::CreateFromSystemClipboard(
295 &rSh.GetView().GetEditWin()) );
296 if( aDataHelper.GetXTransferable().is()
297 /*&& SwTransferable::IsPaste( rSh, aDataHelper )*/ )
299 // Temporary variables, because the shell could already be
300 // destroyed after the paste.
301 SwView* pView = &rView;
303 SwTransferable::PasteFormat( rSh, aDataHelper,
304 ((SfxUInt32Item*)pFmt)->GetValue() );
306 //Done() has to be called before the shell has been removed
307 rReq.Done();
308 bIgnore = true;
309 if( rSh.IsFrmSelected() || rSh.IsObjSelected())
310 rSh.EnterSelFrmMode();
311 pView->AttrChangedNotify( &rSh );
315 break;
317 case SID_PASTE_UNFORMATTED:
319 TransferableDataHelper aDataHelper(
320 TransferableDataHelper::CreateFromSystemClipboard(
321 &rSh.GetView().GetEditWin()) );
322 if( aDataHelper.GetXTransferable().is() &&
323 SwTransferable::IsPaste( rSh, aDataHelper ))
325 // Temporary variables, because the shell could already be
326 // destroyed after the paste.
327 SwView* pView = &rView;
328 rReq.Ignore();
329 bIgnore = true;
330 int nRet = SwTransferable::PasteUnformatted( rSh, aDataHelper );
331 if(nRet)
333 SfxViewFrame* pViewFrame = pView->GetViewFrame();
334 uno::Reference< frame::XDispatchRecorder > xRecorder =
335 pViewFrame->GetBindings().GetRecorder();
336 if(xRecorder.is()) {
337 SfxRequest aReq( pViewFrame, SID_CLIPBOARD_FORMAT_ITEMS );
338 aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, SOT_FORMAT_STRING ) );
339 aReq.Done();
343 if (rSh.IsFrmSelected() || rSh.IsObjSelected())
344 rSh.EnterSelFrmMode();
345 pView->AttrChangedNotify( &rSh );
347 else
348 return;
350 break;
352 case SID_PASTE_SPECIAL:
354 TransferableDataHelper aDataHelper(
355 TransferableDataHelper::CreateFromSystemClipboard(
356 &rSh.GetView().GetEditWin()) );
357 if( aDataHelper.GetXTransferable().is() &&
358 SwTransferable::IsPaste( rSh, aDataHelper ))
360 // Temporary variables, because the shell could already be
361 // destroyed after the paste.
362 SwView* pView = &rView;
363 sal_uLong nFormatId = 0;
364 rReq.Ignore();
365 bIgnore = true;
366 int nRet = SwTransferable::PasteSpecial( rSh, aDataHelper, nFormatId );
367 if(nRet)
369 SfxViewFrame* pViewFrame = pView->GetViewFrame();
370 uno::Reference< frame::XDispatchRecorder > xRecorder =
371 pViewFrame->GetBindings().GetRecorder();
372 if(xRecorder.is()) {
373 SfxRequest aReq( pViewFrame, SID_CLIPBOARD_FORMAT_ITEMS );
374 aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, nFormatId ) );
375 aReq.Done();
379 if (rSh.IsFrmSelected() || rSh.IsObjSelected())
380 rSh.EnterSelFrmMode();
381 pView->AttrChangedNotify( &rSh );
383 else
384 return;
386 break;
387 default:
388 OSL_FAIL("wrong Dispatcher");
389 return;
391 if(!bIgnore)
392 rReq.Done();
395 // ClipBoard state
397 void SwBaseShell::StateClpbrd(SfxItemSet &rSet)
399 SwWrtShell &rSh = GetShell();
400 SfxWhichIter aIter(rSet);
402 const sal_Bool bCopy = rSh.HasSelection();
404 sal_uInt16 nWhich = aIter.FirstWhich();
406 while(nWhich)
408 switch(nWhich)
410 case SID_CUT:
411 if( 0 != rSh.IsSelObjProtected(FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) )
413 rSet.DisableItem( nWhich );
414 break;
416 case SID_COPY:
417 if( !bCopy )
418 rSet.DisableItem( nWhich );
419 break;
421 case SID_PASTE:
422 if( !GetView().IsPasteAllowed() )
423 rSet.DisableItem( SID_PASTE );
424 break;
426 case SID_PASTE_SPECIAL:
427 if( !GetView().IsPasteSpecialAllowed() )
429 rSet.DisableItem( SID_PASTE_SPECIAL );
430 rSet.DisableItem( SID_PASTE_UNFORMATTED );
432 break;
434 case SID_CLIPBOARD_FORMAT_ITEMS:
436 TransferableDataHelper aDataHelper(
437 TransferableDataHelper::CreateFromSystemClipboard(
438 &rSh.GetView().GetEditWin()) );
440 SvxClipboardFmtItem aFmtItem( nWhich );
441 SwTransferable::FillClipFmtItem( rSh, aDataHelper, aFmtItem );
442 rSet.Put( aFmtItem );
444 break;
446 nWhich = aIter.NextWhich();
450 // Perform undo
452 void SwBaseShell::ExecUndo(SfxRequest &rReq)
454 SwWrtShell &rSh = GetShell();
456 sal_uInt16 nId = rReq.GetSlot(), nCnt = 1;
457 const SfxItemSet* pArgs = rReq.GetArgs();
458 const SfxPoolItem* pItem;
459 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nId, sal_False, &pItem ))
460 nCnt = ((SfxUInt16Item*)pItem)->GetValue();
462 // #i106349#: save pointer: undo/redo may delete the shell, i.e., this!
463 SfxViewFrame *const pViewFrame( GetView().GetViewFrame() );
465 switch( nId )
467 case SID_UNDO:
468 rSh.LockPaint();
469 rSh.Do( SwWrtShell::UNDO, nCnt );
470 rSh.UnlockPaint();
471 break;
473 case SID_REDO:
474 rSh.LockPaint();
475 rSh.Do( SwWrtShell::REDO, nCnt );
476 rSh.UnlockPaint();
477 break;
479 case SID_REPEAT:
480 rSh.Do( SwWrtShell::REPEAT );
481 break;
482 default:
483 OSL_FAIL("wrong Dispatcher");
486 if (pViewFrame) { pViewFrame->GetBindings().InvalidateAll(sal_False); }
489 // State of undo
491 void SwBaseShell::StateUndo(SfxItemSet &rSet)
493 SwWrtShell &rSh = GetShell();
494 SfxWhichIter aIter(rSet);
495 sal_uInt16 nWhich = aIter.FirstWhich();
496 while(nWhich)
498 switch(nWhich)
500 case SID_UNDO:
502 if (rSh.GetLastUndoInfo(0, 0))
504 rSet.Put( SfxStringItem(nWhich,
505 rSh.GetDoString(SwWrtShell::UNDO)));
507 else
508 rSet.DisableItem(nWhich);
509 break;
511 case SID_REDO:
513 if (rSh.GetFirstRedoInfo(0))
515 rSet.Put(SfxStringItem(nWhich,
516 rSh.GetDoString(SwWrtShell::REDO)));
518 else
519 rSet.DisableItem(nWhich);
520 break;
522 case SID_REPEAT:
523 { // Repeat is only possible if no REDO is possible - UI-Restriction
524 if ((!rSh.GetFirstRedoInfo(0)) &&
525 !rSh.IsSelFrmMode() &&
526 (UNDO_EMPTY != rSh.GetRepeatInfo(0)))
528 rSet.Put(SfxStringItem(nWhich, rSh.GetRepeatString()));
530 else
531 rSet.DisableItem(nWhich);
532 break;
535 case SID_GETUNDOSTRINGS:
536 if (rSh.GetLastUndoInfo(0, 0))
538 SfxStringListItem aStrLst( nWhich );
539 rSh.GetDoStrings( SwWrtShell::UNDO, aStrLst );
540 rSet.Put( aStrLst );
542 else
543 rSet.DisableItem( nWhich );
544 break;
546 case SID_GETREDOSTRINGS:
547 if (rSh.GetFirstRedoInfo(0))
549 SfxStringListItem aStrLst( nWhich );
550 rSh.GetDoStrings( SwWrtShell::REDO, aStrLst );
551 rSet.Put( aStrLst );
553 else
554 rSet.DisableItem( nWhich );
555 break;
557 nWhich = aIter.NextWhich();
561 // Evaluate respectively dispatching the slot Id
563 void SwBaseShell::Execute(SfxRequest &rReq)
565 const SfxPoolItem *pItem;
566 SwWrtShell &rSh = GetShell();
567 const SfxItemSet* pArgs = rReq.GetArgs();
568 bool bMore = false;
570 sal_uInt16 nSlot = rReq.GetSlot();
571 switch(nSlot)
573 case FN_REPAGINATE:
575 Reference < XModel > xModel = GetView().GetDocShell()->GetModel();
576 Reference < XUnoTunnel > xDocTunnel ( xModel, UNO_QUERY );
577 SwXTextDocument *pDoc = reinterpret_cast < SwXTextDocument * > ( xDocTunnel->getSomething ( SwXTextDocument::getUnoTunnelId() ) );
578 pDoc->NotifyRefreshListeners();
579 rSh.CalcLayout();
581 break;
582 case FN_UPDATE_FIELDS:
584 rSh.UpdateDocStat();
585 rSh.EndAllTblBoxEdit();
586 rSh.ViewShell::UpdateFlds(sal_True);
588 if( rSh.IsCrsrInTbl() )
590 if( !rSh.IsTblComplexForChart() )
591 SwTableFUNC( &rSh, sal_False).UpdateChart();
592 rSh.ClearTblBoxCntnt();
593 rSh.SaveTblBoxCntnt();
596 break;
597 case FN_UPDATE_CHARTS:
599 SwWait aWait( *rView.GetDocShell(), sal_True );
600 rSh.UpdateAllCharts();
602 break;
604 case FN_UPDATE_ALL:
606 SwView& rTempView = GetView();
607 rSh.EnterStdMode();
608 if( !rSh.GetLinkManager().GetLinks().empty() )
610 rSh.StartAllAction();
611 rSh.GetLinkManager().UpdateAllLinks( false, true, true );
612 rSh.EndAllAction();
614 SfxDispatcher &rDis = *rTempView.GetViewFrame()->GetDispatcher();
615 rDis.Execute( FN_UPDATE_FIELDS );
616 rDis.Execute( FN_UPDATE_TOX );
617 rDis.Execute( FN_UPDATE_CHARTS );
618 rSh.CalcLayout();
620 break;
622 case FN_UPDATE_INPUTFIELDS:
623 rSh.UpdateInputFlds(NULL, sal_False);
624 break;
625 case FN_PREV_BOOKMARK:
626 rReq.SetReturnValue(SfxBoolItem( nSlot, rSh.GoPrevBookmark()));
627 break;
628 case FN_NEXT_BOOKMARK:
629 rReq.SetReturnValue(SfxBoolItem( nSlot, rSh.GoNextBookmark()));
630 break;
632 case FN_GOTO_NEXT_MARK:
633 case FN_GOTO_PREV_MARK:
635 SwFldMgr aFldMgr;
636 SwFieldType* pFldType = aFldMgr.GetFldType(RES_JUMPEDITFLD);
638 if (pFldType)
640 if (rSh.IsSelFrmMode())
642 rSh.UnSelectFrm();
643 rSh.LeaveSelFrmMode();
646 if (rSh.HasMark())
648 SwMvContext aMvContext(&rSh);
649 if (rSh.IsCrsrPtAtEnd())
650 rSh.SwapPam();
651 rSh.ClearMark();
652 rSh.EndSelect();
654 sal_Bool bRet = rSh.MoveFldType(pFldType, nSlot == FN_GOTO_NEXT_MARK);
655 SwField* pCurField = bRet ? rSh.GetCurFld() : 0;
656 if (pCurField)
657 rSh.ClickToField(*pCurField);
658 rReq.SetReturnValue(SfxBoolItem( nSlot, bRet));
661 break;
663 case FN_START_DOC_DIRECT:
664 case FN_END_DOC_DIRECT:
666 if (rSh.IsSelFrmMode())
668 rSh.UnSelectFrm();
669 rSh.LeaveSelFrmMode();
671 rSh.EnterStdMode();
672 nSlot == FN_START_DOC_DIRECT ?
673 rSh.SttEndDoc(sal_True) :
674 rSh.SttEndDoc(sal_False);
676 break;
677 case FN_GOTO_PREV_OBJ:
678 case FN_GOTO_NEXT_OBJ:
680 sal_Bool bSuccess = rSh.GotoObj(
681 nSlot == FN_GOTO_NEXT_OBJ ? sal_True : sal_False);
682 rReq.SetReturnValue(SfxBoolItem(nSlot, bSuccess));
683 if (bSuccess && !rSh.IsSelFrmMode())
685 rSh.HideCrsr();
686 rSh.EnterSelFrmMode();
687 GetView().AttrChangedNotify( &rSh );
690 break;
691 case SID_GALLERY_FORMATS:
693 const int nSelType = rSh.GetSelectionType();
694 if(SFX_ITEM_SET == pArgs->GetItemState( nSlot, sal_True, &pItem))
696 GalleryExplorer* pGal = 0;
697 if ( (!rSh.IsSelFrmMode() || nSelType & nsSelectionType::SEL_GRF) &&
698 0!= (pGal = SVX_GALLERY())&&
699 0 != (SGA_FORMAT_GRAPHIC & ((SfxUInt32Item*)pItem)->GetValue()))
701 SwWait aWait( *rView.GetDocShell(), sal_True );
703 String aGrfName, aFltName;
704 const Graphic aGrf( pGal->GetGraphic() );
706 if( pGal->IsLinkage() )
708 // Linked
709 aGrfName = pGal->GetURL().GetMainURL(INetURLObject::NO_DECODE);
710 aFltName = pGal->GetFilterName();
713 if ( nSelType & nsSelectionType::SEL_GRF )
714 rSh.ReRead( aGrfName, aFltName, &aGrf );
715 else
716 rSh.Insert( aGrfName, aFltName, aGrf );
718 GetView().GetEditWin().GrabFocus();
720 else if(!rSh.IsSelFrmMode() && SGA_FORMAT_SOUND & ((SfxUInt32Item*)pItem)->GetValue())
722 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, pGal->GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
723 GetView().GetViewFrame()->GetDispatcher()->Execute( SID_INSERT_AVMEDIA, SFX_CALLMODE_SYNCHRON, &aMediaURLItem, 0L );
727 break;
728 case FN_PAGE_STYLE_SET_COLS:
730 if (pArgs)
732 // Determine the current PageDescriptor and fill the set with that.
733 const sal_uInt16 nCurIdx = rSh.GetCurPageDesc();
734 SwPageDesc aPageDesc(rSh.GetPageDesc(nCurIdx));
736 SwFrmFmt &rFmt = aPageDesc.GetMaster();
738 SwFmtCol aFmtCol = rFmt.GetCol();
740 sal_uInt16 nCount;
741 if(SFX_ITEM_SET == pArgs->GetItemState(nSlot))
742 nCount = ((SfxUInt16Item &)pArgs->Get(nSlot)).GetValue();
743 else
744 nCount = ((SfxUInt16Item &)pArgs->Get(SID_ATTR_COLUMNS)).GetValue();
745 sal_uInt16 nGutterWidth = DEF_GUTTER_WIDTH;
747 aFmtCol.Init(nCount ? nCount : 1, nGutterWidth, USHRT_MAX);
748 aFmtCol.SetWishWidth(USHRT_MAX);
749 aFmtCol.SetGutterWidth(nGutterWidth, USHRT_MAX);
751 rFmt.SetFmtAttr(aFmtCol);
753 rSh.ChgPageDesc(nCurIdx, aPageDesc);
755 else
756 GetView().GetViewFrame()->GetDispatcher()->Execute(FN_FORMAT_PAGE_COLUMN_DLG, sal_False);
758 break;
759 case FN_CONVERT_TABLE_TO_TEXT:
760 case FN_CONVERT_TEXT_TO_TABLE:
761 case FN_CONVERT_TEXT_TABLE:
763 sal_Unicode cDelim = 0;
764 bool bToTable = false;
765 if( nSlot == FN_CONVERT_TEXT_TO_TABLE ||
766 ( nSlot == FN_CONVERT_TEXT_TABLE && 0 == rSh.GetTableFmt() ))
767 bToTable = true;
768 SwInsertTableOptions aInsTblOpts( tabopts::ALL_TBL_INS_ATTR, 1 );
769 SwTableAutoFmt const* pTAFmt = 0;
770 SwTableAutoFmtTbl* pAutoFmtTbl = 0;
771 bool bDeleteFormat = true;
772 if(pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_1, sal_True, &pItem))
774 aInsTblOpts.mnInsMode = 0;
775 // Delimiter
776 String sDelim = static_cast< const SfxStringItem* >(pItem)->GetValue();
777 if(sDelim.Len())
778 cDelim = sDelim.GetChar(0);
779 // AutoFormat
780 if(SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_2, sal_True, &pItem))
782 String sAutoFmt = static_cast< const SfxStringItem* >(pItem)->GetValue();
784 pAutoFmtTbl = new SwTableAutoFmtTbl;
785 pAutoFmtTbl->Load();
787 for( sal_uInt16 i = 0, nCount = pAutoFmtTbl->size(); i < nCount; i++ )
789 SwTableAutoFmt const*const pFmt = &(*pAutoFmtTbl)[ i ];
790 if( pFmt->GetName() == sAutoFmt )
792 pTAFmt = pFmt;
793 bDeleteFormat = false;
794 break;
798 //WithHeader
799 if(SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_3, sal_True, &pItem) &&
800 static_cast< const SfxBoolItem* >(pItem)->GetValue())
801 aInsTblOpts.mnInsMode |= tabopts::HEADLINE;
802 // RepeatHeaderLines
803 if(SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_4, sal_True, &pItem))
804 aInsTblOpts.mnRowsToRepeat =
805 (sal_uInt16)static_cast< const SfxInt16Item* >(pItem)->GetValue();
806 //WithBorder
807 if(SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_5, sal_True, &pItem) &&
808 static_cast< const SfxBoolItem* >(pItem)->GetValue())
809 aInsTblOpts.mnInsMode |= tabopts::DEFAULT_BORDER;
810 //DontSplitTable
811 if(SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_6, sal_True, &pItem) &&
812 !static_cast< const SfxBoolItem* >(pItem)->GetValue() )
813 aInsTblOpts.mnInsMode |= tabopts::SPLIT_LAYOUT;
815 else
817 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
818 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
820 AbstractSwConvertTableDlg* pDlg = pFact->CreateSwConvertTableDlg(GetView(), bToTable);
821 OSL_ENSURE(pDlg, "Dialogdiet fail!");
822 if( RET_OK == pDlg->Execute() )
824 pDlg->GetValues( cDelim, aInsTblOpts, pTAFmt );
827 delete pDlg;
830 if( cDelim )
832 //Shell change!
833 SwView& rSaveView = rView;
834 sal_Bool bInserted = sal_False;
835 //recording:
836 SfxViewFrame* pViewFrame = GetView().GetViewFrame();
837 if( SfxRequest::HasMacroRecorder(pViewFrame) )
839 SfxRequest aReq( pViewFrame, nSlot);
840 aReq.AppendItem( SfxStringItem( FN_PARAM_1, OUString(cDelim) ));
841 if(bToTable)
843 if(pTAFmt)
844 aReq.AppendItem( SfxStringItem( FN_PARAM_2, pTAFmt->GetName()));
845 aReq.AppendItem( SfxBoolItem ( FN_PARAM_3, 0 != (aInsTblOpts.mnInsMode & tabopts::HEADLINE)));
846 aReq.AppendItem( SfxInt16Item( FN_PARAM_4, (short)aInsTblOpts.mnRowsToRepeat ));
847 aReq.AppendItem( SfxBoolItem ( FN_PARAM_5, 0 != (aInsTblOpts.mnInsMode & tabopts::DEFAULT_BORDER) ));
848 aReq.AppendItem( SfxBoolItem ( FN_PARAM_6, !(aInsTblOpts.mnInsMode & tabopts::SPLIT_LAYOUT)));
850 aReq.Done();
853 if( !bToTable )
854 rSh.TableToText( cDelim );
855 else
857 bInserted = rSh.TextToTable( aInsTblOpts, cDelim, text::HoriOrientation::FULL, pTAFmt );
859 rSh.EnterStdMode();
861 if( bInserted )
862 rSaveView.AutoCaption( TABLE_CAP );
864 if(bDeleteFormat)
865 delete pTAFmt;
866 delete pAutoFmtTbl;
868 break;
869 case SID_STYLE_WATERCAN:
870 case SID_STYLE_UPDATE_BY_EXAMPLE:
871 case SID_STYLE_NEW_BY_EXAMPLE:
872 case SID_STYLE_APPLY:
874 ShellModes eMode = GetView().GetShellMode();
875 if ( SHELL_MODE_DRAW != eMode &&
876 SHELL_MODE_DRAW_CTRL != eMode &&
877 SHELL_MODE_DRAW_FORM != eMode &&
878 SHELL_MODE_DRAWTEXT != eMode &&
879 SHELL_MODE_BEZIER != eMode )
881 // oj #107754#
882 if ( SID_STYLE_WATERCAN == nSlot )
884 const sal_Bool bLockedView = rSh.IsViewLocked();
885 rSh.LockView( sal_True ); //lock visible section
887 GetView().GetDocShell()->ExecStyleSheet(rReq);
889 rSh.LockView( bLockedView );
891 else
892 // Will be recorded from the DocShell
893 GetView().GetDocShell()->ExecStyleSheet(rReq);
896 break;
897 case FN_ESCAPE:
898 GetView().ExecuteSlot(rReq);
899 break;
900 case SID_IMAP:
902 sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
904 SfxViewFrame* pVFrame = GetView().GetViewFrame();
905 pVFrame->ToggleChildWindow( nId );
906 pVFrame->GetBindings().Invalidate( SID_IMAP );
908 if ( pVFrame->HasChildWindow( nId ) && rSh.IsFrmSelected() )
909 lcl_UpdateIMapDlg( rSh );
911 break;
912 case SID_IMAP_EXEC:
914 SvxIMapDlg* pDlg = SWIMAPDLG(GetView());
916 // Check, if the allocation is useful or allowed at all.
917 if ( rSh.IsFrmSelected() &&
918 pDlg->GetEditingObject() == rSh.GetIMapInventor() )
920 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
921 rSh.GetFlyFrmAttr( aSet );
922 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
923 aURL.SetMap( &pDlg->GetImageMap() );
924 aSet.Put( aURL );
925 rSh.SetFlyFrmAttr( aSet );
928 break;
929 case SID_CONTOUR_DLG:
931 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
933 SfxViewFrame* pVFrame = GetView().GetViewFrame();
934 pVFrame->ToggleChildWindow( nId );
935 pVFrame->GetBindings().Invalidate( SID_CONTOUR_DLG );
937 int nSel = rSh.GetSelectionType();
938 if ( pVFrame->HasChildWindow( nId ) &&
939 (nSel & (nsSelectionType::SEL_GRF|nsSelectionType::SEL_OLE)) )
941 lcl_UpdateContourDlg( rSh, nSel );
944 break;
945 case SID_CONTOUR_EXEC:
947 SvxContourDlg *pDlg = SWCONTOURDLG(GetView());
948 // Check, if the allocation is useful or allowed at all.
949 int nSel = rSh.GetSelectionType();
950 if ( nSel & (nsSelectionType::SEL_GRF|nsSelectionType::SEL_OLE) )
952 if ( pDlg->GetEditingObject() == rSh.GetIMapInventor() )
954 rSh.StartAction();
955 SfxItemSet aSet( rSh.GetAttrPool(), RES_SURROUND, RES_SURROUND);
956 rSh.GetFlyFrmAttr( aSet );
957 SwFmtSurround aSur( (SwFmtSurround&)aSet.Get( RES_SURROUND ) );
958 if ( !aSur.IsContour() )
960 aSur.SetContour( sal_True );
961 if ( aSur.GetSurround() == SURROUND_NONE )
962 aSur.SetSurround( SURROUND_PARALLEL );
963 aSet.Put( aSur );
964 rSh.SetFlyFrmAttr( aSet );
966 const PolyPolygon aPoly( pDlg->GetPolyPolygon() );
967 rSh.SetGraphicPolygon( &aPoly );
968 if ( pDlg->IsGraphicChanged() )
969 rSh.ReRead( aEmptyStr, aEmptyStr, &pDlg->GetGraphic());
970 rSh.EndAction();
974 break;
975 case FN_FRAME_TO_ANCHOR:
977 rSh.GotoFlyAnchor();
978 rSh.EnterStdMode();
979 rSh.CallChgLnk();
981 break;
982 case FN_TOOL_ANCHOR:
983 break;
984 case FN_TOOL_ANCHOR_PAGE:
985 case FN_TOOL_ANCHOR_PARAGRAPH:
986 case FN_TOOL_ANCHOR_CHAR:
987 case FN_TOOL_ANCHOR_AT_CHAR:
988 case FN_TOOL_ANCHOR_FRAME:
990 RndStdIds eSet = nSlot == FN_TOOL_ANCHOR_PAGE
991 ? FLY_AT_PAGE
992 : nSlot == FN_TOOL_ANCHOR_PARAGRAPH
993 ? FLY_AT_PARA
994 : nSlot == FN_TOOL_ANCHOR_FRAME
995 ? FLY_AT_FLY
996 : nSlot == FN_TOOL_ANCHOR_CHAR
997 ? FLY_AS_CHAR
998 : FLY_AT_CHAR;
999 rSh.StartUndo();
1000 if( rSh.IsObjSelected() )
1001 rSh.ChgAnchor( eSet );
1002 else if( rSh.IsFrmSelected() )
1004 // The set also includes VERT/HORI_ORIENT, because the align
1005 // shall be changed in FEShell::SetFlyFrmAttr/SetFlyFrmAnchor,
1006 // possibly as a result of the anchor change.
1007 SfxItemSet aSet( GetPool(), RES_VERT_ORIENT, RES_ANCHOR );
1008 SwFmtAnchor aAnc( eSet, rSh.GetPhyPageNum() );
1009 aSet.Put( aAnc );
1010 rSh.SetFlyFrmAttr(aSet);
1012 // if new anchor is 'as char' and it is a Math object and the usual
1013 // pre-conditions are met then align the formula to the baseline of the text
1014 const uno::Reference < embed::XEmbeddedObject > xObj( rSh.GetOleRef() );
1015 const bool bDoMathBaselineAlignment = xObj.is() && SotExchange::IsMath( xObj->getClassID() )
1016 && FLY_AS_CHAR == eSet && rSh.GetDoc()->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT );
1017 if (bDoMathBaselineAlignment)
1018 rSh.AlignFormulaToBaseline( xObj );
1020 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
1021 if( nHtmlMode )
1023 SfxItemSet aSet(GetPool(), RES_SURROUND, RES_HORI_ORIENT);
1024 rSh.GetFlyFrmAttr(aSet);
1026 const SwFmtSurround& rSurround = (const SwFmtSurround&)aSet.Get(RES_SURROUND);
1027 const SwFmtVertOrient& rVert = (const SwFmtVertOrient&)aSet.Get(RES_VERT_ORIENT);
1028 const SwFmtHoriOrient& rHori = (const SwFmtHoriOrient&)aSet.Get(RES_HORI_ORIENT);
1029 sal_Int16 eVOrient = rVert.GetVertOrient();
1030 sal_Int16 eHOrient = rHori.GetHoriOrient();
1031 SwSurround eSurround = rSurround.GetSurround();
1033 switch( eSet )
1035 case FLY_AT_FLY:
1036 case FLY_AT_PAGE:
1037 //Wrap through, left or from left, top, from top
1038 if(eSurround != SURROUND_THROUGHT)
1039 aSet.Put(SwFmtSurround(SURROUND_THROUGHT));
1041 if( eVOrient != text::VertOrientation::TOP && eVOrient != text::VertOrientation::NONE)
1042 aSet.Put(SwFmtVertOrient(0, text::VertOrientation::TOP));
1044 if(eHOrient != text::HoriOrientation::NONE || eHOrient != text::HoriOrientation::LEFT)
1045 aSet.Put(SwFmtHoriOrient(0, text::HoriOrientation::LEFT));
1046 break;
1048 case FLY_AT_PARA:
1049 // left, from left, right, top, no wrap, wrap left and right
1050 if(eSurround != SURROUND_LEFT || eSurround != SURROUND_RIGHT)
1051 aSet.Put(SwFmtSurround(SURROUND_LEFT));
1053 if( eVOrient != text::VertOrientation::TOP)
1054 aSet.Put(SwFmtVertOrient(0, text::VertOrientation::TOP));
1056 if(eHOrient != text::HoriOrientation::NONE || eHOrient != text::HoriOrientation::LEFT || eHOrient != text::HoriOrientation::RIGHT)
1057 aSet.Put(SwFmtHoriOrient(0, text::HoriOrientation::LEFT));
1058 break;
1060 case FLY_AT_CHAR:
1061 // left, from left, right, top, wrap through
1062 if(eSurround != SURROUND_THROUGHT)
1063 aSet.Put(SwFmtSurround(SURROUND_THROUGHT));
1065 if( eVOrient != text::VertOrientation::TOP)
1066 aSet.Put(SwFmtVertOrient(0, text::VertOrientation::TOP));
1068 if(eHOrient != text::HoriOrientation::NONE || eHOrient != text::HoriOrientation::LEFT || eHOrient != text::HoriOrientation::RIGHT)
1069 aSet.Put(SwFmtHoriOrient(0, text::HoriOrientation::LEFT));
1070 break;
1072 default:
1076 if( aSet.Count() )
1077 rSh.SetFlyFrmAttr( aSet );
1079 rSh.EndUndo();
1081 GetView().GetViewFrame()->GetBindings().Invalidate( FN_TOOL_ANCHOR );
1083 break;
1085 case FN_FRAME_NOWRAP:
1086 case FN_FRAME_WRAP:
1087 case FN_FRAME_WRAP_IDEAL:
1088 case FN_FRAME_WRAPTHRU:
1089 case FN_FRAME_WRAPTHRU_TRANSP:
1090 case FN_FRAME_WRAP_CONTOUR:
1091 case FN_WRAP_ANCHOR_ONLY:
1092 case FN_FRAME_WRAP_LEFT:
1093 case FN_FRAME_WRAP_RIGHT:
1094 SetWrapMode( nSlot );
1095 break;
1097 case FN_UPDATE_ALL_LINKS:
1099 if( !rSh.GetLinkManager().GetLinks().empty() )
1101 rSh.EnterStdMode();
1102 rSh.StartAllAction();
1103 rSh.GetLinkManager().UpdateAllLinks( false, false, false );
1104 rSh.EndAllAction();
1107 break;
1109 case FN_XFORMS_DESIGN_MODE:
1110 if( pArgs != NULL
1111 && pArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET
1112 && pItem != NULL
1113 && pItem->ISA( SfxBoolItem ) )
1115 sal_Bool bDesignMode =
1116 static_cast<const SfxBoolItem*>( pItem )->GetValue();
1118 // set form design mode
1119 OSL_ENSURE( GetView().GetFormShell() != NULL, "form shell?" );
1120 SfxRequest aReq( GetView().GetViewFrame(), SID_FM_DESIGN_MODE );
1121 aReq.AppendItem( SfxBoolItem( SID_FM_DESIGN_MODE, bDesignMode ) );
1122 GetView().GetFormShell()->Execute( aReq );
1123 aReq.Done();
1125 // also set suitable view options
1126 SwViewOption aViewOption = *rSh.GetViewOptions();
1127 aViewOption.SetFormView( ! bDesignMode );
1128 rSh.ApplyViewOptions( aViewOption );
1130 break;
1132 default:
1133 bMore = true;
1135 if(bMore && pArgs)
1137 pItem = 0;
1138 pArgs->GetItemState(GetPool().GetWhich(nSlot), sal_False, &pItem);
1139 if(pItem)
1140 switch(nSlot)
1142 case SID_ATTR_BRUSH:
1143 case SID_ATTR_BORDER_SHADOW:
1144 case RES_SHADOW:
1146 rSh.StartAllAction();
1147 SfxItemSet aSet( rSh.GetAttrPool(),
1148 RES_SHADOW, RES_SHADOW,
1149 RES_BACKGROUND, RES_BACKGROUND, 0 );
1151 aSet.Put(*pItem);
1152 // Tabele cell(s) selected?
1153 if ( rSh.IsTableMode() )
1155 SwFrmFmt *pFmt = rSh.GetTableFmt();
1156 pFmt->SetFmtAttr( *pItem );
1158 else if ( rSh.IsFrmSelected() )
1160 // Set border attributes via Frame-Manager.
1161 SwFlyFrmAttrMgr aMgr( sal_False, &rSh, FRMMGR_TYPE_NONE );
1162 aMgr.SetAttrSet( *pArgs );
1163 aMgr.UpdateFlyFrm();
1165 else
1167 rSh.SetAttr( *pArgs );
1169 rSh.EndAllAction();
1171 break;
1172 case FN_PAGE_STYLE_SET_LR_MARGIN:
1173 case FN_PAGE_STYLE_SET_UL_MARGIN:
1174 case FN_PAGE_STYLE_SET_NUMBER_FORMAT:
1175 case FN_PAGE_STYLE_SET_PAPER_SIZE:
1176 case FN_PAGE_STYLE_SET_PAPER_BIN:
1178 OSL_FAIL("not implemented");
1180 break;
1182 case SID_ATTR_BORDER_OUTER:
1184 // Tabele cell(s) selected?
1185 if ( rSh.IsTableMode() )
1187 // Set border attributes Get/SetTabBorders()
1188 rSh.SetTabBorders(*pArgs);
1190 else if ( rSh.IsFrmSelected() )
1192 // Set border attributes via Frame-Manager.
1193 SwFlyFrmAttrMgr aMgr( sal_False, &rSh, FRMMGR_TYPE_NONE );
1194 aMgr.SetAttrSet(*pArgs);
1195 aMgr.UpdateFlyFrm();
1197 else
1199 // Set border attributes via shell quite normally.
1200 rSh.SetAttr( *pItem );
1203 break;
1204 default:
1205 OSL_FAIL("wrong Dispatcher");
1211 // Here the state fpr SID_IMAP / SID_CONTOUR will be handled
1212 // until the swapping of the graphic is finished.
1214 IMPL_LINK_NOARG(SwBaseShell, GraphicArrivedHdl)
1216 sal_uInt16 nGrfType;
1217 SwWrtShell &rSh = GetShell();
1218 if( CNT_GRF == rSh.SwEditShell::GetCntType() &&
1219 GRAPHIC_NONE != ( nGrfType = rSh.GetGraphicType() ) &&
1220 !aGrfUpdateSlots.empty() )
1222 bool bProtect = 0 != rSh.IsSelObjProtected(FLYPROTECT_CONTENT|FLYPROTECT_PARENT);
1223 SfxViewFrame* pVFrame = GetView().GetViewFrame();
1224 sal_uInt16 nSlot;
1225 std::set<sal_uInt16>::iterator it;
1226 for( it = aGrfUpdateSlots.begin(); it != aGrfUpdateSlots.end(); ++it )
1228 sal_Bool bSetState = sal_False;
1229 sal_Bool bState = sal_False;
1230 switch( nSlot = *it )
1232 case SID_IMAP:
1233 case SID_IMAP_EXEC:
1235 sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1236 SvxIMapDlg *pDlg = pVFrame->HasChildWindow( nId ) ?
1237 (SvxIMapDlg*) ( pVFrame->GetChildWindow( nId )
1238 ->GetWindow()) : 0;
1240 if( pDlg && ( SID_IMAP_EXEC == nSlot ||
1241 ( SID_IMAP == nSlot && !bProtect)) &&
1242 pDlg->GetEditingObject() != rSh.GetIMapInventor())
1243 lcl_UpdateIMapDlg( rSh );
1245 if( !bProtect && SID_IMAP == nSlot )
1246 bSetState = sal_True, bState = 0 != pDlg;
1248 break;
1250 case SID_CONTOUR_DLG:
1251 if( !bProtect )
1253 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1254 SvxIMapDlg *pDlg = pVFrame->HasChildWindow( nId ) ?
1255 (SvxIMapDlg*) ( pVFrame->GetChildWindow( nId )
1256 ->GetWindow()) : 0;
1257 if( pDlg && pDlg->GetEditingObject() !=
1258 rSh.GetIMapInventor() )
1259 lcl_UpdateContourDlg( rSh, nsSelectionType::SEL_GRF );
1261 bSetState = sal_True;
1262 bState = 0 != pDlg;
1264 break;
1266 case FN_FRAME_WRAP_CONTOUR:
1267 if( !bProtect )
1269 SfxItemSet aSet(GetPool(), RES_SURROUND, RES_SURROUND);
1270 rSh.GetFlyFrmAttr(aSet);
1271 const SwFmtSurround& rWrap = (const SwFmtSurround&)aSet.Get(RES_SURROUND);
1272 bSetState = sal_True;
1273 bState = rWrap.IsContour();
1275 break;
1277 case SID_GRFFILTER:
1278 case SID_GRFFILTER_INVERT:
1279 case SID_GRFFILTER_SMOOTH:
1280 case SID_GRFFILTER_SHARPEN:
1281 case SID_GRFFILTER_REMOVENOISE:
1282 case SID_GRFFILTER_SOBEL:
1283 case SID_GRFFILTER_MOSAIC:
1284 case SID_GRFFILTER_EMBOSS:
1285 case SID_GRFFILTER_POSTER:
1286 case SID_GRFFILTER_POPART:
1287 case SID_GRFFILTER_SEPIA:
1288 case SID_GRFFILTER_SOLARIZE:
1289 bSetState = bState = GRAPHIC_BITMAP == nGrfType;
1290 break;
1293 if( bSetState )
1295 SfxBoolItem aBool( nSlot, bState );
1296 if( pGetStateSet )
1297 pGetStateSet->Put( aBool );
1298 else
1299 pVFrame->GetBindings().SetState( aBool );
1302 aGrfUpdateSlots.clear();
1304 return 0;
1307 void SwBaseShell::GetState( SfxItemSet &rSet )
1309 SwWrtShell &rSh = GetShell();
1310 SfxViewFrame* pVFrame = GetView().GetViewFrame();
1311 SfxWhichIter aIter( rSet );
1312 sal_uInt16 nWhich = aIter.FirstWhich();
1313 pGetStateSet = &rSet;
1314 while ( nWhich )
1316 switch ( nWhich )
1318 case SID_GALLERY_FORMATS:
1319 if ( rSh.IsObjSelected() ||
1320 (rSh.IsSelFrmMode() &&
1321 !(rSh.GetSelectionType() & nsSelectionType::SEL_GRF)) )
1322 rSet.DisableItem( nWhich );
1323 break;
1324 case SID_GALLERY_ENABLE_ADDCOPY:
1325 // #108230# allow copy from gallery in Writer AND Writer/Web!
1326 rSet.Put( SfxBoolItem( SID_GALLERY_ENABLE_ADDCOPY, sal_True ) );
1327 break;
1328 case FN_EDIT_REGION:
1329 if( !rSh.IsAnySectionInDoc() )
1330 rSet.DisableItem(nWhich);
1331 break;
1333 case FN_INSERT_REGION:
1334 if( rSh.IsSelFrmMode() ||
1335 !rSh.IsInsRegionAvailable() )
1336 rSet.DisableItem( nWhich );
1337 break;
1338 case FN_CONVERT_TABLE_TO_TEXT:
1340 sal_uInt16 eFrmType = rSh.GetFrmType(0,sal_True);
1341 if( (eFrmType & FRMTYPE_FOOTNOTE) ||
1342 !rSh.GetTableFmt() )
1343 rSet.DisableItem( nWhich );
1345 break;
1346 case FN_CONVERT_TEXT_TO_TABLE:
1348 sal_uInt16 eFrmType = rSh.GetFrmType(0,sal_True);
1349 if( (eFrmType & FRMTYPE_FOOTNOTE) ||
1350 !rSh.IsTextToTableAvailable() )
1351 rSet.DisableItem( nWhich );
1353 break;
1354 case FN_CONVERT_TEXT_TABLE:
1356 sal_uInt16 eFrmType = rSh.GetFrmType(0,sal_True);
1357 if( (eFrmType & FRMTYPE_FOOTNOTE) ||
1358 (!rSh.GetTableFmt() && !rSh.IsTextToTableAvailable() ) )
1359 rSet.DisableItem( nWhich );
1361 break;
1362 case RES_SHADOW:
1364 SfxItemSet aSet( rSh.GetAttrPool(),
1365 RES_SHADOW, RES_SHADOW );
1367 // Table cell(s) selected?
1368 if ( rSh.IsTableMode() )
1370 SwFrmFmt *pFmt = rSh.GetTableFmt();
1371 aSet.Put(pFmt->GetFmtAttr( nWhich, sal_True ));
1373 else if( rSh.IsFrmSelected() )
1375 SwFlyFrmAttrMgr aMgr( sal_False, &rSh, FRMMGR_TYPE_NONE );
1376 aSet.Put( aMgr.GetAttrSet() );
1378 else
1379 rSh.GetCurAttr( aSet );
1381 const SvxShadowItem& rShItem = (const SvxShadowItem&)aSet.Get(nWhich);
1382 rSet.Put(rShItem);
1384 break;
1385 case SID_IMAP:
1387 // #i59688#
1388 // Improve efficiency:
1389 // If selected object is protected, item has to disabled.
1390 const bool bProtect = 0 != rSh.IsSelObjProtected(FLYPROTECT_CONTENT|FLYPROTECT_PARENT);
1391 if ( bProtect )
1393 rSet.DisableItem( nWhich );
1395 else
1397 const sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1398 const sal_Bool bHas = pVFrame->HasChildWindow( nId );
1399 const sal_Bool bFrmSel = rSh.IsFrmSelected();
1400 const bool bIsGraphicSelection =
1401 rSh.GetSelectionType() == nsSelectionType::SEL_GRF;
1403 // #i59688#
1404 // Avoid unnecessary loading of selected graphic.
1405 // The graphic is only needed, if the dialog is open.
1406 // If the swapping of the graphic is finished, the status
1407 // must be determined asynchronously, until this the slot
1408 // will be disabled.
1409 if ( bHas && bIsGraphicSelection && rSh.IsGrfSwapOut( sal_True ) )
1411 if( AddGrfUpdateSlot( nWhich ))
1412 rSh.GetGraphic(sal_False); // start the loading
1414 else
1416 if ( !bHas &&
1417 ( !bFrmSel ||
1418 ( bIsGraphicSelection &&
1419 rSh.GetGraphicType() == GRAPHIC_NONE ) ) )
1421 rSet.DisableItem( nWhich );
1423 else
1425 SfxBoolItem aBool(nWhich, bHas);
1426 if ( bHas && bFrmSel )
1427 lcl_UpdateIMapDlg( rSh );
1428 rSet.Put(aBool);
1433 break;
1434 case SID_IMAP_EXEC:
1436 sal_Bool bDisable = sal_False;
1437 if( !rSh.IsFrmSelected())
1438 bDisable = sal_True;
1439 sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
1440 if(!bDisable && pVFrame->HasChildWindow( nId ))
1442 if(rSh.GetSelectionType() == nsSelectionType::SEL_GRF
1443 && rSh.IsGrfSwapOut(sal_True))
1445 if( AddGrfUpdateSlot( nWhich ))
1446 rSh.GetGraphic(sal_False); // start the loading
1448 else
1450 SvxIMapDlg *pDlg = SWIMAPDLG(GetView());
1451 if( pDlg->GetEditingObject() != rSh.GetIMapInventor() )
1452 lcl_UpdateIMapDlg( rSh );
1455 rSet.Put(SfxBoolItem(nWhich, bDisable));
1457 break;
1458 case FN_BACKSPACE:
1459 case SID_DELETE:
1460 if (rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0)
1461 rSet.DisableItem( nWhich );
1462 break;
1463 case SID_CONTOUR_DLG:
1465 sal_Bool bParentCntProt = 0 != rSh.IsSelObjProtected(FLYPROTECT_CONTENT|FLYPROTECT_PARENT );
1467 if( bParentCntProt || 0 != (HTMLMODE_ON & ::GetHtmlMode(
1468 GetView().GetDocShell() )) )
1469 rSet.DisableItem( nWhich );
1470 else
1472 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1473 sal_Bool bHas = GetView().GetViewFrame()->HasChildWindow( nId );
1474 int nSel = rSh.GetSelectionType();
1475 sal_Bool bOk = 0 != (nSel & (nsSelectionType::SEL_GRF|nsSelectionType::SEL_OLE));
1477 bool bDisable = false;
1478 if( !bHas && !bOk )
1479 bDisable = true;
1480 // #i59688#
1481 // Avoid unnecessary loading of selected graphic.
1482 // The graphic is only needed, if the dialog is open.
1483 // If the swapping of the graphic is finished, the status
1484 // must be determined asynchronously, until this the slot
1485 // will be disabled.
1486 else if ( bHas && (nSel & nsSelectionType::SEL_GRF) &&
1487 rSh.IsGrfSwapOut(sal_True) )
1489 if( AddGrfUpdateSlot( nWhich ))
1490 rSh.GetGraphic(sal_False); // start the loading
1491 // #i75481#
1492 bDisable = true;
1494 else if( bHas && bOk )
1495 bDisable = !lcl_UpdateContourDlg( rSh, nSel );
1496 else if( bOk )
1498 // #i75481#
1499 // apply fix #i59688# only for selected graphics
1500 if ( nSel & nsSelectionType::SEL_GRF )
1501 bDisable = GRAPHIC_NONE == rSh.GetGraphicType();
1502 else
1503 bDisable = GRAPHIC_NONE == rSh.GetIMapGraphic().GetType();
1506 if( bDisable )
1507 rSet.DisableItem( nWhich );
1508 else
1509 rSet.Put( SfxBoolItem(nWhich, bHas) );
1512 break;
1513 case SID_CONTOUR_EXEC:
1515 sal_Bool bDisable = sal_False;
1516 int nSel = rSh.GetSelectionType();
1517 if( !(nSel & (nsSelectionType::SEL_GRF|nsSelectionType::SEL_OLE)) )
1518 bDisable = sal_True;
1519 sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
1520 if( !bDisable && GetView().GetViewFrame()->HasChildWindow( nId ))
1522 SvxContourDlg *pDlg = SWCONTOURDLG(GetView());
1523 if( pDlg->GetEditingObject() != rSh.GetIMapInventor() )
1524 bDisable = sal_True;
1526 rSet.Put(SfxBoolItem(nWhich, bDisable));
1528 break;
1530 case FN_TOOL_ANCHOR:
1531 case FN_TOOL_ANCHOR_PAGE:
1532 case FN_TOOL_ANCHOR_PARAGRAPH:
1533 case FN_TOOL_ANCHOR_CHAR:
1534 case FN_TOOL_ANCHOR_AT_CHAR:
1535 case FN_TOOL_ANCHOR_FRAME:
1537 sal_Bool bObj = 0 != rSh.IsObjSelected();
1538 sal_Bool bParentCntProt = rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
1540 if( !bParentCntProt && (bObj || rSh.IsFrmSelected()))
1542 SfxItemSet aSet(GetPool(), RES_ANCHOR, RES_ANCHOR);
1543 if(bObj)
1544 rSh.GetObjAttr(aSet);
1545 else
1546 rSh.GetFlyFrmAttr(aSet);
1547 RndStdIds eSet = ((SwFmtAnchor&)aSet.Get(RES_ANCHOR)).GetAnchorId();
1548 const sal_Bool bSet =
1549 ((nWhich == FN_TOOL_ANCHOR_PAGE) &&
1550 (eSet == FLY_AT_PAGE))
1551 || ((nWhich == FN_TOOL_ANCHOR_PARAGRAPH) &&
1552 (eSet == FLY_AT_PARA))
1553 || ((nWhich == FN_TOOL_ANCHOR_FRAME) &&
1554 (eSet == FLY_AT_FLY))
1555 || ((nWhich == FN_TOOL_ANCHOR_AT_CHAR) &&
1556 (eSet == FLY_AT_CHAR))
1557 || ((nWhich == FN_TOOL_ANCHOR_CHAR) &&
1558 (eSet == FLY_AS_CHAR));
1559 if(nWhich != FN_TOOL_ANCHOR)
1561 if( nWhich == FN_TOOL_ANCHOR_FRAME && !rSh.IsFlyInFly() )
1562 rSet.DisableItem(nWhich);
1563 else
1564 rSet.Put(SfxBoolItem(nWhich, bSet));
1566 else
1568 sal_uInt16 nSlotId = 0;
1570 switch (eSet)
1572 case FLY_AT_PAGE:
1573 nSlotId = FN_TOOL_ANCHOR_PAGE;
1574 break;
1575 case FLY_AT_PARA:
1576 nSlotId = FN_TOOL_ANCHOR_PARAGRAPH;
1577 break;
1578 case FLY_AS_CHAR:
1579 nSlotId = FN_TOOL_ANCHOR_CHAR;
1580 break;
1581 case FLY_AT_CHAR:
1582 nSlotId = FN_TOOL_ANCHOR_AT_CHAR;
1583 break;
1584 case FLY_AT_FLY:
1585 nSlotId = FN_TOOL_ANCHOR_FRAME;
1586 break;
1587 default:
1590 rSet.Put(SfxUInt16Item(nWhich, nSlotId));
1593 else
1594 rSet.DisableItem( nWhich );
1596 break;
1597 case FN_FRAME_NOWRAP:
1598 case FN_FRAME_WRAP:
1599 case FN_FRAME_WRAP_IDEAL:
1600 case FN_FRAME_WRAPTHRU:
1601 case FN_FRAME_WRAPTHRU_TRANSP:
1602 case FN_FRAME_WRAP_CONTOUR:
1603 case FN_WRAP_ANCHOR_ONLY:
1604 case FN_FRAME_WRAP_LEFT:
1605 case FN_FRAME_WRAP_RIGHT:
1607 sal_Bool bObj = 0 != rSh.IsObjSelected();
1608 sal_Bool bParentCntProt = rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
1610 if( !bParentCntProt && (bObj || rSh.IsFrmSelected()))
1612 SfxItemSet aSet(GetPool(), RES_OPAQUE, RES_ANCHOR);
1613 int nAnchorType;
1614 if(bObj)
1616 rSh.GetObjAttr(aSet);
1617 nAnchorType = rSh.GetAnchorId();
1619 else
1621 rSh.GetFlyFrmAttr(aSet);
1622 nAnchorType = ((SwFmtAnchor&)aSet.Get(RES_ANCHOR)).GetAnchorId();
1624 const SwFmtSurround& rWrap = (const SwFmtSurround&)aSet.Get(RES_SURROUND);
1626 const SvxOpaqueItem& rOpaque = (const SvxOpaqueItem&)aSet.Get(RES_OPAQUE);
1627 sal_Bool bOpaque = rOpaque.GetValue();
1628 SwSurround nSurround = rWrap.GetSurround();
1629 sal_Bool bSet = sal_False;
1631 bool bDisable =
1632 (nAnchorType == - 1) || (nAnchorType == FLY_AS_CHAR);
1633 const bool bHtmlMode =
1634 0 != ::GetHtmlMode(GetView().GetDocShell());
1636 switch( nWhich )
1638 case FN_FRAME_NOWRAP:
1639 bDisable |=
1640 ( (nAnchorType != FLY_AT_PARA)
1641 && (nAnchorType != FLY_AT_CHAR)
1642 && (nAnchorType != FLY_AT_PAGE));
1643 bSet = nSurround == SURROUND_NONE;
1644 break;
1645 case FN_FRAME_WRAP:
1646 bDisable |= bHtmlMode;
1647 bSet = nSurround == SURROUND_PARALLEL;
1648 break;
1649 case FN_FRAME_WRAP_IDEAL:
1650 bDisable |= bHtmlMode;
1651 bSet = nSurround == SURROUND_IDEAL;
1652 break;
1653 case FN_FRAME_WRAPTHRU:
1654 bDisable |= (bHtmlMode ||
1655 ( (nAnchorType != FLY_AT_PARA)
1656 && (nAnchorType != FLY_AT_CHAR)
1657 && (nAnchorType != FLY_AT_PAGE)));
1658 if(bObj)
1659 bSet = nSurround == SURROUND_THROUGHT && rSh.GetLayerId();
1660 else
1661 bSet = nSurround == SURROUND_THROUGHT && bOpaque;
1662 break;
1663 case FN_FRAME_WRAPTHRU_TRANSP:
1664 bDisable |= bHtmlMode;
1665 if(bObj)
1666 bSet = nSurround == SURROUND_THROUGHT && !rSh.GetLayerId();
1667 else
1668 bSet = nSurround == SURROUND_THROUGHT && !bOpaque;
1669 break;
1670 case FN_FRAME_WRAP_CONTOUR:
1671 bDisable |= bHtmlMode;
1672 //no contour available whenn no wrap or wrap through is set
1673 bDisable |= (nSurround == SURROUND_NONE || nSurround == SURROUND_THROUGHT);
1674 bSet = rWrap.IsContour();
1675 if( !bDisable )
1677 int nSel = rSh.GetSelectionType();
1678 if( (nSel & nsSelectionType::SEL_GRF) &&
1679 rSh.IsGrfSwapOut(sal_True))
1681 if( AddGrfUpdateSlot( nWhich ))
1682 rSh.GetGraphic(sal_False); // start the loading
1684 else if( rSh.IsFrmSelected() )
1686 // #i102253# applied patch from OD (see task)
1687 bDisable =
1688 nSel & nsSelectionType::SEL_FRM ||
1689 GRAPHIC_NONE == rSh.GetIMapGraphic().GetType();
1692 bSet = bDisable ? sal_False : rWrap.IsContour();
1694 break;
1695 case FN_WRAP_ANCHOR_ONLY:
1696 bDisable |= (bHtmlMode ||
1697 (nAnchorType != FLY_AT_PARA));
1698 bSet = rWrap.IsAnchorOnly();
1699 break;
1700 case FN_FRAME_WRAP_LEFT:
1701 bSet = nSurround == SURROUND_LEFT;
1702 break;
1703 case FN_FRAME_WRAP_RIGHT:
1704 bSet = nSurround == SURROUND_RIGHT;
1705 break;
1708 if(bDisable)
1709 rSet.DisableItem(nWhich);
1710 else
1711 rSet.Put(SfxBoolItem(nWhich, bSet));
1713 else
1714 rSet.DisableItem(nWhich);
1716 break;
1717 case FN_UPDATE_CHARTS:
1718 if( !rSh.HasCharts() )
1719 rSet.DisableItem( nWhich );
1720 break;
1721 case FN_UPDATE_ALL_LINKS:
1722 if ( rSh.GetLinkManager().GetLinks().empty() )
1723 rSet.DisableItem(nWhich);
1724 break;
1725 case FN_XFORMS_DESIGN_MODE:
1726 // enable if in XForms document
1727 if( rSh.GetDoc()->isXForms() )
1729 // determine current state from view options
1730 sal_Bool bValue = ! rSh.GetViewOptions()->IsFormView();
1731 rSet.Put( SfxBoolItem( nWhich, bValue ) );
1733 else
1734 rSet.Put( SfxVisibilityItem( nWhich, sal_False ) );
1735 break;
1737 nWhich = aIter.NextWhich();
1739 pGetStateSet = 0;
1742 // Disable the slots with this status methode
1744 void SwBaseShell::StateDisableItems( SfxItemSet &rSet )
1746 SfxWhichIter aIter(rSet);
1747 sal_uInt16 nWhich = aIter.FirstWhich();
1749 while (nWhich)
1751 rSet.DisableItem( nWhich );
1752 nWhich = aIter.NextWhich();
1756 // Disable the slots with this status methode
1758 void SwBaseShell::StateStyle( SfxItemSet &rSet )
1760 bool bParentCntProt = GetShell().IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
1761 ShellModes eMode = GetView().GetShellMode();
1763 if ( bParentCntProt ||
1764 SHELL_MODE_DRAW == eMode ||
1765 SHELL_MODE_DRAW_CTRL == eMode ||
1766 SHELL_MODE_DRAW_FORM == eMode ||
1767 SHELL_MODE_DRAWTEXT == eMode ||
1768 SHELL_MODE_BEZIER == eMode )
1770 SfxWhichIter aIter( rSet );
1771 sal_uInt16 nWhich = aIter.FirstWhich();
1772 while ( nWhich )
1774 rSet.DisableItem( nWhich );
1775 nWhich = aIter.NextWhich();
1778 else
1779 GetView().GetDocShell()->StateStyleSheet(rSet, &GetShell());
1782 void SwBaseShell::SetWrapMode( sal_uInt16 nSlot )
1784 SwWrtShell &rSh = GetShell();
1785 bool bObj = 0 != rSh.IsObjSelected();
1786 if( bObj || rSh.IsFrmSelected())
1788 SfxItemSet aSet(GetPool(), RES_OPAQUE, RES_SURROUND);
1789 if(bObj)
1790 rSh.GetObjAttr(aSet);
1791 else
1792 rSh.GetFlyFrmAttr(aSet);
1793 SwFmtSurround aWrap( (SwFmtSurround&)aSet.Get(RES_SURROUND) );
1794 SwSurround nOldSurround(aWrap.GetSurround());
1795 SwSurround nSurround = SURROUND_PARALLEL;
1797 switch (nSlot)
1799 case FN_FRAME_NOWRAP:
1800 nSurround = SURROUND_NONE;
1801 if (aWrap.IsContour())
1802 aWrap.SetContour(sal_False);
1803 break;
1804 case FN_FRAME_WRAP_IDEAL:
1805 nSurround = SURROUND_IDEAL;
1806 break;
1807 case FN_WRAP_ANCHOR_ONLY:
1808 aWrap.SetAnchorOnly(!aWrap.IsAnchorOnly());
1810 // keep previous wrapping
1812 // switch to wrap SURROUND_PARALLEL, if previous wrap is SURROUND_NONE
1813 if ( nOldSurround != SURROUND_NONE )
1815 nSurround = nOldSurround;
1817 break;
1818 case FN_FRAME_WRAP_CONTOUR:
1819 aWrap.SetContour(!aWrap.IsContour());
1820 if (nSurround == SURROUND_THROUGHT)
1821 nSurround = SURROUND_PARALLEL;
1822 break;
1823 case FN_FRAME_WRAPTHRU_TRANSP:
1824 if (aWrap.IsContour())
1825 aWrap.SetContour(sal_False);
1826 // No break!!!
1827 case FN_FRAME_WRAPTHRU:
1828 nSurround = SURROUND_THROUGHT;
1829 break;
1831 case FN_FRAME_WRAP_LEFT:
1832 nSurround = SURROUND_LEFT;
1833 break;
1835 case FN_FRAME_WRAP_RIGHT:
1836 nSurround = SURROUND_RIGHT;
1837 break;
1839 default:
1840 break;
1842 aWrap.SetSurround(nSurround);
1844 if (nSlot != FN_FRAME_WRAP_CONTOUR)
1846 // Defaulting the contour wrap on draw objects.
1847 if (bObj && nOldSurround != nSurround &&
1848 (nOldSurround == SURROUND_NONE || nOldSurround == SURROUND_THROUGHT))
1850 aWrap.SetContour(sal_True);
1854 aSet.Put( aWrap );
1855 aSet.Put(SvxOpaqueItem(RES_OPAQUE, nSlot != FN_FRAME_WRAPTHRU_TRANSP));
1856 if(bObj)
1858 rSh.SetObjAttr(aSet);
1859 if (nSlot != FN_FRAME_WRAPTHRU_TRANSP)
1860 rSh.SelectionToHeaven();
1861 else
1862 rSh.SelectionToHell();
1864 else
1865 rSh.SetFlyFrmAttr(aSet);
1869 //Force update of the status line
1871 void SwBaseShell::SetFrmMode(FlyMode eMode, SwWrtShell *pSh )
1873 eFrameMode = eMode;
1874 SfxBindings &rBnd = pSh->GetView().GetViewFrame()->GetBindings();
1876 if( eMode == FLY_DRAG ||
1877 (pSh && (pSh->IsFrmSelected() || pSh->IsObjSelected())) )
1879 const SfxPointItem aTmp1( SID_ATTR_POSITION, pSh->GetAnchorObjDiff());
1880 const SvxSizeItem aTmp2( SID_ATTR_SIZE, pSh->GetObjSize());
1881 rBnd.SetState( aTmp1 );
1882 rBnd.SetState( aTmp2 );
1884 else if( eMode == FLY_DRAG_END )
1886 static sal_uInt16 aInval[] =
1888 SID_ATTR_POSITION, SID_ATTR_SIZE, 0
1890 rBnd.Invalidate(aInval);
1894 SwBaseShell::SwBaseShell(SwView& rVw) :
1895 SfxShell( &rVw ),
1896 rView(rVw),
1897 pGetStateSet(0)
1899 SwWrtShell& rWrtSh = rView.GetWrtShell();
1901 SetPool(&rWrtSh.GetAttrPool());
1902 SetName(OUString("Base"));
1903 rWrtSh.SetGrfArrivedLnk( LINK( this, SwBaseShell, GraphicArrivedHdl));
1906 SwBaseShell::~SwBaseShell()
1908 if( rView.GetCurShell() == this )
1909 rView.ResetSubShell();
1911 Link aTmp( LINK( this, SwBaseShell, GraphicArrivedHdl));
1912 if( aTmp == rView.GetWrtShell().GetGrfArrivedLnk() )
1913 rView.GetWrtShell().SetGrfArrivedLnk( Link() );
1916 void SwBaseShell::ExecTxtCtrl( SfxRequest& rReq )
1918 const SfxItemSet *pArgs = rReq.GetArgs();
1920 if( pArgs)
1922 SwWrtShell &rSh = GetShell();
1923 SvxScriptSetItem* pSSetItem = 0;
1924 sal_uInt16 nSlot = rReq.GetSlot();
1925 SfxItemPool& rPool = rSh.GetAttrPool();
1926 sal_uInt16 nWhich = rPool.GetWhich( nSlot );
1927 sal_uInt16 nScripts = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
1928 SfxItemSet aHeightSet( GetPool(), RES_CHRATR_FONTSIZE, RES_CHRATR_FONTSIZE,
1929 RES_CHRATR_CJK_FONTSIZE, RES_CHRATR_CJK_FONTSIZE,
1930 RES_CHRATR_CTL_FONTSIZE, RES_CHRATR_CTL_FONTSIZE,
1931 0L);
1933 switch( nSlot )
1935 case SID_ATTR_CHAR_FONT:
1937 nScripts = rSh.GetScriptType();
1938 // #i42732# input language should be preferred over
1939 // current cursor position to detect script type
1940 if(!rSh.HasSelection())
1942 LanguageType nInputLang = GetView().GetEditWin().GetInputLanguage();
1943 if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
1944 nScripts = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
1947 case SID_ATTR_CHAR_POSTURE:
1948 case SID_ATTR_CHAR_WEIGHT:
1950 pSSetItem = new SvxScriptSetItem( nSlot, rPool );
1951 pSSetItem->PutItemForScriptType( nScripts, pArgs->Get( nWhich ));
1952 pArgs = &pSSetItem->GetItemSet();
1954 break;
1955 case SID_ATTR_CHAR_FONTHEIGHT:
1957 if(rSh.HasSelection())
1959 pSSetItem = new SvxScriptSetItem( nSlot, rPool );
1960 pSSetItem->PutItemForScriptType( nScripts, pArgs->Get( nWhich ));
1961 pArgs = &pSSetItem->GetItemSet();
1963 else
1965 nScripts = rSh.GetScriptType();
1966 LanguageType nInputLang = GetView().GetEditWin().GetInputLanguage();
1967 if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
1968 nScripts = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
1969 sal_uInt32 nHeight = static_cast< const SvxFontHeightItem& >(pArgs->Get( nWhich )).GetHeight();
1970 SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
1972 SfxItemSet aLangSet( GetPool(), RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
1973 RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
1974 RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
1975 0L);
1976 rSh.GetCurAttr( aLangSet );
1978 sal_Int32 nWesternSize =
1979 pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_DEFAULT,
1980 static_cast<const SvxLanguageItem&>(aLangSet.Get( RES_CHRATR_LANGUAGE)).GetLanguage());
1981 sal_Int32 nCJKSize =
1982 pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_CJK,
1983 static_cast<const SvxLanguageItem&>(aLangSet.Get( RES_CHRATR_CJK_LANGUAGE)).GetLanguage());
1984 sal_Int32 nCTLSize =
1985 pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_CTL,
1986 static_cast<const SvxLanguageItem&>(aLangSet.Get( RES_CHRATR_CTL_LANGUAGE)).GetLanguage());
1988 switch(nScripts)
1990 case SCRIPTTYPE_LATIN:
1991 nCJKSize = nHeight * nCJKSize / nWesternSize;
1992 nCTLSize = nHeight * nCTLSize / nWesternSize;
1993 nWesternSize = (sal_Int32) nHeight;
1994 break;
1995 case SCRIPTTYPE_ASIAN:
1996 nCTLSize = nHeight* nCTLSize / nCJKSize;
1997 nWesternSize = nHeight * nWesternSize / nCJKSize;
1998 nCJKSize = (sal_Int32) nHeight;
1999 break;
2000 case SCRIPTTYPE_COMPLEX:
2001 nCJKSize = nHeight * nCJKSize / nCTLSize;
2002 nWesternSize = nHeight * nWesternSize / nCTLSize;
2003 nCTLSize = (sal_Int32) nHeight;
2004 break;
2006 aHeightSet.Put( SvxFontHeightItem( (sal_uInt32)nWesternSize, 100, RES_CHRATR_FONTSIZE ));
2007 aHeightSet.Put( SvxFontHeightItem( (sal_uInt32)nCJKSize, 100, RES_CHRATR_CJK_FONTSIZE ));
2008 aHeightSet.Put( SvxFontHeightItem( (sal_uInt32)nCTLSize, 100, RES_CHRATR_CTL_FONTSIZE ));
2009 pArgs = &aHeightSet;
2012 break;
2015 if( pArgs )
2017 bool bAuto = false;
2018 if ( !isCHRATR(nWhich) ||
2019 ( rSh.HasSelection() && rSh.IsSelFullPara() ) )
2021 SwTxtFmtColl * pColl = rSh.GetCurTxtFmtColl();
2022 if ( pColl && pColl->IsAutoUpdateFmt() )
2024 rSh.AutoUpdatePara( pColl, *pArgs );
2025 bAuto = true;
2029 if (!bAuto)
2031 rSh.SetAttr( *pArgs );
2034 delete pSSetItem;
2036 else
2037 GetView().GetViewFrame()->GetDispatcher()->Execute( SID_CHAR_DLG, sal_False);
2038 rReq.Done();
2041 void SwBaseShell::GetTxtCtrlState( SfxItemSet& rSet )
2043 SwWrtShell &rSh = GetShell();
2044 rSh.GetCurAttr( rSet );
2047 void SwBaseShell::GetTxtFontCtrlState( SfxItemSet& rSet )
2049 SwWrtShell &rSh = GetShell();
2050 bool bFirst = true;
2051 SfxItemSet* pFntCoreSet = 0;
2052 sal_uInt16 nScriptType = SCRIPTTYPE_LATIN;
2053 SfxWhichIter aIter( rSet );
2054 sal_uInt16 nWhich = aIter.FirstWhich();
2055 while( nWhich )
2057 switch( nWhich )
2059 case RES_CHRATR_FONT:
2060 case RES_CHRATR_FONTSIZE:
2061 case RES_CHRATR_WEIGHT:
2062 case RES_CHRATR_POSTURE:
2064 if( !pFntCoreSet )
2066 pFntCoreSet = new SfxItemSet( *rSet.GetPool(),
2067 RES_CHRATR_BEGIN, RES_CHRATR_END-1 );
2068 rSh.GetCurAttr( *pFntCoreSet );
2069 nScriptType = rSh.GetScriptType();
2070 // #i42732# input language should be preferred over
2071 // current cursor position to detect script type
2072 SwEditWin& rEditWin = GetView().GetEditWin();
2073 if( rEditWin.IsUseInputLanguage() )
2075 if(!rSh.HasSelection() && (
2076 nWhich == RES_CHRATR_FONT ||
2077 nWhich == RES_CHRATR_FONTSIZE ))
2079 LanguageType nInputLang = rEditWin.GetInputLanguage();
2080 if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
2081 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
2085 SfxItemPool& rPool = *rSet.GetPool();
2086 SvxScriptSetItem aSetItem( rPool.GetSlotId( nWhich ), rPool );
2087 aSetItem.GetItemSet().Put( *pFntCoreSet, sal_False );
2088 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
2089 if( pI )
2090 rSet.Put( *pI, nWhich );
2091 else
2092 rSet.InvalidateItem( nWhich );
2093 // Set input context of the SwEditWin according to the selected font and script type
2094 if(RES_CHRATR_FONT == nWhich)
2096 Font aFont;
2097 if(pI && pI->ISA(SvxFontItem))
2099 aFont.SetName( ((const SvxFontItem*)pI)->GetFamilyName());
2100 aFont.SetStyleName(((const SvxFontItem*)pI)->GetStyleName());
2101 aFont.SetFamily(((const SvxFontItem*)pI)->GetFamily());
2102 aFont.SetPitch(((const SvxFontItem*)pI)->GetPitch());
2103 aFont.SetCharSet(((const SvxFontItem*)pI)->GetCharSet());
2106 bool bVertical = rSh.IsInVerticalText();
2107 aFont.SetOrientation(bVertical ? 2700 : 0);
2108 aFont.SetVertical(bVertical ? sal_True : sal_False);
2109 GetView().GetEditWin().SetInputContext( InputContext( aFont, INPUTCONTEXT_TEXT |
2110 INPUTCONTEXT_EXTTEXTINPUT ) );
2113 break;
2115 default:
2116 if( bFirst )
2118 rSh.GetCurAttr( rSet );
2119 bFirst = false;
2122 nWhich = aIter.NextWhich();
2124 delete pFntCoreSet;
2127 void SwBaseShell::GetBckColState(SfxItemSet &rSet)
2129 SwWrtShell &rSh = GetShell();
2130 SfxWhichIter aIter( rSet );
2131 sal_uInt16 nWhich = aIter.FirstWhich();
2132 int nSelType = rSh.GetSelectionType();
2134 if( nSelType & nsSelectionType::SEL_OLE )
2136 rSet.DisableItem( SID_BACKGROUND_COLOR );
2137 return;
2140 if ( nSelType & nsSelectionType::SEL_FRM )
2142 bool bParentCntProt = rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
2143 if (bParentCntProt)
2145 rSet.DisableItem( SID_BACKGROUND_COLOR );
2146 return;
2150 SvxBrushItem aBrushItem( RES_BACKGROUND );
2152 if( nsSelectionType::SEL_TBL_CELLS & nSelType )
2153 rSh.GetBoxBackground( aBrushItem );
2154 else
2156 SfxItemSet aCoreSet(GetPool(), RES_BACKGROUND, RES_BACKGROUND);
2157 if( nSelType & nsSelectionType::SEL_GRF || nsSelectionType::SEL_FRM & nSelType )
2158 rSh.GetFlyFrmAttr( aCoreSet );
2159 else
2160 rSh.GetCurAttr( aCoreSet );
2161 aBrushItem = (const SvxBrushItem&)aCoreSet.Get(RES_BACKGROUND);
2164 while ( nWhich )
2166 switch(nWhich)
2168 case SID_BACKGROUND_COLOR :
2170 SvxColorItem aColorItem(aBrushItem.GetColor(), SID_BACKGROUND_COLOR);
2171 rSet.Put( aColorItem, SID_BACKGROUND_COLOR );
2173 break;
2174 case SID_ATTR_BRUSH:
2175 case RES_BACKGROUND:
2176 rSet.Put( aBrushItem, GetPool().GetWhich(nWhich) );
2177 break;
2179 nWhich = aIter.NextWhich();
2183 void SwBaseShell::ExecBckCol(SfxRequest& rReq)
2185 SwWrtShell &rSh = GetShell();
2186 int nSelType = rSh.GetSelectionType();
2187 if ( nSelType & nsSelectionType::SEL_OLE )
2189 return;
2192 const SfxItemSet* pArgs = rReq.GetArgs();
2193 sal_uInt16 nSlot = rReq.GetSlot();
2194 if( !pArgs && nSlot != SID_BACKGROUND_COLOR)
2195 return ;
2197 SvxBrushItem aBrushItem( RES_BACKGROUND );
2199 if( nsSelectionType::SEL_TBL_CELLS & nSelType )
2201 rSh.GetBoxBackground( aBrushItem );
2203 else
2205 SfxItemSet aCoreSet(GetPool(), RES_BACKGROUND, RES_BACKGROUND);
2206 if( (nsSelectionType::SEL_FRM & nSelType) || (nsSelectionType::SEL_GRF & nSelType) )
2207 rSh.GetFlyFrmAttr( aCoreSet );
2208 else
2209 rSh.GetCurAttr( aCoreSet );
2210 aBrushItem = (const SvxBrushItem&)aCoreSet.Get(RES_BACKGROUND);
2213 switch (nSlot)
2215 // RES_BACKGROUND (=SID_ATTR_BRUSH) must be set with two IDs:
2216 case SID_BACKGROUND_COLOR:
2218 aBrushItem.SetGraphicPos(GPOS_NONE);
2220 if(pArgs)
2222 const SvxColorItem& rNewColorItem = (const SvxColorItem&)
2223 pArgs->Get(SID_BACKGROUND_COLOR);
2224 const Color& rNewColor = rNewColorItem.GetValue();
2225 aBrushItem.SetColor( rNewColor );
2226 GetView().GetViewFrame()->GetBindings().SetState(rNewColorItem);
2228 else
2230 aBrushItem.SetColor( COL_TRANSPARENT );
2231 rReq.AppendItem( SvxColorItem( Color( COL_TRANSPARENT ), nSlot ) );
2234 break;
2236 case SID_ATTR_BRUSH:
2237 case RES_BACKGROUND:
2239 const SvxBrushItem& rNewBrushItem = (const SvxBrushItem&)
2240 pArgs->Get( GetPool().GetWhich(nSlot) );
2241 aBrushItem = rNewBrushItem;
2243 break;
2244 default:
2245 rReq.Ignore();
2246 OSL_FAIL("unknown message in ExecuteAttr!" );
2247 return;
2250 if( nsSelectionType::SEL_TBL_CELLS & nSelType )
2252 rSh.SetBoxBackground( aBrushItem );
2254 else if( (nsSelectionType::SEL_FRM & nSelType) ||
2255 (nsSelectionType::SEL_GRF & nSelType) )
2257 SfxItemSet aCoreSet(GetPool(), RES_BACKGROUND, RES_BACKGROUND);
2258 aCoreSet.Put( aBrushItem );
2259 // Template autoupdate
2260 SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
2261 if(pFmt && pFmt->IsAutoUpdateFmt())
2262 rSh.AutoUpdateFrame( pFmt, aCoreSet);
2263 else
2264 rSh.SetFlyFrmAttr( aCoreSet );
2266 else
2268 SwTxtFmtColl* pColl = rSh.GetCurTxtFmtColl();
2269 if( pColl && pColl->IsAutoUpdateFmt())
2271 SfxItemSet aSet(GetPool(), RES_BACKGROUND, RES_BACKGROUND );
2272 aSet.Put(aBrushItem);
2273 rSh.AutoUpdatePara( pColl, aSet);
2275 else
2276 rSh.SetAttr( aBrushItem );
2279 rReq.Done();
2282 void SwBaseShell::GetBorderState(SfxItemSet &rSet)
2284 SwWrtShell &rSh = GetShell();
2285 // Tabele cell(s) selected?
2286 bool bPrepare = true;
2287 sal_Bool bTableMode = rSh.IsTableMode();
2288 if ( bTableMode )
2290 SfxItemSet aCoreSet( GetPool(),
2291 RES_BOX, RES_BOX,
2292 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER, 0 );
2293 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
2294 aCoreSet.Put( aBoxInfo );
2295 rSh.GetTabBorders( aCoreSet );
2296 rSet.Put( aCoreSet );
2298 else if ( rSh.IsFrmSelected() )
2300 SwFlyFrmAttrMgr aMgr( sal_False, &rSh, FRMMGR_TYPE_NONE );
2301 rSet.Put( aMgr.GetAttrSet() );
2302 bPrepare = false;
2304 else
2305 // Get border attributes via shell quite normal
2306 rSh.GetCurAttr( rSet );
2307 if ( bPrepare )
2308 ::PrepareBoxInfo( rSet, rSh );
2309 // Switch the border toolbox controller mode
2310 rSet.Put( SfxBoolItem( SID_BORDER_REDUCED_MODE, !bTableMode ));
2313 void SwBaseShell::ExecDlg(SfxRequest &rReq)
2315 SwWrtShell &rSh = GetShell();
2316 Window *pMDI = &GetView().GetViewFrame()->GetWindow();
2317 // So that from the basic no dialogues for the background views are called:
2318 bool bBackground = (&GetView() != GetActiveView());
2319 const SfxPoolItem* pItem = 0;
2320 const SfxItemSet* pArgs = rReq.GetArgs();
2322 sal_uInt16 nSlot = rReq.GetSlot();
2323 const SfxItemSet* pOutSet = 0;
2324 bool bDone = false;
2325 if(pArgs)
2326 pArgs->GetItemState( GetPool().GetWhich(nSlot), sal_False, &pItem );
2328 switch ( nSlot )
2330 case FN_FORMAT_TITLEPAGE_DLG:
2332 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2333 VclAbstractDialog* pDlg = pFact->CreateTitlePageDlg( pMDI );
2334 pDlg->Execute();
2335 delete pDlg;
2337 break;
2338 case FN_FORMAT_PAGE_DLG:
2339 case FN_FORMAT_PAGE_COLUMN_DLG:
2340 case FN_FORMAT_PAGE_SETTING_DLG:
2342 if( !bBackground )
2344 const sal_uInt16 nCurIdx = rSh.GetCurPageDesc();
2345 const SwPageDesc& rPageDesc = rSh.GetPageDesc( nCurIdx );
2346 // Temporary view, because the shell does not need to be valid after the dialogue
2347 // for example disable header
2348 SwView& rTempView = GetView();
2349 rTempView.GetDocShell()->FormatPage(
2350 rPageDesc.GetName(),
2351 nSlot,
2352 rSh );
2353 rTempView.InvalidateRulerPos();
2356 break;
2357 case FN_FORMAT_BORDER_DLG:
2359 SfxItemSet aSet( rSh.GetAttrPool(),
2360 RES_BOX , RES_SHADOW,
2361 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
2362 0 );
2363 SfxAbstractDialog * pDlg = 0;
2364 // Table cell(s) selected?
2365 if ( rSh.IsTableMode() )
2367 // Set border attributes Get/SetTabBorders()
2368 ::PrepareBoxInfo( aSet, rSh );
2369 rSh.GetTabBorders( aSet );
2370 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2371 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
2373 pDlg = pFact->CreateSwBorderDlg( pMDI, aSet, SW_BORDER_MODE_TABLE, RC_DLG_SWBORDERDLG );
2374 OSL_ENSURE(pDlg, "Dialogdiet fail!");
2375 if ( pDlg->Execute() == RET_OK )
2377 rSh.SetTabBorders( *pDlg->GetOutputItemSet() );
2378 pOutSet = pDlg->GetOutputItemSet();
2381 else if ( rSh.IsFrmSelected() )
2383 // Set border attributes via Frame-Manager
2384 SwFlyFrmAttrMgr aMgr( sal_False, &rSh, FRMMGR_TYPE_NONE );
2385 aSet.Put( aMgr.GetAttrSet() );
2387 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2388 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
2390 pDlg = pFact->CreateSwBorderDlg( pMDI, aSet, SW_BORDER_MODE_FRAME, RC_DLG_SWBORDERDLG );
2391 OSL_ENSURE(pDlg, "Dialogdiet fail!");
2392 if ( pDlg->Execute() == RET_OK )
2394 aMgr.SetAttrSet( *pDlg->GetOutputItemSet() );
2395 aMgr.UpdateFlyFrm();
2396 pOutSet = pDlg->GetOutputItemSet();
2399 else
2401 // Set border attributes via Shell quite normal
2402 rSh.GetCurAttr( aSet );
2403 ::PrepareBoxInfo( aSet, rSh );
2405 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2406 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
2408 pDlg = pFact->CreateSwBorderDlg( pMDI, aSet, SW_BORDER_MODE_PARA, RC_DLG_SWBORDERDLG );
2409 OSL_ENSURE(pDlg, "Dialogdiet fail!");
2410 if ( pDlg->Execute() == RET_OK )
2412 rSh.SetAttr( *pDlg->GetOutputItemSet() );
2413 pOutSet = pDlg->GetOutputItemSet();
2416 if(pOutSet)
2418 rReq.Done(*pOutSet);
2419 bDone = true;
2421 delete pDlg;
2423 break;
2424 case FN_FORMAT_BACKGROUND_DLG:
2426 SfxItemSet aSet( rSh.GetAttrPool(),
2427 RES_BACKGROUND, RES_BACKGROUND );
2429 SfxAbstractDialog * pDlg = 0;
2430 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2431 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
2434 // Table cell(s) selected?
2435 if ( rSh.IsTableMode() )
2437 // Get background attributes of the table and put it in the set
2438 SvxBrushItem aBrush(RES_BACKGROUND);
2439 rSh.GetBoxBackground( aBrush );
2440 pDlg = pFact->CreateSfxDialog( pMDI, aSet,
2441 rView.GetViewFrame()->GetFrame().GetFrameInterface(),
2442 RC_SWDLG_BACKGROUND );
2443 OSL_ENSURE(pDlg, "Dialogdiet fail!");
2444 aSet.Put( aBrush );
2445 if ( pDlg->Execute() == RET_OK )
2448 rSh.SetBoxBackground( (SvxBrushItem&)
2449 pDlg->GetOutputItemSet()->Get( RES_BACKGROUND ));
2450 pOutSet = pDlg->GetOutputItemSet();
2453 else if ( rSh.IsFrmSelected() )
2456 rSh.GetFlyFrmAttr( aSet );
2458 pDlg = pFact->CreateSfxDialog( pMDI, aSet,
2459 rView.GetViewFrame()->GetFrame().GetFrameInterface(),
2460 RC_SWDLG_BACKGROUND );
2461 OSL_ENSURE(pDlg, "Dialogdiet fail!");
2462 if ( pDlg->Execute() == RET_OK )
2464 rSh.SetFlyFrmAttr((SfxItemSet &) *pDlg->GetOutputItemSet() );
2465 pOutSet = pDlg->GetOutputItemSet();
2468 else
2470 // Set border attributes Umrandungsattribute with the shell quite normal.
2471 rSh.GetCurAttr( aSet );
2473 pDlg = pFact->CreateSfxDialog( pMDI, aSet,
2474 rView.GetViewFrame()->GetFrame().GetFrameInterface(),
2475 RC_SWDLG_BACKGROUND );
2476 OSL_ENSURE(pDlg, "Dialogdiet fail!");
2477 if ( pDlg->Execute() == RET_OK )
2479 rSh.SetAttr( *pDlg->GetOutputItemSet() );
2480 pOutSet = pDlg->GetOutputItemSet();
2483 if(pOutSet)
2485 rReq.Done(*pOutSet);
2486 bDone = true;
2488 delete pDlg;
2491 break;
2492 default:OSL_FAIL("wrong Dispatcher (basesh.cxx)");
2494 if(!bDone)
2495 rReq.Done();
2498 SwWrtShell& SwBaseShell::GetShell()
2500 return rView.GetWrtShell();
2503 SwWrtShell* SwBaseShell::GetShellPtr()
2505 return rView.GetWrtShellPtr();
2508 void SwBaseShell::InsertTable( SfxRequest& _rRequest )
2510 const SfxItemSet* pArgs = _rRequest.GetArgs();
2511 SwWrtShell& rSh = GetShell();
2513 if ( !( rSh.GetFrmType( 0, sal_True ) & FRMTYPE_FOOTNOTE ) )
2515 SwView &rTempView = GetView(); // Because GetView() does not work after the shell exchange
2516 sal_Bool bHTMLMode = 0 != (::GetHtmlMode(rTempView.GetDocShell())&HTMLMODE_ON);
2517 bool bCallEndUndo = false;
2519 if( !pArgs && rSh.IsSelection() && !rSh.IsInClickToEdit() &&
2520 !rSh.IsTableMode() )
2522 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
2523 SwInsertTableOptions aInsTblOpts = pModOpt->GetInsTblFlags(bHTMLMode);
2525 rSh.StartUndo(UNDO_INSTABLE);
2526 bCallEndUndo = true;
2528 sal_Bool bInserted = rSh.TextToTable( aInsTblOpts, '\t', text::HoriOrientation::FULL );
2529 rSh.EnterStdMode();
2530 if (bInserted)
2531 rTempView.AutoCaption(TABLE_CAP);
2532 _rRequest.Done();
2534 else
2536 sal_uInt16 nCols = 0;
2537 sal_uInt16 nRows = 0;
2538 SwInsertTableOptions aInsTblOpts( tabopts::ALL_TBL_INS_ATTR, 1 );
2539 String aTableName, aAutoName;
2540 SwTableAutoFmt* pTAFmt = 0;
2542 if( pArgs && pArgs->Count() >= 2 )
2544 SFX_REQUEST_ARG( _rRequest, pName, SfxStringItem, FN_INSERT_TABLE, sal_False );
2545 SFX_REQUEST_ARG( _rRequest, pCols, SfxUInt16Item, SID_ATTR_TABLE_COLUMN, sal_False );
2546 SFX_REQUEST_ARG( _rRequest, pRows, SfxUInt16Item, SID_ATTR_TABLE_ROW, sal_False );
2547 SFX_REQUEST_ARG( _rRequest, pFlags, SfxInt32Item, FN_PARAM_1, sal_False );
2548 SFX_REQUEST_ARG( _rRequest, pAuto, SfxStringItem, FN_PARAM_2, sal_False );
2550 if ( pName )
2551 aTableName = pName->GetValue();
2552 if ( pCols )
2553 nCols = pCols->GetValue();
2554 if ( pRows )
2555 nRows = pRows->GetValue();
2556 if ( pAuto )
2558 aAutoName = pAuto->GetValue();
2559 if ( aAutoName.Len() )
2561 SwTableAutoFmtTbl aTableTbl;
2562 aTableTbl.Load();
2563 for ( sal_uInt16 n=0; n<aTableTbl.size(); n++ )
2565 if ( aTableTbl[n].GetName() == aAutoName )
2567 pTAFmt = new SwTableAutoFmt( aTableTbl[n] );
2568 break;
2574 if ( pFlags )
2575 aInsTblOpts.mnInsMode = (sal_uInt16) pFlags->GetValue();
2576 else
2578 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
2579 aInsTblOpts = pModOpt->GetInsTblFlags(bHTMLMode);
2583 if( !nCols || !nRows )
2585 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2586 OSL_ENSURE(pFact, "Dialogdiet fail!");
2587 AbstractInsTableDlg* pDlg = pFact->CreateInsTableDlg(rTempView);
2588 OSL_ENSURE(pDlg, "Dialogdiet fail!");
2589 if( RET_OK == pDlg->Execute() )
2591 pDlg->GetValues( aTableName, nRows, nCols, aInsTblOpts, aAutoName, pTAFmt );
2593 else
2594 _rRequest.Ignore();
2595 delete pDlg;
2598 if( nCols && nRows )
2600 // record before shell change
2601 _rRequest.AppendItem( SfxStringItem( FN_INSERT_TABLE, aTableName ) );
2602 if ( aAutoName.Len() )
2603 _rRequest.AppendItem( SfxStringItem( FN_PARAM_2, aAutoName ) );
2604 _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_COLUMN, nCols ) );
2605 _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_ROW, nRows ) );
2606 _rRequest.AppendItem( SfxInt32Item( FN_PARAM_1, (sal_Int32) aInsTblOpts.mnInsMode ) );
2607 _rRequest.Done();
2609 rSh.StartUndo(UNDO_INSTABLE);
2610 bCallEndUndo = true;
2612 rSh.StartAllAction();
2613 if( rSh.HasSelection() )
2614 rSh.DelRight();
2616 rSh.InsertTable( aInsTblOpts, nRows, nCols, text::HoriOrientation::FULL, pTAFmt );
2617 rSh.MoveTable( fnTablePrev, fnTableStart );
2619 if( aTableName.Len() && !rSh.GetTblStyle( aTableName ) )
2620 rSh.GetTableFmt()->SetName( aTableName );
2622 rSh.EndAllAction();
2623 rTempView.AutoCaption(TABLE_CAP);
2625 delete pTAFmt;
2628 if( bCallEndUndo )
2630 SwRewriter aRewriter;
2632 if (rSh.GetTableFmt())
2634 aRewriter.AddRule(UndoArg1, SW_RESSTR(STR_START_QUOTE));
2635 aRewriter.AddRule(UndoArg2, rSh.GetTableFmt()->GetName());
2636 aRewriter.AddRule(UndoArg3, SW_RESSTR(STR_END_QUOTE));
2639 rSh.EndUndo(UNDO_INSTABLE, &aRewriter); // If possible change the Shell
2644 void SwBaseShell::GetGalleryState( SfxItemSet &rSet )
2646 SwWrtShell &rSh = GetShell();
2647 SfxWhichIter aIter( rSet );
2648 sal_uInt16 nWhich = aIter.FirstWhich();
2649 switch ( nWhich )
2651 case SID_GALLERY_BG_BRUSH:
2653 int nSel = rSh.GetSelectionType();
2654 SfxStringListItem aLst( nWhich );
2655 std::vector<String> &rLst = aLst.GetList();
2656 nParagraphPos = nGraphicPos = nOlePos = nFramePos = nTablePos =
2657 nTableRowPos = nTableCellPos = nPagePos =
2658 nHeaderPos = nFooterPos = 0;
2659 sal_uInt8 nPos = 1;
2660 rLst.push_back( SW_RESSTR( STR_SWBG_PAGE ) );
2661 nPagePos = nPos++;
2662 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
2663 bool bHtmlMode = 0 != (nHtmlMode & HTMLMODE_ON);
2665 if ( (!bHtmlMode || (nHtmlMode & HTMLMODE_FULL_STYLES)) &&
2666 (nSel & nsSelectionType::SEL_TXT) )
2668 rLst.push_back( SW_RESSTR( STR_SWBG_PARAGRAPH ) );
2669 nParagraphPos = nPos++;
2671 if ( (!bHtmlMode || (nHtmlMode & HTMLMODE_SOME_STYLES)) &&
2672 nSel & (nsSelectionType::SEL_TBL|nsSelectionType::SEL_TBL_CELLS) )
2674 rLst.push_back( SW_RESSTR( STR_SWBG_TABLE ) );
2675 nTablePos = nPos++;
2677 if(!bHtmlMode)
2679 rLst.push_back( SW_RESSTR( STR_SWBG_TABLE_ROW ) );
2680 nTableRowPos = nPos++;
2683 rLst.push_back( SW_RESSTR( STR_SWBG_TABLE_CELL) );
2684 nTableCellPos = nPos++;
2686 if(!bHtmlMode)
2688 if ( nSel & nsSelectionType::SEL_FRM )
2690 rLst.push_back( SW_RESSTR( STR_SWBG_FRAME ) );
2691 nFramePos = nPos++;
2693 if ( nSel & nsSelectionType::SEL_GRF )
2695 rLst.push_back( SW_RESSTR( STR_SWBG_GRAPHIC ) );
2696 nGraphicPos = nPos++;
2698 if ( nSel & nsSelectionType::SEL_OLE )
2700 rLst.push_back( SW_RESSTR( STR_SWBG_OLE ) );
2701 nOlePos = nPos++;
2703 const sal_uInt16 nType = rSh.GetFrmType(0,sal_True);
2704 if ( nType & FRMTYPE_HEADER )
2706 rLst.push_back( SW_RESSTR( STR_SWBG_HEADER ) );
2707 nHeaderPos = nPos++;
2709 if ( nType & FRMTYPE_FOOTER )
2711 rLst.push_back( SW_RESSTR( STR_SWBG_FOOTER ) );
2712 nFooterPos = nPos;
2715 if ( rLst.empty() )
2716 rSet.DisableItem( nWhich );
2717 else
2718 rSet.Put( aLst );
2719 break;
2724 void SwBaseShell::ExecuteGallery(SfxRequest &rReq)
2726 SwWrtShell &rSh = GetShell();
2727 rSh.StartAction();
2728 const SfxItemSet* pArgs = rReq.GetArgs();
2729 sal_uInt16 nSlot = rReq.GetSlot();
2730 switch(nSlot)
2732 case SID_GALLERY_BG_BRUSH:
2734 int nSel = rSh.GetSelectionType();
2735 if ( nSel & nsSelectionType::SEL_DRW_TXT )
2736 break;
2738 sal_uInt8 nPos = (sal_uInt8)((SfxUInt16Item &)pArgs->Get(SID_GALLERY_BG_POS)).GetValue();
2739 ++nPos;
2741 SvxBrushItem aBrush( (SvxBrushItem&)pArgs->Get(SID_GALLERY_BG_BRUSH));
2742 aBrush.SetWhich( RES_BACKGROUND );
2743 if ( nPos == nParagraphPos )
2744 rSh.SetAttr( aBrush );
2745 else if ( nPos == nTablePos )
2746 rSh.SetTabBackground( aBrush );
2747 else if ( nPos == nTableRowPos )
2748 rSh.SetRowBackground( aBrush );
2749 else if ( nPos == nTableCellPos )
2750 rSh.SetBoxBackground( aBrush );
2751 else if ( nPos == nFramePos || nPos == nGraphicPos || nPos == nOlePos )
2753 SfxItemSet aCoreSet(GetPool(), RES_BACKGROUND, RES_BACKGROUND);
2754 aCoreSet.Put( aBrush );
2755 rSh.SetFlyFrmAttr( aCoreSet );
2757 else if ( nPos == nPagePos || nPos == nHeaderPos || nPos == nFooterPos )
2759 sal_uInt16 nDesc = rSh.GetCurPageDesc();
2760 SwPageDesc aDesc( rSh.GetPageDesc( nDesc ) );
2761 if ( nPos == nPagePos )
2762 aDesc.GetMaster().SetFmtAttr( aBrush );
2763 else if ( nPos == nHeaderPos )
2765 SwFmtHeader aHead( aDesc.GetMaster().GetHeader() );
2766 aHead.GetHeaderFmt()->SetFmtAttr( aBrush );
2767 aDesc.GetMaster().SetFmtAttr( aHead );
2769 else if ( nPos == nFooterPos )
2771 SwFmtFooter aFoot( aDesc.GetMaster().GetFooter() );
2772 aFoot.GetFooterFmt()->SetFmtAttr( aBrush );
2773 aDesc.GetMaster().SetFmtAttr( aFoot );
2775 rSh.ChgPageDesc( nDesc, aDesc );
2777 break;
2780 rSh.EndAction();
2781 rReq.Done();
2784 void SwBaseShell::ExecField( SfxRequest& rReq )
2786 sal_uInt16 nSlot = rReq.GetSlot();
2787 switch( nSlot )
2789 case FN_CHANGE_DBFIELD:
2791 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2792 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
2794 VclAbstractDialog* pDlg = pFact->CreateSwChangeDBDlg(GetView());
2795 OSL_ENSURE(pDlg, "Dialogdiet fail!");
2796 pDlg->Execute();
2797 delete pDlg;
2799 break;
2800 default:
2801 OSL_FAIL("wrong dispatcher");
2805 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */