Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "showcols.hxx"
21 : #include "fmsearch.hrc"
22 :
23 : #include <dialmgr.hxx>
24 : #include <vcl/msgbox.hxx>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 : #include <comphelper/types.hxx>
27 :
28 : #define CUIFM_PROP_HIDDEN "Hidden"
29 : #define CUIFM_PROP_LABEL "Label"
30 :
31 0 : FmShowColsDialog::FmShowColsDialog(vcl::Window* pParent)
32 0 : : ModalDialog(pParent, "ShowColDialog", "cui/ui/showcoldialog.ui")
33 : {
34 0 : get(m_pOK, "ok");
35 0 : get(m_pList, "treeview");
36 0 : m_pList->set_height_request(m_pList->GetTextHeight() * 8);
37 0 : m_pList->set_width_request(m_pList->approximate_char_width() * 56);
38 0 : m_pList->EnableMultiSelection(true);
39 0 : m_pOK->SetClickHdl( LINK( this, FmShowColsDialog, OnClickedOk ) );
40 0 : }
41 :
42 :
43 0 : IMPL_LINK_NOARG(FmShowColsDialog, OnClickedOk)
44 : {
45 : DBG_ASSERT(m_xColumns.is(), "FmShowColsDialog::OnClickedOk : you should call SetColumns before executing the dialog !");
46 0 : if (m_xColumns.is())
47 : {
48 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xCol;
49 0 : for (sal_uInt16 i=0; i < m_pList->GetSelectEntryCount(); ++i)
50 : {
51 0 : m_xColumns->getByIndex(sal::static_int_cast<sal_Int32>(reinterpret_cast<sal_uIntPtr>(m_pList->GetEntryData(m_pList->GetSelectEntryPos(i))))) >>= xCol;
52 0 : if (xCol.is())
53 : {
54 : try
55 : {
56 0 : xCol->setPropertyValue(CUIFM_PROP_HIDDEN, css::uno::Any(false));
57 : }
58 0 : catch(...)
59 : {
60 : OSL_FAIL("FmShowColsDialog::OnClickedOk Exception occurred!");
61 : }
62 : }
63 0 : }
64 : }
65 :
66 0 : EndDialog(RET_OK);
67 0 : return 0L;
68 : }
69 :
70 :
71 0 : void FmShowColsDialog::SetColumns(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer>& xCols)
72 : {
73 : DBG_ASSERT(xCols.is(), "FmShowColsDialog::SetColumns : invalid columns !");
74 0 : if (!xCols.is())
75 0 : return;
76 0 : m_xColumns = xCols.get();
77 :
78 0 : m_pList->Clear();
79 :
80 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xCurCol;
81 0 : OUString sCurName;
82 0 : for (sal_uInt16 i=0; i<xCols->getCount(); ++i)
83 : {
84 0 : sCurName = "";
85 0 : xCurCol.set(xCols->getByIndex(i), css::uno::UNO_QUERY);
86 0 : bool bIsHidden = false;
87 : try
88 : {
89 0 : ::com::sun::star::uno::Any aHidden = xCurCol->getPropertyValue(CUIFM_PROP_HIDDEN);
90 0 : bIsHidden = ::comphelper::getBOOL(aHidden);
91 :
92 0 : OUString sName;
93 0 : xCurCol->getPropertyValue(CUIFM_PROP_LABEL) >>= sName;
94 0 : sCurName = sName;
95 : }
96 0 : catch(...)
97 : {
98 : OSL_FAIL("FmShowColsDialog::SetColumns Exception occurred!");
99 : }
100 :
101 : // if the col is hidden, put it into the list
102 0 : if (bIsHidden)
103 0 : m_pList->SetEntryData( m_pList->InsertEntry(sCurName), reinterpret_cast<void*>((sal_Int64)i) );
104 0 : }
105 0 : }
106 :
107 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|