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