xref: /trunk/main/cui/source/dialogs/showcols.cxx (revision 2ee96f1c)
1*2ee96f1cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2ee96f1cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2ee96f1cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2ee96f1cSAndrew Rist  * distributed with this work for additional information
6*2ee96f1cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2ee96f1cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2ee96f1cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2ee96f1cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2ee96f1cSAndrew Rist  *
11*2ee96f1cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2ee96f1cSAndrew Rist  *
13*2ee96f1cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2ee96f1cSAndrew Rist  * software distributed under the License is distributed on an
15*2ee96f1cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2ee96f1cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2ee96f1cSAndrew Rist  * specific language governing permissions and limitations
18*2ee96f1cSAndrew Rist  * under the License.
19*2ee96f1cSAndrew Rist  *
20*2ee96f1cSAndrew Rist  *************************************************************/
21*2ee96f1cSAndrew Rist 
22*2ee96f1cSAndrew 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 //==========================================================================
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 //--------------------------------------------------------------------------
60cdf0e10cSrcweir FmShowColsDialog::~FmShowColsDialog()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	DBG_DTOR(FmShowColsDialog,NULL);
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //--------------------------------------------------------------------------
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 				{
85cdf0e10cSrcweir 					DBG_ERROR("FmShowColsDialog::OnClickedOk Exception occured!");
86cdf0e10cSrcweir 				}
87cdf0e10cSrcweir 			}
88cdf0e10cSrcweir 		}
89cdf0e10cSrcweir 	}
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	EndDialog(RET_OK);
92cdf0e10cSrcweir 	return 0L;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //--------------------------------------------------------------------------
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;
122cdf0e10cSrcweir 			sCurName = (const sal_Unicode*)sName;
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 		catch(...)
125cdf0e10cSrcweir 		{
126cdf0e10cSrcweir 			DBG_ERROR("FmShowColsDialog::SetColumns Exception occured!");
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