xref: /trunk/main/svx/source/form/fmshell.cxx (revision 527198e9106bdcc46565a309bc94ab031dcdd2a2)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_svx.hxx"
24 #include "fmvwimp.hxx"
25 #include <svx/fmshell.hxx>
26 #include "svx/fmtools.hxx"
27 #include "fmservs.hxx"
28 #ifndef _SVX_FMPROP_HRC
29 #include "fmprop.hrc"
30 #endif
31 #include "fmpgeimp.hxx"
32 #include "fmitems.hxx"
33 #include "fmundo.hxx"
34 #include <vcl/waitobj.hxx>
35 #include <com/sun/star/form/XLoadable.hpp>
36 #include <com/sun/star/container/XNamed.hpp>
37 #ifndef _COM_SUN_STAR_SDDB_PRIVILEGE_HPP_
38 #include <com/sun/star/sdbcx/Privilege.hpp>
39 #endif
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/beans/XMultiPropertySet.hpp>
42 #include <com/sun/star/beans/XFastPropertySet.hpp>
43 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/container/XNameContainer.hpp>
46 #include <com/sun/star/awt/XTabControllerModel.hpp>
47 #include <sfx2/viewfrm.hxx>
48 #include <vcl/wrkwin.hxx>
49 #include <vcl/msgbox.hxx>
50 #include <svl/whiter.hxx>
51 #include <sfx2/app.hxx>
52 #include <svl/intitem.hxx>
53 #include <svl/visitem.hxx>
54 #include <unotools/moduleoptions.hxx>
55 #include <sfx2/objface.hxx>
56 #include <sfx2/request.hxx>
57 #include <sfx2/dispatch.hxx>
58 #include <sfx2/objsh.hxx>
59 #include <svx/svdobj.hxx>
60 #include <svx/fmpage.hxx>
61 #include "svx/svditer.hxx"
62 #include "fmobj.hxx"
63 
64 #ifndef _SVX_SVXIDS_HRC
65 #include <svx/svxids.hrc>
66 #endif
67 
68 #ifndef _SVX_FMRESIDS_HRC
69 #include "svx/fmresids.hrc"
70 #endif
71 #include "fmexch.hxx"
72 #include <svx/fmglob.hxx>
73 #include <svl/eitem.hxx>
74 #include <tools/shl.hxx>
75 #include <tools/diagnose_ex.h>
76 #include <svx/svdpage.hxx>
77 #include <svx/fmmodel.hxx>
78 #include <svx/dialmgr.hxx>
79 #include "fmshimp.hxx"
80 #include <svx/svdpagv.hxx>
81 #include <sfx2/objitem.hxx>
82 #include <sfx2/viewsh.hxx>
83 #include "fmexpl.hxx"
84 #include "formcontrolling.hxx"
85 #include <svl/numuno.hxx>
86 #include <connectivity/dbtools.hxx>
87 #include <comphelper/types.hxx>
88 #include <comphelper/processfactory.hxx>
89 #include "fmdocumentclassification.hxx"
90 #include "formtoolbars.hxx"
91 
92 #include <svx/svxdlg.hxx> //CHINA001
93 #include <svx/dialogs.hrc> //CHINA001
94 
95 #include "svx/sdrobjectfilter.hxx"
96 
97 #define HANDLE_SQL_ERRORS( action, successflag, context, message )          \
98     try                                                                     \
99     {                                                                       \
100         successflag = sal_False;                                            \
101         action;                                                             \
102         successflag = sal_True;                                             \
103     }                                                                       \
104     catch(::com::sun::star::sdbc::SQLException& e)                          \
105     {                                                                       \
106         ::com::sun::star::sdb::SQLContext eExtendedInfo =                   \
107         GetImpl()->prependContextInfo(e, Reference< XInterface > (), context, ::rtl::OUString());   \
108         displayException(eExtendedInfo);                                    \
109     }                                                                       \
110     catch(Exception&)                                                       \
111     {                                                                       \
112         DBG_ERROR(message);                                                 \
113     }                                                                       \
114 
115 #define DO_SAFE_WITH_ERROR( action, message ) try { action; } catch(Exception&) { DBG_ERROR(message); }
116 
117 #define FmFormShell
118 #include "svxslots.hxx"
119 
120 #ifndef _SVX_SVXIDS_HRC
121 #include <svx/svxids.hrc>
122 #endif
123 #include "tbxform.hxx"
124 #include <comphelper/property.hxx>
125 #include <com/sun/star/beans/PropertyValue.hpp>
126 
127 // wird für Invalidate verwendet -> mitpflegen
128 // aufsteigend sortieren !!!!!!
129 sal_uInt16 ControllerSlotMap[] =    // slots des Controllers
130 {
131     SID_FM_CONFIG,
132     SID_FM_PUSHBUTTON,
133     SID_FM_RADIOBUTTON,
134     SID_FM_CHECKBOX,
135     SID_FM_FIXEDTEXT,
136     SID_FM_GROUPBOX,
137     SID_FM_EDIT,
138     SID_FM_LISTBOX,
139     SID_FM_COMBOBOX,
140     SID_FM_DBGRID,
141     SID_FM_IMAGEBUTTON,
142     SID_FM_FILECONTROL,
143     SID_FM_NAVIGATIONBAR,
144     SID_FM_CTL_PROPERTIES,
145     SID_FM_PROPERTIES,
146     SID_FM_TAB_DIALOG,
147     SID_FM_ADD_FIELD,
148     SID_FM_DESIGN_MODE,
149     SID_FM_SHOW_FMEXPLORER,
150     SID_FM_SHOW_PROPERTIES,
151     SID_FM_FMEXPLORER_CONTROL,
152     SID_FM_DATEFIELD,
153     SID_FM_TIMEFIELD,
154     SID_FM_NUMERICFIELD,
155     SID_FM_CURRENCYFIELD,
156     SID_FM_PATTERNFIELD,
157     SID_FM_OPEN_READONLY,
158     SID_FM_IMAGECONTROL,
159     SID_FM_USE_WIZARDS,
160     SID_FM_FORMATTEDFIELD,
161     SID_FM_FILTER_NAVIGATOR,
162     SID_FM_AUTOCONTROLFOCUS,
163     SID_FM_SCROLLBAR,
164     SID_FM_SPINBUTTON,
165     SID_FM_SHOW_DATANAVIGATOR,
166     SID_FM_DATANAVIGATOR_CONTROL,
167 
168     0
169 };
170 
171 using namespace ::com::sun::star::uno;
172 using namespace ::com::sun::star::awt;
173 using namespace ::com::sun::star::sdbc;
174 using namespace ::com::sun::star::sdbcx;
175 using namespace ::com::sun::star::beans;
176 using namespace ::com::sun::star::form;
177 using namespace ::com::sun::star::form::runtime;
178 using namespace ::com::sun::star::frame;
179 using namespace ::svxform;
180 
181 //========================================================================
182 // class FmDesignModeChangedHint
183 //========================================================================
184 TYPEINIT1( FmDesignModeChangedHint, SfxHint );
185 
186 //------------------------------------------------------------------------
FmDesignModeChangedHint(sal_Bool bDesMode)187 FmDesignModeChangedHint::FmDesignModeChangedHint( sal_Bool bDesMode )
188     :m_bDesignMode( bDesMode )
189 {
190 }
191 
192 //------------------------------------------------------------------------
~FmDesignModeChangedHint()193 FmDesignModeChangedHint::~FmDesignModeChangedHint()
194 {
195 }
196 
197 //========================================================================
198 const sal_uInt32 FM_UI_FEATURE_SHOW_DATABASEBAR         = 0x00000001;
199 const sal_uInt32 FM_UI_FEATURE_SHOW_FIELD               = 0x00000002;
200 const sal_uInt32 FM_UI_FEATURE_SHOW_PROPERTIES          = 0x00000004;
201 const sal_uInt32 FM_UI_FEATURE_SHOW_EXPLORER            = 0x00000008;
202 const sal_uInt32 FM_UI_FEATURE_SHOW_FILTERBAR           = 0x00000010;
203 const sal_uInt32 FM_UI_FEATURE_SHOW_FILTERNAVIGATOR     = 0x00000020;
204 const sal_uInt32 FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR    = 0x00000040;
205 const sal_uInt32 FM_UI_FEATURE_TB_CONTROLS              = 0x00000080;
206 const sal_uInt32 FM_UI_FEATURE_TB_MORECONTROLS          = 0x00000100;
207 const sal_uInt32 FM_UI_FEATURE_TB_FORMDESIGN            = 0x00000200;
208 const sal_uInt32 FM_UI_FEATURE_SHOW_DATANAVIGATOR       = 0x00000400;
209 
SFX_IMPL_INTERFACE(FmFormShell,SfxShell,SVX_RES (RID_STR_FORMSHELL))210 SFX_IMPL_INTERFACE(FmFormShell, SfxShell, SVX_RES(RID_STR_FORMSHELL))
211 {
212     SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_NAVIGATION|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_READONLYDOC,
213         SVX_RES(RID_SVXTBX_FORM_NAVIGATION),
214         FM_UI_FEATURE_SHOW_DATABASEBAR );
215 
216     SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_NAVIGATION|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_READONLYDOC,
217         SVX_RES(RID_SVXTBX_FORM_FILTER),
218         FM_UI_FEATURE_SHOW_FILTERBAR );
219 
220     SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_READONLYDOC,
221         SVX_RES( RID_SVXTBX_TEXT_CONTROL_ATTRIBUTES ),
222         FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR );
223 
224     SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_FM_ADD_FIELD, FM_UI_FEATURE_SHOW_FIELD);
225     SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_FM_SHOW_PROPERTIES, FM_UI_FEATURE_SHOW_PROPERTIES);
226     SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_FM_SHOW_FMEXPLORER, FM_UI_FEATURE_SHOW_EXPLORER);
227     SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_FM_FILTER_NAVIGATOR, FM_UI_FEATURE_SHOW_FILTERNAVIGATOR);
228     SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_FM_SHOW_DATANAVIGATOR, FM_UI_FEATURE_SHOW_DATANAVIGATOR);
229 
230     SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD,
231         SVX_RES( RID_SVXTBX_CONTROLS ),
232         FM_UI_FEATURE_TB_CONTROLS );
233 
234     SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD,
235         SVX_RES( RID_SVXTBX_MORECONTROLS ),
236         FM_UI_FEATURE_TB_MORECONTROLS );
237 
238     SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD,
239         SVX_RES( RID_SVXTBX_FORMDESIGN ),
240         FM_UI_FEATURE_TB_FORMDESIGN );
241 }
242 
243 //========================================================================
TYPEINIT1(FmFormShell,SfxShell)244 TYPEINIT1(FmFormShell,SfxShell)
245 
246 //------------------------------------------------------------------------
247 FmFormShell::FmFormShell( SfxViewShell* _pParent, FmFormView* pView )
248             :SfxShell(_pParent)
249             ,m_pImpl(new FmXFormShell(*this, _pParent->GetViewFrame()))
250             ,m_pFormView( pView )
251             ,m_pFormModel( NULL )
252             ,m_pParentShell(_pParent)
253             ,m_nLastSlot( 0 )
254             ,m_bDesignMode( sal_True )
255             ,m_bHasForms(sal_False)
256 {
257     m_pImpl->acquire();
258     SetPool( &SFX_APP()->GetPool() );
259     SetName( String::CreateFromAscii( "Form" ) );
260 
261     SetView(m_pFormView);
262 }
263 
264 //------------------------------------------------------------------------
~FmFormShell()265 FmFormShell::~FmFormShell()
266 {
267     if ( m_pFormView )
268         SetView( NULL );
269 
270     m_pImpl->dispose();
271     m_pImpl->release();
272     m_pImpl = NULL;
273 }
274 
275 //------------------------------------------------------------------------
NotifyMarkListChanged(FmFormView * pWhichView)276 void FmFormShell::NotifyMarkListChanged(FmFormView* pWhichView)
277 {
278     FmNavViewMarksChanged aChangeNotification(pWhichView);
279     Broadcast(aChangeNotification);
280 }
281 
282 //------------------------------------------------------------------------
PrepareClose(sal_Bool bUI,sal_Bool)283 sal_uInt16 FmFormShell::PrepareClose(sal_Bool bUI, sal_Bool /*bForBrowsing*/)
284 {
285     if ( GetImpl()->didPrepareClose() )
286         // we already did a PrepareClose for the current modifications of the current form
287         // 2002-11-12 #104702# - fs@openoffice.org
288         return sal_True;
289 
290     sal_Bool bResult = sal_True;
291     // Save the data records, not in DesignMode and FilterMode
292     if (!m_bDesignMode && !GetImpl()->isInFilterMode() &&
293         m_pFormView && m_pFormView->GetActualOutDev() &&
294         m_pFormView->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW)
295     {
296         SdrPageView* pCurPageView = m_pFormView->GetSdrPageView();
297 
298         // sal_uInt16 nPos = pCurPageView ? pCurPageView->GetWinList().Find((OutputDevice*)m_pFormView->GetActualOutDev()) : SDRPAGEVIEWWIN_NOTFOUND;
299         SdrPageWindow* pWindow = pCurPageView ? pCurPageView->FindPageWindow(*((OutputDevice*)m_pFormView->GetActualOutDev())) : 0L;
300 
301         if(pWindow)
302         {
303             // Zunächst werden die aktuellen Inhalte der Controls gespeichert
304             // Wenn alles glatt gelaufen ist, werden die modifizierten Datensätze gespeichert
305             if ( GetImpl()->getActiveController().is() )
306             {
307                 const ::svx::ControllerFeatures& rController = GetImpl()->getActiveControllerFeatures();
308                 if ( rController->commitCurrentControl() )
309                 {
310                     sal_Bool bModified = rController->isModifiedRow();
311 
312                     if ( bModified && bUI )
313                     {
314                         QueryBox aQry(NULL, SVX_RES(RID_QRY_SAVEMODIFIED));
315                         switch (aQry.Execute())
316                         {
317                             case RET_NO:
318                                 bModified = sal_False;
319                                 GetImpl()->didPrepareClose( sal_True );
320                                 break;
321 
322                             case RET_CANCEL:
323                                 return sal_False;
324 
325                             case RET_NEWTASK:
326                                 return RET_NEWTASK;
327                         }
328 
329                             if ( bModified )
330                                 bResult = rController->commitCurrentRecord( );
331                     }
332                 }
333             }
334         }
335     }
336     return bResult;
337 }
338 
339 //------------------------------------------------------------------------
impl_setDesignMode(sal_Bool bDesign)340 void FmFormShell::impl_setDesignMode(sal_Bool bDesign)
341 {
342     if (m_pFormView)
343     {
344         if (!bDesign)
345             m_nLastSlot = SID_FM_DESIGN_MODE;
346 
347         GetImpl()->SetDesignMode(bDesign);
348         // mein m_bDesignMode wird auch von der Impl gesetzt ...
349     }
350     else
351     {
352         m_bHasForms = sal_False;
353         m_bDesignMode = bDesign;
354         UIFeatureChanged();
355     }
356 
357     GetViewShell()->GetViewFrame()->GetBindings().Invalidate(ControllerSlotMap);
358 }
359 
360 //------------------------------------------------------------------------
HasUIFeature(sal_uInt32 nFeature)361 sal_Bool FmFormShell::HasUIFeature( sal_uInt32 nFeature )
362 {
363     sal_Bool bResult = sal_False;
364     if ((nFeature & FM_UI_FEATURE_SHOW_DATABASEBAR) == FM_UI_FEATURE_SHOW_DATABASEBAR)
365     {
366         // nur wenn auch Formulare verfügbar
367         bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar() && !GetImpl()->isInFilterMode();
368     }
369     else if ((nFeature & FM_UI_FEATURE_SHOW_FILTERBAR) == FM_UI_FEATURE_SHOW_FILTERBAR)
370     {
371         // nur wenn auch Formulare verfügbar
372         bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar() && GetImpl()->isInFilterMode();
373     }
374     else if ((nFeature & FM_UI_FEATURE_SHOW_FILTERNAVIGATOR) == FM_UI_FEATURE_SHOW_FILTERNAVIGATOR)
375     {
376         bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar() && GetImpl()->isInFilterMode();
377     }
378     else if ((nFeature & FM_UI_FEATURE_SHOW_FIELD) == FM_UI_FEATURE_SHOW_FIELD)
379     {
380         bResult = m_bDesignMode && m_pFormView && m_bHasForms;
381     }
382     else if ((nFeature & FM_UI_FEATURE_SHOW_PROPERTIES) == FM_UI_FEATURE_SHOW_PROPERTIES)
383     {
384         bResult = m_bDesignMode && m_pFormView && m_bHasForms;
385     }
386     else if ((nFeature & FM_UI_FEATURE_SHOW_EXPLORER) == FM_UI_FEATURE_SHOW_EXPLORER)
387     {
388         bResult = m_bDesignMode; // OJ #101593# && m_pFormView && m_bHasForms;
389     }
390     else if ( ( nFeature & FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR ) == FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR )
391     {
392         bResult = !GetImpl()->IsReadonlyDoc() && m_pImpl->IsActiveControl( true );
393     }
394     else if ((nFeature & FM_UI_FEATURE_SHOW_DATANAVIGATOR) == FM_UI_FEATURE_SHOW_DATANAVIGATOR)
395     {
396         bResult = GetImpl()->isEnhancedForm();
397     }
398     else if (  ( ( nFeature & FM_UI_FEATURE_TB_CONTROLS ) == FM_UI_FEATURE_TB_CONTROLS )
399             || ( ( nFeature & FM_UI_FEATURE_TB_MORECONTROLS ) == FM_UI_FEATURE_TB_MORECONTROLS )
400             || ( ( nFeature & FM_UI_FEATURE_TB_FORMDESIGN ) == FM_UI_FEATURE_TB_FORMDESIGN )
401             )
402     {
403         bResult = sal_True;
404     }
405 
406     return bResult;
407 }
408 
409 //------------------------------------------------------------------------
Execute(SfxRequest & rReq)410 void FmFormShell::Execute(SfxRequest &rReq)
411 {
412     sal_uInt16 nSlot = rReq.GetSlot();
413 
414     //////////////////////////////////////////////////////////////////////
415     // MasterSlot setzen
416     switch( nSlot )
417     {
418         case SID_FM_PUSHBUTTON:
419         case SID_FM_RADIOBUTTON:
420         case SID_FM_CHECKBOX:
421         case SID_FM_FIXEDTEXT:
422         case SID_FM_GROUPBOX:
423         case SID_FM_LISTBOX:
424         case SID_FM_COMBOBOX:
425         case SID_FM_NAVIGATIONBAR:
426         case SID_FM_EDIT:
427         case SID_FM_DBGRID:
428         case SID_FM_IMAGEBUTTON:
429         case SID_FM_IMAGECONTROL:
430         case SID_FM_FILECONTROL:
431         case SID_FM_DATEFIELD:
432         case SID_FM_TIMEFIELD:
433         case SID_FM_NUMERICFIELD:
434         case SID_FM_CURRENCYFIELD:
435         case SID_FM_PATTERNFIELD:
436         case SID_FM_FORMATTEDFIELD:
437         case SID_FM_SCROLLBAR:
438         case SID_FM_SPINBUTTON:
439             m_nLastSlot = nSlot;
440             GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SID_FM_CONFIG );
441             break;
442     }
443 
444     //////////////////////////////////////////////////////////////////////
445     // Identifier und Inventor des Uno-Controls setzen
446     sal_uInt16 nIdentifier = 0;
447     switch( nSlot )
448     {
449         case SID_FM_CHECKBOX:
450             nIdentifier = OBJ_FM_CHECKBOX;
451             break;
452         case SID_FM_PUSHBUTTON:
453             nIdentifier = OBJ_FM_BUTTON;
454             break;
455         case SID_FM_FIXEDTEXT:
456             nIdentifier = OBJ_FM_FIXEDTEXT;
457             break;
458         case SID_FM_LISTBOX:
459             nIdentifier = OBJ_FM_LISTBOX;
460             break;
461         case SID_FM_EDIT:
462             nIdentifier = OBJ_FM_EDIT;
463             break;
464         case SID_FM_RADIOBUTTON:
465             nIdentifier = OBJ_FM_RADIOBUTTON;
466             break;
467         case SID_FM_GROUPBOX:
468             nIdentifier = OBJ_FM_GROUPBOX;
469             break;
470         case SID_FM_COMBOBOX:
471             nIdentifier = OBJ_FM_COMBOBOX;
472             break;
473         case SID_FM_NAVIGATIONBAR:
474             nIdentifier = OBJ_FM_NAVIGATIONBAR;
475             break;
476         case SID_FM_DBGRID:
477             nIdentifier = OBJ_FM_GRID;
478             break;
479         case SID_FM_IMAGEBUTTON:
480             nIdentifier = OBJ_FM_IMAGEBUTTON;
481             break;
482         case SID_FM_IMAGECONTROL:
483             nIdentifier = OBJ_FM_IMAGECONTROL;
484             break;
485         case SID_FM_FILECONTROL:
486             nIdentifier = OBJ_FM_FILECONTROL;
487             break;
488         case SID_FM_DATEFIELD:
489             nIdentifier = OBJ_FM_DATEFIELD;
490             break;
491         case SID_FM_TIMEFIELD:
492             nIdentifier = OBJ_FM_TIMEFIELD;
493             break;
494         case SID_FM_NUMERICFIELD:
495             nIdentifier = OBJ_FM_NUMERICFIELD;
496             break;
497         case SID_FM_CURRENCYFIELD:
498             nIdentifier = OBJ_FM_CURRENCYFIELD;
499             break;
500         case SID_FM_PATTERNFIELD:
501             nIdentifier = OBJ_FM_PATTERNFIELD;
502             break;
503         case SID_FM_FORMATTEDFIELD:
504             nIdentifier = OBJ_FM_FORMATTEDFIELD;
505             break;
506         case SID_FM_SCROLLBAR:
507             nIdentifier = OBJ_FM_SCROLLBAR;
508             break;
509         case SID_FM_SPINBUTTON:
510             nIdentifier = OBJ_FM_SPINBUTTON;
511             break;
512     }
513 
514     switch ( nSlot )
515     {
516         case SID_FM_CHECKBOX:
517         case SID_FM_PUSHBUTTON:
518         case SID_FM_FIXEDTEXT:
519         case SID_FM_LISTBOX:
520         case SID_FM_EDIT:
521         case SID_FM_RADIOBUTTON:
522         case SID_FM_COMBOBOX:
523         case SID_FM_NAVIGATIONBAR:
524         case SID_FM_GROUPBOX:
525         case SID_FM_DBGRID:
526         case SID_FM_IMAGEBUTTON:
527         case SID_FM_IMAGECONTROL:
528         case SID_FM_FILECONTROL:
529         case SID_FM_DATEFIELD:
530         case SID_FM_TIMEFIELD:
531         case SID_FM_NUMERICFIELD:
532         case SID_FM_CURRENCYFIELD:
533         case SID_FM_PATTERNFIELD:
534         case SID_FM_FORMATTEDFIELD:
535         case SID_FM_SCROLLBAR:
536         case SID_FM_SPINBUTTON:
537         {
538             SFX_REQUEST_ARG( rReq, pGrabFocusItem, SfxBoolItem, SID_FM_TOGGLECONTROLFOCUS, sal_False );
539             if ( pGrabFocusItem && pGrabFocusItem->GetValue() )
540             {   // see below
541                 SfxViewShell* pShell = GetViewShell();
542                 Window* pShellWnd = pShell ? pShell->GetWindow() : NULL;
543                 if ( pShellWnd )
544                     pShellWnd->GrabFocus();
545                 break;
546             }
547 
548             SfxUInt16Item aIdentifierItem( SID_FM_CONTROL_IDENTIFIER, nIdentifier );
549             SfxUInt32Item aInventorItem( SID_FM_CONTROL_INVENTOR, FmFormInventor );
550             const SfxPoolItem* pArgs[] =
551             {
552                 &aIdentifierItem, &aInventorItem, NULL
553             };
554             const SfxPoolItem* pInternalArgs[] =
555             {
556                 NULL
557             };
558 
559             GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_CREATE_CONTROL, SFX_CALLMODE_ASYNCHRON,
560                                       pArgs, rReq.GetModifier(), pInternalArgs );
561 
562             if ( rReq.GetModifier() & KEY_MOD1 )
563             {
564                 //  #99013# if selected with control key, return focus to current view
565                 // do this asynchron, so that the creation can be finished first
566                 // reusing the SID_FM_TOGGLECONTROLFOCUS is somewhat hacky ... which it wouldn't if it would have another
567                 // name, so I do not really have a big problem with this ....
568                 SfxBoolItem aGrabFocusIndicatorItem( SID_FM_TOGGLECONTROLFOCUS, sal_True );
569                 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( nSlot, SFX_CALLMODE_ASYNCHRON,
570                                           &aGrabFocusIndicatorItem, NULL );
571             }
572 
573             rReq.Done();
574         }   break;
575     }
576 
577     // Individuelle Aktionen
578     switch( nSlot )
579     {
580         case SID_FM_MORE_CONTROLS:
581         case SID_FM_FORM_DESIGN_TOOLS:
582         {
583             FormToolboxes aToolboxAccess( GetImpl()->getHostFrame() );
584             aToolboxAccess.toggleToolbox( nSlot );
585             rReq.Done();
586         }
587         break;
588 
589         case SID_FM_TOGGLECONTROLFOCUS:
590         {
591             FmFormView* pFormView = GetFormView();
592             if ( !pFormView )
593                 break;
594 
595             // if we execute this ourself, then either the application does not implement an own handling for this,
596             // of we're on the top of the dispatcher stack, which means a control has the focus.
597             // In the latter case, we put the focus to the document window, otherwise, we focus the first control
598             const bool bHasControlFocus = GetImpl()->HasControlFocus();
599             if ( bHasControlFocus )
600             {
601                 const OutputDevice* pDevice = GetCurrentViewDevice();
602                 Window* pWindow = dynamic_cast< Window* >( const_cast< OutputDevice* >( pDevice ) );
603                 if ( pWindow )
604                     pWindow->GrabFocus();
605             }
606             else
607             {
608                 pFormView->GrabFirstControlFocus( );
609             }
610         }
611         break;
612 
613         case SID_FM_VIEW_AS_GRID:
614             GetImpl()->CreateExternalView();
615             break;
616         case SID_FM_CONVERTTO_EDIT          :
617         case SID_FM_CONVERTTO_BUTTON        :
618         case SID_FM_CONVERTTO_FIXEDTEXT     :
619         case SID_FM_CONVERTTO_LISTBOX       :
620         case SID_FM_CONVERTTO_CHECKBOX      :
621         case SID_FM_CONVERTTO_RADIOBUTTON   :
622         case SID_FM_CONVERTTO_GROUPBOX      :
623         case SID_FM_CONVERTTO_COMBOBOX      :
624         case SID_FM_CONVERTTO_IMAGEBUTTON   :
625         case SID_FM_CONVERTTO_FILECONTROL   :
626         case SID_FM_CONVERTTO_DATE          :
627         case SID_FM_CONVERTTO_TIME          :
628         case SID_FM_CONVERTTO_NUMERIC       :
629         case SID_FM_CONVERTTO_CURRENCY      :
630         case SID_FM_CONVERTTO_PATTERN       :
631         case SID_FM_CONVERTTO_IMAGECONTROL  :
632         case SID_FM_CONVERTTO_FORMATTED     :
633         case SID_FM_CONVERTTO_SCROLLBAR     :
634         case SID_FM_CONVERTTO_SPINBUTTON    :
635         case SID_FM_CONVERTTO_NAVIGATIONBAR :
636             GetImpl()->executeControlConversionSlot( nSlot );
637             // nach dem Konvertieren die Selektion neu bestimmen, da sich ja das selektierte Objekt
638             // geändert hat
639             GetImpl()->SetSelection(GetFormView()->GetMarkedObjectList());
640             break;
641         case SID_FM_LEAVE_CREATE:
642             m_nLastSlot = 0;
643             GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SID_FM_CONFIG );
644             rReq.Done();
645             break;
646         case SID_FM_SHOW_PROPERTY_BROWSER:
647         {
648             SFX_REQUEST_ARG( rReq, pShowItem, SfxBoolItem, SID_FM_SHOW_PROPERTIES, sal_False );
649             sal_Bool bShow = sal_True;
650             if ( pShowItem )
651                 bShow = pShowItem->GetValue();
652             GetImpl()->ShowSelectionProperties( bShow );
653 
654             rReq.Done();
655         } break;
656 
657         case SID_FM_PROPERTIES:
658         {
659             // show PropertyBrowser
660             SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSlot, sal_False);
661             sal_Bool bShow = pShowItem ? pShowItem->GetValue() : sal_True;
662 
663             InterfaceBag aOnlyTheForm;
664             aOnlyTheForm.insert( Reference< XInterface >( GetImpl()->getCurrentForm(), UNO_QUERY ) );
665             GetImpl()->setCurrentSelection( aOnlyTheForm );
666 
667             GetImpl()->ShowSelectionProperties( bShow );
668 
669             rReq.Done();
670         }   break;
671 
672         case SID_FM_CTL_PROPERTIES:
673         {
674             SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSlot, sal_False);
675             sal_Bool bShow = pShowItem ? pShowItem->GetValue() : sal_True;
676 
677             OSL_ENSURE( GetImpl()->onlyControlsAreMarked(), "FmFormShell::Execute: ControlProperties should be disabled!" );
678             if ( bShow )
679                 GetImpl()->selectLastMarkedControls();
680             GetImpl()->ShowSelectionProperties( bShow );
681 
682             rReq.Done();
683         }   break;
684         case SID_FM_SHOW_PROPERTIES:
685         case SID_FM_ADD_FIELD:
686         case SID_FM_FILTER_NAVIGATOR:
687         case SID_FM_SHOW_DATANAVIGATOR :
688         {
689             GetViewShell()->GetViewFrame()->ChildWindowExecute( rReq );
690             rReq.Done();
691         }   break;
692         case SID_FM_SHOW_FMEXPLORER:
693         {
694             if (!m_pFormView)   // setzen der ::com::sun::star::sdbcx::View Forcieren
695                 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute(SID_CREATE_SW_DRAWVIEW);
696 
697             GetViewShell()->GetViewFrame()->ChildWindowExecute(rReq);
698             rReq.Done();
699         }
700         break;
701 
702         case SID_FM_TAB_DIALOG:
703         {
704             GetImpl()->ExecuteTabOrderDialog( Reference< XTabControllerModel >( GetImpl()->getCurrentForm(), UNO_QUERY ) );
705             rReq.Done();
706         }
707         break;
708 
709         case SID_FM_DESIGN_MODE:
710         {
711             SFX_REQUEST_ARG(rReq, pDesignItem, SfxBoolItem, nSlot, sal_False);
712             sal_Bool bDesignMode = pDesignItem ? pDesignItem->GetValue() : !m_bDesignMode;
713             SetDesignMode( bDesignMode );
714             if ( m_bDesignMode == bDesignMode )
715                 rReq.Done();
716 
717             m_nLastSlot = SID_FM_DESIGN_MODE;
718             GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SID_FM_CONFIG );
719         }
720         break;
721 
722         case SID_FM_AUTOCONTROLFOCUS:
723         {
724             FmFormModel* pModel = GetFormModel();
725             DBG_ASSERT(pModel, "FmFormShell::Execute : invalid call !");
726                 // should have been disabled in GetState if we don't have a FormModel
727             pModel->SetAutoControlFocus( !pModel->GetAutoControlFocus() );
728             GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_AUTOCONTROLFOCUS);
729         }
730         break;
731         case SID_FM_OPEN_READONLY:
732         {
733             FmFormModel* pModel = GetFormModel();
734             DBG_ASSERT(pModel, "FmFormShell::Execute : invalid call !");
735                 // should have been disabled in GetState if we don't have a FormModel
736             pModel->SetOpenInDesignMode( !pModel->GetOpenInDesignMode() );
737             GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_OPEN_READONLY);
738         }
739         break;
740         case SID_FM_USE_WIZARDS:
741         {
742             GetImpl()->SetWizardUsing(!GetImpl()->GetWizardUsing());
743             GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_USE_WIZARDS);
744         }
745         break;
746         case SID_FM_SEARCH:
747         {
748             const ::svx::ControllerFeatures& rController = GetImpl()->getActiveControllerFeatures();
749             if ( rController->commitCurrentControl() && rController->commitCurrentRecord() )
750                 GetImpl()->ExecuteSearch();
751             rReq.Done();
752         }
753         break;
754 
755         case SID_FM_RECORD_FIRST:
756         case SID_FM_RECORD_PREV:
757         case SID_FM_RECORD_NEXT:
758         case SID_FM_RECORD_LAST:
759         case SID_FM_RECORD_NEW:
760         case SID_FM_REFRESH:
761         case SID_FM_REFRESH_FORM_CONTROL:
762         case SID_FM_RECORD_DELETE:
763         case SID_FM_RECORD_UNDO:
764         case SID_FM_RECORD_SAVE:
765         case SID_FM_REMOVE_FILTER_SORT:
766         case SID_FM_SORTDOWN:
767         case SID_FM_SORTUP:
768         case SID_FM_AUTOFILTER:
769         case SID_FM_ORDERCRIT:
770         case SID_FM_FORM_FILTERED:
771         {
772             GetImpl()->ExecuteFormSlot( nSlot );
773             rReq.Done();
774         }
775         break;
776 
777         case SID_FM_RECORD_ABSOLUTE:
778         {
779             const ::svx::ControllerFeatures& rController = GetImpl()->getNavControllerFeatures();
780             sal_Int32 nRecord = -1;
781 
782             const SfxItemSet* pArgs = rReq.GetArgs();
783             if ( pArgs )
784             {
785                 const SfxPoolItem* pItem;
786                 if ( ( pArgs->GetItemState( FN_PARAM_1, sal_True, &pItem ) ) == SFX_ITEM_SET )
787                 {
788                     const SfxInt32Item* pTypedItem = PTR_CAST( SfxInt32Item, pItem );
789                     if ( pTypedItem )
790                         nRecord = Max( pTypedItem->GetValue(), sal_Int32(0) );
791                 }
792             }
793             else
794             {
795                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
796                 DBG_ASSERT( pFact, "no dialog factory!" );
797                 if ( pFact )
798                 {
799                     ::std::auto_ptr< AbstractFmInputRecordNoDialog > dlg( pFact->CreateFmInputRecordNoDialog( NULL ) );
800                     DBG_ASSERT( dlg.get(), "Dialogdiet fail!" );
801                     dlg->SetValue( rController->getCursor()->getRow() );
802                     if ( dlg->Execute() == RET_OK )
803                         nRecord = dlg->GetValue();
804 
805                     rReq.AppendItem( SfxInt32Item( FN_PARAM_1, nRecord ) );
806                 }
807             }
808 
809             if ( nRecord != -1 )
810                 rController->execute( nSlot, ::rtl::OUString::createFromAscii( "Position" ), makeAny( (sal_Int32)nRecord ) );
811 
812             rReq.Done();
813         }   break;
814         case SID_FM_FILTER_EXECUTE:
815         case SID_FM_FILTER_EXIT:
816         {
817             sal_Bool bCancelled = ( SID_FM_FILTER_EXIT == nSlot );
818             sal_Bool bReopenNavigator = sal_False;
819 
820             if ( !bCancelled )
821             {
822                 // if the filter navigator is still open, we need to close it, so it can possibly
823                 // commit its most recent changes
824                 if ( GetViewShell() && GetViewShell()->GetViewFrame() )
825                     if ( GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_FILTER_NAVIGATOR ) )
826                     {
827                         GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
828                         bReopenNavigator = sal_True;
829                     }
830 
831                 Reference< runtime::XFormController >  xController( GetImpl()->getActiveController() );
832 
833                 if  (   GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_FILTER_NAVIGATOR )
834                         // closing the window was denied, for instance because of a invalid criterion
835 
836                     ||  (   xController.is()
837                         &&  !GetImpl()->getActiveControllerFeatures()->commitCurrentControl( )
838                         )
839                         // committing the controller was denied
840                     )
841                 {
842                     rReq.Done();
843                     break;
844                 }
845             }
846 
847             GetImpl()->stopFiltering( !bCancelled );
848             rReq.Done();
849 
850             if ( bReopenNavigator )
851                 // we closed the navigator only to implicitly commit it (as we do not have another
852                 // direct wire to it), but to the user, it should look it it was always open
853                 GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
854         }
855         break;
856 
857         case SID_FM_FILTER_START:
858         {
859             GetImpl()->startFiltering();
860             rReq.Done();
861 
862             // initially open the filter navigator, the whole form based filter is pretty useless without it
863             SfxBoolItem aIdentifierItem( SID_FM_FILTER_NAVIGATOR, sal_True );
864             GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_FILTER_NAVIGATOR, SFX_CALLMODE_ASYNCHRON,
865                 &aIdentifierItem, NULL );
866         }   break;
867     }
868 }
869 
870 //------------------------------------------------------------------------
GetState(SfxItemSet & rSet)871 void FmFormShell::GetState(SfxItemSet &rSet)
872 {
873     SfxWhichIter aIter( rSet );
874     sal_uInt16 nWhich = aIter.FirstWhich();
875     while ( nWhich )
876     {
877         switch( nWhich )
878         {
879             case SID_FM_MORE_CONTROLS:
880             case SID_FM_FORM_DESIGN_TOOLS:
881             {
882                 FormToolboxes aToolboxAccess( GetImpl()->getHostFrame() );
883                 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible( nWhich ) ) );
884             }
885             break;
886 
887             case SID_FM_FILTER_EXECUTE:
888             case SID_FM_FILTER_EXIT:
889                 if (!GetImpl()->isInFilterMode())
890                     rSet.DisableItem( nWhich );
891                 break;
892 
893             case SID_FM_USE_WIZARDS:
894                 if  ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
895                     rSet.Put( SfxVisibilityItem( nWhich, sal_False ) );
896                 else if (!GetFormModel())
897                     rSet.DisableItem( nWhich );
898                 else
899                     rSet.Put( SfxBoolItem(nWhich, GetImpl()->GetWizardUsing() ) );
900                 break;
901             case SID_FM_AUTOCONTROLFOCUS:
902                 if (!GetFormModel())
903                     rSet.DisableItem( nWhich );
904                 else
905                     rSet.Put( SfxBoolItem(nWhich, GetFormModel()->GetAutoControlFocus() ) );
906                 break;
907             case SID_FM_OPEN_READONLY:
908                 if (!GetFormModel())
909                     rSet.DisableItem( nWhich );
910                 else
911                     rSet.Put( SfxBoolItem(nWhich, GetFormModel()->GetOpenInDesignMode() ) );
912                 break;
913 
914             case SID_FM_NAVIGATIONBAR:
915             case SID_FM_DBGRID:
916                 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
917                 {
918                     rSet.Put( SfxVisibilityItem( nWhich, sal_False ) );
919                     break;
920                 }
921                 // NO break!
922 
923             case SID_FM_SCROLLBAR:
924             case SID_FM_IMAGECONTROL:
925             case SID_FM_FILECONTROL:
926             case SID_FM_CURRENCYFIELD:
927             case SID_FM_PATTERNFIELD:
928             case SID_FM_IMAGEBUTTON:
929             case SID_FM_RADIOBUTTON:
930             case SID_FM_COMBOBOX:
931             case SID_FM_GROUPBOX:
932             case SID_FM_CHECKBOX:
933             case SID_FM_PUSHBUTTON:
934             case SID_FM_FIXEDTEXT:
935             case SID_FM_LISTBOX:
936             case SID_FM_EDIT:
937             case SID_FM_DATEFIELD:
938             case SID_FM_TIMEFIELD:
939             case SID_FM_NUMERICFIELD:
940             case SID_FM_FORMATTEDFIELD:
941             case SID_FM_SPINBUTTON:
942                 if (!m_bDesignMode)
943                     rSet.DisableItem( nWhich );
944                 else
945                 {
946                     sal_Bool bLayerLocked = sal_False;
947                     if (m_pFormView)
948                     {
949                         // Ist der ::com::sun::star::drawing::Layer gelocked, so müssen die Slots disabled werden. #36897
950                         SdrPageView* pPV = m_pFormView->GetSdrPageView();
951                         if (pPV != NULL)
952                             bLayerLocked = pPV->IsLayerLocked(m_pFormView->GetActiveLayer());
953                     }
954                     if (bLayerLocked)
955                         rSet.DisableItem( nWhich );
956                     else
957                         rSet.Put( SfxBoolItem(nWhich, (nWhich==m_nLastSlot)) );
958                 }
959                 break;
960             case SID_FM_FILTER_NAVIGATOR_CONTROL:
961             {
962                 if (GetImpl()->isInFilterMode())
963                     rSet.Put(SfxObjectItem(nWhich, this));
964                 else
965                     rSet.Put(SfxObjectItem(nWhich));
966             }   break;
967             case SID_FM_FIELDS_CONTROL:
968             case SID_FM_PROPERTY_CONTROL:
969             {
970                 if (!m_bDesignMode || !m_pFormView || !m_bHasForms)
971                     rSet.Put(SfxObjectItem(nWhich));
972                 else
973                     rSet.Put(SfxObjectItem(nWhich, this));
974 
975             }   break;
976             case SID_FM_FMEXPLORER_CONTROL:
977             case SID_FM_DATANAVIGATOR_CONTROL :
978             {
979                 if (!m_bDesignMode || !m_pFormView)
980                     rSet.Put(SfxObjectItem(nWhich));
981                 else
982                     rSet.Put(SfxObjectItem(nWhich, this));
983 
984             }   break;
985             case SID_FM_ADD_FIELD:
986             case SID_FM_SHOW_FMEXPLORER:
987             case SID_FM_SHOW_PROPERTIES:
988             case SID_FM_FILTER_NAVIGATOR:
989             case SID_FM_SHOW_DATANAVIGATOR:
990             {
991                 if ( GetViewShell()->GetViewFrame()->KnowsChildWindow(nWhich) )
992                     rSet.Put( SfxBoolItem( nWhich, GetViewShell()->GetViewFrame()->HasChildWindow(nWhich)) );
993                 else
994                     rSet.DisableItem(nWhich);
995             }   break;
996 
997             case SID_FM_SHOW_PROPERTY_BROWSER:
998             {
999                 rSet.Put(SfxBoolItem(GetImpl()->IsPropBrwOpen()));
1000             }
1001             break;
1002 
1003             case SID_FM_CTL_PROPERTIES:
1004             {
1005                 // der Impl eventuell die Möglichjkeit geben, ihre an der aktuellen MarkList ausgerichteten Objekte
1006                 // auf den neuesten Stand zu bringen
1007                 if (GetImpl()->IsSelectionUpdatePending())
1008                     GetImpl()->ForceUpdateSelection(sal_False);
1009 
1010                 if ( !m_pFormView || !m_bDesignMode || !GetImpl()->onlyControlsAreMarked() )
1011                     rSet.DisableItem( nWhich );
1012                 else
1013                 {
1014                     sal_Bool bChecked  = GetImpl()->IsPropBrwOpen() && !GetImpl()->isSolelySelected( GetImpl()->getCurrentForm() );
1015                         // if the property browser is open, and only controls are marked, and the current selection
1016                         // does not consist of only the current form, then the current selection is the (composition of)
1017                         // the currently marked controls
1018                     rSet.Put( SfxBoolItem( nWhich, bChecked ) );
1019                 }
1020             }   break;
1021 
1022             case SID_FM_PROPERTIES:
1023             {
1024                 // der Impl eventuell die Möglichkeit geben, ihre an der aktuellen MarkList ausgerichteten Objekte
1025                 // auf den neuesten Stand zu bringen
1026                 if (GetImpl()->IsSelectionUpdatePending())
1027                     GetImpl()->ForceUpdateSelection(sal_False);
1028 
1029                 if ( !m_pFormView || !m_bDesignMode || !GetImpl()->getCurrentForm().is() )
1030                     rSet.DisableItem( nWhich );
1031                 else
1032                 {
1033                     sal_Bool bChecked = GetImpl()->IsPropBrwOpen() && GetImpl()->isSolelySelected( GetImpl()->getCurrentForm() );
1034                     rSet.Put(SfxBoolItem(nWhich, bChecked));
1035                 }
1036             }   break;
1037             case SID_FM_TAB_DIALOG:
1038                 // der Impl eventuell die Möglichkeit geben, ihre an der aktuellen MarkList ausgerichteten Objekte
1039                 // auf den neuesten Stand zu bringen
1040                 if (GetImpl()->IsSelectionUpdatePending())
1041                     GetImpl()->ForceUpdateSelection(sal_False);
1042 
1043                 if (!m_pFormView || !m_bDesignMode || !GetImpl()->getCurrentForm().is() )
1044                     rSet.DisableItem( nWhich );
1045                 break;
1046             case SID_FM_CONFIG:
1047                 rSet.Put(SfxUInt16Item(nWhich, m_nLastSlot));
1048                 break;
1049             case SID_FM_DESIGN_MODE:
1050                 if (!m_pFormView || GetImpl()->IsReadonlyDoc() )
1051                     rSet.DisableItem( nWhich );
1052                 else
1053                     rSet.Put( SfxBoolItem(nWhich, m_bDesignMode) );
1054                 break;
1055             case SID_FM_SEARCH:
1056             case SID_FM_RECORD_FIRST:
1057             case SID_FM_RECORD_NEXT:
1058             case SID_FM_RECORD_PREV:
1059             case SID_FM_RECORD_LAST:
1060             case SID_FM_RECORD_NEW:
1061             case SID_FM_RECORD_DELETE:
1062             case SID_FM_RECORD_ABSOLUTE:
1063             case SID_FM_RECORD_TOTAL:
1064             case SID_FM_RECORD_SAVE:
1065             case SID_FM_RECORD_UNDO:
1066             case SID_FM_FORM_FILTERED:
1067             case SID_FM_REMOVE_FILTER_SORT:
1068             case SID_FM_SORTUP:
1069             case SID_FM_SORTDOWN:
1070             case SID_FM_ORDERCRIT:
1071             case SID_FM_FILTER_START:
1072             case SID_FM_AUTOFILTER:
1073             case SID_FM_REFRESH:
1074             case SID_FM_REFRESH_FORM_CONTROL:
1075             case SID_FM_VIEW_AS_GRID:
1076                 GetFormState(rSet,nWhich);
1077                 break;
1078 
1079             case SID_FM_CHANGECONTROLTYPE:
1080             {
1081                 if ( !m_pFormView || !m_bDesignMode )
1082                     rSet.DisableItem( nWhich );
1083                 else
1084                 {
1085                     if ( !GetImpl()->canConvertCurrentSelectionToControl( OBJ_FM_FIXEDTEXT ) )
1086                         // if it cannot be converted to a fixed text, it is no single control
1087                         rSet.DisableItem( nWhich );
1088                 }
1089             } break;
1090 
1091             case SID_FM_CONVERTTO_FILECONTROL   :
1092             case SID_FM_CONVERTTO_CURRENCY      :
1093             case SID_FM_CONVERTTO_PATTERN       :
1094             case SID_FM_CONVERTTO_IMAGECONTROL  :
1095             case SID_FM_CONVERTTO_SCROLLBAR     :
1096             case SID_FM_CONVERTTO_NAVIGATIONBAR :
1097             case SID_FM_CONVERTTO_IMAGEBUTTON   :
1098             case SID_FM_CONVERTTO_EDIT          :
1099             case SID_FM_CONVERTTO_BUTTON        :
1100             case SID_FM_CONVERTTO_FIXEDTEXT     :
1101             case SID_FM_CONVERTTO_LISTBOX       :
1102             case SID_FM_CONVERTTO_CHECKBOX      :
1103             case SID_FM_CONVERTTO_RADIOBUTTON   :
1104             case SID_FM_CONVERTTO_GROUPBOX      :
1105             case SID_FM_CONVERTTO_COMBOBOX      :
1106             case SID_FM_CONVERTTO_DATE          :
1107             case SID_FM_CONVERTTO_TIME          :
1108             case SID_FM_CONVERTTO_NUMERIC       :
1109             case SID_FM_CONVERTTO_FORMATTED     :
1110             case SID_FM_CONVERTTO_SPINBUTTON    :
1111             {
1112                 if ( !m_pFormView || !m_bDesignMode || !GetImpl()->canConvertCurrentSelectionToControl( nWhich ) )
1113                     rSet.DisableItem( nWhich );
1114                 else
1115                 {
1116                     rSet.Put( SfxBoolItem( nWhich, sal_False ) );
1117                     // just to have a defined state (available and not checked)
1118                 }
1119             }
1120             break;
1121         }
1122         nWhich = aIter.NextWhich();
1123     }
1124 }
1125 
1126 //------------------------------------------------------------------------
GetFormState(SfxItemSet & rSet,sal_uInt16 nWhich)1127 void FmFormShell::GetFormState(SfxItemSet &rSet, sal_uInt16 nWhich)
1128 {
1129     if  (   !GetImpl()->getNavController().is()
1130         ||  !isRowSetAlive(GetImpl()->getNavController()->getModel())
1131         ||  !m_pFormView
1132         ||  m_bDesignMode
1133         ||  !GetImpl()->getActiveForm().is()
1134         ||  GetImpl()->isInFilterMode()
1135         )
1136         rSet.DisableItem(nWhich);
1137     else
1138     {
1139         sal_Bool bEnable = sal_False;
1140         try
1141         {
1142             switch (nWhich)
1143             {
1144             case SID_FM_VIEW_AS_GRID:
1145                 if (GetImpl()->getHostFrame().is() && GetImpl()->getNavController().is())
1146                 {
1147                     bEnable = sal_True;
1148                     sal_Bool bDisplayingCurrent =
1149                         GetImpl()->getInternalForm(
1150                             Reference< XForm >( GetImpl()->getNavController()->getModel(), UNO_QUERY )
1151                         ) == GetImpl()->getExternallyDisplayedForm();
1152                     rSet.Put(SfxBoolItem(nWhich, bDisplayingCurrent));
1153                 }
1154                 break;
1155 
1156             case SID_FM_SEARCH:
1157             {
1158                 Reference< ::com::sun::star::beans::XPropertySet >  xNavSet(GetImpl()->getActiveForm(), UNO_QUERY);
1159                 sal_Int32 nCount = ::comphelper::getINT32(xNavSet->getPropertyValue(FM_PROP_ROWCOUNT));
1160                 bEnable = nCount != 0;
1161             }   break;
1162             case SID_FM_RECORD_ABSOLUTE:
1163             case SID_FM_RECORD_TOTAL:
1164             {
1165                 FeatureState aState;
1166                 GetImpl()->getNavControllerFeatures()->getState( nWhich, aState );
1167                 if ( SID_FM_RECORD_ABSOLUTE == nWhich )
1168                 {
1169                     sal_Int32 nPosition = 0;
1170                     aState.State >>= nPosition;
1171                     rSet.Put( SfxInt32Item( nWhich, nPosition ) );
1172                 }
1173                 else if ( SID_FM_RECORD_TOTAL == nWhich )
1174                 {
1175                     ::rtl::OUString sTotalCount;
1176                     aState.State >>= sTotalCount;
1177                     rSet.Put( SfxStringItem( nWhich, sTotalCount ) );
1178                 }
1179                 bEnable = aState.Enabled;
1180             }
1181             break;
1182 
1183             // first, prev, next, last, and absolute affect the nav controller, not the
1184             // active controller
1185             case SID_FM_RECORD_FIRST:
1186             case SID_FM_RECORD_PREV:
1187             case SID_FM_RECORD_NEXT:
1188             case SID_FM_RECORD_LAST:
1189             case SID_FM_RECORD_NEW:
1190             case SID_FM_RECORD_SAVE:
1191             case SID_FM_RECORD_UNDO:
1192             case SID_FM_RECORD_DELETE:
1193             case SID_FM_REFRESH:
1194             case SID_FM_REFRESH_FORM_CONTROL:
1195             case SID_FM_REMOVE_FILTER_SORT:
1196             case SID_FM_SORTUP:
1197             case SID_FM_SORTDOWN:
1198             case SID_FM_AUTOFILTER:
1199             case SID_FM_ORDERCRIT:
1200                 bEnable = GetImpl()->IsFormSlotEnabled( nWhich );
1201                 break;
1202 
1203             case SID_FM_FORM_FILTERED:
1204             {
1205                 FeatureState aState;
1206                 bEnable = GetImpl()->IsFormSlotEnabled( nWhich, &aState );
1207 
1208                 rSet.Put( SfxBoolItem( nWhich, ::comphelper::getBOOL( aState.State ) ) );
1209             }
1210             break;
1211 
1212             case SID_FM_FILTER_START:
1213                 bEnable = GetImpl()->getActiveControllerFeatures()->canDoFormFilter();
1214                 break;
1215             }
1216         }
1217         catch( const Exception& )
1218         {
1219             DBG_ERROR( "FmFormShell::GetFormState: caught an exception while determining the state!" );
1220         }
1221         if (!bEnable)
1222             rSet.DisableItem(nWhich);
1223     }
1224 }
1225 
1226 //------------------------------------------------------------------------
GetCurPage() const1227 FmFormPage* FmFormShell::GetCurPage() const
1228 {
1229     FmFormPage* pP = NULL;
1230     if (m_pFormView && m_pFormView->GetSdrPageView())
1231         pP = PTR_CAST(FmFormPage,m_pFormView->GetSdrPageView()->GetPage());
1232     return pP;
1233 }
1234 
1235 //------------------------------------------------------------------------
SetView(FmFormView * _pView)1236 void FmFormShell::SetView( FmFormView* _pView )
1237 {
1238     if ( m_pFormView )
1239     {
1240         if ( IsActive() )
1241             GetImpl()->viewDeactivated( *m_pFormView );
1242 
1243         m_pFormView->SetFormShell( NULL, FmFormView::FormShellAccess() );
1244         m_pFormView = NULL;
1245         m_pFormModel = NULL;
1246     }
1247 
1248     if ( !_pView )
1249         return;
1250 
1251     m_pFormView = _pView;
1252     m_pFormView->SetFormShell( this, FmFormView::FormShellAccess() );
1253     m_pFormModel = (FmFormModel*)m_pFormView->GetModel();
1254 
1255     impl_setDesignMode( m_pFormView->IsDesignMode() );
1256 
1257     // We activate our view if we are activated ourself, but sometimes the Activate precedes the SetView.
1258     // But here we know both the view and our activation state so we at least are able to pass the latter
1259     // to the former.
1260     // FS - 30.06.99 - 67308
1261     if ( IsActive() )
1262         GetImpl()->viewActivated( *m_pFormView );
1263 }
1264 
1265 //------------------------------------------------------------------------
DetermineForms(sal_Bool bInvalidate)1266 void FmFormShell::DetermineForms(sal_Bool bInvalidate)
1267 {
1268     // Existieren Formulare auf der aktuellen Page
1269     sal_Bool bForms = GetImpl()->hasForms();
1270     if (bForms != m_bHasForms)
1271     {
1272         m_bHasForms = bForms;
1273         if (bInvalidate)
1274             UIFeatureChanged();
1275     }
1276 }
1277 
1278 //------------------------------------------------------------------------
GetY2KState(sal_uInt16 & nReturn)1279 sal_Bool FmFormShell::GetY2KState(sal_uInt16& nReturn)
1280 {
1281     return GetImpl()->GetY2KState(nReturn);
1282 }
1283 
1284 //------------------------------------------------------------------------
SetY2KState(sal_uInt16 n)1285 void FmFormShell::SetY2KState(sal_uInt16 n)
1286 {
1287     GetImpl()->SetY2KState(n);
1288 }
1289 
1290 //------------------------------------------------------------------------
Activate(sal_Bool bMDI)1291 void FmFormShell::Activate(sal_Bool bMDI)
1292 {
1293     SfxShell::Activate(bMDI);
1294 
1295     if ( m_pFormView )
1296         GetImpl()->viewActivated( *m_pFormView, sal_True );
1297 }
1298 
1299 //------------------------------------------------------------------------
Deactivate(sal_Bool bMDI)1300 void FmFormShell::Deactivate(sal_Bool bMDI)
1301 {
1302     SfxShell::Deactivate(bMDI);
1303 
1304     if ( m_pFormView )
1305         GetImpl()->viewDeactivated( *m_pFormView, sal_False );
1306 }
1307 
1308 //------------------------------------------------------------------------
ExecuteTextAttribute(SfxRequest & _rReq)1309 void FmFormShell::ExecuteTextAttribute( SfxRequest& _rReq )
1310 {
1311     m_pImpl->ExecuteTextAttribute( _rReq );
1312 }
1313 
1314 //------------------------------------------------------------------------
GetTextAttributeState(SfxItemSet & _rSet)1315 void FmFormShell::GetTextAttributeState( SfxItemSet& _rSet )
1316 {
1317     m_pImpl->GetTextAttributeState( _rSet );
1318 }
1319 
1320 //------------------------------------------------------------------------
IsActiveControl() const1321 bool FmFormShell::IsActiveControl() const
1322 {
1323     return m_pImpl->IsActiveControl();
1324 }
1325 
1326 //------------------------------------------------------------------------
ForgetActiveControl()1327 void FmFormShell::ForgetActiveControl()
1328 {
1329     m_pImpl->ForgetActiveControl();
1330 }
1331 
1332 //------------------------------------------------------------------------
SetControlActivationHandler(const Link & _rHdl)1333 void FmFormShell::SetControlActivationHandler( const Link& _rHdl )
1334 {
1335     m_pImpl->SetControlActivationHandler( _rHdl );
1336 }
1337 
1338 //------------------------------------------------------------------------
1339 namespace
1340 {
lcl_findUnoObject(const SdrObjList & _rObjList,const Reference<XControlModel> & _rxModel)1341     SdrUnoObj* lcl_findUnoObject( const SdrObjList& _rObjList, const Reference< XControlModel >& _rxModel )
1342     {
1343         SdrObjListIter aIter( _rObjList );
1344         while ( aIter.IsMore() )
1345         {
1346             SdrObject* pObject = aIter.Next();
1347             SdrUnoObj* pUnoObject = pObject ? PTR_CAST( SdrUnoObj, pObject ) : NULL;
1348             if ( !pUnoObject )
1349                 continue;
1350 
1351             Reference< XControlModel > xControlModel = pUnoObject->GetUnoControlModel();
1352             if ( !xControlModel.is() )
1353                 continue;
1354 
1355             if ( _rxModel == xControlModel )
1356                 return pUnoObject;
1357         }
1358         return NULL;
1359     }
1360 }
1361 
1362 //------------------------------------------------------------------------
ToggleControlFocus(const SdrUnoObj & i_rUnoObject,const SdrView & i_rView,OutputDevice & i_rDevice) const1363 void FmFormShell::ToggleControlFocus( const SdrUnoObj& i_rUnoObject, const SdrView& i_rView, OutputDevice& i_rDevice ) const
1364 {
1365     try
1366     {
1367         // check if the focus currently is in a control
1368         // Well, okay, do it the other way 'round: Check whether the current control of the active controller
1369         // actually has the focus. This should be equivalent.
1370         const bool bHasControlFocus = GetImpl()->HasControlFocus();
1371 
1372         if ( bHasControlFocus )
1373         {
1374             Window* pWindow( dynamic_cast< Window* >( &i_rDevice ) );
1375             OSL_ENSURE( pWindow, "FmFormShell::ToggleControlFocus: I need a Window, really!" );
1376             if ( pWindow )
1377                 pWindow->GrabFocus();
1378         }
1379         else
1380         {
1381             Reference< XControl > xControl;
1382             GetFormControl( i_rUnoObject.GetUnoControlModel(), i_rView, i_rDevice, xControl );
1383             Reference< XWindow > xControlWindow( xControl, UNO_QUERY );
1384             if ( xControlWindow.is() )
1385                 xControlWindow->setFocus();
1386         }
1387     }
1388     catch( const Exception& )
1389     {
1390         DBG_UNHANDLED_EXCEPTION();
1391     }
1392 }
1393 
1394 //------------------------------------------------------------------------
1395 namespace
1396 {
1397     class FocusableControlsFilter : public ::svx::ISdrObjectFilter
1398     {
1399     public:
FocusableControlsFilter(const SdrView & i_rView,const OutputDevice & i_rDevice)1400         FocusableControlsFilter( const SdrView& i_rView, const OutputDevice& i_rDevice )
1401             :m_rView( i_rView )
1402             ,m_rDevice( i_rDevice )
1403         {
1404         }
1405 
1406     public:
includeObject(const SdrObject & i_rObject) const1407         virtual bool    includeObject( const SdrObject& i_rObject ) const
1408         {
1409             const SdrUnoObj* pUnoObj = dynamic_cast< const SdrUnoObj* >( &i_rObject );
1410             if ( !pUnoObj )
1411                 return false;
1412 
1413             Reference< XControl > xControl = pUnoObj->GetUnoControl( m_rView, m_rDevice );
1414             return FmXFormView::isFocusable( xControl );
1415         }
1416 
1417     private:
1418         const SdrView&      m_rView;
1419         const OutputDevice& m_rDevice;
1420     };
1421 }
1422 
1423 //------------------------------------------------------------------------
CreateFocusableControlFilter(const SdrView & i_rView,const OutputDevice & i_rDevice) const1424 ::std::auto_ptr< ::svx::ISdrObjectFilter > FmFormShell::CreateFocusableControlFilter( const SdrView& i_rView, const OutputDevice& i_rDevice ) const
1425 {
1426     ::std::auto_ptr< ::svx::ISdrObjectFilter > pFilter;
1427 
1428     if ( !i_rView.IsDesignMode() )
1429         pFilter.reset( new FocusableControlsFilter( i_rView, i_rDevice ) );
1430 
1431     return pFilter;
1432 }
1433 
1434 //------------------------------------------------------------------------
GetFormControl(const Reference<XControlModel> & _rxModel,const SdrView & _rView,const OutputDevice & _rDevice,Reference<XControl> & _out_rxControl) const1435 SdrUnoObj* FmFormShell::GetFormControl( const Reference< XControlModel >& _rxModel, const SdrView& _rView, const OutputDevice& _rDevice, Reference< XControl >& _out_rxControl ) const
1436 {
1437     if ( !_rxModel.is() )
1438         return NULL;
1439 
1440     // we can only retrieve controls for SdrObjects which belong to page which is actually displayed in the given view
1441     SdrPageView* pPageView = _rView.GetSdrPageView();
1442     SdrPage* pPage = pPageView ? pPageView->GetPage() : NULL;
1443     OSL_ENSURE( pPage, "FmFormShell::GetFormControl: no page displayed in the given view!" );
1444     if ( !pPage )
1445         return NULL;
1446 
1447     SdrUnoObj* pUnoObject = lcl_findUnoObject( *pPage, _rxModel );
1448     if ( pUnoObject )
1449     {
1450         _out_rxControl = pUnoObject->GetUnoControl( _rView, _rDevice );
1451         return pUnoObject;
1452     }
1453 
1454 #if OSL_DEBUG_LEVEL > 0
1455     // perhaps we are fed with a control model which lives on a page other than the one displayed
1456     // in the given view. This is worth being reported as error, in non-product builds.
1457     FmFormModel* pModel = GetFormModel();
1458     if ( pModel )
1459     {
1460         sal_uInt16 pageCount = pModel->GetPageCount();
1461         for ( sal_uInt16 page = 0; page < pageCount; ++page )
1462         {
1463             pPage = pModel->GetPage( page );
1464             OSL_ENSURE( pPage, "FmFormShell::GetFormControl: NULL page encountered!" );
1465             if  ( !pPage )
1466                 continue;
1467 
1468             pUnoObject = lcl_findUnoObject( *pPage, _rxModel );
1469             OSL_ENSURE( !pUnoObject, "FmFormShell::GetFormControl: the given control model belongs to a wrong page (displayed elsewhere)!" );
1470         }
1471     }
1472 #endif
1473 
1474     return NULL;
1475 }
1476 
1477 //------------------------------------------------------------------------
GetFormController(const Reference<XForm> & _rxForm,const SdrView & _rView,const OutputDevice & _rDevice) const1478 Reference< runtime::XFormController > FmFormShell::GetFormController( const Reference< XForm >& _rxForm, const SdrView& _rView, const OutputDevice& _rDevice ) const
1479 {
1480     const FmFormView* pFormView = dynamic_cast< const FmFormView* >( &_rView );
1481     if ( !pFormView )
1482         return NULL;
1483 
1484     return pFormView->GetFormController( _rxForm, _rDevice );
1485 }
1486 
1487 //------------------------------------------------------------------------
SetDesignMode(sal_Bool _bDesignMode)1488 void FmFormShell::SetDesignMode( sal_Bool _bDesignMode )
1489 {
1490     if ( _bDesignMode == m_bDesignMode )
1491         return;
1492 
1493     FmFormModel* pModel = GetFormModel();
1494     if (pModel)
1495         // für die Zeit des Übergangs das Undo-Environment ausschalten, das sichert, dass man dort auch nicht-transiente
1496         // Properties mal eben ändern kann (sollte allerdings mit Vorsicht genossen und beim Rückschalten des Modes
1497         // auch immer wieder rückgängig gemacht werden. Ein Beispiel ist das Setzen der maximalen Text-Länge durch das
1498         // OEditModel an seinem Control.)
1499         pModel->GetUndoEnv().Lock();
1500 
1501     // dann die eigentliche Umschaltung
1502     if ( m_bDesignMode || PrepareClose( sal_True ) )
1503         impl_setDesignMode(!m_bDesignMode );
1504 
1505     // und mein Undo-Environment wieder an
1506     if ( pModel )
1507         pModel->GetUndoEnv().UnLock();
1508 }
1509 
1510 /* vim: set noet sw=4 ts=4: */
1511