1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_extensions.hxx" 30*cdf0e10cSrcweir #include "selectlabeldialog.hxx" 31*cdf0e10cSrcweir #ifndef _EXTENSIONS_PROPCTRLR_FORMRESID_HRC_ 32*cdf0e10cSrcweir #include "formresid.hrc" 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #include "formbrowsertools.hxx" 35*cdf0e10cSrcweir #include "formstrings.hxx" 36*cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 42*cdf0e10cSrcweir #include <comphelper/property.hxx> 43*cdf0e10cSrcweir #include <comphelper/types.hxx> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir //............................................................................ 46*cdf0e10cSrcweir namespace pcr 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir //............................................................................ 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 51*cdf0e10cSrcweir using namespace ::com::sun::star::container; 52*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 53*cdf0e10cSrcweir using namespace ::com::sun::star::form; 54*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 55*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir //======================================================================== 58*cdf0e10cSrcweir // OSelectLabelDialog 59*cdf0e10cSrcweir //======================================================================== 60*cdf0e10cSrcweir DBG_NAME(OSelectLabelDialog) 61*cdf0e10cSrcweir //------------------------------------------------------------------------ 62*cdf0e10cSrcweir OSelectLabelDialog::OSelectLabelDialog( Window* pParent, Reference< XPropertySet > _xControlModel ) 63*cdf0e10cSrcweir :ModalDialog(pParent, PcrRes(RID_DLG_SELECTLABELCONTROL)) 64*cdf0e10cSrcweir ,m_aMainDesc(this, PcrRes(1)) 65*cdf0e10cSrcweir ,m_aControlTree(this, PcrRes(1)) 66*cdf0e10cSrcweir ,m_aNoAssignment(this, PcrRes(1)) 67*cdf0e10cSrcweir ,m_aSeparator(this, PcrRes(1)) 68*cdf0e10cSrcweir ,m_aOk(this, PcrRes(1)) 69*cdf0e10cSrcweir ,m_aCancel(this, PcrRes(1)) 70*cdf0e10cSrcweir ,m_aModelImages(PcrRes(RID_IL_FORMEXPLORER)) 71*cdf0e10cSrcweir ,m_xControlModel(_xControlModel) 72*cdf0e10cSrcweir ,m_pInitialSelection(NULL) 73*cdf0e10cSrcweir ,m_pLastSelected(NULL) 74*cdf0e10cSrcweir ,m_bHaveAssignableControl(sal_False) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir DBG_CTOR(OSelectLabelDialog,NULL); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // initialize the TreeListBox 79*cdf0e10cSrcweir m_aControlTree.SetSelectionMode( SINGLE_SELECTION ); 80*cdf0e10cSrcweir m_aControlTree.SetDragDropMode( 0 ); 81*cdf0e10cSrcweir m_aControlTree.EnableInplaceEditing( sal_False ); 82*cdf0e10cSrcweir m_aControlTree.SetStyle(m_aControlTree.GetStyle() | WB_BORDER | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HSCROLL); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir m_aControlTree.SetNodeBitmaps( m_aModelImages.GetImage( RID_SVXIMG_COLLAPSEDNODE ), m_aModelImages.GetImage( RID_SVXIMG_EXPANDEDNODE ) ); 85*cdf0e10cSrcweir m_aControlTree.SetSelectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected)); 86*cdf0e10cSrcweir m_aControlTree.SetDeselectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected)); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // fill the description 89*cdf0e10cSrcweir UniString sDescription = m_aMainDesc.GetText(); 90*cdf0e10cSrcweir sal_Int16 nClassID = FormComponentType::CONTROL; 91*cdf0e10cSrcweir if (::comphelper::hasProperty(PROPERTY_CLASSID, m_xControlModel)) 92*cdf0e10cSrcweir nClassID = ::comphelper::getINT16(m_xControlModel->getPropertyValue(PROPERTY_CLASSID)); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir sDescription.SearchAndReplace(String::CreateFromAscii("$control_class$"), GetUIHeadlineName(nClassID, makeAny(m_xControlModel))); 95*cdf0e10cSrcweir UniString sName = ::comphelper::getString(m_xControlModel->getPropertyValue(PROPERTY_NAME)).getStr(); 96*cdf0e10cSrcweir sDescription.SearchAndReplace(String::CreateFromAscii("$control_name$"), sName); 97*cdf0e10cSrcweir m_aMainDesc.SetText(sDescription); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir // search for the root of the form hierarchy 100*cdf0e10cSrcweir Reference< XChild > xCont(m_xControlModel, UNO_QUERY); 101*cdf0e10cSrcweir Reference< XInterface > xSearch( xCont.is() ? xCont->getParent() : Reference< XInterface > ()); 102*cdf0e10cSrcweir Reference< XResultSet > xParentAsResultSet(xSearch, UNO_QUERY); 103*cdf0e10cSrcweir while (xParentAsResultSet.is()) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir xCont = Reference< XChild > (xSearch, UNO_QUERY); 106*cdf0e10cSrcweir xSearch = xCont.is() ? xCont->getParent() : Reference< XInterface > (); 107*cdf0e10cSrcweir xParentAsResultSet = Reference< XResultSet > (xSearch, UNO_QUERY); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir // and insert all entries below this root into the listbox 111*cdf0e10cSrcweir if (xSearch.is()) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir // check wich service the allowed components must suppport 114*cdf0e10cSrcweir sal_Int16 nClassId = 0; 115*cdf0e10cSrcweir try { nClassId = ::comphelper::getINT16(m_xControlModel->getPropertyValue(PROPERTY_CLASSID)); } catch(...) { } 116*cdf0e10cSrcweir m_sRequiredService = (FormComponentType::RADIOBUTTON == nClassId) ? SERVICE_COMPONENT_GROUPBOX : SERVICE_COMPONENT_FIXEDTEXT; 117*cdf0e10cSrcweir m_aRequiredControlImage = m_aModelImages.GetImage((FormComponentType::RADIOBUTTON == nClassId) ? RID_SVXIMG_GROUPBOX : RID_SVXIMG_FIXEDTEXT); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir // calc the currently set label control (so InsertEntries can calc m_pInitialSelection) 120*cdf0e10cSrcweir Any aCurrentLabelControl( m_xControlModel->getPropertyValue(PROPERTY_CONTROLLABEL) ); 121*cdf0e10cSrcweir DBG_ASSERT((aCurrentLabelControl.getValueTypeClass() == TypeClass_INTERFACE) || !aCurrentLabelControl.hasValue(), 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir "OSelectLabelDialog::OSelectLabelDialog : invalid ControlLabel property !"); 124*cdf0e10cSrcweir if (aCurrentLabelControl.hasValue()) 125*cdf0e10cSrcweir aCurrentLabelControl >>= m_xInitialLabelControl; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // insert the root 128*cdf0e10cSrcweir Image aRootImage = m_aModelImages.GetImage(RID_SVXIMG_FORMS); 129*cdf0e10cSrcweir SvLBoxEntry* pRoot = m_aControlTree.InsertEntry(PcrRes(RID_STR_FORMS), aRootImage, aRootImage); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // build the tree 132*cdf0e10cSrcweir m_pInitialSelection = NULL; 133*cdf0e10cSrcweir m_bHaveAssignableControl = sal_False; 134*cdf0e10cSrcweir InsertEntries(xSearch, pRoot); 135*cdf0e10cSrcweir m_aControlTree.Expand(pRoot); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir if (m_pInitialSelection) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir m_aControlTree.MakeVisible(m_pInitialSelection, sal_True); 141*cdf0e10cSrcweir m_aControlTree.Select(m_pInitialSelection, sal_True); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir else 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir m_aControlTree.MakeVisible(m_aControlTree.First(), sal_True); 146*cdf0e10cSrcweir if (m_aControlTree.FirstSelected()) 147*cdf0e10cSrcweir m_aControlTree.Select(m_aControlTree.FirstSelected(), sal_False); 148*cdf0e10cSrcweir m_aNoAssignment.Check(sal_True); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir if (!m_bHaveAssignableControl) 152*cdf0e10cSrcweir { // no controls which can be assigned 153*cdf0e10cSrcweir m_aNoAssignment.Check(sal_True); 154*cdf0e10cSrcweir m_aNoAssignment.Enable(sal_False); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir m_aNoAssignment.SetClickHdl(LINK(this, OSelectLabelDialog, OnNoAssignmentClicked)); 158*cdf0e10cSrcweir m_aNoAssignment.GetClickHdl().Call(&m_aNoAssignment); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir FreeResource(); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir //------------------------------------------------------------------------ 164*cdf0e10cSrcweir OSelectLabelDialog::~OSelectLabelDialog() 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir // delete the entry datas of the listbox entries 167*cdf0e10cSrcweir SvLBoxEntry* pLoop = m_aControlTree.First(); 168*cdf0e10cSrcweir while (pLoop) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir void* pData = pLoop->GetUserData(); 171*cdf0e10cSrcweir if (pData) 172*cdf0e10cSrcweir delete (Reference< XPropertySet > *)pData; 173*cdf0e10cSrcweir pLoop = m_aControlTree.Next(pLoop); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir DBG_DTOR(OSelectLabelDialog,NULL); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir //------------------------------------------------------------------------ 180*cdf0e10cSrcweir sal_Int32 OSelectLabelDialog::InsertEntries(const Reference< XInterface > & _xContainer, SvLBoxEntry* pContainerEntry) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir Reference< XIndexAccess > xContainer(_xContainer, UNO_QUERY); 183*cdf0e10cSrcweir if (!xContainer.is()) 184*cdf0e10cSrcweir return 0; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir sal_Int32 nChildren = 0; 187*cdf0e10cSrcweir UniString sName,sDisplayName; 188*cdf0e10cSrcweir Reference< XPropertySet > xAsSet; 189*cdf0e10cSrcweir for (sal_Int32 i=0; i<xContainer->getCount(); ++i) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir xContainer->getByIndex(i) >>= xAsSet; 192*cdf0e10cSrcweir if (!xAsSet.is()) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir DBG_WARNING("OSelectLabelDialog::InsertEntries : strange : a form component which isn't a property set !"); 195*cdf0e10cSrcweir continue; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir if (!::comphelper::hasProperty(PROPERTY_NAME, xAsSet)) 199*cdf0e10cSrcweir // we need at least a name for displaying ... 200*cdf0e10cSrcweir continue; 201*cdf0e10cSrcweir sName = ::comphelper::getString(xAsSet->getPropertyValue(PROPERTY_NAME)).getStr(); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir // we need to check if the control model supports the required service 204*cdf0e10cSrcweir Reference< XServiceInfo > xInfo(xAsSet, UNO_QUERY); 205*cdf0e10cSrcweir if (!xInfo.is()) 206*cdf0e10cSrcweir continue; 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir if (!xInfo->supportsService(m_sRequiredService)) 209*cdf0e10cSrcweir { // perhaps it is a container 210*cdf0e10cSrcweir Reference< XIndexAccess > xCont(xAsSet, UNO_QUERY); 211*cdf0e10cSrcweir if (xCont.is() && xCont->getCount()) 212*cdf0e10cSrcweir { // yes -> step down 213*cdf0e10cSrcweir Image aFormImage = m_aModelImages.GetImage( RID_SVXIMG_FORM ); 214*cdf0e10cSrcweir SvLBoxEntry* pCont = m_aControlTree.InsertEntry(sName, aFormImage, aFormImage, pContainerEntry); 215*cdf0e10cSrcweir sal_Int32 nContChildren = InsertEntries(xCont, pCont); 216*cdf0e10cSrcweir if (nContChildren) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir m_aControlTree.Expand(pCont); 219*cdf0e10cSrcweir ++nChildren; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir else 222*cdf0e10cSrcweir { // oops, no valid childs -> remove the entry 223*cdf0e10cSrcweir m_aControlTree.ModelIsRemoving(pCont); 224*cdf0e10cSrcweir m_aControlTree.GetModel()->Remove(pCont); 225*cdf0e10cSrcweir m_aControlTree.ModelHasRemoved(pCont); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir continue; 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir // get the label 232*cdf0e10cSrcweir if (!::comphelper::hasProperty(PROPERTY_LABEL, xAsSet)) 233*cdf0e10cSrcweir continue; 234*cdf0e10cSrcweir sDisplayName = ::comphelper::getString(xAsSet->getPropertyValue(PROPERTY_LABEL)).getStr(); 235*cdf0e10cSrcweir sDisplayName += String::CreateFromAscii(" ("); 236*cdf0e10cSrcweir sDisplayName += sName; 237*cdf0e10cSrcweir sDisplayName += ')'; 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir // all requirements met -> insert 240*cdf0e10cSrcweir SvLBoxEntry* pCurrent = m_aControlTree.InsertEntry(sDisplayName, m_aRequiredControlImage, m_aRequiredControlImage, pContainerEntry); 241*cdf0e10cSrcweir pCurrent->SetUserData(new Reference< XPropertySet > (xAsSet)); 242*cdf0e10cSrcweir ++nChildren; 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir if (m_xInitialLabelControl == xAsSet) 245*cdf0e10cSrcweir m_pInitialSelection = pCurrent; 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir m_bHaveAssignableControl = sal_True; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir return nChildren; 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir //------------------------------------------------------------------------ 254*cdf0e10cSrcweir IMPL_LINK(OSelectLabelDialog, OnEntrySelected, SvTreeListBox*, pLB) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir DBG_ASSERT(pLB == &m_aControlTree, "OSelectLabelDialog::OnEntrySelected : where did this come from ?"); 257*cdf0e10cSrcweir (void)pLB; 258*cdf0e10cSrcweir SvLBoxEntry* pSelected = m_aControlTree.FirstSelected(); 259*cdf0e10cSrcweir void* pData = pSelected ? pSelected->GetUserData() : NULL; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir if (pData) 262*cdf0e10cSrcweir m_xSelectedControl = Reference< XPropertySet > (*(Reference< XPropertySet > *)pData); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir m_aNoAssignment.SetClickHdl(Link()); 265*cdf0e10cSrcweir m_aNoAssignment.Check(pData == NULL); 266*cdf0e10cSrcweir m_aNoAssignment.SetClickHdl(LINK(this, OSelectLabelDialog, OnNoAssignmentClicked)); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir return 0L; 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir //------------------------------------------------------------------------ 272*cdf0e10cSrcweir IMPL_LINK(OSelectLabelDialog, OnNoAssignmentClicked, Button*, pButton) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir DBG_ASSERT(pButton == &m_aNoAssignment, "OSelectLabelDialog::OnNoAssignmentClicked : where did this come from ?"); 275*cdf0e10cSrcweir (void)pButton; 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir if (m_aNoAssignment.IsChecked()) 278*cdf0e10cSrcweir m_pLastSelected = m_aControlTree.FirstSelected(); 279*cdf0e10cSrcweir else 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir DBG_ASSERT(m_bHaveAssignableControl, "OSelectLabelDialog::OnNoAssignmentClicked"); 282*cdf0e10cSrcweir // search the first assignable entry 283*cdf0e10cSrcweir SvLBoxEntry* pSearch = m_aControlTree.First(); 284*cdf0e10cSrcweir while (pSearch) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir if (pSearch->GetUserData()) 287*cdf0e10cSrcweir break; 288*cdf0e10cSrcweir pSearch = m_aControlTree.Next(pSearch); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir // and select it 291*cdf0e10cSrcweir if (pSearch) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir m_aControlTree.Select(pSearch); 294*cdf0e10cSrcweir m_pLastSelected = pSearch; 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir if (m_pLastSelected) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir m_aControlTree.SetSelectHdl(Link()); 301*cdf0e10cSrcweir m_aControlTree.SetDeselectHdl(Link()); 302*cdf0e10cSrcweir m_aControlTree.Select(m_pLastSelected, !m_aNoAssignment.IsChecked()); 303*cdf0e10cSrcweir m_aControlTree.SetSelectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected)); 304*cdf0e10cSrcweir m_aControlTree.SetDeselectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected)); 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir return 0L; 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir //............................................................................ 311*cdf0e10cSrcweir } // namespace pcr 312*cdf0e10cSrcweir //............................................................................ 313*cdf0e10cSrcweir 314