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