Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / cui / source / options / optfltr.cxx
blobdf2d57e4718a17f99867aefd776fed1ef40988b2
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 <unotools/moduleoptions.hxx>
21 #include <unotools/fltrcfg.hxx>
22 #include "optfltr.hxx"
23 #include "optfltr.hrc"
24 #include <cuires.hrc>
25 #include "helpid.hrc"
26 #include <dialmgr.hxx>
28 #include "svtools/svlbitm.hxx"
29 #include "svtools/treelistentry.hxx"
31 enum MSFltrPg2_CheckBoxEntries {
32 Math,
33 Writer,
34 Calc,
35 Impress,
36 InvalidCBEntry
39 // -----------------------------------------------------------------------
41 OfaMSFilterTabPage::OfaMSFilterTabPage(Window* pParent, const SfxItemSet& rSet)
42 : SfxTabPage( pParent, CUI_RES( RID_OFAPAGE_MSFILTEROPT ), rSet ),
43 aMSWordGB ( this, CUI_RES( GB_WORD ) ),
44 aWBasicCodeCB ( this, CUI_RES( CB_WBAS_CODE ) ),
45 aWBasicWbctblCB ( this, CUI_RES( CB_WBAS_WBCTBL ) ),
46 aWBasicStgCB ( this, CUI_RES( CB_WBAS_STG ) ),
47 aMSExcelGB ( this, CUI_RES( GB_EXCEL ) ),
48 aEBasicCodeCB ( this, CUI_RES( CB_EBAS_CODE ) ),
49 aEBasicExectblCB( this, CUI_RES( CB_EBAS_EXECTBL ) ),
50 aEBasicStgCB ( this, CUI_RES( CB_EBAS_STG ) ),
51 aMSPPointGB ( this, CUI_RES( GB_PPOINT ) ),
52 aPBasicCodeCB ( this, CUI_RES( CB_PBAS_CODE ) ),
53 aPBasicStgCB ( this, CUI_RES( CB_PBAS_STG ) )
55 FreeResource();
57 aWBasicCodeCB.SetClickHdl( LINK( this, OfaMSFilterTabPage, LoadWordBasicCheckHdl_Impl ) );
58 aEBasicCodeCB.SetClickHdl( LINK( this, OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl ) );
61 OfaMSFilterTabPage::~OfaMSFilterTabPage()
65 IMPL_LINK_NOARG(OfaMSFilterTabPage, LoadWordBasicCheckHdl_Impl)
67 aWBasicWbctblCB.Enable( aWBasicCodeCB.IsChecked() );
68 return 0;
71 IMPL_LINK_NOARG(OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl)
73 aEBasicExectblCB.Enable( aEBasicCodeCB.IsChecked() );
74 return 0;
77 SfxTabPage* OfaMSFilterTabPage::Create( Window* pParent,
78 const SfxItemSet& rAttrSet )
80 return new OfaMSFilterTabPage( pParent, rAttrSet );
83 sal_Bool OfaMSFilterTabPage::FillItemSet( SfxItemSet& )
85 SvtFilterOptions& rOpt = SvtFilterOptions::Get();
87 sal_Bool bFlag;
88 if( aWBasicCodeCB.GetSavedValue() != (bFlag = aWBasicCodeCB.IsChecked()))
89 rOpt.SetLoadWordBasicCode( bFlag );
90 if( aWBasicWbctblCB.GetSavedValue() != (bFlag = aWBasicWbctblCB.IsChecked()))
91 rOpt.SetLoadWordBasicExecutable( bFlag );
92 if( aWBasicStgCB.GetSavedValue() != (bFlag = aWBasicStgCB.IsChecked()))
93 rOpt.SetLoadWordBasicStorage( bFlag );
95 if( aEBasicCodeCB.GetSavedValue() != (bFlag = aEBasicCodeCB.IsChecked()))
96 rOpt.SetLoadExcelBasicCode( bFlag );
97 if( aEBasicExectblCB.GetSavedValue() != (bFlag = aEBasicExectblCB.IsChecked()))
98 rOpt.SetLoadExcelBasicExecutable( bFlag );
99 if( aEBasicStgCB.GetSavedValue() != (bFlag = aEBasicStgCB.IsChecked()))
100 rOpt.SetLoadExcelBasicStorage( bFlag );
102 if( aPBasicCodeCB.GetSavedValue() != (bFlag = aPBasicCodeCB.IsChecked()))
103 rOpt.SetLoadPPointBasicCode( bFlag );
104 if( aPBasicStgCB.GetSavedValue() != (bFlag = aPBasicStgCB.IsChecked()))
105 rOpt.SetLoadPPointBasicStorage( bFlag );
107 return sal_False;
110 void OfaMSFilterTabPage::Reset( const SfxItemSet& )
112 const SvtFilterOptions& rOpt = SvtFilterOptions::Get();
114 aWBasicCodeCB.Check( rOpt.IsLoadWordBasicCode() );
115 aWBasicCodeCB.SaveValue();
116 aWBasicWbctblCB.Check( rOpt.IsLoadWordBasicExecutable() );
117 aWBasicWbctblCB.SaveValue();
118 aWBasicStgCB.Check( rOpt.IsLoadWordBasicStorage() );
119 aWBasicStgCB.SaveValue();
120 LoadWordBasicCheckHdl_Impl( &aWBasicCodeCB );
122 aEBasicCodeCB.Check( rOpt.IsLoadExcelBasicCode() );
123 aEBasicCodeCB.SaveValue();
124 aEBasicExectblCB.Check( rOpt.IsLoadExcelBasicExecutable() );
125 aEBasicExectblCB.SaveValue();
126 aEBasicStgCB.Check( rOpt.IsLoadExcelBasicStorage() );
127 aEBasicStgCB.SaveValue();
128 LoadExcelBasicCheckHdl_Impl( &aEBasicCodeCB );
130 aPBasicCodeCB.Check( rOpt.IsLoadPPointBasicCode() );
131 aPBasicCodeCB.SaveValue();
132 aPBasicStgCB.Check( rOpt.IsLoadPPointBasicStorage() );
133 aPBasicStgCB.SaveValue();
136 OfaMSFilterTabPage2::OfaMSFilterTabPage2( Window* pParent,
137 const SfxItemSet& rSet )
138 : SfxTabPage( pParent, CUI_RES( RID_OFAPAGE_MSFILTEROPT2 ), rSet ),
139 m_aCheckLBContainer(this, CUI_RES( CLB_SETTINGS)),
140 aCheckLB(m_aCheckLBContainer),
141 aHeader1FT ( this, CUI_RES( FT_HEADER1_EXPLANATION )),
142 aHeader2FT ( this, CUI_RES( FT_HEADER2_EXPLANATION )),
143 sHeader1 ( CUI_RES( ST_HEADER1 )),
144 sHeader2 ( CUI_RES( ST_HEADER2 )),
145 sChgToFromMath ( CUI_RES( ST_CHG_MATH )),
146 sChgToFromWriter ( CUI_RES( ST_CHG_WRITER )),
147 sChgToFromCalc ( CUI_RES( ST_CHG_CALC )),
148 sChgToFromImpress ( CUI_RES( ST_CHG_IMPRESS )),
149 pCheckButtonData(0)
151 FreeResource();
153 static long aStaticTabs[] = { 3, 0, 20, 40 };
154 aCheckLB.SvxSimpleTable::SetTabs( aStaticTabs );
156 String sHeader( sHeader1 );
157 (( sHeader += '\t' ) += sHeader2 ) += '\t';
158 aCheckLB.InsertHeaderEntry( sHeader, HEADERBAR_APPEND,
159 HIB_CENTER | HIB_VCENTER | HIB_FIXEDPOS | HIB_FIXED );
161 aCheckLB.SetHelpId( HID_OFAPAGE_MSFLTR2_CLB );
162 aCheckLB.SetStyle( aCheckLB.GetStyle()|WB_HSCROLL| WB_VSCROLL );
165 OfaMSFilterTabPage2::~OfaMSFilterTabPage2()
167 delete pCheckButtonData;
170 SfxTabPage* OfaMSFilterTabPage2::Create( Window* pParent,
171 const SfxItemSet& rAttrSet )
173 return new OfaMSFilterTabPage2( pParent, rAttrSet );
176 sal_Bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet& )
178 SvtFilterOptions& rOpt = SvtFilterOptions::Get();
180 static struct ChkCBoxEntries{
181 MSFltrPg2_CheckBoxEntries eType;
182 sal_Bool (SvtFilterOptions:: *FnIs)() const;
183 void (SvtFilterOptions:: *FnSet)( sal_Bool bFlag );
184 } aChkArr[] = {
185 { Math, &SvtFilterOptions::IsMathType2Math,
186 &SvtFilterOptions::SetMathType2Math },
187 { Math, &SvtFilterOptions::IsMath2MathType,
188 &SvtFilterOptions::SetMath2MathType },
189 { Writer, &SvtFilterOptions::IsWinWord2Writer,
190 &SvtFilterOptions::SetWinWord2Writer },
191 { Writer, &SvtFilterOptions::IsWriter2WinWord,
192 &SvtFilterOptions::SetWriter2WinWord },
193 { Calc, &SvtFilterOptions::IsExcel2Calc,
194 &SvtFilterOptions::SetExcel2Calc },
195 { Calc, &SvtFilterOptions::IsCalc2Excel,
196 &SvtFilterOptions::SetCalc2Excel },
197 { Impress, &SvtFilterOptions::IsPowerPoint2Impress,
198 &SvtFilterOptions::SetPowerPoint2Impress },
199 { Impress, &SvtFilterOptions::IsImpress2PowerPoint,
200 &SvtFilterOptions::SetImpress2PowerPoint },
201 { InvalidCBEntry, 0, 0 }
204 sal_Bool bCheck, bFirst = sal_True;
205 for( const ChkCBoxEntries* pArr = aChkArr;
206 InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
208 sal_uInt16 nCol = bFirst ? 1 : 2;
209 SvTreeListEntry* pEntry = GetEntry4Type( pArr->eType );
210 if( pEntry )
212 SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem( nCol ));
213 if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
215 sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
216 bCheck = SV_BUTTON_CHECKED ==
217 pCheckButtonData->ConvertToButtonState( nButtonFlags );
219 if( bCheck != (rOpt.*pArr->FnIs)() )
220 (rOpt.*pArr->FnSet)( bCheck );
225 return sal_True;
228 void OfaMSFilterTabPage2::Reset( const SfxItemSet& )
230 SvtFilterOptions& rOpt = SvtFilterOptions::Get();
232 aCheckLB.SetUpdateMode(sal_False);
233 aCheckLB.Clear();
235 SvtModuleOptions aModuleOpt;
237 // int the same sequence as the enums of MSFltrPg2_CheckBoxEntries
238 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
239 InsertEntry( sChgToFromMath, static_cast< sal_IntPtr >( Math ) );
240 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
241 InsertEntry( sChgToFromWriter, static_cast< sal_IntPtr >( Writer ) );
242 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
243 InsertEntry( sChgToFromCalc, static_cast< sal_IntPtr >( Calc ) );
244 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
245 InsertEntry( sChgToFromImpress, static_cast< sal_IntPtr >( Impress ) );
247 static struct ChkCBoxEntries{
248 MSFltrPg2_CheckBoxEntries eType;
249 sal_Bool (SvtFilterOptions:: *FnIs)() const;
250 } aChkArr[] = {
251 { Math, &SvtFilterOptions::IsMathType2Math },
252 { Math, &SvtFilterOptions::IsMath2MathType },
253 { Writer, &SvtFilterOptions::IsWinWord2Writer },
254 { Writer, &SvtFilterOptions::IsWriter2WinWord },
255 { Calc, &SvtFilterOptions::IsExcel2Calc },
256 { Calc, &SvtFilterOptions::IsCalc2Excel },
257 { Impress, &SvtFilterOptions::IsPowerPoint2Impress },
258 { Impress, &SvtFilterOptions::IsImpress2PowerPoint },
259 { InvalidCBEntry, NULL }
262 sal_Bool bFirst = sal_True;
263 for( const ChkCBoxEntries* pArr = aChkArr;
264 InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
266 sal_uInt16 nCol = bFirst ? 1 : 2;
267 SvTreeListEntry* pEntry = GetEntry4Type( static_cast< sal_IntPtr >( pArr->eType ) );
268 if( pEntry )
270 SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem( nCol ));
271 if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
273 if( (rOpt.*pArr->FnIs)() )
274 pItem->SetStateChecked();
275 else
276 pItem->SetStateUnchecked();
277 aCheckLB.InvalidateEntry( pEntry );
281 aCheckLB.SetUpdateMode( sal_True );
284 void OfaMSFilterTabPage2::InsertEntry( const String& _rTxt, sal_IntPtr _nType )
286 SvTreeListEntry* pEntry = new SvTreeListEntry;
288 if( !pCheckButtonData )
289 pCheckButtonData = new SvLBoxButtonData( &aCheckLB );
291 pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));
292 pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
293 0, pCheckButtonData ) );
294 pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
295 0, pCheckButtonData ) );
296 pEntry->AddItem( new SvLBoxString( pEntry, 0, _rTxt ) );
298 pEntry->SetUserData( (void*)_nType );
299 aCheckLB.Insert( pEntry );
302 SvTreeListEntry* OfaMSFilterTabPage2::GetEntry4Type( sal_IntPtr _nType ) const
304 SvTreeListEntry* pEntry = aCheckLB.First();
305 while ( pEntry )
307 if ( _nType == sal_IntPtr( pEntry->GetUserData() ) )
308 return pEntry;
309 pEntry = aCheckLB.Next( pEntry );
311 return NULL;
314 void OfaMSFilterTabPage2::MSFltrSimpleTable::SetTabs()
316 SvxSimpleTable::SetTabs();
317 sal_uInt16 nAdjust = SV_LBOXTAB_ADJUST_RIGHT|SV_LBOXTAB_ADJUST_LEFT|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_ADJUST_NUMERIC|SV_LBOXTAB_FORCE;
319 if( aTabs.size() > 1 )
321 SvLBoxTab* pTab = aTabs[1];
322 pTab->nFlags &= ~nAdjust;
323 pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
325 if( aTabs.size() > 2 )
327 SvLBoxTab* pTab = aTabs[2];
328 pTab->nFlags &= ~nAdjust;
329 pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
333 void OfaMSFilterTabPage2::MSFltrSimpleTable::HBarClick()
335 // sorting is stopped by this overloading
338 void OfaMSFilterTabPage2::MSFltrSimpleTable::SetCheckButtonState(
339 SvTreeListEntry* pEntry, sal_uInt16 nCol, SvButtonState eState)
341 SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
343 DBG_ASSERT(pItem,"SetCheckButton:Item not found");
344 if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
346 switch( eState )
348 case SV_BUTTON_CHECKED:
349 pItem->SetStateChecked();
350 break;
352 case SV_BUTTON_UNCHECKED:
353 pItem->SetStateUnchecked();
354 break;
356 case SV_BUTTON_TRISTATE:
357 pItem->SetStateTristate();
358 break;
360 InvalidateEntry( pEntry );
364 SvButtonState OfaMSFilterTabPage2::MSFltrSimpleTable::GetCheckButtonState(
365 SvTreeListEntry* pEntry, sal_uInt16 nCol ) const
367 SvButtonState eState = SV_BUTTON_UNCHECKED;
368 SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
369 DBG_ASSERT(pItem,"GetChButnState:Item not found");
371 if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
373 sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
374 eState = pCheckButtonData->ConvertToButtonState( nButtonFlags );
377 return eState;
380 void OfaMSFilterTabPage2::MSFltrSimpleTable::CheckEntryPos(sal_uLong nPos, sal_uInt16 nCol, sal_Bool bChecked)
382 if ( nPos < GetEntryCount() )
383 SetCheckButtonState(
384 GetEntry(nPos),
385 nCol,
386 bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
387 SvButtonState( SV_BUTTON_UNCHECKED ) );
390 void OfaMSFilterTabPage2::MSFltrSimpleTable::KeyInput( const KeyEvent& rKEvt )
392 if(!rKEvt.GetKeyCode().GetModifier() &&
393 KEY_SPACE == rKEvt.GetKeyCode().GetCode())
395 sal_uLong nSelPos = GetModel()->GetAbsPos(GetCurEntry());
396 sal_uInt16 nCol = GetCurrentTabPos() - 1;
397 if ( nCol < 2 )
399 SvTreeListEntry* pEntry = GetEntry( nSelPos );
400 sal_Bool bIsChecked = ( GetCheckButtonState( pEntry, nCol ) == SV_BUTTON_CHECKED );
401 CheckEntryPos( nSelPos, nCol, !bIsChecked );
402 CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE, (void*)pEntry );
404 else
406 sal_uInt16 nCheck = GetCheckButtonState( GetEntry(nSelPos), 1 ) == SV_BUTTON_CHECKED ? 1 : 0;
407 if(GetCheckButtonState( GetEntry(nSelPos), 0 ))
408 nCheck += 2;
409 nCheck--;
410 nCheck &= 3;
411 CheckEntryPos(nSelPos, 1, 0 != (nCheck & 1));
412 CheckEntryPos(nSelPos, 0, 0 != (nCheck & 2));
415 else
416 SvxSimpleTable::KeyInput(rKEvt);
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */