xref: /trunk/main/sw/source/ui/cctrl/actctrl.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 
33 
34 #include <tools/list.hxx>
35 #include "actctrl.hxx"
36 
37 
38 
39 void NumEditAction::Action()
40 {
41     aActionLink.Call( this );
42 }
43 
44 
45 long NumEditAction::Notify( NotifyEvent& rNEvt )
46 {
47     long nHandled = 0;
48 
49     if ( rNEvt.GetType() == EVENT_KEYINPUT )
50     {
51         const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
52         const KeyCode aKeyCode = pKEvt->GetKeyCode();
53         const sal_uInt16 nModifier = aKeyCode.GetModifier();
54         if( aKeyCode.GetCode() == KEY_RETURN &&
55                 !nModifier)
56         {
57             Action();
58             nHandled = 1;
59         }
60 
61     }
62     if(!nHandled)
63         NumericField::Notify( rNEvt );
64     return nHandled;
65 }
66 
67 /*------------------------------------------------------------------------
68  Beschreibung:  KeyInput fuer ShortName - Edits ohne Spaces
69 ------------------------------------------------------------------------*/
70 
71 NoSpaceEdit::NoSpaceEdit( Window* pParent, const ResId& rResId)
72     : Edit(pParent, rResId),
73     sForbiddenChars(String::CreateFromAscii(" "))
74 {
75 }
76 
77 NoSpaceEdit::~NoSpaceEdit()
78 {
79 }
80 
81 void NoSpaceEdit::KeyInput(const KeyEvent& rEvt)
82 {
83     sal_Bool bCallParent = sal_True;
84     if(rEvt.GetCharCode())
85     {
86         String sKey = rEvt.GetCharCode();
87         if( STRING_NOTFOUND != sForbiddenChars.Search(sKey))
88             bCallParent = sal_False;
89     }
90     if(bCallParent)
91         Edit::KeyInput(rEvt);
92 }
93 /* -----------------------------11.02.00 15:28--------------------------------
94 
95  ---------------------------------------------------------------------------*/
96 void NoSpaceEdit::Modify()
97 {
98     Selection aSel = GetSelection();
99     String sTemp = GetText();
100     for(sal_uInt16 i = 0; i < sForbiddenChars.Len(); i++)
101     {
102         sTemp.EraseAllChars( sForbiddenChars.GetChar(i) );
103     }
104     sal_uInt16 nDiff = GetText().Len() - sTemp.Len();
105     if(nDiff)
106     {
107         aSel.setMin(aSel.getMin() - nDiff);
108         aSel.setMax(aSel.getMin());
109         SetText(sTemp);
110         SetSelection(aSel);
111     }
112     if(GetModifyHdl().IsSet())
113         GetModifyHdl().Call(this);
114 }
115 /* -----------------25.06.2003 15:57-----------------
116 
117  --------------------------------------------------*/
118 ReturnActionEdit::~ReturnActionEdit()
119 {
120 }
121 /* -----------------25.06.2003 15:58-----------------
122 
123  --------------------------------------------------*/
124 void ReturnActionEdit::KeyInput( const KeyEvent& rEvt)
125 {
126     const KeyCode aKeyCode = rEvt.GetKeyCode();
127     const sal_uInt16 nModifier = aKeyCode.GetModifier();
128     if( aKeyCode.GetCode() == KEY_RETURN &&
129             !nModifier)
130     {
131         if(aReturnActionLink.IsSet())
132             aReturnActionLink.Call(this);
133     }
134     else
135         Edit::KeyInput(rEvt);
136 }
137 
138 
139