xref: /aoo41x/main/sfx2/source/dialog/tplcitem.cxx (revision d119d52d)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d119d52dSAndrew Rist  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d119d52dSAndrew Rist  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19*d119d52dSAndrew Rist  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <svl/intitem.hxx>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <sfx2/templdlg.hxx>
33cdf0e10cSrcweir #include <sfx2/bindings.hxx>
34cdf0e10cSrcweir #include "sfx2/tplpitem.hxx"
35cdf0e10cSrcweir #include "tplcitem.hxx"
36cdf0e10cSrcweir #include "templdgi.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <sfx2/sfx.hrc>
39cdf0e10cSrcweir #include "dialog.hrc"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // Konstruktor
44cdf0e10cSrcweir 
SfxTemplateControllerItem(sal_uInt16 nSlotId,SfxCommonTemplateDialog_Impl & rDlg,SfxBindings & rBindings)45cdf0e10cSrcweir SfxTemplateControllerItem::SfxTemplateControllerItem(
46cdf0e10cSrcweir 		sal_uInt16 nSlotId,					// ID
47cdf0e10cSrcweir 		SfxCommonTemplateDialog_Impl &rDlg,	// Controller-Instanz, dem dieses Item zugeordnet ist.
48cdf0e10cSrcweir 		SfxBindings &rBindings):
49cdf0e10cSrcweir 	SfxControllerItem(nSlotId, rBindings),
50cdf0e10cSrcweir     rTemplateDlg(rDlg),
51cdf0e10cSrcweir     nWaterCanState(0xff),
52cdf0e10cSrcweir     nUserEventId(0)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir // -----------------------------------------------------------------------
~SfxTemplateControllerItem()56cdf0e10cSrcweir SfxTemplateControllerItem::~SfxTemplateControllerItem()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     if(nUserEventId)
59cdf0e10cSrcweir         Application::RemoveUserEvent(nUserEventId);
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir // -----------------------------------------------------------------------
63cdf0e10cSrcweir 
64cdf0e10cSrcweir // Benachrichtigung "uber Status"anderung; wird an den
65cdf0e10cSrcweir // im Konstruktor "ubergebenen Controller propagiert
66cdf0e10cSrcweir 
StateChanged(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pItem)67cdf0e10cSrcweir void SfxTemplateControllerItem::StateChanged( sal_uInt16 nSID, SfxItemState eState,
68cdf0e10cSrcweir 											  const SfxPoolItem* pItem )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	switch(nSID)
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 		case SID_STYLE_FAMILY1:
73cdf0e10cSrcweir 		case SID_STYLE_FAMILY2:
74cdf0e10cSrcweir 		case SID_STYLE_FAMILY3:
75cdf0e10cSrcweir 		case SID_STYLE_FAMILY4:
76cdf0e10cSrcweir 		case SID_STYLE_FAMILY5:
77cdf0e10cSrcweir 		{
78cdf0e10cSrcweir 			bool bAvailable = SFX_ITEM_AVAILABLE == eState;
79cdf0e10cSrcweir 			if ( !bAvailable )
80cdf0e10cSrcweir 				rTemplateDlg.SetFamilyState(GetId(), 0);
81cdf0e10cSrcweir 			else {
82cdf0e10cSrcweir 				const SfxTemplateItem *pStateItem = PTR_CAST(
83cdf0e10cSrcweir 					SfxTemplateItem, pItem);
84cdf0e10cSrcweir 				DBG_ASSERT(pStateItem != 0, "SfxTemplateItem erwartet");
85cdf0e10cSrcweir 				rTemplateDlg.SetFamilyState( GetId(), pStateItem );
86cdf0e10cSrcweir 			}
87cdf0e10cSrcweir 			sal_Bool bDisable = eState == SFX_ITEM_DISABLED;
88cdf0e10cSrcweir 			// Familie Disablen
89cdf0e10cSrcweir 			sal_uInt16 nFamily = 0;
90cdf0e10cSrcweir 			switch( GetId())
91cdf0e10cSrcweir 			{
92cdf0e10cSrcweir 				case SID_STYLE_FAMILY1:
93cdf0e10cSrcweir 					nFamily = 1; break;
94cdf0e10cSrcweir 				case SID_STYLE_FAMILY2:
95cdf0e10cSrcweir 					nFamily = 2; break;
96cdf0e10cSrcweir 				case SID_STYLE_FAMILY3:
97cdf0e10cSrcweir 					nFamily = 3; break;
98cdf0e10cSrcweir 				case SID_STYLE_FAMILY4:
99cdf0e10cSrcweir 					nFamily = 4; break;
100cdf0e10cSrcweir 				case SID_STYLE_FAMILY5:
101cdf0e10cSrcweir 					nFamily = 5; break;
102cdf0e10cSrcweir 				default: DBG_ERROR("unbekannte StyleFamily"); break;
103cdf0e10cSrcweir 			}
104cdf0e10cSrcweir 			rTemplateDlg.EnableFamilyItem( nFamily, !bDisable );
105cdf0e10cSrcweir 			break;
106cdf0e10cSrcweir 		}
107cdf0e10cSrcweir 		case SID_STYLE_WATERCAN:
108cdf0e10cSrcweir 		{
109cdf0e10cSrcweir 			if ( eState == SFX_ITEM_DISABLED )
110cdf0e10cSrcweir                 nWaterCanState = 0xff;
111cdf0e10cSrcweir             else if( eState == SFX_ITEM_AVAILABLE )
112cdf0e10cSrcweir 			{
113cdf0e10cSrcweir 				const SfxBoolItem *pStateItem = PTR_CAST(SfxBoolItem, pItem);
114cdf0e10cSrcweir 				DBG_ASSERT(pStateItem != 0, "BoolItem erwartet");
115cdf0e10cSrcweir                 nWaterCanState = pStateItem->GetValue() ? 1 : 0;
116cdf0e10cSrcweir             }
117cdf0e10cSrcweir             //not necessary if the last event is still on the way
118cdf0e10cSrcweir 			if(!nUserEventId)
119cdf0e10cSrcweir 				nUserEventId = Application::PostUserEvent( STATIC_LINK(
120cdf0e10cSrcweir 							this, SfxTemplateControllerItem, SetWaterCanStateHdl_Impl ) );
121cdf0e10cSrcweir 			break;
122cdf0e10cSrcweir 		}
123cdf0e10cSrcweir 		case SID_STYLE_EDIT:
124cdf0e10cSrcweir 			rTemplateDlg.EnableEdit( SFX_ITEM_DISABLED != eState );
125cdf0e10cSrcweir 			break;
126cdf0e10cSrcweir 		case SID_STYLE_DELETE:
127cdf0e10cSrcweir 			rTemplateDlg.EnableDel( SFX_ITEM_DISABLED != eState );
128cdf0e10cSrcweir 			break;
129cdf0e10cSrcweir 		case SID_STYLE_NEW_BY_EXAMPLE:
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 			rTemplateDlg.EnableExample_Impl(
132cdf0e10cSrcweir 				GetId(), SFX_ITEM_DISABLED != eState );
133cdf0e10cSrcweir 			break;
134cdf0e10cSrcweir 		case SID_STYLE_UPDATE_BY_EXAMPLE:
135cdf0e10cSrcweir 		{
136cdf0e10cSrcweir 			rTemplateDlg.EnableExample_Impl(
137cdf0e10cSrcweir 				GetId(), eState != SFX_ITEM_DISABLED );
138cdf0e10cSrcweir 			// Das Select Disabled dann, falls enabled und Style Readonly
139cdf0e10cSrcweir /*			String aStr = rTemplateDlg.GetSelectedEntry();
140cdf0e10cSrcweir 			if( aStr.Len() ) rTemplateDlg.SelectStyle( aStr ); */
141cdf0e10cSrcweir 			break;
142cdf0e10cSrcweir 		}
143cdf0e10cSrcweir 		case SID_STYLE_NEW:
144cdf0e10cSrcweir 		{
145cdf0e10cSrcweir 			rTemplateDlg.EnableNew( SFX_ITEM_DISABLED != eState );
146cdf0e10cSrcweir 			break;
147cdf0e10cSrcweir 		}
148cdf0e10cSrcweir 		case SID_STYLE_DRAGHIERARCHIE:
149cdf0e10cSrcweir 		{
150cdf0e10cSrcweir 			rTemplateDlg.EnableTreeDrag( SFX_ITEM_DISABLED != eState );
151cdf0e10cSrcweir 			break;
152cdf0e10cSrcweir 		}
153cdf0e10cSrcweir 		case SID_STYLE_FAMILY :
154cdf0e10cSrcweir 		{
155cdf0e10cSrcweir 			const SfxUInt16Item *pStateItem = PTR_CAST( SfxUInt16Item, pItem);
156cdf0e10cSrcweir 			if (pStateItem)
157cdf0e10cSrcweir 				rTemplateDlg.SetFamily( pStateItem->GetValue() );
158cdf0e10cSrcweir 			break;
159cdf0e10cSrcweir 		}
160cdf0e10cSrcweir 	}
161cdf0e10cSrcweir }
162cdf0e10cSrcweir /* -----------------------------05.09.2001 10:48------------------------------
163cdf0e10cSrcweir 
164cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
IMPL_STATIC_LINK(SfxTemplateControllerItem,SetWaterCanStateHdl_Impl,SfxTemplateControllerItem *,EMPTYARG)165cdf0e10cSrcweir IMPL_STATIC_LINK(SfxTemplateControllerItem, SetWaterCanStateHdl_Impl,
166cdf0e10cSrcweir                                     SfxTemplateControllerItem*, EMPTYARG)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     pThis->nUserEventId = 0;
169cdf0e10cSrcweir     SfxBoolItem* pState = 0;
170cdf0e10cSrcweir     switch(pThis->nWaterCanState)
171cdf0e10cSrcweir     {
172cdf0e10cSrcweir         case 0 :
173cdf0e10cSrcweir         case 1 :
174cdf0e10cSrcweir             pState = new SfxBoolItem(SID_STYLE_WATERCAN, pThis->nWaterCanState ? sal_True : sal_False);
175cdf0e10cSrcweir         break;
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir     pThis->rTemplateDlg.SetWaterCanState(pState);
178cdf0e10cSrcweir     delete pState;
179cdf0e10cSrcweir     return 0;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182