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