summaryrefslogtreecommitdiff
path: root/cui/source/tabpages/tparea.cxx
blob: 3f54e2263d74c29203c93c506fedc24cd7065635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <stdlib.h>

#include <tools/urlobj.hxx>
#include <sfx2/app.hxx>
#include <sfx2/module.hxx>
#include <svx/dialogs.hrc>

#include "svx/xattr.hxx"
#include <svx/xpool.hxx>
#include <cuires.hrc>
#include <svx/xflbckit.hxx>
#include <svx/svdattr.hxx>
#include <svx/xtable.hxx>
#include <svx/xlineit0.hxx>
#include "svx/drawitem.hxx"
#include "cuitabarea.hxx"
#include "dlgname.hxx"
#include <dialmgr.hxx>
#include "svx/dlgutil.hxx"
#include <svl/intitem.hxx>
#include <sfx2/request.hxx>
#include "paragrph.hrc"

//UUUU
#include "sfx2/opengrf.hxx"
#include <vcl/layout.hxx>

#define DEFAULT_GRADIENTSTEP 64

using namespace com::sun::star;

// static ----------------------------------------------------------------

const sal_uInt16 SvxAreaTabPage::pAreaRanges[] =
{
    XATTR_GRADIENTSTEPCOUNT,
    XATTR_GRADIENTSTEPCOUNT,
    SID_ATTR_FILL_STYLE,
    SID_ATTR_FILL_BITMAP,
    0
};

/*************************************************************************
|*
|*  Dialog to modify fill-attributes
|*
\************************************************************************/

SvxAreaTabPage::SvxAreaTabPage( vcl::Window* pParent, const SfxItemSet& rInAttrs ) :

    SvxTabPage( pParent,
                "AreaTabPage",
                "cui/ui/areatabpage.ui",
               rInAttrs ),
    m_rOutAttrs (rInAttrs ),
    m_eRP( RP_LT ),

    m_pColorList( nullptr ),
    m_pGradientList( nullptr ),
    m_pHatchingList( nullptr ),
    m_pBitmapList( nullptr ),

    // local fixed not o be changed values for local pointers
    maFixed_ChangeType(ChangeType::NONE),
    maFixed_sal_Bool(false),

    // init with pointers to fixed ChangeType
    m_pnColorListState(&maFixed_ChangeType),
    m_pnBitmapListState(&maFixed_ChangeType),
    m_pnGradientListState(&maFixed_ChangeType),
    m_pnHatchingListState(&maFixed_ChangeType),

    m_nPageType(PageType::Area),
    m_nDlgType(0),
    m_nPos(0),

    // init with pointer to fixed bool
    m_pbAreaTP(&maFixed_sal_Bool),

    m_aXFillAttr          ( rInAttrs.GetPool() ),
    m_rXFSet              ( m_aXFillAttr.GetItemSet() )
{
    get(m_pTypeLB,"LB_AREA_TYPE");
    get(m_pFillLB,"boxLB_FILL");
    get(m_pLbColor,"LB_COLOR");
    get(m_pLbGradient,"LB_GRADIENT");
    get(m_pLbHatching,"LB_HATCHING");
    get(m_pLbBitmap,"LB_BITMAP");
    get(m_pCtlBitmapPreview,"CTL_BITMAP_PREVIEW");
    get(m_pCtlXRectPreview,"CTL_COLOR_PREVIEW");


    // groups that overlay each other
    m_pLbBitmap->Hide();
    m_pCtlBitmapPreview->Hide();

    // this page needs ExchangeSupport
    SetExchangeSupport();

    // get PoolUnit
    SfxItemPool* pPool = m_rOutAttrs.GetPool();
    DBG_ASSERT( pPool, "Wo ist der Pool?" );
    m_ePoolUnit = pPool->GetMetric( XATTR_FILLBMP_SIZEX );

    // setting the output device
    m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
    m_rXFSet.Put( XFillColorItem( OUString(), COL_BLACK ) );
    m_pCtlXRectPreview->SetAttributes( m_aXFillAttr.GetItemSet() );
    m_pCtlBitmapPreview->SetAttributes( m_aXFillAttr.GetItemSet() );

    m_pLbColor->SetSelectHdl( LINK( this, SvxAreaTabPage, ModifyColorHdl_Impl ) );
    m_pLbGradient->SetSelectHdl( LINK( this, SvxAreaTabPage, ModifyGradientHdl_Impl ) );
    m_pLbHatching->SetSelectHdl( LINK( this, SvxAreaTabPage, ModifyHatchingHdl_Impl ) );
    m_pLbBitmap->SetSelectHdl(   LINK( this, SvxAreaTabPage, ModifyBitmapHdl_Impl ) );

    m_pTypeLB->SetSelectHdl( LINK( this, SvxAreaTabPage, SelectDialogTypeHdl_Impl ) );

    // #i76307# always paint the preview in LTR, because this is what the document does
    m_pCtlXRectPreview->EnableRTL(false);

    // Calculate size of dropdown listboxes
    Size aSize = LogicToPixel(Size(108, 103), MAP_APPFONT);

    m_pLbColor->set_width_request(aSize.Width());
    m_pLbColor->set_height_request(aSize.Height());
    //m_pLbColor->

    m_pLbGradient->set_width_request(aSize.Width());
    m_pLbGradient->set_height_request(aSize.Height());
    m_pLbHatching->set_width_request(aSize.Width());
    m_pLbHatching->set_height_request(aSize.Height());
    m_pLbBitmap->set_width_request(aSize.Width());
    m_pLbBitmap->set_height_request(aSize.Height());

    // Calculate size of display boxes
    Size aSize2 = LogicToPixel(Size(110, 42), MAP_APPFONT);
    m_pCtlBitmapPreview->set_width_request(aSize2.Width());
    m_pCtlBitmapPreview->set_height_request(aSize2.Height());
    m_pCtlXRectPreview->set_width_request(aSize2.Width());
    m_pCtlXRectPreview->set_height_request(aSize2.Height());
}

SvxAreaTabPage::~SvxAreaTabPage()
{
    disposeOnce();
}

void SvxAreaTabPage::dispose()
{
    m_pTypeLB.clear();
    m_pFillLB.clear();
    m_pLbColor.clear();
    m_pLbGradient.clear();
    m_pLbHatching.clear();
    m_pLbBitmap.clear();
    m_pCtlBitmapPreview.clear();
    m_pCtlXRectPreview.clear();
    SvxTabPage::dispose();
}

void SvxAreaTabPage::Construct()
{
    // fill colortables / lists
    m_pLbColor->Fill( m_pColorList );
    m_pLbGradient->Fill( m_pGradientList );
    m_pLbHatching->Fill( m_pHatchingList );
    m_pLbBitmap->Fill( m_pBitmapList );
}


void SvxAreaTabPage::ActivatePage( const SfxItemSet& rSet )
{
    sal_Int32 nCount(0);
    const SfxUInt16Item* pPageTypeItem = rSet.GetItem<SfxUInt16Item>(SID_PAGE_TYPE, false);
    const SfxUInt16Item* pPosItem = rSet.GetItem<SfxUInt16Item>(SID_TABPAGE_POS, false);
    if (pPageTypeItem)
        SetPageType((PageType) pPageTypeItem->GetValue());
    if (pPosItem)
        SetPos(pPosItem->GetValue());
    if( m_nDlgType == 0 ) // area dialog
    {
        *m_pbAreaTP = true;

        if( m_pColorList.is() )
        {
            //UUUU use evtl. previously selected entry to avoid changing values just by
            // switching TabPages in dialogs using this TabPage
            sal_Int32 _nPos(m_nPos);

            if( *m_pnBitmapListState != ChangeType::NONE )
            {
                if( *m_pnBitmapListState & ChangeType::CHANGED )
                    m_pBitmapList = static_cast<SvxAreaTabDialog*>( GetParentDialog() )->GetNewBitmapList();

                _nPos = m_pLbBitmap->GetSelectEntryPos();

                m_pLbBitmap->Clear();
                m_pLbBitmap->Fill( m_pBitmapList );
                nCount = m_pLbBitmap->GetEntryCount();
                if( nCount == 0 )
                    ; // This case should never occur
                else if( nCount <= _nPos )
                    m_pLbBitmap->SelectEntryPos( 0 );
                else
                    m_pLbBitmap->SelectEntryPos( _nPos );
            }

            if( *m_pnHatchingListState != ChangeType::NONE )
            {
                if( *m_pnHatchingListState & ChangeType::CHANGED )
                    m_pHatchingList = static_cast<SvxAreaTabDialog*>( GetParentDialog() )->GetNewHatchingList();

                _nPos = m_pLbHatching->GetSelectEntryPos();

                m_pLbHatching->Clear();
                m_pLbHatching->Fill( m_pHatchingList );
                nCount = m_pLbHatching->GetEntryCount();
                if( nCount == 0 )
                    ; // This case should never occur
                else if( nCount <= _nPos )
                    m_pLbHatching->SelectEntryPos( 0 );
                else
                    m_pLbHatching->SelectEntryPos( _nPos );
                ModifyHatchingHdl_Impl( *m_pLbHatching );
            }

            if( *m_pnGradientListState != ChangeType::NONE )
            {
                if( *m_pnGradientListState & ChangeType::CHANGED )
                    m_pGradientList = static_cast<SvxAreaTabDialog*>( GetParentDialog() )->GetNewGradientList();

                _nPos = m_pLbGradient->GetSelectEntryPos();

                m_pLbGradient->Clear();
                m_pLbGradient->Fill( m_pGradientList );
                nCount = m_pLbGradient->GetEntryCount();
                if( nCount == 0 )
                    ; // This case should never occur
                else if( nCount <= _nPos )
                    m_pLbGradient->SelectEntryPos( 0 );
                else
                    m_pLbGradient->SelectEntryPos( _nPos );
                ModifyGradientHdl_Impl( *m_pLbGradient );
            }

            if( *m_pnColorListState != ChangeType::NONE )
            {
                if( *m_pnColorListState & ChangeType::CHANGED )
                    m_pColorList = static_cast<SvxAreaTabDialog*>( GetParentDialog() )->GetNewColorList();
                // aLbColor
                _nPos = m_pLbColor->GetSelectEntryPos();
                m_pLbColor->Clear();
                m_pLbColor->Fill( m_pColorList );
                nCount = m_pLbColor->GetEntryCount();
                if( nCount == 0 )
                    ; // This case should never occur
                else if( nCount <= _nPos )
                    m_pLbColor->SelectEntryPos( 0 );
                else
                    m_pLbColor->SelectEntryPos( _nPos );

                ModifyColorHdl_Impl( *m_pLbColor );
            }

            // evaluate if any other Tabpage set another filltype
            if( m_pTypeLB->GetSelectEntryPos() > drawing::FillStyle_NONE)
            {
                switch( m_nPageType )
                {
                    case PageType::Gradient:
                        m_pTypeLB->SelectEntryPos( drawing::FillStyle_GRADIENT );
                        m_pLbGradient->SelectEntryPos( _nPos );
                        ClickGradientHdl_Impl();
                    break;

                    case PageType::Hatch:
                        m_pTypeLB->SelectEntryPos( drawing::FillStyle_HATCH );
                        m_pLbHatching->SelectEntryPos( _nPos );
                        ClickHatchingHdl_Impl();
                    break;

                    case PageType::Bitmap:
                        m_pTypeLB->SelectEntryPos( drawing::FillStyle_BITMAP );
                        m_pLbBitmap->SelectEntryPos( _nPos );
                        ClickBitmapHdl_Impl();
                    break;

                    case PageType::Color:
                        m_pTypeLB->SelectEntryPos( drawing::FillStyle_SOLID );
                        m_pLbColor->SelectEntryPos( _nPos );
                        ClickColorHdl_Impl();
                    break;
                    default: break;
                }
            }
            m_nPageType = PageType::Area;
        }
    }
}


