xref: /trunk/main/cui/source/options/optfltr.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
31 // include ---------------------------------------------------------------
32 #include <unotools/moduleoptions.hxx>
33 #include <unotools/fltrcfg.hxx>
34 #include "optfltr.hxx"
35 #include "optfltr.hrc"
36 #include <cuires.hrc>
37 #include "helpid.hrc"
38 #include <dialmgr.hxx>
39 
40 enum MSFltrPg2_CheckBoxEntries {
41     Math,
42     Writer,
43     Calc,
44     Impress,
45     InvalidCBEntry
46 };
47 
48 #define CBCOL_FIRST     0
49 #define CBCOL_SECOND    1
50 
51 // -----------------------------------------------------------------------
52 
53 OfaMSFilterTabPage::OfaMSFilterTabPage(Window* pParent, const SfxItemSet& rSet)
54     : SfxTabPage( pParent, CUI_RES( RID_OFAPAGE_MSFILTEROPT ), rSet ),
55     aMSWordGB       ( this, CUI_RES( GB_WORD        ) ),
56     aWBasicCodeCB   ( this, CUI_RES( CB_WBAS_CODE ) ),
57     aWBasicStgCB    ( this, CUI_RES( CB_WBAS_STG  ) ),
58     aMSExcelGB      ( this, CUI_RES( GB_EXCEL     ) ),
59     aEBasicCodeCB   ( this, CUI_RES( CB_EBAS_CODE ) ),
60     aEBasicExectblCB( this, CUI_RES( CB_EBAS_EXECTBL ) ),
61     aEBasicStgCB    ( this, CUI_RES( CB_EBAS_STG  ) ),
62     aMSPPointGB     ( this, CUI_RES( GB_PPOINT    ) ),
63     aPBasicCodeCB   ( this, CUI_RES( CB_PBAS_CODE ) ),
64     aPBasicStgCB    ( this, CUI_RES( CB_PBAS_STG  ) )
65 {
66     FreeResource();
67 
68     aEBasicCodeCB.SetClickHdl( LINK( this, OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl ) );
69 }
70 
71 OfaMSFilterTabPage::~OfaMSFilterTabPage()
72 {
73 }
74 
75 IMPL_LINK( OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl, CheckBox*, EMPTYARG )
76 {
77     aEBasicExectblCB.Enable( aEBasicCodeCB.IsChecked() );
78     return 0;
79 }
80 
81 SfxTabPage* OfaMSFilterTabPage::Create( Window* pParent,
82                                         const SfxItemSet& rAttrSet )
83 {
84     return new OfaMSFilterTabPage( pParent, rAttrSet );
85 }
86 
87 sal_Bool OfaMSFilterTabPage::FillItemSet( SfxItemSet& )
88 {
89     SvtFilterOptions* pOpt = SvtFilterOptions::Get();
90 
91     sal_Bool bFlag;
92     if( aWBasicCodeCB.GetSavedValue() != (bFlag = aWBasicCodeCB.IsChecked()))
93         pOpt->SetLoadWordBasicCode( bFlag );
94     if( aWBasicStgCB.GetSavedValue() != (bFlag = aWBasicStgCB.IsChecked()))
95         pOpt->SetLoadWordBasicStorage( bFlag );
96 
97     if( aEBasicCodeCB.GetSavedValue() != (bFlag = aEBasicCodeCB.IsChecked()))
98         pOpt->SetLoadExcelBasicCode( bFlag );
99     if( aEBasicExectblCB.GetSavedValue() != (bFlag = aEBasicExectblCB.IsChecked()))
100         pOpt->SetLoadExcelBasicExecutable( bFlag );
101     if( aEBasicStgCB.GetSavedValue() != (bFlag = aEBasicStgCB.IsChecked()))
102         pOpt->SetLoadExcelBasicStorage( bFlag );
103 
104     if( aPBasicCodeCB.GetSavedValue() != (bFlag = aPBasicCodeCB.IsChecked()))
105         pOpt->SetLoadPPointBasicCode( bFlag );
106     if( aPBasicStgCB.GetSavedValue() != (bFlag = aPBasicStgCB.IsChecked()))
107         pOpt->SetLoadPPointBasicStorage( bFlag );
108 
109     return sal_False;
110 }
111 
112 /*-----------------02.09.96 13.47-------------------
113 
114 --------------------------------------------------*/
115 
116 void OfaMSFilterTabPage::Reset( const SfxItemSet& )
117 {
118     SvtFilterOptions* pOpt = SvtFilterOptions::Get();
119 
120     aWBasicCodeCB.Check( pOpt->IsLoadWordBasicCode() );
121     aWBasicCodeCB.SaveValue();
122     aWBasicStgCB.Check( pOpt->IsLoadWordBasicStorage() );
123     aWBasicStgCB.SaveValue();
124 
125     aEBasicCodeCB.Check( pOpt->IsLoadExcelBasicCode() );
126     aEBasicCodeCB.SaveValue();
127     aEBasicExectblCB.Check( pOpt->IsLoadExcelBasicExecutable() );
128     aEBasicExectblCB.SaveValue();
129     aEBasicStgCB.Check( pOpt->IsLoadExcelBasicStorage() );
130     aEBasicStgCB.SaveValue();
131     LoadExcelBasicCheckHdl_Impl( &aEBasicCodeCB );
132 
133     aPBasicCodeCB.Check( pOpt->IsLoadPPointBasicCode() );
134     aPBasicCodeCB.SaveValue();
135     aPBasicStgCB.Check( pOpt->IsLoadPPointBasicStorage() );
136     aPBasicStgCB.SaveValue();
137 
138 }
139 
140 /*-----------------29.06.00 13:22-------------------
141  *
142  * --------------------------------------------------*/
143 OfaMSFilterTabPage2::OfaMSFilterTabPage2( Window* pParent,
144                                         const SfxItemSet& rSet )
145     : SfxTabPage( pParent, CUI_RES( RID_OFAPAGE_MSFILTEROPT2 ), rSet ),
146     aCheckLB            ( this, CUI_RES( CLB_SETTINGS   )),
147     aHeader1FT          ( this, CUI_RES( FT_HEADER1_EXPLANATION )),
148     aHeader2FT          ( this, CUI_RES( FT_HEADER2_EXPLANATION )),
149     sHeader1            ( CUI_RES( ST_HEADER1 )),
150     sHeader2            ( CUI_RES( ST_HEADER2 )),
151     sChgToFromMath      ( CUI_RES( ST_CHG_MATH  )),
152     sChgToFromWriter    ( CUI_RES( ST_CHG_WRITER )),
153     sChgToFromCalc      ( CUI_RES( ST_CHG_CALC )),
154     sChgToFromImpress   ( CUI_RES( ST_CHG_IMPRESS )),
155     pCheckButtonData(0)
156 {
157     FreeResource();
158 
159     static long aStaticTabs[] = { 3, 0, 20, 40 };
160     aCheckLB.SvxSimpleTable::SetTabs( aStaticTabs );
161 
162     String sHeader( sHeader1 );
163     (( sHeader += '\t' ) += sHeader2 ) += '\t';
164     aCheckLB.InsertHeaderEntry( sHeader, HEADERBAR_APPEND,
165                     HIB_CENTER | HIB_VCENTER | HIB_FIXEDPOS | HIB_FIXED );
166 
167     aCheckLB.SetHelpId( HID_OFAPAGE_MSFLTR2_CLB );
168     aCheckLB.SetStyle( aCheckLB.GetStyle()|WB_HSCROLL| WB_VSCROLL );
169 }
170 
171 OfaMSFilterTabPage2::~OfaMSFilterTabPage2()
172 {
173     delete pCheckButtonData;
174 }
175 
176 SfxTabPage* OfaMSFilterTabPage2::Create( Window* pParent,
177                                 const SfxItemSet& rAttrSet )
178 {
179     return new OfaMSFilterTabPage2( pParent, rAttrSet );
180 }
181 
182 sal_Bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet& )
183 {
184     sal_Bool bModified = sal_False;
185     SvtFilterOptions* pOpt = SvtFilterOptions::Get();
186 
187     static struct ChkCBoxEntries{
188         MSFltrPg2_CheckBoxEntries eType;
189         sal_Bool (SvtFilterOptions:: *FnIs)() const;
190         void (SvtFilterOptions:: *FnSet)( sal_Bool bFlag );
191     } aChkArr[] = {
192         { Math,     &SvtFilterOptions::IsMathType2Math,
193                         &SvtFilterOptions::SetMathType2Math },
194         { Math,     &SvtFilterOptions::IsMath2MathType,
195                         &SvtFilterOptions::SetMath2MathType },
196         { Writer,   &SvtFilterOptions::IsWinWord2Writer,
197                         &SvtFilterOptions::SetWinWord2Writer },
198         { Writer,   &SvtFilterOptions::IsWriter2WinWord,
199                         &SvtFilterOptions::SetWriter2WinWord },
200         { Calc,     &SvtFilterOptions::IsExcel2Calc,
201                         &SvtFilterOptions::SetExcel2Calc },
202         { Calc,     &SvtFilterOptions::IsCalc2Excel,
203                         &SvtFilterOptions::SetCalc2Excel },
204         { Impress,  &SvtFilterOptions::IsPowerPoint2Impress,
205                         &SvtFilterOptions::SetPowerPoint2Impress },
206         { Impress,  &SvtFilterOptions::IsImpress2PowerPoint,
207                         &SvtFilterOptions::SetImpress2PowerPoint },
208         { InvalidCBEntry, 0, 0 }
209     };
210 
211     sal_Bool bCheck, bFirst = sal_True;
212     for( const ChkCBoxEntries* pArr = aChkArr;
213             InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
214     {
215         sal_uInt16 nCol = bFirst ? 1 : 2;
216         SvLBoxEntry* pEntry = GetEntry4Type( pArr->eType );
217         if( pEntry )
218         {
219             SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem( nCol ));
220             if( pItem && ((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON )
221             {
222                 sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
223                 bCheck = SV_BUTTON_CHECKED ==
224                         pCheckButtonData->ConvertToButtonState( nButtonFlags );
225 
226                 if( bCheck != (pOpt->*pArr->FnIs)() )
227                 {
228                     bModified = sal_True;
229                     (pOpt->*pArr->FnSet)( bCheck );
230                 }
231             }
232         }
233     }
234 
235     return sal_True;
236 }
237 
238 void OfaMSFilterTabPage2::Reset( const SfxItemSet& )
239 {
240     SvtFilterOptions* pOpt = SvtFilterOptions::Get();
241 
242     aCheckLB.SetUpdateMode(sal_False);
243     aCheckLB.Clear();
244 
245     SvtModuleOptions aModuleOpt;
246 
247     // int the same sequence as the enums of MSFltrPg2_CheckBoxEntries
248     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
249         InsertEntry( sChgToFromMath, static_cast< sal_IntPtr >( Math ) );
250     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
251         InsertEntry( sChgToFromWriter, static_cast< sal_IntPtr >( Writer ) );
252     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
253         InsertEntry( sChgToFromCalc, static_cast< sal_IntPtr >( Calc ) );
254     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
255         InsertEntry( sChgToFromImpress, static_cast< sal_IntPtr >( Impress ) );
256 
257     static struct ChkCBoxEntries{
258         MSFltrPg2_CheckBoxEntries eType;
259         sal_Bool (SvtFilterOptions:: *FnIs)() const;
260     } aChkArr[] = {
261         { Math,     &SvtFilterOptions::IsMathType2Math },
262         { Math,     &SvtFilterOptions::IsMath2MathType },
263         { Writer,   &SvtFilterOptions::IsWinWord2Writer },
264         { Writer,   &SvtFilterOptions::IsWriter2WinWord },
265         { Calc,     &SvtFilterOptions::IsExcel2Calc },
266         { Calc,     &SvtFilterOptions::IsCalc2Excel },
267         { Impress,  &SvtFilterOptions::IsPowerPoint2Impress },
268         { Impress,  &SvtFilterOptions::IsImpress2PowerPoint },
269         { InvalidCBEntry, NULL }
270     };
271 
272     sal_Bool bFirst = sal_True;
273     for( const ChkCBoxEntries* pArr = aChkArr;
274             InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
275     {
276         sal_uInt16 nCol = bFirst ? 1 : 2;
277         SvLBoxEntry* pEntry = GetEntry4Type( static_cast< sal_IntPtr >( pArr->eType ) );
278         if( pEntry )
279         {
280             SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem( nCol ));
281             if( pItem && ((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON )
282             {
283                 if( (pOpt->*pArr->FnIs)() )
284                     pItem->SetStateChecked();
285                 else
286                     pItem->SetStateUnchecked();
287                 aCheckLB.InvalidateEntry( pEntry );
288             }
289         }
290     }
291     aCheckLB.SetUpdateMode( sal_True );
292 }
293 
294 void OfaMSFilterTabPage2::InsertEntry( const String& _rTxt, sal_IntPtr _nType )
295 {
296     SvLBoxEntry* pEntry = new SvLBoxEntry;
297 
298     if( !pCheckButtonData )
299         pCheckButtonData = new SvLBoxButtonData( &aCheckLB );
300 
301     pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));
302     pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
303                                        0, pCheckButtonData ) );
304     pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
305                                        0, pCheckButtonData ) );
306     pEntry->AddItem( new SvLBoxString( pEntry, 0, _rTxt ) );
307 
308     pEntry->SetUserData( (void*)_nType );
309     aCheckLB.Insert( pEntry );
310 }
311 
312 SvLBoxEntry* OfaMSFilterTabPage2::GetEntry4Type( sal_IntPtr _nType ) const
313 {
314     SvLBoxEntry* pEntry = aCheckLB.First();
315     while ( pEntry )
316     {
317         if ( _nType == sal_IntPtr( pEntry->GetUserData() ) )
318             return pEntry;
319         pEntry = aCheckLB.Next( pEntry );
320     }
321     return NULL;
322 }
323 
324 void OfaMSFilterTabPage2::MSFltrSimpleTable::SetTabs()
325 {
326     SvxSimpleTable::SetTabs();
327     sal_uInt16 nAdjust = SV_LBOXTAB_ADJUST_RIGHT|SV_LBOXTAB_ADJUST_LEFT|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_ADJUST_NUMERIC|SV_LBOXTAB_FORCE;
328 
329     if( aTabs.Count() > 1 )
330     {
331         SvLBoxTab* pTab = (SvLBoxTab*)aTabs.GetObject(1);
332         pTab->nFlags &= ~nAdjust;
333         pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
334     }
335     if( aTabs.Count() > 2 )
336     {
337         SvLBoxTab* pTab = (SvLBoxTab*)aTabs.GetObject(2);
338         pTab->nFlags &= ~nAdjust;
339         pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
340     }
341 }
342 
343 void OfaMSFilterTabPage2::MSFltrSimpleTable::HBarClick()
344 {
345     // Sortierung durch diese Ueberladung abgeklemmt
346 }
347 /* -----------------------------2002/06/20 11:51------------------------------
348 
349  ---------------------------------------------------------------------------*/
350 void OfaMSFilterTabPage2::MSFltrSimpleTable::SetCheckButtonState(
351                             SvLBoxEntry* pEntry, sal_uInt16 nCol, SvButtonState eState)
352 {
353     SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
354 
355     DBG_ASSERT(pItem,"SetCheckButton:Item not found");
356     if (((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON)
357     {
358         switch( eState )
359         {
360             case SV_BUTTON_CHECKED:
361                 pItem->SetStateChecked();
362                 break;
363 
364             case SV_BUTTON_UNCHECKED:
365                 pItem->SetStateUnchecked();
366                 break;
367 
368             case SV_BUTTON_TRISTATE:
369                 pItem->SetStateTristate();
370                 break;
371         }
372         InvalidateEntry( pEntry );
373     }
374 }
375 /* -----------------------------2002/06/20 11:56------------------------------
376 
377  ---------------------------------------------------------------------------*/
378 SvButtonState OfaMSFilterTabPage2::MSFltrSimpleTable::GetCheckButtonState(
379                                     SvLBoxEntry* pEntry, sal_uInt16 nCol ) const
380 {
381     SvButtonState eState = SV_BUTTON_UNCHECKED;
382     SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
383     DBG_ASSERT(pItem,"GetChButnState:Item not found");
384 
385     if (((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON)
386     {
387         sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
388         eState = pCheckButtonData->ConvertToButtonState( nButtonFlags );
389     }
390 
391     return eState;
392 }
393 /* -----------------------------2002/06/20 11:57------------------------------
394 
395  ---------------------------------------------------------------------------*/
396 void OfaMSFilterTabPage2::MSFltrSimpleTable::CheckEntryPos(sal_uLong nPos, sal_uInt16 nCol, sal_Bool bChecked)
397 {
398     if ( nPos < GetEntryCount() )
399         SetCheckButtonState(
400             GetEntry(nPos),
401             nCol,
402             bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
403                                        SvButtonState( SV_BUTTON_UNCHECKED ) );
404 }
405 /* -----------------------------2002/06/20 11:51------------------------------
406 
407  ---------------------------------------------------------------------------*/
408 void OfaMSFilterTabPage2::MSFltrSimpleTable::KeyInput( const KeyEvent& rKEvt )
409 {
410     if(!rKEvt.GetKeyCode().GetModifier() &&
411         KEY_SPACE == rKEvt.GetKeyCode().GetCode())
412     {
413         sal_uLong nSelPos = GetModel()->GetAbsPos(GetCurEntry());
414         sal_uInt16 nCol = GetCurrentTabPos() - 1;
415         if ( nCol < 2 )
416         {
417             SvLBoxEntry* pEntry = GetEntry( nSelPos );
418             sal_Bool bIsChecked = ( GetCheckButtonState( pEntry, nCol ) == SV_BUTTON_CHECKED );
419             CheckEntryPos( nSelPos, nCol, !bIsChecked );
420             CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE, (void*)pEntry );
421         }
422         else
423         {
424             sal_uInt16 nCheck = GetCheckButtonState( GetEntry(nSelPos), 1 ) == SV_BUTTON_CHECKED ? 1 : 0;
425             if(GetCheckButtonState( GetEntry(nSelPos), 0 ))
426                 nCheck += 2;
427             nCheck--;
428             nCheck &= 3;
429             CheckEntryPos(nSelPos, 1, 0 != (nCheck & 1));
430             CheckEntryPos(nSelPos, 0, 0 != (nCheck & 2));
431         }
432     }
433     else
434         SvxSimpleTable::KeyInput(rKEvt);
435 }
436 
437