1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <swtypes.hxx>
21 #include <svl/intitem.hxx>
22 #include <editeng/sizeitem.hxx>
23 #include <editeng/paperinf.hxx>
24 #include <svx/svxids.hrc>
25 #include <svx/colorbox.hxx>
26 #include <svx/dlgutil.hxx>
27 #include <svx/rulritem.hxx>
28 #include "svx/drawitem.hxx"
29 #include <svx/SvxNumOptionsTabPageHelper.hxx>
30 #include "PageStylesPanel.hxx"
31 #include <sfx2/sidebar/ControlFactory.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/viewsh.hxx>
35 #include <sfx2/objsh.hxx>
38 using namespace ::com::sun::star
;
40 namespace sw
{ namespace sidebar
{
52 const SvxPageUsage aArr
[] =
61 sal_uInt16
PageUsageToPos_Impl( SvxPageUsage nUsage
)
63 for ( sal_uInt16 i
= 0; i
< SAL_N_ELEMENTS(aArr
); ++i
)
64 if ( aArr
[i
] == nUsage
)
70 SvxPageUsage
PosToPageUsage_Impl( sal_uInt16 nPos
)
72 if ( nPos
>= SAL_N_ELEMENTS(aArr
) )
73 return SvxPageUsage::NONE
;
77 VclPtr
<vcl::Window
> PageStylesPanel::Create(
79 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rxFrame
,
80 SfxBindings
* pBindings
)
82 if( pParent
== nullptr )
83 throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageStylesPanel::Create", nullptr, 0);
85 throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageStylesPanel::Create", nullptr, 0);
86 if( pBindings
== nullptr )
87 throw ::com::sun::star::lang::IllegalArgumentException("no SfxBindings given to PageStylesPanel::Create", nullptr, 0);
89 return VclPtr
<PageStylesPanel
>::Create(pParent
, rxFrame
, pBindings
);
92 PageStylesPanel::PageStylesPanel(
94 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rxFrame
,
95 SfxBindings
* pBindings
97 PanelLayout(pParent
, "PageStylesPanel", "modules/swriter/ui/pagestylespanel.ui", rxFrame
),
98 mpBindings( pBindings
),
99 mpPageColumnItem( new SfxInt16Item(SID_ATTR_PAGE_COLUMN
) ),
100 mpPageItem( new SvxPageItem(SID_ATTR_PAGE
) ),
101 maPageColumnControl(SID_ATTR_PAGE_COLUMN
, *pBindings
, *this),
102 maPageNumFormatControl( SID_ATTR_PAGE
, *pBindings
, *this ),
103 maBgColorControl( SID_ATTR_PAGE_COLOR
, *pBindings
, *this ),
104 maBgHatchingControl( SID_ATTR_PAGE_HATCH
, *pBindings
, *this ),
105 maBgGradientControl( SID_ATTR_PAGE_GRADIENT
, *pBindings
, *this ),
106 maBgBitmapControl( SID_ATTR_PAGE_BITMAP
, *pBindings
, *this ),
107 maBgFillStyleControl(SID_ATTR_PAGE_FILLSTYLE
, *pBindings
, *this),
110 get(mpColumnCount
, "columnbox");
111 get(mpNumberSelectLB
, "numberbox");
112 get(mpBgFillType
, "bgselect");
113 get(mpBgColorLB
, "lbcolor");
114 get(mpBgHatchingLB
, "lbhatching");
115 get(mpBgGradientLB
, "lbgradient");
116 get(mpBgBitmapLB
, "lbbitmap");
117 get(mpLayoutSelectLB
, "layoutbox");
118 get(mpCustomEntry
, "customlabel");
123 PageStylesPanel::~PageStylesPanel()
128 void PageStylesPanel::dispose()
130 mpColumnCount
.disposeAndClear();
131 mpNumberSelectLB
.disposeAndClear();
132 mpBgFillType
.disposeAndClear();
133 mpBgColorLB
.disposeAndClear();
134 mpBgHatchingLB
.disposeAndClear();
135 mpBgGradientLB
.disposeAndClear();
136 mpBgBitmapLB
.disposeAndClear();
137 mpLayoutSelectLB
.disposeAndClear();
139 maBgBitmapControl
.dispose();
140 maBgColorControl
.dispose();
141 maBgFillStyleControl
.dispose();
142 maBgGradientControl
.dispose();
143 maBgHatchingControl
.dispose();
144 maPageColumnControl
.dispose();
145 maPageNumFormatControl
.dispose();
146 mpCustomEntry
.clear();
147 PanelLayout::dispose();
150 void PageStylesPanel::Initialize()
152 aCustomEntry
= mpCustomEntry
->GetText();
153 mpBindings
->Invalidate(SID_ATTR_PAGE_COLUMN
);
154 mpBindings
->Invalidate(SID_ATTR_PAGE
);
155 mpBindings
->Invalidate(SID_ATTR_PAGE_FILLSTYLE
);
158 mpColumnCount
->SetSelectHdl( LINK(this, PageStylesPanel
, ModifyColumnCountHdl
) );
159 SvxNumOptionsTabPageHelper::GetI18nNumbering( *mpNumberSelectLB
, ::std::numeric_limits
<sal_uInt16
>::max());
160 mpNumberSelectLB
->SetSelectHdl( LINK(this, PageStylesPanel
, ModifyNumberingHdl
) );
161 mpLayoutSelectLB
->SetSelectHdl( LINK(this, PageStylesPanel
, ModifyLayoutHdl
) );
162 mpBgFillType
->SetSelectHdl( LINK(this, PageStylesPanel
, ModifyFillStyleHdl
));
163 mpBgColorLB
->SetSelectHdl( LINK(this, PageStylesPanel
, ModifyFillColorListHdl
));
164 mpBgGradientLB
->SetSelectHdl( LINK(this, PageStylesPanel
, ModifyFillColorListHdl
));
165 mpBgHatchingLB
->SetSelectHdl( LINK(this, PageStylesPanel
, ModifyFillColorHdl
));
166 mpBgBitmapLB
->SetSelectHdl( LINK(this, PageStylesPanel
, ModifyFillColorHdl
));
169 void PageStylesPanel::Update()
171 const eFillStyle eXFS
= (eFillStyle
)mpBgFillType
->GetSelectEntryPos();
172 SfxObjectShell
* pSh
= SfxObjectShell::Current();
178 mpBgHatchingLB
->Hide();
179 mpBgGradientLB
->Hide();
180 mpBgBitmapLB
->Hide();
185 mpBgBitmapLB
->Hide();
186 mpBgGradientLB
->Hide();
187 mpBgHatchingLB
->Hide();
189 const Color aColor
= GetColorSetOrDefault();
190 mpBgColorLB
->SelectEntry(aColor
);
195 mpBgBitmapLB
->Hide();
196 mpBgHatchingLB
->Hide();
198 mpBgGradientLB
->Show();
200 const XGradient xGradient
= GetGradientSetOrDefault();
201 const Color aStartColor
= xGradient
.GetStartColor();
202 mpBgColorLB
->SelectEntry(aStartColor
);
203 const Color aEndColor
= xGradient
.GetEndColor();
204 mpBgGradientLB
->SelectEntry(aEndColor
);
211 mpBgGradientLB
->Hide();
212 mpBgBitmapLB
->Hide();
213 const SvxHatchListItem
aItem(*static_cast<const SvxHatchListItem
*>(pSh
->GetItem(SID_HATCH_LIST
)));
214 mpBgHatchingLB
->Show();
215 mpBgHatchingLB
->Clear();
216 mpBgHatchingLB
->Fill(aItem
.GetHatchList());
218 const OUString aHatchName
= GetHatchingSetOrDefault();
219 mpBgHatchingLB
->SelectEntry( aHatchName
);
227 mpBgGradientLB
->Hide();
228 mpBgHatchingLB
->Hide();
229 mpBgBitmapLB
->Show();
230 mpBgBitmapLB
->Clear();
231 OUString aBitmapName
;
235 const SvxBitmapListItem
aItem(*static_cast<const SvxBitmapListItem
*>(pSh
->GetItem(SID_BITMAP_LIST
)));
236 mpBgBitmapLB
->Fill(aItem
.GetBitmapList());
237 aBitmapName
= GetBitmapSetOrDefault();
241 const SvxPatternListItem
aItem(*static_cast<const SvxPatternListItem
*>(pSh
->GetItem(SID_PATTERN_LIST
)));
242 mpBgBitmapLB
->Fill(aItem
.GetPatternList());
243 aBitmapName
= GetPatternSetOrDefault();
246 mpBgBitmapLB
->SelectEntry( aBitmapName
);
255 Color
PageStylesPanel::GetColorSetOrDefault()
257 if ( !mpBgColorItem
)
258 mpBgColorItem
.reset( new XFillColorItem( OUString(), Color(0x72, 0x9f, 0xcf) ) );
260 return mpBgColorItem
->GetColorValue();
263 XGradient
PageStylesPanel::GetGradientSetOrDefault()
265 if( !mpBgGradientItem
)
267 SfxObjectShell
* pSh
= SfxObjectShell::Current();
268 const SvxGradientListItem
aGradListItem(*static_cast<const SvxGradientListItem
*>(pSh
->GetItem(SID_GRADIENT_LIST
)));
269 const XGradient aGradient
= aGradListItem
.GetGradientList()->GetGradient(0)->GetGradient();
270 const OUString aGradientName
= aGradListItem
.GetGradientList()->GetGradient(0)->GetName();
272 mpBgGradientItem
.reset( new XFillGradientItem( aGradientName
, aGradient
) );
275 return mpBgGradientItem
->GetGradientValue();
278 const OUString
PageStylesPanel::GetHatchingSetOrDefault()
282 SfxObjectShell
* pSh
= SfxObjectShell::Current();
283 const SvxHatchListItem
aHatchListItem(*static_cast<const SvxHatchListItem
*>(pSh
->GetItem(SID_HATCH_LIST
)));
284 const XHatch aHatch
= aHatchListItem
.GetHatchList()->GetHatch(0)->GetHatch();
285 const OUString aHatchName
= aHatchListItem
.GetHatchList()->GetHatch(0)->GetName();
287 mpBgHatchItem
.reset( new XFillHatchItem( aHatchName
, aHatch
) );
290 return mpBgHatchItem
->GetName();
293 const OUString
PageStylesPanel::GetBitmapSetOrDefault()
295 if( !mpBgBitmapItem
|| mpBgBitmapItem
->isPattern() )
297 SfxObjectShell
* pSh
= SfxObjectShell::Current();
298 const SvxBitmapListItem
aBmpListItem(*static_cast<const SvxBitmapListItem
*>(pSh
->GetItem(SID_BITMAP_LIST
)));
299 const GraphicObject aGraphObj
= aBmpListItem
.GetBitmapList()->GetBitmap(0)->GetGraphicObject();
300 const OUString aBmpName
= aBmpListItem
.GetBitmapList()->GetBitmap(0)->GetName();
302 mpBgBitmapItem
.reset( new XFillBitmapItem( aBmpName
, aGraphObj
) );
305 return mpBgBitmapItem
->GetName();
308 const OUString
PageStylesPanel::GetPatternSetOrDefault()
310 if( !mpBgBitmapItem
|| !mpBgBitmapItem
->isPattern() )
312 SfxObjectShell
* pSh
= SfxObjectShell::Current();
313 const SvxPatternListItem
aPatternListItem(*static_cast<const SvxPatternListItem
*>(pSh
->GetItem(SID_PATTERN_LIST
)));
314 const GraphicObject aGraphObj
= aPatternListItem
.GetPatternList()->GetBitmap(0)->GetGraphicObject();
315 const OUString aPatternName
= aPatternListItem
.GetPatternList()->GetBitmap(0)->GetName();
317 mpBgBitmapItem
.reset( new XFillBitmapItem( aPatternName
, aGraphObj
) );
320 return mpBgBitmapItem
->GetName();
323 void PageStylesPanel::NotifyItemUpdate(
324 const sal_uInt16 nSid
,
325 const SfxItemState eState
,
326 const SfxPoolItem
* pState
,
327 const bool bIsEnabled
)
336 case SID_ATTR_PAGE_COLUMN
:
338 if ( eState
>= SfxItemState::DEFAULT
&&
339 pState
&& dynamic_cast< const SfxInt16Item
*>( pState
) != nullptr )
341 mpPageColumnItem
.reset( static_cast<SfxInt16Item
*>(pState
->Clone()) );
342 if(mpPageColumnItem
->GetValue() <= 5)
344 mpColumnCount
->SelectEntryPos(mpPageColumnItem
->GetValue() - 1);
345 mpColumnCount
->RemoveEntry(aCustomEntry
);
349 if(mpColumnCount
->GetEntryPos(aCustomEntry
) == LISTBOX_ENTRY_NOTFOUND
)
350 mpColumnCount
->InsertEntry(aCustomEntry
);
351 mpColumnCount
->SelectEntry(aCustomEntry
);
359 if( eState
>= SfxItemState::DEFAULT
&&
360 pState
&& dynamic_cast< const SvxPageItem
*>( pState
) != nullptr )
362 mpPageItem
.reset( static_cast<SvxPageItem
*>(pState
->Clone()) );
363 SvxNumType eNumType
= mpPageItem
->GetNumType();
364 mpNumberSelectLB
->SetSelection(eNumType
);
366 SvxPageUsage nUse
= mpPageItem
->GetPageUsage();
367 mpLayoutSelectLB
->SelectEntryPos( PageUsageToPos_Impl( nUse
) );
372 case SID_ATTR_PAGE_COLOR
:
374 if(eState
>= SfxItemState::DEFAULT
)
376 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(SOLID
) );
377 mpBgColorItem
.reset(pState
? static_cast< XFillColorItem
* >(pState
->Clone()) : nullptr);
383 case SID_ATTR_PAGE_HATCH
:
385 if(eState
>= SfxItemState::DEFAULT
)
387 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(HATCH
) );
388 mpBgHatchItem
.reset(pState
? static_cast < XFillHatchItem
* >(pState
->Clone()) : nullptr);
394 case SID_ATTR_PAGE_GRADIENT
:
396 if(eState
>= SfxItemState::DEFAULT
)
398 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(GRADIENT
) );
399 mpBgGradientItem
.reset(pState
? static_cast< XFillGradientItem
* >(pState
->Clone()) : nullptr);
404 case SID_ATTR_PAGE_BITMAP
:
406 if(eState
>= SfxItemState::DEFAULT
)
408 mpBgBitmapItem
.reset(pState
? static_cast< XFillBitmapItem
* >(pState
->Clone()) : nullptr);
411 if (mpBgBitmapItem
->isPattern())
412 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(PATTERN
) );
414 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(BITMAP
) );
421 case SID_ATTR_PAGE_FILLSTYLE
:
423 const XFillStyleItem
* pFillStyleItem
= nullptr;
424 if (eState
>= SfxItemState::DEFAULT
)
425 pFillStyleItem
= dynamic_cast< const XFillStyleItem
* >(pState
);
428 css::drawing::FillStyle eXFS
= pFillStyleItem
->GetValue();
431 case drawing::FillStyle_NONE
:
432 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(NONE
) );
434 case drawing::FillStyle_SOLID
:
435 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(SOLID
) );
437 case drawing::FillStyle_GRADIENT
:
438 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(GRADIENT
) );
440 case drawing::FillStyle_HATCH
:
441 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(HATCH
) );
443 case drawing::FillStyle_BITMAP
:
444 if (mpBgBitmapItem
->isPattern())
445 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(PATTERN
) );
447 mpBgFillType
->SelectEntryPos( static_cast<sal_Int32
>(BITMAP
) );
462 IMPL_LINK_NOARG( PageStylesPanel
, ModifyColumnCountHdl
, ListBox
&, void )
464 sal_uInt16 nColumnType
= mpColumnCount
->GetSelectEntryPos() + 1;
465 mpPageColumnItem
->SetValue( nColumnType
);
466 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLUMN
,
467 SfxCallMode::RECORD
, { mpPageColumnItem
.get() });
470 IMPL_LINK_NOARG( PageStylesPanel
, ModifyNumberingHdl
, ListBox
&, void )
472 SvxNumType nEntryData
= static_cast<SvxNumType
>(reinterpret_cast<sal_uLong
>(mpNumberSelectLB
->GetEntryData(mpNumberSelectLB
->GetSelectEntryPos())));
473 mpPageItem
->SetNumType(nEntryData
);
474 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_PAGE
, SfxCallMode::RECORD
, { mpPageItem
.get() });
477 IMPL_LINK_NOARG( PageStylesPanel
, ModifyLayoutHdl
, ListBox
&, void )
479 sal_uInt16 nUse
= mpLayoutSelectLB
->GetSelectEntryPos();
480 mpPageItem
->SetPageUsage(PosToPageUsage_Impl(nUse
));
481 mpBindings
->GetDispatcher()->ExecuteList(SID_ATTR_PAGE
, SfxCallMode::RECORD
, { mpPageItem
.get() });
484 IMPL_LINK_NOARG(PageStylesPanel
, ModifyFillStyleHdl
, ListBox
&, void)
486 const eFillStyle eXFS
= (eFillStyle
)mpBgFillType
->GetSelectEntryPos();
493 const XFillStyleItem
aXFillStyleItem(drawing::FillStyle_NONE
);
494 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_FILLSTYLE
, SfxCallMode::RECORD
, { &aXFillStyleItem
});
500 XFillColorItem
aItem( OUString(), mpBgColorItem
->GetColorValue() );
501 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLOR
, SfxCallMode::RECORD
, { &aItem
});
507 XFillGradientItem
aItem( mpBgGradientItem
->GetName(), mpBgGradientItem
->GetGradientValue() );
508 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_GRADIENT
, SfxCallMode::RECORD
, { &aItem
});
514 XFillHatchItem
aItem( mpBgHatchItem
->GetName(), mpBgHatchItem
->GetHatchValue() );
515 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_HATCH
, SfxCallMode::RECORD
, { &aItem
});
522 XFillBitmapItem
aItem( mpBgBitmapItem
->GetName(), mpBgBitmapItem
->GetGraphicObject() );
523 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_BITMAP
, SfxCallMode::RECORD
, { &aItem
});
530 mpBgFillType
->Selected();
533 void PageStylesPanel::ModifyFillColor()
535 const eFillStyle eXFS
= (eFillStyle
)mpBgFillType
->GetSelectEntryPos();
536 SfxObjectShell
* pSh
= SfxObjectShell::Current();
541 XFillColorItem
aItem(OUString(), mpBgColorLB
->GetSelectEntryColor());
542 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_COLOR
, SfxCallMode::RECORD
, { &aItem
});
548 aGradient
.SetStartColor(mpBgColorLB
->GetSelectEntryColor());
549 aGradient
.SetEndColor(mpBgGradientLB
->GetSelectEntryColor());
551 XFillGradientItem
aItem(aGradient
);
552 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_GRADIENT
, SfxCallMode::RECORD
, { &aItem
});
557 const SvxHatchListItem
aHatchListItem(*static_cast<const SvxHatchListItem
*>(pSh
->GetItem(SID_HATCH_LIST
)));
558 sal_uInt16 nPos
= mpBgHatchingLB
->GetSelectEntryPos();
559 XHatch aHatch
= aHatchListItem
.GetHatchList()->GetHatch(nPos
)->GetHatch();
560 const OUString aHatchName
= aHatchListItem
.GetHatchList()->GetHatch(nPos
)->GetName();
562 XFillHatchItem
aItem(aHatchName
, aHatch
);
563 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_HATCH
, SfxCallMode::RECORD
, { &aItem
});
569 sal_Int16 nPos
= mpBgBitmapLB
->GetSelectEntryPos();
570 GraphicObject aBitmap
;
571 OUString aBitmapName
;
573 if ( eXFS
== BITMAP
)
575 SvxBitmapListItem
aBitmapListItem(*static_cast<const SvxBitmapListItem
*>(pSh
->GetItem(SID_BITMAP_LIST
)));
576 aBitmap
= aBitmapListItem
.GetBitmapList()->GetBitmap(nPos
)->GetGraphicObject();
577 aBitmapName
= aBitmapListItem
.GetBitmapList()->GetBitmap(nPos
)->GetName();
581 SvxPatternListItem
aPatternListItem(*static_cast<const SvxPatternListItem
*>(pSh
->GetItem(SID_PATTERN_LIST
)));
582 aBitmap
= aPatternListItem
.GetPatternList()->GetBitmap(nPos
)->GetGraphicObject();
583 aBitmapName
= aPatternListItem
.GetPatternList()->GetBitmap(nPos
)->GetName();
586 XFillBitmapItem
aItem(aBitmapName
, aBitmap
);
587 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_BITMAP
, SfxCallMode::RECORD
, { &aItem
});
595 IMPL_LINK_NOARG(PageStylesPanel
, ModifyFillColorHdl
, ListBox
&, void)
600 IMPL_LINK_NOARG(PageStylesPanel
, ModifyFillColorListHdl
, SvxColorListBox
&, void)
607 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */