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