Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/UnoControls/source/controls/progressmonitor.cxx
Line
Count
Source
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>
26
#include <cppuhelper/typeprovider.hxx>
27
#include <cppuhelper/queryinterface.hxx>
28
#include <rtl/ustrbuf.hxx>
29
#include <tools/debug.hxx>
30
#include <algorithm>
31
32
#include <progressbar.hxx>
33
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;
39
40
using ::std::vector;
41
42
constexpr OUString CONTROLNAME_TEXT = u"Text"_ustr;   // identifier the control in container
43
constexpr OUString CONTROLNAME_PROGRESSBAR = u"ProgressBar"_ustr;
44
constexpr OUString CONTROLNAME_BUTTON = u"Button"_ustr;
45
constexpr OUString DEFAULT_BUTTONLABEL = u"Abbrechen"_ustr;
46
47
namespace unocontrols {
48
49
ProgressMonitor::ProgressMonitor( const css::uno::Reference< XComponentContext >& rxContext )
50
0
    : ProgressMonitor_BASE(rxContext)
51
0
{
52
    // It's not allowed to work with member in this method (refcounter !!!)
53
    // But with a HACK (++refcount) its "OK" :-(
54
0
    osl_atomic_increment(&m_refCount);
55
56
    // Create instances for fixedtext, button and progress ...
57
58
0
    m_xTopic_Top = new UnoFixedTextControl();
59
0
    m_xText_Top = new UnoFixedTextControl();
60
0
    m_xTopic_Bottom = new UnoFixedTextControl();
61
0
    m_xText_Bottom = new UnoFixedTextControl();
62
0
    m_xButton = new UnoButtonControl();
63
0
    m_xProgressBar = new ProgressBar(rxContext);
64
65
    // ... set models ...
66
0
    m_xTopic_Top->setModel    ( new UnoControlFixedTextModel(rxContext) );
67
0
    m_xText_Top->setModel     ( new UnoControlFixedTextModel(rxContext) );
68
0
    m_xTopic_Bottom->setModel ( new UnoControlFixedTextModel(rxContext) );
69
0
    m_xText_Bottom->setModel  (  new UnoControlFixedTextModel(rxContext) );
70
0
    m_xButton->setModel       ( new UnoControlButtonModel(rxContext) );
71
    // ProgressBar has no model !!!
72
73
    // ... and add controls to basecontainercontrol!
74
0
    addControl ( CONTROLNAME_TEXT, m_xTopic_Top           );
75
0
    addControl ( CONTROLNAME_TEXT, m_xText_Top            );
76
0
    addControl ( CONTROLNAME_TEXT, m_xTopic_Bottom        );
77
0
    addControl ( CONTROLNAME_TEXT, m_xText_Bottom         );
78
0
    addControl ( CONTROLNAME_BUTTON, m_xButton            );
79
0
    addControl ( CONTROLNAME_PROGRESSBAR, m_xProgressBar );
80
81
    // FixedText make it automatically visible by himself ... but not the progressbar !!!
82
    // it must be set explicitly
83
0
    m_xProgressBar->setVisible( true );
84
85
    // Reset to defaults !!!
86
    // (progressbar take automatically its own defaults)
87
0
    m_xButton->setLabel      ( DEFAULT_BUTTONLABEL );
88
0
    m_xTopic_Top->setText    ( PROGRESSMONITOR_DEFAULT_TOPIC );
89
0
    m_xText_Top->setText     ( PROGRESSMONITOR_DEFAULT_TEXT );
90
0
    m_xTopic_Bottom->setText ( PROGRESSMONITOR_DEFAULT_TOPIC );
91
0
    m_xText_Bottom->setText  ( PROGRESSMONITOR_DEFAULT_TEXT );
92
93
0
    osl_atomic_decrement(&m_refCount);
94
0
}
95
96
ProgressMonitor::~ProgressMonitor()
97
0
{
98
0
    impl_cleanMemory ();
99
0
}
100
101
//  XProgressMonitor
102
void SAL_CALL ProgressMonitor::addText(
103
    const OUString& rTopic,
104
    const OUString& rText,
105
    sal_Bool bbeforeProgress
106
)
107
0
{
108
    // Ready for multithreading
109
0
    MutexGuard aGuard ( m_aMutex );
110
111
    // Safe impossible cases
112
    // Check valid call of this method.
113
0
    DBG_ASSERT ( impl_debug_checkParameter ( rTopic, rText ),                 "ProgressMonitor::addText()\nCall without valid parameters!\n");
114
0
    DBG_ASSERT ( !(impl_searchTopic ( rTopic, bbeforeProgress ) != nullptr ), "ProgressMonitor::addText()\nThe text already exist.\n"        );
115
116
    // Do nothing (in Release), if topic already exist.
117
0
    if ( impl_searchTopic ( rTopic, bbeforeProgress ) != nullptr )
118
0
    {
119
0
        return;
120
0
    }
121
122
    // Else ... take memory for new item ...
123
0
    IMPL_TextlistItem aTextItem;
124
125
    // Set values ...
126
0
    aTextItem.sTopic   = rTopic;
127
0
    aTextItem.sText    = rText;
128
129
    // ... and insert it in right list.
130
0
    if ( bbeforeProgress )
131
0
    {
132
0
        maTextlist_Top.push_back( aTextItem );
133
0
    }
134
0
    else
135
0
    {
136
0
        maTextlist_Bottom.push_back( aTextItem );
137
0
    }
138
139
    // ... update window
140
0
    impl_rebuildFixedText   ();
141
0
    impl_recalcLayout       ();
142
0
}
143
144
//  XProgressMonitor
145
void SAL_CALL ProgressMonitor::removeText ( const OUString& rTopic, sal_Bool bbeforeProgress )
146
0
{
147
    // Safe impossible cases
148
    // Check valid call of this method.
149
0
    DBG_ASSERT ( impl_debug_checkParameter ( rTopic ), "ProgressMonitor::removeText()\nCall without valid parameters!" );
150
151
    // Ready for multithreading
152
0
    MutexGuard aGuard ( m_aMutex );
153
154
    // Search the topic ...
155
0
    IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress );
156
157
0
    if ( pSearchItem == nullptr )
158
0
        return;
159
160
    // ... delete item from right list ...
161
0
    if ( bbeforeProgress )
162
0
    {
163
0
        auto itr = std::find_if( maTextlist_Top.begin(), maTextlist_Top.end(),
164
0
                        [&] (IMPL_TextlistItem const &p)
165
0
                        { return &p == pSearchItem; } );
166
0
        if (itr != maTextlist_Top.end())
167
0
            maTextlist_Top.erase(itr);
168
0
    }
169
0
    else
170
0
    {
171
0
        auto itr = std::find_if( maTextlist_Bottom.begin(), maTextlist_Bottom.end(),
172
0
                        [&] (IMPL_TextlistItem const &p)
173
0
                        { return &p == pSearchItem; } );
174
0
        if (itr != maTextlist_Bottom.end())
175
0
            maTextlist_Bottom.erase(itr);
176
0
    }
177
178
    // ... and update window.
179
0
    impl_rebuildFixedText   ();
180
0
    impl_recalcLayout       ();
181
0
}
182
183
//  XProgressMonitor
184
void SAL_CALL ProgressMonitor::updateText (
185
    const OUString& rTopic,
186
    const OUString& rText,
187
    sal_Bool bbeforeProgress
188
)
189
0
{
190
    // Safe impossible cases
191
    // Check valid call of this method.
192
0
    DBG_ASSERT ( impl_debug_checkParameter ( rTopic, rText ), "ProgressMonitor::updateText()\nCall without valid parameters!\n" );
193
194
    // Ready for multithreading
195
0
    MutexGuard aGuard ( m_aMutex );
196
197
    // Search topic ...
198
0
    IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress );
199
200
0
    if ( pSearchItem != nullptr )
201
0
    {
202
        // ... update text ...
203
0
        pSearchItem->sText = rText;
204
205
        // ... and update window.
206
0
        impl_rebuildFixedText   ();
207
0
        impl_recalcLayout       ();
208
0
    }
209
0
}
210
211
//  XProgressBar
212
void SAL_CALL ProgressMonitor::setForegroundColor ( sal_Int32 nColor )
213
0
{
214
    // Ready for multithreading
215
0
    MutexGuard aGuard ( m_aMutex );
216
217
0
    m_xProgressBar->setForegroundColor ( nColor );
218
0
}
219
220
//  XProgressBar
221
void SAL_CALL ProgressMonitor::setBackgroundColor ( sal_Int32 nColor )
222
0
{
223
    // Ready for multithreading
224
0
    MutexGuard aGuard ( m_aMutex );
225
226
0
    m_xProgressBar->setBackgroundColor ( nColor );
227
0
}
228
229
//  XProgressBar
230
void SAL_CALL ProgressMonitor::setValue ( sal_Int32 nValue )
231
0
{
232
    // Ready for multithreading
233
0
    MutexGuard aGuard ( m_aMutex );
234
235
0
    m_xProgressBar->setValue ( nValue );
236
0
}
237
238
//  XProgressBar
239
void SAL_CALL ProgressMonitor::setRange ( sal_Int32 nMin, sal_Int32 nMax )
240
0
{
241
    // Ready for multithreading
242
0
    MutexGuard aGuard ( m_aMutex );
243
244
0
    m_xProgressBar->setRange ( nMin, nMax );
245
0
}
246
247
//  XProgressBar
248
sal_Int32 SAL_CALL ProgressMonitor::getValue ()
249
0
{
250
    // Ready for multithreading
251
0
    MutexGuard aGuard ( m_aMutex );
252
253
0
    return m_xProgressBar->getValue ();
254
0
}
255
256
//  XButton
257
void SAL_CALL ProgressMonitor::addActionListener ( const css::uno::Reference< XActionListener > & rListener )
258
0
{
259
    // Ready for multithreading
260
0
    MutexGuard aGuard ( m_aMutex );
261
262
0
    if ( m_xButton.is () )
263
0
    {
264
0
        m_xButton->addActionListener ( rListener );
265
0
    }
266
0
}
267
268
//  XButton
269
void SAL_CALL ProgressMonitor::removeActionListener ( const css::uno::Reference< XActionListener > & rListener )
270
0
{
271
    // Ready for multithreading
272
0
    MutexGuard aGuard ( m_aMutex );
273
274
0
    if ( m_xButton.is () )
275
0
    {
276
0
        m_xButton->removeActionListener ( rListener );
277
0
    }
278
0
}
279
280
//  XButton
281
void SAL_CALL ProgressMonitor::setLabel ( const OUString& rLabel )
282
0
{
283
    // Ready for multithreading
284
0
    MutexGuard aGuard ( m_aMutex );
285
286
0
    if ( m_xButton.is () )
287
0
    {
288
0
        m_xButton->setLabel ( rLabel );
289
0
    }
290
0
}
291
292
//  XButton
293
void SAL_CALL ProgressMonitor::setActionCommand ( const OUString& rCommand )
294
0
{
295
    // Ready for multithreading
296
0
    MutexGuard aGuard ( m_aMutex );
297
298
0
    if ( m_xButton.is () )
299
0
    {
300
0
        m_xButton->setActionCommand ( rCommand );
301
0
    }
302
0
}
303
304
//  XLayoutConstrains
305
css::awt::Size SAL_CALL ProgressMonitor::getMinimumSize ()
306
0
{
307
0
    return css::awt::Size (PROGRESSMONITOR_DEFAULT_WIDTH, PROGRESSMONITOR_DEFAULT_HEIGHT);
308
0
}
309
310
//  XLayoutConstrains
311
css::awt::Size SAL_CALL ProgressMonitor::getPreferredSize ()
312
0
{
313
    // Ready for multithreading
314
0
    ClearableMutexGuard aGuard ( m_aMutex );
315
316
    // get information about required place of child controls
317
318
0
    css::awt::Size        aTopicSize_Top      =   m_xTopic_Top->getPreferredSize          ();
319
0
    css::awt::Size        aTopicSize_Bottom   =   m_xTopic_Bottom->getPreferredSize       ();
320
0
    css::awt::Size        aButtonSize         =   m_xButton->getPreferredSize             ();
321
0
    Rectangle   aTempRectangle      = m_xProgressBar->getPosSize();
322
0
    css::awt::Size        aProgressBarSize( aTempRectangle.Width, aTempRectangle.Height );
323
324
0
    aGuard.clear ();
325
326
    // calc preferred size of progressmonitor
327
0
    sal_Int32 nWidth   =  3 * PROGRESSMONITOR_FREEBORDER;
328
0
    nWidth  +=  aProgressBarSize.Width;
329
330
0
    sal_Int32 nHeight  =  6 * PROGRESSMONITOR_FREEBORDER;
331
0
    nHeight +=  aTopicSize_Top.Height;
332
0
    nHeight +=  aProgressBarSize.Height;
333
0
    nHeight +=  aTopicSize_Bottom.Height;
334
0
    nHeight +=  2;   // 1 for black line, 1 for white line = 3D-Line!
335
0
    nHeight +=  aButtonSize.Height;
336
337
    // norm to minimum
338
0
    if ( nWidth < PROGRESSMONITOR_DEFAULT_WIDTH )
339
0
    {
340
0
        nWidth = PROGRESSMONITOR_DEFAULT_WIDTH;
341
0
    }
342
0
    if ( nHeight < PROGRESSMONITOR_DEFAULT_HEIGHT )
343
0
    {
344
0
        nHeight = PROGRESSMONITOR_DEFAULT_HEIGHT;
345
0
    }
346
347
    // return to caller
348
0
    return css::awt::Size ( nWidth, nHeight );
349
0
}
350
351
//  XLayoutConstrains
352
css::awt::Size SAL_CALL ProgressMonitor::calcAdjustedSize ( const css::awt::Size& /*rNewSize*/ )
353
0
{
354
0
    return getPreferredSize ();
355
0
}
356
357
//  XControl
358
void SAL_CALL ProgressMonitor::createPeer ( const css::uno::Reference< XToolkit > & rToolkit, const css::uno::Reference< XWindowPeer > & rParent    )
359
0
{
360
0
    if (!getPeer().is())
361
0
    {
362
0
        BaseContainerControl::createPeer ( rToolkit, rParent );
363
364
        // If user forget to call "setPosSize()", we have still a correct size.
365
        // And a "MinimumSize" IS A "MinimumSize"!
366
        // We change not the position of control at this point.
367
0
        css::awt::Size aDefaultSize = getMinimumSize ();
368
0
        setPosSize ( 0, 0, aDefaultSize.Width, aDefaultSize.Height, PosSize::SIZE );
369
0
    }
370
0
}
371
372
//  XControl
373
sal_Bool SAL_CALL ProgressMonitor::setModel ( const css::uno::Reference< XControlModel > & /*rModel*/ )
374
0
{
375
    // We have no model.
376
0
    return false;
377
0
}
378
379
//  XControl
380
css::uno::Reference< XControlModel > SAL_CALL ProgressMonitor::getModel ()
381
0
{
382
    // We have no model.
383
    // return (XControlModel*)this;
384
0
    return css::uno::Reference< XControlModel >  ();
385
0
}
386
387
//  XComponent
388
void SAL_CALL ProgressMonitor::dispose ()
389
0
{
390
    // Ready for multithreading
391
0
    MutexGuard aGuard ( m_aMutex );
392
393
    // "removeControl()" control the state of a reference
394
395
0
    removeControl ( m_xTopic_Top      );
396
0
    removeControl ( m_xText_Top       );
397
0
    removeControl ( m_xTopic_Bottom   );
398
0
    removeControl ( m_xText_Bottom    );
399
0
    removeControl ( m_xButton         );
400
0
    removeControl ( m_xProgressBar );
401
402
    // don't use "...->clear ()" or "... = XFixedText ()"
403
    // when other hold a reference at this object !!!
404
0
    m_xTopic_Top->dispose     ();
405
0
    m_xText_Top->dispose      ();
406
0
    m_xTopic_Bottom->dispose  ();
407
0
    m_xText_Bottom->dispose   ();
408
0
    m_xButton->dispose        ();
409
0
    m_xProgressBar->dispose();
410
411
0
    BaseContainerControl::dispose ();
412
0
}
413
414
//  XWindow
415
void SAL_CALL ProgressMonitor::setPosSize ( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags )
416
0
{
417
0
    Rectangle   aBasePosSize = getPosSize ();
418
0
    BaseContainerControl::setPosSize (nX, nY, nWidth, nHeight, nFlags);
419
420
    // if position or size changed
421
0
    if (
422
0
        ( nWidth  != aBasePosSize.Width ) ||
423
0
        ( nHeight != aBasePosSize.Height)
424
0
       )
425
0
    {
426
        // calc new layout for controls
427
0
        impl_recalcLayout ();
428
        // clear background (!)
429
        // [Children were repainted in "recalcLayout" by setPosSize() automatically!]
430
0
        getPeer()->invalidate(2);
431
        // and repaint the control
432
0
        impl_paint ( 0, 0, impl_getGraphicsPeer() );
433
0
    }
434
0
}
435
436
//  protected method
437
void ProgressMonitor::impl_paint ( sal_Int32 nX, sal_Int32 nY, const css::uno::Reference< XGraphics > & rGraphics )
438
0
{
439
0
    if (!rGraphics.is())
440
0
        return;
441
442
    // Ready for multithreading
443
0
    MutexGuard aGuard ( m_aMutex );
444
445
    // paint shadowed border around the progressmonitor
446
0
    rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW                                                              );
