LibreOffice Module cui (master)  1
optchart.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 <unotools/pathoptions.hxx>
21 #include "optchart.hxx"
22 #include <svx/SvxColorValueSet.hxx>
23 #include <vcl/virdev.hxx>
24 #include <vcl/weld.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/svapp.hxx>
27 #include <svx/svxids.hrc>
28 #include <osl/diagnose.h>
29 #include <officecfg/Office/Common.hxx>
30 
31 void SvxDefaultColorOptPage::InsertColorEntry(const XColorEntry& rEntry, sal_Int32 nPos)
32 {
33  const Color& rColor = rEntry.GetColor();
34  const OUString& rStr = rEntry.GetName();
35 
36  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
37  Size aImageSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
38 
40  xDevice->SetOutputSize(aImageSize);
41  const ::tools::Rectangle aRect(Point(0, 0), aImageSize);
42  xDevice->SetFillColor(rColor);
43  xDevice->SetLineColor(rStyleSettings.GetDisableColor());
44  xDevice->DrawRect(aRect);
45 
46  m_xLbChartColors->insert(nullptr, nPos, &rStr, nullptr,
47  nullptr, xDevice.get(), nullptr, false, nullptr);
48 
49  if (nPos == -1)
50  aColorList.push_back( rColor );
51  else
52  {
53  ImpColorList::iterator it = aColorList.begin();
54  std::advance( it, nPos );
55  aColorList.insert( it, rColor );
56  }
57 }
58 
60 {
61  m_xLbChartColors->remove(nPos);
62  ImpColorList::iterator it = aColorList.begin();
63  std::advance(it, nPos);
64  aColorList.erase(it);
65 }
66 
68 {
69  aColorList.clear();
70  m_xLbChartColors->clear();
71 }
72 
73 void SvxDefaultColorOptPage::ModifyColorEntry(const XColorEntry& rEntry, sal_Int32 nPos)
74 {
75  RemoveColorEntry(nPos);
76  InsertColorEntry(rEntry, nPos);
77 }
78 
80 {
82  return;
83 
84  m_xLbChartColors->freeze();
86  const long nCount(m_SvxChartColorTableUniquePtr->size());
87  for (long i = 0; i < nCount; ++i)
89  m_xLbChartColors->thaw();
90 }
91 
93  : SfxTabPage(pParent, "cui/ui/optchartcolorspage.ui", "OptChartColorsPage", &rInAttrs)
94  , m_xLbChartColors(m_xBuilder->weld_tree_view("colors"))
95  , m_xLbPaletteSelector(m_xBuilder->weld_combo_box("paletteselector"))
96  , m_xPBDefault(m_xBuilder->weld_button("default"))
97  , m_xPBAdd(m_xBuilder->weld_button("add"))
98  , m_xPBRemove(m_xBuilder->weld_button("delete"))
99  , m_xValSetColorBox(new ColorValueSet(m_xBuilder->weld_scrolled_window("tablewin")))
100  , m_xValSetColorBoxWin(new weld::CustomWeld(*m_xBuilder, "table", *m_xValSetColorBox))
101 {
102  m_xLbChartColors->set_size_request(-1, m_xLbChartColors->get_height_rows(16));
103 
104  m_xPBDefault->connect_clicked( LINK( this, SvxDefaultColorOptPage, ResetToDefaults ) );
105  m_xPBAdd->connect_clicked( LINK( this, SvxDefaultColorOptPage, AddChartColor ) );
106  m_xPBRemove->connect_clicked( LINK( this, SvxDefaultColorOptPage, RemoveChartColor ) );
107  m_xValSetColorBox->SetSelectHdl( LINK( this, SvxDefaultColorOptPage, BoxClickedHdl ) );
108  m_xLbPaletteSelector->connect_changed( LINK( this, SvxDefaultColorOptPage, SelectPaletteLbHdl ) );
109 
110  m_xValSetColorBox->SetStyle( m_xValSetColorBox->GetStyle()
112 
114 
115  const SfxPoolItem* pItem = nullptr;
116  if ( rInAttrs.GetItemState( SID_SCH_EDITOPTIONS, false, &pItem ) == SfxItemState::SET )
117  {
118  m_SvxChartColorTableUniquePtr = std::make_unique<SvxChartColorTable>(
119  static_cast<const SvxChartColorTableItem*>(pItem)->GetColorList());
120  }
121  else
122  {
123  m_SvxChartColorTableUniquePtr = std::make_unique<SvxChartColorTable>();
124  m_SvxChartColorTableUniquePtr->useDefault();
126  }
127 
128  Construct();
129 }
130 
132 {
133  disposeOnce();
134 }
135 
137 {
138  m_xValSetColorBoxWin.reset();
139  m_xValSetColorBox.reset();
141 }
142 
144 {
146  FillPaletteLB();
147 
148  m_xLbChartColors->select( 0 );
149 }
150 
152 {
153  return VclPtr<SvxDefaultColorOptPage>::Create( pParent, *rAttrs );
154 }
155 
157 {
159  {
160  rOutAttrs->Put(SvxChartColorTableItem(SID_SCH_EDITOPTIONS, *m_SvxChartColorTableUniquePtr.get()));
161  }
162 
163  return true;
164 }
165 
167 {
168  m_xLbChartColors->select( 0 );
169 }
170 
172 {
173  m_xLbPaletteSelector->clear();
174  std::vector<OUString> aPaletteList = aPaletteManager.GetPaletteList();
175  for (auto const& palette : aPaletteList)
176  m_xLbPaletteSelector->append_text(palette);
177 
178  OUString aPaletteName(officecfg::Office::Common::UserColors::PaletteName::get());
179  m_xLbPaletteSelector->set_active_text(aPaletteName);
180  if (m_xLbPaletteSelector->get_active() != -1)
181  SelectPaletteLbHdl( *m_xLbPaletteSelector );
182 }
183 
185 {
187  {
189  m_SvxChartOptionsUniquePtr->Commit();
190  }
191 }
192 
193 // event handlers
194 
195 
196 // ResetToDefaults
198 {
199  if( m_SvxChartColorTableUniquePtr )
200  {
201  m_SvxChartColorTableUniquePtr->useDefault();
202 
203  FillBoxChartColorLB();
204 
205  m_xLbChartColors->grab_focus();
206  m_xLbChartColors->select( 0 );
207  m_xPBRemove->set_sensitive(true);
208  }
209 }
210 
211 // AddChartColor
213 {
214  if( m_SvxChartColorTableUniquePtr )
215  {
216  Color const black( 0x00, 0x00, 0x00 );
217 
218  m_SvxChartColorTableUniquePtr->append(
219  XColorEntry(black, SvxChartColorTable::getDefaultName(m_SvxChartColorTableUniquePtr->size())));
220 
221  FillBoxChartColorLB();
222  m_xLbChartColors->grab_focus();
223  m_xLbChartColors->select(m_SvxChartColorTableUniquePtr->size() - 1);
224  m_xPBRemove->set_sensitive(true);
225  }
226 }
227 
228 // RemoveChartColor
230 {
231  sal_Int32 nIndex = m_xLbChartColors->get_selected_index();
232  if (nIndex == -1)
233  return;
234 
235  if( m_SvxChartColorTableUniquePtr )
236  {
237  OSL_ENSURE(m_SvxChartColorTableUniquePtr->size() > 1, "don't delete the last chart color");
238 
239  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/querydeletechartcolordialog.ui"));
240  std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("QueryDeleteChartColorDialog"));
241 
242  if (RET_YES == xQuery->run())
243  {
244  m_SvxChartColorTableUniquePtr->remove(nIndex);
245 
246  FillBoxChartColorLB();
247 
248  m_xLbChartColors->grab_focus();
249 
250  if (nIndex == m_xLbChartColors->n_children() && m_xLbChartColors->n_children() > 0)
251  m_xLbChartColors->select(m_SvxChartColorTableUniquePtr->size() - 1);
252  else if (m_xLbChartColors->n_children() > 0)
253  m_xLbChartColors->select( nIndex );
254  else
255  m_xPBRemove->set_sensitive(true);
256  }
257  }
258 }
259 
261 {
262  sal_Int32 nPos = m_xLbPaletteSelector->get_active();
263  aPaletteManager.SetPalette( nPos );
264  aPaletteManager.ReloadColorSet( *m_xValSetColorBox );
265  m_xValSetColorBox->Resize();
266 }
267 
269 {
270  sal_Int32 nIdx = m_xLbChartColors->get_selected_index();
271  if (nIdx != -1)
272  {
273  const XColorEntry aEntry(m_xValSetColorBox->GetItemColor(m_xValSetColorBox->GetSelectedItemId()), m_xLbChartColors->get_selected_text());
274 
275  ModifyColorEntry(aEntry, nIdx);
276  m_SvxChartColorTableUniquePtr->replace(nIdx, aEntry);
277 
278  m_xLbChartColors->select(nIdx); // reselect entry
279  }
280 }
281 
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ImpColorList aColorList
Definition: optchart.hxx:41
std::unique_ptr< weld::Button > m_xPBRemove
Definition: optchart.hxx:48
static OUString getDefaultName(size_t _nIndex)
Definition: cfgchart.cxx:115
std::unique_ptr< SvxChartOptions > m_SvxChartOptionsUniquePtr
Definition: optchart.hxx:36
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
std::unique_ptr< weld::ComboBox > m_xLbPaletteSelector
Definition: optchart.hxx:45
WinBits const WB_VSCROLL
const Size & GetListBoxPreviewDefaultPixelSize() const
void RemoveColorEntry(sal_Int32 nPos)
Definition: optchart.cxx:59
RET_YES
std::unique_ptr< SvxChartColorTable > m_SvxChartColorTableUniquePtr
Definition: optchart.hxx:39
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rInAttrs)
Definition: optchart.cxx:151
#define WB_ITEMBORDER
virtual ~SvxDefaultColorOptPage() override
Definition: optchart.cxx:131
virtual void dispose() override
IMPL_LINK_NOARG(SvxDefaultColorOptPage, ResetToDefaults, weld::Button &, void)
Definition: optchart.cxx:197
PaletteManager aPaletteManager
Definition: optchart.hxx:42
const OUString & GetName() const
const Color & GetDisableColor() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
std::vector< OUString > GetPaletteList()
std::unique_ptr< weld::Button > m_xPBDefault
Definition: optchart.hxx:46
void InsertColorEntry(const XColorEntry &rEntry, sal_Int32 nPos=-1)
Definition: optchart.cxx:31
void ModifyColorEntry(const XColorEntry &rEntry, sal_Int32 nPos)
Definition: optchart.cxx:73
virtual void Reset(const SfxItemSet *rInAttrs) override
Definition: optchart.cxx:166
int i
std::unique_ptr< weld::CustomWeld > m_xValSetColorBoxWin
Definition: optchart.hxx:50
std::unique_ptr< weld::Button > m_xPBAdd
Definition: optchart.hxx:47
std::unique_ptr< ColorValueSet > m_xValSetColorBox
Definition: optchart.hxx:49
virtual void dispose() override
Definition: optchart.cxx:136
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< weld::TreeView > m_xLbChartColors
Definition: optchart.hxx:44
virtual bool FillItemSet(SfxItemSet *rOutAttrs) override
Definition: optchart.cxx:156
static VclPtr< reference_type > Create(Arg &&...arg)
const Color & GetColor() const
reference_type * get() const
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
sal_Int32 nPos
SvxDefaultColorOptPage(TabPageParent pParent, const SfxItemSet &rInAttrs)
Definition: optchart.cxx:92
#define WB_NAMEFIELD