xref: /trunk/main/cui/source/dialogs/showcols.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
31 #include "showcols.hxx"
32 #include "fmsearch.hrc"
33 
34 #include <tools/shl.hxx>
35 #include <dialmgr.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <comphelper/extract.hxx>
39 #include <comphelper/types.hxx>
40 
41 #define CUIFM_PROP_HIDDEN rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Hidden" ) )
42 #define CUIFM_PROP_LABEL  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Label" ) )
43 
44 //==========================================================================
45 //	FmShowColsDialog
46 //==========================================================================
47 DBG_NAME(FmShowColsDialog)
48 //--------------------------------------------------------------------------
49 FmShowColsDialog::FmShowColsDialog(Window* pParent)
50 	:ModalDialog(pParent, CUI_RES(RID_SVX_DLG_SHOWGRIDCOLUMNS))
51 	,m_aList(this, CUI_RES(1))
52 	,m_aLabel(this, CUI_RES(1))
53 	,m_aOK(this, CUI_RES(1))
54 	,m_aCancel(this, CUI_RES(1))
55 {
56 	DBG_CTOR(FmShowColsDialog,NULL);
57 	m_aList.EnableMultiSelection(sal_True);
58 	m_aOK.SetClickHdl( LINK( this, FmShowColsDialog, OnClickedOk ) );
59 
60 	FreeResource();
61 }
62 
63 //--------------------------------------------------------------------------
64 FmShowColsDialog::~FmShowColsDialog()
65 {
66 	DBG_DTOR(FmShowColsDialog,NULL);
67 }
68 
69 //--------------------------------------------------------------------------
70 IMPL_LINK( FmShowColsDialog, OnClickedOk, Button*, EMPTYARG )
71 {
72 	DBG_ASSERT(m_xColumns.is(), "FmShowColsDialog::OnClickedOk : you should call SetColumns before executing the dialog !");
73 	if (m_xColumns.is())
74 	{
75 		::com::sun::star::uno::Any aCol;
76 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xCol;
77 		for (sal_uInt16 i=0; i<m_aList.GetSelectEntryCount(); ++i)
78 		{
79 			m_xColumns->getByIndex(sal::static_int_cast<sal_Int32>(reinterpret_cast<sal_uIntPtr>(m_aList.GetEntryData(m_aList.GetSelectEntryPos(i))))) >>= xCol;
80 			if (xCol.is())
81 			{
82 				try
83 				{
84 					//CHINA001 xCol->setPropertyValue(::svxform::FM_PROP_HIDDEN, ::cppu::bool2any(sal_False));
85 					xCol->setPropertyValue(CUIFM_PROP_HIDDEN, ::cppu::bool2any(sal_False));
86 				}
87 				catch(...)
88 				{
89 					DBG_ERROR("FmShowColsDialog::OnClickedOk Exception occured!");
90 				}
91 			}
92 		}
93 	}
94 
95 	EndDialog(RET_OK);
96 	return 0L;
97 }
98 
99 //--------------------------------------------------------------------------
100 void FmShowColsDialog::SetColumns(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer>& xCols)
101 {
102 	DBG_ASSERT(xCols.is(), "FmShowColsDialog::SetColumns : invalid columns !");
103 	if (!xCols.is())
104 		return;
105 	m_xColumns = xCols.get();
106 
107 	m_aList.Clear();
108 
109 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>  xCurCol;
110 	String sCurName;
111 	for (sal_uInt16 i=0; i<xCols->getCount(); ++i)
112 	{
113 		sCurName.Erase();
114 		::cppu::extractInterface(xCurCol, xCols->getByIndex(i));
115 		sal_Bool bIsHidden = sal_False;
116 		try
117 		{
118 			//CHINA001 ::com::sun::star::uno::Any aHidden = xCurCol->getPropertyValue(::svxform::FM_PROP_HIDDEN);
119 			::com::sun::star::uno::Any aHidden = xCurCol->getPropertyValue(CUIFM_PROP_HIDDEN);
120 			bIsHidden = ::comphelper::getBOOL(aHidden);
121 
122 			::rtl::OUString sName;
123 			//CHINA001 xCurCol->getPropertyValue(::svxform::FM_PROP_LABEL) >>= sName;
124 
125 			xCurCol->getPropertyValue(CUIFM_PROP_LABEL) >>= sName;
126 			sCurName = (const sal_Unicode*)sName;
127 		}
128 		catch(...)
129 		{
130 			DBG_ERROR("FmShowColsDialog::SetColumns Exception occured!");
131 		}
132 
133 		// if the col is hidden, put it into the list
134 		if (bIsHidden)
135 			m_aList.SetEntryData( m_aList.InsertEntry(sCurName), reinterpret_cast<void*>((sal_Int64)i) );
136 	}
137 }
138 
139