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 58cdf0e10cSrcweir ScSolverOptionsEntry() : nPosition(0) {} 59cdf0e10cSrcweir 60cdf0e10cSrcweir 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: 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 81cdf0e10cSrcweir bool IsDouble() const { return mbIsDouble; } 82cdf0e10cSrcweir double GetDoubleValue() const { return mfDoubleValue; } 83cdf0e10cSrcweir sal_Int32 GetIntValue() const { return mnIntValue; } 84cdf0e10cSrcweir 85cdf0e10cSrcweir void SetDoubleValue( double fNew ) { mbIsDouble = true; mfDoubleValue = fNew; } 86cdf0e10cSrcweir void SetIntValue( sal_Int32 nNew ) { mbIsDouble = false; mnIntValue = nNew; } 87*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009----- 88*0deba7fbSSteve Yin // MT: Commented out SV_ITEM_ID_EXTENDRLBOXSTRING and GetExtendText() in svlbitem.hxx - needed? 89*0deba7fbSSteve Yin // virtual USHORT IsA() {return SV_ITEM_ID_EXTENDRLBOXSTRING;} 90*0deba7fbSSteve Yin // virtual XubString GetExtendText() const; 91*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009 92cdf0e10cSrcweir virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry ); 93cdf0e10cSrcweir }; 94cdf0e10cSrcweir 95*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009----- 96*0deba7fbSSteve Yin // MT: Commented out SV_ITEM_ID_EXTENDRLBOXSTRING and GetExtendText() in svlbitem.hxx - needed? 97*0deba7fbSSteve Yin /* 98*0deba7fbSSteve Yin XubString ScSolverOptionsString::GetExtendText() const 99*0deba7fbSSteve Yin { 100*0deba7fbSSteve Yin String aNormalStr( GetText() ); 101*0deba7fbSSteve Yin aNormalStr.Append( (sal_Unicode) ':' ); 102*0deba7fbSSteve Yin String sTxt( ' ' ); 103*0deba7fbSSteve Yin if ( mbIsDouble ) 104*0deba7fbSSteve Yin sTxt += (String)rtl::math::doubleToUString( mfDoubleValue, 105*0deba7fbSSteve Yin rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, 106*0deba7fbSSteve Yin ScGlobal::GetpLocaleData()->getNumDecimalSep().GetChar(0), true ); 107*0deba7fbSSteve Yin else 108*0deba7fbSSteve Yin sTxt += String::CreateFromInt32( mnIntValue ); 109*0deba7fbSSteve Yin aNormalStr.Append(sTxt); 110*0deba7fbSSteve Yin return aNormalStr; 111*0deba7fbSSteve Yin } 112*0deba7fbSSteve Yin */ 113*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009 114*0deba7fbSSteve Yin 115cdf0e10cSrcweir void ScSolverOptionsString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16, SvLBoxEntry* /* pEntry */ ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir //! move position? (SvxLinguTabPage: aPos.X() += 20) 118cdf0e10cSrcweir String aNormalStr( GetText() ); 119cdf0e10cSrcweir aNormalStr.Append( (sal_Unicode) ':' ); 120cdf0e10cSrcweir rDev.DrawText( rPos, aNormalStr ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir Point aNewPos( rPos ); 123cdf0e10cSrcweir aNewPos.X() += rDev.GetTextWidth( aNormalStr ); 124cdf0e10cSrcweir Font aOldFont( rDev.GetFont() ); 125cdf0e10cSrcweir Font aFont( aOldFont ); 126cdf0e10cSrcweir aFont.SetWeight( WEIGHT_BOLD ); 127cdf0e10cSrcweir 128cdf0e10cSrcweir String sTxt( ' ' ); 129cdf0e10cSrcweir if ( mbIsDouble ) 130cdf0e10cSrcweir sTxt += (String)rtl::math::doubleToUString( mfDoubleValue, 131cdf0e10cSrcweir rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, 132cdf0e10cSrcweir ScGlobal::GetpLocaleData()->getNumDecimalSep().GetChar(0), true ); 133cdf0e10cSrcweir else 134cdf0e10cSrcweir sTxt += String::CreateFromInt32( mnIntValue ); 135cdf0e10cSrcweir rDev.SetFont( aFont ); 136cdf0e10cSrcweir rDev.DrawText( aNewPos, sTxt ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir rDev.SetFont( aOldFont ); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir //------------------------------------------------------------------ 142cdf0e10cSrcweir 143cdf0e10cSrcweir ScSolverOptionsDialog::ScSolverOptionsDialog( Window* pParent, 144cdf0e10cSrcweir const uno::Sequence<rtl::OUString>& rImplNames, 145cdf0e10cSrcweir const uno::Sequence<rtl::OUString>& rDescriptions, 146cdf0e10cSrcweir const String& rEngine, 147cdf0e10cSrcweir const uno::Sequence<beans::PropertyValue>& rProperties ) 148cdf0e10cSrcweir : ModalDialog( pParent, ScResId( RID_SCDLG_SOLVEROPTIONS ) ), 149cdf0e10cSrcweir maFtEngine ( this, ScResId( FT_ENGINE ) ), 150cdf0e10cSrcweir maLbEngine ( this, ScResId( LB_ENGINE ) ), 151cdf0e10cSrcweir maFtSettings ( this, ScResId( FT_SETTINGS ) ), 152cdf0e10cSrcweir maLbSettings ( this, ScResId( LB_SETTINGS ) ), 153cdf0e10cSrcweir maBtnEdit ( this, ScResId( BTN_EDIT ) ), 154cdf0e10cSrcweir maFlButtons ( this, ScResId( FL_BUTTONS ) ), 155cdf0e10cSrcweir maBtnHelp ( this, ScResId( BTN_HELP ) ), 156cdf0e10cSrcweir maBtnOk ( this, ScResId( BTN_OK ) ), 157cdf0e10cSrcweir maBtnCancel ( this, ScResId( BTN_CANCEL ) ), 158cdf0e10cSrcweir mpCheckButtonData( NULL ), 159cdf0e10cSrcweir maImplNames( rImplNames ), 160cdf0e10cSrcweir maDescriptions( rDescriptions ), 161cdf0e10cSrcweir maEngine( rEngine ), 162cdf0e10cSrcweir maProperties( rProperties ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir maLbEngine.SetSelectHdl( LINK( this, ScSolverOptionsDialog, EngineSelectHdl ) ); 165cdf0e10cSrcweir 166cdf0e10cSrcweir maBtnEdit.SetClickHdl( LINK( this, ScSolverOptionsDialog, ButtonHdl ) ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir maLbSettings.SetStyle( maLbSettings.GetStyle()|WB_CLIPCHILDREN|WB_FORCE_MAKEVISIBLE ); 169cdf0e10cSrcweir maLbSettings.SetHelpId( HID_SC_SOLVEROPTIONS_LB ); 170cdf0e10cSrcweir maLbSettings.SetHighlightRange(); 171cdf0e10cSrcweir 172cdf0e10cSrcweir maLbSettings.SetSelectHdl( LINK( this, ScSolverOptionsDialog, SettingsSelHdl ) ); 173cdf0e10cSrcweir maLbSettings.SetDoubleClickHdl( LINK( this, ScSolverOptionsDialog, SettingsDoubleClickHdl ) ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir sal_Int32 nSelect = -1; 176cdf0e10cSrcweir sal_Int32 nImplCount = maImplNames.getLength(); 177cdf0e10cSrcweir for (sal_Int32 nImpl=0; nImpl<nImplCount; ++nImpl) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir String aImplName( maImplNames[nImpl] ); 180cdf0e10cSrcweir String aDescription( maDescriptions[nImpl] ); // user-visible descriptions in list box 181cdf0e10cSrcweir maLbEngine.InsertEntry( aDescription ); 182cdf0e10cSrcweir if ( aImplName == maEngine ) 183cdf0e10cSrcweir nSelect = nImpl; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir if ( nSelect < 0 ) // no (valid) engine given 186cdf0e10cSrcweir { 187cdf0e10cSrcweir if ( nImplCount > 0 ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir maEngine = maImplNames[0]; // use first implementation 190cdf0e10cSrcweir nSelect = 0; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir else 193cdf0e10cSrcweir maEngine.Erase(); 194cdf0e10cSrcweir maProperties.realloc(0); // don't use options from different engine 195cdf0e10cSrcweir } 196cdf0e10cSrcweir if ( nSelect >= 0 ) // select in list box 197cdf0e10cSrcweir maLbEngine.SelectEntryPos( static_cast<sal_uInt16>(nSelect) ); 198cdf0e10cSrcweir 199cdf0e10cSrcweir if ( !maProperties.getLength() ) 200cdf0e10cSrcweir ReadFromComponent(); // fill maProperties from component (using maEngine) 201cdf0e10cSrcweir FillListBox(); // using maProperties 202cdf0e10cSrcweir 203cdf0e10cSrcweir FreeResource(); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir ScSolverOptionsDialog::~ScSolverOptionsDialog() 207cdf0e10cSrcweir { 208cdf0e10cSrcweir delete mpCheckButtonData; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir const String& ScSolverOptionsDialog::GetEngine() const 212cdf0e10cSrcweir { 213cdf0e10cSrcweir return maEngine; // already updated in selection handler 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir const uno::Sequence<beans::PropertyValue>& ScSolverOptionsDialog::GetProperties() 217cdf0e10cSrcweir { 218cdf0e10cSrcweir // update maProperties from list box content 219cdf0e10cSrcweir // order of entries in list box and maProperties is the same 220cdf0e10cSrcweir sal_Int32 nEntryCount = maProperties.getLength(); 221cdf0e10cSrcweir SvLBoxTreeList* pModel = maLbSettings.GetModel(); 222cdf0e10cSrcweir if ( nEntryCount == (sal_Int32)pModel->GetEntryCount() ) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir for (sal_Int32 nEntryPos=0; nEntryPos<nEntryCount; ++nEntryPos) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir uno::Any& rValue = maProperties[nEntryPos].Value; 227cdf0e10cSrcweir SvLBoxEntry* pEntry = pModel->GetEntry(nEntryPos); 228cdf0e10cSrcweir 229cdf0e10cSrcweir bool bHasData = false; 230cdf0e10cSrcweir sal_uInt16 nItemCount = pEntry->ItemCount(); 231cdf0e10cSrcweir for (sal_uInt16 nItemPos=0; nItemPos<nItemCount && !bHasData; ++nItemPos) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir SvLBoxItem* pItem = pEntry->GetItem( nItemPos ); 234cdf0e10cSrcweir ScSolverOptionsString* pStringItem = dynamic_cast<ScSolverOptionsString*>(pItem); 235cdf0e10cSrcweir if ( pStringItem ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir if ( pStringItem->IsDouble() ) 238cdf0e10cSrcweir rValue <<= pStringItem->GetDoubleValue(); 239cdf0e10cSrcweir else 240cdf0e10cSrcweir rValue <<= pStringItem->GetIntValue(); 241cdf0e10cSrcweir bHasData = true; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir } 244cdf0e10cSrcweir if ( !bHasData ) 245cdf0e10cSrcweir ScUnoHelpFunctions::SetBoolInAny( rValue, 246cdf0e10cSrcweir maLbSettings.GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir } 249cdf0e10cSrcweir else 250cdf0e10cSrcweir { 251cdf0e10cSrcweir DBG_ERRORFILE( "wrong count" ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir return maProperties; 255cdf0e10cSrcweir } 256cdf0e10cSrcweir 257cdf0e10cSrcweir void ScSolverOptionsDialog::FillListBox() 258cdf0e10cSrcweir { 259cdf0e10cSrcweir // get property descriptions, sort by them 260cdf0e10cSrcweir 261cdf0e10cSrcweir uno::Reference<sheet::XSolverDescription> xDesc( ScSolverUtil::GetSolver( maEngine ), uno::UNO_QUERY ); 262cdf0e10cSrcweir sal_Int32 nCount = maProperties.getLength(); 263cdf0e10cSrcweir std::vector<ScSolverOptionsEntry> aDescriptions( nCount ); 264cdf0e10cSrcweir for (sal_Int32 nPos=0; nPos<nCount; nPos++) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir rtl::OUString aPropName( maProperties[nPos].Name ); 267cdf0e10cSrcweir rtl::OUString aVisName; 268cdf0e10cSrcweir if ( xDesc.is() ) 269cdf0e10cSrcweir aVisName = xDesc->getPropertyDescription( aPropName ); 270cdf0e10cSrcweir if ( !aVisName.getLength() ) 271cdf0e10cSrcweir aVisName = aPropName; 272cdf0e10cSrcweir aDescriptions[nPos].nPosition = nPos; 273cdf0e10cSrcweir aDescriptions[nPos].aDescription = aVisName; 274cdf0e10cSrcweir } 275cdf0e10cSrcweir std::sort( aDescriptions.begin(), aDescriptions.end() ); 276cdf0e10cSrcweir 277cdf0e10cSrcweir // also update maProperties to the order of descriptions 278cdf0e10cSrcweir 279cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aNewSeq; 280cdf0e10cSrcweir aNewSeq.realloc( nCount ); 281cdf0e10cSrcweir for (sal_Int32 nPos=0; nPos<nCount; nPos++) 282cdf0e10cSrcweir aNewSeq[nPos] = maProperties[ aDescriptions[nPos].nPosition ]; 283cdf0e10cSrcweir maProperties = aNewSeq; 284cdf0e10cSrcweir 285cdf0e10cSrcweir // fill the list box 286cdf0e10cSrcweir 287cdf0e10cSrcweir maLbSettings.SetUpdateMode(sal_False); 288cdf0e10cSrcweir maLbSettings.Clear(); 289cdf0e10cSrcweir 290cdf0e10cSrcweir String sEmpty; 291cdf0e10cSrcweir if (!mpCheckButtonData) 292cdf0e10cSrcweir mpCheckButtonData = new SvLBoxButtonData( &maLbSettings ); 293cdf0e10cSrcweir 294cdf0e10cSrcweir SvLBoxTreeList* pModel = maLbSettings.GetModel(); 295cdf0e10cSrcweir SvLBoxEntry* pEntry = NULL; 296cdf0e10cSrcweir 297cdf0e10cSrcweir for (sal_Int32 nPos=0; nPos<nCount; nPos++) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir rtl::OUString aVisName = aDescriptions[nPos].aDescription; 300cdf0e10cSrcweir 301cdf0e10cSrcweir uno::Any aValue = maProperties[nPos].Value; 302cdf0e10cSrcweir uno::TypeClass eClass = aValue.getValueTypeClass(); 303cdf0e10cSrcweir if ( eClass == uno::TypeClass_BOOLEAN ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir // check box entry 306cdf0e10cSrcweir pEntry = new SvLBoxEntry; 307cdf0e10cSrcweir SvLBoxButton* pButton = new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox, 0, mpCheckButtonData ); 308cdf0e10cSrcweir if ( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ) 309cdf0e10cSrcweir pButton->SetStateChecked(); 310cdf0e10cSrcweir else 311cdf0e10cSrcweir pButton->SetStateUnchecked(); 312cdf0e10cSrcweir pEntry->AddItem( pButton ); 313cdf0e10cSrcweir pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0 ) ); 314cdf0e10cSrcweir pEntry->AddItem( new SvLBoxString( pEntry, 0, aVisName ) ); 315cdf0e10cSrcweir } 316cdf0e10cSrcweir else 317cdf0e10cSrcweir { 318cdf0e10cSrcweir // value entry 319cdf0e10cSrcweir pEntry = new SvLBoxEntry; 320cdf0e10cSrcweir pEntry->AddItem( new SvLBoxString( pEntry, 0, sEmpty ) ); // empty column 321cdf0e10cSrcweir pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0 ) ); 322cdf0e10cSrcweir ScSolverOptionsString* pItem = new ScSolverOptionsString( pEntry, 0, aVisName ); 323cdf0e10cSrcweir if ( eClass == uno::TypeClass_DOUBLE ) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir double fDoubleValue = 0.0; 326cdf0e10cSrcweir if ( aValue >>= fDoubleValue ) 327cdf0e10cSrcweir pItem->SetDoubleValue( fDoubleValue ); 328cdf0e10cSrcweir } 329cdf0e10cSrcweir else 330cdf0e10cSrcweir { 331cdf0e10cSrcweir sal_Int32 nIntValue = 0; 332cdf0e10cSrcweir if ( aValue >>= nIntValue ) 333cdf0e10cSrcweir pItem->SetIntValue( nIntValue ); 334cdf0e10cSrcweir } 335cdf0e10cSrcweir pEntry->AddItem( pItem ); 336cdf0e10cSrcweir } 337cdf0e10cSrcweir pModel->Insert( pEntry ); 338cdf0e10cSrcweir } 339cdf0e10cSrcweir 340cdf0e10cSrcweir maLbSettings.SetUpdateMode(sal_True); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir void ScSolverOptionsDialog::ReadFromComponent() 344cdf0e10cSrcweir { 345cdf0e10cSrcweir maProperties = ScSolverUtil::GetDefaults( maEngine ); 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir void ScSolverOptionsDialog::EditOption() 349cdf0e10cSrcweir { 350cdf0e10cSrcweir SvLBoxEntry* pEntry = maLbSettings.GetCurEntry(); 351cdf0e10cSrcweir if (pEntry) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir sal_uInt16 nItemCount = pEntry->ItemCount(); 354cdf0e10cSrcweir for (sal_uInt16 nPos=0; nPos<nItemCount; ++nPos) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir SvLBoxItem* pItem = pEntry->GetItem( nPos ); 357cdf0e10cSrcweir ScSolverOptionsString* pStringItem = dynamic_cast<ScSolverOptionsString*>(pItem); 358cdf0e10cSrcweir if ( pStringItem ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir if ( pStringItem->IsDouble() ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir ScSolverValueDialog aValDialog( this ); 363cdf0e10cSrcweir aValDialog.SetOptionName( pStringItem->GetText() ); 364cdf0e10cSrcweir aValDialog.SetValue( pStringItem->GetDoubleValue() ); 365cdf0e10cSrcweir if ( aValDialog.Execute() == RET_OK ) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir pStringItem->SetDoubleValue( aValDialog.GetValue() ); 368cdf0e10cSrcweir maLbSettings.InvalidateEntry( pEntry ); 369cdf0e10cSrcweir } 370cdf0e10cSrcweir } 371cdf0e10cSrcweir else 372cdf0e10cSrcweir { 373cdf0e10cSrcweir ScSolverIntegerDialog aIntDialog( this ); 374cdf0e10cSrcweir aIntDialog.SetOptionName( pStringItem->GetText() ); 375cdf0e10cSrcweir aIntDialog.SetValue( pStringItem->GetIntValue() ); 376cdf0e10cSrcweir if ( aIntDialog.Execute() == RET_OK ) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir pStringItem->SetIntValue( aIntDialog.GetValue() ); 379cdf0e10cSrcweir maLbSettings.InvalidateEntry( pEntry ); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir } 382cdf0e10cSrcweir } 383cdf0e10cSrcweir } 384cdf0e10cSrcweir } 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir IMPL_LINK( ScSolverOptionsDialog, ButtonHdl, PushButton*, pBtn ) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir if ( pBtn == &maBtnEdit ) 390cdf0e10cSrcweir EditOption(); 391cdf0e10cSrcweir 392cdf0e10cSrcweir return 0; 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir IMPL_LINK( ScSolverOptionsDialog, SettingsDoubleClickHdl, SvTreeListBox*, EMPTYARG ) 396cdf0e10cSrcweir { 397cdf0e10cSrcweir EditOption(); 398cdf0e10cSrcweir return 0; 399cdf0e10cSrcweir } 400cdf0e10cSrcweir 401cdf0e10cSrcweir IMPL_LINK( ScSolverOptionsDialog, EngineSelectHdl, ListBox*, EMPTYARG ) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir sal_uInt16 nSelectPos = maLbEngine.GetSelectEntryPos(); 404cdf0e10cSrcweir if ( nSelectPos < maImplNames.getLength() ) 405cdf0e10cSrcweir { 406cdf0e10cSrcweir String aNewEngine( maImplNames[nSelectPos] ); 407cdf0e10cSrcweir if ( aNewEngine != maEngine ) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir maEngine = aNewEngine; 410cdf0e10cSrcweir ReadFromComponent(); // fill maProperties from component (using maEngine) 411cdf0e10cSrcweir FillListBox(); // using maProperties 412cdf0e10cSrcweir } 413cdf0e10cSrcweir } 414cdf0e10cSrcweir return 0; 415cdf0e10cSrcweir } 416cdf0e10cSrcweir 417cdf0e10cSrcweir IMPL_LINK( ScSolverOptionsDialog, SettingsSelHdl, SvxCheckListBox*, EMPTYARG ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir sal_Bool bCheckbox = sal_False; 420cdf0e10cSrcweir 421cdf0e10cSrcweir SvLBoxEntry* pEntry = maLbSettings.GetCurEntry(); 422cdf0e10cSrcweir if (pEntry) 423cdf0e10cSrcweir { 424cdf0e10cSrcweir SvLBoxItem* pItem = pEntry->GetFirstItem(SV_ITEM_ID_LBOXBUTTON); 425cdf0e10cSrcweir if ( pItem && pItem->IsA() == SV_ITEM_ID_LBOXBUTTON ) 426cdf0e10cSrcweir bCheckbox = sal_True; 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir maBtnEdit.Enable( !bCheckbox ); 430cdf0e10cSrcweir 431cdf0e10cSrcweir return 0; 432cdf0e10cSrcweir } 433cdf0e10cSrcweir 434cdf0e10cSrcweir //------------------------------------------------------------------ 435cdf0e10cSrcweir 436cdf0e10cSrcweir ScSolverIntegerDialog::ScSolverIntegerDialog( Window * pParent ) 437cdf0e10cSrcweir : ModalDialog( pParent, ScResId( RID_SCDLG_SOLVER_INTEGER ) ), 438cdf0e10cSrcweir maFtName ( this, ScResId( FT_OPTIONNAME ) ), 439cdf0e10cSrcweir maNfValue ( this, ScResId( NF_VALUE ) ), 440cdf0e10cSrcweir maFlButtons ( this, ScResId( FL_BUTTONS ) ), 441cdf0e10cSrcweir maBtnOk ( this, ScResId( BTN_OK ) ), 442cdf0e10cSrcweir maBtnCancel ( this, ScResId( BTN_CANCEL ) ) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir FreeResource(); 445cdf0e10cSrcweir } 446cdf0e10cSrcweir 447cdf0e10cSrcweir ScSolverIntegerDialog::~ScSolverIntegerDialog() 448cdf0e10cSrcweir { 449cdf0e10cSrcweir } 450cdf0e10cSrcweir 451cdf0e10cSrcweir void ScSolverIntegerDialog::SetOptionName( const String& rName ) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir maFtName.SetText( rName ); 454cdf0e10cSrcweir } 455cdf0e10cSrcweir 456cdf0e10cSrcweir void ScSolverIntegerDialog::SetValue( sal_Int32 nValue ) 457cdf0e10cSrcweir { 458cdf0e10cSrcweir maNfValue.SetValue( nValue ); 459cdf0e10cSrcweir } 460cdf0e10cSrcweir 461cdf0e10cSrcweir sal_Int32 ScSolverIntegerDialog::GetValue() const 462cdf0e10cSrcweir { 463cdf0e10cSrcweir sal_Int64 nValue = maNfValue.GetValue(); 464cdf0e10cSrcweir if ( nValue < SAL_MIN_INT32 ) 465cdf0e10cSrcweir return SAL_MIN_INT32; 466cdf0e10cSrcweir if ( nValue > SAL_MAX_INT32 ) 467cdf0e10cSrcweir return SAL_MAX_INT32; 468cdf0e10cSrcweir return (sal_Int32) nValue; 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir //------------------------------------------------------------------ 472cdf0e10cSrcweir 473cdf0e10cSrcweir ScSolverValueDialog::ScSolverValueDialog( Window * pParent ) 474cdf0e10cSrcweir : ModalDialog( pParent, ScResId( RID_SCDLG_SOLVER_DOUBLE ) ), 475cdf0e10cSrcweir maFtName ( this, ScResId( FT_OPTIONNAME ) ), 476cdf0e10cSrcweir maEdValue ( this, ScResId( ED_VALUE ) ), 477cdf0e10cSrcweir maFlButtons ( this, ScResId( FL_BUTTONS ) ), 478cdf0e10cSrcweir maBtnOk ( this, ScResId( BTN_OK ) ), 479cdf0e10cSrcweir maBtnCancel ( this, ScResId( BTN_CANCEL ) ) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir FreeResource(); 482cdf0e10cSrcweir } 483cdf0e10cSrcweir 484cdf0e10cSrcweir ScSolverValueDialog::~ScSolverValueDialog() 485cdf0e10cSrcweir { 486cdf0e10cSrcweir } 487cdf0e10cSrcweir 488cdf0e10cSrcweir void ScSolverValueDialog::SetOptionName( const String& rName ) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir maFtName.SetText( rName ); 491cdf0e10cSrcweir } 492cdf0e10cSrcweir 493cdf0e10cSrcweir void ScSolverValueDialog::SetValue( double fValue ) 494cdf0e10cSrcweir { 495cdf0e10cSrcweir maEdValue.SetText( rtl::math::doubleToUString( fValue, 496cdf0e10cSrcweir rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, 497cdf0e10cSrcweir ScGlobal::GetpLocaleData()->getNumDecimalSep().GetChar(0), true ) ); 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir double ScSolverValueDialog::GetValue() const 501cdf0e10cSrcweir { 502cdf0e10cSrcweir String aInput = maEdValue.GetText(); 503cdf0e10cSrcweir 504cdf0e10cSrcweir const LocaleDataWrapper* pLocaleData = ScGlobal::GetpLocaleData(); 505cdf0e10cSrcweir rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok; 506cdf0e10cSrcweir double fValue = rtl::math::stringToDouble( aInput, 507cdf0e10cSrcweir pLocaleData->getNumDecimalSep().GetChar(0), 508cdf0e10cSrcweir pLocaleData->getNumThousandSep().GetChar(0), 509cdf0e10cSrcweir &eStatus, NULL ); 510cdf0e10cSrcweir return fValue; 511cdf0e10cSrcweir } 512cdf0e10cSrcweir 513