/src/libreoffice/vcl/source/weld/EntryFormatter.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
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 | | |
10 | | #include <tools/color.hxx> |
11 | | #include <vcl/settings.hxx> |
12 | | #include <vcl/svapp.hxx> |
13 | | #include <vcl/weld/Entry.hxx> |
14 | | #include <vcl/weld/EntryFormatter.hxx> |
15 | | #include <vcl/weld/FormattedSpinButton.hxx> |
16 | | |
17 | | namespace weld |
18 | | { |
19 | | EntryFormatter::EntryFormatter(weld::FormattedSpinButton& rSpinButton) |
20 | 0 | : m_rEntry(rSpinButton) |
21 | 0 | , m_pSpinButton(&rSpinButton) |
22 | 0 | , m_eOptions(Application::GetSettings().GetStyleSettings().GetSelectionOptions()) |
23 | 0 | { |
24 | 0 | Init(); |
25 | 0 | } |
26 | | |
27 | | EntryFormatter::EntryFormatter(weld::Entry& rEntry) |
28 | 0 | : m_rEntry(rEntry) |
29 | 0 | , m_pSpinButton(nullptr) |
30 | 0 | , m_eOptions(Application::GetSettings().GetStyleSettings().GetSelectionOptions()) |
31 | 0 | { |
32 | 0 | Init(); |
33 | 0 | } |
34 | | |
35 | | EntryFormatter::~EntryFormatter() |
36 | 0 | { |
37 | 0 | m_rEntry.connect_changed(Link<weld::TextWidget&, void>()); |
38 | 0 | m_rEntry.connect_focus_out(Link<weld::Widget&, void>()); |
39 | 0 | if (m_pSpinButton) |
40 | 0 | m_pSpinButton->SetFormatter(nullptr); |
41 | 0 | } |
42 | | |
43 | | void EntryFormatter::Init() |
44 | 0 | { |
45 | 0 | m_rEntry.connect_changed(LINK(this, EntryFormatter, ModifyHdl)); |
46 | 0 | m_rEntry.connect_focus_out(LINK(this, EntryFormatter, FocusOutHdl)); |
47 | 0 | if (m_pSpinButton) |
48 | 0 | m_pSpinButton->SetFormatter(this); |
49 | 0 | } |
50 | | |
51 | | Selection EntryFormatter::GetEntrySelection() const |
52 | 0 | { |
53 | 0 | int nStartPos, nEndPos; |
54 | 0 | m_rEntry.get_selection_bounds(nStartPos, nEndPos); |
55 | 0 | return Selection(nStartPos, nEndPos); |
56 | 0 | } |
57 | | |
58 | 0 | OUString EntryFormatter::GetEntryText() const { return m_rEntry.get_text(); } |
59 | | |
60 | | void EntryFormatter::SetEntryText(const OUString& rText, const Selection& rSel) |
61 | 0 | { |
62 | 0 | m_rEntry.set_text(rText); |
63 | 0 | auto nMin = rSel.Min(); |
64 | 0 | auto nMax = rSel.Max(); |
65 | 0 | m_rEntry.select_region(nMin < 0 ? 0 : nMin, nMax == SELECTION_MAX ? -1 : nMax); |
66 | 0 | } |
67 | | |
68 | | void EntryFormatter::SetEntryTextColor(const Color* pColor) |
69 | 0 | { |
70 | 0 | m_rEntry.set_font_color(pColor ? *pColor : COL_AUTO); |
71 | 0 | } |
72 | | |
73 | | void EntryFormatter::UpdateCurrentValue(double dCurrentValue) |
74 | 0 | { |
75 | 0 | Formatter::UpdateCurrentValue(dCurrentValue); |
76 | 0 | if (m_pSpinButton) |
77 | 0 | m_pSpinButton->sync_value_from_formatter(); |
78 | 0 | } |
79 | | |
80 | | void EntryFormatter::ClearMinValue() |
81 | 0 | { |
82 | 0 | Formatter::ClearMinValue(); |
83 | 0 | if (m_pSpinButton) |
84 | 0 | m_pSpinButton->sync_range_from_formatter(); |
85 | 0 | } |
86 | | |
87 | | void EntryFormatter::SetMinValue(double dMin) |
88 | 0 | { |
89 | 0 | Formatter::SetMinValue(dMin); |
90 | 0 | if (m_pSpinButton) |
91 | 0 | m_pSpinButton->sync_range_from_formatter(); |
92 | 0 | } |
93 | | |
94 | | void EntryFormatter::ClearMaxValue() |
95 | 0 | { |
96 | 0 | Formatter::ClearMaxValue(); |
97 | 0 | if (m_pSpinButton) |
98 | 0 | m_pSpinButton->sync_range_from_formatter(); |
99 | 0 | } |
100 | | |
101 | | void EntryFormatter::SetMaxValue(double dMin) |
102 | 0 | { |
103 | 0 | Formatter::SetMaxValue(dMin); |
104 | 0 | if (m_pSpinButton) |
105 | 0 | m_pSpinButton->sync_range_from_formatter(); |
106 | 0 | } |
107 | | |
108 | | void EntryFormatter::SetSpinSize(double dStep) |
109 | 0 | { |
110 | 0 | Formatter::SetSpinSize(dStep); |
111 | 0 | if (m_pSpinButton) |
112 | 0 | m_pSpinButton->sync_increments_from_formatter(); |
113 | 0 | } |
114 | | |
115 | 0 | SelectionOptions EntryFormatter::GetEntrySelectionOptions() const { return m_eOptions; } |
116 | | |
117 | 0 | void EntryFormatter::FieldModified() { m_aModifyHdl.Call(m_rEntry); } |
118 | | |
119 | | IMPL_LINK_NOARG(EntryFormatter, ModifyHdl, weld::TextWidget&, void) |
120 | 0 | { |
121 | | // This leads to FieldModified getting called at the end of Modify() and |
122 | | // FieldModified then calls any modification callback |
123 | 0 | Modify(); |
124 | 0 | } |
125 | | |
126 | | IMPL_LINK_NOARG(EntryFormatter, FocusOutHdl, weld::Widget&, void) |
127 | 0 | { |
128 | 0 | EntryLostFocus(); |
129 | 0 | if (m_pSpinButton) |
130 | 0 | m_pSpinButton->signal_value_changed(); |
131 | 0 | m_aFocusOutHdl.Call(m_rEntry); |
132 | 0 | } |
133 | | } |
134 | | |
135 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |