Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / form / fmshell.cxx
blobab4189f9c2ba420f439879f6d3d0409702912980
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "fmvwimp.hxx"
30 #include <svx/fmshell.hxx>
31 #include "svx/fmtools.hxx"
32 #include "fmservs.hxx"
33 #include "fmprop.hrc"
34 #include "fmpgeimp.hxx"
35 #include "fmitems.hxx"
36 #include "fmundo.hxx"
37 #include <vcl/waitobj.hxx>
38 #include <com/sun/star/form/XLoadable.hpp>
39 #include <com/sun/star/container/XNamed.hpp>
40 #include <com/sun/star/sdbcx/Privilege.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/beans/XMultiPropertySet.hpp>
43 #include <com/sun/star/beans/XFastPropertySet.hpp>
44 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
45 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <com/sun/star/container/XNameContainer.hpp>
47 #include <com/sun/star/awt/XTabControllerModel.hpp>
48 #include <sfx2/viewfrm.hxx>
49 #include <vcl/wrkwin.hxx>
50 #include <vcl/msgbox.hxx>
51 #include <svl/whiter.hxx>
52 #include <sfx2/app.hxx>
53 #include <svl/intitem.hxx>
54 #include <svl/visitem.hxx>
55 #include <unotools/moduleoptions.hxx>
56 #include <sfx2/objface.hxx>
57 #include <sfx2/request.hxx>
58 #include <sfx2/dispatch.hxx>
59 #include <sfx2/objsh.hxx>
60 #include <svx/svdobj.hxx>
61 #include <svx/fmpage.hxx>
62 #include "svx/svditer.hxx"
63 #include "fmobj.hxx"
65 #include <svx/svxids.hrc>
67 #include "svx/fmresids.hrc"
68 #include "fmexch.hxx"
69 #include <svx/fmglob.hxx>
70 #include <svl/eitem.hxx>
71 #include <tools/shl.hxx>
72 #include <tools/diagnose_ex.h>
73 #include <svx/svdpage.hxx>
74 #include <svx/fmmodel.hxx>
75 #include <svx/dialmgr.hxx>
76 #include "fmshimp.hxx"
77 #include <svx/svdpagv.hxx>
78 #include <sfx2/objitem.hxx>
79 #include <sfx2/viewsh.hxx>
80 #include <vcl/sound.hxx>
81 #include "fmexpl.hxx"
82 #include "formcontrolling.hxx"
83 #include <svl/numuno.hxx>
84 #include <connectivity/dbtools.hxx>
85 #include <comphelper/types.hxx>
86 #include <comphelper/processfactory.hxx>
87 #include "fmdocumentclassification.hxx"
88 #include "formtoolbars.hxx"
90 #include <svx/svxdlg.hxx>
91 #include <svx/dialogs.hrc>
93 #include "svx/sdrobjectfilter.hxx"
95 #define FmFormShell
96 #include "svxslots.hxx"
98 #include "tbxform.hxx"
99 #include <comphelper/property.hxx>
100 #include <com/sun/star/beans/PropertyValue.hpp>
102 #include <boost/scoped_ptr.hpp>
104 // wird fuer Invalidate verwendet -> mitpflegen
105 // aufsteigend sortieren !!!!!!
106 sal_uInt16 ControllerSlotMap[] = // slots des Controllers
108 SID_FM_CONFIG,
109 SID_FM_PUSHBUTTON,
110 SID_FM_RADIOBUTTON,
111 SID_FM_CHECKBOX,
112 SID_FM_FIXEDTEXT,
113 SID_FM_GROUPBOX,
114 SID_FM_EDIT,
115 SID_FM_LISTBOX,
116 SID_FM_COMBOBOX,
117 SID_FM_DBGRID,
118 SID_FM_IMAGEBUTTON,
119 SID_FM_FILECONTROL,
120 SID_FM_NAVIGATIONBAR,
121 SID_FM_CTL_PROPERTIES,
122 SID_FM_PROPERTIES,
123 SID_FM_TAB_DIALOG,
124 SID_FM_ADD_FIELD,
125 SID_FM_DESIGN_MODE,
126 SID_FM_SHOW_FMEXPLORER,
127 SID_FM_SHOW_PROPERTIES,
128 SID_FM_FMEXPLORER_CONTROL,
129 SID_FM_DATEFIELD,
130 SID_FM_TIMEFIELD,
131 SID_FM_NUMERICFIELD,
132 SID_FM_CURRENCYFIELD,
133 SID_FM_PATTERNFIELD,
134 SID_FM_OPEN_READONLY,
135 SID_FM_IMAGECONTROL,
136 SID_FM_USE_WIZARDS,
137 SID_FM_FORMATTEDFIELD,
138 SID_FM_FILTER_NAVIGATOR,
139 SID_FM_AUTOCONTROLFOCUS,
140 SID_FM_SCROLLBAR,
141 SID_FM_SPINBUTTON,
142 SID_FM_SHOW_DATANAVIGATOR,
143 SID_FM_DATANAVIGATOR_CONTROL,
148 using namespace ::com::sun::star::uno;
149 using namespace ::com::sun::star::awt;
150 using namespace ::com::sun::star::sdbc;
151 using namespace ::com::sun::star::sdbcx;
152 using namespace ::com::sun::star::beans;
153 using namespace ::com::sun::star::form;
154 using namespace ::com::sun::star::form::runtime;
155 using namespace ::com::sun::star::frame;
156 using namespace ::svxform;
158 //========================================================================
159 // class FmDesignModeChangedHint
160 //========================================================================
161 TYPEINIT1( FmDesignModeChangedHint, SfxHint );
163 //------------------------------------------------------------------------
164 FmDesignModeChangedHint::FmDesignModeChangedHint( sal_Bool bDesMode )
165 :m_bDesignMode( bDesMode )
169 //------------------------------------------------------------------------
170 FmDesignModeChangedHint::~FmDesignModeChangedHint()
174 //========================================================================
175 const sal_uInt32 FM_UI_FEATURE_SHOW_DATABASEBAR = 0x00000001;
176 const sal_uInt32 FM_UI_FEATURE_SHOW_FIELD = 0x00000002;
177 const sal_uInt32 FM_UI_FEATURE_SHOW_PROPERTIES = 0x00000004;
178 const sal_uInt32 FM_UI_FEATURE_SHOW_EXPLORER = 0x00000008;
179 const sal_uInt32 FM_UI_FEATURE_SHOW_FILTERBAR = 0x00000010;
180 const sal_uInt32 FM_UI_FEATURE_SHOW_FILTERNAVIGATOR = 0x00000020;
181 const sal_uInt32 FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR = 0x00000040;
182 const sal_uInt32 FM_UI_FEATURE_TB_CONTROLS = 0x00000080;
183 const sal_uInt32 FM_UI_FEATURE_TB_MORECONTROLS = 0x00000100;
184 const sal_uInt32 FM_UI_FEATURE_TB_FORMDESIGN = 0x00000200;
185 const sal_uInt32 FM_UI_FEATURE_SHOW_DATANAVIGATOR = 0x00000400;
187 SFX_IMPL_INTERFACE(FmFormShell, SfxShell, SVX_RES(RID_STR_FORMSHELL))
189 SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_NAVIGATION|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_READONLYDOC,
190 SVX_RES(RID_SVXTBX_FORM_NAVIGATION),
191 FM_UI_FEATURE_SHOW_DATABASEBAR );
193 SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_NAVIGATION|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_READONLYDOC,
194 SVX_RES(RID_SVXTBX_FORM_FILTER),
195 FM_UI_FEATURE_SHOW_FILTERBAR );
197 SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_READONLYDOC,
198 SVX_RES( RID_SVXTBX_TEXT_CONTROL_ATTRIBUTES ),
199 FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR );
201 SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_FM_ADD_FIELD, FM_UI_FEATURE_SHOW_FIELD);
202 SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_FM_SHOW_PROPERTIES, FM_UI_FEATURE_SHOW_PROPERTIES);
203 SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_FM_SHOW_FMEXPLORER, FM_UI_FEATURE_SHOW_EXPLORER);
204 SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_FM_FILTER_NAVIGATOR, FM_UI_FEATURE_SHOW_FILTERNAVIGATOR);
205 SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_FM_SHOW_DATANAVIGATOR, FM_UI_FEATURE_SHOW_DATANAVIGATOR);
207 SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD,
208 SVX_RES( RID_SVXTBX_CONTROLS ),
209 FM_UI_FEATURE_TB_CONTROLS );
211 SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD,
212 SVX_RES( RID_SVXTBX_MORECONTROLS ),
213 FM_UI_FEATURE_TB_MORECONTROLS );
215 SFX_FEATURED_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD,
216 SVX_RES( RID_SVXTBX_FORMDESIGN ),
217 FM_UI_FEATURE_TB_FORMDESIGN );
220 //========================================================================
221 TYPEINIT1(FmFormShell,SfxShell)
223 //------------------------------------------------------------------------
224 FmFormShell::FmFormShell( SfxViewShell* _pParent, FmFormView* pView )
225 :SfxShell(_pParent)
226 ,m_pImpl(new FmXFormShell(*this, _pParent->GetViewFrame()))
227 ,m_pFormView( pView )
228 ,m_pFormModel( NULL )
229 ,m_pParentShell(_pParent)
230 ,m_nLastSlot( 0 )
231 ,m_bDesignMode( sal_True )
232 ,m_bHasForms(sal_False)
234 m_pImpl->acquire();
235 SetPool( &SFX_APP()->GetPool() );
236 SetName( String::CreateFromAscii( "Form" ) );
238 SetView(m_pFormView);
241 //------------------------------------------------------------------------
242 FmFormShell::~FmFormShell()
244 if ( m_pFormView )
245 SetView( NULL );
247 m_pImpl->dispose();
248 m_pImpl->release();
249 m_pImpl = NULL;
252 //------------------------------------------------------------------------
253 void FmFormShell::NotifyMarkListChanged(FmFormView* pWhichView)
255 FmNavViewMarksChanged aChangeNotification(pWhichView);
256 Broadcast(aChangeNotification);
259 //------------------------------------------------------------------------
260 sal_uInt16 FmFormShell::PrepareClose(sal_Bool bUI, sal_Bool /*bForBrowsing*/)
262 if ( GetImpl()->didPrepareClose() )
263 // we already did a PrepareClose for the current modifications of the current form
264 return sal_True;
266 sal_Bool bResult = sal_True;
267 // Save the data records, not in DesignMode and FilterMode
268 if (!m_bDesignMode && !GetImpl()->isInFilterMode() &&
269 m_pFormView && m_pFormView->GetActualOutDev() &&
270 m_pFormView->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW)
272 SdrPageView* pCurPageView = m_pFormView->GetSdrPageView();
274 // sal_uInt16 nPos = pCurPageView ? pCurPageView->GetWinList().Find((OutputDevice*)m_pFormView->GetActualOutDev()) : SDRPAGEVIEWWIN_NOTFOUND;
275 SdrPageWindow* pWindow = pCurPageView ? pCurPageView->FindPageWindow(*((OutputDevice*)m_pFormView->GetActualOutDev())) : 0L;
277 if(pWindow)
279 // Zunaechst werden die aktuellen Inhalte der Controls gespeichert
280 // Wenn alles glatt gelaufen ist, werden die modifizierten Datensaetze gespeichert
281 if ( GetImpl()->getActiveController().is() )
283 const ::svx::ControllerFeatures& rController = GetImpl()->getActiveControllerFeatures();
284 if ( rController->commitCurrentControl() )
286 sal_Bool bModified = rController->isModifiedRow();
288 if ( bModified && bUI )
290 QueryBox aQry(NULL, SVX_RES(RID_QRY_SAVEMODIFIED));
291 switch (aQry.Execute())
293 case RET_NO:
294 bModified = sal_False;
295 GetImpl()->didPrepareClose( sal_True );
296 break;
298 case RET_CANCEL:
299 return sal_False;
301 case RET_NEWTASK:
302 return RET_NEWTASK;
305 if ( bModified )
306 bResult = rController->commitCurrentRecord( );
312 return bResult;
315 //------------------------------------------------------------------------
316 void FmFormShell::impl_setDesignMode(sal_Bool bDesign)
318 if (m_pFormView)
320 if (!bDesign)
321 m_nLastSlot = SID_FM_DESIGN_MODE;
323 GetImpl()->SetDesignMode(bDesign);
324 // mein m_bDesignMode wird auch von der Impl gesetzt ...
326 else
328 m_bHasForms = sal_False;
329 m_bDesignMode = bDesign;
330 UIFeatureChanged();
333 GetViewShell()->GetViewFrame()->GetBindings().Invalidate(ControllerSlotMap);
336 //------------------------------------------------------------------------
337 sal_Bool FmFormShell::HasUIFeature( sal_uInt32 nFeature )
339 sal_Bool bResult = sal_False;
340 if ((nFeature & FM_UI_FEATURE_SHOW_DATABASEBAR) == FM_UI_FEATURE_SHOW_DATABASEBAR)
342 // nur wenn auch formulare verfuegbar
343 bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar() && !GetImpl()->isInFilterMode();
345 else if ((nFeature & FM_UI_FEATURE_SHOW_FILTERBAR) == FM_UI_FEATURE_SHOW_FILTERBAR)
347 // nur wenn auch formulare verfuegbar
348 bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar() && GetImpl()->isInFilterMode();
350 else if ((nFeature & FM_UI_FEATURE_SHOW_FILTERNAVIGATOR) == FM_UI_FEATURE_SHOW_FILTERNAVIGATOR)
352 bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar() && GetImpl()->isInFilterMode();
354 else if ((nFeature & FM_UI_FEATURE_SHOW_FIELD) == FM_UI_FEATURE_SHOW_FIELD)
356 bResult = m_bDesignMode && m_pFormView && m_bHasForms;
358 else if ((nFeature & FM_UI_FEATURE_SHOW_PROPERTIES) == FM_UI_FEATURE_SHOW_PROPERTIES)
360 bResult = m_bDesignMode && m_pFormView && m_bHasForms;
362 else if ((nFeature & FM_UI_FEATURE_SHOW_EXPLORER) == FM_UI_FEATURE_SHOW_EXPLORER)
364 bResult = m_bDesignMode; // OJ #101593# && m_pFormView && m_bHasForms;
366 else if ( ( nFeature & FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR ) == FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR )
368 bResult = !GetImpl()->IsReadonlyDoc() && m_pImpl->IsActiveControl( true );
370 else if ((nFeature & FM_UI_FEATURE_SHOW_DATANAVIGATOR) == FM_UI_FEATURE_SHOW_DATANAVIGATOR)
372 bResult = GetImpl()->isEnhancedForm();
374 else if ( ( ( nFeature & FM_UI_FEATURE_TB_CONTROLS ) == FM_UI_FEATURE_TB_CONTROLS )
375 || ( ( nFeature & FM_UI_FEATURE_TB_MORECONTROLS ) == FM_UI_FEATURE_TB_MORECONTROLS )
376 || ( ( nFeature & FM_UI_FEATURE_TB_FORMDESIGN ) == FM_UI_FEATURE_TB_FORMDESIGN )
379 bResult = sal_True;
382 return bResult;
385 //------------------------------------------------------------------------
386 void FmFormShell::Execute(SfxRequest &rReq)
388 sal_uInt16 nSlot = rReq.GetSlot();
390 //////////////////////////////////////////////////////////////////////
391 // MasterSlot setzen
392 switch( nSlot )
394 case SID_FM_PUSHBUTTON:
395 case SID_FM_RADIOBUTTON:
396 case SID_FM_CHECKBOX:
397 case SID_FM_FIXEDTEXT:
398 case SID_FM_GROUPBOX:
399 case SID_FM_LISTBOX:
400 case SID_FM_COMBOBOX:
401 case SID_FM_NAVIGATIONBAR:
402 case SID_FM_EDIT:
403 case SID_FM_DBGRID:
404 case SID_FM_IMAGEBUTTON:
405 case SID_FM_IMAGECONTROL:
406 case SID_FM_FILECONTROL:
407 case SID_FM_DATEFIELD:
408 case SID_FM_TIMEFIELD:
409 case SID_FM_NUMERICFIELD:
410 case SID_FM_CURRENCYFIELD:
411 case SID_FM_PATTERNFIELD:
412 case SID_FM_FORMATTEDFIELD:
413 case SID_FM_SCROLLBAR:
414 case SID_FM_SPINBUTTON:
415 m_nLastSlot = nSlot;
416 GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SID_FM_CONFIG );
417 break;
420 //////////////////////////////////////////////////////////////////////
421 // Identifier und Inventor des Uno-Controls setzen
422 sal_uInt16 nIdentifier = 0;
423 switch( nSlot )
425 case SID_FM_CHECKBOX:
426 nIdentifier = OBJ_FM_CHECKBOX;
427 break;
428 case SID_FM_PUSHBUTTON:
429 nIdentifier = OBJ_FM_BUTTON;
430 break;
431 case SID_FM_FIXEDTEXT:
432 nIdentifier = OBJ_FM_FIXEDTEXT;
433 break;
434 case SID_FM_LISTBOX:
435 nIdentifier = OBJ_FM_LISTBOX;
436 break;
437 case SID_FM_EDIT:
438 nIdentifier = OBJ_FM_EDIT;
439 break;
440 case SID_FM_RADIOBUTTON:
441 nIdentifier = OBJ_FM_RADIOBUTTON;
442 break;
443 case SID_FM_GROUPBOX:
444 nIdentifier = OBJ_FM_GROUPBOX;
445 break;
446 case SID_FM_COMBOBOX:
447 nIdentifier = OBJ_FM_COMBOBOX;
448 break;
449 case SID_FM_NAVIGATIONBAR:
450 nIdentifier = OBJ_FM_NAVIGATIONBAR;
451 break;
452 case SID_FM_DBGRID:
453 nIdentifier = OBJ_FM_GRID;
454 break;
455 case SID_FM_IMAGEBUTTON:
456 nIdentifier = OBJ_FM_IMAGEBUTTON;
457 break;
458 case SID_FM_IMAGECONTROL:
459 nIdentifier = OBJ_FM_IMAGECONTROL;
460 break;
461 case SID_FM_FILECONTROL:
462 nIdentifier = OBJ_FM_FILECONTROL;
463 break;
464 case SID_FM_DATEFIELD:
465 nIdentifier = OBJ_FM_DATEFIELD;
466 break;
467 case SID_FM_TIMEFIELD:
468 nIdentifier = OBJ_FM_TIMEFIELD;
469 break;
470 case SID_FM_NUMERICFIELD:
471 nIdentifier = OBJ_FM_NUMERICFIELD;
472 break;
473 case SID_FM_CURRENCYFIELD:
474 nIdentifier = OBJ_FM_CURRENCYFIELD;
475 break;
476 case SID_FM_PATTERNFIELD:
477 nIdentifier = OBJ_FM_PATTERNFIELD;
478 break;
479 case SID_FM_FORMATTEDFIELD:
480 nIdentifier = OBJ_FM_FORMATTEDFIELD;
481 break;
482 case SID_FM_SCROLLBAR:
483 nIdentifier = OBJ_FM_SCROLLBAR;
484 break;
485 case SID_FM_SPINBUTTON:
486 nIdentifier = OBJ_FM_SPINBUTTON;
487 break;
490 switch ( nSlot )
492 case SID_FM_CHECKBOX:
493 case SID_FM_PUSHBUTTON:
494 case SID_FM_FIXEDTEXT:
495 case SID_FM_LISTBOX:
496 case SID_FM_EDIT:
497 case SID_FM_RADIOBUTTON:
498 case SID_FM_COMBOBOX:
499 case SID_FM_NAVIGATIONBAR:
500 case SID_FM_GROUPBOX:
501 case SID_FM_DBGRID:
502 case SID_FM_IMAGEBUTTON:
503 case SID_FM_IMAGECONTROL:
504 case SID_FM_FILECONTROL:
505 case SID_FM_DATEFIELD:
506 case SID_FM_TIMEFIELD:
507 case SID_FM_NUMERICFIELD:
508 case SID_FM_CURRENCYFIELD:
509 case SID_FM_PATTERNFIELD:
510 case SID_FM_FORMATTEDFIELD:
511 case SID_FM_SCROLLBAR:
512 case SID_FM_SPINBUTTON:
514 SFX_REQUEST_ARG( rReq, pGrabFocusItem, SfxBoolItem, SID_FM_TOGGLECONTROLFOCUS, sal_False );
515 if ( pGrabFocusItem && pGrabFocusItem->GetValue() )
516 { // see below
517 SfxViewShell* pShell = GetViewShell();
518 Window* pShellWnd = pShell ? pShell->GetWindow() : NULL;
519 if ( pShellWnd )
520 pShellWnd->GrabFocus();
521 break;
524 SfxUInt16Item aIdentifierItem( SID_FM_CONTROL_IDENTIFIER, nIdentifier );
525 SfxUInt32Item aInventorItem( SID_FM_CONTROL_INVENTOR, FmFormInventor );
526 const SfxPoolItem* pArgs[] =
528 &aIdentifierItem, &aInventorItem, NULL
530 const SfxPoolItem* pInternalArgs[] =
532 NULL
535 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_CREATE_CONTROL, SFX_CALLMODE_ASYNCHRON,
536 pArgs, rReq.GetModifier(), pInternalArgs );
538 if ( rReq.GetModifier() & KEY_MOD1 )
540 // #99013# if selected with control key, return focus to current view
541 // do this asynchron, so that the creation can be finished first
542 // reusing the SID_FM_TOGGLECONTROLFOCUS is somewhat hacky ... which it wouldn't if it would have another
543 // name, so I do not really have a big problem with this ....
544 SfxBoolItem aGrabFocusIndicatorItem( SID_FM_TOGGLECONTROLFOCUS, sal_True );
545 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( nSlot, SFX_CALLMODE_ASYNCHRON,
546 &aGrabFocusIndicatorItem, NULL );
549 rReq.Done();
550 } break;
553 // Individuelle Aktionen
554 switch( nSlot )
556 case SID_FM_MORE_CONTROLS:
557 case SID_FM_FORM_DESIGN_TOOLS:
559 FormToolboxes aToolboxAccess( GetImpl()->getHostFrame() );
560 aToolboxAccess.toggleToolbox( nSlot );
561 rReq.Done();
563 break;
565 case SID_FM_TOGGLECONTROLFOCUS:
567 FmFormView* pFormView = GetFormView();
568 if ( !pFormView )
569 break;
571 // if we execute this ourself, then either the application does not implement an own handling for this,
572 // of we're on the top of the dispatcher stack, which means a control has the focus.
573 // In the latter case, we put the focus to the document window, otherwise, we focus the first control
574 const bool bHasControlFocus = GetImpl()->HasControlFocus();
575 if ( bHasControlFocus )
577 const OutputDevice* pDevice = GetCurrentViewDevice();
578 Window* pWindow = dynamic_cast< Window* >( const_cast< OutputDevice* >( pDevice ) );
579 if ( pWindow )
580 pWindow->GrabFocus();
582 else
584 pFormView->GrabFirstControlFocus( );
587 break;
589 case SID_FM_VIEW_AS_GRID:
590 GetImpl()->CreateExternalView();
591 break;
592 case SID_FM_CONVERTTO_EDIT :
593 case SID_FM_CONVERTTO_BUTTON :
594 case SID_FM_CONVERTTO_FIXEDTEXT :
595 case SID_FM_CONVERTTO_LISTBOX :
596 case SID_FM_CONVERTTO_CHECKBOX :
597 case SID_FM_CONVERTTO_RADIOBUTTON :
598 case SID_FM_CONVERTTO_GROUPBOX :
599 case SID_FM_CONVERTTO_COMBOBOX :
600 case SID_FM_CONVERTTO_IMAGEBUTTON :
601 case SID_FM_CONVERTTO_FILECONTROL :
602 case SID_FM_CONVERTTO_DATE :
603 case SID_FM_CONVERTTO_TIME :
604 case SID_FM_CONVERTTO_NUMERIC :
605 case SID_FM_CONVERTTO_CURRENCY :
606 case SID_FM_CONVERTTO_PATTERN :
607 case SID_FM_CONVERTTO_IMAGECONTROL :
608 case SID_FM_CONVERTTO_FORMATTED :
609 case SID_FM_CONVERTTO_SCROLLBAR :
610 case SID_FM_CONVERTTO_SPINBUTTON :
611 case SID_FM_CONVERTTO_NAVIGATIONBAR :
612 GetImpl()->executeControlConversionSlot( nSlot );
613 // nach dem Konvertieren die Selektion neu bestimmern, da sich ja das selektierte Objekt
614 // geaendert hat
615 GetImpl()->SetSelection(GetFormView()->GetMarkedObjectList());
616 break;
617 case SID_FM_LEAVE_CREATE:
618 m_nLastSlot = 0;
619 GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SID_FM_CONFIG );
620 rReq.Done();
621 break;
622 case SID_FM_SHOW_PROPERTY_BROWSER:
624 SFX_REQUEST_ARG( rReq, pShowItem, SfxBoolItem, SID_FM_SHOW_PROPERTIES, sal_False );
625 sal_Bool bShow = sal_True;
626 if ( pShowItem )
627 bShow = pShowItem->GetValue();
628 GetImpl()->ShowSelectionProperties( bShow );
630 rReq.Done();
631 } break;
633 case SID_FM_PROPERTIES:
635 // PropertyBrowser anzeigen
636 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSlot, sal_False);
637 sal_Bool bShow = pShowItem ? pShowItem->GetValue() : sal_True;
639 InterfaceBag aOnlyTheForm;
640 aOnlyTheForm.insert( Reference< XInterface >( GetImpl()->getCurrentForm(), UNO_QUERY ) );
641 GetImpl()->setCurrentSelection( aOnlyTheForm );
643 GetImpl()->ShowSelectionProperties( bShow );
645 rReq.Done();
646 } break;
648 case SID_FM_CTL_PROPERTIES:
650 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSlot, sal_False);
651 sal_Bool bShow = pShowItem ? pShowItem->GetValue() : sal_True;
653 OSL_ENSURE( GetImpl()->onlyControlsAreMarked(), "FmFormShell::Execute: ControlProperties should be disabled!" );
654 if ( bShow )
655 GetImpl()->selectLastMarkedControls();
656 GetImpl()->ShowSelectionProperties( bShow );
658 rReq.Done();
659 } break;
660 case SID_FM_SHOW_PROPERTIES:
661 case SID_FM_ADD_FIELD:
662 case SID_FM_FILTER_NAVIGATOR:
663 case SID_FM_SHOW_DATANAVIGATOR :
665 GetViewShell()->GetViewFrame()->ChildWindowExecute( rReq );
666 rReq.Done();
667 } break;
668 case SID_FM_SHOW_FMEXPLORER:
670 if (!m_pFormView) // setzen der ::com::sun::star::sdbcx::View Forcieren
671 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute(SID_CREATE_SW_DRAWVIEW);
673 GetViewShell()->GetViewFrame()->ChildWindowExecute(rReq);
674 rReq.Done();
676 break;
678 case SID_FM_TAB_DIALOG:
680 GetImpl()->ExecuteTabOrderDialog( Reference< XTabControllerModel >( GetImpl()->getCurrentForm(), UNO_QUERY ) );
681 rReq.Done();
683 break;
685 case SID_FM_DESIGN_MODE:
687 SFX_REQUEST_ARG(rReq, pDesignItem, SfxBoolItem, nSlot, sal_False);
688 sal_Bool bDesignMode = pDesignItem ? pDesignItem->GetValue() : !m_bDesignMode;
689 SetDesignMode( bDesignMode );
690 if ( m_bDesignMode == bDesignMode )
691 rReq.Done();
693 m_nLastSlot = SID_FM_DESIGN_MODE;
694 GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SID_FM_CONFIG );
696 break;
698 case SID_FM_AUTOCONTROLFOCUS:
700 FmFormModel* pModel = GetFormModel();
701 DBG_ASSERT(pModel, "FmFormShell::Execute : invalid call !");
702 // should have been disabled in GetState if we don't have a FormModel
703 pModel->SetAutoControlFocus( !pModel->GetAutoControlFocus() );
704 GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_AUTOCONTROLFOCUS);
706 break;
707 case SID_FM_OPEN_READONLY:
709 FmFormModel* pModel = GetFormModel();
710 DBG_ASSERT(pModel, "FmFormShell::Execute : invalid call !");
711 // should have been disabled in GetState if we don't have a FormModel
712 pModel->SetOpenInDesignMode( !pModel->GetOpenInDesignMode() );
713 GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_OPEN_READONLY);
715 break;
716 case SID_FM_USE_WIZARDS:
718 GetImpl()->SetWizardUsing(!GetImpl()->GetWizardUsing());
719 GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_USE_WIZARDS);
721 break;
722 case SID_FM_SEARCH:
724 const ::svx::ControllerFeatures& rController = GetImpl()->getActiveControllerFeatures();
725 if ( rController->commitCurrentControl() && rController->commitCurrentRecord() )
726 GetImpl()->ExecuteSearch();
727 rReq.Done();
729 break;
731 case SID_FM_RECORD_FIRST:
732 case SID_FM_RECORD_PREV:
733 case SID_FM_RECORD_NEXT:
734 case SID_FM_RECORD_LAST:
735 case SID_FM_RECORD_NEW:
736 case SID_FM_REFRESH:
737 case SID_FM_REFRESH_FORM_CONTROL:
738 case SID_FM_RECORD_DELETE:
739 case SID_FM_RECORD_UNDO:
740 case SID_FM_RECORD_SAVE:
741 case SID_FM_REMOVE_FILTER_SORT:
742 case SID_FM_SORTDOWN:
743 case SID_FM_SORTUP:
744 case SID_FM_AUTOFILTER:
745 case SID_FM_ORDERCRIT:
746 case SID_FM_FORM_FILTERED:
748 GetImpl()->ExecuteFormSlot( nSlot );
749 rReq.Done();
751 break;
753 case SID_FM_RECORD_ABSOLUTE:
755 const ::svx::ControllerFeatures& rController = GetImpl()->getNavControllerFeatures();
756 sal_Int32 nRecord = -1;
758 const SfxItemSet* pArgs = rReq.GetArgs();
759 if ( pArgs )
761 const SfxPoolItem* pItem;
762 if ( ( pArgs->GetItemState( FN_PARAM_1, sal_True, &pItem ) ) == SFX_ITEM_SET )
764 const SfxInt32Item* pTypedItem = PTR_CAST( SfxInt32Item, pItem );
765 if ( pTypedItem )
766 nRecord = Max( pTypedItem->GetValue(), sal_Int32(0) );
769 else
771 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
772 DBG_ASSERT( pFact, "no dialog factory!" );
773 if ( pFact )
775 boost::scoped_ptr< AbstractFmInputRecordNoDialog > dlg( pFact->CreateFmInputRecordNoDialog( NULL ) );
776 DBG_ASSERT( dlg.get(), "Dialogdiet fail!" );
777 dlg->SetValue( rController->getCursor()->getRow() );
778 if ( dlg->Execute() == RET_OK )
779 nRecord = dlg->GetValue();
781 rReq.AppendItem( SfxInt32Item( FN_PARAM_1, nRecord ) );
785 if ( nRecord != -1 )
786 rController->execute( nSlot, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Position" )), makeAny( (sal_Int32)nRecord ) );
788 rReq.Done();
789 } break;
790 case SID_FM_FILTER_EXECUTE:
791 case SID_FM_FILTER_EXIT:
793 sal_Bool bCancelled = ( SID_FM_FILTER_EXIT == nSlot );
794 sal_Bool bReopenNavigator = sal_False;
796 if ( !bCancelled )
798 // if the filter navigator is still open, we need to close it, so it can possibly
799 // commit it's most recent changes
800 if ( GetViewShell() && GetViewShell()->GetViewFrame() )
801 if ( GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_FILTER_NAVIGATOR ) )
803 GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
804 bReopenNavigator = sal_True;
807 Reference< runtime::XFormController > xController( GetImpl()->getActiveController() );
809 if ( GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_FILTER_NAVIGATOR )
810 // closing the window was denied, for instance because of a invalid criterion
812 || ( xController.is()
813 && !GetImpl()->getActiveControllerFeatures()->commitCurrentControl( )
815 // committing the controller was denied
818 rReq.Done();
819 break;
823 GetImpl()->stopFiltering( !bCancelled );
824 rReq.Done();
826 if ( bReopenNavigator )
827 // we closed the navigator only to implicitly commit it (as we do not have another
828 // direct wire to it), but to the user, it should look it it was always open
829 GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
831 break;
833 case SID_FM_FILTER_START:
835 GetImpl()->startFiltering();
836 rReq.Done();
838 // initially open the filter navigator, the whole form based filter is pretty useless without it
839 SfxBoolItem aIdentifierItem( SID_FM_FILTER_NAVIGATOR, sal_True );
840 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_FILTER_NAVIGATOR, SFX_CALLMODE_ASYNCHRON,
841 &aIdentifierItem, NULL );
842 } break;
846 //------------------------------------------------------------------------
847 void FmFormShell::GetState(SfxItemSet &rSet)
849 SfxWhichIter aIter( rSet );
850 sal_uInt16 nWhich = aIter.FirstWhich();
851 while ( nWhich )
853 switch( nWhich )
855 case SID_FM_MORE_CONTROLS:
856 case SID_FM_FORM_DESIGN_TOOLS:
858 FormToolboxes aToolboxAccess( GetImpl()->getHostFrame() );
859 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible( nWhich ) ) );
861 break;
863 case SID_FM_FILTER_EXECUTE:
864 case SID_FM_FILTER_EXIT:
865 if (!GetImpl()->isInFilterMode())
866 rSet.DisableItem( nWhich );
867 break;
869 case SID_FM_USE_WIZARDS:
870 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
871 rSet.Put( SfxVisibilityItem( nWhich, sal_False ) );
872 else if (!GetFormModel())
873 rSet.DisableItem( nWhich );
874 else
875 rSet.Put( SfxBoolItem(nWhich, GetImpl()->GetWizardUsing() ) );
876 break;
877 case SID_FM_AUTOCONTROLFOCUS:
878 if (!GetFormModel())
879 rSet.DisableItem( nWhich );
880 else
881 rSet.Put( SfxBoolItem(nWhich, GetFormModel()->GetAutoControlFocus() ) );
882 break;
883 case SID_FM_OPEN_READONLY:
884 if (!GetFormModel())
885 rSet.DisableItem( nWhich );
886 else
887 rSet.Put( SfxBoolItem(nWhich, GetFormModel()->GetOpenInDesignMode() ) );
888 break;
890 case SID_FM_NAVIGATIONBAR:
891 case SID_FM_DBGRID:
892 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
894 rSet.Put( SfxVisibilityItem( nWhich, sal_False ) );
895 break;
897 // NO break!
899 case SID_FM_SCROLLBAR:
900 case SID_FM_IMAGECONTROL:
901 case SID_FM_FILECONTROL:
902 case SID_FM_CURRENCYFIELD:
903 case SID_FM_PATTERNFIELD:
904 case SID_FM_IMAGEBUTTON:
905 case SID_FM_RADIOBUTTON:
906 case SID_FM_COMBOBOX:
907 case SID_FM_GROUPBOX:
908 case SID_FM_CHECKBOX:
909 case SID_FM_PUSHBUTTON:
910 case SID_FM_FIXEDTEXT:
911 case SID_FM_LISTBOX:
912 case SID_FM_EDIT:
913 case SID_FM_DATEFIELD:
914 case SID_FM_TIMEFIELD:
915 case SID_FM_NUMERICFIELD:
916 case SID_FM_FORMATTEDFIELD:
917 case SID_FM_SPINBUTTON:
918 if (!m_bDesignMode)
919 rSet.DisableItem( nWhich );
920 else
922 sal_Bool bLayerLocked = sal_False;
923 if (m_pFormView)
925 // Ist der ::com::sun::star::drawing::Layer gelocked, so m???ssen die Slots disabled werden. #36897
926 SdrPageView* pPV = m_pFormView->GetSdrPageView();
927 if (pPV != NULL)
928 bLayerLocked = pPV->IsLayerLocked(m_pFormView->GetActiveLayer());
930 if (bLayerLocked)
931 rSet.DisableItem( nWhich );
932 else
933 rSet.Put( SfxBoolItem(nWhich, (nWhich==m_nLastSlot)) );
935 break;
936 case SID_FM_FILTER_NAVIGATOR_CONTROL:
938 if (GetImpl()->isInFilterMode())
939 rSet.Put(SfxObjectItem(nWhich, this));
940 else
941 rSet.Put(SfxObjectItem(nWhich));
942 } break;
943 case SID_FM_FIELDS_CONTROL:
944 case SID_FM_PROPERTY_CONTROL:
946 if (!m_bDesignMode || !m_pFormView || !m_bHasForms)
947 rSet.Put(SfxObjectItem(nWhich));
948 else
949 rSet.Put(SfxObjectItem(nWhich, this));
951 } break;
952 case SID_FM_FMEXPLORER_CONTROL:
953 case SID_FM_DATANAVIGATOR_CONTROL :
955 if (!m_bDesignMode || !m_pFormView)
956 rSet.Put(SfxObjectItem(nWhich));
957 else
958 rSet.Put(SfxObjectItem(nWhich, this));
960 } break;
961 case SID_FM_ADD_FIELD:
962 case SID_FM_SHOW_FMEXPLORER:
963 case SID_FM_SHOW_PROPERTIES:
964 case SID_FM_FILTER_NAVIGATOR:
965 case SID_FM_SHOW_DATANAVIGATOR:
967 if ( GetViewShell()->GetViewFrame()->KnowsChildWindow(nWhich) )
968 rSet.Put( SfxBoolItem( nWhich, GetViewShell()->GetViewFrame()->HasChildWindow(nWhich)) );
969 else
970 rSet.DisableItem(nWhich);
971 } break;
973 case SID_FM_SHOW_PROPERTY_BROWSER:
975 rSet.Put(SfxBoolItem(GetImpl()->IsPropBrwOpen()));
977 break;
979 case SID_FM_CTL_PROPERTIES:
981 // der Impl eventuell die Moeglichjkeit geben, ihre an der aktuellen MarkList ausgerichteten Objekte
982 // auf den neuesten Stand zu bringen
983 if (GetImpl()->IsSelectionUpdatePending())
984 GetImpl()->ForceUpdateSelection(sal_False);
986 if ( !m_pFormView || !m_bDesignMode || !GetImpl()->onlyControlsAreMarked() )
987 rSet.DisableItem( nWhich );
988 else
990 sal_Bool bChecked = GetImpl()->IsPropBrwOpen() && !GetImpl()->isSolelySelected( GetImpl()->getCurrentForm() );
991 // if the property browser is open, and only controls are marked, and the current selection
992 // does not consist of only the current form, then the current selection is the (composition of)
993 // the currently marked controls
994 rSet.Put( SfxBoolItem( nWhich, bChecked ) );
996 } break;
998 case SID_FM_PROPERTIES:
1000 // der Impl eventuell die Moeglichjkeit geben, ihre an der aktuellen MarkList ausgerichteten Objekte
1001 // auf den neuesten Stand zu bringen
1002 if (GetImpl()->IsSelectionUpdatePending())
1003 GetImpl()->ForceUpdateSelection(sal_False);
1005 if ( !m_pFormView || !m_bDesignMode || !GetImpl()->getCurrentForm().is() )
1006 rSet.DisableItem( nWhich );
1007 else
1009 sal_Bool bChecked = GetImpl()->IsPropBrwOpen() && GetImpl()->isSolelySelected( GetImpl()->getCurrentForm() );
1010 rSet.Put(SfxBoolItem(nWhich, bChecked));
1012 } break;
1013 case SID_FM_TAB_DIALOG:
1014 // der Impl eventuell die Moeglichjkeit geben, ihre an der aktuellen MarkList ausgerichteten Objekte
1015 // auf den neuesten Stand zu bringen
1016 if (GetImpl()->IsSelectionUpdatePending())
1017 GetImpl()->ForceUpdateSelection(sal_False);
1019 if (!m_pFormView || !m_bDesignMode || !GetImpl()->getCurrentForm().is() )
1020 rSet.DisableItem( nWhich );
1021 break;
1022 case SID_FM_CONFIG:
1023 rSet.Put(SfxUInt16Item(nWhich, m_nLastSlot));
1024 break;
1025 case SID_FM_DESIGN_MODE:
1026 if (!m_pFormView || GetImpl()->IsReadonlyDoc() )
1027 rSet.DisableItem( nWhich );
1028 else
1029 rSet.Put( SfxBoolItem(nWhich, m_bDesignMode) );
1030 break;
1031 case SID_FM_SEARCH:
1032 case SID_FM_RECORD_FIRST:
1033 case SID_FM_RECORD_NEXT:
1034 case SID_FM_RECORD_PREV:
1035 case SID_FM_RECORD_LAST:
1036 case SID_FM_RECORD_NEW:
1037 case SID_FM_RECORD_DELETE:
1038 case SID_FM_RECORD_ABSOLUTE:
1039 case SID_FM_RECORD_TOTAL:
1040 case SID_FM_RECORD_SAVE:
1041 case SID_FM_RECORD_UNDO:
1042 case SID_FM_FORM_FILTERED:
1043 case SID_FM_REMOVE_FILTER_SORT:
1044 case SID_FM_SORTUP:
1045 case SID_FM_SORTDOWN:
1046 case SID_FM_ORDERCRIT:
1047 case SID_FM_FILTER_START:
1048 case SID_FM_AUTOFILTER:
1049 case SID_FM_REFRESH:
1050 case SID_FM_REFRESH_FORM_CONTROL:
1051 case SID_FM_VIEW_AS_GRID:
1052 GetFormState(rSet,nWhich);
1053 break;
1055 case SID_FM_CHANGECONTROLTYPE:
1057 if ( !m_pFormView || !m_bDesignMode )
1058 rSet.DisableItem( nWhich );
1059 else
1061 if ( !GetImpl()->canConvertCurrentSelectionToControl( OBJ_FM_FIXEDTEXT ) )
1062 // if it cannot be converted to a fixed text, it is no single control
1063 rSet.DisableItem( nWhich );
1065 } break;
1067 case SID_FM_CONVERTTO_FILECONTROL :
1068 case SID_FM_CONVERTTO_CURRENCY :
1069 case SID_FM_CONVERTTO_PATTERN :
1070 case SID_FM_CONVERTTO_IMAGECONTROL :
1071 case SID_FM_CONVERTTO_SCROLLBAR :
1072 case SID_FM_CONVERTTO_NAVIGATIONBAR :
1073 case SID_FM_CONVERTTO_IMAGEBUTTON :
1074 case SID_FM_CONVERTTO_EDIT :
1075 case SID_FM_CONVERTTO_BUTTON :
1076 case SID_FM_CONVERTTO_FIXEDTEXT :
1077 case SID_FM_CONVERTTO_LISTBOX :
1078 case SID_FM_CONVERTTO_CHECKBOX :
1079 case SID_FM_CONVERTTO_RADIOBUTTON :
1080 case SID_FM_CONVERTTO_GROUPBOX :
1081 case SID_FM_CONVERTTO_COMBOBOX :
1082 case SID_FM_CONVERTTO_DATE :
1083 case SID_FM_CONVERTTO_TIME :
1084 case SID_FM_CONVERTTO_NUMERIC :
1085 case SID_FM_CONVERTTO_FORMATTED :
1086 case SID_FM_CONVERTTO_SPINBUTTON :
1088 if ( !m_pFormView || !m_bDesignMode || !GetImpl()->canConvertCurrentSelectionToControl( nWhich ) )
1089 rSet.DisableItem( nWhich );
1090 else
1092 rSet.Put( SfxBoolItem( nWhich, sal_False ) );
1093 // just to have a defined state (available and not checked)
1096 break;
1098 nWhich = aIter.NextWhich();
1102 //------------------------------------------------------------------------
1103 void FmFormShell::GetFormState(SfxItemSet &rSet, sal_uInt16 nWhich)
1105 if ( !GetImpl()->getNavController().is()
1106 || !isRowSetAlive(GetImpl()->getNavController()->getModel())
1107 || !m_pFormView
1108 || m_bDesignMode
1109 || !GetImpl()->getActiveForm().is()
1110 || GetImpl()->isInFilterMode()
1112 rSet.DisableItem(nWhich);
1113 else
1115 sal_Bool bEnable = sal_False;
1118 switch (nWhich)
1120 case SID_FM_VIEW_AS_GRID:
1121 if (GetImpl()->getHostFrame().is() && GetImpl()->getNavController().is())
1123 bEnable = sal_True;
1124 sal_Bool bDisplayingCurrent =
1125 GetImpl()->getInternalForm(
1126 Reference< XForm >( GetImpl()->getNavController()->getModel(), UNO_QUERY )
1127 ) == GetImpl()->getExternallyDisplayedForm();
1128 rSet.Put(SfxBoolItem(nWhich, bDisplayingCurrent));
1130 break;
1132 case SID_FM_SEARCH:
1134 Reference< ::com::sun::star::beans::XPropertySet > xNavSet(GetImpl()->getActiveForm(), UNO_QUERY);
1135 sal_Int32 nCount = ::comphelper::getINT32(xNavSet->getPropertyValue(FM_PROP_ROWCOUNT));
1136 bEnable = nCount != 0;
1137 } break;
1138 case SID_FM_RECORD_ABSOLUTE:
1139 case SID_FM_RECORD_TOTAL:
1141 FeatureState aState;
1142 GetImpl()->getNavControllerFeatures()->getState( nWhich, aState );
1143 if ( SID_FM_RECORD_ABSOLUTE == nWhich )
1145 sal_Int32 nPosition = 0;
1146 aState.State >>= nPosition;
1147 rSet.Put( SfxInt32Item( nWhich, nPosition ) );
1149 else if ( SID_FM_RECORD_TOTAL == nWhich )
1151 ::rtl::OUString sTotalCount;
1152 aState.State >>= sTotalCount;
1153 rSet.Put( SfxStringItem( nWhich, sTotalCount ) );
1155 bEnable = aState.Enabled;
1157 break;
1159 // first, prev, next, last, and absolute affect the nav controller, not the
1160 // active controller
1161 case SID_FM_RECORD_FIRST:
1162 case SID_FM_RECORD_PREV:
1163 case SID_FM_RECORD_NEXT:
1164 case SID_FM_RECORD_LAST:
1165 case SID_FM_RECORD_NEW:
1166 case SID_FM_RECORD_SAVE:
1167 case SID_FM_RECORD_UNDO:
1168 case SID_FM_RECORD_DELETE:
1169 case SID_FM_REFRESH:
1170 case SID_FM_REFRESH_FORM_CONTROL:
1171 case SID_FM_REMOVE_FILTER_SORT:
1172 case SID_FM_SORTUP:
1173 case SID_FM_SORTDOWN:
1174 case SID_FM_AUTOFILTER:
1175 case SID_FM_ORDERCRIT:
1176 bEnable = GetImpl()->IsFormSlotEnabled( nWhich );
1177 break;
1179 case SID_FM_FORM_FILTERED:
1181 FeatureState aState;
1182 bEnable = GetImpl()->IsFormSlotEnabled( nWhich, &aState );
1184 rSet.Put( SfxBoolItem( nWhich, ::comphelper::getBOOL( aState.State ) ) );
1186 break;
1188 case SID_FM_FILTER_START:
1189 bEnable = GetImpl()->getActiveControllerFeatures()->canDoFormFilter();
1190 break;
1193 catch( const Exception& )
1195 OSL_FAIL( "FmFormShell::GetFormState: caught an exception while determining the state!" );
1197 if (!bEnable)
1198 rSet.DisableItem(nWhich);
1202 //------------------------------------------------------------------------
1203 FmFormPage* FmFormShell::GetCurPage() const
1205 FmFormPage* pP = NULL;
1206 if (m_pFormView && m_pFormView->GetSdrPageView())
1207 pP = PTR_CAST(FmFormPage,m_pFormView->GetSdrPageView()->GetPage());
1208 return pP;
1211 //------------------------------------------------------------------------
1212 void FmFormShell::SetView( FmFormView* _pView )
1214 if ( m_pFormView )
1216 if ( IsActive() )
1217 GetImpl()->viewDeactivated( *m_pFormView );
1219 m_pFormView->SetFormShell( NULL, FmFormView::FormShellAccess() );
1220 m_pFormView = NULL;
1221 m_pFormModel = NULL;
1224 if ( !_pView )
1225 return;
1227 m_pFormView = _pView;
1228 m_pFormView->SetFormShell( this, FmFormView::FormShellAccess() );
1229 m_pFormModel = (FmFormModel*)m_pFormView->GetModel();
1231 impl_setDesignMode( m_pFormView->IsDesignMode() );
1233 // We activate our view if we are activated ourself, but sometimes the Activate precedes the SetView.
1234 // But here we know both the view and our activation state so we at least are able to pass the latter
1235 // to the former.
1236 // FS - 30.06.99 - 67308
1237 if ( IsActive() )
1238 GetImpl()->viewActivated( *m_pFormView );
1241 //------------------------------------------------------------------------
1242 void FmFormShell::DetermineForms(sal_Bool bInvalidate)
1244 // Existieren Formulare auf der aktuellen Page
1245 sal_Bool bForms = GetImpl()->hasForms();
1246 if (bForms != m_bHasForms)
1248 m_bHasForms = bForms;
1249 if (bInvalidate)
1250 UIFeatureChanged();
1254 //------------------------------------------------------------------------
1255 sal_Bool FmFormShell::GetY2KState(sal_uInt16& nReturn)
1257 return GetImpl()->GetY2KState(nReturn);
1260 //------------------------------------------------------------------------
1261 void FmFormShell::SetY2KState(sal_uInt16 n)
1263 GetImpl()->SetY2KState(n);
1266 //------------------------------------------------------------------------
1267 void FmFormShell::Activate(sal_Bool bMDI)
1269 SfxShell::Activate(bMDI);
1271 if ( m_pFormView )
1272 GetImpl()->viewActivated( *m_pFormView, sal_True );
1275 //------------------------------------------------------------------------
1276 void FmFormShell::Deactivate(sal_Bool bMDI)
1278 SfxShell::Deactivate(bMDI);
1280 if ( m_pFormView )
1281 GetImpl()->viewDeactivated( *m_pFormView, sal_False );
1284 //------------------------------------------------------------------------
1285 void FmFormShell::ExecuteTextAttribute( SfxRequest& _rReq )
1287 m_pImpl->ExecuteTextAttribute( _rReq );
1290 //------------------------------------------------------------------------
1291 void FmFormShell::GetTextAttributeState( SfxItemSet& _rSet )
1293 m_pImpl->GetTextAttributeState( _rSet );
1296 //------------------------------------------------------------------------
1297 bool FmFormShell::IsActiveControl() const
1299 return m_pImpl->IsActiveControl();
1302 //------------------------------------------------------------------------
1303 void FmFormShell::ForgetActiveControl()
1305 m_pImpl->ForgetActiveControl();
1308 //------------------------------------------------------------------------
1309 void FmFormShell::SetControlActivationHandler( const Link& _rHdl )
1311 m_pImpl->SetControlActivationHandler( _rHdl );
1314 //------------------------------------------------------------------------
1315 namespace
1317 SdrUnoObj* lcl_findUnoObject( const SdrObjList& _rObjList, const Reference< XControlModel >& _rxModel )
1319 SdrObjListIter aIter( _rObjList );
1320 while ( aIter.IsMore() )
1322 SdrObject* pObject = aIter.Next();
1323 SdrUnoObj* pUnoObject = pObject ? PTR_CAST( SdrUnoObj, pObject ) : NULL;
1324 if ( !pUnoObject )
1325 continue;
1327 Reference< XControlModel > xControlModel = pUnoObject->GetUnoControlModel();
1328 if ( !xControlModel.is() )
1329 continue;
1331 if ( _rxModel == xControlModel )
1332 return pUnoObject;
1334 return NULL;
1338 //------------------------------------------------------------------------
1339 void FmFormShell::ToggleControlFocus( const SdrUnoObj& i_rUnoObject, const SdrView& i_rView, OutputDevice& i_rDevice ) const
1343 // check if the focus currently is in a control
1344 // Well, okay, do it the other way 'round: Check whether the current control of the active controller
1345 // actually has the focus. This should be equivalent.
1346 const bool bHasControlFocus = GetImpl()->HasControlFocus();
1348 if ( bHasControlFocus )
1350 Window* pWindow( dynamic_cast< Window* >( &i_rDevice ) );
1351 OSL_ENSURE( pWindow, "FmFormShell::ToggleControlFocus: I need a Window, really!" );
1352 if ( pWindow )
1353 pWindow->GrabFocus();
1355 else
1357 Reference< XControl > xControl;
1358 GetFormControl( i_rUnoObject.GetUnoControlModel(), i_rView, i_rDevice, xControl );
1359 Reference< XWindow > xControlWindow( xControl, UNO_QUERY );
1360 if ( xControlWindow.is() )
1361 xControlWindow->setFocus();
1364 catch( const Exception& )
1366 DBG_UNHANDLED_EXCEPTION();
1370 //------------------------------------------------------------------------
1371 namespace
1373 class FocusableControlsFilter : public ::svx::ISdrObjectFilter
1375 public:
1376 FocusableControlsFilter( const SdrView& i_rView, const OutputDevice& i_rDevice )
1377 :m_rView( i_rView )
1378 ,m_rDevice( i_rDevice )
1382 public:
1383 virtual bool includeObject( const SdrObject& i_rObject ) const
1385 const SdrUnoObj* pUnoObj = dynamic_cast< const SdrUnoObj* >( &i_rObject );
1386 if ( !pUnoObj )
1387 return false;
1389 Reference< XControl > xControl = pUnoObj->GetUnoControl( m_rView, m_rDevice );
1390 return FmXFormView::isFocusable( xControl );
1393 private:
1394 const SdrView& m_rView;
1395 const OutputDevice& m_rDevice;
1399 //------------------------------------------------------------------------
1400 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1401 ::std::auto_ptr< ::svx::ISdrObjectFilter > FmFormShell::CreateFocusableControlFilter( const SdrView& i_rView, const OutputDevice& i_rDevice ) const
1403 ::std::auto_ptr< ::svx::ISdrObjectFilter > pFilter;
1405 if ( !i_rView.IsDesignMode() )
1406 pFilter.reset( new FocusableControlsFilter( i_rView, i_rDevice ) );
1408 return pFilter;
1410 SAL_WNODEPRECATED_DECLARATIONS_POP
1412 //------------------------------------------------------------------------
1413 SdrUnoObj* FmFormShell::GetFormControl( const Reference< XControlModel >& _rxModel, const SdrView& _rView, const OutputDevice& _rDevice, Reference< XControl >& _out_rxControl ) const
1415 if ( !_rxModel.is() )
1416 return NULL;
1418 // we can only retrieve controls for SdrObjects which belong to page which is actually displayed in the given view
1419 SdrPageView* pPageView = _rView.GetSdrPageView();
1420 SdrPage* pPage = pPageView ? pPageView->GetPage() : NULL;
1421 OSL_ENSURE( pPage, "FmFormShell::GetFormControl: no page displayed in the given view!" );
1422 if ( !pPage )
1423 return NULL;
1425 SdrUnoObj* pUnoObject = lcl_findUnoObject( *pPage, _rxModel );
1426 if ( pUnoObject )
1428 _out_rxControl = pUnoObject->GetUnoControl( _rView, _rDevice );
1429 return pUnoObject;
1432 #if OSL_DEBUG_LEVEL > 0
1433 // perhaps we are fed with a control model which lives on a page other than the one displayed
1434 // in the given view. This is worth being reported as error, in non-product builds.
1435 FmFormModel* pModel = GetFormModel();
1436 if ( pModel )
1438 sal_uInt16 pageCount = pModel->GetPageCount();
1439 for ( sal_uInt16 page = 0; page < pageCount; ++page )
1441 pPage = pModel->GetPage( page );
1442 OSL_ENSURE( pPage, "FmFormShell::GetFormControl: NULL page encountered!" );
1443 if ( !pPage )
1444 continue;
1446 pUnoObject = lcl_findUnoObject( *pPage, _rxModel );
1447 OSL_ENSURE( !pUnoObject, "FmFormShell::GetFormControl: the given control model belongs to a wrong page (displayed elsewhere)!" );
1450 #endif
1452 return NULL;
1455 //------------------------------------------------------------------------
1456 Reference< runtime::XFormController > FmFormShell::GetFormController( const Reference< XForm >& _rxForm, const SdrView& _rView, const OutputDevice& _rDevice ) const
1458 const FmFormView* pFormView = dynamic_cast< const FmFormView* >( &_rView );
1459 if ( !pFormView )
1460 return NULL;
1462 return pFormView->GetFormController( _rxForm, _rDevice );
1465 //------------------------------------------------------------------------
1466 void FmFormShell::SetDesignMode( sal_Bool _bDesignMode )
1468 if ( _bDesignMode == m_bDesignMode )
1469 return;
1471 FmFormModel* pModel = GetFormModel();
1472 if (pModel)
1473 // fuer die Zeit des Uebergangs das Undo-Environment ausschalten, das sichert, dass man dort auch nicht-transiente
1474 // Properties mal eben aendern kann (sollte allerdings mit Vorsicht genossen und beim Rueckschalten des Modes
1475 // auch immer wieder rueckgaegig gemacht werden. Ein Beispiel ist das Setzen der maximalen Text-Laenge durch das
1476 // OEditModel an seinem Control.)
1477 pModel->GetUndoEnv().Lock();
1479 // dann die eigentliche Umschaltung
1480 if ( m_bDesignMode || PrepareClose( sal_True ) )
1481 impl_setDesignMode(!m_bDesignMode );
1483 // und mein Undo-Environment wieder an
1484 if ( pModel )
1485 pModel->GetUndoEnv().UnLock();
1488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */