masterfix DEV300: #i10000# build fix
[LibreOffice.git] / cui / source / options / optmemory.cxx
blob65e340b1fda6519eaa050006b95660248ba021df
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 #include <svtools/langtab.hxx>
31 #include <svl/zforlist.hxx>
32 #include <svtools/grfmgr.hxx>
33 #include <svl/flagitem.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <unotools/lingucfg.hxx>
36 #include <svl/szitem.hxx>
37 #include <sfx2/viewsh.hxx>
38 #include <sfx2/viewfrm.hxx>
39 #include <sfx2/filedlghelper.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <rtl/math.hxx>
42 #include <unotools/undoopt.hxx>
43 #include <unotools/useroptions.hxx>
44 #include <unotools/cacheoptions.hxx>
45 #include <unotools/fontoptions.hxx>
46 #include <svtools/menuoptions.hxx>
47 #include <unotools/startoptions.hxx>
48 #include <svl/cjkoptions.hxx>
49 #include <svtools/miscopt.hxx>
50 #include <unotools/syslocaleoptions.hxx>
51 #include <svtools/helpopt.hxx>
52 #include <unotools/configitem.hxx>
53 #include <sfx2/objsh.hxx>
54 #include <comphelper/types.hxx>
55 #include <editeng/unolingu.hxx>
56 #include <editeng/langitem.hxx>
57 #include "cuioptgenrl.hxx"
58 #include "optpath.hxx"
59 #include "optsave.hxx"
60 #include "optlingu.hxx"
61 #include <svx/xpool.hxx>
62 #include <svx/dlgutil.hxx>
63 #include "cuitabarea.hxx"
64 #include <cuires.hrc>
65 #include "optmemory.hrc"
66 #include "optmemory.hxx"
67 #include <svx/ofaitem.hxx>
68 #include <cuires.hrc>
69 #include "helpid.hrc"
70 #include <dialmgr.hxx>
72 #define CONFIG_LANGUAGES "OfficeLanguages"
74 using namespace ::com::sun::star::uno;
75 using namespace ::com::sun::star::lang;
76 using namespace ::com::sun::star::beans;
77 using namespace ::utl;
78 using namespace ::rtl;
79 using namespace ::sfx2;
82 #define NF2BYTES 104857.6 // 2^20/10, used for aNfGraphicObjectCache-unit -> Byte
83 #define BYTES2NF (1.0/NF2BYTES) // 10/2^20
86 inline long OfaMemoryOptionsPage::GetNfGraphicCacheVal( void ) const
88 return static_cast<long>(aNfGraphicCache.GetValue() << 20);
91 inline void OfaMemoryOptionsPage::SetNfGraphicCacheVal( long nSizeInBytes )
93 aNfGraphicCache.SetValue( nSizeInBytes >> 20 );
96 long OfaMemoryOptionsPage::GetNfGraphicObjectCacheVal( void ) const
98 return long( ::rtl::math::round( double( aNfGraphicObjectCache.GetValue() ) * NF2BYTES ) );
101 void OfaMemoryOptionsPage::SetNfGraphicObjectCacheVal( long nSizeInBytes )
103 aNfGraphicObjectCache.SetValue( long( ::rtl::math::round( double( nSizeInBytes ) * BYTES2NF ) ) );
106 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheMax( long nSizeInBytes )
108 aNfGraphicObjectCache.SetMax( long( double( nSizeInBytes ) * BYTES2NF ) );
111 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheLast( long nSizeInBytes )
113 aNfGraphicObjectCache.SetLast( long( double( nSizeInBytes ) * BYTES2NF ) );
116 int OfaMemoryOptionsPage::DeactivatePage( SfxItemSet* _pSet )
118 if ( _pSet )
119 FillItemSet( *_pSet );
120 return LEAVE_PAGE;
123 // -----------------------------------------------------------------------
125 OfaMemoryOptionsPage::OfaMemoryOptionsPage(Window* pParent, const SfxItemSet& rSet ) :
127 SfxTabPage( pParent, CUI_RES( OFA_TP_MEMORY ), rSet ),
129 aUndoBox ( this, CUI_RES( GB_UNDO ) ),
130 aUndoText ( this, CUI_RES( FT_UNDO ) ),
131 aUndoEdit ( this, CUI_RES( ED_UNDO ) ),
132 aGbGraphicCache ( this, CUI_RES( GB_GRAPHICCACHE ) ),
133 aFtGraphicCache ( this, CUI_RES( FT_GRAPHICCACHE ) ),
134 aNfGraphicCache ( this, CUI_RES( NF_GRAPHICCACHE ) ),
135 aFtGraphicCacheUnit ( this, CUI_RES( FT_GRAPHICCACHE_UNIT ) ),
136 aFtGraphicObjectCache ( this, CUI_RES( FT_GRAPHICOBJECTCACHE ) ),
137 aNfGraphicObjectCache ( this, CUI_RES( NF_GRAPHICOBJECTCACHE ) ),
138 aFtGraphicObjectCacheUnit(this, CUI_RES( FT_GRAPHICOBJECTCACHE_UNIT ) ),
139 aFtGraphicObjectTime ( this, CUI_RES( FT_GRAPHICOBJECTTIME ) ),
140 aTfGraphicObjectTime ( this, CUI_RES( TF_GRAPHICOBJECTTIME ) ),
141 aFtGraphicObjectTimeUnit( this, CUI_RES( FT_GRAPHICOBJECTTIME_UNIT ) ),
143 aGbOLECache ( this, CUI_RES( GB_OLECACHE ) ),
144 aFtOLECache ( this, CUI_RES( FT_OLECACHE ) ),
145 aNfOLECache ( this, CUI_RES( NF_OLECACHE ) ),
146 aQuickLaunchFL ( this, CUI_RES( FL_QUICKLAUNCH ) ),
147 aQuickLaunchCB ( this, CUI_RES( CB_QUICKLAUNCH ) )//,
149 #if defined(UNX)
150 aQuickLaunchCB.SetText( CUI_RES( STR_QUICKLAUNCH_UNX ) );
151 #endif
152 FreeResource();
154 //quick launch only available in Win and OS/2
155 #if !defined(WNT) && !defined(OS2) && !defined(ENABLE_GTK)
156 aQuickLaunchFL.Hide();
157 aQuickLaunchCB.Hide();
158 #endif
160 aTfGraphicObjectTime.SetExtFormat( EXTTIMEF_24H_SHORT );
162 SetExchangeSupport();
164 aNfGraphicCache.SetModifyHdl( LINK( this, OfaMemoryOptionsPage, GraphicCacheConfigHdl ) );
167 // -----------------------------------------------------------------------
169 OfaMemoryOptionsPage::~OfaMemoryOptionsPage()
173 // -----------------------------------------------------------------------
175 SfxTabPage* OfaMemoryOptionsPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
177 return new OfaMemoryOptionsPage( pParent, rAttrSet );
180 // -----------------------------------------------------------------------
182 sal_Bool OfaMemoryOptionsPage::FillItemSet( SfxItemSet& rSet )
184 sal_Bool bModified = sal_False;
186 SvtCacheOptions aCacheOptions;
188 // Undo-Schritte
189 if ( aUndoEdit.GetText() != aUndoEdit.GetSavedValue() )
190 SvtUndoOptions().SetUndoCount((sal_uInt16)aUndoEdit.GetValue());
192 // GraphicCache
193 aCacheOptions.SetGraphicManagerTotalCacheSize( GetNfGraphicCacheVal() );
194 aCacheOptions.SetGraphicManagerObjectCacheSize( GetNfGraphicObjectCacheVal() );
196 const Time aTime( aTfGraphicObjectTime.GetTime() );
197 aCacheOptions.SetGraphicManagerObjectReleaseTime( aTime.GetSec() + aTime.GetMin() * 60 + aTime.GetHour() * 3600 );
199 // create a dummy graphic object to get access to the common GraphicManager
200 GraphicObject aDummyObject;
201 GraphicManager& rGrfMgr = aDummyObject.GetGraphicManager();
203 rGrfMgr.SetMaxCacheSize( aCacheOptions.GetGraphicManagerTotalCacheSize() );
204 rGrfMgr.SetMaxObjCacheSize( aCacheOptions.GetGraphicManagerObjectCacheSize(), sal_True );
205 rGrfMgr.SetCacheTimeout( aCacheOptions.GetGraphicManagerObjectReleaseTime() );
207 // OLECache
208 aCacheOptions.SetWriterOLE_Objects( static_cast<long>(aNfOLECache.GetValue()) );
209 aCacheOptions.SetDrawingEngineOLE_Objects( static_cast<long>(aNfOLECache.GetValue()) );
211 if( aQuickLaunchCB.IsChecked() != aQuickLaunchCB.GetSavedValue())
213 rSet.Put(SfxBoolItem(SID_ATTR_QUICKLAUNCHER, aQuickLaunchCB.IsChecked()));
214 bModified = sal_True;
217 return bModified;
220 // -----------------------------------------------------------------------
222 void OfaMemoryOptionsPage::Reset( const SfxItemSet& rSet )
224 SvtCacheOptions aCacheOptions;
225 const SfxPoolItem* pItem;
227 // Undo-Schritte
228 aUndoEdit.SetValue( SvtUndoOptions().GetUndoCount() );
229 aUndoEdit.SaveValue();
231 // GraphicCache
232 long n = aCacheOptions.GetGraphicManagerTotalCacheSize();
233 SetNfGraphicCacheVal( n );
234 SetNfGraphicObjectCacheVal( Min( static_cast<sal_Int32>(GetNfGraphicCacheVal()), aCacheOptions.GetGraphicManagerObjectCacheSize() ) );
236 sal_Int32 nTime = aCacheOptions.GetGraphicManagerObjectReleaseTime();
237 Time aTime( (sal_uInt16)( nTime / 3600 ), (sal_uInt16)( ( nTime % 3600 ) / 60 ), (sal_uInt16)( ( nTime % 3600 ) % 60 ) );
238 aTfGraphicObjectTime.SetTime( aTime );
240 GraphicCacheConfigHdl( &aNfGraphicCache );
242 // OLECache
243 aNfOLECache.SetValue( Max( aCacheOptions.GetWriterOLE_Objects(), aCacheOptions.GetDrawingEngineOLE_Objects() ) );
245 SfxItemState eState = rSet.GetItemState( SID_ATTR_QUICKLAUNCHER, sal_False, &pItem );
246 if ( SFX_ITEM_SET == eState )
247 aQuickLaunchCB.Check( ( (SfxBoolItem*)pItem )->GetValue() );
248 else if ( SFX_ITEM_DISABLED == eState )
250 // quickstart not installed
251 aQuickLaunchFL.Hide();
252 aQuickLaunchCB.Hide();
255 aQuickLaunchCB.SaveValue();
258 // -----------------------------------------------------------------------
260 IMPL_LINK( OfaMemoryOptionsPage, GraphicCacheConfigHdl, NumericField*, EMPTYARG )
262 long n = GetNfGraphicCacheVal();
263 SetNfGraphicObjectCacheMax( n );
264 SetNfGraphicObjectCacheLast( n );
266 if( GetNfGraphicObjectCacheVal() > n )
267 SetNfGraphicObjectCacheVal( n );
269 return 0;