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