merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / shells / annotsh.cxx
blob68b8e87c3bc1801b3c3a9d6134b87fe9d8cd00b5
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));
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 if ( (pPostItMgr->GetActivePostIt()->GetStatus()!=SwPostItHelper::DELETED) && pOLV->HasSelection() )
803 pOLV->Cut();
804 break;
805 case SID_COPY:
806 if( pOLV->HasSelection() )
807 pOLV->Copy();
808 break;
809 case SID_PASTE:
810 if (pPostItMgr->GetActivePostIt()->GetStatus()!=SwPostItHelper::DELETED)
811 pOLV->Paste();
812 break;
813 case SID_PASTE_SPECIAL:
815 if (pPostItMgr->GetActivePostIt()->GetStatus()!=SwPostItHelper::DELETED)
817 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
818 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( &rView.GetEditWin() );
820 pDlg->Insert( SOT_FORMAT_STRING, aEmptyStr );
821 pDlg->Insert( SOT_FORMAT_RTF, aEmptyStr );
823 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &rView.GetEditWin() ) );
825 ULONG nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
827 if (nFormat > 0)
829 if (nFormat == SOT_FORMAT_STRING)
830 pOLV->Paste();
831 else
832 pOLV->PasteSpecial();
834 delete pDlg;
836 break;
838 case SID_CLIPBOARD_FORMAT_ITEMS:
840 ULONG nFormat = 0;
841 const SfxPoolItem* pItem;
842 if ( rReq.GetArgs() && rReq.GetArgs()->GetItemState(nSlot, TRUE, &pItem) == SFX_ITEM_SET &&
843 pItem->ISA(SfxUInt32Item) )
845 nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
848 if ( nFormat )
850 if (SOT_FORMAT_STRING == nFormat)
851 pOLV->Paste();
852 else
853 pOLV->PasteSpecial();
855 break;
858 pPostItMgr->GetActivePostIt()->ResizeIfNeccessary(aOldHeight,pPostItMgr->GetActivePostIt()->GetPostItTextHeight());
861 void SwAnnotationShell::StateClpbrd(SfxItemSet &rSet)
863 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
864 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
865 return;
866 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
868 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &rView.GetEditWin() ) );
869 bool bPastePossible = ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) || aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
870 bPastePossible = bPastePossible && (pPostItMgr->GetActivePostIt()->GetStatus()!=SwPostItHelper::DELETED);
872 SfxWhichIter aIter(rSet);
873 sal_uInt16 nWhich = aIter.FirstWhich();
875 while(nWhich)
877 switch(nWhich)
879 case SID_CUT:
881 if ( (pPostItMgr->GetActivePostIt()->GetStatus()==SwPostItHelper::DELETED) || !pOLV->HasSelection() )
882 rSet.DisableItem( nWhich );
884 case SID_COPY:
886 if( !pOLV->HasSelection() )
887 rSet.DisableItem( nWhich );
888 break;
890 case SID_PASTE:
891 case SID_PASTE_SPECIAL:
893 if( !bPastePossible )
894 rSet.DisableItem( nWhich );
895 break;
897 case SID_CLIPBOARD_FORMAT_ITEMS:
899 if ( bPastePossible )
901 SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
902 if ( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
903 aFormats.AddClipbrdFormat( SOT_FORMAT_RTF );
904 //if ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) )
905 aFormats.AddClipbrdFormat( SOT_FORMAT_STRING );
906 rSet.Put( aFormats );
908 else
909 rSet.DisableItem( nWhich );
910 break;
913 nWhich = aIter.NextWhich();
917 void SwAnnotationShell::StateStatusLine(SfxItemSet &rSet)
919 SfxWhichIter aIter( rSet );
920 USHORT nWhich = aIter.FirstWhich();
922 while( nWhich )
924 switch( nWhich )
926 case FN_STAT_SELMODE:
928 rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 0));
929 rSet.DisableItem( nWhich );
930 break;
932 case FN_STAT_TEMPLATE:
934 rSet.DisableItem( nWhich );
935 break;
938 nWhich = aIter.NextWhich();
942 void SwAnnotationShell::StateInsert(SfxItemSet &rSet)
944 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
945 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
946 return;
948 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
949 SfxWhichIter aIter(rSet);
950 sal_uInt16 nWhich = aIter.FirstWhich();
952 while(nWhich)
954 switch(nWhich)
956 case SID_HYPERLINK_GETLINK:
958 SvxHyperlinkItem aHLinkItem;
959 aHLinkItem.SetInsertMode(HLINK_FIELD);
961 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
963 if (pFieldItem)
965 const SvxFieldData* pField = pFieldItem->GetField();
967 if (pField->ISA(SvxURLField))
969 aHLinkItem.SetName(((const SvxURLField*) pField)->GetRepresentation());
970 aHLinkItem.SetURL(((const SvxURLField*) pField)->GetURL());
971 aHLinkItem.SetTargetFrame(((const SvxURLField*) pField)->GetTargetFrame());
974 else
976 String sSel(pOLV->GetSelected());
977 sSel.Erase(255);
978 sSel.EraseTrailingChars();
979 aHLinkItem.SetName(sSel);
982 sal_uInt16 nHtmlMode = ::GetHtmlMode(rView.GetDocShell());
983 aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
984 ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
986 rSet.Put(aHLinkItem);
988 break;
991 if (pPostItMgr->GetActivePostIt()->GetStatus()==SwPostItHelper::DELETED)
992 rSet.DisableItem( nWhich );
994 nWhich = aIter.NextWhich();
999 void SwAnnotationShell::NoteExec(SfxRequest &rReq)
1001 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1002 if ( !pPostItMgr )
1003 return;
1005 sal_uInt16 nSlot = rReq.GetSlot();
1006 switch (nSlot)
1008 case FN_REPLY:
1009 case FN_POSTIT:
1010 case FN_DELETE_COMMENT:
1011 case FN_DELETE_NOTE:
1012 if ( pPostItMgr->GetActivePostIt() )
1013 pPostItMgr->GetActivePostIt()->ExecuteCommand(nSlot);
1014 break;
1015 case FN_DELETE_ALL_NOTES:
1016 pPostItMgr->Delete();
1017 break;
1018 case FN_DELETE_NOTE_AUTHOR:
1020 SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, nSlot, FALSE);
1021 if ( pItem )
1022 pPostItMgr->Delete( pItem->GetValue() );
1023 break;
1025 case FN_HIDE_NOTE:
1027 if ( Mgr()->GetActivePostIt() == this )
1029 Mgr()->SetActivePostIt(0);
1030 // put the cursor back into the document
1031 SwitchToFieldPos();
1033 Mgr()->Hide(mpFld);
1035 break;
1036 case FN_HIDE_ALL_NOTES:
1037 pPostItMgr->Hide();
1038 break;
1039 case FN_HIDE_NOTE_AUTHOR:
1041 SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, nSlot, FALSE);
1042 if ( pItem )
1043 pPostItMgr->Hide( pItem->GetValue() );
1048 void SwAnnotationShell::GetNoteState(SfxItemSet &rSet)
1050 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1051 SfxWhichIter aIter(rSet);
1052 sal_uInt16 nWhich = aIter.FirstWhich();
1053 while(nWhich)
1055 USHORT nSlotId = GetPool().GetSlotId( nWhich );
1056 switch( nSlotId )
1058 case FN_POSTIT:
1059 case FN_DELETE_NOTE:
1060 case FN_DELETE_NOTE_AUTHOR:
1061 case FN_DELETE_ALL_NOTES:
1062 case FN_HIDE_NOTE:
1063 case FN_HIDE_NOTE_AUTHOR:
1064 case FN_HIDE_ALL_NOTES:
1066 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() || !pPostItMgr->GetActivePostIt()->ISA(SwPostIt))
1067 rSet.DisableItem(nWhich);
1068 break;
1070 case FN_DELETE_COMMENT:
1072 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() ) //|| !pPostItMgr->GetActivePostIt()->ISA(SwRedComment))
1073 rSet.DisableItem(nWhich);
1074 break;
1076 case FN_REPLY:
1078 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() || !pPostItMgr->GetActivePostIt()->ISA(SwPostIt))
1079 rSet.DisableItem(nWhich);
1080 else
1082 SvtUserOptions aUserOpt;
1083 String sAuthor;
1084 if( !(sAuthor = aUserOpt.GetFullName()).Len())
1085 if( !(sAuthor = aUserOpt.GetID()).Len() )
1086 sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR ));
1087 if (sAuthor == pPostItMgr->GetActivePostIt()->GetAuthor())
1088 rSet.DisableItem(nWhich);
1090 break;
1092 default:
1093 rSet.InvalidateItem( nWhich );
1094 break;
1097 if (pPostItMgr->GetActivePostIt())
1099 if ( (pPostItMgr->GetActivePostIt()->IsProtected()) &&
1100 ( (nSlotId==FN_DELETE_NOTE) || (nSlotId==FN_REPLY) ) )
1101 rSet.DisableItem( nWhich );
1103 nWhich = aIter.NextWhich();
1107 void SwAnnotationShell::ExecLingu(SfxRequest &rReq)
1109 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1110 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
1111 return;
1113 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
1114 SfxItemSet aEditAttr(pOLV->GetAttribs());
1115 sal_uInt16 nSlot = rReq.GetSlot();
1116 SwWrtShell &rSh = rView.GetWrtShell();
1117 bool bRestoreSelection = false;
1118 ESelection aOldSelection;
1120 switch (nSlot)
1122 case SID_LANGUAGE_STATUS:
1124 aOldSelection = pOLV->GetSelection();
1125 if (!pOLV->GetEditView().HasSelection())
1127 bRestoreSelection = true;
1128 pOLV->GetEditView().SelectCurrentWord();
1131 bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,rView,rSh);
1132 break;
1134 case FN_THESAURUS_DLG:
1136 pOLV->StartThesaurus();
1137 break;
1139 case SID_HANGUL_HANJA_CONVERSION:
1140 pOLV->StartTextConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, NULL,
1141 i18n::TextConversionOption::CHARACTER_BY_CHARACTER, sal_True, sal_False );
1142 break;
1144 case SID_CHINESE_CONVERSION:
1146 //open ChineseTranslationDialog
1147 Reference< XComponentContext > xContext(
1148 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1149 if(xContext.is())
1151 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1152 if(xMCF.is())
1154 Reference< ui::dialogs::XExecutableDialog > xDialog(
1155 xMCF->createInstanceWithContext(
1156 rtl::OUString::createFromAscii("com.sun.star.linguistic2.ChineseTranslationDialog")
1157 , xContext), UNO_QUERY);
1158 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1159 if( xInit.is() )
1161 // initialize dialog
1162 Reference< awt::XWindow > xDialogParentWindow(0);
1163 Sequence<Any> aSeq(1);
1164 Any* pArray = aSeq.getArray();
1165 PropertyValue aParam;
1166 aParam.Name = rtl::OUString::createFromAscii("ParentWindow");
1167 aParam.Value <<= makeAny(xDialogParentWindow);
1168 pArray[0] <<= makeAny(aParam);
1169 xInit->initialize( aSeq );
1171 //execute dialog
1172 sal_Int16 nDialogRet = xDialog->execute();
1173 if( RET_OK == nDialogRet )
1175 //get some parameters from the dialog
1176 sal_Bool bToSimplified = sal_True;
1177 sal_Bool bUseVariants = sal_True;
1178 sal_Bool bCommonTerms = sal_True;
1179 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
1180 if( xProp.is() )
1184 xProp->getPropertyValue( C2U("IsDirectionToSimplified") ) >>= bToSimplified;
1185 xProp->getPropertyValue( C2U("IsUseCharacterVariants") ) >>= bUseVariants;
1186 xProp->getPropertyValue( C2U("IsTranslateCommonTerms") ) >>= bCommonTerms;
1188 catch( Exception& )
1193 //execute translation
1194 sal_Int16 nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1195 sal_Int16 nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1196 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1197 if( !bCommonTerms )
1198 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1200 Font aTargetFont = pOLV->GetWindow()->GetDefaultFont( DEFAULTFONT_CJK_TEXT,
1201 nTargetLang, DEFAULTFONT_FLAGS_ONLYONE );
1203 pOLV->StartTextConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, sal_False, sal_False );
1206 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1207 if( xComponent.is() )
1208 xComponent->dispose();
1212 break;
1215 if (bRestoreSelection)
1217 // restore selection
1218 pOLV->GetEditView().SetSelection( aOldSelection );
1222 void SwAnnotationShell::GetLinguState(SfxItemSet &rSet)
1224 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1225 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
1226 return;
1228 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
1229 SfxItemSet aEditAttr(pOLV->GetAttribs());
1231 SfxWhichIter aIter(rSet);
1232 sal_uInt16 nWhich = aIter.FirstWhich();
1233 while(nWhich)
1235 switch (nWhich)
1237 case SID_LANGUAGE_STATUS:
1239 SwLangHelper::GetLanguageStatus(pOLV,rSet);
1240 break;
1242 // disable "Thesaurus" if the language is not supported
1243 case FN_THESAURUS_DLG:
1245 const SfxPoolItem &rItem = rView.GetWrtShell().GetDoc()->GetDefault(
1246 GetWhichOfScript( RES_CHRATR_LANGUAGE,
1247 GetI18NScriptTypeOfLanguage( (USHORT)GetAppLanguage())) );
1248 LanguageType nLang = ((const SvxLanguageItem &)
1249 rItem).GetLanguage();
1250 uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() );
1251 if (!xThes.is() || nLang == LANGUAGE_NONE ||
1252 !xThes->hasLocale( SvxCreateLocale( nLang ) ))
1253 rSet.DisableItem( FN_THESAURUS_DLG );
1255 break;
1256 case SID_HANGUL_HANJA_CONVERSION:
1257 case SID_CHINESE_CONVERSION:
1259 if (!SvtCJKOptions().IsAnyEnabled())
1261 rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_False );
1262 rSet.DisableItem(nWhich);
1264 else
1265 rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
1267 break;
1270 if (pPostItMgr->GetActivePostIt()->GetStatus()==SwPostItHelper::DELETED)
1271 rSet.DisableItem( nWhich );
1273 nWhich = aIter.NextWhich();
1277 void SwAnnotationShell::ExecTransliteration(SfxRequest &rReq)
1279 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1280 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
1281 return;
1283 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
1285 using namespace ::com::sun::star::i18n;
1287 sal_uInt32 nMode = 0;
1289 switch( rReq.GetSlot() )
1291 case SID_TRANSLITERATE_UPPER:
1292 nMode = TransliterationModules_LOWERCASE_UPPERCASE;
1293 break;
1294 case SID_TRANSLITERATE_LOWER:
1295 nMode = TransliterationModules_UPPERCASE_LOWERCASE;
1296 break;
1297 case SID_TRANSLITERATE_HALFWIDTH:
1298 nMode = TransliterationModules_FULLWIDTH_HALFWIDTH;
1299 break;
1300 case SID_TRANSLITERATE_FULLWIDTH:
1301 nMode = TransliterationModules_HALFWIDTH_FULLWIDTH;
1302 break;
1303 case SID_TRANSLITERATE_HIRAGANA:
1304 nMode = TransliterationModules_KATAKANA_HIRAGANA;
1305 break;
1306 case SID_TRANSLITERATE_KATAGANA:
1307 nMode = TransliterationModules_HIRAGANA_KATAKANA;
1308 break;
1310 default:
1311 ASSERT(!this, "falscher Dispatcher");
1314 if( nMode )
1316 pOLV->TransliterateText( nMode );
1321 void SwAnnotationShell::ExecUndo(SfxRequest &rReq)
1323 const SfxItemSet* pArgs = rReq.GetArgs();
1324 SfxUndoManager* pUndoManager = GetUndoManager();
1325 SwWrtShell &rSh = rView.GetWrtShell();
1327 long aOldHeight = rView.GetPostItMgr()->GetActivePostIt() ? rView.GetPostItMgr()->GetActivePostIt()->GetPostItTextHeight() : 0;
1329 USHORT nId = rReq.GetSlot();
1330 sal_uInt16 nCnt = 1;
1331 const SfxPoolItem* pItem=0;
1332 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nId, FALSE, &pItem ) )
1333 nCnt = ((SfxUInt16Item*)pItem)->GetValue();
1334 switch( nId )
1336 case SID_UNDO:
1338 if ( pUndoManager )
1340 sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1341 sal_uInt16 nSteps = nCnt;
1342 if ( nCount < nCnt )
1344 nCnt = nCnt - nCount;
1345 nSteps = nCount;
1347 else
1348 nCnt = 0;
1350 while( nSteps-- )
1351 pUndoManager->Undo(0);
1354 if ( nCnt )
1355 rSh.Do( SwWrtShell::UNDO, nCnt );
1357 break;
1360 case SID_REDO:
1362 if ( pUndoManager )
1364 sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1365 sal_uInt16 nSteps = nCnt;
1366 if ( nCount < nCnt )
1368 nCnt = nCnt - nCount;
1369 nSteps = nCount;
1371 else
1372 nCnt = 0;
1374 while( nSteps-- )
1375 pUndoManager->Redo(0);
1378 if ( nCnt )
1379 rSh.Do( SwWrtShell::REDO, nCnt );
1381 break;
1385 rView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
1387 if (rView.GetPostItMgr()->GetActivePostIt())
1388 rView.GetPostItMgr()->GetActivePostIt()->ResizeIfNeccessary(aOldHeight,rView.GetPostItMgr()->GetActivePostIt()->GetPostItTextHeight());
1391 void SwAnnotationShell::StateUndo(SfxItemSet &rSet)
1393 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1394 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
1395 return;
1397 SfxWhichIter aIter(rSet);
1398 USHORT nWhich = aIter.FirstWhich();
1399 SfxUndoManager* pUndoManager = GetUndoManager();
1400 SfxViewFrame *pSfxViewFrame = rView.GetViewFrame();
1401 SwWrtShell &rSh = rView.GetWrtShell();
1403 while( nWhich )
1405 switch ( nWhich )
1407 case SID_UNDO:
1409 sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1410 if ( nCount )
1411 pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1412 else if( rSh.GetUndoIds() )
1413 rSet.Put( SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::UNDO)) );
1414 else
1415 rSet.DisableItem(nWhich);
1416 break;
1418 case SID_REDO:
1420 sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1421 if ( nCount )
1422 pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1423 else if(rSh.GetRedoIds())
1424 rSet.Put(SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::REDO)) );
1425 else
1426 rSet.DisableItem(nWhich);
1427 break;
1429 case SID_GETUNDOSTRINGS:
1430 case SID_GETREDOSTRINGS:
1432 if( pUndoManager )
1434 UniString (SfxUndoManager:: *fnGetComment)( USHORT ) const;
1436 sal_uInt16 nCount;
1437 if( SID_GETUNDOSTRINGS == nWhich )
1439 nCount = pUndoManager->GetUndoActionCount();
1440 fnGetComment = &SfxUndoManager::GetUndoActionComment;
1442 else
1444 nCount = pUndoManager->GetRedoActionCount();
1445 fnGetComment = &SfxUndoManager::GetRedoActionComment;
1448 String sList;
1449 if( nCount )
1451 for( sal_uInt16 n = 0; n < nCount; ++n )
1452 ( sList += (pUndoManager->*fnGetComment)( n ) )
1453 += '\n';
1456 SfxStringListItem aItem( nWhich );
1457 if( nWhich == SID_GETUNDOSTRINGS && rSh.GetUndoIds() )
1459 rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1461 else if( nWhich == SID_GETREDOSTRINGS && rSh.GetRedoIds() )
1463 rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1466 sList += aItem.GetString();
1467 aItem.SetString( sList );
1468 rSet.Put( aItem );
1470 else
1471 rSet.DisableItem( nWhich );
1473 break;
1475 default:
1477 pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1478 break;
1483 if (pPostItMgr->GetActivePostIt()->GetStatus()==SwPostItHelper::DELETED)
1484 rSet.DisableItem( nWhich );
1486 nWhich = aIter.NextWhich();
1490 void SwAnnotationShell::StateDisableItems( SfxItemSet &rSet )
1492 SfxWhichIter aIter(rSet);
1493 USHORT nWhich = aIter.FirstWhich();
1494 while (nWhich)
1496 rSet.DisableItem( nWhich );
1497 nWhich = aIter.NextWhich();
1501 void SwAnnotationShell::InsertSymbol(SfxRequest& rReq)
1503 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1504 if ( !pPostItMgr || !pPostItMgr->GetActivePostIt() )
1505 return;
1507 OutlinerView* pOLV = pPostItMgr->GetActivePostIt()->View();
1509 const SfxItemSet *pArgs = rReq.GetArgs();
1510 const SfxPoolItem* pItem = 0;
1511 if( pArgs )
1512 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), FALSE, &pItem);
1514 String sSym;
1515 String sFontName;
1516 if ( pItem )
1518 sSym = ((const SfxStringItem*)pItem)->GetValue();
1519 const SfxPoolItem* pFtItem = NULL;
1520 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), FALSE, &pFtItem);
1521 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
1522 if ( pFontItem )
1523 sFontName = pFontItem->GetValue();
1526 SfxItemSet aSet(pOLV->GetAttribs());
1527 USHORT nScript = pOLV->GetSelectedScriptType();
1528 SvxFontItem aSetDlgFont( RES_CHRATR_FONT );
1530 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1531 aSetItem.GetItemSet().Put( aSet, FALSE );
1532 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1533 if( pI )
1534 aSetDlgFont = *(SvxFontItem*)pI;
1535 else
1536 aSetDlgFont = (SvxFontItem&)aSet.Get( GetWhichOfScript(
1537 SID_ATTR_CHAR_FONT,
1538 GetI18NScriptTypeOfLanguage( (USHORT)GetAppLanguage() ) ));
1539 if (!sFontName.Len())
1540 sFontName = aSetDlgFont.GetFamilyName();
1543 Font aFont(sFontName, Size(1,1));
1544 if( !sSym.Len() )
1546 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1548 SfxAllItemSet aAllSet( GetPool() );
1549 aAllSet.Put( SfxBoolItem( FN_PARAM_1, FALSE ) );
1551 SwViewOption aOpt(*rView.GetWrtShell().GetViewOptions());
1552 String sSymbolFont = aOpt.GetSymbolFont();
1553 if( sSymbolFont.Len() )
1554 aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
1555 else
1556 aAllSet.Put( SfxStringItem( SID_FONT_NAME, aSetDlgFont.GetFamilyName() ) );
1558 // Wenn Zeichen selektiert ist kann es angezeigt werden
1559 SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( rView.GetWindow(), aAllSet,
1560 rView.GetViewFrame()->GetFrame()->GetFrameInterface(), RID_SVXDLG_CHARMAP );
1562 USHORT nResult = pDlg->Execute();
1563 if( nResult == RET_OK )
1565 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, FALSE );
1566 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, FALSE );
1567 if ( pFontItem )
1569 aFont.SetName( pFontItem->GetFamilyName() );
1570 aFont.SetStyleName( pFontItem->GetStyleName() );
1571 aFont.SetCharSet( pFontItem->GetCharSet() );
1572 aFont.SetPitch( pFontItem->GetPitch() );
1575 if ( pCItem )
1577 sSym = pCItem->GetValue();
1578 aOpt.SetSymbolFont(aFont.GetName());
1579 SW_MOD()->ApplyUsrPref(aOpt, &rView);
1583 delete( pDlg );
1586 if( sSym.Len() )
1588 // nicht flackern
1589 pOLV->HideCursor();
1590 Outliner * pOutliner = pOLV->GetOutliner();
1591 pOutliner->SetUpdateMode(FALSE);
1593 SfxItemSet aOldSet( pOLV->GetAttribs() );
1594 SfxItemSet aFontSet( *aOldSet.GetPool(),
1595 EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
1596 EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CJK,
1597 EE_CHAR_FONTINFO_CTL, EE_CHAR_FONTINFO_CTL,
1598 0 );
1599 aFontSet.Set( aOldSet );
1601 // String einfuegen
1602 pOLV->InsertText( sSym);
1604 // attributieren (Font setzen)
1605 SfxItemSet aSetFont( *aFontSet.GetPool(), aFontSet.GetRanges() );
1606 SvxFontItem aFontItem (aFont.GetFamily(), aFont.GetName(),
1607 aFont.GetStyleName(), aFont.GetPitch(),
1608 aFont.GetCharSet(),
1609 EE_CHAR_FONTINFO );
1610 USHORT nScriptBreak = pBreakIt->GetAllScriptsOfText( sSym );
1611 if( SCRIPTTYPE_LATIN & nScriptBreak )
1612 aSetFont.Put( aFontItem, EE_CHAR_FONTINFO );
1613 if( SCRIPTTYPE_ASIAN & nScriptBreak )
1614 aSetFont.Put( aFontItem, EE_CHAR_FONTINFO_CJK );
1615 if( SCRIPTTYPE_COMPLEX & nScriptBreak )
1616 aSetFont.Put( aFontItem, EE_CHAR_FONTINFO_CTL );
1617 pOLV->SetAttribs(aSetFont);
1619 // Selektion loeschen
1620 ESelection aSel(pOLV->GetSelection());
1621 aSel.nStartPara = aSel.nEndPara;
1622 aSel.nStartPos = aSel.nEndPos;
1623 pOLV->SetSelection(aSel);
1625 // Alten Font restaurieren
1626 pOLV->SetAttribs( aFontSet );
1628 // ab jetzt wieder anzeigen
1629 pOutliner->SetUpdateMode(TRUE);
1630 pOLV->ShowCursor();
1632 rReq.AppendItem( SfxStringItem( GetPool().GetWhich(SID_CHARMAP), sSym ) );
1633 if(aFont.GetName().Len())
1634 rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aFont.GetName() ) );
1635 rReq.Done();