1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <progressmonitor.hxx>
22 #include <com/sun/star/awt/XFixedText.hpp>
23 #include <com/sun/star/awt/XGraphics.hpp>
24 #include <com/sun/star/awt/PosSize.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <cppuhelper/typeprovider.hxx>
27 #include <cppuhelper/queryinterface.hxx>
28 #include <tools/debug.hxx>
31 #include <progressbar.hxx>
33 using namespace ::cppu
;
34 using namespace ::osl
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::awt
;
42 #define FIXEDTEXT_SERVICENAME "com.sun.star.awt.UnoControlFixedText"
43 #define FIXEDTEXT_MODELNAME "com.sun.star.awt.UnoControlFixedTextModel"
44 #define CONTROLNAME_TEXT "Text" // identifier the control in container
45 #define CONTROLNAME_PROGRESSBAR "ProgressBar"
46 #define BUTTON_SERVICENAME "com.sun.star.awt.UnoControlButton"
47 #define CONTROLNAME_BUTTON "Button"
48 #define BUTTON_MODELNAME "com.sun.star.awt.UnoControlButtonModel"
49 #define DEFAULT_BUTTONLABEL "Abbrechen"
51 namespace unocontrols
{
53 ProgressMonitor::ProgressMonitor( const css::uno::Reference
< XComponentContext
>& rxContext
)
54 : BaseContainerControl ( rxContext
)
56 // It's not allowed to work with member in this method (refcounter !!!)
57 // But with a HACK (++refcount) its "OK" :-(
58 osl_atomic_increment(&m_refCount
);
60 // Create instances for fixedtext, button and progress ...
62 m_xTopic_Top
.set ( rxContext
->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME
, rxContext
), UNO_QUERY
);
63 m_xText_Top
.set ( rxContext
->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME
, rxContext
), UNO_QUERY
);
64 m_xTopic_Bottom
.set( rxContext
->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME
, rxContext
), UNO_QUERY
);
65 m_xText_Bottom
.set ( rxContext
->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME
, rxContext
), UNO_QUERY
);
66 m_xButton
.set ( rxContext
->getServiceManager()->createInstanceWithContext( BUTTON_SERVICENAME
, rxContext
), UNO_QUERY
);
67 m_xProgressBar
= new ProgressBar(rxContext
);
69 // ... cast controls to Reference< XControl > (for "setModel"!) ...
70 css::uno::Reference
< XControl
> xRef_Topic_Top ( m_xTopic_Top
, UNO_QUERY
);
71 css::uno::Reference
< XControl
> xRef_Text_Top ( m_xText_Top
, UNO_QUERY
);
72 css::uno::Reference
< XControl
> xRef_Topic_Bottom ( m_xTopic_Bottom
, UNO_QUERY
);
73 css::uno::Reference
< XControl
> xRef_Text_Bottom ( m_xText_Bottom
, UNO_QUERY
);
74 css::uno::Reference
< XControl
> xRef_Button ( m_xButton
, UNO_QUERY
);
77 xRef_Topic_Top
->setModel ( css::uno::Reference
< XControlModel
> ( rxContext
->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME
, rxContext
), UNO_QUERY
) );
78 xRef_Text_Top
->setModel ( css::uno::Reference
< XControlModel
> ( rxContext
->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME
, rxContext
), UNO_QUERY
) );
79 xRef_Topic_Bottom
->setModel ( css::uno::Reference
< XControlModel
> ( rxContext
->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME
, rxContext
), UNO_QUERY
) );
80 xRef_Text_Bottom
->setModel ( css::uno::Reference
< XControlModel
> ( rxContext
->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME
, rxContext
), UNO_QUERY
) );
81 xRef_Button
->setModel ( css::uno::Reference
< XControlModel
> ( rxContext
->getServiceManager()->createInstanceWithContext( BUTTON_MODELNAME
, rxContext
), UNO_QUERY
) );
82 // ProgressBar has no model !!!
84 // ... and add controls to basecontainercontrol!
85 addControl ( CONTROLNAME_TEXT
, xRef_Topic_Top
);
86 addControl ( CONTROLNAME_TEXT
, xRef_Text_Top
);
87 addControl ( CONTROLNAME_TEXT
, xRef_Topic_Bottom
);
88 addControl ( CONTROLNAME_TEXT
, xRef_Text_Bottom
);
89 addControl ( CONTROLNAME_BUTTON
, xRef_Button
);
90 addControl ( CONTROLNAME_PROGRESSBAR
, m_xProgressBar
.get() );
92 // FixedText make it automatically visible by himself ... but not the progressbar !!!
93 // it must be set explicitly
94 m_xProgressBar
->setVisible( true );
96 // Reset to defaults !!!
97 // (progressbar take automatically its own defaults)
98 m_xButton
->setLabel ( DEFAULT_BUTTONLABEL
);
99 m_xTopic_Top
->setText ( PROGRESSMONITOR_DEFAULT_TOPIC
);
100 m_xText_Top
->setText ( PROGRESSMONITOR_DEFAULT_TEXT
);
101 m_xTopic_Bottom
->setText ( PROGRESSMONITOR_DEFAULT_TOPIC
);
102 m_xText_Bottom
->setText ( PROGRESSMONITOR_DEFAULT_TEXT
);
104 osl_atomic_decrement(&m_refCount
);
107 ProgressMonitor::~ProgressMonitor()
113 Any SAL_CALL
ProgressMonitor::queryInterface( const Type
& rType
)
116 // Don't use mutex or guard in this method!!! Is a method of XInterface.
118 css::uno::Reference
< XInterface
> xDel
= BaseContainerControl::impl_getDelegator();
121 // If a delegator exists, forward question to its queryInterface.
122 // Delegator will ask its own queryAggregation!
123 aReturn
= xDel
->queryInterface( rType
);
127 // If a delegator is unknown, forward question to own queryAggregation.
128 aReturn
= queryAggregation( rType
);
135 void SAL_CALL
ProgressMonitor::acquire() throw()
138 // Don't use mutex or guard in this method!!! Is a method of XInterface.
140 // Forward to baseclass
141 BaseControl::acquire();
145 void SAL_CALL
ProgressMonitor::release() throw()
148 // Don't use mutex or guard in this method!!! Is a method of XInterface.
150 // Forward to baseclass
151 BaseControl::release();
155 Sequence
< Type
> SAL_CALL
ProgressMonitor::getTypes()
157 static OTypeCollection
ourTypeCollection(
158 cppu::UnoType
<XLayoutConstrains
>::get(),
159 cppu::UnoType
<XButton
>::get(),
160 cppu::UnoType
<XProgressMonitor
>::get(),
161 BaseContainerControl::getTypes() );
163 return ourTypeCollection
.getTypes();
167 Any SAL_CALL
ProgressMonitor::queryAggregation( const Type
& aType
)
169 // Ask for my own supported interfaces ...
170 // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
171 Any
aReturn ( ::cppu::queryInterface( aType
,
172 static_cast< XLayoutConstrains
* > ( this ) ,
173 static_cast< XButton
* > ( this ) ,
174 static_cast< XProgressMonitor
* > ( this )
178 // If searched interface not supported by this class ...
179 if ( !aReturn
.hasValue() )
181 // ... ask baseclasses.
182 aReturn
= BaseControl::queryAggregation( aType
);
189 void SAL_CALL
ProgressMonitor::addText(
190 const OUString
& rTopic
,
191 const OUString
& rText
,
192 sal_Bool bbeforeProgress
195 // Safe impossible cases
196 // Check valid call of this method.
197 DBG_ASSERT ( impl_debug_checkParameter ( rTopic
, rText
), "ProgressMonitor::addText()\nCall without valid parameters!\n");
198 DBG_ASSERT ( !(impl_searchTopic ( rTopic
, bbeforeProgress
) != nullptr ), "ProgressMonitor::addText()\nThe text already exist.\n" );
200 // Do nothing (in Release), if topic already exist.
201 if ( impl_searchTopic ( rTopic
, bbeforeProgress
) != nullptr )
206 // Else ... take memory for new item ...
207 std::unique_ptr
<IMPL_TextlistItem
> pTextItem(new IMPL_TextlistItem
);
210 pTextItem
->sTopic
= rTopic
;
211 pTextItem
->sText
= rText
;
213 // Ready for multithreading
214 MutexGuard
aGuard ( m_aMutex
);
216 // ... and insert it in right list.
217 if ( bbeforeProgress
)
219 maTextlist_Top
.push_back( std::move(pTextItem
) );
223 maTextlist_Bottom
.push_back( std::move(pTextItem
) );
227 impl_rebuildFixedText ();
228 impl_recalcLayout ();
232 void SAL_CALL
ProgressMonitor::removeText ( const OUString
& rTopic
, sal_Bool bbeforeProgress
)
234 // Safe impossible cases
235 // Check valid call of this method.
236 DBG_ASSERT ( impl_debug_checkParameter ( rTopic
), "ProgressMonitor::removeText()\nCall without valid parameters!" );
238 // Search the topic ...
239 IMPL_TextlistItem
* pSearchItem
= impl_searchTopic ( rTopic
, bbeforeProgress
);
241 if ( pSearchItem
!= nullptr )
243 // Ready for multithreading
244 MutexGuard
aGuard ( m_aMutex
);
246 // ... delete item from right list ...
247 if ( bbeforeProgress
)
249 auto itr
= std::find_if( maTextlist_Top
.begin(), maTextlist_Top
.end(),
250 [&] (std::unique_ptr
<IMPL_TextlistItem
> const &p
)
251 { return p
.get() == pSearchItem
; } );
252 if (itr
!= maTextlist_Top
.end())
253 maTextlist_Top
.erase(itr
);
257 auto itr
= std::find_if( maTextlist_Bottom
.begin(), maTextlist_Bottom
.end(),
258 [&] (std::unique_ptr
<IMPL_TextlistItem
> const &p
)
259 { return p
.get() == pSearchItem
; } );
260 if (itr
!= maTextlist_Bottom
.end())
261 maTextlist_Bottom
.erase(itr
);
266 // ... and update window.
267 impl_rebuildFixedText ();
268 impl_recalcLayout ();
273 void SAL_CALL
ProgressMonitor::updateText (
274 const OUString
& rTopic
,
275 const OUString
& rText
,
276 sal_Bool bbeforeProgress
279 // Safe impossible cases
280 // Check valid call of this method.
281 DBG_ASSERT ( impl_debug_checkParameter ( rTopic
, rText
), "ProgressMonitor::updateText()\nCall without valid parameters!\n" );
284 IMPL_TextlistItem
* pSearchItem
= impl_searchTopic ( rTopic
, bbeforeProgress
);
286 if ( pSearchItem
!= nullptr )
288 // Ready for multithreading
289 MutexGuard
aGuard ( m_aMutex
);
291 // ... update text ...
292 pSearchItem
->sText
= rText
;
294 // ... and update window.
295 impl_rebuildFixedText ();
296 impl_recalcLayout ();
301 void SAL_CALL
ProgressMonitor::setForegroundColor ( sal_Int32 nColor
)
303 // Ready for multithreading
304 MutexGuard
aGuard ( m_aMutex
);
306 m_xProgressBar
->setForegroundColor ( nColor
);
310 void SAL_CALL
ProgressMonitor::setBackgroundColor ( sal_Int32 nColor
)
312 // Ready for multithreading
313 MutexGuard
aGuard ( m_aMutex
);
315 m_xProgressBar
->setBackgroundColor ( nColor
);
319 void SAL_CALL
ProgressMonitor::setValue ( sal_Int32 nValue
)
321 // Ready for multithreading
322 MutexGuard
aGuard ( m_aMutex
);
324 m_xProgressBar
->setValue ( nValue
);
328 void SAL_CALL
ProgressMonitor::setRange ( sal_Int32 nMin
, sal_Int32 nMax
)
330 // Ready for multithreading
331 MutexGuard
aGuard ( m_aMutex
);
333 m_xProgressBar
->setRange ( nMin
, nMax
);
337 sal_Int32 SAL_CALL
ProgressMonitor::getValue ()
339 // Ready for multithreading
340 MutexGuard
aGuard ( m_aMutex
);
342 return m_xProgressBar
->getValue ();
346 void SAL_CALL
ProgressMonitor::addActionListener ( const css::uno::Reference
< XActionListener
> & rListener
)
348 // Ready for multithreading
349 MutexGuard
aGuard ( m_aMutex
);
351 if ( m_xButton
.is () )
353 m_xButton
->addActionListener ( rListener
);
358 void SAL_CALL
ProgressMonitor::removeActionListener ( const css::uno::Reference
< XActionListener
> & rListener
)
360 // Ready for multithreading
361 MutexGuard
aGuard ( m_aMutex
);
363 if ( m_xButton
.is () )
365 m_xButton
->removeActionListener ( rListener
);
370 void SAL_CALL
ProgressMonitor::setLabel ( const OUString
& rLabel
)
372 // Ready for multithreading
373 MutexGuard
aGuard ( m_aMutex
);
375 if ( m_xButton
.is () )
377 m_xButton
->setLabel ( rLabel
);
382 void SAL_CALL
ProgressMonitor::setActionCommand ( const OUString
& rCommand
)
384 // Ready for multithreading
385 MutexGuard
aGuard ( m_aMutex
);
387 if ( m_xButton
.is () )
389 m_xButton
->setActionCommand ( rCommand
);
394 Size SAL_CALL
ProgressMonitor::getMinimumSize ()
396 return Size (PROGRESSMONITOR_DEFAULT_WIDTH
, PROGRESSMONITOR_DEFAULT_HEIGHT
);
400 Size SAL_CALL
ProgressMonitor::getPreferredSize ()
402 // Ready for multithreading
403 ClearableMutexGuard
aGuard ( m_aMutex
);
405 // get information about required place of child controls
406 css::uno::Reference
< XLayoutConstrains
> xTopicLayout_Top ( m_xTopic_Top
, UNO_QUERY
);
407 css::uno::Reference
< XLayoutConstrains
> xTopicLayout_Bottom ( m_xTopic_Bottom
, UNO_QUERY
);
408 css::uno::Reference
< XLayoutConstrains
> xButtonLayout ( m_xButton
, UNO_QUERY
);
410 Size aTopicSize_Top
= xTopicLayout_Top
->getPreferredSize ();
411 Size aTopicSize_Bottom
= xTopicLayout_Bottom
->getPreferredSize ();
412 Size aButtonSize
= xButtonLayout
->getPreferredSize ();
413 Rectangle aTempRectangle
= m_xProgressBar
->getPosSize();
414 Size
aProgressBarSize( aTempRectangle
.Width
, aTempRectangle
.Height
);
418 // calc preferred size of progressmonitor
419 sal_Int32 nWidth
= 3 * PROGRESSMONITOR_FREEBORDER
;
420 nWidth
+= aProgressBarSize
.Width
;
422 sal_Int32 nHeight
= 6 * PROGRESSMONITOR_FREEBORDER
;
423 nHeight
+= aTopicSize_Top
.Height
;
424 nHeight
+= aProgressBarSize
.Height
;
425 nHeight
+= aTopicSize_Bottom
.Height
;
426 nHeight
+= 2; // 1 for black line, 1 for white line = 3D-Line!
427 nHeight
+= aButtonSize
.Height
;
430 if ( nWidth
< PROGRESSMONITOR_DEFAULT_WIDTH
)
432 nWidth
= PROGRESSMONITOR_DEFAULT_WIDTH
;
434 if ( nHeight
< PROGRESSMONITOR_DEFAULT_HEIGHT
)
436 nHeight
= PROGRESSMONITOR_DEFAULT_HEIGHT
;
440 return Size ( nWidth
, nHeight
);
444 Size SAL_CALL
ProgressMonitor::calcAdjustedSize ( const Size
& /*rNewSize*/ )
446 return getPreferredSize ();
450 void SAL_CALL
ProgressMonitor::createPeer ( const css::uno::Reference
< XToolkit
> & rToolkit
, const css::uno::Reference
< XWindowPeer
> & rParent
)
454 BaseContainerControl::createPeer ( rToolkit
, rParent
);
456 // If user forget to call "setPosSize()", we have still a correct size.
457 // And a "MinimumSize" IS A "MinimumSize"!
458 // We change not the position of control at this point.
459 Size aDefaultSize
= getMinimumSize ();
460 setPosSize ( 0, 0, aDefaultSize
.Width
, aDefaultSize
.Height
, PosSize::SIZE
);
465 sal_Bool SAL_CALL
ProgressMonitor::setModel ( const css::uno::Reference
< XControlModel
> & /*rModel*/ )
472 css::uno::Reference
< XControlModel
> SAL_CALL
ProgressMonitor::getModel ()
475 // return (XControlModel*)this;
476 return css::uno::Reference
< XControlModel
> ();
480 void SAL_CALL
ProgressMonitor::dispose ()
482 // Ready for multithreading
483 MutexGuard
aGuard ( m_aMutex
);
485 // "removeControl()" control the state of a reference
486 css::uno::Reference
< XControl
> xRef_Topic_Top ( m_xTopic_Top
, UNO_QUERY
);
487 css::uno::Reference
< XControl
> xRef_Text_Top ( m_xText_Top
, UNO_QUERY
);
488 css::uno::Reference
< XControl
> xRef_Topic_Bottom ( m_xTopic_Bottom
, UNO_QUERY
);
489 css::uno::Reference
< XControl
> xRef_Text_Bottom ( m_xText_Bottom
, UNO_QUERY
);
490 css::uno::Reference
< XControl
> xRef_Button ( m_xButton
, UNO_QUERY
);
492 removeControl ( xRef_Topic_Top
);
493 removeControl ( xRef_Text_Top
);
494 removeControl ( xRef_Topic_Bottom
);
495 removeControl ( xRef_Text_Bottom
);
496 removeControl ( xRef_Button
);
497 removeControl ( m_xProgressBar
.get() );
499 // don't use "...->clear ()" or "... = XFixedText ()"
500 // when other hold a reference at this object !!!
501 xRef_Topic_Top
->dispose ();
502 xRef_Text_Top
->dispose ();
503 xRef_Topic_Bottom
->dispose ();
504 xRef_Text_Bottom
->dispose ();
505 xRef_Button
->dispose ();
506 m_xProgressBar
->dispose();
508 BaseContainerControl::dispose ();
512 void SAL_CALL
ProgressMonitor::setPosSize ( sal_Int32 nX
, sal_Int32 nY
, sal_Int32 nWidth
, sal_Int32 nHeight
, sal_Int16 nFlags
)
514 Rectangle aBasePosSize
= getPosSize ();
515 BaseContainerControl::setPosSize (nX
, nY
, nWidth
, nHeight
, nFlags
);
517 // if position or size changed
519 ( nWidth
!= aBasePosSize
.Width
) ||
520 ( nHeight
!= aBasePosSize
.Height
)
523 // calc new layout for controls
524 impl_recalcLayout ();
525 // clear background (!)
526 // [Children were repainted in "recalcLayout" by setPosSize() automatically!]
527 getPeer()->invalidate(2);
528 // and repaint the control
529 impl_paint ( 0, 0, impl_getGraphicsPeer() );
533 // impl but public method to register service
534 Sequence
< OUString
> ProgressMonitor::impl_getStaticSupportedServiceNames()
536 return css::uno::Sequence
<OUString
>();
539 // impl but public method to register service
540 OUString
ProgressMonitor::impl_getStaticImplementationName()
542 return "stardiv.UnoControls.ProgressMonitor";
546 void ProgressMonitor::impl_paint ( sal_Int32 nX
, sal_Int32 nY
, const css::uno::Reference
< XGraphics
> & rGraphics
)
550 // Ready for multithreading
551 MutexGuard
aGuard ( m_aMutex
);
553 // paint shadowed border around the progressmonitor
554 rGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW
);
555 rGraphics
->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY
);
556 rGraphics
->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX
, impl_getHeight()-1 );
558 rGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT
);
559 rGraphics
->drawLine ( nX
, nY
, impl_getWidth(), nY
);
560 rGraphics
->drawLine ( nX
, nY
, nX
, impl_getHeight() );
563 rGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW
);
564 rGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
);
566 rGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT
);
567 rGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
+1, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
+1 );
572 void ProgressMonitor::impl_recalcLayout ()
576 sal_Int32 nWidth_Button
;
577 sal_Int32 nHeight_Button
;
579 sal_Int32 nX_ProgressBar
;
580 sal_Int32 nY_ProgressBar
;
581 sal_Int32 nWidth_ProgressBar
;
582 sal_Int32 nHeight_ProgressBar
;
584 sal_Int32 nX_Text_Top
;
585 sal_Int32 nY_Text_Top
;
586 sal_Int32 nWidth_Text_Top
;
587 sal_Int32 nHeight_Text_Top
;
589 sal_Int32 nX_Topic_Top
;
590 sal_Int32 nY_Topic_Top
;
591 sal_Int32 nWidth_Topic_Top
;
592 sal_Int32 nHeight_Topic_Top
;
594 sal_Int32 nX_Text_Bottom
;
595 sal_Int32 nY_Text_Bottom
;
596 sal_Int32 nWidth_Text_Bottom
;
597 sal_Int32 nHeight_Text_Bottom
;
599 sal_Int32 nX_Topic_Bottom
;
600 sal_Int32 nY_Topic_Bottom
;
601 sal_Int32 nWidth_Topic_Bottom
;
602 sal_Int32 nHeight_Topic_Bottom
;
604 // Ready for multithreading
605 MutexGuard
aGuard ( m_aMutex
);
607 // get information about required place of child controls
608 css::uno::Reference
< XLayoutConstrains
> xTopicLayout_Top ( m_xTopic_Top
, UNO_QUERY
);
609 css::uno::Reference
< XLayoutConstrains
> xTextLayout_Top ( m_xText_Top
, UNO_QUERY
);
610 css::uno::Reference
< XLayoutConstrains
> xTopicLayout_Bottom ( m_xTopic_Bottom
, UNO_QUERY
);
611 css::uno::Reference
< XLayoutConstrains
> xTextLayout_Bottom ( m_xText_Bottom
, UNO_QUERY
);
612 css::uno::Reference
< XLayoutConstrains
> xButtonLayout ( m_xButton
, UNO_QUERY
);
614 Size aTopicSize_Top
= xTopicLayout_Top
->getPreferredSize ();
615 Size aTextSize_Top
= xTextLayout_Top
->getPreferredSize ();
616 Size aTopicSize_Bottom
= xTopicLayout_Bottom
->getPreferredSize ();
617 Size aTextSize_Bottom
= xTextLayout_Bottom
->getPreferredSize ();
618 Size aButtonSize
= xButtonLayout
->getPreferredSize ();
620 // calc position and size of child controls
621 // Button has preferred size!
622 nWidth_Button
= aButtonSize
.Width
;
623 nHeight_Button
= aButtonSize
.Height
;
625 // Left column before progressbar has preferred size and fixed position.
626 // But "Width" is oriented on left column below progressbar to!!! "max(...)"
627 nX_Topic_Top
= PROGRESSMONITOR_FREEBORDER
;
628 nY_Topic_Top
= PROGRESSMONITOR_FREEBORDER
;
629 nWidth_Topic_Top
= std::max( aTopicSize_Top
.Width
, aTopicSize_Bottom
.Width
);
630 nHeight_Topic_Top
= aTopicSize_Top
.Height
;
632 // Right column before progressbar has relative position to left column ...
633 // ... and a size as rest of dialog size!
634 nX_Text_Top
= nX_Topic_Top
+nWidth_Topic_Top
+PROGRESSMONITOR_FREEBORDER
;
635 nY_Text_Top
= nY_Topic_Top
;
636 nWidth_Text_Top
= std::max ( aTextSize_Top
.Width
, aTextSize_Bottom
.Width
);
637 // Fix size of this column to minimum!
638 sal_Int32 nSummaryWidth
= nWidth_Text_Top
+nWidth_Topic_Top
+(3*PROGRESSMONITOR_FREEBORDER
);
639 if ( nSummaryWidth
< PROGRESSMONITOR_DEFAULT_WIDTH
)
640 nWidth_Text_Top
= PROGRESSMONITOR_DEFAULT_WIDTH
-nWidth_Topic_Top
-(3*PROGRESSMONITOR_FREEBORDER
);
641 // Fix size of column to maximum!
642 if ( nSummaryWidth
> impl_getWidth() )
643 nWidth_Text_Top
= impl_getWidth()-nWidth_Topic_Top
-(3*PROGRESSMONITOR_FREEBORDER
);
644 nHeight_Text_Top
= nHeight_Topic_Top
;
646 // Position of progressbar is relative to columns before.
647 // Progressbar.Width = Dialog.Width !!!
648 // Progressbar.Height = Button.Height
649 nX_ProgressBar
= nX_Topic_Top
;
650 nY_ProgressBar
= nY_Topic_Top
+nHeight_Topic_Top
+PROGRESSMONITOR_FREEBORDER
;
651 nWidth_ProgressBar
= PROGRESSMONITOR_FREEBORDER
+nWidth_Topic_Top
+nWidth_Text_Top
;
652 nHeight_ProgressBar
= nHeight_Button
;
654 // Oriented by left column before progressbar.
655 nX_Topic_Bottom
= nX_Topic_Top
;
656 nY_Topic_Bottom
= nY_ProgressBar
+nHeight_ProgressBar
+PROGRESSMONITOR_FREEBORDER
;
657 nWidth_Topic_Bottom
= nWidth_Topic_Top
;
658 nHeight_Topic_Bottom
= aTopicSize_Bottom
.Height
;
660 // Oriented by right column before progressbar.
661 nX_Text_Bottom
= nX_Topic_Bottom
+nWidth_Topic_Bottom
+PROGRESSMONITOR_FREEBORDER
;
662 nY_Text_Bottom
= nY_Topic_Bottom
;
663 nWidth_Text_Bottom
= nWidth_Text_Top
;
664 nHeight_Text_Bottom
= nHeight_Topic_Bottom
;
666 // Oriented by progressbar.
667 nX_Button
= nX_ProgressBar
+nWidth_ProgressBar
-nWidth_Button
;
668 nY_Button
= nY_Topic_Bottom
+nHeight_Topic_Bottom
+PROGRESSMONITOR_FREEBORDER
;
670 // Calc offsets to center controls
674 nDx
= ( (2*PROGRESSMONITOR_FREEBORDER
)+nWidth_ProgressBar
);
675 nDy
= ( (6*PROGRESSMONITOR_FREEBORDER
)+nHeight_Topic_Top
+nHeight_ProgressBar
+nHeight_Topic_Bottom
+2+nHeight_Button
);
677 // At this point use original dialog size to center controls!
678 nDx
= (impl_getWidth ()/2)-(nDx
/2);
679 nDy
= (impl_getHeight()/2)-(nDy
/2);
690 // Set new position and size on all controls
691 css::uno::Reference
< XWindow
> xRef_Topic_Top ( m_xTopic_Top
, UNO_QUERY
);
692 css::uno::Reference
< XWindow
> xRef_Text_Top ( m_xText_Top
, UNO_QUERY
);
693 css::uno::Reference
< XWindow
> xRef_Topic_Bottom ( m_xTopic_Bottom
, UNO_QUERY
);
694 css::uno::Reference
< XWindow
> xRef_Text_Bottom ( m_xText_Bottom
, UNO_QUERY
);
695 css::uno::Reference
< XWindow
> xRef_Button ( m_xButton
, UNO_QUERY
);
697 xRef_Topic_Top
->setPosSize ( nDx
+nX_Topic_Top
, nDy
+nY_Topic_Top
, nWidth_Topic_Top
, nHeight_Topic_Top
, 15 );
698 xRef_Text_Top
->setPosSize ( nDx
+nX_Text_Top
, nDy
+nY_Text_Top
, nWidth_Text_Top
, nHeight_Text_Top
, 15 );
699 xRef_Topic_Bottom
->setPosSize ( nDx
+nX_Topic_Bottom
, nDy
+nY_Topic_Bottom
, nWidth_Topic_Bottom
, nHeight_Topic_Bottom
, 15 );
700 xRef_Text_Bottom
->setPosSize ( nDx
+nX_Text_Bottom
, nDy
+nY_Text_Bottom
, nWidth_Text_Bottom
, nHeight_Text_Bottom
, 15 );
701 xRef_Button
->setPosSize ( nDx
+nX_Button
, nDy
+nY_Button
, nWidth_Button
, nHeight_Button
, 15 );
702 m_xProgressBar
->setPosSize( nDx
+nX_ProgressBar
, nDy
+nY_ProgressBar
, nWidth_ProgressBar
, nHeight_ProgressBar
, 15 );
704 m_a3DLine
.X
= nDx
+nX_Topic_Top
;
705 m_a3DLine
.Y
= nDy
+nY_Topic_Bottom
+nHeight_Topic_Bottom
+(PROGRESSMONITOR_FREEBORDER
/2);
706 m_a3DLine
.Width
= nWidth_ProgressBar
;
707 m_a3DLine
.Height
= nHeight_ProgressBar
;
709 // All childcontrols make an implicit repaint in setPosSize()!
710 // Make it also for this 3D-line ...
711 css::uno::Reference
< XGraphics
> xGraphics
= impl_getGraphicsPeer ();
713 xGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW
);
714 xGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
);
716 xGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT
);
717 xGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
+1, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
+1 );
721 void ProgressMonitor::impl_rebuildFixedText ()
723 // Ready for multithreading
724 MutexGuard
aGuard ( m_aMutex
);
726 // Rebuild fixedtext before progress
728 // Rebuild left site of text
729 if (m_xTopic_Top
.is())
731 OUStringBuffer aCollectString
;
733 // Collect all topics from list and format text.
734 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
735 for (auto const & pSearchItem
: maTextlist_Top
)
737 aCollectString
.append(pSearchItem
->sTopic
).append("\n");
740 m_xTopic_Top
->setText ( aCollectString
.makeStringAndClear() );
743 // Rebuild right site of text
744 if (m_xText_Top
.is())
746 OUStringBuffer aCollectString
;
748 // Collect all topics from list and format text.
749 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
750 for (auto const & pSearchItem
: maTextlist_Top
)
752 aCollectString
.append(pSearchItem
->sText
).append("\n");
755 m_xText_Top
->setText ( aCollectString
.makeStringAndClear() );
758 // Rebuild fixedtext below progress
760 // Rebuild left site of text
761 if (m_xTopic_Bottom
.is())
763 OUStringBuffer aCollectString
;
765 // Collect all topics from list and format text.
766 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
767 for (auto const & pSearchItem
: maTextlist_Bottom
)
769 aCollectString
.append(pSearchItem
->sTopic
).append("\n");
772 m_xTopic_Bottom
->setText ( aCollectString
.makeStringAndClear() );
775 // Rebuild right site of text
776 if (m_xText_Bottom
.is())
778 OUStringBuffer aCollectString
;
780 // Collect all topics from list and format text.
781 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
782 for (auto const & pSearchItem
: maTextlist_Bottom
)
784 aCollectString
.append(pSearchItem
->sText
).append("\n");
787 m_xText_Bottom
->setText ( aCollectString
.makeStringAndClear() );
792 void ProgressMonitor::impl_cleanMemory ()
794 // Ready for multithreading
795 MutexGuard
aGuard ( m_aMutex
);
797 // Delete all of lists.
798 maTextlist_Top
.clear();
799 maTextlist_Bottom
.clear();
803 IMPL_TextlistItem
* ProgressMonitor::impl_searchTopic ( const OUString
& rTopic
, bool bbeforeProgress
)
805 // Get right textlist for following operations.
806 ::std::vector
< std::unique_ptr
<IMPL_TextlistItem
> >* pTextList
;
808 // Ready for multithreading
810 MutexGuard
aGuard(m_aMutex
);
814 pTextList
= &maTextlist_Top
;
818 pTextList
= &maTextlist_Bottom
;
823 // Search the topic in textlist.
824 size_t nPosition
= 0;
825 size_t nCount
= pTextList
->size();
827 for ( nPosition
= 0; nPosition
< nCount
; ++nPosition
)
829 auto pSearchItem
= pTextList
->at( nPosition
).get();
831 if ( pSearchItem
->sTopic
== rTopic
)
833 // We have found this topic... return a valid pointer.
838 // We haven't found this topic... return a nonvalid pointer.
844 // addText, updateText
845 bool ProgressMonitor::impl_debug_checkParameter (
846 const OUString
& rTopic
,
847 const OUString
& rText
849 if ( rTopic
.isEmpty() ) return false; // ""
851 if ( rText
.isEmpty() ) return false; // ""
853 // Parameter OK ... return true.
858 bool ProgressMonitor::impl_debug_checkParameter ( const OUString
& rTopic
)
860 if ( rTopic
.isEmpty() ) return false; // ""
862 // Parameter OK ... return true.
866 } // namespace unocontrols
868 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */