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
113
114 if ( const SvxChartColorTableItem* pEditOptionsItem = rInAttrs.GetItemIfSet( SID_SCH_EDITOPTIONS, false ) )
115 {
116 m_SvxChartColorTableUniquePtr = std::make_unique<SvxChartColorTable>(
117 pEditOptionsItem->GetColorList());
118 }
119 else
120 {
121 m_SvxChartColorTableUniquePtr = std::make_unique<SvxChartColorTable>();
122 m_SvxChartColorTableUniquePtr->useDefault();
124 }
125
126 Construct();
127}
128
130{
131 m_xValSetColorBoxWin.reset();
132 m_xValSetColorBox.reset();
133}
134
136{
139
140 m_xLbChartColors->select( 0 );
141}
142
143std::unique_ptr<SfxTabPage> SvxDefaultColorOptPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs )
144{
145 return std::make_unique<SvxDefaultColorOptPage>( pPage, pController, *rAttrs );
146}
147
149{
151 {
152 rOutAttrs->Put(SvxChartColorTableItem(SID_SCH_EDITOPTIONS, *m_SvxChartColorTableUniquePtr));
153 }
154
155 return true;
156}
157
159{
161 {
162 m_SvxChartColorTableUniquePtr->useDefault();
163
165
166 m_xLbChartColors->grab_focus();
167 m_xLbChartColors->select( 0 );
168 m_xPBRemove->set_sensitive(true);
169 }
170}
171
173{
174 m_xLbPaletteSelector->clear();
175 std::vector<OUString> aPaletteList = aPaletteManager.GetPaletteList();
176 for (auto const& palette : aPaletteList)
177 m_xLbPaletteSelector->append_text(palette);
178
179 OUString aPaletteName(officecfg::Office::Common::UserColors::PaletteName::get());
180 m_xLbPaletteSelector->set_active_text(aPaletteName);
181 if (m_xLbPaletteSelector->get_active() != -1)
182 SelectPaletteLbHdl( *m_xLbPaletteSelector );
183}
184
186{
188 {
191 }
192}
193
194// event handlers
195
196
197// ResetToDefaults
199{
200 if( m_SvxChartColorTableUniquePtr )
201 {
202 m_SvxChartColorTableUniquePtr->useDefault();
203
204 FillBoxChartColorLB();
205
206 m_xLbChartColors->grab_focus();
207 m_xLbChartColors->select( 0 );
208 m_xPBRemove->set_sensitive(true);
209 }
210}
211
212// AddChartColor
214{
215 if( m_SvxChartColorTableUniquePtr )
216 {
217 Color const black( 0x00, 0x00, 0x00 );
218
219 m_SvxChartColorTableUniquePtr->append(
220 XColorEntry(black, SvxChartColorTable::getDefaultName(m_SvxChartColorTableUniquePtr->size())));
221
222 FillBoxChartColorLB();
223 m_xLbChartColors->grab_focus();
224 m_xLbChartColors->select(m_SvxChartColorTableUniquePtr->size() - 1);
225 m_xPBRemove->set_sensitive(true);
226 }
227}
228
229// RemoveChartColor
231{
232 sal_Int32 nIndex = m_xLbChartColors->get_selected_index();
233 if (nIndex == -1)
234 return;
235
236 if( !m_SvxChartColorTableUniquePtr )
237 return;
238
239 OSL_ENSURE(m_SvxChartColorTableUniquePtr->size() > 1, "don't delete the last chart color");
240
241 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletechartcolordialog.ui"));
242 std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("QueryDeleteChartColorDialog"));
243
244 if (RET_YES != xQuery->run())
245 return;
246
247 m_SvxChartColorTableUniquePtr->remove(nIndex);
248
249 FillBoxChartColorLB();
250
251 m_xLbChartColors->grab_focus();
252
253 if (nIndex == m_xLbChartColors->n_children() && m_xLbChartColors->n_children() > 0)
254 m_xLbChartColors->select(m_SvxChartColorTableUniquePtr->size() - 1);
255 else if (m_xLbChartColors->n_children() > 0)
256 m_xLbChartColors->select( nIndex );
257 else
258 m_xPBRemove->set_sensitive(true);
259}
260
262{
263 sal_Int32 nPos = m_xLbPaletteSelector->get_active();
264 aPaletteManager.SetPalette( nPos );
265 aPaletteManager.ReloadColorSet( *m_xValSetColorBox );
266 m_xValSetColorBox->Resize();
267}
268
270{
271 sal_Int32 nIdx = m_xLbChartColors->get_selected_index();
272 if (nIdx != -1)
273 {
274 const XColorEntry aEntry(m_xValSetColorBox->GetItemColor(m_xValSetColorBox->GetSelectedItemId()), m_xLbChartColors->get_selected_text());
275
276 ModifyColorEntry(aEntry, nIdx);
277 m_SvxChartColorTableUniquePtr->replace(nIdx, aEntry);
278
279 m_xLbChartColors->select(nIdx); // reselect entry
280 }
281}
282
283/* 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:115
virtual void Reset(const SfxItemSet *rInAttrs) override
Definition: optchart.cxx:158
std::unique_ptr< weld::Button > m_xPBDefault
Definition: optchart.hxx:45
void InsertColorEntry(const XColorEntry &rEntry, sal_Int32 nPos=-1)
Definition: optchart.cxx:30
virtual bool FillItemSet(SfxItemSet *rOutAttrs) override
Definition: optchart.cxx:148
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rInAttrs)
Definition: optchart.cxx:143
SvxDefaultColorOptPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: optchart.cxx:91
std::unique_ptr< SvxChartOptions > m_SvxChartOptionsUniquePtr
Definition: optchart.hxx:35
void RemoveColorEntry(sal_Int32 nPos)
Definition: optchart.cxx:58
std::unique_ptr< weld::TreeView > m_xLbChartColors
Definition: optchart.hxx:43
std::unique_ptr< weld::CustomWeld > m_xValSetColorBoxWin
Definition: optchart.hxx:49
void ModifyColorEntry(const XColorEntry &rEntry, sal_Int32 nPos)
Definition: optchart.cxx:72
std::unique_ptr< SvxColorValueSet > m_xValSetColorBox
Definition: optchart.hxx:48
std::unique_ptr< weld::Button > m_xPBAdd
Definition: optchart.hxx:46
virtual ~SvxDefaultColorOptPage() override
Definition: optchart.cxx:129
PaletteManager aPaletteManager
Definition: optchart.hxx:41
std::unique_ptr< weld::ComboBox > m_xLbPaletteSelector
Definition: optchart.hxx:44
std::unique_ptr< SvxChartColorTable > m_SvxChartColorTableUniquePtr
Definition: optchart.hxx:38
ImpColorList aColorList
Definition: optchart.hxx:40
std::unique_ptr< weld::Button > m_xPBRemove
Definition: optchart.hxx:47
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
int i
long Long
IMPL_LINK_NOARG(SvxDefaultColorOptPage, ResetToDefaults, weld::Button &, void)
Definition: optchart.cxx:198
#define WB_ITEMBORDER
#define WB_NAMEFIELD
RET_YES
WinBits const WB_VSCROLL