Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/framework/source/uiconfiguration/windowstateconfiguration.cxx
Line
Count
Source (jump to first uncovered line)
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 <uiconfiguration/windowstateproperties.hxx>
21
#include <helper/mischelper.hxx>
22
23
#include <com/sun/star/beans/PropertyValue.hpp>
24
#include <com/sun/star/beans/XPropertySet.hpp>
25
#include <com/sun/star/configuration/theDefaultProvider.hpp>
26
#include <com/sun/star/container/XNameAccess.hpp>
27
#include <com/sun/star/container/XNameContainer.hpp>
28
#include <com/sun/star/container/XContainer.hpp>
29
#include <com/sun/star/lang/XServiceInfo.hpp>
30
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
31
#include <com/sun/star/frame/ModuleManager.hpp>
32
#include <com/sun/star/frame/XModuleManager2.hpp>
33
#include <com/sun/star/awt/Point.hpp>
34
#include <com/sun/star/awt/Size.hpp>
35
#include <com/sun/star/ui/DockingArea.hpp>
36
#include <com/sun/star/util/XChangesBatch.hpp>
37
#include <com/sun/star/uno/XComponentContext.hpp>
38
39
#include <comphelper/compbase.hxx>
40
#include <comphelper/string.hxx>
41
#include <cppuhelper/implbase.hxx>
42
#include <cppuhelper/supportsservice.hxx>
43
#include <comphelper/propertysequence.hxx>
44
#include <comphelper/sequence.hxx>
45
#include <rtl/ref.hxx>
46
#include <sal/log.hxx>
47
#include <o3tl/string_view.hxx>
48
49
#include <mutex>
50
#include <string_view>
51
#include <unordered_map>
52
#include <vector>
53
54
using namespace com::sun::star::uno;
55
using namespace com::sun::star::lang;
56
using namespace com::sun::star::beans;
57
using namespace com::sun::star::util;
58
using namespace com::sun::star::configuration;
59
using namespace com::sun::star::container;
60
using namespace ::com::sun::star::frame;
61
using namespace ::com::sun::star::ui;
62
using namespace framework;
63
64
namespace {
65
66
// Zero based indexes, order must be the same as WindowStateMask && CONFIGURATION_PROPERTIES!
67
const sal_Int16 PROPERTY_LOCKED                  = 0;
68
const sal_Int16 PROPERTY_DOCKED                  = 1;
69
const sal_Int16 PROPERTY_VISIBLE                 = 2;
70
const sal_Int16 PROPERTY_CONTEXT                 = 3;
71
const sal_Int16 PROPERTY_HIDEFROMMENU            = 4;
72
const sal_Int16 PROPERTY_NOCLOSE                 = 5;
73
const sal_Int16 PROPERTY_SOFTCLOSE               = 6;
74
const sal_Int16 PROPERTY_CONTEXTACTIVE           = 7;
75
const sal_Int16 PROPERTY_DOCKINGAREA             = 8;
76
const sal_Int16 PROPERTY_POS                     = 9;
77
const sal_Int16 PROPERTY_SIZE                    = 10;
78
const sal_Int16 PROPERTY_UINAME                  = 11;
79
const sal_Int16 PROPERTY_INTERNALSTATE           = 12;
80
const sal_Int16 PROPERTY_STYLE                   = 13;
81
const sal_Int16 PROPERTY_DOCKPOS                 = 14;
82
const sal_Int16 PROPERTY_DOCKSIZE                = 15;
83
84
// Order must be the same as WindowStateMask!!
85
constexpr OUString CONFIGURATION_PROPERTIES[]
86
{
87
    WINDOWSTATE_PROPERTY_LOCKED,
88
    WINDOWSTATE_PROPERTY_DOCKED,
89
    WINDOWSTATE_PROPERTY_VISIBLE,
90
    WINDOWSTATE_PROPERTY_CONTEXT,
91
    WINDOWSTATE_PROPERTY_HIDEFROMENU,
92
    WINDOWSTATE_PROPERTY_NOCLOSE,
93
    WINDOWSTATE_PROPERTY_SOFTCLOSE,
94
    WINDOWSTATE_PROPERTY_CONTEXTACTIVE,
95
    WINDOWSTATE_PROPERTY_DOCKINGAREA,
96
    WINDOWSTATE_PROPERTY_POS,
97
    WINDOWSTATE_PROPERTY_SIZE,
98
    WINDOWSTATE_PROPERTY_UINAME,
99
    WINDOWSTATE_PROPERTY_INTERNALSTATE,
100
    WINDOWSTATE_PROPERTY_STYLE,
101
    WINDOWSTATE_PROPERTY_DOCKPOS,
102
    WINDOWSTATE_PROPERTY_DOCKSIZE
103
};
104
105
//  Configuration access class for WindowState supplier implementation
106
107
class ConfigurationAccess_WindowState : public  ::cppu::WeakImplHelper< XNameContainer, XContainerListener >
108
{
109
    public:
110
                                  ConfigurationAccess_WindowState( std::u16string_view aWindowStateConfigFile, const Reference< XComponentContext >& rxContext );
111
        virtual                   ~ConfigurationAccess_WindowState() override;
112
113
        // XNameAccess
114
        virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
115
116
        virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
117
118
        virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
119
120
        // XNameContainer
121
        virtual void SAL_CALL removeByName( const OUString& sName ) override;
122
123
        virtual void SAL_CALL insertByName( const OUString& sName, const css::uno::Any&   aPropertySet ) override;
124
125
        // XNameReplace
126
        virtual void SAL_CALL replaceByName( const OUString& sName, const css::uno::Any& aPropertySet ) override;
127
128
        // XElementAccess
129
        virtual css::uno::Type SAL_CALL getElementType() override;
130
131
        virtual sal_Bool SAL_CALL hasElements() override;
132
133
        // container.XContainerListener
134
        virtual void SAL_CALL     elementInserted( const ContainerEvent& aEvent ) override;
135
        virtual void SAL_CALL     elementRemoved ( const ContainerEvent& aEvent ) override;
136
        virtual void SAL_CALL     elementReplaced( const ContainerEvent& aEvent ) override;
137
138
        // lang.XEventListener
139
        virtual void SAL_CALL disposing( const EventObject& aEvent ) override;
140
141
    protected:
142
        enum // WindowStateMask
143
        {
144
            WINDOWSTATE_MASK_DOCKINGAREA    = 256,
145
            WINDOWSTATE_MASK_POS            = 512,
146
            WINDOWSTATE_MASK_SIZE           = 1024,
147
            WINDOWSTATE_MASK_UINAME         = 2048,
148
            WINDOWSTATE_MASK_INTERNALSTATE  = 4096,
149
            WINDOWSTATE_MASK_STYLE          = 8192,
150
            WINDOWSTATE_MASK_DOCKPOS        = 16384,
151
            WINDOWSTATE_MASK_DOCKSIZE       = 32768
152
        };
153
154
        // Cache structure. Valid values are described by the eMask member. All other values should not be
155
        // provided to outside code!
156
        struct WindowStateInfo
157
        {
158
            WindowStateInfo()
159
0
                : bLocked(false)
160
0
                , bDocked(false)
161
0
                , bVisible(false)
162
0
                , bContext(false)
163
0
                , bHideFromMenu(false)
164
0
                , bNoClose(false)
165
0
                , bSoftClose(false)
166
0
                , bContextActive(false)
167
0
                , aDockingArea(css::ui::DockingArea_DOCKINGAREA_TOP)
168
0
                , aDockPos(0, 0)
169
0
                , aPos(0, 0)
170
0
                , aSize(0, 0)
171
0
                , nInternalState(0)
172
0
                , nStyle(0)
173
0
                , nMask(0)
174
0
            {
175
0
            }
176
177
            bool                                    bLocked : 1,
178
                                                    bDocked : 1,
179
                                                    bVisible : 1,
180
                                                    bContext : 1,
181
                                                    bHideFromMenu : 1,
182
                                                    bNoClose : 1,
183
                                                    bSoftClose : 1,
184
                                                    bContextActive : 1;
185
            css::ui::DockingArea                    aDockingArea;
186
            css::awt::Point                         aDockPos;
187
            css::awt::Size                          aDockSize;
188
            css::awt::Point                         aPos;
189
            css::awt::Size                          aSize;
190
            OUString                                aUIName;
191
            sal_uInt32                              nInternalState;
192
            sal_uInt16                              nStyle;
193
            sal_uInt32                              nMask; // see WindowStateMask
194
        };
195
196
        void                      impl_putPropertiesFromStruct( const WindowStateInfo& rWinStateInfo, Reference< XPropertySet > const & xPropSet );
197
        Any                       impl_insertCacheAndReturnSequence( const OUString& rResourceURL, Reference< XNameAccess > const & rNameAccess );
198
        WindowStateInfo&          impl_insertCacheAndReturnWinState( const OUString& rResourceURL, Reference< XNameAccess > const & rNameAccess );
199
        Any                       impl_getSequenceFromStruct( const WindowStateInfo& rWinStateInfo );
200
        void                      impl_fillStructFromSequence( WindowStateInfo& rWinStateInfo, const Sequence< PropertyValue >& rSeq );
201
        Any                       impl_getWindowStateFromResourceURL( const OUString& rResourceURL );
202
        void                      impl_initializeConfigAccess();
203
204
    private:
205
        typedef std::unordered_map< OUString,
206
                                    WindowStateInfo > ResourceURLToInfoCache;
207
208
        std::mutex                        m_aMutex;
209
        OUString                          m_aConfigWindowAccess;
210
        Reference< XMultiServiceFactory > m_xConfigProvider;
211
        Reference< XNameAccess >          m_xConfigAccess;
212
        rtl::Reference< WeakContainerListener >   m_xConfigListener;
213
        ResourceURLToInfoCache            m_aResourceURLToInfoCache;
214
        bool                              m_bConfigAccessInitialized : 1,
215
                                          m_bModified : 1;
216
        std::vector< OUString >           m_aPropArray;
217
};
218
219
ConfigurationAccess_WindowState::ConfigurationAccess_WindowState( std::u16string_view aModuleName, const Reference< XComponentContext >& rxContext ) :
220
    // Create configuration hierarchical access name
221
0
    m_aConfigWindowAccess(
222
0
        OUString::Concat("/org.openoffice.Office.UI.") + aModuleName + "/UIElements/States"),
223
0
    m_xConfigProvider(theDefaultProvider::get( rxContext )),
224
0
    m_bConfigAccessInitialized( false ),
225
0
    m_bModified( false )
226
0
{
227
    // Initialize access array with property names.
228
0
    for (const OUString & s : CONFIGURATION_PROPERTIES )
229
0
        m_aPropArray.push_back(s);
230
0
}
231
232
ConfigurationAccess_WindowState::~ConfigurationAccess_WindowState()
233
0
{
234
    // SAFE
235
0
    std::unique_lock g(m_aMutex);
236
0
    Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
237
0
    if ( xContainer.is() )
238
0
        xContainer->removeContainerListener(m_xConfigListener);
239
0
}
240
241
// XNameAccess
242
Any SAL_CALL ConfigurationAccess_WindowState::getByName( const OUString& rResourceURL )
243
0
{
244
    // SAFE
245
0
    std::unique_lock g(m_aMutex);
246
247
0
    ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
248
0
    if ( pIter != m_aResourceURLToInfoCache.end() )
249
0
        return impl_getSequenceFromStruct( pIter->second );
250
0
    else
251
0
    {
252
0
        Any a( impl_getWindowStateFromResourceURL( rResourceURL ) );
253
0
        if ( a == Any() )
254
0
            throw NoSuchElementException();
255
0
        return a;
256
0
    }
257
0
}
258
259
Sequence< OUString > SAL_CALL ConfigurationAccess_WindowState::getElementNames()
260
0
{
261
    // SAFE
262
0
    std::unique_lock g(m_aMutex);
263
264
0
    if ( !m_bConfigAccessInitialized )
265
0
    {
266
0
        impl_initializeConfigAccess();
267
0
        m_bConfigAccessInitialized = true;
268
0
    }
269
270
0
    if ( m_xConfigAccess.is() )
271
0
        return m_xConfigAccess->getElementNames();
272
0
    else
273
0
        return Sequence< OUString > ();
274
0
}
275
276
sal_Bool SAL_CALL ConfigurationAccess_WindowState::hasByName( const OUString& rResourceURL )
277
0
{
278
    // SAFE
279
0
    std::unique_lock g(m_aMutex);
280
281
0
    ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
282
0
    if ( pIter != m_aResourceURLToInfoCache.end() )
283
0
        return true;
284
0
    else
285
0
    {
286
0
        Any a( impl_getWindowStateFromResourceURL( rResourceURL ) );
287
0
        if ( a == Any() )
288
0
            return false;
289
0
        else
290
0
            return true;
291
0
    }
292
0
}
293
294
// XElementAccess
295
Type SAL_CALL ConfigurationAccess_WindowState::getElementType()
296
0
{
297
0
    return cppu::UnoType<Sequence< PropertyValue >>::get();
298
0
}
299
300
sal_Bool SAL_CALL ConfigurationAccess_WindowState::hasElements()
301
0
{
302
    // SAFE
303
0
    std::unique_lock g(m_aMutex);
304
305
0
    if ( !m_bConfigAccessInitialized )
306
0
    {
307
0
        impl_initializeConfigAccess();
308
0
        m_bConfigAccessInitialized = true;
309
0
    }
310
311
0
    if ( m_xConfigAccess.is() )
312
0
        return m_xConfigAccess->hasElements();
313
0
    else
314
0
        return false;
315
0
}
316
317
// XNameContainer
318
void SAL_CALL ConfigurationAccess_WindowState::removeByName( const OUString& rResourceURL )
319
0
{
320
    // SAFE
321
0
    std::unique_lock g(m_aMutex);
322
323
0
    ResourceURLToInfoCache::iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
324
0
    if ( pIter != m_aResourceURLToInfoCache.end() )
325
0
        m_aResourceURLToInfoCache.erase( pIter );
326
327
0
    if ( !m_bConfigAccessInitialized )
328
0
    {
329
0
        impl_initializeConfigAccess();
330
0
        m_bConfigAccessInitialized = true;
331
0
    }
332
333
0
    try
334
0
    {
335
        // Remove must be write-through => remove element from configuration
336
0
        Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY );
337
0
        if ( xNameContainer.is() )
338
0
        {
339
0
            g.unlock();
340
341
0
            xNameContainer->removeByName( rResourceURL );
342
0
            Reference< XChangesBatch > xFlush( m_xConfigAccess, UNO_QUERY );
343
0
            if ( xFlush.is() )
344
0
                xFlush->commitChanges();
345
0
        }
346
0
    }
347
0
    catch ( const css::lang::WrappedTargetException& )
348
0
    {
349
0
    }
350
0
}
351
352
void SAL_CALL ConfigurationAccess_WindowState::insertByName( const OUString& rResourceURL, const css::uno::Any& aPropertySet )
353
0
{
354
    // SAFE
355
0
    std::unique_lock g(m_aMutex);
356
357
0
    Sequence< PropertyValue > aPropSet;
358
0
    if ( !(aPropertySet >>= aPropSet) )
359
0
        throw IllegalArgumentException();
360
361
0
    ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
362
0
    if ( pIter != m_aResourceURLToInfoCache.end() )
363
0
        throw ElementExistException();
364
365
0
    if ( !m_bConfigAccessInitialized )
366
0
    {
367
0
        impl_initializeConfigAccess();
368
0
        m_bConfigAccessInitialized = true;
369
0
    }
370
371
    // Try to ask our configuration access
372
0
    if ( !m_xConfigAccess.is() )
373
0
        return;
374
375
0
    if ( m_xConfigAccess->hasByName( rResourceURL ) )
376
0
        throw ElementExistException();
377
378
0
    WindowStateInfo aWinStateInfo;
379
0
    impl_fillStructFromSequence( aWinStateInfo, aPropSet );
380
0
    m_aResourceURLToInfoCache.emplace( rResourceURL, aWinStateInfo );
381
382
    // insert must be write-through => insert element into configuration
383
0
    Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY );
384
0
    if ( !xNameContainer.is() )
385
0
        return;
386
387
0
    Reference< XSingleServiceFactory > xFactory( m_xConfigAccess, UNO_QUERY );
388
0
    g.unlock();
389
390
0
    try
391
0
    {
392
0
        Reference< XPropertySet > xPropSet( xFactory->createInstance(), UNO_QUERY );
393
0
        if ( xPropSet.is() )
394
0
        {
395
0
            Any a;
396
0
            impl_putPropertiesFromStruct( aWinStateInfo, xPropSet );
397
0
            a <<= xPropSet;
398
0
            xNameContainer->insertByName( rResourceURL, a );
399
0
            Reference< XChangesBatch > xFlush( xFactory, UNO_QUERY );
400
0
            if ( xFlush.is() )
401
0
                xFlush->commitChanges();
402
0
        }
403
0
    }
404
0
    catch ( const Exception& )
405
0
    {
406
0
    }
407
0
}
408
409
// XNameReplace
410
void SAL_CALL ConfigurationAccess_WindowState::replaceByName( const OUString& rResourceURL, const css::uno::Any& aPropertySet )
411
0
{
412
    // SAFE
413
0
    std::unique_lock g(m_aMutex);
414
415
0
    Sequence< PropertyValue > aPropSet;
416
0
    if ( !(aPropertySet >>= aPropSet) )
417
0
        throw IllegalArgumentException();
418
419
0
    ResourceURLToInfoCache::iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
420
0
    if ( pIter != m_aResourceURLToInfoCache.end() )
421
0
    {
422
0
        WindowStateInfo& rWinStateInfo = pIter->second;
423
0
        impl_fillStructFromSequence( rWinStateInfo, aPropSet );
424
0
        m_bModified = true;
425
0
    }
426
0
    else
427
0
    {
428
0
        if ( !m_bConfigAccessInitialized )
429
0
        {
430
0
            impl_initializeConfigAccess();
431
0
            m_bConfigAccessInitialized = true;
432
0
        }
433
434
        // Try to ask our configuration access
435
0
        Reference< XNameAccess > xNameAccess;
436
0
        Any a( m_xConfigAccess->getByName( rResourceURL ));
437
438
0
        if ( !(a >>= xNameAccess) )
439
0
            throw NoSuchElementException();
440
441
0
        WindowStateInfo& rWinStateInfo( impl_insertCacheAndReturnWinState( rResourceURL, xNameAccess ));
442
0
        impl_fillStructFromSequence( rWinStateInfo, aPropSet );
443
0
        m_bModified = true;
444
0
        pIter = m_aResourceURLToInfoCache.find( rResourceURL );
445
446
0
    }
447
448
0
    if ( !(m_bModified && pIter != m_aResourceURLToInfoCache.end()) )
449
0
        return;
450
451
0
    Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY );
452
0
    if ( !xNameContainer.is() )
453
0
        return;
454
455
0
    WindowStateInfo aWinStateInfo( pIter->second );
456
0
    OUString        aResourceURL( pIter->first );
457
0
    m_bModified = false;
458
0
    g.unlock();
459
460
0
    try
461
0
    {
462
0
        Reference< XPropertySet > xPropSet;
463
0
        if ( xNameContainer->getByName( aResourceURL ) >>= xPropSet )
464
0
        {
465
0
            impl_putPropertiesFromStruct( aWinStateInfo, xPropSet );
466
467
0
            Reference< XChangesBatch > xFlush( m_xConfigAccess, UNO_QUERY );
468
0
            if ( xFlush.is() )
469
0
                xFlush->commitChanges();
470
0
        }
471
0
    }
472
0
    catch ( const Exception& )
473
0
    {
474
0
    }
475
476
0
}
477
478
// container.XContainerListener
479
void SAL_CALL ConfigurationAccess_WindowState::elementInserted( const ContainerEvent& )
480
0
{
481
    // do nothing - next time someone wants to retrieve this node we will find it in the configuration
482
0
}
483
484
void SAL_CALL ConfigurationAccess_WindowState::elementRemoved ( const ContainerEvent& )
485
0
{
486
0
}
487
488
void SAL_CALL ConfigurationAccess_WindowState::elementReplaced( const ContainerEvent& )
489
0
{
490
0
}
491
492
// lang.XEventListener
493
void SAL_CALL ConfigurationAccess_WindowState::disposing( const EventObject& aEvent )
494
0
{
495
    // SAFE
496
    // remove our reference to the config access
497
0
    std::unique_lock g(m_aMutex);
498
499
0
    Reference< XInterface > xIfac1( aEvent.Source, UNO_QUERY );
500
0
    Reference< XInterface > xIfac2( m_xConfigAccess, UNO_QUERY );
501
0
    if ( xIfac1 == xIfac2 )
502
0
        m_xConfigAccess.clear();
503
0
}
504
505
// private helper methods
506
Any ConfigurationAccess_WindowState::impl_getSequenceFromStruct( const WindowStateInfo& rWinStateInfo )
507
0
{
508
0
    sal_Int32                 i( 0 );
509
0
    sal_Int32                 nCount( m_aPropArray.size() );
510
0
    std::vector< PropertyValue > aPropVec;
511
512
0
    for ( i = 0; i < nCount; i++ )
513
0
    {
514
0
        if ( rWinStateInfo.nMask & ( 1 << i ))
515
0
        {
516
            // put value into the return sequence
517
0
            PropertyValue pv;
518
0
            pv.Name = m_aPropArray[i];
519
520
0
            switch ( i )
521
0
            {
522
0
                case PROPERTY_LOCKED:
523
0
                    pv.Value <<= rWinStateInfo.bLocked; break;
524
0
                case PROPERTY_DOCKED:
525
0
                    pv.Value <<= rWinStateInfo.bDocked; break;
526
0
                case PROPERTY_VISIBLE:
527
0
                    pv.Value <<= rWinStateInfo.bVisible; break;
528
0
                case PROPERTY_CONTEXT:
529
0
                    pv.Value <<= rWinStateInfo.bContext; break;
530
0
                case PROPERTY_HIDEFROMMENU:
531
0
                    pv.Value <<= rWinStateInfo.bHideFromMenu; break;
532
0
                case PROPERTY_NOCLOSE:
533
0
                    pv.Value <<= rWinStateInfo.bNoClose; break;
534
0
                case PROPERTY_SOFTCLOSE:
535
0
                    pv.Value <<= rWinStateInfo.bSoftClose; break;
536
0
                case PROPERTY_CONTEXTACTIVE:
537
0
                    pv.Value <<= rWinStateInfo.bContextActive; break;
538
0
                case PROPERTY_DOCKINGAREA:
539
0
                    pv.Value <<= rWinStateInfo.aDockingArea; break;
540
0
                case PROPERTY_POS:
541
0
                    pv.Value <<= rWinStateInfo.aPos; break;
542
0
                case PROPERTY_SIZE:
543
0
                    pv.Value <<= rWinStateInfo.aSize; break;
544
0
                case PROPERTY_UINAME:
545
0
                    pv.Value <<= rWinStateInfo.aUIName; break;
546
0
                case PROPERTY_INTERNALSTATE:
547
0
                    pv.Value <<= sal_Int32( rWinStateInfo.nInternalState ); break;
548
0
                case PROPERTY_STYLE:
549
0
                    pv.Value <<= sal_Int16( rWinStateInfo.nStyle ); break;
550
0
                case PROPERTY_DOCKPOS:
551
0
                    pv.Value <<= rWinStateInfo.aDockPos; break;
552
0
                case PROPERTY_DOCKSIZE:
553
0
                    pv.Value <<= rWinStateInfo.aDockSize; break;
554
0
                default:
555
0
                    assert( false && "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
556
0
            }
557
0
            aPropVec.push_back(pv);
558
0
        }
559
0
    }
560
561
0
    return Any( comphelper::containerToSequence(aPropVec) );
562
0
}
563
564
Any ConfigurationAccess_WindowState::impl_insertCacheAndReturnSequence( const OUString& rResourceURL, Reference< XNameAccess > const & xNameAccess )
565
0
{
566
0
    sal_Int32                 nMask( 0 );
567
0
    sal_Int32                 nCount( m_aPropArray.size() );
568
0
    sal_Int32                 i( 0 );
569
0
    std::vector< PropertyValue > aPropVec;
570
0
    WindowStateInfo           aWindowStateInfo;
571
572
0
    for ( i = 0; i < nCount; i++ )
573
0
    {
574
0
        try
575
0
        {
576
0
            bool    bAddToSeq( false );
577
0
            Any     a( xNameAccess->getByName( m_aPropArray[i] ) );
578
0
            switch ( i )
579
0
            {
580
0
                case PROPERTY_LOCKED:
581
0
                case PROPERTY_DOCKED:
582
0
                case PROPERTY_VISIBLE:
583
0
                case PROPERTY_CONTEXT:
584
0
                case PROPERTY_HIDEFROMMENU:
585
0
                case PROPERTY_NOCLOSE:
586
0
                case PROPERTY_SOFTCLOSE:
587
0
                case PROPERTY_CONTEXTACTIVE:
588
0
                {
589
0
                    bool bValue;
590
0
                    if ( a >>= bValue )
591
0
                    {
592
0
                        sal_Int32 nValue( 1 << i );
593
0
                        nMask |= nValue;
594
0
                        bAddToSeq = true;
595
0
                        switch ( i )
596
0
                        {
597
0
                            case PROPERTY_LOCKED:
598
0
                                aWindowStateInfo.bLocked = bValue; break;
599
0
                            case PROPERTY_DOCKED:
600
0
                                aWindowStateInfo.bDocked = bValue; break;
601
0
                            case PROPERTY_VISIBLE:
602
0
                                aWindowStateInfo.bVisible = bValue; break;
603
0
                            case PROPERTY_CONTEXT:
604
0
                                aWindowStateInfo.bContext = bValue; break;
605
0
                            case PROPERTY_HIDEFROMMENU:
606
0
                                aWindowStateInfo.bHideFromMenu = bValue; break;
607
0
                            case PROPERTY_NOCLOSE:
608
0
                                aWindowStateInfo.bNoClose = bValue; break;
609
0
                            case PROPERTY_SOFTCLOSE:
610
0
                                aWindowStateInfo.bSoftClose = bValue; break;
611
0
                            case PROPERTY_CONTEXTACTIVE:
612
0
                                aWindowStateInfo.bContextActive = bValue; break;
613
0
                        }
614
0
                    }
615
0
                }
616
0
                break;
617
618
0
                case PROPERTY_DOCKINGAREA:
619
0
                {
620
0
                    sal_Int32 nDockingArea = 0;
621
0
                    if ( a >>= nDockingArea )
622
0
                    {
623
0
                        if (( nDockingArea >= 0 ) &&
624
0
                            ( nDockingArea <= sal_Int32( DockingArea_DOCKINGAREA_RIGHT )))
625
0
                        {
626
0
                            aWindowStateInfo.aDockingArea = static_cast<DockingArea>(nDockingArea);
627
0
                            nMask |= WINDOWSTATE_MASK_DOCKINGAREA;
628
0
                            a <<= aWindowStateInfo.aDockingArea;
629
0
                            bAddToSeq = true;
630
0
                        }
631
0
                    }
632
0
                }
633
0
                break;
634
635
0
                case PROPERTY_POS:
636
0
                case PROPERTY_DOCKPOS:
637
0
                {
638
0
                    OUString aString;
639
0
                    if ( a >>= aString )
640
0
                    {
641
0
                        sal_Int32 nToken( 0 );
642
0
                        std::u16string_view aXStr = o3tl::getToken(aString, 0, ',', nToken );
643
0
                        if ( nToken > 0 )
644
0
                        {
645
0
                            css::awt::Point aPos;
646
0
                            aPos.X = o3tl::toInt32(aXStr);
647
0
                            aPos.Y = o3tl::toInt32(o3tl::getToken(aString, 0, ',', nToken ));
648
649
0
                            if ( i == PROPERTY_POS )
650
0
                            {
651
0
                                aWindowStateInfo.aPos = aPos;
652
0
                                nMask |= WINDOWSTATE_MASK_POS;
653
0
                            }
654
0
                            else
655
0
                            {
656
0
                                aWindowStateInfo.aDockPos = aPos;
657
0
                                nMask |= WINDOWSTATE_MASK_DOCKPOS;
658
0
                            }
659
660
0
                            a <<= aPos;
661
0
                            bAddToSeq = true;
662
0
                        }
663
0
                    }
664
0
                }
665
0
                break;
666
667
0
                case PROPERTY_SIZE:
668
0
                case PROPERTY_DOCKSIZE:
669
0
                {
670
0
                    OUString aString;
671
0
                    if ( a >>= aString )
672
0
                    {
673
0
                        sal_Int32 nToken( 0 );
674
0
                        std::u16string_view aStr = o3tl::getToken(aString, 0, ',', nToken );
675
0
                        if ( nToken > 0 )
676
0
                        {
677
0
                            css::awt::Size aSize;
678
0
                            aSize.Width = o3tl::toInt32(aStr);
679
0
                            aSize.Height = o3tl::toInt32(o3tl::getToken(aString, 0, ',', nToken ));
680
0
                            if ( i == PROPERTY_SIZE )
681
0
                            {
682
0
                                aWindowStateInfo.aSize = aSize;
683
0
                                nMask |= WINDOWSTATE_MASK_SIZE;
684
0
                            }
685
0
                            else
686
0
                            {
687
0
                                aWindowStateInfo.aDockSize = aSize;
688
0
                                nMask |= WINDOWSTATE_MASK_DOCKSIZE;
689
0
                            }
690
691
0
                            a <<= aSize;
692
0
                            bAddToSeq = true;
693
0
                        }
694
0
                    }
695
0
                }
696
0
                break;
697
698
0
                case PROPERTY_UINAME:
699
0
                {
700
0
                    OUString aValue;
701
0
                    if ( a >>= aValue )
702
0
                    {
703
0
                        nMask |= WINDOWSTATE_MASK_UINAME;
704
0
                        aWindowStateInfo.aUIName = aValue;
705
0
                        bAddToSeq = true;
706
0
                    }
707
0
                }
708
0
                break;
709
710
0
                case PROPERTY_INTERNALSTATE:
711
0
                {
712
0
                    sal_uInt32 nValue = 0;
713
0
                    if ( a >>= nValue )
714
0
                    {
715
0
                        nMask |= WINDOWSTATE_MASK_INTERNALSTATE;
716
0
                        aWindowStateInfo.nInternalState = nValue;
717
0
                        bAddToSeq = true;
718
0
                    }
719
0
                }
720
0
                break;
721
722
0
                case PROPERTY_STYLE:
723
0
                {
724
0
                    sal_Int32 nValue = 0;
725
0
                    if ( a >>= nValue )
726
0
                    {
727
0
                        nMask |= WINDOWSTATE_MASK_STYLE;
728
0
                        aWindowStateInfo.nStyle = sal_uInt16( nValue );
729
0
                        bAddToSeq = true;
730
0
                    }
731
0
                }
732
0
                break;
733
734
0
                default:
735
0
                   assert( false && "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
736
0
            }
737
738
0
            if ( bAddToSeq )
739
0
            {
740
                // put value into the return sequence
741
0
                PropertyValue pv;
742
0
                pv.Name  = m_aPropArray[i];
743
0
                pv.Value = std::move(a);
744
0
                aPropVec.push_back(pv);
745
0
            }
746
0
        }
747
0
        catch( const css::container::NoSuchElementException& )
748
0
        {
749
0
        }
750
0
        catch ( const css::lang::WrappedTargetException& )
751
0
        {
752
0
        }
753
0
    }
754
755
0
    aWindowStateInfo.nMask = nMask;
756
0
    m_aResourceURLToInfoCache.emplace( rResourceURL, aWindowStateInfo );
757
0
    return Any( comphelper::containerToSequence(aPropVec) );
758
0
}
759
760
ConfigurationAccess_WindowState::WindowStateInfo& ConfigurationAccess_WindowState::impl_insertCacheAndReturnWinState( const OUString& rResourceURL, Reference< XNameAccess > const & rNameAccess )
761
0
{
762
0
    sal_Int32                 nMask( 0 );
763
0
    sal_Int32                 nCount( m_aPropArray.size() );
764
0
    sal_Int32                 i( 0 );
765
0
    WindowStateInfo           aWindowStateInfo;
766
767
0
    for ( i = 0; i < nCount; i++ )
768
0
    {
769
0
        try
770
0
        {
771
0
            Any     a( rNameAccess->getByName( m_aPropArray[i] ) );
772
0
            switch ( i )
773
0
            {
774
0
                case PROPERTY_LOCKED:
775
0
                case PROPERTY_DOCKED:
776
0
                case PROPERTY_VISIBLE:
777
0
                case PROPERTY_CONTEXT:
778
0
                case PROPERTY_HIDEFROMMENU:
779
0
                case PROPERTY_NOCLOSE:
780
0
                case PROPERTY_SOFTCLOSE:
781
0
                case PROPERTY_CONTEXTACTIVE:
782
0
                {
783
0
                    bool bValue;
784
0
                    if ( a >>= bValue )
785
0
                    {
786
0
                        sal_Int32 nValue( 1 << i );
787
0
                        nMask |= nValue;
788
0
                        switch ( i )
789
0
                        {
790
0
                            case PROPERTY_LOCKED:
791
0
                                aWindowStateInfo.bLocked = bValue; break;
792
0
                            case PROPERTY_DOCKED:
793
0
                                aWindowStateInfo.bDocked = bValue; break;
794
0
                            case PROPERTY_VISIBLE:
795
0
                                aWindowStateInfo.bVisible = bValue; break;
796
0
                            case PROPERTY_CONTEXT:
797
0
                                aWindowStateInfo.bContext = bValue; break;
798
0
                            case PROPERTY_HIDEFROMMENU:
799
0
                                aWindowStateInfo.bHideFromMenu = bValue; break;
800
0
                            case PROPERTY_NOCLOSE:
801
0
                                aWindowStateInfo.bNoClose = bValue; break;
802
0
                            case PROPERTY_SOFTCLOSE:
803
0
                                aWindowStateInfo.bNoClose = bValue; break;
804
0
                            case PROPERTY_CONTEXTACTIVE:
805
0
                                aWindowStateInfo.bContextActive = bValue; break;
806
0
                            default:
807
0
                                SAL_WARN( "fwk.uiconfiguration", "Unknown boolean property in WindowState found!" );
808
0
                        }
809
0
                    }
810
0
                }
811
0
                break;
812
813
0
                case PROPERTY_DOCKINGAREA:
814
0
                {
815
0
                    sal_Int32 nDockingArea = 0;
816
0
                    if ( a >>= nDockingArea )
817
0
                    {
818
0
                        if (( nDockingArea >= 0 ) &&
819
0
                            ( nDockingArea <= sal_Int32( DockingArea_DOCKINGAREA_RIGHT )))
820
0
                        {
821
0
                            aWindowStateInfo.aDockingArea = static_cast<DockingArea>(nDockingArea);
822
0
                            nMask |= WINDOWSTATE_MASK_DOCKINGAREA;
823
0
                        }
824
0
                    }
825
0
                }
826
0
                break;
827
828
0
                case PROPERTY_POS:
829
0
                case PROPERTY_DOCKPOS:
830
0
                {
831
0
                    OUString aString;
832
0
                    if ( a >>= aString )
833
0
                    {
834
0
                        sal_Int32 nToken( 0 );
835
0
                        std::u16string_view aXStr = o3tl::getToken(aString, 0, ',', nToken );
836
0
                        if ( nToken > 0 )
837
0
                        {
838
0
                            css::awt::Point aPos;
839
0
                            aPos.X = o3tl::toInt32(aXStr);
840
0
                            aPos.Y = o3tl::toInt32(o3tl::getToken(aString, 0, ',', nToken ));
841
842
0
                            if ( i == PROPERTY_POS )
843
0
                            {
844
0
                                aWindowStateInfo.aPos = aPos;
845
0
                                nMask |= WINDOWSTATE_MASK_POS;
846
0
                            }
847
0
                            else
848
0
                            {
849
0
                                aWindowStateInfo.aDockPos = aPos;
850
0
                                nMask |= WINDOWSTATE_MASK_DOCKPOS;
851
0
                            }
852
0
                        }
853
0
                    }
854
0
                }
855
0
                break;
856
857
0
                case PROPERTY_SIZE:
858
0
                case PROPERTY_DOCKSIZE:
859
0
                {
860
0
                    OUString aString;
861
0
                    if ( a >>= aString )
862
0
                    {
863
0
                        sal_Int32 nToken( 0 );
864
0
                        std::u16string_view aStr = o3tl::getToken(aString, 0, ',', nToken );
865
0
                        if ( nToken > 0 )
866
0
                        {
867
0
                            css::awt::Size aSize;
868
0
                            aSize.Width  = o3tl::toInt32(aStr);
869
0
                            aSize.Height = o3tl::toInt32(o3tl::getToken(aString, 0, ',', nToken ));
870
0
                            if ( i == PROPERTY_SIZE )
871
0
                            {
872
0
                                aWindowStateInfo.aSize = aSize;
873
0
                                nMask |= WINDOWSTATE_MASK_SIZE;
874
0
                            }
875
0
                            else
876
0
                            {
877
0
                                aWindowStateInfo.aDockSize = aSize;
878
0
                                nMask |= WINDOWSTATE_MASK_DOCKSIZE;
879
0
                            }
880
0
                        }
881
0
                    }
882
0
                }
883
0
                break;
884
885
0
                case PROPERTY_UINAME:
886
0
                {
887
0
                    OUString aValue;
888
0
                    if ( a >>= aValue )
889
0
                    {
890
0
                        nMask |= WINDOWSTATE_MASK_UINAME;
891
0
                        aWindowStateInfo.aUIName = aValue;
892
0
                    }
893
0
                }
894
0
                break;
895
896
0
                case PROPERTY_INTERNALSTATE:
897
0
                {
898
0
                    sal_Int32 nValue = 0;
899
0
                    if ( a >>= nValue )
900
0
                    {
901
0
                        nMask |= WINDOWSTATE_MASK_INTERNALSTATE;
902
0
                        aWindowStateInfo.nInternalState = sal_uInt32( nValue );
903
0
                    }
904
0
                }
905
0
                break;
906
907
0
                case PROPERTY_STYLE:
908
0
                {
909
0
                    sal_Int32 nValue = 0;
910
0
                    if ( a >>= nValue )
911
0
                    {
912
0
                        nMask |= WINDOWSTATE_MASK_STYLE;
913
0
                        aWindowStateInfo.nStyle = sal_uInt16( nValue );
914
0
                    }
915
0
                }
916
0
                break;
917
918
0
                default:
919
0
                   assert( false && "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
920
0
            }
921
0
        }
922
0
        catch( const css::container::NoSuchElementException& )
923
0
        {
924
0
        }
925
0
        catch ( const css::lang::WrappedTargetException& )
926
0
        {
927
0
        }
928
0
    }
929
930
0
    aWindowStateInfo.nMask = nMask;
931
0
    ResourceURLToInfoCache::iterator pIter = m_aResourceURLToInfoCache.emplace( rResourceURL, aWindowStateInfo ).first;
932
0
    return pIter->second;
933
0
}
934
935
Any ConfigurationAccess_WindowState::impl_getWindowStateFromResourceURL( const OUString& rResourceURL )
936
0
{
937
0
    if ( !m_bConfigAccessInitialized )
938
0
    {
939
0
        impl_initializeConfigAccess();
940
0
        m_bConfigAccessInitialized = true;
941
0
    }
942
943
0
    try
944
0
    {
945
        // Try to ask our configuration access
946
0
        if ( m_xConfigAccess.is() && m_xConfigAccess->hasByName( rResourceURL ) )
947
0
        {
948
949
0
            Reference< XNameAccess > xNameAccess( m_xConfigAccess->getByName( rResourceURL ), UNO_QUERY );
950
0
            if ( xNameAccess.is() )
951
0
                return impl_insertCacheAndReturnSequence( rResourceURL, xNameAccess );
952
0
        }
953
0
    }
954
0
    catch( const css::container::NoSuchElementException& )
955
0
    {
956
0
    }
957
0
    catch ( const css::lang::WrappedTargetException& )
958
0
    {
959
0
    }
960
961
0
    return Any();
962
0
}
963
964
void ConfigurationAccess_WindowState::impl_fillStructFromSequence( WindowStateInfo& rWinStateInfo, const Sequence< PropertyValue >& rSeq )
965
0
{
966
0
    sal_Int32 nCompareCount( m_aPropArray.size() );
967
0
    sal_Int32 nCount( rSeq.getLength() );
968
0
    sal_Int32 i( 0 );
969
970
0
    for ( i = 0; i < nCount; i++ )
971
0
    {
972
0
        for ( sal_Int32 j = 0; j < nCompareCount; j++ )
973
0
        {
974
0
            if ( rSeq[i].Name == m_aPropArray[j] )
975
0
            {
976
0
                switch ( j )
977
0
                {
978
0
                    case PROPERTY_LOCKED:
979
0
                    case PROPERTY_DOCKED:
980
0
                    case PROPERTY_VISIBLE:
981
0
                    case PROPERTY_CONTEXT:
982
0
                    case PROPERTY_HIDEFROMMENU:
983
0
                    case PROPERTY_NOCLOSE:
984
0
                    case PROPERTY_SOFTCLOSE:
985
0
                    case PROPERTY_CONTEXTACTIVE:
986
0
                    {
987
0
                        bool bValue;
988
0
                        if ( rSeq[i].Value >>= bValue )
989
0
                        {
990
0
                            sal_Int32 nValue( 1 << j );
991
0
                            rWinStateInfo.nMask |= nValue;
992
0
                            switch ( j )
993
0
                            {
994
0
                                case PROPERTY_LOCKED:
995
0
                                    rWinStateInfo.bLocked = bValue;
996
0
                                    break;
997
0
                                case PROPERTY_DOCKED:
998
0
                                    rWinStateInfo.bDocked = bValue;
999
0
                                    break;
1000
0
                                case PROPERTY_VISIBLE:
1001
0
                                    rWinStateInfo.bVisible = bValue;
1002
0
                                    break;
1003
0
                                case PROPERTY_CONTEXT:
1004
0
                                    rWinStateInfo.bContext = bValue;
1005
0
                                    break;
1006
0
                                case PROPERTY_HIDEFROMMENU:
1007
0
                                    rWinStateInfo.bHideFromMenu = bValue;
1008
0
                                    break;
1009
0
                                case PROPERTY_NOCLOSE:
1010
0
                                    rWinStateInfo.bNoClose = bValue;
1011
0
                                    break;
1012
0
                                case PROPERTY_SOFTCLOSE:
1013
0
                                    rWinStateInfo.bSoftClose = bValue;
1014
0
                                    break;
1015
0
                                case PROPERTY_CONTEXTACTIVE:
1016
0
                                    rWinStateInfo.bContextActive = bValue;
1017
0
                                    break;
1018
0
                            }
1019
0
                        }
1020
0
                    }
1021
0
                    break;
1022
1023
0
                    case PROPERTY_DOCKINGAREA:
1024
0
                    {
1025
0
                        css::ui::DockingArea eDockingArea;
1026
0
                        if ( rSeq[i].Value >>= eDockingArea )
1027
0
                        {
1028
0
                            rWinStateInfo.aDockingArea = eDockingArea;
1029
0
                            rWinStateInfo.nMask |= WINDOWSTATE_MASK_DOCKINGAREA;
1030
0
                        }
1031
0
                    }
1032
0
                    break;
1033
1034
0
                    case PROPERTY_POS:
1035
0
                    case PROPERTY_DOCKPOS:
1036
0
                    {
1037
0
                        css::awt::Point aPoint;
1038
0
                        if ( rSeq[i].Value >>= aPoint )
1039
0
                        {
1040
0
                            if ( j == PROPERTY_POS )
1041
0
                            {
1042
0
                                rWinStateInfo.aPos = aPoint;
1043
0
                                rWinStateInfo.nMask |= WINDOWSTATE_MASK_POS;
1044
0
                            }
1045
0
                            else
1046
0
                            {
1047
0
                                rWinStateInfo.aDockPos = aPoint;
1048
0
                                rWinStateInfo.nMask |= WINDOWSTATE_MASK_DOCKPOS;
1049
0
                            }
1050
0
                        }
1051
0
                    }
1052
0
                    break;
1053
1054
0
                    case PROPERTY_SIZE:
1055
0
                    case PROPERTY_DOCKSIZE:
1056
0
                    {
1057
0
                        css::awt::Size aSize;
1058
0
                        if ( rSeq[i].Value >>= aSize )
1059
0
                        {
1060
0
                            if ( j == PROPERTY_SIZE )
1061
0
                            {
1062
0
                                rWinStateInfo.aSize = aSize;
1063
0
                                rWinStateInfo.nMask |= WINDOWSTATE_MASK_SIZE;
1064
0
                            }
1065
0
                            else
1066
0
                            {
1067
0
                                rWinStateInfo.aDockSize = aSize;
1068
0
                                rWinStateInfo.nMask |= WINDOWSTATE_MASK_DOCKSIZE;
1069
0
                            }
1070
0
                        }
1071
0
                    }
1072
0
                    break;
1073
1074
0
                    case PROPERTY_UINAME:
1075
0
                    {
1076
0
                        OUString aValue;
1077
0
                        if ( rSeq[i].Value >>= aValue )
1078
0
                        {
1079
0
                            rWinStateInfo.aUIName = aValue;
1080
0
                            rWinStateInfo.nMask |= WINDOWSTATE_MASK_UINAME;
1081
0
                        }
1082
0
                    }
1083
0
                    break;
1084
1085
0
                    case PROPERTY_INTERNALSTATE:
1086
0
                    {
1087
0
                        sal_Int32 nValue = 0;
1088
0
                        if ( rSeq[i].Value >>= nValue )
1089
0
                        {
1090
0
                            rWinStateInfo.nInternalState = sal_uInt32( nValue );
1091
0
                            rWinStateInfo.nMask |= WINDOWSTATE_MASK_INTERNALSTATE;
1092
0
                        }
1093
0
                    }
1094
0
                    break;
1095
1096
0
                    case PROPERTY_STYLE:
1097
0
                    {
1098
0
                        sal_Int32 nValue = 0;
1099
0
                        if ( rSeq[i].Value >>= nValue )
1100
0
                        {
1101
0
                            rWinStateInfo.nStyle = sal_uInt16( nValue );
1102
0
                            rWinStateInfo.nMask |= WINDOWSTATE_MASK_STYLE;
1103
0
                        }
1104
0
                    }
1105
0
                    break;
1106
1107
0
                    default:
1108
0
                       assert( false && "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1109
0
                }
1110
1111
0
                break;
1112
0
            }
1113
0
        }
1114
0
    }
1115
0
}
1116
1117
void ConfigurationAccess_WindowState::impl_putPropertiesFromStruct( const WindowStateInfo& rWinStateInfo, Reference< XPropertySet > const & xPropSet )
1118
0
{
1119
0
    sal_Int32                 i( 0 );
1120
0
    sal_Int32                 nCount( m_aPropArray.size() );
1121
0
    OUString                  aDelim( u","_ustr );
1122
1123
0
    for ( i = 0; i < nCount; i++ )
1124
0
    {
1125
0
        if ( rWinStateInfo.nMask & ( 1 << i ))
1126
0
        {
1127
0
            try
1128
0
            {
1129
                // put values into the property set
1130
0
                switch ( i )
1131
0
                {
1132
0
                    case PROPERTY_LOCKED:
1133
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bLocked ) ); break;
1134
0
                    case PROPERTY_DOCKED:
1135
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bDocked ) ); break;
1136
0
                    case PROPERTY_VISIBLE:
1137
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bVisible ) ); break;
1138
0
                    case PROPERTY_CONTEXT:
1139
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bContext ) ); break;
1140
0
                    case PROPERTY_HIDEFROMMENU:
1141
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bHideFromMenu ) ); break;
1142
0
                    case PROPERTY_NOCLOSE:
1143
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bNoClose ) ); break;
1144
0
                    case PROPERTY_SOFTCLOSE:
1145
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bSoftClose ) ); break;
1146
0
                    case PROPERTY_CONTEXTACTIVE:
1147
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bContextActive ) ); break;
1148
0
                    case PROPERTY_DOCKINGAREA:
1149
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( sal_Int16( rWinStateInfo.aDockingArea ) ) ); break;
1150
0
                    case PROPERTY_POS:
1151
0
                    case PROPERTY_DOCKPOS:
1152
0
                    {
1153
0
                        OUString aPosStr;
1154
0
                        if ( i == PROPERTY_POS )
1155
0
                            aPosStr = OUString::number( rWinStateInfo.aPos.X );
1156
0
                        else
1157
0
                            aPosStr = OUString::number( rWinStateInfo.aDockPos.X );
1158
0
                        aPosStr += aDelim;
1159
0
                        if ( i == PROPERTY_POS )
1160
0
                            aPosStr += OUString::number( rWinStateInfo.aPos.Y );
1161
0
                        else
1162
0
                            aPosStr += OUString::number( rWinStateInfo.aDockPos.Y );
1163
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( aPosStr ) );
1164
0
                        break;
1165
0
                    }
1166
0
                    case PROPERTY_SIZE:
1167
0
                    case PROPERTY_DOCKSIZE:
1168
0
                    {
1169
0
                        OUString aSizeStr;
1170
0
                        if ( i == PROPERTY_SIZE )
1171
0
                            aSizeStr = OUString::number( rWinStateInfo.aSize.Width );
1172
0
                        else
1173
0
                            aSizeStr = OUString::number( rWinStateInfo.aDockSize.Width );
1174
0
                        aSizeStr += aDelim;
1175
0
                        if ( i == PROPERTY_SIZE )
1176
0
                            aSizeStr += OUString::number( rWinStateInfo.aSize.Height );
1177
0
                        else
1178
0
                            aSizeStr += OUString::number( rWinStateInfo.aDockSize.Height );
1179
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( aSizeStr ) );
1180
0
                        break;
1181
0
                    }
1182
0
                    case PROPERTY_UINAME:
1183
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.aUIName ) ); break;
1184
0
                    case PROPERTY_INTERNALSTATE:
1185
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( sal_Int32( rWinStateInfo.nInternalState )) ); break;
1186
0
                    case PROPERTY_STYLE:
1187
0
                        xPropSet->setPropertyValue( m_aPropArray[i], Any( sal_Int32( rWinStateInfo.nStyle )) ); break;
1188
0
                    default:
1189
0
                       assert( false && "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1190
0
                }
1191
0
            }
1192
0
            catch( const Exception& )
1193
0
            {
1194
0
            }
1195
0
        }
1196
0
    }
1197
0
}
1198
1199
void ConfigurationAccess_WindowState::impl_initializeConfigAccess()
1200
0
{
1201
0
    try
1202
0
    {
1203
0
        Sequence<Any> aArgs(comphelper::InitAnyPropertySequence(
1204
0
        {
1205
0
            {"nodepath", Any(m_aConfigWindowAccess)}
1206
0
        }));
1207
0
        m_xConfigAccess.set( m_xConfigProvider->createInstanceWithArguments(
1208
0
                    u"com.sun.star.configuration.ConfigurationUpdateAccess"_ustr, aArgs ), UNO_QUERY );
1209
0
        if ( m_xConfigAccess.is() )
1210
0
        {
1211
            // Add as container listener
1212
0
            Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
1213
0
            if ( xContainer.is() )
1214
0
            {
1215
0
                m_xConfigListener = new WeakContainerListener(this);
1216
0
                xContainer->addContainerListener(m_xConfigListener);
1217
0
            }
1218
0
        }
1219
0
    }
1220
0
    catch ( const WrappedTargetException& )
1221
0
    {
1222
0
    }
1223
0
    catch ( const Exception& )
1224
0
    {
1225
0
    }
1226
0
}
1227
1228
typedef comphelper::WeakComponentImplHelper< css::container::XNameAccess,
1229
        css::lang::XServiceInfo> WindowStateConfiguration_BASE;
1230
1231
class WindowStateConfiguration : public WindowStateConfiguration_BASE
1232
{
1233
public:
1234
    explicit WindowStateConfiguration( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
1235
    virtual ~WindowStateConfiguration() override;
1236
1237
    virtual OUString SAL_CALL getImplementationName() override
1238
0
    {
1239
0
        return u"com.sun.star.comp.framework.WindowStateConfiguration"_ustr;
1240
0
    }
1241
1242
    virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
1243
0
    {
1244
0
        return cppu::supportsService(this, ServiceName);
1245
0
    }
1246
1247
    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
1248
0
    {
1249
0
        return {u"com.sun.star.ui.WindowStateConfiguration"_ustr};
1250
0
    }
1251
1252
    // XNameAccess
1253
    virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
1254
1255
    virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
1256
1257
    virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
1258
1259
    // XElementAccess
1260
    virtual css::uno::Type SAL_CALL getElementType() override;
1261
    virtual sal_Bool SAL_CALL hasElements() override;
1262
1263
    typedef std::unordered_map< OUString,
1264
                                OUString > ModuleToWindowStateFileMap;
1265
1266
    typedef std::unordered_map< OUString,
1267
                                css::uno::Reference< css::container::XNameAccess > > ModuleToWindowStateConfigHashMap;
1268
1269
private:
1270
    css::uno::Reference< css::uno::XComponentContext>         m_xContext;
1271
    ModuleToWindowStateFileMap                                m_aModuleToFileHashMap;
1272
    ModuleToWindowStateConfigHashMap                          m_aModuleToWindowStateHashMap;
1273
};
1274
1275
WindowStateConfiguration::WindowStateConfiguration( const Reference< XComponentContext >& rxContext ) :
1276
2
    m_xContext( rxContext )
1277
2
{
1278
2
    css::uno::Reference< css::frame::XModuleManager2 > xModuleManager =
1279
2
        ModuleManager::create( m_xContext );
1280
2
    Reference< XNameAccess > xEmptyNameAccess;
1281
2
    Sequence< OUString > aElementNames;
1282
2
    try
1283
2
    {
1284
2
        aElementNames = xModuleManager->getElementNames();
1285
2
    }
1286
2
    catch (const css::uno::RuntimeException &)
1287
2
    {
1288
0
    }
1289
2
    Sequence< PropertyValue > aSeq;
1290
1291
2
    for (OUString const& aModuleIdentifier : aElementNames)
1292
0
    {
1293
0
        if ( xModuleManager->getByName( aModuleIdentifier ) >>= aSeq )
1294
0
        {
1295
0
            OUString aWindowStateFileStr;
1296
0
            for (PropertyValue const& rProp : aSeq)
1297
0
            {
1298
0
                if ( rProp.Name == "ooSetupFactoryWindowStateConfigRef" )
1299
0
                {
1300
0
                    rProp.Value >>= aWindowStateFileStr;
1301
0
                    break;
1302
0
                }
1303
0
            }
1304
1305
0
            if ( !aWindowStateFileStr.isEmpty() )
1306
0
            {
1307
                // Create first mapping ModuleIdentifier ==> Window state configuration file
1308
0
                m_aModuleToFileHashMap.emplace( aModuleIdentifier, aWindowStateFileStr );
1309
1310
                // Create second mapping Command File ==> Window state configuration instance
1311
0
                ModuleToWindowStateConfigHashMap::iterator pIter = m_aModuleToWindowStateHashMap.find( aWindowStateFileStr );
1312
0
                if ( pIter == m_aModuleToWindowStateHashMap.end() )
1313
0
                    m_aModuleToWindowStateHashMap.emplace( aWindowStateFileStr, xEmptyNameAccess );
1314
0
            }
1315
0
        }
1316
0
    }
1317
2
}
1318
1319
WindowStateConfiguration::~WindowStateConfiguration()
1320
0
{
1321
0
    std::unique_lock g(m_aMutex);
1322
0
    m_aModuleToFileHashMap.clear();
1323
0
    m_aModuleToWindowStateHashMap.clear();
1324
0
}
1325
1326
Any SAL_CALL WindowStateConfiguration::getByName( const OUString& aModuleIdentifier )
1327
8.47k
{
1328
8.47k
    std::unique_lock g(m_aMutex);
1329
1330
8.47k
    ModuleToWindowStateFileMap::const_iterator pIter = m_aModuleToFileHashMap.find( aModuleIdentifier );
1331
8.47k
    if ( pIter != m_aModuleToFileHashMap.end() )
1332
0
    {
1333
0
        Any a;
1334
0
        OUString aWindowStateConfigFile( pIter->second );
1335
1336
0
        ModuleToWindowStateConfigHashMap::iterator pModuleIter = m_aModuleToWindowStateHashMap.find( aWindowStateConfigFile );
1337
0
        if ( pModuleIter != m_aModuleToWindowStateHashMap.end() )
1338
0
        {
1339
0
            if ( pModuleIter->second.is() )
1340
0
                a <<= pModuleIter->second;
1341
0
            else
1342
0
            {
1343
0
                Reference< XNameAccess > xResourceURLWindowState = new ConfigurationAccess_WindowState( aWindowStateConfigFile, m_xContext );
1344
0
                pModuleIter->second = xResourceURLWindowState;
1345
0
                a <<= xResourceURLWindowState;
1346
0
            }
1347
1348
0
            return a;
1349
0
        }
1350
0
    }
1351
1352
8.47k
    throw NoSuchElementException();
1353
8.47k
}
1354
1355
Sequence< OUString > SAL_CALL WindowStateConfiguration::getElementNames()
1356
0
{
1357
0
    std::unique_lock g(m_aMutex);
1358
1359
0
    return comphelper::mapKeysToSequence( m_aModuleToFileHashMap );
1360
0
}
1361
1362
sal_Bool SAL_CALL WindowStateConfiguration::hasByName( const OUString& aName )
1363
0
{
1364
0
    std::unique_lock g(m_aMutex);
1365
1366
0
    ModuleToWindowStateFileMap::const_iterator pIter = m_aModuleToFileHashMap.find( aName );
1367
0
    return ( pIter != m_aModuleToFileHashMap.end() );
1368
0
}
1369
1370
// XElementAccess
1371
Type SAL_CALL WindowStateConfiguration::getElementType()
1372
0
{
1373
0
    return cppu::UnoType<XNameAccess>::get();
1374
0
}
1375
1376
sal_Bool SAL_CALL WindowStateConfiguration::hasElements()
1377
0
{
1378
    // We always have at least one module. So it is valid to return true!
1379
0
    return true;
1380
0
}
1381
1382
}
1383
1384
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1385
com_sun_star_comp_framework_WindowStateConfiguration_get_implementation(
1386
    css::uno::XComponentContext *context,
1387
    css::uno::Sequence<css::uno::Any> const &)
1388
2
{
1389
2
    return cppu::acquire(new WindowStateConfiguration(context));
1390
2
}
1391
1392
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */