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 <tools/shl.hxx>
24 : #include <dialmgr.hxx>
25 : #include <vcl/msgbox.hxx>
26 : #include <com/sun/star/beans/XPropertySet.hpp>
27 : #include <comphelper/types.hxx>
28 :
29 : #define CUIFM_PROP_HIDDEN "Hidden"
30 : #define CUIFM_PROP_LABEL "Label"
31 :
32 0 : FmShowColsDialog::FmShowColsDialog(Window* pParent)
33 0 : : ModalDialog(pParent, "ShowColDialog", "cui/ui/showcoldialog.ui")
34 : {
35 0 : get(m_pOK, "ok");
36 0 : get(m_pList, "treeview");
37 0 : m_pList->set_height_request(m_pList->GetTextHeight() * 8);
38 0 : m_pList->set_width_request(m_pList->approximate_char_width() * 56);
39 0 : m_pList->EnableMultiSelection(true);
40 0 : m_pOK->SetClickHdl( LINK( this, FmShowColsDialog, OnClickedOk ) );
41 0 : }
42 :
43 :
44 0 : IMPL_LINK_NOARG(FmShowColsDialog, OnClickedOk)
45 : {
46 : DBG_ASSERT(m_xColumns.is(), "FmShowColsDialog::OnClickedOk : you should call SetColumns before executing the dialog !");
47 0 : if (m_xColumns.is())
48 : {
49 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xCol;
50 0 : for (sal_uInt16 i=0; i < m_pList->GetSelectEntryCount(); ++i)
51 : {
52 0 : m_xColumns->getByIndex(sal::static_int_cast<sal_Int32>(reinterpret_cast<sal_uIntPtr>(m_pList->GetEntryData(m_pList->GetSelectEntryPos(i))))) >>= xCol;
53 0 : if (xCol.is())
54 : {
55 : try
56 : {
57 0 : xCol->setPropertyValue(CUIFM_PROP_HIDDEN, css::uno::Any(false));
58 : }
59 0 : catch(...)
60 : {
61 : OSL_FAIL("FmShowColsDialog::OnClickedOk Exception occurred!");
62 : }
63 : }
64 0 : }
65 : }
66 :
67 0 : EndDialog(RET_OK);
68 0 : return 0L;
69 : }
70 :
71 :
72 0 : void FmShowColsDialog::SetColumns(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer>& xCols)
73 : {
74 : DBG_ASSERT(xCols.is(), "FmShowColsDialog::SetColumns : invalid columns !");
75 0 : if (!xCols.is())
76 0 : return;
77 0 : m_xColumns = xCols.get();
78 :
79 0 : m_pList->Clear();
80 :
81 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xCurCol;
82 0 : OUString sCurName;
83 0 : for (sal_uInt16 i=0; i<xCols->getCount(); ++i)
84 : {
85 0 : sCurName = "";
86 0 : xCurCol.set(xCols->getByIndex(i), css::uno::UNO_QUERY);
87 0 : sal_Bool bIsHidden = sal_False;
88 : try
89 : {
90 0 : ::com::sun::star::uno::Any aHidden = xCurCol->getPropertyValue(CUIFM_PROP_HIDDEN);
91 0 : bIsHidden = ::comphelper::getBOOL(aHidden);
92 :
93 0 : OUString sName;
94 0 : xCurCol->getPropertyValue(CUIFM_PROP_LABEL) >>= sName;
95 0 : sCurName = sName;
96 : }
97 0 : catch(...)
98 : {
99 : OSL_FAIL("FmShowColsDialog::SetColumns Exception occurred!");
100 : }
101 :
102 : // if the col is hidden, put it into the list
103 0 : if (bIsHidden)
104 0 : m_pList->SetEntryData( m_pList->InsertEntry(sCurName), reinterpret_cast<void*>((sal_Int64)i) );
105 0 : }
106 : }
107 :
108 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|