00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "listener.hxx"
00030 #include "solver.hxx"
00031 #include "dialog.hxx"
00032 #include "unoglobal.hxx"
00033 #include "tool/global.hxx"
00034 #include "msgdlg.hxx"
00035 #include "xcalc.hxx"
00036 #include "optiondlg.hxx"
00037
00038 #include <memory>
00039 #include <iostream>
00040
00041 #include <com/sun/star/awt/XTextComponent.hpp>
00042
00043 #include <com/sun/star/beans/XPropertySet.hpp>
00044
00045 #include <com/sun/star/frame/XDispatchProvider.hpp>
00046 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
00047
00048 #include <com/sun/star/lang/XComponent.hpp>
00049 #include <com/sun/star/lang/XInitialization.hpp>
00050 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
00051 #include <com/sun/star/sheet/XRangeSelection.hpp>
00052 #include <com/sun/star/sheet/XSpreadsheet.hpp>
00053 #include <com/sun/star/table/XCell.hpp>
00054 #include <com/sun/star/table/XCellRange.hpp>
00055 #include <com/sun/star/uno/XComponentContext.hpp>
00056
00057
00058 namespace scsolver {
00059
00060
00061
00062
00063 RngSelListener::RngSelListener( BaseDialog* pDlg, RngBtnListener* pBtn,
00064 const rtl::OUString& sEditName )
00065 {
00066 m_pDlg = pDlg;
00067 m_pBtn = pBtn;
00068 m_sEditName = sEditName;
00069 }
00070
00071 RngSelListener::~RngSelListener() throw()
00072 {
00073 }
00074
00075 void RngSelListener::disposing( const lang::EventObject& ) throw ( RuntimeException )
00076 {
00077 }
00078
00079 void RngSelListener::done( const sheet::RangeSelectionEvent& oEvt ) throw ( RuntimeException )
00080 {
00081
00082
00083
00084 if ( m_pBtn->isEventOwner() )
00085 {
00086 rtl::OUString sRange = oEvt.RangeDescriptor;
00087
00088 Reference< uno::XInterface > oRngEdit = m_pDlg->getWidgetByName( m_sEditName );
00089 Reference< awt::XTextComponent > xComp( oRngEdit, UNO_QUERY );
00090 rtl::OUString sRangeOld = xComp->getText();
00091 xComp->setText( sRange );
00092
00093 if ( !m_pDlg->doneRangeSelection() )
00094 xComp->setText( sRangeOld );
00095
00096 m_pDlg->setVisible( true );
00097 m_pBtn->setEventOwner( false );
00098 }
00099 }
00100
00101 void RngSelListener::aborted( const sheet::RangeSelectionEvent& ) throw ( RuntimeException )
00102 {
00103 Debug("RngSelListener::aborted");
00104 if (m_pBtn->isEventOwner())
00105 {
00106 m_pDlg->doneRangeSelection();
00107 m_pDlg->setVisible( true );
00108 m_pBtn->setEventOwner(false);
00109 }
00110 }
00111
00112
00113
00114
00115
00116 RngBtnListener::RngBtnListener( BaseDialog* pDlg,
00117 Reference< sheet::XRangeSelection > xRngSel, const rtl::OUString& sEditName )
00118
00119 : ActionListener( pDlg ),
00120
00121 m_xRngSel( xRngSel ),
00122 m_pRngSelListener( NULL ),
00123 m_sEditName( sEditName ),
00124 m_bEventOwner( false ),
00125 m_bSingleCell( false )
00126 {
00127 registerRngSelListener();
00128 }
00129
00130 RngBtnListener::~RngBtnListener() throw()
00131 {
00132 if ( m_xRngSel.is() )
00133 {
00134
00135
00136
00137 m_xRngSel->removeRangeSelectionListener( m_pRngSelListener );
00138 }
00139 else
00140 Debug( "m_xRngSel == NULL!" );
00141 }
00142
00143 void RngBtnListener::disposing( const lang::EventObject& )
00144 throw ( RuntimeException )
00145 {
00146 }
00147
00148 void RngBtnListener::actionPerformed( const awt::ActionEvent& oActionEvt )
00149 throw ( RuntimeException )
00150 {
00151 if ( m_xRngSel != NULL )
00152 {
00153 uno::Sequence< beans::PropertyValue > aProp( 3 );
00154 uno::Any aValue;
00155 aValue <<= ascii_i18n( "Please select a range" );
00156 aProp[0].Name = ascii( "Title" );
00157 aProp[0].Value = aValue;
00158 aProp[1].Name = ascii( "CloseOnMouseRelease" );
00159 aValue <<= static_cast<sal_Bool>(false);
00160 aProp[1].Value = aValue;
00161
00162
00163
00164 setEventOwner( true );
00165
00166 m_xRngSel->startRangeSelection( aProp );
00167
00168
00169 getDialog()->setVisible( false );
00170
00171 if ( getDialog()->getDialogName().equals( ascii( "ConstEditDialog" ) ) )
00172 {
00173 SolverDialog* pMainDlg = getDialog()->getSolverImpl()->getMainDialog();
00174 pMainDlg->setVisible( false );
00175 }
00176 }
00177 else
00178 Debug( "Range selection interface NULL" );
00179 }
00180
00181 void RngBtnListener::registerRngSelListener()
00182 {
00183 if ( m_pRngSelListener == NULL && m_xRngSel != NULL )
00184 {
00185 m_pRngSelListener = new RngSelListener( getDialog(), this, m_sEditName );
00186 m_xRngSel->addRangeSelectionListener( m_pRngSelListener );
00187 }
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197 SolveBtnListener::SolveBtnListener( SolverDialog* pDlg ) : ActionListener( pDlg )
00198 {
00199 }
00200
00201 SolveBtnListener::~SolveBtnListener() throw()
00202 {
00203 }
00204
00205 void SolveBtnListener::disposing( const lang::EventObject& )
00206 throw ( RuntimeException )
00207 {
00208 }
00209
00210 void SolveBtnListener::actionPerformed( const awt::ActionEvent& )
00211 throw ( RuntimeException )
00212 {
00213 getDialog()->getSolverImpl()->solveModel();
00214 }
00215
00216
00217
00218
00219
00220 CloseBtnListener::CloseBtnListener( BaseDialog* pDlg ) : ActionListener( pDlg )
00221 {
00222 }
00223
00224 CloseBtnListener::~CloseBtnListener() throw()
00225 {
00226 }
00227
00228 void CloseBtnListener::disposing( const lang::EventObject& )
00229 throw ( RuntimeException )
00230 {
00231 }
00232
00233 void CloseBtnListener::actionPerformed( const awt::ActionEvent& )
00234 throw ( RuntimeException )
00235 {
00236 getDialog()->close();
00237 }
00238
00239
00240
00241
00242
00243 SaveBtnListener::SaveBtnListener( SolverDialog* pDlg ) : ActionListener( pDlg )
00244 {
00245 }
00246
00247 SaveBtnListener::~SaveBtnListener() throw()
00248 {
00249 }
00250
00251 void SaveBtnListener::disposing( const lang::EventObject& )
00252 throw ( RuntimeException )
00253 {
00254 }
00255
00256 void SaveBtnListener::actionPerformed( const awt::ActionEvent& )
00257 throw ( RuntimeException )
00258 {
00259 getDialog()->getSolverImpl()->getMainDialog()->saveModelToDocument();
00260 }
00261
00262
00263
00264
00265
00266 LoadBtnListener::LoadBtnListener( SolverDialog* pDlg ) : ActionListener( pDlg )
00267 {
00268 }
00269
00270 LoadBtnListener::~LoadBtnListener() throw()
00271 {
00272 }
00273
00274 void LoadBtnListener::disposing( const lang::EventObject& )
00275 throw ( RuntimeException )
00276 {
00277 }
00278
00279 void LoadBtnListener::actionPerformed( const awt::ActionEvent& )
00280 throw ( RuntimeException )
00281 {
00282 getDialog()->getSolverImpl()->getMainDialog()->loadModelFromDocument();
00283 }
00284
00285
00286
00287
00288
00289 ResetBtnListener::ResetBtnListener( SolverDialog* pDlg ) : ActionListener( pDlg ),
00290 m_pDlg( NULL )
00291 {
00292 }
00293
00294 ResetBtnListener::~ResetBtnListener() throw()
00295 {
00296 }
00297
00298 void ResetBtnListener::disposing( const lang::EventObject& )
00299 throw ( RuntimeException )
00300 {
00301 }
00302
00303 void ResetBtnListener::actionPerformed( const awt::ActionEvent& )
00304 throw ( RuntimeException )
00305 {
00306 getDialog()->getSolverImpl()->getMainDialog()->reset();
00307 }
00308
00309
00310
00311 OptionBtnListener::OptionBtnListener( SolverDialog* pDlg ) :
00312 ActionListener( pDlg )
00313 {
00314 }
00315
00316 OptionBtnListener::~OptionBtnListener() throw()
00317 {
00318 }
00319
00320 void OptionBtnListener::disposing( const lang::EventObject& )
00321 throw ( RuntimeException )
00322 {
00323 }
00324
00325 void OptionBtnListener::actionPerformed( const awt::ActionEvent& )
00326 throw ( RuntimeException )
00327 {
00328 SolverImpl* p = getDialog()->getSolverImpl();
00329 OptionDialog* pDlg = p->getMainDialog()->getOptionDialog();
00330 pDlg->setModelType( p->getOptionData()->getModelType() );
00331 pDlg->setVisible(true);
00332 }
00333
00334
00335
00336
00337
00338 ConstEditBtnListener::ConstEditBtnListener( SolverDialog* pDlg, ConstButtonType eType ) :
00339 ActionListener( pDlg )
00340 {
00341 m_eBtnType = eType;
00342 }
00343
00344 ConstEditBtnListener::~ConstEditBtnListener() throw()
00345 {
00346 }
00347
00348 void ConstEditBtnListener::disposing( const lang::EventObject& )
00349 throw ( RuntimeException )
00350 {
00351 }
00352
00353 void ConstEditBtnListener::actionPerformed( const awt::ActionEvent& )
00354 throw ( RuntimeException )
00355 {
00356 BaseDialog* pDlg = getDialog();
00357
00358 ConstButtonType eType = getButtonType();
00359 SolverDialog* pMainDlg = pDlg->getSolverImpl()->getMainDialog();
00360 switch( eType )
00361 {
00362 case CONST_ADD:
00363 case CONST_CHANGE:
00364 {
00365 ConstEditDialog* pCE = pMainDlg->getConstEditDialog();
00366 if ( pCE != NULL )
00367 {
00368
00369
00370
00371 pCE->setVisible( true );
00372 if ( eType == CONST_CHANGE )
00373 {
00374
00375 sal_Int16 nSel = pMainDlg->getSelectedConstraintPos();
00376 if (nSel < 0)
00377
00378 return;
00379
00380 rtl::OUString sLeft, sRight;
00381 EqualityType eEq;
00382 pMainDlg->getConstraint( nSel, sLeft, sRight, eEq );
00383 pCE->setLeftCellReference( sLeft );
00384 pCE->setRightCellReference( sRight );
00385 pCE->setEquality( eEq );
00386
00387 pCE->setChangeMode( true );
00388 pCE->setConstraintId( nSel );
00389 }
00390 else
00391 {
00392 OSL_ASSERT( eType == CONST_ADD );
00393 pCE->setChangeMode( false );
00394 }
00395 }
00396 else
00397 OSL_ASSERT( !"ConstEditDialog is NULL" );
00398 }
00399 break;
00400
00401 case CONST_DELETE:
00402 {
00403
00404
00405
00406 sal_Int16 nSel = pMainDlg->getSelectedConstraintPos();
00407 if (nSel < 0)
00408
00409 return;
00410 pMainDlg->removeConstraint( nSel );
00411 }
00412 break;
00413
00414 default:
00415 OSL_ASSERT( !"Wrong button type!" );
00416 break;
00417 }
00418 pMainDlg->updateWidgets();
00419 }
00420
00421
00422
00423
00424 ConstListBoxListener::ConstListBoxListener( SolverDialog* pDlg ) : ItemListener( pDlg )
00425 {
00426 }
00427
00428 void ConstListBoxListener::itemStateChanged( const awt::ItemEvent& )
00429 throw ( RuntimeException )
00430 {
00431 getDialog()->enableWidget( ascii( "btnConstChange" ) );
00432 getDialog()->enableWidget( ascii( "btnConstDelete" ) );
00433 }
00434
00435
00436
00437
00438
00439 MaxRadioBtnListener::MaxRadioBtnListener( SolverDialog* pDlg ) : ItemListener( pDlg )
00440 {
00441 }
00442
00443 MaxRadioBtnListener::~MaxRadioBtnListener() throw()
00444 {
00445 }
00446
00447 void MaxRadioBtnListener::disposing( const lang::EventObject& )
00448 throw ( RuntimeException )
00449 {
00450 }
00451
00452 void MaxRadioBtnListener::itemStateChanged( const awt::ItemEvent& )
00453 throw ( RuntimeException )
00454 {
00455 }
00456
00457
00458
00459 WindowFocusListener::WindowFocusListener( BaseDialog* pDlg ) : FocusListener( pDlg )
00460 {
00461 }
00462
00463 void WindowFocusListener::focusGained( const awt::FocusEvent& ) throw( RuntimeException )
00464 {
00465 Debug( "focusGained" );
00466 }
00467
00468 void WindowFocusListener::focusLost( const awt::FocusEvent& ) throw( RuntimeException )
00469 {
00470 Debug( "focusLost" );
00471 }
00472
00473
00474 WindowMouseListener::WindowMouseListener( BaseDialog* pDlg ) : MouseListener( pDlg )
00475 {
00476 }
00477
00478 WindowMouseListener::~WindowMouseListener() throw()
00479 {
00480 }
00481
00482 void WindowMouseListener::mousePressed( const awt::MouseEvent& )
00483 throw( RuntimeException )
00484 {
00485 }
00486
00487
00488 OKCancelBtnListener::OKCancelBtnListener( BaseDialog* pDlg, const rtl::OUString& sMode ) :
00489 ActionListener( pDlg )
00490 {
00491 m_sMode = sMode;
00492 }
00493
00494 OKCancelBtnListener::~OKCancelBtnListener() throw()
00495 {
00496 }
00497
00498 void OKCancelBtnListener::disposing( const lang::EventObject& )
00499 throw ( RuntimeException )
00500 {
00501 }
00502
00503 void OKCancelBtnListener::actionPerformed( const awt::ActionEvent& )
00504 throw ( RuntimeException )
00505 {
00506 SolverDialog* pMainDlg = getDialog()->getSolverImpl()->getMainDialog();
00507 ConstEditDialog* pDlg = pMainDlg->getConstEditDialog();
00508
00509 if ( m_sMode.equals( ascii ( "OK" ) ) )
00510 {
00511 rtl::OUString sLeft = pDlg->getLeftCellReference();
00512 rtl::OUString sRight = pDlg->getRightCellReference();
00513 EqualityType eEq = pDlg->getEquality();
00514
00515 if ( pDlg->isChangeMode() )
00516 pMainDlg->editConstraint( pDlg->getConstraintId(), sLeft, sRight, eEq );
00517 else
00518 pMainDlg->setConstraint( sLeft, sRight, eEq );
00519 }
00520
00521 pDlg->setVisible( false );
00522 pDlg->reset();
00523 pMainDlg->updateWidgets();
00524 }
00525
00526
00527 }