1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/macros.h>
22 #include "fmitems.hxx"
24 #include "fmpgeimp.hxx"
25 #include "svx/fmtools.hxx"
27 #include "svx/fmresids.hrc"
28 #include "fmservs.hxx"
29 #include "fmshimp.hxx"
30 #include "fmtextcontrolshell.hxx"
33 #include "fmvwimp.hxx"
34 #include "formtoolbars.hxx"
35 #include "gridcols.hxx"
36 #include "svx/svditer.hxx"
37 #include "svx/dialmgr.hxx"
38 #include "svx/dialogs.hrc"
39 #include "svx/fmglob.hxx"
40 #include "svx/fmmodel.hxx"
41 #include "svx/fmpage.hxx"
42 #include "svx/fmshell.hxx"
43 #include "svx/obj3d.hxx"
44 #include "svx/sdrpagewindow.hxx"
45 #include "svx/svdpagv.hxx"
46 #include "svx/svxdlg.hxx"
47 #include "svx/svxids.hrc"
49 #include <com/sun/star/awt/XWindow2.hpp>
50 #include <com/sun/star/awt/XCheckBox.hpp>
51 #include <com/sun/star/awt/XListBox.hpp>
52 #include <com/sun/star/awt/XTextComponent.hpp>
53 #include <com/sun/star/beans/Introspection.hpp>
54 #include <com/sun/star/beans/NamedValue.hpp>
55 #include <com/sun/star/beans/PropertyAttribute.hpp>
56 #include <com/sun/star/beans/XPropertyState.hpp>
57 #include <com/sun/star/container/XContainer.hpp>
58 #include <com/sun/star/container/XEnumeration.hpp>
59 #include <com/sun/star/container/XEnumerationAccess.hpp>
60 #include <com/sun/star/container/XIndexAccess.hpp>
61 #include <com/sun/star/container/XNamed.hpp>
62 #include <com/sun/star/form/ListSourceType.hpp>
63 #include <com/sun/star/form/XBoundComponent.hpp>
64 #include <com/sun/star/form/XBoundControl.hpp>
65 #include <com/sun/star/form/XGrid.hpp>
66 #include <com/sun/star/form/XGridPeer.hpp>
67 #include <com/sun/star/form/XLoadable.hpp>
68 #include <com/sun/star/form/XReset.hpp>
69 #include <com/sun/star/form/binding/XBindableValue.hpp>
70 #include <com/sun/star/form/binding/XListEntrySink.hpp>
71 #include <com/sun/star/frame/FrameSearchFlag.hpp>
72 #include <com/sun/star/script/XEventAttacherManager.hpp>
73 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
74 #include <com/sun/star/util/XCancellable.hpp>
75 #include <com/sun/star/util/XModeSelector.hpp>
76 #include <com/sun/star/util/XModifyBroadcaster.hpp>
77 #include <com/sun/star/util/XNumberFormatter.hpp>
78 #include <com/sun/star/view/XSelectionSupplier.hpp>
80 #include <comphelper/extract.hxx>
81 #include <comphelper/evtmethodhelper.hxx>
82 #include <comphelper/processfactory.hxx>
83 #include <comphelper/property.hxx>
84 #include <comphelper/solarmutex.hxx>
85 #include <comphelper/string.hxx>
86 #include <connectivity/dbtools.hxx>
87 #include <rtl/logfile.hxx>
88 #include <sfx2/dispatch.hxx>
89 #include <sfx2/docfile.hxx>
90 #include <sfx2/frame.hxx>
91 #include <sfx2/objsh.hxx>
92 #include <sfx2/viewfrm.hxx>
93 #include <sfx2/viewsh.hxx>
94 #include <toolkit/helper/vclunohelper.hxx>
95 #include <tools/diagnose_ex.h>
96 #include <tools/shl.hxx>
97 #include <vcl/msgbox.hxx>
98 #include <vcl/waitobj.hxx>
101 #include <functional>
105 // wird fuer Invalidate verwendet -> mitpflegen
106 static sal_uInt16 DatabaseSlotMap
[] =
113 SID_FM_RECORD_DELETE
,
114 SID_FM_RECORD_ABSOLUTE
,
118 SID_FM_REMOVE_FILTER_SORT
,
123 SID_FM_FORM_FILTERED
,
125 SID_FM_REFRESH_FORM_CONTROL
,
132 // wird fuer Invalidate verwendet -> mitpflegen
133 // aufsteigend sortieren !!!!!!
134 static sal_Int16 DlgSlotMap
[] = // slots des Controllers
136 SID_FM_CTL_PROPERTIES
,
140 SID_FM_SHOW_FMEXPLORER
,
141 SID_FM_FIELDS_CONTROL
,
142 SID_FM_SHOW_PROPERTIES
,
143 SID_FM_PROPERTY_CONTROL
,
144 SID_FM_FMEXPLORER_CONTROL
,
145 SID_FM_SHOW_DATANAVIGATOR
,
146 SID_FM_DATANAVIGATOR_CONTROL
,
150 static sal_Int16 SelObjectSlotMap
[] = // vom SelObject abhaengige Slots
152 SID_FM_CONVERTTO_EDIT
,
153 SID_FM_CONVERTTO_BUTTON
,
154 SID_FM_CONVERTTO_FIXEDTEXT
,
155 SID_FM_CONVERTTO_LISTBOX
,
156 SID_FM_CONVERTTO_CHECKBOX
,
157 SID_FM_CONVERTTO_RADIOBUTTON
,
158 SID_FM_CONVERTTO_GROUPBOX
,
159 SID_FM_CONVERTTO_COMBOBOX
,
160 SID_FM_CONVERTTO_IMAGEBUTTON
,
161 SID_FM_CONVERTTO_FILECONTROL
,
162 SID_FM_CONVERTTO_DATE
,
163 SID_FM_CONVERTTO_TIME
,
164 SID_FM_CONVERTTO_NUMERIC
,
165 SID_FM_CONVERTTO_CURRENCY
,
166 SID_FM_CONVERTTO_PATTERN
,
167 SID_FM_CONVERTTO_IMAGECONTROL
,
168 SID_FM_CONVERTTO_FORMATTED
,
169 SID_FM_CONVERTTO_SCROLLBAR
,
170 SID_FM_CONVERTTO_SPINBUTTON
,
171 SID_FM_CONVERTTO_NAVIGATIONBAR
,
173 SID_FM_FMEXPLORER_CONTROL
,
174 SID_FM_DATANAVIGATOR_CONTROL
,
179 // die folgenden Arrays muessen kosistent sein, also einander entsprechende Eintraege an der selben relativen Position
180 // innerhalb ihres jeweiligen Arrays stehen
181 static sal_Int16 nConvertSlots
[] =
183 SID_FM_CONVERTTO_EDIT
,
184 SID_FM_CONVERTTO_BUTTON
,
185 SID_FM_CONVERTTO_FIXEDTEXT
,
186 SID_FM_CONVERTTO_LISTBOX
,
187 SID_FM_CONVERTTO_CHECKBOX
,
188 SID_FM_CONVERTTO_RADIOBUTTON
,
189 SID_FM_CONVERTTO_GROUPBOX
,
190 SID_FM_CONVERTTO_COMBOBOX
,
191 SID_FM_CONVERTTO_IMAGEBUTTON
,
192 SID_FM_CONVERTTO_FILECONTROL
,
193 SID_FM_CONVERTTO_DATE
,
194 SID_FM_CONVERTTO_TIME
,
195 SID_FM_CONVERTTO_NUMERIC
,
196 SID_FM_CONVERTTO_CURRENCY
,
197 SID_FM_CONVERTTO_PATTERN
,
198 SID_FM_CONVERTTO_IMAGECONTROL
,
199 SID_FM_CONVERTTO_FORMATTED
,
200 SID_FM_CONVERTTO_SCROLLBAR
,
201 SID_FM_CONVERTTO_SPINBUTTON
,
202 SID_FM_CONVERTTO_NAVIGATIONBAR
205 static sal_Int16 nCreateSlots
[] =
220 SID_FM_CURRENCYFIELD
,
223 SID_FM_FORMATTEDFIELD
,
229 static sal_Int16 nObjectTypes
[] =
244 OBJ_FM_CURRENCYFIELD
,
247 OBJ_FM_FORMATTEDFIELD
,
253 using namespace ::com::sun::star
;
254 using namespace ::com::sun::star::ui
;
255 using namespace ::com::sun::star::uno
;
256 using namespace ::com::sun::star::sdb
;
257 using namespace ::com::sun::star::sdbc
;
258 using namespace ::com::sun::star::sdbcx
;
259 using namespace ::com::sun::star::beans
;
260 using namespace ::com::sun::star::container
;
261 using namespace ::com::sun::star::form
;
262 using namespace ::com::sun::star::form::binding
;
263 using namespace ::com::sun::star::form::runtime
;
264 using namespace ::com::sun::star::awt
;
265 using namespace ::com::sun::star::view
;
266 using namespace ::com::sun::star::lang
;
267 using namespace ::com::sun::star::util
;
268 using namespace ::com::sun::star::frame
;
269 using namespace ::com::sun::star::script
;
270 using namespace ::svxform
;
271 using namespace ::svx
;
273 //==============================================================================
275 //==============================================================================
278 //..........................................................................
279 void collectInterfacesFromMarkList( const SdrMarkList
& _rMarkList
, InterfaceBag
& /* [out] */ _rInterfaces
)
281 _rInterfaces
.clear();
283 sal_uInt32 nMarkCount
= _rMarkList
.GetMarkCount();
284 for ( sal_uInt32 i
= 0; i
< nMarkCount
; ++i
)
286 SdrObject
* pCurrent
= _rMarkList
.GetMark( i
)->GetMarkedSdrObj();
288 SdrObjListIter
* pGroupIterator
= NULL
;
289 if ( pCurrent
->IsGroupObject() )
291 pGroupIterator
= new SdrObjListIter( *pCurrent
->GetSubList() );
292 pCurrent
= pGroupIterator
->IsMore() ? pGroupIterator
->Next() : NULL
;
297 FmFormObj
* pAsFormObject
= FmFormObj::GetFormObject( pCurrent
);
298 // note this will de-reference virtual objects, if necessary/possible
301 Reference
< XInterface
> xControlModel( pAsFormObject
->GetUnoControlModel(), UNO_QUERY
);
302 // the UNO_QUERY is important for normalization
303 if ( xControlModel
.is() )
304 _rInterfaces
.insert( xControlModel
);
308 pCurrent
= pGroupIterator
&& pGroupIterator
->IsMore() ? pGroupIterator
->Next() : NULL
;
311 if ( pGroupIterator
)
312 delete pGroupIterator
;
316 //..........................................................................
317 sal_Int16
GridView2ModelPos(const Reference
< XIndexAccess
>& rColumns
, sal_Int16 nViewPos
)
323 // loop through all columns
325 Reference
< XPropertySet
> xCur
;
326 for (i
=0; i
<rColumns
->getCount(); ++i
)
328 rColumns
->getByIndex(i
) >>= xCur
;
329 if (!::comphelper::getBOOL(xCur
->getPropertyValue(FM_PROP_HIDDEN
)))
331 // for every visible col : if nViewPos is greater zero, decrement it, else we
332 // have found the model position
339 if (i
<rColumns
->getCount())
343 catch(const Exception
&)
345 DBG_UNHANDLED_EXCEPTION();
347 return (sal_Int16
)-1;
350 //..........................................................................
351 void TransferEventScripts(const Reference
< XControlModel
>& xModel
, const Reference
< XControl
>& xControl
,
352 const Sequence
< ScriptEventDescriptor
>& rTransferIfAvailable
)
354 // first check if we have a XEventAttacherManager for the model
355 Reference
< XChild
> xModelChild(xModel
, UNO_QUERY
);
356 if (!xModelChild
.is())
357 return; // nothing to do
359 Reference
< XEventAttacherManager
> xEventManager(xModelChild
->getParent(), UNO_QUERY
);
360 if (!xEventManager
.is())
361 return; // nothing to do
363 if (!rTransferIfAvailable
.getLength())
364 return; // nothing to do
366 // check for the index of the model within it's parent
367 Reference
< XIndexAccess
> xParentIndex(xModelChild
->getParent(), UNO_QUERY
);
368 if (!xParentIndex
.is())
369 return; // nothing to do
370 sal_Int32 nIndex
= getElementPos(xParentIndex
, xModel
);
371 if (nIndex
<0 || nIndex
>=xParentIndex
->getCount())
372 return; // nothing to do
374 // then we need information about the listeners supported by the control and the model
375 Sequence
< Type
> aModelListeners
;
376 Sequence
< Type
> aControlListeners
;
378 Reference
< XIntrospection
> xModelIntrospection
= Introspection::create(::comphelper::getProcessComponentContext());
379 Reference
< XIntrospection
> xControlIntrospection
= Introspection::create(::comphelper::getProcessComponentContext());
383 Any
aModel(makeAny(xModel
));
384 aModelListeners
= xModelIntrospection
->inspect(aModel
)->getSupportedListeners();
389 Any
aControl(makeAny(xControl
));
390 aControlListeners
= xControlIntrospection
->inspect(aControl
)->getSupportedListeners();
393 sal_Int32 nMaxNewLen
= aModelListeners
.getLength() + aControlListeners
.getLength();
395 return; // the model and the listener don't support any listeners (or we were unable to retrieve these infos)
397 Sequence
< ScriptEventDescriptor
> aTransferable(nMaxNewLen
);
398 ScriptEventDescriptor
* pTransferable
= aTransferable
.getArray();
400 const ScriptEventDescriptor
* pCurrent
= rTransferIfAvailable
.getConstArray();
402 for (i
=0; i
<rTransferIfAvailable
.getLength(); ++i
, ++pCurrent
)
404 // search the model/control idl classes for the event described by pCurrent
405 for ( Sequence
< Type
>* pCurrentArray
= &aModelListeners
;
407 pCurrentArray
= (pCurrentArray
== &aModelListeners
) ? &aControlListeners
: NULL
410 const Type
* pCurrentListeners
= pCurrentArray
->getConstArray();
411 for (j
=0; j
<pCurrentArray
->getLength(); ++j
, ++pCurrentListeners
)
413 OUString aListener
= (*pCurrentListeners
).getTypeName();
414 sal_Int32 nTokens
= comphelper::string::getTokenCount(aListener
, '.');
416 aListener
= comphelper::string::getToken(aListener
, nTokens
- 1, '.');
418 if (aListener
== pCurrent
->ListenerType
.getStr())
419 // the current ScriptEventDescriptor doesn't match the current listeners class
422 // now check the methods
423 Sequence
< OUString
> aMethodsNames
= ::comphelper::getEventMethodsForType(*pCurrentListeners
);
425 const OUString
* pMethodsNames
= aMethodsNames
.getConstArray();
426 for (k
=0; k
<aMethodsNames
.getLength(); ++k
, ++pMethodsNames
)
428 if ((*pMethodsNames
).compareTo(pCurrent
->EventMethod
) != COMPARE_EQUAL
)
429 // the current ScriptEventDescriptor doesn't match the current listeners current method
432 // we can transfer the script event : the model (control) supports it
433 *pTransferable
= *pCurrent
;
437 if (k
<aMethodsNames
.getLength())
443 sal_Int32 nRealNewLen
= pTransferable
- aTransferable
.getArray();
444 aTransferable
.realloc(nRealNewLen
);
446 xEventManager
->registerScriptEvents(nIndex
, aTransferable
);
449 //------------------------------------------------------------------------------
450 OUString
getServiceNameByControlType(sal_Int16 nType
)
454 case OBJ_FM_EDIT
: return FM_COMPONENT_TEXTFIELD
;
455 case OBJ_FM_BUTTON
: return FM_COMPONENT_COMMANDBUTTON
;
456 case OBJ_FM_FIXEDTEXT
: return FM_COMPONENT_FIXEDTEXT
;
457 case OBJ_FM_LISTBOX
: return FM_COMPONENT_LISTBOX
;
458 case OBJ_FM_CHECKBOX
: return FM_COMPONENT_CHECKBOX
;
459 case OBJ_FM_RADIOBUTTON
: return FM_COMPONENT_RADIOBUTTON
;
460 case OBJ_FM_GROUPBOX
: return FM_COMPONENT_GROUPBOX
;
461 case OBJ_FM_COMBOBOX
: return FM_COMPONENT_COMBOBOX
;
462 case OBJ_FM_GRID
: return FM_COMPONENT_GRIDCONTROL
;
463 case OBJ_FM_IMAGEBUTTON
: return FM_COMPONENT_IMAGEBUTTON
;
464 case OBJ_FM_FILECONTROL
: return FM_COMPONENT_FILECONTROL
;
465 case OBJ_FM_DATEFIELD
: return FM_COMPONENT_DATEFIELD
;
466 case OBJ_FM_TIMEFIELD
: return FM_COMPONENT_TIMEFIELD
;
467 case OBJ_FM_NUMERICFIELD
: return FM_COMPONENT_NUMERICFIELD
;
468 case OBJ_FM_CURRENCYFIELD
: return FM_COMPONENT_CURRENCYFIELD
;
469 case OBJ_FM_PATTERNFIELD
: return FM_COMPONENT_PATTERNFIELD
;
470 case OBJ_FM_HIDDEN
: return FM_COMPONENT_HIDDENCONTROL
;
471 case OBJ_FM_IMAGECONTROL
: return FM_COMPONENT_IMAGECONTROL
;
472 case OBJ_FM_FORMATTEDFIELD
: return FM_COMPONENT_FORMATTEDFIELD
;
473 case OBJ_FM_SCROLLBAR
: return FM_SUN_COMPONENT_SCROLLBAR
;
474 case OBJ_FM_SPINBUTTON
: return FM_SUN_COMPONENT_SPINBUTTON
;
475 case OBJ_FM_NAVIGATIONBAR
: return FM_SUN_COMPONENT_NAVIGATIONBAR
;
482 //------------------------------------------------------------------------------
483 // check if the control has one of the interfaces we can use for searching
484 // *_pCurrentText will be filled with the current text of the control (as used when searching this control)
485 sal_Bool
IsSearchableControl( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxControl
,
486 OUString
* _pCurrentText
)
488 if ( !_rxControl
.is() )
491 Reference
< XTextComponent
> xAsText( _rxControl
, UNO_QUERY
);
495 *_pCurrentText
= xAsText
->getText();
499 Reference
< XListBox
> xListBox( _rxControl
, UNO_QUERY
);
503 *_pCurrentText
= xListBox
->getSelectedItem();
507 Reference
< XCheckBox
> xCheckBox( _rxControl
, UNO_QUERY
);
508 if ( xCheckBox
.is() )
512 switch ( (::TriState
)xCheckBox
->getState() )
514 case STATE_NOCHECK
: *_pCurrentText
= OUString("0" ); break;
515 case STATE_CHECK
: *_pCurrentText
= OUString("1" ); break;
516 default: *_pCurrentText
= OUString(); break;
525 //------------------------------------------------------------------------------
526 sal_Bool
FmXBoundFormFieldIterator::ShouldStepInto(const Reference
< XInterface
>& _rContainer
) const
528 if (_rContainer
== m_xStartingPoint
)
529 // would be quite stupid to step over the root ....
532 return Reference
< XControlModel
>(_rContainer
, UNO_QUERY
).is();
535 //------------------------------------------------------------------------------
536 sal_Bool
FmXBoundFormFieldIterator::ShouldHandleElement(const Reference
< XInterface
>& _rElement
)
542 if (Reference
< XForm
>(_rElement
, UNO_QUERY
).is() || Reference
< XGrid
>(_rElement
, UNO_QUERY
).is())
546 Reference
< XPropertySet
> xSet(_rElement
, UNO_QUERY
);
547 if (!xSet
.is() || !::comphelper::hasProperty(FM_PROP_BOUNDFIELD
, xSet
))
548 // no "BoundField" property
551 Any
aVal( xSet
->getPropertyValue(FM_PROP_BOUNDFIELD
) );
552 if (aVal
.getValueTypeClass() != TypeClass_INTERFACE
)
553 // void or invalid property value
556 return aVal
.hasValue();
559 //------------------------------------------------------------------------------
560 sal_Bool
isControlList(const SdrMarkList
& rMarkList
)
562 // enthaelt die liste nur Controls und mindestens ein control
563 sal_uInt32 nMarkCount
= rMarkList
.GetMarkCount();
564 sal_Bool bControlList
= nMarkCount
!= 0;
566 sal_Bool bHadAnyLeafs
= sal_False
;
568 for (sal_uInt32 i
= 0; i
< nMarkCount
&& bControlList
; i
++)
570 SdrObject
*pObj
= rMarkList
.GetMark(i
)->GetMarkedSdrObj();
571 E3dObject
* pAs3DObject
= PTR_CAST(E3dObject
, pObj
);
572 // E3dObject's do not contain any 2D-objects (by definition)
573 // we need this extra check here : an E3dObject->IsGroupObject says "YES", but an SdrObjListIter working
574 // with an E3dObject doesn't give me any Nodes (E3dObject has a sub list, but no members in that list,
575 // cause there implementation differs from the one of "normal" SdrObject's. Unfortunally SdrObject::IsGroupObject
576 // doesn't check the element count of the sub list, which is simply a bug in IsGroupObject we can't fix at the moment).
577 // So at the end of this function bControlList would have the same value it was initialized with above : sal_True
578 // And this would be wrong :)
579 // 03.02.00 - 72529 - FS
582 if (pObj
->IsGroupObject())
584 SdrObjListIter
aIter(*pObj
->GetSubList());
585 while (aIter
.IsMore() && bControlList
)
587 bControlList
= FmFormInventor
== aIter
.Next()->GetObjInventor();
588 bHadAnyLeafs
= sal_True
;
593 bHadAnyLeafs
= sal_True
;
594 bControlList
= FmFormInventor
== pObj
->GetObjInventor();
599 return bControlList
&& bHadAnyLeafs
;
602 //------------------------------------------------------------------------
603 Reference
< XForm
> GetForm(const Reference
< XInterface
>& _rxElement
)
605 Reference
< XForm
> xForm( _rxElement
, UNO_QUERY
);
609 Reference
< XChild
> xChild( _rxElement
, UNO_QUERY
);
611 return GetForm( xChild
->getParent() );
613 return Reference
< XForm
>();
616 //========================================================================
617 // class FmXFormShell_Base_Disambiguation
618 //========================================================================
619 FmXFormShell_Base_Disambiguation::FmXFormShell_Base_Disambiguation( ::osl::Mutex
& _rMutex
)
620 :FmXFormShell_BD_BASE( _rMutex
)
624 void SAL_CALL
FmXFormShell_Base_Disambiguation::disposing()
626 WeakComponentImplHelperBase::disposing();
629 // Normally it should be sufficient to call the "disposing" of our direct
630 // base class, but SUN PRO 5 does not like this and claims there is a conflict
631 // with the XEventListener::disposing(EventObject) of our various listener
635 //========================================================================
636 // class FmXFormShell
637 //========================================================================
638 DBG_NAME(FmXFormShell
);
639 //------------------------------------------------------------------------
640 FmXFormShell::FmXFormShell( FmFormShell
& _rShell
, SfxViewFrame
* _pViewFrame
)
641 :FmXFormShell_BASE(m_aMutex
)
642 ,FmXFormShell_CFGBASE(OUString("Office.Common/Misc"), CONFIG_MODE_DELAYED_UPDATE
)
643 ,m_eNavigate( NavigationBarMode_NONE
)
644 ,m_nInvalidationEvent( 0 )
645 ,m_nActivationEvent( 0 )
646 ,m_pShell( &_rShell
)
647 ,m_pTextShell( new ::svx::FmTextControlShell( _pViewFrame
) )
648 ,m_aActiveControllerFeatures( this )
649 ,m_aNavControllerFeatures( this )
650 ,m_eDocumentType( eUnknownDocumentType
)
651 ,m_nLockSlotInvalidation( 0 )
652 ,m_bHadPropertyBrowserInDesignMode( sal_False
)
653 ,m_bTrackProperties( sal_True
)
654 ,m_bUseWizards( sal_True
)
655 ,m_bDatabaseBar( sal_False
)
656 ,m_bInActivate( sal_False
)
657 ,m_bSetFocus( sal_False
)
658 ,m_bFilterMode( sal_False
)
659 ,m_bChangingDesignMode( sal_False
)
660 ,m_bPreparedClose( sal_False
)
661 ,m_bFirstActivation( sal_True
)
663 DBG_CTOR(FmXFormShell
,NULL
);
664 m_aMarkTimer
.SetTimeout(100);
665 m_aMarkTimer
.SetTimeoutHdl(LINK(this,FmXFormShell
,OnTimeOut
));
668 m_xAttachedFrame
= _pViewFrame
->GetFrame().GetFrameInterface();
670 // to prevent deletion of this we acquire our refcounter once
671 ::comphelper::increment(FmXFormShell_BASE::m_refCount
);
673 // correct the refcounter
674 ::comphelper::decrement(FmXFormShell_BASE::m_refCount
);
676 // cache the current configuration settings we're interested in
677 implAdjustConfigCache();
678 // and register for changes on this settings
679 Sequence
< OUString
> aNames(1);
680 aNames
[0] = OUString("FormControlPilotsEnabled");
681 EnableNotification(aNames
);
684 //------------------------------------------------------------------------
685 FmXFormShell::~FmXFormShell()
688 DBG_DTOR(FmXFormShell
,NULL
);
691 //------------------------------------------------------------------
692 Reference
< XModel
> FmXFormShell::getContextDocument() const
694 Reference
< XModel
> xModel
;
696 // determine the type of document we live in
699 Reference
< XController
> xController
;
700 if ( m_xAttachedFrame
.is() )
701 xController
= m_xAttachedFrame
->getController();
702 if ( xController
.is() )
703 xModel
= xController
->getModel();
705 catch( const Exception
& )
707 DBG_UNHANDLED_EXCEPTION();
712 //------------------------------------------------------------------
713 bool FmXFormShell::isEnhancedForm() const
715 return getDocumentType() == eEnhancedForm
;
718 //------------------------------------------------------------------
719 bool FmXFormShell::impl_checkDisposed() const
723 OSL_FAIL( "FmXFormShell::impl_checkDisposed: already disposed!" );
729 //------------------------------------------------------------------
730 ::svxform::DocumentType
FmXFormShell::getDocumentType() const
732 if ( m_eDocumentType
!= eUnknownDocumentType
)
733 return m_eDocumentType
;
735 // determine the type of document we live in
736 Reference
< XModel
> xModel
= getContextDocument();
738 m_eDocumentType
= DocumentClassification::classifyDocument( xModel
);
741 OSL_FAIL( "FmXFormShell::getDocumentType: can't determine the document type!" );
742 m_eDocumentType
= eTextDocument
;
743 // fallback, just to have a defined state
746 return m_eDocumentType
;
749 //------------------------------------------------------------------
750 bool FmXFormShell::IsReadonlyDoc() const
752 if ( impl_checkDisposed() )
755 FmFormModel
* pModel
= m_pShell
->GetFormModel();
756 if ( pModel
&& pModel
->GetObjectShell() )
757 return pModel
->GetObjectShell()->IsReadOnly() || pModel
->GetObjectShell()->IsReadOnlyUI();
761 //------------------------------------------------------------------
762 Any SAL_CALL
FmXFormShell::queryInterface( const Type
& type
) throw ( RuntimeException
)
764 return FmXFormShell_BASE::queryInterface(type
);
766 //------------------------------------------------------------------------------
767 Sequence
< Type
> SAL_CALL
FmXFormShell::getTypes( ) throw(RuntimeException
)
769 return FmXFormShell_BASE::getTypes();
771 //------------------------------------------------------------------------------
772 Sequence
< sal_Int8
> SAL_CALL
FmXFormShell::getImplementationId() throw(RuntimeException
)
774 static ::cppu::OImplementationId
* pId
= 0;
777 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
780 static ::cppu::OImplementationId aId
;
784 return pId
->getImplementationId();
787 //------------------------------------------------------------------------------
788 void SAL_CALL
FmXFormShell::disposing(const EventObject
& e
) throw( RuntimeException
)
790 impl_checkDisposed();
792 if (m_xActiveController
== e
.Source
)
794 // wird der Controller freigeben dann alles loslassen
796 m_xActiveForm
= NULL
;
797 m_xActiveController
= NULL
;
798 m_xNavigationController
= NULL
;
800 m_aActiveControllerFeatures
.dispose();
801 m_aNavControllerFeatures
.dispose();
804 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell
);
807 if (e
.Source
== m_xExternalViewController
)
809 Reference
< runtime::XFormController
> xFormController( m_xExternalViewController
, UNO_QUERY
);
810 OSL_ENSURE( xFormController
.is(), "FmXFormShell::disposing: invalid external view controller!" );
811 if (xFormController
.is())
812 xFormController
->removeActivateListener((XFormControllerListener
*)this);
814 Reference
< ::com::sun::star::lang::XComponent
> xComp(m_xExternalViewController
, UNO_QUERY
);
816 xComp
->removeEventListener((XEventListener
*)(XPropertyChangeListener
*)this);
818 m_xExternalViewController
= NULL
;
819 m_xExternalDisplayedForm
= NULL
;
820 m_xExtViewTriggerController
= NULL
;
822 InvalidateSlot( SID_FM_VIEW_AS_GRID
, sal_False
);
826 //------------------------------------------------------------------------------
827 void SAL_CALL
FmXFormShell::propertyChange(const PropertyChangeEvent
& evt
) throw(::com::sun::star::uno::RuntimeException
)
829 if ( impl_checkDisposed() )
832 if (evt
.PropertyName
== FM_PROP_ROWCOUNT
)
834 // Das gleich folgenden Update erzwingt ein Neu-Painten der entsprechenden Slots. Wenn ich mich aber hier nicht
835 // in dem HauptThread der Applikation befinde (weil zum Beispiel ein Cursor gerade Datensaetze zaehlt und mir dabei
836 // immer diese PropertyChanges beschert), kann sich das mit en normalen Paints im HauptThread der Applikation beissen.
837 // (Solche Paints passieren zum Beispiel, wenn man einfach nur eine andere Applikation ueber das Office legt und wieder
839 // Deshalb die Benutzung des SolarMutex, der sichert das ab.
840 comphelper::SolarMutex
& rSolarSafety
= Application::GetSolarMutex();
841 if (rSolarSafety
.tryToAcquire())
843 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_RECORD_TOTAL
, sal_True
, sal_False
);
844 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().Update(SID_FM_RECORD_TOTAL
);
845 rSolarSafety
.release();
849 // with the following the slot is invalidated asynchron
850 LockSlotInvalidation(sal_True
);
851 InvalidateSlot(SID_FM_RECORD_TOTAL
, sal_False
);
852 LockSlotInvalidation(sal_False
);
856 // this may be called from a non-main-thread so invalidate the shell asynchronously
857 LockSlotInvalidation(sal_True
);
858 InvalidateSlot(0, 0); // special meaning : invalidate m_pShell
859 LockSlotInvalidation(sal_False
);
862 //------------------------------------------------------------------------------
863 void FmXFormShell::invalidateFeatures( const ::std::vector
< sal_Int32
>& _rFeatures
)
865 if ( impl_checkDisposed() )
868 OSL_ENSURE( _rFeatures
.size() > 0, "FmXFormShell::invalidateFeatures: invalid arguments!" );
870 if ( m_pShell
->GetViewShell() && m_pShell
->GetViewShell()->GetViewFrame() )
872 // unfortunately, SFX requires sal_uInt16
873 ::std::vector
< sal_uInt16
> aSlotIds
;
874 aSlotIds
.reserve( _rFeatures
.size() );
875 ::std::copy( _rFeatures
.begin(),
877 ::std::insert_iterator
< ::std::vector
< sal_uInt16
> >( aSlotIds
, aSlotIds
.begin() )
880 // furthermore, SFX wants a terminating 0
881 aSlotIds
.push_back( 0 );
883 // and, last but not least, SFX wants the ids to be sorted
884 ::std::sort( aSlotIds
.begin(), aSlotIds
.end() - 1 );
886 sal_uInt16
*pSlotIds
= &(aSlotIds
[0]);
887 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( pSlotIds
);
891 //------------------------------------------------------------------------------
892 void SAL_CALL
FmXFormShell::formActivated(const EventObject
& rEvent
) throw( RuntimeException
)
894 if ( impl_checkDisposed() )
897 Reference
< runtime::XFormController
> xController( rEvent
.Source
, UNO_QUERY_THROW
);
898 m_pTextShell
->formActivated( xController
);
899 setActiveController( xController
);
902 //------------------------------------------------------------------------------
903 void SAL_CALL
FmXFormShell::formDeactivated(const EventObject
& rEvent
) throw( RuntimeException
)
905 if ( impl_checkDisposed() )
908 Reference
< runtime::XFormController
> xController( rEvent
.Source
, UNO_QUERY_THROW
);
909 m_pTextShell
->formDeactivated( xController
);
912 //------------------------------------------------------------------------------
913 void FmXFormShell::disposing()
915 impl_checkDisposed();
917 FmXFormShell_BASE::disposing();
919 if ( m_pShell
&& !m_pShell
->IsDesignMode() )
920 setActiveController( NULL
, sal_True
);
921 // do NOT save the content of the old form (the second parameter tells this)
922 // if we're here, then we expect that PrepareClose has been called, and thus the user
923 // got a chance to commit or reject any changes. So in case we're here and there
924 // are still uncommitted changes, the user explicitly wanted this.
926 m_pTextShell
->dispose();
928 m_xAttachedFrame
= NULL
;
930 CloseExternalFormViewer();
932 while ( m_aLoadingPages
.size() )
934 Application::RemoveUserEvent( m_aLoadingPages
.front().nEventId
);
935 m_aLoadingPages
.pop();
939 ::osl::MutexGuard
aGuard(m_aInvalidationSafety
);
940 if (m_nInvalidationEvent
)
942 Application::RemoveUserEvent(m_nInvalidationEvent
);
943 m_nInvalidationEvent
= 0;
945 if ( m_nActivationEvent
)
947 Application::RemoveUserEvent( m_nActivationEvent
);
948 m_nActivationEvent
= 0;
953 ::osl::ClearableMutexGuard
aGuard(m_aAsyncSafety
);
956 DBG_ASSERT(!m_nInvalidationEvent
, "FmXFormShell::~FmXFormShell : still have an invalidation event !");
957 // should habe been deleted while beeing disposed
962 DisableNotification();
964 RemoveElement( m_xForms
);
967 impl_switchActiveControllerListening( false );
968 m_xActiveController
= NULL
;
969 m_xActiveForm
= NULL
;
972 m_xNavigationController
= NULL
;
973 m_xCurrentForm
= NULL
;
974 m_xLastGridFound
= NULL
;
975 m_xAttachedFrame
= NULL
;
976 m_xExternalViewController
= NULL
;
977 m_xExtViewTriggerController
= NULL
;
978 m_xExternalDisplayedForm
= NULL
;
979 m_xLastGridFound
= NULL
;
982 m_aCurrentSelection
.swap( aEmpty
);
984 m_aActiveControllerFeatures
.dispose();
985 m_aNavControllerFeatures
.dispose();
988 //------------------------------------------------------------------------------
989 void FmXFormShell::UpdateSlot( sal_Int16 _nId
)
991 if ( impl_checkDisposed() )
994 ::osl::MutexGuard
aGuard(m_aInvalidationSafety
);
996 if ( m_nLockSlotInvalidation
)
998 OSL_FAIL( "FmXFormShell::UpdateSlot: cannot update if invalidation is currently locked!" );
999 InvalidateSlot( _nId
, sal_False
);
1003 OSL_ENSURE( _nId
, "FmXFormShell::UpdateSlot: can't update the complete shell!" );
1004 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( _nId
, sal_True
, sal_True
);
1005 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().Update( _nId
);
1009 //------------------------------------------------------------------------------
1010 void FmXFormShell::InvalidateSlot( sal_Int16 nId
, sal_Bool bWithId
)
1012 if ( impl_checkDisposed() )
1015 ::osl::MutexGuard
aGuard(m_aInvalidationSafety
);
1016 if (m_nLockSlotInvalidation
)
1018 sal_uInt8 nFlags
= ( bWithId
? 0x01 : 0 );
1019 m_arrInvalidSlots
.push_back( InvalidSlotInfo(nId
, nFlags
) );
1023 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(nId
, sal_True
, bWithId
);
1025 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell
);
1028 //------------------------------------------------------------------------------
1029 void FmXFormShell::LockSlotInvalidation(sal_Bool bLock
)
1031 if ( impl_checkDisposed() )
1034 ::osl::MutexGuard
aGuard(m_aInvalidationSafety
);
1035 DBG_ASSERT(bLock
|| m_nLockSlotInvalidation
>0, "FmXFormShell::LockSlotInvalidation : invalid call !");
1038 ++m_nLockSlotInvalidation
;
1039 else if (!--m_nLockSlotInvalidation
)
1041 // alles, was sich waehrend der gelockten Phase angesammelt hat, (asynchron) invalidieren
1042 if (!m_nInvalidationEvent
)
1043 m_nInvalidationEvent
= Application::PostUserEvent(LINK(this, FmXFormShell
, OnInvalidateSlots
));
1047 //------------------------------------------------------------------------------
1048 IMPL_LINK_NOARG(FmXFormShell
, OnInvalidateSlots
)
1050 if ( impl_checkDisposed() )
1053 ::osl::MutexGuard
aGuard(m_aInvalidationSafety
);
1054 m_nInvalidationEvent
= 0;
1056 for (std::vector
<InvalidSlotInfo
>::const_iterator i
= m_arrInvalidSlots
.begin(); i
< m_arrInvalidSlots
.end(); ++i
)
1059 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(i
->id
, sal_True
, (i
->flags
& 0x01));
1061 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell
);
1063 m_arrInvalidSlots
.clear();
1067 //------------------------------------------------------------------------------
1068 void FmXFormShell::ForceUpdateSelection(sal_Bool bAllowInvalidation
)
1070 if ( impl_checkDisposed() )
1073 if (IsSelectionUpdatePending())
1075 m_aMarkTimer
.Stop();
1077 // die Invalidierung der Slots, die implizit von SetSelection besorgt wird, eventuell abschalten
1078 if (!bAllowInvalidation
)
1079 LockSlotInvalidation(sal_True
);
1081 SetSelection(m_pShell
->GetFormView()->GetMarkedObjectList());
1083 if (!bAllowInvalidation
)
1084 LockSlotInvalidation(sal_False
);
1088 //------------------------------------------------------------------------------
1089 PopupMenu
* FmXFormShell::GetConversionMenu()
1092 PopupMenu
* pNewMenu
= new PopupMenu(SVX_RES( RID_FMSHELL_CONVERSIONMENU
));
1094 ImageList
aImageList( SVX_RES( RID_SVXIMGLIST_FMEXPL
) );
1095 for ( size_t i
= 0; i
< sizeof (nConvertSlots
) / sizeof (nConvertSlots
[0]); ++i
)
1097 // das entsprechende Image dran
1098 pNewMenu
->SetItemImage(nConvertSlots
[i
], aImageList
.GetImage(nCreateSlots
[i
]));
1104 //------------------------------------------------------------------------------
1105 bool FmXFormShell::isControlConversionSlot( sal_uInt16 nSlotId
)
1107 for ( size_t i
= 0; i
< sizeof (nConvertSlots
) / sizeof (nConvertSlots
[0]); ++i
)
1108 if (nConvertSlots
[i
] == nSlotId
)
1113 //------------------------------------------------------------------------------
1114 bool FmXFormShell::executeControlConversionSlot( sal_uInt16 _nSlotId
)
1116 OSL_PRECOND( canConvertCurrentSelectionToControl( _nSlotId
), "FmXFormShell::executeControlConversionSlot: illegal call!" );
1117 InterfaceBag::const_iterator aSelectedElement
= m_aCurrentSelection
.begin();
1118 if ( aSelectedElement
== m_aCurrentSelection
.end() )
1121 return executeControlConversionSlot( Reference
< XFormComponent
>( *aSelectedElement
, UNO_QUERY
), _nSlotId
);
1124 //------------------------------------------------------------------------------
1125 bool FmXFormShell::executeControlConversionSlot( const Reference
< XFormComponent
>& _rxObject
, sal_uInt16 _nSlotId
)
1127 if ( impl_checkDisposed() )
1130 OSL_ENSURE( _rxObject
.is(), "FmXFormShell::executeControlConversionSlot: invalid object!" );
1131 if ( !_rxObject
.is() )
1134 SdrPage
* pPage
= m_pShell
->GetCurPage();
1135 FmFormPage
* pFormPage
= pPage
? dynamic_cast< FmFormPage
* >( pPage
) : NULL
;
1136 OSL_ENSURE( pFormPage
, "FmXFormShell::executeControlConversionSlot: no current (form) page!" );
1140 OSL_ENSURE( isSolelySelected( _rxObject
),
1141 "FmXFormShell::executeControlConversionSlot: hmm ... shouldn't this parameter be redundant?" );
1143 for ( size_t lookupSlot
= 0; lookupSlot
< sizeof( nConvertSlots
) / sizeof( nConvertSlots
[0] ); ++lookupSlot
)
1145 if (nConvertSlots
[lookupSlot
] == _nSlotId
)
1147 Reference
< XInterface
> xNormalizedObject( _rxObject
, UNO_QUERY
);
1149 FmFormObj
* pFormObject
= NULL
;
1150 SdrObjListIter
aPageIter( *pFormPage
);
1151 while ( aPageIter
.IsMore() )
1153 SdrObject
* pCurrent
= aPageIter
.Next();
1154 pFormObject
= FmFormObj::GetFormObject( pCurrent
);
1158 Reference
< XInterface
> xCurrentNormalized( pFormObject
->GetUnoControlModel(), UNO_QUERY
);
1159 if ( xCurrentNormalized
.get() == xNormalizedObject
.get() )
1168 OUString
sNewName( getServiceNameByControlType( nObjectTypes
[ lookupSlot
] ) );
1169 Reference
<XComponentContext
> xContext
= comphelper::getProcessComponentContext();
1170 Reference
< XControlModel
> xNewModel( xContext
->getServiceManager()->createInstanceWithContext(sNewName
, xContext
), UNO_QUERY
);
1171 if (!xNewModel
.is())
1174 Reference
< XControlModel
> xOldModel( pFormObject
->GetUnoControlModel() );
1175 Reference
< XServiceInfo
> xModelInfo(xOldModel
, UNO_QUERY
);
1177 // Properties uebertragen
1178 Reference
< XPropertySet
> xOldSet(xOldModel
, UNO_QUERY
);
1179 Reference
< XPropertySet
> xNewSet(xNewModel
, UNO_QUERY
);
1182 Locale aNewLanguage
= Application::GetSettings().GetUILanguageTag().getLocale();
1183 TransferFormComponentProperties(xOldSet
, xNewSet
, aNewLanguage
);
1185 Sequence
< ::com::sun::star::script::ScriptEventDescriptor
> aOldScripts
;
1186 Reference
< XChild
> xChild(xOldModel
, UNO_QUERY
);
1189 Reference
< XIndexAccess
> xParent(xChild
->getParent(), UNO_QUERY
);
1191 // remember old script events
1192 Reference
< ::com::sun::star::script::XEventAttacherManager
> xEvManager(xChild
->getParent(), UNO_QUERY
);
1193 if (xParent
.is() && xEvManager
.is())
1195 sal_Int32 nIndex
= getElementPos(xParent
, xOldModel
);
1196 if (nIndex
>=0 && nIndex
<xParent
->getCount())
1197 aOldScripts
= xEvManager
->getScriptEvents(nIndex
);
1200 // replace the mdoel within the parent container
1201 Reference
< XIndexContainer
> xIndexParent(xChild
->getParent(), UNO_QUERY
);
1202 if (xIndexParent
.is())
1204 // the form container works with FormComponents
1205 Reference
< XFormComponent
> xComponent(xNewModel
, UNO_QUERY
);
1206 DBG_ASSERT(xComponent
.is(), "FmXFormShell::executeControlConversionSlot: the new model is no form component !");
1207 Any
aNewModel(makeAny(xComponent
));
1211 sal_Int32 nIndex
= getElementPos(xParent
, xOldModel
);
1212 if (nIndex
>=0 && nIndex
<xParent
->getCount())
1213 xIndexParent
->replaceByIndex(nIndex
, aNewModel
);
1216 OSL_FAIL("FmXFormShell::executeControlConversionSlot: could not replace the model !");
1217 Reference
< ::com::sun::star::lang::XComponent
> xNewComponent(xNewModel
, UNO_QUERY
);
1218 if (xNewComponent
.is())
1219 xNewComponent
->dispose();
1225 OSL_FAIL("FmXFormShell::executeControlConversionSlot: could not replace the model !");
1226 Reference
< ::com::sun::star::lang::XComponent
> xNewComponent(xNewModel
, UNO_QUERY
);
1227 if (xNewComponent
.is())
1228 xNewComponent
->dispose();
1235 // special handling for the LabelControl-property : can only be set when the model is placed
1236 // within the forms hierarchy
1237 if (::comphelper::hasProperty(FM_PROP_CONTROLLABEL
, xOldSet
) && ::comphelper::hasProperty(FM_PROP_CONTROLLABEL
, xNewSet
))
1241 xNewSet
->setPropertyValue(FM_PROP_CONTROLLABEL
, xOldSet
->getPropertyValue(FM_PROP_CONTROLLABEL
));
1249 // neues Model setzen
1250 pFormObject
->SetChanged();
1251 pFormObject
->SetUnoControlModel(xNewModel
);
1253 // transfer script events
1254 // (do this _after_ SetUnoControlModel as we need the new (implicitly created) control)
1255 if (aOldScripts
.getLength())
1257 // das Control zum Model suchen
1258 Reference
< XControlContainer
> xControlContainer( getControlContainerForView() );
1260 Sequence
< Reference
< XControl
> > aControls( xControlContainer
->getControls() );
1261 const Reference
< XControl
>* pControls
= aControls
.getConstArray();
1263 sal_uInt32 nLen
= aControls
.getLength();
1264 Reference
< XControl
> xControl
;
1265 for (sal_uInt32 i
=0 ; i
<nLen
; ++i
)
1267 if (pControls
[i
]->getModel() == xNewModel
)
1269 xControl
= pControls
[i
];
1273 TransferEventScripts(xNewModel
, xControl
, aOldScripts
);
1276 // transfer value bindings, if possible
1278 Reference
< XBindableValue
> xOldBindable( xOldModel
, UNO_QUERY
);
1279 Reference
< XBindableValue
> xNewBindable( xNewModel
, UNO_QUERY
);
1280 if ( xOldBindable
.is() )
1284 if ( xNewBindable
.is() )
1285 xNewBindable
->setValueBinding( xOldBindable
->getValueBinding() );
1286 xOldBindable
->setValueBinding( NULL
);
1288 catch(const Exception
&)
1290 DBG_UNHANDLED_EXCEPTION();
1294 // same for list entry sources
1296 Reference
< XListEntrySink
> xOldSink( xOldModel
, UNO_QUERY
);
1297 Reference
< XListEntrySink
> xNewSink( xNewModel
, UNO_QUERY
);
1298 if ( xOldSink
.is() )
1302 if ( xNewSink
.is() )
1303 xNewSink
->setListEntrySource( xOldSink
->getListEntrySource() );
1304 xOldSink
->setListEntrySource( NULL
);
1306 catch(const Exception
&)
1308 DBG_UNHANDLED_EXCEPTION();
1313 // create an undo action
1314 FmFormModel
* pModel
= m_pShell
->GetFormModel();
1315 DBG_ASSERT(pModel
!= NULL
, "FmXFormShell::executeControlConversionSlot: my shell has no model !");
1316 if (pModel
&& pModel
->IsUndoEnabled() )
1318 pModel
->AddUndo(new FmUndoModelReplaceAction(*pModel
, pFormObject
, xOldModel
));
1322 FmUndoModelReplaceAction::DisposeElement( xOldModel
);
1331 //------------------------------------------------------------------------------
1332 bool FmXFormShell::canConvertCurrentSelectionToControl( sal_Int16 nConversionSlot
)
1334 if ( m_aCurrentSelection
.empty() )
1337 InterfaceBag::const_iterator aCheck
= m_aCurrentSelection
.begin();
1338 Reference
< XServiceInfo
> xElementInfo( *aCheck
, UNO_QUERY
);
1339 if ( !xElementInfo
.is() )
1340 // no service info -> cannot determine this
1343 if ( ++aCheck
!= m_aCurrentSelection
.end() )
1344 // more than one element
1347 if ( Reference
< XForm
>::query( xElementInfo
).is() )
1351 sal_Int16 nObjectType
= getControlTypeByObject( xElementInfo
);
1353 if ( ( OBJ_FM_HIDDEN
== nObjectType
)
1354 || ( OBJ_FM_CONTROL
== nObjectType
)
1355 || ( OBJ_FM_GRID
== nObjectType
)
1357 return false; // those types cannot be converted
1359 DBG_ASSERT(sizeof(nConvertSlots
)/sizeof(nConvertSlots
[0]) == sizeof(nObjectTypes
)/sizeof(nObjectTypes
[0]),
1360 "FmXFormShell::canConvertCurrentSelectionToControl: nConvertSlots & nObjectTypes must have the same size !");
1362 for ( size_t i
= 0; i
< sizeof( nConvertSlots
) / sizeof( nConvertSlots
[0] ); ++i
)
1363 if (nConvertSlots
[i
] == nConversionSlot
)
1364 return nObjectTypes
[i
] != nObjectType
;
1366 return sal_True
; // all other slots: assume "yes"
1369 //------------------------------------------------------------------------------
1370 void FmXFormShell::checkControlConversionSlotsForCurrentSelection( Menu
& rMenu
)
1372 for (sal_Int16 i
=0; i
<rMenu
.GetItemCount(); ++i
)
1373 // der Context ist schon von einem Typ, der dem Eitnrag entspricht -> disable
1374 rMenu
.EnableItem( rMenu
.GetItemId(i
), canConvertCurrentSelectionToControl( rMenu
.GetItemId( i
) ) );
1377 //------------------------------------------------------------------------------
1378 void FmXFormShell::LoopGrids(sal_Int16 nWhat
)
1380 if ( impl_checkDisposed() )
1383 Reference
< XIndexContainer
> xControlModels(m_xActiveForm
, UNO_QUERY
);
1384 if (xControlModels
.is())
1386 for (sal_Int16 i
=0; i
<xControlModels
->getCount(); ++i
)
1388 Reference
< XPropertySet
> xModelSet
;
1389 xControlModels
->getByIndex(i
) >>= xModelSet
;
1390 if (!xModelSet
.is())
1393 if (!::comphelper::hasProperty(FM_PROP_CLASSID
, xModelSet
))
1395 sal_Int16 nClassId
= ::comphelper::getINT16(xModelSet
->getPropertyValue(FM_PROP_CLASSID
));
1396 if (FormComponentType::GRIDCONTROL
!= nClassId
)
1399 if (!::comphelper::hasProperty(FM_PROP_CURSORCOLOR
, xModelSet
) || !::comphelper::hasProperty(FM_PROP_ALWAYSSHOWCURSOR
, xModelSet
) || !::comphelper::hasProperty(FM_PROP_DISPLAYSYNCHRON
, xModelSet
))
1402 switch (nWhat
& GA_SYNC_MASK
)
1404 case GA_DISABLE_SYNC
:
1406 sal_Bool
bB(sal_False
);
1407 xModelSet
->setPropertyValue(FM_PROP_DISPLAYSYNCHRON
, Any(&bB
,getBooleanCppuType()));
1412 Any
aOldVal( xModelSet
->getPropertyValue(FM_PROP_DISPLAYSYNCHRON
) );
1413 sal_Bool
bB(sal_True
);
1414 xModelSet
->setPropertyValue(FM_PROP_DISPLAYSYNCHRON
, Any(&bB
,getBooleanCppuType()));
1415 xModelSet
->setPropertyValue(FM_PROP_DISPLAYSYNCHRON
, aOldVal
);
1418 case GA_ENABLE_SYNC
:
1420 sal_Bool
bB(sal_True
);
1421 xModelSet
->setPropertyValue(FM_PROP_DISPLAYSYNCHRON
, Any(&bB
,getBooleanCppuType()));
1426 if (nWhat
& GA_DISABLE_ROCTRLR
)
1428 sal_Bool
bB(sal_False
);
1429 xModelSet
->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR
, Any(&bB
,getBooleanCppuType()));
1430 Reference
< XPropertyState
> xModelPropState(xModelSet
, UNO_QUERY
);
1431 if (xModelPropState
.is())
1432 xModelPropState
->setPropertyToDefault(FM_PROP_CURSORCOLOR
);
1434 xModelSet
->setPropertyValue(FM_PROP_CURSORCOLOR
, Any()); // this should be the default
1436 else if (nWhat
& GA_ENABLE_ROCTRLR
)
1438 sal_Bool
bB(sal_True
);
1439 xModelSet
->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR
, Any(&bB
,getBooleanCppuType()));
1440 xModelSet
->setPropertyValue(FM_PROP_CURSORCOLOR
, makeAny(sal_Int32(COL_LIGHTRED
)));
1446 //------------------------------------------------------------------------------
1447 Reference
< XControlContainer
> FmXFormShell::getControlContainerForView()
1449 if ( impl_checkDisposed() )
1452 SdrPageView
* pPageView
= NULL
;
1453 if ( m_pShell
&& m_pShell
->GetFormView() )
1454 pPageView
= m_pShell
->GetFormView()->GetSdrPageView();
1456 Reference
< XControlContainer
> xControlContainer
;
1458 xControlContainer
= pPageView
->GetPageWindow(0)->GetControlContainer();
1460 return xControlContainer
;
1463 //------------------------------------------------------------------------------
1464 void FmXFormShell::ExecuteTabOrderDialog( const Reference
< XTabControllerModel
>& _rxForForm
)
1466 if ( impl_checkDisposed() )
1469 OSL_PRECOND( _rxForForm
.is(), "FmXFormShell::ExecuteTabOrderDialog: invalid tabbing model!" );
1470 if ( !_rxForForm
.is() )
1475 Sequence
< Any
> aDialogArgs( 3 );
1476 aDialogArgs
[0] <<= NamedValue(
1477 OUString( "TabbingModel" ),
1478 makeAny( _rxForForm
)
1480 aDialogArgs
[1] <<= NamedValue(
1481 OUString( "ControlContext" ),
1482 makeAny( getControlContainerForView() )
1485 Reference
< XWindow
> xParentWindow
;
1486 if ( m_pShell
->GetViewShell() && m_pShell
->GetViewShell()->GetViewFrame() )
1487 xParentWindow
= VCLUnoHelper::GetInterface ( &m_pShell
->GetViewShell()->GetViewFrame()->GetWindow() );
1488 aDialogArgs
[2] <<= NamedValue(
1489 OUString( "ParentWindow" ),
1490 makeAny( xParentWindow
)
1493 Reference
< dialogs::XExecutableDialog
> xDialog(
1494 ::comphelper::getProcessServiceFactory()->createInstanceWithArguments(
1495 OUString( "com.sun.star.form.ui.TabOrderDialog" ),
1500 OSL_ENSURE( xDialog
.is(), "FmXFormShell::ExecuteTabOrderDialog: could not create the dialog!" );
1505 catch( const Exception
& )
1507 OSL_FAIL( "FmXFormShell::ExecuteTabOrderDialog: caught an exception!" );
1511 //------------------------------------------------------------------------------
1512 void FmXFormShell::ExecuteSearch()
1514 if ( impl_checkDisposed() )
1517 // eine Sammlung aller (logischen) Formulare
1519 m_aSearchForms
.swap( aEmpty
);
1520 ::std::vector
< OUString
> aContextNames
;
1521 impl_collectFormSearchContexts_nothrow( m_pShell
->GetCurPage()->GetForms(), OUString(), m_aSearchForms
, aContextNames
);
1522 OSL_POSTCOND( m_aSearchForms
.size() == aContextNames
.size(),
1523 "FmXFormShell::ExecuteSearch: nonsense!" );
1524 if ( m_aSearchForms
.size() != aContextNames
.size() )
1527 // filter out the forms which do not contain valid controls at all
1529 FmFormArray aValidForms
;
1530 ::std::vector
< OUString
> aValidContexts
;
1531 FmFormArray::const_iterator form
= m_aSearchForms
.begin();
1532 ::std::vector
< OUString
>::const_iterator contextName
= aContextNames
.begin();
1533 for ( ; form
!= m_aSearchForms
.end(); ++form
, ++contextName
)
1535 FmSearchContext aTestContext
;
1536 aTestContext
.nContext
= static_cast< sal_Int16
>( form
- m_aSearchForms
.begin() );
1537 sal_uInt32 nValidControls
= OnSearchContextRequest( &aTestContext
);
1538 if ( nValidControls
> 0 )
1540 aValidForms
.push_back( *form
);
1541 aValidContexts
.push_back( *contextName
);
1545 m_aSearchForms
.swap( aValidForms
);
1546 aContextNames
.swap( aValidContexts
);
1549 if (m_aSearchForms
.empty() )
1550 { // es gibt keine Controls, die alle Bedingungen fuer eine Suche erfuellen
1551 ErrorBox(NULL
, WB_OK
, SVX_RESSTR(RID_STR_NODATACONTROLS
)).Execute();
1555 // jetzt brauche ich noch einen 'initial context'
1556 sal_Int16 nInitialContext
= 0;
1557 Reference
< XForm
> xActiveForm( getActiveForm());
1558 for ( size_t i
=0; i
<m_aSearchForms
.size(); ++i
)
1560 if (m_aSearchForms
.at(i
) == xActiveForm
)
1562 nInitialContext
= (sal_Int16
)i
;
1567 // wenn der Dialog initial den Text des aktiven Controls anbieten soll, muss dieses ein XTextComponent-Interface habe,
1568 // ausserdem macht das nur Sinn, wenn das aktuelle Feld auch an ein Tabellen- (oder was-auch-immer-)Feld gebunden ist
1569 OUString strActiveField
;
1570 OUString strInitialText
;
1571 // ... das bekomme ich von meinem FormController
1572 DBG_ASSERT(m_xActiveController
.is(), "FmXFormShell::ExecuteSearch : no active controller !");
1573 Reference
< XControl
> xActiveControl( m_xActiveController
->getCurrentControl());
1574 if (xActiveControl
.is())
1576 // das Control kann mir sein Model sagen ...
1577 Reference
< XControlModel
> xActiveModel( xActiveControl
->getModel());
1578 DBG_ASSERT(xActiveModel
.is(), "FmXFormShell::ExecuteSearch : active control has no model !");
1580 // das Model frage ich nach der ControlSource-Eigenschaft ...
1581 Reference
< XPropertySet
> xProperties(xActiveControl
->getModel(), UNO_QUERY
);
1582 if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE
, xProperties
) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD
, xProperties
))
1584 Reference
< XPropertySet
> xField
;
1585 xProperties
->getPropertyValue(FM_PROP_BOUNDFIELD
) >>= xField
;
1586 if (xField
.is()) // (nur wenn das Ding wirklich gebunden ist)
1588 // und das Control selber nach einem TextComponent-Interface (damit ich mir dort den Text abholen kann)
1589 Reference
< XTextComponent
> xText(xActiveControl
, UNO_QUERY
);
1592 strActiveField
= getLabelName(xProperties
).getStr();
1593 strInitialText
= xText
->getText().getStr();
1599 // das Control selber hat keine ControlSource, aber vielleicht ist es ein GridControl
1600 Reference
< XGrid
> xGrid(xActiveControl
, UNO_QUERY
);
1603 // fuer strActiveField brauche ich die die ControlSource der Column, dafuer den Columns-Container, dafuer die
1605 Reference
< XGridPeer
> xGridPeer(xActiveControl
->getPeer(), UNO_QUERY
);
1606 Reference
< XIndexAccess
> xColumns
;
1608 xColumns
= Reference
< XIndexAccess
>(xGridPeer
->getColumns(),UNO_QUERY
);
1610 sal_Int16 nViewCol
= xGrid
->getCurrentColumnPosition();
1611 sal_Int16 nModelCol
= GridView2ModelPos(xColumns
, nViewCol
);
1612 Reference
< XPropertySet
> xCurrentCol
;
1614 xColumns
->getByIndex(nModelCol
) >>= xCurrentCol
;
1615 if (xCurrentCol
.is())
1616 strActiveField
= ::comphelper::getString(xCurrentCol
->getPropertyValue(FM_PROP_LABEL
)).getStr();
1618 // the text fo the current column
1619 Reference
< XIndexAccess
> xColControls(xGridPeer
, UNO_QUERY
);
1620 Reference
< XInterface
> xCurControl
;
1621 xColControls
->getByIndex(nViewCol
) >>= xCurControl
;
1622 OUString sInitialText
;
1623 if (IsSearchableControl(xCurControl
, &sInitialText
))
1624 strInitialText
= sInitialText
.getStr();
1629 // um eventuelle GridControls, die ich kenne, kuemmern
1630 LoopGrids(GA_DISABLE_SYNC
/*| GA_ENABLE_ROCTRLR*/);
1632 // jetzt bin ich reif fuer den Dialog
1633 // wenn die potentiellen Deadlocks, die durch die Benutzung des Solar-Mutex in MTs VCLX...-Klasen entstehen, irgendwann mal
1634 // ausgeraeumt sind, sollte hier ein SM_USETHREAD rein, denn die Suche in einem eigenen Thread ist doch etwas fluessiger
1635 // sollte allerdings irgendwie von dem unterliegenden Cursor abhaengig gemacht werden, DAO zum Beispiel ist nicht thread-sicher
1636 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
1637 AbstractFmSearchDialog
* pDialog
= NULL
;
1639 pDialog
= pFact
->CreateFmSearchDialog( &m_pShell
->GetViewShell()->GetViewFrame()->GetWindow(), strInitialText
, aContextNames
, nInitialContext
, LINK( this, FmXFormShell
, OnSearchContextRequest
) );
1640 DBG_ASSERT( pDialog
, "FmXFormShell::ExecuteSearch: could not create the search dialog!" );
1643 pDialog
->SetActiveField( strActiveField
);
1644 pDialog
->SetFoundHandler( LINK( this, FmXFormShell
, OnFoundData
) );
1645 pDialog
->SetCanceledNotFoundHdl( LINK( this, FmXFormShell
, OnCanceledNotFound
) );
1650 // GridControls wieder restaurieren
1651 LoopGrids(GA_ENABLE_SYNC
| GA_DISABLE_ROCTRLR
);
1653 m_pShell
->GetFormView()->UnMarkAll(m_pShell
->GetFormView()->GetSdrPageView());
1654 // da ich in OnFoundData (fals ich dort war) Controls markiert habe
1657 //------------------------------------------------------------------------------
1658 sal_Bool
FmXFormShell::GetY2KState(sal_uInt16
& n
)
1660 if ( impl_checkDisposed() )
1663 if (m_pShell
->IsDesignMode())
1664 // im Design-Modus (ohne aktive Controls) soll sich das Haupt-Dokument darum kuemmern
1667 Reference
< XForm
> xForm( getActiveForm());
1669 // kein aktuelles Formular (also insbesondere kein aktuelles Control) -> das Haupt-Dokument soll sich kuemmern
1672 Reference
< XRowSet
> xDB(xForm
, UNO_QUERY
);
1673 DBG_ASSERT(xDB
.is(), "FmXFormShell::GetY2KState : current form has no dbform-interface !");
1675 Reference
< XNumberFormatsSupplier
> xSupplier( getNumberFormats(OStaticDataAccessTools().getRowSetConnection(xDB
), sal_False
));
1678 Reference
< XPropertySet
> xSet(xSupplier
->getNumberFormatSettings());
1683 Any
aVal( xSet
->getPropertyValue(OUString("TwoDigitDateStart")) );
1696 //------------------------------------------------------------------------------
1697 void FmXFormShell::SetY2KState(sal_uInt16 n
)
1699 if ( impl_checkDisposed() )
1702 Reference
< XForm
> xActiveForm( getActiveForm());
1703 Reference
< XRowSet
> xActiveRowSet( xActiveForm
, UNO_QUERY
);
1704 if ( xActiveRowSet
.is() )
1706 Reference
< XNumberFormatsSupplier
> xSupplier( getNumberFormats( getRowSetConnection( xActiveRowSet
), sal_False
) );
1709 Reference
< XPropertySet
> xSet(xSupplier
->getNumberFormatSettings());
1716 xSet
->setPropertyValue(OUString("TwoDigitDateStart"), aVal
);
1720 OSL_FAIL("FmXFormShell::SetY2KState: Exception occurred!");
1728 // kein aktives Formular gefunden -> alle aktuell vorhandenen Formulare durchiterieren
1729 Reference
< XIndexAccess
> xCurrentForms( m_xForms
);
1730 if (!xCurrentForms
.is())
1731 { // im alive-Modus sind meine Forms nicht gesetzt, wohl aber die an der Page
1732 if (m_pShell
->GetCurPage())
1733 xCurrentForms
= Reference
< XIndexAccess
>( m_pShell
->GetCurPage()->GetForms( false ), UNO_QUERY
);
1735 if (!xCurrentForms
.is())
1738 ::comphelper::IndexAccessIterator
aIter(xCurrentForms
);
1739 Reference
< XInterface
> xCurrentElement( aIter
.Next());
1740 while (xCurrentElement
.is())
1742 // ist das aktuelle Element eine DatabaseForm ?
1743 Reference
< XRowSet
> xElementAsRowSet( xCurrentElement
, UNO_QUERY
);
1744 if ( xElementAsRowSet
.is() )
1746 Reference
< XNumberFormatsSupplier
> xSupplier( getNumberFormats( getRowSetConnection( xElementAsRowSet
), sal_False
) );
1747 if (!xSupplier
.is())
1750 Reference
< XPropertySet
> xSet(xSupplier
->getNumberFormatSettings());
1757 xSet
->setPropertyValue(OUString("TwoDigitDateStart"), aVal
);
1761 OSL_FAIL("FmXFormShell::SetY2KState: Exception occurred!");
1766 xCurrentElement
= aIter
.Next();
1770 //------------------------------------------------------------------------------
1771 void FmXFormShell::CloseExternalFormViewer()
1773 if ( impl_checkDisposed() )
1776 if (!m_xExternalViewController
.is())
1779 Reference
< ::com::sun::star::frame::XFrame
> xExternalViewFrame( m_xExternalViewController
->getFrame());
1780 Reference
< ::com::sun::star::frame::XDispatchProvider
> xCommLink(xExternalViewFrame
, UNO_QUERY
);
1781 if (!xCommLink
.is())
1784 xExternalViewFrame
->setComponent(NULL
,NULL
);
1785 ::comphelper::disposeComponent(xExternalViewFrame
);
1786 m_xExternalViewController
= NULL
;
1787 m_xExtViewTriggerController
= NULL
;
1788 m_xExternalDisplayedForm
= NULL
;
1791 //------------------------------------------------------------------------------
1792 Reference
< XResultSet
> FmXFormShell::getInternalForm(const Reference
< XResultSet
>& _xForm
) const
1794 if ( impl_checkDisposed() )
1797 Reference
< runtime::XFormController
> xExternalCtrlr(m_xExternalViewController
, UNO_QUERY
);
1798 if (xExternalCtrlr
.is() && (_xForm
== xExternalCtrlr
->getModel()))
1800 DBG_ASSERT(m_xExternalDisplayedForm
.is(), "FmXFormShell::getInternalForm : invalid external form !");
1801 return m_xExternalDisplayedForm
;
1806 //------------------------------------------------------------------------------
1807 Reference
< XForm
> FmXFormShell::getInternalForm(const Reference
< XForm
>& _xForm
) const
1809 if ( impl_checkDisposed() )
1812 Reference
< runtime::XFormController
> xExternalCtrlr(m_xExternalViewController
, UNO_QUERY
);
1813 if (xExternalCtrlr
.is() && (_xForm
== xExternalCtrlr
->getModel()))
1815 DBG_ASSERT(m_xExternalDisplayedForm
.is(), "FmXFormShell::getInternalForm : invalid external form !");
1816 return Reference
< XForm
>(m_xExternalDisplayedForm
, UNO_QUERY
);
1821 //------------------------------------------------------------------------
1824 static bool lcl_isNavigationRelevant( sal_Int32 _nWhich
)
1826 return ( _nWhich
== SID_FM_RECORD_FIRST
)
1827 || ( _nWhich
== SID_FM_RECORD_PREV
)
1828 || ( _nWhich
== SID_FM_RECORD_NEXT
)
1829 || ( _nWhich
== SID_FM_RECORD_LAST
)
1830 || ( _nWhich
== SID_FM_RECORD_NEW
);
1834 //------------------------------------------------------------------------------
1835 bool FmXFormShell::IsFormSlotEnabled( sal_Int32 _nSlot
, FeatureState
* _pCompleteState
)
1837 const ::svx::ControllerFeatures
& rController
=
1838 lcl_isNavigationRelevant( _nSlot
)
1839 ? getNavControllerFeatures()
1840 : getActiveControllerFeatures();
1842 if ( !_pCompleteState
)
1843 return rController
->isEnabled( _nSlot
);
1845 rController
->getState( _nSlot
, *_pCompleteState
);
1846 return _pCompleteState
->Enabled
;
1849 //------------------------------------------------------------------------------
1850 void FmXFormShell::ExecuteFormSlot( sal_Int32 _nSlot
)
1852 const ::svx::ControllerFeatures
& rController
=
1853 lcl_isNavigationRelevant( _nSlot
)
1854 ? getNavControllerFeatures()
1855 : getActiveControllerFeatures();
1857 rController
->execute( _nSlot
);
1859 if ( _nSlot
== SID_FM_RECORD_UNDO
)
1861 // if we're doing an UNDO, *and* if the affected form is the form which we also display
1862 // as external view, then we need to reset the controls of the external form, too
1863 if ( getInternalForm( getActiveForm() ) == m_xExternalDisplayedForm
)
1865 Reference
< XIndexAccess
> xContainer( m_xExternalDisplayedForm
, UNO_QUERY
);
1866 if ( xContainer
.is() )
1868 Reference
< XReset
> xReset
;
1869 for ( sal_Int32 i
= 0; i
< xContainer
->getCount(); ++i
)
1871 if ( ( xContainer
->getByIndex( i
) >>= xReset
) && xReset
.is() )
1873 // no resets on sub forms
1874 Reference
< XForm
> xAsForm( xReset
, UNO_QUERY
);
1875 if ( !xAsForm
.is() )
1884 //------------------------------------------------------------------------------
1885 void FmXFormShell::impl_switchActiveControllerListening( const bool _bListen
)
1887 Reference
< XComponent
> xComp( m_xActiveController
, UNO_QUERY
);
1892 xComp
->addEventListener( (XFormControllerListener
*)this );
1894 xComp
->removeEventListener( (XFormControllerListener
*)this );
1897 //------------------------------------------------------------------------------
1898 void FmXFormShell::setActiveController( const Reference
< runtime::XFormController
>& xController
, sal_Bool _bNoSaveOldContent
)
1900 if ( impl_checkDisposed() )
1903 if (m_bChangingDesignMode
)
1905 DBG_ASSERT(!m_pShell
->IsDesignMode(), "nur im alive mode verwenden");
1907 // Ist die Routine ein zweites Mal gerufen worden,
1908 // dann sollte der Focus nicht mehr umgesetzt werden
1911 m_bSetFocus
= xController
!= m_xActiveController
;
1915 if (xController
!= m_xActiveController
)
1917 ::osl::ClearableMutexGuard
aGuard(m_aAsyncSafety
);
1918 // switch all nav dispatchers belonging to the form of the current nav controller to 'non active'
1919 Reference
< XResultSet
> xNavigationForm
;
1920 if (m_xNavigationController
.is())
1921 xNavigationForm
= Reference
< XResultSet
>(m_xNavigationController
->getModel(), UNO_QUERY
);
1924 m_bInActivate
= sal_True
;
1926 // check if the 2 controllers serve different forms
1927 Reference
< XResultSet
> xOldForm
;
1928 if (m_xActiveController
.is())
1929 xOldForm
= Reference
< XResultSet
>(m_xActiveController
->getModel(), UNO_QUERY
);
1930 Reference
< XResultSet
> xNewForm
;
1931 if (xController
.is())
1932 xNewForm
= Reference
< XResultSet
>(xController
->getModel(), UNO_QUERY
);
1933 xOldForm
= getInternalForm(xOldForm
);
1934 xNewForm
= getInternalForm(xNewForm
);
1936 sal_Bool bDifferentForm
= ( xOldForm
.get() != xNewForm
.get() );
1937 sal_Bool bNeedSave
= bDifferentForm
&& !_bNoSaveOldContent
;
1938 // we save the content of the old form if we move to a new form, and saving old content is allowed
1940 if ( m_xActiveController
.is() && bNeedSave
)
1942 // beim Wechsel des Controllers den Inhalt speichern, ein Commit
1943 // wurde bereits ausgefuehrt
1944 if ( m_aActiveControllerFeatures
->commitCurrentControl() )
1946 m_bSetFocus
= sal_True
;
1947 if ( m_aActiveControllerFeatures
->isModifiedRow() )
1949 sal_Bool bIsNew
= m_aActiveControllerFeatures
->isInsertionRow();
1950 sal_Bool bResult
= m_aActiveControllerFeatures
->commitCurrentRecord();
1951 if ( !bResult
&& m_bSetFocus
)
1953 // if we couldn't save the current record, set the focus back to the
1955 Reference
< XWindow
> xWindow( m_xActiveController
->getCurrentControl(), UNO_QUERY
);
1957 xWindow
->setFocus();
1958 m_bInActivate
= sal_False
;
1961 else if ( bResult
&& bIsNew
)
1963 Reference
< XResultSet
> xCursor( m_aActiveControllerFeatures
->getCursor().get() );
1966 DO_SAFE( xCursor
->last(); );
1975 impl_switchActiveControllerListening( false );
1977 m_aActiveControllerFeatures
.dispose();
1978 m_xActiveController
= xController
;
1979 if ( m_xActiveController
.is() )
1980 m_aActiveControllerFeatures
.assign( m_xActiveController
);
1982 impl_switchActiveControllerListening( true );
1984 if ( m_xActiveController
.is() )
1985 m_xActiveForm
= getInternalForm( Reference
< XForm
>( m_xActiveController
->getModel(), UNO_QUERY
) );
1987 m_xActiveForm
= NULL
;
1991 // activate all dispatchers belonging to form of the new navigation controller
1992 xNavigationForm
= NULL
;
1993 if (m_xNavigationController
.is())
1994 xNavigationForm
= Reference
< XResultSet
>(m_xNavigationController
->getModel(), UNO_QUERY
);
1996 m_bInActivate
= sal_False
;
1998 m_pShell
->UIFeatureChanged();
1999 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell
);
2001 InvalidateSlot(SID_FM_FILTER_NAVIGATOR_CONTROL
, sal_True
);
2005 //------------------------------------------------------------------------------
2006 void FmXFormShell::getCurrentSelection( InterfaceBag
& /* [out] */ _rSelection
) const
2008 _rSelection
= m_aCurrentSelection
;
2011 //------------------------------------------------------------------------------
2012 bool FmXFormShell::setCurrentSelectionFromMark( const SdrMarkList
& _rMarkList
)
2014 m_aLastKnownMarkedControls
.clear();
2016 if ( ( _rMarkList
.GetMarkCount() > 0 ) && isControlList( _rMarkList
) )
2017 collectInterfacesFromMarkList( _rMarkList
, m_aLastKnownMarkedControls
);
2019 return setCurrentSelection( m_aLastKnownMarkedControls
);
2022 //------------------------------------------------------------------------------
2023 bool FmXFormShell::selectLastMarkedControls()
2025 return setCurrentSelection( m_aLastKnownMarkedControls
);
2028 //------------------------------------------------------------------------------
2029 bool FmXFormShell::setCurrentSelection( const InterfaceBag
& _rSelection
)
2031 if ( impl_checkDisposed() )
2034 DBG_ASSERT( m_pShell
->IsDesignMode(), "FmXFormShell::setCurrentSelection: only to be used in design mode!" );
2036 if ( _rSelection
.empty() && m_aCurrentSelection
.empty() )
2040 if ( _rSelection
.size() == m_aCurrentSelection
.size() )
2042 InterfaceBag::const_iterator aNew
= _rSelection
.begin();
2043 InterfaceBag::const_iterator aOld
= m_aCurrentSelection
.begin();
2044 for ( ; aNew
!= _rSelection
.end(); ++aNew
, ++aOld
)
2046 OSL_ENSURE( Reference
< XInterface
>( *aNew
, UNO_QUERY
).get() == aNew
->get(), "FmXFormShell::setCurrentSelection: new interface not normalized!" );
2047 OSL_ENSURE( Reference
< XInterface
>( *aOld
, UNO_QUERY
).get() == aOld
->get(), "FmXFormShell::setCurrentSelection: old interface not normalized!" );
2049 if ( aNew
->get() != aOld
->get() )
2053 if ( aNew
== _rSelection
.end() )
2058 // the following is some strange code to ensure that when you have two grid controls in a document,
2059 // only one of them can have a selected column.
2060 // TODO: this should happen elsewhere, but not here - shouldn't it?
2061 if ( !m_aCurrentSelection
.empty() )
2063 Reference
< XChild
> xCur
; if ( m_aCurrentSelection
.size() == 1 ) xCur
= xCur
.query( *m_aCurrentSelection
.begin() );
2064 Reference
< XChild
> xNew
; if ( _rSelection
.size() == 1 ) xNew
= xNew
.query( *_rSelection
.begin() );
2066 // is there nothing to be selected, or the parents differ, and the parent of the current object
2067 // is a selection supplier, then deselect
2068 if ( xCur
.is() && ( !xNew
.is() || ( xCur
->getParent() != xNew
->getParent() ) ) )
2070 Reference
< XSelectionSupplier
> xSel( xCur
->getParent(), UNO_QUERY
);
2072 xSel
->select( Any() );
2076 m_aCurrentSelection
= _rSelection
;
2078 // determine the form which all the selected obj�cts belong to, if any
2079 Reference
< XForm
> xNewCurrentForm
;
2080 for ( InterfaceBag::const_iterator loop
= m_aCurrentSelection
.begin();
2081 loop
!= m_aCurrentSelection
.end();
2085 Reference
< XForm
> xThisRoundsForm( GetForm( *loop
) );
2086 OSL_ENSURE( xThisRoundsForm
.is(), "FmXFormShell::setCurrentSelection: *everything* should belong to a form!" );
2088 if ( !xNewCurrentForm
.is() )
2089 { // the first form we encounterd
2090 xNewCurrentForm
= xThisRoundsForm
;
2092 else if ( xNewCurrentForm
!= xThisRoundsForm
)
2093 { // different forms -> no "current form" at all
2094 xNewCurrentForm
.clear();
2099 if ( !m_aCurrentSelection
.empty() )
2100 impl_updateCurrentForm( xNewCurrentForm
);
2102 // ensure some slots are updated
2103 for ( size_t i
= 0; i
< sizeof( SelObjectSlotMap
) / sizeof( SelObjectSlotMap
[0] ); ++i
)
2104 InvalidateSlot( SelObjectSlotMap
[i
], sal_False
);
2109 //------------------------------------------------------------------------------
2110 bool FmXFormShell::isSolelySelected( const Reference
< XInterface
>& _rxObject
)
2112 return ( m_aCurrentSelection
.size() == 1 ) && ( *m_aCurrentSelection
.begin() == _rxObject
);
2115 //------------------------------------------------------------------------------
2116 void FmXFormShell::forgetCurrentForm()
2118 if ( !m_xCurrentForm
.is() )
2122 impl_updateCurrentForm( NULL
);
2124 // ... and try finding a new current form
2125 // #i88186# / 2008-04-12 / frank.schoenheit@sun.com
2126 impl_defaultCurrentForm_nothrow();
2129 //------------------------------------------------------------------------------
2130 void FmXFormShell::impl_updateCurrentForm( const Reference
< XForm
>& _rxNewCurForm
)
2132 if ( impl_checkDisposed() )
2135 m_xCurrentForm
= _rxNewCurForm
;
2137 // propagate to the FormPage(Impl)
2138 FmFormPage
* pPage
= m_pShell
->GetCurPage();
2140 pPage
->GetImpl().setCurForm( m_xCurrentForm
);
2142 // ensure the UI which depends on the current form is up-to-date
2143 for ( size_t i
= 0; i
< sizeof( DlgSlotMap
) / sizeof( DlgSlotMap
[0] ); ++i
)
2144 InvalidateSlot( DlgSlotMap
[i
], sal_False
);
2147 //------------------------------------------------------------------------------
2148 void FmXFormShell::startListening()
2150 if ( impl_checkDisposed() )
2153 Reference
< XRowSet
> xDatabaseForm(m_xActiveForm
, UNO_QUERY
);
2154 if (xDatabaseForm
.is() && getRowSetConnection(xDatabaseForm
).is())
2156 Reference
< XPropertySet
> xActiveFormSet(m_xActiveForm
, UNO_QUERY
);
2157 if (xActiveFormSet
.is())
2159 // wenn es eine Datenquelle gibt, dann den Listener aufbauen
2160 // TODO: this is strange - shouldn't this depend on a isLoaded instead of
2161 // a "has command value"? Finally, the command value only means that it was
2162 // intended to be loaded, not that it actually *is* loaded
2163 OUString aSource
= ::comphelper::getString(xActiveFormSet
->getPropertyValue(FM_PROP_COMMAND
));
2164 if (!aSource
.isEmpty())
2166 m_bDatabaseBar
= sal_True
;
2168 xActiveFormSet
->getPropertyValue(FM_PROP_NAVIGATION
) >>= m_eNavigate
;
2170 switch (m_eNavigate
)
2172 case NavigationBarMode_PARENT
:
2174 // suchen des Controllers, ueber den eine Navigation moeglich ist
2175 Reference
< XChild
> xChild(m_xActiveController
, UNO_QUERY
);
2176 Reference
< runtime::XFormController
> xParent
;
2179 xChild
= Reference
< XChild
>(xChild
->getParent(), UNO_QUERY
);
2180 xParent
= Reference
< runtime::XFormController
>(xChild
, UNO_QUERY
);
2181 Reference
< XPropertySet
> xParentSet
;
2183 xParentSet
= Reference
< XPropertySet
>(xParent
->getModel(), UNO_QUERY
);
2184 if (xParentSet
.is())
2186 xParentSet
->getPropertyValue(FM_PROP_NAVIGATION
) >>= m_eNavigate
;
2187 if (m_eNavigate
== NavigationBarMode_CURRENT
)
2191 m_xNavigationController
= xParent
;
2195 case NavigationBarMode_CURRENT
:
2196 m_xNavigationController
= m_xActiveController
;
2200 m_xNavigationController
= NULL
;
2201 m_bDatabaseBar
= sal_False
;
2204 m_aNavControllerFeatures
.dispose();
2205 if ( m_xNavigationController
.is() && ( m_xNavigationController
!= m_xActiveController
) )
2206 m_aNavControllerFeatures
.assign( m_xNavigationController
);
2208 // an dem Controller, der die Navigation regelt, wg. RecordCount lauschen
2209 Reference
< XPropertySet
> xNavigationSet
;
2210 if (m_xNavigationController
.is())
2212 xNavigationSet
= Reference
< XPropertySet
>(m_xNavigationController
->getModel(), UNO_QUERY
);
2213 if (xNavigationSet
.is())
2214 xNavigationSet
->addPropertyChangeListener(FM_PROP_ROWCOUNT
,this);
2221 m_eNavigate
= NavigationBarMode_NONE
;
2222 m_bDatabaseBar
= sal_False
;
2223 m_xNavigationController
= NULL
;
2226 //------------------------------------------------------------------------------
2227 void FmXFormShell::stopListening()
2229 if ( impl_checkDisposed() )
2232 Reference
< XRowSet
> xDatabaseForm(m_xActiveForm
, UNO_QUERY
);
2233 if ( xDatabaseForm
.is() )
2235 if (m_xNavigationController
.is())
2237 Reference
< XPropertySet
> xSet(m_xNavigationController
->getModel(), UNO_QUERY
);
2239 xSet
->removePropertyChangeListener(FM_PROP_ROWCOUNT
, this);
2244 m_bDatabaseBar
= sal_False
;
2245 m_eNavigate
= NavigationBarMode_NONE
;
2246 m_xNavigationController
= NULL
;
2249 //------------------------------------------------------------------------------
2250 void FmXFormShell::ShowSelectionProperties( sal_Bool bShow
)
2252 if ( impl_checkDisposed() )
2255 // if the window is already visible, only update the state
2256 sal_Bool bHasChild
= m_pShell
->GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_SHOW_PROPERTIES
);
2257 if ( bHasChild
&& bShow
)
2258 UpdateSlot( SID_FM_PROPERTY_CONTROL
);
2260 // else toggle state
2262 m_pShell
->GetViewShell()->GetViewFrame()->ToggleChildWindow(SID_FM_SHOW_PROPERTIES
);
2264 InvalidateSlot( SID_FM_PROPERTIES
, sal_False
);
2265 InvalidateSlot( SID_FM_CTL_PROPERTIES
, sal_False
);
2268 //------------------------------------------------------------------------------
2269 IMPL_LINK(FmXFormShell
, OnFoundData
, FmFoundRecordInformation
*, pfriWhere
)
2271 if ( impl_checkDisposed() )
2274 DBG_ASSERT((pfriWhere
->nContext
>= 0) && (pfriWhere
->nContext
< (sal_Int16
)m_aSearchForms
.size()),
2275 "FmXFormShell::OnFoundData : ungueltiger Kontext !");
2276 Reference
< XForm
> xForm( m_aSearchForms
.at(pfriWhere
->nContext
));
2277 DBG_ASSERT(xForm
.is(), "FmXFormShell::OnFoundData : ungueltige Form !");
2279 Reference
< XRowLocate
> xCursor(xForm
, UNO_QUERY
);
2281 return 0; // was soll ich da machen ?
2286 xCursor
->moveToBookmark(pfriWhere
->aPosition
);
2288 catch(const SQLException
&)
2290 OSL_FAIL("Can position on bookmark!");
2293 LoopGrids(GA_FORCE_SYNC
);
2295 // und zum Feld (dazu habe ich vor dem Start des Suchens die XVclComponent-Interfaces eingesammelt)
2296 SAL_WARN_IF(static_cast<size_t>(pfriWhere
->nFieldPos
) >=
2297 m_arrSearchedControls
.size(),
2298 "svx.form", "FmXFormShell::OnFoundData : invalid index!");
2299 SdrObject
* pObject
= m_arrSearchedControls
.at(pfriWhere
->nFieldPos
);
2301 m_pShell
->GetFormView()->UnMarkAll(m_pShell
->GetFormView()->GetSdrPageView());
2302 m_pShell
->GetFormView()->MarkObj(pObject
, m_pShell
->GetFormView()->GetSdrPageView());
2304 FmFormObj
* pFormObject
= FmFormObj::GetFormObject( pObject
);
2305 Reference
< XControlModel
> xControlModel( pFormObject
? pFormObject
->GetUnoControlModel() : Reference
< XControlModel
>() );
2306 DBG_ASSERT( xControlModel
.is(), "FmXFormShell::OnFoundData: invalid control!" );
2307 if ( !xControlModel
.is() )
2310 // disable the permanent cursor for the last grid we found a record
2311 if (m_xLastGridFound
.is() && (m_xLastGridFound
!= xControlModel
))
2313 Reference
< XPropertySet
> xOldSet(m_xLastGridFound
, UNO_QUERY
);
2314 xOldSet
->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR
, makeAny( (sal_Bool
)sal_False
) );
2315 Reference
< XPropertyState
> xOldSetState(xOldSet
, UNO_QUERY
);
2316 if (xOldSetState
.is())
2317 xOldSetState
->setPropertyToDefault(FM_PROP_CURSORCOLOR
);
2319 xOldSet
->setPropertyValue(FM_PROP_CURSORCOLOR
, Any());
2322 // wenn das Feld sich in einem GridControl befindet, muss ich dort noch in die entsprechende Spalte gehen
2323 sal_Int32 nGridColumn
= m_arrRelativeGridColumn
[pfriWhere
->nFieldPos
];
2324 if (nGridColumn
!= -1)
2325 { // dummer weise muss ich mir das Control erst wieder besorgen
2326 Reference
< XControl
> xControl( impl_getControl( xControlModel
, *pFormObject
) );
2327 Reference
< XGrid
> xGrid(xControl
, UNO_QUERY
);
2328 DBG_ASSERT(xGrid
.is(), "FmXFormShell::OnFoundData : ungueltiges Control !");
2329 // wenn eine der Asserts anschlaegt, habe ich beim Aufbauen von m_arrSearchedControls wohl was falsch gemacht
2331 // enable a permanent cursor for the grid so we can see the found text
2332 Reference
< XPropertySet
> xModelSet(xControlModel
, UNO_QUERY
);
2333 DBG_ASSERT(xModelSet
.is(), "FmXFormShell::OnFoundData : invalid control model (no property set) !");
2334 xModelSet
->setPropertyValue( FM_PROP_ALWAYSSHOWCURSOR
, makeAny( (sal_Bool
)sal_True
) );
2335 xModelSet
->setPropertyValue( FM_PROP_CURSORCOLOR
, makeAny( sal_Int32( COL_LIGHTRED
) ) );
2336 m_xLastGridFound
= xControlModel
;
2339 xGrid
->setCurrentColumnPosition((sal_Int16
)nGridColumn
);
2342 // als der Cursor neu positioniert wurde, habe ich (in positioned) meine Formularleisten-Slots invalidiert, aber das greift
2343 // hier dummerweise nicht, da i.A. ja der (modale) Suchdialog oben ist ... also Gewalt ...
2344 sal_uInt16 nPos
= 0;
2345 while (DatabaseSlotMap
[nPos
])
2346 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().Update(DatabaseSlotMap
[nPos
++]);
2347 // leider geht das Update im Gegensatz zum Invalidate nur mit einzelnen Slots)
2352 //------------------------------------------------------------------------------
2353 IMPL_LINK(FmXFormShell
, OnCanceledNotFound
, FmFoundRecordInformation
*, pfriWhere
)
2355 if ( impl_checkDisposed() )
2358 DBG_ASSERT((pfriWhere
->nContext
>= 0) && (pfriWhere
->nContext
< (sal_Int16
)m_aSearchForms
.size()),
2359 "FmXFormShell::OnCanceledNotFound : ungueltiger Kontext !");
2360 Reference
< XForm
> xForm( m_aSearchForms
.at(pfriWhere
->nContext
));
2361 DBG_ASSERT(xForm
.is(), "FmXFormShell::OnCanceledNotFound : ungueltige Form !");
2363 Reference
< XRowLocate
> xCursor(xForm
, UNO_QUERY
);
2365 return 0; // was soll ich da machen ?
2370 xCursor
->moveToBookmark(pfriWhere
->aPosition
);
2372 catch(const SQLException
&)
2374 OSL_FAIL("Can position on bookmark!");
2378 m_pShell
->GetFormView()->UnMarkAll(m_pShell
->GetFormView()->GetSdrPageView());
2382 //------------------------------------------------------------------------------
2383 IMPL_LINK(FmXFormShell
, OnSearchContextRequest
, FmSearchContext
*, pfmscContextInfo
)
2385 if ( impl_checkDisposed() )
2388 DBG_ASSERT(pfmscContextInfo
->nContext
< (sal_Int16
)m_aSearchForms
.size(), "FmXFormShell::OnSearchContextRequest : invalid parameter !");
2389 Reference
< XForm
> xForm( m_aSearchForms
.at(pfmscContextInfo
->nContext
));
2390 DBG_ASSERT(xForm
.is(), "FmXFormShell::OnSearchContextRequest : unexpected : invalid context !");
2392 Reference
< XResultSet
> xIter(xForm
, UNO_QUERY
);
2393 DBG_ASSERT(xIter
.is(), "FmXFormShell::OnSearchContextRequest : unexpected : context has no iterator !");
2395 // --------------------------------------------------------------------------------------------
2396 // assemble the list of fields to involve (that is, the ControlSources of all fields that have such a property)
2397 OUString strFieldList
, sFieldDisplayNames
;
2398 m_arrSearchedControls
.clear();
2399 m_arrRelativeGridColumn
.clear();
2401 // small problem: To mark found fields, I need SdrObjects. To determine which controls
2402 // to include in the search, I need Controls (that is, XControl interfaces). So I have
2403 // to iterate over one of them and get the other in some way. Unfortunately, there is
2404 // no direct connexion between the two worlds (except from a GetUnoControl to a
2405 // SdrUnoObject, but this requires an OutputDevice I can not do anything with.
2406 // However I can get to the Model from the Control and also from the SdrObject, and in
2407 // this way the assignment SdrObject<->Control is possible with a double loop.
2408 // The alternative to this (ugly but certainly not entirely fixable) solution would be
2409 // to renounce the caching of the SdrObjects, which would lead to significant extra
2410 // work in OnFoundData (since there I'd have to get the SdrObject first thing every
2411 // time). But since OnFoundData is usually called more often than ExecuteSeearch, I'll
2414 Reference
< XNameAccess
> xValidFormFields
;
2415 Reference
< XColumnsSupplier
> xSupplyCols(xIter
, UNO_QUERY
);
2416 DBG_ASSERT(xSupplyCols
.is(), "FmXFormShell::OnSearchContextRequest : invalid cursor : no columns supplier !");
2417 if (xSupplyCols
.is())
2418 xValidFormFields
= xSupplyCols
->getColumns();
2419 DBG_ASSERT(xValidFormFields
.is(), "FmXFormShell::OnSearchContextRequest : form has no fields !");
2421 // current Page/Controller
2422 FmFormPage
* pCurrentPage
= m_pShell
->GetCurPage();
2423 DBG_ASSERT(pCurrentPage
!=NULL
, "FmXFormShell::OnSearchContextRequest : no page !");
2424 // Search all SdrControls of this page...
2425 OUString sControlSource
, aName
;
2427 SdrObjListIter
aPageIter( *pCurrentPage
);
2428 while ( aPageIter
.IsMore() )
2430 SdrObject
* pCurrent
= aPageIter
.Next();
2431 FmFormObj
* pFormObject
= FmFormObj::GetFormObject( pCurrent
);
2432 // note that in case pCurrent is a virtual object, pFormObject points to the referenced object
2437 // the current object's model, in different tastes
2438 Reference
< XControlModel
> xControlModel( pFormObject
->GetUnoControlModel() );
2439 Reference
< XFormComponent
> xCurrentFormComponent( xControlModel
, UNO_QUERY
);
2440 DBG_ASSERT( xCurrentFormComponent
.is(), "FmXFormShell::OnSearchContextRequest: invalid objects!" );
2441 if ( !xCurrentFormComponent
.is() )
2444 // does the component belong to the form which we're interested in?
2445 if ( xCurrentFormComponent
->getParent() != xForm
)
2448 // ... ask for the ControlSource property
2449 SearchableControlIterator
iter( xCurrentFormComponent
);
2450 Reference
< XControl
> xControl
;
2451 // the control that has model xControlModel
2452 // (the following while can be passed through several times, without the Control
2453 // being modified, so I don't have to search every time from scratch)
2455 Reference
< XInterface
> xSearchable( iter
.Next() );
2456 while ( xSearchable
.is() )
2458 sControlSource
= iter
.getCurrentValue();
2459 if ( sControlSource
.isEmpty() )
2461 // the current element has no ControlSource, so it is a GridControl (that
2462 // is the only thing that still permits the SearchableControlIteratore)
2463 xControl
= impl_getControl( xControlModel
, *pFormObject
);
2464 DBG_ASSERT(xControl
.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
2466 Reference
< XGridPeer
> xGridPeer
;
2467 if ( xControl
.is() )
2468 xGridPeer
.set( xControl
->getPeer(), UNO_QUERY
);
2471 if (!xGridPeer
.is())
2474 Reference
< XIndexAccess
> xPeerContainer(xGridPeer
, UNO_QUERY
);
2475 if (!xPeerContainer
.is())
2478 Reference
< XIndexAccess
> xModelColumns(xGridPeer
->getColumns(), UNO_QUERY
);
2479 DBG_ASSERT(xModelColumns
.is(), "FmXFormShell::OnSearchContextRequest : there is a grid control without columns !");
2480 // the case 'no columns' should be indicated with an empty container, I think ...
2481 DBG_ASSERT(xModelColumns
->getCount() >= xPeerContainer
->getCount(), "FmXFormShell::OnSearchContextRequest : impossible : have more view than model columns !");
2483 Reference
< XInterface
> xCurrentColumn
;
2484 for (sal_Int16 nViewPos
=0; nViewPos
<xPeerContainer
->getCount(); ++nViewPos
)
2486 xPeerContainer
->getByIndex(nViewPos
) >>= xCurrentColumn
;
2487 if (!xCurrentColumn
.is())
2490 // can we use this column control for searching ?
2491 if (!IsSearchableControl(xCurrentColumn
))
2494 sal_Int16 nModelPos
= GridView2ModelPos(xModelColumns
, nViewPos
);
2495 Reference
< XPropertySet
> xCurrentColModel
;
2496 xModelColumns
->getByIndex(nModelPos
) >>= xCurrentColModel
;
2497 aName
= ::comphelper::getString(xCurrentColModel
->getPropertyValue(FM_PROP_CONTROLSOURCE
));
2498 // the cursor has a field matching the control source ?
2499 if (xValidFormFields
->hasByName(aName
))
2501 strFieldList
= strFieldList
+ OUString(aName
.getStr()) + ";";
2503 sFieldDisplayNames
= sFieldDisplayNames
+
2504 OUString(::comphelper::getString(xCurrentColModel
->getPropertyValue(FM_PROP_LABEL
)).getStr()) +
2507 pfmscContextInfo
->arrFields
.push_back(xCurrentColumn
);
2509 // and the SdrOject to the Field
2510 m_arrSearchedControls
.push_back(pCurrent
);
2511 // the number of the column
2512 m_arrRelativeGridColumn
.push_back(nViewPos
);
2519 if (!sControlSource
.isEmpty() && xValidFormFields
->hasByName(sControlSource
))
2521 // now I need the Control to SdrObject
2524 xControl
= impl_getControl( xControlModel
, *pFormObject
);
2525 DBG_ASSERT(xControl
.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
2528 if (IsSearchableControl(xControl
))
2530 // all tests passed -> take along in the list
2531 strFieldList
= strFieldList
+ OUString(sControlSource
.getStr()) + ";";
2533 // the label which should appear for the control :
2534 sFieldDisplayNames
= sFieldDisplayNames
+
2535 OUString(getLabelName(Reference
< XPropertySet
>(xControlModel
, UNO_QUERY
)).getStr()) +
2538 // mark the SdrObject (accelerates the treatment in OnFoundData)
2539 m_arrSearchedControls
.push_back(pCurrent
);
2541 // the number of the colum (here a dummy, since it is only interesting for GridControls)
2542 m_arrRelativeGridColumn
.push_back(-1);
2544 // and for the formatted search...
2545 pfmscContextInfo
->arrFields
.push_back(Reference
< XInterface
>(xControl
, UNO_QUERY
));
2550 xSearchable
= iter
.Next();
2554 strFieldList
= comphelper::string::stripEnd(strFieldList
, ';');
2555 sFieldDisplayNames
= comphelper::string::stripEnd(sFieldDisplayNames
, ';');
2557 if (pfmscContextInfo
->arrFields
.empty())
2559 pfmscContextInfo
->arrFields
.clear();
2560 pfmscContextInfo
->xCursor
= NULL
;
2561 pfmscContextInfo
->strUsedFields
.Erase();
2565 pfmscContextInfo
->xCursor
= xIter
;
2566 pfmscContextInfo
->strUsedFields
= strFieldList
;
2567 pfmscContextInfo
->sFieldDisplayNames
= sFieldDisplayNames
;
2569 // 66463 - 31.05.99 - FS
2570 // when the cursor is a non-STANDARD RecordMode, set it back
2571 Reference
< XPropertySet
> xCursorSet(pfmscContextInfo
->xCursor
, UNO_QUERY
);
2572 Reference
< XResultSetUpdate
> xUpdateCursor(pfmscContextInfo
->xCursor
, UNO_QUERY
);
2573 if (xUpdateCursor
.is() && xCursorSet
.is() && xCursorSet
.is())
2575 if (::comphelper::getBOOL(xCursorSet
->getPropertyValue(FM_PROP_ISNEW
)))
2576 xUpdateCursor
->moveToCurrentRow();
2577 else if (::comphelper::getBOOL(xCursorSet
->getPropertyValue(FM_PROP_ISMODIFIED
)))
2578 xUpdateCursor
->cancelRowUpdates();
2581 return pfmscContextInfo
->arrFields
.size();
2584 // XContainerListener
2585 //------------------------------------------------------------------------------
2586 void FmXFormShell::elementInserted(const ContainerEvent
& evt
) throw(::com::sun::star::uno::RuntimeException
)
2588 if ( impl_checkDisposed() )
2591 // new object to listen to
2592 Reference
< XInterface
> xTemp
;
2593 evt
.Element
>>= xTemp
;
2595 m_pShell
->DetermineForms(sal_True
);
2598 //------------------------------------------------------------------------------
2599 void FmXFormShell::elementReplaced(const ContainerEvent
& evt
) throw(::com::sun::star::uno::RuntimeException
)
2601 if ( impl_checkDisposed() )
2604 Reference
< XInterface
> xTemp
;
2605 evt
.ReplacedElement
>>= xTemp
;
2606 RemoveElement(xTemp
);
2607 evt
.Element
>>= xTemp
;
2611 //------------------------------------------------------------------------------
2612 void FmXFormShell::elementRemoved(const ContainerEvent
& evt
) throw(::com::sun::star::uno::RuntimeException
)
2614 if ( impl_checkDisposed() )
2617 Reference
< XInterface
> xTemp
;
2618 evt
.Element
>>= xTemp
;
2619 RemoveElement(xTemp
);
2620 m_pShell
->DetermineForms(sal_True
);
2623 //------------------------------------------------------------------------------
2624 void FmXFormShell::UpdateForms( sal_Bool _bInvalidate
)
2626 if ( impl_checkDisposed() )
2629 Reference
< XIndexAccess
> xForms
;
2631 FmFormPage
* pPage
= m_pShell
->GetCurPage();
2634 if ( m_pShell
->m_bDesignMode
)
2635 xForms
= xForms
.query( pPage
->GetForms( false ) );
2638 if ( m_xForms
!= xForms
)
2640 RemoveElement( m_xForms
);
2642 AddElement( m_xForms
);
2645 m_pShell
->DetermineForms( _bInvalidate
);
2648 //------------------------------------------------------------------------------
2649 void FmXFormShell::AddElement(const Reference
< XInterface
>& _xElement
)
2651 if ( impl_checkDisposed() )
2653 impl_AddElement_nothrow(_xElement
);
2655 // -----------------------------------------------------------------------------
2656 void FmXFormShell::impl_AddElement_nothrow(const Reference
< XInterface
>& Element
)
2658 // am Container horchen
2659 const Reference
< XIndexContainer
> xContainer(Element
, UNO_QUERY
);
2660 if (xContainer
.is())
2662 const sal_uInt32 nCount
= xContainer
->getCount();
2663 Reference
< XInterface
> xElement
;
2664 for (sal_uInt32 i
= 0; i
< nCount
; ++i
)
2666 xElement
.set(xContainer
->getByIndex(i
),UNO_QUERY
);
2667 impl_AddElement_nothrow(xElement
);
2670 const Reference
< XContainer
> xCont(Element
, UNO_QUERY
);
2672 xCont
->addContainerListener(this);
2675 const Reference
< ::com::sun::star::view::XSelectionSupplier
> xSelSupplier(Element
, UNO_QUERY
);
2676 if (xSelSupplier
.is())
2677 xSelSupplier
->addSelectionChangeListener(this);
2680 //------------------------------------------------------------------------------
2681 void FmXFormShell::RemoveElement(const Reference
< XInterface
>& Element
)
2683 if ( impl_checkDisposed() )
2685 impl_RemoveElement_nothrow(Element
);
2687 //------------------------------------------------------------------------------
2688 void FmXFormShell::impl_RemoveElement_nothrow(const Reference
< XInterface
>& Element
)
2690 const Reference
< ::com::sun::star::view::XSelectionSupplier
> xSelSupplier(Element
, UNO_QUERY
);
2691 if (xSelSupplier
.is())
2692 xSelSupplier
->removeSelectionChangeListener(this);
2694 // remove connection to children
2695 const Reference
< XIndexContainer
> xContainer(Element
, UNO_QUERY
);
2696 if (xContainer
.is())
2698 const Reference
< XContainer
> xCont(Element
, UNO_QUERY
);
2700 xCont
->removeContainerListener(this);
2702 const sal_uInt32 nCount
= xContainer
->getCount();
2703 Reference
< XInterface
> xElement
;
2704 for (sal_uInt32 i
= 0; i
< nCount
; i
++)
2706 xElement
.set(xContainer
->getByIndex(i
),UNO_QUERY
);
2707 impl_RemoveElement_nothrow(xElement
);
2711 InterfaceBag::iterator wasSelectedPos
= m_aCurrentSelection
.find( Element
);
2712 if ( wasSelectedPos
!= m_aCurrentSelection
.end() )
2713 m_aCurrentSelection
.erase( wasSelectedPos
);
2716 //------------------------------------------------------------------------------
2717 void FmXFormShell::selectionChanged(const EventObject
& rEvent
) throw(::com::sun::star::uno::RuntimeException
)
2719 if ( impl_checkDisposed() )
2722 Reference
< XSelectionSupplier
> xSupplier( rEvent
.Source
, UNO_QUERY
);
2723 Reference
< XInterface
> xSelObj( xSupplier
->getSelection(), UNO_QUERY
);
2724 // a selection was removed, this can only be done by the shell
2725 if ( !xSelObj
.is() )
2728 EnableTrackProperties(sal_False
);
2730 sal_Bool bMarkChanged
= m_pShell
->GetFormView()->checkUnMarkAll(rEvent
.Source
);
2731 Reference
< XForm
> xNewForm( GetForm( rEvent
.Source
) );
2733 InterfaceBag aNewSelection
;
2734 aNewSelection
.insert( Reference
< XInterface
>( xSelObj
, UNO_QUERY
) );
2736 if ( setCurrentSelection( aNewSelection
) && IsPropBrwOpen() )
2737 ShowSelectionProperties( sal_True
);
2739 EnableTrackProperties(sal_True
);
2742 m_pShell
->NotifyMarkListChanged( m_pShell
->GetFormView() );
2745 //------------------------------------------------------------------------------
2746 IMPL_LINK(FmXFormShell
, OnTimeOut
, void*, /*EMPTYTAG*/)
2748 if ( impl_checkDisposed() )
2751 if (m_pShell
->IsDesignMode() && m_pShell
->GetFormView())
2752 SetSelection(m_pShell
->GetFormView()->GetMarkedObjectList());
2757 //------------------------------------------------------------------------
2758 void FmXFormShell::SetSelectionDelayed()
2760 if ( impl_checkDisposed() )
2763 if (m_pShell
->IsDesignMode() && IsTrackPropertiesEnabled() && !m_aMarkTimer
.IsActive())
2764 m_aMarkTimer
.Start();
2767 //------------------------------------------------------------------------
2768 void FmXFormShell::SetSelection(const SdrMarkList
& rMarkList
)
2770 if ( impl_checkDisposed() )
2773 DetermineSelection(rMarkList
);
2774 m_pShell
->NotifyMarkListChanged(m_pShell
->GetFormView());
2777 //------------------------------------------------------------------------
2778 void FmXFormShell::DetermineSelection(const SdrMarkList
& rMarkList
)
2780 if ( setCurrentSelectionFromMark( rMarkList
) && IsPropBrwOpen() )
2781 ShowSelectionProperties( sal_True
);
2784 //------------------------------------------------------------------------------
2785 sal_Bool
FmXFormShell::IsPropBrwOpen() const
2787 if ( impl_checkDisposed() )
2790 return( ( m_pShell
->GetViewShell() && m_pShell
->GetViewShell()->GetViewFrame() ) ?
2791 m_pShell
->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES
) : sal_False
);
2794 //------------------------------------------------------------------------------
2795 class FmXFormShell::SuspendPropertyTracking
2798 FmXFormShell
& m_rShell
;
2799 sal_Bool m_bEnabled
;
2802 SuspendPropertyTracking( FmXFormShell
& _rShell
)
2803 :m_rShell( _rShell
)
2804 ,m_bEnabled( sal_False
)
2806 if ( m_rShell
.IsTrackPropertiesEnabled() )
2808 m_rShell
.EnableTrackProperties( sal_False
);
2809 m_bEnabled
= sal_True
;
2813 ~SuspendPropertyTracking( )
2815 if ( m_bEnabled
) // note that ( sal_False != m_bEnabled ) implies ( NULL != m_pShell )
2816 m_rShell
.EnableTrackProperties( sal_True
);
2820 //------------------------------------------------------------------------------
2821 void FmXFormShell::SetDesignMode(sal_Bool bDesign
)
2823 if ( impl_checkDisposed() )
2826 DBG_ASSERT(m_pShell
->GetFormView(), "FmXFormShell::SetDesignMode : invalid call (have no shell or no view) !");
2827 m_bChangingDesignMode
= sal_True
;
2829 // 67506 - 15.07.99 - FS
2830 // if we're switching off the design mode we have to force the property browser to be closed
2831 // so it can commit it's changes _before_ we load the forms
2834 m_bHadPropertyBrowserInDesignMode
= m_pShell
->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES
);
2835 if (m_bHadPropertyBrowserInDesignMode
)
2836 m_pShell
->GetViewShell()->GetViewFrame()->ToggleChildWindow(SID_FM_SHOW_PROPERTIES
);
2839 FmFormView
* pFormView
= m_pShell
->GetFormView();
2842 // we are currently filtering, so stop filtering
2844 stopFiltering(sal_False
);
2846 // unsubscribe from the objects of my MarkList
2847 pFormView
->GetImpl()->stopMarkListWatching();
2851 m_aMarkTimer
.Stop();
2853 SuspendPropertyTracking
aSuspend( *this );
2854 pFormView
->GetImpl()->saveMarkList( sal_True
);
2857 if (bDesign
&& m_xExternalViewController
.is())
2858 CloseExternalFormViewer();
2860 pFormView
->ChangeDesignMode(bDesign
);
2862 // notify listensers
2863 FmDesignModeChangedHint
aChangedHint( bDesign
);
2864 m_pShell
->Broadcast(aChangedHint
);
2866 m_pShell
->m_bDesignMode
= bDesign
;
2867 UpdateForms( sal_False
);
2869 m_pTextShell
->designModeChanged( m_pShell
->m_bDesignMode
);
2875 // during changing the mark list, don't track the selected objects in the property browser
2876 SuspendPropertyTracking
aSuspend( *this );
2877 // restore the marks
2878 pFormView
->GetImpl()->restoreMarkList( aList
);
2881 // synchronize with the restored mark list
2882 if ( aList
.GetMarkCount() )
2883 SetSelection( aList
);
2887 // subscribe to the model of the view (so that I'm informed when someone deletes
2888 // during the alive mode controls that I had saved in the saveMarklist (60343)
2889 pFormView
->GetImpl()->startMarkListWatching();
2892 m_pShell
->UIFeatureChanged();
2894 // 67506 - 15.07.99 - FS
2895 if (bDesign
&& m_bHadPropertyBrowserInDesignMode
)
2897 // The UIFeatureChanged performes an update (a check of the available features) asynchronously.
2898 // So we can't call ShowSelectionProperties directly as the according feature isn't enabled yet.
2899 // That's why we use an asynchron execution on the dispatcher.
2900 // (And that's why this has to be done AFTER the UIFeatureChanged.)
2901 m_pShell
->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER
, SFX_CALLMODE_ASYNCHRON
);
2903 m_bChangingDesignMode
= sal_False
;
2906 //------------------------------------------------------------------------------
2907 Reference
< XControl
> FmXFormShell::impl_getControl( const Reference
< XControlModel
>& i_rxModel
, const FmFormObj
& i_rKnownFormObj
)
2909 if ( impl_checkDisposed() )
2912 Reference
< XControl
> xControl
;
2915 Reference
< XControlContainer
> xControlContainer( getControlContainerForView(), UNO_SET_THROW
);
2917 Sequence
< Reference
< XControl
> > seqControls( xControlContainer
->getControls() );
2918 const Reference
< XControl
>* pControls
= seqControls
.getArray();
2919 // ... that I can then search
2920 for (sal_Int32 i
=0; i
<seqControls
.getLength(); ++i
)
2922 xControl
.set( pControls
[i
], UNO_SET_THROW
);
2923 Reference
< XControlModel
> xCurrentModel( xControl
->getModel() );
2924 if ( xCurrentModel
== i_rxModel
)
2929 if ( !xControl
.is() )
2931 // fallabck (some controls might not have been created, yet, since they were never visible so far)
2932 Reference
< XControl
> xContainerControl( xControlContainer
, UNO_QUERY_THROW
);
2933 const Window
* pContainerWindow
= VCLUnoHelper::GetWindow( xContainerControl
->getPeer() );
2934 ENSURE_OR_THROW( pContainerWindow
, "unexpected control container implementation" );
2936 const SdrView
* pSdrView
= m_pShell
? m_pShell
->GetFormView() : NULL
;
2937 ENSURE_OR_THROW( pSdrView
, "no current view" );
2939 xControl
.set( i_rKnownFormObj
.GetUnoControl( *pSdrView
, *pContainerWindow
), UNO_QUERY_THROW
);
2942 catch( const Exception
& )
2944 DBG_UNHANDLED_EXCEPTION();
2947 OSL_ENSURE( xControl
.is(), "FmXFormShell::impl_getControl: no control found!" );
2951 //------------------------------------------------------------------------------
2952 void FmXFormShell::impl_collectFormSearchContexts_nothrow( const Reference
< XInterface
>& _rxStartingPoint
,
2953 const OUString
& _rCurrentLevelPrefix
, FmFormArray
& _out_rForms
, ::std::vector
< OUString
>& _out_rNames
)
2957 Reference
< XIndexAccess
> xContainer( _rxStartingPoint
, UNO_QUERY
);
2958 if ( !xContainer
.is() )
2961 sal_Int32
nCount( xContainer
->getCount() );
2965 OUString sCurrentFormName
;
2966 OUStringBuffer aNextLevelPrefix
;
2967 for ( sal_Int32 i
=0; i
<nCount
; ++i
)
2969 // is the current child a form?
2970 Reference
< XForm
> xCurrentAsForm( xContainer
->getByIndex(i
), UNO_QUERY
);
2971 if ( !xCurrentAsForm
.is() )
2974 Reference
< XNamed
> xNamed( xCurrentAsForm
, UNO_QUERY_THROW
);
2975 sCurrentFormName
= xNamed
->getName();
2977 // the name of the current form
2978 OUStringBuffer
sCompleteCurrentName( sCurrentFormName
);
2979 if ( !_rCurrentLevelPrefix
.isEmpty() )
2981 sCompleteCurrentName
.appendAscii( " (" );
2982 sCompleteCurrentName
.append ( _rCurrentLevelPrefix
);
2983 sCompleteCurrentName
.appendAscii( ")" );
2986 // the prefix for the next level
2987 aNextLevelPrefix
= _rCurrentLevelPrefix
;
2988 if ( !_rCurrentLevelPrefix
.isEmpty() )
2989 aNextLevelPrefix
.append( (sal_Unicode
)'/' );
2990 aNextLevelPrefix
.append( sCurrentFormName
);
2992 // remember both the form and it's "display name"
2993 _out_rForms
.push_back( xCurrentAsForm
);
2994 _out_rNames
.push_back( sCompleteCurrentName
.makeStringAndClear() );
2997 impl_collectFormSearchContexts_nothrow( xCurrentAsForm
, aNextLevelPrefix
.makeStringAndClear(), _out_rForms
, _out_rNames
);
3000 catch( const Exception
& )
3002 DBG_UNHANDLED_EXCEPTION();
3006 //------------------------------------------------------------------------------
3007 void FmXFormShell::startFiltering()
3009 if ( impl_checkDisposed() )
3012 // setting all forms in filter mode
3013 FmXFormView
* pXView
= m_pShell
->GetFormView()->GetImpl();
3015 // if the active controller is our external one we have to use the trigger controller
3016 Reference
< XControlContainer
> xContainer
;
3017 if (getActiveController() == m_xExternalViewController
)
3019 DBG_ASSERT(m_xExtViewTriggerController
.is(), "FmXFormShell::startFiltering : inconsistent : active external controller, but noone triggered this !");
3020 xContainer
= m_xExtViewTriggerController
->getContainer();
3023 xContainer
= getActiveController()->getContainer();
3025 PFormViewPageWindowAdapter pAdapter
= pXView
->findWindow( xContainer
);
3026 if ( pAdapter
.is() )
3028 const ::std::vector
< Reference
< runtime::XFormController
> >& rControllerList
= pAdapter
->GetList();
3029 for ( ::std::vector
< Reference
< runtime::XFormController
> >::const_iterator j
= rControllerList
.begin();
3030 j
!= rControllerList
.end();
3034 Reference
< XModeSelector
> xModeSelector(*j
, UNO_QUERY
);
3035 if (xModeSelector
.is())
3036 xModeSelector
->setMode( OUString( "FilterMode" ) );
3040 m_bFilterMode
= sal_True
;
3042 m_pShell
->UIFeatureChanged();
3043 SfxViewFrame
* pViewFrame
= m_pShell
->GetViewShell()->GetViewFrame();
3044 pViewFrame
->GetBindings().InvalidateShell( *m_pShell
);
3046 if ( pViewFrame
->KnowsChildWindow( SID_FM_FILTER_NAVIGATOR
)
3047 && !pViewFrame
->HasChildWindow( SID_FM_FILTER_NAVIGATOR
)
3050 pViewFrame
->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR
);
3054 //------------------------------------------------------------------------------
3055 void saveFilter(const Reference
< runtime::XFormController
>& _rxController
)
3057 Reference
< XPropertySet
> xFormAsSet(_rxController
->getModel(), UNO_QUERY
);
3058 Reference
< XPropertySet
> xControllerAsSet(_rxController
, UNO_QUERY
);
3059 Reference
< XIndexAccess
> xControllerAsIndex(_rxController
, UNO_QUERY
);
3061 // call the subcontroller
3062 Reference
< runtime::XFormController
> xController
;
3063 for (sal_Int32 i
= 0, nCount
= xControllerAsIndex
->getCount(); i
< nCount
; ++i
)
3065 xControllerAsIndex
->getByIndex(i
) >>= xController
;
3066 saveFilter(xController
);
3072 xFormAsSet
->setPropertyValue(FM_PROP_FILTER
, xControllerAsSet
->getPropertyValue(FM_PROP_FILTER
));
3073 xFormAsSet
->setPropertyValue(FM_PROP_APPLYFILTER
, makeAny( (sal_Bool
)sal_True
) );
3075 catch (const Exception
& )
3077 DBG_UNHANDLED_EXCEPTION();
3082 //------------------------------------------------------------------------------
3083 void FmXFormShell::stopFiltering(sal_Bool bSave
)
3085 if ( impl_checkDisposed() )
3088 m_bFilterMode
= sal_False
;
3090 FmXFormView
* pXView
= m_pShell
->GetFormView()->GetImpl();
3092 // if the active controller is our external one we have to use the trigger controller
3093 Reference
< XControlContainer
> xContainer
;
3094 if (getActiveController() == m_xExternalViewController
)
3096 DBG_ASSERT(m_xExtViewTriggerController
.is(), "FmXFormShell::stopFiltering : inconsistent : active external controller, but noone triggered this !");
3097 xContainer
= m_xExtViewTriggerController
->getContainer();
3100 xContainer
= getActiveController()->getContainer();
3102 PFormViewPageWindowAdapter pAdapter
= pXView
->findWindow(xContainer
);
3103 if ( pAdapter
.is() )
3105 const ::std::vector
< Reference
< runtime::XFormController
> >& rControllerList
= pAdapter
->GetList();
3106 ::std::vector
< OUString
> aOriginalFilters
;
3107 ::std::vector
< sal_Bool
> aOriginalApplyFlags
;
3111 for (::std::vector
< Reference
< runtime::XFormController
> > ::const_iterator j
= rControllerList
.begin();
3112 j
!= rControllerList
.end(); ++j
)
3115 { // remember the current filter settings in case we're goin to reload the forms below (which may fail)
3118 Reference
< XPropertySet
> xFormAsSet((*j
)->getModel(), UNO_QUERY
);
3119 aOriginalFilters
.push_back(::comphelper::getString(xFormAsSet
->getPropertyValue(FM_PROP_FILTER
)));
3120 aOriginalApplyFlags
.push_back(::comphelper::getBOOL(xFormAsSet
->getPropertyValue(FM_PROP_APPLYFILTER
)));
3124 OSL_FAIL("FmXFormShell::stopFiltering : could not get the original filter !");
3125 // put dummies into the arrays so the they have the right size
3127 if (aOriginalFilters
.size() == aOriginalApplyFlags
.size())
3128 // the first getPropertyValue failed -> use two dummies
3129 aOriginalFilters
.push_back( OUString() );
3130 aOriginalApplyFlags
.push_back( sal_False
);
3136 for (::std::vector
< Reference
< runtime::XFormController
> > ::const_iterator j
= rControllerList
.begin();
3137 j
!= rControllerList
.end(); ++j
)
3140 Reference
< XModeSelector
> xModeSelector(*j
, UNO_QUERY
);
3141 if (xModeSelector
.is())
3142 xModeSelector
->setMode( OUString( "DataMode" ) );
3144 if (bSave
) // execute the filter
3146 const ::std::vector
< Reference
< runtime::XFormController
> > & rControllers
= pAdapter
->GetList();
3147 for (::std::vector
< Reference
< runtime::XFormController
> > ::const_iterator j
= rControllers
.begin();
3148 j
!= rControllers
.end(); ++j
)
3150 Reference
< XLoadable
> xReload((*j
)->getModel(), UNO_QUERY
);
3153 Reference
< XPropertySet
> xFormSet(xReload
, UNO_QUERY
);
3161 OSL_FAIL("FmXFormShell::stopFiltering: Exception occurred!");
3164 if (!isRowSetAlive(xFormSet
))
3165 { // something went wrong -> restore the original state
3166 OUString sOriginalFilter
= aOriginalFilters
[ j
- rControllers
.begin() ];
3167 sal_Bool bOriginalApplyFlag
= aOriginalApplyFlags
[ j
- rControllers
.begin() ];
3170 xFormSet
->setPropertyValue(FM_PROP_FILTER
, makeAny(sOriginalFilter
));
3171 xFormSet
->setPropertyValue(FM_PROP_APPLYFILTER
, makeAny(bOriginalApplyFlag
));
3174 catch(const Exception
&)
3176 DBG_UNHANDLED_EXCEPTION();
3183 m_pShell
->UIFeatureChanged();
3184 m_pShell
->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell
);
3187 //------------------------------------------------------------------------------
3188 void FmXFormShell::CreateExternalView()
3190 if ( impl_checkDisposed() )
3193 DBG_ASSERT(m_xAttachedFrame
.is(), "FmXFormShell::CreateExternalView : no frame !");
3195 // the frame the external view is displayed in
3196 sal_Bool bAlreadyExistent
= m_xExternalViewController
.is();
3197 Reference
< ::com::sun::star::frame::XFrame
> xExternalViewFrame
;
3198 OUString
sFrameName("_beamer");
3199 sal_Int32 nSearchFlags
= ::com::sun::star::frame::FrameSearchFlag::CHILDREN
| ::com::sun::star::frame::FrameSearchFlag::CREATE
;
3201 Reference
< runtime::XFormController
> xCurrentNavController( getNavController());
3202 // the creation of the "partwindow" may cause a deactivate of the document which will result in our nav controller to be set to NULL
3204 // _first_ check if we have any valid fields we can use for the grid view
3205 // FS - 21.10.99 - 69219
3207 FmXBoundFormFieldIterator
aModelIterator(xCurrentNavController
->getModel());
3208 Reference
< XPropertySet
> xCurrentModelSet
;
3209 sal_Bool bHaveUsableControls
= sal_False
;
3210 while ((xCurrentModelSet
= Reference
< XPropertySet
>(aModelIterator
.Next(), UNO_QUERY
)).is())
3212 // the FmXBoundFormFieldIterator only supplies controls with a valid control source
3213 // so we just have to check the field type
3214 sal_Int16 nClassId
= ::comphelper::getINT16(xCurrentModelSet
->getPropertyValue(FM_PROP_CLASSID
));
3217 case FormComponentType::IMAGECONTROL
:
3218 case FormComponentType::CONTROL
:
3221 bHaveUsableControls
= sal_True
;
3225 if (!bHaveUsableControls
)
3227 ErrorBox(NULL
, WB_OK
, SVX_RESSTR(RID_STR_NOCONTROLS_FOR_EXTERNALDISPLAY
)).Execute();
3232 // load the component for external form views
3233 if (!bAlreadyExistent
)
3235 URL aWantToDispatch
;
3236 aWantToDispatch
.Complete
= FMURL_COMPONENT_FORMGRIDVIEW
;
3238 Reference
< ::com::sun::star::frame::XDispatchProvider
> xProv(m_xAttachedFrame
, UNO_QUERY
);
3239 Reference
< ::com::sun::star::frame::XDispatch
> xDisp
;
3241 xDisp
= xProv
->queryDispatch(aWantToDispatch
, sFrameName
, nSearchFlags
);
3244 xDisp
->dispatch(aWantToDispatch
, Sequence
< PropertyValue
>());
3247 // with this the component should be loaded, now search the frame where it resides in
3248 xExternalViewFrame
= m_xAttachedFrame
->findFrame(sFrameName
, ::com::sun::star::frame::FrameSearchFlag::CHILDREN
);
3249 if (xExternalViewFrame
.is())
3251 m_xExternalViewController
= xExternalViewFrame
->getController();
3252 Reference
< ::com::sun::star::lang::XComponent
> xComp(m_xExternalViewController
, UNO_QUERY
);
3254 xComp
->addEventListener((XEventListener
*)(XPropertyChangeListener
*)this);
3259 xExternalViewFrame
= m_xExternalViewController
->getFrame();
3260 Reference
< ::com::sun::star::frame::XDispatchProvider
> xCommLink(xExternalViewFrame
, UNO_QUERY
);
3262 // if we display the active form we interpret the slot as "remove it"
3263 Reference
< XForm
> xCurrentModel(xCurrentNavController
->getModel(), UNO_QUERY
);
3264 if ((xCurrentModel
== m_xExternalDisplayedForm
) || (getInternalForm(xCurrentModel
) == m_xExternalDisplayedForm
))
3266 if ( m_xExternalViewController
== getActiveController() )
3268 Reference
< runtime::XFormController
> xAsFormController( m_xExternalViewController
, UNO_QUERY
);
3269 ControllerFeatures
aHelper( xAsFormController
, NULL
);
3270 aHelper
->commitCurrentControl();
3273 Reference
< runtime::XFormController
> xNewController(m_xExtViewTriggerController
);
3274 CloseExternalFormViewer();
3275 setActiveController(xNewController
);
3280 aClearURL
.Complete
= FMURL_GRIDVIEW_CLEARVIEW
;
3282 Reference
< ::com::sun::star::frame::XDispatch
> xClear( xCommLink
->queryDispatch(aClearURL
, OUString(), 0));
3284 xClear
->dispatch(aClearURL
, Sequence
< PropertyValue
>());
3287 // TODO: We need an interceptor at the xSupplier, which forwards all queryDispatch requests to the FormController
3288 // instance for which this "external view" was triggered
3290 // get the dispatch interface of the frame so we can communicate (interceptable) with the controller
3291 Reference
< ::com::sun::star::frame::XDispatchProvider
> xCommLink(xExternalViewFrame
, UNO_QUERY
);
3293 if (m_xExternalViewController
.is())
3295 DBG_ASSERT(xCommLink
.is(), "FmXFormShell::CreateExternalView : the component doesn't have the necessary interfaces !");
3296 // collect the dispatchers we will need
3298 aAddColumnURL
.Complete
= FMURL_GRIDVIEW_ADDCOLUMN
;
3299 Reference
< ::com::sun::star::frame::XDispatch
> xAddColumnDispatch( xCommLink
->queryDispatch(aAddColumnURL
, OUString(), 0));
3301 aAttachURL
.Complete
= FMURL_GRIDVIEW_ATTACHTOFORM
;
3302 Reference
< ::com::sun::star::frame::XDispatch
> xAttachDispatch( xCommLink
->queryDispatch(aAttachURL
, OUString(), 0));
3304 if (xAddColumnDispatch
.is() && xAttachDispatch
.is())
3306 DBG_ASSERT(xCurrentNavController
.is(), "FmXFormShell::CreateExternalView : invalid call : have no nav controller !");
3307 // first : dispatch the descriptions for the columns to add
3308 Sequence
< Reference
< XControl
> > aCurrentControls(xCurrentNavController
->getControls());
3310 sal_Int16 nAddedColumns
= 0;
3312 // for radio buttons we need some special structures
3313 typedef std::map
< OUString
, Sequence
< OUString
> > MapUString2UstringSeq
;
3314 typedef std::map
< OUString
, OUString
> FmMapUString2UString
;
3315 typedef std::map
< OUString
, sal_Int16
> FmMapUString2Int16
;
3317 MapUString2UstringSeq aRadioValueLists
;
3318 MapUString2UstringSeq aRadioListSources
;
3319 FmMapUString2UString aRadioControlSources
;
3320 FmMapUString2Int16 aRadioPositions
;
3322 FmXBoundFormFieldIterator
aModelIterator(xCurrentNavController
->getModel());
3323 Reference
< XPropertySet
> xCurrentModelSet
;
3324 Any aCurrentBoundField
;
3325 OUString sColumnType
,aGroupName
,sControlSource
;
3326 Sequence
< Property
> aProps
;
3327 Reference
< XPropertySet
> xCurrentBoundField
;
3328 while ((xCurrentModelSet
= Reference
< XPropertySet
>(aModelIterator
.Next(), UNO_QUERY
)).is())
3330 xCurrentModelSet
->getPropertyValue(FM_PROP_BOUNDFIELD
) >>= xCurrentBoundField
;
3331 OSL_ENSURE(xCurrentModelSet
.is(),"xCurrentModelSet is null!");
3332 // create a description of the column to be created
3333 // first : determine it's type
3335 sal_Int16 nClassId
= ::comphelper::getINT16(xCurrentModelSet
->getPropertyValue(FM_PROP_CLASSID
));
3338 case FormComponentType::RADIOBUTTON
:
3340 // get the label of the button (this is the access key for our structures)
3341 aGroupName
= getLabelName(xCurrentModelSet
);
3343 // add the reference value of the radio button to the list source sequence
3344 Sequence
< OUString
>& aThisGroupLabels
= aRadioListSources
[aGroupName
];
3345 sal_Int32 nNewSizeL
= aThisGroupLabels
.getLength() + 1;
3346 aThisGroupLabels
.realloc(nNewSizeL
);
3347 aThisGroupLabels
.getArray()[nNewSizeL
- 1] = ::comphelper::getString(xCurrentModelSet
->getPropertyValue(FM_PROP_REFVALUE
));
3349 // add the label to the value list sequence
3350 Sequence
< OUString
>& aThisGroupControlSources
= aRadioValueLists
[aGroupName
];
3351 sal_Int32 nNewSizeC
= aThisGroupControlSources
.getLength() + 1;
3352 aThisGroupControlSources
.realloc(nNewSizeC
);
3353 aThisGroupControlSources
.getArray()[nNewSizeC
- 1] = ::comphelper::getString(xCurrentModelSet
->getPropertyValue(FM_PROP_LABEL
));
3355 // remember the controls source of the radio group
3356 sControlSource
= ::comphelper::getString(xCurrentModelSet
->getPropertyValue(FM_PROP_CONTROLSOURCE
));
3357 if (aRadioControlSources
.find(aGroupName
) == aRadioControlSources
.end())
3358 aRadioControlSources
[aGroupName
] = sControlSource
;
3361 DBG_ASSERT(aRadioControlSources
[aGroupName
] == sControlSource
,
3362 "FmXFormShell::CreateExternalView : inconsistent radio buttons detected !");
3363 // (radio buttons with the same name should have the same control source)
3365 // remember the position within the columns
3366 if (aRadioPositions
.find(aGroupName
) == aRadioPositions
.end())
3367 aRadioPositions
[aGroupName
] = (sal_Int16
)nAddedColumns
;
3369 // any further handling is done below
3373 case FormComponentType::IMAGECONTROL
:
3374 case FormComponentType::CONTROL
:
3375 // no grid columns for these types (though they have a control source)
3377 case FormComponentType::CHECKBOX
:
3378 sColumnType
= FM_COL_CHECKBOX
; break;
3379 case FormComponentType::LISTBOX
:
3380 sColumnType
= FM_COL_LISTBOX
; break;
3381 case FormComponentType::COMBOBOX
:
3382 sColumnType
= FM_COL_COMBOBOX
; break;
3383 case FormComponentType::DATEFIELD
:
3384 sColumnType
= FM_COL_DATEFIELD
; break;
3385 case FormComponentType::TIMEFIELD
:
3386 sColumnType
= FM_COL_TIMEFIELD
; break;
3387 case FormComponentType::NUMERICFIELD
:
3388 sColumnType
= FM_COL_NUMERICFIELD
; break;
3389 case FormComponentType::CURRENCYFIELD
:
3390 sColumnType
= FM_COL_CURRENCYFIELD
; break;
3391 case FormComponentType::PATTERNFIELD
:
3392 sColumnType
= FM_COL_PATTERNFIELD
; break;
3394 case FormComponentType::TEXTFIELD
:
3396 sColumnType
= FM_COL_TEXTFIELD
;
3397 // we know at least two different controls which are TextFields : the basic edit field and the formatted
3398 // field. we distinguish them by their service name
3399 Reference
< XServiceInfo
> xInfo(xCurrentModelSet
, UNO_QUERY
);
3402 sal_Int16 nObjectType
= getControlTypeByObject(xInfo
);
3403 if (OBJ_FM_FORMATTEDFIELD
== nObjectType
)
3404 sColumnType
= FM_COL_FORMATTEDFIELD
;
3409 sColumnType
= FM_COL_TEXTFIELD
; break;
3412 const sal_Int16 nDispatchArgs
= 3;
3413 Sequence
< PropertyValue
> aDispatchArgs(nDispatchArgs
);
3414 PropertyValue
* pDispatchArgs
= aDispatchArgs
.getArray();
3416 // properties describing "meta data" about the column
3418 pDispatchArgs
->Name
= FMARG_ADDCOL_COLUMNTYPE
;
3419 pDispatchArgs
->Value
<<= sColumnType
;
3422 // the pos : append the col
3423 pDispatchArgs
->Name
= FMARG_ADDCOL_COLUMNPOS
;
3424 pDispatchArgs
->Value
<<= nAddedColumns
;
3427 // the properties to forward to the new column
3428 Sequence
< PropertyValue
> aColumnProps(1);
3429 PropertyValue
* pColumnProps
= aColumnProps
.getArray();
3432 pColumnProps
->Name
= FM_PROP_LABEL
;
3433 pColumnProps
->Value
<<= getLabelName(xCurrentModelSet
);
3436 // for all other props : transfer them
3437 Reference
< XPropertySetInfo
> xControlModelInfo( xCurrentModelSet
->getPropertySetInfo());
3438 DBG_ASSERT(xControlModelInfo
.is(), "FmXFormShell::CreateExternalView : the control model has no property info ! This will crash !");
3439 aProps
= xControlModelInfo
->getProperties();
3440 const Property
* pProps
= aProps
.getConstArray();
3442 // realloc the control description sequence
3443 sal_Int32 nExistentDescs
= pColumnProps
- aColumnProps
.getArray();
3444 aColumnProps
.realloc(nExistentDescs
+ aProps
.getLength());
3445 pColumnProps
= aColumnProps
.getArray() + nExistentDescs
;
3447 for (sal_Int32 i
=0; i
<aProps
.getLength(); ++i
, ++pProps
)
3449 if (pProps
->Name
.equals(FM_PROP_LABEL
))
3452 if (pProps
->Name
.equals(FM_PROP_DEFAULTCONTROL
))
3453 // allow the column's own "default control"
3455 if (pProps
->Attributes
& PropertyAttribute::READONLY
)
3456 // assume that properties which are readonly for the control are ro for the column to be created, too
3459 pColumnProps
->Name
= pProps
->Name
;
3460 pColumnProps
->Value
= xCurrentModelSet
->getPropertyValue(pProps
->Name
);
3463 aColumnProps
.realloc(pColumnProps
- aColumnProps
.getArray());
3465 // columns props are a dispatch argument
3466 pDispatchArgs
->Name
= OUString("ColumnProperties"); // TODO : fmurl.*
3467 pDispatchArgs
->Value
= makeAny(aColumnProps
);
3469 DBG_ASSERT(nDispatchArgs
== (pDispatchArgs
- aDispatchArgs
.getConstArray()),
3470 "FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
3472 // dispatch the "add column"
3473 xAddColumnDispatch
->dispatch(aAddColumnURL
, aDispatchArgs
);
3477 // now for the radio button handling
3478 sal_Int16
nOffset(0);
3479 // properties describing the "direct" column properties
3480 const sal_Int16 nListBoxDescription
= 6;
3481 Sequence
< PropertyValue
> aListBoxDescription(nListBoxDescription
);
3482 for ( FmMapUString2UString::const_iterator aCtrlSource
= aRadioControlSources
.begin();
3483 aCtrlSource
!= aRadioControlSources
.end();
3484 ++aCtrlSource
, ++nOffset
3488 PropertyValue
* pListBoxDescription
= aListBoxDescription
.getArray();
3490 pListBoxDescription
->Name
= FM_PROP_LABEL
;
3491 pListBoxDescription
->Value
<<= (*aCtrlSource
).first
;
3492 ++pListBoxDescription
;
3495 pListBoxDescription
->Name
= FM_PROP_CONTROLSOURCE
;
3496 pListBoxDescription
->Value
<<= (*aCtrlSource
).second
;
3497 ++pListBoxDescription
;
3500 pListBoxDescription
->Name
= FM_PROP_BOUNDCOLUMN
;
3501 pListBoxDescription
->Value
<<= (sal_Int16
)1;
3502 ++pListBoxDescription
;
3505 pListBoxDescription
->Name
= FM_PROP_LISTSOURCETYPE
;
3506 ListSourceType eType
= ListSourceType_VALUELIST
;
3507 pListBoxDescription
->Value
= makeAny(eType
);
3508 ++pListBoxDescription
;
3511 MapUString2UstringSeq::const_iterator aCurrentListSource
= aRadioListSources
.find((*aCtrlSource
).first
);
3512 DBG_ASSERT(aCurrentListSource
!= aRadioListSources
.end(),
3513 "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
3514 pListBoxDescription
->Name
= FM_PROP_LISTSOURCE
;
3515 pListBoxDescription
->Value
= makeAny((*aCurrentListSource
).second
);
3516 ++pListBoxDescription
;
3519 MapUString2UstringSeq::const_iterator aCurrentValueList
= aRadioValueLists
.find((*aCtrlSource
).first
);
3520 DBG_ASSERT(aCurrentValueList
!= aRadioValueLists
.end(),
3521 "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
3522 pListBoxDescription
->Name
= FM_PROP_STRINGITEMLIST
;
3523 pListBoxDescription
->Value
= makeAny(((*aCurrentValueList
).second
));
3524 ++pListBoxDescription
;
3526 DBG_ASSERT(nListBoxDescription
== (pListBoxDescription
- aListBoxDescription
.getConstArray()),
3527 "FmXFormShell::CreateExternalView : forgot to adjust nListBoxDescription ?");
3529 // properties describing the column "meta data"
3530 const sal_Int16 nDispatchArgs
= 3;
3531 Sequence
< PropertyValue
> aDispatchArgs(nDispatchArgs
);
3532 PropertyValue
* pDispatchArgs
= aDispatchArgs
.getArray();
3534 // column type : listbox
3535 pDispatchArgs
->Name
= FMARG_ADDCOL_COLUMNTYPE
;
3536 OUString fColName
= FM_COL_LISTBOX
;
3537 pDispatchArgs
->Value
<<= fColName
;
3538 // pDispatchArgs->Value <<= (OUString)FM_COL_LISTBOX;
3542 pDispatchArgs
->Name
= FMARG_ADDCOL_COLUMNPOS
;
3543 FmMapUString2Int16::const_iterator aOffset
= aRadioPositions
.find((*aCtrlSource
).first
);
3544 DBG_ASSERT(aOffset
!= aRadioPositions
.end(),
3545 "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
3546 sal_Int16 nPosition
= (*aOffset
).second
;
3547 nPosition
= nPosition
+ nOffset
;
3548 // we already inserted nOffset additional columns ....
3549 pDispatchArgs
->Value
<<= nPosition
;
3553 pDispatchArgs
->Name
= OUString("ColumnProperties"); // TODO : fmurl.*
3554 pDispatchArgs
->Value
= makeAny(aListBoxDescription
);
3556 DBG_ASSERT(nDispatchArgs
== (pDispatchArgs
- aDispatchArgs
.getConstArray()),
3557 "FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
3559 // dispatch the "add column"
3560 xAddColumnDispatch
->dispatch(aAddColumnURL
, aDispatchArgs
);
3565 DBG_ASSERT(nAddedColumns
> 0, "FmXFormShell::CreateExternalView : no controls (inconsistent) !");
3566 // we should have checked if we have any usable controls (see above).
3568 // "load" the "form" of the external view
3570 aArg
.Name
= FMARG_ATTACHTO_MASTERFORM
;
3571 Reference
< XResultSet
> xForm(xCurrentNavController
->getModel(), UNO_QUERY
);
3572 aArg
.Value
<<= xForm
;
3574 m_xExternalDisplayedForm
= Reference
< XResultSet
>(xForm
, UNO_QUERY
);
3575 // do this before dispatching the "attach" command, as the atach may result in a call to our queryDispatch (for the FormSlots)
3576 // whichs needs the m_xExternalDisplayedForm
3578 xAttachDispatch
->dispatch(aAttachURL
, Sequence
< PropertyValue
>(&aArg
, 1));
3580 m_xExtViewTriggerController
= xCurrentNavController
;
3582 // we want to know modifications done in the external view
3583 // if the external controller is a XFormController we can use all our default handlings for it
3584 Reference
< runtime::XFormController
> xFormController( m_xExternalViewController
, UNO_QUERY
);
3585 OSL_ENSURE( xFormController
.is(), "FmXFormShell::CreateExternalView:: invalid external view controller!" );
3586 if (xFormController
.is())
3587 xFormController
->addActivateListener((XFormControllerListener
*)this);
3593 OSL_FAIL("FmXFormShell::CreateExternalView : could not create the external form view !");
3596 InvalidateSlot( SID_FM_VIEW_AS_GRID
, sal_False
);
3599 //------------------------------------------------------------------------
3600 void FmXFormShell::implAdjustConfigCache()
3602 // get (cache) the wizard usage flag
3603 Sequence
< OUString
> aNames(1);
3604 aNames
[0] = OUString("FormControlPilotsEnabled");
3605 Sequence
< Any
> aFlags
= GetProperties(aNames
);
3606 if (1 == aFlags
.getLength())
3607 m_bUseWizards
= ::cppu::any2bool(aFlags
[0]);
3610 //------------------------------------------------------------------------
3611 void FmXFormShell::Notify( const com::sun::star::uno::Sequence
< OUString
>& _rPropertyNames
)
3613 if ( impl_checkDisposed() )
3616 const OUString
* pSearch
= _rPropertyNames
.getConstArray();
3617 const OUString
* pSearchTil
= pSearch
+ _rPropertyNames
.getLength();
3618 for (;pSearch
< pSearchTil
; ++pSearch
)
3619 if (0 == pSearch
->compareToAscii("FormControlPilotsEnabled"))
3621 implAdjustConfigCache();
3622 InvalidateSlot( SID_FM_USE_WIZARDS
, sal_True
);
3626 void FmXFormShell::Commit()
3630 //------------------------------------------------------------------------
3631 void FmXFormShell::SetWizardUsing(sal_Bool _bUseThem
)
3633 m_bUseWizards
= _bUseThem
;
3635 Sequence
< OUString
> aNames(1);
3636 aNames
[0] = OUString("FormControlPilotsEnabled");
3637 Sequence
< Any
> aValues(1);
3638 aValues
[0] = ::cppu::bool2any(m_bUseWizards
);
3639 PutProperties(aNames
, aValues
);
3642 //------------------------------------------------------------------------
3643 void FmXFormShell::viewDeactivated( FmFormView
& _rCurrentView
, sal_Bool _bDeactivateController
/* = sal_True */ )
3646 if ( _rCurrentView
.GetImpl() && !_rCurrentView
.IsDesignMode() )
3648 _rCurrentView
.GetImpl()->Deactivate( _bDeactivateController
);
3651 // if we have an async load operation pending for the 0-th page for this view,
3652 // we need to cancel this
3653 FmFormPage
* pPage
= _rCurrentView
.GetCurPage();
3656 // move all events from our queue to a new one, omit the events for the deactivated
3658 ::std::queue
< FmLoadAction
> aNewEvents
;
3659 while ( !m_aLoadingPages
.empty() )
3661 FmLoadAction aAction
= m_aLoadingPages
.front();
3662 m_aLoadingPages
.pop();
3663 if ( pPage
!= aAction
.pPage
)
3665 aNewEvents
.push( aAction
);
3669 Application::RemoveUserEvent( aAction
.nEventId
);
3672 m_aLoadingPages
= aNewEvents
;
3675 // remove callbacks at the page
3678 pPage
->GetImpl().SetFormsCreationHdl( Link() );
3680 UpdateForms( sal_True
);
3683 //------------------------------------------------------------------------
3684 IMPL_LINK( FmXFormShell
, OnFirstTimeActivation
, void*, /*NOTINTERESTEDIN*/ )
3686 if ( impl_checkDisposed() )
3689 m_nActivationEvent
= 0;
3690 SfxObjectShell
* pDocument
= m_pShell
->GetObjectShell();
3692 if ( pDocument
&& !pDocument
->HasName() )
3694 if ( isEnhancedForm() )
3696 // show the data navigator
3697 if ( !m_pShell
->GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_SHOW_DATANAVIGATOR
) )
3698 m_pShell
->GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_SHOW_DATANAVIGATOR
);
3705 //------------------------------------------------------------------------
3706 IMPL_LINK( FmXFormShell
, OnFormsCreated
, FmFormPage
*, /*_pPage*/ )
3708 UpdateForms( sal_True
);
3712 //------------------------------------------------------------------------
3713 void FmXFormShell::viewActivated( FmFormView
& _rCurrentView
, sal_Bool _bSyncAction
/* = sal_False */ )
3716 FmFormPage
* pPage
= _rCurrentView
.GetCurPage();
3718 // activate our view if we are activated ourself
3719 // FS - 30.06.99 - 67308
3720 if ( _rCurrentView
.GetImpl() && !_rCurrentView
.IsDesignMode() )
3722 // load forms for the page the current view belongs to
3725 if ( !pPage
->GetImpl().hasEverBeenActivated() )
3726 loadForms( pPage
, FORMS_LOAD
| ( _bSyncAction
? FORMS_SYNC
: FORMS_ASYNC
) );
3727 pPage
->GetImpl().setHasBeenActivated( );
3730 // first-time initializations for the views
3731 if ( !_rCurrentView
.GetImpl()->hasEverBeenActivated( ) )
3733 _rCurrentView
.GetImpl()->onFirstViewActivation( PTR_CAST( FmFormModel
, _rCurrentView
.GetModel() ) );
3734 _rCurrentView
.GetImpl()->setHasBeenActivated( );
3737 // activate the current view
3738 _rCurrentView
.GetImpl()->Activate( _bSyncAction
);
3741 // set callbacks at the page
3744 pPage
->GetImpl().SetFormsCreationHdl( LINK( this, FmXFormShell
, OnFormsCreated
) );
3747 UpdateForms( sal_True
);
3749 if ( !hasEverBeenActivated() )
3751 m_nActivationEvent
= Application::PostUserEvent( LINK( this, FmXFormShell
, OnFirstTimeActivation
) );
3752 setHasBeenActivated();
3755 // find a default "current form", if there is none, yet
3756 // #i88186# / 2008-04-12 / frank.schoenheit@sun.com
3757 impl_defaultCurrentForm_nothrow();
3760 //------------------------------------------------------------------------------
3761 void FmXFormShell::impl_defaultCurrentForm_nothrow()
3763 if ( impl_checkDisposed() )
3766 if ( m_xCurrentForm
.is() )
3767 // no action required
3770 FmFormView
* pFormView
= m_pShell
->GetFormView();
3771 FmFormPage
* pPage
= pFormView
? pFormView
->GetCurPage() : NULL
;
3777 Reference
< XIndexAccess
> xForms( pPage
->GetForms( false ), UNO_QUERY
);
3778 if ( !xForms
.is() || !xForms
->hasElements() )
3781 Reference
< XForm
> xNewCurrentForm( xForms
->getByIndex(0), UNO_QUERY_THROW
);
3782 impl_updateCurrentForm( xNewCurrentForm
);
3784 catch( const Exception
& )
3786 DBG_UNHANDLED_EXCEPTION();
3790 //------------------------------------------------------------------------------
3791 void FmXFormShell::smartControlReset( const Reference
< XIndexAccess
>& _rxModels
)
3793 if (!_rxModels
.is())
3795 OSL_FAIL("FmXFormShell::smartControlReset: invalid container!");
3799 static const OUString sClassIdPropertyName
= FM_PROP_CLASSID
;
3800 static const OUString sBoundFieldPropertyName
= FM_PROP_BOUNDFIELD
;
3801 sal_Int32 nCount
= _rxModels
->getCount();
3802 Reference
< XPropertySet
> xCurrent
;
3803 Reference
< XPropertySetInfo
> xCurrentInfo
;
3804 Reference
< XPropertySet
> xBoundField
;
3806 for (sal_Int32 i
=0; i
<nCount
; ++i
)
3808 _rxModels
->getByIndex(i
) >>= xCurrent
;
3810 xCurrentInfo
= xCurrent
->getPropertySetInfo();
3812 xCurrentInfo
.clear();
3813 if (!xCurrentInfo
.is())
3816 if (xCurrentInfo
->hasPropertyByName(sClassIdPropertyName
))
3817 { // it's a control model
3819 // check if this control is bound to a living database field
3820 if (xCurrentInfo
->hasPropertyByName(sBoundFieldPropertyName
))
3821 xCurrent
->getPropertyValue(sBoundFieldPropertyName
) >>= xBoundField
;
3823 xBoundField
.clear();
3825 // reset only if it's *not* bound
3826 bool bReset
= !xBoundField
.is();
3828 // and additionally, check if it has an external value binding
3829 Reference
< XBindableValue
> xBindable( xCurrent
, UNO_QUERY
);
3830 if ( xBindable
.is() && xBindable
->getValueBinding().is() )
3835 Reference
< XReset
> xControlReset( xCurrent
, UNO_QUERY
);
3836 if ( xControlReset
.is() )
3837 xControlReset
->reset();
3842 Reference
< XIndexAccess
> xContainer(xCurrent
, UNO_QUERY
);
3843 if (xContainer
.is())
3844 smartControlReset(xContainer
);
3849 //------------------------------------------------------------------------
3850 IMPL_LINK( FmXFormShell
, OnLoadForms
, FmFormPage
*, /*_pPage*/ )
3852 FmLoadAction aAction
= m_aLoadingPages
.front();
3853 m_aLoadingPages
.pop();
3855 loadForms( aAction
.pPage
, aAction
.nFlags
& ~FORMS_ASYNC
);
3859 //------------------------------------------------------------------------------
3862 sal_Bool
lcl_isLoadable( const Reference
< XInterface
>& _rxLoadable
)
3864 // determines whether a form should be loaded or not
3865 // if there is no datasource or connection there is no reason to load a form
3866 Reference
< XPropertySet
> xSet( _rxLoadable
, UNO_QUERY
);
3871 Reference
< XConnection
> xConn
;
3872 if ( OStaticDataAccessTools().isEmbeddedInDatabase( _rxLoadable
.get(), xConn
) )
3875 // is there already a active connection
3876 xSet
->getPropertyValue(FM_PROP_ACTIVE_CONNECTION
) >>= xConn
;
3880 OUString sPropertyValue
;
3881 OSL_VERIFY( xSet
->getPropertyValue( FM_PROP_DATASOURCE
) >>= sPropertyValue
);
3882 if ( !sPropertyValue
.isEmpty() )
3885 OSL_VERIFY( xSet
->getPropertyValue( FM_PROP_URL
) >>= sPropertyValue
);
3886 if ( !sPropertyValue
.isEmpty() )
3889 catch(const Exception
&)
3891 DBG_UNHANDLED_EXCEPTION();
3897 //------------------------------------------------------------------------
3898 void FmXFormShell::loadForms( FmFormPage
* _pPage
, const sal_uInt16 _nBehaviour
/* FORMS_LOAD | FORMS_SYNC */ )
3900 DBG_ASSERT( ( _nBehaviour
& ( FORMS_ASYNC
| FORMS_UNLOAD
) ) != ( FORMS_ASYNC
| FORMS_UNLOAD
),
3901 "FmXFormShell::loadForms: async loading not supported - this will heavily fail!" );
3903 if ( _nBehaviour
& FORMS_ASYNC
)
3905 m_aLoadingPages
.push( FmLoadAction(
3908 Application::PostUserEvent( LINK( this, FmXFormShell
, OnLoadForms
), _pPage
)
3913 DBG_ASSERT( _pPage
, "FmXFormShell::loadForms: invalid page!" );
3916 // lock the undo env so the forms can change non-transient properties while loading
3917 // (without this my doc's modified flag would be set)
3918 FmFormModel
* pModel
= PTR_CAST( FmFormModel
, _pPage
->GetModel() );
3919 DBG_ASSERT( pModel
, "FmXFormShell::loadForms: invalid model!" );
3921 pModel
->GetUndoEnv().Lock();
3924 Reference
< XIndexAccess
> xForms
;
3925 xForms
= xForms
.query( _pPage
->GetForms( false ) );
3929 Reference
< XLoadable
> xForm
;
3930 sal_Bool bFormWasLoaded
= sal_False
;
3931 for ( sal_Int32 j
= 0, nCount
= xForms
->getCount(); j
< nCount
; ++j
)
3933 xForms
->getByIndex( j
) >>= xForm
;
3934 bFormWasLoaded
= sal_False
;
3935 // a database form must be loaded for
3938 if ( 0 == ( _nBehaviour
& FORMS_UNLOAD
) )
3940 if ( lcl_isLoadable( xForm
) && !xForm
->isLoaded() )
3945 if ( xForm
->isLoaded() )
3947 bFormWasLoaded
= sal_True
;
3952 catch( const Exception
& )
3954 DBG_UNHANDLED_EXCEPTION();
3957 // reset the form if it was loaded
3958 if ( bFormWasLoaded
)
3960 Reference
< XIndexAccess
> xContainer( xForm
, UNO_QUERY
);
3961 DBG_ASSERT( xContainer
.is(), "FmXFormShell::loadForms: the form is no container!" );
3962 if ( xContainer
.is() )
3963 smartControlReset( xContainer
);
3969 // unlock the environment
3970 pModel
->GetUndoEnv().UnLock();
3974 //------------------------------------------------------------------------
3975 void FmXFormShell::ExecuteTextAttribute( SfxRequest
& _rReq
)
3977 m_pTextShell
->ExecuteTextAttribute( _rReq
);
3980 //------------------------------------------------------------------------
3981 void FmXFormShell::GetTextAttributeState( SfxItemSet
& _rSet
)
3983 m_pTextShell
->GetTextAttributeState( _rSet
);
3986 //------------------------------------------------------------------------
3987 bool FmXFormShell::IsActiveControl( bool _bCountRichTextOnly
) const
3989 return m_pTextShell
->IsActiveControl( _bCountRichTextOnly
);
3992 //------------------------------------------------------------------------
3993 void FmXFormShell::ForgetActiveControl()
3995 m_pTextShell
->ForgetActiveControl();
3998 //------------------------------------------------------------------------
3999 void FmXFormShell::SetControlActivationHandler( const Link
& _rHdl
)
4001 m_pTextShell
->SetControlActivationHandler( _rHdl
);
4003 //------------------------------------------------------------------------
4004 void FmXFormShell::handleShowPropertiesRequest()
4006 if ( onlyControlsAreMarked() )
4007 ShowSelectionProperties( sal_True
);
4010 //------------------------------------------------------------------------
4011 void FmXFormShell::handleMouseButtonDown( const SdrViewEvent
& _rViewEvent
)
4013 // catch simple double clicks
4014 if ( ( _rViewEvent
.nMouseClicks
== 2 ) && ( _rViewEvent
.nMouseCode
== MOUSE_LEFT
) )
4016 if ( _rViewEvent
.eHit
== SDRHIT_MARKEDOBJECT
)
4018 if ( onlyControlsAreMarked() )
4019 ShowSelectionProperties( sal_True
);
4024 //------------------------------------------------------------------------------
4025 bool FmXFormShell::HasControlFocus() const
4027 bool bHasControlFocus
= false;
4031 Reference
< XFormController
> xController( getActiveController() );
4032 Reference
< XControl
> xCurrentControl
;
4033 if ( xController
.is() )
4034 xCurrentControl
.set( xController
->getCurrentControl() );
4035 if ( xCurrentControl
.is() )
4037 Reference
< XWindow2
> xPeerWindow( xCurrentControl
->getPeer(), UNO_QUERY_THROW
);
4038 bHasControlFocus
= xPeerWindow
->hasFocus();
4041 catch( const Exception
& )
4043 DBG_UNHANDLED_EXCEPTION();
4046 return bHasControlFocus
;
4049 //==============================================================================
4050 //==============================================================================
4051 SearchableControlIterator::SearchableControlIterator(Reference
< XInterface
> xStartingPoint
)
4052 :IndexAccessIterator(xStartingPoint
)
4056 //------------------------------------------------------------------------------
4057 sal_Bool
SearchableControlIterator::ShouldHandleElement(const Reference
< XInterface
>& xElement
)
4059 // wenn das Ding eine ControlSource und einen BoundField-Property hat
4060 Reference
< XPropertySet
> xProperties(xElement
, UNO_QUERY
);
4061 if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE
, xProperties
) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD
, xProperties
))
4063 // und das BoundField gueltig ist
4064 Reference
< XPropertySet
> xField
;
4065 xProperties
->getPropertyValue(FM_PROP_BOUNDFIELD
) >>= xField
;
4069 m_sCurrentValue
= ::comphelper::getString(xProperties
->getPropertyValue(FM_PROP_CONTROLSOURCE
));
4074 // wenn es ein Grid-Control ist
4075 if (::comphelper::hasProperty(FM_PROP_CLASSID
, xProperties
))
4077 Any
aClassId( xProperties
->getPropertyValue(FM_PROP_CLASSID
) );
4078 if (::comphelper::getINT16(aClassId
) == FormComponentType::GRIDCONTROL
)
4080 m_sCurrentValue
= OUString();
4088 //------------------------------------------------------------------------------
4089 sal_Bool
SearchableControlIterator::ShouldStepInto(const Reference
< XInterface
>& /*xContainer*/) const
4094 //==============================================================================
4095 //==============================================================================
4097 SFX_IMPL_MENU_CONTROL(ControlConversionMenuController
, SfxBoolItem
);
4099 //------------------------------------------------------------------------------
4100 ControlConversionMenuController::ControlConversionMenuController( sal_uInt16 _nId
, Menu
& _rMenu
, SfxBindings
& _rBindings
)
4101 :SfxMenuControl( _nId
, _rBindings
)
4102 ,m_pMainMenu( &_rMenu
)
4103 ,m_pConversionMenu( NULL
)
4105 if ( _nId
== SID_FM_CHANGECONTROLTYPE
)
4107 m_pConversionMenu
= FmXFormShell::GetConversionMenu();
4108 _rMenu
.SetPopupMenu( _nId
, m_pConversionMenu
);
4110 for (sal_Int16 i
=0; i
<m_pConversionMenu
->GetItemCount(); ++i
)
4112 _rBindings
.Invalidate(m_pConversionMenu
->GetItemId(i
));
4113 SfxStatusForwarder
* pForwarder
= new SfxStatusForwarder(m_pConversionMenu
->GetItemId(i
), *this);
4114 m_aStatusForwarders
.push_back(pForwarder
);
4119 //------------------------------------------------------------------------------
4120 ControlConversionMenuController::~ControlConversionMenuController()
4122 m_pMainMenu
->SetPopupMenu(SID_FM_CHANGECONTROLTYPE
, NULL
);
4123 delete m_pConversionMenu
;
4126 //------------------------------------------------------------------------------
4127 void ControlConversionMenuController::StateChanged(sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
4129 if (nSID
== GetId())
4130 SfxMenuControl::StateChanged(nSID
, eState
, pState
);
4131 else if (FmXFormShell::isControlConversionSlot(nSID
))
4133 if ((m_pConversionMenu
->GetItemPos(nSID
) != MENU_ITEM_NOTFOUND
) && (eState
== SFX_ITEM_DISABLED
))
4135 m_pConversionMenu
->RemoveItem(m_pConversionMenu
->GetItemPos(nSID
));
4137 else if ((m_pConversionMenu
->GetItemPos(nSID
) == MENU_ITEM_NOTFOUND
) && (eState
!= SFX_ITEM_DISABLED
))
4139 // We can't simply re-insert the item because we have a clear order for all the our items.
4140 // So first we have to determine the position of the item to insert.
4141 PopupMenu
* pSource
= FmXFormShell::GetConversionMenu();
4142 sal_uInt16 nSourcePos
= pSource
->GetItemPos(nSID
);
4143 DBG_ASSERT(nSourcePos
!= MENU_ITEM_NOTFOUND
, "ControlConversionMenuController::StateChanged : FmXFormShell supplied an invalid menu !");
4144 sal_uInt16 nPrevInSource
= nSourcePos
;
4145 sal_uInt16 nPrevInConversion
= MENU_ITEM_NOTFOUND
;
4146 while (nPrevInSource
>0)
4148 sal_Int16 nPrevId
= pSource
->GetItemId(--nPrevInSource
);
4150 // do we have the source's predecessor in our conversion menu, too ?
4151 nPrevInConversion
= m_pConversionMenu
->GetItemPos(nPrevId
);
4152 if (nPrevInConversion
!= MENU_ITEM_NOTFOUND
)
4155 if (MENU_ITEM_NOTFOUND
== nPrevInConversion
)
4156 // none of the items which precede the nSID-slot in the source menu are present in our conversion menu
4157 nPrevInConversion
= sal::static_int_cast
< sal_uInt16
>(-1); // put the item at the first position
4158 m_pConversionMenu
->InsertItem(nSID
, pSource
->GetItemText(nSID
),
4159 pSource
->GetItemBits(nSID
), OString(), ++nPrevInConversion
);
4160 m_pConversionMenu
->SetItemImage(nSID
, pSource
->GetItemImage(nSID
));
4161 m_pConversionMenu
->SetHelpId(nSID
, pSource
->GetHelpId(nSID
));
4165 m_pMainMenu
->EnableItem(SID_FM_CHANGECONTROLTYPE
, m_pConversionMenu
->GetItemCount() > 0);
4169 OSL_FAIL("ControlConversionMenuController::StateChanged : unknown id !");
4173 //==============================================================================
4175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */