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