1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optsolver.hxx,v $
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
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>
44 namespace com
{ namespace sun
{ namespace star
{
45 namespace beans
{ struct PropertyValue
; }
48 //============================================================================
50 class ScCursorRefEdit
: public formula::RefEdit
53 Link maCursorDownLink
;
56 ScCursorRefEdit( ScAnyRefDlg
* pParent
, const ResId
& rResId
);
57 void SetCursorLinks( const Link
& rUp
, const Link
& rDown
);
60 virtual void KeyInput( const KeyEvent
& rKEvt
);
64 /// The dialog's content for a row, not yet parsed
65 struct ScOptConditionRow
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
84 std::vector
<ScOptConditionRow
> maConditions
;
86 com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
> maProperties
;
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
110 ScOptSolverDlg( SfxBindings
* pB
, SfxChildWindow
* pCW
, Window
* pParent
,
111 ScDocShell
* pDocSh
, ScAddress aCursorPos
);
114 virtual void SetReference( const ScRange
& rRef
, ScDocument
* pDoc
);
115 virtual BOOL
IsRefInputMode() const;
116 virtual void SetActive();
117 virtual BOOL
Close();
120 FixedText maFtObjectiveCell
;
121 formula::RefEdit maEdObjectiveCell
;
122 formula::RefButton maRBObjectiveCell
;
124 FixedText maFtDirection
;
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
;
142 FixedText maFtConstraint
;
143 ScCursorRefEdit maEdRight1
;
144 formula::RefButton maRBRight1
;
145 ImageButton maBtnDel1
;
147 ScCursorRefEdit maEdLeft2
;
148 formula::RefButton maRBLeft2
;
150 ScCursorRefEdit maEdRight2
;
151 formula::RefButton maRBRight2
;
152 ImageButton maBtnDel2
;
154 ScCursorRefEdit maEdLeft3
;
155 formula::RefButton maRBLeft3
;
157 ScCursorRefEdit maEdRight3
;
158 formula::RefButton maRBRight3
;
159 ImageButton maBtnDel3
;
161 ScCursorRefEdit maEdLeft4
;
162 formula::RefButton maRBLeft4
;
164 ScCursorRefEdit maEdRight4
;
165 formula::RefButton maRBRight4
;
166 ImageButton maBtnDel4
;
168 ScrollBar maScrollBar
;
170 FixedLine maFlButtons
;
173 HelpButton maBtnHelp
;
174 CancelButton maBtnCancel
;
175 PushButton maBtnSolve
;
178 String maConditionError
;
180 ScDocShell
* mpDocShell
;
182 const SCTAB mnCurTab
;
183 formula::RefEdit
* mpEdActive
;
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
;
197 com::sun::star::uno::Sequence
<rtl::OUString
> maImplNames
;
198 com::sun::star::uno::Sequence
<rtl::OUString
> maDescriptions
;
200 com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
> maProperties
;
202 void Init(const ScAddress
& rCursorPos
);
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
;
228 FixedLine maFlButtons
;
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
;
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
;
258 CancelButton maBtnCancel
;
261 ScSolverSuccessDialog( Window
* pParent
, const String
& rSolution
);
262 ~ScSolverSuccessDialog();