1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
22 #include <osl/diagnose.h>
23 #include <vcl/msgbox.hxx>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <comphelper/types.hxx>
26 #include <tools/debug.hxx>
28 #define CUIFM_PROP_HIDDEN "Hidden"
29 #define CUIFM_PROP_LABEL "Label"
31 FmShowColsDialog::FmShowColsDialog(weld::Window
* pParent
)
32 : GenericDialogController(pParent
, "cui/ui/showcoldialog.ui", "ShowColDialog")
33 , m_xList(m_xBuilder
->weld_tree_view("treeview"))
34 , m_xOK(m_xBuilder
->weld_button("ok"))
36 m_xList
->set_size_request(m_xList
->get_approximate_digit_width() * 40, m_xList
->get_height_rows(8));
37 m_xList
->set_selection_mode(SelectionMode::Multiple
);
38 m_xOK
->connect_clicked(LINK(this, FmShowColsDialog
, OnClickedOk
));
41 FmShowColsDialog::~FmShowColsDialog()
45 IMPL_LINK_NOARG(FmShowColsDialog
, OnClickedOk
, weld::Button
&, void)
47 DBG_ASSERT(m_xColumns
.is(), "FmShowColsDialog::OnClickedOk : you should call SetColumns before executing the dialog !");
50 css::uno::Reference
< css::beans::XPropertySet
> xCol
;
51 auto nSelectedRows
= m_xList
->get_selected_rows();
52 for (auto i
: nSelectedRows
)
54 m_xColumns
->getByIndex(m_xList
->get_id(i
).toInt32()) >>= xCol
;
59 xCol
->setPropertyValue(CUIFM_PROP_HIDDEN
, css::uno::Any(false));
63 OSL_FAIL("FmShowColsDialog::OnClickedOk Exception occurred!");
69 m_xDialog
->response(RET_OK
);
72 void FmShowColsDialog::SetColumns(const css::uno::Reference
< css::container::XIndexContainer
>& xCols
)
74 DBG_ASSERT(xCols
.is(), "FmShowColsDialog::SetColumns : invalid columns !");
77 m_xColumns
= xCols
.get();
81 css::uno::Reference
< css::beans::XPropertySet
> xCurCol
;
83 for (sal_Int32 i
=0; i
<xCols
->getCount(); ++i
)
86 xCurCol
.set(xCols
->getByIndex(i
), css::uno::UNO_QUERY
);
87 bool bIsHidden
= false;
90 css::uno::Any aHidden
= xCurCol
->getPropertyValue(CUIFM_PROP_HIDDEN
);
91 bIsHidden
= ::comphelper::getBOOL(aHidden
);
94 xCurCol
->getPropertyValue(CUIFM_PROP_LABEL
) >>= sName
;
99 OSL_FAIL("FmShowColsDialog::SetColumns Exception occurred!");
102 // if the col is hidden, put it into the list
104 m_xList
->append(OUString::number(i
), sCurName
);
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */