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 : virtual void dispose() SAL_OVERRIDE;
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 : VclPtr<FixedText> m_pFtObjectiveCell;
108 : VclPtr<formula::RefEdit> m_pEdObjectiveCell;
109 : VclPtr<formula::RefButton> m_pRBObjectiveCell;
110 :
111 : VclPtr<RadioButton> m_pRbMax;
112 : VclPtr<RadioButton> m_pRbMin;
113 : VclPtr<RadioButton> m_pRbValue;
114 : VclPtr<formula::RefEdit> m_pEdTargetValue;
115 : VclPtr<formula::RefButton> m_pRBTargetValue;
116 :
117 : VclPtr<FixedText> m_pFtVariableCells;
118 : VclPtr<formula::RefEdit> m_pEdVariableCells;
119 : VclPtr<formula::RefButton> m_pRBVariableCells;
120 :
121 : VclPtr<FixedText> m_pFtCellRef; // labels are together with controls for the first row
122 : VclPtr<ScCursorRefEdit> m_pEdLeft1;
123 : VclPtr<formula::RefButton> m_pRBLeft1;
124 : VclPtr<FixedText> m_pFtOperator;
125 : VclPtr<ListBox> m_pLbOp1;
126 : VclPtr<FixedText> m_pFtConstraint;
127 : VclPtr<ScCursorRefEdit> m_pEdRight1;
128 : VclPtr<formula::RefButton> m_pRBRight1;
129 : VclPtr<PushButton> m_pBtnDel1;
130 :
131 : VclPtr<ScCursorRefEdit> m_pEdLeft2;
132 : VclPtr<formula::RefButton> m_pRBLeft2;
133 : VclPtr<ListBox> m_pLbOp2;
134 : VclPtr<ScCursorRefEdit> m_pEdRight2;
135 : VclPtr<formula::RefButton> m_pRBRight2;
136 : VclPtr<PushButton> m_pBtnDel2;
137 :
138 : VclPtr<ScCursorRefEdit> m_pEdLeft3;
139 : VclPtr<formula::RefButton> m_pRBLeft3;
140 : VclPtr<ListBox> m_pLbOp3;
141 : VclPtr<ScCursorRefEdit> m_pEdRight3;
142 : VclPtr<formula::RefButton> m_pRBRight3;
143 : VclPtr<PushButton> m_pBtnDel3;
144 :
145 : VclPtr<ScCursorRefEdit> m_pEdLeft4;
146 : VclPtr<formula::RefButton> m_pRBLeft4;
147 : VclPtr<ListBox> m_pLbOp4;
148 : VclPtr<ScCursorRefEdit> m_pEdRight4;
149 : VclPtr<formula::RefButton> m_pRBRight4;
150 : VclPtr<PushButton> m_pBtnDel4;
151 :
152 : VclPtr<ScrollBar> m_pScrollBar;
153 :
154 : VclPtr<PushButton> m_pBtnOpt;
155 : VclPtr<PushButton> m_pBtnCancel;
156 : VclPtr<PushButton> m_pBtnSolve;
157 :
158 : OUString maInputError;
159 : OUString maConditionError;
160 :
161 : ScDocShell* mpDocShell;
162 : ScDocument& mrDoc;
163 : const SCTAB mnCurTab;
164 : VclPtr<formula::RefEdit> mpEdActive;
165 : bool mbDlgLostFocus;
166 :
167 : static const sal_uInt16 EDIT_ROW_COUNT = 4;
168 : VclPtr<ScCursorRefEdit> mpLeftEdit[EDIT_ROW_COUNT];
169 : VclPtr<formula::RefButton> mpLeftButton[EDIT_ROW_COUNT];
170 : VclPtr<ScCursorRefEdit> mpRightEdit[EDIT_ROW_COUNT];
171 : VclPtr<formula::RefButton> mpRightButton[EDIT_ROW_COUNT];
172 : VclPtr<ListBox> mpOperator[EDIT_ROW_COUNT];
173 : VclPtr<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 : class ScSolverProgressDialog : public ModelessDialog
205 : {
206 : VclPtr<FixedText> m_pFtTime;
207 :
208 : public:
209 : ScSolverProgressDialog( vcl::Window* pParent );
210 : virtual ~ScSolverProgressDialog();
211 : virtual void dispose() SAL_OVERRIDE;
212 :
213 : void HideTimeLimit();
214 : void SetTimeLimit( sal_Int32 nSeconds );
215 : };
216 :
217 : class ScSolverNoSolutionDialog : public ModalDialog
218 : {
219 : VclPtr<FixedText> m_pFtErrorText;
220 :
221 : public:
222 : ScSolverNoSolutionDialog(vcl::Window* pParent, const OUString& rErrorText);
223 : virtual ~ScSolverNoSolutionDialog();
224 : virtual void dispose() SAL_OVERRIDE;
225 : };
226 :
227 : class ScSolverSuccessDialog : public ModalDialog
228 : {
229 : VclPtr<FixedText> m_pFtResult;
230 : VclPtr<PushButton> m_pBtnOk;
231 : VclPtr<PushButton> m_pBtnCancel;
232 :
233 : DECL_LINK(ClickHdl, PushButton*);
234 :
235 : public:
236 : ScSolverSuccessDialog( vcl::Window* pParent, const OUString& rSolution );
237 : virtual ~ScSolverSuccessDialog();
238 : virtual void dispose() SAL_OVERRIDE;
239 : };
240 :
241 : #endif
242 :
243 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|