bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / envelp / labelexp.cxx
blob7104b8829fb3ae2bc86903b0a7d49388959b740f
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 <com/sun/star/lang/XMultiServiceFactory.hpp>
21 #include <com/sun/star/text/AutoTextContainer.hpp>
22 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
23 #include <com/sun/star/util/XRefreshable.hpp>
24 #include <comphelper/processfactory.hxx>
25 #include "svtools/treelistentry.hxx"
26 #include <swtypes.hxx>
27 #include <labfmt.hxx>
28 #include <unotools.hxx>
29 #include <unoatxt.hxx>
30 #include <unomid.h>
31 #include <unoprnms.hxx>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::uno;
38 using namespace ::comphelper;
40 #ifdef SW_PROP_NAME_STR
41 #undef SW_PROP_NAME_STR
42 #endif
43 #define SW_PROP_NAME_STR(nId) SwGetPropName((nId)).pName
45 void SwVisitingCardPage::InitFrameControl()
47 Link aLink(LINK(this, SwVisitingCardPage, FrameControlInitializedHdl));
48 aExampleWIN.Show();
49 pExampleFrame = new SwOneExampleFrame( aExampleWIN,
50 EX_SHOW_BUSINESS_CARDS, &aLink );
52 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
54 //now the AutoText ListBoxes have to be filled
56 m_xAutoText = text::AutoTextContainer::create( xContext );
58 uno::Sequence<OUString> aNames = m_xAutoText->getElementNames();
59 const OUString* pGroups = aNames.getConstArray();
60 OUString uTitleName( OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_TITLE)) );
62 for(sal_uInt16 i = 0; i < aNames.getLength(); i++)
64 uno::Any aGroup = m_xAutoText->getByName(pGroups[i]);
65 uno::Reference< text::XAutoTextGroup > xGroup;
66 aGroup >>= xGroup;
67 uno::Reference< container::XIndexAccess > xIdxAcc(xGroup, uno::UNO_QUERY);
68 try
70 if(!xIdxAcc.is() || xIdxAcc->getCount())
72 uno::Reference< beans::XPropertySet > xPrSet(xGroup, uno::UNO_QUERY);
73 uno::Any aTitle = xPrSet->getPropertyValue( uTitleName );
74 OUString uTitle;
75 aTitle >>= uTitle;
76 String sGroup(pGroups[i]);
77 sal_uInt16 nEntry = aAutoTextGroupLB.InsertEntry(uTitle);
78 aAutoTextGroupLB.SetEntryData(nEntry, new String(sGroup));
81 catch (const Exception&)
85 if(aAutoTextGroupLB.GetEntryCount())
87 if(LISTBOX_ENTRY_NOTFOUND == aAutoTextGroupLB.GetSelectEntryPos())
88 aAutoTextGroupLB.SelectEntryPos(0);
89 String sCurGroupName(
90 *(String*)aAutoTextGroupLB.GetEntryData(aAutoTextGroupLB.GetSelectEntryPos()));
91 if(m_xAutoText->hasByName(sCurGroupName))
93 uno::Any aGroup = m_xAutoText->getByName(sCurGroupName);
94 try
96 uno::Reference< text::XAutoTextGroup > xGroup;
97 aGroup >>= xGroup;
98 uno::Sequence< OUString > aBlockNames = xGroup->getElementNames();
99 uno::Sequence< OUString > aTitles = xGroup->getTitles() ;
101 SetUserData( aBlockNames.getLength(), aTitles.getConstArray(),
102 aBlockNames.getConstArray() );
104 catch (const uno::RuntimeException&)
106 // we'll be her if path settings were wrong
112 IMPL_LINK_NOARG(SwVisitingCardPage, FrameControlInitializedHdl)
114 SvTreeListEntry* pSel = aAutoTextLB.FirstSelected();
115 String sEntry;
116 if( pSel )
117 sEntry = *(String*)pSel->GetUserData();
118 uno::Reference< text::XTextCursor > & xCrsr = pExampleFrame->GetTextCursor();
119 OUString uEntry(sEntry);
121 if(LISTBOX_ENTRY_NOTFOUND != aAutoTextGroupLB.GetSelectEntryPos())
123 String sGroup( *(String*)aAutoTextGroupLB.GetEntryData(
124 aAutoTextGroupLB.GetSelectEntryPos() ) );
125 uno::Any aGroup = m_xAutoText->getByName(sGroup);
126 uno::Reference< text::XAutoTextGroup > xGroup;
127 aGroup >>= xGroup;
129 if( sEntry.Len() && xGroup->hasByName( uEntry ) )
131 uno::Any aEntry(xGroup->getByName(uEntry));
132 uno::Reference< text::XAutoTextEntry > xEntry;
133 aEntry >>= xEntry;
134 if(xEntry.is())
136 uno::Reference< text::XTextRange > xRange(xCrsr, uno::UNO_QUERY);
137 xEntry->applyTo(xRange);
139 UpdateFields();
142 return 0;
145 IMPL_LINK( SwVisitingCardPage, AutoTextSelectHdl, void*, pBox )
147 if(m_xAutoText.is())
149 if( &aAutoTextGroupLB == pBox )
151 String sGroup( *(String*)aAutoTextGroupLB.GetEntryData(
152 aAutoTextGroupLB.GetSelectEntryPos()));
153 uno::Any aGroup = m_xAutoText->getByName(sGroup);
154 uno::Reference< text::XAutoTextGroup > xGroup;
155 aGroup >>= xGroup;
157 ClearUserData();
158 aAutoTextLB.Clear();
160 uno::Sequence<OUString> aBlockNames = xGroup->getElementNames();
161 uno::Sequence< OUString > aTitles = xGroup->getTitles() ;
162 SetUserData( aBlockNames.getLength(), aTitles.getConstArray(),
163 aBlockNames.getConstArray() );
165 if(pExampleFrame->IsInitialized())
166 pExampleFrame->ClearDocument( sal_True );
168 return 0;
171 void SwVisitingCardPage::UpdateFields()
173 uno::Reference< frame::XModel > xModel;
174 if( pExampleFrame && (xModel = pExampleFrame->GetModel()).is())
176 SwLabDlg::UpdateFieldInformation(xModel, aLabItem);
180 void SwLabDlg::UpdateFieldInformation(uno::Reference< frame::XModel > & xModel, const SwLabItem& rItem)
182 uno::Reference< text::XTextFieldsSupplier > xFlds(xModel, uno::UNO_QUERY);
183 uno::Reference< container::XNameAccess > xFldMasters = xFlds->getTextFieldMasters();
185 static const struct _SwLabItemMap {
186 const char* pName;
187 OUString SwLabItem:: *pValue;
188 } aArr[] = {
189 { "BC_PRIV_FIRSTNAME" , &SwLabItem::aPrivFirstName },
190 { "BC_PRIV_NAME" , &SwLabItem::aPrivName },
191 { "BC_PRIV_INITIALS" , &SwLabItem::aPrivShortCut },
192 { "BC_PRIV_FIRSTNAME_2", &SwLabItem::aPrivFirstName2 },
193 { "BC_PRIV_NAME_2" , &SwLabItem::aPrivName2 },
194 { "BC_PRIV_INITIALS_2" , &SwLabItem::aPrivShortCut2 },
195 { "BC_PRIV_STREET" , &SwLabItem::aPrivStreet },
196 { "BC_PRIV_ZIP" , &SwLabItem::aPrivZip },
197 { "BC_PRIV_CITY" , &SwLabItem::aPrivCity },
198 { "BC_PRIV_COUNTRY" , &SwLabItem::aPrivCountry },
199 { "BC_PRIV_STATE" , &SwLabItem::aPrivState },
200 { "BC_PRIV_TITLE" , &SwLabItem::aPrivTitle },
201 { "BC_PRIV_PROFESSION" , &SwLabItem::aPrivProfession },
202 { "BC_PRIV_PHONE" , &SwLabItem::aPrivPhone },
203 { "BC_PRIV_MOBILE" , &SwLabItem::aPrivMobile },
204 { "BC_PRIV_FAX" , &SwLabItem::aPrivFax },
205 { "BC_PRIV_WWW" , &SwLabItem::aPrivWWW },
206 { "BC_PRIV_MAIL" , &SwLabItem::aPrivMail },
207 { "BC_COMP_COMPANY" , &SwLabItem::aCompCompany },
208 { "BC_COMP_COMPANYEXT" , &SwLabItem::aCompCompanyExt },
209 { "BC_COMP_SLOGAN" , &SwLabItem::aCompSlogan },
210 { "BC_COMP_STREET" , &SwLabItem::aCompStreet },
211 { "BC_COMP_ZIP" , &SwLabItem::aCompZip },
212 { "BC_COMP_CITY" , &SwLabItem::aCompCity },
213 { "BC_COMP_COUNTRY" , &SwLabItem::aCompCountry },
214 { "BC_COMP_STATE" , &SwLabItem::aCompState },
215 { "BC_COMP_POSITION" , &SwLabItem::aCompPosition },
216 { "BC_COMP_PHONE" , &SwLabItem::aCompPhone },
217 { "BC_COMP_MOBILE" , &SwLabItem::aCompMobile },
218 { "BC_COMP_FAX" , &SwLabItem::aCompFax },
219 { "BC_COMP_WWW" , &SwLabItem::aCompWWW },
220 { "BC_COMP_MAIL" , &SwLabItem::aCompMail },
221 { 0, 0 }
226 OUString sFldName("com.sun.star.text.FieldMaster.User.");
227 OUString uCntName( OUString::createFromAscii( SW_PROP_NAME_STR(UNO_NAME_CONTENT )));
228 for( const _SwLabItemMap* p = aArr; p->pName; ++p )
230 String sCurFldName( sFldName );
231 sCurFldName.AppendAscii( p->pName );
232 OUString uFldName( sCurFldName );
233 if( xFldMasters->hasByName( uFldName ))
235 uno::Any aFirstName = xFldMasters->getByName( uFldName );
236 uno::Reference< beans::XPropertySet > xFld;
237 aFirstName >>= xFld;
238 uno::Any aContent;
239 aContent <<= rItem.*p->pValue;
240 xFld->setPropertyValue( uCntName, aContent );
244 catch (const uno::RuntimeException&)
249 uno::Reference< container::XEnumerationAccess > xFldAcc = xFlds->getTextFields();
250 uno::Reference< util::XRefreshable > xRefresh(xFldAcc, uno::UNO_QUERY);
251 xRefresh->refresh();
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */