Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef SC_OPTSOLVER_HXX
21 : #define SC_OPTSOLVER_HXX
22 :
23 : #include "global.hxx"
24 : #include "address.hxx"
25 : #include "anyrefdg.hxx"
26 : #include <vcl/fixed.hxx>
27 : #include <vcl/group.hxx>
28 : #include <vcl/lstbox.hxx>
29 : #include <com/sun/star/uno/Sequence.hxx>
30 :
31 : #include <vector>
32 :
33 : namespace com { namespace sun { namespace star {
34 : namespace beans { struct PropertyValue; }
35 : } } }
36 :
37 0 : class ScCursorRefEdit : public formula::RefEdit
38 : {
39 : Link maCursorUpLink;
40 : Link maCursorDownLink;
41 :
42 : public:
43 : ScCursorRefEdit( Window* pParent, Window *pLabel );
44 : void SetCursorLinks( const Link& rUp, const Link& rDown );
45 :
46 : protected:
47 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
48 : };
49 :
50 :
51 : /// The dialog's content for a row, not yet parsed
52 0 : struct ScOptConditionRow
53 : {
54 : OUString aLeftStr;
55 : sal_uInt16 nOperator;
56 : OUString aRightStr;
57 :
58 0 : ScOptConditionRow() : nOperator(0) {}
59 0 : bool IsDefault() const { return aLeftStr.isEmpty() && aRightStr.isEmpty() && nOperator == 0; }
60 : };
61 :
62 : /// All settings from the dialog, saved with the DocShell for the next call
63 0 : class ScOptSolverSave
64 : {
65 : OUString maObjective;
66 : bool mbMax;
67 : bool mbMin;
68 : bool mbValue;
69 : OUString maTarget;
70 : OUString maVariable;
71 : std::vector<ScOptConditionRow> maConditions;
72 : OUString maEngine;
73 : com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> maProperties;
74 :
75 : public:
76 : ScOptSolverSave( const OUString& rObjective, bool bMax, bool bMin, bool bValue,
77 : const OUString& rTarget, const OUString& rVariable,
78 : const std::vector<ScOptConditionRow>& rConditions,
79 : const OUString& rEngine,
80 : const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rProperties );
81 :
82 0 : const OUString& GetObjective() const { return maObjective; }
83 0 : bool GetMax() const { return mbMax; }
84 0 : bool GetMin() const { return mbMin; }
85 0 : bool GetValue() const { return mbValue; }
86 0 : const OUString& GetTarget() const { return maTarget; }
87 0 : const OUString& GetVariable() const { return maVariable; }
88 0 : const std::vector<ScOptConditionRow>& GetConditions() const { return maConditions; }
89 0 : const OUString& GetEngine() const { return maEngine; }
90 0 : const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& GetProperties() const
91 0 : { return maProperties; }
92 : };
93 :
94 : class ScOptSolverDlg : public ScAnyRefDlg
95 : {
96 : public:
97 : ScOptSolverDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
98 : ScDocShell* pDocSh, ScAddress aCursorPos );
99 : virtual ~ScOptSolverDlg();
100 :
101 : virtual void SetReference( const ScRange& rRef, ScDocument* pDoc ) SAL_OVERRIDE;
102 : virtual bool IsRefInputMode() const SAL_OVERRIDE;
103 : virtual void SetActive() SAL_OVERRIDE;
104 : virtual bool Close() SAL_OVERRIDE;
105 :
106 : private:
107 : FixedText* m_pFtObjectiveCell;
108 : formula::RefEdit* m_pEdObjectiveCell;
109 : formula::RefButton* m_pRBObjectiveCell;
110 :
111 : RadioButton* m_pRbMax;
112 : RadioButton* m_pRbMin;
113 : RadioButton* m_pRbValue;
114 : formula::RefEdit* m_pEdTargetValue;
115 : formula::RefButton* m_pRBTargetValue;
116 :
117 : FixedText* m_pFtVariableCells;
118 : formula::RefEdit* m_pEdVariableCells;
119 : formula::RefButton* m_pRBVariableCells;
120 :
121 : FixedText* m_pFtCellRef; // labels are together with controls for the first row
122 : ScCursorRefEdit* m_pEdLeft1;
123 : formula::RefButton* m_pRBLeft1;
124 : FixedText* m_pFtOperator;
125 : ListBox* m_pLbOp1;
126 : FixedText* m_pFtConstraint;
127 : ScCursorRefEdit* m_pEdRight1;
128 : formula::RefButton* m_pRBRight1;
129 : PushButton* m_pBtnDel1;
130 :
131 : ScCursorRefEdit* m_pEdLeft2;
132 : formula::RefButton* m_pRBLeft2;
133 : ListBox* m_pLbOp2;
134 : ScCursorRefEdit* m_pEdRight2;
135 : formula::RefButton* m_pRBRight2;
136 : PushButton* m_pBtnDel2;
137 :
138 : ScCursorRefEdit* m_pEdLeft3;
139 : formula::RefButton* m_pRBLeft3;
140 : ListBox* m_pLbOp3;
141 : ScCursorRefEdit* m_pEdRight3;
142 : formula::RefButton* m_pRBRight3;
143 : PushButton* m_pBtnDel3;
144 :
145 : ScCursorRefEdit* m_pEdLeft4;
146 : formula::RefButton* m_pRBLeft4;
147 : ListBox* m_pLbOp4;
148 : ScCursorRefEdit* m_pEdRight4;
149 : formula::RefButton* m_pRBRight4;
150 : PushButton* m_pBtnDel4;
151 :
152 : ScrollBar* m_pScrollBar;
153 :
154 : PushButton* m_pBtnOpt;
155 : PushButton* m_pBtnCancel;
156 : PushButton* m_pBtnSolve;
157 :
158 : OUString maInputError;
159 : OUString maConditionError;
160 :
161 : ScDocShell* mpDocShell;
162 : ScDocument* mpDoc;
163 : const SCTAB mnCurTab;
164 : formula::RefEdit* mpEdActive;
165 : bool mbDlgLostFocus;
166 :
167 : static const sal_uInt16 EDIT_ROW_COUNT = 4;
168 : ScCursorRefEdit* mpLeftEdit[EDIT_ROW_COUNT];
169 : formula::RefButton* mpLeftButton[EDIT_ROW_COUNT];
170 : ScCursorRefEdit* mpRightEdit[EDIT_ROW_COUNT];
171 : formula::RefButton* mpRightButton[EDIT_ROW_COUNT];
172 : ListBox* mpOperator[EDIT_ROW_COUNT];
173 : PushButton* mpDelButton[EDIT_ROW_COUNT];
174 :
175 : std::vector<ScOptConditionRow> maConditions;
176 : long nScrollPos;
177 :
178 : com::sun::star::uno::Sequence<OUString> maImplNames;
179 : com::sun::star::uno::Sequence<OUString> maDescriptions;
180 : OUString maEngine;
181 : com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> maProperties;
182 :
183 : void Init(const ScAddress& rCursorPos);
184 : bool CallSolver();
185 : void ReadConditions();
186 : void ShowConditions();
187 : void EnableButtons();
188 : bool ParseRef( ScRange& rRange, const OUString& rInput, bool bAllowRange );
189 : bool FindTimeout( sal_Int32& rTimeout );
190 : void ShowError( bool bCondition, formula::RefEdit* pFocus );
191 :
192 : DECL_LINK( BtnHdl, PushButton* );
193 : DECL_LINK( DelBtnHdl, PushButton* );
194 : DECL_LINK( GetFocusHdl, Control* );
195 : DECL_LINK( LoseFocusHdl, void* );
196 : DECL_LINK(ScrollHdl, void *);
197 : DECL_LINK( CursorUpHdl, ScCursorRefEdit* );
198 : DECL_LINK( CursorDownHdl, ScCursorRefEdit* );
199 : DECL_LINK( CondModifyHdl, void* );
200 : DECL_LINK( TargetModifyHdl, void* );
201 : DECL_LINK( SelectHdl, void* );
202 : };
203 :
204 :
205 0 : class ScSolverProgressDialog : public ModelessDialog
206 : {
207 : FixedText* m_pFtTime;
208 :
209 : public:
210 : ScSolverProgressDialog( Window* pParent );
211 :
212 : void HideTimeLimit();
213 : void SetTimeLimit( sal_Int32 nSeconds );
214 : };
215 :
216 0 : class ScSolverNoSolutionDialog : public ModalDialog
217 : {
218 : FixedText* m_pFtErrorText;
219 :
220 : public:
221 : ScSolverNoSolutionDialog(Window* pParent, const OUString& rErrorText);
222 : };
223 :
224 0 : class ScSolverSuccessDialog : public ModalDialog
225 : {
226 : FixedText* m_pFtResult;
227 : PushButton* m_pBtnOk;
228 : PushButton* m_pBtnCancel;
229 :
230 : DECL_LINK(ClickHdl, PushButton*);
231 :
232 : public:
233 : ScSolverSuccessDialog( Window* pParent, const OUString& rSolution );
234 : };
235 :
236 :
237 : #endif
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|