bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / dialogs / showcols.cxx
blob4c86ac4da191caaf72ed87c84aa3eeb0be63ea14
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "showcols.hxx"
21 #include "fmsearch.hrc"
23 #include <dialmgr.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <comphelper/types.hxx>
28 #define CUIFM_PROP_HIDDEN "Hidden"
29 #define CUIFM_PROP_LABEL "Label"
31 FmShowColsDialog::FmShowColsDialog(vcl::Window* pParent)
32 : ModalDialog(pParent, "ShowColDialog", "cui/ui/showcoldialog.ui")
34 get(m_pOK, "ok");
35 get(m_pList, "treeview");
36 m_pList->set_height_request(m_pList->GetTextHeight() * 8);
37 m_pList->set_width_request(m_pList->approximate_char_width() * 56);
38 m_pList->EnableMultiSelection(true);
39 m_pOK->SetClickHdl( LINK( this, FmShowColsDialog, OnClickedOk ) );
42 FmShowColsDialog::~FmShowColsDialog()
44 disposeOnce();
47 void FmShowColsDialog::dispose()
49 m_pList.clear();
50 m_pOK.clear();
51 ModalDialog::dispose();
54 IMPL_LINK_NOARG(FmShowColsDialog, OnClickedOk)
56 DBG_ASSERT(m_xColumns.is(), "FmShowColsDialog::OnClickedOk : you should call SetColumns before executing the dialog !");
57 if (m_xColumns.is())
59 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xCol;
60 for (sal_uInt16 i=0; i < m_pList->GetSelectEntryCount(); ++i)
62 m_xColumns->getByIndex(sal::static_int_cast<sal_Int32>(reinterpret_cast<sal_uIntPtr>(m_pList->GetEntryData(m_pList->GetSelectEntryPos(i))))) >>= xCol;
63 if (xCol.is())
65 try
67 xCol->setPropertyValue(CUIFM_PROP_HIDDEN, css::uno::Any(false));
69 catch(...)
71 OSL_FAIL("FmShowColsDialog::OnClickedOk Exception occurred!");
77 EndDialog(RET_OK);
78 return 0L;
82 void FmShowColsDialog::SetColumns(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer>& xCols)
84 DBG_ASSERT(xCols.is(), "FmShowColsDialog::SetColumns : invalid columns !");
85 if (!xCols.is())
86 return;
87 m_xColumns = xCols.get();
89 m_pList->Clear();
91 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xCurCol;
92 OUString sCurName;
93 for (sal_uInt16 i=0; i<xCols->getCount(); ++i)
95 sCurName.clear();
96 xCurCol.set(xCols->getByIndex(i), css::uno::UNO_QUERY);
97 bool bIsHidden = false;
98 try
100 ::com::sun::star::uno::Any aHidden = xCurCol->getPropertyValue(CUIFM_PROP_HIDDEN);
101 bIsHidden = ::comphelper::getBOOL(aHidden);
103 OUString sName;
104 xCurCol->getPropertyValue(CUIFM_PROP_LABEL) >>= sName;
105 sCurName = sName;
107 catch(...)
109 OSL_FAIL("FmShowColsDialog::SetColumns Exception occurred!");
112 // if the col is hidden, put it into the list
113 if (bIsHidden)
114 m_pList->SetEntryData( m_pList->InsertEntry(sCurName), reinterpret_cast<void*>((sal_Int64)i) );
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */