Get the style color and number just once
[LibreOffice.git] / svtools / source / brwbox / recorditemwindow.cxx
blobb62460499d901a2267cf211832c6d7f22ce872ea
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svtools/recorditemwindow.hxx>
21 #include <vcl/event.hxx>
23 RecordItemWindowBase::RecordItemWindowBase(std::unique_ptr<weld::Entry> xEntry)
24 : m_xWidget(std::move(xEntry))
26 m_xWidget->connect_key_press(LINK(this, RecordItemWindowBase, KeyInputHdl));
27 m_xWidget->connect_activate(LINK(this, RecordItemWindowBase, ActivatedHdl));
28 m_xWidget->connect_focus_out(LINK(this, RecordItemWindowBase, FocusOutHdl));
30 m_xWidget->show();
33 RecordItemWindowBase::~RecordItemWindowBase() {}
35 RecordItemWindow::RecordItemWindow(vcl::Window* pParent)
36 : InterimItemWindow(pParent, u"svx/ui/absrecbox.ui"_ustr, u"AbsRecBox"_ustr)
37 , RecordItemWindowBase(m_xBuilder->weld_entry(u"entry-frame"_ustr))
39 InitControlBase(m_xWidget.get());
41 auto aPrefSize(m_xWidget->get_preferred_size());
43 m_xWidget->set_width_chars(1); // so a smaller than default width can be used later
45 SetSizePixel(aPrefSize);
48 void RecordItemWindow::dispose()
50 m_xWidget.reset();
51 InterimItemWindow::dispose();
54 RecordItemWindow::~RecordItemWindow() { disposeOnce(); }
56 void RecordItemWindowBase::FirePosition(bool _bForce)
58 if (!_bForce && !m_xWidget->get_value_changed_from_saved())
59 return;
61 sal_Int64 nRecord = m_xWidget->get_text().toInt64();
62 if (nRecord < 1)
63 nRecord = 1;
65 PositionFired(nRecord);
67 m_xWidget->save_value();
70 IMPL_LINK_NOARG(RecordItemWindowBase, FocusOutHdl, weld::Widget&, void) { FirePosition(false); }
72 bool RecordItemWindowBase::DoKeyInput(const KeyEvent& rKEvt)
74 vcl::KeyCode aCode = rKEvt.GetKeyCode();
75 bool bUp = (aCode.GetCode() == KEY_UP);
76 bool bDown = (aCode.GetCode() == KEY_DOWN);
78 if (!aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() && (bUp || bDown))
80 sal_Int64 nRecord = m_xWidget->get_text().toInt64();
81 if (bUp)
82 ++nRecord;
83 else
84 --nRecord;
85 if (nRecord < 1)
86 nRecord = 1;
87 m_xWidget->set_text(OUString::number(nRecord));
88 return true;
91 return false;
94 bool RecordItemWindow::DoKeyInput(const KeyEvent& rKEvt)
96 return RecordItemWindowBase::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
99 void RecordItemWindowBase::PositionFired(sal_Int64 /*nRecord*/) {}
101 IMPL_LINK(RecordItemWindowBase, KeyInputHdl, const KeyEvent&, rKEvt, bool)
103 return DoKeyInput(rKEvt);
106 IMPL_LINK_NOARG(RecordItemWindowBase, ActivatedHdl, weld::Entry&, bool)
108 if (!m_xWidget->get_text().isEmpty())
109 FirePosition(true);
110 return true;
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */