xref: /aoo41x/main/sw/source/ui/chrdlg/swuiccoll.cxx (revision 4d7c9de0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 
32 
33 #include "cmdid.h"
34 #include <tools/list.hxx>
35 #include "swmodule.hxx"
36 #include "view.hxx"
37 #include "wrtsh.hxx"
38 #include "globals.hrc"
39 #include "helpid.h"
40 
41 
42 #include <sfx2/styfitem.hxx>
43 
44 #include "uitool.hxx"
45 #include "ccoll.hxx"
46 #include "fmtcol.hxx"
47 #include "hintids.hxx"
48 #include "docsh.hxx"
49 #include "docstyle.hxx"
50 #include "hints.hxx"
51 
52 #include "chrdlg.hrc"
53 #include "ccoll.hrc"
54 #include <vcl/svapp.hxx>
55 
56 #include "swuiccoll.hxx"
57 
58 static sal_uInt16 __FAR_DATA aPageRg[] = {
59 	FN_COND_COLL, FN_COND_COLL,
60 	0
61 };
62 
63 // Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert
64 static long nTabs[] =
65 	{	2, // Number of Tabs
66 		0, 100
67 	};
68 
69 /****************************************************************************
70 Page: Ctor
71 ****************************************************************************/
72 
73 
SwCondCollPage(Window * pParent,const SfxItemSet & rSet)74 SwCondCollPage::SwCondCollPage(Window *pParent, const SfxItemSet &rSet)
75 
76 	: SfxTabPage(pParent, SW_RES(TP_CONDCOLL), rSet),
77     aConditionFL( this, SW_RES( FL_CONDITION )),
78 	aConditionCB( this, SW_RES( CB_CONDITION ) ),
79 	aContextFT  ( this, SW_RES( FT_CONTEXT 	) ),
80 	aUsedFT     ( this, SW_RES( FT_USED 		) ),
81 	aTbLinks( 	  this, SW_RES( TB_CONDCOLLS ) ),
82 	aStyleFT    ( this, SW_RES( FT_STYLE 	) ),
83 	aStyleLB    ( this, SW_RES( LB_STYLE 	) ),
84 	aFilterLB   ( this, SW_RES( LB_FILTER 	) ),
85 	aRemovePB   ( this, SW_RES( PB_REMOVE 	) ),
86 	aAssignPB   ( this, SW_RES( PB_ASSIGN 	) ),
87 	sNoTmpl		(		SW_RES( STR_NOTEMPL  ) ),
88 	aStrArr 	( 		SW_RES( STR_REGIONS  ) ),
89 	rSh(::GetActiveView()->GetWrtShell()),
90     pCmds( SwCondCollItem::GetCmds() ),
91 	pFmt(0),
92 
93     bNewTemplate(sal_False)
94 {
95 	FreeResource();
96 	SetExchangeSupport();
97 
98 	aRemovePB.SetAccessibleRelationMemberOf(&aConditionFL);
99 	aAssignPB.SetAccessibleRelationMemberOf(&aConditionFL);
100 	aTbLinks.SetAccessibleRelationLabeledBy(&aConditionCB);
101 
102 	// Handler installieren
103 	aConditionCB.SetClickHdl(	LINK(this, SwCondCollPage, OnOffHdl));
104 	aTbLinks.SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
105 	aStyleLB.SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
106 	aRemovePB.SetClickHdl(		LINK(this, SwCondCollPage, AssignRemoveHdl ));
107 	aAssignPB.SetClickHdl(		LINK(this, SwCondCollPage, AssignRemoveHdl ));
108 	aTbLinks.SetSelectHdl(		LINK(this, SwCondCollPage, SelectHdl));
109 	aStyleLB.SetSelectHdl(		LINK(this, SwCondCollPage, SelectHdl));
110 	aFilterLB.SetSelectHdl(		LINK(this, SwCondCollPage, SelectHdl));
111 
112 	aTbLinks.SetStyle(aTbLinks.GetStyle()|WB_HSCROLL|WB_CLIPCHILDREN);
113 	aTbLinks.SetSelectionMode( SINGLE_SELECTION );
114 	aTbLinks.SetTabs( &nTabs[0], MAP_APPFONT );
115 	aTbLinks.Resize();	// OS: Hack fuer richtige Selektion
116 	aTbLinks.SetSpaceBetweenEntries( 0 );
117 	aTbLinks.SetHelpId(HID_COND_COLL_TABLIST);
118 
119 	SfxStyleFamilies aFamilies(SW_RES(DLG_STYLE_DESIGNER));
120     const SfxStyleFamilyItem* pFamilyItem = 0;
121 	sal_uInt16 nCount = aFamilies.Count();
122 	sal_uInt16 i;
123 
124 	for( i = 0; i < nCount; ++i)
125 	{
126 		if(SFX_STYLE_FAMILY_PARA == (sal_uInt16)(pFamilyItem = aFamilies.GetObject(i))->GetFamily())
127 			break;
128 	}
129 
130 	if( pFamilyItem )
131 	{
132 		const SfxStyleFilter& rFilterList = pFamilyItem->GetFilterList();
133 		for( i = 0; i < rFilterList.Count(); ++i)
134 		{
135 			aFilterLB.InsertEntry(rFilterList.GetObject(i)->aName);
136 			sal_uInt16* pFilter = new sal_uInt16(rFilterList.GetObject(i)->nFlags);
137 			aFilterLB.SetEntryData(i, pFilter);
138 		}
139 	}
140 	aFilterLB.SelectEntryPos(1);
141 
142 	aTbLinks.Show();
143 
144 }
145 
146 /****************************************************************************
147 Page: Dtor
148 ****************************************************************************/
149 
150 
~SwCondCollPage()151 __EXPORT SwCondCollPage::~SwCondCollPage()
152 {
153 	for(sal_uInt16 i = 0; i < aFilterLB.GetEntryCount(); ++i)
154 		delete (sal_uInt16*)aFilterLB.GetEntryData(i);
155 
156 }
157 
158 
DeactivatePage(SfxItemSet * _pSet)159 int __EXPORT SwCondCollPage::DeactivatePage(SfxItemSet * _pSet)
160 {
161     if( _pSet )
162         FillItemSet(*_pSet);
163 
164 	return LEAVE_PAGE;
165 }
166 
167 /****************************************************************************
168 Page: Factory
169 ****************************************************************************/
170 
171 
Create(Window * pParent,const SfxItemSet & rSet)172 SfxTabPage* __EXPORT SwCondCollPage::Create(Window *pParent, const SfxItemSet &rSet)
173 {
174 	return new SwCondCollPage(pParent, rSet);
175 }
176 
177 /****************************************************************************
178 Page: FillItemSet-Overload
179 ****************************************************************************/
180 
181 
FillItemSet(SfxItemSet & rSet)182 sal_Bool __EXPORT SwCondCollPage::FillItemSet(SfxItemSet &rSet)
183 {
184 	sal_Bool bModified = sal_True;
185 	SwCondCollItem aCondItem;
186 	for(sal_uInt16 i = 0; i < aStrArr.Count(); i++)
187 	{
188 		String sEntry = aTbLinks.GetEntryText(i, 1);
189 		aCondItem.SetStyle( &sEntry, i);
190 	}
191 	rSet.Put(aCondItem);
192 	return bModified;
193 }
194 
195 /****************************************************************************
196 Page: Reset-Overload
197 ****************************************************************************/
198 
199 
Reset(const SfxItemSet &)200 void __EXPORT SwCondCollPage::Reset(const SfxItemSet &/*rSet*/)
201 {
202 	if(bNewTemplate)
203 		aConditionCB.Enable();
204 	if(RES_CONDTXTFMTCOLL == pFmt->Which())
205 		aConditionCB.Check();
206 	OnOffHdl(&aConditionCB);
207 
208 	aTbLinks.Clear();
209 
210 	SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
211 	pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL);
212 	aStyleLB.Clear();
213 	const SfxStyleSheetBase* pBase = pPool->First();
214 	while( pBase )
215 	{
216 		if(!pFmt || pBase->GetName() != pFmt->GetName())
217 			aStyleLB.InsertEntry(pBase->GetName());
218 		pBase = pPool->Next();
219 	}
220 	aStyleLB.SelectEntryPos(0);
221 
222 	for( sal_uInt16 n = 0; n < aStrArr.Count(); n++)
223 	{
224 		String aEntry( aStrArr.GetString(n) );
225 		aEntry += '\t';
226 
227         const SwCollCondition* pCond = 0;
228 		if( pFmt && RES_CONDTXTFMTCOLL == pFmt->Which() &&
229 			0 != ( pCond = ((SwConditionTxtFmtColl*)pFmt)->
230 			HasCondition( SwCollCondition( 0, pCmds[n].nCnd, pCmds[n].nSubCond ) ) )
231 			&& pCond->GetTxtFmtColl() )
232 		{
233 			aEntry += pCond->GetTxtFmtColl()->GetName();
234 		}
235 
236 		SvLBoxEntry* pE = aTbLinks.InsertEntryToColumn( aEntry, n );
237 		if(0 == n)
238 			aTbLinks.Select(pE);
239 	}
240 
241 }
242 
243 /****************************************************************************
244 
245 ****************************************************************************/
246 
247 
GetRanges()248 sal_uInt16* __EXPORT SwCondCollPage::GetRanges()
249 {
250 	return aPageRg;
251 }
252 
253 
254 /****************************************************************************
255 
256 ****************************************************************************/
257 
258 
IMPL_LINK(SwCondCollPage,OnOffHdl,CheckBox *,pBox)259 IMPL_LINK( SwCondCollPage, OnOffHdl, CheckBox*, pBox )
260 {
261 	const sal_Bool bEnable = pBox->IsChecked();
262 	aContextFT.Enable( bEnable );
263 	aUsedFT   .Enable( bEnable );
264     aTbLinks  .EnableList( bEnable != sal_False );
265 	aStyleFT  .Enable( bEnable );
266 	aStyleLB  .Enable( bEnable );
267 	aFilterLB .Enable( bEnable );
268 	aRemovePB .Enable( bEnable );
269 	aAssignPB .Enable( bEnable );
270 	if( bEnable )
271 		SelectHdl(0);
272 	return 0;
273 }
274 
275 /****************************************************************************
276 
277 ****************************************************************************/
278 
279 
IMPL_LINK(SwCondCollPage,AssignRemoveHdl,PushButton *,pBtn)280 IMPL_LINK( SwCondCollPage, AssignRemoveHdl, PushButton*, pBtn)
281 {
282 	SvLBoxEntry* pE = aTbLinks.FirstSelected();
283 	sal_uLong nPos;
284 	if( !pE || LISTBOX_ENTRY_NOTFOUND ==
285 		( nPos = aTbLinks.GetModel()->GetAbsPos( pE ) ) )
286 	{
287 		ASSERT( pE, "wo kommt der leere Eintrag her?" );
288 		return 0;
289 	}
290 
291 	String sSel = aStrArr.GetString( sal_uInt16(nPos) );
292 	sSel += '\t';
293 
294 	const sal_Bool bAssEnabled = pBtn != &aRemovePB && aAssignPB.IsEnabled();
295 	aAssignPB.Enable( !bAssEnabled );
296 	aRemovePB.Enable(  bAssEnabled );
297 	if ( bAssEnabled )
298 		sSel += aStyleLB.GetSelectEntry();
299 
300 	aTbLinks.SetUpdateMode(sal_False);
301 	aTbLinks.GetModel()->Remove(pE);
302 	pE = aTbLinks.InsertEntryToColumn(sSel, nPos);
303 	aTbLinks.Select(pE);
304 	aTbLinks.MakeVisible(pE);
305 	aTbLinks.SetUpdateMode(sal_True);
306 	return 0;
307 }
308 
309 /****************************************************************************
310 
311 ****************************************************************************/
312 
313 
IMPL_LINK(SwCondCollPage,SelectHdl,ListBox *,pBox)314 IMPL_LINK( SwCondCollPage, SelectHdl, ListBox*, pBox)
315 {
316 	if(pBox == &aFilterLB)
317 	{
318 		aStyleLB.Clear();
319 		sal_uInt16 nSearchFlags = pBox->GetSelectEntryPos();
320 		nSearchFlags = *(sal_uInt16*)aFilterLB.GetEntryData(nSearchFlags);
321 		SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
322 		pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, nSearchFlags);
323 		const SfxStyleSheetBase* pBase = pPool->First();
324 		while( pBase )
325 		{
326 			if(!pFmt || pBase->GetName() != pFmt->GetName())
327 				aStyleLB.InsertEntry(pBase->GetName());
328 			pBase = pPool->Next();
329 		}
330 		aStyleLB.SelectEntryPos(0);
331 		SelectHdl(&aStyleLB);
332 
333 	}
334 	else
335 	{
336 		String sTbEntry;
337 		SvLBoxEntry* pE = aTbLinks.FirstSelected();
338 		if(pE)
339 			sTbEntry = aTbLinks.GetEntryText(pE);
340 		sTbEntry = sTbEntry.GetToken(1, '\t');
341 		String sStyle = aStyleLB.GetSelectEntry();
342 
343 		aAssignPB.Enable( sStyle != sTbEntry && aConditionCB.IsChecked() );
344 
345 		if(pBox != &aStyleLB)
346 			aRemovePB.Enable( aConditionCB.IsChecked() && sTbEntry.Len() );
347 	}
348 	return 0;
349 }
350 
351 /****************************************************************************
352 
353 ****************************************************************************/
354 
355 
SetCollection(SwFmt * pFormat,sal_Bool bNew)356 void SwCondCollPage::SetCollection( SwFmt* pFormat, sal_Bool bNew )
357 {
358 	pFmt = pFormat;
359 	bNewTemplate = bNew;
360 }
361