1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
/*************************************************************************
*
* $RCSfile: framecontainer.cxx,v $
*
* $Revision: 1.3 $
*
* last change: $Author: as $ $Date: 2000-10-16 13:36:48 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
//_________________________________________________________________________________________________________________
// my own includes
//_________________________________________________________________________________________________________________
#ifndef __FRAMEWORK_FRAMECONTAINER_HXX_
#include <classes/framecontainer.hxx>
#endif
//_________________________________________________________________________________________________________________
// interface includes
//_________________________________________________________________________________________________________________
//_________________________________________________________________________________________________________________
// includes of other projects
//_________________________________________________________________________________________________________________
//_________________________________________________________________________________________________________________
// namespace
//_________________________________________________________________________________________________________________
namespace framework{
using namespace ::std ;
using namespace ::com::sun::star::uno ;
using namespace ::com::sun::star::frame ;
//_________________________________________________________________________________________________________________
// non exported const
//_________________________________________________________________________________________________________________
#define LOCK_OFF sal_False
#define LOCK_ON sal_True
//_________________________________________________________________________________________________________________
// non exported definitions
//_________________________________________________________________________________________________________________
//_________________________________________________________________________________________________________________
// declarations
//_________________________________________________________________________________________________________________
//*****************************************************************************************************************
// constructor
//*****************************************************************************************************************
FrameContainer::FrameContainer()
: m_bLock ( LOCK_OFF )
, m_pQuitTimer ( NULL )
{
}
//*****************************************************************************************************************
// destructor
//*****************************************************************************************************************
FrameContainer::~FrameContainer()
{
// Don't forget to free memory!
disableQuitTimer();
clear();
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void FrameContainer::append( const Reference< XFrame >& xFrame )
{
// Safe impossible cases
// This method is not defined for ALL incoming parameters!
LOG_ASSERT( impldbg_checkParameter_append( xFrame ), "FrameContainer::append()\nInvalid parameter detected!\n" )
// Warn programmer at already existing elements in container.
LOG_ASSERT( !(exist(xFrame)==sal_True), "FrameContainer::append()\nNew frame already exist in container!\n" )
// We search for hidden tasks which have no component!
LOG_ASSERT( impldbg_lookForZombieFrames( xFrame ), "FrameContainer::append()\nZombie frame detected!\n" )
// Work only, if container not locked!
if ( m_bLock == LOCK_OFF )
{
// Append new frame to container.
m_aContainer.push_back( xFrame );
}
// Else; Warn programmer.
LOG_ASSERT( !(m_bLock==LOCK_ON), "FrameContainer::append()\nContainer is locked! You can't append frame.\n" )
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void FrameContainer::remove( const Reference< XFrame >& xFrame )
{
// Safe impossible cases
// This method is not defined for ALL incoming parameters!
LOG_ASSERT( impldbg_checkParameter_remove( xFrame ), "FrameContainer::remove()\nInvalid parameter detected!\n" )
// Warn programmer at non existing elements in container.
LOG_ASSERT( !(exist(xFrame)==sal_False), "FrameContainer::remove()\nFrame to remove not exist in container!\n" )
// Safe impossible cases.
LOG_ASSERT( impldbg_lookForZombieFrames( xFrame ), "FrameContainer::remove()\nZombie frame detected!\n" )
// Work only, if container not locked!
if ( m_bLock == LOCK_OFF )
{
// Search frame and remove it from container ...
vector< Reference< XFrame > >::iterator aSearchedItem = find( m_aContainer.begin(), m_aContainer.end(), xFrame );
// ... if it exist.
if ( aSearchedItem != m_aContainer.end() )
{
m_aContainer.erase( aSearchedItem );
// And if removed frame the current active frame - reset state variable.
if ( m_xActiveFrame == xFrame )
{
m_xActiveFrame = Reference< XFrame >();
}
// If last frame was removed and special quit timer is enabled by the desktop
// we must terminate the desktop by using this timer!
if (
( getCount() < 1 ) &&
( m_pQuitTimer != NULL )
)
{
m_pQuitTimer->start();
}
}
}
// Else; Warn programmer.
LOG_ASSERT( !(m_bLock==LOCK_ON), "FrameContainer::remove()\nContainer is locked! You can't remove frame.\n" )
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
sal_Bool FrameContainer::exist( const REFERENCE< XFRAME >& xFrame )
{
// Safe impossible cases
// This method is not defined for ALL incoming parameters!
LOG_ASSERT( impldbg_checkParameter_exist( xFrame ), "FrameContainer::exist()\nInvalid parameter detected!\n" )
// Set default return value.
sal_Bool bExist = sal_False;
// We ignore the lock, because we do not change the content of container!
// Search frame.
vector< Reference< XFrame > >::iterator aSearchedItem = find( m_aContainer.begin(), m_aContainer.end(), xFrame );
// If it exist ...
if ( aSearchedItem != m_aContainer.end() )
{
// Set new return value.
bExist = sal_True;
}
// Return result of this operation.
return bExist;
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void FrameContainer::clear()
{
// Safe impossible cases.
// We search for hidden tasks which have no component!
LOG_ASSERT( impldbg_lookForZombieFrames( Reference< XFrame >() ), "FrameContainer::clear()\nZombie frame detected!\n" )
// This method is only allowed, if no lock is set!
// Warn programmer, if its not true.
LOG_ASSERT( !(m_bLock==LOCK_ON), "FrameContainer::clear()\nContainer is locked! You can't clear it.\n" )
if ( m_bLock == LOCK_OFF )
{
// Clear the container ...
m_aContainer.clear();
// ... and don't forget to reset the active frame.
// Its an reference to a valid container-item.
// But no container item => no active frame!
m_xActiveFrame = Reference< XFrame >();
// If special quit timer is used - we must terminate the desktop.
// He is the owner of this container and can't work without any visible tasks/frames!
if( m_pQuitTimer != NULL )
{
m_pQuitTimer->start();
}
}
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void FrameContainer::lock()
{
// Lock the container and block all append(), remove() and clear() calls.
m_bLock = LOCK_ON;
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void FrameContainer::unlock()
{
// Unlock the container and block all getCount() and operator[] calls.
m_bLock = LOCK_OFF;
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
sal_uInt32 FrameContainer::getCount() const
{
// Return size of current container.
// We ignore the lock, because you can ask for count of container elements ...
// but if you will have full index access you must lock it!
return (sal_uInt32)m_aContainer.size();
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
Reference< XFrame > FrameContainer::operator[]( sal_uInt32 nIndex ) const
{
// Safe impossible cases
// This method is not defined for ALL incoming parameters!
LOG_ASSERT( impldbg_checkParameter_IndexOperator( nIndex ), "FrameContainer::operator[]()\nInvalid parameter detected!\n" )
// Set default return value.
Reference< XFrame > xFrame;
// This operation is allowed only, if lock is set.
// Warn programmer, if this not true.
LOG_ASSERT( !(m_bLock==LOCK_OFF), "FrameContainer::operator[]()\nContainer is not locked! You can't do this.\n" )
if ( m_bLock == LOCK_ON )
{
try
{
// Get element form container WITH automatic test of ranges!
// If index not valid, a out_of_range exception is thrown.
xFrame = m_aContainer.at( nIndex );
}
catch( out_of_range& )
{
// The index is not valid for current container-content ...
// ... but we must handle this case!
// We return a NULL reference.
xFrame = Reference< XFrame >();
}
}
// Return result of this operation.
return xFrame;
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
Sequence< Reference< XFrame > > FrameContainer::getAllElements()
{
// Lock the container for this method.
// Nobody should append or remove anything between creation of snapshot.
// But - don't forget to unlock the container.
m_bLock = LOCK_ON;
// Get memory for return sequence.
sal_uInt32 nCount = (sal_uInt32)m_aContainer.size();
Sequence< Reference< XFrame > > seqReturn( nCount );
// Copy from container to return list.
Reference< XFrame >* pArray = seqReturn.getArray();
for ( sal_uInt32 nPosition=0; nPosition<nCount; ++nPosition )
{
pArray[nPosition] = m_aContainer[nPosition];
}
// Don't forget this!
m_bLock = LOCK_OFF;
// Return result of this operation.
return seqReturn;
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
sal_Bool FrameContainer::hasElements() const
{
// Has container some elements?
return ( m_aContainer.size() > 0 );
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void FrameContainer::setActive( const Reference< XFrame >& xFrame )
{
// Safe impossible cases
// This method is not defined for ALL incoming parameters!
// BUT we accept null refrences for reset active state. => No frame is active then.
LOG_ASSERT( impldbg_checkParameter_setActive( xFrame ), "FrameContainer::setActive()\nInvalid parameter detected!\n" )
// The new active frame MUST exist in container.
// Control this.
LOG_ASSERT( !(xFrame.is()==sal_True && exist(xFrame)==sal_False), "FrameContainer::setActive()\nThe new active frame is not a member of current container!You cant activate it.\n" )
// All incoming parameters are controlled.
// We have a new active frame or a null reference to reset this state.
// Actualize member.
m_xActiveFrame = xFrame;
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
Reference< XFrame > FrameContainer::getActive() const
{
// Return member.
// The correct state of this variable we have controlled in setActive()!
// But we accept null reference for these variable. => There is no active frame in the moment.
return m_xActiveFrame;
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void FrameContainer::enableQuitTimer( const Reference< XDesktop >& xDesktop ,
const TAsyncQuitMode& aMode )
{
// If no current timer exist - create a new one.
if( m_pQuitTimer == NULL )
{
m_pQuitTimer = new AsyncQuit( xDesktop );
}
// Set given mode on existing or created timer member!
m_pQuitTimer->setMode( aMode );
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void FrameContainer::disableQuitTimer()
{
// Delete current quit timer.
// If user wish to create it again he must do it with "enableQuitTimer()".
if( m_pQuitTimer != NULL )
{
delete m_pQuitTimer;
m_pQuitTimer = NULL;
}
}
//_________________________________________________________________________________________________________________
// debug methods
//_________________________________________________________________________________________________________________
/*-----------------------------------------------------------------------------------------------------------------
The follow methods checks the parameter for other functions. If a parameter or his value is non valid,
we return "sal_False". (else sal_True) This mechanism is used to throw an ASSERT!
ATTENTION
If you miss a test for one of this parameters, contact the autor or add it himself !(?)
But ... look for right testing! See using of this methods!
-----------------------------------------------------------------------------------------------------------------*/
#ifdef ENABLE_ASSERTIONS
//*****************************************************************************************************************
// We accept valid references for working with container only.
sal_Bool FrameContainer::impldbg_checkParameter_append( const Reference< XFrame >& xFrame ) const
{
// Set default return value.
sal_Bool bOK = sal_True;
// Check parameter.
if (
( &xFrame == NULL ) ||
( xFrame.is() == sal_False )
)
{
bOK = sal_False ;
}
// Return result of check.
return bOK ;
}
//*****************************************************************************************************************
// We accept valid references for working with container only.
sal_Bool FrameContainer::impldbg_checkParameter_remove( const Reference< XFrame >& xFrame ) const
{
// Set default return value.
sal_Bool bOK = sal_True;
// Check parameter.
if (
( &xFrame == NULL ) ||
( xFrame.is() == sal_False )
)
{
bOK = sal_False ;
}
// Return result of check.
return bOK ;
}
//*****************************************************************************************************************
// We accept valid references for working with container only.
sal_Bool FrameContainer::impldbg_checkParameter_exist( const Reference< XFrame >& xFrame ) const
{
// Set default return value.
sal_Bool bOK = sal_True;
// Check parameter.
if (
( &xFrame == NULL ) ||
( xFrame.is() == sal_False )
)
{
bOK = sal_False ;
}
// Return result of check.
return bOK ;
}
//*****************************************************************************************************************
// The index in to the container must be in range of 0 and count-1!
sal_Bool FrameContainer::impldbg_checkParameter_IndexOperator( sal_uInt32 nIndex ) const
{
// Set default return value.
sal_Bool bOK = sal_True;
// Check parameter.
if (
( nIndex >= (sal_uInt32)m_aContainer.size() )
)
{
bOK = sal_False ;
}
// Return result of check.
return bOK ;
}
//*****************************************************************************************************************
// setActive accept valid- or null-reference but no null-pointer!
sal_Bool FrameContainer::impldbg_checkParameter_setActive( const Reference< XFrame >& xFrame ) const
{
// Set default return value.
sal_Bool bOK = sal_True;
// Check parameter.
if (
( &xFrame == NULL )
)
{
bOK = sal_False ;
}
// Return result of check.
return bOK ;
}
//*****************************************************************************************************************
sal_Bool FrameContainer::impldbg_lookForZombieFrames( const Reference< XFrame >& xFrame ) const
{
// Step over all container items and search for a frame which contains no component.
// (He has no component window!)
// Use return value directly for an assert ...
sal_Bool bSuppressAssert = sal_True;
sal_Int32 nCount = m_aContainer.size();
for( sal_Int32 nPosition=0; nPosition<nCount; ++nPosition )
{
Reference< XFrame > xZombieFrame = m_aContainer.at(nPosition);
if (
( xZombieFrame.is() == sal_True ) &&
( xZombieFrame != xFrame ) &&
( xZombieFrame->getComponentWindow().is() == sal_False )
)
{
bSuppressAssert = sal_False;
}
}
return bSuppressAssert;
}
#endif // #ifdef ENABLE_ASSERTIONS
} // namespace framework
|