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