update dev300-m58
[ooovba.git] / svx / source / cui / optfltr.cxx
blobf8d185f1078741f7e64286c7844ff0416ac1464c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optfltr.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
39 #include <svtools/moduleoptions.hxx>
41 #include <svtools/fltrcfg.hxx>
42 #include "optfltr.hxx"
43 #include "optfltr.hrc"
44 #include <svx/dialogs.hrc>
45 #include "helpid.hrc"
46 #include <svx/dialmgr.hxx>
48 enum MSFltrPg2_CheckBoxEntries {
49 Math,
50 Writer,
51 Calc,
52 Impress,
53 InvalidCBEntry
56 #define CBCOL_FIRST 0
57 #define CBCOL_SECOND 1
59 // -----------------------------------------------------------------------
61 OfaMSFilterTabPage::OfaMSFilterTabPage(Window* pParent, const SfxItemSet& rSet)
62 : SfxTabPage( pParent, SVX_RES( RID_OFAPAGE_MSFILTEROPT ), rSet ),
63 aMSWordGB ( this, SVX_RES( GB_WORD ) ),
64 aWBasicCodeCB ( this, SVX_RES( CB_WBAS_CODE ) ),
65 aWBasicStgCB ( this, SVX_RES( CB_WBAS_STG ) ),
66 aMSExcelGB ( this, SVX_RES( GB_EXCEL ) ),
67 aEBasicCodeCB ( this, SVX_RES( CB_EBAS_CODE ) ),
68 aEBasicExectblCB( this, SVX_RES( CB_EBAS_EXECTBL ) ),
69 aEBasicStgCB ( this, SVX_RES( CB_EBAS_STG ) ),
70 aMSPPointGB ( this, SVX_RES( GB_PPOINT ) ),
71 aPBasicCodeCB ( this, SVX_RES( CB_PBAS_CODE ) ),
72 aPBasicStgCB ( this, SVX_RES( CB_PBAS_STG ) )
74 FreeResource();
76 aEBasicCodeCB.SetClickHdl( LINK( this, OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl ) );
79 OfaMSFilterTabPage::~OfaMSFilterTabPage()
83 IMPL_LINK( OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl, CheckBox*, EMPTYARG )
85 aEBasicExectblCB.Enable( aEBasicCodeCB.IsChecked() );
86 return 0;
89 SfxTabPage* OfaMSFilterTabPage::Create( Window* pParent,
90 const SfxItemSet& rAttrSet )
92 return new OfaMSFilterTabPage( pParent, rAttrSet );
95 BOOL OfaMSFilterTabPage::FillItemSet( SfxItemSet& )
97 SvtFilterOptions* pOpt = SvtFilterOptions::Get();
99 BOOL bFlag;
100 if( aWBasicCodeCB.GetSavedValue() != (bFlag = aWBasicCodeCB.IsChecked()))
101 pOpt->SetLoadWordBasicCode( bFlag );
102 if( aWBasicStgCB.GetSavedValue() != (bFlag = aWBasicStgCB.IsChecked()))
103 pOpt->SetLoadWordBasicStorage( bFlag );
105 if( aEBasicCodeCB.GetSavedValue() != (bFlag = aEBasicCodeCB.IsChecked()))
106 pOpt->SetLoadExcelBasicCode( bFlag );
107 if( aEBasicExectblCB.GetSavedValue() != (bFlag = aEBasicExectblCB.IsChecked()))
108 pOpt->SetLoadExcelBasicExecutable( bFlag );
109 if( aEBasicStgCB.GetSavedValue() != (bFlag = aEBasicStgCB.IsChecked()))
110 pOpt->SetLoadExcelBasicStorage( bFlag );
112 if( aPBasicCodeCB.GetSavedValue() != (bFlag = aPBasicCodeCB.IsChecked()))
113 pOpt->SetLoadPPointBasicCode( bFlag );
114 if( aPBasicStgCB.GetSavedValue() != (bFlag = aPBasicStgCB.IsChecked()))
115 pOpt->SetLoadPPointBasicStorage( bFlag );
117 return FALSE;
120 /*-----------------02.09.96 13.47-------------------
122 --------------------------------------------------*/
124 void OfaMSFilterTabPage::Reset( const SfxItemSet& )
126 SvtFilterOptions* pOpt = SvtFilterOptions::Get();
128 aWBasicCodeCB.Check( pOpt->IsLoadWordBasicCode() );
129 aWBasicCodeCB.SaveValue();
130 aWBasicStgCB.Check( pOpt->IsLoadWordBasicStorage() );
131 aWBasicStgCB.SaveValue();
133 aEBasicCodeCB.Check( pOpt->IsLoadExcelBasicCode() );
134 aEBasicCodeCB.SaveValue();
135 aEBasicExectblCB.Check( pOpt->IsLoadExcelBasicExecutable() );
136 aEBasicExectblCB.SaveValue();
137 aEBasicStgCB.Check( pOpt->IsLoadExcelBasicStorage() );
138 aEBasicStgCB.SaveValue();
139 LoadExcelBasicCheckHdl_Impl( &aEBasicCodeCB );
141 aPBasicCodeCB.Check( pOpt->IsLoadPPointBasicCode() );
142 aPBasicCodeCB.SaveValue();
143 aPBasicStgCB.Check( pOpt->IsLoadPPointBasicStorage() );
144 aPBasicStgCB.SaveValue();
148 /*-----------------29.06.00 13:22-------------------
150 * --------------------------------------------------*/
151 OfaMSFilterTabPage2::OfaMSFilterTabPage2( Window* pParent,
152 const SfxItemSet& rSet )
153 : SfxTabPage( pParent, SVX_RES( RID_OFAPAGE_MSFILTEROPT2 ), rSet ),
154 aCheckLB ( this, SVX_RES( CLB_SETTINGS )),
155 aHeader1FT ( this, SVX_RES( FT_HEADER1_EXPLANATION )),
156 aHeader2FT ( this, SVX_RES( FT_HEADER2_EXPLANATION )),
157 sHeader1 ( SVX_RES( ST_HEADER1 )),
158 sHeader2 ( SVX_RES( ST_HEADER2 )),
159 sChgToFromMath ( SVX_RES( ST_CHG_MATH )),
160 sChgToFromWriter ( SVX_RES( ST_CHG_WRITER )),
161 sChgToFromCalc ( SVX_RES( ST_CHG_CALC )),
162 sChgToFromImpress ( SVX_RES( ST_CHG_IMPRESS )),
163 pCheckButtonData(0)
165 FreeResource();
167 static long aStaticTabs[] = { 3, 0, 20, 40 };
168 aCheckLB.SvxSimpleTable::SetTabs( aStaticTabs );
170 String sHeader( sHeader1 );
171 (( sHeader += '\t' ) += sHeader2 ) += '\t';
172 aCheckLB.InsertHeaderEntry( sHeader, HEADERBAR_APPEND,
173 HIB_CENTER | HIB_VCENTER | HIB_FIXEDPOS | HIB_FIXED );
175 aCheckLB.SetHelpId( HID_OFAPAGE_MSFLTR2_CLB );
176 aCheckLB.SetWindowBits( WB_HSCROLL| WB_VSCROLL );
179 OfaMSFilterTabPage2::~OfaMSFilterTabPage2()
181 delete pCheckButtonData;
184 SfxTabPage* OfaMSFilterTabPage2::Create( Window* pParent,
185 const SfxItemSet& rAttrSet )
187 return new OfaMSFilterTabPage2( pParent, rAttrSet );
190 BOOL OfaMSFilterTabPage2::FillItemSet( SfxItemSet& )
192 BOOL bModified = FALSE;
193 SvtFilterOptions* pOpt = SvtFilterOptions::Get();
195 static struct ChkCBoxEntries{
196 MSFltrPg2_CheckBoxEntries eType;
197 BOOL (SvtFilterOptions:: *FnIs)() const;
198 void (SvtFilterOptions:: *FnSet)( BOOL bFlag );
199 } aChkArr[] = {
200 { Math, &SvtFilterOptions::IsMathType2Math,
201 &SvtFilterOptions::SetMathType2Math },
202 { Math, &SvtFilterOptions::IsMath2MathType,
203 &SvtFilterOptions::SetMath2MathType },
204 { Writer, &SvtFilterOptions::IsWinWord2Writer,
205 &SvtFilterOptions::SetWinWord2Writer },
206 { Writer, &SvtFilterOptions::IsWriter2WinWord,
207 &SvtFilterOptions::SetWriter2WinWord },
208 { Calc, &SvtFilterOptions::IsExcel2Calc,
209 &SvtFilterOptions::SetExcel2Calc },
210 { Calc, &SvtFilterOptions::IsCalc2Excel,
211 &SvtFilterOptions::SetCalc2Excel },
212 { Impress, &SvtFilterOptions::IsPowerPoint2Impress,
213 &SvtFilterOptions::SetPowerPoint2Impress },
214 { Impress, &SvtFilterOptions::IsImpress2PowerPoint,
215 &SvtFilterOptions::SetImpress2PowerPoint },
216 { InvalidCBEntry, 0, 0 }
219 BOOL bCheck, bFirst = TRUE;
220 for( const ChkCBoxEntries* pArr = aChkArr;
221 InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
223 USHORT nCol = bFirst ? 1 : 2;
224 SvLBoxEntry* pEntry = GetEntry4Type( pArr->eType );
225 if( pEntry )
227 SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem( nCol ));
228 if( pItem && ((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON )
230 USHORT nButtonFlags = pItem->GetButtonFlags();
231 bCheck = SV_BUTTON_CHECKED ==
232 pCheckButtonData->ConvertToButtonState( nButtonFlags );
234 if( bCheck != (pOpt->*pArr->FnIs)() )
236 bModified = TRUE;
237 (pOpt->*pArr->FnSet)( bCheck );
243 return TRUE;
246 void OfaMSFilterTabPage2::Reset( const SfxItemSet& )
248 SvtFilterOptions* pOpt = SvtFilterOptions::Get();
250 aCheckLB.SetUpdateMode(FALSE);
251 aCheckLB.Clear();
253 SvtModuleOptions aModuleOpt;
255 // int the same sequence as the enums of MSFltrPg2_CheckBoxEntries
256 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
257 InsertEntry( sChgToFromMath, static_cast< sal_IntPtr >( Math ) );
258 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
259 InsertEntry( sChgToFromWriter, static_cast< sal_IntPtr >( Writer ) );
260 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
261 InsertEntry( sChgToFromCalc, static_cast< sal_IntPtr >( Calc ) );
262 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
263 InsertEntry( sChgToFromImpress, static_cast< sal_IntPtr >( Impress ) );
265 static struct ChkCBoxEntries{
266 MSFltrPg2_CheckBoxEntries eType;
267 BOOL (SvtFilterOptions:: *FnIs)() const;
268 } aChkArr[] = {
269 { Math, &SvtFilterOptions::IsMathType2Math },
270 { Math, &SvtFilterOptions::IsMath2MathType },
271 { Writer, &SvtFilterOptions::IsWinWord2Writer },
272 { Writer, &SvtFilterOptions::IsWriter2WinWord },
273 { Calc, &SvtFilterOptions::IsExcel2Calc },
274 { Calc, &SvtFilterOptions::IsCalc2Excel },
275 { Impress, &SvtFilterOptions::IsPowerPoint2Impress },
276 { Impress, &SvtFilterOptions::IsImpress2PowerPoint },
277 { InvalidCBEntry, NULL }
280 BOOL bFirst = TRUE;
281 for( const ChkCBoxEntries* pArr = aChkArr;
282 InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
284 USHORT nCol = bFirst ? 1 : 2;
285 SvLBoxEntry* pEntry = GetEntry4Type( static_cast< sal_IntPtr >( pArr->eType ) );
286 if( pEntry )
288 SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem( nCol ));
289 if( pItem && ((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON )
291 if( (pOpt->*pArr->FnIs)() )
292 pItem->SetStateChecked();
293 else
294 pItem->SetStateUnchecked();
295 aCheckLB.InvalidateEntry( pEntry );
299 aCheckLB.SetUpdateMode( TRUE );
302 void OfaMSFilterTabPage2::InsertEntry( const String& _rTxt, sal_IntPtr _nType )
304 SvLBoxEntry* pEntry = new SvLBoxEntry;
306 if( !pCheckButtonData )
307 pCheckButtonData = new SvLBoxButtonData( &aCheckLB );
309 pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));
310 pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
311 0, pCheckButtonData ) );
312 pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
313 0, pCheckButtonData ) );
314 pEntry->AddItem( new SvLBoxString( pEntry, 0, _rTxt ) );
316 pEntry->SetUserData( (void*)_nType );
317 aCheckLB.Insert( pEntry );
320 SvLBoxEntry* OfaMSFilterTabPage2::GetEntry4Type( sal_IntPtr _nType ) const
322 SvLBoxEntry* pEntry = aCheckLB.First();
323 while ( pEntry )
325 if ( _nType == sal_IntPtr( pEntry->GetUserData() ) )
326 return pEntry;
327 pEntry = aCheckLB.Next( pEntry );
329 return NULL;
332 void OfaMSFilterTabPage2::MSFltrSimpleTable::SetTabs()
334 SvxSimpleTable::SetTabs();
335 USHORT nAdjust = SV_LBOXTAB_ADJUST_RIGHT|SV_LBOXTAB_ADJUST_LEFT|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_ADJUST_NUMERIC|SV_LBOXTAB_FORCE;
337 if( aTabs.Count() > 1 )
339 SvLBoxTab* pTab = (SvLBoxTab*)aTabs.GetObject(1);
340 pTab->nFlags &= ~nAdjust;
341 pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
343 if( aTabs.Count() > 2 )
345 SvLBoxTab* pTab = (SvLBoxTab*)aTabs.GetObject(2);
346 pTab->nFlags &= ~nAdjust;
347 pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
351 void OfaMSFilterTabPage2::MSFltrSimpleTable::HBarClick()
353 // Sortierung durch diese Ueberladung abgeklemmt
355 /* -----------------------------2002/06/20 11:51------------------------------
357 ---------------------------------------------------------------------------*/
358 void OfaMSFilterTabPage2::MSFltrSimpleTable::SetCheckButtonState(
359 SvLBoxEntry* pEntry, USHORT nCol, SvButtonState eState)
361 SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
363 DBG_ASSERT(pItem,"SetCheckButton:Item not found");
364 if (((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON)
366 switch( eState )
368 case SV_BUTTON_CHECKED:
369 pItem->SetStateChecked();
370 break;
372 case SV_BUTTON_UNCHECKED:
373 pItem->SetStateUnchecked();
374 break;
376 case SV_BUTTON_TRISTATE:
377 pItem->SetStateTristate();
378 break;
380 InvalidateEntry( pEntry );
383 /* -----------------------------2002/06/20 11:56------------------------------
385 ---------------------------------------------------------------------------*/
386 SvButtonState OfaMSFilterTabPage2::MSFltrSimpleTable::GetCheckButtonState(
387 SvLBoxEntry* pEntry, USHORT nCol ) const
389 SvButtonState eState = SV_BUTTON_UNCHECKED;
390 SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
391 DBG_ASSERT(pItem,"GetChButnState:Item not found");
393 if (((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON)
395 USHORT nButtonFlags = pItem->GetButtonFlags();
396 eState = pCheckButtonData->ConvertToButtonState( nButtonFlags );
399 return eState;
401 /* -----------------------------2002/06/20 11:57------------------------------
403 ---------------------------------------------------------------------------*/
404 void OfaMSFilterTabPage2::MSFltrSimpleTable::CheckEntryPos(ULONG nPos, USHORT nCol, BOOL bChecked)
406 if ( nPos < GetEntryCount() )
407 SetCheckButtonState(
408 GetEntry(nPos),
409 nCol,
410 bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
411 SvButtonState( SV_BUTTON_UNCHECKED ) );
413 /* -----------------------------2002/06/20 11:51------------------------------
415 ---------------------------------------------------------------------------*/
416 void OfaMSFilterTabPage2::MSFltrSimpleTable::KeyInput( const KeyEvent& rKEvt )
418 if(!rKEvt.GetKeyCode().GetModifier() &&
419 KEY_SPACE == rKEvt.GetKeyCode().GetCode())
421 ULONG nSelPos = GetModel()->GetAbsPos(GetCurEntry());
422 USHORT nCol = GetCurrentTabPos() - 1;
423 if ( nCol < 2 )
425 SvLBoxEntry* pEntry = GetEntry( nSelPos );
426 sal_Bool bIsChecked = ( GetCheckButtonState( pEntry, nCol ) == SV_BUTTON_CHECKED );
427 CheckEntryPos( nSelPos, nCol, !bIsChecked );
428 CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE, (void*)pEntry );
430 else
432 USHORT nCheck = GetCheckButtonState( GetEntry(nSelPos), 1 ) == SV_BUTTON_CHECKED ? 1 : 0;
433 if(GetCheckButtonState( GetEntry(nSelPos), 0 ))
434 nCheck += 2;
435 nCheck--;
436 nCheck &= 3;
437 CheckEntryPos(nSelPos, 1, 0 != (nCheck & 1));
438 CheckEntryPos(nSelPos, 0, 0 != (nCheck & 2));
441 else
442 SvxSimpleTable::KeyInput(rKEvt);