Line data Source code
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 :
21 : #include <comphelper/string.hxx>
22 : #include <vcl/builder.hxx>
23 : #include "actctrl.hxx"
24 :
25 0 : void NumEditAction::Action()
26 : {
27 0 : aActionLink.Call( this );
28 0 : }
29 :
30 :
31 0 : long NumEditAction::Notify( NotifyEvent& rNEvt )
32 : {
33 0 : long nHandled = 0;
34 :
35 0 : if ( rNEvt.GetType() == EVENT_KEYINPUT )
36 : {
37 0 : const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
38 0 : const KeyCode aKeyCode = pKEvt->GetKeyCode();
39 0 : const sal_uInt16 nModifier = aKeyCode.GetModifier();
40 0 : if( aKeyCode.GetCode() == KEY_RETURN &&
41 : !nModifier)
42 : {
43 0 : Action();
44 0 : nHandled = 1;
45 : }
46 :
47 : }
48 0 : if(!nHandled)
49 0 : NumericField::Notify( rNEvt );
50 0 : return nHandled;
51 : }
52 :
53 0 : NoSpaceEdit::NoSpaceEdit( Window* pParent, const ResId& rResId)
54 : : Edit(pParent, rResId)
55 0 : , sForbiddenChars(rtl::OUString(" "))
56 : {
57 0 : }
58 :
59 0 : NoSpaceEdit::NoSpaceEdit(Window* pParent)
60 : : Edit(pParent, WB_BORDER|WB_TABSTOP)
61 0 : , sForbiddenChars(rtl::OUString(" "))
62 : {
63 0 : }
64 :
65 0 : NoSpaceEdit::~NoSpaceEdit()
66 : {
67 0 : }
68 :
69 0 : void NoSpaceEdit::KeyInput(const KeyEvent& rEvt)
70 : {
71 0 : sal_Bool bCallParent = sal_True;
72 0 : if(rEvt.GetCharCode())
73 : {
74 0 : rtl::OUString sKey(rEvt.GetCharCode());
75 0 : if( STRING_NOTFOUND != sForbiddenChars.Search(sKey))
76 0 : bCallParent = sal_False;
77 : }
78 0 : if(bCallParent)
79 0 : Edit::KeyInput(rEvt);
80 0 : }
81 :
82 0 : void NoSpaceEdit::Modify()
83 : {
84 0 : Selection aSel = GetSelection();
85 0 : String sTemp = GetText();
86 0 : for(sal_uInt16 i = 0; i < sForbiddenChars.Len(); i++)
87 : {
88 0 : sTemp = comphelper::string::remove(sTemp, sForbiddenChars.GetChar(i));
89 : }
90 0 : sal_uInt16 nDiff = GetText().Len() - sTemp.Len();
91 0 : if(nDiff)
92 : {
93 0 : aSel.setMin(aSel.getMin() - nDiff);
94 0 : aSel.setMax(aSel.getMin());
95 0 : SetText(sTemp);
96 0 : SetSelection(aSel);
97 : }
98 0 : if(GetModifyHdl().IsSet())
99 0 : GetModifyHdl().Call(this);
100 0 : }
101 :
102 0 : ReturnActionEdit::~ReturnActionEdit()
103 : {
104 0 : }
105 :
106 0 : void ReturnActionEdit::KeyInput( const KeyEvent& rEvt)
107 : {
108 0 : const KeyCode aKeyCode = rEvt.GetKeyCode();
109 0 : const sal_uInt16 nModifier = aKeyCode.GetModifier();
110 0 : if( aKeyCode.GetCode() == KEY_RETURN &&
111 : !nModifier)
112 : {
113 0 : if(aReturnActionLink.IsSet())
114 0 : aReturnActionLink.Call(this);
115 : }
116 : else
117 0 : Edit::KeyInput(rEvt);
118 0 : }
119 :
120 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeTableNameEdit(Window *pParent, VclBuilder::stringmap &)
121 : {
122 0 : TableNameEdit* pTableNameEdit = new TableNameEdit(pParent);
123 0 : pTableNameEdit->SetWidthInChars(25);
124 0 : return pTableNameEdit;
125 : }
126 :
127 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeNoSpaceEdit(Window *pParent, VclBuilder::stringmap &)
128 : {
129 0 : return new NoSpaceEdit(pParent);
130 : }
131 :
132 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|