1 /* $Id: gtk-display.h,v 1.10 2009/08/28 01:29:47 fredette Exp $ */
2 
3 /* host/gtk/gtk-display.h - header file for GTK display support: */
4 
5 /*
6  * Copyright (c) 2003 Matt Fredette
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by Matt Fredette.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _HOST_GTK_GTK_DISPLAY_H
37 #define _HOST_GTK_GTK_DISPLAY_H
38 
39 #include <tme/common.h>
40 _TME_RCSID("$Id: gtk-display.h,v 1.10 2009/08/28 01:29:47 fredette Exp $");
41 
42 /* includes: */
43 #include <tme/generic/fb.h>
44 #include <tme/generic/keyboard.h>
45 #include <tme/generic/mouse.h>
46 #include <tme/threads.h>
47 #include <tme/hash.h>
48 #ifndef G_ENABLE_DEBUG
49 #define G_ENABLE_DEBUG (0)
50 #endif /* !G_ENABLE_DEBUG */
51 #include <gtk/gtk.h>
52 
53 /* macros: */
54 
55 /* the callout flags: */
56 #define TME_GTK_DISPLAY_CALLOUT_CHECK		(0)
57 #define TME_GTK_DISPLAY_CALLOUT_RUNNING		TME_BIT(0)
58 #define TME_GTK_DISPLAY_CALLOUTS_MASK		(-2)
59 #define  TME_GTK_DISPLAY_CALLOUT_KEYBOARD_CTRL	TME_BIT(1)
60 #define  TME_GTK_DISPLAY_CALLOUT_MOUSE_CTRL	TME_BIT(2)
61 
62 /* types: */
63 
64 struct tme_gtk_display;
65 
66 /* a screen: */
67 struct tme_gtk_screen {
68 
69   /* the next screen: */
70   struct tme_gtk_screen *tme_gtk_screen_next;
71 
72   /* a backpointer to the display: */
73   struct tme_gtk_display *tme_gtk_screen_display;
74 
75   /* the framebuffer connection.  unlike many other elements, this is
76      *our* side of the framebuffer connection, not the peer's side: */
77   struct tme_fb_connection *tme_gtk_screen_fb;
78 
79   /* the current scaling.  if this is < 0, the user has not forced a
80      given scaling yet: */
81   int tme_gtk_screen_fb_scale;
82 
83   /* any colorset signature: */
84   tme_uint32_t tme_gtk_screen_colorset;
85 
86   /* the top-level window: */
87   GtkWidget *tme_gtk_screen_window;
88 
89   /* the outer vertical packing box: */
90   GtkWidget *tme_gtk_screen_vbox0;
91 
92   /* various menu item widgets: */
93   GtkWidget *tme_gtk_screen_scale_default;
94   GtkWidget *tme_gtk_screen_scale_half;
95 
96   /* the GtkEventBox, GdkImage and GtkImage for the framebuffer: */
97   GtkWidget *tme_gtk_screen_event_box;
98   GdkImage *tme_gtk_screen_gdkimage;
99   GtkWidget *tme_gtk_screen_gtkimage;
100 
101   /* the translation function: */
102   int (*tme_gtk_screen_fb_xlat) _TME_P((struct tme_fb_connection *,
103 					struct tme_fb_connection *));
104 
105   /* the mouse on label: */
106   GtkWidget *tme_gtk_screen_mouse_label;
107 
108   /* the status bar, and the context ID: */
109   GtkWidget *tme_gtk_screen_mouse_statusbar;
110   guint tme_gtk_screen_mouse_statusbar_cid;
111 
112   /* if GDK_VoidSymbol, mouse mode is off.  otherwise,
113      mouse mode is on, and this is the keyval that will
114      turn mouse mode off: */
115   guint tme_gtk_screen_mouse_keyval;
116 
117   /* when mouse mode is on, this is the previous events mask
118      for the framebuffer event box: */
119   GdkEventMask tme_gtk_screen_mouse_events_old;
120 
121   /* when mouse mode is on, this is the warp center: */
122   gint tme_gtk_screen_mouse_warp_x;
123   gint tme_gtk_screen_mouse_warp_y;
124 
125   /* when mouse mode is on, the last tme buttons state: */
126   unsigned int tme_gtk_screen_mouse_buttons_last;
127 
128   /* if nonzero, the screen needs a full redraw: */
129   int tme_gtk_screen_full_redraw;
130 };
131 
132 /* a GTK bad keysym: */
133 struct tme_gtk_keysym_bad {
134 
135   /* these are kept on a singly linked list: */
136   struct tme_gtk_keysym_bad *tme_gtk_keysym_bad_next;
137 
138   /* the bad keysym string: */
139   char *tme_gtk_keysym_bad_string;
140 
141   /* the flags and context used in the lookup: */
142   unsigned int tme_keysym_bad_flags;
143   unsigned int tme_gtk_keysym_bad_context_length;
144   tme_uint8_t *tme_gtk_keysym_bad_context;
145 };
146 
147 /* a display: */
148 struct tme_gtk_display {
149 
150   /* backpointer to our element: */
151   struct tme_element *tme_gtk_display_element;
152 
153   /* our mutex: */
154   tme_mutex_t tme_gtk_display_mutex;
155 
156   /* our keyboard connection: */
157   struct tme_keyboard_connection *tme_gtk_display_keyboard_connection;
158 
159   /* our keyboard buffer: */
160   struct tme_keyboard_buffer *tme_gtk_display_keyboard_buffer;
161 
162   /* our keysyms hash: */
163   tme_hash_t tme_gtk_display_keyboard_keysyms;
164 
165   /* the bad keysym records: */
166   struct tme_gtk_keysym_bad *tme_gtk_display_keyboard_keysyms_bad;
167 
168   /* our keysym to keycode hash: */
169   tme_hash_t tme_gtk_display_keyboard_keysym_to_keycode;
170 
171   /* the next keysym to allocate for an unknown keysym string: */
172   guint tme_gtk_display_keyboard_keysym_alloc_next;
173 
174   /* our mouse connection: */
175   struct tme_mouse_connection *tme_gtk_display_mouse_connection;
176 
177   /* our mouse buffer: */
178   struct tme_mouse_buffer *tme_gtk_display_mouse_buffer;
179 
180   /* our mouse cursor: */
181   GdkCursor *tme_gtk_display_mouse_cursor;
182 
183   /* our screens: */
184   struct tme_gtk_screen *tme_gtk_display_screens;
185 
186   /* the callout flags: */
187   unsigned int tme_gtk_display_callout_flags;
188 
189   /* the tooltips group: */
190   GtkTooltips *tme_gtk_display_tooltips;
191 };
192 
193 /* a menu item: */
194 struct tme_gtk_display_menu_item {
195 
196   /* which menu item this is: */
197   unsigned int tme_gtk_display_menu_item_which;
198 
199   /* where to save the menu item widget: */
200   GtkWidget **tme_gtk_display_menu_item_widget;
201 
202   /* the string for the menu item label: */
203   const char *tme_gtk_display_menu_item_string;
204 };
205 
206 /* this generates menu items: */
207 typedef GtkSignalFunc (*tme_gtk_display_menu_items_t) _TME_P((void *, struct tme_gtk_display_menu_item *));
208 
209 /* prototypes: */
210 struct tme_gtk_screen *_tme_gtk_screen_new _TME_P((struct tme_gtk_display *));
211 int _tme_gtk_screen_connections_new _TME_P((struct tme_gtk_display *,
212 					    struct tme_connection **));
213 void _tme_gtk_keyboard_new _TME_P((struct tme_gtk_display *));
214 void _tme_gtk_keyboard_attach _TME_P((struct tme_gtk_screen *));
215 int _tme_gtk_keyboard_connections_new _TME_P((struct tme_gtk_display *,
216 					      struct tme_connection **));
217 void _tme_gtk_mouse_new _TME_P((struct tme_gtk_display *));
218 void _tme_gtk_mouse_mode_off _TME_P((struct tme_gtk_screen *, guint32));
219 void _tme_gtk_mouse_attach _TME_P((struct tme_gtk_screen *));
220 int _tme_gtk_mouse_connections_new _TME_P((struct tme_gtk_display *,
221 					   struct tme_connection **));
222 void _tme_gtk_screen_th_update _TME_P((struct tme_gtk_display *));
223 void _tme_gtk_display_callout _TME_P((struct tme_gtk_display *,
224 				      int));
225 gint _tme_gtk_display_enter_focus _TME_P((GtkWidget *, GdkEvent *, gpointer));
226 GtkWidget *_tme_gtk_display_menu_radio _TME_P((void *, tme_gtk_display_menu_items_t));
227 
228 #endif /* _HOST_GTK_GTK_DISPLAY_H */
229 
230