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