Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fubullet.cxx
blobdb6df94281382874d7e57cf31c6c62b39cb39337
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 <ViewShellBase.hxx>
29 #include <Window.hxx>
30 #include <drawdoc.hxx>
31 #include <strings.hrc>
32 #include <sdresid.hxx>
33 #include <svx/svdoutl.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>
41 #include <memory>
43 #include <app.hrc>
45 namespace sd {
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_ZWNBSP = u'\x2060';
56 FuBullet::FuBullet (
57 ViewShell* pViewSh,
58 ::sd::Window* pWin,
59 ::sd::View* _pView,
60 SdDrawDocument* pDoc,
61 SfxRequest& rReq)
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);
70 return xFunc;
73 void FuBullet::DoExecute( SfxRequest& rReq )
75 if( rReq.GetSlot() == SID_CHARMAP )
76 InsertSpecialCharacter(rReq);
77 else
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 SID_INSERT_RLM : cMark = CHAR_RLM ; break;
86 case SID_INSERT_LRM : cMark = CHAR_LRM ; break;
87 case SID_INSERT_ZWSP : cMark = CHAR_ZWSP ; break;
88 case SID_INSERT_ZWNBSP: cMark = CHAR_ZWNBSP; break;
91 DBG_ASSERT( cMark != 0, "FuBullet::FuBullet(), illegal slot used!" );
93 if( cMark )
94 InsertFormattingMark( cMark );
99 void FuBullet::InsertFormattingMark( sal_Unicode cMark )
101 OutlinerView* pOV = nullptr;
102 ::Outliner* pOL = nullptr;
104 // depending on ViewShell set Outliner and OutlinerView
105 if( dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr)
107 pOV = mpView->GetTextEditOutlinerView();
108 if (pOV)
109 pOL = mpView->GetTextEditOutliner();
111 else if( dynamic_cast< const OutlineViewShell *>( mpViewShell ) != nullptr)
113 pOL = &static_cast<OutlineView*>(mpView)->GetOutliner();
114 pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
115 mpViewShell->GetActiveWindow());
118 // insert string
119 if(pOV && pOL)
121 // prevent flickering
122 pOV->HideCursor();
123 pOL->SetUpdateMode(false);
125 // remove old selected text
126 pOV->InsertText( "" );
128 // prepare undo
129 ::svl::IUndoManager& rUndoMgr = pOL->GetUndoManager();
130 rUndoMgr.EnterListAction(SdResId(STR_UNDO_INSERT_SPECCHAR),
131 "", 0, mpViewShell->GetViewShellBase().GetViewShellId() );
133 // insert given text
134 OUString aStr( cMark );
135 pOV->InsertText( aStr, true);
137 ESelection aSel = pOV->GetSelection();
138 aSel.nStartPara = aSel.nEndPara;
139 aSel.nStartPos = aSel.nEndPos;
140 pOV->SetSelection(aSel);
142 rUndoMgr.LeaveListAction();
144 // restart repainting
145 pOL->SetUpdateMode(true);
146 pOV->ShowCursor();
150 void FuBullet::InsertSpecialCharacter( SfxRequest const & rReq )
152 const SfxItemSet *pArgs = rReq.GetArgs();
153 const SfxPoolItem* pItem = nullptr;
154 if( pArgs )
155 pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_CHARMAP), false, &pItem);
157 OUString aChars;
158 vcl::Font aFont;
159 if ( pItem )
161 aChars = static_cast<const SfxStringItem*>(pItem)->GetValue();
162 const SfxPoolItem* pFtItem = nullptr;
163 pArgs->GetItemState( mpDoc->GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
164 const SfxStringItem* pFontItem = dynamic_cast<const SfxStringItem*>( pFtItem );
165 if ( pFontItem )
167 OUString aFontName = pFontItem->GetValue();
168 aFont = vcl::Font( aFontName, Size(1,1) );
170 else
172 SfxItemSet aFontAttr( mpDoc->GetPool() );
173 mpView->GetAttributes( aFontAttr );
174 const SvxFontItem* pFItem = static_cast<const SvxFontItem*>(aFontAttr.GetItem( SID_ATTR_CHAR_FONT ));
175 if( pFItem )
176 aFont = vcl::Font( pFItem->GetFamilyName(), pFItem->GetStyleName(), Size( 1, 1 ) );
180 if (aChars.isEmpty())
182 SfxAllItemSet aSet( mpDoc->GetPool() );
183 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
185 SfxItemSet aFontAttr( mpDoc->GetPool() );
186 mpView->GetAttributes( aFontAttr );
187 const SvxFontItem* pFontItem = static_cast<const SvxFontItem*>(aFontAttr.GetItem( SID_ATTR_CHAR_FONT ));
188 if( pFontItem )
189 aSet.Put( *pFontItem );
191 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
192 ScopedVclPtr<SfxAbstractDialog> pDlg(pFact ? pFact->CreateCharMapDialog(mpView->GetViewShell()->GetFrameWeld(), aSet,
193 true ) : nullptr);
194 if( !pDlg )
195 return;
197 // If a character is selected, it can be shown
198 // pDLg->SetFont( );
199 // pDlg->SetChar( );
200 pDlg->Execute();
201 return;
204 if (!aChars.isEmpty())
206 OutlinerView* pOV = nullptr;
207 ::Outliner* pOL = nullptr;
209 // determine depending on ViewShell Outliner and OutlinerView
210 if(mpViewShell && dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr)
212 pOV = mpView->GetTextEditOutlinerView();
213 if (pOV)
215 pOL = mpView->GetTextEditOutliner();
218 else if(mpViewShell && dynamic_cast< const OutlineViewShell *>( mpViewShell ) != nullptr)
220 pOL = &static_cast<OutlineView*>(mpView)->GetOutliner();
221 pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
222 mpViewShell->GetActiveWindow());
225 // insert special character
226 if (pOV)
228 // prevent flicker
229 pOV->HideCursor();
230 pOL->SetUpdateMode(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
236 empty string). */
237 pOV->InsertText( "" );
239 SfxItemSet aOldSet( mpDoc->GetPool(), svl::Items<EE_CHAR_FONTINFO, EE_CHAR_FONTINFO>{} );
240 aOldSet.Put( pOV->GetAttribs() );
242 ::svl::IUndoManager& 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(),
252 aFont.GetCharSet(),
253 EE_CHAR_FONTINFO);
254 aSet.Put(aFontItem);
255 aFontItem.SetWhich(EE_CHAR_FONTINFO_CJK);
256 aSet.Put(aFontItem);
257 aFontItem.SetWhich(EE_CHAR_FONTINFO_CTL);
258 aSet.Put(aFontItem);
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();
271 // show it again
272 pOL->SetUpdateMode(true);
273 pOV->ShowCursor();
278 void FuBullet::GetSlotState( SfxItemSet& rSet, ViewShell const * pViewShell, SfxViewFrame* pViewFrame )
280 if( SfxItemState::DEFAULT == rSet.GetItemState( SID_CHARMAP ) ||
281 SfxItemState::DEFAULT == rSet.GetItemState( FN_INSERT_SOFT_HYPHEN ) ||
282 SfxItemState::DEFAULT == rSet.GetItemState( FN_INSERT_HARDHYPHEN ) ||
283 SfxItemState::DEFAULT == rSet.GetItemState( FN_INSERT_HARD_SPACE ) ||
284 SfxItemState::DEFAULT == rSet.GetItemState( SID_INSERT_RLM ) ||
285 SfxItemState::DEFAULT == rSet.GetItemState( SID_INSERT_LRM ) ||
286 SfxItemState::DEFAULT == rSet.GetItemState( SID_INSERT_ZWNBSP ) ||
287 SfxItemState::DEFAULT == rSet.GetItemState( SID_INSERT_ZWSP ))
289 ::sd::View* pView = pViewShell ? pViewShell->GetView() : nullptr;
290 OutlinerView* pOLV = pView ? pView->GetTextEditOutlinerView() : nullptr;
292 const bool bTextEdit = pOLV;
294 SvtCTLOptions aCTLOptions;
295 const bool bCtlEnabled = aCTLOptions.IsCTLFontEnabled();
297 if(!bTextEdit )
299 rSet.DisableItem(FN_INSERT_SOFT_HYPHEN);
300 rSet.DisableItem(FN_INSERT_HARDHYPHEN);
301 rSet.DisableItem(FN_INSERT_HARD_SPACE);
302 rSet.DisableItem(SID_INSERT_ZWNBSP);
303 rSet.DisableItem(SID_INSERT_ZWSP);
306 if( !bTextEdit && (dynamic_cast<OutlineViewShell const *>( pViewShell ) == nullptr) )
307 rSet.DisableItem(SID_CHARMAP);
309 if(!bTextEdit || !bCtlEnabled )
311 rSet.DisableItem(SID_INSERT_RLM);
312 rSet.DisableItem(SID_INSERT_LRM);
315 if( pViewFrame )
317 SfxBindings& rBindings = pViewFrame->GetBindings();
319 rBindings.SetVisibleState( SID_INSERT_RLM, bCtlEnabled );
320 rBindings.SetVisibleState( SID_INSERT_LRM, bCtlEnabled );
324 } // end of namespace sd
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */