1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optmemory.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
38 #include <svtools/langtab.hxx>
39 #include <svtools/zforlist.hxx>
40 #include <goodies/grfmgr.hxx>
41 #include <svtools/flagitem.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <svtools/lingucfg.hxx>
44 #include <svtools/szitem.hxx>
45 #include <sfx2/viewsh.hxx>
46 #include <sfx2/viewfrm.hxx>
47 #include <sfx2/filedlghelper.hxx>
48 #include <vcl/msgbox.hxx>
49 #include <rtl/math.hxx>
50 #include <svtools/undoopt.hxx>
51 #include <svtools/useroptions.hxx>
52 #include <svtools/cacheoptions.hxx>
53 #include <svtools/fontoptions.hxx>
54 #include <svtools/menuoptions.hxx>
55 #include <svtools/startoptions.hxx>
56 #include <svtools/cjkoptions.hxx>
57 #ifndef INCLUDED_SVTOOLS_MISCPOPT_HXX
58 #include <svtools/miscopt.hxx>
60 #include <svtools/syslocaleoptions.hxx>
61 #include <svtools/helpopt.hxx>
62 #include <unotools/configitem.hxx>
63 #include <sfx2/objsh.hxx>
64 #include <comphelper/types.hxx>
65 #include "unolingu.hxx"
66 #include <svx/langitem.hxx>
67 #include "cuioptgenrl.hxx"
68 #include "optpath.hxx"
69 #include "optsave.hxx"
70 #include <svx/optlingu.hxx>
71 #include <svx/xpool.hxx>
72 #include "dlgutil.hxx"
73 #ifndef _SVX_TAB_AREA_HXX
74 #include "cuitabarea.hxx"
76 #ifndef _SVX_DIALOGS_HRC
77 #include <svx/dialogs.hrc>
81 #include "optmemory.hrc"
82 #include "optmemory.hxx"
83 #include "ofaitem.hxx"
84 #include <svx/dialogs.hrc>
86 #include <svx/dialmgr.hxx>
88 #define CONFIG_LANGUAGES "OfficeLanguages"
90 using namespace ::com::sun::star::uno
;
91 using namespace ::com::sun::star::lang
;
92 using namespace ::com::sun::star::beans
;
93 using namespace ::utl
;
94 using namespace ::rtl
;
95 using namespace ::sfx2
;
98 #define NF2BYTES 104857.6 // 2^20/10, used for aNfGraphicObjectCache-unit -> Byte
99 #define BYTES2NF (1.0/NF2BYTES) // 10/2^20
102 inline long OfaMemoryOptionsPage::GetNfGraphicCacheVal( void ) const
104 return static_cast<long>(aNfGraphicCache
.GetValue() << 20);
107 inline void OfaMemoryOptionsPage::SetNfGraphicCacheVal( long nSizeInBytes
)
109 aNfGraphicCache
.SetValue( nSizeInBytes
>> 20 );
112 long OfaMemoryOptionsPage::GetNfGraphicObjectCacheVal( void ) const
114 return long( ::rtl::math::round( double( aNfGraphicObjectCache
.GetValue() ) * NF2BYTES
) );
117 void OfaMemoryOptionsPage::SetNfGraphicObjectCacheVal( long nSizeInBytes
)
119 aNfGraphicObjectCache
.SetValue( long( ::rtl::math::round( double( nSizeInBytes
) * BYTES2NF
) ) );
122 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheMax( long nSizeInBytes
)
124 aNfGraphicObjectCache
.SetMax( long( double( nSizeInBytes
) * BYTES2NF
) );
127 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheLast( long nSizeInBytes
)
129 aNfGraphicObjectCache
.SetLast( long( double( nSizeInBytes
) * BYTES2NF
) );
132 int OfaMemoryOptionsPage::DeactivatePage( SfxItemSet
* _pSet
)
135 FillItemSet( *_pSet
);
139 // -----------------------------------------------------------------------
141 OfaMemoryOptionsPage::OfaMemoryOptionsPage(Window
* pParent
, const SfxItemSet
& rSet
) :
143 SfxTabPage( pParent
, SVX_RES( OFA_TP_MEMORY
), rSet
),
145 aUndoBox ( this, SVX_RES( GB_UNDO
) ),
146 aUndoText ( this, SVX_RES( FT_UNDO
) ),
147 aUndoEdit ( this, SVX_RES( ED_UNDO
) ),
148 aGbGraphicCache ( this, SVX_RES( GB_GRAPHICCACHE
) ),
149 aFtGraphicCache ( this, SVX_RES( FT_GRAPHICCACHE
) ),
150 aNfGraphicCache ( this, SVX_RES( NF_GRAPHICCACHE
) ),
151 aFtGraphicCacheUnit ( this, SVX_RES( FT_GRAPHICCACHE_UNIT
) ),
152 aFtGraphicObjectCache ( this, SVX_RES( FT_GRAPHICOBJECTCACHE
) ),
153 aNfGraphicObjectCache ( this, SVX_RES( NF_GRAPHICOBJECTCACHE
) ),
154 aFtGraphicObjectCacheUnit(this, SVX_RES( FT_GRAPHICOBJECTCACHE_UNIT
) ),
155 aFtGraphicObjectTime ( this, SVX_RES( FT_GRAPHICOBJECTTIME
) ),
156 aTfGraphicObjectTime ( this, SVX_RES( TF_GRAPHICOBJECTTIME
) ),
157 aFtGraphicObjectTimeUnit( this, SVX_RES( FT_GRAPHICOBJECTTIME_UNIT
) ),
159 aGbOLECache ( this, SVX_RES( GB_OLECACHE
) ),
160 aFtOLECache ( this, SVX_RES( FT_OLECACHE
) ),
161 aNfOLECache ( this, SVX_RES( NF_OLECACHE
) ),
162 aQuickLaunchFL ( this, SVX_RES( FL_QUICKLAUNCH
) ),
163 aQuickLaunchCB ( this, SVX_RES( CB_QUICKLAUNCH
) )//,
166 aQuickLaunchCB
.SetText( SVX_RES( STR_QUICKLAUNCH_UNX
) );
170 //quick launch only available in Win and OS/2
171 #if !defined(WNT) && !defined(OS2) && !defined(ENABLE_GTK)
172 aQuickLaunchFL
.Hide();
173 aQuickLaunchCB
.Hide();
176 aTfGraphicObjectTime
.SetExtFormat( EXTTIMEF_24H_SHORT
);
178 SetExchangeSupport();
180 aNfGraphicCache
.SetModifyHdl( LINK( this, OfaMemoryOptionsPage
, GraphicCacheConfigHdl
) );
183 // -----------------------------------------------------------------------
185 OfaMemoryOptionsPage::~OfaMemoryOptionsPage()
189 // -----------------------------------------------------------------------
191 SfxTabPage
* OfaMemoryOptionsPage::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
193 return new OfaMemoryOptionsPage( pParent
, rAttrSet
);
196 // -----------------------------------------------------------------------
198 BOOL
OfaMemoryOptionsPage::FillItemSet( SfxItemSet
& rSet
)
200 BOOL bModified
= FALSE
;
202 SvtCacheOptions aCacheOptions
;
205 if ( aUndoEdit
.GetText() != aUndoEdit
.GetSavedValue() )
206 SvtUndoOptions().SetUndoCount((UINT16
)aUndoEdit
.GetValue());
209 aCacheOptions
.SetGraphicManagerTotalCacheSize( GetNfGraphicCacheVal() );
210 aCacheOptions
.SetGraphicManagerObjectCacheSize( GetNfGraphicObjectCacheVal() );
212 const Time
aTime( aTfGraphicObjectTime
.GetTime() );
213 aCacheOptions
.SetGraphicManagerObjectReleaseTime( aTime
.GetSec() + aTime
.GetMin() * 60 + aTime
.GetHour() * 3600 );
215 // create a dummy graphic object to get access to the common GraphicManager
216 GraphicObject aDummyObject
;
217 GraphicManager
& rGrfMgr
= aDummyObject
.GetGraphicManager();
219 rGrfMgr
.SetMaxCacheSize( aCacheOptions
.GetGraphicManagerTotalCacheSize() );
220 rGrfMgr
.SetMaxObjCacheSize( aCacheOptions
.GetGraphicManagerObjectCacheSize(), TRUE
);
221 rGrfMgr
.SetCacheTimeout( aCacheOptions
.GetGraphicManagerObjectReleaseTime() );
224 aCacheOptions
.SetWriterOLE_Objects( static_cast<long>(aNfOLECache
.GetValue()) );
225 aCacheOptions
.SetDrawingEngineOLE_Objects( static_cast<long>(aNfOLECache
.GetValue()) );
227 if( aQuickLaunchCB
.IsChecked() != aQuickLaunchCB
.GetSavedValue())
229 rSet
.Put(SfxBoolItem(SID_ATTR_QUICKLAUNCHER
, aQuickLaunchCB
.IsChecked()));
236 // -----------------------------------------------------------------------
238 void OfaMemoryOptionsPage::Reset( const SfxItemSet
& rSet
)
240 SvtCacheOptions aCacheOptions
;
241 const SfxPoolItem
* pItem
;
244 aUndoEdit
.SetValue( SvtUndoOptions().GetUndoCount() );
245 aUndoEdit
.SaveValue();
248 long n
= aCacheOptions
.GetGraphicManagerTotalCacheSize();
249 SetNfGraphicCacheVal( n
);
250 SetNfGraphicObjectCacheVal( Min( static_cast<sal_Int32
>(GetNfGraphicCacheVal()), aCacheOptions
.GetGraphicManagerObjectCacheSize() ) );
252 sal_Int32 nTime
= aCacheOptions
.GetGraphicManagerObjectReleaseTime();
253 Time
aTime( (USHORT
)( nTime
/ 3600 ), (USHORT
)( ( nTime
% 3600 ) / 60 ), (USHORT
)( ( nTime
% 3600 ) % 60 ) );
254 aTfGraphicObjectTime
.SetTime( aTime
);
256 GraphicCacheConfigHdl( &aNfGraphicCache
);
259 aNfOLECache
.SetValue( Max( aCacheOptions
.GetWriterOLE_Objects(), aCacheOptions
.GetDrawingEngineOLE_Objects() ) );
261 SfxItemState eState
= rSet
.GetItemState( SID_ATTR_QUICKLAUNCHER
, FALSE
, &pItem
);
262 if ( SFX_ITEM_SET
== eState
)
263 aQuickLaunchCB
.Check( ( (SfxBoolItem
*)pItem
)->GetValue() );
264 else if ( SFX_ITEM_DISABLED
== eState
)
266 // quickstart not installed
267 aQuickLaunchFL
.Hide();
268 aQuickLaunchCB
.Hide();
271 aQuickLaunchCB
.SaveValue();
274 // -----------------------------------------------------------------------
276 IMPL_LINK( OfaMemoryOptionsPage
, GraphicCacheConfigHdl
, NumericField
*, EMPTYARG
)
278 long n
= GetNfGraphicCacheVal();
279 SetNfGraphicObjectCacheMax( n
);
280 SetNfGraphicObjectCacheLast( n
);
282 if( GetNfGraphicObjectCacheVal() > n
)
283 SetNfGraphicObjectCacheVal( n
);