summaryrefslogtreecommitdiff
path: root/patches/scsolver/scsolver-source-ui-optiondlg-cxx.diff
blob: 2eb8b9be268663c7b115b357508052284908e6a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
--- /dev/null	
+++ scsolver/source/ui/optiondlg.cxx	
@@ -0,0 +1,190 @@
+/*************************************************************************
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Kohei Yoshida.
+ *    1039 Kingsway Dr., Apex, NC 27502, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+
+#include "optiondlg.hxx"
+#include "unoglobal.hxx"
+#include "global.hxx"
+#include "listener.hxx"
+#include "solver.hxx"
+
+#include "com/sun/star/awt/XCheckBox.hpp"
+
+#include "scsolver.hrc"
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace std;
+
+namespace scsolver {
+
+/**
+ * This class defines the action to be performed when the OK
+ * button in the Option dialog is pressed.
+ */
+class OptionDlgOKAction : public ActionObject
+{
+public:
+	OptionDlgOKAction()
+	{
+	}
+
+	virtual ~OptionDlgOKAction() throw()
+	{
+	}
+
+	virtual void execute( BaseDialog *dlg, const awt::ActionEvent &e )
+	{
+		OptionDialog* p = static_cast<OptionDialog*>(dlg);
+		p->setVisible(false);
+		p->getSolverImpl()->getOptionData()->setModelType( p->getModelType() );
+	}
+};
+
+/**
+ * Specifies the action to perform when the window closing event
+ * is received (typically when the user clicks the close button
+ * on the title bar).
+ */
+class OptionDlgWinCloseAction : public SimpleActionObject
+{
+public:
+	virtual void execute( BaseDialog *dlg )
+	{
+		dlg->close();
+	}
+};
+
+//-----------------------------------------------------------------
+
+struct OptionDialogImpl
+{
+	auto_ptr<ActionObject>       pActionOK;
+	auto_ptr<SimpleActionObject> pActionWinClose;
+
+	TopWindowListener* pTopWinListener;
+	ActionListener*    pOKListener;
+	CloseBtnListener*  pCloseListener;
+};
+
+//-----------------------------------------------------------------
+
+OptionDialog::OptionDialog( SolverImpl* p ) :
+	BaseDialog( p ),
+	m_pImpl( new OptionDialogImpl )
+{
+	initialize();
+}
+
+OptionDialog::~OptionDialog() throw()
+{
+}
+
+void OptionDialog::initialize()
+{
+	int nWidth = 200, nHeight = 150;
+	BaseDialog::initialize( 
+		static_cast<sal_Int16>(nWidth), static_cast<sal_Int16>(nHeight), 
+		ascii_i18n("Options") );
+
+	sal_Int32 nX = 5, nY = 5, nMargin = 5;
+
+	addFixedLine( nX, nY, nWidth-nX-nMargin, 12, ascii("flOptions"), 
+				  ascii_i18n("Options") );
+	nY += 13;
+	addCheckBox( nX, nY+2, nWidth-nX-nMargin, 12, ascii("cbLinear"),
+				 ascii_i18n("Assume linear model") );
+
+	addButton( nWidth-110, nHeight-20, 50, 15, ascii("btnOK"), 
+			   getResStr(SCSOLVER_STR_BTN_OK) );
+
+	addButton( nWidth-55, nHeight-20, 50, 15, ascii("btnCancel"), 
+			   getResStr(SCSOLVER_STR_BTN_CANCEL) );
+
+	registerListeners();
+}
+
+void OptionDialog::registerListeners()
+{
+	m_pImpl->pActionOK.reset( new OptionDlgOKAction );
+	m_pImpl->pOKListener = new ActionListener( this, m_pImpl->pActionOK.get() );
+	registerListener( ascii("btnOK"), m_pImpl->pOKListener );
+
+	m_pImpl->pCloseListener = new CloseBtnListener(this);
+	registerListener( ascii("btnCancel"), m_pImpl->pCloseListener );
+
+	m_pImpl->pActionWinClose.reset( new OptionDlgWinCloseAction );
+	m_pImpl->pTopWinListener = new TopWindowListener(this);
+	m_pImpl->pTopWinListener->setActionClosing(m_pImpl->pActionWinClose.get());
+	registerListener( m_pImpl->pTopWinListener );
+}
+
+void OptionDialog::unregisterListeners() throw()
+{
+	unregisterListener( ascii("btnOK"), m_pImpl->pOKListener );
+	unregisterListener( ascii("btnCancel"), m_pImpl->pCloseListener );
+	unregisterListener( m_pImpl->pTopWinListener );
+}
+
+bool OptionDialog::doneRangeSelection() const
+{
+	return false;
+}
+
+void OptionDialog::close()
+{
+	setVisible(false);
+}
+
+const rtl::OUString OptionDialog::getDialogName() const
+{
+	return ascii("OptionDialog");
+}
+
+void OptionDialog::setVisible( bool b )
+{
+	setVisibleDefault( b );
+}
+
+OptModelType OptionDialog::getModelType() const
+{
+	Reference<uno::XInterface> oWgt = getWidgetByName( ascii("cbLinear") );
+	Reference<awt::XCheckBox> xCB( oWgt, UNO_QUERY );
+
+	return xCB->getState() ? OPTMODELTYPE_LP : OPTMODELTYPE_NLP;
+}
+
+void OptionDialog::setModelType( OptModelType type )
+{
+	Reference<uno::XInterface> oWgt = getWidgetByName( ascii("cbLinear") );
+	Reference<awt::XCheckBox> xCB( oWgt, UNO_QUERY );
+	if ( type == OPTMODELTYPE_LP || type == OPTMODELTYPE_MILP )
+		xCB->setState(1);
+	else
+		xCB->setState(0);
+}
+
+}