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