1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fubullet.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
35 #include "fubullet.hxx"
37 #ifndef _BINDING_HXX //autogen
38 #include <sfx2/bindings.hxx>
40 #include <svx/eeitem.hxx>
41 #include <svtools/poolitem.hxx>
42 #include <svx/fontitem.hxx>
43 #include "OutlineViewShell.hxx"
44 #include "DrawViewShell.hxx"
46 #include "drawdoc.hxx"
47 #include "strings.hrc"
48 #include "sdresid.hxx"
49 #include <svx/svdoutl.hxx>
50 #include <vcl/msgbox.hxx>
51 #include <sfx2/request.hxx>
52 #include <svtools/ctloptions.hxx>
53 #include <svtools/itempool.hxx>
56 #include <basic/sbx.hxx>
58 #include <svx/svxdlg.hxx>
59 #include <svx/dialogs.hrc>
60 #include "drawview.hxx"
66 const sal_Unicode CHAR_HARDBLANK
= ((sal_Unicode
)0x00A0);
67 const sal_Unicode CHAR_HARDHYPHEN
= ((sal_Unicode
)0x2011);
68 const sal_Unicode CHAR_SOFTHYPHEN
= ((sal_Unicode
)0x00AD);
69 const sal_Unicode CHAR_RLM
= ((sal_Unicode
)0x200F);
70 const sal_Unicode CHAR_LRM
= ((sal_Unicode
)0x200E);
71 const sal_Unicode CHAR_ZWSP
= ((sal_Unicode
)0x200B);
72 const sal_Unicode CHAR_ZWNBSP
= ((sal_Unicode
)0x2060);
74 TYPEINIT1( FuBullet
, FuPoor
);
76 /*************************************************************************
80 \************************************************************************/
88 : FuPoor(pViewSh
, pWin
, _pView
, pDoc
, rReq
)
92 FunctionReference
FuBullet::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
94 FunctionReference
xFunc( new FuBullet( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
95 xFunc
->DoExecute(rReq
);
99 void FuBullet::DoExecute( SfxRequest
& rReq
)
101 if( rReq
.GetSlot() == SID_CHARMAP
)
102 InsertSpecialCharacter(rReq
);
105 sal_Unicode cMark
= 0;
106 switch( rReq
.GetSlot() )
108 case FN_INSERT_SOFT_HYPHEN
: cMark
= CHAR_SOFTHYPHEN
; break;
109 case FN_INSERT_HARDHYPHEN
: cMark
= CHAR_HARDHYPHEN
; break;
110 case FN_INSERT_HARD_SPACE
: cMark
= CHAR_HARDBLANK
; break;
111 case SID_INSERT_RLM
: cMark
= CHAR_RLM
; break;
112 case SID_INSERT_LRM
: cMark
= CHAR_LRM
; break;
113 case SID_INSERT_ZWSP
: cMark
= CHAR_ZWSP
; break;
114 case SID_INSERT_ZWNBSP
: cMark
= CHAR_ZWNBSP
; break;
117 DBG_ASSERT( cMark
!= 0, "FuBullet::FuBullet(), illegal slot used!" );
120 InsertFormattingMark( cMark
);
125 void FuBullet::InsertFormattingMark( sal_Unicode cMark
)
127 OutlinerView
* pOV
= NULL
;
128 ::Outliner
* pOL
= NULL
;
130 // depending on ViewShell set Outliner and OutlinerView
131 if (mpViewShell
->ISA(DrawViewShell
))
133 pOV
= mpView
->GetTextEditOutlinerView();
135 pOL
= mpView
->GetTextEditOutliner();
137 else if (mpViewShell
->ISA(OutlineViewShell
))
139 pOL
= static_cast<OutlineView
*>(mpView
)->GetOutliner();
140 pOV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
141 mpViewShell
->GetActiveWindow());
147 // prevent flickering
149 pOL
->SetUpdateMode(FALSE
);
151 // remove old selected text
152 pOV
->InsertText( aEmptyStr
);
155 SfxUndoManager
& rUndoMgr
= pOL
->GetUndoManager();
156 rUndoMgr
.EnterListAction(String(SdResId(STR_UNDO_INSERT_SPECCHAR
)),
160 String
aStr( cMark
);
161 pOV
->InsertText( cMark
, TRUE
);
163 ESelection aSel
= pOV
->GetSelection();
164 aSel
.nStartPara
= aSel
.nEndPara
;
165 aSel
.nStartPos
= aSel
.nEndPos
;
166 pOV
->SetSelection(aSel
);
168 rUndoMgr
.LeaveListAction();
170 // restart repainting
171 pOL
->SetUpdateMode(TRUE
);
176 void FuBullet::InsertSpecialCharacter( SfxRequest
& rReq
)
178 const SfxItemSet
*pArgs
= rReq
.GetArgs();
179 const SfxPoolItem
* pItem
= 0;
181 pArgs
->GetItemState(mpDoc
->GetPool().GetWhich(SID_CHARMAP
), FALSE
, &pItem
);
183 String aChars
, aFontName
;
187 aChars
= ((const SfxStringItem
*)pItem
)->GetValue();
188 const SfxPoolItem
* pFtItem
= NULL
;
189 pArgs
->GetItemState( mpDoc
->GetPool().GetWhich(SID_ATTR_SPECIALCHAR
), FALSE
, &pFtItem
);
190 const SfxStringItem
* pFontItem
= PTR_CAST( SfxStringItem
, pFtItem
);
193 aFontName
= pFontItem
->GetValue();
194 aFont
= Font( aFontName
, Size(1,1) );
198 SfxItemSet
aFontAttr( mpDoc
->GetPool() );
199 mpView
->GetAttributes( aFontAttr
);
200 const SvxFontItem
* pFItem
= (const SvxFontItem
*)aFontAttr
.GetItem( SID_ATTR_CHAR_FONT
);
202 aFont
= Font( pFItem
->GetFamilyName(), pFItem
->GetStyleName(), Size( 1, 1 ) );
208 SfxAllItemSet
aSet( mpDoc
->GetPool() );
209 aSet
.Put( SfxBoolItem( FN_PARAM_1
, FALSE
) );
211 SfxItemSet
aFontAttr( mpDoc
->GetPool() );
212 mpView
->GetAttributes( aFontAttr
);
213 const SvxFontItem
* pFontItem
= (const SvxFontItem
*)aFontAttr
.GetItem( SID_ATTR_CHAR_FONT
);
215 aSet
.Put( *pFontItem
);
217 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
218 SfxAbstractDialog
* pDlg
= pFact
? pFact
->CreateSfxDialog( &mpView
->GetViewShell()->GetViewFrame()->GetWindow(), aSet
,
219 mpView
->GetViewShell()->GetViewFrame()->GetFrame()->GetFrameInterface(),
220 RID_SVXDLG_CHARMAP
) : 0;
224 // Wenn Zeichen selektiert ist kann es angezeigt werden
227 USHORT nResult
= pDlg
->Execute();
228 if( nResult
== RET_OK
)
230 SFX_ITEMSET_ARG( pDlg
->GetOutputItemSet(), pCItem
, SfxStringItem
, SID_CHARMAP
, FALSE
);
231 SFX_ITEMSET_ARG( pDlg
->GetOutputItemSet(), pFItem
, SvxFontItem
, SID_ATTR_CHAR_FONT
, FALSE
);
234 aFont
.SetName( pFItem
->GetFamilyName() );
235 aFont
.SetStyleName( pFItem
->GetStyleName() );
236 aFont
.SetCharSet( pFItem
->GetCharSet() );
237 aFont
.SetPitch( pFItem
->GetPitch() );
241 aChars
= pCItem
->GetValue();
249 OutlinerView
* pOV
= NULL
;
250 ::Outliner
* pOL
= NULL
;
252 // je nach ViewShell Outliner und OutlinerView bestimmen
253 if(mpViewShell
&& mpViewShell
->ISA(DrawViewShell
))
255 pOV
= mpView
->GetTextEditOutlinerView();
258 pOL
= mpView
->GetTextEditOutliner();
261 else if(mpViewShell
&& mpViewShell
->ISA(OutlineViewShell
))
263 pOL
= static_cast<OutlineView
*>(mpView
)->GetOutliner();
264 pOV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
265 mpViewShell
->GetActiveWindow());
268 // Sonderzeichen einfuegen
273 pOL
->SetUpdateMode(FALSE
);
275 // alte Attributierung merken;
276 // dazu vorher selektierten Bereich loeschen, denn der muss eh weg
277 // und so gibt es immer eine eindeutige Attributierung (und da es
278 // kein DeleteSelected() an der OutlinerView gibt, wird durch
279 // Einfuegen eines Leerstrings geloescht)
280 pOV
->InsertText( aEmptyStr
);
282 SfxItemSet
aOldSet( mpDoc
->GetPool(), EE_CHAR_FONTINFO
, EE_CHAR_FONTINFO
, 0 );
283 aOldSet
.Put( pOV
->GetAttribs() );
285 SfxUndoManager
& rUndoMgr
= pOL
->GetUndoManager();
286 rUndoMgr
.EnterListAction(String(SdResId(STR_UNDO_INSERT_SPECCHAR
)),
288 pOV
->InsertText(aChars
, TRUE
);
290 // attributieren (Font setzen)
291 SfxItemSet
aSet(pOL
->GetEmptyItemSet());
292 SvxFontItem
aFontItem (aFont
.GetFamily(), aFont
.GetName(),
293 aFont
.GetStyleName(), aFont
.GetPitch(),
297 aSet
.Put(aFontItem
, EE_CHAR_FONTINFO_CJK
);
298 aSet
.Put(aFontItem
, EE_CHAR_FONTINFO_CTL
);
299 pOV
->SetAttribs(aSet
);
301 ESelection aSel
= pOV
->GetSelection();
302 aSel
.nStartPara
= aSel
.nEndPara
;
303 aSel
.nStartPos
= aSel
.nEndPos
;
304 pOV
->SetSelection(aSel
);
306 // nicht mit Sonderzeichenattributierung weiterschreiben
307 pOV
->GetOutliner()->QuickSetAttribs(aOldSet
, aSel
);
309 rUndoMgr
.LeaveListAction();
311 // ab jetzt wieder anzeigen
312 pOL
->SetUpdateMode(TRUE
);
318 void FuBullet::GetSlotState( SfxItemSet
& rSet
, ViewShell
* pViewShell
, SfxViewFrame
* pViewFrame
)
320 if( SFX_ITEM_AVAILABLE
== rSet
.GetItemState( SID_CHARMAP
) ||
321 SFX_ITEM_AVAILABLE
== rSet
.GetItemState( FN_INSERT_SOFT_HYPHEN
) ||
322 SFX_ITEM_AVAILABLE
== rSet
.GetItemState( FN_INSERT_HARDHYPHEN
) ||
323 SFX_ITEM_AVAILABLE
== rSet
.GetItemState( FN_INSERT_HARD_SPACE
) ||
324 SFX_ITEM_AVAILABLE
== rSet
.GetItemState( SID_INSERT_RLM
) ||
325 SFX_ITEM_AVAILABLE
== rSet
.GetItemState( SID_INSERT_LRM
) ||
326 SFX_ITEM_AVAILABLE
== rSet
.GetItemState( SID_INSERT_ZWNBSP
) ||
327 SFX_ITEM_AVAILABLE
== rSet
.GetItemState( SID_INSERT_ZWSP
))
329 ::sd::View
* pView
= pViewShell
? pViewShell
->GetView() : 0;
330 OutlinerView
* pOLV
= pView
? pView
->GetTextEditOutlinerView() : 0;
332 const bool bTextEdit
= pOLV
;
334 SvtCTLOptions aCTLOptions
;
335 const sal_Bool bCtlEnabled
= aCTLOptions
.IsCTLFontEnabled();
339 rSet
.DisableItem(FN_INSERT_SOFT_HYPHEN
);
340 rSet
.DisableItem(FN_INSERT_HARDHYPHEN
);
341 rSet
.DisableItem(FN_INSERT_HARD_SPACE
);
344 if( !bTextEdit
&& (dynamic_cast<OutlineViewShell
*>( pViewShell
) == 0) )
345 rSet
.DisableItem(SID_CHARMAP
);
347 if(!bTextEdit
|| !bCtlEnabled
)
349 rSet
.DisableItem(SID_INSERT_RLM
);
350 rSet
.DisableItem(SID_INSERT_LRM
);
351 rSet
.DisableItem(SID_INSERT_ZWNBSP
);
352 rSet
.DisableItem(SID_INSERT_ZWSP
);
357 SfxBindings
& rBindings
= pViewFrame
->GetBindings();
359 rBindings
.SetVisibleState( SID_INSERT_RLM
, bCtlEnabled
);
360 rBindings
.SetVisibleState( SID_INSERT_LRM
, bCtlEnabled
);
361 rBindings
.SetVisibleState( SID_INSERT_ZWNBSP
, bCtlEnabled
);
362 rBindings
.SetVisibleState( SID_INSERT_ZWSP
, bCtlEnabled
);
366 } // end of namespace sd