bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / dialog / tplcitem.cxx
blob612166cfcf7b6e3d03fd3d1ff6aae52c628bb1b3
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>
23 #include <sfx2/templdlg.hxx>
24 #include <sfx2/bindings.hxx>
25 #include <sfx2/tplpitem.hxx>
26 #include "tplcitem.hxx"
27 #include "templdgi.hxx"
29 #include <sfx2/sfx.hrc>
30 #include "dialog.hrc"
32 // STATIC DATA -----------------------------------------------------------
34 // Constructor
36 SfxTemplateControllerItem::SfxTemplateControllerItem(
37 sal_uInt16 nSlotId, // ID
38 SfxCommonTemplateDialog_Impl &rDlg, // Controller-Instance,
39 // which is assigned to this item.
40 SfxBindings &rBindings):
41 SfxControllerItem(nSlotId, rBindings),
42 rTemplateDlg(rDlg),
43 nWaterCanState(0xff),
44 nUserEventId(0)
48 SfxTemplateControllerItem::~SfxTemplateControllerItem()
50 if(nUserEventId)
51 Application::RemoveUserEvent(nUserEventId);
55 // Notice about change of status, is propagated through the Controller
56 // passed on by the constructor
58 void SfxTemplateControllerItem::StateChanged( sal_uInt16 nSID, SfxItemState eState,
59 const SfxPoolItem* pItem )
61 switch(nSID)
63 case SID_STYLE_FAMILY1:
64 case SID_STYLE_FAMILY2:
65 case SID_STYLE_FAMILY3:
66 case SID_STYLE_FAMILY4:
67 case SID_STYLE_FAMILY5:
69 bool bAvailable = SfxItemState::DEFAULT == eState;
70 if ( !bAvailable )
71 rTemplateDlg.SetFamilyState(GetId(), 0);
72 else {
73 const SfxTemplateItem *pStateItem = PTR_CAST(
74 SfxTemplateItem, pItem);
75 DBG_ASSERT(pStateItem != 0, "SfxTemplateItem expected");
76 rTemplateDlg.SetFamilyState( GetId(), pStateItem );
78 bool bDisable = eState == SfxItemState::DISABLED;
79 // Disable Familly
80 sal_uInt16 nFamily = 0;
81 switch( GetId())
83 case SID_STYLE_FAMILY1:
84 nFamily = 1; break;
85 case SID_STYLE_FAMILY2:
86 nFamily = 2; break;
87 case SID_STYLE_FAMILY3:
88 nFamily = 3; break;
89 case SID_STYLE_FAMILY4:
90 nFamily = 4; break;
91 case SID_STYLE_FAMILY5:
92 nFamily = 5; break;
94 default: OSL_FAIL("unknown StyleFamily"); break;
96 rTemplateDlg.EnableFamilyItem( nFamily, !bDisable );
97 break;
99 case SID_STYLE_WATERCAN:
101 if ( eState == SfxItemState::DISABLED )
102 nWaterCanState = 0xff;
103 else if( eState == SfxItemState::DEFAULT )
105 const SfxBoolItem& rStateItem = dynamic_cast<const SfxBoolItem&>(*pItem);
106 nWaterCanState = rStateItem.GetValue() ? 1 : 0;
108 //not necessary if the last event is still on the way
109 if(!nUserEventId)
110 nUserEventId = Application::PostUserEvent( LINK(
111 this, SfxTemplateControllerItem, SetWaterCanStateHdl_Impl ) );
112 break;
114 case SID_STYLE_EDIT:
115 rTemplateDlg.EnableEdit( SfxItemState::DISABLED != eState );
116 break;
117 case SID_STYLE_DELETE:
118 rTemplateDlg.EnableDel( SfxItemState::DISABLED != eState );
119 break;
120 case SID_STYLE_HIDE:
121 rTemplateDlg.EnableHide( SfxItemState::DISABLED != eState );
122 break;
123 case SID_STYLE_SHOW:
124 rTemplateDlg.EnableShow( SfxItemState::DISABLED != eState );
125 break;
126 case SID_STYLE_NEW_BY_EXAMPLE:
128 rTemplateDlg.EnableExample_Impl(
129 GetId(), SfxItemState::DISABLED != eState );
130 break;
131 case SID_STYLE_UPDATE_BY_EXAMPLE:
133 rTemplateDlg.EnableExample_Impl(
134 GetId(), eState != SfxItemState::DISABLED );
135 break;
137 case SID_STYLE_NEW:
139 rTemplateDlg.EnableNew( SfxItemState::DISABLED != eState );
140 break;
142 case SID_STYLE_DRAGHIERARCHIE:
144 rTemplateDlg.EnableTreeDrag( SfxItemState::DISABLED != eState );
145 break;
147 case SID_STYLE_FAMILY :
149 const SfxUInt16Item *pStateItem = PTR_CAST( SfxUInt16Item, pItem);
150 if (pStateItem)
151 rTemplateDlg.SetFamily( pStateItem->GetValue() );
152 break;
157 IMPL_LINK(SfxTemplateControllerItem, SetWaterCanStateHdl_Impl,
158 SfxTemplateControllerItem*,)
160 nUserEventId = 0;
161 SfxBoolItem* pState = 0;
162 switch(nWaterCanState)
164 case 0 :
165 case 1 :
166 pState = new SfxBoolItem(SID_STYLE_WATERCAN, nWaterCanState != 0);
167 break;
169 rTemplateDlg.SetWaterCanState(pState);
170 delete pState;
171 return 0;
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */