xref: /AOO41X/main/sfx2/source/dialog/tplcitem.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <svl/intitem.hxx>
34*cdf0e10cSrcweir #include <vcl/svapp.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <sfx2/templdlg.hxx>
37*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
38*cdf0e10cSrcweir #include "sfx2/tplpitem.hxx"
39*cdf0e10cSrcweir #include "tplcitem.hxx"
40*cdf0e10cSrcweir #include "templdgi.hxx"
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include <sfx2/sfx.hrc>
43*cdf0e10cSrcweir #include "dialog.hrc"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir // Konstruktor
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir SfxTemplateControllerItem::SfxTemplateControllerItem(
50*cdf0e10cSrcweir 		sal_uInt16 nSlotId,					// ID
51*cdf0e10cSrcweir 		SfxCommonTemplateDialog_Impl &rDlg,	// Controller-Instanz, dem dieses Item zugeordnet ist.
52*cdf0e10cSrcweir 		SfxBindings &rBindings):
53*cdf0e10cSrcweir 	SfxControllerItem(nSlotId, rBindings),
54*cdf0e10cSrcweir     rTemplateDlg(rDlg),
55*cdf0e10cSrcweir     nWaterCanState(0xff),
56*cdf0e10cSrcweir     nUserEventId(0)
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir }
59*cdf0e10cSrcweir // -----------------------------------------------------------------------
60*cdf0e10cSrcweir SfxTemplateControllerItem::~SfxTemplateControllerItem()
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir     if(nUserEventId)
63*cdf0e10cSrcweir         Application::RemoveUserEvent(nUserEventId);
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir // -----------------------------------------------------------------------
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir // Benachrichtigung "uber Status"anderung; wird an den
69*cdf0e10cSrcweir // im Konstruktor "ubergebenen Controller propagiert
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir void SfxTemplateControllerItem::StateChanged( sal_uInt16 nSID, SfxItemState eState,
72*cdf0e10cSrcweir 											  const SfxPoolItem* pItem )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 	switch(nSID)
75*cdf0e10cSrcweir 	{
76*cdf0e10cSrcweir 		case SID_STYLE_FAMILY1:
77*cdf0e10cSrcweir 		case SID_STYLE_FAMILY2:
78*cdf0e10cSrcweir 		case SID_STYLE_FAMILY3:
79*cdf0e10cSrcweir 		case SID_STYLE_FAMILY4:
80*cdf0e10cSrcweir 		case SID_STYLE_FAMILY5:
81*cdf0e10cSrcweir 		{
82*cdf0e10cSrcweir 			bool bAvailable = SFX_ITEM_AVAILABLE == eState;
83*cdf0e10cSrcweir 			if ( !bAvailable )
84*cdf0e10cSrcweir 				rTemplateDlg.SetFamilyState(GetId(), 0);
85*cdf0e10cSrcweir 			else {
86*cdf0e10cSrcweir 				const SfxTemplateItem *pStateItem = PTR_CAST(
87*cdf0e10cSrcweir 					SfxTemplateItem, pItem);
88*cdf0e10cSrcweir 				DBG_ASSERT(pStateItem != 0, "SfxTemplateItem erwartet");
89*cdf0e10cSrcweir 				rTemplateDlg.SetFamilyState( GetId(), pStateItem );
90*cdf0e10cSrcweir 			}
91*cdf0e10cSrcweir 			sal_Bool bDisable = eState == SFX_ITEM_DISABLED;
92*cdf0e10cSrcweir 			// Familie Disablen
93*cdf0e10cSrcweir 			sal_uInt16 nFamily = 0;
94*cdf0e10cSrcweir 			switch( GetId())
95*cdf0e10cSrcweir 			{
96*cdf0e10cSrcweir 				case SID_STYLE_FAMILY1:
97*cdf0e10cSrcweir 					nFamily = 1; break;
98*cdf0e10cSrcweir 				case SID_STYLE_FAMILY2:
99*cdf0e10cSrcweir 					nFamily = 2; break;
100*cdf0e10cSrcweir 				case SID_STYLE_FAMILY3:
101*cdf0e10cSrcweir 					nFamily = 3; break;
102*cdf0e10cSrcweir 				case SID_STYLE_FAMILY4:
103*cdf0e10cSrcweir 					nFamily = 4; break;
104*cdf0e10cSrcweir 				case SID_STYLE_FAMILY5:
105*cdf0e10cSrcweir 					nFamily = 5; break;
106*cdf0e10cSrcweir 				default: DBG_ERROR("unbekannte StyleFamily"); break;
107*cdf0e10cSrcweir 			}
108*cdf0e10cSrcweir 			rTemplateDlg.EnableFamilyItem( nFamily, !bDisable );
109*cdf0e10cSrcweir 			break;
110*cdf0e10cSrcweir 		}
111*cdf0e10cSrcweir 		case SID_STYLE_WATERCAN:
112*cdf0e10cSrcweir 		{
113*cdf0e10cSrcweir 			if ( eState == SFX_ITEM_DISABLED )
114*cdf0e10cSrcweir                 nWaterCanState = 0xff;
115*cdf0e10cSrcweir             else if( eState == SFX_ITEM_AVAILABLE )
116*cdf0e10cSrcweir 			{
117*cdf0e10cSrcweir 				const SfxBoolItem *pStateItem = PTR_CAST(SfxBoolItem, pItem);
118*cdf0e10cSrcweir 				DBG_ASSERT(pStateItem != 0, "BoolItem erwartet");
119*cdf0e10cSrcweir                 nWaterCanState = pStateItem->GetValue() ? 1 : 0;
120*cdf0e10cSrcweir             }
121*cdf0e10cSrcweir             //not necessary if the last event is still on the way
122*cdf0e10cSrcweir 			if(!nUserEventId)
123*cdf0e10cSrcweir 				nUserEventId = Application::PostUserEvent( STATIC_LINK(
124*cdf0e10cSrcweir 							this, SfxTemplateControllerItem, SetWaterCanStateHdl_Impl ) );
125*cdf0e10cSrcweir 			break;
126*cdf0e10cSrcweir 		}
127*cdf0e10cSrcweir 		case SID_STYLE_EDIT:
128*cdf0e10cSrcweir 			rTemplateDlg.EnableEdit( SFX_ITEM_DISABLED != eState );
129*cdf0e10cSrcweir 			break;
130*cdf0e10cSrcweir 		case SID_STYLE_DELETE:
131*cdf0e10cSrcweir 			rTemplateDlg.EnableDel( SFX_ITEM_DISABLED != eState );
132*cdf0e10cSrcweir 			break;
133*cdf0e10cSrcweir 		case SID_STYLE_NEW_BY_EXAMPLE:
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 			rTemplateDlg.EnableExample_Impl(
136*cdf0e10cSrcweir 				GetId(), SFX_ITEM_DISABLED != eState );
137*cdf0e10cSrcweir 			break;
138*cdf0e10cSrcweir 		case SID_STYLE_UPDATE_BY_EXAMPLE:
139*cdf0e10cSrcweir 		{
140*cdf0e10cSrcweir 			rTemplateDlg.EnableExample_Impl(
141*cdf0e10cSrcweir 				GetId(), eState != SFX_ITEM_DISABLED );
142*cdf0e10cSrcweir 			// Das Select Disabled dann, falls enabled und Style Readonly
143*cdf0e10cSrcweir /*			String aStr = rTemplateDlg.GetSelectedEntry();
144*cdf0e10cSrcweir 			if( aStr.Len() ) rTemplateDlg.SelectStyle( aStr ); */
145*cdf0e10cSrcweir 			break;
146*cdf0e10cSrcweir 		}
147*cdf0e10cSrcweir 		case SID_STYLE_NEW:
148*cdf0e10cSrcweir 		{
149*cdf0e10cSrcweir 			rTemplateDlg.EnableNew( SFX_ITEM_DISABLED != eState );
150*cdf0e10cSrcweir 			break;
151*cdf0e10cSrcweir 		}
152*cdf0e10cSrcweir 		case SID_STYLE_DRAGHIERARCHIE:
153*cdf0e10cSrcweir 		{
154*cdf0e10cSrcweir 			rTemplateDlg.EnableTreeDrag( SFX_ITEM_DISABLED != eState );
155*cdf0e10cSrcweir 			break;
156*cdf0e10cSrcweir 		}
157*cdf0e10cSrcweir 		case SID_STYLE_FAMILY :
158*cdf0e10cSrcweir 		{
159*cdf0e10cSrcweir 			const SfxUInt16Item *pStateItem = PTR_CAST( SfxUInt16Item, pItem);
160*cdf0e10cSrcweir 			if (pStateItem)
161*cdf0e10cSrcweir 				rTemplateDlg.SetFamily( pStateItem->GetValue() );
162*cdf0e10cSrcweir 			break;
163*cdf0e10cSrcweir 		}
164*cdf0e10cSrcweir 	}
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir /* -----------------------------05.09.2001 10:48------------------------------
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
169*cdf0e10cSrcweir IMPL_STATIC_LINK(SfxTemplateControllerItem, SetWaterCanStateHdl_Impl,
170*cdf0e10cSrcweir                                     SfxTemplateControllerItem*, EMPTYARG)
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir     pThis->nUserEventId = 0;
173*cdf0e10cSrcweir     SfxBoolItem* pState = 0;
174*cdf0e10cSrcweir     switch(pThis->nWaterCanState)
175*cdf0e10cSrcweir     {
176*cdf0e10cSrcweir         case 0 :
177*cdf0e10cSrcweir         case 1 :
178*cdf0e10cSrcweir             pState = new SfxBoolItem(SID_STYLE_WATERCAN, pThis->nWaterCanState ? sal_True : sal_False);
179*cdf0e10cSrcweir         break;
180*cdf0e10cSrcweir     }
181*cdf0e10cSrcweir     pThis->rTemplateDlg.SetWaterCanState(pState);
182*cdf0e10cSrcweir     delete pState;
183*cdf0e10cSrcweir     return 0;
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186