DeactivateRC SvxAreaTabPage::DeactivatePage( SfxItemSet* _pSet )
{
    if( m_nDlgType == 0 ) // area dialog
    {
        sal_Int32 nPosOrig = m_nPos;
        drawing::FillStyle eStyle = (drawing::FillStyle) m_pTypeLB->GetSelectEntryPos();
        switch( eStyle )
        {
            case drawing::FillStyle_GRADIENT:
            {
                        m_nPageType = PageType::Gradient;
                        m_nPos = m_pLbGradient->GetSelectEntryPos();
                        if( nPosOrig != m_nPos )
                            *m_pnGradientListState |= ChangeType::MODIFIED;
            }
            break;
            case drawing::FillStyle_HATCH:
            {
                m_nPageType = PageType::Hatch;
                m_nPos = m_pLbHatching->GetSelectEntryPos();
                if( nPosOrig != m_nPos )
                    *m_pnHatchingListState |= ChangeType::MODIFIED;
            }
            break;
            case drawing::FillStyle_BITMAP:
            {
                m_nPageType = PageType::Bitmap;
                m_nPos = m_pLbBitmap->GetSelectEntryPos();
                if( nPosOrig != m_nPos )
                    *m_pnBitmapListState |= ChangeType::MODIFIED;
            }
            break;
            case drawing::FillStyle_SOLID:
            {
                m_nPageType = PageType::Color;
                m_nPos = m_pLbColor->GetSelectEntryPos();
                if( nPosOrig != m_nPos )
                    *m_pnColorListState |= ChangeType::MODIFIED;
            }
            break;
            default: ;//prevent warning
        }
    }

    if( _pSet )
        FillItemSet( _pSet );

    return DeactivateRC::LeavePage;
}


bool SvxAreaTabPage::FillItemSet( SfxItemSet* rAttrs )
{
    sal_Int32  _nPos;
    bool    bModified = false;

    if( m_nDlgType != 0 || *m_pbAreaTP )
    {
        const SfxPoolItem* pOld = nullptr;
        drawing::FillStyle eStyle = (drawing::FillStyle) m_pTypeLB->GetSelectEntryPos();
        drawing::FillStyle eSavedStyle = (drawing::FillStyle) m_pTypeLB->GetSavedValue();
        switch( eStyle )
        {
            default:
            case drawing::FillStyle_NONE:
            {
                if(  eSavedStyle != eStyle )
                {
                    XFillStyleItem aStyleItem( drawing::FillStyle_NONE );
                    pOld = GetOldItem( *rAttrs, XATTR_FILLSTYLE );
                    if ( !pOld || !( *static_cast<const XFillStyleItem*>(pOld) == aStyleItem ) )
                    {
                        rAttrs->Put( aStyleItem );
                        bModified = true;
                    }
                }
            }
            break;
            case drawing::FillStyle_SOLID:
            {
                _nPos = m_pLbColor->GetSelectEntryPos();
                 if( _nPos != LISTBOX_ENTRY_NOTFOUND &&
                     m_pLbColor->IsValueChangedFromSaved() )
                 {
                     XFillColorItem aItem( m_pLbColor->GetSelectEntry(),
                                           m_pLbColor->GetSelectEntryColor() );
                     pOld = GetOldItem( *rAttrs, XATTR_FILLCOLOR );
                     if ( !pOld || !( *static_cast<const XFillColorItem*>(pOld) == aItem ) )
                     {
                         rAttrs->Put( aItem );
                         bModified = true;
                     }
                 }
                 // NEW
                 if( (eSavedStyle != eStyle) &&
                     ( bModified ||
                       SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ) ) ) )
                 {
                     XFillStyleItem aStyleItem( drawing::FillStyle_SOLID );
                     pOld = GetOldItem( *rAttrs, XATTR_FILLSTYLE );
                     if ( !pOld || !( *static_cast<const XFillStyleItem*>(pOld) == aStyleItem ) )
                     {
                         rAttrs->Put( aStyleItem );
                         bModified = true;
                     }
                 }
            }
            break;
            case drawing::FillStyle_GRADIENT:
            {
                _nPos = m_pLbGradient->GetSelectEntryPos();
                if( _nPos != LISTBOX_ENTRY_NOTFOUND &&
                    m_pLbGradient->IsValueChangedFromSaved() )
                {
                    XGradient aGradient = m_pGradientList->GetGradient( _nPos )->GetGradient();
                    OUString aString = m_pLbGradient->GetSelectEntry();
                    XFillGradientItem aItem( aString, aGradient );
                    pOld = GetOldItem( *rAttrs, XATTR_FILLGRADIENT );
                    if ( !pOld || !( *static_cast<const XFillGradientItem*>(pOld) == aItem ) )
                    {
                        rAttrs->Put( aItem );
                        bModified = true;
                    }
                }
                // NEW
                if( (eSavedStyle != eStyle) &&
                    ( bModified ||
                      SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ) ) ) )
                {
                    XFillStyleItem aStyleItem( drawing::FillStyle_GRADIENT );
                    pOld = GetOldItem( *rAttrs, XATTR_FILLSTYLE );
                    if ( !pOld || !( *static_cast<const XFillStyleItem*>(pOld) == aStyleItem ) )
                    {
                        rAttrs->Put( aStyleItem );
                        bModified = true;
                    }
                }
            }
            break;
            case drawing::FillStyle_HATCH:
            {
                _nPos = m_pLbHatching->GetSelectEntryPos();
                if( _nPos != LISTBOX_ENTRY_NOTFOUND &&
                   m_pLbHatching->IsValueChangedFromSaved() )
                {
                    XHatch aHatching = m_pHatchingList->GetHatch( _nPos )->GetHatch();
                    OUString aString = m_pLbHatching->GetSelectEntry();
                    XFillHatchItem aItem( aString, aHatching );
                    pOld = GetOldItem( *rAttrs, XATTR_FILLHATCH );
                    if ( !pOld || !( *static_cast<const XFillHatchItem*>(pOld) == aItem ) )
                    {
                        rAttrs->Put( aItem );
                        bModified = true;
                    }
                }
                // NEW
                if( (eSavedStyle != eStyle) &&
                    ( bModified ||
                      SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLHATCH ) ) ) )
                {
                    XFillStyleItem aStyleItem( drawing::FillStyle_HATCH );
                    pOld = GetOldItem( *rAttrs, XATTR_FILLSTYLE );
                    if ( !pOld || !( *static_cast<const XFillStyleItem*>(pOld) == aStyleItem ) )
                    {
                        rAttrs->Put( aStyleItem );
                        bModified = true;
                    }
                }
            }
            break;
            case drawing::FillStyle_BITMAP:
            {
                //UUUU
                m_nPos = m_pLbBitmap->GetSelectEntryPos();
                if( m_nPos != LISTBOX_ENTRY_NOTFOUND &&
                    m_pLbBitmap->IsValueChangedFromSaved() )
                {
                    const XBitmapEntry* pXBitmapEntry = m_pBitmapList->GetBitmap(m_nPos);
                    const OUString aString(m_pLbBitmap->GetSelectEntry());
                    const XFillBitmapItem aFillBitmapItem(aString, pXBitmapEntry->GetGraphicObject());
                    pOld = GetOldItem( *rAttrs, XATTR_FILLBITMAP );
                    if ( !pOld || !( *static_cast<const XFillBitmapItem*>(pOld) == aFillBitmapItem ) )
                    {
                        rAttrs->Put( aFillBitmapItem );
                        bModified = true;
                    }
                }
                // NEW
                if( (eSavedStyle != eStyle) &&
                    ( bModified ||
                      SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLBITMAP ) ) ) )
                {
                        XFillStyleItem aStyleItem( drawing::FillStyle_BITMAP );
                        pOld = GetOldItem( *rAttrs, XATTR_FILLSTYLE );
                        if ( !pOld || !( *static_cast<const XFillStyleItem*>(pOld) == aStyleItem ) )
                        {
                            rAttrs->Put( aStyleItem );
                            bModified = true;
                        }
                }
            }
            break;
        }
        rAttrs->Put (SfxUInt16Item(SID_PAGE_TYPE, (sal_uInt16)m_nPageType));
        rAttrs->Put (SfxUInt16Item(SID_TABPAGE_POS,m_nPos));
    }

    return bModified;
}


