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 <editeng/editund2.hxx>
26 #include <svl/poolitem.hxx>
27 #include <editeng/fontitem.hxx>
28 #include <OutlineView.hxx>
29 #include <OutlineViewShell.hxx>
30 #include <DrawViewShell.hxx>
31 #include <ViewShellBase.hxx>
33 #include <drawdoc.hxx>
34 #include <strings.hrc>
35 #include <sdresid.hxx>
36 #include <svx/svdoutl.hxx>
37 #include <sfx2/request.hxx>
38 #include <svl/ctloptions.hxx>
39 #include <svl/stritem.hxx>
40 #include <tools/debug.hxx>
41 #include <Outliner.hxx>
42 #include <svx/svxdlg.hxx>
43 #include <svx/svxids.hrc>
47 const sal_Unicode CHAR_HARDBLANK
= u
'\x00A0';
48 const sal_Unicode CHAR_HARDHYPHEN
= u
'\x2011';
49 const sal_Unicode CHAR_SOFTHYPHEN
= u
'\x00AD';
50 const sal_Unicode CHAR_RLM
= u
'\x200F';
51 const sal_Unicode CHAR_LRM
= u
'\x200E';
52 const sal_Unicode CHAR_ZWSP
= u
'\x200B';
53 const sal_Unicode CHAR_WJ
= u
'\x2060';
54 const sal_Unicode CHAR_NNBSP
= u
'\x202F'; //NARROW NO-BREAK SPACE
63 : FuPoor(pViewSh
, pWin
, _pView
, pDoc
, rReq
)
67 rtl::Reference
<FuPoor
> FuBullet::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
69 rtl::Reference
<FuPoor
> xFunc( new FuBullet( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
70 xFunc
->DoExecute(rReq
);
74 void FuBullet::DoExecute( SfxRequest
& rReq
)
76 if( rReq
.GetSlot() == SID_CHARMAP
)
77 InsertSpecialCharacter(rReq
);
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 FN_INSERT_NNBSP
: cMark
= CHAR_NNBSP
; break;
87 case SID_INSERT_RLM
: cMark
= CHAR_RLM
; break;
88 case SID_INSERT_LRM
: cMark
= CHAR_LRM
; break;
89 case SID_INSERT_ZWSP
: cMark
= CHAR_ZWSP
; break;
90 case SID_INSERT_WJ
: cMark
= CHAR_WJ
; break;
93 DBG_ASSERT( cMark
!= 0, "FuBullet::FuBullet(), illegal slot used!" );
96 InsertFormattingMark( cMark
);
101 void FuBullet::InsertFormattingMark( sal_Unicode cMark
)
103 OutlinerView
* pOV
= nullptr;
104 ::Outliner
* pOL
= nullptr;
106 // depending on ViewShell set Outliner and OutlinerView
107 if( dynamic_cast< const DrawViewShell
*>( mpViewShell
) != nullptr)
109 pOV
= mpView
->GetTextEditOutlinerView();
111 pOL
= mpView
->GetTextEditOutliner();
113 else if( dynamic_cast< const OutlineViewShell
*>( mpViewShell
) != nullptr)
115 pOL
= &static_cast<OutlineView
*>(mpView
)->GetOutliner();
116 pOV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
117 mpViewShell
->GetActiveWindow());
124 // prevent flickering
126 pOL
->SetUpdateLayout(false);
128 // remove old selected text
129 pOV
->InsertText( u
""_ustr
);
132 EditUndoManager
& rUndoMgr
= pOL
->GetUndoManager();
133 rUndoMgr
.EnterListAction(SdResId(STR_UNDO_INSERT_SPECCHAR
),
134 u
""_ustr
, 0, mpViewShell
->GetViewShellBase().GetViewShellId() );
137 OUString
aStr( cMark
);
138 pOV
->InsertText( aStr
, true);
140 ESelection aSel
= pOV
->GetSelection();
141 aSel
.CollapseToEnd();
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 css::uno::Reference
<css::frame::XFrame
> xFrame
;
194 if (SfxViewFrame
* pFrame
= mpViewShell
->GetFrame())
195 xFrame
= pFrame
->GetFrame().GetFrameInterface();
197 VclPtr
<SfxAbstractDialog
> pDlg( pFact
->CreateCharMapDialog(mpView
->GetViewShell()->GetFrameWeld(), aSet
,
200 // If a character is selected, it can be shown
203 pDlg
->StartExecuteAsync(
204 [pDlg
] (sal_Int32
/*nResult*/)->void
212 if (aChars
.isEmpty())
215 OutlinerView
* pOV
= nullptr;
216 ::Outliner
* pOL
= nullptr;
218 // determine depending on ViewShell Outliner and OutlinerView
219 if(dynamic_cast< const DrawViewShell
*>( mpViewShell
))
221 pOV
= mpView
->GetTextEditOutlinerView();
224 pOL
= mpView
->GetTextEditOutliner();
227 else if(dynamic_cast< const OutlineViewShell
*>( mpViewShell
))
229 pOL
= &static_cast<OutlineView
*>(mpView
)->GetOutliner();
230 pOV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
231 mpViewShell
->GetActiveWindow());
234 // insert special character
240 pOL
->SetUpdateLayout(false);
242 /* remember old attributes:
243 To do that, remove selected area before (it has to go anyway).
244 With that, we get unique attributes (and since there is no
245 DeleteSelected() in OutlinerView, it is deleted by inserting an
247 pOV
->InsertText( u
""_ustr
);
249 SfxItemSetFixed
<EE_CHAR_FONTINFO
, EE_CHAR_FONTINFO
> aOldSet( mpDoc
->GetPool() );
250 aOldSet
.Put( pOV
->GetAttribs() );
252 EditUndoManager
& rUndoMgr
= pOL
->GetUndoManager();
253 ViewShellId nViewShellId
= mpViewShell
? mpViewShell
->GetViewShellBase().GetViewShellId() : ViewShellId(-1);
254 rUndoMgr
.EnterListAction(SdResId(STR_UNDO_INSERT_SPECCHAR
),
255 u
""_ustr
, 0, nViewShellId
);
256 pOV
->InsertText(aChars
, true);
258 // set attributes (set font)
259 SfxItemSet
aSet(pOL
->GetEmptyItemSet());
260 SvxFontItem
aFontItem (aFont
.GetFamilyType(), aFont
.GetFamilyName(),
261 aFont
.GetStyleName(), aFont
.GetPitch(),
265 aFontItem
.SetWhich(EE_CHAR_FONTINFO_CJK
);
267 aFontItem
.SetWhich(EE_CHAR_FONTINFO_CTL
);
269 pOV
->SetAttribs(aSet
);
271 ESelection aSel
= pOV
->GetSelection();
272 aSel
.CollapseToEnd();
273 pOV
->SetSelection(aSel
);
275 // do not go ahead with setting attributes of special characters
276 pOV
->GetOutliner()->QuickSetAttribs(aOldSet
, aSel
);
278 rUndoMgr
.LeaveListAction();
281 pOL
->SetUpdateLayout(true);
285 void FuBullet::GetSlotState( SfxItemSet
& rSet
, ViewShell
const * pViewShell
, SfxViewFrame
* pViewFrame
)
287 if( !(SfxItemState::DEFAULT
== rSet
.GetItemState( SID_CHARMAP
) ||
288 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_CHARMAP_CONTROL
) ||
289 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_SOFT_HYPHEN
) ||
290 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_HARDHYPHEN
) ||
291 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_HARD_SPACE
) ||
292 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_NNBSP
) ||
293 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_RLM
) ||
294 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_LRM
) ||
295 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_WJ
) ||
296 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_ZWSP
)))
299 ::sd::View
* pView
= pViewShell
? pViewShell
->GetView() : nullptr;
300 OutlinerView
* pOLV
= pView
? pView
->GetTextEditOutlinerView() : nullptr;
302 const bool bTextEdit
= pOLV
;
304 const bool bCtlEnabled
= SvtCTLOptions::IsCTLFontEnabled();
308 rSet
.DisableItem(FN_INSERT_SOFT_HYPHEN
);
309 rSet
.DisableItem(FN_INSERT_HARDHYPHEN
);
310 rSet
.DisableItem(FN_INSERT_HARD_SPACE
);
311 rSet
.DisableItem(FN_INSERT_NNBSP
);
312 rSet
.DisableItem(SID_INSERT_WJ
);
313 rSet
.DisableItem(SID_INSERT_ZWSP
);
316 if( !bTextEdit
&& (dynamic_cast<OutlineViewShell
const *>( pViewShell
) == nullptr) )
318 rSet
.DisableItem(SID_CHARMAP
);
319 rSet
.DisableItem(SID_CHARMAP_CONTROL
);
322 if(!bTextEdit
|| !bCtlEnabled
)
324 rSet
.DisableItem(SID_INSERT_RLM
);
325 rSet
.DisableItem(SID_INSERT_LRM
);
330 SfxBindings
& rBindings
= pViewFrame
->GetBindings();
332 rBindings
.SetVisibleState( SID_INSERT_RLM
, bCtlEnabled
);
333 rBindings
.SetVisibleState( SID_INSERT_LRM
, bCtlEnabled
);
336 } // end of namespace sd
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */