bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / options / optfltr.cxx
blobede4059fdbc3d4c1fbb471ababe5f56a1e2ce1eb
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 <cuires.hrc>
24 #include "helpid.hrc"
25 #include <dialmgr.hxx>
27 #include "svtools/svlbitm.hxx"
28 #include "svtools/treelistentry.hxx"
30 enum MSFltrPg2_CheckBoxEntries {
31 Math,
32 Writer,
33 Calc,
34 Impress,
35 SmartArt,
36 InvalidCBEntry
41 OfaMSFilterTabPage::OfaMSFilterTabPage(vcl::Window* pParent, const SfxItemSet& rSet)
42 : SfxTabPage( pParent, "OptFltrPage", "cui/ui/optfltrpage.ui", &rSet )
44 get( aWBasicCodeCB , "wo_basic" );
45 get( aWBasicWbctblCB , "wo_exec" );
46 get( aWBasicStgCB , "wo_saveorig" );
47 get( aEBasicCodeCB , "ex_basic" );
48 get( aEBasicExectblCB , "ex_exec" );
49 get( aEBasicStgCB , "ex_saveorig" );
50 get( aPBasicCodeCB , "pp_basic" );
51 get( aPBasicStgCB , "pp_saveorig" );
53 aWBasicCodeCB->SetClickHdl( LINK( this, OfaMSFilterTabPage, LoadWordBasicCheckHdl_Impl ) );
54 aEBasicCodeCB->SetClickHdl( LINK( this, OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl ) );
57 OfaMSFilterTabPage::~OfaMSFilterTabPage()
59 disposeOnce();
62 void OfaMSFilterTabPage::dispose()
64 aWBasicCodeCB.clear();
65 aWBasicWbctblCB.clear();
66 aWBasicStgCB.clear();
67 aEBasicCodeCB.clear();
68 aEBasicExectblCB.clear();
69 aEBasicStgCB.clear();
70 aPBasicCodeCB.clear();
71 aPBasicStgCB.clear();
72 SfxTabPage::dispose();
76 IMPL_LINK_NOARG(OfaMSFilterTabPage, LoadWordBasicCheckHdl_Impl)
78 aWBasicWbctblCB->Enable( aWBasicCodeCB->IsChecked() );
79 return 0;
82 IMPL_LINK_NOARG(OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl)
84 aEBasicExectblCB->Enable( aEBasicCodeCB->IsChecked() );
85 return 0;
88 VclPtr<SfxTabPage> OfaMSFilterTabPage::Create( vcl::Window* pParent,
89 const SfxItemSet* rAttrSet )
91 return VclPtr<OfaMSFilterTabPage>::Create( pParent, *rAttrSet );
94 bool OfaMSFilterTabPage::FillItemSet( SfxItemSet* )
96 SvtFilterOptions& rOpt = SvtFilterOptions::Get();
98 if( aWBasicCodeCB->IsValueChangedFromSaved() )
99 rOpt.SetLoadWordBasicCode( aWBasicCodeCB->IsChecked() );
100 if( aWBasicWbctblCB->IsValueChangedFromSaved() )
101 rOpt.SetLoadWordBasicExecutable( aWBasicWbctblCB->IsChecked() );
102 if( aWBasicStgCB->IsValueChangedFromSaved() )
103 rOpt.SetLoadWordBasicStorage( aWBasicStgCB->IsChecked() );
105 if( aEBasicCodeCB->IsValueChangedFromSaved())
106 rOpt.SetLoadExcelBasicCode( aEBasicCodeCB->IsChecked() );
107 if( aEBasicExectblCB->IsValueChangedFromSaved())
108 rOpt.SetLoadExcelBasicExecutable( aEBasicExectblCB->IsChecked() );
109 if( aEBasicStgCB->IsValueChangedFromSaved())
110 rOpt.SetLoadExcelBasicStorage( aEBasicStgCB->IsChecked() );
112 if( aPBasicCodeCB->IsValueChangedFromSaved())
113 rOpt.SetLoadPPointBasicCode( aPBasicCodeCB->IsChecked() );
114 if( aPBasicStgCB->IsValueChangedFromSaved())
115 rOpt.SetLoadPPointBasicStorage( aPBasicStgCB->IsChecked() );
117 return false;
120 void OfaMSFilterTabPage::Reset( const SfxItemSet* )
122 const SvtFilterOptions& rOpt = SvtFilterOptions::Get();
124 aWBasicCodeCB->Check( rOpt.IsLoadWordBasicCode() );
125 aWBasicCodeCB->SaveValue();
126 aWBasicWbctblCB->Check( rOpt.IsLoadWordBasicExecutable() );
127 aWBasicWbctblCB->SaveValue();
128 aWBasicStgCB->Check( rOpt.IsLoadWordBasicStorage() );
129 aWBasicStgCB->SaveValue();
130 LoadWordBasicCheckHdl_Impl( aWBasicCodeCB );
132 aEBasicCodeCB->Check( rOpt.IsLoadExcelBasicCode() );
133 aEBasicCodeCB->SaveValue();
134 aEBasicExectblCB->Check( rOpt.IsLoadExcelBasicExecutable() );
135 aEBasicExectblCB->SaveValue();
136 aEBasicStgCB->Check( rOpt.IsLoadExcelBasicStorage() );
137 aEBasicStgCB->SaveValue();
138 LoadExcelBasicCheckHdl_Impl( aEBasicCodeCB );
140 aPBasicCodeCB->Check( rOpt.IsLoadPPointBasicCode() );
141 aPBasicCodeCB->SaveValue();
142 aPBasicStgCB->Check( rOpt.IsLoadPPointBasicStorage() );
143 aPBasicStgCB->SaveValue();
146 OfaMSFilterTabPage2::OfaMSFilterTabPage2( vcl::Window* pParent, const SfxItemSet& rSet ) :
147 SfxTabPage( pParent, "OptFilterPage", "cui/ui/optfltrembedpage.ui", &rSet ),
148 sHeader1(CUI_RES(RID_SVXSTR_HEADER1)),
149 sHeader2(CUI_RES(RID_SVXSTR_HEADER2)),
150 sChgToFromMath(CUI_RES(RID_SVXSTR_CHG_MATH)),
151 sChgToFromWriter(CUI_RES(RID_SVXSTR_CHG_WRITER)),
152 sChgToFromCalc(CUI_RES(RID_SVXSTR_CHG_CALC)),
153 sChgToFromImpress(CUI_RES(RID_SVXSTR_CHG_IMPRESS)),
154 sChgToFromSmartArt(CUI_RES(RID_SVXSTR_CHG_SMARTART)),
155 pCheckButtonData(0)
157 get(m_pCheckLBContainer, "checklbcontainer");
159 get( aHighlightingRB, "highlighting");
160 get( aShadingRB, "shading" );
162 Size aControlSize(248, 55);
163 aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
164 m_pCheckLBContainer->set_width_request(aControlSize.Width());
165 m_pCheckLBContainer->set_height_request(aControlSize.Height());
167 m_pCheckLB = VclPtr<MSFltrSimpleTable>::Create(*m_pCheckLBContainer);
169 static long aStaticTabs[] = { 3, 0, 20, 40 };
170 m_pCheckLB->SvSimpleTable::SetTabs( aStaticTabs );
172 OUString sHeader = sHeader1 + "\t" + sHeader2 + "\t";
173 m_pCheckLB->InsertHeaderEntry( sHeader, HEADERBAR_APPEND,
174 HeaderBarItemBits::CENTER | HeaderBarItemBits::VCENTER | HeaderBarItemBits::FIXEDPOS | HeaderBarItemBits::FIXED );
176 m_pCheckLB->SetStyle( m_pCheckLB->GetStyle()|WB_HSCROLL| WB_VSCROLL );
179 OfaMSFilterTabPage2::~OfaMSFilterTabPage2()
181 disposeOnce();
184 void OfaMSFilterTabPage2::dispose()
186 delete pCheckButtonData;
187 pCheckButtonData = NULL;
188 m_pCheckLB.disposeAndClear();
189 m_pCheckLBContainer.clear();
190 aHighlightingRB.clear();
191 aShadingRB.clear();
193 SfxTabPage::dispose();
196 VclPtr<SfxTabPage> OfaMSFilterTabPage2::Create( vcl::Window* pParent,
197 const SfxItemSet* rAttrSet )
199 return VclPtr<OfaMSFilterTabPage2>::Create( pParent, *rAttrSet );
202 bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet* )
204 SvtFilterOptions& rOpt = SvtFilterOptions::Get();
206 static struct ChkCBoxEntries{
207 MSFltrPg2_CheckBoxEntries eType;
208 bool (SvtFilterOptions:: *FnIs)() const;
209 void (SvtFilterOptions:: *FnSet)( bool bFlag );
210 } aChkArr[] = {
211 { Math, &SvtFilterOptions::IsMathType2Math,
212 &SvtFilterOptions::SetMathType2Math },
213 { Math, &SvtFilterOptions::IsMath2MathType,
214 &SvtFilterOptions::SetMath2MathType },
215 { Writer, &SvtFilterOptions::IsWinWord2Writer,
216 &SvtFilterOptions::SetWinWord2Writer },
217 { Writer, &SvtFilterOptions::IsWriter2WinWord,
218 &SvtFilterOptions::SetWriter2WinWord },
219 { Calc, &SvtFilterOptions::IsExcel2Calc,
220 &SvtFilterOptions::SetExcel2Calc },
221 { Calc, &SvtFilterOptions::IsCalc2Excel,
222 &SvtFilterOptions::SetCalc2Excel },
223 { Impress, &SvtFilterOptions::IsPowerPoint2Impress,
224 &SvtFilterOptions::SetPowerPoint2Impress },
225 { Impress, &SvtFilterOptions::IsImpress2PowerPoint,
226 &SvtFilterOptions::SetImpress2PowerPoint },
227 { SmartArt, &SvtFilterOptions::IsSmartArt2Shape,
228 &SvtFilterOptions::SetSmartArt2Shape },
229 { InvalidCBEntry, 0, 0 }
232 bool bCheck, bFirst = true;
233 for( const ChkCBoxEntries* pArr = aChkArr;
234 InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
236 sal_uInt16 nCol = bFirst ? 1 : 2;
237 SvTreeListEntry* pEntry = GetEntry4Type( pArr->eType );
238 if( pEntry )
240 SvLBoxButton* pItem = static_cast<SvLBoxButton*>(pEntry->GetItem( nCol ));
241 if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
243 SvItemStateFlags nButtonFlags = pItem->GetButtonFlags();
244 bCheck = SV_BUTTON_CHECKED ==
245 SvLBoxButtonData::ConvertToButtonState( nButtonFlags );
247 if( bCheck != (rOpt.*pArr->FnIs)() )
248 (rOpt.*pArr->FnSet)( bCheck );
253 if( aHighlightingRB->IsValueChangedFromSaved() )
255 if( aHighlightingRB->IsChecked() )
256 rOpt.SetCharBackground2Highlighting();
257 else
258 rOpt.SetCharBackground2Shading();
261 return true;
264 void OfaMSFilterTabPage2::Reset( const SfxItemSet* )
266 SvtFilterOptions& rOpt = SvtFilterOptions::Get();
268 m_pCheckLB->SetUpdateMode(false);
269 m_pCheckLB->Clear();
271 SvtModuleOptions aModuleOpt;
273 // int the same sequence as the enums of MSFltrPg2_CheckBoxEntries
274 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::MATH ) )
275 InsertEntry( sChgToFromMath, static_cast< sal_IntPtr >( Math ) );
276 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::WRITER ) )
277 InsertEntry( sChgToFromWriter, static_cast< sal_IntPtr >( Writer ) );
278 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::CALC ) )
279 InsertEntry( sChgToFromCalc, static_cast< sal_IntPtr >( Calc ) );
280 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::IMPRESS ) )
281 InsertEntry( sChgToFromImpress, static_cast< sal_IntPtr >( Impress ) );
282 InsertEntry( sChgToFromSmartArt, static_cast< sal_IntPtr >( SmartArt ), true, false );
284 static struct ChkCBoxEntries{
285 MSFltrPg2_CheckBoxEntries eType;
286 bool (SvtFilterOptions:: *FnIs)() const;
287 } aChkArr[] = {
288 { Math, &SvtFilterOptions::IsMathType2Math },
289 { Math, &SvtFilterOptions::IsMath2MathType },
290 { Writer, &SvtFilterOptions::IsWinWord2Writer },
291 { Writer, &SvtFilterOptions::IsWriter2WinWord },
292 { Calc, &SvtFilterOptions::IsExcel2Calc },
293 { Calc, &SvtFilterOptions::IsCalc2Excel },
294 { Impress, &SvtFilterOptions::IsPowerPoint2Impress },
295 { Impress, &SvtFilterOptions::IsImpress2PowerPoint },
296 { SmartArt, &SvtFilterOptions::IsSmartArt2Shape },
297 { InvalidCBEntry, NULL }
300 bool bFirst = true;
301 for( const ChkCBoxEntries* pArr = aChkArr;
302 InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
304 sal_uInt16 nCol = bFirst ? 1 : 2;
305 SvTreeListEntry* pEntry = GetEntry4Type( static_cast< sal_IntPtr >( pArr->eType ) );
306 if( pEntry )
308 SvLBoxButton* pItem = static_cast<SvLBoxButton*>(pEntry->GetItem( nCol ));
309 if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
311 if( (rOpt.*pArr->FnIs)() )
312 pItem->SetStateChecked();
313 else
314 pItem->SetStateUnchecked();
315 m_pCheckLB->InvalidateEntry( pEntry );
319 m_pCheckLB->SetUpdateMode( true );
321 if (rOpt.IsCharBackground2Highlighting())
322 aHighlightingRB->Check(true);
323 else
324 aShadingRB->Check(true);
326 aHighlightingRB->SaveValue();
329 void OfaMSFilterTabPage2::InsertEntry( const OUString& _rTxt, sal_IntPtr _nType )
331 InsertEntry( _rTxt, _nType, true, true );
334 void OfaMSFilterTabPage2::InsertEntry( const OUString& _rTxt, sal_IntPtr _nType,
335 bool loadEnabled, bool saveEnabled )
337 SvTreeListEntry* pEntry = new SvTreeListEntry;
339 if( !pCheckButtonData )
340 pCheckButtonData = new SvLBoxButtonData( m_pCheckLB );
342 pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), false));
343 pEntry->AddItem( new SvLBoxButton( pEntry, loadEnabled? SvLBoxButtonKind_enabledCheckbox :
344 SvLBoxButtonKind_disabledCheckbox,
345 0, pCheckButtonData ) );
346 pEntry->AddItem( new SvLBoxButton( pEntry, saveEnabled? SvLBoxButtonKind_enabledCheckbox :
347 SvLBoxButtonKind_disabledCheckbox,
348 0, pCheckButtonData ) );
349 pEntry->AddItem( new SvLBoxString( pEntry, 0, _rTxt ) );
351 pEntry->SetUserData( reinterpret_cast<void*>(_nType) );
352 m_pCheckLB->Insert( pEntry );
355 SvTreeListEntry* OfaMSFilterTabPage2::GetEntry4Type( sal_IntPtr _nType ) const
357 SvTreeListEntry* pEntry = m_pCheckLB->First();
358 while ( pEntry )
360 if ( _nType == sal_IntPtr( pEntry->GetUserData() ) )
361 return pEntry;
362 pEntry = m_pCheckLB->Next( pEntry );
364 return NULL;
367 void OfaMSFilterTabPage2::MSFltrSimpleTable::SetTabs()
369 SvSimpleTable::SetTabs();
370 SvLBoxTabFlags nAdjust = SvLBoxTabFlags::ADJUST_RIGHT|SvLBoxTabFlags::ADJUST_LEFT|SvLBoxTabFlags::ADJUST_CENTER|SvLBoxTabFlags::ADJUST_NUMERIC|SvLBoxTabFlags::FORCE;
372 if( aTabs.size() > 1 )
374 SvLBoxTab* pTab = aTabs[1];
375 pTab->nFlags &= ~nAdjust;
376 pTab->nFlags |= SvLBoxTabFlags::PUSHABLE|SvLBoxTabFlags::ADJUST_CENTER|SvLBoxTabFlags::FORCE;
378 if( aTabs.size() > 2 )
380 SvLBoxTab* pTab = aTabs[2];
381 pTab->nFlags &= ~nAdjust;
382 pTab->nFlags |= SvLBoxTabFlags::PUSHABLE|SvLBoxTabFlags::ADJUST_CENTER|SvLBoxTabFlags::FORCE;
386 void OfaMSFilterTabPage2::MSFltrSimpleTable::HBarClick()
388 // sorting is stopped by this override
391 void OfaMSFilterTabPage2::MSFltrSimpleTable::SetCheckButtonState(
392 SvTreeListEntry* pEntry, sal_uInt16 nCol, SvButtonState eState)
394 SvLBoxButton* pItem = static_cast<SvLBoxButton*>(pEntry->GetItem(nCol + 1));
396 DBG_ASSERT(pItem,"SetCheckButton:Item not found");
397 if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
399 switch( eState )
401 case SV_BUTTON_CHECKED:
402 pItem->SetStateChecked();
403 break;
405 case SV_BUTTON_UNCHECKED:
406 pItem->SetStateUnchecked();
407 break;
409 case SV_BUTTON_TRISTATE:
410 pItem->SetStateTristate();
411 break;
413 InvalidateEntry( pEntry );
417 SvButtonState OfaMSFilterTabPage2::MSFltrSimpleTable::GetCheckButtonState(
418 SvTreeListEntry* pEntry, sal_uInt16 nCol )
420 SvButtonState eState = SV_BUTTON_UNCHECKED;
421 SvLBoxButton* pItem = static_cast<SvLBoxButton*>(pEntry->GetItem(nCol + 1));
422 DBG_ASSERT(pItem,"GetChButnState:Item not found");
424 if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
426 SvItemStateFlags nButtonFlags = pItem->GetButtonFlags();
427 eState = SvLBoxButtonData::ConvertToButtonState( nButtonFlags );
430 return eState;
433 void OfaMSFilterTabPage2::MSFltrSimpleTable::CheckEntryPos(sal_uLong nPos, sal_uInt16 nCol, bool bChecked)
435 if ( nPos < GetEntryCount() )
436 SetCheckButtonState(
437 GetEntry(nPos),
438 nCol,
439 bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
440 SvButtonState( SV_BUTTON_UNCHECKED ) );
443 void OfaMSFilterTabPage2::MSFltrSimpleTable::KeyInput( const KeyEvent& rKEvt )
445 if(!rKEvt.GetKeyCode().GetModifier() &&
446 KEY_SPACE == rKEvt.GetKeyCode().GetCode())
448 sal_uLong nSelPos = GetModel()->GetAbsPos(GetCurEntry());
449 sal_uInt16 nCol = GetCurrentTabPos() - 1;
450 if ( nCol < 2 )
452 SvTreeListEntry* pEntry = GetEntry( nSelPos );
453 bool bIsChecked = ( GetCheckButtonState( pEntry, nCol ) == SV_BUTTON_CHECKED );
454 CheckEntryPos( nSelPos, nCol, !bIsChecked );
455 CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE, (void*)pEntry );
457 else
459 sal_uInt16 nCheck = GetCheckButtonState( GetEntry(nSelPos), 1 ) == SV_BUTTON_CHECKED ? 1 : 0;
460 if(GetCheckButtonState( GetEntry(nSelPos), 0 ))
461 nCheck += 2;
462 nCheck--;
463 nCheck &= 3;
464 CheckEntryPos(nSelPos, 1, 0 != (nCheck & 1));
465 CheckEntryPos(nSelPos, 0, 0 != (nCheck & 2));
468 else
469 SvSimpleTable::KeyInput(rKEvt);
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */