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"
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
30void SvxDefaultColorOptPage::InsertColorEntry(const XColorEntry& rEntry, sal_Int32 nPos)
31{
32 const Color& rColor = rEntry.GetColor();
33 const OUString& rStr = rEntry.GetName();
34
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(), 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
72void SvxDefaultColorOptPage::ModifyColorEntry(const XColorEntry& rEntry, sal_Int32 nPos)
73{
75 InsertColorEntry(rEntry, nPos);
76}
77
79{
81 return;
82
83 m_xLbChartColors->freeze();
86 for (tools::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 SvxColorValueSet(m_xBuilder->weld_scrolled_window("tablewin", true)))
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
112 if ( const SvxChartColorTableItem* pEditOptionsItem = rInAttrs.GetItemIfSet( SID_SCH_EDITOPTIONS, false ) )
113 {
114 m_SvxChartColorTableUniquePtr = std::make_unique<SvxChartColorTable>(
115 pEditOptionsItem->GetColorList());
116 }
117 else
118 {
119 m_SvxChartColorTableUniquePtr = std::make_unique<SvxChartColorTable>();
120 m_SvxChartColorTableUniquePtr->useDefault();
122 }
123
124 Construct();
125}
126
128{
129 m_xValSetColorBoxWin.reset();
130 m_xValSetColorBox.reset();
131}
132
134{
137
138 m_xLbChartColors->select( 0 );
139}
140
141std::unique_ptr<SfxTabPage> SvxDefaultColorOptPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs )
142{
143 return std::make_unique<SvxDefaultColorOptPage>( pPage, pController, *rAttrs );
144}
145
147{
149 {
150 rOutAttrs->Put(SvxChartColorTableItem(SID_SCH_EDITOPTIONS, *m_SvxChartColorTableUniquePtr));
151 }
152
153 return true;
154}
155
157{
158 m_xLbChartColors->select( 0 );
159}
160
162{
163 m_xLbPaletteSelector->clear();
164 std::vector<OUString> aPaletteList = aPaletteManager.GetPaletteList();
165 for (auto const& palette : aPaletteList)
166 m_xLbPaletteSelector->append_text(palette);
167
168 OUString aPaletteName(officecfg::Office::Common::UserColors::PaletteName::get());
169 m_xLbPaletteSelector->set_active_text(aPaletteName);
170 if (m_xLbPaletteSelector->get_active() != -1)
171 SelectPaletteLbHdl( *m_xLbPaletteSelector );
172}
173
175{
178}
179
180// event handlers
181
182
183// ResetToDefaults
185{
186 if( m_SvxChartColorTableUniquePtr )
187 {
188 m_SvxChartColorTableUniquePtr->useDefault();
189
190 FillBoxChartColorLB();
191
192 m_xLbChartColors->grab_focus();
193 m_xLbChartColors->select( 0 );
194 m_xPBRemove->set_sensitive(true);
195 }
196}
197
198// AddChartColor
200{
201 if( m_SvxChartColorTableUniquePtr )
202 {
203 Color const black( 0x00, 0x00, 0x00 );
204
205 m_SvxChartColorTableUniquePtr->append(
206 XColorEntry(black, SvxChartColorTable::getDefaultName(m_SvxChartColorTableUniquePtr->size())));
207
208 FillBoxChartColorLB();
209 m_xLbChartColors->grab_focus();
210 m_xLbChartColors->select(m_SvxChartColorTableUniquePtr->size() - 1);
211 m_xPBRemove->set_sensitive(true);
212 }
213}
214
215// RemoveChartColor
217{
218 sal_Int32 nIndex = m_xLbChartColors->get_selected_index();
219 if (nIndex == -1)
220 return;
221
222 if( !m_SvxChartColorTableUniquePtr )
223 return;
224
225 OSL_ENSURE(m_SvxChartColorTableUniquePtr->size() > 1, "don't delete the last chart color");
226
227 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletechartcolordialog.ui"));
228 std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("QueryDeleteChartColorDialog"));
229
230 if (RET_YES != xQuery->run())
231 return;
232
233 m_SvxChartColorTableUniquePtr->remove(nIndex);
234
235 FillBoxChartColorLB();
236
237 m_xLbChartColors->grab_focus();
238
239 if (nIndex == m_xLbChartColors->n_children() && m_xLbChartColors->n_children() > 0)
240 m_xLbChartColors->select(m_SvxChartColorTableUniquePtr->size() - 1);
241 else if (m_xLbChartColors->n_children() > 0)
242 m_xLbChartColors->select( nIndex );
243 else
244 m_xPBRemove->set_sensitive(true);
245}
246
248{
249 sal_Int32 nPos = m_xLbPaletteSelector->get_active();
250 aPaletteManager.SetPalette( nPos );
251 aPaletteManager.ReloadColorSet( *m_xValSetColorBox );
252 m_xValSetColorBox->Resize();
253}
254
256{
257 sal_Int32 nIdx = m_xLbChartColors->get_selected_index();
258 if (nIdx != -1)
259 {
260 const XColorEntry aEntry(m_xValSetColorBox->GetItemColor(m_xValSetColorBox->GetSelectedItemId()), m_xLbChartColors->get_selected_text());
261
262 ModifyColorEntry(aEntry, nIdx);
263 m_SvxChartColorTableUniquePtr->replace(nIdx, aEntry);
264
265 m_xLbChartColors->select(nIdx); // reselect entry
266 }
267}
268
269/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
std::vector< OUString > GetPaletteList()
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const Color & GetDisableColor() const
const Size & GetListBoxPreviewDefaultPixelSize() const
static OUString getDefaultName(size_t _nIndex)
Definition: cfgchart.cxx:116
virtual void Reset(const SfxItemSet *rInAttrs) override
Definition: optchart.cxx:156
std::unique_ptr< weld::Button > m_xPBDefault
Definition: optchart.hxx:44
void InsertColorEntry(const XColorEntry &rEntry, sal_Int32 nPos=-1)
Definition: optchart.cxx:30
virtual bool FillItemSet(SfxItemSet *rOutAttrs) override
Definition: optchart.cxx:146
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rInAttrs)
Definition: optchart.cxx:141
SvxDefaultColorOptPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: optchart.cxx:91
void RemoveColorEntry(sal_Int32 nPos)
Definition: optchart.cxx:58
std::unique_ptr< weld::TreeView > m_xLbChartColors
Definition: optchart.hxx:42
std::unique_ptr< weld::CustomWeld > m_xValSetColorBoxWin
Definition: optchart.hxx:48
void ModifyColorEntry(const XColorEntry &rEntry, sal_Int32 nPos)
Definition: optchart.cxx:72
std::unique_ptr< SvxColorValueSet > m_xValSetColorBox
Definition: optchart.hxx:47
std::unique_ptr< weld::Button > m_xPBAdd
Definition: optchart.hxx:45
virtual ~SvxDefaultColorOptPage() override
Definition: optchart.cxx:127
PaletteManager aPaletteManager
Definition: optchart.hxx:40
std::unique_ptr< weld::ComboBox > m_xLbPaletteSelector
Definition: optchart.hxx:43
std::unique_ptr< SvxChartColorTable > m_SvxChartColorTableUniquePtr
Definition: optchart.hxx:37
ImpColorList aColorList
Definition: optchart.hxx:39
std::unique_ptr< weld::Button > m_xPBRemove
Definition: optchart.hxx:46
reference_type * get() const
const Color & GetColor() const
const OUString & GetName() const
int nCount
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
sal_Int32 nIndex
sal_uInt16 nPos
void SetDefaultColors(const SvxChartColorTable &aCol)
Definition: cfgchart.cxx:199
int i
long Long
IMPL_LINK_NOARG(SvxDefaultColorOptPage, ResetToDefaults, weld::Button &, void)
Definition: optchart.cxx:184
#define WB_ITEMBORDER
#define WB_NAMEFIELD
RET_YES
WinBits const WB_VSCROLL