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

Generated by: LCOV version 1.10