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)
54 : : Edit(pParent, WB_BORDER|WB_TABSTOP)
55 0 : , sForbiddenChars(OUString(" "))
56 : {
57 0 : }
58 :
59 0 : NoSpaceEdit::~NoSpaceEdit()
60 : {
61 0 : }
62 :
63 0 : void NoSpaceEdit::KeyInput(const KeyEvent& rEvt)
64 : {
65 0 : bool bCallParent = true;
66 0 : if(rEvt.GetCharCode())
67 : {
68 0 : OUString sKey(rEvt.GetCharCode());
69 0 : if( STRING_NOTFOUND != sForbiddenChars.Search(sKey))
70 0 : bCallParent = false;
71 : }
72 0 : if(bCallParent)
73 0 : Edit::KeyInput(rEvt);
74 0 : }
75 :
76 0 : void NoSpaceEdit::Modify()
77 : {
78 0 : Selection aSel = GetSelection();
79 0 : OUString sTemp = GetText();
80 0 : for(sal_uInt16 i = 0; i < sForbiddenChars.Len(); i++)
81 : {
82 0 : sTemp = comphelper::string::remove(sTemp, sForbiddenChars.GetChar(i));
83 : }
84 0 : sal_Int32 nDiff = GetText().getLength() - sTemp.getLength();
85 0 : if(nDiff)
86 : {
87 0 : aSel.setMin(aSel.getMin() - nDiff);
88 0 : aSel.setMax(aSel.getMin());
89 0 : SetText(sTemp);
90 0 : SetSelection(aSel);
91 : }
92 0 : if(GetModifyHdl().IsSet())
93 0 : GetModifyHdl().Call(this);
94 0 : }
95 :
96 0 : ReturnActionEdit::~ReturnActionEdit()
97 : {
98 0 : }
99 :
100 0 : void ReturnActionEdit::KeyInput( const KeyEvent& rEvt)
101 : {
102 0 : const KeyCode aKeyCode = rEvt.GetKeyCode();
103 0 : const sal_uInt16 nModifier = aKeyCode.GetModifier();
104 0 : if( aKeyCode.GetCode() == KEY_RETURN &&
105 : !nModifier)
106 : {
107 0 : if(aReturnActionLink.IsSet())
108 0 : aReturnActionLink.Call(this);
109 : }
110 : else
111 0 : Edit::KeyInput(rEvt);
112 0 : }
113 :
114 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeTableNameEdit(Window *pParent, VclBuilder::stringmap &)
115 : {
116 0 : TableNameEdit* pTableNameEdit = new TableNameEdit(pParent);
117 0 : pTableNameEdit->SetWidthInChars(25);
118 0 : return pTableNameEdit;
119 : }
120 :
121 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeNoSpaceEdit(Window *pParent, VclBuilder::stringmap &)
122 : {
123 0 : return new NoSpaceEdit(pParent);
124 99 : }
125 :
126 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|