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_sw.hxx" 30 31 #ifdef SW_DLLIMPLEMENTATION 32 #undef SW_DLLIMPLEMENTATION 33 #endif 34 35 36 #include <hintids.hxx> 37 38 #ifndef _MSGBOX_HXX //autogen 39 #include <vcl/msgbox.hxx> 40 #endif 41 #include <svl/urihelper.hxx> 42 #include <svl/stritem.hxx> 43 #include <editeng/flstitem.hxx> 44 #include <svx/htmlmode.hxx> 45 #include <svl/cjkoptions.hxx> 46 47 #ifndef _CMDID_H 48 #include <cmdid.h> 49 #endif 50 #ifndef _HELPID_H 51 #include <helpid.h> 52 #endif 53 #include <swtypes.hxx> 54 #include <errhdl.hxx> 55 #ifndef _VIEW_HXX 56 #include <view.hxx> 57 #endif 58 #include <wrtsh.hxx> 59 #ifndef _DOCSH_HXX 60 #include <docsh.hxx> 61 #endif 62 #include <uitool.hxx> 63 #include <fmtinfmt.hxx> 64 #include <macassgn.hxx> 65 #ifndef _CHRDLG_HXX 66 #include <chrdlg.hxx> // der Dialog 67 #endif 68 #include <swmodule.hxx> 69 #include <poolfmt.hxx> 70 71 #ifndef _GLOBALS_HRC 72 #include <globals.hrc> 73 #endif 74 #ifndef _CHRDLG_HRC 75 #include <chrdlg.hrc> 76 #endif 77 #ifndef _CHARDLG_HRC 78 #include <chardlg.hrc> 79 #endif 80 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> 81 #include <com/sun/star/ui/dialogs/XFilePicker.hpp> 82 #include <SwStyleNameMapper.hxx> 83 #include <sfx2/filedlghelper.hxx> 84 #include <sfx2/viewfrm.hxx> 85 86 #include <svx/svxdlg.hxx> 87 #include <svx/svxids.hrc> 88 #include <svx/flagsdef.hxx> 89 #include <svx/dialogs.hrc> 90 91 using namespace ::com::sun::star::ui::dialogs; 92 using namespace ::com::sun::star::lang; 93 using namespace ::com::sun::star::uno; 94 using namespace ::sfx2; 95 96 /*-------------------------------------------------------------------- 97 Beschreibung: Der Traeger des Dialoges 98 --------------------------------------------------------------------*/ 99 100 101 SwCharDlg::SwCharDlg(Window* pParent, SwView& rVw, const SfxItemSet& rCoreSet, 102 const String* pStr, sal_Bool bIsDrwTxtDlg) : 103 SfxTabDialog(pParent, SW_RES(DLG_CHAR), &rCoreSet, pStr != 0), 104 rView(rVw), 105 bIsDrwTxtMode(bIsDrwTxtDlg) 106 { 107 FreeResource(); 108 109 // bspFonr fuer beide Bsp-TabPages 110 111 if(pStr) 112 { 113 String aTmp( GetText() ); 114 aTmp += SW_RESSTR(STR_TEXTCOLL_HEADER); 115 aTmp += *pStr; 116 aTmp += ')'; 117 SetText(aTmp); 118 } 119 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); 120 DBG_ASSERT(pFact, "Dialogdiet fail!"); 121 AddTabPage(TP_CHAR_STD, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_NAME ), 0 ); 122 AddTabPage(TP_CHAR_EXT, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_EFFECTS ), 0 ); 123 AddTabPage(TP_CHAR_POS, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_POSITION ), 0 ); 124 AddTabPage(TP_CHAR_TWOLN, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_TWOLINES ), 0 ); 125 AddTabPage(TP_CHAR_URL, SwCharURLPage::Create, 0); 126 AddTabPage(TP_BACKGROUND, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0 ); 127 128 SvtCJKOptions aCJKOptions; 129 if(bIsDrwTxtMode) 130 { 131 RemoveTabPage( TP_CHAR_URL ); 132 RemoveTabPage( TP_BACKGROUND ); 133 RemoveTabPage( TP_CHAR_TWOLN ); 134 } 135 else if(!aCJKOptions.IsDoubleLinesEnabled()) 136 RemoveTabPage( TP_CHAR_TWOLN ); 137 } 138 /*-------------------------------------------------------------------- 139 Beschreibung: 140 --------------------------------------------------------------------*/ 141 142 143 SwCharDlg::~SwCharDlg() 144 { 145 } 146 147 /*-------------------------------------------------------------------- 148 Beschreibung: FontList setzen 149 --------------------------------------------------------------------*/ 150 151 152 153 void SwCharDlg::PageCreated( sal_uInt16 nId, SfxTabPage &rPage ) 154 { 155 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool())); 156 switch( nId ) 157 { 158 case TP_CHAR_STD: 159 { 160 SvxFontListItem aFontListItem( *( (SvxFontListItem*) 161 ( rView.GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST ) ) ) ); 162 aSet.Put (SvxFontListItem( aFontListItem.GetFontList(), SID_ATTR_CHAR_FONTLIST)); 163 if(!bIsDrwTxtMode) 164 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER)); 165 rPage.PageCreated(aSet); 166 } 167 break; 168 case TP_CHAR_EXT: 169 if(bIsDrwTxtMode) 170 aSet.Put (SfxUInt16Item(SID_DISABLE_CTL,DISABLE_CASEMAP)); 171 172 else 173 { 174 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER|SVX_ENABLE_FLASH)); 175 } 176 rPage.PageCreated(aSet); 177 break; 178 case TP_CHAR_POS: 179 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER)); 180 rPage.PageCreated(aSet); 181 break; 182 case TP_CHAR_TWOLN: 183 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER)); 184 rPage.PageCreated(aSet); 185 break; 186 } 187 } 188 189 /*-----------------14.08.96 11.28------------------- 190 191 --------------------------------------------------*/ 192 193 SwCharURLPage::SwCharURLPage( Window* pParent, 194 const SfxItemSet& rCoreSet ) : 195 SfxTabPage( pParent, SW_RES( TP_CHAR_URL ), rCoreSet ), 196 aURLFL ( this, SW_RES(FL_URL)), 197 198 aURLFT( this, SW_RES(FT_URL )), 199 aURLED( this, SW_RES(ED_URL )), 200 aTextFT( this, SW_RES(FT_TEXT )), 201 aTextED( this, SW_RES(ED_TEXT )), 202 aNameFT( this, SW_RES(FT_NAME )), 203 aNameED( this, SW_RES(ED_NAME)), 204 aTargetFrmFT( this, SW_RES(FT_TARGET )), 205 aTargetFrmLB( this, SW_RES(LB_TARGET )), 206 aURLPB( this, SW_RES(PB_URL )), 207 aEventPB( this, SW_RES(PB_EVENT )), 208 aStyleFL( this, SW_RES(FL_STYLE )), 209 aVisitedFT( this, SW_RES(FT_VISITED )), 210 aVisitedLB( this, SW_RES(LB_VISITED )), 211 aNotVisitedFT( this, SW_RES(FT_NOT_VISITED)), 212 aNotVisitedLB( this, SW_RES(LB_NOT_VISITED)), 213 pINetItem(0), 214 bModified(sal_False) 215 216 { 217 FreeResource(); 218 219 aEventPB.SetAccessibleRelationMemberOf(&aURLFL); 220 221 const SfxPoolItem* pItem; 222 SfxObjectShell* pShell; 223 if(SFX_ITEM_SET == rCoreSet.GetItemState(SID_HTML_MODE, sal_False, &pItem) || 224 ( 0 != ( pShell = SfxObjectShell::Current()) && 225 0 != (pItem = pShell->GetItem(SID_HTML_MODE)))) 226 { 227 sal_uInt16 nHtmlMode = ((const SfxUInt16Item*)pItem)->GetValue(); 228 if(HTMLMODE_ON & nHtmlMode) 229 { 230 aStyleFL.Hide(); 231 aVisitedFT.Hide(); 232 aVisitedLB.Hide(); 233 aNotVisitedFT.Hide(); 234 aNotVisitedLB.Hide(); 235 } 236 } 237 238 aURLPB.SetClickHdl (LINK( this, SwCharURLPage, InsertFileHdl)); 239 aEventPB.SetClickHdl(LINK( this, SwCharURLPage, EventHdl )); 240 241 SwView *pView = ::GetActiveView(); 242 ::FillCharStyleListBox(aVisitedLB, pView->GetDocShell()); 243 ::FillCharStyleListBox(aNotVisitedLB, pView->GetDocShell()); 244 245 TargetList* pList = new TargetList; 246 const SfxFrame& rFrame = pView->GetViewFrame()->GetTopFrame(); 247 rFrame.GetTargetList(*pList); 248 sal_uInt16 nCount = (sal_uInt16)pList->Count(); 249 if( nCount ) 250 { 251 sal_uInt16 i; 252 253 for ( i = 0; i < nCount; i++ ) 254 { 255 aTargetFrmLB.InsertEntry(*pList->GetObject(i)); 256 } 257 for ( i = nCount; i; i-- ) 258 { 259 delete pList->GetObject( i - 1 ); 260 } 261 } 262 delete pList; 263 264 265 } 266 267 /*-----------------15.08.96 09.04------------------- 268 269 --------------------------------------------------*/ 270 271 SwCharURLPage::~SwCharURLPage() 272 { 273 delete pINetItem; 274 } 275 276 /*-----------------14.08.96 11.31------------------- 277 278 --------------------------------------------------*/ 279 280 void SwCharURLPage::Reset(const SfxItemSet& rSet) 281 { 282 const SfxPoolItem* pItem; 283 if(SFX_ITEM_SET == rSet.GetItemState(RES_TXTATR_INETFMT, sal_False, &pItem)) 284 { 285 const SwFmtINetFmt* pINetFmt = (const SwFmtINetFmt*)pItem; 286 aURLED.SetText( INetURLObject::decode( pINetFmt->GetValue(), 287 INET_HEX_ESCAPE, 288 INetURLObject::DECODE_UNAMBIGUOUS, 289 RTL_TEXTENCODING_UTF8 )); 290 aURLED.SaveValue(); 291 aNameED.SetText(pINetFmt->GetName()); 292 String sEntry = pINetFmt->GetVisitedFmt(); 293 if( !sEntry.Len() ) 294 SwStyleNameMapper::FillUIName( RES_POOLCHR_INET_VISIT, sEntry ); 295 aVisitedLB.SelectEntry(sEntry); 296 sEntry = pINetFmt->GetINetFmt(); 297 if(!sEntry.Len()) 298 SwStyleNameMapper::FillUIName( RES_POOLCHR_INET_NORMAL, sEntry ); 299 aNotVisitedLB.SelectEntry(sEntry); 300 301 aTargetFrmLB.SetText(pINetFmt->GetTargetFrame()); 302 aVisitedLB. SaveValue(); 303 aNotVisitedLB.SaveValue(); 304 aTargetFrmLB. SaveValue(); 305 pINetItem = new SvxMacroItem(FN_INET_FIELD_MACRO); 306 307 if( pINetFmt->GetMacroTbl() ) 308 pINetItem->SetMacroTable( *pINetFmt->GetMacroTbl() ); 309 } 310 if(SFX_ITEM_SET == rSet.GetItemState(FN_PARAM_SELECTION, sal_False, &pItem)) 311 { 312 aTextED.SetText(((const SfxStringItem*)pItem)->GetValue()); 313 aTextFT.Enable( sal_False ); 314 aTextED.Enable( sal_False ); 315 } 316 } 317 318 /*-----------------14.08.96 11.32------------------- 319 320 --------------------------------------------------*/ 321 322 sal_Bool SwCharURLPage::FillItemSet(SfxItemSet& rSet) 323 { 324 ::rtl::OUString sURL = aURLED.GetText(); 325 if(sURL.getLength()) 326 { 327 sURL = URIHelper::SmartRel2Abs(INetURLObject(), sURL, Link(), false ); 328 // #i100683# file URLs should be normalized in the UI 329 static const sal_Char* pFile = "file:"; 330 sal_Int32 nLength = ((sal_Int32)sizeof(pFile)-1); 331 if( sURL.copy(0, nLength ).equalsAsciiL( pFile, nLength )) 332 sURL = URIHelper::simpleNormalizedMakeRelative(::rtl::OUString(), sURL); 333 } 334 335 SwFmtINetFmt aINetFmt(sURL, aTargetFrmLB.GetText()); 336 aINetFmt.SetName(aNameED.GetText()); 337 bModified |= aURLED.GetText() != aURLED.GetSavedValue(); 338 bModified |= aNameED.IsModified(); 339 bModified |= aTargetFrmLB.GetSavedValue() != aTargetFrmLB.GetText(); 340 341 //zuerst die gueltigen Einstellungen setzen 342 String sEntry = aVisitedLB.GetSelectEntry(); 343 sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT); 344 aINetFmt.SetVisitedFmtId(nId); 345 aINetFmt.SetVisitedFmt(nId == RES_POOLCHR_INET_VISIT ? aEmptyStr : sEntry); 346 347 sEntry = aNotVisitedLB.GetSelectEntry(); 348 nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT); 349 aINetFmt.SetINetFmtId( nId ); 350 aINetFmt.SetINetFmt(nId == RES_POOLCHR_INET_NORMAL ? aEmptyStr : sEntry); 351 352 if( pINetItem && pINetItem->GetMacroTable().Count() ) 353 aINetFmt.SetMacroTbl( &pINetItem->GetMacroTable() ); 354 355 if(aVisitedLB.GetSavedValue() != aVisitedLB.GetSelectEntryPos()) 356 bModified = sal_True; 357 358 if(aNotVisitedLB.GetSavedValue() != aNotVisitedLB.GetSelectEntryPos()) 359 bModified = sal_True; 360 361 if(aTextED.IsModified()) 362 { 363 bModified = sal_True; 364 rSet.Put(SfxStringItem(FN_PARAM_SELECTION, aTextED.GetText())); 365 } 366 if(bModified) 367 rSet.Put(aINetFmt); 368 return bModified; 369 } 370 371 372 /*-----------------14.08.96 11.30------------------- 373 374 --------------------------------------------------*/ 375 376 SfxTabPage* SwCharURLPage::Create( Window* pParent, 377 const SfxItemSet& rAttrSet ) 378 { 379 return ( new SwCharURLPage( pParent, rAttrSet ) ); 380 } 381 382 /*-----------------14.08.96 15.00------------------- 383 384 --------------------------------------------------*/ 385 386 IMPL_LINK( SwCharURLPage, InsertFileHdl, PushButton *, EMPTYARG ) 387 { 388 FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 ); 389 if( aDlgHelper.Execute() == ERRCODE_NONE ) 390 { 391 Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); 392 aURLED.SetText(xFP->getFiles().getConstArray()[0]); 393 } 394 return 0; 395 } 396 /*-----------------14.08.96 15.00------------------- 397 398 --------------------------------------------------*/ 399 400 IMPL_LINK( SwCharURLPage, EventHdl, PushButton *, EMPTYARG ) 401 { 402 bModified |= SwMacroAssignDlg::INetFmtDlg( this, 403 ::GetActiveView()->GetWrtShell(), pINetItem ); 404 return 0; 405 } 406 407 408