update credits
[LibreOffice.git] / sw / source / ui / chrdlg / chardlg.cxx
blobac6df95324c29343a549a550d1d954aafcc118dd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <hintids.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <svl/urihelper.hxx>
24 #include <svl/stritem.hxx>
25 #include <editeng/flstitem.hxx>
26 #include <sfx2/htmlmode.hxx>
27 #include <svl/cjkoptions.hxx>
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>
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>
50 #include <svx/svxdlg.hxx>
51 #include <svx/svxids.hrc>
52 #include <svx/flagsdef.hxx>
53 #include <svx/dialogs.hrc>
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;
60 SwCharDlg::SwCharDlg(Window* pParent, SwView& rVw, const SfxItemSet& rCoreSet,
61 const String* pStr, bool bIsDrwTxtDlg)
62 : SfxTabDialog(0, pParent, "CharacterPropertiesDialog",
63 "modules/swriter/ui/characterproperties.ui", &rCoreSet, pStr != 0)
64 , rView(rVw)
65 , bIsDrwTxtMode(bIsDrwTxtDlg)
67 if(pStr)
69 String aTmp( GetText() );
70 aTmp += SW_RESSTR(STR_TEXTCOLL_HEADER);
71 aTmp += *pStr;
72 aTmp += ')';
73 SetText(aTmp);
75 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
76 OSL_ENSURE(pFact, "Dialogdiet fail!");
77 m_nCharStdId = AddTabPage("font", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_NAME), 0);
78 m_nCharExtId = AddTabPage("fonteffects", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_EFFECTS), 0);
79 m_nCharPosId = AddTabPage("position", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_POSITION ), 0 );
80 m_nCharTwoId = AddTabPage("asianlayout", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_TWOLINES ), 0 );
81 m_nCharUrlId = AddTabPage("hyperlink", SwCharURLPage::Create, 0);
82 m_nCharBgdId = AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0 );
84 SvtCJKOptions aCJKOptions;
85 if(bIsDrwTxtMode)
87 RemoveTabPage(m_nCharUrlId);
88 RemoveTabPage(m_nCharBgdId);
89 RemoveTabPage(m_nCharTwoId);
91 else if(!aCJKOptions.IsDoubleLinesEnabled())
92 RemoveTabPage(m_nCharTwoId);
95 SwCharDlg::~SwCharDlg()
99 /*--------------------------------------------------------------------
100 Description: set FontList
101 --------------------------------------------------------------------*/
103 void SwCharDlg::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
105 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
106 if (nId == m_nCharStdId)
108 SvxFontListItem aFontListItem( *( (SvxFontListItem*)
109 ( rView.GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST ) ) ) );
110 aSet.Put (SvxFontListItem( aFontListItem.GetFontList(), SID_ATTR_CHAR_FONTLIST));
111 if(!bIsDrwTxtMode)
112 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
113 rPage.PageCreated(aSet);
115 else if (nId == m_nCharExtId)
117 if(bIsDrwTxtMode)
118 aSet.Put (SfxUInt16Item(SID_DISABLE_CTL,DISABLE_CASEMAP));
120 else
122 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER|SVX_ENABLE_FLASH));
124 rPage.PageCreated(aSet);
126 else if (nId == m_nCharPosId)
128 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
129 rPage.PageCreated(aSet);
131 else if (nId == m_nCharTwoId)
133 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
134 rPage.PageCreated(aSet);
138 SwCharURLPage::SwCharURLPage(Window* pParent, const SfxItemSet& rCoreSet)
139 : SfxTabPage(pParent, "CharURLPage", "modules/swriter/ui/charurlpage.ui", rCoreSet)
140 , pINetItem(0)
141 , bModified(sal_False)
144 get(m_pURLED, "urled");
145 get(m_pTextFT, "textft");
146 get(m_pTextED, "texted");
147 get(m_pNameED, "nameed");
148 get(m_pTargetFrmLB, "targetfrmlb");
149 get(m_pURLPB, "urlpb");
150 get(m_pEventPB, "eventpb");
151 get(m_pVisitedLB, "visitedlb");
152 get(m_pNotVisitedLB, "unvisitedlb");
153 get(m_pCharStyleContainer, "charstyle");
155 const SfxPoolItem* pItem;
156 SfxObjectShell* pShell;
157 if(SFX_ITEM_SET == rCoreSet.GetItemState(SID_HTML_MODE, sal_False, &pItem) ||
158 ( 0 != ( pShell = SfxObjectShell::Current()) &&
159 0 != (pItem = pShell->GetItem(SID_HTML_MODE))))
161 sal_uInt16 nHtmlMode = ((const SfxUInt16Item*)pItem)->GetValue();
162 if(HTMLMODE_ON & nHtmlMode)
163 m_pCharStyleContainer->Hide();
166 m_pURLPB->SetClickHdl (LINK( this, SwCharURLPage, InsertFileHdl));
167 m_pEventPB->SetClickHdl(LINK( this, SwCharURLPage, EventHdl ));
169 SwView *pView = ::GetActiveView();
170 ::FillCharStyleListBox(*m_pVisitedLB, pView->GetDocShell());
171 ::FillCharStyleListBox(*m_pNotVisitedLB, pView->GetDocShell());
173 TargetList* pList = new TargetList;
174 const SfxFrame& rFrame = pView->GetViewFrame()->GetTopFrame();
175 rFrame.GetTargetList(*pList);
176 if ( !pList->empty() )
178 size_t nCount = pList->size();
179 size_t i;
181 for ( i = 0; i < nCount; i++ )
183 m_pTargetFrmLB->InsertEntry( *pList->at( i ) );
185 for ( i = nCount; i; )
187 delete pList->at( --i );
190 delete pList;
193 SwCharURLPage::~SwCharURLPage()
195 delete pINetItem;
198 void SwCharURLPage::Reset(const SfxItemSet& rSet)
200 const SfxPoolItem* pItem;
201 if(SFX_ITEM_SET == rSet.GetItemState(RES_TXTATR_INETFMT, sal_False, &pItem))
203 const SwFmtINetFmt* pINetFmt = (const SwFmtINetFmt*)pItem;
204 m_pURLED->SetText( INetURLObject::decode( pINetFmt->GetValue(),
205 INET_HEX_ESCAPE,
206 INetURLObject::DECODE_UNAMBIGUOUS,
207 RTL_TEXTENCODING_UTF8 ));
208 m_pURLED->SaveValue();
209 m_pNameED->SetText(pINetFmt->GetName());
210 String sEntry = pINetFmt->GetVisitedFmt();
211 if( !sEntry.Len() )
212 SwStyleNameMapper::FillUIName( RES_POOLCHR_INET_VISIT, sEntry );
213 m_pVisitedLB->SelectEntry(sEntry);
214 sEntry = pINetFmt->GetINetFmt();
215 if(!sEntry.Len())
216 SwStyleNameMapper::FillUIName( RES_POOLCHR_INET_NORMAL, sEntry );
217 m_pNotVisitedLB->SelectEntry(sEntry);
219 m_pTargetFrmLB->SetText(pINetFmt->GetTargetFrame());
220 m_pVisitedLB-> SaveValue();
221 m_pNotVisitedLB->SaveValue();
222 m_pTargetFrmLB-> SaveValue();
223 pINetItem = new SvxMacroItem(FN_INET_FIELD_MACRO);
225 if( pINetFmt->GetMacroTbl() )
226 pINetItem->SetMacroTable( *pINetFmt->GetMacroTbl() );
228 if(SFX_ITEM_SET == rSet.GetItemState(FN_PARAM_SELECTION, sal_False, &pItem))
230 m_pTextED->SetText(((const SfxStringItem*)pItem)->GetValue());
231 m_pTextFT->Enable( sal_False );
232 m_pTextED->Enable( sal_False );
236 sal_Bool SwCharURLPage::FillItemSet(SfxItemSet& rSet)
238 OUString sURL = m_pURLED->GetText();
239 if(!sURL.isEmpty())
241 sURL = URIHelper::SmartRel2Abs(INetURLObject(), sURL, Link(), false );
242 // #i100683# file URLs should be normalized in the UI
243 static const sal_Char* pFile = "file:";
244 sal_Int32 nLength = ((sal_Int32)sizeof(pFile)-1);
245 if( sURL.copy(0, nLength ).equalsAsciiL( pFile, nLength ))
246 sURL = URIHelper::simpleNormalizedMakeRelative(OUString(), sURL);
249 SwFmtINetFmt aINetFmt(sURL, m_pTargetFrmLB->GetText());
250 aINetFmt.SetName(m_pNameED->GetText());
251 bModified |= m_pURLED->GetText() != m_pURLED->GetSavedValue();
252 bModified |= m_pNameED->IsModified();
253 bModified |= m_pTargetFrmLB->GetSavedValue() != m_pTargetFrmLB->GetText();
255 // set valid settings first
256 String sEntry = m_pVisitedLB->GetSelectEntry();
257 sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
258 aINetFmt.SetVisitedFmtId(nId);
259 aINetFmt.SetVisitedFmt(nId == RES_POOLCHR_INET_VISIT ? aEmptyStr : sEntry);
261 sEntry = m_pNotVisitedLB->GetSelectEntry();
262 nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
263 aINetFmt.SetINetFmtId( nId );
264 aINetFmt.SetINetFmt(nId == RES_POOLCHR_INET_NORMAL ? aEmptyStr : sEntry);
266 if( pINetItem && !pINetItem->GetMacroTable().empty() )
267 aINetFmt.SetMacroTbl( &pINetItem->GetMacroTable() );
269 if(m_pVisitedLB->GetSavedValue() != m_pVisitedLB->GetSelectEntryPos())
270 bModified = sal_True;
272 if(m_pNotVisitedLB->GetSavedValue() != m_pNotVisitedLB->GetSelectEntryPos())
273 bModified = sal_True;
275 if(m_pTextED->IsModified())
277 bModified = sal_True;
278 rSet.Put(SfxStringItem(FN_PARAM_SELECTION, m_pTextED->GetText()));
280 if(bModified)
281 rSet.Put(aINetFmt);
282 return bModified;
285 SfxTabPage* SwCharURLPage::Create( Window* pParent,
286 const SfxItemSet& rAttrSet )
288 return ( new SwCharURLPage( pParent, rAttrSet ) );
291 IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl)
293 FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
294 if( aDlgHelper.Execute() == ERRCODE_NONE )
296 Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
297 m_pURLED->SetText(xFP->getFiles().getConstArray()[0]);
299 return 0;
302 IMPL_LINK_NOARG(SwCharURLPage, EventHdl)
304 bModified |= SwMacroAssignDlg::INetFmtDlg( this,
305 ::GetActiveView()->GetWrtShell(), pINetItem );
306 return 0;
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */