Bump version to 4.3-4
[LibreOffice.git] / cui / source / options / optmemory.cxx
blob72bda7a569f7b83cd8b1c8eeee88f208a378c087
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
22 #include <algorithm>
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>
57 #include <cuires.hrc>
58 #include "helpid.hrc"
59 #include <dialmgr.hxx>
61 #include <config_vclplug.h>
63 using namespace ::com::sun::star::uno;
64 using namespace ::com::sun::star::lang;
65 using namespace ::com::sun::star::beans;
66 using namespace ::utl;
67 using namespace ::rtl;
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( void ) 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 int OfaMemoryOptionsPage::DeactivatePage( SfxItemSet* _pSet )
107 if ( _pSet )
108 FillItemSet( *_pSet );
109 return LEAVE_PAGE;
114 OfaMemoryOptionsPage::OfaMemoryOptionsPage(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 get(m_pNfGraphicObjectCache, "objectcache");
120 get(m_pTfGraphicObjectTime,"objecttime");
121 get(m_pNfOLECache, "olecache");
122 get(m_pQuickStarterFrame, "quickstarter");
124 #if defined(UNX)
125 get(m_pQuickLaunchCB, "systray");
126 #else
127 get(m_pQuickLaunchCB, "quicklaunch");
128 #endif
129 m_pQuickLaunchCB->Show();
131 //Only available in Win or if building the gtk systray
132 #if !defined(WNT) && ! ENABLE_GTK
133 m_pQuickStarterFrame->Hide();
134 #endif
136 m_pTfGraphicObjectTime->SetExtFormat( EXTTIMEF_24H_SHORT );
138 SetExchangeSupport();
140 m_pNfGraphicCache->SetModifyHdl( LINK( this, OfaMemoryOptionsPage, GraphicCacheConfigHdl ) );
145 OfaMemoryOptionsPage::~OfaMemoryOptionsPage()
151 SfxTabPage* OfaMemoryOptionsPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
153 return new OfaMemoryOptionsPage( pParent, rAttrSet );
158 bool OfaMemoryOptionsPage::FillItemSet( SfxItemSet& rSet )
160 bool bModified = false;
162 boost::shared_ptr< comphelper::ConfigurationChanges > batch(
163 comphelper::ConfigurationChanges::create());
165 if ( m_pUndoEdit->IsValueChangedFromSaved() )
166 officecfg::Office::Common::Undo::Steps::set(
167 m_pUndoEdit->GetValue(), batch);
169 // GraphicCache
170 sal_Int32 totalCacheSize = GetNfGraphicCacheVal();
171 officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(
172 totalCacheSize, batch);
173 sal_Int32 objectCacheSize = GetNfGraphicObjectCacheVal();
174 officecfg::Office::Common::Cache::GraphicManager::ObjectCacheSize::set(
175 objectCacheSize, batch);
177 const Time aTime( m_pTfGraphicObjectTime->GetTime() );
178 sal_Int32 objectReleaseTime =
179 aTime.GetSec() + aTime.GetMin() * 60 + aTime.GetHour() * 3600;
180 officecfg::Office::Common::Cache::GraphicManager::ObjectReleaseTime::set(
181 objectReleaseTime, batch);
183 // create a dummy graphic object to get access to the common GraphicManager
184 GraphicObject aDummyObject;
185 GraphicManager& rGrfMgr = aDummyObject.GetGraphicManager();
187 rGrfMgr.SetMaxCacheSize(totalCacheSize);
188 rGrfMgr.SetMaxObjCacheSize(objectCacheSize, true);
189 rGrfMgr.SetCacheTimeout(objectReleaseTime);
191 // OLECache
192 officecfg::Office::Common::Cache::Writer::OLE_Objects::set(
193 m_pNfOLECache->GetValue(), batch);
194 officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::set(
195 m_pNfOLECache->GetValue(), batch);
197 batch->commit();
199 if( m_pQuickLaunchCB->IsValueChangedFromSaved())
201 rSet.Put(SfxBoolItem(SID_ATTR_QUICKLAUNCHER, m_pQuickLaunchCB->IsChecked()));
202 bModified = true;
205 return bModified;
210 void OfaMemoryOptionsPage::Reset( const SfxItemSet& rSet )
212 const SfxPoolItem* pItem;
214 m_pUndoEdit->SetValue(officecfg::Office::Common::Undo::Steps::get());
215 m_pUndoEdit->SaveValue();
217 // GraphicCache
218 long n =
219 officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::get();
220 SetNfGraphicCacheVal( n );
221 SetNfGraphicObjectCacheVal(
222 std::min(
223 GetNfGraphicCacheVal(),
224 (officecfg::Office::Common::Cache::GraphicManager::ObjectCacheSize::
225 get())));
227 sal_Int32 nTime =
228 officecfg::Office::Common::Cache::GraphicManager::ObjectReleaseTime::
229 get();
230 Time aTime( (sal_uInt16)( nTime / 3600 ), (sal_uInt16)( ( nTime % 3600 ) / 60 ), (sal_uInt16)( ( nTime % 3600 ) % 60 ) );
231 m_pTfGraphicObjectTime->SetTime( aTime );
233 GraphicCacheConfigHdl(m_pNfGraphicCache);
235 // OLECache
236 m_pNfOLECache->SetValue(
237 std::max(
238 officecfg::Office::Common::Cache::Writer::OLE_Objects::get(),
239 (officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::
240 get())));
242 SfxItemState eState = rSet.GetItemState( SID_ATTR_QUICKLAUNCHER, false, &pItem );
243 if ( SFX_ITEM_SET == eState )
244 m_pQuickLaunchCB->Check( ( (SfxBoolItem*)pItem )->GetValue() );
245 else if ( SFX_ITEM_DISABLED == eState )
247 // quickstart not installed
248 m_pQuickStarterFrame->Hide();
251 m_pQuickLaunchCB->SaveValue();
256 IMPL_LINK_NOARG(OfaMemoryOptionsPage, GraphicCacheConfigHdl)
258 sal_Int32 n = GetNfGraphicCacheVal();
259 SetNfGraphicObjectCacheMax( n );
260 SetNfGraphicObjectCacheLast( n );
262 if( GetNfGraphicObjectCacheVal() > n )
263 SetNfGraphicObjectCacheVal( n );
265 return 0;
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */