1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26
27
28 #include "fubullet.hxx"
29
30 #ifndef _BINDING_HXX //autogen
31 #include <sfx2/bindings.hxx>
32 #endif
33 #include <editeng/eeitem.hxx>
34 #include <svl/poolitem.hxx>
35 #include <editeng/fontitem.hxx>
36 #include "OutlineViewShell.hxx"
37 #include "DrawViewShell.hxx"
38 #include "Window.hxx"
39 #include "drawdoc.hxx"
40 #include "strings.hrc"
41 #include "sdresid.hxx"
42 #include <svx/svdoutl.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <sfx2/request.hxx>
45 #include <svl/ctloptions.hxx>
46 #include <svl/itempool.hxx>
47
48 #include <svx/svxdlg.hxx>
49 #include <svx/dialogs.hrc>
50 #include "drawview.hxx"
51
52 #include "app.hrc"
53
54 namespace sd {
55
56 const sal_Unicode CHAR_HARDBLANK = ((sal_Unicode)0x00A0);
57 const sal_Unicode CHAR_HARDHYPHEN = ((sal_Unicode)0x2011);
58 const sal_Unicode CHAR_SOFTHYPHEN = ((sal_Unicode)0x00AD);
59 const sal_Unicode CHAR_RLM = ((sal_Unicode)0x200F);
60 const sal_Unicode CHAR_LRM = ((sal_Unicode)0x200E);
61 const sal_Unicode CHAR_ZWSP = ((sal_Unicode)0x200B);
62 const sal_Unicode CHAR_ZWNBSP = ((sal_Unicode)0x2060);
63
64 TYPEINIT1( FuBullet, FuPoor );
65
66 /*************************************************************************
67 |*
68 |* Konstruktor
69 |*
70 \************************************************************************/
71
FuBullet(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * _pView,SdDrawDocument * pDoc,SfxRequest & rReq)72 FuBullet::FuBullet (
73 ViewShell* pViewSh,
74 ::sd::Window* pWin,
75 ::sd::View* _pView,
76 SdDrawDocument* pDoc,
77 SfxRequest& rReq)
78 : FuPoor(pViewSh, pWin, _pView, pDoc, rReq)
79 {
80 }
81
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)82 FunctionReference FuBullet::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
83 {
84 FunctionReference xFunc( new FuBullet( pViewSh, pWin, pView, pDoc, rReq ) );
85 xFunc->DoExecute(rReq);
86 return xFunc;
87 }
88
DoExecute(SfxRequest & rReq)89 void FuBullet::DoExecute( SfxRequest& rReq )
90 {
91 if( rReq.GetSlot() == SID_CHARMAP )
92 InsertSpecialCharacter(rReq);
93 else
94 {
95 sal_Unicode cMark = 0;
96 switch( rReq.GetSlot() )
97 {
98 case FN_INSERT_SOFT_HYPHEN: cMark = CHAR_SOFTHYPHEN ; break;
99 case FN_INSERT_HARDHYPHEN: cMark = CHAR_HARDHYPHEN ; break;
100 case FN_INSERT_HARD_SPACE: cMark = CHAR_HARDBLANK ; break;
101 case SID_INSERT_RLM : cMark = CHAR_RLM ; break;
102 case SID_INSERT_LRM : cMark = CHAR_LRM ; break;
103 case SID_INSERT_ZWSP : cMark = CHAR_ZWSP ; break;
104 case SID_INSERT_ZWNBSP: cMark = CHAR_ZWNBSP; break;
105 }
106
107 DBG_ASSERT( cMark != 0, "FuBullet::FuBullet(), illegal slot used!" );
108
109 if( cMark )
110 InsertFormattingMark( cMark );
111 }
112
113 }
114
InsertFormattingMark(sal_Unicode cMark)115 void FuBullet::InsertFormattingMark( sal_Unicode cMark )
116 {
117 OutlinerView* pOV = NULL;
118 ::Outliner* pOL = NULL;
119
120 // depending on ViewShell set Outliner and OutlinerView
121 if (mpViewShell->ISA(DrawViewShell))
122 {
123 pOV = mpView->GetTextEditOutlinerView();
124 if (pOV)
125 pOL = mpView->GetTextEditOutliner();
126 }
127 else if (mpViewShell->ISA(OutlineViewShell))
128 {
129 pOL = static_cast<OutlineView*>(mpView)->GetOutliner();
130 pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
131 mpViewShell->GetActiveWindow());
132 }
133
134 // insert string
135 if(pOV && pOL)
136 {
137 // prevent flickering
138 pOV->HideCursor();
139 pOL->SetUpdateMode(sal_False);
140
141 // remove old selected text
142 pOV->InsertText( aEmptyStr );
143
144 // prepare undo
145 ::svl::IUndoManager& rUndoMgr = pOL->GetUndoManager();
146 rUndoMgr.EnterListAction(String(SdResId(STR_UNDO_INSERT_SPECCHAR)),
147 aEmptyStr );
148
149 // insert given text
150 String aStr( cMark );
151 pOV->InsertText( cMark, sal_True);
152
153 ESelection aSel = pOV->GetSelection();
154 aSel.nStartPara = aSel.nEndPara;
155 aSel.nStartPos = aSel.nEndPos;
156 pOV->SetSelection(aSel);
157
158 rUndoMgr.LeaveListAction();
159
160 // restart repainting
161 pOL->SetUpdateMode(sal_True);
162 pOV->ShowCursor();
163 }
164 }
165
InsertSpecialCharacter(SfxRequest & rReq)166 void FuBullet::InsertSpecialCharacter( SfxRequest& rReq )
167 {
168 const SfxItemSet *pArgs = rReq.GetArgs();
169 const SfxPoolItem* pItem = 0;
170 if( pArgs )
171 pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_CHARMAP), sal_False, &pItem);
172
173 String aChars, aFontName;
174 Font aFont;
175 if ( pItem )
176 {
177 aChars = ((const SfxStringItem*)pItem)->GetValue();
178 const SfxPoolItem* pFtItem = NULL;
179 pArgs->GetItemState( mpDoc->GetPool().GetWhich(SID_ATTR_SPECIALCHAR), sal_False, &pFtItem);
180 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
181 if ( pFontItem )
182 {
183 aFontName = pFontItem->GetValue();
184 aFont = Font( aFontName, Size(1,1) );
185 }
186 else
187 {
188 SfxItemSet aFontAttr( mpDoc->GetPool() );
189 mpView->GetAttributes( aFontAttr );
190 const SvxFontItem* pFItem = (const SvxFontItem*)aFontAttr.GetItem( SID_ATTR_CHAR_FONT );
191 if( pFItem )
192 aFont = Font( pFItem->GetFamilyName(), pFItem->GetStyleName(), Size( 1, 1 ) );
193 }
194 }
195
196 if (!aChars.Len() )
197 {
198 SfxAllItemSet aSet( mpDoc->GetPool() );
199 aSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
200
201 SfxItemSet aFontAttr( mpDoc->GetPool() );
202 mpView->GetAttributes( aFontAttr );
203 const SvxFontItem* pFontItem = (const SvxFontItem*)aFontAttr.GetItem( SID_ATTR_CHAR_FONT );
204 if( pFontItem )
205 aSet.Put( *pFontItem );
206
207 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
208 SfxAbstractDialog* pDlg = pFact ? pFact->CreateSfxDialog( &mpView->GetViewShell()->GetViewFrame()->GetWindow(), aSet,
209 mpView->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface(),
210 RID_SVXDLG_CHARMAP ) : 0;
211 if( !pDlg )
212 return;
213
214 // Wenn Zeichen selektiert ist kann es angezeigt werden
215 // pDLg->SetFont( );
216 // pDlg->SetChar( );
217 sal_uInt16 nResult = pDlg->Execute();
218 if( nResult == RET_OK )
219 {
220 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, sal_False );
221 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False );
222 if ( pFItem )
223 {
224 aFont.SetName( pFItem->GetFamilyName() );
225 aFont.SetStyleName( pFItem->GetStyleName() );
226 aFont.SetCharSet( pFItem->GetCharSet() );
227 aFont.SetPitch( pFItem->GetPitch() );
228 }
229
230 if ( pCItem )
231 aChars = pCItem->GetValue();
232 }
233
234 delete( pDlg );
235 }
236
237 if( aChars.Len() )
238 {
239 OutlinerView* pOV = NULL;
240 ::Outliner* pOL = NULL;
241
242 // je nach ViewShell Outliner und OutlinerView bestimmen
243 if(mpViewShell && mpViewShell->ISA(DrawViewShell))
244 {
245 pOV = mpView->GetTextEditOutlinerView();
246 if (pOV)
247 {
248 pOL = mpView->GetTextEditOutliner();
249 }
250 }
251 else if(mpViewShell && mpViewShell->ISA(OutlineViewShell))
252 {
253 pOL = static_cast<OutlineView*>(mpView)->GetOutliner();
254 pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
255 mpViewShell->GetActiveWindow());
256 }
257
258 // Sonderzeichen einfuegen
259 if (pOV)
260 {
261 // nicht flackern
262 pOV->HideCursor();
263 pOL->SetUpdateMode(sal_False);
264
265 // alte Attributierung merken;
266 // dazu vorher selektierten Bereich loeschen, denn der muss eh weg
267 // und so gibt es immer eine eindeutige Attributierung (und da es
268 // kein DeleteSelected() an der OutlinerView gibt, wird durch
269 // Einfuegen eines Leerstrings geloescht)
270 pOV->InsertText( aEmptyStr );
271
272 SfxItemSet aOldSet( mpDoc->GetPool(), EE_CHAR_FONTINFO, EE_CHAR_FONTINFO, 0 );
273 aOldSet.Put( pOV->GetAttribs() );
274
275 ::svl::IUndoManager& rUndoMgr = pOL->GetUndoManager();
276 rUndoMgr.EnterListAction(String(SdResId(STR_UNDO_INSERT_SPECCHAR)),
277 aEmptyStr );
278 pOV->InsertText(aChars, sal_True);
279
280 // attributieren (Font setzen)
281 SfxItemSet aSet(pOL->GetEmptyItemSet());
282 SvxFontItem aFontItem (aFont.GetFamily(), aFont.GetName(),
283 aFont.GetStyleName(), aFont.GetPitch(),
284 aFont.GetCharSet(),
285 EE_CHAR_FONTINFO);
286 aSet.Put(aFontItem);
287 aSet.Put(aFontItem, EE_CHAR_FONTINFO_CJK);
288 aSet.Put(aFontItem, EE_CHAR_FONTINFO_CTL);
289 pOV->SetAttribs(aSet);
290
291 ESelection aSel = pOV->GetSelection();
292 aSel.nStartPara = aSel.nEndPara;
293 aSel.nStartPos = aSel.nEndPos;
294 pOV->SetSelection(aSel);
295
296 // nicht mit Sonderzeichenattributierung weiterschreiben
297 pOV->GetOutliner()->QuickSetAttribs(aOldSet, aSel);
298
299 rUndoMgr.LeaveListAction();
300
301 // ab jetzt wieder anzeigen
302 pOL->SetUpdateMode(sal_True);
303 pOV->ShowCursor();
304 }
305 }
306 }
307
GetSlotState(SfxItemSet & rSet,ViewShell * pViewShell,SfxViewFrame * pViewFrame)308 void FuBullet::GetSlotState( SfxItemSet& rSet, ViewShell* pViewShell, SfxViewFrame* pViewFrame )
309 {
310 if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_CHARMAP ) ||
311 SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_SOFT_HYPHEN ) ||
312 SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_HARDHYPHEN ) ||
313 SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_HARD_SPACE ) ||
314 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_RLM ) ||
315 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_LRM ) ||
316 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_ZWNBSP ) ||
317 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_ZWSP ))
318 {
319 ::sd::View* pView = pViewShell ? pViewShell->GetView() : 0;
320 OutlinerView* pOLV = pView ? pView->GetTextEditOutlinerView() : 0;
321
322 const bool bTextEdit = pOLV;
323
324 SvtCTLOptions aCTLOptions;
325 const sal_Bool bCtlEnabled = aCTLOptions.IsCTLFontEnabled();
326
327 if(!bTextEdit )
328 {
329 rSet.DisableItem(FN_INSERT_SOFT_HYPHEN);
330 rSet.DisableItem(FN_INSERT_HARDHYPHEN);
331 rSet.DisableItem(FN_INSERT_HARD_SPACE);
332 }
333
334 if( !bTextEdit && (dynamic_cast<OutlineViewShell*>( pViewShell ) == 0) )
335 rSet.DisableItem(SID_CHARMAP);
336
337 if(!bTextEdit || !bCtlEnabled )
338 {
339 rSet.DisableItem(SID_INSERT_RLM);
340 rSet.DisableItem(SID_INSERT_LRM);
341 rSet.DisableItem(SID_INSERT_ZWNBSP);
342 rSet.DisableItem(SID_INSERT_ZWSP);
343 }
344
345 if( pViewFrame )
346 {
347 SfxBindings& rBindings = pViewFrame->GetBindings();
348
349 rBindings.SetVisibleState( SID_INSERT_RLM, bCtlEnabled );
350 rBindings.SetVisibleState( SID_INSERT_LRM, bCtlEnabled );
351 rBindings.SetVisibleState( SID_INSERT_ZWNBSP, bCtlEnabled );
352 rBindings.SetVisibleState( SID_INSERT_ZWSP, bCtlEnabled );
353 }
354 }
355 }
356 } // end of namespace sd
357