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