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 <editeng/eeitem.hxx>
24 #include <svl/poolitem.hxx>
25 #include <editeng/fontitem.hxx>
26 #include "OutlineViewShell.hxx"
27 #include "DrawViewShell.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"
41 #include <boost/scoped_ptr.hpp>
47 const sal_Unicode CHAR_HARDBLANK
= ((sal_Unicode
)0x00A0);
48 const sal_Unicode CHAR_HARDHYPHEN
= ((sal_Unicode
)0x2011);
49 const sal_Unicode CHAR_SOFTHYPHEN
= ((sal_Unicode
)0x00AD);
50 const sal_Unicode CHAR_RLM
= ((sal_Unicode
)0x200F);
51 const sal_Unicode CHAR_LRM
= ((sal_Unicode
)0x200E);
52 const sal_Unicode CHAR_ZWSP
= ((sal_Unicode
)0x200B);
53 const sal_Unicode CHAR_ZWNBSP
= ((sal_Unicode
)0x2060);
55 TYPEINIT1( FuBullet
, FuPoor
);
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 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!" );
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();
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());
122 // prevent flickering
124 pOL
->SetUpdateMode(false);
126 // remove old selected text
127 pOV
->InsertText( aEmptyStr
);
130 ::svl::IUndoManager
& rUndoMgr
= pOL
->GetUndoManager();
131 rUndoMgr
.EnterListAction(SD_RESSTR(STR_UNDO_INSERT_SPECCHAR
),
135 OUString
aStr( cMark
);
136 pOV
->InsertText( aStr
, 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(true);
151 void FuBullet::InsertSpecialCharacter( SfxRequest
& rReq
)
153 const SfxItemSet
*pArgs
= rReq
.GetArgs();
154 const SfxPoolItem
* pItem
= 0;
156 pArgs
->GetItemState(mpDoc
->GetPool().GetWhich(SID_CHARMAP
), false, &pItem
);
162 aChars
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
163 const SfxPoolItem
* pFtItem
= NULL
;
164 pArgs
->GetItemState( mpDoc
->GetPool().GetWhich(SID_ATTR_SPECIALCHAR
), false, &pFtItem
);
165 const SfxStringItem
* pFontItem
= PTR_CAST( SfxStringItem
, pFtItem
);
168 OUString aFontName
= pFontItem
->GetValue();
169 aFont
= vcl::Font( aFontName
, Size(1,1) );
173 SfxItemSet
aFontAttr( mpDoc
->GetPool() );
174 mpView
->GetAttributes( aFontAttr
);
175 const SvxFontItem
* pFItem
= static_cast<const SvxFontItem
*>(aFontAttr
.GetItem( SID_ATTR_CHAR_FONT
));
177 aFont
= vcl::Font( pFItem
->GetFamilyName(), pFItem
->GetStyleName(), Size( 1, 1 ) );
181 if (aChars
.isEmpty())
183 SfxAllItemSet
aSet( mpDoc
->GetPool() );
184 aSet
.Put( SfxBoolItem( FN_PARAM_1
, false ) );
186 SfxItemSet
aFontAttr( mpDoc
->GetPool() );
187 mpView
->GetAttributes( aFontAttr
);
188 const SvxFontItem
* pFontItem
= static_cast<const SvxFontItem
*>(aFontAttr
.GetItem( SID_ATTR_CHAR_FONT
));
190 aSet
.Put( *pFontItem
);
192 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
193 boost::scoped_ptr
<SfxAbstractDialog
> pDlg(pFact
? pFact
->CreateSfxDialog( &mpView
->GetViewShell()->GetViewFrame()->GetWindow(), aSet
,
194 mpView
->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface(),
195 RID_SVXDLG_CHARMAP
) : 0);
199 // If a character is selected, it can be shown
202 sal_uInt16 nResult
= pDlg
->Execute();
203 if( nResult
== RET_OK
)
205 SFX_ITEMSET_ARG( pDlg
->GetOutputItemSet(), pCItem
, SfxStringItem
, SID_CHARMAP
, false );
206 SFX_ITEMSET_ARG( pDlg
->GetOutputItemSet(), pFItem
, SvxFontItem
, SID_ATTR_CHAR_FONT
, false );
209 aFont
.SetName( pFItem
->GetFamilyName() );
210 aFont
.SetStyleName( pFItem
->GetStyleName() );
211 aFont
.SetCharSet( pFItem
->GetCharSet() );
212 aFont
.SetPitch( pFItem
->GetPitch() );
216 aChars
= pCItem
->GetValue();
220 if (!aChars
.isEmpty())
222 OutlinerView
* pOV
= NULL
;
223 ::Outliner
* pOL
= NULL
;
225 // determine depending on ViewShell Outliner and OutlinerView
226 if(mpViewShell
&& mpViewShell
->ISA(DrawViewShell
))
228 pOV
= mpView
->GetTextEditOutlinerView();
231 pOL
= mpView
->GetTextEditOutliner();
234 else if(mpViewShell
&& mpViewShell
->ISA(OutlineViewShell
))
236 pOL
= &static_cast<OutlineView
*>(mpView
)->GetOutliner();
237 pOV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
238 mpViewShell
->GetActiveWindow());
241 // insert special character
246 pOL
->SetUpdateMode(false);
248 /* remember old attributes:
249 To do that, remove selected area before (it has to go anyway).
250 With that, we get unique attributes (and since there is no
251 DeleteSelected() in OutlinerView, it is deleted by inserting an
253 pOV
->InsertText( aEmptyStr
);
255 SfxItemSet
aOldSet( mpDoc
->GetPool(), EE_CHAR_FONTINFO
, EE_CHAR_FONTINFO
, 0 );
256 aOldSet
.Put( pOV
->GetAttribs() );
258 ::svl::IUndoManager
& rUndoMgr
= pOL
->GetUndoManager();
259 rUndoMgr
.EnterListAction(SD_RESSTR(STR_UNDO_INSERT_SPECCHAR
),
261 pOV
->InsertText(aChars
, true);
263 // set attributes (set font)
264 SfxItemSet
aSet(pOL
->GetEmptyItemSet());
265 SvxFontItem
aFontItem (aFont
.GetFamily(), aFont
.GetName(),
266 aFont
.GetStyleName(), aFont
.GetPitch(),
270 aSet
.Put(aFontItem
, EE_CHAR_FONTINFO_CJK
);
271 aSet
.Put(aFontItem
, EE_CHAR_FONTINFO_CTL
);
272 pOV
->SetAttribs(aSet
);
274 ESelection aSel
= pOV
->GetSelection();
275 aSel
.nStartPara
= aSel
.nEndPara
;
276 aSel
.nStartPos
= aSel
.nEndPos
;
277 pOV
->SetSelection(aSel
);
279 // do not go ahead with setting attributes of special characters
280 pOV
->GetOutliner()->QuickSetAttribs(aOldSet
, aSel
);
282 rUndoMgr
.LeaveListAction();
285 pOL
->SetUpdateMode(true);
291 void FuBullet::GetSlotState( SfxItemSet
& rSet
, ViewShell
* pViewShell
, SfxViewFrame
* pViewFrame
)
293 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_CHARMAP
) ||
294 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_SOFT_HYPHEN
) ||
295 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_HARDHYPHEN
) ||
296 SfxItemState::DEFAULT
== rSet
.GetItemState( FN_INSERT_HARD_SPACE
) ||
297 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_RLM
) ||
298 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_LRM
) ||
299 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_ZWNBSP
) ||
300 SfxItemState::DEFAULT
== rSet
.GetItemState( SID_INSERT_ZWSP
))
302 ::sd::View
* pView
= pViewShell
? pViewShell
->GetView() : 0;
303 OutlinerView
* pOLV
= pView
? pView
->GetTextEditOutlinerView() : 0;
305 const bool bTextEdit
= pOLV
;
307 SvtCTLOptions aCTLOptions
;
308 const bool bCtlEnabled
= aCTLOptions
.IsCTLFontEnabled();
312 rSet
.DisableItem(FN_INSERT_SOFT_HYPHEN
);
313 rSet
.DisableItem(FN_INSERT_HARDHYPHEN
);
314 rSet
.DisableItem(FN_INSERT_HARD_SPACE
);
317 if( !bTextEdit
&& (dynamic_cast<OutlineViewShell
*>( pViewShell
) == 0) )
318 rSet
.DisableItem(SID_CHARMAP
);
320 if(!bTextEdit
|| !bCtlEnabled
)
322 rSet
.DisableItem(SID_INSERT_RLM
);
323 rSet
.DisableItem(SID_INSERT_LRM
);
324 rSet
.DisableItem(SID_INSERT_ZWNBSP
);
325 rSet
.DisableItem(SID_INSERT_ZWSP
);
330 SfxBindings
& rBindings
= pViewFrame
->GetBindings();
332 rBindings
.SetVisibleState( SID_INSERT_RLM
, bCtlEnabled
);
333 rBindings
.SetVisibleState( SID_INSERT_LRM
, bCtlEnabled
);
334 rBindings
.SetVisibleState( SID_INSERT_ZWNBSP
, bCtlEnabled
);
335 rBindings
.SetVisibleState( SID_INSERT_ZWSP
, bCtlEnabled
);
339 } // end of namespace sd
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */