1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
2 
3 #ifndef __UI_WINDOW_H__
4 #define __UI_WINDOW_H__
5 
6 #include <pobl/bl_types.h>
7 #include <mef/ef_parser.h>
8 
9 #include "ui_display.h"
10 #include "ui_font.h"
11 #include "ui_color.h"
12 #include "ui_gc.h"
13 #include "ui_bel_mode.h"
14 
15 #define ACTUAL_WIDTH(win) ((win)->width + (win)->hmargin * 2)
16 #define ACTUAL_HEIGHT(win) ((win)->height + (win)->vmargin * 2)
17 
18 /*
19  * Don't use win->parent in xlib to check if win is root window or not
20  * because mlterm can work as libvte.
21  *   vte window
22  *      |
23  *   mlterm window ... ui_window_t::parent == NULL
24  *                     ui_window_t::parent_window == vte window
25  */
26 #define PARENT_WINDOWID_IS_TOP(win) ((win)->parent_window == (win)->disp->my_window)
27 
28 typedef enum ui_resize_flag {
29   NOTIFY_TO_NONE = 0x0,
30   NOTIFY_TO_CHILDREN = 0x01,
31   NOTIFY_TO_PARENT = 0x02,
32   NOTIFY_TO_MYSELF = 0x04,
33 
34   LIMIT_RESIZE = 0x08,
35 
36 } ui_resize_flag_t;
37 
38 typedef enum ui_maximize_flag {
39   MAXIMIZE_RESTORE = 0x0,
40   MAXIMIZE_VERTICAL = 0x1,
41   MAXIMIZE_HORIZONTAL = 0x2,
42   MAXIMIZE_FULL = 0x3,
43 
44 } ui_maximize_flag_t;
45 
46 typedef enum ui_sizehint_flag {
47   SIZEHINT_NONE = 0x0,
48   SIZEHINT_WIDTH = 0x1,
49   SIZEHINT_HEIGHT = 0x2,
50 } ui_sizehint_flag_t;
51 
52 typedef struct ui_xim_event_listener {
53   void *self;
54 
55   int (*get_spot)(void *, int *, int *);
56   XFontSet (*get_fontset)(void *);
57   ui_color_t *(*get_fg_color)(void *);
58   ui_color_t *(*get_bg_color)(void *);
59 
60 } ui_xim_event_listener_t;
61 
62 /* Defined in ui_xic.h */
63 typedef struct ui_xic *ui_xic_ptr_t;
64 
65 /* Defined in ui_xim.h */
66 typedef struct ui_xim *ui_xim_ptr_t;
67 
68 /* Defined in ui_dnd.h */
69 typedef struct ui_dnd_context *ui_dnd_context_ptr_t;
70 
71 /* Defined in ui_picture.h */
72 typedef struct ui_picture_modifier *ui_picture_modifier_ptr_t;
73 typedef struct ui_icon_picture *ui_icon_picture_ptr_t;
74 typedef struct _XftDraw *xft_draw_ptr_t;
75 typedef struct _cairo *cairo_ptr_t;
76 
77 typedef struct ui_window {
78   ui_display_t *disp;
79 
80   Window my_window;
81 
82 #ifdef USE_XLIB
83   /*
84    * Don't remove if USE_XFT and USE_CAIRO are not defined to keep the size of
85    * ui_window_t
86    * for ui_im_xxx_screen_t.
87    */
88   xft_draw_ptr_t xft_draw;
89   cairo_ptr_t cairo_draw;
90 #endif
91 
92   ui_color_t fg_color;
93   ui_color_t bg_color;
94 
95   ui_gc_t *gc;
96 
97   Window parent_window;     /* This member of root window is DefaultRootWindow */
98   struct ui_window *parent; /* This member of root window is NULL */
99   struct ui_window **children;
100   u_int num_children;
101 
102   u_int cursor_shape;
103 
104   long event_mask;
105 
106   int x; /* relative to a root window. */
107   int y; /* relative to a root window. */
108   u_int width;
109   u_int height;
110   u_int min_width;
111   u_int min_height;
112   u_int width_inc;
113   u_int height_inc;
114 
115   /* actual window size is +margin on north/south/east/west */
116   u_int16_t hmargin;
117   u_int16_t vmargin;
118 
119 /*
120  * mlterm-con doesn't use these members, but they are necessary to keep
121  * the size of ui_window_t as the same as mlterm-fb for input method plugins.
122  */
123 #ifdef MANAGE_SUB_WINDOWS_BY_MYSELF
124   u_int clip_y;
125   u_int clip_height;
126 #endif
127 
128   /* used by ui_xim */
129   ui_xim_ptr_t xim;
130   ui_xim_event_listener_t *xim_listener;
131   ui_xic_ptr_t xic; /* Only root window manages xic in win32 */
132 
133 #if defined(USE_WIN32GUI)
134   WORD update_window_flag;
135   int cmd_show;
136 #elif defined(USE_QUARTZ) || defined(USE_BEOS)
137   int update_window_flag;
138 #endif
139 
140   /* button */
141   Time prev_clicked_time;
142   int prev_clicked_button;
143   XButtonEvent prev_button_press_event;
144 
145   ui_picture_modifier_ptr_t pic_mod;
146 
147   /*
148    * XDND
149    */
150   /*
151    * Don't remove if DISABLE_XDND is defined to keep the size of ui_window_t for
152    * ui_im_xxx_screen_t.
153    */
154   ui_dnd_context_ptr_t dnd;
155 
156   /*
157    * XClassHint
158    */
159   char *app_name;
160 
161 /*
162  * flags etc.
163  */
164 
165 #ifdef USE_XLIB
166   int8_t wall_picture_is_set;     /* Actually set picture (including transparency)
167                                      or not. */
168   int8_t wait_copy_area_response; /* Used for XCopyArea() */
169   int8_t configure_root;
170 #else
171   Pixmap wall_picture;
172 #endif
173 #ifdef USE_WIN32GUI
174   int8_t is_sel_owner;
175 #endif
176   int8_t is_transparent;
177   int8_t is_scrollable;
178   int8_t is_focused;
179   int8_t inputtable; /* 1: focused, -1: unfocused */
180   int8_t is_mapped;
181 #ifdef __ANDROID__
182   int8_t saved_mapped;
183 #endif
184   int8_t create_gc;
185 
186   /* button */
187   int8_t button_is_pressing;
188   int8_t click_num;
189 
190   u_int8_t sizehint_flag;
191 
192   void (*window_realized)(struct ui_window *);
193   void (*window_finalized)(struct ui_window *);
194   void (*window_destroyed)(struct ui_window *);
195   void (*mapping_notify)(struct ui_window *);
196   /* Win32: gc->gc is not None. */
197   void (*window_exposed)(struct ui_window *, int, int, u_int, u_int);
198   /* Win32: gc->gc is not None. */
199   void (*update_window)(struct ui_window *, int);
200   void (*window_focused)(struct ui_window *);
201   void (*window_unfocused)(struct ui_window *);
202   void (*key_pressed)(struct ui_window *, XKeyEvent *);
203   void (*pointer_motion)(struct ui_window *, XMotionEvent *);
204   void (*button_motion)(struct ui_window *, XMotionEvent *);
205   void (*button_released)(struct ui_window *, XButtonEvent *);
206   void (*button_pressed)(struct ui_window *, XButtonEvent *, int);
207   void (*button_press_continued)(struct ui_window *, XButtonEvent *);
208   void (*window_resized)(struct ui_window *);
209   void (*child_window_resized)(struct ui_window *, struct ui_window *);
210   void (*selection_cleared)(struct ui_window *);
211   void (*xct_selection_requested)(struct ui_window *, XSelectionRequestEvent *, Atom);
212   void (*utf_selection_requested)(struct ui_window *, XSelectionRequestEvent *, Atom);
213   void (*xct_selection_notified)(struct ui_window *, u_char *, size_t);
214   void (*utf_selection_notified)(struct ui_window *, u_char *, size_t);
215   /*
216    * Don't remove if DISABLE_XDND is defined to keep the size of ui_window_t
217    * for ui_im_xxx_screen_t.
218    */
219   void (*set_xdnd_config)(struct ui_window *, char *, char *, char *);
220   void (*idling)(struct ui_window *);
221 #ifdef UIWINDOW_SUPPORTS_PREEDITING
222   void (*preedit)(struct ui_window *, const char *, const char *);
223 #endif
224 
225 } ui_window_t;
226 
227 int ui_window_init(ui_window_t *win, u_int width, u_int height, u_int min_width, u_int min_height,
228                    u_int width_inc, u_int height_inc, u_int hmargin, u_int vmargin, int create_gc,
229                    int inputtable);
230 
231 void ui_window_final(ui_window_t *win);
232 
233 void ui_window_set_type_engine(ui_window_t *win, ui_type_engine_t type_engine);
234 
235 void ui_window_add_event_mask(ui_window_t *win, long event_mask);
236 
237 void ui_window_remove_event_mask(ui_window_t *win, long event_mask);
238 
239 #define ui_window_check_event_mask(win, mask) ((win)->event_mask & (mask))
240 
241 /* int  ui_window_grab_pointer( ui_window_t *  win) ; */
242 
243 void ui_window_ungrab_pointer(ui_window_t *win);
244 
245 int ui_window_set_wall_picture(ui_window_t *win, Pixmap pic, int do_expose);
246 
247 int ui_window_unset_wall_picture(ui_window_t *win, int do_expose);
248 
249 #ifdef USE_XLIB
250 #define ui_window_has_wall_picture(win) ((win)->wall_picture_is_set)
251 #else
252 #define ui_window_has_wall_picture(win) ((win)->wall_picture != None)
253 #endif
254 
255 int ui_window_set_transparent(ui_window_t *win, ui_picture_modifier_ptr_t pic_mod);
256 
257 int ui_window_unset_transparent(ui_window_t *win);
258 
259 void ui_window_set_cursor(ui_window_t *win, u_int cursor_shape);
260 
261 int ui_window_set_fg_color(ui_window_t *win, ui_color_t *fg_color);
262 
263 int ui_window_set_bg_color(ui_window_t *win, ui_color_t *bg_color);
264 
265 int ui_window_add_child(ui_window_t *win, ui_window_t *child, int x, int y, int map);
266 
267 int ui_window_remove_child(ui_window_t *win, ui_window_t *child);
268 
269 ui_window_t *ui_get_root_window(ui_window_t *win);
270 
271 GC ui_window_get_fg_gc(ui_window_t *win);
272 
273 GC ui_window_get_bg_gc(ui_window_t *win);
274 
275 int ui_window_show(ui_window_t *win, int hint);
276 
277 void ui_window_map(ui_window_t *win);
278 
279 void ui_window_unmap(ui_window_t *win);
280 
281 int ui_window_resize(ui_window_t *win, u_int width, u_int height, ui_resize_flag_t flag);
282 
283 int ui_window_resize_with_margin(ui_window_t *win, u_int width, u_int height,
284                                  ui_resize_flag_t flag);
285 
286 void ui_window_set_maximize_flag(ui_window_t *win, ui_maximize_flag_t flag);
287 
288 void ui_window_set_normal_hints(ui_window_t *win, u_int min_width, u_int min_height,
289                                 u_int width_inc, u_int height_inc);
290 
291 void ui_window_set_override_redirect(ui_window_t *win, int flag);
292 
293 int ui_window_set_borderless_flag(ui_window_t *win, int flag);
294 
295 int ui_window_move(ui_window_t *win, int x, int y);
296 
297 void ui_window_clear(ui_window_t *win, int x, int y, u_int width, u_int height);
298 
299 void ui_window_clear_all(ui_window_t *win);
300 
301 void ui_window_fill(ui_window_t *win, int x, int y, u_int width, u_int height);
302 
303 void ui_window_fill_with(ui_window_t *win, ui_color_t *color, int x, int y, u_int width,
304                         u_int height);
305 
306 void ui_window_blank(ui_window_t *win);
307 
308 #if 0
309 /* Not used */
310 void ui_window_blank_with(ui_window_t *win, ui_color_t *color);
311 #endif
312 
313 /* if flag is 0, no update. */
314 void ui_window_update(ui_window_t *win, int flag);
315 
316 void ui_window_update_all(ui_window_t *win);
317 
318 void ui_window_idling(ui_window_t *win);
319 
320 int ui_window_receive_event(ui_window_t *win, XEvent *event);
321 
322 size_t ui_window_get_str(ui_window_t *win, u_char *seq, size_t seq_len, ef_parser_t **parser,
323                          KeySym *keysym, XKeyEvent *event);
324 
325 #ifdef MANAGE_ROOT_WINDOWS_BY_MYSELF
326 int ui_window_is_scrollable(ui_window_t *win);
327 #else
328 #define ui_window_is_scrollable(win) ((win)->is_scrollable)
329 #endif
330 
331 int ui_window_scroll_upward(ui_window_t *win, u_int height);
332 
333 int ui_window_scroll_upward_region(ui_window_t *win, int boundary_start, int boundary_end,
334                                    u_int height);
335 
336 int ui_window_scroll_downward(ui_window_t *win, u_int height);
337 
338 int ui_window_scroll_downward_region(ui_window_t *win, int boundary_start, int boundary_end,
339                                      u_int height);
340 
341 int ui_window_scroll_leftward(ui_window_t *win, u_int width);
342 
343 int ui_window_scroll_leftward_region(ui_window_t *win, int boundary_start, int boundary_end,
344                                      u_int width);
345 
346 int ui_window_scroll_rightward_region(ui_window_t *win, int boundary_start, int boundary_end,
347                                       u_int width);
348 
349 int ui_window_scroll_rightward(ui_window_t *win, u_int width);
350 
351 int ui_window_copy_area(ui_window_t *win, Pixmap src, PixmapMask mask, int src_x, int src_y,
352                         u_int width, u_int height, int dst_x, int dst_y);
353 
354 void ui_window_set_clip(ui_window_t *win, int x, int y, u_int width, u_int height);
355 
356 void ui_window_unset_clip(ui_window_t *win);
357 
358 void ui_window_draw_decsp_string(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color, int x,
359                                  int y, u_char *str, u_int len);
360 
361 void ui_window_draw_decsp_image_string(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color,
362                                        ui_color_t *bg_color, int x, int y, u_char *str, u_int len);
363 
364 /*
365  * ui_window_draw_*_string functions are used by ui_draw_str.[ch].
366  * Use ui_draw_str* functions usually.
367  */
368 
369 #if !defined(NO_DYNAMIC_LOAD_TYPE) || defined(USE_TYPE_XCORE)
370 void ui_window_draw_string(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color, int x, int y,
371                            u_char *str, u_int len);
372 
373 void ui_window_draw_string16(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color, int x, int y,
374                              XChar2b *str, u_int len);
375 
376 void ui_window_draw_image_string(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color,
377                                  ui_color_t *bg_color, int x, int y, u_char *str, u_int len);
378 
379 void ui_window_draw_image_string16(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color,
380                                    ui_color_t *bg_color, int x, int y, XChar2b *str, u_int len);
381 #endif
382 
383 #ifdef USE_CONSOLE
384 void ui_window_console_draw_decsp_string(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color,
385                                          ui_color_t *bg_color, int x, int y, u_char *str, u_int len,
386                                          int line_style);
387 
388 void ui_window_console_draw_string(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color,
389                                    ui_color_t *bg_color, int x, int y, u_char *str, u_int len,
390                                    int line_style);
391 
392 void ui_window_console_draw_string16(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color,
393                                      ui_color_t *bg_color, int x, int y, XChar2b *str, u_int len,
394                                      int line_style);
395 #endif
396 
397 #if !defined(NO_DYNAMIC_LOAD_TYPE) || defined(USE_TYPE_XFT) || defined(USE_TYPE_CAIRO)
398 void ui_window_ft_draw_string8(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color, int x,
399                                int y, u_char *str, size_t len);
400 
401 void ui_window_ft_draw_string32(ui_window_t *win, ui_font_t *font, ui_color_t *fg_color, int x,
402                                 int y, /* FcChar32 */ u_int32_t *str, u_int len);
403 #endif
404 
405 void ui_window_draw_rect_frame(ui_window_t *win, int x1, int y1, int x2, int y2);
406 
407 void ui_set_use_clipboard_selection(int use_it);
408 
409 int ui_is_using_clipboard_selection(void);
410 
411 int ui_window_set_selection_owner(ui_window_t *win, Time time);
412 
413 #define ui_window_is_selection_owner(win) ((win) == (win)->disp->selection_owner)
414 
415 int ui_window_string_selection_request(ui_window_t *win, Time time);
416 
417 int ui_window_xct_selection_request(ui_window_t *win, Time time);
418 
419 int ui_window_utf_selection_request(ui_window_t *win, Time time);
420 
421 void ui_window_send_picture_selection(ui_window_t *win, Pixmap pixmap, u_int width, u_int height);
422 
423 void ui_window_send_text_selection(ui_window_t *win, XSelectionRequestEvent *event,
424                                    u_char *sel_data, size_t sel_len, Atom sel_type);
425 
426 void ui_set_window_name(ui_window_t *win, u_char *name);
427 
428 void ui_set_icon_name(ui_window_t *win, u_char *name);
429 
430 void ui_window_set_icon(ui_window_t *win, ui_icon_picture_ptr_t icon);
431 
432 void ui_window_remove_icon(ui_window_t *win);
433 
434 void ui_set_click_interval(int interval);
435 
436 int ui_get_click_interval(void);
437 
438 #define ui_window_get_modifier_mapping(win) ui_display_get_modifier_mapping((win)->disp)
439 
440 u_int ui_window_get_mod_ignore_mask(ui_window_t *win, KeySym *keysyms);
441 
442 u_int ui_window_get_mod_meta_mask(ui_window_t *win, char *mod_key);
443 
444 #ifdef SUPPORT_URGENT_BELL
445 void ui_set_use_urgent_bell(int use);
446 #else
447 #define ui_set_use_urgent_bell(use) (0)
448 #endif
449 
450 void ui_window_bell(ui_window_t *win, ui_bel_mode_t mode);
451 
452 void ui_window_translate_coordinates(ui_window_t *win, int x, int y, int *global_x, int *global_y);
453 
454 void ui_window_set_input_focus(ui_window_t *win);
455 
456 #ifdef USE_XLIB
457 void ui_window_flush(ui_window_t *win);
458 #else
459 #define ui_window_flush(win) (0)
460 #endif
461 
462 #ifdef DEBUG
463 void ui_window_dump_children(ui_window_t *win);
464 #endif
465 
466 #endif
467