void SvxAreaTabPage::Reset( const SfxItemSet* rAttrs )
{
    bool isMissingHatching(false);
    bool isMissingGradient(false);
    bool isMissingBitmap(false);
    drawing::FillStyle eXFS = drawing::FillStyle_NONE;
    if( rAttrs->GetItemState( XATTR_FILLSTYLE ) != SfxItemState::DONTCARE )
    {
        eXFS = (drawing::FillStyle) ( static_cast<const XFillStyleItem&>( rAttrs->
                                Get( GetWhich( XATTR_FILLSTYLE ) ) ).GetValue() );
        m_pTypeLB->SelectEntryPos( sal::static_int_cast< sal_Int32 >( eXFS ) );

        if (SfxItemState::DONTCARE != rAttrs->GetItemState(XATTR_FILLCOLOR))
        {
            XFillColorItem const& rColorItem(static_cast<const XFillColorItem&>(
                                rAttrs->Get(XATTR_FILLCOLOR)) );
            m_pLbColor->SelectEntry( rColorItem.GetColorValue() );
        }

        SfxItemState const eGradState(rAttrs->GetItemState(XATTR_FILLGRADIENT));
        XFillGradientItem const* pGradientItem(nullptr);
        if (SfxItemState::DONTCARE != eGradState)
        {
            pGradientItem = &static_cast<const XFillGradientItem&>(
                                    rAttrs->Get(XATTR_FILLGRADIENT));
            OUString  const aString( pGradientItem->GetName() );
            XGradient const aGradient( pGradientItem->GetGradientValue() );
            m_pLbGradient->SelectEntryByList(m_pGradientList, aString, aGradient);
        }
        if (!m_pLbGradient->GetSelectEntryCount()
            && (SfxItemState::DEFAULT == eGradState
                || (pGradientItem && pGradientItem->GetName().isEmpty())))
        {   // avoid relying on pool default - cannot export that
            m_pLbGradient->SelectEntryPos(0); // anything better than nothing
            isMissingGradient = true;
        }

        SfxItemState const eHatchState(rAttrs->GetItemState(XATTR_FILLHATCH));
        XFillHatchItem const* pHatch(nullptr);
        if (SfxItemState::DONTCARE != eHatchState)
        {
            pHatch = &static_cast<const XFillHatchItem&>(
                                rAttrs->Get(XATTR_FILLHATCH));
            m_pLbHatching->SelectEntry(pHatch->GetName());
        }
        if (!m_pLbHatching->GetSelectEntryCount()
            && (SfxItemState::DEFAULT == eHatchState
                || (pHatch && pHatch->GetName().isEmpty())))
        {   // avoid relying on pool default - cannot export that
            m_pLbHatching->SelectEntryPos(0); // anything better than nothing
            isMissingHatching = true;
        }

        SfxItemState const eBitmapState(rAttrs->GetItemState(XATTR_FILLBITMAP));
        XFillBitmapItem const* pBitmapItem(nullptr);
        if (SfxItemState::DONTCARE != eBitmapState)
        {
            pBitmapItem = &static_cast<const XFillBitmapItem&>(
                            rAttrs->Get(XATTR_FILLBITMAP));
            m_pLbBitmap->SelectEntry(pBitmapItem->GetName());
        }
        if (!m_pLbBitmap->GetSelectEntryCount()
            && (SfxItemState::DEFAULT == eBitmapState
                || (pBitmapItem && pBitmapItem->GetName().isEmpty())))
        {   // avoid relying on pool default - cannot export that
            m_pLbBitmap->SelectEntryPos(0); // anything better than nothing
            isMissingBitmap = true;
        }

        switch( eXFS )
        {
            case drawing::FillStyle_NONE:
                ClickInvisibleHdl_Impl();
            break;

            case drawing::FillStyle_SOLID:
                ClickColorHdl_Impl();
            break;

            case drawing::FillStyle_GRADIENT:
                ClickGradientHdl_Impl();
            break;

            case drawing::FillStyle_HATCH:
                ClickHatchingHdl_Impl();
            break;

            case drawing::FillStyle_BITMAP:
            {
                ClickBitmapHdl_Impl();
            }
            break;

            default:
                assert(false);
            break;
        }
    }
    else
    {
        // make all LBs not accessible
        m_pFillLB->Hide();

        m_pCtlBitmapPreview->Hide();
        m_pLbColor->Disable();
        m_pLbColor->Show();

        // so that Reset() also works correctly with Back
        m_pTypeLB->SetNoSelection();
    }

    if( m_pTypeLB->GetSelectEntryPos() == drawing::FillStyle_BITMAP )
        ClickBitmapHdl_Impl();

    m_pTypeLB->SaveValue();
    if(eXFS == drawing::FillStyle_SOLID)
        m_pLbColor->SaveValue();
    if (!isMissingGradient)
        m_pLbGradient->SaveValue();
    if (!isMissingHatching)
        m_pLbHatching->SaveValue();
    if (!isMissingBitmap)
        m_pLbBitmap->SaveValue();
}

