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 0 : uno::Reference< uno::XInterface > xAText = xMgr->createInstance( "com.sun.star.text.AutoTextContainer" );
56 0 : _xAutoText = uno::Reference< container::XNameAccess >(xAText, uno::UNO_QUERY);
57 :
58 0 : uno::Sequence<OUString> aNames = _xAutoText->getElementNames();
59 0 : const OUString* pGroups = aNames.getConstArray();
60 0 : OUString uTitleName( rtl::OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_TITLE)) );
61 :
62 0 : for(sal_uInt16 i = 0; i < aNames.getLength(); i++)
63 : {
64 0 : uno::Any aGroup = _xAutoText->getByName(pGroups[i]);
65 0 : uno::Reference< text::XAutoTextGroup > xGroup;
66 0 : aGroup >>= xGroup;
67 0 : uno::Reference< container::XIndexAccess > xIdxAcc(xGroup, uno::UNO_QUERY);
68 : try
69 : {
70 0 : if(!xIdxAcc.is() || xIdxAcc->getCount())
71 : {
72 0 : uno::Reference< beans::XPropertySet > xPrSet(xGroup, uno::UNO_QUERY);
73 0 : uno::Any aTitle = xPrSet->getPropertyValue( uTitleName );
74 0 : OUString uTitle;
75 0 : aTitle >>= uTitle;
76 0 : String sGroup(pGroups[i]);
77 0 : sal_uInt16 nEntry = aAutoTextGroupLB.InsertEntry(uTitle);
78 0 : aAutoTextGroupLB.SetEntryData(nEntry, new String(sGroup));
79 : }
80 : }
81 0 : catch (const Exception&)
82 : {
83 : }
84 0 : }
85 0 : if(aAutoTextGroupLB.GetEntryCount())
86 : {
87 0 : if(LISTBOX_ENTRY_NOTFOUND == aAutoTextGroupLB.GetSelectEntryPos())
88 0 : aAutoTextGroupLB.SelectEntryPos(0);
89 : String sCurGroupName(
90 0 : *(String*)aAutoTextGroupLB.GetEntryData(aAutoTextGroupLB.GetSelectEntryPos()));
91 0 : if(_xAutoText->hasByName(sCurGroupName))
92 : {
93 0 : uno::Any aGroup = _xAutoText->getByName(sCurGroupName);
94 : try
95 : {
96 0 : uno::Reference< text::XAutoTextGroup > xGroup;
97 0 : aGroup >>= xGroup;
98 0 : uno::Sequence< OUString > aBlockNames = xGroup->getElementNames();
99 0 : uno::Sequence< OUString > aTitles = xGroup->getTitles() ;
100 :
101 0 : SetUserData( aBlockNames.getLength(), aTitles.getConstArray(),
102 0 : aBlockNames.getConstArray() );
103 : }
104 0 : catch (const uno::RuntimeException&)
105 : {
106 : // we'll be her if path settings were wrong
107 0 : }
108 0 : }
109 0 : }
110 0 : }
111 :
112 0 : IMPL_LINK_NOARG(SwVisitingCardPage, FrameControlInitializedHdl)
113 : {
114 0 : SvTreeListEntry* pSel = aAutoTextLB.FirstSelected();
115 0 : String sEntry;
116 0 : if( pSel )
117 0 : sEntry = *(String*)pSel->GetUserData();
118 0 : uno::Reference< text::XTextCursor > & xCrsr = pExampleFrame->GetTextCursor();
119 0 : OUString uEntry(sEntry);
120 :
121 0 : if(LISTBOX_ENTRY_NOTFOUND != aAutoTextGroupLB.GetSelectEntryPos())
122 : {
123 : String sGroup( *(String*)aAutoTextGroupLB.GetEntryData(
124 0 : aAutoTextGroupLB.GetSelectEntryPos() ) );
125 0 : uno::Any aGroup = _xAutoText->getByName(sGroup);
126 0 : uno::Reference< text::XAutoTextGroup > xGroup;
127 0 : aGroup >>= xGroup;
128 :
129 0 : if( sEntry.Len() && xGroup->hasByName( uEntry ) )
130 : {
131 0 : uno::Any aEntry(xGroup->getByName(uEntry));
132 0 : uno::Reference< text::XAutoTextEntry > xEntry;
133 0 : aEntry >>= xEntry;
134 0 : if(xEntry.is())
135 : {
136 0 : uno::Reference< text::XTextRange > xRange(xCrsr, uno::UNO_QUERY);
137 0 : xEntry->applyTo(xRange);
138 : }
139 0 : UpdateFields();
140 0 : }
141 : }
142 0 : return 0;
143 : }
144 :
145 0 : IMPL_LINK( SwVisitingCardPage, AutoTextSelectHdl, void*, pBox )
146 : {
147 0 : if(_xAutoText.is())
148 : {
149 0 : if( &aAutoTextGroupLB == pBox )
150 : {
151 : String sGroup( *(String*)aAutoTextGroupLB.GetEntryData(
152 0 : aAutoTextGroupLB.GetSelectEntryPos()));
153 0 : uno::Any aGroup = _xAutoText->getByName(sGroup);
154 0 : uno::Reference< text::XAutoTextGroup > xGroup;
155 0 : aGroup >>= xGroup;
156 :
157 0 : ClearUserData();
158 0 : aAutoTextLB.Clear();
159 :
160 0 : uno::Sequence<OUString> aBlockNames = xGroup->getElementNames();
161 0 : uno::Sequence< OUString > aTitles = xGroup->getTitles() ;
162 0 : SetUserData( aBlockNames.getLength(), aTitles.getConstArray(),
163 0 : aBlockNames.getConstArray() );
164 : }
165 0 : if(pExampleFrame->IsInitialized())
166 0 : pExampleFrame->ClearDocument( sal_True );
167 : }
168 0 : return 0;
169 : }
170 :
171 0 : void SwVisitingCardPage::UpdateFields()
172 : {
173 0 : uno::Reference< frame::XModel > xModel;
174 0 : if( pExampleFrame && (xModel = pExampleFrame->GetModel()).is())
175 : {
176 0 : SwLabDlg::UpdateFieldInformation(xModel, aLabItem);
177 0 : }
178 0 : }
179 :
180 0 : void SwLabDlg::UpdateFieldInformation(uno::Reference< frame::XModel > & xModel, const SwLabItem& rItem)
181 : {
182 0 : uno::Reference< text::XTextFieldsSupplier > xFlds(xModel, uno::UNO_QUERY);
183 0 : uno::Reference< container::XNameAccess > xFldMasters = xFlds->getTextFieldMasters();
184 :
185 : static const struct _SwLabItemMap {
186 : const char* pName;
187 : rtl::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 }
222 : };
223 :
224 : try
225 : {
226 0 : rtl::OUString sFldName("com.sun.star.text.FieldMaster.User.");
227 0 : OUString uCntName( rtl::OUString::createFromAscii( SW_PROP_NAME_STR(UNO_NAME_CONTENT )));
228 0 : for( const _SwLabItemMap* p = aArr; p->pName; ++p )
229 : {
230 0 : String sCurFldName( sFldName );
231 0 : sCurFldName.AppendAscii( p->pName );
232 0 : OUString uFldName( sCurFldName );
233 0 : if( xFldMasters->hasByName( uFldName ))
234 : {
235 0 : uno::Any aFirstName = xFldMasters->getByName( uFldName );
236 0 : uno::Reference< beans::XPropertySet > xFld;
237 0 : aFirstName >>= xFld;
238 0 : uno::Any aContent;
239 0 : aContent <<= rItem.*p->pValue;
240 0 : xFld->setPropertyValue( uCntName, aContent );
241 : }
242 0 : }
243 : }
244 0 : catch (const uno::RuntimeException&)
245 : {
246 : //
247 : }
248 :
249 0 : uno::Reference< container::XEnumerationAccess > xFldAcc = xFlds->getTextFields();
250 0 : uno::Reference< util::XRefreshable > xRefresh(xFldAcc, uno::UNO_QUERY);
251 0 : xRefresh->refresh();
252 0 : }
253 :
254 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|