xref: /AOO41X/main/sw/source/ui/envelp/labelexp.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sw.hxx"
30*cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION
31*cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <com/sun/star/text/XTextFieldsSupplier.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/util/XRefreshable.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
39*cdf0e10cSrcweir #include <swtypes.hxx>
40*cdf0e10cSrcweir #include <labfmt.hxx>
41*cdf0e10cSrcweir #include <unotools.hxx>
42*cdf0e10cSrcweir #include <unoatxt.hxx>
43*cdf0e10cSrcweir #include <unomid.h>
44*cdf0e10cSrcweir #include <unoprnms.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir using namespace ::com::sun::star;
48*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
49*cdf0e10cSrcweir using namespace ::com::sun::star::container;
50*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
51*cdf0e10cSrcweir using namespace ::comphelper;
52*cdf0e10cSrcweir using ::rtl::OUString;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #ifdef SW_PROP_NAME_STR
55*cdf0e10cSrcweir #undef SW_PROP_NAME_STR
56*cdf0e10cSrcweir #endif
57*cdf0e10cSrcweir #define SW_PROP_NAME_STR(nId) SwGetPropName((nId)).pName
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir /* -----------------08.07.99 15:15-------------------
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir  --------------------------------------------------*/
62*cdf0e10cSrcweir void SwVisitingCardPage::InitFrameControl()
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir 	Link aLink(LINK(this, SwVisitingCardPage, FrameControlInitializedHdl));
65*cdf0e10cSrcweir 	pExampleFrame = new SwOneExampleFrame( aExampleWIN,
66*cdf0e10cSrcweir 									EX_SHOW_BUSINESS_CARDS, &aLink );
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 	uno::Reference< lang::XMultiServiceFactory >  xMgr =
69*cdf0e10cSrcweir 											getProcessServiceFactory();
70*cdf0e10cSrcweir 	//now the AutoText ListBoxes have to be filled
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	uno::Reference< uno::XInterface >  xAText =
73*cdf0e10cSrcweir 		xMgr->createInstance( C2U("com.sun.star.text.AutoTextContainer") );
74*cdf0e10cSrcweir 	_xAutoText = uno::Reference< container::XNameAccess >(xAText, uno::UNO_QUERY);
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	uno::Sequence<OUString> aNames = _xAutoText->getElementNames();
77*cdf0e10cSrcweir 	const OUString* pGroups = aNames.getConstArray();
78*cdf0e10cSrcweir 	OUString uTitleName( C2U(SW_PROP_NAME_STR(UNO_NAME_TITLE)) );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	for(sal_uInt16 i = 0; i < aNames.getLength(); i++)
81*cdf0e10cSrcweir 	{
82*cdf0e10cSrcweir 		uno::Any aGroup = _xAutoText->getByName(pGroups[i]);
83*cdf0e10cSrcweir         uno::Reference< text::XAutoTextGroup >  xGroup;
84*cdf0e10cSrcweir         aGroup >>= xGroup;
85*cdf0e10cSrcweir 		uno::Reference< container::XIndexAccess >  xIdxAcc(xGroup, uno::UNO_QUERY);
86*cdf0e10cSrcweir         try
87*cdf0e10cSrcweir         {
88*cdf0e10cSrcweir             if(!xIdxAcc.is() || xIdxAcc->getCount())
89*cdf0e10cSrcweir             {
90*cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet >  xPrSet(xGroup, uno::UNO_QUERY);
91*cdf0e10cSrcweir                 uno::Any aTitle = xPrSet->getPropertyValue( uTitleName );
92*cdf0e10cSrcweir                 OUString uTitle;
93*cdf0e10cSrcweir                 aTitle >>= uTitle;
94*cdf0e10cSrcweir                 String sGroup(pGroups[i]);
95*cdf0e10cSrcweir                 sal_uInt16 nEntry = aAutoTextGroupLB.InsertEntry(uTitle);
96*cdf0e10cSrcweir                 aAutoTextGroupLB.SetEntryData(nEntry, new String(sGroup));
97*cdf0e10cSrcweir             }
98*cdf0e10cSrcweir         }
99*cdf0e10cSrcweir         catch(Exception&)
100*cdf0e10cSrcweir         {
101*cdf0e10cSrcweir         }
102*cdf0e10cSrcweir 	}
103*cdf0e10cSrcweir 	if(aAutoTextGroupLB.GetEntryCount())
104*cdf0e10cSrcweir 	{
105*cdf0e10cSrcweir 		if(LISTBOX_ENTRY_NOTFOUND == aAutoTextGroupLB.GetSelectEntryPos())
106*cdf0e10cSrcweir 			aAutoTextGroupLB.SelectEntryPos(0);
107*cdf0e10cSrcweir 		String sCurGroupName(
108*cdf0e10cSrcweir 			*(String*)aAutoTextGroupLB.GetEntryData(aAutoTextGroupLB.GetSelectEntryPos()));
109*cdf0e10cSrcweir 		if(_xAutoText->hasByName(sCurGroupName))
110*cdf0e10cSrcweir 		{
111*cdf0e10cSrcweir 			uno::Any aGroup = _xAutoText->getByName(sCurGroupName);
112*cdf0e10cSrcweir 			try
113*cdf0e10cSrcweir 			{
114*cdf0e10cSrcweir                 uno::Reference< text::XAutoTextGroup >  xGroup;
115*cdf0e10cSrcweir                 aGroup >>= xGroup;
116*cdf0e10cSrcweir 				uno::Sequence< OUString > aBlockNames = xGroup->getElementNames();
117*cdf0e10cSrcweir 				uno::Sequence< OUString > aTitles = xGroup->getTitles() ;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 				SetUserData( aBlockNames.getLength(), aTitles.getConstArray(),
120*cdf0e10cSrcweir 							aBlockNames.getConstArray() );
121*cdf0e10cSrcweir 			}
122*cdf0e10cSrcweir 			catch( uno::RuntimeException& )
123*cdf0e10cSrcweir 			{
124*cdf0e10cSrcweir 				// we'll be her if path settings were wrong
125*cdf0e10cSrcweir 			}
126*cdf0e10cSrcweir 		}
127*cdf0e10cSrcweir 	}
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir /* -----------------01.10.99 13:19-------------------
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir  --------------------------------------------------*/
132*cdf0e10cSrcweir IMPL_LINK( SwVisitingCardPage, FrameControlInitializedHdl, void*, EMPTYARG )
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir 	SvLBoxEntry* pSel = aAutoTextLB.FirstSelected();
135*cdf0e10cSrcweir 	String sEntry;
136*cdf0e10cSrcweir 	if( pSel )
137*cdf0e10cSrcweir 		sEntry = *(String*)pSel->GetUserData();
138*cdf0e10cSrcweir 	uno::Reference< text::XTextCursor > & xCrsr = pExampleFrame->GetTextCursor();
139*cdf0e10cSrcweir 	OUString uEntry(sEntry);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir     if(LISTBOX_ENTRY_NOTFOUND != aAutoTextGroupLB.GetSelectEntryPos())
142*cdf0e10cSrcweir     {
143*cdf0e10cSrcweir         String sGroup( *(String*)aAutoTextGroupLB.GetEntryData(
144*cdf0e10cSrcweir                                     aAutoTextGroupLB.GetSelectEntryPos() ) );
145*cdf0e10cSrcweir         uno::Any aGroup = _xAutoText->getByName(sGroup);
146*cdf0e10cSrcweir         uno::Reference< text::XAutoTextGroup >  xGroup;
147*cdf0e10cSrcweir         aGroup >>= xGroup;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir         if( sEntry.Len() && xGroup->hasByName( uEntry ) )
150*cdf0e10cSrcweir         {
151*cdf0e10cSrcweir             uno::Any aEntry(xGroup->getByName(uEntry));
152*cdf0e10cSrcweir             uno::Reference< text::XAutoTextEntry >  xEntry;
153*cdf0e10cSrcweir             aEntry >>= xEntry;
154*cdf0e10cSrcweir             if(xEntry.is())
155*cdf0e10cSrcweir             {
156*cdf0e10cSrcweir                 uno::Reference< text::XTextRange >  xRange(xCrsr, uno::UNO_QUERY);
157*cdf0e10cSrcweir                 xEntry->applyTo(xRange);
158*cdf0e10cSrcweir             }
159*cdf0e10cSrcweir             UpdateFields();
160*cdf0e10cSrcweir         }
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir 	return 0;
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir /* -----------------22.07.99 11:06-------------------
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir  --------------------------------------------------*/
167*cdf0e10cSrcweir IMPL_LINK( SwVisitingCardPage, AutoTextSelectHdl, void*, pBox )
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir 	if(_xAutoText.is())
170*cdf0e10cSrcweir 	{
171*cdf0e10cSrcweir 		if( &aAutoTextGroupLB == pBox )
172*cdf0e10cSrcweir 		{
173*cdf0e10cSrcweir 			String sGroup( *(String*)aAutoTextGroupLB.GetEntryData(
174*cdf0e10cSrcweir 									aAutoTextGroupLB.GetSelectEntryPos()));
175*cdf0e10cSrcweir 			uno::Any aGroup = _xAutoText->getByName(sGroup);
176*cdf0e10cSrcweir 			uno::Reference< text::XAutoTextGroup >  xGroup;
177*cdf0e10cSrcweir 			aGroup >>= xGroup;
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 			ClearUserData();
180*cdf0e10cSrcweir 			aAutoTextLB.Clear();
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 			uno::Sequence<OUString> aBlockNames = xGroup->getElementNames();
183*cdf0e10cSrcweir 			uno::Sequence< OUString > aTitles = xGroup->getTitles() ;
184*cdf0e10cSrcweir 			SetUserData( aBlockNames.getLength(), aTitles.getConstArray(),
185*cdf0e10cSrcweir 						aBlockNames.getConstArray() );
186*cdf0e10cSrcweir 		}
187*cdf0e10cSrcweir 		if(pExampleFrame->IsInitialized())
188*cdf0e10cSrcweir 			pExampleFrame->ClearDocument( sal_True );
189*cdf0e10cSrcweir 	}
190*cdf0e10cSrcweir 	return 0;
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir /* -----------------01.10.99 11:59-------------------
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir  --------------------------------------------------*/
196*cdf0e10cSrcweir void SwVisitingCardPage::UpdateFields()
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir 	uno::Reference< frame::XModel >  xModel;
199*cdf0e10cSrcweir 	if( pExampleFrame && (xModel = pExampleFrame->GetModel()).is())
200*cdf0e10cSrcweir 	{
201*cdf0e10cSrcweir 		SwLabDlg::UpdateFieldInformation(xModel, aLabItem);
202*cdf0e10cSrcweir 	}
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir /* -----------------01.10.99 15:16-------------------
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir  --------------------------------------------------*/
207*cdf0e10cSrcweir void SwLabDlg::UpdateFieldInformation(uno::Reference< frame::XModel > & xModel, const SwLabItem& rItem)
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir 	uno::Reference< text::XTextFieldsSupplier >  xFlds(xModel, uno::UNO_QUERY);
210*cdf0e10cSrcweir 	uno::Reference< container::XNameAccess >  xFldMasters = xFlds->getTextFieldMasters();
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 	static const struct _SwLabItemMap {
213*cdf0e10cSrcweir 		const char* pName;
214*cdf0e10cSrcweir 		rtl::OUString SwLabItem:: *pValue;
215*cdf0e10cSrcweir 	}  aArr[] = {
216*cdf0e10cSrcweir 		{ "BC_PRIV_FIRSTNAME"  , &SwLabItem::aPrivFirstName },
217*cdf0e10cSrcweir 		{ "BC_PRIV_NAME"       , &SwLabItem::aPrivName },
218*cdf0e10cSrcweir 		{ "BC_PRIV_INITIALS"   , &SwLabItem::aPrivShortCut },
219*cdf0e10cSrcweir 		{ "BC_PRIV_FIRSTNAME_2", &SwLabItem::aPrivFirstName2 },
220*cdf0e10cSrcweir 		{ "BC_PRIV_NAME_2"     , &SwLabItem::aPrivName2 },
221*cdf0e10cSrcweir 		{ "BC_PRIV_INITIALS_2" , &SwLabItem::aPrivShortCut2 },
222*cdf0e10cSrcweir 		{ "BC_PRIV_STREET"     , &SwLabItem::aPrivStreet },
223*cdf0e10cSrcweir 		{ "BC_PRIV_ZIP"        , &SwLabItem::aPrivZip },
224*cdf0e10cSrcweir 		{ "BC_PRIV_CITY"       , &SwLabItem::aPrivCity },
225*cdf0e10cSrcweir 		{ "BC_PRIV_COUNTRY"    , &SwLabItem::aPrivCountry },
226*cdf0e10cSrcweir 		{ "BC_PRIV_STATE"      , &SwLabItem::aPrivState },
227*cdf0e10cSrcweir 		{ "BC_PRIV_TITLE"      , &SwLabItem::aPrivTitle },
228*cdf0e10cSrcweir 		{ "BC_PRIV_PROFESSION" , &SwLabItem::aPrivProfession },
229*cdf0e10cSrcweir 		{ "BC_PRIV_PHONE"      , &SwLabItem::aPrivPhone },
230*cdf0e10cSrcweir 		{ "BC_PRIV_MOBILE"     , &SwLabItem::aPrivMobile },
231*cdf0e10cSrcweir 		{ "BC_PRIV_FAX"        , &SwLabItem::aPrivFax },
232*cdf0e10cSrcweir 		{ "BC_PRIV_WWW"        , &SwLabItem::aPrivWWW },
233*cdf0e10cSrcweir 		{ "BC_PRIV_MAIL"       , &SwLabItem::aPrivMail },
234*cdf0e10cSrcweir 		{ "BC_COMP_COMPANY"    , &SwLabItem::aCompCompany },
235*cdf0e10cSrcweir 		{ "BC_COMP_COMPANYEXT" , &SwLabItem::aCompCompanyExt },
236*cdf0e10cSrcweir 		{ "BC_COMP_SLOGAN"     , &SwLabItem::aCompSlogan },
237*cdf0e10cSrcweir 		{ "BC_COMP_STREET"     , &SwLabItem::aCompStreet },
238*cdf0e10cSrcweir 		{ "BC_COMP_ZIP"        , &SwLabItem::aCompZip },
239*cdf0e10cSrcweir 		{ "BC_COMP_CITY"       , &SwLabItem::aCompCity },
240*cdf0e10cSrcweir 		{ "BC_COMP_COUNTRY"    , &SwLabItem::aCompCountry },
241*cdf0e10cSrcweir 		{ "BC_COMP_STATE"      , &SwLabItem::aCompState },
242*cdf0e10cSrcweir 		{ "BC_COMP_POSITION"   , &SwLabItem::aCompPosition },
243*cdf0e10cSrcweir 		{ "BC_COMP_PHONE"      , &SwLabItem::aCompPhone },
244*cdf0e10cSrcweir 		{ "BC_COMP_MOBILE"     , &SwLabItem::aCompMobile },
245*cdf0e10cSrcweir 		{ "BC_COMP_FAX"        , &SwLabItem::aCompFax },
246*cdf0e10cSrcweir 		{ "BC_COMP_WWW"        , &SwLabItem::aCompWWW },
247*cdf0e10cSrcweir 		{ "BC_COMP_MAIL"       , &SwLabItem::aCompMail },
248*cdf0e10cSrcweir 		{ 0, 0 }
249*cdf0e10cSrcweir 	};
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	try
252*cdf0e10cSrcweir 	{
253*cdf0e10cSrcweir 		String sFldName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(
254*cdf0e10cSrcweir 							"com.sun.star.text.FieldMaster.User." )));
255*cdf0e10cSrcweir 		OUString uCntName( C2U( SW_PROP_NAME_STR(UNO_NAME_CONTENT )));
256*cdf0e10cSrcweir 		for( const _SwLabItemMap* p = aArr; p->pName; ++p )
257*cdf0e10cSrcweir 		{
258*cdf0e10cSrcweir 			String sCurFldName( sFldName );
259*cdf0e10cSrcweir 			sCurFldName.AppendAscii( p->pName );
260*cdf0e10cSrcweir 			OUString uFldName( sCurFldName );
261*cdf0e10cSrcweir 			if( xFldMasters->hasByName( uFldName ))
262*cdf0e10cSrcweir 			{
263*cdf0e10cSrcweir 				uno::Any aFirstName = xFldMasters->getByName( uFldName );
264*cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet >  xFld;
265*cdf0e10cSrcweir                 aFirstName >>= xFld;
266*cdf0e10cSrcweir 				uno::Any aContent;
267*cdf0e10cSrcweir 				aContent <<= rItem.*p->pValue;
268*cdf0e10cSrcweir 				xFld->setPropertyValue( uCntName, aContent );
269*cdf0e10cSrcweir 			}
270*cdf0e10cSrcweir 		}
271*cdf0e10cSrcweir 	}
272*cdf0e10cSrcweir 	catch( uno::RuntimeException&)
273*cdf0e10cSrcweir 	{
274*cdf0e10cSrcweir 		//
275*cdf0e10cSrcweir 	}
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 	uno::Reference< container::XEnumerationAccess >  xFldAcc = xFlds->getTextFields();
278*cdf0e10cSrcweir 	uno::Reference< util::XRefreshable >  xRefresh(xFldAcc, uno::UNO_QUERY);
279*cdf0e10cSrcweir 	xRefresh->refresh();
280*cdf0e10cSrcweir }
281*cdf0e10cSrcweir 
282