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