LCOV - code coverage report
Current view: top level - svx/source/form - fmshimp.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 464 1909 24.3 %
Date: 2014-11-03 Functions: 60 129 46.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      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"
      48             : 
      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>
      80             : 
      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 <vcl/layout.hxx>
      96             : #include <vcl/waitobj.hxx>
      97             : #include <vcl/settings.hxx>
      98             : 
      99             : #include <algorithm>
     100             : #include <functional>
     101             : #include <map>
     102             : #include <vector>
     103             : #include <boost/scoped_ptr.hpp>
     104             : 
     105             : // wird fuer Invalidate verwendet -> mitpflegen
     106             : static const sal_uInt16 DatabaseSlotMap[] =
     107             : {
     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,
     129             :     0
     130             : };
     131             : 
     132             : // wird fuer Invalidate verwendet -> mitpflegen
     133             : // aufsteigend sortieren !!!!!!
     134             : static const sal_Int16 DlgSlotMap[] =    // slots des Controllers
     135             : {
     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,
     147             :     0
     148             : };
     149             : 
     150             : static const sal_Int16 SelObjectSlotMap[] =  // vom SelObject abhaengige Slots
     151             : {
     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,
     172             : 
     173             :     SID_FM_FMEXPLORER_CONTROL,
     174             :     SID_FM_DATANAVIGATOR_CONTROL,
     175             : 
     176             :     0
     177             : };
     178             : 
     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[] =
     182             : {
     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
     203             : };
     204             : 
     205             : static const sal_Int16 nCreateSlots[] =
     206             : {
     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
     227             : };
     228             : 
     229             : static const sal_Int16 nObjectTypes[] =
     230             : {
     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
     251             : };
     252             : 
     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;
     272             : 
     273             : 
     274             : //= helper
     275             : 
     276             : namespace
     277             : {
     278             : 
     279           0 :     void collectInterfacesFromMarkList( const SdrMarkList& _rMarkList, InterfaceBag& /* [out] */ _rInterfaces )
     280             :     {
     281           0 :         _rInterfaces.clear();
     282             : 
     283           0 :         const size_t nMarkCount = _rMarkList.GetMarkCount();
     284           0 :         for ( size_t i = 0; i < nMarkCount; ++i)
     285             :         {
     286           0 :             SdrObject* pCurrent = _rMarkList.GetMark( i )->GetMarkedSdrObj();
     287             : 
     288           0 :             boost::scoped_ptr<SdrObjListIter> pGroupIterator;
     289           0 :             if ( pCurrent->IsGroupObject() )
     290             :             {
     291           0 :                 pGroupIterator.reset(new SdrObjListIter( *pCurrent->GetSubList() ));
     292           0 :                 pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
     293             :             }
     294             : 
     295           0 :             while ( pCurrent )
     296             :             {
     297           0 :                 FmFormObj* pAsFormObject = FmFormObj::GetFormObject( pCurrent );
     298             :                     // note this will de-reference virtual objects, if necessary/possible
     299           0 :                 if ( pAsFormObject )
     300             :                 {
     301           0 :                     Reference< XInterface > xControlModel( pAsFormObject->GetUnoControlModel(), UNO_QUERY );
     302             :                         // the UNO_QUERY is important for normalization
     303           0 :                     if ( xControlModel.is() )
     304           0 :                         _rInterfaces.insert( xControlModel );
     305             :                 }
     306             : 
     307             :                 // next element
     308           0 :                 pCurrent = pGroupIterator && pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
     309             :             }
     310           0 :         }
     311           0 :     }
     312             : 
     313             : 
     314           0 :     sal_Int16 GridView2ModelPos(const Reference< XIndexAccess>& rColumns, sal_Int16 nViewPos)
     315             :     {
     316             :         try
     317             :         {
     318           0 :             if (rColumns.is())
     319             :             {
     320             :                 // loop through all columns
     321             :                 sal_Int16 i;
     322           0 :                 Reference< XPropertySet> xCur;
     323           0 :                 for (i=0; i<rColumns->getCount(); ++i)
     324             :                 {
     325           0 :                     rColumns->getByIndex(i) >>= xCur;
     326           0 :                     if (!::comphelper::getBOOL(xCur->getPropertyValue(FM_PROP_HIDDEN)))
     327             :                     {
     328             :                         // for every visible col : if nViewPos is greater zero, decrement it, else we
     329             :                         // have found the model position
     330           0 :                         if (!nViewPos)
     331           0 :                             break;
     332             :                         else
     333           0 :                             --nViewPos;
     334             :                     }
     335             :                 }
     336           0 :                 if (i<rColumns->getCount())
     337           0 :                     return i;
     338             :             }
     339             :         }
     340           0 :         catch(const Exception&)
     341             :         {
     342             :             DBG_UNHANDLED_EXCEPTION();
     343             :         }
     344           0 :         return (sal_Int16)-1;
     345             :     }
     346             : 
     347             : 
     348           0 :     void TransferEventScripts(const Reference< XControlModel>& xModel, const Reference< XControl>& xControl,
     349             :         const Sequence< ScriptEventDescriptor>& rTransferIfAvailable)
     350             :     {
     351             :         // first check if we have a XEventAttacherManager for the model
     352           0 :         Reference< XChild> xModelChild(xModel, UNO_QUERY);
     353           0 :         if (!xModelChild.is())
     354           0 :             return; // nothing to do
     355             : 
     356           0 :         Reference< XEventAttacherManager> xEventManager(xModelChild->getParent(), UNO_QUERY);
     357           0 :         if (!xEventManager.is())
     358           0 :             return; // nothing to do
     359             : 
     360           0 :         if (!rTransferIfAvailable.getLength())
     361           0 :             return; // nothing to do
     362             : 
     363             :         // check for the index of the model within its parent
     364           0 :         Reference< XIndexAccess> xParentIndex(xModelChild->getParent(), UNO_QUERY);
     365           0 :         if (!xParentIndex.is())
     366           0 :             return; // nothing to do
     367           0 :         sal_Int32 nIndex = getElementPos(xParentIndex, xModel);
     368           0 :         if (nIndex<0 || nIndex>=xParentIndex->getCount())
     369           0 :             return; // nothing to do
     370             : 
     371             :         // then we need information about the listeners supported by the control and the model
     372           0 :         Sequence< Type> aModelListeners;
     373           0 :         Sequence< Type> aControlListeners;
     374             : 
     375           0 :         Reference< XIntrospection> xIntrospection = theIntrospection::get(::comphelper::getProcessComponentContext());
     376             : 
     377           0 :         if (xModel.is())
     378             :         {
     379           0 :             Any aModel(makeAny(xModel));
     380           0 :             aModelListeners = xIntrospection->inspect(aModel)->getSupportedListeners();
     381             :         }
     382             : 
     383           0 :         if (xControl.is())
     384             :         {
     385           0 :             Any aControl(makeAny(xControl));
     386           0 :             aControlListeners = xIntrospection->inspect(aControl)->getSupportedListeners();
     387             :         }
     388             : 
     389           0 :         sal_Int32 nMaxNewLen = aModelListeners.getLength() + aControlListeners.getLength();
     390           0 :         if (!nMaxNewLen)
     391           0 :             return; // the model and the listener don't support any listeners (or we were unable to retrieve these infos)
     392             : 
     393           0 :         Sequence< ScriptEventDescriptor>    aTransferable(nMaxNewLen);
     394           0 :         ScriptEventDescriptor* pTransferable = aTransferable.getArray();
     395             : 
     396           0 :         const ScriptEventDescriptor* pCurrent = rTransferIfAvailable.getConstArray();
     397             :         sal_Int32 i,j,k;
     398           0 :         for (i=0; i<rTransferIfAvailable.getLength(); ++i, ++pCurrent)
     399             :         {
     400             :             // search the model/control idl classes for the event described by pCurrent
     401           0 :             for (   Sequence< Type>* pCurrentArray = &aModelListeners;
     402             :                     pCurrentArray;
     403             :                     pCurrentArray = (pCurrentArray == &aModelListeners) ? &aControlListeners : NULL
     404             :                 )
     405             :             {
     406           0 :                 const Type* pCurrentListeners = pCurrentArray->getConstArray();
     407           0 :                 for (j=0; j<pCurrentArray->getLength(); ++j, ++pCurrentListeners)
     408             :                 {
     409           0 :                     OUString aListener = (*pCurrentListeners).getTypeName();
     410           0 :                     sal_Int32 nTokens = comphelper::string::getTokenCount(aListener, '.');
     411           0 :                     if (nTokens)
     412           0 :                         aListener = comphelper::string::getToken(aListener, nTokens - 1, '.');
     413             : 
     414           0 :                     if (aListener == pCurrent->ListenerType.getStr())
     415             :                         // the current ScriptEventDescriptor doesn't match the current listeners class
     416           0 :                         continue;
     417             : 
     418             :                     // now check the methods
     419           0 :                     Sequence< OUString> aMethodsNames = ::comphelper::getEventMethodsForType(*pCurrentListeners);
     420             : 
     421           0 :                     const OUString* pMethodsNames = aMethodsNames.getConstArray();
     422           0 :                     for (k=0; k<aMethodsNames.getLength(); ++k, ++pMethodsNames)
     423             :                     {
     424           0 :                         if ((*pMethodsNames) != pCurrent->EventMethod)
     425             :                             // the current ScriptEventDescriptor doesn't match the current listeners current method
     426           0 :                             continue;
     427             : 
     428             :                         // we can transfer the script event : the model (control) supports it
     429           0 :                         *pTransferable = *pCurrent;
     430           0 :                         ++pTransferable;
     431           0 :                         break;
     432             :                     }
     433           0 :                     if (k<aMethodsNames.getLength())
     434           0 :                         break;
     435           0 :                 }
     436             :             }
     437             :         }
     438             : 
     439           0 :         sal_Int32 nRealNewLen = pTransferable - aTransferable.getArray();
     440           0 :         aTransferable.realloc(nRealNewLen);
     441             : 
     442           0 :         xEventManager->registerScriptEvents(nIndex, aTransferable);
     443             :     }
     444             : 
     445             : 
     446           0 :     OUString getServiceNameByControlType(sal_Int16 nType)
     447             :     {
     448           0 :         switch (nType)
     449             :         {
     450           0 :             case OBJ_FM_EDIT            : return FM_COMPONENT_TEXTFIELD;
     451           0 :             case OBJ_FM_BUTTON          : return FM_COMPONENT_COMMANDBUTTON;
     452           0 :             case OBJ_FM_FIXEDTEXT       : return FM_COMPONENT_FIXEDTEXT;
     453           0 :             case OBJ_FM_LISTBOX         : return FM_COMPONENT_LISTBOX;
     454           0 :             case OBJ_FM_CHECKBOX        : return FM_COMPONENT_CHECKBOX;
     455           0 :             case OBJ_FM_RADIOBUTTON     : return FM_COMPONENT_RADIOBUTTON;
     456           0 :             case OBJ_FM_GROUPBOX        : return FM_COMPONENT_GROUPBOX;
     457           0 :             case OBJ_FM_COMBOBOX        : return FM_COMPONENT_COMBOBOX;
     458           0 :             case OBJ_FM_GRID            : return FM_COMPONENT_GRIDCONTROL;
     459           0 :             case OBJ_FM_IMAGEBUTTON     : return FM_COMPONENT_IMAGEBUTTON;
     460           0 :             case OBJ_FM_FILECONTROL     : return FM_COMPONENT_FILECONTROL;
     461           0 :             case OBJ_FM_DATEFIELD       : return FM_COMPONENT_DATEFIELD;
     462           0 :             case OBJ_FM_TIMEFIELD       : return FM_COMPONENT_TIMEFIELD;
     463           0 :             case OBJ_FM_NUMERICFIELD    : return FM_COMPONENT_NUMERICFIELD;
     464           0 :             case OBJ_FM_CURRENCYFIELD   : return FM_COMPONENT_CURRENCYFIELD;
     465           0 :             case OBJ_FM_PATTERNFIELD    : return FM_COMPONENT_PATTERNFIELD;
     466           0 :             case OBJ_FM_HIDDEN          : return FM_COMPONENT_HIDDENCONTROL;
     467           0 :             case OBJ_FM_IMAGECONTROL    : return FM_COMPONENT_IMAGECONTROL;
     468           0 :             case OBJ_FM_FORMATTEDFIELD  : return FM_COMPONENT_FORMATTEDFIELD;
     469           0 :             case OBJ_FM_SCROLLBAR       : return FM_SUN_COMPONENT_SCROLLBAR;
     470           0 :             case OBJ_FM_SPINBUTTON      : return FM_SUN_COMPONENT_SPINBUTTON;
     471           0 :             case OBJ_FM_NAVIGATIONBAR   : return FM_SUN_COMPONENT_NAVIGATIONBAR;
     472             :         }
     473           0 :         return OUString();
     474             :     }
     475             : 
     476             : }
     477             : 
     478             : 
     479             : // check if the control has one of the interfaces we can use for searching
     480             : // *_pCurrentText will be filled with the current text of the control (as used when searching this control)
     481           0 : bool IsSearchableControl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rxControl,
     482             :     OUString* _pCurrentText )
     483             : {
     484           0 :     if ( !_rxControl.is() )
     485           0 :         return false;
     486             : 
     487           0 :     Reference< XTextComponent > xAsText( _rxControl, UNO_QUERY );
     488           0 :     if ( xAsText.is() )
     489             :     {
     490           0 :         if ( _pCurrentText )
     491           0 :             *_pCurrentText = xAsText->getText();
     492           0 :         return true;
     493             :     }
     494             : 
     495           0 :     Reference< XListBox > xListBox( _rxControl, UNO_QUERY );
     496           0 :     if ( xListBox.is() )
     497             :     {
     498           0 :         if ( _pCurrentText )
     499           0 :             *_pCurrentText = xListBox->getSelectedItem();
     500           0 :         return true;
     501             :     }
     502             : 
     503           0 :     Reference< XCheckBox > xCheckBox( _rxControl, UNO_QUERY );
     504           0 :     if ( xCheckBox.is() )
     505             :     {
     506           0 :         if ( _pCurrentText )
     507             :         {
     508           0 :             switch ( (::TriState)xCheckBox->getState() )
     509             :             {
     510           0 :                 case TRISTATE_FALSE: *_pCurrentText = "0"; break;
     511           0 :                 case TRISTATE_TRUE: *_pCurrentText = "1"; break;
     512           0 :                 default: *_pCurrentText = ""; break;
     513             :             }
     514             :         }
     515           0 :         return true;
     516             :     }
     517             : 
     518           0 :     return false;
     519             : }
     520             : 
     521             : 
     522           0 : bool FmXBoundFormFieldIterator::ShouldStepInto(const Reference< XInterface>& _rContainer) const
     523             : {
     524           0 :     if (_rContainer == m_xStartingPoint)
     525             :         // would be quite stupid to step over the root ....
     526           0 :         return true;
     527             : 
     528           0 :     return Reference< XControlModel>(_rContainer, UNO_QUERY).is();
     529             : }
     530             : 
     531             : 
     532           0 : bool FmXBoundFormFieldIterator::ShouldHandleElement(const Reference< XInterface>& _rElement)
     533             : {
     534           0 :     if (!_rElement.is())
     535             :         // NULL element
     536           0 :         return false;
     537             : 
     538           0 :     if (Reference< XForm>(_rElement, UNO_QUERY).is() || Reference< XGrid>(_rElement, UNO_QUERY).is())
     539             :         // a forms or a grid
     540           0 :         return false;
     541             : 
     542           0 :     Reference< XPropertySet> xSet(_rElement, UNO_QUERY);
     543           0 :     if (!xSet.is() || !::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xSet))
     544             :         // no "BoundField" property
     545           0 :         return false;
     546             : 
     547           0 :     Any aVal( xSet->getPropertyValue(FM_PROP_BOUNDFIELD) );
     548           0 :     if (aVal.getValueTypeClass() != TypeClass_INTERFACE)
     549             :         // void or invalid property value
     550           0 :         return false;
     551             : 
     552           0 :     return aVal.hasValue();
     553             : }
     554             : 
     555             : 
     556           0 : bool isControlList(const SdrMarkList& rMarkList)
     557             : {
     558             :     // enthaelt die liste nur Controls und mindestens ein control
     559           0 :     const size_t nMarkCount = rMarkList.GetMarkCount();
     560           0 :     bool  bControlList = nMarkCount != 0;
     561             : 
     562           0 :     bool bHadAnyLeafs = false;
     563             : 
     564           0 :     for (size_t i = 0; i < nMarkCount && bControlList; ++i)
     565             :     {
     566           0 :         SdrObject *pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
     567           0 :         E3dObject* pAs3DObject = PTR_CAST(E3dObject, pObj);
     568             :         // E3dObject's do not contain any 2D-objects (by definition)
     569             :         // we need this extra check here : an E3dObject->IsGroupObject says "YES", but an SdrObjListIter working
     570             :         // with an E3dObject doesn't give me any Nodes (E3dObject has a sub list, but no members in that list,
     571             :         // cause there implementation differs from the one of "normal" SdrObject's. Unfortunally SdrObject::IsGroupObject
     572             :         // doesn't check the element count of the sub list, which is simply a bug in IsGroupObject we can't fix at the moment).
     573             :         // So at the end of this function bControlList would have the same value it was initialized with above : sal_True
     574             :         // And this would be wrong :)
     575             :         // 03.02.00 - 72529 - FS
     576           0 :         if (!pAs3DObject)
     577             :         {
     578           0 :             if (pObj->IsGroupObject())
     579             :             {
     580           0 :                 SdrObjListIter aIter(*pObj->GetSubList());
     581           0 :                 while (aIter.IsMore() && bControlList)
     582             :                 {
     583           0 :                     bControlList = FmFormInventor == aIter.Next()->GetObjInventor();
     584           0 :                     bHadAnyLeafs = true;
     585           0 :                 }
     586             :             }
     587             :             else
     588             :             {
     589           0 :                 bHadAnyLeafs = true;
     590           0 :                 bControlList = FmFormInventor == pObj->GetObjInventor();
     591             :             }
     592             :         }
     593             :     }
     594             : 
     595           0 :     return bControlList && bHadAnyLeafs;
     596             : }
     597             : 
     598             : 
     599           0 : Reference< XForm > GetForm(const Reference< XInterface>& _rxElement)
     600             : {
     601           0 :     Reference< XForm > xForm( _rxElement, UNO_QUERY );
     602           0 :     if ( xForm.is() )
     603           0 :         return xForm;
     604             : 
     605           0 :     Reference< XChild > xChild( _rxElement, UNO_QUERY );
     606           0 :     if ( xChild.is() )
     607           0 :         return GetForm( xChild->getParent() );
     608             : 
     609           0 :     return Reference< XForm >();
     610             : }
     611             : 
     612        5452 : FmXFormShell_Base_Disambiguation::FmXFormShell_Base_Disambiguation( ::osl::Mutex& _rMutex )
     613        5452 :     :FmXFormShell_BD_BASE( _rMutex )
     614             : {
     615        5452 : }
     616             : 
     617        5450 : void SAL_CALL FmXFormShell_Base_Disambiguation::disposing()
     618             : {
     619        5450 :     WeakComponentImplHelperBase::disposing();
     620             :     // Note:
     621             :     // This is a HACK.
     622             :     // Normally it should be sufficient to call the "disposing" of our direct
     623             :     // base class, but SUN PRO 5 does not like this and claims there is a conflict
     624             :     // with the XEventListener::disposing(EventObject) of our various listener
     625             :     // base classes.
     626        5450 : }
     627             : 
     628        5452 : FmXFormShell::FmXFormShell( FmFormShell& _rShell, SfxViewFrame* _pViewFrame )
     629             :         :FmXFormShell_BASE(m_aMutex)
     630             :         ,FmXFormShell_CFGBASE(OUString("Office.Common/Misc"), CONFIG_MODE_DELAYED_UPDATE)
     631             :         ,m_eNavigate( NavigationBarMode_NONE )
     632             :         ,m_nInvalidationEvent( 0 )
     633             :         ,m_nActivationEvent( 0 )
     634             :         ,m_pShell( &_rShell )
     635        5452 :         ,m_pTextShell( new ::svx::FmTextControlShell( _pViewFrame ) )
     636             :         ,m_aActiveControllerFeatures( this )
     637             :         ,m_aNavControllerFeatures( this )
     638             :         ,m_eDocumentType( eUnknownDocumentType )
     639             :         ,m_nLockSlotInvalidation( 0 )
     640             :         ,m_bHadPropertyBrowserInDesignMode( false )
     641             :         ,m_bTrackProperties( true )
     642             :         ,m_bUseWizards( true )
     643             :         ,m_bDatabaseBar( false )
     644             :         ,m_bInActivate( false )
     645             :         ,m_bSetFocus( false )
     646             :         ,m_bFilterMode( false )
     647             :         ,m_bChangingDesignMode( false )
     648             :         ,m_bPreparedClose( false )
     649       10904 :         ,m_bFirstActivation( true )
     650             : {
     651        5452 :     m_aMarkTimer.SetTimeout(100);
     652        5452 :     m_aMarkTimer.SetTimeoutHdl(LINK(this,FmXFormShell,OnTimeOut));
     653             : 
     654        5452 :     m_xAttachedFrame = _pViewFrame->GetFrame().GetFrameInterface();
     655             : 
     656             :     // to prevent deletion of this we acquire our refcounter once
     657        5452 :     ::comphelper::increment(FmXFormShell_BASE::m_refCount);
     658             : 
     659             :     // correct the refcounter
     660        5452 :     ::comphelper::decrement(FmXFormShell_BASE::m_refCount);
     661             : 
     662             :     // cache the current configuration settings we're interested in
     663        5452 :     implAdjustConfigCache();
     664             :     // and register for changes on this settings
     665        5452 :     Sequence< OUString > aNames(1);
     666        5452 :     aNames[0] = "FormControlPilotsEnabled";
     667        5452 :     EnableNotification(aNames);
     668        5452 : }
     669             : 
     670             : 
     671       16350 : FmXFormShell::~FmXFormShell()
     672             : {
     673        5450 :     delete m_pTextShell;
     674       10900 : }
     675             : 
     676             : 
     677        5406 : Reference< XModel > FmXFormShell::getContextDocument() const
     678             : {
     679        5406 :     Reference< XModel > xModel;
     680             : 
     681             :     // determine the type of document we live in
     682             :     try
     683             :     {
     684        5406 :         Reference< XController > xController;
     685        5406 :         if ( m_xAttachedFrame.is() )
     686        5406 :             xController = m_xAttachedFrame->getController();
     687        5406 :         if ( xController.is() )
     688        5406 :             xModel = xController->getModel();
     689             :     }
     690           0 :     catch( const Exception& )
     691             :     {
     692             :         DBG_UNHANDLED_EXCEPTION();
     693             :     }
     694        5406 :     return xModel;
     695             : }
     696             : 
     697             : 
     698        8405 : bool FmXFormShell::isEnhancedForm() const
     699             : {
     700        8405 :     return getDocumentType() == eEnhancedForm;
     701             : }
     702             : 
     703             : 
     704       55263 : bool FmXFormShell::impl_checkDisposed() const
     705             : {
     706       55263 :     if ( !m_pShell )
     707             :     {
     708             :         OSL_FAIL( "FmXFormShell::impl_checkDisposed: already disposed!" );
     709           0 :         return true;
     710             :     }
     711       55263 :     return false;
     712             : }
     713             : 
     714             : 
     715        8405 : ::svxform::DocumentType FmXFormShell::getDocumentType() const
     716             : {
     717        8405 :     if ( m_eDocumentType != eUnknownDocumentType )
     718        2999 :         return m_eDocumentType;
     719             : 
     720             :     // determine the type of document we live in
     721        5406 :     Reference< XModel > xModel = getContextDocument();
     722        5406 :     if ( xModel.is() )
     723        5406 :         m_eDocumentType = DocumentClassification::classifyDocument( xModel );
     724             :     else
     725             :     {
     726             :         OSL_FAIL( "FmXFormShell::getDocumentType: can't determine the document type!" );
     727           0 :         m_eDocumentType = eTextDocument;
     728             :             // fallback, just to have a defined state
     729             :     }
     730             : 
     731        5406 :     return m_eDocumentType;
     732             : }
     733             : 
     734             : 
     735        7261 : bool FmXFormShell::IsReadonlyDoc() const
     736             : {
     737        7261 :     if ( impl_checkDisposed() )
     738           0 :         return true;
     739             : 
     740        7261 :     FmFormModel* pModel = m_pShell->GetFormModel();
     741        7261 :     if ( pModel && pModel->GetObjectShell() )
     742        7261 :         return pModel->GetObjectShell()->IsReadOnly() || pModel->GetObjectShell()->IsReadOnlyUI();
     743           0 :     return true;
     744             : }
     745             : 
     746             : 
     747         764 : Any SAL_CALL FmXFormShell::queryInterface( const Type& type) throw ( RuntimeException, std::exception )
     748             : {
     749         764 :     return FmXFormShell_BASE::queryInterface(type);
     750             : }
     751             : 
     752           0 : Sequence< Type > SAL_CALL FmXFormShell::getTypes(  ) throw(RuntimeException, std::exception)
     753             : {
     754           0 :     return FmXFormShell_BASE::getTypes();
     755             : }
     756             : 
     757           0 : Sequence< sal_Int8 > SAL_CALL FmXFormShell::getImplementationId() throw(RuntimeException, std::exception)
     758             : {
     759           0 :     return css::uno::Sequence<sal_Int8>();
     760             : }
     761             : //  EventListener
     762             : 
     763           4 : void SAL_CALL FmXFormShell::disposing(const EventObject& e) throw( RuntimeException, std::exception )
     764             : {
     765             : 
     766           4 :     if (m_xActiveController == e.Source)
     767             :     {
     768             :         // wird der Controller freigeben dann alles loslassen
     769           0 :         stopListening();
     770           0 :         m_xActiveForm = NULL;
     771           0 :         m_xActiveController = NULL;
     772           0 :         m_xNavigationController = NULL;
     773             : 
     774           0 :         m_aActiveControllerFeatures.dispose();
     775           0 :         m_aNavControllerFeatures.dispose();
     776             : 
     777           0 :         if ( m_pShell )
     778           0 :             m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
     779             :     }
     780             : 
     781           4 :     if (e.Source == m_xExternalViewController)
     782             :     {
     783           0 :         Reference< runtime::XFormController > xFormController( m_xExternalViewController, UNO_QUERY );
     784             :         OSL_ENSURE( xFormController.is(), "FmXFormShell::disposing: invalid external view controller!" );
     785           0 :         if (xFormController.is())
     786           0 :             xFormController->removeActivateListener((XFormControllerListener*)this);
     787             : 
     788           0 :         Reference< ::com::sun::star::lang::XComponent> xComp(m_xExternalViewController, UNO_QUERY);
     789           0 :         if (xComp.is())
     790           0 :             xComp->removeEventListener((XEventListener*)(XPropertyChangeListener*)this);
     791             : 
     792           0 :         m_xExternalViewController = NULL;
     793           0 :         m_xExternalDisplayedForm = NULL;
     794           0 :         m_xExtViewTriggerController = NULL;
     795             : 
     796           0 :         InvalidateSlot( SID_FM_VIEW_AS_GRID, false );
     797             :     }
     798           4 : }
     799             : 
     800             : 
     801           0 : void SAL_CALL FmXFormShell::propertyChange(const PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException, std::exception)
     802             : {
     803           0 :     if ( impl_checkDisposed() )
     804           0 :         return;
     805             : 
     806           0 :     if (evt.PropertyName == FM_PROP_ROWCOUNT)
     807             :     {
     808             :         // Das gleich folgenden Update erzwingt ein Neu-Painten der entsprechenden Slots. Wenn ich mich aber hier nicht
     809             :         // in dem HauptThread der Applikation befinde (weil zum Beispiel ein Cursor gerade Datensaetze zaehlt und mir dabei
     810             :         // immer diese PropertyChanges beschert), kann sich das mit en normalen Paints im HauptThread der Applikation beissen.
     811             :         // (Solche Paints passieren zum Beispiel, wenn man einfach nur eine andere Applikation ueber das Office legt und wieder
     812             :         // zurueckschaltet).
     813             :         // Deshalb die Benutzung des SolarMutex, der sichert das ab.
     814           0 :         comphelper::SolarMutex& rSolarSafety = Application::GetSolarMutex();
     815           0 :         if (rSolarSafety.tryToAcquire())
     816             :         {
     817           0 :             m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_RECORD_TOTAL, true, false);
     818           0 :             m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update(SID_FM_RECORD_TOTAL);
     819           0 :             rSolarSafety.release();
     820             :         }
     821             :         else
     822             :         {
     823             :             // with the following the slot is invalidated asynchron
     824           0 :             LockSlotInvalidation(true);
     825           0 :             InvalidateSlot(SID_FM_RECORD_TOTAL, false);
     826           0 :             LockSlotInvalidation(false);
     827             :         }
     828             :     }
     829             : 
     830             :     // this may be called from a non-main-thread so invalidate the shell asynchronously
     831           0 :     LockSlotInvalidation(true);
     832           0 :     InvalidateSlot(0, false);       // special meaning : invalidate m_pShell
     833           0 :     LockSlotInvalidation(false);
     834             : }
     835             : 
     836             : 
     837           0 : void FmXFormShell::invalidateFeatures( const ::std::vector< sal_Int32 >& _rFeatures )
     838             : {
     839           0 :     if ( impl_checkDisposed() )
     840           0 :         return;
     841             : 
     842             :     OSL_ENSURE( _rFeatures.size() > 0, "FmXFormShell::invalidateFeatures: invalid arguments!" );
     843             : 
     844           0 :     if ( m_pShell->GetViewShell() && m_pShell->GetViewShell()->GetViewFrame() )
     845             :     {
     846             :         // unfortunately, SFX requires sal_uInt16
     847           0 :         ::std::vector< sal_uInt16 > aSlotIds;
     848           0 :         aSlotIds.reserve( _rFeatures.size() );
     849             :         ::std::copy( _rFeatures.begin(),
     850             :             _rFeatures.end(),
     851             :             ::std::insert_iterator< ::std::vector< sal_uInt16 > >( aSlotIds, aSlotIds.begin() )
     852           0 :         );
     853             : 
     854             :         // furthermore, SFX wants a terminating 0
     855           0 :         aSlotIds.push_back( 0 );
     856             : 
     857             :         // and, last but not least, SFX wants the ids to be sorted
     858           0 :         ::std::sort( aSlotIds.begin(), aSlotIds.end() - 1 );
     859             : 
     860           0 :         sal_uInt16 *pSlotIds = &(aSlotIds[0]);
     861           0 :         m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( pSlotIds );
     862             :     }
     863             : }
     864             : 
     865             : 
     866           2 : void SAL_CALL FmXFormShell::formActivated(const EventObject& rEvent) throw( RuntimeException, std::exception )
     867             : {
     868           2 :     if ( impl_checkDisposed() )
     869           2 :         return;
     870             : 
     871           2 :     Reference< runtime::XFormController > xController( rEvent.Source, UNO_QUERY_THROW );
     872           2 :     m_pTextShell->formActivated( xController );
     873           2 :     setActiveController( xController );
     874             : }
     875             : 
     876             : 
     877           2 : void SAL_CALL FmXFormShell::formDeactivated(const EventObject& rEvent) throw( RuntimeException, std::exception )
     878             : {
     879           2 :     if ( impl_checkDisposed() )
     880           2 :         return;
     881             : 
     882           2 :     Reference< runtime::XFormController > xController( rEvent.Source, UNO_QUERY_THROW );
     883           2 :     m_pTextShell->formDeactivated( xController );
     884             : }
     885             : 
     886             : 
     887        5450 : void FmXFormShell::disposing()
     888             : {
     889             : 
     890        5450 :     FmXFormShell_BASE::disposing();
     891             : 
     892        5450 :     if ( m_pShell && !m_pShell->IsDesignMode() )
     893         320 :         setActiveController( NULL, true );
     894             :         // do NOT save the content of the old form (the second parameter tells this)
     895             :         // if we're here, then we expect that PrepareClose has been called, and thus the user
     896             :         // got a chance to commit or reject any changes. So in case we're here and there
     897             :         // are still uncommitted changes, the user explicitly wanted this.
     898             : 
     899        5450 :     m_pTextShell->dispose();
     900             : 
     901        5450 :     m_xAttachedFrame = NULL;
     902             : 
     903        5450 :     CloseExternalFormViewer();
     904             : 
     905       10902 :     while ( m_aLoadingPages.size() )
     906             :     {
     907           2 :         Application::RemoveUserEvent( m_aLoadingPages.front().nEventId );
     908           2 :         m_aLoadingPages.pop();
     909             :     }
     910             : 
     911             :     {
     912        5450 :         ::osl::MutexGuard aGuard(m_aInvalidationSafety);
     913        5450 :         if (m_nInvalidationEvent)
     914             :         {
     915           0 :             Application::RemoveUserEvent(m_nInvalidationEvent);
     916           0 :             m_nInvalidationEvent = 0;
     917             :         }
     918        5450 :         if ( m_nActivationEvent )
     919             :         {
     920        4172 :             Application::RemoveUserEvent( m_nActivationEvent );
     921        4172 :             m_nActivationEvent = 0;
     922        5450 :         }
     923             :     }
     924             : 
     925             :     {
     926        5450 :         ::osl::ClearableMutexGuard aGuard(m_aAsyncSafety);
     927        5450 :         aGuard.clear();
     928             : 
     929             :         DBG_ASSERT(!m_nInvalidationEvent, "FmXFormShell::~FmXFormShell : still have an invalidation event !");
     930             :             // should have been deleted while being disposed
     931             : 
     932        5450 :         m_aMarkTimer.Stop();
     933             :     }
     934             : 
     935        5450 :     DisableNotification();
     936             : 
     937        5450 :     RemoveElement( m_xForms );
     938        5450 :     m_xForms.clear();
     939             : 
     940        5450 :     impl_switchActiveControllerListening( false );
     941        5450 :     m_xActiveController         = NULL;
     942        5450 :     m_xActiveForm               = NULL;
     943             : 
     944        5450 :     m_pShell                    = NULL;
     945        5450 :     m_xNavigationController     = NULL;
     946        5450 :     m_xCurrentForm              = NULL;
     947        5450 :     m_xLastGridFound            = NULL;
     948        5450 :     m_xAttachedFrame            = NULL;
     949        5450 :     m_xExternalViewController   = NULL;
     950        5450 :     m_xExtViewTriggerController = NULL;
     951        5450 :     m_xExternalDisplayedForm    = NULL;
     952        5450 :     m_xLastGridFound            = NULL;
     953             : 
     954        5450 :     InterfaceBag aEmpty;
     955        5450 :     m_aCurrentSelection.swap( aEmpty );
     956             : 
     957        5450 :     m_aActiveControllerFeatures.dispose();
     958        5450 :     m_aNavControllerFeatures.dispose();
     959        5450 : }
     960             : 
     961             : 
     962           0 : void FmXFormShell::UpdateSlot( sal_Int16 _nId )
     963             : {
     964           0 :     if ( impl_checkDisposed() )
     965           0 :         return;
     966             : 
     967           0 :     ::osl::MutexGuard aGuard(m_aInvalidationSafety);
     968             : 
     969           0 :     if ( m_nLockSlotInvalidation )
     970             :     {
     971             :         OSL_FAIL( "FmXFormShell::UpdateSlot: cannot update if invalidation is currently locked!" );
     972           0 :         InvalidateSlot( _nId, false );
     973             :     }
     974             :     else
     975             :     {
     976             :         OSL_ENSURE( _nId, "FmXFormShell::UpdateSlot: can't update the complete shell!" );
     977           0 :         m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( _nId, true, true );
     978           0 :         m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update( _nId );
     979           0 :     }
     980             : }
     981             : 
     982             : 
     983         700 : void FmXFormShell::InvalidateSlot( sal_Int16 nId, bool bWithId )
     984             : {
     985         700 :     if ( impl_checkDisposed() )
     986         700 :         return;
     987             : 
     988         700 :     ::osl::MutexGuard aGuard(m_aInvalidationSafety);
     989         700 :     if (m_nLockSlotInvalidation)
     990             :     {
     991           0 :         sal_uInt8 nFlags = ( bWithId ? 0x01 : 0 );
     992           0 :         m_arrInvalidSlots.push_back( InvalidSlotInfo(nId, nFlags) );
     993             :     }
     994             :     else
     995         700 :         if (nId)
     996         642 :             m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(nId, true, bWithId);
     997             :         else
     998          58 :             m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
     999             : }
    1000             : 
    1001             : 
    1002           0 : void FmXFormShell::LockSlotInvalidation(bool bLock)
    1003             : {
    1004           0 :     if ( impl_checkDisposed() )
    1005           0 :         return;
    1006             : 
    1007           0 :     ::osl::MutexGuard aGuard(m_aInvalidationSafety);
    1008             :     DBG_ASSERT(bLock || m_nLockSlotInvalidation>0, "FmXFormShell::LockSlotInvalidation : invalid call !");
    1009             : 
    1010           0 :     if (bLock)
    1011           0 :         ++m_nLockSlotInvalidation;
    1012           0 :     else if (!--m_nLockSlotInvalidation)
    1013             :     {
    1014             :         // alles, was sich waehrend der gelockten Phase angesammelt hat, (asynchron) invalidieren
    1015           0 :         if (!m_nInvalidationEvent)
    1016           0 :             m_nInvalidationEvent = Application::PostUserEvent(LINK(this, FmXFormShell, OnInvalidateSlots));
    1017           0 :     }
    1018             : }
    1019             : 
    1020             : 
    1021           0 : IMPL_LINK_NOARG(FmXFormShell, OnInvalidateSlots)
    1022             : {
    1023           0 :     if ( impl_checkDisposed() )
    1024           0 :         return 0L;
    1025             : 
    1026           0 :     ::osl::MutexGuard aGuard(m_aInvalidationSafety);
    1027           0 :     m_nInvalidationEvent = 0;
    1028             : 
    1029           0 :     for (std::vector<InvalidSlotInfo>::const_iterator i = m_arrInvalidSlots.begin(); i < m_arrInvalidSlots.end(); ++i)
    1030             :     {
    1031           0 :         if (i->id)
    1032           0 :             m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(i->id, true, (i->flags & 0x01));
    1033             :         else
    1034           0 :             m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
    1035             :     }
    1036           0 :     m_arrInvalidSlots.clear();
    1037           0 :     return 0L;
    1038             : }
    1039             : 
    1040             : 
    1041           0 : void FmXFormShell::ForceUpdateSelection(bool bAllowInvalidation)
    1042             : {
    1043           0 :     if ( impl_checkDisposed() )
    1044           0 :         return;
    1045             : 
    1046           0 :     if (IsSelectionUpdatePending())
    1047             :     {
    1048           0 :         m_aMarkTimer.Stop();
    1049             : 
    1050             :         // die Invalidierung der Slots, die implizit von SetSelection besorgt wird, eventuell abschalten
    1051           0 :         if (!bAllowInvalidation)
    1052           0 :             LockSlotInvalidation(true);
    1053             : 
    1054           0 :         SetSelection(m_pShell->GetFormView()->GetMarkedObjectList());
    1055             : 
    1056           0 :         if (!bAllowInvalidation)
    1057           0 :             LockSlotInvalidation(false);
    1058             :     }
    1059             : }
    1060             : 
    1061             : 
    1062           0 : PopupMenu* FmXFormShell::GetConversionMenu()
    1063             : {
    1064             : 
    1065           0 :     PopupMenu* pNewMenu = new PopupMenu(SVX_RES( RID_FMSHELL_CONVERSIONMENU ));
    1066             : 
    1067           0 :     ImageList aImageList( SVX_RES( RID_SVXIMGLIST_FMEXPL) );
    1068           0 :     for ( size_t i = 0; i < sizeof (nConvertSlots) / sizeof (nConvertSlots[0]); ++i )
    1069             :     {
    1070             :         // das entsprechende Image dran
    1071           0 :         pNewMenu->SetItemImage(nConvertSlots[i], aImageList.GetImage(nCreateSlots[i]));
    1072             :     }
    1073             : 
    1074           0 :     return pNewMenu;
    1075             : }
    1076             : 
    1077             : 
    1078           0 : bool FmXFormShell::isControlConversionSlot( sal_uInt16 nSlotId )
    1079             : {
    1080           0 :     for ( size_t i = 0; i < sizeof (nConvertSlots) / sizeof (nConvertSlots[0]); ++i )
    1081           0 :         if (nConvertSlots[i] == nSlotId)
    1082           0 :             return true;
    1083           0 :     return false;
    1084             : }
    1085             : 
    1086             : 
    1087           0 : bool FmXFormShell::executeControlConversionSlot( sal_uInt16 _nSlotId )
    1088             : {
    1089             :     OSL_PRECOND( canConvertCurrentSelectionToControl( _nSlotId ), "FmXFormShell::executeControlConversionSlot: illegal call!" );
    1090           0 :     InterfaceBag::const_iterator aSelectedElement = m_aCurrentSelection.begin();
    1091           0 :     if ( aSelectedElement == m_aCurrentSelection.end() )
    1092           0 :         return false;
    1093             : 
    1094           0 :     return executeControlConversionSlot( Reference< XFormComponent >( *aSelectedElement, UNO_QUERY ), _nSlotId );
    1095             : }
    1096             : 
    1097             : 
    1098           0 : bool FmXFormShell::executeControlConversionSlot( const Reference< XFormComponent >& _rxObject, sal_uInt16 _nSlotId )
    1099             : {
    1100           0 :     if ( impl_checkDisposed() )
    1101           0 :         return false;
    1102             : 
    1103             :     OSL_ENSURE( _rxObject.is(), "FmXFormShell::executeControlConversionSlot: invalid object!" );
    1104           0 :     if ( !_rxObject.is() )
    1105           0 :         return false;
    1106             : 
    1107           0 :     SdrPage* pPage = m_pShell->GetCurPage();
    1108           0 :     FmFormPage* pFormPage = pPage ? dynamic_cast< FmFormPage* >( pPage ) : NULL;
    1109             :     OSL_ENSURE( pFormPage, "FmXFormShell::executeControlConversionSlot: no current (form) page!" );
    1110           0 :     if ( !pFormPage )
    1111           0 :         return false;
    1112             : 
    1113             :     OSL_ENSURE( isSolelySelected( _rxObject ),
    1114             :         "FmXFormShell::executeControlConversionSlot: hmm ... shouldn't this parameter be redundant?" );
    1115             : 
    1116           0 :     for ( size_t lookupSlot = 0; lookupSlot < sizeof( nConvertSlots ) / sizeof( nConvertSlots[0] ); ++lookupSlot )
    1117             :     {
    1118           0 :         if (nConvertSlots[lookupSlot] == _nSlotId)
    1119             :         {
    1120           0 :             Reference< XInterface > xNormalizedObject( _rxObject, UNO_QUERY );
    1121             : 
    1122           0 :             FmFormObj* pFormObject = NULL;
    1123           0 :             SdrObjListIter aPageIter( *pFormPage );
    1124           0 :             while ( aPageIter.IsMore() )
    1125             :             {
    1126           0 :                 SdrObject* pCurrent = aPageIter.Next();
    1127           0 :                 pFormObject = FmFormObj::GetFormObject( pCurrent );
    1128           0 :                 if ( !pFormObject )
    1129           0 :                     continue;
    1130             : 
    1131           0 :                 Reference< XInterface > xCurrentNormalized( pFormObject->GetUnoControlModel(), UNO_QUERY );
    1132           0 :                 if ( xCurrentNormalized.get() == xNormalizedObject.get() )
    1133           0 :                     break;
    1134             : 
    1135           0 :                 pFormObject = NULL;
    1136           0 :             }
    1137             : 
    1138           0 :             if ( !pFormObject )
    1139           0 :                 return false;
    1140             : 
    1141           0 :             OUString sNewName( getServiceNameByControlType( nObjectTypes[ lookupSlot ] ) );
    1142           0 :             Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
    1143           0 :             Reference< XControlModel> xNewModel( xContext->getServiceManager()->createInstanceWithContext(sNewName, xContext), UNO_QUERY );
    1144           0 :             if (!xNewModel.is())
    1145           0 :                 return false;
    1146             : 
    1147           0 :             Reference< XControlModel> xOldModel( pFormObject->GetUnoControlModel() );
    1148           0 :             Reference< XServiceInfo> xModelInfo(xOldModel, UNO_QUERY);
    1149             : 
    1150             :             // Properties uebertragen
    1151           0 :             Reference< XPropertySet> xOldSet(xOldModel, UNO_QUERY);
    1152           0 :             Reference< XPropertySet> xNewSet(xNewModel, UNO_QUERY);
    1153             : 
    1154             : 
    1155           0 :             Locale aNewLanguage = Application::GetSettings().GetUILanguageTag().getLocale();
    1156           0 :             TransferFormComponentProperties(xOldSet, xNewSet, aNewLanguage);
    1157             : 
    1158           0 :             Sequence< ::com::sun::star::script::ScriptEventDescriptor> aOldScripts;
    1159           0 :             Reference< XChild> xChild(xOldModel, UNO_QUERY);
    1160           0 :             if (xChild.is())
    1161             :             {
    1162           0 :                 Reference< XIndexAccess> xParent(xChild->getParent(), UNO_QUERY);
    1163             : 
    1164             :                 // remember old script events
    1165           0 :                 Reference< ::com::sun::star::script::XEventAttacherManager> xEvManager(xChild->getParent(), UNO_QUERY);
    1166           0 :                 if (xParent.is() && xEvManager.is())
    1167             :                 {
    1168           0 :                     sal_Int32 nIndex = getElementPos(xParent, xOldModel);
    1169           0 :                     if (nIndex>=0 && nIndex<xParent->getCount())
    1170           0 :                         aOldScripts = xEvManager->getScriptEvents(nIndex);
    1171             :                 }
    1172             : 
    1173             :                 // replace the mdoel within the parent container
    1174           0 :                 Reference< XIndexContainer> xIndexParent(xChild->getParent(), UNO_QUERY);
    1175           0 :                 if (xIndexParent.is())
    1176             :                 {
    1177             :                     // the form container works with FormComponents
    1178           0 :                     Reference< XFormComponent> xComponent(xNewModel, UNO_QUERY);
    1179             :                     DBG_ASSERT(xComponent.is(), "FmXFormShell::executeControlConversionSlot: the new model is no form component !");
    1180           0 :                     Any aNewModel(makeAny(xComponent));
    1181             :                     try
    1182             :                     {
    1183             : 
    1184           0 :                         sal_Int32 nIndex = getElementPos(xParent, xOldModel);
    1185           0 :                         if (nIndex>=0 && nIndex<xParent->getCount())
    1186           0 :                             xIndexParent->replaceByIndex(nIndex, aNewModel);
    1187             :                         else
    1188             :                         {
    1189             :                             OSL_FAIL("FmXFormShell::executeControlConversionSlot: could not replace the model !");
    1190           0 :                             Reference< ::com::sun::star::lang::XComponent> xNewComponent(xNewModel, UNO_QUERY);
    1191           0 :                             if (xNewComponent.is())
    1192           0 :                                 xNewComponent->dispose();
    1193           0 :                             return false;
    1194             :                         }
    1195             :                     }
    1196           0 :                     catch(Exception&)
    1197             :                     {
    1198             :                         OSL_FAIL("FmXFormShell::executeControlConversionSlot: could not replace the model !");
    1199           0 :                         Reference< ::com::sun::star::lang::XComponent> xNewComponent(xNewModel, UNO_QUERY);
    1200           0 :                         if (xNewComponent.is())
    1201           0 :                             xNewComponent->dispose();
    1202           0 :                         return false;
    1203           0 :                     }
    1204             : 
    1205           0 :                 }
    1206             :             }
    1207             : 
    1208             :             // special handling for the LabelControl-property : can only be set when the model is placed
    1209             :             // within the forms hierarchy
    1210           0 :             if (::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xOldSet) && ::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xNewSet))
    1211             :             {
    1212             :                 try
    1213             :                 {
    1214           0 :                     xNewSet->setPropertyValue(FM_PROP_CONTROLLABEL, xOldSet->getPropertyValue(FM_PROP_CONTROLLABEL));
    1215             :                 }
    1216           0 :                 catch(Exception&)
    1217             :                 {
    1218             :                 }
    1219             : 
    1220             :             }
    1221             : 
    1222             :             // neues Model setzen
    1223           0 :             pFormObject->SetChanged();
    1224           0 :             pFormObject->SetUnoControlModel(xNewModel);
    1225             : 
    1226             :             // transfer script events
    1227             :             // (do this _after_ SetUnoControlModel as we need the new (implicitly created) control)
    1228           0 :             if (aOldScripts.getLength())
    1229             :             {
    1230             :                 // das Control zum Model suchen
    1231           0 :                 Reference< XControlContainer > xControlContainer( getControlContainerForView() );
    1232             : 
    1233           0 :                 Sequence< Reference< XControl> > aControls( xControlContainer->getControls() );
    1234           0 :                 const Reference< XControl>* pControls = aControls.getConstArray();
    1235             : 
    1236           0 :                 sal_uInt32 nLen = aControls.getLength();
    1237           0 :                 Reference< XControl> xControl;
    1238           0 :                 for (sal_uInt32 i=0 ; i<nLen; ++i)
    1239             :                 {
    1240           0 :                     if (pControls[i]->getModel() == xNewModel)
    1241             :                     {
    1242           0 :                         xControl = pControls[i];
    1243           0 :                         break;
    1244             :                     }
    1245             :                 }
    1246           0 :                 TransferEventScripts(xNewModel, xControl, aOldScripts);
    1247             :             }
    1248             : 
    1249             :             // transfer value bindings, if possible
    1250             :             {
    1251           0 :                 Reference< XBindableValue > xOldBindable( xOldModel, UNO_QUERY );
    1252           0 :                 Reference< XBindableValue > xNewBindable( xNewModel, UNO_QUERY );
    1253           0 :                 if ( xOldBindable.is() )
    1254             :                 {
    1255             :                     try
    1256             :                     {
    1257           0 :                         if ( xNewBindable.is() )
    1258           0 :                             xNewBindable->setValueBinding( xOldBindable->getValueBinding() );
    1259           0 :                         xOldBindable->setValueBinding( NULL );
    1260             :                     }
    1261           0 :                     catch(const Exception&)
    1262             :                     {
    1263             :                         DBG_UNHANDLED_EXCEPTION();
    1264             :                     }
    1265           0 :                 }
    1266             :             }
    1267             :             // same for list entry sources
    1268             :             {
    1269           0 :                 Reference< XListEntrySink > xOldSink( xOldModel, UNO_QUERY );
    1270           0 :                 Reference< XListEntrySink > xNewSink( xNewModel, UNO_QUERY );
    1271           0 :                 if ( xOldSink.is() )
    1272             :                 {
    1273             :                     try
    1274             :                     {
    1275           0 :                         if ( xNewSink.is() )
    1276           0 :                             xNewSink->setListEntrySource( xOldSink->getListEntrySource() );
    1277           0 :                         xOldSink->setListEntrySource( NULL );
    1278             :                     }
    1279           0 :                     catch(const Exception&)
    1280             :                     {
    1281             :                         DBG_UNHANDLED_EXCEPTION();
    1282             :                     }
    1283           0 :                 }
    1284             :             }
    1285             : 
    1286             :             // create an undo action
    1287           0 :             FmFormModel* pModel = m_pShell->GetFormModel();
    1288             :             DBG_ASSERT(pModel != NULL, "FmXFormShell::executeControlConversionSlot: my shell has no model !");
    1289           0 :             if (pModel && pModel->IsUndoEnabled() )
    1290             :             {
    1291           0 :                 pModel->AddUndo(new FmUndoModelReplaceAction(*pModel, pFormObject, xOldModel));
    1292             :             }
    1293             :             else
    1294             :             {
    1295           0 :                 FmUndoModelReplaceAction::DisposeElement( xOldModel );
    1296             :             }
    1297             : 
    1298           0 :             return true;
    1299             :         }
    1300             :     }
    1301           0 :     return false;
    1302             : }
    1303             : 
    1304             : 
    1305           0 : bool FmXFormShell::canConvertCurrentSelectionToControl( sal_Int16 nConversionSlot )
    1306             : {
    1307           0 :     if ( m_aCurrentSelection.empty() )
    1308           0 :         return false;
    1309             : 
    1310           0 :     InterfaceBag::const_iterator aCheck = m_aCurrentSelection.begin();
    1311           0 :     Reference< XServiceInfo > xElementInfo( *aCheck, UNO_QUERY );
    1312           0 :     if ( !xElementInfo.is() )
    1313             :         // no service info -> cannot determine this
    1314           0 :         return false;
    1315             : 
    1316           0 :     if (  ++aCheck != m_aCurrentSelection.end() )
    1317             :         // more than one element
    1318           0 :         return false;
    1319             : 
    1320           0 :     if ( Reference< XForm >::query( xElementInfo ).is() )
    1321             :         // it's a form
    1322           0 :         return false;
    1323             : 
    1324           0 :     sal_Int16 nObjectType = getControlTypeByObject( xElementInfo );
    1325             : 
    1326           0 :     if (  ( OBJ_FM_HIDDEN == nObjectType )
    1327           0 :        || ( OBJ_FM_CONTROL == nObjectType )
    1328           0 :        || ( OBJ_FM_GRID == nObjectType )
    1329             :        )
    1330           0 :         return false;   // those types cannot be converted
    1331             : 
    1332             :     DBG_ASSERT(sizeof(nConvertSlots)/sizeof(nConvertSlots[0]) == sizeof(nObjectTypes)/sizeof(nObjectTypes[0]),
    1333             :         "FmXFormShell::canConvertCurrentSelectionToControl: nConvertSlots & nObjectTypes must have the same size !");
    1334             : 
    1335           0 :     for ( size_t i = 0; i < sizeof( nConvertSlots ) / sizeof( nConvertSlots[0] ); ++i )
    1336           0 :         if (nConvertSlots[i] == nConversionSlot)
    1337           0 :             return nObjectTypes[i] != nObjectType;
    1338             : 
    1339           0 :     return true;    // all other slots: assume "yes"
    1340             : }
    1341             : 
    1342             : 
    1343           0 : void FmXFormShell::checkControlConversionSlotsForCurrentSelection( Menu& rMenu )
    1344             : {
    1345           0 :     for (sal_Int16 i=0; i<rMenu.GetItemCount(); ++i)
    1346             :         // der Context ist schon von einem Typ, der dem Eitnrag entspricht -> disable
    1347           0 :         rMenu.EnableItem( rMenu.GetItemId(i), canConvertCurrentSelectionToControl( rMenu.GetItemId( i ) ) );
    1348           0 : }
    1349             : 
    1350             : 
    1351           0 : void FmXFormShell::LoopGrids(sal_Int16 nWhat)
    1352             : {
    1353           0 :     if ( impl_checkDisposed() )
    1354           0 :         return;
    1355             : 
    1356           0 :     Reference< XIndexContainer> xControlModels(m_xActiveForm, UNO_QUERY);
    1357           0 :     if (xControlModels.is())
    1358             :     {
    1359           0 :         for (sal_Int16 i=0; i<xControlModels->getCount(); ++i)
    1360             :         {
    1361           0 :             Reference< XPropertySet> xModelSet;
    1362           0 :             xControlModels->getByIndex(i) >>= xModelSet;
    1363           0 :             if (!xModelSet.is())
    1364           0 :                 continue;
    1365             : 
    1366           0 :             if (!::comphelper::hasProperty(FM_PROP_CLASSID, xModelSet))
    1367           0 :                 continue;
    1368           0 :             sal_Int16 nClassId = ::comphelper::getINT16(xModelSet->getPropertyValue(FM_PROP_CLASSID));
    1369           0 :             if (FormComponentType::GRIDCONTROL != nClassId)
    1370           0 :                 continue;
    1371             : 
    1372           0 :             if (!::comphelper::hasProperty(FM_PROP_CURSORCOLOR, xModelSet) || !::comphelper::hasProperty(FM_PROP_ALWAYSSHOWCURSOR, xModelSet) || !::comphelper::hasProperty(FM_PROP_DISPLAYSYNCHRON, xModelSet))
    1373           0 :                 continue;
    1374             : 
    1375           0 :             switch (nWhat & GA_SYNC_MASK)
    1376             :             {
    1377             :                 case GA_DISABLE_SYNC:
    1378             :                     {
    1379           0 :                         sal_Bool bB(sal_False);
    1380           0 :                         xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
    1381             :                     }
    1382           0 :                     break;
    1383             :                 case GA_FORCE_SYNC:
    1384             :                 {
    1385           0 :                     Any aOldVal( xModelSet->getPropertyValue(FM_PROP_DISPLAYSYNCHRON) );
    1386           0 :                     sal_Bool bB(sal_True);
    1387           0 :                     xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
    1388           0 :                     xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, aOldVal);
    1389             :                 }
    1390           0 :                 break;
    1391             :                 case GA_ENABLE_SYNC:
    1392             :                     {
    1393           0 :                         sal_Bool bB(sal_True);
    1394           0 :                         xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
    1395             :                     }
    1396           0 :                     break;
    1397             :             }
    1398             : 
    1399           0 :             if (nWhat & GA_DISABLE_ROCTRLR)
    1400             :             {
    1401           0 :                 sal_Bool bB(sal_False);
    1402           0 :                 xModelSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any(&bB,getBooleanCppuType()));
    1403           0 :                 Reference< XPropertyState> xModelPropState(xModelSet, UNO_QUERY);
    1404           0 :                 if (xModelPropState.is())
    1405           0 :                     xModelPropState->setPropertyToDefault(FM_PROP_CURSORCOLOR);
    1406             :                 else
    1407           0 :                     xModelSet->setPropertyValue(FM_PROP_CURSORCOLOR, Any());        // this should be the default
    1408             :             }
    1409           0 :             else if (nWhat & GA_ENABLE_ROCTRLR)
    1410             :             {
    1411           0 :                 sal_Bool bB(sal_True);
    1412           0 :                 xModelSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any(&bB,getBooleanCppuType()));
    1413           0 :                 xModelSet->setPropertyValue(FM_PROP_CURSORCOLOR, makeAny(sal_Int32(COL_LIGHTRED)));
    1414             :             }
    1415           0 :         }
    1416           0 :     }
    1417             : }
    1418             : 
    1419             : 
    1420           0 : Reference< XControlContainer > FmXFormShell::getControlContainerForView()
    1421             : {
    1422           0 :     if ( impl_checkDisposed() )
    1423           0 :         return NULL;
    1424             : 
    1425           0 :     SdrPageView* pPageView = NULL;
    1426           0 :     if ( m_pShell && m_pShell->GetFormView() )
    1427           0 :         pPageView = m_pShell->GetFormView()->GetSdrPageView();
    1428             : 
    1429           0 :     Reference< XControlContainer> xControlContainer;
    1430           0 :     if ( pPageView )
    1431           0 :         xControlContainer = pPageView->GetPageWindow(0)->GetControlContainer();
    1432             : 
    1433           0 :     return xControlContainer;
    1434             : }
    1435             : 
    1436             : 
    1437           0 : void FmXFormShell::ExecuteTabOrderDialog( const Reference< XTabControllerModel >& _rxForForm )
    1438             : {
    1439           0 :     if ( impl_checkDisposed() )
    1440           0 :         return;
    1441             : 
    1442             :     OSL_PRECOND( _rxForForm.is(), "FmXFormShell::ExecuteTabOrderDialog: invalid tabbing model!" );
    1443           0 :     if ( !_rxForForm.is() )
    1444           0 :         return;
    1445             : 
    1446             :     try
    1447             :     {
    1448           0 :         Reference< XWindow > xParentWindow;
    1449           0 :         if ( m_pShell->GetViewShell() && m_pShell->GetViewShell()->GetViewFrame() )
    1450           0 :             xParentWindow = VCLUnoHelper::GetInterface ( &m_pShell->GetViewShell()->GetViewFrame()->GetWindow() );
    1451             : 
    1452             :         Reference< dialogs::XExecutableDialog > xDialog = form::TabOrderDialog::createWithModel(
    1453             :                 comphelper::getProcessComponentContext(),
    1454             :                 _rxForForm, getControlContainerForView(), xParentWindow
    1455           0 :             );
    1456             : 
    1457           0 :         xDialog->execute();
    1458             :     }
    1459           0 :     catch( const Exception& )
    1460             :     {
    1461             :         OSL_FAIL( "FmXFormShell::ExecuteTabOrderDialog: caught an exception!" );
    1462             :     }
    1463             : }
    1464             : 
    1465             : 
    1466           0 : void FmXFormShell::ExecuteSearch()
    1467             : {
    1468           0 :     if ( impl_checkDisposed() )
    1469           0 :         return;
    1470             : 
    1471             :     // eine Sammlung aller (logischen) Formulare
    1472           0 :     FmFormArray aEmpty;
    1473           0 :     m_aSearchForms.swap( aEmpty );
    1474           0 :     ::std::vector< OUString > aContextNames;
    1475           0 :     impl_collectFormSearchContexts_nothrow( m_pShell->GetCurPage()->GetForms(), OUString(), m_aSearchForms, aContextNames );
    1476             : 
    1477           0 :     if ( m_aSearchForms.size() != aContextNames.size() )
    1478             :     {
    1479             :         SAL_WARN ( "svx.form", "FmXFormShell::ExecuteSearch: nonsense!" );
    1480           0 :         return;
    1481             :     }
    1482             : 
    1483             :     // filter out the forms which do not contain valid controls at all
    1484             :     {
    1485           0 :         FmFormArray aValidForms;
    1486           0 :         ::std::vector< OUString > aValidContexts;
    1487           0 :         FmFormArray::const_iterator form = m_aSearchForms.begin();
    1488           0 :         ::std::vector< OUString >::const_iterator contextName = aContextNames.begin();
    1489           0 :         for ( ; form != m_aSearchForms.end(); ++form, ++contextName )
    1490             :         {
    1491           0 :             FmSearchContext aTestContext;
    1492           0 :             aTestContext.nContext = static_cast< sal_Int16 >( form - m_aSearchForms.begin() );
    1493           0 :             sal_uInt32 nValidControls = OnSearchContextRequest( &aTestContext );
    1494           0 :             if ( nValidControls > 0 )
    1495             :             {
    1496           0 :                 aValidForms.push_back( *form );
    1497           0 :                 aValidContexts.push_back( *contextName );
    1498             :             }
    1499           0 :         }
    1500             : 
    1501           0 :         m_aSearchForms.swap( aValidForms );
    1502           0 :         aContextNames.swap( aValidContexts );
    1503             :     }
    1504             : 
    1505           0 :     if (m_aSearchForms.empty() )
    1506             :     {   // es gibt keine Controls, die alle Bedingungen fuer eine Suche erfuellen
    1507           0 :         MessageDialog(NULL, SVX_RESSTR(RID_STR_NODATACONTROLS)).Execute();
    1508           0 :         return;
    1509             :     }
    1510             : 
    1511             :     // jetzt brauche ich noch einen 'initial context'
    1512           0 :     sal_Int16 nInitialContext = 0;
    1513           0 :     Reference< XForm> xActiveForm( getActiveForm());
    1514           0 :     for ( size_t i=0; i<m_aSearchForms.size(); ++i )
    1515             :     {
    1516           0 :         if (m_aSearchForms.at(i) == xActiveForm)
    1517             :         {
    1518           0 :             nInitialContext = (sal_Int16)i;
    1519           0 :             break;
    1520             :         }
    1521             :     }
    1522             : 
    1523             :     // wenn der Dialog initial den Text des aktiven Controls anbieten soll, muss dieses ein XTextComponent-Interface habe,
    1524             :     // ausserdem macht das nur Sinn, wenn das aktuelle Feld auch an ein Tabellen- (oder was-auch-immer-)Feld gebunden ist
    1525           0 :     OUString strActiveField;
    1526           0 :     OUString strInitialText;
    1527             :     // ... das bekomme ich von meinem FormController
    1528             :     DBG_ASSERT(m_xActiveController.is(), "FmXFormShell::ExecuteSearch : no active controller !");
    1529           0 :     Reference< XControl> xActiveControl( m_xActiveController->getCurrentControl());
    1530           0 :     if (xActiveControl.is())
    1531             :     {
    1532             :         // das Control kann mir sein Model sagen ...
    1533           0 :         Reference< XControlModel> xActiveModel( xActiveControl->getModel());
    1534             :         DBG_ASSERT(xActiveModel.is(), "FmXFormShell::ExecuteSearch : active control has no model !");
    1535             : 
    1536             :         // das Model frage ich nach der ControlSource-Eigenschaft ...
    1537           0 :         Reference< XPropertySet> xProperties(xActiveControl->getModel(), UNO_QUERY);
    1538           0 :         if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xProperties) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xProperties))
    1539             :         {
    1540           0 :             Reference< XPropertySet> xField;
    1541           0 :             xProperties->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField;
    1542           0 :             if (xField.is())    // (nur wenn das Ding wirklich gebunden ist)
    1543             :             {
    1544             :                 // und das Control selber nach einem TextComponent-Interface (damit ich mir dort den Text abholen kann)
    1545           0 :                 Reference< XTextComponent> xText(xActiveControl, UNO_QUERY);
    1546           0 :                 if (xText.is())
    1547             :                 {
    1548           0 :                     strActiveField = getLabelName(xProperties).getStr();
    1549           0 :                     strInitialText = xText->getText().getStr();
    1550           0 :                 }
    1551           0 :             }
    1552             :         }
    1553             :         else
    1554             :         {
    1555             :             // das Control selber hat keine ControlSource, aber vielleicht ist es ein GridControl
    1556           0 :             Reference< XGrid> xGrid(xActiveControl, UNO_QUERY);
    1557           0 :             if (xGrid.is())
    1558             :             {
    1559             :                 // fuer strActiveField brauche ich die die ControlSource der Column, dafuer den Columns-Container, dafuer die
    1560             :                 // GridPeer
    1561           0 :                 Reference< XGridPeer> xGridPeer(xActiveControl->getPeer(), UNO_QUERY);
    1562           0 :                 Reference< XIndexAccess> xColumns;
    1563           0 :                 if (xGridPeer.is())
    1564           0 :                     xColumns = Reference< XIndexAccess>(xGridPeer->getColumns(),UNO_QUERY);
    1565             : 
    1566           0 :                 sal_Int16 nViewCol = xGrid->getCurrentColumnPosition();
    1567           0 :                 sal_Int16 nModelCol = GridView2ModelPos(xColumns, nViewCol);
    1568           0 :                 Reference< XPropertySet> xCurrentCol;
    1569           0 :                 if(xColumns.is())
    1570           0 :                     xColumns->getByIndex(nModelCol) >>= xCurrentCol;
    1571           0 :                 if (xCurrentCol.is())
    1572           0 :                     strActiveField = ::comphelper::getString(xCurrentCol->getPropertyValue(FM_PROP_LABEL)).getStr();
    1573             : 
    1574             :                 // the text fo the current column
    1575           0 :                 Reference< XIndexAccess> xColControls(xGridPeer, UNO_QUERY);
    1576           0 :                 Reference< XInterface> xCurControl;
    1577           0 :                 xColControls->getByIndex(nViewCol) >>= xCurControl;
    1578           0 :                 OUString sInitialText;
    1579           0 :                 if (IsSearchableControl(xCurControl, &sInitialText))
    1580           0 :                     strInitialText = sInitialText.getStr();
    1581           0 :             }
    1582           0 :         }
    1583             :     }
    1584             : 
    1585             :     // um eventuelle GridControls, die ich kenne, kuemmern
    1586           0 :     LoopGrids(GA_DISABLE_SYNC /*| GA_ENABLE_ROCTRLR*/);
    1587             : 
    1588             :     // jetzt bin ich reif fuer den Dialog
    1589             :     // wenn die potentiellen Deadlocks, die durch die Benutzung des Solar-Mutex in MTs VCLX...-Klasen entstehen, irgendwann mal
    1590             :     // ausgeraeumt sind, sollte hier ein SM_USETHREAD rein, denn die Suche in einem eigenen Thread ist doch etwas fluessiger
    1591             :     // sollte allerdings irgendwie von dem unterliegenden Cursor abhaengig gemacht werden, DAO zum Beispiel ist nicht thread-sicher
    1592           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    1593           0 :     boost::scoped_ptr<AbstractFmSearchDialog> pDialog;
    1594           0 :     if ( pFact )
    1595           0 :         pDialog.reset(pFact->CreateFmSearchDialog( &m_pShell->GetViewShell()->GetViewFrame()->GetWindow(), strInitialText, aContextNames, nInitialContext, LINK( this, FmXFormShell, OnSearchContextRequest ) ));
    1596             :     DBG_ASSERT( pDialog, "FmXFormShell::ExecuteSearch: could not create the search dialog!" );
    1597           0 :     if ( pDialog )
    1598             :     {
    1599           0 :         pDialog->SetActiveField( strActiveField );
    1600           0 :         pDialog->SetFoundHandler( LINK( this, FmXFormShell, OnFoundData ) );
    1601           0 :         pDialog->SetCanceledNotFoundHdl( LINK( this, FmXFormShell, OnCanceledNotFound ) );
    1602           0 :         pDialog->Execute();
    1603           0 :         pDialog.reset();
    1604             :     }
    1605             : 
    1606             :     // GridControls wieder restaurieren
    1607           0 :     LoopGrids(GA_ENABLE_SYNC | GA_DISABLE_ROCTRLR);
    1608             : 
    1609           0 :     m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView());
    1610             :         // da ich in OnFoundData (fals ich dort war) Controls markiert habe
    1611             : }
    1612             : 
    1613             : 
    1614           0 : bool FmXFormShell::GetY2KState(sal_uInt16& n)
    1615             : {
    1616           0 :     if ( impl_checkDisposed() )
    1617           0 :         return false;
    1618             : 
    1619           0 :     if (m_pShell->IsDesignMode())
    1620             :         // im Design-Modus (ohne aktive Controls) soll sich das Haupt-Dokument darum kuemmern
    1621           0 :         return false;
    1622             : 
    1623           0 :     Reference< XForm> xForm( getActiveForm());
    1624           0 :     if (!xForm.is())
    1625             :         // kein aktuelles Formular (also insbesondere kein aktuelles Control) -> das Haupt-Dokument soll sich kuemmern
    1626           0 :         return false;
    1627             : 
    1628           0 :     Reference< XRowSet> xDB(xForm, UNO_QUERY);
    1629             :     DBG_ASSERT(xDB.is(), "FmXFormShell::GetY2KState : current form has no dbform-interface !");
    1630             : 
    1631           0 :     Reference< XNumberFormatsSupplier> xSupplier( getNumberFormats(OStaticDataAccessTools().getRowSetConnection(xDB), false));
    1632           0 :     if (xSupplier.is())
    1633             :     {
    1634           0 :         Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
    1635           0 :         if (xSet.is())
    1636             :         {
    1637             :             try
    1638             :             {
    1639           0 :                 Any aVal( xSet->getPropertyValue("TwoDigitDateStart") );
    1640           0 :                 aVal >>= n;
    1641           0 :                 return true;
    1642             :             }
    1643           0 :             catch(Exception&)
    1644             :             {
    1645             :             }
    1646             : 
    1647           0 :         }
    1648             :     }
    1649           0 :     return false;
    1650             : }
    1651             : 
    1652             : 
    1653          10 : void FmXFormShell::SetY2KState(sal_uInt16 n)
    1654             : {
    1655          10 :     if ( impl_checkDisposed() )
    1656          10 :         return;
    1657             : 
    1658          10 :     Reference< XForm > xActiveForm( getActiveForm());
    1659          10 :     Reference< XRowSet > xActiveRowSet( xActiveForm, UNO_QUERY );
    1660          10 :     if ( xActiveRowSet.is() )
    1661             :     {
    1662           0 :         Reference< XNumberFormatsSupplier > xSupplier( getNumberFormats( getRowSetConnection( xActiveRowSet ), false ) );
    1663           0 :         if (xSupplier.is())
    1664             :         {
    1665           0 :             Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
    1666           0 :             if (xSet.is())
    1667             :             {
    1668             :                 try
    1669             :                 {
    1670           0 :                     Any aVal;
    1671           0 :                     aVal <<= n;
    1672           0 :                     xSet->setPropertyValue("TwoDigitDateStart", aVal);
    1673             :                 }
    1674           0 :                 catch(Exception&)
    1675             :                 {
    1676             :                     OSL_FAIL("FmXFormShell::SetY2KState: Exception occurred!");
    1677             :                 }
    1678             : 
    1679             :             }
    1680           0 :             return;
    1681           0 :         }
    1682             :     }
    1683             : 
    1684             :     // kein aktives Formular gefunden -> alle aktuell vorhandenen Formulare durchiterieren
    1685          10 :     Reference< XIndexAccess> xCurrentForms( m_xForms);
    1686          10 :     if (!xCurrentForms.is())
    1687             :     {   // im alive-Modus sind meine Forms nicht gesetzt, wohl aber die an der Page
    1688          10 :         if (m_pShell->GetCurPage())
    1689          10 :             xCurrentForms = Reference< XIndexAccess>( m_pShell->GetCurPage()->GetForms( false ), UNO_QUERY );
    1690             :     }
    1691          10 :     if (!xCurrentForms.is())
    1692          10 :         return;
    1693             : 
    1694           0 :     ::comphelper::IndexAccessIterator aIter(xCurrentForms);
    1695           0 :     Reference< XInterface> xCurrentElement( aIter.Next());
    1696           0 :     while (xCurrentElement.is())
    1697             :     {
    1698             :         // ist das aktuelle Element eine DatabaseForm ?
    1699           0 :         Reference< XRowSet> xElementAsRowSet( xCurrentElement, UNO_QUERY );
    1700           0 :         if ( xElementAsRowSet.is() )
    1701             :         {
    1702           0 :             Reference< XNumberFormatsSupplier > xSupplier( getNumberFormats( getRowSetConnection( xElementAsRowSet ), false ) );
    1703           0 :             if (!xSupplier.is())
    1704           0 :                 continue;
    1705             : 
    1706           0 :             Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
    1707           0 :             if (xSet.is())
    1708             :             {
    1709             :                 try
    1710             :                 {
    1711           0 :                     Any aVal;
    1712           0 :                     aVal <<= n;
    1713           0 :                     xSet->setPropertyValue("TwoDigitDateStart", aVal);
    1714             :                 }
    1715           0 :                 catch(Exception&)
    1716             :                 {
    1717             :                     OSL_FAIL("FmXFormShell::SetY2KState: Exception occurred!");
    1718             :                 }
    1719             : 
    1720           0 :             }
    1721             :         }
    1722           0 :         xCurrentElement = aIter.Next();
    1723           0 :     }
    1724             : }
    1725             : 
    1726             : 
    1727        5450 : void FmXFormShell::CloseExternalFormViewer()
    1728             : {
    1729        5450 :     if ( impl_checkDisposed() )
    1730        5450 :         return;
    1731             : 
    1732        5450 :     if (!m_xExternalViewController.is())
    1733        5450 :         return;
    1734             : 
    1735           0 :     Reference< ::com::sun::star::frame::XFrame> xExternalViewFrame( m_xExternalViewController->getFrame());
    1736           0 :     Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
    1737           0 :     if (!xCommLink.is())
    1738           0 :         return;
    1739             : 
    1740           0 :     xExternalViewFrame->setComponent(NULL,NULL);
    1741           0 :     ::comphelper::disposeComponent(xExternalViewFrame);
    1742           0 :     m_xExternalViewController   = NULL;
    1743           0 :     m_xExtViewTriggerController = NULL;
    1744           0 :     m_xExternalDisplayedForm    = NULL;
    1745             : }
    1746             : 
    1747             : 
    1748           8 : Reference< XResultSet> FmXFormShell::getInternalForm(const Reference< XResultSet>& _xForm) const
    1749             : {
    1750           8 :     if ( impl_checkDisposed() )
    1751           0 :         return NULL;
    1752             : 
    1753           8 :     Reference< runtime::XFormController> xExternalCtrlr(m_xExternalViewController, UNO_QUERY);
    1754           8 :     if (xExternalCtrlr.is() && (_xForm == xExternalCtrlr->getModel()))
    1755             :     {
    1756             :         DBG_ASSERT(m_xExternalDisplayedForm.is(), "FmXFormShell::getInternalForm : invalid external form !");
    1757           0 :         return m_xExternalDisplayedForm;
    1758             :     }
    1759           8 :     return _xForm;
    1760             : }
    1761             : 
    1762             : 
    1763           2 : Reference< XForm> FmXFormShell::getInternalForm(const Reference< XForm>& _xForm) const
    1764             : {
    1765           2 :     if ( impl_checkDisposed() )
    1766           0 :         return NULL;
    1767             : 
    1768           2 :     Reference< runtime::XFormController > xExternalCtrlr(m_xExternalViewController, UNO_QUERY);
    1769           2 :     if (xExternalCtrlr.is() && (_xForm == xExternalCtrlr->getModel()))
    1770             :     {
    1771             :         DBG_ASSERT(m_xExternalDisplayedForm.is(), "FmXFormShell::getInternalForm : invalid external form !");
    1772           0 :         return Reference< XForm>(m_xExternalDisplayedForm, UNO_QUERY);
    1773             :     }
    1774           2 :     return _xForm;
    1775             : }
    1776             : 
    1777             : 
    1778             : namespace
    1779             : {
    1780           0 :     static bool lcl_isNavigationRelevant( sal_Int32 _nWhich )
    1781             :     {
    1782             :         return  ( _nWhich == SID_FM_RECORD_FIRST )
    1783           0 :             ||  ( _nWhich == SID_FM_RECORD_PREV )
    1784           0 :             ||  ( _nWhich == SID_FM_RECORD_NEXT )
    1785           0 :             ||  ( _nWhich == SID_FM_RECORD_LAST )
    1786           0 :             ||  ( _nWhich == SID_FM_RECORD_NEW );
    1787             :     }
    1788             : }
    1789             : 
    1790             : 
    1791           0 : bool FmXFormShell::IsFormSlotEnabled( sal_Int32 _nSlot, FeatureState* _pCompleteState )
    1792             : {
    1793             :     const ::svx::ControllerFeatures& rController =
    1794           0 :             lcl_isNavigationRelevant( _nSlot )
    1795             :         ?   getNavControllerFeatures()
    1796           0 :         :   getActiveControllerFeatures();
    1797             : 
    1798           0 :     if ( !_pCompleteState )
    1799           0 :         return rController->isEnabled( _nSlot );
    1800             : 
    1801           0 :     rController->getState( _nSlot, *_pCompleteState );
    1802           0 :     return _pCompleteState->Enabled;
    1803             : }
    1804             : 
    1805             : 
    1806           0 : void FmXFormShell::ExecuteFormSlot( sal_Int32 _nSlot )
    1807             : {
    1808             :     const ::svx::ControllerFeatures& rController =
    1809           0 :             lcl_isNavigationRelevant( _nSlot )
    1810             :         ?   getNavControllerFeatures()
    1811           0 :         :   getActiveControllerFeatures();
    1812             : 
    1813           0 :     rController->execute( _nSlot );
    1814             : 
    1815           0 :     if ( _nSlot == SID_FM_RECORD_UNDO )
    1816             :     {
    1817             :         // if we're doing an UNDO, *and* if the affected form is the form which we also display
    1818             :         // as external view, then we need to reset the controls of the external form, too
    1819           0 :         if ( getInternalForm( getActiveForm() ) == m_xExternalDisplayedForm )
    1820             :         {
    1821           0 :             Reference< XIndexAccess > xContainer( m_xExternalDisplayedForm, UNO_QUERY );
    1822           0 :             if ( xContainer.is() )
    1823             :             {
    1824           0 :                 Reference< XReset > xReset;
    1825           0 :                 for ( sal_Int32 i = 0; i < xContainer->getCount(); ++i )
    1826             :                 {
    1827           0 :                     if ( ( xContainer->getByIndex( i ) >>= xReset ) && xReset.is() )
    1828             :                     {
    1829             :                         // no resets on sub forms
    1830           0 :                         Reference< XForm > xAsForm( xReset, UNO_QUERY );
    1831           0 :                         if ( !xAsForm.is() )
    1832           0 :                             xReset->reset();
    1833             :                     }
    1834           0 :                 }
    1835           0 :             }
    1836             :         }
    1837             :     }
    1838           0 : }
    1839             : 
    1840             : 
    1841        5458 : void FmXFormShell::impl_switchActiveControllerListening( const bool _bListen )
    1842             : {
    1843        5458 :     Reference< XComponent> xComp( m_xActiveController, UNO_QUERY );
    1844        5458 :     if ( !xComp.is() )
    1845       10912 :         return;
    1846             : 
    1847           4 :     if ( _bListen )
    1848           2 :         xComp->addEventListener( (XFormControllerListener*)this );
    1849             :     else
    1850           2 :         xComp->removeEventListener( (XFormControllerListener*)this );
    1851             : }
    1852             : 
    1853             : 
    1854         506 : void FmXFormShell::setActiveController( const Reference< runtime::XFormController >& xController, bool _bNoSaveOldContent )
    1855             : {
    1856         506 :     if ( impl_checkDisposed() )
    1857           0 :         return;
    1858             : 
    1859         506 :     if (m_bChangingDesignMode)
    1860           0 :         return;
    1861             :     DBG_ASSERT(!m_pShell->IsDesignMode(), "nur im alive mode verwenden");
    1862             : 
    1863             :     // Ist die Routine ein zweites Mal gerufen worden,
    1864             :     // dann sollte der Focus nicht mehr umgesetzt werden
    1865         506 :     if (m_bInActivate)
    1866             :     {
    1867           0 :         m_bSetFocus = xController != m_xActiveController;
    1868           0 :         return;
    1869             :     }
    1870             : 
    1871         506 :     if (xController != m_xActiveController)
    1872             :     {
    1873           4 :         ::osl::ClearableMutexGuard aGuard(m_aAsyncSafety);
    1874             :         // switch all nav dispatchers belonging to the form of the current nav controller to 'non active'
    1875           8 :         Reference< XResultSet> xNavigationForm;
    1876           4 :         if (m_xNavigationController.is())
    1877           0 :             xNavigationForm = Reference< XResultSet>(m_xNavigationController->getModel(), UNO_QUERY);
    1878           4 :         aGuard.clear();
    1879             : 
    1880           4 :         m_bInActivate = true;
    1881             : 
    1882             :         // check if the 2 controllers serve different forms
    1883           8 :         Reference< XResultSet> xOldForm;
    1884           4 :         if (m_xActiveController.is())
    1885           2 :             xOldForm = Reference< XResultSet>(m_xActiveController->getModel(), UNO_QUERY);
    1886           8 :         Reference< XResultSet> xNewForm;
    1887           4 :         if (xController.is())
    1888           2 :             xNewForm = Reference< XResultSet>(xController->getModel(), UNO_QUERY);
    1889           4 :         xOldForm = getInternalForm(xOldForm);
    1890           4 :         xNewForm = getInternalForm(xNewForm);
    1891             : 
    1892           4 :         bool bDifferentForm = ( xOldForm.get() != xNewForm.get() );
    1893           4 :         bool bNeedSave = bDifferentForm && !_bNoSaveOldContent;
    1894             :             // we save the content of the old form if we move to a new form, and saving old content is allowed
    1895             : 
    1896           4 :         if ( m_xActiveController.is() && bNeedSave )
    1897             :         {
    1898             :             // beim Wechsel des Controllers den Inhalt speichern, ein Commit
    1899             :             // wurde bereits ausgefuehrt
    1900           0 :             if ( m_aActiveControllerFeatures->commitCurrentControl() )
    1901             :             {
    1902           0 :                 m_bSetFocus = true;
    1903           0 :                 if ( m_aActiveControllerFeatures->isModifiedRow() )
    1904             :                 {
    1905           0 :                     bool bIsNew = m_aActiveControllerFeatures->isInsertionRow();
    1906           0 :                     bool bResult = m_aActiveControllerFeatures->commitCurrentRecord();
    1907           0 :                     if ( !bResult && m_bSetFocus )
    1908             :                     {
    1909             :                         // if we couldn't save the current record, set the focus back to the
    1910             :                         // current control
    1911           0 :                         Reference< XWindow > xWindow( m_xActiveController->getCurrentControl(), UNO_QUERY );
    1912           0 :                         if ( xWindow.is() )
    1913           0 :                             xWindow->setFocus();
    1914           0 :                         m_bInActivate = false;
    1915           0 :                         return;
    1916             :                     }
    1917           0 :                     else if ( bResult && bIsNew )
    1918             :                     {
    1919           0 :                         Reference< XResultSet > xCursor( m_aActiveControllerFeatures->getCursor().get() );
    1920           0 :                         if ( xCursor.is() )
    1921             :                         {
    1922           0 :                             DO_SAFE( xCursor->last(); );
    1923           0 :                         }
    1924             :                     }
    1925             :                 }
    1926             :             }
    1927             :         }
    1928             : 
    1929           4 :         stopListening();
    1930             : 
    1931           4 :         impl_switchActiveControllerListening( false );
    1932             : 
    1933           4 :         m_aActiveControllerFeatures.dispose();
    1934           4 :         m_xActiveController = xController;
    1935           4 :         if ( m_xActiveController.is() )
    1936           2 :             m_aActiveControllerFeatures.assign( m_xActiveController );
    1937             : 
    1938           4 :         impl_switchActiveControllerListening( true );
    1939             : 
    1940           4 :         if ( m_xActiveController.is() )
    1941           2 :             m_xActiveForm = getInternalForm( Reference< XForm >( m_xActiveController->getModel(), UNO_QUERY ) );
    1942             :         else
    1943           2 :             m_xActiveForm = NULL;
    1944             : 
    1945           4 :         startListening();
    1946             : 
    1947             :         // activate all dispatchers belonging to form of the new navigation controller
    1948           4 :         xNavigationForm = NULL;
    1949           4 :         if (m_xNavigationController.is())
    1950           0 :             xNavigationForm = Reference< XResultSet>(m_xNavigationController->getModel(), UNO_QUERY);
    1951             : 
    1952           4 :         m_bInActivate = false;
    1953             : 
    1954           4 :         m_pShell->UIFeatureChanged();
    1955           4 :         m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
    1956             : 
    1957           8 :         InvalidateSlot(SID_FM_FILTER_NAVIGATOR_CONTROL, true);
    1958             :     }
    1959             : }
    1960             : 
    1961             : 
    1962           0 : void FmXFormShell::getCurrentSelection( InterfaceBag& /* [out] */ _rSelection ) const
    1963             : {
    1964           0 :     _rSelection = m_aCurrentSelection;
    1965           0 : }
    1966             : 
    1967             : 
    1968         578 : bool FmXFormShell::setCurrentSelectionFromMark( const SdrMarkList& _rMarkList )
    1969             : {
    1970         578 :     m_aLastKnownMarkedControls.clear();
    1971             : 
    1972         578 :     if ( ( _rMarkList.GetMarkCount() > 0 ) && isControlList( _rMarkList ) )
    1973           0 :         collectInterfacesFromMarkList( _rMarkList, m_aLastKnownMarkedControls );
    1974             : 
    1975         578 :     return setCurrentSelection( m_aLastKnownMarkedControls );
    1976             : }
    1977             : 
    1978             : 
    1979           0 : bool FmXFormShell::selectLastMarkedControls()
    1980             : {
    1981           0 :     return setCurrentSelection( m_aLastKnownMarkedControls );
    1982             : }
    1983             : 
    1984             : 
    1985         578 : bool FmXFormShell::setCurrentSelection( const InterfaceBag& _rSelection )
    1986             : {
    1987         578 :     if ( impl_checkDisposed() )
    1988           0 :         return false;
    1989             : 
    1990             :     DBG_ASSERT( m_pShell->IsDesignMode(), "FmXFormShell::setCurrentSelection: only to be used in design mode!" );
    1991             : 
    1992         578 :     if ( _rSelection.empty() && m_aCurrentSelection.empty() )
    1993             :         // nothing to do
    1994         578 :         return false;
    1995             : 
    1996           0 :     if ( _rSelection.size() == m_aCurrentSelection.size() )
    1997             :     {
    1998           0 :         InterfaceBag::const_iterator aNew = _rSelection.begin();
    1999           0 :         InterfaceBag::const_iterator aOld = m_aCurrentSelection.begin();
    2000           0 :         for ( ; aNew != _rSelection.end(); ++aNew, ++aOld )
    2001             :         {
    2002             :             OSL_ENSURE( Reference< XInterface >( *aNew, UNO_QUERY ).get() == aNew->get(), "FmXFormShell::setCurrentSelection: new interface not normalized!" );
    2003             :             OSL_ENSURE( Reference< XInterface >( *aOld, UNO_QUERY ).get() == aOld->get(), "FmXFormShell::setCurrentSelection: old interface not normalized!" );
    2004             : 
    2005           0 :             if ( aNew->get() != aOld->get() )
    2006           0 :                 break;
    2007             :         }
    2008             : 
    2009           0 :         if ( aNew == _rSelection.end() )
    2010             :             // both bags equal
    2011           0 :             return false;
    2012             :     }
    2013             : 
    2014             :     // the following is some strange code to ensure that when you have two grid controls in a document,
    2015             :     // only one of them can have a selected column.
    2016             :     // TODO: this should happen elsewhere, but not here - shouldn't it?
    2017           0 :     if ( !m_aCurrentSelection.empty() )
    2018             :     {
    2019           0 :         Reference< XChild > xCur; if ( m_aCurrentSelection.size() == 1 ) xCur.set(*m_aCurrentSelection.begin(), css::uno::UNO_QUERY);
    2020           0 :         Reference< XChild > xNew; if ( _rSelection.size() == 1 ) xNew.set(*_rSelection.begin(), css::uno::UNO_QUERY);
    2021             : 
    2022             :         // is there nothing to be selected, or the parents differ, and the parent of the current object
    2023             :         // is a selection supplier, then deselect
    2024           0 :         if ( xCur.is() && ( !xNew.is() || ( xCur->getParent() != xNew->getParent() ) ) )
    2025             :         {
    2026           0 :             Reference< XSelectionSupplier > xSel( xCur->getParent(), UNO_QUERY );
    2027           0 :             if ( xSel.is() )
    2028           0 :                 xSel->select( Any() );
    2029           0 :         }
    2030             :     }
    2031             : 
    2032           0 :     m_aCurrentSelection = _rSelection;
    2033             : 
    2034             :     // determine the form which all the selected objects belong to, if any
    2035           0 :     Reference< XForm > xNewCurrentForm;
    2036           0 :     for ( InterfaceBag::const_iterator loop = m_aCurrentSelection.begin();
    2037           0 :           loop != m_aCurrentSelection.end();
    2038             :           ++loop
    2039             :         )
    2040             :     {
    2041           0 :         Reference< XForm > xThisRoundsForm( GetForm( *loop ) );
    2042             :         OSL_ENSURE( xThisRoundsForm.is(), "FmXFormShell::setCurrentSelection: *everything* should belong to a form!" );
    2043             : 
    2044           0 :         if ( !xNewCurrentForm.is() )
    2045             :         {   // the first form we encounterd
    2046           0 :             xNewCurrentForm = xThisRoundsForm;
    2047             :         }
    2048           0 :         else if ( xNewCurrentForm != xThisRoundsForm )
    2049             :         {   // different forms -> no "current form" at all
    2050           0 :             xNewCurrentForm.clear();
    2051           0 :             break;
    2052             :         }
    2053           0 :     }
    2054             : 
    2055           0 :     if ( !m_aCurrentSelection.empty() )
    2056           0 :         impl_updateCurrentForm( xNewCurrentForm );
    2057             : 
    2058             :     // ensure some slots are updated
    2059           0 :     for ( size_t i = 0; i < sizeof( SelObjectSlotMap ) / sizeof( SelObjectSlotMap[0] ); ++i )
    2060           0 :         InvalidateSlot( SelObjectSlotMap[i], false);
    2061             : 
    2062           0 :     return true;
    2063             : }
    2064             : 
    2065             : 
    2066           0 : bool FmXFormShell::isSolelySelected( const Reference< XInterface >& _rxObject )
    2067             : {
    2068           0 :     return ( m_aCurrentSelection.size() == 1 ) && ( *m_aCurrentSelection.begin() == _rxObject );
    2069             : }
    2070             : 
    2071             : 
    2072           0 : void FmXFormShell::forgetCurrentForm()
    2073             : {
    2074           0 :     if ( !m_xCurrentForm.is() )
    2075           0 :         return;
    2076             : 
    2077             :     // reset ...
    2078           0 :     impl_updateCurrentForm( NULL );
    2079             : 
    2080             :     // ... and try finding a new current form
    2081             :     // #i88186# / 2008-04-12 / frank.schoenheit@sun.com
    2082           0 :     impl_defaultCurrentForm_nothrow();
    2083             : }
    2084             : 
    2085             : 
    2086          58 : void FmXFormShell::impl_updateCurrentForm( const Reference< XForm >& _rxNewCurForm )
    2087             : {
    2088          58 :     if ( impl_checkDisposed() )
    2089          58 :         return;
    2090             : 
    2091          58 :     m_xCurrentForm = _rxNewCurForm;
    2092             : 
    2093             :     // propagate to the FormPage(Impl)
    2094          58 :     FmFormPage* pPage = m_pShell->GetCurPage();
    2095          58 :     if ( pPage )
    2096          58 :         pPage->GetImpl().setCurForm( m_xCurrentForm );
    2097             : 
    2098             :     // ensure the UI which depends on the current form is up-to-date
    2099         754 :     for ( size_t i = 0; i < sizeof( DlgSlotMap ) / sizeof( DlgSlotMap[0] ); ++i )
    2100         696 :         InvalidateSlot( DlgSlotMap[i], false );
    2101             : }
    2102             : 
    2103             : 
    2104           4 : void FmXFormShell::startListening()
    2105             : {
    2106           4 :     if ( impl_checkDisposed() )
    2107           0 :         return;
    2108             : 
    2109           4 :     Reference< XRowSet> xDatabaseForm(m_xActiveForm, UNO_QUERY);
    2110           4 :     if (xDatabaseForm.is() && getRowSetConnection(xDatabaseForm).is())
    2111             :     {
    2112           0 :         Reference< XPropertySet> xActiveFormSet(m_xActiveForm, UNO_QUERY);
    2113           0 :         if (xActiveFormSet.is())
    2114             :         {
    2115             :             // wenn es eine Datenquelle gibt, dann den Listener aufbauen
    2116             :             // TODO: this is strange - shouldn't this depend on a isLoaded instead of
    2117             :             // a "has command value"? Finally, the command value only means that it was
    2118             :             // intended to be loaded, not that it actually *is* loaded
    2119           0 :             OUString aSource = ::comphelper::getString(xActiveFormSet->getPropertyValue(FM_PROP_COMMAND));
    2120           0 :             if (!aSource.isEmpty())
    2121             :             {
    2122           0 :                 m_bDatabaseBar = true;
    2123             : 
    2124           0 :                 xActiveFormSet->getPropertyValue(FM_PROP_NAVIGATION) >>= m_eNavigate;
    2125             : 
    2126           0 :                 switch (m_eNavigate)
    2127             :                 {
    2128             :                     case NavigationBarMode_PARENT:
    2129             :                     {
    2130             :                         // suchen des Controllers, ueber den eine Navigation moeglich ist
    2131           0 :                         Reference< XChild> xChild(m_xActiveController, UNO_QUERY);
    2132           0 :                         Reference< runtime::XFormController > xParent;
    2133           0 :                         while (xChild.is())
    2134             :                         {
    2135           0 :                             xChild = Reference< XChild>(xChild->getParent(), UNO_QUERY);
    2136           0 :                             xParent  = Reference< runtime::XFormController >(xChild, UNO_QUERY);
    2137           0 :                             Reference< XPropertySet> xParentSet;
    2138           0 :                             if (xParent.is())
    2139           0 :                                 xParentSet = Reference< XPropertySet>(xParent->getModel(), UNO_QUERY);
    2140           0 :                             if (xParentSet.is())
    2141             :                             {
    2142           0 :                                 xParentSet->getPropertyValue(FM_PROP_NAVIGATION) >>= m_eNavigate;
    2143           0 :                                 if (m_eNavigate == NavigationBarMode_CURRENT)
    2144           0 :                                     break;
    2145             :                             }
    2146           0 :                         }
    2147           0 :                         m_xNavigationController = xParent;
    2148             :                     }
    2149           0 :                     break;
    2150             : 
    2151             :                     case NavigationBarMode_CURRENT:
    2152           0 :                         m_xNavigationController = m_xActiveController;
    2153           0 :                         break;
    2154             : 
    2155             :                     default:
    2156           0 :                         m_xNavigationController = NULL;
    2157           0 :                         m_bDatabaseBar = false;
    2158             :                 }
    2159             : 
    2160           0 :                 m_aNavControllerFeatures.dispose();
    2161           0 :                 if ( m_xNavigationController.is() && ( m_xNavigationController != m_xActiveController ) )
    2162           0 :                     m_aNavControllerFeatures.assign( m_xNavigationController );
    2163             : 
    2164             :                 // an dem Controller, der die Navigation regelt, wg. RecordCount lauschen
    2165           0 :                 Reference< XPropertySet> xNavigationSet;
    2166           0 :                 if (m_xNavigationController.is())
    2167             :                 {
    2168           0 :                     xNavigationSet = Reference< XPropertySet>(m_xNavigationController->getModel(), UNO_QUERY);
    2169           0 :                     if (xNavigationSet.is())
    2170           0 :                         xNavigationSet->addPropertyChangeListener(FM_PROP_ROWCOUNT,this);
    2171             :                 }
    2172           0 :                 return;
    2173           0 :             }
    2174           0 :         }
    2175             :     }
    2176             : 
    2177           4 :     m_eNavigate  = NavigationBarMode_NONE;
    2178           4 :     m_bDatabaseBar = false;
    2179           4 :     m_xNavigationController = NULL;
    2180             : }
    2181             : 
    2182             : 
    2183           4 : void FmXFormShell::stopListening()
    2184             : {
    2185           4 :     if ( impl_checkDisposed() )
    2186           4 :         return;
    2187             : 
    2188           4 :     Reference< XRowSet> xDatabaseForm(m_xActiveForm, UNO_QUERY);
    2189           4 :     if ( xDatabaseForm.is() )
    2190             :     {
    2191           2 :         if (m_xNavigationController.is())
    2192             :         {
    2193           0 :             Reference< XPropertySet> xSet(m_xNavigationController->getModel(), UNO_QUERY);
    2194           0 :             if (xSet.is())
    2195           0 :                 xSet->removePropertyChangeListener(FM_PROP_ROWCOUNT, this);
    2196             : 
    2197             :         }
    2198             :     }
    2199             : 
    2200           4 :     m_bDatabaseBar = false;
    2201           4 :     m_eNavigate  = NavigationBarMode_NONE;
    2202           4 :     m_xNavigationController = NULL;
    2203             : }
    2204             : 
    2205             : 
    2206           0 : void FmXFormShell::ShowSelectionProperties( bool bShow )
    2207             : {
    2208           0 :     if ( impl_checkDisposed() )
    2209           0 :         return;
    2210             : 
    2211             :     // if the window is already visible, only update the state
    2212           0 :     bool bHasChild = m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_SHOW_PROPERTIES );
    2213           0 :     if ( bHasChild && bShow )
    2214           0 :         UpdateSlot( SID_FM_PROPERTY_CONTROL );
    2215             : 
    2216             :     // else toggle state
    2217             :     else
    2218           0 :         m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow(SID_FM_SHOW_PROPERTIES);
    2219             : 
    2220           0 :     InvalidateSlot( SID_FM_PROPERTIES, false );
    2221           0 :     InvalidateSlot( SID_FM_CTL_PROPERTIES, false );
    2222             : }
    2223             : 
    2224             : 
    2225           0 : IMPL_LINK(FmXFormShell, OnFoundData, FmFoundRecordInformation*, pfriWhere)
    2226             : {
    2227           0 :     if ( impl_checkDisposed() )
    2228           0 :         return 0;
    2229             : 
    2230             :     DBG_ASSERT((pfriWhere->nContext >= 0) && (pfriWhere->nContext < (sal_Int16)m_aSearchForms.size()),
    2231             :         "FmXFormShell::OnFoundData : ungueltiger Kontext !");
    2232           0 :     Reference< XForm> xForm( m_aSearchForms.at(pfriWhere->nContext));
    2233             :     DBG_ASSERT(xForm.is(), "FmXFormShell::OnFoundData : ungueltige Form !");
    2234             : 
    2235           0 :     Reference< XRowLocate> xCursor(xForm, UNO_QUERY);
    2236           0 :     if (!xCursor.is())
    2237           0 :         return 0;       // was soll ich da machen ?
    2238             : 
    2239             :     // zum Datensatz
    2240             :     try
    2241             :     {
    2242           0 :         xCursor->moveToBookmark(pfriWhere->aPosition);
    2243             :     }
    2244           0 :     catch(const SQLException&)
    2245             :     {
    2246             :         OSL_FAIL("Can position on bookmark!");
    2247             :     }
    2248             : 
    2249           0 :     LoopGrids(GA_FORCE_SYNC);
    2250             : 
    2251             :     // und zum Feld (dazu habe ich vor dem Start des Suchens die XVclComponent-Interfaces eingesammelt)
    2252             :     SAL_WARN_IF(static_cast<size_t>(pfriWhere->nFieldPos) >=
    2253             :             m_arrSearchedControls.size(),
    2254             :         "svx.form", "FmXFormShell::OnFoundData : invalid index!");
    2255           0 :     SdrObject* pObject = m_arrSearchedControls.at(pfriWhere->nFieldPos);
    2256             : 
    2257           0 :     m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView());
    2258           0 :     m_pShell->GetFormView()->MarkObj(pObject, m_pShell->GetFormView()->GetSdrPageView());
    2259             : 
    2260           0 :     FmFormObj* pFormObject = FmFormObj::GetFormObject( pObject );
    2261           0 :     Reference< XControlModel > xControlModel( pFormObject ? pFormObject->GetUnoControlModel() : Reference< XControlModel >() );
    2262             :     DBG_ASSERT( xControlModel.is(), "FmXFormShell::OnFoundData: invalid control!" );
    2263           0 :     if ( !xControlModel.is() )
    2264           0 :         return 0;
    2265             : 
    2266             :     // disable the permanent cursor for the last grid we found a record
    2267           0 :     if (m_xLastGridFound.is() && (m_xLastGridFound != xControlModel))
    2268             :     {
    2269           0 :         Reference< XPropertySet> xOldSet(m_xLastGridFound, UNO_QUERY);
    2270           0 :         xOldSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, makeAny( false ) );
    2271           0 :         Reference< XPropertyState> xOldSetState(xOldSet, UNO_QUERY);
    2272           0 :         if (xOldSetState.is())
    2273           0 :             xOldSetState->setPropertyToDefault(FM_PROP_CURSORCOLOR);
    2274             :         else
    2275           0 :             xOldSet->setPropertyValue(FM_PROP_CURSORCOLOR, Any());
    2276             :     }
    2277             : 
    2278             :     // wenn das Feld sich in einem GridControl befindet, muss ich dort noch in die entsprechende Spalte gehen
    2279           0 :     sal_Int32 nGridColumn = m_arrRelativeGridColumn[pfriWhere->nFieldPos];
    2280           0 :     if (nGridColumn != -1)
    2281             :     {   // dummer weise muss ich mir das Control erst wieder besorgen
    2282           0 :         Reference<XControl> xControl( pFormObject ? impl_getControl( xControlModel, *pFormObject ) : Reference< XControl>() );
    2283           0 :         Reference< XGrid> xGrid(xControl, UNO_QUERY);
    2284             :         DBG_ASSERT(xGrid.is(), "FmXFormShell::OnFoundData : ungueltiges Control !");
    2285             :         // wenn eine der Asserts anschlaegt, habe ich beim Aufbauen von m_arrSearchedControls wohl was falsch gemacht
    2286             : 
    2287             :         // enable a permanent cursor for the grid so we can see the found text
    2288           0 :         Reference< XPropertySet> xModelSet(xControlModel, UNO_QUERY);
    2289             :         DBG_ASSERT(xModelSet.is(), "FmXFormShell::OnFoundData : invalid control model (no property set) !");
    2290           0 :         xModelSet->setPropertyValue( FM_PROP_ALWAYSSHOWCURSOR, makeAny( true ) );
    2291           0 :         xModelSet->setPropertyValue( FM_PROP_CURSORCOLOR, makeAny( sal_Int32( COL_LIGHTRED ) ) );
    2292           0 :         m_xLastGridFound = xControlModel;
    2293             : 
    2294           0 :         if ( xGrid.is() )
    2295           0 :             xGrid->setCurrentColumnPosition((sal_Int16)nGridColumn);
    2296             :     }
    2297             : 
    2298             :     // als der Cursor neu positioniert wurde, habe ich (in positioned) meine Formularleisten-Slots invalidiert, aber das greift
    2299             :     // hier dummerweise nicht, da i.A. ja der (modale) Suchdialog oben ist ... also Gewalt ...
    2300           0 :     sal_uInt16 nPos = 0;
    2301           0 :     while (DatabaseSlotMap[nPos])
    2302           0 :         m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update(DatabaseSlotMap[nPos++]);
    2303             :         // leider geht das Update im Gegensatz zum Invalidate nur mit einzelnen Slots)
    2304             : 
    2305           0 :     return 0;
    2306             : }
    2307             : 
    2308             : 
    2309           0 : IMPL_LINK(FmXFormShell, OnCanceledNotFound, FmFoundRecordInformation*, pfriWhere)
    2310             : {
    2311           0 :     if ( impl_checkDisposed() )
    2312           0 :         return 0;
    2313             : 
    2314             :     DBG_ASSERT((pfriWhere->nContext >= 0) && (pfriWhere->nContext < (sal_Int16)m_aSearchForms.size()),
    2315             :         "FmXFormShell::OnCanceledNotFound : ungueltiger Kontext !");
    2316           0 :     Reference< XForm> xForm( m_aSearchForms.at(pfriWhere->nContext));
    2317             :     DBG_ASSERT(xForm.is(), "FmXFormShell::OnCanceledNotFound : ungueltige Form !");
    2318             : 
    2319           0 :     Reference< XRowLocate> xCursor(xForm, UNO_QUERY);
    2320           0 :     if (!xCursor.is())
    2321           0 :         return 0;       // was soll ich da machen ?
    2322             : 
    2323             :     // zum Datensatz
    2324             :     try
    2325             :     {
    2326           0 :         xCursor->moveToBookmark(pfriWhere->aPosition);
    2327             :     }
    2328           0 :     catch(const SQLException&)
    2329             :     {
    2330             :         OSL_FAIL("Can position on bookmark!");
    2331             :     }
    2332             : 
    2333             : 
    2334           0 :     m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetSdrPageView());
    2335           0 :     return 0L;
    2336             : }
    2337             : 
    2338             : 
    2339           0 : IMPL_LINK(FmXFormShell, OnSearchContextRequest, FmSearchContext*, pfmscContextInfo)
    2340             : {
    2341           0 :     if ( impl_checkDisposed() )
    2342           0 :         return 0;
    2343             : 
    2344             :     DBG_ASSERT(pfmscContextInfo->nContext < (sal_Int16)m_aSearchForms.size(), "FmXFormShell::OnSearchContextRequest : invalid parameter !");
    2345           0 :     Reference< XForm> xForm( m_aSearchForms.at(pfmscContextInfo->nContext));
    2346             :     DBG_ASSERT(xForm.is(), "FmXFormShell::OnSearchContextRequest : unexpected : invalid context !");
    2347             : 
    2348           0 :     Reference< XResultSet> xIter(xForm, UNO_QUERY);
    2349             :     DBG_ASSERT(xIter.is(), "FmXFormShell::OnSearchContextRequest : unexpected : context has no iterator !");
    2350             : 
    2351             : 
    2352             :     // assemble the list of fields to involve (that is, the ControlSources of all fields that have such a property)
    2353           0 :     OUString strFieldList, sFieldDisplayNames;
    2354           0 :     m_arrSearchedControls.clear();
    2355           0 :     m_arrRelativeGridColumn.clear();
    2356             : 
    2357             :     // small problem: To mark found fields, I need SdrObjects. To determine which controls
    2358             :     // to include in the search, I need Controls (that is, XControl interfaces). So I have
    2359             :     // to iterate over one of them and get the other in some way. Unfortunately, there is
    2360             :     // no direct connexion between the two worlds (except from a GetUnoControl to a
    2361             :     // SdrUnoObject, but this requires an OutputDevice I can not do anything with.
    2362             :     // However I can get to the Model from the Control and also from the SdrObject, and in
    2363             :     // this way the assignment SdrObject<->Control is possible with a double loop.
    2364             :     // The alternative to this (ugly but certainly not entirely fixable) solution would be
    2365             :     // to renounce the caching of the SdrObjects, which would lead to significant extra
    2366             :     // work in OnFoundData (since there I'd have to get the SdrObject first thing every
    2367             :     // time). But since OnFoundData is usually called more often than ExecuteSeearch, I'll
    2368             :     // do that here.
    2369             : 
    2370           0 :     Reference< XNameAccess> xValidFormFields;
    2371           0 :     Reference< XColumnsSupplier> xSupplyCols(xIter, UNO_QUERY);
    2372             :     DBG_ASSERT(xSupplyCols.is(), "FmXFormShell::OnSearchContextRequest : invalid cursor : no columns supplier !");
    2373           0 :     if (xSupplyCols.is())
    2374           0 :         xValidFormFields = xSupplyCols->getColumns();
    2375             :     DBG_ASSERT(xValidFormFields.is(), "FmXFormShell::OnSearchContextRequest : form has no fields !");
    2376             : 
    2377             :     // current Page/Controller
    2378           0 :     FmFormPage* pCurrentPage = m_pShell->GetCurPage();
    2379             :     assert(pCurrentPage && "FmXFormShell::OnSearchContextRequest : no page !");
    2380             :     // Search all SdrControls of this page...
    2381           0 :     OUString sControlSource, aName;
    2382             : 
    2383           0 :     SdrObjListIter aPageIter( *pCurrentPage );
    2384           0 :     while ( aPageIter.IsMore() )
    2385             :     {
    2386           0 :         SdrObject* pCurrent = aPageIter.Next();
    2387           0 :         FmFormObj* pFormObject = FmFormObj::GetFormObject( pCurrent );
    2388             :         // note that in case pCurrent is a virtual object, pFormObject points to the referenced object
    2389             : 
    2390           0 :         if ( !pFormObject )
    2391           0 :             continue;
    2392             : 
    2393             :         // the current object's model, in different tastes
    2394           0 :         Reference< XControlModel> xControlModel( pFormObject->GetUnoControlModel() );
    2395           0 :         Reference< XFormComponent > xCurrentFormComponent( xControlModel, UNO_QUERY );
    2396             :         DBG_ASSERT( xCurrentFormComponent.is(), "FmXFormShell::OnSearchContextRequest: invalid objects!" );
    2397           0 :         if ( !xCurrentFormComponent.is() )
    2398           0 :             continue;
    2399             : 
    2400             :         // does the component belong to the form which we're interested in?
    2401           0 :         if ( xCurrentFormComponent->getParent() != xForm )
    2402           0 :             continue;
    2403             : 
    2404             :         // ... ask for the ControlSource property
    2405           0 :         SearchableControlIterator iter( xCurrentFormComponent );
    2406           0 :         Reference< XControl> xControl;
    2407             :         // the control that has model xControlModel
    2408             :         // (the following while can be passed through several times, without the Control
    2409             :         // being modified, so I don't have to search every time from scratch)
    2410             : 
    2411           0 :         Reference< XInterface > xSearchable( iter.Next() );
    2412           0 :         while ( xSearchable.is() )
    2413             :         {
    2414           0 :             sControlSource = iter.getCurrentValue();
    2415           0 :             if ( sControlSource.isEmpty() )
    2416             :             {
    2417             :                 // the current element has no ControlSource, so it is a GridControl (that
    2418             :                 // is the only thing that still permits the SearchableControlIteratore)
    2419           0 :                 xControl = impl_getControl( xControlModel, *pFormObject );
    2420             :                 DBG_ASSERT(xControl.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
    2421             : 
    2422           0 :                 Reference< XGridPeer> xGridPeer;
    2423           0 :                 if ( xControl.is() )
    2424           0 :                     xGridPeer.set( xControl->getPeer(), UNO_QUERY );
    2425             :                 do
    2426             :                 {
    2427           0 :                     if (!xGridPeer.is())
    2428           0 :                         break;
    2429             : 
    2430           0 :                     Reference< XIndexAccess> xPeerContainer(xGridPeer, UNO_QUERY);
    2431           0 :                     if (!xPeerContainer.is())
    2432           0 :                         break;
    2433             : 
    2434           0 :                     Reference< XIndexAccess> xModelColumns(xGridPeer->getColumns(), UNO_QUERY);
    2435             :                     DBG_ASSERT(xModelColumns.is(), "FmXFormShell::OnSearchContextRequest : there is a grid control without columns !");
    2436             :                     // the case 'no columns' should be indicated with an empty container, I think ...
    2437             :                     DBG_ASSERT(xModelColumns->getCount() >= xPeerContainer->getCount(), "FmXFormShell::OnSearchContextRequest : impossible : have more view than model columns !");
    2438             : 
    2439           0 :                     Reference< XInterface> xCurrentColumn;
    2440           0 :                     for (sal_Int16 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos)
    2441             :                     {
    2442           0 :                         xPeerContainer->getByIndex(nViewPos) >>= xCurrentColumn;
    2443           0 :                         if (!xCurrentColumn.is())
    2444           0 :                             continue;
    2445             : 
    2446             :                         // can we use this column control for searching ?
    2447           0 :                         if (!IsSearchableControl(xCurrentColumn))
    2448           0 :                             continue;
    2449             : 
    2450           0 :                         sal_Int16 nModelPos = GridView2ModelPos(xModelColumns, nViewPos);
    2451           0 :                         Reference< XPropertySet> xCurrentColModel;
    2452           0 :                         xModelColumns->getByIndex(nModelPos) >>= xCurrentColModel;
    2453           0 :                         aName = ::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_CONTROLSOURCE));
    2454             :                         // the cursor has a field matching the control source ?
    2455           0 :                         if (xValidFormFields->hasByName(aName))
    2456             :                         {
    2457           0 :                             strFieldList = strFieldList + OUString(aName.getStr()) + ";";
    2458             : 
    2459           0 :                             sFieldDisplayNames = sFieldDisplayNames +
    2460           0 :                                     OUString(::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_LABEL)).getStr()) +
    2461           0 :                                     ";";
    2462             : 
    2463           0 :                             pfmscContextInfo->arrFields.push_back(xCurrentColumn);
    2464             : 
    2465             :                             // and the SdrOject to the Field
    2466           0 :                             m_arrSearchedControls.push_back(pCurrent);
    2467             :                             // the number of the column
    2468           0 :                             m_arrRelativeGridColumn.push_back(nViewPos);
    2469             :                         }
    2470           0 :                     }
    2471           0 :                 } while (false);
    2472             :             }
    2473             :             else
    2474             :             {
    2475           0 :                 if (!sControlSource.isEmpty() && xValidFormFields->hasByName(sControlSource))
    2476             :                 {
    2477             :                     // now I need the Control to SdrObject
    2478           0 :                     if (!xControl.is())
    2479             :                     {
    2480           0 :                         xControl = impl_getControl( xControlModel, *pFormObject );
    2481             :                         DBG_ASSERT(xControl.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
    2482             :                     }
    2483             : 
    2484           0 :                     if (IsSearchableControl(xControl))
    2485             :                     {
    2486             :                         // all tests passed -> take along in the list
    2487           0 :                         strFieldList = strFieldList + OUString(sControlSource.getStr()) + ";";
    2488             : 
    2489             :                         // the label which should appear for the control :
    2490           0 :                         sFieldDisplayNames = sFieldDisplayNames +
    2491           0 :                                 OUString(getLabelName(Reference< XPropertySet>(xControlModel, UNO_QUERY)).getStr()) +
    2492           0 :                                 ";";
    2493             : 
    2494             :                         // mark the SdrObject (accelerates the treatment in OnFoundData)
    2495           0 :                         m_arrSearchedControls.push_back(pCurrent);
    2496             : 
    2497             :                         // the number of the column (here a dummy, since it is only interesting for GridControls)
    2498           0 :                         m_arrRelativeGridColumn.push_back(-1);
    2499             : 
    2500             :                         // and for the formatted search...
    2501           0 :                         pfmscContextInfo->arrFields.push_back(Reference<XInterface>( xControl, UNO_QUERY ));
    2502             :                     }
    2503             :                 }
    2504             :             }
    2505             : 
    2506           0 :             xSearchable = iter.Next();
    2507             :         }
    2508           0 :     }
    2509             : 
    2510           0 :     strFieldList = comphelper::string::stripEnd(strFieldList, ';');
    2511           0 :     sFieldDisplayNames = comphelper::string::stripEnd(sFieldDisplayNames, ';');
    2512             : 
    2513           0 :     if (pfmscContextInfo->arrFields.empty())
    2514             :     {
    2515           0 :         pfmscContextInfo->arrFields.clear();
    2516           0 :         pfmscContextInfo->xCursor = NULL;
    2517           0 :         pfmscContextInfo->strUsedFields = "";
    2518           0 :         return 0L;
    2519             :     }
    2520             : 
    2521           0 :     pfmscContextInfo->xCursor = xIter;
    2522           0 :     pfmscContextInfo->strUsedFields = strFieldList;
    2523           0 :     pfmscContextInfo->sFieldDisplayNames = sFieldDisplayNames;
    2524             : 
    2525             :     // 66463 - 31.05.99 - FS
    2526             :     // when the cursor is a non-STANDARD RecordMode, set it back
    2527           0 :     Reference< XPropertySet> xCursorSet(pfmscContextInfo->xCursor, UNO_QUERY);
    2528           0 :     Reference< XResultSetUpdate> xUpdateCursor(pfmscContextInfo->xCursor, UNO_QUERY);
    2529           0 :     if (xUpdateCursor.is() && xCursorSet.is())
    2530             :     {
    2531           0 :         if (::comphelper::getBOOL(xCursorSet->getPropertyValue(FM_PROP_ISNEW)))
    2532           0 :             xUpdateCursor->moveToCurrentRow();
    2533           0 :         else if (::comphelper::getBOOL(xCursorSet->getPropertyValue(FM_PROP_ISMODIFIED)))
    2534           0 :             xUpdateCursor->cancelRowUpdates();
    2535             :     }
    2536             : 
    2537           0 :     return pfmscContextInfo->arrFields.size();
    2538             : }
    2539             : 
    2540             :   // XContainerListener
    2541             : 
    2542         730 : void FmXFormShell::elementInserted(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException, std::exception)
    2543             : {
    2544         730 :     if ( impl_checkDisposed() )
    2545         730 :         return;
    2546             : 
    2547             :     // new object to listen to
    2548         730 :     Reference< XInterface> xTemp;
    2549         730 :     evt.Element >>= xTemp;
    2550         730 :     AddElement(xTemp);
    2551         730 :     m_pShell->DetermineForms(true);
    2552             : }
    2553             : 
    2554             : 
    2555          12 : void FmXFormShell::elementReplaced(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException, std::exception)
    2556             : {
    2557          12 :     if ( impl_checkDisposed() )
    2558          12 :         return;
    2559             : 
    2560          12 :     Reference< XInterface> xTemp;
    2561          12 :     evt.ReplacedElement >>= xTemp;
    2562          12 :     RemoveElement(xTemp);
    2563          12 :     evt.Element >>= xTemp;
    2564          12 :     AddElement(xTemp);
    2565             : }
    2566             : 
    2567             : 
    2568          18 : void FmXFormShell::elementRemoved(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException, std::exception)
    2569             : {
    2570          18 :     if ( impl_checkDisposed() )
    2571          18 :         return;
    2572             : 
    2573          18 :     Reference< XInterface> xTemp;
    2574          18 :     evt.Element >>= xTemp;
    2575          18 :     RemoveElement(xTemp);
    2576          18 :     m_pShell->DetermineForms(true);
    2577             : }
    2578             : 
    2579             : 
    2580       19290 : void FmXFormShell::UpdateForms( bool _bInvalidate )
    2581             : {
    2582       19290 :     if ( impl_checkDisposed() )
    2583       19290 :         return;
    2584             : 
    2585       19290 :     Reference< XIndexAccess > xForms;
    2586             : 
    2587       19290 :     FmFormPage* pPage = m_pShell->GetCurPage();
    2588       19290 :     if ( pPage )
    2589             :     {
    2590       19256 :         if ( m_pShell->m_bDesignMode )
    2591       17950 :             xForms.set(pPage->GetForms( false ), css::uno::UNO_QUERY);
    2592             :     }
    2593             : 
    2594       19290 :     if ( m_xForms != xForms )
    2595             :     {
    2596         348 :         RemoveElement( m_xForms );
    2597         348 :         m_xForms = xForms;
    2598         348 :         AddElement( m_xForms );
    2599             :     }
    2600             : 
    2601       19290 :     m_pShell->DetermineForms( _bInvalidate );
    2602             : }
    2603             : 
    2604             : 
    2605        1090 : void FmXFormShell::AddElement(const Reference< XInterface>& _xElement)
    2606             : {
    2607        1090 :     if ( impl_checkDisposed() )
    2608        1090 :         return;
    2609        1090 :     impl_AddElement_nothrow(_xElement);
    2610             : }
    2611             : 
    2612        1106 : void FmXFormShell::impl_AddElement_nothrow(const Reference< XInterface>& Element)
    2613             : {
    2614             :     // am Container horchen
    2615        1106 :     const Reference< XIndexContainer> xContainer(Element, UNO_QUERY);
    2616        1106 :     if (xContainer.is())
    2617             :     {
    2618         570 :         const sal_uInt32 nCount = xContainer->getCount();
    2619         570 :         Reference< XInterface> xElement;
    2620         586 :         for (sal_uInt32 i = 0; i < nCount; ++i)
    2621             :         {
    2622          16 :             xElement.set(xContainer->getByIndex(i),UNO_QUERY);
    2623          16 :             impl_AddElement_nothrow(xElement);
    2624             :         }
    2625             : 
    2626        1140 :         const Reference< XContainer> xCont(Element, UNO_QUERY);
    2627         570 :         if (xCont.is())
    2628        1140 :             xCont->addContainerListener(this);
    2629             :     }
    2630             : 
    2631        2212 :     const Reference< ::com::sun::star::view::XSelectionSupplier> xSelSupplier(Element, UNO_QUERY);
    2632        1106 :     if (xSelSupplier.is())
    2633        1126 :         xSelSupplier->addSelectionChangeListener(this);
    2634        1106 : }
    2635             : 
    2636             : 
    2637        5828 : void FmXFormShell::RemoveElement(const Reference< XInterface>& Element)
    2638             : {
    2639        5828 :     if ( impl_checkDisposed() )
    2640        5828 :         return;
    2641        5828 :     impl_RemoveElement_nothrow(Element);
    2642             : }
    2643             : 
    2644        6516 : void FmXFormShell::impl_RemoveElement_nothrow(const Reference< XInterface>& Element)
    2645             : {
    2646        6516 :     const Reference< ::com::sun::star::view::XSelectionSupplier> xSelSupplier(Element, UNO_QUERY);
    2647        6516 :     if (xSelSupplier.is())
    2648          18 :         xSelSupplier->removeSelectionChangeListener(this);
    2649             : 
    2650             :     // remove connection to children
    2651       13032 :     const Reference< XIndexContainer> xContainer(Element, UNO_QUERY);
    2652        6516 :     if (xContainer.is())
    2653             :     {
    2654         568 :         const Reference< XContainer> xCont(Element, UNO_QUERY);
    2655         568 :         if (xCont.is())
    2656         568 :             xCont->removeContainerListener(this);
    2657             : 
    2658         568 :         const sal_uInt32 nCount = xContainer->getCount();
    2659        1136 :         Reference< XInterface> xElement;
    2660        1256 :         for (sal_uInt32 i = 0; i < nCount; i++)
    2661             :         {
    2662         688 :             xElement.set(xContainer->getByIndex(i),UNO_QUERY);
    2663         688 :             impl_RemoveElement_nothrow(xElement);
    2664         568 :         }
    2665             :     }
    2666             : 
    2667        6516 :     InterfaceBag::iterator wasSelectedPos = m_aCurrentSelection.find( Element );
    2668        6516 :     if ( wasSelectedPos != m_aCurrentSelection.end() )
    2669        6516 :         m_aCurrentSelection.erase( wasSelectedPos );
    2670        6516 : }
    2671             : 
    2672             : 
    2673           0 : void FmXFormShell::selectionChanged(const EventObject& rEvent) throw(::com::sun::star::uno::RuntimeException, std::exception)
    2674             : {
    2675           0 :     if ( impl_checkDisposed() )
    2676           0 :         return;
    2677             : 
    2678           0 :     Reference< XSelectionSupplier > xSupplier( rEvent.Source, UNO_QUERY );
    2679           0 :     Reference< XInterface > xSelObj( xSupplier->getSelection(), UNO_QUERY );
    2680             :     // a selection was removed, this can only be done by the shell
    2681           0 :     if ( !xSelObj.is() )
    2682           0 :         return;
    2683             : 
    2684           0 :     EnableTrackProperties(false);
    2685             : 
    2686           0 :     bool bMarkChanged = m_pShell->GetFormView()->checkUnMarkAll(rEvent.Source);
    2687           0 :     Reference< XForm > xNewForm( GetForm( rEvent.Source ) );
    2688             : 
    2689           0 :     InterfaceBag aNewSelection;
    2690           0 :     aNewSelection.insert( Reference<XInterface>( xSelObj, UNO_QUERY ) );
    2691             : 
    2692           0 :     if ( setCurrentSelection( aNewSelection ) && IsPropBrwOpen() )
    2693           0 :         ShowSelectionProperties( true );
    2694             : 
    2695           0 :     EnableTrackProperties(true);
    2696             : 
    2697           0 :     if ( bMarkChanged )
    2698           0 :         m_pShell->NotifyMarkListChanged( m_pShell->GetFormView() );
    2699             : }
    2700             : 
    2701             : 
    2702           0 : IMPL_LINK(FmXFormShell, OnTimeOut, void*, /*EMPTYTAG*/)
    2703             : {
    2704           0 :     if ( impl_checkDisposed() )
    2705           0 :         return 0;
    2706             : 
    2707           0 :     if (m_pShell->IsDesignMode() && m_pShell->GetFormView())
    2708           0 :         SetSelection(m_pShell->GetFormView()->GetMarkedObjectList());
    2709             : 
    2710           0 :     return 0;
    2711             : }
    2712             : 
    2713             : 
    2714          42 : void FmXFormShell::SetSelectionDelayed()
    2715             : {
    2716          42 :     if ( impl_checkDisposed() )
    2717          42 :         return;
    2718             : 
    2719          42 :     if (m_pShell->IsDesignMode() && IsTrackPropertiesEnabled() && !m_aMarkTimer.IsActive())
    2720          12 :         m_aMarkTimer.Start();
    2721             : }
    2722             : 
    2723             : 
    2724         578 : void FmXFormShell::SetSelection(const SdrMarkList& rMarkList)
    2725             : {
    2726         578 :     if ( impl_checkDisposed() )
    2727         578 :         return;
    2728             : 
    2729         578 :     DetermineSelection(rMarkList);
    2730         578 :     m_pShell->NotifyMarkListChanged(m_pShell->GetFormView());
    2731             : }
    2732             : 
    2733             : 
    2734         578 : void FmXFormShell::DetermineSelection(const SdrMarkList& rMarkList)
    2735             : {
    2736         578 :     if ( setCurrentSelectionFromMark( rMarkList ) && IsPropBrwOpen() )
    2737           0 :         ShowSelectionProperties( true );
    2738         578 : }
    2739             : 
    2740             : 
    2741           0 : bool FmXFormShell::IsPropBrwOpen() const
    2742             : {
    2743           0 :     if ( impl_checkDisposed() )
    2744           0 :         return false;
    2745             : 
    2746           0 :     return( ( m_pShell->GetViewShell() && m_pShell->GetViewShell()->GetViewFrame() ) ?
    2747           0 :             m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES) : sal_False );
    2748             : }
    2749             : 
    2750             : 
    2751             : class FmXFormShell::SuspendPropertyTracking
    2752             : {
    2753             : private:
    2754             :     FmXFormShell&   m_rShell;
    2755             :     bool            m_bEnabled;
    2756             : 
    2757             : public:
    2758        5498 :     SuspendPropertyTracking( FmXFormShell& _rShell )
    2759             :         :m_rShell( _rShell )
    2760        5498 :         ,m_bEnabled( false )
    2761             :     {
    2762        5498 :         if ( m_rShell.IsTrackPropertiesEnabled() )
    2763             :         {
    2764        5498 :             m_rShell.EnableTrackProperties( false );
    2765        5498 :             m_bEnabled = true;
    2766             :         }
    2767        5498 :     }
    2768             : 
    2769        5498 :     ~SuspendPropertyTracking( )
    2770             :     {
    2771        5498 :         if ( m_bEnabled )   // note that ( false != m_bEnabled ) implies ( NULL != m_pShell )
    2772        5498 :             m_rShell.EnableTrackProperties( true );
    2773        5498 :     }
    2774             : };
    2775             : 
    2776             : 
    2777        5498 : void FmXFormShell::SetDesignMode(bool bDesign)
    2778             : {
    2779        5498 :     if ( impl_checkDisposed() )
    2780        5498 :         return;
    2781             : 
    2782             :     DBG_ASSERT(m_pShell->GetFormView(), "FmXFormShell::SetDesignMode : invalid call (have no shell or no view) !");
    2783        5498 :     m_bChangingDesignMode = true;
    2784             : 
    2785             :     // 67506 - 15.07.99 - FS
    2786             :     // if we're switching off the design mode we have to force the property browser to be closed
    2787             :     // so it can commit it's changes _before_ we load the forms
    2788        5498 :     if (!bDesign)
    2789             :     {
    2790         320 :         m_bHadPropertyBrowserInDesignMode = m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES);
    2791         320 :         if (m_bHadPropertyBrowserInDesignMode)
    2792           0 :             m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow(SID_FM_SHOW_PROPERTIES);
    2793             :     }
    2794             : 
    2795        5498 :     FmFormView* pFormView = m_pShell->GetFormView();
    2796        5498 :     if (bDesign)
    2797             :     {
    2798             :         // we are currently filtering, so stop filtering
    2799        5178 :         if (m_bFilterMode)
    2800           0 :             stopFiltering(false);
    2801             : 
    2802             :         // unsubscribe from the objects of my MarkList
    2803        5178 :         pFormView->GetImpl()->stopMarkListWatching();
    2804             :     }
    2805             :     else
    2806             :     {
    2807         320 :         m_aMarkTimer.Stop();
    2808             : 
    2809         320 :         SuspendPropertyTracking aSuspend( *this );
    2810         320 :         pFormView->GetImpl()->saveMarkList( true );
    2811             :     }
    2812             : 
    2813        5498 :     if (bDesign && m_xExternalViewController.is())
    2814           0 :         CloseExternalFormViewer();
    2815             : 
    2816        5498 :     pFormView->ChangeDesignMode(bDesign);
    2817             : 
    2818             :     // notify listensers
    2819        5498 :     FmDesignModeChangedHint aChangedHint( bDesign );
    2820        5498 :     m_pShell->Broadcast(aChangedHint);
    2821             : 
    2822        5498 :     m_pShell->m_bDesignMode = bDesign;
    2823        5498 :     UpdateForms( false );
    2824             : 
    2825        5498 :     m_pTextShell->designModeChanged( m_pShell->m_bDesignMode );
    2826             : 
    2827        5498 :     if (bDesign)
    2828             :     {
    2829        5178 :         SdrMarkList aList;
    2830             :         {
    2831             :             // during changing the mark list, don't track the selected objects in the property browser
    2832        5178 :             SuspendPropertyTracking aSuspend( *this );
    2833             :             // restore the marks
    2834        5178 :             pFormView->GetImpl()->restoreMarkList( aList );
    2835             :         }
    2836             : 
    2837             :         // synchronize with the restored mark list
    2838        5178 :         if ( aList.GetMarkCount() )
    2839           0 :             SetSelection( aList );
    2840             :     }
    2841             :     else
    2842             :     {
    2843             :         // subscribe to the model of the view (so that I'm informed when someone deletes
    2844             :         // during the alive mode controls that I had saved in the saveMarklist (60343)
    2845         320 :         pFormView->GetImpl()->startMarkListWatching();
    2846             :     }
    2847             : 
    2848        5498 :     m_pShell->UIFeatureChanged();
    2849             : 
    2850             :     // 67506 - 15.07.99 - FS
    2851        5498 :     if (bDesign && m_bHadPropertyBrowserInDesignMode)
    2852             :     {
    2853             :         // The UIFeatureChanged performes an update (a check of the available features) asynchronously.
    2854             :         // So we can't call ShowSelectionProperties directly as the according feature isn't enabled yet.
    2855             :         // That's why we use an asynchron execution on the dispatcher.
    2856             :         // (And that's why this has to be done AFTER the UIFeatureChanged.)
    2857           0 :         m_pShell->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SfxCallMode::ASYNCHRON );
    2858             :     }
    2859        5498 :     m_bChangingDesignMode = false;
    2860             : }
    2861             : 
    2862             : 
    2863           0 : Reference< XControl> FmXFormShell::impl_getControl( const Reference< XControlModel >& i_rxModel, const FmFormObj& i_rKnownFormObj )
    2864             : {
    2865           0 :     if ( impl_checkDisposed() )
    2866           0 :         return NULL;
    2867             : 
    2868           0 :     Reference< XControl > xControl;
    2869             :     try
    2870             :     {
    2871           0 :         Reference< XControlContainer> xControlContainer( getControlContainerForView(), UNO_SET_THROW );
    2872             : 
    2873           0 :         Sequence< Reference< XControl > > seqControls( xControlContainer->getControls() );
    2874           0 :         const Reference< XControl >* pControls = seqControls.getArray();
    2875             :         // ... that I can then search
    2876           0 :         for (sal_Int32 i=0; i<seqControls.getLength(); ++i)
    2877             :         {
    2878           0 :             xControl.set( pControls[i], UNO_SET_THROW );
    2879           0 :             Reference< XControlModel > xCurrentModel( xControl->getModel() );
    2880           0 :             if ( xCurrentModel == i_rxModel )
    2881           0 :                 break;
    2882           0 :             xControl.clear();
    2883           0 :         }
    2884             : 
    2885           0 :         if ( !xControl.is() )
    2886             :         {
    2887             :             // fallabck (some controls might not have been created, yet, since they were never visible so far)
    2888           0 :             Reference< XControl > xContainerControl( xControlContainer, UNO_QUERY_THROW );
    2889           0 :             const vcl::Window* pContainerWindow = VCLUnoHelper::GetWindow( xContainerControl->getPeer() );
    2890           0 :             ENSURE_OR_THROW( pContainerWindow, "unexpected control container implementation" );
    2891             : 
    2892           0 :             const SdrView* pSdrView = m_pShell ? m_pShell->GetFormView() : NULL;
    2893           0 :             ENSURE_OR_THROW( pSdrView, "no current view" );
    2894             : 
    2895           0 :             xControl.set( i_rKnownFormObj.GetUnoControl( *pSdrView, *pContainerWindow ), UNO_QUERY_THROW );
    2896           0 :         }
    2897             :     }
    2898           0 :     catch( const Exception& )
    2899             :     {
    2900             :         DBG_UNHANDLED_EXCEPTION();
    2901             :     }
    2902             : 
    2903             :     OSL_ENSURE( xControl.is(), "FmXFormShell::impl_getControl: no control found!" );
    2904           0 :     return xControl;
    2905             : }
    2906             : 
    2907             : 
    2908           0 : void FmXFormShell::impl_collectFormSearchContexts_nothrow( const Reference< XInterface>& _rxStartingPoint,
    2909             :     const OUString& _rCurrentLevelPrefix, FmFormArray& _out_rForms, ::std::vector< OUString >& _out_rNames )
    2910             : {
    2911             :     try
    2912             :     {
    2913           0 :         Reference< XIndexAccess> xContainer( _rxStartingPoint, UNO_QUERY );
    2914           0 :         if ( !xContainer.is() )
    2915           0 :             return;
    2916             : 
    2917           0 :         sal_Int32 nCount( xContainer->getCount() );
    2918           0 :         if ( nCount == 0 )
    2919           0 :             return;
    2920             : 
    2921           0 :         OUString sCurrentFormName;
    2922           0 :         OUStringBuffer aNextLevelPrefix;
    2923           0 :         for ( sal_Int32 i=0; i<nCount; ++i )
    2924             :         {
    2925             :             // is the current child a form?
    2926           0 :             Reference< XForm > xCurrentAsForm( xContainer->getByIndex(i), UNO_QUERY );
    2927           0 :             if ( !xCurrentAsForm.is() )
    2928           0 :                 continue;
    2929             : 
    2930           0 :             Reference< XNamed > xNamed( xCurrentAsForm, UNO_QUERY_THROW );
    2931           0 :             sCurrentFormName = xNamed->getName();
    2932             : 
    2933             :             // the name of the current form
    2934           0 :             OUStringBuffer sCompleteCurrentName( sCurrentFormName );
    2935           0 :             if ( !_rCurrentLevelPrefix.isEmpty() )
    2936             :             {
    2937           0 :                 sCompleteCurrentName.appendAscii( " (" );
    2938           0 :                 sCompleteCurrentName.append     ( _rCurrentLevelPrefix );
    2939           0 :                 sCompleteCurrentName.appendAscii( ")" );
    2940             :             }
    2941             : 
    2942             :             // the prefix for the next level
    2943           0 :             aNextLevelPrefix = _rCurrentLevelPrefix;
    2944           0 :             if ( !_rCurrentLevelPrefix.isEmpty() )
    2945           0 :                 aNextLevelPrefix.append( '/' );
    2946           0 :             aNextLevelPrefix.append( sCurrentFormName );
    2947             : 
    2948             :             // remember both the form and it's "display name"
    2949           0 :             _out_rForms.push_back( xCurrentAsForm );
    2950           0 :             _out_rNames.push_back( sCompleteCurrentName.makeStringAndClear() );
    2951             : 
    2952             :             // und absteigen
    2953           0 :             impl_collectFormSearchContexts_nothrow( xCurrentAsForm, aNextLevelPrefix.makeStringAndClear(), _out_rForms, _out_rNames );
    2954           0 :         }
    2955             :     }
    2956           0 :     catch( const Exception& )
    2957             :     {
    2958             :         DBG_UNHANDLED_EXCEPTION();
    2959             :     }
    2960             : }
    2961             : 
    2962             : 
    2963           0 : void FmXFormShell::startFiltering()
    2964             : {
    2965           0 :     if ( impl_checkDisposed() )
    2966           0 :         return;
    2967             : 
    2968             :     // setting all forms in filter mode
    2969           0 :     FmXFormView* pXView = m_pShell->GetFormView()->GetImpl();
    2970             : 
    2971             :     // if the active controller is our external one we have to use the trigger controller
    2972           0 :     Reference< XControlContainer> xContainer;
    2973           0 :     if (getActiveController() == m_xExternalViewController)
    2974             :     {
    2975             :         DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::startFiltering : inconsistent : active external controller, but no one triggered this !");
    2976           0 :         xContainer = m_xExtViewTriggerController->getContainer();
    2977             :     }
    2978             :     else
    2979           0 :         xContainer = getActiveController()->getContainer();
    2980             : 
    2981           0 :     PFormViewPageWindowAdapter pAdapter = pXView->findWindow( xContainer );
    2982           0 :     if ( pAdapter.is() )
    2983             :     {
    2984           0 :         const ::std::vector< Reference< runtime::XFormController> >& rControllerList = pAdapter->GetList();
    2985           0 :         for (   ::std::vector< Reference< runtime::XFormController> >::const_iterator j = rControllerList.begin();
    2986           0 :                 j != rControllerList.end();
    2987             :                 ++j
    2988             :             )
    2989             :         {
    2990           0 :             Reference< XModeSelector> xModeSelector(*j, UNO_QUERY);
    2991           0 :             if (xModeSelector.is())
    2992           0 :                 xModeSelector->setMode( OUString( "FilterMode"  ) );
    2993           0 :         }
    2994             :     }
    2995             : 
    2996           0 :     m_bFilterMode = true;
    2997             : 
    2998           0 :     m_pShell->UIFeatureChanged();
    2999           0 :     SfxViewFrame* pViewFrame = m_pShell->GetViewShell()->GetViewFrame();
    3000           0 :     pViewFrame->GetBindings().InvalidateShell( *m_pShell );
    3001             : 
    3002           0 :     if  (   pViewFrame->KnowsChildWindow( SID_FM_FILTER_NAVIGATOR )
    3003           0 :         &&  !pViewFrame->HasChildWindow( SID_FM_FILTER_NAVIGATOR )
    3004             :         )
    3005             :     {
    3006           0 :         pViewFrame->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
    3007           0 :     }
    3008             : }
    3009             : 
    3010             : 
    3011           0 : void saveFilter(const Reference< runtime::XFormController >& _rxController)
    3012             : {
    3013           0 :     Reference< XPropertySet> xFormAsSet(_rxController->getModel(), UNO_QUERY);
    3014           0 :     Reference< XPropertySet> xControllerAsSet(_rxController, UNO_QUERY);
    3015           0 :     Reference< XIndexAccess> xControllerAsIndex(_rxController, UNO_QUERY);
    3016             : 
    3017             :     // call the subcontroller
    3018           0 :     Reference< runtime::XFormController > xController;
    3019           0 :     for (sal_Int32 i = 0, nCount = xControllerAsIndex->getCount(); i < nCount; ++i)
    3020             :     {
    3021           0 :         xControllerAsIndex->getByIndex(i) >>= xController;
    3022           0 :         saveFilter(xController);
    3023             :     }
    3024             : 
    3025             :     try
    3026             :     {
    3027             : 
    3028           0 :         xFormAsSet->setPropertyValue(FM_PROP_FILTER, xControllerAsSet->getPropertyValue(FM_PROP_FILTER));
    3029           0 :         xFormAsSet->setPropertyValue(FM_PROP_APPLYFILTER, makeAny( true ) );
    3030             :     }
    3031           0 :     catch (const Exception& )
    3032             :     {
    3033             :         DBG_UNHANDLED_EXCEPTION();
    3034           0 :     }
    3035             : 
    3036           0 : }
    3037             : 
    3038             : 
    3039           0 : void FmXFormShell::stopFiltering(bool bSave)
    3040             : {
    3041           0 :     if ( impl_checkDisposed() )
    3042           0 :         return;
    3043             : 
    3044           0 :     m_bFilterMode = false;
    3045             : 
    3046           0 :     FmXFormView* pXView = m_pShell->GetFormView()->GetImpl();
    3047             : 
    3048             :     // if the active controller is our external one we have to use the trigger controller
    3049           0 :     Reference< XControlContainer> xContainer;
    3050           0 :     if (getActiveController() == m_xExternalViewController)
    3051             :     {
    3052             :         DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::stopFiltering : inconsistent : active external controller, but no one triggered this !");
    3053           0 :         xContainer = m_xExtViewTriggerController->getContainer();
    3054             :     }
    3055             :     else
    3056           0 :         xContainer = getActiveController()->getContainer();
    3057             : 
    3058           0 :     PFormViewPageWindowAdapter pAdapter = pXView->findWindow(xContainer);
    3059           0 :     if ( pAdapter.is() )
    3060             :     {
    3061           0 :         const ::std::vector< Reference< runtime::XFormController > >& rControllerList = pAdapter->GetList();
    3062           0 :         ::std::vector < OUString >   aOriginalFilters;
    3063           0 :         ::std::vector < sal_Bool >          aOriginalApplyFlags;
    3064             : 
    3065           0 :         if (bSave)
    3066             :         {
    3067           0 :             for (::std::vector< Reference< runtime::XFormController > > ::const_iterator j = rControllerList.begin();
    3068           0 :                  j != rControllerList.end(); ++j)
    3069             :             {
    3070           0 :                 if (bSave)
    3071             :                 {   // remember the current filter settings in case we're goin to reload the forms below (which may fail)
    3072             :                     try
    3073             :                     {
    3074           0 :                         Reference< XPropertySet > xFormAsSet((*j)->getModel(), UNO_QUERY);
    3075           0 :                         aOriginalFilters.push_back(::comphelper::getString(xFormAsSet->getPropertyValue(FM_PROP_FILTER)));
    3076           0 :                         aOriginalApplyFlags.push_back(::comphelper::getBOOL(xFormAsSet->getPropertyValue(FM_PROP_APPLYFILTER)));
    3077             :                     }
    3078           0 :                     catch(Exception&)
    3079             :                     {
    3080             :                         OSL_FAIL("FmXFormShell::stopFiltering : could not get the original filter !");
    3081             :                         // put dummies into the arrays so the they have the right size
    3082             : 
    3083           0 :                         if (aOriginalFilters.size() == aOriginalApplyFlags.size())
    3084             :                             // the first getPropertyValue failed -> use two dummies
    3085           0 :                             aOriginalFilters.push_back( OUString() );
    3086           0 :                         aOriginalApplyFlags.push_back( sal_False );
    3087             :                     }
    3088             :                 }
    3089           0 :                 saveFilter(*j);
    3090             :             }
    3091             :         }
    3092           0 :         for (::std::vector< Reference< runtime::XFormController > > ::const_iterator j = rControllerList.begin();
    3093           0 :              j != rControllerList.end(); ++j)
    3094             :         {
    3095             : 
    3096           0 :             Reference< XModeSelector> xModeSelector(*j, UNO_QUERY);
    3097           0 :             if (xModeSelector.is())
    3098           0 :                 xModeSelector->setMode( OUString( "DataMode"  ) );
    3099           0 :         }
    3100           0 :         if (bSave)  // execute the filter
    3101             :         {
    3102           0 :             const ::std::vector< Reference< runtime::XFormController > > & rControllers = pAdapter->GetList();
    3103           0 :             for (::std::vector< Reference< runtime::XFormController > > ::const_iterator j = rControllers.begin();
    3104           0 :                  j != rControllers.end(); ++j)
    3105             :             {
    3106           0 :                 Reference< XLoadable> xReload((*j)->getModel(), UNO_QUERY);
    3107           0 :                 if (!xReload.is())
    3108           0 :                     continue;
    3109           0 :                 Reference< XPropertySet > xFormSet(xReload, UNO_QUERY);
    3110             : 
    3111             :                 try
    3112             :                 {
    3113           0 :                     xReload->reload();
    3114             :                 }
    3115           0 :                 catch(Exception&)
    3116             :                 {
    3117             :                     OSL_FAIL("FmXFormShell::stopFiltering: Exception occurred!");
    3118             :                 }
    3119             : 
    3120           0 :                 if (!isRowSetAlive(xFormSet))
    3121             :                 {   // something went wrong -> restore the original state
    3122           0 :                     OUString sOriginalFilter = aOriginalFilters[ j - rControllers.begin() ];
    3123           0 :                     bool bOriginalApplyFlag = aOriginalApplyFlags[ j - rControllers.begin() ];
    3124             :                     try
    3125             :                     {
    3126           0 :                         xFormSet->setPropertyValue(FM_PROP_FILTER, makeAny(sOriginalFilter));
    3127           0 :                         xFormSet->setPropertyValue(FM_PROP_APPLYFILTER, makeAny(bOriginalApplyFlag));
    3128           0 :                         xReload->reload();
    3129             :                     }
    3130           0 :                     catch(const Exception&)
    3131             :                     {
    3132             :                         DBG_UNHANDLED_EXCEPTION();
    3133           0 :                     }
    3134             :                 }
    3135           0 :             }
    3136           0 :         }
    3137             :     }
    3138             : 
    3139           0 :     m_pShell->UIFeatureChanged();
    3140           0 :     m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
    3141             : }
    3142             : 
    3143             : 
    3144           0 : void FmXFormShell::CreateExternalView()
    3145             : {
    3146           0 :     if ( impl_checkDisposed() )
    3147           0 :         return;
    3148             : 
    3149             :     DBG_ASSERT(m_xAttachedFrame.is(), "FmXFormShell::CreateExternalView : no frame !");
    3150             : 
    3151             :     // the frame the external view is displayed in
    3152           0 :     bool bAlreadyExistent = m_xExternalViewController.is();
    3153           0 :     Reference< ::com::sun::star::frame::XFrame> xExternalViewFrame;
    3154           0 :     OUString sFrameName("_beamer");
    3155           0 :     sal_Int32 nSearchFlags = ::com::sun::star::frame::FrameSearchFlag::CHILDREN | ::com::sun::star::frame::FrameSearchFlag::CREATE;
    3156             : 
    3157           0 :     Reference< runtime::XFormController > xCurrentNavController( getNavController());
    3158             :         // the creation of the "partwindow" may cause a deactivate of the document which will result in our nav controller to be set to NULL
    3159             : 
    3160             :     // _first_ check if we have any valid fields we can use for the grid view
    3161             :     // FS - 21.10.99 - 69219
    3162             :     {
    3163           0 :         FmXBoundFormFieldIterator aModelIterator(xCurrentNavController->getModel());
    3164           0 :         Reference< XPropertySet> xCurrentModelSet;
    3165           0 :         bool bHaveUsableControls = false;
    3166           0 :         while ((xCurrentModelSet = Reference< XPropertySet>(aModelIterator.Next(), UNO_QUERY)).is())
    3167             :         {
    3168             :             // the FmXBoundFormFieldIterator only supplies controls with a valid control source
    3169             :             // so we just have to check the field type
    3170           0 :             sal_Int16 nClassId = ::comphelper::getINT16(xCurrentModelSet->getPropertyValue(FM_PROP_CLASSID));
    3171           0 :             switch (nClassId)
    3172             :             {
    3173             :                 case FormComponentType::IMAGECONTROL:
    3174             :                 case FormComponentType::CONTROL:
    3175           0 :                     continue;
    3176             :             }
    3177           0 :             bHaveUsableControls = true;
    3178           0 :             break;
    3179             :         }
    3180             : 
    3181           0 :         if (!bHaveUsableControls)
    3182             :         {
    3183           0 :             MessageDialog(NULL, SVX_RESSTR(RID_STR_NOCONTROLS_FOR_EXTERNALDISPLAY)).Execute();
    3184           0 :             return;
    3185           0 :         }
    3186             :     }
    3187             : 
    3188             :     // load the component for external form views
    3189           0 :     if (!bAlreadyExistent)
    3190             :     {
    3191           0 :         URL aWantToDispatch;
    3192           0 :         aWantToDispatch.Complete = FMURL_COMPONENT_FORMGRIDVIEW;
    3193             : 
    3194           0 :         Reference< ::com::sun::star::frame::XDispatchProvider> xProv(m_xAttachedFrame, UNO_QUERY);
    3195           0 :         Reference< ::com::sun::star::frame::XDispatch> xDisp;
    3196           0 :         if (xProv.is())
    3197           0 :             xDisp = xProv->queryDispatch(aWantToDispatch, sFrameName, nSearchFlags);
    3198           0 :         if (xDisp.is())
    3199             :         {
    3200           0 :             xDisp->dispatch(aWantToDispatch, Sequence< PropertyValue>());
    3201             :         }
    3202             : 
    3203             :         // with this the component should be loaded, now search the frame where it resides in
    3204           0 :         xExternalViewFrame = m_xAttachedFrame->findFrame(sFrameName, ::com::sun::star::frame::FrameSearchFlag::CHILDREN);
    3205           0 :         if (xExternalViewFrame.is())
    3206             :         {
    3207           0 :             m_xExternalViewController = xExternalViewFrame->getController();
    3208           0 :             Reference< ::com::sun::star::lang::XComponent> xComp(m_xExternalViewController, UNO_QUERY);
    3209           0 :             if (xComp.is())
    3210           0 :                 xComp->addEventListener((XEventListener*)(XPropertyChangeListener*)this);
    3211           0 :         }
    3212             :     }
    3213             :     else
    3214             :     {
    3215           0 :         xExternalViewFrame = m_xExternalViewController->getFrame();
    3216           0 :         Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
    3217             : 
    3218             :         // if we display the active form we interpret the slot as "remove it"
    3219           0 :         Reference< XForm> xCurrentModel(xCurrentNavController->getModel(), UNO_QUERY);
    3220           0 :         if ((xCurrentModel == m_xExternalDisplayedForm) || (getInternalForm(xCurrentModel) == m_xExternalDisplayedForm))
    3221             :         {
    3222           0 :             if ( m_xExternalViewController == getActiveController() )
    3223             :             {
    3224           0 :                 Reference< runtime::XFormController > xAsFormController( m_xExternalViewController, UNO_QUERY );
    3225           0 :                 ControllerFeatures aHelper( xAsFormController, NULL );
    3226           0 :                 (void)aHelper->commitCurrentControl();
    3227             :             }
    3228             : 
    3229           0 :             Reference< runtime::XFormController > xNewController(m_xExtViewTriggerController);
    3230           0 :             CloseExternalFormViewer();
    3231           0 :             setActiveController(xNewController);
    3232           0 :             return;
    3233             :         }
    3234             : 
    3235           0 :         URL aClearURL;
    3236           0 :         aClearURL.Complete = FMURL_GRIDVIEW_CLEARVIEW;
    3237             : 
    3238           0 :         Reference< ::com::sun::star::frame::XDispatch> xClear( xCommLink->queryDispatch(aClearURL, OUString(), 0));
    3239           0 :         if (xClear.is())
    3240           0 :             xClear->dispatch(aClearURL, Sequence< PropertyValue>());
    3241             :     }
    3242             : 
    3243             :     // TODO: We need an interceptor at the xSupplier, which forwards all queryDispatch requests to the FormController
    3244             :     // instance for which this "external view" was triggered
    3245             : 
    3246             :     // get the dispatch interface of the frame so we can communicate (interceptable) with the controller
    3247           0 :     Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
    3248             : 
    3249           0 :     if (m_xExternalViewController.is())
    3250             :     {
    3251             :         DBG_ASSERT(xCommLink.is(), "FmXFormShell::CreateExternalView : the component doesn't have the necessary interfaces !");
    3252             :         // collect the dispatchers we will need
    3253           0 :         URL aAddColumnURL;
    3254           0 :         aAddColumnURL.Complete = FMURL_GRIDVIEW_ADDCOLUMN;
    3255           0 :         Reference< ::com::sun::star::frame::XDispatch> xAddColumnDispatch( xCommLink->queryDispatch(aAddColumnURL, OUString(), 0));
    3256           0 :         URL aAttachURL;
    3257           0 :         aAttachURL.Complete = FMURL_GRIDVIEW_ATTACHTOFORM;
    3258           0 :         Reference< ::com::sun::star::frame::XDispatch> xAttachDispatch( xCommLink->queryDispatch(aAttachURL, OUString(), 0));
    3259             : 
    3260           0 :         if (xAddColumnDispatch.is() && xAttachDispatch.is())
    3261             :         {
    3262             :             DBG_ASSERT(xCurrentNavController.is(), "FmXFormShell::CreateExternalView : invalid call : have no nav controller !");
    3263             :             // first : dispatch the descriptions for the columns to add
    3264           0 :             sal_Int16 nAddedColumns = 0;
    3265             : 
    3266             :             // for radio buttons we need some special structures
    3267             :             typedef std::map< OUString, Sequence< OUString> > MapUString2UstringSeq;
    3268             :             typedef std::map< OUString, OUString > FmMapUString2UString;
    3269             :             typedef std::map< OUString, sal_Int16 > FmMapUString2Int16;
    3270             : 
    3271           0 :             MapUString2UstringSeq   aRadioValueLists;
    3272           0 :             MapUString2UstringSeq   aRadioListSources;
    3273           0 :             FmMapUString2UString    aRadioControlSources;
    3274           0 :             FmMapUString2Int16      aRadioPositions;
    3275             : 
    3276           0 :             FmXBoundFormFieldIterator aModelIterator(xCurrentNavController->getModel());
    3277           0 :             Reference< XPropertySet> xCurrentModelSet;
    3278           0 :             OUString sColumnType,aGroupName,sControlSource;
    3279           0 :             Sequence< Property> aProps;
    3280           0 :             Reference< XPropertySet> xCurrentBoundField;
    3281           0 :             while ((xCurrentModelSet = Reference< XPropertySet>(aModelIterator.Next(), UNO_QUERY)).is())
    3282             :             {
    3283           0 :                 xCurrentModelSet->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xCurrentBoundField;
    3284             :                 OSL_ENSURE(xCurrentModelSet.is(),"xCurrentModelSet is null!");
    3285             :                 // create a description of the column to be created
    3286             :                 // first : determine it's type
    3287             : 
    3288           0 :                 sal_Int16 nClassId = ::comphelper::getINT16(xCurrentModelSet->getPropertyValue(FM_PROP_CLASSID));
    3289           0 :                 switch (nClassId)
    3290             :                 {
    3291             :                     case FormComponentType::RADIOBUTTON:
    3292             :                     {
    3293             :                         // get the label of the button (this is the access key for our structures)
    3294           0 :                         aGroupName = getLabelName(xCurrentModelSet);
    3295             : 
    3296             :                         // add the reference value of the radio button to the list source sequence
    3297           0 :                         Sequence< OUString>& aThisGroupLabels = aRadioListSources[aGroupName];
    3298           0 :                         sal_Int32 nNewSizeL = aThisGroupLabels.getLength() + 1;
    3299           0 :                         aThisGroupLabels.realloc(nNewSizeL);
    3300           0 :                         aThisGroupLabels.getArray()[nNewSizeL - 1] = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_REFVALUE));
    3301             : 
    3302             :                         // add the label to the value list sequence
    3303           0 :                         Sequence< OUString>& aThisGroupControlSources = aRadioValueLists[aGroupName];
    3304           0 :                         sal_Int32 nNewSizeC = aThisGroupControlSources.getLength() + 1;
    3305           0 :                         aThisGroupControlSources.realloc(nNewSizeC);
    3306           0 :                         aThisGroupControlSources.getArray()[nNewSizeC - 1] = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_LABEL));
    3307             : 
    3308             :                         // remember the controls source of the radio group
    3309           0 :                         sControlSource = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_CONTROLSOURCE));
    3310           0 :                         if (aRadioControlSources.find(aGroupName) == aRadioControlSources.end())
    3311           0 :                             aRadioControlSources[aGroupName] = sControlSource;
    3312             : #ifdef DBG_UTIL
    3313             :                         else
    3314             :                             DBG_ASSERT(aRadioControlSources[aGroupName] == sControlSource,
    3315             :                             "FmXFormShell::CreateExternalView : inconsistent radio buttons detected !");
    3316             :                             // (radio buttons with the same name should have the same control source)
    3317             : #endif
    3318             :                         // remember the position within the columns
    3319           0 :                         if (aRadioPositions.find(aGroupName) == aRadioPositions.end())
    3320           0 :                             aRadioPositions[aGroupName] = (sal_Int16)nAddedColumns;
    3321             : 
    3322             :                         // any further handling is done below
    3323             :                     }
    3324           0 :                     continue;
    3325             : 
    3326             :                     case FormComponentType::IMAGECONTROL:
    3327             :                     case FormComponentType::CONTROL:
    3328             :                         // no grid columns for these types (though they have a control source)
    3329           0 :                         continue;
    3330             :                     case FormComponentType::CHECKBOX:
    3331           0 :                         sColumnType = FM_COL_CHECKBOX; break;
    3332             :                     case FormComponentType::LISTBOX:
    3333           0 :                         sColumnType = FM_COL_LISTBOX; break;
    3334             :                     case FormComponentType::COMBOBOX:
    3335           0 :                         sColumnType = FM_COL_COMBOBOX; break;
    3336             :                     case FormComponentType::DATEFIELD:
    3337           0 :                         sColumnType = FM_COL_DATEFIELD; break;
    3338             :                     case FormComponentType::TIMEFIELD:
    3339           0 :                         sColumnType = FM_COL_TIMEFIELD; break;
    3340             :                     case FormComponentType::NUMERICFIELD:
    3341           0 :                         sColumnType = FM_COL_NUMERICFIELD; break;
    3342             :                     case FormComponentType::CURRENCYFIELD:
    3343           0 :                         sColumnType = FM_COL_CURRENCYFIELD; break;
    3344             :                     case FormComponentType::PATTERNFIELD:
    3345           0 :                         sColumnType = FM_COL_PATTERNFIELD; break;
    3346             : 
    3347             :                     case FormComponentType::TEXTFIELD:
    3348             :                         {
    3349           0 :                             sColumnType = FM_COL_TEXTFIELD;
    3350             :                             // we know at least two different controls which are TextFields : the basic edit field and the formatted
    3351             :                             // field. we distinguish them by their service name
    3352           0 :                             Reference< XServiceInfo> xInfo(xCurrentModelSet, UNO_QUERY);
    3353           0 :                             if (xInfo.is())
    3354             :                             {
    3355           0 :                                 sal_Int16 nObjectType = getControlTypeByObject(xInfo);
    3356           0 :                                 if (OBJ_FM_FORMATTEDFIELD == nObjectType)
    3357           0 :                                     sColumnType = FM_COL_FORMATTEDFIELD;
    3358           0 :                             }
    3359             :                         }
    3360           0 :                         break;
    3361             :                     default:
    3362           0 :                         sColumnType = FM_COL_TEXTFIELD; break;
    3363             :                 }
    3364             : 
    3365           0 :                 const sal_Int16 nDispatchArgs = 3;
    3366           0 :                 Sequence< PropertyValue> aDispatchArgs(nDispatchArgs);
    3367           0 :                 PropertyValue* pDispatchArgs = aDispatchArgs.getArray();
    3368             : 
    3369             :                 // properties describing "meta data" about the column
    3370             :                 // the type
    3371           0 :                 pDispatchArgs->Name = FMARG_ADDCOL_COLUMNTYPE;
    3372           0 :                 pDispatchArgs->Value <<= sColumnType;
    3373           0 :                 ++pDispatchArgs;
    3374             : 
    3375             :                 // the pos : append the col
    3376           0 :                 pDispatchArgs->Name = FMARG_ADDCOL_COLUMNPOS;
    3377           0 :                 pDispatchArgs->Value <<= nAddedColumns;
    3378           0 :                 ++pDispatchArgs;
    3379             : 
    3380             :                 // the properties to forward to the new column
    3381           0 :                 Sequence< PropertyValue> aColumnProps(1);
    3382           0 :                 PropertyValue* pColumnProps = aColumnProps.getArray();
    3383             : 
    3384             :                 // the label
    3385           0 :                 pColumnProps->Name = FM_PROP_LABEL;
    3386           0 :                 pColumnProps->Value <<= getLabelName(xCurrentModelSet);
    3387           0 :                 ++pColumnProps;
    3388             : 
    3389             :                 // for all other props : transfer them
    3390           0 :                 Reference< XPropertySetInfo> xControlModelInfo( xCurrentModelSet->getPropertySetInfo());
    3391             :                 DBG_ASSERT(xControlModelInfo.is(), "FmXFormShell::CreateExternalView : the control model has no property info ! This will crash !");
    3392           0 :                 aProps = xControlModelInfo->getProperties();
    3393           0 :                 const Property* pProps = aProps.getConstArray();
    3394             : 
    3395             :                 // realloc the control description sequence
    3396           0 :                 sal_Int32 nExistentDescs = pColumnProps - aColumnProps.getArray();
    3397           0 :                 aColumnProps.realloc(nExistentDescs + aProps.getLength());
    3398           0 :                 pColumnProps = aColumnProps.getArray() + nExistentDescs;
    3399             : 
    3400           0 :                 for (sal_Int32 i=0; i<aProps.getLength(); ++i, ++pProps)
    3401             :                 {
    3402           0 :                     if (pProps->Name.equals(FM_PROP_LABEL))
    3403             :                         // already set
    3404           0 :                         continue;
    3405           0 :                     if (pProps->Name.equals(FM_PROP_DEFAULTCONTROL))
    3406             :                         // allow the column's own "default control"
    3407           0 :                         continue;
    3408           0 :                     if (pProps->Attributes & PropertyAttribute::READONLY)
    3409             :                         // assume that properties which are readonly for the control are ro for the column to be created, too
    3410           0 :                         continue;
    3411             : 
    3412           0 :                     pColumnProps->Name = pProps->Name;
    3413           0 :                     pColumnProps->Value = xCurrentModelSet->getPropertyValue(pProps->Name);
    3414           0 :                     ++pColumnProps;
    3415             :                 }
    3416           0 :                 aColumnProps.realloc(pColumnProps - aColumnProps.getArray());
    3417             : 
    3418             :                 // columns props are a dispatch argument
    3419           0 :                 pDispatchArgs->Name = "ColumnProperties"; // TODO : fmurl.*
    3420           0 :                 pDispatchArgs->Value = makeAny(aColumnProps);
    3421           0 :                 ++pDispatchArgs;
    3422             :                 DBG_ASSERT(nDispatchArgs == (pDispatchArgs - aDispatchArgs.getConstArray()),
    3423             :                     "FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
    3424             : 
    3425             :                 // dispatch the "add column"
    3426           0 :                 xAddColumnDispatch->dispatch(aAddColumnURL, aDispatchArgs);
    3427           0 :                 ++nAddedColumns;
    3428           0 :             }
    3429             : 
    3430             :             // now for the radio button handling
    3431           0 :             sal_Int16 nOffset(0);
    3432             :             // properties describing the "direct" column properties
    3433           0 :             const sal_Int16 nListBoxDescription = 6;
    3434           0 :             Sequence< PropertyValue> aListBoxDescription(nListBoxDescription);
    3435           0 :             for (   FmMapUString2UString::const_iterator aCtrlSource = aRadioControlSources.begin();
    3436           0 :                     aCtrlSource != aRadioControlSources.end();
    3437             :                     ++aCtrlSource, ++nOffset
    3438             :                 )
    3439             :             {
    3440             : 
    3441           0 :                 PropertyValue* pListBoxDescription = aListBoxDescription.getArray();
    3442             :                 // label
    3443           0 :                 pListBoxDescription->Name = FM_PROP_LABEL;
    3444           0 :                 pListBoxDescription->Value <<= (*aCtrlSource).first;
    3445           0 :                 ++pListBoxDescription;
    3446             : 
    3447             :                 // control source
    3448           0 :                 pListBoxDescription->Name = FM_PROP_CONTROLSOURCE;
    3449           0 :                 pListBoxDescription->Value <<= (*aCtrlSource).second;
    3450           0 :                 ++pListBoxDescription;
    3451             : 
    3452             :                 // bound column
    3453           0 :                 pListBoxDescription->Name = FM_PROP_BOUNDCOLUMN;
    3454           0 :                 pListBoxDescription->Value <<= (sal_Int16)1;
    3455           0 :                 ++pListBoxDescription;
    3456             : 
    3457             :                 // content type
    3458           0 :                 pListBoxDescription->Name = FM_PROP_LISTSOURCETYPE;
    3459           0 :                  ListSourceType eType = ListSourceType_VALUELIST;
    3460           0 :                  pListBoxDescription->Value = makeAny(eType);
    3461           0 :                 ++pListBoxDescription;
    3462             : 
    3463             :                 // list source
    3464           0 :                 MapUString2UstringSeq::const_iterator aCurrentListSource = aRadioListSources.find((*aCtrlSource).first);
    3465             :                 DBG_ASSERT(aCurrentListSource != aRadioListSources.end(),
    3466             :                     "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
    3467           0 :                 pListBoxDescription->Name = FM_PROP_LISTSOURCE;
    3468           0 :                 pListBoxDescription->Value = makeAny((*aCurrentListSource).second);
    3469           0 :                 ++pListBoxDescription;
    3470             : 
    3471             :                 // value list
    3472           0 :                 MapUString2UstringSeq::const_iterator aCurrentValueList = aRadioValueLists.find((*aCtrlSource).first);
    3473             :                 DBG_ASSERT(aCurrentValueList != aRadioValueLists.end(),
    3474             :                     "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
    3475           0 :                 pListBoxDescription->Name = FM_PROP_STRINGITEMLIST;
    3476           0 :                 pListBoxDescription->Value = makeAny(((*aCurrentValueList).second));
    3477           0 :                 ++pListBoxDescription;
    3478             : 
    3479             :                 DBG_ASSERT(nListBoxDescription == (pListBoxDescription - aListBoxDescription.getConstArray()),
    3480             :                     "FmXFormShell::CreateExternalView : forgot to adjust nListBoxDescription ?");
    3481             : 
    3482             :                 // properties describing the column "meta data"
    3483           0 :                 const sal_Int16 nDispatchArgs = 3;
    3484           0 :                 Sequence< PropertyValue> aDispatchArgs(nDispatchArgs);
    3485           0 :                 PropertyValue* pDispatchArgs = aDispatchArgs.getArray();
    3486             : 
    3487             :                 // column type : listbox
    3488           0 :                 pDispatchArgs->Name = FMARG_ADDCOL_COLUMNTYPE;
    3489           0 :                 OUString fColName = FM_COL_LISTBOX;
    3490           0 :                 pDispatchArgs->Value <<= fColName;
    3491             : //              pDispatchArgs->Value <<= (OUString)FM_COL_LISTBOX;
    3492           0 :                 ++pDispatchArgs;
    3493             : 
    3494             :                 // column position
    3495           0 :                 pDispatchArgs->Name = FMARG_ADDCOL_COLUMNPOS;
    3496           0 :                 FmMapUString2Int16::const_iterator aOffset = aRadioPositions.find((*aCtrlSource).first);
    3497             :                 DBG_ASSERT(aOffset != aRadioPositions.end(),
    3498             :                     "FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
    3499           0 :                 sal_Int16 nPosition = (*aOffset).second;
    3500           0 :                 nPosition = nPosition + nOffset;
    3501             :                     // we already inserted nOffset additional columns ....
    3502           0 :                 pDispatchArgs->Value <<= nPosition;
    3503           0 :                 ++pDispatchArgs;
    3504             : 
    3505             :                 // the
    3506           0 :                 pDispatchArgs->Name = "ColumnProperties"; // TODO : fmurl.*
    3507           0 :                 pDispatchArgs->Value = makeAny(aListBoxDescription);
    3508           0 :                 ++pDispatchArgs;
    3509             :                 DBG_ASSERT(nDispatchArgs == (pDispatchArgs - aDispatchArgs.getConstArray()),
    3510             :                     "FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
    3511             : 
    3512             :                 // dispatch the "add column"
    3513           0 :                 xAddColumnDispatch->dispatch(aAddColumnURL, aDispatchArgs);
    3514           0 :                 ++nAddedColumns;
    3515           0 :             }
    3516             : 
    3517             : 
    3518             :             DBG_ASSERT(nAddedColumns > 0, "FmXFormShell::CreateExternalView : no controls (inconsistent) !");
    3519             :                 // we should have checked if we have any usable controls (see above).
    3520             : 
    3521             :             // "load" the "form" of the external view
    3522           0 :             PropertyValue aArg;
    3523           0 :             aArg.Name = FMARG_ATTACHTO_MASTERFORM;
    3524           0 :             Reference< XResultSet> xForm(xCurrentNavController->getModel(), UNO_QUERY);
    3525           0 :             aArg.Value <<= xForm;
    3526             : 
    3527           0 :             m_xExternalDisplayedForm = xForm;
    3528             :                 // do this before dispatching the "attach" command, as the atach may result in a call to our queryDispatch (for the FormSlots)
    3529             :                 // whichs needs the m_xExternalDisplayedForm
    3530             : 
    3531           0 :             xAttachDispatch->dispatch(aAttachURL, Sequence< PropertyValue>(&aArg, 1));
    3532             : 
    3533           0 :             m_xExtViewTriggerController = xCurrentNavController;
    3534             : 
    3535             :             // we want to know modifications done in the external view
    3536             :             // if the external controller is a XFormController we can use all our default handlings for it
    3537           0 :             Reference< runtime::XFormController > xFormController( m_xExternalViewController, UNO_QUERY );
    3538             :             OSL_ENSURE( xFormController.is(), "FmXFormShell::CreateExternalView:: invalid external view controller!" );
    3539           0 :             if (xFormController.is())
    3540           0 :                 xFormController->addActivateListener((XFormControllerListener*)this);
    3541           0 :         }
    3542             :     }
    3543             : #ifdef DBG_UTIL
    3544             :     else
    3545             :     {
    3546             :         OSL_FAIL("FmXFormShell::CreateExternalView : could not create the external form view !");
    3547             :     }
    3548             : #endif
    3549           0 :     InvalidateSlot( SID_FM_VIEW_AS_GRID, false );
    3550             : }
    3551             : 
    3552             : 
    3553        5452 : void FmXFormShell::implAdjustConfigCache()
    3554             : {
    3555             :     // get (cache) the wizard usage flag
    3556        5452 :     Sequence< OUString > aNames(1);
    3557        5452 :     aNames[0] = "FormControlPilotsEnabled";
    3558       10904 :     Sequence< Any > aFlags = GetProperties(aNames);
    3559        5452 :     if (1 == aFlags.getLength())
    3560       10904 :         m_bUseWizards = ::cppu::any2bool(aFlags[0]);
    3561        5452 : }
    3562             : 
    3563             : 
    3564           0 : void FmXFormShell::Notify( const com::sun::star::uno::Sequence< OUString >& _rPropertyNames)
    3565             : {
    3566           0 :     if ( impl_checkDisposed() )
    3567           0 :         return;
    3568             : 
    3569           0 :     const OUString* pSearch = _rPropertyNames.getConstArray();
    3570           0 :     const OUString* pSearchTil = pSearch + _rPropertyNames.getLength();
    3571           0 :     for (;pSearch < pSearchTil; ++pSearch)
    3572           0 :         if (pSearch->equalsAscii("FormControlPilotsEnabled"))
    3573             :         {
    3574           0 :             implAdjustConfigCache();
    3575           0 :             InvalidateSlot( SID_FM_USE_WIZARDS, true );
    3576             :         }
    3577             : }
    3578             : 
    3579           0 : void FmXFormShell::Commit()
    3580             : {
    3581           0 : }
    3582             : 
    3583             : 
    3584           0 : void FmXFormShell::SetWizardUsing(bool _bUseThem)
    3585             : {
    3586           0 :     m_bUseWizards = _bUseThem;
    3587             : 
    3588           0 :     Sequence< OUString > aNames(1);
    3589           0 :     aNames[0] = "FormControlPilotsEnabled";
    3590           0 :     Sequence< Any > aValues(1);
    3591           0 :     aValues[0] <<= m_bUseWizards;
    3592           0 :     PutProperties(aNames, aValues);
    3593           0 : }
    3594             : 
    3595             : 
    3596        6602 : void FmXFormShell::viewDeactivated( FmFormView& _rCurrentView, bool _bDeactivateController /* = sal_True */ )
    3597             : {
    3598             : 
    3599        6602 :     if ( _rCurrentView.GetImpl() && !_rCurrentView.IsDesignMode() )
    3600             :     {
    3601         518 :         _rCurrentView.GetImpl()->Deactivate( _bDeactivateController );
    3602             :     }
    3603             : 
    3604             :     // if we have an async load operation pending for the 0-th page for this view,
    3605             :     // we need to cancel this
    3606        6602 :     FmFormPage* pPage = _rCurrentView.GetCurPage();
    3607        6602 :     if ( pPage )
    3608             :     {
    3609             :         // move all events from our queue to a new one, omit the events for the deactivated
    3610             :         // page
    3611        6568 :         ::std::queue< FmLoadAction > aNewEvents;
    3612       13406 :         while ( !m_aLoadingPages.empty() )
    3613             :         {
    3614         270 :             FmLoadAction aAction = m_aLoadingPages.front();
    3615         270 :             m_aLoadingPages.pop();
    3616         270 :             if ( pPage != aAction.pPage )
    3617             :             {
    3618           0 :                 aNewEvents.push( aAction );
    3619             :             }
    3620             :             else
    3621             :             {
    3622         270 :                 Application::RemoveUserEvent( aAction.nEventId );
    3623             :             }
    3624             :         }
    3625        6568 :         m_aLoadingPages = aNewEvents;
    3626             :     }
    3627             : 
    3628             :     // remove callbacks at the page
    3629        6602 :     if ( pPage )
    3630             :     {
    3631        6568 :         pPage->GetImpl().SetFormsCreationHdl( Link() );
    3632             :     }
    3633        6602 :     UpdateForms( true );
    3634        6602 : }
    3635             : 
    3636             : 
    3637        2472 : IMPL_LINK( FmXFormShell, OnFirstTimeActivation, void*, /*NOTINTERESTEDIN*/ )
    3638             : {
    3639        1236 :     if ( impl_checkDisposed() )
    3640           0 :         return 0L;
    3641             : 
    3642        1236 :     m_nActivationEvent = 0;
    3643        1236 :     SfxObjectShell* pDocument = m_pShell->GetObjectShell();
    3644             : 
    3645        1236 :     if  ( pDocument && !pDocument->HasName() )
    3646             :     {
    3647        1158 :         if ( isEnhancedForm() )
    3648             :         {
    3649             :             // show the data navigator
    3650           0 :             if ( !m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_SHOW_DATANAVIGATOR ) )
    3651           0 :                 m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_SHOW_DATANAVIGATOR );
    3652             :         }
    3653             :     }
    3654             : 
    3655        1236 :     return 0L;
    3656             : }
    3657             : 
    3658             : 
    3659         512 : IMPL_LINK( FmXFormShell, OnFormsCreated, FmFormPage*, /*_pPage*/ )
    3660             : {
    3661         256 :     UpdateForms( true );
    3662         256 :     return 0L;
    3663             : }
    3664             : 
    3665             : 
    3666        6356 : void FmXFormShell::viewActivated( FmFormView& _rCurrentView, bool _bSyncAction /* = sal_False */ )
    3667             : {
    3668             : 
    3669        6356 :     FmFormPage* pPage = _rCurrentView.GetCurPage();
    3670             : 
    3671             :     // activate our view if we are activated ourself
    3672             :     // FS - 30.06.99 - 67308
    3673        6356 :     if ( _rCurrentView.GetImpl() && !_rCurrentView.IsDesignMode() )
    3674             :     {
    3675             :         // load forms for the page the current view belongs to
    3676         516 :         if ( pPage )
    3677             :         {
    3678         516 :             if ( !pPage->GetImpl().hasEverBeenActivated() )
    3679         332 :                 loadForms( pPage, FORMS_LOAD | ( _bSyncAction ? FORMS_SYNC : FORMS_ASYNC ) );
    3680         516 :             pPage->GetImpl().setHasBeenActivated( );
    3681             :         }
    3682             : 
    3683             :         // first-time initializations for the views
    3684         516 :         if ( !_rCurrentView.GetImpl()->hasEverBeenActivated( ) )
    3685             :         {
    3686         318 :             _rCurrentView.GetImpl()->onFirstViewActivation( PTR_CAST( FmFormModel, _rCurrentView.GetModel() ) );
    3687         318 :             _rCurrentView.GetImpl()->setHasBeenActivated( );
    3688             :         }
    3689             : 
    3690             :         // activate the current view
    3691         516 :         _rCurrentView.GetImpl()->Activate( _bSyncAction );
    3692             :     }
    3693             : 
    3694             :     // set callbacks at the page
    3695        6356 :     if ( pPage )
    3696             :     {
    3697        6356 :         pPage->GetImpl().SetFormsCreationHdl( LINK( this, FmXFormShell, OnFormsCreated ) );
    3698             :     }
    3699             : 
    3700        6356 :     UpdateForms( true );
    3701             : 
    3702        6356 :     if ( !hasEverBeenActivated() )
    3703             :     {
    3704        5408 :         m_nActivationEvent = Application::PostUserEvent( LINK( this, FmXFormShell, OnFirstTimeActivation ) );
    3705        5408 :         setHasBeenActivated();
    3706             :     }
    3707             : 
    3708             :     // find a default "current form", if there is none, yet
    3709             :     // #i88186# / 2008-04-12 / frank.schoenheit@sun.com
    3710        6356 :     impl_defaultCurrentForm_nothrow();
    3711        6356 : }
    3712             : 
    3713             : 
    3714        6356 : void FmXFormShell::impl_defaultCurrentForm_nothrow()
    3715             : {
    3716        6356 :     if ( impl_checkDisposed() )
    3717           0 :         return;
    3718             : 
    3719        6356 :     if ( m_xCurrentForm.is() )
    3720             :         // no action required
    3721         110 :         return;
    3722             : 
    3723        6246 :     FmFormView* pFormView = m_pShell->GetFormView();
    3724        6246 :     FmFormPage* pPage = pFormView ? pFormView->GetCurPage() : NULL;
    3725        6246 :     if ( !pPage )
    3726           0 :         return;
    3727             : 
    3728             :     try
    3729             :     {
    3730        6246 :         Reference< XIndexAccess > xForms( pPage->GetForms( false ), UNO_QUERY );
    3731        6246 :         if ( !xForms.is() || !xForms->hasElements() )
    3732        6188 :             return;
    3733             : 
    3734         116 :         Reference< XForm > xNewCurrentForm( xForms->getByIndex(0), UNO_QUERY_THROW );
    3735         116 :         impl_updateCurrentForm( xNewCurrentForm );
    3736             :     }
    3737           0 :     catch( const Exception& )
    3738             :     {
    3739             :         DBG_UNHANDLED_EXCEPTION();
    3740             :     }
    3741             : }
    3742             : 
    3743             : 
    3744           0 : void FmXFormShell::smartControlReset( const Reference< XIndexAccess >& _rxModels )
    3745             : {
    3746           0 :     if (!_rxModels.is())
    3747             :     {
    3748             :         OSL_FAIL("FmXFormShell::smartControlReset: invalid container!");
    3749           0 :         return;
    3750             :     }
    3751             : 
    3752           0 :     static const OUString sClassIdPropertyName = FM_PROP_CLASSID;
    3753           0 :     static const OUString sBoundFieldPropertyName = FM_PROP_BOUNDFIELD;
    3754           0 :     sal_Int32 nCount = _rxModels->getCount();
    3755           0 :     Reference< XPropertySet > xCurrent;
    3756           0 :     Reference< XPropertySetInfo > xCurrentInfo;
    3757           0 :     Reference< XPropertySet > xBoundField;
    3758             : 
    3759           0 :     for (sal_Int32 i=0; i<nCount; ++i)
    3760             :     {
    3761           0 :         _rxModels->getByIndex(i) >>= xCurrent;
    3762           0 :         if (xCurrent.is())
    3763           0 :             xCurrentInfo = xCurrent->getPropertySetInfo();
    3764             :         else
    3765           0 :             xCurrentInfo.clear();
    3766           0 :         if (!xCurrentInfo.is())
    3767           0 :             continue;
    3768             : 
    3769           0 :         if (xCurrentInfo->hasPropertyByName(sClassIdPropertyName))
    3770             :         {   // it's a control model
    3771             : 
    3772             :             // check if this control is bound to a living database field
    3773           0 :             if (xCurrentInfo->hasPropertyByName(sBoundFieldPropertyName))
    3774           0 :                 xCurrent->getPropertyValue(sBoundFieldPropertyName) >>= xBoundField;
    3775             :             else
    3776           0 :                 xBoundField.clear();
    3777             : 
    3778             :             // reset only if it's *not* bound
    3779           0 :             bool bReset = !xBoundField.is();
    3780             : 
    3781             :             // and additionally, check if it has an external value binding
    3782           0 :             Reference< XBindableValue > xBindable( xCurrent, UNO_QUERY );
    3783           0 :             if ( xBindable.is() && xBindable->getValueBinding().is() )
    3784           0 :                 bReset = false;
    3785             : 
    3786           0 :             if ( bReset )
    3787             :             {
    3788           0 :                 Reference< XReset > xControlReset( xCurrent, UNO_QUERY );
    3789           0 :                 if ( xControlReset.is() )
    3790           0 :                     xControlReset->reset();
    3791           0 :             }
    3792             :         }
    3793             :         else
    3794             :         {
    3795           0 :             Reference< XIndexAccess > xContainer(xCurrent, UNO_QUERY);
    3796           0 :             if (xContainer.is())
    3797           0 :                 smartControlReset(xContainer);
    3798             :         }
    3799           0 :     }
    3800             : }
    3801             : 
    3802             : 
    3803          28 : IMPL_LINK( FmXFormShell, OnLoadForms, FmFormPage*, /*_pPage*/ )
    3804             : {
    3805          14 :     FmLoadAction aAction = m_aLoadingPages.front();
    3806          14 :     m_aLoadingPages.pop();
    3807             : 
    3808          14 :     loadForms( aAction.pPage, aAction.nFlags & ~FORMS_ASYNC );
    3809          14 :     return 0L;
    3810             : }
    3811             : 
    3812             : 
    3813             : namespace
    3814             : {
    3815          14 :     bool lcl_isLoadable( const Reference< XInterface >& _rxLoadable )
    3816             :     {
    3817             :         // determines whether a form should be loaded or not
    3818             :         // if there is no datasource or connection there is no reason to load a form
    3819          14 :         Reference< XPropertySet > xSet( _rxLoadable, UNO_QUERY );
    3820          14 :         if ( !xSet.is() )
    3821           0 :             return false;
    3822             :         try
    3823             :         {
    3824          14 :             Reference< XConnection > xConn;
    3825          14 :             if ( OStaticDataAccessTools().isEmbeddedInDatabase( _rxLoadable.get(), xConn ) )
    3826           0 :                 return true;
    3827             : 
    3828             :             // is there already a active connection
    3829          14 :             xSet->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xConn;
    3830          14 :             if ( xConn.is() )
    3831           0 :                 return true;
    3832             : 
    3833          28 :             OUString sPropertyValue;
    3834          14 :             OSL_VERIFY( xSet->getPropertyValue( FM_PROP_DATASOURCE ) >>= sPropertyValue );
    3835          14 :             if ( !sPropertyValue.isEmpty() )
    3836           0 :                 return true;
    3837             : 
    3838          14 :             OSL_VERIFY( xSet->getPropertyValue( FM_PROP_URL ) >>= sPropertyValue );
    3839          14 :             if ( !sPropertyValue.isEmpty() )
    3840          14 :                 return true;
    3841             :         }
    3842           0 :         catch(const Exception&)
    3843             :         {
    3844             :             DBG_UNHANDLED_EXCEPTION();
    3845             :         }
    3846          14 :         return false;
    3847             :     }
    3848             : }
    3849             : 
    3850             : 
    3851         392 : void FmXFormShell::loadForms( FmFormPage* _pPage, const sal_uInt16 _nBehaviour /* FORMS_LOAD | FORMS_SYNC */ )
    3852             : {
    3853             :     DBG_ASSERT( ( _nBehaviour & ( FORMS_ASYNC | FORMS_UNLOAD ) )  != ( FORMS_ASYNC | FORMS_UNLOAD ),
    3854             :         "FmXFormShell::loadForms: async loading not supported - this will heavily fail!" );
    3855             : 
    3856         392 :     if ( _nBehaviour & FORMS_ASYNC )
    3857             :     {
    3858             :         m_aLoadingPages.push( FmLoadAction(
    3859             :             _pPage,
    3860             :             _nBehaviour,
    3861             :             Application::PostUserEvent( LINK( this, FmXFormShell, OnLoadForms ), _pPage )
    3862         286 :         ) );
    3863         678 :         return;
    3864             :     }
    3865             : 
    3866             :     DBG_ASSERT( _pPage, "FmXFormShell::loadForms: invalid page!" );
    3867         106 :     if ( _pPage )
    3868             :     {
    3869             :         // lock the undo env so the forms can change non-transient properties while loading
    3870             :         // (without this my doc's modified flag would be set)
    3871         106 :         FmFormModel* pModel = PTR_CAST( FmFormModel, _pPage->GetModel() );
    3872             :         DBG_ASSERT( pModel, "FmXFormShell::loadForms: invalid model!" );
    3873         106 :         if ( pModel )
    3874         106 :             pModel->GetUndoEnv().Lock();
    3875             : 
    3876             :         // load all forms
    3877         106 :         Reference< XIndexAccess >  xForms;
    3878         106 :         xForms.set(_pPage->GetForms( false ), css::uno::UNO_QUERY);
    3879             : 
    3880         106 :         if ( xForms.is() )
    3881             :         {
    3882         106 :             Reference< XLoadable >  xForm;
    3883         106 :             bool                    bFormWasLoaded = false;
    3884         120 :             for ( sal_Int32 j = 0, nCount = xForms->getCount(); j < nCount; ++j )
    3885             :             {
    3886          14 :                 xForms->getByIndex( j ) >>= xForm;
    3887          14 :                 bFormWasLoaded = false;
    3888             :                 // a database form must be loaded for
    3889             :                 try
    3890             :                 {
    3891          14 :                     if ( 0 == ( _nBehaviour & FORMS_UNLOAD ) )
    3892             :                     {
    3893          14 :                         if ( lcl_isLoadable( xForm ) && !xForm->isLoaded() )
    3894           0 :                             xForm->load();
    3895             :                     }
    3896             :                     else
    3897             :                     {
    3898           0 :                         if ( xForm->isLoaded() )
    3899             :                         {
    3900           0 :                             bFormWasLoaded = true;
    3901           0 :                             xForm->unload();
    3902             :                         }
    3903             :                     }
    3904             :                 }
    3905           0 :                 catch( const Exception& )
    3906             :                 {
    3907             :                     DBG_UNHANDLED_EXCEPTION();
    3908             :                 }
    3909             : 
    3910             :                 // reset the form if it was loaded
    3911          14 :                 if ( bFormWasLoaded )
    3912             :                 {
    3913           0 :                     Reference< XIndexAccess > xContainer( xForm, UNO_QUERY );
    3914             :                     DBG_ASSERT( xContainer.is(), "FmXFormShell::loadForms: the form is no container!" );
    3915           0 :                     if ( xContainer.is() )
    3916           0 :                         smartControlReset( xContainer );
    3917             :                 }
    3918         106 :             }
    3919             :         }
    3920             : 
    3921         106 :         if ( pModel )
    3922             :             // unlock the environment
    3923         106 :             pModel->GetUndoEnv().UnLock();
    3924             :     }
    3925             : }
    3926             : 
    3927             : 
    3928           0 : void FmXFormShell::ExecuteTextAttribute( SfxRequest& _rReq )
    3929             : {
    3930           0 :     m_pTextShell->ExecuteTextAttribute( _rReq );
    3931           0 : }
    3932             : 
    3933             : 
    3934           2 : void FmXFormShell::GetTextAttributeState( SfxItemSet& _rSet )
    3935             : {
    3936           2 :     m_pTextShell->GetTextAttributeState( _rSet );
    3937           2 : }
    3938             : 
    3939             : 
    3940       31036 : bool FmXFormShell::IsActiveControl( bool _bCountRichTextOnly ) const
    3941             : {
    3942       31036 :     return m_pTextShell->IsActiveControl( _bCountRichTextOnly );
    3943             : }
    3944             : 
    3945             : 
    3946         605 : void FmXFormShell::ForgetActiveControl()
    3947             : {
    3948         605 :     m_pTextShell->ForgetActiveControl();
    3949         605 : }
    3950             : 
    3951             : 
    3952        5660 : void FmXFormShell::SetControlActivationHandler( const Link& _rHdl )
    3953             : {
    3954        5660 :     m_pTextShell->SetControlActivationHandler( _rHdl );
    3955        5660 : }
    3956             : 
    3957           0 : void FmXFormShell::handleShowPropertiesRequest()
    3958             : {
    3959           0 :     if ( onlyControlsAreMarked() )
    3960           0 :         ShowSelectionProperties( true );
    3961           0 : }
    3962             : 
    3963             : 
    3964           0 : void FmXFormShell::handleMouseButtonDown( const SdrViewEvent& _rViewEvent )
    3965             : {
    3966             :     // catch simple double clicks
    3967           0 :     if ( ( _rViewEvent.nMouseClicks == 2 ) && ( _rViewEvent.nMouseCode == MOUSE_LEFT ) )
    3968             :     {
    3969           0 :         if ( _rViewEvent.eHit == SDRHIT_MARKEDOBJECT )
    3970             :         {
    3971           0 :             if ( onlyControlsAreMarked() )
    3972           0 :                 ShowSelectionProperties( true );
    3973             :         }
    3974             :     }
    3975           0 : }
    3976             : 
    3977             : 
    3978           0 : bool FmXFormShell::HasControlFocus() const
    3979             : {
    3980           0 :     bool bHasControlFocus = false;
    3981             : 
    3982             :     try
    3983             :     {
    3984           0 :         Reference< runtime::XFormController > xController( getActiveController() );
    3985           0 :         Reference< XControl > xCurrentControl;
    3986           0 :         if ( xController.is() )
    3987           0 :             xCurrentControl.set( xController->getCurrentControl() );
    3988           0 :         if ( xCurrentControl.is() )
    3989             :         {
    3990           0 :             Reference< XWindow2 > xPeerWindow( xCurrentControl->getPeer(), UNO_QUERY_THROW );
    3991           0 :             bHasControlFocus = xPeerWindow->hasFocus();
    3992           0 :         }
    3993             :     }
    3994           0 :     catch( const Exception& )
    3995             :     {
    3996             :         DBG_UNHANDLED_EXCEPTION();
    3997             :     }
    3998             : 
    3999           0 :     return bHasControlFocus;
    4000             : }
    4001             : 
    4002             : 
    4003             : 
    4004           0 : SearchableControlIterator::SearchableControlIterator(Reference< XInterface> xStartingPoint)
    4005           0 :     :IndexAccessIterator(xStartingPoint)
    4006             : {
    4007           0 : }
    4008             : 
    4009             : 
    4010           0 : bool SearchableControlIterator::ShouldHandleElement(const Reference< XInterface>& xElement)
    4011             : {
    4012             :     // wenn das Ding eine ControlSource und einen BoundField-Property hat
    4013           0 :     Reference< XPropertySet> xProperties(xElement, UNO_QUERY);
    4014           0 :     if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xProperties) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xProperties))
    4015             :     {
    4016             :         // und das BoundField gueltig ist
    4017           0 :         Reference< XPropertySet> xField;
    4018           0 :         xProperties->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField;
    4019           0 :         if (xField.is())
    4020             :         {
    4021             :             // nehmen wir's
    4022           0 :             m_sCurrentValue = ::comphelper::getString(xProperties->getPropertyValue(FM_PROP_CONTROLSOURCE));
    4023           0 :             return true;
    4024           0 :         }
    4025             :     }
    4026             : 
    4027             :     // wenn es ein Grid-Control ist
    4028           0 :     if (::comphelper::hasProperty(FM_PROP_CLASSID, xProperties))
    4029             :     {
    4030           0 :         Any aClassId( xProperties->getPropertyValue(FM_PROP_CLASSID) );
    4031           0 :         if (::comphelper::getINT16(aClassId) == FormComponentType::GRIDCONTROL)
    4032             :         {
    4033           0 :             m_sCurrentValue = "";
    4034           0 :             return true;
    4035           0 :         }
    4036             :     }
    4037             : 
    4038           0 :     return false;
    4039             : }
    4040             : 
    4041             : 
    4042           0 : bool SearchableControlIterator::ShouldStepInto(const Reference< XInterface>& /*xContainer*/) const
    4043             : {
    4044           0 :     return true;
    4045             : }
    4046             : 
    4047             : 
    4048             : 
    4049             : 
    4050         170 : SFX_IMPL_MENU_CONTROL(ControlConversionMenuController, SfxBoolItem);
    4051             : 
    4052             : 
    4053           0 : ControlConversionMenuController::ControlConversionMenuController( sal_uInt16 _nId, Menu& _rMenu, SfxBindings& _rBindings )
    4054             :     :SfxMenuControl( _nId, _rBindings )
    4055             :     ,m_pMainMenu( &_rMenu )
    4056           0 :     ,m_pConversionMenu( NULL )
    4057             : {
    4058           0 :     if ( _nId == SID_FM_CHANGECONTROLTYPE )
    4059             :     {
    4060           0 :         m_pConversionMenu = FmXFormShell::GetConversionMenu();
    4061           0 :         _rMenu.SetPopupMenu( _nId, m_pConversionMenu );
    4062             : 
    4063           0 :         for (sal_Int16 i=0; i<m_pConversionMenu->GetItemCount(); ++i)
    4064             :         {
    4065           0 :             _rBindings.Invalidate(m_pConversionMenu->GetItemId(i));
    4066           0 :             SfxStatusForwarder* pForwarder = new SfxStatusForwarder(m_pConversionMenu->GetItemId(i), *this);
    4067           0 :             m_aStatusForwarders.push_back(pForwarder);
    4068             :         }
    4069             :     }
    4070           0 : }
    4071             : 
    4072             : 
    4073           0 : ControlConversionMenuController::~ControlConversionMenuController()
    4074             : {
    4075           0 :     m_pMainMenu->SetPopupMenu(SID_FM_CHANGECONTROLTYPE, NULL);
    4076           0 :     delete m_pConversionMenu;
    4077           0 : }
    4078             : 
    4079             : 
    4080           0 : void ControlConversionMenuController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
    4081             : {
    4082           0 :     if (nSID == GetId())
    4083           0 :         SfxMenuControl::StateChanged(nSID, eState, pState);
    4084           0 :     else if (FmXFormShell::isControlConversionSlot(nSID))
    4085             :     {
    4086           0 :         if ((m_pConversionMenu->GetItemPos(nSID) != MENU_ITEM_NOTFOUND) && (eState == SfxItemState::DISABLED))
    4087             :         {
    4088           0 :             m_pConversionMenu->RemoveItem(m_pConversionMenu->GetItemPos(nSID));
    4089             :         }
    4090           0 :         else if ((m_pConversionMenu->GetItemPos(nSID) == MENU_ITEM_NOTFOUND) && (eState != SfxItemState::DISABLED))
    4091             :         {
    4092             :             // We can't simply re-insert the item because we have a clear order for all the our items.
    4093             :             // So first we have to determine the position of the item to insert.
    4094           0 :             boost::scoped_ptr<PopupMenu> pSource(FmXFormShell::GetConversionMenu());
    4095           0 :             sal_uInt16 nSourcePos = pSource->GetItemPos(nSID);
    4096             :             DBG_ASSERT(nSourcePos != MENU_ITEM_NOTFOUND, "ControlConversionMenuController::StateChanged : FmXFormShell supplied an invalid menu !");
    4097           0 :             sal_uInt16 nPrevInSource = nSourcePos;
    4098           0 :             sal_uInt16 nPrevInConversion = MENU_ITEM_NOTFOUND;
    4099           0 :             while (nPrevInSource>0)
    4100             :             {
    4101           0 :                 sal_Int16 nPrevId = pSource->GetItemId(--nPrevInSource);
    4102             : 
    4103             :                 // do we have the source's predecessor in our conversion menu, too ?
    4104           0 :                 nPrevInConversion = m_pConversionMenu->GetItemPos(nPrevId);
    4105           0 :                 if (nPrevInConversion != MENU_ITEM_NOTFOUND)
    4106           0 :                     break;
    4107             :             }
    4108           0 :             if (MENU_ITEM_NOTFOUND == nPrevInConversion)
    4109             :                 // none of the items which precede the nSID-slot in the source menu are present in our conversion menu
    4110           0 :                 nPrevInConversion = sal::static_int_cast< sal_uInt16 >(-1); // put the item at the first position
    4111           0 :             m_pConversionMenu->InsertItem(nSID, pSource->GetItemText(nSID),
    4112           0 :                 pSource->GetItemBits(nSID), OString(), ++nPrevInConversion);
    4113           0 :             m_pConversionMenu->SetItemImage(nSID, pSource->GetItemImage(nSID));
    4114           0 :             m_pConversionMenu->SetHelpId(nSID, pSource->GetHelpId(nSID));
    4115             :         }
    4116           0 :         m_pMainMenu->EnableItem(SID_FM_CHANGECONTROLTYPE, m_pConversionMenu->GetItemCount() > 0);
    4117             :     }
    4118             :     else
    4119             :     {
    4120             :         OSL_FAIL("ControlConversionMenuController::StateChanged : unknown id !");
    4121             :     }
    4122         651 : }
    4123             : 
    4124             : 
    4125             : 
    4126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10