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_fpicker.hxx" 30 31 //------------------------------------------------------------------------ 32 // includes 33 //------------------------------------------------------------------------ 34 #include "controlcommand.hxx" 35 #include "controlcommandrequest.hxx" 36 #include "controlcommandresult.hxx" 37 #include "filepickerstate.hxx" 38 39 //--------------------------------------------- 40 // 41 //--------------------------------------------- 42 43 CControlCommand::CControlCommand( sal_Int16 aControlId ) : 44 m_NextCommand( NULL ), 45 m_aControlId( aControlId ) 46 { 47 } 48 49 //--------------------------------------------- 50 // 51 //--------------------------------------------- 52 53 CControlCommand::~CControlCommand( ) 54 { 55 } 56 57 //--------------------------------------------- 58 // 59 //--------------------------------------------- 60 61 CControlCommandResult* SAL_CALL CControlCommand::handleRequest( CControlCommandRequest* pRequest ) 62 { 63 // if the command does not support handleRequest, it should at least 64 // redirect the request to the next element 65 // so the base class implementation has to do it 66 67 OSL_ENSURE( pRequest, "inavlid parameter" ); 68 69 CControlCommandResult* result; 70 CControlCommand* nextCommand; 71 72 nextCommand = getNextCommand( ); 73 if ( nextCommand ) 74 { 75 result = nextCommand->handleRequest( pRequest ); 76 } 77 else 78 { 79 result = new CControlCommandResult(); 80 } 81 82 return result; 83 } 84 85 //--------------------------------------------- 86 // 87 //--------------------------------------------- 88 89 CControlCommand* SAL_CALL CControlCommand::getNextCommand( ) const 90 { 91 return m_NextCommand; 92 } 93 94 //--------------------------------------------- 95 // 96 //--------------------------------------------- 97 98 void SAL_CALL CControlCommand::setNextCommand( CControlCommand* nextCommand ) 99 { 100 m_NextCommand = nextCommand; 101 } 102 103 //--------------------------------------------- 104 // 105 //--------------------------------------------- 106 107 sal_Int16 SAL_CALL CControlCommand::getControlId( ) const 108 { 109 return m_aControlId; 110 } 111 112 113 //--------------------------------------------- 114 // 115 //--------------------------------------------- 116 117 CValueControlCommand::CValueControlCommand( 118 sal_Int16 aControlId, 119 sal_Int16 aControlAction, 120 const ::com::sun::star::uno::Any& aValue ) : 121 CControlCommand( aControlId ), 122 m_aControlAction( aControlAction ), 123 m_aValue( aValue ) 124 { 125 } 126 127 //--------------------------------------------- 128 // 129 //--------------------------------------------- 130 131 void SAL_CALL CValueControlCommand::exec( CFilePickerState* aFilePickerState ) 132 { 133 OSL_ENSURE( aFilePickerState, "empty reference" ); 134 135 aFilePickerState->setValue( 136 getControlId( ), 137 m_aControlAction, 138 m_aValue ); 139 } 140 141 //--------------------------------------------- 142 // 143 //--------------------------------------------- 144 145 CControlCommandResult* SAL_CALL CValueControlCommand::handleRequest( CControlCommandRequest* aRequest ) 146 { 147 CValueControlCommandRequest* value_request = 148 dynamic_cast< CValueControlCommandRequest* >( aRequest ); 149 150 CControlCommandResult* result; 151 CControlCommand* nextCommand; 152 153 if ( value_request && 154 (value_request->getControlId( ) == getControlId( )) && 155 (value_request->getControlAction( ) == m_aControlAction) ) 156 { 157 result = new CValueCommandResult( sal_True, m_aValue ); 158 } 159 else 160 { 161 nextCommand = getNextCommand( ); 162 if ( nextCommand ) 163 { 164 result = nextCommand->handleRequest( aRequest ); 165 } 166 else 167 { 168 result = new CControlCommandResult( ); 169 } 170 } 171 172 return result; 173 } 174 175 //--------------------------------------------- 176 // 177 //--------------------------------------------- 178 179 sal_Int16 SAL_CALL CValueControlCommand::getControlAction( ) const 180 { 181 return m_aControlAction; 182 } 183 184 //--------------------------------------------- 185 // 186 //--------------------------------------------- 187 188 ::com::sun::star::uno::Any SAL_CALL CValueControlCommand::getValue( ) const 189 { 190 return m_aValue; 191 } 192 193 194 //--------------------------------------------- 195 // 196 //--------------------------------------------- 197 198 CLabelControlCommand::CLabelControlCommand( 199 sal_Int16 aControlId, 200 const rtl::OUString& aLabel ) : 201 CControlCommand( aControlId ), 202 m_aLabel( aLabel ) 203 { 204 } 205 206 //--------------------------------------------- 207 // 208 //--------------------------------------------- 209 210 void SAL_CALL CLabelControlCommand::exec( CFilePickerState* aFilePickerState ) 211 { 212 OSL_ENSURE( aFilePickerState, "empty reference" ); 213 214 aFilePickerState->setLabel( getControlId( ), m_aLabel ); 215 } 216 217 //--------------------------------------------- 218 // 219 //--------------------------------------------- 220 221 CControlCommandResult* SAL_CALL CLabelControlCommand::handleRequest( CControlCommandRequest* aRequest ) 222 { 223 OSL_ENSURE( aRequest, "inavlid parameter" ); 224 225 CControlCommandResult* result; 226 CControlCommand* nextCommand; 227 228 CValueControlCommandRequest* value_request = 229 dynamic_cast< CValueControlCommandRequest* >( aRequest ); 230 231 if ( !value_request && 232 (aRequest->getControlId( ) == getControlId( )) ) 233 { 234 result = new CLabelCommandResult( sal_True, m_aLabel ); 235 } 236 else 237 { 238 nextCommand = getNextCommand( ); 239 if ( nextCommand ) 240 { 241 result = nextCommand->handleRequest( aRequest ); 242 } 243 else 244 { 245 result = new CControlCommandResult( ); 246 } 247 } 248 249 return result; 250 } 251 252 //--------------------------------------------- 253 // 254 //--------------------------------------------- 255 256 rtl::OUString SAL_CALL CLabelControlCommand::getLabel( ) const 257 { 258 return m_aLabel; 259 } 260 261 //--------------------------------------------- 262 // 263 //--------------------------------------------- 264 265 CEnableControlCommand::CEnableControlCommand( 266 sal_Int16 aControlId, 267 sal_Bool bEnable ) : 268 CControlCommand( aControlId ), 269 m_bEnable( bEnable ) 270 { 271 } 272 273 //--------------------------------------------- 274 // 275 //--------------------------------------------- 276 277 void SAL_CALL CEnableControlCommand::exec( CFilePickerState* aFilePickerState ) 278 { 279 OSL_ENSURE( aFilePickerState, "empty reference" ); 280 281 aFilePickerState->enableControl( getControlId( ), m_bEnable ); 282 } 283