1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sal/config.h"
24 #include <officecfg/Office/Common.hxx>
25 #include <svtools/langtab.hxx>
26 #include <svl/zforlist.hxx>
27 #include <svtools/grfmgr.hxx>
28 #include <svl/flagitem.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <unotools/lingucfg.hxx>
31 #include <svl/szitem.hxx>
32 #include <sfx2/viewsh.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <rtl/math.hxx>
36 #include <unotools/useroptions.hxx>
37 #include <unotools/fontoptions.hxx>
38 #include <svtools/menuoptions.hxx>
39 #include <svl/cjkoptions.hxx>
40 #include <svtools/miscopt.hxx>
41 #include <unotools/syslocaleoptions.hxx>
42 #include <svtools/helpopt.hxx>
43 #include <unotools/configitem.hxx>
44 #include <sfx2/objsh.hxx>
45 #include <comphelper/types.hxx>
46 #include <editeng/unolingu.hxx>
47 #include <editeng/langitem.hxx>
48 #include "cuioptgenrl.hxx"
49 #include "optpath.hxx"
50 #include "optsave.hxx"
51 #include "optlingu.hxx"
52 #include <svx/xpool.hxx>
53 #include <svx/dlgutil.hxx>
54 #include "cuitabarea.hxx"
55 #include "optmemory.hxx"
56 #include <svx/ofaitem.hxx>
59 #include <dialmgr.hxx>
62 #include <config_vclplug.h>
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::lang
;
66 using namespace ::com::sun::star::beans
;
67 using namespace ::utl
;
68 using namespace ::sfx2
;
71 #define NF2BYTES 104857.6 // 2^20/10, used for M_pNfGraphicObjectCache-unit -> Byte
72 #define BYTES2NF (1.0/NF2BYTES) // 10/2^20
75 sal_Int32
OfaMemoryOptionsPage::GetNfGraphicCacheVal() const
77 return m_pNfGraphicCache
->GetValue() << 20;
80 inline void OfaMemoryOptionsPage::SetNfGraphicCacheVal( long nSizeInBytes
)
82 m_pNfGraphicCache
->SetValue( nSizeInBytes
>> 20 );
85 long OfaMemoryOptionsPage::GetNfGraphicObjectCacheVal() const
87 return long( ::rtl::math::round( double( m_pNfGraphicObjectCache
->GetValue() ) * NF2BYTES
) );
90 void OfaMemoryOptionsPage::SetNfGraphicObjectCacheVal( long nSizeInBytes
)
92 m_pNfGraphicObjectCache
->SetValue( long( ::rtl::math::round( double( nSizeInBytes
) * BYTES2NF
) ) );
95 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheMax( long nSizeInBytes
)
97 m_pNfGraphicObjectCache
->SetMax( long( double( nSizeInBytes
) * BYTES2NF
) );
100 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheLast( long nSizeInBytes
)
102 m_pNfGraphicObjectCache
->SetLast( long( double( nSizeInBytes
) * BYTES2NF
) );
105 SfxTabPage::sfxpg
OfaMemoryOptionsPage::DeactivatePage( SfxItemSet
* _pSet
)
108 FillItemSet( _pSet
);
114 OfaMemoryOptionsPage::OfaMemoryOptionsPage(vcl::Window
* pParent
, const SfxItemSet
& rSet
)
115 : SfxTabPage(pParent
, "OptMemoryPage", "cui/ui/optmemorypage.ui", &rSet
)
117 get(m_pUndoEdit
, "undo");
118 get(m_pNfGraphicCache
, "graphiccache");
119 m_pNfGraphicCache
->SetMax(std::numeric_limits
< long >::max() >> 20);
120 get(m_pNfGraphicObjectCache
, "objectcache");
121 get(m_pTfGraphicObjectTime
,"objecttime");
122 get(m_pNfOLECache
, "olecache");
123 get(m_pQuickStarterFrame
, "quickstarter");
126 get(m_pQuickLaunchCB
, "systray");
128 get(m_pQuickLaunchCB
, "quicklaunch");
130 m_pQuickLaunchCB
->Show();
132 //Only available in Win or if building the gtk systray
133 #if !defined(WNT) && ! ENABLE_GTK
134 m_pQuickStarterFrame
->Hide();
137 m_pTfGraphicObjectTime
->SetExtFormat( EXTTIMEF_24H_SHORT
);
139 SetExchangeSupport();
141 m_pNfGraphicCache
->SetModifyHdl( LINK( this, OfaMemoryOptionsPage
, GraphicCacheConfigHdl
) );
144 OfaMemoryOptionsPage::~OfaMemoryOptionsPage()
149 void OfaMemoryOptionsPage::dispose()
152 m_pNfGraphicCache
.clear();
153 m_pNfGraphicObjectCache
.clear();
154 m_pTfGraphicObjectTime
.clear();
155 m_pNfOLECache
.clear();
156 m_pQuickStarterFrame
.clear();
157 m_pQuickLaunchCB
.clear();
158 SfxTabPage::dispose();
161 VclPtr
<SfxTabPage
> OfaMemoryOptionsPage::Create( vcl::Window
* pParent
, const SfxItemSet
* rAttrSet
)
163 return VclPtr
<OfaMemoryOptionsPage
>::Create( pParent
, *rAttrSet
);
166 bool OfaMemoryOptionsPage::FillItemSet( SfxItemSet
* rSet
)
168 bool bModified
= false;
170 std::shared_ptr
< comphelper::ConfigurationChanges
> batch(
171 comphelper::ConfigurationChanges::create());
173 if ( m_pUndoEdit
->IsValueChangedFromSaved() )
174 officecfg::Office::Common::Undo::Steps::set(
175 m_pUndoEdit
->GetValue(), batch
);
178 sal_Int32 totalCacheSize
= GetNfGraphicCacheVal();
179 officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(
180 totalCacheSize
, batch
);
181 sal_Int32 objectCacheSize
= GetNfGraphicObjectCacheVal();
182 officecfg::Office::Common::Cache::GraphicManager::ObjectCacheSize::set(
183 objectCacheSize
, batch
);
185 const tools::Time
aTime( m_pTfGraphicObjectTime
->GetTime() );
186 sal_Int32 objectReleaseTime
=
187 aTime
.GetSec() + aTime
.GetMin() * 60 + aTime
.GetHour() * 3600;
188 officecfg::Office::Common::Cache::GraphicManager::ObjectReleaseTime::set(
189 objectReleaseTime
, batch
);
191 // create a dummy graphic object to get access to the common GraphicManager
192 GraphicObject aDummyObject
;
193 GraphicManager
& rGrfMgr
= aDummyObject
.GetGraphicManager();
195 rGrfMgr
.SetMaxCacheSize(totalCacheSize
);
196 rGrfMgr
.SetMaxObjCacheSize(objectCacheSize
, true);
197 rGrfMgr
.SetCacheTimeout(objectReleaseTime
);
200 officecfg::Office::Common::Cache::Writer::OLE_Objects::set(
201 m_pNfOLECache
->GetValue(), batch
);
202 officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::set(
203 m_pNfOLECache
->GetValue(), batch
);
207 if( m_pQuickLaunchCB
->IsValueChangedFromSaved())
209 rSet
->Put(SfxBoolItem(SID_ATTR_QUICKLAUNCHER
, m_pQuickLaunchCB
->IsChecked()));
218 void OfaMemoryOptionsPage::Reset( const SfxItemSet
* rSet
)
220 const SfxPoolItem
* pItem
;
222 m_pUndoEdit
->SetValue(officecfg::Office::Common::Undo::Steps::get());
223 m_pUndoEdit
->SaveValue();
227 officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::get();
228 SetNfGraphicCacheVal( n
);
229 SetNfGraphicObjectCacheVal(
231 GetNfGraphicCacheVal(),
232 (officecfg::Office::Common::Cache::GraphicManager::ObjectCacheSize::
236 officecfg::Office::Common::Cache::GraphicManager::ObjectReleaseTime::
238 tools::Time
aTime( (sal_uInt16
)( nTime
/ 3600 ), (sal_uInt16
)( ( nTime
% 3600 ) / 60 ), (sal_uInt16
)( ( nTime
% 3600 ) % 60 ) );
239 m_pTfGraphicObjectTime
->SetTime( aTime
);
241 GraphicCacheConfigHdl(m_pNfGraphicCache
);
244 m_pNfOLECache
->SetValue(
246 officecfg::Office::Common::Cache::Writer::OLE_Objects::get(),
247 (officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::
250 SfxItemState eState
= rSet
->GetItemState( SID_ATTR_QUICKLAUNCHER
, false, &pItem
);
251 if ( SfxItemState::SET
== eState
)
252 m_pQuickLaunchCB
->Check( static_cast<const SfxBoolItem
*>(pItem
)->GetValue() );
253 else if ( SfxItemState::DISABLED
== eState
)
255 // quickstart not installed
256 m_pQuickStarterFrame
->Hide();
259 m_pQuickLaunchCB
->SaveValue();
264 IMPL_LINK_NOARG(OfaMemoryOptionsPage
, GraphicCacheConfigHdl
)
266 sal_Int32 n
= GetNfGraphicCacheVal();
267 SetNfGraphicObjectCacheMax( n
);
268 SetNfGraphicObjectCacheLast( n
);
270 if( GetNfGraphicObjectCacheVal() > n
)
271 SetNfGraphicObjectCacheVal( n
);
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */