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