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