summaryrefslogtreecommitdiff
path: root/reportdesign/source/ui/report/ReportSection.cxx
blob: f910c3dbdf99153f01b9e3c5df3815ce65aeb6f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#include <memory>
#include <ReportSection.hxx>
#include <ReportWindow.hxx>
#include <DesignView.hxx>
#include <strings.hxx>
#include <RptObject.hxx>
#include <RptModel.hxx>
#include <SectionView.hxx>
#include <RptPage.hxx>
#include <ReportController.hxx>
#include <UITools.hxx>
#include <ViewsWindow.hxx>

#include <svx/svdpagv.hxx>
#include <editeng/adjustitem.hxx>
#include <editeng/eeitem.hxx>
#include <svx/sdrpaintwindow.hxx>
#include <svx/gallery.hxx>
#include <svx/svxids.hrc>
#include <svx/svditer.hxx>
#include <svx/dbaexchange.hxx>
#include <svx/sdtagitm.hxx>

#include <com/sun/star/awt/PopupMenuDirection.hpp>
#include <com/sun/star/frame/XPopupMenuController.hpp>
#include <comphelper/propertyvalue.hxx>
#include <toolkit/awt/vclxmenu.hxx>
#include <toolkit/helper/convert.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <RptDef.hxx>
#include <SectionWindow.hxx>
#include <helpids.h>
#include <dlgedclip.hxx>
#include <rptui_slotid.hrc>

#include <utility>
#include <vcl/commandevent.hxx>
#include <o3tl/safeint.hxx>

#include <svl/itempool.hxx>
#include <svtools/extcolorcfg.hxx>


namespace rptui
{

using namespace ::com::sun::star;


static Color lcl_getOverlappedControlColor(/*const uno::Reference <lang::XMultiServiceFactory> _rxFactory*/)
{
    svtools::ExtendedColorConfig aConfig;
    return aConfig.GetColorValue(CFG_REPORTDESIGNER, DBOVERLAPPEDCONTROL).getColor();
}

OReportSection::OReportSection(OSectionWindow* _pParent,uno::Reference< report::XSection > _xSection)
    : Window(_pParent,WB_DIALOGCONTROL)
    , ::comphelper::OPropertyChangeListener(m_aMutex)
    , DropTargetHelper(this)
    , m_pPage(nullptr)
    , m_pView(nullptr)
    , m_pParent(_pParent)
    , m_xSection(std::move(_xSection))
    , m_nPaintEntranceCount(0)
    , m_eMode(DlgEdMode::Select)
{
    //EnableChildTransparentMode();
    SetHelpId(HID_REPORTSECTION);
    SetMapMode(MapMode(MapUnit::Map100thMM));
    SetParentClipMode(ParentClipMode::Clip);
    EnableChildTransparentMode( false );
    SetPaintTransparent( false );

    try
    {
        fill();
    }
    catch(uno::Exception&)
    {
        TOOLS_WARN_EXCEPTION( "reportdesign", "");
    }

    m_pFunc.reset(new DlgEdFuncSelect( this ));
    m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor() );
}

OReportSection::~OReportSection()
{
    disposeOnce();
}

void OReportSection::dispose()
{
    m_pPage = nullptr;
    if ( m_pMulti.is() )
        m_pMulti->dispose();
    m_pMulti.clear();

    if ( m_pReportListener.is() )
        m_pReportListener->dispose();
    m_pReportListener.clear();
    m_pFunc.reset();

    {
        if ( m_pView )
            m_pView->EndListening( *m_pModel );
        delete m_pView;
        m_pView = nullptr;
    }
    m_pParent.clear();
    vcl::Window::dispose();
}

void OReportSection::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect )
{
    Window::Paint(rRenderContext, rRect);

    if ( !(m_pView && m_nPaintEntranceCount == 0))
        return;

    ++m_nPaintEntranceCount;
     // repaint, get PageView and prepare Region
    SdrPageView* pPgView = m_pView->GetSdrPageView();
    const vcl::Region aPaintRectRegion(rRect);

    // #i74769#
    SdrPaintWindow* pTargetPaintWindow = nullptr;

    // mark repaint start
    if (pPgView)
    {
        pTargetPaintWindow = pPgView->GetView().BeginDrawLayers(GetOutDev(), aPaintRectRegion);
        OSL_ENSURE(pTargetPaintWindow, "BeginDrawLayers: Got no SdrPaintWindow (!)");
        // draw background self using wallpaper
        OutputDevice& rTargetOutDev = pTargetPaintWindow->GetTargetOutputDevice();
        rTargetOutDev.DrawWallpaper(rRect, Wallpaper(pPgView->GetApplicationDocumentColor()));

        // do paint (unbuffered) and mark repaint end
        pPgView->DrawLayer(RPT_LAYER_FRONT, &rRenderContext);
        pPgView->GetView().EndDrawLayers(*pTargetPaintWindow, true);
    }

    m_pView->CompleteRedraw(&rRenderContext, aPaintRectRegion);
    --m_nPaintEntranceCount;
}

void OReportSection::fill()
{
    if ( !m_xSection.is() )
        return;

    m_pMulti = new comphelper::OPropertyChangeMultiplexer(this,m_xSection);
    m_pMulti->addProperty(PROPERTY_BACKCOLOR);

    m_pReportListener = addStyleListener(m_xSection->getReportDefinition(),this);

    m_pModel = m_pParent->getViewsWindow()->getView()->getReportView()->getController().getSdrModel();
    m_pPage = m_pModel->getPage(m_xSection);

    m_pView = new OSectionView(
        *m_pModel,
        this,
        m_pParent->getViewsWindow()->getView());

    // #i93597# tell SdrPage that only left and right page border is defined
    // instead of the full rectangle definition
    m_pPage->setPageBorderOnlyLeftRight(true);

    // without the following call, no grid is painted
    m_pView->ShowSdrPage( m_pPage );

    m_pView->SetMoveSnapOnlyTopLeft( true );
    ODesignView* pDesignView = m_pParent->getViewsWindow()->getView()->getReportView();

    // #i93595# Adapted grid to a more coarse grid and subdivisions for better visualisation. This
    // is only for visualisation and has nothing to do with the actual snap
    const Size aGridSizeCoarse(pDesignView->getGridSizeCoarse());
    const Size aGridSizeFine(pDesignView->getGridSizeFine());
    m_pView->SetGridCoarse(aGridSizeCoarse);
    m_pView->SetGridFine(aGridSizeFine);

    // #i93595# set snap grid width to snap to all existing subdivisions
    const Fraction aX(aGridSizeFine.Width());
    const Fraction aY(aGridSizeFine.Height());
    m_pView->SetSnapGridWidth(aX, aY);

    m_pView->SetGridSnap( true );
    m_pView->SetGridFront( false );
    m_pView->SetDragStripes( true );
    m_pView->SetPageVisible();
    sal_Int32 nColor = m_xSection->getBackColor();
    if ( nColor == static_cast<sal_Int32>(COL_TRANSPARENT) )
        nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
    m_pView->SetApplicationDocumentColor(Color(ColorTransparency, nColor));

    uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
    const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
    const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
    m_pPage->SetLeftBorder(nLeftMargin);
    m_pPage->SetRightBorder(nRightMargin);

// LLA: TODO
//  m_pPage->SetUpperBorder(-10000);

    m_pView->SetDesignMode();

    m_pPage->SetSize( Size( getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width,5*m_xSection->getHeight()) );
    const Size aPageSize = m_pPage->GetSize();
    m_pView->SetWorkArea( tools::Rectangle( Point( nLeftMargin, 0), Size(aPageSize.Width() - nLeftMargin - nRightMargin,aPageSize.Height()) ) );
}

void OReportSection::Paste(const uno::Sequence< beans::NamedValue >& _aAllreadyCopiedObjects,bool _bForce)
{
    OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
    if ( !(m_xSection.is() && _aAllreadyCopiedObjects.hasElements()) )
        return;

    // stop all drawing actions
    m_pView->BrkAction();

    // unmark all objects
    m_pView->UnmarkAll();
    const OUString sSectionName = m_xSection->getName();
    for(const beans::NamedValue& rObject : _aAllreadyCopiedObjects)
    {
        if ( _bForce || rObject.Name == sSectionName)
        {
            try
            {
                uno::Sequence< uno::Reference<report::XReportComponent> > aCopies;
                rObject.Value >>= aCopies;
                for (const uno::Reference<report::XReportComponent>& rCopy : aCopies)
                {
                    SdrObject* pObject = SdrObject::getSdrObjectFromXShape( rCopy );
                    if ( pObject )
                    {
                        // Clone to target SdrModel
                        rtl::Reference<SdrObject> pNewObj(pObject->CloneSdrObject(*m_pModel));
                        m_pPage->InsertObject(pNewObj.get(), SAL_MAX_SIZE);
                        tools::Rectangle aRet(VCLPoint(rCopy->getPosition()),VCLSize(rCopy->getSize()));
                        aRet.setHeight(aRet.getOpenHeight() + 1);
                        aRet.setWidth(aRet.getOpenWidth() + 1);
                        bool bOverlapping = true;
                        while ( bOverlapping )
                        {
                            bOverlapping = isOver(aRet,*m_pPage,*m_pView,true,pNewObj.get()) != nullptr;
                            if ( bOverlapping )
                            {
                                aRet.Move(0,aRet.getOpenHeight()+1);
                                pNewObj->SetLogicRect(aRet);
                            }
                        }
                        m_pView->AddUndo(m_pView->GetModel().GetSdrUndoFactory().CreateUndoNewObject(*pNewObj));
                        m_pView->MarkObj( pNewObj.get(), m_pView->GetSdrPageView() );
                        if ( m_xSection.is() && (o3tl::make_unsigned(aRet.getOpenHeight() + aRet.Top()) > m_xSection->getHeight()) )
                            m_xSection->setHeight(aRet.getOpenHeight() + aRet.Top());
                    }
                }
            }
            catch(uno::Exception&)
            {
                TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while pasting a new object!");
            }
            if ( !_bForce )
                break;
        }
    }
}

void OReportSection::Delete()
{
    if( !m_pView->AreObjectsMarked() )
        return;

    m_pView->BrkAction();
    m_pView->DeleteMarked();
}

void OReportSection::SetMode( DlgEdMode eNewMode )
{
    if ( eNewMode == m_eMode )
        return;

    if ( eNewMode == DlgEdMode::Insert )
    {
        m_pFunc.reset(new DlgEdFuncInsert( this ));
    }
    else
    {
        m_pFunc.reset(new DlgEdFuncSelect( this ));
    }
    m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor( ) );
    m_pModel->SetReadOnly(false);
    m_eMode = eNewMode;
}

void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects)
{
    Copy(_rAllreadyCopiedObjects,false);
}

void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects,bool _bEraseAnddNoClone)
{
    OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
    if( !m_pView->AreObjectsMarked() || !m_xSection.is() )
        return;

    // insert control models of marked objects into clipboard dialog model
    const SdrMarkList& rMarkedList = m_pView->GetMarkedObjectList();
    const size_t nMark = rMarkedList.GetMarkCount();

    ::std::vector< uno::Reference<report::XReportComponent> > aCopies;
    aCopies.reserve(nMark);

    SdrUndoFactory& rUndo = m_pView->GetModel().GetSdrUndoFactory();

    for( size_t i = nMark; i > 0; )
    {
        --i;
        SdrObject* pSdrObject = rMarkedList.GetMark(i)->GetMarkedSdrObj();
        OObjectBase* pObj = dynamic_cast<OObjectBase*>(pSdrObject);
        if ( pObj  )
        {
            try
            {
                rtl::Reference<SdrObject> pNewObj(pSdrObject->CloneSdrObject(pSdrObject->getSdrModelFromSdrObject()));
                aCopies.emplace_back(pNewObj->getUnoShape(),uno::UNO_QUERY);
                if ( _bEraseAnddNoClone )
                {
                    m_pView->AddUndo( rUndo.CreateUndoDeleteObject( *pSdrObject ) );
                    m_pPage->RemoveObject(pSdrObject->GetOrdNum());
                }

            }
            catch(uno::Exception&)
            {
                OSL_FAIL("Can't copy report elements!");
            }
        }
    }

    if ( !aCopies.empty() )
    {
        ::std::reverse(aCopies.begin(),aCopies.end());
        const sal_Int32 nLength = _rAllreadyCopiedObjects.getLength();
        _rAllreadyCopiedObjects.realloc( nLength + 1);
        beans::NamedValue* pNewValue = _rAllreadyCopiedObjects.getArray() + nLength;
        pNewValue->Name = m_xSection->getName();
        pNewValue->Value <<= uno::Sequence< uno::Reference<report::XReportComponent> >(&(*aCopies.begin()),aCopies.size());
    }
}

void OReportSection::MouseButtonDown( const MouseEvent& rMEvt )
{
    m_pParent->getViewsWindow()->getView()->setMarked(m_pView, true); // mark the section in which is clicked
    m_pFunc->MouseButtonDown( rMEvt );
    Window::MouseButtonDown(rMEvt);
}

void OReportSection::MouseButtonUp( const MouseEvent& rMEvt )
{
    if ( !m_pFunc->MouseButtonUp( rMEvt ) )
        m_pParent->getViewsWindow()->getView()->getReportView()->getController().executeUnChecked(SID_OBJECT_SELECT,uno::Sequence< beans::PropertyValue>());
}


void OReportSection::MouseMove( const MouseEvent& rMEvt )
{
    m_pFunc->MouseMove( rMEvt );

}

void OReportSection::SetGridVisible(bool _bVisible)
{
    m_pView->SetGridVisible( _bVisible );
}

void OReportSection::SelectAll(const SdrObjKind _nObjectType)
{
    if ( !m_pView )
        return;

    if ( _nObjectType == SdrObjKind::NONE )
        m_pView->MarkAllObj();
    else
    {
        m_pView->UnmarkAll();
        SdrObjListIter aIter(m_pPage,SdrIterMode::DeepNoGroups);
        SdrObject* pObjIter = nullptr;
        while( (pObjIter = aIter.Next()) != nullptr )
        {
            if ( pObjIter->GetObjIdentifier() == _nObjectType )
                m_pView->MarkObj( pObjIter, m_pView->GetSdrPageView() );
        }
    }
}

void OReportSection::Command( const CommandEvent& _rCEvt )
{
    Window::Command(_rCEvt);
    if (_rCEvt.GetCommand() != CommandEventId::ContextMenu)
        return;

    OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
    uno::Reference<frame::XFrame> xFrame = rController.getFrame();
    css::uno::Sequence<css::uno::Any> aArgs {
        css::uno::Any(comphelper::makePropertyValue("Value", OUString("report"))),
        css::uno::Any(comphelper::makePropertyValue("Frame", xFrame)),
        css::uno::Any(comphelper::makePropertyValue("IsContextMenu", true))
    };

    css::uno::Reference<css::uno::XComponentContext> xContext(rController.getORB());
    css::uno::Reference<css::frame::XPopupMenuController> xMenuController(
        xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
        "com.sun.star.comp.framework.ResourceMenuController", aArgs, xContext), css::uno::UNO_QUERY);

    if (!xMenuController.is())
        return;

    rtl::Reference<VCLXPopupMenu> xPopupMenu = new VCLXPopupMenu();

    if (!xPopupMenu.is())
        return;

    xMenuController->setPopupMenu(xPopupMenu);

    Point aPos = _rCEvt.GetMousePosPixel();
    m_pView->EndAction();

    xPopupMenu->execute(GetComponentInterface(),
                        css::awt::Rectangle(aPos.X(), aPos.Y(), 1, 1),
                        css::awt::PopupMenuDirection::EXECUTE_DOWN);

    css::uno::Reference<css::lang::XComponent> xComponent(xMenuController, css::uno::UNO_QUERY);
    xComponent->dispose();
}

void OReportSection::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
{
    if ( !m_xSection.is() )
        return;

    if ( _rEvent.Source == m_xSection || PROPERTY_BACKCOLOR == _rEvent.PropertyName )
    {
        sal_Int32 nColor = m_xSection->getBackColor();
        if ( nColor == static_cast<sal_Int32>(COL_TRANSPARENT) )
            nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
        m_pView->SetApplicationDocumentColor(Color(ColorTransparency, nColor));
        Invalidate(InvalidateFlags::NoChildren|InvalidateFlags::NoErase);
    }
    else
    {
        uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
        const sal_Int32 nLeftMargin  = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
        const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
        const sal_Int32 nPaperWidth  = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;

        if ( _rEvent.PropertyName == PROPERTY_LEFTMARGIN )
        {
            m_pPage->SetLeftBorder(nLeftMargin);
        }
        else if ( _rEvent.PropertyName == PROPERTY_RIGHTMARGIN )
        {
            m_pPage->SetRightBorder(nRightMargin);
        }
        const Size aOldPageSize = m_pPage->GetSize();
        sal_Int32 nNewHeight = 5*m_xSection->getHeight();
        if ( aOldPageSize.Height() != nNewHeight || nPaperWidth != aOldPageSize.Width() )
        {
            m_pPage->SetSize( Size( nPaperWidth,nNewHeight) );
            const Size aPageSize = m_pPage->GetSize();
            m_pView->SetWorkArea( tools::Rectangle( Point( nLeftMargin, 0), Size(aPageSize.Width() - nLeftMargin - nRightMargin,aPageSize.Height()) ) );
        }
        impl_adjustObjectSizePosition(nPaperWidth,nLeftMargin,nRightMargin);
        m_pParent->Invalidate(InvalidateFlags::Update | InvalidateFlags::Transparent);
    }
}
void OReportSection::impl_adjustObjectSizePosition(sal_Int32 i_nPaperWidth,sal_Int32 i_nLeftMargin,sal_Int32 i_nRightMargin)
{
    try
    {
        sal_Int32 nRightBorder = i_nPaperWidth - i_nRightMargin;
        const sal_Int32 nCount = m_xSection->getCount();
        for (sal_Int32 i = 0; i < nCount; ++i)
        {
            uno::Reference< report::XReportComponent> xReportComponent(m_xSection->getByIndex(i),uno::UNO_QUERY_THROW);
            awt::Point aPos = xReportComponent->getPosition();
            awt::Size aSize = xReportComponent->getSize();
            SdrObject* pObject = SdrObject::getSdrObjectFromXShape( xReportComponent );
            if ( pObject )
            {
                bool bChanged = false;

                OObjectBase& rBase = dynamic_cast<OObjectBase&>(*pObject);
                rBase.EndListening();
                if ( aPos.X < i_nLeftMargin )
                {
                    aPos.X  = i_nLeftMargin;
                    bChanged = true;
                }
                if ( (aPos.X + aSize.Width) > nRightBorder )
                {
                    aPos.X = nRightBorder - aSize.Width;
                    if ( aPos.X < i_nLeftMargin )
                    {
                        aSize.Width += aPos.X - i_nLeftMargin;
                        aPos.X = i_nLeftMargin;
                        // add listener around
                        rBase.StartListening();
                        xReportComponent->setSize(aSize);
                        rBase.EndListening();
                    }
                    bChanged = true;
                }
                if ( aPos.Y < 0 )
                    aPos.Y = 0;
                if ( bChanged )
                {
                    xReportComponent->setPosition(aPos);
                    correctOverlapping(pObject,*this,false);
                    tools::Rectangle aRet(VCLPoint(xReportComponent->getPosition()),VCLSize(xReportComponent->getSize()));
                    aRet.setHeight(aRet.getOpenHeight() + 1);
                    aRet.setWidth(aRet.getOpenWidth() + 1);
                    if ( m_xSection.is() && (o3tl::make_unsigned(aRet.getOpenHeight() + aRet.Top()) > m_xSection->getHeight()) )
                        m_xSection->setHeight(aRet.getOpenHeight() + aRet.Top());

                    pObject->RecalcBoundRect();
                }
                rBase.StartListening();
            }
        }
    }
    catch(const uno::Exception &)
    {
        TOOLS_WARN_EXCEPTION( "reportdesign", "OReportSection::impl_adjustObjectSizePosition()");
    }
}

bool OReportSection::handleKeyEvent(const KeyEvent& _rEvent)
{
    return m_pFunc && m_pFunc->handleKeyEvent(_rEvent);
}

void OReportSection::deactivateOle()
{
    if (m_pFunc)
        m_pFunc->deactivateOle(true);
}

void OReportSection::createDefault(const OUString& _sType)
{
    SdrObject* pObj = m_pView->GetCreateObj();
    if ( !pObj )
        return;
    createDefault(_sType,pObj);
}

void OReportSection::createDefault(const OUString& _sType,SdrObject* _pObj)
{
    bool bAttributesAppliedFromGallery = false;

    if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
    {
        std::vector< OUString > aObjList;
        if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
        {
            auto aIter = std::find_if(aObjList.begin(), aObjList.end(),
                [&_sType](const OUString& rObj) { return rObj.equalsIgnoreAsciiCase(_sType); });
            if (aIter != aObjList.end())
            {
                auto i = static_cast<sal_uInt32>(std::distance(aObjList.begin(), aIter));
                OReportModel aReportModel(nullptr);

                if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aReportModel ) )
                {
                    const SdrObject* pSourceObj = aReportModel.GetPage( 0 )->GetObj( 0 );
                    if( pSourceObj )
                    {
                        const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
                        SfxItemSetFixed<
                                // Ranges from SdrAttrObj:
                                SDRATTR_START, SDRATTR_SHADOW_LAST,
                                SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
                                SDRATTR_TEXTDIRECTION,
                                    SDRATTR_TEXTDIRECTION,
                                // Graphic attributes, 3D properties,
                                // CustomShape properties:
                                SDRATTR_GRAF_FIRST,
                                    SDRATTR_CUSTOMSHAPE_LAST,
                                // Range from SdrTextObj:
                                EE_ITEMS_START, EE_ITEMS_END>
                            aDest( _pObj->getSdrModelFromSdrObject().GetItemPool() );
                        aDest.Set( rSource );
                        _pObj->SetMergedItemSet( aDest );
                        Degree100 nAngle = pSourceObj->GetRotateAngle();
                        if ( nAngle )
                            _pObj->NbcRotate( _pObj->GetSnapRect().Center(), nAngle );
                        bAttributesAppliedFromGallery = true;
                    }
                }
            }
        }
    }
    if ( !bAttributesAppliedFromGallery )
    {
        _pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST) );
        _pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
        _pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
        _pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
        static_cast<SdrObjCustomShape*>(_pObj)->MergeDefaultAttributes( &_sType );
    }
}

uno::Reference< report::XReportComponent > OReportSection::getCurrentControlModel() const
{
    uno::Reference< report::XReportComponent > xModel;
    if ( m_pView )
    {
        const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();

        if ( rMarkList.GetMarkCount() == 1 )
        {
            SdrObject* pDlgEdObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
            OObjectBase* pObj = dynamic_cast<OObjectBase*>(pDlgEdObj);
            if ( pObj )
                xModel = pObj->getReportComponent().get();
        }
    }
    return xModel;
}

void OReportSection::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
{
    if ( !m_pView )
        return;

    const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
    const size_t nMarkCount = rMarkList.GetMarkCount();

    for (size_t i=0; i < nMarkCount; ++i)
    {
        const SdrObject* pDlgEdObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
        const OObjectBase* pObj = dynamic_cast<const OObjectBase*>(pDlgEdObj);
        if ( pObj )
        {
            uno::Reference<uno::XInterface> xInterface(pObj->getReportComponent());
            _rSelection.push_back(xInterface);
        }
    }
}

sal_Int8 OReportSection::AcceptDrop( const AcceptDropEvent& _rEvt )
{
    ::Point aDropPos(_rEvt.maPosPixel);
    const MouseEvent aMouseEvt(aDropPos);
    if ( m_pFunc->isOverlapping(aMouseEvt) )
        return DND_ACTION_NONE;

    if ( _rEvt.mnAction == DND_ACTION_COPY ||
         _rEvt.mnAction == DND_ACTION_LINK
         )
    {
        if (!m_pParent) return DND_ACTION_NONE;
        sal_uInt16 nCurrentPosition = m_pParent->getViewsWindow()->getPosition(m_pParent);
        if (_rEvt.mnAction == DND_ACTION_COPY )
        {
            // we must assure, we can't drop in the top section
            if (nCurrentPosition < 1)
            {
                return DND_ACTION_NONE;
            }
            return DND_ACTION_LINK;
        }
        if (_rEvt.mnAction == DND_ACTION_LINK)
        {
            // we must assure, we can't drop in the bottom section
            if (m_pParent->getViewsWindow()->getSectionCount() > (nCurrentPosition + 1)  )
            {
                return DND_ACTION_COPY;
            }
            return DND_ACTION_NONE;
        }
    }
    else
    {
        const DataFlavorExVector& rFlavors = GetDataFlavorExVector();
        if (   svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors)
            || svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, ColumnTransferFormatFlags::FIELD_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE | ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) )
            return _rEvt.mnAction;

        const sal_Int8 nDropOption = ( OReportExchange::canExtract(rFlavors) ) ? DND_ACTION_COPYMOVE : DND_ACTION_NONE;

        return nDropOption;
    }
    return DND_ACTION_NONE;
}


