Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / form / fmshimp.cxx
blob732d947b5e2d85602c86f95f2b04147f6b74628b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
23 #include "fmobj.hxx"
24 #include "fmpgeimp.hxx"
25 #include "svx/fmtools.hxx"
26 #include "fmprop.hrc"
27 #include "svx/fmresids.hrc"
28 #include "fmservs.hxx"
29 #include "fmshimp.hxx"
30 #include "fmtextcontrolshell.hxx"
31 #include "fmundo.hxx"
32 #include "fmurl.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/theIntrospection.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/TabOrderDialog.hpp>
64 #include <com/sun/star/form/XBoundComponent.hpp>
65 #include <com/sun/star/form/XBoundControl.hpp>
66 #include <com/sun/star/form/XGrid.hpp>
67 #include <com/sun/star/form/XGridPeer.hpp>
68 #include <com/sun/star/form/XLoadable.hpp>
69 #include <com/sun/star/form/XReset.hpp>
70 #include <com/sun/star/form/binding/XBindableValue.hpp>
71 #include <com/sun/star/form/binding/XListEntrySink.hpp>
72 #include <com/sun/star/frame/FrameSearchFlag.hpp>
73 #include <com/sun/star/script/XEventAttacherManager.hpp>
74 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
75 #include <com/sun/star/util/XCancellable.hpp>
76 #include <com/sun/star/util/XModeSelector.hpp>
77 #include <com/sun/star/util/XModifyBroadcaster.hpp>
78 #include <com/sun/star/util/XNumberFormatter.hpp>
79 #include <com/sun/star/view/XSelectionSupplier.hpp>
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 <sfx2/dispatch.hxx>
88 #include <sfx2/docfile.hxx>
89 #include <sfx2/frame.hxx>
90 #include <sfx2/objsh.hxx>
91 #include <sfx2/viewfrm.hxx>
92 #include <sfx2/viewsh.hxx>
93 #include <toolkit/helper/vclunohelper.hxx>
94 #include <tools/diagnose_ex.h>
95 #include <tools/shl.hxx>
96 #include <vcl/msgbox.hxx>
97 #include <vcl/waitobj.hxx>
98 #include <vcl/settings.hxx>
100 #include <algorithm>
101 #include <functional>
102 #include <map>
103 #include <vector>
105 // wird fuer Invalidate verwendet -> mitpflegen
106 static const sal_uInt16 DatabaseSlotMap[] =
108 SID_FM_RECORD_FIRST,
109 SID_FM_RECORD_NEXT,
110 SID_FM_RECORD_PREV,
111 SID_FM_RECORD_LAST,
112 SID_FM_RECORD_NEW,
113 SID_FM_RECORD_DELETE,
114 SID_FM_RECORD_ABSOLUTE,
115 SID_FM_RECORD_TOTAL,
116 SID_FM_RECORD_SAVE,
117 SID_FM_RECORD_UNDO,
118 SID_FM_REMOVE_FILTER_SORT,
119 SID_FM_SORTUP,
120 SID_FM_SORTDOWN,
121 SID_FM_ORDERCRIT,
122 SID_FM_AUTOFILTER,
123 SID_FM_FORM_FILTERED,
124 SID_FM_REFRESH,
125 SID_FM_REFRESH_FORM_CONTROL,
126 SID_FM_SEARCH,
127 SID_FM_FILTER_START,
128 SID_FM_VIEW_AS_GRID,
132 // wird fuer Invalidate verwendet -> mitpflegen
133 // aufsteigend sortieren !!!!!!
134 static const sal_Int16 DlgSlotMap[] = // slots des Controllers
136 SID_FM_CTL_PROPERTIES,
137 SID_FM_PROPERTIES,
138 SID_FM_TAB_DIALOG,
139 SID_FM_ADD_FIELD,
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 const 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 const 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 const sal_Int16 nCreateSlots[] =
207 SID_FM_EDIT,
208 SID_FM_PUSHBUTTON,
209 SID_FM_FIXEDTEXT,
210 SID_FM_LISTBOX,
211 SID_FM_CHECKBOX,
212 SID_FM_RADIOBUTTON,
213 SID_FM_GROUPBOX,
214 SID_FM_COMBOBOX,
215 SID_FM_IMAGEBUTTON,
216 SID_FM_FILECONTROL,
217 SID_FM_DATEFIELD,
218 SID_FM_TIMEFIELD,
219 SID_FM_NUMERICFIELD,
220 SID_FM_CURRENCYFIELD,
221 SID_FM_PATTERNFIELD,
222 SID_FM_IMAGECONTROL,
223 SID_FM_FORMATTEDFIELD,
224 SID_FM_SCROLLBAR,
225 SID_FM_SPINBUTTON,
226 SID_FM_NAVIGATIONBAR
229 static const sal_Int16 nObjectTypes[] =
231 OBJ_FM_EDIT,
232 OBJ_FM_BUTTON,
233 OBJ_FM_FIXEDTEXT,
234 OBJ_FM_LISTBOX,
235 OBJ_FM_CHECKBOX,
236 OBJ_FM_RADIOBUTTON,
237 OBJ_FM_GROUPBOX,
238 OBJ_FM_COMBOBOX,
239 OBJ_FM_IMAGEBUTTON,
240 OBJ_FM_FILECONTROL,
241 OBJ_FM_DATEFIELD,
242 OBJ_FM_TIMEFIELD,
243 OBJ_FM_NUMERICFIELD,
244 OBJ_FM_CURRENCYFIELD,
245 OBJ_FM_PATTERNFIELD,
246 OBJ_FM_IMAGECONTROL,
247 OBJ_FM_FORMATTEDFIELD,
248 OBJ_FM_SCROLLBAR,
249 OBJ_FM_SPINBUTTON,
250 OBJ_FM_NAVIGATIONBAR
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;
274 //= helper
276 namespace
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;
295 while ( pCurrent )
297 FmFormObj* pAsFormObject = FmFormObj::GetFormObject( pCurrent );
298 // note this will de-reference virtual objects, if necessary/possible
299 if ( pAsFormObject )
301 Reference< XInterface > xControlModel( pAsFormObject->GetUnoControlModel(), UNO_QUERY );
302 // the UNO_QUERY is important for normalization
303 if ( xControlModel.is() )
304 _rInterfaces.insert( xControlModel );
307 // next element
308 pCurrent = pGroupIterator && pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
311 if ( pGroupIterator )
312 delete pGroupIterator;
317 sal_Int16 GridView2ModelPos(const Reference< XIndexAccess>& rColumns, sal_Int16 nViewPos)
321 if (rColumns.is())
323 // loop through all columns
324 sal_Int16 i;
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
333 if (!nViewPos)
334 break;
335 else
336 --nViewPos;
339 if (i<rColumns->getCount())
340 return i;
343 catch(const Exception&)
345 DBG_UNHANDLED_EXCEPTION();
347 return (sal_Int16)-1;
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 its 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> xIntrospection = theIntrospection::get(::comphelper::getProcessComponentContext());
380 if (xModel.is())
382 Any aModel(makeAny(xModel));
383 aModelListeners = xIntrospection->inspect(aModel)->getSupportedListeners();
386 if (xControl.is())
388 Any aControl(makeAny(xControl));
389 aControlListeners = xIntrospection->inspect(aControl)->getSupportedListeners();
392 sal_Int32 nMaxNewLen = aModelListeners.getLength() + aControlListeners.getLength();
393 if (!nMaxNewLen)
394 return; // the model and the listener don't support any listeners (or we were unable to retrieve these infos)
396 Sequence< ScriptEventDescriptor> aTransferable(nMaxNewLen);
397 ScriptEventDescriptor* pTransferable = aTransferable.getArray();
399 const ScriptEventDescriptor* pCurrent = rTransferIfAvailable.getConstArray();
400 sal_Int32 i,j,k;
401 for (i=0; i<rTransferIfAvailable.getLength(); ++i, ++pCurrent)
403 // search the model/control idl classes for the event described by pCurrent
404 for ( Sequence< Type>* pCurrentArray = &aModelListeners;
405 pCurrentArray;
406 pCurrentArray = (pCurrentArray == &aModelListeners) ? &aControlListeners : NULL
409 const Type* pCurrentListeners = pCurrentArray->getConstArray();
410 for (j=0; j<pCurrentArray->getLength(); ++j, ++pCurrentListeners)
412 OUString aListener = (*pCurrentListeners).getTypeName();
413 sal_Int32 nTokens = comphelper::string::getTokenCount(aListener, '.');
414 if (nTokens)
415 aListener = comphelper::string::getToken(aListener, nTokens - 1, '.');
417 if (aListener == pCurrent->ListenerType.getStr())
418 // the current ScriptEventDescriptor doesn't match the current listeners class
419 continue;
421 // now check the methods
422 Sequence< OUString> aMethodsNames = ::comphelper::getEventMethodsForType(*pCurrentListeners);
424 const OUString* pMethodsNames = aMethodsNames.getConstArray();
425 for (k=0; k<aMethodsNames.getLength(); ++k, ++pMethodsNames)
427 if ((*pMethodsNames) != pCurrent->EventMethod)
428 // the current ScriptEventDescriptor doesn't match the current listeners current method
429 continue;
431 // we can transfer the script event : the model (control) supports it
432 *pTransferable = *pCurrent;
433 ++pTransferable;
434 break;
436 if (k<aMethodsNames.getLength())
437 break;
442 sal_Int32 nRealNewLen = pTransferable - aTransferable.getArray();
443 aTransferable.realloc(nRealNewLen);
445 xEventManager->registerScriptEvents(nIndex, aTransferable);
449 OUString getServiceNameByControlType(sal_Int16 nType)
451 switch (nType)
453 case OBJ_FM_EDIT : return FM_COMPONENT_TEXTFIELD;
454 case OBJ_FM_BUTTON : return FM_COMPONENT_COMMANDBUTTON;
455 case OBJ_FM_FIXEDTEXT : return FM_COMPONENT_FIXEDTEXT;
456 case OBJ_FM_LISTBOX : return FM_COMPONENT_LISTBOX;
457 case OBJ_FM_CHECKBOX : return FM_COMPONENT_CHECKBOX;
458 case OBJ_FM_RADIOBUTTON : return FM_COMPONENT_RADIOBUTTON;
459 case OBJ_FM_GROUPBOX : return FM_COMPONENT_GROUPBOX;
460 case OBJ_FM_COMBOBOX : return FM_COMPONENT_COMBOBOX;
461 case OBJ_FM_GRID : return FM_COMPONENT_GRIDCONTROL;
462 case OBJ_FM_IMAGEBUTTON : return FM_COMPONENT_IMAGEBUTTON;
463 case OBJ_FM_FILECONTROL : return FM_COMPONENT_FILECONTROL;
464 case OBJ_FM_DATEFIELD : return FM_COMPONENT_DATEFIELD;
465 case OBJ_FM_TIMEFIELD : return FM_COMPONENT_TIMEFIELD;
466 case OBJ_FM_NUMERICFIELD : return FM_COMPONENT_NUMERICFIELD;
467 case OBJ_FM_CURRENCYFIELD : return FM_COMPONENT_CURRENCYFIELD;
468 case OBJ_FM_PATTERNFIELD : return FM_COMPONENT_PATTERNFIELD;
469 case OBJ_FM_HIDDEN : return FM_COMPONENT_HIDDENCONTROL;
470 case OBJ_FM_IMAGECONTROL : return FM_COMPONENT_IMAGECONTROL;
471 case OBJ_FM_FORMATTEDFIELD : return FM_COMPONENT_FORMATTEDFIELD;
472 case OBJ_FM_SCROLLBAR : return FM_SUN_COMPONENT_SCROLLBAR;
473 case OBJ_FM_SPINBUTTON : return FM_SUN_COMPONENT_SPINBUTTON;
474 case OBJ_FM_NAVIGATIONBAR : return FM_SUN_COMPONENT_NAVIGATIONBAR;
476 return OUString();
482 // check if the control has one of the interfaces we can use for searching
483 // *_pCurrentText will be filled with the current text of the control (as used when searching this control)
484 bool IsSearchableControl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rxControl,
485 OUString* _pCurrentText )
487 if ( !_rxControl.is() )
488 return false;
490 Reference< XTextComponent > xAsText( _rxControl, UNO_QUERY );
491 if ( xAsText.is() )
493 if ( _pCurrentText )
494 *_pCurrentText = xAsText->getText();
495 return true;
498 Reference< XListBox > xListBox( _rxControl, UNO_QUERY );
499 if ( xListBox.is() )
501 if ( _pCurrentText )
502 *_pCurrentText = xListBox->getSelectedItem();
503 return true;
506 Reference< XCheckBox > xCheckBox( _rxControl, UNO_QUERY );
507 if ( xCheckBox.is() )
509 if ( _pCurrentText )
511 switch ( (::TriState)xCheckBox->getState() )
513 case TRISTATE_FALSE: *_pCurrentText = "0"; break;
514 case TRISTATE_TRUE: *_pCurrentText = "1"; break;
515 default: *_pCurrentText = ""; break;
518 return true;
521 return false;
525 bool FmXBoundFormFieldIterator::ShouldStepInto(const Reference< XInterface>& _rContainer) const
527 if (_rContainer == m_xStartingPoint)
528 // would be quite stupid to step over the root ....
529 return true;
531 return Reference< XControlModel>(_rContainer, UNO_QUERY).is();
535 bool FmXBoundFormFieldIterator::ShouldHandleElement(const Reference< XInterface>& _rElement)
537 if (!_rElement.is())
538 // NULL element
539 return false;
541 if (Reference< XForm>(_rElement, UNO_QUERY).is() || Reference< XGrid>(_rElement, UNO_QUERY).is())
542 // a forms or a grid
543 return false;
545 Reference< XPropertySet> xSet(_rElement, UNO_QUERY);
546 if (!xSet.is() || !::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xSet))
547 // no "BoundField" property
548 return false;
550 Any aVal( xSet->getPropertyValue(FM_PROP_BOUNDFIELD) );
551 if (aVal.getValueTypeClass() != TypeClass_INTERFACE)
552 // void or invalid property value
553 return false;
555 return aVal.hasValue();
559 bool isControlList(const SdrMarkList& rMarkList)
561 // enthaelt die liste nur Controls und mindestens ein control
562 sal_uInt32 nMarkCount = rMarkList.GetMarkCount();
563 bool bControlList = nMarkCount != 0;
565 bool bHadAnyLeafs = false;
567 for (sal_uInt32 i = 0; i < nMarkCount && bControlList; i++)
569 SdrObject *pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
570 E3dObject* pAs3DObject = PTR_CAST(E3dObject, pObj);
571 // E3dObject's do not contain any 2D-objects (by definition)
572 // we need this extra check here : an E3dObject->IsGroupObject says "YES", but an SdrObjListIter working
573 // with an E3dObject doesn't give me any Nodes (E3dObject has a sub list, but no members in that list,
574 // cause there implementation differs from the one of "normal" SdrObject's. Unfortunally SdrObject::IsGroupObject
575 // doesn't check the element count of the sub list, which is simply a bug in IsGroupObject we can't fix at the moment).
576 // So at the end of this function bControlList would have the same value it was initialized with above : sal_True
577 // And this would be wrong :)
578 // 03.02.00 - 72529 - FS
579 if (!pAs3DObject)
581 if (pObj->IsGroupObject())
583 SdrObjListIter aIter(*pObj->GetSubList());
584 while (aIter.IsMore() && bControlList)
586 bControlList = FmFormInventor == aIter.Next()->GetObjInventor();
587 bHadAnyLeafs = true;
590 else
592 bHadAnyLeafs = true;
593 bControlList = FmFormInventor == pObj->GetObjInventor();
598 return bControlList && bHadAnyLeafs;
602 Reference< XForm > GetForm(const Reference< XInterface>& _rxElement)
604 Reference< XForm > xForm( _rxElement, UNO_QUERY );
605 if ( xForm.is() )
606 return xForm;
608 Reference< XChild > xChild( _rxElement, UNO_QUERY );
609 if ( xChild.is() )
610 return GetForm( xChild->getParent() );
612 return Reference< XForm >();
616 // class FmXFormShell_Base_Disambiguation
618 FmXFormShell_Base_Disambiguation::FmXFormShell_Base_Disambiguation( ::osl::Mutex& _rMutex )
619 :FmXFormShell_BD_BASE( _rMutex )
623 void SAL_CALL FmXFormShell_Base_Disambiguation::disposing()
625 WeakComponentImplHelperBase::disposing();
626 // Note:
627 // This is a HACK.
628 // Normally it should be sufficient to call the "disposing" of our direct
629 // base class, but SUN PRO 5 does not like this and claims there is a conflict
630 // with the XEventListener::disposing(EventObject) of our various listener
631 // base classes.
635 // class FmXFormShell
638 FmXFormShell::FmXFormShell( FmFormShell& _rShell, SfxViewFrame* _pViewFrame )
639 :FmXFormShell_BASE(m_aMutex)
640 ,FmXFormShell_CFGBASE(OUString("Office.Common/Misc"), CONFIG_MODE_DELAYED_UPDATE)
641 ,m_eNavigate( NavigationBarMode_NONE )
642 ,m_nInvalidationEvent( 0 )
643 ,m_nActivationEvent( 0 )
644 ,m_pShell( &_rShell )
645 ,m_pTextShell( new ::svx::FmTextControlShell( _pViewFrame ) )
646 ,m_aActiveControllerFeatures( this )
647 ,m_aNavControllerFeatures( this )
648 ,m_eDocumentType( eUnknownDocumentType )
649 ,m_nLockSlotInvalidation( 0 )
650 ,m_bHadPropertyBrowserInDesignMode( false )
651 ,m_bTrackProperties( true )
652 ,m_bUseWizards( true )
653 ,m_bDatabaseBar( false )
654 ,m_bInActivate( false )
655 ,m_bSetFocus( false )
656 ,m_bFilterMode( false )
657 ,m_bChangingDesignMode( false )
658 ,m_bPreparedClose( false )
659 ,m_bFirstActivation( true )
661 m_aMarkTimer.SetTimeout(100);
662 m_aMarkTimer.SetTimeoutHdl(LINK(this,FmXFormShell,OnTimeOut));
664 m_xAttachedFrame = _pViewFrame->GetFrame().GetFrameInterface();
666 // to prevent deletion of this we acquire our refcounter once
667 ::comphelper::increment(FmXFormShell_BASE::m_refCount);
669 // correct the refcounter
670 ::comphelper::decrement(FmXFormShell_BASE::m_refCount);
672 // cache the current configuration settings we're interested in
673 implAdjustConfigCache();
674 // and register for changes on this settings
675 Sequence< OUString > aNames(1);
676 aNames[0] = "FormControlPilotsEnabled";
677 EnableNotification(aNames);
681 FmXFormShell::~FmXFormShell()
683 delete m_pTextShell;
687 Reference< XModel > FmXFormShell::getContextDocument() const
689 Reference< XModel > xModel;
691 // determine the type of document we live in
694 Reference< XController > xController;
695 if ( m_xAttachedFrame.is() )
696 xController = m_xAttachedFrame->getController();
697 if ( xController.is() )
698 xModel = xController->getModel();
700 catch( const Exception& )
702 DBG_UNHANDLED_EXCEPTION();
704 return xModel;
708 bool FmXFormShell::isEnhancedForm() const
710 return getDocumentType() == eEnhancedForm;
714 bool FmXFormShell::impl_checkDisposed() const
716 if ( !m_pShell )
718 OSL_FAIL( "FmXFormShell::impl_checkDisposed: already disposed!" );
719 return true;
721 return false;
725 ::svxform::DocumentType FmXFormShell::getDocumentType() const
727 if ( m_eDocumentType != eUnknownDocumentType )
728 return m_eDocumentType;
730 // determine the type of document we live in
731 Reference< XModel > xModel = getContextDocument();
732 if ( xModel.is() )
733 m_eDocumentType = DocumentClassification::classifyDocument( xModel );
734 else
736 OSL_FAIL( "FmXFormShell::getDocumentType: can't determine the document type!" );
737 m_eDocumentType = eTextDocument;
738 // fallback, just to have a defined state
741 return m_eDocumentType;
745 bool FmXFormShell::IsReadonlyDoc() const
747 if ( impl_checkDisposed() )
748 return true;
750 FmFormModel* pModel = m_pShell->GetFormModel();
751 if ( pModel && pModel->GetObjectShell() )
752 return pModel->GetObjectShell()->IsReadOnly() || pModel->GetObjectShell()->IsReadOnlyUI();
753 return true;
757 Any SAL_CALL FmXFormShell::queryInterface( const Type& type) throw ( RuntimeException, std::exception )
759 return FmXFormShell_BASE::queryInterface(type);
762 Sequence< Type > SAL_CALL FmXFormShell::getTypes( ) throw(RuntimeException, std::exception)
764 return FmXFormShell_BASE::getTypes();
767 Sequence< sal_Int8 > SAL_CALL FmXFormShell::getImplementationId() throw(RuntimeException, std::exception)
769 return css::uno::Sequence<sal_Int8>();
771 // EventListener
773 void SAL_CALL FmXFormShell::disposing(const EventObject& e) throw( RuntimeException, std::exception )
775 impl_checkDisposed();
777 if (m_xActiveController == e.Source)
779 // wird der Controller freigeben dann alles loslassen
780 stopListening();
781 m_xActiveForm = NULL;
782 m_xActiveController = NULL;
783 m_xNavigationController = NULL;
785 m_aActiveControllerFeatures.dispose();
786 m_aNavControllerFeatures.dispose();
788 if ( m_pShell )
789 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
792 if (e.Source == m_xExternalViewController)
794 Reference< runtime::XFormController > xFormController( m_xExternalViewController, UNO_QUERY );
795 OSL_ENSURE( xFormController.is(), "FmXFormShell::disposing: invalid external view controller!" );
796 if (xFormController.is())
797 xFormController->removeActivateListener((XFormControllerListener*)this);
799 Reference< ::com::sun::star::lang::XComponent> xComp(m_xExternalViewController, UNO_QUERY);
800 if (xComp.is())
801 xComp->removeEventListener((XEventListener*)(XPropertyChangeListener*)this);
803 m_xExternalViewController = NULL;
804 m_xExternalDisplayedForm = NULL;
805 m_xExtViewTriggerController = NULL;
807 InvalidateSlot( SID_FM_VIEW_AS_GRID, false );
812 void SAL_CALL FmXFormShell::propertyChange(const PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException, std::exception)
814 if ( impl_checkDisposed() )
815 return;
817 if (evt.PropertyName == FM_PROP_ROWCOUNT)
819 // Das gleich folgenden Update erzwingt ein Neu-Painten der entsprechenden Slots. Wenn ich mich aber hier nicht
820 // in dem HauptThread der Applikation befinde (weil zum Beispiel ein Cursor gerade Datensaetze zaehlt und mir dabei
821 // immer diese PropertyChanges beschert), kann sich das mit en normalen Paints im HauptThread der Applikation beissen.
822 // (Solche Paints passieren zum Beispiel, wenn man einfach nur eine andere Applikation ueber das Office legt und wieder
823 // zurueckschaltet).
824 // Deshalb die Benutzung des SolarMutex, der sichert das ab.
825 comphelper::SolarMutex& rSolarSafety = Application::GetSolarMutex();
826 if (rSolarSafety.tryToAcquire())
828 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_RECORD_TOTAL, true, false);
829 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update(SID_FM_RECORD_TOTAL);
830 rSolarSafety.release();
832 else
834 // with the following the slot is invalidated asynchron
835 LockSlotInvalidation(true);
836 InvalidateSlot(SID_FM_RECORD_TOTAL, false);
837 LockSlotInvalidation(false);
841 // this may be called from a non-main-thread so invalidate the shell asynchronously
842 LockSlotInvalidation(true);
843 InvalidateSlot(0, false); // special meaning : invalidate m_pShell
844 LockSlotInvalidation(false);
848 void FmXFormShell::invalidateFeatures( const ::std::vector< sal_Int32 >& _rFeatures )
850 if ( impl_checkDisposed() )
851 return;
853 OSL_ENSURE( _rFeatures.size() > 0, "FmXFormShell::invalidateFeatures: invalid arguments!" );
855 if ( m_pShell->GetViewShell() && m_pShell->GetViewShell()->GetViewFrame() )
857 // unfortunately, SFX requires sal_uInt16
858 ::std::vector< sal_uInt16 > aSlotIds;
859 aSlotIds.reserve( _rFeatures.size() );
860 ::std::copy( _rFeatures.begin(),
861 _rFeatures.end(),
862 ::std::insert_iterator< ::std::vector< sal_uInt16 > >( aSlotIds, aSlotIds.begin() )
865 // furthermore, SFX wants a terminating 0
866 aSlotIds.push_back( 0 );
868 // and, last but not least, SFX wants the ids to be sorted
869 ::std::sort( aSlotIds.begin(), aSlotIds.end() - 1 );
871 sal_uInt16 *pSlotIds = &(aSlotIds[0]);
872 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( pSlotIds );
877 void SAL_CALL FmXFormShell::formActivated(const EventObject& rEvent) throw( RuntimeException, std::exception )
879 if ( impl_checkDisposed() )
880 return;
882 Reference< runtime::XFormController > xController( rEvent.Source, UNO_QUERY_THROW );
883 m_pTextShell->formActivated( xController );
884 setActiveController( xController );
888 void SAL_CALL FmXFormShell::formDeactivated(const EventObject& rEvent) throw( RuntimeException, std::exception )
890 if ( impl_checkDisposed() )
891 return;
893 Reference< runtime::XFormController > xController( rEvent.Source, UNO_QUERY_THROW );
894 m_pTextShell->formDeactivated( xController );
898 void FmXFormShell::disposing()
900 impl_checkDisposed();
902 FmXFormShell_BASE::disposing();
904 if ( m_pShell && !m_pShell->IsDesignMode() )
905 setActiveController( NULL, true );
906 // do NOT save the content of the old form (the second parameter tells this)
907 // if we're here, then we expect that PrepareClose has been called, and thus the user
908 // got a chance to commit or reject any changes. So in case we're here and there
909 // are still uncommitted changes, the user explicitly wanted this.
911 m_pTextShell->dispose();
913 m_xAttachedFrame = NULL;
915 CloseExternalFormViewer();
917 while ( m_aLoadingPages.size() )
919 Application::RemoveUserEvent( m_aLoadingPages.front().nEventId );
920 m_aLoadingPages.pop();
924 ::osl::MutexGuard aGuard(m_aInvalidationSafety);
925 if (m_nInvalidationEvent)
927 Application::RemoveUserEvent(m_nInvalidationEvent);
928 m_nInvalidationEvent = 0;
930 if ( m_nActivationEvent )
932 Application::RemoveUserEvent( m_nActivationEvent );
933 m_nActivationEvent = 0;
938 ::osl::ClearableMutexGuard aGuard(m_aAsyncSafety);
939 aGuard.clear();
941 DBG_ASSERT(!m_nInvalidationEvent, "FmXFormShell::~FmXFormShell : still have an invalidation event !");
942 // should habe been deleted while beeing disposed
944 m_aMarkTimer.Stop();
947 DisableNotification();
949 RemoveElement( m_xForms );
950 m_xForms.clear();
952 impl_switchActiveControllerListening( false );
953 m_xActiveController = NULL;
954 m_xActiveForm = NULL;
956 m_pShell = NULL;
957 m_xNavigationController = NULL;
958 m_xCurrentForm = NULL;
959 m_xLastGridFound = NULL;
960 m_xAttachedFrame = NULL;
961 m_xExternalViewController = NULL;
962 m_xExtViewTriggerController = NULL;
963 m_xExternalDisplayedForm = NULL;
964 m_xLastGridFound = NULL;
966 InterfaceBag aEmpty;
967 m_aCurrentSelection.swap( aEmpty );
969 m_aActiveControllerFeatures.dispose();
970 m_aNavControllerFeatures.dispose();
974 void FmXFormShell::UpdateSlot( sal_Int16 _nId )
976 if ( impl_checkDisposed() )
977 return;
979 ::osl::MutexGuard aGuard(m_aInvalidationSafety);
981 if ( m_nLockSlotInvalidation )
983 OSL_FAIL( "FmXFormShell::UpdateSlot: cannot update if invalidation is currently locked!" );
984 InvalidateSlot( _nId, false );
986 else
988 OSL_ENSURE( _nId, "FmXFormShell::UpdateSlot: can't update the complete shell!" );
989 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( _nId, true, true );
990 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update( _nId );
995 void FmXFormShell::InvalidateSlot( sal_Int16 nId, bool bWithId )
997 if ( impl_checkDisposed() )
998 return;
1000 ::osl::MutexGuard aGuard(m_aInvalidationSafety);
1001 if (m_nLockSlotInvalidation)
1003 sal_uInt8 nFlags = ( bWithId ? 0x01 : 0 );
1004 m_arrInvalidSlots.push_back( InvalidSlotInfo(nId, nFlags) );
1006 else
1007 if (nId)
1008 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(nId, true, bWithId);
1009 else
1010 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
1014 void FmXFormShell::LockSlotInvalidation(bool bLock)
1016 if ( impl_checkDisposed() )
1017 return;
1019 ::osl::MutexGuard aGuard(m_aInvalidationSafety);
1020 DBG_ASSERT(bLock || m_nLockSlotInvalidation>0, "FmXFormShell::LockSlotInvalidation : invalid call !");
1022 if (bLock)
1023 ++m_nLockSlotInvalidation;
1024 else if (!--m_nLockSlotInvalidation)
1026 // alles, was sich waehrend der gelockten Phase angesammelt hat, (asynchron) invalidieren
1027 if (!m_nInvalidationEvent)
1028 m_nInvalidationEvent = Application::PostUserEvent(LINK(this, FmXFormShell, OnInvalidateSlots));
1033 IMPL_LINK_NOARG(FmXFormShell, OnInvalidateSlots)
1035 if ( impl_checkDisposed() )
1036 return 0L;
1038 ::osl::MutexGuard aGuard(m_aInvalidationSafety);
1039 m_nInvalidationEvent = 0;
1041 for (std::vector<InvalidSlotInfo>::const_iterator i = m_arrInvalidSlots.begin(); i < m_arrInvalidSlots.end(); ++i)
1043 if (i->id)
1044 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(i->id, true, (i->flags & 0x01));
1045 else
1046 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
1048 m_arrInvalidSlots.clear();
1049 return 0L;
1053 void FmXFormShell::ForceUpdateSelection(bool bAllowInvalidation)
1055 if ( impl_checkDisposed() )
1056 return;
1058 if (IsSelectionUpdatePending())
1060 m_aMarkTimer.Stop();
1062 // die Invalidierung der Slots, die implizit von SetSelection besorgt wird, eventuell abschalten
1063 if (!bAllowInvalidation)
1064 LockSlotInvalidation(true);
1066 SetSelection(m_pShell->GetFormView()->GetMarkedObjectList());
1068 if (!bAllowInvalidation)
1069 LockSlotInvalidation(false);
1074 PopupMenu* FmXFormShell::GetConversionMenu()
1077 PopupMenu* pNewMenu = new PopupMenu(SVX_RES( RID_FMSHELL_CONVERSIONMENU ));
1079 ImageList aImageList( SVX_RES( RID_SVXIMGLIST_FMEXPL) );
1080 for ( size_t i = 0; i < sizeof (nConvertSlots) / sizeof (nConvertSlots[0]); ++i )
1082 // das entsprechende Image dran
1083 pNewMenu->SetItemImage(nConvertSlots[i], aImageList.GetImage(nCreateSlots[i]));
1086 return pNewMenu;
1090 bool FmXFormShell::isControlConversionSlot( sal_uInt16 nSlotId )
1092 for ( size_t i = 0; i < sizeof (nConvertSlots) / sizeof (nConvertSlots[0]); ++i )
1093 if (nConvertSlots[i] == nSlotId)
1094 return true;
1095 return false;
1099 bool FmXFormShell::executeControlConversionSlot( sal_uInt16 _nSlotId )
1101 OSL_PRECOND( canConvertCurrentSelectionToControl( _nSlotId ), "FmXFormShell::executeControlConversionSlot: illegal call!" );
1102 InterfaceBag::const_iterator aSelectedElement = m_aCurrentSelection.begin();
1103 if ( aSelectedElement == m_aCurrentSelection.end() )
1104 return false;
1106 return executeControlConversionSlot( Reference< XFormComponent >( *aSelectedElement, UNO_QUERY ), _nSlotId );
1110 bool FmXFormShell::executeControlConversionSlot( const Reference< XFormComponent >& _rxObject, sal_uInt16 _nSlotId )
1112 if ( impl_checkDisposed() )
1113 return false;
1115 OSL_ENSURE( _rxObject.is(), "FmXFormShell::executeControlConversionSlot: invalid object!" );
1116 if ( !_rxObject.is() )
1117 return false;
1119 SdrPage* pPage = m_pShell->GetCurPage();
1120 FmFormPage* pFormPage = pPage ? dynamic_cast< FmFormPage* >( pPage ) : NULL;
1121 OSL_ENSURE( pFormPage, "FmXFormShell::executeControlConversionSlot: no current (form) page!" );
1122 if ( !pFormPage )
1123 return false;
1125 OSL_ENSURE( isSolelySelected( _rxObject ),
1126 "FmXFormShell::executeControlConversionSlot: hmm ... shouldn't this parameter be redundant?" );
1128 for ( size_t lookupSlot = 0; lookupSlot < sizeof( nConvertSlots ) / sizeof( nConvertSlots[0] ); ++lookupSlot )
1130 if (nConvertSlots[lookupSlot] == _nSlotId)
1132 Reference< XInterface > xNormalizedObject( _rxObject, UNO_QUERY );
1134 FmFormObj* pFormObject = NULL;
1135 SdrObjListIter aPageIter( *pFormPage );
1136 while ( aPageIter.IsMore() )
1138 SdrObject* pCurrent = aPageIter.Next();
1139 pFormObject = FmFormObj::GetFormObject( pCurrent );
1140 if ( !pFormObject )
1141 continue;
1143 Reference< XInterface > xCurrentNormalized( pFormObject->GetUnoControlModel(), UNO_QUERY );
1144 if ( xCurrentNormalized.get() == xNormalizedObject.get() )
1145 break;
1147 pFormObject = NULL;
1150 if ( !pFormObject )
1151 return false;
1153 OUString sNewName( getServiceNameByControlType( nObjectTypes[ lookupSlot ] ) );
1154 Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
1155 Reference< XControlModel> xNewModel( xContext->getServiceManager()->createInstanceWithContext(sNewName, xContext), UNO_QUERY );
1156 if (!xNewModel.is())
1157 return false;
1159 Reference< XControlModel> xOldModel( pFormObject->GetUnoControlModel() );
1160 Reference< XServiceInfo> xModelInfo(xOldModel, UNO_QUERY);
1162 // Properties uebertragen
1163 Reference< XPropertySet> xOldSet(xOldModel, UNO_QUERY);
1164 Reference< XPropertySet> xNewSet(xNewModel, UNO_QUERY);
1167 Locale aNewLanguage = Application::GetSettings().GetUILanguageTag().getLocale();
1168 TransferFormComponentProperties(xOldSet, xNewSet, aNewLanguage);
1170 Sequence< ::com::sun::star::script::ScriptEventDescriptor> aOldScripts;
1171 Reference< XChild> xChild(xOldModel, UNO_QUERY);
1172 if (xChild.is())
1174 Reference< XIndexAccess> xParent(xChild->getParent(), UNO_QUERY);
1176 // remember old script events
1177 Reference< ::com::sun::star::script::XEventAttacherManager> xEvManager(xChild->getParent(), UNO_QUERY);
1178 if (xParent.is() && xEvManager.is())
1180 sal_Int32 nIndex = getElementPos(xParent, xOldModel);
1181 if (nIndex>=0 && nIndex<xParent->getCount())
1182 aOldScripts = xEvManager->getScriptEvents(nIndex);
1185 // replace the mdoel within the parent container
1186 Reference< XIndexContainer> xIndexParent(xChild->getParent(), UNO_QUERY);
1187 if (xIndexParent.is())
1189 // the form container works with FormComponents
1190 Reference< XFormComponent> xComponent(xNewModel, UNO_QUERY);
1191 DBG_ASSERT(xComponent.is(), "FmXFormShell::executeControlConversionSlot: the new model is no form component !");
1192 Any aNewModel(makeAny(xComponent));
1196 sal_Int32 nIndex = getElementPos(xParent, xOldModel);
1197 if (nIndex>=0 && nIndex<xParent->getCount())
1198 xIndexParent->replaceByIndex(nIndex, aNewModel);
1199 else
1201 OSL_FAIL("FmXFormShell::executeControlConversionSlot: could not replace the model !");
1202 Reference< ::com::sun::star::lang::XComponent> xNewComponent(xNewModel, UNO_QUERY);
1203 if (xNewComponent.is())
1204 xNewComponent->dispose();
1205 return false;
1208 catch(Exception&)
1210 OSL_FAIL("FmXFormShell::executeControlConversionSlot: could not replace the model !");
1211 Reference< ::com::sun::star::lang::XComponent> xNewComponent(xNewModel, UNO_QUERY);
1212 if (xNewComponent.is())
1213 xNewComponent->dispose();
1214 return false;
1220 // special handling for the LabelControl-property : can only be set when the model is placed
1221 // within the forms hierarchy
1222 if (::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xOldSet) && ::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xNewSet))
1226 xNewSet->setPropertyValue(FM_PROP_CONTROLLABEL, xOldSet->getPropertyValue(FM_PROP_CONTROLLABEL));
1228 catch(Exception&)
1234 // neues Model setzen
1235 pFormObject->SetChanged();
1236 pFormObject->SetUnoControlModel(xNewModel);
1238 // transfer script events
1239 // (do this _after_ SetUnoControlModel as we need the new (implicitly created) control)
1240 if (aOldScripts.getLength())
1242 // das Control zum Model suchen
1243 Reference< XControlContainer > xControlContainer( getControlContainerForView() );
1245 Sequence< Reference< XControl> > aControls( xControlContainer->getControls() );
1246 const Reference< XControl>* pControls = aControls.getConstArray();
1248 sal_uInt32 nLen = aControls.getLength();
1249 Reference< XControl> xControl;
1250 for (sal_uInt32 i=0 ; i<nLen; ++i)
1252 if (pControls[i]->getModel() == xNewModel)
1254 xControl = pControls[i];
1255 break;
1258 TransferEventScripts(xNewModel, xControl, aOldScripts);
1261 // transfer value bindings, if possible
1263 Reference< XBindableValue > xOldBindable( xOldModel, UNO_QUERY );
1264 Reference< XBindableValue > xNewBindable( xNewModel, UNO_QUERY );
1265 if ( xOldBindable.is() )
1269 if ( xNewBindable.is() )
1270 xNewBindable->setValueBinding( xOldBindable->getValueBinding() );
1271 xOldBindable->setValueBinding( NULL );
1273 catch(const Exception&)
1275 DBG_UNHANDLED_EXCEPTION();
1279 // same for list entry sources
1281 Reference< XListEntrySink > xOldSink( xOldModel, UNO_QUERY );
1282 Reference< XListEntrySink > xNewSink( xNewModel, UNO_QUERY );
1283 if ( xOldSink.is() )
1287 if ( xNewSink.is() )
1288 xNewSink->setListEntrySource( xOldSink->getListEntrySource() );
1289 xOldSink->setListEntrySource( NULL );
1291 catch(const Exception&)
1293 DBG_UNHANDLED_EXCEPTION();
1298 // create an undo action
1299 FmFormModel* pModel = m_pShell->GetFormModel();
1300 DBG_ASSERT(pModel != NULL, "FmXFormShell::executeControlConversionSlot: my shell has no model !");
1301 if (pModel && pModel->IsUndoEnabled() )
1303 pModel->AddUndo(new FmUndoModelReplaceAction(*pModel, pFormObject, xOldModel));
1305 else
1307 FmUndoModelReplaceAction::DisposeElement( xOldModel );
1310 return true;
1313 return false;
1317 bool FmXFormShell::canConvertCurrentSelectionToControl( sal_Int16 nConversionSlot )
1319 if ( m_aCurrentSelection.empty() )
1320 return false;
1322 InterfaceBag::const_iterator aCheck = m_aCurrentSelection.begin();
1323 Reference< XServiceInfo > xElementInfo( *aCheck, UNO_QUERY );
1324 if ( !xElementInfo.is() )
1325 // no service info -> cannot determine this
1326 return false;
1328 if ( ++aCheck != m_aCurrentSelection.end() )
1329 // more than one element
1330 return false;
1332 if ( Reference< XForm >::query( xElementInfo ).is() )
1333 // it's a form
1334 return false;
1336 sal_Int16 nObjectType = getControlTypeByObject( xElementInfo );
1338 if ( ( OBJ_FM_HIDDEN == nObjectType )
1339 || ( OBJ_FM_CONTROL == nObjectType )
1340 || ( OBJ_FM_GRID == nObjectType )
1342 return false; // those types cannot be converted
1344 DBG_ASSERT(sizeof(nConvertSlots)/sizeof(nConvertSlots[0]) == sizeof(nObjectTypes)/sizeof(nObjectTypes[0]),
1345 "FmXFormShell::canConvertCurrentSelectionToControl: nConvertSlots & nObjectTypes must have the same size !");
1347 for ( size_t i = 0; i < sizeof( nConvertSlots ) / sizeof( nConvertSlots[0] ); ++i )
1348 if (nConvertSlots[i] == nConversionSlot)
1349 return nObjectTypes[i] != nObjectType;
1351 return true; // all other slots: assume "yes"
1355 void FmXFormShell::checkControlConversionSlotsForCurrentSelection( Menu& rMenu )
1357 for (sal_Int16 i=0; i<rMenu.GetItemCount(); ++i)
1358 // der Context ist schon von einem Typ, der dem Eitnrag entspricht -> disable
1359 rMenu.EnableItem( rMenu.GetItemId(i), canConvertCurrentSelectionToControl( rMenu.GetItemId( i ) ) );
1363 void FmXFormShell::LoopGrids(sal_Int16 nWhat)
1365 if ( impl_checkDisposed() )
1366 return;
1368 Reference< XIndexContainer> xControlModels(m_xActiveForm, UNO_QUERY);
1369 if (xControlModels.is())
1371 for (sal_Int16 i=0; i<xControlModels->getCount(); ++i)
1373 Reference< XPropertySet> xModelSet;
1374 xControlModels->getByIndex(i) >>= xModelSet;
1375 if (!xModelSet.is())
1376 continue;
1378 if (!::comphelper::hasProperty(FM_PROP_CLASSID, xModelSet))
1379 continue;
1380 sal_Int16 nClassId = ::comphelper::getINT16(xModelSet->getPropertyValue(FM_PROP_CLASSID));
1381 if (FormComponentType::GRIDCONTROL != nClassId)
1382 continue;
1384 if (!::comphelper::hasProperty(FM_PROP_CURSORCOLOR, xModelSet) || !::comphelper::hasProperty(FM_PROP_ALWAYSSHOWCURSOR, xModelSet) || !::comphelper::hasProperty(FM_PROP_DISPLAYSYNCHRON, xModelSet))
1385 continue;
1387 switch (nWhat & GA_SYNC_MASK)
1389 case GA_DISABLE_SYNC:
1391 sal_Bool bB(sal_False);
1392 xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
1394 break;
1395 case GA_FORCE_SYNC:
1397 Any aOldVal( xModelSet->getPropertyValue(FM_PROP_DISPLAYSYNCHRON) );
1398 sal_Bool bB(sal_True);
1399 xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
1400 xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, aOldVal);
1402 break;
1403 case GA_ENABLE_SYNC:
1405 sal_Bool bB(sal_True);
1406 xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
1408 break;
1411 if (nWhat & GA_DISABLE_ROCTRLR)
1413 sal_Bool bB(sal_False);
1414 xModelSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any(&bB,getBooleanCppuType()));
1415 Reference< XPropertyState> xModelPropState(xModelSet, UNO_QUERY);
1416 if (xModelPropState.is())
1417 xModelPropState->setPropertyToDefault(FM_PROP_CURSORCOLOR);
1418 else
1419 xModelSet->setPropertyValue(FM_PROP_CURSORCOLOR, Any()); // this should be the default
1421 else if (nWhat & GA_ENABLE_ROCTRLR)
1423 sal_Bool bB(sal_True);
1424 xModelSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any(&bB,getBooleanCppuType()));
1425 xModelSet->setPropertyValue(FM_PROP_CURSORCOLOR, makeAny(sal_Int32(COL_LIGHTRED)));
1432 Reference< XControlContainer > FmXFormShell::getControlContainerForView()
1434 if ( impl_checkDisposed() )
1435 return NULL;
1437 SdrPageView* pPageView = NULL;
1438 if ( m_pShell && m_pShell->GetFormView() )
1439 pPageView = m_pShell->GetFormView()->GetSdrPageView();
1441 Reference< XControlContainer> xControlContainer;
1442 if ( pPageView )
1443 xControlContainer = pPageView->GetPageWindow(0)->GetControlContainer();
1445 return xControlContainer;
1449 void FmXFormShell::ExecuteTabOrderDialog( const Reference< XTabControllerModel >& _rxForForm )
1451 if ( impl_checkDisposed() )
1452 return;
1454 OSL_PRECOND( _rxForForm.is(), "FmXFormShell::ExecuteTabOrderDialog: invalid tabbing model!" );
1455 if ( !_rxForForm.is() )
1456 return;
1460 Reference< XWindow > xParentWindow;
1461 if ( m_pShell->GetViewShell() && m_pShell->GetViewShell()->GetViewFrame() )
1462 xParentWindow = VCLUnoHelper::GetInterface ( &m_pShell->GetViewShell()->GetViewFrame()->GetWindow() );
1464 Reference< dialogs::XExecutableDialog > xDialog = form::TabOrderDialog::createWithModel(
1465 comphelper::getProcessComponentContext(),
1466 _rxForForm, getControlContainerForView(), xParentWindow
1469 xDialog->execute();
1471 catch( const Exception& )
1473 OSL_FAIL( "FmXFormShell::ExecuteTabOrderDialog: caught an exception!" );
1478 void FmXFormShell::ExecuteSearch()
1480 if ( impl_checkDisposed() )
1481 return;
1483 // eine Sammlung aller (logischen) Formulare
1484 FmFormArray aEmpty;
1485 m_aSearchForms.swap( aEmpty );
1486 ::std::vector< OUString > aContextNames;
1487 impl_collectFormSearchContexts_nothrow( m_pShell->GetCurPage()->GetForms(), OUString(), m_aSearchForms, aContextNames );
1489 if ( m_aSearchForms.size() != aContextNames.size() )
1491 SAL_WARN ( "svx.form", "FmXFormShell::ExecuteSearch: nonsense!" );
1492 return;
1495 // filter out the forms which do not contain valid controls at all
1497 FmFormArray aValidForms;
1498 ::std::vector< OUString > aValidContexts;
1499 FmFormArray::const_iterator form = m_aSearchForms.begin();
1500 ::std::vector< OUString >::const_iterator contextName = aContextNames.begin();
1501 for ( ; form != m_aSearchForms.end(); ++form, ++contextName )
1503 FmSearchContext aTestContext;
1504 aTestContext.nContext = static_cast< sal_Int16 >( form - m_aSearchForms.begin() );
1505 sal_uInt32 nValidControls = OnSearchContextRequest( &aTestContext );
1506 if ( nValidControls > 0 )
1508 aValidForms.push_back( *form );
1509 aValidContexts.push_back( *contextName );
1513 m_aSearchForms.swap( aValidForms );
1514 aContextNames.swap( aValidContexts );
1517 if (m_aSearchForms.empty() )
1518 { // es gibt keine Controls, die alle Bedingungen fuer eine Suche erfuellen
1519 ErrorBox(NULL, WB_OK, SVX_RESSTR(RID_STR_NODATACONTROLS)).Execute();
1520 return;
1523 // jetzt brauche ich noch einen 'initial context'
1524 sal_Int16 nInitialContext = 0;
1525 Reference< XForm> xActiveForm( getActiveForm());
1526 for ( size_t i=0; i<m_aSearchForms.size(); ++i )
1528 if (m_aSearchForms.at(i) == xActiveForm)
1530 nInitialContext = (sal_Int16)i;
1531 break;
1535 // wenn der Dialog initial den Text des aktiven Controls anbieten soll, muss dieses ein XTextComponent-Interface habe,
1536 // ausserdem macht das nur Sinn, wenn das aktuelle Feld auch an ein Tabellen- (oder was-auch-immer-)Feld gebunden ist
1537 OUString strActiveField;
1538 OUString strInitialText;
1539 // ... das bekomme ich von meinem FormController
1540 DBG_ASSERT(m_xActiveController.is(), "FmXFormShell::ExecuteSearch : no active controller !");
1541 Reference< XControl> xActiveControl( m_xActiveController->getCurrentControl());
1542 if (xActiveControl.is())
1544 // das Control kann mir sein Model sagen ...
1545 Reference< XControlModel> xActiveModel( xActiveControl->getModel());
1546 DBG_ASSERT(xActiveModel.is(), "FmXFormShell::ExecuteSearch : active control has no model !");
1548 // das Model frage ich nach der ControlSource-Eigenschaft ...
1549 Reference< XPropertySet> xProperties(xActiveControl->getModel(), UNO_QUERY);
1550 if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xProperties) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xProperties))
1552 Reference< XPropertySet> xField;
1553 xProperties->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField;
1554 if (xField.is()) // (nur wenn das Ding wirklich gebunden ist)
1556 // und das Control selber nach einem TextComponent-Interface (damit ich mir dort den Text abholen kann)
1557 Reference< XTextComponent> xText(xActiveControl, UNO_QUERY);
1558 if (xText.is())
1560 strActiveField = getLabelName(xProperties).getStr();
1561 strInitialText = xText->getText().getStr();
1565 else
1567 // das Control selber hat keine ControlSource, aber vielleicht ist es ein GridControl
1568 Reference< XGrid> xGrid(xActiveControl, UNO_QUERY);
1569 if (xGrid.is())
1571 // fuer strActiveField brauche ich die die ControlSource der Column, dafuer den Columns-Container, dafuer die
1572 // GridPeer
1573 Reference< XGridPeer> xGridPeer(xActiveControl->getPeer(), UNO_QUERY);
1574 Reference< XIndexAccess> xColumns;
1575 if (xGridPeer.is())
1576 xColumns = Reference< XIndexAccess>(xGridPeer->getColumns(),UNO_QUERY);
1578 sal_Int16 nViewCol = xGrid->getCurrentColumnPosition();
1579 sal_Int16 nModelCol = GridView2ModelPos(xColumns, nViewCol);
1580 Reference< XPropertySet> xCurrentCol;
1581 if(xColumns.is())
1582 xColumns->getByIndex(nModelCol) >>= xCurrentCol;
1583 if (xCurrentCol.is())
1584 strActiveField = ::comphelper::getString(xCurrentCol->getPropertyValue(FM_PROP_LABEL)).getStr();
1586 // the text fo the current column
1587 Reference< XIndexAccess> xColControls(xGridPeer, UNO_QUERY);
1588 Reference< XInterface> xCurControl;
1589 xColControls->getByIndex(nViewCol) >>= xCurControl;
1590 OUString sInitialText;
1591 if (IsSearchableControl(xCurControl, &sInitialText))
1592 strInitialText = sInitialText.getStr();
1597 // um eventuelle GridControls, die ich kenne, kuemmern
1598 LoopGrids(GA_DISABLE_SYNC /*| GA_ENABLE_ROCTRLR*/);
1600 // jetzt bin ich reif fuer den Dialog
1601 // wenn die potentiellen Deadlocks, die durch die Benutzung des Solar-Mutex in MTs VCLX...-Klasen entstehen, irgendwann mal
1602 // ausgeraeumt sind, sollte hier ein SM_USETHREAD rein, denn die Suche in einem eigenen Thread ist doch etwas fluessiger
1603 // sollte allerdings irgendwie von dem unterliegenden Cursor abhaengig gemacht werden, DAO zum Beispiel ist nicht thread-sicher
1604 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1605 AbstractFmSearchDialog* pDialog = NULL;
1606 if ( pFact )
1607 pDialog = pFact->CreateFmSearchDialog( &m_pShell->GetViewShell()->GetViewFrame()->GetWindow(), strInitialText, aContextNames, nInitialContext, LINK( this, FmXFormShell, OnSearchContextRequest ) );
1608 DBG_ASSERT( pDialog, "FmXFormShell::ExecuteSearch: could not create the search dialog!" );
1609 if ( pDialog )
1611 pDialog->SetActiveField( strActiveField );
1612 pDialog->SetFoundHandler( LINK( this, FmXFormShell, OnFoundData ) );
1613 pDialog->SetCanceledNotFoundHdl( LINK( this, FmXFormShell, OnCanceledNotFound ) );
1614 pDialog->Execute();
1615 delete pDialog;
1618 // GridControls wieder restaurieren
1619 LoopGrids(GA_ENABLE_SYNC | GA_DISABLE_ROCTRLR);
1621 m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView());
1622 // da ich in OnFoundData (fals ich dort war) Controls markiert habe
1626 bool FmXFormShell::GetY2KState(sal_uInt16& n)
1628 if ( impl_checkDisposed() )
1629 return false;
1631 if (m_pShell->IsDesignMode())
1632 // im Design-Modus (ohne aktive Controls) soll sich das Haupt-Dokument darum kuemmern
1633 return false;
1635 Reference< XForm> xForm( getActiveForm());
1636 if (!xForm.is())
1637 // kein aktuelles Formular (also insbesondere kein aktuelles Control) -> das Haupt-Dokument soll sich kuemmern
1638 return false;
1640 Reference< XRowSet> xDB(xForm, UNO_QUERY);
1641 DBG_ASSERT(xDB.is(), "FmXFormShell::GetY2KState : current form has no dbform-interface !");
1643 Reference< XNumberFormatsSupplier> xSupplier( getNumberFormats(OStaticDataAccessTools().getRowSetConnection(xDB), false));
1644 if (xSupplier.is())
1646 Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
1647 if (xSet.is())
1651 Any aVal( xSet->getPropertyValue("TwoDigitDateStart") );
1652 aVal >>= n;
1653 return true;
1655 catch(Exception&)
1661 return false;
1665 void FmXFormShell::SetY2KState(sal_uInt16 n)
1667 if ( impl_checkDisposed() )
1668 return;
1670 Reference< XForm > xActiveForm( getActiveForm());
1671 Reference< XRowSet > xActiveRowSet( xActiveForm, UNO_QUERY );
1672 if ( xActiveRowSet.is() )
1674 Reference< XNumberFormatsSupplier > xSupplier( getNumberFormats( getRowSetConnection( xActiveRowSet ), false ) );
1675 if (xSupplier.is())
1677 Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
1678 if (xSet.is())
1682 Any aVal;
1683 aVal <<= n;
1684 xSet->setPropertyValue("TwoDigitDateStart", aVal);
1686 catch(Exception&)
1688 OSL_FAIL("FmXFormShell::SetY2KState: Exception occurred!");
1692 return;
1696 // kein aktives Formular gefunden -> alle aktuell vorhandenen Formulare durchiterieren
1697 Reference< XIndexAccess> xCurrentForms( m_xForms);
1698 if (!xCurrentForms.is())
1699 { // im alive-Modus sind meine Forms nicht gesetzt, wohl aber die an der Page
1700 if (m_pShell->GetCurPage())
1701 xCurrentForms = Reference< XIndexAccess>( m_pShell->GetCurPage()->GetForms( false ), UNO_QUERY );
1703 if (!xCurrentForms.is())
1704 return;
1706 ::comphelper::IndexAccessIterator aIter(xCurrentForms);
1707 Reference< XInterface> xCurrentElement( aIter.Next());
1708 while (xCurrentElement.is())
1710 // ist das aktuelle Element eine DatabaseForm ?
1711 Reference< XRowSet> xElementAsRowSet( xCurrentElement, UNO_QUERY );
1712 if ( xElementAsRowSet.is() )
1714 Reference< XNumberFormatsSupplier > xSupplier( getNumberFormats( getRowSetConnection( xElementAsRowSet ), false ) );
1715 if (!xSupplier.is())
1716 continue;
1718 Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
1719 if (xSet.is())
1723 Any aVal;
1724 aVal <<= n;
1725 xSet->setPropertyValue("TwoDigitDateStart", aVal);
1727 catch(Exception&)
1729 OSL_FAIL("FmXFormShell::SetY2KState: Exception occurred!");
1734 xCurrentElement = aIter.Next();
1739 void FmXFormShell::CloseExternalFormViewer()
1741 if ( impl_checkDisposed() )
1742 return;
1744 if (!m_xExternalViewController.is())
1745 return;
1747 Reference< ::com::sun::star::frame::XFrame> xExternalViewFrame( m_xExternalViewController->getFrame());
1748 Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
1749 if (!xCommLink.is())
1750 return;
1752 xExternalViewFrame->setComponent(NULL,NULL);
1753 ::comphelper::disposeComponent(xExternalViewFrame);
1754 m_xExternalViewController = NULL;
1755 m_xExtViewTriggerController = NULL;
1756 m_xExternalDisplayedForm = NULL;
1760 Reference< XResultSet> FmXFormShell::getInternalForm(const Reference< XResultSet>& _xForm) const
1762 if ( impl_checkDisposed() )
1763 return NULL;
1765 Reference< runtime::XFormController> xExternalCtrlr(m_xExternalViewController, UNO_QUERY);
1766 if (xExternalCtrlr.is() && (_xForm == xExternalCtrlr->getModel()))
1768 DBG_ASSERT(m_xExternalDisplayedForm.is(), "FmXFormShell::getInternalForm : invalid external form !");
1769 return m_xExternalDisplayedForm;
1771 return _xForm;
1775 Reference< XForm> FmXFormShell::getInternalForm(const Reference< XForm>& _xForm) const
1777 if ( impl_checkDisposed() )
1778 return NULL;
1780 Reference< runtime::XFormController > xExternalCtrlr(m_xExternalViewController, UNO_QUERY);
1781 if (xExternalCtrlr.is() && (_xForm == xExternalCtrlr->getModel()))
1783 DBG_ASSERT(m_xExternalDisplayedForm.is(), "FmXFormShell::getInternalForm : invalid external form !");
1784 return Reference< XForm>(m_xExternalDisplayedForm, UNO_QUERY);
1786 return _xForm;
1790 namespace
1792 static bool lcl_isNavigationRelevant( sal_Int32 _nWhich )
1794 return ( _nWhich == SID_FM_RECORD_FIRST )
1795 || ( _nWhich == SID_FM_RECORD_PREV )
1796 || ( _nWhich == SID_FM_RECORD_NEXT )
1797 || ( _nWhich == SID_FM_RECORD_LAST )
1798 || ( _nWhich == SID_FM_RECORD_NEW );
1803 bool FmXFormShell::IsFormSlotEnabled( sal_Int32 _nSlot, FeatureState* _pCompleteState )
1805 const ::svx::ControllerFeatures& rController =
1806 lcl_isNavigationRelevant( _nSlot )
1807 ? getNavControllerFeatures()
1808 : getActiveControllerFeatures();
1810 if ( !_pCompleteState )
1811 return rController->isEnabled( _nSlot );
1813 rController->getState( _nSlot, *_pCompleteState );
1814 return _pCompleteState->Enabled;
1818 void FmXFormShell::ExecuteFormSlot( sal_Int32 _nSlot )
1820 const ::svx::ControllerFeatures& rController =
1821 lcl_isNavigationRelevant( _nSlot )
1822 ? getNavControllerFeatures()
1823 : getActiveControllerFeatures();
1825 rController->execute( _nSlot );
1827 if ( _nSlot == SID_FM_RECORD_UNDO )
1829 // if we're doing an UNDO, *and* if the affected form is the form which we also display
1830 // as external view, then we need to reset the controls of the external form, too
1831 if ( getInternalForm( getActiveForm() ) == m_xExternalDisplayedForm )
1833 Reference< XIndexAccess > xContainer( m_xExternalDisplayedForm, UNO_QUERY );
1834 if ( xContainer.is() )
1836 Reference< XReset > xReset;
1837 for ( sal_Int32 i = 0; i < xContainer->getCount(); ++i )
1839 if ( ( xContainer->getByIndex( i ) >>= xReset ) && xReset.is() )
1841 // no resets on sub forms
1842 Reference< XForm > xAsForm( xReset, UNO_QUERY );
1843 if ( !xAsForm.is() )
1844 xReset->reset();
1853 void FmXFormShell::impl_switchActiveControllerListening( const bool _bListen )
1855 Reference< XComponent> xComp( m_xActiveController, UNO_QUERY );
1856 if ( !xComp.is() )
1857 return;
1859 if ( _bListen )
1860 xComp->addEventListener( (XFormControllerListener*)this );
1861 else
1862 xComp->removeEventListener( (XFormControllerListener*)this );
1866 void FmXFormShell::setActiveController( const Reference< runtime::XFormController >& xController, bool _bNoSaveOldContent )
1868 if ( impl_checkDisposed() )
1869 return;
1871 if (m_bChangingDesignMode)
1872 return;
1873 DBG_ASSERT(!m_pShell->IsDesignMode(), "nur im alive mode verwenden");
1875 // Ist die Routine ein zweites Mal gerufen worden,
1876 // dann sollte der Focus nicht mehr umgesetzt werden
1877 if (m_bInActivate)
1879 m_bSetFocus = xController != m_xActiveController;
1880 return;
1883 if (xController != m_xActiveController)
1885 ::osl::ClearableMutexGuard aGuard(m_aAsyncSafety);
1886 // switch all nav dispatchers belonging to the form of the current nav controller to 'non active'
1887 Reference< XResultSet> xNavigationForm;
1888 if (m_xNavigationController.is())
1889 xNavigationForm = Reference< XResultSet>(m_xNavigationController->getModel(), UNO_QUERY);
1890 aGuard.clear();
1892 m_bInActivate = true;
1894 // check if the 2 controllers serve different forms
1895 Reference< XResultSet> xOldForm;
1896 if (m_xActiveController.is())
1897 xOldForm = Reference< XResultSet>(m_xActiveController->getModel(), UNO_QUERY);
1898 Reference< XResultSet> xNewForm;
1899 if (xController.is())
1900 xNewForm = Reference< XResultSet>(xController->getModel(), UNO_QUERY);
1901 xOldForm = getInternalForm(xOldForm);
1902 xNewForm = getInternalForm(xNewForm);
1904 bool bDifferentForm = ( xOldForm.get() != xNewForm.get() );
1905 bool bNeedSave = bDifferentForm && !_bNoSaveOldContent;
1906 // we save the content of the old form if we move to a new form, and saving old content is allowed
1908 if ( m_xActiveController.is() && bNeedSave )
1910 // beim Wechsel des Controllers den Inhalt speichern, ein Commit
1911 // wurde bereits ausgefuehrt
1912 if ( m_aActiveControllerFeatures->commitCurrentControl() )
1914 m_bSetFocus = true;
1915 if ( m_aActiveControllerFeatures->isModifiedRow() )
1917 bool bIsNew = m_aActiveControllerFeatures->isInsertionRow();
1918 bool bResult = m_aActiveControllerFeatures->commitCurrentRecord();
1919 if ( !bResult && m_bSetFocus )
1921 // if we couldn't save the current record, set the focus back to the
1922 // current control
1923 Reference< XWindow > xWindow( m_xActiveController->getCurrentControl(), UNO_QUERY );
1924 if ( xWindow.is() )
1925 xWindow->setFocus();
1926 m_bInActivate = false;
1927 return;
1929 else if ( bResult && bIsNew )
1931 Reference< XResultSet > xCursor( m_aActiveControllerFeatures->getCursor().get() );
1932 if ( xCursor.is() )
1934 DO_SAFE( xCursor->last(); );
1941 stopListening();
1943 impl_switchActiveControllerListening( false );
1945 m_aActiveControllerFeatures.dispose();
1946 m_xActiveController = xController;
1947 if ( m_xActiveController.is() )
1948 m_aActiveControllerFeatures.assign( m_xActiveController );
1950 impl_switchActiveControllerListening( true );
1952 if ( m_xActiveController.is() )
1953 m_xActiveForm = getInternalForm( Reference< XForm >( m_xActiveController->getModel(), UNO_QUERY ) );
1954 else
1955 m_xActiveForm = NULL;
1957 startListening();
1959 // activate all dispatchers belonging to form of the new navigation controller
1960 xNavigationForm = NULL;
1961 if (m_xNavigationController.is())
1962 xNavigationForm = Reference< XResultSet>(m_xNavigationController->getModel(), UNO_QUERY);
1964 m_bInActivate = false;
1966 m_pShell->UIFeatureChanged();
1967 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
1969 InvalidateSlot(SID_FM_FILTER_NAVIGATOR_CONTROL, true);
1974 void FmXFormShell::getCurrentSelection( InterfaceBag& /* [out] */ _rSelection ) const
1976 _rSelection = m_aCurrentSelection;
1980 bool FmXFormShell::setCurrentSelectionFromMark( const SdrMarkList& _rMarkList )
1982 m_aLastKnownMarkedControls.clear();
1984 if ( ( _rMarkList.GetMarkCount() > 0 ) && isControlList( _rMarkList ) )
1985 collectInterfacesFromMarkList( _rMarkList, m_aLastKnownMarkedControls );
1987 return setCurrentSelection( m_aLastKnownMarkedControls );
1991 bool FmXFormShell::selectLastMarkedControls()
1993 return setCurrentSelection( m_aLastKnownMarkedControls );
1997 bool FmXFormShell::setCurrentSelection( const InterfaceBag& _rSelection )
1999 if ( impl_checkDisposed() )
2000 return false;
2002 DBG_ASSERT( m_pShell->IsDesignMode(), "FmXFormShell::setCurrentSelection: only to be used in design mode!" );
2004 if ( _rSelection.empty() && m_aCurrentSelection.empty() )
2005 // nothing to do
2006 return false;
2008 if ( _rSelection.size() == m_aCurrentSelection.size() )
2010 InterfaceBag::const_iterator aNew = _rSelection.begin();
2011 InterfaceBag::const_iterator aOld = m_aCurrentSelection.begin();
2012 for ( ; aNew != _rSelection.end(); ++aNew, ++aOld )
2014 OSL_ENSURE( Reference< XInterface >( *aNew, UNO_QUERY ).get() == aNew->get(), "FmXFormShell::setCurrentSelection: new interface not normalized!" );
2015 OSL_ENSURE( Reference< XInterface >( *aOld, UNO_QUERY ).get() == aOld->get(), "FmXFormShell::setCurrentSelection: old interface not normalized!" );
2017 if ( aNew->get() != aOld->get() )
2018 break;
2021 if ( aNew == _rSelection.end() )
2022 // both bags equal
2023 return false;
2026 // the following is some strange code to ensure that when you have two grid controls in a document,
2027 // only one of them can have a selected column.
2028 // TODO: this should happen elsewhere, but not here - shouldn't it?
2029 if ( !m_aCurrentSelection.empty() )
2031 Reference< XChild > xCur; if ( m_aCurrentSelection.size() == 1 ) xCur = xCur.query( *m_aCurrentSelection.begin() );
2032 Reference< XChild > xNew; if ( _rSelection.size() == 1 ) xNew = xNew.query( *_rSelection.begin() );
2034 // is there nothing to be selected, or the parents differ, and the parent of the current object
2035 // is a selection supplier, then deselect
2036 if ( xCur.is() && ( !xNew.is() || ( xCur->getParent() != xNew->getParent() ) ) )
2038 Reference< XSelectionSupplier > xSel( xCur->getParent(), UNO_QUERY );
2039 if ( xSel.is() )
2040 xSel->select( Any() );
2044 m_aCurrentSelection = _rSelection;
2046 // determine the form which all the selected objects belong to, if any
2047 Reference< XForm > xNewCurrentForm;
2048 for ( InterfaceBag::const_iterator loop = m_aCurrentSelection.begin();
2049 loop != m_aCurrentSelection.end();
2050 ++loop
2053 Reference< XForm > xThisRoundsForm( GetForm( *loop ) );
2054 OSL_ENSURE( xThisRoundsForm.is(), "FmXFormShell::setCurrentSelection: *everything* should belong to a form!" );
2056 if ( !xNewCurrentForm.is() )
2057 { // the first form we encounterd
2058 xNewCurrentForm = xThisRoundsForm;
2060 else if ( xNewCurrentForm != xThisRoundsForm )
2061 { // different forms -> no "current form" at all
2062 xNewCurrentForm.clear();
2063 break;
2067 if ( !m_aCurrentSelection.empty() )
2068 impl_updateCurrentForm( xNewCurrentForm );
2070 // ensure some slots are updated
2071 for ( size_t i = 0; i < sizeof( SelObjectSlotMap ) / sizeof( SelObjectSlotMap[0] ); ++i )
2072 InvalidateSlot( SelObjectSlotMap[i], false);
2074 return true;
2078 bool FmXFormShell::isSolelySelected( const Reference< XInterface >& _rxObject )
2080 return ( m_aCurrentSelection.size() == 1 ) && ( *m_aCurrentSelection.begin() == _rxObject );
2084 void FmXFormShell::forgetCurrentForm()
2086 if ( !m_xCurrentForm.is() )
2087 return;
2089 // reset ...
2090 impl_updateCurrentForm( NULL );
2092 // ... and try finding a new current form
2093 // #i88186# / 2008-04-12 / frank.schoenheit@sun.com
2094 impl_defaultCurrentForm_nothrow();
2098 void FmXFormShell::impl_updateCurrentForm( const Reference< XForm >& _rxNewCurForm )
2100 if ( impl_checkDisposed() )
2101 return;
2103 m_xCurrentForm = _rxNewCurForm;
2105 // propagate to the FormPage(Impl)
2106 FmFormPage* pPage = m_pShell->GetCurPage();
2107 if ( pPage )
2108 pPage->GetImpl().setCurForm( m_xCurrentForm );
2110 // ensure the UI which depends on the current form is up-to-date
2111 for ( size_t i = 0; i < sizeof( DlgSlotMap ) / sizeof( DlgSlotMap[0] ); ++i )
2112 InvalidateSlot( DlgSlotMap[i], false );
2116 void FmXFormShell::startListening()
2118 if ( impl_checkDisposed() )
2119 return;
2121 Reference< XRowSet> xDatabaseForm(m_xActiveForm, UNO_QUERY);
2122 if (xDatabaseForm.is() && getRowSetConnection(xDatabaseForm).is())
2124 Reference< XPropertySet> xActiveFormSet(m_xActiveForm, UNO_QUERY);
2125 if (xActiveFormSet.is())
2127 // wenn es eine Datenquelle gibt, dann den Listener aufbauen
2128 // TODO: this is strange - shouldn't this depend on a isLoaded instead of
2129 // a "has command value"? Finally, the command value only means that it was
2130 // intended to be loaded, not that it actually *is* loaded
2131 OUString aSource = ::comphelper::getString(xActiveFormSet->getPropertyValue(FM_PROP_COMMAND));
2132 if (!aSource.isEmpty())
2134 m_bDatabaseBar = true;
2136 xActiveFormSet->getPropertyValue(FM_PROP_NAVIGATION) >>= m_eNavigate;
2138 switch (m_eNavigate)
2140 case NavigationBarMode_PARENT:
2142 // suchen des Controllers, ueber den eine Navigation moeglich ist
2143 Reference< XChild> xChild(m_xActiveController, UNO_QUERY);
2144 Reference< runtime::XFormController > xParent;
2145 while (xChild.is())
2147 xChild = Reference< XChild>(xChild->getParent(), UNO_QUERY);
2148 xParent = Reference< runtime::XFormController >(xChild, UNO_QUERY);
2149 Reference< XPropertySet> xParentSet;
2150 if (xParent.is())
2151 xParentSet = Reference< XPropertySet>(xParent->getModel(), UNO_QUERY);
2152 if (xParentSet.is())
2154 xParentSet->getPropertyValue(FM_PROP_NAVIGATION) >>= m_eNavigate;
2155 if (m_eNavigate == NavigationBarMode_CURRENT)
2156 break;
2159 m_xNavigationController = xParent;
2161 break;
2163 case NavigationBarMode_CURRENT:
2164 m_xNavigationController = m_xActiveController;
2165 break;
2167 default:
2168 m_xNavigationController = NULL;
2169 m_bDatabaseBar = false;
2172 m_aNavControllerFeatures.dispose();
2173 if ( m_xNavigationController.is() && ( m_xNavigationController != m_xActiveController ) )
2174 m_aNavControllerFeatures.assign( m_xNavigationController );
2176 // an dem Controller, der die Navigation regelt, wg. RecordCount lauschen
2177 Reference< XPropertySet> xNavigationSet;
2178 if (m_xNavigationController.is())
2180 xNavigationSet = Reference< XPropertySet>(m_xNavigationController->getModel(), UNO_QUERY);
2181 if (xNavigationSet.is())
2182 xNavigationSet->addPropertyChangeListener(FM_PROP_ROWCOUNT,this);
2184 return;
2189 m_eNavigate = NavigationBarMode_NONE;
2190 m_bDatabaseBar = false;
2191 m_xNavigationController = NULL;
2195 void FmXFormShell::stopListening()
2197 if ( impl_checkDisposed() )
2198 return;
2200 Reference< XRowSet> xDatabaseForm(m_xActiveForm, UNO_QUERY);
2201 if ( xDatabaseForm.is() )
2203 if (m_xNavigationController.is())
2205 Reference< XPropertySet> xSet(m_xNavigationController->getModel(), UNO_QUERY);
2206 if (xSet.is())
2207 xSet->removePropertyChangeListener(FM_PROP_ROWCOUNT, this);
2212 m_bDatabaseBar = false;
2213 m_eNavigate = NavigationBarMode_NONE;
2214 m_xNavigationController = NULL;
2218 void FmXFormShell::ShowSelectionProperties( bool bShow )
2220 if ( impl_checkDisposed() )
2221 return;
2223 // if the window is already visible, only update the state
2224 bool bHasChild = m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_SHOW_PROPERTIES );
2225 if ( bHasChild && bShow )
2226 UpdateSlot( SID_FM_PROPERTY_CONTROL );
2228 // else toggle state
2229 else
2230 m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow(SID_FM_SHOW_PROPERTIES);
2232 InvalidateSlot( SID_FM_PROPERTIES, false );
2233 InvalidateSlot( SID_FM_CTL_PROPERTIES, false );
2237 IMPL_LINK(FmXFormShell, OnFoundData, FmFoundRecordInformation*, pfriWhere)
2239 if ( impl_checkDisposed() )
2240 return 0;
2242 DBG_ASSERT((pfriWhere->nContext >= 0) && (pfriWhere->nContext < (sal_Int16)m_aSearchForms.size()),
2243 "FmXFormShell::OnFoundData : ungueltiger Kontext !");
2244 Reference< XForm> xForm( m_aSearchForms.at(pfriWhere->nContext));
2245 DBG_ASSERT(xForm.is(), "FmXFormShell::OnFoundData : ungueltige Form !");
2247 Reference< XRowLocate> xCursor(xForm, UNO_QUERY);
2248 if (!xCursor.is())
2249 return 0; // was soll ich da machen ?
2251 // zum Datensatz
2254 xCursor->moveToBookmark(pfriWhere->aPosition);
2256 catch(const SQLException&)
2258 OSL_FAIL("Can position on bookmark!");
2261 LoopGrids(GA_FORCE_SYNC);
2263 // und zum Feld (dazu habe ich vor dem Start des Suchens die XVclComponent-Interfaces eingesammelt)
2264 SAL_WARN_IF(static_cast<size_t>(pfriWhere->nFieldPos) >=
2265 m_arrSearchedControls.size(),
2266 "svx.form", "FmXFormShell::OnFoundData : invalid index!");
2267 SdrObject* pObject = m_arrSearchedControls.at(pfriWhere->nFieldPos);
2269 m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView());
2270 m_pShell->GetFormView()->MarkObj(pObject, m_pShell->GetFormView()->GetSdrPageView());
2272 FmFormObj* pFormObject = FmFormObj::GetFormObject( pObject );
2273 Reference< XControlModel > xControlModel( pFormObject ? pFormObject->GetUnoControlModel() : Reference< XControlModel >() );
2274 DBG_ASSERT( xControlModel.is(), "FmXFormShell::OnFoundData: invalid control!" );
2275 if ( !xControlModel.is() )
2276 return 0;
2278 // disable the permanent cursor for the last grid we found a record
2279 if (m_xLastGridFound.is() && (m_xLastGridFound != xControlModel))
2281 Reference< XPropertySet> xOldSet(m_xLastGridFound, UNO_QUERY);
2282 xOldSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, makeAny( false ) );
2283 Reference< XPropertyState> xOldSetState(xOldSet, UNO_QUERY);
2284 if (xOldSetState.is())
2285 xOldSetState->setPropertyToDefault(FM_PROP_CURSORCOLOR);
2286 else
2287 xOldSet->setPropertyValue(FM_PROP_CURSORCOLOR, Any());
2290 // wenn das Feld sich in einem GridControl befindet, muss ich dort noch in die entsprechende Spalte gehen
2291 sal_Int32 nGridColumn = m_arrRelativeGridColumn[pfriWhere->nFieldPos];
2292 if (nGridColumn != -1)
2293 { // dummer weise muss ich mir das Control erst wieder besorgen
2294 Reference<XControl> xControl( pFormObject ? impl_getControl( xControlModel, *pFormObject ) : Reference< XControl>() );
2295 Reference< XGrid> xGrid(xControl, UNO_QUERY);
2296 DBG_ASSERT(xGrid.is(), "FmXFormShell::OnFoundData : ungueltiges Control !");
2297 // wenn eine der Asserts anschlaegt, habe ich beim Aufbauen von m_arrSearchedControls wohl was falsch gemacht
2299 // enable a permanent cursor for the grid so we can see the found text
2300 Reference< XPropertySet> xModelSet(xControlModel, UNO_QUERY);
2301 DBG_ASSERT(xModelSet.is(), "FmXFormShell::OnFoundData : invalid control model (no property set) !");
2302 xModelSet->setPropertyValue( FM_PROP_ALWAYSSHOWCURSOR, makeAny( true ) );
2303 xModelSet->setPropertyValue( FM_PROP_CURSORCOLOR, makeAny( sal_Int32( COL_LIGHTRED ) ) );
2304 m_xLastGridFound = xControlModel;
2306 if ( xGrid.is() )
2307 xGrid->setCurrentColumnPosition((sal_Int16)nGridColumn);
2310 // als der Cursor neu positioniert wurde, habe ich (in positioned) meine Formularleisten-Slots invalidiert, aber das greift
2311 // hier dummerweise nicht, da i.A. ja der (modale) Suchdialog oben ist ... also Gewalt ...
2312 sal_uInt16 nPos = 0;
2313 while (DatabaseSlotMap[nPos])
2314 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update(DatabaseSlotMap[nPos++]);
2315 // leider geht das Update im Gegensatz zum Invalidate nur mit einzelnen Slots)
2317 return 0;
2321 IMPL_LINK(FmXFormShell, OnCanceledNotFound, FmFoundRecordInformation*, pfriWhere)
2323 if ( impl_checkDisposed() )
2324 return 0;
2326 DBG_ASSERT((pfriWhere->nContext >= 0) && (pfriWhere->nContext < (sal_Int16)m_aSearchForms.size()),
2327 "FmXFormShell::OnCanceledNotFound : ungueltiger Kontext !");
2328 Reference< XForm> xForm( m_aSearchForms.at(pfriWhere->nContext));
2329 DBG_ASSERT(xForm.is(), "FmXFormShell::OnCanceledNotFound : ungueltige Form !");
2331 Reference< XRowLocate> xCursor(xForm, UNO_QUERY);
2332 if (!xCursor.is())
2333 return 0; // was soll ich da machen ?
2335 // zum Datensatz
2338 xCursor->moveToBookmark(pfriWhere->aPosition);
2340 catch(const SQLException&)
2342 OSL_FAIL("Can position on bookmark!");
2346 m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView());
2347 return 0L;
2351 IMPL_LINK(FmXFormShell, OnSearchContextRequest, FmSearchContext*, pfmscContextInfo)
2353 if ( impl_checkDisposed() )
2354 return 0;
2356 DBG_ASSERT(pfmscContextInfo->nContext < (sal_Int16)m_aSearchForms.size(), "FmXFormShell::OnSearchContextRequest : invalid parameter !");
2357 Reference< XForm> xForm( m_aSearchForms.at(pfmscContextInfo->nContext));
2358 DBG_ASSERT(xForm.is(), "FmXFormShell::OnSearchContextRequest : unexpected : invalid context !");
2360 Reference< XResultSet> xIter(xForm, UNO_QUERY);
2361 DBG_ASSERT(xIter.is(), "FmXFormShell::OnSearchContextRequest : unexpected : context has no iterator !");
2364 // assemble the list of fields to involve (that is, the ControlSources of all fields that have such a property)
2365 OUString strFieldList, sFieldDisplayNames;
2366 m_arrSearchedControls.clear();
2367 m_arrRelativeGridColumn.clear();
2369 // small problem: To mark found fields, I need SdrObjects. To determine which controls
2370 // to include in the search, I need Controls (that is, XControl interfaces). So I have
2371 // to iterate over one of them and get the other in some way. Unfortunately, there is
2372 // no direct connexion between the two worlds (except from a GetUnoControl to a
2373 // SdrUnoObject, but this requires an OutputDevice I can not do anything with.
2374 // However I can get to the Model from the Control and also from the SdrObject, and in
2375 // this way the assignment SdrObject<->Control is possible with a double loop.
2376 // The alternative to this (ugly but certainly not entirely fixable) solution would be
2377 // to renounce the caching of the SdrObjects, which would lead to significant extra
2378 // work in OnFoundData (since there I'd have to get the SdrObject first thing every
2379 // time). But since OnFoundData is usually called more often than ExecuteSeearch, I'll
2380 // do that here.
2382 Reference< XNameAccess> xValidFormFields;
2383 Reference< XColumnsSupplier> xSupplyCols(xIter, UNO_QUERY);
2384 DBG_ASSERT(xSupplyCols.is(), "FmXFormShell::OnSearchContextRequest : invalid cursor : no columns supplier !");
2385 if (xSupplyCols.is())
2386 xValidFormFields = xSupplyCols->getColumns();
2387 DBG_ASSERT(xValidFormFields.is(), "FmXFormShell::OnSearchContextRequest : form has no fields !");
2389 // current Page/Controller
2390 FmFormPage* pCurrentPage = m_pShell->GetCurPage();
2391 DBG_ASSERT(pCurrentPage!=NULL, "FmXFormShell::OnSearchContextRequest : no page !");
2392 // Search all SdrControls of this page...
2393 OUString sControlSource, aName;
2395 SdrObjListIter aPageIter( *pCurrentPage );
2396 while ( aPageIter.IsMore() )
2398 SdrObject* pCurrent = aPageIter.Next();
2399 FmFormObj* pFormObject = FmFormObj::GetFormObject( pCurrent );
2400 // note that in case pCurrent is a virtual object, pFormObject points to the referenced object
2402 if ( !pFormObject )
2403 continue;
2405 // the current object's model, in different tastes
2406 Reference< XControlModel> xControlModel( pFormObject->GetUnoControlModel() );
2407 Reference< XFormComponent > xCurrentFormComponent( xControlModel, UNO_QUERY );
2408 DBG_ASSERT( xCurrentFormComponent.is(), "FmXFormShell::OnSearchContextRequest: invalid objects!" );
2409 if ( !xCurrentFormComponent.is() )
2410 continue;
2412 // does the component belong to the form which we're interested in?
2413 if ( xCurrentFormComponent->getParent() != xForm )
2414 continue;
2416 // ... ask for the ControlSource property
2417 SearchableControlIterator iter( xCurrentFormComponent );
2418 Reference< XControl> xControl;
2419 // the control that has model xControlModel
2420 // (the following while can be passed through several times, without the Control
2421 // being modified, so I don't have to search every time from scratch)
2423 Reference< XInterface > xSearchable( iter.Next() );
2424 while ( xSearchable.is() )
2426 sControlSource = iter.getCurrentValue();
2427 if ( sControlSource.isEmpty() )
2429 // the current element has no ControlSource, so it is a GridControl (that
2430 // is the only thing that still permits the SearchableControlIteratore)
2431 xControl = impl_getControl( xControlModel, *pFormObject );
2432 DBG_ASSERT(xControl.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
2434 Reference< XGridPeer> xGridPeer;
2435 if ( xControl.is() )
2436 xGridPeer.set( xControl->getPeer(), UNO_QUERY );
2439 if (!xGridPeer.is())
2440 break;
2442 Reference< XIndexAccess> xPeerContainer(xGridPeer, UNO_QUERY);
2443 if (!xPeerContainer.is())
2444 break;
2446 Reference< XIndexAccess> xModelColumns(xGridPeer->getColumns(), UNO_QUERY);
2447 DBG_ASSERT(xModelColumns.is(), "FmXFormShell::OnSearchContextRequest : there is a grid control without columns !");
2448 // the case 'no columns' should be indicated with an empty container, I think ...
2449 DBG_ASSERT(xModelColumns->getCount() >= xPeerContainer->getCount(), "FmXFormShell::OnSearchContextRequest : impossible : have more view than model columns !");
2451 Reference< XInterface> xCurrentColumn;
2452 for (sal_Int16 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos)
2454 xPeerContainer->getByIndex(nViewPos) >>= xCurrentColumn;
2455 if (!xCurrentColumn.is())
2456 continue;
2458 // can we use this column control for searching ?
2459 if (!IsSearchableControl(xCurrentColumn))
2460 continue;
2462 sal_Int16 nModelPos = GridView2ModelPos(xModelColumns, nViewPos);
2463 Reference< XPropertySet> xCurrentColModel;
2464 xModelColumns->getByIndex(nModelPos) >>= xCurrentColModel;
2465 aName = ::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_CONTROLSOURCE));
2466 // the cursor has a field matching the control source ?
2467 if (xValidFormFields->hasByName(aName))
2469 strFieldList = strFieldList + OUString(aName.getStr()) + ";";
2471 sFieldDisplayNames = sFieldDisplayNames +
2472 OUString(::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_LABEL)).getStr()) +
2473 ";";
2475 pfmscContextInfo->arrFields.push_back(xCurrentColumn);
2477 // and the SdrOject to the Field
2478 m_arrSearchedControls.push_back(pCurrent);
2479 // the number of the column
2480 m_arrRelativeGridColumn.push_back(nViewPos);
2483 } while (false);
2485 else
2487 if (!sControlSource.isEmpty() && xValidFormFields->hasByName(sControlSource))
2489 // now I need the Control to SdrObject
2490 if (!xControl.is())
2492 xControl = impl_getControl( xControlModel, *pFormObject );
2493 DBG_ASSERT(xControl.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
2496 if (IsSearchableControl(xControl))
2498 // all tests passed -> take along in the list
2499 strFieldList = strFieldList + OUString(sControlSource.getStr()) + ";";
2501 // the label which should appear for the control :
2502 sFieldDisplayNames = sFieldDisplayNames +
2503 OUString(getLabelName(Reference< XPropertySet>(xControlModel, UNO_QUERY)).getStr()) +
2504 ";";
2506 // mark the SdrObject (accelerates the treatment in OnFoundData)
2507 m_arrSearchedControls.push_back(pCurrent);
2509 // the number of the column (here a dummy, since it is only interesting for GridControls)
2510 m_arrRelativeGridColumn.push_back(-1);
2512 // and for the formatted search...
2513 pfmscContextInfo->arrFields.push_back(xControl);
2518 xSearchable = iter.Next();
2522 strFieldList = comphelper::string::stripEnd(strFieldList, ';');
2523 sFieldDisplayNames = comphelper::string::stripEnd(sFieldDisplayNames, ';');
2525 if (pfmscContextInfo->arrFields.empty())
2527 pfmscContextInfo->arrFields.clear();
2528 pfmscContextInfo->xCursor = NULL;
2529 pfmscContextInfo->strUsedFields = "";
2530 return 0L;
2533 pfmscContextInfo->xCursor = xIter;
2534 pfmscContextInfo->strUsedFields = strFieldList;
2535 pfmscContextInfo->sFieldDisplayNames = sFieldDisplayNames;
2537 // 66463 - 31.05.99 - FS
2538 // when the cursor is a non-STANDARD RecordMode, set it back
2539 Reference< XPropertySet> xCursorSet(pfmscContextInfo->xCursor, UNO_QUERY);
2540 Reference< XResultSetUpdate> xUpdateCursor(pfmscContextInfo->xCursor, UNO_QUERY);
2541 if (xUpdateCursor.is() && xCursorSet.is())
2543 if (::comphelper::getBOOL(xCursorSet->getPropertyValue(FM_PROP_ISNEW)))
2544 xUpdateCursor->moveToCurrentRow();
2545 else if (::comphelper::getBOOL(xCursorSet->getPropertyValue(FM_PROP_ISMODIFIED)))
2546 xUpdateCursor->cancelRowUpdates();
2549 return pfmscContextInfo->arrFields.size();
2552 // XContainerListener
2554 void FmXFormShell::elementInserted(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException, std::exception)
2556 if ( impl_checkDisposed() )
2557 return;
2559 // new object to listen to
2560 Reference< XInterface> xTemp;
2561 evt.Element >>= xTemp;
2562 AddElement(xTemp);
2563 m_pShell->DetermineForms(true);
2567 void FmXFormShell::elementReplaced(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException, std::exception)
2569 if ( impl_checkDisposed() )
2570 return;
2572 Reference< XInterface> xTemp;
2573 evt.ReplacedElement >>= xTemp;
2574 RemoveElement(xTemp);
2575 evt.Element >>= xTemp;
2576 AddElement(xTemp);
2580 void FmXFormShell::elementRemoved(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException, std::exception)
2582 if ( impl_checkDisposed() )
2583 return;
2585 Reference< XInterface> xTemp;
2586 evt.Element >>= xTemp;
2587 RemoveElement(xTemp);
2588 m_pShell->DetermineForms(true);
2592 void FmXFormShell::UpdateForms( bool _bInvalidate )
2594 if ( impl_checkDisposed() )
2595 return;
2597 Reference< XIndexAccess > xForms;
2599 FmFormPage* pPage = m_pShell->GetCurPage();
2600 if ( pPage )
2602 if ( m_pShell->m_bDesignMode )
2603 xForms = xForms.query( pPage->GetForms( false ) );
2606 if ( m_xForms != xForms )
2608 RemoveElement( m_xForms );
2609 m_xForms = xForms;
2610 AddElement( m_xForms );
2613 m_pShell->DetermineForms( _bInvalidate );
2617 void FmXFormShell::AddElement(const Reference< XInterface>& _xElement)
2619 if ( impl_checkDisposed() )
2620 return;
2621 impl_AddElement_nothrow(_xElement);
2624 void FmXFormShell::impl_AddElement_nothrow(const Reference< XInterface>& Element)
2626 // am Container horchen
2627 const Reference< XIndexContainer> xContainer(Element, UNO_QUERY);
2628 if (xContainer.is())
2630 const sal_uInt32 nCount = xContainer->getCount();
2631 Reference< XInterface> xElement;
2632 for (sal_uInt32 i = 0; i < nCount; ++i)
2634 xElement.set(xContainer->getByIndex(i),UNO_QUERY);
2635 impl_AddElement_nothrow(xElement);
2638 const Reference< XContainer> xCont(Element, UNO_QUERY);
2639 if (xCont.is())
2640 xCont->addContainerListener(this);
2643 const Reference< ::com::sun::star::view::XSelectionSupplier> xSelSupplier(Element, UNO_QUERY);
2644 if (xSelSupplier.is())
2645 xSelSupplier->addSelectionChangeListener(this);
2649 void FmXFormShell::RemoveElement(const Reference< XInterface>& Element)
2651 if ( impl_checkDisposed() )
2652 return;
2653 impl_RemoveElement_nothrow(Element);
2656 void FmXFormShell::impl_RemoveElement_nothrow(const Reference< XInterface>& Element)
2658 const Reference< ::com::sun::star::view::XSelectionSupplier> xSelSupplier(Element, UNO_QUERY);
2659 if (xSelSupplier.is())
2660 xSelSupplier->removeSelectionChangeListener(this);
2662 // remove connection to children
2663 const Reference< XIndexContainer> xContainer(Element, UNO_QUERY);
2664 if (xContainer.is())
2666 const Reference< XContainer> xCont(Element, UNO_QUERY);
2667 if (xCont.is())
2668 xCont->removeContainerListener(this);
2670 const sal_uInt32 nCount = xContainer->getCount();
2671 Reference< XInterface> xElement;
2672 for (sal_uInt32 i = 0; i < nCount; i++)
2674 xElement.set(xContainer->getByIndex(i),UNO_QUERY);
2675 impl_RemoveElement_nothrow(xElement);
2679 InterfaceBag::iterator wasSelectedPos = m_aCurrentSelection.find( Element );
2680 if ( wasSelectedPos != m_aCurrentSelection.end() )
2681 m_aCurrentSelection.erase( wasSelectedPos );
2685 void FmXFormShell::selectionChanged(const EventObject& rEvent) throw(::com::sun::star::uno::RuntimeException, std::exception)
2687 if ( impl_checkDisposed() )
2688 return;
2690 Reference< XSelectionSupplier > xSupplier( rEvent.Source, UNO_QUERY );
2691 Reference< XInterface > xSelObj( xSupplier->getSelection(), UNO_QUERY );
2692 // a selection was removed, this can only be done by the shell
2693 if ( !xSelObj.is() )
2694 return;
2696 EnableTrackProperties(false);
2698 bool bMarkChanged = m_pShell->GetFormView()->checkUnMarkAll(rEvent.Source);
2699 Reference< XForm > xNewForm( GetForm( rEvent.Source ) );
2701 InterfaceBag aNewSelection;
2702 aNewSelection.insert( xSelObj );
2704 if ( setCurrentSelection( aNewSelection ) && IsPropBrwOpen() )
2705 ShowSelectionProperties( true );
2707 EnableTrackProperties(true);
2709 if ( bMarkChanged )
2710 m_pShell->NotifyMarkListChanged( m_pShell->GetFormView() );
2714 IMPL_LINK(FmXFormShell, OnTimeOut, void*, /*EMPTYTAG*/)
2716 if ( impl_checkDisposed() )
2717 return 0;
2719 if (m_pShell->IsDesignMode() && m_pShell->GetFormView())
2720 SetSelection(m_pShell->GetFormView()->GetMarkedObjectList());
2722 return 0;
2726 void FmXFormShell::SetSelectionDelayed()
2728 if ( impl_checkDisposed() )
2729 return;
2731 if (m_pShell->IsDesignMode() && IsTrackPropertiesEnabled() && !m_aMarkTimer.IsActive())
2732 m_aMarkTimer.Start();
2736 void FmXFormShell::SetSelection(const SdrMarkList& rMarkList)
2738 if ( impl_checkDisposed() )
2739 return;
2741 DetermineSelection(rMarkList);
2742 m_pShell->NotifyMarkListChanged(m_pShell->GetFormView());
2746 void FmXFormShell::DetermineSelection(const SdrMarkList& rMarkList)
2748 if ( setCurrentSelectionFromMark( rMarkList ) && IsPropBrwOpen() )
2749 ShowSelectionProperties( true );
2753 bool FmXFormShell::IsPropBrwOpen() const
2755 if ( impl_checkDisposed() )
2756 return false;
2758 return( ( m_pShell->GetViewShell() && m_pShell->GetViewShell()->GetViewFrame() ) ?
2759 m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES) : sal_False );
2763 class FmXFormShell::SuspendPropertyTracking
2765 private:
2766 FmXFormShell& m_rShell;
2767 bool m_bEnabled;
2769 public:
2770 SuspendPropertyTracking( FmXFormShell& _rShell )
2771 :m_rShell( _rShell )
2772 ,m_bEnabled( false )
2774 if ( m_rShell.IsTrackPropertiesEnabled() )
2776 m_rShell.EnableTrackProperties( false );
2777 m_bEnabled = true;
2781 ~SuspendPropertyTracking( )
2783 if ( m_bEnabled ) // note that ( false != m_bEnabled ) implies ( NULL != m_pShell )
2784 m_rShell.EnableTrackProperties( true );
2789 void FmXFormShell::SetDesignMode(bool bDesign)
2791 if ( impl_checkDisposed() )
2792 return;
2794 DBG_ASSERT(m_pShell->GetFormView(), "FmXFormShell::SetDesignMode : invalid call (have no shell or no view) !");
2795 m_bChangingDesignMode = true;
2797 // 67506 - 15.07.99 - FS
2798 // if we're switching off the design mode we have to force the property browser to be closed
2799 // so it can commit it's changes _before_ we load the forms
2800 if (!bDesign)
2802 m_bHadPropertyBrowserInDesignMode = m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES);
2803 if (m_bHadPropertyBrowserInDesignMode)
2804 m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow(SID_FM_SHOW_PROPERTIES);
2807 FmFormView* pFormView = m_pShell->GetFormView();
2808 if (bDesign)
2810 // we are currently filtering, so stop filtering
2811 if (m_bFilterMode)
2812 stopFiltering(false);
2814 // unsubscribe from the objects of my MarkList
2815 pFormView->GetImpl()->stopMarkListWatching();
2817 else
2819 m_aMarkTimer.Stop();
2821 SuspendPropertyTracking aSuspend( *this );
2822 pFormView->GetImpl()->saveMarkList( true );
2825 if (bDesign && m_xExternalViewController.is())
2826 CloseExternalFormViewer();
2828 pFormView->ChangeDesignMode(bDesign);
2830 // notify listensers
2831 FmDesignModeChangedHint aChangedHint( bDesign );
2832 m_pShell->Broadcast(aChangedHint);
2834 m_pShell->m_bDesignMode = bDesign;
2835 UpdateForms( false );
2837 m_pTextShell->designModeChanged( m_pShell->m_bDesignMode );
2839 if (bDesign)
2841 SdrMarkList aList;
2843 // during changing the mark list, don't track the selected objects in the property browser
2844 SuspendPropertyTracking aSuspend( *this );
2845 // restore the marks
2846 pFormView->GetImpl()->restoreMarkList( aList );
2849 // synchronize with the restored mark list
2850 if ( aList.GetMarkCount() )
2851 SetSelection( aList );
2853 else
2855 // subscribe to the model of the view (so that I'm informed when someone deletes
2856 // during the alive mode controls that I had saved in the saveMarklist (60343)
2857 pFormView->GetImpl()->startMarkListWatching();
2860 m_pShell->UIFeatureChanged();
2862 // 67506 - 15.07.99 - FS
2863 if (bDesign && m_bHadPropertyBrowserInDesignMode)
2865 // The UIFeatureChanged performes an update (a check of the available features) asynchronously.
2866 // So we can't call ShowSelectionProperties directly as the according feature isn't enabled yet.
2867 // That's why we use an asynchron execution on the dispatcher.
2868 // (And that's why this has to be done AFTER the UIFeatureChanged.)
2869 m_pShell->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SFX_CALLMODE_ASYNCHRON );
2871 m_bChangingDesignMode = false;
2875 Reference< XControl> FmXFormShell::impl_getControl( const Reference< XControlModel >& i_rxModel, const FmFormObj& i_rKnownFormObj )
2877 if ( impl_checkDisposed() )
2878 return NULL;
2880 Reference< XControl > xControl;
2883 Reference< XControlContainer> xControlContainer( getControlContainerForView(), UNO_SET_THROW );
2885 Sequence< Reference< XControl > > seqControls( xControlContainer->getControls() );
2886 const Reference< XControl >* pControls = seqControls.getArray();
2887 // ... that I can then search
2888 for (sal_Int32 i=0; i<seqControls.getLength(); ++i)
2890 xControl.set( pControls[i], UNO_SET_THROW );
2891 Reference< XControlModel > xCurrentModel( xControl->getModel() );
2892 if ( xCurrentModel == i_rxModel )
2893 break;
2894 xControl.clear();
2897 if ( !xControl.is() )
2899 // fallabck (some controls might not have been created, yet, since they were never visible so far)
2900 Reference< XControl > xContainerControl( xControlContainer, UNO_QUERY_THROW );
2901 const Window* pContainerWindow = VCLUnoHelper::GetWindow( xContainerControl->getPeer() );
2902 ENSURE_OR_THROW( pContainerWindow, "unexpected control container implementation" );
2904 const SdrView* pSdrView = m_pShell ? m_pShell->GetFormView() : NULL;
2905 ENSURE_OR_THROW( pSdrView, "no current view" );
2907 xControl.set( i_rKnownFormObj.GetUnoControl( *pSdrView, *pContainerWindow ), UNO_QUERY_THROW );
2910 catch( const Exception& )
2912 DBG_UNHANDLED_EXCEPTION();
2915 OSL_ENSURE( xControl.is(), "FmXFormShell::impl_getControl: no control found!" );
2916 return xControl;
2920 void FmXFormShell::impl_collectFormSearchContexts_nothrow( const Reference< XInterface>& _rxStartingPoint,
2921 const OUString& _rCurrentLevelPrefix, FmFormArray& _out_rForms, ::std::vector< OUString >& _out_rNames )
2925 Reference< XIndexAccess> xContainer( _rxStartingPoint, UNO_QUERY );
2926 if ( !xContainer.is() )
2927 return;
2929 sal_Int32 nCount( xContainer->getCount() );
2930 if ( nCount == 0 )
2931 return;
2933 OUString sCurrentFormName;
2934 OUStringBuffer aNextLevelPrefix;
2935 for ( sal_Int32 i=0; i<nCount; ++i )
2937 // is the current child a form?
2938 Reference< XForm > xCurrentAsForm( xContainer->getByIndex(i), UNO_QUERY );
2939 if ( !xCurrentAsForm.is() )
2940 continue;
2942 Reference< XNamed > xNamed( xCurrentAsForm, UNO_QUERY_THROW );
2943 sCurrentFormName = xNamed->getName();
2945 // the name of the current form
2946 OUStringBuffer sCompleteCurrentName( sCurrentFormName );
2947 if ( !_rCurrentLevelPrefix.isEmpty() )
2949 sCompleteCurrentName.appendAscii( " (" );
2950 sCompleteCurrentName.append ( _rCurrentLevelPrefix );
2951 sCompleteCurrentName.appendAscii( ")" );
2954 // the prefix for the next level
2955 aNextLevelPrefix = _rCurrentLevelPrefix;
2956 if ( !_rCurrentLevelPrefix.isEmpty() )
2957 aNextLevelPrefix.append( '/' );
2958 aNextLevelPrefix.append( sCurrentFormName );
2960 // remember both the form and it's "display name"
2961 _out_rForms.push_back( xCurrentAsForm );
2962 _out_rNames.push_back( sCompleteCurrentName.makeStringAndClear() );
2964 // und absteigen
2965 impl_collectFormSearchContexts_nothrow( xCurrentAsForm, aNextLevelPrefix.makeStringAndClear(), _out_rForms, _out_rNames );
2968 catch( const Exception& )
2970 DBG_UNHANDLED_EXCEPTION();
2975 void FmXFormShell::startFiltering()
2977 if ( impl_checkDisposed() )
2978 return;
2980 // setting all forms in filter mode
2981 FmXFormView* pXView = m_pShell->GetFormView()->GetImpl();
2983 // if the active controller is our external one we have to use the trigger controller
2984 Reference< XControlContainer> xContainer;
2985 if (getActiveController() == m_xExternalViewController)
2987 DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::startFiltering : inconsistent : active external controller, but no one triggered this !");
2988 xContainer = m_xExtViewTriggerController->getContainer();
2990 else
2991 xContainer = getActiveController()->getContainer();
2993 PFormViewPageWindowAdapter pAdapter = pXView->findWindow( xContainer );
2994 if ( pAdapter.is() )
2996 const ::std::vector< Reference< runtime::XFormController> >& rControllerList = pAdapter->GetList();
2997 for ( ::std::vector< Reference< runtime::XFormController> >::const_iterator j = rControllerList.begin();
2998 j != rControllerList.end();
3002 Reference< XModeSelector> xModeSelector(*j, UNO_QUERY);
3003 if (xModeSelector.is())
3004 xModeSelector->setMode( OUString( "FilterMode" ) );
3008 m_bFilterMode = true;
3010 m_pShell->UIFeatureChanged();
3011 SfxViewFrame* pViewFrame = m_pShell->GetViewShell()->GetViewFrame();
3012 pViewFrame->GetBindings().InvalidateShell( *m_pShell );
3014 if ( pViewFrame->KnowsChildWindow( SID_FM_FILTER_NAVIGATOR )
3015 && !pViewFrame->HasChildWindow( SID_FM_FILTER_NAVIGATOR )
3018 pViewFrame->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
3023 void saveFilter(const Reference< runtime::XFormController >& _rxController)
3025 Reference< XPropertySet> xFormAsSet(_rxController->getModel(), UNO_QUERY);
3026 Reference< XPropertySet> xControllerAsSet(_rxController, UNO_QUERY);
3027 Reference< XIndexAccess> xControllerAsIndex(_rxController, UNO_QUERY);
3029 // call the subcontroller
3030 Reference< runtime::XFormController > xController;
3031 for (sal_Int32 i = 0, nCount = xControllerAsIndex->getCount(); i < nCount; ++i)
3033 xControllerAsIndex->getByIndex(i) >>= xController;
3034 saveFilter(xController);
3040 xFormAsSet->setPropertyValue(FM_PROP_FILTER, xControllerAsSet->getPropertyValue(FM_PROP_FILTER));
3041 xFormAsSet->setPropertyValue(FM_PROP_APPLYFILTER, makeAny( true ) );
3043 catch (const Exception& )
3045 DBG_UNHANDLED_EXCEPTION();
3051 void FmXFormShell::stopFiltering(bool bSave)
3053 if ( impl_checkDisposed() )
3054 return;
3056 m_bFilterMode = false;
3058 FmXFormView* pXView = m_pShell->GetFormView()->GetImpl();
3060 // if the active controller is our external one we have to use the trigger controller
3061 Reference< XControlContainer> xContainer;
3062 if (getActiveController() == m_xExternalViewController)
3064 DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::stopFiltering : inconsistent : active external controller, but no one triggered this !");
3065 xContainer = m_xExtViewTriggerController->getContainer();
3067 else
3068 xContainer = getActiveController()->getContainer();
3070 PFormViewPageWindowAdapter pAdapter = pXView->findWindow(xContainer);
3071 if ( pAdapter.is() )
3073 const ::std::vector< Reference< runtime::XFormController > >& rControllerList = pAdapter->GetList();
3074 ::std::vector < OUString > aOriginalFilters;
3075 ::std::vector < sal_Bool > aOriginalApplyFlags;
3077 if (bSave)
3079 for (::std::vector< Reference< runtime::XFormController > > ::const_iterator j = rControllerList.begin();
3080 j != rControllerList.end(); ++j)
3082 if (bSave)
3083 { // remember the current filter settings in case we're goin to reload the forms below (which may fail)
3086 Reference< XPropertySet > xFormAsSet((*j)->getModel(), UNO_QUERY);
3087 aOriginalFilters.push_back(::comphelper::getString(xFormAsSet->getPropertyValue(FM_PROP_FILTER)));
3088 aOriginalApplyFlags.push_back(::comphelper::getBOOL(xFormAsSet->getPropertyValue(FM_PROP_APPLYFILTER)));
3090 catch(Exception&)
3092 OSL_FAIL("FmXFormShell::stopFiltering : could not get the original filter !");
3093 // put dummies into the arrays so the they have the right size
3095 if (aOriginalFilters.size() == aOriginalApplyFlags.size())
3096 // the first getPropertyValue failed -> use two dummies
3097 aOriginalFilters.push_back( OUString() );
3098 aOriginalApplyFlags.push_back( sal_False );
3101 saveFilter(*j);
3104 for (::std::vector< Reference< runtime::XFormController > > ::const_iterator j = rControllerList.begin();
3105 j != rControllerList.end(); ++j)
3108 Reference< XModeSelector> xModeSelector(*j, UNO_QUERY);
3109 if (xModeSelector.is())
3110 xModeSelector->setMode( OUString( "DataMode" ) );
3112 if (bSave) // execute the filter
3114 const ::std::vector< Reference< runtime::XFormController > > & rControllers = pAdapter->GetList();
3115 for (::std::vector< Reference< runtime::XFormController > > ::const_iterator j = rControllers.begin();
3116 j != rControllers.end(); ++j)
3118 Reference< XLoadable> xReload((*j)->getModel(), UNO_QUERY);
3119 if (!xReload.is())
3120 continue;
3121 Reference< XPropertySet > xFormSet(xReload, UNO_QUERY);
3125 xReload->reload();
3127 catch(Exception&)
3129 OSL_FAIL("FmXFormShell::stopFiltering: Exception occurred!");
3132 if (!isRowSetAlive(xFormSet))
3133 { // something went wrong -> restore the original state
3134 OUString sOriginalFilter = aOriginalFilters[ j - rControllers.begin() ];
3135 bool bOriginalApplyFlag = aOriginalApplyFlags[ j - rControllers.begin() ];
3138 xFormSet->setPropertyValue(FM_PROP_FILTER, makeAny(sOriginalFilter));
3139 xFormSet->setPropertyValue(FM_PROP_APPLYFILTER, makeAny(bOriginalApplyFlag));
3140 xReload->reload();
3142 catch(const Exception&)
3144 DBG_UNHANDLED_EXCEPTION();
3151 m_pShell->UIFeatureChanged();
3152 m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
3156 void FmXFormShell::CreateExternalView()
3158 if ( impl_checkDisposed() )
3159 return;
3161 DBG_ASSERT(m_xAttachedFrame.is(), "FmXFormShell::CreateExternalView : no frame !");
3163 // the frame the external view is displayed in
3164 bool bAlreadyExistent = m_xExternalViewController.is();
3165 Reference< ::com::sun::star::frame::XFrame> xExternalViewFrame;
3166 OUString sFrameName("_beamer");
3167 sal_Int32 nSearchFlags = ::com::sun::star::frame::FrameSearchFlag::CHILDREN | ::com::sun::star::frame::FrameSearchFlag::CREATE;
3169 Reference< runtime::XFormController > xCurrentNavController( getNavController());
3170 // the creation of the "partwindow" may cause a deactivate of the document which will result in our nav controller to be set to NULL
3172 // _first_ check if we have any valid fields we can use for the grid view
3173 // FS - 21.10.99 - 69219
3175 FmXBoundFormFieldIterator aModelIterator(xCurrentNavController->getModel());
3176 Reference< XPropertySet> xCurrentModelSet;
3177 bool bHaveUsableControls = false;
3178 while ((xCurrentModelSet = Reference< XPropertySet>(aModelIterator.Next(), UNO_QUERY)).is())
3180 // the FmXBoundFormFieldIterator only supplies controls with a valid control source
3181 // so we just have to check the field type
3182 sal_Int16 nClassId = ::comphelper::getINT16(xCurrentModelSet->getPropertyValue(FM_PROP_CLASSID));
3183 switch (nClassId)
3185 case FormComponentType::IMAGECONTROL:
3186 case FormComponentType::CONTROL:
3187 continue;
3189 bHaveUsableControls = true;
3190 break;
3193 if (!bHaveUsableControls)
3195 ErrorBox(NULL, WB_OK, SVX_RESSTR(RID_STR_NOCONTROLS_FOR_EXTERNALDISPLAY)).Execute();
3196 return;
3200 // load the component for external form views
3201 if (!bAlreadyExistent)
3203 URL aWantToDispatch;
3204 aWantToDispatch.Complete = FMURL_COMPONENT_FORMGRIDVIEW;
3206 Reference< ::com::sun::star::frame::XDispatchProvider> xProv(m_xAttachedFrame, UNO_QUERY);
3207 Reference< ::com::sun::star::frame::XDispatch> xDisp;
3208 if (xProv.is())
3209 xDisp = xProv->queryDispatch(aWantToDispatch, sFrameName, nSearchFlags);
3210 if (xDisp.is())
3212 xDisp->dispatch(aWantToDispatch, Sequence< PropertyValue>());
3215 // with this the component should be loaded, now search the frame where it resides in
3216 xExternalViewFrame = m_xAttachedFrame->findFrame(sFrameName, ::com::sun::star::frame::FrameSearchFlag::CHILDREN);
3217 if (xExternalViewFrame.is())
3219 m_xExternalViewController = xExternalViewFrame->getController();
3220 Reference< ::com::sun::star::lang::XComponent> xComp(m_xExternalViewController, UNO_QUERY);
3221 if (xComp.is())
3222 xComp->addEventListener((XEventListener*)(XPropertyChangeListener*)this);
3225 else
3227 xExternalViewFrame = m_xExternalViewController->getFrame();
3228 Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
3230 // if we display the active form we interpret the slot as "remove it"
3231 Reference< XForm> xCurrentModel(xCurrentNavController->getModel(), UNO_QUERY);
3232 if ((xCurrentModel == m_xExternalDisplayedForm) || (getInternalForm(xCurrentModel) == m_xExternalDisplayedForm))
3234 if ( m_xExternalViewController == getActiveController() )
3236 Reference< runtime::XFormController > xAsFormController( m_xExternalViewController, UNO_QUERY );
3237 ControllerFeatures aHelper( xAsFormController, NULL );
3238 aHelper->commitCurrentControl();
3241 Reference< runtime::XFormController > xNewController(m_xExtViewTriggerController);
3242 CloseExternalFormViewer();
3243 setActiveController(xNewController);
3244 return;
3247 URL aClearURL;
3248 aClearURL.Complete = FMURL_GRIDVIEW_CLEARVIEW;
3250 Reference< ::com::sun::star::frame::XDispatch> xClear( xCommLink->queryDispatch(aClearURL, OUString(), 0));
3251 if (xClear.is())
3252 xClear->dispatch(aClearURL, Sequence< PropertyValue>());
3255 // TODO: We need an interceptor at the xSupplier, which forwards all queryDispatch requests to the FormController
3256 // instance for which this "external view" was triggered
3258 // get the dispatch interface of the frame so we can communicate (interceptable) with the controller
3259 Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
3261 if (m_xExternalViewController.is())
3263 DBG_ASSERT(xCommLink.is(), "FmXFormShell::CreateExternalView : the component doesn't have the necessary interfaces !");
3264 // collect the dispatchers we will need
3265 URL aAddColumnURL;
3266 aAddColumnURL.Complete = FMURL_GRIDVIEW_ADDCOLUMN;
3267 Reference< ::com::sun::star::frame::XDispatch> xAddColumnDispatch( xCommLink->queryDispatch(aAddColumnURL, OUString(), 0));
3268 URL aAttachURL;
3269 aAttachURL.Complete = FMURL_GRIDVIEW_ATTACHTOFORM;
3270 Reference< ::com::sun::star::frame::XDispatch> xAttachDispatch( xCommLink->queryDispatch(aAttachURL, OUString(), 0));
3272 if (xAddColumnDispatch.is() && xAttachDispatch.is())
3274 DBG_ASSERT(xCurrentNavController.is(), "FmXFormShell::CreateExternalView : invalid call : have no nav controller !");
3275 // first : dispatch the descriptions for the columns to add
3276 sal_Int16 nAddedColumns = 0;
3278 // for radio buttons we need some special structures
3279 typedef std::map< OUString, Sequence< OUString> > MapUString2UstringSeq;
3280 typedef std::map< OUString, OUString > FmMapUString2UString;
3281 typedef std::map< OUString, sal_Int16 > FmMapUString2Int16;
3283 MapUString2UstringSeq aRadioValueLists;
3284 MapUString2UstringSeq aRadioListSources;
3285 FmMapUString2UString aRadioControlSources;
3286 FmMapUString2Int16 aRadioPositions;
3288 FmXBoundFormFieldIterator aModelIterator(xCurrentNavController->getModel());
3289 Reference< XPropertySet> xCurrentModelSet;
3290 OUString sColumnType,aGroupName,sControlSource;
3291 Sequence< Property> aProps;
3292 Reference< XPropertySet> xCurrentBoundField;
3293 while ((xCurrentModelSet = Reference< XPropertySet>(aModelIterator.Next(), UNO_QUERY)).is())
3295 xCurrentModelSet->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xCurrentBoundField;
3296 OSL_ENSURE(xCurrentModelSet.is(),"xCurrentModelSet is null!");
3297 // create a description of the column to be created
3298 // first : determine it's type
3300 sal_Int16 nClassId = ::comphelper::getINT16(xCurrentModelSet->getPropertyValue(FM_PROP_CLASSID));
3301 switch (nClassId)
3303 case FormComponentType::RADIOBUTTON:
3305 // get the label of the button (this is the access key for our structures)
3306 aGroupName = getLabelName(xCurrentModelSet);
3308 // add the reference value of the radio button to the list source sequence
3309 Sequence< OUString>& aThisGroupLabels = aRadioListSources[aGroupName];
3310 sal_Int32 nNewSizeL = aThisGroupLabels.getLength() + 1;
3311 aThisGroupLabels.realloc(nNewSizeL);
3312 aThisGroupLabels.getArray()[nNewSizeL - 1] = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_REFVALUE));
3314 // add the label to the value list sequence
3315 Sequence< OUString>& aThisGroupControlSources = aRadioValueLists[aGroupName];
3316 sal_Int32 nNewSizeC = aThisGroupControlSources.getLength() + 1;
3317 aThisGroupControlSources.realloc(nNewSizeC);
3318 aThisGroupControlSources.getArray()[nNewSizeC - 1] = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_LABEL));
3320 // remember the controls source of the radio group
3321 sControlSource = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_CONTROLSOURCE));
3322 if (aRadioControlSources.find(aGroupName) == aRadioControlSources.end())
3323 aRadioControlSources[aGroupName] = sControlSource;
3324 #ifdef DBG_UTIL
3325 else
3326 DBG_ASSERT(aRadioControlSources[aGroupName] == sControlSource,
3327 "FmXFormShell::CreateExternalView : inconsistent radio buttons detected !");
3328 // (radio buttons with the same name should have the same control source)
3329 #endif
3330 // remember the position within the columns
3331 if (aRadioPositions.find(aGroupName) == aRadioPositions.end())
3332 aRadioPositions[aGroupName] = (sal_Int16)nAddedColumns;
3334 // any further handling is done below
3336 continue;
3338 case FormComponentType::IMAGECONTROL:
3339 case FormComponentType::CONTROL:
3340 // no grid columns for these types (though they have a control source)
3341 continue;
3342 case FormComponentType::CHECKBOX:
3343 sColumnType = FM_COL_CHECKBOX; break;
3344 case FormComponentType::LISTBOX:
3345 sColumnType = FM_COL_LISTBOX; break;
3346 case FormComponentType::COMBOBOX:
3347 sColumnType = FM_COL_COMBOBOX; break;
3348 case FormComponentType::DATEFIELD:
3349 sColumnType = FM_COL_DATEFIELD; break;
3350 case FormComponentType::TIMEFIELD:
3351 sColumnType = FM_COL_TIMEFIELD; break;
3352 case FormComponentType::NUMERICFIELD:
3353 sColumnType = FM_COL_NUMERICFIELD; break;
3354 case FormComponentType::CURRENCYFIELD:
3355 sColumnType = FM_COL_CURRENCYFIELD; break;
3356 case FormComponentType::PATTERNFIELD:
3357 sColumnType = FM_COL_PATTERNFIELD; break;
3359 case FormComponentType::TEXTFIELD:
3361 sColumnType = FM_COL_TEXTFIELD;
3362 // we know at least two different controls which are TextFields : the basic edit field and the formatted
3363 // field. we distinguish them by their service name
3364 Reference< XServiceInfo> xInfo(xCurrentModelSet, UNO_QUERY);
3365 if (xInfo.is())
3367 sal_Int16 nObjectType = getControlTypeByObject(xInfo);
3368 if (OBJ_FM_FORMATTEDFIELD == nObjectType)
3369 sColumnType = FM_COL_FORMATTEDFIELD;
3372 break;
3373 default:
3374 sColumnType = FM_COL_TEXTFIELD; break;
3377 const sal_Int16 nDispatchArgs = 3;
3378 Sequence< PropertyValue> aDispatchArgs(nDispatchArgs);
3379 PropertyValue* pDispatchArgs = aDispatchArgs.getArray();
3381 // properties describing "meta data" about the column
3382 // the type
3383 pDispatchArgs->Name = FMARG_ADDCOL_COLUMNTYPE;
3384 pDispatchArgs->Value <<= sColumnType;
3385 ++pDispatchArgs;
3387 // the pos : append the col
3388 pDispatchArgs->Name = FMARG_ADDCOL_COLUMNPOS;
3389 pDispatchArgs->Value <<= nAddedColumns;
3390 ++pDispatchArgs;
3392 // the properties to forward to the new column
3393 Sequence< PropertyValue> aColumnProps(1);
3394 PropertyValue* pColumnProps = aColumnProps.getArray();
3396 // the label
3397 pColumnProps->Name = FM_PROP_LABEL;
3398 pColumnProps->Value <<= getLabelName(xCurrentModelSet);
3399 ++pColumnProps;
3401 // for all other props : transfer them
3402 Reference< XPropertySetInfo> xControlModelInfo( xCurrentModelSet->getPropertySetInfo());
3403 DBG_ASSERT(xControlModelInfo.is(), "FmXFormShell::CreateExternalView : the control model has no property info ! This will crash !");
3404 aProps = xControlModelInfo->getProperties();
3405 const Property* pProps = aProps.getConstArray();
3407 // realloc the control description sequence
3408 sal_Int32 nExistentDescs = pColumnProps - aColumnProps.getArray();
3409 aColumnProps.realloc(nExistentDescs + aProps.getLength());
3410 pColumnProps = aColumnProps.getArray() + nExistentDescs;
3412 for (sal_Int32 i=0; i<aProps.getLength(); ++i, ++pProps)
3414 if (pProps->Name.equals(FM_PROP_LABEL))
3415 // already set
3416 continue;
3417 if (pProps->Name.equals(FM_PROP_DEFAULTCONTROL))
3418 // allow the column's own "default control"
3419 continue;
3420 if (pProps->Attributes & PropertyAttribute::READONLY)
3421 // assume that properties which are readonly for the control are ro for the column to be created, too
3422 continue;
3424 pColumnProps->Name = pProps->Name;
3425 pColumnProps->Value = xCurrentModelSet->getPropertyValue(pProps->Name);
3426 ++pColumnProps;
3428 aColumnProps.realloc(pColumnProps - aColumnProps.getArray());
3430 // columns props are a dispatch argument
3431 pDispatchArgs->Name = "ColumnProperties"; // TODO : fmurl.*
3432 pDispatchArgs->Value = makeAny(aColumnProps);
3433 ++pDispatchArgs;
3434 DBG_ASSERT(nDispatchArgs == (pDispatchArgs - aDispatchArgs.getConstArray()),
3435 "FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
3437 // dispatch the "add column"
3438 xAddColumnDispatch->dispatch(aAddColumnURL, aDispatchArgs);
3439 ++nAddedColumns;
3442 // now for the radio button handling
3443 sal_Int16 nOffset(0);
3444 // properties describing the "direct" column properties
3445 const sal_Int16 nListBoxDescription = 6;
3446 Sequence< PropertyValue> aListBoxDescription(nListBoxDescription);
3447 for ( FmMapUString2UString::const_iterator aCtrlSource = aRadioControlSources.begin();
3448 aCtrlSource != aRadioControlSources.end();
3449 ++aCtrlSource, ++nOffset
3453 PropertyValue* pListBoxDescription = aListBoxDescription.getArray();
3454 // label
3455 pListBoxDescription->Name = FM_PROP_LABEL;
3456 pListBoxDescription->Value <<= (*aCtrlSource).first;
3457 ++pListBoxDescription;
3459 // control source
3460 pListBoxDescription->Name = FM_PROP_CONTROLSOURCE;
3461 pListBoxDescription->Value <<= (*aCtrlSource).second;
3462 ++pListBoxDescription;
3464 // bound column
3465 pListBoxDescription->Name = FM_PROP_BOUNDCOLUMN;
3466 pListBoxDescription->Value <<= (sal_Int16)1;
3467 ++pListBoxDescription;
3469 // content type
3470 pListBoxDescription->Name = FM_PROP_LISTSOURCETYPE;
3471 ListSourceType eType = ListSourceType_VALUELIST;
3472 pListBoxDescription->Value = makeAny(eType);
3473 ++pListBoxDescription;
3475 // list source
3476 MapUString2UstringSeq::const_iterator aCurrentListSource = aRadioListSources.find((*aCtrlSource).first);
3477 DBG_ASSERT(aCurrentListSource != aRadioListSources.end(),
3478 "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
3479 pListBoxDescription->Name = FM_PROP_LISTSOURCE;
3480 pListBoxDescription->Value = makeAny((*aCurrentListSource).second);
3481 ++pListBoxDescription;
3483 // value list
3484 MapUString2UstringSeq::const_iterator aCurrentValueList = aRadioValueLists.find((*aCtrlSource).first);
3485 DBG_ASSERT(aCurrentValueList != aRadioValueLists.end(),
3486 "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
3487 pListBoxDescription->Name = FM_PROP_STRINGITEMLIST;
3488 pListBoxDescription->Value = makeAny(((*aCurrentValueList).second));
3489 ++pListBoxDescription;
3491 DBG_ASSERT(nListBoxDescription == (pListBoxDescription - aListBoxDescription.getConstArray()),
3492 "FmXFormShell::CreateExternalView : forgot to adjust nListBoxDescription ?");
3494 // properties describing the column "meta data"
3495 const sal_Int16 nDispatchArgs = 3;
3496 Sequence< PropertyValue> aDispatchArgs(nDispatchArgs);
3497 PropertyValue* pDispatchArgs = aDispatchArgs.getArray();
3499 // column type : listbox
3500 pDispatchArgs->Name = FMARG_ADDCOL_COLUMNTYPE;
3501 OUString fColName = FM_COL_LISTBOX;
3502 pDispatchArgs->Value <<= fColName;
3503 // pDispatchArgs->Value <<= (OUString)FM_COL_LISTBOX;
3504 ++pDispatchArgs;
3506 // column position
3507 pDispatchArgs->Name = FMARG_ADDCOL_COLUMNPOS;
3508 FmMapUString2Int16::const_iterator aOffset = aRadioPositions.find((*aCtrlSource).first);
3509 DBG_ASSERT(aOffset != aRadioPositions.end(),
3510 "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
3511 sal_Int16 nPosition = (*aOffset).second;
3512 nPosition = nPosition + nOffset;
3513 // we already inserted nOffset additional columns ....
3514 pDispatchArgs->Value <<= nPosition;
3515 ++pDispatchArgs;
3517 // the
3518 pDispatchArgs->Name = "ColumnProperties"; // TODO : fmurl.*
3519 pDispatchArgs->Value = makeAny(aListBoxDescription);
3520 ++pDispatchArgs;
3521 DBG_ASSERT(nDispatchArgs == (pDispatchArgs - aDispatchArgs.getConstArray()),
3522 "FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
3524 // dispatch the "add column"
3525 xAddColumnDispatch->dispatch(aAddColumnURL, aDispatchArgs);
3526 ++nAddedColumns;
3530 DBG_ASSERT(nAddedColumns > 0, "FmXFormShell::CreateExternalView : no controls (inconsistent) !");
3531 // we should have checked if we have any usable controls (see above).
3533 // "load" the "form" of the external view
3534 PropertyValue aArg;
3535 aArg.Name = FMARG_ATTACHTO_MASTERFORM;
3536 Reference< XResultSet> xForm(xCurrentNavController->getModel(), UNO_QUERY);
3537 aArg.Value <<= xForm;
3539 m_xExternalDisplayedForm = xForm;
3540 // do this before dispatching the "attach" command, as the atach may result in a call to our queryDispatch (for the FormSlots)
3541 // whichs needs the m_xExternalDisplayedForm
3543 xAttachDispatch->dispatch(aAttachURL, Sequence< PropertyValue>(&aArg, 1));
3545 m_xExtViewTriggerController = xCurrentNavController;
3547 // we want to know modifications done in the external view
3548 // if the external controller is a XFormController we can use all our default handlings for it
3549 Reference< runtime::XFormController > xFormController( m_xExternalViewController, UNO_QUERY );
3550 OSL_ENSURE( xFormController.is(), "FmXFormShell::CreateExternalView:: invalid external view controller!" );
3551 if (xFormController.is())
3552 xFormController->addActivateListener((XFormControllerListener*)this);
3555 #ifdef DBG_UTIL
3556 else
3558 OSL_FAIL("FmXFormShell::CreateExternalView : could not create the external form view !");
3560 #endif
3561 InvalidateSlot( SID_FM_VIEW_AS_GRID, false );
3565 void FmXFormShell::implAdjustConfigCache()
3567 // get (cache) the wizard usage flag
3568 Sequence< OUString > aNames(1);
3569 aNames[0] = "FormControlPilotsEnabled";
3570 Sequence< Any > aFlags = GetProperties(aNames);
3571 if (1 == aFlags.getLength())
3572 m_bUseWizards = ::cppu::any2bool(aFlags[0]);
3576 void FmXFormShell::Notify( const com::sun::star::uno::Sequence< OUString >& _rPropertyNames)
3578 if ( impl_checkDisposed() )
3579 return;
3581 const OUString* pSearch = _rPropertyNames.getConstArray();
3582 const OUString* pSearchTil = pSearch + _rPropertyNames.getLength();
3583 for (;pSearch < pSearchTil; ++pSearch)
3584 if (pSearch->equalsAscii("FormControlPilotsEnabled"))
3586 implAdjustConfigCache();
3587 InvalidateSlot( SID_FM_USE_WIZARDS, true );
3591 void FmXFormShell::Commit()
3596 void FmXFormShell::SetWizardUsing(bool _bUseThem)
3598 m_bUseWizards = _bUseThem;
3600 Sequence< OUString > aNames(1);
3601 aNames[0] = "FormControlPilotsEnabled";
3602 Sequence< Any > aValues(1);
3603 aValues[0] <<= m_bUseWizards;
3604 PutProperties(aNames, aValues);
3608 void FmXFormShell::viewDeactivated( FmFormView& _rCurrentView, bool _bDeactivateController /* = sal_True */ )
3611 if ( _rCurrentView.GetImpl() && !_rCurrentView.IsDesignMode() )
3613 _rCurrentView.GetImpl()->Deactivate( _bDeactivateController );
3616 // if we have an async load operation pending for the 0-th page for this view,
3617 // we need to cancel this
3618 FmFormPage* pPage = _rCurrentView.GetCurPage();
3619 if ( pPage )
3621 // move all events from our queue to a new one, omit the events for the deactivated
3622 // page
3623 ::std::queue< FmLoadAction > aNewEvents;
3624 while ( !m_aLoadingPages.empty() )
3626 FmLoadAction aAction = m_aLoadingPages.front();
3627 m_aLoadingPages.pop();
3628 if ( pPage != aAction.pPage )
3630 aNewEvents.push( aAction );
3632 else
3634 Application::RemoveUserEvent( aAction.nEventId );
3637 m_aLoadingPages = aNewEvents;
3640 // remove callbacks at the page
3641 if ( pPage )
3643 pPage->GetImpl().SetFormsCreationHdl( Link() );
3645 UpdateForms( true );
3649 IMPL_LINK( FmXFormShell, OnFirstTimeActivation, void*, /*NOTINTERESTEDIN*/ )
3651 if ( impl_checkDisposed() )
3652 return 0L;
3654 m_nActivationEvent = 0;
3655 SfxObjectShell* pDocument = m_pShell->GetObjectShell();
3657 if ( pDocument && !pDocument->HasName() )
3659 if ( isEnhancedForm() )
3661 // show the data navigator
3662 if ( !m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_SHOW_DATANAVIGATOR ) )
3663 m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_SHOW_DATANAVIGATOR );
3667 return 0L;
3671 IMPL_LINK( FmXFormShell, OnFormsCreated, FmFormPage*, /*_pPage*/ )
3673 UpdateForms( true );
3674 return 0L;
3678 void FmXFormShell::viewActivated( FmFormView& _rCurrentView, bool _bSyncAction /* = sal_False */ )
3681 FmFormPage* pPage = _rCurrentView.GetCurPage();
3683 // activate our view if we are activated ourself
3684 // FS - 30.06.99 - 67308
3685 if ( _rCurrentView.GetImpl() && !_rCurrentView.IsDesignMode() )
3687 // load forms for the page the current view belongs to
3688 if ( pPage )
3690 if ( !pPage->GetImpl().hasEverBeenActivated() )
3691 loadForms( pPage, FORMS_LOAD | ( _bSyncAction ? FORMS_SYNC : FORMS_ASYNC ) );
3692 pPage->GetImpl().setHasBeenActivated( );
3695 // first-time initializations for the views
3696 if ( !_rCurrentView.GetImpl()->hasEverBeenActivated( ) )
3698 _rCurrentView.GetImpl()->onFirstViewActivation( PTR_CAST( FmFormModel, _rCurrentView.GetModel() ) );
3699 _rCurrentView.GetImpl()->setHasBeenActivated( );
3702 // activate the current view
3703 _rCurrentView.GetImpl()->Activate( _bSyncAction );
3706 // set callbacks at the page
3707 if ( pPage )
3709 pPage->GetImpl().SetFormsCreationHdl( LINK( this, FmXFormShell, OnFormsCreated ) );
3712 UpdateForms( true );
3714 if ( !hasEverBeenActivated() )
3716 m_nActivationEvent = Application::PostUserEvent( LINK( this, FmXFormShell, OnFirstTimeActivation ) );
3717 setHasBeenActivated();
3720 // find a default "current form", if there is none, yet
3721 // #i88186# / 2008-04-12 / frank.schoenheit@sun.com
3722 impl_defaultCurrentForm_nothrow();
3726 void FmXFormShell::impl_defaultCurrentForm_nothrow()
3728 if ( impl_checkDisposed() )
3729 return;
3731 if ( m_xCurrentForm.is() )
3732 // no action required
3733 return;
3735 FmFormView* pFormView = m_pShell->GetFormView();
3736 FmFormPage* pPage = pFormView ? pFormView->GetCurPage() : NULL;
3737 if ( !pPage )
3738 return;
3742 Reference< XIndexAccess > xForms( pPage->GetForms( false ), UNO_QUERY );
3743 if ( !xForms.is() || !xForms->hasElements() )
3744 return;
3746 Reference< XForm > xNewCurrentForm( xForms->getByIndex(0), UNO_QUERY_THROW );
3747 impl_updateCurrentForm( xNewCurrentForm );
3749 catch( const Exception& )
3751 DBG_UNHANDLED_EXCEPTION();
3756 void FmXFormShell::smartControlReset( const Reference< XIndexAccess >& _rxModels )
3758 if (!_rxModels.is())
3760 OSL_FAIL("FmXFormShell::smartControlReset: invalid container!");
3761 return;
3764 static const OUString sClassIdPropertyName = FM_PROP_CLASSID;
3765 static const OUString sBoundFieldPropertyName = FM_PROP_BOUNDFIELD;
3766 sal_Int32 nCount = _rxModels->getCount();
3767 Reference< XPropertySet > xCurrent;
3768 Reference< XPropertySetInfo > xCurrentInfo;
3769 Reference< XPropertySet > xBoundField;
3771 for (sal_Int32 i=0; i<nCount; ++i)
3773 _rxModels->getByIndex(i) >>= xCurrent;
3774 if (xCurrent.is())
3775 xCurrentInfo = xCurrent->getPropertySetInfo();
3776 else
3777 xCurrentInfo.clear();
3778 if (!xCurrentInfo.is())
3779 continue;
3781 if (xCurrentInfo->hasPropertyByName(sClassIdPropertyName))
3782 { // it's a control model
3784 // check if this control is bound to a living database field
3785 if (xCurrentInfo->hasPropertyByName(sBoundFieldPropertyName))
3786 xCurrent->getPropertyValue(sBoundFieldPropertyName) >>= xBoundField;
3787 else
3788 xBoundField.clear();
3790 // reset only if it's *not* bound
3791 bool bReset = !xBoundField.is();
3793 // and additionally, check if it has an external value binding
3794 Reference< XBindableValue > xBindable( xCurrent, UNO_QUERY );
3795 if ( xBindable.is() && xBindable->getValueBinding().is() )
3796 bReset = false;
3798 if ( bReset )
3800 Reference< XReset > xControlReset( xCurrent, UNO_QUERY );
3801 if ( xControlReset.is() )
3802 xControlReset->reset();
3805 else
3807 Reference< XIndexAccess > xContainer(xCurrent, UNO_QUERY);
3808 if (xContainer.is())
3809 smartControlReset(xContainer);
3815 IMPL_LINK( FmXFormShell, OnLoadForms, FmFormPage*, /*_pPage*/ )
3817 FmLoadAction aAction = m_aLoadingPages.front();
3818 m_aLoadingPages.pop();
3820 loadForms( aAction.pPage, aAction.nFlags & ~FORMS_ASYNC );
3821 return 0L;
3825 namespace
3827 bool lcl_isLoadable( const Reference< XInterface >& _rxLoadable )
3829 // determines whether a form should be loaded or not
3830 // if there is no datasource or connection there is no reason to load a form
3831 Reference< XPropertySet > xSet( _rxLoadable, UNO_QUERY );
3832 if ( !xSet.is() )
3833 return false;
3836 Reference< XConnection > xConn;
3837 if ( OStaticDataAccessTools().isEmbeddedInDatabase( _rxLoadable.get(), xConn ) )
3838 return true;
3840 // is there already a active connection
3841 xSet->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xConn;
3842 if ( xConn.is() )
3843 return true;
3845 OUString sPropertyValue;
3846 OSL_VERIFY( xSet->getPropertyValue( FM_PROP_DATASOURCE ) >>= sPropertyValue );
3847 if ( !sPropertyValue.isEmpty() )
3848 return true;
3850 OSL_VERIFY( xSet->getPropertyValue( FM_PROP_URL ) >>= sPropertyValue );
3851 if ( !sPropertyValue.isEmpty() )
3852 return true;
3854 catch(const Exception&)
3856 DBG_UNHANDLED_EXCEPTION();
3858 return false;
3863 void FmXFormShell::loadForms( FmFormPage* _pPage, const sal_uInt16 _nBehaviour /* FORMS_LOAD | FORMS_SYNC */ )
3865 DBG_ASSERT( ( _nBehaviour & ( FORMS_ASYNC | FORMS_UNLOAD ) ) != ( FORMS_ASYNC | FORMS_UNLOAD ),
3866 "FmXFormShell::loadForms: async loading not supported - this will heavily fail!" );
3868 if ( _nBehaviour & FORMS_ASYNC )
3870 m_aLoadingPages.push( FmLoadAction(
3871 _pPage,
3872 _nBehaviour,
3873 Application::PostUserEvent( LINK( this, FmXFormShell, OnLoadForms ), _pPage )
3874 ) );
3875 return;
3878 DBG_ASSERT( _pPage, "FmXFormShell::loadForms: invalid page!" );
3879 if ( _pPage )
3881 // lock the undo env so the forms can change non-transient properties while loading
3882 // (without this my doc's modified flag would be set)
3883 FmFormModel* pModel = PTR_CAST( FmFormModel, _pPage->GetModel() );
3884 DBG_ASSERT( pModel, "FmXFormShell::loadForms: invalid model!" );
3885 if ( pModel )
3886 pModel->GetUndoEnv().Lock();
3888 // load all forms
3889 Reference< XIndexAccess > xForms;
3890 xForms = xForms.query( _pPage->GetForms( false ) );
3892 if ( xForms.is() )
3894 Reference< XLoadable > xForm;
3895 bool bFormWasLoaded = false;
3896 for ( sal_Int32 j = 0, nCount = xForms->getCount(); j < nCount; ++j )
3898 xForms->getByIndex( j ) >>= xForm;
3899 bFormWasLoaded = false;
3900 // a database form must be loaded for
3903 if ( 0 == ( _nBehaviour & FORMS_UNLOAD ) )
3905 if ( lcl_isLoadable( xForm ) && !xForm->isLoaded() )
3906 xForm->load();
3908 else
3910 if ( xForm->isLoaded() )
3912 bFormWasLoaded = true;
3913 xForm->unload();
3917 catch( const Exception& )
3919 DBG_UNHANDLED_EXCEPTION();
3922 // reset the form if it was loaded
3923 if ( bFormWasLoaded )
3925 Reference< XIndexAccess > xContainer( xForm, UNO_QUERY );
3926 DBG_ASSERT( xContainer.is(), "FmXFormShell::loadForms: the form is no container!" );
3927 if ( xContainer.is() )
3928 smartControlReset( xContainer );
3933 if ( pModel )
3934 // unlock the environment
3935 pModel->GetUndoEnv().UnLock();
3940 void FmXFormShell::ExecuteTextAttribute( SfxRequest& _rReq )
3942 m_pTextShell->ExecuteTextAttribute( _rReq );
3946 void FmXFormShell::GetTextAttributeState( SfxItemSet& _rSet )
3948 m_pTextShell->GetTextAttributeState( _rSet );
3952 bool FmXFormShell::IsActiveControl( bool _bCountRichTextOnly ) const
3954 return m_pTextShell->IsActiveControl( _bCountRichTextOnly );
3958 void FmXFormShell::ForgetActiveControl()
3960 m_pTextShell->ForgetActiveControl();
3964 void FmXFormShell::SetControlActivationHandler( const Link& _rHdl )
3966 m_pTextShell->SetControlActivationHandler( _rHdl );
3969 void FmXFormShell::handleShowPropertiesRequest()
3971 if ( onlyControlsAreMarked() )
3972 ShowSelectionProperties( true );
3976 void FmXFormShell::handleMouseButtonDown( const SdrViewEvent& _rViewEvent )
3978 // catch simple double clicks
3979 if ( ( _rViewEvent.nMouseClicks == 2 ) && ( _rViewEvent.nMouseCode == MOUSE_LEFT ) )
3981 if ( _rViewEvent.eHit == SDRHIT_MARKEDOBJECT )
3983 if ( onlyControlsAreMarked() )
3984 ShowSelectionProperties( true );
3990 bool FmXFormShell::HasControlFocus() const
3992 bool bHasControlFocus = false;
3996 Reference< XFormController > xController( getActiveController() );
3997 Reference< XControl > xCurrentControl;
3998 if ( xController.is() )
3999 xCurrentControl.set( xController->getCurrentControl() );
4000 if ( xCurrentControl.is() )
4002 Reference< XWindow2 > xPeerWindow( xCurrentControl->getPeer(), UNO_QUERY_THROW );
4003 bHasControlFocus = xPeerWindow->hasFocus();
4006 catch( const Exception& )
4008 DBG_UNHANDLED_EXCEPTION();
4011 return bHasControlFocus;
4016 SearchableControlIterator::SearchableControlIterator(Reference< XInterface> xStartingPoint)
4017 :IndexAccessIterator(xStartingPoint)
4022 bool SearchableControlIterator::ShouldHandleElement(const Reference< XInterface>& xElement)
4024 // wenn das Ding eine ControlSource und einen BoundField-Property hat
4025 Reference< XPropertySet> xProperties(xElement, UNO_QUERY);
4026 if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xProperties) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xProperties))
4028 // und das BoundField gueltig ist
4029 Reference< XPropertySet> xField;
4030 xProperties->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField;
4031 if (xField.is())
4033 // nehmen wir's
4034 m_sCurrentValue = ::comphelper::getString(xProperties->getPropertyValue(FM_PROP_CONTROLSOURCE));
4035 return true;
4039 // wenn es ein Grid-Control ist
4040 if (::comphelper::hasProperty(FM_PROP_CLASSID, xProperties))
4042 Any aClassId( xProperties->getPropertyValue(FM_PROP_CLASSID) );
4043 if (::comphelper::getINT16(aClassId) == FormComponentType::GRIDCONTROL)
4045 m_sCurrentValue = "";
4046 return true;
4050 return false;
4054 bool SearchableControlIterator::ShouldStepInto(const Reference< XInterface>& /*xContainer*/) const
4056 return true;
4062 SFX_IMPL_MENU_CONTROL(ControlConversionMenuController, SfxBoolItem);
4065 ControlConversionMenuController::ControlConversionMenuController( sal_uInt16 _nId, Menu& _rMenu, SfxBindings& _rBindings )
4066 :SfxMenuControl( _nId, _rBindings )
4067 ,m_pMainMenu( &_rMenu )
4068 ,m_pConversionMenu( NULL )
4070 if ( _nId == SID_FM_CHANGECONTROLTYPE )
4072 m_pConversionMenu = FmXFormShell::GetConversionMenu();
4073 _rMenu.SetPopupMenu( _nId, m_pConversionMenu );
4075 for (sal_Int16 i=0; i<m_pConversionMenu->GetItemCount(); ++i)
4077 _rBindings.Invalidate(m_pConversionMenu->GetItemId(i));
4078 SfxStatusForwarder* pForwarder = new SfxStatusForwarder(m_pConversionMenu->GetItemId(i), *this);
4079 m_aStatusForwarders.push_back(pForwarder);
4085 ControlConversionMenuController::~ControlConversionMenuController()
4087 m_pMainMenu->SetPopupMenu(SID_FM_CHANGECONTROLTYPE, NULL);
4088 delete m_pConversionMenu;
4092 void ControlConversionMenuController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
4094 if (nSID == GetId())
4095 SfxMenuControl::StateChanged(nSID, eState, pState);
4096 else if (FmXFormShell::isControlConversionSlot(nSID))
4098 if ((m_pConversionMenu->GetItemPos(nSID) != MENU_ITEM_NOTFOUND) && (eState == SFX_ITEM_DISABLED))
4100 m_pConversionMenu->RemoveItem(m_pConversionMenu->GetItemPos(nSID));
4102 else if ((m_pConversionMenu->GetItemPos(nSID) == MENU_ITEM_NOTFOUND) && (eState != SFX_ITEM_DISABLED))
4104 // We can't simply re-insert the item because we have a clear order for all the our items.
4105 // So first we have to determine the position of the item to insert.
4106 PopupMenu* pSource = FmXFormShell::GetConversionMenu();
4107 sal_uInt16 nSourcePos = pSource->GetItemPos(nSID);
4108 DBG_ASSERT(nSourcePos != MENU_ITEM_NOTFOUND, "ControlConversionMenuController::StateChanged : FmXFormShell supplied an invalid menu !");
4109 sal_uInt16 nPrevInSource = nSourcePos;
4110 sal_uInt16 nPrevInConversion = MENU_ITEM_NOTFOUND;
4111 while (nPrevInSource>0)
4113 sal_Int16 nPrevId = pSource->GetItemId(--nPrevInSource);
4115 // do we have the source's predecessor in our conversion menu, too ?
4116 nPrevInConversion = m_pConversionMenu->GetItemPos(nPrevId);
4117 if (nPrevInConversion != MENU_ITEM_NOTFOUND)
4118 break;
4120 if (MENU_ITEM_NOTFOUND == nPrevInConversion)
4121 // none of the items which precede the nSID-slot in the source menu are present in our conversion menu
4122 nPrevInConversion = sal::static_int_cast< sal_uInt16 >(-1); // put the item at the first position
4123 m_pConversionMenu->InsertItem(nSID, pSource->GetItemText(nSID),
4124 pSource->GetItemBits(nSID), OString(), ++nPrevInConversion);
4125 m_pConversionMenu->SetItemImage(nSID, pSource->GetItemImage(nSID));
4126 m_pConversionMenu->SetHelpId(nSID, pSource->GetHelpId(nSID));
4128 delete pSource;
4130 m_pMainMenu->EnableItem(SID_FM_CHANGECONTROLTYPE, m_pConversionMenu->GetItemCount() > 0);
4132 else
4134 OSL_FAIL("ControlConversionMenuController::StateChanged : unknown id !");
4140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */