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
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
|
/* -*- 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 <sfx2/dispatch.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/viewsh.hxx>
#include <rtl/ustring.hxx>
#include <vcl/event.hxx>
#include <vcl/settings.hxx>
#include <vcl/toolbox.hxx>
#include <svx/svxids.hrc>
#define TMP_STR_BEGIN "["
#define TMP_STR_END "]"
#include <svx/drawitem.hxx>
#include <svx/xfillit0.hxx>
#include <svx/xtable.hxx>
#include <svx/fillctrl.hxx>
#include <svx/itemwin.hxx>
#include <svx/xflclit.hxx>
#include <svx/xflgrit.hxx>
#include <svx/xflhtit.hxx>
#include <svx/xbtmpit.hxx>
#include <boost/property_tree/ptree.hpp>
#include <memory>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
SFX_IMPL_TOOLBOX_CONTROL( SvxFillToolBoxControl, XFillStyleItem );
SvxFillToolBoxControl::SvxFillToolBoxControl(
sal_uInt16 nSlotId,
sal_uInt16 nId,
ToolBox& rTbx )
: SfxToolBoxControl( nSlotId, nId, rTbx )
, mpStyleItem()
, mpColorItem()
, mpFillGradientItem()
, mpHatchItem()
, mpBitmapItem()
, mxFillControl(nullptr)
, mpLbFillType(nullptr)
, mpToolBoxColor(nullptr)
, mpLbFillAttr(nullptr)
, meLastXFS(static_cast<drawing::FillStyle>(-1))
, mnLastPosGradient(0)
, mnLastPosHatch(0)
, mnLastPosBitmap(0)
{
addStatusListener( ".uno:FillColor");
addStatusListener( ".uno:FillGradient");
addStatusListener( ".uno:FillHatch");
addStatusListener( ".uno:FillBitmap");
addStatusListener( ".uno:ColorTableState");
addStatusListener( ".uno:GradientListState");
addStatusListener( ".uno:HatchListState");
addStatusListener( ".uno:BitmapListState");
}
SvxFillToolBoxControl::~SvxFillToolBoxControl()
{
}
void SvxFillToolBoxControl::StateChanged(
sal_uInt16 nSID,
SfxItemState eState,
const SfxPoolItem* pState)
{
const bool bDisabled(SfxItemState::DISABLED == eState);
switch(nSID)
{
case SID_ATTR_FILL_STYLE:
{
if(bDisabled)
{
mpLbFillType->set_sensitive(false);
mpLbFillType->set_active(-1);
mpLbFillAttr->show();
mpLbFillAttr->set_sensitive(false);
mpLbFillAttr->set_active(-1);
mpToolBoxColor->hide();
meLastXFS = static_cast<drawing::FillStyle>(-1);
mpStyleItem.reset();
}
if(eState >= SfxItemState::DEFAULT)
{
const XFillStyleItem* pItem = dynamic_cast< const XFillStyleItem* >(pState);
if(pItem)
{
mpStyleItem.reset(pItem->Clone());
mpLbFillType->set_sensitive(true);
drawing::FillStyle eXFS = mpStyleItem->GetValue();
meLastXFS = eXFS;
mpLbFillType->set_active(sal::static_int_cast< sal_Int32 >(eXFS));
if(drawing::FillStyle_NONE == eXFS)
{
mpLbFillAttr->set_active(-1);
mpLbFillAttr->set_sensitive(false);
}
Update();
break;
}
}
mpLbFillType->set_active(-1);
mpLbFillAttr->show();
mpLbFillAttr->set_sensitive(false);
mpLbFillAttr->set_active(-1);
mpToolBoxColor->hide();
meLastXFS = static_cast<drawing::FillStyle>(-1);
mpStyleItem.reset();
mxFillControl->Resize();
break;
}
case SID_ATTR_FILL_COLOR:
{
if(SfxItemState::DEFAULT == eState)
{
mpColorItem.reset(pState ? static_cast<XFillColorItem*>(pState->Clone()) : nullptr);
}
if(mpStyleItem && drawing::FillStyle_SOLID == mpStyleItem->GetValue())
{
mpLbFillAttr->hide();
mpToolBoxColor->show();
mxFillControl->Resize();
Update();
}
break;
}
case SID_ATTR_FILL_GRADIENT:
{
if(SfxItemState::DEFAULT == eState)
{
mpFillGradientItem.reset(pState ? static_cast<XFillGradientItem*>(pState->Clone()) : nullptr);
}
if(mpStyleItem && drawing::FillStyle_GRADIENT == mpStyleItem->GetValue())
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
mxFillControl->Resize();
if(SfxItemState::DEFAULT == eState)
{
mpLbFillAttr->set_sensitive(true);
Update();
}
else if(SfxItemState::DISABLED == eState )
{
mpLbFillAttr->set_sensitive(false);
mpLbFillAttr->set_active(-1);
}
else
{
mpLbFillAttr->set_active(-1);
}
}
break;
}
case SID_ATTR_FILL_HATCH:
{
if(SfxItemState::DEFAULT == eState)
{
mpHatchItem.reset(pState ? static_cast<XFillHatchItem*>(pState->Clone()) : nullptr);
}
if(mpStyleItem && drawing::FillStyle_HATCH == mpStyleItem->GetValue())
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
mxFillControl->Resize();
if(SfxItemState::DEFAULT == eState)
{
mpLbFillAttr->set_sensitive(true);
Update();
}
else if(SfxItemState::DISABLED == eState )
{
mpLbFillAttr->set_sensitive(false);
mpLbFillAttr->set_active(-1);
}
else
{
mpLbFillAttr->set_active(-1);
}
}
break;
}
case SID_ATTR_FILL_BITMAP:
{
if(SfxItemState::DEFAULT == eState)
{
mpBitmapItem.reset(pState ? static_cast<XFillBitmapItem*>(pState->Clone()) : nullptr);
}
if(mpStyleItem && drawing::FillStyle_BITMAP == mpStyleItem->GetValue())
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
mxFillControl->Resize();
if(SfxItemState::DEFAULT == eState)
{
mpLbFillAttr->set_sensitive(true);
Update();
}
else if(SfxItemState::DISABLED == eState )
{
mpLbFillAttr->set_sensitive(false);
mpLbFillAttr->set_active(-1);
}
else
{
mpLbFillAttr->set_active(-1);
}
}
break;
}
case SID_GRADIENT_LIST:
{
if(SfxItemState::DEFAULT == eState)
{
if(mpStyleItem && drawing::FillStyle_GRADIENT == mpStyleItem->GetValue())
{
if(mpFillGradientItem)
{
const OUString aString( mpFillGradientItem->GetName() );
const SfxObjectShell* pSh = SfxObjectShell::Current();
mpLbFillAttr->clear();
mpLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
mpLbFillAttr->set_active_text(aString);
}
else
{
mpLbFillAttr->set_active(-1);
}
}
}
break;
}
case SID_HATCH_LIST:
{
if(SfxItemState::DEFAULT == eState)
{
if(mpStyleItem && drawing::FillStyle_HATCH == mpStyleItem->GetValue())
{
if(mpHatchItem)
{
const OUString aString( mpHatchItem->GetName() );
const SfxObjectShell* pSh = SfxObjectShell::Current();
mpLbFillAttr->clear();
mpLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
mpLbFillAttr->set_active_text(aString);
}
else
{
mpLbFillAttr->set_active(-1);
}
}
}
break;
}
case SID_BITMAP_LIST:
{
if(SfxItemState::DEFAULT == eState)
{
if(mpStyleItem && drawing::FillStyle_BITMAP == mpStyleItem->GetValue())
{
if(mpBitmapItem)
{
const OUString aString( mpBitmapItem->GetName() );
const SfxObjectShell* pSh = SfxObjectShell::Current();
mpLbFillAttr->clear();
mpLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
mpLbFillAttr->set_active_text(aString);
}
else
{
mpLbFillAttr->set_active(-1);
}
}
}
break;
}
}
}
void SvxFillToolBoxControl::Update()
{
if(mpStyleItem)
{
const drawing::FillStyle eXFS = mpStyleItem->GetValue();
SfxObjectShell* pSh = SfxObjectShell::Current();
switch( eXFS )
{
case drawing::FillStyle_NONE:
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
mxFillControl->Resize();
break;
}
case drawing::FillStyle_SOLID:
{
if(mpColorItem)
{
mpLbFillAttr->hide();
mpToolBoxColor->show();
mxFillControl->Resize();
}
break;
}
case drawing::FillStyle_GRADIENT:
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
mxFillControl->Resize();
if(pSh && pSh->GetItem(SID_GRADIENT_LIST))
{
mpLbFillAttr->set_sensitive(true);
mpLbFillAttr->clear();
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
if(mpFillGradientItem)
{
const OUString aString(mpFillGradientItem->GetName());
mpLbFillAttr->set_active_text(aString);
// Check if the entry is not in the list
if (mpLbFillAttr->get_active_text() != aString)
{
sal_Int32 nCount = mpLbFillAttr->get_count();
OUString aTmpStr;
if( nCount > 0 )
{
// Last entry gets tested against temporary entry
aTmpStr = mpLbFillAttr->get_text( nCount - 1 );
if( aTmpStr.startsWith(TMP_STR_BEGIN) &&
aTmpStr.endsWith(TMP_STR_END) )
{
mpLbFillAttr->remove(nCount - 1);
}
}
aTmpStr = TMP_STR_BEGIN + aString + TMP_STR_END;
XGradientList aGradientList( "", ""/*TODO?*/ );
aGradientList.Insert(std::make_unique<XGradientEntry>(mpFillGradientItem->GetGradientValue(), aTmpStr));
aGradientList.SetDirty( false );
const BitmapEx aBmp = aGradientList.GetUiBitmap( 0 );
if (!aBmp.IsEmpty())
{
ScopedVclPtrInstance< VirtualDevice > pVD;
const Size aBmpSize(aBmp.GetSizePixel());
pVD->SetOutputSizePixel(aBmpSize, false);
pVD->DrawBitmapEx(Point(), aBmp);
mpLbFillAttr->append("", aGradientList.Get(0)->GetName(), *pVD);
mpLbFillAttr->set_active(mpLbFillAttr->get_count() - 1);
}
}
}
else
{
mpLbFillAttr->set_active(-1);
}
}
else
{
mpLbFillAttr->set_active(-1);
}
break;
}
case drawing::FillStyle_HATCH:
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
mxFillControl->Resize();
if(pSh && pSh->GetItem(SID_HATCH_LIST))
{
mpLbFillAttr->set_sensitive(true);
mpLbFillAttr->clear();
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
if(mpHatchItem)
{
const OUString aString(mpHatchItem->GetName());
mpLbFillAttr->set_active_text( aString );
// Check if the entry is not in the list
if( mpLbFillAttr->get_active_text() != aString )
{
const sal_Int32 nCount = mpLbFillAttr->get_count();
OUString aTmpStr;
if( nCount > 0 )
{
// Last entry gets tested against temporary entry
aTmpStr = mpLbFillAttr->get_text( nCount - 1 );
if( aTmpStr.startsWith(TMP_STR_BEGIN) &&
aTmpStr.endsWith(TMP_STR_END) )
{
mpLbFillAttr->remove( nCount - 1 );
}
}
aTmpStr = TMP_STR_BEGIN + aString + TMP_STR_END;
XHatchList aHatchList( "", ""/*TODO?*/ );
aHatchList.Insert(std::make_unique<XHatchEntry>(mpHatchItem->GetHatchValue(), aTmpStr));
aHatchList.SetDirty( false );
const BitmapEx & aBmp = aHatchList.GetUiBitmap( 0 );
if( !aBmp.IsEmpty() )
{
ScopedVclPtrInstance< VirtualDevice > pVD;
const Size aBmpSize(aBmp.GetSizePixel());
pVD->SetOutputSizePixel(aBmpSize, false);
pVD->DrawBitmapEx(Point(), aBmp);
mpLbFillAttr->append("", aHatchList.GetHatch(0)->GetName(), *pVD);
mpLbFillAttr->set_active(mpLbFillAttr->get_count() - 1);
}
}
}
else
{
mpLbFillAttr->set_active(-1);
}
}
else
{
mpLbFillAttr->set_active(-1);
}
break;
}
case drawing::FillStyle_BITMAP:
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
mxFillControl->Resize();
if(pSh && pSh->GetItem(SID_BITMAP_LIST))
{
mpLbFillAttr->set_sensitive(true);
mpLbFillAttr->clear();
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
if(mpBitmapItem)
{
const OUString aString(mpBitmapItem->GetName());
mpLbFillAttr->set_active_text(aString);
// Check if the entry is not in the list
if (mpLbFillAttr->get_active_text() != aString)
{
sal_Int32 nCount = mpLbFillAttr->get_count();
OUString aTmpStr;
if( nCount > 0 )
{
// Last entry gets tested against temporary entry
aTmpStr = mpLbFillAttr->get_text(nCount - 1);
if( aTmpStr.startsWith(TMP_STR_BEGIN) &&
aTmpStr.endsWith(TMP_STR_END) )
{
mpLbFillAttr->remove(nCount - 1);
}
}
aTmpStr = TMP_STR_BEGIN + aString + TMP_STR_END;
XBitmapListRef xBitmapList =
XPropertyList::AsBitmapList(
XPropertyList::CreatePropertyList(
XPropertyListType::Bitmap, "TmpList", ""/*TODO?*/));
xBitmapList->Insert(std::make_unique<XBitmapEntry>(mpBitmapItem->GetGraphicObject(), aTmpStr));
xBitmapList->SetDirty( false );
SvxFillAttrBox::Fill(*mpLbFillAttr, xBitmapList);
mpLbFillAttr->set_active(mpLbFillAttr->get_count() - 1);
}
}
else
{
mpLbFillAttr->set_active(-1);
}
}
else
{
mpLbFillAttr->set_active(-1);
}
break;
}
default:
OSL_ENSURE(false, "Non supported FillType (!)");
break;
}
}
}
VclPtr<InterimItemWindow> SvxFillToolBoxControl::CreateItemWindow(vcl::Window *pParent)
{
if(GetSlotId() == SID_ATTR_FILL_STYLE)
{
mxFillControl.reset(VclPtr<FillControl>::Create(pParent, m_xFrame));
mpLbFillType = mxFillControl->mxLbFillType.get();
mpLbFillAttr = mxFillControl->mxLbFillAttr.get();
mpToolBoxColor = mxFillControl->mxToolBoxColor.get();
mpLbFillType->connect_changed(LINK(this,SvxFillToolBoxControl,SelectFillTypeHdl));
mpLbFillAttr->connect_changed(LINK(this,SvxFillToolBoxControl,SelectFillAttrHdl));
return mxFillControl;
}
return VclPtr<InterimItemWindow>();
}
FillControl::FillControl(vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& rFrame)
: InterimItemWindow(pParent, "svx/ui/fillctrlbox.ui", "FillCtrlBox")
, mxLbFillType(m_xBuilder->weld_combo_box("type"))
, mxToolBoxColor(m_xBuilder->weld_toolbar("color"))
, mxColorDispatch(new ToolbarUnoDispatcher(*mxToolBoxColor, *m_xBuilder, rFrame))
, mxLbFillAttr(m_xBuilder->weld_combo_box("attr"))
, mnTypeCurPos(0)
, mnAttrCurPos(0)
{
mxLbFillAttr->connect_key_press(LINK(this, FillControl, AttrKeyInputHdl));
mxLbFillType->connect_key_press(LINK(this, FillControl, TypeKeyInputHdl));
mxToolBoxColor->connect_key_press(LINK(this, FillControl, ColorKeyInputHdl));
mxLbFillType->connect_get_property_tree(LINK(this, FillControl, DumpAsPropertyTreeHdl));
mxLbFillType->connect_focus_in(LINK(this, FillControl, TypeFocusHdl));
mxLbFillAttr->connect_focus_in(LINK(this, FillControl, AttrFocusHdl));
SvxFillTypeBox::Fill(*mxLbFillType);
SetOptimalSize();
}
IMPL_STATIC_LINK(FillControl, DumpAsPropertyTreeHdl, boost::property_tree::ptree&, rTree, void)
{
rTree.put("command", ".uno:FillStyle");
}
void FillControl::ReleaseFocus_Impl()
{
SfxViewShell* pCurSh = SfxViewShell::Current();
if (pCurSh)
{
vcl::Window* pShellWnd = pCurSh->GetWindow();
if (pShellWnd)
pShellWnd->GrabFocus();
}
}
IMPL_LINK(FillControl, TypeKeyInputHdl, const KeyEvent&, rKEvt, bool)
{
const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
sal_uInt16 nCode = rKeyCode.GetCode();
if (nCode == KEY_ESCAPE)
{
mxLbFillType->set_active(mnTypeCurPos);
ReleaseFocus_Impl();
return true;
}
if (nCode != KEY_TAB)
return false;
if (rKeyCode.IsShift())
return ChildKeyInput(rKEvt);
if (mxLbFillAttr->get_visible() && !mxLbFillAttr->get_sensitive())
return ChildKeyInput(rKEvt);
return false;
}
IMPL_LINK_NOARG(FillControl, TypeFocusHdl, weld::Widget&, void)
{
mnTypeCurPos = mxLbFillType->get_active();
}
IMPL_LINK_NOARG(FillControl, AttrFocusHdl, weld::Widget&, void)
{
mnAttrCurPos = mxLbFillAttr->get_active();
}
IMPL_LINK(FillControl, AttrKeyInputHdl, const KeyEvent&, rKEvt, bool)
{
const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
sal_uInt16 nCode = rKeyCode.GetCode();
if (nCode == KEY_ESCAPE)
{
mxLbFillAttr->set_active(mnAttrCurPos);
ReleaseFocus_Impl();
return true;
}
return ChildKeyInput(rKEvt);
}
IMPL_LINK(FillControl, ColorKeyInputHdl, const KeyEvent&, rKEvt, bool)
{
return ChildKeyInput(rKEvt);
}
void FillControl::GetFocus()
{
if (mxLbFillType)
mxLbFillType->grab_focus();
InterimItemWindow::GetFocus();
}
FillControl::~FillControl()
{
disposeOnce();
}
void FillControl::dispose()
{
mxLbFillAttr.reset();
mxColorDispatch.reset();
mxToolBoxColor.reset();
mxLbFillType.reset();
InterimItemWindow::dispose();
}
IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillTypeHdl, weld::ComboBox&, void)
{
const drawing::FillStyle eXFS = static_cast<drawing::FillStyle>(mpLbFillType->get_active());
if(meLastXFS != eXFS)
{
mpLbFillAttr->clear();
SfxObjectShell* pSh = SfxObjectShell::Current();
const XFillStyleItem aXFillStyleItem(eXFS);
// #i122676# Do no longer trigger two Execute calls, one for SID_ATTR_FILL_STYLE
// and one for setting the fill attribute itself, but add two SfxPoolItems to the
// call to get just one action at the SdrObject and to create only one Undo action, too.
// Checked that this works in all apps.
switch( eXFS )
{
default:
case drawing::FillStyle_NONE:
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
mpLbFillAttr->set_sensitive(false);
// #i122676# need to call a single SID_ATTR_FILL_STYLE change
SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
SID_ATTR_FILL_STYLE, SfxCallMode::RECORD,
{ &aXFillStyleItem });
break;
}
case drawing::FillStyle_SOLID:
{
mpLbFillAttr->hide();
mpToolBoxColor->show();
const OUString aTmpStr;
const ::Color aColor = mpColorItem->GetColorValue();
const XFillColorItem aXFillColorItem( aTmpStr, aColor );
// #i122676# change FillStyle and Color in one call
SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
SID_ATTR_FILL_COLOR, SfxCallMode::RECORD,
{ &aXFillColorItem, &aXFillStyleItem });
break;
}
case drawing::FillStyle_GRADIENT:
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
if(pSh && pSh->GetItem(SID_GRADIENT_LIST))
{
if(!mpLbFillAttr->get_count())
{
mpLbFillAttr->set_sensitive(true);
mpLbFillAttr->clear();
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
}
if (mnLastPosGradient != -1)
{
const SvxGradientListItem * pItem = pSh->GetItem(SID_GRADIENT_LIST);
if(mnLastPosGradient < pItem->GetGradientList()->Count())
{
const XGradient aGradient = pItem->GetGradientList()->GetGradient(mnLastPosGradient)->GetGradient();
const XFillGradientItem aXFillGradientItem(mpLbFillAttr->get_text(mnLastPosGradient), aGradient);
// #i122676# change FillStyle and Gradient in one call
SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
SID_ATTR_FILL_GRADIENT, SfxCallMode::RECORD,
{ &aXFillGradientItem, &aXFillStyleItem });
mpLbFillAttr->set_active(mnLastPosGradient);
}
}
}
else
{
mpLbFillAttr->set_sensitive(false);
}
break;
}
case drawing::FillStyle_HATCH:
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
if(pSh && pSh->GetItem(SID_HATCH_LIST))
{
if(!mpLbFillAttr->get_count())
{
mpLbFillAttr->set_sensitive(true);
mpLbFillAttr->clear();
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
}
if (mnLastPosHatch != -1)
{
const SvxHatchListItem * pItem = pSh->GetItem(SID_HATCH_LIST);
if(mnLastPosHatch < pItem->GetHatchList()->Count())
{
const XHatch aHatch = pItem->GetHatchList()->GetHatch(mnLastPosHatch)->GetHatch();
const XFillHatchItem aXFillHatchItem(mpLbFillAttr->get_active_text(), aHatch);
// #i122676# change FillStyle and Hatch in one call
SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
SID_ATTR_FILL_HATCH, SfxCallMode::RECORD,
{ &aXFillHatchItem, &aXFillStyleItem });
mpLbFillAttr->set_active(mnLastPosHatch);
}
}
}
else
{
mpLbFillAttr->set_sensitive(false);
}
break;
}
case drawing::FillStyle_BITMAP:
{
mpLbFillAttr->show();
mpToolBoxColor->hide();
if(pSh && pSh->GetItem(SID_BITMAP_LIST))
{
if(!mpLbFillAttr->get_count())
{
mpLbFillAttr->set_sensitive(true);
mpLbFillAttr->clear();
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
}
if (mnLastPosBitmap != -1)
{
const SvxBitmapListItem * pItem = pSh->GetItem(SID_BITMAP_LIST);
if(mnLastPosBitmap < pItem->GetBitmapList()->Count())
{
const XBitmapEntry* pXBitmapEntry = pItem->GetBitmapList()->GetBitmap(mnLastPosBitmap);
const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->get_active_text(), pXBitmapEntry->GetGraphicObject());
// #i122676# change FillStyle and Bitmap in one call
SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
SID_ATTR_FILL_BITMAP, SfxCallMode::RECORD,
{ &aXFillBitmapItem, &aXFillStyleItem });
mpLbFillAttr->set_active(mnLastPosBitmap);
}
}
}
else
{
mpLbFillAttr->set_sensitive(false);
}
break;
}
}
meLastXFS = eXFS;
mxFillControl->Resize();
}
}
IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillAttrHdl, weld::ComboBox&, void)
{
const drawing::FillStyle eXFS = static_cast<drawing::FillStyle>(mpLbFillType->get_active());
const XFillStyleItem aXFillStyleItem(eXFS);
SfxObjectShell* pSh = SfxObjectShell::Current();
// #i122676# dependent from bFillStyleChange, do execute a single or two
// changes in one Execute call
const bool bFillStyleChange(meLastXFS != eXFS);
switch(eXFS)
{
case drawing::FillStyle_SOLID:
{
if(bFillStyleChange)
{
// #i122676# Single FillStyle change call needed here
SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
SID_ATTR_FILL_STYLE, SfxCallMode::RECORD,
{ &aXFillStyleItem });
}
break;
}
case drawing::FillStyle_GRADIENT:
{
sal_Int32 nPos = mpLbFillAttr->get_active();
if (nPos == -1)
{
nPos = mnLastPosGradient;
}
if (nPos != -1 && pSh && pSh->GetItem(SID_GRADIENT_LIST))
{
const SvxGradientListItem * pItem = pSh->GetItem(SID_GRADIENT_LIST);
if(nPos < pItem->GetGradientList()->Count())
{
const XGradient aGradient = pItem->GetGradientList()->GetGradient(nPos)->GetGradient();
const XFillGradientItem aXFillGradientItem(mpLbFillAttr->get_active_text(), aGradient);
// #i122676# Change FillStyle and Gradient in one call
SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
SID_ATTR_FILL_GRADIENT, SfxCallMode::RECORD,
bFillStyleChange
? std::initializer_list<SfxPoolItem const*>{ &aXFillGradientItem, &aXFillStyleItem }
: std::initializer_list<SfxPoolItem const*>{ &aXFillGradientItem });
}
}
if (nPos != -1)
{
mnLastPosGradient = nPos;
}
break;
}
case drawing::FillStyle_HATCH:
{
sal_Int32 nPos = mpLbFillAttr->get_active();
if (nPos == -1)
{
nPos = mnLastPosHatch;
}
if (nPos != -1 && pSh && pSh->GetItem(SID_HATCH_LIST))
{
const SvxHatchListItem * pItem = pSh->GetItem(SID_HATCH_LIST);
if(nPos < pItem->GetHatchList()->Count())
{
const XHatch aHatch = pItem->GetHatchList()->GetHatch(nPos)->GetHatch();
const XFillHatchItem aXFillHatchItem( mpLbFillAttr->get_active_text(), aHatch);
// #i122676# Change FillStyle and Hatch in one call
SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
SID_ATTR_FILL_HATCH, SfxCallMode::RECORD,
bFillStyleChange
? std::initializer_list<SfxPoolItem const*>{ &aXFillHatchItem, &aXFillStyleItem }
: std::initializer_list<SfxPoolItem const*>{ &aXFillHatchItem });
}
}
if (nPos != -1)
{
mnLastPosHatch = nPos;
}
break;
}
case drawing::FillStyle_BITMAP:
{
sal_Int32 nPos = mpLbFillAttr->get_active();
if (nPos == -1)
{
nPos = mnLastPosBitmap;
}
if (nPos != -1 && pSh && pSh->GetItem(SID_BITMAP_LIST))
{
const SvxBitmapListItem * pItem = pSh->GetItem(SID_BITMAP_LIST);
if(nPos < pItem->GetBitmapList()->Count())
{
const XBitmapEntry* pXBitmapEntry = pItem->GetBitmapList()->GetBitmap(nPos);
const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->get_active_text(), pXBitmapEntry->GetGraphicObject());
// #i122676# Change FillStyle and Bitmap in one call
SfxViewFrame::Current()->GetDispatcher()->ExecuteList(
SID_ATTR_FILL_BITMAP, SfxCallMode::RECORD,
bFillStyleChange
? std::initializer_list<SfxPoolItem const*>{ &aXFillBitmapItem, &aXFillStyleItem }
: std::initializer_list<SfxPoolItem const*>{ &aXFillBitmapItem });
}
}
if (nPos != -1)
{
mnLastPosBitmap = nPos;
}
break;
}
default: break;
}
}
void FillControl::SetOptimalSize()
{
Size aSize(mxLbFillType->get_preferred_size());
Size aFirstSize(mxToolBoxColor->get_preferred_size());
auto nWidth = std::max(aFirstSize.Width(), LogicToPixel(Size(55, 0), MapMode(MapUnit::MapAppFont)).Width());
auto nHeight = std::max(aSize.Height(), aFirstSize.Height());
mxToolBoxColor->set_size_request(nWidth, -1);
mxLbFillAttr->set_size_request(42, -1); //something narrow so the toolbar sets the overall size of this column
SetSizePixel(Size(m_xContainer->get_preferred_size().Width(), nHeight));
}
void FillControl::DataChanged(const DataChangedEvent& rDCEvt)
{
if((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
(rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
{
SetOptimalSize();
}
InterimItemWindow::DataChanged(rDCEvt);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|