1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10b3f79822SAndrew Rist *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19b3f79822SAndrew Rist *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir //------------------------------------------------------------------
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "solveroptions.hxx"
30cdf0e10cSrcweir #include "solveroptions.hrc"
31cdf0e10cSrcweir #include "scresid.hxx"
32cdf0e10cSrcweir #include "global.hxx"
33cdf0e10cSrcweir #include "miscuno.hxx"
34cdf0e10cSrcweir #include "solverutil.hxx"
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <rtl/math.hxx>
37cdf0e10cSrcweir #include <vcl/msgbox.hxx>
38cdf0e10cSrcweir #include <unotools/collatorwrapper.hxx>
39cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include <algorithm>
42cdf0e10cSrcweir
43cdf0e10cSrcweir #include <com/sun/star/sheet/Solver.hpp>
44cdf0e10cSrcweir #include <com/sun/star/sheet/XSolverDescription.hpp>
45cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
46cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
47cdf0e10cSrcweir
48cdf0e10cSrcweir using namespace com::sun::star;
49cdf0e10cSrcweir
50cdf0e10cSrcweir //==================================================================
51cdf0e10cSrcweir
52cdf0e10cSrcweir /// Helper for sorting properties
53cdf0e10cSrcweir struct ScSolverOptionsEntry
54cdf0e10cSrcweir {
55cdf0e10cSrcweir sal_Int32 nPosition;
56cdf0e10cSrcweir rtl::OUString aDescription;
57cdf0e10cSrcweir
ScSolverOptionsEntryScSolverOptionsEntry58cdf0e10cSrcweir ScSolverOptionsEntry() : nPosition(0) {}
59cdf0e10cSrcweir
operator <ScSolverOptionsEntry60cdf0e10cSrcweir bool operator< (const ScSolverOptionsEntry& rOther) const
61cdf0e10cSrcweir {
62cdf0e10cSrcweir return ( ScGlobal::GetCollator()->compareString( aDescription, rOther.aDescription ) == COMPARE_LESS );
63cdf0e10cSrcweir }
64cdf0e10cSrcweir };
65cdf0e10cSrcweir
66cdf0e10cSrcweir //------------------------------------------------------------------
67cdf0e10cSrcweir
68cdf0e10cSrcweir class ScSolverOptionsString : public SvLBoxString
69cdf0e10cSrcweir {
70cdf0e10cSrcweir bool mbIsDouble;
71cdf0e10cSrcweir double mfDoubleValue;
72cdf0e10cSrcweir sal_Int32 mnIntValue;
73cdf0e10cSrcweir
74cdf0e10cSrcweir public:
ScSolverOptionsString(SvLBoxEntry * pEntry,sal_uInt16 nFlags,const String & rStr)75cdf0e10cSrcweir ScSolverOptionsString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& rStr ) :
76cdf0e10cSrcweir SvLBoxString( pEntry, nFlags, rStr ),
77cdf0e10cSrcweir mbIsDouble( false ),
78cdf0e10cSrcweir mfDoubleValue( 0.0 ),
79cdf0e10cSrcweir mnIntValue( 0 ) {}
80cdf0e10cSrcweir
IsDouble() const81cdf0e10cSrcweir bool IsDouble() const { return mbIsDouble; }
GetDoubleValue() const82cdf0e10cSrcweir double GetDoubleValue() const { return mfDoubleValue; }
GetIntValue() const83cdf0e10cSrcweir sal_Int32 GetIntValue() const { return mnIntValue; }
84cdf0e10cSrcweir
SetDoubleValue(double fNew)85cdf0e10cSrcweir void SetDoubleValue( double fNew ) { mbIsDouble = true; mfDoubleValue = fNew; }
SetIntValue(sal_Int32 nNew)86cdf0e10cSrcweir void SetIntValue( sal_Int32 nNew ) { mbIsDouble = false; mnIntValue = nNew; }
87*0deba7fbSSteve Yin // MT: Commented out SV_ITEM_ID_EXTENDRLBOXSTRING and GetExtendText() in svlbitem.hxx - needed?
88*0deba7fbSSteve Yin // virtual USHORT IsA() {return SV_ITEM_ID_EXTENDRLBOXSTRING;}
89*0deba7fbSSteve Yin // virtual XubString GetExtendText() const;
90cdf0e10cSrcweir virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry );
91cdf0e10cSrcweir };
92cdf0e10cSrcweir
93*0deba7fbSSteve Yin // MT: Commented out SV_ITEM_ID_EXTENDRLBOXSTRING and GetExtendText() in svlbitem.hxx - needed?
94*0deba7fbSSteve Yin /*
95*0deba7fbSSteve Yin XubString ScSolverOptionsString::GetExtendText() const
96*0deba7fbSSteve Yin {
97*0deba7fbSSteve Yin String aNormalStr( GetText() );
98*0deba7fbSSteve Yin aNormalStr.Append( (sal_Unicode) ':' );
99*0deba7fbSSteve Yin String sTxt( ' ' );
100*0deba7fbSSteve Yin if ( mbIsDouble )
101*0deba7fbSSteve Yin sTxt += (String)rtl::math::doubleToUString( mfDoubleValue,
102*0deba7fbSSteve Yin rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
103*0deba7fbSSteve Yin ScGlobal::GetpLocaleData()->getNumDecimalSep().GetChar(0), true );
104*0deba7fbSSteve Yin else
105*0deba7fbSSteve Yin sTxt += String::CreateFromInt32( mnIntValue );
106*0deba7fbSSteve Yin aNormalStr.Append(sTxt);
107*0deba7fbSSteve Yin return aNormalStr;
108*0deba7fbSSteve Yin }
109*0deba7fbSSteve Yin */
110*0deba7fbSSteve Yin
Paint(const Point & rPos,SvLBox & rDev,sal_uInt16,SvLBoxEntry *)111cdf0e10cSrcweir void ScSolverOptionsString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16, SvLBoxEntry* /* pEntry */ )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir //! move position? (SvxLinguTabPage: aPos.X() += 20)
114cdf0e10cSrcweir String aNormalStr( GetText() );
115cdf0e10cSrcweir aNormalStr.Append( (sal_Unicode) ':' );
116cdf0e10cSrcweir rDev.DrawText( rPos, aNormalStr );
117cdf0e10cSrcweir
118cdf0e10cSrcweir Point aNewPos( rPos );
119cdf0e10cSrcweir aNewPos.X() += rDev.GetTextWidth( aNormalStr );
120cdf0e10cSrcweir Font aOldFont( rDev.GetFont() );
121cdf0e10cSrcweir Font aFont( aOldFont );
122cdf0e10cSrcweir aFont.SetWeight( WEIGHT_BOLD );
123cdf0e10cSrcweir
124cdf0e10cSrcweir String sTxt( ' ' );
125cdf0e10cSrcweir if ( mbIsDouble )
126cdf0e10cSrcweir sTxt += (String)rtl::math::doubleToUString( mfDoubleValue,
127cdf0e10cSrcweir rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
128cdf0e10cSrcweir ScGlobal::GetpLocaleData()->getNumDecimalSep().GetChar(0), true );
129cdf0e10cSrcweir else
130cdf0e10cSrcweir sTxt += String::CreateFromInt32( mnIntValue );
131cdf0e10cSrcweir rDev.SetFont( aFont );
132cdf0e10cSrcweir rDev.DrawText( aNewPos, sTxt );
133cdf0e10cSrcweir
134cdf0e10cSrcweir rDev.SetFont( aOldFont );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir //------------------------------------------------------------------
138cdf0e10cSrcweir
ScSolverOptionsDialog(Window * pParent,const uno::Sequence<rtl::OUString> & rImplNames,const uno::Sequence<rtl::OUString> & rDescriptions,const String & rEngine,const uno::Sequence<beans::PropertyValue> & rProperties)139cdf0e10cSrcweir ScSolverOptionsDialog::ScSolverOptionsDialog( Window* pParent,
140cdf0e10cSrcweir const uno::Sequence<rtl::OUString>& rImplNames,
141cdf0e10cSrcweir const uno::Sequence<rtl::OUString>& rDescriptions,
142cdf0e10cSrcweir const String& rEngine,
143cdf0e10cSrcweir const uno::Sequence<beans::PropertyValue>& rProperties )
144cdf0e10cSrcweir : ModalDialog( pParent, ScResId( RID_SCDLG_SOLVEROPTIONS ) ),
145cdf0e10cSrcweir maFtEngine ( this, ScResId( FT_ENGINE ) ),
146cdf0e10cSrcweir maLbEngine ( this, ScResId( LB_ENGINE ) ),
147cdf0e10cSrcweir maFtSettings ( this, ScResId( FT_SETTINGS ) ),
148cdf0e10cSrcweir maLbSettings ( this, ScResId( LB_SETTINGS ) ),
149cdf0e10cSrcweir maBtnEdit ( this, ScResId( BTN_EDIT ) ),
150cdf0e10cSrcweir maFlButtons ( this, ScResId( FL_BUTTONS ) ),
151cdf0e10cSrcweir maBtnHelp ( this, ScResId( BTN_HELP ) ),
152cdf0e10cSrcweir maBtnOk ( this, ScResId( BTN_OK ) ),
153cdf0e10cSrcweir maBtnCancel ( this, ScResId( BTN_CANCEL ) ),
154cdf0e10cSrcweir mpCheckButtonData( NULL ),
155cdf0e10cSrcweir maImplNames( rImplNames ),
156cdf0e10cSrcweir maDescriptions( rDescriptions ),
157cdf0e10cSrcweir maEngine( rEngine ),
158cdf0e10cSrcweir maProperties( rProperties )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir maLbEngine.SetSelectHdl( LINK( this, ScSolverOptionsDialog, EngineSelectHdl ) );
161cdf0e10cSrcweir
162cdf0e10cSrcweir maBtnEdit.SetClickHdl( LINK( this, ScSolverOptionsDialog, ButtonHdl ) );
163cdf0e10cSrcweir
164cdf0e10cSrcweir maLbSettings.SetStyle( maLbSettings.GetStyle()|WB_CLIPCHILDREN|WB_FORCE_MAKEVISIBLE );
165cdf0e10cSrcweir maLbSettings.SetHelpId( HID_SC_SOLVEROPTIONS_LB );
166cdf0e10cSrcweir maLbSettings.SetHighlightRange();
167cdf0e10cSrcweir
168cdf0e10cSrcweir maLbSettings.SetSelectHdl( LINK( this, ScSolverOptionsDialog, SettingsSelHdl ) );
169cdf0e10cSrcweir maLbSettings.SetDoubleClickHdl( LINK( this, ScSolverOptionsDialog, SettingsDoubleClickHdl ) );
170cdf0e10cSrcweir
171cdf0e10cSrcweir sal_Int32 nSelect = -1;
172cdf0e10cSrcweir sal_Int32 nImplCount = maImplNames.getLength();
173cdf0e10cSrcweir for (sal_Int32 nImpl=0; nImpl<nImplCount; ++nImpl)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir String aImplName( maImplNames[nImpl] );
176cdf0e10cSrcweir String aDescription( maDescriptions[nImpl] ); // user-visible descriptions in list box
177cdf0e10cSrcweir maLbEngine.InsertEntry( aDescription );
178cdf0e10cSrcweir if ( aImplName == maEngine )
179cdf0e10cSrcweir nSelect = nImpl;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir if ( nSelect < 0 ) // no (valid) engine given
182cdf0e10cSrcweir {
183cdf0e10cSrcweir if ( nImplCount > 0 )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir maEngine = maImplNames[0]; // use first implementation
186cdf0e10cSrcweir nSelect = 0;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir else
189cdf0e10cSrcweir maEngine.Erase();
190cdf0e10cSrcweir maProperties.realloc(0); // don't use options from different engine
191cdf0e10cSrcweir }
192cdf0e10cSrcweir if ( nSelect >= 0 ) // select in list box
193cdf0e10cSrcweir maLbEngine.SelectEntryPos( static_cast<sal_uInt16>(nSelect) );
194cdf0e10cSrcweir
195cdf0e10cSrcweir if ( !maProperties.getLength() )
196cdf0e10cSrcweir ReadFromComponent(); // fill maProperties from component (using maEngine)
197cdf0e10cSrcweir FillListBox(); // using maProperties
198cdf0e10cSrcweir
199cdf0e10cSrcweir FreeResource();
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
~ScSolverOptionsDialog()202cdf0e10cSrcweir ScSolverOptionsDialog::~ScSolverOptionsDialog()
203cdf0e10cSrcweir {
204cdf0e10cSrcweir delete mpCheckButtonData;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
GetEngine() const207cdf0e10cSrcweir const String& ScSolverOptionsDialog::GetEngine() const
208cdf0e10cSrcweir {
209cdf0e10cSrcweir return maEngine; // already updated in selection handler
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
GetProperties()212cdf0e10cSrcweir const uno::Sequence<beans::PropertyValue>& ScSolverOptionsDialog::GetProperties()
213cdf0e10cSrcweir {
214cdf0e10cSrcweir // update maProperties from list box content
215cdf0e10cSrcweir // order of entries in list box and maProperties is the same
216cdf0e10cSrcweir sal_Int32 nEntryCount = maProperties.getLength();
217cdf0e10cSrcweir SvLBoxTreeList* pModel = maLbSettings.GetModel();
218cdf0e10cSrcweir if ( nEntryCount == (sal_Int32)pModel->GetEntryCount() )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir for (sal_Int32 nEntryPos=0; nEntryPos<nEntryCount; ++nEntryPos)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir uno::Any& rValue = maProperties[nEntryPos].Value;
223cdf0e10cSrcweir SvLBoxEntry* pEntry = pModel->GetEntry(nEntryPos);
224cdf0e10cSrcweir
225cdf0e10cSrcweir bool bHasData = false;
226cdf0e10cSrcweir sal_uInt16 nItemCount = pEntry->ItemCount();
227cdf0e10cSrcweir for (sal_uInt16 nItemPos=0; nItemPos<nItemCount && !bHasData; ++nItemPos)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir SvLBoxItem* pItem = pEntry->GetItem( nItemPos );
230cdf0e10cSrcweir ScSolverOptionsString* pStringItem = dynamic_cast<ScSolverOptionsString*>(pItem);
231cdf0e10cSrcweir if ( pStringItem )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir if ( pStringItem->IsDouble() )
234cdf0e10cSrcweir rValue <<= pStringItem->GetDoubleValue();
235cdf0e10cSrcweir else
236cdf0e10cSrcweir rValue <<= pStringItem->GetIntValue();
237cdf0e10cSrcweir bHasData = true;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir if ( !bHasData )
241cdf0e10cSrcweir ScUnoHelpFunctions::SetBoolInAny( rValue,
242cdf0e10cSrcweir maLbSettings.GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
243cdf0e10cSrcweir }
244cdf0e10cSrcweir }
245cdf0e10cSrcweir else
246cdf0e10cSrcweir {
247cdf0e10cSrcweir DBG_ERRORFILE( "wrong count" );
248cdf0e10cSrcweir }
249cdf0e10cSrcweir
250cdf0e10cSrcweir return maProperties;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir
FillListBox()253cdf0e10cSrcweir void ScSolverOptionsDialog::FillListBox()
254cdf0e10cSrcweir {
255cdf0e10cSrcweir // get property descriptions, sort by them
256cdf0e10cSrcweir
257cdf0e10cSrcweir uno::Reference<sheet::XSolverDescription> xDesc( ScSolverUtil::GetSolver( maEngine ), uno::UNO_QUERY );
258cdf0e10cSrcweir sal_Int32 nCount = maProperties.getLength();
259cdf0e10cSrcweir std::vector<ScSolverOptionsEntry> aDescriptions( nCount );
260cdf0e10cSrcweir for (sal_Int32 nPos=0; nPos<nCount; nPos++)
261cdf0e10cSrcweir {
262cdf0e10cSrcweir rtl::OUString aPropName( maProperties[nPos].Name );
263cdf0e10cSrcweir rtl::OUString aVisName;
264cdf0e10cSrcweir if ( xDesc.is() )
265cdf0e10cSrcweir aVisName = xDesc->getPropertyDescription( aPropName );
266cdf0e10cSrcweir if ( !aVisName.getLength() )
267cdf0e10cSrcweir aVisName = aPropName;
268cdf0e10cSrcweir aDescriptions[nPos].nPosition = nPos;
269cdf0e10cSrcweir aDescriptions[nPos].aDescription = aVisName;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir std::sort( aDescriptions.begin(), aDescriptions.end() );
272cdf0e10cSrcweir
273cdf0e10cSrcweir // also update maProperties to the order of descriptions
274cdf0e10cSrcweir
275cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aNewSeq;
276cdf0e10cSrcweir aNewSeq.realloc( nCount );
277cdf0e10cSrcweir for (sal_Int32 nPos=0; nPos<nCount; nPos++)
278cdf0e10cSrcweir aNewSeq[nPos] = maProperties[ aDescriptions[nPos].nPosition ];
279cdf0e10cSrcweir maProperties = aNewSeq;
280cdf0e10cSrcweir
281cdf0e10cSrcweir // fill the list box
282cdf0e10cSrcweir
283cdf0e10cSrcweir maLbSettings.SetUpdateMode(sal_False);
284cdf0e10cSrcweir maLbSettings.Clear();
285cdf0e10cSrcweir
286cdf0e10cSrcweir String sEmpty;
287cdf0e10cSrcweir if (!mpCheckButtonData)
288cdf0e10cSrcweir mpCheckButtonData = new SvLBoxButtonData( &maLbSettings );
289cdf0e10cSrcweir
290cdf0e10cSrcweir SvLBoxTreeList* pModel = maLbSettings.GetModel();
291cdf0e10cSrcweir SvLBoxEntry* pEntry = NULL;
292cdf0e10cSrcweir
293cdf0e10cSrcweir for (sal_Int32 nPos=0; nPos<nCount; nPos++)
294cdf0e10cSrcweir {
295cdf0e10cSrcweir rtl::OUString aVisName = aDescriptions[nPos].aDescription;
296cdf0e10cSrcweir
297cdf0e10cSrcweir uno::Any aValue = maProperties[nPos].Value;
298cdf0e10cSrcweir uno::TypeClass eClass = aValue.getValueTypeClass();
299cdf0e10cSrcweir if ( eClass == uno::TypeClass_BOOLEAN )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir // check box entry
302cdf0e10cSrcweir pEntry = new SvLBoxEntry;
303cdf0e10cSrcweir SvLBoxButton* pButton = new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox, 0, mpCheckButtonData );
304cdf0e10cSrcweir if ( ScUnoHelpFunctions::GetBoolFromAny( aValue ) )
305cdf0e10cSrcweir pButton->SetStateChecked();
306cdf0e10cSrcweir else
307cdf0e10cSrcweir pButton->SetStateUnchecked();
308cdf0e10cSrcweir pEntry->AddItem( pButton );
309cdf0e10cSrcweir pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0 ) );
310cdf0e10cSrcweir pEntry->AddItem( new SvLBoxString( pEntry, 0, aVisName ) );
311cdf0e10cSrcweir }
312cdf0e10cSrcweir else
313cdf0e10cSrcweir {
314cdf0e10cSrcweir // value entry
315cdf0e10cSrcweir pEntry = new SvLBoxEntry;
316cdf0e10cSrcweir pEntry->AddItem( new SvLBoxString( pEntry, 0, sEmpty ) ); // empty column
317cdf0e10cSrcweir pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0 ) );
318cdf0e10cSrcweir ScSolverOptionsString* pItem = new ScSolverOptionsString( pEntry, 0, aVisName );
319cdf0e10cSrcweir if ( eClass == uno::TypeClass_DOUBLE )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir double fDoubleValue = 0.0;
322cdf0e10cSrcweir if ( aValue >>= fDoubleValue )
323cdf0e10cSrcweir pItem->SetDoubleValue( fDoubleValue );
324cdf0e10cSrcweir }
325cdf0e10cSrcweir else
326cdf0e10cSrcweir {
327cdf0e10cSrcweir sal_Int32 nIntValue = 0;
328cdf0e10cSrcweir if ( aValue >>= nIntValue )
329cdf0e10cSrcweir pItem->SetIntValue( nIntValue );
330cdf0e10cSrcweir }
331cdf0e10cSrcweir pEntry->AddItem( pItem );
332cdf0e10cSrcweir }
333cdf0e10cSrcweir pModel->Insert( pEntry );
334cdf0e10cSrcweir }
335cdf0e10cSrcweir
336cdf0e10cSrcweir maLbSettings.SetUpdateMode(sal_True);
337cdf0e10cSrcweir }
338cdf0e10cSrcweir
ReadFromComponent()339cdf0e10cSrcweir void ScSolverOptionsDialog::ReadFromComponent()
340cdf0e10cSrcweir {
341cdf0e10cSrcweir maProperties = ScSolverUtil::GetDefaults( maEngine );
342cdf0e10cSrcweir }
343cdf0e10cSrcweir
EditOption()344cdf0e10cSrcweir void ScSolverOptionsDialog::EditOption()
345cdf0e10cSrcweir {
346cdf0e10cSrcweir SvLBoxEntry* pEntry = maLbSettings.GetCurEntry();
347cdf0e10cSrcweir if (pEntry)
348cdf0e10cSrcweir {
349cdf0e10cSrcweir sal_uInt16 nItemCount = pEntry->ItemCount();
350cdf0e10cSrcweir for (sal_uInt16 nPos=0; nPos<nItemCount; ++nPos)
351cdf0e10cSrcweir {
352cdf0e10cSrcweir SvLBoxItem* pItem = pEntry->GetItem( nPos );
353cdf0e10cSrcweir ScSolverOptionsString* pStringItem = dynamic_cast<ScSolverOptionsString*>(pItem);
354cdf0e10cSrcweir if ( pStringItem )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir if ( pStringItem->IsDouble() )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir ScSolverValueDialog aValDialog( this );
359cdf0e10cSrcweir aValDialog.SetOptionName( pStringItem->GetText() );
360cdf0e10cSrcweir aValDialog.SetValue( pStringItem->GetDoubleValue() );
361cdf0e10cSrcweir if ( aValDialog.Execute() == RET_OK )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir pStringItem->SetDoubleValue( aValDialog.GetValue() );
364cdf0e10cSrcweir maLbSettings.InvalidateEntry( pEntry );
365cdf0e10cSrcweir }
366cdf0e10cSrcweir }
367cdf0e10cSrcweir else
368cdf0e10cSrcweir {
369cdf0e10cSrcweir ScSolverIntegerDialog aIntDialog( this );
370cdf0e10cSrcweir aIntDialog.SetOptionName( pStringItem->GetText() );
371cdf0e10cSrcweir aIntDialog.SetValue( pStringItem->GetIntValue() );
372cdf0e10cSrcweir if ( aIntDialog.Execute() == RET_OK )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir pStringItem->SetIntValue( aIntDialog.GetValue() );
375cdf0e10cSrcweir maLbSettings.InvalidateEntry( pEntry );
376cdf0e10cSrcweir }
377cdf0e10cSrcweir }
378cdf0e10cSrcweir }
379cdf0e10cSrcweir }
380cdf0e10cSrcweir }
381cdf0e10cSrcweir }
382cdf0e10cSrcweir
IMPL_LINK(ScSolverOptionsDialog,ButtonHdl,PushButton *,pBtn)383cdf0e10cSrcweir IMPL_LINK( ScSolverOptionsDialog, ButtonHdl, PushButton*, pBtn )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir if ( pBtn == &maBtnEdit )
386cdf0e10cSrcweir EditOption();
387cdf0e10cSrcweir
388cdf0e10cSrcweir return 0;
389cdf0e10cSrcweir }
390cdf0e10cSrcweir
IMPL_LINK(ScSolverOptionsDialog,SettingsDoubleClickHdl,SvTreeListBox *,EMPTYARG)391cdf0e10cSrcweir IMPL_LINK( ScSolverOptionsDialog, SettingsDoubleClickHdl, SvTreeListBox*, EMPTYARG )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir EditOption();
394cdf0e10cSrcweir return 0;
395cdf0e10cSrcweir }
396cdf0e10cSrcweir
IMPL_LINK(ScSolverOptionsDialog,EngineSelectHdl,ListBox *,EMPTYARG)397cdf0e10cSrcweir IMPL_LINK( ScSolverOptionsDialog, EngineSelectHdl, ListBox*, EMPTYARG )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir sal_uInt16 nSelectPos = maLbEngine.GetSelectEntryPos();
400cdf0e10cSrcweir if ( nSelectPos < maImplNames.getLength() )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir String aNewEngine( maImplNames[nSelectPos] );
403cdf0e10cSrcweir if ( aNewEngine != maEngine )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir maEngine = aNewEngine;
406cdf0e10cSrcweir ReadFromComponent(); // fill maProperties from component (using maEngine)
407cdf0e10cSrcweir FillListBox(); // using maProperties
408cdf0e10cSrcweir }
409cdf0e10cSrcweir }
410cdf0e10cSrcweir return 0;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir
IMPL_LINK(ScSolverOptionsDialog,SettingsSelHdl,SvxCheckListBox *,EMPTYARG)413cdf0e10cSrcweir IMPL_LINK( ScSolverOptionsDialog, SettingsSelHdl, SvxCheckListBox*, EMPTYARG )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir sal_Bool bCheckbox = sal_False;
416cdf0e10cSrcweir
417cdf0e10cSrcweir SvLBoxEntry* pEntry = maLbSettings.GetCurEntry();
418cdf0e10cSrcweir if (pEntry)
419cdf0e10cSrcweir {
420cdf0e10cSrcweir SvLBoxItem* pItem = pEntry->GetFirstItem(SV_ITEM_ID_LBOXBUTTON);
421cdf0e10cSrcweir if ( pItem && pItem->IsA() == SV_ITEM_ID_LBOXBUTTON )
422cdf0e10cSrcweir bCheckbox = sal_True;
423cdf0e10cSrcweir }
424cdf0e10cSrcweir
425cdf0e10cSrcweir maBtnEdit.Enable( !bCheckbox );
426cdf0e10cSrcweir
427cdf0e10cSrcweir return 0;
428cdf0e10cSrcweir }
429cdf0e10cSrcweir
430cdf0e10cSrcweir //------------------------------------------------------------------
431cdf0e10cSrcweir
ScSolverIntegerDialog(Window * pParent)432cdf0e10cSrcweir ScSolverIntegerDialog::ScSolverIntegerDialog( Window * pParent )
433cdf0e10cSrcweir : ModalDialog( pParent, ScResId( RID_SCDLG_SOLVER_INTEGER ) ),
434cdf0e10cSrcweir maFtName ( this, ScResId( FT_OPTIONNAME ) ),
435cdf0e10cSrcweir maNfValue ( this, ScResId( NF_VALUE ) ),
436cdf0e10cSrcweir maFlButtons ( this, ScResId( FL_BUTTONS ) ),
437cdf0e10cSrcweir maBtnOk ( this, ScResId( BTN_OK ) ),
438cdf0e10cSrcweir maBtnCancel ( this, ScResId( BTN_CANCEL ) )
439cdf0e10cSrcweir {
440cdf0e10cSrcweir FreeResource();
441cdf0e10cSrcweir }
442cdf0e10cSrcweir
~ScSolverIntegerDialog()443cdf0e10cSrcweir ScSolverIntegerDialog::~ScSolverIntegerDialog()
444cdf0e10cSrcweir {
445cdf0e10cSrcweir }
446cdf0e10cSrcweir
SetOptionName(const String & rName)447cdf0e10cSrcweir void ScSolverIntegerDialog::SetOptionName( const String& rName )
448cdf0e10cSrcweir {
449cdf0e10cSrcweir maFtName.SetText( rName );
450cdf0e10cSrcweir }
451cdf0e10cSrcweir
SetValue(sal_Int32 nValue)452cdf0e10cSrcweir void ScSolverIntegerDialog::SetValue( sal_Int32 nValue )
453cdf0e10cSrcweir {
454cdf0e10cSrcweir maNfValue.SetValue( nValue );
455cdf0e10cSrcweir }
456cdf0e10cSrcweir
GetValue() const457cdf0e10cSrcweir sal_Int32 ScSolverIntegerDialog::GetValue() const
458cdf0e10cSrcweir {
459cdf0e10cSrcweir sal_Int64 nValue = maNfValue.GetValue();
460cdf0e10cSrcweir if ( nValue < SAL_MIN_INT32 )
461cdf0e10cSrcweir return SAL_MIN_INT32;
462cdf0e10cSrcweir if ( nValue > SAL_MAX_INT32 )
463cdf0e10cSrcweir return SAL_MAX_INT32;
464cdf0e10cSrcweir return (sal_Int32) nValue;
465cdf0e10cSrcweir }
466cdf0e10cSrcweir
467cdf0e10cSrcweir //------------------------------------------------------------------
468cdf0e10cSrcweir
ScSolverValueDialog(Window * pParent)469cdf0e10cSrcweir ScSolverValueDialog::ScSolverValueDialog( Window * pParent )
470cdf0e10cSrcweir : ModalDialog( pParent, ScResId( RID_SCDLG_SOLVER_DOUBLE ) ),
471cdf0e10cSrcweir maFtName ( this, ScResId( FT_OPTIONNAME ) ),
472cdf0e10cSrcweir maEdValue ( this, ScResId( ED_VALUE ) ),
473cdf0e10cSrcweir maFlButtons ( this, ScResId( FL_BUTTONS ) ),
474cdf0e10cSrcweir maBtnOk ( this, ScResId( BTN_OK ) ),
475cdf0e10cSrcweir maBtnCancel ( this, ScResId( BTN_CANCEL ) )
476cdf0e10cSrcweir {
477cdf0e10cSrcweir FreeResource();
478cdf0e10cSrcweir }
479cdf0e10cSrcweir
~ScSolverValueDialog()480cdf0e10cSrcweir ScSolverValueDialog::~ScSolverValueDialog()
481cdf0e10cSrcweir {
482cdf0e10cSrcweir }
483cdf0e10cSrcweir
SetOptionName(const String & rName)484cdf0e10cSrcweir void ScSolverValueDialog::SetOptionName( const String& rName )
485cdf0e10cSrcweir {
486cdf0e10cSrcweir maFtName.SetText( rName );
487cdf0e10cSrcweir }
488cdf0e10cSrcweir
SetValue(double fValue)489cdf0e10cSrcweir void ScSolverValueDialog::SetValue( double fValue )
490cdf0e10cSrcweir {
491cdf0e10cSrcweir maEdValue.SetText( rtl::math::doubleToUString( fValue,
492cdf0e10cSrcweir rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
493cdf0e10cSrcweir ScGlobal::GetpLocaleData()->getNumDecimalSep().GetChar(0), true ) );
494cdf0e10cSrcweir }
495cdf0e10cSrcweir
GetValue() const496cdf0e10cSrcweir double ScSolverValueDialog::GetValue() const
497cdf0e10cSrcweir {
498cdf0e10cSrcweir String aInput = maEdValue.GetText();
499cdf0e10cSrcweir
500cdf0e10cSrcweir const LocaleDataWrapper* pLocaleData = ScGlobal::GetpLocaleData();
501cdf0e10cSrcweir rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
502cdf0e10cSrcweir double fValue = rtl::math::stringToDouble( aInput,
503cdf0e10cSrcweir pLocaleData->getNumDecimalSep().GetChar(0),
504cdf0e10cSrcweir pLocaleData->getNumThousandSep().GetChar(0),
505cdf0e10cSrcweir &eStatus, NULL );
506cdf0e10cSrcweir return fValue;
507cdf0e10cSrcweir }
508cdf0e10cSrcweir
509