Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "fubullet.hxx"
21 : :
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 "Window.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>
37 : :
38 : : #include <svx/svxdlg.hxx>
39 : : #include <svx/dialogs.hrc>
40 : : #include "drawview.hxx"
41 : :
42 : : #include "app.hrc"
43 : :
44 : : namespace sd {
45 : :
46 : : const sal_Unicode CHAR_HARDBLANK = ((sal_Unicode)0x00A0);
47 : : const sal_Unicode CHAR_HARDHYPHEN = ((sal_Unicode)0x2011);
48 : : const sal_Unicode CHAR_SOFTHYPHEN = ((sal_Unicode)0x00AD);
49 : : const sal_Unicode CHAR_RLM = ((sal_Unicode)0x200F);
50 : : const sal_Unicode CHAR_LRM = ((sal_Unicode)0x200E);
51 : : const sal_Unicode CHAR_ZWSP = ((sal_Unicode)0x200B);
52 : : const sal_Unicode CHAR_ZWNBSP = ((sal_Unicode)0x2060);
53 : :
54 [ # # ][ # # ]: 0 : TYPEINIT1( FuBullet, FuPoor );
55 : :
56 : : /*************************************************************************
57 : : |*
58 : : |* Konstruktor
59 : : |*
60 : : \************************************************************************/
61 : :
62 : 0 : FuBullet::FuBullet (
63 : : ViewShell* pViewSh,
64 : : ::sd::Window* pWin,
65 : : ::sd::View* _pView,
66 : : SdDrawDocument* pDoc,
67 : : SfxRequest& rReq)
68 : 0 : : FuPoor(pViewSh, pWin, _pView, pDoc, rReq)
69 : : {
70 : 0 : }
71 : :
72 : 0 : FunctionReference FuBullet::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
73 : : {
74 [ # # ][ # # ]: 0 : FunctionReference xFunc( new FuBullet( pViewSh, pWin, pView, pDoc, rReq ) );
75 [ # # ]: 0 : xFunc->DoExecute(rReq);
76 : 0 : return xFunc;
77 : : }
78 : :
79 : 0 : void FuBullet::DoExecute( SfxRequest& rReq )
80 : : {
81 [ # # ]: 0 : if( rReq.GetSlot() == SID_CHARMAP )
82 : 0 : InsertSpecialCharacter(rReq);
83 : : else
84 : : {
85 : 0 : sal_Unicode cMark = 0;
86 [ # # # # : 0 : switch( rReq.GetSlot() )
# # # # ]
87 : : {
88 : 0 : case FN_INSERT_SOFT_HYPHEN: cMark = CHAR_SOFTHYPHEN ; break;
89 : 0 : case FN_INSERT_HARDHYPHEN: cMark = CHAR_HARDHYPHEN ; break;
90 : 0 : case FN_INSERT_HARD_SPACE: cMark = CHAR_HARDBLANK ; break;
91 : 0 : case SID_INSERT_RLM : cMark = CHAR_RLM ; break;
92 : 0 : case SID_INSERT_LRM : cMark = CHAR_LRM ; break;
93 : 0 : case SID_INSERT_ZWSP : cMark = CHAR_ZWSP ; break;
94 : 0 : case SID_INSERT_ZWNBSP: cMark = CHAR_ZWNBSP; break;
95 : : }
96 : :
97 : : DBG_ASSERT( cMark != 0, "FuBullet::FuBullet(), illegal slot used!" );
98 : :
99 [ # # ]: 0 : if( cMark )
100 : 0 : InsertFormattingMark( cMark );
101 : : }
102 : :
103 : 0 : }
104 : :
105 : 0 : void FuBullet::InsertFormattingMark( sal_Unicode cMark )
106 : : {
107 : 0 : OutlinerView* pOV = NULL;
108 : 0 : ::Outliner* pOL = NULL;
109 : :
110 : : // depending on ViewShell set Outliner and OutlinerView
111 [ # # ]: 0 : if (mpViewShell->ISA(DrawViewShell))
112 : : {
113 : 0 : pOV = mpView->GetTextEditOutlinerView();
114 [ # # ]: 0 : if (pOV)
115 : 0 : pOL = mpView->GetTextEditOutliner();
116 : : }
117 [ # # ]: 0 : else if (mpViewShell->ISA(OutlineViewShell))
118 : : {
119 : 0 : pOL = static_cast<OutlineView*>(mpView)->GetOutliner();
120 : : pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
121 : 0 : mpViewShell->GetActiveWindow());
122 : : }
123 : :
124 : : // insert string
125 [ # # ][ # # ]: 0 : if(pOV && pOL)
126 : : {
127 : : // prevent flickering
128 [ # # ]: 0 : pOV->HideCursor();
129 [ # # ]: 0 : pOL->SetUpdateMode(sal_False);
130 : :
131 : : // remove old selected text
132 [ # # ]: 0 : pOV->InsertText( aEmptyStr );
133 : :
134 : : // prepare undo
135 [ # # ]: 0 : ::svl::IUndoManager& rUndoMgr = pOL->GetUndoManager();
136 : : rUndoMgr.EnterListAction(String(SdResId(STR_UNDO_INSERT_SPECCHAR)),
137 [ # # ][ # # ]: 0 : aEmptyStr );
[ # # ][ # # ]
138 : :
139 : : // insert given text
140 : 0 : rtl::OUString aStr( cMark );
141 [ # # ][ # # ]: 0 : pOV->InsertText( aStr, sal_True);
[ # # ]
142 : :
143 [ # # ]: 0 : ESelection aSel = pOV->GetSelection();
144 : 0 : aSel.nStartPara = aSel.nEndPara;
145 : 0 : aSel.nStartPos = aSel.nEndPos;
146 [ # # ]: 0 : pOV->SetSelection(aSel);
147 : :
148 [ # # ]: 0 : rUndoMgr.LeaveListAction();
149 : :
150 : : // restart repainting
151 [ # # ]: 0 : pOL->SetUpdateMode(sal_True);
152 [ # # ]: 0 : pOV->ShowCursor();
153 : : }
154 : 0 : }
155 : :
156 : 0 : void FuBullet::InsertSpecialCharacter( SfxRequest& rReq )
157 : : {
158 : 0 : const SfxItemSet *pArgs = rReq.GetArgs();
159 : 0 : const SfxPoolItem* pItem = 0;
160 [ # # ]: 0 : if( pArgs )
161 [ # # ][ # # ]: 0 : pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_CHARMAP), sal_False, &pItem);
162 : :
163 [ # # ][ # # ]: 0 : String aChars, aFontName;
164 [ # # ]: 0 : Font aFont;
165 [ # # ]: 0 : if ( pItem )
166 : : {
167 [ # # ]: 0 : aChars = ((const SfxStringItem*)pItem)->GetValue();
168 : 0 : const SfxPoolItem* pFtItem = NULL;
169 [ # # ][ # # ]: 0 : pArgs->GetItemState( mpDoc->GetPool().GetWhich(SID_ATTR_SPECIALCHAR), sal_False, &pFtItem);
170 [ # # ][ # # ]: 0 : const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
[ # # ][ # # ]
171 [ # # ]: 0 : if ( pFontItem )
172 : : {
173 [ # # ]: 0 : aFontName = pFontItem->GetValue();
174 [ # # ][ # # ]: 0 : aFont = Font( aFontName, Size(1,1) );
[ # # ]
175 : : }
176 : : else
177 : : {
178 [ # # ]: 0 : SfxItemSet aFontAttr( mpDoc->GetPool() );
179 [ # # ]: 0 : mpView->GetAttributes( aFontAttr );
180 [ # # ]: 0 : const SvxFontItem* pFItem = (const SvxFontItem*)aFontAttr.GetItem( SID_ATTR_CHAR_FONT );
181 [ # # ]: 0 : if( pFItem )
182 [ # # ][ # # ]: 0 : aFont = Font( pFItem->GetFamilyName(), pFItem->GetStyleName(), Size( 1, 1 ) );
[ # # ][ # # ]
183 : : }
184 : : }
185 : :
186 [ # # ]: 0 : if (!aChars.Len() )
187 : : {
188 [ # # ]: 0 : SfxAllItemSet aSet( mpDoc->GetPool() );
189 [ # # ][ # # ]: 0 : aSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
[ # # ]
190 : :
191 [ # # ]: 0 : SfxItemSet aFontAttr( mpDoc->GetPool() );
192 [ # # ]: 0 : mpView->GetAttributes( aFontAttr );
193 [ # # ]: 0 : const SvxFontItem* pFontItem = (const SvxFontItem*)aFontAttr.GetItem( SID_ATTR_CHAR_FONT );
194 [ # # ]: 0 : if( pFontItem )
195 [ # # ]: 0 : aSet.Put( *pFontItem );
196 : :
197 [ # # ]: 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
198 [ # # ][ # # ]: 0 : SfxAbstractDialog* pDlg = pFact ? pFact->CreateSfxDialog( &mpView->GetViewShell()->GetViewFrame()->GetWindow(), aSet,
199 [ # # ][ # # ]: 0 : mpView->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface(),
200 [ # # ][ # # ]: 0 : RID_SVXDLG_CHARMAP ) : 0;
[ # # ][ # # ]
[ # # ]
201 [ # # ]: 0 : if( !pDlg )
202 : 0 : return;
203 : :
204 : : // Wenn Zeichen selektiert ist kann es angezeigt werden
205 : : // pDLg->SetFont( );
206 : : // pDlg->SetChar( );
207 [ # # ]: 0 : sal_uInt16 nResult = pDlg->Execute();
208 [ # # ]: 0 : if( nResult == RET_OK )
209 : : {
210 [ # # ][ # # ]: 0 : SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, sal_False );
[ # # ]
211 [ # # ][ # # ]: 0 : SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False );
[ # # ]
212 [ # # ]: 0 : if ( pFItem )
213 : : {
214 [ # # ][ # # ]: 0 : aFont.SetName( pFItem->GetFamilyName() );
215 [ # # ]: 0 : aFont.SetStyleName( pFItem->GetStyleName() );
216 [ # # ]: 0 : aFont.SetCharSet( pFItem->GetCharSet() );
217 [ # # ]: 0 : aFont.SetPitch( pFItem->GetPitch() );
218 : : }
219 : :
220 [ # # ]: 0 : if ( pCItem )
221 [ # # ]: 0 : aChars = pCItem->GetValue();
222 : : }
223 : :
224 [ # # ][ # # ]: 0 : delete( pDlg );
[ # # ][ # # ]
[ # # ][ # # ]
225 : : }
226 : :
227 [ # # ]: 0 : if( aChars.Len() )
228 : : {
229 : 0 : OutlinerView* pOV = NULL;
230 : 0 : ::Outliner* pOL = NULL;
231 : :
232 : : // je nach ViewShell Outliner und OutlinerView bestimmen
233 [ # # ][ # # ]: 0 : if(mpViewShell && mpViewShell->ISA(DrawViewShell))
[ # # ][ # # ]
[ # # ]
234 : : {
235 : 0 : pOV = mpView->GetTextEditOutlinerView();
236 [ # # ]: 0 : if (pOV)
237 : : {
238 : 0 : pOL = mpView->GetTextEditOutliner();
239 : : }
240 : : }
241 [ # # ][ # # ]: 0 : else if(mpViewShell && mpViewShell->ISA(OutlineViewShell))
[ # # ][ # # ]
[ # # ]
242 : : {
243 : 0 : pOL = static_cast<OutlineView*>(mpView)->GetOutliner();
244 : : pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
245 [ # # ][ # # ]: 0 : mpViewShell->GetActiveWindow());
246 : : }
247 : :
248 : : // Sonderzeichen einfuegen
249 [ # # ]: 0 : if (pOV)
250 : : {
251 : : // nicht flackern
252 [ # # ]: 0 : pOV->HideCursor();
253 [ # # ]: 0 : pOL->SetUpdateMode(sal_False);
254 : :
255 : : // alte Attributierung merken;
256 : : // dazu vorher selektierten Bereich loeschen, denn der muss eh weg
257 : : // und so gibt es immer eine eindeutige Attributierung (und da es
258 : : // kein DeleteSelected() an der OutlinerView gibt, wird durch
259 : : // Einfuegen eines Leerstrings geloescht)
260 [ # # ]: 0 : pOV->InsertText( aEmptyStr );
261 : :
262 [ # # ]: 0 : SfxItemSet aOldSet( mpDoc->GetPool(), EE_CHAR_FONTINFO, EE_CHAR_FONTINFO, 0 );
263 [ # # ][ # # ]: 0 : aOldSet.Put( pOV->GetAttribs() );
[ # # ]
264 : :
265 [ # # ]: 0 : ::svl::IUndoManager& rUndoMgr = pOL->GetUndoManager();
266 : : rUndoMgr.EnterListAction(String(SdResId(STR_UNDO_INSERT_SPECCHAR)),
267 [ # # ][ # # ]: 0 : aEmptyStr );
[ # # ][ # # ]
268 [ # # ]: 0 : pOV->InsertText(aChars, sal_True);
269 : :
270 : : // attributieren (Font setzen)
271 [ # # ][ # # ]: 0 : SfxItemSet aSet(pOL->GetEmptyItemSet());
272 [ # # ]: 0 : SvxFontItem aFontItem (aFont.GetFamily(), aFont.GetName(),
273 [ # # ]: 0 : aFont.GetStyleName(), aFont.GetPitch(),
274 [ # # ]: 0 : aFont.GetCharSet(),
275 [ # # ][ # # ]: 0 : EE_CHAR_FONTINFO);
[ # # ]
276 [ # # ]: 0 : aSet.Put(aFontItem);
277 [ # # ]: 0 : aSet.Put(aFontItem, EE_CHAR_FONTINFO_CJK);
278 [ # # ]: 0 : aSet.Put(aFontItem, EE_CHAR_FONTINFO_CTL);
279 [ # # ]: 0 : pOV->SetAttribs(aSet);
280 : :
281 [ # # ]: 0 : ESelection aSel = pOV->GetSelection();
282 : 0 : aSel.nStartPara = aSel.nEndPara;
283 : 0 : aSel.nStartPos = aSel.nEndPos;
284 [ # # ]: 0 : pOV->SetSelection(aSel);
285 : :
286 : : // nicht mit Sonderzeichenattributierung weiterschreiben
287 [ # # ]: 0 : pOV->GetOutliner()->QuickSetAttribs(aOldSet, aSel);
288 : :
289 [ # # ]: 0 : rUndoMgr.LeaveListAction();
290 : :
291 : : // ab jetzt wieder anzeigen
292 [ # # ]: 0 : pOL->SetUpdateMode(sal_True);
293 [ # # ][ # # ]: 0 : pOV->ShowCursor();
[ # # ][ # # ]
294 : : }
295 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ][ # # ]
296 : : }
297 : :
298 : 6385 : void FuBullet::GetSlotState( SfxItemSet& rSet, ViewShell* pViewShell, SfxViewFrame* pViewFrame )
299 : : {
300 [ + - + - : 51080 : if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_CHARMAP ) ||
+ - + - +
- + - + -
- + ][ - + ]
301 : 6385 : SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_SOFT_HYPHEN ) ||
302 : 6385 : SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_HARDHYPHEN ) ||
303 : 6385 : SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_HARD_SPACE ) ||
304 : 6385 : SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_RLM ) ||
305 : 6385 : SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_LRM ) ||
306 : 6385 : SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_ZWNBSP ) ||
307 : 6385 : SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_ZWSP ))
308 : : {
309 [ # # ]: 0 : ::sd::View* pView = pViewShell ? pViewShell->GetView() : 0;
310 [ # # ]: 0 : OutlinerView* pOLV = pView ? pView->GetTextEditOutlinerView() : 0;
311 : :
312 : 0 : const bool bTextEdit = pOLV;
313 : :
314 [ # # ]: 0 : SvtCTLOptions aCTLOptions;
315 [ # # ]: 0 : const sal_Bool bCtlEnabled = aCTLOptions.IsCTLFontEnabled();
316 : :
317 [ # # ]: 0 : if(!bTextEdit )
318 : : {
319 [ # # ]: 0 : rSet.DisableItem(FN_INSERT_SOFT_HYPHEN);
320 [ # # ]: 0 : rSet.DisableItem(FN_INSERT_HARDHYPHEN);
321 [ # # ]: 0 : rSet.DisableItem(FN_INSERT_HARD_SPACE);
322 : : }
323 : :
324 [ # # ][ # # ]: 0 : if( !bTextEdit && (dynamic_cast<OutlineViewShell*>( pViewShell ) == 0) )
[ # # ][ # # ]
325 [ # # ]: 0 : rSet.DisableItem(SID_CHARMAP);
326 : :
327 [ # # ][ # # ]: 0 : if(!bTextEdit || !bCtlEnabled )
328 : : {
329 [ # # ]: 0 : rSet.DisableItem(SID_INSERT_RLM);
330 [ # # ]: 0 : rSet.DisableItem(SID_INSERT_LRM);
331 [ # # ]: 0 : rSet.DisableItem(SID_INSERT_ZWNBSP);
332 [ # # ]: 0 : rSet.DisableItem(SID_INSERT_ZWSP);
333 : : }
334 : :
335 [ # # ]: 0 : if( pViewFrame )
336 : : {
337 : 0 : SfxBindings& rBindings = pViewFrame->GetBindings();
338 : :
339 [ # # ]: 0 : rBindings.SetVisibleState( SID_INSERT_RLM, bCtlEnabled );
340 [ # # ]: 0 : rBindings.SetVisibleState( SID_INSERT_LRM, bCtlEnabled );
341 [ # # ]: 0 : rBindings.SetVisibleState( SID_INSERT_ZWNBSP, bCtlEnabled );
342 [ # # ]: 0 : rBindings.SetVisibleState( SID_INSERT_ZWSP, bCtlEnabled );
343 [ # # ]: 0 : }
344 : : }
345 : 6385 : }
346 : : } // end of namespace sd
347 : :
348 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|