LibreOffice Module UnoControls (master) 1
progressmonitor.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <progressmonitor.hxx>
21
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>
28#include <rtl/ustrbuf.hxx>
29#include <tools/debug.hxx>
30#include <algorithm>
31
32#include <progressbar.hxx>
33
34using namespace ::cppu;
35using namespace ::osl;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::lang;
38using namespace ::com::sun::star::awt;
39
40using ::std::vector;
41
42constexpr OUStringLiteral FIXEDTEXT_SERVICENAME = u"com.sun.star.awt.UnoControlFixedText";
43constexpr OUStringLiteral FIXEDTEXT_MODELNAME = u"com.sun.star.awt.UnoControlFixedTextModel";
44constexpr OUStringLiteral CONTROLNAME_TEXT = u"Text"; // identifier the control in container
45constexpr OUStringLiteral CONTROLNAME_PROGRESSBAR = u"ProgressBar";
46constexpr OUStringLiteral BUTTON_SERVICENAME = u"com.sun.star.awt.UnoControlButton";
47constexpr OUStringLiteral CONTROLNAME_BUTTON = u"Button";
48constexpr OUStringLiteral BUTTON_MODELNAME = u"com.sun.star.awt.UnoControlButtonModel";
49constexpr OUStringLiteral DEFAULT_BUTTONLABEL = u"Abbrechen";
50
51namespace unocontrols {
52
53ProgressMonitor::ProgressMonitor( const css::uno::Reference< XComponentContext >& rxContext )
54 : BaseContainerControl ( rxContext )
55{
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);
59
60 // Create instances for fixedtext, button and progress ...
61
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);
68
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 );
75
76 // ... set models ...
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 !!!
83
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 );
91
92 // FixedText make it automatically visible by himself ... but not the progressbar !!!
93 // it must be set explicitly
94 m_xProgressBar->setVisible( true );
95
96 // Reset to defaults !!!
97 // (progressbar take automatically its own defaults)
98 m_xButton->setLabel ( DEFAULT_BUTTONLABEL );
103
104 osl_atomic_decrement(&m_refCount);
105}
106
108{
110}
111
112// XInterface
114{
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 )
121 )
122 );
123
124 // If searched interface not supported by this class ...
125 if ( !aReturn.hasValue() )
126 {
127 // ... ask baseclasses.
128 aReturn = BaseControl::queryInterface( rType );
129 }
130
131 return aReturn;
132}
133
134// XInterface
135void SAL_CALL ProgressMonitor::acquire() noexcept
136{
137 // Attention:
138 // Don't use mutex or guard in this method!!! Is a method of XInterface.
139
140 // Forward to baseclass
142}
143
144// XInterface
145void SAL_CALL ProgressMonitor::release() noexcept
146{
147 // Attention:
148 // Don't use mutex or guard in this method!!! Is a method of XInterface.
149
150 // Forward to baseclass
152}
153
154// XTypeProvider
155Sequence< Type > SAL_CALL ProgressMonitor::getTypes()
156{
157 static OTypeCollection ourTypeCollection(
162
163 return ourTypeCollection.getTypes();
164}
165
166// XProgressMonitor
168 const OUString& rTopic,
169 const OUString& rText,
170 sal_Bool bbeforeProgress
171)
172{
173 // Ready for multithreading
174 MutexGuard aGuard ( m_aMutex );
175
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" );
180
181 // Do nothing (in Release), if topic already exist.
182 if ( impl_searchTopic ( rTopic, bbeforeProgress ) != nullptr )
183 {
184 return;
185 }
186
187 // Else ... take memory for new item ...
188 IMPL_TextlistItem aTextItem;
189
190 // Set values ...
191 aTextItem.sTopic = rTopic;
192 aTextItem.sText = rText;
193
194 // ... and insert it in right list.
195 if ( bbeforeProgress )
196 {
197 maTextlist_Top.push_back( aTextItem );
198 }
199 else
200 {
201 maTextlist_Bottom.push_back( aTextItem );
202 }
203
204 // ... update window
207}
208
209// XProgressMonitor
210void SAL_CALL ProgressMonitor::removeText ( const OUString& rTopic, sal_Bool bbeforeProgress )
211{
212 // Safe impossible cases
213 // Check valid call of this method.
214 DBG_ASSERT ( impl_debug_checkParameter ( rTopic ), "ProgressMonitor::removeText()\nCall without valid parameters!" );
215
216 // Ready for multithreading
217 MutexGuard aGuard ( m_aMutex );
218
219 // Search the topic ...
220 IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress );
221
222 if ( pSearchItem == nullptr )
223 return;
224
225 // ... delete item from right list ...
226 if ( bbeforeProgress )
227 {
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);
233 }
234 else
235 {
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);
241 }
242
243 // ... and update window.
246}
247
248// XProgressMonitor
250 const OUString& rTopic,
251 const OUString& rText,
252 sal_Bool bbeforeProgress
253)
254{
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" );
258
259 // Ready for multithreading
260 MutexGuard aGuard ( m_aMutex );
261
262 // Search topic ...
263 IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress );
264
265 if ( pSearchItem != nullptr )
266 {
267 // ... update text ...
268 pSearchItem->sText = rText;
269
270 // ... and update window.
273 }
274}
275
276// XProgressBar
277void SAL_CALL ProgressMonitor::setForegroundColor ( sal_Int32 nColor )
278{
279 // Ready for multithreading
280 MutexGuard aGuard ( m_aMutex );
281
282 m_xProgressBar->setForegroundColor ( nColor );
283}
284
285// XProgressBar
286void SAL_CALL ProgressMonitor::setBackgroundColor ( sal_Int32 nColor )
287{
288 // Ready for multithreading
289 MutexGuard aGuard ( m_aMutex );
290
291 m_xProgressBar->setBackgroundColor ( nColor );
292}
293
294// XProgressBar
295void SAL_CALL ProgressMonitor::setValue ( sal_Int32 nValue )
296{
297 // Ready for multithreading
298 MutexGuard aGuard ( m_aMutex );
299
300 m_xProgressBar->setValue ( nValue );
301}
302
303// XProgressBar
304void SAL_CALL ProgressMonitor::setRange ( sal_Int32 nMin, sal_Int32 nMax )
305{
306 // Ready for multithreading
307 MutexGuard aGuard ( m_aMutex );
308
309 m_xProgressBar->setRange ( nMin, nMax );
310}
311
312// XProgressBar
313sal_Int32 SAL_CALL ProgressMonitor::getValue ()
314{
315 // Ready for multithreading
316 MutexGuard aGuard ( m_aMutex );
317
318 return m_xProgressBar->getValue ();
319}
320
321// XButton
322void SAL_CALL ProgressMonitor::addActionListener ( const css::uno::Reference< XActionListener > & rListener )
323{
324 // Ready for multithreading
325 MutexGuard aGuard ( m_aMutex );
326
327 if ( m_xButton.is () )
328 {
329 m_xButton->addActionListener ( rListener );
330 }
331}
332
333// XButton
334void SAL_CALL ProgressMonitor::removeActionListener ( const css::uno::Reference< XActionListener > & rListener )
335{
336 // Ready for multithreading
337 MutexGuard aGuard ( m_aMutex );
338
339 if ( m_xButton.is () )
340 {
341 m_xButton->removeActionListener ( rListener );
342 }
343}
344
345// XButton
346void SAL_CALL ProgressMonitor::setLabel ( const OUString& rLabel )
347{
348 // Ready for multithreading
349 MutexGuard aGuard ( m_aMutex );
350
351 if ( m_xButton.is () )
352 {
353 m_xButton->setLabel ( rLabel );
354 }
355}
356
357// XButton
358void SAL_CALL ProgressMonitor::setActionCommand ( const OUString& rCommand )
359{
360 // Ready for multithreading
361 MutexGuard aGuard ( m_aMutex );
362
363 if ( m_xButton.is () )
364 {
365 m_xButton->setActionCommand ( rCommand );
366 }
367}
368
369// XLayoutConstrains
371{
373}
374
375// XLayoutConstrains
377{
378 // Ready for multithreading
379 ClearableMutexGuard aGuard ( m_aMutex );
380
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 );
385
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 );
391
392 aGuard.clear ();
393
394 // calc preferred size of progressmonitor
395 sal_Int32 nWidth = 3 * PROGRESSMONITOR_FREEBORDER;
396 nWidth += aProgressBarSize.Width;
397
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;
404
405 // norm to minimum
406 if ( nWidth < PROGRESSMONITOR_DEFAULT_WIDTH )
407 {
409 }
410 if ( nHeight < PROGRESSMONITOR_DEFAULT_HEIGHT )
411 {
413 }
414
415 // return to caller
416 return Size ( nWidth, nHeight );
417}
418
419// XLayoutConstrains
420Size SAL_CALL ProgressMonitor::calcAdjustedSize ( const Size& /*rNewSize*/ )
421{
422 return getPreferredSize ();
423}
424
425// XControl
426void SAL_CALL ProgressMonitor::createPeer ( const css::uno::Reference< XToolkit > & rToolkit, const css::uno::Reference< XWindowPeer > & rParent )
427{
428 if (!getPeer().is())
429 {
430 BaseContainerControl::createPeer ( rToolkit, rParent );
431
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 );
437 }
438}
439
440// XControl
441sal_Bool SAL_CALL ProgressMonitor::setModel ( const css::uno::Reference< XControlModel > & /*rModel*/ )
442{
443 // We have no model.
444 return false;
445}
446
447// XControl
448css::uno::Reference< XControlModel > SAL_CALL ProgressMonitor::getModel ()
449{
450 // We have no model.
451 // return (XControlModel*)this;
452 return css::uno::Reference< XControlModel > ();
453}
454
455// XComponent
457{
458 // Ready for multithreading
459 MutexGuard aGuard ( m_aMutex );
460
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 );
467
468 removeControl ( xRef_Topic_Top );
469 removeControl ( xRef_Text_Top );
470 removeControl ( xRef_Topic_Bottom );
471 removeControl ( xRef_Text_Bottom );
472 removeControl ( xRef_Button );
474
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();
483
485}
486
487// XWindow
488void SAL_CALL ProgressMonitor::setPosSize ( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags )
489{
490 Rectangle aBasePosSize = getPosSize ();
491 BaseContainerControl::setPosSize (nX, nY, nWidth, nHeight, nFlags);
492
493 // if position or size changed
494 if (
495 ( nWidth != aBasePosSize.Width ) ||
496 ( nHeight != aBasePosSize.Height)
497 )
498 {
499 // calc new layout for controls
501 // clear background (!)
502 // [Children were repainted in "recalcLayout" by setPosSize() automatically!]
503 getPeer()->invalidate(2);
504 // and repaint the control
506 }
507}
508
509// protected method
510void ProgressMonitor::impl_paint ( sal_Int32 nX, sal_Int32 nY, const css::uno::Reference< XGraphics > & rGraphics )
511{
512 if (!rGraphics.is())
513 return;
514
515 // Ready for multithreading
516 MutexGuard aGuard ( m_aMutex );
517
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 );
522
523 rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT );
524 rGraphics->drawLine ( nX, nY, impl_getWidth(), nY );
525 rGraphics->drawLine ( nX, nY, nX , impl_getHeight() );
526
527 // Paint 3D-line
528 rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW );
529 rGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y );
530
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 );
533}
534
535// private method
537{
538 sal_Int32 nX_Button;
539 sal_Int32 nY_Button;
540 sal_Int32 nWidth_Button;
541 sal_Int32 nHeight_Button;
542
543 sal_Int32 nX_ProgressBar;
544 sal_Int32 nY_ProgressBar;
545 sal_Int32 nWidth_ProgressBar;
546 sal_Int32 nHeight_ProgressBar;
547
548 sal_Int32 nX_Text_Top;
549 sal_Int32 nY_Text_Top;
550 sal_Int32 nWidth_Text_Top;
551 sal_Int32 nHeight_Text_Top;
552
553 sal_Int32 nX_Topic_Top;
554 sal_Int32 nY_Topic_Top;
555 sal_Int32 nWidth_Topic_Top;
556 sal_Int32 nHeight_Topic_Top;
557
558 sal_Int32 nX_Text_Bottom;
559 sal_Int32 nY_Text_Bottom;
560 sal_Int32 nWidth_Text_Bottom;
561 sal_Int32 nHeight_Text_Bottom;
562
563 sal_Int32 nX_Topic_Bottom;
564 sal_Int32 nY_Topic_Bottom;
565 sal_Int32 nWidth_Topic_Bottom;
566 sal_Int32 nHeight_Topic_Bottom;
567
568 // Ready for multithreading
569 MutexGuard aGuard ( m_aMutex );
570
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 );
577
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 ();
583
584 // calc position and size of child controls
585 // Button has preferred size!
586 nWidth_Button = aButtonSize.Width;
587 nHeight_Button = aButtonSize.Height;
588
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;
595
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;
609
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;
617
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;
623
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;
629
630 // Oriented by progressbar.
631 nX_Button = nX_ProgressBar+nWidth_ProgressBar-nWidth_Button;
632 nY_Button = nY_Topic_Bottom+nHeight_Topic_Bottom+PROGRESSMONITOR_FREEBORDER;
633
634 // Calc offsets to center controls
635 sal_Int32 nDx;
636 sal_Int32 nDy;
637
638 nDx = ( (2*PROGRESSMONITOR_FREEBORDER)+nWidth_ProgressBar );
639 nDy = ( (6*PROGRESSMONITOR_FREEBORDER)+nHeight_Topic_Top+nHeight_ProgressBar+nHeight_Topic_Bottom+2+nHeight_Button );
640
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);
644
645 if ( nDx<0 )
646 {
647 nDx=0;
648 }
649 if ( nDy<0 )
650 {
651 nDy=0;
652 }
653
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 );
660
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 );
667
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;
672
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 ();
676
677 xGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW );
678 xGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y );
679
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 );
682}
683
684// private method
686{
687 // Ready for multithreading
688 MutexGuard aGuard ( m_aMutex );
689
690 // Rebuild fixedtext before progress
691
692 // Rebuild left site of text
693 if (m_xTopic_Top.is())
694 {
695 OUStringBuffer aCollectString;
696
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)
700 {
701 aCollectString.append(rSearchItem.sTopic + "\n");
702 }
703
704 m_xTopic_Top->setText ( aCollectString.makeStringAndClear() );
705 }
706
707 // Rebuild right site of text
708 if (m_xText_Top.is())
709 {
710 OUStringBuffer aCollectString;
711
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)
715 {
716 aCollectString.append(rSearchItem.sText + "\n");
717 }
718
719 m_xText_Top->setText ( aCollectString.makeStringAndClear() );
720 }
721
722 // Rebuild fixedtext below progress
723
724 // Rebuild left site of text
725 if (m_xTopic_Bottom.is())
726 {
727 OUStringBuffer aCollectString;
728
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)
732 {
733 aCollectString.append(rSearchItem.sTopic + "\n");
734 }
735
736 m_xTopic_Bottom->setText ( aCollectString.makeStringAndClear() );
737 }
738
739 // Rebuild right site of text
740 if (!m_xText_Bottom.is())
741 return;
742
743 OUStringBuffer aCollectString;
744
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)
748 {
749 aCollectString.append(rSearchItem.sText + "\n");
750 }
751
752 m_xText_Bottom->setText ( aCollectString.makeStringAndClear() );
753}
754
755// private method
757{
758 // Ready for multithreading
759 MutexGuard aGuard ( m_aMutex );
760
761 // Delete all of lists.
762 maTextlist_Top.clear();
763 maTextlist_Bottom.clear();
764}
765
766// private method
767IMPL_TextlistItem* ProgressMonitor::impl_searchTopic ( std::u16string_view rTopic, bool bbeforeProgress )
768{
769 // Get right textlist for following operations.
770 ::std::vector< IMPL_TextlistItem >* pTextList;
771
772 if (bbeforeProgress)
773 {
774 pTextList = &maTextlist_Top;
775 }
776 else
777 {
778 pTextList = &maTextlist_Bottom;
779 }
780
781 // Search the topic in textlist.
782 size_t nPosition = 0;
783 size_t nCount = pTextList->size();
784
785 for ( nPosition = 0; nPosition < nCount; ++nPosition )
786 {
787 auto& rSearchItem = pTextList->at( nPosition );
788
789 if ( rSearchItem.sTopic == rTopic )
790 {
791 // We have found this topic... return a valid pointer.
792 return &rSearchItem;
793 }
794 }
795
796 // We haven't found this topic... return a nonvalid pointer.
797 return nullptr;
798}
799
800// debug methods
801
802// addText, updateText
804 std::u16string_view rTopic,
805 std::u16string_view rText
806) {
807 if ( rTopic.empty() ) return false; // ""
808
809 if ( rText.empty() ) return false; // ""
810
811 // Parameter OK ... return true.
812 return true;
813}
814
815// removeText
816bool ProgressMonitor::impl_debug_checkParameter ( std::u16string_view rTopic )
817{
818 if ( rTopic.empty() ) return false; // ""
819
820 // Parameter OK ... return true.
821 return true;
822}
823
824} // namespace unocontrols
825
826extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
828 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
829{
830 return cppu::acquire(new unocontrols::ProgressMonitor(context));
831}
832/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr tools::Long Height() const
constexpr tools::Long Width() const
mutable::osl::Mutex m_aMutex
virtual void SAL_CALL dispose() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
get information about supported interfaces @seealso XTypeProvider
virtual void SAL_CALL createPeer(const css::uno::Reference< css::awt::XToolkit > &xToolkit, const css::uno::Reference< css::awt::XWindowPeer > &xParent) override
virtual void SAL_CALL removeControl(const css::uno::Reference< css::awt::XControl > &xControl) override
virtual void SAL_CALL addControl(const OUString &sName, const css::uno::Reference< css::awt::XControl > &xControl) override
sal_Int32 impl_getWidth() const
virtual void SAL_CALL setPosSize(sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags) override
sal_Int32 impl_getHeight() const
const css::uno::Reference< css::awt::XGraphics > & impl_getGraphicsPeer() const
virtual void SAL_CALL release() noexcept override
decrement refcount @seealso XInterface @seealso acquire() @onerror A RuntimeException is thrown.
virtual css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getPeer() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
give answer, if interface is supported @descr The interfaces are searched by type.
Definition: basecontrol.cxx:70
virtual css::awt::Rectangle SAL_CALL getPosSize() override
virtual void SAL_CALL acquire() noexcept override
increment refcount @seealso XInterface @seealso release() @onerror A RuntimeException is thrown.
Definition: basecontrol.cxx:99
virtual void SAL_CALL setBackgroundColor(sal_Int32 nColor) override
css::uno::Reference< css::awt::XFixedText > m_xTopic_Top
virtual css::awt::Size SAL_CALL getMinimumSize() override
virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override
virtual void SAL_CALL release() noexcept override
decrement refcount @seealso XInterface @seealso acquire() @onerror A RuntimeException is thrown.
virtual css::awt::Size SAL_CALL calcAdjustedSize(const css::awt::Size &aNewSize) override
virtual ~ProgressMonitor() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
give answer, if interface is supported @descr The interfaces are searched by type.
ProgressMonitor(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
get information about supported interfaces @seealso XTypeProvider
virtual void SAL_CALL removeText(const OUString &sTopic, sal_Bool bbeforeProgress) override
virtual sal_Bool SAL_CALL setModel(const css::uno::Reference< css::awt::XControlModel > &xModel) override
virtual void SAL_CALL setPosSize(sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags) override
::std::vector< IMPL_TextlistItem > maTextlist_Bottom
virtual css::awt::Size SAL_CALL getPreferredSize() override
virtual void SAL_CALL setForegroundColor(sal_Int32 nColor) override
virtual void SAL_CALL removeActionListener(const css::uno::Reference< css::awt::XActionListener > &xListener) override
css::uno::Reference< css::awt::XFixedText > m_xText_Bottom
virtual void SAL_CALL addText(const OUString &sTopic, const OUString &sText, sal_Bool bbeforeProgress) override
add topic to dialog @descr Add a topic with a text in right textlist (used for FixedText-member).
virtual void SAL_CALL addActionListener(const css::uno::Reference< css::awt::XActionListener > &xListener) override
virtual void SAL_CALL dispose() override
::std::vector< IMPL_TextlistItem > maTextlist_Top
virtual void SAL_CALL createPeer(const css::uno::Reference< css::awt::XToolkit > &xToolkit, const css::uno::Reference< css::awt::XWindowPeer > &xParent) override
virtual sal_Int32 SAL_CALL getValue() override
virtual void impl_paint(sal_Int32 nX, sal_Int32 nY, const css::uno::Reference< css::awt::XGraphics > &xGraphics) override
virtual void SAL_CALL setRange(sal_Int32 nMin, sal_Int32 nMax) override
css::uno::Reference< css::awt::XFixedText > m_xTopic_Bottom
css::uno::Reference< css::awt::XButton > m_xButton
virtual void SAL_CALL setActionCommand(const OUString &sCommand) override
css::uno::Reference< css::awt::XFixedText > m_xText_Top
virtual void SAL_CALL setLabel(const OUString &sLabel) override
IMPL_TextlistItem * impl_searchTopic(std::u16string_view sTopic, bool bbeforeProgress)
virtual void SAL_CALL setValue(sal_Int32 nValue) override
static bool impl_debug_checkParameter(std::u16string_view sTopic, std::u16string_view sText)
rtl::Reference< ProgressBar > m_xProgressBar
virtual void SAL_CALL updateText(const OUString &sTopic, const OUString &sText, sal_Bool bbeforeProgress) override
virtual void SAL_CALL acquire() noexcept override
increment refcount @seealso XInterface @seealso release() @onerror A RuntimeException is thrown.
int nCount
#define DBG_ASSERT(sCon, aError)
ULONG m_refCount
float u
sal_Int16 nValue
void * p
Type
constexpr OUStringLiteral PROGRESSMONITOR_DEFAULT_TEXT
constexpr OUStringLiteral PROGRESSMONITOR_DEFAULT_TOPIC
constexpr OUStringLiteral FIXEDTEXT_SERVICENAME
constexpr OUStringLiteral CONTROLNAME_PROGRESSBAR
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stardiv_UnoControls_ProgressMonitor_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral FIXEDTEXT_MODELNAME
constexpr OUStringLiteral BUTTON_SERVICENAME
constexpr OUStringLiteral DEFAULT_BUTTONLABEL
constexpr OUStringLiteral CONTROLNAME_TEXT
constexpr OUStringLiteral CONTROLNAME_BUTTON
constexpr OUStringLiteral BUTTON_MODELNAME
#define PROGRESSMONITOR_DEFAULT_HEIGHT
#define PROGRESSMONITOR_DEFAULT_WIDTH
#define PROGRESSMONITOR_LINECOLOR_SHADOW
#define PROGRESSMONITOR_FREEBORDER
#define PROGRESSMONITOR_LINECOLOR_BRIGHT
OUString sText
Left site of textline in dialog.
unsigned char sal_Bool