447
0
    rGraphics->drawLine     ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY                  );
448
0
    rGraphics->drawLine     ( impl_getWidth()-1, impl_getHeight()-1, nX               , impl_getHeight()-1  );
449
450
0
    rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT                          );
451
0
    rGraphics->drawLine     ( nX, nY, impl_getWidth(), nY               );
452
0
    rGraphics->drawLine     ( nX, nY, nX             , impl_getHeight() );
453
454
    // Paint 3D-line
455
0
    rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW  );
456
0
    rGraphics->drawLine     ( m_a3DLine.X, m_a3DLine.Y, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y );
457
458
0
    rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT  );
459
0
    rGraphics->drawLine     ( m_a3DLine.X, m_a3DLine.Y+1, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y+1 );
460
0
}
461
462
//  private method
463
void ProgressMonitor::impl_recalcLayout ()
464
0
{
465
0
    sal_Int32   nX_Button;
466
0
    sal_Int32   nY_Button;
467
0
    sal_Int32   nWidth_Button;
468
0
    sal_Int32   nHeight_Button;
469
470
0
    sal_Int32   nX_ProgressBar;
471
0
    sal_Int32   nY_ProgressBar;
472
0
    sal_Int32   nWidth_ProgressBar;
473
0
    sal_Int32   nHeight_ProgressBar;
474
475
0
    sal_Int32   nX_Text_Top;
476
0
    sal_Int32   nY_Text_Top;
477
0
    sal_Int32   nWidth_Text_Top;
478
0
    sal_Int32   nHeight_Text_Top;
479
480
0
    sal_Int32   nX_Topic_Top;
481
0
    sal_Int32   nY_Topic_Top;
482
0
    sal_Int32   nWidth_Topic_Top;
483
0
    sal_Int32   nHeight_Topic_Top;
484
485
0
    sal_Int32   nX_Text_Bottom;
486
0
    sal_Int32   nY_Text_Bottom;
487
0
    sal_Int32   nWidth_Text_Bottom;
488
0
    sal_Int32   nHeight_Text_Bottom;
489
490
0
    sal_Int32   nX_Topic_Bottom;
491
0
    sal_Int32   nY_Topic_Bottom;
492
0
    sal_Int32   nWidth_Topic_Bottom;
493
0
    sal_Int32   nHeight_Topic_Bottom;
494
495
    // Ready for multithreading
496
0
    MutexGuard aGuard ( m_aMutex );
497
498
    // get information about required place of child controls
499
500
0
    css::awt::Size    aTopicSize_Top      =   m_xTopic_Top->getPreferredSize      ();
501
0
    css::awt::Size    aTextSize_Top       =   m_xText_Top->getPreferredSize       ();
502
0
    css::awt::Size    aTopicSize_Bottom   =   m_xTopic_Bottom->getPreferredSize   ();
503
0
    css::awt::Size    aTextSize_Bottom    =   m_xText_Bottom->getPreferredSize    ();
504
0
    css::awt::Size    aButtonSize         =   m_xButton->getPreferredSize         ();
505
506
    // calc position and size of child controls
507
    // Button has preferred size!
508
0
    nWidth_Button           =   aButtonSize.Width;
509
0
    nHeight_Button          =   aButtonSize.Height;
510
511
    // Left column before progressbar has preferred size and fixed position.
512
    // But "Width" is oriented on left column below progressbar to!!! "max(...)"
513
0
    nX_Topic_Top            =   PROGRESSMONITOR_FREEBORDER;
514
0
    nY_Topic_Top            =   PROGRESSMONITOR_FREEBORDER;
515
0
    nWidth_Topic_Top        =   std::max( aTopicSize_Top.Width, aTopicSize_Bottom.Width );
516
0
    nHeight_Topic_Top       =   aTopicSize_Top.Height;
517
518
    // Right column before progressbar has relative position to left column ...
519
    // ... and a size as rest of dialog size!
520
0
    nX_Text_Top             =   nX_Topic_Top+nWidth_Topic_Top+PROGRESSMONITOR_FREEBORDER;
521
0
    nY_Text_Top             =   nY_Topic_Top;
522
0
    nWidth_Text_Top         =   std::max ( aTextSize_Top.Width, aTextSize_Bottom.Width );
523
    // Fix size of this column to minimum!
524
0
    sal_Int32 nSummaryWidth = nWidth_Text_Top+nWidth_Topic_Top+(3*PROGRESSMONITOR_FREEBORDER);
525
0
    if ( nSummaryWidth < PROGRESSMONITOR_DEFAULT_WIDTH )
526
0
        nWidth_Text_Top     =   PROGRESSMONITOR_DEFAULT_WIDTH-nWidth_Topic_Top-(3*PROGRESSMONITOR_FREEBORDER);
527
    // Fix size of column to maximum!
528
0
    if ( nSummaryWidth > impl_getWidth() )
529
0
        nWidth_Text_Top     =   impl_getWidth()-nWidth_Topic_Top-(3*PROGRESSMONITOR_FREEBORDER);
530
0
    nHeight_Text_Top        =   nHeight_Topic_Top;
531
532
    // Position of progressbar is relative to columns before.
533
    // Progressbar.Width  = Dialog.Width !!!
534
    // Progressbar.Height = Button.Height
535
0
    nX_ProgressBar          =   nX_Topic_Top;
536
0
    nY_ProgressBar          =   nY_Topic_Top+nHeight_Topic_Top+PROGRESSMONITOR_FREEBORDER;
537
0
    nWidth_ProgressBar      =   PROGRESSMONITOR_FREEBORDER+nWidth_Topic_Top+nWidth_Text_Top;
538
0
    nHeight_ProgressBar     =   nHeight_Button;
539
540
    // Oriented by left column before progressbar.
541
0
    nX_Topic_Bottom         =   nX_Topic_Top;
542
0
    nY_Topic_Bottom         =   nY_ProgressBar+nHeight_ProgressBar+PROGRESSMONITOR_FREEBORDER;
543
0
    nWidth_Topic_Bottom     =   nWidth_Topic_Top;
544
0
    nHeight_Topic_Bottom    =   aTopicSize_Bottom.Height;
545
546
    // Oriented by right column before progressbar.
547
0
    nX_Text_Bottom          =   nX_Topic_Bottom+nWidth_Topic_Bottom+PROGRESSMONITOR_FREEBORDER;
548
0
    nY_Text_Bottom          =   nY_Topic_Bottom;
549
0
    nWidth_Text_Bottom      =   nWidth_Text_Top;
550
0
    nHeight_Text_Bottom     =   nHeight_Topic_Bottom;
551
552
    // Oriented by progressbar.
553
0
    nX_Button               =   nX_ProgressBar+nWidth_ProgressBar-nWidth_Button;
554
0
    nY_Button               =   nY_Topic_Bottom+nHeight_Topic_Bottom+PROGRESSMONITOR_FREEBORDER;
555
556
    // Calc offsets to center controls
557
0
    sal_Int32   nDx;
558
0
    sal_Int32   nDy;
559
560
0
    nDx =   ( (2*PROGRESSMONITOR_FREEBORDER)+nWidth_ProgressBar                                                             );
561
0
    nDy =   ( (6*PROGRESSMONITOR_FREEBORDER)+nHeight_Topic_Top+nHeight_ProgressBar+nHeight_Topic_Bottom+2+nHeight_Button    );
562
563
    // At this point use original dialog size to center controls!
564
0
    nDx =   (impl_getWidth ()/2)-(nDx/2);
565
0
    nDy =   (impl_getHeight()/2)-(nDy/2);
566
567
0
    if ( nDx<0 )
568
0
    {
569
0
        nDx=0;
570
0
    }
571
0
    if ( nDy<0 )
572
0
    {
573
0
        nDy=0;
574
0
    }
575
576
    // Set new position and size on all controls
577
578
0
    m_xTopic_Top->setPosSize    ( nDx+nX_Topic_Top    , nDy+nY_Topic_Top    , nWidth_Topic_Top    , nHeight_Topic_Top    , PosSize::POSSIZE );
579
0
    m_xText_Top->setPosSize     ( nDx+nX_Text_Top     , nDy+nY_Text_Top     , nWidth_Text_Top     , nHeight_Text_Top     , PosSize::POSSIZE );
580
0
    m_xTopic_Bottom->setPosSize ( nDx+nX_Topic_Bottom , nDy+nY_Topic_Bottom , nWidth_Topic_Bottom , nHeight_Topic_Bottom , PosSize::POSSIZE );
581
0
    m_xText_Bottom->setPosSize  ( nDx+nX_Text_Bottom  , nDy+nY_Text_Bottom  , nWidth_Text_Bottom  , nHeight_Text_Bottom  , PosSize::POSSIZE );
582
0
    m_xButton->setPosSize       ( nDx+nX_Button       , nDy+nY_Button       , nWidth_Button       , nHeight_Button       , PosSize::POSSIZE );
583
0
    m_xProgressBar->setPosSize    ( nDx+nX_ProgressBar  , nDy+nY_ProgressBar  , nWidth_ProgressBar  , nHeight_ProgressBar  , PosSize::POSSIZE );
584
585
0
    m_a3DLine.X      = nDx+nX_Topic_Top;
586
0
    m_a3DLine.Y      = nDy+nY_Topic_Bottom+nHeight_Topic_Bottom+(PROGRESSMONITOR_FREEBORDER/2);
587
0
    m_a3DLine.Width  = nWidth_ProgressBar;
588
0
    m_a3DLine.Height = nHeight_ProgressBar;
589
590
    // All childcontrols make an implicit repaint in setPosSize()!
591
    // Make it also for this 3D-line ...
592
0
    css::uno::Reference< XGraphics >  xGraphics = impl_getGraphicsPeer ();
593
594
0
    xGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW  );
595
0
    xGraphics->drawLine     ( m_a3DLine.X, m_a3DLine.Y, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y );
596
597
0
    xGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT  );
598
0
    xGraphics->drawLine     ( m_a3DLine.X, m_a3DLine.Y+1, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y+1 );
599
0
}
600
601
//  private method
602
void ProgressMonitor::impl_rebuildFixedText ()
603
0
{
604
    // Ready for multithreading
605
0
    MutexGuard aGuard ( m_aMutex );
606
607
    // Rebuild fixedtext before progress
608
609
    // Rebuild left site of text
610
0
    if (m_xTopic_Top.is())
611
0
    {
612
0
        OUStringBuffer aCollectString;
613
614
        // Collect all topics from list and format text.
615
        // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
616
0
        for (auto const & rSearchItem : maTextlist_Top)
617
0
        {
618
0
            aCollectString.append(rSearchItem.sTopic + "\n");
619
0
        }
620
621
0
        m_xTopic_Top->setText ( aCollectString.makeStringAndClear() );
622
0
    }
623
624
    // Rebuild right site of text
625
0
    if (m_xText_Top.is())
626
0
    {
627
0
        OUStringBuffer aCollectString;
628
629
        // Collect all topics from list and format text.
630
        // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
631
0
        for (auto const & rSearchItem : maTextlist_Top)
632
0
        {
633
0
            aCollectString.append(rSearchItem.sText + "\n");
634
0
        }
635
636
0
        m_xText_Top->setText ( aCollectString.makeStringAndClear() );
637
0
    }
638
639
    // Rebuild fixedtext below progress
640
641
    // Rebuild left site of text
642
0
    if (m_xTopic_Bottom.is())
643
0
    {
644
0
        OUStringBuffer aCollectString;
645
646
        // Collect all topics from list and format text.
647
        // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
648
0
        for (auto const & rSearchItem : maTextlist_Bottom)
649
0
        {
650
0
            aCollectString.append(rSearchItem.sTopic + "\n");
651
0
        }
652
653
0
        m_xTopic_Bottom->setText ( aCollectString.makeStringAndClear() );
654
0
    }
655
656
    // Rebuild right site of text
657
0
    if (!m_xText_Bottom.is())
658
0
        return;
659
660
0
    OUStringBuffer aCollectString;
661
662
    // Collect all topics from list and format text.
663
    // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
664
0
    for (auto const & rSearchItem : maTextlist_Bottom)
665
0
    {
666
0
        aCollectString.append(rSearchItem.sText + "\n");
667
0
    }
668
669
0
    m_xText_Bottom->setText ( aCollectString.makeStringAndClear() );
670
0
}
671
672
//  private method
673
void ProgressMonitor::impl_cleanMemory ()
674
0
{
675
    // Ready for multithreading
676
0
    MutexGuard aGuard ( m_aMutex );
677
678
    // Delete all of lists.
679
0
    maTextlist_Top.clear();
680
0
    maTextlist_Bottom.clear();
681
0
}
682
683
//  private method
684
IMPL_TextlistItem* ProgressMonitor::impl_searchTopic ( std::u16string_view rTopic, bool bbeforeProgress )
685
0
{
686
    // Get right textlist for following operations.
687
0
    ::std::vector< IMPL_TextlistItem >* pTextList;
688
689
0
    if (bbeforeProgress)
690
0
    {
691
0
        pTextList = &maTextlist_Top;
692
0
    }
693
0
    else
694
0
    {
695
0
        pTextList = &maTextlist_Bottom;
696
0
    }
697
698
    // Search the topic in textlist.
699
0
    size_t nPosition    = 0;
700
0
    size_t nCount       = pTextList->size();
701
702
0
    for ( nPosition = 0; nPosition < nCount; ++nPosition )
703
0
    {
704
0
        auto& rSearchItem = pTextList->at( nPosition );
705
706
0
        if ( rSearchItem.sTopic == rTopic )
707
0
        {
708
            // We have found this topic... return a valid pointer.
709
0
            return &rSearchItem;
710
0
        }
711
0
    }
712
713
    // We haven't found this topic... return a nonvalid pointer.
714
0
    return nullptr;
715
0
}
716
717
//  debug methods
718
719
// addText, updateText
720
bool ProgressMonitor::impl_debug_checkParameter (
721
    std::u16string_view rTopic,
722
    std::u16string_view rText
723
0
) {
724
0
    if ( rTopic.empty()       ) return false;    // ""
725
726
0
    if ( rText.empty()       ) return false;    // ""
727
728
    // Parameter OK ... return true.
729
0
    return true;
730
0
}
731
732
// removeText
733
bool ProgressMonitor::impl_debug_checkParameter ( std::u16string_view rTopic )
734
0
{
735
0
    if ( rTopic.empty()      ) return false;    // ""
736
737
    // Parameter OK ... return true.
738
0
    return true;
739
0
}
740
741
}   // namespace unocontrols
742
743
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
744
stardiv_UnoControls_ProgressMonitor_get_implementation(
745
    css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
746
0
{
747
0
    return cppu::acquire(new unocontrols::ProgressMonitor(context));
748
0
}
749
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */