| 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 "tp_ChartColorPalette.hxx" |
| 21 |
|
| 22 |
#include <ChartColorPaletteHelper.hxx> |
| 23 |
#include <ChartModel.hxx> |
| 24 |
#include <chartview/ChartSfxItemIds.hxx> |
| 25 |
#include <svx/chrtitem.hxx> |
| 26 |
#include <vcl/svapp.hxx> |
| 27 |
|
| 28 |
namespace chart |
| 29 |
{ |
| 30 |
ChartColorPaletteTabPage::ChartColorPaletteTabPage(weld::Container* pPage, |
| 31 |
weld::DialogController* pController, |
| 32 |
const SfxItemSet& rInAttrs) |
| 33 |
: SfxTabPage(pPage, pController, "modules/schart/ui/tp_ChartColorPalette.ui", |
| 34 |
"tp_ChartColorPalette", &rInAttrs) |
| 35 |
, mxColorfulPalettes(new ChartColorPalettes(*m_xBuilder, "colorful_palettes", "colorfulwin")) |
| 36 |
, mxMonoPalettes( |
| 37 |
new ChartColorPalettes(*m_xBuilder, "monochromatic_palettes", "monochromaticwin")) |
| 38 |
{ |
| 39 |
mxColorfulPalettes->SetSelectHdl( |
| 40 |
LINK(this, ChartColorPaletteTabPage, SelectColorfulPaletteHdl)); |
| 41 |
|
| 42 |
mxMonoPalettes->SetSelectHdl(LINK(this, ChartColorPaletteTabPage, SelectMonoPaletteHdl)); |
| 43 |
} |
| 44 |
|
| 45 |
ChartColorPaletteTabPage::~ChartColorPaletteTabPage() |
| 46 |
{ |
| 47 |
mxColorfulPalettes.reset(); |
| 48 |
mxMonoPalettes.reset(); |
| 49 |
} |
| 50 |
|
| 51 |
std::unique_ptr<SfxTabPage> ChartColorPaletteTabPage::Create(weld::Container* pPage, |
| 52 |
weld::DialogController* pController, |
| 53 |
const SfxItemSet* rInAttrs) |
| 54 |
{ |
| 55 |
return std::make_unique<ChartColorPaletteTabPage>(pPage, pController, *rInAttrs); |
| 56 |
} |
| 57 |
|
| 58 |
void ChartColorPaletteTabPage::init(const rtl::Reference<ChartModel>& xChartModel) |
| 59 |
{ |
| 60 |
assert(xChartModel); |
| 61 |
mxChartModel = xChartModel; |
| 62 |
|
| 63 |
const std::shared_ptr<model::Theme> pTheme = mxChartModel->getDocumentTheme(); |
| 64 |
mxHelper = std::make_unique<ChartColorPaletteHelper>(pTheme); |
| 65 |
|
| 66 |
selectItem(mxChartModel->getColorPaletteType(), mxChartModel->getColorPaletteIndex() + 1); |
| 67 |
initColorPalettes(); |
| 68 |
} |
| 69 |
|
| 70 |
void ChartColorPaletteTabPage::initColorPalettes() const |
| 71 |
{ |
| 72 |
if (!mxHelper) |
| 73 |
return; |
| 74 |
// colorful palettes |
| 75 |
for (size_t i = 0; i < ChartColorPaletteHelper::ColorfulPaletteSize; ++i) |
| 76 |
mxColorfulPalettes->insert(mxHelper->getColorPalette(ChartColorPaletteType::Colorful, i)); |
| 77 |
mxColorfulPalettes->Fill(); |
| 78 |
// monotonic palettes |
| 79 |
for (size_t i = 0; i < ChartColorPaletteHelper::MonotonicPaletteSize; ++i) |
| 80 |
mxMonoPalettes->insert(mxHelper->getColorPalette(ChartColorPaletteType::Monochromatic, i)); |
| 81 |
mxMonoPalettes->Fill(); |
| 82 |
} |
| 83 |
|
| 84 |
void ChartColorPaletteTabPage::selectItem(const ChartColorPaletteType eType, |
| 85 |
const sal_uInt32 nIndex) const |
| 86 |
{ |
| 87 |
switch (eType) |
| 88 |
{ |
| 89 |
default: |
| 90 |
case ChartColorPaletteType::Unknown: |
| 91 |
mxColorfulPalettes->SetNoSelection(); |
| 92 |
mxMonoPalettes->SetNoSelection(); |
| 93 |
break; |
| 94 |
case ChartColorPaletteType::Colorful: |
| 95 |
mxMonoPalettes->SetNoSelection(); |
| 96 |
mxColorfulPalettes->SelectItem(nIndex); |
| 97 |
break; |
| 98 |
case ChartColorPaletteType::Monochromatic: |
| 99 |
mxColorfulPalettes->SetNoSelection(); |
| 100 |
mxMonoPalettes->SelectItem(nIndex); |
| 101 |
break; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
bool ChartColorPaletteTabPage::FillItemSet(SfxItemSet* pOutAttrs) |
| 106 |
{ |
| 107 |
ChartColorPaletteType eType = ChartColorPaletteType::Unknown; |
| 108 |
sal_uInt32 nIndex = 0; |
| 109 |
|
| 110 |
if (!mxColorfulPalettes->IsNoSelection()) |
| 111 |
{ |
| 112 |
eType = ChartColorPaletteType::Colorful; |
| 113 |
nIndex = mxColorfulPalettes->GetSelectedItemId() - 1; |
| 114 |
} |
| 115 |
else if (!mxMonoPalettes->IsNoSelection()) |
| 116 |
{ |
| 117 |
eType = ChartColorPaletteType::Monochromatic; |
| 118 |
nIndex = mxMonoPalettes->GetSelectedItemId() - 1; |
| 119 |
} |
| 120 |
|
| 121 |
pOutAttrs->Put(SvxChartColorPaletteItem(eType, nIndex, SCHATTR_COLOR_PALETTE)); |
| 122 |
|
| 123 |
return true; |
| 124 |
} |
| 125 |
|
| 126 |
void ChartColorPaletteTabPage::Reset(const SfxItemSet*) |
| 127 |
{ |
| 128 |
selectItem(mxChartModel->getColorPaletteType(), mxChartModel->getColorPaletteIndex() + 1); |
| 129 |
} |
| 130 |
|
| 131 |
DeactivateRC ChartColorPaletteTabPage::DeactivatePage(SfxItemSet* pItemSet) |
| 132 |
{ |
| 133 |
if (pItemSet) |
| 134 |
FillItemSet(pItemSet); |
| 135 |
|
| 136 |
return DeactivateRC::LeavePage; |
| 137 |
} |
| 138 |
|
| 139 |
IMPL_LINK_NOARG(ChartColorPaletteTabPage, SelectColorfulPaletteHdl, weld::IconView&, bool) |
| 140 |
{ |
| 141 |
sal_uInt32 nIndex = SelectPaletteHdl(mxColorfulPalettes); |
| 142 |
if (nIndex != static_cast<sal_uInt32>(-1)) |
| 143 |
{ |
| 144 |
mxMonoPalettes->SetNoSelection(); |
| 145 |
} |
| 146 |
return true; |
| 147 |
} |
| 148 |
|
| 149 |
IMPL_LINK_NOARG(ChartColorPaletteTabPage, SelectMonoPaletteHdl, weld::IconView&, bool) |
| 150 |
{ |
| 151 |
sal_uInt32 nIndex = SelectPaletteHdl(mxMonoPalettes); |
| 152 |
if (nIndex != static_cast<sal_uInt32>(-1)) |
| 153 |
{ |
| 154 |
mxColorfulPalettes->SetNoSelection(); |
| 155 |
} |
| 156 |
return true; |
| 157 |
} |
| 158 |
|
| 159 |
sal_uInt32 |
| 160 |
ChartColorPaletteTabPage::SelectPaletteHdl(const std::unique_ptr<ChartColorPalettes>& xValueSet) |
| 161 |
{ |
| 162 |
const sal_uInt32 nItemId = xValueSet->GetSelectedItemId(); |
| 163 |
|
| 164 |
if (!nItemId) |
| 165 |
return static_cast<sal_uInt32>(-1); |
| 166 |
|
| 167 |
const sal_uInt32 nIndex = nItemId - 1; |
| 168 |
|
| 169 |
if (xValueSet->getPalette(nIndex)) |
| 170 |
{ |
| 171 |
return nIndex; |
| 172 |
} |
| 173 |
return static_cast<sal_uInt32>(-1); |
| 174 |
} |
| 175 |
} //namespace chart |
| 176 |
|
| 177 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |