bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fubullet.cxx
blob7795cb8ac451a8f684ca129540218be392b329cb
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 .
20 #include "fubullet.hxx"
22 #include <sfx2/bindings.hxx>
23 #include <editeng/eeitem.hxx>
24 #include <svl/poolitem.hxx>
25 #include <editeng/fontitem.hxx>
26 #include "OutlineViewShell.hxx"
27 #include "DrawViewShell.hxx"
28 #include "Window.hxx"
29 #include "drawdoc.hxx"
30 #include "strings.hrc"
31 #include "sdresid.hxx"
32 #include <svx/svdoutl.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <sfx2/request.hxx>
35 #include <svl/ctloptions.hxx>
36 #include <svl/itempool.hxx>
38 #include <svx/svxdlg.hxx>
39 #include <svx/dialogs.hrc>
40 #include "drawview.hxx"
42 #include "app.hrc"
44 namespace sd {
46 const sal_Unicode CHAR_HARDBLANK = ((sal_Unicode)0x00A0);
47 const sal_Unicode CHAR_HARDHYPHEN = ((sal_Unicode)0x2011);
48 const sal_Unicode CHAR_SOFTHYPHEN = ((sal_Unicode)0x00AD);
49 const sal_Unicode CHAR_RLM = ((sal_Unicode)0x200F);
50 const sal_Unicode CHAR_LRM = ((sal_Unicode)0x200E);
51 const sal_Unicode CHAR_ZWSP = ((sal_Unicode)0x200B);
52 const sal_Unicode CHAR_ZWNBSP = ((sal_Unicode)0x2060);
54 TYPEINIT1( FuBullet, FuPoor );
57 FuBullet::FuBullet (
58 ViewShell* pViewSh,
59 ::sd::Window* pWin,
60 ::sd::View* _pView,
61 SdDrawDocument* pDoc,
62 SfxRequest& rReq)
63 : FuPoor(pViewSh, pWin, _pView, pDoc, rReq)
67 FunctionReference FuBullet::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
69 FunctionReference xFunc( new FuBullet( pViewSh, pWin, pView, pDoc, rReq ) );
70 xFunc->DoExecute(rReq);
71 return xFunc;
74 void FuBullet::DoExecute( SfxRequest& rReq )
76 if( rReq.GetSlot() == SID_CHARMAP )
77 InsertSpecialCharacter(rReq);
78 else
80 sal_Unicode cMark = 0;
81 switch( rReq.GetSlot() )
83 case FN_INSERT_SOFT_HYPHEN: cMark = CHAR_SOFTHYPHEN ; break;
84 case FN_INSERT_HARDHYPHEN: cMark = CHAR_HARDHYPHEN ; break;
85 case FN_INSERT_HARD_SPACE: cMark = CHAR_HARDBLANK ; break;
86 case SID_INSERT_RLM : cMark = CHAR_RLM ; break;
87 case SID_INSERT_LRM : cMark = CHAR_LRM ; break;
88 case SID_INSERT_ZWSP : cMark = CHAR_ZWSP ; break;
89 case SID_INSERT_ZWNBSP: cMark = CHAR_ZWNBSP; break;
92 DBG_ASSERT( cMark != 0, "FuBullet::FuBullet(), illegal slot used!" );
94 if( cMark )
95 InsertFormattingMark( cMark );
100 void FuBullet::InsertFormattingMark( sal_Unicode cMark )
102 OutlinerView* pOV = NULL;
103 ::Outliner* pOL = NULL;
105 // depending on ViewShell set Outliner and OutlinerView
106 if (mpViewShell->ISA(DrawViewShell))
108 pOV = mpView->GetTextEditOutlinerView();
109 if (pOV)
110 pOL = mpView->GetTextEditOutliner();
112 else if (mpViewShell->ISA(OutlineViewShell))
114 pOL = static_cast<OutlineView*>(mpView)->GetOutliner();
115 pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
116 mpViewShell->GetActiveWindow());
119 // insert string
120 if(pOV && pOL)
122 // prevent flickering
123 pOV->HideCursor();
124 pOL->SetUpdateMode(sal_False);
126 // remove old selected text
127 pOV->InsertText( aEmptyStr );
129 // prepare undo
130 ::svl::IUndoManager& rUndoMgr = pOL->GetUndoManager();
131 rUndoMgr.EnterListAction(String(SdResId(STR_UNDO_INSERT_SPECCHAR)),
132 aEmptyStr );
134 // insert given text
135 OUString aStr( cMark );
136 pOV->InsertText( aStr, sal_True);
138 ESelection aSel = pOV->GetSelection();
139 aSel.nStartPara = aSel.nEndPara;
140 aSel.nStartPos = aSel.nEndPos;
141 pOV->SetSelection(aSel);
143 rUndoMgr.LeaveListAction();
145 // restart repainting
146 pOL->SetUpdateMode(sal_True);
147 pOV->ShowCursor();
151 void FuBullet::InsertSpecialCharacter( SfxRequest& rReq )
153 const SfxItemSet *pArgs = rReq.GetArgs();
154 const SfxPoolItem* pItem = 0;
155 if( pArgs )
156 pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_CHARMAP), sal_False, &pItem);
158 String aChars, aFontName;
159 Font aFont;
160 if ( pItem )
162 aChars = ((const SfxStringItem*)pItem)->GetValue();
163 const SfxPoolItem* pFtItem = NULL;
164 pArgs->GetItemState( mpDoc->GetPool().GetWhich(SID_ATTR_SPECIALCHAR), sal_False, &pFtItem);
165 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
166 if ( pFontItem )
168 aFontName = pFontItem->GetValue();
169 aFont = Font( aFontName, Size(1,1) );
171 else
173 SfxItemSet aFontAttr( mpDoc->GetPool() );
174 mpView->GetAttributes( aFontAttr );
175 const SvxFontItem* pFItem = (const SvxFontItem*)aFontAttr.GetItem( SID_ATTR_CHAR_FONT );
176 if( pFItem )
177 aFont = Font( pFItem->GetFamilyName(), pFItem->GetStyleName(), Size( 1, 1 ) );
181 if (!aChars.Len() )
183 SfxAllItemSet aSet( mpDoc->GetPool() );
184 aSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
186 SfxItemSet aFontAttr( mpDoc->GetPool() );
187 mpView->GetAttributes( aFontAttr );
188 const SvxFontItem* pFontItem = (const SvxFontItem*)aFontAttr.GetItem( SID_ATTR_CHAR_FONT );
189 if( pFontItem )
190 aSet.Put( *pFontItem );
192 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
193 SfxAbstractDialog* pDlg = pFact ? pFact->CreateSfxDialog( &mpView->GetViewShell()->GetViewFrame()->GetWindow(), aSet,
194 mpView->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface(),
195 RID_SVXDLG_CHARMAP ) : 0;
196 if( !pDlg )
197 return;
199 // If a character is selected, it can be shown
200 // pDLg->SetFont( );
201 // pDlg->SetChar( );
202 sal_uInt16 nResult = pDlg->Execute();
203 if( nResult == RET_OK )
205 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, sal_False );
206 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False );
207 if ( pFItem )
209 aFont.SetName( pFItem->GetFamilyName() );
210 aFont.SetStyleName( pFItem->GetStyleName() );
211 aFont.SetCharSet( pFItem->GetCharSet() );
212 aFont.SetPitch( pFItem->GetPitch() );
215 if ( pCItem )
216 aChars = pCItem->GetValue();
219 delete( pDlg );
222 if( aChars.Len() )
224 OutlinerView* pOV = NULL;
225 ::Outliner* pOL = NULL;
227 // determine depending on ViewShell Outliner and OutlinerView
228 if(mpViewShell && mpViewShell->ISA(DrawViewShell))
230 pOV = mpView->GetTextEditOutlinerView();
231 if (pOV)
233 pOL = mpView->GetTextEditOutliner();
236 else if(mpViewShell && mpViewShell->ISA(OutlineViewShell))
238 pOL = static_cast<OutlineView*>(mpView)->GetOutliner();
239 pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
240 mpViewShell->GetActiveWindow());
243 // insert special character
244 if (pOV)
246 // prevent flicker
247 pOV->HideCursor();
248 pOL->SetUpdateMode(sal_False);
250 /* remember old attributes:
251 To do that, remove selected area before (it has to go anyway).
252 With that, we get unique attributes (and since there is no
253 DeleteSelected() in OutlinerView, it is deleted by inserting an
254 empty string). */
255 pOV->InsertText( aEmptyStr );
257 SfxItemSet aOldSet( mpDoc->GetPool(), EE_CHAR_FONTINFO, EE_CHAR_FONTINFO, 0 );
258 aOldSet.Put( pOV->GetAttribs() );
260 ::svl::IUndoManager& rUndoMgr = pOL->GetUndoManager();
261 rUndoMgr.EnterListAction(String(SdResId(STR_UNDO_INSERT_SPECCHAR)),
262 aEmptyStr );
263 pOV->InsertText(aChars, sal_True);
265 // set attributes (set font)
266 SfxItemSet aSet(pOL->GetEmptyItemSet());
267 SvxFontItem aFontItem (aFont.GetFamily(), aFont.GetName(),
268 aFont.GetStyleName(), aFont.GetPitch(),
269 aFont.GetCharSet(),
270 EE_CHAR_FONTINFO);
271 aSet.Put(aFontItem);
272 aSet.Put(aFontItem, EE_CHAR_FONTINFO_CJK);
273 aSet.Put(aFontItem, EE_CHAR_FONTINFO_CTL);
274 pOV->SetAttribs(aSet);
276 ESelection aSel = pOV->GetSelection();
277 aSel.nStartPara = aSel.nEndPara;
278 aSel.nStartPos = aSel.nEndPos;
279 pOV->SetSelection(aSel);
281 // do not go ahead with setting attributes of special characters
282 pOV->GetOutliner()->QuickSetAttribs(aOldSet, aSel);
284 rUndoMgr.LeaveListAction();
286 // show it again
287 pOL->SetUpdateMode(sal_True);
288 pOV->ShowCursor();
293 void FuBullet::GetSlotState( SfxItemSet& rSet, ViewShell* pViewShell, SfxViewFrame* pViewFrame )
295 if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_CHARMAP ) ||
296 SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_SOFT_HYPHEN ) ||
297 SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_HARDHYPHEN ) ||
298 SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_HARD_SPACE ) ||
299 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_RLM ) ||
300 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_LRM ) ||
301 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_ZWNBSP ) ||
302 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_ZWSP ))
304 ::sd::View* pView = pViewShell ? pViewShell->GetView() : 0;
305 OutlinerView* pOLV = pView ? pView->GetTextEditOutlinerView() : 0;
307 const bool bTextEdit = pOLV;
309 SvtCTLOptions aCTLOptions;
310 const sal_Bool bCtlEnabled = aCTLOptions.IsCTLFontEnabled();
312 if(!bTextEdit )
314 rSet.DisableItem(FN_INSERT_SOFT_HYPHEN);
315 rSet.DisableItem(FN_INSERT_HARDHYPHEN);
316 rSet.DisableItem(FN_INSERT_HARD_SPACE);
319 if( !bTextEdit && (dynamic_cast<OutlineViewShell*>( pViewShell ) == 0) )
320 rSet.DisableItem(SID_CHARMAP);
322 if(!bTextEdit || !bCtlEnabled )
324 rSet.DisableItem(SID_INSERT_RLM);
325 rSet.DisableItem(SID_INSERT_LRM);
326 rSet.DisableItem(SID_INSERT_ZWNBSP);
327 rSet.DisableItem(SID_INSERT_ZWSP);
330 if( pViewFrame )
332 SfxBindings& rBindings = pViewFrame->GetBindings();
334 rBindings.SetVisibleState( SID_INSERT_RLM, bCtlEnabled );
335 rBindings.SetVisibleState( SID_INSERT_LRM, bCtlEnabled );
336 rBindings.SetVisibleState( SID_INSERT_ZWNBSP, bCtlEnabled );
337 rBindings.SetVisibleState( SID_INSERT_ZWSP, bCtlEnabled );
341 } // end of namespace sd
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */