LibreOffice Module svtools (master) 1
recorditemwindow.cxx
Go to the documentation of this file.
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
21#include <vcl/event.hxx>
22
23RecordItemWindowBase::RecordItemWindowBase(std::unique_ptr<weld::Entry> xEntry)
24 : m_xWidget(std::move(xEntry))
25{
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));
29
30 m_xWidget->show();
31}
32
34
36 : InterimItemWindow(pParent, "svx/ui/absrecbox.ui", "AbsRecBox")
37 , RecordItemWindowBase(m_xBuilder->weld_entry("entry-frame"))
38{
40
41 auto aPrefSize(m_xWidget->get_preferred_size());
42
43 m_xWidget->set_width_chars(1); // so a smaller than default width can be used later
44
45 SetSizePixel(aPrefSize);
46}
47
49{
50 m_xWidget.reset();
52}
53
55
57{
58 if (!_bForce && !m_xWidget->get_value_changed_from_saved())
59 return;
60
61 sal_Int64 nRecord = m_xWidget->get_text().toInt64();
62 if (nRecord < 1)
63 nRecord = 1;
64
65 PositionFired(nRecord);
66
67 m_xWidget->save_value();
68}
69
70IMPL_LINK_NOARG(RecordItemWindowBase, FocusOutHdl, weld::Widget&, void) { FirePosition(false); }
71
73{
74 vcl::KeyCode aCode = rKEvt.GetKeyCode();
75 bool bUp = (aCode.GetCode() == KEY_UP);
76 bool bDown = (aCode.GetCode() == KEY_DOWN);
77
78 if (!aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() && (bUp || bDown))
79 {
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;
89 }
90
91 return false;
92}
93
95{
96 return RecordItemWindowBase::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
97}
98
99void RecordItemWindowBase::PositionFired(sal_Int64 /*nRecord*/) {}
100
101IMPL_LINK(RecordItemWindowBase, KeyInputHdl, const KeyEvent&, rKEvt, bool)
102{
103 return DoKeyInput(rKEvt);
104}
105
107{
108 if (!m_xWidget->get_text().isEmpty())
109 FirePosition(true);
110 return true;
111}
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Image > m_xWidget
bool ChildKeyInput(const KeyEvent &rKEvt)
virtual void dispose() override
void InitControlBase(weld::Widget *pWidget)
const vcl::KeyCode & GetKeyCode() const
RecordItemWindowBase(std::unique_ptr< weld::Entry > xEntry)
virtual void PositionFired(sal_Int64 nRecord)
virtual bool DoKeyInput(const KeyEvent &rEvt)
std::unique_ptr< weld::Entry > m_xWidget
void FirePosition(bool bForce)
virtual void dispose() override
RecordItemWindow(vcl::Window *pParent)
virtual bool DoKeyInput(const KeyEvent &rEvt) override
virtual ~RecordItemWindow() override
bool IsMod1() const
sal_uInt16 GetCode() const
bool IsShift() const
bool IsMod2() const
virtual void SetSizePixel(const Size &rNewSize)
constexpr sal_uInt16 KEY_UP
constexpr sal_uInt16 KEY_DOWN
IMPL_LINK(RecordItemWindowBase, KeyInputHdl, const KeyEvent &, rKEvt, bool)
IMPL_LINK_NOARG(RecordItemWindowBase, FocusOutHdl, weld::Widget &, void)