update dev300-m58
[ooovba.git] / sw / source / ui / chrdlg / swuiccoll.cxx
blobfe6aba72aec97ed70be09494a92bafa8c23a38cf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swuiccoll.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
40 #include "cmdid.h"
41 #include <tools/list.hxx>
42 #include "swmodule.hxx"
43 #include "view.hxx"
44 #include "wrtsh.hxx"
45 #include "globals.hrc"
46 #include "helpid.h"
49 #include <sfx2/styfitem.hxx>
51 #include "uitool.hxx"
52 #include "ccoll.hxx"
53 #include "fmtcol.hxx"
54 #include "hintids.hxx"
55 #include "docsh.hxx"
56 #include "docstyle.hxx"
57 #include "hints.hxx"
59 #include "chrdlg.hrc"
60 #include "ccoll.hrc"
61 #include <vcl/svapp.hxx>
63 #include "swuiccoll.hxx"
65 static USHORT __FAR_DATA aPageRg[] = {
66 FN_COND_COLL, FN_COND_COLL,
70 // Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert
71 static long nTabs[] =
72 { 2, // Number of Tabs
73 0, 100
76 /****************************************************************************
77 Page: Ctor
78 ****************************************************************************/
81 SwCondCollPage::SwCondCollPage(Window *pParent, const SfxItemSet &rSet)
83 : SfxTabPage(pParent, SW_RES(TP_CONDCOLL), rSet),
84 aConditionFL( this, SW_RES( FL_CONDITION )),
85 aConditionCB( this, SW_RES( CB_CONDITION ) ),
86 aContextFT ( this, SW_RES( FT_CONTEXT ) ),
87 aUsedFT ( this, SW_RES( FT_USED ) ),
88 aTbLinks( this, SW_RES( TB_CONDCOLLS ) ),
89 aStyleFT ( this, SW_RES( FT_STYLE ) ),
90 aStyleLB ( this, SW_RES( LB_STYLE ) ),
91 aFilterLB ( this, SW_RES( LB_FILTER ) ),
92 aRemovePB ( this, SW_RES( PB_REMOVE ) ),
93 aAssignPB ( this, SW_RES( PB_ASSIGN ) ),
94 sNoTmpl ( SW_RES( STR_NOTEMPL ) ),
95 aStrArr ( SW_RES( STR_REGIONS ) ),
96 rSh(::GetActiveView()->GetWrtShell()),
97 pCmds( SwCondCollItem::GetCmds() ),
98 pFmt(0),
100 bNewTemplate(FALSE)
102 FreeResource();
103 SetExchangeSupport();
105 // Handler installieren
106 aConditionCB.SetClickHdl( LINK(this, SwCondCollPage, OnOffHdl));
107 aTbLinks.SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
108 aStyleLB.SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
109 aRemovePB.SetClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
110 aAssignPB.SetClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
111 aTbLinks.SetSelectHdl( LINK(this, SwCondCollPage, SelectHdl));
112 aStyleLB.SetSelectHdl( LINK(this, SwCondCollPage, SelectHdl));
113 aFilterLB.SetSelectHdl( LINK(this, SwCondCollPage, SelectHdl));
115 aTbLinks.SetWindowBits(WB_HSCROLL|WB_CLIPCHILDREN);
116 aTbLinks.SetSelectionMode( SINGLE_SELECTION );
117 aTbLinks.SetTabs( &nTabs[0], MAP_APPFONT );
118 aTbLinks.Resize(); // OS: Hack fuer richtige Selektion
119 aTbLinks.SetSpaceBetweenEntries( 0 );
120 aTbLinks.SetHelpId(HID_COND_COLL_TABLIST);
122 SfxStyleFamilies aFamilies(SW_RES(DLG_STYLE_DESIGNER));
123 const SfxStyleFamilyItem* pFamilyItem = 0;
124 USHORT nCount = aFamilies.Count();
125 USHORT i;
127 for( i = 0; i < nCount; ++i)
129 if(SFX_STYLE_FAMILY_PARA == (USHORT)(pFamilyItem = aFamilies.GetObject(i))->GetFamily())
130 break;
133 const SfxStyleFilter& rFilterList = pFamilyItem->GetFilterList();
134 for( i = 0; i < rFilterList.Count(); ++i)
136 aFilterLB.InsertEntry(rFilterList.GetObject(i)->aName);
137 USHORT* pFilter = new USHORT(rFilterList.GetObject(i)->nFlags);
138 aFilterLB.SetEntryData(i, pFilter);
140 aFilterLB.SelectEntryPos(1);
142 aTbLinks.Show();
146 /****************************************************************************
147 Page: Dtor
148 ****************************************************************************/
151 __EXPORT SwCondCollPage::~SwCondCollPage()
153 for(USHORT i = 0; i < aFilterLB.GetEntryCount(); ++i)
154 delete (USHORT*)aFilterLB.GetEntryData(i);
159 int __EXPORT SwCondCollPage::DeactivatePage(SfxItemSet * _pSet)
161 if( _pSet )
162 FillItemSet(*_pSet);
164 return LEAVE_PAGE;
167 /****************************************************************************
168 Page: Factory
169 ****************************************************************************/
172 SfxTabPage* __EXPORT SwCondCollPage::Create(Window *pParent, const SfxItemSet &rSet)
174 return new SwCondCollPage(pParent, rSet);
177 /****************************************************************************
178 Page: FillItemSet-Overload
179 ****************************************************************************/
182 BOOL __EXPORT SwCondCollPage::FillItemSet(SfxItemSet &rSet)
184 BOOL bModified = TRUE;
185 SwCondCollItem aCondItem;
186 for(USHORT i = 0; i < aStrArr.Count(); i++)
188 String sEntry = aTbLinks.GetEntryText(i, 1);
189 aCondItem.SetStyle( &sEntry, i);
191 rSet.Put(aCondItem);
192 return bModified;
195 /****************************************************************************
196 Page: Reset-Overload
197 ****************************************************************************/
200 void __EXPORT SwCondCollPage::Reset(const SfxItemSet &/*rSet*/)
202 if(bNewTemplate)
203 aConditionCB.Enable();
204 if(RES_CONDTXTFMTCOLL == pFmt->Which())
205 aConditionCB.Check();
206 OnOffHdl(&aConditionCB);
208 aTbLinks.Clear();
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 )
216 if(!pFmt || pBase->GetName() != pFmt->GetName())
217 aStyleLB.InsertEntry(pBase->GetName());
218 pBase = pPool->Next();
220 aStyleLB.SelectEntryPos(0);
222 for( USHORT n = 0; n < aStrArr.Count(); n++)
224 String aEntry( aStrArr.GetString(n) );
225 aEntry += '\t';
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() )
233 aEntry += pCond->GetTxtFmtColl()->GetName();
236 SvLBoxEntry* pE = aTbLinks.InsertEntryToColumn( aEntry, n );
237 if(0 == n)
238 aTbLinks.Select(pE);
243 /****************************************************************************
245 ****************************************************************************/
248 USHORT* __EXPORT SwCondCollPage::GetRanges()
250 return aPageRg;
254 /****************************************************************************
256 ****************************************************************************/
259 IMPL_LINK( SwCondCollPage, OnOffHdl, CheckBox*, pBox )
261 const BOOL bEnable = pBox->IsChecked();
262 aContextFT.Enable( bEnable );
263 aUsedFT .Enable( bEnable );
264 aTbLinks .EnableList( bEnable != 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;
275 /****************************************************************************
277 ****************************************************************************/
280 IMPL_LINK( SwCondCollPage, AssignRemoveHdl, PushButton*, pBtn)
282 SvLBoxEntry* pE = aTbLinks.FirstSelected();
283 ULONG nPos;
284 if( !pE || LISTBOX_ENTRY_NOTFOUND ==
285 ( nPos = aTbLinks.GetModel()->GetAbsPos( pE ) ) )
287 ASSERT( pE, "wo kommt der leere Eintrag her?" );
288 return 0;
291 String sSel = aStrArr.GetString( USHORT(nPos) );
292 sSel += '\t';
294 const BOOL bAssEnabled = pBtn != &aRemovePB && aAssignPB.IsEnabled();
295 aAssignPB.Enable( !bAssEnabled );
296 aRemovePB.Enable( bAssEnabled );
297 if ( bAssEnabled )
298 sSel += aStyleLB.GetSelectEntry();
300 aTbLinks.SetUpdateMode(FALSE);
301 aTbLinks.GetModel()->Remove(pE);
302 pE = aTbLinks.InsertEntryToColumn(sSel, nPos);
303 aTbLinks.Select(pE);
304 aTbLinks.MakeVisible(pE);
305 aTbLinks.SetUpdateMode(TRUE);
306 return 0;
309 /****************************************************************************
311 ****************************************************************************/
314 IMPL_LINK( SwCondCollPage, SelectHdl, ListBox*, pBox)
316 if(pBox == &aFilterLB)
318 aStyleLB.Clear();
319 USHORT nSearchFlags = pBox->GetSelectEntryPos();
320 nSearchFlags = *(USHORT*)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 )
326 if(!pFmt || pBase->GetName() != pFmt->GetName())
327 aStyleLB.InsertEntry(pBase->GetName());
328 pBase = pPool->Next();
330 aStyleLB.SelectEntryPos(0);
331 SelectHdl(&aStyleLB);
334 else
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();
343 aAssignPB.Enable( sStyle != sTbEntry && aConditionCB.IsChecked() );
345 if(pBox != &aStyleLB)
346 aRemovePB.Enable( aConditionCB.IsChecked() && sTbEntry.Len() );
348 return 0;
351 /****************************************************************************
353 ****************************************************************************/
356 void SwCondCollPage::SetCollection( SwFmt* pFormat, BOOL bNew )
358 pFmt = pFormat;
359 bNewTemplate = bNew;