bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / chrdlg / swuiccoll.cxx
blobbeb916efbc8a7f0c3e0aeec637633f2db7592ad5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "cmdid.h"
21 #include "swmodule.hxx"
22 #include "view.hxx"
23 #include "wrtsh.hxx"
24 #include "globals.hrc"
25 #include "helpid.h"
27 #include <sfx2/styfitem.hxx>
29 #include "uitool.hxx"
30 #include "ccoll.hxx"
31 #include "fmtcol.hxx"
32 #include "hintids.hxx"
33 #include "docsh.hxx"
34 #include "docstyle.hxx"
35 #include "hints.hxx"
37 #include "chrdlg.hrc"
38 #include "ccoll.hrc"
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, ...)
49 static long nTabs[] =
50 { 2, // Number of Tabs
51 0, 100
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() ),
71 pFmt(0),
73 bNewTemplate(sal_False)
75 FreeResource();
76 SetExchangeSupport();
78 aRemovePB.SetAccessibleRelationMemberOf(&aConditionFL);
79 aAssignPB.SetAccessibleRelationMemberOf(&aConditionFL);
80 aTbLinks.SetAccessibleRelationLabeledBy(&aConditionCB);
82 // Install handlers
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())
106 break;
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);
118 aTbLinks.Show();
122 /****************************************************************************
123 Page: Dtor
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)
137 if( _pSet )
138 FillItemSet(*_pSet);
140 return LEAVE_PAGE;
143 /****************************************************************************
144 Page: Factory
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);
167 rSet.Put(aCondItem);
168 return bModified;
171 /****************************************************************************
172 Page: Reset-Overload
173 ****************************************************************************/
176 void SwCondCollPage::Reset(const SfxItemSet &/*rSet*/)
178 if(bNewTemplate)
179 aConditionCB.Enable();
180 if(RES_CONDTXTFMTCOLL == pFmt->Which())
181 aConditionCB.Check();
182 OnOffHdl(&aConditionCB);
184 aTbLinks.Clear();
186 SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
187 pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL);
188 aStyleLB.Clear();
189 const SfxStyleSheetBase* pBase = pPool->First();
190 while( pBase )
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) );
201 aEntry += '\t';
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 );
213 if(0 == n)
214 aTbLinks.Select(pE);
219 sal_uInt16* SwCondCollPage::GetRanges()
221 return aPageRg;
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 );
235 if( bEnable )
236 SelectHdl(0);
237 return 0;
240 IMPL_LINK( SwCondCollPage, AssignRemoveHdl, PushButton*, pBtn)
242 SvTreeListEntry* pE = aTbLinks.FirstSelected();
243 sal_uLong nPos;
244 if( !pE || LISTBOX_ENTRY_NOTFOUND ==
245 ( nPos = aTbLinks.GetModel()->GetAbsPos( pE ) ) )
247 OSL_ENSURE( pE, "where's the empty entry from?" );
248 return 0;
251 String sSel = aStrArr.GetString( sal_uInt16(nPos) );
252 sSel += '\t';
254 const sal_Bool bAssEnabled = pBtn != &aRemovePB && aAssignPB.IsEnabled();
255 aAssignPB.Enable( !bAssEnabled );
256 aRemovePB.Enable( bAssEnabled );
257 if ( bAssEnabled )
258 sSel += aStyleLB.GetSelectEntry();
260 aTbLinks.SetUpdateMode(sal_False);
261 aTbLinks.GetModel()->Remove(pE);
262 pE = aTbLinks.InsertEntryToColumn(sSel, nPos);
263 aTbLinks.Select(pE);
264 aTbLinks.MakeVisible(pE);
265 aTbLinks.SetUpdateMode(sal_True);
266 return 0;
269 IMPL_LINK( SwCondCollPage, SelectHdl, ListBox*, pBox)
271 if(pBox == &aFilterLB)
273 aStyleLB.Clear();
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();
280 while( pBase )
282 if(!pFmt || pBase->GetName() != pFmt->GetName())
283 aStyleLB.InsertEntry(pBase->GetName());
284 pBase = pPool->Next();
286 aStyleLB.SelectEntryPos(0);
287 SelectHdl(&aStyleLB);
290 else
292 String sTbEntry;
293 SvTreeListEntry* pE = aTbLinks.FirstSelected();
294 if(pE)
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() );
304 return 0;
307 void SwCondCollPage::SetCollection( SwFmt* pFormat, sal_Bool bNew )
309 pFmt = pFormat;
310 bNewTemplate = bNew;
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */