LibreOffice Module svx (master)  1
fmshell.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <fmvwimp.hxx>
21 #include <svx/fmshell.hxx>
22 #include <svx/fmtools.hxx>
23 #include <fmservs.hxx>
24 #include <fmprop.hxx>
25 #include <fmpgeimp.hxx>
26 #include <fmundo.hxx>
27 #include <com/sun/star/form/XLoadable.hpp>
28 #include <com/sun/star/container/XNamed.hpp>
29 #include <com/sun/star/sdbcx/Privilege.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/beans/XMultiPropertySet.hpp>
32 #include <com/sun/star/beans/XFastPropertySet.hpp>
33 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/container/XNameContainer.hpp>
36 #include <com/sun/star/awt/XTabControllerModel.hpp>
37 #include <sfx2/viewfrm.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/weld.hxx>
40 #include <svl/whiter.hxx>
41 #include <sfx2/app.hxx>
42 #include <svl/intitem.hxx>
43 #include <svl/stritem.hxx>
44 #include <svl/visitem.hxx>
46 #include <sfx2/objface.hxx>
47 #include <sfx2/request.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include <sfx2/objsh.hxx>
50 #include <svx/svdobj.hxx>
51 #include <svx/fmpage.hxx>
52 #include <svx/svditer.hxx>
53 #include <fmobj.hxx>
54 
55 #include <svx/svxids.hrc>
56 
57 #include <fmexch.hxx>
58 #include <svx/fmglob.hxx>
59 #include <svl/eitem.hxx>
60 #include <tools/diagnose_ex.h>
61 #include <svx/svdpage.hxx>
62 #include <svx/fmmodel.hxx>
63 #include <fmshimp.hxx>
64 #include <svx/svdpagv.hxx>
65 #include <sfx2/objitem.hxx>
66 #include <sfx2/viewsh.hxx>
67 #include <fmexpl.hxx>
68 #include <formcontrolling.hxx>
69 #include <svl/numuno.hxx>
70 #include <connectivity/dbtools.hxx>
71 #include <comphelper/types.hxx>
73 #include <formtoolbars.hxx>
74 
75 #include <svx/svxdlg.hxx>
76 
77 #include <svx/sdrobjectfilter.hxx>
78 
79 #define ShellClass_FmFormShell
80 #include <svxslots.hxx>
81 
82 #include <tbxform.hxx>
83 #include <com/sun/star/beans/PropertyValue.hpp>
84 
85 #include <memory>
86 
87 // is used for Invalidate -> maintain it as well
88 // sort ascending !!!!!!
89 sal_uInt16 const ControllerSlotMap[] = // slots of the controller
90 {
91  SID_FM_CONFIG,
92  SID_FM_PUSHBUTTON,
93  SID_FM_RADIOBUTTON,
94  SID_FM_CHECKBOX,
95  SID_FM_FIXEDTEXT,
96  SID_FM_GROUPBOX,
97  SID_FM_EDIT,
98  SID_FM_LISTBOX,
99  SID_FM_COMBOBOX,
100  SID_FM_DBGRID,
101  SID_FM_IMAGEBUTTON,
102  SID_FM_FILECONTROL,
103  SID_FM_NAVIGATIONBAR,
104  SID_FM_CTL_PROPERTIES,
105  SID_FM_PROPERTIES,
106  SID_FM_TAB_DIALOG,
107  SID_FM_ADD_FIELD,
108  SID_FM_DESIGN_MODE,
109  SID_FM_SHOW_FMEXPLORER,
110  SID_FM_SHOW_PROPERTIES,
111  SID_FM_FMEXPLORER_CONTROL,
112  SID_FM_DATEFIELD,
113  SID_FM_TIMEFIELD,
114  SID_FM_NUMERICFIELD,
115  SID_FM_CURRENCYFIELD,
116  SID_FM_PATTERNFIELD,
117  SID_FM_OPEN_READONLY,
118  SID_FM_IMAGECONTROL,
119  SID_FM_USE_WIZARDS,
120  SID_FM_FORMATTEDFIELD,
121  SID_FM_FILTER_NAVIGATOR,
122  SID_FM_AUTOCONTROLFOCUS,
123  SID_FM_SCROLLBAR,
124  SID_FM_SPINBUTTON,
125  SID_FM_SHOW_DATANAVIGATOR,
126  SID_FM_DATANAVIGATOR_CONTROL,
127 
128  0
129 };
130 
131 using namespace ::com::sun::star::uno;
132 using namespace ::com::sun::star::awt;
133 using namespace ::com::sun::star::sdbc;
134 using namespace ::com::sun::star::sdbcx;
135 using namespace ::com::sun::star::beans;
136 using namespace ::com::sun::star::form;
137 using namespace ::com::sun::star::form::runtime;
138 using namespace ::svxform;
139 
141  :m_bDesignMode( bDesMode )
142 {
143 }
144 
145 
147 {
148 }
149 
151 
152 void FmFormShell::InitInterface_Impl()
153 {
154  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_NAVIGATION, SfxVisibilityFlags::Standard|SfxVisibilityFlags::ReadonlyDoc,
155  ToolbarId::SvxTbx_Form_Navigation,
156  SfxShellFeature::FormShowDatabaseBar);
157 
158  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_NAVIGATION, SfxVisibilityFlags::Standard|SfxVisibilityFlags::ReadonlyDoc,
159  ToolbarId::SvxTbx_Form_Filter,
160  SfxShellFeature::FormShowFilterBar);
161 
162  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Standard | SfxVisibilityFlags::ReadonlyDoc,
163  ToolbarId::SvxTbx_Text_Control_Attributes,
164  SfxShellFeature::FormShowTextControlBar);
165 
166  GetStaticInterface()->RegisterChildWindow(SID_FM_ADD_FIELD, false, SfxShellFeature::FormShowField);
167  GetStaticInterface()->RegisterChildWindow(SID_FM_SHOW_PROPERTIES, false, SfxShellFeature::FormShowProperies);
168  GetStaticInterface()->RegisterChildWindow(SID_FM_SHOW_FMEXPLORER, false, SfxShellFeature::FormShowExplorer);
169  GetStaticInterface()->RegisterChildWindow(SID_FM_FILTER_NAVIGATOR, false, SfxShellFeature::FormShowFilterNavigator);
170  GetStaticInterface()->RegisterChildWindow(SID_FM_SHOW_DATANAVIGATOR, false, SfxShellFeature::FormShowDataNavigator);
171 
172  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Standard,
173  ToolbarId::SvxTbx_Controls,
174  SfxShellFeature::FormTBControls);
175 
176  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Standard,
177  ToolbarId::SvxTbx_FormDesign,
178  SfxShellFeature::FormTBDesign);
179 }
180 
181 
183  :SfxShell(_pParent)
184  ,m_pImpl(new FmXFormShell(*this, _pParent->GetViewFrame()))
185  ,m_pFormView( pView )
186  ,m_pFormModel( nullptr )
187  ,m_nLastSlot( 0 )
188  ,m_bDesignMode( true )
189  ,m_bHasForms(false)
190 {
191  SetPool( &SfxGetpApp()->GetPool() );
192  SetName( "Form" );
193 
195 }
196 
197 
199 {
200  if ( m_pFormView )
201  SetView( nullptr );
202 
203  m_pImpl->dispose();
204 }
205 
206 
208 {
209  FmNavViewMarksChanged aChangeNotification(pWhichView);
210  Broadcast(aChangeNotification);
211 }
212 
213 
215 {
216  if (GetImpl()->didPrepareClose_Lock())
217  // we already did a PrepareClose for the current modifications of the current form
218  return true;
219 
220  bool bResult = true;
221  // Save the data records, not in DesignMode and FilterMode
222  if (!m_bDesignMode && !GetImpl()->isInFilterMode_Lock() &&
225  {
226  SdrPageView* pCurPageView = m_pFormView->GetSdrPageView();
227 
228  // sal_uInt16 nPos = pCurPageView ? pCurPageView->GetWinList().Find((OutputDevice*)m_pFormView->GetActualOutDev()) : SDRPAGEVIEWWIN_NOTFOUND;
229  SdrPageWindow* pWindow = pCurPageView ? pCurPageView->FindPageWindow(*const_cast<OutputDevice*>(m_pFormView->GetActualOutDev())) : nullptr;
230 
231  if(pWindow)
232  {
233  // First, the current contents of the controls are stored.
234  // If everything has gone smoothly, the modified records are stored.
235  if (GetImpl()->getActiveController_Lock().is())
236  {
238  if ( rController->commitCurrentControl() )
239  {
240  const bool bModified = rController->isModifiedRow();
241 
242  if ( bModified && bUI )
243  {
244  SfxViewShell* pShell = GetViewShell();
245  vcl::Window* pShellWnd = pShell ? pShell->GetWindow() : nullptr;
246  weld::Widget* pFrameWeld = pShellWnd ? pShellWnd->GetFrameWeld() : nullptr;
247  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pFrameWeld, "svx/ui/savemodifieddialog.ui"));
248  std::unique_ptr<weld::MessageDialog> xQry(xBuilder->weld_message_dialog("SaveModifiedDialog"));
249  switch (xQry->run())
250  {
251  case RET_YES:
252  bResult = rController->commitCurrentRecord( );
253  [[fallthrough]];
254  case RET_NO:
255  GetImpl()->didPrepareClose_Lock(true);
256  break;
257 
258  case RET_CANCEL:
259  return false;
260  }
261  }
262  }
263  }
264  }
265  }
266  return bResult;
267 }
268 
269 
271 {
272  if (m_pFormView)
273  {
274  if (!bDesign)
275  m_nLastSlot = SID_FM_DESIGN_MODE;
276 
277  GetImpl()->SetDesignMode_Lock(bDesign);
278  // my m_bDesignMode is also set by the Impl ...
279  }
280  else
281  {
282  m_bHasForms = false;
283  m_bDesignMode = bDesign;
285  }
286 
288 }
289 
290 
292 {
293  assert((nFeature & ~SfxShellFeature::FormMask) == SfxShellFeature::NONE);
294  bool bResult = false;
295  if (nFeature & SfxShellFeature::FormShowDatabaseBar)
296  {
297  // only if forms are also available
299  }
300  else if (nFeature & SfxShellFeature::FormShowFilterBar)
301  {
302  // only if forms are also available
304  }
305  else if (nFeature & SfxShellFeature::FormShowFilterNavigator)
306  {
308  }
309  else if (nFeature & SfxShellFeature::FormShowField)
310  {
311  bResult = m_bDesignMode && m_pFormView && m_bHasForms;
312  }
313  else if (nFeature & SfxShellFeature::FormShowProperies)
314  {
315  bResult = m_bDesignMode && m_pFormView && m_bHasForms;
316  }
317  else if (nFeature & SfxShellFeature::FormShowExplorer)
318  {
319  bResult = m_bDesignMode; // OJ #101593# && m_pFormView && m_bHasForms;
320  }
321  else if (nFeature & SfxShellFeature::FormShowTextControlBar)
322  {
323  bResult = !GetImpl()->IsReadonlyDoc_Lock() && m_pImpl->IsActiveControl_Lock(true);
324  }
325  else if (nFeature & SfxShellFeature::FormShowDataNavigator)
326  {
327  bResult = GetImpl()->isEnhancedForm_Lock();
328  }
329  else if ( (nFeature & SfxShellFeature::FormTBControls)
330  || (nFeature & SfxShellFeature::FormTBDesign)
331  )
332  {
333  bResult = true;
334  }
335 
336  return bResult;
337 }
338 
339 
341 {
342  sal_uInt16 nSlot = rReq.GetSlot();
343 
344 
345  // set MasterSlot
346  switch( nSlot )
347  {
348  case SID_FM_PUSHBUTTON:
349  case SID_FM_RADIOBUTTON:
350  case SID_FM_CHECKBOX:
351  case SID_FM_FIXEDTEXT:
352  case SID_FM_GROUPBOX:
353  case SID_FM_LISTBOX:
354  case SID_FM_COMBOBOX:
355  case SID_FM_NAVIGATIONBAR:
356  case SID_FM_EDIT:
357  case SID_FM_DBGRID:
358  case SID_FM_IMAGEBUTTON:
359  case SID_FM_IMAGECONTROL:
360  case SID_FM_FILECONTROL:
361  case SID_FM_DATEFIELD:
362  case SID_FM_TIMEFIELD:
363  case SID_FM_NUMERICFIELD:
364  case SID_FM_CURRENCYFIELD:
365  case SID_FM_PATTERNFIELD:
366  case SID_FM_FORMATTEDFIELD:
367  case SID_FM_SCROLLBAR:
368  case SID_FM_SPINBUTTON:
369  m_nLastSlot = nSlot;
370  break;
371  }
372 
373 
374  // set the Identifier and Inventor of the Uno control
375  sal_uInt16 nIdentifier = 0;
376  switch( nSlot )
377  {
378  case SID_FM_CHECKBOX:
379  nIdentifier = OBJ_FM_CHECKBOX;
380  break;
381  case SID_FM_PUSHBUTTON:
382  nIdentifier = OBJ_FM_BUTTON;
383  break;
384  case SID_FM_FIXEDTEXT:
385  nIdentifier = OBJ_FM_FIXEDTEXT;
386  break;
387  case SID_FM_LISTBOX:
388  nIdentifier = OBJ_FM_LISTBOX;
389  break;
390  case SID_FM_EDIT:
391  nIdentifier = OBJ_FM_EDIT;
392  break;
393  case SID_FM_RADIOBUTTON:
394  nIdentifier = OBJ_FM_RADIOBUTTON;
395  break;
396  case SID_FM_GROUPBOX:
397  nIdentifier = OBJ_FM_GROUPBOX;
398  break;
399  case SID_FM_COMBOBOX:
400  nIdentifier = OBJ_FM_COMBOBOX;
401  break;
402  case SID_FM_NAVIGATIONBAR:
403  nIdentifier = OBJ_FM_NAVIGATIONBAR;
404  break;
405  case SID_FM_DBGRID:
406  nIdentifier = OBJ_FM_GRID;
407  break;
408  case SID_FM_IMAGEBUTTON:
409  nIdentifier = OBJ_FM_IMAGEBUTTON;
410  break;
411  case SID_FM_IMAGECONTROL:
412  nIdentifier = OBJ_FM_IMAGECONTROL;
413  break;
414  case SID_FM_FILECONTROL:
415  nIdentifier = OBJ_FM_FILECONTROL;
416  break;
417  case SID_FM_DATEFIELD:
418  nIdentifier = OBJ_FM_DATEFIELD;
419  break;
420  case SID_FM_TIMEFIELD:
421  nIdentifier = OBJ_FM_TIMEFIELD;
422  break;
423  case SID_FM_NUMERICFIELD:
424  nIdentifier = OBJ_FM_NUMERICFIELD;
425  break;
426  case SID_FM_CURRENCYFIELD:
427  nIdentifier = OBJ_FM_CURRENCYFIELD;
428  break;
429  case SID_FM_PATTERNFIELD:
430  nIdentifier = OBJ_FM_PATTERNFIELD;
431  break;
432  case SID_FM_FORMATTEDFIELD:
433  nIdentifier = OBJ_FM_FORMATTEDFIELD;
434  break;
435  case SID_FM_SCROLLBAR:
436  nIdentifier = OBJ_FM_SCROLLBAR;
437  break;
438  case SID_FM_SPINBUTTON:
439  nIdentifier = OBJ_FM_SPINBUTTON;
440  break;
441  }
442 
443  switch ( nSlot )
444  {
445  case SID_FM_CHECKBOX:
446  case SID_FM_PUSHBUTTON:
447  case SID_FM_FIXEDTEXT:
448  case SID_FM_LISTBOX:
449  case SID_FM_EDIT:
450  case SID_FM_RADIOBUTTON:
451  case SID_FM_COMBOBOX:
452  case SID_FM_NAVIGATIONBAR:
453  case SID_FM_GROUPBOX:
454  case SID_FM_DBGRID:
455  case SID_FM_IMAGEBUTTON:
456  case SID_FM_IMAGECONTROL:
457  case SID_FM_FILECONTROL:
458  case SID_FM_DATEFIELD:
459  case SID_FM_TIMEFIELD:
460  case SID_FM_NUMERICFIELD:
461  case SID_FM_CURRENCYFIELD:
462  case SID_FM_PATTERNFIELD:
463  case SID_FM_FORMATTEDFIELD:
464  case SID_FM_SCROLLBAR:
465  case SID_FM_SPINBUTTON:
466  {
467  const SfxBoolItem* pGrabFocusItem = rReq.GetArg<SfxBoolItem>(SID_FM_TOGGLECONTROLFOCUS);
468  if ( pGrabFocusItem && pGrabFocusItem->GetValue() )
469  { // see below
470  SfxViewShell* pShell = GetViewShell();
471  vcl::Window* pShellWnd = pShell ? pShell->GetWindow() : nullptr;
472  if ( pShellWnd )
473  pShellWnd->GrabFocus();
474  break;
475  }
476 
477  SfxUInt16Item aIdentifierItem( SID_FM_CONTROL_IDENTIFIER, nIdentifier );
478  SfxUInt32Item aInventorItem( SID_FM_CONTROL_INVENTOR, sal_uInt32(SdrInventor::FmForm) );
479  const SfxPoolItem* pArgs[] =
480  {
481  &aIdentifierItem, &aInventorItem, nullptr
482  };
483  const SfxPoolItem* pInternalArgs[] =
484  {
485  nullptr
486  };
487 
488  GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_CREATE_CONTROL, SfxCallMode::ASYNCHRON,
489  pArgs, rReq.GetModifier(), pInternalArgs );
490 
491  if ( rReq.GetModifier() & KEY_MOD1 )
492  {
493  // #99013# if selected with control key, return focus to current view
494  // do this asynchron, so that the creation can be finished first
495  // reusing the SID_FM_TOGGLECONTROLFOCUS is somewhat hacky... which it wouldn't if it would have another
496  // name, so I do not really have a big problem with this...
497  SfxBoolItem aGrabFocusIndicatorItem( SID_FM_TOGGLECONTROLFOCUS, true );
499  nSlot, SfxCallMode::ASYNCHRON,
500  { &aGrabFocusIndicatorItem });
501  }
502 
503  rReq.Done();
504  } break;
505  }
506 
507  // individual actions
508  switch( nSlot )
509  {
510  case SID_FM_FORM_DESIGN_TOOLS:
511  {
512  FormToolboxes aToolboxAccess(GetImpl()->getHostFrame_Lock());
513  aToolboxAccess.toggleToolbox( nSlot );
514  rReq.Done();
515  }
516  break;
517 
518  case SID_FM_TOGGLECONTROLFOCUS:
519  {
520  FmFormView* pFormView = GetFormView();
521  if ( !pFormView )
522  break;
523 
524  // if we execute this ourself, then either the application does not implement an own handling for this,
525  // of we're on the top of the dispatcher stack, which means a control has the focus.
526  // In the latter case, we put the focus to the document window, otherwise, we focus the first control
527  const bool bHasControlFocus = GetImpl()->HasControlFocus_Lock();
528  if ( bHasControlFocus )
529  {
530  if (m_pFormView)
531  {
532  const OutputDevice* pDevice = m_pFormView->GetActualOutDev();
533  vcl::Window* pWindow = dynamic_cast< vcl::Window* >( const_cast< OutputDevice* >( pDevice ) );
534  if ( pWindow )
535  pWindow->GrabFocus();
536  }
537  }
538  else
539  {
540  pFormView->GrabFirstControlFocus( );
541  }
542  }
543  break;
544 
545  case SID_FM_VIEW_AS_GRID:
547  break;
548  case SID_FM_CONVERTTO_EDIT :
549  case SID_FM_CONVERTTO_BUTTON :
550  case SID_FM_CONVERTTO_FIXEDTEXT :
551  case SID_FM_CONVERTTO_LISTBOX :
552  case SID_FM_CONVERTTO_CHECKBOX :
553  case SID_FM_CONVERTTO_RADIOBUTTON :
554  case SID_FM_CONVERTTO_GROUPBOX :
555  case SID_FM_CONVERTTO_COMBOBOX :
556  case SID_FM_CONVERTTO_IMAGEBUTTON :
557  case SID_FM_CONVERTTO_FILECONTROL :
558  case SID_FM_CONVERTTO_DATE :
559  case SID_FM_CONVERTTO_TIME :
560  case SID_FM_CONVERTTO_NUMERIC :
561  case SID_FM_CONVERTTO_CURRENCY :
562  case SID_FM_CONVERTTO_PATTERN :
563  case SID_FM_CONVERTTO_IMAGECONTROL :
564  case SID_FM_CONVERTTO_FORMATTED :
565  case SID_FM_CONVERTTO_SCROLLBAR :
566  case SID_FM_CONVERTTO_SPINBUTTON :
567  case SID_FM_CONVERTTO_NAVIGATIONBAR :
569  // after the conversion, re-determine the selection, since the
570  // selected object has changed
571  GetImpl()->SetSelection_Lock(GetFormView()->GetMarkedObjectList());
572  break;
573  case SID_FM_LEAVE_CREATE:
574  m_nLastSlot = 0;
575  rReq.Done();
576  break;
577  case SID_FM_SHOW_PROPERTY_BROWSER:
578  {
579  const SfxBoolItem* pShowItem = rReq.GetArg<SfxBoolItem>(SID_FM_SHOW_PROPERTIES);
580  bool bShow = true;
581  if ( pShowItem )
582  bShow = pShowItem->GetValue();
584 
585  rReq.Done();
586  } break;
587 
588  case SID_FM_PROPERTIES:
589  {
590  // display the PropertyBrowser
591  const SfxBoolItem* pShowItem = rReq.GetArg<SfxBoolItem>(nSlot);
592  bool bShow = pShowItem == nullptr || pShowItem->GetValue();
593 
594  InterfaceBag aOnlyTheForm;
595  aOnlyTheForm.insert(Reference<XInterface>(GetImpl()->getCurrentForm_Lock(), UNO_QUERY));
596  GetImpl()->setCurrentSelection_Lock(aOnlyTheForm);
597 
599 
600  rReq.Done();
601  } break;
602 
603  case SID_FM_CTL_PROPERTIES:
604  {
605  const SfxBoolItem* pShowItem = rReq.GetArg<SfxBoolItem>(nSlot);
606  bool bShow = pShowItem == nullptr || pShowItem->GetValue();
607 
608  OSL_ENSURE( GetImpl()->onlyControlsAreMarked_Lock(), "FmFormShell::Execute: ControlProperties should be disabled!" );
609  if ( bShow )
612 
613  rReq.Done();
614  } break;
615  case SID_FM_SHOW_PROPERTIES:
616  case SID_FM_ADD_FIELD:
617  case SID_FM_FILTER_NAVIGATOR:
618  case SID_FM_SHOW_DATANAVIGATOR :
619  {
621  rReq.Done();
622  } break;
623  case SID_FM_SHOW_FMEXPLORER:
624  {
625  if (!m_pFormView) // force setting the view
626  GetViewShell()->GetViewFrame()->GetDispatcher()->Execute(SID_CREATE_SW_DRAWVIEW);
627 
629  rReq.Done();
630  }
631  break;
632 
633  case SID_FM_TAB_DIALOG:
634  {
636  Reference<XTabControllerModel>(GetImpl()->getCurrentForm_Lock(), UNO_QUERY));
637  rReq.Done();
638  }
639  break;
640 
641  case SID_FM_DESIGN_MODE:
642  {
643  const SfxBoolItem* pDesignItem = rReq.GetArg<SfxBoolItem>(nSlot);
644  bool bDesignMode = pDesignItem ? pDesignItem->GetValue() : !m_bDesignMode;
645  SetDesignMode( bDesignMode );
646  if ( m_bDesignMode == bDesignMode )
647  rReq.Done();
648 
649  m_nLastSlot = SID_FM_DESIGN_MODE;
650  }
651  break;
652 
653  case SID_FM_AUTOCONTROLFOCUS:
654  {
655  FmFormModel* pModel = GetFormModel();
656  DBG_ASSERT(pModel, "FmFormShell::Execute : invalid call !");
657  // should have been disabled in GetState if we don't have a FormModel
658  pModel->SetAutoControlFocus( !pModel->GetAutoControlFocus() );
659  GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_AUTOCONTROLFOCUS);
660  }
661  break;
662  case SID_FM_OPEN_READONLY:
663  {
664  FmFormModel* pModel = GetFormModel();
665  DBG_ASSERT(pModel, "FmFormShell::Execute : invalid call !");
666  // should have been disabled in GetState if we don't have a FormModel
667  pModel->SetOpenInDesignMode( !pModel->GetOpenInDesignMode() );
668  GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_OPEN_READONLY);
669  }
670  break;
671  case SID_FM_USE_WIZARDS:
672  {
673  GetImpl()->SetWizardUsing_Lock(!GetImpl()->GetWizardUsing_Lock());
674  GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_USE_WIZARDS);
675  }
676  break;
677  case SID_FM_SEARCH:
678  {
680  if ( rController->commitCurrentControl() && rController->commitCurrentRecord() )
682  rReq.Done();
683  }
684  break;
685 
686  case SID_FM_RECORD_FIRST:
687  case SID_FM_RECORD_PREV:
688  case SID_FM_RECORD_NEXT:
689  case SID_FM_RECORD_LAST:
690  case SID_FM_RECORD_NEW:
691  case SID_FM_REFRESH:
692  case SID_FM_REFRESH_FORM_CONTROL:
693  case SID_FM_RECORD_DELETE:
694  case SID_FM_RECORD_UNDO:
695  case SID_FM_RECORD_SAVE:
696  case SID_FM_REMOVE_FILTER_SORT:
697  case SID_FM_SORTDOWN:
698  case SID_FM_SORTUP:
699  case SID_FM_AUTOFILTER:
700  case SID_FM_ORDERCRIT:
701  case SID_FM_FORM_FILTERED:
702  {
703  GetImpl()->ExecuteFormSlot_Lock(nSlot);
704  rReq.Done();
705  }
706  break;
707 
708  case SID_FM_RECORD_ABSOLUTE:
709  {
711  sal_Int32 nRecord = -1;
712 
713  const SfxItemSet* pArgs = rReq.GetArgs();
714  if ( pArgs )
715  {
716  const SfxPoolItem* pItem;
717  if ( ( pArgs->GetItemState( FN_PARAM_1, true, &pItem ) ) == SfxItemState::SET )
718  {
719  const SfxInt32Item* pTypedItem = dynamic_cast<const SfxInt32Item* >( pItem );
720  if ( pTypedItem )
721  nRecord = std::max( pTypedItem->GetValue(), sal_Int32(0) );
722  }
723  }
724  else
725  {
728  dlg->SetValue( rController->getCursor()->getRow() );
729  if ( dlg->Execute() == RET_OK )
730  nRecord = dlg->GetValue();
731 
732  rReq.AppendItem( SfxInt32Item( FN_PARAM_1, nRecord ) );
733  }
734 
735  if ( nRecord != -1 )
736  rController->execute( nSlot, "Position", makeAny( nRecord ) );
737 
738  rReq.Done();
739  } break;
740  case SID_FM_FILTER_EXECUTE:
741  case SID_FM_FILTER_EXIT:
742  {
743  bool bCancelled = ( SID_FM_FILTER_EXIT == nSlot );
744  bool bReopenNavigator = false;
745 
746  if ( !bCancelled )
747  {
748  // if the filter navigator is still open, we need to close it, so it can possibly
749  // commit it's most recent changes
750  if ( GetViewShell() && GetViewShell()->GetViewFrame() )
751  if ( GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_FILTER_NAVIGATOR ) )
752  {
753  GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
754  bReopenNavigator = true;
755  }
756 
757  Reference<runtime::XFormController> const xController(GetImpl()->getActiveController_Lock());
758 
759  if ( GetViewShell()->GetViewFrame()->HasChildWindow( SID_FM_FILTER_NAVIGATOR )
760  // closing the window was denied, for instance because of an invalid criterion
761 
762  || ( xController.is()
764  )
765  // committing the controller was denied
766  )
767  {
768  rReq.Done();
769  break;
770  }
771  }
772 
773  GetImpl()->stopFiltering_Lock(!bCancelled);
774  rReq.Done();
775 
776  if ( bReopenNavigator )
777  // we closed the navigator only to implicitly commit it (as we do not have another
778  // direct wire to it), but to the user, it should look as it was always open
779  GetViewShell()->GetViewFrame()->ToggleChildWindow( SID_FM_FILTER_NAVIGATOR );
780  }
781  break;
782 
783  case SID_FM_FILTER_START:
784  {
786  rReq.Done();
787 
788  // initially open the filter navigator, the whole form based filter is pretty useless without it
789  SfxBoolItem aIdentifierItem( SID_FM_FILTER_NAVIGATOR, true );
791  SID_FM_FILTER_NAVIGATOR, SfxCallMode::ASYNCHRON,
792  { &aIdentifierItem });
793  } break;
794  }
795 }
796 
797 
799 {
800  SfxWhichIter aIter( rSet );
801  sal_uInt16 nWhich = aIter.FirstWhich();
802  while ( nWhich )
803  {
804  switch( nWhich )
805  {
806  case SID_FM_FORM_DESIGN_TOOLS:
807  {
808  FormToolboxes aToolboxAccess(GetImpl()->getHostFrame_Lock());
809  rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible( nWhich ) ) );
810  }
811  break;
812 
813  case SID_FM_FILTER_EXECUTE:
814  case SID_FM_FILTER_EXIT:
815  if (!GetImpl()->isInFilterMode_Lock())
816  rSet.DisableItem( nWhich );
817  break;
818 
819  case SID_FM_USE_WIZARDS:
820  if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::EModule::DATABASE ) )
821  rSet.Put( SfxVisibilityItem( nWhich, false ) );
822  else if (!GetFormModel())
823  rSet.DisableItem( nWhich );
824  else
825  rSet.Put(SfxBoolItem(nWhich, GetImpl()->GetWizardUsing_Lock()));
826  break;
827  case SID_FM_AUTOCONTROLFOCUS:
828  if (!GetFormModel())
829  rSet.DisableItem( nWhich );
830  else
831  rSet.Put( SfxBoolItem(nWhich, GetFormModel()->GetAutoControlFocus() ) );
832  break;
833  case SID_FM_OPEN_READONLY:
834  if (!GetFormModel())
835  rSet.DisableItem( nWhich );
836  else
837  rSet.Put( SfxBoolItem(nWhich, GetFormModel()->GetOpenInDesignMode() ) );
838  break;
839 
840  case SID_FM_NAVIGATIONBAR:
841  case SID_FM_DBGRID:
842  if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::EModule::DATABASE ) )
843  {
844  rSet.Put( SfxVisibilityItem( nWhich, false ) );
845  break;
846  }
847  [[fallthrough]];
848 
849  case SID_FM_SCROLLBAR:
850  case SID_FM_IMAGECONTROL:
851  case SID_FM_FILECONTROL:
852  case SID_FM_CURRENCYFIELD:
853  case SID_FM_PATTERNFIELD:
854  case SID_FM_IMAGEBUTTON:
855  case SID_FM_RADIOBUTTON:
856  case SID_FM_COMBOBOX:
857  case SID_FM_GROUPBOX:
858  case SID_FM_CHECKBOX:
859  case SID_FM_PUSHBUTTON:
860  case SID_FM_FIXEDTEXT:
861  case SID_FM_LISTBOX:
862  case SID_FM_EDIT:
863  case SID_FM_DATEFIELD:
864  case SID_FM_TIMEFIELD:
865  case SID_FM_NUMERICFIELD:
866  case SID_FM_FORMATTEDFIELD:
867  case SID_FM_SPINBUTTON:
868  if (!m_bDesignMode)
869  rSet.DisableItem( nWhich );
870  else
871  {
872  bool bLayerLocked = false;
873  if (m_pFormView)
874  {
875  // If the css::drawing::Layer is locked, the slots must be disabled. #36897
877  if (pPV != nullptr)
878  bLayerLocked = pPV->IsLayerLocked(m_pFormView->GetActiveLayer());
879  }
880  if (bLayerLocked)
881  rSet.DisableItem( nWhich );
882  else
883  rSet.Put( SfxBoolItem(nWhich, (nWhich==m_nLastSlot)) );
884  }
885  break;
886  case SID_FM_FILTER_NAVIGATOR_CONTROL:
887  {
888  if (GetImpl()->isInFilterMode_Lock())
889  rSet.Put(SfxObjectItem(nWhich, this));
890  else
891  rSet.Put(SfxObjectItem(nWhich));
892  } break;
893  case SID_FM_FIELDS_CONTROL:
894  case SID_FM_PROPERTY_CONTROL:
895  {
897  rSet.Put(SfxObjectItem(nWhich));
898  else
899  rSet.Put(SfxObjectItem(nWhich, this));
900 
901  } break;
902  case SID_FM_FMEXPLORER_CONTROL:
903  case SID_FM_DATANAVIGATOR_CONTROL :
904  {
905  if (!m_bDesignMode || !m_pFormView)
906  rSet.Put(SfxObjectItem(nWhich));
907  else
908  rSet.Put(SfxObjectItem(nWhich, this));
909 
910  } break;
911  case SID_FM_ADD_FIELD:
912  case SID_FM_SHOW_FMEXPLORER:
913  case SID_FM_SHOW_PROPERTIES:
914  case SID_FM_FILTER_NAVIGATOR:
915  case SID_FM_SHOW_DATANAVIGATOR:
916  {
917  if ( GetViewShell()->GetViewFrame()->KnowsChildWindow(nWhich) )
918  rSet.Put( SfxBoolItem( nWhich, GetViewShell()->GetViewFrame()->HasChildWindow(nWhich)) );
919  else
920  rSet.DisableItem(nWhich);
921  } break;
922 
923  case SID_FM_SHOW_PROPERTY_BROWSER:
924  {
925  rSet.Put(SfxBoolItem(nWhich, GetImpl()->IsPropBrwOpen_Lock()));
926  }
927  break;
928 
929  case SID_FM_CTL_PROPERTIES:
930  {
931  // potentially, give the Impl the opportunity to update its
932  // current objects which are aligned with the current MarkList
933  if (GetImpl()->IsSelectionUpdatePending_Lock())
935 
936  if (!m_pFormView || !m_bDesignMode || !GetImpl()->onlyControlsAreMarked_Lock())
937  rSet.DisableItem( nWhich );
938  else
939  {
940  bool const bChecked = GetImpl()->IsPropBrwOpen_Lock() && !GetImpl()->isSolelySelected_Lock(GetImpl()->getCurrentForm_Lock());
941  // if the property browser is open, and only controls are marked, and the current selection
942  // does not consist of only the current form, then the current selection is the (composition of)
943  // the currently marked controls
944  rSet.Put( SfxBoolItem( nWhich, bChecked ) );
945  }
946  } break;
947 
948  case SID_FM_PROPERTIES:
949  {
950  // potentially, give the Impl the opportunity to update its
951  // current objects which are aligned with the current MarkList
952  if (GetImpl()->IsSelectionUpdatePending_Lock())
954 
955  if (!m_pFormView || !m_bDesignMode || !GetImpl()->getCurrentForm_Lock().is())
956  rSet.DisableItem( nWhich );
957  else
958  {
959  bool const bChecked = GetImpl()->IsPropBrwOpen_Lock() && GetImpl()->isSolelySelected_Lock(GetImpl()->getCurrentForm_Lock());
960  rSet.Put(SfxBoolItem(nWhich, bChecked));
961  }
962  } break;
963  case SID_FM_TAB_DIALOG:
964  // potentially, give the Impl the opportunity to update its
965  // current objects which are aligned with the current MarkList
966  if (GetImpl()->IsSelectionUpdatePending_Lock())
968 
969  if (!m_pFormView || !m_bDesignMode || !GetImpl()->getCurrentForm_Lock().is() )
970  rSet.DisableItem( nWhich );
971  break;
972  case SID_FM_DESIGN_MODE:
973  if (!m_pFormView || GetImpl()->IsReadonlyDoc_Lock())
974  rSet.DisableItem( nWhich );
975  else
976  rSet.Put( SfxBoolItem(nWhich, m_bDesignMode) );
977  break;
978  case SID_FM_SEARCH:
979  case SID_FM_RECORD_FIRST:
980  case SID_FM_RECORD_NEXT:
981  case SID_FM_RECORD_PREV:
982  case SID_FM_RECORD_LAST:
983  case SID_FM_RECORD_NEW:
984  case SID_FM_RECORD_DELETE:
985  case SID_FM_RECORD_ABSOLUTE:
986  case SID_FM_RECORD_TOTAL:
987  case SID_FM_RECORD_SAVE:
988  case SID_FM_RECORD_UNDO:
989  case SID_FM_FORM_FILTERED:
990  case SID_FM_REMOVE_FILTER_SORT:
991  case SID_FM_SORTUP:
992  case SID_FM_SORTDOWN:
993  case SID_FM_ORDERCRIT:
994  case SID_FM_FILTER_START:
995  case SID_FM_AUTOFILTER:
996  case SID_FM_REFRESH:
997  case SID_FM_REFRESH_FORM_CONTROL:
998  case SID_FM_VIEW_AS_GRID:
999  GetFormState(rSet,nWhich);
1000  break;
1001 
1002  case SID_FM_CHANGECONTROLTYPE:
1003  {
1004  if ( !m_pFormView || !m_bDesignMode )
1005  rSet.DisableItem( nWhich );
1006  else
1007  {
1008  if (!GetImpl()->canConvertCurrentSelectionToControl_Lock("ConvertToFixed"))
1009  // if it cannot be converted to a fixed text, it is no single control
1010  rSet.DisableItem( nWhich );
1011  }
1012  } break;
1013 
1014  case SID_FM_CONVERTTO_FILECONTROL :
1015  case SID_FM_CONVERTTO_CURRENCY :
1016  case SID_FM_CONVERTTO_PATTERN :
1017  case SID_FM_CONVERTTO_IMAGECONTROL :
1018  case SID_FM_CONVERTTO_SCROLLBAR :
1019  case SID_FM_CONVERTTO_NAVIGATIONBAR :
1020  case SID_FM_CONVERTTO_IMAGEBUTTON :
1021  case SID_FM_CONVERTTO_EDIT :
1022  case SID_FM_CONVERTTO_BUTTON :
1023  case SID_FM_CONVERTTO_FIXEDTEXT :
1024  case SID_FM_CONVERTTO_LISTBOX :
1025  case SID_FM_CONVERTTO_CHECKBOX :
1026  case SID_FM_CONVERTTO_RADIOBUTTON :
1027  case SID_FM_CONVERTTO_GROUPBOX :
1028  case SID_FM_CONVERTTO_COMBOBOX :
1029  case SID_FM_CONVERTTO_DATE :
1030  case SID_FM_CONVERTTO_TIME :
1031  case SID_FM_CONVERTTO_NUMERIC :
1032  case SID_FM_CONVERTTO_FORMATTED :
1033  case SID_FM_CONVERTTO_SPINBUTTON :
1034  {
1035  if (!m_pFormView || !m_bDesignMode || !GetImpl()->canConvertCurrentSelectionToControl_Lock(FmXFormShell::SlotToIdent(nWhich)))
1036  rSet.DisableItem( nWhich );
1037  else
1038  {
1039  rSet.Put( SfxBoolItem( nWhich, false ) );
1040  // just to have a defined state (available and not checked)
1041  }
1042  }
1043  break;
1044  }
1045  nWhich = aIter.NextWhich();
1046  }
1047 }
1048 
1049 
1050 void FmFormShell::GetFormState(SfxItemSet &rSet, sal_uInt16 nWhich)
1051 {
1052  if ( !GetImpl()->getNavController_Lock().is()
1053  || !isRowSetAlive(GetImpl()->getNavController_Lock()->getModel())
1054  || !m_pFormView
1055  || m_bDesignMode
1056  || !GetImpl()->getActiveForm_Lock().is()
1057  || GetImpl()->isInFilterMode_Lock()
1058  )
1059  rSet.DisableItem(nWhich);
1060  else
1061  {
1062  bool bEnable = false;
1063  try
1064  {
1065  switch (nWhich)
1066  {
1067  case SID_FM_VIEW_AS_GRID:
1068  if (GetImpl()->getHostFrame_Lock().is() && GetImpl()->getNavController_Lock().is())
1069  {
1070  bEnable = true;
1071  bool bDisplayingCurrent =
1073  Reference<XForm>(GetImpl()->getNavController_Lock()->getModel(), UNO_QUERY)
1075  rSet.Put(SfxBoolItem(nWhich, bDisplayingCurrent));
1076  }
1077  break;
1078 
1079  case SID_FM_SEARCH:
1080  {
1081  Reference<css::beans::XPropertySet> const xNavSet(GetImpl()->getActiveForm_Lock(), UNO_QUERY);
1082  sal_Int32 nCount = ::comphelper::getINT32(xNavSet->getPropertyValue(FM_PROP_ROWCOUNT));
1083  bEnable = nCount != 0;
1084  } break;
1085  case SID_FM_RECORD_ABSOLUTE:
1086  case SID_FM_RECORD_TOTAL:
1087  {
1088  FeatureState aState;
1089  GetImpl()->getNavControllerFeatures_Lock()->getState( nWhich, aState );
1090  if ( SID_FM_RECORD_ABSOLUTE == nWhich )
1091  {
1092  sal_Int32 nPosition = 0;
1093  aState.State >>= nPosition;
1094  rSet.Put( SfxInt32Item( nWhich, nPosition ) );
1095  }
1096  else if ( SID_FM_RECORD_TOTAL == nWhich )
1097  {
1098  OUString sTotalCount;
1099  aState.State >>= sTotalCount;
1100  rSet.Put( SfxStringItem( nWhich, sTotalCount ) );
1101  }
1102  bEnable = aState.Enabled;
1103  }
1104  break;
1105 
1106  // first, prev, next, last, and absolute affect the nav controller, not the
1107  // active controller
1108  case SID_FM_RECORD_FIRST:
1109  case SID_FM_RECORD_PREV:
1110  case SID_FM_RECORD_NEXT:
1111  case SID_FM_RECORD_LAST:
1112  case SID_FM_RECORD_NEW:
1113  case SID_FM_RECORD_SAVE:
1114  case SID_FM_RECORD_UNDO:
1115  case SID_FM_RECORD_DELETE:
1116  case SID_FM_REFRESH:
1117  case SID_FM_REFRESH_FORM_CONTROL:
1118  case SID_FM_REMOVE_FILTER_SORT:
1119  case SID_FM_SORTUP:
1120  case SID_FM_SORTDOWN:
1121  case SID_FM_AUTOFILTER:
1122  case SID_FM_ORDERCRIT:
1123  bEnable = GetImpl()->IsFormSlotEnabled( nWhich, nullptr );
1124  break;
1125 
1126  case SID_FM_FORM_FILTERED:
1127  {
1128  FeatureState aState;
1129  bEnable = GetImpl()->IsFormSlotEnabled( nWhich, &aState );
1130 
1131  rSet.Put( SfxBoolItem( nWhich, ::comphelper::getBOOL( aState.State ) ) );
1132  }
1133  break;
1134 
1135  case SID_FM_FILTER_START:
1137  break;
1138  }
1139  }
1140  catch( const Exception& )
1141  {
1142  OSL_FAIL( "FmFormShell::GetFormState: caught an exception while determining the state!" );
1143  }
1144  if (!bEnable)
1145  rSet.DisableItem(nWhich);
1146  }
1147 }
1148 
1149 
1151 {
1152  FmFormPage* pP = nullptr;
1154  pP = dynamic_cast<FmFormPage*>( m_pFormView->GetSdrPageView()->GetPage() );
1155  return pP;
1156 }
1157 
1158 
1160 {
1161  if ( m_pFormView )
1162  {
1163  if ( IsActive() )
1165 
1167  m_pFormView = nullptr;
1168  m_pFormModel = nullptr;
1169  }
1170 
1171  if ( !_pView )
1172  return;
1173 
1174  m_pFormView = _pView;
1176  m_pFormModel = static_cast<FmFormModel*>(m_pFormView->GetModel());
1177 
1179 
1180  // We activate our view if we are activated ourself, but sometimes the Activate precedes the SetView.
1181  // But here we know both the view and our activation state so we at least are able to pass the latter
1182  // to the former.
1183  // FS - 30.06.99 - 67308
1184  if ( IsActive() )
1186 }
1187 
1188 
1189 void FmFormShell::DetermineForms(bool bInvalidate)
1190 {
1191  // are there forms on the current page
1192  bool bForms = GetImpl()->hasForms_Lock();
1193  if (bForms != m_bHasForms)
1194  {
1195  m_bHasForms = bForms;
1196  if (bInvalidate)
1197  UIFeatureChanged();
1198  }
1199 }
1200 
1201 
1202 bool FmFormShell::GetY2KState(sal_uInt16& nReturn)
1203 {
1204  return GetImpl()->GetY2KState_Lock(nReturn);
1205 }
1206 
1207 
1208 void FmFormShell::SetY2KState(sal_uInt16 n)
1209 {
1210  GetImpl()->SetY2KState_Lock(n);
1211 }
1212 
1213 
1214 void FmFormShell::Activate(bool bMDI)
1215 {
1216  SfxShell::Activate(bMDI);
1217 
1218  if ( m_pFormView )
1220 }
1221 
1222 
1224 {
1225  SfxShell::Deactivate(bMDI);
1226 
1227  if ( m_pFormView )
1229 }
1230 
1231 
1233 {
1234  m_pImpl->ExecuteTextAttribute_Lock(_rReq);
1235 }
1236 
1237 
1239 {
1240  m_pImpl->GetTextAttributeState_Lock(_rSet);
1241 }
1242 
1243 
1245 {
1246  return m_pImpl->IsActiveControl_Lock(false);
1247 }
1248 
1249 
1251 {
1252  m_pImpl->ForgetActiveControl_Lock();
1253 }
1254 
1255 
1257 {
1258  m_pImpl->SetControlActivationHandler_Lock(_rHdl);
1259 }
1260 
1261 
1262 namespace
1263 {
1264  SdrUnoObj* lcl_findUnoObject( const SdrObjList& _rObjList, const Reference< XControlModel >& _rxModel )
1265  {
1266  SdrObjListIter aIter( &_rObjList );
1267  while ( aIter.IsMore() )
1268  {
1269  SdrObject* pObject = aIter.Next();
1270  SdrUnoObj* pUnoObject = dynamic_cast<SdrUnoObj*>( pObject );
1271  if ( !pUnoObject )
1272  continue;
1273 
1274  Reference< XControlModel > xControlModel = pUnoObject->GetUnoControlModel();
1275  if ( !xControlModel.is() )
1276  continue;
1277 
1278  if ( _rxModel == xControlModel )
1279  return pUnoObject;
1280  }
1281  return nullptr;
1282  }
1283 }
1284 
1285 
1286 void FmFormShell::ToggleControlFocus( const SdrUnoObj& i_rUnoObject, const SdrView& i_rView, OutputDevice& i_rDevice ) const
1287 {
1288  try
1289  {
1290  // check if the focus currently is in a control
1291  // Well, okay, do it the other way 'round: Check whether the current control of the active controller
1292  // actually has the focus. This should be equivalent.
1293  const bool bHasControlFocus = GetImpl()->HasControlFocus_Lock();
1294 
1295  if ( bHasControlFocus )
1296  {
1297  vcl::Window* pWindow( dynamic_cast< vcl::Window* >( &i_rDevice ) );
1298  OSL_ENSURE( pWindow, "FmFormShell::ToggleControlFocus: I need a Window, really!" );
1299  if ( pWindow )
1300  pWindow->GrabFocus();
1301  }
1302  else
1303  {
1304  Reference< XControl > xControl;
1305  GetFormControl( i_rUnoObject.GetUnoControlModel(), i_rView, i_rDevice, xControl );
1306  Reference< XWindow > xControlWindow( xControl, UNO_QUERY );
1307  if ( xControlWindow.is() )
1308  xControlWindow->setFocus();
1309  }
1310  }
1311  catch( const Exception& )
1312  {
1313  DBG_UNHANDLED_EXCEPTION("svx");
1314  }
1315 }
1316 
1317 
1318 namespace
1319 {
1320  class FocusableControlsFilter : public svx::ISdrObjectFilter
1321  {
1322  public:
1323  FocusableControlsFilter( const SdrView& i_rView, const OutputDevice& i_rDevice )
1324  :m_rView( i_rView )
1325  ,m_rDevice( i_rDevice )
1326  {
1327  }
1328 
1329  public:
1330  virtual bool includeObject( const SdrObject& i_rObject ) const override
1331  {
1332  const SdrUnoObj* pUnoObj = dynamic_cast< const SdrUnoObj* >( &i_rObject );
1333  if ( !pUnoObj )
1334  return false;
1335 
1336  Reference< XControl > xControl = pUnoObj->GetUnoControl( m_rView, m_rDevice );
1337  return FmXFormView::isFocusable( xControl );
1338  }
1339 
1340  private:
1341  const SdrView& m_rView;
1342  const OutputDevice& m_rDevice;
1343  };
1344 }
1345 
1346 
1347 ::std::unique_ptr< svx::ISdrObjectFilter > FmFormShell::CreateFocusableControlFilter( const SdrView& i_rView, const OutputDevice& i_rDevice )
1348 {
1349  ::std::unique_ptr< svx::ISdrObjectFilter > pFilter;
1350 
1351  if ( !i_rView.IsDesignMode() )
1352  pFilter.reset( new FocusableControlsFilter( i_rView, i_rDevice ) );
1353 
1354  return pFilter;
1355 }
1356 
1357 
1358 SdrUnoObj* FmFormShell::GetFormControl( const Reference< XControlModel >& _rxModel, const SdrView& _rView, const OutputDevice& _rDevice, Reference< XControl >& _out_rxControl ) const
1359 {
1360  if ( !_rxModel.is() )
1361  return nullptr;
1362 
1363  // we can only retrieve controls for SdrObjects which belong to page which is actually displayed in the given view
1364  SdrPageView* pPageView = _rView.GetSdrPageView();
1365  SdrPage* pPage = pPageView ? pPageView->GetPage() : nullptr;
1366  OSL_ENSURE( pPage, "FmFormShell::GetFormControl: no page displayed in the given view!" );
1367  if ( !pPage )
1368  return nullptr;
1369 
1370  SdrUnoObj* pUnoObject = lcl_findUnoObject( *pPage, _rxModel );
1371  if ( pUnoObject )
1372  {
1373  _out_rxControl = pUnoObject->GetUnoControl( _rView, _rDevice );
1374  return pUnoObject;
1375  }
1376 
1377 #if OSL_DEBUG_LEVEL > 0
1378  // perhaps we are fed with a control model which lives on a page other than the one displayed
1379  // in the given view. This is worth being reported as error, in non-product builds.
1380  FmFormModel* pModel = GetFormModel();
1381  if ( pModel )
1382  {
1383  sal_uInt16 pageCount = pModel->GetPageCount();
1384  for ( sal_uInt16 page = 0; page < pageCount; ++page )
1385  {
1386  pPage = pModel->GetPage( page );
1387  OSL_ENSURE( pPage, "FmFormShell::GetFormControl: NULL page encountered!" );
1388  if ( !pPage )
1389  continue;
1390 
1391  pUnoObject = lcl_findUnoObject( *pPage, _rxModel );
1392  OSL_ENSURE( !pUnoObject, "FmFormShell::GetFormControl: the given control model belongs to a wrong page (displayed elsewhere)!" );
1393  }
1394  }
1395 #else
1396  (void) this; // avoid loplugin:staticmethods
1397 #endif
1398 
1399  return nullptr;
1400 }
1401 
1402 
1403 Reference< runtime::XFormController > FmFormShell::GetFormController( const Reference< XForm >& _rxForm, const SdrView& _rView, const OutputDevice& _rDevice )
1404 {
1405  const FmFormView* pFormView = dynamic_cast< const FmFormView* >( &_rView );
1406  if ( !pFormView )
1407  return nullptr;
1408 
1409  return pFormView->GetFormController( _rxForm, _rDevice );
1410 }
1411 
1412 
1413 void FmFormShell::SetDesignMode( bool _bDesignMode )
1414 {
1415  if ( _bDesignMode == m_bDesignMode )
1416  return;
1417 
1418  FmFormModel* pModel = GetFormModel();
1419  if (pModel)
1420  // Switch off the undo environment for the time of the transition. This ensures that
1421  // one can also change non-transient properties there. (It should be done with
1422  // caution, however, and it should always be reversed when one switches the mode back.
1423  // An example is the setting of the maximum text length by the OEditModel on its control.)
1424  pModel->GetUndoEnv().Lock();
1425 
1426  // then the actual switch
1427  if ( m_bDesignMode || PrepareClose() )
1429 
1430  // and my undo environment back on
1431  if ( pModel )
1432  pModel->GetUndoEnv().UnLock();
1433 }
1434 
1435 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SdrUnoObj * GetFormControl(const css::uno::Reference< css::awt::XControlModel > &_rxModel, const SdrView &_rView, const OutputDevice &_rDevice, css::uno::Reference< css::awt::XControl > &_out_rxControl) const
Definition: fmshell.cxx:1358
SfxViewFrame * GetViewFrame() const
specifies a boolean predicate on the set of all SdrObjects - vulgo a filter.
FmFormView * m_pFormView
Definition: fmshell.hxx:79
bool GetValue() const
::std::set< css::uno::Reference< css::uno::XInterface > > InterfaceBag
Definition: fmtools.hxx:170
void UIFeatureChanged()
OutDevType GetOutDevType() const
SAL_DLLPRIVATE bool selectLastMarkedControls_Lock()
sets the new selection to the last known marked controls
Definition: fmshimp.cxx:1930
virtual void Activate(bool bMDI) override
Definition: fmshell.cxx:1214
virtual ~FmFormShell() override
Definition: fmshell.cxx:198
sal_Int32 GetValue() const
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
SAL_DLLPRIVATE void viewActivated_Lock(FmFormView &_rCurrentView, bool _bSyncAction=false)
Definition: fmshimp.cxx:3596
SAL_DLLPRIVATE bool IsReadonlyDoc_Lock() const
determines whether our host document is currently read-only
Definition: fmshimp.cxx:715
void ToggleControlFocus(const SdrUnoObj &i_rNextCandidate, const SdrView &i_rView, OutputDevice &i_rDevice) const
puts the focus into the document window, if current a form control has the focus. ...
Definition: fmshell.cxx:1286
SAL_DLLPRIVATE void viewDeactivated_Lock(FmFormView &_rCurrentView, bool _bDeactivateController=true)
Definition: fmshimp.cxx:3533
SAL_DLLPRIVATE const svx::ControllerFeatures & getNavControllerFeatures_Lock() const
Definition: fmshimp.hxx:356
#define SFX_IMPL_INTERFACE(Class, SuperClass)
void SetAutoControlFocus(bool _bAutoControlFocus)
Definition: fmmodel.cxx:168
easier access to a FormControllerHelper instance
SAL_DLLPRIVATE void ExecuteSearch_Lock()
Definition: fmshimp.cxx:1418
FmFormView * GetFormView() const
Definition: fmshell.hxx:115
void DetermineForms(bool bInvalidate)
Definition: fmshell.cxx:1189
SAL_DLLPRIVATE bool executeControlConversionSlot_Lock(const css::uno::Reference< css::form::XFormComponent > &_rxObject, const OString &rIdent)
executes a control conversion slot for a given object
FmXFormShell * GetImpl() const
Definition: fmshell.hxx:118
SVX_DLLPRIVATE const OutputDevice * GetActualOutDev() const
Definition: fmview.hxx:145
void GetState(SfxItemSet &)
Definition: fmshell.cxx:798
SfxDispatcher * GetDispatcher()
void execute(sal_Int32 _nSlotId) const
static SvxAbstractDialogFactory * Create()
Definition: svxdlg.cxx:23
bool IsDesignMode() const
Definition: svdmrkv.hxx:227
bool getBOOL(const Any &_rAny)
sal_uInt16 const ControllerSlotMap[]
Definition: fmshell.cxx:89
SAL_DLLPRIVATE void SetSelection_Lock(const SdrMarkList &rMarkList)
Definition: fmshimp.cxx:2676
void NotifyMarkListChanged(FmFormView *)
Definition: fmshell.cxx:207
#define KEY_MOD1
const sal_uInt16 OBJ_FM_NAVIGATIONBAR
Definition: fmglob.hxx:48
SVX_DLLPRIVATE void GrabFirstControlFocus()
grab the focus to the first form control on the view
Definition: fmview.cxx:304
FmFormPage * GetCurPage() const
Definition: fmshell.cxx:1150
sal_uInt16 FirstWhich()
SAL_DLLPRIVATE void ExecuteFormSlot_Lock(sal_Int32 _nSlot)
execute the given form slot
Definition: fmshimp.cxx:1761
bool m_bDesignMode
Definition: fmshell.hxx:83
SAL_DLLPRIVATE const css::uno::Reference< css::sdbc::XResultSet > & getExternallyDisplayedForm_Lock() const
Definition: fmshimp.hxx:255
void Done(bool bRemove=false)
const sal_uInt16 OBJ_FM_NUMERICFIELD
Definition: fmglob.hxx:40
bool GetAutoControlFocus() const
Definition: fmmodel.hxx:64
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
virtual short Execute()=0
EmbeddedObjectRef * pObject
void SetOpenInDesignMode(bool _bOpenDesignMode)
Definition: fmmodel.cxx:143
RET_CANCEL
SAL_DLLPRIVATE const css::uno::Reference< css::form::runtime::XFormController > & getActiveController_Lock() const
Definition: fmshimp.hxx:349
bool isRowSetAlive(const Reference< XInterface > &_rxRowSet)
Definition: fmtools.cxx:404
sal_uInt16 NextWhich()
FmFormModel * GetFormModel() const
Definition: fmshell.hxx:116
SfxApplication * SfxGetpApp()
void ToggleChildWindow(sal_uInt16)
RET_NO
void impl_setDesignMode(bool bDesign)
Definition: fmshell.cxx:270
SdrPageWindow * FindPageWindow(SdrPaintWindow &rPaintWindow) const
Definition: svdpagv.cxx:53
virtual long GetValue() const =0
weld::Window * GetFrameWeld() const
virtual VclPtr< AbstractFmInputRecordNoDialog > CreateFmInputRecordNoDialog(weld::Window *pParent)=0
Reference< XController > xController
RET_YES
SAL_DLLPRIVATE bool GetY2KState_Lock(sal_uInt16 &n)
Definition: fmshimp.cxx:1573
virtual bool HasUIFeature(SfxShellFeature nFeature) const override
Definition: fmshell.cxx:291
OUTDEV_WINDOW
SAL_DLLPRIVATE const svx::ControllerFeatures & getActiveControllerFeatures_Lock() const
Definition: fmshimp.hxx:354
const sal_uInt16 OBJ_FM_IMAGEBUTTON
Definition: fmglob.hxx:36
static bool isFocusable(const css::uno::Reference< css::awt::XControl > &i_rControl)
Definition: fmvwimp.cxx:790
int nCount
SAL_DLLPRIVATE bool didPrepareClose_Lock() const
Definition: fmshimp.hxx:258
SAL_DLLPRIVATE void SetDesignMode_Lock(bool bDesign)
Definition: fmshimp.cxx:2729
virtual void Deactivate(bool bMDI)
FmXUndoEnvironment & GetUndoEnv()
Definition: fmmodel.cxx:203
SAL_DLLPRIVATE bool IsFormSlotEnabled(sal_Int32 _nSlot, css::form::runtime::FeatureState *_pCompleteState)
determines whether the current form slot is currently enabled
Definition: fmshimp.cxx:1746
const sal_uInt16 OBJ_FM_PATTERNFIELD
Definition: fmglob.hxx:42
const sal_uInt16 OBJ_FM_EDIT
Definition: fmglob.hxx:27
SAL_DLLPRIVATE bool isSolelySelected_Lock(const css::uno::Reference< css::uno::XInterface > &_rxObject)
determines whether the current selection consists of exactly the given object
Definition: fmshimp.cxx:2014
void SetView(FmFormView *pView)
Definition: fmshell.cxx:1159
SfxItemPool & GetPool() const
#define DBG_UNHANDLED_EXCEPTION(...)
FmDesignModeChangedHint(bool bDesMode)
Definition: fmshell.cxx:140
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define DBG_ASSERT(sCon, aError)
SAL_DLLPRIVATE void ShowSelectionProperties_Lock(bool bShow)
Definition: fmshimp.cxx:2154
void ChildWindowExecute(SfxRequest &)
const sal_uInt16 OBJ_FM_GROUPBOX
Definition: fmglob.hxx:34
sal_uInt16 GetModifier() const
friend friend class SfxObjectItem
SfxShellFeature
bool IsLayerLocked(const OUString &rName) const
Definition: svdpagv.hxx:200
SfxBindings & GetBindings()
sal_uInt16 m_nLastSlot
Definition: fmshell.hxx:82
bool GetOpenInDesignMode() const
Definition: fmmodel.hxx:61
const T * GetArg(sal_uInt16 nSlotId) const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
Definition: svdmodel.cxx:1917
void SetPool(SfxItemPool *pNewPool)
const sal_uInt16 OBJ_FM_FILECONTROL
Definition: fmglob.hxx:37
const sal_uInt16 OBJ_FM_COMBOBOX
Definition: fmglob.hxx:32
bool IsActiveControl() const
Definition: fmshell.cxx:1244
rtl::Reference< FmXFormShell > m_pImpl
Definition: fmshell.hxx:78
#define FM_PROP_ROWCOUNT
Definition: fmprop.hxx:32
void SetName(const OUString &rName)
const sal_uInt16 OBJ_FM_CHECKBOX
Definition: fmglob.hxx:31
const sal_uInt16 OBJ_FM_SCROLLBAR
Definition: fmglob.hxx:46
const sal_uInt16 OBJ_FM_FIXEDTEXT
Definition: fmglob.hxx:29
Abstract DrawObject.
Definition: svdobj.hxx:312
void GrabFocus()
SAL_DLLPRIVATE bool setCurrentSelection_Lock(const InterfaceBag &rSelection)
announces a new "current selection"
Definition: fmshimp.cxx:1936
SAL_DLLPRIVATE void ForceUpdateSelection_Lock()
Definition: fmshimp.cxx:1006
SfxViewShell * GetViewShell() const
const sal_uInt16 OBJ_FM_SPINBUTTON
Definition: fmglob.hxx:47
#define SFX_OBJECTBAR_OBJECT
const sal_uInt16 OBJ_FM_GRID
Definition: fmglob.hxx:35
FmFormShell(SfxViewShell *pParent, FmFormView *pView=nullptr)
Definition: fmshell.cxx:182
css::uno::Reference< css::sdbc::XRowSet > getCursor() const
SAL_DLLPRIVATE void stopFiltering_Lock(bool bSave)
Definition: fmshimp.cxx:2988
weld::Window * GetFrameWeld() const
SAL_DLLPRIVATE bool isInFilterMode_Lock() const
Definition: fmshimp.hxx:412
SAL_DLLPRIVATE css::uno::Reference< css::form::XForm > getInternalForm_Lock(const css::uno::Reference< css::form::XForm > &_xForm) const
static css::uno::Reference< css::form::runtime::XFormController > GetFormController(const css::uno::Reference< css::form::XForm > &_rxForm, const SdrView &_rView, const OutputDevice &_rDevice)
Definition: fmshell.cxx:1403
SAL_DLLPRIVATE bool HasControlFocus_Lock() const
Definition: fmshimp.cxx:3908
void SetDesignMode(bool _bDesignMode)
Definition: fmshell.cxx:1413
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SAL_DLLPRIVATE bool IsPropBrwOpen_Lock() const
Definition: fmshimp.cxx:2693
sal_uInt16 GetSlot() const
SAL_DLLPRIVATE bool hasDatabaseBar_Lock() const
Definition: fmshimp.hxx:397
bool HasChildWindow(sal_uInt16)
const sal_uInt16 OBJ_FM_RADIOBUTTON
Definition: fmglob.hxx:33
void GetTextAttributeState(SfxItemSet &)
Definition: fmshell.cxx:1238
void DisableItem(sal_uInt16 nWhich)
const sal_uInt16 OBJ_FM_FORMATTEDFIELD
Definition: fmglob.hxx:45
FmFormModel * m_pFormModel
Definition: fmshell.hxx:80
SdrPage * GetPage() const
Definition: svdpagv.hxx:173
RET_OK
bool PrepareClose(bool bUI=true)
Definition: fmshell.cxx:214
bool GetY2KState(sal_uInt16 &nReturn)
Definition: fmshell.cxx:1202
virtual ~FmDesignModeChangedHint() override
Definition: fmshell.cxx:146
bool m_bHasForms
Definition: fmshell.hxx:84
const sal_uInt16 OBJ_FM_LISTBOX
Definition: fmglob.hxx:30
SAL_DLLPRIVATE void SetWizardUsing_Lock(bool _bUseThem)
Definition: fmshimp.cxx:3522
vcl::Window * GetWindow() const
static::std::unique_ptr< svx::ISdrObjectFilter > CreateFocusableControlFilter(const SdrView &i_rView, const OutputDevice &i_rDevice)
Definition: fmshell.cxx:1347
css::uno::Reference< css::awt::XControl > GetUnoControl(const SdrView &_rView, const OutputDevice &_rOut) const
Definition: svdouno.cxx:477
virtual void SetValue(long dNew)=0
void Execute(SfxRequest &)
Definition: fmshell.cxx:340
SdrPageView * GetSdrPageView() const
Definition: svdpntv.hxx:310
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
Definition: svdouno.hxx:91
const sal_uInt16 OBJ_FM_IMAGECONTROL
Definition: fmglob.hxx:44
bool IsActive() const
#define SFX_OBJECTBAR_NAVIGATION
void GetFormState(SfxItemSet &rSet, sal_uInt16 nWhich)
Definition: fmshell.cxx:1050
SAL_DLLPRIVATE void SetY2KState_Lock(sal_uInt16 n)
Definition: fmshimp.cxx:1612
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
void AppendItem(const SfxPoolItem &)
class FmSearchEngine - Impl class for FmSearchDialog
void SetControlActivationHandler(const Link< LinkParamNone *, void > &_rHdl)
Definition: fmshell.cxx:1256
virtual bool includeObject(const SdrObject &i_rObject) const =0
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:366
virtual void Activate(bool bMDI)
const OUString & GetActiveLayer() const
Definition: svdpntv.hxx:430
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
SAL_DLLPRIVATE void startFiltering_Lock()
Definition: fmshimp.cxx:2916
void ExecuteTextAttribute(SfxRequest &)
Definition: fmshell.cxx:1232
SAL_DLLPRIVATE void ExecuteTabOrderDialog_Lock(const css::uno::Reference< css::awt::XTabControllerModel > &_rxForForm)
Definition: fmshimp.cxx:1389
SdrModel * GetModel() const
Definition: svdpntv.hxx:271
SVX_DLLPRIVATE css::uno::Reference< css::form::runtime::XFormController > GetFormController(const css::uno::Reference< css::form::XForm > &_rxForm, const OutputDevice &_rDevice) const
returns the form controller for a given form and a given device
Definition: fmview.cxx:583
void SetY2KState(sal_uInt16 n)
Definition: fmshell.cxx:1208
const sal_uInt16 OBJ_FM_BUTTON
Definition: fmglob.hxx:28
static SAL_DLLPRIVATE OString SlotToIdent(sal_uInt16 nSlot)
Definition: fmshimp.cxx:1036
SAL_DLLPRIVATE void CreateExternalView_Lock()
Definition: fmshimp.cxx:3089
void ForgetActiveControl()
Definition: fmshell.cxx:1250
const sal_uInt16 OBJ_FM_TIMEFIELD
Definition: fmglob.hxx:39
SAL_DLLPRIVATE bool isEnhancedForm_Lock() const
Definition: fmshimp.cxx:677
const sal_uInt16 OBJ_FM_CURRENCYFIELD
Definition: fmglob.hxx:41
void SetFormShell(FmFormShell *pShell, FormShellAccess)
Definition: fmview.hxx:135
sal_uInt16 GetPageCount() const
Definition: svdmodel.cxx:1929
const sal_uInt16 OBJ_FM_DATEFIELD
Definition: fmglob.hxx:38
virtual void Deactivate(bool bMDI) override
Definition: fmshell.cxx:1223
SAL_DLLPRIVATE bool hasForms_Lock() const
Definition: fmshimp.hxx:396
void getState(sal_Int32 _nSlotId, css::form::runtime::FeatureState &_out_rState) const
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)