LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - selectlabeldialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 131 0.0 %
Date: 2012-08-25 Functions: 0 8 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 "selectlabeldialog.hxx"
      30                 :            : #include "formresid.hrc"
      31                 :            : #include "formbrowsertools.hxx"
      32                 :            : #include "formstrings.hxx"
      33                 :            : #include <com/sun/star/form/FormComponentType.hpp>
      34                 :            : #include <com/sun/star/container/XChild.hpp>
      35                 :            : #include <com/sun/star/container/XIndexAccess.hpp>
      36                 :            : #include <com/sun/star/sdbc/XResultSet.hpp>
      37                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      38                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      39                 :            : #include <comphelper/property.hxx>
      40                 :            : #include <comphelper/types.hxx>
      41                 :            : 
      42                 :            : //............................................................................
      43                 :            : namespace pcr
      44                 :            : {
      45                 :            : //............................................................................
      46                 :            : 
      47                 :            :     using namespace ::com::sun::star::uno;
      48                 :            :     using namespace ::com::sun::star::container;
      49                 :            :     using namespace ::com::sun::star::beans;
      50                 :            :     using namespace ::com::sun::star::form;
      51                 :            :     using namespace ::com::sun::star::sdbc;
      52                 :            :     using namespace ::com::sun::star::lang;
      53                 :            : 
      54                 :            :     //========================================================================
      55                 :            :     // OSelectLabelDialog
      56                 :            :     //========================================================================
      57                 :            :     DBG_NAME(OSelectLabelDialog)
      58                 :            :     //------------------------------------------------------------------------
      59                 :          0 :     OSelectLabelDialog::OSelectLabelDialog( Window* pParent, Reference< XPropertySet >  _xControlModel )
      60                 :            :         :ModalDialog(pParent, PcrRes(RID_DLG_SELECTLABELCONTROL))
      61                 :            :         ,m_aMainDesc(this, PcrRes(1))
      62                 :            :         ,m_aControlTree(this, PcrRes(1))
      63                 :            :         ,m_aNoAssignment(this, PcrRes(1))
      64                 :            :         ,m_aSeparator(this, PcrRes(1))
      65                 :            :         ,m_aOk(this, PcrRes(1))
      66                 :            :         ,m_aCancel(this, PcrRes(1))
      67                 :            :         ,m_aModelImages(PcrRes(RID_IL_FORMEXPLORER))
      68                 :            :         ,m_xControlModel(_xControlModel)
      69                 :            :         ,m_pInitialSelection(NULL)
      70                 :            :         ,m_pLastSelected(NULL)
      71                 :          0 :         ,m_bHaveAssignableControl(sal_False)
      72                 :            :     {
      73                 :            :         DBG_CTOR(OSelectLabelDialog,NULL);
      74                 :            : 
      75                 :            :         // initialize the TreeListBox
      76                 :          0 :         m_aControlTree.SetSelectionMode( SINGLE_SELECTION );
      77                 :          0 :         m_aControlTree.SetDragDropMode( 0 );
      78                 :          0 :         m_aControlTree.EnableInplaceEditing( sal_False );
      79                 :          0 :         m_aControlTree.SetStyle(m_aControlTree.GetStyle() | WB_BORDER | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HSCROLL);
      80                 :            : 
      81                 :          0 :         m_aControlTree.SetNodeBitmaps( m_aModelImages.GetImage( RID_SVXIMG_COLLAPSEDNODE ), m_aModelImages.GetImage( RID_SVXIMG_EXPANDEDNODE ) );
      82                 :          0 :         m_aControlTree.SetSelectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected));
      83                 :          0 :         m_aControlTree.SetDeselectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected));
      84                 :            : 
      85                 :            :         // fill the description
      86                 :          0 :         rtl::OUString sDescription = m_aMainDesc.GetText();
      87                 :          0 :         sal_Int16 nClassID = FormComponentType::CONTROL;
      88                 :          0 :         if (::comphelper::hasProperty(PROPERTY_CLASSID, m_xControlModel))
      89                 :          0 :             nClassID = ::comphelper::getINT16(m_xControlModel->getPropertyValue(PROPERTY_CLASSID));
      90                 :            : 
      91                 :            :         sDescription = sDescription.replaceAll(rtl::OUString("$control_class$"),
      92                 :          0 :             GetUIHeadlineName(nClassID, makeAny(m_xControlModel)));
      93                 :          0 :         rtl::OUString sName = ::comphelper::getString(m_xControlModel->getPropertyValue(PROPERTY_NAME));
      94                 :          0 :         sDescription = sDescription.replaceAll(rtl::OUString("$control_name$"), sName);
      95                 :          0 :         m_aMainDesc.SetText(sDescription);
      96                 :            : 
      97                 :            :         // search for the root of the form hierarchy
      98                 :          0 :         Reference< XChild >  xCont(m_xControlModel, UNO_QUERY);
      99                 :          0 :         Reference< XInterface >  xSearch( xCont.is() ? xCont->getParent() : Reference< XInterface > ());
     100                 :          0 :         Reference< XResultSet >  xParentAsResultSet(xSearch, UNO_QUERY);
     101                 :          0 :         while (xParentAsResultSet.is())
     102                 :            :         {
     103                 :          0 :             xCont = Reference< XChild > (xSearch, UNO_QUERY);
     104                 :          0 :             xSearch = xCont.is() ? xCont->getParent() : Reference< XInterface > ();
     105                 :          0 :             xParentAsResultSet = Reference< XResultSet > (xSearch, UNO_QUERY);
     106                 :            :         }
     107                 :            : 
     108                 :            :         // and insert all entries below this root into the listbox
     109                 :          0 :         if (xSearch.is())
     110                 :            :         {
     111                 :            :             // check wich service the allowed components must suppport
     112                 :          0 :             sal_Int16 nClassId = 0;
     113                 :          0 :             try { nClassId = ::comphelper::getINT16(m_xControlModel->getPropertyValue(PROPERTY_CLASSID)); } catch(...) { }
     114                 :          0 :             m_sRequiredService = (FormComponentType::RADIOBUTTON == nClassId) ? SERVICE_COMPONENT_GROUPBOX : SERVICE_COMPONENT_FIXEDTEXT;
     115                 :          0 :             m_aRequiredControlImage = m_aModelImages.GetImage((FormComponentType::RADIOBUTTON == nClassId) ? RID_SVXIMG_GROUPBOX : RID_SVXIMG_FIXEDTEXT);
     116                 :            : 
     117                 :            :             // calc the currently set label control (so InsertEntries can calc m_pInitialSelection)
     118                 :          0 :             Any aCurrentLabelControl( m_xControlModel->getPropertyValue(PROPERTY_CONTROLLABEL) );
     119                 :            :             DBG_ASSERT((aCurrentLabelControl.getValueTypeClass() == TypeClass_INTERFACE) || !aCurrentLabelControl.hasValue(),
     120                 :            : 
     121                 :            :                 "OSelectLabelDialog::OSelectLabelDialog : invalid ControlLabel property !");
     122                 :          0 :             if (aCurrentLabelControl.hasValue())
     123                 :          0 :                 aCurrentLabelControl >>= m_xInitialLabelControl;
     124                 :            : 
     125                 :            :             // insert the root
     126                 :          0 :             Image aRootImage = m_aModelImages.GetImage(RID_SVXIMG_FORMS);
     127                 :          0 :             SvLBoxEntry* pRoot = m_aControlTree.InsertEntry(PcrRes(RID_STR_FORMS), aRootImage, aRootImage);
     128                 :            : 
     129                 :            :             // build the tree
     130                 :          0 :             m_pInitialSelection = NULL;
     131                 :          0 :             m_bHaveAssignableControl = sal_False;
     132                 :          0 :             InsertEntries(xSearch, pRoot);
     133                 :          0 :             m_aControlTree.Expand(pRoot);
     134                 :            :         }
     135                 :            : 
     136                 :          0 :         if (m_pInitialSelection)
     137                 :            :         {
     138                 :          0 :             m_aControlTree.MakeVisible(m_pInitialSelection, sal_True);
     139                 :          0 :             m_aControlTree.Select(m_pInitialSelection, sal_True);
     140                 :            :         }
     141                 :            :         else
     142                 :            :         {
     143                 :          0 :             m_aControlTree.MakeVisible(m_aControlTree.First(), sal_True);
     144                 :          0 :             if (m_aControlTree.FirstSelected())
     145                 :          0 :                 m_aControlTree.Select(m_aControlTree.FirstSelected(), sal_False);
     146                 :          0 :             m_aNoAssignment.Check(sal_True);
     147                 :            :         }
     148                 :            : 
     149                 :          0 :         if (!m_bHaveAssignableControl)
     150                 :            :         {   // no controls which can be assigned
     151                 :          0 :             m_aNoAssignment.Check(sal_True);
     152                 :          0 :             m_aNoAssignment.Enable(sal_False);
     153                 :            :         }
     154                 :            : 
     155                 :          0 :         m_aNoAssignment.SetClickHdl(LINK(this, OSelectLabelDialog, OnNoAssignmentClicked));
     156                 :          0 :         m_aNoAssignment.GetClickHdl().Call(&m_aNoAssignment);
     157                 :            : 
     158                 :          0 :         FreeResource();
     159                 :          0 :     }
     160                 :            : 
     161                 :            :     //------------------------------------------------------------------------
     162                 :          0 :     OSelectLabelDialog::~OSelectLabelDialog()
     163                 :            :     {
     164                 :            :         // delete the entry datas of the listbox entries
     165                 :          0 :         SvLBoxEntry* pLoop = m_aControlTree.First();
     166                 :          0 :         while (pLoop)
     167                 :            :         {
     168                 :          0 :             void* pData = pLoop->GetUserData();
     169                 :          0 :             if (pData)
     170                 :          0 :                 delete (Reference< XPropertySet > *)pData;
     171                 :          0 :             pLoop = m_aControlTree.Next(pLoop);
     172                 :            :         }
     173                 :            : 
     174                 :            :         DBG_DTOR(OSelectLabelDialog,NULL);
     175                 :          0 :     }
     176                 :            : 
     177                 :            :     //------------------------------------------------------------------------
     178                 :          0 :     sal_Int32 OSelectLabelDialog::InsertEntries(const Reference< XInterface > & _xContainer, SvLBoxEntry* pContainerEntry)
     179                 :            :     {
     180                 :          0 :         Reference< XIndexAccess >  xContainer(_xContainer, UNO_QUERY);
     181                 :          0 :         if (!xContainer.is())
     182                 :          0 :             return 0;
     183                 :            : 
     184                 :          0 :         sal_Int32 nChildren = 0;
     185                 :          0 :         rtl::OUString sName;
     186                 :          0 :         Reference< XPropertySet >  xAsSet;
     187                 :          0 :         for (sal_Int32 i=0; i<xContainer->getCount(); ++i)
     188                 :            :         {
     189                 :          0 :             xContainer->getByIndex(i) >>= xAsSet;
     190                 :          0 :             if (!xAsSet.is())
     191                 :            :             {
     192                 :            :                 DBG_WARNING("OSelectLabelDialog::InsertEntries : strange : a form component which isn't a property set !");
     193                 :          0 :                 continue;
     194                 :            :             }
     195                 :            : 
     196                 :          0 :             if (!::comphelper::hasProperty(PROPERTY_NAME, xAsSet))
     197                 :            :                 // we need at least a name for displaying ...
     198                 :          0 :                 continue;
     199                 :          0 :             sName = ::comphelper::getString(xAsSet->getPropertyValue(PROPERTY_NAME)).getStr();
     200                 :            : 
     201                 :            :             // we need to check if the control model supports the required service
     202                 :          0 :             Reference< XServiceInfo >  xInfo(xAsSet, UNO_QUERY);
     203                 :          0 :             if (!xInfo.is())
     204                 :          0 :                 continue;
     205                 :            : 
     206                 :          0 :             if (!xInfo->supportsService(m_sRequiredService))
     207                 :            :             {   // perhaps it is a container
     208                 :          0 :                 Reference< XIndexAccess >  xCont(xAsSet, UNO_QUERY);
     209                 :          0 :                 if (xCont.is() && xCont->getCount())
     210                 :            :                 {   // yes -> step down
     211                 :          0 :                     Image aFormImage = m_aModelImages.GetImage( RID_SVXIMG_FORM );
     212                 :          0 :                     SvLBoxEntry* pCont = m_aControlTree.InsertEntry(sName, aFormImage, aFormImage, pContainerEntry);
     213                 :          0 :                     sal_Int32 nContChildren = InsertEntries(xCont, pCont);
     214                 :          0 :                     if (nContChildren)
     215                 :            :                     {
     216                 :          0 :                         m_aControlTree.Expand(pCont);
     217                 :          0 :                         ++nChildren;
     218                 :            :                     }
     219                 :            :                     else
     220                 :            :                     {   // oops, no valid children -> remove the entry
     221                 :          0 :                         m_aControlTree.ModelIsRemoving(pCont);
     222                 :          0 :                         m_aControlTree.GetModel()->Remove(pCont);
     223                 :          0 :                         m_aControlTree.ModelHasRemoved(pCont);
     224                 :          0 :                     }
     225                 :            :                 }
     226                 :          0 :                 continue;
     227                 :            :             }
     228                 :            : 
     229                 :            :             // get the label
     230                 :          0 :             if (!::comphelper::hasProperty(PROPERTY_LABEL, xAsSet))
     231                 :          0 :                 continue;
     232                 :            : 
     233                 :            :             rtl::OUString sDisplayName = rtl::OUStringBuffer(
     234                 :          0 :                 ::comphelper::getString(xAsSet->getPropertyValue(PROPERTY_LABEL))).
     235                 :          0 :                 appendAscii(RTL_CONSTASCII_STRINGPARAM(" (")).append(sName).append(')').
     236                 :          0 :                 makeStringAndClear();
     237                 :            : 
     238                 :            :             // all requirements met -> insert
     239                 :          0 :             SvLBoxEntry* pCurrent = m_aControlTree.InsertEntry(sDisplayName, m_aRequiredControlImage, m_aRequiredControlImage, pContainerEntry);
     240                 :          0 :             pCurrent->SetUserData(new Reference< XPropertySet > (xAsSet));
     241                 :          0 :             ++nChildren;
     242                 :            : 
     243                 :          0 :             if (m_xInitialLabelControl == xAsSet)
     244                 :          0 :                 m_pInitialSelection = pCurrent;
     245                 :            : 
     246                 :          0 :             m_bHaveAssignableControl = sal_True;
     247                 :          0 :         }
     248                 :            : 
     249                 :          0 :         return nChildren;
     250                 :            :     }
     251                 :            : 
     252                 :            :     //------------------------------------------------------------------------
     253                 :          0 :     IMPL_LINK(OSelectLabelDialog, OnEntrySelected, SvTreeListBox*, pLB)
     254                 :            :     {
     255                 :            :         DBG_ASSERT(pLB == &m_aControlTree, "OSelectLabelDialog::OnEntrySelected : where did this come from ?");
     256                 :            :         (void)pLB;
     257                 :          0 :         SvLBoxEntry* pSelected = m_aControlTree.FirstSelected();
     258                 :          0 :         void* pData = pSelected ? pSelected->GetUserData() : NULL;
     259                 :            : 
     260                 :          0 :         if (pData)
     261                 :          0 :             m_xSelectedControl = Reference< XPropertySet > (*(Reference< XPropertySet > *)pData);
     262                 :            : 
     263                 :          0 :         m_aNoAssignment.SetClickHdl(Link());
     264                 :          0 :         m_aNoAssignment.Check(pData == NULL);
     265                 :          0 :         m_aNoAssignment.SetClickHdl(LINK(this, OSelectLabelDialog, OnNoAssignmentClicked));
     266                 :            : 
     267                 :          0 :         return 0L;
     268                 :            :     }
     269                 :            : 
     270                 :            :     //------------------------------------------------------------------------
     271                 :          0 :     IMPL_LINK(OSelectLabelDialog, OnNoAssignmentClicked, Button*, pButton)
     272                 :            :     {
     273                 :            :         DBG_ASSERT(pButton == &m_aNoAssignment, "OSelectLabelDialog::OnNoAssignmentClicked : where did this come from ?");
     274                 :            :         (void)pButton;
     275                 :            : 
     276                 :          0 :         if (m_aNoAssignment.IsChecked())
     277                 :          0 :             m_pLastSelected = m_aControlTree.FirstSelected();
     278                 :            :         else
     279                 :            :         {
     280                 :            :             DBG_ASSERT(m_bHaveAssignableControl, "OSelectLabelDialog::OnNoAssignmentClicked");
     281                 :            :             // search the first assignable entry
     282                 :          0 :             SvLBoxEntry* pSearch = m_aControlTree.First();
     283                 :          0 :             while (pSearch)
     284                 :            :             {
     285                 :          0 :                 if (pSearch->GetUserData())
     286                 :          0 :                     break;
     287                 :          0 :                 pSearch = m_aControlTree.Next(pSearch);
     288                 :            :             }
     289                 :            :             // and select it
     290                 :          0 :             if (pSearch)
     291                 :            :             {
     292                 :          0 :                 m_aControlTree.Select(pSearch);
     293                 :          0 :                 m_pLastSelected = pSearch;
     294                 :            :             }
     295                 :            :         }
     296                 :            : 
     297                 :          0 :         if (m_pLastSelected)
     298                 :            :         {
     299                 :          0 :             m_aControlTree.SetSelectHdl(Link());
     300                 :          0 :             m_aControlTree.SetDeselectHdl(Link());
     301                 :          0 :             m_aControlTree.Select(m_pLastSelected, !m_aNoAssignment.IsChecked());
     302                 :          0 :             m_aControlTree.SetSelectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected));
     303                 :          0 :             m_aControlTree.SetDeselectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected));
     304                 :            :         }
     305                 :            : 
     306                 :          0 :         return 0L;
     307                 :            :     }
     308                 :            : 
     309                 :            : //............................................................................
     310                 :            : }   // namespace pcr
     311                 :            : //............................................................................
     312                 :            : 
     313                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10