1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/dispatchcommand.hxx>
21 #include <officecfg/Office/Common.hxx>
22 #include <charmapcontrol.hxx>
23 #include <sfx2/charmappopup.hxx>
24 #include <sfx2/viewfrm.hxx>
28 SfxCharmapCtrl::SfxCharmapCtrl(CharmapPopup
* pControl
, weld::Widget
* pParent
)
29 : WeldToolbarPopup(pControl
->getFrameInterface(), pParent
, "sfx/ui/charmapcontrol.ui", "charmapctrl")
30 , m_xControl(pControl
)
31 , m_xVirDev(VclPtr
<VirtualDevice
>::Create())
32 , m_aRecentCharView
{SvxCharView(m_xVirDev
),
33 SvxCharView(m_xVirDev
),
34 SvxCharView(m_xVirDev
),
35 SvxCharView(m_xVirDev
),
36 SvxCharView(m_xVirDev
),
37 SvxCharView(m_xVirDev
),
38 SvxCharView(m_xVirDev
),
39 SvxCharView(m_xVirDev
),
40 SvxCharView(m_xVirDev
),
41 SvxCharView(m_xVirDev
),
42 SvxCharView(m_xVirDev
),
43 SvxCharView(m_xVirDev
),
44 SvxCharView(m_xVirDev
),
45 SvxCharView(m_xVirDev
),
46 SvxCharView(m_xVirDev
),
47 SvxCharView(m_xVirDev
)}
48 , m_aFavCharView
{SvxCharView(m_xVirDev
),
49 SvxCharView(m_xVirDev
),
50 SvxCharView(m_xVirDev
),
51 SvxCharView(m_xVirDev
),
52 SvxCharView(m_xVirDev
),
53 SvxCharView(m_xVirDev
),
54 SvxCharView(m_xVirDev
),
55 SvxCharView(m_xVirDev
),
56 SvxCharView(m_xVirDev
),
57 SvxCharView(m_xVirDev
),
58 SvxCharView(m_xVirDev
),
59 SvxCharView(m_xVirDev
),
60 SvxCharView(m_xVirDev
),
61 SvxCharView(m_xVirDev
),
62 SvxCharView(m_xVirDev
),
63 SvxCharView(m_xVirDev
)}
64 , m_xDlgBtn(m_xBuilder
->weld_button("specialchardlg"))
65 , m_xRecentCharView
{std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar1", m_aRecentCharView
[0]),
66 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar2", m_aRecentCharView
[1]),
67 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar3", m_aRecentCharView
[2]),
68 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar4", m_aRecentCharView
[3]),
69 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar5", m_aRecentCharView
[4]),
70 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar6", m_aRecentCharView
[5]),
71 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar7", m_aRecentCharView
[6]),
72 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar8", m_aRecentCharView
[7]),
73 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar9", m_aRecentCharView
[8]),
74 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar10", m_aRecentCharView
[9]),
75 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar11", m_aRecentCharView
[10]),
76 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar12", m_aRecentCharView
[11]),
77 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar13", m_aRecentCharView
[12]),
78 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar14", m_aRecentCharView
[13]),
79 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar15", m_aRecentCharView
[14]),
80 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "viewchar16", m_aRecentCharView
[15])}
81 , m_xFavCharView
{std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar1", m_aFavCharView
[0]),
82 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar2", m_aFavCharView
[1]),
83 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar3", m_aFavCharView
[2]),
84 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar4", m_aFavCharView
[3]),
85 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar5", m_aFavCharView
[4]),
86 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar6", m_aFavCharView
[5]),
87 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar7", m_aFavCharView
[6]),
88 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar8", m_aFavCharView
[7]),
89 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar9", m_aFavCharView
[8]),
90 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar10", m_aFavCharView
[9]),
91 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar11", m_aFavCharView
[10]),
92 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar12", m_aFavCharView
[11]),
93 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar13", m_aFavCharView
[12]),
94 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar14", m_aFavCharView
[13]),
95 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar15", m_aFavCharView
[14]),
96 std::make_unique
<weld::CustomWeld
>(*m_xBuilder
, "favchar16", m_aFavCharView
[15])}
98 for(int i
= 0; i
< 16; i
++)
100 m_aRecentCharView
[i
].setMouseClickHdl(LINK(this,SfxCharmapCtrl
, CharClickHdl
));
101 m_aFavCharView
[i
].setMouseClickHdl(LINK(this,SfxCharmapCtrl
, CharClickHdl
));
104 m_xDlgBtn
->connect_clicked(LINK(this, SfxCharmapCtrl
, OpenDlgHdl
));
106 getRecentCharacterList();
107 updateRecentCharControl();
108 getFavCharacterList();
109 updateFavCharControl();
112 SfxCharmapCtrl::~SfxCharmapCtrl()
116 void SfxCharmapCtrl::getFavCharacterList()
118 //retrieve recent character list
119 css::uno::Sequence
< OUString
> rFavCharList( officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterList::get() );
120 m_aFavCharList
.insert( m_aFavCharList
.end(), rFavCharList
.begin(), rFavCharList
.end() );
122 //retrieve recent character font list
123 css::uno::Sequence
< OUString
> rFavCharFontList( officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterFontList::get() );
124 m_aFavCharFontList
.insert( m_aFavCharFontList
.end(), rFavCharFontList
.begin(), rFavCharFontList
.end() );
126 // tdf#135997: make sure that the two lists are same length
127 const auto nCommonLength
= std::min(m_aFavCharList
.size(), m_aFavCharFontList
.size());
128 m_aFavCharList
.resize(nCommonLength
);
129 m_aFavCharFontList
.resize(nCommonLength
);
132 void SfxCharmapCtrl::updateFavCharControl()
134 assert(m_aFavCharList
.size() == m_aFavCharFontList
.size());
137 for ( std::deque
< OUString
>::iterator it
= m_aFavCharList
.begin(), it2
= m_aFavCharFontList
.begin();
138 it
!= m_aFavCharList
.end() && it2
!= m_aFavCharFontList
.end();
141 m_aFavCharView
[i
].SetText(*it
);
142 vcl::Font rFont
= m_aFavCharView
[i
].GetFont();
143 rFont
.SetFamilyName( *it2
);
144 m_aFavCharView
[i
].SetFont(rFont
);
145 m_aFavCharView
[i
].Show();
150 m_aFavCharView
[i
].SetText(OUString());
151 m_aFavCharView
[i
].Hide();
155 void SfxCharmapCtrl::getRecentCharacterList()
157 //retrieve recent character list
158 css::uno::Sequence
< OUString
> rRecentCharList( officecfg::Office::Common::RecentCharacters::RecentCharacterList::get() );
159 m_aRecentCharList
.insert( m_aRecentCharList
.end(), rRecentCharList
.begin(), rRecentCharList
.end() );
161 //retrieve recent character font list
162 css::uno::Sequence
< OUString
> rRecentCharFontList( officecfg::Office::Common::RecentCharacters::RecentCharacterFontList::get() );
163 m_aRecentCharFontList
.insert( m_aRecentCharFontList
.end(), rRecentCharFontList
.begin(), rRecentCharFontList
.end() );
165 // tdf#135997: make sure that the two lists are same length
166 const auto nCommonLength
= std::min(m_aRecentCharList
.size(), m_aRecentCharFontList
.size());
167 m_aRecentCharList
.resize(nCommonLength
);
168 m_aRecentCharFontList
.resize(nCommonLength
);
171 void SfxCharmapCtrl::updateRecentCharControl()
173 assert(m_aRecentCharList
.size() == m_aRecentCharFontList
.size());
175 for ( std::deque
< OUString
>::iterator it
= m_aRecentCharList
.begin(), it2
= m_aRecentCharFontList
.begin();
176 it
!= m_aRecentCharList
.end() && it2
!= m_aRecentCharFontList
.end();
179 m_aRecentCharView
[i
].SetText(*it
);
180 vcl::Font rFont
= m_aRecentCharView
[i
].GetFont();
181 rFont
.SetFamilyName( *it2
);
182 m_aRecentCharView
[i
].SetFont(rFont
);
183 m_aRecentCharView
[i
].Show();
188 m_aRecentCharView
[i
].SetText(OUString());
189 m_aRecentCharView
[i
].Hide();
193 IMPL_LINK(SfxCharmapCtrl
, CharClickHdl
, SvxCharView
*, pView
, void)
195 m_xControl
->EndPopupMode();
197 pView
->InsertCharToDoc();
200 IMPL_LINK_NOARG(SfxCharmapCtrl
, OpenDlgHdl
, weld::Button
&, void)
202 m_xControl
->EndPopupMode();
204 uno::Reference
<frame::XFrame
> xFrame
= SfxViewFrame::Current()->GetFrame().GetFrameInterface();
205 comphelper::dispatchCommand(".uno:InsertSymbol", xFrame
, {});
208 void SfxCharmapCtrl::GrabFocus()
210 m_aFavCharView
[0].GrabFocus();
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */