File: | home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx |
Warning: | line 1624, column 26 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | |||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | |||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | |||
12 | * contributor license agreements. See the NOTICE file distributed | |||
13 | * with this work for additional information regarding copyright | |||
14 | * ownership. The ASF licenses this file to you under the Apache | |||
15 | * License, Version 2.0 (the "License"); you may not use this file | |||
16 | * except in compliance with the License. You may obtain a copy of | |||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | |||
18 | */ | |||
19 | ||||
20 | #include <vcl/svapp.hxx> | |||
21 | #include <vcl/idle.hxx> | |||
22 | #include <svtools/ctrltool.hxx> | |||
23 | #include <sfx2/objsh.hxx> | |||
24 | #include <svx/svxids.hrc> | |||
25 | #include <svtools/unitconv.hxx> | |||
26 | #include <svl/languageoptions.hxx> | |||
27 | #include <chardlg.hxx> | |||
28 | #include <editeng/fontitem.hxx> | |||
29 | #include <editeng/postitem.hxx> | |||
30 | #include <editeng/udlnitem.hxx> | |||
31 | #include <editeng/crossedoutitem.hxx> | |||
32 | #include <editeng/contouritem.hxx> | |||
33 | #include <editeng/langitem.hxx> | |||
34 | #include <editeng/wghtitem.hxx> | |||
35 | #include <editeng/fhgtitem.hxx> | |||
36 | #include <editeng/shdditem.hxx> | |||
37 | #include <editeng/escapementitem.hxx> | |||
38 | #include <editeng/wrlmitem.hxx> | |||
39 | #include <editeng/cmapitem.hxx> | |||
40 | #include <editeng/kernitem.hxx> | |||
41 | #include <editeng/blinkitem.hxx> | |||
42 | #include <editeng/flstitem.hxx> | |||
43 | #include <editeng/autokernitem.hxx> | |||
44 | #include <editeng/colritem.hxx> | |||
45 | #include <dialmgr.hxx> | |||
46 | #include <sfx2/htmlmode.hxx> | |||
47 | #include <cui/cuicharmap.hxx> | |||
48 | #include "chardlg.h" | |||
49 | #include <editeng/emphasismarkitem.hxx> | |||
50 | #include <editeng/charreliefitem.hxx> | |||
51 | #include <editeng/twolinesitem.hxx> | |||
52 | #include <editeng/charhiddenitem.hxx> | |||
53 | #include <editeng/charscaleitem.hxx> | |||
54 | #include <editeng/charrotateitem.hxx> | |||
55 | #include <officecfg/Office/Common.hxx> | |||
56 | #include <strings.hrc> | |||
57 | #include <twolines.hrc> | |||
58 | #include <svl/intitem.hxx> | |||
59 | #include <svx/flagsdef.hxx> | |||
60 | #include <FontFeaturesDialog.hxx> | |||
61 | #include <sal/log.hxx> | |||
62 | #include <osl/diagnose.h> | |||
63 | ||||
64 | using namespace ::com::sun::star; | |||
65 | ||||
66 | // static ---------------------------------------------------------------- | |||
67 | ||||
68 | const sal_uInt16 SvxCharNamePage::pNameRanges[] = | |||
69 | { | |||
70 | SID_ATTR_CHAR_FONT( 10000 + 7 ), | |||
71 | SID_ATTR_CHAR_WEIGHT( 10000 + 9 ), | |||
72 | SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ), | |||
73 | SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ), | |||
74 | SID_ATTR_CHAR_COLOR( 10000 + 17 ), | |||
75 | SID_ATTR_CHAR_COLOR( 10000 + 17 ), | |||
76 | SID_ATTR_CHAR_LANGUAGE( 10000 + 20 ), | |||
77 | SID_ATTR_CHAR_LANGUAGE( 10000 + 20 ), | |||
78 | SID_ATTR_CHAR_CJK_FONT( 10000 + 887 ), | |||
79 | SID_ATTR_CHAR_CJK_WEIGHT( 10000 + 891 ), | |||
80 | SID_ATTR_CHAR_CTL_FONT( 10000 + 892 ), | |||
81 | SID_ATTR_CHAR_CTL_WEIGHT( 10000 + 896 ), | |||
82 | 0 | |||
83 | }; | |||
84 | ||||
85 | const sal_uInt16 SvxCharEffectsPage::pEffectsRanges[] = | |||
86 | { | |||
87 | SID_ATTR_CHAR_SHADOWED( 10000 + 10 ), | |||
88 | SID_ATTR_CHAR_UNDERLINE( 10000 + 14 ), | |||
89 | SID_ATTR_CHAR_COLOR( 10000 + 17 ), | |||
90 | SID_ATTR_CHAR_COLOR( 10000 + 17 ), | |||
91 | SID_ATTR_CHAR_CASEMAP( 10000 + 19 ), | |||
92 | SID_ATTR_CHAR_CASEMAP( 10000 + 19 ), | |||
93 | SID_ATTR_FLASH( 10000 + 406 ), | |||
94 | SID_ATTR_FLASH( 10000 + 406 ), | |||
95 | SID_ATTR_CHAR_EMPHASISMARK( 10000 + 899 ), | |||
96 | SID_ATTR_CHAR_EMPHASISMARK( 10000 + 899 ), | |||
97 | SID_ATTR_CHAR_RELIEF( 10000 + 920 ), | |||
98 | SID_ATTR_CHAR_RELIEF( 10000 + 920 ), | |||
99 | SID_ATTR_CHAR_HIDDEN( 10000 + 989 ), | |||
100 | SID_ATTR_CHAR_HIDDEN( 10000 + 989 ), | |||
101 | SID_ATTR_CHAR_OVERLINE( ((10000 + 1499) + 1) + 68 ), | |||
102 | SID_ATTR_CHAR_OVERLINE( ((10000 + 1499) + 1) + 68 ), | |||
103 | 0 | |||
104 | }; | |||
105 | ||||
106 | const sal_uInt16 SvxCharPositionPage::pPositionRanges[] = | |||
107 | { | |||
108 | SID_ATTR_CHAR_KERNING( 10000 + 18 ), | |||
109 | SID_ATTR_CHAR_KERNING( 10000 + 18 ), | |||
110 | SID_ATTR_CHAR_ESCAPEMENT( 10000 + 21 ), | |||
111 | SID_ATTR_CHAR_ESCAPEMENT( 10000 + 21 ), | |||
112 | SID_ATTR_CHAR_AUTOKERN( 10000 + 67 ), | |||
113 | SID_ATTR_CHAR_AUTOKERN( 10000 + 67 ), | |||
114 | SID_ATTR_CHAR_ROTATED( 10000 + 910 ), | |||
115 | SID_ATTR_CHAR_SCALEWIDTH( 10000 + 911 ), | |||
116 | SID_ATTR_CHAR_WIDTH_FIT_TO_LINE( 10000 + 919 ), | |||
117 | SID_ATTR_CHAR_WIDTH_FIT_TO_LINE( 10000 + 919 ), | |||
118 | 0 | |||
119 | }; | |||
120 | ||||
121 | const sal_uInt16 SvxCharTwoLinesPage::pTwoLinesRanges[] = | |||
122 | { | |||
123 | SID_ATTR_CHAR_TWO_LINES( 10000 + 897 ), | |||
124 | SID_ATTR_CHAR_TWO_LINES( 10000 + 897 ), | |||
125 | 0 | |||
126 | }; | |||
127 | ||||
128 | // C-Function ------------------------------------------------------------ | |||
129 | ||||
130 | static bool StateToAttr( TriState aState ) | |||
131 | { | |||
132 | return ( TRISTATE_TRUE == aState ); | |||
133 | } | |||
134 | ||||
135 | namespace | |||
136 | { | |||
137 | void setPrevFontEscapement(SvxFont& _rFont,sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc ) | |||
138 | { | |||
139 | _rFont.SetPropr( nProp ); | |||
140 | _rFont.SetProprRel( nEscProp ); | |||
141 | _rFont.SetEscapement( nEsc ); | |||
142 | } | |||
143 | } | |||
144 | ||||
145 | inline SvxFont& SvxCharBasePage::GetPreviewFont() | |||
146 | { | |||
147 | return m_aPreviewWin.GetFont(); | |||
148 | } | |||
149 | ||||
150 | inline SvxFont& SvxCharBasePage::GetPreviewCJKFont() | |||
151 | { | |||
152 | return m_aPreviewWin.GetCJKFont(); | |||
153 | } | |||
154 | ||||
155 | inline SvxFont& SvxCharBasePage::GetPreviewCTLFont() | |||
156 | { | |||
157 | return m_aPreviewWin.GetCTLFont(); | |||
158 | } | |||
159 | ||||
160 | SvxCharBasePage::SvxCharBasePage(weld::Container* pPage, weld::DialogController* pController, const OUString& rUIXMLDescription, const OString& rID, const SfxItemSet& rItemset) | |||
161 | : SfxTabPage(pPage, pController, rUIXMLDescription, rID, &rItemset) | |||
162 | , m_bPreviewBackgroundToCharacter( false ) | |||
163 | { | |||
164 | } | |||
165 | ||||
166 | SvxCharBasePage::~SvxCharBasePage() | |||
167 | { | |||
168 | } | |||
169 | ||||
170 | void SvxCharBasePage::ActivatePage(const SfxItemSet& rSet) | |||
171 | { | |||
172 | m_aPreviewWin.SetFromItemSet(rSet, m_bPreviewBackgroundToCharacter); | |||
173 | } | |||
174 | ||||
175 | void SvxCharBasePage::SetPrevFontWidthScale( const SfxItemSet& rSet ) | |||
176 | { | |||
177 | sal_uInt16 nWhich = GetWhich( SID_ATTR_CHAR_SCALEWIDTH( 10000 + 911 ) ); | |||
178 | if (rSet.GetItemState(nWhich)>=SfxItemState::DEFAULT) | |||
179 | { | |||
180 | const SvxCharScaleWidthItem &rItem = static_cast<const SvxCharScaleWidthItem&>( rSet.Get( nWhich ) ); | |||
181 | m_aPreviewWin.SetFontWidthScale(rItem.GetValue()); | |||
182 | } | |||
183 | } | |||
184 | ||||
185 | void SvxCharBasePage::SetPrevFontEscapement( sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc ) | |||
186 | { | |||
187 | setPrevFontEscapement(GetPreviewFont(),nProp,nEscProp,nEsc); | |||
188 | setPrevFontEscapement(GetPreviewCJKFont(),nProp,nEscProp,nEsc); | |||
189 | setPrevFontEscapement(GetPreviewCTLFont(),nProp,nEscProp,nEsc); | |||
190 | m_aPreviewWin.Invalidate(); | |||
191 | } | |||
192 | ||||
193 | ||||
194 | // SvxCharNamePage_Impl -------------------------------------------------- | |||
195 | ||||
196 | struct SvxCharNamePage_Impl | |||
197 | { | |||
198 | Idle m_aUpdateIdle; | |||
199 | OUString m_aNoStyleText; | |||
200 | std::unique_ptr<FontList> m_pFontList; | |||
201 | int m_nExtraEntryPos; | |||
202 | bool m_bInSearchMode; | |||
203 | ||||
204 | SvxCharNamePage_Impl() | |||
205 | : m_nExtraEntryPos(std::numeric_limits<int>::max()) | |||
206 | , m_bInSearchMode(false) | |||
207 | ||||
208 | { | |||
209 | m_aUpdateIdle.SetPriority( TaskPriority::LOWEST ); | |||
210 | } | |||
211 | }; | |||
212 | ||||
213 | // class SvxCharNamePage ------------------------------------------------- | |||
214 | ||||
215 | SvxCharNamePage::SvxCharNamePage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInSet) | |||
216 | : SvxCharBasePage(pPage, pController, "cui/ui/charnamepage.ui", "CharNamePage", rInSet) | |||
217 | , m_pImpl(new SvxCharNamePage_Impl) | |||
218 | , m_xEastFrame(m_xBuilder->weld_widget("asian")) | |||
219 | , m_xEastFontNameFT(m_xBuilder->weld_label("eastfontnameft")) | |||
220 | , m_xEastFontNameLB(m_xBuilder->weld_combo_box("eastfontnamelb")) | |||
221 | , m_xEastFontStyleFT(m_xBuilder->weld_label("eaststyleft")) | |||
222 | , m_xEastFontStyleLB(new FontStyleBox(m_xBuilder->weld_combo_box("eaststylelb"))) | |||
223 | , m_xEastFontSizeFT(m_xBuilder->weld_label("eastsizeft")) | |||
224 | , m_xEastFontSizeLB(new FontSizeBox(m_xBuilder->weld_combo_box("eastsizelb"))) | |||
225 | , m_xEastFontLanguageFT(m_xBuilder->weld_label("eastlangft")) | |||
226 | , m_xEastFontLanguageLB(new SvxLanguageBox(m_xBuilder->weld_combo_box("eastlanglb"))) | |||
227 | , m_xEastFontTypeFT(m_xBuilder->weld_label("eastfontinfo")) | |||
228 | , m_xEastFontFeaturesButton(m_xBuilder->weld_button("east_features_button")) | |||
229 | , m_xCTLFrame(m_xBuilder->weld_widget("ctl")) | |||
230 | , m_xCTLFontNameFT(m_xBuilder->weld_label("ctlfontnameft")) | |||
231 | , m_xCTLFontNameLB(m_xBuilder->weld_combo_box("ctlfontnamelb")) | |||
232 | , m_xCTLFontStyleFT(m_xBuilder->weld_label("ctlstyleft")) | |||
233 | , m_xCTLFontStyleLB(new FontStyleBox(m_xBuilder->weld_combo_box("ctlstylelb"))) | |||
234 | , m_xCTLFontSizeFT(m_xBuilder->weld_label("ctlsizeft")) | |||
235 | , m_xCTLFontSizeLB(new FontSizeBox(m_xBuilder->weld_combo_box("ctlsizelb"))) | |||
236 | , m_xCTLFontLanguageFT(m_xBuilder->weld_label("ctllangft")) | |||
237 | , m_xCTLFontLanguageLB(new SvxLanguageBox(m_xBuilder->weld_combo_box("ctllanglb"))) | |||
238 | , m_xCTLFontTypeFT(m_xBuilder->weld_label("ctlfontinfo")) | |||
239 | , m_xCTLFontFeaturesButton(m_xBuilder->weld_button("ctl_features_button")) | |||
240 | { | |||
241 | m_xPreviewWin.reset(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWin)); | |||
242 | #ifdef IOS | |||
243 | m_xPreviewWin->hide(); | |||
244 | #endif | |||
245 | m_pImpl->m_aNoStyleText = CuiResId( RID_SVXSTR_CHARNAME_NOSTYLEreinterpret_cast<char const *>("RID_SVXSTR_CHARNAME_NOSTYLE" "\004" u8"No %1") ); | |||
246 | ||||
247 | SvtLanguageOptions aLanguageOptions; | |||
248 | bool bShowCJK = aLanguageOptions.IsCJKFontEnabled(); | |||
249 | bool bShowCTL = aLanguageOptions.IsCTLFontEnabled(); | |||
250 | bool bShowNonWestern = bShowCJK || bShowCTL; | |||
251 | ||||
252 | if (bShowNonWestern) | |||
253 | { | |||
254 | m_xWestFrame = m_xBuilder->weld_widget("western"); | |||
255 | m_xWestFontNameFT = m_xBuilder->weld_label("westfontnameft-cjk"); | |||
256 | m_xWestFontNameLB = m_xBuilder->weld_combo_box("westfontnamelb-cjk"); | |||
257 | m_xWestFontStyleFT = m_xBuilder->weld_label("weststyleft-cjk"); | |||
258 | m_xWestFontSizeFT = m_xBuilder->weld_label("westsizeft-cjk"); | |||
259 | ||||
260 | m_xWestFontStyleLB.reset(new FontStyleBox(m_xBuilder->weld_combo_box("weststylelb-cjk"))); | |||
261 | m_xWestFontSizeLB.reset(new FontSizeBox(m_xBuilder->weld_combo_box("westsizelb-cjk"))); | |||
262 | ||||
263 | m_xWestFontLanguageFT = m_xBuilder->weld_label("westlangft-cjk"); | |||
264 | m_xWestFontLanguageLB.reset(new SvxLanguageBox(m_xBuilder->weld_combo_box("westlanglb-cjk"))); | |||
265 | m_xWestFontTypeFT = m_xBuilder->weld_label("westfontinfo-cjk"); | |||
266 | ||||
267 | m_xWestFontFeaturesButton = m_xBuilder->weld_button("west_features_button-cjk"); | |||
268 | } | |||
269 | else | |||
270 | { | |||
271 | m_xWestFrame = m_xBuilder->weld_widget("simple"); | |||
272 | m_xWestFontNameFT = m_xBuilder->weld_label("westfontnameft-nocjk"); | |||
273 | m_xWestFontStyleFT = m_xBuilder->weld_label("weststyleft-nocjk"); | |||
274 | m_xWestFontSizeFT = m_xBuilder->weld_label("westsizeft-nocjk"); | |||
275 | ||||
276 | m_xWestFontLanguageFT = m_xBuilder->weld_label("westlangft-nocjk"); | |||
277 | m_xWestFontLanguageLB.reset(new SvxLanguageBox(m_xBuilder->weld_combo_box("westlanglb-nocjk"))); | |||
278 | m_xWestFontTypeFT = m_xBuilder->weld_label("westfontinfo-nocjk"); | |||
279 | ||||
280 | m_xWestFontFeaturesButton = m_xBuilder->weld_button("west_features_button-nocjk"); | |||
281 | ||||
282 | std::unique_ptr<weld::EntryTreeView> xWestFontNameLB = m_xBuilder->weld_entry_tree_view("namegrid", "westfontname-nocjk", "westfontnamelb-nocjk"); | |||
283 | std::unique_ptr<weld::EntryTreeView> xWestFontStyleLB = m_xBuilder->weld_entry_tree_view("stylegrid", "weststyle-nocjk", "weststylelb-nocjk"); | |||
284 | std::unique_ptr<weld::EntryTreeView> xWestFontSizeLB = m_xBuilder->weld_entry_tree_view("sizegrid", "westsize-nocjk", "westsizelb-nocjk"); | |||
285 | ||||
286 | // 7 lines in the treeview | |||
287 | xWestFontNameLB->set_height_request_by_rows(7); | |||
288 | xWestFontStyleLB->set_height_request_by_rows(7); | |||
289 | xWestFontSizeLB->set_height_request_by_rows(7); | |||
290 | ||||
291 | m_xWestFontNameLB = std::move(xWestFontNameLB); | |||
292 | m_xWestFontStyleLB.reset(new FontStyleBox(std::move(xWestFontStyleLB))); | |||
293 | m_xWestFontSizeLB.reset(new FontSizeBox(std::move(xWestFontSizeLB))); | |||
294 | } | |||
295 | ||||
296 | //In MacOSX the standard dialogs name font-name, font-style as | |||
297 | //Family, Typeface | |||
298 | //In GNOME the standard dialogs name font-name, font-style as | |||
299 | //Family, Style | |||
300 | //In Windows the standard dialogs name font-name, font-style as | |||
301 | //Font, Style | |||
302 | #ifdef _WIN32 | |||
303 | OUString sFontFamilyString(CuiResId(RID_SVXSTR_CHARNAME_FONTreinterpret_cast<char const *>("RID_SVXSTR_CHARNAME_FONT" "\004" u8"Font:"))); | |||
304 | #else | |||
305 | OUString sFontFamilyString(CuiResId(RID_SVXSTR_CHARNAME_FAMILYreinterpret_cast<char const *>("RID_SVXSTR_CHARNAME_FAMILY" "\004" u8"Family:"))); | |||
306 | #endif | |||
307 | m_xWestFontNameFT->set_label(sFontFamilyString); | |||
308 | m_xEastFontNameFT->set_label(sFontFamilyString); | |||
309 | m_xCTLFontNameFT->set_label(sFontFamilyString); | |||
310 | ||||
311 | #ifdef MACOSX | |||
312 | OUString sFontStyleString(CuiResId(RID_SVXSTR_CHARNAME_TYPEFACEreinterpret_cast<char const *>("RID_SVXSTR_CHARNAME_TYPEFACE" "\004" u8"Typeface:"))); | |||
313 | #else | |||
314 | OUString sFontStyleString(CuiResId(RID_SVXSTR_CHARNAME_STYLEreinterpret_cast<char const *>("RID_SVXSTR_CHARNAME_STYLE" "\004" u8"Style:"))); | |||
315 | #endif | |||
316 | m_xWestFontStyleFT->set_label(sFontStyleString); | |||
317 | m_xEastFontStyleFT->set_label(sFontStyleString); | |||
318 | m_xCTLFontStyleFT->set_label(sFontStyleString); | |||
319 | ||||
320 | m_xWestFrame->show(); | |||
321 | m_xEastFrame->set_visible(bShowCJK); | |||
322 | m_xCTLFrame->set_visible(bShowCTL); | |||
323 | ||||
324 | m_xWestFontLanguageLB->SetLanguageList(SvxLanguageListFlags::WESTERN, true, false, true, true, | |||
325 | LANGUAGE_SYSTEMLanguageType(0x0000), css::i18n::ScriptType::LATIN); | |||
326 | m_xEastFontLanguageLB->SetLanguageList(SvxLanguageListFlags::CJK, true, false, true, true, | |||
327 | LANGUAGE_SYSTEMLanguageType(0x0000), css::i18n::ScriptType::ASIAN); | |||
328 | m_xCTLFontLanguageLB->SetLanguageList(SvxLanguageListFlags::CTL, true, false, true, true, | |||
329 | LANGUAGE_SYSTEMLanguageType(0x0000), css::i18n::ScriptType::COMPLEX); | |||
330 | ||||
331 | Initialize(); | |||
332 | } | |||
333 | ||||
334 | SvxCharNamePage::~SvxCharNamePage() | |||
335 | { | |||
336 | m_pImpl.reset(); | |||
337 | m_xCTLFontStyleLB.reset(); | |||
338 | m_xEastFontLanguageLB.reset(); | |||
339 | m_xWestFontStyleLB.reset(); | |||
340 | m_xCTLFontSizeLB.reset(); | |||
341 | m_xEastFontSizeLB.reset(); | |||
342 | m_xWestFontSizeLB.reset(); | |||
343 | m_xWestFontLanguageLB.reset(); | |||
344 | m_xPreviewWin.reset(); | |||
345 | m_xCTLFontLanguageLB.reset(); | |||
346 | m_xEastFontLanguageLB.reset(); | |||
347 | } | |||
348 | ||||
349 | void SvxCharNamePage::Initialize() | |||
350 | { | |||
351 | // to handle the changes of the other pages | |||
352 | SetExchangeSupport(); | |||
353 | ||||
354 | Link<weld::ComboBox&,void> aLink = LINK(this, SvxCharNamePage, FontModifyComboBoxHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharNamePage *>(this), &SvxCharNamePage::LinkStubFontModifyComboBoxHdl_Impl ); | |||
355 | m_xWestFontNameLB->connect_changed(aLink); | |||
356 | m_xWestFontStyleLB->connect_changed(aLink); | |||
357 | m_xWestFontSizeLB->connect_changed(aLink); | |||
358 | m_xWestFontLanguageLB->connect_changed(aLink); | |||
359 | ||||
360 | m_xWestFontFeaturesButton->connect_clicked(LINK(this, SvxCharNamePage, FontFeatureButtonClicked)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharNamePage *>(this), &SvxCharNamePage::LinkStubFontFeatureButtonClicked )); | |||
361 | ||||
362 | m_xEastFontNameLB->connect_changed(aLink); | |||
363 | m_xEastFontStyleLB->connect_changed(aLink); | |||
364 | m_xEastFontSizeLB->connect_changed(aLink); | |||
365 | m_xEastFontLanguageLB->connect_changed(aLink); | |||
366 | m_xEastFontFeaturesButton->connect_clicked(LINK(this, SvxCharNamePage, FontFeatureButtonClicked)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharNamePage *>(this), &SvxCharNamePage::LinkStubFontFeatureButtonClicked )); | |||
367 | ||||
368 | m_xCTLFontNameLB->connect_changed(aLink); | |||
369 | m_xCTLFontStyleLB->connect_changed(aLink); | |||
370 | m_xCTLFontSizeLB->connect_changed(aLink); | |||
371 | m_xCTLFontLanguageLB->connect_changed(aLink); | |||
372 | m_xCTLFontFeaturesButton->connect_clicked(LINK(this, SvxCharNamePage, FontFeatureButtonClicked)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharNamePage *>(this), &SvxCharNamePage::LinkStubFontFeatureButtonClicked )); | |||
373 | ||||
374 | m_pImpl->m_aUpdateIdle.SetInvokeHandler( LINK( this, SvxCharNamePage, UpdateHdl_Impl )::tools::detail::makeLink( ::tools::detail::castTo<SvxCharNamePage *>(this), &SvxCharNamePage::LinkStubUpdateHdl_Impl) ); | |||
375 | } | |||
376 | ||||
377 | const FontList* SvxCharNamePage::GetFontList() const | |||
378 | { | |||
379 | if ( !m_pImpl->m_pFontList ) | |||
380 | { | |||
381 | SfxObjectShell* pDocSh = SfxObjectShell::Current(); | |||
382 | ||||
383 | /* #110771# SvxFontListItem::GetFontList can return NULL */ | |||
384 | if ( pDocSh ) | |||
385 | { | |||
386 | const SfxPoolItem* pItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST( 10000 + 22 ) ); | |||
387 | if ( pItem != nullptr ) | |||
388 | { | |||
389 | DBG_ASSERT(nullptr != static_cast<const SvxFontListItem*>(pItem)->GetFontList(),do { if (true && (!(nullptr != static_cast<const SvxFontListItem *>(pItem)->GetFontList()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "390" ": "), "%s", "Where is the font list?"); } } while (false) | |||
390 | "Where is the font list?")do { if (true && (!(nullptr != static_cast<const SvxFontListItem *>(pItem)->GetFontList()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "390" ": "), "%s", "Where is the font list?"); } } while (false); | |||
391 | m_pImpl->m_pFontList = static_cast<const SvxFontListItem*>(pItem )->GetFontList()->Clone(); | |||
392 | } | |||
393 | } | |||
394 | if(!m_pImpl->m_pFontList) | |||
395 | { | |||
396 | m_pImpl->m_pFontList.reset(new FontList( Application::GetDefaultDevice() )); | |||
397 | } | |||
398 | } | |||
399 | ||||
400 | return m_pImpl->m_pFontList.get(); | |||
401 | } | |||
402 | ||||
403 | ||||
404 | namespace | |||
405 | { | |||
406 | FontMetric calcFontMetrics( SvxFont& _rFont, | |||
407 | SvxCharNamePage const * _pPage, | |||
408 | const weld::ComboBox* _pFontNameLB, | |||
409 | const FontStyleBox* _pFontStyleLB, | |||
410 | const FontSizeBox* _pFontSizeLB, | |||
411 | const SvxLanguageBox* _pLanguageLB, | |||
412 | const FontList* _pFontList, | |||
413 | sal_uInt16 _nFontWhich, | |||
414 | sal_uInt16 _nFontHeightWhich) | |||
415 | { | |||
416 | Size aSize = _rFont.GetFontSize(); | |||
417 | aSize.setWidth( 0 ); | |||
418 | FontMetric aFontMetrics; | |||
419 | OUString sFontName(_pFontNameLB->get_active_text()); | |||
420 | bool bFontAvailable = _pFontList->IsAvailable( sFontName ); | |||
421 | if (bFontAvailable || _pFontNameLB->get_value_changed_from_saved()) | |||
422 | aFontMetrics = _pFontList->Get(sFontName, _pFontStyleLB->get_active_text()); | |||
423 | else | |||
424 | { | |||
425 | //get the font from itemset | |||
426 | SfxItemState eState = _pPage->GetItemSet().GetItemState( _nFontWhich ); | |||
427 | if ( eState >= SfxItemState::DEFAULT ) | |||
428 | { | |||
429 | const SvxFontItem* pFontItem = static_cast<const SvxFontItem*>(&( _pPage->GetItemSet().Get( _nFontWhich ) )); | |||
430 | aFontMetrics.SetFamilyName(pFontItem->GetFamilyName()); | |||
431 | aFontMetrics.SetStyleName(pFontItem->GetStyleName()); | |||
432 | aFontMetrics.SetFamily(pFontItem->GetFamily()); | |||
433 | aFontMetrics.SetPitch(pFontItem->GetPitch()); | |||
434 | aFontMetrics.SetCharSet(pFontItem->GetCharSet()); | |||
435 | } | |||
436 | } | |||
437 | if ( _pFontSizeLB->IsRelative() ) | |||
438 | { | |||
439 | DBG_ASSERT( _pPage->GetItemSet().GetParent(), "No parent set" )do { if (true && (!(_pPage->GetItemSet().GetParent ()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "439" ": "), "%s", "No parent set"); } } while (false); | |||
440 | const SvxFontHeightItem& rOldItem = static_cast<const SvxFontHeightItem&>(_pPage->GetItemSet().GetParent()->Get( _nFontHeightWhich )); | |||
441 | ||||
442 | // old value, scaled | |||
443 | long nHeight; | |||
444 | if ( _pFontSizeLB->IsPtRelative() ) | |||
445 | nHeight = rOldItem.GetHeight() + PointToTwips( static_cast<long>(_pFontSizeLB->get_value() / 10) ); | |||
446 | else | |||
447 | nHeight = static_cast<long>(rOldItem.GetHeight() * _pFontSizeLB->get_value() / 100); | |||
448 | ||||
449 | // conversion twips for the example-window | |||
450 | aSize.setHeight( | |||
451 | ItemToControl( nHeight, _pPage->GetItemSet().GetPool()->GetMetric( _nFontHeightWhich ), FieldUnit::TWIP ) ); | |||
452 | } | |||
453 | else if ( !_pFontSizeLB->get_active_text().isEmpty() ) | |||
454 | aSize.setHeight( PointToTwips( static_cast<long>(_pFontSizeLB->get_value() / 10) ) ); | |||
455 | else | |||
456 | aSize.setHeight( 200 ); // default 10pt | |||
457 | aFontMetrics.SetFontSize( aSize ); | |||
458 | ||||
459 | _rFont.SetLanguage(_pLanguageLB->get_active_id()); | |||
460 | ||||
461 | _rFont.SetFamily( aFontMetrics.GetFamilyType() ); | |||
462 | _rFont.SetFamilyName( aFontMetrics.GetFamilyName() ); | |||
463 | _rFont.SetStyleName( aFontMetrics.GetStyleName() ); | |||
464 | _rFont.SetPitch( aFontMetrics.GetPitch() ); | |||
465 | _rFont.SetCharSet( aFontMetrics.GetCharSet() ); | |||
466 | _rFont.SetWeight( aFontMetrics.GetWeight() ); | |||
467 | _rFont.SetItalic( aFontMetrics.GetItalic() ); | |||
468 | _rFont.SetFontSize( aFontMetrics.GetFontSize() ); | |||
469 | ||||
470 | return aFontMetrics; | |||
471 | } | |||
472 | } | |||
473 | ||||
474 | ||||
475 | void SvxCharNamePage::UpdatePreview_Impl() | |||
476 | { | |||
477 | SvxFont& rFont = GetPreviewFont(); | |||
478 | SvxFont& rCJKFont = GetPreviewCJKFont(); | |||
479 | SvxFont& rCTLFont = GetPreviewCTLFont(); | |||
480 | // Font | |||
481 | const FontList* pFontList = GetFontList(); | |||
482 | ||||
483 | FontMetric aWestFontMetric = calcFontMetrics(rFont, this, m_xWestFontNameLB.get(), | |||
484 | m_xWestFontStyleLB.get(), m_xWestFontSizeLB.get(), m_xWestFontLanguageLB.get(), | |||
485 | pFontList, GetWhich(SID_ATTR_CHAR_FONT( 10000 + 7 )), | |||
486 | GetWhich(SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ))); | |||
487 | ||||
488 | m_xWestFontTypeFT->set_label(pFontList->GetFontMapText(aWestFontMetric)); | |||
489 | ||||
490 | FontMetric aEastFontMetric = calcFontMetrics(rCJKFont, this, m_xEastFontNameLB.get(), | |||
491 | m_xEastFontStyleLB.get(), m_xEastFontSizeLB.get(), m_xEastFontLanguageLB.get(), | |||
492 | pFontList, GetWhich(SID_ATTR_CHAR_CJK_FONT( 10000 + 887 )), | |||
493 | GetWhich(SID_ATTR_CHAR_CJK_FONTHEIGHT( 10000 + 888 ))); | |||
494 | ||||
495 | m_xEastFontTypeFT->set_label(pFontList->GetFontMapText(aEastFontMetric)); | |||
496 | ||||
497 | FontMetric aCTLFontMetric = calcFontMetrics(rCTLFont, | |||
498 | this, m_xCTLFontNameLB.get(), m_xCTLFontStyleLB.get(), m_xCTLFontSizeLB.get(), | |||
499 | m_xCTLFontLanguageLB.get(), pFontList, GetWhich(SID_ATTR_CHAR_CTL_FONT( 10000 + 892 )), | |||
500 | GetWhich(SID_ATTR_CHAR_CTL_FONTHEIGHT( 10000 + 893 ))); | |||
501 | ||||
502 | m_xCTLFontTypeFT->set_label(pFontList->GetFontMapText(aCTLFontMetric)); | |||
503 | ||||
504 | m_aPreviewWin.Invalidate(); | |||
505 | } | |||
506 | ||||
507 | void SvxCharNamePage::FillStyleBox_Impl(const weld::Widget& rNameBox) | |||
508 | { | |||
509 | const FontList* pFontList = GetFontList(); | |||
510 | DBG_ASSERT( pFontList, "no fontlist" )do { if (true && (!(pFontList))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "510" ": "), "%s", "no fontlist"); } } while (false); | |||
511 | ||||
512 | FontStyleBox* pStyleBox = nullptr; | |||
513 | OUString sFontName; | |||
514 | ||||
515 | if (m_xWestFontNameLB.get() == &rNameBox) | |||
516 | { | |||
517 | pStyleBox = m_xWestFontStyleLB.get(); | |||
518 | sFontName = m_xWestFontNameLB->get_active_text(); | |||
519 | } | |||
520 | else if (m_xEastFontNameLB.get() == &rNameBox) | |||
521 | { | |||
522 | pStyleBox = m_xEastFontStyleLB.get(); | |||
523 | sFontName = m_xEastFontStyleLB->get_active_text(); | |||
524 | } | |||
525 | else if (m_xCTLFontNameLB.get() == &rNameBox) | |||
526 | { | |||
527 | pStyleBox = m_xCTLFontStyleLB.get(); | |||
528 | sFontName = m_xCTLFontNameLB->get_active_text(); | |||
529 | } | |||
530 | else | |||
531 | { | |||
532 | SAL_WARN( "cui.tabpages", "invalid font name box" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.tabpages")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "invalid font name box" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "532" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "invalid font name box"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "invalid font name box"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui.tabpages"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "532" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "invalid font name box") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "532" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "invalid font name box"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "invalid font name box"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui.tabpages"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "532" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
533 | return; | |||
534 | } | |||
535 | ||||
536 | pStyleBox->Fill(sFontName, pFontList); | |||
537 | ||||
538 | if ( !m_pImpl->m_bInSearchMode ) | |||
539 | return; | |||
540 | ||||
541 | // additional entries for the search: | |||
542 | // "not bold" and "not italic" | |||
543 | OUString aEntry = m_pImpl->m_aNoStyleText; | |||
544 | const char sS[] = "%1"; | |||
545 | aEntry = aEntry.replaceFirst( sS, pFontList->GetBoldStr() ); | |||
546 | m_pImpl->m_nExtraEntryPos = pStyleBox->get_count(); | |||
547 | pStyleBox->append_text( aEntry ); | |||
548 | aEntry = m_pImpl->m_aNoStyleText; | |||
549 | aEntry = aEntry.replaceFirst( sS, pFontList->GetItalicStr() ); | |||
550 | pStyleBox->append_text(aEntry); | |||
551 | } | |||
552 | ||||
553 | void SvxCharNamePage::FillSizeBox_Impl(const weld::Widget& rNameBox) | |||
554 | { | |||
555 | const FontList* pFontList = GetFontList(); | |||
556 | DBG_ASSERT( pFontList, "no fontlist" )do { if (true && (!(pFontList))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "556" ": "), "%s", "no fontlist"); } } while (false); | |||
557 | ||||
558 | FontStyleBox* pStyleBox = nullptr; | |||
559 | FontSizeBox* pSizeBox = nullptr; | |||
560 | OUString sFontName; | |||
561 | ||||
562 | if (m_xWestFontNameLB.get() == &rNameBox) | |||
563 | { | |||
564 | pStyleBox = m_xWestFontStyleLB.get(); | |||
565 | pSizeBox = m_xWestFontSizeLB.get(); | |||
566 | sFontName = m_xWestFontNameLB->get_active_text(); | |||
567 | } | |||
568 | else if (m_xEastFontNameLB.get() == &rNameBox) | |||
569 | { | |||
570 | pStyleBox = m_xEastFontStyleLB.get(); | |||
571 | pSizeBox = m_xEastFontSizeLB.get(); | |||
572 | sFontName = m_xEastFontNameLB->get_active_text(); | |||
573 | } | |||
574 | else if (m_xCTLFontNameLB.get() == &rNameBox) | |||
575 | { | |||
576 | pStyleBox = m_xCTLFontStyleLB.get(); | |||
577 | pSizeBox = m_xCTLFontSizeLB.get(); | |||
578 | sFontName = m_xCTLFontNameLB->get_active_text(); | |||
579 | } | |||
580 | else | |||
581 | { | |||
582 | SAL_WARN( "cui.tabpages", "invalid font name box" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "cui.tabpages")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "invalid font name box" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "582" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "invalid font name box"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "invalid font name box"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui.tabpages"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "582" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "invalid font name box") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.tabpages"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "582" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "invalid font name box"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "invalid font name box"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("cui.tabpages"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "582" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
583 | return; | |||
584 | } | |||
585 | ||||
586 | FontMetric _aFontMetric(pFontList->Get(sFontName, pStyleBox->get_active_text())); | |||
587 | pSizeBox->Fill( &_aFontMetric, pFontList ); | |||
588 | } | |||
589 | ||||
590 | namespace | |||
591 | { | |||
592 | void FillFontNames(weld::ComboBox& rBox, const FontList& rList) | |||
593 | { | |||
594 | // insert fonts | |||
595 | sal_uInt16 nFontCount = rList.GetFontNameCount(); | |||
596 | std::vector<weld::ComboBoxEntry> aVector; | |||
597 | aVector.reserve(nFontCount); | |||
598 | for (sal_uInt16 i = 0; i < nFontCount; ++i) | |||
599 | { | |||
600 | const FontMetric& rFontMetric = rList.GetFontName(i); | |||
601 | aVector.emplace_back(rFontMetric.GetFamilyName()); | |||
602 | } | |||
603 | rBox.insert_vector(aVector, false); | |||
604 | } | |||
605 | } | |||
606 | ||||
607 | void SvxCharNamePage::Reset_Impl( const SfxItemSet& rSet, LanguageGroup eLangGrp ) | |||
608 | { | |||
609 | weld::ComboBox* pNameBox = nullptr; | |||
610 | weld::Label* pStyleLabel = nullptr; | |||
611 | FontStyleBox* pStyleBox = nullptr; | |||
612 | weld::Label* pSizeLabel = nullptr; | |||
613 | FontSizeBox* pSizeBox = nullptr; | |||
614 | weld::Label* pLangFT = nullptr; | |||
615 | SvxLanguageBox* pLangBox = nullptr; | |||
616 | sal_uInt16 nWhich = 0; | |||
617 | ||||
618 | switch ( eLangGrp ) | |||
619 | { | |||
620 | case Western : | |||
621 | pNameBox = m_xWestFontNameLB.get(); | |||
622 | pStyleLabel = m_xWestFontStyleFT.get(); | |||
623 | pStyleBox = m_xWestFontStyleLB.get(); | |||
624 | pSizeLabel = m_xWestFontSizeFT.get(); | |||
625 | pSizeBox = m_xWestFontSizeLB.get(); | |||
626 | pLangFT = m_xWestFontLanguageFT.get(); | |||
627 | pLangBox = m_xWestFontLanguageLB.get(); | |||
628 | nWhich = GetWhich( SID_ATTR_CHAR_FONT( 10000 + 7 ) ); | |||
629 | break; | |||
630 | ||||
631 | case Asian : | |||
632 | pNameBox = m_xEastFontNameLB.get(); | |||
633 | pStyleLabel = m_xEastFontStyleFT.get(); | |||
634 | pStyleBox = m_xEastFontStyleLB.get(); | |||
635 | pSizeLabel = m_xEastFontSizeFT.get(); | |||
636 | pSizeBox = m_xEastFontSizeLB.get(); | |||
637 | pLangFT = m_xEastFontLanguageFT.get(); | |||
638 | pLangBox = m_xEastFontLanguageLB.get(); | |||
639 | nWhich = GetWhich( SID_ATTR_CHAR_CJK_FONT( 10000 + 887 ) ); | |||
640 | break; | |||
641 | ||||
642 | case Ctl : | |||
643 | pNameBox = m_xCTLFontNameLB.get(); | |||
644 | pStyleLabel = m_xCTLFontStyleFT.get(); | |||
645 | pStyleBox = m_xCTLFontStyleLB.get(); | |||
646 | pSizeLabel = m_xCTLFontSizeFT.get(); | |||
647 | pSizeBox = m_xCTLFontSizeLB.get(); | |||
648 | pLangFT = m_xCTLFontLanguageFT.get(); | |||
649 | pLangBox = m_xCTLFontLanguageLB.get(); | |||
650 | nWhich = GetWhich( SID_ATTR_CHAR_CTL_FONT( 10000 + 892 ) ); | |||
651 | break; | |||
652 | } | |||
653 | ||||
654 | const FontList* pFontList = GetFontList(); | |||
655 | FillFontNames(*pNameBox, *pFontList); | |||
656 | ||||
657 | const SvxFontItem* pFontItem = nullptr; | |||
658 | SfxItemState eState = rSet.GetItemState( nWhich ); | |||
659 | ||||
660 | if ( eState >= SfxItemState::DEFAULT ) | |||
661 | { | |||
662 | pFontItem = static_cast<const SvxFontItem*>(&( rSet.Get( nWhich ) )); | |||
663 | const OUString &rName = pFontItem->GetFamilyName(); | |||
664 | int nIndex = pNameBox->find_text(rName); | |||
665 | pNameBox->set_active(nIndex); | |||
666 | // tdf#122992 if it didn't exist in the list, set the entry text to it anyway | |||
667 | if (nIndex == -1) | |||
668 | pNameBox->set_entry_text(rName); | |||
669 | } | |||
670 | else | |||
671 | { | |||
672 | pNameBox->set_active_text( OUString() ); | |||
673 | } | |||
674 | ||||
675 | FillStyleBox_Impl(*pNameBox); | |||
676 | ||||
677 | bool bStyle = false; | |||
678 | bool bStyleAvailable = true; | |||
679 | FontItalic eItalic = ITALIC_NONE; | |||
680 | FontWeight eWeight = WEIGHT_NORMAL; | |||
681 | switch ( eLangGrp ) | |||
682 | { | |||
683 | case Western : nWhich = GetWhich( SID_ATTR_CHAR_POSTURE( 10000 + 8 ) ); break; | |||
684 | case Asian : nWhich = GetWhich( SID_ATTR_CHAR_CJK_POSTURE( 10000 + 890 ) ); break; | |||
685 | case Ctl : nWhich = GetWhich( SID_ATTR_CHAR_CTL_POSTURE( 10000 + 895 ) ); break; | |||
686 | } | |||
687 | eState = rSet.GetItemState( nWhich ); | |||
688 | ||||
689 | if ( eState >= SfxItemState::DEFAULT ) | |||
690 | { | |||
691 | const SvxPostureItem& rItem = static_cast<const SvxPostureItem&>(rSet.Get( nWhich )); | |||
692 | eItalic = rItem.GetValue(); | |||
693 | bStyle = true; | |||
694 | } | |||
695 | bStyleAvailable = bStyleAvailable && (eState >= SfxItemState::DONTCARE); | |||
696 | ||||
697 | switch ( eLangGrp ) | |||
698 | { | |||
699 | case Western : nWhich = GetWhich( SID_ATTR_CHAR_WEIGHT( 10000 + 9 ) ); break; | |||
700 | case Asian : nWhich = GetWhich( SID_ATTR_CHAR_CJK_WEIGHT( 10000 + 891 ) ); break; | |||
701 | case Ctl : nWhich = GetWhich( SID_ATTR_CHAR_CTL_WEIGHT( 10000 + 896 ) ); break; | |||
702 | } | |||
703 | eState = rSet.GetItemState( nWhich ); | |||
704 | ||||
705 | if ( eState >= SfxItemState::DEFAULT ) | |||
706 | { | |||
707 | const SvxWeightItem& rItem = static_cast<const SvxWeightItem&>(rSet.Get( nWhich )); | |||
708 | eWeight = rItem.GetValue(); | |||
709 | } | |||
710 | else | |||
711 | bStyle = false; | |||
712 | bStyleAvailable = bStyleAvailable && (eState >= SfxItemState::DONTCARE); | |||
713 | ||||
714 | // currently chosen font | |||
715 | if ( bStyle && pFontItem ) | |||
716 | { | |||
717 | FontMetric aFontMetric = pFontList->Get( pFontItem->GetFamilyName(), eWeight, eItalic ); | |||
718 | pStyleBox->set_active_text( pFontList->GetStyleName( aFontMetric ) ); | |||
719 | } | |||
720 | else if ( !m_pImpl->m_bInSearchMode || !bStyle ) | |||
721 | { | |||
722 | pStyleBox->set_active_text( OUString() ); | |||
723 | } | |||
724 | else if ( bStyle ) | |||
725 | { | |||
726 | FontMetric aFontMetric = pFontList->Get( OUString(), eWeight, eItalic ); | |||
727 | pStyleBox->set_active_text( pFontList->GetStyleName( aFontMetric ) ); | |||
728 | } | |||
729 | if (!bStyleAvailable) | |||
730 | { | |||
731 | pStyleBox->set_sensitive(false); | |||
732 | pStyleLabel->set_sensitive(false); | |||
733 | } | |||
734 | ||||
735 | FillSizeBox_Impl(*pNameBox); | |||
736 | switch ( eLangGrp ) | |||
737 | { | |||
738 | case Western : nWhich = GetWhich( SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ) ); break; | |||
739 | case Asian : nWhich = GetWhich( SID_ATTR_CHAR_CJK_FONTHEIGHT( 10000 + 888 ) ); break; | |||
740 | case Ctl : nWhich = GetWhich( SID_ATTR_CHAR_CTL_FONTHEIGHT( 10000 + 893 ) ); break; | |||
741 | } | |||
742 | eState = rSet.GetItemState( nWhich ); | |||
743 | ||||
744 | if ( pSizeBox->IsRelativeMode() ) | |||
745 | { | |||
746 | MapUnit eUnit = rSet.GetPool()->GetMetric( nWhich ); | |||
747 | const SvxFontHeightItem& rItem = static_cast<const SvxFontHeightItem&>(rSet.Get( nWhich )); | |||
748 | ||||
749 | if( rItem.GetProp() != 100 || MapUnit::MapRelative != rItem.GetPropUnit() ) | |||
750 | { | |||
751 | bool bPtRel = MapUnit::MapPoint == rItem.GetPropUnit(); | |||
752 | pSizeBox->SetPtRelative( bPtRel ); | |||
753 | pSizeBox->set_value( bPtRel ? static_cast<short>(rItem.GetProp()) * 10 : rItem.GetProp() ); | |||
754 | } | |||
755 | else | |||
756 | { | |||
757 | pSizeBox->SetRelative(false); | |||
758 | pSizeBox->set_value( CalcToPoint( rItem.GetHeight(), eUnit, 10 ) ); | |||
759 | } | |||
760 | } | |||
761 | else if ( eState >= SfxItemState::DEFAULT ) | |||
762 | { | |||
763 | MapUnit eUnit = rSet.GetPool()->GetMetric( nWhich ); | |||
764 | const SvxFontHeightItem& rItem = static_cast<const SvxFontHeightItem&>(rSet.Get( nWhich )); | |||
765 | pSizeBox->set_value( CalcToPoint( rItem.GetHeight(), eUnit, 10 ) ); | |||
766 | } | |||
767 | else | |||
768 | { | |||
769 | pSizeBox->set_active_or_entry_text(OUString()); | |||
770 | if ( eState <= SfxItemState::READONLY ) | |||
771 | { | |||
772 | pSizeBox->set_sensitive(false); | |||
773 | pSizeLabel->set_sensitive(false); | |||
774 | } | |||
775 | } | |||
776 | ||||
777 | switch ( eLangGrp ) | |||
778 | { | |||
779 | case Western : nWhich = GetWhich( SID_ATTR_CHAR_LANGUAGE( 10000 + 20 ) ); break; | |||
780 | case Asian : nWhich = GetWhich( SID_ATTR_CHAR_CJK_LANGUAGE( 10000 + 889 ) ); break; | |||
781 | case Ctl : nWhich = GetWhich( SID_ATTR_CHAR_CTL_LANGUAGE( 10000 + 894 ) ); break; | |||
782 | } | |||
783 | pLangBox->set_active(-1); | |||
784 | eState = rSet.GetItemState( nWhich ); | |||
785 | ||||
786 | switch ( eState ) | |||
787 | { | |||
788 | case SfxItemState::UNKNOWN: | |||
789 | pLangFT->hide(); | |||
790 | pLangBox->hide(); | |||
791 | break; | |||
792 | ||||
793 | case SfxItemState::DISABLED: | |||
794 | case SfxItemState::READONLY: | |||
795 | pLangFT->set_sensitive(false); | |||
796 | pLangBox->set_sensitive(false); | |||
797 | break; | |||
798 | ||||
799 | case SfxItemState::DEFAULT: | |||
800 | case SfxItemState::SET: | |||
801 | { | |||
802 | const SvxLanguageItem& rItem = static_cast<const SvxLanguageItem&>(rSet.Get( nWhich )); | |||
803 | LanguageType eLangType = rItem.GetValue(); | |||
804 | DBG_ASSERT( eLangType != LANGUAGE_SYSTEM, "LANGUAGE_SYSTEM not allowed" )do { if (true && (!(eLangType != LanguageType(0x0000) ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "804" ": "), "%s", "LANGUAGE_SYSTEM not allowed"); } } while (false); | |||
805 | if (eLangType != LANGUAGE_DONTKNOWLanguageType(0x03FF)) | |||
806 | pLangBox->set_active_id(eLangType); | |||
807 | break; | |||
808 | } | |||
809 | case SfxItemState::DONTCARE: | |||
810 | break; | |||
811 | } | |||
812 | ||||
813 | OUString sMapText(pFontList->GetFontMapText( | |||
814 | pFontList->Get(pNameBox->get_active_text(), pStyleBox->get_active_text()))); | |||
815 | ||||
816 | switch (eLangGrp) | |||
817 | { | |||
818 | case Western: | |||
819 | m_xWestFontTypeFT->set_label(sMapText); | |||
820 | break; | |||
821 | case Asian: | |||
822 | m_xEastFontTypeFT->set_label(sMapText); | |||
823 | break; | |||
824 | case Ctl: | |||
825 | m_xCTLFontTypeFT->set_label(sMapText); | |||
826 | break; | |||
827 | } | |||
828 | ||||
829 | // save these settings | |||
830 | pNameBox->save_value(); | |||
831 | pStyleBox->save_value(); | |||
832 | pSizeBox->save_value(); | |||
833 | pLangBox->save_active_id(); | |||
834 | } | |||
835 | ||||
836 | bool SvxCharNamePage::FillItemSet_Impl( SfxItemSet& rSet, LanguageGroup eLangGrp ) | |||
837 | { | |||
838 | bool bModified = false; | |||
839 | ||||
840 | weld::ComboBox* pNameBox = nullptr; | |||
841 | FontStyleBox* pStyleBox = nullptr; | |||
842 | FontSizeBox* pSizeBox = nullptr; | |||
843 | SvxLanguageBox* pLangBox = nullptr; | |||
844 | sal_uInt16 nWhich = 0; | |||
845 | sal_uInt16 nSlot = 0; | |||
846 | ||||
847 | switch ( eLangGrp ) | |||
848 | { | |||
849 | case Western : | |||
850 | pNameBox = m_xWestFontNameLB.get(); | |||
851 | pStyleBox = m_xWestFontStyleLB.get(); | |||
852 | pSizeBox = m_xWestFontSizeLB.get(); | |||
853 | pLangBox = m_xWestFontLanguageLB.get(); | |||
854 | nSlot = SID_ATTR_CHAR_FONT( 10000 + 7 ); | |||
855 | break; | |||
856 | ||||
857 | case Asian : | |||
858 | pNameBox = m_xEastFontNameLB.get(); | |||
859 | pStyleBox = m_xEastFontStyleLB.get(); | |||
860 | pSizeBox = m_xEastFontSizeLB.get(); | |||
861 | pLangBox = m_xEastFontLanguageLB.get(); | |||
862 | nSlot = SID_ATTR_CHAR_CJK_FONT( 10000 + 887 ); | |||
863 | break; | |||
864 | ||||
865 | case Ctl : | |||
866 | pNameBox = m_xCTLFontNameLB.get(); | |||
867 | pStyleBox = m_xCTLFontStyleLB.get(); | |||
868 | pSizeBox = m_xCTLFontSizeLB.get(); | |||
869 | pLangBox = m_xCTLFontLanguageLB.get(); | |||
870 | nSlot = SID_ATTR_CHAR_CTL_FONT( 10000 + 892 ); | |||
871 | break; | |||
872 | } | |||
873 | ||||
874 | nWhich = GetWhich( nSlot ); | |||
875 | const SfxPoolItem* pItem = nullptr; | |||
876 | const SfxItemSet& rOldSet = GetItemSet(); | |||
877 | const SfxPoolItem* pOld = nullptr; | |||
878 | ||||
879 | const SfxItemSet* pExampleSet = GetDialogExampleSet(); | |||
880 | ||||
881 | bool bChanged = true; | |||
882 | const OUString& rFontName = pNameBox->get_active_text(); | |||
883 | const FontList* pFontList = GetFontList(); | |||
884 | OUString aStyleBoxText = pStyleBox->get_active_text(); | |||
885 | int nEntryPos = pStyleBox->find_text(aStyleBoxText); | |||
886 | if (nEntryPos >= m_pImpl->m_nExtraEntryPos) | |||
887 | aStyleBoxText.clear(); | |||
888 | FontMetric aInfo( pFontList->Get( rFontName, aStyleBoxText ) ); | |||
889 | SvxFontItem aFontItem( aInfo.GetFamilyType(), aInfo.GetFamilyName(), aInfo.GetStyleName(), | |||
890 | aInfo.GetPitch(), aInfo.GetCharSet(), nWhich ); | |||
891 | pOld = GetOldItem( rSet, nSlot ); | |||
892 | ||||
893 | if ( pOld ) | |||
894 | { | |||
895 | const SvxFontItem& rItem = *static_cast<const SvxFontItem*>(pOld); | |||
896 | ||||
897 | if ( rItem.GetFamilyName() == aFontItem.GetFamilyName() ) | |||
898 | bChanged = false; | |||
899 | } | |||
900 | ||||
901 | if ( !bChanged ) | |||
902 | bChanged = pNameBox->get_saved_value().isEmpty(); | |||
903 | ||||
904 | if ( !bChanged && pExampleSet && | |||
905 | pExampleSet->GetItemState( nWhich, false, &pItem ) == SfxItemState::SET && | |||
906 | static_cast<const SvxFontItem*>(pItem)->GetFamilyName() != aFontItem.GetFamilyName() ) | |||
907 | bChanged = true; | |||
908 | ||||
909 | if ( bChanged && !rFontName.isEmpty() ) | |||
910 | { | |||
911 | rSet.Put( aFontItem ); | |||
912 | bModified = true; | |||
913 | } | |||
914 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
915 | rSet.ClearItem( nWhich ); | |||
916 | ||||
917 | ||||
918 | bChanged = true; | |||
919 | switch ( eLangGrp ) | |||
920 | { | |||
921 | case Western : nSlot = SID_ATTR_CHAR_WEIGHT( 10000 + 9 ); break; | |||
922 | case Asian : nSlot = SID_ATTR_CHAR_CJK_WEIGHT( 10000 + 891 ); break; | |||
923 | case Ctl : nSlot = SID_ATTR_CHAR_CTL_WEIGHT( 10000 + 896 ); break; | |||
924 | } | |||
925 | nWhich = GetWhich( nSlot ); | |||
926 | FontWeight eWeight = aInfo.GetWeight(); | |||
927 | if ( nEntryPos >= m_pImpl->m_nExtraEntryPos ) | |||
928 | eWeight = WEIGHT_NORMAL; | |||
929 | SvxWeightItem aWeightItem( eWeight, nWhich ); | |||
930 | pOld = GetOldItem( rSet, nSlot ); | |||
931 | ||||
932 | if ( pOld ) | |||
933 | { | |||
934 | const SvxWeightItem& rItem = *static_cast<const SvxWeightItem*>(pOld); | |||
935 | ||||
936 | if ( rItem.GetValue() == aWeightItem.GetValue() ) | |||
937 | bChanged = false; | |||
938 | } | |||
939 | ||||
940 | if ( !bChanged ) | |||
941 | { | |||
942 | bChanged = pStyleBox->get_saved_value().isEmpty(); | |||
943 | ||||
944 | if ( m_pImpl->m_bInSearchMode && bChanged && | |||
945 | aInfo.GetWeight() == WEIGHT_NORMAL && aInfo.GetItalic() != ITALIC_NONE ) | |||
946 | bChanged = false; | |||
947 | } | |||
948 | ||||
949 | if ( !bChanged && pExampleSet && | |||
950 | pExampleSet->GetItemState( nWhich, false, &pItem ) == SfxItemState::SET && | |||
951 | static_cast<const SvxWeightItem*>(pItem)->GetValue() != aWeightItem.GetValue() ) | |||
952 | bChanged = true; | |||
953 | ||||
954 | if ( nEntryPos >= m_pImpl->m_nExtraEntryPos ) | |||
955 | bChanged = ( nEntryPos == m_pImpl->m_nExtraEntryPos ); | |||
956 | ||||
957 | OUString aText( pStyleBox->get_active_text() ); // Tristate, then text empty | |||
958 | ||||
959 | if ( bChanged && !aText.isEmpty() ) | |||
960 | { | |||
961 | rSet.Put( aWeightItem ); | |||
962 | bModified = true; | |||
963 | } | |||
964 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
965 | rSet.InvalidateItem(nWhich); | |||
966 | ||||
967 | bChanged = true; | |||
968 | switch ( eLangGrp ) | |||
969 | { | |||
970 | case Western : nSlot = SID_ATTR_CHAR_POSTURE( 10000 + 8 ); break; | |||
971 | case Asian : nSlot = SID_ATTR_CHAR_CJK_POSTURE( 10000 + 890 ); break; | |||
972 | case Ctl : nSlot = SID_ATTR_CHAR_CTL_POSTURE( 10000 + 895 ); break; | |||
973 | } | |||
974 | nWhich = GetWhich( nSlot ); | |||
975 | FontItalic eItalic = aInfo.GetItalic(); | |||
976 | if ( nEntryPos >= m_pImpl->m_nExtraEntryPos ) | |||
977 | eItalic = ITALIC_NONE; | |||
978 | SvxPostureItem aPostureItem( eItalic, nWhich ); | |||
979 | pOld = GetOldItem( rSet, nSlot ); | |||
980 | ||||
981 | if ( pOld ) | |||
982 | { | |||
983 | const SvxPostureItem& rItem = *static_cast<const SvxPostureItem*>(pOld); | |||
984 | ||||
985 | if ( rItem.GetValue() == aPostureItem.GetValue() ) | |||
986 | bChanged = false; | |||
987 | } | |||
988 | ||||
989 | if ( !bChanged ) | |||
990 | { | |||
991 | bChanged = pStyleBox->get_saved_value().isEmpty(); | |||
992 | ||||
993 | if ( m_pImpl->m_bInSearchMode && bChanged && | |||
994 | aInfo.GetItalic() == ITALIC_NONE && aInfo.GetWeight() != WEIGHT_NORMAL ) | |||
995 | bChanged = false; | |||
996 | } | |||
997 | ||||
998 | if ( !bChanged && pExampleSet && | |||
999 | pExampleSet->GetItemState( nWhich, false, &pItem ) == SfxItemState::SET && | |||
1000 | static_cast<const SvxPostureItem*>(pItem)->GetValue() != aPostureItem.GetValue() ) | |||
1001 | bChanged = true; | |||
1002 | ||||
1003 | if ( nEntryPos >= m_pImpl->m_nExtraEntryPos ) | |||
1004 | bChanged = ( nEntryPos == ( m_pImpl->m_nExtraEntryPos + 1 ) ); | |||
1005 | ||||
1006 | if ( bChanged && !aText.isEmpty() ) | |||
1007 | { | |||
1008 | rSet.Put( aPostureItem ); | |||
1009 | bModified = true; | |||
1010 | } | |||
1011 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
1012 | rSet.InvalidateItem(nWhich); | |||
1013 | ||||
1014 | // FontSize | |||
1015 | long nSize = pSizeBox->get_value(); | |||
1016 | ||||
1017 | if ( pSizeBox->get_active_text().isEmpty() ) // GetValue() returns the min-value | |||
1018 | nSize = 0; | |||
1019 | long nSavedSize = pSizeBox->get_saved_value(); | |||
1020 | const bool bRel = pSizeBox->IsRelative(); | |||
1021 | ||||
1022 | switch ( eLangGrp ) | |||
1023 | { | |||
1024 | case Western : nSlot = SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ); break; | |||
1025 | case Asian : nSlot = SID_ATTR_CHAR_CJK_FONTHEIGHT( 10000 + 888 ); break; | |||
1026 | case Ctl : nSlot = SID_ATTR_CHAR_CTL_FONTHEIGHT( 10000 + 893 ); break; | |||
1027 | } | |||
1028 | nWhich = GetWhich( nSlot ); | |||
1029 | const SvxFontHeightItem* pOldHeight = static_cast<const SvxFontHeightItem*>(GetOldItem( rSet, nSlot )); | |||
1030 | bChanged = ( nSize != nSavedSize ); | |||
1031 | ||||
1032 | if ( !bChanged && pExampleSet && | |||
1033 | pExampleSet->GetItemState( nWhich, false, &pItem ) == SfxItemState::SET ) | |||
1034 | { | |||
1035 | float fSize = static_cast<float>(nSize) / 10; | |||
1036 | long nVal = CalcToUnit( fSize, rSet.GetPool()->GetMetric( nWhich ) ); | |||
1037 | if ( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() != static_cast<sal_uInt32>(nVal) ) | |||
1038 | bChanged = true; | |||
1039 | } | |||
1040 | ||||
1041 | if ( bChanged || !pOldHeight || | |||
1042 | bRel != ( MapUnit::MapRelative != pOldHeight->GetPropUnit() || 100 != pOldHeight->GetProp() ) ) | |||
1043 | { | |||
1044 | MapUnit eUnit = rSet.GetPool()->GetMetric( nWhich ); | |||
1045 | if ( pSizeBox->IsRelative() ) | |||
1046 | { | |||
1047 | DBG_ASSERT( GetItemSet().GetParent(), "No parent set" )do { if (true && (!(GetItemSet().GetParent()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "1047" ": "), "%s", "No parent set"); } } while (false); | |||
1048 | const SvxFontHeightItem& rOldItem = | |||
1049 | static_cast<const SvxFontHeightItem&>(GetItemSet().GetParent()->Get( nWhich )); | |||
1050 | ||||
1051 | SvxFontHeightItem aHeight( 240, 100, nWhich ); | |||
1052 | if ( pSizeBox->IsPtRelative() ) | |||
1053 | aHeight.SetHeight( rOldItem.GetHeight(), static_cast<sal_uInt16>( nSize / 10 ), MapUnit::MapPoint, eUnit ); | |||
1054 | else | |||
1055 | aHeight.SetHeight( rOldItem.GetHeight(), static_cast<sal_uInt16>(nSize) ); | |||
1056 | rSet.Put( aHeight ); | |||
1057 | } | |||
1058 | else | |||
1059 | { | |||
1060 | float fSize = static_cast<float>(nSize) / 10; | |||
1061 | rSet.Put( SvxFontHeightItem( CalcToUnit( fSize, eUnit ), 100, nWhich ) ); | |||
1062 | } | |||
1063 | bModified = true; | |||
1064 | } | |||
1065 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
1066 | rSet.InvalidateItem(nWhich); | |||
1067 | ||||
1068 | bChanged = true; | |||
1069 | switch ( eLangGrp ) | |||
1070 | { | |||
1071 | case Western : nSlot = SID_ATTR_CHAR_LANGUAGE( 10000 + 20 ); break; | |||
1072 | case Asian : nSlot = SID_ATTR_CHAR_CJK_LANGUAGE( 10000 + 889 ); break; | |||
1073 | case Ctl : nSlot = SID_ATTR_CHAR_CTL_LANGUAGE( 10000 + 894 ); break; | |||
1074 | } | |||
1075 | nWhich = GetWhich( nSlot ); | |||
1076 | pOld = GetOldItem( rSet, nSlot ); | |||
1077 | ||||
1078 | // For language list boxes acting as ComboBox, check for, add and select an | |||
1079 | // edited entry. | |||
1080 | if (pLangBox == m_xWestFontLanguageLB.get()) | |||
1081 | { | |||
1082 | switch (pLangBox->GetEditedAndValid()) | |||
1083 | { | |||
1084 | case SvxLanguageBox::EditedAndValid::No: | |||
1085 | ; // nothing to do | |||
1086 | break; | |||
1087 | case SvxLanguageBox::EditedAndValid::Valid: | |||
1088 | { | |||
1089 | const int nPos = pLangBox->SaveEditedAsEntry(); | |||
1090 | if (nPos != -1) | |||
1091 | pLangBox->set_active(nPos); | |||
1092 | } | |||
1093 | break; | |||
1094 | case SvxLanguageBox::EditedAndValid::Invalid: | |||
1095 | pLangBox->set_active_id(pLangBox->get_saved_active_id()); | |||
1096 | break; | |||
1097 | } | |||
1098 | } | |||
1099 | ||||
1100 | int nLangPos = pLangBox->get_active(); | |||
1101 | LanguageType eLangType = pLangBox->get_active_id(); | |||
1102 | ||||
1103 | if (pOld) | |||
1104 | { | |||
1105 | const SvxLanguageItem& rItem = *static_cast<const SvxLanguageItem*>(pOld); | |||
1106 | if (nLangPos == -1 || eLangType == rItem.GetValue()) | |||
1107 | bChanged = false; | |||
1108 | } | |||
1109 | ||||
1110 | if (!bChanged) | |||
1111 | bChanged = pLangBox->get_active_id_changed_from_saved(); | |||
1112 | ||||
1113 | if (bChanged && nLangPos != -1) | |||
1114 | { | |||
1115 | rSet.Put(SvxLanguageItem(eLangType, nWhich)); | |||
1116 | bModified = true; | |||
1117 | } | |||
1118 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
1119 | rSet.InvalidateItem(nWhich); | |||
1120 | ||||
1121 | return bModified; | |||
1122 | } | |||
1123 | ||||
1124 | IMPL_LINK_NOARG(SvxCharNamePage, UpdateHdl_Impl, Timer *, void)void SvxCharNamePage::LinkStubUpdateHdl_Impl(void * instance, Timer * data) { return static_cast<SvxCharNamePage *>( instance)->UpdateHdl_Impl(data); } void SvxCharNamePage::UpdateHdl_Impl (__attribute__ ((unused)) Timer *) | |||
1125 | { | |||
1126 | UpdatePreview_Impl(); | |||
1127 | } | |||
1128 | ||||
1129 | IMPL_LINK(SvxCharNamePage, FontModifyComboBoxHdl_Impl, weld::ComboBox&, rBox, void)void SvxCharNamePage::LinkStubFontModifyComboBoxHdl_Impl(void * instance, weld::ComboBox& data) { return static_cast< SvxCharNamePage *>(instance)->FontModifyComboBoxHdl_Impl (data); } void SvxCharNamePage::FontModifyComboBoxHdl_Impl(weld ::ComboBox& rBox) | |||
1130 | { | |||
1131 | FontModifyHdl_Impl(rBox); | |||
1132 | } | |||
1133 | ||||
1134 | IMPL_LINK(SvxCharNamePage, FontFeatureButtonClicked, weld::Button&, rButton, void)void SvxCharNamePage::LinkStubFontFeatureButtonClicked(void * instance, weld::Button& data) { return static_cast<SvxCharNamePage *>(instance)->FontFeatureButtonClicked(data); } void SvxCharNamePage ::FontFeatureButtonClicked(weld::Button& rButton) | |||
1135 | { | |||
1136 | OUString sFontName; | |||
1137 | weld::ComboBox* pNameBox = nullptr; | |||
1138 | ||||
1139 | if (&rButton == m_xWestFontFeaturesButton.get()) | |||
1140 | { | |||
1141 | pNameBox = m_xWestFontNameLB.get(); | |||
1142 | sFontName = GetPreviewFont().GetFamilyName(); | |||
1143 | } | |||
1144 | else if (&rButton == m_xEastFontFeaturesButton.get()) | |||
1145 | { | |||
1146 | pNameBox = m_xEastFontNameLB.get(); | |||
1147 | sFontName = GetPreviewCJKFont().GetFamilyName(); | |||
1148 | } | |||
1149 | else if (&rButton == m_xCTLFontFeaturesButton.get()) | |||
1150 | { | |||
1151 | pNameBox = m_xCTLFontNameLB.get(); | |||
1152 | sFontName = GetPreviewCTLFont().GetFamilyName(); | |||
1153 | } | |||
1154 | ||||
1155 | if (!sFontName.isEmpty() && pNameBox) | |||
1156 | { | |||
1157 | cui::FontFeaturesDialog aDialog(GetFrameWeld(), sFontName); | |||
1158 | if (aDialog.run() == RET_OK) | |||
1159 | { | |||
1160 | pNameBox->set_entry_text(aDialog.getResultFontName()); | |||
1161 | UpdatePreview_Impl(); | |||
1162 | } | |||
1163 | } | |||
1164 | } | |||
1165 | ||||
1166 | void SvxCharNamePage::FontModifyHdl_Impl(const weld::Widget& rNameBox) | |||
1167 | { | |||
1168 | m_pImpl->m_aUpdateIdle.Start(); | |||
1169 | ||||
1170 | if (m_xWestFontNameLB.get() == &rNameBox || m_xEastFontNameLB.get() == &rNameBox || m_xCTLFontNameLB.get() == &rNameBox) | |||
1171 | { | |||
1172 | FillStyleBox_Impl(rNameBox); | |||
1173 | FillSizeBox_Impl(rNameBox); | |||
1174 | } | |||
1175 | } | |||
1176 | ||||
1177 | void SvxCharNamePage::ActivatePage( const SfxItemSet& rSet ) | |||
1178 | { | |||
1179 | SvxCharBasePage::ActivatePage( rSet ); | |||
1180 | ||||
1181 | UpdatePreview_Impl(); // instead of asynchronous calling in ctor | |||
1182 | } | |||
1183 | ||||
1184 | DeactivateRC SvxCharNamePage::DeactivatePage( SfxItemSet* _pSet ) | |||
1185 | { | |||
1186 | if ( _pSet ) | |||
1187 | FillItemSet( _pSet ); | |||
1188 | return DeactivateRC::LeavePage; | |||
1189 | } | |||
1190 | ||||
1191 | std::unique_ptr<SfxTabPage> SvxCharNamePage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet) | |||
1192 | { | |||
1193 | return std::make_unique<SvxCharNamePage>(pPage, pController, *rSet ); | |||
1194 | } | |||
1195 | ||||
1196 | void SvxCharNamePage::Reset( const SfxItemSet* rSet ) | |||
1197 | { | |||
1198 | Reset_Impl( *rSet, Western ); | |||
1199 | Reset_Impl( *rSet, Asian ); | |||
1200 | Reset_Impl( *rSet, Ctl ); | |||
1201 | ||||
1202 | SetPrevFontWidthScale( *rSet ); | |||
1203 | UpdatePreview_Impl(); | |||
1204 | } | |||
1205 | ||||
1206 | void SvxCharNamePage::ChangesApplied() | |||
1207 | { | |||
1208 | m_xWestFontNameLB->save_value(); | |||
1209 | m_xWestFontStyleLB->save_value(); | |||
1210 | m_xWestFontSizeLB->save_value(); | |||
1211 | m_xWestFontLanguageLB->save_active_id(); | |||
1212 | m_xEastFontNameLB->save_value(); | |||
1213 | m_xEastFontStyleLB->save_value(); | |||
1214 | m_xEastFontSizeLB->save_value(); | |||
1215 | m_xEastFontLanguageLB->save_active_id(); | |||
1216 | m_xCTLFontNameLB->save_value(); | |||
1217 | m_xCTLFontStyleLB->save_value(); | |||
1218 | m_xCTLFontSizeLB->save_value(); | |||
1219 | m_xCTLFontLanguageLB->save_active_id(); | |||
1220 | } | |||
1221 | ||||
1222 | bool SvxCharNamePage::FillItemSet( SfxItemSet* rSet ) | |||
1223 | { | |||
1224 | bool bModified = FillItemSet_Impl( *rSet, Western ); | |||
1225 | bModified |= FillItemSet_Impl( *rSet, Asian ); | |||
1226 | bModified |= FillItemSet_Impl( *rSet, Ctl ); | |||
1227 | return bModified; | |||
1228 | } | |||
1229 | ||||
1230 | void SvxCharNamePage::SetFontList( const SvxFontListItem& rItem ) | |||
1231 | { | |||
1232 | m_pImpl->m_pFontList = rItem.GetFontList()->Clone(); | |||
1233 | } | |||
1234 | ||||
1235 | namespace | |||
1236 | { | |||
1237 | void enableRelativeMode( SvxCharNamePage const * _pPage, FontSizeBox* _pFontSizeLB, sal_uInt16 _nHeightWhich ) | |||
1238 | { | |||
1239 | _pFontSizeLB->EnableRelativeMode( 5, 995 ); // min 5%, max 995%, step 5 | |||
1240 | ||||
1241 | const SvxFontHeightItem& rHeightItem = | |||
1242 | static_cast<const SvxFontHeightItem&>(_pPage->GetItemSet().GetParent()->Get( _nHeightWhich )); | |||
1243 | MapUnit eUnit = _pPage->GetItemSet().GetPool()->GetMetric( _nHeightWhich ); | |||
1244 | short nCurHeight = | |||
1245 | static_cast< short >( CalcToPoint( rHeightItem.GetHeight(), eUnit, 1 ) * 10 ); | |||
1246 | ||||
1247 | // based on the current height: | |||
1248 | // - negative until minimum of 2 pt | |||
1249 | // - positive until maximum of 999 pt | |||
1250 | _pFontSizeLB->EnablePtRelativeMode( sal::static_int_cast< short >(-(nCurHeight - 20)), (9999 - nCurHeight) ); | |||
1251 | } | |||
1252 | } | |||
1253 | ||||
1254 | void SvxCharNamePage::EnableRelativeMode() | |||
1255 | { | |||
1256 | DBG_ASSERT( GetItemSet().GetParent(), "RelativeMode, but no ParentSet!" )do { if (true && (!(GetItemSet().GetParent()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "1256" ": "), "%s", "RelativeMode, but no ParentSet!"); } } while (false); | |||
1257 | enableRelativeMode(this,m_xWestFontSizeLB.get(),GetWhich( SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ) )); | |||
1258 | enableRelativeMode(this,m_xEastFontSizeLB.get(),GetWhich( SID_ATTR_CHAR_CJK_FONTHEIGHT( 10000 + 888 ) )); | |||
1259 | enableRelativeMode(this,m_xCTLFontSizeLB.get(),GetWhich( SID_ATTR_CHAR_CTL_FONTHEIGHT( 10000 + 893 ) )); | |||
1260 | } | |||
1261 | ||||
1262 | void SvxCharNamePage::EnableSearchMode() | |||
1263 | { | |||
1264 | m_pImpl->m_bInSearchMode = true; | |||
1265 | } | |||
1266 | ||||
1267 | void SvxCharNamePage::DisableControls( sal_uInt16 nDisable ) | |||
1268 | { | |||
1269 | if ( DISABLE_HIDE_LANGUAGE(sal_uInt16(0x0020)) & nDisable ) | |||
1270 | { | |||
1271 | if ( m_xWestFontLanguageFT ) m_xWestFontLanguageFT->hide(); | |||
1272 | if ( m_xWestFontLanguageLB ) m_xWestFontLanguageLB->hide(); | |||
1273 | if ( m_xEastFontLanguageFT ) m_xEastFontLanguageFT->hide(); | |||
1274 | if ( m_xEastFontLanguageLB ) m_xEastFontLanguageLB->hide(); | |||
1275 | if ( m_xCTLFontLanguageFT ) m_xCTLFontLanguageFT->hide(); | |||
1276 | if ( m_xCTLFontLanguageLB ) m_xCTLFontLanguageLB->hide(); | |||
1277 | } | |||
1278 | } | |||
1279 | ||||
1280 | void SvxCharNamePage::PageCreated(const SfxAllItemSet& aSet) | |||
1281 | { | |||
1282 | const SvxFontListItem* pFontListItem = aSet.GetItem<SvxFontListItem>(SID_ATTR_CHAR_FONTLIST( 10000 + 22 ), false); | |||
1283 | const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_FLAG_TYPE( 10000 + 1034 ), false); | |||
1284 | const SfxUInt16Item* pDisableItem = aSet.GetItem<SfxUInt16Item>(SID_DISABLE_CTL( 10000 + 1036 ), false); | |||
1285 | if (pFontListItem) | |||
1286 | SetFontList(*pFontListItem); | |||
1287 | ||||
1288 | if (pFlagItem) | |||
1289 | { | |||
1290 | sal_uInt32 nFlags=pFlagItem->GetValue(); | |||
1291 | if ( ( nFlags & SVX_RELATIVE_MODE0x02 ) == SVX_RELATIVE_MODE0x02 ) | |||
1292 | EnableRelativeMode(); | |||
1293 | if ( ( nFlags & SVX_PREVIEW_CHARACTER0x01 ) == SVX_PREVIEW_CHARACTER0x01 ) | |||
1294 | // the writer uses SID_ATTR_BRUSH as font background | |||
1295 | m_bPreviewBackgroundToCharacter = true; | |||
1296 | } | |||
1297 | if (pDisableItem) | |||
1298 | DisableControls(pDisableItem->GetValue()); | |||
1299 | } | |||
1300 | // class SvxCharEffectsPage ---------------------------------------------- | |||
1301 | ||||
1302 | SvxCharEffectsPage::SvxCharEffectsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInSet) | |||
1303 | : SvxCharBasePage(pPage, pController, "cui/ui/effectspage.ui", "EffectsPage", rInSet) | |||
1304 | , m_bOrigFontColor(false) | |||
1305 | , m_bNewFontColor(false) | |||
1306 | , m_bEnableNoneFontColor(false) | |||
1307 | , m_xFontColorFT(m_xBuilder->weld_label("fontcolorft")) | |||
1308 | , m_xFontColorLB(new ColorListBox(m_xBuilder->weld_menu_button("fontcolorlb"), pController->getDialog())) | |||
1309 | , m_xFontTransparencyFT(m_xBuilder->weld_label("fonttransparencyft")) | |||
1310 | , m_xFontTransparencyMtr( | |||
1311 | m_xBuilder->weld_metric_spin_button("fonttransparencymtr", FieldUnit::PERCENT)) | |||
1312 | , m_xEffectsFT(m_xBuilder->weld_label("effectsft")) | |||
1313 | , m_xEffectsLB(m_xBuilder->weld_combo_box("effectslb")) | |||
1314 | , m_xReliefFT(m_xBuilder->weld_label("reliefft")) | |||
1315 | , m_xReliefLB(m_xBuilder->weld_combo_box("relieflb")) | |||
1316 | , m_xOutlineBtn(m_xBuilder->weld_check_button("outlinecb")) | |||
1317 | , m_xShadowBtn(m_xBuilder->weld_check_button("shadowcb")) | |||
1318 | , m_xHiddenBtn(m_xBuilder->weld_check_button("hiddencb")) | |||
1319 | , m_xOverlineLB(m_xBuilder->weld_combo_box("overlinelb")) | |||
1320 | , m_xOverlineColorFT(m_xBuilder->weld_label("overlinecolorft")) | |||
1321 | , m_xOverlineColorLB(new ColorListBox(m_xBuilder->weld_menu_button("overlinecolorlb"), pController->getDialog())) | |||
1322 | , m_xStrikeoutLB(m_xBuilder->weld_combo_box("strikeoutlb")) | |||
1323 | , m_xUnderlineLB(m_xBuilder->weld_combo_box("underlinelb")) | |||
1324 | , m_xUnderlineColorFT(m_xBuilder->weld_label("underlinecolorft")) | |||
1325 | , m_xUnderlineColorLB(new ColorListBox(m_xBuilder->weld_menu_button("underlinecolorlb"), pController->getDialog())) | |||
1326 | , m_xIndividualWordsBtn(m_xBuilder->weld_check_button("individualwordscb")) | |||
1327 | , m_xEmphasisFT(m_xBuilder->weld_label("emphasisft")) | |||
1328 | , m_xEmphasisLB(m_xBuilder->weld_combo_box("emphasislb")) | |||
1329 | , m_xPositionFT(m_xBuilder->weld_label("positionft")) | |||
1330 | , m_xPositionLB(m_xBuilder->weld_combo_box("positionlb")) | |||
1331 | , m_xA11yWarningFT(m_xBuilder->weld_label("a11ywarning")) | |||
1332 | { | |||
1333 | m_xPreviewWin.reset(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWin)); | |||
1334 | #ifdef IOS | |||
1335 | m_xPreviewWin->hide(); | |||
1336 | #endif | |||
1337 | m_xFontColorLB->SetSlotId(SID_ATTR_CHAR_COLOR( 10000 + 17 )); | |||
1338 | m_xOverlineColorLB->SetSlotId(SID_ATTR_CHAR_COLOR( 10000 + 17 )); | |||
1339 | m_xUnderlineColorLB->SetSlotId(SID_ATTR_CHAR_COLOR( 10000 + 17 )); | |||
1340 | Initialize(); | |||
1341 | } | |||
1342 | ||||
1343 | void SvxCharEffectsPage::EnableNoneFontColor() | |||
1344 | { | |||
1345 | m_xFontColorLB->SetSlotId(SID_ATTR_CHAR_COLOR( 10000 + 17 ), true); | |||
1346 | m_bEnableNoneFontColor = true; | |||
1347 | } | |||
1348 | ||||
1349 | Color SvxCharEffectsPage::GetPreviewFontColor(const Color& rColor) const | |||
1350 | { | |||
1351 | if (rColor == COL_AUTO) | |||
1352 | return COL_BLACK; | |||
1353 | if (m_bEnableNoneFontColor && rColor == COL_NONE_COLOR::Color(0x80, 0xFF, 0xFF, 0xFF)) | |||
1354 | return COL_BLACK; | |||
1355 | return rColor; | |||
1356 | } | |||
1357 | ||||
1358 | SvxCharEffectsPage::~SvxCharEffectsPage() | |||
1359 | { | |||
1360 | m_xUnderlineColorLB.reset(); | |||
1361 | m_xOverlineColorLB.reset(); | |||
1362 | m_xFontTransparencyMtr.reset(); | |||
1363 | m_xFontColorLB.reset(); | |||
1364 | } | |||
1365 | ||||
1366 | void SvxCharEffectsPage::Initialize() | |||
1367 | { | |||
1368 | // to handle the changes of the other pages | |||
1369 | SetExchangeSupport(); | |||
1370 | ||||
1371 | // HTML-Mode | |||
1372 | const SfxPoolItem* pItem; | |||
1373 | SfxObjectShell* pShell; | |||
1374 | if ( SfxItemState::SET == GetItemSet().GetItemState( SID_HTML_MODE(10000 + 414), false, &pItem ) || | |||
1375 | ( nullptr != ( pShell = SfxObjectShell::Current() ) && | |||
1376 | nullptr != ( pItem = pShell->GetItem( SID_HTML_MODE(10000 + 414) ) ) ) ) | |||
1377 | { | |||
1378 | m_nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
1379 | if ( ( m_nHtmlMode & HTMLMODE_ON ) == HTMLMODE_ON ) | |||
1380 | { | |||
1381 | //!!! hide some controls please | |||
1382 | } | |||
1383 | } | |||
1384 | ||||
1385 | m_xFontColorLB->SetSelectHdl(LINK(this, SvxCharEffectsPage, ColorBoxSelectHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharEffectsPage *>(this), &SvxCharEffectsPage::LinkStubColorBoxSelectHdl_Impl )); | |||
1386 | m_xFontTransparencyMtr->connect_value_changed( | |||
1387 | LINK(this, SvxCharEffectsPage, ModifyFontTransparencyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharEffectsPage *>(this), &SvxCharEffectsPage::LinkStubModifyFontTransparencyHdl_Impl )); | |||
1388 | ||||
1389 | // handler | |||
1390 | Link<weld::ComboBox&,void> aLink = LINK( this, SvxCharEffectsPage, SelectListBoxHdl_Impl )::tools::detail::makeLink( ::tools::detail::castTo<SvxCharEffectsPage *>(this), &SvxCharEffectsPage::LinkStubSelectListBoxHdl_Impl ); | |||
1391 | m_xUnderlineLB->connect_changed( aLink ); | |||
1392 | m_xUnderlineColorLB->SetSelectHdl(LINK(this, SvxCharEffectsPage, ColorBoxSelectHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharEffectsPage *>(this), &SvxCharEffectsPage::LinkStubColorBoxSelectHdl_Impl )); | |||
1393 | m_xOverlineLB->connect_changed( aLink ); | |||
1394 | m_xOverlineColorLB->SetSelectHdl(LINK(this, SvxCharEffectsPage, ColorBoxSelectHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharEffectsPage *>(this), &SvxCharEffectsPage::LinkStubColorBoxSelectHdl_Impl )); | |||
1395 | m_xStrikeoutLB->connect_changed( aLink ); | |||
1396 | m_xEmphasisLB->connect_changed( aLink ); | |||
1397 | m_xPositionLB->connect_changed( aLink ); | |||
1398 | m_xEffectsLB->connect_changed( aLink ); | |||
1399 | m_xReliefLB->connect_changed( aLink ); | |||
1400 | ||||
1401 | m_xUnderlineLB->set_active( 0 ); | |||
1402 | m_xOverlineLB->set_active( 0 ); | |||
1403 | m_xStrikeoutLB->set_active( 0 ); | |||
1404 | m_xEmphasisLB->set_active( 0 ); | |||
1405 | m_xPositionLB->set_active( 0 ); | |||
1406 | SelectHdl_Impl(nullptr); | |||
1407 | SelectHdl_Impl(m_xEmphasisLB.get()); | |||
1408 | ||||
1409 | m_xEffectsLB->set_active( 0 ); | |||
1410 | ||||
1411 | m_xHiddenBtn->connect_toggled(LINK(this, SvxCharEffectsPage, HiddenBtnClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharEffectsPage *>(this), &SvxCharEffectsPage::LinkStubHiddenBtnClickHdl )); | |||
1412 | m_xIndividualWordsBtn->connect_toggled(LINK(this, SvxCharEffectsPage, CbClickHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharEffectsPage *>(this), &SvxCharEffectsPage::LinkStubCbClickHdl_Impl )); | |||
1413 | m_xOutlineBtn->connect_toggled(LINK(this, SvxCharEffectsPage, OutlineBtnClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharEffectsPage *>(this), &SvxCharEffectsPage::LinkStubOutlineBtnClickHdl )); | |||
1414 | m_xShadowBtn->connect_toggled(LINK(this, SvxCharEffectsPage, ShadowBtnClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharEffectsPage *>(this), &SvxCharEffectsPage::LinkStubShadowBtnClickHdl )); | |||
1415 | ||||
1416 | if ( !SvtLanguageOptions().IsAsianTypographyEnabled() ) | |||
1417 | { | |||
1418 | m_xEmphasisFT->hide(); | |||
1419 | m_xEmphasisLB->hide(); | |||
1420 | m_xPositionFT->hide(); | |||
1421 | m_xPositionLB->hide(); | |||
1422 | } | |||
1423 | ||||
1424 | m_xA11yWarningFT->set_visible(officecfg::Office::Common::Accessibility::IsAutomaticFontColor::get()); | |||
1425 | } | |||
1426 | ||||
1427 | void SvxCharEffectsPage::UpdatePreview_Impl() | |||
1428 | { | |||
1429 | SvxFont& rFont = GetPreviewFont(); | |||
1430 | SvxFont& rCJKFont = GetPreviewCJKFont(); | |||
1431 | SvxFont& rCTLFont = GetPreviewCTLFont(); | |||
1432 | ||||
1433 | const Color& rSelectedColor = m_xFontColorLB->GetSelectEntryColor(); | |||
1434 | rFont.SetColor(GetPreviewFontColor(rSelectedColor)); | |||
1435 | rCJKFont.SetColor(GetPreviewFontColor(rSelectedColor)); | |||
1436 | rCTLFont.SetColor(GetPreviewFontColor(rSelectedColor)); | |||
1437 | ||||
1438 | FontLineStyle eUnderline = static_cast<FontLineStyle>(m_xUnderlineLB->get_active_id().toInt32()); | |||
1439 | FontLineStyle eOverline = static_cast<FontLineStyle>(m_xOverlineLB->get_active_id().toInt32()); | |||
1440 | FontStrikeout eStrikeout = static_cast<FontStrikeout>(m_xStrikeoutLB->get_active_id().toInt32()); | |||
1441 | rFont.SetUnderline( eUnderline ); | |||
1442 | rCJKFont.SetUnderline( eUnderline ); | |||
1443 | rCTLFont.SetUnderline( eUnderline ); | |||
1444 | m_aPreviewWin.SetTextLineColor( m_xUnderlineColorLB->GetSelectEntryColor() ); | |||
1445 | rFont.SetOverline( eOverline ); | |||
1446 | rCJKFont.SetOverline( eOverline ); | |||
1447 | rCTLFont.SetOverline( eOverline ); | |||
1448 | m_aPreviewWin.SetOverlineColor( m_xOverlineColorLB->GetSelectEntryColor() ); | |||
1449 | rFont.SetStrikeout( eStrikeout ); | |||
1450 | rCJKFont.SetStrikeout( eStrikeout ); | |||
1451 | rCTLFont.SetStrikeout( eStrikeout ); | |||
1452 | ||||
1453 | auto nEmphasis = m_xEmphasisLB->get_active(); | |||
1454 | if (nEmphasis != -1) | |||
1455 | { | |||
1456 | bool bUnder = (CHRDLG_POSITION_UNDER1 == m_xPositionLB->get_active_id().toInt32()); | |||
1457 | FontEmphasisMark eMark = static_cast<FontEmphasisMark>(nEmphasis); | |||
1458 | eMark |= bUnder ? FontEmphasisMark::PosBelow : FontEmphasisMark::PosAbove; | |||
1459 | rFont.SetEmphasisMark( eMark ); | |||
1460 | rCJKFont.SetEmphasisMark( eMark ); | |||
1461 | rCTLFont.SetEmphasisMark( eMark ); | |||
1462 | } | |||
1463 | ||||
1464 | auto nRelief = m_xReliefLB->get_active(); | |||
1465 | if (nRelief != -1) | |||
1466 | { | |||
1467 | rFont.SetRelief( static_cast<FontRelief>(nRelief) ); | |||
1468 | rCJKFont.SetRelief( static_cast<FontRelief>(nRelief) ); | |||
1469 | rCTLFont.SetRelief( static_cast<FontRelief>(nRelief) ); | |||
1470 | } | |||
1471 | ||||
1472 | rFont.SetOutline( StateToAttr( m_xOutlineBtn->get_state() ) ); | |||
1473 | rCJKFont.SetOutline( rFont.IsOutline() ); | |||
1474 | rCTLFont.SetOutline( rFont.IsOutline() ); | |||
1475 | ||||
1476 | rFont.SetShadow( StateToAttr( m_xShadowBtn->get_state() ) ); | |||
1477 | rCJKFont.SetShadow( rFont.IsShadow() ); | |||
1478 | rCTLFont.SetShadow( rFont.IsShadow() ); | |||
1479 | ||||
1480 | auto nCapsPos = m_xEffectsLB->get_active(); | |||
1481 | if (nCapsPos != -1) | |||
1482 | { | |||
1483 | SvxCaseMap eCaps = static_cast<SvxCaseMap>(nCapsPos); | |||
1484 | rFont.SetCaseMap( eCaps ); | |||
1485 | rCJKFont.SetCaseMap( eCaps ); | |||
1486 | // #i78474# small caps do not exist in CTL fonts | |||
1487 | rCTLFont.SetCaseMap( eCaps == SvxCaseMap::SmallCaps ? SvxCaseMap::NotMapped : eCaps ); | |||
1488 | } | |||
1489 | ||||
1490 | bool bWordLine = StateToAttr( m_xIndividualWordsBtn->get_state() ); | |||
1491 | rFont.SetWordLineMode( bWordLine ); | |||
1492 | rCJKFont.SetWordLineMode( bWordLine ); | |||
1493 | rCTLFont.SetWordLineMode( bWordLine ); | |||
1494 | ||||
1495 | m_aPreviewWin.Invalidate(); | |||
1496 | } | |||
1497 | ||||
1498 | void SvxCharEffectsPage::SetCaseMap_Impl( SvxCaseMap eCaseMap ) | |||
1499 | { | |||
1500 | if ( SvxCaseMap::End > eCaseMap ) | |||
1501 | m_xEffectsLB->set_active( | |||
1502 | sal::static_int_cast< sal_Int32 >( eCaseMap ) ); | |||
1503 | else | |||
1504 | { | |||
1505 | // not mapped | |||
1506 | m_xEffectsLB->set_active(-1); | |||
1507 | } | |||
1508 | ||||
1509 | UpdatePreview_Impl(); | |||
1510 | } | |||
1511 | ||||
1512 | void SvxCharEffectsPage::ResetColor_Impl( const SfxItemSet& rSet ) | |||
1513 | { | |||
1514 | sal_uInt16 nWhich = GetWhich( SID_ATTR_CHAR_COLOR( 10000 + 17 ) ); | |||
1515 | SfxItemState eState = rSet.GetItemState( nWhich ); | |||
1516 | ||||
1517 | m_bOrigFontColor = false; | |||
1518 | switch ( eState ) | |||
1519 | { | |||
1520 | case SfxItemState::UNKNOWN: | |||
1521 | m_xFontColorFT->hide(); | |||
1522 | m_xFontColorLB->hide(); | |||
1523 | break; | |||
1524 | ||||
1525 | case SfxItemState::DISABLED: | |||
1526 | case SfxItemState::READONLY: | |||
1527 | m_xFontColorFT->set_sensitive(false); | |||
1528 | m_xFontColorLB->set_sensitive(false); | |||
1529 | break; | |||
1530 | ||||
1531 | case SfxItemState::DONTCARE: | |||
1532 | //Related: tdf#106080 if there is no font color, then allow "none" | |||
1533 | //as a color so the listbox can display that state. | |||
1534 | EnableNoneFontColor(); | |||
1535 | m_xFontColorLB->SetNoSelection(); | |||
1536 | break; | |||
1537 | ||||
1538 | case SfxItemState::DEFAULT: | |||
1539 | case SfxItemState::SET: | |||
1540 | { | |||
1541 | SvxFont& rFont = GetPreviewFont(); | |||
1542 | SvxFont& rCJKFont = GetPreviewCJKFont(); | |||
1543 | SvxFont& rCTLFont = GetPreviewCTLFont(); | |||
1544 | ||||
1545 | const SvxColorItem& rItem = static_cast<const SvxColorItem&>(rSet.Get( nWhich )); | |||
1546 | Color aColor = rItem.GetValue(); | |||
1547 | rFont.SetColor(GetPreviewFontColor(aColor)); | |||
1548 | rCJKFont.SetColor(GetPreviewFontColor(aColor)); | |||
1549 | rCTLFont.SetColor(GetPreviewFontColor(aColor)); | |||
1550 | ||||
1551 | m_aPreviewWin.Invalidate(); | |||
1552 | ||||
1553 | Color aRGBColor = aColor; | |||
1554 | if (aRGBColor.GetTransparency() && aColor != COL_AUTO) | |||
1555 | { | |||
1556 | aRGBColor.SetTransparency(0); | |||
1557 | } | |||
1558 | m_xFontColorLB->SelectEntry(aRGBColor); | |||
1559 | ||||
1560 | if (m_xFontTransparencyMtr->get_visible() && aColor != COL_AUTO) | |||
1561 | { | |||
1562 | double fTransparency = aColor.GetTransparency() * 100.0 / 255; | |||
1563 | m_xFontTransparencyMtr->set_value(basegfx::fround(fTransparency), | |||
1564 | FieldUnit::PERCENT); | |||
1565 | } | |||
1566 | ||||
1567 | m_aOrigFontColor = aColor; | |||
1568 | m_bOrigFontColor = true; | |||
1569 | break; | |||
1570 | } | |||
1571 | } | |||
1572 | m_bNewFontColor = false; | |||
1573 | } | |||
1574 | ||||
1575 | bool SvxCharEffectsPage::FillItemSetColor_Impl( SfxItemSet& rSet ) | |||
1576 | { | |||
1577 | sal_uInt16 nWhich = GetWhich( SID_ATTR_CHAR_COLOR( 10000 + 17 ) ); | |||
1578 | const SfxItemSet& rOldSet = GetItemSet(); | |||
1579 | ||||
1580 | Color aSelectedColor; | |||
1581 | bool bChanged = m_bNewFontColor; | |||
1582 | ||||
1583 | if (bChanged) | |||
1584 | { | |||
1585 | aSelectedColor = m_xFontColorLB->GetSelectEntryColor(); | |||
1586 | ||||
1587 | if (m_xFontTransparencyMtr->get_value_changed_from_saved()) | |||
1588 | { | |||
1589 | double fTransparency | |||
1590 | = m_xFontTransparencyMtr->get_value(FieldUnit::PERCENT) * 255.0 / 100; | |||
1591 | aSelectedColor.SetTransparency(static_cast<sal_uInt8>(basegfx::fround(fTransparency))); | |||
1592 | } | |||
1593 | ||||
1594 | if (m_bOrigFontColor) | |||
1595 | bChanged = aSelectedColor != m_aOrigFontColor; | |||
1596 | if (m_bEnableNoneFontColor && bChanged && aSelectedColor == COL_NONE_COLOR::Color(0x80, 0xFF, 0xFF, 0xFF)) | |||
1597 | bChanged = false; | |||
1598 | } | |||
1599 | ||||
1600 | if (bChanged) | |||
1601 | rSet.Put( SvxColorItem( aSelectedColor, nWhich ) ); | |||
1602 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
1603 | rSet.InvalidateItem(nWhich); | |||
1604 | ||||
1605 | return bChanged; | |||
1606 | } | |||
1607 | ||||
1608 | IMPL_LINK( SvxCharEffectsPage, SelectListBoxHdl_Impl, weld::ComboBox&, rBox, void )void SvxCharEffectsPage::LinkStubSelectListBoxHdl_Impl(void * instance, weld::ComboBox& data) { return static_cast< SvxCharEffectsPage *>(instance)->SelectListBoxHdl_Impl( data); } void SvxCharEffectsPage::SelectListBoxHdl_Impl(weld:: ComboBox& rBox) | |||
1609 | { | |||
1610 | SelectHdl_Impl(&rBox); | |||
1611 | } | |||
1612 | ||||
1613 | void SvxCharEffectsPage::SelectHdl_Impl(const weld::ComboBox* pBox) | |||
1614 | { | |||
1615 | if (m_xEmphasisLB.get() == pBox) | |||
1616 | { | |||
1617 | auto nEPos = m_xEmphasisLB->get_active(); | |||
1618 | bool bEnable = nEPos > 0; | |||
1619 | m_xPositionFT->set_sensitive( bEnable ); | |||
1620 | m_xPositionLB->set_sensitive( bEnable ); | |||
1621 | } | |||
1622 | else if (m_xReliefLB.get() == pBox) | |||
1623 | { | |||
1624 | bool bEnable = ( pBox->get_active() == 0 ); | |||
| ||||
1625 | m_xOutlineBtn->set_sensitive( bEnable ); | |||
1626 | m_xShadowBtn->set_sensitive( bEnable ); | |||
1627 | } | |||
1628 | else if (m_xPositionLB.get() != pBox) | |||
1629 | { | |||
1630 | auto nUPos = m_xUnderlineLB->get_active(); | |||
1631 | bool bUEnable = nUPos > 0; | |||
1632 | m_xUnderlineColorFT->set_sensitive(bUEnable); | |||
1633 | m_xUnderlineColorLB->set_sensitive(bUEnable); | |||
1634 | ||||
1635 | auto nOPos = m_xOverlineLB->get_active(); | |||
1636 | bool bOEnable = nOPos > 0; | |||
1637 | m_xOverlineColorFT->set_sensitive(bOEnable); | |||
1638 | m_xOverlineColorLB->set_sensitive(bOEnable); | |||
1639 | ||||
1640 | auto nSPos = m_xStrikeoutLB->get_active(); | |||
1641 | m_xIndividualWordsBtn->set_sensitive( bUEnable || bOEnable || nSPos > 0); | |||
1642 | } | |||
1643 | UpdatePreview_Impl(); | |||
1644 | } | |||
1645 | ||||
1646 | IMPL_LINK(SvxCharEffectsPage, CbClickHdl_Impl, weld::ToggleButton&, rToggle, void)void SvxCharEffectsPage::LinkStubCbClickHdl_Impl(void * instance , weld::ToggleButton& data) { return static_cast<SvxCharEffectsPage *>(instance)->CbClickHdl_Impl(data); } void SvxCharEffectsPage ::CbClickHdl_Impl(weld::ToggleButton& rToggle) | |||
1647 | { | |||
1648 | m_aIndividualWordsState.ButtonToggled(rToggle); | |||
1649 | UpdatePreview_Impl(); | |||
1650 | UpdatePreview_Impl(); | |||
1651 | } | |||
1652 | ||||
1653 | IMPL_LINK(SvxCharEffectsPage, ColorBoxSelectHdl_Impl, ColorListBox&, rBox, void)void SvxCharEffectsPage::LinkStubColorBoxSelectHdl_Impl(void * instance, ColorListBox& data) { return static_cast<SvxCharEffectsPage *>(instance)->ColorBoxSelectHdl_Impl(data); } void SvxCharEffectsPage ::ColorBoxSelectHdl_Impl(ColorListBox& rBox) | |||
1654 | { | |||
1655 | if (m_xFontColorLB.get() == &rBox) | |||
1656 | m_bNewFontColor = true; | |||
1657 | UpdatePreview_Impl(); | |||
1658 | } | |||
1659 | ||||
1660 | IMPL_LINK_NOARG(SvxCharEffectsPage, ModifyFontTransparencyHdl_Impl, weld::MetricSpinButton&, void)void SvxCharEffectsPage::LinkStubModifyFontTransparencyHdl_Impl (void * instance, weld::MetricSpinButton& data) { return static_cast <SvxCharEffectsPage *>(instance)->ModifyFontTransparencyHdl_Impl (data); } void SvxCharEffectsPage::ModifyFontTransparencyHdl_Impl (__attribute__ ((unused)) weld::MetricSpinButton&) | |||
1661 | { | |||
1662 | m_bNewFontColor = true; | |||
1663 | } | |||
1664 | ||||
1665 | DeactivateRC SvxCharEffectsPage::DeactivatePage( SfxItemSet* _pSet ) | |||
1666 | { | |||
1667 | if ( _pSet ) | |||
1668 | FillItemSet( _pSet ); | |||
1669 | return DeactivateRC::LeavePage; | |||
1670 | } | |||
1671 | ||||
1672 | std::unique_ptr<SfxTabPage> SvxCharEffectsPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet ) | |||
1673 | { | |||
1674 | return std::make_unique<SvxCharEffectsPage>( pPage, pController, *rSet ); | |||
| ||||
1675 | } | |||
1676 | ||||
1677 | void SvxCharEffectsPage::Reset( const SfxItemSet* rSet ) | |||
1678 | { | |||
1679 | SvxFont& rFont = GetPreviewFont(); | |||
1680 | SvxFont& rCJKFont = GetPreviewCJKFont(); | |||
1681 | SvxFont& rCTLFont = GetPreviewCTLFont(); | |||
1682 | ||||
1683 | bool bEnable = false; | |||
1684 | ||||
1685 | // Underline | |||
1686 | sal_uInt16 nWhich = GetWhich( SID_ATTR_CHAR_UNDERLINE( 10000 + 14 ) ); | |||
1687 | rFont.SetUnderline( LINESTYLE_NONE ); | |||
1688 | rCJKFont.SetUnderline( LINESTYLE_NONE ); | |||
1689 | rCTLFont.SetUnderline( LINESTYLE_NONE ); | |||
1690 | ||||
1691 | m_xUnderlineLB->set_active( 0 ); | |||
1692 | SfxItemState eState = rSet->GetItemState( nWhich ); | |||
1693 | ||||
1694 | if ( eState >= SfxItemState::DONTCARE ) | |||
1695 | { | |||
1696 | if ( eState == SfxItemState::DONTCARE ) | |||
1697 | m_xUnderlineLB->set_active(-1); | |||
1698 | else | |||
1699 | { | |||
1700 | const SvxUnderlineItem& rItem = static_cast<const SvxUnderlineItem&>(rSet->Get( nWhich )); | |||
1701 | FontLineStyle eUnderline = rItem.GetValue(); | |||
1702 | rFont.SetUnderline( eUnderline ); | |||
1703 | rCJKFont.SetUnderline( eUnderline ); | |||
1704 | rCTLFont.SetUnderline( eUnderline ); | |||
1705 | ||||
1706 | if ( eUnderline != LINESTYLE_NONE ) | |||
1707 | { | |||
1708 | auto nPos = m_xUnderlineLB->find_id(OUString::number(eUnderline)); | |||
1709 | if (nPos != -1) | |||
1710 | { | |||
1711 | m_xUnderlineLB->set_active(nPos); | |||
1712 | bEnable = true; | |||
1713 | } | |||
1714 | Color aColor = rItem.GetColor(); | |||
1715 | m_xUnderlineColorLB->SelectEntry(aColor); | |||
1716 | } | |||
1717 | else | |||
1718 | { | |||
1719 | m_xUnderlineColorLB->SelectEntry(COL_AUTO); | |||
1720 | m_xUnderlineColorLB->set_sensitive(false); | |||
1721 | } | |||
1722 | } | |||
1723 | } | |||
1724 | ||||
1725 | // Overline | |||
1726 | nWhich = GetWhich( SID_ATTR_CHAR_OVERLINE( ((10000 + 1499) + 1) + 68 ) ); | |||
1727 | rFont.SetOverline( LINESTYLE_NONE ); | |||
1728 | rCJKFont.SetOverline( LINESTYLE_NONE ); | |||
1729 | rCTLFont.SetOverline( LINESTYLE_NONE ); | |||
1730 | ||||
1731 | m_xOverlineLB->set_active( 0 ); | |||
1732 | eState = rSet->GetItemState( nWhich ); | |||
1733 | ||||
1734 | if ( eState >= SfxItemState::DONTCARE ) | |||
1735 | { | |||
1736 | if ( eState == SfxItemState::DONTCARE ) | |||
1737 | m_xOverlineLB->set_active(-1); | |||
1738 | else | |||
1739 | { | |||
1740 | const SvxOverlineItem& rItem = static_cast<const SvxOverlineItem&>(rSet->Get( nWhich )); | |||
1741 | FontLineStyle eOverline = rItem.GetValue(); | |||
1742 | rFont.SetOverline( eOverline ); | |||
1743 | rCJKFont.SetOverline( eOverline ); | |||
1744 | rCTLFont.SetOverline( eOverline ); | |||
1745 | ||||
1746 | if ( eOverline != LINESTYLE_NONE ) | |||
1747 | { | |||
1748 | auto nPos = m_xOverlineLB->find_id(OUString::number(eOverline)); | |||
1749 | if (nPos != -1) | |||
1750 | { | |||
1751 | m_xOverlineLB->set_active(nPos); | |||
1752 | bEnable = true; | |||
1753 | } | |||
1754 | Color aColor = rItem.GetColor(); | |||
1755 | m_xOverlineColorLB->SelectEntry(aColor); | |||
1756 | } | |||
1757 | else | |||
1758 | { | |||
1759 | m_xOverlineColorLB->SelectEntry(COL_AUTO); | |||
1760 | m_xOverlineColorLB->set_sensitive(false); | |||
1761 | } | |||
1762 | } | |||
1763 | } | |||
1764 | ||||
1765 | // Strikeout | |||
1766 | nWhich = GetWhich( SID_ATTR_CHAR_STRIKEOUT( 10000 + 13 ) ); | |||
1767 | rFont.SetStrikeout( STRIKEOUT_NONE ); | |||
1768 | rCJKFont.SetStrikeout( STRIKEOUT_NONE ); | |||
1769 | rCTLFont.SetStrikeout( STRIKEOUT_NONE ); | |||
1770 | ||||
1771 | m_xStrikeoutLB->set_active( 0 ); | |||
1772 | eState = rSet->GetItemState( nWhich ); | |||
1773 | ||||
1774 | if ( eState >= SfxItemState::DONTCARE ) | |||
1775 | { | |||
1776 | if ( eState == SfxItemState::DONTCARE ) | |||
1777 | m_xStrikeoutLB->set_active(-1); | |||
1778 | else | |||
1779 | { | |||
1780 | const SvxCrossedOutItem& rItem = static_cast<const SvxCrossedOutItem&>(rSet->Get( nWhich )); | |||
1781 | FontStrikeout eStrikeout = rItem.GetValue(); | |||
1782 | rFont.SetStrikeout( eStrikeout ); | |||
1783 | rCJKFont.SetStrikeout( eStrikeout ); | |||
1784 | rCTLFont.SetStrikeout( eStrikeout ); | |||
1785 | ||||
1786 | if ( eStrikeout != STRIKEOUT_NONE ) | |||
1787 | { | |||
1788 | auto nPos = m_xStrikeoutLB->find_id(OUString::number(eStrikeout)); | |||
1789 | if (nPos != -1) | |||
1790 | { | |||
1791 | m_xStrikeoutLB->set_active(nPos); | |||
1792 | bEnable = true; | |||
1793 | } | |||
1794 | } | |||
1795 | } | |||
1796 | } | |||
1797 | ||||
1798 | // WordLineMode | |||
1799 | nWhich = GetWhich( SID_ATTR_CHAR_WORDLINEMODE( 10000 + 11 ) ); | |||
1800 | eState = rSet->GetItemState( nWhich ); | |||
1801 | ||||
1802 | switch ( eState ) | |||
1803 | { | |||
1804 | case SfxItemState::UNKNOWN: | |||
1805 | m_aIndividualWordsState.bTriStateEnabled = false; | |||
1806 | m_xIndividualWordsBtn->hide(); | |||
1807 | break; | |||
1808 | ||||
1809 | case SfxItemState::DISABLED: | |||
1810 | case SfxItemState::READONLY: | |||
1811 | m_aIndividualWordsState.bTriStateEnabled = false; | |||
1812 | m_xIndividualWordsBtn->set_sensitive(false); | |||
1813 | break; | |||
1814 | ||||
1815 | case SfxItemState::DONTCARE: | |||
1816 | m_aIndividualWordsState.bTriStateEnabled = true; | |||
1817 | m_xIndividualWordsBtn->set_state( TRISTATE_INDET ); | |||
1818 | break; | |||
1819 | ||||
1820 | case SfxItemState::DEFAULT: | |||
1821 | case SfxItemState::SET: | |||
1822 | { | |||
1823 | const SvxWordLineModeItem& rItem = static_cast<const SvxWordLineModeItem&>(rSet->Get( nWhich )); | |||
1824 | rFont.SetWordLineMode( rItem.GetValue() ); | |||
1825 | rCJKFont.SetWordLineMode( rItem.GetValue() ); | |||
1826 | rCTLFont.SetWordLineMode( rItem.GetValue() ); | |||
1827 | ||||
1828 | m_aIndividualWordsState.bTriStateEnabled = false; | |||
1829 | m_xIndividualWordsBtn->set_active(rItem.GetValue()); | |||
1830 | m_xIndividualWordsBtn->set_sensitive(bEnable); | |||
1831 | break; | |||
1832 | } | |||
1833 | } | |||
1834 | ||||
1835 | // Emphasis | |||
1836 | nWhich = GetWhich( SID_ATTR_CHAR_EMPHASISMARK( 10000 + 899 ) ); | |||
1837 | eState = rSet->GetItemState( nWhich ); | |||
1838 | ||||
1839 | if ( eState >= SfxItemState::DEFAULT ) | |||
1840 | { | |||
1841 | const SvxEmphasisMarkItem& rItem = static_cast<const SvxEmphasisMarkItem&>(rSet->Get( nWhich )); | |||
1842 | FontEmphasisMark eMark = rItem.GetEmphasisMark(); | |||
1843 | rFont.SetEmphasisMark( eMark ); | |||
1844 | rCJKFont.SetEmphasisMark( eMark ); | |||
1845 | rCTLFont.SetEmphasisMark( eMark ); | |||
1846 | ||||
1847 | m_xEmphasisLB->set_active( static_cast<sal_Int32>(FontEmphasisMark( eMark & FontEmphasisMark::Style )) ); | |||
1848 | eMark &= ~FontEmphasisMark::Style; | |||
1849 | int nEntryData = ( eMark == FontEmphasisMark::PosAbove ) | |||
1850 | ? CHRDLG_POSITION_OVER0 | |||
1851 | : ( eMark == FontEmphasisMark::PosBelow ) ? CHRDLG_POSITION_UNDER1 : 0; | |||
1852 | ||||
1853 | auto nPos = m_xPositionLB->find_id(OUString::number(nEntryData)); | |||
1854 | if (nPos != -1) | |||
1855 | m_xPositionLB->set_active(nPos); | |||
1856 | } | |||
1857 | else if ( eState == SfxItemState::DONTCARE ) | |||
1858 | m_xEmphasisLB->set_active(-1); | |||
1859 | else if ( eState == SfxItemState::UNKNOWN ) | |||
1860 | { | |||
1861 | m_xEmphasisFT->hide(); | |||
1862 | m_xEmphasisLB->hide(); | |||
1863 | } | |||
1864 | else // SfxItemState::DISABLED or SfxItemState::READONLY | |||
1865 | { | |||
1866 | m_xEmphasisFT->set_sensitive(false); | |||
1867 | m_xEmphasisLB->set_sensitive(false); | |||
1868 | } | |||
1869 | ||||
1870 | // the select handler for the underline/overline/strikeout list boxes | |||
1871 | SelectHdl_Impl(m_xUnderlineLB.get()); | |||
1872 | ||||
1873 | // the select handler for the emphasis listbox | |||
1874 | SelectHdl_Impl(m_xEmphasisLB.get()); | |||
1875 | ||||
1876 | // Effects | |||
1877 | SvxCaseMap eCaseMap = SvxCaseMap::End; | |||
1878 | nWhich = GetWhich( SID_ATTR_CHAR_CASEMAP( 10000 + 19 ) ); | |||
1879 | eState = rSet->GetItemState( nWhich ); | |||
1880 | switch ( eState ) | |||
1881 | { | |||
1882 | case SfxItemState::UNKNOWN: | |||
1883 | m_xEffectsFT->hide(); | |||
1884 | m_xEffectsLB->hide(); | |||
1885 | break; | |||
1886 | ||||
1887 | case SfxItemState::DISABLED: | |||
1888 | case SfxItemState::READONLY: | |||
1889 | m_xEffectsFT->set_sensitive(false); | |||
1890 | m_xEffectsLB->set_sensitive(false); | |||
1891 | break; | |||
1892 | ||||
1893 | case SfxItemState::DONTCARE: | |||
1894 | m_xEffectsLB->set_active(-1); | |||
1895 | break; | |||
1896 | ||||
1897 | case SfxItemState::DEFAULT: | |||
1898 | case SfxItemState::SET: | |||
1899 | { | |||
1900 | const SvxCaseMapItem& rItem = static_cast<const SvxCaseMapItem&>(rSet->Get( nWhich )); | |||
1901 | eCaseMap = rItem.GetValue(); | |||
1902 | break; | |||
1903 | } | |||
1904 | } | |||
1905 | SetCaseMap_Impl( eCaseMap ); | |||
1906 | ||||
1907 | //Relief | |||
1908 | nWhich = GetWhich(SID_ATTR_CHAR_RELIEF( 10000 + 920 )); | |||
1909 | eState = rSet->GetItemState( nWhich ); | |||
1910 | switch ( eState ) | |||
1911 | { | |||
1912 | case SfxItemState::UNKNOWN: | |||
1913 | m_xReliefFT->hide(); | |||
1914 | m_xReliefLB->hide(); | |||
1915 | break; | |||
1916 | ||||
1917 | case SfxItemState::DISABLED: | |||
1918 | case SfxItemState::READONLY: | |||
1919 | m_xReliefFT->set_sensitive(false); | |||
1920 | m_xReliefLB->set_sensitive(false); | |||
1921 | break; | |||
1922 | ||||
1923 | case SfxItemState::DONTCARE: | |||
1924 | m_xReliefLB->set_active(-1); | |||
1925 | break; | |||
1926 | ||||
1927 | case SfxItemState::DEFAULT: | |||
1928 | case SfxItemState::SET: | |||
1929 | { | |||
1930 | const SvxCharReliefItem& rItem = static_cast<const SvxCharReliefItem&>(rSet->Get( nWhich )); | |||
1931 | m_xReliefLB->set_active(static_cast<sal_Int32>(rItem.GetValue())); | |||
1932 | SelectHdl_Impl(m_xReliefLB.get()); | |||
1933 | break; | |||
1934 | } | |||
1935 | } | |||
1936 | ||||
1937 | // Outline | |||
1938 | nWhich = GetWhich( SID_ATTR_CHAR_CONTOUR( 10000 + 12 ) ); | |||
1939 | eState = rSet->GetItemState( nWhich ); | |||
1940 | switch ( eState ) | |||
1941 | { | |||
1942 | case SfxItemState::UNKNOWN: | |||
1943 | m_aOutlineState.bTriStateEnabled = false; | |||
1944 | m_xOutlineBtn->hide(); | |||
1945 | break; | |||
1946 | ||||
1947 | case SfxItemState::DISABLED: | |||
1948 | case SfxItemState::READONLY: | |||
1949 | m_aOutlineState.bTriStateEnabled = false; | |||
1950 | m_xOutlineBtn->set_sensitive(false); | |||
1951 | break; | |||
1952 | ||||
1953 | case SfxItemState::DONTCARE: | |||
1954 | m_aOutlineState.bTriStateEnabled = true; | |||
1955 | m_xOutlineBtn->set_state(TRISTATE_INDET); | |||
1956 | break; | |||
1957 | ||||
1958 | case SfxItemState::DEFAULT: | |||
1959 | case SfxItemState::SET: | |||
1960 | { | |||
1961 | const SvxContourItem& rItem = static_cast<const SvxContourItem&>(rSet->Get( nWhich )); | |||
1962 | m_aOutlineState.bTriStateEnabled = false; | |||
1963 | m_xOutlineBtn->set_state(static_cast<TriState>(rItem.GetValue())); | |||
1964 | break; | |||
1965 | } | |||
1966 | } | |||
1967 | ||||
1968 | // Shadow | |||
1969 | nWhich = GetWhich( SID_ATTR_CHAR_SHADOWED( 10000 + 10 ) ); | |||
1970 | eState = rSet->GetItemState( nWhich ); | |||
1971 | ||||
1972 | switch ( eState ) | |||
1973 | { | |||
1974 | case SfxItemState::UNKNOWN: | |||
1975 | m_aShadowState.bTriStateEnabled = false; | |||
1976 | m_xShadowBtn->hide(); | |||
1977 | break; | |||
1978 | ||||
1979 | case SfxItemState::DISABLED: | |||
1980 | case SfxItemState::READONLY: | |||
1981 | m_aShadowState.bTriStateEnabled = false; | |||
1982 | m_xShadowBtn->set_sensitive(false); | |||
1983 | break; | |||
1984 | ||||
1985 | case SfxItemState::DONTCARE: | |||
1986 | m_aShadowState.bTriStateEnabled = true; | |||
1987 | m_xShadowBtn->set_state( TRISTATE_INDET ); | |||
1988 | break; | |||
1989 | ||||
1990 | case SfxItemState::DEFAULT: | |||
1991 | case SfxItemState::SET: | |||
1992 | { | |||
1993 | const SvxShadowedItem& rItem = static_cast<const SvxShadowedItem&>(rSet->Get( nWhich )); | |||
1994 | m_aShadowState.bTriStateEnabled = false; | |||
1995 | m_xShadowBtn->set_state( static_cast<TriState>(rItem.GetValue()) ); | |||
1996 | break; | |||
1997 | } | |||
1998 | } | |||
1999 | ||||
2000 | // Hidden | |||
2001 | nWhich = GetWhich( SID_ATTR_CHAR_HIDDEN( 10000 + 989 ) ); | |||
2002 | eState = rSet->GetItemState( nWhich ); | |||
2003 | ||||
2004 | switch ( eState ) | |||
2005 | { | |||
2006 | case SfxItemState::UNKNOWN: | |||
2007 | m_aHiddenState.bTriStateEnabled = false; | |||
2008 | m_xHiddenBtn->hide(); | |||
2009 | break; | |||
2010 | ||||
2011 | case SfxItemState::DISABLED: | |||
2012 | case SfxItemState::READONLY: | |||
2013 | m_aHiddenState.bTriStateEnabled = false; | |||
2014 | m_xHiddenBtn->set_sensitive(false); | |||
2015 | break; | |||
2016 | ||||
2017 | case SfxItemState::DONTCARE: | |||
2018 | m_aHiddenState.bTriStateEnabled = true; | |||
2019 | m_xHiddenBtn->set_state(TRISTATE_INDET); | |||
2020 | break; | |||
2021 | ||||
2022 | case SfxItemState::DEFAULT: | |||
2023 | case SfxItemState::SET: | |||
2024 | { | |||
2025 | const SvxCharHiddenItem& rItem = static_cast<const SvxCharHiddenItem&>(rSet->Get( nWhich )); | |||
2026 | m_aHiddenState.bTriStateEnabled = false; | |||
2027 | m_xHiddenBtn->set_state(static_cast<TriState>(rItem.GetValue())); | |||
2028 | break; | |||
2029 | } | |||
2030 | } | |||
2031 | ||||
2032 | SetPrevFontWidthScale( *rSet ); | |||
2033 | ResetColor_Impl( *rSet ); | |||
2034 | ||||
2035 | // preview update | |||
2036 | m_aPreviewWin.Invalidate(); | |||
2037 | ||||
2038 | // save this settings | |||
2039 | ChangesApplied(); | |||
2040 | } | |||
2041 | ||||
2042 | IMPL_LINK(SvxCharEffectsPage, HiddenBtnClickHdl, weld::ToggleButton&, rToggle, void)void SvxCharEffectsPage::LinkStubHiddenBtnClickHdl(void * instance , weld::ToggleButton& data) { return static_cast<SvxCharEffectsPage *>(instance)->HiddenBtnClickHdl(data); } void SvxCharEffectsPage ::HiddenBtnClickHdl(weld::ToggleButton& rToggle) | |||
2043 | { | |||
2044 | m_aHiddenState.ButtonToggled(rToggle); | |||
2045 | } | |||
2046 | ||||
2047 | IMPL_LINK(SvxCharEffectsPage, OutlineBtnClickHdl, weld::ToggleButton&, rToggle, void)void SvxCharEffectsPage::LinkStubOutlineBtnClickHdl(void * instance , weld::ToggleButton& data) { return static_cast<SvxCharEffectsPage *>(instance)->OutlineBtnClickHdl(data); } void SvxCharEffectsPage ::OutlineBtnClickHdl(weld::ToggleButton& rToggle) | |||
2048 | { | |||
2049 | m_aOutlineState.ButtonToggled(rToggle); | |||
2050 | UpdatePreview_Impl(); | |||
2051 | } | |||
2052 | ||||
2053 | IMPL_LINK(SvxCharEffectsPage, ShadowBtnClickHdl, weld::ToggleButton&, rToggle, void)void SvxCharEffectsPage::LinkStubShadowBtnClickHdl(void * instance , weld::ToggleButton& data) { return static_cast<SvxCharEffectsPage *>(instance)->ShadowBtnClickHdl(data); } void SvxCharEffectsPage ::ShadowBtnClickHdl(weld::ToggleButton& rToggle) | |||
2054 | { | |||
2055 | m_aShadowState.ButtonToggled(rToggle); | |||
2056 | UpdatePreview_Impl(); | |||
2057 | } | |||
2058 | ||||
2059 | void SvxCharEffectsPage::ChangesApplied() | |||
2060 | { | |||
2061 | m_xUnderlineLB->save_value(); | |||
2062 | m_xOverlineLB->save_value(); | |||
2063 | m_xStrikeoutLB->save_value(); | |||
2064 | m_xIndividualWordsBtn->save_state(); | |||
2065 | m_xEmphasisLB->save_value(); | |||
2066 | m_xPositionLB->save_value(); | |||
2067 | m_xEffectsLB->save_value(); | |||
2068 | m_xReliefLB->save_value(); | |||
2069 | m_xOutlineBtn->save_state(); | |||
2070 | m_xShadowBtn->save_state(); | |||
2071 | m_xHiddenBtn->save_state(); | |||
2072 | m_xFontTransparencyMtr->save_value(); | |||
2073 | } | |||
2074 | ||||
2075 | bool SvxCharEffectsPage::FillItemSet( SfxItemSet* rSet ) | |||
2076 | { | |||
2077 | const SfxPoolItem* pOld = nullptr; | |||
2078 | const SfxItemSet& rOldSet = GetItemSet(); | |||
2079 | bool bModified = false; | |||
2080 | bool bChanged = true; | |||
2081 | ||||
2082 | // Underline | |||
2083 | sal_uInt16 nWhich = GetWhich( SID_ATTR_CHAR_UNDERLINE( 10000 + 14 ) ); | |||
2084 | pOld = GetOldItem( *rSet, SID_ATTR_CHAR_UNDERLINE( 10000 + 14 ) ); | |||
2085 | auto nPos = m_xUnderlineLB->get_active(); | |||
2086 | FontLineStyle eUnder = static_cast<FontLineStyle>(m_xUnderlineLB->get_active_id().toInt32()); | |||
2087 | ||||
2088 | if ( pOld ) | |||
2089 | { | |||
2090 | //! if there are different underline styles in the selection the | |||
2091 | //! item-state in the 'rOldSet' will be invalid. In this case | |||
2092 | //! changing the underline style will be allowed if a style is | |||
2093 | //! selected in the listbox. | |||
2094 | bool bAllowChg = nPos != -1 && | |||
2095 | SfxItemState::DEFAULT > rOldSet.GetItemState( nWhich ); | |||
2096 | ||||
2097 | const SvxUnderlineItem& rItem = *static_cast<const SvxUnderlineItem*>(pOld); | |||
2098 | if ( rItem.GetValue() == eUnder && | |||
2099 | ( LINESTYLE_NONE == eUnder || rItem.GetColor() == m_xUnderlineColorLB->GetSelectEntryColor() ) && | |||
2100 | ! bAllowChg ) | |||
2101 | bChanged = false; | |||
2102 | } | |||
2103 | ||||
2104 | if ( bChanged ) | |||
2105 | { | |||
2106 | SvxUnderlineItem aNewItem( eUnder, nWhich ); | |||
2107 | aNewItem.SetColor( m_xUnderlineColorLB->GetSelectEntryColor() ); | |||
2108 | rSet->Put( aNewItem ); | |||
2109 | bModified = true; | |||
2110 | } | |||
2111 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2112 | rSet->InvalidateItem(nWhich); | |||
2113 | ||||
2114 | bChanged = true; | |||
2115 | ||||
2116 | // Overline | |||
2117 | nWhich = GetWhich( SID_ATTR_CHAR_OVERLINE( ((10000 + 1499) + 1) + 68 ) ); | |||
2118 | pOld = GetOldItem( *rSet, SID_ATTR_CHAR_OVERLINE( ((10000 + 1499) + 1) + 68 ) ); | |||
2119 | nPos = m_xOverlineLB->get_active(); | |||
2120 | FontLineStyle eOver = static_cast<FontLineStyle>(m_xOverlineLB->get_active_id().toInt32()); | |||
2121 | ||||
2122 | if ( pOld ) | |||
2123 | { | |||
2124 | //! if there are different underline styles in the selection the | |||
2125 | //! item-state in the 'rOldSet' will be invalid. In this case | |||
2126 | //! changing the underline style will be allowed if a style is | |||
2127 | //! selected in the listbox. | |||
2128 | bool bAllowChg = nPos != -1 && | |||
2129 | SfxItemState::DEFAULT > rOldSet.GetItemState( nWhich ); | |||
2130 | ||||
2131 | const SvxOverlineItem& rItem = *static_cast<const SvxOverlineItem*>(pOld); | |||
2132 | if ( rItem.GetValue() == eOver && | |||
2133 | ( LINESTYLE_NONE == eOver || rItem.GetColor() == m_xOverlineColorLB->GetSelectEntryColor() ) && | |||
2134 | ! bAllowChg ) | |||
2135 | bChanged = false; | |||
2136 | } | |||
2137 | ||||
2138 | if ( bChanged ) | |||
2139 | { | |||
2140 | SvxOverlineItem aNewItem( eOver, nWhich ); | |||
2141 | aNewItem.SetColor( m_xOverlineColorLB->GetSelectEntryColor() ); | |||
2142 | rSet->Put( aNewItem ); | |||
2143 | bModified = true; | |||
2144 | } | |||
2145 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2146 | rSet->InvalidateItem(nWhich); | |||
2147 | ||||
2148 | bChanged = true; | |||
2149 | ||||
2150 | // Strikeout | |||
2151 | nWhich = GetWhich( SID_ATTR_CHAR_STRIKEOUT( 10000 + 13 ) ); | |||
2152 | pOld = GetOldItem( *rSet, SID_ATTR_CHAR_STRIKEOUT( 10000 + 13 ) ); | |||
2153 | nPos = m_xStrikeoutLB->get_active(); | |||
2154 | FontStrikeout eStrike = static_cast<FontStrikeout>(m_xStrikeoutLB->get_active_id().toInt32()); | |||
2155 | ||||
2156 | if ( pOld ) | |||
2157 | { | |||
2158 | //! if there are different strikeout styles in the selection the | |||
2159 | //! item-state in the 'rOldSet' will be invalid. In this case | |||
2160 | //! changing the strikeout style will be allowed if a style is | |||
2161 | //! selected in the listbox. | |||
2162 | bool bAllowChg = nPos != -1 && | |||
2163 | SfxItemState::DEFAULT > rOldSet.GetItemState( nWhich ); | |||
2164 | ||||
2165 | const SvxCrossedOutItem& rItem = *static_cast<const SvxCrossedOutItem*>(pOld); | |||
2166 | if ( !m_xStrikeoutLB->get_sensitive() | |||
2167 | || (rItem.GetValue() == eStrike && !bAllowChg) ) | |||
2168 | bChanged = false; | |||
2169 | } | |||
2170 | ||||
2171 | if ( bChanged ) | |||
2172 | { | |||
2173 | rSet->Put( SvxCrossedOutItem( eStrike, nWhich ) ); | |||
2174 | bModified = true; | |||
2175 | } | |||
2176 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2177 | rSet->InvalidateItem(nWhich); | |||
2178 | ||||
2179 | bChanged = true; | |||
2180 | ||||
2181 | // Individual words | |||
2182 | const SfxItemSet* pExampleSet = GetDialogExampleSet(); | |||
2183 | nWhich = GetWhich( SID_ATTR_CHAR_WORDLINEMODE( 10000 + 11 ) ); | |||
2184 | pOld = GetOldItem( *rSet, SID_ATTR_CHAR_WORDLINEMODE( 10000 + 11 ) ); | |||
2185 | TriState eState = m_xIndividualWordsBtn->get_state(); | |||
2186 | const SfxPoolItem* pItem; | |||
2187 | ||||
2188 | if ( pOld ) | |||
2189 | { | |||
2190 | const SvxWordLineModeItem& rItem = *static_cast<const SvxWordLineModeItem*>(pOld); | |||
2191 | if ( rItem.GetValue() == StateToAttr( eState ) && m_xIndividualWordsBtn->get_saved_state() == eState ) | |||
2192 | bChanged = false; | |||
2193 | } | |||
2194 | ||||
2195 | if ( !bChanged && pExampleSet && pExampleSet->GetItemState( nWhich, false, &pItem ) == SfxItemState::SET && | |||
2196 | !StateToAttr( eState ) && static_cast<const SvxWordLineModeItem*>(pItem)->GetValue() ) | |||
2197 | bChanged = true; | |||
2198 | ||||
2199 | if ( bChanged && eState != TRISTATE_INDET ) | |||
2200 | { | |||
2201 | rSet->Put( SvxWordLineModeItem( StateToAttr( eState ), nWhich ) ); | |||
2202 | bModified = true; | |||
2203 | } | |||
2204 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2205 | rSet->InvalidateItem(nWhich); | |||
2206 | ||||
2207 | bChanged = true; | |||
2208 | ||||
2209 | // Emphasis | |||
2210 | nWhich = GetWhich( SID_ATTR_CHAR_EMPHASISMARK( 10000 + 899 ) ); | |||
2211 | pOld = GetOldItem( *rSet, SID_ATTR_CHAR_EMPHASISMARK( 10000 + 899 ) ); | |||
2212 | int nMarkPos = m_xEmphasisLB->get_active(); | |||
2213 | OUString sMarkPos = m_xEmphasisLB->get_active_text(); | |||
2214 | OUString sPosPos = m_xPositionLB->get_active_text(); | |||
2215 | FontEmphasisMark eMark = static_cast<FontEmphasisMark>(nMarkPos); | |||
2216 | if (m_xPositionLB->get_sensitive()) | |||
2217 | { | |||
2218 | eMark |= (CHRDLG_POSITION_UNDER1 == m_xPositionLB->get_active_id().toInt32()) | |||
2219 | ? FontEmphasisMark::PosBelow : FontEmphasisMark::PosAbove; | |||
2220 | } | |||
2221 | ||||
2222 | if ( pOld ) | |||
2223 | { | |||
2224 | if( rOldSet.GetItemState( nWhich ) != SfxItemState::DONTCARE ) | |||
2225 | { | |||
2226 | const SvxEmphasisMarkItem& rItem = *static_cast<const SvxEmphasisMarkItem*>(pOld); | |||
2227 | if ( rItem.GetEmphasisMark() == eMark ) | |||
2228 | bChanged = false; | |||
2229 | } | |||
2230 | } | |||
2231 | ||||
2232 | if (rOldSet.GetItemState( nWhich ) == SfxItemState::DONTCARE && | |||
2233 | m_xEmphasisLB->get_saved_value() == sMarkPos && m_xPositionLB->get_saved_value() == sPosPos) | |||
2234 | { | |||
2235 | bChanged = false; | |||
2236 | } | |||
2237 | ||||
2238 | if (bChanged) | |||
2239 | { | |||
2240 | rSet->Put( SvxEmphasisMarkItem( eMark, nWhich ) ); | |||
2241 | bModified = true; | |||
2242 | } | |||
2243 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2244 | rSet->InvalidateItem(nWhich); | |||
2245 | ||||
2246 | bChanged = true; | |||
2247 | ||||
2248 | // Effects | |||
2249 | nWhich = GetWhich( SID_ATTR_CHAR_CASEMAP( 10000 + 19 ) ); | |||
2250 | pOld = GetOldItem( *rSet, SID_ATTR_CHAR_CASEMAP( 10000 + 19 ) ); | |||
2251 | SvxCaseMap eCaseMap = SvxCaseMap::NotMapped; | |||
2252 | bool bChecked = false; | |||
2253 | auto nCapsPos = m_xEffectsLB->get_active(); | |||
2254 | if (nCapsPos != -1) | |||
2255 | { | |||
2256 | eCaseMap = static_cast<SvxCaseMap>(nCapsPos); | |||
2257 | bChecked = true; | |||
2258 | } | |||
2259 | ||||
2260 | if ( pOld ) | |||
2261 | { | |||
2262 | //! if there are different effect styles in the selection the | |||
2263 | //! item-state in the 'rOldSet' will be invalid. In this case | |||
2264 | //! changing the effect style will be allowed if a style is | |||
2265 | //! selected in the listbox. | |||
2266 | bool bAllowChg = nPos != -1 && | |||
2267 | SfxItemState::DEFAULT > rOldSet.GetItemState( nWhich ); | |||
2268 | ||||
2269 | const SvxCaseMapItem& rItem = *static_cast<const SvxCaseMapItem*>(pOld); | |||
2270 | if ( rItem.GetValue() == eCaseMap && !bAllowChg ) | |||
2271 | bChanged = false; | |||
2272 | } | |||
2273 | ||||
2274 | if ( bChanged && bChecked ) | |||
2275 | { | |||
2276 | rSet->Put( SvxCaseMapItem( eCaseMap, nWhich ) ); | |||
2277 | bModified = true; | |||
2278 | } | |||
2279 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2280 | rSet->InvalidateItem(nWhich); | |||
2281 | ||||
2282 | bChanged = true; | |||
2283 | ||||
2284 | //Relief | |||
2285 | nWhich = GetWhich(SID_ATTR_CHAR_RELIEF( 10000 + 920 )); | |||
2286 | if (m_xReliefLB->get_value_changed_from_saved()) | |||
2287 | { | |||
2288 | m_xReliefLB->save_value(); | |||
2289 | SvxCharReliefItem aRelief(static_cast<FontRelief>(m_xReliefLB->get_active()), nWhich); | |||
2290 | rSet->Put(aRelief); | |||
2291 | } | |||
2292 | ||||
2293 | // Outline | |||
2294 | nWhich = GetWhich( SID_ATTR_CHAR_CONTOUR( 10000 + 12 ) ); | |||
2295 | pOld = GetOldItem( *rSet, SID_ATTR_CHAR_CONTOUR( 10000 + 12 ) ); | |||
2296 | eState = m_xOutlineBtn->get_state(); | |||
2297 | ||||
2298 | if ( pOld ) | |||
2299 | { | |||
2300 | const SvxContourItem& rItem = *static_cast<const SvxContourItem*>(pOld); | |||
2301 | if ( rItem.GetValue() == StateToAttr( eState ) && m_xOutlineBtn->get_saved_state() == eState ) | |||
2302 | bChanged = false; | |||
2303 | } | |||
2304 | ||||
2305 | if ( !bChanged && pExampleSet && pExampleSet->GetItemState( nWhich, false, &pItem ) == SfxItemState::SET && | |||
2306 | !StateToAttr( eState ) && static_cast<const SvxContourItem*>(pItem)->GetValue() ) | |||
2307 | bChanged = true; | |||
2308 | ||||
2309 | if ( bChanged && eState != TRISTATE_INDET ) | |||
2310 | { | |||
2311 | rSet->Put( SvxContourItem( StateToAttr( eState ), nWhich ) ); | |||
2312 | bModified = true; | |||
2313 | } | |||
2314 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2315 | rSet->InvalidateItem(nWhich); | |||
2316 | ||||
2317 | bChanged = true; | |||
2318 | ||||
2319 | // Shadow | |||
2320 | nWhich = GetWhich( SID_ATTR_CHAR_SHADOWED( 10000 + 10 ) ); | |||
2321 | pOld = GetOldItem( *rSet, SID_ATTR_CHAR_SHADOWED( 10000 + 10 ) ); | |||
2322 | eState = m_xShadowBtn->get_state(); | |||
2323 | ||||
2324 | if ( pOld ) | |||
2325 | { | |||
2326 | const SvxShadowedItem& rItem = *static_cast<const SvxShadowedItem*>(pOld); | |||
2327 | if ( rItem.GetValue() == StateToAttr( eState ) && m_xShadowBtn->get_saved_state() == eState ) | |||
2328 | bChanged = false; | |||
2329 | } | |||
2330 | ||||
2331 | if ( !bChanged && pExampleSet && pExampleSet->GetItemState( nWhich, false, &pItem ) == SfxItemState::SET && | |||
2332 | !StateToAttr( eState ) && static_cast<const SvxShadowedItem*>(pItem)->GetValue() ) | |||
2333 | bChanged = true; | |||
2334 | ||||
2335 | if ( bChanged && eState != TRISTATE_INDET ) | |||
2336 | { | |||
2337 | rSet->Put( SvxShadowedItem( StateToAttr( eState ), nWhich ) ); | |||
2338 | bModified = true; | |||
2339 | } | |||
2340 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2341 | rSet->InvalidateItem(nWhich); | |||
2342 | ||||
2343 | bChanged = true; | |||
2344 | ||||
2345 | // Hidden | |||
2346 | nWhich = GetWhich( SID_ATTR_CHAR_HIDDEN( 10000 + 989 ) ); | |||
2347 | pOld = GetOldItem( *rSet, SID_ATTR_CHAR_HIDDEN( 10000 + 989 ) ); | |||
2348 | eState = m_xHiddenBtn->get_state(); | |||
2349 | bChanged = true; | |||
2350 | ||||
2351 | if ( pOld ) | |||
2352 | { | |||
2353 | const SvxCharHiddenItem& rItem = *static_cast<const SvxCharHiddenItem*>(pOld); | |||
2354 | if ( rItem.GetValue() == StateToAttr( eState ) && m_xHiddenBtn->get_saved_state() == eState ) | |||
2355 | bChanged = false; | |||
2356 | } | |||
2357 | ||||
2358 | if ( !bChanged && pExampleSet && pExampleSet->GetItemState( nWhich, false, &pItem ) == SfxItemState::SET && | |||
2359 | !StateToAttr( eState ) && static_cast<const SvxCharHiddenItem*>(pItem)->GetValue() ) | |||
2360 | bChanged = true; | |||
2361 | ||||
2362 | if ( bChanged && eState != TRISTATE_INDET ) | |||
2363 | { | |||
2364 | rSet->Put( SvxCharHiddenItem( StateToAttr( eState ), nWhich ) ); | |||
2365 | bModified = true; | |||
2366 | } | |||
2367 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2368 | rSet->InvalidateItem(nWhich); | |||
2369 | ||||
2370 | bModified |= FillItemSetColor_Impl( *rSet ); | |||
2371 | ||||
2372 | return bModified; | |||
2373 | } | |||
2374 | ||||
2375 | void SvxCharEffectsPage::DisableControls( sal_uInt16 nDisable ) | |||
2376 | { | |||
2377 | if ( ( DISABLE_CASEMAP(sal_uInt16(0x0001)) & nDisable ) == DISABLE_CASEMAP(sal_uInt16(0x0001)) ) | |||
2378 | { | |||
2379 | m_xEffectsFT->set_sensitive(false); | |||
2380 | m_xEffectsLB->set_sensitive(false); | |||
2381 | } | |||
2382 | } | |||
2383 | ||||
2384 | void SvxCharEffectsPage::PageCreated(const SfxAllItemSet& aSet) | |||
2385 | { | |||
2386 | const SfxUInt16Item* pDisableCtlItem = aSet.GetItem<SfxUInt16Item>(SID_DISABLE_CTL( 10000 + 1036 ), false); | |||
2387 | const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_FLAG_TYPE( 10000 + 1034 ), false); | |||
2388 | if (pDisableCtlItem) | |||
2389 | DisableControls(pDisableCtlItem->GetValue()); | |||
2390 | ||||
2391 | if (!pFlagItem) | |||
2392 | return; | |||
2393 | ||||
2394 | sal_uInt32 nFlags=pFlagItem->GetValue(); | |||
2395 | if ( ( nFlags & SVX_PREVIEW_CHARACTER0x01 ) == SVX_PREVIEW_CHARACTER0x01 ) | |||
2396 | // the writer uses SID_ATTR_BRUSH as font background | |||
2397 | m_bPreviewBackgroundToCharacter = true; | |||
2398 | if ((nFlags & SVX_ENABLE_CHAR_TRANSPARENCY0x08) != SVX_ENABLE_CHAR_TRANSPARENCY0x08) | |||
2399 | { | |||
2400 | // Only show these in case client code explicitly wants this. | |||
2401 | m_xFontTransparencyFT->hide(); | |||
2402 | m_xFontTransparencyMtr->hide(); | |||
2403 | } | |||
2404 | } | |||
2405 | ||||
2406 | // class SvxCharPositionPage --------------------------------------------- | |||
2407 | ||||
2408 | SvxCharPositionPage::SvxCharPositionPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInSet) | |||
2409 | : SvxCharBasePage(pPage, pController, "cui/ui/positionpage.ui", "PositionPage", rInSet) | |||
2410 | , m_nSuperEsc(short(DFLT_ESC_SUPER33)) | |||
2411 | , m_nSubEsc(short(DFLT_ESC_SUB-8)) | |||
2412 | , m_nScaleWidthItemSetVal(100) | |||
2413 | , m_nScaleWidthInitialVal(100) | |||
2414 | , m_nSuperProp(sal_uInt8(DFLT_ESC_PROP58)) | |||
2415 | , m_nSubProp(sal_uInt8(DFLT_ESC_PROP58)) | |||
2416 | , m_xHighPosBtn(m_xBuilder->weld_radio_button("superscript")) | |||
2417 | , m_xNormalPosBtn(m_xBuilder->weld_radio_button("normal")) | |||
2418 | , m_xLowPosBtn(m_xBuilder->weld_radio_button("subscript")) | |||
2419 | , m_xHighLowFT(m_xBuilder->weld_label("raiselower")) | |||
2420 | , m_xHighLowMF(m_xBuilder->weld_metric_spin_button("raiselowersb", FieldUnit::PERCENT)) | |||
2421 | , m_xHighLowRB(m_xBuilder->weld_check_button("automatic")) | |||
2422 | , m_xFontSizeFT(m_xBuilder->weld_label("relativefontsize")) | |||
2423 | , m_xFontSizeMF(m_xBuilder->weld_metric_spin_button("fontsizesb", FieldUnit::PERCENT)) | |||
2424 | , m_xRotationContainer(m_xBuilder->weld_widget("rotationcontainer")) | |||
2425 | , m_xScalingFT(m_xBuilder->weld_label("scale")) | |||
2426 | , m_xScalingAndRotationFT(m_xBuilder->weld_label("rotateandscale")) | |||
2427 | , m_x0degRB(m_xBuilder->weld_radio_button("0deg")) | |||
2428 | , m_x90degRB(m_xBuilder->weld_radio_button("90deg")) | |||
2429 | , m_x270degRB(m_xBuilder->weld_radio_button("270deg")) | |||
2430 | , m_xFitToLineCB(m_xBuilder->weld_check_button("fittoline")) | |||
2431 | , m_xScaleWidthMF(m_xBuilder->weld_metric_spin_button("scalewidthsb", FieldUnit::PERCENT)) | |||
2432 | , m_xKerningMF(m_xBuilder->weld_metric_spin_button("kerningsb", FieldUnit::POINT)) | |||
2433 | , m_xPairKerningBtn(m_xBuilder->weld_check_button("pairkerning")) | |||
2434 | { | |||
2435 | m_xPreviewWin.reset(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWin)); | |||
2436 | #ifdef IOS | |||
2437 | m_xPreviewWin->hide(); | |||
2438 | #endif | |||
2439 | Initialize(); | |||
2440 | } | |||
2441 | ||||
2442 | SvxCharPositionPage::~SvxCharPositionPage() | |||
2443 | { | |||
2444 | } | |||
2445 | ||||
2446 | ||||
2447 | void SvxCharPositionPage::Initialize() | |||
2448 | { | |||
2449 | // to handle the changes of the other pages | |||
2450 | SetExchangeSupport(); | |||
2451 | ||||
2452 | GetPreviewFont().SetFontSize( Size( 0, 240 ) ); | |||
2453 | GetPreviewCJKFont().SetFontSize( Size( 0, 240 ) ); | |||
2454 | GetPreviewCTLFont().SetFontSize( Size( 0, 240 ) ); | |||
2455 | ||||
2456 | m_xNormalPosBtn->set_active(true); | |||
2457 | PositionHdl_Impl(*m_xNormalPosBtn); | |||
2458 | ||||
2459 | Link<weld::ToggleButton&,void> aLink2 = LINK(this, SvxCharPositionPage, PositionHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharPositionPage *>(this), &SvxCharPositionPage::LinkStubPositionHdl_Impl ); | |||
2460 | m_xHighPosBtn->connect_toggled(aLink2); | |||
2461 | m_xNormalPosBtn->connect_toggled(aLink2); | |||
2462 | m_xLowPosBtn->connect_toggled(aLink2); | |||
2463 | ||||
2464 | aLink2 = LINK( this, SvxCharPositionPage, RotationHdl_Impl )::tools::detail::makeLink( ::tools::detail::castTo<SvxCharPositionPage *>(this), &SvxCharPositionPage::LinkStubRotationHdl_Impl ); | |||
2465 | m_x0degRB->connect_toggled(aLink2); | |||
2466 | m_x90degRB->connect_toggled(aLink2); | |||
2467 | m_x270degRB->connect_toggled(aLink2); | |||
2468 | ||||
2469 | Link<weld::MetricSpinButton&,void> aLink3 = LINK(this, SvxCharPositionPage, ValueChangedHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharPositionPage *>(this), &SvxCharPositionPage::LinkStubValueChangedHdl_Impl ); | |||
2470 | m_xHighLowMF->connect_value_changed(aLink3); | |||
2471 | m_xFontSizeMF->connect_value_changed(aLink3); | |||
2472 | ||||
2473 | m_xHighLowRB->connect_toggled(LINK(this, SvxCharPositionPage, AutoPositionHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharPositionPage *>(this), &SvxCharPositionPage::LinkStubAutoPositionHdl_Impl )); | |||
2474 | m_xFitToLineCB->connect_toggled(LINK(this, SvxCharPositionPage, FitToLineHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharPositionPage *>(this), &SvxCharPositionPage::LinkStubFitToLineHdl_Impl )); | |||
2475 | m_xKerningMF->connect_value_changed(LINK(this, SvxCharPositionPage, KerningModifyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharPositionPage *>(this), &SvxCharPositionPage::LinkStubKerningModifyHdl_Impl )); | |||
2476 | m_xScaleWidthMF->connect_value_changed(LINK(this, SvxCharPositionPage, ScaleWidthModifyHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharPositionPage *>(this), &SvxCharPositionPage::LinkStubScaleWidthModifyHdl_Impl )); | |||
2477 | } | |||
2478 | ||||
2479 | void SvxCharPositionPage::UpdatePreview_Impl( sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc ) | |||
2480 | { | |||
2481 | SetPrevFontEscapement( nProp, nEscProp, nEsc ); | |||
2482 | } | |||
2483 | ||||
2484 | ||||
2485 | void SvxCharPositionPage::SetEscapement_Impl( SvxEscapement nEsc ) | |||
2486 | { | |||
2487 | SvxEscapementItem aEscItm( nEsc, SID_ATTR_CHAR_ESCAPEMENT( 10000 + 21 ) ); | |||
2488 | ||||
2489 | if ( SvxEscapement::Superscript == nEsc ) | |||
2490 | { | |||
2491 | aEscItm.GetEsc() = m_nSuperEsc; | |||
2492 | aEscItm.GetProportionalHeight() = m_nSuperProp; | |||
2493 | } | |||
2494 | else if ( SvxEscapement::Subscript == nEsc ) | |||
2495 | { | |||
2496 | aEscItm.GetEsc() = m_nSubEsc; | |||
2497 | aEscItm.GetProportionalHeight() = m_nSubProp; | |||
2498 | } | |||
2499 | ||||
2500 | short nFac = aEscItm.GetEsc() < 0 ? -1 : 1; | |||
2501 | ||||
2502 | m_xHighLowMF->set_value(aEscItm.GetEsc() * nFac, FieldUnit::PERCENT); | |||
2503 | m_xFontSizeMF->set_value(aEscItm.GetProportionalHeight(), FieldUnit::PERCENT); | |||
2504 | ||||
2505 | if ( SvxEscapement::Off == nEsc ) | |||
2506 | { | |||
2507 | m_xHighLowFT->set_sensitive(false); | |||
2508 | m_xHighLowMF->set_sensitive(false); | |||
2509 | m_xFontSizeFT->set_sensitive(false); | |||
2510 | m_xFontSizeMF->set_sensitive(false); | |||
2511 | m_xHighLowRB->set_sensitive(false); | |||
2512 | } | |||
2513 | else | |||
2514 | { | |||
2515 | m_xFontSizeFT->set_sensitive(true); | |||
2516 | m_xFontSizeMF->set_sensitive(true); | |||
2517 | m_xHighLowRB->set_sensitive(true); | |||
2518 | ||||
2519 | if (!m_xHighLowRB->get_active()) | |||
2520 | { | |||
2521 | m_xHighLowFT->set_sensitive(true); | |||
2522 | m_xHighLowMF->set_sensitive(true); | |||
2523 | } | |||
2524 | else | |||
2525 | AutoPositionHdl_Impl(*m_xHighLowRB); | |||
2526 | } | |||
2527 | ||||
2528 | UpdatePreview_Impl( 100, aEscItm.GetProportionalHeight(), aEscItm.GetEsc() ); | |||
2529 | } | |||
2530 | ||||
2531 | ||||
2532 | IMPL_LINK_NOARG(SvxCharPositionPage, PositionHdl_Impl, weld::ToggleButton&, void)void SvxCharPositionPage::LinkStubPositionHdl_Impl(void * instance , weld::ToggleButton& data) { return static_cast<SvxCharPositionPage *>(instance)->PositionHdl_Impl(data); } void SvxCharPositionPage ::PositionHdl_Impl(__attribute__ ((unused)) weld::ToggleButton &) | |||
2533 | { | |||
2534 | SvxEscapement nEsc = SvxEscapement::Off; // also when pBtn == NULL | |||
2535 | ||||
2536 | if (m_xHighPosBtn->get_active()) | |||
2537 | nEsc = SvxEscapement::Superscript; | |||
2538 | else if (m_xLowPosBtn->get_active()) | |||
2539 | nEsc = SvxEscapement::Subscript; | |||
2540 | ||||
2541 | SetEscapement_Impl( nEsc ); | |||
2542 | } | |||
2543 | ||||
2544 | IMPL_LINK_NOARG(SvxCharPositionPage, RotationHdl_Impl, weld::ToggleButton&, void)void SvxCharPositionPage::LinkStubRotationHdl_Impl(void * instance , weld::ToggleButton& data) { return static_cast<SvxCharPositionPage *>(instance)->RotationHdl_Impl(data); } void SvxCharPositionPage ::RotationHdl_Impl(__attribute__ ((unused)) weld::ToggleButton &) | |||
2545 | { | |||
2546 | bool bEnable = false; | |||
2547 | if (m_x90degRB->get_active() || m_x270degRB->get_active()) | |||
2548 | bEnable = true; | |||
2549 | else | |||
2550 | OSL_ENSURE(m_x0degRB->get_active(), "unexpected button")do { if (true && (!(m_x0degRB->get_active()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "2550" ": "), "%s", "unexpected button"); } } while (false ); | |||
2551 | m_xFitToLineCB->set_sensitive(bEnable); | |||
2552 | } | |||
2553 | ||||
2554 | void SvxCharPositionPage::FontModifyHdl_Impl() | |||
2555 | { | |||
2556 | sal_uInt8 nEscProp = static_cast<sal_uInt8>(m_xFontSizeMF->get_value(FieldUnit::PERCENT)); | |||
2557 | short nEsc = static_cast<short>(m_xHighLowMF->get_value(FieldUnit::PERCENT)); | |||
2558 | nEsc *= m_xLowPosBtn->get_active() ? -1 : 1; | |||
2559 | UpdatePreview_Impl( 100, nEscProp, nEsc ); | |||
2560 | } | |||
2561 | ||||
2562 | IMPL_LINK(SvxCharPositionPage, AutoPositionHdl_Impl, weld::ToggleButton&, rBox, void)void SvxCharPositionPage::LinkStubAutoPositionHdl_Impl(void * instance, weld::ToggleButton& data) { return static_cast <SvxCharPositionPage *>(instance)->AutoPositionHdl_Impl (data); } void SvxCharPositionPage::AutoPositionHdl_Impl(weld ::ToggleButton& rBox) | |||
2563 | { | |||
2564 | if (rBox.get_active()) | |||
2565 | { | |||
2566 | m_xHighLowFT->set_sensitive(false); | |||
2567 | m_xHighLowMF->set_sensitive(false); | |||
2568 | } | |||
2569 | else | |||
2570 | PositionHdl_Impl(m_xHighPosBtn->get_active() ? *m_xHighPosBtn | |||
2571 | : m_xLowPosBtn->get_active() ? *m_xLowPosBtn | |||
2572 | : *m_xNormalPosBtn); | |||
2573 | } | |||
2574 | ||||
2575 | IMPL_LINK_NOARG(SvxCharPositionPage, FitToLineHdl_Impl, weld::ToggleButton&, void)void SvxCharPositionPage::LinkStubFitToLineHdl_Impl(void * instance , weld::ToggleButton& data) { return static_cast<SvxCharPositionPage *>(instance)->FitToLineHdl_Impl(data); } void SvxCharPositionPage ::FitToLineHdl_Impl(__attribute__ ((unused)) weld::ToggleButton &) | |||
2576 | { | |||
2577 | sal_uInt16 nVal = m_nScaleWidthInitialVal; | |||
2578 | if (m_xFitToLineCB->get_active()) | |||
2579 | nVal = m_nScaleWidthItemSetVal; | |||
2580 | m_xScaleWidthMF->set_value(nVal, FieldUnit::PERCENT); | |||
2581 | m_aPreviewWin.SetFontWidthScale( nVal ); | |||
2582 | } | |||
2583 | ||||
2584 | IMPL_LINK_NOARG(SvxCharPositionPage, KerningModifyHdl_Impl, weld::MetricSpinButton&, void)void SvxCharPositionPage::LinkStubKerningModifyHdl_Impl(void * instance, weld::MetricSpinButton& data) { return static_cast <SvxCharPositionPage *>(instance)->KerningModifyHdl_Impl (data); } void SvxCharPositionPage::KerningModifyHdl_Impl(__attribute__ ((unused)) weld::MetricSpinButton&) | |||
2585 | { | |||
2586 | long nVal = static_cast<long>(m_xKerningMF->get_value(FieldUnit::POINT)); | |||
2587 | nVal = OutputDevice::LogicToLogic( nVal, MapUnit::MapPoint, MapUnit::MapTwip ); | |||
2588 | long nKern = static_cast<short>(m_xKerningMF->denormalize(nVal)); | |||
2589 | ||||
2590 | SvxFont& rFont = GetPreviewFont(); | |||
2591 | SvxFont& rCJKFont = GetPreviewCJKFont(); | |||
2592 | SvxFont& rCTLFont = GetPreviewCTLFont(); | |||
2593 | ||||
2594 | rFont.SetFixKerning( static_cast<short>(nKern) ); | |||
2595 | rCJKFont.SetFixKerning( static_cast<short>(nKern) ); | |||
2596 | rCTLFont.SetFixKerning( static_cast<short>(nKern) ); | |||
2597 | m_aPreviewWin.Invalidate(); | |||
2598 | } | |||
2599 | ||||
2600 | IMPL_LINK(SvxCharPositionPage, ValueChangedHdl_Impl, weld::MetricSpinButton&, rField, void)void SvxCharPositionPage::LinkStubValueChangedHdl_Impl(void * instance, weld::MetricSpinButton& data) { return static_cast <SvxCharPositionPage *>(instance)->ValueChangedHdl_Impl (data); } void SvxCharPositionPage::ValueChangedHdl_Impl(weld ::MetricSpinButton& rField) | |||
2601 | { | |||
2602 | bool bHigh = m_xHighPosBtn->get_active(); | |||
2603 | bool bLow = m_xLowPosBtn->get_active(); | |||
2604 | DBG_ASSERT( bHigh || bLow, "normal position is not valid" )do { if (true && (!(bHigh || bLow))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "2604" ": "), "%s", "normal position is not valid"); } } while (false); | |||
2605 | ||||
2606 | if (m_xHighLowMF.get() == &rField) | |||
2607 | { | |||
2608 | if ( bLow ) | |||
2609 | m_nSubEsc = static_cast<short>(m_xHighLowMF->get_value(FieldUnit::PERCENT)) * -1; | |||
2610 | else | |||
2611 | m_nSuperEsc = static_cast<short>(m_xHighLowMF->get_value(FieldUnit::PERCENT)); | |||
2612 | } | |||
2613 | else if (m_xFontSizeMF.get() == &rField) | |||
2614 | { | |||
2615 | if ( bLow ) | |||
2616 | m_nSubProp = static_cast<sal_uInt8>(m_xFontSizeMF->get_value(FieldUnit::PERCENT)); | |||
2617 | else | |||
2618 | m_nSuperProp = static_cast<sal_uInt8>(m_xFontSizeMF->get_value(FieldUnit::PERCENT)); | |||
2619 | } | |||
2620 | ||||
2621 | FontModifyHdl_Impl(); | |||
2622 | } | |||
2623 | ||||
2624 | IMPL_LINK_NOARG(SvxCharPositionPage, ScaleWidthModifyHdl_Impl, weld::MetricSpinButton&, void)void SvxCharPositionPage::LinkStubScaleWidthModifyHdl_Impl(void * instance, weld::MetricSpinButton& data) { return static_cast <SvxCharPositionPage *>(instance)->ScaleWidthModifyHdl_Impl (data); } void SvxCharPositionPage::ScaleWidthModifyHdl_Impl( __attribute__ ((unused)) weld::MetricSpinButton&) | |||
2625 | { | |||
2626 | m_aPreviewWin.SetFontWidthScale(sal_uInt16(m_xScaleWidthMF->get_value(FieldUnit::PERCENT))); | |||
2627 | } | |||
2628 | ||||
2629 | DeactivateRC SvxCharPositionPage::DeactivatePage( SfxItemSet* _pSet ) | |||
2630 | { | |||
2631 | if ( _pSet ) | |||
2632 | FillItemSet( _pSet ); | |||
2633 | return DeactivateRC::LeavePage; | |||
2634 | } | |||
2635 | ||||
2636 | std::unique_ptr<SfxTabPage> SvxCharPositionPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet) | |||
2637 | { | |||
2638 | return std::make_unique<SvxCharPositionPage>(pPage, pController, *rSet); | |||
2639 | } | |||
2640 | ||||
2641 | void SvxCharPositionPage::Reset( const SfxItemSet* rSet ) | |||
2642 | { | |||
2643 | OUString sUser = GetUserData(); | |||
2644 | ||||
2645 | if ( !sUser.isEmpty() ) | |||
2646 | { | |||
2647 | sal_Int32 nIdx {0}; | |||
2648 | m_nSuperEsc = static_cast<short>(sUser.getToken( 0, ';', nIdx ).toInt32()); | |||
2649 | m_nSubEsc = static_cast<short>(sUser.getToken( 0, ';', nIdx ).toInt32()); | |||
2650 | m_nSuperProp = static_cast<sal_uInt8>(sUser.getToken( 0, ';', nIdx ).toInt32()); | |||
2651 | m_nSubProp = static_cast<sal_uInt8>(sUser.getToken( 0, ';', nIdx ).toInt32()); | |||
2652 | ||||
2653 | m_xHighLowMF->set_max(MAX_ESC_POS13999, FieldUnit::PERCENT); | |||
2654 | ||||
2655 | //fdo#75307 validate all the entries and discard all of them if any are | |||
2656 | //out of range | |||
2657 | bool bValid = true; | |||
2658 | if (m_nSuperEsc < m_xHighLowMF->get_min(FieldUnit::PERCENT) || m_nSuperEsc > m_xHighLowMF->get_max(FieldUnit::PERCENT)) | |||
2659 | bValid = false; | |||
2660 | if (m_nSubEsc*-1 < m_xHighLowMF->get_min(FieldUnit::PERCENT) || m_nSubEsc*-1 > m_xHighLowMF->get_max(FieldUnit::PERCENT)) | |||
2661 | bValid = false; | |||
2662 | if (m_nSuperProp < m_xFontSizeMF->get_min(FieldUnit::PERCENT) || m_nSuperProp > m_xFontSizeMF->get_max(FieldUnit::PERCENT)) | |||
2663 | bValid = false; | |||
2664 | if (m_nSubProp < m_xFontSizeMF->get_min(FieldUnit::PERCENT) || m_nSubProp > m_xFontSizeMF->get_max(FieldUnit::PERCENT)) | |||
2665 | bValid = false; | |||
2666 | ||||
2667 | if (!bValid) | |||
2668 | { | |||
2669 | m_nSuperEsc = DFLT_ESC_SUPER33; | |||
2670 | m_nSubEsc = DFLT_ESC_SUB-8; | |||
2671 | m_nSuperProp = DFLT_ESC_PROP58; | |||
2672 | m_nSubProp = DFLT_ESC_PROP58; | |||
2673 | } | |||
2674 | } | |||
2675 | ||||
2676 | short nEsc = 0; | |||
2677 | sal_uInt8 nEscProp = 100; | |||
2678 | ||||
2679 | m_xHighLowFT->set_sensitive(false); | |||
2680 | m_xHighLowMF->set_sensitive(false); | |||
2681 | m_xFontSizeFT->set_sensitive(false); | |||
2682 | m_xFontSizeMF->set_sensitive(false); | |||
2683 | ||||
2684 | SvxFont& rFont = GetPreviewFont(); | |||
2685 | SvxFont& rCJKFont = GetPreviewCJKFont(); | |||
2686 | SvxFont& rCTLFont = GetPreviewCTLFont(); | |||
2687 | sal_uInt16 nWhich = GetWhich( SID_ATTR_CHAR_ESCAPEMENT( 10000 + 21 ) ); | |||
2688 | ||||
2689 | if ( rSet->GetItemState( nWhich ) >= SfxItemState::DEFAULT ) | |||
2690 | { | |||
2691 | const SvxEscapementItem& rItem = static_cast<const SvxEscapementItem&>(rSet->Get( nWhich )); | |||
2692 | nEsc = rItem.GetEsc(); | |||
2693 | nEscProp = rItem.GetProportionalHeight(); | |||
2694 | ||||
2695 | if ( nEsc != 0 ) | |||
2696 | { | |||
2697 | m_xHighLowFT->set_sensitive(true); | |||
2698 | m_xHighLowMF->set_sensitive(true); | |||
2699 | m_xFontSizeFT->set_sensitive(true); | |||
2700 | m_xFontSizeMF->set_sensitive(true); | |||
2701 | ||||
2702 | short nFac; | |||
2703 | bool bAutomatic(false); | |||
2704 | ||||
2705 | if ( nEsc > 0 ) | |||
2706 | { | |||
2707 | nFac = 1; | |||
2708 | m_xHighPosBtn->set_active(true); | |||
2709 | if ( nEsc == DFLT_ESC_AUTO_SUPER(13999 +1) ) | |||
2710 | { | |||
2711 | nEsc = DFLT_ESC_SUPER33; | |||
2712 | bAutomatic = true; | |||
2713 | } | |||
2714 | } | |||
2715 | else | |||
2716 | { | |||
2717 | nFac = -1; | |||
2718 | m_xLowPosBtn->set_active(true); | |||
2719 | if ( nEsc == DFLT_ESC_AUTO_SUB-(13999 +1) ) | |||
2720 | { | |||
2721 | nEsc = DFLT_ESC_SUB-8; | |||
2722 | bAutomatic = true; | |||
2723 | } | |||
2724 | } | |||
2725 | if (!m_xHighLowRB->get_sensitive()) | |||
2726 | { | |||
2727 | m_xHighLowRB->set_sensitive(true); | |||
2728 | } | |||
2729 | m_xHighLowRB->set_active(bAutomatic); | |||
2730 | ||||
2731 | if (m_xHighLowRB->get_active()) | |||
2732 | { | |||
2733 | m_xHighLowFT->set_sensitive(false); | |||
2734 | m_xHighLowMF->set_sensitive(false); | |||
2735 | } | |||
2736 | m_xHighLowMF->set_value(m_xHighLowMF->normalize(nFac * nEsc), FieldUnit::PERCENT); | |||
2737 | } | |||
2738 | else | |||
2739 | { | |||
2740 | m_xNormalPosBtn->set_active(true); | |||
2741 | m_xHighLowRB->set_active(true); | |||
2742 | PositionHdl_Impl(*m_xNormalPosBtn); | |||
2743 | } | |||
2744 | //the height has to be set after the handler is called to keep the value also if the escapement is zero | |||
2745 | m_xFontSizeMF->set_value(m_xFontSizeMF->normalize(nEscProp), FieldUnit::PERCENT); | |||
2746 | } | |||
2747 | else | |||
2748 | { | |||
2749 | m_xHighPosBtn->set_active(false); | |||
2750 | m_xNormalPosBtn->set_active(false); | |||
2751 | m_xLowPosBtn->set_active(false); | |||
2752 | } | |||
2753 | ||||
2754 | // set BspFont | |||
2755 | SetPrevFontEscapement( 100, nEscProp, nEsc ); | |||
2756 | ||||
2757 | // Kerning | |||
2758 | nWhich = GetWhich( SID_ATTR_CHAR_KERNING( 10000 + 18 ) ); | |||
2759 | ||||
2760 | if ( rSet->GetItemState( nWhich ) >= SfxItemState::DEFAULT ) | |||
2761 | { | |||
2762 | const SvxKerningItem& rItem = static_cast<const SvxKerningItem&>(rSet->Get( nWhich )); | |||
2763 | MapUnit eUnit = rSet->GetPool()->GetMetric( nWhich ); | |||
2764 | long nBig = static_cast<long>(m_xKerningMF->normalize( static_cast<long>(rItem.GetValue()) )); | |||
2765 | long nKerning = OutputDevice::LogicToLogic(nBig, eUnit, MapUnit::MapPoint); | |||
2766 | ||||
2767 | // set Kerning at the Font, convert into Twips before | |||
2768 | long nKern = OutputDevice::LogicToLogic(rItem.GetValue(), eUnit, MapUnit::MapTwip); | |||
2769 | rFont.SetFixKerning( static_cast<short>(nKern) ); | |||
2770 | rCJKFont.SetFixKerning( static_cast<short>(nKern) ); | |||
2771 | rCTLFont.SetFixKerning( static_cast<short>(nKern) ); | |||
2772 | ||||
2773 | //the attribute value must be displayed also if it's above the maximum allowed value | |||
2774 | long nVal = static_cast<long>(m_xKerningMF->get_max(FieldUnit::POINT)); | |||
2775 | if(nVal < nKerning) | |||
2776 | m_xKerningMF->set_max(nKerning, FieldUnit::POINT); | |||
2777 | m_xKerningMF->set_value(nKerning, FieldUnit::POINT); | |||
2778 | } | |||
2779 | else | |||
2780 | m_xKerningMF->set_text(OUString()); | |||
2781 | ||||
2782 | // Pair kerning | |||
2783 | nWhich = GetWhich( SID_ATTR_CHAR_AUTOKERN( 10000 + 67 ) ); | |||
2784 | ||||
2785 | if ( rSet->GetItemState( nWhich ) >= SfxItemState::DEFAULT ) | |||
2786 | { | |||
2787 | const SvxAutoKernItem& rItem = static_cast<const SvxAutoKernItem&>(rSet->Get( nWhich )); | |||
2788 | m_xPairKerningBtn->set_active(rItem.GetValue()); | |||
2789 | } | |||
2790 | else | |||
2791 | m_xPairKerningBtn->set_active(false); | |||
2792 | ||||
2793 | // Scale Width | |||
2794 | nWhich = GetWhich( SID_ATTR_CHAR_SCALEWIDTH( 10000 + 911 ) ); | |||
2795 | if ( rSet->GetItemState( nWhich ) >= SfxItemState::DEFAULT ) | |||
2796 | { | |||
2797 | const SvxCharScaleWidthItem& rItem = static_cast<const SvxCharScaleWidthItem&>( rSet->Get( nWhich ) ); | |||
2798 | m_nScaleWidthInitialVal = rItem.GetValue(); | |||
2799 | m_xScaleWidthMF->set_value(m_nScaleWidthInitialVal, FieldUnit::PERCENT); | |||
2800 | } | |||
2801 | else | |||
2802 | m_xScaleWidthMF->set_value(100, FieldUnit::PERCENT); | |||
2803 | ||||
2804 | nWhich = GetWhich( SID_ATTR_CHAR_WIDTH_FIT_TO_LINE( 10000 + 919 ) ); | |||
2805 | if ( rSet->GetItemState( nWhich ) >= SfxItemState::DEFAULT ) | |||
2806 | m_nScaleWidthItemSetVal = static_cast<const SfxUInt16Item&>( rSet->Get( nWhich )).GetValue(); | |||
2807 | ||||
2808 | // Rotation | |||
2809 | nWhich = GetWhich( SID_ATTR_CHAR_ROTATED( 10000 + 910 ) ); | |||
2810 | SfxItemState eState = rSet->GetItemState( nWhich ); | |||
2811 | if( SfxItemState::UNKNOWN == eState ) | |||
2812 | { | |||
2813 | m_xRotationContainer->hide(); | |||
2814 | m_xScalingAndRotationFT->hide(); | |||
2815 | m_xScalingFT->show(); | |||
2816 | } | |||
2817 | else | |||
2818 | { | |||
2819 | m_xRotationContainer->show(); | |||
2820 | m_xScalingAndRotationFT->show(); | |||
2821 | m_xScalingFT->hide(); | |||
2822 | ||||
2823 | if( eState >= SfxItemState::DEFAULT ) | |||
2824 | { | |||
2825 | const SvxCharRotateItem& rItem = | |||
2826 | static_cast<const SvxCharRotateItem&>( rSet->Get( nWhich )); | |||
2827 | if (rItem.IsBottomToTop()) | |||
2828 | m_x90degRB->set_active(true); | |||
2829 | else if (rItem.IsTopToBottom()) | |||
2830 | m_x270degRB->set_active(true); | |||
2831 | else | |||
2832 | { | |||
2833 | DBG_ASSERT( 0 == rItem.GetValue(), "incorrect value" )do { if (true && (!(0 == rItem.GetValue()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/chardlg.cxx" ":" "2833" ": "), "%s", "incorrect value"); } } while (false ); | |||
2834 | m_x0degRB->set_active(true); | |||
2835 | } | |||
2836 | m_xFitToLineCB->set_active(rItem.IsFitToLine()); | |||
2837 | } | |||
2838 | else | |||
2839 | { | |||
2840 | if( eState == SfxItemState::DONTCARE ) | |||
2841 | { | |||
2842 | m_x0degRB->set_active(false); | |||
2843 | m_x90degRB->set_active(false); | |||
2844 | m_x270degRB->set_active(false); | |||
2845 | } | |||
2846 | else | |||
2847 | m_x0degRB->set_active(true); | |||
2848 | ||||
2849 | m_xFitToLineCB->set_active(false); | |||
2850 | } | |||
2851 | m_xFitToLineCB->set_sensitive(!m_x0degRB->get_active()); | |||
2852 | ||||
2853 | // is this value set? | |||
2854 | if( SfxItemState::UNKNOWN == rSet->GetItemState( GetWhich( | |||
2855 | SID_ATTR_CHAR_WIDTH_FIT_TO_LINE( 10000 + 919 ) ) )) | |||
2856 | m_xFitToLineCB->hide(); | |||
2857 | } | |||
2858 | ChangesApplied(); | |||
2859 | } | |||
2860 | ||||
2861 | void SvxCharPositionPage::ChangesApplied() | |||
2862 | { | |||
2863 | m_xHighPosBtn->save_state(); | |||
2864 | m_xNormalPosBtn->save_state(); | |||
2865 | m_xLowPosBtn->save_state(); | |||
2866 | m_xHighLowRB->save_state(); | |||
2867 | m_x0degRB->save_state(); | |||
2868 | m_x90degRB->save_state(); | |||
2869 | m_x270degRB->save_state(); | |||
2870 | m_xFitToLineCB->save_state(); | |||
2871 | m_xScaleWidthMF->save_value(); | |||
2872 | m_xKerningMF->save_value(); | |||
2873 | m_xPairKerningBtn->save_state(); | |||
2874 | } | |||
2875 | ||||
2876 | bool SvxCharPositionPage::FillItemSet( SfxItemSet* rSet ) | |||
2877 | { | |||
2878 | // Position (high, normal or low) | |||
2879 | const SfxItemSet& rOldSet = GetItemSet(); | |||
2880 | bool bModified = false, bChanged = true; | |||
2881 | sal_uInt16 nWhich = GetWhich( SID_ATTR_CHAR_ESCAPEMENT( 10000 + 21 ) ); | |||
2882 | const SfxPoolItem* pOld = GetOldItem( *rSet, SID_ATTR_CHAR_ESCAPEMENT( 10000 + 21 ) ); | |||
2883 | const bool bHigh = m_xHighPosBtn->get_active(); | |||
2884 | short nEsc; | |||
2885 | sal_uInt8 nEscProp; | |||
2886 | ||||
2887 | if (bHigh || m_xLowPosBtn->get_active()) | |||
2888 | { | |||
2889 | if (m_xHighLowRB->get_active()) | |||
2890 | nEsc = bHigh ? DFLT_ESC_AUTO_SUPER(13999 +1) : DFLT_ESC_AUTO_SUB-(13999 +1); | |||
2891 | else | |||
2892 | { | |||
2893 | nEsc = static_cast<short>(m_xHighLowMF->denormalize(m_xHighLowMF->get_value(FieldUnit::PERCENT))); | |||
2894 | nEsc *= (bHigh ? 1 : -1); | |||
2895 | } | |||
2896 | nEscProp = static_cast<sal_uInt8>(m_xFontSizeMF->denormalize(m_xFontSizeMF->get_value(FieldUnit::PERCENT))); | |||
2897 | } | |||
2898 | else | |||
2899 | { | |||
2900 | nEsc = 0; | |||
2901 | nEscProp = 100; | |||
2902 | } | |||
2903 | ||||
2904 | if ( pOld ) | |||
2905 | { | |||
2906 | const SvxEscapementItem& rItem = *static_cast<const SvxEscapementItem*>(pOld); | |||
2907 | if (rItem.GetEsc() == nEsc && rItem.GetProportionalHeight() == nEscProp) | |||
2908 | bChanged = false; | |||
2909 | } | |||
2910 | ||||
2911 | if ( !bChanged && !m_xHighPosBtn->get_saved_state() && | |||
2912 | !m_xNormalPosBtn->get_saved_state() && !m_xLowPosBtn->get_saved_state() ) | |||
2913 | bChanged = true; | |||
2914 | ||||
2915 | if ( bChanged && | |||
2916 | ( m_xHighPosBtn->get_active() || m_xNormalPosBtn->get_active() || m_xLowPosBtn->get_active() ) ) | |||
2917 | { | |||
2918 | rSet->Put( SvxEscapementItem( nEsc, nEscProp, nWhich ) ); | |||
2919 | bModified = true; | |||
2920 | } | |||
2921 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2922 | rSet->InvalidateItem(nWhich); | |||
2923 | ||||
2924 | bChanged = true; | |||
2925 | ||||
2926 | // Kerning | |||
2927 | nWhich = GetWhich( SID_ATTR_CHAR_KERNING( 10000 + 18 ) ); | |||
2928 | pOld = GetOldItem( *rSet, SID_ATTR_CHAR_KERNING( 10000 + 18 ) ); | |||
2929 | short nKerning = 0; | |||
2930 | MapUnit eUnit = rSet->GetPool()->GetMetric( nWhich ); | |||
2931 | ||||
2932 | long nTmp = static_cast<long>(m_xKerningMF->get_value(FieldUnit::POINT)); | |||
2933 | long nVal = OutputDevice::LogicToLogic(nTmp, MapUnit::MapPoint, eUnit); | |||
2934 | nKerning = static_cast<short>(m_xKerningMF->denormalize( nVal )); | |||
2935 | ||||
2936 | SfxItemState eOldKernState = rOldSet.GetItemState( nWhich, false ); | |||
2937 | if ( pOld ) | |||
2938 | { | |||
2939 | const SvxKerningItem& rItem = *static_cast<const SvxKerningItem*>(pOld); | |||
2940 | if ( (eOldKernState >= SfxItemState::DEFAULT || m_xKerningMF->get_text().isEmpty()) && rItem.GetValue() == nKerning ) | |||
2941 | bChanged = false; | |||
2942 | } | |||
2943 | ||||
2944 | if ( bChanged ) | |||
2945 | { | |||
2946 | rSet->Put( SvxKerningItem( nKerning, nWhich ) ); | |||
2947 | bModified = true; | |||
2948 | } | |||
2949 | else if ( SfxItemState::DEFAULT == eOldKernState ) | |||
2950 | rSet->InvalidateItem(nWhich); | |||
2951 | ||||
2952 | // Pair-Kerning | |||
2953 | nWhich = GetWhich( SID_ATTR_CHAR_AUTOKERN( 10000 + 67 ) ); | |||
2954 | ||||
2955 | if (m_xPairKerningBtn->get_state_changed_from_saved()) | |||
2956 | { | |||
2957 | rSet->Put( SvxAutoKernItem( m_xPairKerningBtn->get_active(), nWhich ) ); | |||
2958 | bModified = true; | |||
2959 | } | |||
2960 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2961 | rSet->InvalidateItem(nWhich); | |||
2962 | ||||
2963 | // Scale Width | |||
2964 | nWhich = GetWhich( SID_ATTR_CHAR_SCALEWIDTH( 10000 + 911 ) ); | |||
2965 | if (m_xScaleWidthMF->get_value_changed_from_saved()) | |||
2966 | { | |||
2967 | rSet->Put(SvxCharScaleWidthItem(static_cast<sal_uInt16>(m_xScaleWidthMF->get_value(FieldUnit::PERCENT)), nWhich)); | |||
2968 | bModified = true; | |||
2969 | } | |||
2970 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2971 | rSet->InvalidateItem(nWhich); | |||
2972 | ||||
2973 | // Rotation | |||
2974 | nWhich = GetWhich( SID_ATTR_CHAR_ROTATED( 10000 + 910 ) ); | |||
2975 | if ( m_x0degRB->get_state_changed_from_saved() || | |||
2976 | m_x90degRB->get_state_changed_from_saved() || | |||
2977 | m_x270degRB->get_state_changed_from_saved() || | |||
2978 | m_xFitToLineCB->get_state_changed_from_saved() ) | |||
2979 | { | |||
2980 | SvxCharRotateItem aItem( 0, m_xFitToLineCB->get_active(), nWhich ); | |||
2981 | if (m_x90degRB->get_active()) | |||
2982 | aItem.SetBottomToTop(); | |||
2983 | else if (m_x270degRB->get_active()) | |||
2984 | aItem.SetTopToBottom(); | |||
2985 | rSet->Put( aItem ); | |||
2986 | bModified = true; | |||
2987 | } | |||
2988 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
2989 | rSet->InvalidateItem(nWhich); | |||
2990 | ||||
2991 | return bModified; | |||
2992 | } | |||
2993 | ||||
2994 | ||||
2995 | void SvxCharPositionPage::FillUserData() | |||
2996 | { | |||
2997 | const OUString cTok( ";" ); | |||
2998 | ||||
2999 | OUString sUser = OUString::number( m_nSuperEsc ) + cTok + | |||
3000 | OUString::number( m_nSubEsc ) + cTok + | |||
3001 | OUString::number( m_nSuperProp ) + cTok + | |||
3002 | OUString::number( m_nSubProp ); | |||
3003 | SetUserData( sUser ); | |||
3004 | } | |||
3005 | ||||
3006 | ||||
3007 | void SvxCharPositionPage::PageCreated(const SfxAllItemSet& aSet) | |||
3008 | { | |||
3009 | const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_FLAG_TYPE( 10000 + 1034 ), false); | |||
3010 | if (pFlagItem) | |||
3011 | { | |||
3012 | sal_uInt32 nFlags=pFlagItem->GetValue(); | |||
3013 | if ( ( nFlags & SVX_PREVIEW_CHARACTER0x01 ) == SVX_PREVIEW_CHARACTER0x01 ) | |||
3014 | // the writer uses SID_ATTR_BRUSH as font background | |||
3015 | m_bPreviewBackgroundToCharacter = true; | |||
3016 | } | |||
3017 | } | |||
3018 | // class SvxCharTwoLinesPage ------------------------------------------------ | |||
3019 | ||||
3020 | SvxCharTwoLinesPage::SvxCharTwoLinesPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInSet) | |||
3021 | : SvxCharBasePage(pPage, pController, "cui/ui/twolinespage.ui", "TwoLinesPage", rInSet) | |||
3022 | , m_nStartBracketPosition( 0 ) | |||
3023 | , m_nEndBracketPosition( 0 ) | |||
3024 | , m_xTwoLinesBtn(m_xBuilder->weld_check_button("twolines")) | |||
3025 | , m_xEnclosingFrame(m_xBuilder->weld_widget("enclosing")) | |||
3026 | , m_xStartBracketLB(m_xBuilder->weld_tree_view("startbracket")) | |||
3027 | , m_xEndBracketLB(m_xBuilder->weld_tree_view("endbracket")) | |||
3028 | { | |||
3029 | for (size_t i = 0; i < SAL_N_ELEMENTS(TWOLINE_OPEN)(sizeof(sal_n_array_size(TWOLINE_OPEN))); ++i) | |||
3030 | m_xStartBracketLB->append(OUString::number(TWOLINE_OPEN[i].second), CuiResId(TWOLINE_OPEN[i].first)); | |||
3031 | for (size_t i = 0; i < SAL_N_ELEMENTS(TWOLINE_CLOSE)(sizeof(sal_n_array_size(TWOLINE_CLOSE))); ++i) | |||
3032 | m_xEndBracketLB->append(OUString::number(TWOLINE_CLOSE[i].second), CuiResId(TWOLINE_CLOSE[i].first)); | |||
3033 | ||||
3034 | m_xPreviewWin.reset(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWin)); | |||
3035 | #ifdef IOS | |||
3036 | m_xPreviewWin->hide(); | |||
3037 | #endif | |||
3038 | Initialize(); | |||
3039 | } | |||
3040 | ||||
3041 | SvxCharTwoLinesPage::~SvxCharTwoLinesPage() | |||
3042 | { | |||
3043 | } | |||
3044 | ||||
3045 | void SvxCharTwoLinesPage::Initialize() | |||
3046 | { | |||
3047 | m_xTwoLinesBtn->set_active(false); | |||
3048 | TwoLinesHdl_Impl(*m_xTwoLinesBtn); | |||
3049 | ||||
3050 | m_xTwoLinesBtn->connect_toggled(LINK(this, SvxCharTwoLinesPage, TwoLinesHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharTwoLinesPage *>(this), &SvxCharTwoLinesPage::LinkStubTwoLinesHdl_Impl )); | |||
3051 | ||||
3052 | Link<weld::TreeView&,void> aLink = LINK(this, SvxCharTwoLinesPage, CharacterMapHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxCharTwoLinesPage *>(this), &SvxCharTwoLinesPage::LinkStubCharacterMapHdl_Impl ); | |||
3053 | m_xStartBracketLB->connect_changed(aLink); | |||
3054 | m_xEndBracketLB->connect_changed(aLink); | |||
3055 | ||||
3056 | SvxFont& rFont = GetPreviewFont(); | |||
3057 | SvxFont& rCJKFont = GetPreviewCJKFont(); | |||
3058 | SvxFont& rCTLFont = GetPreviewCTLFont(); | |||
3059 | rFont.SetFontSize( Size( 0, 220 ) ); | |||
3060 | rCJKFont.SetFontSize( Size( 0, 220 ) ); | |||
3061 | rCTLFont.SetFontSize( Size( 0, 220 ) ); | |||
3062 | } | |||
3063 | ||||
3064 | void SvxCharTwoLinesPage::SelectCharacter(weld::TreeView* pBox) | |||
3065 | { | |||
3066 | bool bStart = pBox == m_xStartBracketLB.get(); | |||
3067 | SvxCharacterMap aDlg(GetFrameWeld(), nullptr, nullptr); | |||
3068 | aDlg.DisableFontSelection(); | |||
3069 | ||||
3070 | if (aDlg.run() == RET_OK) | |||
3071 | { | |||
3072 | sal_Unicode cChar = static_cast<sal_Unicode>(aDlg.GetChar()); | |||
3073 | SetBracket( cChar, bStart ); | |||
3074 | } | |||
3075 | else | |||
3076 | { | |||
3077 | pBox->select(bStart ? m_nStartBracketPosition : m_nEndBracketPosition); | |||
3078 | } | |||
3079 | } | |||
3080 | ||||
3081 | ||||
3082 | void SvxCharTwoLinesPage::SetBracket( sal_Unicode cBracket, bool bStart ) | |||
3083 | { | |||
3084 | int nEntryPos = 0; | |||
3085 | weld::TreeView* pBox = bStart ? m_xStartBracketLB.get() : m_xEndBracketLB.get(); | |||
3086 | if (cBracket == 0) | |||
3087 | pBox->select(0); | |||
3088 | else | |||
3089 | { | |||
3090 | bool bFound = false; | |||
3091 | for (int i = 1; i < pBox->n_children(); ++i) | |||
3092 | { | |||
3093 | if (pBox->get_id(i).toInt32() != CHRDLG_ENCLOSE_SPECIAL_CHAR5) | |||
3094 | { | |||
3095 | const sal_Unicode cChar = pBox->get_text(i)[0]; | |||
3096 | if (cChar == cBracket) | |||
3097 | { | |||
3098 | pBox->select(i); | |||
3099 | nEntryPos = i; | |||
3100 | bFound = true; | |||
3101 | break; | |||
3102 | } | |||
3103 | } | |||
3104 | } | |||
3105 | ||||
3106 | if (!bFound) | |||
3107 | { | |||
3108 | pBox->append_text(OUString(cBracket)); | |||
3109 | nEntryPos = pBox->n_children() - 1; | |||
3110 | pBox->select(nEntryPos); | |||
3111 | } | |||
3112 | } | |||
3113 | if (bStart) | |||
3114 | m_nStartBracketPosition = nEntryPos; | |||
3115 | else | |||
3116 | m_nEndBracketPosition = nEntryPos; | |||
3117 | } | |||
3118 | ||||
3119 | IMPL_LINK_NOARG(SvxCharTwoLinesPage, TwoLinesHdl_Impl, weld::ToggleButton&, void)void SvxCharTwoLinesPage::LinkStubTwoLinesHdl_Impl(void * instance , weld::ToggleButton& data) { return static_cast<SvxCharTwoLinesPage *>(instance)->TwoLinesHdl_Impl(data); } void SvxCharTwoLinesPage ::TwoLinesHdl_Impl(__attribute__ ((unused)) weld::ToggleButton &) | |||
3120 | { | |||
3121 | bool bChecked = m_xTwoLinesBtn->get_active(); | |||
3122 | m_xEnclosingFrame->set_sensitive(bChecked); | |||
3123 | UpdatePreview_Impl(); | |||
3124 | } | |||
3125 | ||||
3126 | IMPL_LINK(SvxCharTwoLinesPage, CharacterMapHdl_Impl, weld::TreeView&, rBox, void)void SvxCharTwoLinesPage::LinkStubCharacterMapHdl_Impl(void * instance, weld::TreeView& data) { return static_cast< SvxCharTwoLinesPage *>(instance)->CharacterMapHdl_Impl( data); } void SvxCharTwoLinesPage::CharacterMapHdl_Impl(weld:: TreeView& rBox) | |||
3127 | { | |||
3128 | int nPos = rBox.get_selected_index(); | |||
3129 | if (rBox.get_id(nPos).toInt32() == CHRDLG_ENCLOSE_SPECIAL_CHAR5) | |||
3130 | SelectCharacter( &rBox ); | |||
3131 | else | |||
3132 | { | |||
3133 | bool bStart = &rBox == m_xStartBracketLB.get(); | |||
3134 | if (bStart) | |||
3135 | m_nStartBracketPosition = nPos; | |||
3136 | else | |||
3137 | m_nEndBracketPosition = nPos; | |||
3138 | } | |||
3139 | UpdatePreview_Impl(); | |||
3140 | } | |||
3141 | ||||
3142 | void SvxCharTwoLinesPage::ActivatePage( const SfxItemSet& rSet ) | |||
3143 | { | |||
3144 | SvxCharBasePage::ActivatePage(rSet); | |||
3145 | } | |||
3146 | ||||
3147 | DeactivateRC SvxCharTwoLinesPage::DeactivatePage( SfxItemSet* _pSet ) | |||
3148 | { | |||
3149 | if ( _pSet ) | |||
3150 | FillItemSet( _pSet ); | |||
3151 | return DeactivateRC::LeavePage; | |||
3152 | } | |||
3153 | ||||
3154 | std::unique_ptr<SfxTabPage> SvxCharTwoLinesPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet) | |||
3155 | { | |||
3156 | return std::make_unique<SvxCharTwoLinesPage>(pPage, pController, *rSet); | |||
3157 | } | |||
3158 | ||||
3159 | void SvxCharTwoLinesPage::Reset( const SfxItemSet* rSet ) | |||
3160 | { | |||
3161 | m_xTwoLinesBtn->set_active(false); | |||
3162 | sal_uInt16 nWhich = GetWhich( SID_ATTR_CHAR_TWO_LINES( 10000 + 897 ) ); | |||
3163 | SfxItemState eState = rSet->GetItemState( nWhich ); | |||
3164 | ||||
3165 | if ( eState >= SfxItemState::DONTCARE ) | |||
3166 | { | |||
3167 | const SvxTwoLinesItem& rItem = static_cast<const SvxTwoLinesItem&>(rSet->Get( nWhich )); | |||
3168 | m_xTwoLinesBtn->set_active(rItem.GetValue()); | |||
3169 | ||||
3170 | if ( rItem.GetValue() ) | |||
3171 | { | |||
3172 | SetBracket( rItem.GetStartBracket(), true ); | |||
3173 | SetBracket( rItem.GetEndBracket(), false ); | |||
3174 | } | |||
3175 | } | |||
3176 | TwoLinesHdl_Impl(*m_xTwoLinesBtn); | |||
3177 | ||||
3178 | SetPrevFontWidthScale( *rSet ); | |||
3179 | } | |||
3180 | ||||
3181 | bool SvxCharTwoLinesPage::FillItemSet( SfxItemSet* rSet ) | |||
3182 | { | |||
3183 | const SfxItemSet& rOldSet = GetItemSet(); | |||
3184 | bool bModified = false, bChanged = true; | |||
3185 | sal_uInt16 nWhich = GetWhich( SID_ATTR_CHAR_TWO_LINES( 10000 + 897 ) ); | |||
3186 | const SfxPoolItem* pOld = GetOldItem( *rSet, SID_ATTR_CHAR_TWO_LINES( 10000 + 897 ) ); | |||
3187 | bool bOn = m_xTwoLinesBtn->get_active(); | |||
3188 | sal_Unicode cStart = ( bOn && m_xStartBracketLB->get_selected_index() > 0 ) | |||
3189 | ? m_xStartBracketLB->get_selected_text()[0] : 0; | |||
3190 | sal_Unicode cEnd = ( bOn && m_xEndBracketLB->get_selected_index() > 0 ) | |||
3191 | ? m_xEndBracketLB->get_selected_text()[0] : 0; | |||
3192 | ||||
3193 | if ( pOld ) | |||
3194 | { | |||
3195 | const SvxTwoLinesItem& rItem = *static_cast<const SvxTwoLinesItem*>(pOld); | |||
3196 | if ( rItem.GetValue() == bOn && | |||
3197 | ( !bOn || ( rItem.GetStartBracket() == cStart && rItem.GetEndBracket() == cEnd ) ) ) | |||
3198 | bChanged = false; | |||
3199 | } | |||
3200 | ||||
3201 | if ( bChanged ) | |||
3202 | { | |||
3203 | rSet->Put( SvxTwoLinesItem( bOn, cStart, cEnd, nWhich ) ); | |||
3204 | bModified = true; | |||
3205 | } | |||
3206 | else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) | |||
3207 | rSet->InvalidateItem(nWhich); | |||
3208 | ||||
3209 | return bModified; | |||
3210 | } | |||
3211 | ||||
3212 | void SvxCharTwoLinesPage::UpdatePreview_Impl() | |||
3213 | { | |||
3214 | sal_Unicode cStart = m_xStartBracketLB->get_selected_index() > 0 | |||
3215 | ? m_xStartBracketLB->get_selected_text()[0] : 0; | |||
3216 | sal_Unicode cEnd = m_xEndBracketLB->get_selected_index() > 0 | |||
3217 | ? m_xEndBracketLB->get_selected_text()[0] : 0; | |||
3218 | m_aPreviewWin.SetBrackets(cStart, cEnd); | |||
3219 | m_aPreviewWin.SetTwoLines(m_xTwoLinesBtn->get_active()); | |||
3220 | m_aPreviewWin.Invalidate(); | |||
3221 | } | |||
3222 | ||||
3223 | void SvxCharTwoLinesPage::PageCreated(const SfxAllItemSet& aSet) | |||
3224 | { | |||
3225 | const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_FLAG_TYPE( 10000 + 1034 ), false); | |||
3226 | if (pFlagItem) | |||
3227 | { | |||
3228 | sal_uInt32 nFlags=pFlagItem->GetValue(); | |||
3229 | if ( ( nFlags & SVX_PREVIEW_CHARACTER0x01 ) == SVX_PREVIEW_CHARACTER0x01 ) | |||
3230 | // the writer uses SID_ATTR_BRUSH as font background | |||
3231 | m_bPreviewBackgroundToCharacter = true; | |||
3232 | } | |||
3233 | } | |||
3234 | ||||
3235 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | // unique_ptr implementation -*- C++ -*- |
2 | |
3 | // Copyright (C) 2008-2020 Free Software Foundation, Inc. |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free |
6 | // software; you can redistribute it and/or modify it under the |
7 | // terms of the GNU General Public License as published by the |
8 | // Free Software Foundation; either version 3, or (at your option) |
9 | // any later version. |
10 | |
11 | // This library is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU General Public License for more details. |
15 | |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version |
18 | // 3.1, as published by the Free Software Foundation. |
19 | |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
23 | // <http://www.gnu.org/licenses/>. |
24 | |
25 | /** @file bits/unique_ptr.h |
26 | * This is an internal header file, included by other library headers. |
27 | * Do not attempt to use it directly. @headername{memory} |
28 | */ |
29 | |
30 | #ifndef _UNIQUE_PTR_H1 |
31 | #define _UNIQUE_PTR_H1 1 |
32 | |
33 | #include <bits/c++config.h> |
34 | #include <debug/assertions.h> |
35 | #include <type_traits> |
36 | #include <utility> |
37 | #include <tuple> |
38 | #include <bits/stl_function.h> |
39 | #include <bits/functional_hash.h> |
40 | #if __cplusplus201703L > 201703L |
41 | # include <compare> |
42 | # include <ostream> |
43 | #endif |
44 | |
45 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
46 | { |
47 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
48 | |
49 | /** |
50 | * @addtogroup pointer_abstractions |
51 | * @{ |
52 | */ |
53 | |
54 | #if _GLIBCXX_USE_DEPRECATED1 |
55 | #pragma GCC diagnostic push |
56 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
57 | template<typename> class auto_ptr; |
58 | #pragma GCC diagnostic pop |
59 | #endif |
60 | |
61 | /// Primary template of default_delete, used by unique_ptr for single objects |
62 | template<typename _Tp> |
63 | struct default_delete |
64 | { |
65 | /// Default constructor |
66 | constexpr default_delete() noexcept = default; |
67 | |
68 | /** @brief Converting constructor. |
69 | * |
70 | * Allows conversion from a deleter for objects of another type, `_Up`, |
71 | * only if `_Up*` is convertible to `_Tp*`. |
72 | */ |
73 | template<typename _Up, |
74 | typename = _Require<is_convertible<_Up*, _Tp*>>> |
75 | default_delete(const default_delete<_Up>&) noexcept { } |
76 | |
77 | /// Calls `delete __ptr` |
78 | void |
79 | operator()(_Tp* __ptr) const |
80 | { |
81 | static_assert(!is_void<_Tp>::value, |
82 | "can't delete pointer to incomplete type"); |
83 | static_assert(sizeof(_Tp)>0, |
84 | "can't delete pointer to incomplete type"); |
85 | delete __ptr; |
86 | } |
87 | }; |
88 | |
89 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
90 | // DR 740 - omit specialization for array objects with a compile time length |
91 | |
92 | /// Specialization of default_delete for arrays, used by `unique_ptr<T[]>` |
93 | template<typename _Tp> |
94 | struct default_delete<_Tp[]> |
95 | { |
96 | public: |
97 | /// Default constructor |
98 | constexpr default_delete() noexcept = default; |
99 | |
100 | /** @brief Converting constructor. |
101 | * |
102 | * Allows conversion from a deleter for arrays of another type, such as |
103 | * a const-qualified version of `_Tp`. |
104 | * |
105 | * Conversions from types derived from `_Tp` are not allowed because |
106 | * it is undefined to `delete[]` an array of derived types through a |
107 | * pointer to the base type. |
108 | */ |
109 | template<typename _Up, |
110 | typename = _Require<is_convertible<_Up(*)[], _Tp(*)[]>>> |
111 | default_delete(const default_delete<_Up[]>&) noexcept { } |
112 | |
113 | /// Calls `delete[] __ptr` |
114 | template<typename _Up> |
115 | typename enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value>::type |
116 | operator()(_Up* __ptr) const |
117 | { |
118 | static_assert(sizeof(_Tp)>0, |
119 | "can't delete pointer to incomplete type"); |
120 | delete [] __ptr; |
121 | } |
122 | }; |
123 | |
124 | /// @cond undocumented |
125 | |
126 | // Manages the pointer and deleter of a unique_ptr |
127 | template <typename _Tp, typename _Dp> |
128 | class __uniq_ptr_impl |
129 | { |
130 | template <typename _Up, typename _Ep, typename = void> |
131 | struct _Ptr |
132 | { |
133 | using type = _Up*; |
134 | }; |
135 | |
136 | template <typename _Up, typename _Ep> |
137 | struct |
138 | _Ptr<_Up, _Ep, __void_t<typename remove_reference<_Ep>::type::pointer>> |
139 | { |
140 | using type = typename remove_reference<_Ep>::type::pointer; |
141 | }; |
142 | |
143 | public: |
144 | using _DeleterConstraint = enable_if< |
145 | __and_<__not_<is_pointer<_Dp>>, |
146 | is_default_constructible<_Dp>>::value>; |
147 | |
148 | using pointer = typename _Ptr<_Tp, _Dp>::type; |
149 | |
150 | static_assert( !is_rvalue_reference<_Dp>::value, |
151 | "unique_ptr's deleter type must be a function object type" |
152 | " or an lvalue reference type" ); |
153 | |
154 | __uniq_ptr_impl() = default; |
155 | __uniq_ptr_impl(pointer __p) : _M_t() { _M_ptr() = __p; } |
156 | |
157 | template<typename _Del> |
158 | __uniq_ptr_impl(pointer __p, _Del&& __d) |
159 | : _M_t(__p, std::forward<_Del>(__d)) { } |
160 | |
161 | __uniq_ptr_impl(__uniq_ptr_impl&& __u) noexcept |
162 | : _M_t(std::move(__u._M_t)) |
163 | { __u._M_ptr() = nullptr; } |
164 | |
165 | __uniq_ptr_impl& operator=(__uniq_ptr_impl&& __u) noexcept |
166 | { |
167 | reset(__u.release()); |
168 | _M_deleter() = std::forward<_Dp>(__u._M_deleter()); |
169 | return *this; |
170 | } |
171 | |
172 | pointer& _M_ptr() { return std::get<0>(_M_t); } |
173 | pointer _M_ptr() const { return std::get<0>(_M_t); } |
174 | _Dp& _M_deleter() { return std::get<1>(_M_t); } |
175 | const _Dp& _M_deleter() const { return std::get<1>(_M_t); } |
176 | |
177 | void reset(pointer __p) noexcept |
178 | { |
179 | const pointer __old_p = _M_ptr(); |
180 | _M_ptr() = __p; |
181 | if (__old_p) |
182 | _M_deleter()(__old_p); |
183 | } |
184 | |
185 | pointer release() noexcept |
186 | { |
187 | pointer __p = _M_ptr(); |
188 | _M_ptr() = nullptr; |
189 | return __p; |
190 | } |
191 | |
192 | void |
193 | swap(__uniq_ptr_impl& __rhs) noexcept |
194 | { |
195 | using std::swap; |
196 | swap(this->_M_ptr(), __rhs._M_ptr()); |
197 | swap(this->_M_deleter(), __rhs._M_deleter()); |
198 | } |
199 | |
200 | private: |
201 | tuple<pointer, _Dp> _M_t; |
202 | }; |
203 | |
204 | // Defines move construction + assignment as either defaulted or deleted. |
205 | template <typename _Tp, typename _Dp, |
206 | bool = is_move_constructible<_Dp>::value, |
207 | bool = is_move_assignable<_Dp>::value> |
208 | struct __uniq_ptr_data : __uniq_ptr_impl<_Tp, _Dp> |
209 | { |
210 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
211 | __uniq_ptr_data(__uniq_ptr_data&&) = default; |
212 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = default; |
213 | }; |
214 | |
215 | template <typename _Tp, typename _Dp> |
216 | struct __uniq_ptr_data<_Tp, _Dp, true, false> : __uniq_ptr_impl<_Tp, _Dp> |
217 | { |
218 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
219 | __uniq_ptr_data(__uniq_ptr_data&&) = default; |
220 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = delete; |
221 | }; |
222 | |
223 | template <typename _Tp, typename _Dp> |
224 | struct __uniq_ptr_data<_Tp, _Dp, false, true> : __uniq_ptr_impl<_Tp, _Dp> |
225 | { |
226 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
227 | __uniq_ptr_data(__uniq_ptr_data&&) = delete; |
228 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = default; |
229 | }; |
230 | |
231 | template <typename _Tp, typename _Dp> |
232 | struct __uniq_ptr_data<_Tp, _Dp, false, false> : __uniq_ptr_impl<_Tp, _Dp> |
233 | { |
234 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
235 | __uniq_ptr_data(__uniq_ptr_data&&) = delete; |
236 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = delete; |
237 | }; |
238 | /// @endcond |
239 | |
240 | /// 20.7.1.2 unique_ptr for single objects. |
241 | template <typename _Tp, typename _Dp = default_delete<_Tp>> |
242 | class unique_ptr |
243 | { |
244 | template <typename _Up> |
245 | using _DeleterConstraint = |
246 | typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type; |
247 | |
248 | __uniq_ptr_data<_Tp, _Dp> _M_t; |
249 | |
250 | public: |
251 | using pointer = typename __uniq_ptr_impl<_Tp, _Dp>::pointer; |
252 | using element_type = _Tp; |
253 | using deleter_type = _Dp; |
254 | |
255 | private: |
256 | // helper template for detecting a safe conversion from another |
257 | // unique_ptr |
258 | template<typename _Up, typename _Ep> |
259 | using __safe_conversion_up = __and_< |
260 | is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>, |
261 | __not_<is_array<_Up>> |
262 | >; |
263 | |
264 | public: |
265 | // Constructors. |
266 | |
267 | /// Default constructor, creates a unique_ptr that owns nothing. |
268 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
269 | constexpr unique_ptr() noexcept |
270 | : _M_t() |
271 | { } |
272 | |
273 | /** Takes ownership of a pointer. |
274 | * |
275 | * @param __p A pointer to an object of @c element_type |
276 | * |
277 | * The deleter will be value-initialized. |
278 | */ |
279 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
280 | explicit |
281 | unique_ptr(pointer __p) noexcept |
282 | : _M_t(__p) |
283 | { } |
284 | |
285 | /** Takes ownership of a pointer. |
286 | * |
287 | * @param __p A pointer to an object of @c element_type |
288 | * @param __d A reference to a deleter. |
289 | * |
290 | * The deleter will be initialized with @p __d |
291 | */ |
292 | template<typename _Del = deleter_type, |
293 | typename = _Require<is_copy_constructible<_Del>>> |
294 | unique_ptr(pointer __p, const deleter_type& __d) noexcept |
295 | : _M_t(__p, __d) { } |
296 | |
297 | /** Takes ownership of a pointer. |
298 | * |
299 | * @param __p A pointer to an object of @c element_type |
300 | * @param __d An rvalue reference to a (non-reference) deleter. |
301 | * |
302 | * The deleter will be initialized with @p std::move(__d) |
303 | */ |
304 | template<typename _Del = deleter_type, |
305 | typename = _Require<is_move_constructible<_Del>>> |
306 | unique_ptr(pointer __p, |
307 | __enable_if_t<!is_lvalue_reference<_Del>::value, |
308 | _Del&&> __d) noexcept |
309 | : _M_t(__p, std::move(__d)) |
310 | { } |
311 | |
312 | template<typename _Del = deleter_type, |
313 | typename _DelUnref = typename remove_reference<_Del>::type> |
314 | unique_ptr(pointer, |
315 | __enable_if_t<is_lvalue_reference<_Del>::value, |
316 | _DelUnref&&>) = delete; |
317 | |
318 | /// Creates a unique_ptr that owns nothing. |
319 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
320 | constexpr unique_ptr(nullptr_t) noexcept |
321 | : _M_t() |
322 | { } |
323 | |
324 | // Move constructors. |
325 | |
326 | /// Move constructor. |
327 | unique_ptr(unique_ptr&&) = default; |
328 | |
329 | /** @brief Converting constructor from another type |
330 | * |
331 | * Requires that the pointer owned by @p __u is convertible to the |
332 | * type of pointer owned by this object, @p __u does not own an array, |
333 | * and @p __u has a compatible deleter type. |
334 | */ |
335 | template<typename _Up, typename _Ep, typename = _Require< |
336 | __safe_conversion_up<_Up, _Ep>, |
337 | typename conditional<is_reference<_Dp>::value, |
338 | is_same<_Ep, _Dp>, |
339 | is_convertible<_Ep, _Dp>>::type>> |
340 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept |
341 | : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter())) |
342 | { } |
343 | |
344 | #if _GLIBCXX_USE_DEPRECATED1 |
345 | #pragma GCC diagnostic push |
346 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
347 | /// Converting constructor from @c auto_ptr |
348 | template<typename _Up, typename = _Require< |
349 | is_convertible<_Up*, _Tp*>, is_same<_Dp, default_delete<_Tp>>>> |
350 | unique_ptr(auto_ptr<_Up>&& __u) noexcept; |
351 | #pragma GCC diagnostic pop |
352 | #endif |
353 | |
354 | /// Destructor, invokes the deleter if the stored pointer is not null. |
355 | ~unique_ptr() noexcept |
356 | { |
357 | static_assert(__is_invocable<deleter_type&, pointer>::value, |
358 | "unique_ptr's deleter must be invocable with a pointer"); |
359 | auto& __ptr = _M_t._M_ptr(); |
360 | if (__ptr != nullptr) |
361 | get_deleter()(std::move(__ptr)); |
362 | __ptr = pointer(); |
363 | } |
364 | |
365 | // Assignment. |
366 | |
367 | /** @brief Move assignment operator. |
368 | * |
369 | * Invokes the deleter if this object owns a pointer. |
370 | */ |
371 | unique_ptr& operator=(unique_ptr&&) = default; |
372 | |
373 | /** @brief Assignment from another type. |
374 | * |
375 | * @param __u The object to transfer ownership from, which owns a |
376 | * convertible pointer to a non-array object. |
377 | * |
378 | * Invokes the deleter if this object owns a pointer. |
379 | */ |
380 | template<typename _Up, typename _Ep> |
381 | typename enable_if< __and_< |
382 | __safe_conversion_up<_Up, _Ep>, |
383 | is_assignable<deleter_type&, _Ep&&> |
384 | >::value, |
385 | unique_ptr&>::type |
386 | operator=(unique_ptr<_Up, _Ep>&& __u) noexcept |
387 | { |
388 | reset(__u.release()); |
389 | get_deleter() = std::forward<_Ep>(__u.get_deleter()); |
390 | return *this; |
391 | } |
392 | |
393 | /// Reset the %unique_ptr to empty, invoking the deleter if necessary. |
394 | unique_ptr& |
395 | operator=(nullptr_t) noexcept |
396 | { |
397 | reset(); |
398 | return *this; |
399 | } |
400 | |
401 | // Observers. |
402 | |
403 | /// Dereference the stored pointer. |
404 | typename add_lvalue_reference<element_type>::type |
405 | operator*() const |
406 | { |
407 | __glibcxx_assert(get() != pointer()); |
408 | return *get(); |
409 | } |
410 | |
411 | /// Return the stored pointer. |
412 | pointer |
413 | operator->() const noexcept |
414 | { |
415 | _GLIBCXX_DEBUG_PEDASSERT(get() != pointer()); |
416 | return get(); |
417 | } |
418 | |
419 | /// Return the stored pointer. |
420 | pointer |
421 | get() const noexcept |
422 | { return _M_t._M_ptr(); } |
423 | |
424 | /// Return a reference to the stored deleter. |
425 | deleter_type& |
426 | get_deleter() noexcept |
427 | { return _M_t._M_deleter(); } |
428 | |
429 | /// Return a reference to the stored deleter. |
430 | const deleter_type& |
431 | get_deleter() const noexcept |
432 | { return _M_t._M_deleter(); } |
433 | |
434 | /// Return @c true if the stored pointer is not null. |
435 | explicit operator bool() const noexcept |
436 | { return get() == pointer() ? false : true; } |
437 | |
438 | // Modifiers. |
439 | |
440 | /// Release ownership of any stored pointer. |
441 | pointer |
442 | release() noexcept |
443 | { return _M_t.release(); } |
444 | |
445 | /** @brief Replace the stored pointer. |
446 | * |
447 | * @param __p The new pointer to store. |
448 | * |
449 | * The deleter will be invoked if a pointer is already owned. |
450 | */ |
451 | void |
452 | reset(pointer __p = pointer()) noexcept |
453 | { |
454 | static_assert(__is_invocable<deleter_type&, pointer>::value, |
455 | "unique_ptr's deleter must be invocable with a pointer"); |
456 | _M_t.reset(std::move(__p)); |
457 | } |
458 | |
459 | /// Exchange the pointer and deleter with another object. |
460 | void |
461 | swap(unique_ptr& __u) noexcept |
462 | { |
463 | static_assert(__is_swappable<_Dp>::value, "deleter must be swappable"); |
464 | _M_t.swap(__u._M_t); |
465 | } |
466 | |
467 | // Disable copy from lvalue. |
468 | unique_ptr(const unique_ptr&) = delete; |
469 | unique_ptr& operator=(const unique_ptr&) = delete; |
470 | }; |
471 | |
472 | /// 20.7.1.3 unique_ptr for array objects with a runtime length |
473 | // [unique.ptr.runtime] |
474 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
475 | // DR 740 - omit specialization for array objects with a compile time length |
476 | template<typename _Tp, typename _Dp> |
477 | class unique_ptr<_Tp[], _Dp> |
478 | { |
479 | template <typename _Up> |
480 | using _DeleterConstraint = |
481 | typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type; |
482 | |
483 | __uniq_ptr_data<_Tp, _Dp> _M_t; |
484 | |
485 | template<typename _Up> |
486 | using __remove_cv = typename remove_cv<_Up>::type; |
487 | |
488 | // like is_base_of<_Tp, _Up> but false if unqualified types are the same |
489 | template<typename _Up> |
490 | using __is_derived_Tp |
491 | = __and_< is_base_of<_Tp, _Up>, |
492 | __not_<is_same<__remove_cv<_Tp>, __remove_cv<_Up>>> >; |
493 | |
494 | public: |
495 | using pointer = typename __uniq_ptr_impl<_Tp, _Dp>::pointer; |
496 | using element_type = _Tp; |
497 | using deleter_type = _Dp; |
498 | |
499 | // helper template for detecting a safe conversion from another |
500 | // unique_ptr |
501 | template<typename _Up, typename _Ep, |
502 | typename _UPtr = unique_ptr<_Up, _Ep>, |
503 | typename _UP_pointer = typename _UPtr::pointer, |
504 | typename _UP_element_type = typename _UPtr::element_type> |
505 | using __safe_conversion_up = __and_< |
506 | is_array<_Up>, |
507 | is_same<pointer, element_type*>, |
508 | is_same<_UP_pointer, _UP_element_type*>, |
509 | is_convertible<_UP_element_type(*)[], element_type(*)[]> |
510 | >; |
511 | |
512 | // helper template for detecting a safe conversion from a raw pointer |
513 | template<typename _Up> |
514 | using __safe_conversion_raw = __and_< |
515 | __or_<__or_<is_same<_Up, pointer>, |
516 | is_same<_Up, nullptr_t>>, |
517 | __and_<is_pointer<_Up>, |
518 | is_same<pointer, element_type*>, |
519 | is_convertible< |
520 | typename remove_pointer<_Up>::type(*)[], |
521 | element_type(*)[]> |
522 | > |
523 | > |
524 | >; |
525 | |
526 | // Constructors. |
527 | |
528 | /// Default constructor, creates a unique_ptr that owns nothing. |
529 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
530 | constexpr unique_ptr() noexcept |
531 | : _M_t() |
532 | { } |
533 | |
534 | /** Takes ownership of a pointer. |
535 | * |
536 | * @param __p A pointer to an array of a type safely convertible |
537 | * to an array of @c element_type |
538 | * |
539 | * The deleter will be value-initialized. |
540 | */ |
541 | template<typename _Up, |
542 | typename _Vp = _Dp, |
543 | typename = _DeleterConstraint<_Vp>, |
544 | typename = typename enable_if< |
545 | __safe_conversion_raw<_Up>::value, bool>::type> |
546 | explicit |
547 | unique_ptr(_Up __p) noexcept |
548 | : _M_t(__p) |
549 | { } |
550 | |
551 | /** Takes ownership of a pointer. |
552 | * |
553 | * @param __p A pointer to an array of a type safely convertible |
554 | * to an array of @c element_type |
555 | * @param __d A reference to a deleter. |
556 | * |
557 | * The deleter will be initialized with @p __d |
558 | */ |
559 | template<typename _Up, typename _Del = deleter_type, |
560 | typename = _Require<__safe_conversion_raw<_Up>, |
561 | is_copy_constructible<_Del>>> |
562 | unique_ptr(_Up __p, const deleter_type& __d) noexcept |
563 | : _M_t(__p, __d) { } |
564 | |
565 | /** Takes ownership of a pointer. |
566 | * |
567 | * @param __p A pointer to an array of a type safely convertible |
568 | * to an array of @c element_type |
569 | * @param __d A reference to a deleter. |
570 | * |
571 | * The deleter will be initialized with @p std::move(__d) |
572 | */ |
573 | template<typename _Up, typename _Del = deleter_type, |
574 | typename = _Require<__safe_conversion_raw<_Up>, |
575 | is_move_constructible<_Del>>> |
576 | unique_ptr(_Up __p, |
577 | __enable_if_t<!is_lvalue_reference<_Del>::value, |
578 | _Del&&> __d) noexcept |
579 | : _M_t(std::move(__p), std::move(__d)) |
580 | { } |
581 | |
582 | template<typename _Up, typename _Del = deleter_type, |
583 | typename _DelUnref = typename remove_reference<_Del>::type, |
584 | typename = _Require<__safe_conversion_raw<_Up>>> |
585 | unique_ptr(_Up, |
586 | __enable_if_t<is_lvalue_reference<_Del>::value, |
587 | _DelUnref&&>) = delete; |
588 | |
589 | /// Move constructor. |
590 | unique_ptr(unique_ptr&&) = default; |
591 | |
592 | /// Creates a unique_ptr that owns nothing. |
593 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
594 | constexpr unique_ptr(nullptr_t) noexcept |
595 | : _M_t() |
596 | { } |
597 | |
598 | template<typename _Up, typename _Ep, typename = _Require< |
599 | __safe_conversion_up<_Up, _Ep>, |
600 | typename conditional<is_reference<_Dp>::value, |
601 | is_same<_Ep, _Dp>, |
602 | is_convertible<_Ep, _Dp>>::type>> |
603 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept |
604 | : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter())) |
605 | { } |
606 | |
607 | /// Destructor, invokes the deleter if the stored pointer is not null. |
608 | ~unique_ptr() |
609 | { |
610 | auto& __ptr = _M_t._M_ptr(); |
611 | if (__ptr != nullptr) |
612 | get_deleter()(__ptr); |
613 | __ptr = pointer(); |
614 | } |
615 | |
616 | // Assignment. |
617 | |
618 | /** @brief Move assignment operator. |
619 | * |
620 | * Invokes the deleter if this object owns a pointer. |
621 | */ |
622 | unique_ptr& |
623 | operator=(unique_ptr&&) = default; |
624 | |
625 | /** @brief Assignment from another type. |
626 | * |
627 | * @param __u The object to transfer ownership from, which owns a |
628 | * convertible pointer to an array object. |
629 | * |
630 | * Invokes the deleter if this object owns a pointer. |
631 | */ |
632 | template<typename _Up, typename _Ep> |
633 | typename |
634 | enable_if<__and_<__safe_conversion_up<_Up, _Ep>, |
635 | is_assignable<deleter_type&, _Ep&&> |
636 | >::value, |
637 | unique_ptr&>::type |
638 | operator=(unique_ptr<_Up, _Ep>&& __u) noexcept |
639 | { |
640 | reset(__u.release()); |
641 | get_deleter() = std::forward<_Ep>(__u.get_deleter()); |
642 | return *this; |
643 | } |
644 | |
645 | /// Reset the %unique_ptr to empty, invoking the deleter if necessary. |
646 | unique_ptr& |
647 | operator=(nullptr_t) noexcept |
648 | { |
649 | reset(); |
650 | return *this; |
651 | } |
652 | |
653 | // Observers. |
654 | |
655 | /// Access an element of owned array. |
656 | typename std::add_lvalue_reference<element_type>::type |
657 | operator[](size_t __i) const |
658 | { |
659 | __glibcxx_assert(get() != pointer()); |
660 | return get()[__i]; |
661 | } |
662 | |
663 | /// Return the stored pointer. |
664 | pointer |
665 | get() const noexcept |
666 | { return _M_t._M_ptr(); } |
667 | |
668 | /// Return a reference to the stored deleter. |
669 | deleter_type& |
670 | get_deleter() noexcept |
671 | { return _M_t._M_deleter(); } |
672 | |
673 | /// Return a reference to the stored deleter. |
674 | const deleter_type& |
675 | get_deleter() const noexcept |
676 | { return _M_t._M_deleter(); } |
677 | |
678 | /// Return @c true if the stored pointer is not null. |
679 | explicit operator bool() const noexcept |
680 | { return get() == pointer() ? false : true; } |
681 | |
682 | // Modifiers. |
683 | |
684 | /// Release ownership of any stored pointer. |
685 | pointer |
686 | release() noexcept |
687 | { return _M_t.release(); } |
688 | |
689 | /** @brief Replace the stored pointer. |
690 | * |
691 | * @param __p The new pointer to store. |
692 | * |
693 | * The deleter will be invoked if a pointer is already owned. |
694 | */ |
695 | template <typename _Up, |
696 | typename = _Require< |
697 | __or_<is_same<_Up, pointer>, |
698 | __and_<is_same<pointer, element_type*>, |
699 | is_pointer<_Up>, |
700 | is_convertible< |
701 | typename remove_pointer<_Up>::type(*)[], |
702 | element_type(*)[] |
703 | > |
704 | > |
705 | > |
706 | >> |
707 | void |
708 | reset(_Up __p) noexcept |
709 | { _M_t.reset(std::move(__p)); } |
710 | |
711 | void reset(nullptr_t = nullptr) noexcept |
712 | { reset(pointer()); } |
713 | |
714 | /// Exchange the pointer and deleter with another object. |
715 | void |
716 | swap(unique_ptr& __u) noexcept |
717 | { |
718 | static_assert(__is_swappable<_Dp>::value, "deleter must be swappable"); |
719 | _M_t.swap(__u._M_t); |
720 | } |
721 | |
722 | // Disable copy from lvalue. |
723 | unique_ptr(const unique_ptr&) = delete; |
724 | unique_ptr& operator=(const unique_ptr&) = delete; |
725 | }; |
726 | |
727 | /// @relates unique_ptr @{ |
728 | |
729 | /// Swap overload for unique_ptr |
730 | template<typename _Tp, typename _Dp> |
731 | inline |
732 | #if __cplusplus201703L > 201402L || !defined(__STRICT_ANSI__1) // c++1z or gnu++11 |
733 | // Constrained free swap overload, see p0185r1 |
734 | typename enable_if<__is_swappable<_Dp>::value>::type |
735 | #else |
736 | void |
737 | #endif |
738 | swap(unique_ptr<_Tp, _Dp>& __x, |
739 | unique_ptr<_Tp, _Dp>& __y) noexcept |
740 | { __x.swap(__y); } |
741 | |
742 | #if __cplusplus201703L > 201402L || !defined(__STRICT_ANSI__1) // c++1z or gnu++11 |
743 | template<typename _Tp, typename _Dp> |
744 | typename enable_if<!__is_swappable<_Dp>::value>::type |
745 | swap(unique_ptr<_Tp, _Dp>&, |
746 | unique_ptr<_Tp, _Dp>&) = delete; |
747 | #endif |
748 | |
749 | /// Equality operator for unique_ptr objects, compares the owned pointers |
750 | template<typename _Tp, typename _Dp, |
751 | typename _Up, typename _Ep> |
752 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
753 | operator==(const unique_ptr<_Tp, _Dp>& __x, |
754 | const unique_ptr<_Up, _Ep>& __y) |
755 | { return __x.get() == __y.get(); } |
756 | |
757 | /// unique_ptr comparison with nullptr |
758 | template<typename _Tp, typename _Dp> |
759 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
760 | operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept |
761 | { return !__x; } |
762 | |
763 | #ifndef __cpp_lib_three_way_comparison |
764 | /// unique_ptr comparison with nullptr |
765 | template<typename _Tp, typename _Dp> |
766 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
767 | operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept |
768 | { return !__x; } |
769 | |
770 | /// Inequality operator for unique_ptr objects, compares the owned pointers |
771 | template<typename _Tp, typename _Dp, |
772 | typename _Up, typename _Ep> |
773 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
774 | operator!=(const unique_ptr<_Tp, _Dp>& __x, |
775 | const unique_ptr<_Up, _Ep>& __y) |
776 | { return __x.get() != __y.get(); } |
777 | |
778 | /// unique_ptr comparison with nullptr |
779 | template<typename _Tp, typename _Dp> |
780 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
781 | operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept |
782 | { return (bool)__x; } |
783 | |
784 | /// unique_ptr comparison with nullptr |
785 | template<typename _Tp, typename _Dp> |
786 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
787 | operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept |
788 | { return (bool)__x; } |
789 | #endif // three way comparison |
790 | |
791 | /// Relational operator for unique_ptr objects, compares the owned pointers |
792 | template<typename _Tp, typename _Dp, |
793 | typename _Up, typename _Ep> |
794 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
795 | operator<(const unique_ptr<_Tp, _Dp>& __x, |
796 | const unique_ptr<_Up, _Ep>& __y) |
797 | { |
798 | typedef typename |
799 | std::common_type<typename unique_ptr<_Tp, _Dp>::pointer, |
800 | typename unique_ptr<_Up, _Ep>::pointer>::type _CT; |
801 | return std::less<_CT>()(__x.get(), __y.get()); |
802 | } |
803 | |
804 | /// unique_ptr comparison with nullptr |
805 | template<typename _Tp, typename _Dp> |
806 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
807 | operator<(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
808 | { |
809 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(), |
810 | nullptr); |
811 | } |
812 | |
813 | /// unique_ptr comparison with nullptr |
814 | template<typename _Tp, typename _Dp> |
815 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
816 | operator<(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
817 | { |
818 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr, |
819 | __x.get()); |
820 | } |
821 | |
822 | /// Relational operator for unique_ptr objects, compares the owned pointers |
823 | template<typename _Tp, typename _Dp, |
824 | typename _Up, typename _Ep> |
825 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
826 | operator<=(const unique_ptr<_Tp, _Dp>& __x, |
827 | const unique_ptr<_Up, _Ep>& __y) |
828 | { return !(__y < __x); } |
829 | |
830 | /// unique_ptr comparison with nullptr |
831 | template<typename _Tp, typename _Dp> |
832 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
833 | operator<=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
834 | { return !(nullptr < __x); } |
835 | |
836 | /// unique_ptr comparison with nullptr |
837 | template<typename _Tp, typename _Dp> |
838 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
839 | operator<=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
840 | { return !(__x < nullptr); } |
841 | |
842 | /// Relational operator for unique_ptr objects, compares the owned pointers |
843 | template<typename _Tp, typename _Dp, |
844 | typename _Up, typename _Ep> |
845 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
846 | operator>(const unique_ptr<_Tp, _Dp>& __x, |
847 | const unique_ptr<_Up, _Ep>& __y) |
848 | { return (__y < __x); } |
849 | |
850 | /// unique_ptr comparison with nullptr |
851 | template<typename _Tp, typename _Dp> |
852 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
853 | operator>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
854 | { |
855 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr, |
856 | __x.get()); |
857 | } |
858 | |
859 | /// unique_ptr comparison with nullptr |
860 | template<typename _Tp, typename _Dp> |
861 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
862 | operator>(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
863 | { |
864 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(), |
865 | nullptr); |
866 | } |
867 | |
868 | /// Relational operator for unique_ptr objects, compares the owned pointers |
869 | template<typename _Tp, typename _Dp, |
870 | typename _Up, typename _Ep> |
871 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
872 | operator>=(const unique_ptr<_Tp, _Dp>& __x, |
873 | const unique_ptr<_Up, _Ep>& __y) |
874 | { return !(__x < __y); } |
875 | |
876 | /// unique_ptr comparison with nullptr |
877 | template<typename _Tp, typename _Dp> |
878 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
879 | operator>=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
880 | { return !(__x < nullptr); } |
881 | |
882 | /// unique_ptr comparison with nullptr |
883 | template<typename _Tp, typename _Dp> |
884 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
885 | operator>=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
886 | { return !(nullptr < __x); } |
887 | |
888 | #ifdef __cpp_lib_three_way_comparison |
889 | template<typename _Tp, typename _Dp, typename _Up, typename _Ep> |
890 | requires three_way_comparable_with<typename unique_ptr<_Tp, _Dp>::pointer, |
891 | typename unique_ptr<_Up, _Ep>::pointer> |
892 | inline |
893 | compare_three_way_result_t<typename unique_ptr<_Tp, _Dp>::pointer, |
894 | typename unique_ptr<_Up, _Ep>::pointer> |
895 | operator<=>(const unique_ptr<_Tp, _Dp>& __x, |
896 | const unique_ptr<_Up, _Ep>& __y) |
897 | { return compare_three_way()(__x.get(), __y.get()); } |
898 | |
899 | template<typename _Tp, typename _Dp> |
900 | requires three_way_comparable<typename unique_ptr<_Tp, _Dp>::pointer> |
901 | inline |
902 | compare_three_way_result_t<typename unique_ptr<_Tp, _Dp>::pointer> |
903 | operator<=>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
904 | { |
905 | using pointer = typename unique_ptr<_Tp, _Dp>::pointer; |
906 | return compare_three_way()(__x.get(), static_cast<pointer>(nullptr)); |
907 | } |
908 | #endif |
909 | // @} relates unique_ptr |
910 | |
911 | /// @cond undocumented |
912 | template<typename _Up, typename _Ptr = typename _Up::pointer, |
913 | bool = __poison_hash<_Ptr>::__enable_hash_call> |
914 | struct __uniq_ptr_hash |
915 | #if ! _GLIBCXX_INLINE_VERSION0 |
916 | : private __poison_hash<_Ptr> |
917 | #endif |
918 | { |
919 | size_t |
920 | operator()(const _Up& __u) const |
921 | noexcept(noexcept(std::declval<hash<_Ptr>>()(std::declval<_Ptr>()))) |
922 | { return hash<_Ptr>()(__u.get()); } |
923 | }; |
924 | |
925 | template<typename _Up, typename _Ptr> |
926 | struct __uniq_ptr_hash<_Up, _Ptr, false> |
927 | : private __poison_hash<_Ptr> |
928 | { }; |
929 | /// @endcond |
930 | |
931 | /// std::hash specialization for unique_ptr. |
932 | template<typename _Tp, typename _Dp> |
933 | struct hash<unique_ptr<_Tp, _Dp>> |
934 | : public __hash_base<size_t, unique_ptr<_Tp, _Dp>>, |
935 | public __uniq_ptr_hash<unique_ptr<_Tp, _Dp>> |
936 | { }; |
937 | |
938 | #if __cplusplus201703L >= 201402L |
939 | /// @relates unique_ptr @{ |
940 | #define __cpp_lib_make_unique201304 201304 |
941 | |
942 | /// @cond undocumented |
943 | |
944 | template<typename _Tp> |
945 | struct _MakeUniq |
946 | { typedef unique_ptr<_Tp> __single_object; }; |
947 | |
948 | template<typename _Tp> |
949 | struct _MakeUniq<_Tp[]> |
950 | { typedef unique_ptr<_Tp[]> __array; }; |
951 | |
952 | template<typename _Tp, size_t _Bound> |
953 | struct _MakeUniq<_Tp[_Bound]> |
954 | { struct __invalid_type { }; }; |
955 | |
956 | /// @endcond |
957 | |
958 | /// std::make_unique for single objects |
959 | template<typename _Tp, typename... _Args> |
960 | inline typename _MakeUniq<_Tp>::__single_object |
961 | make_unique(_Args&&... __args) |
962 | { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); } |
963 | |
964 | /// std::make_unique for arrays of unknown bound |
965 | template<typename _Tp> |
966 | inline typename _MakeUniq<_Tp>::__array |
967 | make_unique(size_t __num) |
968 | { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); } |
969 | |
970 | /// Disable std::make_unique for arrays of known bound |
971 | template<typename _Tp, typename... _Args> |
972 | inline typename _MakeUniq<_Tp>::__invalid_type |
973 | make_unique(_Args&&...) = delete; |
974 | // @} relates unique_ptr |
975 | #endif // C++14 |
976 | |
977 | #if __cplusplus201703L > 201703L && __cpp_concepts |
978 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
979 | // 2948. unique_ptr does not define operator<< for stream output |
980 | /// Stream output operator for unique_ptr |
981 | template<typename _CharT, typename _Traits, typename _Tp, typename _Dp> |
982 | inline basic_ostream<_CharT, _Traits>& |
983 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
984 | const unique_ptr<_Tp, _Dp>& __p) |
985 | requires requires { __os << __p.get(); } |
986 | { |
987 | __os << __p.get(); |
988 | return __os; |
989 | } |
990 | #endif // C++20 |
991 | |
992 | // @} group pointer_abstractions |
993 | |
994 | #if __cplusplus201703L >= 201703L |
995 | namespace __detail::__variant |
996 | { |
997 | template<typename> struct _Never_valueless_alt; // see <variant> |
998 | |
999 | // Provide the strong exception-safety guarantee when emplacing a |
1000 | // unique_ptr into a variant. |
1001 | template<typename _Tp, typename _Del> |
1002 | struct _Never_valueless_alt<std::unique_ptr<_Tp, _Del>> |
1003 | : std::true_type |
1004 | { }; |
1005 | } // namespace __detail::__variant |
1006 | #endif // C++17 |
1007 | |
1008 | _GLIBCXX_END_NAMESPACE_VERSION |
1009 | } // namespace |
1010 | |
1011 | #endif /* _UNIQUE_PTR_H */ |