/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// is used for Invalidate -> maintain it as well const sal_uInt16 DatabaseSlotMap[] =
{
SID_FM_RECORD_FIRST,
SID_FM_RECORD_NEXT,
SID_FM_RECORD_PREV,
SID_FM_RECORD_LAST,
SID_FM_RECORD_NEW,
SID_FM_RECORD_DELETE,
SID_FM_RECORD_ABSOLUTE,
SID_FM_RECORD_TOTAL,
SID_FM_RECORD_SAVE,
SID_FM_RECORD_UNDO,
SID_FM_REMOVE_FILTER_SORT,
SID_FM_SORTUP,
SID_FM_SORTDOWN,
SID_FM_ORDERCRIT,
SID_FM_AUTOFILTER,
SID_FM_FORM_FILTERED,
SID_FM_REFRESH,
SID_FM_REFRESH_FORM_CONTROL,
SID_FM_SEARCH,
SID_FM_FILTER_START,
SID_FM_VIEW_AS_GRID,
0
};
// is used for Invalidate -> maintain it as well // sort ascending !!!!!! const sal_uInt16 DlgSlotMap[] = // slots of the controller
{
SID_FM_CTL_PROPERTIES,
SID_FM_PROPERTIES,
SID_FM_TAB_DIALOG,
SID_FM_ADD_FIELD,
SID_FM_SHOW_FMEXPLORER,
SID_FM_FIELDS_CONTROL,
SID_FM_SHOW_PROPERTIES,
SID_FM_PROPERTY_CONTROL,
SID_FM_FMEXPLORER_CONTROL,
SID_FM_SHOW_DATANAVIGATOR,
SID_FM_DATANAVIGATOR_CONTROL,
0
};
// the following arrays must be consistent, i.e., corresponding entries should // be at the same relative position within their respective arrays static std::u16string_view aConvertSlots[] =
{
u"ConvertToEdit",
u"ConvertToButton",
u"ConvertToFixed",
u"ConvertToList",
u"ConvertToCheckBox",
u"ConvertToRadio",
u"ConvertToGroup",
u"ConvertToCombo",
u"ConvertToImageBtn",
u"ConvertToFileControl",
u"ConvertToDate",
u"ConvertToTime",
u"ConvertToNumeric",
u"ConvertToCurrency",
u"ConvertToPattern",
u"ConvertToImageControl",
u"ConvertToFormatted",
u"ConvertToScrollBar",
u"ConvertToSpinButton",
u"ConvertToNavigationBar"
};
while ( 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 ); // the UNO_QUERY is important for normalization if ( xControlModel.is() )
_rInterfaces.insert( xControlModel );
}
// next element
pCurrent = oGroupIterator && oGroupIterator->IsMore() ? oGroupIterator->Next() : nullptr;
}
}
}
sal_Int32 GridView2ModelPos(const Reference< XIndexAccess>& rColumns, sal_Int16 nViewPos)
{ try
{ if (rColumns.is())
{ // loop through all columns
sal_Int32 i;
Reference< XPropertySet> xCur; for (i=0; i<rColumns->getCount(); ++i)
{
rColumns->getByIndex(i) >>= xCur; if (!::comphelper::getBOOL(xCur->getPropertyValue(FM_PROP_HIDDEN)))
{ // for every visible col : if nViewPos is greater zero, decrement it, else we // have found the model position if (!nViewPos) break; else
--nViewPos;
}
} if (i<rColumns->getCount()) return i;
}
} catch(const Exception&)
{
DBG_UNHANDLED_EXCEPTION("svx");
} return -1;
}
void TransferEventScripts(const Reference< XControlModel>& xModel, const Reference< XControl>& xControl, const Sequence< ScriptEventDescriptor>& rTransferIfAvailable)
{ // first check if we have a XEventAttacherManager for the model
Reference< XChild> xModelChild(xModel, UNO_QUERY); if (!xModelChild.is()) return; // nothing to do
Reference< XEventAttacherManager> xEventManager(xModelChild->getParent(), UNO_QUERY); if (!xEventManager.is()) return; // nothing to do
if (!rTransferIfAvailable.hasElements()) return; // nothing to do
// check for the index of the model within its parent
Reference< XIndexAccess> xParentIndex(xModelChild->getParent(), UNO_QUERY); if (!xParentIndex.is()) return; // nothing to do
sal_Int32 nIndex = getElementPos(xParentIndex, xModel); if (nIndex<0 || nIndex>=xParentIndex->getCount()) return; // nothing to do
// then we need information about the listeners supported by the control and the model
Sequence< Type> aModelListeners;
Sequence< Type> aControlListeners;
if (xModel.is())
{
Any aModel(xModel);
aModelListeners = xIntrospection->inspect(aModel)->getSupportedListeners();
}
if (xControl.is())
{
Any aControl(xControl);
aControlListeners = xIntrospection->inspect(aControl)->getSupportedListeners();
}
sal_Int32 nMaxNewLen = aModelListeners.getLength() + aControlListeners.getLength(); if (!nMaxNewLen) return; // the model and the listener don't support any listeners (or we were unable to retrieve these infos)
for (const ScriptEventDescriptor& rCurrent : rTransferIfAvailable)
{ // search the model/control idl classes for the event described by pCurrent for (const Sequence< Type>* pCurrentArray : { &aModelListeners, &aControlListeners })
{ for (const Type& rCurrentListener : *pCurrentArray)
{
OUString aListener = rCurrentListener.getTypeName(); if (!aListener.isEmpty())
aListener = aListener.copy(aListener.lastIndexOf('.')+1);
if (aListener == rCurrent.ListenerType) // the current ScriptEventDescriptor doesn't match the current listeners class continue;
// now check the methods
Sequence< OUString> aMethodsNames = ::comphelper::getEventMethodsForType(rCurrentListener);
if (comphelper::findValue(aMethodsNames, rCurrent.EventMethod) != -1)
{ // we can transfer the script event : the model (control) supports it
*pTransferable = rCurrent;
++pTransferable; break;
}
}
}
}
const OUString & getServiceNameByControlType(SdrObjKind nType)
{ switch (nType)
{ case SdrObjKind::FormEdit : return FM_COMPONENT_TEXTFIELD; case SdrObjKind::FormButton : return FM_COMPONENT_COMMANDBUTTON; case SdrObjKind::FormFixedText : return FM_COMPONENT_FIXEDTEXT; case SdrObjKind::FormListbox : return FM_COMPONENT_LISTBOX; case SdrObjKind::FormCheckbox : return FM_COMPONENT_CHECKBOX; case SdrObjKind::FormRadioButton : return FM_COMPONENT_RADIOBUTTON; case SdrObjKind::FormGroupBox : return FM_COMPONENT_GROUPBOX; case SdrObjKind::FormCombobox : return FM_COMPONENT_COMBOBOX; case SdrObjKind::FormGrid : return FM_COMPONENT_GRIDCONTROL; case SdrObjKind::FormImageButton : return FM_COMPONENT_IMAGEBUTTON; case SdrObjKind::FormFileControl : return FM_COMPONENT_FILECONTROL; case SdrObjKind::FormDateField : return FM_COMPONENT_DATEFIELD; case SdrObjKind::FormTimeField : return FM_COMPONENT_TIMEFIELD; case SdrObjKind::FormNumericField : return FM_COMPONENT_NUMERICFIELD; case SdrObjKind::FormCurrencyField : return FM_COMPONENT_CURRENCYFIELD; case SdrObjKind::FormPatternField : return FM_COMPONENT_PATTERNFIELD; case SdrObjKind::FormHidden : return FM_COMPONENT_HIDDENCONTROL; case SdrObjKind::FormImageControl : return FM_COMPONENT_IMAGECONTROL; case SdrObjKind::FormFormattedField : return FM_COMPONENT_FORMATTEDFIELD; case SdrObjKind::FormScrollbar : return FM_SUN_COMPONENT_SCROLLBAR; case SdrObjKind::FormSpinButton : return FM_SUN_COMPONENT_SPINBUTTON; case SdrObjKind::FormNavigationBar : return FM_SUN_COMPONENT_NAVIGATIONBAR; default:;
} return EMPTY_OUSTRING;
}
}
// check if the control has one of the interfaces we can use for searching // *_pCurrentText will be filled with the current text of the control (as used when searching this control) bool IsSearchableControl( const css::uno::Reference< css::uno::XInterface>& _rxControl,
OUString* _pCurrentText )
{ if ( !_rxControl.is() ) returnfalse;
bool FmXBoundFormFieldIterator::ShouldStepInto(const Reference< XInterface>& _rContainer) const
{ if (_rContainer == m_xStartingPoint) // would be quite stupid to step over the root... returntrue;
bool FmXBoundFormFieldIterator::ShouldHandleElement(const Reference< XInterface>& _rElement)
{ if (!_rElement.is()) // NULL element returnfalse;
if (Reference< XForm>(_rElement, UNO_QUERY).is() || Reference< XGrid>(_rElement, UNO_QUERY).is()) // a forms or a grid returnfalse;
Reference< XPropertySet> xSet(_rElement, UNO_QUERY); if (!xSet.is() || !::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xSet)) // no "BoundField" property returnfalse;
Any aVal( xSet->getPropertyValue(FM_PROP_BOUNDFIELD) ); if (aVal.getValueTypeClass() != TypeClass_INTERFACE) // void or invalid property value returnfalse;
return aVal.hasValue();
}
staticbool isControlList(const SdrMarkList& rMarkList)
{ // the list contains only controls and at least one control const size_t nMarkCount = rMarkList.GetMarkCount(); bool bControlList = nMarkCount != 0;
bool bHadAnyLeafs = false;
for (size_t i = 0; i < nMarkCount && bControlList; ++i)
{
SdrObject *pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
E3dObject* pAs3DObject = DynCastE3dObject( pObj); // E3dObject's do not contain any 2D-objects (by definition) // we need this extra check here : an E3dObject->IsGroupObject says "YES", but an SdrObjListIter working // with an E3dObject doesn't give me any Nodes (E3dObject has a sub list, but no members in that list, // cause there implementation differs from the one of "normal" SdrObject's. Unfortunally SdrObject::IsGroupObject // doesn't check the element count of the sub list, which is simply a bug in IsGroupObject we can't fix at the moment). // So at the end of this function bControlList would have the same value it was initialized with above : sal_True // And this would be wrong :) // 03.02.00 - 72529 - FS if (!pAs3DObject)
{ if (pObj->IsGroupObject())
{
SdrObjListIter aIter(pObj->GetSubList()); while (aIter.IsMore() && bControlList)
{
bControlList = SdrInventor::FmForm == aIter.Next()->GetObjInventor();
bHadAnyLeafs = true;
}
} else
{
bHadAnyLeafs = true;
bControlList = SdrInventor::FmForm == pObj->GetObjInventor();
}
}
}
// to prevent deletion of this we acquire our refcounter once
osl_atomic_increment(&m_refCount);
// correct the refcounter
osl_atomic_decrement(&m_refCount);
// cache the current configuration settings we're interested in
implAdjustConfigCache_Lock(); // and register for changes on this settings
Sequence< OUString > aNames { u"FormControlPilotsEnabled"_ustr };
EnableNotification(aNames);
}
// determine the type of document we live in try
{
Reference< css::frame::XController > xController; if ( m_xAttachedFrame.is() )
xController = m_xAttachedFrame->getController(); if ( xController.is() )
xModel = xController->getModel();
} catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("svx");
} return xModel;
}
// determine the type of document we live in
Reference<css::frame::XModel> xModel = getContextDocument_Lock(); if ( xModel.is() )
m_eDocumentType = DocumentClassification::classifyDocument( xModel ); else
{
OSL_FAIL( "FmXFormShell::getDocumentType: can't determine the document type!" );
m_eDocumentType = eTextDocument; // fallback, just to have a defined state
}
return m_eDocumentType;
}
bool FmXFormShell::IsReadonlyDoc_Lock() const
{ if (impl_checkDisposed_Lock()) returntrue;
if (m_xExternalViewController.is())
m_xExternalViewController->removeEventListener(static_cast<XEventListener*>(static_cast<XPropertyChangeListener*>(this)));
if (evt.PropertyName == FM_PROP_ROWCOUNT)
{ // The update following this forces a re-painting of the corresponding // slots. But if I am not in the MainThread of the application (because, // for example, a cursor is counting data sets at the moment and always // gives me this PropertyChanges), this can clash with normal paints in // the MainThread of the application. (Such paints happen, for example, // if one simply places another application over the office and switches // back again). // Therefore the use of the SolarMutex, which safeguards that.
comphelper::SolarMutex& rSolarSafety = Application::GetSolarMutex(); if (rSolarSafety.tryToAcquire())
{
m_pShell->GetViewShell()->GetViewFrame().GetBindings().Invalidate(SID_FM_RECORD_TOTAL, true);
m_pShell->GetViewShell()->GetViewFrame().GetBindings().Update(SID_FM_RECORD_TOTAL);
rSolarSafety.release();
} else
{ // with the following the slot is invalidated asynchron
LockSlotInvalidation_Lock(true);
InvalidateSlot_Lock(SID_FM_RECORD_TOTAL, false);
LockSlotInvalidation_Lock(false);
}
}
// this may be called from a non-main-thread so invalidate the shell asynchronously
LockSlotInvalidation_Lock(true);
InvalidateSlot_Lock(0, false); // special meaning : invalidate m_pShell
LockSlotInvalidation_Lock(false);
}
if ( m_pShell && !m_pShell->IsDesignMode() )
setActiveController_Lock(nullptr, true); // do NOT save the content of the old form (the second parameter tells this) // if we're here, then we expect that PrepareClose has been called, and thus the user // got a chance to commit or reject any changes. So in case we're here and there // are still uncommitted changes, the user explicitly wanted this.
m_pTextShell->dispose();
m_xAttachedFrame = nullptr;
CloseExternalFormViewer_Lock();
while ( !m_aLoadingPages.empty() )
{
Application::RemoveUserEvent( m_aLoadingPages.front().nEventId );
m_aLoadingPages.pop();
}
{
DBG_ASSERT(!m_nInvalidationEvent, "FmXFormShell::~FmXFormShell : still have an invalidation event !"); // should have been deleted while being disposed
void FmXFormShell::GetConversionMenu_Lock(weld::Menu& rNewMenu)
{ for (size_t i = 0; i < SAL_N_ELEMENTS(aConvertSlots); ++i)
{ // the corresponding image at it
rNewMenu.append(OUString(aConvertSlots[i]), SvxResId(RID_SVXSW_CONVERTMENU[i]), aImgIds[i]);
}
}
// remember old script events
Reference< css::script::XEventAttacherManager> xEvManager(xChild->getParent(), UNO_QUERY); if (xParent.is() && xEvManager.is())
{
sal_Int32 nIndex = getElementPos(xParent, xOldModel); if (nIndex>=0 && nIndex<xParent->getCount())
aOldScripts = xEvManager->getScriptEvents(nIndex);
}
// replace the model within the parent container
Reference< XIndexContainer> xIndexParent(xChild->getParent(), UNO_QUERY); if (xIndexParent.is())
{ // the form container works with FormComponents
Reference< XFormComponent> xComponent(xNewModel, UNO_QUERY);
DBG_ASSERT(xComponent.is(), "FmXFormShell::executeControlConversionSlot: the new model is no form component !");
Any aNewModel(xComponent); try
{
sal_Int32 nIndex = getElementPos(xParent, xOldModel); if (nIndex>=0 && nIndex<xParent->getCount())
xIndexParent->replaceByIndex(nIndex, aNewModel); else
{
OSL_FAIL("FmXFormShell::executeControlConversionSlot: could not replace the model !");
Reference< css::lang::XComponent> xNewComponent(xNewModel, UNO_QUERY); if (xNewComponent.is())
xNewComponent->dispose(); returnfalse;
}
} catch(Exception&)
{
OSL_FAIL("FmXFormShell::executeControlConversionSlot: could not replace the model !");
Reference< css::lang::XComponent> xNewComponent(xNewModel, UNO_QUERY); if (xNewComponent.is())
xNewComponent->dispose(); returnfalse;
}
}
}
// special handling for the LabelControl-property : can only be set when the model is placed // within the forms hierarchy if (::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xOldSet) && ::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xNewSet))
{ try
{
xNewSet->setPropertyValue(FM_PROP_CONTROLLABEL, xOldSet->getPropertyValue(FM_PROP_CONTROLLABEL));
} catch(Exception&)
{
}
}
// set new model
pFormObject->SetChanged();
pFormObject->SetUnoControlModel(xNewModel);
// transfer script events // (do this _after_ SetUnoControlModel as we need the new (implicitly created) control) if (aOldScripts.hasElements())
{ // find the control for the model
Reference<XControlContainer> xControlContainer(getControlContainerForView_Lock());
// transfer value bindings, if possible
{
Reference< XBindableValue > xOldBindable( xOldModel, UNO_QUERY );
Reference< XBindableValue > xNewBindable( xNewModel, UNO_QUERY ); if ( xOldBindable.is() )
{ try
{ if ( xNewBindable.is() )
xNewBindable->setValueBinding( xOldBindable->getValueBinding() );
xOldBindable->setValueBinding( nullptr );
} catch(const Exception&)
{
DBG_UNHANDLED_EXCEPTION("svx");
}
}
} // same for list entry sources
{
Reference< XListEntrySink > xOldSink( xOldModel, UNO_QUERY );
Reference< XListEntrySink > xNewSink( xNewModel, UNO_QUERY ); if ( xOldSink.is() )
{ try
{ if ( xNewSink.is() )
xNewSink->setListEntrySource( xOldSink->getListEntrySource() );
xOldSink->setListEntrySource( nullptr );
} catch(const Exception&)
{
DBG_UNHANDLED_EXCEPTION("svx");
}
}
}
// create an undo action
FmFormModel* pModel = m_pShell->GetFormModel();
DBG_ASSERT(pModel != nullptr, "FmXFormShell::executeControlConversionSlot: my shell has no model !"); if (pModel && pModel->IsUndoEnabled() )
{
pModel->AddUndo(std::make_unique<FmUndoModelReplaceAction>(*pModel, pFormObject, xOldModel));
} else
{
FmUndoModelReplaceAction::DisposeElement( xOldModel );
}
returntrue;
}
} returnfalse;
}
bool FmXFormShell::canConvertCurrentSelectionToControl_Lock(std::u16string_view rIdent)
{ if ( m_aCurrentSelection.empty() ) returnfalse;
InterfaceBag::const_iterator aCheck = m_aCurrentSelection.begin();
Reference< lang::XServiceInfo > xElementInfo( *aCheck, UNO_QUERY ); if ( !xElementInfo.is() ) // no service info -> cannot determine this returnfalse;
if ( ++aCheck != m_aCurrentSelection.end() ) // more than one element returnfalse;
if ( Reference< XForm >::query( xElementInfo ).is() ) // it's a form returnfalse;
if ( ( SdrObjKind::FormHidden == nObjectType )
|| ( SdrObjKind::FormControl == nObjectType )
|| ( SdrObjKind::FormGrid == nObjectType )
) returnfalse; // those types cannot be converted
DBG_ASSERT(SAL_N_ELEMENTS(aConvertSlots) == SAL_N_ELEMENTS(nObjectTypes), "FmXFormShell::canConvertCurrentSelectionToControl: aConvertSlots & nObjectTypes must have the same size !");
for (size_t i = 0; i < SAL_N_ELEMENTS(aConvertSlots); ++i) if (rIdent == aConvertSlots[i]) return nObjectTypes[i] != nObjectType;
returntrue; // all other slots: assume "yes"
}
void FmXFormShell::checkControlConversionSlotsForCurrentSelection_Lock(weld::Menu& rMenu)
{ for (int i = 0, nCount = rMenu.n_children(); i < nCount; ++i)
{ // the context is already of a type that corresponds to the entry -> disable
OUString sIdent(aConvertSlots[i]);
rMenu.set_sensitive(sIdent, canConvertCurrentSelectionToControl_Lock(sIdent));
}
}
void FmXFormShell::LoopGrids_Lock(LoopGridsSync nSync, LoopGridsFlags nFlags)
{ if (impl_checkDisposed_Lock()) return;
Reference< XIndexContainer> xControlModels(m_xActiveForm, UNO_QUERY); if (!xControlModels.is()) return;
for (sal_Int32 i=0; i<xControlModels->getCount(); ++i)
{
Reference< XPropertySet> xModelSet;
xControlModels->getByIndex(i) >>= xModelSet; if (!xModelSet.is()) continue;
if (!::comphelper::hasProperty(FM_PROP_CLASSID, xModelSet)) continue;
sal_Int16 nClassId = ::comphelper::getINT16(xModelSet->getPropertyValue(FM_PROP_CLASSID)); if (FormComponentType::GRIDCONTROL != nClassId) continue;
if (!::comphelper::hasProperty(FM_PROP_CURSORCOLOR, xModelSet) || !::comphelper::hasProperty(FM_PROP_ALWAYSSHOWCURSOR, xModelSet) || !::comphelper::hasProperty(FM_PROP_DISPLAYSYNCHRON, xModelSet)) continue;
switch (nSync)
{ case LoopGridsSync::DISABLE_SYNC:
{
xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(false));
} break; case LoopGridsSync::FORCE_SYNC:
{
Any aOldVal( xModelSet->getPropertyValue(FM_PROP_DISPLAYSYNCHRON) );
xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(true));
xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, aOldVal);
} break; case LoopGridsSync::ENABLE_SYNC:
{
xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(true));
} break;
}
if (nFlags & LoopGridsFlags::DISABLE_ROCTRLR)
{
xModelSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any(false));
Reference< XPropertyState> xModelPropState(xModelSet, UNO_QUERY); if (xModelPropState.is())
xModelPropState->setPropertyToDefault(FM_PROP_CURSORCOLOR); else
xModelSet->setPropertyValue(FM_PROP_CURSORCOLOR, Any()); // this should be the default
}
}
}
Reference< XControlContainer > FmXFormShell::getControlContainerForView_Lock() const
{ if (impl_checkDisposed_Lock()) return nullptr;
void FmXFormShell::ExecuteSearch_Lock()
{ if (impl_checkDisposed_Lock()) return;
// a collection of all (logical) forms
FmFormArray().swap(m_aSearchForms);
::std::vector< OUString > aContextNames;
impl_collectFormSearchContexts_nothrow_Lock(
m_pShell->GetCurPage()->GetForms(), u"",
m_aSearchForms, aContextNames);
if (m_aSearchForms.empty() )
{ // there are no controls that meet all the conditions for a search
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
VclMessageType::Warning, VclButtonsType::Ok,
SvxResId(RID_STR_NODATACONTROLS)));
xBox->run(); return;
}
// now I need another 'initial context'
sal_Int16 nInitialContext = 0;
Reference<XForm> xActiveForm(getActiveForm_Lock()); for ( size_t i=0; i<m_aSearchForms.size(); ++i )
{ if (m_aSearchForms.at(i) == xActiveForm)
{
nInitialContext = static_cast<sal_Int16>(i); break;
}
}
// If the dialog should initially offer the text of the active control, // this must have an XTextComponent interface. An addition, this makes // sense only if the current field is also bound to a table (or whatever) field.
OUString strActiveField;
OUString strInitialText; // ... this I get from my FormController
DBG_ASSERT(m_xActiveController.is(), "FmXFormShell::ExecuteSearch : no active controller !");
Reference< XControl> xActiveControl( m_xActiveController->getCurrentControl()); if (xActiveControl.is())
{ // the control can tell me its model ...
Reference< XControlModel> xActiveModel( xActiveControl->getModel());
DBG_ASSERT(xActiveModel.is(), "FmXFormShell::ExecuteSearch : active control has no model !");
// I ask the model for the ControlSource property ...
Reference< XPropertySet> xProperties(xActiveControl->getModel(), UNO_QUERY); if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xProperties) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xProperties))
{
Reference< XPropertySet> xField;
xProperties->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField; if (xField.is()) // (only when the thing is really bound)
{ // and the control itself for a TextComponent interface (so that I can pick up the text there)
Reference< XTextComponent> xText(xActiveControl, UNO_QUERY); if (xText.is())
{
strActiveField = getLabelName(xProperties);
strInitialText = xText->getText();
}
}
} else
{ // the control itself has no ControlSource, but maybe it is a GridControl
Reference< XGrid> xGrid(xActiveControl, UNO_QUERY); if (xGrid.is())
{ // for strActiveField I need the ControlSource of the column, // for that the columns container, for that the GridPeer
Reference< XGridPeer> xGridPeer(xActiveControl->getPeer(), UNO_QUERY);
Reference< XIndexAccess> xColumns; if (xGridPeer.is())
xColumns = xGridPeer->getColumns();
// the text of the current column
Reference< XIndexAccess> xColControls(xGridPeer, UNO_QUERY);
Reference< XInterface> xCurControl;
xColControls->getByIndex(nViewCol) >>= xCurControl;
OUString sInitialText; if (IsSearchableControl(xCurControl, &sInitialText))
strInitialText = sInitialText;
}
}
}
// taking care of possible GridControls that I know
LoopGrids_Lock(LoopGridsSync::DISABLE_SYNC);
// Now I am ready for the dialogue. // When the potential deadlocks caused by the use of the solar mutex in // MTs VCLX... classes are eventually cleared, an SM_USETHREAD should be // placed here, because the search in a separate thread is nevertheless // somewhat more fluid. Should be, however, somehow made dependent of the // underlying cursor. DAO for example is not thread-safe.
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
ScopedVclPtr<AbstractFmSearchDialog> pDialog(
pFact->CreateFmSearchDialog(
m_pShell->GetViewShell()->GetViewFrame().GetFrameWeld(),
strInitialText, aContextNames, nInitialContext,
LINK(this, FmXFormShell, OnSearchContextRequest_Lock) ));
pDialog->SetActiveField( strActiveField );
pDialog->SetFoundHandler(LINK(this, FmXFormShell, OnFoundData_Lock));
pDialog->SetCanceledNotFoundHdl(LINK(this, FmXFormShell, OnCanceledNotFound_Lock));
pDialog->Execute();
pDialog.disposeAndClear();
// restore GridControls again
LoopGrids_Lock(LoopGridsSync::ENABLE_SYNC, LoopGridsFlags::DISABLE_ROCTRLR);
m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView()); // because I marked controls in OnFoundData (if I was there)
}
bool FmXFormShell::GetY2KState_Lock(sal_uInt16& n)
{ if (impl_checkDisposed_Lock()) returnfalse;
if (m_pShell->IsDesignMode()) // in the design mode (without active controls) the main document is to take care of it returnfalse;
Reference<XForm> xForm(getActiveForm_Lock()); if (!xForm.is()) // no current form (in particular no current control) -> the main document is to take care returnfalse;
Reference< XRowSet> xDB(xForm, UNO_QUERY);
DBG_ASSERT(xDB.is(), "FmXFormShell::GetY2KState : current form has no dbform-interface !");
Reference< XNumberFormatsSupplier> xSupplier( getNumberFormats(getConnection(xDB))); if (xSupplier.is())
{
Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings()); if (xSet.is())
{ try
{
Any aVal( xSet->getPropertyValue(u"TwoDigitDateStart"_ustr) );
aVal >>= n; returntrue;
} catch(Exception&)
{
}
}
} returnfalse;
}
void FmXFormShell::SetY2KState_Lock(sal_uInt16 n)
{ if (impl_checkDisposed_Lock()) return;
// no active form found -> iterate through all current forms
Reference< XIndexAccess> xCurrentForms( m_xForms); if (!xCurrentForms.is())
{ // in the alive mode, my forms are not set, but the ones on the page are if (m_pShell->GetCurPage())
xCurrentForms = m_pShell->GetCurPage()->GetForms( false );
} if (!xCurrentForms.is()) return;
::comphelper::IndexAccessIterator aIter(xCurrentForms);
Reference< XInterface> xCurrentElement( aIter.Next()); while (xCurrentElement.is())
{ // is the current element a DatabaseForm?
Reference< XRowSet> xElementAsRowSet( xCurrentElement, UNO_QUERY ); if ( xElementAsRowSet.is() )
{
Reference< XNumberFormatsSupplier > xSupplier( getNumberFormats( getConnection( xElementAsRowSet ) ) ); if (!xSupplier.is()) continue;
// if we're doing an UNDO, *and* if the affected form is the form which we also display // as external view, then we need to reset the controls of the external form, too if (getInternalForm_Lock(getActiveForm_Lock()) != m_xExternalDisplayedForm) return;
Reference< XReset > xReset; for ( sal_Int32 i = 0; i < xContainer->getCount(); ++i )
{ if ( ( xContainer->getByIndex( i ) >>= xReset ) && xReset.is() )
{ // no resets on sub forms
Reference< XForm > xAsForm( xReset, UNO_QUERY ); if ( !xAsForm.is() )
xReset->reset();
}
}
}
void FmXFormShell::impl_switchActiveControllerListening_Lock(constbool _bListen)
{ if ( !m_xActiveController.is() ) return;
void FmXFormShell::setActiveController_Lock(const Reference<runtime::XFormController>& xController, bool _bNoSaveOldContent)
{ if (impl_checkDisposed_Lock()) return;
if (m_bChangingDesignMode) return;
DBG_ASSERT(!m_pShell->IsDesignMode(), "only to be used in alive mode");
// if the routine has been called a second time, // the focus should no longer be transferred if (m_bInActivate)
{
m_bSetFocus = xController != m_xActiveController; return;
}
if (xController == m_xActiveController) return;
// switch all nav dispatchers belonging to the form of the current nav controller to 'non active'
Reference< XResultSet> xNavigationForm; if (m_xNavigationController.is())
xNavigationForm.set(m_xNavigationController->getModel(), UNO_QUERY);
m_bInActivate = true;
// check if the 2 controllers serve different forms
Reference< XResultSet> xOldForm; if (m_xActiveController.is())
xOldForm.set(m_xActiveController->getModel(), UNO_QUERY);
Reference< XResultSet> xNewForm; if (xController.is())
xNewForm = Reference< XResultSet>(xController->getModel(), UNO_QUERY);
xOldForm = getInternalForm_Lock(xOldForm);
xNewForm = getInternalForm_Lock(xNewForm);
bool bDifferentForm = ( xOldForm.get() != xNewForm.get() ); bool bNeedSave = bDifferentForm && !_bNoSaveOldContent; // we save the content of the old form if we move to a new form, and saving old content is allowed
if ( m_xActiveController.is() && bNeedSave )
{ // save content on change of the controller; a commit has already been executed if ( m_aActiveControllerFeatures->commitCurrentControl() )
{
m_bSetFocus = true; if ( m_aActiveControllerFeatures->isModifiedRow() )
{ bool bIsNew = m_aActiveControllerFeatures->isInsertionRow(); bool bResult = m_aActiveControllerFeatures->commitCurrentRecord(); if ( !bResult && m_bSetFocus )
{ // if we couldn't save the current record, set the focus back to the // current control
Reference< XWindow > xWindow( m_xActiveController->getCurrentControl(), UNO_QUERY ); if ( xWindow.is() )
xWindow->setFocus();
m_bInActivate = false; return;
} elseif ( bResult && bIsNew )
{
Reference< XResultSet > xCursor( m_aActiveControllerFeatures->getCursor() ); if ( xCursor.is() )
{
DO_SAFE( xCursor->last(); );
}
}
}
}
}
// activate all dispatchers belonging to form of the new navigation controller
xNavigationForm = nullptr; if (m_xNavigationController.is())
xNavigationForm.set(m_xNavigationController->getModel(), UNO_QUERY);
bool FmXFormShell::setCurrentSelection_Lock( InterfaceBag&& _rSelection )
{ if (impl_checkDisposed_Lock()) returnfalse;
DBG_ASSERT( m_pShell->IsDesignMode(), "FmXFormShell::setCurrentSelection: only to be used in design mode!" );
if ( _rSelection.empty() && m_aCurrentSelection.empty() ) // nothing to do returnfalse;
if ( _rSelection.size() == m_aCurrentSelection.size() )
{
InterfaceBag::const_iterator aNew = _rSelection.begin();
InterfaceBag::const_iterator aOld = m_aCurrentSelection.begin(); for ( ; aNew != _rSelection.end(); ++aNew, ++aOld )
{
OSL_ENSURE( Reference< XInterface >( *aNew, UNO_QUERY ).get() == aNew->get(), "FmXFormShell::setCurrentSelection: new interface not normalized!" );
OSL_ENSURE( Reference< XInterface >( *aOld, UNO_QUERY ).get() == aOld->get(), "FmXFormShell::setCurrentSelection: old interface not normalized!" );
if ( aNew->get() != aOld->get() ) break;
}
if ( aNew == _rSelection.end() ) // both bags equal returnfalse;
}
// the following is some strange code to ensure that when you have two grid controls in a document, // only one of them can have a selected column. // TODO: this should happen elsewhere, but not here - shouldn't it? if ( !m_aCurrentSelection.empty() )
{
Reference< XChild > xCur; if ( m_aCurrentSelection.size() == 1 ) xCur.set(*m_aCurrentSelection.begin(), css::uno::UNO_QUERY);
Reference< XChild > xNew; if ( _rSelection.size() == 1 ) xNew.set(*_rSelection.begin(), css::uno::UNO_QUERY);
// is there nothing to be selected, or the parents differ, and the parent of the current object // is a selection supplier, then deselect if ( xCur.is() && ( !xNew.is() || ( xCur->getParent() != xNew->getParent() ) ) )
{
Reference< XSelectionSupplier > xSel( xCur->getParent(), UNO_QUERY ); if ( xSel.is() )
xSel->select( Any() );
}
}
m_aCurrentSelection = std::move(_rSelection);
// determine the form which all the selected objects belong to, if any
Reference< XForm > xNewCurrentForm; for (constauto& rpSelection : m_aCurrentSelection)
{
Reference< XForm > xThisRoundsForm( GetForm( rpSelection ) );
OSL_ENSURE( xThisRoundsForm.is(), "FmXFormShell::setCurrentSelection: *everything* should belong to a form!" );
if ( !xNewCurrentForm.is() )
{ // the first form we encountered
xNewCurrentForm = std::move(xThisRoundsForm);
} elseif ( xNewCurrentForm != xThisRoundsForm )
{ // different forms -> no "current form" at all
xNewCurrentForm.clear(); break;
}
}
if ( !m_aCurrentSelection.empty() )
impl_updateCurrentForm_Lock(xNewCurrentForm);
// ensure some slots are updated for (sal_Int16 i : SelObjectSlotMap)
InvalidateSlot_Lock(i, false);
// ... and try finding a new current form // #i88186# / 2008-04-12 / frank.schoenheit@sun.com
impl_defaultCurrentForm_nothrow_Lock();
}
void FmXFormShell::impl_updateCurrentForm_Lock(const Reference<XForm>& _rxNewCurForm)
{ if (impl_checkDisposed_Lock()) return;
m_xCurrentForm = _rxNewCurForm;
// propagate to the FormPage(Impl)
FmFormPage* pPage = m_pShell->GetCurPage(); if ( pPage )
pPage->GetImpl().setCurForm( m_xCurrentForm );
// ensure the UI which depends on the current form is up-to-date for (sal_Int16 i : DlgSlotMap)
InvalidateSlot_Lock(i, false);
}
void FmXFormShell::startListening_Lock()
{ if (impl_checkDisposed_Lock()) return;
Reference< XRowSet> xDatabaseForm(m_xActiveForm, UNO_QUERY); if (xDatabaseForm.is() && getConnection(xDatabaseForm).is())
{
Reference< XPropertySet> xActiveFormSet(m_xActiveForm, UNO_QUERY); if (xActiveFormSet.is())
{ // if there is a data source, then build the listener // TODO: this is strange - shouldn't this depend on a isLoaded instead of // a "has command value"? Finally, the command value only means that it was // intended to be loaded, not that it actually *is* loaded
OUString aSource = ::comphelper::getString(xActiveFormSet->getPropertyValue(FM_PROP_COMMAND)); if (!aSource.isEmpty())
{
m_bDatabaseBar = true;
// because of RecordCount, listen at the controller which controls the navigation
Reference< XPropertySet> xNavigationSet; if (m_xNavigationController.is())
{
xNavigationSet.set(m_xNavigationController->getModel(), UNO_QUERY); if (xNavigationSet.is())
xNavigationSet->addPropertyChangeListener(FM_PROP_ROWCOUNT,this);
} return;
}
}
}
void FmXFormShell::ShowSelectionProperties_Lock(bool bShow)
{ if (impl_checkDisposed_Lock()) return;
// if the window is already visible, only update the state bool bHasChild = m_pShell->GetViewShell()->GetViewFrame().HasChildWindow( SID_FM_SHOW_PROPERTIES ); if ( bHasChild && bShow )
UpdateSlot_Lock(SID_FM_PROPERTY_CONTROL);
// else toggle state else
m_pShell->GetViewShell()->GetViewFrame().ToggleChildWindow(SID_FM_SHOW_PROPERTIES);
Reference< XRowLocate> xCursor(xForm, UNO_QUERY); if (!xCursor.is()) return; // what should I do there?
// to the record try
{
xCursor->moveToBookmark(rfriWhere.aPosition);
} catch(const SQLException&)
{
OSL_FAIL("Can position on bookmark!");
}
LoopGrids_Lock(LoopGridsSync::FORCE_SYNC);
// and to the field (for that, I collected the XVclComponent interfaces before the start of the search)
SAL_WARN_IF(o3tl::make_unsigned(rfriWhere.nFieldPos) >=
m_arrSearchedControls.size(), "svx.form", "FmXFormShell::OnFoundData : invalid index!");
SdrObject* pObject = m_arrSearchedControls.at(rfriWhere.nFieldPos);
// disable the permanent cursor for the last grid we found a record if (m_xLastGridFound.is() && (m_xLastGridFound != xControlModel))
{
Reference< XPropertySet> xOldSet(m_xLastGridFound, UNO_QUERY);
xOldSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any( false ) );
Reference< XPropertyState> xOldSetState(xOldSet, UNO_QUERY); if (xOldSetState.is())
xOldSetState->setPropertyToDefault(FM_PROP_CURSORCOLOR); else
xOldSet->setPropertyValue(FM_PROP_CURSORCOLOR, Any());
}
// if the field is in a GridControl, I have to additionally go into the corresponding column there
sal_Int32 nGridColumn = m_arrRelativeGridColumn[rfriWhere.nFieldPos]; if (nGridColumn != -1)
{ // unfortunately, I have to first get the control again
Reference<XControl> xControl(pFormObject ? impl_getControl_Lock(xControlModel, *pFormObject) : Reference<XControl>());
Reference< XGrid> xGrid(xControl, UNO_QUERY);
DBG_ASSERT(xGrid.is(), "FmXFormShell::OnFoundData : invalid control!"); // if one of the asserts fires, I probably did something wrong on building of m_arrSearchedControls
// enable a permanent cursor for the grid so we can see the found text
Reference< XPropertySet> xModelSet(xControlModel, UNO_QUERY);
DBG_ASSERT(xModelSet.is(), "FmXFormShell::OnFoundData : invalid control model (no property set) !");
xModelSet->setPropertyValue( FM_PROP_ALWAYSSHOWCURSOR, Any( true ) );
xModelSet->setPropertyValue( FM_PROP_CURSORCOLOR, Any( COL_LIGHTRED ) );
m_xLastGridFound = std::move(xControlModel);
if ( xGrid.is() )
xGrid->setCurrentColumnPosition(static_cast<sal_Int16>(nGridColumn));
}
// As the cursor has been repositioned, I have (in positioned) invalidated // my form bar slots. But that does not take effect here unfortunately, as // generally the (modal) search dialog is of course at the top ... So, force ...
sal_uInt16 nPos = 0; while (DatabaseSlotMap[nPos])
m_pShell->GetViewShell()->GetViewFrame().GetBindings().Update(DatabaseSlotMap[nPos++]); // unfortunately the update goes against the invalidate with only individual slots
}
IMPL_LINK(FmXFormShell, OnCanceledNotFound_Lock, FmFoundRecordInformation&, rfriWhere, void)
{ if (impl_checkDisposed_Lock()) return;
Reference< XResultSet> xIter(xForm, UNO_QUERY);
DBG_ASSERT(xIter.is(), "FmXFormShell::OnSearchContextRequest : unexpected : context has no iterator !");
// assemble the list of fields to involve (that is, the ControlSources of all fields that have such a property)
OUString strFieldList, sFieldDisplayNames;
m_arrSearchedControls.clear();
m_arrRelativeGridColumn.clear();
// small problem: To mark found fields, I need SdrObjects. To determine which controls // to include in the search, I need Controls (that is, XControl interfaces). So I have // to iterate over one of them and get the other in some way. Unfortunately, there is // no direct connection between the two worlds (except from a GetUnoControl to a // SdrUnoObject, but this requires an OutputDevice I can not do anything with. // However I can get to the Model from the Control and also from the SdrObject, and in // this way the assignment SdrObject<->Control is possible with a double loop. // The alternative to this (ugly but certainly not entirely fixable) solution would be // to renounce the caching of the SdrObjects, which would lead to significant extra // work in OnFoundData (since there I'd have to get the SdrObject first thing every // time). But since OnFoundData is usually called more often than ExecuteSearch, I'll // do that here.
Reference< XNameAccess> xValidFormFields;
Reference< XColumnsSupplier> xSupplyCols(xIter, UNO_QUERY);
DBG_ASSERT(xSupplyCols.is(), "FmXFormShell::OnSearchContextRequest : invalid cursor : no columns supplier !"); if (xSupplyCols.is())
xValidFormFields = xSupplyCols->getColumns();
DBG_ASSERT(xValidFormFields.is(), "FmXFormShell::OnSearchContextRequest : form has no fields !");
// current Page/Controller
FmFormPage* pCurrentPage = m_pShell->GetCurPage();
assert(pCurrentPage && "FmXFormShell::OnSearchContextRequest : no page !"); // Search all SdrControls of this page...
OUString sControlSource, aName;
SdrObjListIter aPageIter( pCurrentPage ); while ( aPageIter.IsMore() )
{
SdrObject* pCurrent = aPageIter.Next();
FmFormObj* pFormObject = FmFormObj::GetFormObject( pCurrent ); // note that in case pCurrent is a virtual object, pFormObject points to the referenced object
if ( !pFormObject ) 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;
// does the component belong to the form which we're interested in? if ( xCurrentFormComponent->getParent() != xForm ) continue;
// ... ask for the ControlSource property
SearchableControlIterator iter( xCurrentFormComponent );
Reference< XControl> xControl; // the control that has model xControlModel // (the following while can be passed through several times, without the Control // being modified, so I don't have to search every time from scratch)
Reference< XInterface > xSearchable( iter.Next() ); while ( xSearchable.is() )
{
sControlSource = iter.getCurrentValue(); if ( sControlSource.isEmpty() )
{ // the current element has no ControlSource, so it is a GridControl (that // is the only thing that still permits the SearchableControlIteratore)
xControl = impl_getControl_Lock(xControlModel, *pFormObject);
DBG_ASSERT(xControl.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
Reference< XGridPeer> xGridPeer; if ( xControl.is() )
xGridPeer.set( xControl->getPeer(), UNO_QUERY ); do
{ if (!xGridPeer.is()) break;
Reference< XIndexAccess> xPeerContainer(xGridPeer, UNO_QUERY); if (!xPeerContainer.is()) break;
Reference< XIndexAccess> xModelColumns = xGridPeer->getColumns();
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< XInterface> xCurrentColumn; for (sal_Int32 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos)
{
xPeerContainer->getByIndex(nViewPos) >>= xCurrentColumn; if (!xCurrentColumn.is()) continue;
// can we use this column control for searching ? if (!IsSearchableControl(xCurrentColumn)) continue;
sal_Int32 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 + ";";
// and the SdrOject to the Field
m_arrSearchedControls.push_back(pCurrent); // the number of the column
m_arrRelativeGridColumn.push_back(nViewPos);
}
}
} while (false);
} else
{ if (!sControlSource.isEmpty() && xValidFormFields->hasByName(sControlSource))
{ // now I need the Control to SdrObject if (!xControl.is())
{
xControl = impl_getControl_Lock(xControlModel, *pFormObject);
DBG_ASSERT(xControl.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
}
if (IsSearchableControl(xControl))
{ // all tests passed -> take along in the list
strFieldList += sControlSource + ";";
// the label which should appear for the control :
sFieldDisplayNames +=
getLabelName(Reference< XPropertySet>(xControlModel, UNO_QUERY)) + ";";
// mark the SdrObject (accelerates the treatment in OnFoundData)
m_arrSearchedControls.push_back(pCurrent);
// the number of the column (here a dummy, since it is only interesting for GridControls)
m_arrRelativeGridColumn.push_back(-1);
// and for the formatted search...
rfmscContextInfo.arrFields.emplace_back( xControl, UNO_QUERY );
}
}
}
// 66463 - 31.05.99 - FS // when the cursor is a non-STANDARD RecordMode, set it back
Reference< XPropertySet> xCursorSet(rfmscContextInfo.xCursor, UNO_QUERY);
Reference< XResultSetUpdate> xUpdateCursor(rfmscContextInfo.xCursor, UNO_QUERY); if (xUpdateCursor.is() && xCursorSet.is())
{ if (::comphelper::getBOOL(xCursorSet->getPropertyValue(FM_PROP_ISNEW)))
xUpdateCursor->moveToCurrentRow(); elseif (::comphelper::getBOOL(xCursorSet->getPropertyValue(FM_PROP_ISMODIFIED)))
xUpdateCursor->cancelRowUpdates();
}
Reference< XSelectionSupplier > xSupplier( rEvent.Source, UNO_QUERY );
Reference< XInterface > xSelObj( xSupplier->getSelection(), UNO_QUERY ); // a selection was removed, this can only be done by the shell if ( !xSelObj.is() ) return;
void FmXFormShell::SetDesignMode_Lock(bool bDesign)
{ if (impl_checkDisposed_Lock()) return;
DBG_ASSERT(m_pShell->GetFormView(), "FmXFormShell::SetDesignMode : invalid call (have no shell or no view) !");
m_bChangingDesignMode = true;
// 67506 - 15.07.99 - FS // if we're switching off the design mode we have to force the property browser to be closed // so it can commit it's changes _before_ we load the forms if (!bDesign)
{
m_bHadPropertyBrowserInDesignMode = m_pShell->GetViewShell()->GetViewFrame().HasChildWindow(SID_FM_SHOW_PROPERTIES); if (m_bHadPropertyBrowserInDesignMode)
m_pShell->GetViewShell()->GetViewFrame().ToggleChildWindow(SID_FM_SHOW_PROPERTIES);
}
FmFormView* pFormView = m_pShell->GetFormView(); if (bDesign)
{ // we are currently filtering, so stop filtering if (m_bFilterMode)
stopFiltering_Lock(false);
// unsubscribe from the objects of my MarkList
pFormView->GetImpl()->stopMarkListWatching();
} else
{
m_aMarkTimer.Stop();
if (bDesign)
{
SdrMarkList aList;
{ // during changing the mark list, don't track the selected objects in the property browser
SuspendPropertyTracking aSuspend( *this ); // restore the marks
pFormView->GetImpl()->restoreMarkList( aList );
}
// synchronize with the restored mark list if ( aList.GetMarkCount() )
SetSelection_Lock(aList);
} else
{ // subscribe to the model of the view (so that I'm informed when someone deletes // during the alive mode controls that I had saved in the saveMarklist (60343)
pFormView->GetImpl()->startMarkListWatching();
}
m_pShell->UIFeatureChanged();
// 67506 - 15.07.99 - FS if (bDesign && m_bHadPropertyBrowserInDesignMode)
{ // The UIFeatureChanged performs an update (a check of the available features) asynchronously. // So we can't call ShowSelectionProperties directly as the according feature isn't enabled yet. // That's why we use an asynchron execution on the dispatcher. // (And that's why this has to be done AFTER the UIFeatureChanged.)
m_pShell->GetViewShell()->GetViewFrame().GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SfxCallMode::ASYNCHRON );
}
m_bChangingDesignMode = false;
}
const Sequence< Reference< XControl > > seqControls( xControlContainer->getControls() ); // ... that I can then search for (Reference< XControl > const & control : seqControls)
{
xControl.set( control, UNO_SET_THROW );
Reference< XControlModel > xCurrentModel( xControl->getModel() ); if ( xCurrentModel == i_rxModel ) break;
xControl.clear();
}
if ( !xControl.is() )
{ // fallback (some controls might not have been created, yet, since they were never visible so far)
Reference< XControl > xContainerControl( xControlContainer, UNO_QUERY_THROW ); const vcl::Window* pContainerWindow = VCLUnoHelper::GetWindow( xContainerControl->getPeer() );
ENSURE_OR_THROW( pContainerWindow, "unexpected control container implementation" );
const SdrView* pSdrView = m_pShell ? m_pShell->GetFormView() : nullptr;
ENSURE_OR_THROW( pSdrView, "no current view" );
// the name of the current form
OUString sCompleteCurrentName( sCurrentFormName ); if ( !_rCurrentLevelPrefix.empty() )
{
sCompleteCurrentName += OUString::Concat(" (") + _rCurrentLevelPrefix + ")";
}
// the prefix for the next level
aNextLevelPrefix = _rCurrentLevelPrefix; if ( !_rCurrentLevelPrefix.empty() )
aNextLevelPrefix.append( '/' );
aNextLevelPrefix.append( sCurrentFormName );
// remember both the form and its "display name"
_out_rForms.push_back( xCurrentAsForm );
_out_rNames.push_back( sCompleteCurrentName );
void FmXFormShell::startFiltering_Lock()
{ if (impl_checkDisposed_Lock()) return;
// setting all forms in filter mode
FmXFormView* pXView = m_pShell->GetFormView()->GetImpl();
// if the active controller is our external one we have to use the trigger controller
Reference< XControlContainer> xContainer; if (getActiveController_Lock() == m_xExternalViewController)
{
DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::startFiltering : inconsistent : active external controller, but no one triggered this !");
xContainer = m_xExtViewTriggerController->getContainer();
} else
xContainer = getActiveController_Lock()->getContainer();
// if the active controller is our external one we have to use the trigger controller
Reference< XControlContainer> xContainer; if (getActiveController_Lock() == m_xExternalViewController)
{
DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::stopFiltering : inconsistent : active external controller, but no one triggered this !");
xContainer = m_xExtViewTriggerController->getContainer();
} else
xContainer = getActiveController_Lock()->getContainer();
if (bSave)
{ for (constauto& rpController : rControllerList)
{ // remember the current filter settings in case we're going to reload the forms below (which may fail) try
{
Reference< XPropertySet > xFormAsSet(rpController->getModel(), UNO_QUERY);
aOriginalFilters.push_back(::comphelper::getString(xFormAsSet->getPropertyValue(FM_PROP_FILTER)));
aOriginalApplyFlags.push_back(::comphelper::getBOOL(xFormAsSet->getPropertyValue(FM_PROP_APPLYFILTER)));
} catch(Exception&)
{
OSL_FAIL("FmXFormShell::stopFiltering : could not get the original filter !"); // put dummies into the arrays so the they have the right size
if (aOriginalFilters.size() == aOriginalApplyFlags.size()) // the first getPropertyValue failed -> use two dummies
aOriginalFilters.emplace_back( );
aOriginalApplyFlags.push_back( false );
}
saveFilter(rpController);
}
} for (constauto& rController : rControllerList)
{
void FmXFormShell::CreateExternalView_Lock()
{ if (impl_checkDisposed_Lock()) return;
DBG_ASSERT(m_xAttachedFrame.is(), "FmXFormShell::CreateExternalView : no frame !");
// the frame the external view is displayed in bool bAlreadyExistent = m_xExternalViewController.is();
Reference< css::frame::XFrame> xExternalViewFrame;
Reference<runtime::XFormController> xCurrentNavController(getNavController_Lock()); // the creation of the "partwindow" may cause a deactivate of the document which will result in our nav controller to be set to NULL
// _first_ check if we have any valid fields we can use for the grid view // FS - 21.10.99 - 69219
{
FmXBoundFormFieldIterator aModelIterator(xCurrentNavController->getModel()); bool bHaveUsableControls = false; for (;;)
{
Reference< XPropertySet> xCurrentModelSet(aModelIterator.Next(), UNO_QUERY); if (!xCurrentModelSet.is()) break; // the FmXBoundFormFieldIterator only supplies controls with a valid control source // so we just have to check the field type
sal_Int16 nClassId = ::comphelper::getINT16(xCurrentModelSet->getPropertyValue(FM_PROP_CLASSID)); switch (nClassId)
{ case FormComponentType::IMAGECONTROL: case FormComponentType::CONTROL: continue;
}
bHaveUsableControls = true; break;
}
// load the component for external form views if (!bAlreadyExistent)
{
OUString sFrameName(u"_beamer"_ustr);
URL aWantToDispatch;
aWantToDispatch.Complete = FMURL_COMPONENT_FORMGRIDVIEW;
// with this the component should be loaded, now search the frame where it resides in
xExternalViewFrame = m_xAttachedFrame->findFrame(sFrameName, css::frame::FrameSearchFlag::CHILDREN); if (xExternalViewFrame.is())
{
m_xExternalViewController = xExternalViewFrame->getController(); if (m_xExternalViewController.is())
m_xExternalViewController->addEventListener(static_cast<XEventListener*>(static_cast<XPropertyChangeListener*>(this)));
}
} else
{
xExternalViewFrame = m_xExternalViewController->getFrame();
Reference< css::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
// if we display the active form we interpret the slot as "remove it"
Reference< XForm> xCurrentModel(xCurrentNavController->getModel(), UNO_QUERY); if ((xCurrentModel == m_xExternalDisplayedForm) || (getInternalForm_Lock(xCurrentModel) == m_xExternalDisplayedForm))
{ if (m_xExternalViewController == getActiveController_Lock())
{
Reference< runtime::XFormController > xAsFormController( m_xExternalViewController, UNO_QUERY );
ControllerFeatures aHelper( xAsFormController );
(void)aHelper->commitCurrentControl();
}
// TODO: We need an interceptor at the xSupplier, which forwards all queryDispatch requests to the FormController // instance for which this "external view" was triggered
// get the dispatch interface of the frame so we can communicate (interceptable) with the controller
Reference< css::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
if (m_xExternalViewController.is())
{
DBG_ASSERT(xCommLink.is(), "FmXFormShell::CreateExternalView : the component doesn't have the necessary interfaces !"); // collect the dispatchers we will need
URL aAddColumnURL;
aAddColumnURL.Complete = FMURL_GRIDVIEW_ADDCOLUMN;
Reference< css::frame::XDispatch> xAddColumnDispatch( xCommLink->queryDispatch(aAddColumnURL, OUString(), 0));
URL aAttachURL;
aAttachURL.Complete = FMURL_GRIDVIEW_ATTACHTOFORM;
Reference< css::frame::XDispatch> xAttachDispatch( xCommLink->queryDispatch(aAttachURL, OUString(), 0));
if (xAddColumnDispatch.is() && xAttachDispatch.is())
{
DBG_ASSERT(xCurrentNavController.is(), "FmXFormShell::CreateExternalView : invalid call : have no nav controller !"); // first : dispatch the descriptions for the columns to add
sal_Int16 nAddedColumns = 0;
// for radio buttons we need some special structures typedef std::map< OUString, Sequence< OUString> > MapUString2UstringSeq; typedef std::map< OUString, OUString > FmMapUString2UString; typedef std::map< OUString, sal_Int16 > FmMapUString2Int16;
FmXBoundFormFieldIterator aModelIterator(xCurrentNavController->getModel());
OUString sColumnType,aGroupName,sControlSource;
Sequence< Property> aProps; for (;;)
{
Reference< XPropertySet> xCurrentModelSet(aModelIterator.Next(), UNO_QUERY); if (!xCurrentModelSet.is()) break;
OSL_ENSURE(xCurrentModelSet.is(),"xCurrentModelSet is null!"); // create a description of the column to be created // first : determine it's type
sal_Int16 nClassId = ::comphelper::getINT16(xCurrentModelSet->getPropertyValue(FM_PROP_CLASSID)); switch (nClassId)
{ case FormComponentType::RADIOBUTTON:
{ // get the label of the button (this is the access key for our structures)
aGroupName = getLabelName(xCurrentModelSet);
// add the reference value of the radio button to the list source sequence
Sequence< OUString>& aThisGroupLabels = aRadioListSources[aGroupName];
sal_Int32 nNewSizeL = aThisGroupLabels.getLength() + 1;
aThisGroupLabels.realloc(nNewSizeL);
aThisGroupLabels.getArray()[nNewSizeL - 1] = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_REFVALUE));
// add the label to the value list sequence
Sequence< OUString>& aThisGroupControlSources = aRadioValueLists[aGroupName];
sal_Int32 nNewSizeC = aThisGroupControlSources.getLength() + 1;
aThisGroupControlSources.realloc(nNewSizeC);
aThisGroupControlSources.getArray()[nNewSizeC - 1] = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_LABEL));
// remember the controls source of the radio group
sControlSource = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_CONTROLSOURCE)); if (aRadioControlSources.find(aGroupName) == aRadioControlSources.end())
aRadioControlSources[aGroupName] = sControlSource; #ifdef DBG_UTIL else
DBG_ASSERT(aRadioControlSources[aGroupName] == sControlSource, "FmXFormShell::CreateExternalView : inconsistent radio buttons detected !"); // (radio buttons with the same name should have the same control source) #endif // remember the position within the columns if (aRadioPositions.find(aGroupName) == aRadioPositions.end())
aRadioPositions[aGroupName] = nAddedColumns;
// any further handling is done below
} continue;
case FormComponentType::IMAGECONTROL: case FormComponentType::CONTROL: // no grid columns for these types (though they have a control source) continue; case FormComponentType::CHECKBOX:
sColumnType = FM_COL_CHECKBOX; break; case FormComponentType::LISTBOX:
sColumnType = FM_COL_LISTBOX; break; case FormComponentType::COMBOBOX:
sColumnType = FM_COL_COMBOBOX; break; case FormComponentType::DATEFIELD:
sColumnType = FM_COL_DATEFIELD; break; case FormComponentType::TIMEFIELD:
sColumnType = FM_COL_TIMEFIELD; break; case FormComponentType::NUMERICFIELD:
sColumnType = FM_COL_NUMERICFIELD; break; case FormComponentType::CURRENCYFIELD:
sColumnType = FM_COL_CURRENCYFIELD; break; case FormComponentType::PATTERNFIELD:
sColumnType = FM_COL_PATTERNFIELD; break;
case FormComponentType::TEXTFIELD:
{
sColumnType = FM_COL_TEXTFIELD; // we know at least two different controls which are TextFields : the basic edit field and the formatted // field. we distinguish them by their service name
Reference< lang::XServiceInfo> xInfo(xCurrentModelSet, UNO_QUERY); if (xInfo.is())
{
SdrObjKind nObjectType = getControlTypeByObject(xInfo); if (SdrObjKind::FormFormattedField == nObjectType)
sColumnType = FM_COL_FORMATTEDFIELD;
}
} break; default:
sColumnType = FM_COL_TEXTFIELD; break;
}
// properties describing "meta data" about the column // the type
pDispatchArgs->Name = FMARG_ADDCOL_COLUMNTYPE;
pDispatchArgs->Value <<= sColumnType;
++pDispatchArgs;
// the pos : append the col
pDispatchArgs->Name = FMARG_ADDCOL_COLUMNPOS;
pDispatchArgs->Value <<= nAddedColumns;
++pDispatchArgs;
// the properties to forward to the new column
Sequence< PropertyValue> aColumnProps(1);
PropertyValue* pColumnProps = aColumnProps.getArray();
// the label
pColumnProps->Name = FM_PROP_LABEL;
pColumnProps->Value <<= getLabelName(xCurrentModelSet);
++pColumnProps;
// for all other props : transfer them
Reference< XPropertySetInfo> xControlModelInfo( xCurrentModelSet->getPropertySetInfo());
DBG_ASSERT(xControlModelInfo.is(), "FmXFormShell::CreateExternalView : the control model has no property info ! This will crash !");
aProps = xControlModelInfo->getProperties();
// realloc the control description sequence
sal_Int32 nExistentDescs = pColumnProps - aColumnProps.getArray();
aColumnProps.realloc(nExistentDescs + aProps.getLength());
pColumnProps = aColumnProps.getArray() + nExistentDescs;
for (const Property& rProp : aProps)
{ if (rProp.Name == FM_PROP_LABEL) // already set continue; if (rProp.Name == FM_PROP_DEFAULTCONTROL) // allow the column's own "default control" continue; if (rProp.Attributes & PropertyAttribute::READONLY) // assume that properties which are readonly for the control are ro for the column to be created, too continue;
// the
pDispatchArgs->Name = "ColumnProperties"; // TODO : fmurl.*
pDispatchArgs->Value <<= aListBoxDescription;
++pDispatchArgs;
DBG_ASSERT(nDispatchArgs == (pDispatchArgs - aDispatchArgs.getConstArray()), "FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
// dispatch the "add column"
xAddColumnDispatch->dispatch(aAddColumnURL, aDispatchArgs);
++nAddedColumns;
++nOffset;
}
DBG_ASSERT(nAddedColumns > 0, "FmXFormShell::CreateExternalView : no controls (inconsistent) !"); // we should have checked if we have any usable controls (see above).
// "load" the "form" of the external view
PropertyValue aArg;
aArg.Name = FMARG_ATTACHTO_MASTERFORM;
Reference< XResultSet> xForm(xCurrentNavController->getModel(), UNO_QUERY);
aArg.Value <<= xForm;
m_xExternalDisplayedForm = std::move(xForm); // do this before dispatching the "attach" command, as the attach may result in a call to our queryDispatch (for the FormSlots) // which needs the m_xExternalDisplayedForm
// we want to know modifications done in the external view // if the external controller is a XFormController we can use all our default handlings for it
Reference< runtime::XFormController > xFormController( m_xExternalViewController, UNO_QUERY );
OSL_ENSURE( xFormController.is(), "FmXFormShell::CreateExternalView:: invalid external view controller!" ); if (xFormController.is())
xFormController->addActivateListener(static_cast<XFormControllerListener*>(this));
}
} #ifdef DBG_UTIL else
{
OSL_FAIL("FmXFormShell::CreateExternalView : could not create the external form view !");
} #endif
InvalidateSlot_Lock(SID_FM_VIEW_AS_GRID, false);
}
void FmXFormShell::implAdjustConfigCache_Lock()
{ constbool bFuzzing(comphelper::IsFuzzing()); if (bFuzzing) return;
// get (cache) the wizard usage flag
Sequence< OUString > aNames { u"FormControlPilotsEnabled"_ustr };
Sequence< Any > aFlags = GetProperties(aNames); if (1 == aFlags.getLength())
m_bUseWizards = ::cppu::any2bool(aFlags[0]);
}
// if we have an async load operation pending for the 0-th page for this view, // we need to cancel this if (FmFormPage* pPage = _rCurrentView.GetCurPage())
{ // move all events from our queue to a new one, omit the events for the deactivated // page
::std::queue< FmLoadAction > aNewEvents; while ( !m_aLoadingPages.empty() )
{
FmLoadAction aAction = m_aLoadingPages.front();
m_aLoadingPages.pop(); if ( pPage != aAction.pPage )
{
aNewEvents.push( aAction );
} else
{
Application::RemoveUserEvent( aAction.nEventId );
}
}
m_aLoadingPages = std::move(aNewEvents);
// remove callbacks at the page
pPage->GetImpl().SetFormsCreationHdl( Link<FmFormPageImpl&,void>() );
}
UpdateForms_Lock(true);
}
IMPL_LINK_NOARG( FmXFormShell, OnFirstTimeActivation_Lock, void*, void )
{ if (impl_checkDisposed_Lock()) return;
if ( pDocument && !pDocument->HasName() )
{ if (isEnhancedForm_Lock())
{ // show the data navigator if ( !m_pShell->GetViewShell()->GetViewFrame().HasChildWindow( SID_FM_SHOW_DATANAVIGATOR ) )
m_pShell->GetViewShell()->GetViewFrame().ToggleChildWindow( SID_FM_SHOW_DATANAVIGATOR );
}
}
}
// activate our view if we are activated ourself // FS - 30.06.99 - 67308 if ( _rCurrentView.GetImpl() && !_rCurrentView.IsDesignMode() )
{ // load forms for the page the current view belongs to if ( pPage )
{ if ( !pPage->GetImpl().hasEverBeenActivated() )
loadForms_Lock(pPage, LoadFormsFlags::Load
| (_bSyncAction ? LoadFormsFlags::Sync
: LoadFormsFlags::Async));
pPage->GetImpl().setHasBeenActivated( );
}
// first-time initializations for the views if ( !_rCurrentView.GetImpl()->hasEverBeenActivated( ) )
{ auto* pFormModel = dynamic_cast<FmFormModel*>(&_rCurrentView.GetModel());
_rCurrentView.GetImpl()->onFirstViewActivation(pFormModel);
_rCurrentView.GetImpl()->setHasBeenActivated();
}
// activate the current view
_rCurrentView.GetImpl()->Activate( _bSyncAction );
}
// set callbacks at the page if ( pPage )
{
pPage->GetImpl().SetFormsCreationHdl(LINK(this, FmXFormShell, OnFormsCreated_Lock));
}
for (sal_Int32 i=0; i<nCount; ++i)
{
_rxModels->getByIndex(i) >>= xCurrent; if (xCurrent.is())
xCurrentInfo = xCurrent->getPropertySetInfo(); else
xCurrentInfo.clear(); if (!xCurrentInfo.is()) continue;
if (xCurrentInfo->hasPropertyByName(FM_PROP_CLASSID))
{ // it's a control model
// check if this control is bound to a living database field if (xCurrentInfo->hasPropertyByName(FM_PROP_BOUNDFIELD))
xCurrent->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xBoundField; else
xBoundField.clear();
// reset only if it's *not* bound bool bReset = !xBoundField.is();
// and additionally, check if it has an external value binding
Reference< XBindableValue > xBindable( xCurrent, UNO_QUERY ); if ( xBindable.is() && xBindable->getValueBinding().is() )
bReset = false;
namespace
{ bool lcl_isLoadable( const Reference< XInterface >& _rxLoadable )
{ // determines whether a form should be loaded or not // if there is no datasource or connection there is no reason to load a form
Reference< XPropertySet > xSet( _rxLoadable, UNO_QUERY ); if ( !xSet.is() ) returnfalse; try
{
Reference< XConnection > xConn; if ( isEmbeddedInDatabase( _rxLoadable, xConn ) ) returntrue;
// is there already an active connection
xSet->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xConn; if ( xConn.is() ) returntrue;
// lock the undo env so the forms can change non-transient properties while loading // (without this my doc's modified flag would be set)
FmFormModel& rFmFormModel(dynamic_cast< FmFormModel& >(_pPage->getSdrModelFromSdrPage()));
rFmFormModel.GetUndoEnv().Lock();
// load all forms
Reference< XIndexAccess > xForms = _pPage->GetForms( false );
if ( xForms.is() )
{
Reference< XLoadable > xForm; for ( sal_Int32 j = 0, nCount = xForms->getCount(); j < nCount; ++j )
{
xForms->getByIndex( j ) >>= xForm; bool bFormWasLoaded = false; // a database form must be loaded for try
{ if ( !( _nBehaviour & LoadFormsFlags::Unload ) )
{ if ( lcl_isLoadable( xForm ) && !xForm->isLoaded() )
xForm->load();
} else
{ if ( xForm->isLoaded() )
{
bFormWasLoaded = true;
xForm->unload();
}
}
} catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("svx");
}
// reset the form if it was loaded if ( bFormWasLoaded )
{
Reference< XIndexAccess > xContainer( xForm, UNO_QUERY );
DBG_ASSERT( xContainer.is(), "FmXFormShell::loadForms: the form is no container!" ); if ( xContainer.is() )
smartControlReset( xContainer );
}
}
}
// unlock the environment
rFmFormModel.GetUndoEnv().UnLock();
}
bool SearchableControlIterator::ShouldHandleElement(const Reference< XInterface>& xElement)
{ // if the thing has a ControlSource and a BoundField property
Reference< XPropertySet> xProperties(xElement, UNO_QUERY); if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xProperties) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xProperties))
{ // and the BoundField is valid
Reference< XPropertySet> xField;
xProperties->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField; if (xField.is())
{ // we take it
m_sCurrentValue = ::comphelper::getString(xProperties->getPropertyValue(FM_PROP_CONTROLSOURCE)); returntrue;
}
}
// if it is a grid control if (::comphelper::hasProperty(FM_PROP_CLASSID, xProperties))
{
Any aClassId( xProperties->getPropertyValue(FM_PROP_CLASSID) ); if (::comphelper::getINT16(aClassId) == FormComponentType::GRIDCONTROL)
{
m_sCurrentValue.clear(); returntrue;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.