1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SC_OPTSOLVER_HXX 29 #define SC_OPTSOLVER_HXX 30 31 #include "global.hxx" 32 #include "address.hxx" 33 #include "anyrefdg.hxx" 34 #include <vcl/fixed.hxx> 35 #include <vcl/group.hxx> 36 #include <vcl/lstbox.hxx> 37 #include <com/sun/star/uno/Sequence.hxx> 38 39 #include <vector> 40 41 namespace com { namespace sun { namespace star { 42 namespace beans { struct PropertyValue; } 43 } } } 44 45 //============================================================================ 46 47 class ScCursorRefEdit : public formula::RefEdit 48 { 49 Link maCursorUpLink; 50 Link maCursorDownLink; 51 52 public: 53 ScCursorRefEdit( ScAnyRefDlg* pParent, const ResId& rResId ); 54 void SetCursorLinks( const Link& rUp, const Link& rDown ); 55 56 protected: 57 virtual void KeyInput( const KeyEvent& rKEvt ); 58 }; 59 60 61 /// The dialog's content for a row, not yet parsed 62 struct ScOptConditionRow 63 { 64 String aLeftStr; 65 sal_uInt16 nOperator; 66 String aRightStr; 67 68 ScOptConditionRow() : nOperator(0) {} 69 bool IsDefault() const { return aLeftStr.Len() == 0 && aRightStr.Len() == 0 && nOperator == 0; } 70 }; 71 72 /// All settings from the dialog, saved with the DocShell for the next call 73 class ScOptSolverSave 74 { 75 String maObjective; 76 sal_Bool mbMax; 77 sal_Bool mbMin; 78 sal_Bool mbValue; 79 String maTarget; 80 String maVariable; 81 std::vector<ScOptConditionRow> maConditions; 82 String maEngine; 83 com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> maProperties; 84 85 public: 86 ScOptSolverSave( const String& rObjective, sal_Bool bMax, sal_Bool bMin, sal_Bool bValue, 87 const String& rTarget, const String& rVariable, 88 const std::vector<ScOptConditionRow>& rConditions, 89 const String& rEngine, 90 const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rProperties ); 91 92 const String& GetObjective() const { return maObjective; } 93 sal_Bool GetMax() const { return mbMax; } 94 sal_Bool GetMin() const { return mbMin; } 95 sal_Bool GetValue() const { return mbValue; } 96 const String& GetTarget() const { return maTarget; } 97 const String& GetVariable() const { return maVariable; } 98 const std::vector<ScOptConditionRow>& GetConditions() const { return maConditions; } 99 const String& GetEngine() const { return maEngine; } 100 const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& GetProperties() const 101 { return maProperties; } 102 }; 103 104 class ScOptSolverDlg : public ScAnyRefDlg 105 { 106 public: 107 ScOptSolverDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, 108 ScDocShell* pDocSh, ScAddress aCursorPos ); 109 ~ScOptSolverDlg(); 110 111 virtual void SetReference( const ScRange& rRef, ScDocument* pDoc ); 112 virtual sal_Bool IsRefInputMode() const; 113 virtual void SetActive(); 114 virtual sal_Bool Close(); 115 116 private: 117 FixedText maFtObjectiveCell; 118 formula::RefEdit maEdObjectiveCell; 119 formula::RefButton maRBObjectiveCell; 120 121 FixedText maFtDirection; 122 RadioButton maRbMax; 123 RadioButton maRbMin; 124 RadioButton maRbValue; 125 formula::RefEdit maEdTargetValue; 126 formula::RefButton maRBTargetValue; 127 128 FixedText maFtVariableCells; 129 formula::RefEdit maEdVariableCells; 130 formula::RefButton maRBVariableCells; 131 132 FixedLine maFlConditions; 133 134 FixedText maFtCellRef; // labels are together with controls for the first row 135 ScCursorRefEdit maEdLeft1; 136 formula::RefButton maRBLeft1; 137 FixedText maFtOperator; 138 ListBox maLbOp1; 139 FixedText maFtConstraint; 140 ScCursorRefEdit maEdRight1; 141 formula::RefButton maRBRight1; 142 ImageButton maBtnDel1; 143 144 ScCursorRefEdit maEdLeft2; 145 formula::RefButton maRBLeft2; 146 ListBox maLbOp2; 147 ScCursorRefEdit maEdRight2; 148 formula::RefButton maRBRight2; 149 ImageButton maBtnDel2; 150 151 ScCursorRefEdit maEdLeft3; 152 formula::RefButton maRBLeft3; 153 ListBox maLbOp3; 154 ScCursorRefEdit maEdRight3; 155 formula::RefButton maRBRight3; 156 ImageButton maBtnDel3; 157 158 ScCursorRefEdit maEdLeft4; 159 formula::RefButton maRBLeft4; 160 ListBox maLbOp4; 161 ScCursorRefEdit maEdRight4; 162 formula::RefButton maRBRight4; 163 ImageButton maBtnDel4; 164 165 ScrollBar maScrollBar; 166 167 FixedLine maFlButtons; 168 169 PushButton maBtnOpt; 170 HelpButton maBtnHelp; 171 CancelButton maBtnCancel; 172 PushButton maBtnSolve; 173 174 String maInputError; 175 String maConditionError; 176 177 ScDocShell* mpDocShell; 178 ScDocument* mpDoc; 179 const SCTAB mnCurTab; 180 formula::RefEdit* mpEdActive; 181 bool mbDlgLostFocus; 182 183 static const sal_uInt16 EDIT_ROW_COUNT = 4; 184 ScCursorRefEdit* mpLeftEdit[EDIT_ROW_COUNT]; 185 formula::RefButton* mpLeftButton[EDIT_ROW_COUNT]; 186 ScCursorRefEdit* mpRightEdit[EDIT_ROW_COUNT]; 187 formula::RefButton* mpRightButton[EDIT_ROW_COUNT]; 188 ListBox* mpOperator[EDIT_ROW_COUNT]; 189 ImageButton* mpDelButton[EDIT_ROW_COUNT]; 190 191 std::vector<ScOptConditionRow> maConditions; 192 long nScrollPos; 193 194 com::sun::star::uno::Sequence<rtl::OUString> maImplNames; 195 com::sun::star::uno::Sequence<rtl::OUString> maDescriptions; 196 String maEngine; 197 com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> maProperties; 198 199 void Init(const ScAddress& rCursorPos); 200 bool CallSolver(); 201 void ReadConditions(); 202 void ShowConditions(); 203 void EnableButtons(); 204 bool ParseRef( ScRange& rRange, const String& rInput, bool bAllowRange ); 205 bool FindTimeout( sal_Int32& rTimeout ); 206 void ShowError( bool bCondition, formula::RefEdit* pFocus ); 207 208 DECL_LINK( BtnHdl, PushButton* ); 209 DECL_LINK( DelBtnHdl, PushButton* ); 210 DECL_LINK( GetFocusHdl, Control* ); 211 DECL_LINK( LoseFocusHdl, Control* ); 212 DECL_LINK( ScrollHdl, ScrollBar* ); 213 DECL_LINK( CursorUpHdl, ScCursorRefEdit* ); 214 DECL_LINK( CursorDownHdl, ScCursorRefEdit* ); 215 DECL_LINK( CondModifyHdl, Edit* ); 216 DECL_LINK( TargetModifyHdl, Edit* ); 217 DECL_LINK( SelectHdl, ListBox* ); 218 }; 219 220 221 class ScSolverProgressDialog : public ModelessDialog 222 { 223 FixedText maFtProgress; 224 FixedText maFtTime; 225 FixedLine maFlButtons; 226 OKButton maBtnOk; 227 228 public: 229 ScSolverProgressDialog( Window* pParent ); 230 ~ScSolverProgressDialog(); 231 232 void HideTimeLimit(); 233 void SetTimeLimit( sal_Int32 nSeconds ); 234 }; 235 236 class ScSolverNoSolutionDialog : public ModalDialog 237 { 238 FixedText maFtNoSolution; 239 FixedText maFtErrorText; 240 FixedLine maFlButtons; 241 OKButton maBtnOk; 242 243 public: 244 ScSolverNoSolutionDialog( Window* pParent, const String& rErrorText ); 245 ~ScSolverNoSolutionDialog(); 246 }; 247 248 class ScSolverSuccessDialog : public ModalDialog 249 { 250 FixedText maFtSuccess; 251 FixedText maFtResult; 252 FixedText maFtQuestion; 253 FixedLine maFlButtons; 254 OKButton maBtnOk; 255 CancelButton maBtnCancel; 256 257 public: 258 ScSolverSuccessDialog( Window* pParent, const String& rSolution ); 259 ~ScSolverSuccessDialog(); 260 }; 261 262 263 #endif 264 265