LCOV - code coverage report
Current view: top level - extensions/source/dbpilots - optiongrouplayouter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 74 0.0 %
Date: 2012-08-25 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "optiongrouplayouter.hxx"
      30                 :            : #include <com/sun/star/awt/Size.hpp>
      31                 :            : #include <com/sun/star/awt/Point.hpp>
      32                 :            : #include <com/sun/star/container/XIndexAccess.hpp>
      33                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      34                 :            : #include <com/sun/star/drawing/XShapes.hpp>
      35                 :            : #include <com/sun/star/drawing/XShapeGrouper.hpp>
      36                 :            : #include <com/sun/star/text/TextContentAnchorType.hpp>
      37                 :            : #include <com/sun/star/view/XSelectionSupplier.hpp>
      38                 :            : #include "controlwizard.hxx"
      39                 :            : #include "groupboxwiz.hxx"
      40                 :            : #include "dbptools.hxx"
      41                 :            : 
      42                 :            : //.........................................................................
      43                 :            : namespace dbp
      44                 :            : {
      45                 :            : //.........................................................................
      46                 :            : 
      47                 :            : #define BUTTON_HEIGHT       300
      48                 :            : #define HEIGHT              450
      49                 :            : #define OFFSET              300
      50                 :            : #define MIN_WIDTH           600
      51                 :            : 
      52                 :            :     using namespace ::com::sun::star::uno;
      53                 :            :     using namespace ::com::sun::star::drawing;
      54                 :            :     using namespace ::com::sun::star::beans;
      55                 :            :     using namespace ::com::sun::star::awt;
      56                 :            :     using namespace ::com::sun::star::container;
      57                 :            :     using namespace ::com::sun::star::lang;
      58                 :            :     using namespace ::com::sun::star::text;
      59                 :            :     using namespace ::com::sun::star::view;
      60                 :            : 
      61                 :            :     //=====================================================================
      62                 :            :     //= OOptionGroupLayouter
      63                 :            :     //=====================================================================
      64                 :            :     //---------------------------------------------------------------------
      65                 :          0 :     OOptionGroupLayouter::OOptionGroupLayouter(const Reference< XMultiServiceFactory >& _rxORB)
      66                 :          0 :         :m_xORB(_rxORB)
      67                 :            :     {
      68                 :          0 :     }
      69                 :            : 
      70                 :            :     //---------------------------------------------------------------------
      71                 :          0 :     void OOptionGroupLayouter::doLayout(const OControlWizardContext& _rContext, const OOptionGroupSettings& _rSettings)
      72                 :            :     {
      73                 :          0 :         Reference< XShapes > xPageShapes(_rContext.xDrawPage, UNO_QUERY);
      74                 :          0 :         if (!xPageShapes.is())
      75                 :            :         {
      76                 :            :             OSL_FAIL("OOptionGroupLayouter::OOptionGroupLayouter: missing the XShapes interface for the page!");
      77                 :            :             return;
      78                 :            :         }
      79                 :            : 
      80                 :          0 :         Reference< XMultiServiceFactory > xDocFactory(_rContext.xDocumentModel, UNO_QUERY);
      81                 :          0 :         if (!xDocFactory.is())
      82                 :            :         {
      83                 :            :             OSL_FAIL("OOptionGroupLayouter::OOptionGroupLayouter: no document service factory!");
      84                 :            :             return;
      85                 :            :         }
      86                 :            : 
      87                 :            :         // no. of buttons to create
      88                 :          0 :         sal_Int32 nRadioButtons = _rSettings.aLabels.size();
      89                 :            : 
      90                 :          0 :         sal_Int32 nTopSpace = 0;
      91                 :            : 
      92                 :            :         // the shape of the groupbox
      93                 :          0 :         ::com::sun::star::awt::Size aControlShapeSize = _rContext.xObjectShape->getSize();
      94                 :            :         // maybe need to adjust the size if the control shapes
      95                 :          0 :         sal_Int32 nMinShapeHeight = BUTTON_HEIGHT*(nRadioButtons+1) + BUTTON_HEIGHT + BUTTON_HEIGHT/4;
      96                 :          0 :         if (aControlShapeSize.Height < nMinShapeHeight)
      97                 :          0 :             aControlShapeSize.Height = nMinShapeHeight;
      98                 :          0 :         if (aControlShapeSize.Width < MIN_WIDTH)
      99                 :          0 :             aControlShapeSize.Width = MIN_WIDTH;
     100                 :          0 :         _rContext.xObjectShape->setSize(aControlShapeSize);
     101                 :            : 
     102                 :            :         // if we're working on a writer document, we need to anchor the shape
     103                 :          0 :         implAnchorShape(Reference< XPropertySet >(_rContext.xObjectShape, UNO_QUERY));
     104                 :            : 
     105                 :            :         // shape collection (for grouping the shapes)
     106                 :          0 :         Reference< XShapes > xButtonCollection(m_xORB->createInstance(
     107                 :          0 :                 ::rtl::OUString("com.sun.star.drawing.ShapeCollection")),
     108                 :          0 :             UNO_QUERY);
     109                 :            :         // first member : the shape of the control
     110                 :          0 :         xButtonCollection->add(_rContext.xObjectShape.get());
     111                 :            : 
     112                 :          0 :         sal_Int32 nTempHeight = (aControlShapeSize.Height - BUTTON_HEIGHT/4) / (nRadioButtons + 1);
     113                 :            : 
     114                 :          0 :         ::com::sun::star::awt::Point aShapePosition = _rContext.xObjectShape->getPosition();
     115                 :            : 
     116                 :          0 :         ::com::sun::star::awt::Size aButtonSize(aControlShapeSize);
     117                 :          0 :         aButtonSize.Width = aControlShapeSize.Width - OFFSET;
     118                 :          0 :         aButtonSize.Height = HEIGHT;
     119                 :          0 :         ::com::sun::star::awt::Point aButtonPosition;
     120                 :          0 :         aButtonPosition.X = aShapePosition.X + OFFSET;
     121                 :            : 
     122                 :          0 :         ::rtl::OUString sElementsName("RadioGroup");
     123                 :          0 :         disambiguateName(Reference< XNameAccess >(_rContext.xForm, UNO_QUERY), sElementsName);
     124                 :            : 
     125                 :          0 :         StringArray::const_iterator aLabelIter = _rSettings.aLabels.begin();
     126                 :          0 :         StringArray::const_iterator aValueIter = _rSettings.aValues.begin();
     127                 :          0 :         for (sal_Int32 i=0; i<nRadioButtons; ++i, ++aLabelIter, ++aValueIter)
     128                 :            :         {
     129                 :          0 :             aButtonPosition.Y = aShapePosition.Y + (i+1) * nTempHeight + nTopSpace;
     130                 :            : 
     131                 :            :             Reference< XPropertySet > xRadioModel(
     132                 :          0 :                     xDocFactory->createInstance(::rtl::OUString("com.sun.star.form.component.RadioButton")),
     133                 :          0 :                 UNO_QUERY);
     134                 :            : 
     135                 :            :             // the label
     136                 :          0 :             xRadioModel->setPropertyValue(::rtl::OUString("Label"), makeAny(rtl::OUString(*aLabelIter)));
     137                 :            :             // the value
     138                 :          0 :             xRadioModel->setPropertyValue(::rtl::OUString("RefValue"), makeAny(rtl::OUString(*aValueIter)));
     139                 :            : 
     140                 :            :             // default selection
     141                 :          0 :             if (_rSettings.sDefaultField == *aLabelIter)
     142                 :          0 :                 xRadioModel->setPropertyValue(::rtl::OUString("DefaultState"), makeAny(sal_Int16(1)));
     143                 :            : 
     144                 :            :             // the connection to the database field
     145                 :          0 :             if (0 != _rSettings.sDBField.Len())
     146                 :          0 :                 xRadioModel->setPropertyValue(::rtl::OUString("DataField"), makeAny(::rtl::OUString(_rSettings.sDBField)));
     147                 :            : 
     148                 :            :             // the name for the model
     149                 :          0 :             xRadioModel->setPropertyValue(::rtl::OUString("Name"), makeAny(sElementsName));
     150                 :            : 
     151                 :            :             // create a shape for the radio button
     152                 :            :             Reference< XControlShape > xRadioShape(
     153                 :          0 :                     xDocFactory->createInstance(::rtl::OUString("com.sun.star.drawing.ControlShape")),
     154                 :          0 :                 UNO_QUERY);
     155                 :          0 :             Reference< XPropertySet > xShapeProperties(xRadioShape, UNO_QUERY);
     156                 :            : 
     157                 :            :             // if we're working on a writer document, we need to anchor the shape
     158                 :          0 :             implAnchorShape(xShapeProperties);
     159                 :            : 
     160                 :            :             // position it
     161                 :          0 :             xRadioShape->setSize(aButtonSize);
     162                 :          0 :             xRadioShape->setPosition(aButtonPosition);
     163                 :            :             // knitting with the model
     164                 :          0 :             xRadioShape->setControl(Reference< XControlModel >(xRadioModel, UNO_QUERY));
     165                 :            : 
     166                 :            :             // the name of the shape
     167                 :          0 :             if (xShapeProperties.is())
     168                 :          0 :                 xShapeProperties->setPropertyValue(::rtl::OUString("Name"), makeAny(sElementsName));
     169                 :            : 
     170                 :            :             // add to the page
     171                 :          0 :             xPageShapes->add(xRadioShape.get());
     172                 :            :             // add to the collection (for the later grouping)
     173                 :          0 :             xButtonCollection->add(xRadioShape.get());
     174                 :            : 
     175                 :            :             // set the GroupBox as "LabelControl" for the RadioButton
     176                 :            :             // (_after_ having inserted the model into the page!)
     177                 :          0 :             xRadioModel->setPropertyValue(::rtl::OUString("LabelControl"), makeAny(_rContext.xObjectModel));
     178                 :          0 :         }
     179                 :            : 
     180                 :            :         // group the shapes
     181                 :            :         try
     182                 :            :         {
     183                 :          0 :             Reference< XShapeGrouper > xGrouper(_rContext.xDrawPage, UNO_QUERY);
     184                 :          0 :             if (xGrouper.is())
     185                 :            :             {
     186                 :          0 :                 Reference< XShapeGroup > xGroupedOptions = xGrouper->group(xButtonCollection);
     187                 :          0 :                 Reference< XSelectionSupplier > xSelector(_rContext.xDocumentModel->getCurrentController(), UNO_QUERY);
     188                 :          0 :                 if (xSelector.is())
     189                 :          0 :                     xSelector->select(makeAny(xGroupedOptions));
     190                 :          0 :             }
     191                 :            :         }
     192                 :          0 :         catch(Exception&)
     193                 :            :         {
     194                 :            :             OSL_FAIL("OOptionGroupLayouter::doLayout: caught an exception while grouping the shapes!");
     195                 :          0 :         }
     196                 :            :     }
     197                 :            : 
     198                 :            :     //---------------------------------------------------------------------
     199                 :          0 :     void OOptionGroupLayouter::implAnchorShape(const Reference< XPropertySet >& _rxShapeProps)
     200                 :            :     {
     201                 :          0 :         static const ::rtl::OUString s_sAnchorPropertyName("AnchorType");
     202                 :          0 :         Reference< XPropertySetInfo > xPropertyInfo;
     203                 :          0 :         if (_rxShapeProps.is())
     204                 :          0 :             xPropertyInfo = _rxShapeProps->getPropertySetInfo();
     205                 :          0 :         if (xPropertyInfo.is() && xPropertyInfo->hasPropertyByName(s_sAnchorPropertyName))
     206                 :          0 :             _rxShapeProps->setPropertyValue(s_sAnchorPropertyName, makeAny(TextContentAnchorType_AT_PAGE));
     207                 :          0 :     }
     208                 :            : 
     209                 :            : //.........................................................................
     210                 :            : }   // namespace dbp
     211                 :            : //.........................................................................
     212                 :            : 
     213                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10