1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swuiccoll.cxx,v $
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
41 #include <tools/list.hxx>
42 #include "swmodule.hxx"
45 #include "globals.hrc"
49 #include <sfx2/styfitem.hxx>
54 #include "hintids.hxx"
56 #include "docstyle.hxx"
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
72 { 2, // Number of Tabs
76 /****************************************************************************
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() ),
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();
127 for( i
= 0; i
< nCount
; ++i
)
129 if(SFX_STYLE_FAMILY_PARA
== (USHORT
)(pFamilyItem
= aFamilies
.GetObject(i
))->GetFamily())
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);
146 /****************************************************************************
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
)
167 /****************************************************************************
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
);
195 /****************************************************************************
197 ****************************************************************************/
200 void __EXPORT
SwCondCollPage::Reset(const SfxItemSet
&/*rSet*/)
203 aConditionCB
.Enable();
204 if(RES_CONDTXTFMTCOLL
== pFmt
->Which())
205 aConditionCB
.Check();
206 OnOffHdl(&aConditionCB
);
210 SfxStyleSheetBasePool
* pPool
= rSh
.GetView().GetDocShell()->GetStyleSheetPool();
211 pPool
->SetSearchMask(SFX_STYLE_FAMILY_PARA
, SFXSTYLEBIT_ALL
);
213 const SfxStyleSheetBase
* pBase
= pPool
->First();
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
) );
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
);
243 /****************************************************************************
245 ****************************************************************************/
248 USHORT
* __EXPORT
SwCondCollPage::GetRanges()
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
);
275 /****************************************************************************
277 ****************************************************************************/
280 IMPL_LINK( SwCondCollPage
, AssignRemoveHdl
, PushButton
*, pBtn
)
282 SvLBoxEntry
* pE
= aTbLinks
.FirstSelected();
284 if( !pE
|| LISTBOX_ENTRY_NOTFOUND
==
285 ( nPos
= aTbLinks
.GetModel()->GetAbsPos( pE
) ) )
287 ASSERT( pE
, "wo kommt der leere Eintrag her?" );
291 String sSel
= aStrArr
.GetString( USHORT(nPos
) );
294 const BOOL bAssEnabled
= pBtn
!= &aRemovePB
&& aAssignPB
.IsEnabled();
295 aAssignPB
.Enable( !bAssEnabled
);
296 aRemovePB
.Enable( bAssEnabled
);
298 sSel
+= aStyleLB
.GetSelectEntry();
300 aTbLinks
.SetUpdateMode(FALSE
);
301 aTbLinks
.GetModel()->Remove(pE
);
302 pE
= aTbLinks
.InsertEntryToColumn(sSel
, nPos
);
304 aTbLinks
.MakeVisible(pE
);
305 aTbLinks
.SetUpdateMode(TRUE
);
309 /****************************************************************************
311 ****************************************************************************/
314 IMPL_LINK( SwCondCollPage
, SelectHdl
, ListBox
*, pBox
)
316 if(pBox
== &aFilterLB
)
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();
326 if(!pFmt
|| pBase
->GetName() != pFmt
->GetName())
327 aStyleLB
.InsertEntry(pBase
->GetName());
328 pBase
= pPool
->Next();
330 aStyleLB
.SelectEntryPos(0);
331 SelectHdl(&aStyleLB
);
337 SvLBoxEntry
* pE
= aTbLinks
.FirstSelected();
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() );
351 /****************************************************************************
353 ****************************************************************************/
356 void SwCondCollPage::SetCollection( SwFmt
* pFormat
, BOOL bNew
)