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