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 <iostream>
00030
00031 #include "basedlg.hxx"
00032 #include "tool/global.hxx"
00033 #include "unoglobal.hxx"
00034 #include "type.hxx"
00035 #include "solver.hxx"
00036 #include "listener.hxx"
00037 #include "xcalc.hxx"
00038
00039 #include <com/sun/star/beans/XPropertySet.hpp>
00040 #include <com/sun/star/container/XNameContainer.hpp>
00041
00042 #include <com/sun/star/awt/PosSize.hpp>
00043 #include <com/sun/star/awt/Rectangle.hpp>
00044 #include <com/sun/star/awt/XButton.hpp>
00045 #include <com/sun/star/awt/XControl.hpp>
00046 #include <com/sun/star/awt/XControlContainer.hpp>
00047 #include <com/sun/star/awt/XControlModel.hpp>
00048 #include <com/sun/star/awt/XDialog.hpp>
00049 #include <com/sun/star/awt/XListBox.hpp>
00050 #include <com/sun/star/awt/XRadioButton.hpp>
00051 #include <com/sun/star/awt/XTextComponent.hpp>
00052 #include <com/sun/star/awt/XTopWindow.hpp>
00053 #include <com/sun/star/awt/XWindow.hpp>
00054
00055 #include <memory>
00056
00057 using namespace com::sun::star;
00058 using uno::Any;
00059 using ::std::auto_ptr;
00060
00061 namespace scsolver {
00062
00068 #if SCSOLVER_DEBUG
00069 void lcl_dumpServiceNames( const Reference< uno::XInterface >& oWgt )
00070 {
00071 if (oWgt == NULL)
00072 return;
00073 Reference< lang::XServiceInfo > xSN( oWgt, UNO_QUERY );
00074 Sequence< rtl::OUString > sSN = xSN->getSupportedServiceNames();
00075 for ( int nIdx = 0; nIdx < sSN.getLength(); ++nIdx )
00076 printOUStr( sSN[nIdx] );
00077
00078 OSL_ASSERT( !"No appropriate widget type got picked up!" );
00079 }
00080 #else
00081 void lcl_dumpServiceNames( const Reference< uno::XInterface >& )
00082 {
00083 }
00084 #endif
00085
00086
00087
00088
00089 class BaseDialogImpl
00090 {
00091
00092 public:
00093 BaseDialogImpl( SolverImpl* );
00094 ~BaseDialogImpl();
00095
00096 void initialize( sal_Int32 nW, sal_Int32 nH, const rtl::OUString& );
00097 void setVisibleDefault( bool );
00098
00099 uno::Reference < uno::XInterface > getDialog() const { return m_oDlg; }
00100 uno::Reference < uno::XInterface > getDialogModel() const { return m_oDlgModel; }
00101 uno::Reference < uno::XInterface > getWidgetByName( const rtl::OUString& );
00102 uno::Reference < uno::XInterface > getRangeEditWidget();
00103 SolverImpl* getSolverImpl() const { return m_pSolverImpl; }
00104
00105 void enableWidget( const rtl::OUString&, sal_Bool );
00106 void toFront();
00107 void setFocus() const;
00108 void execute();
00109
00110 void setRefBoundingBox(const awt::Rectangle* rect);
00111 const awt::Rectangle* getPosSize();
00112
00113 apWidgetProp addButton( sal_Int32, sal_Int32, sal_Int32, sal_Int32,
00114 const rtl::OUString &, const rtl::OUString &, sal_Int16 = awt::PushButtonType_STANDARD );
00115
00116 apWidgetProp addButtonImage( sal_Int32, sal_Int32, sal_Int32, sal_Int32,
00117 const rtl::OUString &, const rtl::OUString &, sal_Int16 = awt::PushButtonType_STANDARD );
00118
00119 apWidgetProp addEdit( sal_Int32, sal_Int32, sal_Int32, sal_Int32, const rtl::OUString & );
00120
00121 apWidgetProp addFixedLine( sal_Int32, sal_Int32, sal_Int32, sal_Int32,
00122 const rtl::OUString &, const rtl::OUString &, sal_Int32 = 0 );
00123
00124 apWidgetProp addFixedText( sal_Int32, sal_Int32, sal_Int32, sal_Int32,
00125 const rtl::OUString &, const rtl::OUString & );
00126
00127 apWidgetProp addGroupBox( sal_Int32, sal_Int32, sal_Int32, sal_Int32, const rtl::OUString & );
00128
00129 apWidgetProp addListBox( sal_Int32, sal_Int32, sal_Int32, sal_Int32, const rtl::OUString & );
00130
00131 apWidgetProp addRadioButton( sal_Int32, sal_Int32, sal_Int32, sal_Int32,
00132 const rtl::OUString &, const rtl::OUString & );
00133
00134 apWidgetProp addCheckBox( sal_Int32 x, sal_Int32 y, sal_Int32 w, sal_Int32 h,
00135 const rtl::OUString& name, const rtl::OUString& label )
00136 {
00137 apWidgetProp p = addWidget(
00138 ascii("com.sun.star.awt.UnoControlCheckBoxModel"), x, y, w, h, name );
00139 p->setLabel(label);
00140 return p;
00141 }
00142
00143 apWidgetProp addRangeEdit( sal_Int32, sal_Int32, sal_Int32, sal_Int32,
00144 const rtl::OUString &, const rtl::OUString & );
00145
00146 apWidgetProp addWidget( const rtl::OUString&,
00147 sal_Int32, sal_Int32, sal_Int32, sal_Int32, const rtl::OUString & );
00148
00149 template<typename ListenerT>
00150 void registerListener( ListenerT* );
00151
00152 template<typename ListenerT>
00153 void registerListener( const rtl::OUString &, ListenerT* );
00154
00155 void registerListener( TopWindowListener* p )
00156 {
00157 Reference<awt::XTopWindow> xTW(getDialog(), UNO_QUERY);
00158 xTW->addTopWindowListener(p);
00159 }
00160
00161 void registerListener( const Reference< uno::XInterface >&, ActionListener* );
00162 void registerListener( const Reference< uno::XInterface >&, ItemListener* );
00163 void registerListener( const Reference< uno::XInterface >&, FocusListener* );
00164 void registerListener( const Reference< uno::XInterface >&, MouseListener* );
00165
00166 template<typename ListenerT>
00167 void unregisterListener( ListenerT* );
00168
00169 template<typename ListenerT>
00170 void unregisterListener( const rtl::OUString &, ListenerT* );
00171
00172 void unregisterListener( const Reference< uno::XInterface >&, ActionListener* );
00173 void unregisterListener( const Reference< uno::XInterface >&, ItemListener* );
00174 void unregisterListener( const Reference< uno::XInterface >&, FocusListener* );
00175 void unregisterListener( const Reference< uno::XInterface >&, MouseListener* );
00176
00177 void unregisterListener( const Reference<uno::XInterface>& oWgt, TopWindowListener* p )
00178 {
00179 Reference<awt::XTopWindow> xWnd(oWgt, UNO_QUERY);
00180 if ( xWnd.is() )
00181 {
00182 xWnd->removeTopWindowListener( p );
00183 return;
00184 }
00185 lcl_dumpServiceNames( oWgt );
00186 }
00187
00188 private:
00189
00190 SolverImpl* m_pSolverImpl;
00191 auto_ptr<awt::Rectangle> mpDlgPosSize;
00192 auto_ptr<awt::Rectangle> mpRefBoundingBox;
00193 bool mbIsVisible;
00194
00195 uno::Reference< uno::XInterface > m_oDlg;
00196 uno::Reference< uno::XInterface > m_oDlgModel;
00197 };
00198
00199
00200
00201 BaseDialogImpl::BaseDialogImpl( SolverImpl* p ) :
00202 m_pSolverImpl(p),
00203 mpDlgPosSize(NULL),
00204 mbIsVisible(false)
00205 {
00206 }
00207
00208 BaseDialogImpl::~BaseDialogImpl()
00209 {
00210 }
00211
00212 void BaseDialogImpl::initialize( sal_Int32 nW, sal_Int32 nH, const rtl::OUString& sTitle )
00213 {
00214 CalcInterface* pCalc = getSolverImpl()->getCalcInterface();
00215 Reference< lang::XMultiComponentFactory > xSM = pCalc->getServiceManager();
00216 Reference< uno::XComponentContext > xCC = pCalc->getComponentContext();
00217
00218 m_oDlg = xSM->createInstanceWithContext(
00219 ascii( "com.sun.star.awt.UnoControlDialog" ), xCC );
00220 m_oDlgModel = xSM->createInstanceWithContext(
00221 ascii( "com.sun.star.awt.UnoControlDialogModel" ), xCC );
00222
00223
00224 Reference< awt::XControl > xCtrl( m_oDlg, UNO_QUERY );
00225 Reference< awt::XControlModel > xCtrlModel( m_oDlgModel, UNO_QUERY );
00226 xCtrl->setModel( xCtrlModel );
00227
00228 Reference< beans::XPropertySet > xPS( m_oDlgModel, UNO_QUERY );
00229 uno::Any aWidth, aHeight, aTitle, aCloseable;
00230 aWidth <<= nW;
00231 aHeight <<= nH;
00232 aTitle <<= sTitle;
00233 aCloseable <<= static_cast<sal_Bool>(true);
00234 xPS->setPropertyValue( ascii( "Width" ), aWidth );
00235 xPS->setPropertyValue( ascii( "Height" ), aHeight );
00236 xPS->setPropertyValue( ascii( "Title" ), aTitle );
00237 xPS->setPropertyValue( ascii("Closeable"), aCloseable );
00238 }
00239
00240 void BaseDialogImpl::setVisibleDefault( bool bVisible )
00241 {
00242 if (bVisible == mbIsVisible)
00243 return;
00244
00245 Reference< awt::XWindow > xWnd(m_oDlg, UNO_QUERY);
00246 if (!xWnd.is())
00247 {
00248 Debug("xWnd is NULL!");
00249 return;
00250 }
00251
00252 if (bVisible)
00253 {
00254
00255 if (mpDlgPosSize.get())
00256 {
00257
00258 xWnd->setPosSize(mpDlgPosSize->X, mpDlgPosSize->Y, mpDlgPosSize->Width,
00259 mpDlgPosSize->Height, awt::PosSize::POS);
00260 }
00261 else if (mpRefBoundingBox.get())
00262 {
00263
00264
00265
00266 const awt::Rectangle* pRect = getPosSize();
00267 if (pRect)
00268 {
00269 sal_Int32 xoffset = (mpRefBoundingBox->Width - pRect->Width)/2;
00270 sal_Int32 yoffset = (mpRefBoundingBox->Height - pRect->Height)/2;
00271 xWnd->setPosSize(mpRefBoundingBox->X + xoffset,
00272 mpRefBoundingBox->Y + yoffset,
00273 0, 0, awt::PosSize::POS);
00274 }
00275 }
00276 }
00277 else
00278 {
00279
00280 if (!mpDlgPosSize.get())
00281 mpDlgPosSize.reset(new awt::Rectangle);
00282 *mpDlgPosSize = xWnd->getPosSize();
00283 }
00284
00285 xWnd->setVisible(bVisible);
00286 mbIsVisible = bVisible;
00287 }
00288
00289 apWidgetProp BaseDialogImpl::addButton(
00290 sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00291 const rtl::OUString& sName, const rtl::OUString& sLabel, sal_Int16 nPushBtnType )
00292 {
00293 apWidgetProp p = addWidget( ascii( "com.sun.star.awt.UnoControlButtonModel" ),
00294 nX, nY, nW, nH, sName );
00295
00296 p->setLabel( sLabel );
00297 p->setPropertyValue( "PushButtonType", nPushBtnType );
00298
00299 return p;
00300 }
00301
00302 apWidgetProp BaseDialogImpl::addButtonImage(
00303 sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00304 const rtl::OUString& sName, const rtl::OUString& sUrl, sal_Int16 nPushBtnType )
00305 {
00306 apWidgetProp p = addWidget( ascii( "com.sun.star.awt.UnoControlButtonModel" ),
00307 nX, nY, nW, nH, sName );
00308 uno::Any aType, aUrl;
00309 aType <<= nPushBtnType;
00310 aUrl <<= sUrl;
00311
00312 p->setPropertyValue( "ImageURL", aUrl );
00313 p->setPropertyValue( "PushButtonType", aType );
00314
00315 return p;
00316 }
00317
00318 apWidgetProp BaseDialogImpl::addEdit( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00319 const rtl::OUString& sName )
00320 {
00321 apWidgetProp p = addWidget( ascii( "com.sun.star.awt.UnoControlEditModel" ),
00322 nX, nY, nW, nH, sName );
00323
00324 return p;
00325 }
00326
00327 apWidgetProp BaseDialogImpl::addFixedLine( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00328 const rtl::OUString& sName, const rtl::OUString& sLabel, sal_Int32 nOrientation )
00329 {
00330 apWidgetProp p = addWidget( ascii( "com.sun.star.awt.UnoControlFixedLineModel" ),
00331 nX, nY, nW, nH, sName );
00332
00333 if ( sLabel.getLength() )
00334 p->setLabel( sLabel );
00335
00336 uno::Any aOrientation;
00337 aOrientation <<= nOrientation;
00338 p->setPropertyValue( "Orientation", aOrientation );
00339
00340 return p;
00341 }
00342
00343 apWidgetProp BaseDialogImpl::addFixedText( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00344 const rtl::OUString& sName, const rtl::OUString& sLabel )
00345 {
00346 apWidgetProp p = addWidget(
00347 ascii( "com.sun.star.awt.UnoControlFixedTextModel" ), nX, nY, nW, nH, sName );
00348 p->setLabel( sLabel );
00349
00350 return p;
00351 }
00352
00353 apWidgetProp BaseDialogImpl::addGroupBox( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00354 const rtl::OUString& sName )
00355 {
00356 apWidgetProp p = addWidget( ascii( "com.sun.star.awt.UnoControlGroupBoxModel" ),
00357 nX, nY, nW, nH, sName );
00358 p->setLabel( ascii( "Group Box Label" ) );
00359
00360 return p;
00361 }
00362
00363 apWidgetProp BaseDialogImpl::addListBox( sal_Int32 nX, sal_Int32 nY,
00364 sal_Int32 nW, sal_Int32 nH, const rtl::OUString& sName )
00365 {
00366 apWidgetProp p = addWidget(
00367 ascii( "com.sun.star.awt.UnoControlListBoxModel" ), nX, nY, nW, nH, sName );
00368
00369 return p;
00370 }
00371
00372 apWidgetProp BaseDialogImpl::addRadioButton( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00373 const rtl::OUString& sName, const rtl::OUString& sLabel )
00374 {
00375 apWidgetProp p = addWidget(
00376 ascii( "com.sun.star.awt.UnoControlRadioButtonModel" ), nX, nY, nW, nH, sName );
00377 p->setLabel( sLabel );
00378 return p;
00379 }
00380
00381 apWidgetProp BaseDialogImpl::addRangeEdit( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00382 const rtl::OUString& sEditName, const rtl::OUString& sBtnName )
00383 {
00384
00385
00386 const sal_Int32 nGap = 2, nBtnW = 13, nBtnH = 15;
00387
00388 apWidgetProp p = addWidget(ascii("com.sun.star.awt.UnoControlEditModel"),
00389 nX, nY, nW - nGap - nBtnW, nH, sEditName);
00390
00391
00392 addButtonImage(nX + nW - nBtnW, nY-1, nBtnW, nBtnH, sBtnName,
00393 ascii("private:resource/sc/image/25041"));
00394 return p;
00395 }
00396
00397 apWidgetProp BaseDialogImpl::addWidget( const rtl::OUString& sWidgetName,
00398 sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, const rtl::OUString& sName )
00399 {
00400 Reference< lang::XMultiServiceFactory > xMSF( m_oDlgModel, UNO_QUERY );
00401 Reference< container::XNameContainer > xNC( m_oDlgModel, UNO_QUERY );
00402
00403 Reference< uno::XInterface > oModel = xMSF->createInstance( sWidgetName );
00404 Any aWidget;
00405 aWidget <<= oModel;
00406 xNC->insertByName( sName, aWidget );
00407
00408 apWidgetProp pProp( new WidgetProperty( oModel ) );
00409 pProp->setPositionX( nX );
00410 pProp->setPositionY( nY );
00411 pProp->setWidth( nWidth );
00412 pProp->setHeight( nHeight );
00413 pProp->setName( sName );
00414
00415 return pProp;
00416 }
00417
00418
00419 Reference< uno::XInterface > BaseDialogImpl::getRangeEditWidget()
00420 {
00421 return getWidgetByName( ascii( "editVarCells" ) );
00422 }
00423
00424
00425 Reference< uno::XInterface > BaseDialogImpl::getWidgetByName( const rtl::OUString& sName )
00426 {
00427 Reference< awt::XControlContainer > xCtrlContainer( m_oDlg, UNO_QUERY );
00428 Reference< uno::XInterface > xWidget = xCtrlContainer->getControl( sName );
00429 Reference< lang::XServiceInfo > xSN( xWidget, UNO_QUERY );
00430
00431 return xWidget;
00432 }
00433
00434 template<typename ListenerT>
00435 void BaseDialogImpl::registerListener( ListenerT* p )
00436 {
00437 registerListener( getDialog(), p );
00438 }
00439
00440 template<typename ListenerT>
00441 void BaseDialogImpl::registerListener( const rtl::OUString& sName, ListenerT* p )
00442 {
00443 registerListener( getWidgetByName( sName ), p );
00444 }
00445
00446
00447 void BaseDialogImpl::registerListener( const Reference< uno::XInterface >& oWgt, ActionListener* p )
00448 {
00449 OSL_ASSERT( oWgt != NULL );
00450
00451 Reference< awt::XButton > xWidget( oWgt, UNO_QUERY );
00452 if ( xWidget.is() )
00453 {
00454 xWidget->addActionListener( p );
00455 return;
00456 }
00457
00458 lcl_dumpServiceNames( oWgt );
00459 }
00460
00461 void BaseDialogImpl::registerListener( const Reference< uno::XInterface >& oWgt, ItemListener* p )
00462 {
00463 Reference< awt::XRadioButton > xRB( oWgt, UNO_QUERY );
00464 if ( xRB.is() )
00465 {
00466 xRB->addItemListener( p );
00467 return;
00468 }
00469
00470 Reference< awt::XListBox > xLB( oWgt, UNO_QUERY );
00471 if ( xLB.is() )
00472 {
00473 xLB->addItemListener( p );
00474 return;
00475 }
00476
00477 lcl_dumpServiceNames( oWgt );
00478 }
00479
00480 void BaseDialogImpl::registerListener( const Reference< uno::XInterface >& oWgt, FocusListener* p )
00481 {
00482 Reference< awt::XWindow > xWnd( oWgt, UNO_QUERY );
00483 if ( xWnd.is() )
00484 {
00485 xWnd->addFocusListener( p );
00486 return;
00487 }
00488
00489 lcl_dumpServiceNames( oWgt );
00490 }
00491
00492 void BaseDialogImpl::registerListener( const Reference< uno::XInterface >& oWgt, MouseListener* p )
00493 {
00494 Reference< awt::XWindow > xWnd( oWgt, UNO_QUERY );
00495 if ( xWnd.is() )
00496 {
00497 xWnd->addMouseListener( p );
00498 return;
00499 }
00500
00501 lcl_dumpServiceNames( oWgt );
00502 }
00503
00504 template<typename ListenerT>
00505 void BaseDialogImpl::unregisterListener( ListenerT* p )
00506 {
00507 unregisterListener( getDialog(), p );
00508 }
00509
00510 template<typename ListenerT>
00511 void BaseDialogImpl::unregisterListener( const rtl::OUString& sName, ListenerT* p )
00512 {
00513 Reference<uno::XInterface> oWgt = getWidgetByName(sName);
00514 if (oWgt == NULL)
00515 {
00516 printOUStr(ascii("warning: widget named ") + sName + ascii(" does not exist, thus cannot be unregistered."));
00517 return;
00518 }
00519 unregisterListener(oWgt, p);
00520 }
00521
00522 void BaseDialogImpl::unregisterListener( const Reference< uno::XInterface >& oWgt, ActionListener* p )
00523 {
00524 OSL_ASSERT( oWgt != NULL );
00525 Reference< awt::XButton > xWidget( oWgt, UNO_QUERY );
00526 if ( xWidget.is() )
00527 {
00528 xWidget->removeActionListener( p );
00529 return;
00530 }
00531
00532 lcl_dumpServiceNames( oWgt );
00533 }
00534
00535 void BaseDialogImpl::unregisterListener( const Reference< uno::XInterface >& oWgt, ItemListener* p )
00536 {
00537 Reference< awt::XRadioButton > xRB( oWgt, UNO_QUERY );
00538 if ( xRB.is() )
00539 {
00540 xRB->removeItemListener( p );
00541 return;
00542 }
00543
00544 Reference< awt::XListBox > xLB( oWgt, UNO_QUERY );
00545 if ( xLB.is() )
00546 {
00547 xLB->removeItemListener( p );
00548 return;
00549 }
00550
00551 lcl_dumpServiceNames( oWgt );
00552 }
00553
00554 void BaseDialogImpl::unregisterListener( const Reference< uno::XInterface >& oWgt, FocusListener* p )
00555 {
00556 Reference< awt::XWindow > xWnd( oWgt, UNO_QUERY );
00557 if ( xWnd.is() )
00558 {
00559 xWnd->removeFocusListener( p );
00560 return;
00561 }
00562
00563 lcl_dumpServiceNames( oWgt );
00564 }
00565
00566 void BaseDialogImpl::unregisterListener( const Reference< uno::XInterface >& oWgt, MouseListener* p )
00567 {
00568 Reference< awt::XWindow > xWnd( oWgt, UNO_QUERY );
00569 if ( xWnd.is() )
00570 {
00571 xWnd->removeMouseListener( static_cast<MouseListener*>( p ) );
00572 return;
00573 }
00574
00575 lcl_dumpServiceNames( oWgt );
00576 }
00577
00578 void BaseDialogImpl::enableWidget( const rtl::OUString& sName, sal_Bool bEnable )
00579 {
00580 Reference< uno::XInterface > oWgt = getWidgetByName( sName );
00581 Reference< awt::XWindow > xWnd( oWgt, UNO_QUERY );
00582 if (!xWnd.is())
00583 return;
00584 xWnd->setEnable( bEnable );
00585 }
00586
00587 void BaseDialogImpl::toFront()
00588 {
00589 Reference< awt::XTopWindow > xWnd( m_oDlg, UNO_QUERY );
00590 if (!xWnd.is())
00591 return;
00592 xWnd->toFront();
00593 }
00594
00595 void BaseDialogImpl::setFocus() const
00596 {
00597 Reference<awt::XWindow> xWnd(m_oDlg, UNO_QUERY);
00598 if (!xWnd.is())
00599 return;
00600
00601 xWnd->setFocus();
00602 }
00603
00604 void BaseDialogImpl::execute()
00605 {
00606 setVisibleDefault( true );
00607 toFront();
00608 Reference< awt::XDialog > xDlg( m_oDlg, UNO_QUERY );
00609 xDlg->execute();
00610 }
00611
00612 void BaseDialogImpl::setRefBoundingBox(const awt::Rectangle* rect)
00613 {
00614 if (!rect)
00615 return;
00616
00617 if (!mpRefBoundingBox.get())
00618 mpRefBoundingBox.reset(new awt::Rectangle);
00619 *mpRefBoundingBox = *rect;
00620 }
00621
00622 const awt::Rectangle* BaseDialogImpl::getPosSize()
00623 {
00624 Reference< awt::XWindow > xWnd(m_oDlg, UNO_QUERY);
00625 if (xWnd.is())
00626 mpDlgPosSize.reset(new awt::Rectangle(xWnd->getPosSize()));
00627 return mpDlgPosSize.get();
00628 }
00629
00630
00631
00632
00633 BaseDialog::BaseDialog( SolverImpl* p ) : m_pImpl( new BaseDialogImpl( p ) )
00634 {
00635 }
00636
00637 BaseDialog::~BaseDialog() throw()
00638 {
00639 }
00640
00641 void BaseDialog::setRefBoundingBox(const awt::Rectangle* rect)
00642 {
00643 m_pImpl->setRefBoundingBox(rect);
00644 }
00645
00646 const awt::Rectangle* BaseDialog::getPosSize() const
00647 {
00648 return m_pImpl->getPosSize();
00649 }
00650
00651 void BaseDialog::initializeDefault( sal_Int16 nW, sal_Int16 nH, const rtl::OUString& sTitle ) const
00652 {
00653 m_pImpl->initialize( nW, nH, sTitle );
00654 }
00655
00656 void BaseDialog::setVisibleDefault( bool b ) const
00657 {
00658 m_pImpl->setVisibleDefault( b );
00659 }
00660
00661 rtl::OUString BaseDialog::getResStr( int resid ) const
00662 {
00663 return getSolverImpl()->getResStr( resid );
00664 }
00665
00666 apWidgetProp BaseDialog::addButton(
00667 sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00668 const rtl::OUString& sName, const rtl::OUString& sLabel, sal_Int16 nPushBtnType )
00669 {
00670 return m_pImpl->addButton( nX, nY, nW, nH, sName, sLabel, nPushBtnType );
00671 }
00672
00673
00674 apWidgetProp BaseDialog::addButtonImage(
00675 sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00676 const rtl::OUString& sName, const rtl::OUString& sUrl, sal_Int16 nPushBtnType )
00677 {
00678 return m_pImpl->addButtonImage( nX, nY, nW, nH, sName, sUrl, nPushBtnType );
00679 }
00680
00681
00682 apWidgetProp BaseDialog::addEdit( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00683 const rtl::OUString& sName )
00684 {
00685 return m_pImpl->addEdit( nX, nY, nW, nH, sName );
00686 }
00687
00688
00689 apWidgetProp BaseDialog::addFixedLine( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00690 const rtl::OUString& sName, const rtl::OUString& sLabel, sal_Int32 nOrientation )
00691 {
00692 return m_pImpl->addFixedLine( nX, nY, nW, nH, sName, sLabel, nOrientation );
00693 }
00694
00695
00696 apWidgetProp BaseDialog::addFixedText( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00697 const rtl::OUString& sName, const rtl::OUString& sLabel )
00698 {
00699 return m_pImpl->addFixedText( nX, nY, nW, nH, sName, sLabel );
00700 }
00701
00702
00703 apWidgetProp BaseDialog::addGroupBox( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00704 const rtl::OUString& sName )
00705 {
00706 return m_pImpl->addGroupBox( nX, nY, nW, nH, sName );
00707 }
00708
00709
00710 apWidgetProp BaseDialog::addListBox( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00711 const rtl::OUString& sName )
00712 {
00713 return m_pImpl->addListBox( nX, nY, nW, nH, sName );
00714 }
00715
00716
00717 apWidgetProp BaseDialog::addRadioButton( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00718 const rtl::OUString& sName, const rtl::OUString& sLabel )
00719 {
00720 return m_pImpl->addRadioButton( nX, nY, nW, nH, sName, sLabel );
00721 }
00722
00723 apWidgetProp BaseDialog::addCheckBox( sal_Int32 x, sal_Int32 y, sal_Int32 w, sal_Int32 h,
00724 const rtl::OUString& name, const rtl::OUString& label )
00725 {
00726 return m_pImpl->addCheckBox(x, y, w, h, name, label);
00727 }
00728
00729 apWidgetProp BaseDialog::addRangeEdit( sal_Int32 nX, sal_Int32 nY, sal_Int32 nW, sal_Int32 nH,
00730 const rtl::OUString& sEditName, const rtl::OUString& sBtnName )
00731 {
00732 return m_pImpl->addRangeEdit( nX, nY, nW, nH, sEditName, sBtnName );
00733 }
00734
00735 void BaseDialog::registerListener( TopWindowListener* p ) const
00736 {
00737 m_pImpl->registerListener(p);
00738 }
00739
00740 void BaseDialog::registerListener( FocusListener* p ) const
00741 {
00742 m_pImpl->registerListener( p );
00743 }
00744
00745 void BaseDialog::registerListener( MouseListener* p ) const
00746 {
00747 m_pImpl->registerListener( p );
00748 }
00749
00750 void BaseDialog::registerListener( const rtl::OUString& sName, ActionListener* p ) const
00751 {
00752 m_pImpl->registerListener( sName, p );
00753 }
00754
00755 void BaseDialog::registerListener( const rtl::OUString& sName, ItemListener* p ) const
00756 {
00757 m_pImpl->registerListener( sName, p );
00758 }
00759
00760 void BaseDialog::unregisterListener( TopWindowListener* p ) const
00761 {
00762 m_pImpl->unregisterListener(p);
00763 }
00764
00765 void BaseDialog::unregisterListener( FocusListener* p ) const
00766 {
00767 m_pImpl->unregisterListener( p );
00768 }
00769
00770 void BaseDialog::unregisterListener( MouseListener* p ) const
00771 {
00772 m_pImpl->unregisterListener( p );
00773 }
00774
00775 void BaseDialog::unregisterListener( const rtl::OUString& sName, ActionListener* p ) const
00776 {
00777 m_pImpl->unregisterListener( sName, p );
00778 }
00779
00780 void BaseDialog::unregisterListener( const rtl::OUString& sName, ItemListener* p ) const
00781 {
00782 m_pImpl->unregisterListener( sName, p );
00783 }
00784
00785 SolverImpl* BaseDialog::getSolverImpl() const
00786 {
00787 return m_pImpl->getSolverImpl();
00788 }
00789
00790 const Reference< XInterface > BaseDialog::getWidgetByName( const rtl::OUString& sName ) const
00791 {
00792 return m_pImpl->getWidgetByName( sName );
00793 }
00794
00795 const Reference< awt::XControlModel > BaseDialog::getWidgetModelByName(
00796 const rtl::OUString& sName ) const
00797 {
00798 Reference< XInterface > obj = m_pImpl->getWidgetByName( sName );
00799 Reference< awt::XControl > xCtrl( obj, UNO_QUERY );
00800 return xCtrl->getModel();
00801 }
00802
00803 void BaseDialog::enableWidget( const rtl::OUString& sName, sal_Bool bEnable ) const
00804 {
00805 return m_pImpl->enableWidget( sName, bEnable );
00806 }
00807
00808 void BaseDialog::toFront() const
00809 {
00810 m_pImpl->toFront();
00811 }
00812
00813 void BaseDialog::setFocus() const
00814 {
00815 m_pImpl->setFocus();
00816 }
00817
00818 void BaseDialog::execute() const
00819 {
00820 m_pImpl->execute();
00821 }
00822
00823
00824
00825
00826 class ObjPropertyImpl
00827 {
00828 public:
00829 ObjPropertyImpl( const Reference< XInterface >& );
00830 ~ObjPropertyImpl() throw();
00831 void setPropertyValue( const char*, const Any& );
00832
00833 private:
00834 const Reference< beans::XPropertySet >& getPropertySet() const;
00835
00836 Reference< XInterface > m_oModel;
00837 mutable Reference< beans::XPropertySet > m_xPS;
00838 };
00839
00840 ObjPropertyImpl::ObjPropertyImpl( const Reference< XInterface >& aRef ) :
00841 m_oModel( aRef ), m_xPS( NULL )
00842 {
00843 m_oModel = aRef;
00844 }
00845
00846 ObjPropertyImpl::~ObjPropertyImpl() throw()
00847 {
00848 }
00849
00850 void ObjPropertyImpl::setPropertyValue( const char* name, const Any& aVal )
00851 {
00852 getPropertySet()->setPropertyValue( ascii( name ), aVal );
00853 }
00854
00855 const Reference< beans::XPropertySet >& ObjPropertyImpl::getPropertySet() const
00856 {
00857 if ( m_xPS == NULL )
00858 {
00859 Reference< beans::XPropertySet > x( m_oModel, UNO_QUERY );
00860 m_xPS = x;
00861 }
00862
00863 return m_xPS;
00864 }
00865
00866
00867
00868
00869
00870 ObjProperty::ObjProperty( const Reference< XInterface >& aRef ) :
00871 m_pImpl( new ObjPropertyImpl( aRef ) )
00872 {
00873 }
00874
00875 ObjProperty::~ObjProperty() throw()
00876 {
00877 }
00878
00879 void ObjProperty::setPropertyValueAny( const char* name, const uno::Any& aVal )
00880 {
00881 m_pImpl->setPropertyValue( name, aVal );
00882 }
00883
00884 template<typename AnyValue>
00885 void ObjProperty::setPropertyValue( const char* name, const AnyValue& t )
00886 {
00887 Any aVal;
00888 aVal <<= t;
00889 m_pImpl->setPropertyValue( name, aVal );
00890 }
00891
00892
00893
00894
00895 class WidgetPropertyImpl
00896 {
00897 public:
00898 WidgetPropertyImpl( WidgetProperty* );
00899 ~WidgetPropertyImpl() throw();
00900
00901 void setPositionX( sal_Int32 ) const;
00902 void setPositionY( sal_Int32 ) const;
00903 void setWidth( sal_Int32 ) const;
00904 void setHeight( sal_Int32 ) const;
00905 void setName( const rtl::OUString& ) const;
00906 void setLabel( const rtl::OUString& ) const;
00907
00908 private:
00909 WidgetProperty* m_pSelf;
00910 };
00911
00912 WidgetPropertyImpl::WidgetPropertyImpl( WidgetProperty* p ) :
00913 m_pSelf( p )
00914 {
00915 }
00916
00917 WidgetPropertyImpl::~WidgetPropertyImpl() throw()
00918 {
00919 }
00920
00921 void WidgetPropertyImpl::setPositionX( sal_Int32 n ) const
00922 {
00923 m_pSelf->setPropertyValue( "PositionX", n );
00924 }
00925
00926 void WidgetPropertyImpl::setPositionY( sal_Int32 n ) const
00927 {
00928 m_pSelf->setPropertyValue( "PositionY", n );
00929 }
00930
00931 void WidgetPropertyImpl::setWidth( sal_Int32 n ) const
00932 {
00933 m_pSelf->setPropertyValue( "Width", n );
00934 }
00935
00936 void WidgetPropertyImpl::setHeight( sal_Int32 n ) const
00937 {
00938 m_pSelf->setPropertyValue( "Height", n );
00939 }
00940
00941 void WidgetPropertyImpl::setName( const rtl::OUString& s ) const
00942 {
00943 m_pSelf->setPropertyValue( "Name", s );
00944 }
00945
00946 void WidgetPropertyImpl::setLabel( const rtl::OUString& s ) const
00947 {
00948 m_pSelf->setPropertyValue( "Label", s );
00949 }
00950
00951
00952
00953
00954 WidgetProperty::WidgetProperty( const Reference< XInterface >& aRef ) :
00955 ObjProperty( aRef ), m_pImpl( new WidgetPropertyImpl( this ) )
00956 {
00957 }
00958
00959 WidgetProperty::~WidgetProperty() throw()
00960 {
00961 }
00962
00963 void WidgetProperty::setPositionX( sal_Int32 n ) const
00964 {
00965 m_pImpl->setPositionX( n );
00966 }
00967
00968 void WidgetProperty::setPositionY( sal_Int32 n ) const
00969 {
00970 m_pImpl->setPositionY( n );
00971 }
00972
00973 void WidgetProperty::setWidth( sal_Int32 n ) const
00974 {
00975 m_pImpl->setWidth( n );
00976 }
00977
00978 void WidgetProperty::setHeight( sal_Int32 n ) const
00979 {
00980 m_pImpl->setHeight( n );
00981 }
00982
00983 void WidgetProperty::setName( const rtl::OUString& s ) const
00984 {
00985 m_pImpl->setName( s );
00986 }
00987
00988 void WidgetProperty::setLabel( const rtl::OUString& s ) const
00989 {
00990 m_pImpl->setLabel( s );
00991 }
00992
00993
00994
00995 const rtl::OUString getTextByWidget( BaseDialog* pDlg, const rtl::OUString& sName )
00996 {
00997 Reference< uno::XInterface > o = pDlg->getWidgetByName( sName );
00998 Reference< awt::XTextComponent > xComp( o, UNO_QUERY );
00999 return xComp->getText();
01000 }
01001
01002 void setTextByWidget( BaseDialog* pDlg, const rtl::OUString& sName, const rtl::OUString& sVal )
01003 {
01004 Reference< uno::XInterface > o = pDlg->getWidgetByName( sName );
01005 Reference< awt::XTextComponent > xComp( o, UNO_QUERY );
01006 xComp->setText( sVal );
01007 }
01008
01009 }
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026