void SvxAreaTabPage::ChangesApplied()
{
    m_pTypeLB->SaveValue();
    m_pLbColor->SaveValue();
    m_pLbGradient->SaveValue();
    m_pLbHatching->SaveValue();
    m_pLbBitmap->SaveValue();
}


VclPtr<SfxTabPage> SvxAreaTabPage::Create( vcl::Window* pWindow,
                                           const SfxItemSet* rAttrs )
{
    return VclPtr<SvxAreaTabPage>::Create( pWindow, *rAttrs );
}


IMPL_LINK_NOARG_TYPED(SvxAreaTabPage, SelectDialogTypeHdl_Impl, ListBox&, void)
{
    switch( (drawing::FillStyle)m_pTypeLB->GetSelectEntryPos() )
    {
        default:
        case drawing::FillStyle_NONE: ClickInvisibleHdl_Impl(); break;
        case drawing::FillStyle_SOLID: ClickColorHdl_Impl(); break;
        case drawing::FillStyle_GRADIENT: ClickGradientHdl_Impl(); break;
        case drawing::FillStyle_HATCH: ClickHatchingHdl_Impl(); break;
        case drawing::FillStyle_BITMAP: ClickBitmapHdl_Impl(); break;
    }
}

void SvxAreaTabPage::ClickInvisibleHdl_Impl()
{
    m_pFillLB->Hide();

    m_pCtlXRectPreview->Hide();
    m_pCtlBitmapPreview->Hide();

    m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
    m_pCtlXRectPreview->SetAttributes( m_aXFillAttr.GetItemSet() );
    m_pCtlBitmapPreview->SetAttributes( m_aXFillAttr.GetItemSet() );

    m_pCtlXRectPreview->Invalidate();
    m_pCtlBitmapPreview->Invalidate();
}


void SvxAreaTabPage::ClickColorHdl_Impl()
{
    m_pFillLB->Show();
    m_pLbColor->Enable();
    m_pLbColor->Show();
    m_pLbGradient->Hide();
    m_pLbHatching->Hide();
    m_pLbBitmap->Hide();
    m_pCtlXRectPreview->Enable();
    m_pCtlXRectPreview->Show();
    m_pCtlBitmapPreview->Hide();

    ModifyColorHdl_Impl( *m_pLbColor );
}


IMPL_LINK_NOARG_TYPED(SvxAreaTabPage, ModifyColorHdl_Impl, ListBox&, void)
{
    const SfxPoolItem* pPoolItem = nullptr;
    sal_Int32 _nPos = m_pLbColor->GetSelectEntryPos();
    if( _nPos != LISTBOX_ENTRY_NOTFOUND )
    {
        m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
        m_rXFSet.Put( XFillColorItem( OUString(), m_pLbColor->GetSelectEntryColor() ) );
    }
    // NEW
    else if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), true, &pPoolItem ) )
    {
        m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
        Color aColor( static_cast<const XFillColorItem*>( pPoolItem )->GetColorValue() );
        m_rXFSet.Put( XFillColorItem( OUString(), aColor ) );
    }
    else
        m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) );

    m_pCtlXRectPreview->SetAttributes( m_aXFillAttr.GetItemSet() );
    m_pCtlXRectPreview->Invalidate();
}


void SvxAreaTabPage::ClickGradientHdl_Impl()
{
    m_pFillLB->Show();
    m_pLbColor->Hide();
    m_pLbGradient->Enable();
    m_pLbGradient->Show();
    m_pLbHatching->Hide();
    m_pLbBitmap->Hide();
    m_pCtlXRectPreview->Enable();
    m_pCtlXRectPreview->Show();
    m_pCtlBitmapPreview->Hide();

    ModifyGradientHdl_Impl( *m_pLbGradient );
}


IMPL_LINK_NOARG_TYPED(SvxAreaTabPage, ModifyGradientHdl_Impl, ListBox&, void)
{
    const SfxPoolItem* pPoolItem = nullptr;
    sal_Int32 _nPos = m_pLbGradient->GetSelectEntryPos();
    if( _nPos != LISTBOX_ENTRY_NOTFOUND )
    {
        // fill ItemSet and pass it on to aCtlXRectPreview
        const XGradientEntry* pEntry = m_pGradientList->GetGradient(_nPos);

        m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_GRADIENT ) );
        m_rXFSet.Put( XFillGradientItem( OUString(), pEntry->GetGradient() ) );
    }
    else if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), true, &pPoolItem ) )
    {
        m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_GRADIENT ) );
        m_rXFSet.Put( XFillGradientItem( OUString(), static_cast<const XFillGradientItem*>( pPoolItem )->GetGradientValue() ) );
    }
    else
        m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) );

    sal_uInt16 nValue = static_cast<const XGradientStepCountItem&>( m_rOutAttrs.Get( XATTR_GRADIENTSTEPCOUNT ) ).GetValue();
    if( nValue == 0 )
        nValue = DEFAULT_GRADIENTSTEP;
    m_rXFSet.Put( XGradientStepCountItem( nValue ) );

    m_pCtlXRectPreview->SetAttributes( m_aXFillAttr.GetItemSet() );
    m_pCtlXRectPreview->Invalidate();
}


void SvxAreaTabPage::ClickHatchingHdl_Impl()
{
    m_pFillLB->Show();
    m_pLbColor->Hide();
    m_pLbGradient->Hide();
    m_pLbHatching->Enable();
    m_pLbHatching->Show();
    m_pLbBitmap->Hide();
    m_pCtlXRectPreview->Enable();
    m_pCtlXRectPreview->Show();
    m_pCtlBitmapPreview->Hide();

    ModifyHatchingHdl_Impl( *m_pLbHatching );
}

