LibreOffice Module cui (master) 1
showcols.cxx
Go to the documentation of this file.
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
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <comphelper/types.hxx>
24#include <tools/debug.hxx>
26
27constexpr OUStringLiteral CUIFM_PROP_HIDDEN = u"Hidden";
28constexpr OUStringLiteral CUIFM_PROP_LABEL = u"Label";
29
31 : GenericDialogController(pParent, "cui/ui/showcoldialog.ui", "ShowColDialog")
32 , m_xList(m_xBuilder->weld_tree_view("treeview"))
33 , m_xOK(m_xBuilder->weld_button("ok"))
34{
35 m_xList->set_size_request(m_xList->get_approximate_digit_width() * 40,
36 m_xList->get_height_rows(8));
37 m_xList->set_selection_mode(SelectionMode::Multiple);
38 m_xOK->connect_clicked(LINK(this, FmShowColsDialog, OnClickedOk));
39}
40
42
44{
46 m_xColumns.is(),
47 "FmShowColsDialog::OnClickedOk : you should call SetColumns before executing the dialog !");
48 if (m_xColumns.is())
49 {
50 css::uno::Reference<css::beans::XPropertySet> xCol;
51 auto nSelectedRows = m_xList->get_selected_rows();
52 for (auto i : nSelectedRows)
53 {
54 m_xColumns->getByIndex(m_xList->get_id(i).toInt32()) >>= xCol;
55 if (xCol.is())
56 {
57 try
58 {
59 xCol->setPropertyValue(CUIFM_PROP_HIDDEN, css::uno::Any(false));
60 }
61 catch (...)
62 {
63 TOOLS_WARN_EXCEPTION("cui.dialogs",
64 "FmShowColsDialog::OnClickedOk Exception occurred!");
65 }
66 }
67 }
68 }
69
70 m_xDialog->response(RET_OK);
71}
72
73void FmShowColsDialog::SetColumns(const css::uno::Reference<css::container::XIndexContainer>& xCols)
74{
75 DBG_ASSERT(xCols.is(), "FmShowColsDialog::SetColumns : invalid columns !");
76 if (!xCols.is())
77 return;
78 m_xColumns = xCols.get();
79
80 m_xList->clear();
81
82 css::uno::Reference<css::beans::XPropertySet> xCurCol;
83 OUString sCurName;
84 for (sal_Int32 i = 0; i < xCols->getCount(); ++i)
85 {
86 sCurName.clear();
87 xCurCol.set(xCols->getByIndex(i), css::uno::UNO_QUERY);
88 bool bIsHidden = false;
89 try
90 {
91 css::uno::Any aHidden = xCurCol->getPropertyValue(CUIFM_PROP_HIDDEN);
92 bIsHidden = ::comphelper::getBOOL(aHidden);
93
94 OUString sName;
95 xCurCol->getPropertyValue(CUIFM_PROP_LABEL) >>= sName;
96 sCurName = sName;
97 }
98 catch (...)
99 {
100 TOOLS_WARN_EXCEPTION("cui.dialogs", "FmShowColsDialog::SetColumns Exception occurred!");
101 }
102
103 // if the col is hidden, put it into the list
104 if (bIsHidden)
105 m_xList->append(OUString::number(i), sCurName);
106 }
107}
108
109/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
void SetColumns(const css::uno::Reference< css::container::XIndexContainer > &xCols)
Definition: showcols.cxx:73
virtual ~FmShowColsDialog() override
Definition: showcols.cxx:41
std::unique_ptr< weld::Button > m_xOK
Definition: showcols.hxx:31
std::unique_ptr< weld::TreeView > m_xList
Definition: showcols.hxx:30
FmShowColsDialog(weld::Window *pParent)
Definition: showcols.cxx:30
css::uno::Reference< css::container::XIndexAccess > m_xColumns
Definition: showcols.hxx:33
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
float u
OUString sName
int i
constexpr OUStringLiteral CUIFM_PROP_HIDDEN
Definition: showcols.cxx:27
IMPL_LINK_NOARG(FmShowColsDialog, OnClickedOk, weld::Button &, void)
Definition: showcols.cxx:43
constexpr OUStringLiteral CUIFM_PROP_LABEL
Definition: showcols.cxx:28
RET_OK