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