xref: /trunk/main/sw/source/ui/chrdlg/swuiccoll.cxx (revision efeef26f)
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 
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 	const SfxStyleFilter& rFilterList = pFamilyItem->GetFilterList();
131 	for( i = 0; i < rFilterList.Count(); ++i)
132 	{
133 		aFilterLB.InsertEntry(rFilterList.GetObject(i)->aName);
134 		sal_uInt16* pFilter = new sal_uInt16(rFilterList.GetObject(i)->nFlags);
135 		aFilterLB.SetEntryData(i, pFilter);
136 	}
137 	aFilterLB.SelectEntryPos(1);
138 
139 	aTbLinks.Show();
140 
141 }
142 
143 /****************************************************************************
144 Page: Dtor
145 ****************************************************************************/
146 
147 
148 __EXPORT SwCondCollPage::~SwCondCollPage()
149 {
150 	for(sal_uInt16 i = 0; i < aFilterLB.GetEntryCount(); ++i)
151 		delete (sal_uInt16*)aFilterLB.GetEntryData(i);
152 
153 }
154 
155 
156 int __EXPORT SwCondCollPage::DeactivatePage(SfxItemSet * _pSet)
157 {
158     if( _pSet )
159         FillItemSet(*_pSet);
160 
161 	return LEAVE_PAGE;
162 }
163 
164 /****************************************************************************
165 Page: Factory
166 ****************************************************************************/
167 
168 
169 SfxTabPage* __EXPORT SwCondCollPage::Create(Window *pParent, const SfxItemSet &rSet)
170 {
171 	return new SwCondCollPage(pParent, rSet);
172 }
173 
174 /****************************************************************************
175 Page: FillItemSet-Overload
176 ****************************************************************************/
177 
178 
179 sal_Bool __EXPORT SwCondCollPage::FillItemSet(SfxItemSet &rSet)
180 {
181 	sal_Bool bModified = sal_True;
182 	SwCondCollItem aCondItem;
183 	for(sal_uInt16 i = 0; i < aStrArr.Count(); i++)
184 	{
185 		String sEntry = aTbLinks.GetEntryText(i, 1);
186 		aCondItem.SetStyle( &sEntry, i);
187 	}
188 	rSet.Put(aCondItem);
189 	return bModified;
190 }
191 
192 /****************************************************************************
193 Page: Reset-Overload
194 ****************************************************************************/
195 
196 
197 void __EXPORT SwCondCollPage::Reset(const SfxItemSet &/*rSet*/)
198 {
199 	if(bNewTemplate)
200 		aConditionCB.Enable();
201 	if(RES_CONDTXTFMTCOLL == pFmt->Which())
202 		aConditionCB.Check();
203 	OnOffHdl(&aConditionCB);
204 
205 	aTbLinks.Clear();
206 
207 	SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
208 	pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL);
209 	aStyleLB.Clear();
210 	const SfxStyleSheetBase* pBase = pPool->First();
211 	while( pBase )
212 	{
213 		if(!pFmt || pBase->GetName() != pFmt->GetName())
214 			aStyleLB.InsertEntry(pBase->GetName());
215 		pBase = pPool->Next();
216 	}
217 	aStyleLB.SelectEntryPos(0);
218 
219 	for( sal_uInt16 n = 0; n < aStrArr.Count(); n++)
220 	{
221 		String aEntry( aStrArr.GetString(n) );
222 		aEntry += '\t';
223 
224         const SwCollCondition* pCond = 0;
225 		if( pFmt && RES_CONDTXTFMTCOLL == pFmt->Which() &&
226 			0 != ( pCond = ((SwConditionTxtFmtColl*)pFmt)->
227 			HasCondition( SwCollCondition( 0, pCmds[n].nCnd, pCmds[n].nSubCond ) ) )
228 			&& pCond->GetTxtFmtColl() )
229 		{
230 			aEntry += pCond->GetTxtFmtColl()->GetName();
231 		}
232 
233 		SvLBoxEntry* pE = aTbLinks.InsertEntryToColumn( aEntry, n );
234 		if(0 == n)
235 			aTbLinks.Select(pE);
236 	}
237 
238 }
239 
240 /****************************************************************************
241 
242 ****************************************************************************/
243 
244 
245 sal_uInt16* __EXPORT SwCondCollPage::GetRanges()
246 {
247 	return aPageRg;
248 }
249 
250 
251 /****************************************************************************
252 
253 ****************************************************************************/
254 
255 
256 IMPL_LINK( SwCondCollPage, OnOffHdl, CheckBox*, pBox )
257 {
258 	const sal_Bool bEnable = pBox->IsChecked();
259 	aContextFT.Enable( bEnable );
260 	aUsedFT   .Enable( bEnable );
261     aTbLinks  .EnableList( bEnable != sal_False );
262 	aStyleFT  .Enable( bEnable );
263 	aStyleLB  .Enable( bEnable );
264 	aFilterLB .Enable( bEnable );
265 	aRemovePB .Enable( bEnable );
266 	aAssignPB .Enable( bEnable );
267 	if( bEnable )
268 		SelectHdl(0);
269 	return 0;
270 }
271 
272 /****************************************************************************
273 
274 ****************************************************************************/
275 
276 
277 IMPL_LINK( SwCondCollPage, AssignRemoveHdl, PushButton*, pBtn)
278 {
279 	SvLBoxEntry* pE = aTbLinks.FirstSelected();
280 	sal_uLong nPos;
281 	if( !pE || LISTBOX_ENTRY_NOTFOUND ==
282 		( nPos = aTbLinks.GetModel()->GetAbsPos( pE ) ) )
283 	{
284 		ASSERT( pE, "wo kommt der leere Eintrag her?" );
285 		return 0;
286 	}
287 
288 	String sSel = aStrArr.GetString( sal_uInt16(nPos) );
289 	sSel += '\t';
290 
291 	const sal_Bool bAssEnabled = pBtn != &aRemovePB && aAssignPB.IsEnabled();
292 	aAssignPB.Enable( !bAssEnabled );
293 	aRemovePB.Enable(  bAssEnabled );
294 	if ( bAssEnabled )
295 		sSel += aStyleLB.GetSelectEntry();
296 
297 	aTbLinks.SetUpdateMode(sal_False);
298 	aTbLinks.GetModel()->Remove(pE);
299 	pE = aTbLinks.InsertEntryToColumn(sSel, nPos);
300 	aTbLinks.Select(pE);
301 	aTbLinks.MakeVisible(pE);
302 	aTbLinks.SetUpdateMode(sal_True);
303 	return 0;
304 }
305 
306 /****************************************************************************
307 
308 ****************************************************************************/
309 
310 
311 IMPL_LINK( SwCondCollPage, SelectHdl, ListBox*, pBox)
312 {
313 	if(pBox == &aFilterLB)
314 	{
315 		aStyleLB.Clear();
316 		sal_uInt16 nSearchFlags = pBox->GetSelectEntryPos();
317 		nSearchFlags = *(sal_uInt16*)aFilterLB.GetEntryData(nSearchFlags);
318 		SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
319 		pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, nSearchFlags);
320 		const SfxStyleSheetBase* pBase = pPool->First();
321 		while( pBase )
322 		{
323 			if(!pFmt || pBase->GetName() != pFmt->GetName())
324 				aStyleLB.InsertEntry(pBase->GetName());
325 			pBase = pPool->Next();
326 		}
327 		aStyleLB.SelectEntryPos(0);
328 		SelectHdl(&aStyleLB);
329 
330 	}
331 	else
332 	{
333 		String sTbEntry;
334 		SvLBoxEntry* pE = aTbLinks.FirstSelected();
335 		if(pE)
336 			sTbEntry = aTbLinks.GetEntryText(pE);
337 		sTbEntry = sTbEntry.GetToken(1, '\t');
338 		String sStyle = aStyleLB.GetSelectEntry();
339 
340 		aAssignPB.Enable( sStyle != sTbEntry && aConditionCB.IsChecked() );
341 
342 		if(pBox != &aStyleLB)
343 			aRemovePB.Enable( aConditionCB.IsChecked() && sTbEntry.Len() );
344 	}
345 	return 0;
346 }
347 
348 /****************************************************************************
349 
350 ****************************************************************************/
351 
352 
353 void SwCondCollPage::SetCollection( SwFmt* pFormat, sal_Bool bNew )
354 {
355 	pFmt = pFormat;
356 	bNewTemplate = bNew;
357 }
358