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