sal_Int8 OReportSection::ExecuteDrop( const ExecuteDropEvent& _rEvt )
{
    ::Point aDropPos(PixelToLogic(_rEvt.maPosPixel));
    const MouseEvent aMouseEvt(aDropPos);
    if ( m_pFunc->isOverlapping(aMouseEvt) )
        return DND_ACTION_NONE;

    sal_Int8 nDropOption = DND_ACTION_NONE;
    const TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
    const DataFlavorExVector& rFlavors = aDropped.GetDataFlavorExVector();
    bool bMultipleFormat = svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors);
    if ( OReportExchange::canExtract(rFlavors) )
    {
        OReportExchange::TSectionElements aCopies = OReportExchange::extractCopies(aDropped);
        Paste(aCopies,true);
        nDropOption = DND_ACTION_COPYMOVE;
        m_pParent->getViewsWindow()->BrkAction();
        m_pParent->getViewsWindow()->unmarkAllObjects(m_pView);
    }
    else if ( bMultipleFormat
        || svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, ColumnTransferFormatFlags::FIELD_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE | ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) )
    {
        m_pParent->getViewsWindow()->getView()->setMarked(m_pView, true);
        m_pView->UnmarkAll();
        const tools::Rectangle& rRect = m_pView->GetWorkArea();
        if ( aDropPos.X() < rRect.Left() )
            aDropPos.setX( rRect.Left() );
        else if ( aDropPos.X() > rRect.Right() )
            aDropPos.setX( rRect.Right() );

        if ( aDropPos.Y() > rRect.Bottom() )
            aDropPos.setY( rRect.Bottom() );

        uno::Sequence<beans::PropertyValue> aValues;
        if ( !bMultipleFormat )
        {
            svx::ODataAccessDescriptor aDescriptor = svx::OColumnTransferable::extractColumnDescriptor(aDropped);

            aValues.realloc(1);
            aValues.getArray()[0].Value <<= aDescriptor.createPropertyValueSequence();
        }
        else
            aValues = svx::OMultiColumnTransferable::extractDescriptor(aDropped);

        for(beans::PropertyValue & propVal : asNonConstRange(aValues))
        {
            uno::Sequence<beans::PropertyValue> aCurrent;
            propVal.Value >>= aCurrent;
            sal_Int32 nLength = aCurrent.getLength();
            if ( nLength )
            {
                aCurrent.realloc(nLength + 3);
                auto pCurrent = aCurrent.getArray();
                pCurrent[nLength].Name = PROPERTY_POSITION;
                pCurrent[nLength++].Value <<= AWTPoint(aDropPos);
                // give also the DND Action (Shift|Ctrl) Key to really say what we want
                pCurrent[nLength].Name = "DNDAction";
                pCurrent[nLength++].Value <<= _rEvt.mnAction;

                pCurrent[nLength].Name = "Section";
                pCurrent[nLength++].Value <<= getSection();
                propVal.Value <<= aCurrent;
            }
        }

        // we use this way to create undo actions
        OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
        rController.executeChecked(SID_ADD_CONTROL_PAIR,aValues);
        nDropOption = DND_ACTION_COPY;
    }
    return nDropOption;
}

void OReportSection::stopScrollTimer()
{
    m_pFunc->stopScrollTimer();
}

bool OReportSection::isUiActive() const
{
    return m_pFunc->isUiActive();
}


}


/* vim:set shiftwidth=4 softtabstop=4 expandtab: */