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