1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: progressmonitor.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 //____________________________________________________________________________________________________________
33 //____________________________________________________________________________________________________________
35 #include "progressmonitor.hxx"
37 //____________________________________________________________________________________________________________
38 // includes of other projects
39 //____________________________________________________________________________________________________________
40 #include <com/sun/star/awt/GradientStyle.hpp>
41 #include <com/sun/star/awt/RasterOperation.hpp>
42 #include <com/sun/star/awt/Gradient.hpp>
43 #include <com/sun/star/awt/XGraphics.hpp>
44 #include <com/sun/star/awt/PosSize.hpp>
45 #include <cppuhelper/typeprovider.hxx>
46 #include <tools/debug.hxx>
47 #include <tools/solar.h>
49 //____________________________________________________________________________________________________________
50 // includes of my project
51 //____________________________________________________________________________________________________________
52 #include "progressbar.hxx"
54 //____________________________________________________________________________________________________________
56 //____________________________________________________________________________________________________________
58 using namespace ::cppu
;
59 using namespace ::osl
;
60 using namespace ::rtl
;
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::lang
;
63 using namespace ::com::sun::star::awt
;
65 namespace unocontrols
{
67 //____________________________________________________________________________________________________________
69 //____________________________________________________________________________________________________________
71 ProgressMonitor::ProgressMonitor( const Reference
< XMultiServiceFactory
>& xFactory
)
72 : BaseContainerControl ( xFactory
)
74 // Its not allowed to work with member in this method (refcounter !!!)
75 // But with a HACK (++refcount) its "OK" :-(
78 // Create instances for fixedtext, button and progress ...
79 m_xTopic_Top
= Reference
< XFixedText
> ( xFactory
->createInstance ( OUString::createFromAscii( FIXEDTEXT_SERVICENAME
) ), UNO_QUERY
) ;
80 m_xText_Top
= Reference
< XFixedText
> ( xFactory
->createInstance ( OUString::createFromAscii( FIXEDTEXT_SERVICENAME
) ), UNO_QUERY
) ;
81 m_xTopic_Bottom
= Reference
< XFixedText
> ( xFactory
->createInstance ( OUString::createFromAscii( FIXEDTEXT_SERVICENAME
) ), UNO_QUERY
) ;
82 m_xText_Bottom
= Reference
< XFixedText
> ( xFactory
->createInstance ( OUString::createFromAscii( FIXEDTEXT_SERVICENAME
) ), UNO_QUERY
) ;
83 m_xButton
= Reference
< XButton
> ( xFactory
->createInstance ( OUString::createFromAscii( BUTTON_SERVICENAME
) ), UNO_QUERY
) ;
84 m_xProgressBar
= Reference
< XProgressBar
> ( xFactory
->createInstance ( OUString::createFromAscii( SERVICENAME_PROGRESSBAR
) ), UNO_QUERY
) ;
86 // ... cast controls to Reference< XControl > (for "setModel"!) ...
87 Reference
< XControl
> xRef_Topic_Top ( m_xTopic_Top
, UNO_QUERY
) ;
88 Reference
< XControl
> xRef_Text_Top ( m_xText_Top
, UNO_QUERY
) ;
89 Reference
< XControl
> xRef_Topic_Bottom ( m_xTopic_Bottom
, UNO_QUERY
) ;
90 Reference
< XControl
> xRef_Text_Bottom ( m_xText_Bottom
, UNO_QUERY
) ;
91 Reference
< XControl
> xRef_Button ( m_xButton
, UNO_QUERY
) ;
92 Reference
< XControl
> xRef_ProgressBar ( m_xProgressBar
, UNO_QUERY
) ;
95 xRef_Topic_Top
->setModel ( Reference
< XControlModel
> ( xFactory
->createInstance ( OUString::createFromAscii( FIXEDTEXT_MODELNAME
) ), UNO_QUERY
) ) ;
96 xRef_Text_Top
->setModel ( Reference
< XControlModel
> ( xFactory
->createInstance ( OUString::createFromAscii( FIXEDTEXT_MODELNAME
) ), UNO_QUERY
) ) ;
97 xRef_Topic_Bottom
->setModel ( Reference
< XControlModel
> ( xFactory
->createInstance ( OUString::createFromAscii( FIXEDTEXT_MODELNAME
) ), UNO_QUERY
) ) ;
98 xRef_Text_Bottom
->setModel ( Reference
< XControlModel
> ( xFactory
->createInstance ( OUString::createFromAscii( FIXEDTEXT_MODELNAME
) ), UNO_QUERY
) ) ;
99 xRef_Button
->setModel ( Reference
< XControlModel
> ( xFactory
->createInstance ( OUString::createFromAscii( BUTTON_MODELNAME
) ), UNO_QUERY
) ) ;
100 // ProgressBar has no model !!!
102 // ... and add controls to basecontainercontrol!
103 addControl ( OUString::createFromAscii( CONTROLNAME_TEXT
) , xRef_Topic_Top
) ;
104 addControl ( OUString::createFromAscii( CONTROLNAME_TEXT
) , xRef_Text_Top
) ;
105 addControl ( OUString::createFromAscii( CONTROLNAME_TEXT
) , xRef_Topic_Bottom
) ;
106 addControl ( OUString::createFromAscii( CONTROLNAME_TEXT
) , xRef_Text_Bottom
) ;
107 addControl ( OUString::createFromAscii( CONTROLNAME_BUTTON
) , xRef_Button
) ;
108 addControl ( OUString::createFromAscii( CONTROLNAME_PROGRESSBAR
) , xRef_ProgressBar
) ;
110 // FixedText make it automaticly visible by himself ... but not the progressbar !!!
111 // it must be set explicitly
112 Reference
< XWindow
> xWindowRef_ProgressBar( m_xProgressBar
, UNO_QUERY
);
113 xWindowRef_ProgressBar
->setVisible( sal_True
);
115 // Reset to defaults !!!
116 // (progressbar take automaticly its own defaults)
117 m_xButton
->setLabel ( OUString::createFromAscii( DEFAULT_BUTTONLABEL
) ) ;
118 m_xTopic_Top
->setText ( OUString::createFromAscii( DEFAULT_TOPIC
) ) ;
119 m_xText_Top
->setText ( OUString::createFromAscii( DEFAULT_TEXT
) ) ;
120 m_xTopic_Bottom
->setText ( OUString::createFromAscii( DEFAULT_TOPIC
) ) ;
121 m_xText_Bottom
->setText ( OUString::createFromAscii( DEFAULT_TEXT
) ) ;
125 // Initialize info lists for fixedtext's
126 m_pTextlist_Top
= new IMPL_Textlist
;
127 m_pTextlist_Bottom
= new IMPL_Textlist
;
130 ProgressMonitor::~ProgressMonitor()
132 impl_cleanMemory () ;
135 //____________________________________________________________________________________________________________
137 //____________________________________________________________________________________________________________
139 Any SAL_CALL
ProgressMonitor::queryInterface( const Type
& rType
) throw( RuntimeException
)
142 // Don't use mutex or guard in this method!!! Is a method of XInterface.
144 Reference
< XInterface
> xDel
= BaseContainerControl::impl_getDelegator();
147 // If an delegator exist, forward question to his queryInterface.
148 // Delegator will ask his own queryAggregation!
149 aReturn
= xDel
->queryInterface( rType
);
153 // If an delegator unknown, forward question to own queryAggregation.
154 aReturn
= queryAggregation( rType
);
160 //____________________________________________________________________________________________________________
162 //____________________________________________________________________________________________________________
164 void SAL_CALL
ProgressMonitor::acquire() throw()
167 // Don't use mutex or guard in this method!!! Is a method of XInterface.
169 // Forward to baseclass
170 BaseControl::acquire();
173 //____________________________________________________________________________________________________________
175 //____________________________________________________________________________________________________________
177 void SAL_CALL
ProgressMonitor::release() throw()
180 // Don't use mutex or guard in this method!!! Is a method of XInterface.
182 // Forward to baseclass
183 BaseControl::release();
186 //____________________________________________________________________________________________________________
188 //____________________________________________________________________________________________________________
190 Sequence
< Type
> SAL_CALL
ProgressMonitor::getTypes() throw( RuntimeException
)
192 // Optimize this method !
193 // We initialize a static variable only one time. And we don't must use a mutex at every call!
194 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
195 static OTypeCollection
* pTypeCollection
= NULL
;
197 if ( pTypeCollection
== NULL
)
199 // Ready for multithreading; get global mutex for first call of this method only! see before
200 MutexGuard
aGuard( Mutex::getGlobalMutex() );
202 // Control these pointer again ... it can be, that another instance will be faster then these!
203 if ( pTypeCollection
== NULL
)
205 // Create a static typecollection ...
206 static OTypeCollection
aTypeCollection ( ::getCppuType(( const Reference
< XLayoutConstrains
>*)NULL
) ,
207 ::getCppuType(( const Reference
< XButton
>*)NULL
) ,
208 ::getCppuType(( const Reference
< XProgressMonitor
>*)NULL
) ,
209 BaseContainerControl::getTypes()
211 // ... and set his address to static pointer!
212 pTypeCollection
= &aTypeCollection
;
216 return pTypeCollection
->getTypes();
219 //____________________________________________________________________________________________________________
221 //____________________________________________________________________________________________________________
223 Any SAL_CALL
ProgressMonitor::queryAggregation( const Type
& aType
) throw( RuntimeException
)
225 // Ask for my own supported interfaces ...
226 // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
227 Any
aReturn ( ::cppu::queryInterface( aType
,
228 static_cast< XLayoutConstrains
* > ( this ) ,
229 static_cast< XButton
* > ( this ) ,
230 static_cast< XProgressMonitor
* > ( this )
234 // If searched interface not supported by this class ...
235 if ( aReturn
.hasValue() == sal_False
)
237 // ... ask baseclasses.
238 aReturn
= BaseControl::queryAggregation( aType
);
244 //____________________________________________________________________________________________________________
246 //____________________________________________________________________________________________________________
248 void SAL_CALL
ProgressMonitor::addText( const OUString
& rTopic
, const OUString
& rText
, sal_Bool bbeforeProgress
) throw( RuntimeException
)
250 // Safe impossible cases
251 // Check valid call of this method.
252 DBG_ASSERT ( impl_debug_checkParameter ( rTopic
, rText
, bbeforeProgress
) , "ProgressMonitor::addText()\nCall without valid parameters!\n") ;
253 DBG_ASSERT ( !(impl_searchTopic ( rTopic
, bbeforeProgress
) != NULL
) , "ProgresMonitor::addText()\nThe text already exist.\n" ) ;
255 // Do nothing (in Release), if topic already exist.
256 if ( impl_searchTopic ( rTopic
, bbeforeProgress
) != NULL
)
261 // Else ... take memory for new item ...
262 IMPL_TextlistItem
* pTextItem
= new IMPL_TextlistItem
;
264 if ( pTextItem
!= NULL
)
267 pTextItem
->sTopic
= rTopic
;
268 pTextItem
->sText
= rText
;
270 // Ready for multithreading
271 MutexGuard
aGuard ( m_aMutex
) ;
273 // ... and insert it in right list.
274 if ( bbeforeProgress
== sal_True
)
276 m_pTextlist_Top
->Insert ( pTextItem
, LIST_APPEND
) ;
280 m_pTextlist_Bottom
->Insert ( pTextItem
, LIST_APPEND
) ;
285 impl_rebuildFixedText () ;
286 impl_recalcLayout () ;
289 //____________________________________________________________________________________________________________
291 //____________________________________________________________________________________________________________
293 void SAL_CALL
ProgressMonitor::removeText ( const OUString
& rTopic
, sal_Bool bbeforeProgress
) throw( RuntimeException
)
295 // Safe impossible cases
296 // Check valid call of this method.
297 DBG_ASSERT ( impl_debug_checkParameter ( rTopic
, bbeforeProgress
), "ProgressMonitor::removeText()\nCall without valid parameters!\n" ) ;
299 // Search the topic ...
300 IMPL_TextlistItem
* pSearchItem
= impl_searchTopic ( rTopic
, bbeforeProgress
) ;
302 if ( pSearchItem
!= NULL
)
304 // Ready for multithreading
305 MutexGuard
aGuard ( m_aMutex
) ;
307 // ... delete item from right list ...
308 if ( bbeforeProgress
== sal_True
)
310 m_pTextlist_Top
->Remove ( pSearchItem
) ;
314 m_pTextlist_Bottom
->Remove ( pSearchItem
) ;
319 // ... and update window.
320 impl_rebuildFixedText () ;
321 impl_recalcLayout () ;
325 //____________________________________________________________________________________________________________
327 //____________________________________________________________________________________________________________
329 void SAL_CALL
ProgressMonitor::updateText ( const OUString
& rTopic
, const OUString
& rText
, sal_Bool bbeforeProgress
) throw( RuntimeException
)
331 // Safe impossible cases
332 // Check valid call of this method.
333 DBG_ASSERT ( impl_debug_checkParameter ( rTopic
, rText
, bbeforeProgress
), "ProgressMonitor::updateText()\nCall without valid parameters!\n" ) ;
336 IMPL_TextlistItem
* pSearchItem
= impl_searchTopic ( rTopic
, bbeforeProgress
) ;
338 if ( pSearchItem
!= NULL
)
340 // Ready for multithreading
341 MutexGuard
aGuard ( m_aMutex
) ;
343 // ... update text ...
344 pSearchItem
->sText
= rText
;
346 // ... and update window.
347 impl_rebuildFixedText () ;
348 impl_recalcLayout () ;
352 //____________________________________________________________________________________________________________
354 //____________________________________________________________________________________________________________
356 void SAL_CALL
ProgressMonitor::setForegroundColor ( sal_Int32 nColor
) throw( RuntimeException
)
358 // Ready for multithreading
359 MutexGuard
aGuard ( m_aMutex
) ;
361 if ( m_xProgressBar
.is () )
363 m_xProgressBar
->setForegroundColor ( nColor
) ;
367 //____________________________________________________________________________________________________________
369 //____________________________________________________________________________________________________________
371 void SAL_CALL
ProgressMonitor::setBackgroundColor ( sal_Int32 nColor
) throw( RuntimeException
)
373 // Ready for multithreading
374 MutexGuard
aGuard ( m_aMutex
) ;
376 if ( m_xProgressBar
.is () )
378 m_xProgressBar
->setBackgroundColor ( nColor
) ;
382 //____________________________________________________________________________________________________________
384 //____________________________________________________________________________________________________________
386 void SAL_CALL
ProgressMonitor::setValue ( sal_Int32 nValue
) throw( RuntimeException
)
388 // Ready for multithreading
389 MutexGuard
aGuard ( m_aMutex
) ;
391 if ( m_xProgressBar
.is () )
393 m_xProgressBar
->setValue ( nValue
) ;
397 //____________________________________________________________________________________________________________
399 //____________________________________________________________________________________________________________
401 void SAL_CALL
ProgressMonitor::setRange ( sal_Int32 nMin
, sal_Int32 nMax
) throw( RuntimeException
)
403 // Ready for multithreading
404 MutexGuard
aGuard ( m_aMutex
) ;
406 if ( m_xProgressBar
.is () )
408 m_xProgressBar
->setRange ( nMin
, nMax
) ;
412 //____________________________________________________________________________________________________________
414 //____________________________________________________________________________________________________________
416 sal_Int32 SAL_CALL
ProgressMonitor::getValue () throw( RuntimeException
)
418 // Ready for multithreading
419 MutexGuard
aGuard ( m_aMutex
) ;
421 if (m_xProgressBar
.is())
423 return m_xProgressBar
->getValue () ;
429 //____________________________________________________________________________________________________________
431 //____________________________________________________________________________________________________________
433 void SAL_CALL
ProgressMonitor::addActionListener ( const Reference
< XActionListener
> & rListener
) throw( RuntimeException
)
435 // Ready for multithreading
436 MutexGuard
aGuard ( m_aMutex
) ;
438 if ( m_xButton
.is () )
440 m_xButton
->addActionListener ( rListener
) ;
444 //____________________________________________________________________________________________________________
446 //____________________________________________________________________________________________________________
448 void SAL_CALL
ProgressMonitor::removeActionListener ( const Reference
< XActionListener
> & rListener
) throw( RuntimeException
)
450 // Ready for multithreading
451 MutexGuard
aGuard ( m_aMutex
) ;
453 if ( m_xButton
.is () )
455 m_xButton
->removeActionListener ( rListener
) ;
459 //____________________________________________________________________________________________________________
461 //____________________________________________________________________________________________________________
463 void SAL_CALL
ProgressMonitor::setLabel ( const OUString
& rLabel
) throw( RuntimeException
)
465 // Ready for multithreading
466 MutexGuard
aGuard ( m_aMutex
) ;
468 if ( m_xButton
.is () )
470 m_xButton
->setLabel ( rLabel
) ;
474 //____________________________________________________________________________________________________________
476 //____________________________________________________________________________________________________________
478 void SAL_CALL
ProgressMonitor::setActionCommand ( const OUString
& rCommand
) throw( RuntimeException
)
480 // Ready for multithreading
481 MutexGuard
aGuard ( m_aMutex
) ;
483 if ( m_xButton
.is () )
485 m_xButton
->setActionCommand ( rCommand
) ;
489 //____________________________________________________________________________________________________________
491 //____________________________________________________________________________________________________________
493 Size SAL_CALL
ProgressMonitor::getMinimumSize () throw( RuntimeException
)
495 return Size (DEFAULT_WIDTH
, DEFAULT_HEIGHT
) ;
498 //____________________________________________________________________________________________________________
500 //____________________________________________________________________________________________________________
502 Size SAL_CALL
ProgressMonitor::getPreferredSize () throw( RuntimeException
)
504 // Ready for multithreading
505 ClearableMutexGuard
aGuard ( m_aMutex
) ;
507 // get information about required place of child controls
508 Reference
< XLayoutConstrains
> xTopicLayout_Top ( m_xTopic_Top
, UNO_QUERY
) ;
509 Reference
< XLayoutConstrains
> xTopicLayout_Bottom ( m_xTopic_Bottom
, UNO_QUERY
) ;
510 Reference
< XLayoutConstrains
> xButtonLayout ( m_xButton
, UNO_QUERY
) ;
511 Reference
< XWindow
> xProgressBarWindow ( m_xProgressBar
, UNO_QUERY
) ;
513 Size aTopicSize_Top
= xTopicLayout_Top
->getPreferredSize ();
514 Size aTopicSize_Bottom
= xTopicLayout_Bottom
->getPreferredSize ();
515 Size aButtonSize
= xButtonLayout
->getPreferredSize ();
516 Rectangle aTempRectangle
= xProgressBarWindow
->getPosSize ();
517 Size aProgressBarSize
= Size( aTempRectangle
.Width
, aTempRectangle
.Height
);
521 // calc preferred size of progressmonitor
522 sal_Int32 nWidth
= 0 ;
523 sal_Int32 nHeight
= 0 ;
525 nWidth
= 3 * FREEBORDER
;
526 nWidth
+= aProgressBarSize
.Width
;
528 nHeight
= 6 * FREEBORDER
;
529 nHeight
+= aTopicSize_Top
.Height
;
530 nHeight
+= aProgressBarSize
.Height
;
531 nHeight
+= aTopicSize_Bottom
.Height
;
532 nHeight
+= 2 ; // 1 for black line, 1 for white line = 3D-Line!
533 nHeight
+= aButtonSize
.Height
;
536 if ( nWidth
<DEFAULT_WIDTH
)
538 nWidth
= DEFAULT_WIDTH
;
540 if ( nHeight
<DEFAULT_HEIGHT
)
542 nHeight
= DEFAULT_HEIGHT
;
546 return Size ( nWidth
, nHeight
) ;
549 //____________________________________________________________________________________________________________
551 //____________________________________________________________________________________________________________
553 Size SAL_CALL
ProgressMonitor::calcAdjustedSize ( const Size
& /*rNewSize*/ ) throw( RuntimeException
)
555 return getPreferredSize () ;
558 //____________________________________________________________________________________________________________
560 //____________________________________________________________________________________________________________
562 void SAL_CALL
ProgressMonitor::createPeer ( const Reference
< XToolkit
> & rToolkit
, const Reference
< XWindowPeer
> & rParent
) throw( RuntimeException
)
566 BaseContainerControl::createPeer ( rToolkit
, rParent
) ;
568 // If user forget to call "setPosSize()", we have still a correct size.
569 // And a "MinimumSize" IS A "MinimumSize"!
570 // We change not the position of control at this point.
571 Size aDefaultSize
= getMinimumSize () ;
572 setPosSize ( 0, 0, aDefaultSize
.Width
, aDefaultSize
.Height
, PosSize::SIZE
) ;
576 //____________________________________________________________________________________________________________
578 //____________________________________________________________________________________________________________
580 sal_Bool SAL_CALL
ProgressMonitor::setModel ( const Reference
< XControlModel
> & /*rModel*/ ) throw( RuntimeException
)
586 //____________________________________________________________________________________________________________
588 //____________________________________________________________________________________________________________
590 Reference
< XControlModel
> SAL_CALL
ProgressMonitor::getModel () throw( RuntimeException
)
593 // return (XControlModel*)this ;
594 return Reference
< XControlModel
> () ;
597 //____________________________________________________________________________________________________________
599 //____________________________________________________________________________________________________________
601 void SAL_CALL
ProgressMonitor::dispose () throw( RuntimeException
)
603 // Ready for multithreading
604 MutexGuard
aGuard ( m_aMutex
) ;
606 // "removeControl()" control the state of a reference
607 Reference
< XControl
> xRef_Topic_Top ( m_xTopic_Top
, UNO_QUERY
) ;
608 Reference
< XControl
> xRef_Text_Top ( m_xText_Top
, UNO_QUERY
) ;
609 Reference
< XControl
> xRef_Topic_Bottom ( m_xTopic_Bottom
, UNO_QUERY
) ;
610 Reference
< XControl
> xRef_Text_Bottom ( m_xText_Bottom
, UNO_QUERY
) ;
611 Reference
< XControl
> xRef_Button ( m_xButton
, UNO_QUERY
) ;
612 Reference
< XControl
> xRef_ProgressBar ( m_xProgressBar
, UNO_QUERY
) ;
614 removeControl ( xRef_Topic_Top
) ;
615 removeControl ( xRef_Text_Top
) ;
616 removeControl ( xRef_Topic_Bottom
) ;
617 removeControl ( xRef_Text_Bottom
) ;
618 removeControl ( xRef_Button
) ;
619 removeControl ( xRef_ProgressBar
) ;
621 // do'nt use "...->clear ()" or "... = XFixedText ()"
622 // when other hold a reference at this object !!!
623 xRef_Topic_Top
->dispose () ;
624 xRef_Text_Top
->dispose () ;
625 xRef_Topic_Bottom
->dispose () ;
626 xRef_Text_Bottom
->dispose () ;
627 xRef_Button
->dispose () ;
628 xRef_ProgressBar
->dispose () ;
630 BaseContainerControl::dispose () ;
633 //____________________________________________________________________________________________________________
635 //____________________________________________________________________________________________________________
637 void SAL_CALL
ProgressMonitor::setPosSize ( sal_Int32 nX
, sal_Int32 nY
, sal_Int32 nWidth
, sal_Int32 nHeight
, sal_Int16 nFlags
) throw( RuntimeException
)
639 Rectangle aBasePosSize
= getPosSize () ;
640 BaseContainerControl::setPosSize (nX
, nY
, nWidth
, nHeight
, nFlags
) ;
642 // if position or size changed
644 ( nWidth
!= aBasePosSize
.Width
) ||
645 ( nHeight
!= aBasePosSize
.Height
)
648 // calc new layout for controls
649 impl_recalcLayout () ;
650 // clear background (!)
651 // [Childs was repainted in "recalcLayout" by setPosSize() automaticly!]
652 getPeer()->invalidate(2);
653 // and repaint the control
654 impl_paint ( 0, 0, impl_getGraphicsPeer() ) ;
658 //____________________________________________________________________________________________________________
659 // impl but public method to register service
660 //____________________________________________________________________________________________________________
662 const Sequence
< OUString
> ProgressMonitor::impl_getStaticSupportedServiceNames()
664 MutexGuard
aGuard( Mutex::getGlobalMutex() );
665 Sequence
< OUString
> seqServiceNames( 1 );
666 seqServiceNames
.getArray() [0] = OUString::createFromAscii( SERVICENAME_PROGRESSMONITOR
);
667 return seqServiceNames
;
670 //____________________________________________________________________________________________________________
671 // impl but public method to register service
672 //____________________________________________________________________________________________________________
674 const OUString
ProgressMonitor::impl_getStaticImplementationName()
676 return OUString::createFromAscii( IMPLEMENTATIONNAME_PROGRESSMONITOR
);
679 //____________________________________________________________________________________________________________
681 //____________________________________________________________________________________________________________
683 void ProgressMonitor::impl_paint ( sal_Int32 nX
, sal_Int32 nY
, const Reference
< XGraphics
> & rGraphics
)
687 // Ready for multithreading
688 MutexGuard
aGuard ( m_aMutex
) ;
690 // paint shadowed border around the progressmonitor
691 rGraphics
->setLineColor ( LINECOLOR_SHADOW
) ;
692 rGraphics
->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY
) ;
693 rGraphics
->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX
, impl_getHeight()-1 ) ;
695 rGraphics
->setLineColor ( LINECOLOR_BRIGHT
) ;
696 rGraphics
->drawLine ( nX
, nY
, impl_getWidth(), nY
) ;
697 rGraphics
->drawLine ( nX
, nY
, nX
, impl_getHeight() ) ;
700 rGraphics
->setLineColor ( LINECOLOR_SHADOW
) ;
701 rGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
) ;
703 rGraphics
->setLineColor ( LINECOLOR_BRIGHT
) ;
704 rGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
+1, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
+1 ) ;
708 //____________________________________________________________________________________________________________
710 //____________________________________________________________________________________________________________
712 void ProgressMonitor::impl_recalcLayout ()
714 sal_Int32 nX_Button
;
715 sal_Int32 nY_Button
;
716 sal_Int32 nWidth_Button
;
717 sal_Int32 nHeight_Button
;
719 sal_Int32 nX_ProgressBar
;
720 sal_Int32 nY_ProgressBar
;
721 sal_Int32 nWidth_ProgressBar
;
722 sal_Int32 nHeight_ProgressBar
;
724 sal_Int32 nX_3DLine
;
725 sal_Int32 nY_3DLine
;
726 sal_Int32 nWidth_3DLine
;
727 sal_Int32 nHeight_3DLine
;
729 sal_Int32 nX_Text_Top
;
730 sal_Int32 nY_Text_Top
;
731 sal_Int32 nWidth_Text_Top
;
732 sal_Int32 nHeight_Text_Top
;
734 sal_Int32 nX_Topic_Top
;
735 sal_Int32 nY_Topic_Top
;
736 sal_Int32 nWidth_Topic_Top
;
737 sal_Int32 nHeight_Topic_Top
;
739 sal_Int32 nX_Text_Bottom
;
740 sal_Int32 nY_Text_Bottom
;
741 sal_Int32 nWidth_Text_Bottom
;
742 sal_Int32 nHeight_Text_Bottom
;
744 sal_Int32 nX_Topic_Bottom
;
745 sal_Int32 nY_Topic_Bottom
;
746 sal_Int32 nWidth_Topic_Bottom
;
747 sal_Int32 nHeight_Topic_Bottom
;
749 // Ready for multithreading
750 MutexGuard
aGuard ( m_aMutex
) ;
752 // get information about required place of child controls
753 Reference
< XLayoutConstrains
> xTopicLayout_Top ( m_xTopic_Top
, UNO_QUERY
) ;
754 Reference
< XLayoutConstrains
> xTextLayout_Top ( m_xText_Top
, UNO_QUERY
) ;
755 Reference
< XLayoutConstrains
> xTopicLayout_Bottom ( m_xTopic_Bottom
, UNO_QUERY
) ;
756 Reference
< XLayoutConstrains
> xTextLayout_Bottom ( m_xText_Bottom
, UNO_QUERY
) ;
757 Reference
< XLayoutConstrains
> xButtonLayout ( m_xButton
, UNO_QUERY
) ;
759 Size aTopicSize_Top
= xTopicLayout_Top
->getPreferredSize () ;
760 Size aTextSize_Top
= xTextLayout_Top
->getPreferredSize () ;
761 Size aTopicSize_Bottom
= xTopicLayout_Bottom
->getPreferredSize () ;
762 Size aTextSize_Bottom
= xTextLayout_Bottom
->getPreferredSize () ;
763 Size aButtonSize
= xButtonLayout
->getPreferredSize () ;
765 // calc position and size of child controls
766 // Button has preferred size!
767 nWidth_Button
= aButtonSize
.Width
;
768 nHeight_Button
= aButtonSize
.Height
;
770 // Left column before progressbar has preferred size and fixed position.
771 // But "Width" is oriented on left column below progressbar to!!! "max(...)"
772 nX_Topic_Top
= FREEBORDER
;
773 nY_Topic_Top
= FREEBORDER
;
774 nWidth_Topic_Top
= Max ( aTopicSize_Top
.Width
, aTopicSize_Bottom
.Width
) ;
775 nHeight_Topic_Top
= aTopicSize_Top
.Height
;
777 // Right column before progressbar has relativ position to left column ...
778 // ... and a size as rest of dialog size!
779 nX_Text_Top
= nX_Topic_Top
+nWidth_Topic_Top
+FREEBORDER
;
780 nY_Text_Top
= nY_Topic_Top
;
781 nWidth_Text_Top
= Max ( aTextSize_Top
.Width
, aTextSize_Bottom
.Width
) ;
782 // Fix size of this column to minimum!
783 sal_Int32 nSummaryWidth
= nWidth_Text_Top
+nWidth_Topic_Top
+(3*FREEBORDER
) ;
784 if ( nSummaryWidth
< DEFAULT_WIDTH
)
785 nWidth_Text_Top
= DEFAULT_WIDTH
-nWidth_Topic_Top
-(3*FREEBORDER
);
786 // Fix size of column to maximum!
787 if ( nSummaryWidth
> impl_getWidth() )
788 nWidth_Text_Top
= impl_getWidth()-nWidth_Topic_Top
-(3*FREEBORDER
) ;
789 nHeight_Text_Top
= nHeight_Topic_Top
;
791 // Position of progressbar is relativ to columns before.
792 // Progressbar.Width = Dialog.Width !!!
793 // Progressbar.Height = Button.Height
794 nX_ProgressBar
= nX_Topic_Top
;
795 nY_ProgressBar
= nY_Topic_Top
+nHeight_Topic_Top
+FREEBORDER
;
796 nWidth_ProgressBar
= FREEBORDER
+nWidth_Topic_Top
+nWidth_Text_Top
;
797 nHeight_ProgressBar
= nHeight_Button
;
799 // Oriented by left column before progressbar.
800 nX_Topic_Bottom
= nX_Topic_Top
;
801 nY_Topic_Bottom
= nY_ProgressBar
+nHeight_ProgressBar
+FREEBORDER
;
802 nWidth_Topic_Bottom
= nWidth_Topic_Top
;
803 nHeight_Topic_Bottom
= aTopicSize_Bottom
.Height
;
805 // Oriented by right column before progressbar.
806 nX_Text_Bottom
= nX_Topic_Bottom
+nWidth_Topic_Bottom
+FREEBORDER
;
807 nY_Text_Bottom
= nY_Topic_Bottom
;
808 nWidth_Text_Bottom
= nWidth_Text_Top
;
809 nHeight_Text_Bottom
= nHeight_Topic_Bottom
;
811 // Oriented by progressbar.
812 nX_3DLine
= nX_Topic_Top
;
813 nY_3DLine
= nY_Topic_Bottom
+nHeight_Topic_Bottom
+(FREEBORDER
/2) ;
814 nWidth_3DLine
= nWidth_ProgressBar
;
815 nHeight_3DLine
= 1 ; // Height for ONE line ! (But we paint two lines!)
817 // Oriented by progressbar.
818 nX_Button
= nX_ProgressBar
+nWidth_ProgressBar
-nWidth_Button
;
819 nY_Button
= nY_Topic_Bottom
+nHeight_Topic_Bottom
+FREEBORDER
;
821 // Calc offsets to center controls
825 nDx
= ( (2*FREEBORDER
)+nWidth_ProgressBar
) ;
826 nDy
= ( (6*FREEBORDER
)+nHeight_Topic_Top
+nHeight_ProgressBar
+nHeight_Topic_Bottom
+2+nHeight_Button
) ;
828 // At this point use original dialog size to center controls!
829 nDx
= (impl_getWidth ()/2)-(nDx
/2) ;
830 nDy
= (impl_getHeight()/2)-(nDy
/2) ;
841 // Set new position and size on all controls
842 Reference
< XWindow
> xRef_Topic_Top ( m_xTopic_Top
, UNO_QUERY
) ;
843 Reference
< XWindow
> xRef_Text_Top ( m_xText_Top
, UNO_QUERY
) ;
844 Reference
< XWindow
> xRef_Topic_Bottom ( m_xTopic_Bottom
, UNO_QUERY
) ;
845 Reference
< XWindow
> xRef_Text_Bottom ( m_xText_Bottom
, UNO_QUERY
) ;
846 Reference
< XWindow
> xRef_Button ( m_xButton
, UNO_QUERY
) ;
847 Reference
< XWindow
> xRef_ProgressBar ( m_xProgressBar
, UNO_QUERY
) ;
849 xRef_Topic_Top
->setPosSize ( nDx
+nX_Topic_Top
, nDy
+nY_Topic_Top
, nWidth_Topic_Top
, nHeight_Topic_Top
, 15 ) ;
850 xRef_Text_Top
->setPosSize ( nDx
+nX_Text_Top
, nDy
+nY_Text_Top
, nWidth_Text_Top
, nHeight_Text_Top
, 15 ) ;
851 xRef_Topic_Bottom
->setPosSize ( nDx
+nX_Topic_Bottom
, nDy
+nY_Topic_Bottom
, nWidth_Topic_Bottom
, nHeight_Topic_Bottom
, 15 ) ;
852 xRef_Text_Bottom
->setPosSize ( nDx
+nX_Text_Bottom
, nDy
+nY_Text_Bottom
, nWidth_Text_Bottom
, nHeight_Text_Bottom
, 15 ) ;
853 xRef_Button
->setPosSize ( nDx
+nX_Button
, nDy
+nY_Button
, nWidth_Button
, nHeight_Button
, 15 ) ;
854 xRef_ProgressBar
->setPosSize ( nDx
+nX_ProgressBar
, nDy
+nY_ProgressBar
, nWidth_ProgressBar
, nHeight_ProgressBar
, 15 ) ;
856 m_a3DLine
.X
= nDx
+nX_Topic_Top
;
857 m_a3DLine
.Y
= nDy
+nY_Topic_Bottom
+nHeight_Topic_Bottom
+(FREEBORDER
/2) ;
858 m_a3DLine
.Width
= nWidth_ProgressBar
;
859 m_a3DLine
.Height
= nHeight_ProgressBar
;
861 // All childcontrols make an implicit repaint in setPosSize()!
862 // Make it also for this 3D-line ...
863 Reference
< XGraphics
> xGraphics
= impl_getGraphicsPeer () ;
865 xGraphics
->setLineColor ( LINECOLOR_SHADOW
) ;
866 xGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
) ;
868 xGraphics
->setLineColor ( LINECOLOR_BRIGHT
) ;
869 xGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
+1, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
+1 ) ;
872 //____________________________________________________________________________________________________________
874 //____________________________________________________________________________________________________________
876 void ProgressMonitor::impl_rebuildFixedText ()
878 // Ready for multithreading
879 MutexGuard
aGuard ( m_aMutex
) ;
881 // Rebuild fixedtext before progress
883 // Rebuild left site of text
884 if (m_xTopic_Top
.is())
886 OUString aCollectString
;
888 // Collect all topics from list and format text.
889 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
890 for ( sal_uInt32 n
=0; n
<m_pTextlist_Top
->Count(); ++n
)
892 IMPL_TextlistItem
* pSearchItem
= m_pTextlist_Top
->GetObject (n
) ;
893 aCollectString
+= pSearchItem
->sTopic
;
894 aCollectString
+= OUString::createFromAscii("\n") ;
896 aCollectString
+= OUString::createFromAscii("\0") ; // It's better :-)
898 m_xTopic_Top
->setText ( aCollectString
) ;
901 // Rebuild right site of text
902 if (m_xText_Top
.is())
904 OUString aCollectString
;
906 // Collect all topics from list and format text.
907 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
908 for ( sal_uInt32 n
=0; n
<m_pTextlist_Top
->Count(); ++n
)
910 IMPL_TextlistItem
* pSearchItem
= m_pTextlist_Top
->GetObject (n
) ;
911 aCollectString
+= pSearchItem
->sText
;
912 aCollectString
+= OUString::createFromAscii("\n") ;
914 aCollectString
+= OUString::createFromAscii("\0") ; // It's better :-)
916 m_xText_Top
->setText ( aCollectString
) ;
919 // Rebuild fixedtext below progress
921 // Rebuild left site of text
922 if (m_xTopic_Bottom
.is())
924 OUString aCollectString
;
926 // Collect all topics from list and format text.
927 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
928 for ( sal_uInt32 n
=0; n
<m_pTextlist_Bottom
->Count(); ++n
)
930 IMPL_TextlistItem
* pSearchItem
= m_pTextlist_Bottom
->GetObject (n
) ;
931 aCollectString
+= pSearchItem
->sTopic
;
932 aCollectString
+= OUString::createFromAscii("\n") ;
934 aCollectString
+= OUString::createFromAscii("\0") ; // It's better :-)
936 m_xTopic_Bottom
->setText ( aCollectString
) ;
939 // Rebuild right site of text
940 if (m_xText_Bottom
.is())
942 OUString aCollectString
;
944 // Collect all topics from list and format text.
945 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
946 for ( sal_uInt32 n
=0; n
<m_pTextlist_Bottom
->Count(); ++n
)
948 IMPL_TextlistItem
* pSearchItem
= m_pTextlist_Bottom
->GetObject (n
) ;
949 aCollectString
+= pSearchItem
->sText
;
950 aCollectString
+= OUString::createFromAscii("\n") ;
952 aCollectString
+= OUString::createFromAscii("\0") ; // It's better :-)
954 m_xText_Bottom
->setText ( aCollectString
) ;
958 //____________________________________________________________________________________________________________
960 //____________________________________________________________________________________________________________
962 void ProgressMonitor::impl_cleanMemory ()
964 // Ready for multithreading
965 MutexGuard
aGuard ( m_aMutex
) ;
967 // Delete all of lists.
969 sal_uInt32 nPosition
;
971 for ( nPosition
= 0; nPosition
< m_pTextlist_Top
->Count () ; ++nPosition
)
973 IMPL_TextlistItem
* pSearchItem
= m_pTextlist_Top
->GetObject ( nPosition
) ;
976 m_pTextlist_Top
->Clear () ;
977 delete m_pTextlist_Top
;
979 for ( nPosition
= 0; nPosition
< m_pTextlist_Bottom
->Count () ; ++nPosition
)
981 IMPL_TextlistItem
* pSearchItem
= m_pTextlist_Bottom
->GetObject ( nPosition
) ;
984 m_pTextlist_Bottom
->Clear () ;
985 delete m_pTextlist_Bottom
;
988 //____________________________________________________________________________________________________________
990 //____________________________________________________________________________________________________________
992 IMPL_TextlistItem
* ProgressMonitor::impl_searchTopic ( const OUString
& rTopic
, sal_Bool bbeforeProgress
)
994 // Get right textlist for following operations.
995 IMPL_Textlist
* pTextList
;
997 // Ready for multithreading
998 ClearableMutexGuard
aGuard ( m_aMutex
) ;
1000 if ( bbeforeProgress
== sal_True
)
1002 pTextList
= m_pTextlist_Top
;
1006 pTextList
= m_pTextlist_Bottom
;
1009 // Switch off guard.
1012 // Search the topic in textlist.
1013 sal_uInt32 nPosition
= 0 ;
1014 sal_uInt32 nCount
= pTextList
->Count () ;
1016 for ( nPosition
= 0; nPosition
< nCount
; ++nPosition
)
1018 IMPL_TextlistItem
* pSearchItem
= pTextList
->GetObject ( nPosition
) ;
1020 if ( pSearchItem
->sTopic
== rTopic
)
1022 // We have found this topic ... return a valid pointer.
1023 return pSearchItem
;
1027 // We have'nt found this topic ... return a nonvalid pointer.
1031 //____________________________________________________________________________________________________________
1033 //____________________________________________________________________________________________________________
1037 // addText, updateText
1038 sal_Bool
ProgressMonitor::impl_debug_checkParameter ( const OUString
& rTopic
, const OUString
& rText
, sal_Bool
/*bbeforeProgress*/ )
1041 if ( &rTopic
== NULL
) return sal_False
; // NULL-pointer for reference ???!!!
1042 if ( rTopic
.getLength () < 1 ) return sal_False
; // ""
1045 if ( &rText
== NULL
) return sal_False
; // NULL-pointer for reference ???!!!
1046 if ( rText
.getLength () < 1 ) return sal_False
; // ""
1048 // "bbeforeProgress" is valid in everyway!
1050 // Parameter OK ... return sal_True.
1055 sal_Bool
ProgressMonitor::impl_debug_checkParameter ( const OUString
& rTopic
, sal_Bool
/*bbeforeProgress*/ )
1058 if ( &rTopic
== NULL
) return sal_False
; // NULL-pointer for reference ???!!!
1059 if ( rTopic
.getLength () < 1 ) return sal_False
; // ""
1061 // "bbeforeProgress" is valid in everyway!
1063 // Parameter OK ... return sal_True.
1067 #endif // #ifdef DBG_UTIL
1069 } // namespace unocontrols