Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / miscdlgs / tabbgcolordlg.cxx
bloba8993d851bd1bdca785cc33cd0e5650f4e58930d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include "tabbgcolordlg.hxx"
23 #include "scresid.hxx"
24 #include "miscdlgs.hrc"
26 #include <tools/color.hxx>
27 #include <sfx2/objsh.hxx>
28 #include <svx/xtable.hxx>
29 #include <svx/drawitem.hxx>
30 #include <unotools/pathoptions.hxx>
31 #include <tools/resid.hxx>
32 #include <editeng/editrids.hrc>
33 #include <editeng/eerdll.hxx>
34 #include <vcl/builderfactory.hxx>
36 #define HDL(hdl) LINK(this,ScTabBgColorDlg,hdl)
38 ScTabBgColorDlg::ScTabBgColorDlg(vcl::Window* pParent, const OUString& rTitle,
39 const OUString& rTabBgColorNoColorText, const Color& rDefaultColor,
40 const OString& sHelpId)
41 : ModalDialog(pParent, "TabColorDialog", "modules/scalc/ui/tabcolordialog.ui")
42 , m_aTabBgColor(rDefaultColor)
43 , m_aTabBgColorNoColorText(rTabBgColorNoColorText)
46 get(m_pTabBgColorSet, "colorset");
47 m_pTabBgColorSet->SetDialog(this);
48 m_pTabBgColorSet->SetColCount(SvxColorValueSet::getColumnCount());
49 get(m_pBtnOk, "ok");
51 SetHelpId( sHelpId );
52 this->SetText( rTitle );
53 this->SetStyle(GetStyle() | WB_BORDER | WB_STDFLOATWIN | WB_3DLOOK | WB_DIALOGCONTROL | WB_SYSTEMWINDOW | WB_STANDALONE | WB_HIDE);
55 FillColorValueSets_Impl();
56 m_pTabBgColorSet->SetDoubleClickHdl( HDL(TabBgColorDblClickHdl_Impl) );
57 m_pBtnOk->SetClickHdl( HDL(TabBgColorOKHdl_Impl) );
60 ScTabBgColorDlg::~ScTabBgColorDlg()
62 disposeOnce();
65 void ScTabBgColorDlg::dispose()
67 m_pTabBgColorSet.clear();
68 m_pBtnOk.clear();
69 ModalDialog::dispose();
72 void ScTabBgColorDlg::GetSelectedColor( Color& rColor ) const
74 rColor = this->m_aTabBgColor;
77 void ScTabBgColorDlg::FillColorValueSets_Impl()
79 SfxObjectShell* pDocSh = SfxObjectShell::Current();
80 const SfxPoolItem* pItem = nullptr;
81 XColorListRef pColorList;
83 sal_uInt16 nSelectedItem = 0;
85 OSL_ENSURE( pDocSh, "DocShell not found!" );
87 if ( pDocSh && ( nullptr != ( pItem = pDocSh->GetItem(SID_COLOR_TABLE) ) ) )
88 pColorList = static_cast<const SvxColorListItem*>(pItem)->GetColorList();
89 if ( !pColorList.is() )
90 pColorList = XColorList::CreateStdColorList();
92 long nColorCount(0);
94 if ( pColorList.is() )
96 nColorCount = pColorList->Count();
97 m_pTabBgColorSet->addEntriesForXColorList(*pColorList);
100 if (nColorCount)
102 const WinBits nBits(m_pTabBgColorSet->GetStyle() | WB_NAMEFIELD | WB_ITEMBORDER | WB_NONEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_NOPOINTERFOCUS);
103 m_pTabBgColorSet->SetText( m_aTabBgColorNoColorText );
104 m_pTabBgColorSet->SetStyle( nBits );
107 //lock down a preferred size
108 const sal_uInt32 nColCount = SvxColorValueSet::getColumnCount();
109 const sal_uInt32 nRowCount(ceil(double(nColorCount)/nColCount));
110 const sal_uInt32 nLength = SvxColorValueSet::getEntryEdgeLength();
111 Size aSize(m_pTabBgColorSet->CalcWindowSizePixel(Size(nLength, nLength), nColCount, nRowCount));
112 m_pTabBgColorSet->set_width_request(aSize.Width()+8);
113 m_pTabBgColorSet->set_height_request(aSize.Height()+8);
115 m_pTabBgColorSet->SelectItem(nSelectedItem);
118 /// Handler, called when color selection is changed
119 IMPL_LINK_NOARG_TYPED(ScTabBgColorDlg, TabBgColorDblClickHdl_Impl, ValueSet*, void)
121 sal_uInt16 nItemId = m_pTabBgColorSet->GetSelectItemId();
122 Color aColor = nItemId ? ( m_pTabBgColorSet->GetItemColor( nItemId ) ) : Color( COL_AUTO );
123 m_aTabBgColor = aColor;
124 EndDialog( RET_OK );
127 // Handler, called when the OK button is pushed
128 IMPL_LINK_NOARG_TYPED(ScTabBgColorDlg, TabBgColorOKHdl_Impl, Button*, void)
130 sal_uInt16 nItemId = m_pTabBgColorSet->GetSelectItemId();
131 Color aColor = nItemId ? ( m_pTabBgColorSet->GetItemColor( nItemId ) ) : Color( COL_AUTO );
132 m_aTabBgColor = aColor;
133 EndDialog( RET_OK );
136 ScTabBgColorDlg::ScTabBgColorValueSet::ScTabBgColorValueSet(vcl::Window* pParent, WinBits nStyle)
137 : SvxColorValueSet(pParent, nStyle)
138 , m_pTabBgColorDlg(nullptr)
142 ScTabBgColorDlg::ScTabBgColorValueSet::~ScTabBgColorValueSet()
144 disposeOnce();
147 void ScTabBgColorDlg::ScTabBgColorValueSet::dispose()
149 m_pTabBgColorDlg.clear();
150 SvxColorValueSet::dispose();
153 VCL_BUILDER_DECL_FACTORY(ScTabBgColorValueSet)
155 WinBits nWinBits = WB_TABSTOP;
157 OString sBorder = VclBuilder::extractCustomProperty(rMap);
158 if (!sBorder.isEmpty())
159 nWinBits |= WB_BORDER;
161 rRet = VclPtr<ScTabBgColorDlg::ScTabBgColorValueSet>::Create(pParent, nWinBits);
164 void ScTabBgColorDlg::ScTabBgColorValueSet::KeyInput( const KeyEvent& rKEvt )
166 switch ( rKEvt.GetKeyCode().GetCode() )
168 case KEY_SPACE:
169 case KEY_RETURN:
171 sal_uInt16 nItemId = GetSelectItemId();
172 const Color& aColor = nItemId ? ( GetItemColor( nItemId ) ) : Color( COL_AUTO );
173 m_pTabBgColorDlg->m_aTabBgColor = aColor;
174 m_pTabBgColorDlg->EndDialog(RET_OK);
176 break;
178 SvxColorValueSet::KeyInput(rKEvt);
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */