tbx  0.7.6
keylistener.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 /*
26  * keylistener.h
27  *
28  * Created on: 9 Jul 2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_KEYLISTENER_H_
33 #define TBX_KEYLISTENER_H_
34 
35 #include "listener.h"
36 #include "eventinfo.h"
37 #include "window.h"
38 #include "gadget.h"
39 
40 namespace tbx
41 {
45  class KeyEvent : public EventInfo
46  {
47  private:
48  bool _used;
49 
50  public:
58  EventInfo(id_block, poll_block), _used(false)
59  {}
60 
64  Window window() const {return id_block().self_object();}
65 
71  Gadget gadget() const {return id_block().self_component();}
72 
77  int x_offset() const {return _data.word[2];}
78 
83  int y_offset() const {return _data.word[3];}
84 
88  int height() const { return (_data.word[4] & 0xFFFF); }
89 
93  int colour() const {return (_data.word[4] >> 16) & 0xFF;}
94 
99  bool vdu() const {return (_data.word[4] & (1<<24))!=0;}
100 
104  bool invisible() const {return (_data.word[4] & (1<<25));}
105 
109  bool uses_colour() const {return (_data.word[4] & (1<<26));}
110 
114  bool colour_untranslated() const {return (_data.word[4] & (1<<27));}
115 
120  int index() const {return _data.word[5];}
121 
128  int key() const {return _data.word[6];}
129 
134  {
135  Escape = 0x1B,
136  Print = 0x180, Shift_Print = 0x190, Control_Print = 0x1A0, ControlShift_Print = 0x1B0,
137  F1 = 0x181, Shift_F1 = 0x191, Control_F1 = 0x1A1, ControlShift_F1 = 0x1B1,
138  F2 = 0x182, Shift_F2 = 0x192, Control_F2 = 0x1A2, ControlShift_F2 = 0x1B2,
139  F3 = 0x183, Shift_F3 = 0x193, Control_F3 = 0x1A3, ControlShift_F3 = 0x1B3,
140  F4 = 0x184, Shift_F4 = 0x194, Control_F4 = 0x1A4, ControlShift_F4 = 0x1B4,
141  F5 = 0x185, Shift_F5 = 0x195, Control_F5 = 0x1A5, ControlShift_F5 = 0x1B5,
142  F6 = 0x186, Shift_F6 = 0x196, Control_F6 = 0x1A6, ControlShift_F6 = 0x1B6,
143  F7 = 0x187, Shift_F7 = 0x197, Control_F7 = 0x1A7, ControlShift_F7 = 0x1B7,
144  F8 = 0x188, Shift_F8 = 0x198, Control_F8 = 0x1A8, ControlShift_F8 = 0x1B8,
145  F9 = 0x189, Shift_F9 = 0x199, Control_F9 = 0x1A9, ControlShift_F9 = 0x1B9,
146  Tab = 0x18A, Shift_Tab = 0x19A, Control_Tab = 0x1AA, ControlShift_Tab = 0x1BA,
147  Copy = 0x18B, Shift_Copy = 0x19B, Control_Copy = 0x1AB, ControlShift_Copy = 0x1BB,
148  LeftArrow = 0x18C, Shift_LeftArrow = 0x19C, Control_LeftArrow = 0x1AC, ControlShift_LeftArrow = 0x1BC,
149  RightArrow = 0x18D, Shift_RightArrow = 0x19D, Control_RightArrow = 0x1AD, ControlShift_RightArrow = 0x1BD,
150  DownArrow = 0x18E, Shift_DownArrow = 0x19E, Control_DownArrow = 0x1AE, ControlShift_DownArrow = 0x1BE,
151  UpArrow = 0x18F, Shift_UpArrow = 0x19F, Control_UpArrow = 0x1AF, ControlShift_UpArrow = 0x1BF,
152  PageDown = 0x19E, Shift_PageDown = 0x18E, Control_PageDown = 0x1BE, ControlShift_PageDown = 0x1AE,
153  PageUp = 0x19F, Shift_PageUp = 0x18F, Control_PageUp = 0x1BF, ControlShift_PageUp = 0x1AF,
154  F10 = 0x1CA, Shift_F10 = 0x1DA, Control_F10 = 0x1EA, ControlShift_F10 = 0x1FA,
155  F11 = 0x1CB, Shift_F11 = 0x1DB, Control_F11 = 0x1EB, ControlShift_F11 = 0x1FB,
156  F12 = 0x1CC, Shift_F12 = 0x1DC, Control_F12 = 0x1EC, ControlShift_F12 = 0x1FC,
157  Insert = 0x1CD, Shift_Insert = 0x1DD, Control_Insert = 0x1ED, ControlShift_Insert = 0x1FD
158  };
159 
163  void key_used() {_used = true;}
164 
168  bool is_key_used() const {return _used;}
169  };
170 
178  class KeyListener : public Listener
179  {
180  public:
187  virtual void key(KeyEvent &event) = 0;
188  };
189 
190 }
191 
192 
193 #endif /* TBX_KEYLISTENER_H_ */
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::KeyEvent::vdu
bool vdu() const
Is it a vdu caret.
Definition: keylistener.h:99
tbx::KeyEvent::window
Window window() const
Get Window that the key is pressed in.
Definition: keylistener.h:64
tbx::EventInfo::id_block
const IdBlock & id_block() const
IdBlock for the current event.
Definition: eventinfo.h:71
tbx::Window
The Window object represents a toolbox window.
Definition: window.h:70
tbx::EventInfo::_data
PollBlock & _data
raw data from the event
Definition: eventinfo.h:53
tbx::PollBlock
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:72
tbx::KeyEvent::gadget
Gadget gadget() const
Get the gadget that the key is pressed in.
Definition: keylistener.h:71
tbx::KeyEvent::key_used
void key_used()
Call if the key has been used by the listener.
Definition: keylistener.h:163
tbx::KeyEvent::key
int key() const
key code of character press.
Definition: keylistener.h:128
tbx::KeyEvent::index
int index() const
The index of the caret into the writeable field or -1 if not in a writeable field.
Definition: keylistener.h:120
tbx::IdBlock
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:42
tbx::IdBlock::self_component
Component self_component() const
Get the component the event occured on.
Definition: eventrouter.cc:1658
tbx::KeyEvent::y_offset
int y_offset() const
Get the current y offset of the caret relative to the window origin.
Definition: keylistener.h:83
tbx::IdBlock::self_object
Object self_object() const
Get the object the event occured on.
Definition: eventrouter.cc:1647
tbx::KeyEvent::uses_colour
bool uses_colour() const
caret_color is used for the colour otherwise caret is Wimp colour 11
Definition: keylistener.h:109
tbx::KeyEvent::height
int height() const
Get the height of the caret.
Definition: keylistener.h:88
tbx::KeyEvent::x_offset
int x_offset() const
Get the current x offset of the caret relative to the window origin.
Definition: keylistener.h:77
tbx::Listener
Base class for all toolbox event listeners.
Definition: listener.h:34
tbx::KeyEvent::invisible
bool invisible() const
Invisible caret.
Definition: keylistener.h:104
tbx::KeyEvent::colour
int colour() const
Get caret colour - if colour set.
Definition: keylistener.h:93
tbx::KeyEvent::colour_untranslated
bool colour_untranslated() const
Colour is untranslated, otherwise they are a Wimp colour.
Definition: keylistener.h:114
tbx::KeyListener::key
virtual void key(KeyEvent &event)=0
virtual function called when the application receives a key pressed window event
tbx::KeyEvent::SpecialKeys
SpecialKeys
Enumeration for special key codes passed from the WIMP.
Definition: keylistener.h:134
tbx::KeyEvent
Event data for lose or gain caret listener.
Definition: keylistener.h:46
tbx::KeyListener
Listener for KeyPressed WIMP event.
Definition: keylistener.h:179
tbx::Gadget
This is the base class for all Gadgets.
Definition: gadget.h:49
tbx::PollBlock::word
int word[64]
Array containing information return from Wimp_Poll.
Definition: pollinfo.h:76
tbx::KeyEvent::is_key_used
bool is_key_used() const
Returns true if a listener has used the key.
Definition: keylistener.h:168
tbx::KeyEvent::KeyEvent
KeyEvent(IdBlock &id_block, PollBlock &poll_block)
Construct KeyEvent from information returned from the WIMP.
Definition: keylistener.h:57
tbx::EventInfo
Class to provide information on a toolbox event.
Definition: eventinfo.h:49