1*38d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*38d50f7bSAndrew Rist * distributed with this work for additional information 6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 10*38d50f7bSAndrew Rist * 11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*38d50f7bSAndrew Rist * 13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an 15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 17*38d50f7bSAndrew Rist * specific language governing permissions and limitations 18*38d50f7bSAndrew Rist * under the License. 19*38d50f7bSAndrew Rist * 20*38d50f7bSAndrew Rist *************************************************************/ 21*38d50f7bSAndrew Rist 22*38d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_OPTSOLVER_HXX 25cdf0e10cSrcweir #define SC_OPTSOLVER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "global.hxx" 28cdf0e10cSrcweir #include "address.hxx" 29cdf0e10cSrcweir #include "anyrefdg.hxx" 30cdf0e10cSrcweir #include <vcl/fixed.hxx> 31cdf0e10cSrcweir #include <vcl/group.hxx> 32cdf0e10cSrcweir #include <vcl/lstbox.hxx> 33cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <vector> 36cdf0e10cSrcweir 37cdf0e10cSrcweir namespace com { namespace sun { namespace star { 38cdf0e10cSrcweir namespace beans { struct PropertyValue; } 39cdf0e10cSrcweir } } } 40cdf0e10cSrcweir 41cdf0e10cSrcweir //============================================================================ 42cdf0e10cSrcweir 43cdf0e10cSrcweir class ScCursorRefEdit : public formula::RefEdit 44cdf0e10cSrcweir { 45cdf0e10cSrcweir Link maCursorUpLink; 46cdf0e10cSrcweir Link maCursorDownLink; 47cdf0e10cSrcweir 48cdf0e10cSrcweir public: 49cdf0e10cSrcweir ScCursorRefEdit( ScAnyRefDlg* pParent, const ResId& rResId ); 50cdf0e10cSrcweir void SetCursorLinks( const Link& rUp, const Link& rDown ); 51cdf0e10cSrcweir 52cdf0e10cSrcweir protected: 53cdf0e10cSrcweir virtual void KeyInput( const KeyEvent& rKEvt ); 54cdf0e10cSrcweir }; 55cdf0e10cSrcweir 56cdf0e10cSrcweir 57cdf0e10cSrcweir /// The dialog's content for a row, not yet parsed 58cdf0e10cSrcweir struct ScOptConditionRow 59cdf0e10cSrcweir { 60cdf0e10cSrcweir String aLeftStr; 61cdf0e10cSrcweir sal_uInt16 nOperator; 62cdf0e10cSrcweir String aRightStr; 63cdf0e10cSrcweir ScOptConditionRowScOptConditionRow64cdf0e10cSrcweir ScOptConditionRow() : nOperator(0) {} IsDefaultScOptConditionRow65cdf0e10cSrcweir bool IsDefault() const { return aLeftStr.Len() == 0 && aRightStr.Len() == 0 && nOperator == 0; } 66cdf0e10cSrcweir }; 67cdf0e10cSrcweir 68cdf0e10cSrcweir /// All settings from the dialog, saved with the DocShell for the next call 69cdf0e10cSrcweir class ScOptSolverSave 70cdf0e10cSrcweir { 71cdf0e10cSrcweir String maObjective; 72cdf0e10cSrcweir sal_Bool mbMax; 73cdf0e10cSrcweir sal_Bool mbMin; 74cdf0e10cSrcweir sal_Bool mbValue; 75cdf0e10cSrcweir String maTarget; 76cdf0e10cSrcweir String maVariable; 77cdf0e10cSrcweir std::vector<ScOptConditionRow> maConditions; 78cdf0e10cSrcweir String maEngine; 79cdf0e10cSrcweir com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> maProperties; 80cdf0e10cSrcweir 81cdf0e10cSrcweir public: 82cdf0e10cSrcweir ScOptSolverSave( const String& rObjective, sal_Bool bMax, sal_Bool bMin, sal_Bool bValue, 83cdf0e10cSrcweir const String& rTarget, const String& rVariable, 84cdf0e10cSrcweir const std::vector<ScOptConditionRow>& rConditions, 85cdf0e10cSrcweir const String& rEngine, 86cdf0e10cSrcweir const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rProperties ); 87cdf0e10cSrcweir GetObjective() const88cdf0e10cSrcweir const String& GetObjective() const { return maObjective; } GetMax() const89cdf0e10cSrcweir sal_Bool GetMax() const { return mbMax; } GetMin() const90cdf0e10cSrcweir sal_Bool GetMin() const { return mbMin; } GetValue() const91cdf0e10cSrcweir sal_Bool GetValue() const { return mbValue; } GetTarget() const92cdf0e10cSrcweir const String& GetTarget() const { return maTarget; } GetVariable() const93cdf0e10cSrcweir const String& GetVariable() const { return maVariable; } GetConditions() const94cdf0e10cSrcweir const std::vector<ScOptConditionRow>& GetConditions() const { return maConditions; } GetEngine() const95cdf0e10cSrcweir const String& GetEngine() const { return maEngine; } GetProperties() const96cdf0e10cSrcweir const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& GetProperties() const 97cdf0e10cSrcweir { return maProperties; } 98cdf0e10cSrcweir }; 99cdf0e10cSrcweir 100cdf0e10cSrcweir class ScOptSolverDlg : public ScAnyRefDlg 101cdf0e10cSrcweir { 102cdf0e10cSrcweir public: 103cdf0e10cSrcweir ScOptSolverDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, 104cdf0e10cSrcweir ScDocShell* pDocSh, ScAddress aCursorPos ); 105cdf0e10cSrcweir ~ScOptSolverDlg(); 106cdf0e10cSrcweir 107cdf0e10cSrcweir virtual void SetReference( const ScRange& rRef, ScDocument* pDoc ); 108cdf0e10cSrcweir virtual sal_Bool IsRefInputMode() const; 109cdf0e10cSrcweir virtual void SetActive(); 110cdf0e10cSrcweir virtual sal_Bool Close(); 111cdf0e10cSrcweir 112cdf0e10cSrcweir private: 113cdf0e10cSrcweir FixedText maFtObjectiveCell; 114cdf0e10cSrcweir formula::RefEdit maEdObjectiveCell; 115cdf0e10cSrcweir formula::RefButton maRBObjectiveCell; 116cdf0e10cSrcweir 117cdf0e10cSrcweir FixedText maFtDirection; 118cdf0e10cSrcweir RadioButton maRbMax; 119cdf0e10cSrcweir RadioButton maRbMin; 120cdf0e10cSrcweir RadioButton maRbValue; 121cdf0e10cSrcweir formula::RefEdit maEdTargetValue; 122cdf0e10cSrcweir formula::RefButton maRBTargetValue; 123cdf0e10cSrcweir 124cdf0e10cSrcweir FixedText maFtVariableCells; 125cdf0e10cSrcweir formula::RefEdit maEdVariableCells; 126cdf0e10cSrcweir formula::RefButton maRBVariableCells; 127cdf0e10cSrcweir 128cdf0e10cSrcweir FixedLine maFlConditions; 129cdf0e10cSrcweir 130cdf0e10cSrcweir FixedText maFtCellRef; // labels are together with controls for the first row 131cdf0e10cSrcweir ScCursorRefEdit maEdLeft1; 132cdf0e10cSrcweir formula::RefButton maRBLeft1; 133cdf0e10cSrcweir FixedText maFtOperator; 134cdf0e10cSrcweir ListBox maLbOp1; 135cdf0e10cSrcweir FixedText maFtConstraint; 136cdf0e10cSrcweir ScCursorRefEdit maEdRight1; 137cdf0e10cSrcweir formula::RefButton maRBRight1; 138cdf0e10cSrcweir ImageButton maBtnDel1; 139cdf0e10cSrcweir 140cdf0e10cSrcweir ScCursorRefEdit maEdLeft2; 141cdf0e10cSrcweir formula::RefButton maRBLeft2; 142cdf0e10cSrcweir ListBox maLbOp2; 143cdf0e10cSrcweir ScCursorRefEdit maEdRight2; 144cdf0e10cSrcweir formula::RefButton maRBRight2; 145cdf0e10cSrcweir ImageButton maBtnDel2; 146cdf0e10cSrcweir 147cdf0e10cSrcweir ScCursorRefEdit maEdLeft3; 148cdf0e10cSrcweir formula::RefButton maRBLeft3; 149cdf0e10cSrcweir ListBox maLbOp3; 150cdf0e10cSrcweir ScCursorRefEdit maEdRight3; 151cdf0e10cSrcweir formula::RefButton maRBRight3; 152cdf0e10cSrcweir ImageButton maBtnDel3; 153cdf0e10cSrcweir 154cdf0e10cSrcweir ScCursorRefEdit maEdLeft4; 155cdf0e10cSrcweir formula::RefButton maRBLeft4; 156cdf0e10cSrcweir ListBox maLbOp4; 157cdf0e10cSrcweir ScCursorRefEdit maEdRight4; 158cdf0e10cSrcweir formula::RefButton maRBRight4; 159cdf0e10cSrcweir ImageButton maBtnDel4; 160cdf0e10cSrcweir 161cdf0e10cSrcweir ScrollBar maScrollBar; 162cdf0e10cSrcweir 163cdf0e10cSrcweir FixedLine maFlButtons; 164cdf0e10cSrcweir 165cdf0e10cSrcweir PushButton maBtnOpt; 166cdf0e10cSrcweir HelpButton maBtnHelp; 167cdf0e10cSrcweir CancelButton maBtnCancel; 168cdf0e10cSrcweir PushButton maBtnSolve; 169cdf0e10cSrcweir 170cdf0e10cSrcweir String maInputError; 171cdf0e10cSrcweir String maConditionError; 172cdf0e10cSrcweir 173cdf0e10cSrcweir ScDocShell* mpDocShell; 174cdf0e10cSrcweir ScDocument* mpDoc; 175cdf0e10cSrcweir const SCTAB mnCurTab; 176cdf0e10cSrcweir formula::RefEdit* mpEdActive; 177cdf0e10cSrcweir bool mbDlgLostFocus; 178cdf0e10cSrcweir 179cdf0e10cSrcweir static const sal_uInt16 EDIT_ROW_COUNT = 4; 180cdf0e10cSrcweir ScCursorRefEdit* mpLeftEdit[EDIT_ROW_COUNT]; 181cdf0e10cSrcweir formula::RefButton* mpLeftButton[EDIT_ROW_COUNT]; 182cdf0e10cSrcweir ScCursorRefEdit* mpRightEdit[EDIT_ROW_COUNT]; 183cdf0e10cSrcweir formula::RefButton* mpRightButton[EDIT_ROW_COUNT]; 184cdf0e10cSrcweir ListBox* mpOperator[EDIT_ROW_COUNT]; 185cdf0e10cSrcweir ImageButton* mpDelButton[EDIT_ROW_COUNT]; 186cdf0e10cSrcweir 187cdf0e10cSrcweir std::vector<ScOptConditionRow> maConditions; 188cdf0e10cSrcweir long nScrollPos; 189cdf0e10cSrcweir 190cdf0e10cSrcweir com::sun::star::uno::Sequence<rtl::OUString> maImplNames; 191cdf0e10cSrcweir com::sun::star::uno::Sequence<rtl::OUString> maDescriptions; 192cdf0e10cSrcweir String maEngine; 193cdf0e10cSrcweir com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> maProperties; 194cdf0e10cSrcweir 195cdf0e10cSrcweir void Init(const ScAddress& rCursorPos); 196cdf0e10cSrcweir bool CallSolver(); 197cdf0e10cSrcweir void ReadConditions(); 198cdf0e10cSrcweir void ShowConditions(); 199cdf0e10cSrcweir void EnableButtons(); 200cdf0e10cSrcweir bool ParseRef( ScRange& rRange, const String& rInput, bool bAllowRange ); 201cdf0e10cSrcweir bool FindTimeout( sal_Int32& rTimeout ); 202cdf0e10cSrcweir void ShowError( bool bCondition, formula::RefEdit* pFocus ); 203cdf0e10cSrcweir 204cdf0e10cSrcweir DECL_LINK( BtnHdl, PushButton* ); 205cdf0e10cSrcweir DECL_LINK( DelBtnHdl, PushButton* ); 206cdf0e10cSrcweir DECL_LINK( GetFocusHdl, Control* ); 207cdf0e10cSrcweir DECL_LINK( LoseFocusHdl, Control* ); 208cdf0e10cSrcweir DECL_LINK( ScrollHdl, ScrollBar* ); 209cdf0e10cSrcweir DECL_LINK( CursorUpHdl, ScCursorRefEdit* ); 210cdf0e10cSrcweir DECL_LINK( CursorDownHdl, ScCursorRefEdit* ); 211cdf0e10cSrcweir DECL_LINK( CondModifyHdl, Edit* ); 212cdf0e10cSrcweir DECL_LINK( TargetModifyHdl, Edit* ); 213cdf0e10cSrcweir DECL_LINK( SelectHdl, ListBox* ); 214cdf0e10cSrcweir }; 215cdf0e10cSrcweir 216cdf0e10cSrcweir 217cdf0e10cSrcweir class ScSolverProgressDialog : public ModelessDialog 218cdf0e10cSrcweir { 219cdf0e10cSrcweir FixedText maFtProgress; 220cdf0e10cSrcweir FixedText maFtTime; 221cdf0e10cSrcweir FixedLine maFlButtons; 222cdf0e10cSrcweir OKButton maBtnOk; 223cdf0e10cSrcweir 224cdf0e10cSrcweir public: 225cdf0e10cSrcweir ScSolverProgressDialog( Window* pParent ); 226cdf0e10cSrcweir ~ScSolverProgressDialog(); 227cdf0e10cSrcweir 228cdf0e10cSrcweir void HideTimeLimit(); 229cdf0e10cSrcweir void SetTimeLimit( sal_Int32 nSeconds ); 230cdf0e10cSrcweir }; 231cdf0e10cSrcweir 232cdf0e10cSrcweir class ScSolverNoSolutionDialog : public ModalDialog 233cdf0e10cSrcweir { 234cdf0e10cSrcweir FixedText maFtNoSolution; 235cdf0e10cSrcweir FixedText maFtErrorText; 236cdf0e10cSrcweir FixedLine maFlButtons; 237cdf0e10cSrcweir OKButton maBtnOk; 238cdf0e10cSrcweir 239cdf0e10cSrcweir public: 240cdf0e10cSrcweir ScSolverNoSolutionDialog( Window* pParent, const String& rErrorText ); 241cdf0e10cSrcweir ~ScSolverNoSolutionDialog(); 242cdf0e10cSrcweir }; 243cdf0e10cSrcweir 244cdf0e10cSrcweir class ScSolverSuccessDialog : public ModalDialog 245cdf0e10cSrcweir { 246cdf0e10cSrcweir FixedText maFtSuccess; 247cdf0e10cSrcweir FixedText maFtResult; 248cdf0e10cSrcweir FixedText maFtQuestion; 249cdf0e10cSrcweir FixedLine maFlButtons; 250cdf0e10cSrcweir OKButton maBtnOk; 251cdf0e10cSrcweir CancelButton maBtnCancel; 252cdf0e10cSrcweir 253cdf0e10cSrcweir public: 254cdf0e10cSrcweir ScSolverSuccessDialog( Window* pParent, const String& rSolution ); 255cdf0e10cSrcweir ~ScSolverSuccessDialog(); 256cdf0e10cSrcweir }; 257cdf0e10cSrcweir 258cdf0e10cSrcweir 259cdf0e10cSrcweir #endif 260cdf0e10cSrcweir 261