xref: /trunk/main/cui/source/dialogs/showcols.cxx (revision 07a3d7f1)
12ee96f1cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32ee96f1cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42ee96f1cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52ee96f1cSAndrew Rist  * distributed with this work for additional information
62ee96f1cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72ee96f1cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82ee96f1cSAndrew Rist  * "License"); you may not use this file except in compliance
92ee96f1cSAndrew Rist  * with the License.  You may obtain a copy of the License at
102ee96f1cSAndrew Rist  *
112ee96f1cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122ee96f1cSAndrew Rist  *
132ee96f1cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142ee96f1cSAndrew Rist  * software distributed under the License is distributed on an
152ee96f1cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162ee96f1cSAndrew Rist  * KIND, either express or implied.  See the License for the
172ee96f1cSAndrew Rist  * specific language governing permissions and limitations
182ee96f1cSAndrew Rist  * under the License.
192ee96f1cSAndrew Rist  *
202ee96f1cSAndrew Rist  *************************************************************/
212ee96f1cSAndrew Rist 
222ee96f1cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "showcols.hxx"
28cdf0e10cSrcweir #include "fmsearch.hrc"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <tools/shl.hxx>
31cdf0e10cSrcweir #include <dialmgr.hxx>
32cdf0e10cSrcweir #include <vcl/msgbox.hxx>
33cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
34cdf0e10cSrcweir #include <comphelper/extract.hxx>
35cdf0e10cSrcweir #include <comphelper/types.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #define CUIFM_PROP_HIDDEN rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Hidden" ) )
38cdf0e10cSrcweir #define CUIFM_PROP_LABEL  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Label" ) )
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //==========================================================================
41cdf0e10cSrcweir //	FmShowColsDialog
42cdf0e10cSrcweir //==========================================================================
DBG_NAME(FmShowColsDialog)43cdf0e10cSrcweir DBG_NAME(FmShowColsDialog)
44cdf0e10cSrcweir //--------------------------------------------------------------------------
45cdf0e10cSrcweir FmShowColsDialog::FmShowColsDialog(Window* pParent)
46cdf0e10cSrcweir 	:ModalDialog(pParent, CUI_RES(RID_SVX_DLG_SHOWGRIDCOLUMNS))
47cdf0e10cSrcweir 	,m_aList(this, CUI_RES(1))
48cdf0e10cSrcweir 	,m_aLabel(this, CUI_RES(1))
49cdf0e10cSrcweir 	,m_aOK(this, CUI_RES(1))
50cdf0e10cSrcweir 	,m_aCancel(this, CUI_RES(1))
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	DBG_CTOR(FmShowColsDialog,NULL);
53cdf0e10cSrcweir 	m_aList.EnableMultiSelection(sal_True);
54cdf0e10cSrcweir 	m_aOK.SetClickHdl( LINK( this, FmShowColsDialog, OnClickedOk ) );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	FreeResource();
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //--------------------------------------------------------------------------
~FmShowColsDialog()60cdf0e10cSrcweir FmShowColsDialog::~FmShowColsDialog()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	DBG_DTOR(FmShowColsDialog,NULL);
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //--------------------------------------------------------------------------
IMPL_LINK(FmShowColsDialog,OnClickedOk,Button *,EMPTYARG)66cdf0e10cSrcweir IMPL_LINK( FmShowColsDialog, OnClickedOk, Button*, EMPTYARG )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	DBG_ASSERT(m_xColumns.is(), "FmShowColsDialog::OnClickedOk : you should call SetColumns before executing the dialog !");
69cdf0e10cSrcweir 	if (m_xColumns.is())
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		::com::sun::star::uno::Any aCol;
72cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xCol;
73cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<m_aList.GetSelectEntryCount(); ++i)
74cdf0e10cSrcweir 		{
75cdf0e10cSrcweir 			m_xColumns->getByIndex(sal::static_int_cast<sal_Int32>(reinterpret_cast<sal_uIntPtr>(m_aList.GetEntryData(m_aList.GetSelectEntryPos(i))))) >>= xCol;
76cdf0e10cSrcweir 			if (xCol.is())
77cdf0e10cSrcweir 			{
78cdf0e10cSrcweir 				try
79cdf0e10cSrcweir 				{
80cdf0e10cSrcweir 					//CHINA001 xCol->setPropertyValue(::svxform::FM_PROP_HIDDEN, ::cppu::bool2any(sal_False));
81cdf0e10cSrcweir 					xCol->setPropertyValue(CUIFM_PROP_HIDDEN, ::cppu::bool2any(sal_False));
82cdf0e10cSrcweir 				}
83cdf0e10cSrcweir 				catch(...)
84cdf0e10cSrcweir 				{
85*07a3d7f1SPedro Giffuni 					DBG_ERROR("FmShowColsDialog::OnClickedOk Exception occurred!");
86cdf0e10cSrcweir 				}
87cdf0e10cSrcweir 			}
88cdf0e10cSrcweir 		}
89cdf0e10cSrcweir 	}
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	EndDialog(RET_OK);
92cdf0e10cSrcweir 	return 0L;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //--------------------------------------------------------------------------
SetColumns(const::com::sun::star::uno::Reference<::com::sun::star::container::XIndexContainer> & xCols)96cdf0e10cSrcweir void FmShowColsDialog::SetColumns(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer>& xCols)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	DBG_ASSERT(xCols.is(), "FmShowColsDialog::SetColumns : invalid columns !");
99cdf0e10cSrcweir 	if (!xCols.is())
100cdf0e10cSrcweir 		return;
101cdf0e10cSrcweir 	m_xColumns = xCols.get();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	m_aList.Clear();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>  xCurCol;
106cdf0e10cSrcweir 	String sCurName;
107cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<xCols->getCount(); ++i)
108cdf0e10cSrcweir 	{
109cdf0e10cSrcweir 		sCurName.Erase();
110cdf0e10cSrcweir 		::cppu::extractInterface(xCurCol, xCols->getByIndex(i));
111cdf0e10cSrcweir 		sal_Bool bIsHidden = sal_False;
112cdf0e10cSrcweir 		try
113cdf0e10cSrcweir 		{
114cdf0e10cSrcweir 			//CHINA001 ::com::sun::star::uno::Any aHidden = xCurCol->getPropertyValue(::svxform::FM_PROP_HIDDEN);
115cdf0e10cSrcweir 			::com::sun::star::uno::Any aHidden = xCurCol->getPropertyValue(CUIFM_PROP_HIDDEN);
116cdf0e10cSrcweir 			bIsHidden = ::comphelper::getBOOL(aHidden);
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 			::rtl::OUString sName;
119cdf0e10cSrcweir 			//CHINA001 xCurCol->getPropertyValue(::svxform::FM_PROP_LABEL) >>= sName;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 			xCurCol->getPropertyValue(CUIFM_PROP_LABEL) >>= sName;
12224c56ab9SHerbert Dürr 			sCurName = sName.getStr();
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 		catch(...)
125cdf0e10cSrcweir 		{
126*07a3d7f1SPedro Giffuni 			DBG_ERROR("FmShowColsDialog::SetColumns Exception occurred!");
127cdf0e10cSrcweir 		}
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		// if the col is hidden, put it into the list
130cdf0e10cSrcweir 		if (bIsHidden)
131cdf0e10cSrcweir 			m_aList.SetEntryData( m_aList.InsertEntry(sCurName), reinterpret_cast<void*>((sal_Int64)i) );
132cdf0e10cSrcweir 	}
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135