sd: keep a non-owning pointer to the OverridingShell
[LibreOffice.git] / sfx2 / source / dialog / tplcitem.cxx
blobc86aabcd7c541a278a2f115b97d2d2939a71e426
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 #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>
30 // Constructor
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),
38 rTemplateDlg(rDlg),
39 nWaterCanState(0xff),
40 nUserEventId(nullptr)
44 SfxTemplateControllerItem::~SfxTemplateControllerItem()
46 if(nUserEventId)
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 )
57 switch(nSID)
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;
67 if ( !bAvailable )
68 rTemplateDlg.SetFamilyState(GetId(), nullptr);
69 else {
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;
75 // Disable Family
76 sal_uInt16 nFamily = 0;
77 switch( GetId())
79 case SID_STYLE_FAMILY1:
80 nFamily = 1; break;
81 case SID_STYLE_FAMILY2:
82 nFamily = 2; break;
83 case SID_STYLE_FAMILY3:
84 nFamily = 3; break;
85 case SID_STYLE_FAMILY4:
86 nFamily = 4; break;
87 case SID_STYLE_FAMILY5:
88 nFamily = 5; break;
89 case SID_STYLE_FAMILY6:
90 nFamily = 6; break;
92 default: OSL_FAIL("unknown StyleFamily"); break;
94 rTemplateDlg.EnableFamilyItem( nFamily, !bDisable );
95 break;
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
107 if(!nUserEventId)
108 nUserEventId = Application::PostUserEvent( LINK(
109 this, SfxTemplateControllerItem, SetWaterCanStateHdl_Impl ) );
110 break;
112 case SID_STYLE_EDIT:
113 rTemplateDlg.EnableEdit( SfxItemState::DISABLED != eState, nullptr );
114 break;
115 case SID_STYLE_DELETE:
116 rTemplateDlg.EnableDel( SfxItemState::DISABLED != eState, nullptr );
117 break;
118 case SID_STYLE_HIDE:
119 rTemplateDlg.EnableHide( SfxItemState::DISABLED != eState, nullptr );
120 break;
121 case SID_STYLE_SHOW:
122 rTemplateDlg.EnableShow( SfxItemState::DISABLED != eState, nullptr );
123 break;
124 case SID_STYLE_NEW_BY_EXAMPLE:
126 rTemplateDlg.EnableExample_Impl(nSID, SfxItemState::DISABLED != eState);
127 break;
128 case SID_STYLE_UPDATE_BY_EXAMPLE:
130 rTemplateDlg.EnableExample_Impl(nSID, eState != SfxItemState::DISABLED);
131 break;
133 case SID_STYLE_NEW:
135 rTemplateDlg.EnableNew( SfxItemState::DISABLED != eState, nullptr );
136 break;
138 case SID_STYLE_DRAGHIERARCHIE:
140 rTemplateDlg.EnableTreeDrag( SfxItemState::DISABLED != eState );
141 break;
143 case SID_STYLE_FAMILY :
145 const SfxUInt16Item *pStateItem = dynamic_cast< const SfxUInt16Item* >(pItem);
146 if (pStateItem)
148 rTemplateDlg.SetFamily(static_cast<SfxStyleFamily>(pStateItem->GetValue()));
150 break;
155 IMPL_LINK_NOARG(SfxTemplateControllerItem, SetWaterCanStateHdl_Impl, void*, void)
157 nUserEventId = nullptr;
158 std::unique_ptr<SfxBoolItem> pState;
159 switch(nWaterCanState)
161 case 0 :
162 case 1 :
163 pState.reset(new SfxBoolItem(SID_STYLE_WATERCAN, nWaterCanState != 0));
164 break;
166 rTemplateDlg.SetWaterCanState(pState.get());
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */