bump product version to 4.1.6.2
[LibreOffice.git] / fpicker / source / win32 / filepicker / controlcommand.cxx
blob222bb1960bc262b6cad9e16f062e976b0825a41b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "controlcommand.hxx"
21 #include "controlcommandrequest.hxx"
22 #include "controlcommandresult.hxx"
23 #include "filepickerstate.hxx"
25 //---------------------------------------------
27 //---------------------------------------------
29 CControlCommand::CControlCommand( sal_Int16 aControlId ) :
30 m_NextCommand( NULL ),
31 m_aControlId( aControlId )
35 //---------------------------------------------
37 //---------------------------------------------
39 CControlCommand::~CControlCommand( )
43 //---------------------------------------------
45 //---------------------------------------------
47 CControlCommandResult* SAL_CALL CControlCommand::handleRequest( CControlCommandRequest* pRequest )
49 // if the command does not support handleRequest, it should at least
50 // redirect the request to the next element
51 // so the base class implementation has to do it
53 OSL_ENSURE( pRequest, "invalid parameter" );
55 CControlCommandResult* result;
56 CControlCommand* nextCommand;
58 nextCommand = getNextCommand( );
59 if ( nextCommand )
61 result = nextCommand->handleRequest( pRequest );
63 else
65 result = new CControlCommandResult();
68 return result;
71 //---------------------------------------------
73 //---------------------------------------------
75 CControlCommand* SAL_CALL CControlCommand::getNextCommand( ) const
77 return m_NextCommand;
80 //---------------------------------------------
82 //---------------------------------------------
84 void SAL_CALL CControlCommand::setNextCommand( CControlCommand* nextCommand )
86 m_NextCommand = nextCommand;
89 //---------------------------------------------
91 //---------------------------------------------
93 sal_Int16 SAL_CALL CControlCommand::getControlId( ) const
95 return m_aControlId;
99 //---------------------------------------------
101 //---------------------------------------------
103 CValueControlCommand::CValueControlCommand(
104 sal_Int16 aControlId,
105 sal_Int16 aControlAction,
106 const ::com::sun::star::uno::Any& aValue ) :
107 CControlCommand( aControlId ),
108 m_aControlAction( aControlAction ),
109 m_aValue( aValue )
113 //---------------------------------------------
115 //---------------------------------------------
117 void SAL_CALL CValueControlCommand::exec( CFilePickerState* aFilePickerState )
119 OSL_ENSURE( aFilePickerState, "empty reference" );
121 aFilePickerState->setValue(
122 getControlId( ),
123 m_aControlAction,
124 m_aValue );
127 //---------------------------------------------
129 //---------------------------------------------
131 CControlCommandResult* SAL_CALL CValueControlCommand::handleRequest( CControlCommandRequest* aRequest )
133 CValueControlCommandRequest* value_request =
134 dynamic_cast< CValueControlCommandRequest* >( aRequest );
136 CControlCommandResult* result;
137 CControlCommand* nextCommand;
139 if ( value_request &&
140 (value_request->getControlId( ) == getControlId( )) &&
141 (value_request->getControlAction( ) == m_aControlAction) )
143 result = new CValueCommandResult( sal_True, m_aValue );
145 else
147 nextCommand = getNextCommand( );
148 if ( nextCommand )
150 result = nextCommand->handleRequest( aRequest );
152 else
154 result = new CControlCommandResult( );
158 return result;
161 //---------------------------------------------
163 //---------------------------------------------
165 sal_Int16 SAL_CALL CValueControlCommand::getControlAction( ) const
167 return m_aControlAction;
170 //---------------------------------------------
172 //---------------------------------------------
174 ::com::sun::star::uno::Any SAL_CALL CValueControlCommand::getValue( ) const
176 return m_aValue;
180 //---------------------------------------------
182 //---------------------------------------------
184 CLabelControlCommand::CLabelControlCommand(
185 sal_Int16 aControlId,
186 const OUString& aLabel ) :
187 CControlCommand( aControlId ),
188 m_aLabel( aLabel )
192 //---------------------------------------------
194 //---------------------------------------------
196 void SAL_CALL CLabelControlCommand::exec( CFilePickerState* aFilePickerState )
198 OSL_ENSURE( aFilePickerState, "empty reference" );
200 aFilePickerState->setLabel( getControlId( ), m_aLabel );
203 //---------------------------------------------
205 //---------------------------------------------
207 CControlCommandResult* SAL_CALL CLabelControlCommand::handleRequest( CControlCommandRequest* aRequest )
209 OSL_ENSURE( aRequest, "invalid parameter" );
211 CControlCommandResult* result;
212 CControlCommand* nextCommand;
214 CValueControlCommandRequest* value_request =
215 dynamic_cast< CValueControlCommandRequest* >( aRequest );
217 if ( !value_request &&
218 (aRequest->getControlId( ) == getControlId( )) )
220 result = new CLabelCommandResult( sal_True, m_aLabel );
222 else
224 nextCommand = getNextCommand( );
225 if ( nextCommand )
227 result = nextCommand->handleRequest( aRequest );
229 else
231 result = new CControlCommandResult( );
235 return result;
238 //---------------------------------------------
240 //---------------------------------------------
242 OUString SAL_CALL CLabelControlCommand::getLabel( ) const
244 return m_aLabel;
247 //---------------------------------------------
249 //---------------------------------------------
251 CEnableControlCommand::CEnableControlCommand(
252 sal_Int16 aControlId,
253 sal_Bool bEnable ) :
254 CControlCommand( aControlId ),
255 m_bEnable( bEnable )
259 //---------------------------------------------
261 //---------------------------------------------
263 void SAL_CALL CEnableControlCommand::exec( CFilePickerState* aFilePickerState )
265 OSL_ENSURE( aFilePickerState, "empty reference" );
267 aFilePickerState->enableControl( getControlId( ), m_bEnable );
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */