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