sd: keep a non-owning pointer to the OverridingShell
[LibreOffice.git] / svx / source / form / fmshell.cxx
blobd88eb91fb3ec3e11d5516f2e5621c4c84ce1a71d
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 <fmprop.hxx>
24 #include <fmundo.hxx>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/awt/XTabControllerModel.hpp>
27 #include <sfx2/viewfrm.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/weld.hxx>
30 #include <svl/whiter.hxx>
31 #include <sfx2/app.hxx>
32 #include <svl/intitem.hxx>
33 #include <svl/stritem.hxx>
34 #include <svl/visitem.hxx>
35 #include <unotools/moduleoptions.hxx>
36 #include <sfx2/objface.hxx>
37 #include <sfx2/request.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <svx/svdobj.hxx>
40 #include <svx/fmpage.hxx>
41 #include <svx/svditer.hxx>
43 #include <svx/svxids.hrc>
45 #include <svx/svdobjkind.hxx>
46 #include <svl/eitem.hxx>
47 #include <comphelper/diagnose_ex.hxx>
48 #include <svx/svdpage.hxx>
49 #include <svx/fmmodel.hxx>
50 #include <fmshimp.hxx>
51 #include <svx/svdpagv.hxx>
52 #include <sfx2/objitem.hxx>
53 #include <sfx2/viewsh.hxx>
54 #include <fmexpl.hxx>
55 #include <formcontrolling.hxx>
56 #include <comphelper/types.hxx>
57 #include <fmdocumentclassification.hxx>
58 #include <formtoolbars.hxx>
60 #include <svx/svxdlg.hxx>
62 #include <svx/sdrobjectfilter.hxx>
64 #define ShellClass_FmFormShell
65 #include <svxslots.hxx>
67 #include <memory>
69 // is used for Invalidate -> maintain it as well
70 // sort ascending !!!!!!
71 sal_uInt16 const ControllerSlotMap[] = // slots of the controller
73 SID_FM_CONFIG,
74 SID_FM_PUSHBUTTON,
75 SID_FM_RADIOBUTTON,
76 SID_FM_CHECKBOX,
77 SID_FM_FIXEDTEXT,
78 SID_FM_GROUPBOX,
79 SID_FM_EDIT,
80 SID_FM_LISTBOX,
81 SID_FM_COMBOBOX,
82 SID_FM_DBGRID,
83 SID_FM_IMAGEBUTTON,
84 SID_FM_FILECONTROL,
85 SID_FM_NAVIGATIONBAR,
86 SID_FM_CTL_PROPERTIES,
87 SID_FM_PROPERTIES,
88 SID_FM_TAB_DIALOG,
89 SID_FM_ADD_FIELD,
90 SID_FM_DESIGN_MODE,
91 SID_FM_SHOW_FMEXPLORER,
92 SID_FM_SHOW_PROPERTIES,
93 SID_FM_FMEXPLORER_CONTROL,
94 SID_FM_DATEFIELD,
95 SID_FM_TIMEFIELD,
96 SID_FM_NUMERICFIELD,
97 SID_FM_CURRENCYFIELD,
98 SID_FM_PATTERNFIELD,
99 SID_FM_OPEN_READONLY,
100 SID_FM_IMAGECONTROL,
101 SID_FM_USE_WIZARDS,
102 SID_FM_FORMATTEDFIELD,
103 SID_FM_FILTER_NAVIGATOR,
104 SID_FM_AUTOCONTROLFOCUS,
105 SID_FM_SCROLLBAR,
106 SID_FM_SPINBUTTON,
107 SID_FM_SHOW_DATANAVIGATOR,
108 SID_FM_DATANAVIGATOR_CONTROL,
113 using namespace ::com::sun::star::uno;
114 using namespace ::com::sun::star::awt;
115 using namespace ::com::sun::star::sdbc;
116 using namespace ::com::sun::star::beans;
117 using namespace ::com::sun::star::form;
118 using namespace ::com::sun::star::form::runtime;
119 using namespace ::svxform;
121 FmDesignModeChangedHint::FmDesignModeChangedHint( bool bDesMode )
122 :SfxHint(SfxHintId::FmDesignModeChanged), m_bDesignMode( bDesMode )
127 FmDesignModeChangedHint::~FmDesignModeChangedHint()
131 SFX_IMPL_INTERFACE(FmFormShell, SfxShell)
133 void FmFormShell::InitInterface_Impl()
135 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_NAVIGATION, SfxVisibilityFlags::Standard|SfxVisibilityFlags::ReadonlyDoc,
136 ToolbarId::SvxTbx_Form_Navigation,
137 SfxShellFeature::FormShowDatabaseBar);
139 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_NAVIGATION, SfxVisibilityFlags::Standard|SfxVisibilityFlags::ReadonlyDoc,
140 ToolbarId::SvxTbx_Form_Filter,
141 SfxShellFeature::FormShowFilterBar);
143 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Standard | SfxVisibilityFlags::ReadonlyDoc,
144 ToolbarId::SvxTbx_Text_Control_Attributes,
145 SfxShellFeature::FormShowTextControlBar);
147 GetStaticInterface()->RegisterChildWindow(SID_FM_ADD_FIELD, false, SfxShellFeature::FormShowField);
148 GetStaticInterface()->RegisterChildWindow(SID_FM_SHOW_PROPERTIES, false, SfxShellFeature::FormShowProperties);
149 GetStaticInterface()->RegisterChildWindow(SID_FM_SHOW_FMEXPLORER, false, SfxShellFeature::FormShowExplorer);
150 GetStaticInterface()->RegisterChildWindow(SID_FM_FILTER_NAVIGATOR, false, SfxShellFeature::FormShowFilterNavigator);
151 GetStaticInterface()->RegisterChildWindow(SID_FM_SHOW_DATANAVIGATOR, false, SfxShellFeature::FormShowDataNavigator);
153 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Standard,
154 ToolbarId::SvxTbx_Controls,
155 SfxShellFeature::FormTBControls);
157 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Standard,
158 ToolbarId::SvxTbx_FormDesign,
159 SfxShellFeature::FormTBDesign);
163 FmFormShell::FmFormShell( SfxViewShell* _pParent, FmFormView* pView )
164 :SfxShell(_pParent)
165 ,m_pImpl(new FmXFormShell(*this, &_pParent->GetViewFrame()))
166 ,m_pFormView( pView )
167 ,m_pFormModel( nullptr )
168 ,m_nLastSlot( 0 )
169 ,m_bDesignMode( true )
170 ,m_bHasForms(false)
172 SetPool( &SfxGetpApp()->GetPool() );
173 SetName( u"Form"_ustr );
175 SetView(m_pFormView);
179 FmFormShell::~FmFormShell()
181 if ( m_pFormView )
182 SetView( nullptr );
184 m_pImpl->dispose();
188 void FmFormShell::NotifyMarkListChanged(FmFormView* pWhichView)
190 FmNavViewMarksChanged aChangeNotification(pWhichView);
191 Broadcast(aChangeNotification);
195 bool FmFormShell::PrepareClose(bool bUI)
197 if (GetImpl()->didPrepareClose_Lock())
198 // we already made a PrepareClose for the current modifications of the current form
199 return true;
201 bool bResult = true;
202 // Save the data records, not in DesignMode and FilterMode
203 if (!m_bDesignMode && !GetImpl()->isInFilterMode_Lock() &&
204 m_pFormView && m_pFormView->GetActualOutDev() &&
205 m_pFormView->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW)
207 SdrPageView* pCurPageView = m_pFormView->GetSdrPageView();
209 // sal_uInt16 nPos = pCurPageView ? pCurPageView->GetWinList().Find((OutputDevice*)m_pFormView->GetActualOutDev()) : SDRPAGEVIEWWIN_NOTFOUND;
210 SdrPageWindow* pWindow = pCurPageView ? pCurPageView->FindPageWindow(*const_cast<OutputDevice*>(m_pFormView->GetActualOutDev())) : nullptr;
212 if(pWindow)
214 // First, the current contents of the controls are stored.
215 // If everything has gone smoothly, the modified records are stored.
216 if (GetImpl()->getActiveController_Lock().is())
218 const svx::ControllerFeatures& rController = GetImpl()->getActiveControllerFeatures_Lock();
219 if ( rController->commitCurrentControl() )
221 const bool bModified = rController->isModifiedRow();
223 if ( bModified && bUI )
225 SfxViewShell* pShell = GetViewShell();
226 vcl::Window* pShellWnd = pShell ? pShell->GetWindow() : nullptr;
227 weld::Widget* pFrameWeld = pShellWnd ? pShellWnd->GetFrameWeld() : nullptr;
228 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pFrameWeld, u"svx/ui/savemodifieddialog.ui"_ustr));
229 std::unique_ptr<weld::MessageDialog> xQry(xBuilder->weld_message_dialog(u"SaveModifiedDialog"_ustr));
230 switch (xQry->run())
232 case RET_YES:
233 bResult = rController->commitCurrentRecord( );
234 [[fallthrough]];
235 case RET_NO:
236 GetImpl()->didPrepareClose_Lock(true);
237 break;
239 case RET_CANCEL:
240 return false;
247 return bResult;
251 void FmFormShell::impl_setDesignMode(bool bDesign)
253 if (m_pFormView)
255 if (!bDesign)
256 m_nLastSlot = SID_FM_DESIGN_MODE;
258 GetImpl()->SetDesignMode_Lock(bDesign);
259 // my m_bDesignMode is also set by the Impl ...
261 else
263 m_bHasForms = false;
264 m_bDesignMode = bDesign;
265 UIFeatureChanged();
268 GetViewShell()->GetViewFrame().GetBindings().Invalidate(ControllerSlotMap);
271 bool FmFormShell::HasUIFeature(SfxShellFeature nFeature) const
273 assert((nFeature & ~SfxShellFeature::FormMask) == SfxShellFeature::NONE);
274 bool bResult = false;
275 if (nFeature & SfxShellFeature::FormShowDatabaseBar)
277 // only if forms are also available
278 bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar_Lock() && !GetImpl()->isInFilterMode_Lock();
280 else if (nFeature & SfxShellFeature::FormShowFilterBar)
282 // only if forms are also available
283 bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar_Lock() && GetImpl()->isInFilterMode_Lock();
285 else if (nFeature & SfxShellFeature::FormShowFilterNavigator)
287 bResult = !m_bDesignMode && GetImpl()->hasDatabaseBar_Lock() && GetImpl()->isInFilterMode_Lock();
289 else if (nFeature & SfxShellFeature::FormShowField)
291 bResult = m_bDesignMode && m_pFormView && m_bHasForms;
293 else if (nFeature & SfxShellFeature::FormShowProperties)
295 bResult = m_bDesignMode && m_pFormView && m_bHasForms;
297 else if (nFeature & SfxShellFeature::FormShowExplorer)
299 bResult = m_bDesignMode; // OJ #101593# && m_pFormView && m_bHasForms;
301 else if (nFeature & SfxShellFeature::FormShowTextControlBar)
303 bResult = !GetImpl()->IsReadonlyDoc_Lock() && m_pImpl->IsActiveControl_Lock(true);
305 else if (nFeature & SfxShellFeature::FormShowDataNavigator)
307 bResult = GetImpl()->isEnhancedForm_Lock();
309 else if ( (nFeature & SfxShellFeature::FormTBControls)
310 || (nFeature & SfxShellFeature::FormTBDesign)
313 bResult = true;
316 return bResult;
320 void FmFormShell::Execute(SfxRequest &rReq)
322 sal_uInt16 nSlot = rReq.GetSlot();
325 // set MasterSlot
326 switch( nSlot )
328 case SID_FM_PUSHBUTTON:
329 case SID_FM_RADIOBUTTON:
330 case SID_FM_CHECKBOX:
331 case SID_FM_FIXEDTEXT:
332 case SID_FM_GROUPBOX:
333 case SID_FM_LISTBOX:
334 case SID_FM_COMBOBOX:
335 case SID_FM_NAVIGATIONBAR:
336 case SID_FM_EDIT:
337 case SID_FM_DBGRID:
338 case SID_FM_IMAGEBUTTON:
339 case SID_FM_IMAGECONTROL:
340 case SID_FM_FILECONTROL:
341 case SID_FM_DATEFIELD:
342 case SID_FM_TIMEFIELD:
343 case SID_FM_NUMERICFIELD:
344 case SID_FM_CURRENCYFIELD:
345 case SID_FM_PATTERNFIELD:
346 case SID_FM_FORMATTEDFIELD:
347 case SID_FM_SCROLLBAR:
348 case SID_FM_SPINBUTTON:
349 m_nLastSlot = nSlot;
350 break;
354 // set the Identifier and Inventor of the Uno control
355 SdrObjKind nIdentifier = SdrObjKind::NONE;
356 switch( nSlot )
358 case SID_FM_CHECKBOX:
359 nIdentifier = SdrObjKind::FormCheckbox;
360 break;
361 case SID_FM_PUSHBUTTON:
362 nIdentifier = SdrObjKind::FormButton;
363 break;
364 case SID_FM_FIXEDTEXT:
365 nIdentifier = SdrObjKind::FormFixedText;
366 break;
367 case SID_FM_LISTBOX:
368 nIdentifier = SdrObjKind::FormListbox;
369 break;
370 case SID_FM_EDIT:
371 nIdentifier = SdrObjKind::FormEdit;
372 break;
373 case SID_FM_RADIOBUTTON:
374 nIdentifier = SdrObjKind::FormRadioButton;
375 break;
376 case SID_FM_GROUPBOX:
377 nIdentifier = SdrObjKind::FormGroupBox;
378 break;
379 case SID_FM_COMBOBOX:
380 nIdentifier = SdrObjKind::FormCombobox;
381 break;
382 case SID_FM_NAVIGATIONBAR:
383 nIdentifier = SdrObjKind::FormNavigationBar;
384 break;
385 case SID_FM_DBGRID:
386 nIdentifier = SdrObjKind::FormGrid;
387 break;
388 case SID_FM_IMAGEBUTTON:
389 nIdentifier = SdrObjKind::FormImageButton;
390 break;
391 case SID_FM_IMAGECONTROL:
392 nIdentifier = SdrObjKind::FormImageControl;
393 break;
394 case SID_FM_FILECONTROL:
395 nIdentifier = SdrObjKind::FormFileControl;
396 break;
397 case SID_FM_DATEFIELD:
398 nIdentifier = SdrObjKind::FormDateField;
399 break;
400 case SID_FM_TIMEFIELD:
401 nIdentifier = SdrObjKind::FormTimeField;
402 break;
403 case SID_FM_NUMERICFIELD:
404 nIdentifier = SdrObjKind::FormNumericField;
405 break;
406 case SID_FM_CURRENCYFIELD:
407 nIdentifier = SdrObjKind::FormCurrencyField;
408 break;
409 case SID_FM_PATTERNFIELD:
410 nIdentifier = SdrObjKind::FormPatternField;
411 break;
412 case SID_FM_FORMATTEDFIELD:
413 nIdentifier = SdrObjKind::FormFormattedField;
414 break;
415 case SID_FM_SCROLLBAR:
416 nIdentifier = SdrObjKind::FormScrollbar;
417 break;
418 case SID_FM_SPINBUTTON:
419 nIdentifier = SdrObjKind::FormSpinButton;
420 break;
423 switch ( nSlot )
425 case SID_FM_CHECKBOX:
426 case SID_FM_PUSHBUTTON:
427 case SID_FM_FIXEDTEXT:
428 case SID_FM_LISTBOX:
429 case SID_FM_EDIT:
430 case SID_FM_RADIOBUTTON:
431 case SID_FM_COMBOBOX:
432 case SID_FM_NAVIGATIONBAR:
433 case SID_FM_GROUPBOX:
434 case SID_FM_DBGRID:
435 case SID_FM_IMAGEBUTTON:
436 case SID_FM_IMAGECONTROL:
437 case SID_FM_FILECONTROL:
438 case SID_FM_DATEFIELD:
439 case SID_FM_TIMEFIELD:
440 case SID_FM_NUMERICFIELD:
441 case SID_FM_CURRENCYFIELD:
442 case SID_FM_PATTERNFIELD:
443 case SID_FM_FORMATTEDFIELD:
444 case SID_FM_SCROLLBAR:
445 case SID_FM_SPINBUTTON:
447 const SfxBoolItem* pGrabFocusItem = rReq.GetArg<SfxBoolItem>(SID_FM_TOGGLECONTROLFOCUS);
448 if ( pGrabFocusItem && pGrabFocusItem->GetValue() )
449 { // see below
450 SfxViewShell* pShell = GetViewShell();
451 vcl::Window* pShellWnd = pShell ? pShell->GetWindow() : nullptr;
452 if ( pShellWnd )
453 pShellWnd->GrabFocus();
454 break;
457 SfxUInt16Item aIdentifierItem( SID_FM_CONTROL_IDENTIFIER, static_cast<sal_uInt16>(nIdentifier) );
458 SfxUInt32Item aInventorItem( SID_FM_CONTROL_INVENTOR, sal_uInt32(SdrInventor::FmForm) );
459 const SfxPoolItem* pArgs[] =
461 &aIdentifierItem, &aInventorItem, nullptr
463 const SfxPoolItem* pInternalArgs[] =
465 nullptr
468 GetViewShell()->GetViewFrame().GetDispatcher()->Execute( SID_FM_CREATE_CONTROL, SfxCallMode::ASYNCHRON,
469 pArgs, rReq.GetModifier(), pInternalArgs );
471 if ( rReq.GetModifier() & KEY_MOD1 )
473 // #99013# if selected with control key, return focus to current view
474 // do this asynchron, so that the creation can be finished first
475 // reusing the SID_FM_TOGGLECONTROLFOCUS is somewhat hacky... which it wouldn't if it would have another
476 // name, so I do not really have a big problem with this...
477 SfxBoolItem aGrabFocusIndicatorItem( SID_FM_TOGGLECONTROLFOCUS, true );
478 GetViewShell()->GetViewFrame().GetDispatcher()->ExecuteList(
479 nSlot, SfxCallMode::ASYNCHRON,
480 { &aGrabFocusIndicatorItem });
483 rReq.Done();
484 } break;
487 // individual actions
488 switch( nSlot )
490 case SID_FM_FORM_DESIGN_TOOLS:
492 FormToolboxes aToolboxAccess(GetImpl()->getHostFrame_Lock());
493 aToolboxAccess.toggleToolbox( nSlot );
494 rReq.Done();
496 break;
498 case SID_FM_TOGGLECONTROLFOCUS:
500 FmFormView* pFormView = GetFormView();
501 if ( !pFormView )
502 break;
504 // if we execute this ourself, then either the application does not implement an own handling for this,
505 // of we're on the top of the dispatcher stack, which means a control has the focus.
506 // In the latter case, we put the focus to the document window, otherwise, we focus the first control
507 const bool bHasControlFocus = GetImpl()->HasControlFocus_Lock();
508 if ( bHasControlFocus )
510 if (m_pFormView)
512 const OutputDevice* pDevice = m_pFormView->GetActualOutDev();
513 vcl::Window* pWindow = pDevice->GetOwnerWindow();
514 if ( pWindow )
515 pWindow->GrabFocus();
518 else
520 pFormView->GrabFirstControlFocus( );
523 break;
525 case SID_FM_VIEW_AS_GRID:
526 GetImpl()->CreateExternalView_Lock();
527 break;
528 case SID_FM_CONVERTTO_EDIT :
529 case SID_FM_CONVERTTO_BUTTON :
530 case SID_FM_CONVERTTO_FIXEDTEXT :
531 case SID_FM_CONVERTTO_LISTBOX :
532 case SID_FM_CONVERTTO_CHECKBOX :
533 case SID_FM_CONVERTTO_RADIOBUTTON :
534 case SID_FM_CONVERTTO_GROUPBOX :
535 case SID_FM_CONVERTTO_COMBOBOX :
536 case SID_FM_CONVERTTO_IMAGEBUTTON :
537 case SID_FM_CONVERTTO_FILECONTROL :
538 case SID_FM_CONVERTTO_DATE :
539 case SID_FM_CONVERTTO_TIME :
540 case SID_FM_CONVERTTO_NUMERIC :
541 case SID_FM_CONVERTTO_CURRENCY :
542 case SID_FM_CONVERTTO_PATTERN :
543 case SID_FM_CONVERTTO_IMAGECONTROL :
544 case SID_FM_CONVERTTO_FORMATTED :
545 case SID_FM_CONVERTTO_SCROLLBAR :
546 case SID_FM_CONVERTTO_SPINBUTTON :
547 case SID_FM_CONVERTTO_NAVIGATIONBAR :
548 GetImpl()->executeControlConversionSlot_Lock(FmXFormShell::SlotToIdent(nSlot));
549 // after the conversion, re-determine the selection, since the
550 // selected object has changed
551 GetImpl()->SetSelection_Lock(GetFormView()->GetMarkedObjectList());
552 break;
553 case SID_FM_LEAVE_CREATE:
554 m_nLastSlot = 0;
555 rReq.Done();
556 break;
557 case SID_FM_SHOW_PROPERTY_BROWSER:
559 const SfxBoolItem* pShowItem = rReq.GetArg<SfxBoolItem>(SID_FM_SHOW_PROPERTIES);
560 bool bShow = true;
561 if ( pShowItem )
562 bShow = pShowItem->GetValue();
563 GetImpl()->ShowSelectionProperties_Lock(bShow);
565 rReq.Done();
566 } break;
568 case SID_FM_PROPERTIES:
570 // display the PropertyBrowser
571 const SfxBoolItem* pShowItem = rReq.GetArg<SfxBoolItem>(nSlot);
572 bool bShow = pShowItem == nullptr || pShowItem->GetValue();
574 InterfaceBag aOnlyTheForm;
575 aOnlyTheForm.insert(Reference<XInterface>(GetImpl()->getCurrentForm_Lock(), UNO_QUERY));
576 GetImpl()->setCurrentSelection_Lock(std::move(aOnlyTheForm));
578 GetImpl()->ShowSelectionProperties_Lock(bShow);
580 rReq.Done();
581 } break;
583 case SID_FM_CTL_PROPERTIES:
585 const SfxBoolItem* pShowItem = rReq.GetArg<SfxBoolItem>(nSlot);
586 bool bShow = pShowItem == nullptr || pShowItem->GetValue();
588 OSL_ENSURE( GetImpl()->onlyControlsAreMarked_Lock(), "FmFormShell::Execute: ControlProperties should be disabled!" );
589 if ( bShow )
590 GetImpl()->selectLastMarkedControls_Lock();
591 GetImpl()->ShowSelectionProperties_Lock(bShow);
593 rReq.Done();
594 } break;
595 case SID_FM_SHOW_PROPERTIES:
596 case SID_FM_ADD_FIELD:
597 case SID_FM_FILTER_NAVIGATOR:
598 case SID_FM_SHOW_DATANAVIGATOR :
600 GetViewShell()->GetViewFrame().ToggleChildWindow(nSlot);
601 rReq.Done();
602 } break;
603 case SID_FM_SHOW_FMEXPLORER:
605 if (!m_pFormView) // force setting the view
606 GetViewShell()->GetViewFrame().GetDispatcher()->Execute(SID_CREATE_SW_DRAWVIEW);
608 GetViewShell()->GetViewFrame().ChildWindowExecute(rReq);
609 rReq.Done();
611 break;
613 case SID_FM_TAB_DIALOG:
615 GetImpl()->ExecuteTabOrderDialog_Lock(
616 Reference<XTabControllerModel>(GetImpl()->getCurrentForm_Lock(), UNO_QUERY));
617 rReq.Done();
619 break;
621 case SID_FM_DESIGN_MODE:
623 const SfxBoolItem* pDesignItem = rReq.GetArg<SfxBoolItem>(nSlot);
624 bool bDesignMode = pDesignItem ? pDesignItem->GetValue() : !m_bDesignMode;
625 SetDesignMode( bDesignMode );
626 if ( m_bDesignMode == bDesignMode )
627 rReq.Done();
629 m_nLastSlot = SID_FM_DESIGN_MODE;
631 break;
633 case SID_FM_AUTOCONTROLFOCUS:
635 FmFormModel* pModel = GetFormModel();
636 DBG_ASSERT(pModel, "FmFormShell::Execute : invalid call !");
637 // should have been disabled in GetState if we don't have a FormModel
638 pModel->SetAutoControlFocus( !pModel->GetAutoControlFocus() );
639 GetViewShell()->GetViewFrame().GetBindings().Invalidate(SID_FM_AUTOCONTROLFOCUS);
641 break;
642 case SID_FM_OPEN_READONLY:
644 FmFormModel* pModel = GetFormModel();
645 DBG_ASSERT(pModel, "FmFormShell::Execute : invalid call !");
646 // should have been disabled in GetState if we don't have a FormModel
647 pModel->SetOpenInDesignMode( !pModel->GetOpenInDesignMode() );
648 GetViewShell()->GetViewFrame().GetBindings().Invalidate(SID_FM_OPEN_READONLY);
650 break;
651 case SID_FM_USE_WIZARDS:
653 GetImpl()->SetWizardUsing_Lock(!GetImpl()->GetWizardUsing_Lock());
654 GetViewShell()->GetViewFrame().GetBindings().Invalidate(SID_FM_USE_WIZARDS);
656 break;
657 case SID_FM_SEARCH:
659 const svx::ControllerFeatures& rController = GetImpl()->getActiveControllerFeatures_Lock();
660 if ( rController->commitCurrentControl() && rController->commitCurrentRecord() )
661 GetImpl()->ExecuteSearch_Lock();
662 rReq.Done();
664 break;
666 case SID_FM_RECORD_FIRST:
667 case SID_FM_RECORD_PREV:
668 case SID_FM_RECORD_NEXT:
669 case SID_FM_RECORD_LAST:
670 case SID_FM_RECORD_NEW:
671 case SID_FM_REFRESH:
672 case SID_FM_REFRESH_FORM_CONTROL:
673 case SID_FM_RECORD_DELETE:
674 case SID_FM_RECORD_UNDO:
675 case SID_FM_RECORD_SAVE:
676 case SID_FM_REMOVE_FILTER_SORT:
677 case SID_FM_SORTDOWN:
678 case SID_FM_SORTUP:
679 case SID_FM_AUTOFILTER:
680 case SID_FM_ORDERCRIT:
681 case SID_FM_FORM_FILTERED:
683 GetImpl()->ExecuteFormSlot_Lock(nSlot);
684 rReq.Done();
686 break;
688 case SID_FM_RECORD_ABSOLUTE:
690 const svx::ControllerFeatures& rController = GetImpl()->getNavControllerFeatures_Lock();
691 sal_Int32 nRecord = -1;
693 const SfxItemSet* pArgs = rReq.GetArgs();
694 if ( pArgs )
696 const SfxPoolItem* pItem;
697 if ( ( pArgs->GetItemState( FN_PARAM_1, true, &pItem ) ) == SfxItemState::SET )
699 const SfxInt32Item* pTypedItem = dynamic_cast<const SfxInt32Item* >( pItem );
700 if ( pTypedItem )
701 nRecord = std::max( pTypedItem->GetValue(), sal_Int32(0) );
704 else
706 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
707 ScopedVclPtr<AbstractFmInputRecordNoDialog> dlg(pFact->CreateFmInputRecordNoDialog(rReq.GetFrameWeld()));
708 dlg->SetValue( rController->getCursor()->getRow() );
709 if ( dlg->Execute() == RET_OK )
710 nRecord = dlg->GetValue();
712 rReq.AppendItem( SfxInt32Item( TypedWhichId<SfxInt32Item>(FN_PARAM_1), nRecord ) );
715 if ( nRecord != -1 )
716 rController->execute( nSlot, u"Position"_ustr, Any( nRecord ) );
718 rReq.Done();
719 } break;
720 case SID_FM_FILTER_EXECUTE:
721 case SID_FM_FILTER_EXIT:
723 bool bCancelled = ( SID_FM_FILTER_EXIT == nSlot );
724 bool bReopenNavigator = false;
726 if ( !bCancelled )
728 // if the filter navigator is still open, we need to close it, so it can possibly
729 // commit it's most recent changes
730 if (GetViewShell())
731 if ( GetViewShell()->GetViewFrame().HasChildWindow( SID_FM_FILTER_NAVIGATOR ) )
733 GetViewShell()->GetViewFrame().ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
734 bReopenNavigator = true;
737 Reference<runtime::XFormController> const xController(GetImpl()->getActiveController_Lock());
739 if ( GetViewShell()->GetViewFrame().HasChildWindow( SID_FM_FILTER_NAVIGATOR )
740 // closing the window was denied, for instance because of an invalid criterion
742 || ( xController.is()
743 && !GetImpl()->getActiveControllerFeatures_Lock()->commitCurrentControl()
745 // committing the controller was denied
748 rReq.Done();
749 break;
753 GetImpl()->stopFiltering_Lock(!bCancelled);
754 rReq.Done();
756 if ( bReopenNavigator )
757 // we closed the navigator only to implicitly commit it (as we do not have another
758 // direct wire to it), but to the user, it should look as it was always open
759 GetViewShell()->GetViewFrame().ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
761 break;
763 case SID_FM_FILTER_START:
765 GetImpl()->startFiltering_Lock();
766 rReq.Done();
768 // initially open the filter navigator, the whole form based filter is pretty useless without it
769 SfxBoolItem aIdentifierItem( SID_FM_FILTER_NAVIGATOR, true );
770 GetViewShell()->GetViewFrame().GetDispatcher()->ExecuteList(
771 SID_FM_FILTER_NAVIGATOR, SfxCallMode::ASYNCHRON,
772 { &aIdentifierItem });
773 } break;
778 void FmFormShell::GetState(SfxItemSet &rSet)
780 SfxWhichIter aIter( rSet );
781 sal_uInt16 nWhich = aIter.FirstWhich();
782 while ( nWhich )
784 switch( nWhich )
786 case SID_FM_FORM_DESIGN_TOOLS:
788 FormToolboxes aToolboxAccess(GetImpl()->getHostFrame_Lock());
789 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible( nWhich ) ) );
791 break;
793 case SID_FM_FILTER_EXECUTE:
794 case SID_FM_FILTER_EXIT:
795 if (!GetImpl()->isInFilterMode_Lock())
796 rSet.DisableItem( nWhich );
797 break;
799 case SID_FM_USE_WIZARDS:
800 if (!SvtModuleOptions().IsDataBaseInstalled())
801 rSet.Put( SfxVisibilityItem( nWhich, false ) );
802 else if (!GetFormModel())
803 rSet.DisableItem( nWhich );
804 else
805 rSet.Put(SfxBoolItem(nWhich, GetImpl()->GetWizardUsing_Lock()));
806 break;
807 case SID_FM_AUTOCONTROLFOCUS:
808 if (!GetFormModel())
809 rSet.DisableItem( nWhich );
810 else
811 rSet.Put( SfxBoolItem(nWhich, GetFormModel()->GetAutoControlFocus() ) );
812 break;
813 case SID_FM_OPEN_READONLY:
814 if (!GetFormModel())
815 rSet.DisableItem( nWhich );
816 else
817 rSet.Put( SfxBoolItem(nWhich, GetFormModel()->GetOpenInDesignMode() ) );
818 break;
820 case SID_FM_NAVIGATIONBAR:
821 case SID_FM_DBGRID:
822 if (!SvtModuleOptions().IsDataBaseInstalled())
824 rSet.Put( SfxVisibilityItem( nWhich, false ) );
825 break;
827 [[fallthrough]];
829 case SID_FM_SCROLLBAR:
830 case SID_FM_IMAGECONTROL:
831 case SID_FM_FILECONTROL:
832 case SID_FM_CURRENCYFIELD:
833 case SID_FM_PATTERNFIELD:
834 case SID_FM_IMAGEBUTTON:
835 case SID_FM_RADIOBUTTON:
836 case SID_FM_COMBOBOX:
837 case SID_FM_GROUPBOX:
838 case SID_FM_CHECKBOX:
839 case SID_FM_PUSHBUTTON:
840 case SID_FM_FIXEDTEXT:
841 case SID_FM_LISTBOX:
842 case SID_FM_EDIT:
843 case SID_FM_DATEFIELD:
844 case SID_FM_TIMEFIELD:
845 case SID_FM_NUMERICFIELD:
846 case SID_FM_FORMATTEDFIELD:
847 case SID_FM_SPINBUTTON:
848 if (!m_bDesignMode)
849 rSet.DisableItem( nWhich );
850 else
852 bool bLayerLocked = false;
853 if (m_pFormView)
855 // If the css::drawing::Layer is locked, the slots must be disabled. #36897
856 SdrPageView* pPV = m_pFormView->GetSdrPageView();
857 if (pPV != nullptr)
858 bLayerLocked = pPV->IsLayerLocked(m_pFormView->GetActiveLayer());
860 if (bLayerLocked)
861 rSet.DisableItem( nWhich );
862 else
863 rSet.Put( SfxBoolItem(nWhich, (nWhich==m_nLastSlot)) );
865 break;
866 case SID_FM_FILTER_NAVIGATOR_CONTROL:
868 if (GetImpl()->isInFilterMode_Lock())
869 rSet.Put(SfxObjectItem(nWhich, this));
870 else
871 rSet.Put(SfxObjectItem(nWhich));
872 } break;
873 case SID_FM_FIELDS_CONTROL:
874 case SID_FM_PROPERTY_CONTROL:
876 if (!m_bDesignMode || !m_pFormView || !m_bHasForms)
877 rSet.Put(SfxObjectItem(nWhich));
878 else
879 rSet.Put(SfxObjectItem(nWhich, this));
881 } break;
882 case SID_FM_FMEXPLORER_CONTROL:
883 case SID_FM_DATANAVIGATOR_CONTROL :
885 if (!m_bDesignMode || !m_pFormView)
886 rSet.Put(SfxObjectItem(nWhich));
887 else
888 rSet.Put(SfxObjectItem(nWhich, this));
890 } break;
891 case SID_FM_ADD_FIELD:
892 case SID_FM_SHOW_FMEXPLORER:
893 case SID_FM_SHOW_PROPERTIES:
894 case SID_FM_FILTER_NAVIGATOR:
895 case SID_FM_SHOW_DATANAVIGATOR:
897 if ( GetViewShell()->GetViewFrame().KnowsChildWindow(nWhich) )
898 rSet.Put( SfxBoolItem( nWhich, GetViewShell()->GetViewFrame().HasChildWindow(nWhich)) );
899 else
900 rSet.DisableItem(nWhich);
901 } break;
903 case SID_FM_SHOW_PROPERTY_BROWSER:
905 rSet.Put(SfxBoolItem(nWhich, GetImpl()->IsPropBrwOpen_Lock()));
907 break;
909 case SID_FM_CTL_PROPERTIES:
911 // potentially, give the Impl the opportunity to update its
912 // current objects which are aligned with the current MarkList
913 if (GetImpl()->IsSelectionUpdatePending_Lock())
914 GetImpl()->ForceUpdateSelection_Lock();
916 if (!m_pFormView || !m_bDesignMode || !GetImpl()->onlyControlsAreMarked_Lock())
917 rSet.DisableItem( nWhich );
918 else
920 bool const bChecked = GetImpl()->IsPropBrwOpen_Lock() && !GetImpl()->isSolelySelected_Lock(GetImpl()->getCurrentForm_Lock());
921 // if the property browser is open, and only controls are marked, and the current selection
922 // does not consist of only the current form, then the current selection is the (composition of)
923 // the currently marked controls
924 rSet.Put( SfxBoolItem( nWhich, bChecked ) );
926 } break;
928 case SID_FM_PROPERTIES:
930 // potentially, give the Impl the opportunity to update its
931 // current objects which are aligned with the current MarkList
932 if (GetImpl()->IsSelectionUpdatePending_Lock())
933 GetImpl()->ForceUpdateSelection_Lock();
935 if (!m_pFormView || !m_bDesignMode || !GetImpl()->getCurrentForm_Lock().is())
936 rSet.DisableItem( nWhich );
937 else
939 bool const bChecked = GetImpl()->IsPropBrwOpen_Lock() && GetImpl()->isSolelySelected_Lock(GetImpl()->getCurrentForm_Lock());
940 rSet.Put(SfxBoolItem(nWhich, bChecked));
942 } break;
943 case SID_FM_TAB_DIALOG:
944 // potentially, give the Impl the opportunity to update its
945 // current objects which are aligned with the current MarkList
946 if (GetImpl()->IsSelectionUpdatePending_Lock())
947 GetImpl()->ForceUpdateSelection_Lock();
949 if (!m_pFormView || !m_bDesignMode || !GetImpl()->getCurrentForm_Lock().is() )
950 rSet.DisableItem( nWhich );
951 break;
952 case SID_FM_DESIGN_MODE:
953 if (!m_pFormView || GetImpl()->IsReadonlyDoc_Lock())
954 rSet.DisableItem( nWhich );
955 else
956 rSet.Put( SfxBoolItem(nWhich, m_bDesignMode) );
957 break;
958 case SID_FM_SEARCH:
959 case SID_FM_RECORD_FIRST:
960 case SID_FM_RECORD_NEXT:
961 case SID_FM_RECORD_PREV:
962 case SID_FM_RECORD_LAST:
963 case SID_FM_RECORD_NEW:
964 case SID_FM_RECORD_DELETE:
965 case SID_FM_RECORD_ABSOLUTE:
966 case SID_FM_RECORD_TOTAL:
967 case SID_FM_RECORD_SAVE:
968 case SID_FM_RECORD_UNDO:
969 case SID_FM_FORM_FILTERED:
970 case SID_FM_REMOVE_FILTER_SORT:
971 case SID_FM_SORTUP:
972 case SID_FM_SORTDOWN:
973 case SID_FM_ORDERCRIT:
974 case SID_FM_FILTER_START:
975 case SID_FM_AUTOFILTER:
976 case SID_FM_REFRESH:
977 case SID_FM_REFRESH_FORM_CONTROL:
978 case SID_FM_VIEW_AS_GRID:
979 GetFormState(rSet,nWhich);
980 break;
982 case SID_FM_CHANGECONTROLTYPE:
984 if ( !m_pFormView || !m_bDesignMode )
985 rSet.DisableItem( nWhich );
986 else
988 if (!GetImpl()->canConvertCurrentSelectionToControl_Lock(u"ConvertToFixed"))
989 // if it cannot be converted to a fixed text, it is no single control
990 rSet.DisableItem( nWhich );
992 } break;
994 case SID_FM_CONVERTTO_FILECONTROL :
995 case SID_FM_CONVERTTO_CURRENCY :
996 case SID_FM_CONVERTTO_PATTERN :
997 case SID_FM_CONVERTTO_IMAGECONTROL :
998 case SID_FM_CONVERTTO_SCROLLBAR :
999 case SID_FM_CONVERTTO_NAVIGATIONBAR :
1000 case SID_FM_CONVERTTO_IMAGEBUTTON :
1001 case SID_FM_CONVERTTO_EDIT :
1002 case SID_FM_CONVERTTO_BUTTON :
1003 case SID_FM_CONVERTTO_FIXEDTEXT :
1004 case SID_FM_CONVERTTO_LISTBOX :
1005 case SID_FM_CONVERTTO_CHECKBOX :
1006 case SID_FM_CONVERTTO_RADIOBUTTON :
1007 case SID_FM_CONVERTTO_GROUPBOX :
1008 case SID_FM_CONVERTTO_COMBOBOX :
1009 case SID_FM_CONVERTTO_DATE :
1010 case SID_FM_CONVERTTO_TIME :
1011 case SID_FM_CONVERTTO_NUMERIC :
1012 case SID_FM_CONVERTTO_FORMATTED :
1013 case SID_FM_CONVERTTO_SPINBUTTON :
1015 if (!m_pFormView || !m_bDesignMode || !GetImpl()->canConvertCurrentSelectionToControl_Lock(FmXFormShell::SlotToIdent(nWhich)))
1016 rSet.DisableItem( nWhich );
1017 else
1019 rSet.Put( SfxBoolItem( nWhich, false ) );
1020 // just to have a defined state (available and not checked)
1023 break;
1025 nWhich = aIter.NextWhich();
1030 void FmFormShell::GetFormState(SfxItemSet &rSet, sal_uInt16 nWhich)
1032 if ( !GetImpl()->getNavController_Lock().is()
1033 || !isRowSetAlive(GetImpl()->getNavController_Lock()->getModel())
1034 || !m_pFormView
1035 || m_bDesignMode
1036 || !GetImpl()->getActiveForm_Lock().is()
1037 || GetImpl()->isInFilterMode_Lock()
1039 rSet.DisableItem(nWhich);
1040 else
1042 bool bEnable = false;
1045 switch (nWhich)
1047 case SID_FM_VIEW_AS_GRID:
1048 if (GetImpl()->getHostFrame_Lock().is() && GetImpl()->getNavController_Lock().is())
1050 bEnable = true;
1051 bool bDisplayingCurrent =
1052 GetImpl()->getInternalForm_Lock(
1053 Reference<XForm>(GetImpl()->getNavController_Lock()->getModel(), UNO_QUERY)
1054 ) == GetImpl()->getExternallyDisplayedForm_Lock();
1055 rSet.Put(SfxBoolItem(nWhich, bDisplayingCurrent));
1057 break;
1059 case SID_FM_SEARCH:
1061 Reference<css::beans::XPropertySet> const xNavSet(GetImpl()->getActiveForm_Lock(), UNO_QUERY);
1062 sal_Int32 nCount = ::comphelper::getINT32(xNavSet->getPropertyValue(FM_PROP_ROWCOUNT));
1063 bEnable = nCount != 0;
1064 } break;
1065 case SID_FM_RECORD_ABSOLUTE:
1066 case SID_FM_RECORD_TOTAL:
1068 FeatureState aState;
1069 GetImpl()->getNavControllerFeatures_Lock()->getState( nWhich, aState );
1070 if ( SID_FM_RECORD_ABSOLUTE == nWhich )
1072 sal_Int32 nPosition = 0;
1073 aState.State >>= nPosition;
1074 rSet.Put( SfxInt32Item( SID_FM_RECORD_ABSOLUTE, nPosition ) );
1076 else if ( SID_FM_RECORD_TOTAL == nWhich )
1078 OUString sTotalCount;
1079 aState.State >>= sTotalCount;
1080 rSet.Put( SfxStringItem( nWhich, sTotalCount ) );
1082 bEnable = aState.Enabled;
1084 break;
1086 // first, prev, next, last, and absolute affect the nav controller, not the
1087 // active controller
1088 case SID_FM_RECORD_FIRST:
1089 case SID_FM_RECORD_PREV:
1090 case SID_FM_RECORD_NEXT:
1091 case SID_FM_RECORD_LAST:
1092 case SID_FM_RECORD_NEW:
1093 case SID_FM_RECORD_SAVE:
1094 case SID_FM_RECORD_UNDO:
1095 case SID_FM_RECORD_DELETE:
1096 case SID_FM_REFRESH:
1097 case SID_FM_REFRESH_FORM_CONTROL:
1098 case SID_FM_REMOVE_FILTER_SORT:
1099 case SID_FM_SORTUP:
1100 case SID_FM_SORTDOWN:
1101 case SID_FM_AUTOFILTER:
1102 case SID_FM_ORDERCRIT:
1103 bEnable = GetImpl()->IsFormSlotEnabled( nWhich, nullptr );
1104 break;
1106 case SID_FM_FORM_FILTERED:
1108 FeatureState aState;
1109 bEnable = GetImpl()->IsFormSlotEnabled( nWhich, &aState );
1111 rSet.Put( SfxBoolItem( nWhich, ::comphelper::getBOOL( aState.State ) ) );
1113 break;
1115 case SID_FM_FILTER_START:
1116 bEnable = GetImpl()->getActiveControllerFeatures_Lock()->canDoFormFilter();
1117 break;
1120 catch( const Exception& )
1122 TOOLS_WARN_EXCEPTION("svx.form", "caught an exception while determining the state!");
1124 if (!bEnable)
1125 rSet.DisableItem(nWhich);
1130 FmFormPage* FmFormShell::GetCurPage() const
1132 FmFormPage* pP = nullptr;
1133 if (m_pFormView && m_pFormView->GetSdrPageView())
1134 pP = dynamic_cast<FmFormPage*>( m_pFormView->GetSdrPageView()->GetPage() );
1135 return pP;
1139 void FmFormShell::SetView( FmFormView* _pView )
1141 if ( m_pFormView )
1143 if ( IsActive() )
1144 GetImpl()->viewDeactivated_Lock(*m_pFormView);
1146 m_pFormView->SetFormShell( nullptr, FmFormView::FormShellAccess() );
1147 m_pFormView = nullptr;
1148 m_pFormModel = nullptr;
1151 if ( !_pView )
1152 return;
1154 m_pFormView = _pView;
1155 m_pFormView->SetFormShell( this, FmFormView::FormShellAccess() );
1156 m_pFormModel = static_cast<FmFormModel*>(&m_pFormView->GetModel());
1158 impl_setDesignMode( m_pFormView->IsDesignMode() );
1160 // We activate our view if we are activated ourself, but sometimes the Activate precedes the SetView.
1161 // But here we know both the view and our activation state so we at least are able to pass the latter
1162 // to the former.
1163 // FS - 30.06.99 - 67308
1164 if ( IsActive() )
1165 GetImpl()->viewActivated_Lock(*m_pFormView);
1169 void FmFormShell::DetermineForms(bool bInvalidate)
1171 // are there forms on the current page
1172 bool bForms = GetImpl()->hasForms_Lock();
1173 if (bForms != m_bHasForms)
1175 m_bHasForms = bForms;
1176 if (bInvalidate)
1177 UIFeatureChanged();
1182 bool FmFormShell::GetY2KState(sal_uInt16& nReturn)
1184 return GetImpl()->GetY2KState_Lock(nReturn);
1188 void FmFormShell::SetY2KState(sal_uInt16 n)
1190 GetImpl()->SetY2KState_Lock(n);
1194 void FmFormShell::Activate(bool bMDI)
1196 SfxShell::Activate(bMDI);
1198 if ( m_pFormView )
1199 GetImpl()->viewActivated_Lock(*m_pFormView, true);
1203 void FmFormShell::Deactivate(bool bMDI)
1205 SfxShell::Deactivate(bMDI);
1207 if ( m_pFormView )
1208 GetImpl()->viewDeactivated_Lock(*m_pFormView, false);
1212 void FmFormShell::ExecuteTextAttribute( SfxRequest& _rReq )
1214 m_pImpl->ExecuteTextAttribute_Lock(_rReq);
1218 void FmFormShell::GetTextAttributeState( SfxItemSet& _rSet )
1220 m_pImpl->GetTextAttributeState_Lock(_rSet);
1224 bool FmFormShell::IsActiveControl() const
1226 return m_pImpl->IsActiveControl_Lock(false);
1230 void FmFormShell::ForgetActiveControl()
1232 m_pImpl->ForgetActiveControl_Lock();
1236 void FmFormShell::SetControlActivationHandler( const Link<LinkParamNone*,void>& _rHdl )
1238 m_pImpl->SetControlActivationHandler_Lock(_rHdl);
1242 namespace
1244 SdrUnoObj* lcl_findUnoObject( const SdrObjList& _rObjList, const Reference< XControlModel >& _rxModel )
1246 SdrObjListIter aIter( &_rObjList );
1247 while ( aIter.IsMore() )
1249 SdrObject* pObject = aIter.Next();
1250 SdrUnoObj* pUnoObject = dynamic_cast<SdrUnoObj*>( pObject );
1251 if ( !pUnoObject )
1252 continue;
1254 Reference< XControlModel > xControlModel = pUnoObject->GetUnoControlModel();
1255 if ( !xControlModel.is() )
1256 continue;
1258 if ( _rxModel == xControlModel )
1259 return pUnoObject;
1261 return nullptr;
1266 void FmFormShell::ToggleControlFocus( const SdrUnoObj& i_rUnoObject, const SdrView& i_rView, const OutputDevice& i_rDevice ) const
1270 // check if the focus currently is in a control
1271 // Well, okay, do it the other way 'round: Check whether the current control of the active controller
1272 // actually has the focus. This should be equivalent.
1273 const bool bHasControlFocus = GetImpl()->HasControlFocus_Lock();
1275 if ( bHasControlFocus )
1277 vcl::Window* pWindow = i_rDevice.GetOwnerWindow();
1278 OSL_ENSURE( pWindow, "FmFormShell::ToggleControlFocus: I need a Window, really!" );
1279 if ( pWindow )
1280 pWindow->GrabFocus();
1282 else
1284 Reference< XControl > xControl;
1285 GetFormControl( i_rUnoObject.GetUnoControlModel(), i_rView, i_rDevice, xControl );
1286 Reference< XWindow > xControlWindow( xControl, UNO_QUERY );
1287 if ( xControlWindow.is() )
1288 xControlWindow->setFocus();
1291 catch( const Exception& )
1293 DBG_UNHANDLED_EXCEPTION("svx");
1298 namespace
1300 class FocusableControlsFilter : public svx::ISdrObjectFilter
1302 public:
1303 FocusableControlsFilter( const SdrView& i_rView, const OutputDevice& i_rDevice )
1304 :m_rView( i_rView )
1305 ,m_rDevice( i_rDevice )
1309 public:
1310 virtual bool includeObject( const SdrObject& i_rObject ) const override
1312 const SdrUnoObj* pUnoObj = dynamic_cast< const SdrUnoObj* >( &i_rObject );
1313 if ( !pUnoObj )
1314 return false;
1316 Reference< XControl > xControl = pUnoObj->GetUnoControl( m_rView, m_rDevice );
1317 return FmXFormView::isFocusable( xControl );
1320 private:
1321 const SdrView& m_rView;
1322 const OutputDevice& m_rDevice;
1327 ::std::unique_ptr< svx::ISdrObjectFilter > FmFormShell::CreateFocusableControlFilter( const SdrView& i_rView, const OutputDevice& i_rDevice )
1329 ::std::unique_ptr< svx::ISdrObjectFilter > pFilter;
1331 if ( !i_rView.IsDesignMode() )
1332 pFilter.reset( new FocusableControlsFilter( i_rView, i_rDevice ) );
1334 return pFilter;
1338 SdrUnoObj* FmFormShell::GetFormControl( const Reference< XControlModel >& _rxModel, const SdrView& _rView, const OutputDevice& _rDevice, Reference< XControl >& _out_rxControl ) const
1340 if ( !_rxModel.is() )
1341 return nullptr;
1343 // we can only retrieve controls for SdrObjects which belong to page which is actually displayed in the given view
1344 SdrPageView* pPageView = _rView.GetSdrPageView();
1345 SdrPage* pPage = pPageView ? pPageView->GetPage() : nullptr;
1346 OSL_ENSURE( pPage, "FmFormShell::GetFormControl: no page displayed in the given view!" );
1347 if ( !pPage )
1348 return nullptr;
1350 SdrUnoObj* pUnoObject = lcl_findUnoObject( *pPage, _rxModel );
1351 if ( pUnoObject )
1353 _out_rxControl = pUnoObject->GetUnoControl( _rView, _rDevice );
1354 return pUnoObject;
1357 #if OSL_DEBUG_LEVEL > 0
1358 // perhaps we are fed with a control model which lives on a page other than the one displayed
1359 // in the given view. This is worth being reported as error, in non-product builds.
1360 FmFormModel* pModel = GetFormModel();
1361 if ( pModel )
1363 sal_uInt16 pageCount = pModel->GetPageCount();
1364 for ( sal_uInt16 page = 0; page < pageCount; ++page )
1366 pPage = pModel->GetPage( page );
1367 OSL_ENSURE( pPage, "FmFormShell::GetFormControl: NULL page encountered!" );
1368 if ( !pPage )
1369 continue;
1371 pUnoObject = lcl_findUnoObject( *pPage, _rxModel );
1372 OSL_ENSURE( !pUnoObject, "FmFormShell::GetFormControl: the given control model belongs to a wrong page (displayed elsewhere)!" );
1375 #else
1376 (void) this; // avoid loplugin:staticmethods
1377 #endif
1379 return nullptr;
1383 Reference< runtime::XFormController > FmFormShell::GetFormController( const Reference< XForm >& _rxForm, const SdrView& _rView, const OutputDevice& _rDevice )
1385 const FmFormView* pFormView = dynamic_cast< const FmFormView* >( &_rView );
1386 if ( !pFormView )
1387 return nullptr;
1389 return pFormView->GetFormController( _rxForm, _rDevice );
1393 void FmFormShell::SetDesignMode( bool _bDesignMode )
1395 if ( _bDesignMode == m_bDesignMode )
1396 return;
1398 FmFormModel* pModel = GetFormModel();
1399 if (pModel)
1400 // Switch off the undo environment for the time of the transition. This ensures that
1401 // one can also change non-transient properties there. (It should be done with
1402 // caution, however, and it should always be reversed when one switches the mode back.
1403 // An example is the setting of the maximum text length by the OEditModel on its control.)
1404 pModel->GetUndoEnv().Lock();
1406 // then the actual switch
1407 if ( m_bDesignMode || PrepareClose() )
1408 impl_setDesignMode(!m_bDesignMode );
1410 // and my undo environment back on
1411 if ( pModel )
1412 pModel->GetUndoEnv().UnLock();
1415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */