xref: /aoo41x/main/sw/source/ui/shells/annotsh.cxx (revision 8ef2f12b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #include <hintids.hxx>
28 
29 #include <com/sun/star/i18n/TransliterationModules.hpp>
30 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
31 #include <com/sun/star/i18n/TextConversionOption.hpp>
32 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
33 #include <com/sun/star/lang/XInitialization.hpp>
34 
35 #include <tools/shl.hxx>
36 #include <i18npool/mslangid.hxx>
37 #include <sfx2/objface.hxx>
38 #include <sfx2/viewfrm.hxx>
39 #include <sfx2/bindings.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <sfx2/request.hxx>
42 #include <editeng/spltitem.hxx>
43 #include <editeng/lrspitem.hxx>
44 #include <editeng/ulspitem.hxx>
45 #include <editeng/orphitem.hxx>
46 #include <editeng/brkitem.hxx>
47 #include <editeng/widwitem.hxx>
48 #include <editeng/kernitem.hxx>
49 #include <editeng/escpitem.hxx>
50 #include <editeng/lspcitem.hxx>
51 #include <editeng/adjitem.hxx>
52 #include <editeng/crsditem.hxx>
53 #include <editeng/shdditem.hxx>
54 #include <editeng/hyznitem.hxx>
55 #include <editeng/udlnitem.hxx>
56 #include <editeng/fontitem.hxx>
57 #include <editeng/fhgtitem.hxx>
58 #include <svx/clipfmtitem.hxx>
59 #include <svl/stritem.hxx>
60 #include <svl/slstitm.hxx>
61 #include <editeng/colritem.hxx>
62 #include <editeng/wghtitem.hxx>
63 #include <editeng/cntritem.hxx>
64 #include <editeng/postitem.hxx>
65 #include <editeng/frmdiritem.hxx>
66 #include <svx/svdoutl.hxx>
67 #include <svl/whiter.hxx>
68 #include <svl/cjkoptions.hxx>
69 #include <svl/ctloptions.hxx>
70 #include <unotools/useroptions.hxx>
71 #include <vcl/msgbox.hxx>
72 #include <editeng/flditem.hxx>
73 #include <editeng/editstat.hxx>
74 #include <svx/hlnkitem.hxx>
75 #include <svx/htmlmode.hxx>
76 #include <editeng/langitem.hxx>
77 #include <editeng/unolingu.hxx>
78 #include <editeng/scripttypeitem.hxx>
79 #include <editeng/writingmodeitem.hxx>
80 #include <swundo.hxx>
81 #include <doc.hxx>
82 #include <viewopt.hxx>
83 #include <wrtsh.hxx>
84 #include <uitool.hxx>
85 #include <popup.hrc>
86 #include <pardlg.hxx>
87 #include <swdtflvr.hxx>
88 #include <drwtxtsh.hxx>
89 #include <swmodule.hxx>
90 #include <initui.hxx>
91 #include <edtwin.hxx>
92 #include <swwait.hxx>
93 #include <docstat.hxx>
94 
95 #include <cmdid.h>
96 #include <globals.hrc>
97 #include <shells.hrc>
98 #include <breakit.hxx>
99 #include "annotsh.hxx"
100 #include "view.hxx"
101 #include <PostItMgr.hxx>
102 #include <SidebarWin.hxx>
103 
104 #include "swtypes.hxx"
105 
106 #include <svx/svxdlg.hxx>
107 #include <svx/dialogs.hrc>
108 
109 #include <svx/svxids.hrc>
110 #include <sfx2/sidebar/EnumContext.hxx>
111 #include <svl/itempool.hxx>
112 #include <editeng/outliner.hxx>
113 #include <editeng/editeng.hxx>
114 #include <editeng/editview.hxx>
115 
116 #include <svl/languageoptions.hxx>
117 #include <editeng/langitem.hxx>
118 #include <svtools/langtab.hxx>
119 #include <svl/slstitm.hxx>
120 
121 #include <docsh.hxx>
122 #include <svl/undo.hxx>
123 #include "swabstdlg.hxx"
124 #include "chrdlg.hrc"
125 #include "misc.hrc"
126 #include <app.hrc>
127 
128 #include <comphelper/processfactory.hxx>
129 
130 #include <cppuhelper/bootstrap.hxx>
131 
132 #include <langhelper.hxx>
133 
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;
138 
139 #define SwAnnotationShell
140 
141 #include <sfx2/msg.hxx>
142 #include <swslots.hxx>
143 
SFX_IMPL_INTERFACE(SwAnnotationShell,SfxShell,SW_RES (STR_SHELLNAME_DRAW_TEXT))144 SFX_IMPL_INTERFACE(SwAnnotationShell, SfxShell, SW_RES(STR_SHELLNAME_DRAW_TEXT))
145 {
146 	SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TEXT_TOOLBOX));
147 	SFX_POPUPMENU_REGISTRATION(SW_RES(MN_ANNOTATION_POPUPMENU));
148 }
149 
TYPEINIT1(SwAnnotationShell,SfxShell)150 TYPEINIT1(SwAnnotationShell,SfxShell)
151 
152 SwAnnotationShell::SwAnnotationShell( SwView& r )
153 : rView(r)
154 {
155 	SwWrtShell &rSh = rView.GetWrtShell();
156 	SetPool(rSh.GetAttrPool().GetSecondaryPool());
157     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Annotation));
158 }
159 
~SwAnnotationShell()160 SwAnnotationShell::~SwAnnotationShell()
161 {
162 }
163 
GetUndoManager()164 ::svl::IUndoManager* SwAnnotationShell::GetUndoManager()
165 {
166 	SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
167     if ( !pPostItMgr ||
168          !pPostItMgr->HasActiveSidebarWin() )
169 	{
170 		DBG_ASSERT(pPostItMgr,"PostItMgr::Layout(): We are looping forever");
171 		return 0;
172 	}
173     return &pPostItMgr->GetActiveSidebarWin()->GetOutlinerView()->GetOutliner()->GetUndoManager();
174 }
175 
Exec(SfxRequest & rReq)176 void SwAnnotationShell::Exec( SfxRequest &rReq )
177 {
178 	//TODO: clean this up!!!!
179 	SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
180     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
181 		return;
182 
183     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
184     SfxItemSet aEditAttr(pOLV->GetAttribs());
185 	SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
186 
187 	sal_uInt16 nSlot = rReq.GetSlot();
188 	sal_uInt16 nWhich = GetPool().GetWhich(nSlot);
189 	const SfxItemSet *pNewAttrs = rReq.GetArgs();
190     sal_uInt16 nEEWhich = 0;
191 	switch (nSlot)
192 	{
193 		case SID_ATTR_PARA_LRSPACE:
194 			{
195 				SvxLRSpaceItem aParaMargin((const SvxLRSpaceItem&)rReq.
196 										GetArgs()->Get(nSlot));
197 				aParaMargin.SetWhich( EE_PARA_LRSPACE );
198 
199 				aNewAttr.Put(aParaMargin);
200 				rReq.Done();
201 				break;
202 			}
203 		case SID_ATTR_PARA_LINESPACE:
204 			{
205 				SvxLineSpacingItem aParaMargin = (const SvxLineSpacingItem&)pNewAttrs->Get(
206 															GetPool().GetWhich(nSlot));
207 				aParaMargin.SetWhich( EE_PARA_SBL );
208 
209 				aNewAttr.Put(aParaMargin);
210 				rReq.Done();
211 				break;
212 			}
213 		case SID_ATTR_PARA_ULSPACE:
214 			{
215 				SvxULSpaceItem aULSpace = (const SvxULSpaceItem&)pNewAttrs->Get(
216 					GetPool().GetWhich(nSlot));
217 				aULSpace.SetWhich( EE_PARA_ULSPACE );
218 				aNewAttr.Put( aULSpace );
219 				rReq.Done();
220 			}
221 			break;
222 		case SID_ATTR_CHAR_FONT:
223 		case SID_ATTR_CHAR_FONTHEIGHT:
224 		case SID_ATTR_CHAR_WEIGHT:
225 		case SID_ATTR_CHAR_POSTURE:
226 			{
227 				SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
228 				if( !pSecondPool )
229 					pSecondPool = aEditAttr.GetPool();
230 				SvxScriptSetItem aSetItem( nSlot, *pSecondPool );
231 				aSetItem.PutItemForScriptType( pOLV->GetSelectedScriptType(), pNewAttrs->Get( nWhich ));
232 				aNewAttr.Put( aSetItem.GetItemSet() );
233 				rReq.Done();
234 				break;
235 			}
236 		case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
237 		case SID_ATTR_CHAR_UNDERLINE:
238 		{
239 			if( rReq.GetArgs() )
240 			{
241 				SFX_REQUEST_ARG( rReq, pItem, SvxUnderlineItem, SID_ATTR_CHAR_UNDERLINE , sal_False );
242 				if (pItem)
243 				{
244 					aNewAttr.Put(*pItem);
245 				}
246 				else
247 				{
248 					FontUnderline eFU = ( (const SvxUnderlineItem&) aEditAttr.Get( EE_CHAR_UNDERLINE ) ).GetLineStyle();
249 					aNewAttr.Put( SvxUnderlineItem( eFU != UNDERLINE_NONE ?UNDERLINE_NONE : UNDERLINE_SINGLE,  EE_CHAR_UNDERLINE ) );
250 				}
251 			}
252 			break;
253 		}
254 		case SID_ATTR_CHAR_OVERLINE:
255 		{
256 		 	FontUnderline eFO = ((const SvxOverlineItem&)aEditAttr.Get(EE_CHAR_OVERLINE)).GetLineStyle();
257 			aNewAttr.Put(SvxOverlineItem(eFO == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_OVERLINE));
258 			break;
259 		}
260 		case SID_ATTR_CHAR_CONTOUR:     nEEWhich = EE_CHAR_OUTLINE; break;
261         case SID_ATTR_CHAR_SHADOWED:    nEEWhich = EE_CHAR_SHADOW; break;
262         case SID_ATTR_CHAR_STRIKEOUT:   nEEWhich = EE_CHAR_STRIKEOUT; break;
263 		case SID_ATTR_CHAR_WORDLINEMODE: nEEWhich = EE_CHAR_WLM; break;
264         case SID_ATTR_CHAR_RELIEF      : nEEWhich = EE_CHAR_RELIEF;  break;
265         case SID_ATTR_CHAR_LANGUAGE    : nEEWhich = EE_CHAR_LANGUAGE;break;
266         case SID_ATTR_CHAR_KERNING     : nEEWhich = EE_CHAR_KERNING; break;
267         case SID_ATTR_CHAR_SCALEWIDTH:   nEEWhich = EE_CHAR_FONTWIDTH; break;
268         case SID_ATTR_CHAR_AUTOKERN  :   nEEWhich = EE_CHAR_PAIRKERNING; break;
269         case SID_ATTR_CHAR_ESCAPEMENT:   nEEWhich = EE_CHAR_ESCAPEMENT; break;
270         case SID_ATTR_PARA_ADJUST_LEFT:
271 			aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_LEFT, EE_PARA_JUST));
272         break;
273 		case SID_ATTR_PARA_ADJUST_CENTER:
274 			aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_CENTER, EE_PARA_JUST));
275         break;
276 		case SID_ATTR_PARA_ADJUST_RIGHT:
277 			aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_RIGHT, EE_PARA_JUST));
278         break;
279 		case SID_ATTR_PARA_ADJUST_BLOCK:
280 			aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_BLOCK, EE_PARA_JUST));
281         break;
282 
283 		case SID_ATTR_PARA_LINESPACE_10:
284 		{
285 			SvxLineSpacingItem aItem(SVX_LINESPACE_ONE_LINE, EE_PARA_SBL);
286 			aItem.SetPropLineSpace(100);
287 			aNewAttr.Put(aItem);
288 		}
289 		break;
290 		case SID_ATTR_PARA_LINESPACE_15:
291 		{
292 			SvxLineSpacingItem aItem(SVX_LINESPACE_ONE_POINT_FIVE_LINES, EE_PARA_SBL);
293 			aItem.SetPropLineSpace(150);
294 			aNewAttr.Put(aItem);
295 		}
296 		break;
297 		case SID_ATTR_PARA_LINESPACE_20:
298 		{
299 			SvxLineSpacingItem aItem(SVX_LINESPACE_TWO_LINES, EE_PARA_SBL);
300 			aItem.SetPropLineSpace(200);
301 			aNewAttr.Put(aItem);
302 		}
303 		break;
304 		case SID_SELECTALL:
305 		{
306             Outliner * pOutliner = pOLV->GetOutliner();
307             if(pOutliner)
308             {
309                 sal_uLong nParaCount = pOutliner->GetParagraphCount();
310                 if (nParaCount > 0)
311                     pOLV->SelectRange(0L, sal_uInt16(nParaCount) );
312             }
313 			break;
314 		}
315 		case FN_FORMAT_RESET:
316 		{
317             pPostItMgr->GetActiveSidebarWin()->ResetAttributes();
318 			rReq.Done();
319 			break;
320 		}
321 		case FN_SET_SUPER_SCRIPT:
322 		{
323 			SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
324 			SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&)
325 							aEditAttr.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
326 
327 			if( eEsc == SVX_ESCAPEMENT_SUPERSCRIPT )
328 				aItem.SetEscapement( SVX_ESCAPEMENT_OFF );
329 			else
330 				aItem.SetEscapement( SVX_ESCAPEMENT_SUPERSCRIPT );
331 			aNewAttr.Put( aItem, EE_CHAR_ESCAPEMENT );
332 		}
333 		break;
334 		case FN_SET_SUB_SCRIPT:
335 		{
336 			SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
337 			SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&)
338 							aEditAttr.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
339 
340 			if( eEsc == SVX_ESCAPEMENT_SUBSCRIPT )
341 				aItem.SetEscapement( SVX_ESCAPEMENT_OFF );
342 			else
343 				aItem.SetEscapement( SVX_ESCAPEMENT_SUBSCRIPT );
344 			aNewAttr.Put( aItem, EE_CHAR_ESCAPEMENT );
345 		}
346 		break;
347 		case SID_HYPERLINK_SETLINK:
348 		{
349 			const SfxPoolItem* pItem = 0;
350 			if(pNewAttrs)
351 				pNewAttrs->GetItemState(nSlot, sal_False, &pItem);
352 
353 			if(pItem)
354 			{
355 				const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
356 				SvxURLField aFld(rHLinkItem.GetURL(), rHLinkItem.GetName(), SVXURLFORMAT_APPDEFAULT);
357 				aFld.SetTargetFrame(rHLinkItem.GetTargetFrame());
358 
359 				const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
360 
361 				if (pFieldItem && pFieldItem->GetField()->ISA(SvxURLField))
362 				{
363 					// Feld selektieren, so dass es beim Insert geloescht wird
364 					ESelection aSel = pOLV->GetSelection();
365 					aSel.nEndPos++;
366 					pOLV->SetSelection(aSel);
367 				}
368                 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
369 					pOLV->InsertField(SvxFieldItem(aFld, EE_FEATURE_FIELD));
370 			}
371 			break;
372 		}
373 		case FN_INSERT_SOFT_HYPHEN:
374         case FN_INSERT_HARDHYPHEN:
375         case FN_INSERT_HARD_SPACE:
376         case SID_INSERT_RLM :
377         case SID_INSERT_LRM :
378         case SID_INSERT_ZWNBSP :
379         case SID_INSERT_ZWSP:
380         {
381             sal_Unicode cIns = 0;
382             switch(rReq.GetSlot())
383             {
384                 case FN_INSERT_SOFT_HYPHEN: cIns = CHAR_SOFTHYPHEN; break;
385                 case FN_INSERT_HARDHYPHEN: cIns = CHAR_HARDHYPHEN; break;
386                 case FN_INSERT_HARD_SPACE: cIns = CHAR_HARDBLANK; break;
387                 case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
388                 case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
389                 case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
390                 case SID_INSERT_ZWNBSP: cIns = CHAR_ZWNBSP; break;
391             }
392             pOLV->InsertText( String(cIns));
393             rReq.Done();
394 			break;
395         }
396 		case SID_CHARMAP:
397 		{
398             if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
399 				InsertSymbol(rReq);
400 			break;
401 		}
402 	        case FN_INSERT_STRING:
403                 {
404 			const SfxPoolItem* pItem = 0;
405 			if(pNewAttrs)
406 				pNewAttrs->GetItemState(nSlot, sal_False, &pItem );
407                         if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
408                                 pOLV->InsertText(((const SfxStringItem *)pItem)->GetValue());
409                         break;
410                 }
411 
412 		case FN_FORMAT_FOOTNOTE_DLG:
413 		{
414             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
415             DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
416 
417             VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( rView.GetWindow(), rView.GetWrtShell(), DLG_DOC_FOOTNOTE );
418             DBG_ASSERT(pDlg, "Dialogdiet fail!");
419 			pDlg->Execute();
420 			delete pDlg;
421 			break;
422 		}
423 		case FN_NUMBERING_OUTLINE_DLG:
424 		{
425 			SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
426 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
427             DBG_ASSERT(pFact, "Dialogdiet fail!");
428             SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
429 														rView.GetWindow(), &aTmp, rView.GetWrtShell());
430             DBG_ASSERT(pDlg, "Dialogdiet fail!");
431 			pDlg->Execute();
432 			delete pDlg;
433 			rReq.Done();
434 		}
435 		break;
436 		case SID_OPEN_XML_FILTERSETTINGS:
437 		{
438 			try
439 			{
440 				uno::Reference < ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), uno::UNO_QUERY);
441 				if( xDialog.is() )
442 				{
443 					xDialog->execute();
444 				}
445 			}
446 			catch( uno::Exception& )
447 			{
448 			}
449 			rReq.Ignore ();
450 		}
451 		break;
452 		case FN_WORDCOUNT_DIALOG:
453 		{
454 			SwWrtShell &rSh = rView.GetWrtShell();
455 			SwDocStat aCurr;
456 			SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
457 			{
458 				SwWait aWait( *rView.GetDocShell(), true );
459 				rSh.StartAction();
460 				rSh.CountWords( aCurr );
461 				rSh.UpdateDocStat( aDocStat );
462 				rSh.EndAction();
463 			}
464 
465 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
466 			DBG_ASSERT(pFact, "Dialogdiet fail!");
467 			AbstractSwWordCountDialog* pDialog = pFact->CreateSwWordCountDialog( rView.GetWindow() );
468 			pDialog->SetValues(aCurr, aDocStat );
469 			pDialog->Execute();
470 			delete pDialog;
471 		}
472 		break;
473 		case SID_CHAR_DLG_EFFECT:
474 		case SID_CHAR_DLG:
475 		{
476 			const SfxItemSet* pArgs = rReq.GetArgs();
477 
478 			if( !pArgs )
479 			{
480 				/* mod
481 				SwView* pView = &GetView();
482 				FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
483 				SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
484 				*/
485 				SfxItemSet aDlgAttr(GetPool(), EE_ITEMS_START, EE_ITEMS_END);
486 
487 				// util::Language gibts an der EditEngine nicht! Daher nicht im Set.
488 
489 				aDlgAttr.Put( aEditAttr );
490                 aDlgAttr.Put( SvxKerningItem(0, RES_CHRATR_KERNING) );
491 
492 				//CHINA001 SwCharDlg* pDlg = new SwCharDlg(pView->GetWindow(), *pView, aDlgAttr, 0, sal_True);
493 				SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();//CHINA001
494 				DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");//CHINA001
495 
496 				SfxAbstractTabDialog* pDlg = pFact->CreateSwCharDlg( rView.GetWindow(), rView, aDlgAttr, DLG_CHAR,0, sal_True );
497 				DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
498 				if (nSlot == SID_CHAR_DLG_EFFECT)
499 				{
500 					pDlg->SetCurPageId(TP_CHAR_EXT);
501 				}
502 				sal_uInt16 nRet = pDlg->Execute();
503 				if(RET_OK == nRet )
504                 {
505                     rReq.Done( *( pDlg->GetOutputItemSet() ) );
506                     aNewAttr.Put(*pDlg->GetOutputItemSet());
507                 }
508 				delete( pDlg );
509 				if(RET_OK != nRet)
510 					return ;
511 			}
512 			else
513 				aNewAttr.Put(*pArgs);
514 		break;
515 		}
516 		case SID_PARA_DLG:
517 		{
518 			const SfxItemSet* pArgs = rReq.GetArgs();
519 
520 			if (!pArgs)
521 			{
522 				/* mod todo ???
523 				SwView* pView = &GetView();
524 				FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
525 				SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
526 				*/
527 				SfxItemSet aDlgAttr(GetPool(),
528 									EE_ITEMS_START, EE_ITEMS_END,
529 									SID_ATTR_PARA_HYPHENZONE, SID_ATTR_PARA_HYPHENZONE,
530 									SID_ATTR_PARA_SPLIT, SID_ATTR_PARA_SPLIT,
531 									SID_ATTR_PARA_WIDOWS, SID_ATTR_PARA_WIDOWS,
532 									SID_ATTR_PARA_ORPHANS, SID_ATTR_PARA_ORPHANS,
533 									0);
534 
535 				aDlgAttr.Put(aEditAttr);
536 
537 
538                 aDlgAttr.Put( SvxHyphenZoneItem( sal_False, RES_PARATR_HYPHENZONE) );
539                 aDlgAttr.Put( SvxFmtBreakItem( SVX_BREAK_NONE, RES_BREAK ) );
540                 aDlgAttr.Put( SvxFmtSplitItem( sal_True, RES_PARATR_SPLIT ) );
541                 aDlgAttr.Put( SvxWidowsItem( 0, RES_PARATR_WIDOWS ) );
542                 aDlgAttr.Put( SvxOrphansItem( 0, RES_PARATR_ORPHANS ) );
543 
544 				//CHINA001 SwParaDlg* pDlg = new SwParaDlg(GetView().GetWindow(), GetView(), aDlgAttr, DLG_STD, 0, sal_True);
545 
546 				SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();//CHINA001
547 				DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");//CHINA001
548 
549 				SfxAbstractTabDialog* pDlg = pFact->CreateSwParaDlg( rView.GetWindow(), rView, aDlgAttr,DLG_STD, DLG_PARA, 0, sal_True );
550 				DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
551 				sal_uInt16 nRet = pDlg->Execute();
552 				if(RET_OK == nRet)
553                 {
554                     rReq.Done( *( pDlg->GetOutputItemSet() ) );
555                     aNewAttr.Put(*pDlg->GetOutputItemSet());
556                 }
557 				delete( pDlg );
558 				if(RET_OK != nRet)
559 					return;
560 			}
561 			else
562 				aNewAttr.Put(*pArgs);
563 			break;
564 		}
565 
566 		case SID_AUTOSPELL_CHECK:
567 		{
568 			rView.ExecuteSlot(rReq);
569 			break;
570 		}
571 		case SID_ATTR_PARA_LEFT_TO_RIGHT:
572         case SID_ATTR_PARA_RIGHT_TO_LEFT:
573         {
574             sal_Bool bLeftToRight = nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT;
575 
576             const SfxPoolItem* pPoolItem;
577             if( pNewAttrs && SFX_ITEM_SET == pNewAttrs->GetItemState( nSlot, sal_True, &pPoolItem ) )
578             {
579                 if( !( (SfxBoolItem*)pPoolItem)->GetValue() )
580                     bLeftToRight = !bLeftToRight;
581             }
582             SfxItemSet aAttr( *aNewAttr.GetPool(),
583                         EE_PARA_JUST, EE_PARA_JUST,
584                         EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
585                         0 );
586 
587             sal_uInt16 nAdjust = SVX_ADJUST_LEFT;
588             if( SFX_ITEM_ON == aEditAttr.GetItemState(EE_PARA_JUST, sal_True, &pPoolItem ) )
589                 nAdjust = ( (SvxAdjustItem*)pPoolItem)->GetEnumValue();
590 
591             if( bLeftToRight )
592             {
593                 aAttr.Put( SvxFrameDirectionItem( FRMDIR_HORI_LEFT_TOP, EE_PARA_WRITINGDIR ) );
594                 if( nAdjust == SVX_ADJUST_RIGHT )
595                     aAttr.Put( SvxAdjustItem( SVX_ADJUST_LEFT, EE_PARA_JUST ) );
596             }
597             else
598             {
599                 aAttr.Put( SvxFrameDirectionItem( FRMDIR_HORI_RIGHT_TOP, EE_PARA_WRITINGDIR ) );
600                 if( nAdjust == SVX_ADJUST_LEFT )
601                     aAttr.Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
602             }
603             pOLV->SetAttribs(aAttr);
604 			break;
605         }
606 	}
607 
608     if(nEEWhich && pNewAttrs)
609         aNewAttr.Put(pNewAttrs->Get(nWhich), nEEWhich);
610 
611 	Rectangle aNullRect;
612     Rectangle aOutRect = pOLV->GetOutputArea();
613 	if (aNullRect != aOutRect)
614 		pOLV->SetAttribs(aNewAttr);
615 
616 	rView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
617 	if ( pOLV->GetOutliner()->IsModified() )
618 		rView.GetWrtShell().SetModified();
619 
620 }
621 
GetState(SfxItemSet & rSet)622 void SwAnnotationShell::GetState(SfxItemSet& rSet)
623 {
624 	//TODO: clean this up!!!
625 	// FN_SET_SUPER_SCRIPT
626 	//SID_ATTR_PARA_ADJUST
627 	//SID_ATTR_PARA_ADJUST_BLOCK
628 
629 	SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
630     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
631 		return;
632 
633     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
634 	SfxItemSet aEditAttr(pOLV->GetAttribs());
635 
636 	SfxWhichIter aIter(rSet);
637 	sal_uInt16 nWhich = aIter.FirstWhich();
638     while(nWhich)
639 	{
640         sal_uInt16 nEEWhich = 0;
641         sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
642 		switch( nSlotId )
643 		{
644 			case SID_ATTR_PARA_LRSPACE:
645 			{
646 				SfxItemState eState = aEditAttr.GetItemState( EE_PARA_LRSPACE );
647 				if( eState >= SFX_ITEM_DEFAULT )
648 				{
649 					SvxLRSpaceItem aLR = ( (const SvxLRSpaceItem&) aEditAttr.Get( EE_PARA_LRSPACE ) );
650 					aLR.SetWhich(SID_ATTR_PARA_LRSPACE);
651 					rSet.Put(aLR);
652 				}
653 				else
654 					rSet.InvalidateItem(nSlotId);
655 			}
656 			break;
657 			case SID_ATTR_PARA_LINESPACE:
658 			{
659 				SfxItemState eState = aEditAttr.GetItemState( EE_PARA_SBL );
660 				if( eState >= SFX_ITEM_DEFAULT )
661 				{
662 					SvxLineSpacingItem aLR = ( (const SvxLineSpacingItem&) aEditAttr.Get( EE_PARA_SBL ) );
663 					rSet.Put(aLR);
664 				}
665 				else
666 					rSet.InvalidateItem(nSlotId);
667 			}
668 			break;
669 			case SID_ATTR_PARA_ULSPACE:
670 				{
671 					SfxItemState eState = aEditAttr.GetItemState( EE_PARA_ULSPACE );
672 					if( eState >= SFX_ITEM_DEFAULT )
673 					{
674 						SvxULSpaceItem aULSpace = (const SvxULSpaceItem&) aEditAttr.Get( EE_PARA_ULSPACE );
675 						aULSpace.SetWhich(SID_ATTR_PARA_ULSPACE);
676 						rSet.Put(aULSpace);
677 					}
678 					else
679 						rSet.InvalidateItem(nSlotId);
680 				}
681             		break;
682 			case SID_ATTR_CHAR_FONT:
683 			case SID_ATTR_CHAR_FONTHEIGHT:
684 			case SID_ATTR_CHAR_WEIGHT:
685 			case SID_ATTR_CHAR_POSTURE:
686 				{
687 					if ( pOLV )
688 					{
689 						sal_uInt16 nScriptType = pOLV->GetSelectedScriptType();
690 						SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
691 						if( !pSecondPool )
692 							pSecondPool = aEditAttr.GetPool();
693 						SvxScriptSetItem aSetItem( nSlotId, *pSecondPool );
694 						aSetItem.GetItemSet().Put( aEditAttr, sal_False );
695 						const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
696 						if( pI )
697 							rSet.Put( *pI, nWhich );
698 						else
699 							rSet.InvalidateItem( nWhich );
700 					}
701 					else
702 						rSet.InvalidateItem( nWhich );
703 				}
704 				break;
705             case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
706             case SID_ATTR_CHAR_UNDERLINE: nEEWhich = EE_CHAR_UNDERLINE;break;
707             case SID_ATTR_CHAR_OVERLINE: nEEWhich = EE_CHAR_OVERLINE;break;
708             case SID_ATTR_CHAR_CONTOUR:	nEEWhich = EE_CHAR_OUTLINE; break;
709             case SID_ATTR_CHAR_SHADOWED:  nEEWhich = EE_CHAR_SHADOW;break;
710             case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT;break;
711 			case SID_ATTR_CHAR_LANGUAGE    : nEEWhich = EE_CHAR_LANGUAGE;break;
712 			case SID_ATTR_CHAR_ESCAPEMENT: nEEWhich = EE_CHAR_ESCAPEMENT;break;
713 			case SID_ATTR_CHAR_KERNING:	 nEEWhich = EE_CHAR_KERNING;break;
714 			case FN_SET_SUPER_SCRIPT:
715 			case FN_SET_SUB_SCRIPT:
716 			{
717 				sal_uInt16 nEsc = 0;
718 				const SfxPoolItem *pEscItem = 0;
719 				if (nWhich==FN_SET_SUPER_SCRIPT)
720 					nEsc = SVX_ESCAPEMENT_SUPERSCRIPT;
721 				else
722 					nEsc = SVX_ESCAPEMENT_SUBSCRIPT;
723 
724 				if( !pEscItem )
725 					pEscItem = &aEditAttr.Get( EE_CHAR_ESCAPEMENT );
726 
727 				if( nEsc == ((const SvxEscapementItem*)pEscItem)->GetEnumValue() )
728 					rSet.Put( SfxBoolItem( nWhich, sal_True ));
729 				else
730 					rSet.InvalidateItem( nWhich );
731 				break;
732 			}
733 			case SID_ATTR_PARA_ADJUST_LEFT:
734 			case SID_ATTR_PARA_ADJUST_RIGHT:
735 			case SID_ATTR_PARA_ADJUST_CENTER:
736 			case SID_ATTR_PARA_ADJUST_BLOCK:
737 				{
738 					const SfxPoolItem *pAdjust = 0;
739 					int eAdjust = 0;
740 
741 					if (nWhich==SID_ATTR_PARA_ADJUST_LEFT)
742 						eAdjust = SVX_ADJUST_LEFT;
743 					else
744 					if (nWhich==SID_ATTR_PARA_ADJUST_RIGHT)
745 						eAdjust = SVX_ADJUST_RIGHT;
746 					else
747 					if (nWhich==SID_ATTR_PARA_ADJUST_CENTER)
748 						eAdjust = SVX_ADJUST_CENTER;
749 					else
750 					if (nWhich==SID_ATTR_PARA_ADJUST_BLOCK)
751 						eAdjust = SVX_ADJUST_BLOCK;
752 
753 					if( !pAdjust )
754 						aEditAttr.GetItemState( EE_PARA_JUST, sal_False, &pAdjust);
755 
756 					if( !pAdjust || IsInvalidItem( pAdjust ))
757 						rSet.InvalidateItem( nSlotId ), nSlotId = 0;
758 					else
759 					{
760 						if ( eAdjust == ((const SvxAdjustItem*)pAdjust)->GetAdjust())
761 							rSet.Put( SfxBoolItem( nWhich, sal_True ));
762 						else
763 							rSet.InvalidateItem( nWhich );
764 					}
765 					break;
766 				}
767 			case SID_ATTR_PARA_LINESPACE_10:
768 			case SID_ATTR_PARA_LINESPACE_15:
769 			case SID_ATTR_PARA_LINESPACE_20:
770 				{
771 					const SfxPoolItem *pLSpace = 0;
772 					int nLSpace = 0;
773 
774 					if (nWhich==SID_ATTR_PARA_LINESPACE_10)
775 						nLSpace = 100;
776 					else
777 					if (nWhich==SID_ATTR_PARA_LINESPACE_15)
778 						nLSpace = 150;
779 					else
780 					if (nWhich==SID_ATTR_PARA_LINESPACE_20)
781 						nLSpace = 200;
782 
783 					if( !pLSpace )
784 						aEditAttr.GetItemState( EE_PARA_SBL, sal_False, &pLSpace );
785 
786 					if( !pLSpace || IsInvalidItem( pLSpace ))
787 						rSet.InvalidateItem( nSlotId ), nSlotId = 0;
788 					else
789 					{
790 						if( nLSpace == ((const SvxLineSpacingItem*)pLSpace)->GetPropLineSpace() )
791 							rSet.Put( SfxBoolItem( nWhich, sal_True ));
792 						else
793 							rSet.InvalidateItem( nWhich );
794 					}
795 					break;
796 				}
797             case SID_AUTOSPELL_CHECK:
798             {
799 				const SfxPoolItem* pState = rView.GetSlotState(nWhich);
800                 if (pState)
801                     rSet.Put(SfxBoolItem(nWhich, ((const SfxBoolItem*)pState)->GetValue()));
802                 else
803                     rSet.DisableItem( nWhich );
804                 break;
805             }
806 			case SID_ATTR_PARA_LEFT_TO_RIGHT:
807 			case SID_ATTR_PARA_RIGHT_TO_LEFT:
808 			{
809 				if ( !SvtLanguageOptions().IsCTLFontEnabled() )
810 					rSet.DisableItem( nWhich );
811 				else
812 				{
813 					if(pOLV->GetOutliner() && pOLV->GetOutliner()->IsVertical())
814 						rSet.DisableItem( nWhich );
815 					else
816 					{
817 						sal_Bool bFlag = sal_False;
818 						switch( ( ( (SvxFrameDirectionItem&) aEditAttr.Get( EE_PARA_WRITINGDIR ) ) ).GetValue() )
819 						{
820 							case FRMDIR_HORI_LEFT_TOP:
821 							{
822 								bFlag = nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT;
823 								rSet.Put( SfxBoolItem( nWhich, bFlag ));
824 								break;
825 							}
826 							case FRMDIR_HORI_RIGHT_TOP:
827 							{
828 								bFlag = nWhich != SID_ATTR_PARA_LEFT_TO_RIGHT;
829 								rSet.Put( SfxBoolItem( nWhich, bFlag ));
830 								break;
831 							}
832 						}
833 					}
834 				}
835 			}
836 			break;
837 			case SID_INSERT_RLM :
838             case SID_INSERT_LRM :
839             case SID_INSERT_ZWNBSP :
840             case SID_INSERT_ZWSP:
841             {
842                 SvtCTLOptions aCTLOptions;
843                 sal_Bool bEnabled = aCTLOptions.IsCTLFontEnabled();
844                 rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, bEnabled );
845                 if(!bEnabled)
846                     rSet.DisableItem(nWhich);
847             }
848             break;
849 			default:
850 				rSet.InvalidateItem( nWhich );
851 				break;
852 		}
853 
854         if(nEEWhich)
855         {
856             rSet.Put(aEditAttr.Get(nEEWhich, sal_True), nWhich);
857 		if(nEEWhich == EE_CHAR_KERNING)
858 		{
859 			SfxItemState eState = aEditAttr.GetItemState( EE_CHAR_KERNING, sal_True );
860 			if ( eState == SFX_ITEM_DONTCARE )
861 			{
862 				rSet.InvalidateItem(EE_CHAR_KERNING);
863 			}
864 		}
865         }
866 
867         if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
868 			rSet.DisableItem( nWhich );
869 
870 		nWhich = aIter.NextWhich();
871 	}
872 }
873 
ExecSearch(SfxRequest & rReq,sal_Bool bNoMessage)874 void SwAnnotationShell::ExecSearch(SfxRequest& rReq, sal_Bool bNoMessage)
875 {
876 	rView.ExecSearch(rReq,bNoMessage);
877 }
878 
StateSearch(SfxItemSet & rSet)879 void SwAnnotationShell::StateSearch(SfxItemSet &rSet)
880 {
881 	rView.StateSearch(rSet);
882 }
883 
ExecClpbrd(SfxRequest & rReq)884 void SwAnnotationShell::ExecClpbrd(SfxRequest &rReq)
885 {
886 	SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
887     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
888 		return;
889 
890     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
891     SfxItemSet aEditAttr(pOLV->GetAttribs());
892 	SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
893 
894     long aOldHeight = pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight();
895 	sal_uInt16 nSlot = rReq.GetSlot();
896 	switch (nSlot)
897 	{
898 		case SID_CUT:
899             if ( (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED) && pOLV->HasSelection() )
900 				pOLV->Cut();
901 			break;
902 		case SID_COPY:
903 			if( pOLV->HasSelection() )
904 				pOLV->Copy();
905 			break;
906 		case SID_PASTE:
907             if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
908 				pOLV->Paste();
909 			break;
910         case SID_PASTE_SPECIAL:
911 		{
912             if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
913 			{
914 				SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
915 				SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( &rView.GetEditWin() );
916 
917 				pDlg->Insert( SOT_FORMAT_STRING, aEmptyStr );
918 				pDlg->Insert( SOT_FORMAT_RTF,	 aEmptyStr );
919 
920 				TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &rView.GetEditWin() ) );
921 
922 				sal_uLong nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
923 
924 				if (nFormat > 0)
925 				{
926 					if (nFormat == SOT_FORMAT_STRING)
927 						pOLV->Paste();
928 					else
929 						pOLV->PasteSpecial();
930 				}
931 				delete pDlg;
932 			}
933 			break;
934 		}
935 		case SID_CLIPBOARD_FORMAT_ITEMS:
936 		{
937 			sal_uLong nFormat = 0;
938 			const SfxPoolItem* pItem;
939 			if ( rReq.GetArgs() && rReq.GetArgs()->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET &&
940 									pItem->ISA(SfxUInt32Item) )
941 			{
942 				nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
943 			}
944 
945 			if ( nFormat )
946 			{
947 				if (SOT_FORMAT_STRING == nFormat)
948 					pOLV->Paste();
949 				else
950 					pOLV->PasteSpecial();
951 			}
952 			break;
953 		}
954 	}
955     pPostItMgr->GetActiveSidebarWin()->ResizeIfNeccessary(aOldHeight,pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight());
956 }
957 
StateClpbrd(SfxItemSet & rSet)958 void SwAnnotationShell::StateClpbrd(SfxItemSet &rSet)
959 {
960 	SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
961     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
962 		return;
963     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
964 
965 	TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &rView.GetEditWin() ) );
966 	bool bPastePossible = ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) || aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
967     bPastePossible = bPastePossible &&  (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED);
968 
969 	SfxWhichIter aIter(rSet);
970 	sal_uInt16 nWhich = aIter.FirstWhich();
971 
972 	while(nWhich)
973 	{
974 		switch(nWhich)
975 		{
976 			case SID_CUT:
977 			{
978                 if ( (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED) || !pOLV->HasSelection() )
979 					rSet.DisableItem( nWhich );
980 			}
981 			case SID_COPY:
982 			{
983 				if( !pOLV->HasSelection() )
984 					rSet.DisableItem( nWhich );
985 				break;
986 			}
987 			case SID_PASTE:
988             case SID_PASTE_SPECIAL:
989 				{
990 					if( !bPastePossible )
991 						rSet.DisableItem( nWhich );
992 					break;
993 				}
994 			case SID_CLIPBOARD_FORMAT_ITEMS:
995 				{
996 					if ( bPastePossible )
997 					{
998 						SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
999 						if ( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
1000 							aFormats.AddClipbrdFormat( SOT_FORMAT_RTF );
1001 						//if ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) )
1002 							aFormats.AddClipbrdFormat( SOT_FORMAT_STRING );
1003 						rSet.Put( aFormats );
1004 					}
1005 					else
1006 						rSet.DisableItem( nWhich );
1007 					break;
1008 				}
1009 		}
1010 		nWhich = aIter.NextWhich();
1011 	}
1012 }
1013 
StateStatusLine(SfxItemSet & rSet)1014 void SwAnnotationShell::StateStatusLine(SfxItemSet &rSet)
1015 {
1016 	SfxWhichIter aIter( rSet );
1017 	sal_uInt16 nWhich = aIter.FirstWhich();
1018 
1019 	while( nWhich )
1020 	{
1021 		switch( nWhich )
1022 		{
1023 			case FN_STAT_SELMODE:
1024 			{
1025 				rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 0));
1026 				rSet.DisableItem( nWhich );
1027 				break;
1028 			}
1029 			case FN_STAT_TEMPLATE:
1030 			{
1031 				rSet.DisableItem( nWhich );
1032 				break;
1033 			}
1034 		}
1035 		nWhich = aIter.NextWhich();
1036 	}
1037 }
1038 
StateInsert(SfxItemSet & rSet)1039 void SwAnnotationShell::StateInsert(SfxItemSet &rSet)
1040 {
1041 	SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1042     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1043 		return;
1044 
1045     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1046     SfxWhichIter aIter(rSet);
1047 	sal_uInt16 nWhich = aIter.FirstWhich();
1048 
1049 	while(nWhich)
1050 	{
1051 		switch(nWhich)
1052 		{
1053 			case SID_HYPERLINK_GETLINK:
1054 				{
1055 					SvxHyperlinkItem aHLinkItem;
1056 					aHLinkItem.SetInsertMode(HLINK_FIELD);
1057 
1058 					const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
1059 
1060 					if (pFieldItem)
1061 					{
1062 						const SvxFieldData* pField = pFieldItem->GetField();
1063 
1064 						if (pField->ISA(SvxURLField))
1065 						{
1066 							aHLinkItem.SetName(((const SvxURLField*) pField)->GetRepresentation());
1067 							aHLinkItem.SetURL(((const SvxURLField*) pField)->GetURL());
1068 							aHLinkItem.SetTargetFrame(((const SvxURLField*) pField)->GetTargetFrame());
1069 						}
1070 					}
1071 					else
1072 					{
1073 						String sSel(pOLV->GetSelected());
1074 						sSel.Erase(255);
1075 						sSel.EraseTrailingChars();
1076 						aHLinkItem.SetName(sSel);
1077 					}
1078 
1079 					sal_uInt16 nHtmlMode = ::GetHtmlMode(rView.GetDocShell());
1080 					aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
1081 						((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
1082 
1083 					rSet.Put(aHLinkItem);
1084 				}
1085 				break;
1086 		}
1087 
1088         if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1089 			rSet.DisableItem( nWhich );
1090 
1091 		nWhich = aIter.NextWhich();
1092 	}
1093 }
1094 
1095 
NoteExec(SfxRequest & rReq)1096 void SwAnnotationShell::NoteExec(SfxRequest &rReq)
1097 {
1098     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1099     if ( !pPostItMgr )
1100         return;
1101 
1102     sal_uInt16 nSlot = rReq.GetSlot();
1103     switch (nSlot)
1104     {
1105     case FN_REPLY:
1106     case FN_POSTIT:
1107     case FN_DELETE_COMMENT:
1108         if ( pPostItMgr->HasActiveSidebarWin() )
1109             pPostItMgr->GetActiveSidebarWin()->ExecuteCommand(nSlot);
1110         break;
1111 
1112     case FN_DELETE_ALL_NOTES:
1113 			pPostItMgr->Delete();
1114 			break;
1115 		case FN_DELETE_NOTE_AUTHOR:
1116 		{
1117 			SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, nSlot, sal_False);
1118 			if ( pItem )
1119 				pPostItMgr->Delete( pItem->GetValue() );
1120 			break;
1121 		}
1122 		case FN_HIDE_NOTE:
1123 			/*
1124             if ( Mgr()->GetActiveSidebarWin() == this )
1125             {
1126                 Mgr()->SetActivePostIt(0);
1127                 // put the cursor back into the document
1128                 SwitchToFieldPos();
1129             }
1130             Mgr()->Hide(mpFld);
1131 			*/
1132 			break;
1133 		case FN_HIDE_ALL_NOTES:
1134 			pPostItMgr->Hide();
1135 			break;
1136 		case FN_HIDE_NOTE_AUTHOR:
1137 		{
1138 			SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, nSlot, sal_False);
1139 			if ( pItem )
1140 				pPostItMgr->Hide( pItem->GetValue() );
1141 		}
1142 	}
1143 }
1144 
GetNoteState(SfxItemSet & rSet)1145 void SwAnnotationShell::GetNoteState(SfxItemSet &rSet)
1146 {
1147     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1148     SfxWhichIter aIter(rSet);
1149     sal_uInt16 nWhich = aIter.FirstWhich();
1150     while(nWhich)
1151     {
1152         sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
1153         switch( nSlotId )
1154         {
1155         case FN_POSTIT:
1156         case FN_DELETE_NOTE_AUTHOR:
1157         case FN_DELETE_ALL_NOTES:
1158         case FN_HIDE_NOTE:
1159         case FN_HIDE_NOTE_AUTHOR:
1160         case FN_HIDE_ALL_NOTES:
1161         case FN_DELETE_COMMENT:
1162             {
1163                 if( !pPostItMgr
1164                     || !pPostItMgr->HasActiveAnnotationWin() )
1165                 {
1166                     rSet.DisableItem(nWhich);
1167                 }
1168                 break;
1169             }
1170 
1171         case FN_REPLY:
1172             {
1173                 if ( !pPostItMgr ||
1174                      !pPostItMgr->HasActiveAnnotationWin() )
1175                 {
1176 					rSet.DisableItem(nWhich);
1177                 }
1178 				else
1179 				{
1180 					SvtUserOptions aUserOpt;
1181 					String sAuthor;
1182 					if( !(sAuthor = aUserOpt.GetFullName()).Len())
1183 							if( !(sAuthor = aUserOpt.GetID()).Len() )
1184 						sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR ));
1185                     if (sAuthor == pPostItMgr->GetActiveSidebarWin()->GetAuthor())
1186 						rSet.DisableItem(nWhich);
1187 				}
1188 				break;
1189 			}
1190 			default:
1191 				rSet.InvalidateItem( nWhich );
1192 				break;
1193 		}
1194 
1195         if (pPostItMgr->HasActiveSidebarWin())
1196 		{
1197             if ( (pPostItMgr->GetActiveSidebarWin()->IsProtected()) &&
1198                     ( (nSlotId==FN_DELETE_COMMENT) || (nSlotId==FN_REPLY) ) )
1199 				rSet.DisableItem( nWhich );
1200 		}
1201 		nWhich = aIter.NextWhich();
1202 	}
1203 }
1204 
ExecLingu(SfxRequest & rReq)1205 void SwAnnotationShell::ExecLingu(SfxRequest &rReq)
1206 {
1207 	SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1208     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1209 		return;
1210 
1211     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1212 	SfxItemSet aEditAttr(pOLV->GetAttribs());
1213 	sal_uInt16 nSlot = rReq.GetSlot();
1214 	SwWrtShell &rSh = rView.GetWrtShell();
1215 	bool bRestoreSelection = false;
1216 	ESelection aOldSelection;
1217 
1218 	switch (nSlot)
1219 	{
1220 		case SID_LANGUAGE_STATUS:
1221         {
1222 			aOldSelection = pOLV->GetSelection();
1223 			if (!pOLV->GetEditView().HasSelection())
1224 			{
1225 				bRestoreSelection	= true;
1226 				pOLV->GetEditView().SelectCurrentWord();
1227 			}
1228 
1229 			bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,rView,rSh);
1230 			break;
1231 		}
1232         case SID_THES:
1233         {
1234             String aReplaceText;
1235             SFX_REQUEST_ARG( rReq, pItem2, SfxStringItem, SID_THES, sal_False );
1236             if (pItem2)
1237                 aReplaceText = pItem2->GetValue();
1238             if (aReplaceText.Len() > 0)
1239                 ReplaceTextWithSynonym( pOLV->GetEditView(), aReplaceText );
1240             break;
1241         }
1242         case SID_THESAURUS:
1243 		{
1244             pOLV->StartThesaurus();
1245 			break;
1246 		}
1247 		case SID_HANGUL_HANJA_CONVERSION:
1248             pOLV->StartTextConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, NULL,
1249                     i18n::TextConversionOption::CHARACTER_BY_CHARACTER, sal_True, sal_False );
1250             break;
1251 
1252         case SID_CHINESE_CONVERSION:
1253 		{
1254                 //open ChineseTranslationDialog
1255                 Reference< XComponentContext > xContext(
1256                     ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1257                 if(xContext.is())
1258                 {
1259                     Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1260                     if(xMCF.is())
1261                     {
1262                         Reference< ui::dialogs::XExecutableDialog > xDialog(
1263                                 xMCF->createInstanceWithContext(
1264                                     rtl::OUString::createFromAscii("com.sun.star.linguistic2.ChineseTranslationDialog")
1265                                     , xContext), UNO_QUERY);
1266                         Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1267                         if( xInit.is() )
1268                         {
1269                             //  initialize dialog
1270                             Reference< awt::XWindow > xDialogParentWindow(0);
1271                             Sequence<Any> aSeq(1);
1272                             Any* pArray = aSeq.getArray();
1273                             PropertyValue aParam;
1274                             aParam.Name = rtl::OUString::createFromAscii("ParentWindow");
1275                             aParam.Value <<= makeAny(xDialogParentWindow);
1276                             pArray[0] <<= makeAny(aParam);
1277                             xInit->initialize( aSeq );
1278 
1279                             //execute dialog
1280                             sal_Int16 nDialogRet = xDialog->execute();
1281                             if( RET_OK == nDialogRet )
1282                             {
1283                                 //get some parameters from the dialog
1284                                 sal_Bool bToSimplified = sal_True;
1285                                 sal_Bool bUseVariants = sal_True;
1286                                 sal_Bool bCommonTerms = sal_True;
1287                                 Reference< beans::XPropertySet >  xProp( xDialog, UNO_QUERY );
1288                                 if( xProp.is() )
1289                                 {
1290                                     try
1291                                     {
1292                                         xProp->getPropertyValue( C2U("IsDirectionToSimplified") ) >>= bToSimplified;
1293                                         xProp->getPropertyValue( C2U("IsUseCharacterVariants") ) >>= bUseVariants;
1294                                         xProp->getPropertyValue( C2U("IsTranslateCommonTerms") ) >>= bCommonTerms;
1295                                     }
1296                                     catch( Exception& )
1297                                     {
1298                                     }
1299                                 }
1300 
1301                                 //execute translation
1302                                 sal_Int16 nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1303                                 sal_Int16 nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1304                                 sal_Int32 nOptions    = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1305                                 if( !bCommonTerms )
1306                                     nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1307 
1308                                 Font aTargetFont = pOLV->GetWindow()->GetDefaultFont( DEFAULTFONT_CJK_TEXT,
1309                                             nTargetLang, DEFAULTFONT_FLAGS_ONLYONE );
1310 
1311                                 pOLV->StartTextConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, sal_False, sal_False );
1312                             }
1313                         }
1314                         Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1315                         if( xComponent.is() )
1316                             xComponent->dispose();
1317                     }
1318                 }
1319             }
1320             break;
1321 	}
1322 
1323 	if (bRestoreSelection)
1324 	{
1325 		// restore selection
1326 		pOLV->GetEditView().SetSelection( aOldSelection );
1327 	}
1328 }
1329 
GetLinguState(SfxItemSet & rSet)1330 void SwAnnotationShell::GetLinguState(SfxItemSet &rSet)
1331 {
1332 	SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1333     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1334 		return;
1335 
1336     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1337 	SfxItemSet aEditAttr(pOLV->GetAttribs());
1338 
1339 	SfxWhichIter aIter(rSet);
1340 	sal_uInt16 nWhich = aIter.FirstWhich();
1341     while(nWhich)
1342 	{
1343 		switch (nWhich)
1344 		{
1345 			case SID_LANGUAGE_STATUS:
1346             {
1347 				SwLangHelper::GetLanguageStatus(pOLV,rSet);
1348 				break;
1349 			}
1350 
1351             case SID_THES:
1352             {
1353                 String          aStatusVal;
1354                 LanguageType    nLang = LANGUAGE_NONE;
1355                 bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, pOLV->GetEditView() );
1356                 rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
1357 
1358                 // disable "Thesaurus" context menu entry if there is nothing to look up
1359                 uno::Reference< linguistic2::XThesaurus >  xThes( ::GetThesaurus() );
1360                 lang::Locale aLocale( SvxCreateLocale( nLang ) );
1361                 if (!bIsLookUpWord ||
1362                     !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( aLocale ))
1363                     rSet.DisableItem( SID_THES );
1364                 break;
1365             }
1366 
1367             // disable "Thesaurus" if the language is not supported
1368             case SID_THESAURUS:
1369 			{
1370 				const SfxPoolItem &rItem = rView.GetWrtShell().GetDoc()->GetDefault(
1371                             GetWhichOfScript( RES_CHRATR_LANGUAGE,
1372                             GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage())) );
1373 				LanguageType nLang = ((const SvxLanguageItem &)
1374 														rItem).GetLanguage();
1375 				uno::Reference< linguistic2::XThesaurus >  xThes( ::GetThesaurus() );
1376 				if (!xThes.is() || nLang == LANGUAGE_NONE ||
1377 					!xThes->hasLocale( SvxCreateLocale( nLang ) ))
1378                     rSet.DisableItem( SID_THESAURUS );
1379 			}
1380 			break;
1381 			case SID_HANGUL_HANJA_CONVERSION:
1382 			case SID_CHINESE_CONVERSION:
1383 			{
1384 				if (!SvtCJKOptions().IsAnyEnabled())
1385 				{
1386 					rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_False );
1387 					rSet.DisableItem(nWhich);
1388 				}
1389 				else
1390 					rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
1391 			}
1392 			break;
1393 		}
1394 
1395         if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1396 			rSet.DisableItem( nWhich );
1397 
1398 		nWhich = aIter.NextWhich();
1399 	}
1400 }
1401 
ExecTransliteration(SfxRequest & rReq)1402 void SwAnnotationShell::ExecTransliteration(SfxRequest &rReq)
1403 {
1404 	SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1405     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1406 		return;
1407 
1408     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1409 
1410 	using namespace ::com::sun::star::i18n;
1411 	{
1412 		sal_uInt32 nMode = 0;
1413 
1414 		switch( rReq.GetSlot() )
1415 		{
1416             case SID_TRANSLITERATE_SENTENCE_CASE:
1417                 nMode = TransliterationModulesExtra::SENTENCE_CASE;
1418                 break;
1419             case SID_TRANSLITERATE_TITLE_CASE:
1420                 nMode = TransliterationModulesExtra::TITLE_CASE;
1421                 break;
1422             case SID_TRANSLITERATE_TOGGLE_CASE:
1423                 nMode = TransliterationModulesExtra::TOGGLE_CASE;
1424                 break;
1425 			case SID_TRANSLITERATE_UPPER:
1426 				nMode = TransliterationModules_LOWERCASE_UPPERCASE;
1427 				break;
1428 			case SID_TRANSLITERATE_LOWER:
1429 				nMode = TransliterationModules_UPPERCASE_LOWERCASE;
1430 				break;
1431 			case SID_TRANSLITERATE_HALFWIDTH:
1432 				nMode = TransliterationModules_FULLWIDTH_HALFWIDTH;
1433 				break;
1434 			case SID_TRANSLITERATE_FULLWIDTH:
1435 				nMode = TransliterationModules_HALFWIDTH_FULLWIDTH;
1436 				break;
1437 			case SID_TRANSLITERATE_HIRAGANA:
1438 				nMode = TransliterationModules_KATAKANA_HIRAGANA;
1439 				break;
1440 			case SID_TRANSLITERATE_KATAGANA:
1441 				nMode = TransliterationModules_HIRAGANA_KATAKANA;
1442 				break;
1443 
1444 			default:
1445 				ASSERT(!this, "falscher Dispatcher");
1446 		}
1447 
1448 		if( nMode )
1449         {
1450             pOLV->TransliterateText( nMode );
1451         }
1452 	}
1453 }
1454 
ExecUndo(SfxRequest & rReq)1455 void SwAnnotationShell::ExecUndo(SfxRequest &rReq)
1456 {
1457 	const SfxItemSet* pArgs = rReq.GetArgs();
1458 	::svl::IUndoManager* pUndoManager = GetUndoManager();
1459 	SwWrtShell &rSh = rView.GetWrtShell();
1460 
1461     long aOldHeight = rView.GetPostItMgr()->HasActiveSidebarWin()
1462                       ? rView.GetPostItMgr()->GetActiveSidebarWin()->GetPostItTextHeight()
1463                       : 0;
1464 
1465 	sal_uInt16 nId = rReq.GetSlot();
1466 	sal_uInt16 nCnt = 1;
1467 	const SfxPoolItem* pItem=0;
1468 	if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nId, sal_False, &pItem ) )
1469 		nCnt = ((SfxUInt16Item*)pItem)->GetValue();
1470 	switch( nId )
1471 	{
1472 		case SID_UNDO:
1473 		{
1474 			if ( pUndoManager )
1475 			{
1476 				sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1477 				sal_uInt16 nSteps = nCnt;
1478 				if ( nCount < nCnt )
1479 				{
1480 					nCnt = nCnt - nCount;
1481 					nSteps = nCount;
1482 				}
1483 				else
1484 					nCnt = 0;
1485 
1486 				while( nSteps-- )
1487 					pUndoManager->Undo();
1488 			}
1489 
1490 			if ( nCnt )
1491 				rSh.Do( SwWrtShell::UNDO, nCnt );
1492 
1493 			break;
1494 		}
1495 
1496 		case SID_REDO:
1497 		{
1498 			if ( pUndoManager )
1499 			{
1500 				sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1501 				sal_uInt16 nSteps = nCnt;
1502 				if ( nCount < nCnt )
1503 				{
1504 					nCnt = nCnt - nCount;
1505 					nSteps = nCount;
1506 				}
1507 				else
1508 					nCnt = 0;
1509 
1510 				while( nSteps-- )
1511                     pUndoManager->Redo();
1512 			}
1513 
1514 			if ( nCnt )
1515 				rSh.Do( SwWrtShell::REDO, nCnt );
1516 
1517 			break;
1518 		}
1519 	}
1520 
1521 	rView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
1522 
1523     if (rView.GetPostItMgr()->HasActiveSidebarWin())
1524         rView.GetPostItMgr()->GetActiveSidebarWin()->ResizeIfNeccessary(aOldHeight,rView.GetPostItMgr()->GetActiveSidebarWin()->GetPostItTextHeight());
1525 }
1526 
StateUndo(SfxItemSet & rSet)1527 void SwAnnotationShell::StateUndo(SfxItemSet &rSet)
1528 {
1529 	SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1530     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1531 		return;
1532 
1533 	SfxWhichIter aIter(rSet);
1534 	sal_uInt16 nWhich = aIter.FirstWhich();
1535 	::svl::IUndoManager* pUndoManager = GetUndoManager();
1536 	SfxViewFrame *pSfxViewFrame = rView.GetViewFrame();
1537 	SwWrtShell &rSh = rView.GetWrtShell();
1538 
1539 	while( nWhich )
1540 	{
1541 		switch ( nWhich )
1542 		{
1543 		case SID_UNDO:
1544 			{
1545 				sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1546 				if ( nCount )
1547 					pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1548                 else if (rSh.GetLastUndoInfo(0, 0))
1549                 {
1550 					rSet.Put( SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::UNDO)) );
1551                 }
1552 				else
1553 					rSet.DisableItem(nWhich);
1554 				break;
1555 			}
1556 		case SID_REDO:
1557 			{
1558 				sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1559 				if ( nCount )
1560 					pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1561                 else if (rSh.GetFirstRedoInfo(0))
1562                 {
1563 					rSet.Put(SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::REDO)) );
1564                 }
1565 				else
1566 					rSet.DisableItem(nWhich);
1567 				break;
1568 			}
1569 		case SID_GETUNDOSTRINGS:
1570 		case SID_GETREDOSTRINGS:
1571 			{
1572 				if( pUndoManager )
1573 				{
1574 					UniString (::svl::IUndoManager:: *fnGetComment)( size_t, bool const ) const;
1575 
1576 					sal_uInt16 nCount;
1577 					if( SID_GETUNDOSTRINGS == nWhich )
1578 					{
1579 						nCount = pUndoManager->GetUndoActionCount();
1580 						fnGetComment = &::svl::IUndoManager::GetUndoActionComment;
1581 					}
1582 					else
1583 					{
1584 						nCount = pUndoManager->GetRedoActionCount();
1585 						fnGetComment = &::svl::IUndoManager::GetRedoActionComment;
1586 					}
1587 
1588 					String sList;
1589 					if( nCount )
1590 					{
1591 						for( sal_uInt16 n = 0; n < nCount; ++n )
1592                             ( sList += (pUndoManager->*fnGetComment)( n, ::svl::IUndoManager::TopLevel ) )
1593 									+= '\n';
1594 					}
1595 
1596 					SfxStringListItem aItem( nWhich );
1597                     if ((nWhich == SID_GETUNDOSTRINGS) &&
1598                         rSh.GetLastUndoInfo(0, 0))
1599                     {
1600 						rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1601                     }
1602                     else if ((nWhich == SID_GETREDOSTRINGS) &&
1603                              (rSh.GetFirstRedoInfo(0)))
1604                     {
1605 						rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1606 					}
1607 
1608 					sList += aItem.GetString();
1609 					aItem.SetString( sList );
1610 					rSet.Put( aItem );
1611 				}
1612 				else
1613 					rSet.DisableItem( nWhich );
1614 			}
1615 			break;
1616 
1617 		default:
1618 			{
1619 				pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1620 				break;
1621 			}
1622 
1623 		}
1624 
1625         if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1626 			rSet.DisableItem( nWhich );
1627 
1628 		nWhich = aIter.NextWhich();
1629 	}
1630 }
1631 
StateDisableItems(SfxItemSet & rSet)1632 void SwAnnotationShell::StateDisableItems( SfxItemSet &rSet )
1633 {
1634 	SfxWhichIter aIter(rSet);
1635 	sal_uInt16 nWhich = aIter.FirstWhich();
1636 	while (nWhich)
1637 	{
1638 		rSet.DisableItem( nWhich );
1639 		nWhich = aIter.NextWhich();
1640 	}
1641 }
1642 
InsertSymbol(SfxRequest & rReq)1643 void SwAnnotationShell::InsertSymbol(SfxRequest& rReq)
1644 {
1645     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1646     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1647 		return;
1648 
1649     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1650 
1651     const SfxItemSet *pArgs = rReq.GetArgs();
1652     const SfxPoolItem* pItem = 0;
1653     if( pArgs )
1654         pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), sal_False, &pItem);
1655 
1656     String sSym;
1657     String sFontName;
1658     if ( pItem )
1659     {
1660         sSym = ((const SfxStringItem*)pItem)->GetValue();
1661         const SfxPoolItem* pFtItem = NULL;
1662         pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), sal_False, &pFtItem);
1663         const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
1664         if ( pFontItem )
1665             sFontName = pFontItem->GetValue();
1666     }
1667 
1668     SfxItemSet aSet(pOLV->GetAttribs());
1669     sal_uInt16 nScript = pOLV->GetSelectedScriptType();
1670     SvxFontItem aSetDlgFont( RES_CHRATR_FONT );
1671     {
1672         SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1673         aSetItem.GetItemSet().Put( aSet, sal_False );
1674         const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1675         if( pI )
1676             aSetDlgFont = *(SvxFontItem*)pI;
1677         else
1678             aSetDlgFont = (SvxFontItem&)aSet.Get( GetWhichOfScript(
1679                         SID_ATTR_CHAR_FONT,
1680                         GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() ) ));
1681 		if (!sFontName.Len())
1682 			sFontName = aSetDlgFont.GetFamilyName();
1683     }
1684 
1685 	Font aFont(sFontName, Size(1,1));
1686     if( !sSym.Len() )
1687     {
1688 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1689 
1690         SfxAllItemSet aAllSet( GetPool() );
1691         aAllSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
1692 
1693         SwViewOption aOpt(*rView.GetWrtShell().GetViewOptions());
1694         String sSymbolFont = aOpt.GetSymbolFont();
1695         if( sSymbolFont.Len() )
1696             aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
1697         else
1698             aAllSet.Put( SfxStringItem( SID_FONT_NAME, aSetDlgFont.GetFamilyName() ) );
1699 
1700         // Wenn Zeichen selektiert ist kann es angezeigt werden
1701         SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( rView.GetWindow(), aAllSet,
1702 			rView.GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
1703 
1704         sal_uInt16 nResult = pDlg->Execute();
1705         if( nResult == RET_OK )
1706         {
1707             SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, sal_False );
1708 			SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False );
1709 			if ( pFontItem )
1710 			{
1711 				aFont.SetName( pFontItem->GetFamilyName() );
1712 				aFont.SetStyleName( pFontItem->GetStyleName() );
1713 				aFont.SetCharSet( pFontItem->GetCharSet() );
1714 				aFont.SetPitch( pFontItem->GetPitch() );
1715 			}
1716 
1717             if ( pCItem )
1718 			{
1719                 sSym  = pCItem->GetValue();
1720 				aOpt.SetSymbolFont(aFont.GetName());
1721 				SW_MOD()->ApplyUsrPref(aOpt, &rView);
1722 			}
1723         }
1724 
1725 		delete( pDlg );
1726     }
1727 
1728     if( sSym.Len() )
1729 	{
1730 		// nicht flackern
1731 		pOLV->HideCursor();
1732         Outliner * pOutliner = pOLV->GetOutliner();
1733         pOutliner->SetUpdateMode(sal_False);
1734 
1735 		SfxItemSet aOldSet( pOLV->GetAttribs() );
1736 		SfxItemSet aFontSet( *aOldSet.GetPool(),
1737 							EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
1738 							EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CJK,
1739 							EE_CHAR_FONTINFO_CTL, EE_CHAR_FONTINFO_CTL,
1740 							0 );
1741 		aFontSet.Set( aOldSet );
1742 
1743 		// String einfuegen
1744         pOLV->InsertText( sSym);
1745 
1746 		// attributieren (Font setzen)
1747 		SfxItemSet aSetFont( *aFontSet.GetPool(), aFontSet.GetRanges() );
1748 		SvxFontItem aFontItem (aFont.GetFamily(),	 aFont.GetName(),
1749 								aFont.GetStyleName(), aFont.GetPitch(),
1750 								aFont.GetCharSet(),
1751 								EE_CHAR_FONTINFO );
1752 		sal_uInt16 nScriptBreak = pBreakIt->GetAllScriptsOfText( sSym );
1753 		if( SCRIPTTYPE_LATIN & nScriptBreak )
1754 			aSetFont.Put( aFontItem, EE_CHAR_FONTINFO );
1755 		if( SCRIPTTYPE_ASIAN & nScriptBreak )
1756 			aSetFont.Put( aFontItem, EE_CHAR_FONTINFO_CJK );
1757 		if( SCRIPTTYPE_COMPLEX & nScriptBreak )
1758 			aSetFont.Put( aFontItem, EE_CHAR_FONTINFO_CTL );
1759 		pOLV->SetAttribs(aSetFont);
1760 
1761 		// Selektion loeschen
1762 		ESelection aSel(pOLV->GetSelection());
1763 		aSel.nStartPara = aSel.nEndPara;
1764 		aSel.nStartPos = aSel.nEndPos;
1765 		pOLV->SetSelection(aSel);
1766 
1767 		// Alten Font restaurieren
1768 		pOLV->SetAttribs( aFontSet );
1769 
1770 		// ab jetzt wieder anzeigen
1771 		pOutliner->SetUpdateMode(sal_True);
1772 		pOLV->ShowCursor();
1773 
1774 		rReq.AppendItem( SfxStringItem( GetPool().GetWhich(SID_CHARMAP), sSym ) );
1775         if(aFont.GetName().Len())
1776             rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aFont.GetName() ) );
1777         rReq.Done();
1778 	}
1779 }
1780