1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef SC_OPTSOLVER_HXX
21 #define SC_OPTSOLVER_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>
33 namespace com
{ namespace sun
{ namespace star
{
34 namespace beans
{ struct PropertyValue
; }
37 //============================================================================
39 class ScCursorRefEdit
: public formula::RefEdit
42 Link maCursorDownLink
;
45 ScCursorRefEdit( Window
* pParent
, Window
*pLabel
);
46 void SetCursorLinks( const Link
& rUp
, const Link
& rDown
);
49 virtual void KeyInput( const KeyEvent
& rKEvt
);
53 /// The dialog's content for a row, not yet parsed
54 struct ScOptConditionRow
60 ScOptConditionRow() : nOperator(0) {}
61 bool IsDefault() const { return aLeftStr
.isEmpty() && aRightStr
.isEmpty() && nOperator
== 0; }
64 /// All settings from the dialog, saved with the DocShell for the next call
73 std::vector
<ScOptConditionRow
> maConditions
;
75 com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
> maProperties
;
78 ScOptSolverSave( const OUString
& rObjective
, sal_Bool bMax
, sal_Bool bMin
, sal_Bool bValue
,
79 const OUString
& rTarget
, const OUString
& rVariable
,
80 const std::vector
<ScOptConditionRow
>& rConditions
,
81 const OUString
& rEngine
,
82 const com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
>& rProperties
);
84 const OUString
& GetObjective() const { return maObjective
; }
85 sal_Bool
GetMax() const { return mbMax
; }
86 sal_Bool
GetMin() const { return mbMin
; }
87 sal_Bool
GetValue() const { return mbValue
; }
88 const OUString
& GetTarget() const { return maTarget
; }
89 const OUString
& GetVariable() const { return maVariable
; }
90 const std::vector
<ScOptConditionRow
>& GetConditions() const { return maConditions
; }
91 const OUString
& GetEngine() const { return maEngine
; }
92 const com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
>& GetProperties() const
93 { return maProperties
; }
96 class ScOptSolverDlg
: public ScAnyRefDlg
99 ScOptSolverDlg( SfxBindings
* pB
, SfxChildWindow
* pCW
, Window
* pParent
,
100 ScDocShell
* pDocSh
, ScAddress aCursorPos
);
103 virtual void SetReference( const ScRange
& rRef
, ScDocument
* pDoc
);
104 virtual sal_Bool
IsRefInputMode() const;
105 virtual void SetActive();
106 virtual sal_Bool
Close();
109 FixedText
* m_pFtObjectiveCell
;
110 formula::RefEdit
* m_pEdObjectiveCell
;
111 formula::RefButton
* m_pRBObjectiveCell
;
113 RadioButton
* m_pRbMax
;
114 RadioButton
* m_pRbMin
;
115 RadioButton
* m_pRbValue
;
116 formula::RefEdit
* m_pEdTargetValue
;
117 formula::RefButton
* m_pRBTargetValue
;
119 FixedText
* m_pFtVariableCells
;
120 formula::RefEdit
* m_pEdVariableCells
;
121 formula::RefButton
* m_pRBVariableCells
;
123 FixedText
* m_pFtCellRef
; // labels are together with controls for the first row
124 ScCursorRefEdit
* m_pEdLeft1
;
125 formula::RefButton
* m_pRBLeft1
;
126 FixedText
* m_pFtOperator
;
128 FixedText
* m_pFtConstraint
;
129 ScCursorRefEdit
* m_pEdRight1
;
130 formula::RefButton
* m_pRBRight1
;
131 PushButton
* m_pBtnDel1
;
133 ScCursorRefEdit
* m_pEdLeft2
;
134 formula::RefButton
* m_pRBLeft2
;
136 ScCursorRefEdit
* m_pEdRight2
;
137 formula::RefButton
* m_pRBRight2
;
138 PushButton
* m_pBtnDel2
;
140 ScCursorRefEdit
* m_pEdLeft3
;
141 formula::RefButton
* m_pRBLeft3
;
143 ScCursorRefEdit
* m_pEdRight3
;
144 formula::RefButton
* m_pRBRight3
;
145 PushButton
* m_pBtnDel3
;
147 ScCursorRefEdit
* m_pEdLeft4
;
148 formula::RefButton
* m_pRBLeft4
;
150 ScCursorRefEdit
* m_pEdRight4
;
151 formula::RefButton
* m_pRBRight4
;
152 PushButton
* m_pBtnDel4
;
154 ScrollBar
* m_pScrollBar
;
156 PushButton
* m_pBtnOpt
;
157 PushButton
* m_pBtnCancel
;
158 PushButton
* m_pBtnSolve
;
160 OUString maInputError
;
161 OUString maConditionError
;
163 ScDocShell
* mpDocShell
;
165 const SCTAB mnCurTab
;
166 formula::RefEdit
* mpEdActive
;
169 static const sal_uInt16 EDIT_ROW_COUNT
= 4;
170 ScCursorRefEdit
* mpLeftEdit
[EDIT_ROW_COUNT
];
171 formula::RefButton
* mpLeftButton
[EDIT_ROW_COUNT
];
172 ScCursorRefEdit
* mpRightEdit
[EDIT_ROW_COUNT
];
173 formula::RefButton
* mpRightButton
[EDIT_ROW_COUNT
];
174 ListBox
* mpOperator
[EDIT_ROW_COUNT
];
175 PushButton
* mpDelButton
[EDIT_ROW_COUNT
];
177 std::vector
<ScOptConditionRow
> maConditions
;
180 com::sun::star::uno::Sequence
<OUString
> maImplNames
;
181 com::sun::star::uno::Sequence
<OUString
> maDescriptions
;
183 com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
> maProperties
;
185 void Init(const ScAddress
& rCursorPos
);
187 void ReadConditions();
188 void ShowConditions();
189 void EnableButtons();
190 bool ParseRef( ScRange
& rRange
, const OUString
& rInput
, bool bAllowRange
);
191 bool FindTimeout( sal_Int32
& rTimeout
);
192 void ShowError( bool bCondition
, formula::RefEdit
* pFocus
);
194 DECL_LINK( BtnHdl
, PushButton
* );
195 DECL_LINK( DelBtnHdl
, PushButton
* );
196 DECL_LINK( GetFocusHdl
, Control
* );
197 DECL_LINK( LoseFocusHdl
, void* );
198 DECL_LINK(ScrollHdl
, void *);
199 DECL_LINK( CursorUpHdl
, ScCursorRefEdit
* );
200 DECL_LINK( CursorDownHdl
, ScCursorRefEdit
* );
201 DECL_LINK( CondModifyHdl
, void* );
202 DECL_LINK( TargetModifyHdl
, void* );
203 DECL_LINK( SelectHdl
, void* );
207 class ScSolverProgressDialog
: public ModelessDialog
209 FixedText maFtProgress
;
211 FixedLine maFlButtons
;
215 ScSolverProgressDialog( Window
* pParent
);
216 ~ScSolverProgressDialog();
218 void HideTimeLimit();
219 void SetTimeLimit( sal_Int32 nSeconds
);
222 class ScSolverNoSolutionDialog
: public ModalDialog
224 FixedText maFtNoSolution
;
225 FixedText maFtErrorText
;
226 FixedLine maFlButtons
;
230 ScSolverNoSolutionDialog( Window
* pParent
, const OUString
& rErrorText
);
231 ~ScSolverNoSolutionDialog();
234 class ScSolverSuccessDialog
: public ModalDialog
236 FixedText maFtSuccess
;
237 FixedText maFtResult
;
238 FixedText maFtQuestion
;
239 FixedLine maFlButtons
;
241 CancelButton maBtnCancel
;
244 ScSolverSuccessDialog( Window
* pParent
, const OUString
& rSolution
);
245 ~ScSolverSuccessDialog();
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */