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 0 : FuBullet::FuBullet (
58 : ViewShell* pViewSh,
59 : ::sd::Window* pWin,
60 : ::sd::View* _pView,
61 : SdDrawDocument* pDoc,
62 : SfxRequest& rReq)
63 0 : : FuPoor(pViewSh, pWin, _pView, pDoc, rReq)
64 : {
65 0 : }
66 :
67 0 : rtl::Reference<FuPoor> FuBullet::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
68 : {
69 0 : rtl::Reference<FuPoor> xFunc( new FuBullet( pViewSh, pWin, pView, pDoc, rReq ) );
70 0 : xFunc->DoExecute(rReq);
71 0 : return xFunc;
72 : }
73 :
74 0 : void FuBullet::DoExecute( SfxRequest& rReq )
75 : {
76 0 : if( rReq.GetSlot() == SID_CHARMAP )
77 0 : InsertSpecialCharacter(rReq);
78 : else
79 : {
80 0 : sal_Unicode cMark = 0;
81 0 : switch( rReq.GetSlot() )
82 : {
83 0 : case FN_INSERT_SOFT_HYPHEN: cMark = CHAR_SOFTHYPHEN ; break;
84 0 : case FN_INSERT_HARDHYPHEN: cMark = CHAR_HARDHYPHEN ; break;
85 0 : case FN_INSERT_HARD_SPACE: cMark = CHAR_HARDBLANK ; break;
86 0 : case SID_INSERT_RLM : cMark = CHAR_RLM ; break;
87 0 : case SID_INSERT_LRM : cMark = CHAR_LRM ; break;
88 0 : case SID_INSERT_ZWSP : cMark = CHAR_ZWSP ; break;
89 0 : case SID_INSERT_ZWNBSP: cMark = CHAR_ZWNBSP; break;
90 : }
91 :
92 : DBG_ASSERT( cMark != 0, "FuBullet::FuBullet(), illegal slot used!" );
93 :
94 0 : if( cMark )
95 0 : InsertFormattingMark( cMark );
96 : }
97 :
98 0 : }
99 :
100 0 : void FuBullet::InsertFormattingMark( sal_Unicode cMark )
101 : {
102 0 : OutlinerView* pOV = NULL;
103 0 : ::Outliner* pOL = NULL;
104 :
105 : // depending on ViewShell set Outliner and OutlinerView
106 0 : if (mpViewShell->ISA(DrawViewShell))
107 : {
108 0 : pOV = mpView->GetTextEditOutlinerView();
109 0 : if (pOV)
110 0 : pOL = mpView->GetTextEditOutliner();
111 : }
112 0 : else if (mpViewShell->ISA(OutlineViewShell))
113 : {
114 0 : pOL = static_cast<OutlineView*>(mpView)->GetOutliner();
115 : pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
116 0 : mpViewShell->GetActiveWindow());
117 : }
118 :
119 : // insert string
120 0 : if(pOV && pOL)
121 : {
122 : // prevent flickering
123 0 : pOV->HideCursor();
124 0 : pOL->SetUpdateMode(false);
125 :
126 : // remove old selected text
127 0 : pOV->InsertText( aEmptyStr );
128 :
129 : // prepare undo
130 0 : ::svl::IUndoManager& rUndoMgr = pOL->GetUndoManager();
131 : rUndoMgr.EnterListAction(SD_RESSTR(STR_UNDO_INSERT_SPECCHAR),
132 0 : aEmptyStr );
133 :
134 : // insert given text
135 0 : OUString aStr( cMark );
136 0 : pOV->InsertText( aStr, true);
137 :
138 0 : ESelection aSel = pOV->GetSelection();
139 0 : aSel.nStartPara = aSel.nEndPara;
140 0 : aSel.nStartPos = aSel.nEndPos;
141 0 : pOV->SetSelection(aSel);
142 :
143 0 : rUndoMgr.LeaveListAction();
144 :
145 : // restart repainting
146 0 : pOL->SetUpdateMode(true);
147 0 : pOV->ShowCursor();
148 : }
149 0 : }
150 :
151 0 : void FuBullet::InsertSpecialCharacter( SfxRequest& rReq )
152 : {
153 0 : const SfxItemSet *pArgs = rReq.GetArgs();
154 0 : const SfxPoolItem* pItem = 0;
155 0 : if( pArgs )
156 0 : pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_CHARMAP), false, &pItem);
157 :
158 0 : OUString aChars;
159 0 : Font aFont;
160 0 : if ( pItem )
161 : {
162 0 : aChars = ((const SfxStringItem*)pItem)->GetValue();
163 0 : const SfxPoolItem* pFtItem = NULL;
164 0 : pArgs->GetItemState( mpDoc->GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
165 0 : const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
166 0 : if ( pFontItem )
167 : {
168 0 : OUString aFontName = pFontItem->GetValue();
169 0 : aFont = Font( aFontName, Size(1,1) );
170 : }
171 : else
172 : {
173 0 : SfxItemSet aFontAttr( mpDoc->GetPool() );
174 0 : mpView->GetAttributes( aFontAttr );
175 0 : const SvxFontItem* pFItem = (const SvxFontItem*)aFontAttr.GetItem( SID_ATTR_CHAR_FONT );
176 0 : if( pFItem )
177 0 : aFont = Font( pFItem->GetFamilyName(), pFItem->GetStyleName(), Size( 1, 1 ) );
178 : }
179 : }
180 :
181 0 : if (aChars.isEmpty())
182 : {
183 0 : SfxAllItemSet aSet( mpDoc->GetPool() );
184 0 : aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
185 :
186 0 : SfxItemSet aFontAttr( mpDoc->GetPool() );
187 0 : mpView->GetAttributes( aFontAttr );
188 0 : const SvxFontItem* pFontItem = (const SvxFontItem*)aFontAttr.GetItem( SID_ATTR_CHAR_FONT );
189 0 : if( pFontItem )
190 0 : aSet.Put( *pFontItem );
191 :
192 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
193 0 : SfxAbstractDialog* pDlg = pFact ? pFact->CreateSfxDialog( &mpView->GetViewShell()->GetViewFrame()->GetWindow(), aSet,
194 0 : mpView->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface(),
195 0 : RID_SVXDLG_CHARMAP ) : 0;
196 0 : if( !pDlg )
197 0 : return;
198 :
199 : // If a character is selected, it can be shown
200 : // pDLg->SetFont( );
201 : // pDlg->SetChar( );
202 0 : sal_uInt16 nResult = pDlg->Execute();
203 0 : if( nResult == RET_OK )
204 : {
205 0 : SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, false );
206 0 : SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFItem, SvxFontItem, SID_ATTR_CHAR_FONT, false );
207 0 : if ( pFItem )
208 : {
209 0 : aFont.SetName( pFItem->GetFamilyName() );
210 0 : aFont.SetStyleName( pFItem->GetStyleName() );
211 0 : aFont.SetCharSet( pFItem->GetCharSet() );
212 0 : aFont.SetPitch( pFItem->GetPitch() );
213 : }
214 :
215 0 : if ( pCItem )
216 0 : aChars = pCItem->GetValue();
217 : }
218 :
219 0 : delete( pDlg );
220 : }
221 :
222 0 : if (!aChars.isEmpty())
223 : {
224 0 : OutlinerView* pOV = NULL;
225 0 : ::Outliner* pOL = NULL;
226 :
227 : // determine depending on ViewShell Outliner and OutlinerView
228 0 : if(mpViewShell && mpViewShell->ISA(DrawViewShell))
229 : {
230 0 : pOV = mpView->GetTextEditOutlinerView();
231 0 : if (pOV)
232 : {
233 0 : pOL = mpView->GetTextEditOutliner();
234 : }
235 : }
236 0 : else if(mpViewShell && mpViewShell->ISA(OutlineViewShell))
237 : {
238 0 : pOL = static_cast<OutlineView*>(mpView)->GetOutliner();
239 : pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
240 0 : mpViewShell->GetActiveWindow());
241 : }
242 :
243 : // insert special character
244 0 : if (pOV)
245 : {
246 : // prevent flicker
247 0 : pOV->HideCursor();
248 0 : pOL->SetUpdateMode(false);
249 :
250 : /* remember old attributes:
251 : To do that, remove selected area before (it has to go anyway).
252 : With that, we get unique attributes (and since there is no
253 : DeleteSelected() in OutlinerView, it is deleted by inserting an
254 : empty string). */
255 0 : pOV->InsertText( aEmptyStr );
256 :
257 0 : SfxItemSet aOldSet( mpDoc->GetPool(), EE_CHAR_FONTINFO, EE_CHAR_FONTINFO, 0 );
258 0 : aOldSet.Put( pOV->GetAttribs() );
259 :
260 0 : ::svl::IUndoManager& rUndoMgr = pOL->GetUndoManager();
261 : rUndoMgr.EnterListAction(SD_RESSTR(STR_UNDO_INSERT_SPECCHAR),
262 0 : aEmptyStr );
263 0 : pOV->InsertText(aChars, true);
264 :
265 : // set attributes (set font)
266 0 : SfxItemSet aSet(pOL->GetEmptyItemSet());
267 0 : SvxFontItem aFontItem (aFont.GetFamily(), aFont.GetName(),
268 0 : aFont.GetStyleName(), aFont.GetPitch(),
269 0 : aFont.GetCharSet(),
270 0 : EE_CHAR_FONTINFO);
271 0 : aSet.Put(aFontItem);
272 0 : aSet.Put(aFontItem, EE_CHAR_FONTINFO_CJK);
273 0 : aSet.Put(aFontItem, EE_CHAR_FONTINFO_CTL);
274 0 : pOV->SetAttribs(aSet);
275 :
276 0 : ESelection aSel = pOV->GetSelection();
277 0 : aSel.nStartPara = aSel.nEndPara;
278 0 : aSel.nStartPos = aSel.nEndPos;
279 0 : pOV->SetSelection(aSel);
280 :
281 : // do not go ahead with setting attributes of special characters
282 0 : pOV->GetOutliner()->QuickSetAttribs(aOldSet, aSel);
283 :
284 0 : rUndoMgr.LeaveListAction();
285 :
286 : // show it again
287 0 : pOL->SetUpdateMode(true);
288 0 : pOV->ShowCursor();
289 : }
290 0 : }
291 : }
292 :
293 0 : void FuBullet::GetSlotState( SfxItemSet& rSet, ViewShell* pViewShell, SfxViewFrame* pViewFrame )
294 : {
295 0 : if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_CHARMAP ) ||
296 0 : SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_SOFT_HYPHEN ) ||
297 0 : SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_HARDHYPHEN ) ||
298 0 : SFX_ITEM_AVAILABLE == rSet.GetItemState( FN_INSERT_HARD_SPACE ) ||
299 0 : SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_RLM ) ||
300 0 : SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_LRM ) ||
301 0 : SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_ZWNBSP ) ||
302 0 : SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_INSERT_ZWSP ))
303 : {
304 0 : ::sd::View* pView = pViewShell ? pViewShell->GetView() : 0;
305 0 : OutlinerView* pOLV = pView ? pView->GetTextEditOutlinerView() : 0;
306 :
307 0 : const bool bTextEdit = pOLV;
308 :
309 0 : SvtCTLOptions aCTLOptions;
310 0 : const sal_Bool bCtlEnabled = aCTLOptions.IsCTLFontEnabled();
311 :
312 0 : if(!bTextEdit )
313 : {
314 0 : rSet.DisableItem(FN_INSERT_SOFT_HYPHEN);
315 0 : rSet.DisableItem(FN_INSERT_HARDHYPHEN);
316 0 : rSet.DisableItem(FN_INSERT_HARD_SPACE);
317 : }
318 :
319 0 : if( !bTextEdit && (dynamic_cast<OutlineViewShell*>( pViewShell ) == 0) )
320 0 : rSet.DisableItem(SID_CHARMAP);
321 :
322 0 : if(!bTextEdit || !bCtlEnabled )
323 : {
324 0 : rSet.DisableItem(SID_INSERT_RLM);
325 0 : rSet.DisableItem(SID_INSERT_LRM);
326 0 : rSet.DisableItem(SID_INSERT_ZWNBSP);
327 0 : rSet.DisableItem(SID_INSERT_ZWSP);
328 : }
329 :
330 0 : if( pViewFrame )
331 : {
332 0 : SfxBindings& rBindings = pViewFrame->GetBindings();
333 :
334 0 : rBindings.SetVisibleState( SID_INSERT_RLM, bCtlEnabled );
335 0 : rBindings.SetVisibleState( SID_INSERT_LRM, bCtlEnabled );
336 0 : rBindings.SetVisibleState( SID_INSERT_ZWNBSP, bCtlEnabled );
337 0 : rBindings.SetVisibleState( SID_INSERT_ZWSP, bCtlEnabled );
338 0 : }
339 : }
340 0 : }
341 0 : } // end of namespace sd
342 :
343 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|