xref: /aoo41x/main/cui/source/options/optmemory.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
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>
71 
72 #define CONFIG_LANGUAGES "OfficeLanguages"
73 
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;
80 
81 
82 #define NF2BYTES		104857.6						// 2^20/10, used for aNfGraphicObjectCache-unit -> Byte
83 #define BYTES2NF		(1.0/NF2BYTES)					// 10/2^20
84 
85 
86 inline long OfaMemoryOptionsPage::GetNfGraphicCacheVal( void ) const
87 {
88 	return static_cast<long>(aNfGraphicCache.GetValue() << 20);
89 }
90 
91 inline void OfaMemoryOptionsPage::SetNfGraphicCacheVal( long nSizeInBytes )
92 {
93 	aNfGraphicCache.SetValue( nSizeInBytes >> 20 );
94 }
95 
96 long OfaMemoryOptionsPage::GetNfGraphicObjectCacheVal( void ) const
97 {
98 	return long( ::rtl::math::round( double( aNfGraphicObjectCache.GetValue() ) * NF2BYTES ) );
99 }
100 
101 void OfaMemoryOptionsPage::SetNfGraphicObjectCacheVal( long nSizeInBytes )
102 {
103 	aNfGraphicObjectCache.SetValue( long( ::rtl::math::round( double( nSizeInBytes ) * BYTES2NF ) ) );
104 }
105 
106 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheMax( long nSizeInBytes )
107 {
108     aNfGraphicObjectCache.SetMax( long( double( nSizeInBytes ) * BYTES2NF ) );
109 }
110 
111 inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheLast( long nSizeInBytes )
112 {
113     aNfGraphicObjectCache.SetLast( long( double( nSizeInBytes ) * BYTES2NF ) );
114 }
115 
116 int OfaMemoryOptionsPage::DeactivatePage( SfxItemSet* _pSet )
117 {
118     if ( _pSet )
119         FillItemSet( *_pSet );
120 	return LEAVE_PAGE;
121 }
122 
123 // -----------------------------------------------------------------------
124 
125 OfaMemoryOptionsPage::OfaMemoryOptionsPage(Window* pParent, const SfxItemSet& rSet ) :
126 
127 	SfxTabPage( pParent, CUI_RES( OFA_TP_MEMORY ), rSet ),
128 
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     ) ),
142 
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 ) )//,
148 {
149 #if defined(UNX)
150 	aQuickLaunchCB.SetText( CUI_RES( STR_QUICKLAUNCH_UNX ) );
151 #endif
152 	FreeResource();
153 
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
159 
160 	aTfGraphicObjectTime.SetExtFormat( EXTTIMEF_24H_SHORT );
161 
162     SetExchangeSupport();
163 
164 	aNfGraphicCache.SetModifyHdl( LINK( this, OfaMemoryOptionsPage, GraphicCacheConfigHdl ) );
165 }
166 
167 // -----------------------------------------------------------------------
168 
169 OfaMemoryOptionsPage::~OfaMemoryOptionsPage()
170 {
171 }
172 
173 // -----------------------------------------------------------------------
174 
175 SfxTabPage*	OfaMemoryOptionsPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
176 {
177 	return new OfaMemoryOptionsPage( pParent, rAttrSet );
178 }
179 
180 // -----------------------------------------------------------------------
181 
182 sal_Bool OfaMemoryOptionsPage::FillItemSet( SfxItemSet& rSet )
183 {
184 	sal_Bool bModified = sal_False;
185 
186     SvtCacheOptions aCacheOptions;
187 
188     // Undo-Schritte
189 	if ( aUndoEdit.GetText() != aUndoEdit.GetSavedValue() )
190         SvtUndoOptions().SetUndoCount((sal_uInt16)aUndoEdit.GetValue());
191 
192     // GraphicCache
193     aCacheOptions.SetGraphicManagerTotalCacheSize( GetNfGraphicCacheVal() );
194     aCacheOptions.SetGraphicManagerObjectCacheSize( GetNfGraphicObjectCacheVal() );
195 
196    	const Time aTime( aTfGraphicObjectTime.GetTime() );
197     aCacheOptions.SetGraphicManagerObjectReleaseTime( aTime.GetSec() + aTime.GetMin() * 60 + aTime.GetHour() * 3600 );
198 
199     // create a dummy graphic object to get access to the common GraphicManager
200     GraphicObject       aDummyObject;
201     GraphicManager&     rGrfMgr = aDummyObject.GetGraphicManager();
202 
203     rGrfMgr.SetMaxCacheSize( aCacheOptions.GetGraphicManagerTotalCacheSize() );
204     rGrfMgr.SetMaxObjCacheSize( aCacheOptions.GetGraphicManagerObjectCacheSize(), sal_True );
205     rGrfMgr.SetCacheTimeout( aCacheOptions.GetGraphicManagerObjectReleaseTime() );
206 
207     // OLECache
208     aCacheOptions.SetWriterOLE_Objects( static_cast<long>(aNfOLECache.GetValue()) );
209     aCacheOptions.SetDrawingEngineOLE_Objects( static_cast<long>(aNfOLECache.GetValue()) );
210 
211     if( aQuickLaunchCB.IsChecked() != aQuickLaunchCB.GetSavedValue())
212     {
213         rSet.Put(SfxBoolItem(SID_ATTR_QUICKLAUNCHER, aQuickLaunchCB.IsChecked()));
214         bModified = sal_True;
215     }
216 
217 	return bModified;
218 }
219 
220 // -----------------------------------------------------------------------
221 
222 void OfaMemoryOptionsPage::Reset( const SfxItemSet& rSet )
223 {
224     SvtCacheOptions     aCacheOptions;
225 	const SfxPoolItem*  pItem;
226 
227     // Undo-Schritte
228     aUndoEdit.SetValue( SvtUndoOptions().GetUndoCount() );
229     aUndoEdit.SaveValue();
230 
231     // GraphicCache
232 	long	n = aCacheOptions.GetGraphicManagerTotalCacheSize();
233 	SetNfGraphicCacheVal( n );
234 	SetNfGraphicObjectCacheVal( Min( static_cast<sal_Int32>(GetNfGraphicCacheVal()), aCacheOptions.GetGraphicManagerObjectCacheSize() ) );
235 
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 );
239 
240     GraphicCacheConfigHdl( &aNfGraphicCache );
241 
242     // OLECache
243     aNfOLECache.SetValue( Max( aCacheOptions.GetWriterOLE_Objects(), aCacheOptions.GetDrawingEngineOLE_Objects() ) );
244 
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 )
249     {
250         // quickstart not installed
251         aQuickLaunchFL.Hide();
252         aQuickLaunchCB.Hide();
253     }
254 
255     aQuickLaunchCB.SaveValue();
256 }
257 
258 // -----------------------------------------------------------------------
259 
260 IMPL_LINK( OfaMemoryOptionsPage, GraphicCacheConfigHdl, NumericField*, EMPTYARG )
261 {
262 	long	n = GetNfGraphicCacheVal();
263 	SetNfGraphicObjectCacheMax( n );
264 	SetNfGraphicObjectCacheLast( n );
265 
266 	if( GetNfGraphicObjectCacheVal() > n )
267 		SetNfGraphicObjectCacheVal( n );
268 
269     return 0;
270 }
271 
272