1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sfx2/viewfrm.hxx>
24 #include <editeng/eeitem.hxx>
25 #include <svl/poolitem.hxx>
26 #include <editeng/fontitem.hxx>
27 #include <OutlineView.hxx>
28 #include <OutlineViewShell.hxx>
29 #include <DrawViewShell.hxx>
30 #include <ViewShellBase.hxx>
32 #include <drawdoc.hxx>
33 #include <strings.hrc>
34 #include <sdresid.hxx>
35 #include <svx/svdoutl.hxx>
36 #include <sfx2/request.hxx>
37 #include <svl/ctloptions.hxx>
38 #include <svl/stritem.hxx>
39 #include <tools/debug.hxx>
41 #include <svx/svxdlg.hxx>
42 #include <svx/svxids.hrc>
46 const sal_Unicode CHAR_HARDBLANK
= u
'\x00A0';
47 const sal_Unicode CHAR_HARDHYPHEN
= u
'\x2011';
48 const sal_Unicode CHAR_SOFTHYPHEN
= u
'\x00AD';
49 const sal_Unicode CHAR_RLM
= u
'\x200F';
50 const sal_Unicode CHAR_LRM
= u
'\x200E';
51 const sal_Unicode CHAR_ZWSP
= u
'\x200B';
52 const sal_Unicode CHAR_WJ
= u
'\x2060';
53 const sal_Unicode CHAR_NNBSP
= u
'\x202F'; //NARROW NO-BREAK SPACE
62 : FuPoor(pViewSh
, pWin
, _pView
, pDoc
, rReq
)
66 rtl::Reference
<FuPoor
> FuBullet::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
68 rtl::Reference
<FuPoor
> xFunc( new FuBullet( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
69 xFunc
->DoExecute(rReq
);
73 void FuBullet::DoExecute( SfxRequest
& rReq
)
75 if( rReq
.GetSlot() == SID_CHARMAP
)
76 InsertSpecialCharacter(rReq
);
79 sal_Unicode cMark
= 0;
80 switch( rReq
.GetSlot() )
82 case FN_INSERT_SOFT_HYPHEN
: cMark
= CHAR_SOFTHYPHEN
; break;
83 case FN_INSERT_HARDHYPHEN
: cMark
= CHAR_HARDHYPHEN
; break;
84 case FN_INSERT_HARD_SPACE
: cMark
= CHAR_HARDBLANK
; break;
85 case FN_INSERT_NNBSP
: cMark
= CHAR_NNBSP
; 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_WJ
: cMark
= CHAR_WJ
; break;
92 DBG_ASSERT( cMark
!= 0, "FuBullet::FuBullet(), illegal slot used!" );
95 InsertFormattingMark( cMark
);
100 void FuBullet::InsertFormattingMark( sal_Unicode cMark
)
102 OutlinerView
* pOV
= nullptr;
103 ::Outliner
* pOL
= nullptr;
105 // depending on ViewShell set Outliner and OutlinerView
106 if( dynamic_cast< const DrawViewShell
*>( mpViewShell
) != nullptr)
108 pOV
= mpView
->GetTextEditOutlinerView();
110 pOL
= mpView
->GetTextEditOutliner();
112 else if( dynamic_cast< const OutlineViewShell
*>( mpViewShell
) != nullptr)
114 pOL
= &static_cast<OutlineView
*>(mpView
)->GetOutliner();
115 pOV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
116 mpViewShell
->GetActiveWindow());
123 // prevent flickering
125 pOL
->SetUpdateLayout(false);
127 // remove old selected text
128 pOV
->InsertText( "" );
131 SfxUndoManager
& rUndoMgr
= pOL
->GetUndoManager();
132 rUndoMgr
.EnterListAction(SdResId(STR_UNDO_INSERT_SPECCHAR
),
133 "", 0, mpViewShell
->GetViewShellBase().GetViewShellId() );
136 OUString
aStr( cMark
);
137 pOV
->InsertText( aStr
, true);
139 ESelection aSel
= pOV
->GetSelection();
140 aSel
.nStartPara
= aSel
.nEndPara
;
141 aSel
.nStartPos
= aSel
.nEndPos
;
142 pOV
->SetSelection(aSel
);
144 rUndoMgr
.LeaveListAction();
146 // restart repainting
147 pOL
->SetUpdateLayout(true);
151 void FuBullet::InsertSpecialCharacter( SfxRequest
const & rReq
)
153 const SfxItemSet
*pArgs
= rReq
.GetArgs();
154 const SfxStringItem
* pItem
= nullptr;
156 pItem
= pArgs
->GetItemIfSet(SID_CHARMAP
, false);
162 aChars
= pItem
->GetValue();
163 const SfxStringItem
* pFontItem
= pArgs
->GetItemIfSet( SID_ATTR_SPECIALCHAR
, false );
166 const OUString
& aFontName
= pFontItem
->GetValue();
167 aFont
= vcl::Font( aFontName
, Size(1,1) );
171 SfxItemSet
aFontAttr( mpDoc
->GetPool() );
172 mpView
->GetAttributes( aFontAttr
);
173 const SvxFontItem
* pFItem
= aFontAttr
.GetItem( SID_ATTR_CHAR_FONT
);
175 aFont
= vcl::Font( pFItem
->GetFamilyName(), pFItem
->GetStyleName(), Size( 1, 1 ) );
179 if (aChars
.isEmpty())
181 SfxAllItemSet
aSet( mpDoc
->GetPool() );
182 aSet
.Put( SfxBoolItem( FN_PARAM_1
, false ) );
184 SfxItemSet
aFontAttr( mpDoc
->GetPool() );
185 mpView
->GetAttributes( aFontAttr
);
186 const SvxFontItem
* pFontItem
= aFontAttr
.GetItem( SID_ATTR_CHAR_FONT
);
188 aSet
.Put( *pFontItem
);
190 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
191 auto xFrame
= mpViewShell
? mpViewShell
->GetFrame()->GetFrame().GetFrameInterface() : nullptr;
192 ScopedVclPtr
<SfxAbstractDialog
> pDlg( pFact
->CreateCharMapDialog(mpView
->GetViewShell()->GetFrameWeld(), aSet
,
195 // If a character is selected, it can be shown
202 if (aChars
.isEmpty())
205 OutlinerView
* pOV
= nullptr;
206 ::Outliner
* pOL
= nullptr;
208 // determine depending on ViewShell Outliner and OutlinerView
209 if(dynamic_cast< const DrawViewShell
*>( mpViewShell
))
211 pOV
= mpView
->GetTextEditOutlinerView();
214 pOL
= mpView
->GetTextEditOutliner();
217 else if(dynamic_cast< const OutlineViewShell
*>( mpViewShell
))
219 pOL
= &static_cast<OutlineView
*>(mpView
)->GetOutliner();
220 pOV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
221 mpViewShell
->GetActiveWindow());
224 // insert special character
230 pOL
->SetUpdateLayout(false);
232 /* remember old attributes:
233 To do that, remove selected area before (it has to go anyway).
234 With that, we get unique attributes (and since there is no
235 DeleteSelected() in OutlinerView, it is deleted by inserting an
237 pOV
->InsertText( "" );
239 SfxItemSetFixed
<EE_CHAR_FONTINFO
, EE_CHAR_FONTINFO
> aOldSet( mpDoc
->GetPool() );
240 aOldSet
.Put( pOV
->GetAttribs() );
242 SfxUndoManager
& rUndoMgr
= pOL
->GetUndoManager();
243 ViewShellId nViewShellId
= mpViewShell
? mpViewShell
->GetViewShellBase().GetViewShellId() : ViewShellId(-1);
244 rUndoMgr
.EnterListAction(SdResId(STR_UNDO_INSERT_SPECCHAR
),
245 "", 0, nViewShellId
);
246 pOV
->InsertText(aChars
, true);
248 // set attributes (set font)
249 SfxItemSet
aSet(pOL
->GetEmptyItemSet());
250 SvxFontItem
aFontItem (aFont
.GetFamilyType(), aFont
.GetFamilyName(),
251 aFont
.GetStyleName(), aFont
.GetPitch(),
255 aFontItem
.SetWhich(EE_CHAR_FONTINFO_CJK
);
257 aFontItem
.SetWhich(EE_CHAR_FONTINFO_CTL
);
259 pOV
->SetAttribs(aSet
);
261 ESelection aSel
= pOV
->GetSelection();
262 aSel
.nStartPara
= aSel
.nEndPara
;
263 aSel
.nStartPos
= aSel
.nEndPos
;
264 pOV
->SetSelection(aSel
);
266 // do not go ahead with setting attributes of special characters
267 pOV
->GetOutliner()->QuickSetAttribs(aOldSet
, aSel
);
269 rUndoMgr
.LeaveListAction();
272 pOL
->SetUpdateLayout(true);
276 void FuBullet::GetSlotState( SfxItemSet
& rSet
, ViewShell
const * pViewShell
, SfxViewFrame
* pViewFrame
)
278 if( !(SfxItemState::DEFAULT
== rSet
.GetItemState( SID_CHARMAP
) ||
279 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_CHARMAP_CONTROL
) ||
280 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_SOFT_HYPHEN
) ||
281 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_HARDHYPHEN
) ||
282 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_HARD_SPACE
) ||
283 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_NNBSP
) ||
284 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_RLM
) ||
285 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_LRM
) ||
286 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_WJ
) ||
287 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_ZWSP
)))
290 ::sd::View
* pView
= pViewShell
? pViewShell
->GetView() : nullptr;
291 OutlinerView
* pOLV
= pView
? pView
->GetTextEditOutlinerView() : nullptr;
293 const bool bTextEdit
= pOLV
;
295 const bool bCtlEnabled
= SvtCTLOptions::IsCTLFontEnabled();
299 rSet
.DisableItem(FN_INSERT_SOFT_HYPHEN
);
300 rSet
.DisableItem(FN_INSERT_HARDHYPHEN
);
301 rSet
.DisableItem(FN_INSERT_HARD_SPACE
);
302 rSet
.DisableItem(FN_INSERT_NNBSP
);
303 rSet
.DisableItem(SID_INSERT_WJ
);
304 rSet
.DisableItem(SID_INSERT_ZWSP
);
307 if( !bTextEdit
&& (dynamic_cast<OutlineViewShell
const *>( pViewShell
) == nullptr) )
309 rSet
.DisableItem(SID_CHARMAP
);
310 rSet
.DisableItem(SID_CHARMAP_CONTROL
);
313 if(!bTextEdit
|| !bCtlEnabled
)
315 rSet
.DisableItem(SID_INSERT_RLM
);
316 rSet
.DisableItem(SID_INSERT_LRM
);
321 SfxBindings
& rBindings
= pViewFrame
->GetBindings();
323 rBindings
.SetVisibleState( SID_INSERT_RLM
, bCtlEnabled
);
324 rBindings
.SetVisibleState( SID_INSERT_LRM
, bCtlEnabled
);
327 } // end of namespace sd
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */