update dev300-m58
[ooovba.git] / sw / source / ui / shells / annotsh.cxx
blobadf7f14ddb715b737b26307e4decc2b286746b1f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: annotsh.cxx,v $
10 * $Revision: 1.7.82.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <hintids.hxx>
35 #include <tools/shl.hxx>
36 #include <com/sun/star/i18n/TransliterationModules.hpp>
37 #include <com/sun/star/i18n/TextConversionOption.hpp>
38 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
39 #include <com/sun/star/lang/XInitialization.hpp>
40 #include <sfx2/objface.hxx>
41 #include <sfx2/viewfrm.hxx>
42 #include <sfx2/bindings.hxx>
43 #include <sfx2/dispatch.hxx>
44 #include <sfx2/request.hxx>
45 #include <svx/spltitem.hxx>
46 #include <svx/orphitem.hxx>
47 #include <svx/brkitem.hxx>
48 #include <svx/widwitem.hxx>
49 #include <svx/kernitem.hxx>
50 #include <svx/escpitem.hxx>
51 #include <svx/lspcitem.hxx>
52 #include <svx/adjitem.hxx>
53 #include <svx/crsditem.hxx>
54 #include <svx/shdditem.hxx>
55 #include <svx/hyznitem.hxx>
56 #include <svx/udlnitem.hxx>
57 #include <svx/fontitem.hxx>
58 #include <svx/fhgtitem.hxx>
59 #include <svx/clipfmtitem.hxx>
60 #include <svtools/stritem.hxx>
61 #include <svtools/slstitm.hxx>
62 #include <svx/colritem.hxx>
63 #include <svx/wghtitem.hxx>
64 #include <svx/cntritem.hxx>
65 #include <svx/postitem.hxx>
66 #include <svx/frmdiritem.hxx>
67 #include <svx/svdoutl.hxx>
68 #include <svtools/whiter.hxx>
69 #include <svtools/cjkoptions.hxx>
70 #include <svtools/ctloptions.hxx>
71 #include <svtools/useroptions.hxx>
72 #include <vcl/msgbox.hxx>
73 #include <svx/flditem.hxx>
74 #include <svx/editstat.hxx>
75 #include <svx/hlnkitem.hxx>
76 #include <svx/htmlmode.hxx>
77 #include <svx/langitem.hxx>
78 #include <svx/unolingu.hxx>
79 #include <svx/scripttypeitem.hxx>
80 #include <svx/writingmodeitem.hxx>
81 #include <swundo.hxx>
82 #include <doc.hxx>
83 #include <viewopt.hxx>
84 #include <wrtsh.hxx>
85 #include <uitool.hxx>
86 #include <popup.hrc>
87 #include <pardlg.hxx>
88 #include <swdtflvr.hxx>
89 #include <drwtxtsh.hxx>
90 #include <swmodule.hxx>
91 #include <initui.hxx>
92 #include <edtwin.hxx>
93 #include <swwait.hxx>
94 #include <docstat.hxx>
96 #include <cmdid.h>
97 #include <globals.hrc>
98 #include <shells.hrc>
99 #include <breakit.hxx>
100 #include "annotsh.hxx"
101 #include "view.hxx"
102 #include "PostItMgr.hxx"
103 #include "postit.hxx"
105 #include "swtypes.hxx"
107 #include <svx/svxdlg.hxx>
108 #include <svx/dialogs.hrc>
110 #include <svx/svxids.hrc>
111 #include <svtools/itempool.hxx>
112 #include <svx/outliner.hxx>
113 #include <svx/editeng.hxx>
114 #include <svx/editview.hxx>
116 #include <svtools/languageoptions.hxx>
117 #include <svx/langitem.hxx>
118 #include <svtools/langtab.hxx>
119 #include <svtools/slstitm.hxx>
121 #include <docsh.hxx>
122 #include <svtools/undo.hxx>
123 #include "swabstdlg.hxx" //CHINA001
124 #include "chrdlg.hrc" //CHINA001
125 #include "misc.hrc"
126 #include <app.hrc>
128 #include <comphelper/processfactory.hxx>
130 #include <cppuhelper/bootstrap.hxx>
132 #include <langhelper.hxx>
134 using namespace ::com::sun::star;
135 using namespace ::com::sun::star::uno;
136 using namespace ::com::sun::star::beans;
137 using namespace ::com::sun::star::i18n;
139 #define SwAnnotationShell
141 #include <sfx2/msg.hxx>
142 #include <swslots.hxx>
144 SFX_IMPL_INTERFACE(SwAnnotationShell, SfxShell, SW_RES(STR_SHELLNAME_DRAW_TEXT))
146 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TEXT_TOOLBOX));
147 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_ANNOTATION_POPUPMENU));
150 TYPEINIT1(SwAnnotationShell,SfxShell)
152 SwAnnotationShell::SwAnnotationShell( SwView& r )
153 : rView(r)
155 SwWrtShell &rSh = rView.GetWrtShell();
156 SetPool(rSh.GetAttrPool().GetSecondaryPool());
159 SwAnnotationShell::~SwAnnotationShell()
163 SfxUndoManager* SwAnnotationShell::GetUndoManager()
165 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
166 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
168 DBG_ASSERT(pPostItMgr,"PostItMgr::Layout(): We are looping forever");
169 return 0;
171 return &pPostItMgr->GetActivePostIt()->Engine()->GetUndoManager();
174 void SwAnnotationShell::Exec( SfxRequest &rReq )
176 //TODO: clean this up!!!!
177 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
178 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
179 return;
181 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
182 SfxItemSet aEditAttr(pOLV->GetAttribs());
183 SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
185 sal_uInt16 nSlot = rReq.GetSlot();
186 sal_uInt16 nWhich = GetPool().GetWhich(nSlot);
187 const SfxItemSet *pNewAttrs = rReq.GetArgs();
188 sal_uInt16 nEEWhich = 0;
189 switch (nSlot)
191 case SID_ATTR_CHAR_FONT:
192 case SID_ATTR_CHAR_FONTHEIGHT:
193 case SID_ATTR_CHAR_WEIGHT:
194 case SID_ATTR_CHAR_POSTURE:
196 SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
197 if( !pSecondPool )
198 pSecondPool = aEditAttr.GetPool();
199 SvxScriptSetItem aSetItem( nSlot, *pSecondPool );
200 aSetItem.PutItemForScriptType( pOLV->GetSelectedScriptType(), pNewAttrs->Get( nWhich ));
201 aNewAttr.Put( aSetItem.GetItemSet() );
202 rReq.Done();
203 break;
205 case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
206 case SID_ATTR_CHAR_UNDERLINE:
208 FontUnderline eFU = ((const SvxUnderlineItem&)aEditAttr.Get(EE_CHAR_UNDERLINE)).GetLineStyle();
209 aNewAttr.Put(SvxUnderlineItem(eFU == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_UNDERLINE));
210 break;
212 case SID_ATTR_CHAR_OVERLINE:
214 FontUnderline eFO = ((const SvxOverlineItem&)aEditAttr.Get(EE_CHAR_OVERLINE)).GetLineStyle();
215 aNewAttr.Put(SvxOverlineItem(eFO == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_OVERLINE));
216 break;
218 case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
219 case SID_ATTR_CHAR_SHADOWED: nEEWhich = EE_CHAR_SHADOW; break;
220 case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT; break;
221 case SID_ATTR_CHAR_WORDLINEMODE: nEEWhich = EE_CHAR_WLM; break;
222 case SID_ATTR_CHAR_RELIEF : nEEWhich = EE_CHAR_RELIEF; break;
223 case SID_ATTR_CHAR_LANGUAGE : nEEWhich = EE_CHAR_LANGUAGE;break;
224 case SID_ATTR_CHAR_KERNING : nEEWhich = EE_CHAR_KERNING; break;
225 case SID_ATTR_CHAR_SCALEWIDTH: nEEWhich = EE_CHAR_FONTWIDTH; break;
226 case SID_ATTR_CHAR_AUTOKERN : nEEWhich = EE_CHAR_PAIRKERNING; break;
227 case SID_ATTR_CHAR_ESCAPEMENT: nEEWhich = EE_CHAR_ESCAPEMENT; break;
228 case SID_ATTR_PARA_ADJUST_LEFT:
229 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_LEFT, EE_PARA_JUST));
230 break;
231 case SID_ATTR_PARA_ADJUST_CENTER:
232 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_CENTER, EE_PARA_JUST));
233 break;
234 case SID_ATTR_PARA_ADJUST_RIGHT:
235 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_RIGHT, EE_PARA_JUST));
236 break;
237 case SID_ATTR_PARA_ADJUST_BLOCK:
238 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_BLOCK, EE_PARA_JUST));
239 break;
241 case SID_ATTR_PARA_LINESPACE_10:
243 SvxLineSpacingItem aItem(SVX_LINESPACE_ONE_LINE, EE_PARA_SBL);
244 aItem.SetPropLineSpace(100);
245 aNewAttr.Put(aItem);
247 break;
248 case SID_ATTR_PARA_LINESPACE_15:
250 SvxLineSpacingItem aItem(SVX_LINESPACE_ONE_POINT_FIVE_LINES, EE_PARA_SBL);
251 aItem.SetPropLineSpace(150);
252 aNewAttr.Put(aItem);
254 break;
255 case SID_ATTR_PARA_LINESPACE_20:
257 SvxLineSpacingItem aItem(SVX_LINESPACE_TWO_LINES, EE_PARA_SBL);
258 aItem.SetPropLineSpace(200);
259 aNewAttr.Put(aItem);
261 break;
262 case SID_SELECTALL:
264 Outliner * pOutliner = pOLV->GetOutliner();
265 if(pOutliner)
267 ULONG nParaCount = pOutliner->GetParagraphCount();
268 if (nParaCount > 0)
269 pOLV->SelectRange(0L, USHORT(nParaCount) );
271 break;
273 case FN_FORMAT_RESET:
275 pPostItMgr->GetActivePostIt()->ResetAttributes();
276 rReq.Done();
277 break;
279 case FN_SET_SUPER_SCRIPT:
281 SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
282 SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&)
283 aEditAttr.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
285 if( eEsc == SVX_ESCAPEMENT_SUPERSCRIPT )
286 aItem.SetEscapement( SVX_ESCAPEMENT_OFF );
287 else
288 aItem.SetEscapement( SVX_ESCAPEMENT_SUPERSCRIPT );
289 aNewAttr.Put( aItem, EE_CHAR_ESCAPEMENT );
291 break;
292 case FN_SET_SUB_SCRIPT:
294 SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
295 SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&)
296 aEditAttr.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
298 if( eEsc == SVX_ESCAPEMENT_SUBSCRIPT )
299 aItem.SetEscapement( SVX_ESCAPEMENT_OFF );
300 else
301 aItem.SetEscapement( SVX_ESCAPEMENT_SUBSCRIPT );
302 aNewAttr.Put( aItem, EE_CHAR_ESCAPEMENT );
304 break;
305 case SID_HYPERLINK_SETLINK:
307 const SfxPoolItem* pItem = 0;
308 if(pNewAttrs)
309 pNewAttrs->GetItemState(nSlot, sal_False, &pItem);
311 if(pItem)
313 const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
314 SvxURLField aFld(rHLinkItem.GetURL(), rHLinkItem.GetName(), SVXURLFORMAT_APPDEFAULT);
315 aFld.SetTargetFrame(rHLinkItem.GetTargetFrame());
317 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
319 if (pFieldItem && pFieldItem->GetField()->ISA(SvxURLField))
321 // Feld selektieren, so dass es beim Insert geloescht wird
322 ESelection aSel = pOLV->GetSelection();
323 aSel.nEndPos++;
324 pOLV->SetSelection(aSel);
326 if (pPostItMgr->GetActivePostIt()->GetStatus()!=SwPostItHelper::DELETED)
327 pOLV->InsertField(SvxFieldItem(aFld, EE_FEATURE_FIELD));
329 break;
331 case FN_INSERT_SOFT_HYPHEN:
332 case FN_INSERT_HARDHYPHEN:
333 case FN_INSERT_HARD_SPACE:
334 case SID_INSERT_RLM :
335 case SID_INSERT_LRM :
336 case SID_INSERT_ZWNBSP :
337 case SID_INSERT_ZWSP:
339 sal_Unicode cIns = 0;
340 switch(rReq.GetSlot())
342 case FN_INSERT_SOFT_HYPHEN: cIns = CHAR_SOFTHYPHEN; break;
343 case FN_INSERT_HARDHYPHEN: cIns = CHAR_HARDHYPHEN; break;
344 case FN_INSERT_HARD_SPACE: cIns = CHAR_HARDBLANK; break;
345 case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
346 case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
347 case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
348 case SID_INSERT_ZWNBSP: cIns = CHAR_ZWNBSP; break;
350 pOLV->InsertText( String(cIns), TRUE );
351 rReq.Done();
352 break;
354 case SID_CHARMAP:
356 if (pPostItMgr->GetActivePostIt()->GetStatus()!=SwPostItHelper::DELETED)
357 InsertSymbol(rReq);
358 break;
360 case FN_INSERT_STRING:
362 const SfxPoolItem* pItem = 0;
363 if(pNewAttrs)
364 pNewAttrs->GetItemState(nSlot, FALSE, &pItem );
365 if (pPostItMgr->GetActivePostIt()->GetStatus()!=SwPostItHelper::DELETED)
366 pOLV->InsertText(((const SfxStringItem *)pItem)->GetValue());
367 break;
370 case FN_FORMAT_FOOTNOTE_DLG:
372 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
373 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
375 VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( rView.GetWindow(), rView.GetWrtShell(), DLG_DOC_FOOTNOTE );
376 DBG_ASSERT(pDlg, "Dialogdiet fail!");
377 pDlg->Execute();
378 delete pDlg;
379 break;
381 case FN_NUMBERING_OUTLINE_DLG:
383 SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
384 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
385 DBG_ASSERT(pFact, "Dialogdiet fail!");
386 SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
387 rView.GetWindow(), &aTmp, rView.GetWrtShell());
388 DBG_ASSERT(pDlg, "Dialogdiet fail!");
389 pDlg->Execute();
390 delete pDlg;
391 rReq.Done();
393 break;
394 case SID_OPEN_XML_FILTERSETTINGS:
398 uno::Reference < ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), uno::UNO_QUERY);
399 if( xDialog.is() )
401 xDialog->execute();
404 catch( uno::Exception& )
407 rReq.Ignore ();
409 break;
410 case FN_WORDCOUNT_DIALOG:
412 SwWrtShell &rSh = rView.GetWrtShell();
413 SwDocStat aCurr;
414 SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
416 SwWait aWait( *rView.GetDocShell(), TRUE );
417 rSh.StartAction();
418 rSh.CountWords( aCurr );
419 rSh.UpdateDocStat( aDocStat );
420 rSh.EndAction();
423 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
424 DBG_ASSERT(pFact, "Dialogdiet fail!");
425 AbstractSwWordCountDialog* pDialog = pFact->CreateSwWordCountDialog( rView.GetWindow() );
426 pDialog->SetValues(aCurr, aDocStat );
427 pDialog->Execute();
428 delete pDialog;
430 break;
431 case SID_CHAR_DLG:
433 const SfxItemSet* pArgs = rReq.GetArgs();
435 if( !pArgs )
437 /* mod
438 SwView* pView = &GetView();
439 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
440 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
442 SfxItemSet aDlgAttr(GetPool(), EE_ITEMS_START, EE_ITEMS_END);
444 // util::Language gibts an der EditEngine nicht! Daher nicht im Set.
446 aDlgAttr.Put( aEditAttr );
447 aDlgAttr.Put( SvxKerningItem(0, RES_CHRATR_KERNING) );
449 //CHINA001 SwCharDlg* pDlg = new SwCharDlg(pView->GetWindow(), *pView, aDlgAttr, 0, sal_True);
450 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();//CHINA001
451 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");//CHINA001
453 SfxAbstractTabDialog* pDlg = pFact->CreateSwCharDlg( rView.GetWindow(), rView, aDlgAttr, DLG_CHAR,0, sal_True );
454 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
455 USHORT nRet = pDlg->Execute();
456 if(RET_OK == nRet )
458 rReq.Done( *( pDlg->GetOutputItemSet() ) );
459 aNewAttr.Put(*pDlg->GetOutputItemSet());
461 delete( pDlg );
462 if(RET_OK != nRet)
463 return ;
465 else
466 aNewAttr.Put(*pArgs);
467 break;
469 case SID_PARA_DLG:
471 const SfxItemSet* pArgs = rReq.GetArgs();
473 if (!pArgs)
475 /* mod todo ???
476 SwView* pView = &GetView();
477 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
478 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
480 SfxItemSet aDlgAttr(GetPool(),
481 EE_ITEMS_START, EE_ITEMS_END,
482 SID_ATTR_PARA_HYPHENZONE, SID_ATTR_PARA_HYPHENZONE,
483 SID_ATTR_PARA_SPLIT, SID_ATTR_PARA_SPLIT,
484 SID_ATTR_PARA_WIDOWS, SID_ATTR_PARA_WIDOWS,
485 SID_ATTR_PARA_ORPHANS, SID_ATTR_PARA_ORPHANS,
488 aDlgAttr.Put(aEditAttr);
491 aDlgAttr.Put( SvxHyphenZoneItem( sal_False, RES_PARATR_HYPHENZONE) );
492 aDlgAttr.Put( SvxFmtBreakItem( SVX_BREAK_NONE, RES_BREAK ) );
493 aDlgAttr.Put( SvxFmtSplitItem( sal_True, RES_PARATR_SPLIT ) );
494 aDlgAttr.Put( SvxWidowsItem( 0, RES_PARATR_WIDOWS ) );
495 aDlgAttr.Put( SvxOrphansItem( 0, RES_PARATR_ORPHANS ) );
497 //CHINA001 SwParaDlg* pDlg = new SwParaDlg(GetView().GetWindow(), GetView(), aDlgAttr, DLG_STD, 0, sal_True);
499 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();//CHINA001
500 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");//CHINA001
502 SfxAbstractTabDialog* pDlg = pFact->CreateSwParaDlg( rView.GetWindow(), rView, aDlgAttr,DLG_STD, DLG_PARA, 0, sal_True );
503 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
504 USHORT nRet = pDlg->Execute();
505 if(RET_OK == nRet)
507 rReq.Done( *( pDlg->GetOutputItemSet() ) );
508 aNewAttr.Put(*pDlg->GetOutputItemSet());
510 delete( pDlg );
511 if(RET_OK != nRet)
512 return;
514 else
515 aNewAttr.Put(*pArgs);
516 break;
519 case SID_AUTOSPELL_CHECK:
521 rView.ExecuteSlot(rReq);
522 break;
524 case SID_ATTR_PARA_LEFT_TO_RIGHT:
525 case SID_ATTR_PARA_RIGHT_TO_LEFT:
527 sal_Bool bLeftToRight = nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT;
529 const SfxPoolItem* pPoolItem;
530 if( pNewAttrs && SFX_ITEM_SET == pNewAttrs->GetItemState( nSlot, TRUE, &pPoolItem ) )
532 if( !( (SfxBoolItem*)pPoolItem)->GetValue() )
533 bLeftToRight = !bLeftToRight;
535 SfxItemSet aAttr( *aNewAttr.GetPool(),
536 EE_PARA_JUST, EE_PARA_JUST,
537 EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
538 0 );
540 USHORT nAdjust = SVX_ADJUST_LEFT;
541 if( SFX_ITEM_ON == aEditAttr.GetItemState(EE_PARA_JUST, TRUE, &pPoolItem ) )
542 nAdjust = ( (SvxAdjustItem*)pPoolItem)->GetEnumValue();
544 if( bLeftToRight )
546 aAttr.Put( SvxFrameDirectionItem( FRMDIR_HORI_LEFT_TOP, EE_PARA_WRITINGDIR ) );
547 if( nAdjust == SVX_ADJUST_RIGHT )
548 aAttr.Put( SvxAdjustItem( SVX_ADJUST_LEFT, EE_PARA_JUST ) );
550 else
552 aAttr.Put( SvxFrameDirectionItem( FRMDIR_HORI_RIGHT_TOP, EE_PARA_WRITINGDIR ) );
553 if( nAdjust == SVX_ADJUST_LEFT )
554 aAttr.Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
556 pOLV->SetAttribs(aAttr);
557 break;
561 if(nEEWhich && pNewAttrs)
562 aNewAttr.Put(pNewAttrs->Get(nWhich), nEEWhich);
564 Rectangle aNullRect;
565 Rectangle aOutRect = pOLV->GetOutputArea();
566 if (aNullRect != aOutRect)
567 pOLV->SetAttribs(aNewAttr);
569 rView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
570 if ( pOLV->GetOutliner()->IsModified() )
571 rView.GetWrtShell().SetModified();
575 void SwAnnotationShell::GetState(SfxItemSet& rSet)
577 //TODO: clean this up!!!
578 // FN_SET_SUPER_SCRIPT
579 //SID_ATTR_PARA_ADJUST
580 //SID_ATTR_PARA_ADJUST_BLOCK
582 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
583 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
584 return;
586 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
587 SfxItemSet aEditAttr(pOLV->GetAttribs());
589 SfxWhichIter aIter(rSet);
590 sal_uInt16 nWhich = aIter.FirstWhich();
591 while(nWhich)
593 sal_uInt16 nEEWhich = 0;
594 USHORT nSlotId = GetPool().GetSlotId( nWhich );
595 switch( nSlotId )
597 case SID_ATTR_CHAR_FONT:
598 case SID_ATTR_CHAR_FONTHEIGHT:
599 case SID_ATTR_CHAR_WEIGHT:
600 case SID_ATTR_CHAR_POSTURE:
602 if ( pOLV )
604 USHORT nScriptType = pOLV->GetSelectedScriptType();
605 SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
606 if( !pSecondPool )
607 pSecondPool = aEditAttr.GetPool();
608 SvxScriptSetItem aSetItem( nSlotId, *pSecondPool );
609 aSetItem.GetItemSet().Put( aEditAttr, FALSE );
610 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
611 if( pI )
612 rSet.Put( *pI, nWhich );
613 else
614 rSet.InvalidateItem( nWhich );
616 else
617 rSet.InvalidateItem( nWhich );
619 break;
620 case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
621 case SID_ATTR_CHAR_UNDERLINE: nEEWhich = EE_CHAR_UNDERLINE;break;
622 case SID_ATTR_CHAR_OVERLINE: nEEWhich = EE_CHAR_OVERLINE;break;
623 case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
624 case SID_ATTR_CHAR_SHADOWED: nEEWhich = EE_CHAR_SHADOW;break;
625 case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT;break;
626 case SID_ATTR_CHAR_LANGUAGE : nEEWhich = EE_CHAR_LANGUAGE;break;
627 case FN_SET_SUPER_SCRIPT:
628 case FN_SET_SUB_SCRIPT:
630 USHORT nEsc = 0;
631 const SfxPoolItem *pEscItem = 0;
632 if (nWhich==FN_SET_SUPER_SCRIPT)
633 nEsc = SVX_ESCAPEMENT_SUPERSCRIPT;
634 else
635 nEsc = SVX_ESCAPEMENT_SUBSCRIPT;
637 if( !pEscItem )
638 pEscItem = &aEditAttr.Get( EE_CHAR_ESCAPEMENT );
640 if( nEsc == ((const SvxEscapementItem*)pEscItem)->GetEnumValue() )
641 rSet.Put( SfxBoolItem( nWhich, sal_True ));
642 else
643 rSet.InvalidateItem( nWhich );
644 break;
646 case SID_ATTR_PARA_ADJUST_LEFT:
647 case SID_ATTR_PARA_ADJUST_RIGHT:
648 case SID_ATTR_PARA_ADJUST_CENTER:
649 case SID_ATTR_PARA_ADJUST_BLOCK:
651 const SfxPoolItem *pAdjust = 0;
652 int eAdjust = 0;
654 if (nWhich==SID_ATTR_PARA_ADJUST_LEFT)
655 eAdjust = SVX_ADJUST_LEFT;
656 else
657 if (nWhich==SID_ATTR_PARA_ADJUST_RIGHT)
658 eAdjust = SVX_ADJUST_RIGHT;
659 else
660 if (nWhich==SID_ATTR_PARA_ADJUST_CENTER)
661 eAdjust = SVX_ADJUST_CENTER;
662 else
663 if (nWhich==SID_ATTR_PARA_ADJUST_BLOCK)
664 eAdjust = SVX_ADJUST_BLOCK;
666 if( !pAdjust )
667 aEditAttr.GetItemState( EE_PARA_JUST, sal_False, &pAdjust);
669 if( !pAdjust || IsInvalidItem( pAdjust ))
670 rSet.InvalidateItem( nSlotId ), nSlotId = 0;
671 else
673 if ( eAdjust == ((const SvxAdjustItem*)pAdjust)->GetAdjust())
674 rSet.Put( SfxBoolItem( nWhich, sal_True ));
675 else
676 rSet.InvalidateItem( nWhich );
678 break;
680 case SID_ATTR_PARA_LINESPACE_10:
681 case SID_ATTR_PARA_LINESPACE_15:
682 case SID_ATTR_PARA_LINESPACE_20:
684 const SfxPoolItem *pLSpace = 0;
685 int nLSpace = 0;
687 if (nWhich==SID_ATTR_PARA_LINESPACE_10)
688 nLSpace = 100;
689 else
690 if (nWhich==SID_ATTR_PARA_LINESPACE_15)
691 nLSpace = 150;
692 else
693 if (nWhich==SID_ATTR_PARA_LINESPACE_20)
694 nLSpace = 200;
696 if( !pLSpace )
697 aEditAttr.GetItemState( EE_PARA_SBL, sal_False, &pLSpace );
699 if( !pLSpace || IsInvalidItem( pLSpace ))
700 rSet.InvalidateItem( nSlotId ), nSlotId = 0;
701 else
703 if( nLSpace == ((const SvxLineSpacingItem*)pLSpace)->GetPropLineSpace() )
704 rSet.Put( SfxBoolItem( nWhich, sal_True ));
705 else
706 rSet.InvalidateItem( nWhich );
708 break;
710 case SID_AUTOSPELL_CHECK:
712 const SfxPoolItem* pState = rView.GetSlotState(nWhich);
713 if (pState)
714 rSet.Put(SfxBoolItem(nWhich, ((const SfxBoolItem*)pState)->GetValue()));
715 else
716 rSet.DisableItem( nWhich );
717 break;
719 case SID_ATTR_PARA_LEFT_TO_RIGHT:
720 case SID_ATTR_PARA_RIGHT_TO_LEFT:
722 if ( !SvtLanguageOptions().IsCTLFontEnabled() )
723 rSet.DisableItem( nWhich );
724 else
726 if(pOLV->GetOutliner() && pOLV->GetOutliner()->IsVertical())
727 rSet.DisableItem( nWhich );
728 else
730 BOOL bFlag = FALSE;
731 switch( ( ( (SvxFrameDirectionItem&) aEditAttr.Get( EE_PARA_WRITINGDIR ) ) ).GetValue() )
733 case FRMDIR_HORI_LEFT_TOP:
735 bFlag = nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT;
736 rSet.Put( SfxBoolItem( nWhich, bFlag ));
737 break;
739 case FRMDIR_HORI_RIGHT_TOP:
741 bFlag = nWhich != SID_ATTR_PARA_LEFT_TO_RIGHT;
742 rSet.Put( SfxBoolItem( nWhich, bFlag ));
743 break;
749 break;
750 case SID_INSERT_RLM :
751 case SID_INSERT_LRM :
752 case SID_INSERT_ZWNBSP :
753 case SID_INSERT_ZWSP:
755 SvtCTLOptions aCTLOptions;
756 sal_Bool bEnabled = aCTLOptions.IsCTLFontEnabled();
757 rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, bEnabled );
758 if(!bEnabled)
759 rSet.DisableItem(nWhich);
761 break;
762 default:
763 rSet.InvalidateItem( nWhich );
764 break;
767 if(nEEWhich)
768 rSet.Put(aEditAttr.Get(nEEWhich, sal_True), nWhich);
770 if (pPostItMgr->GetActivePostIt()->GetStatus()==SwPostItHelper::DELETED)
771 rSet.DisableItem( nWhich );
773 nWhich = aIter.NextWhich();
777 void SwAnnotationShell::ExecSearch(SfxRequest& rReq, BOOL bNoMessage)
779 rView.ExecSearch(rReq,bNoMessage);
782 void SwAnnotationShell::StateSearch(SfxItemSet &rSet)
784 rView.StateSearch(rSet);
787 void SwAnnotationShell::ExecClpbrd(SfxRequest &rReq)
789 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
790 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
791 return;
793 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
794 SfxItemSet aEditAttr(pOLV->GetAttribs());
795 SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
797 long aOldHeight = pPostItMgr->GetActivePostIt()->GetPostItTextHeight();
798 sal_uInt16 nSlot = rReq.GetSlot();
799 switch (nSlot)
801 case SID_CUT:
802 pOLV->Cut();
803 break;
804 case SID_COPY:
805 pOLV->Copy();
806 break;
807 case SID_PASTE:
808 if (pPostItMgr->GetActivePostIt()->GetStatus()!=SwPostItHelper::DELETED)
809 pOLV->Paste();
810 break;
811 case FN_PASTESPECIAL:
813 if (pPostItMgr->GetActivePostIt()->GetStatus()!=SwPostItHelper::DELETED)
815 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
816 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( &rView.GetEditWin() );
818 pDlg->Insert( SOT_FORMAT_STRING, aEmptyStr );
819 pDlg->Insert( SOT_FORMAT_RTF, aEmptyStr );
821 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &rView.GetEditWin() ) );
823 ULONG nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
825 if (nFormat > 0)
827 if (nFormat == SOT_FORMAT_STRING)
828 pOLV->Paste();
829 else
830 pOLV->PasteSpecial();
832 delete pDlg;
834 break;
836 case SID_CLIPBOARD_FORMAT_ITEMS:
838 ULONG nFormat = 0;
839 const SfxPoolItem* pItem;
840 if ( rReq.GetArgs() && rReq.GetArgs()->GetItemState(nSlot, TRUE, &pItem) == SFX_ITEM_SET &&
841 pItem->ISA(SfxUInt32Item) )
843 nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
846 if ( nFormat )
848 if (SOT_FORMAT_STRING == nFormat)
849 pOLV->Paste();
850 else
851 pOLV->PasteSpecial();
853 break;
856 pPostItMgr->GetActivePostIt()->ResizeIfNeccessary(aOldHeight,pPostItMgr->GetActivePostIt()->GetPostItTextHeight());
859 void SwAnnotationShell::StateClpbrd(SfxItemSet &rSet)
861 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
862 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
863 return;
864 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
866 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &rView.GetEditWin() ) );
867 bool bPastePossible = ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) || aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
868 bPastePossible = bPastePossible && (pPostItMgr->GetActivePostIt()->GetStatus()!=SwPostItHelper::DELETED);
870 SfxWhichIter aIter(rSet);
871 sal_uInt16 nWhich = aIter.FirstWhich();
873 while(nWhich)
875 switch(nWhich)
877 case SID_CUT:
879 if ( (pPostItMgr->GetActivePostIt()->GetStatus()==SwPostItHelper::DELETED) || !pOLV->HasSelection() )
880 rSet.DisableItem( nWhich );
882 case SID_COPY:
884 if( !pOLV->HasSelection() )
885 rSet.DisableItem( nWhich );
886 break;
888 case SID_PASTE:
889 case FN_PASTESPECIAL:
891 if( !bPastePossible )
892 rSet.DisableItem( nWhich );
893 break;
895 case SID_CLIPBOARD_FORMAT_ITEMS:
897 if ( bPastePossible )
899 SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
900 if ( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
901 aFormats.AddClipbrdFormat( SOT_FORMAT_RTF );
902 //if ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) )
903 aFormats.AddClipbrdFormat( SOT_FORMAT_STRING );
904 rSet.Put( aFormats );
906 else
907 rSet.DisableItem( nWhich );
908 break;
911 nWhich = aIter.NextWhich();
915 void SwAnnotationShell::StateStatusLine(SfxItemSet &rSet)
917 SfxWhichIter aIter( rSet );
918 USHORT nWhich = aIter.FirstWhich();
920 while( nWhich )
922 switch( nWhich )
924 case FN_STAT_SELMODE:
926 rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 0));
927 rSet.DisableItem( nWhich );
928 break;
930 case FN_STAT_TEMPLATE:
932 rSet.DisableItem( nWhich );
933 break;
936 nWhich = aIter.NextWhich();
940 void SwAnnotationShell::StateInsert(SfxItemSet &rSet)
942 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
943 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
944 return;
946 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
947 SfxWhichIter aIter(rSet);
948 sal_uInt16 nWhich = aIter.FirstWhich();
950 while(nWhich)
952 switch(nWhich)
954 case SID_HYPERLINK_GETLINK:
956 SvxHyperlinkItem aHLinkItem;
957 aHLinkItem.SetInsertMode(HLINK_FIELD);
959 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
961 if (pFieldItem)
963 const SvxFieldData* pField = pFieldItem->GetField();
965 if (pField->ISA(SvxURLField))
967 aHLinkItem.SetName(((const SvxURLField*) pField)->GetRepresentation());
968 aHLinkItem.SetURL(((const SvxURLField*) pField)->GetURL());
969 aHLinkItem.SetTargetFrame(((const SvxURLField*) pField)->GetTargetFrame());
972 else
974 String sSel(pOLV->GetSelected());
975 sSel.Erase(255);
976 sSel.EraseTrailingChars();
977 aHLinkItem.SetName(sSel);
980 sal_uInt16 nHtmlMode = ::GetHtmlMode(rView.GetDocShell());
981 aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
982 ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
984 rSet.Put(aHLinkItem);
986 break;
989 if (pPostItMgr->GetActivePostIt()->GetStatus()==SwPostItHelper::DELETED)
990 rSet.DisableItem( nWhich );
992 nWhich = aIter.NextWhich();
997 void SwAnnotationShell::NoteExec(SfxRequest &rReq)
999 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1000 if ( !pPostItMgr )
1001 return;
1003 sal_uInt16 nSlot = rReq.GetSlot();
1004 switch (nSlot)
1006 case FN_REPLY:
1007 case FN_POSTIT:
1008 case FN_DELETE_COMMENT:
1009 case FN_DELETE_NOTE:
1010 if ( pPostItMgr->GetActivePostIt() )
1011 pPostItMgr->GetActivePostIt()->ExecuteCommand(nSlot);
1012 break;
1013 case FN_DELETE_ALL_NOTES:
1014 pPostItMgr->Delete();
1015 break;
1016 case FN_DELETE_NOTE_AUTHOR:
1018 SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, nSlot, FALSE);
1019 if ( pItem )
1020 pPostItMgr->Delete( pItem->GetValue() );
1021 break;
1023 case FN_HIDE_NOTE:
1025 if ( Mgr()->GetActivePostIt() == this )
1027 Mgr()->SetActivePostIt(0);
1028 // put the cursor back into the document
1029 SwitchToFieldPos();
1031 Mgr()->Hide(mpFld);
1033 break;
1034 case FN_HIDE_ALL_NOTES:
1035 pPostItMgr->Hide();
1036 break;
1037 case FN_HIDE_NOTE_AUTHOR:
1039 SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, nSlot, FALSE);
1040 if ( pItem )
1041 pPostItMgr->Hide( pItem->GetValue() );
1046 void SwAnnotationShell::GetNoteState(SfxItemSet &rSet)
1048 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1049 SfxWhichIter aIter(rSet);
1050 sal_uInt16 nWhich = aIter.FirstWhich();
1051 while(nWhich)
1053 USHORT nSlotId = GetPool().GetSlotId( nWhich );
1054 switch( nSlotId )
1056 case FN_POSTIT:
1057 case FN_DELETE_NOTE:
1058 case FN_DELETE_NOTE_AUTHOR:
1059 case FN_DELETE_ALL_NOTES:
1060 case FN_HIDE_NOTE:
1061 case FN_HIDE_NOTE_AUTHOR:
1062 case FN_HIDE_ALL_NOTES:
1064 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() || !pPostItMgr->GetActivePostIt()->ISA(SwPostIt))
1065 rSet.DisableItem(nWhich);
1066 break;
1068 case FN_DELETE_COMMENT:
1070 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() ) //|| !pPostItMgr->GetActivePostIt()->ISA(SwRedComment))
1071 rSet.DisableItem(nWhich);
1072 break;
1074 case FN_REPLY:
1076 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() || !pPostItMgr->GetActivePostIt()->ISA(SwPostIt))
1077 rSet.DisableItem(nWhich);
1078 else
1080 SvtUserOptions aUserOpt;
1081 String sAuthor;
1082 if( !(sAuthor = aUserOpt.GetFullName()).Len())
1083 if( !(sAuthor = aUserOpt.GetID()).Len() )
1084 sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR ));
1085 if (sAuthor == pPostItMgr->GetActivePostIt()->GetAuthor())
1086 rSet.DisableItem(nWhich);
1088 break;
1090 default:
1091 rSet.InvalidateItem( nWhich );
1092 break;
1095 if (pPostItMgr->GetActivePostIt())
1097 if ( (pPostItMgr->GetActivePostIt()->IsProtected()) &&
1098 ( (nSlotId==FN_DELETE_NOTE) || (nSlotId==FN_REPLY) ) )
1099 rSet.DisableItem( nWhich );
1101 nWhich = aIter.NextWhich();
1105 void SwAnnotationShell::ExecLingu(SfxRequest &rReq)
1107 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1108 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
1109 return;
1111 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
1112 SfxItemSet aEditAttr(pOLV->GetAttribs());
1113 sal_uInt16 nSlot = rReq.GetSlot();
1114 SwWrtShell &rSh = rView.GetWrtShell();
1115 bool bRestoreSelection = false;
1116 ESelection aOldSelection;
1118 switch (nSlot)
1120 case SID_LANGUAGE_STATUS:
1122 aOldSelection = pOLV->GetSelection();
1123 if (!pOLV->GetEditView().HasSelection())
1125 bRestoreSelection = true;
1126 pOLV->GetEditView().SelectCurrentWord();
1129 bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,rView,rSh);
1130 break;
1132 case FN_THESAURUS_DLG:
1134 pOLV->StartThesaurus();
1135 break;
1137 case SID_HANGUL_HANJA_CONVERSION:
1138 pOLV->StartTextConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, NULL,
1139 i18n::TextConversionOption::CHARACTER_BY_CHARACTER, sal_True, sal_False );
1140 break;
1142 case SID_CHINESE_CONVERSION:
1144 //open ChineseTranslationDialog
1145 Reference< XComponentContext > xContext(
1146 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1147 if(xContext.is())
1149 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1150 if(xMCF.is())
1152 Reference< ui::dialogs::XExecutableDialog > xDialog(
1153 xMCF->createInstanceWithContext(
1154 rtl::OUString::createFromAscii("com.sun.star.linguistic2.ChineseTranslationDialog")
1155 , xContext), UNO_QUERY);
1156 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1157 if( xInit.is() )
1159 // initialize dialog
1160 Reference< awt::XWindow > xDialogParentWindow(0);
1161 Sequence<Any> aSeq(1);
1162 Any* pArray = aSeq.getArray();
1163 PropertyValue aParam;
1164 aParam.Name = rtl::OUString::createFromAscii("ParentWindow");
1165 aParam.Value <<= makeAny(xDialogParentWindow);
1166 pArray[0] <<= makeAny(aParam);
1167 xInit->initialize( aSeq );
1169 //execute dialog
1170 sal_Int16 nDialogRet = xDialog->execute();
1171 if( RET_OK == nDialogRet )
1173 //get some parameters from the dialog
1174 sal_Bool bToSimplified = sal_True;
1175 sal_Bool bUseVariants = sal_True;
1176 sal_Bool bCommonTerms = sal_True;
1177 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
1178 if( xProp.is() )
1182 xProp->getPropertyValue( C2U("IsDirectionToSimplified") ) >>= bToSimplified;
1183 xProp->getPropertyValue( C2U("IsUseCharacterVariants") ) >>= bUseVariants;
1184 xProp->getPropertyValue( C2U("IsTranslateCommonTerms") ) >>= bCommonTerms;
1186 catch( Exception& )
1191 //execute translation
1192 sal_Int16 nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1193 sal_Int16 nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1194 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1195 if( !bCommonTerms )
1196 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1198 Font aTargetFont = pOLV->GetWindow()->GetDefaultFont( DEFAULTFONT_CJK_TEXT,
1199 nTargetLang, DEFAULTFONT_FLAGS_ONLYONE );
1201 pOLV->StartTextConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, sal_False, sal_False );
1204 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1205 if( xComponent.is() )
1206 xComponent->dispose();
1210 break;
1213 if (bRestoreSelection)
1215 // restore selection
1216 pOLV->GetEditView().SetSelection( aOldSelection );
1220 void SwAnnotationShell::GetLinguState(SfxItemSet &rSet)
1222 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1223 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
1224 return;
1226 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
1227 SfxItemSet aEditAttr(pOLV->GetAttribs());
1229 SfxWhichIter aIter(rSet);
1230 sal_uInt16 nWhich = aIter.FirstWhich();
1231 while(nWhich)
1233 switch (nWhich)
1235 case SID_LANGUAGE_STATUS:
1237 SwLangHelper::GetLanguageStatus(pOLV,rSet);
1238 break;
1240 // disable "Thesaurus" if the language is not supported
1241 case FN_THESAURUS_DLG:
1243 const SfxPoolItem &rItem = rView.GetWrtShell().GetDoc()->GetDefault(
1244 GetWhichOfScript( RES_CHRATR_LANGUAGE,
1245 GetI18NScriptTypeOfLanguage( (USHORT)GetAppLanguage())) );
1246 LanguageType nLang = ((const SvxLanguageItem &)
1247 rItem).GetLanguage();
1248 uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() );
1249 if (!xThes.is() || nLang == LANGUAGE_NONE ||
1250 !xThes->hasLocale( SvxCreateLocale( nLang ) ))
1251 rSet.DisableItem( FN_THESAURUS_DLG );
1253 break;
1254 case SID_HANGUL_HANJA_CONVERSION:
1255 case SID_CHINESE_CONVERSION:
1257 if (!SvtCJKOptions().IsAnyEnabled())
1259 rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_False );
1260 rSet.DisableItem(nWhich);
1262 else
1263 rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
1265 break;
1268 if (pPostItMgr->GetActivePostIt()->GetStatus()==SwPostItHelper::DELETED)
1269 rSet.DisableItem( nWhich );
1271 nWhich = aIter.NextWhich();
1275 void SwAnnotationShell::ExecTransliteration(SfxRequest &rReq)
1277 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1278 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
1279 return;
1281 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
1283 using namespace ::com::sun::star::i18n;
1285 sal_uInt32 nMode = 0;
1287 switch( rReq.GetSlot() )
1289 case SID_TRANSLITERATE_UPPER:
1290 nMode = TransliterationModules_LOWERCASE_UPPERCASE;
1291 break;
1292 case SID_TRANSLITERATE_LOWER:
1293 nMode = TransliterationModules_UPPERCASE_LOWERCASE;
1294 break;
1295 case SID_TRANSLITERATE_HALFWIDTH:
1296 nMode = TransliterationModules_FULLWIDTH_HALFWIDTH;
1297 break;
1298 case SID_TRANSLITERATE_FULLWIDTH:
1299 nMode = TransliterationModules_HALFWIDTH_FULLWIDTH;
1300 break;
1301 case SID_TRANSLITERATE_HIRAGANA:
1302 nMode = TransliterationModules_KATAKANA_HIRAGANA;
1303 break;
1304 case SID_TRANSLITERATE_KATAGANA:
1305 nMode = TransliterationModules_HIRAGANA_KATAKANA;
1306 break;
1308 default:
1309 ASSERT(!this, "falscher Dispatcher");
1312 if( nMode )
1314 pOLV->TransliterateText( nMode );
1319 void SwAnnotationShell::ExecUndo(SfxRequest &rReq)
1321 const SfxItemSet* pArgs = rReq.GetArgs();
1322 SfxUndoManager* pUndoManager = GetUndoManager();
1323 SwWrtShell &rSh = rView.GetWrtShell();
1325 long aOldHeight = rView.GetPostItMgr()->GetActivePostIt() ? rView.GetPostItMgr()->GetActivePostIt()->GetPostItTextHeight() : 0;
1327 USHORT nId = rReq.GetSlot();
1328 sal_uInt16 nCnt = 1;
1329 const SfxPoolItem* pItem=0;
1330 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nId, FALSE, &pItem ) )
1331 nCnt = ((SfxUInt16Item*)pItem)->GetValue();
1332 switch( nId )
1334 case SID_UNDO:
1336 if ( pUndoManager )
1338 sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1339 sal_uInt16 nSteps = nCnt;
1340 if ( nCount < nCnt )
1342 nCnt = nCnt - nCount;
1343 nSteps = nCount;
1345 else
1346 nCnt = 0;
1348 while( nSteps-- )
1349 pUndoManager->Undo(0);
1352 if ( nCnt )
1353 rSh.Do( SwWrtShell::UNDO, nCnt );
1355 break;
1358 case SID_REDO:
1360 if ( pUndoManager )
1362 sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1363 sal_uInt16 nSteps = nCnt;
1364 if ( nCount < nCnt )
1366 nCnt = nCnt - nCount;
1367 nSteps = nCount;
1369 else
1370 nCnt = 0;
1372 while( nSteps-- )
1373 pUndoManager->Redo(0);
1376 if ( nCnt )
1377 rSh.Do( SwWrtShell::REDO, nCnt );
1379 break;
1383 if (rView.GetPostItMgr()->GetActivePostIt())
1384 rView.GetPostItMgr()->GetActivePostIt()->ResizeIfNeccessary(aOldHeight,rView.GetPostItMgr()->GetActivePostIt()->GetPostItTextHeight());
1387 void SwAnnotationShell::StateUndo(SfxItemSet &rSet)
1389 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1390 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
1391 return;
1393 SfxWhichIter aIter(rSet);
1394 USHORT nWhich = aIter.FirstWhich();
1395 SfxUndoManager* pUndoManager = GetUndoManager();
1396 SfxViewFrame *pSfxViewFrame = rView.GetViewFrame();
1397 SwWrtShell &rSh = rView.GetWrtShell();
1399 while( nWhich )
1401 switch ( nWhich )
1403 case SID_UNDO:
1405 sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1406 if ( nCount )
1407 pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1408 else if( rSh.GetUndoIds() )
1409 rSet.Put( SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::UNDO)) );
1410 else
1411 rSet.DisableItem(nWhich);
1412 break;
1414 case SID_REDO:
1416 sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1417 if ( nCount )
1418 pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1419 else if(rSh.GetRedoIds())
1420 rSet.Put(SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::REDO)) );
1421 else
1422 rSet.DisableItem(nWhich);
1423 break;
1425 case SID_GETUNDOSTRINGS:
1426 case SID_GETREDOSTRINGS:
1428 if( pUndoManager )
1430 UniString (SfxUndoManager:: *fnGetComment)( USHORT ) const;
1432 sal_uInt16 nCount;
1433 if( SID_GETUNDOSTRINGS == nWhich )
1435 nCount = pUndoManager->GetUndoActionCount();
1436 fnGetComment = &SfxUndoManager::GetUndoActionComment;
1438 else
1440 nCount = pUndoManager->GetRedoActionCount();
1441 fnGetComment = &SfxUndoManager::GetRedoActionComment;
1444 String sList;
1445 if( nCount )
1447 for( sal_uInt16 n = 0; n < nCount; ++n )
1448 ( sList += (pUndoManager->*fnGetComment)( n ) )
1449 += '\n';
1452 SfxStringListItem aItem( nWhich );
1453 if( nWhich == SID_GETUNDOSTRINGS && rSh.GetUndoIds() )
1455 rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1457 else if( nWhich == SID_GETREDOSTRINGS && rSh.GetRedoIds() )
1459 rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1462 sList += aItem.GetString();
1463 aItem.SetString( sList );
1464 rSet.Put( aItem );
1466 else
1467 rSet.DisableItem( nWhich );
1469 break;
1471 default:
1473 pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1474 break;
1479 if (pPostItMgr->GetActivePostIt()->GetStatus()==SwPostItHelper::DELETED)
1480 rSet.DisableItem( nWhich );
1482 nWhich = aIter.NextWhich();
1486 void SwAnnotationShell::StateDisableItems( SfxItemSet &rSet )
1488 SfxWhichIter aIter(rSet);
1489 USHORT nWhich = aIter.FirstWhich();
1490 while (nWhich)
1492 rSet.DisableItem( nWhich );
1493 nWhich = aIter.NextWhich();
1497 void SwAnnotationShell::InsertSymbol(SfxRequest& rReq)
1499 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1500 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
1501 return;
1503 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
1505 const SfxItemSet *pArgs = rReq.GetArgs();
1506 const SfxPoolItem* pItem = 0;
1507 if( pArgs )
1508 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), FALSE, &pItem);
1510 String sSym;
1511 String sFontName;
1512 if ( pItem )
1514 sSym = ((const SfxStringItem*)pItem)->GetValue();
1515 const SfxPoolItem* pFtItem = NULL;
1516 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), FALSE, &pFtItem);
1517 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
1518 if ( pFontItem )
1519 sFontName = pFontItem->GetValue();
1522 SfxItemSet aSet(pOLV->GetAttribs());
1523 USHORT nScript = pOLV->GetSelectedScriptType();
1524 SvxFontItem aSetDlgFont( RES_CHRATR_FONT );
1526 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1527 aSetItem.GetItemSet().Put( aSet, FALSE );
1528 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1529 if( pI )
1530 aSetDlgFont = *(SvxFontItem*)pI;
1531 else
1532 aSetDlgFont = (SvxFontItem&)aSet.Get( GetWhichOfScript(
1533 SID_ATTR_CHAR_FONT,
1534 GetI18NScriptTypeOfLanguage( (USHORT)GetAppLanguage() ) ));
1535 if (!sFontName.Len())
1536 sFontName = aSetDlgFont.GetFamilyName();
1539 Font aFont(sFontName, Size(1,1));
1540 if( !sSym.Len() )
1542 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1544 SfxAllItemSet aAllSet( GetPool() );
1545 aAllSet.Put( SfxBoolItem( FN_PARAM_1, FALSE ) );
1547 SwViewOption aOpt(*rView.GetWrtShell().GetViewOptions());
1548 String sSymbolFont = aOpt.GetSymbolFont();
1549 if( sSymbolFont.Len() )
1550 aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
1551 else
1552 aAllSet.Put( SfxStringItem( SID_FONT_NAME, aSetDlgFont.GetFamilyName() ) );
1554 // Wenn Zeichen selektiert ist kann es angezeigt werden
1555 SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( rView.GetWindow(), aAllSet,
1556 rView.GetViewFrame()->GetFrame()->GetFrameInterface(), RID_SVXDLG_CHARMAP );
1558 USHORT nResult = pDlg->Execute();
1559 if( nResult == RET_OK )
1561 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, FALSE );
1562 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, FALSE );
1563 if ( pFontItem )
1565 aFont.SetName( pFontItem->GetFamilyName() );
1566 aFont.SetStyleName( pFontItem->GetStyleName() );
1567 aFont.SetCharSet( pFontItem->GetCharSet() );
1568 aFont.SetPitch( pFontItem->GetPitch() );
1571 if ( pCItem )
1573 sSym = pCItem->GetValue();
1574 aOpt.SetSymbolFont(aFont.GetName());
1575 SW_MOD()->ApplyUsrPref(aOpt, &rView);
1579 delete( pDlg );
1582 if( sSym.Len() )
1584 // nicht flackern
1585 pOLV->HideCursor();
1586 Outliner * pOutliner = pOLV->GetOutliner();
1587 pOutliner->SetUpdateMode(FALSE);
1589 SfxItemSet aOldSet( pOLV->GetAttribs() );
1590 SfxItemSet aFontSet( *aOldSet.GetPool(),
1591 EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
1592 EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CJK,
1593 EE_CHAR_FONTINFO_CTL, EE_CHAR_FONTINFO_CTL,
1594 0 );
1595 aFontSet.Set( aOldSet );
1597 // String einfuegen
1598 pOLV->InsertText( sSym, TRUE );
1600 // attributieren (Font setzen)
1601 SfxItemSet aSetFont( *aFontSet.GetPool(), aFontSet.GetRanges() );
1602 SvxFontItem aFontItem (aFont.GetFamily(), aFont.GetName(),
1603 aFont.GetStyleName(), aFont.GetPitch(),
1604 aFont.GetCharSet(),
1605 EE_CHAR_FONTINFO );
1606 USHORT nScriptBreak = pBreakIt->GetAllScriptsOfText( sSym );
1607 if( SCRIPTTYPE_LATIN & nScriptBreak )
1608 aSetFont.Put( aFontItem, EE_CHAR_FONTINFO );
1609 if( SCRIPTTYPE_ASIAN & nScriptBreak )
1610 aSetFont.Put( aFontItem, EE_CHAR_FONTINFO_CJK );
1611 if( SCRIPTTYPE_COMPLEX & nScriptBreak )
1612 aSetFont.Put( aFontItem, EE_CHAR_FONTINFO_CTL );
1613 pOLV->SetAttribs(aSetFont);
1615 // Selektion loeschen
1616 ESelection aSel(pOLV->GetSelection());
1617 aSel.nStartPara = aSel.nEndPara;
1618 aSel.nStartPos = aSel.nEndPos;
1619 pOLV->SetSelection(aSel);
1621 // Alten Font restaurieren
1622 pOLV->SetAttribs( aFontSet );
1624 // ab jetzt wieder anzeigen
1625 pOutliner->SetUpdateMode(TRUE);
1626 pOLV->ShowCursor();
1628 rReq.AppendItem( SfxStringItem( GetPool().GetWhich(SID_CHARMAP), sSym ) );
1629 if(aFont.GetName().Len())
1630 rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aFont.GetName() ) );
1631 rReq.Done();