LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - taborder.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 186 0.5 %
Date: 2014-11-03 Functions: 2 33 6.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "taborder.hxx"
      21             : 
      22             : #include "modulepcr.hxx"
      23             : #include "formresid.hrc"
      24             : #include "formstrings.hxx"
      25             : #include <comphelper/types.hxx>
      26             : #include <comphelper/property.hxx>
      27             : #include <cppuhelper/implbase1.hxx>
      28             : #include <com/sun/star/form/FormComponentType.hpp>
      29             : #include <com/sun/star/form/runtime/FormController.hpp>
      30             : #include <vcl/scrbar.hxx>
      31             : #include <svtools/treelistentry.hxx>
      32             : #include <vcl/builder.hxx>
      33             : 
      34             : 
      35             : namespace pcr
      36             : {
      37             : 
      38             : 
      39             :     using namespace ::com::sun::star::uno;
      40             :     using namespace ::com::sun::star::awt;
      41             :     using namespace ::com::sun::star::lang;
      42             :     using namespace ::com::sun::star::form;
      43             :     using namespace ::com::sun::star::beans;
      44             :     using namespace ::com::sun::star::datatransfer;
      45             : 
      46             : 
      47             :     //= OSimpleTabModel
      48             : 
      49           0 :     class OSimpleTabModel : public ::cppu::WeakImplHelper1< XTabControllerModel>
      50             :     {
      51             :         Sequence< Reference< XControlModel > > m_aModels;
      52             : 
      53             :     public:
      54           0 :         OSimpleTabModel( const Sequence< Reference< XControlModel > >& _rModels )
      55           0 :             :m_aModels( _rModels )
      56             :         {
      57           0 :         }
      58             : 
      59             :         // XTabControllerModel
      60           0 :         virtual void SAL_CALL setControlModels(const Sequence< Reference< XControlModel > >& rModels) throw( RuntimeException, std::exception ) SAL_OVERRIDE {m_aModels = rModels;}
      61           0 :         virtual Sequence< Reference< XControlModel > > SAL_CALL getControlModels(void) throw( RuntimeException, std::exception ) SAL_OVERRIDE {return m_aModels;}
      62           0 :         virtual void SAL_CALL setGroup(const Sequence< Reference< XControlModel > >& /*Group*/, const OUString& /*GroupName*/) throw( RuntimeException, std::exception ) SAL_OVERRIDE {}
      63           0 :         virtual sal_Int32 SAL_CALL getGroupCount(void) throw( RuntimeException, std::exception ) SAL_OVERRIDE {return 0;}
      64           0 :         virtual void SAL_CALL getGroup(sal_Int32 /*nGroup*/, Sequence< Reference< XControlModel > >& /*Group*/, OUString& /*Name*/) throw( RuntimeException, std::exception ) SAL_OVERRIDE {}
      65           0 :         virtual void SAL_CALL getGroupByName(const OUString& /*Name*/, Sequence< Reference< XControlModel > >& /*Group*/) throw( RuntimeException, std::exception ) SAL_OVERRIDE {}
      66           0 :         virtual sal_Bool SAL_CALL getGroupControl(void) throw( RuntimeException, std::exception ) SAL_OVERRIDE {return sal_False;} ;
      67           0 :         virtual void SAL_CALL setGroupControl(sal_Bool /*GroupControl*/) throw( RuntimeException, std::exception ) SAL_OVERRIDE {};
      68             :     };
      69             : 
      70             : 
      71             :     //= TabOrderDialog
      72             : 
      73             : 
      74           0 :     TabOrderDialog::TabOrderDialog( vcl::Window* _pParent, const Reference< XTabControllerModel >& _rxTabModel,
      75             :                     const Reference< XControlContainer >& _rxControlCont, const Reference< XComponentContext >& _rxORB )
      76             :         :ModalDialog( _pParent, "TabOrderDialog", "modules/spropctrlr/ui/taborder.ui")
      77             :         ,m_xModel( _rxTabModel )
      78             :         ,m_xControlContainer( _rxControlCont )
      79             :         ,m_xORB( _rxORB )
      80           0 :         ,pImageList( NULL )
      81             :     {
      82           0 :         get(m_pLB_Controls, "CTRLtree");
      83           0 :         get(m_pPB_OK, "ok");
      84           0 :         get(m_pPB_MoveUp, "upB");
      85           0 :         get(m_pPB_MoveDown, "downB");
      86           0 :         get(m_pPB_AutoOrder, "autoB");
      87             : 
      88             : 
      89           0 :         m_pPB_MoveUp->SetClickHdl( LINK( this, TabOrderDialog, MoveUpClickHdl ) );
      90           0 :         m_pPB_MoveDown->SetClickHdl( LINK( this, TabOrderDialog, MoveDownClickHdl ) );
      91           0 :         m_pPB_AutoOrder->SetClickHdl( LINK( this, TabOrderDialog, AutoOrderClickHdl ) );
      92           0 :         m_pPB_OK->SetClickHdl( LINK( this, TabOrderDialog, OKClickHdl ) );
      93           0 :         m_pPB_OK->Disable();
      94             : 
      95           0 :         pImageList = new ImageList( PcrRes( RID_IL_FORMEXPLORER ) );
      96             : 
      97           0 :         if ( m_xModel.is() )
      98           0 :             m_xTempModel = new OSimpleTabModel( m_xModel->getControlModels() );
      99             : 
     100           0 :         if ( m_xTempModel.is() && m_xControlContainer.is() )
     101           0 :             FillList();
     102             : 
     103           0 :         if ( m_pLB_Controls->GetEntryCount() < 2 )
     104             :         {
     105           0 :             m_pPB_MoveUp->Disable();
     106           0 :             m_pPB_MoveDown->Disable();
     107           0 :             m_pPB_AutoOrder->Disable();
     108             :         }
     109             : 
     110           0 :     }
     111             : 
     112             : 
     113           0 :     void TabOrderDialog::SetModified()
     114             :     {
     115           0 :         m_pPB_OK->Enable();
     116           0 :     }
     117             : 
     118             : 
     119           0 :     TabOrderDialog::~TabOrderDialog()
     120             :     {
     121           0 :         m_pLB_Controls->Hide();
     122             :         //  delete pLB_Controls;
     123           0 :         delete pImageList;
     124             : 
     125           0 :     }
     126             : 
     127             : 
     128           0 :     Image TabOrderDialog::GetImage( const Reference< XPropertySet >& _rxSet ) const
     129             :     {
     130           0 :         sal_uInt16 nImageId = RID_SVXIMG_CONTROL;
     131             :         // TODO: classify controls also in Basic propbrw
     132           0 :         if ( _rxSet.is() && ::comphelper::hasProperty( PROPERTY_CLASSID, _rxSet ) )
     133             :         {
     134           0 :             switch( ::comphelper::getINT16( _rxSet->getPropertyValue( PROPERTY_CLASSID ) ) )
     135             :             {
     136           0 :             case FormComponentType::COMMANDBUTTON:  nImageId = RID_SVXIMG_BUTTON; break;
     137           0 :             case FormComponentType::FIXEDTEXT:      nImageId = RID_SVXIMG_FIXEDTEXT; break;
     138           0 :             case FormComponentType::TEXTFIELD:      nImageId = RID_SVXIMG_EDIT; break;
     139           0 :             case FormComponentType::RADIOBUTTON:    nImageId = RID_SVXIMG_RADIOBUTTON; break;
     140           0 :             case FormComponentType::CHECKBOX:       nImageId = RID_SVXIMG_CHECKBOX; break;
     141           0 :             case FormComponentType::LISTBOX:        nImageId = RID_SVXIMG_LISTBOX; break;
     142           0 :             case FormComponentType::COMBOBOX:       nImageId = RID_SVXIMG_COMBOBOX; break;
     143           0 :             case FormComponentType::GROUPBOX:       nImageId = RID_SVXIMG_GROUPBOX; break;
     144           0 :             case FormComponentType::IMAGEBUTTON:    nImageId = RID_SVXIMG_IMAGEBUTTON; break;
     145           0 :             case FormComponentType::FILECONTROL:    nImageId = RID_SVXIMG_FILECONTROL; break;
     146           0 :             case FormComponentType::HIDDENCONTROL:  nImageId = RID_SVXIMG_HIDDEN; break;
     147           0 :             case FormComponentType::DATEFIELD:      nImageId = RID_SVXIMG_DATEFIELD; break;
     148           0 :             case FormComponentType::TIMEFIELD:      nImageId = RID_SVXIMG_TIMEFIELD; break;
     149           0 :             case FormComponentType::NUMERICFIELD:   nImageId = RID_SVXIMG_NUMERICFIELD; break;
     150           0 :             case FormComponentType::CURRENCYFIELD:  nImageId = RID_SVXIMG_CURRENCYFIELD; break;
     151           0 :             case FormComponentType::PATTERNFIELD:   nImageId = RID_SVXIMG_PATTERNFIELD; break;
     152           0 :             case FormComponentType::IMAGECONTROL:   nImageId = RID_SVXIMG_IMAGECONTROL; break;
     153           0 :             case FormComponentType::GRIDCONTROL:    nImageId = RID_SVXIMG_GRID; break;
     154           0 :             case FormComponentType::SCROLLBAR:      nImageId = RID_SVXIMG_SCROLLBAR; break;
     155           0 :             case FormComponentType::SPINBUTTON:     nImageId = RID_SVXIMG_SPINBUTTON; break;
     156           0 :             case FormComponentType::NAVIGATIONBAR:  nImageId = RID_SVXIMG_NAVIGATIONBAR; break;
     157             :             default:
     158             :                 OSL_FAIL( "TabOrderDialog::GetImage: unknown control type" );
     159             :             }
     160             :         }
     161             : 
     162           0 :         return pImageList->GetImage( nImageId );
     163             :     }
     164             : 
     165             : 
     166           0 :     void TabOrderDialog::FillList()
     167             :     {
     168             :         DBG_ASSERT( m_xTempModel.is() && m_xControlContainer.is(), "TabOrderDialog::FillList: invalid call!" );
     169           0 :         if ( !m_xTempModel.is() || !m_xControlContainer.is() )
     170           0 :             return;
     171             : 
     172           0 :         m_pLB_Controls->Clear();
     173             : 
     174             :         try
     175             :         {
     176           0 :             Sequence< Reference< XControlModel > > aControlModels( m_xTempModel->getControlModels() );
     177           0 :             const Reference< XControlModel >* pControlModels = aControlModels.getConstArray();
     178             : 
     179           0 :             OUString aName;
     180           0 :             Image aImage;
     181             : 
     182           0 :             for ( sal_Int32 i=0; i < aControlModels.getLength(); ++i, ++pControlModels )
     183             :             {
     184           0 :                 Reference< XPropertySet > xControl( *pControlModels, UNO_QUERY );
     185           0 :                 Reference< XPropertySetInfo > xPI;
     186           0 :                 if ( xControl.is() )
     187           0 :                     xPI = xControl->getPropertySetInfo();
     188             : 
     189           0 :                 if ( xPI.is() )
     190             :                 {
     191           0 :                     if ( xPI->hasPropertyByName( PROPERTY_TABSTOP ) )
     192             :                     {
     193           0 :                         aName = ::comphelper::getString( xControl->getPropertyValue( PROPERTY_NAME ) );
     194             :                             // TODO: do Basic controls have a name?
     195           0 :                         aImage = GetImage( xControl );
     196           0 :                         m_pLB_Controls->InsertEntry( aName, aImage, aImage, 0, false, TREELIST_APPEND, xControl.get() );
     197             :                     }
     198             :                 }
     199             :                 else
     200             :                 {
     201             :                     // no property set -> no tab order
     202             :                     OSL_FAIL( "TabOrderDialog::FillList: invalid control encountered!" );
     203           0 :                     m_pLB_Controls->Clear();
     204           0 :                     break;
     205             :                 }
     206           0 :             }
     207             :         }
     208           0 :         catch( const Exception& )
     209             :         {
     210             :             OSL_FAIL( "TabOrderDialog::FillList: caught an exception!" );
     211             :         }
     212             : 
     213             :         // select first entry
     214           0 :         SvTreeListEntry* pFirstEntry = m_pLB_Controls->GetEntry( 0 );
     215           0 :         if ( pFirstEntry )
     216           0 :             m_pLB_Controls->Select( pFirstEntry );
     217             :     }
     218             : 
     219             : 
     220           0 :     IMPL_LINK( TabOrderDialog, MoveUpClickHdl, Button*, /*pButton*/ )
     221             :     {
     222           0 :         m_pLB_Controls->MoveSelection( -1 );
     223           0 :         return 0;
     224             :     }
     225             : 
     226             : 
     227           0 :     IMPL_LINK( TabOrderDialog, MoveDownClickHdl, Button*, /*pButton*/ )
     228             :     {
     229           0 :         m_pLB_Controls->MoveSelection( 1 );
     230           0 :         return 0;
     231             :     }
     232             : 
     233             : 
     234           0 :     IMPL_LINK( TabOrderDialog, AutoOrderClickHdl, Button*, /*pButton*/ )
     235             :     {
     236             :         try
     237             :         {
     238           0 :             Reference< css::form::runtime::XFormController > xTabController = css::form::runtime::FormController::create( m_xORB );
     239             : 
     240           0 :             xTabController->setModel( m_xTempModel );
     241           0 :             xTabController->setContainer( m_xControlContainer );
     242           0 :             xTabController->autoTabOrder();
     243             : 
     244           0 :             SetModified();
     245           0 :             FillList();
     246             : 
     247           0 :             ::comphelper::disposeComponent( xTabController );
     248             :         }
     249           0 :         catch( const Exception& )
     250             :         {
     251             :             OSL_FAIL( "TabOrderDialog::AutoOrderClickHdl: caught an exception!" );
     252             :         }
     253             : 
     254           0 :         return 0;
     255             :     }
     256             : 
     257             : 
     258           0 :     IMPL_LINK( TabOrderDialog, OKClickHdl, Button*, /*pButton*/ )
     259             :     {
     260           0 :         sal_uLong nEntryCount = m_pLB_Controls->GetEntryCount();
     261           0 :         Sequence< Reference< XControlModel > > aSortedControlModelSeq( nEntryCount );
     262           0 :         Sequence< Reference< XControlModel > > aControlModels( m_xTempModel->getControlModels());
     263           0 :         Reference< XControlModel > * pSortedControlModels = aSortedControlModelSeq.getArray();
     264           0 :         const Reference< XControlModel > * pControlModels = aControlModels.getConstArray();
     265             : 
     266           0 :         for (sal_uLong i=0; i < nEntryCount; i++)
     267             :         {
     268           0 :             SvTreeListEntry* pEntry = m_pLB_Controls->GetEntry(i);
     269             : 
     270           0 :             for( sal_Int32 j=0; j<aControlModels.getLength(); j++ )
     271             :             {
     272           0 :                 Reference< XPropertySet >  xSet(pControlModels[j], UNO_QUERY);
     273           0 :                 if ((XPropertySet*)xSet.get() == ((XPropertySet*)pEntry->GetUserData()))
     274             :                 {
     275           0 :                     pSortedControlModels[i] = pControlModels[j];
     276           0 :                     break;
     277             :                 }
     278           0 :             }
     279             :         }
     280             : 
     281             :         // TODO: UNO action (to bracket all the single actions which are being created)
     282           0 :         m_xModel->setControlModels( aSortedControlModelSeq );
     283             : 
     284           0 :         EndDialog( sal_True );
     285           0 :         return 0;
     286             :     }
     287             : 
     288             : 
     289             :     //= TabOrderListBox
     290             : 
     291             : 
     292           0 :     TabOrderListBox::TabOrderListBox( vcl::Window* pParent, WinBits nBits  )
     293           0 :         :SvTreeListBox( pParent, nBits  )
     294             :     {
     295           0 :         SetDragDropMode(0xFFFF/*SV_DRAGDROP_CTRL_MOVE*/);
     296             :             // Hmm. The flag alone is not enough, so to be on the safe side ...
     297             : 
     298           0 :         SetSelectionMode( MULTIPLE_SELECTION );
     299           0 :     }
     300             : 
     301           0 :     extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeTabOrderListBox(vcl::Window *pParent,
     302             :          VclBuilder::stringmap &rMap)
     303             :     {
     304           0 :          WinBits nWinStyle = WB_TABSTOP;
     305           0 :          OString sBorder = VclBuilder::extractCustomProperty(rMap);
     306           0 :          if (!sBorder.isEmpty())
     307           0 :              nWinStyle |= WB_BORDER;
     308           0 :          return new TabOrderListBox(pParent, nWinStyle);
     309             :     }
     310             : 
     311             : 
     312           0 :     TabOrderListBox::~TabOrderListBox()
     313             :     {
     314           0 :     }
     315             : 
     316             : 
     317           0 :     void TabOrderListBox::ModelHasMoved( SvTreeListEntry* _pSource )
     318             :     {
     319           0 :         SvTreeListBox::ModelHasMoved( _pSource );
     320             : 
     321           0 :         static_cast<TabOrderDialog*>(GetParentDialog())->SetModified();
     322           0 :     }
     323             : 
     324             : 
     325           0 :     void TabOrderListBox::MoveSelection( long nRelPos )
     326             :     {
     327           0 :         OUString aSelEntryPrevText, aSelEntryNextText;
     328           0 :         Image  aImage;
     329           0 :         for (long i=0; i<labs(nRelPos); i++)
     330             :         {
     331           0 :             static_cast<TabOrderDialog*>(GetParentDialog())->SetModified();
     332             : 
     333             : 
     334             :             // move entries
     335           0 :             if( nRelPos < 0 )
     336             :             {
     337           0 :                 SvTreeListEntry* pFirstSelected = FirstSelected();
     338           0 :                 if( !pFirstSelected ) return;
     339           0 :                 sal_uLong nFirstSelPos = GetModel()->GetAbsPos( pFirstSelected );
     340           0 :                 if( nFirstSelPos == 0 ) return;
     341             : 
     342           0 :                 SvTreeListEntry* pSelEntry = pFirstSelected;
     343           0 :                 while( pSelEntry )
     344             :                 {
     345           0 :                     sal_uLong nSelEntryPos = GetModel()->GetAbsPos( pSelEntry );
     346           0 :                     SvTreeListEntry* pSelEntryPrev = GetEntry( nSelEntryPos-1 );
     347           0 :                     aSelEntryPrevText = GetEntryText( pSelEntryPrev );
     348           0 :                     aImage = GetExpandedEntryBmp(pSelEntryPrev);
     349           0 :                     void*  pData = pSelEntryPrev->GetUserData();
     350             : 
     351           0 :                     GetModel()->Remove( pSelEntryPrev );
     352           0 :                     InsertEntry( aSelEntryPrevText, aImage, aImage, 0, false, nSelEntryPos, pData );
     353             : 
     354           0 :                     pSelEntry = NextSelected( pSelEntry );
     355             :                 }
     356             :             }
     357             : 
     358           0 :             else if( nRelPos > 0 )
     359             :             {
     360           0 :                 SvTreeListEntry* pLastSelected = LastSelected();
     361           0 :                 if( !pLastSelected ) return;
     362           0 :                 sal_uLong nLastSelPos = GetModel()->GetAbsPos( pLastSelected );
     363             : 
     364           0 :                 if( (nLastSelPos + nRelPos - i) > (GetEntryCount()-1) ) return;
     365             : 
     366             : #if OSL_DEBUG_LEVEL > 0
     367             :                 sal_uLong nSelCount = GetSelectionCount();
     368             :                 (void)nSelCount;
     369             : #endif
     370             : 
     371             : 
     372           0 :                 SvTreeListEntry* pSelEntry = pLastSelected;
     373           0 :                 while( pSelEntry )
     374             :                 {
     375           0 :                     sal_uLong nSelEntryPos = GetModel()->GetAbsPos( pSelEntry );
     376           0 :                     SvTreeListEntry* pSelEntryNext = GetEntry( nSelEntryPos+1 );
     377           0 :                     void* pData = pSelEntryNext->GetUserData();
     378             : 
     379           0 :                     aSelEntryNextText = GetEntryText( pSelEntryNext );
     380           0 :                     aImage = GetExpandedEntryBmp(pSelEntryNext);
     381             : 
     382           0 :                     GetModel()->Remove( pSelEntryNext );
     383           0 :                     InsertEntry( aSelEntryNextText, aImage, aImage, 0, false, nSelEntryPos, pData );
     384             : 
     385           0 :                     pSelEntry = PrevSelected( pSelEntry );
     386             :                 }
     387           0 :                 long nThumbPos      = GetVScroll()->GetThumbPos();
     388           0 :                 long nVisibleSize   = GetVScroll()->GetVisibleSize();
     389           0 :                 long nFirstVisible = GetModel()->GetAbsPos( FirstVisible());
     390             : 
     391           0 :                 if ( ( nThumbPos + nVisibleSize + 1 ) < (long)( nLastSelPos + 3 ) )
     392           0 :                     GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
     393           0 :                 else if((nThumbPos+nVisibleSize+1) >= (nFirstVisible))
     394           0 :                     GetVScroll()->DoScrollAction(SCROLL_LINEUP);
     395             :             }
     396           0 :         }
     397             :     }
     398             : 
     399             : 
     400          12 : }  // namespace pcr
     401             : 
     402             : 
     403             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10