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 <hintids.hxx>
21 :
22 : #include <vcl/msgbox.hxx>
23 : #include <svl/urihelper.hxx>
24 : #include <svl/stritem.hxx>
25 : #include <editeng/flstitem.hxx>
26 : #include <svx/htmlmode.hxx>
27 : #include <svl/cjkoptions.hxx>
28 :
29 : #include <cmdid.h>
30 : #include <helpid.h>
31 : #include <swtypes.hxx>
32 : #include <view.hxx>
33 : #include <wrtsh.hxx>
34 : #include <docsh.hxx>
35 : #include <uitool.hxx>
36 : #include <fmtinfmt.hxx>
37 : #include <macassgn.hxx>
38 : #include <chrdlg.hxx> // the dialog
39 : #include <swmodule.hxx>
40 : #include <poolfmt.hxx>
41 :
42 : #include <globals.hrc>
43 : #include <chrdlg.hrc>
44 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
45 : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
46 : #include <SwStyleNameMapper.hxx>
47 : #include <sfx2/filedlghelper.hxx>
48 : #include <sfx2/viewfrm.hxx>
49 :
50 : #include <svx/svxdlg.hxx>
51 : #include <svx/svxids.hrc>
52 : #include <svx/flagsdef.hxx>
53 : #include <svx/dialogs.hrc>
54 :
55 : using namespace ::com::sun::star::ui::dialogs;
56 : using namespace ::com::sun::star::lang;
57 : using namespace ::com::sun::star::uno;
58 : using namespace ::sfx2;
59 :
60 0 : SwCharDlg::SwCharDlg(Window* pParent, SwView& rVw, const SfxItemSet& rCoreSet,
61 : const String* pStr, sal_Bool bIsDrwTxtDlg) :
62 : SfxTabDialog(pParent, SW_RES(DLG_CHAR), &rCoreSet, pStr != 0),
63 : rView(rVw),
64 0 : bIsDrwTxtMode(bIsDrwTxtDlg)
65 : {
66 0 : FreeResource();
67 :
68 0 : if(pStr)
69 : {
70 0 : String aTmp( GetText() );
71 0 : aTmp += SW_RESSTR(STR_TEXTCOLL_HEADER);
72 0 : aTmp += *pStr;
73 0 : aTmp += ')';
74 0 : SetText(aTmp);
75 : }
76 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
77 : OSL_ENSURE(pFact, "Dialogdiet fail!");
78 0 : AddTabPage(TP_CHAR_STD, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_NAME ), 0 );
79 0 : AddTabPage(TP_CHAR_EXT, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_EFFECTS ), 0 );
80 0 : AddTabPage(TP_CHAR_POS, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_POSITION ), 0 );
81 0 : AddTabPage(TP_CHAR_TWOLN, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_TWOLINES ), 0 );
82 0 : AddTabPage(TP_CHAR_URL, SwCharURLPage::Create, 0);
83 0 : AddTabPage(TP_BACKGROUND, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0 );
84 :
85 0 : SvtCJKOptions aCJKOptions;
86 0 : if(bIsDrwTxtMode)
87 : {
88 0 : RemoveTabPage( TP_CHAR_URL );
89 0 : RemoveTabPage( TP_BACKGROUND );
90 0 : RemoveTabPage( TP_CHAR_TWOLN );
91 : }
92 0 : else if(!aCJKOptions.IsDoubleLinesEnabled())
93 0 : RemoveTabPage( TP_CHAR_TWOLN );
94 0 : }
95 :
96 0 : SwCharDlg::~SwCharDlg()
97 : {
98 0 : }
99 :
100 : /*--------------------------------------------------------------------
101 : Description: set FontList
102 : --------------------------------------------------------------------*/
103 :
104 0 : void SwCharDlg::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
105 : {
106 0 : SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
107 0 : switch( nId )
108 : {
109 : case TP_CHAR_STD:
110 : {
111 : SvxFontListItem aFontListItem( *( (SvxFontListItem*)
112 0 : ( rView.GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST ) ) ) );
113 0 : aSet.Put (SvxFontListItem( aFontListItem.GetFontList(), SID_ATTR_CHAR_FONTLIST));
114 0 : if(!bIsDrwTxtMode)
115 0 : aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
116 0 : rPage.PageCreated(aSet);
117 : }
118 0 : break;
119 : case TP_CHAR_EXT:
120 0 : if(bIsDrwTxtMode)
121 0 : aSet.Put (SfxUInt16Item(SID_DISABLE_CTL,DISABLE_CASEMAP));
122 :
123 : else
124 : {
125 0 : aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER|SVX_ENABLE_FLASH));
126 : }
127 0 : rPage.PageCreated(aSet);
128 0 : break;
129 : case TP_CHAR_POS:
130 0 : aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
131 0 : rPage.PageCreated(aSet);
132 0 : break;
133 : case TP_CHAR_TWOLN:
134 0 : aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
135 0 : rPage.PageCreated(aSet);
136 0 : break;
137 0 : }
138 0 : }
139 :
140 0 : SwCharURLPage::SwCharURLPage(Window* pParent, const SfxItemSet& rCoreSet)
141 : : SfxTabPage(pParent, "CharURLPage", "modules/swriter/ui/charurlpage.ui", rCoreSet)
142 : , pINetItem(0)
143 0 : , bModified(sal_False)
144 :
145 : {
146 0 : get(m_pURLED, "urled");
147 0 : get(m_pTextFT, "textft");
148 0 : get(m_pTextED, "texted");
149 0 : get(m_pNameED, "nameed");
150 0 : get(m_pTargetFrmLB, "targetfrmlb");
151 0 : get(m_pURLPB, "urlpb");
152 0 : get(m_pEventPB, "eventpb");
153 0 : get(m_pVisitedLB, "visitedlb");
154 0 : get(m_pNotVisitedLB, "unvisitedlb");
155 0 : get(m_pCharStyleContainer, "charstyle");
156 :
157 : const SfxPoolItem* pItem;
158 : SfxObjectShell* pShell;
159 0 : if(SFX_ITEM_SET == rCoreSet.GetItemState(SID_HTML_MODE, sal_False, &pItem) ||
160 : ( 0 != ( pShell = SfxObjectShell::Current()) &&
161 0 : 0 != (pItem = pShell->GetItem(SID_HTML_MODE))))
162 : {
163 0 : sal_uInt16 nHtmlMode = ((const SfxUInt16Item*)pItem)->GetValue();
164 0 : if(HTMLMODE_ON & nHtmlMode)
165 0 : m_pCharStyleContainer->Hide();
166 : }
167 :
168 0 : m_pURLPB->SetClickHdl (LINK( this, SwCharURLPage, InsertFileHdl));
169 0 : m_pEventPB->SetClickHdl(LINK( this, SwCharURLPage, EventHdl ));
170 :
171 0 : SwView *pView = ::GetActiveView();
172 0 : ::FillCharStyleListBox(*m_pVisitedLB, pView->GetDocShell());
173 0 : ::FillCharStyleListBox(*m_pNotVisitedLB, pView->GetDocShell());
174 :
175 0 : TargetList* pList = new TargetList;
176 0 : const SfxFrame& rFrame = pView->GetViewFrame()->GetTopFrame();
177 0 : rFrame.GetTargetList(*pList);
178 0 : if ( !pList->empty() )
179 : {
180 0 : size_t nCount = pList->size();
181 : size_t i;
182 :
183 0 : for ( i = 0; i < nCount; i++ )
184 : {
185 0 : m_pTargetFrmLB->InsertEntry( *pList->at( i ) );
186 : }
187 0 : for ( i = nCount; i; )
188 : {
189 0 : delete pList->at( --i );
190 : }
191 : }
192 0 : delete pList;
193 0 : }
194 :
195 0 : SwCharURLPage::~SwCharURLPage()
196 : {
197 0 : delete pINetItem;
198 0 : }
199 :
200 0 : void SwCharURLPage::Reset(const SfxItemSet& rSet)
201 : {
202 : const SfxPoolItem* pItem;
203 0 : if(SFX_ITEM_SET == rSet.GetItemState(RES_TXTATR_INETFMT, sal_False, &pItem))
204 : {
205 0 : const SwFmtINetFmt* pINetFmt = (const SwFmtINetFmt*)pItem;
206 0 : m_pURLED->SetText( INetURLObject::decode( pINetFmt->GetValue(),
207 : INET_HEX_ESCAPE,
208 : INetURLObject::DECODE_UNAMBIGUOUS,
209 0 : RTL_TEXTENCODING_UTF8 ));
210 0 : m_pURLED->SaveValue();
211 0 : m_pNameED->SetText(pINetFmt->GetName());
212 0 : String sEntry = pINetFmt->GetVisitedFmt();
213 0 : if( !sEntry.Len() )
214 0 : SwStyleNameMapper::FillUIName( RES_POOLCHR_INET_VISIT, sEntry );
215 0 : m_pVisitedLB->SelectEntry(sEntry);
216 0 : sEntry = pINetFmt->GetINetFmt();
217 0 : if(!sEntry.Len())
218 0 : SwStyleNameMapper::FillUIName( RES_POOLCHR_INET_NORMAL, sEntry );
219 0 : m_pNotVisitedLB->SelectEntry(sEntry);
220 :
221 0 : m_pTargetFrmLB->SetText(pINetFmt->GetTargetFrame());
222 0 : m_pVisitedLB-> SaveValue();
223 0 : m_pNotVisitedLB->SaveValue();
224 0 : m_pTargetFrmLB-> SaveValue();
225 0 : pINetItem = new SvxMacroItem(FN_INET_FIELD_MACRO);
226 :
227 0 : if( pINetFmt->GetMacroTbl() )
228 0 : pINetItem->SetMacroTable( *pINetFmt->GetMacroTbl() );
229 : }
230 0 : if(SFX_ITEM_SET == rSet.GetItemState(FN_PARAM_SELECTION, sal_False, &pItem))
231 : {
232 0 : m_pTextED->SetText(((const SfxStringItem*)pItem)->GetValue());
233 0 : m_pTextFT->Enable( sal_False );
234 0 : m_pTextED->Enable( sal_False );
235 : }
236 0 : }
237 :
238 0 : sal_Bool SwCharURLPage::FillItemSet(SfxItemSet& rSet)
239 : {
240 0 : ::rtl::OUString sURL = m_pURLED->GetText();
241 0 : if(!sURL.isEmpty())
242 : {
243 0 : sURL = URIHelper::SmartRel2Abs(INetURLObject(), sURL, Link(), false );
244 : // #i100683# file URLs should be normalized in the UI
245 : static const sal_Char* pFile = "file:";
246 0 : sal_Int32 nLength = ((sal_Int32)sizeof(pFile)-1);
247 0 : if( sURL.copy(0, nLength ).equalsAsciiL( pFile, nLength ))
248 0 : sURL = URIHelper::simpleNormalizedMakeRelative(::rtl::OUString(), sURL);
249 : }
250 :
251 0 : SwFmtINetFmt aINetFmt(sURL, m_pTargetFrmLB->GetText());
252 0 : aINetFmt.SetName(m_pNameED->GetText());
253 0 : bModified |= m_pURLED->GetText() != m_pURLED->GetSavedValue();
254 0 : bModified |= m_pNameED->IsModified();
255 0 : bModified |= m_pTargetFrmLB->GetSavedValue() != m_pTargetFrmLB->GetText();
256 :
257 : // set valid settings first
258 0 : String sEntry = m_pVisitedLB->GetSelectEntry();
259 0 : sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
260 0 : aINetFmt.SetVisitedFmtId(nId);
261 0 : aINetFmt.SetVisitedFmt(nId == RES_POOLCHR_INET_VISIT ? aEmptyStr : sEntry);
262 :
263 0 : sEntry = m_pNotVisitedLB->GetSelectEntry();
264 0 : nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
265 0 : aINetFmt.SetINetFmtId( nId );
266 0 : aINetFmt.SetINetFmt(nId == RES_POOLCHR_INET_NORMAL ? aEmptyStr : sEntry);
267 :
268 0 : if( pINetItem && !pINetItem->GetMacroTable().empty() )
269 0 : aINetFmt.SetMacroTbl( &pINetItem->GetMacroTable() );
270 :
271 0 : if(m_pVisitedLB->GetSavedValue() != m_pVisitedLB->GetSelectEntryPos())
272 0 : bModified = sal_True;
273 :
274 0 : if(m_pNotVisitedLB->GetSavedValue() != m_pNotVisitedLB->GetSelectEntryPos())
275 0 : bModified = sal_True;
276 :
277 0 : if(m_pTextED->IsModified())
278 : {
279 0 : bModified = sal_True;
280 0 : rSet.Put(SfxStringItem(FN_PARAM_SELECTION, m_pTextED->GetText()));
281 : }
282 0 : if(bModified)
283 0 : rSet.Put(aINetFmt);
284 0 : return bModified;
285 : }
286 :
287 0 : SfxTabPage* SwCharURLPage::Create( Window* pParent,
288 : const SfxItemSet& rAttrSet )
289 : {
290 0 : return ( new SwCharURLPage( pParent, rAttrSet ) );
291 : }
292 :
293 0 : IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl)
294 : {
295 0 : FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
296 0 : if( aDlgHelper.Execute() == ERRCODE_NONE )
297 : {
298 0 : Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
299 0 : m_pURLED->SetText(xFP->getFiles().getConstArray()[0]);
300 : }
301 0 : return 0;
302 : }
303 :
304 0 : IMPL_LINK_NOARG(SwCharURLPage, EventHdl)
305 : {
306 : bModified |= SwMacroAssignDlg::INetFmtDlg( this,
307 0 : ::GetActiveView()->GetWrtShell(), pINetItem );
308 0 : return 0;
309 0 : }
310 :
311 :
312 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|