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