IMPL_LINK_NOARG_TYPED(SvxAreaTabPage, ModifyHatchingHdl_Impl, ListBox&, void)
{
    // fill Hatch ItemSet
    const SfxPoolItem* pPoolItem = nullptr;
    sal_Int32 _nPos = m_pLbHatching->GetSelectEntryPos();
    if( _nPos != LISTBOX_ENTRY_NOTFOUND )
    {
        // fill ItemSet and pass it on to aCtlXRectPreview
        const XHatchEntry* pEntry = m_pHatchingList->GetHatch(_nPos);

        m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_HATCH ) );
        m_rXFSet.Put( XFillHatchItem( OUString(), pEntry->GetHatch() ) );
    }
    else if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLHATCH ), true, &pPoolItem ) )
    {
        m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_HATCH ) );
        m_rXFSet.Put( XFillHatchItem( OUString(), static_cast<const XFillHatchItem*>( pPoolItem )->GetHatchValue() ) );
    }
    else
        m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) );

    // fill Hatch background ItemSet
    XFillBackgroundItem aItem(static_cast<const XFillBackgroundItem&>(m_rOutAttrs.Get( XATTR_FILLBACKGROUND )));
    aItem.SetWhich( XATTR_FILLBACKGROUND );
    m_rXFSet.Put ( aItem );
    if(aItem.GetValue())
    {
        if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), true, &pPoolItem ) )
        {
            Color aColor( static_cast<const XFillColorItem*>( pPoolItem )->GetColorValue() );
            m_rXFSet.Put( XFillColorItem( OUString(), aColor ) );
        }
        else
            m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
    }

    m_pCtlXRectPreview->SetAttributes( m_aXFillAttr.GetItemSet() );
    m_pCtlXRectPreview->Invalidate();
}

void SvxAreaTabPage::ClickBitmapHdl_Impl()
{
    m_pFillLB->Show();
    m_pLbColor->Hide();
    m_pLbGradient->Hide();
    m_pLbHatching->Hide();
    m_pLbBitmap->Show();
    m_pCtlBitmapPreview->Enable();
    m_pCtlBitmapPreview->Show();
    m_pCtlXRectPreview->Hide();

    ModifyBitmapHdl_Impl( *m_pLbBitmap );
}


IMPL_LINK_NOARG_TYPED(SvxAreaTabPage, ModifyBitmapHdl_Impl, ListBox&, void)
{
    const SfxPoolItem* pPoolItem = nullptr;
    sal_Int32 _nPos = m_pLbBitmap->GetSelectEntryPos();
    if( _nPos != LISTBOX_ENTRY_NOTFOUND )
    {
        // fill ItemSet and pass it on to aCtlXRectPreview
        const XBitmapEntry* pEntry = m_pBitmapList->GetBitmap(_nPos);

        m_rXFSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP));
        m_rXFSet.Put(XFillBitmapItem(OUString(), pEntry->GetGraphicObject()));
    }
    else if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLBITMAP ), true, &pPoolItem ) )
    {
        m_rXFSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP));
        m_rXFSet.Put(XFillBitmapItem(OUString(), static_cast<const XFillBitmapItem*>(pPoolItem)->GetGraphicObject()));
    }
    else
        m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) );

    m_pCtlBitmapPreview->SetAttributes( m_aXFillAttr.GetItemSet() );
    m_pCtlBitmapPreview->Invalidate();
}

void SvxAreaTabPage::PointChanged( vcl::Window* , RECT_POINT )
{
}

void SvxAreaTabPage::PageCreated(const SfxAllItemSet& aSet)
{
    const SvxColorListItem* pColorListItem = aSet.GetItem<SvxColorListItem>(SID_COLOR_TABLE, false);
    const SvxGradientListItem* pGradientListItem = aSet.GetItem<SvxGradientListItem>(SID_GRADIENT_LIST, false);
    const SvxHatchListItem* pHatchingListItem = aSet.GetItem<SvxHatchListItem>(SID_HATCH_LIST, false);
    const SvxBitmapListItem* pBitmapListItem = aSet.GetItem<SvxBitmapListItem>(SID_BITMAP_LIST, false);
    const SfxUInt16Item* pPageTypeItem = aSet.GetItem<SfxUInt16Item>(SID_PAGE_TYPE, false);
    const SfxUInt16Item* pDlgTypeItem = aSet.GetItem<SfxUInt16Item>(SID_DLG_TYPE, false);
    const SfxUInt16Item* pPosItem = aSet.GetItem<SfxUInt16Item>(SID_TABPAGE_POS, false);

    if (pColorListItem)
        SetColorList(pColorListItem->GetColorList());
    if (pGradientListItem)
        SetGradientList(pGradientListItem->GetGradientList());
    if (pHatchingListItem)
        SetHatchingList(pHatchingListItem->GetHatchList());
    if (pBitmapListItem)
        SetBitmapList(pBitmapListItem->GetBitmapList());
    if (pPageTypeItem)
        SetPageType((PageType) pPageTypeItem->GetValue());
    if (pDlgTypeItem)
        SetDlgType(pDlgTypeItem->GetValue());
    if (pPosItem)
        SetPos(pPosItem->GetValue());

    Construct();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */