diff options
Diffstat (limited to 'svx/source/form/fmshimp.cxx')
-rw-r--r-- | svx/source/form/fmshimp.cxx | 347 |
1 files changed, 158 insertions, 189 deletions
diff --git a/svx/source/form/fmshimp.cxx b/svx/source/form/fmshimp.cxx index efdf05a52d84..fab478154247 100644 --- a/svx/source/form/fmshimp.cxx +++ b/svx/source/form/fmshimp.cxx @@ -306,7 +306,8 @@ namespace while ( pCurrent ) { - FmFormObj* pAsFormObject = PTR_CAST( FmFormObj, pCurrent ); + FmFormObj* pAsFormObject = FmFormObj::GetFormObject( pCurrent ); + // note this will de-reference virtual objects, if necessary/possible if ( pAsFormObject ) { Reference< XInterface > xControlModel( pAsFormObject->GetUnoControlModel(), UNO_QUERY ); @@ -745,11 +746,9 @@ void SAL_CALL FmXFormShell::formActivated(const EventObject& rEvent) throw( Runt if ( impl_checkDisposed() ) return; - Reference< XFormController > xController( rEvent.Source, UNO_QUERY ); - OSL_ENSURE( xController.is(), "FmXFormShell::formActivated: invalid event source!" ); - - setActiveController( xController ); + Reference< XFormController > xController( rEvent.Source, UNO_QUERY_THROW ); m_pTextShell->formActivated( xController ); + setActiveController( xController ); } //------------------------------------------------------------------------------ @@ -758,9 +757,7 @@ void SAL_CALL FmXFormShell::formDeactivated(const EventObject& rEvent) throw( Ru if ( impl_checkDisposed() ) return; - Reference< XFormController > xController( rEvent.Source, UNO_QUERY ); - OSL_ENSURE( xController.is(), "FmXFormShell::formDeactivated: invalid event source!" ); - + Reference< XFormController > xController( rEvent.Source, UNO_QUERY_THROW ); m_pTextShell->formDeactivated( xController ); } @@ -828,12 +825,15 @@ void FmXFormShell::disposing() DisableNotification(); - // we are disposed from within the destructor of our shell, so now the shell pointer is invalid .... - m_pShell = NULL; + RemoveElement( m_xForms ); + m_xForms.clear(); + + impl_switchActiveControllerListening( false ); m_xActiveController = NULL; - m_xNavigationController = NULL; m_xActiveForm = NULL; - m_xForms = NULL; + + m_pShell = NULL; + m_xNavigationController = NULL; m_xCurrentForm = NULL; m_xLastGridFound = NULL; m_xAttachedFrame = NULL; @@ -1005,6 +1005,12 @@ bool FmXFormShell::executeControlConversionSlot( const Reference< XFormComponent if ( !_rxObject.is() ) return false; + SdrPage* pPage = m_pShell->GetCurPage(); + FmFormPage* pFormPage = pPage ? dynamic_cast< FmFormPage* >( pPage ) : NULL; + OSL_ENSURE( pFormPage, "FmXFormShell::executeControlConversionSlot: no current (form) page!" ); + if ( !pFormPage ) + return false; + OSL_ENSURE( isSolelySelected( _rxObject ), "FmXFormShell::executeControlConversionSlot: hmm ... shouldn't this parameter be redundant?" ); @@ -1012,46 +1018,25 @@ bool FmXFormShell::executeControlConversionSlot( const Reference< XFormComponent { if (nConvertSlots[lookupSlot] == _nSlotId) { - FmFormPage* pCurrentPage = m_pShell->GetCurPage(); + Reference< XInterface > xNormalizedObject( _rxObject, UNO_QUERY ); - SdrUnoObj* pFound = NULL; - for (sal_uInt32 obj=0; obj<pCurrentPage->GetObjCount(); ++obj) + FmFormObj* pFormObject = NULL; + SdrObjListIter aPageIter( *pFormPage ); + while ( aPageIter.IsMore() ) { - SdrObject* pCurrent = pCurrentPage->GetObj(obj); - - // wenn das Ding eine Gruppierung ist -> durchiterieren - SdrObjListIter* pGroupIterator = NULL; - if (pCurrent->IsGroupObject()) - { - pGroupIterator = new SdrObjListIter(*pCurrent->GetSubList()); - pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL; - } - - Reference< XInterface > xNormalizedObject( _rxObject, UNO_QUERY ); - while (pCurrent) - { - if (pCurrent->IsUnoObj()) - { - Reference< XInterface > xCurrentNormalized( static_cast< SdrUnoObj* >( pCurrent )->GetUnoControlModel(), UNO_QUERY ); - if ( xCurrentNormalized == xNormalizedObject ) - break; - } - - if (pGroupIterator) // ich iteriere gerade durch eine Gruppe von Controls - pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL; - else - pCurrent = NULL; - } - delete pGroupIterator; + SdrObject* pCurrent = aPageIter.Next(); + pFormObject = FmFormObj::GetFormObject( pCurrent ); + if ( !pFormObject ) + continue; - if (pCurrent) - { - pFound = (SdrUnoObj*)pCurrent; + Reference< XInterface > xCurrentNormalized( pFormObject->GetUnoControlModel(), UNO_QUERY ); + if ( xCurrentNormalized.get() == xNormalizedObject.get() ) break; - } + + pFormObject = NULL; } - if (!pFound) + if ( !pFormObject ) return false; ::rtl::OUString sNewName( getServiceNameByControlType( nObjectTypes[ lookupSlot ] ) ); @@ -1059,7 +1044,7 @@ bool FmXFormShell::executeControlConversionSlot( const Reference< XFormComponent if (!xNewModel.is()) return false; - Reference< XControlModel> xOldModel(pFound->GetUnoControlModel()); + Reference< XControlModel> xOldModel( pFormObject->GetUnoControlModel() ); Reference< XServiceInfo> xModelInfo(xOldModel, UNO_QUERY); // Properties uebertragen @@ -1135,8 +1120,8 @@ bool FmXFormShell::executeControlConversionSlot( const Reference< XFormComponent } // neues Model setzen - pFound->SetChanged(); - pFound->SetUnoControlModel(xNewModel); + pFormObject->SetChanged(); + pFormObject->SetUnoControlModel(xNewModel); // transfer script events // (do this _after_ SetUnoControlModel as we need the new (implicitly created) control) @@ -1198,7 +1183,7 @@ bool FmXFormShell::executeControlConversionSlot( const Reference< XFormComponent FmFormModel* pModel = m_pShell->GetFormModel(); DBG_ASSERT(pModel != NULL, "FmXFormShell::executeControlConversionSlot: my shell has no model !"); if (pModel) - pModel->AddUndo(new FmUndoModelReplaceAction(*pModel, pFound, xOldModel)); + pModel->AddUndo(new FmUndoModelReplaceAction(*pModel, pFormObject, xOldModel)); return true; } @@ -1757,6 +1742,19 @@ void FmXFormShell::ExecuteFormSlot( sal_Int32 _nSlot ) } //------------------------------------------------------------------------------ +void FmXFormShell::impl_switchActiveControllerListening( const bool _bListen ) +{ + Reference< XComponent> xComp( m_xActiveController, UNO_QUERY ); + if ( !xComp.is() ) + return; + + if ( _bListen ) + xComp->addEventListener( (XFormControllerListener*)this ); + else + xComp->removeEventListener( (XFormControllerListener*)this ); +} + +//------------------------------------------------------------------------------ void FmXFormShell::setActiveController( const Reference< XFormController>& xController, sal_Bool _bNoSaveOldContent ) { if ( impl_checkDisposed() ) @@ -1811,7 +1809,7 @@ void FmXFormShell::setActiveController( const Reference< XFormController>& xCont { m_bSetFocus = sal_True; if ( m_aActiveControllerFeatures->isModifiedRow() ) - { + { sal_Bool bIsNew = m_aActiveControllerFeatures->isInsertionRow(); sal_Bool bResult = m_aActiveControllerFeatures->commitCurrentRecord(); if ( !bResult && m_bSetFocus ) @@ -1820,7 +1818,7 @@ void FmXFormShell::setActiveController( const Reference< XFormController>& xCont // current control Reference< XWindow > xWindow( m_xActiveController->getCurrentControl(), UNO_QUERY ); if ( xWindow.is() ) - xWindow->setFocus(); + xWindow->setFocus(); m_bInActivate = sal_False; return; } @@ -1838,20 +1836,17 @@ void FmXFormShell::setActiveController( const Reference< XFormController>& xCont stopListening(); + impl_switchActiveControllerListening( false ); + m_aActiveControllerFeatures.dispose(); m_xActiveController = xController; if ( m_xActiveController.is() ) m_aActiveControllerFeatures.assign( m_xActiveController ); - if ( m_xActiveController.is() ) - { - // set eventlistener to know when it is disposed - Reference< ::com::sun::star::lang::XComponent> xComp(m_xActiveController, UNO_QUERY); - if (xComp.is()) - xComp->addEventListener((XEventListener*)(XPropertyChangeListener*)this); + impl_switchActiveControllerListening( true ); - m_xActiveForm = getInternalForm(Reference< XForm>(m_xActiveController->getModel(), UNO_QUERY)); - } + if ( m_xActiveController.is() ) + m_xActiveForm = getInternalForm( Reference< XForm >( m_xActiveController->getModel(), UNO_QUERY ) ); else m_xActiveForm = NULL; @@ -2172,9 +2167,9 @@ IMPL_LINK(FmXFormShell, OnFoundData, FmFoundRecordInformation*, pfriWhere) m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView()); m_pShell->GetFormView()->MarkObj(pObject, m_pShell->GetFormView()->GetSdrPageView()); - DBG_ASSERT(pObject->IsUnoObj(), "FmXFormShell::OnFoundData : ungueltiges Control !"); - Reference< XControlModel> xControlModel( ((SdrUnoObj*)pObject)->GetUnoControlModel()); - DBG_ASSERT(xControlModel.is(), "FmXFormShell::OnFoundData : ungueltiges Control !"); + FmFormObj* pFormObject = FmFormObj::GetFormObject( pObject ); + Reference< XControlModel > xControlModel( pFormObject ? pFormObject->GetUnoControlModel() : Reference< XControlModel >() ); + DBG_ASSERT( xControlModel.is(), "FmXFormShell::OnFoundData: invalid control!" ); // disable the permanent cursor for the last grid we found a record if (m_xLastGridFound.is() && (m_xLastGridFound != xControlModel)) @@ -2287,157 +2282,131 @@ IMPL_LINK(FmXFormShell, OnSearchContextRequest, FmSearchContext*, pfmscContextIn FmFormPage* pCurrentPage = m_pShell->GetCurPage(); DBG_ASSERT(pCurrentPage!=NULL, "FmXFormShell::OnSearchContextRequest : no page !"); // alle Sdr-Controls dieser Seite durchsuchen ... - ::rtl::OUString sControlSource, sCompareString,aName; - for (sal_Int32 i=0; i<(sal_Int32)pCurrentPage->GetObjCount(); ++i) + ::rtl::OUString sControlSource, aName; + + SdrObjListIter aPageIter( *pCurrentPage ); + while ( aPageIter.IsMore() ) { - SdrObject* pCurrent = pCurrentPage->GetObj(i); + SdrObject* pCurrent = aPageIter.Next(); + FmFormObj* pFormObject = FmFormObj::GetFormObject( pCurrent ); + // note that in case pCurrent is a virtual object, pFormObject points to the referenced object - // wenn das Ding eine Gruppierung ist -> durchiterieren - SdrObjListIter* pGroupIterator = NULL; - if (pCurrent->IsGroupObject()) - { - pGroupIterator = new SdrObjListIter(*pCurrent->GetSubList()); - pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL; - } + if ( !pFormObject ) + continue; - while (pCurrent) - { - if (pCurrent->IsUnoObj()) - { - // das Model zum aktuellen Object ... - Reference< XControlModel> xControlModel( ((SdrUnoObj*)pCurrent)->GetUnoControlModel()); - DBG_ASSERT(xControlModel.is(), "FmXFormShell::OnSearchContextRequest : invalid objects !"); - // ... als FormComponent - Reference< XFormComponent> xCurrentAsFormComponent(xControlModel, UNO_QUERY); - if (!xCurrentAsFormComponent.is()) - { - if (pGroupIterator) // ich iteriere gerade durch eine Gruppe von Controls - pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL; - else - pCurrent = NULL; - continue; - } + // the current object's model, in different tastes + Reference< XControlModel> xControlModel( pFormObject->GetUnoControlModel() ); + Reference< XFormComponent > xCurrentFormComponent( xControlModel, UNO_QUERY ); + DBG_ASSERT( xCurrentFormComponent.is(), "FmXFormShell::OnSearchContextRequest: invalid objects!" ); + if ( !xCurrentFormComponent.is() ) + continue; - // gehoert diese FormComponent ueberhaupt zu der Form, um die es geht ? - Reference< XInterface> xParentOfCurrent( xCurrentAsFormComponent->getParent()); - if (xParentOfCurrent != xForm) // vergleich fuehrt zu richtigem Ergebnis, seit TF_ONE - { - if (pGroupIterator) // ich iteriere gerade durch eine Gruppe von Controls - pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL; - else - pCurrent = NULL; - continue; - } + // does the component belong to the form which we're interested in? + if ( xCurrentFormComponent->getParent() != xForm ) + continue; - // ... nach der ControlSource-Eigenschaft fragen - SearchableControlIterator iter(xCurrentAsFormComponent); - Reference< XControl> xControlBehindModel; - // das Control, das als Model xControlModel hat - // (das folgende while kann mehrmals durchlaufen werden, ohne dass das Control sich aendert, dann muss - // ich nicht jedesmal neu suchen) + // ... nach der ControlSource-Eigenschaft fragen + SearchableControlIterator iter( xCurrentFormComponent ); + Reference< XControl> xControlBehindModel; + // das Control, das als Model xControlModel hat + // (das folgende while kann mehrmals durchlaufen werden, ohne dass das Control sich aendert, dann muss + // ich nicht jedesmal neu suchen) - Reference< XInterface> xCurrent( iter.Next()); - while (xCurrent.is()) + Reference< XInterface > xSearchable( iter.Next() ); + while ( xSearchable.is() ) + { + sControlSource = iter.getCurrentValue(); + if ( sControlSource.getLength() == 0 ) + { // das aktuelle Element hat keine ControlSource, also ist es ein GridControl (das ist das einzige, was + // der SearchableControlIterator noch zulaesst) + xControlBehindModel = GetControlFromModel(xControlModel); + DBG_ASSERT(xControlBehindModel.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !"); + + Reference< XGridPeer> xGridPeer(xControlBehindModel->getPeer(), UNO_QUERY); + do { - sControlSource = iter.getCurrentValue(); - if (sControlSource == sCompareString) - { // das aktuelle Element hat keine ControlSource, also ist es ein GridControl (das ist das einzige, was - // der SearchableControlIterator noch zulaesst) - xControlBehindModel = GetControlFromModel(xControlModel); - DBG_ASSERT(xControlBehindModel.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !"); + if (!xGridPeer.is()) + break; + + Reference< XIndexAccess> xPeerContainer(xGridPeer, UNO_QUERY); + if (!xPeerContainer.is()) + break; + + Reference< XIndexAccess> xModelColumns(xGridPeer->getColumns(), UNO_QUERY); + DBG_ASSERT(xModelColumns.is(), "FmXFormShell::OnSearchContextRequest : there is a grid control without columns !"); + // the case 'no columns' should be indicated with an empty container, I think ... + DBG_ASSERT(xModelColumns->getCount() >= xPeerContainer->getCount(), "FmXFormShell::OnSearchContextRequest : impossible : have more view than model columns !"); - Reference< XGridPeer> xGridPeer(xControlBehindModel->getPeer(), UNO_QUERY); - do + Reference< XInterface> xCurrentColumn; + for (sal_Int16 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos) + { + xPeerContainer->getByIndex(nViewPos) >>= xCurrentColumn; + if (!xCurrentColumn.is()) + continue; + + // can we use this column control fo searching ? + if (!IsSearchableControl(xCurrentColumn)) + continue; + + sal_Int16 nModelPos = GridView2ModelPos(xModelColumns, nViewPos); + Reference< XPropertySet> xCurrentColModel; + xModelColumns->getByIndex(nModelPos) >>= xCurrentColModel; + aName = ::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_CONTROLSOURCE)); + // the cursor has a field matching the control source ? + if (xValidFormFields->hasByName(aName)) { - if (!xGridPeer.is()) - break; + strFieldList += aName.getStr(); + strFieldList += ';'; - Reference< XIndexAccess> xPeerContainer(xGridPeer, UNO_QUERY); - if (!xPeerContainer.is()) - break; + sFieldDisplayNames += ::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_LABEL)).getStr(); + sFieldDisplayNames += ';'; - Reference< XIndexAccess> xModelColumns(xGridPeer->getColumns(), UNO_QUERY); - DBG_ASSERT(xModelColumns.is(), "FmXFormShell::OnSearchContextRequest : there is a grid control without columns !"); - // the case 'no columns' should be indicated with an empty container, I think ... - DBG_ASSERT(xModelColumns->getCount() >= xPeerContainer->getCount(), "FmXFormShell::OnSearchContextRequest : impossible : have more view than model columns !"); + pfmscContextInfo->arrFields.push_back(xCurrentColumn); - Reference< XInterface> xCurrentColumn; - for (sal_Int16 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos) - { - xPeerContainer->getByIndex(nViewPos) >>= xCurrentColumn; - if (!xCurrentColumn.is()) - continue; - - // can we use this column control fo searching ? - if (!IsSearchableControl(xCurrentColumn)) - continue; - - sal_Int16 nModelPos = GridView2ModelPos(xModelColumns, nViewPos); - Reference< XPropertySet> xCurrentColModel; - xModelColumns->getByIndex(nModelPos) >>= xCurrentColModel; - aName = ::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_CONTROLSOURCE)); - // the cursor has a field matching the control source ? - if (xValidFormFields->hasByName(aName)) - { - strFieldList += aName.getStr(); - strFieldList += ';'; - - sFieldDisplayNames += ::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_LABEL)).getStr(); - sFieldDisplayNames += ';'; - - pfmscContextInfo->arrFields.push_back(xCurrentColumn); - - // und das SdrObjekt zum Feld - m_arrSearchedControls.C40_INSERT(SdrObject, pCurrent, m_arrSearchedControls.Count()); - // die Nummer der Spalte - m_arrRelativeGridColumn.Insert(nViewPos, m_arrRelativeGridColumn.Count()); - } - } - } while (sal_False); + // und das SdrObjekt zum Feld + m_arrSearchedControls.C40_INSERT(SdrObject, pCurrent, m_arrSearchedControls.Count()); + // die Nummer der Spalte + m_arrRelativeGridColumn.Insert(nViewPos, m_arrRelativeGridColumn.Count()); + } } - else + } while (sal_False); + } + else + { + if (sControlSource.getLength() && xValidFormFields->hasByName(sControlSource)) + { + // jetzt brauche ich das Control zum SdrObject + if (!xControlBehindModel.is()) { - if (sControlSource.getLength() && xValidFormFields->hasByName(sControlSource)) - { - // jetzt brauche ich das Control zum SdrObject - if (!xControlBehindModel.is()) - { - xControlBehindModel = GetControlFromModel(xControlModel); - DBG_ASSERT(xControlBehindModel.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !"); - } + xControlBehindModel = GetControlFromModel(xControlModel); + DBG_ASSERT(xControlBehindModel.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !"); + } - if (IsSearchableControl(xControlBehindModel)) - { // alle Tests ueberstanden -> in die Liste mit aufnehmen - strFieldList += sControlSource.getStr(); - strFieldList += ';'; + if (IsSearchableControl(xControlBehindModel)) + { // alle Tests ueberstanden -> in die Liste mit aufnehmen + strFieldList += sControlSource.getStr(); + strFieldList += ';'; - // the label which should appear for the control : - sFieldDisplayNames += getLabelName(Reference< XPropertySet>(xControlModel, UNO_QUERY)).getStr(); - sFieldDisplayNames += ';'; + // the label which should appear for the control : + sFieldDisplayNames += getLabelName(Reference< XPropertySet>(xControlModel, UNO_QUERY)).getStr(); + sFieldDisplayNames += ';'; - // das SdrObjekt merken (beschleunigt die Behandlung in OnFoundData) - m_arrSearchedControls.C40_INSERT(SdrObject, pCurrent, m_arrSearchedControls.Count()); + // das SdrObjekt merken (beschleunigt die Behandlung in OnFoundData) + m_arrSearchedControls.C40_INSERT(SdrObject, pCurrent, m_arrSearchedControls.Count()); - // die Nummer der Spalte (hier ein Dummy, nur fuer GridControls interesant) - m_arrRelativeGridColumn.Insert(-1, m_arrRelativeGridColumn.Count()); + // die Nummer der Spalte (hier ein Dummy, nur fuer GridControls interesant) + m_arrRelativeGridColumn.Insert(-1, m_arrRelativeGridColumn.Count()); - // und fuer die formatierte Suche ... - pfmscContextInfo->arrFields.push_back(Reference< XInterface>(xControlBehindModel, UNO_QUERY)); - } - } + // und fuer die formatierte Suche ... + pfmscContextInfo->arrFields.push_back(Reference< XInterface>(xControlBehindModel, UNO_QUERY)); } - - xCurrent = iter.Next(); } } - if (pGroupIterator) // ich iteriere gerade durch eine Gruppe von Controls - pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL; - else - pCurrent = NULL; + xSearchable = iter.Next(); } - delete pGroupIterator; } + strFieldList.EraseTrailingChars(';'); sFieldDisplayNames.EraseTrailingChars(';'); |