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 #include "precompiled_reportdesign.hxx"
28 
29 #define RPTUI_ID_LRSPACE	1
30 #define RPTUI_ID_ULSPACE	2
31 #define RPTUI_ID_PAGE		3
32 #define RPTUI_ID_SIZE		4
33 #define RPTUI_ID_PAGE_MODE	5
34 #define RPTUI_ID_START		6
35 #define RPTUI_ID_END		7
36 #define RPTUI_ID_BRUSH		8
37 #define RPTUI_ID_METRIC		9
38 
39 #define ITEMID_LRSPACE      RPTUI_ID_LRSPACE
40 #define ITEMID_ULSPACE      RPTUI_ID_ULSPACE
41 #define ITEMID_SIZE         RPTUI_ID_SIZE
42 #define ITEMID_PAGE			RPTUI_ID_PAGE
43 #define ITEMID_BRUSH		RPTUI_ID_BRUSH
44 
45 
46 #include "ReportController.hxx"
47 #include "ReportDefinition.hxx"
48 #include "CondFormat.hxx"
49 #include "UITools.hxx"
50 #include "AddField.hxx"
51 #include <toolkit/helper/vclunohelper.hxx>
52 #include "DateTime.hxx"
53 
54 #include <sfx2/filedlghelper.hxx>
55 #include <tools/string.hxx>
56 #include <tools/diagnose_ex.h>
57 #include "rptui_slotid.hrc"
58 #include "reportformula.hxx"
59 
60 #include <comphelper/documentconstants.hxx>
61 #include <comphelper/mediadescriptor.hxx>
62 #include <comphelper/property.hxx>
63 #include <comphelper/sequenceashashmap.hxx>
64 #include <comphelper/types.hxx>
65 
66 #include <connectivity/dbtools.hxx>
67 #include <com/sun/star/view/PaperFormat.hpp>
68 #include <com/sun/star/style/GraphicLocation.hpp>
69 #include <com/sun/star/style/XStyle.hpp>
70 #include <com/sun/star/style/PageStyleLayout.hpp>
71 #include <com/sun/star/style/ParagraphAdjust.hpp>
72 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
73 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
74 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
75 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
76 #include <com/sun/star/frame/FrameSearchFlag.hpp>
77 #include <com/sun/star/datatransfer/XTransferable.hpp>
78 #include <com/sun/star/container/XChild.hpp>
79 #include <com/sun/star/container/XNameContainer.hpp>
80 #include <com/sun/star/report/XImageControl.hpp>
81 #include <com/sun/star/report/XFixedLine.hpp>
82 #include <com/sun/star/report/Function.hpp>
83 #include <com/sun/star/report/XShape.hpp>
84 #include <com/sun/star/awt/FontDescriptor.hpp>
85 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
86 #include <com/sun/star/sdb/XParametersSupplier.hpp>
87 #include <com/sun/star/sdb/CommandType.hpp>
88 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
89 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
90 #include <com/sun/star/embed/ElementModes.hpp>
91 #include <com/sun/star/embed/EmbedMapUnits.hpp>
92 #include <comphelper/streamsection.hxx>
93 #include <com/sun/star/awt/FontWeight.hpp>
94 #include <com/sun/star/awt/FontUnderline.hpp>
95 #include <com/sun/star/awt/TextAlign.hpp>
96 #include <com/sun/star/awt/FontSlant.hpp>
97 #include <com/sun/star/frame/status/FontHeight.hpp>
98 #include <com/sun/star/report/XFormattedField.hpp>
99 #include <com/sun/star/sdb/SQLContext.hpp>
100 #include <com/sun/star/sdbc/SQLWarning.hpp>
101 #include <com/sun/star/beans/PropertyAttribute.hpp>
102 #include <com/sun/star/document/XUndoManagerSupplier.hpp>
103 
104 #include <vcl/svapp.hxx>
105 #include <vcl/msgbox.hxx>
106 #include <vcl/waitobj.hxx>
107 
108 #include <svx/fmview.hxx>
109 #include <editeng/paperinf.hxx>
110 #include <editeng/memberids.hrc>
111 #include <svx/svxids.hrc>
112 #include <svx/svdobj.hxx>
113 #include <svx/dataaccessdescriptor.hxx>
114 #include <editeng/svxenum.hxx>
115 #include <svx/pageitem.hxx>
116 #include <editeng/lrspitem.hxx>
117 #include <editeng/ulspitem.hxx>
118 #include <editeng/sizeitem.hxx>
119 #include <svx/zoomitem.hxx>
120 #include <svx/zoomslideritem.hxx>
121 #include <editeng/brshitem.hxx>
122 #include <svx/flagsdef.hxx>
123 #include <svx/svdpagv.hxx>
124 #include <svx/svxdlg.hxx>
125 #include <svx/zoom_def.hxx>
126 #include <svx/dialogs.hrc>
127 
128 #include "DesignView.hxx"
129 #include "ModuleHelper.hxx"
130 #include "RptObject.hxx"
131 #include "RptUndo.hxx"
132 #include "uistrings.hrc"
133 #include "RptDef.hxx"
134 #include "ReportSection.hxx"
135 #include "SectionView.hxx"
136 #include "UndoActions.hxx"
137 #include "dlgpage.hxx"
138 #include "RptResId.hrc"
139 
140 #include <svl/itempool.hxx>
141 #include <svl/itemset.hxx>
142 #include <svl/aeitem.hxx>
143 #include <svtools/cliplistener.hxx>
144 #include <unotools/syslocale.hxx>
145 #include <unotools/viewoptions.hxx>
146 
147 #include <vos/mutex.hxx>
148 #include "PropertyForward.hxx"
149 #include "SectionWindow.hxx"
150 
151 #include <toolkit/helper/convert.hxx>
152 #include "GroupsSorting.hxx"
153 #include "PageNumber.hxx"
154 #include <toolkit/helper/vclunohelper.hxx>
155 #include "UndoEnv.hxx"
156 #include "InsertFunctions.hxx"
157 #include "ReportControllerObserver.hxx"
158 
159 #include <boost/mem_fn.hpp>
160 #include <boost/bind.hpp>
161 #include <boost/utility.hpp>
162 #include <boost/scoped_ptr.hpp>
163 
164 #include <cppuhelper/exc_hlp.hxx>
165 #include <unotools/confignode.hxx>
166 #include <helpids.hrc>
167 
168 #include <ReportControllerObserver.hxx>
169 
170 #define MAX_ROWS_FOR_PREVIEW    20
171 
172 using namespace ::com::sun::star;
173 using namespace uno;
174 using namespace io;
175 using namespace beans;
176 using namespace frame;
177 using namespace util;
178 using namespace lang;
179 using namespace container;
180 using namespace sdbcx;
181 using namespace sdbc;
182 using namespace sdb;
183 using namespace ui;
184 using namespace ui::dialogs;
185 using namespace util;
186 using namespace ::dbtools;
187 using namespace ::rptui;
188 using namespace ::dbaui;
189 using namespace ::comphelper;
190 using namespace ::cppu;
191 
192 // -----------------------------------------------------------------------------
193 namespace
194 {
195     // comparing two PropertyValue instances
196     struct PropertyValueCompare : public ::std::binary_function< beans::PropertyValue, ::rtl::OUString , bool >
197     {
198 	    bool operator() (const beans::PropertyValue& x, const ::rtl::OUString& y) const
199 	    {
200 		    return x.Name.equals(y);// ? true : false;
201 	    }
202         bool operator() (const ::rtl::OUString& x,const beans::PropertyValue& y) const
203 	    {
204 		    return x.equals(y.Name);// ? true : false;
205 	    }
206     };
207 
208     void lcl_setFontWPU_nothrow(const uno::Reference< report::XReportControlFormat>& _xReportControlFormat,const sal_Int32 _nId)
209     {
210         if ( _xReportControlFormat.is() )
211 	    {
212 		    try
213 		    {
214 			    awt::FontDescriptor aFontDescriptor = _xReportControlFormat->getFontDescriptor();
215                 switch(_nId)
216                 {
217                     case SID_ATTR_CHAR_WEIGHT:
218                         aFontDescriptor.Weight = (awt::FontWeight::NORMAL + awt::FontWeight::BOLD) - aFontDescriptor.Weight;
219                         break;
220                     case SID_ATTR_CHAR_POSTURE:
221                         aFontDescriptor.Slant = static_cast<awt::FontSlant>(static_cast<sal_Int16>(awt::FontSlant_ITALIC) - static_cast<sal_Int16>(aFontDescriptor.Slant));
222                         break;
223                     case SID_ATTR_CHAR_UNDERLINE:
224                         aFontDescriptor.Underline = awt::FontUnderline::SINGLE - aFontDescriptor.Underline;
225                         break;
226                     default:
227                         OSL_ENSURE(0,"Illegal value in default!");
228                         break;
229                 }
230 
231 			    _xReportControlFormat->setFontDescriptor(aFontDescriptor);
232 		    }
233 		    catch(beans::UnknownPropertyException&)
234 		    {
235 		    }
236 	    } // if ( xReportControlFormat.is() )
237     }
238 }
239 
240 // -----------------------------------------------------------------------------
241 void lcl_getReportControlFormat(const Sequence< PropertyValue >& aArgs,
242                                  ODesignView* _pView,
243                                  uno::Reference< awt::XWindow>& _xWindow,
244                                  ::std::vector< uno::Reference< uno::XInterface > >& _rControlsFormats)
245 {
246 	uno::Reference< report::XReportControlFormat> xReportControlFormat;
247 	if ( aArgs.getLength() )
248 	{
249 		SequenceAsHashMap aMap(aArgs);
250 		xReportControlFormat = aMap.getUnpackedValueOrDefault(REPORTCONTROLFORMAT,uno::Reference< report::XReportControlFormat>());
251 		_xWindow = aMap.getUnpackedValueOrDefault(CURRENT_WINDOW,uno::Reference< awt::XWindow>());
252 	}
253 
254 	if ( !xReportControlFormat.is() )
255     {
256         _pView->fillControlModelSelection(_rControlsFormats);
257     }
258     else
259     {
260         _rControlsFormats.push_back(xReportControlFormat);
261     }
262 
263 	if ( !_xWindow.is() )
264 		_xWindow = VCLUnoHelper::GetInterface(_pView);
265 }
266 // -----------------------------------------------------------------------------
267 ::rtl::OUString SAL_CALL OReportController::getImplementationName() throw( RuntimeException )
268 {
269 	return getImplementationName_Static();
270 }
271 
272 //------------------------------------------------------------------------------
273 ::rtl::OUString OReportController::getImplementationName_Static() throw( RuntimeException )
274 {
275 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.comp.ReportDesign"));
276 }
277 //------------------------------------------------------------------------------
278 Sequence< ::rtl::OUString> OReportController::getSupportedServiceNames_Static(void) throw( RuntimeException )
279 {
280 	Sequence< ::rtl::OUString> aSupported(1);
281 	aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.ReportDesign"));
282 	return aSupported;
283 }
284 //-------------------------------------------------------------------------
285 Sequence< ::rtl::OUString> SAL_CALL OReportController::getSupportedServiceNames() throw(RuntimeException)
286 {
287 	return getSupportedServiceNames_Static();
288 }
289 // -------------------------------------------------------------------------
290 Reference< XInterface > OReportController::create(Reference< XComponentContext > const & xContext)
291 {
292 	return *(new OReportController(xContext));
293 }
294 
295 #define PROPERTY_ID_ZOOMVALUE   1
296 
297 DBG_NAME( rpt_OReportController )
298 // -----------------------------------------------------------------------------
299 OReportController::OReportController(Reference< XComponentContext > const & xContext)
300     :OReportController_BASE(Reference< XMultiServiceFactory >(xContext->getServiceManager(),UNO_QUERY))
301     ,OPropertyStateContainer(OGenericUnoController_Base::rBHelper)
302     ,m_aSelectionListeners( getMutex() )
303     ,m_pClipbordNotifier(NULL)
304     ,m_pGroupsFloater(NULL)
305     ,m_xContext(xContext)
306     ,m_nSplitPos(-1)
307     ,m_nPageNum(-1)
308     ,m_nSelectionCount(0)
309     ,m_nZoomValue(100)
310     ,m_eZoomType(SVX_ZOOM_PERCENT)
311     ,m_bShowRuler(sal_True)
312     ,m_bGridVisible(sal_True)
313     ,m_bGridUse(sal_True)
314     ,m_bShowProperties(sal_True)
315     ,m_bGroupFloaterWasVisible(sal_False)
316     ,m_bHelplinesMove(sal_True)
317     ,m_bChartEnabled(false)
318     ,m_bChartEnabledAsked(false)
319     ,m_bInGeneratePreview(false)
320 {
321     // new Observer
322     m_pReportControllerObserver = new OXReportControllerObserver(*this);
323     m_pReportControllerObserver->acquire();
324 
325 	m_sMode =  ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("normal"));
326     DBG_CTOR( rpt_OReportController,NULL);
327     registerProperty(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ZoomValue")),PROPERTY_ID_ZOOMVALUE,beans::PropertyAttribute::BOUND| beans::PropertyAttribute::TRANSIENT,&m_nZoomValue,::getCppuType(reinterpret_cast< sal_Int16*>(NULL)));
328 
329 }
330 // -----------------------------------------------------------------------------
331 OReportController::~OReportController()
332 {
333     DBG_DTOR( rpt_OReportController,NULL);
334 }
335 // -----------------------------------------------------------------------------
336 IMPLEMENT_FORWARD_XTYPEPROVIDER2(OReportController,OReportController_BASE,OReportController_Listener)
337 IMPLEMENT_FORWARD_XINTERFACE2(OReportController,OReportController_BASE,OReportController_Listener)
338 // -----------------------------------------------------------------------------
339 void OReportController::disposing()
340 {
341 
342 	if ( m_pClipbordNotifier )
343 	{
344 		m_pClipbordNotifier->ClearCallbackLink();
345 		m_pClipbordNotifier->AddRemoveListener( getView(), sal_False );
346 		m_pClipbordNotifier->release();
347 		m_pClipbordNotifier = NULL;
348 	} // if ( getView() && m_pClipbordNotifier )
349     if ( m_pGroupsFloater )
350 	{
351         SvtViewOptions aDlgOpt( E_WINDOW, String::CreateFromInt32( RID_GROUPS_SORTING ) );
352         aDlgOpt.SetWindowState( ::rtl::OUString::createFromAscii( m_pGroupsFloater->GetWindowState(WINDOWSTATE_MASK_ALL).GetBuffer() ) );
353 		::std::auto_ptr<FloatingWindow> aTemp(m_pGroupsFloater);
354 		m_pGroupsFloater = NULL;
355 	}
356 
357     try
358     {
359         m_xHoldAlive.clear();
360         m_xColumns.clear();
361         ::comphelper::disposeComponent( m_xRowSet );
362         ::comphelper::disposeComponent( m_xRowSetMediator );
363         ::comphelper::disposeComponent( m_xFormatter );
364     }
365     catch(uno::Exception&)
366     {
367         OSL_ENSURE(0,"Exception caught while disposing row sets.");
368     }
369     m_xRowSet.clear();
370     m_xRowSetMediator.clear();
371 
372     if ( m_xReportDefinition.is() )
373     {
374         try
375 	    {
376             ::boost::shared_ptr<OSectionWindow> pSectionWindow;
377             if ( getDesignView() )
378                 pSectionWindow = getDesignView()->getMarkedSection();
379             if ( pSectionWindow )
380                 pSectionWindow->getReportSection().deactivateOle();
381             clearUndoManager();
382             if ( m_aReportModel )
383                 listen(false);
384             m_pReportControllerObserver->Clear();
385             m_pReportControllerObserver->release();
386         }
387         catch ( const uno::Exception& )
388 	    {
389             DBG_UNHANDLED_EXCEPTION();
390 	    }
391     }
392 
393     {
394         EventObject aDisposingEvent( *this );
395         m_aSelectionListeners.disposeAndClear( aDisposingEvent );
396     }
397 
398     OReportController_BASE::disposing();
399 
400 
401     try
402 	{
403         m_xReportDefinition.clear();
404         m_aReportModel.reset();
405         m_xFrameLoader.clear();
406         m_xReportEngine.clear();
407     }
408     catch(uno::Exception&)
409 	{
410 	}
411     if ( getDesignView() )
412         EndListening( *getDesignView() );
413     clearView();
414 }
415 // -----------------------------------------------------------------------------
416 FeatureState OReportController::GetState(sal_uInt16 _nId) const
417 {
418 	FeatureState aReturn;
419 	// (disabled automatically)
420 	aReturn.bEnabled = sal_False;
421 	// check this first
422 	if ( !getView() )
423 		return aReturn;
424 
425 	switch (_nId)
426 	{
427         case SID_RPT_TEXTDOCUMENT:
428             aReturn.bEnabled = isEditable();
429             aReturn.bChecked = (m_xReportDefinition.is() && m_xReportDefinition->getMimeType() == MIMETYPE_OASIS_OPENDOCUMENT_TEXT);
430             break;
431         case SID_RPT_SPREADSHEET:
432             aReturn.bEnabled = isEditable();
433             aReturn.bChecked = (m_xReportDefinition.is() && m_xReportDefinition->getMimeType() == MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET);
434             break;
435 		case SID_REPORTHEADER_WITHOUT_UNDO:
436 		case SID_REPORTFOOTER_WITHOUT_UNDO:
437 		case SID_REPORTHEADERFOOTER:
438             {
439 			    aReturn.bEnabled = isEditable();
440                 ::rtl::OUString sText = String(ModuleRes((m_xReportDefinition.is() && m_xReportDefinition->getReportHeaderOn()) ? RID_STR_REPORTHEADERFOOTER_DELETE : RID_STR_REPORTHEADERFOOTER_INSERT));
441                 aReturn.sTitle = sText;
442             }
443 			break;
444 		case SID_PAGEHEADER_WITHOUT_UNDO:
445 		case SID_PAGEFOOTER_WITHOUT_UNDO:
446 		case SID_PAGEHEADERFOOTER:
447             {
448 			    aReturn.bEnabled = isEditable();
449                 ::rtl::OUString sText = String(ModuleRes((m_xReportDefinition.is() && m_xReportDefinition->getPageHeaderOn()) ? RID_STR_PAGEHEADERFOOTER_DELETE : RID_STR_PAGEHEADERFOOTER_INSERT));
450                 aReturn.sTitle = sText;
451             }
452 			break;
453 		case SID_GROUP_APPEND:
454 		case SID_GROUP_REMOVE:
455 		case SID_GROUPHEADER_WITHOUT_UNDO:
456 		case SID_GROUPHEADER:
457 		case SID_GROUPFOOTER_WITHOUT_UNDO:
458 		case SID_GROUPFOOTER:
459             aReturn.bEnabled = isEditable();
460             break;
461 		case SID_ADD_CONTROL_PAIR:
462 			aReturn.bEnabled = isEditable();
463 			break;
464 		case SID_REDO:
465 		case SID_UNDO:
466             {
467                 size_t ( SfxUndoManager::*retrieveCount )( bool const ) const =
468                     ( _nId == SID_UNDO ) ? &SfxUndoManager::GetUndoActionCount : &SfxUndoManager::GetRedoActionCount;
469 
470                 SfxUndoManager& rUndoManager( getUndoManager() );
471                 aReturn.bEnabled = ( rUndoManager.*retrieveCount )( ::svl::IUndoManager::TopLevel ) > 0;
472                 if ( aReturn.bEnabled )
473                 {
474                     // TODO: add "Undo/Redo: prefix"
475                     String ( SfxUndoManager::*retrieveComment )( size_t, bool const ) const =
476                         ( _nId == SID_UNDO ) ? &SfxUndoManager::GetUndoActionComment : &SfxUndoManager::GetRedoActionComment;
477                     aReturn.sTitle = (rUndoManager.*retrieveComment)( 0, ::svl::IUndoManager::TopLevel );
478                 }
479             }
480 			break;
481         case SID_OBJECT_RESIZING:
482         case SID_OBJECT_SMALLESTWIDTH:
483         case SID_OBJECT_SMALLESTHEIGHT:
484         case SID_OBJECT_GREATESTWIDTH:
485         case SID_OBJECT_GREATESTHEIGHT:
486             aReturn.bEnabled = isEditable() && getDesignView()->HasSelection();// && getDesignView()->isAlignPossible();
487             if ( aReturn.bEnabled )
488                 aReturn.bEnabled = m_nSelectionCount > 1;
489 			break;
490 
491         case SID_DISTRIBUTION:
492             aReturn.bEnabled = isEditable() && getDesignView()->HasSelection();
493             if ( aReturn.bEnabled )
494             {
495                 OSectionView* pSectionView = getCurrentSectionView();
496                 aReturn.bEnabled = pSectionView && pSectionView->GetMarkedObjectCount() > 2;
497             }
498             break;
499         case SID_ARRANGEMENU:
500         case SID_FRAME_DOWN:
501         case SID_FRAME_UP:
502         case SID_FRAME_TO_TOP:
503         case SID_FRAME_TO_BOTTOM:
504         case SID_OBJECT_HEAVEN:
505         case SID_OBJECT_HELL:
506             aReturn.bEnabled = isEditable() && getDesignView()->HasSelection();
507             if ( aReturn.bEnabled )
508             {
509                 OSectionView* pSectionView = getCurrentSectionView();
510                 aReturn.bEnabled = pSectionView && pSectionView->OnlyShapesMarked();
511                 if ( aReturn.bEnabled )
512                 {
513                     if ( SID_OBJECT_HEAVEN == _nId )
514                         aReturn.bEnabled = pSectionView->GetLayerIdOfMarkedObjects() != RPT_LAYER_FRONT;
515                     else if ( SID_OBJECT_HELL == _nId )
516                         aReturn.bEnabled = pSectionView->GetLayerIdOfMarkedObjects() != RPT_LAYER_BACK;
517                 }
518             }
519             break;
520 
521         case SID_SECTION_SHRINK:
522         case SID_SECTION_SHRINK_TOP:
523         case SID_SECTION_SHRINK_BOTTOM:
524         	{
525                 sal_Int32 nCount = 0;
526                 uno::Reference<report::XSection> xSection = getDesignView()->getCurrentSection();
527                 if ( xSection.is() )
528                 {
529                     nCount = xSection->getCount();
530                 }
531                 aReturn.bEnabled = isEditable() && nCount > 0;
532             }
533             break;
534         case SID_OBJECT_ALIGN:
535         case SID_OBJECT_ALIGN_LEFT:
536         case SID_OBJECT_ALIGN_CENTER:
537         case SID_OBJECT_ALIGN_RIGHT:
538         case SID_OBJECT_ALIGN_UP:
539         case SID_OBJECT_ALIGN_MIDDLE:
540         case SID_OBJECT_ALIGN_DOWN:
541         case SID_SECTION_ALIGN:
542         case SID_SECTION_ALIGN_LEFT:
543         case SID_SECTION_ALIGN_CENTER:
544         case SID_SECTION_ALIGN_RIGHT:
545         case SID_SECTION_ALIGN_UP:
546         case SID_SECTION_ALIGN_MIDDLE:
547         case SID_SECTION_ALIGN_DOWN:
548             aReturn.bEnabled = isEditable() && getDesignView()->HasSelection();// && getDesignView()->isAlignPossible();
549 			break;
550 		case SID_CUT:
551 			aReturn.bEnabled = isEditable() && getDesignView()->HasSelection() && !getDesignView()->isHandleEvent(_nId);
552 			break;
553 		case SID_COPY:
554 			aReturn.bEnabled = getDesignView()->HasSelection() && !getDesignView()->isHandleEvent(_nId);
555 			break;
556 		case SID_PASTE:
557 			aReturn.bEnabled = isEditable()  && !getDesignView()->isHandleEvent(_nId) && getDesignView()->IsPasteAllowed();
558 			break;
559 		case SID_SELECTALL:
560 			aReturn.bEnabled = !getDesignView()->isHandleEvent(_nId);
561 			break;
562         case SID_SELECTALL_IN_SECTION:
563             aReturn.bEnabled = !getDesignView()->isHandleEvent(_nId);
564             if ( aReturn.bEnabled )
565                 aReturn.bEnabled = getCurrentSectionView() != NULL;
566 			break;
567         case SID_ESCAPE:
568             aReturn.bEnabled = getDesignView()->GetMode() == RPTUI_INSERT;
569             break;
570         case SID_TERMINATE_INPLACEACTIVATION:
571             aReturn.bEnabled = sal_True;
572             break;
573         case SID_SELECT_ALL_EDITS:
574         case SID_SELECT_ALL_LABELS:
575             aReturn.bEnabled = sal_True;
576             break;
577         case SID_RPT_NEW_FUNCTION:
578             aReturn.bEnabled = isEditable();
579             break;
580         case SID_COLLAPSE_SECTION:
581         case SID_EXPAND_SECTION:
582         case SID_NEXT_MARK:
583         case SID_PREV_MARK:
584             aReturn.bEnabled = isEditable() && !getDesignView()->isHandleEvent(_nId);
585             break;
586         case SID_SELECT:
587 		case SID_SELECT_REPORT:
588 			aReturn.bEnabled = sal_True;
589 			break;
590         case SID_EXECUTE_REPORT:
591             aReturn.bEnabled = isConnected() && m_xReportDefinition.is();
592             break;
593 		case SID_DELETE:
594 			aReturn.bEnabled = isEditable() && getDesignView()->HasSelection() && !getDesignView()->isHandleEvent(_nId);
595             if ( aReturn.bEnabled )
596             {
597                 ::boost::shared_ptr<OSectionWindow> pSectionWindow = getDesignView()->getMarkedSection();
598                 if ( pSectionWindow )
599                     aReturn.bEnabled = !pSectionWindow->getReportSection().isUiActive();
600             }
601             {
602                 ::rtl::OUString sText = String(ModuleRes(RID_STR_DELETE));
603                 aReturn.sTitle = sText;
604             }
605 			break;
606 		case SID_GRID_VISIBLE:
607 			aReturn.bEnabled = isEditable();
608 			aReturn.bChecked = m_bGridVisible;
609 			break;
610 		case SID_GRID_USE:
611             aReturn.bEnabled = isEditable();
612 			aReturn.bChecked = m_bGridUse;
613 			break;
614         case SID_HELPLINES_MOVE:
615             aReturn.bEnabled = isEditable();
616 			aReturn.bChecked = m_bHelplinesMove;
617             break;
618 		case SID_RULER:
619 			aReturn.bEnabled = isEditable();
620 			aReturn.bChecked = m_bShowRuler;
621 			break;
622 		case SID_OBJECT_SELECT:
623 			aReturn.bEnabled = sal_True;
624 			aReturn.bChecked = getDesignView()->GetMode() == RPTUI_SELECT;
625 			break;
626         case SID_INSERT_DIAGRAM:
627             aReturn.bEnabled = isEditable();
628             aReturn.bInvisible = optional< bool >(!m_bChartEnabled);
629 			aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_OLE2;
630             break;
631 		case SID_FM_FIXEDTEXT:
632 			aReturn.bEnabled = isEditable();
633 			aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_DLG_FIXEDTEXT;
634 			break;
635         case SID_INSERT_HFIXEDLINE:
636 			aReturn.bEnabled = isEditable();
637 			aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_DLG_HFIXEDLINE;
638 			break;
639         case SID_INSERT_VFIXEDLINE:
640 			aReturn.bEnabled = isEditable();
641 			aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_DLG_VFIXEDLINE;
642 			break;
643 		case SID_FM_EDIT:
644 			aReturn.bEnabled = isEditable();
645 			aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_DLG_FORMATTEDFIELD;
646 			break;
647 		case SID_FM_IMAGECONTROL:
648 			aReturn.bEnabled = isEditable();
649 			aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_DLG_IMAGECONTROL;
650 			break;
651         case SID_DRAWTBX_CS_BASIC:
652         case SID_DRAWTBX_CS_BASIC1:
653         case SID_DRAWTBX_CS_BASIC2:
654         case SID_DRAWTBX_CS_BASIC3:
655         case SID_DRAWTBX_CS_BASIC4:
656         case SID_DRAWTBX_CS_BASIC5:
657         case SID_DRAWTBX_CS_BASIC6:
658         case SID_DRAWTBX_CS_BASIC7:
659         case SID_DRAWTBX_CS_BASIC8:
660         case SID_DRAWTBX_CS_BASIC9:
661         case SID_DRAWTBX_CS_BASIC10:
662         case SID_DRAWTBX_CS_BASIC11:
663         case SID_DRAWTBX_CS_BASIC12:
664         case SID_DRAWTBX_CS_BASIC13:
665         case SID_DRAWTBX_CS_BASIC14:
666         case SID_DRAWTBX_CS_BASIC15:
667         case SID_DRAWTBX_CS_BASIC16:
668         case SID_DRAWTBX_CS_BASIC17:
669         case SID_DRAWTBX_CS_BASIC18:
670         case SID_DRAWTBX_CS_BASIC19:
671         case SID_DRAWTBX_CS_BASIC20:
672         case SID_DRAWTBX_CS_BASIC21:
673         case SID_DRAWTBX_CS_BASIC22:
674             impl_fillCustomShapeState_nothrow("diamond",aReturn);
675 	        break;
676         case SID_DRAWTBX_CS_SYMBOL:
677 		case SID_DRAWTBX_CS_SYMBOL1:
678 		case SID_DRAWTBX_CS_SYMBOL2:
679 		case SID_DRAWTBX_CS_SYMBOL3:
680 		case SID_DRAWTBX_CS_SYMBOL4:
681 		case SID_DRAWTBX_CS_SYMBOL5:
682 		case SID_DRAWTBX_CS_SYMBOL6:
683 		case SID_DRAWTBX_CS_SYMBOL7:
684 		case SID_DRAWTBX_CS_SYMBOL8:
685 		case SID_DRAWTBX_CS_SYMBOL9:
686 		case SID_DRAWTBX_CS_SYMBOL10:
687 		case SID_DRAWTBX_CS_SYMBOL11:
688 		case SID_DRAWTBX_CS_SYMBOL12:
689 		case SID_DRAWTBX_CS_SYMBOL13:
690 		case SID_DRAWTBX_CS_SYMBOL14:
691 		case SID_DRAWTBX_CS_SYMBOL15:
692 		case SID_DRAWTBX_CS_SYMBOL16:
693 		case SID_DRAWTBX_CS_SYMBOL17:
694 		case SID_DRAWTBX_CS_SYMBOL18:
695             impl_fillCustomShapeState_nothrow("smiley",aReturn);
696             break;
697         case SID_DRAWTBX_CS_ARROW:
698 		case SID_DRAWTBX_CS_ARROW1:
699 		case SID_DRAWTBX_CS_ARROW2:
700 		case SID_DRAWTBX_CS_ARROW3:
701 		case SID_DRAWTBX_CS_ARROW4:
702 		case SID_DRAWTBX_CS_ARROW5:
703 		case SID_DRAWTBX_CS_ARROW6:
704 		case SID_DRAWTBX_CS_ARROW7:
705 		case SID_DRAWTBX_CS_ARROW8:
706 		case SID_DRAWTBX_CS_ARROW9:
707 		case SID_DRAWTBX_CS_ARROW10:
708 		case SID_DRAWTBX_CS_ARROW11:
709 		case SID_DRAWTBX_CS_ARROW12:
710 		case SID_DRAWTBX_CS_ARROW13:
711 		case SID_DRAWTBX_CS_ARROW14:
712 		case SID_DRAWTBX_CS_ARROW15:
713 		case SID_DRAWTBX_CS_ARROW16:
714 		case SID_DRAWTBX_CS_ARROW17:
715 		case SID_DRAWTBX_CS_ARROW18:
716 		case SID_DRAWTBX_CS_ARROW19:
717 		case SID_DRAWTBX_CS_ARROW20:
718 		case SID_DRAWTBX_CS_ARROW21:
719 		case SID_DRAWTBX_CS_ARROW22:
720 		case SID_DRAWTBX_CS_ARROW23:
721 		case SID_DRAWTBX_CS_ARROW24:
722 		case SID_DRAWTBX_CS_ARROW25:
723 		case SID_DRAWTBX_CS_ARROW26:
724             impl_fillCustomShapeState_nothrow("left-right-arrow",aReturn);
725             break;
726         case SID_DRAWTBX_CS_STAR:
727 		case SID_DRAWTBX_CS_STAR1:
728 		case SID_DRAWTBX_CS_STAR2:
729 		case SID_DRAWTBX_CS_STAR3:
730 		case SID_DRAWTBX_CS_STAR4:
731 		case SID_DRAWTBX_CS_STAR5:
732 		case SID_DRAWTBX_CS_STAR6:
733 		case SID_DRAWTBX_CS_STAR7:
734 		case SID_DRAWTBX_CS_STAR8:
735 		case SID_DRAWTBX_CS_STAR9:
736 		case SID_DRAWTBX_CS_STAR10:
737 		case SID_DRAWTBX_CS_STAR11:
738 		case SID_DRAWTBX_CS_STAR12:
739             impl_fillCustomShapeState_nothrow("star5",aReturn);
740             break;
741         case SID_DRAWTBX_CS_FLOWCHART:
742 		case SID_DRAWTBX_CS_FLOWCHART1:
743 		case SID_DRAWTBX_CS_FLOWCHART2:
744 		case SID_DRAWTBX_CS_FLOWCHART3:
745 		case SID_DRAWTBX_CS_FLOWCHART4:
746 		case SID_DRAWTBX_CS_FLOWCHART5:
747 		case SID_DRAWTBX_CS_FLOWCHART6:
748 		case SID_DRAWTBX_CS_FLOWCHART7:
749 		case SID_DRAWTBX_CS_FLOWCHART8:
750 		case SID_DRAWTBX_CS_FLOWCHART9:
751 		case SID_DRAWTBX_CS_FLOWCHART10:
752 		case SID_DRAWTBX_CS_FLOWCHART11:
753 		case SID_DRAWTBX_CS_FLOWCHART12:
754 		case SID_DRAWTBX_CS_FLOWCHART13:
755 		case SID_DRAWTBX_CS_FLOWCHART14:
756 		case SID_DRAWTBX_CS_FLOWCHART15:
757 		case SID_DRAWTBX_CS_FLOWCHART16:
758 		case SID_DRAWTBX_CS_FLOWCHART17:
759 		case SID_DRAWTBX_CS_FLOWCHART18:
760 		case SID_DRAWTBX_CS_FLOWCHART19:
761 		case SID_DRAWTBX_CS_FLOWCHART20:
762 		case SID_DRAWTBX_CS_FLOWCHART21:
763 		case SID_DRAWTBX_CS_FLOWCHART22:
764 		case SID_DRAWTBX_CS_FLOWCHART23:
765 		case SID_DRAWTBX_CS_FLOWCHART24:
766 		case SID_DRAWTBX_CS_FLOWCHART25:
767 		case SID_DRAWTBX_CS_FLOWCHART26:
768 		case SID_DRAWTBX_CS_FLOWCHART27:
769 		case SID_DRAWTBX_CS_FLOWCHART28:
770             impl_fillCustomShapeState_nothrow("flowchart-internal-storage",aReturn);
771             break;
772         case SID_DRAWTBX_CS_CALLOUT:
773 		case SID_DRAWTBX_CS_CALLOUT1:
774 		case SID_DRAWTBX_CS_CALLOUT2:
775 		case SID_DRAWTBX_CS_CALLOUT3:
776 		case SID_DRAWTBX_CS_CALLOUT4:
777 		case SID_DRAWTBX_CS_CALLOUT5:
778 		case SID_DRAWTBX_CS_CALLOUT6:
779 		case SID_DRAWTBX_CS_CALLOUT7:
780             impl_fillCustomShapeState_nothrow("round-rectangular-callout",aReturn);
781             break;
782         case SID_RPT_SHOWREPORTEXPLORER:
783             aReturn.bEnabled = m_xReportDefinition.is();
784 			aReturn.bChecked = getDesignView() && getDesignView()->isReportExplorerVisible();
785             break;
786 		case SID_FM_ADD_FIELD:
787             aReturn.bEnabled = isConnected() && isEditable() && m_xReportDefinition.is()
788                 && m_xReportDefinition->getCommand().getLength();
789 			aReturn.bChecked = getDesignView() && getDesignView()->isAddFieldVisible();
790 			break;
791 		case SID_SHOW_PROPERTYBROWSER:
792 			aReturn.bEnabled = sal_True;
793 			aReturn.bChecked = m_bShowProperties;
794 			break;
795         case SID_PROPERTYBROWSER_LAST_PAGE:
796 			aReturn.bEnabled = sal_True;
797             aReturn.aValue <<= m_sLastActivePage;
798             break;
799         case SID_SPLIT_POSITION:
800             aReturn.bEnabled = sal_True;
801             aReturn.aValue <<= getSplitPos();
802             break;
803 		case SID_SAVEDOC:
804 			aReturn.bEnabled = impl_isModified() && isEditable();
805 			break;
806 		case SID_SAVEASDOC:
807 			aReturn.bEnabled = isConnected() && isEditable();
808 			break;
809 		case SID_EDITDOC:
810 			aReturn.bChecked = isEditable();
811 			break;
812         case SID_PAGEDIALOG:
813 			aReturn.bEnabled = isEditable();
814 			break;
815 		case SID_BACKGROUND_COLOR:
816             impl_fillState_nothrow(PROPERTY_CONTROLBACKGROUND,aReturn);
817 			break;
818 		case SID_ATTR_CHAR_COLOR_BACKGROUND:
819             aReturn.bEnabled = isEditable();
820 			{
821 				uno::Reference<report::XSection> xSection = getDesignView()->getCurrentSection();
822 				if ( xSection.is() )
823 					try
824 					{
825 						aReturn.aValue <<= xSection->getBackColor();
826                         const uno::Reference< report::XReportControlModel> xControlModel(getDesignView()->getCurrentControlModel(),uno::UNO_QUERY);
827 						aReturn.bEnabled = !xControlModel.is();
828 					}
829 					catch(beans::UnknownPropertyException&)
830 					{
831 					}
832 				else
833 					aReturn.bEnabled = sal_False;
834 			}
835 			break;
836 		case SID_SORTINGANDGROUPING:
837 			aReturn.bEnabled = sal_True;
838 			aReturn.bChecked = m_pGroupsFloater && m_pGroupsFloater->IsVisible();
839 			break;
840 		case SID_ATTR_CHAR_WEIGHT:
841 		case SID_ATTR_CHAR_POSTURE:
842 		case SID_ATTR_CHAR_UNDERLINE:
843 			impl_fillState_nothrow(PROPERTY_FONTDESCRIPTOR,aReturn);
844             if ( aReturn.bEnabled )
845             {
846                 awt::FontDescriptor aFontDescriptor;
847                 aReturn.aValue >>= aFontDescriptor;
848                 aReturn.aValue.clear();
849 
850 			    switch(_nId)
851 			    {
852 				    case SID_ATTR_CHAR_WEIGHT:
853 					    aReturn.bChecked = awt::FontWeight::BOLD == aFontDescriptor.Weight;
854 					    break;
855 				    case SID_ATTR_CHAR_POSTURE:
856 					    aReturn.bChecked = awt::FontSlant_ITALIC == aFontDescriptor.Slant;
857 					    break;
858 				    case SID_ATTR_CHAR_UNDERLINE:
859 					    aReturn.bChecked = awt::FontUnderline::SINGLE == aFontDescriptor.Underline;
860 					    break;
861 				    default:
862 					    ;
863 			        } // switch(_nCommand)
864             }
865 			break;
866 		case SID_ATTR_CHAR_COLOR:
867 		case SID_ATTR_CHAR_COLOR2:
868             impl_fillState_nothrow(PROPERTY_CHARCOLOR,aReturn);
869 			break;
870         case SID_ATTR_CHAR_FONT:
871             impl_fillState_nothrow(PROPERTY_FONTDESCRIPTOR,aReturn);
872             break;
873         case SID_ATTR_CHAR_FONTHEIGHT:
874             impl_fillState_nothrow(PROPERTY_CHARHEIGHT,aReturn);
875             if ( aReturn.aValue.hasValue() )
876             {
877                 frame::status::FontHeight aFontHeight;
878                 aReturn.aValue >>= aFontHeight.Height;
879                 aReturn.aValue <<= aFontHeight; // another type is needed here, so
880             }
881             break;
882         case SID_ATTR_PARA_ADJUST_LEFT:
883         case SID_ATTR_PARA_ADJUST_CENTER:
884         case SID_ATTR_PARA_ADJUST_RIGHT:
885         case SID_ATTR_PARA_ADJUST_BLOCK:
886             impl_fillState_nothrow(PROPERTY_PARAADJUST,aReturn);
887             if ( aReturn.bEnabled )
888             {
889                 ::sal_Int16 nParaAdjust = 0;
890                 if ( aReturn.aValue >>= nParaAdjust )
891                 {
892                     switch(nParaAdjust)
893                     {
894                         case style::ParagraphAdjust_LEFT:
895                             aReturn.bChecked = _nId == SID_ATTR_PARA_ADJUST_LEFT;
896                             break;
897                         case style::ParagraphAdjust_RIGHT:
898                             aReturn.bChecked = _nId == SID_ATTR_PARA_ADJUST_RIGHT;
899                             break;
900                         case style::ParagraphAdjust_BLOCK:
901                         case style::ParagraphAdjust_STRETCH:
902                             aReturn.bChecked = _nId == SID_ATTR_PARA_ADJUST_BLOCK;
903                             break;
904                         case style::ParagraphAdjust_CENTER:
905                             aReturn.bChecked = _nId == SID_ATTR_PARA_ADJUST_CENTER;
906                             break;
907                     }
908                 } // if ( aReturn.aValue >>= nParaAdjust )
909                 aReturn.aValue.clear();
910             }
911             break;
912 
913 		case SID_INSERT_GRAPHIC:
914             aReturn.bEnabled = m_xReportDefinition.is() && isEditable() && getDesignView()->getCurrentSection().is();
915 			break;
916         case SID_CHAR_DLG:
917 		case SID_SETCONTROLDEFAULTS:
918 			aReturn.bEnabled = m_xReportDefinition.is() && isEditable();// && getDesignView()->getCurrentControlModel().is();
919             if ( aReturn.bEnabled )
920             {
921                 ::std::vector< uno::Reference< uno::XInterface > > aSelection;
922                 getDesignView()->fillControlModelSelection(aSelection);
923                 ::std::vector< uno::Reference< uno::XInterface > >::iterator aIter = aSelection.begin();
924                 for(; aIter != aSelection.end()
925                     && !uno::Reference< report::XFixedLine >(*aIter,uno::UNO_QUERY).is()
926                     && !uno::Reference< report::XImageControl >(*aIter,uno::UNO_QUERY).is()
927                     && uno::Reference< report::XReportControlFormat >(*aIter,uno::UNO_QUERY).is() ;++aIter)
928                     ;
929                 aReturn.bEnabled = !aSelection.empty() && aIter == aSelection.end();
930             }
931 			break;
932 		case SID_CONDITIONALFORMATTING:
933 			{
934                 const uno::Reference< report::XFormattedField> xFormattedField(getDesignView()->getCurrentControlModel(),uno::UNO_QUERY);
935 				aReturn.bEnabled = xFormattedField.is();
936 			}
937 			break;
938 		case SID_INSERT_FLD_PGNUMBER:
939 		case SID_DATETIME:
940 			aReturn.bEnabled = m_xReportDefinition.is() && isEditable() && getDesignView()->getCurrentSection().is();
941 			break;
942 		case SID_EXPORTDOC:
943 		case SID_EXPORTDOCASPDF:
944 			aReturn.bEnabled = m_xReportDefinition.is();
945 			break;
946 		case SID_PRINTPREVIEW:
947             aReturn.bEnabled = sal_False;
948 			break;
949         case SID_ATTR_ZOOM:
950             aReturn.bEnabled = sal_True;
951             {
952                 SvxZoomItem aZoom(m_eZoomType,m_nZoomValue);
953                 aZoom.SetValueSet(SVX_ZOOM_ENABLE_50|SVX_ZOOM_ENABLE_75|SVX_ZOOM_ENABLE_100|SVX_ZOOM_ENABLE_200);
954                 aZoom.QueryValue(aReturn.aValue);
955                 //aReturn.sTitle = ::rtl::OUString::valueOf((sal_Int32)m_nZoomValue);
956             }
957             break;
958         case SID_ATTR_ZOOMSLIDER:
959             aReturn.bEnabled = sal_True;
960             {
961                 SvxZoomSliderItem aZoomSlider(m_nZoomValue,20,400);
962                 aZoomSlider.AddSnappingPoint(50);
963                 aZoomSlider.AddSnappingPoint(75);
964                 aZoomSlider.AddSnappingPoint(100);
965                 aZoomSlider.AddSnappingPoint(200);
966                 aZoomSlider.QueryValue(aReturn.aValue);
967                 //aReturn.sTitle = ::rtl::OUString::valueOf((sal_Int32)m_nZoomValue);
968             }
969 			break;
970 		default:
971 			aReturn = OReportController_BASE::GetState(_nId);
972 	}
973 	return aReturn;
974 }
975 
976 // -----------------------------------------------------------------------------
977 namespace
978 {
979     /** extracts a background color from a dispatched SID_BACKGROUND_COLOR call
980 
981         The dispatch might originate from either the toolbar, or the conditional
982         formatting dialog. In both cases, argument formats are different.
983     */
984     util::Color lcl_extractBackgroundColor( const Sequence< PropertyValue >& _rDispatchArgs )
985     {
986 		util::Color aColor( COL_TRANSPARENT );
987         if ( _rDispatchArgs.getLength() == 1 )
988         {
989             OSL_VERIFY( _rDispatchArgs[0].Value >>= aColor );
990         }
991         else
992         {
993 			SequenceAsHashMap aMap( _rDispatchArgs );
994             aColor = aMap.getUnpackedValueOrDefault( PROPERTY_FONTCOLOR, aColor );
995         }
996         return aColor;
997     }
998 }
999 
1000 // -----------------------------------------------------------------------------
1001 void OReportController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
1002 {
1003 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1004 	::osl::MutexGuard aGuard( getMutex() );
1005 
1006     sal_Bool bForceBroadcast = sal_False;
1007 	switch(_nId)
1008 	{
1009         case SID_RPT_TEXTDOCUMENT:
1010             if ( m_xReportDefinition.is() )
1011                 m_xReportDefinition->setMimeType( MIMETYPE_OASIS_OPENDOCUMENT_TEXT );
1012             break;
1013         case SID_RPT_SPREADSHEET:
1014             if (m_xReportDefinition.is() )
1015                 m_xReportDefinition->setMimeType( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET );
1016             break;
1017 		case SID_REPORTHEADER_WITHOUT_UNDO:
1018 		case SID_REPORTFOOTER_WITHOUT_UNDO:
1019 		case SID_REPORTHEADERFOOTER:
1020             switchReportSection(_nId);
1021 			break;
1022 		case SID_PAGEHEADER_WITHOUT_UNDO:
1023 		case SID_PAGEFOOTER_WITHOUT_UNDO:
1024 		case SID_PAGEHEADERFOOTER:
1025             switchPageSection(_nId);
1026 			break;
1027 		case SID_GROUP_APPEND:
1028 		case SID_GROUP_REMOVE:
1029             modifyGroup(_nId == SID_GROUP_APPEND,aArgs);
1030 			break;
1031 		case SID_GROUPHEADER_WITHOUT_UNDO:
1032 		case SID_GROUPHEADER:
1033             createGroupSection(SID_GROUPHEADER == _nId,true,aArgs);
1034 			break;
1035 		case SID_GROUPFOOTER_WITHOUT_UNDO:
1036 		case SID_GROUPFOOTER:
1037             createGroupSection(SID_GROUPFOOTER == _nId,false,aArgs);
1038 			break;
1039 		case SID_ADD_CONTROL_PAIR:
1040             addPairControls(aArgs);
1041 			break;
1042 		case SID_REDO:
1043         case SID_UNDO:
1044         {
1045             const OXUndoEnvironment::OUndoMode aLock( m_aReportModel->GetUndoEnv() );
1046             sal_Bool ( SfxUndoManager::*doXDo )() =
1047                 ( _nId == SID_UNDO ) ? &SfxUndoManager::Undo : &SfxUndoManager::Redo;
1048 
1049             SfxUndoManager& rUndoManager( getUndoManager() );
1050             (rUndoManager.*doXDo)();
1051             InvalidateAll();
1052             updateFloater();
1053         }
1054 		break;
1055 		case SID_CUT:
1056             executeMethodWithUndo(RID_STR_UNDO_REMOVE_SELECTION,::std::mem_fun(&ODesignView::Cut));
1057 			break;
1058 		case SID_COPY:
1059 			getDesignView()->Copy();
1060 			break;
1061 		case SID_PASTE:
1062             executeMethodWithUndo(RID_STR_UNDO_PASTE,::std::mem_fun(&ODesignView::Paste));
1063 			break;
1064 
1065         case SID_FRAME_TO_TOP:
1066         case SID_FRAME_DOWN:
1067         case SID_FRAME_UP:
1068         case SID_FRAME_TO_BOTTOM:
1069         case SID_OBJECT_HEAVEN:
1070         case SID_OBJECT_HELL:
1071             changeZOrder(_nId);
1072 			break;
1073         case SID_DISTRIBUTION:
1074             {
1075                 OSectionView* pSectionView = getCurrentSectionView();
1076                 if ( pSectionView )
1077                     pSectionView->DistributeMarkedObjects();
1078             }
1079             break;
1080         case SID_OBJECT_SMALLESTWIDTH:
1081             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::WIDTH_SMALLEST);
1082             break;
1083         case SID_OBJECT_SMALLESTHEIGHT:
1084             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::HEIGHT_SMALLEST);
1085             break;
1086         case SID_OBJECT_GREATESTWIDTH:
1087             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::WIDTH_GREATEST);
1088             break;
1089         case SID_OBJECT_GREATESTHEIGHT:
1090             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::HEIGHT_GREATEST);
1091             break;
1092         case SID_SECTION_ALIGN_LEFT:
1093         case SID_OBJECT_ALIGN_LEFT:
1094             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::LEFT,SID_SECTION_ALIGN_LEFT == _nId);
1095 			break;
1096         case SID_SECTION_ALIGN_CENTER:
1097         case SID_OBJECT_ALIGN_CENTER:
1098             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::CENTER_HORIZONTAL,SID_SECTION_ALIGN_CENTER == _nId);
1099 			break;
1100         case SID_SECTION_ALIGN_RIGHT:
1101         case SID_OBJECT_ALIGN_RIGHT:
1102             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::RIGHT,SID_SECTION_ALIGN_RIGHT == _nId);
1103 			break;
1104         case SID_SECTION_ALIGN_UP:
1105         case SID_OBJECT_ALIGN_UP:
1106             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::TOP,SID_SECTION_ALIGN_UP == _nId);
1107 			break;
1108         case SID_SECTION_ALIGN_MIDDLE:
1109         case SID_OBJECT_ALIGN_MIDDLE:
1110             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::CENTER_VERTICAL,SID_SECTION_ALIGN_MIDDLE == _nId);
1111 			break;
1112         case SID_SECTION_ALIGN_DOWN:
1113         case SID_OBJECT_ALIGN_DOWN:
1114             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::BOTTOM,SID_SECTION_ALIGN_DOWN == _nId);
1115 			break;
1116 
1117         case SID_SECTION_SHRINK_BOTTOM:
1118         case SID_SECTION_SHRINK_TOP:
1119         case SID_SECTION_SHRINK:
1120             {
1121         		uno::Reference<report::XSection> xSection = getDesignView()->getCurrentSection();
1122                 shrinkSection(RID_STR_UNDO_SHRINK, xSection, _nId);
1123             }
1124             break;
1125 
1126         case SID_SELECTALL:
1127 			getDesignView()->SelectAll(OBJ_NONE);
1128 			break;
1129         case SID_SELECTALL_IN_SECTION:
1130             {
1131                 OSectionView* pSectionView = getCurrentSectionView();
1132                 if ( pSectionView )
1133                     pSectionView->MarkAll();
1134             }
1135             break;
1136         case SID_ESCAPE:
1137             getDesignView()->SetMode(RPTUI_SELECT);
1138             InvalidateFeature( SID_OBJECT_SELECT );
1139             break;
1140         case SID_SELECT_ALL_EDITS:
1141             getDesignView()->SelectAll(OBJ_DLG_FORMATTEDFIELD);
1142             break;
1143         case SID_SELECT_ALL_LABELS:
1144             getDesignView()->SelectAll(OBJ_DLG_FIXEDTEXT);
1145             break;
1146         case SID_TERMINATE_INPLACEACTIVATION:
1147             {
1148                 ::boost::shared_ptr<OSectionWindow> pSection = getDesignView()->getMarkedSection();
1149                 if ( pSection )
1150                     pSection->getReportSection().deactivateOle();
1151             }
1152             break;
1153         case SID_SELECT:
1154             if ( aArgs.getLength() == 1 )
1155                 select(aArgs[0].Value);
1156             break;
1157 		case SID_SELECT_REPORT:
1158             select(uno::makeAny(m_xReportDefinition));
1159 			break;
1160         case SID_EXECUTE_REPORT:
1161             /*m_nExecuteReportEvent = */getView()->PostUserEvent(LINK(this, OReportController,OnExecuteReport));
1162             break;
1163         case SID_RPT_NEW_FUNCTION:
1164             createNewFunction(aArgs[0].Value);
1165             break;
1166         case SID_COLLAPSE_SECTION:
1167             collapseSection(true);
1168             break;
1169         case SID_EXPAND_SECTION:
1170             collapseSection(false);
1171             break;
1172         case SID_NEXT_MARK:
1173             markSection(true);
1174             break;
1175         case SID_PREV_MARK:
1176             markSection(false);
1177             break;
1178 		case SID_DELETE:
1179             if ( aArgs.getLength() == 1 )
1180             {
1181                 uno::Reference< report::XFunction> xFunction;
1182                 aArgs[0].Value >>= xFunction;
1183                 if ( xFunction.is() )
1184                 {
1185                     uno::Reference< report::XFunctions> xFunctions(xFunction->getParent(),uno::UNO_QUERY_THROW);
1186                     sal_Int32 nIndex = getPositionInIndexAccess(xFunctions.get(),xFunction);
1187                     const String sUndoAction = String((ModuleRes(RID_STR_UNDO_REMOVE_FUNCTION)));
1188                     UndoContext aUndoContext( getUndoManager(), sUndoAction );
1189                     xFunctions->removeByIndex(nIndex);
1190                     select(uno::makeAny(xFunctions->getParent()));
1191 	                InvalidateFeature( SID_SAVEDOC );
1192 	                InvalidateFeature( SID_UNDO );
1193                 }
1194             }
1195             else
1196                 executeMethodWithUndo(RID_STR_UNDO_REMOVE_SELECTION,::std::mem_fun(&ODesignView::Delete));
1197 			break;
1198 		case SID_GRID_USE:
1199             getDesignView()->setGridSnap(m_bGridUse = !m_bGridUse);
1200 			break;
1201         case SID_HELPLINES_MOVE:
1202             getDesignView()->setDragStripes(m_bHelplinesMove = !m_bHelplinesMove);
1203             break;
1204 		case SID_GRID_VISIBLE:
1205 			getDesignView()->toggleGrid(m_bGridVisible = !m_bGridVisible);
1206 			break;
1207 		case SID_RULER:
1208 			getDesignView()->showRuler(m_bShowRuler = !m_bShowRuler);
1209 			break;
1210 		case SID_OBJECT_SELECT:
1211 			getDesignView()->SetMode(RPTUI_SELECT);
1212 			InvalidateAll();
1213 			break;
1214         case SID_INSERT_DIAGRAM:
1215             getDesignView()->SetMode( RPTUI_INSERT );
1216 			getDesignView()->SetInsertObj( OBJ_OLE2);
1217             createDefaultControl(aArgs);
1218 			InvalidateAll();
1219             break;
1220 		case SID_FM_FIXEDTEXT:
1221 			getDesignView()->SetMode( RPTUI_INSERT );
1222 			getDesignView()->SetInsertObj( OBJ_DLG_FIXEDTEXT );
1223             createDefaultControl(aArgs);
1224 			InvalidateAll();
1225 			break;
1226         case SID_INSERT_HFIXEDLINE:
1227 			getDesignView()->SetMode( RPTUI_INSERT );
1228 			getDesignView()->SetInsertObj( OBJ_DLG_HFIXEDLINE );
1229             createDefaultControl(aArgs);
1230 			InvalidateAll();
1231 			break;
1232         case SID_INSERT_VFIXEDLINE:
1233 			getDesignView()->SetMode( RPTUI_INSERT );
1234 			getDesignView()->SetInsertObj( OBJ_DLG_VFIXEDLINE );
1235             createDefaultControl(aArgs);
1236 			InvalidateAll();
1237 			break;
1238 		case SID_FM_EDIT:
1239 			getDesignView()->SetMode( RPTUI_INSERT );
1240 			getDesignView()->SetInsertObj( OBJ_DLG_FORMATTEDFIELD );
1241             createDefaultControl(aArgs);
1242 			InvalidateAll();
1243 			break;
1244 		case SID_FM_IMAGECONTROL:
1245 			getDesignView()->SetMode( RPTUI_INSERT );
1246 			getDesignView()->SetInsertObj( OBJ_DLG_IMAGECONTROL );
1247             createDefaultControl(aArgs);
1248 			InvalidateAll();
1249 			break;
1250         case SID_DRAWTBX_CS_BASIC:
1251         case SID_DRAWTBX_CS_BASIC1:
1252         case SID_DRAWTBX_CS_BASIC2:
1253         case SID_DRAWTBX_CS_BASIC3:
1254         case SID_DRAWTBX_CS_BASIC4:
1255         case SID_DRAWTBX_CS_BASIC5:
1256         case SID_DRAWTBX_CS_BASIC6:
1257         case SID_DRAWTBX_CS_BASIC7:
1258         case SID_DRAWTBX_CS_BASIC8:
1259         case SID_DRAWTBX_CS_BASIC9:
1260         case SID_DRAWTBX_CS_BASIC10:
1261         case SID_DRAWTBX_CS_BASIC11:
1262         case SID_DRAWTBX_CS_BASIC12:
1263         case SID_DRAWTBX_CS_BASIC13:
1264         case SID_DRAWTBX_CS_BASIC14:
1265         case SID_DRAWTBX_CS_BASIC15:
1266         case SID_DRAWTBX_CS_BASIC16:
1267         case SID_DRAWTBX_CS_BASIC17:
1268         case SID_DRAWTBX_CS_BASIC18:
1269         case SID_DRAWTBX_CS_BASIC19:
1270         case SID_DRAWTBX_CS_BASIC20:
1271         case SID_DRAWTBX_CS_BASIC21:
1272         case SID_DRAWTBX_CS_BASIC22:
1273         case SID_DRAWTBX_CS_SYMBOL1:
1274 		case SID_DRAWTBX_CS_SYMBOL2:
1275 		case SID_DRAWTBX_CS_SYMBOL3:
1276 		case SID_DRAWTBX_CS_SYMBOL4:
1277 		case SID_DRAWTBX_CS_SYMBOL5:
1278 		case SID_DRAWTBX_CS_SYMBOL6:
1279 		case SID_DRAWTBX_CS_SYMBOL7:
1280 		case SID_DRAWTBX_CS_SYMBOL8:
1281 		case SID_DRAWTBX_CS_SYMBOL9:
1282 		case SID_DRAWTBX_CS_SYMBOL10:
1283 		case SID_DRAWTBX_CS_SYMBOL11:
1284 		case SID_DRAWTBX_CS_SYMBOL12:
1285 		case SID_DRAWTBX_CS_SYMBOL13:
1286 		case SID_DRAWTBX_CS_SYMBOL14:
1287 		case SID_DRAWTBX_CS_SYMBOL15:
1288 		case SID_DRAWTBX_CS_SYMBOL16:
1289 		case SID_DRAWTBX_CS_SYMBOL17:
1290 		case SID_DRAWTBX_CS_SYMBOL18:
1291 		case SID_DRAWTBX_CS_ARROW1:
1292 		case SID_DRAWTBX_CS_ARROW2:
1293 		case SID_DRAWTBX_CS_ARROW3:
1294 		case SID_DRAWTBX_CS_ARROW4:
1295 		case SID_DRAWTBX_CS_ARROW5:
1296 		case SID_DRAWTBX_CS_ARROW6:
1297 		case SID_DRAWTBX_CS_ARROW7:
1298 		case SID_DRAWTBX_CS_ARROW8:
1299 		case SID_DRAWTBX_CS_ARROW9:
1300 		case SID_DRAWTBX_CS_ARROW10:
1301 		case SID_DRAWTBX_CS_ARROW11:
1302 		case SID_DRAWTBX_CS_ARROW12:
1303 		case SID_DRAWTBX_CS_ARROW13:
1304 		case SID_DRAWTBX_CS_ARROW14:
1305 		case SID_DRAWTBX_CS_ARROW15:
1306 		case SID_DRAWTBX_CS_ARROW16:
1307 		case SID_DRAWTBX_CS_ARROW17:
1308 		case SID_DRAWTBX_CS_ARROW18:
1309 		case SID_DRAWTBX_CS_ARROW19:
1310 		case SID_DRAWTBX_CS_ARROW20:
1311 		case SID_DRAWTBX_CS_ARROW21:
1312 		case SID_DRAWTBX_CS_ARROW22:
1313 		case SID_DRAWTBX_CS_ARROW23:
1314 		case SID_DRAWTBX_CS_ARROW24:
1315 		case SID_DRAWTBX_CS_ARROW25:
1316 		case SID_DRAWTBX_CS_ARROW26:
1317 		case SID_DRAWTBX_CS_STAR1:
1318 		case SID_DRAWTBX_CS_STAR2:
1319 		case SID_DRAWTBX_CS_STAR3:
1320 		case SID_DRAWTBX_CS_STAR4:
1321 		case SID_DRAWTBX_CS_STAR5:
1322 		case SID_DRAWTBX_CS_STAR6:
1323 		case SID_DRAWTBX_CS_STAR7:
1324 		case SID_DRAWTBX_CS_STAR8:
1325 		case SID_DRAWTBX_CS_STAR9:
1326 		case SID_DRAWTBX_CS_STAR10:
1327 		case SID_DRAWTBX_CS_STAR11:
1328 		case SID_DRAWTBX_CS_STAR12:
1329 		case SID_DRAWTBX_CS_FLOWCHART1:
1330 		case SID_DRAWTBX_CS_FLOWCHART2:
1331 		case SID_DRAWTBX_CS_FLOWCHART3:
1332 		case SID_DRAWTBX_CS_FLOWCHART4:
1333 		case SID_DRAWTBX_CS_FLOWCHART5:
1334 		case SID_DRAWTBX_CS_FLOWCHART6:
1335 		case SID_DRAWTBX_CS_FLOWCHART7:
1336 		case SID_DRAWTBX_CS_FLOWCHART8:
1337 		case SID_DRAWTBX_CS_FLOWCHART9:
1338 		case SID_DRAWTBX_CS_FLOWCHART10:
1339 		case SID_DRAWTBX_CS_FLOWCHART11:
1340 		case SID_DRAWTBX_CS_FLOWCHART12:
1341 		case SID_DRAWTBX_CS_FLOWCHART13:
1342 		case SID_DRAWTBX_CS_FLOWCHART14:
1343 		case SID_DRAWTBX_CS_FLOWCHART15:
1344 		case SID_DRAWTBX_CS_FLOWCHART16:
1345 		case SID_DRAWTBX_CS_FLOWCHART17:
1346 		case SID_DRAWTBX_CS_FLOWCHART18:
1347 		case SID_DRAWTBX_CS_FLOWCHART19:
1348 		case SID_DRAWTBX_CS_FLOWCHART20:
1349 		case SID_DRAWTBX_CS_FLOWCHART21:
1350 		case SID_DRAWTBX_CS_FLOWCHART22:
1351 		case SID_DRAWTBX_CS_FLOWCHART23:
1352 		case SID_DRAWTBX_CS_FLOWCHART24:
1353 		case SID_DRAWTBX_CS_FLOWCHART25:
1354 		case SID_DRAWTBX_CS_FLOWCHART26:
1355 		case SID_DRAWTBX_CS_FLOWCHART27:
1356 		case SID_DRAWTBX_CS_FLOWCHART28:
1357 		case SID_DRAWTBX_CS_CALLOUT1:
1358 		case SID_DRAWTBX_CS_CALLOUT2:
1359 		case SID_DRAWTBX_CS_CALLOUT3:
1360 		case SID_DRAWTBX_CS_CALLOUT4:
1361 		case SID_DRAWTBX_CS_CALLOUT5:
1362 		case SID_DRAWTBX_CS_CALLOUT6:
1363 		case SID_DRAWTBX_CS_CALLOUT7:
1364         case SID_DRAWTBX_CS_SYMBOL:
1365         case SID_DRAWTBX_CS_ARROW:
1366         case SID_DRAWTBX_CS_FLOWCHART:
1367         case SID_DRAWTBX_CS_CALLOUT:
1368         case SID_DRAWTBX_CS_STAR:
1369             getDesignView()->SetMode( RPTUI_INSERT );
1370             {
1371                 URL aUrl = getURLForId(_nId);
1372                 sal_Int32 nIndex = 1;
1373                 ::rtl::OUString sType = aUrl.Complete.getToken(0,'.',nIndex);
1374                 if ( nIndex == -1 || !sType.getLength() )
1375                 {
1376                     switch(_nId)
1377                     {
1378                         case SID_DRAWTBX_CS_SYMBOL:
1379                             sType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("smiley"));
1380                             break;
1381                         case SID_DRAWTBX_CS_ARROW:
1382                             sType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("left-right-arrow"));
1383                             break;
1384                         case SID_DRAWTBX_CS_FLOWCHART:
1385                             sType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("flowchart-internal-storage"));
1386                             break;
1387                         case SID_DRAWTBX_CS_CALLOUT:
1388                             sType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("round-rectangular-callout"));
1389                             break;
1390                         case SID_DRAWTBX_CS_STAR:
1391                             sType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("star5"));
1392                             break;
1393                         case SID_DRAWTBX_CS_BASIC:
1394                         default:
1395                             sType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("diamond"));
1396                     }
1397                 }
1398                 else
1399                     sType = aUrl.Complete.getToken(0,'.',nIndex);
1400 
1401 			    getDesignView()->SetInsertObj( OBJ_CUSTOMSHAPE ,sType);
1402                 createDefaultControl(aArgs);
1403             }
1404             InvalidateAll();
1405             break;
1406         case SID_RPT_SHOWREPORTEXPLORER:
1407 			if ( isUiVisible() )
1408 	            getDesignView()->toggleReportExplorer();
1409             break;
1410 		case SID_FM_ADD_FIELD:
1411 			if ( isUiVisible() )
1412 				getDesignView()->toggleAddField();
1413 			break;
1414 		case SID_SHOW_PROPERTYBROWSER:
1415             if ( m_bShowProperties )
1416                 m_sLastActivePage = getDesignView()->getCurrentPage();
1417             else
1418                 getDesignView()->setCurrentPage(m_sLastActivePage);
1419 
1420 			if ( isUiVisible() )
1421 			{
1422 	            m_bShowProperties = !m_bShowProperties;
1423     	        if ( aArgs.getLength() == 1 )
1424         	        aArgs[0].Value >>= m_bShowProperties;
1425 
1426 				getDesignView()->togglePropertyBrowser(m_bShowProperties);
1427 			}
1428 			break;
1429         case SID_PROPERTYBROWSER_LAST_PAGE: // nothing to do
1430             m_sLastActivePage = getDesignView()->getCurrentPage();
1431             break;
1432         case SID_SPLIT_POSITION:
1433             getDesignView()->Resize();
1434             break;
1435 		case SID_PAGEDIALOG:
1436 		case SID_ATTR_CHAR_COLOR_BACKGROUND:
1437 			{
1438 				uno::Reference<report::XSection> xSection;
1439 				if (aArgs.getLength() == 1 )
1440 					aArgs[0].Value >>= xSection;
1441 				openPageDialog(xSection);
1442                 bForceBroadcast = sal_True;
1443 			}
1444 			break;
1445 		case SID_SORTINGANDGROUPING:
1446 			openSortingAndGroupingDialog();
1447             m_bGroupFloaterWasVisible = m_pGroupsFloater && m_pGroupsFloater->IsVisible();
1448 			break;
1449 		case SID_BACKGROUND_COLOR:
1450 			{
1451                 const util::Color aColor( lcl_extractBackgroundColor( aArgs ) );
1452                 if ( !impl_setPropertyAtControls_throw(RID_STR_UNDO_CHANGEFONT,PROPERTY_CONTROLBACKGROUND,uno::makeAny(aColor),aArgs) )
1453                 {
1454                     uno::Reference< report::XSection > xSection = getDesignView()->getCurrentSection();
1455                     if ( xSection.is() )
1456 		            {
1457 			            xSection->setBackColor( aColor );
1458 		            }
1459                 }
1460                 bForceBroadcast = sal_True;
1461 			}
1462 			break;
1463         case SID_ATTR_CHAR_WEIGHT:
1464 		case SID_ATTR_CHAR_POSTURE:
1465         case SID_ATTR_CHAR_UNDERLINE:
1466 			{
1467 				uno::Reference< awt::XWindow> xWindow;
1468                 ::std::vector< uno::Reference< uno::XInterface > > aControlsFormats;
1469                 lcl_getReportControlFormat( aArgs, getDesignView(), xWindow, aControlsFormats );
1470 
1471                 const String sUndoAction(ModuleRes(RID_STR_UNDO_CHANGEFONT));
1472                 UndoContext aUndoContext( getUndoManager(), sUndoAction );
1473 
1474                 ::std::vector< uno::Reference< uno::XInterface > >::iterator aIter = aControlsFormats.begin();
1475                 for(; aIter != aControlsFormats.end();++aIter)
1476                 {
1477                     uno::Reference< report::XReportControlFormat> xReportControlFormat(*aIter,uno::UNO_QUERY);
1478                     lcl_setFontWPU_nothrow(xReportControlFormat,_nId);
1479                 }
1480 			}
1481 			break;
1482 		case SID_ATTR_CHAR_COLOR:
1483 		case SID_ATTR_CHAR_COLOR2:
1484 			{
1485                 const SequenceAsHashMap aMap(aArgs);
1486                 const util::Color aColor = aMap.getUnpackedValueOrDefault(PROPERTY_FONTCOLOR,util::Color());
1487                 impl_setPropertyAtControls_throw(RID_STR_UNDO_CHANGEFONT,PROPERTY_CHARCOLOR,uno::makeAny(aColor),aArgs);
1488                 bForceBroadcast = sal_True;
1489 			}
1490 			break;
1491         case SID_ATTR_CHAR_FONT:
1492             if ( aArgs.getLength() == 1 )
1493             {
1494                 awt::FontDescriptor aFont;
1495                 if ( aArgs[0].Value >>= aFont )
1496                 {
1497                     impl_setPropertyAtControls_throw(RID_STR_UNDO_CHANGEFONT,PROPERTY_CHARFONTNAME,uno::makeAny(aFont.Name),aArgs);
1498                 } // if ( aArgs[0].Value >>= aFont )
1499             }
1500             break;
1501         case SID_ATTR_CHAR_FONTHEIGHT:
1502             if ( aArgs.getLength() == 1 )
1503             {
1504                 float fSelVal = 0.0;
1505                 if ( aArgs[0].Value >>= fSelVal )
1506                     impl_setPropertyAtControls_throw(RID_STR_UNDO_CHANGEFONT,PROPERTY_CHARHEIGHT,aArgs[0].Value,aArgs);
1507             }
1508             break;
1509         case SID_ATTR_PARA_ADJUST_LEFT:
1510         case SID_ATTR_PARA_ADJUST_CENTER:
1511         case SID_ATTR_PARA_ADJUST_RIGHT:
1512         case SID_ATTR_PARA_ADJUST_BLOCK:
1513             {
1514                 sal_Int16 eParagraphAdjust = style::ParagraphAdjust_LEFT;
1515                 switch(_nId)
1516                 {
1517                     case SID_ATTR_PARA_ADJUST_LEFT:
1518                         eParagraphAdjust = style::ParagraphAdjust_LEFT;
1519                         break;
1520                     case SID_ATTR_PARA_ADJUST_CENTER:
1521                         eParagraphAdjust = style::ParagraphAdjust_CENTER;
1522                         break;
1523                     case SID_ATTR_PARA_ADJUST_RIGHT:
1524                         eParagraphAdjust = style::ParagraphAdjust_RIGHT;
1525                         break;
1526                     case SID_ATTR_PARA_ADJUST_BLOCK:
1527                         eParagraphAdjust = style::ParagraphAdjust_BLOCK;
1528                         break;
1529                 } // switch(_nId)
1530                 impl_setPropertyAtControls_throw(RID_STR_UNDO_ALIGNMENT,PROPERTY_PARAADJUST,uno::makeAny(eParagraphAdjust),aArgs);
1531 
1532                 InvalidateFeature(SID_ATTR_PARA_ADJUST_LEFT);
1533                 InvalidateFeature(SID_ATTR_PARA_ADJUST_CENTER);
1534                 InvalidateFeature(SID_ATTR_PARA_ADJUST_RIGHT);
1535                 InvalidateFeature(SID_ATTR_PARA_ADJUST_BLOCK);
1536             }
1537             break;
1538 		case SID_CHAR_DLG:
1539 			{
1540                 uno::Sequence< beans::NamedValue > aSettings;
1541 				uno::Reference< awt::XWindow> xWindow;
1542                 ::std::vector< uno::Reference< uno::XInterface > > aControlsFormats;
1543                 lcl_getReportControlFormat( aArgs, getDesignView(), xWindow, aControlsFormats );
1544 
1545                 if ( !aControlsFormats.empty() )
1546                 {
1547                     const String sUndoAction( ModuleRes( RID_STR_UNDO_CHANGEFONT ) );
1548                     UndoContext aUndoContext( getUndoManager(), sUndoAction );
1549 
1550                     ::std::vector< uno::Reference< uno::XInterface > >::iterator aIter = aControlsFormats.begin();
1551                     for(; aIter != aControlsFormats.end();++aIter)
1552                     {
1553                         uno::Reference< report::XReportControlFormat > xFormat( *aIter, uno::UNO_QUERY );
1554 				        if ( !xFormat.is() )
1555                             continue;
1556 
1557                         if ( aSettings.getLength() == 0 )
1558                         {
1559                             ::rptui::openCharDialog( xFormat, xWindow, aSettings );
1560                             if ( aSettings.getLength() == 0 )
1561                                 break;
1562                         }
1563 
1564                         applyCharacterSettings( xFormat, aSettings );
1565                     }
1566 
1567                     InvalidateAll();
1568                 }
1569 			}
1570 			break;
1571 		case SID_INSERT_GRAPHIC:
1572             insertGraphic();
1573             break;
1574 		case SID_SETCONTROLDEFAULTS:
1575 			break;
1576 		case SID_CONDITIONALFORMATTING:
1577 			{
1578 				uno::Reference< report::XFormattedField> xFormattedField(getDesignView()->getCurrentControlModel(),uno::UNO_QUERY);
1579 				if ( xFormattedField.is() )
1580 				{
1581 					ConditionalFormattingDialog aDlg( getView(), xFormattedField.get(), *this );
1582 					aDlg.Execute();
1583 				}
1584 			}
1585 			break;
1586 		case SID_DATETIME:
1587 			if ( m_xReportDefinition.is() )
1588 			{
1589                 if ( !aArgs.getLength() )
1590                 {
1591 				    ODateTimeDialog aDlg(getView(),getDesignView()->getCurrentSection(),this);
1592 				    aDlg.Execute();
1593                 }
1594                 else
1595                     createDateTime(aArgs);
1596 			} // if ( m_xReportDefinition.is() )
1597 			break;
1598 		case SID_INSERT_FLD_PGNUMBER:
1599 			if ( m_xReportDefinition.is() )
1600 			{
1601                 if ( !aArgs.getLength() )
1602                 {
1603 				    OPageNumberDialog aDlg(getView(),m_xReportDefinition,this);
1604 				    aDlg.Execute();
1605                 }
1606                 else
1607                     createPageNumber(aArgs);
1608 			} // if ( m_xReportDefinition.is() )
1609 			break;
1610 		case SID_EXPORTDOC:
1611 		case SID_EXPORTDOCASPDF:
1612 			break;
1613 		case SID_PRINTPREVIEW:
1614 			if ( m_xReportDefinition.is() )
1615 			{
1616 			}
1617 			break;
1618 		case SID_EDITDOC:
1619 			if(isEditable())
1620 			{ // the state should be changed to not editable
1621 				switch (saveModified())
1622 				{
1623 					case RET_CANCEL:
1624 						// don't change anything here so return
1625 						return;
1626 					case RET_NO:
1627 						setModified(sal_False);		// and we are not modified yet
1628 						break;
1629 					default:
1630 						break;
1631 				}
1632 			}
1633 			setEditable(!isEditable());
1634 			//getJoinView()->setReadOnly(!isEditable());
1635 			InvalidateAll();
1636 			return;
1637         case SID_GROUP:
1638             break;
1639         case SID_ATTR_ZOOM:
1640             if ( aArgs.getLength() == 0 )
1641             {
1642                 openZoomDialog();
1643             }
1644             else if ( aArgs.getLength() == 1 && aArgs[0].Name.equalsAscii("Zoom") )
1645             {
1646                 SvxZoomItem aZoomItem;
1647                 aZoomItem.PutValue(aArgs[0].Value);
1648                 m_nZoomValue = aZoomItem.GetValue();
1649                 m_eZoomType = aZoomItem.GetType();
1650                 impl_zoom_nothrow();
1651             } // if ( aArgs.getLength() == 1 && aArgs[0].Name.equalsAscii("Zoom") )
1652             break;
1653         case SID_ATTR_ZOOMSLIDER:
1654             if ( aArgs.getLength() == 1 && aArgs[0].Name.equalsAscii("ZoomSlider") )
1655             {
1656                 SvxZoomSliderItem aZoomSlider;
1657                 aZoomSlider.PutValue(aArgs[0].Value);
1658                 m_nZoomValue = aZoomSlider.GetValue();
1659                 m_eZoomType = SVX_ZOOM_PERCENT;
1660                 impl_zoom_nothrow();
1661             }
1662 			break;
1663 		default:
1664 			OReportController_BASE::Execute(_nId,aArgs);
1665 	}
1666 	InvalidateFeature(_nId,Reference< XStatusListener >(),bForceBroadcast);
1667 }
1668 // -----------------------------------------------------------------------------
1669 short OReportController::saveModified()
1670 {
1671 	return RET_NO;
1672 }
1673 
1674 // -----------------------------------------------------------------------------
1675 void OReportController::impl_initialize( )
1676 {
1677     OReportController_BASE::impl_initialize();
1678 
1679     const ::comphelper::NamedValueCollection& rArguments( getInitParams() );
1680 
1681     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_REPORTNAME, m_sName );
1682     if ( !m_sName.getLength() )
1683         rArguments.get_ensureType( "DocumentTitle", m_sName );
1684 
1685 	try
1686 	{
1687 		if ( m_xReportDefinition.is() )
1688 		{
1689 			//m_sName = m_xReportDefinition->getName();
1690 			getView()->initialize();	// show the windows and fill with our informations
1691 
1692             m_aReportModel = reportdesign::OReportDefinition::getSdrModel(m_xReportDefinition);
1693             if ( !m_aReportModel )
1694                 throw RuntimeException();
1695             m_aReportModel->attachController( *this );
1696 
1697 		    clearUndoManager();
1698             UndoSuppressor aSuppressUndo( getUndoManager() );
1699 
1700             ::comphelper::NamedValueCollection aArgs(getModel()->getArgs());
1701             setMode(aArgs.getOrDefault("Mode", rtl::OUString::createFromAscii("normal")));
1702 
1703             listen(true);
1704             setEditable( !m_aReportModel->IsReadOnly() );
1705             m_xFormatter.set(getORB()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY);
1706             m_xFormatter->attachNumberFormatsSupplier(Reference< XNumberFormatsSupplier>(m_xReportDefinition,uno::UNO_QUERY));
1707 
1708             ::comphelper::MediaDescriptor aDescriptor( m_xReportDefinition->getArgs() );
1709             ::rtl::OUString sHierarchicalDocumentName;
1710             sHierarchicalDocumentName = aDescriptor.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HierarchicalDocumentName")),sHierarchicalDocumentName);
1711 
1712             if ( !sHierarchicalDocumentName.getLength() && getConnection().is() )
1713             {
1714                 uno::Reference<sdbcx::XTablesSupplier> xTablesSup(getConnection(),uno::UNO_QUERY_THROW);
1715                 uno::Reference<container::XNameAccess> xTables = xTablesSup->getTables();
1716                 const uno::Sequence< ::rtl::OUString > aNames( xTables->getElementNames() );
1717 
1718                 if ( aNames.hasElements() )
1719                 {
1720                     m_xReportDefinition->setCommand(aNames[0]);
1721                     m_xReportDefinition->setCommandType(sdb::CommandType::TABLE);
1722                 }
1723             } // if ( !sHierarchicalDocumentName.getLength() && getConnection().is() )
1724 
1725             m_aVisualAreaSize = m_xReportDefinition->getVisualAreaSize(0);
1726 
1727 		} // if ( m_xReportDefinition.is() )
1728 
1729         // check if chart is supported by the engine
1730         checkChartEnabled();
1731         // restore the view data
1732         getDesignView()->toggleGrid(m_bGridVisible);
1733         getDesignView()->showRuler(m_bShowRuler);
1734         getDesignView()->togglePropertyBrowser(m_bShowProperties);
1735         getDesignView()->setCurrentPage(m_sLastActivePage);
1736         getDesignView()->unmarkAllObjects(NULL);
1737 
1738         if ( m_nPageNum != -1 )
1739         {
1740             if ( m_nPageNum < m_aReportModel->GetPageCount() )
1741             {
1742                 const OReportPage* pPage = dynamic_cast<OReportPage*>(m_aReportModel->GetPage(static_cast<sal_uInt16>(m_nPageNum)));
1743                 if ( pPage )
1744                 {
1745                     uno::Sequence< beans::PropertyValue> aArgs(1);
1746                     aArgs[0].Value <<= pPage->getSection();
1747                     executeUnChecked(SID_SELECT,aArgs);
1748                 }
1749             }
1750             else
1751                 m_nPageNum = -1;
1752         }
1753         getDesignView()->collapseSections(m_aCollapsedSections);
1754         impl_zoom_nothrow();
1755         getDesignView()->Resize();
1756         getDesignView()->Invalidate();
1757         InvalidateAll();
1758 
1759         if ( m_bShowProperties && m_nPageNum == -1 )
1760         {
1761             m_sLastActivePage = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Data"));
1762             getDesignView()->setCurrentPage(m_sLastActivePage);
1763             uno::Sequence< beans::PropertyValue> aArgs;
1764             executeUnChecked(SID_SELECT_REPORT,aArgs);
1765         } // if ( m_bShowProperties && m_nPageNum == -1 )
1766 
1767 		setModified(sal_False);		// and we are not modified yet
1768 
1769 		// open the global help agent
1770 		// we need a Frame but at this time there is no frame, therefore we send a UserEvent
1771 		getView()->PostUserEvent(LINK(this, OReportController, OnOpenHelpAgent));
1772 	}
1773 	catch(const SQLException&)
1774 	{
1775         DBG_UNHANDLED_EXCEPTION();
1776 	}
1777 }
1778 // -----------------------------------------------------------------------------
1779 IMPL_LINK( OReportController, OnOpenHelpAgent, void* ,/*_pMemfun*/)
1780 {
1781     //m_nExecuteReportEvent = 0;
1782     doOpenHelpAgent();
1783     return 0L;
1784 }
1785 // -----------------------------------------------------------------------------
1786 IMPL_LINK( OReportController, OnCreateHdl, OAddFieldWindow* ,_pAddFieldDlg)
1787 {
1788     WaitObject aObj( getDesignView() );
1789     uno::Sequence< beans::PropertyValue > aArgs = _pAddFieldDlg->getSelectedFieldDescriptors();
1790     // we use this way to create undo actions
1791     if ( aArgs.getLength() )
1792     {
1793         executeChecked(SID_ADD_CONTROL_PAIR,aArgs);
1794     }
1795     return 0L;
1796 }
1797 // -----------------------------------------------------------------------------
1798 
1799 void OReportController::doOpenHelpAgent()
1800 {
1801 	if (getFrame().is())
1802 	{
1803 		rtl::OUString suURL = rtl::OUString::createFromAscii("vnd.sun.star.help://shared/text/shared/explorer/database/rep_main.xhp?UseDB=no&DbPAR=swriter");
1804 		openHelpAgent(suURL);
1805 		// openHelpAgent(68245 /* HID_REPORT_DESIGN... UNKNOWN */ );
1806 		// HID_APP_REPORT_TREE
1807 	}
1808 	else
1809 	{
1810         // as long as we don't get a Frame, we send the user event again.
1811 		getView()->PostUserEvent(LINK(this, OReportController, OnOpenHelpAgent));
1812 	}
1813 }
1814 // -----------------------------------------------------------------------------
1815 sal_Bool OReportController::Construct(Window* pParent)
1816 {
1817 	ODesignView* pMyOwnView = new ODesignView( pParent, getORB(), *this );
1818 	StartListening( *pMyOwnView );
1819     setView( *pMyOwnView );
1820 
1821 	// now that we have a view we can create the clipboard listener
1822 	m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
1823 	m_aSystemClipboard.StartClipboardListening( );
1824 	m_pClipbordNotifier = new TransferableClipboardListener( LINK( this, OReportController, OnClipboardChanged ) );
1825 	m_pClipbordNotifier->acquire();
1826 	m_pClipbordNotifier->AddRemoveListener( getView(), sal_True );
1827 
1828 	OReportController_BASE::Construct(pParent);
1829 	//getView()->Show();
1830 	return sal_True;
1831 }
1832 // -----------------------------------------------------------------------------
1833 sal_Bool SAL_CALL OReportController::suspend(sal_Bool /*_bSuspend*/) throw( RuntimeException )
1834 {
1835 	if ( getBroadcastHelper().bInDispose || getBroadcastHelper().bDisposed )
1836 		return sal_True;
1837 
1838 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1839 	::osl::MutexGuard aGuard( getMutex() );
1840 
1841     if ( getView() && getView()->IsInModalMode() )
1842         return sal_False;
1843 
1844     // this suspend will be handled in the DBAccess interceptor implementation
1845 	return sal_True;
1846 }
1847 // -----------------------------------------------------------------------------
1848 void OReportController::describeSupportedFeatures()
1849 {
1850 	DBSubComponentController::describeSupportedFeatures();
1851 
1852     implDescribeSupportedFeature( ".uno:TextDocument",          	SID_RPT_TEXTDOCUMENT,           CommandGroup::APPLICATION );
1853     implDescribeSupportedFeature( ".uno:Spreadsheet",          		SID_RPT_SPREADSHEET,   			CommandGroup::APPLICATION );
1854 
1855     implDescribeSupportedFeature( ".uno:Redo",          			SID_REDO,        				CommandGroup::EDIT );
1856 	implDescribeSupportedFeature( ".uno:Undo",          			SID_UNDO,		 				CommandGroup::EDIT );
1857 	//implDescribeSupportedFeature( ".uno:PasteSpecial",			  SID_PASTE,					CommandGroup::EDIT );
1858 	implDescribeSupportedFeature( ".uno:SelectAll",					SID_SELECTALL,					CommandGroup::EDIT );
1859     implDescribeSupportedFeature( ".uno:SelectAllInSection",		SID_SELECTALL_IN_SECTION,		CommandGroup::EDIT );
1860 	implDescribeSupportedFeature( ".uno:Delete",					SID_DELETE,						CommandGroup::EDIT );
1861 	implDescribeSupportedFeature( ".uno:SelectReport",				SID_SELECT_REPORT,				CommandGroup::EDIT );
1862     implDescribeSupportedFeature( ".uno:ExecuteReport",				SID_EXECUTE_REPORT,				CommandGroup::EDIT );
1863 
1864 	implDescribeSupportedFeature( ".uno:GridVisible",				SID_GRID_VISIBLE,				CommandGroup::VIEW );
1865 	implDescribeSupportedFeature( ".uno:GridUse",    				SID_GRID_USE,   				CommandGroup::VIEW );
1866     implDescribeSupportedFeature( ".uno:HelplinesMove", 			SID_HELPLINES_MOVE, 			CommandGroup::VIEW );
1867 	implDescribeSupportedFeature( ".uno:ShowRuler",					SID_RULER,						CommandGroup::VIEW );
1868 	implDescribeSupportedFeature( ".uno:AddField",					SID_FM_ADD_FIELD,				CommandGroup::VIEW );
1869     implDescribeSupportedFeature( ".uno:ReportNavigator",		    SID_RPT_SHOWREPORTEXPLORER,	    CommandGroup::VIEW );
1870 	implDescribeSupportedFeature( ".uno:ControlProperties",			SID_SHOW_PROPERTYBROWSER,		CommandGroup::VIEW );
1871 	//implDescribeSupportedFeature( ".uno:SwitchControlDesignMode",	SID_FM_DESIGN_MODE,				CommandGroup::VIEW );
1872 	implDescribeSupportedFeature( ".uno:DbSortingAndGrouping",		SID_SORTINGANDGROUPING,			CommandGroup::VIEW );
1873 	implDescribeSupportedFeature( ".uno:PageHeaderFooter",			SID_PAGEHEADERFOOTER,			CommandGroup::VIEW );
1874 	implDescribeSupportedFeature( ".uno:ReportHeaderFooter",		SID_REPORTHEADERFOOTER,			CommandGroup::VIEW );
1875     implDescribeSupportedFeature( ".uno:ZoomSlider",		        SID_ATTR_ZOOMSLIDER,			CommandGroup::VIEW );
1876     implDescribeSupportedFeature( ".uno:Zoom",		                SID_ATTR_ZOOM,			        CommandGroup::VIEW );
1877 	//implDescribeSupportedFeature( ".uno:SwitchControlDesignMode",	SID_FM_DESIGN_MODE,				CommandGroup::VIEW );
1878 
1879 	implDescribeSupportedFeature( ".uno:ConditionalFormatting",		SID_CONDITIONALFORMATTING,		CommandGroup::FORMAT );
1880 	implDescribeSupportedFeature( ".uno:PageDialog",				SID_PAGEDIALOG,					CommandGroup::FORMAT );
1881 	implDescribeSupportedFeature( ".uno:ResetAttributes",		    SID_SETCONTROLDEFAULTS,			CommandGroup::FORMAT );
1882 
1883 	implDescribeSupportedFeature( ".uno:Bold",						SID_ATTR_CHAR_WEIGHT,			CommandGroup::FORMAT );
1884 	implDescribeSupportedFeature( ".uno:Italic",					SID_ATTR_CHAR_POSTURE,			CommandGroup::FORMAT );
1885 	implDescribeSupportedFeature( ".uno:Underline",					SID_ATTR_CHAR_UNDERLINE,		CommandGroup::FORMAT );
1886 	implDescribeSupportedFeature( ".uno:BackColor",					SID_ATTR_CHAR_COLOR_BACKGROUND,	CommandGroup::FORMAT );
1887 	implDescribeSupportedFeature( ".uno:BackgroundColor",			SID_BACKGROUND_COLOR,			CommandGroup::FORMAT );
1888 	implDescribeSupportedFeature( ".uno:Color",						SID_ATTR_CHAR_COLOR);
1889 	implDescribeSupportedFeature( ".uno:FontColor",					SID_ATTR_CHAR_COLOR2,			CommandGroup::FORMAT );
1890 	implDescribeSupportedFeature( ".uno:FontDialog",				SID_CHAR_DLG,					CommandGroup::FORMAT );
1891     implDescribeSupportedFeature( ".uno:LeftPara",				    SID_ATTR_PARA_ADJUST_LEFT,      CommandGroup::FORMAT );
1892     implDescribeSupportedFeature( ".uno:CenterPara",				SID_ATTR_PARA_ADJUST_CENTER,	CommandGroup::FORMAT );
1893     implDescribeSupportedFeature( ".uno:RightPara",				    SID_ATTR_PARA_ADJUST_RIGHT,		CommandGroup::FORMAT );
1894     implDescribeSupportedFeature( ".uno:JustifyPara",				SID_ATTR_PARA_ADJUST_BLOCK,		CommandGroup::FORMAT );
1895 
1896     implDescribeSupportedFeature( ".uno:FontHeight",				SID_ATTR_CHAR_FONTHEIGHT,		CommandGroup::FORMAT );
1897     implDescribeSupportedFeature( ".uno:CharFontName",				SID_ATTR_CHAR_FONT,		        CommandGroup::FORMAT );
1898 
1899     implDescribeSupportedFeature( ".uno:ArrangeMenu",			    SID_ARRANGEMENU,			    CommandGroup::FORMAT );
1900     implDescribeSupportedFeature( ".uno:BringToFront",			    SID_FRAME_TO_TOP,			    CommandGroup::FORMAT );
1901     implDescribeSupportedFeature( ".uno:ObjectBackOne",				SID_FRAME_DOWN,		            CommandGroup::FORMAT );
1902     implDescribeSupportedFeature( ".uno:ObjectForwardOne",			SID_FRAME_UP,			        CommandGroup::FORMAT );
1903     implDescribeSupportedFeature( ".uno:SendToBack",				SID_FRAME_TO_BOTTOM,			CommandGroup::FORMAT );
1904     implDescribeSupportedFeature( ".uno:SetObjectToForeground",		SID_OBJECT_HEAVEN,			    CommandGroup::FORMAT );
1905     implDescribeSupportedFeature( ".uno:SetObjectToBackground",		SID_OBJECT_HELL,			    CommandGroup::FORMAT );
1906 
1907     implDescribeSupportedFeature( ".uno:ObjectAlign",			    SID_OBJECT_ALIGN,			    CommandGroup::FORMAT );
1908     implDescribeSupportedFeature( ".uno:ObjectAlignLeft",			SID_OBJECT_ALIGN_LEFT,			CommandGroup::FORMAT );
1909     implDescribeSupportedFeature( ".uno:AlignCenter",				SID_OBJECT_ALIGN_CENTER,		CommandGroup::FORMAT );
1910     implDescribeSupportedFeature( ".uno:ObjectAlignRight",			SID_OBJECT_ALIGN_RIGHT,			CommandGroup::FORMAT );
1911     implDescribeSupportedFeature( ".uno:AlignUp",				    SID_OBJECT_ALIGN_UP,			CommandGroup::FORMAT );
1912     implDescribeSupportedFeature( ".uno:AlignMiddle",				SID_OBJECT_ALIGN_MIDDLE,		CommandGroup::FORMAT );
1913     implDescribeSupportedFeature( ".uno:AlignDown",			    	SID_OBJECT_ALIGN_DOWN,			CommandGroup::FORMAT );
1914 
1915     implDescribeSupportedFeature( ".uno:SectionAlign",			    SID_SECTION_ALIGN,			    CommandGroup::FORMAT );
1916     implDescribeSupportedFeature( ".uno:SectionAlignLeft",			SID_SECTION_ALIGN_LEFT,			CommandGroup::FORMAT );
1917     implDescribeSupportedFeature( ".uno:SectionAlignCenter",		SID_SECTION_ALIGN_CENTER,		CommandGroup::FORMAT );
1918     implDescribeSupportedFeature( ".uno:SectionAlignRight",			SID_SECTION_ALIGN_RIGHT,		CommandGroup::FORMAT );
1919     implDescribeSupportedFeature( ".uno:SectionAlignTop",			SID_SECTION_ALIGN_UP,			CommandGroup::FORMAT );
1920     implDescribeSupportedFeature( ".uno:SectionAlignMiddle",		SID_SECTION_ALIGN_MIDDLE,		CommandGroup::FORMAT );
1921     implDescribeSupportedFeature( ".uno:SectionAlignBottom",		SID_SECTION_ALIGN_DOWN,			CommandGroup::FORMAT );
1922     implDescribeSupportedFeature( ".uno:SectionShrink",             SID_SECTION_SHRINK,             CommandGroup::FORMAT );
1923     implDescribeSupportedFeature( ".uno:SectionShrinkTop",          SID_SECTION_SHRINK_TOP,         CommandGroup::FORMAT );
1924     implDescribeSupportedFeature( ".uno:SectionShrinkBottom",       SID_SECTION_SHRINK_BOTTOM,      CommandGroup::FORMAT );
1925 
1926     implDescribeSupportedFeature( ".uno:ObjectResize",			    SID_OBJECT_RESIZING,		    CommandGroup::FORMAT );
1927     implDescribeSupportedFeature( ".uno:SmallestWidth",			    SID_OBJECT_SMALLESTWIDTH,		CommandGroup::FORMAT );
1928     implDescribeSupportedFeature( ".uno:SmallestHeight",			SID_OBJECT_SMALLESTHEIGHT,		CommandGroup::FORMAT );
1929     implDescribeSupportedFeature( ".uno:GreatestWidth",			    SID_OBJECT_GREATESTWIDTH,		CommandGroup::FORMAT );
1930     implDescribeSupportedFeature( ".uno:GreatestHeight",			SID_OBJECT_GREATESTHEIGHT,		CommandGroup::FORMAT );
1931     implDescribeSupportedFeature( ".uno:Distribution",		        SID_DISTRIBUTION,		        CommandGroup::FORMAT );
1932 
1933 	implDescribeSupportedFeature( ".uno:HelpMenu",      			SID_HELPMENU,					CommandGroup::APPLICATION );
1934 	implDescribeSupportedFeature( ".uno:ExportTo",      			SID_EXPORTDOC,					CommandGroup::APPLICATION );
1935 	implDescribeSupportedFeature( ".uno:ExportToPDF",   			SID_EXPORTDOCASPDF,				CommandGroup::APPLICATION );
1936 	implDescribeSupportedFeature( ".uno:PrintPreview",  			SID_PRINTPREVIEW,				CommandGroup::APPLICATION );
1937 
1938 	implDescribeSupportedFeature( ".uno:NewDoc",        			SID_NEWDOC,      				CommandGroup::DOCUMENT );
1939 	implDescribeSupportedFeature( ".uno:Save",          			SID_SAVEDOC,					CommandGroup::DOCUMENT );
1940 	implDescribeSupportedFeature( ".uno:SaveAs",        			SID_SAVEASDOC,   				CommandGroup::DOCUMENT );
1941 
1942     implDescribeSupportedFeature( ".uno:InsertPageNumberField",		SID_INSERT_FLD_PGNUMBER,		CommandGroup::INSERT );
1943 	implDescribeSupportedFeature( ".uno:InsertDateTimeField",		SID_DATETIME,					CommandGroup::INSERT );
1944 	implDescribeSupportedFeature( ".uno:InsertObjectChart",			SID_INSERT_DIAGRAM,				CommandGroup::INSERT );
1945 	implDescribeSupportedFeature( ".uno:InsertGraphic",				SID_INSERT_GRAPHIC,				CommandGroup::INSERT );
1946 	// controls
1947 	implDescribeSupportedFeature( ".uno:SelectObject",				SID_OBJECT_SELECT,				CommandGroup::INSERT );
1948 	implDescribeSupportedFeature( ".uno:Label",						SID_FM_FIXEDTEXT,				CommandGroup::INSERT );
1949 	implDescribeSupportedFeature( ".uno:Edit",						SID_FM_EDIT,					CommandGroup::INSERT );
1950 	implDescribeSupportedFeature( ".uno:ImageControl",				SID_FM_IMAGECONTROL,			CommandGroup::INSERT );
1951     implDescribeSupportedFeature( ".uno:HFixedLine",			    SID_INSERT_HFIXEDLINE,			CommandGroup::INSERT );
1952     implDescribeSupportedFeature( ".uno:VFixedLine",			    SID_INSERT_VFIXEDLINE,			CommandGroup::INSERT );
1953 
1954     // shapes
1955     implDescribeSupportedFeature( ".uno:BasicShapes",				SID_DRAWTBX_CS_BASIC,			CommandGroup::INSERT );
1956     implDescribeSupportedFeature( ".uno:BasicShapes.rectangle",     SID_DRAWTBX_CS_BASIC1,			CommandGroup::INSERT );
1957     implDescribeSupportedFeature( ".uno:BasicShapes.round-rectangle",SID_DRAWTBX_CS_BASIC2,			CommandGroup::INSERT );
1958     implDescribeSupportedFeature( ".uno:BasicShapes.quadrat",       SID_DRAWTBX_CS_BASIC3,			CommandGroup::INSERT );
1959     implDescribeSupportedFeature( ".uno:BasicShapes.round-quadrat", SID_DRAWTBX_CS_BASIC4,			CommandGroup::INSERT );
1960     implDescribeSupportedFeature( ".uno:BasicShapes.circle",        SID_DRAWTBX_CS_BASIC5,			CommandGroup::INSERT );
1961     implDescribeSupportedFeature( ".uno:BasicShapes.ellipse",       SID_DRAWTBX_CS_BASIC6,			CommandGroup::INSERT );
1962     implDescribeSupportedFeature( ".uno:BasicShapes.circle-pie",    SID_DRAWTBX_CS_BASIC7,			CommandGroup::INSERT );
1963     implDescribeSupportedFeature( ".uno:BasicShapes.isosceles-triangle",SID_DRAWTBX_CS_BASIC8,		CommandGroup::INSERT );
1964     implDescribeSupportedFeature( ".uno:BasicShapes.right-triangle",SID_DRAWTBX_CS_BASIC9,			CommandGroup::INSERT );
1965     implDescribeSupportedFeature( ".uno:BasicShapes.trapezoid",     SID_DRAWTBX_CS_BASIC10,			CommandGroup::INSERT );
1966     implDescribeSupportedFeature( ".uno:BasicShapes.diamond",       SID_DRAWTBX_CS_BASIC11,			CommandGroup::INSERT );
1967     implDescribeSupportedFeature( ".uno:BasicShapes.parallelogram", SID_DRAWTBX_CS_BASIC12,			CommandGroup::INSERT );
1968     implDescribeSupportedFeature( ".uno:BasicShapes.pentagon",      SID_DRAWTBX_CS_BASIC13,			CommandGroup::INSERT );
1969     implDescribeSupportedFeature( ".uno:BasicShapes.hexagon",       SID_DRAWTBX_CS_BASIC14,			CommandGroup::INSERT );
1970     implDescribeSupportedFeature( ".uno:BasicShapes.octagon",       SID_DRAWTBX_CS_BASIC15,			CommandGroup::INSERT );
1971     implDescribeSupportedFeature( ".uno:BasicShapes.cross",         SID_DRAWTBX_CS_BASIC16,			CommandGroup::INSERT );
1972     implDescribeSupportedFeature( ".uno:BasicShapes.ring",          SID_DRAWTBX_CS_BASIC17,			CommandGroup::INSERT );
1973     implDescribeSupportedFeature( ".uno:BasicShapes.block-arc",     SID_DRAWTBX_CS_BASIC18,			CommandGroup::INSERT );
1974     implDescribeSupportedFeature( ".uno:BasicShapes.can",           SID_DRAWTBX_CS_BASIC19,			CommandGroup::INSERT );
1975     implDescribeSupportedFeature( ".uno:BasicShapes.cube",          SID_DRAWTBX_CS_BASIC20,			CommandGroup::INSERT );
1976     implDescribeSupportedFeature( ".uno:BasicShapes.paper",         SID_DRAWTBX_CS_BASIC21,			CommandGroup::INSERT );
1977     implDescribeSupportedFeature( ".uno:BasicShapes.frame",         SID_DRAWTBX_CS_BASIC22,			CommandGroup::INSERT );
1978 
1979     implDescribeSupportedFeature( ".uno:SymbolShapes",				SID_DRAWTBX_CS_SYMBOL,			CommandGroup::INSERT );
1980 
1981     implDescribeSupportedFeature( ".uno:SymbolShapes.smiley" ,		SID_DRAWTBX_CS_SYMBOL1,			CommandGroup::INSERT );
1982     implDescribeSupportedFeature( ".uno:SymbolShapes.sun" ,			SID_DRAWTBX_CS_SYMBOL2,			CommandGroup::INSERT );
1983     implDescribeSupportedFeature( ".uno:SymbolShapes.moon" ,		SID_DRAWTBX_CS_SYMBOL3,			CommandGroup::INSERT );
1984     implDescribeSupportedFeature( ".uno:SymbolShapes.lightning" ,	SID_DRAWTBX_CS_SYMBOL4,			CommandGroup::INSERT );
1985     implDescribeSupportedFeature( ".uno:SymbolShapes.heart" ,		SID_DRAWTBX_CS_SYMBOL5,			CommandGroup::INSERT );
1986     implDescribeSupportedFeature( ".uno:SymbolShapes.flower" ,		SID_DRAWTBX_CS_SYMBOL6,			CommandGroup::INSERT );
1987     implDescribeSupportedFeature( ".uno:SymbolShapes.cloud" ,		SID_DRAWTBX_CS_SYMBOL7,			CommandGroup::INSERT );
1988     implDescribeSupportedFeature( ".uno:SymbolShapes.forbidden" ,	SID_DRAWTBX_CS_SYMBOL8,			CommandGroup::INSERT );
1989     implDescribeSupportedFeature( ".uno:SymbolShapes.puzzle" ,		SID_DRAWTBX_CS_SYMBOL9,			CommandGroup::INSERT );
1990     implDescribeSupportedFeature( ".uno:SymbolShapes.bracket-pair" ,SID_DRAWTBX_CS_SYMBOL10,		CommandGroup::INSERT );
1991     implDescribeSupportedFeature( ".uno:SymbolShapes.left-bracket" ,SID_DRAWTBX_CS_SYMBOL11,		CommandGroup::INSERT );
1992     implDescribeSupportedFeature( ".uno:SymbolShapes.right-bracket",SID_DRAWTBX_CS_SYMBOL12,		CommandGroup::INSERT );
1993     implDescribeSupportedFeature( ".uno:SymbolShapes.brace-pair" ,	SID_DRAWTBX_CS_SYMBOL13,		CommandGroup::INSERT );
1994     implDescribeSupportedFeature( ".uno:SymbolShapes.left-brace" ,	SID_DRAWTBX_CS_SYMBOL14,		CommandGroup::INSERT );
1995     implDescribeSupportedFeature( ".uno:SymbolShapes.right-brace" ,	SID_DRAWTBX_CS_SYMBOL15,		CommandGroup::INSERT );
1996     implDescribeSupportedFeature( ".uno:SymbolShapes.quad-bevel" ,	SID_DRAWTBX_CS_SYMBOL16,		CommandGroup::INSERT );
1997     implDescribeSupportedFeature( ".uno:SymbolShapes.octagon-bevel",SID_DRAWTBX_CS_SYMBOL17,		CommandGroup::INSERT );
1998     implDescribeSupportedFeature( ".uno:SymbolShapes.diamond-bevel",SID_DRAWTBX_CS_SYMBOL18,		CommandGroup::INSERT );
1999 
2000     implDescribeSupportedFeature( ".uno:ArrowShapes.left-arrow" ,	        SID_DRAWTBX_CS_ARROW1,	CommandGroup::INSERT );
2001     implDescribeSupportedFeature( ".uno:ArrowShapes.right-arrow" ,	        SID_DRAWTBX_CS_ARROW2,	CommandGroup::INSERT );
2002     implDescribeSupportedFeature( ".uno:ArrowShapes.up-arrow" ,		        SID_DRAWTBX_CS_ARROW3,	CommandGroup::INSERT );
2003     implDescribeSupportedFeature( ".uno:ArrowShapes.down-arrow" ,	        SID_DRAWTBX_CS_ARROW4,	CommandGroup::INSERT );
2004     implDescribeSupportedFeature( ".uno:ArrowShapes.left-right-arrow" ,     SID_DRAWTBX_CS_ARROW5,	CommandGroup::INSERT );
2005     implDescribeSupportedFeature( ".uno:ArrowShapes.up-down-arrow" ,        SID_DRAWTBX_CS_ARROW6,	CommandGroup::INSERT );
2006     implDescribeSupportedFeature( ".uno:ArrowShapes.up-right-arrow" ,       SID_DRAWTBX_CS_ARROW7,	CommandGroup::INSERT );
2007     implDescribeSupportedFeature( ".uno:ArrowShapes.up-right-down-arrow" ,  SID_DRAWTBX_CS_ARROW8,	CommandGroup::INSERT );
2008     implDescribeSupportedFeature( ".uno:ArrowShapes.quad-arrow" ,	        SID_DRAWTBX_CS_ARROW9,	CommandGroup::INSERT );
2009     implDescribeSupportedFeature( ".uno:ArrowShapes.corner-right-arrow" ,   SID_DRAWTBX_CS_ARROW10,	CommandGroup::INSERT );
2010     implDescribeSupportedFeature( ".uno:ArrowShapes.split-arrow" ,	        SID_DRAWTBX_CS_ARROW11,	CommandGroup::INSERT );
2011     implDescribeSupportedFeature( ".uno:ArrowShapes.striped-right-arrow" ,  SID_DRAWTBX_CS_ARROW12,	CommandGroup::INSERT );
2012     implDescribeSupportedFeature( ".uno:ArrowShapes.notched-right-arrow" ,  SID_DRAWTBX_CS_ARROW13,	CommandGroup::INSERT );
2013     implDescribeSupportedFeature( ".uno:ArrowShapes.pentagon-right" ,	    SID_DRAWTBX_CS_ARROW14,	CommandGroup::INSERT );
2014     implDescribeSupportedFeature( ".uno:ArrowShapes.chevron" ,		        SID_DRAWTBX_CS_ARROW15,	CommandGroup::INSERT );
2015     implDescribeSupportedFeature( ".uno:ArrowShapes.right-arrow-callout" ,  SID_DRAWTBX_CS_ARROW16,	CommandGroup::INSERT );
2016     implDescribeSupportedFeature( ".uno:ArrowShapes.left-arrow-callout" ,   SID_DRAWTBX_CS_ARROW17,	CommandGroup::INSERT );
2017     implDescribeSupportedFeature( ".uno:ArrowShapes.up-arrow-callout" ,	    SID_DRAWTBX_CS_ARROW18,	CommandGroup::INSERT );
2018     implDescribeSupportedFeature( ".uno:ArrowShapes.down-arrow-callout" ,   SID_DRAWTBX_CS_ARROW19,	CommandGroup::INSERT );
2019     implDescribeSupportedFeature( ".uno:ArrowShapes.left-right-arrow-callout",SID_DRAWTBX_CS_ARROW20,		CommandGroup::INSERT );
2020     implDescribeSupportedFeature( ".uno:ArrowShapes.up-down-arrow-callout" ,SID_DRAWTBX_CS_ARROW21,	CommandGroup::INSERT );
2021     implDescribeSupportedFeature( ".uno:ArrowShapes.up-right-arrow-callout",SID_DRAWTBX_CS_ARROW22,	CommandGroup::INSERT );
2022     implDescribeSupportedFeature( ".uno:ArrowShapes.quad-arrow-callout" ,	SID_DRAWTBX_CS_ARROW23,	CommandGroup::INSERT );
2023     implDescribeSupportedFeature( ".uno:ArrowShapes.circular-arrow" ,		SID_DRAWTBX_CS_ARROW24,	CommandGroup::INSERT );
2024     implDescribeSupportedFeature( ".uno:ArrowShapes.split-round-arrow" ,	SID_DRAWTBX_CS_ARROW25,	CommandGroup::INSERT );
2025     implDescribeSupportedFeature( ".uno:ArrowShapes.s-sharped-arrow" ,		SID_DRAWTBX_CS_ARROW26,	CommandGroup::INSERT );
2026 
2027     implDescribeSupportedFeature( ".uno:StarShapes.bang" ,			        SID_DRAWTBX_CS_STAR1,			CommandGroup::INSERT );
2028     implDescribeSupportedFeature( ".uno:StarShapes.star4" ,			        SID_DRAWTBX_CS_STAR2,			CommandGroup::INSERT );
2029     implDescribeSupportedFeature( ".uno:StarShapes.star5" ,			        SID_DRAWTBX_CS_STAR3,			CommandGroup::INSERT );
2030     implDescribeSupportedFeature( ".uno:StarShapes.star6" ,			        SID_DRAWTBX_CS_STAR4,			CommandGroup::INSERT );
2031     implDescribeSupportedFeature( ".uno:StarShapes.star8" ,			        SID_DRAWTBX_CS_STAR5,			CommandGroup::INSERT );
2032     implDescribeSupportedFeature( ".uno:StarShapes.star12" ,		        SID_DRAWTBX_CS_STAR6,			CommandGroup::INSERT );
2033     implDescribeSupportedFeature( ".uno:StarShapes.star24" ,		        SID_DRAWTBX_CS_STAR7,			CommandGroup::INSERT );
2034     implDescribeSupportedFeature( ".uno:StarShapes.concave-star6" ,			SID_DRAWTBX_CS_STAR8,			CommandGroup::INSERT );
2035     implDescribeSupportedFeature( ".uno:StarShapes.vertical-scroll" ,		SID_DRAWTBX_CS_STAR9,			CommandGroup::INSERT );
2036     implDescribeSupportedFeature( ".uno:StarShapes.horizontal-scroll" ,		SID_DRAWTBX_CS_STAR10,			CommandGroup::INSERT );
2037     implDescribeSupportedFeature( ".uno:StarShapes.signet" ,				SID_DRAWTBX_CS_STAR11,			CommandGroup::INSERT );
2038     implDescribeSupportedFeature( ".uno:StarShapes.doorplate" ,				SID_DRAWTBX_CS_STAR12,			CommandGroup::INSERT );
2039 
2040     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-process" ,			SID_DRAWTBX_CS_FLOWCHART1,			CommandGroup::INSERT );
2041     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-alternate-process" ,	SID_DRAWTBX_CS_FLOWCHART2,			CommandGroup::INSERT );
2042     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-decision" ,			SID_DRAWTBX_CS_FLOWCHART3,			CommandGroup::INSERT );
2043     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-data" ,				SID_DRAWTBX_CS_FLOWCHART4,			CommandGroup::INSERT );
2044     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-predefined-process" ,	SID_DRAWTBX_CS_FLOWCHART5,			CommandGroup::INSERT );
2045     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-internal-storage" ,	SID_DRAWTBX_CS_FLOWCHART6,			CommandGroup::INSERT );
2046     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-document" ,			SID_DRAWTBX_CS_FLOWCHART7,			CommandGroup::INSERT );
2047     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-multidocument" ,		SID_DRAWTBX_CS_FLOWCHART8,			CommandGroup::INSERT );
2048     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-terminator" ,			SID_DRAWTBX_CS_FLOWCHART9,			CommandGroup::INSERT );
2049     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-preparation" ,		SID_DRAWTBX_CS_FLOWCHART10,			CommandGroup::INSERT );
2050     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-manual-input" ,	    SID_DRAWTBX_CS_FLOWCHART11,			CommandGroup::INSERT );
2051     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-manual-operation" ,	SID_DRAWTBX_CS_FLOWCHART12,			CommandGroup::INSERT );
2052     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-connector" ,			SID_DRAWTBX_CS_FLOWCHART13,			CommandGroup::INSERT );
2053     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-off-page-connector" ,	SID_DRAWTBX_CS_FLOWCHART14,			CommandGroup::INSERT );
2054     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-card" ,				SID_DRAWTBX_CS_FLOWCHART15,			CommandGroup::INSERT );
2055     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-punched-tape" ,		SID_DRAWTBX_CS_FLOWCHART16,			CommandGroup::INSERT );
2056     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-summing-junction" ,	SID_DRAWTBX_CS_FLOWCHART17,			CommandGroup::INSERT );
2057     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-or" ,				    SID_DRAWTBX_CS_FLOWCHART18,			CommandGroup::INSERT );
2058     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-collate" ,			SID_DRAWTBX_CS_FLOWCHART19,			CommandGroup::INSERT );
2059     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-sort" ,				SID_DRAWTBX_CS_FLOWCHART20,			CommandGroup::INSERT );
2060     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-extract" ,			SID_DRAWTBX_CS_FLOWCHART21,			CommandGroup::INSERT );
2061     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-merge" ,				SID_DRAWTBX_CS_FLOWCHART22,			CommandGroup::INSERT );
2062     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-stored-data" ,		SID_DRAWTBX_CS_FLOWCHART23,			CommandGroup::INSERT );
2063     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-delay" ,				SID_DRAWTBX_CS_FLOWCHART24,			CommandGroup::INSERT );
2064     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-sequential-access" ,	SID_DRAWTBX_CS_FLOWCHART25,			CommandGroup::INSERT );
2065     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-magnetic-disk" ,		SID_DRAWTBX_CS_FLOWCHART26,			CommandGroup::INSERT );
2066     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-direct-access-storage",SID_DRAWTBX_CS_FLOWCHART27,		CommandGroup::INSERT );
2067     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-display" ,			SID_DRAWTBX_CS_FLOWCHART28,			CommandGroup::INSERT );
2068 
2069     implDescribeSupportedFeature( ".uno:CalloutShapes.rectangular-callout" ,		SID_DRAWTBX_CS_CALLOUT1,			CommandGroup::INSERT );
2070     implDescribeSupportedFeature( ".uno:CalloutShapes.round-rectangular-callout" ,	SID_DRAWTBX_CS_CALLOUT2,			CommandGroup::INSERT );
2071     implDescribeSupportedFeature( ".uno:CalloutShapes.round-callout" ,				SID_DRAWTBX_CS_CALLOUT3,			CommandGroup::INSERT );
2072     implDescribeSupportedFeature( ".uno:CalloutShapes.cloud-callout" ,				SID_DRAWTBX_CS_CALLOUT4,			CommandGroup::INSERT );
2073     implDescribeSupportedFeature( ".uno:CalloutShapes.line-callout-1" ,				SID_DRAWTBX_CS_CALLOUT5,			CommandGroup::INSERT );
2074     implDescribeSupportedFeature( ".uno:CalloutShapes.line-callout-2" ,				SID_DRAWTBX_CS_CALLOUT6,			CommandGroup::INSERT );
2075     implDescribeSupportedFeature( ".uno:CalloutShapes.line-callout-3" ,				SID_DRAWTBX_CS_CALLOUT7,			CommandGroup::INSERT );
2076 
2077     implDescribeSupportedFeature( ".uno:ArrowShapes",				SID_DRAWTBX_CS_ARROW,			CommandGroup::INSERT );
2078 
2079     implDescribeSupportedFeature( ".uno:FlowChartShapes",   		SID_DRAWTBX_CS_FLOWCHART,		CommandGroup::INSERT );
2080     implDescribeSupportedFeature( ".uno:CalloutShapes",   		    SID_DRAWTBX_CS_CALLOUT,			CommandGroup::INSERT );
2081     implDescribeSupportedFeature( ".uno:StarShapes",   	    	    SID_DRAWTBX_CS_STAR,			CommandGroup::INSERT );
2082 
2083 
2084     // keys
2085     implDescribeSupportedFeature( ".uno:Escape",					SID_ESCAPE,                     CommandGroup::CONTROLS);
2086 
2087 	// internal one
2088 	implDescribeSupportedFeature( ".uno:RPT_RPTHEADER_UNDO",			SID_REPORTHEADER_WITHOUT_UNDO);
2089 	implDescribeSupportedFeature( ".uno:RPT_RPTFOOTER_UNDO",			SID_REPORTFOOTER_WITHOUT_UNDO);
2090 	implDescribeSupportedFeature( ".uno:RPT_PGHEADER_UNDO",				SID_PAGEHEADER_WITHOUT_UNDO);
2091 	implDescribeSupportedFeature( ".uno:RPT_PGFOOTER_UNDO",				SID_PAGEFOOTER_WITHOUT_UNDO);
2092 	implDescribeSupportedFeature( ".uno:DBBackgroundColor",				SID_ATTR_CHAR_COLOR_BACKGROUND);
2093 	implDescribeSupportedFeature( ".uno:SID_GROUPHEADER",				SID_GROUPHEADER);
2094 	implDescribeSupportedFeature( ".uno:SID_GROUPHEADER_WITHOUT_UNDO",	SID_GROUPHEADER_WITHOUT_UNDO);
2095 	implDescribeSupportedFeature( ".uno:SID_GROUPFOOTER",				SID_GROUPFOOTER);
2096 	implDescribeSupportedFeature( ".uno:SID_GROUPFOOTER_WITHOUT_UNDO",	SID_GROUPFOOTER_WITHOUT_UNDO);
2097 	implDescribeSupportedFeature( ".uno:SID_GROUP_REMOVE",				SID_GROUP_REMOVE);
2098 	implDescribeSupportedFeature( ".uno:SID_GROUP_APPEND",				SID_GROUP_APPEND);
2099 	implDescribeSupportedFeature( ".uno:SID_ADD_CONTROL_PAIR",			SID_ADD_CONTROL_PAIR);
2100     implDescribeSupportedFeature( ".uno:SplitPosition",			        SID_SPLIT_POSITION);
2101     implDescribeSupportedFeature( ".uno:LastPropertyBrowserPage",	    SID_PROPERTYBROWSER_LAST_PAGE);
2102     implDescribeSupportedFeature( ".uno:Select",	                    SID_SELECT);
2103     implDescribeSupportedFeature( ".uno:InsertFunction",				SID_RPT_NEW_FUNCTION);
2104     implDescribeSupportedFeature( ".uno:NextMark",				        SID_NEXT_MARK);
2105     implDescribeSupportedFeature( ".uno:PrevMark",				        SID_PREV_MARK);
2106     implDescribeSupportedFeature( ".uno:TerminateInplaceActivation",    SID_TERMINATE_INPLACEACTIVATION);
2107     implDescribeSupportedFeature( ".uno:SelectAllLabels",               SID_SELECT_ALL_LABELS);
2108     implDescribeSupportedFeature( ".uno:SelectAllEdits",                SID_SELECT_ALL_EDITS);
2109     implDescribeSupportedFeature( ".uno:CollapseSection",			SID_COLLAPSE_SECTION);
2110     implDescribeSupportedFeature( ".uno:ExpandSection",				SID_EXPAND_SECTION);
2111 }
2112 // -----------------------------------------------------------------------------
2113 void OReportController::impl_onModifyChanged()
2114 {
2115 	try
2116     {
2117 	    if ( m_xReportDefinition.is() )
2118 		    m_xReportDefinition->setModified( impl_isModified() );
2119         DBSubComponentController::impl_onModifyChanged();
2120     }
2121     catch(uno::Exception)
2122     {
2123         DBG_UNHANDLED_EXCEPTION();
2124     }
2125 }
2126 // -----------------------------------------------------------------------------
2127 void OReportController::onLoadedMenu(const Reference< frame::XLayoutManager >& _xLayoutManager)
2128 {
2129 	if ( _xLayoutManager.is() )
2130 	{
2131         static const ::rtl::OUString s_sMenu[] = {
2132 		     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:resource/statusbar/statusbar"))
2133             ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:resource/toolbar/reportcontrols"))
2134             ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:resource/toolbar/drawbar"))
2135             ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:resource/toolbar/Formatting"))
2136             ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:resource/toolbar/alignmentbar"))
2137             ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:resource/toolbar/sectionalignmentbar"))
2138             ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:resource/toolbar/resizebar"))
2139             ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:resource/toolbar/sectionshrinkbar"))
2140         };
2141         for (size_t i = 0; i< sizeof(s_sMenu)/sizeof(s_sMenu[0]); ++i)
2142         {
2143             _xLayoutManager->createElement( s_sMenu[i] );
2144 		    _xLayoutManager->requestElement( s_sMenu[i] );
2145         }
2146 	} // if ( _xLayoutManager.is() )
2147 }
2148 // -----------------------------------------------------------------------------
2149 void OReportController::notifyGroupSections(const ContainerEvent& _rEvent,bool _bShow)
2150 {
2151     uno::Reference< report::XGroup> xGroup(_rEvent.Element,uno::UNO_QUERY);
2152 	if ( xGroup.is() )
2153 	{
2154         ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
2155 	    ::osl::MutexGuard aGuard( getMutex() );
2156         sal_Int32 nGroupPos = 0;
2157 		_rEvent.Accessor >>= nGroupPos;
2158 
2159         if ( _bShow )
2160         {
2161 		    xGroup->addPropertyChangeListener(PROPERTY_HEADERON, static_cast<XPropertyChangeListener*>(this));
2162 		    xGroup->addPropertyChangeListener(PROPERTY_FOOTERON, static_cast<XPropertyChangeListener*>(this));
2163         }
2164         else
2165         {
2166             xGroup->removePropertyChangeListener(PROPERTY_HEADERON, static_cast<XPropertyChangeListener*>(this));
2167 		    xGroup->removePropertyChangeListener(PROPERTY_FOOTERON, static_cast<XPropertyChangeListener*>(this));
2168         }
2169 
2170 	    if ( xGroup->getHeaderOn() )
2171 	    {
2172 		    groupChange(xGroup,PROPERTY_HEADERON,nGroupPos,_bShow);
2173             if (_bShow)
2174             {
2175                 m_pReportControllerObserver->AddSection(xGroup->getHeader());
2176             }
2177             else
2178             {
2179                 m_pReportControllerObserver->RemoveSection(xGroup->getHeader());
2180             }
2181 	    }
2182 	    if ( xGroup->getFooterOn() )
2183 	    {
2184 		    groupChange(xGroup,PROPERTY_FOOTERON,nGroupPos,_bShow);
2185             if (_bShow)
2186             {
2187                 m_pReportControllerObserver->AddSection(xGroup->getFooter());
2188             }
2189             else
2190             {
2191                 m_pReportControllerObserver->RemoveSection(xGroup->getFooter());
2192             }
2193 	    }
2194     }
2195 }
2196 // -----------------------------------------------------------------------------
2197 // ::container::XContainerListener
2198 void SAL_CALL OReportController::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
2199 {
2200 	notifyGroupSections(_rEvent,true);
2201 }
2202 // -----------------------------------------------------------------------------
2203 void SAL_CALL OReportController::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
2204 {
2205 	notifyGroupSections(_rEvent,false);
2206 }
2207 // -----------------------------------------------------------------------------
2208 void SAL_CALL OReportController::elementReplaced( const ContainerEvent& /*_rEvent*/ ) throw(RuntimeException)
2209 {
2210 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
2211 	::osl::MutexGuard aGuard( getMutex() );
2212 	OSL_ENSURE(0,"Not yet implemented!");
2213 }
2214 // -----------------------------------------------------------------------------
2215 void SAL_CALL OReportController::propertyChange( const beans::PropertyChangeEvent& evt ) throw (RuntimeException)
2216 {
2217 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
2218 	::osl::MutexGuard aGuard( getMutex() );
2219 	try
2220 	{
2221 		sal_Bool bShow = sal_False;
2222 		evt.NewValue >>= bShow;
2223 		if ( evt.Source == m_xReportDefinition )
2224 		{
2225 			if ( evt.PropertyName.equals( PROPERTY_REPORTHEADERON ) )
2226 			{
2227                 const sal_uInt16 nPosition = m_xReportDefinition->getPageHeaderOn() ? 1 : 0;
2228 				if ( bShow )
2229                 {
2230                     getDesignView()->addSection(m_xReportDefinition->getReportHeader(),DBREPORTHEADER,nPosition);
2231                     m_pReportControllerObserver->AddSection(m_xReportDefinition->getReportHeader());
2232                 }
2233 				else
2234                 {
2235                     getDesignView()->removeSection(nPosition);
2236     			}
2237             }
2238 			else if ( evt.PropertyName.equals( PROPERTY_REPORTFOOTERON ) )
2239 			{
2240                 sal_uInt16 nPosition = getDesignView()->getSectionCount();
2241 				if ( m_xReportDefinition->getPageFooterOn() )
2242 					--nPosition;
2243 				if ( bShow )
2244                 {
2245                     getDesignView()->addSection(m_xReportDefinition->getReportFooter(),DBREPORTFOOTER,nPosition);
2246                     m_pReportControllerObserver->AddSection(m_xReportDefinition->getReportFooter());
2247                 }
2248                 else
2249                 {
2250                     getDesignView()->removeSection(nPosition - 1);
2251     			}
2252             }
2253 			else if ( evt.PropertyName.equals( PROPERTY_PAGEHEADERON ) )
2254 			{
2255 				if ( bShow )
2256                 {
2257                     getDesignView()->addSection(m_xReportDefinition->getPageHeader(),DBPAGEHEADER,0);
2258                     m_pReportControllerObserver->AddSection(m_xReportDefinition->getPageHeader());
2259                 }
2260 				else
2261                 {
2262                     getDesignView()->removeSection(sal_uInt16(0));
2263                 }
2264 			}
2265 			else if ( evt.PropertyName.equals( PROPERTY_PAGEFOOTERON ) )
2266 			{
2267                 if ( bShow )
2268                 {
2269                     getDesignView()->addSection(m_xReportDefinition->getPageFooter(),DBPAGEFOOTER);
2270                     m_pReportControllerObserver->AddSection(m_xReportDefinition->getPageFooter());
2271                 }
2272 				else
2273                 {
2274                     getDesignView()->removeSection(getDesignView()->getSectionCount() - 1);
2275                 }
2276 			}
2277             else if (   evt.PropertyName.equals( PROPERTY_COMMAND )
2278                     ||  evt.PropertyName.equals( PROPERTY_COMMANDTYPE )
2279                     ||  evt.PropertyName.equals( PROPERTY_ESCAPEPROCESSING )
2280                     ||  evt.PropertyName.equals( PROPERTY_FILTER )
2281                     )
2282 			{
2283                 m_xColumns.clear();
2284                 m_xHoldAlive.clear();
2285                 InvalidateFeature(SID_FM_ADD_FIELD);
2286                 if ( !getDesignView()->isAddFieldVisible() && isUiVisible() )
2287                     getDesignView()->toggleAddField();
2288             }
2289             /// TODO: check what we need to notify here TitleHelper
2290             /*else if (   evt.PropertyName.equals( PROPERTY_CAPTION ) )
2291                 updateTitle();*/
2292 		} // if ( evt.Source == m_xReportDefinition )
2293 		else
2294 		{
2295 			uno::Reference< report::XGroup> xGroup(evt.Source,uno::UNO_QUERY);
2296 			if ( xGroup.is() )
2297 			{
2298 				sal_Int32 nGroupPos = getGroupPosition(xGroup);
2299 
2300 				groupChange(xGroup,evt.PropertyName,nGroupPos,bShow);
2301 			}
2302 		}
2303 	}
2304     catch(const uno::Exception&)
2305 	{
2306         DBG_UNHANDLED_EXCEPTION();
2307 	}
2308 }
2309 
2310 // -----------------------------------------------------------------------------
2311 void SAL_CALL OReportController::disposing( const lang::EventObject& Source ) throw(uno::RuntimeException)
2312 {
2313     // simply disambiguate
2314     OReportController_BASE::disposing(Source);
2315 }
2316 
2317 // -----------------------------------------------------------------------------
2318 sal_uInt16 lcl_getNonVisbleGroupsBefore( const uno::Reference< report::XGroups>& _xGroups
2319 						  ,sal_Int32 _nGroupPos
2320 						  ,::std::mem_fun_t<sal_Bool,OGroupHelper>&_pGroupMemberFunction)
2321 {
2322 	uno::Reference< report::XGroup> xGroup;
2323 	sal_uInt16 nNonVisibleGroups = 0;
2324 	sal_Int32 nCount = _xGroups->getCount();
2325 	for( sal_Int32 i = 0; i < _nGroupPos && i < nCount; ++i)
2326 	{
2327 		xGroup.set(_xGroups->getByIndex(i),uno::UNO_QUERY);
2328 		OSL_ENSURE(xGroup.is(),"Group is NULL! -> GPF");
2329 		OGroupHelper aGroupHelper(xGroup);
2330 		if ( !_pGroupMemberFunction(&aGroupHelper) )
2331 			++nNonVisibleGroups;
2332 	}
2333 	return nNonVisibleGroups;
2334 }
2335 // -----------------------------------------------------------------------------
2336 void OReportController::groupChange( const uno::Reference< report::XGroup>& _xGroup,const ::rtl::OUString& _sPropName,sal_Int32 _nGroupPos,bool _bShow)
2337 {
2338 	//adjustSectionName(_xGroup,_nGroupPos);
2339 	::std::mem_fun_t<sal_Bool,OGroupHelper> pMemFun = ::std::mem_fun(&OGroupHelper::getHeaderOn);
2340 	::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> pMemFunSection = ::std::mem_fun(&OGroupHelper::getHeader);
2341 	::rtl::OUString sColor(DBGROUPHEADER);
2342 	sal_uInt16 nPosition = 0;
2343 	bool bHandle = false;
2344 	if ( _sPropName.equals( PROPERTY_HEADERON ) )
2345 	{
2346 		nPosition = m_xReportDefinition->getPageHeaderOn() ? (m_xReportDefinition->getReportHeaderOn() ? 2 : 1) : (m_xReportDefinition->getReportHeaderOn() ? 1 : 0);
2347 		nPosition += (static_cast<sal_uInt16>(_nGroupPos) - lcl_getNonVisbleGroupsBefore(m_xReportDefinition->getGroups(),_nGroupPos,pMemFun));
2348 		bHandle = true;
2349 	}
2350 	else if ( _sPropName.equals( PROPERTY_FOOTERON ) )
2351 	{
2352 		pMemFun = ::std::mem_fun(&OGroupHelper::getFooterOn);
2353 		pMemFunSection = ::std::mem_fun(&OGroupHelper::getFooter);
2354 		nPosition = getDesignView()->getSectionCount();
2355 
2356         if ( m_xReportDefinition->getPageFooterOn() )
2357 			--nPosition;
2358 		if ( m_xReportDefinition->getReportFooterOn() )
2359 			--nPosition;
2360 		sColor = DBGROUPFOOTER;
2361 		nPosition -= (static_cast<sal_uInt16>(_nGroupPos) - lcl_getNonVisbleGroupsBefore(m_xReportDefinition->getGroups(),_nGroupPos,pMemFun));
2362 		if ( !_bShow )
2363 			--nPosition;
2364 		bHandle = true;
2365 	}
2366 	if ( bHandle )
2367 	{
2368 		if ( _bShow )
2369 		{
2370 			OGroupHelper aGroupHelper(_xGroup);
2371 			getDesignView()->addSection(pMemFunSection(&aGroupHelper),sColor,nPosition);
2372 		}
2373 		else
2374         {
2375             getDesignView()->removeSection(nPosition);
2376         }
2377 	}
2378 }
2379 //------------------------------------------------------------------------------
2380 IMPL_LINK( OReportController, OnClipboardChanged, void*, EMPTYARG )
2381 {
2382 	return OnInvalidateClipboard( NULL );
2383 }
2384 //------------------------------------------------------------------------------
2385 IMPL_LINK(OReportController, OnInvalidateClipboard, void*, EMPTYARG)
2386 {
2387 	InvalidateFeature(SID_CUT);
2388 	InvalidateFeature(SID_COPY);
2389 	InvalidateFeature(SID_PASTE);
2390 	return 0L;
2391 }
2392 // -----------------------------------------------------------------------------
2393 void OReportController::openPageDialog(const uno::Reference<report::XSection>& _xSection)
2394 {
2395 	if ( !m_xReportDefinition.is() )
2396 		return;
2397 	// ------------
2398 	// UNO->ItemSet
2399 	static SfxItemInfo aItemInfos[] =
2400 	{
2401 		{ SID_ATTR_LRSPACE,		SFX_ITEM_POOLABLE },
2402 		{ SID_ATTR_ULSPACE,		SFX_ITEM_POOLABLE },
2403 		{ SID_ATTR_PAGE,		SFX_ITEM_POOLABLE },
2404 		{ SID_ATTR_PAGE_SIZE,	SFX_ITEM_POOLABLE },
2405 		{ SID_ENUM_PAGE_MODE,	SFX_ITEM_POOLABLE },
2406 		{ SID_PAPER_START,		SFX_ITEM_POOLABLE },
2407 		{ SID_PAPER_END,		SFX_ITEM_POOLABLE },
2408 		{ SID_ATTR_BRUSH,		SFX_ITEM_POOLABLE },
2409 		{ SID_FLAG_TYPE,		SFX_ITEM_POOLABLE },
2410 		{ SID_ATTR_METRIC,		SFX_ITEM_POOLABLE }
2411 	};
2412 
2413 	MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
2414     FieldUnit eUserMetric = MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH;
2415 	SfxPoolItem* pDefaults[] =
2416 	{
2417 		new SvxLRSpaceItem(RPTUI_ID_LRSPACE),
2418 		new SvxULSpaceItem(RPTUI_ID_ULSPACE),
2419 		new SvxPageItem(RPTUI_ID_PAGE),
2420 		new SvxSizeItem(RPTUI_ID_SIZE),
2421 		new SfxAllEnumItem(RPTUI_ID_PAGE_MODE,SVX_PAGE_MODE_STANDARD),
2422 		new SfxAllEnumItem(RPTUI_ID_START,PAPER_A4),
2423 		new SfxAllEnumItem(RPTUI_ID_END,PAPER_E),
2424 		new SvxBrushItem(ITEMID_BRUSH),
2425 		new SfxUInt16Item(RPTUI_ID_METRIC,static_cast<sal_uInt16>(eUserMetric))
2426 	};
2427 
2428 	static sal_uInt16 pRanges[] =
2429 	{
2430 		RPTUI_ID_LRSPACE,RPTUI_ID_BRUSH,
2431 		SID_ATTR_METRIC,SID_ATTR_METRIC,
2432         0
2433 	};
2434 	SfxItemPool* pPool( new SfxItemPool(String::CreateFromAscii("ReportPageProperties"), RPTUI_ID_LRSPACE,RPTUI_ID_METRIC, aItemInfos, pDefaults) );
2435 	pPool->SetDefaultMetric( SFX_MAPUNIT_100TH_MM );	// ripped, don't understand why
2436 	pPool->FreezeIdRanges();						// the same
2437 
2438 	try
2439 	{
2440 		::std::auto_ptr<SfxItemSet> pDescriptor(new SfxItemSet(*pPool, pRanges));
2441 		// fill it
2442 		if ( _xSection.is() )
2443 			pDescriptor->Put(SvxBrushItem(::Color(_xSection->getBackColor()),ITEMID_BRUSH));
2444 		else
2445 		{
2446             pDescriptor->Put(SvxSizeItem(RPTUI_ID_SIZE,VCLSize(getStyleProperty<awt::Size>(m_xReportDefinition,PROPERTY_PAPERSIZE))));
2447 			pDescriptor->Put(SvxLRSpaceItem(getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_LEFTMARGIN)
2448                                             ,getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_RIGHTMARGIN),0,0,RPTUI_ID_LRSPACE));
2449 			pDescriptor->Put(SvxULSpaceItem(static_cast<sal_uInt16>(getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_TOPMARGIN))
2450                                             ,static_cast<sal_uInt16>(getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_BOTTOMMARGIN)),RPTUI_ID_ULSPACE));
2451 			pDescriptor->Put(SfxUInt16Item(SID_ATTR_METRIC,static_cast<sal_uInt16>(eUserMetric)));
2452 
2453             uno::Reference< style::XStyle> xPageStyle(getUsedStyle(m_xReportDefinition));
2454             if ( xPageStyle.is() )
2455             {
2456                 SvxPageItem aPageItem(RPTUI_ID_PAGE);
2457                 aPageItem.SetDescName(xPageStyle->getName());
2458                 uno::Reference<beans::XPropertySet> xProp(xPageStyle,uno::UNO_QUERY_THROW);
2459                 aPageItem.PutValue(xProp->getPropertyValue(PROPERTY_PAGESTYLELAYOUT),MID_PAGE_LAYOUT);
2460 	            aPageItem.SetLandscape(getStyleProperty<sal_Bool>(m_xReportDefinition,PROPERTY_ISLANDSCAPE));
2461 	            aPageItem.SetNumType((SvxNumType)getStyleProperty<sal_Int16>(m_xReportDefinition,PROPERTY_NUMBERINGTYPE));
2462                 pDescriptor->Put(aPageItem);
2463                 pDescriptor->Put(SvxBrushItem(::Color(getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_BACKCOLOR)),RPTUI_ID_BRUSH));
2464             }
2465 		}
2466 
2467 		{	// want the dialog to be destroyed before our set
2468 			ORptPageDialog aDlg(getView(), pDescriptor.get(),_xSection.is() ? RID_PAGEDIALOG_BACKGROUND : RID_PAGEDIALOG_PAGE);
2469 			if (RET_OK == aDlg.Execute())
2470 			{
2471 				// ------------
2472 				// ItemSet->UNO
2473 				// UNO-properties
2474 				const SfxItemSet* pSet = aDlg.GetOutputItemSet();
2475 				if ( _xSection.is() )
2476 				{
2477 					const SfxPoolItem* pItem;
2478 					if ( SFX_ITEM_SET == pSet->GetItemState( RPTUI_ID_BRUSH,sal_True,&pItem))
2479 						_xSection->setBackColor(static_cast<const SvxBrushItem*>(pItem)->GetColor().GetColor());
2480 				}
2481 				else
2482 				{
2483                     uno::Reference< beans::XPropertySet> xProp(getUsedStyle(m_xReportDefinition),uno::UNO_QUERY_THROW);
2484                     const String sUndoAction(ModuleRes(RID_STR_UNDO_CHANGEPAGE));
2485                     UndoContext aUndoContext( getUndoManager(), sUndoAction );
2486 					const SfxPoolItem* pItem = NULL;
2487 					if ( SFX_ITEM_SET == pSet->GetItemState( RPTUI_ID_SIZE,sal_True,&pItem))
2488                     {
2489                         const Size aPaperSize = static_cast<const SvxSizeItem*>(pItem)->GetSize();
2490                         uno::Any aValue;
2491                         static_cast<const SvxSizeItem*>(pItem)->QueryValue(aValue,MID_SIZE_SIZE);
2492 						xProp->setPropertyValue(PROPERTY_PAPERSIZE,aValue);
2493                         resetZoomType();
2494                     }
2495 
2496 					if ( SFX_ITEM_SET == pSet->GetItemState( RPTUI_ID_LRSPACE,sal_True,&pItem))
2497 					{
2498                         Any aValue;
2499                         static_cast<const SvxLRSpaceItem*>(pItem)->QueryValue(aValue,MID_L_MARGIN);
2500                         xProp->setPropertyValue(PROPERTY_LEFTMARGIN,aValue);
2501                         static_cast<const SvxLRSpaceItem*>(pItem)->QueryValue(aValue,MID_R_MARGIN);
2502 						xProp->setPropertyValue(PROPERTY_RIGHTMARGIN,aValue);
2503 					}
2504 					if ( SFX_ITEM_SET == pSet->GetItemState( RPTUI_ID_ULSPACE,sal_True,&pItem))
2505 					{
2506 						xProp->setPropertyValue(PROPERTY_TOPMARGIN,uno::makeAny(static_cast<const SvxULSpaceItem*>(pItem)->GetUpper()));
2507 						xProp->setPropertyValue(PROPERTY_BOTTOMMARGIN,uno::makeAny(static_cast<const SvxULSpaceItem*>(pItem)->GetLower()));
2508 					}
2509                     if ( SFX_ITEM_SET == pSet->GetItemState( RPTUI_ID_PAGE,sal_True,&pItem))
2510 					{
2511                         const SvxPageItem* pPageItem = static_cast<const SvxPageItem*>(pItem);
2512                         xProp->setPropertyValue(PROPERTY_ISLANDSCAPE,uno::makeAny(static_cast<sal_Bool>(pPageItem->IsLandscape())));
2513                         xProp->setPropertyValue(PROPERTY_NUMBERINGTYPE,uno::makeAny(static_cast<sal_Int16>(pPageItem->GetNumType())));
2514                         uno::Any aValue;
2515                         pPageItem->QueryValue(aValue,MID_PAGE_LAYOUT);
2516                         xProp->setPropertyValue(PROPERTY_PAGESTYLELAYOUT,aValue);
2517                         resetZoomType();
2518                     }
2519                     if ( SFX_ITEM_SET == pSet->GetItemState( RPTUI_ID_BRUSH,sal_True,&pItem))
2520                     {
2521                         ::Color aBackColor = static_cast<const SvxBrushItem*>(pItem)->GetColor();
2522                         xProp->setPropertyValue(PROPERTY_BACKTRANSPARENT,uno::makeAny(aBackColor == COL_TRANSPARENT));
2523                         xProp->setPropertyValue(PROPERTY_BACKCOLOR,uno::makeAny(aBackColor.GetColor()));
2524                     }
2525 				}
2526 			}
2527 		}
2528 	}
2529 	catch(Exception&)
2530 	{
2531         DBG_UNHANDLED_EXCEPTION();
2532 	}
2533 	SfxItemPool::Free(pPool);
2534 
2535 	for (sal_uInt16 i=0; i<sizeof(pDefaults)/sizeof(pDefaults[0]); ++i)
2536 		delete pDefaults[i];
2537 
2538 }
2539 
2540 // -----------------------------------------------------------------------------
2541 sal_Bool SAL_CALL OReportController::attachModel(const uno::Reference< frame::XModel > & xModel) throw( uno::RuntimeException )
2542 {
2543 	::osl::MutexGuard aGuard( getMutex() );
2544 
2545     uno::Reference< report::XReportDefinition > xReportDefinition( xModel, UNO_QUERY );
2546     if ( !xReportDefinition.is() )
2547         return sal_False;
2548 
2549     uno::Reference< document::XUndoManagerSupplier > xTestSuppUndo( xModel, UNO_QUERY );
2550     if ( !xTestSuppUndo.is() )
2551         return sal_False;
2552 
2553 	m_xReportDefinition = xReportDefinition;
2554     return sal_True;
2555 }
2556 
2557 // -----------------------------------------------------------------------------
2558 void OReportController::openSortingAndGroupingDialog()
2559 {
2560     if ( !m_xReportDefinition.is() )
2561         return;
2562 	if ( !m_pGroupsFloater )
2563 	{
2564 		m_pGroupsFloater = new OGroupsSortingDialog(getView(),!isEditable(),this);
2565         SvtViewOptions aDlgOpt( E_WINDOW, String::CreateFromInt32( RID_GROUPS_SORTING ) );
2566         if ( aDlgOpt.Exists() )
2567             m_pGroupsFloater->SetWindowState( ByteString( aDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US ) );
2568 		m_pGroupsFloater->AddEventListener(LINK(this,OReportController,EventLstHdl));
2569 	}
2570 	else if ( isUiVisible() )
2571 		m_pGroupsFloater->Show(!m_pGroupsFloater->IsVisible());
2572 }
2573 // -----------------------------------------------------------------------------
2574 sal_Int32 OReportController::getGroupPosition(const uno::Reference< report::XGroup >& _xGroup)
2575 {
2576 	return rptui::getPositionInIndexAccess(m_xReportDefinition->getGroups().get(),_xGroup);
2577 }
2578 // -----------------------------------------------------------------------------
2579 // -----------------------------------------------------------------------------
2580 IMPL_LINK( OReportController, EventLstHdl, VclWindowEvent*, _pEvent )
2581 {
2582 	if ( _pEvent && _pEvent->GetId() == VCLEVENT_WINDOW_CLOSE )
2583 	{
2584 		InvalidateFeature(SID_SORTINGANDGROUPING);
2585         InvalidateFeature(SID_FM_ADD_FIELD);
2586         InvalidateFeature(SID_RPT_SHOWREPORTEXPLORER);
2587 	}
2588 	return 1L;
2589 }
2590 // -----------------------------------------------------------------------------
2591 void OReportController::Notify(SfxBroadcaster & /* _rBc */, SfxHint const & _rHint)
2592 {
2593     if (_rHint.ISA(DlgEdHint)
2594         && (static_cast< DlgEdHint const & >(_rHint).GetKind()
2595             == RPTUI_HINT_SELECTIONCHANGED))
2596     {
2597         const sal_Int32 nSelectionCount = getDesignView()->getMarkedObjectCount();
2598         if ( m_nSelectionCount != nSelectionCount )
2599         {
2600             m_nSelectionCount = nSelectionCount;
2601 		    InvalidateAll();
2602         }
2603         lang::EventObject aEvent(*this);
2604         m_aSelectionListeners.forEach<view::XSelectionChangeListener>(
2605 			::boost::bind(&view::XSelectionChangeListener::selectionChanged,_1,boost::cref(aEvent)));
2606 
2607 	}
2608 }
2609 // -----------------------------------------------------------------------------
2610 void OReportController::executeMethodWithUndo(sal_uInt16 _nUndoStrId,const ::std::mem_fun_t<void,ODesignView>& _pMemfun)
2611 {
2612     const String sUndoAction = String((ModuleRes(_nUndoStrId)));
2613     UndoContext aUndoContext( getUndoManager(), sUndoAction );
2614     _pMemfun( getDesignView() );
2615 	InvalidateFeature( SID_SAVEDOC );
2616 	InvalidateFeature( SID_UNDO );
2617 }
2618 // -----------------------------------------------------------------------------
2619 void OReportController::alignControlsWithUndo(sal_uInt16 _nUndoStrId,sal_Int32 _nControlModification,bool _bAlignAtSection)
2620 {
2621     const String sUndoAction = String((ModuleRes(_nUndoStrId)));
2622     UndoContext aUndoContext( getUndoManager(), sUndoAction );
2623     getDesignView()->alignMarkedObjects(_nControlModification,_bAlignAtSection);
2624 	InvalidateFeature( SID_SAVEDOC );
2625 	InvalidateFeature( SID_UNDO );
2626 }
2627 // -----------------------------------------------------------------------------
2628 void OReportController::shrinkSectionBottom(uno::Reference<report::XSection> _xSection)
2629 {
2630     const sal_Int32 nElements = _xSection->getCount();
2631     if (nElements == 0)
2632     {
2633         // there are no elements
2634         return;
2635     }
2636     const sal_Int32 nSectionHeight = _xSection->getHeight();
2637     // sal_Int32 nMinPositionY = nSectionHeight;
2638     sal_Int32 nMaxPositionY = 0;
2639     uno::Reference< report::XReportComponent> xReportComponent;
2640 
2641     // for every component get it's Y-position and compare it to the current Y-position
2642     for (int i=0;i<nElements;i++)
2643     {
2644         xReportComponent.set(_xSection->getByIndex(i), uno::UNO_QUERY);
2645         const sal_Int32 nReportComponentPositionY = xReportComponent->getPositionY();
2646         const sal_Int32 nReportComponentHeight = xReportComponent->getHeight();
2647         const sal_Int32 nReportComponentPositionYAndHeight = nReportComponentPositionY + nReportComponentHeight;
2648         // nMinPositionY = std::min(nReportComponentPositionY, nMinPositionY);
2649         nMaxPositionY = std::max(nReportComponentPositionYAndHeight, nMaxPositionY);
2650     }
2651     // now we know the minimal Y-Position and maximal Y-Position
2652 
2653     if (nMaxPositionY > (nSectionHeight - 7) ) // Magic Number, we use a little bit less heights for right positioning
2654     {
2655         // the lowest position is already 0
2656         return;
2657     }
2658     _xSection->setHeight(nMaxPositionY);
2659 }
2660 
2661 void OReportController::shrinkSectionTop(uno::Reference<report::XSection> _xSection)
2662 {
2663     const sal_Int32 nElements = _xSection->getCount();
2664     if (nElements == 0)
2665     {
2666         // there are no elements
2667         return;
2668     }
2669 
2670     const sal_Int32 nSectionHeight = _xSection->getHeight();
2671     sal_Int32 nMinPositionY = nSectionHeight;
2672     // sal_Int32 nMaxPositionY = 0;
2673     uno::Reference< report::XReportComponent> xReportComponent;
2674 
2675     // for every component get it's Y-position and compare it to the current Y-position
2676     for (int i=0;i<nElements;i++)
2677     {
2678         xReportComponent.set(_xSection->getByIndex(i), uno::UNO_QUERY);
2679         const sal_Int32 nReportComponentPositionY = xReportComponent->getPositionY();
2680         // const sal_Int32 nReportComponentHeight = xReportComponent->getHeight();
2681         // const sal_Int32 nReportComponentPositionYAndHeight = nReportComponentPositionY + nReportComponentHeight;
2682         nMinPositionY = std::min(nReportComponentPositionY, nMinPositionY);
2683         // nMaxPositionY = std::max(nReportComponentPositionYAndHeight, nMaxPositionY);
2684     }
2685     // now we know the minimal Y-Position and maximal Y-Position
2686     if (nMinPositionY == 0)
2687     {
2688         // the lowest position is already 0
2689         return;
2690     }
2691     for (int i=0;i<nElements;i++)
2692     {
2693         xReportComponent.set(_xSection->getByIndex(i), uno::UNO_QUERY);
2694         const sal_Int32 nReportComponentPositionY = xReportComponent->getPositionY();
2695         const sal_Int32 nNewPositionY = nReportComponentPositionY - nMinPositionY;
2696         xReportComponent->setPositionY(nNewPositionY);
2697     }
2698     const sal_Int32 nNewSectionHeight = nSectionHeight - nMinPositionY;
2699     _xSection->setHeight(nNewSectionHeight);
2700 }
2701 
2702 void OReportController::shrinkSection(sal_uInt16 _nUndoStrId, uno::Reference<report::XSection> _xSection, sal_Int32 _nSid)
2703 {
2704 	if ( _xSection.is() )
2705     {
2706         const String sUndoAction = String((ModuleRes(_nUndoStrId)));
2707         UndoContext aUndoContext( getUndoManager(), sUndoAction );
2708 
2709         if (_nSid == SID_SECTION_SHRINK)
2710         {
2711             shrinkSectionTop(_xSection);
2712             shrinkSectionBottom(_xSection);
2713         }
2714         else if (_nSid == SID_SECTION_SHRINK_TOP)
2715         {
2716             shrinkSectionTop(_xSection);
2717         }
2718         else if (_nSid == SID_SECTION_SHRINK_BOTTOM)
2719         {
2720             shrinkSectionBottom(_xSection);
2721         }
2722     }
2723 
2724     InvalidateFeature( SID_SAVEDOC );
2725     InvalidateFeature( SID_UNDO );
2726 }
2727 
2728 // -----------------------------------------------------------------------------
2729 uno::Any SAL_CALL OReportController::getViewData(void) throw( uno::RuntimeException )
2730 {
2731     ::osl::MutexGuard aGuard( getMutex() );
2732 
2733     sal_Int32 nCommandIDs[] =
2734     {
2735         SID_GRID_VISIBLE,
2736         SID_GRID_USE,
2737         SID_HELPLINES_MOVE,
2738         SID_RULER,
2739         SID_SHOW_PROPERTYBROWSER,
2740         SID_PROPERTYBROWSER_LAST_PAGE,
2741         SID_SPLIT_POSITION
2742     };
2743 
2744     ::comphelper::NamedValueCollection aCommandProperties;
2745     for ( size_t i=0; i < sizeof( nCommandIDs ) / sizeof( nCommandIDs[0] ); ++i )
2746     {
2747         const FeatureState aFeatureState = GetState( nCommandIDs[i] );
2748 
2749         ::rtl::OUString sCommandURL( getURLForId( nCommandIDs[i] ).Main );
2750         OSL_ENSURE( sCommandURL.indexOfAsciiL( ".uno:", 5 ) == 0, "OReportController::getViewData: illegal command URL!" );
2751         sCommandURL = sCommandURL.copy( 5 );
2752 
2753         Any aCommandState;
2754         if ( !!aFeatureState.bChecked )
2755             aCommandState <<= (*aFeatureState.bChecked) ? sal_True : sal_False;
2756         else if ( aFeatureState.aValue.hasValue() )
2757             aCommandState = aFeatureState.aValue;
2758 
2759         aCommandProperties.put( sCommandURL, aCommandState );
2760     }
2761 
2762     ::comphelper::NamedValueCollection aViewData;
2763     aViewData.put( "CommandProperties", aCommandProperties.getPropertyValues() );
2764 
2765     if ( getDesignView() )
2766     {
2767         ::std::vector<sal_uInt16> aCollapsedPositions;
2768         getDesignView()->fillCollapsedSections(aCollapsedPositions);
2769         if ( !aCollapsedPositions.empty() )
2770         {
2771             uno::Sequence<beans::PropertyValue> aCollapsedSections(aCollapsedPositions.size());
2772             beans::PropertyValue* pCollapsedIter = aCollapsedSections.getArray();
2773             ::std::vector<sal_uInt16>::iterator aIter = aCollapsedPositions.begin();
2774             ::std::vector<sal_uInt16>::iterator aEnd = aCollapsedPositions.end();
2775             for (sal_Int32 i = 1; aIter != aEnd ; ++aIter,++pCollapsedIter,++i)
2776             {
2777                 pCollapsedIter->Name = PROPERTY_SECTION + ::rtl::OUString::valueOf(i);
2778                 pCollapsedIter->Value <<= static_cast<sal_Int32>(*aIter);
2779             }
2780 
2781             aViewData.put( "CollapsedSections", aCollapsedSections );
2782         }
2783 
2784         ::boost::shared_ptr<OSectionWindow> pSectionWindow = getDesignView()->getMarkedSection();
2785         if ( pSectionWindow.get() )
2786         {
2787             aViewData.put( "MarkedSection", (sal_Int32)pSectionWindow->getReportSection().getPage()->GetPageNum() );
2788         } // if ( pSectionWindow.get() )
2789     } // if ( getDesignView() )
2790 
2791     aViewData.put( "ZoomFactor", m_nZoomValue );
2792     return uno::makeAny( aViewData.getPropertyValues() );
2793 }
2794 // -----------------------------------------------------------------------------
2795 void SAL_CALL OReportController::restoreViewData(const uno::Any& i_data) throw( uno::RuntimeException )
2796 {
2797     ::osl::MutexGuard aGuard( getMutex() );
2798 
2799     try
2800     {
2801         const ::comphelper::NamedValueCollection aViewData( i_data );
2802 
2803         m_aCollapsedSections = aViewData.getOrDefault( "CollapsedSections", m_aCollapsedSections );
2804         m_nPageNum = aViewData.getOrDefault( "MarkedSection", m_nPageNum );
2805         m_nZoomValue = aViewData.getOrDefault( "ZoomFactor", m_nZoomValue );
2806         // TODO: setting those 3 members is not enough - in theory, restoreViewData can be called when the
2807         // view is fully alive, so we need to reflect those 3 values in the view.
2808         // (At the moment, the method is called only during construction phase)
2809 
2810 
2811         ::comphelper::NamedValueCollection aCommandProperties( aViewData.get( "CommandProperties" ) );
2812         const ::std::vector< ::rtl::OUString > aCommandNames( aCommandProperties.getNames() );
2813 
2814         for (   ::std::vector< ::rtl::OUString >::const_iterator commandName = aCommandNames.begin();
2815                 commandName != aCommandNames.end();
2816                 ++commandName
2817             )
2818         {
2819             const Any& rCommandValue = aCommandProperties.get( *commandName );
2820             if ( !rCommandValue.hasValue() )
2821                 continue;
2822 
2823             if ( getView() )
2824             {
2825                 util::URL aCommand;
2826                 aCommand.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ) ) + *commandName;
2827 
2828                 Sequence< PropertyValue > aCommandArgs(1);
2829                 aCommandArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Value" ) );
2830                 aCommandArgs[0].Value = rCommandValue;
2831 
2832                 executeUnChecked( aCommand, aCommandArgs );
2833             }
2834             else
2835             {
2836                 if ( commandName->equalsAscii( "ShowRuler" ) )
2837                     OSL_VERIFY( rCommandValue >>= m_bShowRuler );
2838                 else if ( commandName->equalsAscii( "HelplinesMove" ) )
2839                     OSL_VERIFY( rCommandValue >>= m_bHelplinesMove );
2840                 else if ( commandName->equalsAscii( "GridVisible" ) )
2841                     OSL_VERIFY( rCommandValue >>= m_bGridVisible );
2842                 else if ( commandName->equalsAscii( "GridUse" ) )
2843                     OSL_VERIFY( rCommandValue >>= m_bGridUse );
2844                 else if ( commandName->equalsAscii( "ControlProperties" ) )
2845                     OSL_VERIFY( rCommandValue >>= m_bShowProperties );
2846                 else if ( commandName->equalsAscii( "LastPropertyBrowserPage" ) )
2847                     OSL_VERIFY( rCommandValue >>= m_sLastActivePage );
2848                 else if ( commandName->equalsAscii( "SplitPosition" ) )
2849                     OSL_VERIFY( rCommandValue >>= m_nSplitPos );
2850             }
2851         }
2852     }
2853     catch ( const IllegalArgumentException& e )
2854     {
2855         DBG_UNHANDLED_EXCEPTION();
2856     }
2857 }
2858 // -----------------------------------------------------------------------------
2859 void OReportController::updateFloater()
2860 {
2861    	if ( m_pGroupsFloater && m_pGroupsFloater->IsVisible() )
2862 		m_pGroupsFloater->UpdateData();
2863 }
2864 
2865 // -----------------------------------------------------------------------------
2866 Reference<XFrame> OReportController::getXFrame()
2867 {
2868     if ( !m_xFrameLoader.is() )
2869     {
2870         m_xFrameLoader.set(getORB()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"))),uno::UNO_QUERY_THROW);
2871     }
2872     const sal_Int32 nFrameSearchFlag = frame::FrameSearchFlag::TASKS | frame::FrameSearchFlag::CREATE;
2873     const ::rtl::OUString sTarget(RTL_CONSTASCII_USTRINGPARAM("_blank"));
2874     Reference<XFrame> xFrame = Reference<XFrame>(m_xFrameLoader,uno::UNO_QUERY_THROW)->findFrame(sTarget,nFrameSearchFlag);
2875     return xFrame;
2876 }
2877 
2878 // -----------------------------------------------------------------------------
2879 uno::Reference<frame::XModel> OReportController::executeReport()
2880 {
2881     OSL_ENSURE(m_xReportDefinition.is(),"Where is my report?");
2882 
2883     uno::Reference<frame::XModel> xModel;
2884     if ( m_xReportDefinition.is() )
2885     {
2886         sal_uInt16 nErrorId = RID_ERR_NO_COMMAND;
2887         bool bEnabled = m_xReportDefinition->getCommand().getLength() != 0;
2888         if ( bEnabled )
2889         {
2890             bEnabled = false;
2891 	        const sal_uInt16 nCount = m_aReportModel->GetPageCount();
2892             sal_uInt16 i = 0;
2893             for (; i < nCount && !bEnabled ; ++i)
2894             {
2895                 const SdrPage* pPage = m_aReportModel->GetPage(i);
2896                 bEnabled = pPage->GetObjCount() != 0;
2897             }
2898             if ( !bEnabled )
2899                 nErrorId = RID_ERR_NO_OBJECTS;
2900         }
2901 
2902         dbtools::SQLExceptionInfo aInfo;
2903         if ( !bEnabled )
2904         {
2905             sdb::SQLContext aFirstMessage;
2906             String sInfo = String( ModuleRes( nErrorId ) );
2907             aFirstMessage.Message = sInfo;
2908             aInfo = aFirstMessage;
2909             if ( isEditable() )
2910             {
2911                 sal_uInt16 nCommand = 0;
2912                 if ( nErrorId == RID_ERR_NO_COMMAND )
2913                 {
2914                     if ( !m_bShowProperties )
2915                         executeUnChecked(SID_SHOW_PROPERTYBROWSER,uno::Sequence< beans::PropertyValue>());
2916 
2917                     m_sLastActivePage = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Data"));
2918                     getDesignView()->setCurrentPage(m_sLastActivePage);
2919                     nCommand = SID_SELECT_REPORT;
2920                 }
2921                 else if ( getDesignView() && !getDesignView()->isAddFieldVisible() )
2922                 {
2923                     nCommand = SID_FM_ADD_FIELD;
2924                 }
2925                 if ( nCommand )
2926                 {
2927                     uno::Sequence< beans::PropertyValue> aArgs;
2928                     executeUnChecked(nCommand,aArgs);
2929                 }
2930             }
2931         }
2932         else
2933         {
2934             m_bInGeneratePreview = true;
2935             try
2936             {
2937                 WaitObject aWait(getView()); // cursor
2938                 if ( !m_xReportEngine.is() )
2939                     m_xReportEngine.set(getORB()->createInstance(SERVICE_REPORTENGINE),uno::UNO_QUERY_THROW);
2940                 m_xReportEngine->setReportDefinition(m_xReportDefinition);
2941                 m_xReportEngine->setActiveConnection(getConnection());
2942                 Reference<XFrame> xFrame = getXFrame();
2943                 xModel = m_xReportEngine->createDocumentAlive(xFrame);
2944             }
2945             catch( const sdbc::SQLException& /*e*/ )
2946             {   // SQLExceptions and derived exceptions must not be translated
2947                 aInfo = ::cppu::getCaughtException();
2948             }
2949             catch(const uno::Exception& e)
2950             {
2951                 uno::Any aCaughtException( ::cppu::getCaughtException() );
2952 
2953                 // our first message says: we caught an exception
2954                 sdb::SQLContext aFirstMessage;
2955                 String sInfo = String( ModuleRes( RID_STR_CAUGHT_FOREIGN_EXCEPTION ) );
2956                 sInfo.SearchAndReplaceAllAscii( "$type$", aCaughtException.getValueTypeName() );
2957                 aFirstMessage.Message = sInfo;
2958 
2959                 // our second message: the message of the exception we caught
2960                 sdbc::SQLException aSecondMessage;
2961                 aSecondMessage.Message = e.Message;
2962                 aSecondMessage.Context = e.Context;
2963 
2964                 // maybe our third message: the message which is wrapped in the exception we caught
2965                 sdbc::SQLException aThirdMessage;
2966                 lang::WrappedTargetException aWrapped;
2967                 if ( aCaughtException >>= aWrapped )
2968                 {
2969                     aThirdMessage.Message = aWrapped.Message;
2970                     aThirdMessage.Context = aWrapped.Context;
2971                 }
2972 
2973                 if ( aThirdMessage.Message.getLength() )
2974                     aSecondMessage.NextException <<= aThirdMessage;
2975                 aFirstMessage.NextException <<= aSecondMessage;
2976 
2977                 aInfo = aFirstMessage;
2978             }
2979             if (aInfo.isValid())
2980             {
2981                 const String suSQLContext = String( ModuleRes( RID_STR_COULD_NOT_CREATE_REPORT ) );
2982                 aInfo.prepend(suSQLContext);
2983             } // if (aInfo.isValid())
2984             m_bInGeneratePreview = false;
2985         }
2986 
2987         if (aInfo.isValid())
2988         {
2989             showError(aInfo);
2990         }
2991     }
2992     return xModel;
2993 }
2994 // -----------------------------------------------------------------------------
2995 uno::Reference< frame::XModel >  SAL_CALL OReportController::getModel(void) throw( uno::RuntimeException )
2996 {
2997 	return m_xReportDefinition.get();
2998 }
2999 // -----------------------------------------------------------------------------
3000 uno::Reference< sdbc::XRowSet > OReportController::getRowSet()
3001 {
3002     OSL_PRECOND( m_xReportDefinition.is(), "OReportController::getRowSet: no report definition?!" );
3003 
3004     if ( m_xRowSet.is() || !m_xReportDefinition.is() )
3005         return m_xRowSet;
3006 
3007     try
3008     {
3009         uno::Reference< sdbc::XRowSet > xRowSet( getORB()->createInstance(
3010             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.RowSet" ) ) ), uno::UNO_QUERY );
3011         uno::Reference< beans::XPropertySet> xRowSetProp( xRowSet, uno::UNO_QUERY_THROW );
3012 
3013         xRowSetProp->setPropertyValue( PROPERTY_ACTIVECONNECTION, uno::makeAny( getConnection() ) );
3014         xRowSetProp->setPropertyValue( PROPERTY_APPLYFILTER, uno::makeAny( sal_True ) );
3015 
3016         ::boost::shared_ptr<AnyConverter> aNoConverter(new AnyConverter());
3017         TPropertyNamePair aPropertyMediation;
3018         aPropertyMediation.insert( TPropertyNamePair::value_type( PROPERTY_COMMAND, TPropertyConverter(PROPERTY_COMMAND,aNoConverter) ) );
3019         aPropertyMediation.insert( TPropertyNamePair::value_type( PROPERTY_COMMANDTYPE, TPropertyConverter(PROPERTY_COMMANDTYPE,aNoConverter) ) );
3020         aPropertyMediation.insert( TPropertyNamePair::value_type( PROPERTY_ESCAPEPROCESSING, TPropertyConverter(PROPERTY_ESCAPEPROCESSING,aNoConverter) ) );
3021         aPropertyMediation.insert( TPropertyNamePair::value_type( PROPERTY_FILTER, TPropertyConverter(PROPERTY_FILTER,aNoConverter) ) );
3022 
3023         m_xRowSetMediator = new OPropertyMediator( m_xReportDefinition.get(), xRowSetProp, aPropertyMediation );
3024         m_xRowSet = xRowSet;
3025     }
3026     catch( const uno::Exception& )
3027     {
3028     	DBG_UNHANDLED_EXCEPTION();
3029     }
3030 
3031     return m_xRowSet;
3032 }
3033 // -----------------------------------------------------------------------------
3034 void OReportController::insertGraphic()
3035 {
3036     const String sTitle(ModuleRes(RID_STR_IMPORT_GRAPHIC));
3037 	// build some arguments for the upcoming dialog
3038 	try
3039 	{
3040         uno::Reference< report::XSection> xSection = getDesignView()->getCurrentSection();
3041 		::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW, SFXWB_GRAPHIC );
3042 		aDialog.SetTitle( sTitle );
3043 
3044         uno::Reference< ui::dialogs::XFilePickerControlAccess > xController(aDialog.GetFilePicker(), UNO_QUERY_THROW);
3045 		xController->setValue(ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, ::cppu::bool2any(sal_True));
3046 		xController->enableControl(ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, sal_False/*sal_True*/);
3047         sal_Bool bLink = sal_True;
3048         xController->setValue( ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, ::cppu::bool2any( bLink ) );
3049 
3050 		if ( ERRCODE_NONE == aDialog.Execute() )
3051         {
3052             xController->getValue( ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0) >>= bLink;
3053             uno::Sequence<beans::PropertyValue> aArgs(2);
3054             aArgs[0].Name = PROPERTY_IMAGEURL;
3055             aArgs[0].Value <<= ::rtl::OUString(aDialog.GetPath());
3056             aArgs[1].Name = PROPERTY_PRESERVEIRI;
3057             aArgs[1].Value <<= bLink;
3058             createControl(aArgs,xSection,::rtl::OUString(),OBJ_DLG_IMAGECONTROL);
3059         }
3060 	}
3061 	catch(Exception&)
3062 	{
3063         DBG_UNHANDLED_EXCEPTION();
3064 	}
3065 }
3066 // -----------------------------------------------------------------------------
3067 ::boost::shared_ptr<rptui::OReportModel> OReportController::getSdrModel() const
3068 {
3069     return m_aReportModel;
3070 }
3071 // -----------------------------------------------------------------------------
3072 ::sal_Bool SAL_CALL OReportController::select( const Any& aSelection ) throw (IllegalArgumentException, RuntimeException)
3073 {
3074     ::osl::MutexGuard aGuard( getMutex() );
3075     ::sal_Bool bRet = sal_True;
3076     if ( getDesignView() )
3077     {
3078         getDesignView()->unmarkAllObjects(NULL);
3079         getDesignView()->SetMode(RPTUI_SELECT);
3080 
3081         uno::Sequence< uno::Reference<report::XReportComponent> > aElements;
3082         if ( aSelection >>= aElements )
3083         {
3084             if ( aElements.getLength() > 0 )
3085                 getDesignView()->showProperties(uno::Reference<uno::XInterface>(aElements[0],uno::UNO_QUERY));
3086             getDesignView()->setMarked(aElements,sal_True);
3087         }
3088         else
3089         {
3090             uno::Reference<uno::XInterface> xObject(aSelection,uno::UNO_QUERY);
3091             uno::Reference<report::XReportComponent> xProp(xObject,uno::UNO_QUERY);
3092             if ( xProp.is() )
3093             {
3094                 getDesignView()->showProperties(xObject);
3095                 aElements.realloc(1);
3096                 aElements[0] = xProp;
3097                 getDesignView()->setMarked(aElements,sal_True);
3098             }
3099             else
3100             {
3101                 uno::Reference<report::XSection> xSection(aSelection,uno::UNO_QUERY);
3102                 if ( !xSection.is() && xObject.is() )
3103                     getDesignView()->showProperties(xObject);
3104                 getDesignView()->setMarked(xSection,xSection.is());
3105             }
3106         }
3107         InvalidateAll();
3108     }
3109     return bRet;
3110 }
3111 // -----------------------------------------------------------------------------
3112 Any SAL_CALL OReportController::getSelection(  ) throw (RuntimeException)
3113 {
3114     ::osl::MutexGuard aGuard( getMutex() );
3115     Any aRet;
3116     if ( getDesignView() )
3117     {
3118         aRet = getDesignView()->getCurrentlyShownProperty();
3119 		if ( !aRet.hasValue() )
3120 			aRet <<= getDesignView()->getCurrentSection();
3121     }
3122     return aRet;
3123 }
3124 // -----------------------------------------------------------------------------
3125 void SAL_CALL OReportController::addSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException)
3126 {
3127     m_aSelectionListeners.addInterface( _Listener );
3128 }
3129 // -----------------------------------------------------------------------------
3130 void SAL_CALL OReportController::removeSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException)
3131 {
3132     m_aSelectionListeners.removeInterface( _Listener );
3133 }
3134 // -----------------------------------------------------------------------------
3135 void OReportController::createNewFunction(const uno::Any& _aValue)
3136 {
3137     uno::Reference< container::XIndexContainer> xFunctions(_aValue,uno::UNO_QUERY_THROW);
3138     const ::rtl::OUString sNewName = String(ModuleRes(RID_STR_FUNCTION));
3139     uno::Reference< report::XFunction> xFunction(report::Function::create(m_xContext));
3140     xFunction->setName(sNewName);
3141     // the call below will also create an undo action -> listener
3142     xFunctions->insertByIndex(xFunctions->getCount(),uno::makeAny(xFunction));
3143 }
3144 // -----------------------------------------------------------------------------
3145 IMPL_LINK( OReportController, OnExecuteReport, void* ,/*_pMemfun*/)
3146 {
3147     //m_nExecuteReportEvent = 0;
3148     executeReport();
3149     return 0L;
3150 }
3151 // -----------------------------------------------------------------------------
3152 void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,const uno::Reference< report::XSection>& _xSection,const ::rtl::OUString& _sFunction,sal_uInt16 _nObjectId)
3153 {
3154     SequenceAsHashMap aMap(_aArgs);
3155     getDesignView()->setMarked(_xSection ,sal_True);
3156     ::boost::shared_ptr<OSectionWindow> pSectionWindow = getDesignView()->getMarkedSection();
3157     if ( !pSectionWindow )
3158         return;
3159 
3160     OSL_ENSURE(pSectionWindow->getReportSection().getSection() == _xSection,"Invalid section after marking the corrct one.");
3161 
3162     sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_LEFTMARGIN);
3163     const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_RIGHTMARGIN);
3164     const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_xReportDefinition,PROPERTY_PAPERSIZE).Width - nRightMargin;
3165     awt::Point aPos = aMap.getUnpackedValueOrDefault(PROPERTY_POSITION,awt::Point(nLeftMargin,0));
3166     if ( aPos.X < nLeftMargin )
3167         aPos.X = nLeftMargin;
3168 
3169     SdrObject* pNewControl = NULL;
3170     uno::Reference< report::XReportComponent> xShapeProp;
3171     if ( _nObjectId == OBJ_CUSTOMSHAPE )
3172     {
3173         pNewControl = SdrObjFactory::MakeNewObject( ReportInventor, _nObjectId, pSectionWindow->getReportSection().getPage(),m_aReportModel.get() );
3174         xShapeProp.set(pNewControl->getUnoShape(),uno::UNO_QUERY);
3175 		::rtl::OUString sCustomShapeType = getDesignView()->GetInsertObjString();
3176         if ( !sCustomShapeType.getLength() )
3177             sCustomShapeType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("diamond"));
3178         pSectionWindow->getReportSection().createDefault(sCustomShapeType,pNewControl);
3179 		pNewControl->SetLogicRect(Rectangle(3000,500,6000,3500)); // switch height and width
3180     } // if ( _nObjectId == OBJ_CUSTOMSHAPE )
3181     else if ( _nObjectId == OBJ_OLE2 || OBJ_DLG_SUBREPORT == _nObjectId  )
3182     {
3183         pNewControl = SdrObjFactory::MakeNewObject( ReportInventor, _nObjectId, pSectionWindow->getReportSection().getPage(),m_aReportModel.get() );
3184 
3185         pNewControl->SetLogicRect(Rectangle(3000,500,8000,5500)); // switch height and width
3186         xShapeProp.set(pNewControl->getUnoShape(),uno::UNO_QUERY_THROW);
3187         OOle2Obj* pObj = dynamic_cast<OOle2Obj*>(pNewControl);
3188         if ( pObj && !pObj->IsEmpty() )
3189         {
3190             pObj->initializeChart(getModel());
3191         }
3192     }
3193     else
3194     {
3195         SdrUnoObj* pLabel( NULL );
3196         SdrUnoObj* pControl( NULL );
3197         FmFormView::createControlLabelPair( getDesignView()
3198                             ,nLeftMargin,0
3199                             ,NULL,NULL,_nObjectId,::rtl::OUString(),ReportInventor,OBJ_DLG_FIXEDTEXT,
3200  					    NULL,pSectionWindow->getReportSection().getPage(),m_aReportModel.get(),
3201  					    pLabel,pControl);
3202         delete pLabel;
3203 
3204         pNewControl = pControl;
3205         OUnoObject* pObj = dynamic_cast<OUnoObject*>(pControl);
3206         uno::Reference<beans::XPropertySet> xUnoProp(pObj->GetUnoControlModel(),uno::UNO_QUERY);
3207         xShapeProp.set(pObj->getUnoShape(),uno::UNO_QUERY);
3208         uno::Reference<beans::XPropertySetInfo> xShapeInfo = xShapeProp->getPropertySetInfo();
3209         uno::Reference<beans::XPropertySetInfo> xInfo = xUnoProp->getPropertySetInfo();
3210 
3211         const ::rtl::OUString sProps[] = {   PROPERTY_NAME
3212                                             ,PROPERTY_FONTDESCRIPTOR
3213                                             ,PROPERTY_FONTDESCRIPTORASIAN
3214                                             ,PROPERTY_FONTDESCRIPTORCOMPLEX
3215                                             ,PROPERTY_ORIENTATION
3216                                             ,PROPERTY_BORDER
3217                                             ,PROPERTY_FORMATSSUPPLIER
3218                                             ,PROPERTY_BACKGROUNDCOLOR
3219         };
3220         for(size_t i = 0; i < sizeof(sProps)/sizeof(sProps[0]);++i)
3221         {
3222             if ( xInfo->hasPropertyByName(sProps[i]) && xShapeInfo->hasPropertyByName(sProps[i]) )
3223                 xUnoProp->setPropertyValue(sProps[i],xShapeProp->getPropertyValue(sProps[i]));
3224         } // for(size_t i = 0; i < sizeof(sProps)/sizeof(sProps[0]);++i)
3225 
3226         if ( xInfo->hasPropertyByName(PROPERTY_BORDER) && xShapeInfo->hasPropertyByName(PROPERTY_CONTROLBORDER) )
3227             xUnoProp->setPropertyValue(PROPERTY_BORDER,xShapeProp->getPropertyValue(PROPERTY_CONTROLBORDER));
3228 
3229 
3230         if ( xInfo->hasPropertyByName(PROPERTY_DATAFIELD) && _sFunction.getLength() )
3231         {
3232             ReportFormula aFunctionFormula( ReportFormula::Expression, _sFunction );
3233             xUnoProp->setPropertyValue( PROPERTY_DATAFIELD, uno::makeAny( aFunctionFormula.getCompleteFormula() ) );
3234         }
3235 
3236         sal_Int32 nFormatKey = aMap.getUnpackedValueOrDefault(PROPERTY_FORMATKEY,sal_Int32(0));
3237         if ( nFormatKey && xInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
3238             xUnoProp->setPropertyValue( PROPERTY_FORMATKEY, uno::makeAny( nFormatKey ) );
3239 
3240         ::rtl::OUString sUrl = aMap.getUnpackedValueOrDefault(PROPERTY_IMAGEURL,::rtl::OUString());
3241         if ( sUrl.getLength() && xInfo->hasPropertyByName(PROPERTY_IMAGEURL) )
3242             xUnoProp->setPropertyValue( PROPERTY_IMAGEURL, uno::makeAny( sUrl ) );
3243 
3244         pObj->CreateMediator(sal_True);
3245 
3246         if ( _nObjectId == OBJ_DLG_FIXEDTEXT ) // special case for fixed text
3247             xUnoProp->setPropertyValue(PROPERTY_LABEL,uno::makeAny(OUnoObject::GetDefaultName(pObj)));
3248         else if ( _nObjectId == OBJ_DLG_VFIXEDLINE )
3249         {
3250             awt::Size aOlSize = xShapeProp->getSize();
3251             xShapeProp->setSize(awt::Size(aOlSize.Height,aOlSize.Width)); // switch height and width
3252         }
3253     }
3254 
3255     const sal_Int32 nShapeWidth = aMap.getUnpackedValueOrDefault(PROPERTY_WIDTH,xShapeProp->getWidth());
3256     if ( nShapeWidth != xShapeProp->getWidth() )
3257         xShapeProp->setWidth( nShapeWidth );
3258 
3259     const bool bChangedPos = (aPos.X + nShapeWidth) > nPaperWidth;
3260     if ( bChangedPos )
3261         aPos.X = nPaperWidth - nShapeWidth;
3262     xShapeProp->setPosition(aPos);
3263 
3264     correctOverlapping(pNewControl,pSectionWindow->getReportSection());
3265 }
3266 // -----------------------------------------------------------------------------
3267 void OReportController::createDateTime(const Sequence< PropertyValue >& _aArgs)
3268 {
3269     getDesignView()->unmarkAllObjects(NULL);
3270 
3271     const String sUndoAction(ModuleRes(RID_STR_UNDO_INSERT_CONTROL));
3272     UndoContext aUndoContext( getUndoManager(), sUndoAction );
3273 
3274     SequenceAsHashMap aMap(_aArgs);
3275     aMap.createItemIfMissing(PROPERTY_FORMATKEY,aMap.getUnpackedValueOrDefault(PROPERTY_FORMATKEYDATE,sal_Int32(0)));
3276 
3277     uno::Reference< report::XSection> xSection = aMap.getUnpackedValueOrDefault(PROPERTY_SECTION,uno::Reference< report::XSection>());
3278     ::rtl::OUString sFunction;
3279 
3280     sal_Bool bDate = aMap.getUnpackedValueOrDefault(PROPERTY_DATE_STATE,sal_False);
3281     if ( bDate )
3282     {
3283         sFunction = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("TODAY()"));
3284         createControl(aMap.getAsConstPropertyValueList(),xSection,sFunction);
3285     }
3286     sal_Bool bTime = aMap.getUnpackedValueOrDefault(PROPERTY_TIME_STATE,sal_False);
3287     if ( bTime )
3288     {
3289         sFunction = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("TIMEVALUE(NOW())"));
3290         aMap[PROPERTY_FORMATKEY] <<= aMap.getUnpackedValueOrDefault(PROPERTY_FORMATKEYTIME,sal_Int32(0));
3291         createControl(aMap.getAsConstPropertyValueList(),xSection,sFunction);
3292     }
3293 }
3294 // -----------------------------------------------------------------------------
3295 void OReportController::createPageNumber(const Sequence< PropertyValue >& _aArgs)
3296 {
3297     getDesignView()->unmarkAllObjects(NULL);
3298 
3299     const String sUndoAction(ModuleRes(RID_STR_UNDO_INSERT_CONTROL));
3300     UndoContext aUndoContext( getUndoManager(), sUndoAction );
3301 
3302     if ( !m_xReportDefinition->getPageHeaderOn() )
3303 	{
3304 		uno::Sequence< beans::PropertyValue > aArgs;
3305 		executeChecked(SID_PAGEHEADERFOOTER,aArgs);
3306 	} // if ( !m_xHoldAlive->getPageHeaderOn() )
3307 
3308     SequenceAsHashMap aMap(_aArgs);
3309     sal_Bool bStateOfPage = aMap.getUnpackedValueOrDefault(PROPERTY_STATE,sal_False);
3310 
3311     String sFunction = String(ModuleRes(STR_RPT_PN_PAGE));
3312     ::rtl::OUString sPageNumber(RTL_CONSTASCII_USTRINGPARAM("PageNumber()"));
3313     sFunction.SearchAndReplace(String::CreateFromAscii("#PAGENUMBER#"),sPageNumber);
3314 
3315     if ( bStateOfPage )
3316     {
3317         ::rtl::OUString sPageCount(RTL_CONSTASCII_USTRINGPARAM("PageCount()"));
3318         sFunction += String(ModuleRes(STR_RPT_PN_PAGE_OF));
3319         sFunction.SearchAndReplace(String::CreateFromAscii("#PAGECOUNT#"),sPageCount);
3320     }
3321 
3322     sal_Bool bInPageHeader = aMap.getUnpackedValueOrDefault(PROPERTY_PAGEHEADERON,sal_True);
3323     createControl(_aArgs,bInPageHeader ? m_xReportDefinition->getPageHeader() : m_xReportDefinition->getPageFooter(),sFunction);
3324 }
3325 
3326 // -----------------------------------------------------------------------------
3327 void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs)
3328 {
3329     getDesignView()->unmarkAllObjects(NULL);
3330 	//////////////////////////////////////////////////////////////////////
3331 	// Anhand des FormatKeys wird festgestellt, welches Feld benoetigt wird
3332     ::boost::shared_ptr<OSectionWindow> pSectionWindow[2];
3333     pSectionWindow[0] = getDesignView()->getMarkedSection();
3334 
3335 	if ( !pSectionWindow[0] )
3336     {
3337         select(uno::makeAny(m_xReportDefinition->getDetail()));
3338         pSectionWindow[0] = getDesignView()->getMarkedSection();
3339         if ( !pSectionWindow[0] )
3340             return;
3341     }
3342 
3343     uno::Reference<report::XSection> xCurrentSection = getDesignView()->getCurrentSection();
3344     UndoContext aUndoContext( getUndoManager(), String( ModuleRes( RID_STR_UNDO_INSERT_CONTROL ) ) );
3345 
3346     try
3347     {
3348         bool bHandleOnlyOne = false;
3349         const PropertyValue* pIter = aArgs.getConstArray();
3350         const PropertyValue* pEnd  = pIter + aArgs.getLength();
3351         for(;pIter != pEnd && !bHandleOnlyOne;++pIter)
3352         {
3353             Sequence< PropertyValue > aValue;
3354             if ( !(pIter->Value >>= aValue) )
3355             {   // the sequence has only one element which already contains the descriptor
3356                 bHandleOnlyOne = true;
3357                 aValue = aArgs;
3358             }
3359             ::svx::ODataAccessDescriptor aDescriptor(aValue);
3360             SequenceAsHashMap aMap(aValue);
3361             uno::Reference<report::XSection> xSection = aMap.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Section")),xCurrentSection);
3362             uno::Reference<report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
3363 
3364             getDesignView()->setMarked(xSection,sal_True);
3365             pSectionWindow[0] = getDesignView()->getMarkedSection();
3366 
3367             sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_LEFTMARGIN);
3368             awt::Point aPos = aMap.getUnpackedValueOrDefault(PROPERTY_POSITION,awt::Point(nLeftMargin,0));
3369             if ( aPos.X < nLeftMargin )
3370                 aPos.X = nLeftMargin;
3371 
3372 		    // LLA: new feature, add the Label in dependency of the given DND_ACTION one section up, normal or one section down
3373 		    sal_Int8 nDNDAction = aMap.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DNDAction")), sal_Int8(0));
3374 		    pSectionWindow[1] = pSectionWindow[0];
3375 		    // ::boost::shared_ptr<OReportSection> pReportSectionPost;
3376 		    sal_Bool bLabelAboveTextField = nDNDAction == DND_ACTION_COPY;
3377 		    if ( bLabelAboveTextField || nDNDAction == DND_ACTION_LINK )
3378 		    {
3379 			    // Add the Label one Section up
3380                 pSectionWindow[1] = getDesignView()->getMarkedSection(bLabelAboveTextField ? PREVIOUS : POST);
3381 			    if (!pSectionWindow[1])
3382 			    {
3383 				    // maybe out of bounds
3384 				    pSectionWindow[1] = pSectionWindow[0];
3385 			    }
3386 		    }
3387             // clear all selections
3388             getDesignView()->unmarkAllObjects(NULL);
3389 
3390             uno::Reference< beans::XPropertySet > xField( aDescriptor[ ::svx::daColumnObject ], uno::UNO_QUERY );
3391             uno::Reference< lang::XComponent > xHoldAlive;
3392             if ( !xField.is() )
3393             {
3394                 ::rtl::OUString sCommand;
3395                 ::rtl::OUString sColumnName;
3396                 sal_Int32 nCommandType( -1 );
3397                 OSL_VERIFY( aDescriptor[ ::svx::daCommand ] >>= sCommand );
3398                 OSL_VERIFY( aDescriptor[ ::svx::daColumnName ] >>= sColumnName );
3399                 OSL_VERIFY( aDescriptor[ ::svx::daCommandType ] >>= nCommandType );
3400 
3401                 uno::Reference< container::XNameAccess > xColumns;
3402                 uno::Reference< sdbc::XConnection > xConnection( getConnection() );
3403                 if ( sCommand.getLength() && nCommandType != -1 && sColumnName.getLength() && xConnection.is() )
3404                 {
3405                     if ( !xReportDefinition->getCommand().getLength() )
3406                     {
3407                         xReportDefinition->setCommand(sCommand);
3408                         xReportDefinition->setCommandType(nCommandType);
3409                     } // if ( !xReportDefinition->getCommand().getLength() )
3410 
3411 			        xColumns = dbtools::getFieldsByCommandDescriptor(xConnection,nCommandType,sCommand,xHoldAlive);
3412                     if ( xColumns.is() && xColumns->hasByName(sColumnName) )
3413                         xField.set( xColumns->getByName( sColumnName ), uno::UNO_QUERY );
3414                 }
3415 
3416                 if ( !xField.is() )
3417                 {
3418                 #if OSL_DEBUG_LEVEL > 0
3419                     try
3420                     {
3421                         uno::Reference< beans::XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
3422                         ::rtl::OUString sRowSetCommand;
3423                         sal_Int32 nRowSetCommandType( -1 );
3424                         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMAND ) >>= sRowSetCommand );
3425                         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMANDTYPE ) >>= nRowSetCommandType );
3426                         OSL_ENSURE( ( sRowSetCommand == sCommand ) && ( nCommandType == nRowSetCommandType ),
3427                             "OReportController::addPairControls: this only works for a data source which equals our current settings!" );
3428                         // if this asserts, then either our row set and our report definition are not in sync, or somebody
3429                         // requested the creation of a control/pair for another data source than what our report
3430                         // definition is bound to - which is not supported for the parameters case, since we
3431                         // can retrieve parameters from the RowSet only.
3432                     }
3433                     catch( const Exception& )
3434                     {
3435             	        DBG_UNHANDLED_EXCEPTION();
3436                     }
3437                 #endif
3438 
3439                     // no column name - perhaps a parameter name?
3440                     uno::Reference< sdb::XParametersSupplier > xSuppParam( getRowSet(), uno::UNO_QUERY_THROW );
3441                     uno::Reference< container::XIndexAccess > xParams( xSuppParam->getParameters(), uno::UNO_QUERY_THROW );
3442                     sal_Int32 nParamCount( xParams->getCount() );
3443                     for ( sal_Int32 i=0; i<nParamCount; ++i)
3444                     {
3445                         uno::Reference< beans::XPropertySet > xParamCol( xParams->getByIndex(i), uno::UNO_QUERY_THROW );
3446                         ::rtl::OUString sParamName;
3447                         OSL_VERIFY( xParamCol->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ) ) >>= sParamName );
3448                         if ( sParamName == sColumnName )
3449                         {
3450                             xField = xParamCol;
3451                             break;
3452                         }
3453                     }
3454                 }
3455             }
3456 		    if ( !xField.is() )
3457                 continue;
3458 
3459             sal_uInt16 nOBJID = 0;
3460 		    sal_Int32 nDataType = sdbc::DataType::BINARY;
3461 		    xField->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
3462 		    switch ( nDataType )
3463 		    {
3464                 case sdbc::DataType::BINARY:
3465 			    case sdbc::DataType::VARBINARY:
3466 			    case sdbc::DataType::LONGVARBINARY:
3467 				    nOBJID = OBJ_DLG_IMAGECONTROL;
3468 				    break;
3469 			    default:
3470 				    nOBJID = OBJ_DLG_FORMATTEDFIELD;
3471 				    break;
3472 		    }
3473 
3474             if ( !nOBJID )
3475                 continue;
3476 
3477             Reference< util::XNumberFormatsSupplier >  xSupplier = getReportNumberFormatter()->getNumberFormatsSupplier();
3478             if ( !xSupplier.is() )
3479                 continue;
3480 
3481             Reference< XNumberFormats >  xNumberFormats(xSupplier->getNumberFormats());
3482 		    SdrUnoObj* pControl[2];
3483 		    pControl[0] = NULL;
3484 		    pControl[1] = NULL;
3485             //getDesignView()->GetModel()->GetUndoEnv().Lock();
3486             const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_RIGHTMARGIN);
3487             const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_xReportDefinition,PROPERTY_PAPERSIZE).Width - nRightMargin;
3488 		    OSectionView* pSectionViews[2];
3489 		    pSectionViews[0] = &pSectionWindow[1]->getReportSection().getSectionView();
3490 		    pSectionViews[1] = &pSectionWindow[0]->getReportSection().getSectionView();
3491             // find this in svx
3492 		    FmFormView::createControlLabelPair( getDesignView()
3493                 ,nLeftMargin,0
3494                 ,xField,xNumberFormats,nOBJID,::rtl::OUString(),ReportInventor,OBJ_DLG_FIXEDTEXT,
3495 			    pSectionWindow[1]->getReportSection().getPage(),pSectionWindow[0]->getReportSection().getPage(),m_aReportModel.get(),
3496 			    pControl[0],pControl[1]);
3497             //getDesignView()->GetModel()->GetUndoEnv().UnLock();
3498 		    if ( pControl[0] && pControl[1] )
3499 		    {
3500 			    SdrPageView* pPgViews[2];
3501 			    pPgViews[0] = pSectionViews[0]->GetSdrPageView();
3502 			    pPgViews[1] = pSectionViews[1]->GetSdrPageView();
3503 			    if ( pPgViews[0] && pPgViews[1] )
3504 			    {
3505                     ::rtl::OUString sDefaultName;
3506                     size_t i = 0;
3507                     OUnoObject* pObjs[2];
3508 				    for(i = 0; i < sizeof(pControl)/sizeof(pControl[0]);++i)
3509 				    {
3510                         pObjs[i] = dynamic_cast<OUnoObject*>(pControl[i]);
3511                         uno::Reference<beans::XPropertySet> xUnoProp(pObjs[i]->GetUnoControlModel(),uno::UNO_QUERY_THROW);
3512                         uno::Reference< report::XReportComponent> xShapeProp(pObjs[i]->getUnoShape(),uno::UNO_QUERY_THROW);
3513                         xUnoProp->setPropertyValue(PROPERTY_NAME,xShapeProp->getPropertyValue(PROPERTY_NAME));
3514 
3515                         uno::Reference<beans::XPropertySetInfo> xShapeInfo = xShapeProp->getPropertySetInfo();
3516                         uno::Reference<beans::XPropertySetInfo> xInfo = xUnoProp->getPropertySetInfo();
3517                         const ::rtl::OUString sProps[] = {   PROPERTY_FONTDESCRIPTOR
3518                                                             ,PROPERTY_FONTDESCRIPTORASIAN
3519                                                             ,PROPERTY_FONTDESCRIPTORCOMPLEX
3520                                                             ,PROPERTY_BORDER
3521                                                             ,PROPERTY_BACKGROUNDCOLOR
3522                         };
3523                         for(size_t k = 0; k < sizeof(sProps)/sizeof(sProps[0]);++k)
3524                         {
3525                             if ( xInfo->hasPropertyByName(sProps[k]) && xShapeInfo->hasPropertyByName(sProps[k]) )
3526                                 xUnoProp->setPropertyValue(sProps[k],xShapeProp->getPropertyValue(sProps[k]));
3527                         }
3528                         if ( xInfo->hasPropertyByName(PROPERTY_DATAFIELD) )
3529                         {
3530                             ::rtl::OUString sName;
3531                             xUnoProp->getPropertyValue(PROPERTY_DATAFIELD) >>= sName;
3532                             sDefaultName = sName;
3533                             xUnoProp->setPropertyValue(PROPERTY_NAME,uno::makeAny(sDefaultName));
3534 
3535                             ReportFormula aFormula( ReportFormula::Field, sName );
3536                             xUnoProp->setPropertyValue( PROPERTY_DATAFIELD, uno::makeAny( aFormula.getCompleteFormula() ) );
3537                         } // if ( xInfo->hasPropertyByName(PROPERTY_DATAFIELD) )
3538 
3539                         if ( xInfo->hasPropertyByName(PROPERTY_BORDER) && xShapeInfo->hasPropertyByName(PROPERTY_CONTROLBORDER) )
3540                             xUnoProp->setPropertyValue(PROPERTY_BORDER,xShapeProp->getPropertyValue(PROPERTY_CONTROLBORDER));
3541 
3542                         pObjs[i]->CreateMediator(sal_True);
3543                         // need SectionView from the above or follow Section
3544                         // (getMarkedSection) returns the current Section
3545                         //pSectionViews[i]->InsertObjectAtView(pControl[i],*pPgViews[i],SDRINSERT_ADDMARK);
3546 
3547                         const sal_Int32 nShapeWidth = xShapeProp->getWidth();
3548                         const bool bChangedPos = (aPos.X + nShapeWidth) > nPaperWidth;
3549                         if ( bChangedPos )
3550                             aPos.X = nPaperWidth - nShapeWidth;
3551                         xShapeProp->setPosition(aPos);
3552                         if ( bChangedPos )
3553                             aPos.Y += xShapeProp->getHeight();
3554                         aPos.X += nShapeWidth;
3555 				    }
3556                     ::rtl::OUString sLabel;
3557                     if ( xField->getPropertySetInfo()->hasPropertyByName(PROPERTY_LABEL) )
3558                         xField->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
3559 
3560 				    if (pSectionViews[0] != pSectionViews[1] &&
3561 					    nOBJID == OBJ_DLG_FORMATTEDFIELD) // we want this nice feature only at FORMATTEDFIELD
3562 				    {
3563 					    // we have two different Views, so set the position x new.
3564 					    // pSectionViews[1].position.x = pSectionViews[0].position.x
3565                         uno::Reference< report::XReportComponent> xShapePropLabel(pObjs[0]->getUnoShape(),uno::UNO_QUERY_THROW);
3566                         uno::Reference< report::XReportComponent> xShapePropTextField(pObjs[1]->getUnoShape(),uno::UNO_QUERY_THROW);
3567                         if ( sLabel.getLength() )
3568                             xShapePropTextField->setName(sLabel);
3569 					    awt::Point aPosLabel = xShapePropLabel->getPosition();
3570 					    awt::Point aPosTextField = xShapePropTextField->getPosition();
3571 					    aPosTextField.X = aPosLabel.X;
3572 					    xShapePropTextField->setPosition(aPosTextField);
3573 					    if (bLabelAboveTextField)
3574 					    {
3575 						    // move the label down near the splitter
3576 						    const uno::Reference<report::XSection> xLabelSection = pSectionWindow[1]->getReportSection().getSection();
3577 						    aPosLabel.Y = xLabelSection->getHeight() - xShapePropLabel->getHeight();
3578 					    }
3579 					    else
3580 					    {
3581 						    // move the label up to the splitter
3582 						    aPosLabel.Y = 0;
3583 					    }
3584 					    xShapePropLabel->setPosition(aPosLabel);
3585 				    }
3586                     OUnoObject* pObj = dynamic_cast<OUnoObject*>(pControl[0]);
3587                     uno::Reference< report::XFixedText> xShapeProp(pObj->getUnoShape(),uno::UNO_QUERY_THROW);
3588                     xShapeProp->setName(xShapeProp->getName() + sDefaultName );
3589 
3590                     for(i = 0; i < sizeof(pControl)/sizeof(pControl[0]);++i) // insert controls
3591                     {
3592                         correctOverlapping(pControl[i],pSectionWindow[1-i]->getReportSection());
3593                     }
3594 
3595                     if (!bLabelAboveTextField )
3596                     {
3597 						if ( pSectionViews[0] == pSectionViews[1] )
3598                         {
3599 							Rectangle aLabel = getRectangleFromControl(pControl[0]);
3600 							Rectangle aTextfield = getRectangleFromControl(pControl[1]);
3601 
3602 							// create a Union of the given Label and Textfield
3603 							Rectangle aLabelAndTextfield( aLabel );
3604                             aLabelAndTextfield.Union(aTextfield);
3605 
3606 							// check if there exists other fields and if yes, move down
3607                             bool bOverlapping = true;
3608 							bool bHasToMove = false;
3609                             while ( bOverlapping )
3610                             {
3611                                 const SdrObject* pOverlappedObj = isOver(aLabelAndTextfield, *pSectionWindow[0]->getReportSection().getPage(), *pSectionViews[0], true, pControl, 2);
3612                                 bOverlapping = pOverlappedObj != NULL;
3613                                 if ( bOverlapping )
3614                                 {
3615                                     const Rectangle& aLogicRect = pOverlappedObj->GetLogicRect();
3616                                     aLabelAndTextfield.Move(0,aLogicRect.Top() + aLogicRect.getHeight() - aLabelAndTextfield.Top());
3617 									bHasToMove = true;
3618                                 }
3619                             }
3620 
3621 							if (bHasToMove)
3622 							{
3623 								// There was a move down, we need to move the Label and the Textfield down
3624 								aLabel.Move(0, aLabelAndTextfield.Top() - aLabel.Top());
3625 								aTextfield.Move(0, aLabelAndTextfield.Top() - aTextfield.Top());
3626 
3627 								uno::Reference< report::XReportComponent> xLabel(pControl[0]->getUnoShape(),uno::UNO_QUERY_THROW);
3628 								xLabel->setPositionY(aLabel.Top());
3629 
3630 								uno::Reference< report::XReportComponent> xTextfield(pControl[1]->getUnoShape(),uno::UNO_QUERY_THROW);
3631 								xTextfield->setPositionY(aTextfield.Top());
3632                         }
3633                     }
3634 						// this should never happen.
3635 						// else
3636 						// {
3637 						//	DBG_ERROR("unhandled case.");
3638 						// }
3639 					}
3640 			    }
3641 		    }
3642 		    else
3643             {
3644 			    for(size_t i = 0; i < sizeof(pControl)/sizeof(pControl[0]);++i)
3645 				    delete pControl[i];
3646             }
3647         }
3648     }
3649     catch( const Exception& )
3650     {
3651     	DBG_UNHANDLED_EXCEPTION();
3652     }
3653 }
3654 
3655 // -----------------------------------------------------------------------------
3656 OSectionView* OReportController::getCurrentSectionView() const
3657 {
3658     OSectionView* pSectionView = NULL;
3659     ::boost::shared_ptr<OSectionWindow> pSectionWindow = getDesignView()->getMarkedSection();
3660 	if ( pSectionWindow.get() )
3661         pSectionView = &pSectionWindow->getReportSection().getSectionView();
3662     return pSectionView;
3663 }
3664 // -----------------------------------------------------------------------------
3665 void OReportController::changeZOrder(sal_Int32 _nId)
3666 {
3667     OSectionView* pSectionView = getCurrentSectionView();
3668     if ( pSectionView )
3669     {
3670         switch(_nId)
3671         {
3672             case SID_FRAME_TO_BOTTOM:
3673                 pSectionView->PutMarkedToBtm();
3674                 break;
3675             case SID_FRAME_TO_TOP:
3676                 pSectionView->PutMarkedToTop();
3677                 break;
3678             case SID_FRAME_DOWN:
3679                 pSectionView->MovMarkedToBtm();
3680                 break;
3681             case SID_FRAME_UP:
3682                 pSectionView->MovMarkedToTop();
3683                 break;
3684 
3685             case SID_OBJECT_HEAVEN:
3686                 pSectionView->SetMarkedToLayer( RPT_LAYER_FRONT );
3687                 break;
3688             case SID_OBJECT_HELL:
3689                 pSectionView->SetMarkedToLayer( RPT_LAYER_BACK );
3690                 break;
3691         }
3692     }
3693 }
3694 // -----------------------------------------------------------------------------
3695 void OReportController::listen(const bool _bAdd)
3696 {
3697     const ::rtl::OUString aProps [] = {    PROPERTY_REPORTHEADERON,PROPERTY_REPORTFOOTERON
3698                                             ,PROPERTY_PAGEHEADERON,PROPERTY_PAGEFOOTERON
3699                                             ,PROPERTY_COMMAND, PROPERTY_COMMANDTYPE,PROPERTY_CAPTION
3700     };
3701 
3702     void (SAL_CALL XPropertySet::*pPropertyListenerAction)( const ::rtl::OUString&, const uno::Reference< XPropertyChangeListener >& ) =
3703         _bAdd ? &XPropertySet::addPropertyChangeListener : &XPropertySet::removePropertyChangeListener;
3704 
3705     for (size_t i = 0; i < sizeof(aProps)/sizeof(aProps[0]); ++i)
3706         (m_xReportDefinition.get()->*pPropertyListenerAction)( aProps[i], static_cast< XPropertyChangeListener* >( this ) );
3707 
3708     OXUndoEnvironment& rUndoEnv = m_aReportModel->GetUndoEnv();
3709     uno::Reference< XPropertyChangeListener > xUndo = &rUndoEnv;
3710     uno::Sequence< beans::Property> aSeq = m_xReportDefinition->getPropertySetInfo()->getProperties();
3711     const beans::Property* pIter = aSeq.getConstArray();
3712     const beans::Property* pEnd	  = pIter + aSeq.getLength();
3713     const ::rtl::OUString* pPropsBegin = &aProps[0];
3714     const ::rtl::OUString* pPropsEnd   = pPropsBegin + (sizeof(aProps)/sizeof(aProps[0])) - 3;
3715     for(;pIter != pEnd;++pIter)
3716     {
3717         if ( ::std::find(pPropsBegin,pPropsEnd,pIter->Name) == pPropsEnd )
3718             (m_xReportDefinition.get()->*pPropertyListenerAction)( pIter->Name, xUndo );
3719     }
3720 
3721     // Add Listeners to UndoEnvironment
3722     void (OXUndoEnvironment::*pElementUndoFunction)( const uno::Reference< uno::XInterface >& ) =
3723         _bAdd ? &OXUndoEnvironment::AddElement : &OXUndoEnvironment::RemoveElement;
3724 
3725     (rUndoEnv.*pElementUndoFunction)( m_xReportDefinition->getStyleFamilies() );
3726     (rUndoEnv.*pElementUndoFunction)( m_xReportDefinition->getFunctions() );
3727 
3728     // Add Listeners to ReportControllerObserver
3729     OXReportControllerObserver& rObserver = *m_pReportControllerObserver;
3730     // void (OXReportControllerObserver::*pObserverFunction)( const uno::Reference< uno::XInterface >& ) =
3731     //     _bAdd ? &OXReportControllerObserver::AddElement : &OXReportControllerObserver::RemoveElement;
3732 
3733     // (rObserver.*pObserverFunction)( m_xReportDefinition->getStyleFamilies() );
3734     // (rObserver.*pObserverFunction)( m_xReportDefinition->getFunctions() );
3735 
3736     if ( m_xReportDefinition->getPageHeaderOn() && _bAdd )
3737     {
3738         getDesignView()->addSection(m_xReportDefinition->getPageHeader(),DBPAGEHEADER);
3739         rObserver.AddSection(m_xReportDefinition->getPageHeader());
3740     }
3741 	if ( m_xReportDefinition->getReportHeaderOn() && _bAdd )
3742     {
3743         getDesignView()->addSection(m_xReportDefinition->getReportHeader(),DBREPORTHEADER);
3744         rObserver.AddSection(m_xReportDefinition->getReportHeader());
3745     }
3746 
3747 	uno::Reference< report::XGroups > xGroups = m_xReportDefinition->getGroups();
3748 	const sal_Int32 nCount = xGroups->getCount();
3749     _bAdd ? xGroups->addContainerListener(&rUndoEnv) : xGroups->removeContainerListener(&rUndoEnv);
3750     _bAdd ? xGroups->addContainerListener(&rObserver) : xGroups->removeContainerListener(&rObserver);
3751 
3752 	for (sal_Int32 i=0;i<nCount ; ++i)
3753 	{
3754 		uno::Reference< report::XGroup > xGroup(xGroups->getByIndex(i),uno::UNO_QUERY);
3755         (xGroup.get()->*pPropertyListenerAction)( PROPERTY_HEADERON, static_cast< XPropertyChangeListener* >( this ) );
3756         (xGroup.get()->*pPropertyListenerAction)( PROPERTY_FOOTERON, static_cast< XPropertyChangeListener* >( this ) );
3757 
3758         (rUndoEnv.*pElementUndoFunction)( xGroup );
3759         (rUndoEnv.*pElementUndoFunction)( xGroup->getFunctions() );
3760 		if ( xGroup->getHeaderOn() && _bAdd )
3761         {
3762 			getDesignView()->addSection(xGroup->getHeader(),DBGROUPHEADER);
3763             rObserver.AddSection(xGroup->getHeader());
3764         }
3765 	} // for (sal_Int32 i=0;i<nCount ; ++i)
3766 
3767     if ( _bAdd )
3768     {
3769         getDesignView()->addSection(m_xReportDefinition->getDetail(),DBDETAIL);
3770         rObserver.AddSection(m_xReportDefinition->getDetail());
3771 
3772 	    for (sal_Int32 i=nCount;i > 0 ; --i)
3773 	    {
3774 		    uno::Reference< report::XGroup > xGroup(xGroups->getByIndex(i-1),uno::UNO_QUERY);
3775 		    if ( xGroup->getFooterOn() )
3776             {
3777                 getDesignView()->addSection(xGroup->getFooter(),DBGROUPFOOTER);
3778                 rObserver.AddSection(xGroup->getFooter());
3779 	        }
3780 	    }
3781         if ( m_xReportDefinition->getReportFooterOn() )
3782         {
3783 		    getDesignView()->addSection(m_xReportDefinition->getReportFooter(),DBREPORTFOOTER);
3784             rObserver.AddSection(m_xReportDefinition->getReportFooter());
3785         }
3786 	    if ( m_xReportDefinition->getPageFooterOn())
3787         {
3788 		    getDesignView()->addSection(m_xReportDefinition->getPageFooter(),DBPAGEFOOTER);
3789             rObserver.AddSection(m_xReportDefinition->getPageFooter());
3790         }
3791 
3792         xGroups->addContainerListener(static_cast<XContainerListener*>(this));
3793         m_xReportDefinition->addModifyListener(static_cast<XModifyListener*>(this));
3794     }
3795     else /* ! _bAdd */
3796     {
3797         rObserver.RemoveSection(m_xReportDefinition->getDetail());
3798         xGroups->removeContainerListener(static_cast<XContainerListener*>(this));
3799         m_xReportDefinition->removeModifyListener(static_cast<XModifyListener*>(this));
3800         m_aReportModel->detachController();
3801     }
3802 }
3803 // -----------------------------------------------------------------------------
3804 void OReportController::switchReportSection(const sal_Int16 _nId)
3805 {
3806     OSL_ENSURE(_nId == SID_REPORTHEADER_WITHOUT_UNDO || _nId == SID_REPORTFOOTER_WITHOUT_UNDO || _nId == SID_REPORTHEADERFOOTER ,"Illegal id given!");
3807 
3808 	if ( m_xReportDefinition.is() )
3809 	{
3810 		const OXUndoEnvironment::OUndoEnvLock aLock( m_aReportModel->GetUndoEnv() );
3811 		const bool bSwitchOn = !m_xReportDefinition->getReportHeaderOn();
3812 
3813         ::boost::scoped_ptr< UndoContext > pUndoContext;
3814 		if ( SID_REPORTHEADERFOOTER == _nId )
3815 		{
3816 			const String sUndoAction(ModuleRes(bSwitchOn ? RID_STR_UNDO_ADD_REPORTHEADERFOOTER : RID_STR_UNDO_REMOVE_REPORTHEADERFOOTER));
3817             pUndoContext.reset( new UndoContext( getUndoManager(), sUndoAction ) );
3818 
3819 			addUndoAction(new OReportSectionUndo(*(m_aReportModel),SID_REPORTHEADER_WITHOUT_UNDO
3820 															,::std::mem_fun(&OReportHelper::getReportHeader)
3821 															,m_xReportDefinition
3822 															,bSwitchOn ? Inserted : Removed
3823 															,0
3824 															));
3825 
3826 			addUndoAction(new OReportSectionUndo(*(m_aReportModel),SID_REPORTFOOTER_WITHOUT_UNDO
3827 															,::std::mem_fun(&OReportHelper::getReportFooter)
3828 															,m_xReportDefinition
3829 															,bSwitchOn ? Inserted : Removed
3830 															,0
3831 															));
3832 		}
3833 
3834 		switch( _nId )
3835 		{
3836 			case SID_REPORTHEADER_WITHOUT_UNDO:
3837 				m_xReportDefinition->setReportHeaderOn( bSwitchOn );
3838 				break;
3839 			case SID_REPORTFOOTER_WITHOUT_UNDO:
3840 				m_xReportDefinition->setReportFooterOn( !m_xReportDefinition->getReportFooterOn() );
3841 				break;
3842 			case SID_REPORTHEADERFOOTER:
3843 				m_xReportDefinition->setReportHeaderOn( bSwitchOn );
3844 				m_xReportDefinition->setReportFooterOn( bSwitchOn );
3845 				break;
3846 		}
3847 
3848         if ( SID_REPORTHEADERFOOTER == _nId )
3849             pUndoContext.reset();
3850 		getView()->Resize();
3851 	}
3852 }
3853 // -----------------------------------------------------------------------------
3854 void OReportController::switchPageSection(const sal_Int16 _nId)
3855 {
3856     OSL_ENSURE(_nId == SID_PAGEHEADERFOOTER || _nId == SID_PAGEHEADER_WITHOUT_UNDO || _nId == SID_PAGEFOOTER_WITHOUT_UNDO ,"Illegal id given!");
3857     if ( m_xReportDefinition.is() )
3858 	{
3859 		const OXUndoEnvironment::OUndoEnvLock aLock( m_aReportModel->GetUndoEnv() );
3860 		const bool bSwitchOn = !m_xReportDefinition->getPageHeaderOn();
3861 
3862         ::boost::scoped_ptr< UndoContext > pUndoContext;
3863 		if ( SID_PAGEHEADERFOOTER == _nId )
3864 		{
3865 			const String sUndoAction(ModuleRes(bSwitchOn ? RID_STR_UNDO_ADD_REPORTHEADERFOOTER : RID_STR_UNDO_REMOVE_REPORTHEADERFOOTER));
3866             pUndoContext.reset( new UndoContext( getUndoManager(), sUndoAction ) );
3867 
3868 			addUndoAction(new OReportSectionUndo(*m_aReportModel
3869 															,SID_PAGEHEADER_WITHOUT_UNDO
3870 															,::std::mem_fun(&OReportHelper::getPageHeader)
3871 															,m_xReportDefinition
3872 															,bSwitchOn ? Inserted : Removed
3873 															,0
3874 															));
3875 
3876 			addUndoAction(new OReportSectionUndo(*m_aReportModel
3877 															,SID_PAGEFOOTER_WITHOUT_UNDO
3878 															,::std::mem_fun(&OReportHelper::getPageFooter)
3879 															,m_xReportDefinition
3880 															,bSwitchOn ? Inserted : Removed
3881 															,0
3882 															));
3883 		} // if ( SID_PAGEHEADERFOOTER == _nId )
3884 		switch( _nId )
3885 		{
3886 			case SID_PAGEHEADER_WITHOUT_UNDO:
3887 				m_xReportDefinition->setPageHeaderOn( bSwitchOn );
3888 				break;
3889 			case SID_PAGEFOOTER_WITHOUT_UNDO:
3890 				m_xReportDefinition->setPageFooterOn( !m_xReportDefinition->getPageFooterOn() );
3891 				break;
3892 			case SID_PAGEHEADERFOOTER:
3893 				m_xReportDefinition->setPageHeaderOn( bSwitchOn );
3894 				m_xReportDefinition->setPageFooterOn( bSwitchOn );
3895 				break;
3896 		}
3897         if ( SID_PAGEHEADERFOOTER == _nId )
3898             pUndoContext.reset();
3899 		getView()->Resize();
3900 	}
3901 }
3902 // -----------------------------------------------------------------------------
3903 void OReportController::modifyGroup(const bool _bAppend, const Sequence< PropertyValue >& _aArgs)
3904 {
3905     if ( !m_xReportDefinition.is() )
3906         return;
3907 
3908     try
3909     {
3910 		const SequenceAsHashMap aMap( _aArgs );
3911 		uno::Reference< report::XGroup > xGroup = aMap.getUnpackedValueOrDefault( PROPERTY_GROUP, uno::Reference< report::XGroup >() );
3912         if ( !xGroup.is() )
3913             return;
3914 
3915         OXUndoEnvironment& rUndoEnv = m_aReportModel->GetUndoEnv();
3916 		uno::Reference< report::XGroups > xGroups = m_xReportDefinition->getGroups();
3917 		if ( _bAppend )
3918 		{
3919 			const sal_Int32 nPos = aMap.getUnpackedValueOrDefault( PROPERTY_POSITIONY, xGroups->getCount() );
3920 			xGroups->insertByIndex( nPos, uno::makeAny( xGroup ) );
3921             rUndoEnv.AddElement( xGroup->getFunctions() );
3922 		}
3923 
3924 		addUndoAction( new OGroupUndo(
3925             *m_aReportModel,
3926             _bAppend ? RID_STR_UNDO_APPEND_GROUP : RID_STR_UNDO_REMOVE_GROUP,
3927             _bAppend ? Inserted : Removed,
3928             xGroup,
3929             m_xReportDefinition
3930         ) );
3931 
3932 		if ( !_bAppend )
3933 		{
3934             rUndoEnv.RemoveElement( xGroup->getFunctions() );
3935 			const sal_Int32 nPos = getGroupPosition( xGroup );
3936             const OXUndoEnvironment::OUndoEnvLock aLock( m_aReportModel->GetUndoEnv() );
3937 			xGroups->removeByIndex( nPos );
3938 		}
3939     }
3940     catch( const Exception& )
3941     {
3942         DBG_UNHANDLED_EXCEPTION();
3943     }
3944 }
3945 
3946 // -----------------------------------------------------------------------------
3947 void OReportController::createGroupSection(const bool _bUndo,const bool _bHeader, const Sequence< PropertyValue >& _aArgs)
3948 {
3949     if ( m_xReportDefinition.is() )
3950 	{
3951 		const SequenceAsHashMap aMap(_aArgs);
3952         const sal_Bool bSwitchOn = aMap.getUnpackedValueOrDefault(_bHeader ? PROPERTY_HEADERON : PROPERTY_FOOTERON,sal_False);
3953 		uno::Reference< report::XGroup> xGroup = aMap.getUnpackedValueOrDefault(PROPERTY_GROUP,uno::Reference< report::XGroup>());
3954 		if ( xGroup.is() )
3955 		{
3956             const OXUndoEnvironment::OUndoEnvLock aLock(m_aReportModel->GetUndoEnv());
3957 			if ( _bUndo )
3958 				addUndoAction(new OGroupSectionUndo(*m_aReportModel
3959                                                                 ,_bHeader ? SID_GROUPHEADER_WITHOUT_UNDO : SID_GROUPFOOTER_WITHOUT_UNDO
3960                                                                 ,_bHeader ? ::std::mem_fun(&OGroupHelper::getHeader) : ::std::mem_fun(&OGroupHelper::getFooter)
3961 																,xGroup
3962 																,bSwitchOn ? Inserted : Removed
3963                                                                 , ( _bHeader ?
3964 																        (bSwitchOn ? RID_STR_UNDO_ADD_GROUP_HEADER : RID_STR_UNDO_REMOVE_GROUP_HEADER)
3965                                                                        :(bSwitchOn ? RID_STR_UNDO_ADD_GROUP_FOOTER : RID_STR_UNDO_REMOVE_GROUP_FOOTER)
3966                                                                   )
3967 																));
3968 
3969             if ( _bHeader )
3970 			    xGroup->setHeaderOn( bSwitchOn );
3971             else
3972                 xGroup->setFooterOn( bSwitchOn );
3973 		}
3974 	}
3975 }
3976 // -----------------------------------------------------------------------------
3977 void OReportController::collapseSection(const bool _bCollapse)
3978 {
3979     ::boost::shared_ptr<OSectionWindow> pSection = getDesignView()->getMarkedSection();
3980     if ( pSection )
3981     {
3982         pSection->setCollapsed(_bCollapse);
3983     }
3984 }
3985 // -----------------------------------------------------------------------------
3986 void OReportController::markSection(const bool _bNext)
3987 {
3988     ::boost::shared_ptr<OSectionWindow> pSection = getDesignView()->getMarkedSection();
3989     if ( pSection )
3990     {
3991         ::boost::shared_ptr<OSectionWindow> pPrevSection = getDesignView()->getMarkedSection(_bNext ? POST : PREVIOUS);
3992         if ( pPrevSection != pSection && pPrevSection )
3993             select(uno::makeAny(pPrevSection->getReportSection().getSection()));
3994         else
3995             select(uno::makeAny(m_xReportDefinition));
3996     }
3997     else
3998     {
3999         getDesignView()->markSection(_bNext ? 0 : getDesignView()->getSectionCount() - 1);
4000         pSection = getDesignView()->getMarkedSection();
4001         if ( pSection )
4002             select(uno::makeAny(pSection->getReportSection().getSection()));
4003     }
4004 }
4005 // -----------------------------------------------------------------------------
4006 void OReportController::createDefaultControl(const uno::Sequence< beans::PropertyValue>& _aArgs)
4007 {
4008     uno::Reference< report::XSection > xSection = getDesignView()->getCurrentSection();
4009     if ( !xSection.is() )
4010         xSection = m_xReportDefinition->getDetail();
4011 
4012     if ( xSection.is() )
4013     {
4014         const ::rtl::OUString sKeyModifier(RTL_CONSTASCII_USTRINGPARAM("KeyModifier"));
4015         const beans::PropertyValue* pIter = _aArgs.getConstArray();
4016         const beans::PropertyValue* pEnd  = pIter + _aArgs.getLength();
4017         const beans::PropertyValue* pKeyModifier = ::std::find_if(pIter,pEnd,::std::bind2nd(PropertyValueCompare(),boost::cref(sKeyModifier)));
4018         sal_Int16 nKeyModifier = 0;
4019         if ( pKeyModifier == pEnd || ((pKeyModifier->Value >>= nKeyModifier) && nKeyModifier == KEY_MOD1) )
4020         {
4021             Sequence< PropertyValue > aCreateArgs;
4022             getDesignView()->unmarkAllObjects(NULL);
4023             createControl(aCreateArgs,xSection,::rtl::OUString(),getDesignView()->GetInsertObj());
4024         }
4025     }
4026 }
4027 // -----------------------------------------------------------------------------
4028 uno::Reference< util::XNumberFormatter > OReportController::getReportNumberFormatter() const
4029 {
4030     return m_xFormatter;
4031 }
4032 // -----------------------------------------------------------------------------
4033 void OReportController::checkChartEnabled()
4034 {
4035     if ( !m_bChartEnabledAsked )
4036     {
4037         m_bChartEnabledAsked = true;
4038         const ::rtl::OUString sConfigName( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.ReportDesign" ) );
4039         const ::rtl::OUString sPropertyName( RTL_CONSTASCII_USTRINGPARAM( "UserData/Chart" ) );
4040 
4041         try
4042         {
4043             ::utl::OConfigurationTreeRoot aConfiguration(
4044                 ::utl::OConfigurationTreeRoot::createWithServiceFactory( m_xServiceFactory, sConfigName ) );
4045 
4046             sal_Bool bChartEnabled = sal_False;
4047             if ( aConfiguration.hasByHierarchicalName(sPropertyName) )
4048                 aConfiguration.getNodeValue( sPropertyName ) >>= bChartEnabled;
4049             m_bChartEnabled = bChartEnabled;
4050         }
4051         catch(const Exception&)
4052         {
4053         }
4054     }
4055 }
4056 // -----------------------------------------------------------------------------
4057 
4058 // css.frame.XTitle
4059 ::rtl::OUString SAL_CALL OReportController::getTitle()
4060     throw (uno::RuntimeException)
4061 {
4062     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
4063 	::osl::MutexGuard aGuard( getMutex() );
4064 
4065     uno::Reference< frame::XTitle> xTitle(m_xReportDefinition,uno::UNO_QUERY_THROW);
4066 
4067     return xTitle->getTitle ();
4068 }
4069 // -----------------------------------------------------------------------------
4070 void OReportController::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, Any& _rDefault ) const
4071 {
4072 	_rDefault <<= sal_Int16(100);
4073 }
4074 // -----------------------------------------------------------------------------
4075 // comphelper::OPropertyArrayUsageHelper
4076 ::cppu::IPropertyArrayHelper* OReportController::createArrayHelper( ) const
4077 {
4078 	Sequence< Property > aProps;
4079 	describeProperties(aProps);
4080 	return new ::cppu::OPropertyArrayHelper(aProps);
4081 }
4082 // -------------------------------------------------------------------------
4083 
4084 // cppu::OPropertySetHelper
4085 ::cppu::IPropertyArrayHelper& SAL_CALL OReportController::getInfoHelper()
4086 {
4087 	typedef ::comphelper::OPropertyArrayUsageHelper<OReportController_BASE> OReportController_PROP;
4088 	return *OReportController_PROP::getArrayHelper();
4089 }
4090 // -----------------------------------------------------------------------------
4091 void SAL_CALL OReportController::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle,const Any& _aValue) throw (Exception)
4092 {
4093     if ( _nHandle == PROPERTY_ID_ZOOMVALUE )
4094     {
4095         _aValue >>= m_nZoomValue;
4096         impl_zoom_nothrow();
4097     }
4098 }
4099 void SAL_CALL OReportController::setMode( const ::rtl::OUString& aMode ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException)
4100 {
4101 	::osl::MutexGuard aGuard( getMutex() );
4102 	m_sMode = aMode;
4103 }
4104 ::rtl::OUString SAL_CALL OReportController::getMode(  ) throw (::com::sun::star::uno::RuntimeException)
4105 {
4106 	::osl::MutexGuard aGuard( getMutex() );
4107 	return m_sMode;
4108 }
4109 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OReportController::getSupportedModes(  ) throw (::com::sun::star::uno::RuntimeException)
4110 {
4111 	static ::rtl::OUString s_sModes[] = { ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("remote")),
4112 										  ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("normal")) };
4113 	return uno::Sequence< ::rtl::OUString> (&s_sModes[0],sizeof(s_sModes)/sizeof(s_sModes[0]));
4114 }
4115 ::sal_Bool SAL_CALL OReportController::supportsMode( const ::rtl::OUString& aMode ) throw (::com::sun::star::uno::RuntimeException)
4116 {
4117 	uno::Sequence< ::rtl::OUString> aModes = getSupportedModes();
4118 	const ::rtl::OUString* pIter = aModes.getConstArray();
4119     const ::rtl::OUString* pEnd  = pIter + aModes.getLength();
4120     for(;pIter != pEnd;++pIter)
4121     {
4122 		if ( pIter->equals(aMode ) )
4123 			break;
4124 	}
4125 	return pIter != pEnd;
4126 }
4127 // -----------------------------------------------------------------------------
4128 bool OReportController::isUiVisible() const
4129 {
4130     return !m_sMode.equalsAscii("remote");
4131 }
4132 // -----------------------------------------------------------------------------
4133 void OReportController::impl_fillState_nothrow(const ::rtl::OUString& _sProperty,dbaui::FeatureState& _rState) const
4134 {
4135     _rState.bEnabled = isEditable();
4136 	if ( _rState.bEnabled )
4137     {
4138         ::std::vector< uno::Reference< uno::XInterface > > aSelection;
4139         getDesignView()->fillControlModelSelection(aSelection);
4140         _rState.bEnabled = !aSelection.empty();
4141         if ( _rState.bEnabled )
4142         {
4143             uno::Any aTemp;
4144             ::std::vector< uno::Reference< uno::XInterface > >::iterator aIter = aSelection.begin();
4145             for(; aIter != aSelection.end() && _rState.bEnabled ;++aIter)
4146             {
4147                 uno::Reference< beans::XPropertySet> xProp(*aIter,uno::UNO_QUERY);
4148                 try
4149                 {
4150                     uno::Any aTemp2 = xProp->getPropertyValue(_sProperty);
4151                     if ( aIter == aSelection.begin() )
4152                     {
4153                         aTemp = aTemp2;
4154                     }
4155                     else if ( !comphelper::compare(aTemp,aTemp2) )
4156                         break;
4157                 }
4158                 catch(beans::UnknownPropertyException&)
4159                 {
4160                     _rState.bEnabled = sal_False;
4161                 }
4162             } // for(; aIter != aSelection.end();++aIter)
4163             if ( aIter == aSelection.end() )
4164                 _rState.aValue = aTemp;
4165         }
4166     } // if ( _rState.bEnabled )
4167 }
4168 // -----------------------------------------------------------------------------
4169 void OReportController::impl_zoom_nothrow()
4170 {
4171     Fraction aZoom(m_nZoomValue,100);
4172     setZoomFactor( aZoom,*getDesignView() );
4173     getDesignView()->zoom(aZoom);
4174     // TRY
4175     /*getDesignView()->Invalidate(INVALIDATE_NOCHILDREN);*/
4176     InvalidateFeature(SID_ATTR_ZOOM,Reference< XStatusListener >(),sal_True);
4177     InvalidateFeature(SID_ATTR_ZOOMSLIDER,Reference< XStatusListener >(),sal_True);
4178 }
4179 // -----------------------------------------------------------------------------
4180 sal_Bool OReportController::isFormatCommandEnabled(sal_uInt16 _nCommand,const uno::Reference< report::XReportControlFormat>& _xReportControlFormat) const
4181 {
4182 	sal_Bool bRet = sal_False;
4183     if ( _xReportControlFormat.is() && !uno::Reference< report::XFixedLine>(_xReportControlFormat,uno::UNO_QUERY).is() ) // this command is really often called so we nedd a short cut here
4184 	{
4185 		try
4186 		{
4187 			const awt::FontDescriptor aFontDescriptor = _xReportControlFormat->getFontDescriptor();
4188 
4189 			switch(_nCommand)
4190 			{
4191 				case SID_ATTR_CHAR_WEIGHT:
4192 					bRet = awt::FontWeight::BOLD == aFontDescriptor.Weight;
4193 					break;
4194 				case SID_ATTR_CHAR_POSTURE:
4195 					bRet = awt::FontSlant_ITALIC == aFontDescriptor.Slant;
4196 					break;
4197 				case SID_ATTR_CHAR_UNDERLINE:
4198 					bRet = awt::FontUnderline::SINGLE == aFontDescriptor.Underline;
4199 					break;
4200 				default:
4201 					;
4202 			} // switch(_nCommand)
4203 		}
4204 		catch(uno::Exception&)
4205 		{
4206 		}
4207 	}
4208 	return bRet;
4209 }
4210 // -----------------------------------------------------------------------------
4211 bool OReportController::impl_setPropertyAtControls_throw(const sal_uInt16 _nUndoResId,const ::rtl::OUString& _sProperty,const uno::Any& _aValue,const Sequence< PropertyValue >& _aArgs)
4212 {
4213     ::std::vector< uno::Reference< uno::XInterface > > aSelection;
4214     uno::Reference< awt::XWindow> xWindow;
4215     lcl_getReportControlFormat( _aArgs, getDesignView(), xWindow, aSelection );
4216     ::std::vector< uno::Reference< uno::XInterface > >::iterator aIter = aSelection.begin();
4217 
4218     const String sUndoAction = String( ModuleRes( _nUndoResId ) );
4219     UndoContext aUndoContext( getUndoManager(), sUndoAction );
4220 
4221     for(;  aIter != aSelection.end();++aIter)
4222     {
4223         const uno::Reference< beans::XPropertySet > xControlModel(*aIter,uno::UNO_QUERY);
4224         if ( xControlModel.is() )
4225             xControlModel->setPropertyValue(_sProperty,_aValue);
4226     }
4227 
4228     return !aSelection.empty();
4229 }
4230 // -----------------------------------------------------------------------------
4231 void OReportController::impl_fillCustomShapeState_nothrow(const char* _pCustomShapeType,dbaui::FeatureState& _rState) const
4232 {
4233     _rState.bEnabled = isEditable();
4234 	_rState.bChecked = getDesignView()->GetInsertObj() == OBJ_CUSTOMSHAPE && getDesignView()->GetInsertObjString().compareToAscii(_pCustomShapeType) == 0;
4235 }
4236 
4237 // -----------------------------------------------------------------------------
4238 ::boost::shared_ptr<OSectionWindow> OReportController::getSectionWindow(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection) const
4239 {
4240     if ( getDesignView() )
4241     {
4242         return  getDesignView()->getSectionWindow(_xSection);
4243     }
4244 
4245     // throw NullPointerException?
4246     ::boost::shared_ptr<OSectionWindow> pEmpty;
4247     return pEmpty;
4248 }
4249 
4250 
4251 // -----------------------------------------------------------------------------
4252 void OReportController::openZoomDialog()
4253 {
4254     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
4255 	if ( pFact )
4256 	{
4257         static SfxItemInfo aItemInfos[] =
4258 	    {
4259 		    { SID_ATTR_ZOOM, SFX_ITEM_POOLABLE }
4260         };
4261         SfxPoolItem* pDefaults[] =
4262 	    {
4263 		    new SvxZoomItem()
4264         };
4265         static sal_uInt16 pRanges[] =
4266 	    {
4267 		    SID_ATTR_ZOOM,SID_ATTR_ZOOM,
4268             0
4269 	    };
4270         SfxItemPool* pPool( new SfxItemPool(String::CreateFromAscii("ZoomProperties"), SID_ATTR_ZOOM,SID_ATTR_ZOOM, aItemInfos, pDefaults) );
4271         pPool->SetDefaultMetric( SFX_MAPUNIT_100TH_MM );	// ripped, don't understand why
4272 		pPool->FreezeIdRanges();						// the same
4273         try
4274         {
4275 		    ::std::auto_ptr<SfxItemSet> pDescriptor(new SfxItemSet(*pPool, pRanges));
4276 		    // fill it
4277             SvxZoomItem aZoomItem( m_eZoomType, m_nZoomValue, SID_ATTR_ZOOM );
4278             aZoomItem.SetValueSet(SVX_ZOOM_ENABLE_100|SVX_ZOOM_ENABLE_WHOLEPAGE|SVX_ZOOM_ENABLE_PAGEWIDTH);
4279             pDescriptor->Put(aZoomItem);
4280 
4281             ::std::auto_ptr<AbstractSvxZoomDialog> pDlg( pFact->CreateSvxZoomDialog(NULL, *pDescriptor.get()) );
4282 		    pDlg->SetLimits( 20, 400 );
4283 		    bool bCancel = ( RET_CANCEL == pDlg->Execute() );
4284 
4285 		    if ( !bCancel )
4286 		    {
4287 			    const SvxZoomItem&	rZoomItem = (const SvxZoomItem&)pDlg->GetOutputItemSet()->Get( SID_ATTR_ZOOM );
4288                 m_eZoomType = rZoomItem.GetType();
4289                 m_nZoomValue = rZoomItem.GetValue();
4290                 if ( m_eZoomType != SVX_ZOOM_PERCENT )
4291                     m_nZoomValue = getDesignView()->getZoomFactor( m_eZoomType );
4292 
4293                 impl_zoom_nothrow();
4294 		    } // if ( !bCancel )
4295         }
4296         catch(uno::Exception&)
4297 	    {
4298             DBG_UNHANDLED_EXCEPTION();
4299 	    }
4300         SfxItemPool::Free(pPool);
4301 
4302 	    for (sal_uInt16 i=0; i<sizeof(pDefaults)/sizeof(pDefaults[0]); ++i)
4303 		    delete pDefaults[i];
4304 	} // if(pFact)
4305 }
4306 // -----------------------------------------------------------------------------
4307 // -----------------------------------------------------------------------------
4308 // XVisualObject
4309 void SAL_CALL OReportController::setVisualAreaSize( ::sal_Int64 _nAspect, const awt::Size& _aSize ) throw (lang::IllegalArgumentException, embed::WrongStateException, uno::Exception, uno::RuntimeException)
4310 {
4311 	::osl::MutexGuard aGuard( getMutex() );
4312     //if( nAspect == embed::Aspects::MSOLE_CONTENT )
4313     {
4314         bool bChanged =
4315             (m_aVisualAreaSize.Width != _aSize.Width ||
4316              m_aVisualAreaSize.Height != _aSize.Height);
4317         m_aVisualAreaSize = _aSize;
4318         if( bChanged )
4319             setModified( sal_True );
4320     }
4321 	m_nAspect = _nAspect;
4322 }
4323 // -----------------------------------------------------------------------------
4324 awt::Size SAL_CALL OReportController::getVisualAreaSize( ::sal_Int64 /*nAspect*/ ) throw (lang::IllegalArgumentException, embed::WrongStateException, uno::Exception, uno::RuntimeException)
4325 {
4326     ::osl::MutexGuard aGuard( getMutex() );
4327 	return m_aVisualAreaSize;
4328 }
4329 // -----------------------------------------------------------------------------
4330 embed::VisualRepresentation SAL_CALL OReportController::getPreferredVisualRepresentation( ::sal_Int64 _nAspect ) throw (lang::IllegalArgumentException, embed::WrongStateException, uno::Exception, uno::RuntimeException)
4331 {
4332     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
4333 	::osl::MutexGuard aGuard( getMutex() );
4334 	embed::VisualRepresentation aResult;
4335     if ( !m_bInGeneratePreview )
4336     {
4337         m_bInGeneratePreview = true;
4338         try
4339         {
4340             if ( !m_xReportEngine.is() )
4341                 m_xReportEngine.set(getORB()->createInstance(SERVICE_REPORTENGINE),uno::UNO_QUERY_THROW);
4342             const sal_Int32 nOldMaxRows = m_xReportEngine->getMaxRows();
4343             m_xReportEngine->setMaxRows(MAX_ROWS_FOR_PREVIEW);
4344             m_xReportEngine->setReportDefinition(m_xReportDefinition);
4345             m_xReportEngine->setActiveConnection(getConnection());
4346             try
4347             {
4348                 Reference<embed::XVisualObject> xTransfer(m_xReportEngine->createDocumentModel(),UNO_QUERY);
4349 		        if ( xTransfer.is() )
4350 		        {
4351                     xTransfer->setVisualAreaSize(m_nAspect,m_aVisualAreaSize);
4352 			        aResult = xTransfer->getPreferredVisualRepresentation( _nAspect );
4353 		        } // if ( xTransfer.is() )
4354             }
4355             catch( uno::Exception & ex )
4356             {
4357                 (void)ex;
4358             }
4359             m_xReportEngine->setMaxRows(nOldMaxRows);
4360         }
4361         catch( uno::Exception & ex )
4362         {
4363             (void)ex;
4364         }
4365         m_bInGeneratePreview = false;
4366     }
4367 	return aResult;
4368 }
4369 // -----------------------------------------------------------------------------
4370 ::sal_Int32 SAL_CALL OReportController::getMapUnit( ::sal_Int64 /*nAspect*/ ) throw (uno::Exception, uno::RuntimeException)
4371 {
4372 	return embed::EmbedMapUnits::ONE_100TH_MM;
4373 }
4374 // -----------------------------------------------------------------------------
4375 uno::Reference< container::XNameAccess > OReportController::getColumns() const
4376 {
4377     if ( !m_xColumns.is() && m_xReportDefinition.is() && m_xReportDefinition->getCommand().getLength() )
4378     {
4379 		m_xColumns = dbtools::getFieldsByCommandDescriptor(getConnection(),m_xReportDefinition->getCommandType(),m_xReportDefinition->getCommand(),m_xHoldAlive);
4380     }
4381     return m_xColumns;
4382 }
4383 // -----------------------------------------------------------------------------
4384 ::rtl::OUString OReportController::getColumnLabel_throw(const ::rtl::OUString& i_sColumnName) const
4385 {
4386     ::rtl::OUString sLabel;
4387     uno::Reference< container::XNameAccess > xColumns = getColumns();
4388     if ( xColumns.is() && xColumns->hasByName(i_sColumnName) )
4389     {
4390         uno::Reference< beans::XPropertySet> xColumn(xColumns->getByName(i_sColumnName),uno::UNO_QUERY_THROW);
4391         if ( xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_LABEL) )
4392             xColumn->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
4393     }
4394     return sLabel;
4395 }
4396 
4397 // -----------------------------------------------------------------------------
4398 SfxUndoManager& OReportController::getUndoManager() const
4399 {
4400     DBG_TESTSOLARMUTEX();
4401         // this is expected to be called during UI actions, so the SM is assumed to be locked
4402 
4403     ::boost::shared_ptr< OReportModel > pReportModel( getSdrModel() );
4404     ENSURE_OR_THROW( !!pReportModel, "no access to our model" );
4405 
4406     SfxUndoManager* pUndoManager( pReportModel->GetSdrUndoManager() );
4407     ENSURE_OR_THROW( pUndoManager != NULL, "no access to our model's UndoManager" );
4408 
4409     return *pUndoManager;
4410 }
4411 
4412 // -----------------------------------------------------------------------------
4413 void OReportController::clearUndoManager() const
4414 {
4415     getUndoManager().Clear();
4416 }
4417 
4418 // -----------------------------------------------------------------------------
4419 void OReportController::addUndoAction( SfxUndoAction* i_pAction )
4420 {
4421 	getUndoManager().AddUndoAction( i_pAction );
4422 
4423 	InvalidateFeature( SID_UNDO );
4424 	InvalidateFeature( SID_REDO );
4425 }
4426