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 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
|
/* -*- 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 "Navigator.hxx"
#include "uistrings.hrc"
#include "ReportController.hxx"
#include "UITools.hxx"
#include "RptUndo.hxx"
#include "reportformula.hxx"
#include <com/sun/star/container/XContainerListener.hpp>
#include <com/sun/star/report/XReportDefinition.hpp>
#include <com/sun/star/report/XFixedText.hpp>
#include <com/sun/star/report/XFixedLine.hpp>
#include <com/sun/star/report/XFormattedField.hpp>
#include <com/sun/star/report/XImageControl.hpp>
#include <com/sun/star/report/XShape.hpp>
#include "helpids.hrc"
#include "RptResId.hrc"
#include "rptui_slotid.hrc"
#include <tools/debug.hxx>
#include <comphelper/propmultiplex.hxx>
#include <comphelper/containermultiplexer.hxx>
#include <comphelper/types.hxx>
#include <cppuhelper/basemutex.hxx>
#include <comphelper/SelectionMultiplex.hxx>
#include <svtools/treelistbox.hxx>
#include <svtools/treelistentry.hxx>
#include <svl/solar.hrc>
#include "ReportVisitor.hxx"
#include "ModuleHelper.hxx"
#include <rtl/ref.hxx>
#include <memory>
#include <algorithm>
#define RID_SVXIMG_COLLAPSEDNODE (RID_FORMS_START + 2)
#define RID_SVXIMG_EXPANDEDNODE (RID_FORMS_START + 3)
#define DROP_ACTION_TIMER_INITIAL_TICKS 10
#define DROP_ACTION_TIMER_SCROLL_TICKS 3
#define DROP_ACTION_TIMER_TICK_BASE 10
namespace rptui
{
using namespace ::com::sun::star;
using namespace utl;
using namespace ::comphelper;
sal_uInt16 lcl_getImageId(const uno::Reference< report::XReportComponent>& _xElement)
{
sal_uInt16 nId = 0;
uno::Reference< report::XFixedLine> xFixedLine(_xElement,uno::UNO_QUERY);
if ( uno::Reference< report::XFixedText>(_xElement,uno::UNO_QUERY).is() )
nId = SID_FM_FIXEDTEXT;
else if ( xFixedLine.is() )
nId = xFixedLine->getOrientation() ? SID_INSERT_VFIXEDLINE : SID_INSERT_HFIXEDLINE;
else if ( uno::Reference< report::XFormattedField>(_xElement,uno::UNO_QUERY).is() )
nId = SID_FM_EDIT;
else if ( uno::Reference< report::XImageControl>(_xElement,uno::UNO_QUERY).is() )
nId = SID_FM_IMAGECONTROL;
else if ( uno::Reference< report::XShape>(_xElement,uno::UNO_QUERY).is() )
nId = SID_DRAWTBX_CS_BASIC;
return nId;
}
OUString lcl_getName(const uno::Reference< beans::XPropertySet>& _xElement)
{
OSL_ENSURE(_xElement.is(),"Found report element which is NULL!");
OUString sTempName;
_xElement->getPropertyValue(PROPERTY_NAME) >>= sTempName;
OUStringBuffer sName = sTempName;
uno::Reference< report::XFixedText> xFixedText(_xElement,uno::UNO_QUERY);
uno::Reference< report::XReportControlModel> xReportModel(_xElement,uno::UNO_QUERY);
if ( xFixedText.is() )
{
sName.append(" : ");
sName.append(xFixedText->getLabel());
}
else if ( xReportModel.is() && _xElement->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
{
ReportFormula aFormula( xReportModel->getDataField() );
if ( aFormula.isValid() )
{
sName.append(" : ");
sName.append( aFormula.getUndecoratedContent() );
}
}
return sName.makeStringAndClear();
}
class NavigatorTree : public ::cppu::BaseMutex
, public SvTreeListBox
, public reportdesign::ITraverseReport
, public comphelper::OSelectionChangeListener
, public ::comphelper::OPropertyChangeListener
{
class UserData;
friend class UserData;
class UserData : public ::cppu::BaseMutex
,public ::comphelper::OPropertyChangeListener
,public ::comphelper::OContainerListener
{
uno::Reference< uno::XInterface > m_xContent;
::rtl::Reference< comphelper::OPropertyChangeMultiplexer> m_pListener;
::rtl::Reference< comphelper::OContainerListenerAdapter> m_pContainerListener;
VclPtr<NavigatorTree> m_pTree;
public:
UserData(NavigatorTree* _pTree,const uno::Reference<uno::XInterface>& _xContent);
virtual ~UserData();
const uno::Reference< uno::XInterface >& getContent() const { return m_xContent; }
inline void setContent(const uno::Reference< uno::XInterface >& _xContent) { m_xContent = _xContent; }
protected:
// OPropertyChangeListener
virtual void _propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException) override;
// OContainerListener
virtual void _elementInserted( const container::ContainerEvent& _rEvent ) throw(uno::RuntimeException, std::exception) override;
virtual void _elementRemoved( const container::ContainerEvent& Event )
throw (uno::RuntimeException, std::exception) override;
virtual void _elementReplaced( const container::ContainerEvent& _rEvent ) throw(uno::RuntimeException, std::exception) override;
virtual void _disposing(const lang::EventObject& _rSource)
throw (uno::RuntimeException, std::exception) override;
};
enum DROP_ACTION { DA_SCROLLUP, DA_SCROLLDOWN, DA_EXPANDNODE };
AutoTimer m_aDropActionTimer;
ImageList m_aNavigatorImages;
Point m_aTimerTriggered; // position at which the DropTimer started
DROP_ACTION m_aDropActionType;
OReportController& m_rController;
SvTreeListEntry* m_pMasterReport;
SvTreeListEntry* m_pDragedEntry;
::rtl::Reference< comphelper::OPropertyChangeMultiplexer> m_pReportListener;
::rtl::Reference< comphelper::OSelectionChangeMultiplexer> m_pSelectionListener;
unsigned short m_nTimerCounter;
SvTreeListEntry* insertEntry(const OUString& _sName,SvTreeListEntry* _pParent,sal_uInt16 _nImageId,sal_uLong _nPosition,UserData* _pData);
void traverseSection(const uno::Reference< report::XSection>& _xSection,SvTreeListEntry* _pParent,sal_uInt16 _nImageId,sal_uLong _nPosition = TREELIST_APPEND);
void traverseFunctions(const uno::Reference< report::XFunctions>& _xFunctions,SvTreeListEntry* _pParent);
protected:
virtual void Command( const CommandEvent& rEvt ) override;
// DragSourceHelper overridables
virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;
// DropTargetHelper overridables
virtual sal_Int8 AcceptDrop( const AcceptDropEvent& _rEvt ) override;
virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& _rEvt ) override;
// OSelectionChangeListener
virtual void _disposing(const lang::EventObject& _rSource)
throw (uno::RuntimeException, std::exception) override;
// OPropertyChangeListener
virtual void _propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException) override;
// OContainerListener Helper
void _elementInserted( const container::ContainerEvent& _rEvent );
void _elementRemoved( const container::ContainerEvent& Event );
void _elementReplaced( const container::ContainerEvent& _rEvent );
public:
NavigatorTree(vcl::Window* pParent,OReportController& _rController );
virtual ~NavigatorTree();
virtual void dispose() override;
DECL_LINK_TYPED(OnEntrySelDesel, SvTreeListBox*, void);
DECL_LINK_TYPED( OnDropActionTimer, Timer*, void );
virtual void _selectionChanged( const lang::EventObject& aEvent ) throw (uno::RuntimeException) override;
// ITraverseReport
virtual void traverseReport(const uno::Reference< report::XReportDefinition>& _xReport) override;
virtual void traverseReportFunctions(const uno::Reference< report::XFunctions>& _xFunctions) override;
virtual void traverseReportHeader(const uno::Reference< report::XSection>& _xSection) override;
virtual void traverseReportFooter(const uno::Reference< report::XSection>& _xSection) override;
virtual void traversePageHeader(const uno::Reference< report::XSection>& _xSection) override;
virtual void traversePageFooter(const uno::Reference< report::XSection>& _xSection) override;
virtual void traverseGroups(const uno::Reference< report::XGroups>& _xGroups) override;
virtual void traverseGroup(const uno::Reference< report::XGroup>& _xGroup) override;
virtual void traverseGroupFunctions(const uno::Reference< report::XFunctions>& _xFunctions) override;
virtual void traverseGroupHeader(const uno::Reference< report::XSection>& _xSection) override;
virtual void traverseGroupFooter(const uno::Reference< report::XSection>& _xSection) override;
virtual void traverseDetail(const uno::Reference< report::XSection>& _xSection) override;
SvTreeListEntry* find(const uno::Reference< uno::XInterface >& _xContent);
void removeEntry(SvTreeListEntry* _pEntry,bool _bRemove = true);
virtual Size GetOptimalSize() const override;
private:
using SvTreeListBox::ExecuteDrop;
};
NavigatorTree::NavigatorTree( vcl::Window* pParent,OReportController& _rController )
:SvTreeListBox( pParent, WB_TABSTOP| WB_HASBUTTONS|WB_HASLINES|WB_BORDER|WB_HSCROLL|WB_HASBUTTONSATROOT )
,comphelper::OSelectionChangeListener(m_aMutex)
,OPropertyChangeListener(m_aMutex)
,m_aTimerTriggered(-1,-1)
,m_aDropActionType( DA_SCROLLUP )
,m_rController(_rController)
,m_pMasterReport(nullptr)
,m_pDragedEntry(nullptr)
,m_nTimerCounter( DROP_ACTION_TIMER_INITIAL_TICKS )
{
set_hexpand(true);
set_vexpand(true);
m_pReportListener = new OPropertyChangeMultiplexer(this,m_rController.getReportDefinition().get());
m_pReportListener->addProperty(PROPERTY_PAGEHEADERON);
m_pReportListener->addProperty(PROPERTY_PAGEFOOTERON);
m_pReportListener->addProperty(PROPERTY_REPORTHEADERON);
m_pReportListener->addProperty(PROPERTY_REPORTFOOTERON);
m_pSelectionListener = new OSelectionChangeMultiplexer(this,&m_rController);
SetHelpId( HID_REPORT_NAVIGATOR_TREE );
m_aNavigatorImages = ImageList( ModuleRes( RID_SVXIMGLIST_RPTEXPL ) );
SetNodeBitmaps(
m_aNavigatorImages.GetImage( RID_SVXIMG_COLLAPSEDNODE ),
m_aNavigatorImages.GetImage( RID_SVXIMG_EXPANDEDNODE )
);
SetDragDropMode(DragDropMode::ALL);
EnableInplaceEditing( false );
SetSelectionMode(MULTIPLE_SELECTION);
Clear();
m_aDropActionTimer.SetTimeoutHdl(LINK(this, NavigatorTree, OnDropActionTimer));
SetSelectHdl(LINK(this, NavigatorTree, OnEntrySelDesel));
SetDeselectHdl(LINK(this, NavigatorTree, OnEntrySelDesel));
}
NavigatorTree::~NavigatorTree()
{
disposeOnce();
}
void NavigatorTree::dispose()
{
SvTreeListEntry* pCurrent = First();
while ( pCurrent )
{
delete static_cast<UserData*>(pCurrent->GetUserData());
pCurrent = Next(pCurrent);
}
m_pReportListener->dispose();
m_pSelectionListener->dispose();
SvTreeListBox::dispose();
}
void NavigatorTree::Command( const CommandEvent& rEvt )
{
bool bHandled = false;
switch( rEvt.GetCommand())
{
case CommandEventId::ContextMenu:
{
// the point that was clicked on
SvTreeListEntry* ptClickedOn = nullptr;
::Point aWhere;
if (rEvt.IsMouseEvent())
{
aWhere = rEvt.GetMousePosPixel();
ptClickedOn = GetEntry(aWhere);
if (ptClickedOn == nullptr)
break;
if ( !IsSelected(ptClickedOn) )
{
SelectAll(false);
Select(ptClickedOn);
SetCurEntry(ptClickedOn);
}
}
else
{
ptClickedOn = GetCurEntry();
if ( !ptClickedOn )
break;
aWhere = GetEntryPosition(ptClickedOn);
}
UserData* pData = static_cast<UserData*>(ptClickedOn->GetUserData());
uno::Reference< report::XFunctionsSupplier> xSupplier(pData->getContent(),uno::UNO_QUERY);
uno::Reference< report::XFunctions> xFunctions(pData->getContent(),uno::UNO_QUERY);
uno::Reference< report::XGroup> xGroup(pData->getContent(),uno::UNO_QUERY);
bool bDeleteAllowed = m_rController.isEditable() && (xGroup.is() ||
uno::Reference< report::XFunction>(pData->getContent(),uno::UNO_QUERY).is());
PopupMenu aContextMenu( ModuleRes( RID_MENU_NAVIGATOR ) );
sal_uInt16 nCount = aContextMenu.GetItemCount();
for (sal_uInt16 i = 0; i < nCount; ++i)
{
if ( MenuItemType::SEPARATOR != aContextMenu.GetItemType(i))
{
sal_uInt16 nId = aContextMenu.GetItemId(i);
aContextMenu.CheckItem(nId,m_rController.isCommandChecked(nId));
bool bEnabled = m_rController.isCommandEnabled(nId);
if ( nId == SID_RPT_NEW_FUNCTION )
aContextMenu.EnableItem(nId,m_rController.isEditable() && (xSupplier.is() || xFunctions.is()) );
// special condition, check for function and group
else if ( nId == SID_DELETE )
aContextMenu.EnableItem(SID_DELETE,bDeleteAllowed);
else
aContextMenu.EnableItem(nId,bEnabled);
}
}
sal_uInt16 nId = aContextMenu.Execute(this, aWhere);
if ( nId )
{
uno::Sequence< beans::PropertyValue> aArgs;
if ( nId == SID_RPT_NEW_FUNCTION )
{
aArgs.realloc(1);
aArgs[0].Value <<= (xFunctions.is() ? xFunctions : xSupplier->getFunctions());
}
else if ( nId == SID_DELETE )
{
if ( xGroup.is() )
nId = SID_GROUP_REMOVE;
aArgs.realloc(1);
aArgs[0].Name = PROPERTY_GROUP;
aArgs[0].Value <<= pData->getContent();
}
m_rController.executeUnChecked(nId,aArgs);
}
bHandled = true;
}
break;
default: break;
}
if (!bHandled)
SvTreeListBox::Command( rEvt );
}
sal_Int8 NavigatorTree::AcceptDrop( const AcceptDropEvent& _rEvt )
{
sal_Int8 nDropOption = DND_ACTION_NONE;
::Point aDropPos = _rEvt.maPosPixel;
if (_rEvt.mbLeaving)
{
if (m_aDropActionTimer.IsActive())
m_aDropActionTimer.Stop();
}
else
{
bool bNeedTrigger = false;
// At the first record?
if ((aDropPos.Y() >= 0) && (aDropPos.Y() < GetEntryHeight()))
{
m_aDropActionType = DA_SCROLLUP;
bNeedTrigger = true;
}
else if ((aDropPos.Y() < GetSizePixel().Height()) && (aDropPos.Y() >= GetSizePixel().Height() - GetEntryHeight()))
{
m_aDropActionType = DA_SCROLLDOWN;
bNeedTrigger = true;
}
else
{
SvTreeListEntry* pDropppedOn = GetEntry(aDropPos);
if (pDropppedOn && (GetChildCount(pDropppedOn) > 0) && !IsExpanded(pDropppedOn))
{
m_aDropActionType = DA_EXPANDNODE;
bNeedTrigger = true;
}
}
if (bNeedTrigger && (m_aTimerTriggered != aDropPos))
{
// again start counting
m_nTimerCounter = DROP_ACTION_TIMER_INITIAL_TICKS;
// remember the position, because I also get AcceptDrops, if the mouse does not move
m_aTimerTriggered = aDropPos;
// start Timer
if (!m_aDropActionTimer.IsActive()) // Does the Timer already exists?
{
m_aDropActionTimer.SetTimeout(DROP_ACTION_TIMER_TICK_BASE);
m_aDropActionTimer.Start();
}
}
else if (!bNeedTrigger)
m_aDropActionTimer.Stop();
}
return nDropOption;
}
sal_Int8 NavigatorTree::ExecuteDrop( const ExecuteDropEvent& /*_rEvt*/ )
{
return DND_ACTION_NONE;
}
void NavigatorTree::StartDrag( sal_Int8 /*_nAction*/, const Point& _rPosPixel )
{
m_pDragedEntry = GetEntry(_rPosPixel);
if ( m_pDragedEntry )
{
EndSelection();
}
}
IMPL_LINK_NOARG_TYPED(NavigatorTree, OnDropActionTimer, Timer *, void)
{
if (--m_nTimerCounter > 0)
return;
switch ( m_aDropActionType )
{
case DA_EXPANDNODE:
{
SvTreeListEntry* pToExpand = GetEntry(m_aTimerTriggered);
if (pToExpand && (GetChildCount(pToExpand) > 0) && !IsExpanded(pToExpand))
Expand(pToExpand);
m_aDropActionTimer.Stop();
}
break;
case DA_SCROLLUP :
ScrollOutputArea( 1 );
m_nTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
break;
case DA_SCROLLDOWN :
ScrollOutputArea( -1 );
m_nTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
break;
}
}
IMPL_LINK_NOARG_TYPED(NavigatorTree, OnEntrySelDesel, SvTreeListBox*, void)
{
if ( !m_pSelectionListener->locked() )
{
m_pSelectionListener->lock();
SvTreeListEntry* pEntry = GetCurEntry();
uno::Any aSelection;
if ( IsSelected(pEntry) )
aSelection <<= static_cast<UserData*>(pEntry->GetUserData())->getContent();
m_rController.select(aSelection);
m_pSelectionListener->unlock();
}
}
void NavigatorTree::_selectionChanged( const lang::EventObject& aEvent ) throw (uno::RuntimeException)
{
m_pSelectionListener->lock();
uno::Reference< view::XSelectionSupplier> xSelectionSupplier(aEvent.Source,uno::UNO_QUERY);
uno::Any aSec = xSelectionSupplier->getSelection();
uno::Sequence< uno::Reference< report::XReportComponent > > aSelection;
aSec >>= aSelection;
if ( !aSelection.getLength() )
{
uno::Reference< uno::XInterface> xSelection(aSec,uno::UNO_QUERY);
SvTreeListEntry* pEntry = find(xSelection);
if ( pEntry && !IsSelected(pEntry) )
{
Select(pEntry);
SetCurEntry(pEntry);
}
else if ( !pEntry )
SelectAll(false,false);
}
else
{
const uno::Reference< report::XReportComponent >* pIter = aSelection.getConstArray();
const uno::Reference< report::XReportComponent >* pEnd = pIter + aSelection.getLength();
for (; pIter != pEnd; ++pIter)
{
SvTreeListEntry* pEntry = find(*pIter);
if ( pEntry && !IsSelected(pEntry) )
{
Select(pEntry);
SetCurEntry(pEntry);
}
}
}
m_pSelectionListener->unlock();
}
SvTreeListEntry* NavigatorTree::insertEntry(const OUString& _sName,SvTreeListEntry* _pParent,sal_uInt16 _nImageId,sal_uLong _nPosition,UserData* _pData)
{
SvTreeListEntry* pEntry = nullptr;
if ( _nImageId )
{
const Image aImage( m_aNavigatorImages.GetImage( _nImageId ) );
pEntry = InsertEntry(_sName,aImage,aImage,_pParent,false,_nPosition,_pData);
}
else
pEntry = InsertEntry(_sName,_pParent,false,_nPosition,_pData);
return pEntry;
}
void NavigatorTree::traverseSection(const uno::Reference< report::XSection>& _xSection,SvTreeListEntry* _pParent,sal_uInt16 _nImageId,sal_uLong _nPosition)
{
SvTreeListEntry* pSection = insertEntry(_xSection->getName(),_pParent,_nImageId,_nPosition,new UserData(this,_xSection));
const sal_Int32 nCount = _xSection->getCount();
for (sal_Int32 i = 0; i < nCount; ++i)
{
uno::Reference< report::XReportComponent> xElement(_xSection->getByIndex(i),uno::UNO_QUERY_THROW);
OSL_ENSURE(xElement.is(),"Found report element which is NULL!");
insertEntry(lcl_getName(xElement.get()),pSection,lcl_getImageId(xElement),TREELIST_APPEND,new UserData(this,xElement));
uno::Reference< report::XReportDefinition> xSubReport(xElement,uno::UNO_QUERY);
if ( xSubReport.is() )
{
m_pMasterReport = find(_xSection->getReportDefinition());
reportdesign::OReportVisitor aSubVisitor(this);
aSubVisitor.start(xSubReport);
}
}
}
void NavigatorTree::traverseFunctions(const uno::Reference< report::XFunctions>& _xFunctions,SvTreeListEntry* _pParent)
{
SvTreeListEntry* pFunctions = insertEntry(OUString(ModuleRes(RID_STR_FUNCTIONS)), _pParent, SID_RPT_NEW_FUNCTION, TREELIST_APPEND, new UserData(this,_xFunctions));
const sal_Int32 nCount = _xFunctions->getCount();
for (sal_Int32 i = 0; i< nCount; ++i)
{
uno::Reference< report::XFunction> xElement(_xFunctions->getByIndex(i),uno::UNO_QUERY);
insertEntry(xElement->getName(),pFunctions,SID_RPT_NEW_FUNCTION,TREELIST_APPEND,new UserData(this,xElement));
}
}
SvTreeListEntry* NavigatorTree::find(const uno::Reference< uno::XInterface >& _xContent)
{
SvTreeListEntry* pRet = nullptr;
if ( _xContent.is() )
{
SvTreeListEntry* pCurrent = First();
while ( pCurrent )
{
UserData* pData = static_cast<UserData*>(pCurrent->GetUserData());
OSL_ENSURE(pData,"No UserData set an entry!");
if ( pData->getContent() == _xContent )
{
pRet = pCurrent;
break;
}
pCurrent = Next(pCurrent);
}
}
return pRet;
}
// ITraverseReport
void NavigatorTree::traverseReport(const uno::Reference< report::XReportDefinition>& _xReport)
{
insertEntry(_xReport->getName(),m_pMasterReport,SID_SELECT_REPORT,TREELIST_APPEND,new UserData(this,_xReport));
}
void NavigatorTree::traverseReportFunctions(const uno::Reference< report::XFunctions>& _xFunctions)
{
SvTreeListEntry* pReport = find(_xFunctions->getParent());
traverseFunctions(_xFunctions,pReport);
}
void NavigatorTree::traverseReportHeader(const uno::Reference< report::XSection>& _xSection)
{
SvTreeListEntry* pReport = find(_xSection->getReportDefinition());
traverseSection(_xSection,pReport,SID_REPORTHEADERFOOTER);
}
void NavigatorTree::traverseReportFooter(const uno::Reference< report::XSection>& _xSection)
{
SvTreeListEntry* pReport = find(_xSection->getReportDefinition());
traverseSection(_xSection,pReport,SID_REPORTHEADERFOOTER);
}
void NavigatorTree::traversePageHeader(const uno::Reference< report::XSection>& _xSection)
{
SvTreeListEntry* pReport = find(_xSection->getReportDefinition());
traverseSection(_xSection,pReport,SID_PAGEHEADERFOOTER);
}
void NavigatorTree::traversePageFooter(const uno::Reference< report::XSection>& _xSection)
{
SvTreeListEntry* pReport = find(_xSection->getReportDefinition());
traverseSection(_xSection,pReport,SID_PAGEHEADERFOOTER);
}
void NavigatorTree::traverseGroups(const uno::Reference< report::XGroups>& _xGroups)
{
SvTreeListEntry* pReport = find(_xGroups->getReportDefinition());
insertEntry(OUString(ModuleRes(RID_STR_GROUPS)), pReport, SID_SORTINGANDGROUPING, TREELIST_APPEND, new UserData(this,_xGroups));
}
void NavigatorTree::traverseGroup(const uno::Reference< report::XGroup>& _xGroup)
{
uno::Reference< report::XGroups> xGroups(_xGroup->getParent(),uno::UNO_QUERY);
SvTreeListEntry* pGroups = find(xGroups);
OSL_ENSURE(pGroups,"No Groups inserted so far. Why!");
insertEntry(_xGroup->getExpression(),pGroups,SID_GROUP,rptui::getPositionInIndexAccess(xGroups.get(),_xGroup),new UserData(this,_xGroup));
}
void NavigatorTree::traverseGroupFunctions(const uno::Reference< report::XFunctions>& _xFunctions)
{
SvTreeListEntry* pGroup = find(_xFunctions->getParent());
traverseFunctions(_xFunctions,pGroup);
}
void NavigatorTree::traverseGroupHeader(const uno::Reference< report::XSection>& _xSection)
{
SvTreeListEntry* pGroup = find(_xSection->getGroup());
OSL_ENSURE(pGroup,"No group found");
traverseSection(_xSection,pGroup,SID_GROUPHEADER,1);
}
void NavigatorTree::traverseGroupFooter(const uno::Reference< report::XSection>& _xSection)
{
SvTreeListEntry* pGroup = find(_xSection->getGroup());
OSL_ENSURE(pGroup,"No group found");
traverseSection(_xSection,pGroup,SID_GROUPFOOTER);
}
void NavigatorTree::traverseDetail(const uno::Reference< report::XSection>& _xSection)
{
uno::Reference< report::XReportDefinition> xReport = _xSection->getReportDefinition();
SvTreeListEntry* pParent = find(xReport);
traverseSection(_xSection,pParent,SID_ICON_DETAIL);
}
void NavigatorTree::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
{
uno::Reference< report::XReportDefinition> xReport(_rEvent.Source,uno::UNO_QUERY);
if ( xReport.is() )
{
bool bEnabled = false;
_rEvent.NewValue >>= bEnabled;
if ( bEnabled )
{
SvTreeListEntry* pParent = find(xReport);
if ( _rEvent.PropertyName == PROPERTY_REPORTHEADERON )
{
sal_uLong nPos = xReport->getReportHeaderOn() ? 2 : 1;
traverseSection(xReport->getReportHeader(),pParent,SID_REPORTHEADERFOOTER,nPos);
}
else if ( _rEvent.PropertyName == PROPERTY_PAGEHEADERON )
{
traverseSection(xReport->getPageHeader(),pParent, SID_PAGEHEADERFOOTER,1);
}
else if ( _rEvent.PropertyName == PROPERTY_PAGEFOOTERON )
traverseSection(xReport->getPageFooter(),pParent, SID_PAGEHEADERFOOTER);
else if ( _rEvent.PropertyName == PROPERTY_REPORTFOOTERON )
{
sal_uLong nPos = xReport->getPageFooterOn() ? (GetLevelChildCount(pParent) - 1) : TREELIST_APPEND;
traverseSection(xReport->getReportFooter(),pParent,SID_REPORTHEADERFOOTER,nPos);
}
}
}
}
void NavigatorTree::_elementInserted( const container::ContainerEvent& _rEvent )
{
SvTreeListEntry* pEntry = find(_rEvent.Source);
uno::Reference<beans::XPropertySet> xProp(_rEvent.Element,uno::UNO_QUERY_THROW);
OUString sName;
uno::Reference< beans::XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
if ( xInfo.is() )
{
if ( xInfo->hasPropertyByName(PROPERTY_NAME) )
xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
else if ( xInfo->hasPropertyByName(PROPERTY_EXPRESSION) )
xProp->getPropertyValue(PROPERTY_EXPRESSION) >>= sName;
}
uno::Reference< report::XGroup> xGroup(xProp,uno::UNO_QUERY);
if ( xGroup.is() )
{
reportdesign::OReportVisitor aSubVisitor(this);
aSubVisitor.start(xGroup);
}
else
{
uno::Reference< report::XReportComponent> xElement(xProp,uno::UNO_QUERY);
if ( xProp.is() )
sName = lcl_getName(xProp);
insertEntry(sName,pEntry,(!xElement.is() ? sal_uInt16(SID_RPT_NEW_FUNCTION) : lcl_getImageId(xElement)),TREELIST_APPEND,new UserData(this,xProp));
}
if ( !IsExpanded(pEntry) )
Expand(pEntry);
}
void NavigatorTree::_elementRemoved( const container::ContainerEvent& _rEvent )
{
uno::Reference<beans::XPropertySet> xProp(_rEvent.Element,uno::UNO_QUERY);
SvTreeListEntry* pEntry = find(xProp);
OSL_ENSURE(pEntry,"NavigatorTree::_elementRemoved: No Entry found!");
if (pEntry)
{
removeEntry(pEntry);
Invalidate();
}
}
void NavigatorTree::_elementReplaced( const container::ContainerEvent& _rEvent )
{
uno::Reference<beans::XPropertySet> xProp(_rEvent.ReplacedElement,uno::UNO_QUERY);
SvTreeListEntry* pEntry = find(xProp);
if ( pEntry )
{
UserData* pData = static_cast<UserData*>(pEntry->GetUserData());
xProp.set(_rEvent.Element,uno::UNO_QUERY);
pData->setContent(xProp);
OUString sName;
xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
SetEntryText(pEntry,sName);
}
}
void NavigatorTree::_disposing(const lang::EventObject& _rSource)
throw (uno::RuntimeException, std::exception)
{
removeEntry(find(_rSource.Source));
}
void NavigatorTree::removeEntry(SvTreeListEntry* _pEntry,bool _bRemove)
{
if ( _pEntry )
{
SvTreeListEntry* pChild = FirstChild(_pEntry);
while( pChild )
{
removeEntry(pChild,false);
pChild = NextSibling(pChild);
}
delete static_cast<UserData*>(_pEntry->GetUserData());
if ( _bRemove )
GetModel()->Remove(_pEntry);
}
}
NavigatorTree::UserData::UserData(NavigatorTree* _pTree,const uno::Reference<uno::XInterface>& _xContent)
: OPropertyChangeListener(m_aMutex)
, OContainerListener(m_aMutex)
, m_xContent(_xContent)
, m_pTree(_pTree)
{
uno::Reference<beans::XPropertySet> xProp(m_xContent,uno::UNO_QUERY);
if ( xProp.is() )
{
uno::Reference< beans::XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
if ( xInfo.is() )
{
m_pListener = new ::comphelper::OPropertyChangeMultiplexer(this,xProp);
if ( xInfo->hasPropertyByName(PROPERTY_NAME) )
m_pListener->addProperty(PROPERTY_NAME);
else if ( xInfo->hasPropertyByName(PROPERTY_EXPRESSION) )
m_pListener->addProperty(PROPERTY_EXPRESSION);
if ( xInfo->hasPropertyByName(PROPERTY_DATAFIELD) )
m_pListener->addProperty(PROPERTY_DATAFIELD);
if ( xInfo->hasPropertyByName(PROPERTY_LABEL) )
m_pListener->addProperty(PROPERTY_LABEL);
if ( xInfo->hasPropertyByName(PROPERTY_HEADERON) )
m_pListener->addProperty(PROPERTY_HEADERON);
if ( xInfo->hasPropertyByName(PROPERTY_FOOTERON) )
m_pListener->addProperty(PROPERTY_FOOTERON);
}
}
uno::Reference< container::XContainer> xContainer(m_xContent,uno::UNO_QUERY);
if ( xContainer.is() )
{
m_pContainerListener = new ::comphelper::OContainerListenerAdapter(this,xContainer);
}
}
NavigatorTree::UserData::~UserData()
{
if ( m_pContainerListener.is() )
m_pContainerListener->dispose();
if ( m_pListener.is() )
m_pListener->dispose();
}
// OPropertyChangeListener
void NavigatorTree::UserData::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
{
SvTreeListEntry* pEntry = m_pTree->find(_rEvent.Source);
OSL_ENSURE(pEntry,"No entry could be found! Why not!");
const bool bFooterOn = (PROPERTY_FOOTERON == _rEvent.PropertyName);
try
{
if ( bFooterOn || PROPERTY_HEADERON == _rEvent.PropertyName )
{
sal_Int32 nPos = 1;
uno::Reference< report::XGroup> xGroup(_rEvent.Source,uno::UNO_QUERY);
::std::mem_fun_t< bool,OGroupHelper> pIsOn = ::std::mem_fun(&OGroupHelper::getHeaderOn);
::std::mem_fun_t< uno::Reference<report::XSection> ,OGroupHelper> pMemFunSection = ::std::mem_fun(&OGroupHelper::getHeader);
if ( bFooterOn )
{
pIsOn = ::std::mem_fun(&OGroupHelper::getFooterOn);
pMemFunSection = ::std::mem_fun(&OGroupHelper::getFooter);
nPos = m_pTree->GetChildCount(pEntry) - 1;
}
OGroupHelper aGroupHelper(xGroup);
if ( pIsOn(&aGroupHelper) )
{
if ( bFooterOn )
++nPos;
m_pTree->traverseSection(pMemFunSection(&aGroupHelper),pEntry,bFooterOn ? SID_GROUPFOOTER : SID_GROUPHEADER,nPos);
}
}
else if ( PROPERTY_EXPRESSION == _rEvent.PropertyName)
{
OUString sNewName;
_rEvent.NewValue >>= sNewName;
m_pTree->SetEntryText(pEntry,sNewName);
}
else if ( PROPERTY_DATAFIELD == _rEvent.PropertyName || PROPERTY_LABEL == _rEvent.PropertyName || PROPERTY_NAME == _rEvent.PropertyName )
{
uno::Reference<beans::XPropertySet> xProp(_rEvent.Source,uno::UNO_QUERY);
m_pTree->SetEntryText(pEntry,lcl_getName(xProp));
}
}
catch(const uno::Exception &)
{}
}
void NavigatorTree::UserData::_elementInserted( const container::ContainerEvent& _rEvent ) throw(uno::RuntimeException, std::exception)
{
m_pTree->_elementInserted( _rEvent );
}
void NavigatorTree::UserData::_elementRemoved( const container::ContainerEvent& _rEvent )
throw (uno::RuntimeException, std::exception)
{
m_pTree->_elementRemoved( _rEvent );
}
void NavigatorTree::UserData::_elementReplaced( const container::ContainerEvent& _rEvent ) throw(uno::RuntimeException, std::exception)
{
m_pTree->_elementReplaced( _rEvent );
}
void NavigatorTree::UserData::_disposing(const lang::EventObject& _rSource)
throw (uno::RuntimeException, std::exception)
{
m_pTree->_disposing( _rSource );
}
Size NavigatorTree::GetOptimalSize() const
{
return LogicToPixel(Size(100, 70), MAP_APPFONT);
}
// class ONavigatorImpl
class ONavigatorImpl
{
public:
ONavigatorImpl(OReportController& _rController,ONavigator* _pParent);
ONavigatorImpl(const ONavigatorImpl&) = delete;
ONavigatorImpl& operator=(const ONavigatorImpl&) = delete;
uno::Reference< report::XReportDefinition> m_xReport;
::rptui::OReportController& m_rController;
VclPtr<NavigatorTree> m_pNavigatorTree;
};
ONavigatorImpl::ONavigatorImpl(OReportController& _rController,ONavigator* _pParent)
:m_xReport(_rController.getReportDefinition())
,m_rController(_rController)
,m_pNavigatorTree(VclPtr<NavigatorTree>::Create(_pParent->get<vcl::Window>("box"),_rController))
{
reportdesign::OReportVisitor aVisitor(m_pNavigatorTree.get());
aVisitor.start(m_xReport);
m_pNavigatorTree->Expand(m_pNavigatorTree->find(m_xReport));
lang::EventObject aEvent(m_rController);
m_pNavigatorTree->_selectionChanged(aEvent);
}
// class ONavigator
ONavigator::ONavigator(vcl::Window* _pParent ,OReportController& _rController)
: FloatingWindow( _pParent, "FloatingNavigator", "modules/dbreport/ui/floatingnavigator.ui")
{
m_pImpl.reset(new ONavigatorImpl(_rController,this));
m_pImpl->m_pNavigatorTree->Show();
m_pImpl->m_pNavigatorTree->GrabFocus();
Show();
}
void ONavigator::GetFocus()
{
Window::GetFocus();
if ( m_pImpl->m_pNavigatorTree.get() )
m_pImpl->m_pNavigatorTree->GrabFocus();
}
void ONavigator::dispose()
{
m_pImpl->m_pNavigatorTree.disposeAndClear();
FloatingWindow::dispose();
}
} // rptui
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|