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

Generated by: LCOV version 1.10