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