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.hrc"
56 #include "optmemory.hxx"
57 #include <svx/ofaitem.hxx>
60 #include <dialmgr.hxx>
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::lang
;
64 using namespace ::com::sun::star::beans
;
65 using namespace ::utl
;
66 using namespace ::rtl
;
67 using namespace ::sfx2
;
70 #define NF2BYTES 104857.6 // 2^20/10, used for aNfGraphicObjectCache-unit -> Byte
71 #define BYTES2NF (1.0/NF2BYTES) // 10/2^20
74 sal_Int32
OfaMemoryOptionsPage::GetNfGraphicCacheVal() const
76 return aNfGraphicCache
.GetValue() << 20;
79 inline void OfaMemoryOptionsPage::SetNfGraphicCacheVal( long nSizeInBytes
)
81 aNfGraphicCache
.SetValue( nSizeInBytes
>> 20 );
84 long OfaMemoryOptionsPage::GetNfGraphicObjectCacheVal( void ) const
86 return long( ::rtl::math::round( double( aNfGraphicObjectCache
.GetValue() ) * NF2BYTES
) );
89 void OfaMemoryOptionsPage::SetNfGraphicObjectCacheVal( long nSizeInBytes
)
91 aNfGraphicObjectCache
.SetValue( long( ::rtl::math::round( double( nSizeInBytes
) * BYTES2NF
) ) );
94 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheMax( long nSizeInBytes
)
96 aNfGraphicObjectCache
.SetMax( long( double( nSizeInBytes
) * BYTES2NF
) );
99 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheLast( long nSizeInBytes
)
101 aNfGraphicObjectCache
.SetLast( long( double( nSizeInBytes
) * BYTES2NF
) );
104 int OfaMemoryOptionsPage::DeactivatePage( SfxItemSet
* _pSet
)
107 FillItemSet( *_pSet
);
111 // -----------------------------------------------------------------------
113 OfaMemoryOptionsPage::OfaMemoryOptionsPage(Window
* pParent
, const SfxItemSet
& rSet
) :
115 SfxTabPage( pParent
, CUI_RES( OFA_TP_MEMORY
), rSet
),
117 aUndoBox ( this, CUI_RES( GB_UNDO
) ),
118 aUndoText ( this, CUI_RES( FT_UNDO
) ),
119 aUndoEdit ( this, CUI_RES( ED_UNDO
) ),
120 aGbGraphicCache ( this, CUI_RES( GB_GRAPHICCACHE
) ),
121 aFtGraphicCache ( this, CUI_RES( FT_GRAPHICCACHE
) ),
122 aNfGraphicCache ( this, CUI_RES( NF_GRAPHICCACHE
) ),
123 aFtGraphicCacheUnit ( this, CUI_RES( FT_GRAPHICCACHE_UNIT
) ),
124 aFtGraphicObjectCache ( this, CUI_RES( FT_GRAPHICOBJECTCACHE
) ),
125 aNfGraphicObjectCache ( this, CUI_RES( NF_GRAPHICOBJECTCACHE
) ),
126 aFtGraphicObjectCacheUnit(this, CUI_RES( FT_GRAPHICOBJECTCACHE_UNIT
) ),
127 aFtGraphicObjectTime ( this, CUI_RES( FT_GRAPHICOBJECTTIME
) ),
128 aTfGraphicObjectTime ( this, CUI_RES( TF_GRAPHICOBJECTTIME
) ),
129 aFtGraphicObjectTimeUnit( this, CUI_RES( FT_GRAPHICOBJECTTIME_UNIT
) ),
131 aGbOLECache ( this, CUI_RES( GB_OLECACHE
) ),
132 aFtOLECache ( this, CUI_RES( FT_OLECACHE
) ),
133 aNfOLECache ( this, CUI_RES( NF_OLECACHE
) ),
134 aQuickLaunchFL ( this, CUI_RES( FL_QUICKLAUNCH
) ),
135 aQuickLaunchCB ( this, CUI_RES( CB_QUICKLAUNCH
) )//,
138 aQuickLaunchCB
.SetText( CUI_RES( STR_QUICKLAUNCH_UNX
) );
142 //quick launch only available in Win
143 #if !defined(WNT) && !defined(ENABLE_GTK)
144 aQuickLaunchFL
.Hide();
145 aQuickLaunchCB
.Hide();
148 aTfGraphicObjectTime
.SetExtFormat( EXTTIMEF_24H_SHORT
);
150 SetExchangeSupport();
152 aNfGraphicCache
.SetModifyHdl( LINK( this, OfaMemoryOptionsPage
, GraphicCacheConfigHdl
) );
155 // -----------------------------------------------------------------------
157 OfaMemoryOptionsPage::~OfaMemoryOptionsPage()
161 // -----------------------------------------------------------------------
163 SfxTabPage
* OfaMemoryOptionsPage::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
165 return new OfaMemoryOptionsPage( pParent
, rAttrSet
);
168 // -----------------------------------------------------------------------
170 sal_Bool
OfaMemoryOptionsPage::FillItemSet( SfxItemSet
& rSet
)
172 sal_Bool bModified
= sal_False
;
174 boost::shared_ptr
< comphelper::ConfigurationChanges
> batch(
175 comphelper::ConfigurationChanges::create());
177 if ( aUndoEdit
.GetText() != aUndoEdit
.GetSavedValue() )
178 officecfg::Office::Common::Undo::Steps::set(
179 aUndoEdit
.GetValue(), batch
);
182 sal_Int32 totalCacheSize
= GetNfGraphicCacheVal();
183 officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(
184 totalCacheSize
, batch
);
185 sal_Int32 objectCacheSize
= GetNfGraphicObjectCacheVal();
186 officecfg::Office::Common::Cache::GraphicManager::ObjectCacheSize::set(
187 objectCacheSize
, batch
);
189 const Time
aTime( aTfGraphicObjectTime
.GetTime() );
190 sal_Int32 objectReleaseTime
=
191 aTime
.GetSec() + aTime
.GetMin() * 60 + aTime
.GetHour() * 3600;
192 officecfg::Office::Common::Cache::GraphicManager::ObjectReleaseTime::set(
193 objectReleaseTime
, batch
);
195 // create a dummy graphic object to get access to the common GraphicManager
196 GraphicObject aDummyObject
;
197 GraphicManager
& rGrfMgr
= aDummyObject
.GetGraphicManager();
199 rGrfMgr
.SetMaxCacheSize(totalCacheSize
);
200 rGrfMgr
.SetMaxObjCacheSize(objectCacheSize
, true);
201 rGrfMgr
.SetCacheTimeout(objectReleaseTime
);
204 officecfg::Office::Common::Cache::Writer::OLE_Objects::set(
205 aNfOLECache
.GetValue(), batch
);
206 officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::set(
207 aNfOLECache
.GetValue(), batch
);
211 if( aQuickLaunchCB
.IsChecked() != aQuickLaunchCB
.GetSavedValue())
213 rSet
.Put(SfxBoolItem(SID_ATTR_QUICKLAUNCHER
, aQuickLaunchCB
.IsChecked()));
214 bModified
= sal_True
;
220 // -----------------------------------------------------------------------
222 void OfaMemoryOptionsPage::Reset( const SfxItemSet
& rSet
)
224 const SfxPoolItem
* pItem
;
226 aUndoEdit
.SetValue(officecfg::Office::Common::Undo::Steps::get());
227 aUndoEdit
.SaveValue();
231 officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::get();
232 SetNfGraphicCacheVal( n
);
233 SetNfGraphicObjectCacheVal(
235 GetNfGraphicCacheVal(),
236 (officecfg::Office::Common::Cache::GraphicManager::ObjectCacheSize::
240 officecfg::Office::Common::Cache::GraphicManager::ObjectReleaseTime::
242 Time
aTime( (sal_uInt16
)( nTime
/ 3600 ), (sal_uInt16
)( ( nTime
% 3600 ) / 60 ), (sal_uInt16
)( ( nTime
% 3600 ) % 60 ) );
243 aTfGraphicObjectTime
.SetTime( aTime
);
245 GraphicCacheConfigHdl( &aNfGraphicCache
);
248 aNfOLECache
.SetValue(
250 officecfg::Office::Common::Cache::Writer::OLE_Objects::get(),
251 (officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::
254 SfxItemState eState
= rSet
.GetItemState( SID_ATTR_QUICKLAUNCHER
, sal_False
, &pItem
);
255 if ( SFX_ITEM_SET
== eState
)
256 aQuickLaunchCB
.Check( ( (SfxBoolItem
*)pItem
)->GetValue() );
257 else if ( SFX_ITEM_DISABLED
== eState
)
259 // quickstart not installed
260 aQuickLaunchFL
.Hide();
261 aQuickLaunchCB
.Hide();
264 aQuickLaunchCB
.SaveValue();
267 // -----------------------------------------------------------------------
269 IMPL_LINK_NOARG(OfaMemoryOptionsPage
, GraphicCacheConfigHdl
)
271 sal_Int32 n
= GetNfGraphicCacheVal();
272 SetNfGraphicObjectCacheMax( n
);
273 SetNfGraphicObjectCacheLast( n
);
275 if( GetNfGraphicObjectCacheVal() > n
)
276 SetNfGraphicObjectCacheVal( n
);
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */