documentation was wrong
[sdlhildon] / sdlhim / src / SDL_him.h
1 /* This file is part of SDL_him - SDL Hildon Input Method addon
2  * Copyright (C) 2010 Javier S. Pedro
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 3 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA or see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef __SDL_HIM_H
21 #define __SDL_HIM_H
22
23 /* Set up for C function definitions, even when using C++ */
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /* Equivalent (and binary compatible) to HildonIMTrigger */
29 typedef enum HIM_Trigger
30 {
31         HIM_TRIGGER_NONE = -1,
32         HIM_TRIGGER_STYLUS,
33         HIM_TRIGGER_FINGER,
34         HIM_TRIGGER_KEY
35 } HIM_Trigger;
36
37 /* Equivalent (and binary compatible) to HildonGtkInputMode */
38 typedef enum HIM_Mode
39 {
40         HIM_MODE_NONE = 0,
41         HIM_MODE_ALPHA = 1 << 0,
42         HIM_MODE_NUMERIC = 1 << 1,
43         HIM_MODE_SPECIAL = 1 << 2,
44         HIM_MODE_HEXA = 1 << 3,
45         HIM_MODE_TELE = 1 << 4,
46
47         HIM_MODE_FULL = (HIM_MODE_ALPHA | HIM_MODE_NUMERIC | HIM_MODE_SPECIAL),
48
49         /** This is a special SDL_him setting which causes it to keep sending
50                 SDL_KEYDOWN events on most "normal" keys.
51          */
52         HIM_MODE_NO_FILTER = 1 << 10,
53
54         HIM_MODE_MULTILINE = 1 << 28,
55         HIM_MODE_INVISIBLE = 1 << 29,
56         HIM_MODE_AUTOCAP = 1 << 30,
57         HIM_MODE_DICTIONARY = 1 << 31
58 } HIM_Mode;
59
60 #define HIM_TEXTEVENT_SIZE 32
61 typedef struct HIM_TextEvent {
62         Uint8 type;
63         Uint8 code;
64 } HIM_TextEvent;
65
66 #define HIM_TEXTINPUTEVENT_TEXT_SIZE (32-2)
67 #define HIM_TEXTINPUTEVENT 1
68 typedef struct HIM_TextInputEvent {
69         Uint8 type;
70         Uint8 code;
71         char text[HIM_TEXTINPUTEVENT_TEXT_SIZE];
72 } HIM_TextInputEvent;
73
74 #define HIM_TEXTEDITINGEVENT_TEXT_SIZE (32-2)
75 #define HIM_TEXTEDITINGEVENT 2
76 typedef struct HIM_TextEditingEvent {
77         Uint8 type;
78         Uint8 code;
79         char text[HIM_TEXTEDITINGEVENT_TEXT_SIZE];
80 } HIM_TextEditingEvent;
81
82 #define HIM_SPECIALKEYEVENT 3
83 typedef struct HIM_SpecialKeyEvent {
84         Uint8 type;
85         Uint8 code;
86         SDLKey sym;
87 } HIM_SpecialKeyEvent;
88
89 #define HIM_CURSORMOVEEVENT 4
90 typedef struct HIM_CursorMoveEvent {
91         Uint8 type;
92         Uint8 code;
93         Uint8 relative;
94         Sint32 offset;
95 } HIM_CursorMoveEvent;
96
97 #define HIM_REQUESTSURROUNDINGEVENT 5
98 typedef struct HIM_RequestSurroundingEvent {
99         Uint8 type;
100         Uint8 code;
101         Uint8 full;
102 } HIM_RequestSurroundingEvent;
103
104 #define HIM_CLIPBOARDEVENT 6
105 typedef enum HIM_ClipboardAction {
106         HIM_CLIPBOARD_NONE = 0,
107         HIM_CLIPBOARD_CUT,
108         HIM_CLIPBOARD_COPY,
109         HIM_CLIPBOARD_PASTE,
110         HIM_CLIPBOARD_REQUEST_SELECTION
111 } HIM_ClipboardAction;
112 typedef struct HIM_ClipboardEvent {
113         Uint8 type;
114         Uint8 code;
115         HIM_ClipboardAction action;
116 } HIM_ClipboardEvent;
117
118 /** Invoke after SDL_Init.
119         @param flags 0
120         @param event event identifier to bind the library to 
121                         (SDL_USEREVENT through SDL_NUMEVENTS-1)
122         @return 0 if SDL_him was initialized correctly.
123   */
124 extern DECLSPEC int SDLCALL HIM_Init(Uint32 flags, Uint8 event);
125
126 /** Invoke after SDL_Quit. */
127 extern DECLSPEC void SDLCALL HIM_Quit();
128
129 extern DECLSPEC void SDLCALL HIM_Enable(HIM_Mode mode);
130 extern DECLSPEC void SDLCALL HIM_Disable();
131
132 extern DECLSPEC void SDLCALL HIM_ShowKeyboard(HIM_Trigger reason);
133 extern DECLSPEC void SDLCALL HIM_HideKeyboard();
134
135 /** 
136   Call before handling any SDL_Event (or use SDL_SetEventFilter).
137   @param event the SDL_Event you were about to handle.
138   @return 1 if the event was filtered and should not be handled by your app.
139  */
140 extern DECLSPEC int SDLCALL HIM_FilterEvent(const SDL_Event *event);
141
142 /**
143   Call in the RequestSurrounding event handler.
144   @param text
145   @param cursor where the cursor is, relative to text.
146  */
147 extern DECLSPEC void SDLCALL HIM_SendSurrounding
148         (const char * text, unsigned long cursor);
149         
150 /**
151   Call in the ClipboardRequestSelection event handler.
152   @param text the selected text
153  */
154 extern DECLSPEC void SDLCALL HIM_SendSelection
155         (const char * text);
156
157 /* Ends C function definitions when using C++ */
158 #ifdef __cplusplus
159 }
160 #endif
161
162 #endif
163