xref: /AOO41X/main/sw/source/ui/shells/drwtxtsh.cxx (revision 3ce09a58b0d6873449cda31e55c66dba2dbc8f7f)
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 <i18npool/lang.h>
29 #include <svl/slstitm.hxx>
30 #include <svl/cjkoptions.hxx>
31 #include <editeng/fontitem.hxx>
32 #include <editeng/langitem.hxx>
33 #include <svx/svdview.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/objface.hxx>
37 #include <svx/svdotext.hxx>
38 #include <editeng/editeng.hxx>
39 #include <editeng/editview.hxx>
40 #include <editeng/eeitem.hxx>
41 #include <editeng/scripttypeitem.hxx>
42 #include <sfx2/bindings.hxx>
43 #include <svx/fontwork.hxx>
44 #include <sfx2/request.hxx>
45 #include <sfx2/sidebar/EnumContext.hxx>
46 #include <svl/whiter.hxx>
47 #include <editeng/outliner.hxx>
48 #include <editeng/editstat.hxx>
49 #include <svx/svdoutl.hxx>
50 #include <com/sun/star/i18n/TransliterationModules.hpp>
51 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
52 #include <com/sun/star/i18n/TextConversionOption.hpp>
53 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
54 #include <com/sun/star/lang/XInitialization.hpp>
55 #include <swtypes.hxx>
56 #include <view.hxx>
57 #include <wrtsh.hxx>
58 #include <viewopt.hxx>
59 #include <initui.hxx>               // fuer SpellPointer
60 #include <drwtxtsh.hxx>
61 #include <swundo.hxx>
62 #include <breakit.hxx>
63 
64 #include <cmdid.h>
65 #include <helpid.h>
66 #ifndef _GLOBALS_HRC
67 #include <globals.hrc>
68 #endif
69 #ifndef _SHELLS_HRC
70 #include <shells.hrc>
71 #endif
72 
73 #define SwDrawTextShell
74 #include <sfx2/msg.hxx>
75 #include <swslots.hxx>
76 #ifndef _POPUP_HRC
77 #include <popup.hrc>
78 #endif
79 #include <uitool.hxx>
80 #include <wview.hxx>
81 #include <swmodule.hxx>
82 #include <svx/xtable.hxx>
83 #include <svx/svxdlg.hxx>
84 #include <svx/dialogs.hrc>
85 #include <svx/svxdlg.hxx>
86 #include <svx/dialogs.hrc>
87 #include <svx/svdoashp.hxx>
88 #include <cppuhelper/bootstrap.hxx>
89 #include "swabstdlg.hxx" //CHINA001
90 #include "misc.hrc"
91 
92 using namespace ::com::sun::star;
93 using namespace ::com::sun::star::uno;
94 using namespace ::com::sun::star::beans;
95 using namespace ::com::sun::star::i18n;
96 
97 
98 
SFX_IMPL_INTERFACE(SwDrawTextShell,SfxShell,SW_RES (STR_SHELLNAME_DRAW_TEXT))99 SFX_IMPL_INTERFACE(SwDrawTextShell, SfxShell, SW_RES(STR_SHELLNAME_DRAW_TEXT))
100 {
101     SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRWTXT_POPUPMENU));
102     SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_DRAW_TEXT_TOOLBOX));
103     SFX_CHILDWINDOW_REGISTRATION(SvxFontWorkChildWindow::GetChildWindowId());
104 }
105 
TYPEINIT1(SwDrawTextShell,SfxShell)106 TYPEINIT1(SwDrawTextShell,SfxShell)
107 
108 /*--------------------------------------------------------------------
109     Beschreibung:
110  --------------------------------------------------------------------*/
111 
112 
113 
114 void SwDrawTextShell::Init()
115 {
116     SwWrtShell &rSh = GetShell();
117     pSdrView = rSh.GetDrawView();
118     SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
119     //#97471# mouse click _and_ key input at the same time
120     if( !pOutliner )
121         return ;
122     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
123     sal_uLong nCtrl = pOutliner->GetControlWord();
124     nCtrl |= EE_CNTRL_AUTOCORRECT;
125 
126     SetUndoManager(&pOutliner->GetUndoManager());
127 
128     // jetzt versuchen wir mal ein AutoSpell
129 
130     const SwViewOption* pVOpt = rSh.GetViewOptions();
131     if(pVOpt->IsOnlineSpell())
132     {
133         nCtrl |= EE_CNTRL_ONLINESPELLING|EE_CNTRL_ALLOWBIGOBJS;
134     }
135     else
136         nCtrl &= ~(EE_CNTRL_ONLINESPELLING);
137 
138     pOutliner->SetControlWord(nCtrl);
139     pOLV->ShowCursor();
140 }
141 
142 /*--------------------------------------------------------------------
143     Beschreibung:
144  --------------------------------------------------------------------*/
145 
146 
SwDrawTextShell(SwView & rV)147 SwDrawTextShell::SwDrawTextShell(SwView &rV) :
148     SfxShell(&rV),
149     rView(rV)
150 {
151     SwWrtShell &rSh = GetShell();
152     SetPool(rSh.GetAttrPool().GetSecondaryPool());
153 
154     Init();
155 
156     rSh.NoEdit(sal_True);
157     SetName(String::CreateFromAscii("ObjectText"));
158     SetHelpId(SW_DRWTXTSHELL);
159     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_DrawText));
160 }
161 
162 /*--------------------------------------------------------------------
163     Beschreibung:
164  --------------------------------------------------------------------*/
165 
166 
167 
~SwDrawTextShell()168 __EXPORT SwDrawTextShell::~SwDrawTextShell()
169 {
170     if ( GetView().GetCurShell() == this )
171         rView.ResetSubShell();
172 }
173 
GetShell()174 SwWrtShell& SwDrawTextShell::GetShell()
175 {
176     return rView.GetWrtShell();
177 }
178 
179 
180 /*--------------------------------------------------------------------
181     Beschreibung:   Slots mit dieser Statusmethode disablen
182  --------------------------------------------------------------------*/
183 
StateDisableItems(SfxItemSet & rSet)184 void SwDrawTextShell::StateDisableItems( SfxItemSet &rSet )
185 {
186     SfxWhichIter aIter(rSet);
187     sal_uInt16 nWhich = aIter.FirstWhich();
188 
189     while (nWhich)
190     {
191         rSet.DisableItem( nWhich );
192         nWhich = aIter.NextWhich();
193     }
194 }
195 
196 
197 /*************************************************************************
198 |*
199 |* Attribute setzen
200 |*
201 \************************************************************************/
202 
203 
204 
SetAttrToMarked(const SfxItemSet & rAttr)205 void SwDrawTextShell::SetAttrToMarked(const SfxItemSet& rAttr)
206 {
207     Rectangle aNullRect;
208     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
209     Rectangle aOutRect = pOLV->GetOutputArea();
210 
211     if (aNullRect != aOutRect)
212     {
213         GetShell().GetDrawView()->SetAttributes(rAttr);
214 //      Init();
215     }
216 }
217 
218 /*--------------------------------------------------------------------
219     Beschreibung:
220  --------------------------------------------------------------------*/
221 
222 
223 
IsTextEdit()224 sal_Bool SwDrawTextShell::IsTextEdit()
225 {
226     return pSdrView->IsTextEdit();
227 }
228 
229 /*--------------------------------------------------------------------
230     Beschreibung:
231  --------------------------------------------------------------------*/
232 
233 
234 
ExecFontWork(SfxRequest & rReq)235 void SwDrawTextShell::ExecFontWork(SfxRequest& rReq)
236 {
237     SwWrtShell &rSh = GetShell();
238     FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &rSh.GetView()));
239     SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
240     SfxViewFrame* pVFrame = GetView().GetViewFrame();
241     if ( rReq.GetArgs() )
242     {
243         pVFrame->SetChildWindow(SvxFontWorkChildWindow::GetChildWindowId(),
244                                 ((const SfxBoolItem&) (rReq.GetArgs()->
245                                 Get(SID_FONTWORK))).GetValue());
246     }
247     else
248         pVFrame->ToggleChildWindow(SvxFontWorkChildWindow::GetChildWindowId());
249 
250     pVFrame->GetBindings().Invalidate(SID_FONTWORK);
251 }
252 
253 /*--------------------------------------------------------------------
254     Beschreibung:
255  --------------------------------------------------------------------*/
256 
257 
258 
StateFontWork(SfxItemSet & rSet)259 void SwDrawTextShell::StateFontWork(SfxItemSet& rSet)
260 {
261     const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
262     rSet.Put(SfxBoolItem(SID_FONTWORK, GetView().GetViewFrame()->HasChildWindow(nId)));
263 }
264 
265 /*************************************************************************
266 |*
267 |* SfxRequests fuer FontWork bearbeiten
268 |*
269 \************************************************************************/
270 
271 
272 
ExecFormText(SfxRequest & rReq)273 void SwDrawTextShell::ExecFormText(SfxRequest& rReq)
274 {
275     SwWrtShell &rSh = GetShell();
276     SdrView* pDrView = rSh.GetDrawView();
277 
278     const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
279 
280     if ( rMarkList.GetMarkCount() == 1 && rReq.GetArgs() )
281     {
282         const SfxItemSet& rSet = *rReq.GetArgs();
283 
284         //ask for the ViewFrame here - "this" may not be valid any longer!
285     // SfxViewFrame* pVFrame = GetView().GetViewFrame();
286         if ( pDrView->IsTextEdit() )
287         {
288             //#111733# Sometimes SdrEndTextEdit() initiates the change in selection and
289             // 'this' is not valid anymore
290             SwView& rTempView = GetView();
291             pDrView->SdrEndTextEdit(sal_True);
292             //this removes the current shell from the dispatcher stack!!
293             rTempView.AttrChangedNotify(&rSh);
294         }
295 
296         pDrView->SetAttributes(rSet);
297     }
298 
299 }
300 
301 /*************************************************************************
302 |*
303 |* Statuswerte fuer FontWork zurueckgeben
304 |*
305 \************************************************************************/
306 
307 
308 
GetFormTextState(SfxItemSet & rSet)309 void SwDrawTextShell::GetFormTextState(SfxItemSet& rSet)
310 {
311     SwWrtShell &rSh = GetShell();
312     SdrView* pDrView = rSh.GetDrawView();
313     const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
314     const SdrObject* pObj = NULL;
315     SvxFontWorkDialog* pDlg = NULL;
316 
317     const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
318 
319     SfxViewFrame* pVFrame = GetView().GetViewFrame();
320     if ( pVFrame->HasChildWindow(nId) )
321         pDlg = (SvxFontWorkDialog*)(pVFrame->GetChildWindow(nId)->GetWindow());
322 
323     if ( rMarkList.GetMarkCount() == 1 )
324         pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
325 
326     const SdrTextObj* pTextObj = dynamic_cast< const SdrTextObj* >(pObj);
327     const bool bDeactivate(
328         !pObj ||
329         !pTextObj ||
330         !pTextObj->HasText() ||
331         dynamic_cast< const SdrObjCustomShape* >(pObj)); // #121538# no FontWork for CustomShapes
332 
333     if (bDeactivate)
334     {
335         rSet.DisableItem(XATTR_FORMTXTSTYLE);
336         rSet.DisableItem(XATTR_FORMTXTADJUST);
337         rSet.DisableItem(XATTR_FORMTXTDISTANCE);
338         rSet.DisableItem(XATTR_FORMTXTSTART);
339         rSet.DisableItem(XATTR_FORMTXTMIRROR);
340         rSet.DisableItem(XATTR_FORMTXTHIDEFORM);
341         rSet.DisableItem(XATTR_FORMTXTOUTLINE);
342         rSet.DisableItem(XATTR_FORMTXTSHADOW);
343         rSet.DisableItem(XATTR_FORMTXTSHDWCOLOR);
344         rSet.DisableItem(XATTR_FORMTXTSHDWXVAL);
345         rSet.DisableItem(XATTR_FORMTXTSHDWYVAL);
346     }
347     else
348     {
349         if ( pDlg )
350             pDlg->SetColorTable(XColorList::GetStdColorList());
351 
352         pDrView->GetAttributes( rSet );
353     }
354 }
355 
356 /*--------------------------------------------------------------------
357     Beschreibung:
358  --------------------------------------------------------------------*/
359 
360 
361 
ExecDrawLingu(SfxRequest & rReq)362 void SwDrawTextShell::ExecDrawLingu(SfxRequest &rReq)
363 {
364     SwWrtShell &rSh = GetShell();
365     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
366     if( rSh.GetDrawView()->GetMarkedObjectList().GetMarkCount() )
367     {
368         switch(rReq.GetSlot())
369         {
370         case SID_THESAURUS:
371             pOLV->StartThesaurus();
372             break;
373 
374         case SID_HANGUL_HANJA_CONVERSION:
375             pOLV->StartTextConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, NULL,
376                     i18n::TextConversionOption::CHARACTER_BY_CHARACTER, sal_True, sal_False );
377             break;
378 
379         case SID_CHINESE_CONVERSION:
380             {
381                 //open ChineseTranslationDialog
382                 Reference< XComponentContext > xContext(
383                     ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
384                 if(xContext.is())
385                 {
386                     Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
387                     if(xMCF.is())
388                     {
389                         Reference< ui::dialogs::XExecutableDialog > xDialog(
390                                 xMCF->createInstanceWithContext(
391                                     rtl::OUString::createFromAscii("com.sun.star.linguistic2.ChineseTranslationDialog")
392                                     , xContext), UNO_QUERY);
393                         Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
394                         if( xInit.is() )
395                         {
396                             //  initialize dialog
397                             Reference< awt::XWindow > xDialogParentWindow(0);
398                             Sequence<Any> aSeq(1);
399                             Any* pArray = aSeq.getArray();
400                             PropertyValue aParam;
401                             aParam.Name = rtl::OUString::createFromAscii("ParentWindow");
402                             aParam.Value <<= makeAny(xDialogParentWindow);
403                             pArray[0] <<= makeAny(aParam);
404                             xInit->initialize( aSeq );
405 
406                             //execute dialog
407                             sal_Int16 nDialogRet = xDialog->execute();
408                             if( RET_OK == nDialogRet )
409                             {
410                                 //get some parameters from the dialog
411                                 sal_Bool bToSimplified = sal_True;
412                                 sal_Bool bUseVariants = sal_True;
413                                 sal_Bool bCommonTerms = sal_True;
414                                 Reference< beans::XPropertySet >  xProp( xDialog, UNO_QUERY );
415                                 if( xProp.is() )
416                                 {
417                                     try
418                                     {
419                                         xProp->getPropertyValue( C2U("IsDirectionToSimplified") ) >>= bToSimplified;
420                                         xProp->getPropertyValue( C2U("IsUseCharacterVariants") ) >>= bUseVariants;
421                                         xProp->getPropertyValue( C2U("IsTranslateCommonTerms") ) >>= bCommonTerms;
422                                     }
423                                     catch( Exception& )
424                                     {
425                                     }
426                                 }
427 
428                                 //execute translation
429                                 sal_Int16 nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
430                                 sal_Int16 nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
431                                 sal_Int32 nOptions    = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
432                                 if( !bCommonTerms )
433                                     nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
434 
435                                 Font aTargetFont = pOLV->GetWindow()->GetDefaultFont( DEFAULTFONT_CJK_TEXT,
436                                             nTargetLang, DEFAULTFONT_FLAGS_ONLYONE );
437 
438                                 pOLV->StartTextConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, sal_False, sal_False );
439                             }
440                         }
441                         Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
442                         if( xComponent.is() )
443                             xComponent->dispose();
444                     }
445                 }
446             }
447             break;
448 
449         default:
450             ASSERT(!this, "unexpected slot-id");
451         }
452     }
453 }
454 
455 /*--------------------------------------------------------------------
456     Beschreibung:
457  --------------------------------------------------------------------*/
ExecDraw(SfxRequest & rReq)458 void SwDrawTextShell::ExecDraw(SfxRequest &rReq)
459 {
460     SwWrtShell &rSh = GetShell();
461     pSdrView = rSh.GetDrawView();
462     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
463 
464     switch (rReq.GetSlot())
465     {
466         case FN_INSERT_SOFT_HYPHEN:
467         case FN_INSERT_HARDHYPHEN:
468         case FN_INSERT_HARD_SPACE:
469         case SID_INSERT_RLM :
470         case SID_INSERT_LRM :
471         case SID_INSERT_ZWNBSP :
472         case SID_INSERT_ZWSP:
473         {
474             sal_Unicode cIns = 0;
475             switch(rReq.GetSlot())
476             {
477                 case FN_INSERT_SOFT_HYPHEN: cIns = CHAR_SOFTHYPHEN; break;
478                 case FN_INSERT_HARDHYPHEN: cIns = CHAR_HARDHYPHEN; break;
479                 case FN_INSERT_HARD_SPACE: cIns = CHAR_HARDBLANK; break;
480                 case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
481                 case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
482                 case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
483                 case SID_INSERT_ZWNBSP: cIns = CHAR_ZWNBSP; break;
484             }
485             pOLV->InsertText( String(cIns));
486             rReq.Done();
487         }
488         break;
489         case SID_CHARMAP:
490     {  // Sonderzeichen einfuegen
491             InsertSymbol(rReq);
492             break;
493     }
494           case FN_INSERT_STRING:
495                 {
496             const SfxItemSet *pNewAttrs = rReq.GetArgs();
497                         sal_uInt16 nSlot = rReq.GetSlot();
498             const SfxPoolItem* pItem = 0;
499                         if(pNewAttrs)
500             {
501                                 pNewAttrs->GetItemState(nSlot, sal_False, &pItem );
502                             pOLV->InsertText(((const SfxStringItem *)pItem)->GetValue());
503             }
504                         break;
505                 }
506 
507         case SID_SELECTALL:
508         {
509             SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
510             if(pOutliner)
511             {
512                 sal_uLong nParaCount = pOutliner->GetParagraphCount();
513                 if (nParaCount > 0)
514                     pOLV->SelectRange(0L, sal_uInt16(nParaCount) );
515             }
516         }
517         break;
518 
519         case FN_FORMAT_RESET:   // delete hard text attributes
520         {
521             pOLV->RemoveAttribsKeepLanguages( true );
522             pOLV->GetEditView().GetEditEngine()->RemoveFields(sal_True);
523             rReq.Done();
524         }
525         break;
526 
527         case FN_ESCAPE:
528             if (pSdrView->IsTextEdit())
529             {
530                 // Shellwechsel!
531                 rSh.EndTextEdit();
532                 SwView& rTempView = rSh.GetView();
533                 rTempView.ExitDraw();
534                 rSh.Edit();
535                 return;
536             }
537             break;
538         case FN_DRAWTEXT_ATTR_DLG:
539             {
540                 SfxItemSet aNewAttr( pSdrView->GetModel()->GetItemPool() );
541                 pSdrView->GetAttributes( aNewAttr );
542                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
543                 if ( pFact )
544                 {
545                     SfxAbstractTabDialog *pDlg = pFact->CreateTextTabDialog(
546                                 &(GetView().GetViewFrame()->GetWindow()),
547                                 &aNewAttr, pSdrView );
548                     sal_uInt16 nResult = pDlg->Execute();
549 
550                     if (nResult == RET_OK)
551                     {
552                         if (pSdrView->AreObjectsMarked())
553                         {
554                             pSdrView->SetAttributes(*pDlg->GetOutputItemSet());
555                             rReq.Done(*(pDlg->GetOutputItemSet()));
556                         }
557                     }
558 
559                     delete( pDlg );
560                 }
561             }
562             break;
563         case SID_TABLE_VERT_NONE:
564         case SID_TABLE_VERT_CENTER:
565         case SID_TABLE_VERT_BOTTOM:
566             {
567                 sal_uInt16 nSId = rReq.GetSlot();
568                 if (pSdrView->AreObjectsMarked())
569                 {
570                     SdrTextVertAdjust eTVA = SDRTEXTVERTADJUST_TOP;
571                     if (nSId == SID_TABLE_VERT_CENTER)
572                         eTVA = SDRTEXTVERTADJUST_CENTER;
573                     else if (nSId == SID_TABLE_VERT_BOTTOM)
574                         eTVA = SDRTEXTVERTADJUST_BOTTOM;
575 
576                     SfxItemSet aNewAttr( pSdrView->GetModel()->GetItemPool() );
577                     pSdrView->GetAttributes( aNewAttr );
578                     aNewAttr.Put(SdrTextVertAdjustItem(eTVA));
579                     pSdrView->SetAttributes(aNewAttr);
580                     rReq.Done();
581                 }
582 
583             }
584             break;
585 
586         default:
587             ASSERT(!this, "unexpected slot-id");
588             return;
589     }
590 
591     GetView().GetViewFrame()->GetBindings().InvalidateAll(sal_False);
592 
593     if (IsTextEdit() && pOLV->GetOutliner()->IsModified())
594         rSh.SetModified();
595 }
596 
597 /*--------------------------------------------------------------------
598     Beschreibung:   Undo ausfuehren
599  --------------------------------------------------------------------*/
600 
601 
602 
ExecUndo(SfxRequest & rReq)603 void SwDrawTextShell::ExecUndo(SfxRequest &rReq)
604 {
605     if( IsTextEdit() )
606     {
607         sal_Bool bCallBase = sal_True;
608         const SfxItemSet* pArgs = rReq.GetArgs();
609         if( pArgs )
610         {
611             sal_uInt16 nId = rReq.GetSlot(), nCnt = 1;
612             const SfxPoolItem* pItem;
613             switch( nId )
614             {
615             case SID_UNDO:
616             case SID_REDO:
617                 if( SFX_ITEM_SET == pArgs->GetItemState( nId, sal_False, &pItem ) &&
618                     1 < (nCnt = ((SfxUInt16Item*)pItem)->GetValue()) )
619                 {
620                     // then we make by ourself.
621                     ::svl::IUndoManager* pUndoManager = GetUndoManager();
622                     if( pUndoManager )
623                     {
624                         if( SID_UNDO == nId )
625                             while( nCnt-- )
626                                 pUndoManager->Undo();
627                         else
628                             while( nCnt-- )
629                                 pUndoManager->Redo();
630                     }
631                     bCallBase = sal_False;
632                     GetView().GetViewFrame()->GetBindings().InvalidateAll(sal_False);
633                 }
634                 break;
635             }
636         }
637         if( bCallBase )
638         {
639             SfxViewFrame *pSfxViewFrame = GetView().GetViewFrame();
640             pSfxViewFrame->ExecuteSlot(rReq, pSfxViewFrame->GetInterface());
641         }
642     }
643 }
644 
645 /*--------------------------------------------------------------------
646     Beschreibung:   Zustand Undo
647  --------------------------------------------------------------------*/
648 
649 
650 
StateUndo(SfxItemSet & rSet)651 void SwDrawTextShell::StateUndo(SfxItemSet &rSet)
652 {
653     if ( !IsTextEdit() )
654         return;
655 
656     SfxViewFrame *pSfxViewFrame = GetView().GetViewFrame();
657     SfxWhichIter aIter(rSet);
658     sal_uInt16 nWhich = aIter.FirstWhich();
659     while( nWhich )
660     {
661         switch ( nWhich )
662         {
663         case SID_GETUNDOSTRINGS:
664         case SID_GETREDOSTRINGS:
665             {
666                 ::svl::IUndoManager* pUndoManager = GetUndoManager();
667                 if( pUndoManager )
668                 {
669                     UniString (::svl::IUndoManager:: *fnGetComment)( size_t, bool const ) const;
670 
671                     sal_uInt16 nCount;
672                     if( SID_GETUNDOSTRINGS == nWhich )
673                     {
674                         nCount = pUndoManager->GetUndoActionCount();
675                         fnGetComment = &::svl::IUndoManager::GetUndoActionComment;
676                     }
677                     else
678                     {
679                         nCount = pUndoManager->GetRedoActionCount();
680                         fnGetComment = &::svl::IUndoManager::GetRedoActionComment;
681                     }
682                     if( nCount )
683                     {
684                         String sList;
685                         for( sal_uInt16 n = 0; n < nCount; ++n )
686                             ( sList += (pUndoManager->*fnGetComment)( n, ::svl::IUndoManager::TopLevel ) )
687                                     += '\n';
688 
689                         SfxStringListItem aItem( nWhich );
690                         aItem.SetString( sList );
691                         rSet.Put( aItem );
692                     }
693                 }
694                 else
695                     rSet.DisableItem( nWhich );
696             }
697             break;
698 
699         default:
700             pSfxViewFrame->GetSlotState( nWhich,
701                                     pSfxViewFrame->GetInterface(), &rSet );
702         }
703 
704         nWhich = aIter.NextWhich();
705     }
706 }
707 
ExecTransliteration(SfxRequest & rReq)708 void SwDrawTextShell::ExecTransliteration( SfxRequest & rReq )
709 {
710     using namespace i18n;
711     {
712         sal_uInt32 nMode = 0;
713 
714         switch( rReq.GetSlot() )
715         {
716         case SID_TRANSLITERATE_SENTENCE_CASE:
717             nMode = TransliterationModulesExtra::SENTENCE_CASE;
718             break;
719         case SID_TRANSLITERATE_TITLE_CASE:
720             nMode = TransliterationModulesExtra::TITLE_CASE;
721             break;
722         case SID_TRANSLITERATE_TOGGLE_CASE:
723             nMode = TransliterationModulesExtra::TOGGLE_CASE;
724             break;
725         case SID_TRANSLITERATE_UPPER:
726             nMode = TransliterationModules_LOWERCASE_UPPERCASE;
727             break;
728         case SID_TRANSLITERATE_LOWER:
729             nMode = TransliterationModules_UPPERCASE_LOWERCASE;
730             break;
731 
732         case SID_TRANSLITERATE_HALFWIDTH:
733             nMode = TransliterationModules_FULLWIDTH_HALFWIDTH;
734             break;
735         case SID_TRANSLITERATE_FULLWIDTH:
736             nMode = TransliterationModules_HALFWIDTH_FULLWIDTH;
737             break;
738 
739         case SID_TRANSLITERATE_HIRAGANA:
740             nMode = TransliterationModules_KATAKANA_HIRAGANA;
741             break;
742         case SID_TRANSLITERATE_KATAGANA:
743             nMode = TransliterationModules_HIRAGANA_KATAKANA;
744             break;
745 
746         default:
747             ASSERT(!this, "falscher Dispatcher");
748         }
749 
750         if( nMode )
751         {
752             OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
753             pOLV->TransliterateText( nMode );
754         }
755     }
756 }
757 
758 /*--------------------------------------------------------------------
759     Beschreibung:   Sonderzeichen einfuegen (siehe SDraw: FUBULLET.CXX)
760  --------------------------------------------------------------------*/
761 
InsertSymbol(SfxRequest & rReq)762 void SwDrawTextShell::InsertSymbol(SfxRequest& rReq)
763 {
764     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
765     if(!pOLV)
766         return;
767     const SfxItemSet *pArgs = rReq.GetArgs();
768     const SfxPoolItem* pItem = 0;
769     if( pArgs )
770         pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), sal_False, &pItem);
771 
772     String sSym;
773     String sFontName;
774     if ( pItem )
775     {
776         sSym = ((const SfxStringItem*)pItem)->GetValue();
777         const SfxPoolItem* pFtItem = NULL;
778         pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), sal_False, &pFtItem);
779         const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
780         if ( pFontItem )
781             sFontName = pFontItem->GetValue();
782     }
783 
784     SfxItemSet aSet(pOLV->GetAttribs());
785     sal_uInt16 nScript = pOLV->GetSelectedScriptType();
786     SvxFontItem aSetDlgFont( RES_CHRATR_FONT );
787     {
788         SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
789         aSetItem.GetItemSet().Put( aSet, sal_False );
790         const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
791         if( pI )
792             aSetDlgFont = *(SvxFontItem*)pI;
793         else
794             aSetDlgFont = (SvxFontItem&)aSet.Get( GetWhichOfScript(
795                         SID_ATTR_CHAR_FONT,
796                         GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() ) ));
797         if (!sFontName.Len())
798             sFontName = aSetDlgFont.GetFamilyName();
799     }
800 
801     Font aFont(sFontName, Size(1,1));
802     if(!sSym.Len())
803     {
804         SfxAllItemSet aAllSet( GetPool() );
805         aAllSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
806 
807         SwViewOption aOpt(*rView.GetWrtShell().GetViewOptions());
808         String sSymbolFont = aOpt.GetSymbolFont();
809         if( sSymbolFont.Len() )
810             aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
811         else
812             aAllSet.Put( SfxStringItem( SID_FONT_NAME, aSetDlgFont.GetFamilyName() ) );
813 
814         // Wenn Zeichen selektiert ist kann es angezeigt werden
815         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
816         SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( rView.GetWindow(), aAllSet,
817             rView.GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
818         sal_uInt16 nResult = pDlg->Execute();
819         if( nResult == RET_OK )
820         {
821             SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, sal_False );
822             SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False );
823             if ( pFontItem )
824             {
825                 aFont.SetName( pFontItem->GetFamilyName() );
826                 aFont.SetStyleName( pFontItem->GetStyleName() );
827                 aFont.SetCharSet( pFontItem->GetCharSet() );
828                 aFont.SetPitch( pFontItem->GetPitch() );
829             }
830 
831             if ( pCItem )
832             {
833                 sSym  = pCItem->GetValue();
834                 aOpt.SetSymbolFont(aFont.GetName());
835                 SW_MOD()->ApplyUsrPref(aOpt, &rView);
836             }
837         }
838 
839         delete( pDlg );
840     }
841 
842     if( sSym.Len() )
843     {
844         // nicht flackern
845         pOLV->HideCursor();
846         SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
847         pOutliner->SetUpdateMode(sal_False);
848 
849         SfxItemSet aOldSet( pOLV->GetAttribs() );
850         SfxItemSet aFontSet( *aOldSet.GetPool(),
851                             EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
852                             EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CJK,
853                             EE_CHAR_FONTINFO_CTL, EE_CHAR_FONTINFO_CTL,
854                             0 );
855         aFontSet.Set( aOldSet );
856 
857         // String einfuegen
858         pOLV->InsertText( sSym );
859 
860         // attributieren (Font setzen)
861         SfxItemSet aFontAttribSet( *aFontSet.GetPool(), aFontSet.GetRanges() );
862         SvxFontItem aFontItem (aFont.GetFamily(),    aFont.GetName(),
863                                 aFont.GetStyleName(), aFont.GetPitch(),
864                                 aFont.GetCharSet(),
865                                 EE_CHAR_FONTINFO );
866         nScript = pBreakIt->GetAllScriptsOfText( sSym );
867         if( SCRIPTTYPE_LATIN & nScript )
868             aFontAttribSet.Put( aFontItem, EE_CHAR_FONTINFO );
869         if( SCRIPTTYPE_ASIAN & nScript )
870             aFontAttribSet.Put( aFontItem, EE_CHAR_FONTINFO_CJK );
871         if( SCRIPTTYPE_COMPLEX & nScript )
872             aFontAttribSet.Put( aFontItem, EE_CHAR_FONTINFO_CTL );
873         pOLV->SetAttribs(aFontAttribSet);
874 
875         // Selektion loeschen
876         ESelection aSel(pOLV->GetSelection());
877         aSel.nStartPara = aSel.nEndPara;
878         aSel.nStartPos = aSel.nEndPos;
879         pOLV->SetSelection(aSel);
880 
881         // Alten Font restaurieren
882         pOLV->SetAttribs( aFontSet );
883 
884         // ab jetzt wieder anzeigen
885         pOutliner->SetUpdateMode(sal_True);
886         pOLV->ShowCursor();
887 
888         rReq.AppendItem( SfxStringItem( GetPool().GetWhich(SID_CHARMAP), sSym ) );
889         if(aFont.GetName().Len())
890             rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aFont.GetName() ) );
891         rReq.Done();
892     }
893 }
894 /*-- 22.10.2003 14:26:32---------------------------------------------------
895 
896   -----------------------------------------------------------------------*/
GetUndoManager()897 ::svl::IUndoManager* SwDrawTextShell::GetUndoManager()
898 {
899     SwWrtShell &rSh = GetShell();
900     pSdrView = rSh.GetDrawView();
901     SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
902     pOutliner = pSdrView->GetTextEditOutliner();
903     return &pOutliner->GetUndoManager();
904 }
905 
GetStatePropPanelAttr(SfxItemSet & rSet)906 void SwDrawTextShell::GetStatePropPanelAttr(SfxItemSet &rSet)
907 {
908     SfxWhichIter    aIter( rSet );
909     sal_uInt16 nWhich = aIter.FirstWhich();
910 
911     SwWrtShell &rSh = GetShell();
912     pSdrView = rSh.GetDrawView();
913 
914     SfxItemSet aAttrs( pSdrView->GetModel()->GetItemPool() );
915     pSdrView->GetAttributes( aAttrs );
916 
917     while ( nWhich )
918     {
919         sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
920             ? GetPool().GetSlotId(nWhich)
921             : nWhich;
922         switch ( nSlotId )
923         {
924             case SID_TABLE_VERT_NONE:
925             case SID_TABLE_VERT_CENTER:
926             case SID_TABLE_VERT_BOTTOM:
927                 sal_Bool bContour = sal_False;
928                 SfxItemState eConState = aAttrs.GetItemState( SDRATTR_TEXT_CONTOURFRAME );
929                 if( eConState != SFX_ITEM_DONTCARE )
930                 {
931                     bContour = ( ( const SdrTextContourFrameItem& )aAttrs.Get( SDRATTR_TEXT_CONTOURFRAME ) ).GetValue();
932                 }
933                 if (bContour) break;
934 
935                 SfxItemState eVState = aAttrs.GetItemState( SDRATTR_TEXT_VERTADJUST );
936                 //SfxItemState eHState = aAttrs.GetItemState( SDRATTR_TEXT_HORZADJUST );
937 
938                 //if(SFX_ITEM_DONTCARE != eVState && SFX_ITEM_DONTCARE != eHState)
939                 if(SFX_ITEM_DONTCARE != eVState)
940                 {
941                     SdrTextVertAdjust eTVA = (SdrTextVertAdjust)((const SdrTextVertAdjustItem&)aAttrs.Get(SDRATTR_TEXT_VERTADJUST)).GetValue();
942                     sal_Bool bSet = nSlotId == SID_TABLE_VERT_NONE && eTVA == SDRTEXTVERTADJUST_TOP||
943                             nSlotId == SID_TABLE_VERT_CENTER && eTVA == SDRTEXTVERTADJUST_CENTER ||
944                             nSlotId == SID_TABLE_VERT_BOTTOM && eTVA == SDRTEXTVERTADJUST_BOTTOM;
945                     rSet.Put(SfxBoolItem(nSlotId, bSet));
946                 }
947                 else
948                 {
949                     rSet.Put(SfxBoolItem(nSlotId, sal_False));
950                 }
951                 break;
952         }
953         nWhich = aIter.NextWhich();
954     }
955 }
956