xref: /aoo42x/main/cui/source/options/optmemory.cxx (revision 2ee96f1c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 #include <svtools/langtab.hxx>
27 #include <svl/zforlist.hxx>
28 #include <svtools/grfmgr.hxx>
29 #include <svl/flagitem.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <unotools/lingucfg.hxx>
32 #include <svl/szitem.hxx>
33 #include <sfx2/viewsh.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/filedlghelper.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <rtl/math.hxx>
38 #include <unotools/undoopt.hxx>
39 #include <unotools/useroptions.hxx>
40 #include <unotools/cacheoptions.hxx>
41 #include <unotools/fontoptions.hxx>
42 #include <svtools/menuoptions.hxx>
43 #include <unotools/startoptions.hxx>
44 #include <svl/cjkoptions.hxx>
45 #include <svtools/miscopt.hxx>
46 #include <unotools/syslocaleoptions.hxx>
47 #include <svtools/helpopt.hxx>
48 #include <unotools/configitem.hxx>
49 #include <sfx2/objsh.hxx>
50 #include <comphelper/types.hxx>
51 #include <editeng/unolingu.hxx>
52 #include <editeng/langitem.hxx>
53 #include "cuioptgenrl.hxx"
54 #include "optpath.hxx"
55 #include "optsave.hxx"
56 #include "optlingu.hxx"
57 #include <svx/xpool.hxx>
58 #include <svx/dlgutil.hxx>
59 #include "cuitabarea.hxx"
60 #include <cuires.hrc>
61 #include "optmemory.hrc"
62 #include "optmemory.hxx"
63 #include <svx/ofaitem.hxx>
64 #include <cuires.hrc>
65 #include "helpid.hrc"
66 #include <dialmgr.hxx>
67 
68 #define CONFIG_LANGUAGES "OfficeLanguages"
69 
70 using namespace ::com::sun::star::uno;
71 using namespace ::com::sun::star::lang;
72 using namespace ::com::sun::star::beans;
73 using namespace ::utl;
74 using namespace ::rtl;
75 using namespace ::sfx2;
76 
77 
78 #define NF2BYTES		104857.6						// 2^20/10, used for aNfGraphicObjectCache-unit -> Byte
79 #define BYTES2NF		(1.0/NF2BYTES)					// 10/2^20
80 
81 
GetNfGraphicCacheVal(void) const82 inline long OfaMemoryOptionsPage::GetNfGraphicCacheVal( void ) const
83 {
84 	return static_cast<long>(aNfGraphicCache.GetValue() << 20);
85 }
86 
SetNfGraphicCacheVal(long nSizeInBytes)87 inline void OfaMemoryOptionsPage::SetNfGraphicCacheVal( long nSizeInBytes )
88 {
89 	aNfGraphicCache.SetValue( nSizeInBytes >> 20 );
90 }
91 
GetNfGraphicObjectCacheVal(void) const92 long OfaMemoryOptionsPage::GetNfGraphicObjectCacheVal( void ) const
93 {
94 	return long( ::rtl::math::round( double( aNfGraphicObjectCache.GetValue() ) * NF2BYTES ) );
95 }
96 
SetNfGraphicObjectCacheVal(long nSizeInBytes)97 void OfaMemoryOptionsPage::SetNfGraphicObjectCacheVal( long nSizeInBytes )
98 {
99 	aNfGraphicObjectCache.SetValue( long( ::rtl::math::round( double( nSizeInBytes ) * BYTES2NF ) ) );
100 }
101 
SetNfGraphicObjectCacheMax(long nSizeInBytes)102 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheMax( long nSizeInBytes )
103 {
104     aNfGraphicObjectCache.SetMax( long( double( nSizeInBytes ) * BYTES2NF ) );
105 }
106 
SetNfGraphicObjectCacheLast(long nSizeInBytes)107 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheLast( long nSizeInBytes )
108 {
109     aNfGraphicObjectCache.SetLast( long( double( nSizeInBytes ) * BYTES2NF ) );
110 }
111 
DeactivatePage(SfxItemSet * _pSet)112 int OfaMemoryOptionsPage::DeactivatePage( SfxItemSet* _pSet )
113 {
114     if ( _pSet )
115         FillItemSet( *_pSet );
116 	return LEAVE_PAGE;
117 }
118 
119 // -----------------------------------------------------------------------
120 
OfaMemoryOptionsPage(Window * pParent,const SfxItemSet & rSet)121 OfaMemoryOptionsPage::OfaMemoryOptionsPage(Window* pParent, const SfxItemSet& rSet ) :
122 
123 	SfxTabPage( pParent, CUI_RES( OFA_TP_MEMORY ), rSet ),
124 
125     aUndoBox                ( this, CUI_RES( GB_UNDO ) ),
126 	aUndoText			    ( this,	CUI_RES( FT_UNDO ) ),
127 	aUndoEdit			    ( this,	CUI_RES( ED_UNDO ) ),
128     aGbGraphicCache         ( this, CUI_RES( GB_GRAPHICCACHE ) ),
129 	aFtGraphicCache         ( this, CUI_RES( FT_GRAPHICCACHE ) ),
130     aNfGraphicCache         ( this, CUI_RES( NF_GRAPHICCACHE ) ),
131     aFtGraphicCacheUnit     ( this, CUI_RES( FT_GRAPHICCACHE_UNIT         ) ),
132     aFtGraphicObjectCache   ( this, CUI_RES( FT_GRAPHICOBJECTCACHE ) ),
133     aNfGraphicObjectCache   ( this, CUI_RES( NF_GRAPHICOBJECTCACHE ) ),
134     aFtGraphicObjectCacheUnit(this, CUI_RES( FT_GRAPHICOBJECTCACHE_UNIT ) ),
135     aFtGraphicObjectTime    ( this, CUI_RES( FT_GRAPHICOBJECTTIME ) ),
136     aTfGraphicObjectTime    ( this, CUI_RES( TF_GRAPHICOBJECTTIME ) ),
137     aFtGraphicObjectTimeUnit( this, CUI_RES( FT_GRAPHICOBJECTTIME_UNIT     ) ),
138 
139     aGbOLECache             ( this, CUI_RES( GB_OLECACHE ) ),
140 	aFtOLECache             ( this, CUI_RES( FT_OLECACHE ) ),
141     aNfOLECache             ( this, CUI_RES( NF_OLECACHE ) ),
142     aQuickLaunchFL          ( this, CUI_RES( FL_QUICKLAUNCH ) ),
143     aQuickLaunchCB          ( this, CUI_RES( CB_QUICKLAUNCH ) )//,
144 {
145 #if defined(UNX)
146 	aQuickLaunchCB.SetText( CUI_RES( STR_QUICKLAUNCH_UNX ) );
147 #endif
148 	FreeResource();
149 
150     //quick launch only available in Win and OS/2
151 #if !defined(WNT) && !defined(OS2) && !defined(ENABLE_GTK)
152     aQuickLaunchFL.Hide();
153     aQuickLaunchCB.Hide();
154 #endif
155 
156 	aTfGraphicObjectTime.SetExtFormat( EXTTIMEF_24H_SHORT );
157 
158     SetExchangeSupport();
159 
160 	aNfGraphicCache.SetModifyHdl( LINK( this, OfaMemoryOptionsPage, GraphicCacheConfigHdl ) );
161 }
162 
163 // -----------------------------------------------------------------------
164 
~OfaMemoryOptionsPage()165 OfaMemoryOptionsPage::~OfaMemoryOptionsPage()
166 {
167 }
168 
169 // -----------------------------------------------------------------------
170 
Create(Window * pParent,const SfxItemSet & rAttrSet)171 SfxTabPage*	OfaMemoryOptionsPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
172 {
173 	return new OfaMemoryOptionsPage( pParent, rAttrSet );
174 }
175 
176 // -----------------------------------------------------------------------
177 
FillItemSet(SfxItemSet & rSet)178 sal_Bool OfaMemoryOptionsPage::FillItemSet( SfxItemSet& rSet )
179 {
180 	sal_Bool bModified = sal_False;
181 
182     SvtCacheOptions aCacheOptions;
183 
184     // Undo-Schritte
185 	if ( aUndoEdit.GetText() != aUndoEdit.GetSavedValue() )
186         SvtUndoOptions().SetUndoCount((sal_uInt16)aUndoEdit.GetValue());
187 
188     // GraphicCache
189     aCacheOptions.SetGraphicManagerTotalCacheSize( GetNfGraphicCacheVal() );
190     aCacheOptions.SetGraphicManagerObjectCacheSize( GetNfGraphicObjectCacheVal() );
191 
192    	const Time aTime( aTfGraphicObjectTime.GetTime() );
193     aCacheOptions.SetGraphicManagerObjectReleaseTime( aTime.GetSec() + aTime.GetMin() * 60 + aTime.GetHour() * 3600 );
194 
195     // create a dummy graphic object to get access to the common GraphicManager
196     GraphicObject       aDummyObject;
197     GraphicManager&     rGrfMgr = aDummyObject.GetGraphicManager();
198 
199     rGrfMgr.SetMaxCacheSize( aCacheOptions.GetGraphicManagerTotalCacheSize() );
200     rGrfMgr.SetMaxObjCacheSize( aCacheOptions.GetGraphicManagerObjectCacheSize(), sal_True );
201     rGrfMgr.SetCacheTimeout( aCacheOptions.GetGraphicManagerObjectReleaseTime() );
202 
203     // OLECache
204     aCacheOptions.SetWriterOLE_Objects( static_cast<long>(aNfOLECache.GetValue()) );
205     aCacheOptions.SetDrawingEngineOLE_Objects( static_cast<long>(aNfOLECache.GetValue()) );
206 
207     if( aQuickLaunchCB.IsChecked() != aQuickLaunchCB.GetSavedValue())
208     {
209         rSet.Put(SfxBoolItem(SID_ATTR_QUICKLAUNCHER, aQuickLaunchCB.IsChecked()));
210         bModified = sal_True;
211     }
212 
213 	return bModified;
214 }
215 
216 // -----------------------------------------------------------------------
217 
Reset(const SfxItemSet & rSet)218 void OfaMemoryOptionsPage::Reset( const SfxItemSet& rSet )
219 {
220     SvtCacheOptions     aCacheOptions;
221 	const SfxPoolItem*  pItem;
222 
223     // Undo-Schritte
224     aUndoEdit.SetValue( SvtUndoOptions().GetUndoCount() );
225     aUndoEdit.SaveValue();
226 
227     // GraphicCache
228 	long	n = aCacheOptions.GetGraphicManagerTotalCacheSize();
229 	SetNfGraphicCacheVal( n );
230 	SetNfGraphicObjectCacheVal( Min( static_cast<sal_Int32>(GetNfGraphicCacheVal()), aCacheOptions.GetGraphicManagerObjectCacheSize() ) );
231 
232 	sal_Int32 nTime = aCacheOptions.GetGraphicManagerObjectReleaseTime();
233     Time aTime( (sal_uInt16)( nTime / 3600 ), (sal_uInt16)( ( nTime % 3600 ) / 60 ), (sal_uInt16)( ( nTime % 3600 ) % 60 ) );
234     aTfGraphicObjectTime.SetTime( aTime );
235 
236     GraphicCacheConfigHdl( &aNfGraphicCache );
237 
238     // OLECache
239     aNfOLECache.SetValue( Max( aCacheOptions.GetWriterOLE_Objects(), aCacheOptions.GetDrawingEngineOLE_Objects() ) );
240 
241     SfxItemState eState = rSet.GetItemState( SID_ATTR_QUICKLAUNCHER, sal_False, &pItem );
242     if ( SFX_ITEM_SET == eState )
243         aQuickLaunchCB.Check( ( (SfxBoolItem*)pItem )->GetValue() );
244     else if ( SFX_ITEM_DISABLED == eState )
245     {
246         // quickstart not installed
247         aQuickLaunchFL.Hide();
248         aQuickLaunchCB.Hide();
249     }
250 
251     aQuickLaunchCB.SaveValue();
252 }
253 
254 // -----------------------------------------------------------------------
255 
IMPL_LINK(OfaMemoryOptionsPage,GraphicCacheConfigHdl,NumericField *,EMPTYARG)256 IMPL_LINK( OfaMemoryOptionsPage, GraphicCacheConfigHdl, NumericField*, EMPTYARG )
257 {
258 	long	n = GetNfGraphicCacheVal();
259 	SetNfGraphicObjectCacheMax( n );
260 	SetNfGraphicObjectCacheLast( n );
261 
262 	if( GetNfGraphicObjectCacheVal() > n )
263 		SetNfGraphicObjectCacheVal( n );
264 
265     return 0;
266 }
267 
268