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 INCLUDED_SC_SOURCE_UI_INC_OPTSOLVER_HXX
21 : #define INCLUDED_SC_SOURCE_UI_INC_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( vcl::Window* pParent, vcl::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 : /// The dialog's content for a row, not yet parsed
51 0 : struct ScOptConditionRow
52 : {
53 : OUString aLeftStr;
54 : sal_uInt16 nOperator;
55 : OUString aRightStr;
56 :
57 0 : ScOptConditionRow() : nOperator(0) {}
58 0 : bool IsDefault() const { return aLeftStr.isEmpty() && aRightStr.isEmpty() && nOperator == 0; }
59 : };
60 :
61 : /// All settings from the dialog, saved with the DocShell for the next call
62 0 : class ScOptSolverSave
63 : {
64 : OUString maObjective;
65 : bool mbMax;
66 : bool mbMin;
67 : bool mbValue;
68 : OUString maTarget;
69 : OUString maVariable;
70 : std::vector<ScOptConditionRow> maConditions;
71 : OUString maEngine;
72 : com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> maProperties;
73 :
74 : public:
75 : ScOptSolverSave( const OUString& rObjective, bool bMax, bool bMin, bool bValue,
76 : const OUString& rTarget, const OUString& rVariable,
77 : const std::vector<ScOptConditionRow>& rConditions,
78 : const OUString& rEngine,
79 : const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rProperties );
80 :
81 0 : const OUString& GetObjective() const { return maObjective; }
82 0 : bool GetMax() const { return mbMax; }
83 0 : bool GetMin() const { return mbMin; }
84 0 : bool GetValue() const { return mbValue; }
85 0 : const OUString& GetTarget() const { return maTarget; }
86 0 : const OUString& GetVariable() const { return maVariable; }
87 0 : const std::vector<ScOptConditionRow>& GetConditions() const { return maConditions; }
88 0 : const OUString& GetEngine() const { return maEngine; }
89 0 : const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& GetProperties() const
90 0 : { return maProperties; }
91 : };
92 :
93 : class ScOptSolverDlg : public ScAnyRefDlg
94 : {
95 : public:
96 : ScOptSolverDlg( SfxBindings* pB, SfxChildWindow* pCW, vcl::Window* pParent,
97 : ScDocShell* pDocSh, ScAddress aCursorPos );
98 : virtual ~ScOptSolverDlg();
99 :
100 : virtual void SetReference( const ScRange& rRef, ScDocument* pDoc ) SAL_OVERRIDE;
101 : virtual bool IsRefInputMode() const SAL_OVERRIDE;
102 : virtual void SetActive() SAL_OVERRIDE;
103 : virtual bool Close() SAL_OVERRIDE;
104 :
105 : private:
106 : FixedText* m_pFtObjectiveCell;
107 : formula::RefEdit* m_pEdObjectiveCell;
108 : formula::RefButton* m_pRBObjectiveCell;
109 :
110 : RadioButton* m_pRbMax;
111 : RadioButton* m_pRbMin;
112 : RadioButton* m_pRbValue;
113 : formula::RefEdit* m_pEdTargetValue;
114 : formula::RefButton* m_pRBTargetValue;
115 :
116 : FixedText* m_pFtVariableCells;
117 : formula::RefEdit* m_pEdVariableCells;
118 : formula::RefButton* m_pRBVariableCells;
119 :
120 : FixedText* m_pFtCellRef; // labels are together with controls for the first row
121 : ScCursorRefEdit* m_pEdLeft1;
122 : formula::RefButton* m_pRBLeft1;
123 : FixedText* m_pFtOperator;
124 : ListBox* m_pLbOp1;
125 : FixedText* m_pFtConstraint;
126 : ScCursorRefEdit* m_pEdRight1;
127 : formula::RefButton* m_pRBRight1;
128 : PushButton* m_pBtnDel1;
129 :
130 : ScCursorRefEdit* m_pEdLeft2;
131 : formula::RefButton* m_pRBLeft2;
132 : ListBox* m_pLbOp2;
133 : ScCursorRefEdit* m_pEdRight2;
134 : formula::RefButton* m_pRBRight2;
135 : PushButton* m_pBtnDel2;
136 :
137 : ScCursorRefEdit* m_pEdLeft3;
138 : formula::RefButton* m_pRBLeft3;
139 : ListBox* m_pLbOp3;
140 : ScCursorRefEdit* m_pEdRight3;
141 : formula::RefButton* m_pRBRight3;
142 : PushButton* m_pBtnDel3;
143 :
144 : ScCursorRefEdit* m_pEdLeft4;
145 : formula::RefButton* m_pRBLeft4;
146 : ListBox* m_pLbOp4;
147 : ScCursorRefEdit* m_pEdRight4;
148 : formula::RefButton* m_pRBRight4;
149 : PushButton* m_pBtnDel4;
150 :
151 : ScrollBar* m_pScrollBar;
152 :
153 : PushButton* m_pBtnOpt;
154 : PushButton* m_pBtnCancel;
155 : PushButton* m_pBtnSolve;
156 :
157 : OUString maInputError;
158 : OUString maConditionError;
159 :
160 : ScDocShell* mpDocShell;
161 : ScDocument& mrDoc;
162 : const SCTAB mnCurTab;
163 : formula::RefEdit* mpEdActive;
164 : bool mbDlgLostFocus;
165 :
166 : static const sal_uInt16 EDIT_ROW_COUNT = 4;
167 : ScCursorRefEdit* mpLeftEdit[EDIT_ROW_COUNT];
168 : formula::RefButton* mpLeftButton[EDIT_ROW_COUNT];
169 : ScCursorRefEdit* mpRightEdit[EDIT_ROW_COUNT];
170 : formula::RefButton* mpRightButton[EDIT_ROW_COUNT];
171 : ListBox* mpOperator[EDIT_ROW_COUNT];
172 : PushButton* mpDelButton[EDIT_ROW_COUNT];
173 :
174 : std::vector<ScOptConditionRow> maConditions;
175 : long nScrollPos;
176 :
177 : com::sun::star::uno::Sequence<OUString> maImplNames;
178 : com::sun::star::uno::Sequence<OUString> maDescriptions;
179 : OUString maEngine;
180 : com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> maProperties;
181 :
182 : void Init(const ScAddress& rCursorPos);
183 : bool CallSolver();
184 : void ReadConditions();
185 : void ShowConditions();
186 : void EnableButtons();
187 : bool ParseRef( ScRange& rRange, const OUString& rInput, bool bAllowRange );
188 : bool FindTimeout( sal_Int32& rTimeout );
189 : void ShowError( bool bCondition, formula::RefEdit* pFocus );
190 :
191 : DECL_LINK( BtnHdl, PushButton* );
192 : DECL_LINK( DelBtnHdl, PushButton* );
193 : DECL_LINK( GetFocusHdl, Control* );
194 : DECL_LINK( LoseFocusHdl, void* );
195 : DECL_LINK(ScrollHdl, void *);
196 : DECL_LINK( CursorUpHdl, ScCursorRefEdit* );
197 : DECL_LINK( CursorDownHdl, ScCursorRefEdit* );
198 : DECL_LINK( CondModifyHdl, void* );
199 : DECL_LINK( TargetModifyHdl, void* );
200 : DECL_LINK( SelectHdl, void* );
201 : };
202 :
203 0 : class ScSolverProgressDialog : public ModelessDialog
204 : {
205 : FixedText* m_pFtTime;
206 :
207 : public:
208 : ScSolverProgressDialog( vcl::Window* pParent );
209 :
210 : void HideTimeLimit();
211 : void SetTimeLimit( sal_Int32 nSeconds );
212 : };
213 :
214 0 : class ScSolverNoSolutionDialog : public ModalDialog
215 : {
216 : FixedText* m_pFtErrorText;
217 :
218 : public:
219 : ScSolverNoSolutionDialog(vcl::Window* pParent, const OUString& rErrorText);
220 : };
221 :
222 0 : class ScSolverSuccessDialog : public ModalDialog
223 : {
224 : FixedText* m_pFtResult;
225 : PushButton* m_pBtnOk;
226 : PushButton* m_pBtnCancel;
227 :
228 : DECL_LINK(ClickHdl, PushButton*);
229 :
230 : public:
231 : ScSolverSuccessDialog( vcl::Window* pParent, const OUString& rSolution );
232 : };
233 :
234 : #endif
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|