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(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 : 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 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, const SfxItemSet& rSet ) :
133 : SfxTabPage( pParent, "OptFilterPage", "cui/ui/optfltrembedpage.ui", rSet ),
134 0 : sHeader1(CUI_RES(RID_SVXSTR_HEADER1)),
135 0 : sHeader2(CUI_RES(RID_SVXSTR_HEADER2)),
136 0 : sChgToFromMath(CUI_RES(RID_SVXSTR_CHG_MATH)),
137 0 : sChgToFromWriter(CUI_RES(RID_SVXSTR_CHG_WRITER)),
138 0 : sChgToFromCalc(CUI_RES(RID_SVXSTR_CHG_CALC)),
139 0 : sChgToFromImpress(CUI_RES(RID_SVXSTR_CHG_IMPRESS)),
140 0 : sChgToFromSmartArt(CUI_RES(RID_SVXSTR_CHG_SMARTART)),
141 0 : pCheckButtonData(0)
142 : {
143 0 : get(m_pCheckLBContainer, "checklbcontainer");
144 0 : Size aControlSize(248, 55);
145 0 : aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
146 0 : m_pCheckLBContainer->set_width_request(aControlSize.Width());
147 0 : m_pCheckLBContainer->set_height_request(aControlSize.Height());
148 :
149 0 : m_pCheckLB = new MSFltrSimpleTable(*m_pCheckLBContainer);
150 :
151 : static long aStaticTabs[] = { 3, 0, 20, 40 };
152 0 : m_pCheckLB->SvSimpleTable::SetTabs( aStaticTabs );
153 :
154 0 : OUString sHeader = sHeader1 + "\t" + sHeader2 + "\t";
155 : m_pCheckLB->InsertHeaderEntry( sHeader, HEADERBAR_APPEND,
156 0 : HIB_CENTER | HIB_VCENTER | HIB_FIXEDPOS | HIB_FIXED );
157 :
158 0 : m_pCheckLB->SetStyle( m_pCheckLB->GetStyle()|WB_HSCROLL| WB_VSCROLL );
159 0 : }
160 :
161 0 : OfaMSFilterTabPage2::~OfaMSFilterTabPage2()
162 : {
163 0 : delete pCheckButtonData;
164 0 : delete m_pCheckLB;
165 0 : }
166 :
167 0 : SfxTabPage* OfaMSFilterTabPage2::Create( Window* pParent,
168 : const SfxItemSet& rAttrSet )
169 : {
170 0 : return new OfaMSFilterTabPage2( pParent, rAttrSet );
171 : }
172 :
173 0 : bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet& )
174 : {
175 0 : SvtFilterOptions& rOpt = SvtFilterOptions::Get();
176 :
177 : static struct ChkCBoxEntries{
178 : MSFltrPg2_CheckBoxEntries eType;
179 : bool (SvtFilterOptions:: *FnIs)() const;
180 : void (SvtFilterOptions:: *FnSet)( bool bFlag );
181 : } aChkArr[] = {
182 : { Math, &SvtFilterOptions::IsMathType2Math,
183 : &SvtFilterOptions::SetMathType2Math },
184 : { Math, &SvtFilterOptions::IsMath2MathType,
185 : &SvtFilterOptions::SetMath2MathType },
186 : { Writer, &SvtFilterOptions::IsWinWord2Writer,
187 : &SvtFilterOptions::SetWinWord2Writer },
188 : { Writer, &SvtFilterOptions::IsWriter2WinWord,
189 : &SvtFilterOptions::SetWriter2WinWord },
190 : { Calc, &SvtFilterOptions::IsExcel2Calc,
191 : &SvtFilterOptions::SetExcel2Calc },
192 : { Calc, &SvtFilterOptions::IsCalc2Excel,
193 : &SvtFilterOptions::SetCalc2Excel },
194 : { Impress, &SvtFilterOptions::IsPowerPoint2Impress,
195 : &SvtFilterOptions::SetPowerPoint2Impress },
196 : { Impress, &SvtFilterOptions::IsImpress2PowerPoint,
197 : &SvtFilterOptions::SetImpress2PowerPoint },
198 : { SmartArt, &SvtFilterOptions::IsSmartArt2Shape,
199 : &SvtFilterOptions::SetSmartArt2Shape },
200 : { InvalidCBEntry, 0, 0 }
201 : };
202 :
203 0 : bool bCheck, bFirst = true;
204 0 : for( const ChkCBoxEntries* pArr = aChkArr;
205 0 : InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
206 : {
207 0 : sal_uInt16 nCol = bFirst ? 1 : 2;
208 0 : SvTreeListEntry* pEntry = GetEntry4Type( pArr->eType );
209 0 : if( pEntry )
210 : {
211 0 : SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem( nCol ));
212 0 : if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
213 : {
214 0 : sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
215 : bCheck = SV_BUTTON_CHECKED ==
216 0 : pCheckButtonData->ConvertToButtonState( nButtonFlags );
217 :
218 0 : if( bCheck != (rOpt.*pArr->FnIs)() )
219 0 : (rOpt.*pArr->FnSet)( bCheck );
220 : }
221 : }
222 : }
223 :
224 0 : return true;
225 : }
226 :
227 0 : void OfaMSFilterTabPage2::Reset( const SfxItemSet& )
228 : {
229 0 : SvtFilterOptions& rOpt = SvtFilterOptions::Get();
230 :
231 0 : m_pCheckLB->SetUpdateMode(false);
232 0 : m_pCheckLB->Clear();
233 :
234 0 : SvtModuleOptions aModuleOpt;
235 :
236 : // int the same sequence as the enums of MSFltrPg2_CheckBoxEntries
237 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
238 0 : InsertEntry( sChgToFromMath, static_cast< sal_IntPtr >( Math ) );
239 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
240 0 : InsertEntry( sChgToFromWriter, static_cast< sal_IntPtr >( Writer ) );
241 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
242 0 : InsertEntry( sChgToFromCalc, static_cast< sal_IntPtr >( Calc ) );
243 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
244 0 : InsertEntry( sChgToFromImpress, static_cast< sal_IntPtr >( Impress ) );
245 0 : InsertEntry( sChgToFromSmartArt, static_cast< sal_IntPtr >( SmartArt ), true, false );
246 :
247 : static struct ChkCBoxEntries{
248 : MSFltrPg2_CheckBoxEntries eType;
249 : 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 : { SmartArt, &SvtFilterOptions::IsSmartArt2Shape },
260 : { InvalidCBEntry, NULL }
261 : };
262 :
263 0 : sal_Bool bFirst = sal_True;
264 0 : for( const ChkCBoxEntries* pArr = aChkArr;
265 0 : InvalidCBEntry != pArr->eType; ++pArr, bFirst = !bFirst )
266 : {
267 0 : sal_uInt16 nCol = bFirst ? 1 : 2;
268 0 : SvTreeListEntry* pEntry = GetEntry4Type( static_cast< sal_IntPtr >( pArr->eType ) );
269 0 : if( pEntry )
270 : {
271 0 : SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem( nCol ));
272 0 : if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
273 : {
274 0 : if( (rOpt.*pArr->FnIs)() )
275 0 : pItem->SetStateChecked();
276 : else
277 0 : pItem->SetStateUnchecked();
278 0 : m_pCheckLB->InvalidateEntry( pEntry );
279 : }
280 : }
281 : }
282 0 : m_pCheckLB->SetUpdateMode( true );
283 0 : }
284 :
285 0 : void OfaMSFilterTabPage2::InsertEntry( const OUString& _rTxt, sal_IntPtr _nType )
286 : {
287 0 : InsertEntry( _rTxt, _nType, true, true );
288 0 : }
289 :
290 0 : void OfaMSFilterTabPage2::InsertEntry( const OUString& _rTxt, sal_IntPtr _nType,
291 : sal_Bool loadEnabled, sal_Bool saveEnabled )
292 : {
293 0 : SvTreeListEntry* pEntry = new SvTreeListEntry;
294 :
295 0 : if( !pCheckButtonData )
296 0 : pCheckButtonData = new SvLBoxButtonData( m_pCheckLB );
297 :
298 0 : pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), false));
299 : pEntry->AddItem( new SvLBoxButton( pEntry, loadEnabled? SvLBoxButtonKind_enabledCheckbox :
300 : SvLBoxButtonKind_disabledCheckbox,
301 0 : 0, pCheckButtonData ) );
302 : pEntry->AddItem( new SvLBoxButton( pEntry, saveEnabled? SvLBoxButtonKind_enabledCheckbox :
303 : SvLBoxButtonKind_disabledCheckbox,
304 0 : 0, pCheckButtonData ) );
305 0 : pEntry->AddItem( new SvLBoxString( pEntry, 0, _rTxt ) );
306 :
307 0 : pEntry->SetUserData( (void*)_nType );
308 0 : m_pCheckLB->Insert( pEntry );
309 0 : }
310 :
311 0 : SvTreeListEntry* OfaMSFilterTabPage2::GetEntry4Type( sal_IntPtr _nType ) const
312 : {
313 0 : SvTreeListEntry* pEntry = m_pCheckLB->First();
314 0 : while ( pEntry )
315 : {
316 0 : if ( _nType == sal_IntPtr( pEntry->GetUserData() ) )
317 0 : return pEntry;
318 0 : pEntry = m_pCheckLB->Next( pEntry );
319 : }
320 0 : return NULL;
321 : }
322 :
323 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::SetTabs()
324 : {
325 0 : SvSimpleTable::SetTabs();
326 0 : sal_uInt16 nAdjust = SV_LBOXTAB_ADJUST_RIGHT|SV_LBOXTAB_ADJUST_LEFT|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_ADJUST_NUMERIC|SV_LBOXTAB_FORCE;
327 :
328 0 : if( aTabs.size() > 1 )
329 : {
330 0 : SvLBoxTab* pTab = aTabs[1];
331 0 : pTab->nFlags &= ~nAdjust;
332 0 : pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
333 : }
334 0 : if( aTabs.size() > 2 )
335 : {
336 0 : SvLBoxTab* pTab = aTabs[2];
337 0 : pTab->nFlags &= ~nAdjust;
338 0 : pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
339 : }
340 0 : }
341 :
342 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::HBarClick()
343 : {
344 : // sorting is stopped by this overloading
345 0 : }
346 :
347 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::SetCheckButtonState(
348 : SvTreeListEntry* pEntry, sal_uInt16 nCol, SvButtonState eState)
349 : {
350 0 : SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
351 :
352 : DBG_ASSERT(pItem,"SetCheckButton:Item not found");
353 0 : if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
354 : {
355 0 : switch( eState )
356 : {
357 : case SV_BUTTON_CHECKED:
358 0 : pItem->SetStateChecked();
359 0 : break;
360 :
361 : case SV_BUTTON_UNCHECKED:
362 0 : pItem->SetStateUnchecked();
363 0 : break;
364 :
365 : case SV_BUTTON_TRISTATE:
366 0 : pItem->SetStateTristate();
367 0 : break;
368 : }
369 0 : InvalidateEntry( pEntry );
370 : }
371 0 : }
372 :
373 0 : SvButtonState OfaMSFilterTabPage2::MSFltrSimpleTable::GetCheckButtonState(
374 : SvTreeListEntry* pEntry, sal_uInt16 nCol ) const
375 : {
376 0 : SvButtonState eState = SV_BUTTON_UNCHECKED;
377 0 : SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
378 : DBG_ASSERT(pItem,"GetChButnState:Item not found");
379 :
380 0 : if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
381 : {
382 0 : sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
383 0 : eState = pCheckButtonData->ConvertToButtonState( nButtonFlags );
384 : }
385 :
386 0 : return eState;
387 : }
388 :
389 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::CheckEntryPos(sal_uLong nPos, sal_uInt16 nCol, sal_Bool bChecked)
390 : {
391 0 : if ( nPos < GetEntryCount() )
392 : SetCheckButtonState(
393 : GetEntry(nPos),
394 : nCol,
395 : bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
396 0 : SvButtonState( SV_BUTTON_UNCHECKED ) );
397 0 : }
398 :
399 0 : void OfaMSFilterTabPage2::MSFltrSimpleTable::KeyInput( const KeyEvent& rKEvt )
400 : {
401 0 : if(!rKEvt.GetKeyCode().GetModifier() &&
402 0 : KEY_SPACE == rKEvt.GetKeyCode().GetCode())
403 : {
404 0 : sal_uLong nSelPos = GetModel()->GetAbsPos(GetCurEntry());
405 0 : sal_uInt16 nCol = GetCurrentTabPos() - 1;
406 0 : if ( nCol < 2 )
407 : {
408 0 : SvTreeListEntry* pEntry = GetEntry( nSelPos );
409 0 : sal_Bool bIsChecked = ( GetCheckButtonState( pEntry, nCol ) == SV_BUTTON_CHECKED );
410 0 : CheckEntryPos( nSelPos, nCol, !bIsChecked );
411 0 : CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE, (void*)pEntry );
412 : }
413 : else
414 : {
415 0 : sal_uInt16 nCheck = GetCheckButtonState( GetEntry(nSelPos), 1 ) == SV_BUTTON_CHECKED ? 1 : 0;
416 0 : if(GetCheckButtonState( GetEntry(nSelPos), 0 ))
417 0 : nCheck += 2;
418 0 : nCheck--;
419 0 : nCheck &= 3;
420 0 : CheckEntryPos(nSelPos, 1, 0 != (nCheck & 1));
421 0 : CheckEntryPos(nSelPos, 0, 0 != (nCheck & 2));
422 : }
423 : }
424 : else
425 0 : SvSimpleTable::KeyInput(rKEvt);
426 0 : }
427 :
428 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|