1 /*
2  * Copyright © 2016  Red Hat, Inc. All rights reserved.
3  * Copyright © 2016  Ding-Yi Chen <dchen@redhat.com>
4  *
5  * This file is part of the ibus-chewing Project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  */
21 
22 /**
23  * SECTION:IBusChewingSystray
24  * @short_description: Systray support
25  * @title: IBusChewingSystray
26  * @stability: Stable
27  * @include: IbusChewingSystray
28  *
29  * Systray support that shows:
30  *   Chinese/English state
31  *
32  */
33 
34 #ifndef _IBUS_CHEWING_SYSTRAY_H_
35 #define _IBUS_CHEWING_SYSTRAY_H_
36 #include <stdarg.h>
37 #include <glib.h>
38 #include <gtk/gtk.h>
39 #include <locale.h>
40 #include <glib/gi18n.h>
41 #include "MakerDialogUtil.h"
42 #include "IBusChewingPreEdit.h"
43 #define IBUS_CHEWING_SYSTRAY_ICON_COUNT_MAX 5
44 typedef struct _IBusChewingSystrayIcon IBusChewingSystrayIcon;
45 
46 typedef void (*IBusChewingSystrayClickFunc) (IBusChewingSystrayIcon *
47 					     iSystrayIcon,
48 					     gpointer userData);
49 
50 typedef enum {
51     IBUS_CHEWING_SYSTRAY_CHINESE_FLAG = 1,
52     IBUS_CHEWING_SYSTRAY_FULL_HALF_SHAPE_FLAG = 2,
53 } IBusChewingSystrayFlag;
54 
55 /**
56  * IBusChewingSystrayIcon:
57  * Systray Icon for ibus-chewin
58  *
59  * @icon: The actual systray object
60  * @value: An unsigned integer that hold the state of the systray icon.
61  * also the index (starting from 0) for icon file. Thus it should not exceed length
62  * of iconFileArray
63  * @iconFileArray: Array of icon files.
64  * @leftClickFunc: Callback function handles left click. NULL means do nothing
65  * @leftClickData: Data that passed to leftClickFunc
66  * @rightClickFunc: Callback function handles right click. NULL means do nothing
67  * @rightClickData: Data that passed to rightClickFunc
68  */
69 struct _IBusChewingSystrayIcon {
70     GtkStatusIcon *icon;
71     guint value;
72     GPtrArray *iconFileArray;
73     GPtrArray *iconCacheArray;
74     IBusChewingSystrayClickFunc leftClickFunc;
75     gpointer leftClickData;
76     IBusChewingSystrayClickFunc rightClickFunc;
77     gpointer rightClickData;
78 };
79 
80 void ibus_chewing_systray_icon_free(IBusChewingSystrayIcon * self);
81 
82 /**
83  * ibus_chewing_systray_icon_get_icon_file:
84  * @self: An IBusChewingSystrayIcon
85  * @index: File index that starts from 0
86  */
87 #define ibus_chewing_systray_icon_get_icon_file(self, index) (const gchar *) g_ptr_array_index(self->iconFileArray,index)
88 
89 /**
90  * ibus_chewing_systray_icon_set_value:
91  * @self: An IBusChewingSystrayIcon
92  * @value: The value to set.
93  *
94  * Sets value to IBusChewingSystrayIcon.
95  * This does not update display icon, see ibus_chewing_systray_icon_update for that.
96  */
97 void ibus_chewing_systray_icon_set_value(IBusChewingSystrayIcon *
98 					 self, guint value);
99 
100 /**
101  * ibus_chewing_systray_icon_set_visible:
102  * @self: An IBusChewingSystrayIcon
103  * @visible: TRUE for visible, FALSE for not visible.
104  *
105  * Sets whether this SystrayIcon visible.
106  */
107 void ibus_chewing_systray_icon_set_visible(IBusChewingSystrayIcon *
108 					   self, gboolean visible);
109 
110 /**
111  * ibus_chewing_systray_icon_update:
112  * @self: An IBusChewingSystrayIcon
113  *
114  * Updates display icon according to value.
115  */
116 void ibus_chewing_systray_icon_update(IBusChewingSystrayIcon * self);
117 
118 
119 #include "ibus-chewing-engine.h"
120 
121 IBusChewingSystrayIcon
122     * ibus_chewing_systray_chi_eng_icon_new(IBusChewingEngine * iEngine);
123 
124 /**
125  * ibus_chewing_systray_chi_eng_icon_create_or_hide:
126  * @iEngine: An IBusChewingEngine
127  *
128  * Create or destroy systray icon depending on property 'show-systray'
129  * @returns: TRUE if systray icon created; FALSE otherwise.
130  */
131 gboolean
132 ibus_chewing_systray_chi_eng_icon_create_or_hide(IBusChewingEngine *
133 						    iEngine);
134 
135 void ibus_chewing_systray_chi_eng_icon_refresh_value(IBusChewingEngine *
136 						     iEngine);
137 #endif
138