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