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, INetURLObject::DECODE_UNAMBIGUOUS, 284 RTL_TEXTENCODING_UTF8 ) ); 285 aURLED.SaveValue(); 286 aNameED.SetText( pINetFmt->GetName() ); 287 288 String sEntry = pINetFmt->GetVisitedFmt(); 289 if ( sEntry.Len() == 0 ) 290 { 291 ASSERT( false, "<SwCharURLPage::Reset(..)> - missing visited character format at hyperlink attribute" ); 292 SwStyleNameMapper::FillUIName( RES_POOLCHR_INET_VISIT, sEntry ); 293 } 294 aVisitedLB.SelectEntry( sEntry ); 295 296 sEntry = pINetFmt->GetINetFmt(); 297 if ( sEntry.Len() == 0 ) 298 { 299 ASSERT( false, "<SwCharURLPage::Reset(..)> - missing unvisited character format at hyperlink attribute" ); 300 SwStyleNameMapper::FillUIName( RES_POOLCHR_INET_NORMAL, sEntry ); 301 } 302 aNotVisitedLB.SelectEntry( sEntry ); 303 304 aTargetFrmLB.SetText(pINetFmt->GetTargetFrame()); 305 aVisitedLB. SaveValue(); 306 aNotVisitedLB.SaveValue(); 307 aTargetFrmLB. SaveValue(); 308 pINetItem = new SvxMacroItem(FN_INET_FIELD_MACRO); 309 310 if( pINetFmt->GetMacroTbl() ) 311 pINetItem->SetMacroTable( *pINetFmt->GetMacroTbl() ); 312 } 313 if(SFX_ITEM_SET == rSet.GetItemState(FN_PARAM_SELECTION, sal_False, &pItem)) 314 { 315 aTextED.SetText(((const SfxStringItem*)pItem)->GetValue()); 316 aTextFT.Enable( sal_False ); 317 aTextED.Enable( sal_False ); 318 } 319 } 320 321 /*-----------------14.08.96 11.32------------------- 322 323 --------------------------------------------------*/ 324 325 sal_Bool SwCharURLPage::FillItemSet(SfxItemSet& rSet) 326 { 327 ::rtl::OUString sURL = aURLED.GetText(); 328 if(sURL.getLength()) 329 { 330 sURL = URIHelper::SmartRel2Abs(INetURLObject(), sURL, Link(), false ); 331 // #i100683# file URLs should be normalized in the UI 332 static const sal_Char* pFile = "file:"; 333 sal_Int32 nLength = ((sal_Int32)sizeof(pFile)-1); 334 if( sURL.copy(0, nLength ).equalsAsciiL( pFile, nLength )) 335 sURL = URIHelper::simpleNormalizedMakeRelative(::rtl::OUString(), sURL); 336 } 337 338 SwFmtINetFmt aINetFmt(sURL, aTargetFrmLB.GetText()); 339 aINetFmt.SetName(aNameED.GetText()); 340 bModified |= aURLED.GetText() != aURLED.GetSavedValue(); 341 bModified |= aNameED.IsModified(); 342 bModified |= aTargetFrmLB.GetSavedValue() != aTargetFrmLB.GetText(); 343 344 //zuerst die gueltigen Einstellungen setzen 345 String sEntry = aVisitedLB.GetSelectEntry(); 346 sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT); 347 aINetFmt.SetVisitedFmtAndId( sEntry, nId ); 348 349 sEntry = aNotVisitedLB.GetSelectEntry(); 350 nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT); 351 aINetFmt.SetINetFmtAndId( sEntry, nId ); 352 353 if( pINetItem && pINetItem->GetMacroTable().Count() ) 354 aINetFmt.SetMacroTbl( &pINetItem->GetMacroTable() ); 355 356 if(aVisitedLB.GetSavedValue() != aVisitedLB.GetSelectEntryPos()) 357 bModified = sal_True; 358 359 if(aNotVisitedLB.GetSavedValue() != aNotVisitedLB.GetSelectEntryPos()) 360 bModified = sal_True; 361 362 if(aTextED.IsModified()) 363 { 364 bModified = sal_True; 365 rSet.Put(SfxStringItem(FN_PARAM_SELECTION, aTextED.GetText())); 366 } 367 if(bModified) 368 rSet.Put(aINetFmt); 369 return bModified; 370 } 371 372 373 /*-----------------14.08.96 11.30------------------- 374 375 --------------------------------------------------*/ 376 377 SfxTabPage* SwCharURLPage::Create( Window* pParent, 378 const SfxItemSet& rAttrSet ) 379 { 380 return ( new SwCharURLPage( pParent, rAttrSet ) ); 381 } 382 383 /*-----------------14.08.96 15.00------------------- 384 385 --------------------------------------------------*/ 386 387 IMPL_LINK( SwCharURLPage, InsertFileHdl, PushButton *, EMPTYARG ) 388 { 389 FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 ); 390 if( aDlgHelper.Execute() == ERRCODE_NONE ) 391 { 392 Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); 393 aURLED.SetText(xFP->getFiles().getConstArray()[0]); 394 } 395 return 0; 396 } 397 /*-----------------14.08.96 15.00------------------- 398 399 --------------------------------------------------*/ 400 401 IMPL_LINK( SwCharURLPage, EventHdl, PushButton *, EMPTYARG ) 402 { 403 bModified |= SwMacroAssignDlg::INetFmtDlg( this, 404 ::GetActiveView()->GetWrtShell(), pINetItem ); 405 return 0; 406 } 407 408 409