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