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

Generated by: LCOV version 1.10