Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / dialog / tplcitem.cxx
blobe5d79fe866f367848b1a2175c5178481484f57be
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // INCLUDE ---------------------------------------------------------------
32 #include <svl/intitem.hxx>
33 #include <vcl/svapp.hxx>
35 #include <sfx2/templdlg.hxx>
36 #include <sfx2/bindings.hxx>
37 #include "sfx2/tplpitem.hxx"
38 #include "tplcitem.hxx"
39 #include "templdgi.hxx"
41 #include <sfx2/sfx.hrc>
42 #include "dialog.hrc"
44 // STATIC DATA -----------------------------------------------------------
46 // Constructor
48 SfxTemplateControllerItem::SfxTemplateControllerItem(
49 sal_uInt16 nSlotId, // ID
50 SfxCommonTemplateDialog_Impl &rDlg, // Controller-Instance,
51 // which is assigned to this item.
52 SfxBindings &rBindings):
53 SfxControllerItem(nSlotId, rBindings),
54 rTemplateDlg(rDlg),
55 nWaterCanState(0xff),
56 nUserEventId(0)
59 // -----------------------------------------------------------------------
60 SfxTemplateControllerItem::~SfxTemplateControllerItem()
62 if(nUserEventId)
63 Application::RemoveUserEvent(nUserEventId);
66 // -----------------------------------------------------------------------
67 // Notice about change of status, is propagated through the Controller
68 // passed on by the constructor
70 void SfxTemplateControllerItem::StateChanged( sal_uInt16 nSID, SfxItemState eState,
71 const SfxPoolItem* pItem )
73 switch(nSID)
75 case SID_STYLE_FAMILY1:
76 case SID_STYLE_FAMILY2:
77 case SID_STYLE_FAMILY3:
78 case SID_STYLE_FAMILY4:
79 case SID_STYLE_FAMILY5:
81 bool bAvailable = SFX_ITEM_AVAILABLE == eState;
82 if ( !bAvailable )
83 rTemplateDlg.SetFamilyState(GetId(), 0);
84 else {
85 const SfxTemplateItem *pStateItem = PTR_CAST(
86 SfxTemplateItem, pItem);
87 DBG_ASSERT(pStateItem != 0, "SfxTemplateItem expected");
88 rTemplateDlg.SetFamilyState( GetId(), pStateItem );
90 sal_Bool bDisable = eState == SFX_ITEM_DISABLED;
91 // Disable Familly
92 sal_uInt16 nFamily = 0;
93 switch( GetId())
95 case SID_STYLE_FAMILY1:
96 nFamily = 1; break;
97 case SID_STYLE_FAMILY2:
98 nFamily = 2; break;
99 case SID_STYLE_FAMILY3:
100 nFamily = 3; break;
101 case SID_STYLE_FAMILY4:
102 nFamily = 4; break;
103 case SID_STYLE_FAMILY5:
104 nFamily = 5; break;
106 default: OSL_FAIL("unknown StyleFamily"); break;
108 rTemplateDlg.EnableFamilyItem( nFamily, !bDisable );
109 break;
111 case SID_STYLE_WATERCAN:
113 if ( eState == SFX_ITEM_DISABLED )
114 nWaterCanState = 0xff;
115 else if( eState == SFX_ITEM_AVAILABLE )
117 const SfxBoolItem *pStateItem = PTR_CAST(SfxBoolItem, pItem);
118 DBG_ASSERT(pStateItem != 0, "BoolItem expected");
119 nWaterCanState = pStateItem->GetValue() ? 1 : 0;
121 //not necessary if the last event is still on the way
122 if(!nUserEventId)
123 nUserEventId = Application::PostUserEvent( STATIC_LINK(
124 this, SfxTemplateControllerItem, SetWaterCanStateHdl_Impl ) );
125 break;
127 case SID_STYLE_EDIT:
128 rTemplateDlg.EnableEdit( SFX_ITEM_DISABLED != eState );
129 break;
130 case SID_STYLE_DELETE:
131 rTemplateDlg.EnableDel( SFX_ITEM_DISABLED != eState );
132 break;
133 case SID_STYLE_NEW_BY_EXAMPLE:
135 rTemplateDlg.EnableExample_Impl(
136 GetId(), SFX_ITEM_DISABLED != eState );
137 break;
138 case SID_STYLE_UPDATE_BY_EXAMPLE:
140 rTemplateDlg.EnableExample_Impl(
141 GetId(), eState != SFX_ITEM_DISABLED );
142 break;
144 case SID_STYLE_NEW:
146 rTemplateDlg.EnableNew( SFX_ITEM_DISABLED != eState );
147 break;
149 case SID_STYLE_DRAGHIERARCHIE:
151 rTemplateDlg.EnableTreeDrag( SFX_ITEM_DISABLED != eState );
152 break;
154 case SID_STYLE_FAMILY :
156 const SfxUInt16Item *pStateItem = PTR_CAST( SfxUInt16Item, pItem);
157 if (pStateItem)
158 rTemplateDlg.SetFamily( pStateItem->GetValue() );
159 break;
164 IMPL_STATIC_LINK(SfxTemplateControllerItem, SetWaterCanStateHdl_Impl,
165 SfxTemplateControllerItem*, EMPTYARG)
167 pThis->nUserEventId = 0;
168 SfxBoolItem* pState = 0;
169 switch(pThis->nWaterCanState)
171 case 0 :
172 case 1 :
173 pState = new SfxBoolItem(SID_STYLE_WATERCAN, pThis->nWaterCanState ? sal_True : sal_False);
174 break;
176 pThis->rTemplateDlg.SetWaterCanState(pState);
177 delete pState;
178 return 0;
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */