bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / shells / annotsh.cxx
blobe5ccd066fba01157273e007534c88323206b8d03
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <hintids.hxx>
23 #include <com/sun/star/i18n/TransliterationModules.hpp>
24 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
25 #include <com/sun/star/i18n/TextConversionOption.hpp>
26 #include <com/sun/star/ui/dialogs/XSLTFilterDialog.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
29 #include <tools/shl.hxx>
30 #include <i18nlangtag/mslangid.hxx>
31 #include <sfx2/objface.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/request.hxx>
36 #include <editeng/spltitem.hxx>
37 #include <editeng/lrspitem.hxx>
38 #include <editeng/ulspitem.hxx>
39 #include <editeng/orphitem.hxx>
40 #include <editeng/formatbreakitem.hxx>
41 #include <editeng/widwitem.hxx>
42 #include <editeng/kernitem.hxx>
43 #include <editeng/escapementitem.hxx>
44 #include <editeng/lspcitem.hxx>
45 #include <editeng/adjustitem.hxx>
46 #include <editeng/crossedoutitem.hxx>
47 #include <editeng/shdditem.hxx>
48 #include <editeng/hyphenzoneitem.hxx>
49 #include <editeng/udlnitem.hxx>
50 #include <editeng/fontitem.hxx>
51 #include <editeng/fhgtitem.hxx>
52 #include <svx/clipfmtitem.hxx>
53 #include <svl/stritem.hxx>
54 #include <svl/slstitm.hxx>
55 #include <editeng/colritem.hxx>
56 #include <editeng/wghtitem.hxx>
57 #include <editeng/contouritem.hxx>
58 #include <editeng/postitem.hxx>
59 #include <editeng/frmdiritem.hxx>
60 #include <svx/svdoutl.hxx>
61 #include <svl/whiter.hxx>
62 #include <svl/cjkoptions.hxx>
63 #include <svl/ctloptions.hxx>
64 #include <unotools/useroptions.hxx>
65 #include <vcl/msgbox.hxx>
66 #include <editeng/flditem.hxx>
67 #include <editeng/editstat.hxx>
68 #include <svx/hlnkitem.hxx>
69 #include <sfx2/htmlmode.hxx>
70 #include <editeng/langitem.hxx>
71 #include <editeng/unolingu.hxx>
72 #include <editeng/scripttypeitem.hxx>
73 #include <editeng/writingmodeitem.hxx>
74 #include <swundo.hxx>
75 #include <doc.hxx>
76 #include <viewopt.hxx>
77 #include <wrtsh.hxx>
78 #include <uitool.hxx>
79 #include <popup.hrc>
80 #include <pardlg.hxx>
81 #include <swdtflvr.hxx>
82 #include <drwtxtsh.hxx>
83 #include <swmodule.hxx>
84 #include <initui.hxx>
85 #include <edtwin.hxx>
86 #include <swwait.hxx>
87 #include <docstat.hxx>
89 #include <cmdid.h>
90 #include <globals.hrc>
91 #include <shells.hrc>
92 #include <breakit.hxx>
93 #include "annotsh.hxx"
94 #include "view.hxx"
95 #include <PostItMgr.hxx>
96 #include <SidebarWin.hxx>
98 #include "swtypes.hxx"
100 #include <svx/svxdlg.hxx>
101 #include <svx/dialogs.hrc>
103 #include <svx/svxids.hrc>
104 #include <sfx2/sidebar/EnumContext.hxx>
105 #include <svl/itempool.hxx>
106 #include <editeng/outliner.hxx>
107 #include <editeng/editeng.hxx>
108 #include <editeng/editview.hxx>
110 #include <svl/languageoptions.hxx>
111 #include <svtools/langtab.hxx>
113 #include <docsh.hxx>
114 #include <svl/undo.hxx>
115 #include "swabstdlg.hxx"
116 #include "chrdlg.hrc"
117 #include "misc.hrc"
118 #include <app.hrc>
120 #include <comphelper/processfactory.hxx>
121 #include <comphelper/string.hxx>
122 #include <cppuhelper/bootstrap.hxx>
124 #include <langhelper.hxx>
126 #include <wordcountdialog.hxx>
127 #include <tools/diagnose_ex.h>
129 using namespace ::com::sun::star;
130 using namespace ::com::sun::star::uno;
131 using namespace ::com::sun::star::beans;
132 using namespace ::com::sun::star::i18n;
134 #define SwAnnotationShell
136 #include <sfx2/msg.hxx>
137 #include <swslots.hxx>
139 SFX_IMPL_INTERFACE(SwAnnotationShell, SfxShell, SW_RES(STR_SHELLNAME_DRAW_TEXT))
141 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TEXT_TOOLBOX));
142 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_ANNOTATION_POPUPMENU));
145 TYPEINIT1(SwAnnotationShell,SfxShell)
147 SwAnnotationShell::SwAnnotationShell( SwView& r )
148 : rView(r)
150 SwWrtShell &rSh = rView.GetWrtShell();
151 SetPool(rSh.GetAttrPool().GetSecondaryPool());
152 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Annotation));
155 SwAnnotationShell::~SwAnnotationShell()
159 ::svl::IUndoManager* SwAnnotationShell::GetUndoManager()
161 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
162 if ( !pPostItMgr ||
163 !pPostItMgr->HasActiveSidebarWin() )
165 OSL_ENSURE(pPostItMgr,"PostItMgr::Layout(): We are looping forever");
166 return 0;
168 return &pPostItMgr->GetActiveSidebarWin()->GetOutlinerView()->GetOutliner()->GetUndoManager();
171 void SwAnnotationShell::Exec( SfxRequest &rReq )
173 //TODO: clean this up!!!!
174 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
175 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
176 return;
178 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
179 SfxItemSet aEditAttr(pOLV->GetAttribs());
180 SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
182 sal_uInt16 nSlot = rReq.GetSlot();
183 sal_uInt16 nWhich = GetPool().GetWhich(nSlot);
184 const SfxItemSet *pNewAttrs = rReq.GetArgs();
185 sal_uInt16 nEEWhich = 0;
186 switch (nSlot)
188 case SID_ATTR_PARA_LRSPACE:
190 SvxLRSpaceItem aParaMargin((const SvxLRSpaceItem&)rReq.
191 GetArgs()->Get(nSlot));
192 aParaMargin.SetWhich( EE_PARA_LRSPACE );
194 aNewAttr.Put(aParaMargin);
195 rReq.Done();
196 break;
198 case SID_ATTR_PARA_LINESPACE:
200 SvxLineSpacingItem aParaMargin = (const SvxLineSpacingItem&)pNewAttrs->Get(
201 GetPool().GetWhich(nSlot));
202 aParaMargin.SetWhich( EE_PARA_SBL );
204 aNewAttr.Put(aParaMargin);
205 rReq.Done();
206 break;
208 case SID_ATTR_PARA_ULSPACE:
210 SvxULSpaceItem aULSpace = (const SvxULSpaceItem&)pNewAttrs->Get(
211 GetPool().GetWhich(nSlot));
212 aULSpace.SetWhich( EE_PARA_ULSPACE );
213 aNewAttr.Put( aULSpace );
214 rReq.Done();
216 break;
217 case SID_ATTR_CHAR_FONT:
218 case SID_ATTR_CHAR_FONTHEIGHT:
219 case SID_ATTR_CHAR_WEIGHT:
220 case SID_ATTR_CHAR_POSTURE:
222 SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
223 if( !pSecondPool )
224 pSecondPool = aEditAttr.GetPool();
225 SvxScriptSetItem aSetItem( nSlot, *pSecondPool );
226 aSetItem.PutItemForScriptType( pOLV->GetSelectedScriptType(), pNewAttrs->Get( nWhich ));
227 aNewAttr.Put( aSetItem.GetItemSet() );
228 rReq.Done();
229 break;
231 case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
232 case SID_ATTR_CHAR_UNDERLINE:
234 if( rReq.GetArgs() )
236 SFX_REQUEST_ARG( rReq, pItem, SvxUnderlineItem, SID_ATTR_CHAR_UNDERLINE , sal_False );
237 if (pItem)
239 aNewAttr.Put(*pItem);
241 else
243 FontUnderline eFU = ( (const SvxUnderlineItem&) aEditAttr.Get( EE_CHAR_UNDERLINE ) ).GetLineStyle();
244 aNewAttr.Put( SvxUnderlineItem( eFU != UNDERLINE_NONE ?UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_UNDERLINE ) );
247 break;
249 case SID_ATTR_CHAR_OVERLINE:
251 FontUnderline eFO = ((const SvxOverlineItem&)aEditAttr.Get(EE_CHAR_OVERLINE)).GetLineStyle();
252 aNewAttr.Put(SvxOverlineItem(eFO == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_OVERLINE));
253 break;
255 case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
256 case SID_ATTR_CHAR_SHADOWED: nEEWhich = EE_CHAR_SHADOW; break;
257 case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT; break;
258 case SID_ATTR_CHAR_WORDLINEMODE: nEEWhich = EE_CHAR_WLM; break;
259 case SID_ATTR_CHAR_RELIEF : nEEWhich = EE_CHAR_RELIEF; break;
260 case SID_ATTR_CHAR_LANGUAGE : nEEWhich = EE_CHAR_LANGUAGE;break;
261 case SID_ATTR_CHAR_KERNING : nEEWhich = EE_CHAR_KERNING; break;
262 case SID_ATTR_CHAR_SCALEWIDTH: nEEWhich = EE_CHAR_FONTWIDTH; break;
263 case SID_ATTR_CHAR_AUTOKERN : nEEWhich = EE_CHAR_PAIRKERNING; break;
264 case SID_ATTR_CHAR_ESCAPEMENT: nEEWhich = EE_CHAR_ESCAPEMENT; break;
265 case SID_ATTR_PARA_ADJUST_LEFT:
266 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_LEFT, EE_PARA_JUST));
267 break;
268 case SID_ATTR_PARA_ADJUST_CENTER:
269 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_CENTER, EE_PARA_JUST));
270 break;
271 case SID_ATTR_PARA_ADJUST_RIGHT:
272 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_RIGHT, EE_PARA_JUST));
273 break;
274 case SID_ATTR_PARA_ADJUST_BLOCK:
275 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_BLOCK, EE_PARA_JUST));
276 break;
278 case SID_ATTR_PARA_LINESPACE_10:
280 SvxLineSpacingItem aItem(SVX_LINESPACE_ONE_LINE, EE_PARA_SBL);
281 aItem.SetPropLineSpace(100);
282 aNewAttr.Put(aItem);
284 break;
285 case SID_ATTR_PARA_LINESPACE_15:
287 SvxLineSpacingItem aItem(SVX_LINESPACE_ONE_POINT_FIVE_LINES, EE_PARA_SBL);
288 aItem.SetPropLineSpace(150);
289 aNewAttr.Put(aItem);
291 break;
292 case SID_ATTR_PARA_LINESPACE_20:
294 SvxLineSpacingItem aItem(SVX_LINESPACE_TWO_LINES, EE_PARA_SBL);
295 aItem.SetPropLineSpace(200);
296 aNewAttr.Put(aItem);
298 break;
299 case SID_SELECTALL:
301 Outliner * pOutliner = pOLV->GetOutliner();
302 if(pOutliner)
304 sal_Int32 nParaCount = pOutliner->GetParagraphCount();
305 if (nParaCount > 0)
306 pOLV->SelectRange(0L, nParaCount );
308 break;
310 case FN_FORMAT_RESET:
312 pPostItMgr->GetActiveSidebarWin()->ResetAttributes();
313 rReq.Done();
314 break;
316 case FN_SET_SUPER_SCRIPT:
318 SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
319 SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&)
320 aEditAttr.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
322 if( eEsc == SVX_ESCAPEMENT_SUPERSCRIPT )
323 aItem.SetEscapement( SVX_ESCAPEMENT_OFF );
324 else
325 aItem.SetEscapement( SVX_ESCAPEMENT_SUPERSCRIPT );
326 aNewAttr.Put( aItem, EE_CHAR_ESCAPEMENT );
328 break;
329 case FN_SET_SUB_SCRIPT:
331 SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
332 SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&)
333 aEditAttr.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
335 if( eEsc == SVX_ESCAPEMENT_SUBSCRIPT )
336 aItem.SetEscapement( SVX_ESCAPEMENT_OFF );
337 else
338 aItem.SetEscapement( SVX_ESCAPEMENT_SUBSCRIPT );
339 aNewAttr.Put( aItem, EE_CHAR_ESCAPEMENT );
341 break;
342 case SID_HYPERLINK_SETLINK:
344 const SfxPoolItem* pItem = 0;
345 if(pNewAttrs)
346 pNewAttrs->GetItemState(nSlot, sal_False, &pItem);
348 if(pItem)
350 const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
351 SvxURLField aFld(rHLinkItem.GetURL(), rHLinkItem.GetName(), SVXURLFORMAT_APPDEFAULT);
352 aFld.SetTargetFrame(rHLinkItem.GetTargetFrame());
354 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
356 if (pFieldItem && pFieldItem->GetField()->ISA(SvxURLField))
358 // Select the field so that it will be deleted during insert
359 ESelection aSel = pOLV->GetSelection();
360 aSel.nEndPos++;
361 pOLV->SetSelection(aSel);
363 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
364 pOLV->InsertField(SvxFieldItem(aFld, EE_FEATURE_FIELD));
366 break;
368 case FN_INSERT_SOFT_HYPHEN:
369 case FN_INSERT_HARDHYPHEN:
370 case FN_INSERT_HARD_SPACE:
371 case SID_INSERT_RLM :
372 case SID_INSERT_LRM :
373 case SID_INSERT_ZWNBSP :
374 case SID_INSERT_ZWSP:
376 sal_Unicode cIns = 0;
377 switch(rReq.GetSlot())
379 case FN_INSERT_SOFT_HYPHEN: cIns = CHAR_SOFTHYPHEN; break;
380 case FN_INSERT_HARDHYPHEN: cIns = CHAR_HARDHYPHEN; break;
381 case FN_INSERT_HARD_SPACE: cIns = CHAR_HARDBLANK; break;
382 case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
383 case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
384 case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
385 case SID_INSERT_ZWNBSP: cIns = CHAR_ZWNBSP; break;
387 pOLV->InsertText( OUString(cIns));
388 rReq.Done();
389 break;
391 case SID_CHARMAP:
393 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
394 InsertSymbol(rReq);
395 break;
397 case FN_INSERT_STRING:
399 const SfxPoolItem* pItem = 0;
400 if(pNewAttrs)
401 pNewAttrs->GetItemState(nSlot, sal_False, &pItem );
402 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
403 pOLV->InsertText(((const SfxStringItem *)pItem)->GetValue());
404 break;
407 case FN_FORMAT_FOOTNOTE_DLG:
409 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
410 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
412 VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( rView.GetWindow(), rView.GetWrtShell(), DLG_DOC_FOOTNOTE );
413 OSL_ENSURE(pDlg, "Dialogdiet fail!");
414 pDlg->Execute();
415 delete pDlg;
416 break;
418 case FN_NUMBERING_OUTLINE_DLG:
420 SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
421 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
422 OSL_ENSURE(pFact, "Dialogdiet fail!");
423 SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
424 rView.GetWindow(), &aTmp, rView.GetWrtShell());
425 OSL_ENSURE(pDlg, "Dialogdiet fail!");
426 pDlg->Execute();
427 delete pDlg;
428 rReq.Done();
430 break;
431 case SID_OPEN_XML_FILTERSETTINGS:
435 uno::Reference < ui::dialogs::XExecutableDialog > xDialog = ui::dialogs::XSLTFilterDialog::create( ::comphelper::getProcessComponentContext() );
436 xDialog->execute();
438 catch (const uno::Exception&)
440 DBG_UNHANDLED_EXCEPTION();
442 rReq.Ignore ();
444 break;
445 case FN_WORDCOUNT_DIALOG:
447 SfxViewFrame* pVFrame = rView.GetViewFrame();
448 if (pVFrame != NULL)
450 pVFrame->ToggleChildWindow(FN_WORDCOUNT_DIALOG);
451 Invalidate(rReq.GetSlot());
453 SwWordCountWrapper *pWrdCnt = (SwWordCountWrapper*)pVFrame->GetChildWindow(SwWordCountWrapper::GetChildWindowId());
454 if (pWrdCnt)
455 pWrdCnt->UpdateCounts();
458 break;
459 case SID_CHAR_DLG_EFFECT:
460 case SID_CHAR_DLG:
462 const SfxItemSet* pArgs = rReq.GetArgs();
464 if( !pArgs )
466 /* mod
467 SwView* pView = &GetView();
468 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
469 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
471 SfxItemSet aDlgAttr(GetPool(), EE_ITEMS_START, EE_ITEMS_END);
473 // util::Language does not exist in the EditEngine! Therefore not included in the set.
475 aDlgAttr.Put( aEditAttr );
476 aDlgAttr.Put( SvxKerningItem(0, RES_CHRATR_KERNING) );
478 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
479 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
481 SfxAbstractTabDialog* pDlg = pFact->CreateSwCharDlg( rView.GetWindow(), rView, aDlgAttr, 0, sal_True );
482 OSL_ENSURE(pDlg, "Dialogdiet fail!");
483 if (nSlot == SID_CHAR_DLG_EFFECT)
485 pDlg->SetCurPageId(TP_CHAR_EXT);
487 sal_uInt16 nRet = pDlg->Execute();
488 if(RET_OK == nRet )
490 rReq.Done( *( pDlg->GetOutputItemSet() ) );
491 aNewAttr.Put(*pDlg->GetOutputItemSet());
493 delete( pDlg );
494 if(RET_OK != nRet)
495 return ;
497 else
498 aNewAttr.Put(*pArgs);
499 break;
501 case SID_PARA_DLG:
503 const SfxItemSet* pArgs = rReq.GetArgs();
505 if (!pArgs)
507 /* mod todo ???
508 SwView* pView = &GetView();
509 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
510 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
512 SfxItemSet aDlgAttr(GetPool(),
513 EE_ITEMS_START, EE_ITEMS_END,
514 SID_ATTR_PARA_HYPHENZONE, SID_ATTR_PARA_HYPHENZONE,
515 SID_ATTR_PARA_SPLIT, SID_ATTR_PARA_SPLIT,
516 SID_ATTR_PARA_WIDOWS, SID_ATTR_PARA_WIDOWS,
517 SID_ATTR_PARA_ORPHANS, SID_ATTR_PARA_ORPHANS,
520 aDlgAttr.Put(aEditAttr);
523 aDlgAttr.Put( SvxHyphenZoneItem( sal_False, RES_PARATR_HYPHENZONE) );
524 aDlgAttr.Put( SvxFmtBreakItem( SVX_BREAK_NONE, RES_BREAK ) );
525 aDlgAttr.Put( SvxFmtSplitItem( sal_True, RES_PARATR_SPLIT ) );
526 aDlgAttr.Put( SvxWidowsItem( 0, RES_PARATR_WIDOWS ) );
527 aDlgAttr.Put( SvxOrphansItem( 0, RES_PARATR_ORPHANS ) );
530 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
531 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
533 SfxAbstractTabDialog* pDlg = pFact->CreateSwParaDlg( rView.GetWindow(), rView, aDlgAttr,DLG_STD, DLG_PARA, 0, sal_True );
534 OSL_ENSURE(pDlg, "Dialogdiet fail!");
535 sal_uInt16 nRet = pDlg->Execute();
536 if(RET_OK == nRet)
538 rReq.Done( *( pDlg->GetOutputItemSet() ) );
539 aNewAttr.Put(*pDlg->GetOutputItemSet());
541 delete( pDlg );
542 if(RET_OK != nRet)
543 return;
545 else
546 aNewAttr.Put(*pArgs);
547 break;
550 case SID_AUTOSPELL_CHECK:
552 rView.ExecuteSlot(rReq);
553 break;
555 case SID_ATTR_PARA_LEFT_TO_RIGHT:
556 case SID_ATTR_PARA_RIGHT_TO_LEFT:
558 bool bLeftToRight = nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT;
560 const SfxPoolItem* pPoolItem;
561 if( pNewAttrs && SFX_ITEM_SET == pNewAttrs->GetItemState( nSlot, sal_True, &pPoolItem ) )
563 if( !( (SfxBoolItem*)pPoolItem)->GetValue() )
564 bLeftToRight = !bLeftToRight;
566 SfxItemSet aAttr( *aNewAttr.GetPool(),
567 EE_PARA_JUST, EE_PARA_JUST,
568 EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
569 0 );
571 sal_uInt16 nAdjust = SVX_ADJUST_LEFT;
572 if( SFX_ITEM_ON == aEditAttr.GetItemState(EE_PARA_JUST, sal_True, &pPoolItem ) )
573 nAdjust = ( (SvxAdjustItem*)pPoolItem)->GetEnumValue();
575 if( bLeftToRight )
577 aAttr.Put( SvxFrameDirectionItem( FRMDIR_HORI_LEFT_TOP, EE_PARA_WRITINGDIR ) );
578 if( nAdjust == SVX_ADJUST_RIGHT )
579 aAttr.Put( SvxAdjustItem( SVX_ADJUST_LEFT, EE_PARA_JUST ) );
581 else
583 aAttr.Put( SvxFrameDirectionItem( FRMDIR_HORI_RIGHT_TOP, EE_PARA_WRITINGDIR ) );
584 if( nAdjust == SVX_ADJUST_LEFT )
585 aAttr.Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
587 pOLV->SetAttribs(aAttr);
588 break;
592 if(nEEWhich && pNewAttrs)
593 aNewAttr.Put(pNewAttrs->Get(nWhich), nEEWhich);
595 Rectangle aNullRect;
596 Rectangle aOutRect = pOLV->GetOutputArea();
597 if (aNullRect != aOutRect)
598 pOLV->SetAttribs(aNewAttr);
600 rView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
601 if ( pOLV->GetOutliner()->IsModified() )
602 rView.GetWrtShell().SetModified();
606 void SwAnnotationShell::GetState(SfxItemSet& rSet)
608 //TODO: clean this up!!!
609 // FN_SET_SUPER_SCRIPT
610 //SID_ATTR_PARA_ADJUST
611 //SID_ATTR_PARA_ADJUST_BLOCK
613 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
614 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
615 return;
617 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
618 SfxItemSet aEditAttr(pOLV->GetAttribs());
620 SfxWhichIter aIter(rSet);
621 sal_uInt16 nWhich = aIter.FirstWhich();
622 while(nWhich)
624 sal_uInt16 nEEWhich = 0;
625 sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
626 switch( nSlotId )
628 case SID_ATTR_PARA_LRSPACE:
630 SfxItemState eState = aEditAttr.GetItemState( EE_PARA_LRSPACE );
631 if( eState >= SFX_ITEM_DEFAULT )
633 SvxLRSpaceItem aLR = ( (const SvxLRSpaceItem&) aEditAttr.Get( EE_PARA_LRSPACE ) );
634 aLR.SetWhich(SID_ATTR_PARA_LRSPACE);
635 rSet.Put(aLR);
637 else
638 rSet.InvalidateItem(nSlotId);
640 break;
641 case SID_ATTR_PARA_LINESPACE:
643 SfxItemState eState = aEditAttr.GetItemState( EE_PARA_SBL );
644 if( eState >= SFX_ITEM_DEFAULT )
646 SvxLineSpacingItem aLR = ( (const SvxLineSpacingItem&) aEditAttr.Get( EE_PARA_SBL ) );
647 rSet.Put(aLR);
649 else
650 rSet.InvalidateItem(nSlotId);
652 break;
653 case SID_ATTR_PARA_ULSPACE:
655 SfxItemState eState = aEditAttr.GetItemState( EE_PARA_ULSPACE );
656 if( eState >= SFX_ITEM_DEFAULT )
658 SvxULSpaceItem aULSpace = (const SvxULSpaceItem&) aEditAttr.Get( EE_PARA_ULSPACE );
659 aULSpace.SetWhich(SID_ATTR_PARA_ULSPACE);
660 rSet.Put(aULSpace);
662 else
663 rSet.InvalidateItem(nSlotId);
665 break;
666 case SID_ATTR_CHAR_FONT:
667 case SID_ATTR_CHAR_FONTHEIGHT:
668 case SID_ATTR_CHAR_WEIGHT:
669 case SID_ATTR_CHAR_POSTURE:
671 if ( pOLV )
673 sal_uInt16 nScriptType = pOLV->GetSelectedScriptType();
674 SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
675 if( !pSecondPool )
676 pSecondPool = aEditAttr.GetPool();
677 SvxScriptSetItem aSetItem( nSlotId, *pSecondPool );
678 aSetItem.GetItemSet().Put( aEditAttr, sal_False );
679 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
680 if( pI )
681 rSet.Put( *pI, nWhich );
682 else
683 rSet.InvalidateItem( nWhich );
685 else
686 rSet.InvalidateItem( nWhich );
688 break;
689 case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
690 case SID_ATTR_CHAR_UNDERLINE: nEEWhich = EE_CHAR_UNDERLINE;break;
691 case SID_ATTR_CHAR_OVERLINE: nEEWhich = EE_CHAR_OVERLINE;break;
692 case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
693 case SID_ATTR_CHAR_SHADOWED: nEEWhich = EE_CHAR_SHADOW;break;
694 case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT;break;
695 case SID_ATTR_CHAR_LANGUAGE : nEEWhich = EE_CHAR_LANGUAGE;break;
696 case SID_ATTR_CHAR_ESCAPEMENT: nEEWhich = EE_CHAR_ESCAPEMENT;break;
697 case SID_ATTR_CHAR_KERNING: nEEWhich = EE_CHAR_KERNING;break;
698 case FN_SET_SUPER_SCRIPT:
699 case FN_SET_SUB_SCRIPT:
701 sal_uInt16 nEsc = 0;
702 const SfxPoolItem *pEscItem = 0;
703 if (nWhich==FN_SET_SUPER_SCRIPT)
704 nEsc = SVX_ESCAPEMENT_SUPERSCRIPT;
705 else
706 nEsc = SVX_ESCAPEMENT_SUBSCRIPT;
708 if( !pEscItem )
709 pEscItem = &aEditAttr.Get( EE_CHAR_ESCAPEMENT );
711 if( nEsc == ((const SvxEscapementItem*)pEscItem)->GetEnumValue() )
712 rSet.Put( SfxBoolItem( nWhich, sal_True ));
713 else
714 rSet.InvalidateItem( nWhich );
715 break;
717 case SID_ATTR_PARA_ADJUST_LEFT:
718 case SID_ATTR_PARA_ADJUST_RIGHT:
719 case SID_ATTR_PARA_ADJUST_CENTER:
720 case SID_ATTR_PARA_ADJUST_BLOCK:
722 const SfxPoolItem *pAdjust = 0;
723 int eAdjust = 0;
725 if (nWhich==SID_ATTR_PARA_ADJUST_LEFT)
726 eAdjust = SVX_ADJUST_LEFT;
727 else if (nWhich==SID_ATTR_PARA_ADJUST_RIGHT)
728 eAdjust = SVX_ADJUST_RIGHT;
729 else if (nWhich==SID_ATTR_PARA_ADJUST_CENTER)
730 eAdjust = SVX_ADJUST_CENTER;
731 else if (nWhich==SID_ATTR_PARA_ADJUST_BLOCK)
732 eAdjust = SVX_ADJUST_BLOCK;
734 if( !pAdjust )
735 aEditAttr.GetItemState( EE_PARA_JUST, sal_False, &pAdjust);
737 if( !pAdjust || IsInvalidItem( pAdjust ))
738 rSet.InvalidateItem( nSlotId ), nSlotId = 0;
739 else
741 if ( eAdjust == ((const SvxAdjustItem*)pAdjust)->GetAdjust())
742 rSet.Put( SfxBoolItem( nWhich, sal_True ));
743 else
744 rSet.InvalidateItem( nWhich );
746 break;
748 case SID_ATTR_PARA_LINESPACE_10:
749 case SID_ATTR_PARA_LINESPACE_15:
750 case SID_ATTR_PARA_LINESPACE_20:
752 const SfxPoolItem *pLSpace = 0;
753 int nLSpace = 0;
755 if (nWhich==SID_ATTR_PARA_LINESPACE_10)
756 nLSpace = 100;
757 else if (nWhich==SID_ATTR_PARA_LINESPACE_15)
758 nLSpace = 150;
759 else if (nWhich==SID_ATTR_PARA_LINESPACE_20)
760 nLSpace = 200;
762 if( !pLSpace )
763 aEditAttr.GetItemState( EE_PARA_SBL, sal_False, &pLSpace );
765 if( !pLSpace || IsInvalidItem( pLSpace ))
766 rSet.InvalidateItem( nSlotId ), nSlotId = 0;
767 else
769 if( nLSpace == ((const SvxLineSpacingItem*)pLSpace)->GetPropLineSpace() )
770 rSet.Put( SfxBoolItem( nWhich, sal_True ));
771 else
772 rSet.InvalidateItem( nWhich );
774 break;
776 case SID_AUTOSPELL_CHECK:
778 const SfxPoolItem* pState = rView.GetSlotState(nWhich);
779 if (pState)
780 rSet.Put(SfxBoolItem(nWhich, ((const SfxBoolItem*)pState)->GetValue()));
781 else
782 rSet.DisableItem( nWhich );
783 break;
785 case SID_ATTR_PARA_LEFT_TO_RIGHT:
786 case SID_ATTR_PARA_RIGHT_TO_LEFT:
788 if ( !SvtLanguageOptions().IsCTLFontEnabled() )
789 rSet.DisableItem( nWhich );
790 else
792 if(pOLV->GetOutliner() && pOLV->GetOutliner()->IsVertical())
793 rSet.DisableItem( nWhich );
794 else
796 sal_Bool bFlag = sal_False;
797 switch( ( ( (SvxFrameDirectionItem&) aEditAttr.Get( EE_PARA_WRITINGDIR ) ) ).GetValue() )
799 case FRMDIR_HORI_LEFT_TOP:
801 bFlag = nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT;
802 rSet.Put( SfxBoolItem( nWhich, bFlag ));
803 break;
805 case FRMDIR_HORI_RIGHT_TOP:
807 bFlag = nWhich != SID_ATTR_PARA_LEFT_TO_RIGHT;
808 rSet.Put( SfxBoolItem( nWhich, bFlag ));
809 break;
815 break;
816 case SID_INSERT_RLM :
817 case SID_INSERT_LRM :
818 case SID_INSERT_ZWNBSP :
819 case SID_INSERT_ZWSP:
821 SvtCTLOptions aCTLOptions;
822 sal_Bool bEnabled = aCTLOptions.IsCTLFontEnabled();
823 rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, bEnabled );
824 if(!bEnabled)
825 rSet.DisableItem(nWhich);
827 break;
828 default:
829 rSet.InvalidateItem( nWhich );
830 break;
833 if(nEEWhich)
835 rSet.Put(aEditAttr.Get(nEEWhich, sal_True), nWhich);
836 if(nEEWhich == EE_CHAR_KERNING)
838 SfxItemState eState = aEditAttr.GetItemState( EE_CHAR_KERNING, sal_True );
839 if ( eState == SFX_ITEM_DONTCARE )
841 rSet.InvalidateItem(EE_CHAR_KERNING);
846 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
847 rSet.DisableItem( nWhich );
849 nWhich = aIter.NextWhich();
853 void SwAnnotationShell::ExecSearch(SfxRequest& rReq, sal_Bool bNoMessage)
855 rView.ExecSearch(rReq,bNoMessage);
858 void SwAnnotationShell::StateSearch(SfxItemSet &rSet)
860 rView.StateSearch(rSet);
863 void SwAnnotationShell::ExecClpbrd(SfxRequest &rReq)
865 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
866 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
867 return;
869 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
870 SfxItemSet aEditAttr(pOLV->GetAttribs());
871 SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
873 long aOldHeight = pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight();
874 sal_uInt16 nSlot = rReq.GetSlot();
875 switch (nSlot)
877 case SID_CUT:
878 if ( (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED) && pOLV->HasSelection() )
879 pOLV->Cut();
880 break;
881 case SID_COPY:
882 if( pOLV->HasSelection() )
883 pOLV->Copy();
884 break;
885 case SID_PASTE:
886 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
887 pOLV->Paste();
888 break;
889 case SID_PASTE_SPECIAL:
891 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
893 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
894 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( &rView.GetEditWin() );
896 pDlg->Insert( SOT_FORMAT_STRING, aEmptyStr );
897 pDlg->Insert( SOT_FORMAT_RTF, aEmptyStr );
899 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &rView.GetEditWin() ) );
901 sal_uLong nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
903 if (nFormat > 0)
905 if (nFormat == SOT_FORMAT_STRING)
906 pOLV->Paste();
907 else
908 pOLV->PasteSpecial();
910 delete pDlg;
912 break;
914 case SID_CLIPBOARD_FORMAT_ITEMS:
916 sal_uLong nFormat = 0;
917 const SfxPoolItem* pItem;
918 if ( rReq.GetArgs() && rReq.GetArgs()->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET &&
919 pItem->ISA(SfxUInt32Item) )
921 nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
924 if ( nFormat )
926 if (SOT_FORMAT_STRING == nFormat)
927 pOLV->Paste();
928 else
929 pOLV->PasteSpecial();
931 break;
934 pPostItMgr->GetActiveSidebarWin()->ResizeIfNeccessary(aOldHeight,pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight());
937 void SwAnnotationShell::StateClpbrd(SfxItemSet &rSet)
939 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
940 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
941 return;
942 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
944 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &rView.GetEditWin() ) );
945 bool bPastePossible = ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) || aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
946 bPastePossible = bPastePossible && (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED);
948 SfxWhichIter aIter(rSet);
949 sal_uInt16 nWhich = aIter.FirstWhich();
951 while(nWhich)
953 switch(nWhich)
955 case SID_CUT:
957 if ( (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED) || !pOLV->HasSelection() )
958 rSet.DisableItem( nWhich );
960 case SID_COPY:
962 if( !pOLV->HasSelection() )
963 rSet.DisableItem( nWhich );
964 break;
966 case SID_PASTE:
967 case SID_PASTE_SPECIAL:
969 if( !bPastePossible )
970 rSet.DisableItem( nWhich );
971 break;
973 case SID_CLIPBOARD_FORMAT_ITEMS:
975 if ( bPastePossible )
977 SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
978 if ( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
979 aFormats.AddClipbrdFormat( SOT_FORMAT_RTF );
980 aFormats.AddClipbrdFormat( SOT_FORMAT_STRING );
981 rSet.Put( aFormats );
983 else
984 rSet.DisableItem( nWhich );
985 break;
988 nWhich = aIter.NextWhich();
992 void SwAnnotationShell::StateStatusLine(SfxItemSet &rSet)
994 SfxWhichIter aIter( rSet );
995 sal_uInt16 nWhich = aIter.FirstWhich();
997 while( nWhich )
999 switch( nWhich )
1001 case FN_STAT_SELMODE:
1003 rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 0));
1004 rSet.DisableItem( nWhich );
1005 break;
1007 case FN_STAT_TEMPLATE:
1009 rSet.DisableItem( nWhich );
1010 break;
1013 nWhich = aIter.NextWhich();
1017 void SwAnnotationShell::StateInsert(SfxItemSet &rSet)
1019 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1020 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1021 return;
1023 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1024 SfxWhichIter aIter(rSet);
1025 sal_uInt16 nWhich = aIter.FirstWhich();
1027 while(nWhich)
1029 switch(nWhich)
1031 case SID_HYPERLINK_GETLINK:
1033 SvxHyperlinkItem aHLinkItem;
1034 aHLinkItem.SetInsertMode(HLINK_FIELD);
1036 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
1038 if (pFieldItem)
1040 const SvxFieldData* pField = pFieldItem->GetField();
1042 if (pField->ISA(SvxURLField))
1044 aHLinkItem.SetName(((const SvxURLField*) pField)->GetRepresentation());
1045 aHLinkItem.SetURL(((const SvxURLField*) pField)->GetURL());
1046 aHLinkItem.SetTargetFrame(((const SvxURLField*) pField)->GetTargetFrame());
1049 else
1051 String sSel(pOLV->GetSelected());
1052 sSel.Erase(255);
1053 aHLinkItem.SetName(comphelper::string::stripEnd(sSel, ' '));
1056 sal_uInt16 nHtmlMode = ::GetHtmlMode(rView.GetDocShell());
1057 aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
1058 ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
1060 rSet.Put(aHLinkItem);
1062 break;
1065 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1066 rSet.DisableItem( nWhich );
1068 nWhich = aIter.NextWhich();
1073 void SwAnnotationShell::NoteExec(SfxRequest &rReq)
1075 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1076 if ( !pPostItMgr )
1077 return;
1079 sal_uInt16 nSlot = rReq.GetSlot();
1080 switch (nSlot)
1082 case FN_REPLY:
1083 case FN_POSTIT:
1084 case FN_DELETE_COMMENT:
1085 if ( pPostItMgr->HasActiveSidebarWin() )
1086 pPostItMgr->GetActiveSidebarWin()->ExecuteCommand(nSlot);
1087 break;
1088 case FN_DELETE_ALL_NOTES:
1089 pPostItMgr->Delete();
1090 break;
1091 case FN_DELETE_NOTE_AUTHOR:
1093 SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, nSlot, sal_False);
1094 if ( pItem )
1095 pPostItMgr->Delete( pItem->GetValue() );
1096 break;
1098 case FN_HIDE_NOTE:
1099 break;
1100 case FN_HIDE_ALL_NOTES:
1101 pPostItMgr->Hide();
1102 break;
1103 case FN_HIDE_NOTE_AUTHOR:
1105 SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, nSlot, sal_False);
1106 if ( pItem )
1107 pPostItMgr->Hide( pItem->GetValue() );
1112 void SwAnnotationShell::GetNoteState(SfxItemSet &rSet)
1114 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1115 SfxWhichIter aIter(rSet);
1116 sal_uInt16 nWhich = aIter.FirstWhich();
1117 while(nWhich)
1119 sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
1120 switch( nSlotId )
1122 case FN_POSTIT:
1123 case FN_DELETE_NOTE_AUTHOR:
1124 case FN_DELETE_ALL_NOTES:
1125 case FN_HIDE_NOTE:
1126 case FN_HIDE_NOTE_AUTHOR:
1127 case FN_HIDE_ALL_NOTES:
1128 case FN_DELETE_COMMENT:
1130 if ( !pPostItMgr ||
1131 !pPostItMgr->HasActiveAnnotationWin() )
1133 rSet.DisableItem(nWhich);
1135 break;
1137 case FN_REPLY:
1139 if ( !pPostItMgr ||
1140 !pPostItMgr->HasActiveAnnotationWin() )
1142 rSet.DisableItem(nWhich);
1144 else
1146 SvtUserOptions aUserOpt;
1147 String sAuthor;
1148 if( !(sAuthor = aUserOpt.GetFullName()).Len())
1149 if( !(sAuthor = aUserOpt.GetID()).Len() )
1150 sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR ));
1151 if (sAuthor == pPostItMgr->GetActiveSidebarWin()->GetAuthor())
1152 rSet.DisableItem(nWhich);
1154 break;
1156 default:
1157 rSet.InvalidateItem( nWhich );
1158 break;
1161 if (pPostItMgr->HasActiveSidebarWin())
1163 if ( (pPostItMgr->GetActiveSidebarWin()->IsProtected()) &&
1164 ( (nSlotId==FN_DELETE_COMMENT) || (nSlotId==FN_REPLY) ) )
1165 rSet.DisableItem( nWhich );
1167 nWhich = aIter.NextWhich();
1171 void SwAnnotationShell::ExecLingu(SfxRequest &rReq)
1173 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1174 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1175 return;
1177 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1178 SfxItemSet aEditAttr(pOLV->GetAttribs());
1179 sal_uInt16 nSlot = rReq.GetSlot();
1180 SwWrtShell &rSh = rView.GetWrtShell();
1181 bool bRestoreSelection = false;
1182 ESelection aOldSelection;
1184 switch (nSlot)
1186 case SID_LANGUAGE_STATUS:
1188 aOldSelection = pOLV->GetSelection();
1189 if (!pOLV->GetEditView().HasSelection())
1191 bRestoreSelection = true;
1192 pOLV->GetEditView().SelectCurrentWord();
1195 bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,rView,rSh);
1196 break;
1198 case SID_THES:
1200 String aReplaceText;
1201 SFX_REQUEST_ARG( rReq, pItem2, SfxStringItem, SID_THES, sal_False );
1202 if (pItem2)
1203 aReplaceText = pItem2->GetValue();
1204 if (aReplaceText.Len() > 0)
1205 ReplaceTextWithSynonym( pOLV->GetEditView(), aReplaceText );
1206 break;
1208 case SID_THESAURUS:
1210 pOLV->StartThesaurus();
1211 break;
1213 case SID_HANGUL_HANJA_CONVERSION:
1214 pOLV->StartTextConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, NULL,
1215 i18n::TextConversionOption::CHARACTER_BY_CHARACTER, sal_True, sal_False );
1216 break;
1218 case SID_CHINESE_CONVERSION:
1220 //open ChineseTranslationDialog
1221 Reference< XComponentContext > xContext(
1222 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1223 if(xContext.is())
1225 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1226 if(xMCF.is())
1228 Reference< ui::dialogs::XExecutableDialog > xDialog(
1229 xMCF->createInstanceWithContext(
1230 OUString("com.sun.star.linguistic2.ChineseTranslationDialog")
1231 , xContext), UNO_QUERY);
1232 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1233 if( xInit.is() )
1235 // initialize dialog
1236 Reference< awt::XWindow > xDialogParentWindow(0);
1237 Sequence<Any> aSeq(1);
1238 Any* pArray = aSeq.getArray();
1239 PropertyValue aParam;
1240 aParam.Name = OUString("ParentWindow");
1241 aParam.Value <<= makeAny(xDialogParentWindow);
1242 pArray[0] <<= makeAny(aParam);
1243 xInit->initialize( aSeq );
1245 //execute dialog
1246 sal_Int16 nDialogRet = xDialog->execute();
1247 if( RET_OK == nDialogRet )
1249 //get some parameters from the dialog
1250 sal_Bool bToSimplified = sal_True;
1251 sal_Bool bUseVariants = sal_True;
1252 sal_Bool bCommonTerms = sal_True;
1253 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
1254 if( xProp.is() )
1258 xProp->getPropertyValue( "IsDirectionToSimplified" ) >>= bToSimplified;
1259 xProp->getPropertyValue( "IsUseCharacterVariants" ) >>= bUseVariants;
1260 xProp->getPropertyValue( "IsTranslateCommonTerms" ) >>= bCommonTerms;
1262 catch (const Exception&)
1267 //execute translation
1268 sal_Int16 nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1269 sal_Int16 nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1270 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1271 if( !bCommonTerms )
1272 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1274 Font aTargetFont = pOLV->GetWindow()->GetDefaultFont( DEFAULTFONT_CJK_TEXT,
1275 nTargetLang, DEFAULTFONT_FLAGS_ONLYONE );
1277 pOLV->StartTextConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, sal_False, sal_False );
1280 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1281 if( xComponent.is() )
1282 xComponent->dispose();
1286 break;
1289 if (bRestoreSelection)
1291 // restore selection
1292 pOLV->GetEditView().SetSelection( aOldSelection );
1296 void SwAnnotationShell::GetLinguState(SfxItemSet &rSet)
1298 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1299 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1300 return;
1302 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1303 SfxItemSet aEditAttr(pOLV->GetAttribs());
1305 SfxWhichIter aIter(rSet);
1306 sal_uInt16 nWhich = aIter.FirstWhich();
1307 while(nWhich)
1309 switch (nWhich)
1311 case SID_LANGUAGE_STATUS:
1313 SwLangHelper::GetLanguageStatus(pOLV,rSet);
1314 break;
1317 case SID_THES:
1319 String aStatusVal;
1320 LanguageType nLang = LANGUAGE_NONE;
1321 bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, pOLV->GetEditView() );
1322 rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
1324 // disable "Thesaurus" context menu entry if there is nothing to look up
1325 uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() );
1326 if (!bIsLookUpWord ||
1327 !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( LanguageTag( nLang ).getLocale() ))
1328 rSet.DisableItem( SID_THES );
1329 break;
1332 // disable "Thesaurus" if the language is not supported
1333 case SID_THESAURUS:
1335 const SfxPoolItem &rItem = rView.GetWrtShell().GetDoc()->GetDefault(
1336 GetWhichOfScript( RES_CHRATR_LANGUAGE,
1337 GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage())) );
1338 LanguageType nLang = ((const SvxLanguageItem &)
1339 rItem).GetLanguage();
1340 uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() );
1341 if (!xThes.is() || nLang == LANGUAGE_NONE ||
1342 !xThes->hasLocale( LanguageTag( nLang ).getLocale() ))
1343 rSet.DisableItem( SID_THESAURUS );
1345 break;
1346 case SID_HANGUL_HANJA_CONVERSION:
1347 case SID_CHINESE_CONVERSION:
1349 if (!SvtCJKOptions().IsAnyEnabled())
1351 rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_False );
1352 rSet.DisableItem(nWhich);
1354 else
1355 rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
1357 break;
1360 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1361 rSet.DisableItem( nWhich );
1363 nWhich = aIter.NextWhich();
1367 void SwAnnotationShell::ExecTransliteration(SfxRequest &rReq)
1369 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1370 if (!pPostItMgr || !pPostItMgr->HasActiveSidebarWin())
1371 return;
1373 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1375 if (!pOLV)
1376 return;
1378 using namespace ::com::sun::star::i18n;
1380 sal_uInt32 nMode = 0;
1382 switch( rReq.GetSlot() )
1384 case SID_TRANSLITERATE_SENTENCE_CASE:
1385 nMode = TransliterationModulesExtra::SENTENCE_CASE;
1386 break;
1387 case SID_TRANSLITERATE_TITLE_CASE:
1388 nMode = TransliterationModulesExtra::TITLE_CASE;
1389 break;
1390 case SID_TRANSLITERATE_TOGGLE_CASE:
1391 nMode = TransliterationModulesExtra::TOGGLE_CASE;
1392 break;
1393 case SID_TRANSLITERATE_UPPER:
1394 nMode = TransliterationModules_LOWERCASE_UPPERCASE;
1395 break;
1396 case SID_TRANSLITERATE_LOWER:
1397 nMode = TransliterationModules_UPPERCASE_LOWERCASE;
1398 break;
1399 case SID_TRANSLITERATE_HALFWIDTH:
1400 nMode = TransliterationModules_FULLWIDTH_HALFWIDTH;
1401 break;
1402 case SID_TRANSLITERATE_FULLWIDTH:
1403 nMode = TransliterationModules_HALFWIDTH_FULLWIDTH;
1404 break;
1405 case SID_TRANSLITERATE_HIRAGANA:
1406 nMode = TransliterationModules_KATAKANA_HIRAGANA;
1407 break;
1408 case SID_TRANSLITERATE_KATAGANA:
1409 nMode = TransliterationModules_HIRAGANA_KATAKANA;
1410 break;
1412 default:
1413 OSL_ENSURE(!this, "wrong dispatcher");
1416 if( nMode )
1417 pOLV->TransliterateText( nMode );
1420 void SwAnnotationShell::ExecRotateTransliteration( SfxRequest & rReq )
1422 if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE )
1424 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1425 if (!pPostItMgr || !pPostItMgr->HasActiveSidebarWin())
1426 return;
1428 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1430 if (!pOLV)
1431 return;
1433 pOLV->TransliterateText(m_aRotateCase.getNextMode());
1437 void SwAnnotationShell::ExecUndo(SfxRequest &rReq)
1439 const SfxItemSet* pArgs = rReq.GetArgs();
1440 ::svl::IUndoManager* pUndoManager = GetUndoManager();
1441 SwWrtShell &rSh = rView.GetWrtShell();
1443 long aOldHeight = rView.GetPostItMgr()->HasActiveSidebarWin()
1444 ? rView.GetPostItMgr()->GetActiveSidebarWin()->GetPostItTextHeight()
1445 : 0;
1447 sal_uInt16 nId = rReq.GetSlot();
1448 sal_uInt16 nCnt = 1;
1449 const SfxPoolItem* pItem=0;
1450 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nId, sal_False, &pItem ) )
1451 nCnt = ((SfxUInt16Item*)pItem)->GetValue();
1452 switch( nId )
1454 case SID_UNDO:
1456 if ( pUndoManager )
1458 sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1459 sal_uInt16 nSteps = nCnt;
1460 if ( nCount < nCnt )
1462 nCnt = nCnt - nCount;
1463 nSteps = nCount;
1465 else
1466 nCnt = 0;
1468 while( nSteps-- )
1469 pUndoManager->Undo();
1472 if ( nCnt )
1473 rSh.Do( SwWrtShell::UNDO, nCnt );
1475 break;
1478 case SID_REDO:
1480 if ( pUndoManager )
1482 sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1483 sal_uInt16 nSteps = nCnt;
1484 if ( nCount < nCnt )
1486 nCnt = nCnt - nCount;
1487 nSteps = nCount;
1489 else
1490 nCnt = 0;
1492 while( nSteps-- )
1493 pUndoManager->Redo();
1496 if ( nCnt )
1497 rSh.Do( SwWrtShell::REDO, nCnt );
1499 break;
1503 rView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
1505 if (rView.GetPostItMgr()->HasActiveSidebarWin())
1506 rView.GetPostItMgr()->GetActiveSidebarWin()->ResizeIfNeccessary(aOldHeight,rView.GetPostItMgr()->GetActiveSidebarWin()->GetPostItTextHeight());
1509 void SwAnnotationShell::StateUndo(SfxItemSet &rSet)
1511 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1512 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1513 return;
1515 SfxWhichIter aIter(rSet);
1516 sal_uInt16 nWhich = aIter.FirstWhich();
1517 ::svl::IUndoManager* pUndoManager = GetUndoManager();
1518 SfxViewFrame *pSfxViewFrame = rView.GetViewFrame();
1519 SwWrtShell &rSh = rView.GetWrtShell();
1521 while( nWhich )
1523 switch ( nWhich )
1525 case SID_UNDO:
1527 sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1528 if ( nCount )
1529 pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1530 else if (rSh.GetLastUndoInfo(0, 0))
1532 rSet.Put( SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::UNDO)) );
1534 else
1535 rSet.DisableItem(nWhich);
1536 break;
1538 case SID_REDO:
1540 sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1541 if ( nCount )
1542 pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1543 else if (rSh.GetFirstRedoInfo(0))
1545 rSet.Put(SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::REDO)) );
1547 else
1548 rSet.DisableItem(nWhich);
1549 break;
1551 case SID_GETUNDOSTRINGS:
1552 case SID_GETREDOSTRINGS:
1554 if( pUndoManager )
1556 OUString (::svl::IUndoManager:: *fnGetComment)( size_t, bool const ) const;
1558 sal_uInt16 nCount;
1559 if( SID_GETUNDOSTRINGS == nWhich )
1561 nCount = pUndoManager->GetUndoActionCount();
1562 fnGetComment = &::svl::IUndoManager::GetUndoActionComment;
1564 else
1566 nCount = pUndoManager->GetRedoActionCount();
1567 fnGetComment = &::svl::IUndoManager::GetRedoActionComment;
1570 String sList;
1571 if( nCount )
1573 for( sal_uInt16 n = 0; n < nCount; ++n )
1574 ( sList += (pUndoManager->*fnGetComment)( n, ::svl::IUndoManager::TopLevel ) )
1575 += '\n';
1578 SfxStringListItem aItem( nWhich );
1579 if ((nWhich == SID_GETUNDOSTRINGS) &&
1580 rSh.GetLastUndoInfo(0, 0))
1582 rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1584 else if ((nWhich == SID_GETREDOSTRINGS) &&
1585 (rSh.GetFirstRedoInfo(0)))
1587 rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1590 sList += aItem.GetString();
1591 aItem.SetString( sList );
1592 rSet.Put( aItem );
1594 else
1595 rSet.DisableItem( nWhich );
1597 break;
1599 default:
1601 pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1602 break;
1607 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1608 rSet.DisableItem( nWhich );
1610 nWhich = aIter.NextWhich();
1614 void SwAnnotationShell::StateDisableItems( SfxItemSet &rSet )
1616 SfxWhichIter aIter(rSet);
1617 sal_uInt16 nWhich = aIter.FirstWhich();
1618 while (nWhich)
1620 rSet.DisableItem( nWhich );
1621 nWhich = aIter.NextWhich();
1625 void SwAnnotationShell::InsertSymbol(SfxRequest& rReq)
1627 SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1628 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1629 return;
1631 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1633 const SfxItemSet *pArgs = rReq.GetArgs();
1634 const SfxPoolItem* pItem = 0;
1635 if( pArgs )
1636 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), sal_False, &pItem);
1638 String sSym;
1639 String sFontName;
1640 if ( pItem )
1642 sSym = ((const SfxStringItem*)pItem)->GetValue();
1643 const SfxPoolItem* pFtItem = NULL;
1644 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), sal_False, &pFtItem);
1645 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
1646 if ( pFontItem )
1647 sFontName = pFontItem->GetValue();
1650 SfxItemSet aSet(pOLV->GetAttribs());
1651 sal_uInt16 nScript = pOLV->GetSelectedScriptType();
1652 SvxFontItem aSetDlgFont( RES_CHRATR_FONT );
1654 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1655 aSetItem.GetItemSet().Put( aSet, sal_False );
1656 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1657 if( pI )
1658 aSetDlgFont = *(SvxFontItem*)pI;
1659 else
1660 aSetDlgFont = (SvxFontItem&)aSet.Get( GetWhichOfScript(
1661 SID_ATTR_CHAR_FONT,
1662 GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() ) ));
1663 if (!sFontName.Len())
1664 sFontName = aSetDlgFont.GetFamilyName();
1667 Font aFont(sFontName, Size(1,1));
1668 if( !sSym.Len() )
1670 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1672 SfxAllItemSet aAllSet( GetPool() );
1673 aAllSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
1675 SwViewOption aOpt(*rView.GetWrtShell().GetViewOptions());
1676 String sSymbolFont = aOpt.GetSymbolFont();
1677 if( sSymbolFont.Len() )
1678 aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
1679 else
1680 aAllSet.Put( SfxStringItem( SID_FONT_NAME, aSetDlgFont.GetFamilyName() ) );
1682 // If character is selected then it can be shown.
1683 SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( rView.GetWindow(), aAllSet,
1684 rView.GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
1686 sal_uInt16 nResult = pDlg->Execute();
1687 if( nResult == RET_OK )
1689 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, sal_False );
1690 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False );
1691 if ( pFontItem )
1693 aFont.SetName( pFontItem->GetFamilyName() );
1694 aFont.SetStyleName( pFontItem->GetStyleName() );
1695 aFont.SetCharSet( pFontItem->GetCharSet() );
1696 aFont.SetPitch( pFontItem->GetPitch() );
1699 if ( pCItem )
1701 sSym = pCItem->GetValue();
1702 aOpt.SetSymbolFont(aFont.GetName());
1703 SW_MOD()->ApplyUsrPref(aOpt, &rView);
1707 delete( pDlg );
1710 if( sSym.Len() )
1712 // do not flicker
1713 pOLV->HideCursor();
1714 Outliner * pOutliner = pOLV->GetOutliner();
1715 pOutliner->SetUpdateMode(sal_False);
1717 SfxItemSet aOldSet( pOLV->GetAttribs() );
1718 SfxItemSet aFontSet( *aOldSet.GetPool(),
1719 EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
1720 EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CJK,
1721 EE_CHAR_FONTINFO_CTL, EE_CHAR_FONTINFO_CTL,
1722 0 );
1723 aFontSet.Set( aOldSet );
1725 // Insert string
1726 pOLV->InsertText( sSym);
1728 // Attributing (set font)
1729 SfxItemSet aSetFont( *aFontSet.GetPool(), aFontSet.GetRanges() );
1730 SvxFontItem aFontItem (aFont.GetFamily(), aFont.GetName(),
1731 aFont.GetStyleName(), aFont.GetPitch(),
1732 aFont.GetCharSet(),
1733 EE_CHAR_FONTINFO );
1734 sal_uInt16 nScriptBreak = g_pBreakIt->GetAllScriptsOfText( sSym );
1735 if( SCRIPTTYPE_LATIN & nScriptBreak )
1736 aSetFont.Put( aFontItem, EE_CHAR_FONTINFO );
1737 if( SCRIPTTYPE_ASIAN & nScriptBreak )
1738 aSetFont.Put( aFontItem, EE_CHAR_FONTINFO_CJK );
1739 if( SCRIPTTYPE_COMPLEX & nScriptBreak )
1740 aSetFont.Put( aFontItem, EE_CHAR_FONTINFO_CTL );
1741 pOLV->SetAttribs(aSetFont);
1743 // Erase selection
1744 ESelection aSel(pOLV->GetSelection());
1745 aSel.nStartPara = aSel.nEndPara;
1746 aSel.nStartPos = aSel.nEndPos;
1747 pOLV->SetSelection(aSel);
1749 // Restore old font
1750 pOLV->SetAttribs( aFontSet );
1752 // From now on show it again
1753 pOutliner->SetUpdateMode(sal_True);
1754 pOLV->ShowCursor();
1756 rReq.AppendItem( SfxStringItem( GetPool().GetWhich(SID_CHARMAP), sSym ) );
1757 if(aFont.GetName().Len())
1758 rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aFont.GetName() ) );
1759 rReq.Done();
1763 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */