1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "swmodule.hxx"
24 #include "globals.hrc"
27 #include <sfx2/styfitem.hxx>
32 #include "hintids.hxx"
34 #include "docstyle.hxx"
39 #include <vcl/svapp.hxx>
41 #include "swuiccoll.hxx"
43 static sal_uInt16 aPageRg
[] = {
44 FN_COND_COLL
, FN_COND_COLL
,
48 // Warning! This table is indicated directly in code (0, 1, ...)
50 { 2, // Number of Tabs
54 SwCondCollPage::SwCondCollPage(Window
*pParent
, const SfxItemSet
&rSet
)
56 : SfxTabPage(pParent
, SW_RES(TP_CONDCOLL
), rSet
),
57 aConditionFL( this, SW_RES( FL_CONDITION
)),
58 aConditionCB( this, SW_RES( CB_CONDITION
) ),
59 aContextFT ( this, SW_RES( FT_CONTEXT
) ),
60 aUsedFT ( this, SW_RES( FT_USED
) ),
61 aTbLinks( this, SW_RES( TB_CONDCOLLS
) ),
62 aStyleFT ( this, SW_RES( FT_STYLE
) ),
63 aStyleLB ( this, SW_RES( LB_STYLE
) ),
64 aFilterLB ( this, SW_RES( LB_FILTER
) ),
65 aRemovePB ( this, SW_RES( PB_REMOVE
) ),
66 aAssignPB ( this, SW_RES( PB_ASSIGN
) ),
67 sNoTmpl ( SW_RES( STR_NOTEMPL
) ),
68 aStrArr ( SW_RES( STR_REGIONS
) ),
69 rSh(::GetActiveView()->GetWrtShell()),
70 pCmds( SwCondCollItem::GetCmds() ),
73 bNewTemplate(sal_False
)
78 aRemovePB
.SetAccessibleRelationMemberOf(&aConditionFL
);
79 aAssignPB
.SetAccessibleRelationMemberOf(&aConditionFL
);
80 aTbLinks
.SetAccessibleRelationLabeledBy(&aConditionCB
);
83 aConditionCB
.SetClickHdl( LINK(this, SwCondCollPage
, OnOffHdl
));
84 aTbLinks
.SetDoubleClickHdl( LINK(this, SwCondCollPage
, AssignRemoveHdl
));
85 aStyleLB
.SetDoubleClickHdl( LINK(this, SwCondCollPage
, AssignRemoveHdl
));
86 aRemovePB
.SetClickHdl( LINK(this, SwCondCollPage
, AssignRemoveHdl
));
87 aAssignPB
.SetClickHdl( LINK(this, SwCondCollPage
, AssignRemoveHdl
));
88 aTbLinks
.SetSelectHdl( LINK(this, SwCondCollPage
, SelectHdl
));
89 aStyleLB
.SetSelectHdl( LINK(this, SwCondCollPage
, SelectHdl
));
90 aFilterLB
.SetSelectHdl( LINK(this, SwCondCollPage
, SelectHdl
));
92 aTbLinks
.SetStyle(aTbLinks
.GetStyle()|WB_HSCROLL
|WB_CLIPCHILDREN
);
93 aTbLinks
.SetSelectionMode( SINGLE_SELECTION
);
94 aTbLinks
.SetTabs( &nTabs
[0], MAP_APPFONT
);
95 aTbLinks
.Resize(); // OS: Hack for the right selection
96 aTbLinks
.SetSpaceBetweenEntries( 0 );
97 aTbLinks
.SetHelpId(HID_COND_COLL_TABLIST
);
99 SfxStyleFamilies
aFamilies(SW_RES(DLG_STYLE_DESIGNER
));
100 const SfxStyleFamilyItem
* pFamilyItem
= 0;
102 size_t nCount
= aFamilies
.size();
103 for( size_t i
= 0; i
< nCount
; ++i
)
105 if(SFX_STYLE_FAMILY_PARA
== (sal_uInt16
)(pFamilyItem
= aFamilies
.at( i
))->GetFamily())
109 const SfxStyleFilter
& rFilterList
= pFamilyItem
->GetFilterList();
110 for( size_t i
= 0; i
< rFilterList
.size(); ++i
)
112 aFilterLB
.InsertEntry( rFilterList
[ i
]->aName
);
113 sal_uInt16
* pFilter
= new sal_uInt16(rFilterList
[i
]->nFlags
);
114 aFilterLB
.SetEntryData(i
, pFilter
);
116 aFilterLB
.SelectEntryPos(1);
122 /****************************************************************************
124 ****************************************************************************/
127 SwCondCollPage::~SwCondCollPage()
129 for(sal_uInt16 i
= 0; i
< aFilterLB
.GetEntryCount(); ++i
)
130 delete (sal_uInt16
*)aFilterLB
.GetEntryData(i
);
135 int SwCondCollPage::DeactivatePage(SfxItemSet
* _pSet
)
143 /****************************************************************************
145 ****************************************************************************/
148 SfxTabPage
* SwCondCollPage::Create(Window
*pParent
, const SfxItemSet
&rSet
)
150 return new SwCondCollPage(pParent
, rSet
);
153 /****************************************************************************
154 Page: FillItemSet-Overload
155 ****************************************************************************/
158 sal_Bool
SwCondCollPage::FillItemSet(SfxItemSet
&rSet
)
160 sal_Bool bModified
= sal_True
;
161 SwCondCollItem aCondItem
;
162 for(sal_uInt16 i
= 0; i
< aStrArr
.Count(); i
++)
164 String sEntry
= aTbLinks
.GetEntryText(i
, 1);
165 aCondItem
.SetStyle( &sEntry
, i
);
171 /****************************************************************************
173 ****************************************************************************/
176 void SwCondCollPage::Reset(const SfxItemSet
&/*rSet*/)
179 aConditionCB
.Enable();
180 if(RES_CONDTXTFMTCOLL
== pFmt
->Which())
181 aConditionCB
.Check();
182 OnOffHdl(&aConditionCB
);
186 SfxStyleSheetBasePool
* pPool
= rSh
.GetView().GetDocShell()->GetStyleSheetPool();
187 pPool
->SetSearchMask(SFX_STYLE_FAMILY_PARA
, SFXSTYLEBIT_ALL
);
189 const SfxStyleSheetBase
* pBase
= pPool
->First();
192 if(!pFmt
|| pBase
->GetName() != pFmt
->GetName())
193 aStyleLB
.InsertEntry(pBase
->GetName());
194 pBase
= pPool
->Next();
196 aStyleLB
.SelectEntryPos(0);
198 for( sal_uInt16 n
= 0; n
< aStrArr
.Count(); n
++)
200 String
aEntry( aStrArr
.GetString(n
) );
203 const SwCollCondition
* pCond
= 0;
204 if( pFmt
&& RES_CONDTXTFMTCOLL
== pFmt
->Which() &&
205 0 != ( pCond
= ((SwConditionTxtFmtColl
*)pFmt
)->
206 HasCondition( SwCollCondition( 0, pCmds
[n
].nCnd
, pCmds
[n
].nSubCond
) ) )
207 && pCond
->GetTxtFmtColl() )
209 aEntry
+= pCond
->GetTxtFmtColl()->GetName();
212 SvTreeListEntry
* pE
= aTbLinks
.InsertEntryToColumn( aEntry
, n
);
219 sal_uInt16
* SwCondCollPage::GetRanges()
224 IMPL_LINK( SwCondCollPage
, OnOffHdl
, CheckBox
*, pBox
)
226 const sal_Bool bEnable
= pBox
->IsChecked();
227 aContextFT
.Enable( bEnable
);
228 aUsedFT
.Enable( bEnable
);
229 aTbLinks
.EnableList( bEnable
!= sal_False
);
230 aStyleFT
.Enable( bEnable
);
231 aStyleLB
.Enable( bEnable
);
232 aFilterLB
.Enable( bEnable
);
233 aRemovePB
.Enable( bEnable
);
234 aAssignPB
.Enable( bEnable
);
240 IMPL_LINK( SwCondCollPage
, AssignRemoveHdl
, PushButton
*, pBtn
)
242 SvTreeListEntry
* pE
= aTbLinks
.FirstSelected();
244 if( !pE
|| LISTBOX_ENTRY_NOTFOUND
==
245 ( nPos
= aTbLinks
.GetModel()->GetAbsPos( pE
) ) )
247 OSL_ENSURE( pE
, "where's the empty entry from?" );
251 String sSel
= aStrArr
.GetString( sal_uInt16(nPos
) );
254 const sal_Bool bAssEnabled
= pBtn
!= &aRemovePB
&& aAssignPB
.IsEnabled();
255 aAssignPB
.Enable( !bAssEnabled
);
256 aRemovePB
.Enable( bAssEnabled
);
258 sSel
+= aStyleLB
.GetSelectEntry();
260 aTbLinks
.SetUpdateMode(sal_False
);
261 aTbLinks
.GetModel()->Remove(pE
);
262 pE
= aTbLinks
.InsertEntryToColumn(sSel
, nPos
);
264 aTbLinks
.MakeVisible(pE
);
265 aTbLinks
.SetUpdateMode(sal_True
);
269 IMPL_LINK( SwCondCollPage
, SelectHdl
, ListBox
*, pBox
)
271 if(pBox
== &aFilterLB
)
274 sal_uInt16 nSearchFlags
= pBox
->GetSelectEntryPos();
275 nSearchFlags
= *(sal_uInt16
*)aFilterLB
.GetEntryData(nSearchFlags
);
276 SfxStyleSheetBasePool
* pPool
= rSh
.GetView().GetDocShell()->GetStyleSheetPool();
277 pPool
->SetSearchMask(SFX_STYLE_FAMILY_PARA
, nSearchFlags
);
278 const SfxStyleSheetBase
* pBase
= pPool
->First();
282 if(!pFmt
|| pBase
->GetName() != pFmt
->GetName())
283 aStyleLB
.InsertEntry(pBase
->GetName());
284 pBase
= pPool
->Next();
286 aStyleLB
.SelectEntryPos(0);
287 SelectHdl(&aStyleLB
);
293 SvTreeListEntry
* pE
= aTbLinks
.FirstSelected();
295 sTbEntry
= aTbLinks
.GetEntryText(pE
);
296 sTbEntry
= sTbEntry
.GetToken(1, '\t');
297 String sStyle
= aStyleLB
.GetSelectEntry();
299 aAssignPB
.Enable( sStyle
!= sTbEntry
&& aConditionCB
.IsChecked() );
301 if(pBox
!= &aStyleLB
)
302 aRemovePB
.Enable( aConditionCB
.IsChecked() && sTbEntry
.Len() );
307 void SwCondCollPage::SetCollection( SwFmt
* pFormat
, sal_Bool bNew
)
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */