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
|
/* -*- 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 <com/sun/star/text/WritingMode.hpp>
#include <vcl/toolbox.hxx>
#include <vcl/virdev.hxx>
#include <svl/itempool.hxx>
#include <svtools/toolbarmenu.hxx>
#include <svtools/popupwindowcontroller.hxx>
#include <svx/fmmodel.hxx>
#include <svx/dialmgr.hxx>
#include <svx/strings.hrc>
#include <svx/svdpage.hxx>
#include <svx/svdobj.hxx>
#include <svx/svdview.hxx>
#include <svx/gallery.hxx>
#include <svx/fontworkgallery.hxx>
#include <algorithm>
#include <memory>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
namespace svx
{
const int nColCount = 4;
const int nLineCount = 4;
FontWorkGalleryDialog::FontWorkGalleryDialog(weld::Window* pParent, SdrView& rSdrView)
: GenericDialogController(pParent, "svx/ui/fontworkgallerydialog.ui", "FontworkGalleryDialog")
, mnThemeId(0xffff)
, mrSdrView(rSdrView)
, mppSdrObject(nullptr)
, mpDestModel(nullptr)
, maCtlFavorites(m_xBuilder->weld_scrolled_window("ctlFavoriteswin"))
, mxCtlFavorites(new weld::CustomWeld(*m_xBuilder, "ctlFavorites", maCtlFavorites))
, mxOKButton(m_xBuilder->weld_button("ok"))
{
Size aSize(maCtlFavorites.GetDrawingArea()->get_ref_device().LogicToPixel(Size(200, 200), MapMode(MapUnit::MapAppFont)));
mxCtlFavorites->set_size_request(aSize.Width(), aSize.Height());
maCtlFavorites.SetDoubleClickHdl( LINK( this, FontWorkGalleryDialog, DoubleClickFavoriteHdl ) );
mxOKButton->connect_clicked(LINK(this, FontWorkGalleryDialog, ClickOKHdl));
maCtlFavorites.SetColCount( nColCount );
maCtlFavorites.SetLineCount( nLineCount );
maCtlFavorites.SetExtraSpacing( 3 );
initFavorites( GALLERY_THEME_FONTWORK );
fillFavorites( GALLERY_THEME_FONTWORK );
}
FontWorkGalleryDialog::~FontWorkGalleryDialog()
{
}
void FontWorkGalleryDialog::initFavorites(sal_uInt16 nThemeId)
{
// the favorites are read via the gallery
sal_uInt32 nFavCount = GalleryExplorer::GetSdrObjCount( nThemeId );
// lock gallery theme
GalleryExplorer::BeginLocking(nThemeId);
sal_uInt32 nModelPos;
FmFormModel *pModel = nullptr;
for( nModelPos = 0; nModelPos < nFavCount; nModelPos++ )
{
BitmapEx aThumb;
if (GalleryExplorer::GetSdrObj(nThemeId, nModelPos, pModel, &aThumb) && !!aThumb)
{
ScopedVclPtrInstance< VirtualDevice > pVDev;
const Point aNull(0, 0);
if (pVDev->GetDPIScaleFactor() > 1)
aThumb.Scale(pVDev->GetDPIScaleFactor(), pVDev->GetDPIScaleFactor());
const Size aSize(aThumb.GetSizePixel());
pVDev->SetOutputSizePixel(aSize);
static const sal_uInt32 nLen(8);
static const Color aW(COL_WHITE);
static const Color aG(0xef, 0xef, 0xef);
pVDev->DrawCheckered(aNull, aSize, nLen, aW, aG);
pVDev->DrawBitmapEx(aNull, aThumb);
maFavoritesHorizontal.emplace_back(pVDev->GetBitmapEx(aNull, aSize));
}
}
// release gallery theme
GalleryExplorer::EndLocking(nThemeId);
}
void FontWorkGalleryDialog::fillFavorites(sal_uInt16 nThemeId)
{
mnThemeId = nThemeId;
Size aThumbSize(maCtlFavorites.GetOutputSizePixel());
aThumbSize.setWidth( aThumbSize.Width() / nColCount );
aThumbSize.setHeight( aThumbSize.Height() / nLineCount );
aThumbSize.AdjustWidth( -12 );
aThumbSize.AdjustHeight( -12 );
auto nFavCount = maFavoritesHorizontal.size();
// ValueSet favorites
if( nFavCount > (nColCount * nLineCount) )
{
WinBits nWinBits = maCtlFavorites.GetStyle();
nWinBits |= WB_VSCROLL;
maCtlFavorites.SetStyle( nWinBits );
}
maCtlFavorites.Clear();
for( size_t nFavorite = 1; nFavorite <= nFavCount; nFavorite++ )
{
OUString aStr = SvxResId(RID_SVXFLOAT3D_FAVORITE) + " " + OUString::number(nFavorite);
Image aThumbImage( maFavoritesHorizontal[nFavorite-1] );
maCtlFavorites.InsertItem( static_cast<sal_uInt16>(nFavorite), aThumbImage, aStr );
}
if (maCtlFavorites.GetItemCount())
maCtlFavorites.SelectItem(1);
}
void FontWorkGalleryDialog::SetSdrObjectRef( SdrObject** ppSdrObject, SdrModel* pModel )
{
mppSdrObject = ppSdrObject;
mpDestModel = pModel;
}
void FontWorkGalleryDialog::insertSelectedFontwork()
{
sal_uInt16 nItemId = maCtlFavorites.GetSelectedItemId();
if( nItemId > 0 )
{
std::unique_ptr<FmFormModel> pModel(new FmFormModel());
pModel->GetItemPool().FreezeIdRanges();
if( GalleryExplorer::GetSdrObj( mnThemeId, nItemId-1, pModel.get() ) )
{
SdrPage* pPage = pModel->GetPage(0);
if( pPage && pPage->GetObjCount() )
{
// tdf#116993 Calc uses a 'special' mode for this dialog in being the
// only caller of ::SetSdrObjectRef. Only in that case mpDestModel seems
// to be the correct target SdrModel.
// If this is not used, the correct SdrModel seems to be the one from
// the mrSdrView that is used to insert (InsertObjectAtView below) the
// cloned SdrObject.
const bool bUseSpecialCalcMode(nullptr != mppSdrObject && nullptr != mpDestModel);
// center shape on current view
OutputDevice* pOutDev(mrSdrView.GetFirstOutputDevice());
if (pOutDev)
{
// Clone directly to target SdrModel (may be different due to user/caller (!))
SdrObject* pNewObject(
pPage->GetObj(0)->CloneSdrObject(
bUseSpecialCalcMode ? *mpDestModel : mrSdrView.getSdrModelFromSdrView()));
pNewObject->MakeNameUnique();
// tdf#117629
// Since the 'old' ::CloneSdrObject also copies the SdrPage* the
// SdrObject::getUnoShape() *will* create the wrong UNO API object
// early. This IS one of the reasons I do change these things - this
// error does not happen with my next change I am working on already
// ARGH! For now, reset the SdrPage* to nullptr.
// What sense does it have to copy the SdrPage* of the original SdrObject ?!?
// TTTT: This also *might* be the hidden reason for the strange code at the
// end of SdrObject::SetPage that tries to delete the SvxShape under some
// circumstances...
// pNewObject->SetPage(nullptr);
tools::Rectangle aObjRect( pNewObject->GetLogicRect() );
tools::Rectangle aVisArea = pOutDev->PixelToLogic(tools::Rectangle(Point(0,0), pOutDev->GetOutputSizePixel()));
Point aPagePos = aVisArea.Center();
aPagePos.AdjustX( -(aObjRect.GetWidth() / 2) );
aPagePos.AdjustY( -(aObjRect.GetHeight() / 2) );
tools::Rectangle aNewObjectRectangle(aPagePos, aObjRect.GetSize());
pNewObject->SetLogicRect(aNewObjectRectangle);
if (bUseSpecialCalcMode)
{
*mppSdrObject = pNewObject;
}
else
{
SdrPageView* pPV(mrSdrView.GetSdrPageView());
if (nullptr != pPV)
{
mrSdrView.InsertObjectAtView( pNewObject, *pPV );
}
else
{
// tdf#116993 no target -> delete clone
SdrObject::Free(pNewObject);
}
}
}
}
}
}
}
IMPL_LINK_NOARG(FontWorkGalleryDialog, ClickOKHdl, weld::Button&, void)
{
insertSelectedFontwork();
m_xDialog->response(RET_OK);
}
IMPL_LINK_NOARG(FontWorkGalleryDialog, DoubleClickFavoriteHdl, ValueSet*, void)
{
insertSelectedFontwork();
m_xDialog->response(RET_OK);
}
namespace {
class FontworkAlignmentWindow final : public WeldToolbarPopup
{
public:
FontworkAlignmentWindow(svt::PopupWindowController* pControl, weld::Widget* pParentWindow);
virtual void GrabFocus() override
{
mxLeft->grab_focus();
}
virtual void statusChanged( const css::frame::FeatureStateEvent& Event ) override;
private:
rtl::Reference<svt::PopupWindowController> mxControl;
std::unique_ptr<weld::RadioButton> mxLeft;
std::unique_ptr<weld::RadioButton> mxCenter;
std::unique_ptr<weld::RadioButton> mxRight;
std::unique_ptr<weld::RadioButton> mxWord;
std::unique_ptr<weld::RadioButton> mxStretch;
bool mbSettingValue;
DECL_LINK( SelectHdl, weld::ToggleButton&, void );
void implSetAlignment( int nAlignmentMode, bool bEnabled );
};
}
static const OUStringLiteral gsFontworkAlignment(".uno:FontworkAlignment");
FontworkAlignmentWindow::FontworkAlignmentWindow(svt::PopupWindowController* pControl, weld::Widget* pParent)
: WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/fontworkalignmentcontrol.ui", "FontworkAlignmentControl")
, mxControl(pControl)
, mxLeft(m_xBuilder->weld_radio_button("left"))
, mxCenter(m_xBuilder->weld_radio_button("center"))
, mxRight(m_xBuilder->weld_radio_button("right"))
, mxWord(m_xBuilder->weld_radio_button("word"))
, mxStretch(m_xBuilder->weld_radio_button("stretch"))
, mbSettingValue(false)
{
mxLeft->connect_toggled(LINK(this, FontworkAlignmentWindow, SelectHdl));
mxCenter->connect_toggled(LINK(this, FontworkAlignmentWindow, SelectHdl));
mxRight->connect_toggled(LINK(this, FontworkAlignmentWindow, SelectHdl));
mxWord->connect_toggled(LINK(this, FontworkAlignmentWindow, SelectHdl));
mxStretch->connect_toggled(LINK(this, FontworkAlignmentWindow, SelectHdl));
AddStatusListener( gsFontworkAlignment );
}
void FontworkAlignmentWindow::implSetAlignment( int nSurface, bool bEnabled )
{
bool bSettingValue = mbSettingValue;
mbSettingValue = true;
mxLeft->set_active(nSurface == 0 && bEnabled);
mxLeft->set_sensitive(bEnabled);
mxCenter->set_active(nSurface == 1 && bEnabled);
mxCenter->set_sensitive(bEnabled);
mxRight->set_active(nSurface == 2 && bEnabled);
mxRight->set_sensitive(bEnabled);
mxWord->set_active(nSurface == 3 && bEnabled);
mxWord->set_sensitive(bEnabled);
mxStretch->set_active(nSurface == 4 && bEnabled);
mxStretch->set_sensitive(bEnabled);
mbSettingValue = bSettingValue;
}
void FontworkAlignmentWindow::statusChanged( const css::frame::FeatureStateEvent& Event )
{
if( Event.FeatureURL.Main == gsFontworkAlignment )
{
if( !Event.IsEnabled )
{
implSetAlignment( 0, false );
}
else
{
sal_Int32 nValue = 0;
if( Event.State >>= nValue )
implSetAlignment( nValue, true );
}
}
}
IMPL_LINK(FontworkAlignmentWindow, SelectHdl, weld::ToggleButton&, rButton, void)
{
if (mbSettingValue || !rButton.get_active())
return;
sal_Int32 nAlignment;
if (mxLeft->get_active())
nAlignment = 0;
else if (mxCenter->get_active())
nAlignment = 1;
else if (mxRight->get_active())
nAlignment = 2;
else if (mxWord->get_active())
nAlignment = 3;
else
nAlignment = 4;
Sequence< PropertyValue > aArgs( 1 );
aArgs[0].Name = OUString(gsFontworkAlignment).copy(5);
aArgs[0].Value <<= nAlignment;
mxControl->dispatchCommand( gsFontworkAlignment, aArgs );
implSetAlignment( nAlignment, true );
mxControl->EndPopupMode();
}
namespace {
class FontworkAlignmentControl : public svt::PopupWindowController
{
public:
explicit FontworkAlignmentControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override;
virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override;
// XInitialization
virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
};
}
FontworkAlignmentControl::FontworkAlignmentControl( const Reference< XComponentContext >& rxContext )
: svt::PopupWindowController( rxContext, Reference< css::frame::XFrame >(), ".uno:FontworkAlignment" )
{
}
std::unique_ptr<WeldToolbarPopup> FontworkAlignmentControl::weldPopupWindow()
{
return std::make_unique<FontworkAlignmentWindow>(this, m_pToolbar);
}
VclPtr<vcl::Window> FontworkAlignmentControl::createVclPopupWindow( vcl::Window* pParent )
{
mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
std::make_unique<FontworkAlignmentWindow>(this, pParent->GetFrameWeld()));
mxInterimPopover->Show();
return mxInterimPopover;
}
// XInitialization
void SAL_CALL FontworkAlignmentControl::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
{
svt::PopupWindowController::initialize( aArguments );
ToolBox* pToolBox = nullptr;
sal_uInt16 nId = 0;
if ( getToolboxId( nId, &pToolBox ) )
pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
}
// XServiceInfo
OUString FontworkAlignmentControl::getImplementationName()
{
return "com.sun.star.comp.svx.FontworkAlignmentController";
}
Sequence< OUString > FontworkAlignmentControl::getSupportedServiceNames()
{
return { "com.sun.star.frame.ToolbarController" };
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
com_sun_star_comp_svx_FontworkAlignmentControl_get_implementation(
css::uno::XComponentContext* xContext,
css::uno::Sequence<css::uno::Any> const &)
{
return cppu::acquire(new FontworkAlignmentControl(xContext));
}
namespace {
class FontworkCharacterSpacingWindow final : public WeldToolbarPopup
{
public:
FontworkCharacterSpacingWindow(svt::PopupWindowController* pControl, weld::Widget* pParentWindow);
virtual void GrabFocus() override;
virtual void statusChanged( const css::frame::FeatureStateEvent& Event ) override;
private:
rtl::Reference<svt::PopupWindowController> mxControl;
std::unique_ptr<weld::RadioButton> mxVeryTight;
std::unique_ptr<weld::RadioButton> mxTight;
std::unique_ptr<weld::RadioButton> mxNormal;
std::unique_ptr<weld::RadioButton> mxLoose;
std::unique_ptr<weld::RadioButton> mxVeryLoose;
std::unique_ptr<weld::RadioButton> mxCustom;
std::unique_ptr<weld::CheckButton> mxKernPairs;
bool mbSettingValue;
DECL_LINK( SelectHdl, weld::ToggleButton&, void );
DECL_LINK( ClickHdl, weld::Button&, void );
void implSetCharacterSpacing( sal_Int32 nCharacterSpacing, bool bEnabled );
void implSetKernCharacterPairs(bool bKernOnOff, bool bEnabled);
};
}
static const OUStringLiteral gsFontworkCharacterSpacing(".uno:FontworkCharacterSpacing");
static const OUStringLiteral gsFontworkKernCharacterPairs(".uno:FontworkKernCharacterPairs");
FontworkCharacterSpacingWindow::FontworkCharacterSpacingWindow(svt::PopupWindowController* pControl, weld::Widget* pParent)
: WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/fontworkcharacterspacingcontrol.ui", "FontworkCharacterSpacingControl")
, mxControl(pControl)
, mxVeryTight(m_xBuilder->weld_radio_button("verytight"))
, mxTight(m_xBuilder->weld_radio_button("tight"))
, mxNormal(m_xBuilder->weld_radio_button("normal"))
, mxLoose(m_xBuilder->weld_radio_button("loose"))
, mxVeryLoose(m_xBuilder->weld_radio_button("veryloose"))
, mxCustom(m_xBuilder->weld_radio_button("custom"))
, mxKernPairs(m_xBuilder->weld_check_button("kernpairs"))
, mbSettingValue(false)
{
mxVeryTight->connect_toggled(LINK(this, FontworkCharacterSpacingWindow, SelectHdl));
mxTight->connect_toggled(LINK(this, FontworkCharacterSpacingWindow, SelectHdl));
mxNormal->connect_toggled(LINK(this, FontworkCharacterSpacingWindow, SelectHdl));
mxLoose->connect_toggled(LINK(this, FontworkCharacterSpacingWindow, SelectHdl));
mxVeryLoose->connect_toggled(LINK(this, FontworkCharacterSpacingWindow, SelectHdl));
mxCustom->connect_clicked(LINK(this, FontworkCharacterSpacingWindow, ClickHdl));
mxKernPairs->connect_toggled(LINK(this, FontworkCharacterSpacingWindow, SelectHdl));
AddStatusListener( gsFontworkCharacterSpacing );
AddStatusListener( gsFontworkKernCharacterPairs );
// See TODO in svx/source/toolbars/fontworkbar.cxx for SID_FONTWORK_KERN_CHARACTER_PAIRS,
// the kernpairs setting is ignored, so hide the widget entirely
mxKernPairs->hide();
}
void FontworkCharacterSpacingWindow::GrabFocus()
{
mxVeryTight->grab_focus();
}
void FontworkCharacterSpacingWindow::implSetCharacterSpacing( sal_Int32 nCharacterSpacing, bool bEnabled )
{
bool bSettingValue = mbSettingValue;
mbSettingValue = true;
mxVeryTight->set_sensitive(bEnabled);
mxTight->set_sensitive(bEnabled);
mxNormal->set_sensitive(bEnabled);
mxLoose->set_sensitive(bEnabled);
mxVeryLoose->set_sensitive(bEnabled);
mxCustom->set_sensitive(bEnabled);
mxVeryTight->set_active(false);
mxTight->set_active(false);
mxNormal->set_active(false);
mxLoose->set_active(false);
mxVeryLoose->set_active(false);
mxCustom->set_active(true);
switch(nCharacterSpacing)
{
case 80:
mxVeryTight->set_active(true);
break;
case 90:
mxTight->set_active(true);
break;
case 100:
mxNormal->set_active(true);
break;
case 120:
mxLoose->set_active(true);
break;
case 150:
mxVeryLoose->set_active(true);
break;
}
mbSettingValue = bSettingValue;
}
void FontworkCharacterSpacingWindow::implSetKernCharacterPairs(bool bKernOnOff, bool bEnabled)
{
mxKernPairs->set_sensitive(bEnabled);
mxKernPairs->set_active(bKernOnOff);
}
void FontworkCharacterSpacingWindow::statusChanged( const css::frame::FeatureStateEvent& Event )
{
if( Event.FeatureURL.Main == gsFontworkCharacterSpacing )
{
if( !Event.IsEnabled )
{
implSetCharacterSpacing( 0, false );
}
else
{
sal_Int32 nValue = 0;
if( Event.State >>= nValue )
implSetCharacterSpacing( nValue, true );
}
}
else if( Event.FeatureURL.Main == gsFontworkKernCharacterPairs )
{
if( !Event.IsEnabled )
{
implSetKernCharacterPairs(false, false);
}
else
{
bool bValue = false;
if( Event.State >>= bValue )
implSetKernCharacterPairs(bValue, true);
}
}
}
IMPL_LINK_NOARG(FontworkCharacterSpacingWindow, ClickHdl, weld::Button&, void)
{
SelectHdl(*mxCustom);
}
IMPL_LINK(FontworkCharacterSpacingWindow, SelectHdl, weld::ToggleButton&, rButton, void)
{
if (mbSettingValue || !rButton.get_active())
return;
if (&rButton == mxCustom.get())
{
Sequence< PropertyValue > aArgs( 1 );
aArgs[0].Name = OUString(gsFontworkCharacterSpacing).copy(5);
aArgs[0].Value <<= sal_Int32(100);
rtl::Reference<svt::PopupWindowController> xControl(mxControl);
xControl->EndPopupMode();
xControl->dispatchCommand(".uno:FontworkCharacterSpacingDialog", aArgs);
}
else if (&rButton == mxKernPairs.get())
{
Sequence< PropertyValue > aArgs( 1 );
aArgs[0].Name = OUString(gsFontworkKernCharacterPairs).copy(5);
bool bKernOnOff = mxKernPairs->get_active();
aArgs[0].Value <<= bKernOnOff;
mxControl->dispatchCommand( gsFontworkKernCharacterPairs, aArgs );
implSetKernCharacterPairs(bKernOnOff, true);
}
else
{
sal_Int32 nCharacterSpacing;
if (&rButton == mxVeryTight.get())
nCharacterSpacing = 80;
else if (&rButton == mxTight.get())
nCharacterSpacing = 90;
else if (&rButton == mxLoose.get())
nCharacterSpacing = 120;
else if (&rButton == mxVeryLoose.get())
nCharacterSpacing = 150;
else
nCharacterSpacing = 100;
Sequence< PropertyValue > aArgs( 1 );
aArgs[0].Name = OUString(gsFontworkCharacterSpacing).copy(5);
aArgs[0].Value <<= nCharacterSpacing;
mxControl->dispatchCommand( gsFontworkCharacterSpacing, aArgs );
implSetCharacterSpacing( nCharacterSpacing, true );
}
mxControl->EndPopupMode();
}
namespace {
class FontworkCharacterSpacingControl : public svt::PopupWindowController
{
public:
explicit FontworkCharacterSpacingControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override;
virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override;
// XInitialization
virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
};
}
FontworkCharacterSpacingControl::FontworkCharacterSpacingControl( const Reference< XComponentContext >& rxContext )
: svt::PopupWindowController( rxContext, Reference< css::frame::XFrame >(), ".uno:FontworkCharacterSpacingFloater" )
{
}
std::unique_ptr<WeldToolbarPopup> FontworkCharacterSpacingControl::weldPopupWindow()
{
return std::make_unique<FontworkCharacterSpacingWindow>(this, m_pToolbar);
}
VclPtr<vcl::Window> FontworkCharacterSpacingControl::createVclPopupWindow( vcl::Window* pParent )
{
mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
std::make_unique<FontworkCharacterSpacingWindow>(this, pParent->GetFrameWeld()));
mxInterimPopover->Show();
return mxInterimPopover;
}
// XInitialization
void SAL_CALL FontworkCharacterSpacingControl::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
{
svt::PopupWindowController::initialize( aArguments );
ToolBox* pToolBox = nullptr;
sal_uInt16 nId = 0;
if ( getToolboxId( nId, &pToolBox ) )
pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
}
// XServiceInfo
OUString FontworkCharacterSpacingControl::getImplementationName()
{
return "com.sun.star.comp.svx.FontworkCharacterSpacingController";
}
Sequence< OUString > FontworkCharacterSpacingControl::getSupportedServiceNames()
{
Sequence<OUString> aSNS { "com.sun.star.frame.ToolbarController" };
return aSNS;
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
com_sun_star_comp_svx_FontworkCharacterSpacingControl_get_implementation(
css::uno::XComponentContext* xContext,
css::uno::Sequence<css::uno::Any> const &)
{
return cppu::acquire(new FontworkCharacterSpacingControl(xContext));
}
FontworkCharacterSpacingDialog::FontworkCharacterSpacingDialog(weld::Window* pParent, sal_Int32 nScale)
: GenericDialogController(pParent, "svx/ui/fontworkspacingdialog.ui", "FontworkSpacingDialog")
, m_xMtrScale(m_xBuilder->weld_metric_spin_button("entry", FieldUnit::PERCENT))
{
m_xMtrScale->set_value(nScale, FieldUnit::PERCENT);
}
FontworkCharacterSpacingDialog::~FontworkCharacterSpacingDialog()
{
}
sal_Int32 FontworkCharacterSpacingDialog::getScale() const
{
return static_cast<sal_Int32>(m_xMtrScale->get_value(FieldUnit::PERCENT));
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|