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 .
20 #include <svl/intitem.hxx>
21 #include <vcl/svapp.hxx>
22 #include <osl/diagnose.h>
24 #include <sfx2/bindings.hxx>
25 #include <sfx2/tplpitem.hxx>
26 #include <sfx2/sfxsids.hrc>
27 #include <tplcitem.hxx>
28 #include <templdgi.hxx>
32 SfxTemplateControllerItem::SfxTemplateControllerItem(
33 sal_uInt16 nSlotId
, // ID
34 SfxCommonTemplateDialog_Impl
&rDlg
, // Controller-Instance,
35 // which is assigned to this item.
36 SfxBindings
&rBindings
):
37 SfxControllerItem(nSlotId
, rBindings
),
44 SfxTemplateControllerItem::~SfxTemplateControllerItem()
47 Application::RemoveUserEvent(nUserEventId
);
51 // Notice about change of status, is propagated through the Controller
52 // passed on by the constructor
54 void SfxTemplateControllerItem::StateChangedAtToolBoxControl( sal_uInt16 nSID
, SfxItemState eState
,
55 const SfxPoolItem
* pItem
)
59 case SID_STYLE_FAMILY1
:
60 case SID_STYLE_FAMILY2
:
61 case SID_STYLE_FAMILY3
:
62 case SID_STYLE_FAMILY4
:
63 case SID_STYLE_FAMILY5
:
64 case SID_STYLE_FAMILY6
:
66 bool bAvailable
= SfxItemState::DEFAULT
== eState
;
68 rTemplateDlg
.SetFamilyState(GetId(), nullptr);
70 const SfxTemplateItem
*pStateItem
= dynamic_cast< const SfxTemplateItem
* >(pItem
);
71 DBG_ASSERT(pStateItem
!= nullptr, "SfxTemplateItem expected");
72 rTemplateDlg
.SetFamilyState( GetId(), pStateItem
);
74 bool bDisable
= eState
== SfxItemState::DISABLED
;
76 sal_uInt16 nFamily
= 0;
79 case SID_STYLE_FAMILY1
:
81 case SID_STYLE_FAMILY2
:
83 case SID_STYLE_FAMILY3
:
85 case SID_STYLE_FAMILY4
:
87 case SID_STYLE_FAMILY5
:
89 case SID_STYLE_FAMILY6
:
92 default: OSL_FAIL("unknown StyleFamily"); break;
94 rTemplateDlg
.EnableFamilyItem( nFamily
, !bDisable
);
97 case SID_STYLE_WATERCAN
:
99 if ( eState
== SfxItemState::DISABLED
)
100 nWaterCanState
= 0xff;
101 else if( eState
== SfxItemState::DEFAULT
)
103 const SfxBoolItem
& rStateItem
= dynamic_cast<const SfxBoolItem
&>(*pItem
);
104 nWaterCanState
= rStateItem
.GetValue() ? 1 : 0;
106 //not necessary if the last event is still on the way
108 nUserEventId
= Application::PostUserEvent( LINK(
109 this, SfxTemplateControllerItem
, SetWaterCanStateHdl_Impl
) );
113 rTemplateDlg
.EnableEdit( SfxItemState::DISABLED
!= eState
, nullptr );
115 case SID_STYLE_DELETE
:
116 rTemplateDlg
.EnableDel( SfxItemState::DISABLED
!= eState
, nullptr );
119 rTemplateDlg
.EnableHide( SfxItemState::DISABLED
!= eState
, nullptr );
122 rTemplateDlg
.EnableShow( SfxItemState::DISABLED
!= eState
, nullptr );
124 case SID_STYLE_NEW_BY_EXAMPLE
:
126 rTemplateDlg
.EnableExample_Impl(nSID
, SfxItemState::DISABLED
!= eState
);
128 case SID_STYLE_UPDATE_BY_EXAMPLE
:
130 rTemplateDlg
.EnableExample_Impl(nSID
, eState
!= SfxItemState::DISABLED
);
135 rTemplateDlg
.EnableNew( SfxItemState::DISABLED
!= eState
, nullptr );
138 case SID_STYLE_DRAGHIERARCHIE
:
140 rTemplateDlg
.EnableTreeDrag( SfxItemState::DISABLED
!= eState
);
143 case SID_STYLE_FAMILY
:
145 const SfxUInt16Item
*pStateItem
= dynamic_cast< const SfxUInt16Item
* >(pItem
);
148 rTemplateDlg
.SetFamily(static_cast<SfxStyleFamily
>(pStateItem
->GetValue()));
155 IMPL_LINK_NOARG(SfxTemplateControllerItem
, SetWaterCanStateHdl_Impl
, void*, void)
157 nUserEventId
= nullptr;
158 std::unique_ptr
<SfxBoolItem
> pState
;
159 switch(nWaterCanState
)
163 pState
.reset(new SfxBoolItem(SID_STYLE_WATERCAN
, nWaterCanState
!= 0));
166 rTemplateDlg
.SetWaterCanState(pState
.get());
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */