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