nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / uibase / sidebar / PageStylesPanel.cxx
blob64260077a54cbc8c6b48ecebf427deccfcb77d4e
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 .
19 #include <sal/config.h>
20 #include <svl/intitem.hxx>
21 #include <svx/colorbox.hxx>
22 #include <svx/drawitem.hxx>
23 #include <svx/xfillit0.hxx>
24 #include <svx/xflclit.hxx>
25 #include <svx/xflgrit.hxx>
26 #include <svx/xflhtit.hxx>
27 #include <svx/xbtmpit.hxx>
28 #include <svx/SvxNumOptionsTabPageHelper.hxx>
29 #include "PageStylesPanel.hxx"
30 #include <sfx2/sidebar/Panel.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/objsh.hxx>
34 #include <cmdid.h>
36 using namespace ::com::sun::star;
38 namespace sw::sidebar{
40 namespace {
42 enum eFillStyle
44 NONE,
45 SOLID,
46 GRADIENT,
47 HATCH,
48 BITMAP,
49 PATTERN
54 const SvxPageUsage aArr[] =
56 SvxPageUsage::All,
57 SvxPageUsage::Mirror,
58 SvxPageUsage::Right,
59 SvxPageUsage::Left
63 static sal_uInt16 PageUsageToPos_Impl( SvxPageUsage nUsage )
65 for ( size_t i = 0; i < SAL_N_ELEMENTS(aArr); ++i )
66 if ( aArr[i] == nUsage )
67 return i;
68 return 3;
72 static SvxPageUsage PosToPageUsage_Impl( sal_uInt16 nPos )
74 if ( nPos >= SAL_N_ELEMENTS(aArr) )
75 return SvxPageUsage::NONE;
76 return aArr[nPos];
79 VclPtr<vcl::Window> PageStylesPanel::Create(
80 vcl::Window* pParent,
81 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
82 SfxBindings* pBindings)
84 if( pParent == nullptr )
85 throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageStylesPanel::Create", nullptr, 0);
86 if( !rxFrame.is() )
87 throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageStylesPanel::Create", nullptr, 0);
88 if( pBindings == nullptr )
89 throw ::com::sun::star::lang::IllegalArgumentException("no SfxBindings given to PageStylesPanel::Create", nullptr, 0);
91 return VclPtr<PageStylesPanel>::Create(pParent, rxFrame, pBindings);
94 PageStylesPanel::PageStylesPanel(
95 vcl::Window* pParent,
96 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
97 SfxBindings* pBindings
98 ) :
99 PanelLayout(pParent, "PageStylesPanel", "modules/swriter/ui/pagestylespanel.ui", rxFrame),
100 mpBindings( pBindings ),
101 mpPageColumnItem( new SfxInt16Item(SID_ATTR_PAGE_COLUMN) ),
102 mpPageItem( new SvxPageItem(SID_ATTR_PAGE) ),
103 maPageColumnControl(SID_ATTR_PAGE_COLUMN, *pBindings, *this),
104 maPageNumFormatControl( SID_ATTR_PAGE, *pBindings, *this ),
105 maBgColorControl( SID_ATTR_PAGE_COLOR, *pBindings, *this ),
106 maBgHatchingControl( SID_ATTR_PAGE_HATCH, *pBindings, *this ),
107 maBgGradientControl( SID_ATTR_PAGE_GRADIENT, *pBindings, *this ),
108 maBgBitmapControl( SID_ATTR_PAGE_BITMAP, *pBindings, *this ),
109 maBgFillStyleControl(SID_ATTR_PAGE_FILLSTYLE, *pBindings, *this),
110 mxBgColorLB(new ColorListBox(m_xBuilder->weld_menu_button("lbcolor"), GetFrameWeld())),
111 mxBgHatchingLB(m_xBuilder->weld_combo_box("lbhatching")),
112 mxBgGradientLB(new ColorListBox(m_xBuilder->weld_menu_button("lbgradient"), GetFrameWeld())),
113 mxBgBitmapLB(m_xBuilder->weld_combo_box("lbbitmap")),
114 mxLayoutSelectLB(m_xBuilder->weld_combo_box("layoutbox")),
115 mxColumnCount(m_xBuilder->weld_combo_box("columnbox")),
116 mxNumberSelectLB(new SvxPageNumberListBox(m_xBuilder->weld_combo_box("numberbox"))),
117 mxBgFillType(m_xBuilder->weld_combo_box("bgselect")),
118 mxCustomEntry(m_xBuilder->weld_label("customlabel")),
119 aCustomEntry()
121 Initialize();
124 PageStylesPanel::~PageStylesPanel()
126 disposeOnce();
129 void PageStylesPanel::dispose()
131 mxColumnCount.reset();
132 mxNumberSelectLB.reset();
133 mxBgFillType.reset();
134 mxBgColorLB.reset();
135 mxBgHatchingLB.reset();
136 mxBgGradientLB.reset();
137 mxBgBitmapLB.reset();
138 mxLayoutSelectLB.reset();
139 mxCustomEntry.reset();
141 maBgBitmapControl.dispose();
142 maBgColorControl.dispose();
143 maBgFillStyleControl.dispose();
144 maBgGradientControl.dispose();
145 maBgHatchingControl.dispose();
146 maPageColumnControl.dispose();
147 maPageNumFormatControl.dispose();
148 PanelLayout::dispose();
151 void PageStylesPanel::Initialize()
153 SvxFillTypeBox::Fill(*mxBgFillType);
155 aCustomEntry = mxCustomEntry->get_label();
156 mpBindings->Invalidate(SID_ATTR_PAGE_COLUMN);
157 mpBindings->Invalidate(SID_ATTR_PAGE);
158 mpBindings->Invalidate(SID_ATTR_PAGE_FILLSTYLE);
159 Update();
161 mxColumnCount->connect_changed( LINK(this, PageStylesPanel, ModifyColumnCountHdl) );
162 SvxNumOptionsTabPageHelper::GetI18nNumbering(mxNumberSelectLB->get_widget(), ::std::numeric_limits<sal_uInt16>::max());
163 mxNumberSelectLB->connect_changed( LINK(this, PageStylesPanel, ModifyNumberingHdl) );
164 mxLayoutSelectLB->connect_changed( LINK(this, PageStylesPanel, ModifyLayoutHdl) );
165 mxBgFillType->connect_changed( LINK(this, PageStylesPanel, ModifyFillStyleHdl));
166 mxBgColorLB->SetSelectHdl( LINK(this, PageStylesPanel, ModifyFillColorListHdl));
167 mxBgGradientLB->SetSelectHdl( LINK(this, PageStylesPanel, ModifyFillColorListHdl));
168 mxBgHatchingLB->connect_changed( LINK(this, PageStylesPanel, ModifyFillColorHdl));
169 mxBgBitmapLB->connect_changed( LINK(this, PageStylesPanel, ModifyFillColorHdl));
172 void PageStylesPanel::Update()
174 const eFillStyle eXFS = static_cast<eFillStyle>(mxBgFillType->get_active());
175 SfxObjectShell* pSh = SfxObjectShell::Current();
176 switch(eXFS)
178 case NONE:
180 mxBgColorLB->hide();
181 mxBgHatchingLB->hide();
182 mxBgGradientLB->hide();
183 mxBgBitmapLB->hide();
185 break;
186 case SOLID:
188 mxBgBitmapLB->hide();
189 mxBgGradientLB->hide();
190 mxBgHatchingLB->hide();
191 mxBgColorLB->show();
192 const Color aColor = GetColorSetOrDefault();
193 mxBgColorLB->SelectEntry(aColor);
195 break;
196 case GRADIENT:
198 mxBgBitmapLB->hide();
199 mxBgHatchingLB->hide();
200 mxBgColorLB->show();
201 mxBgGradientLB->show();
203 const XGradient xGradient = GetGradientSetOrDefault();
204 const Color aStartColor = xGradient.GetStartColor();
205 mxBgColorLB->SelectEntry(aStartColor);
206 const Color aEndColor = xGradient.GetEndColor();
207 mxBgGradientLB->SelectEntry(aEndColor);
209 break;
211 case HATCH:
213 mxBgColorLB->hide();
214 mxBgGradientLB->hide();
215 mxBgBitmapLB->hide();
216 mxBgHatchingLB->show();
217 mxBgHatchingLB->clear();
218 SvxFillAttrBox::Fill(*mxBgHatchingLB, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
220 const OUString aHatchName = GetHatchingSetOrDefault();
221 mxBgHatchingLB->set_active_text( aHatchName );
223 break;
225 case BITMAP:
226 case PATTERN:
228 mxBgColorLB->hide();
229 mxBgGradientLB->hide();
230 mxBgHatchingLB->hide();
231 mxBgBitmapLB->show();
232 mxBgBitmapLB->clear();
233 OUString aBitmapName;
235 if( eXFS == BITMAP )
237 SvxFillAttrBox::Fill(*mxBgBitmapLB, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
238 aBitmapName = GetBitmapSetOrDefault();
240 else
242 SvxFillAttrBox::Fill(*mxBgBitmapLB, pSh->GetItem(SID_PATTERN_LIST)->GetPatternList());
243 aBitmapName = GetPatternSetOrDefault();
246 mxBgBitmapLB->set_active_text( aBitmapName );
248 break;
250 default:
251 break;
254 // Need to do a relayouting, otherwise the panel size is not updated after show / hide controls
255 sfx2::sidebar::Panel* pPanel = dynamic_cast<sfx2::sidebar::Panel*>(GetParent());
256 if (pPanel)
257 pPanel->TriggerDeckLayouting();
260 Color const & PageStylesPanel::GetColorSetOrDefault()
262 if ( !mpBgColorItem )
263 mpBgColorItem.reset( new XFillColorItem( OUString(), Color(0x72, 0x9f, 0xcf) ) );
265 return mpBgColorItem->GetColorValue();
268 XGradient const & PageStylesPanel::GetGradientSetOrDefault()
270 if( !mpBgGradientItem )
272 SfxObjectShell* pSh = SfxObjectShell::Current();
273 const SvxGradientListItem * pGradListItem = pSh->GetItem(SID_GRADIENT_LIST);
274 const XGradient aGradient = pGradListItem->GetGradientList()->GetGradient(0)->GetGradient();
275 const OUString aGradientName = pGradListItem->GetGradientList()->GetGradient(0)->GetName();
277 mpBgGradientItem.reset( new XFillGradientItem( aGradientName, aGradient ) );
280 return mpBgGradientItem->GetGradientValue();
283 OUString const & PageStylesPanel::GetHatchingSetOrDefault()
285 if( !mpBgHatchItem )
287 SfxObjectShell* pSh = SfxObjectShell::Current();
288 const SvxHatchListItem * pHatchListItem = pSh->GetItem(SID_HATCH_LIST);
289 const XHatch aHatch = pHatchListItem->GetHatchList()->GetHatch(0)->GetHatch();
290 const OUString aHatchName = pHatchListItem->GetHatchList()->GetHatch(0)->GetName();
292 mpBgHatchItem.reset( new XFillHatchItem( aHatchName, aHatch ) );
295 return mpBgHatchItem->GetName();
298 OUString const & PageStylesPanel::GetBitmapSetOrDefault()
300 if( !mpBgBitmapItem || mpBgBitmapItem->isPattern() )
302 SfxObjectShell* pSh = SfxObjectShell::Current();
303 const SvxBitmapListItem * pBmpListItem = pSh->GetItem(SID_BITMAP_LIST);
304 const GraphicObject aGraphObj = pBmpListItem->GetBitmapList()->GetBitmap(0)->GetGraphicObject();
305 const OUString aBmpName = pBmpListItem->GetBitmapList()->GetBitmap(0)->GetName();
307 mpBgBitmapItem.reset( new XFillBitmapItem( aBmpName, aGraphObj ) );
310 return mpBgBitmapItem->GetName();
313 OUString const & PageStylesPanel::GetPatternSetOrDefault()
315 if( !mpBgBitmapItem || !mpBgBitmapItem->isPattern() )
317 SfxObjectShell* pSh = SfxObjectShell::Current();
318 const SvxPatternListItem * pPatternListItem = pSh->GetItem(SID_PATTERN_LIST);
319 const GraphicObject aGraphObj = pPatternListItem->GetPatternList()->GetBitmap(0)->GetGraphicObject();
320 const OUString aPatternName = pPatternListItem->GetPatternList()->GetBitmap(0)->GetName();
322 mpBgBitmapItem.reset( new XFillBitmapItem( aPatternName, aGraphObj ) );
325 return mpBgBitmapItem->GetName();
328 void PageStylesPanel::NotifyItemUpdate(
329 const sal_uInt16 nSid,
330 const SfxItemState eState,
331 const SfxPoolItem* pState)
333 if(IsDisposed())
334 return;
336 switch(nSid)
338 case SID_ATTR_PAGE_COLUMN:
340 if ( eState >= SfxItemState::DEFAULT &&
341 dynamic_cast< const SfxInt16Item *>( pState ) )
343 mpPageColumnItem.reset( static_cast<SfxInt16Item*>(pState->Clone()) );
344 if(mpPageColumnItem->GetValue() <= 5)
346 mxColumnCount->set_active(mpPageColumnItem->GetValue() - 1);
347 int nIndex = mxColumnCount->find_text(aCustomEntry);
348 if (nIndex != -1)
349 mxColumnCount->remove(nIndex);
351 else
353 if (mxColumnCount->find_text(aCustomEntry) == -1)
354 mxColumnCount->append_text(aCustomEntry);
355 mxColumnCount->set_active_text(aCustomEntry);
359 break;
361 case SID_ATTR_PAGE:
363 if( eState >= SfxItemState::DEFAULT &&
364 dynamic_cast< const SvxPageItem*>( pState ) )
366 mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) );
367 SvxNumType eNumType = mpPageItem->GetNumType();
368 mxNumberSelectLB->set_active_id(eNumType);
370 SvxPageUsage nUse = mpPageItem->GetPageUsage();
371 mxLayoutSelectLB->set_active( PageUsageToPos_Impl( nUse ) );
374 break;
376 case SID_ATTR_PAGE_COLOR:
378 if(eState >= SfxItemState::DEFAULT)
380 mxBgFillType->set_active( static_cast<sal_Int32>(SOLID) );
381 mpBgColorItem.reset(pState ? static_cast< XFillColorItem* >(pState->Clone()) : nullptr);
382 Update();
385 break;
387 case SID_ATTR_PAGE_HATCH:
389 if(eState >= SfxItemState::DEFAULT)
391 mxBgFillType->set_active( static_cast<sal_Int32>(HATCH) );
392 mpBgHatchItem.reset(pState ? static_cast < XFillHatchItem* >(pState->Clone()) : nullptr);
393 Update();
396 break;
398 case SID_ATTR_PAGE_GRADIENT:
400 if(eState >= SfxItemState::DEFAULT)
402 mxBgFillType->set_active( static_cast<sal_Int32>(GRADIENT) );
403 mpBgGradientItem.reset(pState ? static_cast< XFillGradientItem* >(pState->Clone()) : nullptr);
404 Update();
407 break;
408 case SID_ATTR_PAGE_BITMAP:
410 if(eState >= SfxItemState::DEFAULT)
412 mpBgBitmapItem.reset(pState ? static_cast< XFillBitmapItem* >(pState->Clone()) : nullptr);
413 if (mpBgBitmapItem)
415 if (mpBgBitmapItem->isPattern())
416 mxBgFillType->set_active( static_cast<sal_Int32>(PATTERN) );
417 else
418 mxBgFillType->set_active( static_cast<sal_Int32>(BITMAP) );
420 Update();
423 break;
425 case SID_ATTR_PAGE_FILLSTYLE:
427 const XFillStyleItem* pFillStyleItem = nullptr;
428 if (eState >= SfxItemState::DEFAULT)
429 pFillStyleItem = dynamic_cast< const XFillStyleItem* >(pState);
430 if (pFillStyleItem)
432 css::drawing::FillStyle eXFS = pFillStyleItem->GetValue();
433 switch(eXFS)
435 case drawing::FillStyle_NONE:
436 mxBgFillType->set_active( static_cast<sal_Int32>(NONE) );
437 break;
438 case drawing::FillStyle_SOLID:
439 mxBgFillType->set_active( static_cast<sal_Int32>(SOLID) );
440 break;
441 case drawing::FillStyle_GRADIENT:
442 mxBgFillType->set_active( static_cast<sal_Int32>(GRADIENT) );
443 break;
444 case drawing::FillStyle_HATCH:
445 mxBgFillType->set_active( static_cast<sal_Int32>(HATCH) );
446 break;
447 case drawing::FillStyle_BITMAP:
448 if (mpBgBitmapItem->isPattern())
449 mxBgFillType->set_active( static_cast<sal_Int32>(PATTERN) );
450 else
451 mxBgFillType->set_active( static_cast<sal_Int32>(BITMAP) );
452 break;
453 default:
454 break;
456 Update();
459 break;
461 default:
462 break;
466 IMPL_LINK_NOARG( PageStylesPanel, ModifyColumnCountHdl, weld::ComboBox&, void )
468 sal_uInt16 nColumnType = mxColumnCount->get_active() + 1;
469 mpPageColumnItem->SetValue( nColumnType );
470 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLUMN,
471 SfxCallMode::RECORD, { mpPageColumnItem.get() });
474 IMPL_LINK_NOARG( PageStylesPanel, ModifyNumberingHdl, weld::ComboBox&, void )
476 SvxNumType nEntryData = mxNumberSelectLB->get_active_id();
477 mpPageItem->SetNumType(nEntryData);
478 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE, SfxCallMode::RECORD, { mpPageItem.get() });
481 IMPL_LINK_NOARG( PageStylesPanel, ModifyLayoutHdl, weld::ComboBox&, void )
483 sal_uInt16 nUse = mxLayoutSelectLB->get_active();
484 mpPageItem->SetPageUsage(PosToPageUsage_Impl(nUse));
485 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE, SfxCallMode::RECORD, { mpPageItem.get() });
488 IMPL_LINK_NOARG(PageStylesPanel, ModifyFillStyleHdl, weld::ComboBox&, void)
490 const eFillStyle eXFS = static_cast<eFillStyle>(mxBgFillType->get_active());
491 Update();
493 switch (eXFS)
495 case NONE:
497 const XFillStyleItem aXFillStyleItem(drawing::FillStyle_NONE);
498 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_FILLSTYLE, SfxCallMode::RECORD, { &aXFillStyleItem });
500 break;
502 case SOLID:
504 XFillColorItem aItem( OUString(), mpBgColorItem->GetColorValue() );
505 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLOR, SfxCallMode::RECORD, { &aItem });
507 break;
509 case GRADIENT:
511 XFillGradientItem aItem( mpBgGradientItem->GetName(), mpBgGradientItem->GetGradientValue() );
512 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_GRADIENT, SfxCallMode::RECORD, { &aItem });
514 break;
516 case HATCH:
518 XFillHatchItem aItem( mpBgHatchItem->GetName(), mpBgHatchItem->GetHatchValue() );
519 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_HATCH, SfxCallMode::RECORD, { &aItem });
521 break;
523 case BITMAP:
524 case PATTERN:
526 XFillBitmapItem aItem( mpBgBitmapItem->GetName(), mpBgBitmapItem->GetGraphicObject() );
527 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_BITMAP, SfxCallMode::RECORD, { &aItem });
529 break;
531 default:
532 break;
536 void PageStylesPanel::ModifyFillColor()
538 const eFillStyle eXFS = static_cast<eFillStyle>(mxBgFillType->get_active());
539 SfxObjectShell* pSh = SfxObjectShell::Current();
540 switch(eXFS)
542 case SOLID:
544 XFillColorItem aItem(OUString(), mxBgColorLB->GetSelectEntryColor());
545 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLOR, SfxCallMode::RECORD, { &aItem });
547 break;
548 case GRADIENT:
550 XGradient aGradient;
551 aGradient.SetStartColor(mxBgColorLB->GetSelectEntryColor());
552 aGradient.SetEndColor(mxBgGradientLB->GetSelectEntryColor());
554 XFillGradientItem aItem(aGradient);
555 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_GRADIENT, SfxCallMode::RECORD, { &aItem });
557 break;
558 case HATCH:
560 const SvxHatchListItem * pHatchListItem = pSh->GetItem(SID_HATCH_LIST);
561 sal_uInt16 nPos = mxBgHatchingLB->get_active();
562 XHatch aHatch = pHatchListItem->GetHatchList()->GetHatch(nPos)->GetHatch();
563 const OUString aHatchName = pHatchListItem->GetHatchList()->GetHatch(nPos)->GetName();
565 XFillHatchItem aItem(aHatchName, aHatch);
566 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_HATCH, SfxCallMode::RECORD, { &aItem });
568 break;
569 case BITMAP:
570 case PATTERN:
572 sal_Int16 nPos = mxBgBitmapLB->get_active();
573 GraphicObject aBitmap;
574 OUString aBitmapName;
576 if ( eXFS == BITMAP )
578 SvxBitmapListItem const * pBitmapListItem = pSh->GetItem(SID_BITMAP_LIST);
579 aBitmap = pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetGraphicObject();
580 aBitmapName = pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetName();
582 else
584 SvxPatternListItem const * pPatternListItem = pSh->GetItem(SID_PATTERN_LIST);
585 aBitmap = pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetGraphicObject();
586 aBitmapName = pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetName();
589 XFillBitmapItem aItem(aBitmapName, aBitmap);
590 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_BITMAP, SfxCallMode::RECORD, { &aItem });
592 break;
593 default:
594 break;
598 IMPL_LINK_NOARG(PageStylesPanel, ModifyFillColorHdl, weld::ComboBox&, void)
600 ModifyFillColor();
603 IMPL_LINK_NOARG(PageStylesPanel, ModifyFillColorListHdl, ColorListBox&, void)
605 ModifyFillColor();
610 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */