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 INCLUDED_SC_SOURCE_UI_INC_OPTSOLVER_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_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 class ScCursorRefEdit
: public formula::RefEdit
39 Link
<> maCursorUpLink
;
40 Link
<> maCursorDownLink
;
43 ScCursorRefEdit( vcl::Window
* pParent
, vcl::Window
*pLabel
);
44 void SetCursorLinks( const Link
<>& rUp
, const Link
<>& rDown
);
47 virtual void KeyInput( const KeyEvent
& rKEvt
) SAL_OVERRIDE
;
50 /// The dialog's content for a row, not yet parsed
51 struct ScOptConditionRow
57 ScOptConditionRow() : nOperator(0) {}
58 bool IsDefault() const { return aLeftStr
.isEmpty() && aRightStr
.isEmpty() && nOperator
== 0; }
61 /// All settings from the dialog, saved with the DocShell for the next call
70 std::vector
<ScOptConditionRow
> maConditions
;
72 com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
> maProperties
;
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
);
81 const OUString
& GetObjective() const { return maObjective
; }
82 bool GetMax() const { return mbMax
; }
83 bool GetMin() const { return mbMin
; }
84 bool GetValue() const { return mbValue
; }
85 const OUString
& GetTarget() const { return maTarget
; }
86 const OUString
& GetVariable() const { return maVariable
; }
87 const std::vector
<ScOptConditionRow
>& GetConditions() const { return maConditions
; }
88 const OUString
& GetEngine() const { return maEngine
; }
89 const com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
>& GetProperties() const
90 { return maProperties
; }
93 class ScOptSolverDlg
: public ScAnyRefDlg
96 ScOptSolverDlg( SfxBindings
* pB
, SfxChildWindow
* pCW
, vcl::Window
* pParent
,
97 ScDocShell
* pDocSh
, ScAddress aCursorPos
);
98 virtual ~ScOptSolverDlg();
99 virtual void dispose() SAL_OVERRIDE
;
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
;
107 VclPtr
<FixedText
> m_pFtObjectiveCell
;
108 VclPtr
<formula::RefEdit
> m_pEdObjectiveCell
;
109 VclPtr
<formula::RefButton
> m_pRBObjectiveCell
;
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
;
117 VclPtr
<FixedText
> m_pFtVariableCells
;
118 VclPtr
<formula::RefEdit
> m_pEdVariableCells
;
119 VclPtr
<formula::RefButton
> m_pRBVariableCells
;
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
;
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
;
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
;
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
;
152 VclPtr
<ScrollBar
> m_pScrollBar
;
154 VclPtr
<PushButton
> m_pBtnOpt
;
155 VclPtr
<PushButton
> m_pBtnCancel
;
156 VclPtr
<PushButton
> m_pBtnSolve
;
158 OUString maInputError
;
159 OUString maConditionError
;
161 ScDocShell
* mpDocShell
;
163 const SCTAB mnCurTab
;
164 VclPtr
<formula::RefEdit
> mpEdActive
;
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
];
175 std::vector
<ScOptConditionRow
> maConditions
;
178 com::sun::star::uno::Sequence
<OUString
> maImplNames
;
179 com::sun::star::uno::Sequence
<OUString
> maDescriptions
;
181 com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
> maProperties
;
183 void Init(const ScAddress
& rCursorPos
);
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
);
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* );
204 class ScSolverProgressDialog
: public ModelessDialog
206 VclPtr
<FixedText
> m_pFtTime
;
209 ScSolverProgressDialog( vcl::Window
* pParent
);
210 virtual ~ScSolverProgressDialog();
211 virtual void dispose() SAL_OVERRIDE
;
213 void HideTimeLimit();
214 void SetTimeLimit( sal_Int32 nSeconds
);
217 class ScSolverNoSolutionDialog
: public ModalDialog
219 VclPtr
<FixedText
> m_pFtErrorText
;
222 ScSolverNoSolutionDialog(vcl::Window
* pParent
, const OUString
& rErrorText
);
223 virtual ~ScSolverNoSolutionDialog();
224 virtual void dispose() SAL_OVERRIDE
;
227 class ScSolverSuccessDialog
: public ModalDialog
229 VclPtr
<FixedText
> m_pFtResult
;
230 VclPtr
<PushButton
> m_pBtnOk
;
231 VclPtr
<PushButton
> m_pBtnCancel
;
233 DECL_LINK(ClickHdl
, PushButton
*);
236 ScSolverSuccessDialog( vcl::Window
* pParent
, const OUString
& rSolution
);
237 virtual ~ScSolverSuccessDialog();
238 virtual void dispose() SAL_OVERRIDE
;
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */