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