tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sd / source / ui / func / fubullet.cxx
blobba2e1d71cc504133ef72f4e001a34b0077f63024
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 <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>
32 #include <Window.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>
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_WJ = u'\x2060';
54 const sal_Unicode CHAR_NNBSP = u'\x202F'; //NARROW NO-BREAK SPACE
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 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);
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 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!" );
95 if( cMark )
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();
110 if (pOV)
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());
120 // insert string
121 if(!(pOV && pOL))
122 return;
124 // prevent flickering
125 pOV->HideCursor();
126 pOL->SetUpdateLayout(false);
128 // remove old selected text
129 pOV->InsertText( u""_ustr );
131 // prepare undo
132 EditUndoManager& rUndoMgr = pOL->GetUndoManager();
133 rUndoMgr.EnterListAction(SdResId(STR_UNDO_INSERT_SPECCHAR),
134 u""_ustr, 0, mpViewShell->GetViewShellBase().GetViewShellId() );
136 // insert given text
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);
148 pOV->ShowCursor();
151 void FuBullet::InsertSpecialCharacter( SfxRequest const & rReq )
153 const SfxItemSet *pArgs = rReq.GetArgs();
154 const SfxStringItem* pItem = nullptr;
155 if( pArgs )
156 pItem = pArgs->GetItemIfSet(SID_CHARMAP, false);
158 OUString aChars;
159 vcl::Font aFont;
160 if ( pItem )
162 aChars = pItem->GetValue();
163 const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false );
164 if ( pFontItem )
166 const OUString& aFontName = pFontItem->GetValue();
167 aFont = vcl::Font( aFontName, Size(1,1) );
169 else
171 SfxItemSet aFontAttr( mpDoc->GetPool() );
172 mpView->GetAttributes( aFontAttr );
173 const SvxFontItem* pFItem = aFontAttr.GetItem( SID_ATTR_CHAR_FONT );
174 if( pFItem )
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 );
187 if( pFontItem )
188 aSet.Put( *pFontItem );
190 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
191 css::uno::Reference<css::frame::XFrame> xFrame;
192 if (mpViewShell)
194 if (SfxViewFrame* pFrame = mpViewShell->GetFrame())
195 xFrame = pFrame->GetFrame().GetFrameInterface();
197 VclPtr<SfxAbstractDialog> pDlg( pFact->CreateCharMapDialog(mpView->GetViewShell()->GetFrameWeld(), aSet,
198 xFrame) );
200 // If a character is selected, it can be shown
201 // pDLg->SetFont( );
202 // pDlg->SetChar( );
203 pDlg->StartExecuteAsync(
204 [pDlg] (sal_Int32 /*nResult*/)->void
206 pDlg->disposeOnce();
209 return;
212 if (aChars.isEmpty())
213 return;
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();
222 if (pOV)
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
235 if (!pOV)
236 return;
238 // prevent flicker
239 pOV->HideCursor();
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
246 empty string). */
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(),
262 aFont.GetCharSet(),
263 EE_CHAR_FONTINFO);
264 aSet.Put(aFontItem);
265 aFontItem.SetWhich(EE_CHAR_FONTINFO_CJK);
266 aSet.Put(aFontItem);
267 aFontItem.SetWhich(EE_CHAR_FONTINFO_CTL);
268 aSet.Put(aFontItem);
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();
280 // show it again
281 pOL->SetUpdateLayout(true);
282 pOV->ShowCursor();
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 )))
297 return;
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();
306 if(!bTextEdit )
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);
328 if( pViewFrame )
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: */