update dev300-m58
[ooovba.git] / svx / source / form / fmtools.cxx
blob3f978a53a04a2b0a2026fcbd47f1bfac38a2cf39
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmtools.cxx,v $
10 * $Revision: 1.40 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/io/XPersistObject.hpp>
35 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
36 #include <com/sun/star/sdb/XCompletedConnection.hpp>
37 #include <com/sun/star/sdbcx/Privilege.hpp>
38 #include <com/sun/star/lang/Locale.hpp>
39 #include "fmtools.hxx"
40 #include "svx/dbtoolsclient.hxx"
41 #include "fmservs.hxx"
42 #include <svx/fmglob.hxx>
43 #include <vcl/stdtext.hxx>
44 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
45 #include <toolkit/unohlp.hxx>
46 #endif
48 #include <stdlib.h>
49 #include <stdio.h>
50 #include <wchar.h>
51 #include <com/sun/star/uno/XNamingService.hpp>
52 #include <com/sun/star/sdbc/XDataSource.hpp>
53 #include <com/sun/star/sdb/CommandType.hpp>
54 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
55 #include <com/sun/star/sdb/SQLContext.hpp>
56 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
57 #include <com/sun/star/sdb/XResultSetAccess.hpp>
58 #include <com/sun/star/sdb/ErrorCondition.hpp>
59 #include <com/sun/star/sdbc/DataType.hpp>
60 #include <com/sun/star/util/NumberFormat.hpp>
61 #include <com/sun/star/io/XActiveDataSink.hpp>
62 #include <com/sun/star/io/XActiveDataSource.hpp>
63 #include <com/sun/star/script/XEventAttacherManager.hpp>
64 #include <com/sun/star/form/XForm.hpp>
65 #include <com/sun/star/form/XFormComponent.hpp>
66 #include <com/sun/star/util/XNumberFormatter.hpp>
67 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
68 #include <com/sun/star/util/Language.hpp>
69 #include <com/sun/star/util/XNumberFormats.hpp>
70 #include <com/sun/star/util/XNumberFormatTypes.hpp>
71 #include <com/sun/star/util/XCloneable.hpp>
72 #include <com/sun/star/io/XObjectInputStream.hpp>
73 #include <com/sun/star/io/XObjectOutputStream.hpp>
74 #include <com/sun/star/reflection/XIdlClass.hpp>
75 #include <com/sun/star/reflection/XIdlMethod.hpp>
76 #include <com/sun/star/beans/XIntrospection.hpp>
77 #include <com/sun/star/beans/PropertyAttribute.hpp>
78 #include <com/sun/star/container/XChild.hpp>
79 #include <com/sun/star/task/XInteractionHandler.hpp>
80 #include <com/sun/star/awt/LineEndFormat.hpp>
81 #include <com/sun/star/form/XGridColumnFactory.hpp>
84 #include <tools/debug.hxx>
85 #include <tools/string.hxx>
86 #include <basic/sbxvar.hxx>
87 #include <rtl/math.hxx>
88 #include <vcl/svapp.hxx>
90 #ifndef _SVX_FMPROP_HRC
91 #include "fmprop.hrc"
92 #endif
93 #include <sfx2/bindings.hxx>
94 #include <svtools/eitem.hxx>
95 #include <svtools/stritem.hxx>
96 #include <cppuhelper/servicefactory.hxx>
97 #include <comphelper/types.hxx>
98 #include <comphelper/property.hxx>
99 #include <comphelper/container.hxx>
100 #include <connectivity/dbtools.hxx>
101 #include <comphelper/processfactory.hxx>
102 #include <comphelper/sequence.hxx>
103 #include <comphelper/extract.hxx>
104 #include <comphelper/uno3.hxx>
105 #include <connectivity/dbexception.hxx>
106 #include <comphelper/evtmethodhelper.hxx>
107 #include <cppuhelper/typeprovider.hxx>
108 #include <algorithm>
109 #include <rtl/logfile.hxx>
111 using namespace ::com::sun::star::uno;
112 using namespace ::com::sun::star::util;
113 using namespace ::com::sun::star::lang;
114 using namespace ::com::sun::star::frame;
115 using namespace ::com::sun::star::awt;
116 using namespace ::com::sun::star::beans;
117 using namespace ::com::sun::star::container;
118 using namespace ::com::sun::star::ui::dialogs;
119 using namespace ::com::sun::star::sdbc;
120 using namespace ::com::sun::star::sdbcx;
121 using namespace ::com::sun::star::sdb;
122 using namespace ::com::sun::star::task;
123 using namespace ::com::sun::star::form;
124 using namespace ::svxform;
125 using namespace ::connectivity::simple;
127 // ------------------------------------------------------------------------------
128 namespace
130 static bool lcl_shouldDisplayError( const Any& _rError )
132 SQLException aError;
133 if ( !( _rError >>= aError ) )
134 return true;
136 if ( aError.Message.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "[OOoBase]" ) ) != 0 )
137 // it is an exception *not* thrown by an OOo Base core component
138 return true;
140 // the only exception we do not display ATM is a RowSetVetoException, which
141 // has been raised because an XRowSetApprovalListener vetoed a change
142 if ( aError.ErrorCode + ErrorCondition::ROW_SET_OPERATION_VETOED == 0 )
143 return false;
145 // everything else is to be displayed
146 return true;
150 // ------------------------------------------------------------------------------
151 void displayException(const Any& _rExcept, Window* _pParent)
153 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::displayException" );
154 // check whether we need to display it
155 if ( !lcl_shouldDisplayError( _rExcept ) )
156 return;
160 // the parent window
161 Window* pParentWindow = _pParent ? _pParent : GetpApp()->GetDefDialogParent();
162 Reference< XWindow > xParentWindow = VCLUnoHelper::GetInterface(pParentWindow);
164 Sequence< Any > aArgs(2);
165 aArgs[0] <<= PropertyValue(::rtl::OUString::createFromAscii("SQLException"), 0, _rExcept, PropertyState_DIRECT_VALUE);
166 aArgs[1] <<= PropertyValue(::rtl::OUString::createFromAscii("ParentWindow"), 0, makeAny(xParentWindow), PropertyState_DIRECT_VALUE);
168 static ::rtl::OUString s_sDialogServiceName = ::rtl::OUString::createFromAscii("com.sun.star.sdb.ErrorMessageDialog");
169 Reference< XExecutableDialog > xErrorDialog(
170 ::comphelper::getProcessServiceFactory()->createInstanceWithArguments(s_sDialogServiceName, aArgs), UNO_QUERY);
171 if (xErrorDialog.is())
172 xErrorDialog->execute();
173 else
174 ShowServiceNotAvailableError(pParentWindow, s_sDialogServiceName, sal_True);
176 catch(Exception&)
178 OSL_ENSURE(sal_False, "displayException: could not display the error message!");
182 // ------------------------------------------------------------------------------
183 void displayException(const ::com::sun::star::sdbc::SQLException& _rExcept, Window* _pParent)
185 displayException(makeAny(_rExcept), _pParent);
188 // ------------------------------------------------------------------------------
189 void displayException(const ::com::sun::star::sdbc::SQLWarning& _rExcept, Window* _pParent)
191 displayException(makeAny(_rExcept), _pParent);
194 // ------------------------------------------------------------------------------
195 void displayException(const ::com::sun::star::sdb::SQLContext& _rExcept, Window* _pParent)
197 displayException(makeAny(_rExcept), _pParent);
200 // ------------------------------------------------------------------------------
201 void displayException(const ::com::sun::star::sdb::SQLErrorEvent& _rEvent, Window* _pParent)
203 displayException(_rEvent.Reason, _pParent);
206 //------------------------------------------------------------------------------
207 Reference< XInterface > cloneUsingProperties(const Reference< ::com::sun::star::io::XPersistObject>& _xObj)
209 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::cloneUsingProperties" );
210 if (!_xObj.is())
211 return Reference< XInterface >();
213 // create a new object
214 ::rtl::OUString aObjectService = _xObj->getServiceName();
215 Reference< ::com::sun::star::beans::XPropertySet> xDestSet(::comphelper::getProcessServiceFactory()->createInstance(aObjectService), UNO_QUERY);
216 if (!xDestSet.is())
218 DBG_ERROR("cloneUsingProperties : could not instantiate an object of the given type !");
219 return Reference< XInterface >();
221 // transfer properties
222 Reference< XPropertySet > xSourceSet(_xObj, UNO_QUERY);
223 Reference< XPropertySetInfo > xSourceInfo( xSourceSet->getPropertySetInfo());
224 Sequence< Property> aSourceProperties = xSourceInfo->getProperties();
225 Reference< XPropertySetInfo > xDestInfo( xDestSet->getPropertySetInfo());
226 Sequence< Property> aDestProperties = xDestInfo->getProperties();
227 int nDestLen = aDestProperties.getLength();
229 Property* pSourceProps = aSourceProperties.getArray();
230 Property* pSourceEnd = pSourceProps + aSourceProperties.getLength();
231 Property* pDestProps = aDestProperties.getArray();
233 for (; pSourceProps != pSourceEnd; ++pSourceProps)
235 ::com::sun::star::beans::Property* pResult = ::std::lower_bound(
236 pDestProps,
237 pDestProps + nDestLen,
238 pSourceProps->Name,
239 ::comphelper::PropertyStringLessFunctor()
242 if ( ( pResult != pDestProps + nDestLen )
243 && ( pResult->Name == pSourceProps->Name )
244 && ( pResult->Attributes == pSourceProps->Attributes )
245 && ( (pResult->Attributes & PropertyAttribute::READONLY ) == 0 )
246 && ( pResult->Type.equals( pSourceProps->Type ) )
248 { // Attribute/type are the same and the prop isn't readonly
251 xDestSet->setPropertyValue(pResult->Name, xSourceSet->getPropertyValue(pResult->Name));
253 catch(IllegalArgumentException e)
255 (void)e;
256 #ifdef DBG_UTIL
257 ::rtl::OString sMessage("cloneUsingProperties : could not transfer the value for property \"");
258 sMessage = sMessage + ::rtl::OString(pResult->Name.getStr(), pResult->Name.getLength(), RTL_TEXTENCODING_ASCII_US);
259 sMessage = sMessage + '\"';
260 DBG_ERROR(sMessage);
261 #endif
267 return xDestSet.get();
270 //------------------------------------------------------------------------------
271 sal_Bool searchElement(const Reference< ::com::sun::star::container::XIndexAccess>& xCont, const Reference< XInterface >& xElement)
273 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::searchElement" );
274 if (!xCont.is() || !xElement.is())
275 return sal_False;
277 sal_Int32 nCount = xCont->getCount();
278 Reference< XInterface > xComp;
279 for (sal_Int32 i = 0; i < nCount; i++)
283 xCont->getByIndex(i) >>= xComp;
284 if (xComp.is())
286 if ( xElement == xComp )
287 return sal_True;
288 else
290 Reference< ::com::sun::star::container::XIndexAccess> xCont2(xComp, UNO_QUERY);
291 if (xCont2.is() && searchElement(xCont2, xElement))
292 return sal_True;
296 catch(Exception&)
300 return sal_False;
303 //------------------------------------------------------------------------------
304 sal_Int32 getElementPos(const Reference< ::com::sun::star::container::XIndexAccess>& xCont, const Reference< XInterface >& xElement)
306 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::getElementPos" );
307 sal_Int32 nIndex = -1;
308 if (!xCont.is())
309 return nIndex;
312 Reference< XInterface > xNormalized( xElement, UNO_QUERY );
313 DBG_ASSERT( xNormalized.is(), "getElementPos: invalid element!" );
314 if ( xNormalized.is() )
316 // Feststellen an welcher Position sich das Kind befindet
317 nIndex = xCont->getCount();
318 while (nIndex--)
322 Reference< XInterface > xCurrent(xCont->getByIndex( nIndex ),UNO_QUERY);
323 DBG_ASSERT( xCurrent.get() == Reference< XInterface >( xCurrent, UNO_QUERY ).get(),
324 "getElementPos: container element not normalized!" );
325 if ( xNormalized.get() == xCurrent.get() )
326 break;
328 catch(Exception&)
330 DBG_ERROR( "getElementPos: caught an exception!" );
335 return nIndex;
338 //------------------------------------------------------------------
339 String getFormComponentAccessPath(const Reference< XInterface >& _xElement, Reference< XInterface >& _rTopLevelElement)
341 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::getFormComponentAccessPath" );
342 Reference< ::com::sun::star::form::XFormComponent> xChild(_xElement, UNO_QUERY);
343 Reference< ::com::sun::star::container::XIndexAccess> xParent;
344 if (xChild.is())
345 xParent = Reference< ::com::sun::star::container::XIndexAccess>(xChild->getParent(), UNO_QUERY);
347 // while the current content is a form
348 String sReturn;
349 String sCurrentIndex;
350 while (xChild.is())
352 // get the content's relative pos within it's parent container
353 sal_Int32 nPos = getElementPos(xParent, xChild);
355 // prepend this current relaive pos
356 sCurrentIndex = String::CreateFromInt32(nPos);
357 if (sReturn.Len() != 0)
359 sCurrentIndex += '\\';
360 sCurrentIndex += sReturn;
363 sReturn = sCurrentIndex;
365 // travel up
366 if (::comphelper::query_interface((Reference< XInterface >)xParent,xChild))
367 xParent = Reference< ::com::sun::star::container::XIndexAccess>(xChild->getParent(), UNO_QUERY);
370 _rTopLevelElement = xParent;
371 return sReturn;
374 //------------------------------------------------------------------
375 String getFormComponentAccessPath(const Reference< XInterface >& _xElement)
377 Reference< XInterface > xDummy;
378 return getFormComponentAccessPath(_xElement, xDummy);
381 //------------------------------------------------------------------------------
382 Reference< XInterface > getElementFromAccessPath(const Reference< ::com::sun::star::container::XIndexAccess>& _xParent, const String& _rRelativePath)
384 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::getElementFromAccessPath" );
385 if (!_xParent.is())
386 return Reference< XInterface >();
387 Reference< ::com::sun::star::container::XIndexAccess> xContainer(_xParent);
388 Reference< XInterface > xElement( _xParent);
390 String sPath(_rRelativePath);
391 while (sPath.Len() && xContainer.is())
393 xub_StrLen nSepPos = sPath.Search((sal_Unicode)'\\');
395 String sIndex(sPath.Copy(0, (nSepPos == STRING_NOTFOUND) ? sPath.Len() : nSepPos));
396 // DBG_ASSERT(sIndex.IsNumeric(), "getElementFromAccessPath : invalid path !");
398 sPath = sPath.Copy((nSepPos == STRING_NOTFOUND) ? sPath.Len() : nSepPos+1);
400 ::cppu::extractInterface(xElement, xContainer->getByIndex(sIndex.ToInt32()));
401 xContainer = Reference< ::com::sun::star::container::XIndexAccess>::query(xElement);
404 if (sPath.Len() != 0)
405 // the loop terminated because an element wasn't a container, but we stil have a path -> the path is invalid
406 xElement = NULL;
408 return xElement;
411 //------------------------------------------------------------------
412 // Vergleichen von PropertyInfo
413 extern "C" int
414 #if defined( WNT )
415 __cdecl
416 #endif
417 #if defined( ICC ) && defined( OS2 )
418 _Optlink
419 #endif
420 NameCompare(const void* pFirst, const void* pSecond)
422 return ((::rtl::OUString*)pFirst)->compareTo(*(::rtl::OUString*)pSecond);
425 //------------------------------------------------------------------------------
426 sal_Int32 findPos(const ::rtl::OUString& aStr, const Sequence< ::rtl::OUString>& rList)
428 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::findPos" );
429 const ::rtl::OUString* pStrList = rList.getConstArray();
430 ::rtl::OUString* pResult = (::rtl::OUString*) bsearch(&aStr, (void*)pStrList, rList.getLength(), sizeof(::rtl::OUString),
431 &NameCompare);
433 if (pResult)
434 return (pResult - pStrList);
435 else
436 return -1;
439 //------------------------------------------------------------------
440 Reference< ::com::sun::star::frame::XModel> getXModel(const Reference< XInterface >& xIface)
442 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::getXModel" );
443 Reference< ::com::sun::star::frame::XModel> xModel(xIface, UNO_QUERY);
444 if (xModel.is())
445 return xModel;
446 else
448 Reference< ::com::sun::star::container::XChild> xChild(xIface, UNO_QUERY);
449 if (xChild.is())
451 Reference< XInterface > xParent( xChild->getParent());
452 return getXModel(xParent);
454 else
455 return NULL;
459 //------------------------------------------------------------------
460 ::rtl::OUString getLabelName(const Reference< ::com::sun::star::beans::XPropertySet>& xControlModel)
462 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::getLabelName" );
463 if (!xControlModel.is())
464 return ::rtl::OUString();
466 if (::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xControlModel))
468 Reference< ::com::sun::star::beans::XPropertySet> xLabelSet;
469 xControlModel->getPropertyValue(FM_PROP_CONTROLLABEL) >>= xLabelSet;
470 if (xLabelSet.is() && ::comphelper::hasProperty(FM_PROP_LABEL, xLabelSet))
472 Any aLabel( xLabelSet->getPropertyValue(FM_PROP_LABEL) );
473 if ((aLabel.getValueTypeClass() == TypeClass_STRING) && ::comphelper::getString(aLabel).getLength())
474 return ::comphelper::getString(aLabel);
478 return ::comphelper::getString(xControlModel->getPropertyValue(FM_PROP_CONTROLSOURCE));
481 //========================================================================
482 // = CursorWrapper
483 //------------------------------------------------------------------------
484 CursorWrapper::CursorWrapper(const Reference< ::com::sun::star::sdbc::XRowSet>& _rxCursor, sal_Bool bUseCloned)
486 ImplConstruct(Reference< ::com::sun::star::sdbc::XResultSet>(_rxCursor, UNO_QUERY), bUseCloned);
489 //------------------------------------------------------------------------
490 CursorWrapper::CursorWrapper(const Reference< ::com::sun::star::sdbc::XResultSet>& _rxCursor, sal_Bool bUseCloned)
492 ImplConstruct(_rxCursor, bUseCloned);
495 //------------------------------------------------------------------------
496 void CursorWrapper::ImplConstruct(const Reference< ::com::sun::star::sdbc::XResultSet>& _rxCursor, sal_Bool bUseCloned)
498 if (bUseCloned)
500 Reference< ::com::sun::star::sdb::XResultSetAccess> xAccess(_rxCursor, UNO_QUERY);
503 m_xMoveOperations = xAccess.is() ? xAccess->createResultSet() : Reference< ::com::sun::star::sdbc::XResultSet>();
505 catch(Exception&)
509 else
510 m_xMoveOperations = _rxCursor;
512 m_xBookmarkOperations = m_xBookmarkOperations.query( m_xMoveOperations );
513 m_xColumnsSupplier = m_xColumnsSupplier.query( m_xMoveOperations );
514 m_xPropertyAccess = m_xPropertyAccess.query( m_xMoveOperations );
516 if ( !m_xMoveOperations.is() || !m_xBookmarkOperations.is() || !m_xColumnsSupplier.is() || !m_xPropertyAccess.is() )
517 { // all or nothing !!
518 m_xMoveOperations = NULL;
519 m_xBookmarkOperations = NULL;
520 m_xColumnsSupplier = NULL;
522 else
523 m_xGeneric = m_xMoveOperations.get();
526 //------------------------------------------------------------------------
527 const CursorWrapper& CursorWrapper::operator=(const Reference< ::com::sun::star::sdbc::XRowSet>& _rxCursor)
529 m_xMoveOperations = Reference< ::com::sun::star::sdbc::XResultSet>(_rxCursor, UNO_QUERY);
530 m_xBookmarkOperations = Reference< ::com::sun::star::sdbcx::XRowLocate>(_rxCursor, UNO_QUERY);
531 m_xColumnsSupplier = Reference< ::com::sun::star::sdbcx::XColumnsSupplier>(_rxCursor, UNO_QUERY);
532 if (!m_xMoveOperations.is() || !m_xBookmarkOperations.is() || !m_xColumnsSupplier.is())
533 { // all or nothing !!
534 m_xMoveOperations = NULL;
535 m_xBookmarkOperations = NULL;
536 m_xColumnsSupplier = NULL;
538 return *this;
541 //------------------------------------------------------------------------------
542 FmXDisposeListener::~FmXDisposeListener()
544 setAdapter(NULL);
547 //------------------------------------------------------------------------------
548 void FmXDisposeListener::setAdapter(FmXDisposeMultiplexer* pAdapter)
550 if (m_pAdapter)
552 ::osl::MutexGuard aGuard(m_rMutex);
553 m_pAdapter->release();
554 m_pAdapter = NULL;
557 if (pAdapter)
559 ::osl::MutexGuard aGuard(m_rMutex);
560 m_pAdapter = pAdapter;
561 m_pAdapter->acquire();
565 //==============================================================================
566 DBG_NAME(FmXDisposeMultiplexer);
567 //------------------------------------------------------------------------------
568 FmXDisposeMultiplexer::FmXDisposeMultiplexer(FmXDisposeListener* _pListener, const Reference< ::com::sun::star::lang::XComponent>& _rxObject, sal_Int16 _nId)
569 :m_xObject(_rxObject)
570 ,m_pListener(_pListener)
571 ,m_nId(_nId)
573 DBG_CTOR(FmXDisposeMultiplexer, NULL);
574 m_pListener->setAdapter(this);
576 if (m_xObject.is())
577 m_xObject->addEventListener(this);
580 //------------------------------------------------------------------------------
581 FmXDisposeMultiplexer::~FmXDisposeMultiplexer()
583 DBG_DTOR(FmXDisposeMultiplexer, NULL);
586 // ::com::sun::star::lang::XEventListener
587 //------------------------------------------------------------------
588 void FmXDisposeMultiplexer::disposing(const ::com::sun::star::lang::EventObject& _Source) throw( RuntimeException )
590 Reference< ::com::sun::star::lang::XEventListener> xPreventDelete(this);
592 if (m_pListener)
594 m_pListener->disposing(_Source, m_nId);
595 m_pListener->setAdapter(NULL);
596 m_pListener = NULL;
598 m_xObject = NULL;
601 //------------------------------------------------------------------
602 void FmXDisposeMultiplexer::dispose()
604 if (m_xObject.is())
606 Reference< ::com::sun::star::lang::XEventListener> xPreventDelete(this);
608 m_xObject->removeEventListener(this);
609 m_xObject = NULL;
611 m_pListener->setAdapter(NULL);
612 m_pListener = NULL;
616 //==============================================================================
617 //------------------------------------------------------------------------------
618 sal_Int16 getControlTypeByObject(const Reference< ::com::sun::star::lang::XServiceInfo>& _rxObject)
620 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::getControlTypeByObject" );
621 // ask for the persistent service name
622 Reference< ::com::sun::star::io::XPersistObject> xPersistence(_rxObject, UNO_QUERY);
623 DBG_ASSERT(xPersistence.is(), "::getControlTypeByObject : argument shold be an ::com::sun::star::io::XPersistObject !");
624 if (!xPersistence.is())
625 return OBJ_FM_CONTROL;
627 ::rtl::OUString sPersistentServiceName = xPersistence->getServiceName();
628 if (sPersistentServiceName.equals(FM_COMPONENT_EDIT)) // 5.0-Name
630 // may be a simple edit field or a formatted field, dependent of the supported services
631 if (_rxObject->supportsService(FM_SUN_COMPONENT_FORMATTEDFIELD))
632 return OBJ_FM_FORMATTEDFIELD;
633 return OBJ_FM_EDIT;
635 if (sPersistentServiceName.equals(FM_COMPONENT_TEXTFIELD))
636 return OBJ_FM_EDIT;
637 if (sPersistentServiceName.equals(FM_COMPONENT_COMMANDBUTTON))
638 return OBJ_FM_BUTTON;
639 if (sPersistentServiceName.equals(FM_COMPONENT_FIXEDTEXT))
640 return OBJ_FM_FIXEDTEXT;
641 if (sPersistentServiceName.equals(FM_COMPONENT_LISTBOX))
642 return OBJ_FM_LISTBOX;
643 if (sPersistentServiceName.equals(FM_COMPONENT_CHECKBOX))
644 return OBJ_FM_CHECKBOX;
645 if (sPersistentServiceName.equals(FM_COMPONENT_RADIOBUTTON))
646 return OBJ_FM_RADIOBUTTON;
647 if (sPersistentServiceName.equals(FM_COMPONENT_GROUPBOX))
648 return OBJ_FM_GROUPBOX;
649 if (sPersistentServiceName.equals(FM_COMPONENT_COMBOBOX))
650 return OBJ_FM_COMBOBOX;
651 if (sPersistentServiceName.equals(FM_COMPONENT_GRID)) // 5.0-Name
652 return OBJ_FM_GRID;
653 if (sPersistentServiceName.equals(FM_COMPONENT_GRIDCONTROL))
654 return OBJ_FM_GRID;
655 if (sPersistentServiceName.equals(FM_COMPONENT_IMAGEBUTTON))
656 return OBJ_FM_IMAGEBUTTON;
657 if (sPersistentServiceName.equals(FM_COMPONENT_FILECONTROL))
658 return OBJ_FM_FILECONTROL;
659 if (sPersistentServiceName.equals(FM_COMPONENT_DATEFIELD))
660 return OBJ_FM_DATEFIELD;
661 if (sPersistentServiceName.equals(FM_COMPONENT_TIMEFIELD))
662 return OBJ_FM_TIMEFIELD;
663 if (sPersistentServiceName.equals(FM_COMPONENT_NUMERICFIELD))
664 return OBJ_FM_NUMERICFIELD;
665 if (sPersistentServiceName.equals(FM_COMPONENT_CURRENCYFIELD))
666 return OBJ_FM_CURRENCYFIELD;
667 if (sPersistentServiceName.equals(FM_COMPONENT_PATTERNFIELD))
668 return OBJ_FM_PATTERNFIELD;
669 if (sPersistentServiceName.equals(FM_COMPONENT_HIDDEN)) // 5.0-Name
670 return OBJ_FM_HIDDEN;
671 if (sPersistentServiceName.equals(FM_COMPONENT_HIDDENCONTROL))
672 return OBJ_FM_HIDDEN;
673 if (sPersistentServiceName.equals(FM_COMPONENT_IMAGECONTROL))
674 return OBJ_FM_IMAGECONTROL;
675 if (sPersistentServiceName.equals(FM_COMPONENT_FORMATTEDFIELD))
677 DBG_ERROR("::getControlTypeByObject : suspicious persistent service name (formatted field) !");
678 // objects with that service name should exist as they aren't compatible with older versions
679 return OBJ_FM_FORMATTEDFIELD;
681 if ( sPersistentServiceName.equals( FM_SUN_COMPONENT_SCROLLBAR ) )
682 return OBJ_FM_SCROLLBAR;
683 if ( sPersistentServiceName.equals( FM_SUN_COMPONENT_SPINBUTTON) )
684 return OBJ_FM_SPINBUTTON;
685 if (sPersistentServiceName.equals(FM_SUN_COMPONENT_NAVIGATIONBAR))
686 return OBJ_FM_NAVIGATIONBAR;
688 DBG_ERROR("::getControlTypeByObject : unknown object type !");
689 return OBJ_FM_CONTROL;
692 //------------------------------------------------------------------------------
693 ::rtl::OUString getServiceNameByControlType(sal_Int16 nType)
695 switch (nType)
697 case OBJ_FM_EDIT : return FM_COMPONENT_TEXTFIELD;
698 case OBJ_FM_BUTTON : return FM_COMPONENT_COMMANDBUTTON;
699 case OBJ_FM_FIXEDTEXT : return FM_COMPONENT_FIXEDTEXT;
700 case OBJ_FM_LISTBOX : return FM_COMPONENT_LISTBOX;
701 case OBJ_FM_CHECKBOX : return FM_COMPONENT_CHECKBOX;
702 case OBJ_FM_RADIOBUTTON : return FM_COMPONENT_RADIOBUTTON;
703 case OBJ_FM_GROUPBOX : return FM_COMPONENT_GROUPBOX;
704 case OBJ_FM_COMBOBOX : return FM_COMPONENT_COMBOBOX;
705 case OBJ_FM_GRID : return FM_COMPONENT_GRIDCONTROL;
706 case OBJ_FM_IMAGEBUTTON : return FM_COMPONENT_IMAGEBUTTON;
707 case OBJ_FM_FILECONTROL : return FM_COMPONENT_FILECONTROL;
708 case OBJ_FM_DATEFIELD : return FM_COMPONENT_DATEFIELD;
709 case OBJ_FM_TIMEFIELD : return FM_COMPONENT_TIMEFIELD;
710 case OBJ_FM_NUMERICFIELD : return FM_COMPONENT_NUMERICFIELD;
711 case OBJ_FM_CURRENCYFIELD : return FM_COMPONENT_CURRENCYFIELD;
712 case OBJ_FM_PATTERNFIELD : return FM_COMPONENT_PATTERNFIELD;
713 case OBJ_FM_HIDDEN : return FM_COMPONENT_HIDDENCONTROL;
714 case OBJ_FM_IMAGECONTROL : return FM_COMPONENT_IMAGECONTROL;
715 case OBJ_FM_FORMATTEDFIELD : return FM_COMPONENT_FORMATTEDFIELD;
716 case OBJ_FM_SCROLLBAR : return FM_SUN_COMPONENT_SCROLLBAR;
717 case OBJ_FM_SPINBUTTON : return FM_SUN_COMPONENT_SPINBUTTON;
718 case OBJ_FM_NAVIGATIONBAR : return FM_SUN_COMPONENT_NAVIGATIONBAR;
720 return ::rtl::OUString();
722 //------------------------------------------------------------------------------
723 void TransferEventScripts(const Reference< ::com::sun::star::awt::XControlModel>& xModel, const Reference< ::com::sun::star::awt::XControl>& xControl,
724 const Sequence< ::com::sun::star::script::ScriptEventDescriptor>& rTransferIfAvailable)
726 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::TransferEventScripts" );
727 // first check if we have a XEventAttacherManager for the model
728 Reference< ::com::sun::star::container::XChild> xModelChild(xModel, UNO_QUERY);
729 if (!xModelChild.is())
730 return; // nothing to do
732 Reference< ::com::sun::star::script::XEventAttacherManager> xEventManager(xModelChild->getParent(), UNO_QUERY);
733 if (!xEventManager.is())
734 return; // nothing to do
736 if (!rTransferIfAvailable.getLength())
737 return; // nothing to do
739 // check for the index of the model within it's parent
740 Reference< ::com::sun::star::container::XIndexAccess> xParentIndex(xModelChild->getParent(), UNO_QUERY);
741 if (!xParentIndex.is())
742 return; // nothing to do
743 sal_Int32 nIndex = getElementPos(xParentIndex, xModel);
744 if (nIndex<0 || nIndex>=xParentIndex->getCount())
745 return; // nothing to do
747 // then we need informations about the listeners supported by the control and the model
748 Sequence< Type> aModelListeners;
749 Sequence< Type> aControlListeners;
751 Reference< ::com::sun::star::beans::XIntrospection> xModelIntrospection(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.beans.Introspection")), UNO_QUERY);
752 Reference< ::com::sun::star::beans::XIntrospection> xControlIntrospection(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.beans.Introspection")), UNO_QUERY);
754 if (xModelIntrospection.is() && xModel.is())
756 Any aModel(makeAny(xModel));
757 aModelListeners = xModelIntrospection->inspect(aModel)->getSupportedListeners();
760 if (xControlIntrospection.is() && xControl.is())
762 Any aControl(makeAny(xControl));
763 aControlListeners = xControlIntrospection->inspect(aControl)->getSupportedListeners();
766 sal_Int32 nMaxNewLen = aModelListeners.getLength() + aControlListeners.getLength();
767 if (!nMaxNewLen)
768 return; // the model and the listener don't support any listeners (or we were unable to retrieve these infos)
770 Sequence< ::com::sun::star::script::ScriptEventDescriptor> aTransferable(nMaxNewLen);
771 ::com::sun::star::script::ScriptEventDescriptor* pTransferable = aTransferable.getArray();
773 const ::com::sun::star::script::ScriptEventDescriptor* pCurrent = rTransferIfAvailable.getConstArray();
774 sal_Int32 i,j,k;
775 for (i=0; i<rTransferIfAvailable.getLength(); ++i, ++pCurrent)
777 // search the model/control idl classes for the event described by pCurrent
778 for ( Sequence< Type>* pCurrentArray = &aModelListeners;
779 pCurrentArray;
780 pCurrentArray = (pCurrentArray == &aModelListeners) ? &aControlListeners : NULL
783 const Type* pCurrentListeners = pCurrentArray->getConstArray();
784 for (j=0; j<pCurrentArray->getLength(); ++j, ++pCurrentListeners)
786 UniString aListener = (*pCurrentListeners).getTypeName();
787 xub_StrLen nTokens = aListener.GetTokenCount('.');
788 if (nTokens)
789 aListener = aListener.GetToken(nTokens - 1, '.');
791 if (aListener == pCurrent->ListenerType.getStr())
792 // the current ::com::sun::star::script::ScriptEventDescriptor doesn't match the current listeners class
793 continue;
795 // now check the methods
796 Sequence< ::rtl::OUString> aMethodsNames = ::comphelper::getEventMethodsForType(*pCurrentListeners);
798 const ::rtl::OUString* pMethodsNames = aMethodsNames.getConstArray();
799 for (k=0; k<aMethodsNames.getLength(); ++k, ++pMethodsNames)
801 if ((*pMethodsNames).compareTo(pCurrent->EventMethod) != COMPARE_EQUAL)
802 // the current ::com::sun::star::script::ScriptEventDescriptor doesn't match the current listeners current method
803 continue;
805 // we can transfer the script event : the model (control) supports it
806 *pTransferable = *pCurrent;
807 ++pTransferable;
808 break;
810 if (k<aMethodsNames.getLength())
811 break;
816 sal_Int32 nRealNewLen = pTransferable - aTransferable.getArray();
817 aTransferable.realloc(nRealNewLen);
819 xEventManager->registerScriptEvents(nIndex, aTransferable);
822 //------------------------------------------------------------------------------
823 sal_Int16 GridView2ModelPos(const Reference< ::com::sun::star::container::XIndexAccess>& rColumns, sal_Int16 nViewPos)
825 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::GridView2ModelPos" );
828 if (rColumns.is())
830 // loop through all columns
831 sal_Int16 i;
832 Reference< ::com::sun::star::beans::XPropertySet> xCur;
833 for (i=0; i<rColumns->getCount(); ++i)
835 rColumns->getByIndex(i) >>= xCur;
836 if (!::comphelper::getBOOL(xCur->getPropertyValue(FM_PROP_HIDDEN)))
838 // for every visible col : if nViewPos is greater zero, decrement it, else we
839 // have found the model position
840 if (!nViewPos)
841 break;
842 else
843 --nViewPos;
846 if (i<rColumns->getCount())
847 return i;
850 catch(const Exception&)
852 DBG_ERROR("GridView2ModelPos Exception occured!");
854 return (sal_Int16)-1;
857 //========================================================================
858 //= FmXDispatchInterceptorImpl
859 //========================================================================
861 DBG_NAME(FmXDispatchInterceptorImpl);
862 //------------------------------------------------------------------------
863 FmXDispatchInterceptorImpl::FmXDispatchInterceptorImpl(
864 const Reference< XDispatchProviderInterception >& _rxToIntercept, FmDispatchInterceptor* _pMaster,
865 sal_Int16 _nId, Sequence< ::rtl::OUString > _rInterceptedSchemes)
866 :FmXDispatchInterceptorImpl_BASE(_pMaster && _pMaster->getInterceptorMutex() ? *_pMaster->getInterceptorMutex() : m_aFallback)
867 ,m_xIntercepted(_rxToIntercept)
868 ,m_bListening(sal_False)
869 ,m_pMaster(_pMaster)
870 ,m_nId(_nId)
871 ,m_aInterceptedURLSchemes(_rInterceptedSchemes)
873 DBG_CTOR(FmXDispatchInterceptorImpl,NULL);
875 ::osl::MutexGuard aGuard(getAccessSafety());
876 ::comphelper::increment(m_refCount);
877 if (_rxToIntercept.is())
879 _rxToIntercept->registerDispatchProviderInterceptor((::com::sun::star::frame::XDispatchProviderInterceptor*)this);
880 // this should make us the top-level dispatch-provider for the component, via a call to our
881 // setDispatchProvider we should have got an fallback for requests we (i.e. our master) cannot fullfill
882 Reference< ::com::sun::star::lang::XComponent> xInterceptedComponent(_rxToIntercept, UNO_QUERY);
883 if (xInterceptedComponent.is())
885 xInterceptedComponent->addEventListener(this);
886 m_bListening = sal_True;
889 ::comphelper::decrement(m_refCount);
892 //------------------------------------------------------------------------
893 FmXDispatchInterceptorImpl::~FmXDispatchInterceptorImpl()
895 if (!rBHelper.bDisposed)
896 dispose();
898 DBG_DTOR(FmXDispatchInterceptorImpl,NULL);
901 //------------------------------------------------------------------------------
902 Sequence< sal_Int8 > SAL_CALL FmXDispatchInterceptorImpl::getImplementationId() throw(RuntimeException)
904 static ::cppu::OImplementationId* pId = 0;
905 if (! pId)
907 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
908 if (! pId)
910 static ::cppu::OImplementationId aId;
911 pId = &aId;
914 return pId->getImplementationId();
917 //------------------------------------------------------------------------------
918 Reference< ::com::sun::star::frame::XDispatch > SAL_CALL FmXDispatchInterceptorImpl::queryDispatch( const URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags ) throw(RuntimeException)
920 ::osl::MutexGuard aGuard(getAccessSafety());
921 Reference< ::com::sun::star::frame::XDispatch> xResult;
922 // ask our 'real' interceptor
923 if (m_pMaster)
924 xResult = m_pMaster->interceptedQueryDispatch(m_nId, aURL, aTargetFrameName, nSearchFlags);
926 // ask our slave provider
927 if (!xResult.is() && m_xSlaveDispatcher.is())
928 xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
930 return xResult;
933 //------------------------------------------------------------------------------
934 Sequence< Reference< ::com::sun::star::frame::XDispatch > > SAL_CALL
935 FmXDispatchInterceptorImpl::queryDispatches( const Sequence< ::com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw(RuntimeException)
937 ::osl::MutexGuard aGuard(getAccessSafety());
938 Sequence< Reference< ::com::sun::star::frame::XDispatch> > aReturn(aDescripts.getLength());
939 Reference< ::com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray();
940 const ::com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
941 for (sal_Int16 i=0; i<aDescripts.getLength(); ++i, ++pReturn, ++pDescripts)
943 *pReturn = queryDispatch(pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags);
945 return aReturn;
948 //------------------------------------------------------------------------------
949 Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL FmXDispatchInterceptorImpl::getSlaveDispatchProvider( ) throw(RuntimeException)
951 ::osl::MutexGuard aGuard(getAccessSafety());
952 return m_xSlaveDispatcher;
955 //------------------------------------------------------------------------------
956 void SAL_CALL FmXDispatchInterceptorImpl::setSlaveDispatchProvider(const Reference< ::com::sun::star::frame::XDispatchProvider>& xNewDispatchProvider) throw( RuntimeException )
958 ::osl::MutexGuard aGuard(getAccessSafety());
959 m_xSlaveDispatcher = xNewDispatchProvider;
962 //------------------------------------------------------------------------------
963 Reference< ::com::sun::star::frame::XDispatchProvider> SAL_CALL FmXDispatchInterceptorImpl::getMasterDispatchProvider(void) throw( RuntimeException )
965 ::osl::MutexGuard aGuard(getAccessSafety());
966 return m_xMasterDispatcher;
969 //------------------------------------------------------------------------------
970 void SAL_CALL FmXDispatchInterceptorImpl::setMasterDispatchProvider(const Reference< ::com::sun::star::frame::XDispatchProvider>& xNewSupplier) throw( RuntimeException )
972 ::osl::MutexGuard aGuard(getAccessSafety());
973 m_xMasterDispatcher = xNewSupplier;
976 //------------------------------------------------------------------------------
977 Sequence< ::rtl::OUString > SAL_CALL FmXDispatchInterceptorImpl::getInterceptedURLs( ) throw(RuntimeException)
979 return m_aInterceptedURLSchemes;
982 //------------------------------------------------------------------------------
983 void SAL_CALL FmXDispatchInterceptorImpl::disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException )
985 if (m_bListening)
987 Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
988 if (Source.Source == xIntercepted)
989 ImplDetach();
993 //------------------------------------------------------------------------------
994 void FmXDispatchInterceptorImpl::ImplDetach()
996 ::osl::MutexGuard aGuard(getAccessSafety());
997 OSL_ENSURE(m_bListening, "FmXDispatchInterceptorImpl::ImplDetach: invalid call!");
999 // deregister ourself from the interception component
1000 Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
1001 if (xIntercepted.is())
1002 xIntercepted->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
1004 // m_xIntercepted = Reference< XDispatchProviderInterception >();
1005 // Don't reset m_xIntercepted: It may be needed by our owner to check for which object we were
1006 // responsible. As we hold the object with a weak reference only, this should be no problem.
1007 // 88936 - 23.07.2001 - frank.schoenheit@sun.com
1008 m_pMaster = NULL;
1009 m_bListening = sal_False;
1012 //------------------------------------------------------------------------------
1013 void FmXDispatchInterceptorImpl::disposing()
1015 // remove ourself as event listener from the interception component
1016 if (m_bListening)
1018 Reference< ::com::sun::star::lang::XComponent> xInterceptedComponent(m_xIntercepted.get(), UNO_QUERY);
1019 if (xInterceptedComponent.is())
1020 xInterceptedComponent->removeEventListener(static_cast<XEventListener*>(this));
1022 // detach from the interception component
1023 ImplDetach();
1027 //==============================================================================
1028 //==============================================================================
1030 //------------------------------------------------------------------------------
1031 sal_Bool isLoadable( const Reference< XInterface >& _rxLoadable )
1033 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::isLoadable" );
1034 // determines whether a form should be loaded or not
1035 // if there is no datasource or connection there is no reason to load a form
1036 Reference< XPropertySet > xSet( _rxLoadable, UNO_QUERY );
1037 if ( xSet.is() )
1041 Reference< XConnection > xConn;
1042 if ( OStaticDataAccessTools().isEmbeddedInDatabase( _rxLoadable.get(), xConn ) )
1043 return sal_True;
1045 // is there already a active connection
1046 xSet->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xConn;
1047 if ( xConn.is() )
1048 return sal_True;
1050 ::rtl::OUString sPropertyValue;
1051 OSL_VERIFY( xSet->getPropertyValue( FM_PROP_DATASOURCE ) >>= sPropertyValue );
1052 if ( sPropertyValue.getLength() )
1053 return sal_True;
1055 OSL_VERIFY( xSet->getPropertyValue( FM_PROP_URL ) >>= sPropertyValue );
1056 if ( sPropertyValue.getLength() )
1057 return sal_True;
1059 catch(Exception&)
1061 DBG_ERROR( "isLoadable: caught an exception!" );
1065 return sal_False;
1068 //------------------------------------------------------------------------------
1069 void setConnection(const Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet, const Reference< ::com::sun::star::sdbc::XConnection>& _rxConn)
1071 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::setConnection" );
1072 Reference< ::com::sun::star::beans::XPropertySet> xRowSetProps(_rxRowSet, UNO_QUERY);
1073 if (xRowSetProps.is())
1077 Any aConn(makeAny(_rxConn));
1078 xRowSetProps->setPropertyValue(FM_PROP_ACTIVE_CONNECTION, aConn);
1080 catch(Exception&)
1082 DBG_ERROR("::setConnection : could not set the connection !");
1087 //------------------------------------------------------------------------------
1088 sal_Bool isRowSetAlive(const Reference< XInterface >& _rxRowSet)
1090 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "fmtools::isRowSetAlive" );
1091 sal_Bool bIsAlive = sal_False;
1092 Reference< ::com::sun::star::sdbcx::XColumnsSupplier> xSupplyCols(_rxRowSet, UNO_QUERY);
1093 Reference< ::com::sun::star::container::XIndexAccess> xCols;
1094 if (xSupplyCols.is())
1095 xCols = Reference< ::com::sun::star::container::XIndexAccess>(xSupplyCols->getColumns(), UNO_QUERY);
1096 if (xCols.is() && (xCols->getCount() > 0))
1097 bIsAlive = sal_True;
1099 return bIsAlive;