fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / UnoControls / source / controls / progressmonitor.cxx
blob709ea0fe207bf577f13150450c3e58f40183bb1b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/GradientStyle.hpp>
23 #include <com/sun/star/awt/RasterOperation.hpp>
24 #include <com/sun/star/awt/Gradient.hpp>
25 #include <com/sun/star/awt/XGraphics.hpp>
26 #include <com/sun/star/awt/PosSize.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <cppuhelper/typeprovider.hxx>
29 #include <cppuhelper/queryinterface.hxx>
30 #include <tools/debug.hxx>
31 #include <algorithm>
33 #include "progressbar.hxx"
35 using namespace ::cppu;
36 using namespace ::osl;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::awt;
41 using ::std::vector;
42 using ::std::find;
44 namespace unocontrols{
46 ProgressMonitor::ProgressMonitor( const css::uno::Reference< XComponentContext >& rxContext )
47 : BaseContainerControl ( rxContext )
49 // Its not allowed to work with member in this method (refcounter !!!)
50 // But with a HACK (++refcount) its "OK" :-(
51 ++m_refCount;
53 // Create instances for fixedtext, button and progress ...
55 m_xTopic_Top = css::uno::Reference< XFixedText > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY );
56 m_xText_Top = css::uno::Reference< XFixedText > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY );
57 m_xTopic_Bottom = css::uno::Reference< XFixedText > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY );
58 m_xText_Bottom = css::uno::Reference< XFixedText > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY );
59 m_xButton = css::uno::Reference< XButton > ( rxContext->getServiceManager()->createInstanceWithContext( BUTTON_SERVICENAME, rxContext ), UNO_QUERY );
60 m_xProgressBar = VclPtr<ProgressBar>::Create(rxContext);
62 // ... cast controls to Reference< XControl > (for "setModel"!) ...
63 css::uno::Reference< XControl > xRef_Topic_Top ( m_xTopic_Top , UNO_QUERY );
64 css::uno::Reference< XControl > xRef_Text_Top ( m_xText_Top , UNO_QUERY );
65 css::uno::Reference< XControl > xRef_Topic_Bottom ( m_xTopic_Bottom , UNO_QUERY );
66 css::uno::Reference< XControl > xRef_Text_Bottom ( m_xText_Bottom , UNO_QUERY );
67 css::uno::Reference< XControl > xRef_Button ( m_xButton , UNO_QUERY );
69 // ... set models ...
70 xRef_Topic_Top->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) );
71 xRef_Text_Top->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) );
72 xRef_Topic_Bottom->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) );
73 xRef_Text_Bottom->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) );
74 xRef_Button->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( BUTTON_MODELNAME, rxContext ), UNO_QUERY ) );
75 // ProgressBar has no model !!!
77 // ... and add controls to basecontainercontrol!
78 addControl ( CONTROLNAME_TEXT, xRef_Topic_Top );
79 addControl ( CONTROLNAME_TEXT, xRef_Text_Top );
80 addControl ( CONTROLNAME_TEXT, xRef_Topic_Bottom );
81 addControl ( CONTROLNAME_TEXT, xRef_Text_Bottom );
82 addControl ( CONTROLNAME_BUTTON, xRef_Button );
83 addControl ( CONTROLNAME_PROGRESSBAR, m_xProgressBar.get() );
85 // FixedText make it automatically visible by himself ... but not the progressbar !!!
86 // it must be set explicitly
87 m_xProgressBar->setVisible( true );
89 // Reset to defaults !!!
90 // (progressbar take automatically its own defaults)
91 m_xButton->setLabel ( DEFAULT_BUTTONLABEL );
92 m_xTopic_Top->setText ( PROGRESSMONITOR_DEFAULT_TOPIC );
93 m_xText_Top->setText ( PROGRESSMONITOR_DEFAULT_TEXT );
94 m_xTopic_Bottom->setText ( PROGRESSMONITOR_DEFAULT_TOPIC );
95 m_xText_Bottom->setText ( PROGRESSMONITOR_DEFAULT_TEXT );
97 --m_refCount;
100 ProgressMonitor::~ProgressMonitor()
102 impl_cleanMemory ();
105 // XInterface
106 Any SAL_CALL ProgressMonitor::queryInterface( const Type& rType ) throw( RuntimeException, std::exception )
108 // Attention:
109 // Don't use mutex or guard in this method!!! Is a method of XInterface.
110 Any aReturn;
111 css::uno::Reference< XInterface > xDel = BaseContainerControl::impl_getDelegator();
112 if ( xDel.is() )
114 // If an delegator exist, forward question to his queryInterface.
115 // Delegator will ask his own queryAggregation!
116 aReturn = xDel->queryInterface( rType );
118 else
120 // If an delegator unknown, forward question to own queryAggregation.
121 aReturn = queryAggregation( rType );
124 return aReturn;
127 // XInterface
128 void SAL_CALL ProgressMonitor::acquire() throw()
130 // Attention:
131 // Don't use mutex or guard in this method!!! Is a method of XInterface.
133 // Forward to baseclass
134 BaseControl::acquire();
137 // XInterface
138 void SAL_CALL ProgressMonitor::release() throw()
140 // Attention:
141 // Don't use mutex or guard in this method!!! Is a method of XInterface.
143 // Forward to baseclass
144 BaseControl::release();
147 // XTypeProvider
148 Sequence< Type > SAL_CALL ProgressMonitor::getTypes() throw( RuntimeException, std::exception )
150 // Optimize this method !
151 // We initialize a static variable only one time. And we don't must use a mutex at every call!
152 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
153 static OTypeCollection* pTypeCollection = NULL;
155 if ( pTypeCollection == NULL )
157 // Ready for multithreading; get global mutex for first call of this method only! see before
158 MutexGuard aGuard( Mutex::getGlobalMutex() );
160 // Control these pointer again ... it can be, that another instance will be faster then these!
161 if ( pTypeCollection == NULL )
163 // Create a static typecollection ...
164 static OTypeCollection aTypeCollection ( cppu::UnoType<XLayoutConstrains>::get(),
165 cppu::UnoType<XButton>::get(),
166 cppu::UnoType<XProgressMonitor>::get(),
167 BaseContainerControl::getTypes()
169 // ... and set his address to static pointer!
170 pTypeCollection = &aTypeCollection;
174 return pTypeCollection->getTypes();
177 // XAggregation
178 Any SAL_CALL ProgressMonitor::queryAggregation( const Type& aType ) throw( RuntimeException, std::exception )
180 // Ask for my own supported interfaces ...
181 // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
182 Any aReturn ( ::cppu::queryInterface( aType ,
183 static_cast< XLayoutConstrains* > ( this ) ,
184 static_cast< XButton* > ( this ) ,
185 static_cast< XProgressMonitor* > ( this )
189 // If searched interface not supported by this class ...
190 if ( !aReturn.hasValue() )
192 // ... ask baseclasses.
193 aReturn = BaseControl::queryAggregation( aType );
196 return aReturn;
199 // XProgressMonitor
200 void SAL_CALL ProgressMonitor::addText(
201 const OUString& rTopic,
202 const OUString& rText,
203 sal_Bool bbeforeProgress
204 ) throw( RuntimeException, std::exception )
206 // Safe impossible cases
207 // Check valid call of this method.
208 DBG_ASSERT ( impl_debug_checkParameter ( rTopic, rText, bbeforeProgress ) , "ProgressMonitor::addText()\nCall without valid parameters!\n");
209 DBG_ASSERT ( !(impl_searchTopic ( rTopic, bbeforeProgress ) != NULL ) , "ProgresMonitor::addText()\nThe text already exist.\n" );
211 // Do nothing (in Release), if topic already exist.
212 if ( impl_searchTopic ( rTopic, bbeforeProgress ) != NULL )
214 return;
217 // Else ... take memory for new item ...
218 IMPL_TextlistItem* pTextItem = new IMPL_TextlistItem;
220 // Set values ...
221 pTextItem->sTopic = rTopic;
222 pTextItem->sText = rText;
224 // Ready for multithreading
225 MutexGuard aGuard ( m_aMutex );
227 // ... and insert it in right list.
228 if ( bbeforeProgress )
230 maTextlist_Top.push_back( pTextItem );
232 else
234 maTextlist_Bottom.push_back( pTextItem );
237 // ... update window
238 impl_rebuildFixedText ();
239 impl_recalcLayout ();
242 // XProgressMonitor
243 void SAL_CALL ProgressMonitor::removeText ( const OUString& rTopic, sal_Bool bbeforeProgress ) throw( RuntimeException, std::exception )
245 // Safe impossible cases
246 // Check valid call of this method.
247 DBG_ASSERT ( impl_debug_checkParameter ( rTopic, bbeforeProgress ), "ProgressMonitor::removeText()\nCall without valid parameters!\n" );
249 // Search the topic ...
250 IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress );
252 if ( pSearchItem != NULL )
254 // Ready for multithreading
255 MutexGuard aGuard ( m_aMutex );
257 // ... delete item from right list ...
258 if ( bbeforeProgress )
260 vector< IMPL_TextlistItem* >::iterator
261 itr = find( maTextlist_Top.begin(), maTextlist_Top.end(), pSearchItem );
262 if (itr != maTextlist_Top.end())
263 maTextlist_Top.erase(itr);
265 else
267 vector< IMPL_TextlistItem* >::iterator
268 itr = find( maTextlist_Bottom.begin(), maTextlist_Bottom.end(), pSearchItem );
269 if (itr != maTextlist_Bottom.end())
270 maTextlist_Bottom.erase(itr);
273 delete pSearchItem;
275 // ... and update window.
276 impl_rebuildFixedText ();
277 impl_recalcLayout ();
281 // XProgressMonitor
282 void SAL_CALL ProgressMonitor::updateText (
283 const OUString& rTopic,
284 const OUString& rText,
285 sal_Bool bbeforeProgress
286 ) throw( RuntimeException, std::exception )
288 // Safe impossible cases
289 // Check valid call of this method.
290 DBG_ASSERT ( impl_debug_checkParameter ( rTopic, rText, bbeforeProgress ), "ProgressMonitor::updateText()\nCall without valid parameters!\n" );
292 // Search topic ...
293 IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress );
295 if ( pSearchItem != NULL )
297 // Ready for multithreading
298 MutexGuard aGuard ( m_aMutex );
300 // ... update text ...
301 pSearchItem->sText = rText;
303 // ... and update window.
304 impl_rebuildFixedText ();
305 impl_recalcLayout ();
309 // XProgressBar
310 void SAL_CALL ProgressMonitor::setForegroundColor ( sal_Int32 nColor ) throw( RuntimeException, std::exception )
312 // Ready for multithreading
313 MutexGuard aGuard ( m_aMutex );
315 m_xProgressBar->setForegroundColor ( nColor );
318 // XProgressBar
319 void SAL_CALL ProgressMonitor::setBackgroundColor ( sal_Int32 nColor ) throw( RuntimeException, std::exception )
321 // Ready for multithreading
322 MutexGuard aGuard ( m_aMutex );
324 m_xProgressBar->setBackgroundColor ( nColor );
327 // XProgressBar
328 void SAL_CALL ProgressMonitor::setValue ( sal_Int32 nValue ) throw( RuntimeException, std::exception )
330 // Ready for multithreading
331 MutexGuard aGuard ( m_aMutex );
333 m_xProgressBar->setValue ( nValue );
336 // XProgressBar
337 void SAL_CALL ProgressMonitor::setRange ( sal_Int32 nMin, sal_Int32 nMax ) throw( RuntimeException, std::exception )
339 // Ready for multithreading
340 MutexGuard aGuard ( m_aMutex );
342 m_xProgressBar->setRange ( nMin, nMax );
345 // XProgressBar
346 sal_Int32 SAL_CALL ProgressMonitor::getValue () throw( RuntimeException, std::exception )
348 // Ready for multithreading
349 MutexGuard aGuard ( m_aMutex );
351 return m_xProgressBar->getValue ();
354 // XButton
355 void SAL_CALL ProgressMonitor::addActionListener ( const css::uno::Reference< XActionListener > & rListener ) throw( RuntimeException, std::exception )
357 // Ready for multithreading
358 MutexGuard aGuard ( m_aMutex );
360 if ( m_xButton.is () )
362 m_xButton->addActionListener ( rListener );
366 // XButton
367 void SAL_CALL ProgressMonitor::removeActionListener ( const css::uno::Reference< XActionListener > & rListener ) throw( RuntimeException, std::exception )
369 // Ready for multithreading
370 MutexGuard aGuard ( m_aMutex );
372 if ( m_xButton.is () )
374 m_xButton->removeActionListener ( rListener );
378 // XButton
379 void SAL_CALL ProgressMonitor::setLabel ( const OUString& rLabel ) throw( RuntimeException, std::exception )
381 // Ready for multithreading
382 MutexGuard aGuard ( m_aMutex );
384 if ( m_xButton.is () )
386 m_xButton->setLabel ( rLabel );
390 // XButton
391 void SAL_CALL ProgressMonitor::setActionCommand ( const OUString& rCommand ) throw( RuntimeException, std::exception )
393 // Ready for multithreading
394 MutexGuard aGuard ( m_aMutex );
396 if ( m_xButton.is () )
398 m_xButton->setActionCommand ( rCommand );
402 // XLayoutConstrains
403 Size SAL_CALL ProgressMonitor::getMinimumSize () throw( RuntimeException, std::exception )
405 return Size (PROGRESSMONITOR_DEFAULT_WIDTH, PROGRESSMONITOR_DEFAULT_HEIGHT);
408 // XLayoutConstrains
409 Size SAL_CALL ProgressMonitor::getPreferredSize () throw( RuntimeException, std::exception )
411 // Ready for multithreading
412 ClearableMutexGuard aGuard ( m_aMutex );
414 // get information about required place of child controls
415 css::uno::Reference< XLayoutConstrains > xTopicLayout_Top ( m_xTopic_Top , UNO_QUERY );
416 css::uno::Reference< XLayoutConstrains > xTopicLayout_Bottom ( m_xTopic_Bottom , UNO_QUERY );
417 css::uno::Reference< XLayoutConstrains > xButtonLayout ( m_xButton , UNO_QUERY );
419 Size aTopicSize_Top = xTopicLayout_Top->getPreferredSize ();
420 Size aTopicSize_Bottom = xTopicLayout_Bottom->getPreferredSize ();
421 Size aButtonSize = xButtonLayout->getPreferredSize ();
422 Rectangle aTempRectangle = m_xProgressBar->getPosSize();
423 Size aProgressBarSize = Size( aTempRectangle.Width, aTempRectangle.Height );
425 aGuard.clear ();
427 // calc preferred size of progressmonitor
428 sal_Int32 nWidth = 3 * PROGRESSMONITOR_FREEBORDER;
429 nWidth += aProgressBarSize.Width;
431 sal_Int32 nHeight = 6 * PROGRESSMONITOR_FREEBORDER;
432 nHeight += aTopicSize_Top.Height;
433 nHeight += aProgressBarSize.Height;
434 nHeight += aTopicSize_Bottom.Height;
435 nHeight += 2; // 1 for black line, 1 for white line = 3D-Line!
436 nHeight += aButtonSize.Height;
438 // norm to minimum
439 if ( nWidth < PROGRESSMONITOR_DEFAULT_WIDTH )
441 nWidth = PROGRESSMONITOR_DEFAULT_WIDTH;
443 if ( nHeight < PROGRESSMONITOR_DEFAULT_HEIGHT )
445 nHeight = PROGRESSMONITOR_DEFAULT_HEIGHT;
448 // return to caller
449 return Size ( nWidth, nHeight );
452 // XLayoutConstrains
453 Size SAL_CALL ProgressMonitor::calcAdjustedSize ( const Size& /*rNewSize*/ ) throw( RuntimeException, std::exception )
455 return getPreferredSize ();
458 // XControl
459 void SAL_CALL ProgressMonitor::createPeer ( const css::uno::Reference< XToolkit > & rToolkit, const css::uno::Reference< XWindowPeer > & rParent ) throw( RuntimeException, std::exception )
461 if (!getPeer().is())
463 BaseContainerControl::createPeer ( rToolkit, rParent );
465 // If user forget to call "setPosSize()", we have still a correct size.
466 // And a "MinimumSize" IS A "MinimumSize"!
467 // We change not the position of control at this point.
468 Size aDefaultSize = getMinimumSize ();
469 setPosSize ( 0, 0, aDefaultSize.Width, aDefaultSize.Height, PosSize::SIZE );
473 // XControl
474 sal_Bool SAL_CALL ProgressMonitor::setModel ( const css::uno::Reference< XControlModel > & /*rModel*/ ) throw( RuntimeException, std::exception )
476 // We have no model.
477 return false;
480 // XControl
481 css::uno::Reference< XControlModel > SAL_CALL ProgressMonitor::getModel () throw( RuntimeException, std::exception )
483 // We have no model.
484 // return (XControlModel*)this;
485 return css::uno::Reference< XControlModel > ();
488 // XComponent
489 void SAL_CALL ProgressMonitor::dispose () throw( RuntimeException, std::exception )
491 // Ready for multithreading
492 MutexGuard aGuard ( m_aMutex );
494 // "removeControl()" control the state of a reference
495 css::uno::Reference< XControl > xRef_Topic_Top ( m_xTopic_Top , UNO_QUERY );
496 css::uno::Reference< XControl > xRef_Text_Top ( m_xText_Top , UNO_QUERY );
497 css::uno::Reference< XControl > xRef_Topic_Bottom ( m_xTopic_Bottom , UNO_QUERY );
498 css::uno::Reference< XControl > xRef_Text_Bottom ( m_xText_Bottom , UNO_QUERY );
499 css::uno::Reference< XControl > xRef_Button ( m_xButton , UNO_QUERY );
501 removeControl ( xRef_Topic_Top );
502 removeControl ( xRef_Text_Top );
503 removeControl ( xRef_Topic_Bottom );
504 removeControl ( xRef_Text_Bottom );
505 removeControl ( xRef_Button );
506 removeControl ( m_xProgressBar.get() );
508 // do'nt use "...->clear ()" or "... = XFixedText ()"
509 // when other hold a reference at this object !!!
510 xRef_Topic_Top->dispose ();
511 xRef_Text_Top->dispose ();
512 xRef_Topic_Bottom->dispose ();
513 xRef_Text_Bottom->dispose ();
514 xRef_Button->dispose ();
515 m_xProgressBar->dispose();
517 BaseContainerControl::dispose ();
520 // XWindow
521 void SAL_CALL ProgressMonitor::setPosSize ( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags ) throw( RuntimeException, std::exception )
523 Rectangle aBasePosSize = getPosSize ();
524 BaseContainerControl::setPosSize (nX, nY, nWidth, nHeight, nFlags);
526 // if position or size changed
527 if (
528 ( nWidth != aBasePosSize.Width ) ||
529 ( nHeight != aBasePosSize.Height)
532 // calc new layout for controls
533 impl_recalcLayout ();
534 // clear background (!)
535 // [Children were repainted in "recalcLayout" by setPosSize() automatically!]
536 getPeer()->invalidate(2);
537 // and repaint the control
538 impl_paint ( 0, 0, impl_getGraphicsPeer() );
542 // impl but public method to register service
543 const Sequence< OUString > ProgressMonitor::impl_getStaticSupportedServiceNames()
545 return css::uno::Sequence<OUString>();
548 // impl but public method to register service
549 const OUString ProgressMonitor::impl_getStaticImplementationName()
551 return OUString("stardiv.UnoControls.ProgressMonitor");
554 // protected method
555 void ProgressMonitor::impl_paint ( sal_Int32 nX, sal_Int32 nY, const css::uno::Reference< XGraphics > & rGraphics )
557 if (rGraphics.is())
559 // Ready for multithreading
560 MutexGuard aGuard ( m_aMutex );
562 // paint shadowed border around the progressmonitor
563 rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW );
564 rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY );
565 rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX , impl_getHeight()-1 );
567 rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT );
568 rGraphics->drawLine ( nX, nY, impl_getWidth(), nY );
569 rGraphics->drawLine ( nX, nY, nX , impl_getHeight() );
571 // Paint 3D-line
572 rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW );
573 rGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y );
575 rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT );
576 rGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y+1, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y+1 );
580 // private method
581 void ProgressMonitor::impl_recalcLayout ()
583 sal_Int32 nX_Button;
584 sal_Int32 nY_Button;
585 sal_Int32 nWidth_Button;
586 sal_Int32 nHeight_Button;
588 sal_Int32 nX_ProgressBar;
589 sal_Int32 nY_ProgressBar;
590 sal_Int32 nWidth_ProgressBar;
591 sal_Int32 nHeight_ProgressBar;
593 sal_Int32 nX_Text_Top;
594 sal_Int32 nY_Text_Top;
595 sal_Int32 nWidth_Text_Top;
596 sal_Int32 nHeight_Text_Top;
598 sal_Int32 nX_Topic_Top;
599 sal_Int32 nY_Topic_Top;
600 sal_Int32 nWidth_Topic_Top;
601 sal_Int32 nHeight_Topic_Top;
603 sal_Int32 nX_Text_Bottom;
604 sal_Int32 nY_Text_Bottom;
605 sal_Int32 nWidth_Text_Bottom;
606 sal_Int32 nHeight_Text_Bottom;
608 sal_Int32 nX_Topic_Bottom;
609 sal_Int32 nY_Topic_Bottom;
610 sal_Int32 nWidth_Topic_Bottom;
611 sal_Int32 nHeight_Topic_Bottom;
613 // Ready for multithreading
614 MutexGuard aGuard ( m_aMutex );
616 // get information about required place of child controls
617 css::uno::Reference< XLayoutConstrains > xTopicLayout_Top ( m_xTopic_Top , UNO_QUERY );
618 css::uno::Reference< XLayoutConstrains > xTextLayout_Top ( m_xText_Top , UNO_QUERY );
619 css::uno::Reference< XLayoutConstrains > xTopicLayout_Bottom ( m_xTopic_Bottom , UNO_QUERY );
620 css::uno::Reference< XLayoutConstrains > xTextLayout_Bottom ( m_xText_Bottom , UNO_QUERY );
621 css::uno::Reference< XLayoutConstrains > xButtonLayout ( m_xButton , UNO_QUERY );
623 Size aTopicSize_Top = xTopicLayout_Top->getPreferredSize ();
624 Size aTextSize_Top = xTextLayout_Top->getPreferredSize ();
625 Size aTopicSize_Bottom = xTopicLayout_Bottom->getPreferredSize ();
626 Size aTextSize_Bottom = xTextLayout_Bottom->getPreferredSize ();
627 Size aButtonSize = xButtonLayout->getPreferredSize ();
629 // calc position and size of child controls
630 // Button has preferred size!
631 nWidth_Button = aButtonSize.Width;
632 nHeight_Button = aButtonSize.Height;
634 // Left column before progressbar has preferred size and fixed position.
635 // But "Width" is oriented on left column below progressbar to!!! "max(...)"
636 nX_Topic_Top = PROGRESSMONITOR_FREEBORDER;
637 nY_Topic_Top = PROGRESSMONITOR_FREEBORDER;
638 nWidth_Topic_Top = std::max( aTopicSize_Top.Width, aTopicSize_Bottom.Width );
639 nHeight_Topic_Top = aTopicSize_Top.Height;
641 // Right column before progressbar has relativ position to left column ...
642 // ... and a size as rest of dialog size!
643 nX_Text_Top = nX_Topic_Top+nWidth_Topic_Top+PROGRESSMONITOR_FREEBORDER;
644 nY_Text_Top = nY_Topic_Top;
645 nWidth_Text_Top = std::max ( aTextSize_Top.Width, aTextSize_Bottom.Width );
646 // Fix size of this column to minimum!
647 sal_Int32 nSummaryWidth = nWidth_Text_Top+nWidth_Topic_Top+(3*PROGRESSMONITOR_FREEBORDER);
648 if ( nSummaryWidth < PROGRESSMONITOR_DEFAULT_WIDTH )
649 nWidth_Text_Top = PROGRESSMONITOR_DEFAULT_WIDTH-nWidth_Topic_Top-(3*PROGRESSMONITOR_FREEBORDER);
650 // Fix size of column to maximum!
651 if ( nSummaryWidth > impl_getWidth() )
652 nWidth_Text_Top = impl_getWidth()-nWidth_Topic_Top-(3*PROGRESSMONITOR_FREEBORDER);
653 nHeight_Text_Top = nHeight_Topic_Top;
655 // Position of progressbar is relativ to columns before.
656 // Progressbar.Width = Dialog.Width !!!
657 // Progressbar.Height = Button.Height
658 nX_ProgressBar = nX_Topic_Top;
659 nY_ProgressBar = nY_Topic_Top+nHeight_Topic_Top+PROGRESSMONITOR_FREEBORDER;
660 nWidth_ProgressBar = PROGRESSMONITOR_FREEBORDER+nWidth_Topic_Top+nWidth_Text_Top;
661 nHeight_ProgressBar = nHeight_Button;
663 // Oriented by left column before progressbar.
664 nX_Topic_Bottom = nX_Topic_Top;
665 nY_Topic_Bottom = nY_ProgressBar+nHeight_ProgressBar+PROGRESSMONITOR_FREEBORDER;
666 nWidth_Topic_Bottom = nWidth_Topic_Top;
667 nHeight_Topic_Bottom = aTopicSize_Bottom.Height;
669 // Oriented by right column before progressbar.
670 nX_Text_Bottom = nX_Topic_Bottom+nWidth_Topic_Bottom+PROGRESSMONITOR_FREEBORDER;
671 nY_Text_Bottom = nY_Topic_Bottom;
672 nWidth_Text_Bottom = nWidth_Text_Top;
673 nHeight_Text_Bottom = nHeight_Topic_Bottom;
675 // Oriented by progressbar.
676 nX_Button = nX_ProgressBar+nWidth_ProgressBar-nWidth_Button;
677 nY_Button = nY_Topic_Bottom+nHeight_Topic_Bottom+PROGRESSMONITOR_FREEBORDER;
679 // Calc offsets to center controls
680 sal_Int32 nDx;
681 sal_Int32 nDy;
683 nDx = ( (2*PROGRESSMONITOR_FREEBORDER)+nWidth_ProgressBar );
684 nDy = ( (6*PROGRESSMONITOR_FREEBORDER)+nHeight_Topic_Top+nHeight_ProgressBar+nHeight_Topic_Bottom+2+nHeight_Button );
686 // At this point use original dialog size to center controls!
687 nDx = (impl_getWidth ()/2)-(nDx/2);
688 nDy = (impl_getHeight()/2)-(nDy/2);
690 if ( nDx<0 )
692 nDx=0;
694 if ( nDy<0 )
696 nDy=0;
699 // Set new position and size on all controls
700 css::uno::Reference< XWindow > xRef_Topic_Top ( m_xTopic_Top , UNO_QUERY );
701 css::uno::Reference< XWindow > xRef_Text_Top ( m_xText_Top , UNO_QUERY );
702 css::uno::Reference< XWindow > xRef_Topic_Bottom ( m_xTopic_Bottom , UNO_QUERY );
703 css::uno::Reference< XWindow > xRef_Text_Bottom ( m_xText_Bottom , UNO_QUERY );
704 css::uno::Reference< XWindow > xRef_Button ( m_xButton , UNO_QUERY );
706 xRef_Topic_Top->setPosSize ( nDx+nX_Topic_Top , nDy+nY_Topic_Top , nWidth_Topic_Top , nHeight_Topic_Top , 15 );
707 xRef_Text_Top->setPosSize ( nDx+nX_Text_Top , nDy+nY_Text_Top , nWidth_Text_Top , nHeight_Text_Top , 15 );
708 xRef_Topic_Bottom->setPosSize ( nDx+nX_Topic_Bottom , nDy+nY_Topic_Bottom , nWidth_Topic_Bottom , nHeight_Topic_Bottom , 15 );
709 xRef_Text_Bottom->setPosSize ( nDx+nX_Text_Bottom , nDy+nY_Text_Bottom , nWidth_Text_Bottom , nHeight_Text_Bottom , 15 );
710 xRef_Button->setPosSize ( nDx+nX_Button , nDy+nY_Button , nWidth_Button , nHeight_Button , 15 );
711 m_xProgressBar->setPosSize( nDx+nX_ProgressBar, nDy+nY_ProgressBar, nWidth_ProgressBar, nHeight_ProgressBar, 15 );
713 m_a3DLine.X = nDx+nX_Topic_Top;
714 m_a3DLine.Y = nDy+nY_Topic_Bottom+nHeight_Topic_Bottom+(PROGRESSMONITOR_FREEBORDER/2);
715 m_a3DLine.Width = nWidth_ProgressBar;
716 m_a3DLine.Height = nHeight_ProgressBar;
718 // All childcontrols make an implicit repaint in setPosSize()!
719 // Make it also for this 3D-line ...
720 css::uno::Reference< XGraphics > xGraphics = impl_getGraphicsPeer ();
722 xGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW );
723 xGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y );
725 xGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT );
726 xGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y+1, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y+1 );
729 // private method
730 void ProgressMonitor::impl_rebuildFixedText ()
732 // Ready for multithreading
733 MutexGuard aGuard ( m_aMutex );
735 // Rebuild fixedtext before progress
737 // Rebuild left site of text
738 if (m_xTopic_Top.is())
740 OUString aCollectString;
742 // Collect all topics from list and format text.
743 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
744 for ( size_t n = 0; n < maTextlist_Top.size(); ++n )
746 IMPL_TextlistItem* pSearchItem = maTextlist_Top[ n ];
747 aCollectString += pSearchItem->sTopic;
748 aCollectString += "\n";
751 m_xTopic_Top->setText ( aCollectString );
754 // Rebuild right site of text
755 if (m_xText_Top.is())
757 OUString aCollectString;
759 // Collect all topics from list and format text.
760 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
761 for ( size_t n = 0; n < maTextlist_Top.size(); ++n )
763 IMPL_TextlistItem* pSearchItem = maTextlist_Top[ n ];
764 aCollectString += pSearchItem->sText;
765 aCollectString += "\n";
768 m_xText_Top->setText ( aCollectString );
771 // Rebuild fixedtext below progress
773 // Rebuild left site of text
774 if (m_xTopic_Bottom.is())
776 OUString aCollectString;
778 // Collect all topics from list and format text.
779 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
780 for ( size_t n = 0; n < maTextlist_Bottom.size(); ++n )
782 IMPL_TextlistItem* pSearchItem = maTextlist_Bottom[ n ];
783 aCollectString += pSearchItem->sTopic;
784 aCollectString += "\n";
787 m_xTopic_Bottom->setText ( aCollectString );
790 // Rebuild right site of text
791 if (m_xText_Bottom.is())
793 OUString aCollectString;
795 // Collect all topics from list and format text.
796 // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
797 for ( size_t n = 0; n < maTextlist_Bottom.size(); ++n )
799 IMPL_TextlistItem* pSearchItem = maTextlist_Bottom[ n ];
800 aCollectString += pSearchItem->sText;
801 aCollectString += "\n";
804 m_xText_Bottom->setText ( aCollectString );
808 // private method
809 void ProgressMonitor::impl_cleanMemory ()
811 // Ready for multithreading
812 MutexGuard aGuard ( m_aMutex );
814 // Delete all of lists.
816 for ( size_t nPosition = 0; nPosition < maTextlist_Top.size(); ++nPosition )
818 IMPL_TextlistItem* pSearchItem = maTextlist_Top[ nPosition ];
819 delete pSearchItem;
821 maTextlist_Top.clear();
823 for ( size_t nPosition = 0; nPosition < maTextlist_Bottom.size(); ++nPosition )
825 IMPL_TextlistItem* pSearchItem = maTextlist_Bottom[ nPosition ];
826 delete pSearchItem;
828 maTextlist_Bottom.clear();
831 // private method
832 IMPL_TextlistItem* ProgressMonitor::impl_searchTopic ( const OUString& rTopic, bool bbeforeProgress )
834 // Get right textlist for following operations.
835 ::std::vector< IMPL_TextlistItem* >* pTextList;
837 // Ready for multithreading
838 ClearableMutexGuard aGuard ( m_aMutex );
840 if ( bbeforeProgress )
842 pTextList = &maTextlist_Top;
844 else
846 pTextList = &maTextlist_Bottom;
849 // Switch off guard.
850 aGuard.clear ();
852 // Search the topic in textlist.
853 size_t nPosition = 0;
854 size_t nCount = pTextList->size();
856 for ( nPosition = 0; nPosition < nCount; ++nPosition )
858 IMPL_TextlistItem* pSearchItem = pTextList->at( nPosition );
860 if ( pSearchItem->sTopic == rTopic )
862 // We have found this topic... return a valid pointer.
863 return pSearchItem;
867 // We haven't found this topic... return a nonvalid pointer.
868 return NULL;
871 // debug methods
872 #ifdef DBG_UTIL
874 // addText, updateText
875 bool ProgressMonitor::impl_debug_checkParameter (
876 const OUString& rTopic,
877 const OUString& rText,
878 bool /*bbeforeProgress*/
880 if ( rTopic.isEmpty() ) return false; // ""
882 if ( rText.isEmpty() ) return false; // ""
884 // "bbeforeProgress" is valid in everyway!
886 // Parameter OK ... return true.
887 return true;
890 // removeText
891 bool ProgressMonitor::impl_debug_checkParameter ( const OUString& rTopic, bool /*bbeforeProgress*/ )
893 if ( rTopic.isEmpty() ) return false; // ""
895 // "bbeforeProgress" is valid in everyway!
897 // Parameter OK ... return true.
898 return true;
901 #endif // #ifdef DBG_UTIL
903 } // namespace unocontrols
905 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */