LCOV - code coverage report
Current view: top level - libreoffice/sdext/source/minimizer - unodialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 131 0.0 %
Date: 2012-12-27 Functions: 0 19 0.0 %
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             : 
      21             : #include "unodialog.hxx"
      22             : #include <com/sun/star/text/XTextRange.hpp>
      23             : #include <com/sun/star/drawing/XShapes.hpp>
      24             : #include <com/sun/star/container/XIndexAccess.hpp>
      25             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      26             : #include <com/sun/star/view/XControlAccess.hpp>
      27             : #include <com/sun/star/frame/XDispatch.hpp>
      28             : #include <com/sun/star/awt/Toolkit.hpp>
      29             : #include <com/sun/star/awt/XMessageBoxFactory.hpp>
      30             : #include <com/sun/star/awt/MessageBoxButtons.hpp>
      31             : 
      32             : // -------------
      33             : // - UnoDialog -
      34             : // -------------
      35             : 
      36             : using namespace ::rtl;
      37             : using namespace ::com::sun::star::awt;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::util;
      40             : using namespace ::com::sun::star::lang;
      41             : using namespace ::com::sun::star::view;
      42             : using namespace ::com::sun::star::frame;
      43             : using namespace ::com::sun::star::beans;
      44             : using namespace ::com::sun::star::script;
      45             : 
      46           0 : UnoDialog::UnoDialog( const Reference< XComponentContext > &rxMSF, Reference< XFrame >& rxFrame ) :
      47             :     mxMSF( rxMSF ),
      48           0 :     mxController( rxFrame->getController() ),
      49           0 :     mxDialogModel( mxMSF->getServiceManager()->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM(
      50           0 :         "com.sun.star.awt.UnoControlDialogModel" ) ), mxMSF ), UNO_QUERY_THROW ),
      51             :     mxDialogModelMultiPropertySet( mxDialogModel, UNO_QUERY_THROW ),
      52             :     mxDialogModelPropertySet( mxDialogModel, UNO_QUERY_THROW ),
      53             :     mxDialogModelMSF( mxDialogModel, UNO_QUERY_THROW ),
      54             :     mxDialogModelNameContainer( mxDialogModel, UNO_QUERY_THROW ),
      55             :     mxDialogModelNameAccess( mxDialogModel, UNO_QUERY_THROW ),
      56             :     mxControlModel( mxDialogModel, UNO_QUERY_THROW ),
      57           0 :     mxDialog( mxMSF->getServiceManager()->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM(
      58           0 :         "com.sun.star.awt.UnoControlDialog" ) ), mxMSF ), UNO_QUERY_THROW ),
      59             :     mxControl( mxDialog, UNO_QUERY_THROW ),
      60           0 :     mbStatus( sal_False )
      61             : {
      62           0 :     mxControl->setModel( mxControlModel );
      63           0 :     mxDialogControlContainer = Reference< XControlContainer >( mxDialog, UNO_QUERY_THROW );
      64           0 :     mxDialogComponent = Reference< XComponent >( mxDialog, UNO_QUERY_THROW );
      65           0 :     mxDialogWindow = Reference< XWindow >( mxDialog, UNO_QUERY_THROW );
      66             : 
      67           0 :     Reference< XFrame > xFrame( mxController->getFrame() );
      68           0 :     Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
      69           0 :     mxWindowPeer = Reference< XWindowPeer >( xContainerWindow, UNO_QUERY_THROW );
      70           0 :     createWindowPeer( mxWindowPeer );
      71           0 : }
      72             : 
      73             : // -----------------------------------------------------------------------------
      74             : 
      75           0 : UnoDialog::~UnoDialog()
      76             : {
      77             : 
      78           0 : }
      79             : 
      80             : // -----------------------------------------------------------------------------
      81             : 
      82           0 : void UnoDialog::execute()
      83             : {
      84           0 :     mxDialogWindow->setEnable( sal_True );
      85           0 :     mxDialogWindow->setVisible( sal_True );
      86           0 :     mxDialog->execute();
      87           0 : }
      88             : 
      89           0 : void UnoDialog::endExecute( sal_Bool bStatus )
      90             : {
      91           0 :     mbStatus = bStatus;
      92           0 :     mxDialog->endExecute();
      93           0 : }
      94             : 
      95             : // -----------------------------------------------------------------------------
      96             : 
      97           0 : Reference< XWindowPeer > UnoDialog::createWindowPeer( Reference< XWindowPeer > xParentPeer )
      98             :     throw ( Exception )
      99             : {
     100           0 :     mxDialogWindow->setVisible( sal_False );
     101           0 :     Reference< XToolkit > xToolkit( Toolkit::create( mxMSF ), UNO_QUERY_THROW  );
     102           0 :     if ( !xParentPeer.is() )
     103           0 :         xParentPeer = xToolkit->getDesktopWindow();
     104           0 :     mxReschedule = Reference< XReschedule >( xToolkit, UNO_QUERY );
     105           0 :     mxControl->createPeer( xToolkit, xParentPeer );
     106             : //  xWindowPeer = xControl.getPeer();
     107           0 :     return mxControl->getPeer();
     108             : }
     109             : 
     110             : // -----------------------------------------------------------------------------
     111             : 
     112           0 : Reference< XInterface > UnoDialog::insertControlModel( const OUString& rServiceName, const OUString& rName,
     113             :                                                         const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
     114             : {
     115           0 :     Reference< XInterface > xControlModel;
     116             :     try
     117             :     {
     118           0 :         xControlModel = mxDialogModelMSF->createInstance( rServiceName );
     119           0 :         Reference< XMultiPropertySet > xMultiPropSet( xControlModel, UNO_QUERY_THROW );
     120           0 :         xMultiPropSet->setPropertyValues( rPropertyNames, rPropertyValues );
     121           0 :         mxDialogModelNameContainer->insertByName( rName, Any( xControlModel ) );
     122             :     }
     123           0 :     catch( Exception& )
     124             :     {
     125             :     }
     126           0 :     return xControlModel;
     127             : }
     128             : 
     129             : // -----------------------------------------------------------------------------
     130             : 
     131           0 : void UnoDialog::setVisible( const OUString& rName, sal_Bool bVisible )
     132             : {
     133             :     try
     134             :     {
     135           0 :         Reference< XInterface > xControl( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
     136           0 :         Reference< XWindow > xWindow( xControl, UNO_QUERY_THROW );
     137           0 :         xWindow->setVisible( bVisible );
     138             :     }
     139           0 :     catch ( Exception& )
     140             :     {
     141             :     }
     142           0 : }
     143             : 
     144             : // -----------------------------------------------------------------------------
     145             : 
     146           0 : Reference< XButton > UnoDialog::insertButton( const OUString& rName, Reference< XActionListener > xActionListener,
     147             :             const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
     148             : {
     149           0 :     Reference< XButton > xButton;
     150             :     try
     151             :     {
     152             :         Reference< XInterface > xButtonModel( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ),
     153           0 :             rName, rPropertyNames, rPropertyValues ) );
     154           0 :         Reference< XPropertySet > xPropertySet( xButtonModel, UNO_QUERY_THROW );
     155           0 :         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
     156           0 :         xButton = Reference< XButton >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
     157             : 
     158           0 :         if ( xActionListener.is() )
     159             :         {
     160           0 :             xButton->addActionListener( xActionListener );
     161           0 :             xButton->setActionCommand( rName );
     162             :         }
     163           0 :         return xButton;
     164             :     }
     165           0 :     catch( Exception& )
     166             :     {
     167             :     }
     168           0 :     return xButton;
     169             : }
     170             : 
     171             : // -----------------------------------------------------------------------------
     172             : 
     173           0 : Reference< XFixedText > UnoDialog::insertFixedText( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
     174             : {
     175           0 :     Reference< XFixedText > xFixedText;
     176             :     try
     177             :     {
     178             :         Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFixedTextModel" ) ),
     179           0 :             rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
     180           0 :         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
     181           0 :         xFixedText = Reference< XFixedText >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
     182             :     }
     183           0 :     catch ( Exception& )
     184             :     {
     185             :     }
     186           0 :     return xFixedText;
     187             : }
     188             : 
     189             : // -----------------------------------------------------------------------------
     190             : 
     191           0 : Reference< XCheckBox > UnoDialog::insertCheckBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
     192             : {
     193           0 :     Reference< XCheckBox > xCheckBox;
     194             :     try
     195             :     {
     196             :         Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlCheckBoxModel" ) ),
     197           0 :             rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
     198           0 :         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
     199           0 :         xCheckBox = Reference< XCheckBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
     200             :     }
     201           0 :     catch ( Exception& )
     202             :     {
     203             :     }
     204           0 :     return xCheckBox;
     205             : }
     206             : 
     207             : // -----------------------------------------------------------------------------
     208             : 
     209           0 : Reference< XControl > UnoDialog::insertFormattedField( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
     210             : {
     211           0 :     Reference< XControl > xControl;
     212             :     try
     213             :     {
     214             :         Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFormattedFieldModel" ) ),
     215           0 :             rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
     216           0 :         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
     217           0 :         xControl = Reference< XControl >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
     218             :     }
     219           0 :     catch ( Exception& )
     220             :     {
     221             :     }
     222           0 :     return xControl;
     223             : }
     224             : 
     225             : // -----------------------------------------------------------------------------
     226             : 
     227           0 : Reference< XComboBox > UnoDialog::insertComboBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
     228             : {
     229           0 :     Reference< XComboBox > xControl;
     230             :     try
     231             :     {
     232             :         Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlComboBoxModel" ) ),
     233           0 :             rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
     234           0 :         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
     235           0 :         xControl = Reference< XComboBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
     236             :     }
     237           0 :     catch ( Exception& )
     238             :     {
     239             :     }
     240           0 :     return xControl;
     241             : }
     242             : 
     243             : // -----------------------------------------------------------------------------
     244             : 
     245           0 : Reference< XRadioButton > UnoDialog::insertRadioButton( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
     246             : {
     247           0 :     Reference< XRadioButton > xControl;
     248             :     try
     249             :     {
     250             :         Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlRadioButtonModel" ) ),
     251           0 :             rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
     252           0 :         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
     253           0 :         xControl = Reference< XRadioButton >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
     254             :     }
     255           0 :     catch ( Exception& )
     256             :     {
     257             :     }
     258           0 :     return xControl;
     259             : }
     260             : 
     261             : // -----------------------------------------------------------------------------
     262             : 
     263           0 : Reference< XListBox > UnoDialog::insertListBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
     264             : {
     265           0 :     Reference< XListBox > xControl;
     266             :     try
     267             :     {
     268             :         Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlListBoxModel" ) ),
     269           0 :             rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
     270           0 :         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
     271           0 :         xControl = Reference< XListBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
     272             :     }
     273           0 :     catch ( Exception& )
     274             :     {
     275             :     }
     276           0 :     return xControl;
     277             : }
     278             : 
     279             : // -----------------------------------------------------------------------------
     280             : 
     281           0 : Reference< XControl > UnoDialog::insertImage( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
     282             : {
     283           0 :     Reference< XControl > xControl;
     284             :     try
     285             :     {
     286             :         Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlImageControlModel" ) ),
     287           0 :             rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
     288           0 :         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
     289           0 :         xControl = Reference< XControl >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
     290             :     }
     291           0 :     catch ( Exception& )
     292             :     {
     293             :     }
     294           0 :     return xControl;
     295             : }
     296             : 
     297             : // -----------------------------------------------------------------------------
     298             : 
     299           0 : void UnoDialog::setControlProperty( const OUString& rControlName, const OUString& rPropertyName, const Any& rPropertyValue )
     300             : {
     301             :     try
     302             :     {
     303           0 :         if ( mxDialogModelNameAccess->hasByName( rControlName ) )
     304             :         {
     305           0 :             Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
     306           0 :             xPropertySet->setPropertyValue( rPropertyName, rPropertyValue );
     307             :         }
     308             :     }
     309           0 :     catch ( Exception& )
     310             :     {
     311             :     }
     312           0 : }
     313             : 
     314             : // -----------------------------------------------------------------------------
     315             : 
     316           0 : Any UnoDialog::getControlProperty( const OUString& rControlName, const OUString& rPropertyName )
     317             : {
     318           0 :     Any aRet;
     319             :     try
     320             :     {
     321           0 :         if ( mxDialogModelNameAccess->hasByName( rControlName ) )
     322             :         {
     323           0 :             Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
     324           0 :             aRet = xPropertySet->getPropertyValue( rPropertyName );
     325             :         }
     326             :     }
     327           0 :     catch ( Exception& )
     328             :     {
     329             :     }
     330           0 :     return aRet;
     331             : }
     332             : 
     333             : // -----------------------------------------------------------------------------
     334             : 
     335           0 : void UnoDialog::enableControl( const OUString& rControlName )
     336             : {
     337           0 :     const OUString sEnabled( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) );
     338           0 :     setControlProperty( rControlName, sEnabled, Any( sal_True ) );
     339           0 : }
     340             : 
     341             : // -----------------------------------------------------------------------------
     342             : 
     343           0 : void UnoDialog::disableControl( const OUString& rControlName )
     344             : {
     345           0 :     const OUString sEnabled( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) );
     346           0 :     setControlProperty( rControlName, sEnabled, Any( sal_False ) );
     347           0 : }
     348             : 
     349             : // -----------------------------------------------------------------------------
     350             : 
     351             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10