Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / form / fmshell.cxx
blob987e729e645b970537333758e243406f2fb3fb97
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "fmvwimp.hxx"
21 #include <svx/fmshell.hxx>
22 #include "svx/fmtools.hxx"
23 #include "fmservs.hxx"
24 #include "fmprop.hrc"
25 #include "fmpgeimp.hxx"
26 #include "fmitems.hxx"
27 #include "fmundo.hxx"
28 #include <vcl/waitobj.hxx>
29 #include <com/sun/star/form/XLoadable.hpp>
30 #include <com/sun/star/container/XNamed.hpp>
31 #include <com/sun/star/sdbcx/Privilege.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/beans/XMultiPropertySet.hpp>
34 #include <com/sun/star/beans/XFastPropertySet.hpp>
35 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/container/XNameContainer.hpp>
38 #include <com/sun/star/awt/XTabControllerModel.hpp>
39 #include <sfx2/viewfrm.hxx>
40 #include <vcl/wrkwin.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <svl/whiter.hxx>
43 #include <sfx2/app.hxx>
44 #include <svl/intitem.hxx>
45 #include <svl/visitem.hxx>
46 #include <unotools/moduleoptions.hxx>
47 #include <sfx2/objface.hxx>
48 #include <sfx2/request.hxx>
49 #include <sfx2/dispatch.hxx>
50 #include <sfx2/objsh.hxx>
51 #include <svx/svdobj.hxx>
52 #include <svx/fmpage.hxx>
53 #include "svx/svditer.hxx"
54 #include "fmobj.hxx"
56 #include <svx/svxids.hrc>
58 #include "svx/fmresids.hrc"
59 #include "fmexch.hxx"
60 #include <svx/fmglob.hxx>
61 #include <svl/eitem.hxx>
62 #include <tools/shl.hxx>
63 #include <tools/diagnose_ex.h>
64 #include <svx/svdpage.hxx>
65 #include <svx/fmmodel.hxx>
66 #include <svx/dialmgr.hxx>
67 #include "fmshimp.hxx"
68 #include <svx/svdpagv.hxx>
69 #include <sfx2/objitem.hxx>
70 #include <sfx2/viewsh.hxx>
71 #include "fmexpl.hxx"
72 #include "formcontrolling.hxx"
73 #include <svl/numuno.hxx>
74 #include <connectivity/dbtools.hxx>
75 #include <comphelper/types.hxx>
76 #include <comphelper/processfactory.hxx>
77 #include "fmdocumentclassification.hxx"
78 #include "formtoolbars.hxx"
80 #include <svx/svxdlg.hxx>
81 #include <svx/dialogs.hrc>
83 #include "svx/sdrobjectfilter.hxx"
85 #define FmFormShell
86 #include "svxslots.hxx"
88 #include "tbxform.hxx"
89 #include <comphelper/property.hxx>
90 #include <com/sun/star/beans/PropertyValue.hpp>
92 #include <boost/scoped_ptr.hpp>
94 // wird fuer Invalidate verwendet -> mitpflegen
95 // aufsteigend sortieren !!!!!!
96 sal_uInt16 ControllerSlotMap[] = // slots des Controllers
98 SID_FM_CONFIG,
99 SID_FM_PUSHBUTTON,
100 SID_FM_RADIOBUTTON,
101 SID_FM_CHECKBOX,
102 SID_FM_FIXEDTEXT,
103 SID_FM_GROUPBOX,
104 SID_FM_EDIT,
105 SID_FM_LISTBOX,
106 SID_FM_COMBOBOX,
107 SID_FM_DBGRID,
108 SID_FM_IMAGEBUTTON,
109 SID_FM_FILECONTROL,
110 SID_FM_NAVIGATIONBAR,
111 SID_FM_CTL_PROPERTIES,
112 SID_FM_PROPERTIES,
113 SID_FM_TAB_DIALOG,
114 SID_FM_ADD_FIELD,
115 SID_FM_DESIGN_MODE,
116 SID_FM_SHOW_FMEXPLORER,
117 SID_FM_SHOW_PROPERTIES,
118 SID_FM_FMEXPLORER_CONTROL,
119 SID_FM_DATEFIELD,
120 SID_FM_TIMEFIELD,
121 SID_FM_NUMERICFIELD,
122 SID_FM_CURRENCYFIELD,
123 SID_FM_PATTERNFIELD,
124 SID_FM_OPEN_READONLY,
125 SID_FM_IMAGECONTROL,
126 SID_FM_USE_WIZARDS,
127 SID_FM_FORMATTEDFIELD,
128 SID_FM_FILTER_NAVIGATOR,
129 SID_FM_AUTOCONTROLFOCUS,
130 SID_FM_SCROLLBAR,
131 SID_FM_SPINBUTTON,
132 SID_FM_SHOW_DATANAVIGATOR,
133 SID_FM_DATANAVIGATOR_CONTROL,
138 using namespace ::com::sun::star::uno;
139 using namespace ::com::sun::star::awt;
140 using namespace ::com::sun::star::sdbc;
141 using namespace ::com::sun::star::sdbcx;
142 using namespace ::com::sun::star::beans;
143 using namespace ::com::sun::star::form;
144 using namespace ::com::sun::star::form::runtime;
145 using namespace ::com::sun::star::frame;
146 using namespace ::svxform;
149 // class FmDesignModeChangedHint
151 TYPEINIT1( FmDesignModeChangedHint, SfxHint );
154 FmDesignModeChangedHint::FmDesignModeChangedHint( bool bDesMode )
155 :m_bDesignMode( bDesMode )
160 FmDesignModeChangedHint::~FmDesignModeChangedHint()
164 const sal_uInt32 FM_UI_FEATURE_SHOW_DATABASEBAR = 0x00000001;
165 const sal_uInt32 FM_UI_FEATURE_SHOW_FIELD = 0x00000002;
166 const sal_uInt32 FM_UI_FEATURE_SHOW_PROPERTIES = 0x00000004;
167 const sal_uInt32 FM_UI_FEATURE_SHOW_EXPLORER = 0x00000008;
168 const sal_uInt32 FM_UI_FEATURE_SHOW_FILTERBAR = 0x00000010;
169 const sal_uInt32 FM_UI_FEATURE_SHOW_FILTERNAVIGATOR = 0x00000020;
170 const sal_uInt32 FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR = 0x00000040;
171 const sal_uInt32 FM_UI_FEATURE_TB_CONTROLS = 0x00000080;
172 const sal_uInt32 FM_UI_FEATURE_TB_MORECONTROLS = 0x00000100;
173 const sal_uInt32 FM_UI_FEATURE_TB_FORMDESIGN = 0x00000200;
174 const sal_uInt32 FM_UI_FEATURE_SHOW_DATANAVIGATOR = 0x00000400;
176 SFX_IMPL_INTERFACE(FmFormShell, SfxShell, SVX_RES(RID_STR_FORMSHELL))
178 void FmFormShell::InitInterface_Impl()
180 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_NAVIGATION|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_READONLYDOC,
181 SVX_RES(RID_SVXTBX_FORM_NAVIGATION),
182 FM_UI_FEATURE_SHOW_DATABASEBAR);
184 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_NAVIGATION|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_READONLYDOC,
185 SVX_RES(RID_SVXTBX_FORM_FILTER),
186 FM_UI_FEATURE_SHOW_FILTERBAR);
188 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_READONLYDOC,
189 SVX_RES(RID_SVXTBX_TEXT_CONTROL_ATTRIBUTES),
190 FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR);
192 GetStaticInterface()->RegisterChildWindow(SID_FM_ADD_FIELD, false, FM_UI_FEATURE_SHOW_FIELD);
193 GetStaticInterface()->RegisterChildWindow(SID_FM_SHOW_PROPERTIES, false, FM_UI_FEATURE_SHOW_PROPERTIES);
194 GetStaticInterface()->RegisterChildWindow(SID_FM_SHOW_FMEXPLORER, false, FM_UI_FEATURE_SHOW_EXPLORER);
195 GetStaticInterface()->RegisterChildWindow(SID_FM_FILTER_NAVIGATOR, false, FM_UI_FEATURE_SHOW_FILTERNAVIGATOR);
196 GetStaticInterface()->RegisterChildWindow(SID_FM_SHOW_DATANAVIGATOR, false, FM_UI_FEATURE_SHOW_DATANAVIGATOR);
198 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD,
199 SVX_RES(RID_SVXTBX_CONTROLS),
200 FM_UI_FEATURE_TB_CONTROLS);
202 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD,
203 SVX_RES(RID_SVXTBX_MORECONTROLS),
204 FM_UI_FEATURE_TB_MORECONTROLS);
206 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD,
207 SVX_RES(RID_SVXTBX_FORMDESIGN),
208 FM_UI_FEATURE_TB_FORMDESIGN);
211 TYPEINIT1(FmFormShell,SfxShell)
213 FmFormShell::FmFormShell( SfxViewShell* _pParent, FmFormView* pView )
214 :SfxShell(_pParent)
215 ,m_pImpl(new FmXFormShell(*this, _pParent->GetViewFrame()))
216 ,m_pFormView( pView )
217 ,m_pFormModel( NULL )
218 ,m_pParentShell(_pParent)
219 ,m_nLastSlot( 0 )
220 ,m_bDesignMode( true )
221 ,m_bHasForms(false)
223 m_pImpl->acquire();
224 SetPool( &SFX_APP()->GetPool() );
225 SetName( OUString("Form") );
227 SetView(m_pFormView);
231 FmFormShell::~FmFormShell()
233 if ( m_pFormView )
234 SetView( NULL );
236 m_pImpl->dispose();
237 m_pImpl->release();
238 m_pImpl = NULL;
242 void FmFormShell::NotifyMarkListChanged(FmFormView* pWhichView)
244 FmNavViewMarksChanged aChangeNotification(pWhichView);
245 Broadcast(aChangeNotification);
249 bool FmFormShell::PrepareClose(bool bUI)
251 if ( GetImpl()->didPrepareClose() )
252 // we already did a PrepareClose for the current modifications of the current form
253 return true;
255 bool bResult = true;
256 // Save the data records, not in DesignMode and FilterMode
257 if (!m_bDesignMode && !GetImpl()->isInFilterMode() &&
258 m_pFormView && m_pFormView->GetActualOutDev() &&
259 m_pFormView->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW)
261 SdrPageView* pCurPageView = m_pFormView->GetSdrPageView();
263 // sal_uInt16 nPos = pCurPageView ? pCurPageView->GetWinList().Find((OutputDevice*)m_pFormView->GetActualOutDev()) : SDRPAGEVIEWWIN_NOTFOUND;
264 SdrPageWindow* pWindow = pCurPageView ? pCurPageView->FindPageWindow(*((OutputDevice*)m_pFormView->GetActualOutDev())) : 0L;
266 if(pWindow)
268 // Zunaechst werden die aktuellen Inhalte der Controls gespeichert
269 // Wenn alles glatt gelaufen ist, werden die modifizierten Datensaetze gespeichert
270 if ( GetImpl()->getActiveController().is() )
272 const ::svx::ControllerFeatures& rController = GetImpl()->getActiveControllerFeatures();
273 if ( rController->commitCurrentControl() )
275 bool bModified = rController->isModifiedRow();
277 if ( bModified && bUI )
279 QueryBox aQry(NULL, SVX_RES(RID_QRY_SAVEMODIFIED));
280 switch (aQry.Execute())
282 case RET_NO:
283 bModified = false;
284 GetImpl()->didPrepareClose( true );
285 break;
287 case RET_CANCEL:
288 return false;
291 if ( bModified )
292 bResult = rController->commitCurrentRecord( );
298 return bResult;
302 void FmFormShell::impl_setDesignMode(bool bDesign)
304 if (m_pFormView)
306 if (!bDesign)
307 m_nLastSlot = SID_FM_DESIGN_MODE;
309 GetImpl()->SetDesignMode(bDesign);
310 // mein m_bDesignMode wird auch von der Impl gesetzt ...
312 else
314 m_bHasForms = false;
315 m_bDesignMode = bDesign;
316 UIFeatureChanged();
319 GetViewShell()->GetViewFrame()->GetBindings().Invalidate(ControllerSlotMap);
323 bool FmFormShell::HasUIFeature( sal_uInt32 nFeature )
325 bool bResult = false;
326 if ((nFeature & FM_UI_FEATURE_SHOW_DATABASEBAR) == FM_UI_FEATURE_SHOW_DATABASEBAR)
328 // nur wenn auch formulare verfuegbar
329 bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar() && !GetImpl()->isInFilterMode();
331 else if ((nFeature & FM_UI_FEATURE_SHOW_FILTERBAR) == FM_UI_FEATURE_SHOW_FILTERBAR)
333 // nur wenn auch formulare verfuegbar
334 bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar() && GetImpl()->isInFilterMode();
336 else if ((nFeature & FM_UI_FEATURE_SHOW_FILTERNAVIGATOR) == FM_UI_FEATURE_SHOW_FILTERNAVIGATOR)
338 bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar() && GetImpl()->isInFilterMode();
340 else if ((nFeature & FM_UI_FEATURE_SHOW_FIELD) == FM_UI_FEATURE_SHOW_FIELD)
342 bResult = m_bDesignMode && m_pFormView && m_bHasForms;
344 else if ((nFeature & FM_UI_FEATURE_SHOW_PROPERTIES) == FM_UI_FEATURE_SHOW_PROPERTIES)
346 bResult = m_bDesignMode && m_pFormView && m_bHasForms;
348 else if ((nFeature & FM_UI_FEATURE_SHOW_EXPLORER) == FM_UI_FEATURE_SHOW_EXPLORER)
350 bResult = m_bDesignMode; // OJ #101593# && m_pFormView && m_bHasForms;
352 else if ( ( nFeature & FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR ) == FM_UI_FEATURE_SHOW_TEXT_CONTROL_BAR )
354 bResult = !GetImpl()->IsReadonlyDoc() && m_pImpl->IsActiveControl( true );
356 else if ((nFeature & FM_UI_FEATURE_SHOW_DATANAVIGATOR) == FM_UI_FEATURE_SHOW_DATANAVIGATOR)
358 bResult = GetImpl()->isEnhancedForm();
360 else if ( ( ( nFeature & FM_UI_FEATURE_TB_CONTROLS ) == FM_UI_FEATURE_TB_CONTROLS )
361 || ( ( nFeature & FM_UI_FEATURE_TB_MORECONTROLS ) == FM_UI_FEATURE_TB_MORECONTROLS )
362 || ( ( nFeature & FM_UI_FEATURE_TB_FORMDESIGN ) == FM_UI_FEATURE_TB_FORMDESIGN )
365 bResult = true;
368 return bResult;
372 void FmFormShell::Execute(SfxRequest &rReq)
374 sal_uInt16 nSlot = rReq.GetSlot();
377 // MasterSlot setzen
378 switch( nSlot )
380 case SID_FM_PUSHBUTTON:
381 case SID_FM_RADIOBUTTON:
382 case SID_FM_CHECKBOX:
383 case SID_FM_FIXEDTEXT:
384 case SID_FM_GROUPBOX:
385 case SID_FM_LISTBOX:
386 case SID_FM_COMBOBOX:
387 case SID_FM_NAVIGATIONBAR:
388 case SID_FM_EDIT:
389 case SID_FM_DBGRID:
390 case SID_FM_IMAGEBUTTON:
391 case SID_FM_IMAGECONTROL:
392 case SID_FM_FILECONTROL:
393 case SID_FM_DATEFIELD:
394 case SID_FM_TIMEFIELD:
395 case SID_FM_NUMERICFIELD:
396 case SID_FM_CURRENCYFIELD:
397 case SID_FM_PATTERNFIELD:
398 case SID_FM_FORMATTEDFIELD:
399 case SID_FM_SCROLLBAR:
400 case SID_FM_SPINBUTTON:
401 m_nLastSlot = nSlot;
402 GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SID_FM_CONFIG );
403 break;
407 // Identifier und Inventor des Uno-Controls setzen
408 sal_uInt16 nIdentifier = 0;
409 switch( nSlot )
411 case SID_FM_CHECKBOX:
412 nIdentifier = OBJ_FM_CHECKBOX;
413 break;
414 case SID_FM_PUSHBUTTON:
415 nIdentifier = OBJ_FM_BUTTON;
416 break;
417 case SID_FM_FIXEDTEXT:
418 nIdentifier = OBJ_FM_FIXEDTEXT;
419 break;
420 case SID_FM_LISTBOX:
421 nIdentifier = OBJ_FM_LISTBOX;
422 break;
423 case SID_FM_EDIT:
424 nIdentifier = OBJ_FM_EDIT;
425 break;
426 case SID_FM_RADIOBUTTON:
427 nIdentifier = OBJ_FM_RADIOBUTTON;
428 break;
429 case SID_FM_GROUPBOX:
430 nIdentifier = OBJ_FM_GROUPBOX;
431 break;
432 case SID_FM_COMBOBOX:
433 nIdentifier = OBJ_FM_COMBOBOX;
434 break;
435 case SID_FM_NAVIGATIONBAR:
436 nIdentifier = OBJ_FM_NAVIGATIONBAR;
437 break;
438 case SID_FM_DBGRID:
439 nIdentifier = OBJ_FM_GRID;
440 break;
441 case SID_FM_IMAGEBUTTON:
442 nIdentifier = OBJ_FM_IMAGEBUTTON;
443 break;
444 case SID_FM_IMAGECONTROL:
445 nIdentifier = OBJ_FM_IMAGECONTROL;
446 break;
447 case SID_FM_FILECONTROL:
448 nIdentifier = OBJ_FM_FILECONTROL;
449 break;
450 case SID_FM_DATEFIELD:
451 nIdentifier = OBJ_FM_DATEFIELD;
452 break;
453 case SID_FM_TIMEFIELD:
454 nIdentifier = OBJ_FM_TIMEFIELD;
455 break;
456 case SID_FM_NUMERICFIELD:
457 nIdentifier = OBJ_FM_NUMERICFIELD;
458 break;
459 case SID_FM_CURRENCYFIELD:
460 nIdentifier = OBJ_FM_CURRENCYFIELD;
461 break;
462 case SID_FM_PATTERNFIELD:
463 nIdentifier = OBJ_FM_PATTERNFIELD;
464 break;
465 case SID_FM_FORMATTEDFIELD:
466 nIdentifier = OBJ_FM_FORMATTEDFIELD;
467 break;
468 case SID_FM_SCROLLBAR:
469 nIdentifier = OBJ_FM_SCROLLBAR;
470 break;
471 case SID_FM_SPINBUTTON:
472 nIdentifier = OBJ_FM_SPINBUTTON;
473 break;
476 switch ( nSlot )
478 case SID_FM_CHECKBOX:
479 case SID_FM_PUSHBUTTON:
480 case SID_FM_FIXEDTEXT:
481 case SID_FM_LISTBOX:
482 case SID_FM_EDIT:
483 case SID_FM_RADIOBUTTON:
484 case SID_FM_COMBOBOX:
485 case SID_FM_NAVIGATIONBAR:
486 case SID_FM_GROUPBOX:
487 case SID_FM_DBGRID:
488 case SID_FM_IMAGEBUTTON:
489 case SID_FM_IMAGECONTROL:
490 case SID_FM_FILECONTROL:
491 case SID_FM_DATEFIELD:
492 case SID_FM_TIMEFIELD:
493 case SID_FM_NUMERICFIELD:
494 case SID_FM_CURRENCYFIELD:
495 case SID_FM_PATTERNFIELD:
496 case SID_FM_FORMATTEDFIELD:
497 case SID_FM_SCROLLBAR:
498 case SID_FM_SPINBUTTON:
500 SFX_REQUEST_ARG( rReq, pGrabFocusItem, SfxBoolItem, SID_FM_TOGGLECONTROLFOCUS, false );
501 if ( pGrabFocusItem && pGrabFocusItem->GetValue() )
502 { // see below
503 SfxViewShell* pShell = GetViewShell();
504 Window* pShellWnd = pShell ? pShell->GetWindow() : NULL;
505 if ( pShellWnd )
506 pShellWnd->GrabFocus();
507 break;
510 SfxUInt16Item aIdentifierItem( SID_FM_CONTROL_IDENTIFIER, nIdentifier );
511 SfxUInt32Item aInventorItem( SID_FM_CONTROL_INVENTOR, FmFormInventor );
512 const SfxPoolItem* pArgs[] =
514 &aIdentifierItem, &aInventorItem, NULL
516 const SfxPoolItem* pInternalArgs[] =
518 NULL
521 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_CREATE_CONTROL, SFX_CALLMODE_ASYNCHRON,
522 pArgs, rReq.GetModifier(), pInternalArgs );
524 if ( rReq.GetModifier() & KEY_MOD1 )
526 // #99013# if selected with control key, return focus to current view
527 // do this asynchron, so that the creation can be finished first
528 // reusing the SID_FM_TOGGLECONTROLFOCUS is somewhat hacky ... which it wouldn't if it would have another
529 // name, so I do not really have a big problem with this ....
530 SfxBoolItem aGrabFocusIndicatorItem( SID_FM_TOGGLECONTROLFOCUS, true );
531 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( nSlot, SFX_CALLMODE_ASYNCHRON,
532 &aGrabFocusIndicatorItem, NULL );
535 rReq.Done();
536 } break;
539 // Individuelle Aktionen
540 switch( nSlot )
542 case SID_FM_MORE_CONTROLS:
543 case SID_FM_FORM_DESIGN_TOOLS:
545 FormToolboxes aToolboxAccess( GetImpl()->getHostFrame() );
546 aToolboxAccess.toggleToolbox( nSlot );
547 rReq.Done();
549 break;
551 case SID_FM_TOGGLECONTROLFOCUS:
553 FmFormView* pFormView = GetFormView();
554 if ( !pFormView )
555 break;
557 // if we execute this ourself, then either the application does not implement an own handling for this,
558 // of we're on the top of the dispatcher stack, which means a control has the focus.
559 // In the latter case, we put the focus to the document window, otherwise, we focus the first control
560 const bool bHasControlFocus = GetImpl()->HasControlFocus();
561 if ( bHasControlFocus )
563 const OutputDevice* pDevice = GetCurrentViewDevice();
564 Window* pWindow = dynamic_cast< Window* >( const_cast< OutputDevice* >( pDevice ) );
565 if ( pWindow )
566 pWindow->GrabFocus();
568 else
570 pFormView->GrabFirstControlFocus( );
573 break;
575 case SID_FM_VIEW_AS_GRID:
576 GetImpl()->CreateExternalView();
577 break;
578 case SID_FM_CONVERTTO_EDIT :
579 case SID_FM_CONVERTTO_BUTTON :
580 case SID_FM_CONVERTTO_FIXEDTEXT :
581 case SID_FM_CONVERTTO_LISTBOX :
582 case SID_FM_CONVERTTO_CHECKBOX :
583 case SID_FM_CONVERTTO_RADIOBUTTON :
584 case SID_FM_CONVERTTO_GROUPBOX :
585 case SID_FM_CONVERTTO_COMBOBOX :
586 case SID_FM_CONVERTTO_IMAGEBUTTON :
587 case SID_FM_CONVERTTO_FILECONTROL :
588 case SID_FM_CONVERTTO_DATE :
589 case SID_FM_CONVERTTO_TIME :
590 case SID_FM_CONVERTTO_NUMERIC :
591 case SID_FM_CONVERTTO_CURRENCY :
592 case SID_FM_CONVERTTO_PATTERN :
593 case SID_FM_CONVERTTO_IMAGECONTROL :
594 case SID_FM_CONVERTTO_FORMATTED :
595 case SID_FM_CONVERTTO_SCROLLBAR :
596 case SID_FM_CONVERTTO_SPINBUTTON :
597 case SID_FM_CONVERTTO_NAVIGATIONBAR :
598 GetImpl()->executeControlConversionSlot( nSlot );
599 // nach dem Konvertieren die Selektion neu bestimmern, da sich ja das selektierte Objekt
600 // geaendert hat
601 GetImpl()->SetSelection(GetFormView()->GetMarkedObjectList());
602 break;
603 case SID_FM_LEAVE_CREATE:
604 m_nLastSlot = 0;
605 GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SID_FM_CONFIG );
606 rReq.Done();
607 break;
608 case SID_FM_SHOW_PROPERTY_BROWSER:
610 SFX_REQUEST_ARG( rReq, pShowItem, SfxBoolItem, SID_FM_SHOW_PROPERTIES, false );
611 bool bShow = true;
612 if ( pShowItem )
613 bShow = pShowItem->GetValue();
614 GetImpl()->ShowSelectionProperties( bShow );
616 rReq.Done();
617 } break;
619 case SID_FM_PROPERTIES:
621 // PropertyBrowser anzeigen
622 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSlot, false);
623 bool bShow = pShowItem ? pShowItem->GetValue() : sal_True;
625 InterfaceBag aOnlyTheForm;
626 aOnlyTheForm.insert( Reference< XInterface >( GetImpl()->getCurrentForm(), UNO_QUERY ) );
627 GetImpl()->setCurrentSelection( aOnlyTheForm );
629 GetImpl()->ShowSelectionProperties( bShow );
631 rReq.Done();
632 } break;
634 case SID_FM_CTL_PROPERTIES:
636 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSlot, false);
637 bool bShow = pShowItem ? pShowItem->GetValue() : sal_True;
639 OSL_ENSURE( GetImpl()->onlyControlsAreMarked(), "FmFormShell::Execute: ControlProperties should be disabled!" );
640 if ( bShow )
641 GetImpl()->selectLastMarkedControls();
642 GetImpl()->ShowSelectionProperties( bShow );
644 rReq.Done();
645 } break;
646 case SID_FM_SHOW_PROPERTIES:
647 case SID_FM_ADD_FIELD:
648 case SID_FM_FILTER_NAVIGATOR:
649 case SID_FM_SHOW_DATANAVIGATOR :
651 GetViewShell()->GetViewFrame()->ChildWindowExecute( rReq );
652 rReq.Done();
653 } break;
654 case SID_FM_SHOW_FMEXPLORER:
656 if (!m_pFormView) // setzen der ::com::sun::star::sdbcx::View Forcieren
657 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute(SID_CREATE_SW_DRAWVIEW);
659 GetViewShell()->GetViewFrame()->ChildWindowExecute(rReq);
660 rReq.Done();
662 break;
664 case SID_FM_TAB_DIALOG:
666 GetImpl()->ExecuteTabOrderDialog( Reference< XTabControllerModel >( GetImpl()->getCurrentForm(), UNO_QUERY ) );
667 rReq.Done();
669 break;
671 case SID_FM_DESIGN_MODE:
673 SFX_REQUEST_ARG(rReq, pDesignItem, SfxBoolItem, nSlot, false);
674 bool bDesignMode = pDesignItem ? pDesignItem->GetValue() : !m_bDesignMode;
675 SetDesignMode( bDesignMode );
676 if ( m_bDesignMode == bDesignMode )
677 rReq.Done();
679 m_nLastSlot = SID_FM_DESIGN_MODE;
680 GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SID_FM_CONFIG );
682 break;
684 case SID_FM_AUTOCONTROLFOCUS:
686 FmFormModel* pModel = GetFormModel();
687 DBG_ASSERT(pModel, "FmFormShell::Execute : invalid call !");
688 // should have been disabled in GetState if we don't have a FormModel
689 pModel->SetAutoControlFocus( !pModel->GetAutoControlFocus() );
690 GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_AUTOCONTROLFOCUS);
692 break;
693 case SID_FM_OPEN_READONLY:
695 FmFormModel* pModel = GetFormModel();
696 DBG_ASSERT(pModel, "FmFormShell::Execute : invalid call !");
697 // should have been disabled in GetState if we don't have a FormModel
698 pModel->SetOpenInDesignMode( !pModel->GetOpenInDesignMode() );
699 GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_OPEN_READONLY);
701 break;
702 case SID_FM_USE_WIZARDS:
704 GetImpl()->SetWizardUsing(!GetImpl()->GetWizardUsing());
705 GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_USE_WIZARDS);
707 break;
708 case SID_FM_SEARCH:
710 const ::svx::ControllerFeatures& rController = GetImpl()->getActiveControllerFeatures();
711 if ( rController->commitCurrentControl() && rController->commitCurrentRecord() )
712 GetImpl()->ExecuteSearch();
713 rReq.Done();
715 break;
717 case SID_FM_RECORD_FIRST:
718 case SID_FM_RECORD_PREV:
719 case SID_FM_RECORD_NEXT:
720 case SID_FM_RECORD_LAST:
721 case SID_FM_RECORD_NEW:
722 case SID_FM_REFRESH:
723 case SID_FM_REFRESH_FORM_CONTROL:
724 case SID_FM_RECORD_DELETE:
725 case SID_FM_RECORD_UNDO:
726 case SID_FM_RECORD_SAVE:
727 case SID_FM_REMOVE_FILTER_SORT:
728 case SID_FM_SORTDOWN:
729 case SID_FM_SORTUP:
730 case SID_FM_AUTOFILTER:
731 case SID_FM_ORDERCRIT:
732 case SID_FM_FORM_FILTERED:
734 GetImpl()->ExecuteFormSlot( nSlot );
735 rReq.Done();
737 break;
739 case SID_FM_RECORD_ABSOLUTE:
741 const ::svx::ControllerFeatures& rController = GetImpl()->getNavControllerFeatures();
742 sal_Int32 nRecord = -1;
744 const SfxItemSet* pArgs = rReq.GetArgs();
745 if ( pArgs )
747 const SfxPoolItem* pItem;
748 if ( ( pArgs->GetItemState( FN_PARAM_1, true, &pItem ) ) == SFX_ITEM_SET )
750 const SfxInt32Item* pTypedItem = PTR_CAST( SfxInt32Item, pItem );
751 if ( pTypedItem )
752 nRecord = std::max( pTypedItem->GetValue(), sal_Int32(0) );
755 else
757 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
758 DBG_ASSERT( pFact, "no dialog factory!" );
759 if ( pFact )
761 boost::scoped_ptr< AbstractFmInputRecordNoDialog > dlg( pFact->CreateFmInputRecordNoDialog( NULL ) );
762 DBG_ASSERT( dlg.get(), "Dialogdiet fail!" );
763 dlg->SetValue( rController->getCursor()->getRow() );
764 if ( dlg->Execute() == RET_OK )
765 nRecord = dlg->GetValue();
767 rReq.AppendItem( SfxInt32Item( FN_PARAM_1, nRecord ) );
771 if ( nRecord != -1 )
772 rController->execute( nSlot, OUString( "Position" ), makeAny( (sal_Int32)nRecord ) );
774 rReq.Done();
775 } break;
776 case SID_FM_FILTER_EXECUTE:
777 case SID_FM_FILTER_EXIT:
779 bool bCancelled = ( SID_FM_FILTER_EXIT == nSlot );
780 bool bReopenNavigator = false;
782 if ( !bCancelled )
784 // if the filter navigator is still open, we need to close it, so it can possibly
785 // commit it's most recent changes
786 if ( GetViewShell() && GetViewShell()->GetViewFrame() )
787 if ( GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_FILTER_NAVIGATOR ) )
789 GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
790 bReopenNavigator = true;
793 Reference< runtime::XFormController > xController( GetImpl()->getActiveController() );
795 if ( GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_FILTER_NAVIGATOR )
796 // closing the window was denied, for instance because of a invalid criterion
798 || ( xController.is()
799 && !GetImpl()->getActiveControllerFeatures()->commitCurrentControl( )
801 // committing the controller was denied
804 rReq.Done();
805 break;
809 GetImpl()->stopFiltering( !bCancelled );
810 rReq.Done();
812 if ( bReopenNavigator )
813 // we closed the navigator only to implicitly commit it (as we do not have another
814 // direct wire to it), but to the user, it should look it it was always open
815 GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
817 break;
819 case SID_FM_FILTER_START:
821 GetImpl()->startFiltering();
822 rReq.Done();
824 // initially open the filter navigator, the whole form based filter is pretty useless without it
825 SfxBoolItem aIdentifierItem( SID_FM_FILTER_NAVIGATOR, true );
826 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_FILTER_NAVIGATOR, SFX_CALLMODE_ASYNCHRON,
827 &aIdentifierItem, NULL );
828 } break;
833 void FmFormShell::GetState(SfxItemSet &rSet)
835 SfxWhichIter aIter( rSet );
836 sal_uInt16 nWhich = aIter.FirstWhich();
837 while ( nWhich )
839 switch( nWhich )
841 case SID_FM_MORE_CONTROLS:
842 case SID_FM_FORM_DESIGN_TOOLS:
844 FormToolboxes aToolboxAccess( GetImpl()->getHostFrame() );
845 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible( nWhich ) ) );
847 break;
849 case SID_FM_FILTER_EXECUTE:
850 case SID_FM_FILTER_EXIT:
851 if (!GetImpl()->isInFilterMode())
852 rSet.DisableItem( nWhich );
853 break;
855 case SID_FM_USE_WIZARDS:
856 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
857 rSet.Put( SfxVisibilityItem( nWhich, false ) );
858 else if (!GetFormModel())
859 rSet.DisableItem( nWhich );
860 else
861 rSet.Put( SfxBoolItem(nWhich, GetImpl()->GetWizardUsing() ) );
862 break;
863 case SID_FM_AUTOCONTROLFOCUS:
864 if (!GetFormModel())
865 rSet.DisableItem( nWhich );
866 else
867 rSet.Put( SfxBoolItem(nWhich, GetFormModel()->GetAutoControlFocus() ) );
868 break;
869 case SID_FM_OPEN_READONLY:
870 if (!GetFormModel())
871 rSet.DisableItem( nWhich );
872 else
873 rSet.Put( SfxBoolItem(nWhich, GetFormModel()->GetOpenInDesignMode() ) );
874 break;
876 case SID_FM_NAVIGATIONBAR:
877 case SID_FM_DBGRID:
878 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
880 rSet.Put( SfxVisibilityItem( nWhich, false ) );
881 break;
883 // NO break!
885 case SID_FM_SCROLLBAR:
886 case SID_FM_IMAGECONTROL:
887 case SID_FM_FILECONTROL:
888 case SID_FM_CURRENCYFIELD:
889 case SID_FM_PATTERNFIELD:
890 case SID_FM_IMAGEBUTTON:
891 case SID_FM_RADIOBUTTON:
892 case SID_FM_COMBOBOX:
893 case SID_FM_GROUPBOX:
894 case SID_FM_CHECKBOX:
895 case SID_FM_PUSHBUTTON:
896 case SID_FM_FIXEDTEXT:
897 case SID_FM_LISTBOX:
898 case SID_FM_EDIT:
899 case SID_FM_DATEFIELD:
900 case SID_FM_TIMEFIELD:
901 case SID_FM_NUMERICFIELD:
902 case SID_FM_FORMATTEDFIELD:
903 case SID_FM_SPINBUTTON:
904 if (!m_bDesignMode)
905 rSet.DisableItem( nWhich );
906 else
908 bool bLayerLocked = false;
909 if (m_pFormView)
911 // Ist der ::com::sun::star::drawing::Layer gelocked, so m???ssen die Slots disabled werden. #36897
912 SdrPageView* pPV = m_pFormView->GetSdrPageView();
913 if (pPV != NULL)
914 bLayerLocked = pPV->IsLayerLocked(m_pFormView->GetActiveLayer());
916 if (bLayerLocked)
917 rSet.DisableItem( nWhich );
918 else
919 rSet.Put( SfxBoolItem(nWhich, (nWhich==m_nLastSlot)) );
921 break;
922 case SID_FM_FILTER_NAVIGATOR_CONTROL:
924 if (GetImpl()->isInFilterMode())
925 rSet.Put(SfxObjectItem(nWhich, this));
926 else
927 rSet.Put(SfxObjectItem(nWhich));
928 } break;
929 case SID_FM_FIELDS_CONTROL:
930 case SID_FM_PROPERTY_CONTROL:
932 if (!m_bDesignMode || !m_pFormView || !m_bHasForms)
933 rSet.Put(SfxObjectItem(nWhich));
934 else
935 rSet.Put(SfxObjectItem(nWhich, this));
937 } break;
938 case SID_FM_FMEXPLORER_CONTROL:
939 case SID_FM_DATANAVIGATOR_CONTROL :
941 if (!m_bDesignMode || !m_pFormView)
942 rSet.Put(SfxObjectItem(nWhich));
943 else
944 rSet.Put(SfxObjectItem(nWhich, this));
946 } break;
947 case SID_FM_ADD_FIELD:
948 case SID_FM_SHOW_FMEXPLORER:
949 case SID_FM_SHOW_PROPERTIES:
950 case SID_FM_FILTER_NAVIGATOR:
951 case SID_FM_SHOW_DATANAVIGATOR:
953 if ( GetViewShell()->GetViewFrame()->KnowsChildWindow(nWhich) )
954 rSet.Put( SfxBoolItem( nWhich, GetViewShell()->GetViewFrame()->HasChildWindow(nWhich)) );
955 else
956 rSet.DisableItem(nWhich);
957 } break;
959 case SID_FM_SHOW_PROPERTY_BROWSER:
961 rSet.Put(SfxBoolItem(nWhich, GetImpl()->IsPropBrwOpen()));
963 break;
965 case SID_FM_CTL_PROPERTIES:
967 // der Impl eventuell die Moeglichjkeit geben, ihre an der aktuellen MarkList ausgerichteten Objekte
968 // auf den neuesten Stand zu bringen
969 if (GetImpl()->IsSelectionUpdatePending())
970 GetImpl()->ForceUpdateSelection(false);
972 if ( !m_pFormView || !m_bDesignMode || !GetImpl()->onlyControlsAreMarked() )
973 rSet.DisableItem( nWhich );
974 else
976 bool bChecked = GetImpl()->IsPropBrwOpen() && !GetImpl()->isSolelySelected( GetImpl()->getCurrentForm() );
977 // if the property browser is open, and only controls are marked, and the current selection
978 // does not consist of only the current form, then the current selection is the (composition of)
979 // the currently marked controls
980 rSet.Put( SfxBoolItem( nWhich, bChecked ) );
982 } break;
984 case SID_FM_PROPERTIES:
986 // der Impl eventuell die Moeglichjkeit geben, ihre an der aktuellen MarkList ausgerichteten Objekte
987 // auf den neuesten Stand zu bringen
988 if (GetImpl()->IsSelectionUpdatePending())
989 GetImpl()->ForceUpdateSelection(false);
991 if ( !m_pFormView || !m_bDesignMode || !GetImpl()->getCurrentForm().is() )
992 rSet.DisableItem( nWhich );
993 else
995 bool bChecked = GetImpl()->IsPropBrwOpen() && GetImpl()->isSolelySelected( GetImpl()->getCurrentForm() );
996 rSet.Put(SfxBoolItem(nWhich, bChecked));
998 } break;
999 case SID_FM_TAB_DIALOG:
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(false);
1005 if (!m_pFormView || !m_bDesignMode || !GetImpl()->getCurrentForm().is() )
1006 rSet.DisableItem( nWhich );
1007 break;
1008 case SID_FM_CONFIG:
1009 rSet.Put(SfxUInt16Item(nWhich, m_nLastSlot));
1010 break;
1011 case SID_FM_DESIGN_MODE:
1012 if (!m_pFormView || GetImpl()->IsReadonlyDoc() )
1013 rSet.DisableItem( nWhich );
1014 else
1015 rSet.Put( SfxBoolItem(nWhich, m_bDesignMode) );
1016 break;
1017 case SID_FM_SEARCH:
1018 case SID_FM_RECORD_FIRST:
1019 case SID_FM_RECORD_NEXT:
1020 case SID_FM_RECORD_PREV:
1021 case SID_FM_RECORD_LAST:
1022 case SID_FM_RECORD_NEW:
1023 case SID_FM_RECORD_DELETE:
1024 case SID_FM_RECORD_ABSOLUTE:
1025 case SID_FM_RECORD_TOTAL:
1026 case SID_FM_RECORD_SAVE:
1027 case SID_FM_RECORD_UNDO:
1028 case SID_FM_FORM_FILTERED:
1029 case SID_FM_REMOVE_FILTER_SORT:
1030 case SID_FM_SORTUP:
1031 case SID_FM_SORTDOWN:
1032 case SID_FM_ORDERCRIT:
1033 case SID_FM_FILTER_START:
1034 case SID_FM_AUTOFILTER:
1035 case SID_FM_REFRESH:
1036 case SID_FM_REFRESH_FORM_CONTROL:
1037 case SID_FM_VIEW_AS_GRID:
1038 GetFormState(rSet,nWhich);
1039 break;
1041 case SID_FM_CHANGECONTROLTYPE:
1043 if ( !m_pFormView || !m_bDesignMode )
1044 rSet.DisableItem( nWhich );
1045 else
1047 if ( !GetImpl()->canConvertCurrentSelectionToControl( OBJ_FM_FIXEDTEXT ) )
1048 // if it cannot be converted to a fixed text, it is no single control
1049 rSet.DisableItem( nWhich );
1051 } break;
1053 case SID_FM_CONVERTTO_FILECONTROL :
1054 case SID_FM_CONVERTTO_CURRENCY :
1055 case SID_FM_CONVERTTO_PATTERN :
1056 case SID_FM_CONVERTTO_IMAGECONTROL :
1057 case SID_FM_CONVERTTO_SCROLLBAR :
1058 case SID_FM_CONVERTTO_NAVIGATIONBAR :
1059 case SID_FM_CONVERTTO_IMAGEBUTTON :
1060 case SID_FM_CONVERTTO_EDIT :
1061 case SID_FM_CONVERTTO_BUTTON :
1062 case SID_FM_CONVERTTO_FIXEDTEXT :
1063 case SID_FM_CONVERTTO_LISTBOX :
1064 case SID_FM_CONVERTTO_CHECKBOX :
1065 case SID_FM_CONVERTTO_RADIOBUTTON :
1066 case SID_FM_CONVERTTO_GROUPBOX :
1067 case SID_FM_CONVERTTO_COMBOBOX :
1068 case SID_FM_CONVERTTO_DATE :
1069 case SID_FM_CONVERTTO_TIME :
1070 case SID_FM_CONVERTTO_NUMERIC :
1071 case SID_FM_CONVERTTO_FORMATTED :
1072 case SID_FM_CONVERTTO_SPINBUTTON :
1074 if ( !m_pFormView || !m_bDesignMode || !GetImpl()->canConvertCurrentSelectionToControl( nWhich ) )
1075 rSet.DisableItem( nWhich );
1076 else
1078 rSet.Put( SfxBoolItem( nWhich, false ) );
1079 // just to have a defined state (available and not checked)
1082 break;
1084 nWhich = aIter.NextWhich();
1089 void FmFormShell::GetFormState(SfxItemSet &rSet, sal_uInt16 nWhich)
1091 if ( !GetImpl()->getNavController().is()
1092 || !isRowSetAlive(GetImpl()->getNavController()->getModel())
1093 || !m_pFormView
1094 || m_bDesignMode
1095 || !GetImpl()->getActiveForm().is()
1096 || GetImpl()->isInFilterMode()
1098 rSet.DisableItem(nWhich);
1099 else
1101 bool bEnable = false;
1104 switch (nWhich)
1106 case SID_FM_VIEW_AS_GRID:
1107 if (GetImpl()->getHostFrame().is() && GetImpl()->getNavController().is())
1109 bEnable = true;
1110 bool bDisplayingCurrent =
1111 GetImpl()->getInternalForm(
1112 Reference< XForm >( GetImpl()->getNavController()->getModel(), UNO_QUERY )
1113 ) == GetImpl()->getExternallyDisplayedForm();
1114 rSet.Put(SfxBoolItem(nWhich, bDisplayingCurrent));
1116 break;
1118 case SID_FM_SEARCH:
1120 Reference< ::com::sun::star::beans::XPropertySet > xNavSet(GetImpl()->getActiveForm(), UNO_QUERY);
1121 sal_Int32 nCount = ::comphelper::getINT32(xNavSet->getPropertyValue(FM_PROP_ROWCOUNT));
1122 bEnable = nCount != 0;
1123 } break;
1124 case SID_FM_RECORD_ABSOLUTE:
1125 case SID_FM_RECORD_TOTAL:
1127 FeatureState aState;
1128 GetImpl()->getNavControllerFeatures()->getState( nWhich, aState );
1129 if ( SID_FM_RECORD_ABSOLUTE == nWhich )
1131 sal_Int32 nPosition = 0;
1132 aState.State >>= nPosition;
1133 rSet.Put( SfxInt32Item( nWhich, nPosition ) );
1135 else if ( SID_FM_RECORD_TOTAL == nWhich )
1137 OUString sTotalCount;
1138 aState.State >>= sTotalCount;
1139 rSet.Put( SfxStringItem( nWhich, sTotalCount ) );
1141 bEnable = aState.Enabled;
1143 break;
1145 // first, prev, next, last, and absolute affect the nav controller, not the
1146 // active controller
1147 case SID_FM_RECORD_FIRST:
1148 case SID_FM_RECORD_PREV:
1149 case SID_FM_RECORD_NEXT:
1150 case SID_FM_RECORD_LAST:
1151 case SID_FM_RECORD_NEW:
1152 case SID_FM_RECORD_SAVE:
1153 case SID_FM_RECORD_UNDO:
1154 case SID_FM_RECORD_DELETE:
1155 case SID_FM_REFRESH:
1156 case SID_FM_REFRESH_FORM_CONTROL:
1157 case SID_FM_REMOVE_FILTER_SORT:
1158 case SID_FM_SORTUP:
1159 case SID_FM_SORTDOWN:
1160 case SID_FM_AUTOFILTER:
1161 case SID_FM_ORDERCRIT:
1162 bEnable = GetImpl()->IsFormSlotEnabled( nWhich );
1163 break;
1165 case SID_FM_FORM_FILTERED:
1167 FeatureState aState;
1168 bEnable = GetImpl()->IsFormSlotEnabled( nWhich, &aState );
1170 rSet.Put( SfxBoolItem( nWhich, ::comphelper::getBOOL( aState.State ) ) );
1172 break;
1174 case SID_FM_FILTER_START:
1175 bEnable = GetImpl()->getActiveControllerFeatures()->canDoFormFilter();
1176 break;
1179 catch( const Exception& )
1181 OSL_FAIL( "FmFormShell::GetFormState: caught an exception while determining the state!" );
1183 if (!bEnable)
1184 rSet.DisableItem(nWhich);
1189 FmFormPage* FmFormShell::GetCurPage() const
1191 FmFormPage* pP = NULL;
1192 if (m_pFormView && m_pFormView->GetSdrPageView())
1193 pP = PTR_CAST(FmFormPage,m_pFormView->GetSdrPageView()->GetPage());
1194 return pP;
1198 void FmFormShell::SetView( FmFormView* _pView )
1200 if ( m_pFormView )
1202 if ( IsActive() )
1203 GetImpl()->viewDeactivated( *m_pFormView );
1205 m_pFormView->SetFormShell( NULL, FmFormView::FormShellAccess() );
1206 m_pFormView = NULL;
1207 m_pFormModel = NULL;
1210 if ( !_pView )
1211 return;
1213 m_pFormView = _pView;
1214 m_pFormView->SetFormShell( this, FmFormView::FormShellAccess() );
1215 m_pFormModel = (FmFormModel*)m_pFormView->GetModel();
1217 impl_setDesignMode( m_pFormView->IsDesignMode() );
1219 // We activate our view if we are activated ourself, but sometimes the Activate precedes the SetView.
1220 // But here we know both the view and our activation state so we at least are able to pass the latter
1221 // to the former.
1222 // FS - 30.06.99 - 67308
1223 if ( IsActive() )
1224 GetImpl()->viewActivated( *m_pFormView );
1228 void FmFormShell::DetermineForms(bool bInvalidate)
1230 // Existieren Formulare auf der aktuellen Page
1231 bool bForms = GetImpl()->hasForms();
1232 if (bForms != m_bHasForms)
1234 m_bHasForms = bForms;
1235 if (bInvalidate)
1236 UIFeatureChanged();
1241 bool FmFormShell::GetY2KState(sal_uInt16& nReturn)
1243 return GetImpl()->GetY2KState(nReturn);
1247 void FmFormShell::SetY2KState(sal_uInt16 n)
1249 GetImpl()->SetY2KState(n);
1253 void FmFormShell::Activate(bool bMDI)
1255 SfxShell::Activate(bMDI);
1257 if ( m_pFormView )
1258 GetImpl()->viewActivated( *m_pFormView, true );
1262 void FmFormShell::Deactivate(bool bMDI)
1264 SfxShell::Deactivate(bMDI);
1266 if ( m_pFormView )
1267 GetImpl()->viewDeactivated( *m_pFormView, false );
1271 void FmFormShell::ExecuteTextAttribute( SfxRequest& _rReq )
1273 m_pImpl->ExecuteTextAttribute( _rReq );
1277 void FmFormShell::GetTextAttributeState( SfxItemSet& _rSet )
1279 m_pImpl->GetTextAttributeState( _rSet );
1283 bool FmFormShell::IsActiveControl() const
1285 return m_pImpl->IsActiveControl();
1289 void FmFormShell::ForgetActiveControl()
1291 m_pImpl->ForgetActiveControl();
1295 void FmFormShell::SetControlActivationHandler( const Link& _rHdl )
1297 m_pImpl->SetControlActivationHandler( _rHdl );
1301 namespace
1303 SdrUnoObj* lcl_findUnoObject( const SdrObjList& _rObjList, const Reference< XControlModel >& _rxModel )
1305 SdrObjListIter aIter( _rObjList );
1306 while ( aIter.IsMore() )
1308 SdrObject* pObject = aIter.Next();
1309 SdrUnoObj* pUnoObject = pObject ? PTR_CAST( SdrUnoObj, pObject ) : NULL;
1310 if ( !pUnoObject )
1311 continue;
1313 Reference< XControlModel > xControlModel = pUnoObject->GetUnoControlModel();
1314 if ( !xControlModel.is() )
1315 continue;
1317 if ( _rxModel == xControlModel )
1318 return pUnoObject;
1320 return NULL;
1325 void FmFormShell::ToggleControlFocus( const SdrUnoObj& i_rUnoObject, const SdrView& i_rView, OutputDevice& i_rDevice ) const
1329 // check if the focus currently is in a control
1330 // Well, okay, do it the other way 'round: Check whether the current control of the active controller
1331 // actually has the focus. This should be equivalent.
1332 const bool bHasControlFocus = GetImpl()->HasControlFocus();
1334 if ( bHasControlFocus )
1336 Window* pWindow( dynamic_cast< Window* >( &i_rDevice ) );
1337 OSL_ENSURE( pWindow, "FmFormShell::ToggleControlFocus: I need a Window, really!" );
1338 if ( pWindow )
1339 pWindow->GrabFocus();
1341 else
1343 Reference< XControl > xControl;
1344 GetFormControl( i_rUnoObject.GetUnoControlModel(), i_rView, i_rDevice, xControl );
1345 Reference< XWindow > xControlWindow( xControl, UNO_QUERY );
1346 if ( xControlWindow.is() )
1347 xControlWindow->setFocus();
1350 catch( const Exception& )
1352 DBG_UNHANDLED_EXCEPTION();
1357 namespace
1359 class FocusableControlsFilter : public ::svx::ISdrObjectFilter
1361 public:
1362 FocusableControlsFilter( const SdrView& i_rView, const OutputDevice& i_rDevice )
1363 :m_rView( i_rView )
1364 ,m_rDevice( i_rDevice )
1368 public:
1369 virtual bool includeObject( const SdrObject& i_rObject ) const SAL_OVERRIDE
1371 const SdrUnoObj* pUnoObj = dynamic_cast< const SdrUnoObj* >( &i_rObject );
1372 if ( !pUnoObj )
1373 return false;
1375 Reference< XControl > xControl = pUnoObj->GetUnoControl( m_rView, m_rDevice );
1376 return FmXFormView::isFocusable( xControl );
1379 private:
1380 const SdrView& m_rView;
1381 const OutputDevice& m_rDevice;
1386 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1387 ::std::auto_ptr< ::svx::ISdrObjectFilter > FmFormShell::CreateFocusableControlFilter( const SdrView& i_rView, const OutputDevice& i_rDevice ) const
1389 ::std::auto_ptr< ::svx::ISdrObjectFilter > pFilter;
1391 if ( !i_rView.IsDesignMode() )
1392 pFilter.reset( new FocusableControlsFilter( i_rView, i_rDevice ) );
1394 return pFilter;
1396 SAL_WNODEPRECATED_DECLARATIONS_POP
1399 SdrUnoObj* FmFormShell::GetFormControl( const Reference< XControlModel >& _rxModel, const SdrView& _rView, const OutputDevice& _rDevice, Reference< XControl >& _out_rxControl ) const
1401 if ( !_rxModel.is() )
1402 return NULL;
1404 // we can only retrieve controls for SdrObjects which belong to page which is actually displayed in the given view
1405 SdrPageView* pPageView = _rView.GetSdrPageView();
1406 SdrPage* pPage = pPageView ? pPageView->GetPage() : NULL;
1407 OSL_ENSURE( pPage, "FmFormShell::GetFormControl: no page displayed in the given view!" );
1408 if ( !pPage )
1409 return NULL;
1411 SdrUnoObj* pUnoObject = lcl_findUnoObject( *pPage, _rxModel );
1412 if ( pUnoObject )
1414 _out_rxControl = pUnoObject->GetUnoControl( _rView, _rDevice );
1415 return pUnoObject;
1418 #if OSL_DEBUG_LEVEL > 0
1419 // perhaps we are fed with a control model which lives on a page other than the one displayed
1420 // in the given view. This is worth being reported as error, in non-product builds.
1421 FmFormModel* pModel = GetFormModel();
1422 if ( pModel )
1424 sal_uInt16 pageCount = pModel->GetPageCount();
1425 for ( sal_uInt16 page = 0; page < pageCount; ++page )
1427 pPage = pModel->GetPage( page );
1428 OSL_ENSURE( pPage, "FmFormShell::GetFormControl: NULL page encountered!" );
1429 if ( !pPage )
1430 continue;
1432 pUnoObject = lcl_findUnoObject( *pPage, _rxModel );
1433 OSL_ENSURE( !pUnoObject, "FmFormShell::GetFormControl: the given control model belongs to a wrong page (displayed elsewhere)!" );
1436 #endif
1438 return NULL;
1442 Reference< runtime::XFormController > FmFormShell::GetFormController( const Reference< XForm >& _rxForm, const SdrView& _rView, const OutputDevice& _rDevice ) const
1444 const FmFormView* pFormView = dynamic_cast< const FmFormView* >( &_rView );
1445 if ( !pFormView )
1446 return NULL;
1448 return pFormView->GetFormController( _rxForm, _rDevice );
1452 void FmFormShell::SetDesignMode( bool _bDesignMode )
1454 if ( _bDesignMode == m_bDesignMode )
1455 return;
1457 FmFormModel* pModel = GetFormModel();
1458 if (pModel)
1459 // fuer die Zeit des Uebergangs das Undo-Environment ausschalten, das sichert, dass man dort auch nicht-transiente
1460 // Properties mal eben aendern kann (sollte allerdings mit Vorsicht genossen und beim Rueckschalten des Modes
1461 // auch immer wieder rueckgaegig gemacht werden. Ein Beispiel ist das Setzen der maximalen Text-Laenge durch das
1462 // OEditModel an seinem Control.)
1463 pModel->GetUndoEnv().Lock();
1465 // dann die eigentliche Umschaltung
1466 if ( m_bDesignMode || PrepareClose( true ) )
1467 impl_setDesignMode(!m_bDesignMode );
1469 // und mein Undo-Environment wieder an
1470 if ( pModel )
1471 pModel->GetUndoEnv().UnLock();
1474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */