Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
27 :
28 : #include "svtools/svlbitm.hxx"
29 : #include "svtools/treelistentry.hxx"
30 :
31 : enum MSFltrPg2_CheckBoxEntries {
32 : Math,
33 : Writer,
34 : Calc,
35 : Impress,
36 : InvalidCBEntry
37 : };
38 :
39 : // -----------------------------------------------------------------------
40 :
41 0 : OfaMSFilterTabPage::OfaMSFilterTabPage(Window* pParent, const SfxItemSet& rSet)
42 0 : : SfxTabPage( pParent, CUI_RES( RID_OFAPAGE_MSFILTEROPT ), rSet ),
43 0 : aMSWordGB ( this, CUI_RES( GB_WORD ) ),
44 0 : aWBasicCodeCB ( this, CUI_RES( CB_WBAS_CODE ) ),
45 0 : aWBasicWbctblCB ( this, CUI_RES( CB_WBAS_WBCTBL ) ),
46 0 : aWBasicStgCB ( this, CUI_RES( CB_WBAS_STG ) ),
47 0 : aMSExcelGB ( this, CUI_RES( GB_EXCEL ) ),
48 0 : aEBasicCodeCB ( this, CUI_RES( CB_EBAS_CODE ) ),
49 0 : aEBasicExectblCB( this, CUI_RES( CB_EBAS_EXECTBL ) ),
50 0 : aEBasicStgCB ( this, CUI_RES( CB_EBAS_STG ) ),
51 0 : aMSPPointGB ( this, CUI_RES( GB_PPOINT ) ),
52 0 : aPBasicCodeCB ( this, CUI_RES( CB_PBAS_CODE ) ),
53 0 : aPBasicStgCB ( this, CUI_RES( CB_PBAS_STG ) )
54 : {
55 0 : FreeResource();
56 :
57 0 : aWBasicCodeCB.SetClickHdl( LINK( this, OfaMSFilterTabPage, LoadWordBasicCheckHdl_Impl ) );
58 0 : aEBasicCodeCB.SetClickHdl( LINK( this, OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl ) );
59 0 : }
60 :
61 0 : OfaMSFilterTabPage::~OfaMSFilterTabPage()
62 : {
63 0 : }
64 :
65 0 : IMPL_LINK_NOARG(OfaMSFilterTabPage, LoadWordBasicCheckHdl_Impl)
66 : {
67 0 : aWBasicWbctblCB.Enable( aWBasicCodeCB.IsChecked() );
68 0 : return 0;
69 : }
70 :
71 0 : IMPL_LINK_NOARG(OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl)
72 : {
73 0 : aEBasicExectblCB.Enable( aEBasicCodeCB.IsChecked() );
74 0 : return 0;
75 : }
76 :
77 0 : SfxTabPage* OfaMSFilterTabPage::Create( Window* pParent,
78 : const SfxItemSet& rAttrSet )
79 : {
80 0 : return new OfaMSFilterTabPage( pParent, rAttrSet );
81 : }
82 :
83 0 : sal_Bool OfaMSFilterTabPage::FillItemSet( SfxItemSet& )
84 : {
85 0 : SvtFilterOptions& rOpt = SvtFilterOptions::Get();
86 :
87 : sal_Bool bFlag;
88 0 : if( aWBasicCodeCB.GetSavedValue() != (bFlag = aWBasicCodeCB.IsChecked()))
89 0 : rOpt.SetLoadWordBasicCode( bFlag );
90 0 : if( aWBasicWbctblCB.GetSavedValue() != (bFlag = aWBasicWbctblCB.IsChecked()))
91 0 : rOpt.SetLoadWordBasicExecutable( bFlag );
92 0 : if( aWBasicStgCB.GetSavedValue() != (bFlag = aWBasicStgCB.IsChecked()))
93 0 : rOpt.SetLoadWordBasicStorage( bFlag );
94 :
95 0 : if( aEBasicCodeCB.GetSavedValue() != (bFlag = aEBasicCodeCB.IsChecked()))
96 0 : rOpt.SetLoadExcelBasicCode( bFlag );
97 0 : if( aEBasicExectblCB.GetSavedValue() != (bFlag = aEBasicExectblCB.IsChecked()))
98 0 : rOpt.SetLoadExcelBasicExecutable( bFlag );
99 0 : if( aEBasicStgCB.GetSavedValue() != (bFlag = aEBasicStgCB.IsChecked()))
100 0 : rOpt.SetLoadExcelBasicStorage( bFlag );
101 :
102 0 : if( aPBasicCodeCB.GetSavedValue() != (bFlag = aPBasicCodeCB.IsChecked()))
103 0 : rOpt.SetLoadPPointBasicCode( bFlag );
104 0 : if( aPBasicStgCB.GetSavedValue() != (bFlag = aPBasicStgCB.IsChecked()))
105 0 : rOpt.SetLoadPPointBasicStorage( bFlag );
106 :
107 0 : return sal_False;
108 : }
109 :
110 0 : void OfaMSFilterTabPage::Reset( const SfxItemSet& )
111 : {
112 0 : const SvtFilterOptions& rOpt = SvtFilterOptions::Get();
113 :
114 0 : aWBasicCodeCB.Check( rOpt.IsLoadWordBasicCode() );
115 0 : aWBasicCodeCB.SaveValue();
116 0 : aWBasicWbctblCB.Check( rOpt.IsLoadWordBasicExecutable() );
117 0 : aWBasicWbctblCB.SaveValue();
118 0 : aWBasicStgCB.Check( rOpt.IsLoadWordBasicStorage() );
119 0 : aWBasicStgCB.SaveValue();
120 0 : LoadWordBasicCheckHdl_Impl( &aWBasicCodeCB );
121 :
122 0 : aEBasicCodeCB.Check( rOpt.IsLoadExcelBasicCode() );
123 0 : aEBasicCodeCB.SaveValue();
124 0 : aEBasicExectblCB.Check( rOpt.IsLoadExcelBasicExecutable() );
125 0 : aEBasicExectblCB.SaveValue();
126 0 : aEBasicStgCB.Check( rOpt.IsLoadExcelBasicStorage() );
127 0 : aEBasicStgCB.SaveValue();
128 0 : LoadExcelBasicCheckHdl_Impl( &aEBasicCodeCB );
129 :
130 0 : aPBasicCodeCB.Check( rOpt.IsLoadPPointBasicCode() );
131 0 : aPBasicCodeCB.SaveValue();
132 0 : aPBasicStgCB.Check( rOpt.IsLoadPPointBasicStorage() );
133 0 : aPBasicStgCB.SaveValue();
134 0 : }
135 :
136 0 : OfaMSFilterTabPage2::OfaMSFilterTabPage2( Window* pParent,
137 : const SfxItemSet& rSet )
138 0 : : SfxTabPage( pParent, CUI_RES( RID_OFAPAGE_MSFILTEROPT2 ), rSet ),
139 0 : m_aCheckLBContainer(this, CUI_RES( CLB_SETTINGS)),
140 : aCheckLB(m_aCheckLBContainer),
141 0 : aHeader1FT ( this, CUI_RES( FT_HEADER1_EXPLANATION )),
142 0 : aHeader2FT ( this, CUI_RES( FT_HEADER2_EXPLANATION )),
143 0 : sHeader1 ( CUI_RES( ST_HEADER1 )),
144 0 : sHeader2 ( CUI_RES( ST_HEADER2 )),
145 0 : sChgToFromMath ( CUI_RES( ST_CHG_MATH )),
146 0 : sChgToFromWriter ( CUI_RES( ST_CHG_WRITER )),
147 0 : sChgToFromCalc ( CUI_RES( ST_CHG_CALC )),
148 0 : sChgToFromImpress ( CUI_RES( ST_CHG_IMPRESS )),
149 0 : pCheckButtonData(0)
150 : {
151 0 : FreeResource();
152 :
153 : static long aStaticTabs[] = { 3, 0, 20, 40 };
154 0 : aCheckLB.SvxSimpleTable::SetTabs( aStaticTabs );
155 :
156 0 : String sHeader( sHeader1 );
157 0 : (( sHeader += '\t' ) += sHeader2 ) += '\t';
158 : aCheckLB.InsertHeaderEntry( sHeader, HEADERBAR_APPEND,
159 0 : HIB_CENTER | HIB_VCENTER | HIB_FIXEDPOS | HIB_FIXED );
160 :
161 0 : aCheckLB.SetHelpId( HID_OFAPAGE_MSFLTR2_CLB );
162 0 : aCheckLB.SetStyle( aCheckLB.GetStyle()|WB_HSCROLL| WB_VSCROLL );
163 0 : }
164 :
165 0 : OfaMSFilterTabPage2::~OfaMSFilterTabPage2()
166 : {
167 0 : delete pCheckButtonData;
168 0 : }
169 :
170 0 : SfxTabPage* OfaMSFilterTabPage2::Create( Window* pParent,
171 : const SfxItemSet& rAttrSet )
172 : {
173 0 : return new OfaMSFilterTabPage2( pParent, rAttrSet );
174 : }
175 :
176 0 : sal_Bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet& )
177 : {
178 0 : SvtFilterOptions& rOpt = SvtFilterOptions::Get();
179 :
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 }
202 : };
203 :
204 0 : sal_Bool bCheck, bFirst = sal_True;
205 0 : for( const ChkCBoxEntries* pArr = aChkArr;
206 0 : InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
207 : {
208 0 : sal_uInt16 nCol = bFirst ? 1 : 2;
209 0 : SvTreeListEntry* pEntry = GetEntry4Type( pArr->eType );
210 0 : if( pEntry )
211 : {
212 0 : SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem( nCol ));
213 0 : if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
214 : {
215 0 : sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
216 : bCheck = SV_BUTTON_CHECKED ==
217 0 : pCheckButtonData->ConvertToButtonState( nButtonFlags );
218 :
219 0 : if( bCheck != (rOpt.*pArr->FnIs)() )
220 0 : (rOpt.*pArr->FnSet)( bCheck );
221 : }
222 : }
223 : }
224 :
225 0 : return sal_True;
226 : }
227 :
228 0 : void OfaMSFilterTabPage2::Reset( const SfxItemSet& )
229 : {
230 0 : SvtFilterOptions& rOpt = SvtFilterOptions::Get();
231 :
232 0 : aCheckLB.SetUpdateMode(sal_False);
233 0 : aCheckLB.Clear();
234 :
235 0 : SvtModuleOptions aModuleOpt;
236 :
237 : // int the same sequence as the enums of MSFltrPg2_CheckBoxEntries
238 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
239 0 : InsertEntry( sChgToFromMath, static_cast< sal_IntPtr >( Math ) );
240 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
241 0 : InsertEntry( sChgToFromWriter, static_cast< sal_IntPtr >( Writer ) );
242 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
243 0 : InsertEntry( sChgToFromCalc, static_cast< sal_IntPtr >( Calc ) );
244 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
245 0 : InsertEntry( sChgToFromImpress, static_cast< sal_IntPtr >( Impress ) );
246 :
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 }
260 : };
261 :
262 0 : sal_Bool bFirst = sal_True;
263 0 : for( const ChkCBoxEntries* pArr = aChkArr;
264 0 : InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
265 : {
266 0 : sal_uInt16 nCol = bFirst ? 1 : 2;
267 0 : SvTreeListEntry* pEntry = GetEntry4Type( static_cast< sal_IntPtr >( pArr->eType ) );
268 0 : if( pEntry )
269 : {
270 0 : SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem( nCol ));
271 0 : if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
272 : {
273 0 : if( (rOpt.*pArr->FnIs)() )
274 0 : pItem->SetStateChecked();
275 : else
276 0 : pItem->SetStateUnchecked();
277 0 : aCheckLB.InvalidateEntry( pEntry );
278 : }
279 : }
280 : }
281 0 : aCheckLB.SetUpdateMode( sal_True );
282 0 : }
283 :
284 0 : void OfaMSFilterTabPage2::InsertEntry( const String& _rTxt, sal_IntPtr _nType )
285 : {
286 0 : SvTreeListEntry* pEntry = new SvTreeListEntry;
287 :
288 0 : if( !pCheckButtonData )
289 0 : pCheckButtonData = new SvLBoxButtonData( &aCheckLB );
290 :
291 0 : pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));
292 : pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
293 0 : 0, pCheckButtonData ) );
294 : pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
295 0 : 0, pCheckButtonData ) );
296 0 : pEntry->AddItem( new SvLBoxString( pEntry, 0, _rTxt ) );
297 :
298 0 : pEntry->SetUserData( (void*)_nType );
299 0 : aCheckLB.Insert( pEntry );
300 0 : }
301 :
302 0 : SvTreeListEntry* OfaMSFilterTabPage2::GetEntry4Type( sal_IntPtr _nType ) const
303 : {
304 0 : SvTreeListEntry* pEntry = aCheckLB.First();
305 0 : while ( pEntry )
306 : {
307 0 : if ( _nType == sal_IntPtr( pEntry->GetUserData() ) )
308 0 : return pEntry;
309 0 : pEntry = aCheckLB.Next( pEntry );
310 : }
311 0 : return NULL;
312 : }
313 :
314 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::SetTabs()
315 : {
316 0 : SvxSimpleTable::SetTabs();
317 0 : sal_uInt16 nAdjust = SV_LBOXTAB_ADJUST_RIGHT|SV_LBOXTAB_ADJUST_LEFT|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_ADJUST_NUMERIC|SV_LBOXTAB_FORCE;
318 :
319 0 : if( aTabs.size() > 1 )
320 : {
321 0 : SvLBoxTab* pTab = aTabs[1];
322 0 : pTab->nFlags &= ~nAdjust;
323 0 : pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
324 : }
325 0 : if( aTabs.size() > 2 )
326 : {
327 0 : SvLBoxTab* pTab = aTabs[2];
328 0 : pTab->nFlags &= ~nAdjust;
329 0 : pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
330 : }
331 0 : }
332 :
333 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::HBarClick()
334 : {
335 : // sorting is stopped by this overloading
336 0 : }
337 :
338 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::SetCheckButtonState(
339 : SvTreeListEntry* pEntry, sal_uInt16 nCol, SvButtonState eState)
340 : {
341 0 : SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
342 :
343 : DBG_ASSERT(pItem,"SetCheckButton:Item not found");
344 0 : if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
345 : {
346 0 : switch( eState )
347 : {
348 : case SV_BUTTON_CHECKED:
349 0 : pItem->SetStateChecked();
350 0 : break;
351 :
352 : case SV_BUTTON_UNCHECKED:
353 0 : pItem->SetStateUnchecked();
354 0 : break;
355 :
356 : case SV_BUTTON_TRISTATE:
357 0 : pItem->SetStateTristate();
358 0 : break;
359 : }
360 0 : InvalidateEntry( pEntry );
361 : }
362 0 : }
363 :
364 0 : SvButtonState OfaMSFilterTabPage2::MSFltrSimpleTable::GetCheckButtonState(
365 : SvTreeListEntry* pEntry, sal_uInt16 nCol ) const
366 : {
367 0 : SvButtonState eState = SV_BUTTON_UNCHECKED;
368 0 : SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
369 : DBG_ASSERT(pItem,"GetChButnState:Item not found");
370 :
371 0 : if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
372 : {
373 0 : sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
374 0 : eState = pCheckButtonData->ConvertToButtonState( nButtonFlags );
375 : }
376 :
377 0 : return eState;
378 : }
379 :
380 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::CheckEntryPos(sal_uLong nPos, sal_uInt16 nCol, sal_Bool bChecked)
381 : {
382 0 : if ( nPos < GetEntryCount() )
383 : SetCheckButtonState(
384 : GetEntry(nPos),
385 : nCol,
386 : bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
387 0 : SvButtonState( SV_BUTTON_UNCHECKED ) );
388 0 : }
389 :
390 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::KeyInput( const KeyEvent& rKEvt )
391 : {
392 0 : if(!rKEvt.GetKeyCode().GetModifier() &&
393 0 : KEY_SPACE == rKEvt.GetKeyCode().GetCode())
394 : {
395 0 : sal_uLong nSelPos = GetModel()->GetAbsPos(GetCurEntry());
396 0 : sal_uInt16 nCol = GetCurrentTabPos() - 1;
397 0 : if ( nCol < 2 )
398 : {
399 0 : SvTreeListEntry* pEntry = GetEntry( nSelPos );
400 0 : sal_Bool bIsChecked = ( GetCheckButtonState( pEntry, nCol ) == SV_BUTTON_CHECKED );
401 0 : CheckEntryPos( nSelPos, nCol, !bIsChecked );
402 0 : CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE, (void*)pEntry );
403 : }
404 : else
405 : {
406 0 : sal_uInt16 nCheck = GetCheckButtonState( GetEntry(nSelPos), 1 ) == SV_BUTTON_CHECKED ? 1 : 0;
407 0 : if(GetCheckButtonState( GetEntry(nSelPos), 0 ))
408 0 : nCheck += 2;
409 0 : nCheck--;
410 0 : nCheck &= 3;
411 0 : CheckEntryPos(nSelPos, 1, 0 != (nCheck & 1));
412 0 : CheckEntryPos(nSelPos, 0, 0 != (nCheck & 2));
413 : }
414 : }
415 : else
416 0 : SvxSimpleTable::KeyInput(rKEvt);
417 3 : }
418 :
419 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|