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