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