1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
2 /*
3  * nimf-engine.h
4  * This file is part of Nimf.
5  *
6  * Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com>
7  *
8  * Nimf is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Nimf is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program;  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef __NIMF_ENGINE_H__
23 #define __NIMF_ENGINE_H__
24 
25 #include <glib-object.h>
26 #include "nimf-events.h"
27 #include "nimf-service-ic.h"
28 #include "nimf-candidatable.h"
29 
30 G_BEGIN_DECLS
31 
32 #define NIMF_TYPE_ENGINE            (nimf_engine_get_type ())
33 #define NIMF_ENGINE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NIMF_TYPE_ENGINE, NimfEngine))
34 #define NIMF_ENGINE_CLASS(class)    (G_TYPE_CHECK_CLASS_CAST ((class), NIMF_TYPE_ENGINE, NimfEngineClass))
35 #define NIMF_IS_ENGINE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NIMF_TYPE_ENGINE))
36 #define NIMF_ENGINE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NIMF_TYPE_ENGINE, NimfEngineClass))
37 
38 #ifndef __GTK_DOC_IGNORE__
39 typedef struct _NimfServiceIC    NimfServiceIC;
40 typedef struct _NimfCandidatable NimfCandidatable;
41 #endif
42 typedef struct _NimfEngine        NimfEngine;
43 typedef struct _NimfEngineClass   NimfEngineClass;
44 typedef struct _NimfEnginePrivate NimfEnginePrivate;
45 
46 struct _NimfEngine
47 {
48   GObject parent_instance;
49   NimfEnginePrivate *priv;
50 };
51 
52 /**
53  * NimfEngineClass:
54  * @filter_event: If the language engine consumes the event, returns %TRUE.
55  * @reset: Resets the language engine.
56  * @focus_in: Called via nimf_im_focus_in() when the caller has gained focus.
57  * @focus_out: Called via nimf_im_focus_out() when the caller has lost focus.
58  * @set_method: Sets the method in the language engine.
59  * @candidate_page_up: handler when candidate page up
60  * @candidate_page_down: handler when candidate page down
61  * @candidate_clicked: handler when candidate clicked
62  * @candidate_scrolled: handler when candidate scrolled
63  * @get_id: Gets the language engine id.
64  * @get_icon_name: Gets the language engine name.
65  */
66 struct _NimfEngineClass
67 {
68   /*< private >*/
69   GObjectClass parent_class;
70 
71   /*< public >*/
72   /* Virtual functions */
73   gboolean (* filter_event)       (NimfEngine          *engine,
74                                    NimfServiceIC       *ic,
75                                    NimfEvent           *event);
76   void     (* reset)              (NimfEngine          *engine,
77                                    NimfServiceIC       *ic);
78   void     (* focus_in)           (NimfEngine          *engine,
79                                    NimfServiceIC       *ic);
80   void     (* focus_out)          (NimfEngine          *engine,
81                                    NimfServiceIC       *ic);
82   void     (* set_method)         (NimfEngine          *engine,
83                                    const gchar         *method_id);
84   /* candidate */
85   gboolean (* candidate_page_up)   (NimfEngine         *engine,
86                                     NimfServiceIC      *ic);
87   gboolean (* candidate_page_down) (NimfEngine         *engine,
88                                     NimfServiceIC      *ic);
89   void     (* candidate_clicked)   (NimfEngine         *engine,
90                                     NimfServiceIC      *ic,
91                                     gchar              *text,
92                                     gint                index);
93   void     (* candidate_scrolled)  (NimfEngine         *engine,
94                                     NimfServiceIC      *ic,
95                                     gdouble             value);
96   /* info */
97   const gchar * (* get_id)        (NimfEngine          *engine);
98   const gchar * (* get_icon_name) (NimfEngine          *engine);
99 };
100 
101 GType    nimf_engine_get_type                  (void) G_GNUC_CONST;
102 gboolean nimf_engine_filter_event              (NimfEngine          *engine,
103                                                 NimfServiceIC       *ic,
104                                                 NimfEvent           *event);
105 void     nimf_engine_reset                     (NimfEngine          *engine,
106                                                 NimfServiceIC       *ic);
107 void     nimf_engine_focus_in                  (NimfEngine          *engine,
108                                                 NimfServiceIC       *ic);
109 void     nimf_engine_focus_out                 (NimfEngine          *engine,
110                                                 NimfServiceIC       *ic);
111 void     nimf_engine_set_surrounding           (NimfEngine          *engine,
112                                                 const char          *text,
113                                                 gint                 len,
114                                                 gint                 cursor_index);
115 gboolean nimf_engine_get_surrounding           (NimfEngine          *engine,
116                                                 NimfServiceIC       *ic,
117                                                 gchar              **text,
118                                                 gint                *cursor_index);
119 void     nimf_engine_status_changed            (NimfEngine          *engine);
120 void     nimf_engine_set_method                (NimfEngine          *engine,
121                                                 const gchar         *method_id);
122 /* signals */
123 void     nimf_engine_emit_preedit_start        (NimfEngine       *engine,
124                                                 NimfServiceIC    *ic);
125 void     nimf_engine_emit_preedit_changed      (NimfEngine       *engine,
126                                                 NimfServiceIC    *ic,
127                                                 const gchar      *preedit_string,
128                                                 NimfPreeditAttr **attrs,
129                                                 gint              cursor_pos);
130 void     nimf_engine_emit_preedit_end          (NimfEngine       *engine,
131                                                 NimfServiceIC    *ic);
132 void     nimf_engine_emit_commit               (NimfEngine       *engine,
133                                                 NimfServiceIC    *ic,
134                                                 gchar const      *text);
135 gboolean nimf_engine_emit_retrieve_surrounding (NimfEngine       *engine,
136                                                 NimfServiceIC    *ic);
137 gboolean nimf_engine_emit_delete_surrounding   (NimfEngine       *engine,
138                                                 NimfServiceIC    *ic,
139                                                 gint              offset,
140                                                 gint              n_chars);
141 void     nimf_engine_emit_beep                 (NimfEngine       *engine,
142                                                 NimfServiceIC    *ic);
143 /* info */
144 const gchar      *nimf_engine_get_id           (NimfEngine *engine);
145 const gchar      *nimf_engine_get_icon_name    (NimfEngine *engine);
146 /* candidate */
147 NimfCandidatable *nimf_engine_get_candidatable (NimfEngine *engine);
148 
149 G_END_DECLS
150 
151 #endif /* __NIMF_ENGINE_H__ */
152