/src/libreoffice/svx/source/tbxctrls/tbcontrl.cxx
Line | Count | Source (jump to first uncovered line) |
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 <utility> |
21 | | |
22 | | #include <comphelper/configurationlistener.hxx> |
23 | | #include <comphelper/propertysequence.hxx> |
24 | | #include <comphelper/propertyvalue.hxx> |
25 | | #include <tools/color.hxx> |
26 | | #include <svl/numformat.hxx> |
27 | | #include <svl/poolitem.hxx> |
28 | | #include <svl/itemset.hxx> |
29 | | #include <svl/itempool.hxx> |
30 | | #include <vcl/commandinfoprovider.hxx> |
31 | | #include <vcl/event.hxx> |
32 | | #include <vcl/toolbox.hxx> |
33 | | #include <vcl/customweld.hxx> |
34 | | #include <vcl/vclptr.hxx> |
35 | | #include <vcl/weldutils.hxx> |
36 | | #include <svtools/valueset.hxx> |
37 | | #include <svtools/ctrlbox.hxx> |
38 | | #include <svl/style.hxx> |
39 | | #include <svtools/ctrltool.hxx> |
40 | | #include <svtools/borderhelper.hxx> |
41 | | #include <vcl/InterimItemWindow.hxx> |
42 | | #include <sfx2/tbxctrl.hxx> |
43 | | #include <sfx2/tplpitem.hxx> |
44 | | #include <sfx2/sfxstatuslistener.hxx> |
45 | | #include <sfx2/viewsh.hxx> |
46 | | #include <toolkit/helper/vclunohelper.hxx> |
47 | | #include <sfx2/viewfrm.hxx> |
48 | | #include <vcl/svapp.hxx> |
49 | | #include <vcl/settings.hxx> |
50 | | #include <vcl/virdev.hxx> |
51 | | #include <com/sun/star/awt/FontDescriptor.hpp> |
52 | | #include <com/sun/star/table/BorderLine2.hpp> |
53 | | #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> |
54 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
55 | | #include <com/sun/star/beans/XPropertySet.hpp> |
56 | | #include <com/sun/star/util/XNumberFormatsSupplier.hpp> |
57 | | #include <com/sun/star/frame/XDispatchProvider.hpp> |
58 | | #include <com/sun/star/frame/XFrame.hpp> |
59 | | #include <svx/strings.hrc> |
60 | | #include <svx/svxids.hrc> |
61 | | #include <helpids.h> |
62 | | #include <sfx2/sidebar/Sidebar.hxx> |
63 | | #include <svx/xtable.hxx> |
64 | | #include <editeng/editids.hrc> |
65 | | #include <editeng/fontitem.hxx> |
66 | | #include <editeng/fhgtitem.hxx> |
67 | | #include <editeng/boxitem.hxx> |
68 | | #include <editeng/charreliefitem.hxx> |
69 | | #include <editeng/contouritem.hxx> |
70 | | #include <editeng/colritem.hxx> |
71 | | #include <editeng/crossedoutitem.hxx> |
72 | | #include <editeng/emphasismarkitem.hxx> |
73 | | #include <editeng/flstitem.hxx> |
74 | | #include <editeng/lineitem.hxx> |
75 | | #include <editeng/postitem.hxx> |
76 | | #include <editeng/shdditem.hxx> |
77 | | #include <editeng/udlnitem.hxx> |
78 | | #include <editeng/wghtitem.hxx> |
79 | | #include <editeng/svxfont.hxx> |
80 | | #include <editeng/cmapitem.hxx> |
81 | | #include <svx/colorwindow.hxx> |
82 | | #include <svx/colorbox.hxx> |
83 | | #include <svx/tbcontrl.hxx> |
84 | | #include <svx/dialmgr.hxx> |
85 | | #include <svx/PaletteManager.hxx> |
86 | | #include <memory> |
87 | | |
88 | | #include <tbxcolorupdate.hxx> |
89 | | #include <editeng/eerdll.hxx> |
90 | | #include <editeng/editrids.hrc> |
91 | | #include <svx/xdef.hxx> |
92 | | #include <svx/xfillit0.hxx> |
93 | | #include <svx/xflclit.hxx> |
94 | | #include <svl/currencytable.hxx> |
95 | | #include <svtools/langtab.hxx> |
96 | | #include <cppuhelper/supportsservice.hxx> |
97 | | #include <officecfg/Office/Common.hxx> |
98 | | #include <o3tl/temporary.hxx> |
99 | | #include <o3tl/safeint.hxx> |
100 | | #include <o3tl/string_view.hxx> |
101 | | #include <o3tl/typed_flags_set.hxx> |
102 | | #include <bitmaps.hlst> |
103 | | #include <sal/log.hxx> |
104 | | #include <unotools/collatorwrapper.hxx> |
105 | | #include <sfx2/IDocumentModelAccessor.hxx> |
106 | | |
107 | | #include <comphelper/lok.hxx> |
108 | | #include <tools/json_writer.hxx> |
109 | | |
110 | | #include <editeng/editeng.hxx> |
111 | | |
112 | 0 | #define MAX_MRU_FONTNAME_ENTRIES 5 |
113 | | |
114 | 0 | #define COMBO_WIDTH_IN_CHARS 18 |
115 | | |
116 | | // namespaces |
117 | | using namespace ::editeng; |
118 | | using namespace ::com::sun::star; |
119 | | using namespace ::com::sun::star::uno; |
120 | | using namespace ::com::sun::star::frame; |
121 | | using namespace ::com::sun::star::beans; |
122 | | using namespace ::com::sun::star::lang; |
123 | | |
124 | | namespace |
125 | | { |
126 | | struct ScriptInfo |
127 | | { |
128 | | tools::Long textWidth; |
129 | | SvtScriptType scriptType; |
130 | | sal_Int32 changePos; |
131 | | ScriptInfo(SvtScriptType scrptType, sal_Int32 position) |
132 | 0 | : textWidth(0) |
133 | 0 | , scriptType(scrptType) |
134 | 0 | , changePos(position) |
135 | 0 | { |
136 | 0 | } |
137 | | }; |
138 | | |
139 | | class SvxStyleBox_Base |
140 | | { |
141 | | public: |
142 | | SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget, OUString rCommand, SfxStyleFamily eFamily, |
143 | | const Reference<XFrame>& _xFrame, OUString aClearFormatKey, |
144 | | OUString aMoreKey, bool bInSpecialMode, SvxStyleToolBoxControl& rCtrl); |
145 | | |
146 | | virtual ~SvxStyleBox_Base() |
147 | 0 | { |
148 | 0 | } |
149 | | |
150 | | void SetFamily( SfxStyleFamily eNewFamily ); |
151 | | |
152 | 0 | void SetDefaultStyle( const OUString& rDefault ) { sDefaultStyle = rDefault; } |
153 | | |
154 | 0 | int get_count() const { return m_xWidget->get_count(); } |
155 | 0 | OUString get_text(int nIndex) const { return m_xWidget->get_text(nIndex); } |
156 | 0 | OUString get_active_text() const { return m_xWidget->get_active_text(); } |
157 | | |
158 | | void append_text(const OUString& rStr) |
159 | 0 | { |
160 | 0 | OUString sId(OUString::number(m_xWidget->get_count())); |
161 | 0 | m_xWidget->append(sId, rStr); |
162 | 0 | } |
163 | | |
164 | | void insert_separator(int pos, const OUString& rId) |
165 | 0 | { |
166 | 0 | m_xWidget->insert_separator(pos, rId); |
167 | 0 | } |
168 | | |
169 | | void set_active_or_entry_text(const OUString& rText) |
170 | 0 | { |
171 | 0 | const int nFound = m_xWidget->find_text(rText); |
172 | 0 | if (nFound != -1) |
173 | 0 | m_xWidget->set_active(nFound); |
174 | 0 | else |
175 | 0 | m_xWidget->set_entry_text(rText); |
176 | 0 | } |
177 | | |
178 | | int find_text(const OUString& rText) |
179 | 0 | { |
180 | 0 | return m_xWidget->find_text(rText); |
181 | 0 | } |
182 | | |
183 | | void set_active(int nActive) |
184 | 0 | { |
185 | 0 | m_xWidget->set_active(nActive); |
186 | 0 | } |
187 | | |
188 | | void freeze() |
189 | 0 | { |
190 | 0 | m_xWidget->freeze(); |
191 | 0 | } |
192 | | |
193 | | void save_value() |
194 | 0 | { |
195 | 0 | m_xWidget->save_value(); |
196 | 0 | } |
197 | | |
198 | | void clear() |
199 | 0 | { |
200 | 0 | m_xWidget->clear(); |
201 | 0 | m_nMaxUserDrawFontWidth = 0; |
202 | 0 | } |
203 | | |
204 | | void thaw() |
205 | 0 | { |
206 | 0 | m_xWidget->thaw(); |
207 | 0 | } |
208 | | |
209 | | virtual bool DoKeyInput(const KeyEvent& rKEvt); |
210 | | |
211 | | private: |
212 | | std::optional<SvxFont> m_oFont; |
213 | | std::optional<SvxFont> m_oCJKFont; |
214 | | std::optional<SvxFont> m_oCTLFont; |
215 | | |
216 | | DECL_LINK(SelectHdl, weld::ComboBox&, void); |
217 | | DECL_LINK(KeyInputHdl, const KeyEvent&, bool); |
218 | | DECL_LINK(ActivateHdl, weld::ComboBox&, bool); |
219 | | DECL_LINK(FocusOutHdl, weld::Widget&, void); |
220 | | DECL_LINK(DumpAsPropertyTreeHdl, tools::JsonWriter&, void); |
221 | | DECL_LINK(CustomRenderHdl, weld::ComboBox::render_args, void); |
222 | | DECL_LINK(CustomGetSizeHdl, OutputDevice&, Size); |
223 | | |
224 | | /// Calculate the optimal width of the dropdown. Very expensive operation, triggers lots of font measurement. |
225 | | void CalcOptimalExtraUserWidth(vcl::RenderContext& rRenderContext); |
226 | | |
227 | | void Select(bool bNonTravelSelect); |
228 | | |
229 | | tools::Rectangle CalcBoundRect(vcl::RenderContext& rRenderContext, const OUString &rStyleName, std::vector<ScriptInfo>& rScriptChanges, double fRatio = 1); |
230 | | |
231 | | protected: |
232 | | SvxStyleToolBoxControl& m_rCtrl; |
233 | | |
234 | | std::unique_ptr<weld::Builder> m_xMenuBuilder; |
235 | | std::unique_ptr<weld::Menu> m_xMenu; |
236 | | std::unique_ptr<weld::ComboBox> m_xWidget; |
237 | | |
238 | | SfxStyleFamily eStyleFamily; |
239 | | int m_nMaxUserDrawFontWidth; |
240 | | int m_nLastItemWithMenu; |
241 | | bool bRelease; |
242 | | Reference< XFrame > m_xFrame; |
243 | | OUString m_aCommand; |
244 | | OUString aClearFormatKey; |
245 | | OUString aMoreKey; |
246 | | OUString sDefaultStyle; |
247 | | bool bInSpecialMode; |
248 | | |
249 | | void ReleaseFocus(); |
250 | | static Color TestColorsVisible(const Color &FontCol, const Color &BackCol); |
251 | | void UserDrawEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const tools::Rectangle& rTextRect, const OUString &rStyleName, const std::vector<ScriptInfo>& rScriptChanges); |
252 | | void SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32 nItem, const tools::Rectangle& rRect, std::u16string_view rStyleName, bool bIsNotSelected); |
253 | | DECL_LINK(MenuSelectHdl, const OUString&, void); |
254 | | DECL_STATIC_LINK(SvxStyleBox_Base, ShowMoreHdl, void*, void); |
255 | | }; |
256 | | |
257 | | class SvxStyleBox_Impl final : public InterimItemWindow |
258 | | , public SvxStyleBox_Base |
259 | | { |
260 | | public: |
261 | | SvxStyleBox_Impl(vcl::Window* pParent, const OUString& rCommand, SfxStyleFamily eFamily, |
262 | | const Reference< XFrame >& _xFrame,const OUString& rClearFormatKey, const OUString& rMoreKey, bool bInSpecialMode, SvxStyleToolBoxControl& rCtrl); |
263 | | |
264 | | virtual ~SvxStyleBox_Impl() override |
265 | 0 | { |
266 | 0 | disposeOnce(); |
267 | 0 | } |
268 | | |
269 | | virtual void dispose() override |
270 | 0 | { |
271 | 0 | m_xWidget.reset(); |
272 | 0 | m_xMenu.reset(); |
273 | 0 | m_xMenuBuilder.reset(); |
274 | 0 | InterimItemWindow::dispose(); |
275 | 0 | } |
276 | | |
277 | | virtual bool DoKeyInput(const KeyEvent& rKEvt) override; |
278 | | |
279 | | private: |
280 | | |
281 | | virtual void DataChanged(const DataChangedEvent& rDCEvt) override; |
282 | | void SetOptimalSize(); |
283 | | }; |
284 | | |
285 | | class SvxFontNameBox_Impl; |
286 | | class SvxFontNameBox_Base; |
287 | | |
288 | | class SvxFontNameToolBoxControl final : public cppu::ImplInheritanceHelper<svt::ToolboxController, |
289 | | css::lang::XServiceInfo> |
290 | | { |
291 | | public: |
292 | | SvxFontNameToolBoxControl(); |
293 | | |
294 | | // XStatusListener |
295 | | virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; |
296 | | |
297 | | // XToolbarController |
298 | | virtual css::uno::Reference<css::awt::XWindow> SAL_CALL createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent) override; |
299 | | |
300 | | // XComponent |
301 | | virtual void SAL_CALL dispose() override; |
302 | | |
303 | | // XServiceInfo |
304 | | virtual OUString SAL_CALL getImplementationName() override; |
305 | | virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override; |
306 | | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
307 | | |
308 | | private: |
309 | | VclPtr<SvxFontNameBox_Impl> m_xVclBox; |
310 | | std::unique_ptr<SvxFontNameBox_Base> m_xWeldBox; |
311 | | SvxFontNameBox_Base* m_pBox; |
312 | | }; |
313 | | |
314 | | class FontOptionsListener final : public comphelper::ConfigurationListenerProperty<bool> |
315 | | { |
316 | | private: |
317 | | SvxFontNameBox_Base& m_rBox; |
318 | | |
319 | | virtual void setProperty(const css::uno::Any &rProperty) override; |
320 | | public: |
321 | | FontOptionsListener(const rtl::Reference<comphelper::ConfigurationListener>& rListener, const OUString& rProp, SvxFontNameBox_Base& rBox) |
322 | 0 | : comphelper::ConfigurationListenerProperty<bool>(rListener, rProp) |
323 | 0 | , m_rBox(rBox) |
324 | 0 | { |
325 | 0 | } |
326 | | }; |
327 | | |
328 | | class SvxFontNameBox_Base |
329 | | { |
330 | | private: |
331 | | rtl::Reference<comphelper::ConfigurationListener> m_xListener; |
332 | | FontOptionsListener m_aWYSIWYG; |
333 | | FontOptionsListener m_aHistory; |
334 | | |
335 | | protected: |
336 | | SvxFontNameToolBoxControl& m_rCtrl; |
337 | | |
338 | | std::unique_ptr<FontNameBox> m_xWidget; |
339 | | const FontList* pFontList; |
340 | | ::std::unique_ptr<FontList> m_aOwnFontList; |
341 | | vcl::Font aCurFont; |
342 | | sal_uInt16 nFtCount; |
343 | | bool bRelease; |
344 | | Reference< XFrame > m_xFrame; |
345 | | bool mbCheckingUnknownFont; |
346 | | bool mbDropDownActive; |
347 | | |
348 | | void ReleaseFocus_Impl(); |
349 | | |
350 | | void Select(bool bNonTravelSelect); |
351 | | |
352 | | void EndPreview() |
353 | 0 | { |
354 | 0 | Sequence< PropertyValue > aArgs; |
355 | 0 | const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY); |
356 | 0 | SfxToolBoxControl::Dispatch(xProvider, u".uno:CharEndPreviewFontName"_ustr, aArgs); |
357 | 0 | } |
358 | | |
359 | | bool CheckFontIsAvailable(std::u16string_view fontname); |
360 | | void CheckAndMarkUnknownFont(); |
361 | | |
362 | | public: |
363 | | SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget, const Reference<XFrame>& rFrame, |
364 | | SvxFontNameToolBoxControl& rCtrl); |
365 | | virtual ~SvxFontNameBox_Base() |
366 | 0 | { |
367 | 0 | m_xListener->dispose(); |
368 | 0 | } |
369 | | |
370 | | void FillList(); |
371 | | void Update( const css::awt::FontDescriptor* pFontDesc ); |
372 | 0 | sal_uInt16 GetListCount() const { return nFtCount; } |
373 | 0 | void Clear() { m_xWidget->clear(); nFtCount = 0; } |
374 | | void Fill( const FontList* pList ) |
375 | 0 | { |
376 | 0 | m_xWidget->Fill(pList); |
377 | 0 | nFtCount = pList->GetFontNameCount(); |
378 | 0 | } |
379 | | |
380 | 0 | void SetOwnFontList(::std::unique_ptr<FontList> && _aOwnFontList) { m_aOwnFontList = std::move(_aOwnFontList); } |
381 | | |
382 | | virtual void set_sensitive(bool bSensitive) |
383 | 0 | { |
384 | 0 | m_xWidget->set_sensitive(bSensitive); |
385 | 0 | } |
386 | | |
387 | | void set_active_or_entry_text(const OUString& rText); |
388 | | |
389 | | void statusChanged_Impl(const css::frame::FeatureStateEvent& rEvent); |
390 | | |
391 | | virtual bool DoKeyInput(const KeyEvent& rKEvt); |
392 | | |
393 | | void EnableControls(); |
394 | | |
395 | | DECL_LINK(SelectHdl, weld::ComboBox&, void); |
396 | | DECL_LINK(KeyInputHdl, const KeyEvent&, bool); |
397 | | DECL_LINK(ActivateHdl, weld::ComboBox&, bool); |
398 | | DECL_LINK(FocusInHdl, weld::Widget&, void); |
399 | | DECL_LINK(FocusOutHdl, weld::Widget&, void); |
400 | | DECL_LINK(PopupToggledHdl, weld::ComboBox&, void); |
401 | | DECL_LINK(LivePreviewHdl, const FontMetric&, void); |
402 | | DECL_LINK(DumpAsPropertyTreeHdl, tools::JsonWriter&, void); |
403 | | }; |
404 | | |
405 | | void FontOptionsListener::setProperty(const css::uno::Any &rProperty) |
406 | 0 | { |
407 | 0 | comphelper::ConfigurationListenerProperty<bool>::setProperty(rProperty); |
408 | 0 | m_rBox.EnableControls(); |
409 | 0 | } |
410 | | |
411 | | class SvxFontNameBox_Impl final : public InterimItemWindow |
412 | | , public SvxFontNameBox_Base |
413 | | { |
414 | | private: |
415 | | virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; |
416 | | virtual void GetFocus() override |
417 | 0 | { |
418 | 0 | if (m_xWidget) |
419 | 0 | m_xWidget->grab_focus(); |
420 | 0 | InterimItemWindow::GetFocus(); |
421 | 0 | } |
422 | | |
423 | | void SetOptimalSize(); |
424 | | |
425 | | virtual bool DoKeyInput(const KeyEvent& rKEvt) override; |
426 | | |
427 | | public: |
428 | | SvxFontNameBox_Impl(vcl::Window* pParent, |
429 | | const Reference<XFrame>& rFrame, SvxFontNameToolBoxControl& rCtrl); |
430 | | |
431 | | virtual void dispose() override |
432 | 0 | { |
433 | 0 | m_xWidget.reset(); |
434 | 0 | InterimItemWindow::dispose(); |
435 | 0 | } |
436 | | |
437 | | virtual ~SvxFontNameBox_Impl() override |
438 | 0 | { |
439 | 0 | disposeOnce(); |
440 | 0 | } |
441 | | |
442 | | virtual Reference< css::accessibility::XAccessible > CreateAccessible() override; |
443 | | |
444 | | virtual void StateChanged(StateChangedType nStateChange) override |
445 | 0 | { |
446 | 0 | if (nStateChange == StateChangedType::Enable) |
447 | 0 | m_xWidget->set_sensitive(IsEnabled()); |
448 | 0 | InterimItemWindow::StateChanged(nStateChange); |
449 | 0 | } |
450 | | |
451 | | virtual void set_sensitive(bool bSensitive) override |
452 | 0 | { |
453 | 0 | m_xWidget->set_sensitive(bSensitive); |
454 | 0 | if (bSensitive) |
455 | 0 | InterimItemWindow::Enable(); |
456 | 0 | else |
457 | 0 | InterimItemWindow::Disable(); |
458 | 0 | } |
459 | | }; |
460 | | |
461 | | |
462 | | // SelectHdl needs the Modifiers, get them in MouseButtonUp |
463 | | class SvxFrmValueSet_Impl final : public ValueSet |
464 | | { |
465 | | private: |
466 | | sal_uInt16 nModifier; |
467 | | |
468 | | virtual bool MouseButtonUp(const MouseEvent& rMEvt) override |
469 | 0 | { |
470 | 0 | nModifier = rMEvt.GetModifier(); |
471 | 0 | return ValueSet::MouseButtonUp(rMEvt); |
472 | 0 | } |
473 | | |
474 | | public: |
475 | | SvxFrmValueSet_Impl() |
476 | 0 | : ValueSet(nullptr) |
477 | 0 | , nModifier(0) |
478 | 0 | { |
479 | 0 | } |
480 | 0 | sal_uInt16 GetModifier() const {return nModifier;} |
481 | | }; |
482 | | |
483 | | } |
484 | | |
485 | | namespace { |
486 | | |
487 | | class SvxFrameToolBoxControl; |
488 | | |
489 | | class SvxFrameWindow_Impl final : public WeldToolbarPopup |
490 | | { |
491 | | private: |
492 | | rtl::Reference<SvxFrameToolBoxControl> mxControl; |
493 | | std::unique_ptr<SvxFrmValueSet_Impl> mxFrameSet; |
494 | | std::unique_ptr<weld::CustomWeld> mxFrameSetWin; |
495 | | std::vector<std::pair<BitmapEx, OUString>> aImgVec; |
496 | | bool bParagraphMode; |
497 | | bool m_bIsWriter; |
498 | | bool m_bIsCalc; |
499 | | |
500 | | void InitImageList(); |
501 | | void CalcSizeValueSet(); |
502 | | DECL_LINK( SelectHdl, ValueSet*, void ); |
503 | | |
504 | | void SetDiagonalDownBorder(const SvxLineItem& dDownLineItem); |
505 | | void SetDiagonalUpBorder(const SvxLineItem& dUpLineItem); |
506 | | |
507 | | public: |
508 | | SvxFrameWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent); |
509 | | virtual void GrabFocus() override |
510 | 0 | { |
511 | 0 | mxFrameSet->GrabFocus(); |
512 | 0 | } |
513 | | |
514 | | virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; |
515 | | }; |
516 | | |
517 | | class SvxFrameToolBoxControl : public svt::PopupWindowController |
518 | | { |
519 | | public: |
520 | | explicit SvxFrameToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rContext ); |
521 | | |
522 | | // XInitialization |
523 | | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) override; |
524 | | |
525 | | // XServiceInfo |
526 | | virtual OUString SAL_CALL getImplementationName() override; |
527 | | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
528 | | |
529 | | virtual void SAL_CALL execute(sal_Int16 nKeyModifier) override; |
530 | | private: |
531 | | virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override; |
532 | | virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override; |
533 | | }; |
534 | | |
535 | | class LineListBox final : public ValueSet |
536 | | { |
537 | | public: |
538 | | typedef Color (*ColorFunc)(Color); |
539 | | typedef Color (*ColorDistFunc)(Color, Color); |
540 | | |
541 | | LineListBox(); |
542 | | |
543 | | /** Set the width in Twips */ |
544 | | Size SetWidth( tools::Long nWidth ) |
545 | 0 | { |
546 | 0 | tools::Long nOldWidth = m_nWidth; |
547 | 0 | m_nWidth = nWidth; |
548 | 0 | return UpdateEntries( nOldWidth ); |
549 | 0 | } |
550 | | |
551 | | void SetNone( const OUString& sNone ) |
552 | 0 | { |
553 | 0 | m_sNone = sNone; |
554 | 0 | } |
555 | | |
556 | | /** Insert a listbox entry with all widths in Twips. */ |
557 | | void InsertEntry(const BorderWidthImpl& rWidthImpl, |
558 | | SvxBorderLineStyle nStyle, tools::Long nMinWidth = 0, |
559 | | ColorFunc pColor1Fn = &sameColor, |
560 | | ColorFunc pColor2Fn = &sameColor, |
561 | | ColorDistFunc pColorDistFn = &sameDistColor); |
562 | | |
563 | | SvxBorderLineStyle GetEntryStyle( sal_Int32 nPos ) const; |
564 | | |
565 | | SvxBorderLineStyle GetSelectEntryStyle() const; |
566 | | |
567 | 0 | void SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; } |
568 | | |
569 | 0 | const Color& GetColor() const { return aColor; } |
570 | | |
571 | | virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override; |
572 | | private: |
573 | | |
574 | | void ImpGetLine(tools::Long nLine1, tools::Long nLine2, tools::Long nDistance, |
575 | | Color nColor1, Color nColor2, Color nColorDist, |
576 | | SvxBorderLineStyle nStyle, BitmapEx& rBmp); |
577 | | |
578 | | void UpdatePaintLineColor(); // returns sal_True if maPaintCol has changed |
579 | | |
580 | | Size UpdateEntries( tools::Long nOldWidth ); |
581 | | sal_Int32 GetStylePos( sal_Int32 nListPos, tools::Long nWidth ); |
582 | | |
583 | | const Color& GetPaintColor() const |
584 | 0 | { |
585 | 0 | return maPaintCol; |
586 | 0 | } |
587 | | |
588 | | Color GetColorLine1( sal_Int32 nPos ); |
589 | | Color GetColorLine2( sal_Int32 nPos ); |
590 | | Color GetColorDist( sal_Int32 nPos ); |
591 | | |
592 | | LineListBox( const LineListBox& ) = delete; |
593 | | LineListBox& operator =( const LineListBox& ) = delete; |
594 | | |
595 | | std::vector<std::unique_ptr<ImpLineListData>> m_vLineList; |
596 | | tools::Long m_nWidth; |
597 | | OUString m_sNone; |
598 | | ScopedVclPtr<VirtualDevice> aVirDev; |
599 | | Size aTxtSize; |
600 | | Color const aColor; |
601 | | Color maPaintCol; |
602 | | FieldUnit eSourceUnit; |
603 | | }; |
604 | | |
605 | | SvxBorderLineStyle LineListBox::GetSelectEntryStyle() const |
606 | 0 | { |
607 | 0 | SvxBorderLineStyle nStyle = SvxBorderLineStyle::SOLID; |
608 | 0 | size_t nPos = GetSelectItemPos(); |
609 | 0 | if (nPos != VALUESET_ITEM_NOTFOUND) |
610 | 0 | { |
611 | 0 | if (!m_sNone.isEmpty()) |
612 | 0 | --nPos; |
613 | 0 | nStyle = GetEntryStyle( nPos ); |
614 | 0 | } |
615 | |
|
616 | 0 | return nStyle; |
617 | 0 | } |
618 | | |
619 | | void LineListBox::ImpGetLine( tools::Long nLine1, tools::Long nLine2, tools::Long nDistance, |
620 | | Color aColor1, Color aColor2, Color aColorDist, |
621 | | SvxBorderLineStyle nStyle, BitmapEx& rBmp ) |
622 | 0 | { |
623 | 0 | auto nMinWidth = GetDrawingArea()->get_ref_device().approximate_digit_width() * COMBO_WIDTH_IN_CHARS; |
624 | 0 | Size aSize(nMinWidth, aTxtSize.Height()); |
625 | 0 | aSize.AdjustWidth( -(aTxtSize.Width()) ); |
626 | 0 | aSize.AdjustWidth( -6 ); |
627 | | |
628 | | // SourceUnit to Twips |
629 | 0 | if ( eSourceUnit == FieldUnit::POINT ) |
630 | 0 | { |
631 | 0 | nLine1 /= 5; |
632 | 0 | nLine2 /= 5; |
633 | 0 | nDistance /= 5; |
634 | 0 | } |
635 | | |
636 | | // Paint the lines |
637 | 0 | aSize = aVirDev->PixelToLogic( aSize ); |
638 | 0 | tools::Long nPix = aVirDev->PixelToLogic( Size( 0, 1 ) ).Height(); |
639 | 0 | sal_uInt32 n1 = nLine1; |
640 | 0 | sal_uInt32 n2 = nLine2; |
641 | 0 | tools::Long nDist = nDistance; |
642 | 0 | n1 += nPix-1; |
643 | 0 | n1 -= n1%nPix; |
644 | 0 | if ( n2 ) |
645 | 0 | { |
646 | 0 | nDist += nPix-1; |
647 | 0 | nDist -= nDist%nPix; |
648 | 0 | n2 += nPix-1; |
649 | 0 | n2 -= n2%nPix; |
650 | 0 | } |
651 | 0 | tools::Long nVirHeight = n1+nDist+n2; |
652 | 0 | if ( nVirHeight > aSize.Height() ) |
653 | 0 | aSize.setHeight( nVirHeight ); |
654 | | // negative width should not be drawn |
655 | 0 | if ( aSize.Width() <= 0 ) |
656 | 0 | return; |
657 | | |
658 | 0 | Size aVirSize = aVirDev->LogicToPixel( aSize ); |
659 | 0 | if ( aVirDev->GetOutputSizePixel() != aVirSize ) |
660 | 0 | aVirDev->SetOutputSizePixel( aVirSize ); |
661 | 0 | aVirDev->SetFillColor( aColorDist ); |
662 | 0 | aVirDev->DrawRect( tools::Rectangle( Point(), aSize ) ); |
663 | |
|
664 | 0 | aVirDev->SetFillColor( aColor1 ); |
665 | |
|
666 | 0 | double y1 = double( n1 ) / 2; |
667 | 0 | svtools::DrawLine( *aVirDev, basegfx::B2DPoint( 0, y1 ), basegfx::B2DPoint( aSize.Width( ), y1 ), n1, nStyle ); |
668 | |
|
669 | 0 | if ( n2 ) |
670 | 0 | { |
671 | 0 | double y2 = n1 + nDist + double( n2 ) / 2; |
672 | 0 | aVirDev->SetFillColor( aColor2 ); |
673 | 0 | svtools::DrawLine( *aVirDev, basegfx::B2DPoint( 0, y2 ), basegfx::B2DPoint( aSize.Width(), y2 ), n2, SvxBorderLineStyle::SOLID ); |
674 | 0 | } |
675 | 0 | rBmp = aVirDev->GetBitmapEx( Point(), Size( aSize.Width(), n1+nDist+n2 ) ); |
676 | 0 | } |
677 | | |
678 | | LineListBox::LineListBox() |
679 | 0 | : ValueSet(nullptr) |
680 | 0 | , m_nWidth( 5 ) |
681 | 0 | , aVirDev(VclPtr<VirtualDevice>::Create()) |
682 | 0 | , aColor(Application::GetSettings().GetStyleSettings().GetWindowTextColor()) |
683 | 0 | , maPaintCol(COL_BLACK) |
684 | 0 | , eSourceUnit(FieldUnit::POINT) |
685 | 0 | { |
686 | 0 | aVirDev->SetLineColor(); |
687 | 0 | aVirDev->SetMapMode( MapMode( MapUnit::MapTwip ) ); |
688 | 0 | } |
689 | | |
690 | | void LineListBox::SetDrawingArea(weld::DrawingArea* pDrawingArea) |
691 | 0 | { |
692 | 0 | ValueSet::SetDrawingArea(pDrawingArea); |
693 | |
|
694 | 0 | OutputDevice& rDevice = pDrawingArea->get_ref_device(); |
695 | |
|
696 | 0 | aTxtSize.setWidth( rDevice.approximate_digit_width() ); |
697 | 0 | aTxtSize.setHeight( rDevice.GetTextHeight() ); |
698 | |
|
699 | 0 | UpdatePaintLineColor(); |
700 | 0 | } |
701 | | |
702 | | sal_Int32 LineListBox::GetStylePos( sal_Int32 nListPos, tools::Long nWidth ) |
703 | 0 | { |
704 | 0 | sal_Int32 nPos = -1; |
705 | 0 | if (!m_sNone.isEmpty()) |
706 | 0 | nListPos--; |
707 | |
|
708 | 0 | sal_Int32 n = 0; |
709 | 0 | size_t i = 0; |
710 | 0 | size_t nCount = m_vLineList.size(); |
711 | 0 | while ( nPos == -1 && i < nCount ) |
712 | 0 | { |
713 | 0 | auto& pData = m_vLineList[ i ]; |
714 | 0 | if ( pData->GetMinWidth() <= nWidth ) |
715 | 0 | { |
716 | 0 | if ( nListPos == n ) |
717 | 0 | nPos = static_cast<sal_Int32>(i); |
718 | 0 | n++; |
719 | 0 | } |
720 | 0 | i++; |
721 | 0 | } |
722 | |
|
723 | 0 | return nPos; |
724 | 0 | } |
725 | | |
726 | | void LineListBox::InsertEntry( |
727 | | const BorderWidthImpl& rWidthImpl, SvxBorderLineStyle nStyle, tools::Long nMinWidth, |
728 | | ColorFunc pColor1Fn, ColorFunc pColor2Fn, ColorDistFunc pColorDistFn ) |
729 | 0 | { |
730 | 0 | m_vLineList.emplace_back(new ImpLineListData( |
731 | 0 | rWidthImpl, nStyle, nMinWidth, pColor1Fn, pColor2Fn, pColorDistFn)); |
732 | 0 | } |
733 | | |
734 | | SvxBorderLineStyle LineListBox::GetEntryStyle( sal_Int32 nPos ) const |
735 | 0 | { |
736 | 0 | ImpLineListData* pData = (0 <= nPos && o3tl::make_unsigned(nPos) < m_vLineList.size()) ? m_vLineList[ nPos ].get() : nullptr; |
737 | 0 | return pData ? pData->GetStyle() : SvxBorderLineStyle::NONE; |
738 | 0 | } |
739 | | |
740 | | void LineListBox::UpdatePaintLineColor() |
741 | 0 | { |
742 | 0 | const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); |
743 | 0 | Color aNewCol( rSettings.GetWindowColor().IsDark()? rSettings.GetLabelTextColor() : aColor ); |
744 | |
|
745 | 0 | bool bRet = aNewCol != maPaintCol; |
746 | |
|
747 | 0 | if( bRet ) |
748 | 0 | maPaintCol = aNewCol; |
749 | 0 | } |
750 | | |
751 | | Size LineListBox::UpdateEntries( tools::Long nOldWidth ) |
752 | 0 | { |
753 | 0 | Size aSize; |
754 | |
|
755 | 0 | UpdatePaintLineColor( ); |
756 | |
|
757 | 0 | sal_Int32 nSelEntry = GetSelectItemPos(); |
758 | 0 | sal_Int32 nTypePos = GetStylePos( nSelEntry, nOldWidth ); |
759 | | |
760 | | // Remove the old entries |
761 | 0 | Clear(); |
762 | |
|
763 | 0 | sal_uInt16 nId(1); |
764 | | |
765 | | // Add the new entries based on the defined width |
766 | 0 | if (!m_sNone.isEmpty()) |
767 | 0 | InsertItem(nId++, Image(), m_sNone); |
768 | |
|
769 | 0 | sal_uInt16 n = 0; |
770 | 0 | sal_uInt16 nCount = m_vLineList.size( ); |
771 | 0 | while ( n < nCount ) |
772 | 0 | { |
773 | 0 | auto& pData = m_vLineList[ n ]; |
774 | 0 | if ( pData->GetMinWidth() <= m_nWidth ) |
775 | 0 | { |
776 | 0 | BitmapEx aBmp; |
777 | 0 | ImpGetLine( pData->GetLine1ForWidth( m_nWidth ), |
778 | 0 | pData->GetLine2ForWidth( m_nWidth ), |
779 | 0 | pData->GetDistForWidth( m_nWidth ), |
780 | 0 | GetColorLine1( GetItemCount( ) ), |
781 | 0 | GetColorLine2( GetItemCount( ) ), |
782 | 0 | GetColorDist( GetItemCount( ) ), |
783 | 0 | pData->GetStyle(), aBmp ); |
784 | 0 | InsertItem(nId, Image(aBmp), SvtLineListBox::GetLineStyleName(pData->GetStyle())); |
785 | 0 | Size aBmpSize = aBmp.GetSizePixel(); |
786 | 0 | if (aBmpSize.Width() > aSize.Width()) |
787 | 0 | aSize.setWidth(aBmpSize.getWidth()); |
788 | 0 | if (aBmpSize.Height() > aSize.Height()) |
789 | 0 | aSize.setHeight(aBmpSize.getHeight()); |
790 | 0 | if ( n == nTypePos ) |
791 | 0 | SelectItem(nId); |
792 | 0 | } |
793 | 0 | else if ( n == nTypePos ) |
794 | 0 | SetNoSelection(); |
795 | 0 | n++; |
796 | 0 | ++nId; |
797 | 0 | } |
798 | |
|
799 | 0 | Invalidate(); |
800 | |
|
801 | 0 | return aSize; |
802 | 0 | } |
803 | | |
804 | | Color LineListBox::GetColorLine1( sal_Int32 nPos ) |
805 | 0 | { |
806 | 0 | sal_Int32 nStyle = GetStylePos( nPos, m_nWidth ); |
807 | 0 | if (nStyle == -1) |
808 | 0 | return GetPaintColor( ); |
809 | 0 | auto& pData = m_vLineList[ nStyle ]; |
810 | 0 | return pData->GetColorLine1( GetColor( ) ); |
811 | 0 | } |
812 | | |
813 | | Color LineListBox::GetColorLine2( sal_Int32 nPos ) |
814 | 0 | { |
815 | 0 | sal_Int32 nStyle = GetStylePos( nPos, m_nWidth ); |
816 | 0 | if (nStyle == -1) |
817 | 0 | return GetPaintColor( ); |
818 | 0 | auto& pData = m_vLineList[ nStyle ]; |
819 | 0 | return pData->GetColorLine2( GetColor( ) ); |
820 | 0 | } |
821 | | |
822 | | Color LineListBox::GetColorDist( sal_Int32 nPos ) |
823 | 0 | { |
824 | 0 | Color rResult = Application::GetSettings().GetStyleSettings().GetFieldColor(); |
825 | |
|
826 | 0 | sal_Int32 nStyle = GetStylePos( nPos, m_nWidth ); |
827 | 0 | if (nStyle == -1) |
828 | 0 | return rResult; |
829 | 0 | auto& pData = m_vLineList[ nStyle ]; |
830 | 0 | return pData->GetColorDist( GetColor( ), rResult ); |
831 | 0 | } |
832 | | } |
833 | | |
834 | | namespace { |
835 | | |
836 | | class SvxLineWindow_Impl final : public WeldToolbarPopup |
837 | | { |
838 | | private: |
839 | | rtl::Reference<SvxFrameToolBoxControl> m_xControl; |
840 | | std::unique_ptr<LineListBox> m_xLineStyleLb; |
841 | | std::unique_ptr<weld::CustomWeld> m_xLineStyleLbWin; |
842 | | bool m_bIsWriter; |
843 | | |
844 | | DECL_LINK( SelectHdl, ValueSet*, void ); |
845 | | |
846 | | public: |
847 | | SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent); |
848 | | virtual void GrabFocus() override |
849 | 0 | { |
850 | 0 | m_xLineStyleLb->GrabFocus(); |
851 | 0 | } |
852 | | }; |
853 | | |
854 | | } |
855 | | |
856 | | class SvxStyleToolBoxControl; |
857 | | |
858 | | class SfxStyleControllerItem_Impl : public SfxStatusListener |
859 | | { |
860 | | public: |
861 | | SfxStyleControllerItem_Impl( const Reference< XDispatchProvider >& rDispatchProvider, |
862 | | sal_uInt16 nSlotId, |
863 | | const OUString& rCommand, |
864 | | SvxStyleToolBoxControl& rTbxCtl ); |
865 | | |
866 | | protected: |
867 | | virtual void StateChangedAtStatusListener( SfxItemState eState, const SfxPoolItem* pState ) override; |
868 | | |
869 | | private: |
870 | | SvxStyleToolBoxControl& rControl; |
871 | | }; |
872 | | |
873 | 0 | #define BUTTON_PADDING 10 |
874 | 0 | #define ITEM_HEIGHT 30 |
875 | | |
876 | | SvxStyleBox_Base::SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget, |
877 | | OUString aCommand, |
878 | | SfxStyleFamily eFamily, |
879 | | const Reference< XFrame >& _xFrame, |
880 | | OUString _aClearFormatKey, |
881 | | OUString _aMoreKey, |
882 | | bool bInSpec, SvxStyleToolBoxControl& rCtrl) |
883 | 0 | : m_rCtrl(rCtrl) |
884 | 0 | , m_xMenuBuilder(Application::CreateBuilder(nullptr, u"svx/ui/stylemenu.ui"_ustr)) |
885 | 0 | , m_xMenu(m_xMenuBuilder->weld_menu(u"menu"_ustr)) |
886 | 0 | , m_xWidget(std::move(xWidget)) |
887 | 0 | , eStyleFamily( eFamily ) |
888 | 0 | , m_nMaxUserDrawFontWidth(0) |
889 | 0 | , m_nLastItemWithMenu(-1) |
890 | 0 | , bRelease( true ) |
891 | 0 | , m_xFrame(_xFrame) |
892 | 0 | , m_aCommand(std::move( aCommand )) |
893 | 0 | , aClearFormatKey(std::move( _aClearFormatKey )) |
894 | 0 | , aMoreKey(std::move( _aMoreKey )) |
895 | 0 | , bInSpecialMode( bInSpec ) |
896 | 0 | { |
897 | 0 | m_xWidget->connect_changed(LINK(this, SvxStyleBox_Base, SelectHdl)); |
898 | 0 | m_xWidget->connect_key_press(LINK(this, SvxStyleBox_Base, KeyInputHdl)); |
899 | 0 | m_xWidget->connect_entry_activate(LINK(this, SvxStyleBox_Base, ActivateHdl)); |
900 | 0 | m_xWidget->connect_focus_out(LINK(this, SvxStyleBox_Base, FocusOutHdl)); |
901 | 0 | m_xWidget->connect_get_property_tree(LINK(this, SvxStyleBox_Base, DumpAsPropertyTreeHdl)); |
902 | 0 | m_xWidget->set_help_id(HID_STYLE_LISTBOX); |
903 | 0 | m_xWidget->set_entry_completion(true); |
904 | 0 | m_xMenu->connect_activate(LINK(this, SvxStyleBox_Base, MenuSelectHdl)); |
905 | |
|
906 | 0 | m_xWidget->connect_custom_get_size(LINK(this, SvxStyleBox_Base, CustomGetSizeHdl)); |
907 | 0 | m_xWidget->connect_custom_render(LINK(this, SvxStyleBox_Base, CustomRenderHdl)); |
908 | 0 | m_xWidget->set_custom_renderer(true); |
909 | |
|
910 | 0 | m_xWidget->set_entry_width_chars(COMBO_WIDTH_IN_CHARS + 3); |
911 | 0 | } |
912 | | |
913 | | IMPL_LINK(SvxStyleBox_Base, CustomGetSizeHdl, OutputDevice&, rArg, Size) |
914 | 0 | { |
915 | 0 | CalcOptimalExtraUserWidth(rArg); |
916 | 0 | if (comphelper::LibreOfficeKit::isActive()) |
917 | 0 | return Size(m_nMaxUserDrawFontWidth * rArg.GetDPIX() / 96, ITEM_HEIGHT * rArg.GetDPIY() / 96); |
918 | 0 | return Size(m_nMaxUserDrawFontWidth, ITEM_HEIGHT); |
919 | 0 | } |
920 | | |
921 | | SvxStyleBox_Impl::SvxStyleBox_Impl(vcl::Window* pParent, |
922 | | const OUString& rCommand, |
923 | | SfxStyleFamily eFamily, |
924 | | const Reference< XFrame >& _xFrame, |
925 | | const OUString& rClearFormatKey, |
926 | | const OUString& rMoreKey, |
927 | | bool bInSpec, SvxStyleToolBoxControl& rCtrl) |
928 | 0 | : InterimItemWindow(pParent, u"svx/ui/applystylebox.ui"_ustr, u"ApplyStyleBox"_ustr) |
929 | 0 | , SvxStyleBox_Base(m_xBuilder->weld_combo_box(u"applystyle"_ustr), rCommand, eFamily, _xFrame, |
930 | 0 | rClearFormatKey, rMoreKey, bInSpec, rCtrl) |
931 | 0 | { |
932 | 0 | InitControlBase(m_xWidget.get()); |
933 | |
|
934 | 0 | set_id(u"applystyle"_ustr); |
935 | 0 | SetOptimalSize(); |
936 | 0 | } |
937 | | |
938 | | void SvxStyleBox_Base::ReleaseFocus() |
939 | 0 | { |
940 | 0 | if ( !bRelease ) |
941 | 0 | { |
942 | 0 | bRelease = true; |
943 | 0 | return; |
944 | 0 | } |
945 | 0 | if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() ) |
946 | 0 | m_xFrame->getContainerWindow()->setFocus(); |
947 | 0 | } |
948 | | |
949 | | IMPL_LINK(SvxStyleBox_Base, MenuSelectHdl, const OUString&, rMenuIdent, void) |
950 | 0 | { |
951 | 0 | if (m_nLastItemWithMenu < 0 || m_nLastItemWithMenu >= m_xWidget->get_count()) |
952 | 0 | return; |
953 | | |
954 | 0 | OUString sEntry = m_xWidget->get_text(m_nLastItemWithMenu); |
955 | |
|
956 | 0 | ReleaseFocus(); // It must be after getting entry pos! |
957 | 0 | Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue(u"Param"_ustr, sEntry), |
958 | 0 | comphelper::makePropertyValue(u"Family"_ustr, |
959 | 0 | sal_Int16( eStyleFamily )) }; |
960 | |
|
961 | 0 | const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY); |
962 | 0 | if (rMenuIdent == "update") |
963 | 0 | { |
964 | 0 | SfxToolBoxControl::Dispatch(xProvider, u".uno:StyleUpdateByExample"_ustr, aArgs); |
965 | 0 | } |
966 | 0 | else if (rMenuIdent == "edit") |
967 | 0 | { |
968 | 0 | SfxToolBoxControl::Dispatch(xProvider, u".uno:EditStyle"_ustr, aArgs); |
969 | 0 | } |
970 | 0 | } |
971 | | |
972 | | IMPL_STATIC_LINK_NOARG(SvxStyleBox_Base, ShowMoreHdl, void*, void) |
973 | 0 | { |
974 | 0 | SfxViewFrame* pViewFrm = SfxViewFrame::Current(); |
975 | 0 | DBG_ASSERT( pViewFrm, "SvxStyleBox_Base::Select(): no viewframe" ); |
976 | 0 | if (!pViewFrm) |
977 | 0 | return; |
978 | 0 | pViewFrm->ShowChildWindow(SID_SIDEBAR); |
979 | 0 | ::sfx2::sidebar::Sidebar::ShowPanel(u"StyleListPanel", pViewFrm->GetFrame().GetFrameInterface(), true); |
980 | 0 | } |
981 | | |
982 | | IMPL_LINK(SvxStyleBox_Base, SelectHdl, weld::ComboBox&, rCombo, void) |
983 | 0 | { |
984 | 0 | Select(rCombo.changed_by_direct_pick()); // only when picked from the list |
985 | 0 | } |
986 | | |
987 | | IMPL_LINK_NOARG(SvxStyleBox_Base, ActivateHdl, weld::ComboBox&, bool) |
988 | 0 | { |
989 | 0 | Select(true); |
990 | 0 | return true; |
991 | 0 | } |
992 | | |
993 | | void SvxStyleBox_Base::Select(bool bNonTravelSelect) |
994 | 0 | { |
995 | 0 | if (!bNonTravelSelect) |
996 | 0 | return; |
997 | | |
998 | 0 | OUString aSearchEntry(m_xWidget->get_active_text()); |
999 | 0 | bool bDoIt = true, bClear = false; |
1000 | 0 | if( bInSpecialMode ) |
1001 | 0 | { |
1002 | 0 | if( aSearchEntry == aClearFormatKey && m_xWidget->get_active() == 0 ) |
1003 | 0 | { |
1004 | 0 | aSearchEntry = sDefaultStyle; |
1005 | 0 | bClear = true; |
1006 | | //not only apply default style but also call 'ClearFormatting' |
1007 | 0 | Sequence< PropertyValue > aEmptyVals; |
1008 | 0 | const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY); |
1009 | 0 | SfxToolBoxControl::Dispatch(xProvider, u".uno:ResetAttributes"_ustr, aEmptyVals); |
1010 | 0 | } |
1011 | 0 | else if (aSearchEntry == aMoreKey && m_xWidget->get_active() == (m_xWidget->get_count() - 1)) |
1012 | 0 | { |
1013 | 0 | Application::PostUserEvent(LINK(nullptr, SvxStyleBox_Base, ShowMoreHdl)); |
1014 | | //tdf#113214 change text back to previous entry |
1015 | 0 | set_active_or_entry_text(m_xWidget->get_saved_value()); |
1016 | 0 | bDoIt = false; |
1017 | 0 | } |
1018 | 0 | } |
1019 | | |
1020 | | //Do we need to create a new style? |
1021 | 0 | SfxObjectShell *pShell = SfxObjectShell::Current(); |
1022 | 0 | if (!pShell) |
1023 | 0 | return; |
1024 | | |
1025 | 0 | SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool(); |
1026 | 0 | SfxStyleSheetBase* pStyle = nullptr; |
1027 | |
|
1028 | 0 | bool bCreateNew = false; |
1029 | |
|
1030 | 0 | if ( pPool ) |
1031 | 0 | { |
1032 | 0 | pStyle = pPool->First(eStyleFamily); |
1033 | 0 | while ( pStyle && pStyle->GetName() != aSearchEntry ) |
1034 | 0 | pStyle = pPool->Next(); |
1035 | 0 | } |
1036 | |
|
1037 | 0 | if ( !pStyle ) |
1038 | 0 | { |
1039 | | // cannot find the style for whatever reason |
1040 | | // therefore create a new style |
1041 | 0 | bCreateNew = true; |
1042 | 0 | } |
1043 | | |
1044 | | /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call. |
1045 | | This instance may be deleted in the meantime (i.e. when a dialog is opened |
1046 | | while in Dispatch()), accessing members will crash in this case. */ |
1047 | 0 | ReleaseFocus(); |
1048 | |
|
1049 | 0 | if( !bDoIt ) |
1050 | 0 | return; |
1051 | | |
1052 | 0 | if ( bClear ) |
1053 | 0 | set_active_or_entry_text(aSearchEntry); |
1054 | 0 | m_xWidget->save_value(); |
1055 | |
|
1056 | 0 | Sequence< PropertyValue > aArgs( 2 ); |
1057 | 0 | auto pArgs = aArgs.getArray(); |
1058 | 0 | pArgs[0].Value <<= aSearchEntry; |
1059 | 0 | pArgs[1].Name = "Family"; |
1060 | 0 | pArgs[1].Value <<= sal_Int16( eStyleFamily ); |
1061 | |
|
1062 | 0 | const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY); |
1063 | 0 | if( bCreateNew ) |
1064 | 0 | { |
1065 | 0 | pArgs[0].Name = "Param"; |
1066 | 0 | SfxToolBoxControl::Dispatch(xProvider, u".uno:StyleNewByExample"_ustr, aArgs); |
1067 | 0 | } |
1068 | 0 | else |
1069 | 0 | { |
1070 | 0 | pArgs[0].Name = "Template"; |
1071 | 0 | SfxToolBoxControl::Dispatch(xProvider, m_aCommand, aArgs); |
1072 | 0 | } |
1073 | 0 | } |
1074 | | |
1075 | | void SvxStyleBox_Base::SetFamily( SfxStyleFamily eNewFamily ) |
1076 | 0 | { |
1077 | 0 | eStyleFamily = eNewFamily; |
1078 | 0 | } |
1079 | | |
1080 | | IMPL_LINK_NOARG(SvxStyleBox_Base, FocusOutHdl, weld::Widget&, void) |
1081 | 0 | { |
1082 | 0 | if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus |
1083 | 0 | set_active_or_entry_text(m_xWidget->get_saved_value()); |
1084 | 0 | } |
1085 | | |
1086 | | IMPL_LINK(SvxStyleBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool) |
1087 | 0 | { |
1088 | 0 | return DoKeyInput(rKEvt); |
1089 | 0 | } |
1090 | | |
1091 | | bool SvxStyleBox_Base::DoKeyInput(const KeyEvent& rKEvt) |
1092 | 0 | { |
1093 | 0 | bool bHandled = false; |
1094 | |
|
1095 | 0 | sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); |
1096 | |
|
1097 | 0 | switch (nCode) |
1098 | 0 | { |
1099 | 0 | case KEY_TAB: |
1100 | 0 | bRelease = false; |
1101 | 0 | Select(true); |
1102 | 0 | break; |
1103 | 0 | case KEY_ESCAPE: |
1104 | 0 | set_active_or_entry_text(m_xWidget->get_saved_value()); |
1105 | 0 | if (!m_rCtrl.IsInSidebar()) |
1106 | 0 | { |
1107 | 0 | ReleaseFocus(); |
1108 | 0 | bHandled = true; |
1109 | 0 | } |
1110 | 0 | break; |
1111 | 0 | } |
1112 | | |
1113 | 0 | return bHandled; |
1114 | 0 | } |
1115 | | |
1116 | | bool SvxStyleBox_Impl::DoKeyInput(const KeyEvent& rKEvt) |
1117 | 0 | { |
1118 | 0 | return SvxStyleBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt); |
1119 | 0 | } |
1120 | | |
1121 | | void SvxStyleBox_Impl::DataChanged( const DataChangedEvent& rDCEvt ) |
1122 | 0 | { |
1123 | 0 | if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && |
1124 | 0 | (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) ) |
1125 | 0 | { |
1126 | 0 | SetOptimalSize(); |
1127 | 0 | } |
1128 | |
|
1129 | 0 | InterimItemWindow::DataChanged( rDCEvt ); |
1130 | 0 | } |
1131 | | |
1132 | | void SvxStyleBox_Impl::SetOptimalSize() |
1133 | 0 | { |
1134 | | // set width in chars low so the size request will not be overridden |
1135 | 0 | m_xWidget->set_entry_width_chars(1); |
1136 | | // tdf#132338 purely using this calculation to keep things their traditional width |
1137 | 0 | Size aSize(LogicToPixel(Size((COMBO_WIDTH_IN_CHARS + 3) * 4, 0), MapMode(MapUnit::MapAppFont))); |
1138 | 0 | m_xWidget->set_size_request(aSize.Width(), -1); |
1139 | |
|
1140 | 0 | SetSizePixel(get_preferred_size()); |
1141 | 0 | } |
1142 | | |
1143 | | namespace |
1144 | | { |
1145 | | std::vector<ScriptInfo> CheckScript(const OUString &rStyleName) |
1146 | 0 | { |
1147 | 0 | assert(!rStyleName.isEmpty()); // must have a preview text here! |
1148 | |
|
1149 | 0 | std::vector<ScriptInfo> aScriptChanges; |
1150 | |
|
1151 | 0 | auto aEditEngine = EditEngine(nullptr); |
1152 | 0 | aEditEngine.SetText(rStyleName); |
1153 | |
|
1154 | 0 | auto aScript = aEditEngine.GetScriptType({ 0, 0, 0, 0 }); |
1155 | 0 | for (sal_Int32 i = 1; i <= rStyleName.getLength(); i++) |
1156 | 0 | { |
1157 | 0 | auto aNextScript = aEditEngine.GetScriptType({ 0, i, 0, i }); |
1158 | 0 | if (aNextScript != aScript || i == rStyleName.getLength()) |
1159 | 0 | aScriptChanges.emplace_back(aScript, i); |
1160 | 0 | aScript = aNextScript; |
1161 | 0 | } |
1162 | |
|
1163 | 0 | return aScriptChanges; |
1164 | 0 | } |
1165 | | } |
1166 | | |
1167 | | tools::Rectangle SvxStyleBox_Base::CalcBoundRect(vcl::RenderContext& rRenderContext, const OUString &rStyleName, std::vector<ScriptInfo>& rScriptChanges, double fRatio) |
1168 | 0 | { |
1169 | 0 | tools::Rectangle aTextRect; |
1170 | |
|
1171 | 0 | SvtScriptType aScript; |
1172 | 0 | sal_uInt16 nIdx = 0; |
1173 | 0 | sal_Int32 nStart = 0; |
1174 | 0 | sal_Int32 nEnd; |
1175 | 0 | size_t nCnt = rScriptChanges.size(); |
1176 | |
|
1177 | 0 | if (nCnt) |
1178 | 0 | { |
1179 | 0 | nEnd = rScriptChanges[nIdx].changePos; |
1180 | 0 | aScript = rScriptChanges[nIdx].scriptType; |
1181 | 0 | } |
1182 | 0 | else |
1183 | 0 | { |
1184 | 0 | nEnd = rStyleName.getLength(); |
1185 | 0 | aScript = SvtScriptType::LATIN; |
1186 | 0 | } |
1187 | |
|
1188 | 0 | do |
1189 | 0 | { |
1190 | 0 | auto oFont = (aScript == SvtScriptType::ASIAN) ? |
1191 | 0 | m_oCJKFont : |
1192 | 0 | ((aScript == SvtScriptType::COMPLEX) ? |
1193 | 0 | m_oCTLFont : |
1194 | 0 | m_oFont); |
1195 | |
|
1196 | 0 | rRenderContext.Push(vcl::PushFlags::FONT); |
1197 | |
|
1198 | 0 | if (oFont) |
1199 | 0 | rRenderContext.SetFont(*oFont); |
1200 | |
|
1201 | 0 | if (fRatio != 1) |
1202 | 0 | { |
1203 | 0 | vcl::Font aFont(rRenderContext.GetFont()); |
1204 | 0 | Size aPixelSize(aFont.GetFontSize()); |
1205 | 0 | aPixelSize.setWidth(aPixelSize.Width() * fRatio); |
1206 | 0 | aPixelSize.setHeight(aPixelSize.Height() * fRatio); |
1207 | 0 | aFont.SetFontSize(aPixelSize); |
1208 | 0 | rRenderContext.SetFont(aFont); |
1209 | 0 | } |
1210 | |
|
1211 | 0 | tools::Rectangle aRect; |
1212 | 0 | rRenderContext.GetTextBoundRect(aRect, rStyleName, nStart, nStart, nEnd - nStart); |
1213 | 0 | aTextRect = aTextRect.Union(aRect); |
1214 | |
|
1215 | 0 | tools::Long nWidth = rRenderContext.GetTextWidth(rStyleName, nStart, nEnd - nStart); |
1216 | |
|
1217 | 0 | rRenderContext.Pop(); |
1218 | |
|
1219 | 0 | if (nIdx >= rScriptChanges.size()) |
1220 | 0 | break; |
1221 | | |
1222 | 0 | rScriptChanges[nIdx++].textWidth = nWidth; |
1223 | |
|
1224 | 0 | if (nEnd < rStyleName.getLength() && nIdx < nCnt) |
1225 | 0 | { |
1226 | 0 | nStart = nEnd; |
1227 | 0 | nEnd = rScriptChanges[nIdx].changePos; |
1228 | 0 | aScript = rScriptChanges[nIdx].scriptType; |
1229 | 0 | } |
1230 | 0 | else |
1231 | 0 | break; |
1232 | 0 | } |
1233 | 0 | while(true); |
1234 | | |
1235 | 0 | return aTextRect; |
1236 | 0 | } |
1237 | | |
1238 | | void SvxStyleBox_Base::UserDrawEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const tools::Rectangle& rTextRect, const OUString &rStyleName, const std::vector<ScriptInfo>& rScriptChanges) |
1239 | 0 | { |
1240 | | // IMG_TXT_DISTANCE in ilstbox.hxx is 6, then 1 is added as |
1241 | | // nBorder, and we are adding 1 in order to look better when |
1242 | | // italics is present |
1243 | 0 | const int nLeftDistance = 8; |
1244 | |
|
1245 | 0 | Point aPos(rRect.TopLeft()); |
1246 | 0 | aPos.AdjustX(nLeftDistance ); |
1247 | |
|
1248 | 0 | double fRatio = 1; |
1249 | 0 | if (rTextRect.Bottom() > rRect.GetHeight()) |
1250 | 0 | fRatio = static_cast<double>(rRect.GetHeight()) / rTextRect.Bottom(); |
1251 | 0 | else |
1252 | 0 | aPos.AdjustY((rRect.GetHeight() - rTextRect.Bottom()) / 2); |
1253 | |
|
1254 | 0 | SvtScriptType aScript; |
1255 | 0 | sal_uInt16 nIdx = 0; |
1256 | 0 | sal_Int32 nStart = 0; |
1257 | 0 | sal_Int32 nEnd; |
1258 | 0 | size_t nCnt = rScriptChanges.size(); |
1259 | |
|
1260 | 0 | if (nCnt) |
1261 | 0 | { |
1262 | 0 | nEnd = rScriptChanges[nIdx].changePos; |
1263 | 0 | aScript = rScriptChanges[nIdx].scriptType; |
1264 | 0 | } |
1265 | 0 | else |
1266 | 0 | { |
1267 | 0 | nEnd = rStyleName.getLength(); |
1268 | 0 | aScript = SvtScriptType::LATIN; |
1269 | 0 | } |
1270 | | |
1271 | |
|
1272 | 0 | do |
1273 | 0 | { |
1274 | 0 | auto oFont = (aScript == SvtScriptType::ASIAN) ? |
1275 | 0 | m_oCJKFont : |
1276 | 0 | ((aScript == SvtScriptType::COMPLEX) ? |
1277 | 0 | m_oCTLFont : |
1278 | 0 | m_oFont); |
1279 | |
|
1280 | 0 | rRenderContext.Push(vcl::PushFlags::FONT); |
1281 | |
|
1282 | 0 | if (oFont) |
1283 | 0 | rRenderContext.SetFont(*oFont); |
1284 | |
|
1285 | 0 | if (fRatio != 1) |
1286 | 0 | { |
1287 | 0 | vcl::Font aFont(rRenderContext.GetFont()); |
1288 | 0 | Size aPixelSize(aFont.GetFontSize()); |
1289 | 0 | aPixelSize.setWidth(aPixelSize.Width() * fRatio); |
1290 | 0 | aPixelSize.setHeight(aPixelSize.Height() * fRatio); |
1291 | 0 | aFont.SetFontSize(aPixelSize); |
1292 | 0 | rRenderContext.SetFont(aFont); |
1293 | 0 | } |
1294 | |
|
1295 | 0 | rRenderContext.DrawText(aPos, rStyleName, nStart, nEnd - nStart); |
1296 | |
|
1297 | 0 | rRenderContext.Pop(); |
1298 | |
|
1299 | 0 | aPos.AdjustX(rScriptChanges[nIdx++].textWidth * fRatio); |
1300 | 0 | if (nEnd < rStyleName.getLength() && nIdx < nCnt) |
1301 | 0 | { |
1302 | 0 | nStart = nEnd; |
1303 | 0 | nEnd = rScriptChanges[nIdx].changePos; |
1304 | 0 | aScript = rScriptChanges[nIdx].scriptType; |
1305 | 0 | } |
1306 | 0 | else |
1307 | 0 | break; |
1308 | 0 | } |
1309 | 0 | while(true); |
1310 | 0 | } |
1311 | | |
1312 | | static bool GetWhich(const SfxItemSet& rSet, sal_uInt16 nSlot, sal_uInt16& rWhich) |
1313 | 0 | { |
1314 | 0 | rWhich = rSet.GetPool()->GetWhichIDFromSlotID(nSlot); |
1315 | 0 | return rSet.GetItemState(rWhich) >= SfxItemState::DEFAULT; |
1316 | 0 | } |
1317 | | |
1318 | | static bool SetFont(const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont) |
1319 | 0 | { |
1320 | 0 | sal_uInt16 nWhich; |
1321 | 0 | if (GetWhich(rSet, nSlot, nWhich)) |
1322 | 0 | { |
1323 | 0 | const auto& rFontItem = static_cast<const SvxFontItem&>(rSet.Get(nWhich)); |
1324 | 0 | rFont.SetFamilyName(rFontItem.GetFamilyName()); |
1325 | 0 | rFont.SetStyleName(rFontItem.GetStyleName()); |
1326 | 0 | return true; |
1327 | 0 | } |
1328 | 0 | return false; |
1329 | 0 | } |
1330 | | |
1331 | | static bool SetFontSize(const vcl::RenderContext& rRenderContext, const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont) |
1332 | 0 | { |
1333 | 0 | sal_uInt16 nWhich; |
1334 | 0 | if (GetWhich(rSet, nSlot, nWhich)) |
1335 | 0 | { |
1336 | 0 | const auto& rFontHeightItem = static_cast<const SvxFontHeightItem&>(rSet.Get(nWhich)); |
1337 | 0 | if (SfxObjectShell *pShell = SfxObjectShell::Current()) |
1338 | 0 | { |
1339 | 0 | Size aFontSize(0, rFontHeightItem.GetHeight()); |
1340 | 0 | Size aPixelSize(rRenderContext.LogicToPixel(aFontSize, MapMode(pShell->GetMapUnit()))); |
1341 | 0 | rFont.SetFontSize(aPixelSize); |
1342 | 0 | return true; |
1343 | 0 | } |
1344 | 0 | } |
1345 | 0 | return false; |
1346 | 0 | } |
1347 | | |
1348 | | static void SetFontStyle(const SfxItemSet& rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont& rFont) |
1349 | 0 | { |
1350 | 0 | sal_uInt16 nWhich; |
1351 | 0 | if (GetWhich(rSet, nPosture, nWhich)) |
1352 | 0 | { |
1353 | 0 | const auto& rItem = static_cast<const SvxPostureItem&>(rSet.Get(nWhich)); |
1354 | 0 | rFont.SetItalic(rItem.GetPosture()); |
1355 | 0 | } |
1356 | |
|
1357 | 0 | if (GetWhich(rSet, nWeight, nWhich)) |
1358 | 0 | { |
1359 | 0 | const auto& rItem = static_cast<const SvxWeightItem&>(rSet.Get(nWhich)); |
1360 | 0 | rFont.SetWeight(rItem.GetWeight()); |
1361 | 0 | } |
1362 | 0 | } |
1363 | | |
1364 | | void SvxStyleBox_Base::SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32 nItem, const tools::Rectangle& rRect, std::u16string_view rStyleName, bool bIsNotSelected) |
1365 | 0 | { |
1366 | 0 | const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); |
1367 | 0 | if (!bIsNotSelected) |
1368 | 0 | rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor()); |
1369 | 0 | else |
1370 | 0 | rRenderContext.SetTextColor(rStyleSettings.GetDialogTextColor()); |
1371 | | |
1372 | | // handle the push-button |
1373 | 0 | if (!bIsNotSelected) |
1374 | 0 | { |
1375 | 0 | if (nItem == 0 || nItem == m_xWidget->get_count() - 1) |
1376 | 0 | m_xWidget->set_item_menu(OUString::number(nItem), nullptr); |
1377 | 0 | else |
1378 | 0 | { |
1379 | 0 | m_nLastItemWithMenu = nItem; |
1380 | 0 | m_xWidget->set_item_menu(OUString::number(nItem), m_xMenu.get()); |
1381 | 0 | } |
1382 | 0 | } |
1383 | |
|
1384 | 0 | if (nItem <= 0 || nItem >= m_xWidget->get_count() - 1) |
1385 | 0 | return; |
1386 | | |
1387 | 0 | SfxObjectShell *pShell = SfxObjectShell::Current(); |
1388 | 0 | if (!pShell) |
1389 | 0 | return; |
1390 | | |
1391 | 0 | SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool(); |
1392 | 0 | if (!pPool) |
1393 | 0 | return; |
1394 | | |
1395 | 0 | SfxStyleSheetBase* pStyle = pPool->First(eStyleFamily); |
1396 | 0 | while (pStyle && pStyle->GetName() != rStyleName) |
1397 | 0 | pStyle = pPool->Next(); |
1398 | |
|
1399 | 0 | if (!pStyle ) |
1400 | 0 | return; |
1401 | | |
1402 | 0 | std::optional<SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview()); |
1403 | 0 | if (!pItemSet) return; |
1404 | | |
1405 | 0 | SvxFont aFont; |
1406 | 0 | SvxFont aCJKFont; |
1407 | 0 | SvxFont aCTLFont; |
1408 | |
|
1409 | 0 | SetFontStyle(*pItemSet, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, aFont); |
1410 | 0 | SetFontStyle(*pItemSet, SID_ATTR_CHAR_CJK_POSTURE, SID_ATTR_CHAR_CJK_WEIGHT, aCJKFont); |
1411 | 0 | SetFontStyle(*pItemSet, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT, aCTLFont); |
1412 | |
|
1413 | 0 | const SfxPoolItem *pItem = pItemSet->GetItem( SID_ATTR_CHAR_CONTOUR ); |
1414 | 0 | if ( pItem ) |
1415 | 0 | { |
1416 | 0 | auto aVal = static_cast< const SvxContourItem* >( pItem )->GetValue(); |
1417 | 0 | aFont.SetOutline(aVal); |
1418 | 0 | aCJKFont.SetOutline(aVal); |
1419 | 0 | aCTLFont.SetOutline(aVal); |
1420 | 0 | } |
1421 | |
|
1422 | 0 | pItem = pItemSet->GetItem( SID_ATTR_CHAR_SHADOWED ); |
1423 | 0 | if ( pItem ) |
1424 | 0 | { |
1425 | 0 | auto aVal = static_cast< const SvxShadowedItem* >( pItem )->GetValue(); |
1426 | 0 | aFont.SetShadow(aVal); |
1427 | 0 | aCJKFont.SetShadow(aVal); |
1428 | 0 | aCTLFont.SetShadow(aVal); |
1429 | 0 | } |
1430 | |
|
1431 | 0 | pItem = pItemSet->GetItem( SID_ATTR_CHAR_RELIEF ); |
1432 | 0 | if ( pItem ) |
1433 | 0 | { |
1434 | 0 | auto aVal = static_cast< const SvxCharReliefItem* >( pItem )->GetValue(); |
1435 | 0 | aFont.SetRelief(aVal); |
1436 | 0 | aCJKFont.SetRelief(aVal); |
1437 | 0 | aCTLFont.SetRelief(aVal); |
1438 | 0 | } |
1439 | |
|
1440 | 0 | pItem = pItemSet->GetItem( SID_ATTR_CHAR_UNDERLINE ); |
1441 | 0 | if ( pItem ) |
1442 | 0 | { |
1443 | 0 | auto aVal = static_cast<const SvxUnderlineItem*>(pItem)->GetLineStyle(); |
1444 | 0 | aFont.SetUnderline(aVal); |
1445 | 0 | aCJKFont.SetUnderline(aVal); |
1446 | 0 | aCTLFont.SetUnderline(aVal); |
1447 | 0 | } |
1448 | |
|
1449 | 0 | pItem = pItemSet->GetItem( SID_ATTR_CHAR_OVERLINE ); |
1450 | 0 | if ( pItem ) |
1451 | 0 | { |
1452 | 0 | auto aVal = static_cast< const SvxOverlineItem* >( pItem )->GetValue(); |
1453 | 0 | aFont.SetOverline(aVal); |
1454 | 0 | aCJKFont.SetOverline(aVal); |
1455 | 0 | aCTLFont.SetOverline(aVal); |
1456 | 0 | } |
1457 | |
|
1458 | 0 | pItem = pItemSet->GetItem( SID_ATTR_CHAR_STRIKEOUT ); |
1459 | 0 | if ( pItem ) |
1460 | 0 | { |
1461 | 0 | auto aVal = static_cast< const SvxCrossedOutItem* >( pItem )->GetStrikeout(); |
1462 | 0 | aFont.SetStrikeout(aVal); |
1463 | 0 | aCJKFont.SetStrikeout(aVal); |
1464 | 0 | aCTLFont.SetStrikeout(aVal); |
1465 | 0 | } |
1466 | |
|
1467 | 0 | pItem = pItemSet->GetItem( SID_ATTR_CHAR_CASEMAP ); |
1468 | 0 | if ( pItem ) |
1469 | 0 | { |
1470 | 0 | auto aVal = static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap(); |
1471 | 0 | aFont.SetCaseMap(aVal); |
1472 | 0 | aCJKFont.SetCaseMap(aVal); |
1473 | 0 | aCTLFont.SetCaseMap(aVal); |
1474 | 0 | } |
1475 | |
|
1476 | 0 | pItem = pItemSet->GetItem( SID_ATTR_CHAR_EMPHASISMARK ); |
1477 | 0 | if ( pItem ) |
1478 | 0 | { |
1479 | 0 | auto aVal = static_cast< const SvxEmphasisMarkItem* >( pItem )->GetEmphasisMark(); |
1480 | 0 | aFont.SetEmphasisMark(aVal); |
1481 | 0 | aCJKFont.SetEmphasisMark(aVal); |
1482 | 0 | aCTLFont.SetEmphasisMark(aVal); |
1483 | 0 | } |
1484 | | |
1485 | | // setup the device & draw |
1486 | 0 | Color aFontCol = COL_AUTO, aBackCol = COL_AUTO; |
1487 | |
|
1488 | 0 | pItem = pItemSet->GetItem( SID_ATTR_CHAR_COLOR ); |
1489 | | // text color, when nothing is selected |
1490 | 0 | if ( (nullptr != pItem) && bIsNotSelected) |
1491 | 0 | aFontCol = static_cast< const SvxColorItem* >( pItem )->GetValue(); |
1492 | |
|
1493 | 0 | drawing::FillStyle style = drawing::FillStyle_NONE; |
1494 | | // which kind of Fill style is selected |
1495 | 0 | pItem = pItemSet->GetItem( XATTR_FILLSTYLE ); |
1496 | | // only when ok and not selected |
1497 | 0 | if ( (nullptr != pItem) && bIsNotSelected) |
1498 | 0 | style = static_cast< const XFillStyleItem* >( pItem )->GetValue(); |
1499 | |
|
1500 | 0 | switch(style) |
1501 | 0 | { |
1502 | 0 | case drawing::FillStyle_SOLID: |
1503 | 0 | { |
1504 | | // set background color |
1505 | 0 | pItem = pItemSet->GetItem( XATTR_FILLCOLOR ); |
1506 | 0 | if ( nullptr != pItem ) |
1507 | 0 | aBackCol = static_cast< const XFillColorItem* >( pItem )->GetColorValue(); |
1508 | |
|
1509 | 0 | if ( aBackCol != COL_AUTO ) |
1510 | 0 | { |
1511 | 0 | rRenderContext.SetFillColor(aBackCol); |
1512 | 0 | rRenderContext.DrawRect(rRect); |
1513 | 0 | } |
1514 | 0 | } |
1515 | 0 | break; |
1516 | | |
1517 | 0 | default: break; |
1518 | | //TODO Draw the other background styles: gradient, hatching and bitmap |
1519 | 0 | } |
1520 | | |
1521 | | // when the font and background color are too similar, adjust the Font-Color |
1522 | 0 | if( (aFontCol != COL_AUTO) || (aBackCol != COL_AUTO) ) |
1523 | 0 | aFontCol = TestColorsVisible(aFontCol, (aBackCol != COL_AUTO) ? aBackCol : rRenderContext.GetBackground().GetColor()); |
1524 | | |
1525 | | // set text color |
1526 | 0 | if ( aFontCol != COL_AUTO ) |
1527 | 0 | rRenderContext.SetTextColor(aFontCol); |
1528 | |
|
1529 | 0 | if (SetFont(*pItemSet, SID_ATTR_CHAR_FONT, aFont) && |
1530 | 0 | SetFontSize(rRenderContext, *pItemSet, SID_ATTR_CHAR_FONTHEIGHT, aFont)) |
1531 | 0 | m_oFont = aFont; |
1532 | |
|
1533 | 0 | if (SetFont(*pItemSet, SID_ATTR_CHAR_CJK_FONT, aCJKFont) && |
1534 | 0 | SetFontSize(rRenderContext, *pItemSet, SID_ATTR_CHAR_CJK_FONTHEIGHT, aCJKFont)) |
1535 | 0 | m_oCJKFont = aCJKFont; |
1536 | |
|
1537 | 0 | if (SetFont(*pItemSet, SID_ATTR_CHAR_CTL_FONT, aCTLFont) && |
1538 | 0 | SetFontSize(rRenderContext, *pItemSet, SID_ATTR_CHAR_CTL_FONTHEIGHT, aCTLFont)) |
1539 | 0 | m_oCTLFont = aCTLFont; |
1540 | 0 | } |
1541 | | |
1542 | | IMPL_LINK(SvxStyleBox_Base, CustomRenderHdl, weld::ComboBox::render_args, aPayload, void) |
1543 | 0 | { |
1544 | 0 | vcl::RenderContext& rRenderContext = std::get<0>(aPayload); |
1545 | 0 | const ::tools::Rectangle& rRect = std::get<1>(aPayload); |
1546 | 0 | bool bSelected = std::get<2>(aPayload); |
1547 | 0 | const OUString& rId = std::get<3>(aPayload); |
1548 | |
|
1549 | 0 | sal_uInt32 nIndex = rId.toUInt32(); |
1550 | |
|
1551 | 0 | OUString aStyleName(m_xWidget->get_text(nIndex)); |
1552 | |
|
1553 | 0 | rRenderContext.Push(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::FONT | vcl::PushFlags::TEXTCOLOR); |
1554 | |
|
1555 | 0 | SetupEntry(rRenderContext, nIndex, rRect, aStyleName, !bSelected); |
1556 | 0 | auto aScriptChanges = CheckScript(aStyleName); |
1557 | 0 | auto aTextRect = CalcBoundRect(rRenderContext, aStyleName, aScriptChanges); |
1558 | 0 | UserDrawEntry(rRenderContext, rRect, aTextRect, aStyleName, aScriptChanges); |
1559 | |
|
1560 | 0 | rRenderContext.Pop(); |
1561 | 0 | } |
1562 | | |
1563 | | void SvxStyleBox_Base::CalcOptimalExtraUserWidth(vcl::RenderContext& rRenderContext) |
1564 | 0 | { |
1565 | 0 | if (m_nMaxUserDrawFontWidth) |
1566 | 0 | return; |
1567 | | |
1568 | 0 | tools::Long nMaxNormalFontWidth = 0; |
1569 | 0 | sal_Int32 nEntryCount = m_xWidget->get_count(); |
1570 | 0 | for (sal_Int32 i = 0; i < nEntryCount; ++i) |
1571 | 0 | { |
1572 | 0 | OUString sStyleName(get_text(i)); |
1573 | 0 | tools::Rectangle aTextRectForDefaultFont; |
1574 | 0 | rRenderContext.GetTextBoundRect(aTextRectForDefaultFont, sStyleName); |
1575 | |
|
1576 | 0 | const tools::Long nWidth = aTextRectForDefaultFont.GetWidth(); |
1577 | |
|
1578 | 0 | nMaxNormalFontWidth = std::max(nWidth, nMaxNormalFontWidth); |
1579 | 0 | } |
1580 | |
|
1581 | 0 | m_nMaxUserDrawFontWidth = nMaxNormalFontWidth; |
1582 | 0 | for (sal_Int32 i = 1; i < nEntryCount-1; ++i) |
1583 | 0 | { |
1584 | 0 | OUString sStyleName(get_text(i)); |
1585 | |
|
1586 | 0 | if (sStyleName.isEmpty()) |
1587 | 0 | continue; |
1588 | | |
1589 | 0 | rRenderContext.Push(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::FONT | vcl::PushFlags::TEXTCOLOR); |
1590 | 0 | SetupEntry(rRenderContext, i, tools::Rectangle(0, 0, RECT_MAX, ITEM_HEIGHT), sStyleName, true); |
1591 | 0 | auto aScriptChanges = CheckScript(sStyleName); |
1592 | 0 | tools::Rectangle aTextRectForActualFont = CalcBoundRect(rRenderContext, sStyleName, aScriptChanges); |
1593 | 0 | if (aTextRectForActualFont.Bottom() > ITEM_HEIGHT) |
1594 | 0 | { |
1595 | | //Font didn't fit, re-calculate with adjustment ratio. |
1596 | 0 | double fRatio = static_cast<double>(ITEM_HEIGHT) / aTextRectForActualFont.Bottom(); |
1597 | 0 | aTextRectForActualFont = CalcBoundRect(rRenderContext, sStyleName, aScriptChanges, fRatio); |
1598 | 0 | } |
1599 | 0 | rRenderContext.Pop(); |
1600 | |
|
1601 | 0 | const int nWidth = aTextRectForActualFont.GetWidth() + m_xWidget->get_menu_button_width() + BUTTON_PADDING; |
1602 | |
|
1603 | 0 | m_nMaxUserDrawFontWidth = std::max(nWidth, m_nMaxUserDrawFontWidth); |
1604 | 0 | } |
1605 | 0 | } |
1606 | | |
1607 | | // test is the color between Font- and background-color to be identify |
1608 | | // return is always the Font-Color |
1609 | | // when both light or dark, change the Contrast |
1610 | | // in other case do not change the origin color |
1611 | | // when the color is R=G=B=128 the DecreaseContrast make 128 the need an exception |
1612 | | Color SvxStyleBox_Base::TestColorsVisible(const Color &FontCol, const Color &BackCol) |
1613 | 0 | { |
1614 | 0 | constexpr sal_uInt8 ChgVal = 60; // increase/decrease the Contrast |
1615 | |
|
1616 | 0 | Color retCol = FontCol; |
1617 | 0 | if ((FontCol.IsDark() == BackCol.IsDark()) && (FontCol.IsBright() == BackCol.IsBright())) |
1618 | 0 | { |
1619 | 0 | sal_uInt8 lumi = retCol.GetLuminance(); |
1620 | |
|
1621 | 0 | if((lumi > 120) && (lumi < 140)) |
1622 | 0 | retCol.DecreaseLuminance(ChgVal / 2); |
1623 | 0 | else |
1624 | 0 | retCol.DecreaseContrast(ChgVal); |
1625 | 0 | } |
1626 | |
|
1627 | 0 | return retCol; |
1628 | 0 | } |
1629 | | |
1630 | | IMPL_LINK(SvxStyleBox_Base, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void) |
1631 | 0 | { |
1632 | 0 | if (!m_xWidget) |
1633 | 0 | return; |
1634 | | |
1635 | 0 | { |
1636 | 0 | auto entriesNode = rJsonWriter.startNode("entries"); |
1637 | 0 | for (int i = 0, nEntryCount = m_xWidget->get_count(); i < nEntryCount; ++i) |
1638 | 0 | { |
1639 | 0 | auto entryNode = rJsonWriter.startNode(""); |
1640 | 0 | rJsonWriter.put("", m_xWidget->get_text(i)); |
1641 | 0 | } |
1642 | 0 | } |
1643 | |
|
1644 | 0 | int nActive = m_xWidget->get_active(); |
1645 | 0 | rJsonWriter.put("selectedCount", static_cast<sal_Int32>(nActive == -1 ? 0 : 1)); |
1646 | |
|
1647 | 0 | { |
1648 | 0 | auto selectedNode = rJsonWriter.startNode("selectedEntries"); |
1649 | 0 | if (nActive != -1) |
1650 | 0 | { |
1651 | 0 | auto node = rJsonWriter.startNode(""); |
1652 | 0 | rJsonWriter.put("", static_cast<sal_Int32>(nActive)); |
1653 | 0 | } |
1654 | 0 | } |
1655 | |
|
1656 | 0 | rJsonWriter.put("command", ".uno:StyleApply"); |
1657 | 0 | } |
1658 | | |
1659 | | static bool lcl_GetDocFontList(const FontList** ppFontList, SvxFontNameBox_Base& rBox) |
1660 | 0 | { |
1661 | 0 | bool bChanged = false; |
1662 | 0 | const SfxObjectShell* pDocSh = SfxObjectShell::Current(); |
1663 | 0 | const SvxFontListItem* pFontListItem = nullptr; |
1664 | |
|
1665 | 0 | if ( pDocSh ) |
1666 | 0 | pFontListItem = |
1667 | 0 | static_cast<const SvxFontListItem*>(pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST )); |
1668 | 0 | else |
1669 | 0 | { |
1670 | 0 | ::std::unique_ptr<FontList> aFontList(new FontList(Application::GetDefaultDevice())); |
1671 | 0 | *ppFontList = aFontList.get(); |
1672 | 0 | rBox.SetOwnFontList(std::move(aFontList)); |
1673 | 0 | bChanged = true; |
1674 | 0 | } |
1675 | |
|
1676 | 0 | if ( pFontListItem ) |
1677 | 0 | { |
1678 | 0 | const FontList* pNewFontList = pFontListItem->GetFontList(); |
1679 | 0 | DBG_ASSERT( pNewFontList, "Doc-FontList not available!" ); |
1680 | | |
1681 | | // No old list, but a new list |
1682 | 0 | if ( !*ppFontList && pNewFontList ) |
1683 | 0 | { |
1684 | | // => take over |
1685 | 0 | *ppFontList = pNewFontList; |
1686 | 0 | bChanged = true; |
1687 | 0 | } |
1688 | 0 | else |
1689 | 0 | { |
1690 | | // Comparing the font lists is not perfect. |
1691 | | // When you change the font list in the Doc, you can track |
1692 | | // changes here only on the Listbox, because ppFontList |
1693 | | // has already been updated. |
1694 | 0 | bChanged = !pNewFontList || |
1695 | 0 | *ppFontList != pNewFontList || |
1696 | 0 | rBox.GetListCount() != pNewFontList->GetFontNameCount(); |
1697 | | // HACK: Comparing is incomplete |
1698 | |
|
1699 | 0 | if ( bChanged ) |
1700 | 0 | *ppFontList = pNewFontList; |
1701 | 0 | } |
1702 | |
|
1703 | 0 | rBox.set_sensitive(true); |
1704 | 0 | } |
1705 | 0 | else if ( pDocSh || !ppFontList) |
1706 | 0 | { |
1707 | | // Disable box only when we have a SfxObjectShell and didn't get a font list OR |
1708 | | // we don't have a SfxObjectShell and no current font list. |
1709 | | // It's possible that we currently have no SfxObjectShell, but a current font list. |
1710 | | // See #i58471: When a user set the focus into the font name combo box and opens |
1711 | | // the help window with F1. After closing the help window, we disable the font name |
1712 | | // combo box. The SfxObjectShell::Current() method returns in that case zero. But the |
1713 | | // font list hasn't changed and therefore the combo box shouldn't be disabled! |
1714 | 0 | rBox.set_sensitive(false); |
1715 | 0 | } |
1716 | | |
1717 | | // Fill the FontBox, also the new list if necessary |
1718 | 0 | if ( bChanged ) |
1719 | 0 | { |
1720 | 0 | if (ppFontList && *ppFontList) |
1721 | 0 | rBox.Fill( *ppFontList ); |
1722 | 0 | else |
1723 | 0 | rBox.Clear(); |
1724 | 0 | } |
1725 | 0 | return bChanged; |
1726 | 0 | } |
1727 | | |
1728 | | SvxFontNameBox_Base::SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget, |
1729 | | const Reference<XFrame>& rFrame, |
1730 | | SvxFontNameToolBoxControl& rCtrl) |
1731 | 0 | : m_xListener(new comphelper::ConfigurationListener(u"/org.openoffice.Office.Common/Font/View"_ustr)) |
1732 | 0 | , m_aWYSIWYG(m_xListener, u"ShowFontBoxWYSIWYG"_ustr, *this) |
1733 | 0 | , m_aHistory(m_xListener, u"History"_ustr, *this) |
1734 | 0 | , m_rCtrl(rCtrl) |
1735 | 0 | , m_xWidget(new FontNameBox(std::move(xWidget))) |
1736 | 0 | , pFontList(nullptr) |
1737 | 0 | , nFtCount(0) |
1738 | 0 | , bRelease(true) |
1739 | 0 | , m_xFrame(rFrame) |
1740 | 0 | , mbCheckingUnknownFont(false) |
1741 | 0 | , mbDropDownActive(false) |
1742 | 0 | { |
1743 | 0 | EnableControls(); |
1744 | |
|
1745 | 0 | m_xWidget->connect_changed(LINK(this, SvxFontNameBox_Base, SelectHdl)); |
1746 | 0 | m_xWidget->connect_key_press(LINK(this, SvxFontNameBox_Base, KeyInputHdl)); |
1747 | 0 | m_xWidget->connect_entry_activate(LINK(this, SvxFontNameBox_Base, ActivateHdl)); |
1748 | 0 | m_xWidget->connect_focus_in(LINK(this, SvxFontNameBox_Base, FocusInHdl)); |
1749 | 0 | m_xWidget->connect_focus_out(LINK(this, SvxFontNameBox_Base, FocusOutHdl)); |
1750 | 0 | m_xWidget->connect_popup_toggled(LINK(this, SvxFontNameBox_Base, PopupToggledHdl)); |
1751 | 0 | m_xWidget->connect_live_preview(LINK(this, SvxFontNameBox_Base, LivePreviewHdl)); |
1752 | 0 | m_xWidget->connect_get_property_tree(LINK(this, SvxFontNameBox_Base, DumpAsPropertyTreeHdl)); |
1753 | |
|
1754 | 0 | m_xWidget->set_entry_width_chars(COMBO_WIDTH_IN_CHARS + 5); |
1755 | 0 | } |
1756 | | |
1757 | | SvxFontNameBox_Impl::SvxFontNameBox_Impl(vcl::Window* pParent, const Reference<XFrame>& rFrame, |
1758 | | SvxFontNameToolBoxControl& rCtrl) |
1759 | 0 | : InterimItemWindow(pParent, u"svx/ui/fontnamebox.ui"_ustr, u"FontNameBox"_ustr, true, reinterpret_cast<sal_uInt64>(SfxViewShell::Current())) |
1760 | 0 | , SvxFontNameBox_Base(m_xBuilder->weld_combo_box(u"fontnamecombobox"_ustr), rFrame, rCtrl) |
1761 | 0 | { |
1762 | 0 | set_id(u"fontnamecombobox"_ustr); |
1763 | 0 | SetOptimalSize(); |
1764 | 0 | } |
1765 | | |
1766 | | void SvxFontNameBox_Base::FillList() |
1767 | 0 | { |
1768 | 0 | if (!m_xWidget) // e.g. disposed |
1769 | 0 | return; |
1770 | | // Save old Selection, set back in the end |
1771 | 0 | int nStartPos, nEndPos; |
1772 | 0 | m_xWidget->get_entry_selection_bounds(nStartPos, nEndPos); |
1773 | | |
1774 | | // Did Doc-Fontlist change? |
1775 | 0 | lcl_GetDocFontList(&pFontList, *this); |
1776 | |
|
1777 | 0 | m_xWidget->select_entry_region(nStartPos, nEndPos); |
1778 | 0 | } |
1779 | | |
1780 | | bool SvxFontNameBox_Base::CheckFontIsAvailable(std::u16string_view fontname) |
1781 | 0 | { |
1782 | 0 | lcl_GetDocFontList(&pFontList, *this); |
1783 | 0 | return pFontList && pFontList->IsAvailable(fontname); |
1784 | 0 | } |
1785 | | |
1786 | | void SvxFontNameBox_Base::CheckAndMarkUnknownFont() |
1787 | 0 | { |
1788 | 0 | if (mbCheckingUnknownFont) //tdf#117537 block rentry |
1789 | 0 | return; |
1790 | 0 | mbCheckingUnknownFont = true; |
1791 | 0 | OUString fontname = m_xWidget->get_active_text(); |
1792 | | // tdf#154680 If a font is set and that font is unknown, show it in italic. |
1793 | 0 | vcl::Font font = m_xWidget->get_entry_font(); |
1794 | 0 | if (fontname.isEmpty() || CheckFontIsAvailable(fontname)) |
1795 | 0 | { |
1796 | 0 | if( font.GetItalicMaybeAskConfig() != ITALIC_NONE ) |
1797 | 0 | { |
1798 | 0 | font.SetItalic( ITALIC_NONE ); |
1799 | 0 | m_xWidget->set_entry_font(font); |
1800 | 0 | m_xWidget->set_tooltip_text(SvxResId(RID_SVXSTR_CHARFONTNAME)); |
1801 | 0 | } |
1802 | 0 | } |
1803 | 0 | else |
1804 | 0 | { |
1805 | 0 | if( font.GetItalicMaybeAskConfig() != ITALIC_NORMAL ) |
1806 | 0 | { |
1807 | 0 | font.SetItalic( ITALIC_NORMAL ); |
1808 | 0 | m_xWidget->set_entry_font(font); |
1809 | 0 | m_xWidget->set_tooltip_text(SvxResId(RID_SVXSTR_CHARFONTNAME_NOTAVAILABLE)); |
1810 | 0 | } |
1811 | 0 | } |
1812 | 0 | mbCheckingUnknownFont = false; |
1813 | 0 | } |
1814 | | |
1815 | | void SvxFontNameBox_Base::Update( const css::awt::FontDescriptor* pFontDesc ) |
1816 | 0 | { |
1817 | 0 | if ( pFontDesc ) |
1818 | 0 | { |
1819 | 0 | aCurFont.SetFamilyName ( pFontDesc->Name ); |
1820 | 0 | aCurFont.SetFamily ( FontFamily( pFontDesc->Family ) ); |
1821 | 0 | aCurFont.SetStyleName ( pFontDesc->StyleName ); |
1822 | 0 | aCurFont.SetPitch ( FontPitch( pFontDesc->Pitch ) ); |
1823 | 0 | aCurFont.SetCharSet ( rtl_TextEncoding( pFontDesc->CharSet ) ); |
1824 | 0 | } |
1825 | 0 | OUString aCurName = aCurFont.GetFamilyName(); |
1826 | 0 | OUString aText = m_xWidget->get_active_text(); |
1827 | 0 | if (aText != aCurName) |
1828 | 0 | set_active_or_entry_text(aCurName); |
1829 | 0 | } |
1830 | | |
1831 | | void SvxFontNameBox_Base::set_active_or_entry_text(const OUString& rText) |
1832 | 0 | { |
1833 | 0 | m_xWidget->set_active_or_entry_text(rText); |
1834 | 0 | CheckAndMarkUnknownFont(); |
1835 | 0 | } |
1836 | | |
1837 | | IMPL_LINK_NOARG(SvxFontNameBox_Base, FocusInHdl, weld::Widget&, void) |
1838 | 0 | { |
1839 | 0 | FillList(); |
1840 | 0 | } |
1841 | | |
1842 | | IMPL_LINK(SvxFontNameBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool) |
1843 | 0 | { |
1844 | 0 | return DoKeyInput(rKEvt); |
1845 | 0 | } |
1846 | | |
1847 | | bool SvxFontNameBox_Base::DoKeyInput(const KeyEvent& rKEvt) |
1848 | 0 | { |
1849 | 0 | bool bHandled = false; |
1850 | |
|
1851 | 0 | sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); |
1852 | |
|
1853 | 0 | switch (nCode) |
1854 | 0 | { |
1855 | 0 | case KEY_TAB: |
1856 | 0 | bRelease = false; |
1857 | 0 | Select(true); |
1858 | 0 | break; |
1859 | | |
1860 | 0 | case KEY_ESCAPE: |
1861 | 0 | set_active_or_entry_text(m_xWidget->get_saved_value()); |
1862 | 0 | if (!m_rCtrl.IsInSidebar()) |
1863 | 0 | { |
1864 | 0 | ReleaseFocus_Impl(); |
1865 | 0 | bHandled = true; |
1866 | 0 | } |
1867 | 0 | break; |
1868 | 0 | } |
1869 | | |
1870 | 0 | return bHandled; |
1871 | 0 | } |
1872 | | |
1873 | | bool SvxFontNameBox_Impl::DoKeyInput(const KeyEvent& rKEvt) |
1874 | 0 | { |
1875 | 0 | return SvxFontNameBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt); |
1876 | 0 | } |
1877 | | |
1878 | | IMPL_LINK_NOARG(SvxFontNameBox_Base, FocusOutHdl, weld::Widget&, void) |
1879 | 0 | { |
1880 | 0 | if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus |
1881 | 0 | { |
1882 | 0 | set_active_or_entry_text(m_xWidget->get_saved_value()); |
1883 | | // send EndPreview |
1884 | 0 | EndPreview(); |
1885 | 0 | } |
1886 | 0 | } |
1887 | | |
1888 | | IMPL_LINK(SvxFontNameBox_Base, LivePreviewHdl, const FontMetric&, rFontMetric, void) |
1889 | 0 | { |
1890 | 0 | Sequence<PropertyValue> aArgs(1); |
1891 | |
|
1892 | 0 | SvxFontItem aFontItem(rFontMetric.GetFamilyType(), |
1893 | 0 | rFontMetric.GetFamilyName(), |
1894 | 0 | rFontMetric.GetStyleName(), |
1895 | 0 | rFontMetric.GetPitch(), |
1896 | 0 | rFontMetric.GetCharSet(), |
1897 | 0 | SID_ATTR_CHAR_FONT); |
1898 | 0 | PropertyValue* pArgs = aArgs.getArray(); |
1899 | 0 | aFontItem.QueryValue(pArgs[0].Value); |
1900 | 0 | pArgs[0].Name = "CharPreviewFontName"; |
1901 | 0 | const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY); |
1902 | 0 | SfxToolBoxControl::Dispatch(xProvider, u".uno:CharPreviewFontName"_ustr, aArgs); |
1903 | 0 | } |
1904 | | |
1905 | | IMPL_LINK_NOARG(SvxFontNameBox_Base, PopupToggledHdl, weld::ComboBox&, void) |
1906 | 0 | { |
1907 | 0 | mbDropDownActive = !mbDropDownActive; |
1908 | 0 | if (!mbDropDownActive) |
1909 | 0 | EndPreview(); |
1910 | 0 | } |
1911 | | |
1912 | | void SvxFontNameBox_Impl::SetOptimalSize() |
1913 | 0 | { |
1914 | | // set width in chars low so the size request will not be overridden |
1915 | 0 | m_xWidget->set_entry_width_chars(1); |
1916 | | // tdf#132338 purely using this calculation to keep things their traditional width |
1917 | 0 | Size aSize(LogicToPixel(Size((COMBO_WIDTH_IN_CHARS +5) * 4, 0), MapMode(MapUnit::MapAppFont))); |
1918 | 0 | m_xWidget->set_size_request(aSize.Width(), -1); |
1919 | |
|
1920 | 0 | SetSizePixel(get_preferred_size()); |
1921 | 0 | } |
1922 | | |
1923 | | void SvxFontNameBox_Impl::DataChanged( const DataChangedEvent& rDCEvt ) |
1924 | 0 | { |
1925 | 0 | if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && |
1926 | 0 | (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) ) |
1927 | 0 | { |
1928 | 0 | SetOptimalSize(); |
1929 | 0 | } |
1930 | 0 | else if ( ( rDCEvt.GetType() == DataChangedEventType::FONTS ) || |
1931 | 0 | ( rDCEvt.GetType() == DataChangedEventType::DISPLAY ) ) |
1932 | 0 | { |
1933 | | // The old font list in shell has likely been destroyed at this point, so we need to get |
1934 | | // the new one before doing anything further. |
1935 | 0 | lcl_GetDocFontList( &pFontList, *this ); |
1936 | 0 | } |
1937 | 0 | } |
1938 | | |
1939 | | void SvxFontNameBox_Base::ReleaseFocus_Impl() |
1940 | 0 | { |
1941 | 0 | if ( !bRelease ) |
1942 | 0 | { |
1943 | 0 | bRelease = true; |
1944 | 0 | return; |
1945 | 0 | } |
1946 | 0 | if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() ) |
1947 | 0 | m_xFrame->getContainerWindow()->setFocus(); |
1948 | 0 | } |
1949 | | |
1950 | | void SvxFontNameBox_Base::EnableControls() |
1951 | 0 | { |
1952 | 0 | bool bEnableMRU = m_aHistory.get(); |
1953 | 0 | sal_uInt16 nEntries = bEnableMRU ? MAX_MRU_FONTNAME_ENTRIES : 0; |
1954 | |
|
1955 | 0 | bool bNewWYSIWYG = m_aWYSIWYG.get(); |
1956 | 0 | bool bOldWYSIWYG = m_xWidget->IsWYSIWYGEnabled(); |
1957 | |
|
1958 | 0 | if (m_xWidget->get_max_mru_count() != nEntries || bNewWYSIWYG != bOldWYSIWYG) |
1959 | 0 | { |
1960 | | // refill in the next GetFocus-Handler |
1961 | 0 | pFontList = nullptr; |
1962 | 0 | Clear(); |
1963 | 0 | m_xWidget->set_max_mru_count(nEntries); |
1964 | 0 | } |
1965 | |
|
1966 | 0 | if (bNewWYSIWYG != bOldWYSIWYG) |
1967 | 0 | m_xWidget->EnableWYSIWYG(bNewWYSIWYG); |
1968 | 0 | } |
1969 | | |
1970 | | IMPL_LINK(SvxFontNameBox_Base, SelectHdl, weld::ComboBox&, rCombo, void) |
1971 | 0 | { |
1972 | 0 | Select(rCombo.changed_by_direct_pick()); // only when picked from the list |
1973 | 0 | } |
1974 | | |
1975 | | IMPL_LINK_NOARG(SvxFontNameBox_Base, ActivateHdl, weld::ComboBox&, bool) |
1976 | 0 | { |
1977 | 0 | Select(true); |
1978 | 0 | return true; |
1979 | 0 | } |
1980 | | |
1981 | | void SvxFontNameBox_Base::Select(bool bNonTravelSelect) |
1982 | 0 | { |
1983 | 0 | Sequence< PropertyValue > aArgs( 1 ); |
1984 | 0 | auto pArgs = aArgs.getArray(); |
1985 | 0 | std::unique_ptr<SvxFontItem> pFontItem; |
1986 | 0 | if ( pFontList ) |
1987 | 0 | { |
1988 | 0 | FontMetric aFontMetric( pFontList->Get(m_xWidget->get_active_text(), |
1989 | 0 | aCurFont.GetWeightMaybeAskConfig(), |
1990 | 0 | aCurFont.GetItalicMaybeAskConfig() ) ); |
1991 | 0 | aCurFont = aFontMetric; |
1992 | |
|
1993 | 0 | pFontItem.reset( new SvxFontItem( aFontMetric.GetFamilyTypeMaybeAskConfig(), |
1994 | 0 | aFontMetric.GetFamilyName(), |
1995 | 0 | aFontMetric.GetStyleName(), |
1996 | 0 | aFontMetric.GetPitchMaybeAskConfig(), |
1997 | 0 | aFontMetric.GetCharSet(), |
1998 | 0 | SID_ATTR_CHAR_FONT ) ); |
1999 | |
|
2000 | 0 | Any a; |
2001 | 0 | pFontItem->QueryValue( a ); |
2002 | 0 | pArgs[0].Value = std::move(a); |
2003 | 0 | } |
2004 | |
|
2005 | 0 | const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY); |
2006 | 0 | if (bNonTravelSelect) |
2007 | 0 | { |
2008 | 0 | CheckAndMarkUnknownFont(); |
2009 | | // #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call. |
2010 | | // This instance may be deleted in the meantime (i.e. when a dialog is opened |
2011 | | // while in Dispatch()), accessing members will crash in this case. |
2012 | 0 | ReleaseFocus_Impl(); |
2013 | 0 | EndPreview(); |
2014 | 0 | if (pFontItem) |
2015 | 0 | { |
2016 | 0 | pArgs[0].Name = "CharFontName"; |
2017 | 0 | SfxToolBoxControl::Dispatch(xProvider, u".uno:CharFontName"_ustr, aArgs); |
2018 | 0 | } |
2019 | 0 | } |
2020 | 0 | else |
2021 | 0 | { |
2022 | 0 | if (pFontItem) |
2023 | 0 | { |
2024 | 0 | pArgs[0].Name = "CharPreviewFontName"; |
2025 | 0 | SfxToolBoxControl::Dispatch(xProvider, u".uno:CharPreviewFontName"_ustr, aArgs); |
2026 | 0 | } |
2027 | 0 | } |
2028 | 0 | } |
2029 | | |
2030 | | IMPL_LINK(SvxFontNameBox_Base, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void) |
2031 | 0 | { |
2032 | 0 | { |
2033 | 0 | auto entriesNode = rJsonWriter.startNode("entries"); |
2034 | 0 | for (int i = 0, nEntryCount = m_xWidget->get_count(); i < nEntryCount; ++i) |
2035 | 0 | { |
2036 | 0 | auto entryNode = rJsonWriter.startNode(""); |
2037 | 0 | rJsonWriter.put("", m_xWidget->get_text(i)); |
2038 | 0 | } |
2039 | 0 | } |
2040 | |
|
2041 | 0 | int nSelectedEntry = m_xWidget->get_active(); |
2042 | 0 | rJsonWriter.put("selectedCount", static_cast<sal_Int32>(nSelectedEntry == -1 ? 0 : 1)); |
2043 | |
|
2044 | 0 | { |
2045 | 0 | auto selectedNode = rJsonWriter.startNode("selectedEntries"); |
2046 | 0 | if (nSelectedEntry != -1) |
2047 | 0 | { |
2048 | 0 | auto entryNode = rJsonWriter.startNode(""); |
2049 | 0 | rJsonWriter.put("", m_xWidget->get_text(nSelectedEntry)); |
2050 | 0 | } |
2051 | 0 | } |
2052 | |
|
2053 | 0 | rJsonWriter.put("command", ".uno:CharFontName"); |
2054 | 0 | } |
2055 | | |
2056 | | ColorWindow::ColorWindow(OUString rCommand, |
2057 | | std::shared_ptr<PaletteManager> xPaletteManager, |
2058 | | ColorStatus& rColorStatus, |
2059 | | sal_uInt16 nSlotId, |
2060 | | const Reference< XFrame >& rFrame, |
2061 | | const MenuOrToolMenuButton& rMenuButton, |
2062 | | TopLevelParentFunction aTopLevelParentFunction, |
2063 | | ColorSelectFunction aColorSelectFunction) |
2064 | 0 | : WeldToolbarPopup(rFrame, rMenuButton.get_widget(), u"svx/ui/colorwindow.ui"_ustr, u"palette_popup_window"_ustr) |
2065 | 0 | , mnSlotId(nSlotId) |
2066 | 0 | , maCommand(std::move(rCommand)) |
2067 | 0 | , maMenuButton(rMenuButton) |
2068 | 0 | , mxPaletteManager(std::move(xPaletteManager)) |
2069 | 0 | , mrColorStatus(rColorStatus) |
2070 | 0 | , maTopLevelParentFunction(std::move(aTopLevelParentFunction)) |
2071 | 0 | , maColorSelectFunction(std::move(aColorSelectFunction)) |
2072 | 0 | , mxColorSet(new SvxColorValueSet(m_xBuilder->weld_scrolled_window(u"colorsetwin"_ustr, true))) |
2073 | 0 | , mxRecentColorSet(new SvxColorValueSet(nullptr)) |
2074 | 0 | , mxPaletteListBox(m_xBuilder->weld_combo_box(u"palette_listbox"_ustr)) |
2075 | 0 | , mxButtonAutoColor(m_xBuilder->weld_button(u"auto_color_button"_ustr)) |
2076 | 0 | , mxButtonNoneColor(m_xBuilder->weld_button(u"none_color_button"_ustr)) |
2077 | 0 | , mxButtonPicker(m_xBuilder->weld_button(u"color_picker_button"_ustr)) |
2078 | 0 | , mxAutomaticSeparator(m_xBuilder->weld_widget(u"separator4"_ustr)) |
2079 | 0 | , mxColorSetWin(new weld::CustomWeld(*m_xBuilder, u"colorset"_ustr, *mxColorSet)) |
2080 | 0 | , mxRecentColorSetWin(new weld::CustomWeld(*m_xBuilder, u"recent_colorset"_ustr, *mxRecentColorSet)) |
2081 | 0 | , mpDefaultButton(nullptr) |
2082 | 0 | { |
2083 | 0 | mxColorSet->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) ); |
2084 | 0 | mxRecentColorSet->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) ); |
2085 | |
|
2086 | 0 | switch ( mnSlotId ) |
2087 | 0 | { |
2088 | 0 | case SID_ATTR_CHAR_COLOR_BACKGROUND: |
2089 | 0 | case SID_BACKGROUND_COLOR: |
2090 | 0 | case SID_ATTR_CHAR_BACK_COLOR: |
2091 | 0 | case SID_TABLE_CELL_BACKGROUND_COLOR: |
2092 | 0 | { |
2093 | 0 | mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_NOFILL ) ); |
2094 | 0 | break; |
2095 | 0 | } |
2096 | 0 | case SID_AUTHOR_COLOR: |
2097 | 0 | { |
2098 | 0 | mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_BY_AUTHOR ) ); |
2099 | 0 | break; |
2100 | 0 | } |
2101 | 0 | case SID_BMPMASK_COLOR: |
2102 | 0 | { |
2103 | 0 | mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_TRANSPARENT ) ); |
2104 | 0 | break; |
2105 | 0 | } |
2106 | 0 | case SID_ATTR_CHAR_COLOR: |
2107 | 0 | case SID_ATTR_CHAR_COLOR2: |
2108 | 0 | case SID_EXTRUSION_3D_COLOR: |
2109 | 0 | { |
2110 | 0 | mxButtonAutoColor->set_label(EditResId(RID_SVXSTR_AUTOMATIC)); |
2111 | 0 | break; |
2112 | 0 | } |
2113 | 0 | case SID_FM_CTL_PROPERTIES: |
2114 | 0 | { |
2115 | 0 | mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_DEFAULT ) ); |
2116 | 0 | break; |
2117 | 0 | } |
2118 | 0 | default: |
2119 | 0 | { |
2120 | 0 | mxButtonAutoColor->hide(); |
2121 | 0 | mxAutomaticSeparator->hide(); |
2122 | 0 | break; |
2123 | 0 | } |
2124 | 0 | } |
2125 | | |
2126 | 0 | mxPaletteListBox->connect_changed(LINK(this, ColorWindow, SelectPaletteHdl)); |
2127 | 0 | std::vector<OUString> aPaletteList = mxPaletteManager->GetPaletteList(); |
2128 | 0 | mxPaletteListBox->freeze(); |
2129 | 0 | for (const auto& rPalette : aPaletteList) |
2130 | 0 | mxPaletteListBox->append_text(rPalette); |
2131 | 0 | mxPaletteListBox->thaw(); |
2132 | | |
2133 | | // tdf#162104 If the current palette does not exist, select the equivalent to the localized "Standard" palette |
2134 | | // This is required because the names are now localized and in Common.xcs the "Standard" (in English) |
2135 | | // palette is selected by default |
2136 | 0 | OUString aPaletteName(officecfg::Office::Common::UserColors::PaletteName::get()); |
2137 | 0 | auto it = std::find(aPaletteList.begin(), aPaletteList.end(), aPaletteName); |
2138 | 0 | if (it == aPaletteList.end()) |
2139 | 0 | aPaletteName = SvxResId(RID_SVXSTR_COLOR_PALETTE_STANDARD); |
2140 | |
|
2141 | 0 | mxPaletteListBox->set_active_text(aPaletteName); |
2142 | 0 | const int nSelectedEntry(mxPaletteListBox->get_active()); |
2143 | 0 | if (nSelectedEntry != -1) |
2144 | 0 | mxPaletteManager->SetPalette(nSelectedEntry); |
2145 | |
|
2146 | 0 | mxButtonAutoColor->connect_clicked(LINK(this, ColorWindow, AutoColorClickHdl)); |
2147 | 0 | mxButtonNoneColor->connect_clicked(LINK(this, ColorWindow, AutoColorClickHdl)); |
2148 | 0 | mxButtonPicker->connect_clicked(LINK(this, ColorWindow, OpenPickerClickHdl)); |
2149 | |
|
2150 | 0 | mxColorSet->SetSelectHdl(LINK( this, ColorWindow, SelectHdl)); |
2151 | 0 | mxRecentColorSet->SetSelectHdl(LINK( this, ColorWindow, SelectHdl)); |
2152 | 0 | m_xTopLevel->set_help_id(HID_POPUP_COLOR); |
2153 | 0 | mxColorSet->SetHelpId(HID_POPUP_COLOR_CTRL); |
2154 | |
|
2155 | 0 | mxPaletteManager->ReloadColorSet(*mxColorSet); |
2156 | 0 | const sal_uInt32 nMaxItems(SvxColorValueSet::getMaxRowCount() * SvxColorValueSet::getColumnCount()); |
2157 | 0 | Size aSize = mxColorSet->layoutAllVisible(nMaxItems); |
2158 | 0 | mxColorSet->set_size_request(aSize.Width(), aSize.Height()); |
2159 | |
|
2160 | 0 | mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet); |
2161 | 0 | aSize = mxRecentColorSet->layoutAllVisible(mxPaletteManager->GetRecentColorCount()); |
2162 | 0 | mxRecentColorSet->set_size_request(aSize.Width(), aSize.Height()); |
2163 | |
|
2164 | 0 | AddStatusListener( u".uno:ColorTableState"_ustr ); |
2165 | 0 | AddStatusListener( maCommand ); |
2166 | 0 | if ( maCommand == ".uno:FrameLineColor" ) |
2167 | 0 | { |
2168 | 0 | AddStatusListener( u".uno:BorderTLBR"_ustr ); |
2169 | 0 | AddStatusListener( u".uno:BorderBLTR"_ustr ); |
2170 | 0 | } |
2171 | 0 | } |
2172 | | |
2173 | | void ColorWindow::GrabFocus() |
2174 | 0 | { |
2175 | 0 | if (mxColorSet->IsNoSelection() && mpDefaultButton) |
2176 | 0 | mpDefaultButton->grab_focus(); |
2177 | 0 | else |
2178 | 0 | mxColorSet->GrabFocus(); |
2179 | 0 | } |
2180 | | |
2181 | | void ColorWindow::ShowNoneButton() |
2182 | 0 | { |
2183 | 0 | mxButtonNoneColor->show(); |
2184 | 0 | } |
2185 | | |
2186 | | ColorWindow::~ColorWindow() |
2187 | 0 | { |
2188 | 0 | } |
2189 | | |
2190 | | NamedColor ColorWindow::GetSelectEntryColor(ValueSet const * pColorSet) |
2191 | 0 | { |
2192 | 0 | Color aColor = pColorSet->GetItemColor(pColorSet->GetSelectedItemId()); |
2193 | 0 | const OUString& sColorName = pColorSet->GetItemText(pColorSet->GetSelectedItemId()); |
2194 | 0 | return { aColor, sColorName }; |
2195 | 0 | } |
2196 | | |
2197 | | namespace |
2198 | | { |
2199 | | NamedColor GetAutoColor(sal_uInt16 nSlotId) |
2200 | 0 | { |
2201 | 0 | Color aColor; |
2202 | 0 | OUString sColorName; |
2203 | 0 | switch (nSlotId) |
2204 | 0 | { |
2205 | 0 | case SID_ATTR_CHAR_COLOR_BACKGROUND: |
2206 | 0 | case SID_BACKGROUND_COLOR: |
2207 | 0 | case SID_ATTR_CHAR_BACK_COLOR: |
2208 | 0 | case SID_TABLE_CELL_BACKGROUND_COLOR: |
2209 | 0 | aColor = COL_TRANSPARENT; |
2210 | 0 | sColorName = SvxResId(RID_SVXSTR_NOFILL); |
2211 | 0 | break; |
2212 | 0 | case SID_AUTHOR_COLOR: |
2213 | 0 | aColor = COL_TRANSPARENT; |
2214 | 0 | sColorName = SvxResId(RID_SVXSTR_BY_AUTHOR); |
2215 | 0 | break; |
2216 | 0 | case SID_BMPMASK_COLOR: |
2217 | 0 | aColor = COL_TRANSPARENT; |
2218 | 0 | sColorName = SvxResId(RID_SVXSTR_TRANSPARENT); |
2219 | 0 | break; |
2220 | 0 | case SID_FM_CTL_PROPERTIES: |
2221 | 0 | aColor = COL_TRANSPARENT; |
2222 | 0 | sColorName = SvxResId(RID_SVXSTR_DEFAULT); |
2223 | 0 | break; |
2224 | 0 | case SID_ATTR_CHAR_COLOR: |
2225 | 0 | case SID_ATTR_CHAR_COLOR2: |
2226 | 0 | case SID_EXTRUSION_3D_COLOR: |
2227 | 0 | default: |
2228 | 0 | aColor = COL_AUTO; |
2229 | 0 | sColorName = EditResId(RID_SVXSTR_AUTOMATIC); |
2230 | 0 | break; |
2231 | 0 | } |
2232 | | |
2233 | 0 | return {aColor, sColorName}; |
2234 | 0 | } |
2235 | | |
2236 | | NamedColor GetNoneColor() |
2237 | 0 | { |
2238 | 0 | OUString aName = comphelper::LibreOfficeKit::isActive() |
2239 | 0 | ? SvxResId(RID_SVXSTR_INVISIBLE) |
2240 | 0 | : SvxResId(RID_SVXSTR_NONE); |
2241 | 0 | return { COL_NONE_COLOR, aName }; |
2242 | 0 | } |
2243 | | } |
2244 | | |
2245 | | NamedColor ColorWindow::GetSelectEntryColor() const |
2246 | 0 | { |
2247 | 0 | if (!mxColorSet->IsNoSelection()) |
2248 | 0 | return GetSelectEntryColor(mxColorSet.get()); |
2249 | 0 | if (!mxRecentColorSet->IsNoSelection()) |
2250 | 0 | return GetSelectEntryColor(mxRecentColorSet.get()); |
2251 | 0 | if (mxButtonNoneColor.get() == mpDefaultButton) |
2252 | 0 | return GetNoneColor(); |
2253 | 0 | return GetAutoColor(); |
2254 | 0 | } |
2255 | | |
2256 | | IMPL_LINK(ColorWindow, SelectHdl, ValueSet*, pColorSet, void) |
2257 | 0 | { |
2258 | 0 | NamedColor aNamedColor = GetSelectEntryColor(pColorSet); |
2259 | |
|
2260 | 0 | if (pColorSet != mxRecentColorSet.get()) |
2261 | 0 | { |
2262 | 0 | mxPaletteManager->AddRecentColor(aNamedColor.m_aColor, aNamedColor.m_aName); |
2263 | 0 | if (!maMenuButton.get_active()) |
2264 | 0 | mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet); |
2265 | 0 | } |
2266 | |
|
2267 | 0 | mxPaletteManager->SetSplitButtonColor(aNamedColor); |
2268 | | |
2269 | | // deliberate take a copy here in case maMenuButton.set_inactive |
2270 | | // triggers a callback that destroys ourself |
2271 | 0 | ColorSelectFunction aColorSelectFunction(maColorSelectFunction); |
2272 | 0 | OUString sCommand(maCommand); |
2273 | | // Same for querying IsTheme early. |
2274 | 0 | bool bThemePaletteSelected = mxPaletteManager->IsThemePaletteSelected(); |
2275 | 0 | sal_uInt16 nSelectedItemId = pColorSet->GetSelectedItemId(); |
2276 | |
|
2277 | 0 | if (bThemePaletteSelected) |
2278 | 0 | { |
2279 | 0 | sal_uInt16 nThemeIndex; |
2280 | 0 | sal_uInt16 nEffectIndex; |
2281 | 0 | if (PaletteManager::GetThemeAndEffectIndex(nSelectedItemId, nThemeIndex, nEffectIndex)) |
2282 | 0 | { |
2283 | 0 | aNamedColor.m_nThemeIndex = nThemeIndex; |
2284 | 0 | mxPaletteManager->GetLumModOff(nThemeIndex, nEffectIndex, aNamedColor.m_nLumMod, aNamedColor.m_nLumOff); |
2285 | 0 | } |
2286 | 0 | } |
2287 | |
|
2288 | 0 | maMenuButton.set_inactive(); |
2289 | 0 | aColorSelectFunction(sCommand, aNamedColor); |
2290 | 0 | } |
2291 | | |
2292 | | IMPL_LINK_NOARG(ColorWindow, SelectPaletteHdl, weld::ComboBox&, void) |
2293 | 0 | { |
2294 | 0 | int nPos = mxPaletteListBox->get_active(); |
2295 | 0 | mxPaletteManager->SetPalette( nPos ); |
2296 | 0 | mxPaletteManager->ReloadColorSet(*mxColorSet); |
2297 | 0 | mxColorSet->layoutToGivenHeight(mxColorSet->GetOutputSizePixel().Height(), mxPaletteManager->GetColorCount()); |
2298 | 0 | } |
2299 | | |
2300 | | NamedColor ColorWindow::GetAutoColor() const |
2301 | 0 | { |
2302 | 0 | return ::GetAutoColor(mnSlotId); |
2303 | 0 | } |
2304 | | |
2305 | | IMPL_LINK(ColorWindow, AutoColorClickHdl, weld::Button&, rButton, void) |
2306 | 0 | { |
2307 | 0 | NamedColor aNamedColor = &rButton == mxButtonAutoColor.get() ? GetAutoColor() : GetNoneColor(); |
2308 | |
|
2309 | 0 | mxColorSet->SetNoSelection(); |
2310 | 0 | mxRecentColorSet->SetNoSelection(); |
2311 | 0 | mpDefaultButton = &rButton; |
2312 | |
|
2313 | 0 | mxPaletteManager->SetSplitButtonColor(aNamedColor); |
2314 | | |
2315 | | // deliberate take a copy here in case maMenuButton.set_inactive |
2316 | | // triggers a callback that destroys ourself |
2317 | 0 | ColorSelectFunction aColorSelectFunction(maColorSelectFunction); |
2318 | 0 | OUString sCommand(maCommand); |
2319 | |
|
2320 | 0 | maMenuButton.set_inactive(); |
2321 | |
|
2322 | 0 | aColorSelectFunction(sCommand, aNamedColor); |
2323 | 0 | } |
2324 | | |
2325 | | IMPL_LINK_NOARG(ColorWindow, OpenPickerClickHdl, weld::Button&, void) |
2326 | 0 | { |
2327 | | // copy before set_inactive |
2328 | 0 | auto nColor = GetSelectEntryColor().m_aColor; |
2329 | 0 | auto pParentWindow = maTopLevelParentFunction(); |
2330 | 0 | OUString sCommand = maCommand; |
2331 | 0 | std::shared_ptr<PaletteManager> xPaletteManager(mxPaletteManager); |
2332 | |
|
2333 | 0 | maMenuButton.set_inactive(); |
2334 | |
|
2335 | 0 | xPaletteManager->PopupColorPicker(pParentWindow, sCommand, nColor); |
2336 | 0 | } |
2337 | | |
2338 | | void ColorWindow::SetNoSelection() |
2339 | 0 | { |
2340 | 0 | mxColorSet->SetNoSelection(); |
2341 | 0 | mxRecentColorSet->SetNoSelection(); |
2342 | 0 | mpDefaultButton = nullptr; |
2343 | 0 | } |
2344 | | |
2345 | | bool ColorWindow::IsNoSelection() const |
2346 | 0 | { |
2347 | 0 | if (!mxColorSet->IsNoSelection()) |
2348 | 0 | return false; |
2349 | 0 | if (!mxRecentColorSet->IsNoSelection()) |
2350 | 0 | return false; |
2351 | 0 | return !mxButtonAutoColor->get_visible() && !mxButtonNoneColor->get_visible(); |
2352 | 0 | } |
2353 | | |
2354 | | void ColorWindow::statusChanged( const css::frame::FeatureStateEvent& rEvent ) |
2355 | 0 | { |
2356 | 0 | if (rEvent.FeatureURL.Complete == ".uno:ColorTableState") |
2357 | 0 | { |
2358 | 0 | if (rEvent.IsEnabled && mxPaletteManager->GetPalette() == 0) |
2359 | 0 | { |
2360 | 0 | mxPaletteManager->ReloadColorSet(*mxColorSet); |
2361 | 0 | mxColorSet->layoutToGivenHeight(mxColorSet->GetOutputSizePixel().Height(), mxPaletteManager->GetColorCount()); |
2362 | 0 | } |
2363 | 0 | } |
2364 | 0 | else |
2365 | 0 | { |
2366 | 0 | mrColorStatus.statusChanged(rEvent); |
2367 | 0 | SelectEntry(mrColorStatus.GetColor()); |
2368 | 0 | } |
2369 | 0 | } |
2370 | | |
2371 | | bool ColorWindow::SelectValueSetEntry(SvxColorValueSet* pColorSet, const Color& rColor) |
2372 | 0 | { |
2373 | 0 | for (size_t i = 1; i <= pColorSet->GetItemCount(); ++i) |
2374 | 0 | { |
2375 | 0 | if (rColor == pColorSet->GetItemColor(i)) |
2376 | 0 | { |
2377 | 0 | pColorSet->SelectItem(i); |
2378 | 0 | return true; |
2379 | 0 | } |
2380 | 0 | } |
2381 | 0 | return false; |
2382 | 0 | } |
2383 | | |
2384 | | void ColorWindow::SelectEntry(const NamedColor& rNamedColor) |
2385 | 0 | { |
2386 | 0 | SetNoSelection(); |
2387 | |
|
2388 | 0 | const Color &rColor = rNamedColor.m_aColor; |
2389 | |
|
2390 | 0 | if (mxButtonAutoColor->get_visible() && rColor.IsFullyTransparent()) |
2391 | 0 | { |
2392 | 0 | mpDefaultButton = mxButtonAutoColor.get(); |
2393 | 0 | return; |
2394 | 0 | } |
2395 | | |
2396 | 0 | if (mxButtonNoneColor->get_visible() && rColor == COL_NONE_COLOR) |
2397 | 0 | { |
2398 | 0 | mpDefaultButton = mxButtonNoneColor.get(); |
2399 | 0 | return; |
2400 | 0 | } |
2401 | | |
2402 | | // try current palette |
2403 | 0 | bool bFoundColor = SelectValueSetEntry(mxColorSet.get(), rColor); |
2404 | | // try recently used |
2405 | 0 | if (!bFoundColor) |
2406 | 0 | bFoundColor = SelectValueSetEntry(mxRecentColorSet.get(), rColor); |
2407 | | // if it's not there, add it there now to the end of the recently used |
2408 | | // so its available somewhere handy, but not without trashing the |
2409 | | // whole recently used |
2410 | 0 | if (!bFoundColor) |
2411 | 0 | { |
2412 | 0 | const OUString& rColorName = rNamedColor.m_aName; |
2413 | 0 | mxPaletteManager->AddRecentColor(rColor, rColorName, false); |
2414 | 0 | mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet); |
2415 | 0 | SelectValueSetEntry(mxRecentColorSet.get(), rColor); |
2416 | 0 | } |
2417 | 0 | } |
2418 | | |
2419 | | void ColorWindow::SelectEntry(const Color& rColor) |
2420 | 0 | { |
2421 | 0 | OUString sColorName = "#" + rColor.AsRGBHexString().toAsciiUpperCase(); |
2422 | 0 | ColorWindow::SelectEntry({rColor, sColorName}); |
2423 | 0 | } |
2424 | | |
2425 | | ColorStatus::ColorStatus() : |
2426 | 0 | maColor( COL_TRANSPARENT ), |
2427 | 0 | maTLBRColor( COL_TRANSPARENT ), |
2428 | 0 | maBLTRColor( COL_TRANSPARENT ) |
2429 | 0 | { |
2430 | 0 | } |
2431 | | |
2432 | | void ColorStatus::statusChanged( const css::frame::FeatureStateEvent& rEvent ) |
2433 | 0 | { |
2434 | 0 | Color aColor( COL_TRANSPARENT ); |
2435 | 0 | css::table::BorderLine2 aTable; |
2436 | |
|
2437 | 0 | if ( rEvent.State >>= aTable ) |
2438 | 0 | { |
2439 | 0 | SvxBorderLine aLine; |
2440 | 0 | SvxBoxItem::LineToSvxLine( aTable, aLine, false ); |
2441 | 0 | if ( !aLine.isEmpty() ) |
2442 | 0 | aColor = aLine.GetColor(); |
2443 | 0 | } |
2444 | 0 | else |
2445 | 0 | rEvent.State >>= aColor; |
2446 | |
|
2447 | 0 | if ( rEvent.FeatureURL.Path == "BorderTLBR" ) |
2448 | 0 | maTLBRColor = aColor; |
2449 | 0 | else if ( rEvent.FeatureURL.Path == "BorderBLTR" ) |
2450 | 0 | maBLTRColor = aColor; |
2451 | 0 | else |
2452 | 0 | maColor = aColor; |
2453 | 0 | } |
2454 | | |
2455 | | Color ColorStatus::GetColor() |
2456 | 0 | { |
2457 | 0 | Color aColor( maColor ); |
2458 | |
|
2459 | 0 | if ( maTLBRColor != COL_TRANSPARENT ) |
2460 | 0 | { |
2461 | 0 | if ( aColor != maTLBRColor && aColor != COL_TRANSPARENT ) |
2462 | 0 | return COL_TRANSPARENT; |
2463 | 0 | aColor = maTLBRColor; |
2464 | 0 | } |
2465 | | |
2466 | 0 | if ( maBLTRColor != COL_TRANSPARENT ) |
2467 | 0 | { |
2468 | 0 | if ( aColor != maBLTRColor && aColor != COL_TRANSPARENT ) |
2469 | 0 | return COL_TRANSPARENT; |
2470 | 0 | return maBLTRColor; |
2471 | 0 | } |
2472 | | |
2473 | 0 | return aColor; |
2474 | 0 | } |
2475 | | |
2476 | | |
2477 | | SvxFrameWindow_Impl::SvxFrameWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent) |
2478 | 0 | : WeldToolbarPopup(pControl->getFrameInterface(), pParent, u"svx/ui/floatingframeborder.ui"_ustr, u"FloatingFrameBorder"_ustr) |
2479 | 0 | , mxControl(pControl) |
2480 | 0 | , mxFrameSet(new SvxFrmValueSet_Impl) |
2481 | 0 | , mxFrameSetWin(new weld::CustomWeld(*m_xBuilder, u"valueset"_ustr, *mxFrameSet)) |
2482 | 0 | , bParagraphMode(false) |
2483 | 0 | , m_bIsWriter(false) |
2484 | 0 | , m_bIsCalc(false) |
2485 | 0 | { |
2486 | | |
2487 | | // check whether the document is Writer or not |
2488 | | // check also if it's Calc or not |
2489 | 0 | if (Reference<lang::XServiceInfo> xSI{ m_xFrame->getController()->getModel(), UNO_QUERY }) |
2490 | 0 | { |
2491 | 0 | m_bIsWriter = xSI->supportsService(u"com.sun.star.text.TextDocument"_ustr); |
2492 | 0 | m_bIsCalc = xSI->supportsService(u"com.sun.star.sheet.SpreadsheetDocument"_ustr); |
2493 | 0 | } |
2494 | |
|
2495 | 0 | mxFrameSet->SetStyle(WB_ITEMBORDER | WB_DOUBLEBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT); |
2496 | 0 | AddStatusListener(u".uno:BorderReducedMode"_ustr); |
2497 | 0 | InitImageList(); |
2498 | | |
2499 | | /* |
2500 | | * 1 2 3 4 5 |
2501 | | * ------------------------------------------------------ |
2502 | | * NONE LEFT RIGHT LEFTRIGHT DIAGONALDOWN |
2503 | | * TOP BOTTOM TOPBOTTOM OUTER DIAGONALUP |
2504 | | * ------------------------------------------------------ |
2505 | | * HOR HORINNER VERINNER ALL CRISSCROSS <- can be switched of via bParagraphMode |
2506 | | */ |
2507 | |
|
2508 | 0 | sal_uInt16 i = 0; |
2509 | | |
2510 | | // diagonal borders available only for Calc. |
2511 | | // Therefore, Calc uses 10 border types while |
2512 | | // Writer uses 8 of them - for a single cell. |
2513 | 0 | for ( i=1; i < (m_bIsCalc ? 11 : 9); i++ ) |
2514 | 0 | mxFrameSet->InsertItem(i, Image(aImgVec[i-1].first), aImgVec[i-1].second); |
2515 | | |
2516 | | //bParagraphMode should have been set in StateChanged |
2517 | 0 | if ( !bParagraphMode ) |
2518 | | // when multiple cell selected: |
2519 | | // Writer has 12 border types and Calc has 15 of them. |
2520 | 0 | for ( i = (m_bIsCalc ? 11 : 9); i < (m_bIsCalc ? 16 : 13); i++ ) |
2521 | 0 | mxFrameSet->InsertItem(i, Image(aImgVec[i-1].first), aImgVec[i-1].second); |
2522 | | |
2523 | | // adjust frame column for Writer |
2524 | 0 | sal_uInt16 colCount = m_bIsWriter ? 4 : 5; |
2525 | 0 | mxFrameSet->SetColCount( colCount ); |
2526 | 0 | mxFrameSet->SetSelectHdl( LINK( this, SvxFrameWindow_Impl, SelectHdl ) ); |
2527 | 0 | CalcSizeValueSet(); |
2528 | |
|
2529 | 0 | mxFrameSet->SetHelpId( HID_POPUP_FRAME ); |
2530 | 0 | mxFrameSet->SetAccessibleName( SvxResId(RID_SVXSTR_FRAME) ); |
2531 | 0 | } |
2532 | | |
2533 | | namespace { |
2534 | | |
2535 | | enum class FrmValidFlags { |
2536 | | NONE = 0x00, |
2537 | | Left = 0x01, |
2538 | | Right = 0x02, |
2539 | | Top = 0x04, |
2540 | | Bottom = 0x08, |
2541 | | HInner = 0x10, |
2542 | | VInner = 0x20, |
2543 | | AllMask = 0x3f, |
2544 | | }; |
2545 | | |
2546 | | } |
2547 | | |
2548 | | namespace o3tl { |
2549 | | template<> struct typed_flags<FrmValidFlags> : is_typed_flags<FrmValidFlags, 0x3f> {}; |
2550 | | } |
2551 | | |
2552 | | // By default unset lines remain unchanged. |
2553 | | // Via Shift unset lines are reset |
2554 | | |
2555 | | IMPL_LINK_NOARG(SvxFrameWindow_Impl, SelectHdl, ValueSet*, void) |
2556 | 0 | { |
2557 | 0 | SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER ); |
2558 | 0 | SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER ); |
2559 | 0 | SvxBorderLine theDefLine; |
2560 | | |
2561 | | // diagonal down border |
2562 | 0 | SvxBorderLine dDownBorderLine(nullptr, SvxBorderLineWidth::Hairline); |
2563 | 0 | SvxLineItem dDownLineItem(SID_ATTR_BORDER_DIAG_TLBR); |
2564 | | |
2565 | | // diagonal up border |
2566 | 0 | SvxBorderLine dUpBorderLine(nullptr, SvxBorderLineWidth::Hairline); |
2567 | 0 | SvxLineItem dUpLineItem(SID_ATTR_BORDER_DIAG_BLTR); |
2568 | |
|
2569 | 0 | bool bIsDiagonalBorder = false; |
2570 | |
|
2571 | 0 | SvxBorderLine *pLeft = nullptr, |
2572 | 0 | *pRight = nullptr, |
2573 | 0 | *pTop = nullptr, |
2574 | 0 | *pBottom = nullptr; |
2575 | 0 | sal_uInt16 nSel = mxFrameSet->GetSelectedItemId(); |
2576 | 0 | sal_uInt16 nModifier = mxFrameSet->GetModifier(); |
2577 | 0 | FrmValidFlags nValidFlags = FrmValidFlags::NONE; |
2578 | | |
2579 | | // tdf#48622, tdf#145828 use correct default to create intended 0.75pt |
2580 | | // cell border using the border formatting tool in the standard toolbar |
2581 | 0 | theDefLine.GuessLinesWidths(theDefLine.GetBorderLineStyle(), SvxBorderLineWidth::Thin); |
2582 | | |
2583 | | // nSel has 15 cases which means 15 border |
2584 | | // types for Calc. But Writer uses only 12 |
2585 | | // of them - when diagonal borders excluded. |
2586 | 0 | if (!m_bIsCalc) |
2587 | 0 | { |
2588 | | // add appropriate increments |
2589 | | // to match the correct borders. |
2590 | 0 | if (nSel > 8) { nSel += 2; } |
2591 | 0 | else if (nSel > 4) { nSel++; } |
2592 | 0 | } |
2593 | |
|
2594 | 0 | switch ( nSel ) |
2595 | 0 | { |
2596 | 0 | case 1: nValidFlags |= FrmValidFlags::AllMask; |
2597 | | // set nullptr to remove diagonal lines |
2598 | 0 | dDownLineItem.SetLine(nullptr); |
2599 | 0 | dUpLineItem.SetLine(nullptr); |
2600 | 0 | SetDiagonalDownBorder(dDownLineItem); |
2601 | 0 | SetDiagonalUpBorder(dUpLineItem); |
2602 | 0 | break; // NONE |
2603 | 0 | case 2: pLeft = &theDefLine; |
2604 | 0 | nValidFlags |= FrmValidFlags::Left; |
2605 | 0 | break; // LEFT |
2606 | 0 | case 3: pRight = &theDefLine; |
2607 | 0 | nValidFlags |= FrmValidFlags::Right; |
2608 | 0 | break; // RIGHT |
2609 | 0 | case 4: pLeft = pRight = &theDefLine; |
2610 | 0 | nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left; |
2611 | 0 | break; // LEFTRIGHT |
2612 | 0 | case 5: dDownLineItem.SetLine(&dDownBorderLine); |
2613 | 0 | SetDiagonalDownBorder(dDownLineItem); |
2614 | 0 | bIsDiagonalBorder = true; |
2615 | 0 | break; // DIAGONAL DOWN |
2616 | 0 | case 6: pTop = &theDefLine; |
2617 | 0 | nValidFlags |= FrmValidFlags::Top; |
2618 | 0 | break; // TOP |
2619 | 0 | case 7: pBottom = &theDefLine; |
2620 | 0 | nValidFlags |= FrmValidFlags::Bottom; |
2621 | 0 | break; // BOTTOM |
2622 | 0 | case 8: pTop = pBottom = &theDefLine; |
2623 | 0 | nValidFlags |= FrmValidFlags::Bottom|FrmValidFlags::Top; |
2624 | 0 | break; // TOPBOTTOM |
2625 | 0 | case 9: pLeft = pRight = pTop = pBottom = &theDefLine; |
2626 | 0 | nValidFlags |= FrmValidFlags::Left | FrmValidFlags::Right | FrmValidFlags::Top | FrmValidFlags::Bottom; |
2627 | 0 | break; // OUTER |
2628 | 0 | case 10: |
2629 | 0 | dUpLineItem.SetLine(&dUpBorderLine); |
2630 | 0 | SetDiagonalUpBorder(dUpLineItem); |
2631 | 0 | bIsDiagonalBorder = true; |
2632 | 0 | break; // DIAGONAL UP |
2633 | | |
2634 | | // Inner Table: |
2635 | 0 | case 11: // HOR |
2636 | 0 | pTop = pBottom = &theDefLine; |
2637 | 0 | aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI ); |
2638 | 0 | aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::VERT ); |
2639 | 0 | nValidFlags |= FrmValidFlags::HInner|FrmValidFlags::Top|FrmValidFlags::Bottom; |
2640 | 0 | break; |
2641 | | |
2642 | 0 | case 12: // HORINNER |
2643 | 0 | pLeft = pRight = pTop = pBottom = &theDefLine; |
2644 | 0 | aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI ); |
2645 | 0 | aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::VERT ); |
2646 | 0 | nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left|FrmValidFlags::HInner|FrmValidFlags::Top|FrmValidFlags::Bottom; |
2647 | 0 | break; |
2648 | | |
2649 | 0 | case 13: // VERINNER |
2650 | 0 | pLeft = pRight = pTop = pBottom = &theDefLine; |
2651 | 0 | aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::HORI ); |
2652 | 0 | aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT ); |
2653 | 0 | nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left|FrmValidFlags::VInner|FrmValidFlags::Top|FrmValidFlags::Bottom; |
2654 | 0 | break; |
2655 | | |
2656 | 0 | case 14: // ALL |
2657 | 0 | pLeft = pRight = pTop = pBottom = &theDefLine; |
2658 | 0 | aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI ); |
2659 | 0 | aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT ); |
2660 | 0 | nValidFlags |= FrmValidFlags::AllMask; |
2661 | 0 | break; |
2662 | | |
2663 | 0 | case 15: |
2664 | | // set both diagonal lines to draw criss-cross line |
2665 | 0 | dDownLineItem.SetLine(&dDownBorderLine); |
2666 | 0 | dUpLineItem.SetLine(&dUpBorderLine); |
2667 | |
|
2668 | 0 | SetDiagonalDownBorder(dDownLineItem); |
2669 | 0 | SetDiagonalUpBorder(dUpLineItem); |
2670 | 0 | bIsDiagonalBorder = true; |
2671 | 0 | break; // CRISS-CROSS |
2672 | | |
2673 | 0 | default: |
2674 | 0 | break; |
2675 | 0 | } |
2676 | | |
2677 | | // if diagonal borders selected, |
2678 | | // no need to execute this block |
2679 | 0 | if (!bIsDiagonalBorder) |
2680 | 0 | { |
2681 | 0 | aBorderOuter.SetLine( pLeft, SvxBoxItemLine::LEFT ); |
2682 | 0 | aBorderOuter.SetLine( pRight, SvxBoxItemLine::RIGHT ); |
2683 | 0 | aBorderOuter.SetLine( pTop, SvxBoxItemLine::TOP ); |
2684 | 0 | aBorderOuter.SetLine( pBottom, SvxBoxItemLine::BOTTOM ); |
2685 | |
|
2686 | 0 | if(nModifier == KEY_SHIFT) |
2687 | 0 | nValidFlags |= FrmValidFlags::AllMask; |
2688 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP, bool(nValidFlags&FrmValidFlags::Top )); |
2689 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, bool(nValidFlags&FrmValidFlags::Bottom )); |
2690 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, bool(nValidFlags&FrmValidFlags::Left)); |
2691 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, bool(nValidFlags&FrmValidFlags::Right )); |
2692 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI, bool(nValidFlags&FrmValidFlags::HInner )); |
2693 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT, bool(nValidFlags&FrmValidFlags::VInner)); |
2694 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE ); |
2695 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false ); |
2696 | |
|
2697 | 0 | Any a1, a2; |
2698 | 0 | aBorderOuter.QueryValue( a1 ); |
2699 | 0 | aBorderInner.QueryValue( a2 ); |
2700 | 0 | Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(u"OuterBorder"_ustr, a1), |
2701 | 0 | comphelper::makePropertyValue(u"InnerBorder"_ustr, a2) }; |
2702 | |
|
2703 | 0 | mxControl->dispatchCommand( u".uno:SetBorderStyle"_ustr, aArgs ); |
2704 | 0 | } |
2705 | | |
2706 | | // coverity[ check_after_deref : FALSE] |
2707 | 0 | if (mxFrameSet) |
2708 | 0 | { |
2709 | | /* #i33380# Moved the following line above the Dispatch() call. |
2710 | | This instance may be deleted in the meantime (i.e. when a dialog is opened |
2711 | | while in Dispatch()), accessing members will crash in this case. */ |
2712 | 0 | mxFrameSet->SetNoSelection(); |
2713 | 0 | } |
2714 | |
|
2715 | 0 | mxControl->EndPopupMode(); |
2716 | 0 | } |
2717 | | |
2718 | | void SvxFrameWindow_Impl::SetDiagonalDownBorder(const SvxLineItem& dDownLineItem) |
2719 | 0 | { |
2720 | | // apply diagonal down border |
2721 | 0 | Any a; |
2722 | 0 | dDownLineItem.QueryValue(a); |
2723 | 0 | Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue(u"BorderTLBR"_ustr, a) }; |
2724 | |
|
2725 | 0 | mxControl->dispatchCommand(u".uno:BorderTLBR"_ustr, aArgs); |
2726 | 0 | } |
2727 | | |
2728 | | void SvxFrameWindow_Impl::SetDiagonalUpBorder(const SvxLineItem& dUpLineItem) |
2729 | 0 | { |
2730 | | // apply diagonal up border |
2731 | 0 | Any a; |
2732 | 0 | dUpLineItem.QueryValue(a); |
2733 | 0 | Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue(u"BorderBLTR"_ustr, a) }; |
2734 | |
|
2735 | 0 | mxControl->dispatchCommand(u".uno:BorderBLTR"_ustr, aArgs); |
2736 | 0 | } |
2737 | | |
2738 | | void SvxFrameWindow_Impl::statusChanged( const css::frame::FeatureStateEvent& rEvent ) |
2739 | 0 | { |
2740 | 0 | if ( rEvent.FeatureURL.Complete != ".uno:BorderReducedMode" ) |
2741 | 0 | return; |
2742 | | |
2743 | 0 | bool bValue; |
2744 | 0 | if ( !(rEvent.State >>= bValue) ) |
2745 | 0 | return; |
2746 | | |
2747 | 0 | bParagraphMode = bValue; |
2748 | | //initial calls mustn't insert or remove elements |
2749 | 0 | if(!mxFrameSet->GetItemCount()) |
2750 | 0 | return; |
2751 | | |
2752 | | // set 12 border types for Writer, otherwise 15 for Calc. |
2753 | 0 | bool bTableMode = ( mxFrameSet->GetItemCount() == static_cast<size_t>(m_bIsCalc ? 15 : 12) ); |
2754 | 0 | bool bResize = false; |
2755 | |
|
2756 | 0 | if ( bTableMode && bParagraphMode ) |
2757 | 0 | { |
2758 | 0 | for ( sal_uInt16 i = (m_bIsWriter ? 9 : 11); i < (m_bIsWriter ? 13 : 16); i++ ) |
2759 | 0 | mxFrameSet->RemoveItem(i); |
2760 | 0 | bResize = true; |
2761 | 0 | } |
2762 | 0 | else if ( !bTableMode && !bParagraphMode ) |
2763 | 0 | { |
2764 | 0 | for ( sal_uInt16 i = (m_bIsWriter ? 9 : 11); i < (m_bIsWriter ? 13 : 16); i++ ) |
2765 | 0 | mxFrameSet->InsertItem(i, Image(aImgVec[i-1].first), aImgVec[i-1].second); |
2766 | 0 | bResize = true; |
2767 | 0 | } |
2768 | |
|
2769 | 0 | if ( bResize ) |
2770 | 0 | { |
2771 | 0 | CalcSizeValueSet(); |
2772 | 0 | } |
2773 | 0 | } |
2774 | | |
2775 | | void SvxFrameWindow_Impl::CalcSizeValueSet() |
2776 | 0 | { |
2777 | 0 | weld::DrawingArea* pDrawingArea = mxFrameSet->GetDrawingArea(); |
2778 | 0 | const OutputDevice& rDevice = pDrawingArea->get_ref_device(); |
2779 | 0 | Size aItemSize( 20 * rDevice.GetDPIScaleFactor(), 20 * rDevice.GetDPIScaleFactor() ); |
2780 | 0 | Size aSize = mxFrameSet->CalcWindowSizePixel( aItemSize ); |
2781 | 0 | pDrawingArea->set_size_request(aSize.Width(), aSize.Height()); |
2782 | 0 | mxFrameSet->SetOutputSizePixel(aSize); |
2783 | 0 | } |
2784 | | |
2785 | | void SvxFrameWindow_Impl::InitImageList() |
2786 | 0 | { |
2787 | 0 | if (!m_bIsCalc) |
2788 | 0 | { |
2789 | | // not Writer/Impress/Draw-specific aImgVec. |
2790 | | // Since they don't have diagonal borders, |
2791 | | // we have to use 12 border types here. |
2792 | 0 | aImgVec = { |
2793 | 0 | {BitmapEx(RID_SVXBMP_FRAME1), SvxResId(RID_SVXSTR_TABLE_PRESET_NONE)}, |
2794 | 0 | {BitmapEx(RID_SVXBMP_FRAME2), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYLEFT)}, |
2795 | 0 | {BitmapEx(RID_SVXBMP_FRAME3), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYRIGHT)}, |
2796 | 0 | {BitmapEx(RID_SVXBMP_FRAME4), SvxResId(RID_SVXSTR_PARA_PRESET_LEFTRIGHT)}, |
2797 | |
|
2798 | 0 | {BitmapEx(RID_SVXBMP_FRAME5), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTOP)}, |
2799 | 0 | {BitmapEx(RID_SVXBMP_FRAME6), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYBOTTOM)}, |
2800 | 0 | {BitmapEx(RID_SVXBMP_FRAME7), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOM)}, |
2801 | 0 | {BitmapEx(RID_SVXBMP_FRAME8), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTER)}, |
2802 | |
|
2803 | 0 | {BitmapEx(RID_SVXBMP_FRAME9), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOMHORI)}, |
2804 | 0 | {BitmapEx(RID_SVXBMP_FRAME10), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERHORI)}, |
2805 | 0 | {BitmapEx(RID_SVXBMP_FRAME11), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERVERI)}, |
2806 | 0 | {BitmapEx(RID_SVXBMP_FRAME12), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERALL)} |
2807 | 0 | }; |
2808 | 0 | } |
2809 | 0 | else |
2810 | 0 | { |
2811 | | // Calc has diagonal borders feature. |
2812 | | // Therefore use additional 3 diagonal border types, |
2813 | | // which make border types 15 in total. |
2814 | 0 | aImgVec = { |
2815 | 0 | {BitmapEx(RID_SVXBMP_FRAME1), SvxResId(RID_SVXSTR_TABLE_PRESET_NONE)}, |
2816 | 0 | {BitmapEx(RID_SVXBMP_FRAME2), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYLEFT)}, |
2817 | 0 | {BitmapEx(RID_SVXBMP_FRAME3), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYRIGHT)}, |
2818 | 0 | {BitmapEx(RID_SVXBMP_FRAME4), SvxResId(RID_SVXSTR_PARA_PRESET_LEFTRIGHT)}, |
2819 | 0 | {BitmapEx(RID_SVXBMP_FRAME14), SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALDOWN)}, // diagonal down border |
2820 | |
|
2821 | 0 | {BitmapEx(RID_SVXBMP_FRAME5), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTOP)}, |
2822 | 0 | {BitmapEx(RID_SVXBMP_FRAME6), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYBOTTOM)}, |
2823 | 0 | {BitmapEx(RID_SVXBMP_FRAME7), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOM)}, |
2824 | 0 | {BitmapEx(RID_SVXBMP_FRAME8), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTER)}, |
2825 | 0 | {BitmapEx(RID_SVXBMP_FRAME13), SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALUP)}, // diagonal up border |
2826 | |
|
2827 | 0 | {BitmapEx(RID_SVXBMP_FRAME9), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOMHORI)}, |
2828 | 0 | {BitmapEx(RID_SVXBMP_FRAME10), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERHORI)}, |
2829 | 0 | {BitmapEx(RID_SVXBMP_FRAME11), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERVERI)}, |
2830 | 0 | {BitmapEx(RID_SVXBMP_FRAME12), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERALL)}, |
2831 | 0 | {BitmapEx(RID_SVXBMP_FRAME15), SvxResId(RID_SVXSTR_PARA_PRESET_CRISSCROSS)} // criss-cross border |
2832 | 0 | }; |
2833 | 0 | } |
2834 | 0 | } |
2835 | | |
2836 | | static Color lcl_mediumColor( Color aMain, Color /*aDefault*/ ) |
2837 | 0 | { |
2838 | 0 | return SvxBorderLine::threeDMediumColor( aMain ); |
2839 | 0 | } |
2840 | | |
2841 | | SvxLineWindow_Impl::SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent) |
2842 | 0 | : WeldToolbarPopup(pControl->getFrameInterface(), pParent, u"svx/ui/floatingframeborder.ui"_ustr, u"FloatingFrameBorder"_ustr) |
2843 | 0 | , m_xControl(pControl) |
2844 | 0 | , m_xLineStyleLb(new LineListBox) |
2845 | 0 | , m_xLineStyleLbWin(new weld::CustomWeld(*m_xBuilder, u"valueset"_ustr, *m_xLineStyleLb)) |
2846 | 0 | , m_bIsWriter(false) |
2847 | 0 | { |
2848 | 0 | try |
2849 | 0 | { |
2850 | 0 | Reference< lang::XServiceInfo > xServices(m_xFrame->getController()->getModel(), UNO_QUERY); |
2851 | 0 | if (xServices) |
2852 | 0 | m_bIsWriter = xServices->supportsService(u"com.sun.star.text.TextDocument"_ustr); |
2853 | 0 | } |
2854 | 0 | catch(const uno::Exception& ) |
2855 | 0 | { |
2856 | 0 | } |
2857 | |
|
2858 | 0 | m_xLineStyleLb->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) ); |
2859 | |
|
2860 | 0 | m_xLineStyleLb->SetSourceUnit( FieldUnit::TWIP ); |
2861 | 0 | m_xLineStyleLb->SetNone( comphelper::LibreOfficeKit::isActive() ? SvxResId(RID_SVXSTR_INVISIBLE) |
2862 | 0 | :SvxResId(RID_SVXSTR_NONE) ); |
2863 | |
|
2864 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::SOLID ), SvxBorderLineStyle::SOLID ); |
2865 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DOTTED ), SvxBorderLineStyle::DOTTED ); |
2866 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DASHED ), SvxBorderLineStyle::DASHED ); |
2867 | | |
2868 | | // Double lines |
2869 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DOUBLE ), SvxBorderLineStyle::DOUBLE ); |
2870 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_SMALLGAP ), SvxBorderLineStyle::THINTHICK_SMALLGAP, 20 ); |
2871 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_MEDIUMGAP ), SvxBorderLineStyle::THINTHICK_MEDIUMGAP ); |
2872 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_LARGEGAP ), SvxBorderLineStyle::THINTHICK_LARGEGAP ); |
2873 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_SMALLGAP ), SvxBorderLineStyle::THICKTHIN_SMALLGAP, 20 ); |
2874 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_MEDIUMGAP ), SvxBorderLineStyle::THICKTHIN_MEDIUMGAP ); |
2875 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_LARGEGAP ), SvxBorderLineStyle::THICKTHIN_LARGEGAP ); |
2876 | | |
2877 | | // Engraved / Embossed |
2878 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::EMBOSSED ), SvxBorderLineStyle::EMBOSSED, 15, |
2879 | 0 | &SvxBorderLine::threeDLightColor, &SvxBorderLine::threeDDarkColor, |
2880 | 0 | &lcl_mediumColor ); |
2881 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::ENGRAVED ), SvxBorderLineStyle::ENGRAVED, 15, |
2882 | 0 | &SvxBorderLine::threeDDarkColor, &SvxBorderLine::threeDLightColor, |
2883 | 0 | &lcl_mediumColor ); |
2884 | | |
2885 | | // Inset / Outset |
2886 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::OUTSET ), SvxBorderLineStyle::OUTSET, 10, |
2887 | 0 | &SvxBorderLine::lightColor, &SvxBorderLine::darkColor ); |
2888 | 0 | m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::INSET ), SvxBorderLineStyle::INSET, 10, |
2889 | 0 | &SvxBorderLine::darkColor, &SvxBorderLine::lightColor ); |
2890 | 0 | Size aSize = m_xLineStyleLb->SetWidth( 20 ); // 1pt by default |
2891 | |
|
2892 | 0 | m_xLineStyleLb->SetSelectHdl( LINK( this, SvxLineWindow_Impl, SelectHdl ) ); |
2893 | |
|
2894 | 0 | m_xContainer->set_help_id(HID_POPUP_LINE); |
2895 | |
|
2896 | 0 | aSize.AdjustWidth(6); |
2897 | 0 | aSize.AdjustHeight(6); |
2898 | 0 | aSize = m_xLineStyleLb->CalcWindowSizePixel(aSize); |
2899 | 0 | m_xLineStyleLb->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height()); |
2900 | 0 | m_xLineStyleLb->SetOutputSizePixel(aSize); |
2901 | 0 | } |
2902 | | |
2903 | | IMPL_LINK_NOARG(SvxLineWindow_Impl, SelectHdl, ValueSet*, void) |
2904 | 0 | { |
2905 | 0 | SvxLineItem aLineItem( SID_FRAME_LINESTYLE ); |
2906 | 0 | SvxBorderLineStyle nStyle = m_xLineStyleLb->GetSelectEntryStyle(); |
2907 | |
|
2908 | 0 | if ( m_xLineStyleLb->GetSelectItemPos( ) > 0 ) |
2909 | 0 | { |
2910 | 0 | SvxBorderLine aTmp; |
2911 | 0 | aTmp.SetBorderLineStyle( nStyle ); |
2912 | 0 | aTmp.SetWidth( SvxBorderLineWidth::Thin ); // TODO Make it depend on a width field |
2913 | 0 | aLineItem.SetLine( &aTmp ); |
2914 | 0 | } |
2915 | 0 | else |
2916 | 0 | aLineItem.SetLine( nullptr ); |
2917 | |
|
2918 | 0 | Any a; |
2919 | 0 | aLineItem.QueryValue( a, m_bIsWriter ? CONVERT_TWIPS : 0 ); |
2920 | 0 | Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(u"LineStyle"_ustr, a) }; |
2921 | |
|
2922 | 0 | m_xControl->dispatchCommand( u".uno:LineStyle"_ustr, aArgs ); |
2923 | |
|
2924 | 0 | m_xControl->EndPopupMode(); |
2925 | 0 | } |
2926 | | |
2927 | | SfxStyleControllerItem_Impl::SfxStyleControllerItem_Impl( |
2928 | | const Reference< XDispatchProvider >& rDispatchProvider, |
2929 | | sal_uInt16 nSlotId, // Family-ID |
2930 | | const OUString& rCommand, // .uno: command bound to this item |
2931 | | SvxStyleToolBoxControl& rTbxCtl ) // controller instance, which the item is assigned to. |
2932 | 0 | : SfxStatusListener( rDispatchProvider, nSlotId, rCommand ), |
2933 | 0 | rControl( rTbxCtl ) |
2934 | 0 | { |
2935 | 0 | } |
2936 | | |
2937 | | void SfxStyleControllerItem_Impl::StateChangedAtStatusListener( |
2938 | | SfxItemState eState, const SfxPoolItem* pState ) |
2939 | 0 | { |
2940 | 0 | switch ( GetId() ) |
2941 | 0 | { |
2942 | 0 | case SID_STYLE_FAMILY1: |
2943 | 0 | case SID_STYLE_FAMILY2: |
2944 | 0 | case SID_STYLE_FAMILY3: |
2945 | 0 | case SID_STYLE_FAMILY4: |
2946 | 0 | case SID_STYLE_FAMILY5: |
2947 | 0 | { |
2948 | 0 | const sal_uInt16 nIdx = GetId() - SID_STYLE_FAMILY_START; |
2949 | |
|
2950 | 0 | if ( SfxItemState::DEFAULT == eState ) |
2951 | 0 | { |
2952 | 0 | const SfxTemplateItem* pStateItem = |
2953 | 0 | dynamic_cast<const SfxTemplateItem*>( pState ); |
2954 | 0 | DBG_ASSERT( pStateItem != nullptr, "SfxTemplateItem expected" ); |
2955 | 0 | rControl.SetFamilyState( nIdx, pStateItem ); |
2956 | 0 | } |
2957 | 0 | else |
2958 | 0 | rControl.SetFamilyState( nIdx, nullptr ); |
2959 | 0 | break; |
2960 | 0 | } |
2961 | 0 | } |
2962 | 0 | } |
2963 | | |
2964 | | struct SvxStyleToolBoxControl::Impl |
2965 | | { |
2966 | | OUString aClearForm; |
2967 | | OUString aMore; |
2968 | | ::std::vector< std::pair< OUString, OUString > > aDefaultStyles; |
2969 | | bool bSpecModeWriter; |
2970 | | bool bSpecModeCalc; |
2971 | | |
2972 | | VclPtr<SvxStyleBox_Impl> m_xVclBox; |
2973 | | std::unique_ptr<SvxStyleBox_Base> m_xWeldBox; |
2974 | | SvxStyleBox_Base* m_pBox; |
2975 | | |
2976 | | Impl() |
2977 | 0 | :aClearForm ( SvxResId( RID_SVXSTR_CLEARFORM ) ) |
2978 | 0 | ,aMore ( SvxResId( RID_SVXSTR_MORE_STYLES ) ) |
2979 | 0 | ,bSpecModeWriter ( false ) |
2980 | 0 | ,bSpecModeCalc ( false ) |
2981 | 0 | ,m_pBox ( nullptr ) |
2982 | 0 | { |
2983 | | |
2984 | |
|
2985 | 0 | } |
2986 | | void InitializeStyles(const Reference < frame::XModel >& xModel) |
2987 | 0 | { |
2988 | 0 | aDefaultStyles.clear(); |
2989 | | |
2990 | | //now convert the default style names to the localized names |
2991 | 0 | try |
2992 | 0 | { |
2993 | 0 | Reference< style::XStyleFamiliesSupplier > xStylesSupplier( xModel, UNO_QUERY_THROW ); |
2994 | 0 | Reference< lang::XServiceInfo > xServices( xModel, UNO_QUERY_THROW ); |
2995 | 0 | bSpecModeWriter = xServices->supportsService(u"com.sun.star.text.TextDocument"_ustr); |
2996 | 0 | if(bSpecModeWriter) |
2997 | 0 | { |
2998 | 0 | Reference<container::XNameAccess> xParaStyles; |
2999 | 0 | xStylesSupplier->getStyleFamilies()->getByName(u"ParagraphStyles"_ustr) >>= |
3000 | 0 | xParaStyles; |
3001 | 0 | static constexpr OUString aWriterStyles[] |
3002 | 0 | { |
3003 | 0 | u"Standard"_ustr, |
3004 | 0 | u"Text body"_ustr, |
3005 | 0 | u"Title"_ustr, |
3006 | 0 | u"Subtitle"_ustr, |
3007 | 0 | u"Heading 1"_ustr, |
3008 | 0 | u"Heading 2"_ustr, |
3009 | 0 | u"Heading 3"_ustr, |
3010 | 0 | u"Heading 4"_ustr, |
3011 | 0 | u"Quotations"_ustr, |
3012 | 0 | u"Preformatted Text"_ustr |
3013 | 0 | }; |
3014 | 0 | for( const OUString& aStyle: aWriterStyles ) |
3015 | 0 | { |
3016 | 0 | try |
3017 | 0 | { |
3018 | 0 | Reference< beans::XPropertySet > xStyle; |
3019 | 0 | xParaStyles->getByName( aStyle ) >>= xStyle; |
3020 | 0 | OUString sName; |
3021 | 0 | xStyle->getPropertyValue(u"DisplayName"_ustr) >>= sName; |
3022 | 0 | if( !sName.isEmpty() ) |
3023 | 0 | aDefaultStyles.push_back( |
3024 | 0 | std::pair<OUString, OUString>(aStyle, sName) ); |
3025 | 0 | } |
3026 | 0 | catch( const uno::Exception& ) |
3027 | 0 | {} |
3028 | 0 | } |
3029 | |
|
3030 | 0 | } |
3031 | 0 | else if( ( |
3032 | 0 | bSpecModeCalc = xServices->supportsService( |
3033 | 0 | u"com.sun.star.sheet.SpreadsheetDocument"_ustr))) |
3034 | 0 | { |
3035 | 0 | static constexpr OUString aCalcStyles[] |
3036 | 0 | { |
3037 | 0 | u"Default"_ustr, |
3038 | 0 | u"Accent 1"_ustr, |
3039 | 0 | u"Accent 2"_ustr, |
3040 | 0 | u"Accent 3"_ustr, |
3041 | 0 | u"Heading 1"_ustr, |
3042 | 0 | u"Heading 2"_ustr, |
3043 | 0 | u"Result"_ustr |
3044 | 0 | }; |
3045 | 0 | Reference<container::XNameAccess> xCellStyles; |
3046 | 0 | xStylesSupplier->getStyleFamilies()->getByName(u"CellStyles"_ustr) >>= xCellStyles; |
3047 | 0 | for(const OUString & sStyleName : aCalcStyles) |
3048 | 0 | { |
3049 | 0 | try |
3050 | 0 | { |
3051 | 0 | if( xCellStyles->hasByName( sStyleName ) ) |
3052 | 0 | { |
3053 | 0 | Reference< beans::XPropertySet > xStyle( xCellStyles->getByName( sStyleName), UNO_QUERY_THROW ); |
3054 | 0 | OUString sName; |
3055 | 0 | xStyle->getPropertyValue(u"DisplayName"_ustr) >>= sName; |
3056 | 0 | if( !sName.isEmpty() ) |
3057 | 0 | aDefaultStyles.push_back( |
3058 | 0 | std::pair<OUString, OUString>(sStyleName, sName) ); |
3059 | 0 | } |
3060 | 0 | } |
3061 | 0 | catch( const uno::Exception& ) |
3062 | 0 | {} |
3063 | 0 | } |
3064 | 0 | } |
3065 | 0 | } |
3066 | 0 | catch(const uno::Exception& ) |
3067 | 0 | { |
3068 | 0 | OSL_FAIL("error while initializing style names"); |
3069 | 0 | } |
3070 | 0 | } |
3071 | | }; |
3072 | | |
3073 | | // mapping table from bound items. BE CAREFUL this table must be in the |
3074 | | // same order as the uno commands bound to the slots SID_STYLE_FAMILY1..n |
3075 | | // MAX_FAMILIES must also be correctly set! |
3076 | | constexpr OUString StyleSlotToStyleCommand[MAX_FAMILIES] = |
3077 | | { |
3078 | | u".uno:CharStyle"_ustr, |
3079 | | u".uno:ParaStyle"_ustr, |
3080 | | u".uno:FrameStyle"_ustr, |
3081 | | u".uno:PageStyle"_ustr, |
3082 | | u".uno:TemplateFamily5"_ustr |
3083 | | }; |
3084 | | |
3085 | | SvxStyleToolBoxControl::SvxStyleToolBoxControl() |
3086 | 0 | : pImpl(new Impl) |
3087 | 0 | , pStyleSheetPool(nullptr) |
3088 | 0 | , nActFamily(0xffff) |
3089 | 0 | { |
3090 | 0 | for (sal_uInt16 i = 0; i < MAX_FAMILIES; ++i) |
3091 | 0 | { |
3092 | 0 | m_xBoundItems[i].clear(); |
3093 | 0 | pFamilyState[i] = nullptr; |
3094 | 0 | } |
3095 | 0 | } |
3096 | | |
3097 | | SvxStyleToolBoxControl::~SvxStyleToolBoxControl() |
3098 | 0 | { |
3099 | 0 | } |
3100 | | |
3101 | | void SAL_CALL SvxStyleToolBoxControl::initialize(const Sequence<Any>& rArguments) |
3102 | 0 | { |
3103 | 0 | svt::ToolboxController::initialize(rArguments); |
3104 | | |
3105 | | // After initialize we should have a valid frame member where we can retrieve our |
3106 | | // dispatch provider. |
3107 | 0 | if ( !m_xFrame.is() ) |
3108 | 0 | return; |
3109 | | |
3110 | 0 | pImpl->InitializeStyles(m_xFrame->getController()->getModel()); |
3111 | 0 | Reference< XDispatchProvider > xDispatchProvider( m_xFrame->getController(), UNO_QUERY ); |
3112 | 0 | for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ ) |
3113 | 0 | { |
3114 | 0 | m_xBoundItems[i] = new SfxStyleControllerItem_Impl( xDispatchProvider, |
3115 | 0 | SID_STYLE_FAMILY_START + i, |
3116 | 0 | StyleSlotToStyleCommand[i], |
3117 | 0 | *this ); |
3118 | 0 | pFamilyState[i] = nullptr; |
3119 | 0 | } |
3120 | 0 | } |
3121 | | |
3122 | | // XComponent |
3123 | | void SAL_CALL SvxStyleToolBoxControl::dispose() |
3124 | 0 | { |
3125 | 0 | svt::ToolboxController::dispose(); |
3126 | |
|
3127 | 0 | SolarMutexGuard aSolarMutexGuard; |
3128 | 0 | pImpl->m_xVclBox.disposeAndClear(); |
3129 | 0 | pImpl->m_xWeldBox.reset(); |
3130 | 0 | pImpl->m_pBox = nullptr; |
3131 | |
|
3132 | 0 | for (rtl::Reference<SfxStyleControllerItem_Impl>& pBoundItem : m_xBoundItems) |
3133 | 0 | { |
3134 | 0 | if (!pBoundItem) |
3135 | 0 | continue; |
3136 | 0 | pBoundItem->UnBind(); |
3137 | 0 | } |
3138 | 0 | unbindListener(); |
3139 | |
|
3140 | 0 | for( sal_uInt16 i=0; i<MAX_FAMILIES; i++ ) |
3141 | 0 | { |
3142 | 0 | if ( m_xBoundItems[i].is() ) |
3143 | 0 | { |
3144 | 0 | try |
3145 | 0 | { |
3146 | 0 | m_xBoundItems[i]->dispose(); |
3147 | 0 | } |
3148 | 0 | catch ( Exception& ) |
3149 | 0 | { |
3150 | 0 | } |
3151 | |
|
3152 | 0 | m_xBoundItems[i].clear(); |
3153 | 0 | } |
3154 | 0 | pFamilyState[i].reset(); |
3155 | 0 | } |
3156 | 0 | pStyleSheetPool = nullptr; |
3157 | 0 | pImpl.reset(); |
3158 | 0 | } |
3159 | | |
3160 | | OUString SvxStyleToolBoxControl::getImplementationName() |
3161 | 0 | { |
3162 | 0 | return u"com.sun.star.comp.svx.StyleToolBoxControl"_ustr; |
3163 | 0 | } |
3164 | | |
3165 | | sal_Bool SvxStyleToolBoxControl::supportsService( const OUString& rServiceName ) |
3166 | 0 | { |
3167 | 0 | return cppu::supportsService( this, rServiceName ); |
3168 | 0 | } |
3169 | | |
3170 | | css::uno::Sequence< OUString > SvxStyleToolBoxControl::getSupportedServiceNames() |
3171 | 0 | { |
3172 | 0 | return { u"com.sun.star.frame.ToolbarController"_ustr }; |
3173 | 0 | } |
3174 | | |
3175 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
3176 | | com_sun_star_comp_svx_StyleToolBoxControl_get_implementation( |
3177 | | css::uno::XComponentContext*, |
3178 | | css::uno::Sequence<css::uno::Any> const & ) |
3179 | 0 | { |
3180 | 0 | return cppu::acquire( new SvxStyleToolBoxControl() ); |
3181 | 0 | } |
3182 | | |
3183 | | void SAL_CALL SvxStyleToolBoxControl::update() |
3184 | 0 | { |
3185 | 0 | for (rtl::Reference<SfxStyleControllerItem_Impl>& pBoundItem : m_xBoundItems) |
3186 | 0 | pBoundItem->ReBind(); |
3187 | 0 | bindListener(); |
3188 | 0 | } |
3189 | | |
3190 | | SfxStyleFamily SvxStyleToolBoxControl::GetActFamily() const |
3191 | 0 | { |
3192 | 0 | switch ( nActFamily-1 + SID_STYLE_FAMILY_START ) |
3193 | 0 | { |
3194 | 0 | case SID_STYLE_FAMILY1: return SfxStyleFamily::Char; |
3195 | 0 | case SID_STYLE_FAMILY2: return SfxStyleFamily::Para; |
3196 | 0 | case SID_STYLE_FAMILY3: return SfxStyleFamily::Frame; |
3197 | 0 | case SID_STYLE_FAMILY4: return SfxStyleFamily::Page; |
3198 | 0 | case SID_STYLE_FAMILY5: return SfxStyleFamily::Pseudo; |
3199 | 0 | default: |
3200 | 0 | OSL_FAIL( "unknown style family" ); |
3201 | 0 | break; |
3202 | 0 | } |
3203 | 0 | return SfxStyleFamily::Para; |
3204 | 0 | } |
3205 | | |
3206 | | void SvxStyleToolBoxControl::FillStyleBox() |
3207 | 0 | { |
3208 | 0 | SvxStyleBox_Base* pBox = pImpl->m_pBox; |
3209 | |
|
3210 | 0 | DBG_ASSERT( pStyleSheetPool, "StyleSheetPool not found!" ); |
3211 | 0 | DBG_ASSERT( pBox, "Control not found!" ); |
3212 | |
|
3213 | 0 | if ( !(pStyleSheetPool && pBox && nActFamily!=0xffff) ) |
3214 | 0 | return; |
3215 | | |
3216 | 0 | const SfxStyleFamily eFamily = GetActFamily(); |
3217 | 0 | SfxStyleSheetBase* pStyle = nullptr; |
3218 | 0 | bool bDoFill = false; |
3219 | |
|
3220 | 0 | auto xIter = pStyleSheetPool->CreateIterator(eFamily, SfxStyleSearchBits::Used); |
3221 | 0 | sal_uInt16 nCount = xIter->Count(); |
3222 | | |
3223 | | // Check whether fill is necessary |
3224 | 0 | pStyle = xIter->First(); |
3225 | | //!!! TODO: This condition isn't right any longer, because we always show some default entries |
3226 | | //!!! so the list doesn't show the count |
3227 | 0 | if ( nCount != pBox->get_count() ) |
3228 | 0 | { |
3229 | 0 | bDoFill = true; |
3230 | 0 | } |
3231 | 0 | else |
3232 | 0 | { |
3233 | 0 | sal_uInt16 i= 0; |
3234 | 0 | while ( pStyle && !bDoFill ) |
3235 | 0 | { |
3236 | 0 | bDoFill = ( pBox->get_text(i) != pStyle->GetName() ); |
3237 | 0 | pStyle = xIter->Next(); |
3238 | 0 | i++; |
3239 | 0 | } |
3240 | 0 | } |
3241 | |
|
3242 | 0 | if ( !bDoFill ) |
3243 | 0 | return; |
3244 | | |
3245 | 0 | OUString aStrSel(pBox->get_active_text()); |
3246 | 0 | pBox->freeze(); |
3247 | 0 | pBox->clear(); |
3248 | |
|
3249 | 0 | std::vector<OUString> aStyles; |
3250 | | |
3251 | | // add used styles |
3252 | 0 | pStyle = xIter->Next(); |
3253 | 0 | while ( pStyle ) |
3254 | 0 | { |
3255 | 0 | aStyles.push_back(pStyle->GetName()); |
3256 | 0 | pStyle = xIter->Next(); |
3257 | 0 | } |
3258 | |
|
3259 | 0 | if (pImpl->bSpecModeWriter || pImpl->bSpecModeCalc) |
3260 | 0 | { |
3261 | 0 | pBox->append_text(pImpl->aClearForm); |
3262 | 0 | pBox->insert_separator(1, u"separator"_ustr); |
3263 | | |
3264 | | // add default styles if less than 12 items |
3265 | 0 | for( const auto &rStyle : pImpl->aDefaultStyles ) |
3266 | 0 | { |
3267 | 0 | if ( aStyles.size() + pBox->get_count() > 12) |
3268 | 0 | break; |
3269 | 0 | pBox->append_text(rStyle.second); |
3270 | 0 | } |
3271 | 0 | } |
3272 | 0 | std::sort(aStyles.begin(), aStyles.end()); |
3273 | |
|
3274 | 0 | for (const auto& rStyle : aStyles) |
3275 | 0 | if (pBox->find_text(rStyle) == -1) |
3276 | 0 | pBox->append_text(rStyle); |
3277 | |
|
3278 | 0 | if ((pImpl->bSpecModeWriter || pImpl->bSpecModeCalc) && !comphelper::LibreOfficeKit::isActive()) |
3279 | 0 | pBox->append_text(pImpl->aMore); |
3280 | |
|
3281 | 0 | pBox->thaw(); |
3282 | 0 | pBox->set_active_or_entry_text(aStrSel); |
3283 | 0 | pBox->SetFamily( eFamily ); |
3284 | 0 | } |
3285 | | |
3286 | | void SvxStyleToolBoxControl::SelectStyle( const OUString& rStyleName ) |
3287 | 0 | { |
3288 | 0 | SvxStyleBox_Base* pBox = pImpl->m_pBox; |
3289 | 0 | DBG_ASSERT( pBox, "Control not found!" ); |
3290 | |
|
3291 | 0 | if ( !pBox ) |
3292 | 0 | return; |
3293 | | |
3294 | 0 | OUString aStrSel(pBox->get_active_text()); |
3295 | |
|
3296 | 0 | if ( !rStyleName.isEmpty() ) |
3297 | 0 | { |
3298 | 0 | OUString aNewStyle = rStyleName; |
3299 | |
|
3300 | 0 | auto aFound = std::find_if(pImpl->aDefaultStyles.begin(), pImpl->aDefaultStyles.end(), |
3301 | 0 | [rStyleName] (auto it) { return it.first == rStyleName || it.second == rStyleName; } |
3302 | 0 | ); |
3303 | |
|
3304 | 0 | if (aFound != pImpl->aDefaultStyles.end()) |
3305 | 0 | aNewStyle = aFound->second; |
3306 | |
|
3307 | 0 | if ( aNewStyle != aStrSel ) |
3308 | 0 | pBox->set_active_or_entry_text( aNewStyle ); |
3309 | 0 | } |
3310 | 0 | else |
3311 | 0 | pBox->set_active(-1); |
3312 | 0 | pBox->save_value(); |
3313 | 0 | } |
3314 | | |
3315 | | void SvxStyleToolBoxControl::Update() |
3316 | 0 | { |
3317 | 0 | SfxStyleSheetBasePool* pPool = nullptr; |
3318 | 0 | SfxObjectShell* pDocShell = SfxObjectShell::Current(); |
3319 | |
|
3320 | 0 | if ( pDocShell ) |
3321 | 0 | pPool = pDocShell->GetStyleSheetPool(); |
3322 | |
|
3323 | 0 | sal_uInt16 i; |
3324 | 0 | for ( i=0; i<MAX_FAMILIES; i++ ) |
3325 | 0 | if( pFamilyState[i] ) |
3326 | 0 | break; |
3327 | |
|
3328 | 0 | if ( i==MAX_FAMILIES || !pPool ) |
3329 | 0 | { |
3330 | 0 | pStyleSheetPool = pPool; |
3331 | 0 | return; |
3332 | 0 | } |
3333 | | |
3334 | | |
3335 | 0 | const SfxTemplateItem* pItem = nullptr; |
3336 | |
|
3337 | 0 | if ( nActFamily == 0xffff || nullptr == (pItem = pFamilyState[nActFamily-1].get()) ) |
3338 | | // Current range not within allowed ranges or default |
3339 | 0 | { |
3340 | 0 | pStyleSheetPool = pPool; |
3341 | 0 | nActFamily = 2; |
3342 | |
|
3343 | 0 | pItem = pFamilyState[nActFamily-1].get(); |
3344 | 0 | if ( !pItem ) |
3345 | 0 | { |
3346 | 0 | nActFamily++; |
3347 | 0 | pItem = pFamilyState[nActFamily-1].get(); |
3348 | 0 | } |
3349 | 0 | } |
3350 | 0 | else if ( pPool != pStyleSheetPool ) |
3351 | 0 | pStyleSheetPool = pPool; |
3352 | |
|
3353 | 0 | FillStyleBox(); // Decides by itself whether Fill is needed |
3354 | |
|
3355 | 0 | if ( pItem ) |
3356 | 0 | SelectStyle( pItem->GetStyleName() ); |
3357 | 0 | } |
3358 | | |
3359 | | void SvxStyleToolBoxControl::SetFamilyState( sal_uInt16 nIdx, |
3360 | | const SfxTemplateItem* pItem ) |
3361 | 0 | { |
3362 | 0 | pFamilyState[nIdx].reset( pItem == nullptr ? nullptr : new SfxTemplateItem( *pItem ) ); |
3363 | 0 | Update(); |
3364 | 0 | } |
3365 | | |
3366 | | void SvxStyleToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent ) |
3367 | 0 | { |
3368 | 0 | SolarMutexGuard aGuard; |
3369 | |
|
3370 | 0 | if (m_pToolbar) |
3371 | 0 | m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled); |
3372 | 0 | else |
3373 | 0 | { |
3374 | 0 | ToolBox* pToolBox = nullptr; |
3375 | 0 | ToolBoxItemId nId; |
3376 | 0 | if (!getToolboxId( nId, &pToolBox ) ) |
3377 | 0 | return; |
3378 | 0 | pToolBox->EnableItem( nId, rEvent.IsEnabled ); |
3379 | 0 | } |
3380 | | |
3381 | 0 | if (rEvent.IsEnabled) |
3382 | 0 | Update(); |
3383 | 0 | } |
3384 | | |
3385 | | css::uno::Reference<css::awt::XWindow> SvxStyleToolBoxControl::createItemWindow(const css::uno::Reference< css::awt::XWindow>& rParent) |
3386 | 0 | { |
3387 | 0 | uno::Reference< awt::XWindow > xItemWindow; |
3388 | |
|
3389 | 0 | if (m_pBuilder) |
3390 | 0 | { |
3391 | 0 | SolarMutexGuard aSolarMutexGuard; |
3392 | |
|
3393 | 0 | std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box(u"applystyle"_ustr)); |
3394 | |
|
3395 | 0 | xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get())); |
3396 | |
|
3397 | 0 | pImpl->m_xWeldBox.reset(new SvxStyleBox_Base(std::move(xWidget), |
3398 | 0 | u".uno:StyleApply"_ustr, |
3399 | 0 | SfxStyleFamily::Para, |
3400 | 0 | m_xFrame, |
3401 | 0 | pImpl->aClearForm, |
3402 | 0 | pImpl->aMore, |
3403 | 0 | pImpl->bSpecModeWriter || pImpl->bSpecModeCalc, *this)); |
3404 | 0 | pImpl->m_pBox = pImpl->m_xWeldBox.get(); |
3405 | 0 | } |
3406 | 0 | else |
3407 | 0 | { |
3408 | 0 | VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent); |
3409 | 0 | if ( pParent ) |
3410 | 0 | { |
3411 | 0 | SolarMutexGuard aSolarMutexGuard; |
3412 | |
|
3413 | 0 | pImpl->m_xVclBox = VclPtr<SvxStyleBox_Impl>::Create(pParent, |
3414 | 0 | ".uno:StyleApply", |
3415 | 0 | SfxStyleFamily::Para, |
3416 | 0 | m_xFrame, |
3417 | 0 | pImpl->aClearForm, |
3418 | 0 | pImpl->aMore, |
3419 | 0 | pImpl->bSpecModeWriter || pImpl->bSpecModeCalc, *this); |
3420 | 0 | pImpl->m_pBox = pImpl->m_xVclBox.get(); |
3421 | 0 | xItemWindow = VCLUnoHelper::GetInterface(pImpl->m_xVclBox); |
3422 | 0 | } |
3423 | 0 | } |
3424 | |
|
3425 | 0 | if (pImpl->m_pBox && !pImpl->aDefaultStyles.empty()) |
3426 | 0 | pImpl->m_pBox->SetDefaultStyle(pImpl->aDefaultStyles[0].second); |
3427 | |
|
3428 | 0 | return xItemWindow; |
3429 | 0 | } |
3430 | | |
3431 | | SvxFontNameToolBoxControl::SvxFontNameToolBoxControl() |
3432 | 0 | : m_pBox(nullptr) |
3433 | 0 | { |
3434 | 0 | } |
3435 | | |
3436 | | void SvxFontNameBox_Base::statusChanged_Impl( const css::frame::FeatureStateEvent& rEvent ) |
3437 | 0 | { |
3438 | 0 | if ( !rEvent.IsEnabled ) |
3439 | 0 | { |
3440 | 0 | set_sensitive(false); |
3441 | 0 | Update( nullptr ); |
3442 | 0 | } |
3443 | 0 | else |
3444 | 0 | { |
3445 | 0 | set_sensitive(true); |
3446 | |
|
3447 | 0 | css::awt::FontDescriptor aFontDesc; |
3448 | 0 | if ( rEvent.State >>= aFontDesc ) |
3449 | 0 | Update(&aFontDesc); |
3450 | 0 | else { |
3451 | | // no active element; delete value in the display |
3452 | 0 | m_xWidget->set_active(-1); |
3453 | 0 | set_active_or_entry_text(u""_ustr); |
3454 | 0 | } |
3455 | 0 | m_xWidget->save_value(); |
3456 | 0 | } |
3457 | 0 | } |
3458 | | |
3459 | | void SvxFontNameToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent ) |
3460 | 0 | { |
3461 | 0 | SolarMutexGuard aGuard; |
3462 | 0 | m_pBox->statusChanged_Impl(rEvent); |
3463 | |
|
3464 | 0 | if (m_pToolbar) |
3465 | 0 | m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled); |
3466 | 0 | else |
3467 | 0 | { |
3468 | 0 | ToolBox* pToolBox = nullptr; |
3469 | 0 | ToolBoxItemId nId; |
3470 | 0 | if (!getToolboxId( nId, &pToolBox ) ) |
3471 | 0 | return; |
3472 | 0 | pToolBox->EnableItem( nId, rEvent.IsEnabled ); |
3473 | 0 | } |
3474 | 0 | } |
3475 | | |
3476 | | css::uno::Reference<css::awt::XWindow> SvxFontNameToolBoxControl::createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent) |
3477 | 0 | { |
3478 | 0 | uno::Reference< awt::XWindow > xItemWindow; |
3479 | |
|
3480 | 0 | if (m_pBuilder) |
3481 | 0 | { |
3482 | 0 | SolarMutexGuard aSolarMutexGuard; |
3483 | |
|
3484 | 0 | std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box(u"fontnamecombobox"_ustr)); |
3485 | |
|
3486 | 0 | xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get())); |
3487 | |
|
3488 | 0 | m_xWeldBox.reset(new SvxFontNameBox_Base(std::move(xWidget), m_xFrame, *this)); |
3489 | 0 | m_pBox = m_xWeldBox.get(); |
3490 | 0 | } |
3491 | 0 | else |
3492 | 0 | { |
3493 | 0 | VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent); |
3494 | 0 | if ( pParent ) |
3495 | 0 | { |
3496 | 0 | SolarMutexGuard aSolarMutexGuard; |
3497 | 0 | m_xVclBox = VclPtr<SvxFontNameBox_Impl>::Create(pParent, m_xFrame, *this); |
3498 | 0 | m_pBox = m_xVclBox.get(); |
3499 | 0 | xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox); |
3500 | 0 | } |
3501 | 0 | } |
3502 | |
|
3503 | 0 | return xItemWindow; |
3504 | 0 | } |
3505 | | |
3506 | | void SvxFontNameToolBoxControl::dispose() |
3507 | 0 | { |
3508 | 0 | ToolboxController::dispose(); |
3509 | |
|
3510 | 0 | SolarMutexGuard aSolarMutexGuard; |
3511 | 0 | m_xVclBox.disposeAndClear(); |
3512 | 0 | m_xWeldBox.reset(); |
3513 | 0 | m_pBox = nullptr; |
3514 | 0 | } |
3515 | | |
3516 | | OUString SvxFontNameToolBoxControl::getImplementationName() |
3517 | 0 | { |
3518 | 0 | return u"com.sun.star.comp.svx.FontNameToolBoxControl"_ustr; |
3519 | 0 | } |
3520 | | |
3521 | | sal_Bool SvxFontNameToolBoxControl::supportsService( const OUString& rServiceName ) |
3522 | 0 | { |
3523 | 0 | return cppu::supportsService( this, rServiceName ); |
3524 | 0 | } |
3525 | | |
3526 | | css::uno::Sequence< OUString > SvxFontNameToolBoxControl::getSupportedServiceNames() |
3527 | 0 | { |
3528 | 0 | return { u"com.sun.star.frame.ToolbarController"_ustr }; |
3529 | 0 | } |
3530 | | |
3531 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
3532 | | com_sun_star_comp_svx_FontNameToolBoxControl_get_implementation( |
3533 | | css::uno::XComponentContext*, |
3534 | | css::uno::Sequence<css::uno::Any> const & ) |
3535 | 0 | { |
3536 | 0 | return cppu::acquire( new SvxFontNameToolBoxControl() ); |
3537 | 0 | } |
3538 | | |
3539 | | SvxColorToolBoxControl::SvxColorToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext ) : |
3540 | 0 | ImplInheritanceHelper( rContext, nullptr, OUString() ), |
3541 | 0 | m_bSplitButton(true), |
3542 | 0 | m_nSlotId(0), |
3543 | 0 | m_aColorSelectFunction(PaletteManager::DispatchColorCommand) |
3544 | 0 | { |
3545 | 0 | } |
3546 | | |
3547 | | namespace { |
3548 | | |
3549 | | sal_uInt16 MapCommandToSlotId(const OUString& rCommand) |
3550 | 0 | { |
3551 | 0 | if (rCommand == ".uno:Color") |
3552 | 0 | return SID_ATTR_CHAR_COLOR; |
3553 | 0 | else if (rCommand == ".uno:FontColor") |
3554 | 0 | return SID_ATTR_CHAR_COLOR2; |
3555 | 0 | else if (rCommand == ".uno:BackColor") // deprecated - use CharBackColor |
3556 | 0 | return SID_ATTR_CHAR_COLOR_BACKGROUND; |
3557 | 0 | else if (rCommand == ".uno:CharBackColor") |
3558 | 0 | return SID_ATTR_CHAR_BACK_COLOR; |
3559 | 0 | else if (rCommand == ".uno:BackgroundColor") |
3560 | 0 | return SID_BACKGROUND_COLOR; |
3561 | 0 | else if (rCommand == ".uno:TableCellBackgroundColor") |
3562 | 0 | return SID_TABLE_CELL_BACKGROUND_COLOR; |
3563 | 0 | else if (rCommand == ".uno:Extrusion3DColor") |
3564 | 0 | return SID_EXTRUSION_3D_COLOR; |
3565 | 0 | else if (rCommand == ".uno:XLineColor") |
3566 | 0 | return SID_ATTR_LINE_COLOR; |
3567 | 0 | else if (rCommand == ".uno:FillColor") |
3568 | 0 | return SID_ATTR_FILL_COLOR; |
3569 | 0 | else if (rCommand == ".uno:FrameLineColor") |
3570 | 0 | return SID_FRAME_LINECOLOR; |
3571 | | |
3572 | 0 | SAL_WARN("svx.tbxcrtls", "Unknown color command: " << rCommand); |
3573 | 0 | return 0; |
3574 | 0 | } |
3575 | | |
3576 | | } |
3577 | | |
3578 | | void SvxColorToolBoxControl::initialize( const css::uno::Sequence<css::uno::Any>& rArguments ) |
3579 | 0 | { |
3580 | 0 | PopupWindowController::initialize( rArguments ); |
3581 | |
|
3582 | 0 | m_nSlotId = MapCommandToSlotId( m_aCommandURL ); |
3583 | |
|
3584 | 0 | if ( m_nSlotId == SID_ATTR_LINE_COLOR || m_nSlotId == SID_ATTR_FILL_COLOR || |
3585 | 0 | m_nSlotId == SID_FRAME_LINECOLOR || m_nSlotId == SID_BACKGROUND_COLOR ) |
3586 | 0 | { |
3587 | | // Sidebar uses wide buttons for those. |
3588 | 0 | m_bSplitButton = !m_bSidebar; |
3589 | 0 | } |
3590 | |
|
3591 | 0 | auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(getCommandURL(), getModuleName()); |
3592 | 0 | OUString aCommandLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties); |
3593 | |
|
3594 | 0 | if (m_pToolbar) |
3595 | 0 | { |
3596 | 0 | mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar)); |
3597 | 0 | m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel()); |
3598 | 0 | m_xBtnUpdater.reset(new svx::ToolboxButtonColorUpdater(m_nSlotId, m_aCommandURL, m_pToolbar, !m_bSplitButton, aCommandLabel, m_xFrame)); |
3599 | 0 | return; |
3600 | 0 | } |
3601 | | |
3602 | 0 | ToolBox* pToolBox = nullptr; |
3603 | 0 | ToolBoxItemId nId; |
3604 | 0 | if (getToolboxId(nId, &pToolBox)) |
3605 | 0 | { |
3606 | 0 | m_xBtnUpdater.reset( new svx::VclToolboxButtonColorUpdater( m_nSlotId, nId, pToolBox, !m_bSplitButton, aCommandLabel, m_aCommandURL, m_xFrame ) ); |
3607 | 0 | pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ( m_bSplitButton ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) ); |
3608 | 0 | } |
3609 | 0 | } |
3610 | | |
3611 | | void SvxColorToolBoxControl::update() |
3612 | 0 | { |
3613 | 0 | PopupWindowController::update(); |
3614 | |
|
3615 | 0 | switch( m_nSlotId ) |
3616 | 0 | { |
3617 | 0 | case SID_ATTR_CHAR_COLOR2: |
3618 | 0 | addStatusListener( u".uno:CharColorExt"_ustr); |
3619 | 0 | break; |
3620 | | |
3621 | 0 | case SID_ATTR_CHAR_BACK_COLOR: |
3622 | 0 | case SID_ATTR_CHAR_COLOR_BACKGROUND: |
3623 | 0 | addStatusListener( u".uno:CharBackgroundExt"_ustr); |
3624 | 0 | break; |
3625 | | |
3626 | 0 | case SID_FRAME_LINECOLOR: |
3627 | 0 | addStatusListener( u".uno:BorderTLBR"_ustr); |
3628 | 0 | addStatusListener( u".uno:BorderBLTR"_ustr); |
3629 | 0 | break; |
3630 | 0 | } |
3631 | 0 | } |
3632 | | |
3633 | | void SvxColorToolBoxControl::EnsurePaletteManager() |
3634 | 0 | { |
3635 | 0 | if (!m_xPaletteManager) |
3636 | 0 | { |
3637 | 0 | m_xPaletteManager = std::make_shared<PaletteManager>(); |
3638 | 0 | m_xPaletteManager->SetBtnUpdater(m_xBtnUpdater.get()); |
3639 | 0 | } |
3640 | 0 | } |
3641 | | |
3642 | | SvxColorToolBoxControl::~SvxColorToolBoxControl() |
3643 | 0 | { |
3644 | 0 | if (m_xPaletteManager) |
3645 | 0 | m_xPaletteManager->SetBtnUpdater(nullptr); |
3646 | 0 | } |
3647 | | |
3648 | | void SvxColorToolBoxControl::setColorSelectFunction(const ColorSelectFunction& aColorSelectFunction) |
3649 | 0 | { |
3650 | 0 | m_aColorSelectFunction = aColorSelectFunction; |
3651 | 0 | if (m_xPaletteManager) |
3652 | 0 | m_xPaletteManager->SetColorSelectFunction(aColorSelectFunction); |
3653 | 0 | } |
3654 | | |
3655 | | weld::Window* SvxColorToolBoxControl::GetParentFrame() const |
3656 | 0 | { |
3657 | 0 | const css::uno::Reference<css::awt::XWindow> xParent = m_xFrame->getContainerWindow(); |
3658 | 0 | return Application::GetFrameWeld(xParent); |
3659 | 0 | } |
3660 | | |
3661 | | std::unique_ptr<WeldToolbarPopup> SvxColorToolBoxControl::weldPopupWindow() |
3662 | 0 | { |
3663 | 0 | EnsurePaletteManager(); |
3664 | |
|
3665 | 0 | auto xPopover = std::make_unique<ColorWindow>( |
3666 | 0 | m_aCommandURL, |
3667 | 0 | m_xPaletteManager, |
3668 | 0 | m_aColorStatus, |
3669 | 0 | m_nSlotId, |
3670 | 0 | m_xFrame, |
3671 | 0 | MenuOrToolMenuButton(m_pToolbar, m_aCommandURL), |
3672 | 0 | [this] { return GetParentFrame(); }, |
3673 | 0 | m_aColorSelectFunction); |
3674 | |
|
3675 | 0 | return xPopover; |
3676 | 0 | } |
3677 | | |
3678 | | VclPtr<vcl::Window> SvxColorToolBoxControl::createVclPopupWindow( vcl::Window* pParent ) |
3679 | 0 | { |
3680 | 0 | ToolBox* pToolBox = nullptr; |
3681 | 0 | ToolBoxItemId nId; |
3682 | 0 | if (!getToolboxId(nId, &pToolBox)) |
3683 | 0 | return nullptr; |
3684 | | |
3685 | 0 | EnsurePaletteManager(); |
3686 | |
|
3687 | 0 | auto xPopover = std::make_unique<ColorWindow>( |
3688 | 0 | m_aCommandURL, |
3689 | 0 | m_xPaletteManager, |
3690 | 0 | m_aColorStatus, |
3691 | 0 | m_nSlotId, |
3692 | 0 | m_xFrame, |
3693 | 0 | MenuOrToolMenuButton(this, pToolBox, nId), |
3694 | 0 | [this] { return GetParentFrame(); }, |
3695 | 0 | m_aColorSelectFunction); |
3696 | |
|
3697 | 0 | mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent, |
3698 | 0 | std::move(xPopover), true); |
3699 | |
|
3700 | 0 | auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(m_aCommandURL, m_sModuleName); |
3701 | 0 | OUString aWindowTitle = vcl::CommandInfoProvider::GetLabelForCommand(aProperties); |
3702 | 0 | mxInterimPopover->SetText(aWindowTitle); |
3703 | |
|
3704 | 0 | mxInterimPopover->Show(); |
3705 | |
|
3706 | 0 | return mxInterimPopover; |
3707 | 0 | } |
3708 | | |
3709 | | void SvxColorToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent ) |
3710 | 0 | { |
3711 | 0 | ToolBox* pToolBox = nullptr; |
3712 | 0 | ToolBoxItemId nId; |
3713 | 0 | if (!getToolboxId(nId, &pToolBox) && !m_pToolbar) |
3714 | 0 | return; |
3715 | | |
3716 | 0 | if ( rEvent.FeatureURL.Complete == m_aCommandURL ) |
3717 | 0 | { |
3718 | 0 | if (m_pToolbar) |
3719 | 0 | m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled); |
3720 | 0 | else |
3721 | 0 | pToolBox->EnableItem( nId, rEvent.IsEnabled ); |
3722 | 0 | } |
3723 | |
|
3724 | 0 | bool bValue; |
3725 | 0 | if ( !m_bSplitButton ) |
3726 | 0 | { |
3727 | 0 | m_aColorStatus.statusChanged( rEvent ); |
3728 | 0 | m_xBtnUpdater->Update( m_aColorStatus.GetColor() ); |
3729 | 0 | } |
3730 | 0 | else if ( rEvent.State >>= bValue ) |
3731 | 0 | { |
3732 | 0 | if (m_pToolbar) |
3733 | 0 | m_pToolbar->set_item_active(m_aCommandURL, bValue); |
3734 | 0 | else if (pToolBox) |
3735 | 0 | pToolBox->CheckItem( nId, bValue ); |
3736 | 0 | } |
3737 | 0 | } |
3738 | | |
3739 | | void SvxColorToolBoxControl::execute(sal_Int16 /*nSelectModifier*/) |
3740 | 0 | { |
3741 | 0 | if ( !m_bSplitButton ) |
3742 | 0 | { |
3743 | 0 | if (m_pToolbar) |
3744 | 0 | { |
3745 | | // Toggle the popup also when toolbutton is activated |
3746 | 0 | m_pToolbar->set_menu_item_active(m_aCommandURL, !m_pToolbar->get_menu_item_active(m_aCommandURL)); |
3747 | 0 | } |
3748 | 0 | else |
3749 | 0 | { |
3750 | | // Open the popup also when Enter key is pressed. |
3751 | 0 | createPopupWindow(); |
3752 | 0 | } |
3753 | 0 | return; |
3754 | 0 | } |
3755 | | |
3756 | 0 | OUString aCommand = m_aCommandURL; |
3757 | 0 | Color aColor = m_xBtnUpdater->GetCurrentColor(); |
3758 | |
|
3759 | 0 | switch( m_nSlotId ) |
3760 | 0 | { |
3761 | 0 | case SID_ATTR_CHAR_COLOR2 : |
3762 | 0 | aCommand = ".uno:CharColorExt"; |
3763 | 0 | break; |
3764 | 0 | } |
3765 | | |
3766 | 0 | auto aArgs( comphelper::InitPropertySequence( { |
3767 | 0 | { m_aCommandURL.copy(5), css::uno::Any(aColor) } |
3768 | 0 | } ) ); |
3769 | 0 | dispatchCommand( aCommand, aArgs ); |
3770 | |
|
3771 | 0 | EnsurePaletteManager(); |
3772 | 0 | OUString sColorName = m_xBtnUpdater->GetCurrentColorName(); |
3773 | 0 | m_xPaletteManager->AddRecentColor(aColor, sColorName); |
3774 | 0 | } |
3775 | | |
3776 | | sal_Bool SvxColorToolBoxControl::opensSubToolbar() |
3777 | 0 | { |
3778 | | // We mark this controller as a sub-toolbar controller, so we get notified |
3779 | | // (through updateImage method) on button image changes, and could redraw |
3780 | | // the last used color on top of it. |
3781 | 0 | return true; |
3782 | 0 | } |
3783 | | |
3784 | | void SvxColorToolBoxControl::updateImage() |
3785 | 0 | { |
3786 | 0 | m_xBtnUpdater->Update(m_xBtnUpdater->GetCurrentColor(), true); |
3787 | 0 | } |
3788 | | |
3789 | | OUString SvxColorToolBoxControl::getSubToolbarName() |
3790 | 0 | { |
3791 | 0 | return OUString(); |
3792 | 0 | } |
3793 | | |
3794 | | void SvxColorToolBoxControl::functionSelected( const OUString& /*rCommand*/ ) |
3795 | 0 | { |
3796 | 0 | } |
3797 | | |
3798 | | OUString SvxColorToolBoxControl::getImplementationName() |
3799 | 0 | { |
3800 | 0 | return u"com.sun.star.comp.svx.ColorToolBoxControl"_ustr; |
3801 | 0 | } |
3802 | | |
3803 | | css::uno::Sequence<OUString> SvxColorToolBoxControl::getSupportedServiceNames() |
3804 | 0 | { |
3805 | 0 | return { u"com.sun.star.frame.ToolbarController"_ustr }; |
3806 | 0 | } |
3807 | | |
3808 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
3809 | | com_sun_star_comp_svx_ColorToolBoxControl_get_implementation( |
3810 | | css::uno::XComponentContext* rContext, |
3811 | | css::uno::Sequence<css::uno::Any> const & ) |
3812 | 0 | { |
3813 | 0 | return cppu::acquire( new SvxColorToolBoxControl( rContext ) ); |
3814 | 0 | } |
3815 | | |
3816 | | SvxFrameToolBoxControl::SvxFrameToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rContext ) |
3817 | 0 | : svt::PopupWindowController( rContext, nullptr, OUString() ) |
3818 | 0 | { |
3819 | 0 | } |
3820 | | |
3821 | | void SAL_CALL SvxFrameToolBoxControl::execute(sal_Int16 /*KeyModifier*/) |
3822 | 0 | { |
3823 | 0 | if (m_pToolbar) |
3824 | 0 | { |
3825 | | // Toggle the popup also when toolbutton is activated |
3826 | 0 | m_pToolbar->set_menu_item_active(m_aCommandURL, !m_pToolbar->get_menu_item_active(m_aCommandURL)); |
3827 | 0 | } |
3828 | 0 | else |
3829 | 0 | { |
3830 | | // Open the popup also when Enter key is pressed. |
3831 | 0 | createPopupWindow(); |
3832 | 0 | } |
3833 | 0 | } |
3834 | | |
3835 | | void SvxFrameToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) |
3836 | 0 | { |
3837 | 0 | svt::PopupWindowController::initialize( rArguments ); |
3838 | |
|
3839 | 0 | if (m_pToolbar) |
3840 | 0 | { |
3841 | 0 | mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar)); |
3842 | 0 | m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel()); |
3843 | 0 | } |
3844 | |
|
3845 | 0 | ToolBox* pToolBox = nullptr; |
3846 | 0 | ToolBoxItemId nId; |
3847 | 0 | if (getToolboxId(nId, &pToolBox)) |
3848 | 0 | pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY ); |
3849 | 0 | } |
3850 | | |
3851 | | std::unique_ptr<WeldToolbarPopup> SvxFrameToolBoxControl::weldPopupWindow() |
3852 | 0 | { |
3853 | 0 | if ( m_aCommandURL == ".uno:LineStyle" ) |
3854 | 0 | return std::make_unique<SvxLineWindow_Impl>(this, m_pToolbar); |
3855 | 0 | return std::make_unique<SvxFrameWindow_Impl>(this, m_pToolbar); |
3856 | 0 | } |
3857 | | |
3858 | | VclPtr<vcl::Window> SvxFrameToolBoxControl::createVclPopupWindow( vcl::Window* pParent ) |
3859 | 0 | { |
3860 | 0 | if ( m_aCommandURL == ".uno:LineStyle" ) |
3861 | 0 | { |
3862 | 0 | mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent, |
3863 | 0 | std::make_unique<SvxLineWindow_Impl>(this, pParent->GetFrameWeld()), true); |
3864 | |
|
3865 | 0 | mxInterimPopover->Show(); |
3866 | |
|
3867 | 0 | mxInterimPopover->SetText(SvxResId(RID_SVXSTR_FRAME_STYLE)); |
3868 | |
|
3869 | 0 | return mxInterimPopover; |
3870 | 0 | } |
3871 | | |
3872 | 0 | mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent, |
3873 | 0 | std::make_unique<SvxFrameWindow_Impl>(this, pParent->GetFrameWeld()), true); |
3874 | |
|
3875 | 0 | mxInterimPopover->Show(); |
3876 | |
|
3877 | 0 | mxInterimPopover->SetText(SvxResId(RID_SVXSTR_FRAME)); |
3878 | |
|
3879 | 0 | return mxInterimPopover; |
3880 | 0 | } |
3881 | | |
3882 | | OUString SvxFrameToolBoxControl::getImplementationName() |
3883 | 0 | { |
3884 | 0 | return u"com.sun.star.comp.svx.FrameToolBoxControl"_ustr; |
3885 | 0 | } |
3886 | | |
3887 | | css::uno::Sequence< OUString > SvxFrameToolBoxControl::getSupportedServiceNames() |
3888 | 0 | { |
3889 | 0 | return { u"com.sun.star.frame.ToolbarController"_ustr }; |
3890 | 0 | } |
3891 | | |
3892 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
3893 | | com_sun_star_comp_svx_FrameToolBoxControl_get_implementation( |
3894 | | css::uno::XComponentContext* rContext, |
3895 | | css::uno::Sequence<css::uno::Any> const & ) |
3896 | 0 | { |
3897 | 0 | return cppu::acquire( new SvxFrameToolBoxControl( rContext ) ); |
3898 | 0 | } |
3899 | | |
3900 | | SvxCurrencyToolBoxControl::SvxCurrencyToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext ) : |
3901 | 0 | PopupWindowController( rContext, nullptr, OUString() ), |
3902 | 0 | m_eLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() ), |
3903 | 0 | m_nFormatKey( NUMBERFORMAT_ENTRY_NOT_FOUND ) |
3904 | 0 | { |
3905 | 0 | } |
3906 | | |
3907 | 0 | SvxCurrencyToolBoxControl::~SvxCurrencyToolBoxControl() {} |
3908 | | |
3909 | | namespace |
3910 | | { |
3911 | | /** Implementation of the currency combo widget **/ |
3912 | | class SvxCurrencyList_Impl : public WeldToolbarPopup |
3913 | | { |
3914 | | private: |
3915 | | rtl::Reference<SvxCurrencyToolBoxControl> m_xControl; |
3916 | | std::unique_ptr<weld::TreeView> m_xCurrencyLb; |
3917 | | OUString& m_rSelectedFormat; |
3918 | | LanguageType& m_eSelectedLanguage; |
3919 | | |
3920 | | std::vector<OUString> m_aFormatEntries; |
3921 | | LanguageType m_eFormatLanguage; |
3922 | | DECL_LINK(RowActivatedHdl, weld::TreeView&, bool); |
3923 | | |
3924 | | virtual void GrabFocus() override; |
3925 | | |
3926 | | public: |
3927 | | SvxCurrencyList_Impl(SvxCurrencyToolBoxControl* pControl, weld::Widget* pParent, OUString& rSelectedFormat, LanguageType& eSelectedLanguage) |
3928 | 0 | : WeldToolbarPopup(pControl->getFrameInterface(), pParent, u"svx/ui/currencywindow.ui"_ustr, u"CurrencyWindow"_ustr) |
3929 | 0 | , m_xControl(pControl) |
3930 | 0 | , m_xCurrencyLb(m_xBuilder->weld_tree_view(u"currency"_ustr)) |
3931 | 0 | , m_rSelectedFormat(rSelectedFormat) |
3932 | 0 | , m_eSelectedLanguage(eSelectedLanguage) |
3933 | 0 | { |
3934 | 0 | std::vector< OUString > aList; |
3935 | 0 | std::vector< sal_uInt16 > aCurrencyList; |
3936 | 0 | const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable(); |
3937 | 0 | sal_uInt16 nLen = rCurrencyTable.size(); |
3938 | |
|
3939 | 0 | SvNumberFormatter aFormatter( m_xControl->getContext(), LANGUAGE_SYSTEM ); |
3940 | 0 | m_eFormatLanguage = aFormatter.GetLanguage(); |
3941 | |
|
3942 | 0 | std::vector<sfx::CurrencyID> aCurrencyIDs; |
3943 | |
|
3944 | 0 | if (SfxObjectShell* pDocShell = SfxObjectShell::Current()) |
3945 | 0 | if (auto pModelAccessor = pDocShell->GetDocumentModelAccessor()) |
3946 | 0 | aCurrencyIDs = pModelAccessor->getDocumentCurrencies(); |
3947 | |
|
3948 | 0 | SvxCurrencyToolBoxControl::GetCurrencySymbols(aList, true, aCurrencyList, aCurrencyIDs); |
3949 | |
|
3950 | 0 | sal_uInt16 nPos = 0, nCount = 0; |
3951 | 0 | sal_Int32 nSelectedPos = -1; |
3952 | 0 | bool bIsSymbol; |
3953 | 0 | NfWSStringsDtor aStringsDtor; |
3954 | |
|
3955 | 0 | OUString sLongestString; |
3956 | |
|
3957 | 0 | m_xCurrencyLb->freeze(); |
3958 | 0 | for( const auto& rItem : aList ) |
3959 | 0 | { |
3960 | 0 | sal_uInt16& rCurrencyIndex = aCurrencyList[ nCount ]; |
3961 | 0 | if ( rCurrencyIndex < nLen ) |
3962 | 0 | { |
3963 | 0 | m_xCurrencyLb->append_text(rItem); |
3964 | |
|
3965 | 0 | if (rItem.getLength() > sLongestString.getLength()) |
3966 | 0 | sLongestString = rItem; |
3967 | |
|
3968 | 0 | bIsSymbol = nPos >= nLen; |
3969 | |
|
3970 | 0 | sal_uInt16 nDefaultFormat; |
3971 | 0 | const NfCurrencyEntry& rCurrencyEntry = rCurrencyTable[ rCurrencyIndex ]; |
3972 | 0 | if (rCurrencyIndex == 0) |
3973 | 0 | { |
3974 | | // Stored with system locale, but we want the resolved |
3975 | | // full LCID format string. For example |
3976 | | // "[$$-409]#,##0.00" instead of "[$$]#,##0.00". |
3977 | 0 | NfCurrencyEntry aCurrencyEntry( rCurrencyEntry); |
3978 | 0 | aCurrencyEntry.SetLanguage( LanguageTag( aCurrencyEntry.GetLanguage()).getLanguageType()); |
3979 | 0 | nDefaultFormat = aFormatter.GetCurrencyFormatStrings( aStringsDtor, aCurrencyEntry, bIsSymbol); |
3980 | 0 | } |
3981 | 0 | else |
3982 | 0 | { |
3983 | 0 | nDefaultFormat = aFormatter.GetCurrencyFormatStrings( aStringsDtor, rCurrencyEntry, bIsSymbol); |
3984 | 0 | } |
3985 | 0 | const OUString& rFormatStr = aStringsDtor[ nDefaultFormat ]; |
3986 | 0 | m_aFormatEntries.push_back( rFormatStr ); |
3987 | 0 | if( rFormatStr == m_rSelectedFormat ) |
3988 | 0 | nSelectedPos = nPos; |
3989 | 0 | ++nPos; |
3990 | 0 | } |
3991 | 0 | ++nCount; |
3992 | 0 | } |
3993 | 0 | m_xCurrencyLb->thaw(); |
3994 | | // enable multiple selection enabled so we can start with nothing selected |
3995 | 0 | m_xCurrencyLb->set_selection_mode(SelectionMode::Multiple); |
3996 | 0 | m_xCurrencyLb->connect_row_activated( LINK( this, SvxCurrencyList_Impl, RowActivatedHdl ) ); |
3997 | 0 | m_xCurrencyLb->select( nSelectedPos ); |
3998 | | |
3999 | | // gtk will initially make a best guess depending on the first few entries, so copy the probable |
4000 | | // longest entry to the start temporarily and force in the width at this point |
4001 | 0 | m_xCurrencyLb->insert_text(0, sLongestString); |
4002 | 0 | m_xCurrencyLb->set_size_request(m_xCurrencyLb->get_preferred_size().Width(), m_xCurrencyLb->get_height_rows(12)); |
4003 | 0 | m_xCurrencyLb->remove(0); |
4004 | 0 | } |
4005 | | }; |
4006 | | |
4007 | | void SvxCurrencyList_Impl::GrabFocus() |
4008 | 0 | { |
4009 | 0 | m_xCurrencyLb->grab_focus(); |
4010 | 0 | } |
4011 | | |
4012 | | IMPL_LINK_NOARG(SvxCurrencyList_Impl, RowActivatedHdl, weld::TreeView&, bool) |
4013 | 0 | { |
4014 | 0 | if (!m_xControl.is()) |
4015 | 0 | return true; |
4016 | | |
4017 | | // multiple selection enabled so we can start with nothing selected, |
4018 | | // so force single selection after something is picked |
4019 | 0 | int nSelected = m_xCurrencyLb->get_selected_index(); |
4020 | 0 | if (nSelected == -1) |
4021 | 0 | return true; |
4022 | | |
4023 | 0 | m_xCurrencyLb->set_selection_mode(SelectionMode::Single); |
4024 | |
|
4025 | 0 | m_rSelectedFormat = m_aFormatEntries[nSelected]; |
4026 | 0 | m_eSelectedLanguage = m_eFormatLanguage; |
4027 | |
|
4028 | 0 | m_xControl->execute(nSelected + 1); |
4029 | |
|
4030 | 0 | m_xControl->EndPopupMode(); |
4031 | |
|
4032 | 0 | return true; |
4033 | 0 | } |
4034 | | } |
4035 | | |
4036 | | void SvxCurrencyToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) |
4037 | 0 | { |
4038 | 0 | PopupWindowController::initialize(rArguments); |
4039 | |
|
4040 | 0 | if (m_pToolbar) |
4041 | 0 | { |
4042 | 0 | mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar)); |
4043 | 0 | m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel()); |
4044 | 0 | return; |
4045 | 0 | } |
4046 | | |
4047 | 0 | ToolBox* pToolBox = nullptr; |
4048 | 0 | ToolBoxItemId nId; |
4049 | 0 | if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL) |
4050 | 0 | pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWN | pToolBox->GetItemBits(nId)); |
4051 | 0 | } |
4052 | | |
4053 | | std::unique_ptr<WeldToolbarPopup> SvxCurrencyToolBoxControl::weldPopupWindow() |
4054 | 0 | { |
4055 | 0 | return std::make_unique<SvxCurrencyList_Impl>(this, m_pToolbar, m_aFormatString, m_eLanguage); |
4056 | 0 | } |
4057 | | |
4058 | | VclPtr<vcl::Window> SvxCurrencyToolBoxControl::createVclPopupWindow( vcl::Window* pParent ) |
4059 | 0 | { |
4060 | 0 | mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent, |
4061 | 0 | std::make_unique<SvxCurrencyList_Impl>(this, pParent->GetFrameWeld(), m_aFormatString, m_eLanguage)); |
4062 | |
|
4063 | 0 | mxInterimPopover->Show(); |
4064 | |
|
4065 | 0 | return mxInterimPopover; |
4066 | 0 | } |
4067 | | |
4068 | | void SvxCurrencyToolBoxControl::execute( sal_Int16 nSelectModifier ) |
4069 | 0 | { |
4070 | 0 | sal_uInt32 nFormatKey; |
4071 | 0 | if (m_aFormatString.isEmpty()) |
4072 | 0 | nFormatKey = NUMBERFORMAT_ENTRY_NOT_FOUND; |
4073 | 0 | else |
4074 | 0 | { |
4075 | 0 | if ( nSelectModifier > 0 ) |
4076 | 0 | { |
4077 | 0 | try |
4078 | 0 | { |
4079 | 0 | uno::Reference< util::XNumberFormatsSupplier > xRef( m_xFrame->getController()->getModel(), uno::UNO_QUERY ); |
4080 | 0 | uno::Reference< util::XNumberFormats > rxNumberFormats( xRef->getNumberFormats(), uno::UNO_SET_THROW ); |
4081 | 0 | css::lang::Locale aLocale = LanguageTag::convertToLocale( m_eLanguage ); |
4082 | 0 | nFormatKey = rxNumberFormats->queryKey( m_aFormatString, aLocale, false ); |
4083 | 0 | if ( nFormatKey == NUMBERFORMAT_ENTRY_NOT_FOUND ) |
4084 | 0 | nFormatKey = rxNumberFormats->addNew( m_aFormatString, aLocale ); |
4085 | 0 | } |
4086 | 0 | catch( const uno::Exception& ) |
4087 | 0 | { |
4088 | 0 | nFormatKey = m_nFormatKey; |
4089 | 0 | } |
4090 | 0 | } |
4091 | 0 | else |
4092 | 0 | nFormatKey = m_nFormatKey; |
4093 | 0 | } |
4094 | |
|
4095 | 0 | if( nFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND ) |
4096 | 0 | { |
4097 | 0 | Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(u"NumberFormatCurrency"_ustr, |
4098 | 0 | nFormatKey) }; |
4099 | 0 | dispatchCommand( m_aCommandURL, aArgs ); |
4100 | 0 | m_nFormatKey = nFormatKey; |
4101 | 0 | } |
4102 | 0 | else |
4103 | 0 | PopupWindowController::execute( nSelectModifier ); |
4104 | 0 | } |
4105 | | |
4106 | | OUString SvxCurrencyToolBoxControl::getImplementationName() |
4107 | 0 | { |
4108 | 0 | return u"com.sun.star.comp.svx.CurrencyToolBoxControl"_ustr; |
4109 | 0 | } |
4110 | | |
4111 | | css::uno::Sequence<OUString> SvxCurrencyToolBoxControl::getSupportedServiceNames() |
4112 | 0 | { |
4113 | 0 | return { u"com.sun.star.frame.ToolbarController"_ustr }; |
4114 | 0 | } |
4115 | | |
4116 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
4117 | | com_sun_star_comp_svx_CurrencyToolBoxControl_get_implementation( |
4118 | | css::uno::XComponentContext* rContext, |
4119 | | css::uno::Sequence<css::uno::Any> const & ) |
4120 | 0 | { |
4121 | 0 | return cppu::acquire( new SvxCurrencyToolBoxControl( rContext ) ); |
4122 | 0 | } |
4123 | | |
4124 | | Reference< css::accessibility::XAccessible > SvxFontNameBox_Impl::CreateAccessible() |
4125 | 0 | { |
4126 | 0 | FillList(); |
4127 | 0 | return InterimItemWindow::CreateAccessible(); |
4128 | 0 | } |
4129 | | |
4130 | | //static |
4131 | | void SvxCurrencyToolBoxControl::GetCurrencySymbols(std::vector<OUString>& rList, bool bFlag, |
4132 | | std::vector<sal_uInt16>& rCurrencyList, |
4133 | | std::vector<sfx::CurrencyID> const& rDocumentCurrencyIDs) |
4134 | 0 | { |
4135 | 0 | rCurrencyList.clear(); |
4136 | |
|
4137 | 0 | static constexpr OUString aTwoSpace = u" "_ustr; |
4138 | 0 | const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable(); |
4139 | 0 | sal_uInt16 nCount = rCurrencyTable.size(); |
4140 | |
|
4141 | 0 | sal_uInt16 nStart = 1; |
4142 | |
|
4143 | 0 | LanguageTag eLangTag = Application::GetSettings().GetLanguageTag(); |
4144 | 0 | OUString aString(ApplyLreOrRleEmbedding(rCurrencyTable[0].GetBankSymbol())); |
4145 | 0 | aString += aTwoSpace; |
4146 | 0 | aString += ApplyLreOrRleEmbedding(rCurrencyTable[0].GetSymbol()); |
4147 | 0 | aString += aTwoSpace; |
4148 | 0 | aString += ApplyLreOrRleEmbedding(SvtLanguageTable::GetLanguageString(eLangTag.getLanguageType())); |
4149 | 0 | aString += aTwoSpace; |
4150 | 0 | aString += ApplyLreOrRleEmbedding(SvtLanguageTable::GetLanguageString(rCurrencyTable[0].GetLanguage())); |
4151 | |
|
4152 | 0 | rList.push_back( aString ); |
4153 | 0 | rCurrencyList.push_back( sal_uInt16(-1) ); // nAuto |
4154 | |
|
4155 | 0 | if( bFlag ) |
4156 | 0 | { |
4157 | 0 | rList.push_back( aString ); |
4158 | 0 | rCurrencyList.push_back( 0 ); |
4159 | 0 | ++nStart; |
4160 | 0 | } |
4161 | |
|
4162 | 0 | CollatorWrapper aCollator( ::comphelper::getProcessComponentContext() ); |
4163 | 0 | aCollator.loadDefaultCollator(eLangTag.getLocale(), 0); |
4164 | |
|
4165 | 0 | for( sal_uInt16 i = 1; i < nCount; ++i ) |
4166 | 0 | { |
4167 | 0 | auto& rCurrencyEntry = rCurrencyTable[i]; |
4168 | |
|
4169 | 0 | OUString aStr( ApplyLreOrRleEmbedding(rCurrencyEntry.GetBankSymbol())); |
4170 | 0 | aStr += aTwoSpace; |
4171 | 0 | aStr += ApplyLreOrRleEmbedding(rCurrencyEntry.GetSymbol()); |
4172 | 0 | aStr += aTwoSpace; |
4173 | 0 | aStr += ApplyLreOrRleEmbedding(SvtLanguageTable::GetLanguageString(rCurrencyEntry.GetLanguage())); |
4174 | |
|
4175 | 0 | std::vector<OUString>::size_type j = nStart; |
4176 | | |
4177 | | // Search if the currency is present in the document |
4178 | 0 | auto iter = std::find_if(rDocumentCurrencyIDs.begin(), rDocumentCurrencyIDs.end(), [rCurrencyEntry](sfx::CurrencyID const& rCurrency) |
4179 | 0 | { |
4180 | 0 | const NfCurrencyEntry* pEntry = SvNumberFormatter::GetCurrencyEntry(o3tl::temporary(bool()), rCurrency.aSymbol, rCurrency.aExtension, rCurrency.eLanguage); |
4181 | |
|
4182 | 0 | if (pEntry) |
4183 | 0 | return rCurrencyEntry.GetLanguage() == pEntry->GetLanguage() && rCurrencyEntry.GetSymbol() == pEntry->GetSymbol(); |
4184 | | |
4185 | 0 | return false; |
4186 | 0 | }); |
4187 | | |
4188 | | // If currency is in document, insert it on top |
4189 | 0 | if (iter != rDocumentCurrencyIDs.end()) |
4190 | 0 | { |
4191 | 0 | nStart++; |
4192 | 0 | } |
4193 | 0 | else |
4194 | 0 | { |
4195 | 0 | for( ; j < rList.size(); ++j ) |
4196 | 0 | { |
4197 | 0 | if ( aCollator.compareString( aStr, rList[j] ) < 0 ) |
4198 | 0 | break; // insert before first greater than |
4199 | 0 | } |
4200 | 0 | } |
4201 | |
|
4202 | 0 | rList.insert( rList.begin() + j, aStr ); |
4203 | 0 | rCurrencyList.insert( rCurrencyList.begin() + j, i ); |
4204 | 0 | } |
4205 | | |
4206 | | // Append ISO codes to symbol list. |
4207 | | // XXX If this is to be changed, various other places would had to be |
4208 | | // adapted that assume this order! |
4209 | 0 | std::vector<OUString>::size_type nCont = rList.size(); |
4210 | |
|
4211 | 0 | for ( sal_uInt16 i = 1; i < nCount; ++i ) |
4212 | 0 | { |
4213 | 0 | bool bInsert = true; |
4214 | 0 | auto& rCurrencyEntry = rCurrencyTable[i]; |
4215 | 0 | OUString aStr( ApplyLreOrRleEmbedding(rCurrencyEntry.GetBankSymbol())); |
4216 | |
|
4217 | 0 | std::vector<OUString>::size_type j = nCont; |
4218 | 0 | for ( ; j < rList.size() && bInsert; ++j ) |
4219 | 0 | { |
4220 | 0 | if( rList[j] == aStr ) |
4221 | 0 | bInsert = false; |
4222 | 0 | else if ( aCollator.compareString( aStr, rList[j] ) < 0 ) |
4223 | 0 | break; // insert before first greater than |
4224 | 0 | } |
4225 | 0 | if ( bInsert ) |
4226 | 0 | { |
4227 | 0 | rList.insert( rList.begin() + j, aStr ); |
4228 | 0 | rCurrencyList.insert( rCurrencyList.begin() + j, i ); |
4229 | 0 | } |
4230 | 0 | } |
4231 | 0 | } |
4232 | | |
4233 | | ListBoxColorWrapper::ListBoxColorWrapper(ColorListBox* pControl) |
4234 | 0 | : mpControl(pControl) |
4235 | 0 | { |
4236 | 0 | } |
4237 | | |
4238 | | void ListBoxColorWrapper::operator()( |
4239 | | [[maybe_unused]] const OUString& /*rCommand*/, const NamedColor& rColor) |
4240 | 0 | { |
4241 | 0 | mpControl->Selected(rColor); |
4242 | 0 | } |
4243 | | |
4244 | | void ColorListBox::EnsurePaletteManager() |
4245 | 0 | { |
4246 | 0 | if (!m_xPaletteManager) |
4247 | 0 | { |
4248 | 0 | m_xPaletteManager = std::make_shared<PaletteManager>(); |
4249 | 0 | m_xPaletteManager->SetColorSelectFunction(std::ref(m_aColorWrapper)); |
4250 | 0 | } |
4251 | 0 | } |
4252 | | |
4253 | | void ColorListBox::SetSlotId(sal_uInt16 nSlotId, bool bShowNoneButton) |
4254 | 0 | { |
4255 | 0 | m_nSlotId = nSlotId; |
4256 | 0 | m_bShowNoneButton = bShowNoneButton; |
4257 | 0 | m_xButton->set_popover(nullptr); |
4258 | 0 | m_xColorWindow.reset(); |
4259 | 0 | m_aSelectedColor = bShowNoneButton ? GetNoneColor() : GetAutoColor(m_nSlotId); |
4260 | 0 | ShowPreview(m_aSelectedColor); |
4261 | 0 | createColorWindow(); |
4262 | 0 | } |
4263 | | |
4264 | | ColorListBox::ColorListBox(std::unique_ptr<weld::MenuButton> pControl, |
4265 | | TopLevelParentFunction aTopLevelParentFunction) |
4266 | 0 | : m_xButton(std::move(pControl)) |
4267 | 0 | , m_aColorWrapper(this) |
4268 | 0 | , m_aAutoDisplayColor(Application::GetSettings().GetStyleSettings().GetDialogColor()) |
4269 | 0 | , m_nSlotId(0) |
4270 | 0 | , m_bShowNoneButton(false) |
4271 | 0 | , m_aTopLevelParentFunction(std::move(aTopLevelParentFunction)) |
4272 | 0 | { |
4273 | 0 | m_xButton->connect_toggled(LINK(this, ColorListBox, ToggleHdl)); |
4274 | 0 | m_aSelectedColor = GetAutoColor(m_nSlotId); |
4275 | 0 | LockWidthRequest(CalcBestWidthRequest()); |
4276 | 0 | ShowPreview(m_aSelectedColor); |
4277 | 0 | } |
4278 | | |
4279 | | IMPL_LINK(ColorListBox, ToggleHdl, weld::Toggleable&, rButton, void) |
4280 | 0 | { |
4281 | 0 | if (rButton.get_active()) |
4282 | 0 | { |
4283 | 0 | ColorWindow* pColorWindow = getColorWindow(); |
4284 | 0 | if (pColorWindow && !comphelper::LibreOfficeKit::isActive()) |
4285 | 0 | pColorWindow->GrabFocus(); |
4286 | 0 | } |
4287 | 0 | } |
4288 | | |
4289 | | ColorListBox::~ColorListBox() |
4290 | 0 | { |
4291 | 0 | } |
4292 | | |
4293 | | ColorWindow* ColorListBox::getColorWindow() const |
4294 | 0 | { |
4295 | 0 | if (!m_xColorWindow) |
4296 | 0 | const_cast<ColorListBox*>(this)->createColorWindow(); |
4297 | 0 | return m_xColorWindow.get(); |
4298 | 0 | } |
4299 | | |
4300 | | void ColorListBox::createColorWindow() |
4301 | 0 | { |
4302 | 0 | const SfxViewFrame* pViewFrame = SfxViewFrame::Current(); |
4303 | 0 | const SfxFrame* pFrame = pViewFrame ? &pViewFrame->GetFrame() : nullptr; |
4304 | 0 | css::uno::Reference<css::frame::XFrame> xFrame(pFrame ? pFrame->GetFrameInterface() : uno::Reference<css::frame::XFrame>()); |
4305 | |
|
4306 | 0 | EnsurePaletteManager(); |
4307 | |
|
4308 | 0 | m_xColorWindow.reset(new ColorWindow( |
4309 | 0 | OUString() /*m_aCommandURL*/, |
4310 | 0 | m_xPaletteManager, |
4311 | 0 | m_aColorStatus, |
4312 | 0 | m_nSlotId, |
4313 | 0 | xFrame, |
4314 | 0 | m_xButton.get(), |
4315 | 0 | m_aTopLevelParentFunction, |
4316 | 0 | m_aColorWrapper)); |
4317 | |
|
4318 | 0 | SetNoSelection(); |
4319 | 0 | m_xButton->set_popover(m_xColorWindow->getTopLevel()); |
4320 | 0 | if (m_bShowNoneButton) |
4321 | 0 | m_xColorWindow->ShowNoneButton(); |
4322 | 0 | m_xColorWindow->SelectEntry(m_aSelectedColor); |
4323 | 0 | } |
4324 | | |
4325 | | void ColorListBox::SelectEntry(const NamedColor& rColor) |
4326 | 0 | { |
4327 | 0 | if (o3tl::trim(rColor.m_aName).empty()) |
4328 | 0 | { |
4329 | 0 | SelectEntry(rColor.m_aColor); |
4330 | 0 | return; |
4331 | 0 | } |
4332 | 0 | ColorWindow* pColorWindow = getColorWindow(); |
4333 | 0 | pColorWindow->SelectEntry(rColor); |
4334 | 0 | m_aSelectedColor = pColorWindow->GetSelectEntryColor(); |
4335 | 0 | ShowPreview(m_aSelectedColor); |
4336 | 0 | } |
4337 | | |
4338 | | void ColorListBox::SelectEntry(const Color& rColor) |
4339 | 0 | { |
4340 | 0 | ColorWindow* pColorWindow = getColorWindow(); |
4341 | 0 | pColorWindow->SelectEntry(rColor); |
4342 | 0 | m_aSelectedColor = pColorWindow->GetSelectEntryColor(); |
4343 | 0 | ShowPreview(m_aSelectedColor); |
4344 | 0 | } |
4345 | | |
4346 | | void ColorListBox::Selected(const NamedColor& rColor) |
4347 | 0 | { |
4348 | 0 | ShowPreview(rColor); |
4349 | 0 | m_aSelectedColor = rColor; |
4350 | 0 | if (m_aSelectedLink.IsSet()) |
4351 | 0 | m_aSelectedLink.Call(*this); |
4352 | 0 | } |
4353 | | |
4354 | | //to avoid the box resizing every time the color is changed to |
4355 | | //the optimal size of the individual color, get the longest |
4356 | | //standard color and stick with that as the size for all |
4357 | | int ColorListBox::CalcBestWidthRequest() |
4358 | 0 | { |
4359 | 0 | NamedColor aLongestColor; |
4360 | 0 | tools::Long nMaxStandardColorTextWidth = 0; |
4361 | 0 | XColorListRef const xColorTable = XColorList::CreateStdColorList(); |
4362 | 0 | for (tools::Long i = 0; i != xColorTable->Count(); ++i) |
4363 | 0 | { |
4364 | 0 | XColorEntry& rEntry = *xColorTable->GetColor(i); |
4365 | 0 | auto nColorTextWidth = m_xButton->get_pixel_size(rEntry.GetName()).Width(); |
4366 | 0 | if (nColorTextWidth > nMaxStandardColorTextWidth) |
4367 | 0 | { |
4368 | 0 | nMaxStandardColorTextWidth = nColorTextWidth; |
4369 | 0 | aLongestColor.m_aName = rEntry.GetName(); |
4370 | 0 | } |
4371 | 0 | } |
4372 | 0 | ShowPreview(aLongestColor); |
4373 | 0 | return m_xButton->get_preferred_size().Width(); |
4374 | 0 | } |
4375 | | |
4376 | | void ColorListBox::LockWidthRequest(int nWidth) |
4377 | 0 | { |
4378 | 0 | m_xButton->set_size_request(nWidth, -1); |
4379 | 0 | } |
4380 | | |
4381 | | void ColorListBox::ShowPreview(const NamedColor &rColor) |
4382 | 0 | { |
4383 | | // ScGridWindow::UpdateAutoFilterFromMenu is similar |
4384 | 0 | const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); |
4385 | 0 | Size aImageSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize()); |
4386 | |
|
4387 | 0 | ScopedVclPtrInstance<VirtualDevice> xDevice; |
4388 | 0 | xDevice->SetOutputSize(aImageSize); |
4389 | 0 | const tools::Rectangle aRect(Point(0, 0), aImageSize); |
4390 | 0 | if (m_bShowNoneButton && rColor.m_aColor == COL_NONE_COLOR) |
4391 | 0 | { |
4392 | 0 | const Color aW(COL_WHITE); |
4393 | 0 | const Color aG(0xef, 0xef, 0xef); |
4394 | 0 | int nMinDim = std::min(aImageSize.Width(), aImageSize.Height()) + 1; |
4395 | 0 | int nCheckSize = nMinDim / 3; |
4396 | 0 | xDevice->DrawCheckered(aRect.TopLeft(), aRect.GetSize(), std::min(nCheckSize, 8), aW, aG); |
4397 | 0 | xDevice->SetFillColor(); |
4398 | 0 | } |
4399 | 0 | else |
4400 | 0 | { |
4401 | 0 | if (rColor.m_aColor == COL_AUTO) |
4402 | 0 | xDevice->SetFillColor(m_aAutoDisplayColor); |
4403 | 0 | else |
4404 | 0 | xDevice->SetFillColor(rColor.m_aColor); |
4405 | 0 | } |
4406 | |
|
4407 | 0 | xDevice->SetLineColor(rStyleSettings.GetDisableColor()); |
4408 | 0 | xDevice->DrawRect(aRect); |
4409 | |
|
4410 | 0 | m_xButton->set_image(xDevice.get()); |
4411 | 0 | m_xButton->set_label(rColor.m_aName); |
4412 | 0 | } |
4413 | | |
4414 | | MenuOrToolMenuButton::MenuOrToolMenuButton(weld::MenuButton* pMenuButton) |
4415 | 0 | : m_pMenuButton(pMenuButton) |
4416 | 0 | , m_pToolbar(nullptr) |
4417 | 0 | , m_pControl(nullptr) |
4418 | 0 | , m_nId(0) |
4419 | 0 | { |
4420 | 0 | } |
4421 | | |
4422 | | MenuOrToolMenuButton::MenuOrToolMenuButton(weld::Toolbar* pToolbar, OUString aIdent) |
4423 | 0 | : m_pMenuButton(nullptr) |
4424 | 0 | , m_pToolbar(pToolbar) |
4425 | 0 | , m_aIdent(std::move(aIdent)) |
4426 | 0 | , m_pControl(nullptr) |
4427 | 0 | , m_nId(0) |
4428 | 0 | { |
4429 | 0 | } |
4430 | | |
4431 | | MenuOrToolMenuButton::MenuOrToolMenuButton(SvxColorToolBoxControl* pControl, ToolBox* pToolbar, ToolBoxItemId nId) |
4432 | 0 | : m_pMenuButton(nullptr) |
4433 | 0 | , m_pToolbar(nullptr) |
4434 | 0 | , m_pControl(pControl) |
4435 | 0 | , m_xToolBox(pToolbar) |
4436 | 0 | , m_nId(nId) |
4437 | 0 | { |
4438 | 0 | } |
4439 | | |
4440 | | MenuOrToolMenuButton::~MenuOrToolMenuButton() |
4441 | 0 | { |
4442 | 0 | } |
4443 | | |
4444 | | bool MenuOrToolMenuButton::get_active() const |
4445 | 0 | { |
4446 | 0 | if (m_pMenuButton) |
4447 | 0 | return m_pMenuButton->get_active(); |
4448 | 0 | if (m_pToolbar) |
4449 | 0 | return m_pToolbar->get_menu_item_active(m_aIdent); |
4450 | 0 | return m_xToolBox->GetDownItemId() == m_nId; |
4451 | 0 | } |
4452 | | |
4453 | | void MenuOrToolMenuButton::set_inactive() const |
4454 | 0 | { |
4455 | 0 | if (m_pMenuButton) |
4456 | 0 | { |
4457 | 0 | if (m_pMenuButton->get_active()) |
4458 | 0 | m_pMenuButton->set_active(false); |
4459 | 0 | return; |
4460 | 0 | } |
4461 | 0 | if (m_pToolbar) |
4462 | 0 | { |
4463 | 0 | if (m_pToolbar->get_menu_item_active(m_aIdent)) |
4464 | 0 | m_pToolbar->set_menu_item_active(m_aIdent, false); |
4465 | 0 | return; |
4466 | 0 | } |
4467 | 0 | m_pControl->EndPopupMode(); |
4468 | 0 | } |
4469 | | |
4470 | | weld::Widget* MenuOrToolMenuButton::get_widget() const |
4471 | 0 | { |
4472 | 0 | if (m_pMenuButton) |
4473 | 0 | return m_pMenuButton; |
4474 | 0 | if (m_pToolbar) |
4475 | 0 | return m_pToolbar; |
4476 | 0 | return m_xToolBox->GetFrameWeld(); |
4477 | 0 | } |
4478 | | |
4479 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |