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 <cuires.hrc>
24 : #include "helpid.hrc"
25 : #include <dialmgr.hxx>
26 :
27 : #include "svtools/svlbitm.hxx"
28 : #include "svtools/treelistentry.hxx"
29 :
30 : enum MSFltrPg2_CheckBoxEntries {
31 : Math,
32 : Writer,
33 : Calc,
34 : Impress,
35 : SmartArt,
36 : InvalidCBEntry
37 : };
38 :
39 :
40 :
41 0 : OfaMSFilterTabPage::OfaMSFilterTabPage(vcl::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( vcl::Window* pParent,
74 : const SfxItemSet* rAttrSet )
75 : {
76 0 : return new OfaMSFilterTabPage( pParent, *rAttrSet );
77 : }
78 :
79 0 : bool OfaMSFilterTabPage::FillItemSet( SfxItemSet* )
80 : {
81 0 : SvtFilterOptions& rOpt = SvtFilterOptions::Get();
82 :
83 0 : if( aWBasicCodeCB->IsValueChangedFromSaved() )
84 0 : rOpt.SetLoadWordBasicCode( aWBasicCodeCB->IsChecked() );
85 0 : if( aWBasicWbctblCB->IsValueChangedFromSaved() )
86 0 : rOpt.SetLoadWordBasicExecutable( aWBasicWbctblCB->IsChecked() );
87 0 : if( aWBasicStgCB->IsValueChangedFromSaved() )
88 0 : rOpt.SetLoadWordBasicStorage( aWBasicStgCB->IsChecked() );
89 :
90 0 : if( aEBasicCodeCB->IsValueChangedFromSaved())
91 0 : rOpt.SetLoadExcelBasicCode( aEBasicCodeCB->IsChecked() );
92 0 : if( aEBasicExectblCB->IsValueChangedFromSaved())
93 0 : rOpt.SetLoadExcelBasicExecutable( aEBasicExectblCB->IsChecked() );
94 0 : if( aEBasicStgCB->IsValueChangedFromSaved())
95 0 : rOpt.SetLoadExcelBasicStorage( aEBasicStgCB->IsChecked() );
96 :
97 0 : if( aPBasicCodeCB->IsValueChangedFromSaved())
98 0 : rOpt.SetLoadPPointBasicCode( aPBasicCodeCB->IsChecked() );
99 0 : if( aPBasicStgCB->IsValueChangedFromSaved())
100 0 : rOpt.SetLoadPPointBasicStorage( aPBasicStgCB->IsChecked() );
101 :
102 0 : return false;
103 : }
104 :
105 0 : void OfaMSFilterTabPage::Reset( const SfxItemSet* )
106 : {
107 0 : const SvtFilterOptions& rOpt = SvtFilterOptions::Get();
108 :
109 0 : aWBasicCodeCB->Check( rOpt.IsLoadWordBasicCode() );
110 0 : aWBasicCodeCB->SaveValue();
111 0 : aWBasicWbctblCB->Check( rOpt.IsLoadWordBasicExecutable() );
112 0 : aWBasicWbctblCB->SaveValue();
113 0 : aWBasicStgCB->Check( rOpt.IsLoadWordBasicStorage() );
114 0 : aWBasicStgCB->SaveValue();
115 0 : LoadWordBasicCheckHdl_Impl( aWBasicCodeCB );
116 :
117 0 : aEBasicCodeCB->Check( rOpt.IsLoadExcelBasicCode() );
118 0 : aEBasicCodeCB->SaveValue();
119 0 : aEBasicExectblCB->Check( rOpt.IsLoadExcelBasicExecutable() );
120 0 : aEBasicExectblCB->SaveValue();
121 0 : aEBasicStgCB->Check( rOpt.IsLoadExcelBasicStorage() );
122 0 : aEBasicStgCB->SaveValue();
123 0 : LoadExcelBasicCheckHdl_Impl( aEBasicCodeCB );
124 :
125 0 : aPBasicCodeCB->Check( rOpt.IsLoadPPointBasicCode() );
126 0 : aPBasicCodeCB->SaveValue();
127 0 : aPBasicStgCB->Check( rOpt.IsLoadPPointBasicStorage() );
128 0 : aPBasicStgCB->SaveValue();
129 0 : }
130 :
131 0 : OfaMSFilterTabPage2::OfaMSFilterTabPage2( vcl::Window* pParent, const SfxItemSet& rSet ) :
132 : SfxTabPage( pParent, "OptFilterPage", "cui/ui/optfltrembedpage.ui", &rSet ),
133 0 : sHeader1(CUI_RES(RID_SVXSTR_HEADER1)),
134 0 : sHeader2(CUI_RES(RID_SVXSTR_HEADER2)),
135 0 : sChgToFromMath(CUI_RES(RID_SVXSTR_CHG_MATH)),
136 0 : sChgToFromWriter(CUI_RES(RID_SVXSTR_CHG_WRITER)),
137 0 : sChgToFromCalc(CUI_RES(RID_SVXSTR_CHG_CALC)),
138 0 : sChgToFromImpress(CUI_RES(RID_SVXSTR_CHG_IMPRESS)),
139 0 : sChgToFromSmartArt(CUI_RES(RID_SVXSTR_CHG_SMARTART)),
140 0 : pCheckButtonData(0)
141 : {
142 0 : get(m_pCheckLBContainer, "checklbcontainer");
143 0 : Size aControlSize(248, 55);
144 0 : aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
145 0 : m_pCheckLBContainer->set_width_request(aControlSize.Width());
146 0 : m_pCheckLBContainer->set_height_request(aControlSize.Height());
147 :
148 0 : m_pCheckLB = new MSFltrSimpleTable(*m_pCheckLBContainer);
149 :
150 : static long aStaticTabs[] = { 3, 0, 20, 40 };
151 0 : m_pCheckLB->SvSimpleTable::SetTabs( aStaticTabs );
152 :
153 0 : OUString sHeader = sHeader1 + "\t" + sHeader2 + "\t";
154 : m_pCheckLB->InsertHeaderEntry( sHeader, HEADERBAR_APPEND,
155 0 : HIB_CENTER | HIB_VCENTER | HIB_FIXEDPOS | HIB_FIXED );
156 :
157 0 : m_pCheckLB->SetStyle( m_pCheckLB->GetStyle()|WB_HSCROLL| WB_VSCROLL );
158 0 : }
159 :
160 0 : OfaMSFilterTabPage2::~OfaMSFilterTabPage2()
161 : {
162 0 : delete pCheckButtonData;
163 0 : delete m_pCheckLB;
164 0 : }
165 :
166 0 : SfxTabPage* OfaMSFilterTabPage2::Create( vcl::Window* pParent,
167 : const SfxItemSet* rAttrSet )
168 : {
169 0 : return new OfaMSFilterTabPage2( pParent, *rAttrSet );
170 : }
171 :
172 0 : bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet* )
173 : {
174 0 : SvtFilterOptions& rOpt = SvtFilterOptions::Get();
175 :
176 : static struct ChkCBoxEntries{
177 : MSFltrPg2_CheckBoxEntries eType;
178 : bool (SvtFilterOptions:: *FnIs)() const;
179 : void (SvtFilterOptions:: *FnSet)( 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 : { SmartArt, &SvtFilterOptions::IsSmartArt2Shape,
198 : &SvtFilterOptions::SetSmartArt2Shape },
199 : { InvalidCBEntry, 0, 0 }
200 : };
201 :
202 0 : bool bCheck, bFirst = true;
203 0 : for( const ChkCBoxEntries* pArr = aChkArr;
204 0 : InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
205 : {
206 0 : sal_uInt16 nCol = bFirst ? 1 : 2;
207 0 : SvTreeListEntry* pEntry = GetEntry4Type( pArr->eType );
208 0 : if( pEntry )
209 : {
210 0 : SvLBoxButton* pItem = static_cast<SvLBoxButton*>(pEntry->GetItem( nCol ));
211 0 : if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
212 : {
213 0 : sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
214 : bCheck = SV_BUTTON_CHECKED ==
215 0 : pCheckButtonData->ConvertToButtonState( nButtonFlags );
216 :
217 0 : if( bCheck != (rOpt.*pArr->FnIs)() )
218 0 : (rOpt.*pArr->FnSet)( bCheck );
219 : }
220 : }
221 : }
222 :
223 0 : return true;
224 : }
225 :
226 0 : void OfaMSFilterTabPage2::Reset( const SfxItemSet* )
227 : {
228 0 : SvtFilterOptions& rOpt = SvtFilterOptions::Get();
229 :
230 0 : m_pCheckLB->SetUpdateMode(false);
231 0 : m_pCheckLB->Clear();
232 :
233 0 : SvtModuleOptions aModuleOpt;
234 :
235 : // int the same sequence as the enums of MSFltrPg2_CheckBoxEntries
236 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
237 0 : InsertEntry( sChgToFromMath, static_cast< sal_IntPtr >( Math ) );
238 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
239 0 : InsertEntry( sChgToFromWriter, static_cast< sal_IntPtr >( Writer ) );
240 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
241 0 : InsertEntry( sChgToFromCalc, static_cast< sal_IntPtr >( Calc ) );
242 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
243 0 : InsertEntry( sChgToFromImpress, static_cast< sal_IntPtr >( Impress ) );
244 0 : InsertEntry( sChgToFromSmartArt, static_cast< sal_IntPtr >( SmartArt ), true, false );
245 :
246 : static struct ChkCBoxEntries{
247 : MSFltrPg2_CheckBoxEntries eType;
248 : bool (SvtFilterOptions:: *FnIs)() const;
249 : } aChkArr[] = {
250 : { Math, &SvtFilterOptions::IsMathType2Math },
251 : { Math, &SvtFilterOptions::IsMath2MathType },
252 : { Writer, &SvtFilterOptions::IsWinWord2Writer },
253 : { Writer, &SvtFilterOptions::IsWriter2WinWord },
254 : { Calc, &SvtFilterOptions::IsExcel2Calc },
255 : { Calc, &SvtFilterOptions::IsCalc2Excel },
256 : { Impress, &SvtFilterOptions::IsPowerPoint2Impress },
257 : { Impress, &SvtFilterOptions::IsImpress2PowerPoint },
258 : { SmartArt, &SvtFilterOptions::IsSmartArt2Shape },
259 : { InvalidCBEntry, NULL }
260 : };
261 :
262 0 : bool bFirst = 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 = static_cast<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 : m_pCheckLB->InvalidateEntry( pEntry );
278 : }
279 : }
280 : }
281 0 : m_pCheckLB->SetUpdateMode( true );
282 0 : }
283 :
284 0 : void OfaMSFilterTabPage2::InsertEntry( const OUString& _rTxt, sal_IntPtr _nType )
285 : {
286 0 : InsertEntry( _rTxt, _nType, true, true );
287 0 : }
288 :
289 0 : void OfaMSFilterTabPage2::InsertEntry( const OUString& _rTxt, sal_IntPtr _nType,
290 : bool loadEnabled, bool saveEnabled )
291 : {
292 0 : SvTreeListEntry* pEntry = new SvTreeListEntry;
293 :
294 0 : if( !pCheckButtonData )
295 0 : pCheckButtonData = new SvLBoxButtonData( m_pCheckLB );
296 :
297 0 : pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), false));
298 : pEntry->AddItem( new SvLBoxButton( pEntry, loadEnabled? SvLBoxButtonKind_enabledCheckbox :
299 : SvLBoxButtonKind_disabledCheckbox,
300 0 : 0, pCheckButtonData ) );
301 : pEntry->AddItem( new SvLBoxButton( pEntry, saveEnabled? SvLBoxButtonKind_enabledCheckbox :
302 : SvLBoxButtonKind_disabledCheckbox,
303 0 : 0, pCheckButtonData ) );
304 0 : pEntry->AddItem( new SvLBoxString( pEntry, 0, _rTxt ) );
305 :
306 0 : pEntry->SetUserData( reinterpret_cast<void*>(_nType) );
307 0 : m_pCheckLB->Insert( pEntry );
308 0 : }
309 :
310 0 : SvTreeListEntry* OfaMSFilterTabPage2::GetEntry4Type( sal_IntPtr _nType ) const
311 : {
312 0 : SvTreeListEntry* pEntry = m_pCheckLB->First();
313 0 : while ( pEntry )
314 : {
315 0 : if ( _nType == sal_IntPtr( pEntry->GetUserData() ) )
316 0 : return pEntry;
317 0 : pEntry = m_pCheckLB->Next( pEntry );
318 : }
319 0 : return NULL;
320 : }
321 :
322 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::SetTabs()
323 : {
324 0 : SvSimpleTable::SetTabs();
325 0 : sal_uInt16 nAdjust = SV_LBOXTAB_ADJUST_RIGHT|SV_LBOXTAB_ADJUST_LEFT|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_ADJUST_NUMERIC|SV_LBOXTAB_FORCE;
326 :
327 0 : if( aTabs.size() > 1 )
328 : {
329 0 : SvLBoxTab* pTab = aTabs[1];
330 0 : pTab->nFlags &= ~nAdjust;
331 0 : pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
332 : }
333 0 : if( aTabs.size() > 2 )
334 : {
335 0 : SvLBoxTab* pTab = aTabs[2];
336 0 : pTab->nFlags &= ~nAdjust;
337 0 : pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
338 : }
339 0 : }
340 :
341 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::HBarClick()
342 : {
343 : // sorting is stopped by this overloading
344 0 : }
345 :
346 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::SetCheckButtonState(
347 : SvTreeListEntry* pEntry, sal_uInt16 nCol, SvButtonState eState)
348 : {
349 0 : SvLBoxButton* pItem = static_cast<SvLBoxButton*>(pEntry->GetItem(nCol + 1));
350 :
351 : DBG_ASSERT(pItem,"SetCheckButton:Item not found");
352 0 : if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
353 : {
354 0 : switch( eState )
355 : {
356 : case SV_BUTTON_CHECKED:
357 0 : pItem->SetStateChecked();
358 0 : break;
359 :
360 : case SV_BUTTON_UNCHECKED:
361 0 : pItem->SetStateUnchecked();
362 0 : break;
363 :
364 : case SV_BUTTON_TRISTATE:
365 0 : pItem->SetStateTristate();
366 0 : break;
367 : }
368 0 : InvalidateEntry( pEntry );
369 : }
370 0 : }
371 :
372 0 : SvButtonState OfaMSFilterTabPage2::MSFltrSimpleTable::GetCheckButtonState(
373 : SvTreeListEntry* pEntry, sal_uInt16 nCol ) const
374 : {
375 0 : SvButtonState eState = SV_BUTTON_UNCHECKED;
376 0 : SvLBoxButton* pItem = static_cast<SvLBoxButton*>(pEntry->GetItem(nCol + 1));
377 : DBG_ASSERT(pItem,"GetChButnState:Item not found");
378 :
379 0 : if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
380 : {
381 0 : sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
382 0 : eState = pCheckButtonData->ConvertToButtonState( nButtonFlags );
383 : }
384 :
385 0 : return eState;
386 : }
387 :
388 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::CheckEntryPos(sal_uLong nPos, sal_uInt16 nCol, bool bChecked)
389 : {
390 0 : if ( nPos < GetEntryCount() )
391 : SetCheckButtonState(
392 : GetEntry(nPos),
393 : nCol,
394 : bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
395 0 : SvButtonState( SV_BUTTON_UNCHECKED ) );
396 0 : }
397 :
398 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::KeyInput( const KeyEvent& rKEvt )
399 : {
400 0 : if(!rKEvt.GetKeyCode().GetModifier() &&
401 0 : KEY_SPACE == rKEvt.GetKeyCode().GetCode())
402 : {
403 0 : sal_uLong nSelPos = GetModel()->GetAbsPos(GetCurEntry());
404 0 : sal_uInt16 nCol = GetCurrentTabPos() - 1;
405 0 : if ( nCol < 2 )
406 : {
407 0 : SvTreeListEntry* pEntry = GetEntry( nSelPos );
408 0 : bool bIsChecked = ( GetCheckButtonState( pEntry, nCol ) == SV_BUTTON_CHECKED );
409 0 : CheckEntryPos( nSelPos, nCol, !bIsChecked );
410 0 : CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE, (void*)pEntry );
411 : }
412 : else
413 : {
414 0 : sal_uInt16 nCheck = GetCheckButtonState( GetEntry(nSelPos), 1 ) == SV_BUTTON_CHECKED ? 1 : 0;
415 0 : if(GetCheckButtonState( GetEntry(nSelPos), 0 ))
416 0 : nCheck += 2;
417 0 : nCheck--;
418 0 : nCheck &= 3;
419 0 : CheckEntryPos(nSelPos, 1, 0 != (nCheck & 1));
420 0 : CheckEntryPos(nSelPos, 0, 0 != (nCheck & 2));
421 : }
422 : }
423 : else
424 0 : SvSimpleTable::KeyInput(rKEvt);
425 0 : }
426 :
427 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|