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 <rtl/ustrbuf.hxx>
29 #include <tools/debug.hxx>
32 #include <progressbar.hxx>
34 using namespace ::cppu
;
35 using namespace ::osl
;
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::awt
;
42 constexpr OUStringLiteral FIXEDTEXT_SERVICENAME
= u
"com.sun.star.awt.UnoControlFixedText";
43 constexpr OUStringLiteral FIXEDTEXT_MODELNAME
= u
"com.sun.star.awt.UnoControlFixedTextModel";
44 constexpr OUStringLiteral CONTROLNAME_TEXT
= u
"Text"; // identifier the control in container
45 constexpr OUStringLiteral CONTROLNAME_PROGRESSBAR
= u
"ProgressBar";
46 constexpr OUStringLiteral BUTTON_SERVICENAME
= u
"com.sun.star.awt.UnoControlButton";
47 constexpr OUStringLiteral CONTROLNAME_BUTTON
= u
"Button";
48 constexpr OUStringLiteral BUTTON_MODELNAME
= u
"com.sun.star.awt.UnoControlButtonModel";
49 constexpr OUStringLiteral DEFAULT_BUTTONLABEL
= u
"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
);
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
)
115 // Ask for my own supported interfaces ...
116 // Attention: XTypeProvider and XInterface are supported by WeakComponentImplHelper!
117 Any
aReturn ( ::cppu::queryInterface( rType
,
118 static_cast< XLayoutConstrains
* > ( this ) ,
119 static_cast< XButton
* > ( this ) ,
120 static_cast< XProgressMonitor
* > ( this )
124 // If searched interface not supported by this class ...
125 if ( !aReturn
.hasValue() )
127 // ... ask baseclasses.
128 aReturn
= BaseControl::queryInterface( rType
);
135 void SAL_CALL
ProgressMonitor::acquire() noexcept
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() noexcept
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 void SAL_CALL
ProgressMonitor::addText(
168 const OUString
& rTopic
,
169 const OUString
& rText
,
170 sal_Bool bbeforeProgress
173 // Ready for multithreading
174 MutexGuard
aGuard ( m_aMutex
);
176 // Safe impossible cases
177 // Check valid call of this method.
178 DBG_ASSERT ( impl_debug_checkParameter ( rTopic
, rText
), "ProgressMonitor::addText()\nCall without valid parameters!\n");
179 DBG_ASSERT ( !(impl_searchTopic ( rTopic
, bbeforeProgress
) != nullptr ), "ProgressMonitor::addText()\nThe text already exist.\n" );
181 // Do nothing (in Release), if topic already exist.
182 if ( impl_searchTopic ( rTopic
, bbeforeProgress
) != nullptr )
187 // Else ... take memory for new item ...
188 IMPL_TextlistItem aTextItem
;
191 aTextItem
.sTopic
= rTopic
;
192 aTextItem
.sText
= rText
;
194 // ... and insert it in right list.
195 if ( bbeforeProgress
)
197 maTextlist_Top
.push_back( aTextItem
);
201 maTextlist_Bottom
.push_back( aTextItem
);
205 impl_rebuildFixedText ();
206 impl_recalcLayout ();
210 void SAL_CALL
ProgressMonitor::removeText ( const OUString
& rTopic
, sal_Bool bbeforeProgress
)
212 // Safe impossible cases
213 // Check valid call of this method.
214 DBG_ASSERT ( impl_debug_checkParameter ( rTopic
), "ProgressMonitor::removeText()\nCall without valid parameters!" );
216 // Ready for multithreading
217 MutexGuard
aGuard ( m_aMutex
);
219 // Search the topic ...
220 IMPL_TextlistItem
* pSearchItem
= impl_searchTopic ( rTopic
, bbeforeProgress
);
222 if ( pSearchItem
== nullptr )
225 // ... delete item from right list ...
226 if ( bbeforeProgress
)
228 auto itr
= std::find_if( maTextlist_Top
.begin(), maTextlist_Top
.end(),
229 [&] (IMPL_TextlistItem
const &p
)
230 { return &p
== pSearchItem
; } );
231 if (itr
!= maTextlist_Top
.end())
232 maTextlist_Top
.erase(itr
);
236 auto itr
= std::find_if( maTextlist_Bottom
.begin(), maTextlist_Bottom
.end(),
237 [&] (IMPL_TextlistItem
const &p
)
238 { return &p
== pSearchItem
; } );
239 if (itr
!= maTextlist_Bottom
.end())
240 maTextlist_Bottom
.erase(itr
);
243 // ... and update window.
244 impl_rebuildFixedText ();
245 impl_recalcLayout ();
249 void SAL_CALL
ProgressMonitor::updateText (
250 const OUString
& rTopic
,
251 const OUString
& rText
,
252 sal_Bool bbeforeProgress
255 // Safe impossible cases
256 // Check valid call of this method.
257 DBG_ASSERT ( impl_debug_checkParameter ( rTopic
, rText
), "ProgressMonitor::updateText()\nCall without valid parameters!\n" );
259 // Ready for multithreading
260 MutexGuard
aGuard ( m_aMutex
);
263 IMPL_TextlistItem
* pSearchItem
= impl_searchTopic ( rTopic
, bbeforeProgress
);
265 if ( pSearchItem
!= nullptr )
267 // ... update text ...
268 pSearchItem
->sText
= rText
;
270 // ... and update window.
271 impl_rebuildFixedText ();
272 impl_recalcLayout ();
277 void SAL_CALL
ProgressMonitor::setForegroundColor ( sal_Int32 nColor
)
279 // Ready for multithreading
280 MutexGuard
aGuard ( m_aMutex
);
282 m_xProgressBar
->setForegroundColor ( nColor
);
286 void SAL_CALL
ProgressMonitor::setBackgroundColor ( sal_Int32 nColor
)
288 // Ready for multithreading
289 MutexGuard
aGuard ( m_aMutex
);
291 m_xProgressBar
->setBackgroundColor ( nColor
);
295 void SAL_CALL
ProgressMonitor::setValue ( sal_Int32 nValue
)
297 // Ready for multithreading
298 MutexGuard
aGuard ( m_aMutex
);
300 m_xProgressBar
->setValue ( nValue
);
304 void SAL_CALL
ProgressMonitor::setRange ( sal_Int32 nMin
, sal_Int32 nMax
)
306 // Ready for multithreading
307 MutexGuard
aGuard ( m_aMutex
);
309 m_xProgressBar
->setRange ( nMin
, nMax
);
313 sal_Int32 SAL_CALL
ProgressMonitor::getValue ()
315 // Ready for multithreading
316 MutexGuard
aGuard ( m_aMutex
);
318 return m_xProgressBar
->getValue ();
322 void SAL_CALL
ProgressMonitor::addActionListener ( const css::uno::Reference
< XActionListener
> & rListener
)
324 // Ready for multithreading
325 MutexGuard
aGuard ( m_aMutex
);
327 if ( m_xButton
.is () )
329 m_xButton
->addActionListener ( rListener
);
334 void SAL_CALL
ProgressMonitor::removeActionListener ( const css::uno::Reference
< XActionListener
> & rListener
)
336 // Ready for multithreading
337 MutexGuard
aGuard ( m_aMutex
);
339 if ( m_xButton
.is () )
341 m_xButton
->removeActionListener ( rListener
);
346 void SAL_CALL
ProgressMonitor::setLabel ( const OUString
& rLabel
)
348 // Ready for multithreading
349 MutexGuard
aGuard ( m_aMutex
);
351 if ( m_xButton
.is () )
353 m_xButton
->setLabel ( rLabel
);
358 void SAL_CALL
ProgressMonitor::setActionCommand ( const OUString
& rCommand
)
360 // Ready for multithreading
361 MutexGuard
aGuard ( m_aMutex
);
363 if ( m_xButton
.is () )
365 m_xButton
->setActionCommand ( rCommand
);
370 Size SAL_CALL
ProgressMonitor::getMinimumSize ()
372 return Size (PROGRESSMONITOR_DEFAULT_WIDTH
, PROGRESSMONITOR_DEFAULT_HEIGHT
);
376 Size SAL_CALL
ProgressMonitor::getPreferredSize ()
378 // Ready for multithreading
379 ClearableMutexGuard
aGuard ( m_aMutex
);
381 // get information about required place of child controls
382 css::uno::Reference
< XLayoutConstrains
> xTopicLayout_Top ( m_xTopic_Top
, UNO_QUERY
);
383 css::uno::Reference
< XLayoutConstrains
> xTopicLayout_Bottom ( m_xTopic_Bottom
, UNO_QUERY
);
384 css::uno::Reference
< XLayoutConstrains
> xButtonLayout ( m_xButton
, UNO_QUERY
);
386 Size aTopicSize_Top
= xTopicLayout_Top
->getPreferredSize ();
387 Size aTopicSize_Bottom
= xTopicLayout_Bottom
->getPreferredSize ();
388 Size aButtonSize
= xButtonLayout
->getPreferredSize ();
389 Rectangle aTempRectangle
= m_xProgressBar
->getPosSize();
390 Size
aProgressBarSize( aTempRectangle
.Width
, aTempRectangle
.Height
);
394 // calc preferred size of progressmonitor
395 sal_Int32 nWidth
= 3 * PROGRESSMONITOR_FREEBORDER
;
396 nWidth
+= aProgressBarSize
.Width
;
398 sal_Int32 nHeight
= 6 * PROGRESSMONITOR_FREEBORDER
;
399 nHeight
+= aTopicSize_Top
.Height
;
400 nHeight
+= aProgressBarSize
.Height
;
401 nHeight
+= aTopicSize_Bottom
.Height
;
402 nHeight
+= 2; // 1 for black line, 1 for white line = 3D-Line!
403 nHeight
+= aButtonSize
.Height
;
406 if ( nWidth
< PROGRESSMONITOR_DEFAULT_WIDTH
)
408 nWidth
= PROGRESSMONITOR_DEFAULT_WIDTH
;
410 if ( nHeight
< PROGRESSMONITOR_DEFAULT_HEIGHT
)
412 nHeight
= PROGRESSMONITOR_DEFAULT_HEIGHT
;
416 return Size ( nWidth
, nHeight
);
420 Size SAL_CALL
ProgressMonitor::calcAdjustedSize ( const Size
& /*rNewSize*/ )
422 return getPreferredSize ();
426 void SAL_CALL
ProgressMonitor::createPeer ( const css::uno::Reference
< XToolkit
> & rToolkit
, const css::uno::Reference
< XWindowPeer
> & rParent
)
430 BaseContainerControl::createPeer ( rToolkit
, rParent
);
432 // If user forget to call "setPosSize()", we have still a correct size.
433 // And a "MinimumSize" IS A "MinimumSize"!
434 // We change not the position of control at this point.
435 Size aDefaultSize
= getMinimumSize ();
436 setPosSize ( 0, 0, aDefaultSize
.Width
, aDefaultSize
.Height
, PosSize::SIZE
);
441 sal_Bool SAL_CALL
ProgressMonitor::setModel ( const css::uno::Reference
< XControlModel
> & /*rModel*/ )
448 css::uno::Reference
< XControlModel
> SAL_CALL
ProgressMonitor::getModel ()
451 // return (XControlModel*)this;
452 return css::uno::Reference
< XControlModel
> ();
456 void SAL_CALL
ProgressMonitor::dispose ()
458 // Ready for multithreading
459 MutexGuard
aGuard ( m_aMutex
);
461 // "removeControl()" control the state of a reference
462 css::uno::Reference
< XControl
> xRef_Topic_Top ( m_xTopic_Top
, UNO_QUERY
);
463 css::uno::Reference
< XControl
> xRef_Text_Top ( m_xText_Top
, UNO_QUERY
);
464 css::uno::Reference
< XControl
> xRef_Topic_Bottom ( m_xTopic_Bottom
, UNO_QUERY
);
465 css::uno::Reference
< XControl
> xRef_Text_Bottom ( m_xText_Bottom
, UNO_QUERY
);
466 css::uno::Reference
< XControl
> xRef_Button ( m_xButton
, UNO_QUERY
);
468 removeControl ( xRef_Topic_Top
);
469 removeControl ( xRef_Text_Top
);
470 removeControl ( xRef_Topic_Bottom
);
471 removeControl ( xRef_Text_Bottom
);
472 removeControl ( xRef_Button
);
473 removeControl ( m_xProgressBar
);
475 // don't use "...->clear ()" or "... = XFixedText ()"
476 // when other hold a reference at this object !!!
477 xRef_Topic_Top
->dispose ();
478 xRef_Text_Top
->dispose ();
479 xRef_Topic_Bottom
->dispose ();
480 xRef_Text_Bottom
->dispose ();
481 xRef_Button
->dispose ();
482 m_xProgressBar
->dispose();
484 BaseContainerControl::dispose ();
488 void SAL_CALL
ProgressMonitor::setPosSize ( sal_Int32 nX
, sal_Int32 nY
, sal_Int32 nWidth
, sal_Int32 nHeight
, sal_Int16 nFlags
)
490 Rectangle aBasePosSize
= getPosSize ();
491 BaseContainerControl::setPosSize (nX
, nY
, nWidth
, nHeight
, nFlags
);
493 // if position or size changed
495 ( nWidth
!= aBasePosSize
.Width
) ||
496 ( nHeight
!= aBasePosSize
.Height
)
499 // calc new layout for controls
500 impl_recalcLayout ();
501 // clear background (!)
502 // [Children were repainted in "recalcLayout" by setPosSize() automatically!]
503 getPeer()->invalidate(2);
504 // and repaint the control
505 impl_paint ( 0, 0, impl_getGraphicsPeer() );
510 void ProgressMonitor::impl_paint ( sal_Int32 nX
, sal_Int32 nY
, const css::uno::Reference
< XGraphics
> & rGraphics
)
515 // Ready for multithreading
516 MutexGuard
aGuard ( m_aMutex
);
518 // paint shadowed border around the progressmonitor
519 rGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW
);
520 rGraphics
->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY
);
521 rGraphics
->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX
, impl_getHeight()-1 );
523 rGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT
);
524 rGraphics
->drawLine ( nX
, nY
, impl_getWidth(), nY
);
525 rGraphics
->drawLine ( nX
, nY
, nX
, impl_getHeight() );
528 rGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW
);
529 rGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
);
531 rGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT
);
532 rGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
+1, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
+1 );
536 void ProgressMonitor::impl_recalcLayout ()
540 sal_Int32 nWidth_Button
;
541 sal_Int32 nHeight_Button
;
543 sal_Int32 nX_ProgressBar
;
544 sal_Int32 nY_ProgressBar
;
545 sal_Int32 nWidth_ProgressBar
;
546 sal_Int32 nHeight_ProgressBar
;
548 sal_Int32 nX_Text_Top
;
549 sal_Int32 nY_Text_Top
;
550 sal_Int32 nWidth_Text_Top
;
551 sal_Int32 nHeight_Text_Top
;
553 sal_Int32 nX_Topic_Top
;
554 sal_Int32 nY_Topic_Top
;
555 sal_Int32 nWidth_Topic_Top
;
556 sal_Int32 nHeight_Topic_Top
;
558 sal_Int32 nX_Text_Bottom
;
559 sal_Int32 nY_Text_Bottom
;
560 sal_Int32 nWidth_Text_Bottom
;
561 sal_Int32 nHeight_Text_Bottom
;
563 sal_Int32 nX_Topic_Bottom
;
564 sal_Int32 nY_Topic_Bottom
;
565 sal_Int32 nWidth_Topic_Bottom
;
566 sal_Int32 nHeight_Topic_Bottom
;
568 // Ready for multithreading
569 MutexGuard
aGuard ( m_aMutex
);
571 // get information about required place of child controls
572 css::uno::Reference
< XLayoutConstrains
> xTopicLayout_Top ( m_xTopic_Top
, UNO_QUERY
);
573 css::uno::Reference
< XLayoutConstrains
> xTextLayout_Top ( m_xText_Top
, UNO_QUERY
);
574 css::uno::Reference
< XLayoutConstrains
> xTopicLayout_Bottom ( m_xTopic_Bottom
, UNO_QUERY
);
575 css::uno::Reference
< XLayoutConstrains
> xTextLayout_Bottom ( m_xText_Bottom
, UNO_QUERY
);
576 css::uno::Reference
< XLayoutConstrains
> xButtonLayout ( m_xButton
, UNO_QUERY
);
578 Size aTopicSize_Top
= xTopicLayout_Top
->getPreferredSize ();
579 Size aTextSize_Top
= xTextLayout_Top
->getPreferredSize ();
580 Size aTopicSize_Bottom
= xTopicLayout_Bottom
->getPreferredSize ();
581 Size aTextSize_Bottom
= xTextLayout_Bottom
->getPreferredSize ();
582 Size aButtonSize
= xButtonLayout
->getPreferredSize ();
584 // calc position and size of child controls
585 // Button has preferred size!
586 nWidth_Button
= aButtonSize
.Width
;
587 nHeight_Button
= aButtonSize
.Height
;
589 // Left column before progressbar has preferred size and fixed position.
590 // But "Width" is oriented on left column below progressbar to!!! "max(...)"
591 nX_Topic_Top
= PROGRESSMONITOR_FREEBORDER
;
592 nY_Topic_Top
= PROGRESSMONITOR_FREEBORDER
;
593 nWidth_Topic_Top
= std::max( aTopicSize_Top
.Width
, aTopicSize_Bottom
.Width
);
594 nHeight_Topic_Top
= aTopicSize_Top
.Height
;
596 // Right column before progressbar has relative position to left column ...
597 // ... and a size as rest of dialog size!
598 nX_Text_Top
= nX_Topic_Top
+nWidth_Topic_Top
+PROGRESSMONITOR_FREEBORDER
;
599 nY_Text_Top
= nY_Topic_Top
;
600 nWidth_Text_Top
= std::max ( aTextSize_Top
.Width
, aTextSize_Bottom
.Width
);
601 // Fix size of this column to minimum!
602 sal_Int32 nSummaryWidth
= nWidth_Text_Top
+nWidth_Topic_Top
+(3*PROGRESSMONITOR_FREEBORDER
);
603 if ( nSummaryWidth
< PROGRESSMONITOR_DEFAULT_WIDTH
)
604 nWidth_Text_Top
= PROGRESSMONITOR_DEFAULT_WIDTH
-nWidth_Topic_Top
-(3*PROGRESSMONITOR_FREEBORDER
);
605 // Fix size of column to maximum!
606 if ( nSummaryWidth
> impl_getWidth() )
607 nWidth_Text_Top
= impl_getWidth()-nWidth_Topic_Top
-(3*PROGRESSMONITOR_FREEBORDER
);
608 nHeight_Text_Top
= nHeight_Topic_Top
;
610 // Position of progressbar is relative to columns before.
611 // Progressbar.Width = Dialog.Width !!!
612 // Progressbar.Height = Button.Height
613 nX_ProgressBar
= nX_Topic_Top
;
614 nY_ProgressBar
= nY_Topic_Top
+nHeight_Topic_Top
+PROGRESSMONITOR_FREEBORDER
;
615 nWidth_ProgressBar
= PROGRESSMONITOR_FREEBORDER
+nWidth_Topic_Top
+nWidth_Text_Top
;
616 nHeight_ProgressBar
= nHeight_Button
;
618 // Oriented by left column before progressbar.
619 nX_Topic_Bottom
= nX_Topic_Top
;
620 nY_Topic_Bottom
= nY_ProgressBar
+nHeight_ProgressBar
+PROGRESSMONITOR_FREEBORDER
;
621 nWidth_Topic_Bottom
= nWidth_Topic_Top
;
622 nHeight_Topic_Bottom
= aTopicSize_Bottom
.Height
;
624 // Oriented by right column before progressbar.
625 nX_Text_Bottom
= nX_Topic_Bottom
+nWidth_Topic_Bottom
+PROGRESSMONITOR_FREEBORDER
;
626 nY_Text_Bottom
= nY_Topic_Bottom
;
627 nWidth_Text_Bottom
= nWidth_Text_Top
;
628 nHeight_Text_Bottom
= nHeight_Topic_Bottom
;
630 // Oriented by progressbar.
631 nX_Button
= nX_ProgressBar
+nWidth_ProgressBar
-nWidth_Button
;
632 nY_Button
= nY_Topic_Bottom
+nHeight_Topic_Bottom
+PROGRESSMONITOR_FREEBORDER
;
634 // Calc offsets to center controls
638 nDx
= ( (2*PROGRESSMONITOR_FREEBORDER
)+nWidth_ProgressBar
);
639 nDy
= ( (6*PROGRESSMONITOR_FREEBORDER
)+nHeight_Topic_Top
+nHeight_ProgressBar
+nHeight_Topic_Bottom
+2+nHeight_Button
);
641 // At this point use original dialog size to center controls!
642 nDx
= (impl_getWidth ()/2)-(nDx
/2);
643 nDy
= (impl_getHeight()/2)-(nDy
/2);
654 // Set new position and size on all controls
655 css::uno::Reference
< XWindow
> xRef_Topic_Top ( m_xTopic_Top
, UNO_QUERY
);
656 css::uno::Reference
< XWindow
> xRef_Text_Top ( m_xText_Top
, UNO_QUERY
);
657 css::uno::Reference
< XWindow
> xRef_Topic_Bottom ( m_xTopic_Bottom
, UNO_QUERY
);
658 css::uno::Reference
< XWindow
> xRef_Text_Bottom ( m_xText_Bottom
, UNO_QUERY
);
659 css::uno::Reference
< XWindow
> xRef_Button ( m_xButton
, UNO_QUERY
);
661 xRef_Topic_Top
->setPosSize ( nDx
+nX_Topic_Top
, nDy
+nY_Topic_Top
, nWidth_Topic_Top
, nHeight_Topic_Top
, 15 );
662 xRef_Text_Top
->setPosSize ( nDx
+nX_Text_Top
, nDy
+nY_Text_Top
, nWidth_Text_Top
, nHeight_Text_Top
, 15 );
663 xRef_Topic_Bottom
->setPosSize ( nDx
+nX_Topic_Bottom
, nDy
+nY_Topic_Bottom
, nWidth_Topic_Bottom
, nHeight_Topic_Bottom
, 15 );
664 xRef_Text_Bottom
->setPosSize ( nDx
+nX_Text_Bottom
, nDy
+nY_Text_Bottom
, nWidth_Text_Bottom
, nHeight_Text_Bottom
, 15 );
665 xRef_Button
->setPosSize ( nDx
+nX_Button
, nDy
+nY_Button
, nWidth_Button
, nHeight_Button
, 15 );
666 m_xProgressBar
->setPosSize( nDx
+nX_ProgressBar
, nDy
+nY_ProgressBar
, nWidth_ProgressBar
, nHeight_ProgressBar
, 15 );
668 m_a3DLine
.X
= nDx
+nX_Topic_Top
;
669 m_a3DLine
.Y
= nDy
+nY_Topic_Bottom
+nHeight_Topic_Bottom
+(PROGRESSMONITOR_FREEBORDER
/2);
670 m_a3DLine
.Width
= nWidth_ProgressBar
;
671 m_a3DLine
.Height
= nHeight_ProgressBar
;
673 // All childcontrols make an implicit repaint in setPosSize()!
674 // Make it also for this 3D-line ...
675 css::uno::Reference
< XGraphics
> xGraphics
= impl_getGraphicsPeer ();
677 xGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW
);
678 xGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
);
680 xGraphics
->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT
);
681 xGraphics
->drawLine ( m_a3DLine
.X
, m_a3DLine
.Y
+1, m_a3DLine
.X
+m_a3DLine
.Width
, m_a3DLine
.Y
+1 );
685 void ProgressMonitor::impl_rebuildFixedText ()
687 // Ready for multithreading
688 MutexGuard
aGuard ( m_aMutex
);
690 // Rebuild fixedtext before progress
692 // Rebuild left site of text
693 if (m_xTopic_Top
.is())
695 OUStringBuffer aCollectString
;
697 // Collect all topics from list and format text.
698 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
699 for (auto const & rSearchItem
: maTextlist_Top
)
701 aCollectString
.append(rSearchItem
.sTopic
+ "\n");
704 m_xTopic_Top
->setText ( aCollectString
.makeStringAndClear() );
707 // Rebuild right site of text
708 if (m_xText_Top
.is())
710 OUStringBuffer aCollectString
;
712 // Collect all topics from list and format text.
713 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
714 for (auto const & rSearchItem
: maTextlist_Top
)
716 aCollectString
.append(rSearchItem
.sText
+ "\n");
719 m_xText_Top
->setText ( aCollectString
.makeStringAndClear() );
722 // Rebuild fixedtext below progress
724 // Rebuild left site of text
725 if (m_xTopic_Bottom
.is())
727 OUStringBuffer aCollectString
;
729 // Collect all topics from list and format text.
730 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
731 for (auto const & rSearchItem
: maTextlist_Bottom
)
733 aCollectString
.append(rSearchItem
.sTopic
+ "\n");
736 m_xTopic_Bottom
->setText ( aCollectString
.makeStringAndClear() );
739 // Rebuild right site of text
740 if (!m_xText_Bottom
.is())
743 OUStringBuffer aCollectString
;
745 // Collect all topics from list and format text.
746 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
747 for (auto const & rSearchItem
: maTextlist_Bottom
)
749 aCollectString
.append(rSearchItem
.sText
+ "\n");
752 m_xText_Bottom
->setText ( aCollectString
.makeStringAndClear() );
756 void ProgressMonitor::impl_cleanMemory ()
758 // Ready for multithreading
759 MutexGuard
aGuard ( m_aMutex
);
761 // Delete all of lists.
762 maTextlist_Top
.clear();
763 maTextlist_Bottom
.clear();
767 IMPL_TextlistItem
* ProgressMonitor::impl_searchTopic ( std::u16string_view rTopic
, bool bbeforeProgress
)
769 // Get right textlist for following operations.
770 ::std::vector
< IMPL_TextlistItem
>* pTextList
;
774 pTextList
= &maTextlist_Top
;
778 pTextList
= &maTextlist_Bottom
;
781 // Search the topic in textlist.
782 size_t nPosition
= 0;
783 size_t nCount
= pTextList
->size();
785 for ( nPosition
= 0; nPosition
< nCount
; ++nPosition
)
787 auto& rSearchItem
= pTextList
->at( nPosition
);
789 if ( rSearchItem
.sTopic
== rTopic
)
791 // We have found this topic... return a valid pointer.
796 // We haven't found this topic... return a nonvalid pointer.
802 // addText, updateText
803 bool ProgressMonitor::impl_debug_checkParameter (
804 std::u16string_view rTopic
,
805 std::u16string_view rText
807 if ( rTopic
.empty() ) return false; // ""
809 if ( rText
.empty() ) return false; // ""
811 // Parameter OK ... return true.
816 bool ProgressMonitor::impl_debug_checkParameter ( std::u16string_view rTopic
)
818 if ( rTopic
.empty() ) return false; // ""
820 // Parameter OK ... return true.
824 } // namespace unocontrols
826 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
827 stardiv_UnoControls_ProgressMonitor_get_implementation(
828 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
830 return cppu::acquire(new unocontrols::ProgressMonitor(context
));
832 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */