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