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