merged hv7 mod
[goodguy/history.git] / cinelerra-5.1 / guicast / bcwindowbase.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef BCWINDOWBASE_H
23 #define BCWINDOWBASE_H
24
25 // Window types
26 #define MAIN_WINDOW 0
27 #define SUB_WINDOW 1
28 #define POPUP_WINDOW 2
29
30 #ifdef HAVE_LIBXXF86VM
31 #define VIDMODE_SCALED_WINDOW 3
32 #endif
33
34 #define TOOLTIP_MARGIN 2
35 #define BC_INFINITY 65536
36
37 #include "arraylist.h"
38 #include "bcbar.inc"
39 #include "bcbitmap.inc"
40 #include "bcbutton.inc"
41 #include "bccapture.inc"
42 #include "bcclipboard.inc"
43 #include "bccmodels.inc"
44 #include "bcdisplay.inc"
45 #include "bcdragwindow.inc"
46 #include "bcfilebox.inc"
47 #include "bckeyboard.h"
48 #include "bclistbox.inc"
49 #include "bcmenubar.inc"
50 #include "bcmeter.inc"
51 #include "bcpan.inc"
52 #include "bcpbuffer.inc"
53 #include "bcpixmap.inc"
54 #include "bcpopup.inc"
55 #include "bcpopupmenu.inc"
56 #include "bcpot.inc"
57 #include "bcprogress.inc"
58 #include "bcrepeater.inc"
59 #include "bcresources.inc"
60 #include "bcscrollbar.inc"
61 #include "bcslider.inc"
62 #include "bcsubwindow.inc"
63 #include "bcsynchronous.inc"
64 #include "bctextbox.inc"
65 #include "bctimer.inc"
66 #include "bctitle.inc"
67 #include "bctoggle.inc"
68 #include "bctrace.inc"
69 #include "bctumble.inc"
70 #include "bcwindow.inc"
71 #include "bcwindowbase.inc"
72 #include "bcwindowevents.inc"
73 #include "condition.inc"
74 #include "bchash.inc"
75 #include "linklist.h"
76 #include "mutex.inc"
77 #include "vframe.inc"
78
79
80 #include <stdint.h>
81 #include <stdio.h>
82 #include <stdlib.h>
83 #include <X11/Xatom.h>
84 #ifdef HAVE_XFT
85 #include <X11/Xft/Xft.h>
86 #endif
87 #include <X11/Xlib.h>
88 #include <X11/Xutil.h>
89 #include <X11/keysym.h>
90 #include <X11/cursorfont.h>
91 #ifdef HAVE_LIBXXF86VM
92 #include <X11/extensions/xf86vmode.h>
93 #endif
94 #include <X11/extensions/Xinerama.h>
95 #ifdef HAVE_GL
96 #define GL_GLEXT_PROTOTYPES
97 #include <GL/glx.h>
98 #endif
99
100
101
102 #ifdef HAVE_GL
103 //typedef void* GLXContext;
104 #endif
105
106 class BC_ResizeCall
107 {
108 public:
109         BC_ResizeCall(int w, int h);
110         int w, h;
111 };
112
113 typedef XClientMessageEvent xatom_event;
114
115
116 class BC_ActiveBitmaps : public List<BC_BitmapImage> {
117         Mutex active_lock;
118 public:
119         void reque(XEvent *ev);
120         void insert(BC_BitmapImage *image, Drawable pixmap);
121         void remove_buffers(BC_WindowBase *wdw);
122
123         BC_ActiveBitmaps();
124         ~BC_ActiveBitmaps();
125 };
126
127
128 // Windows, subwindows, popupwindows inherit from this
129 class BC_WindowBase : public trace_info
130 {
131 public:
132         BC_WindowBase(int opts=0);
133         virtual ~BC_WindowBase();
134
135         friend class BC_Bar;
136         friend class BC_BitmapImage;
137         friend class BC_XImage;
138         friend class BC_XShmImage;
139         friend class BC_XvImage;
140         friend class BC_XvShmImage;
141         friend class BC_Bitmap;
142         friend class BC_Button;
143         friend class BC_GenericButton;
144         friend class BC_Capture;
145         friend class BC_Clipboard;
146         friend class BC_Display;
147         friend class BC_DragWindow;
148         friend class BC_FileBox;
149         friend class BC_FullScreen;
150         friend class BC_ListBox;
151         friend class BC_Menu;
152         friend class BC_MenuBar;
153         friend class BC_MenuItem;
154         friend class BC_MenuPopup;
155         friend class BC_Meter;
156         friend class BC_Pan;
157         friend class BC_PBuffer;
158         friend class BC_Pixmap;
159         friend class BC_PixmapSW;
160         friend class BC_Popup;
161         friend class BC_PopupMenu;
162         friend class BC_Pot;
163         friend class BC_ProgressBar;
164         friend class BC_Repeater;
165         friend class BC_Resources;
166         friend class BC_ScrollBar;
167         friend class BC_Slider;
168         friend class BC_SubWindow;
169         friend class BC_Synchronous;
170         friend class BC_TextBox;
171         friend class BC_Title;
172         friend class BC_Toggle;
173         friend class BC_Tumbler;
174         friend class BC_Window;
175         friend class BC_WindowEvents;
176
177 // Main loop
178         int run_window();
179 // Terminal event dispatchers
180         virtual int close_event();
181         virtual int resize_event(int w, int h);
182         virtual int repeat_event(int64_t duration) { return 0; };
183         virtual int focus_in_event() { return 0; };
184         virtual int focus_out_event() { return 0; };
185         virtual int button_press_event() { return 0; };
186         virtual int button_release_event() { return 0; };
187         virtual int cursor_motion_event() { return 0; };
188         virtual int cursor_leave_event();
189         virtual int cursor_enter_event();
190         virtual int keypress_event() { return 0; };
191         virtual int keyrelease_event() { return 0; };
192         virtual int translation_event() { return 0; };
193         virtual int drag_start_event() { return 0; };
194         virtual int drag_motion_event() { return 0; };
195         virtual int drag_stop_event() { return 0; };
196         virtual int uses_text() { return 0; };
197         virtual int selection_clear_event() { return 0; }
198 // Only if opengl is enabled
199         virtual int expose_event() { return 0; };
200         virtual int grab_event(XEvent *event) { return 0; };
201         virtual void create_objects() { return; };
202
203         int get_window_type() { return window_type; }
204 // Wait until event loop is running
205         void init_wait();
206         int is_running() { return window_running; }
207         int is_hidden() { return hidden; }
208 // Check if a hardware accelerated colormodel is available and reserve it
209         int accel_available(int color_model, int lock_it);
210         void get_input_context();
211         void close_input_context();
212 // Get color model adjusted for byte order and pixel size
213         int get_color_model();
214 // return the colormap pixel of the color for all bit depths
215         int get_color(int64_t color);
216 // return the currently selected color
217         int64_t get_color();
218         virtual int show_window(int flush = 1);
219         virtual int hide_window(int flush = 1);
220         int get_hidden();
221         int get_video_on();
222 // Shouldn't deference a pointer to delete a window if a parent is
223 // currently being deleted.  This returns 1 if any parent is being deleted.
224         int get_deleting();
225
226
227
228 //============================= OpenGL functions ===============================
229 // OpenGL functions must be called from inside a BC_Synchronous command.
230 // Create openGL context and bind it to the current window.
231 // If it's called inside start_video/stop_video, the context is bound to the window.
232 // If it's called outside start_video/stop_video, the context is bound to the pixmap.
233 // Must be called at the beginning of any opengl routine to make sure
234 // the context is current.
235 // No locking is performed.
236         void enable_opengl();
237         void disable_opengl();
238         void flip_opengl();
239
240 // Calls the BC_Synchronous version of the function with the window_id.
241 // Not run in OpenGL thread because it has its own lock.
242         unsigned int get_shader(char *title, int *got_it);
243         void put_shader(unsigned int handle, char *title);
244         int get_opengl_server_version();
245
246         int flash(int x, int y, int w, int h, int flush = 1);
247         int flash(int flush = 1);
248         void flush();
249         void sync_display();
250 // Lock out other threads
251         int lock_window(const char *location = 0);
252         int unlock_window();
253         int get_window_lock();
254
255         BC_MenuBar* add_menubar(BC_MenuBar *menu_bar);
256         BC_WindowBase* add_subwindow(BC_WindowBase *subwindow);
257         BC_WindowBase* add_tool(BC_WindowBase *subwindow);
258
259 // Use this to get events for the popup window.
260 // Events are not propagated to the popup window.
261         BC_WindowBase* add_popup(BC_WindowBase *window);
262         void remove_popup(BC_WindowBase *window);
263
264         static BC_Resources* get_resources();
265 // User must create synchronous object first
266         static BC_Synchronous* get_synchronous();
267         static int shm_completion_event;
268 // bckeyboard / remote control
269         virtual int keyboard_listener(BC_WindowBase *wp) { return 0; }
270         void add_keyboard_listener(int(BC_WindowBase::*handler)(BC_WindowBase *));
271         void del_keyboard_listener(int(BC_WindowBase::*handler)(BC_WindowBase *));
272 // Dimensions
273         virtual int get_w() { return w; }
274         virtual int get_h() { return h; }
275         virtual int get_x() { return x; }
276         virtual int get_y() { return y; }
277         int get_root_w(int lock_display);
278         int get_root_h(int lock_display);
279         XineramaScreenInfo *get_xinerama_info(int screen);
280         int get_screen_w(int lock_display, int screen);
281         int get_screen_h(int lock_display, int screen);
282         int get_screen_x(int lock_display, int screen);
283         int get_screen_y(int lock_display, int screen);
284 // Get current position
285         void get_abs_cursor_xy(int &abs_x, int &abs_y, int lock_window=0);
286         int get_abs_cursor_x(int lock_window=0);
287         int get_abs_cursor_y(int lock_window=0);
288         void get_pop_cursor_xy(int &px, int &py, int lock_window=0);
289         int get_pop_cursor_x(int lock_window=0);
290         int get_pop_cursor_y(int lock_window=0);
291         void get_relative_cursor_xy(int &x, int &y, int lock_window=0);
292         int get_relative_cursor_x(int lock_window=0);
293         int get_relative_cursor_y(int lock_window=0);
294         void get_root_coordinates(int x, int y, int *abs_x, int *abs_y);
295         void get_win_coordinates(int abs_x, int abs_y, int *x, int *y);
296 // Return 1 if cursor is over an unobscured part of this window.
297 // An argument is provided for excluding a drag popup
298         int get_cursor_over_window();
299 // Return 1 if cursor is above/inside window
300         int cursor_above();
301 // For traversing windows... return 1 if this or any subwindow is win
302         int match_window(Window win);
303
304 // 1 or 0 if a button is down
305         int get_button_down();
306 // Number of button pressed 1 - 5
307         int get_buttonpress();
308         int get_has_focus();
309         int get_dragging();
310         wchar_t* get_wkeystring(int *length = 0);
311         int get_keypress();
312 #ifdef X_HAVE_UTF8_STRING
313         char* get_keypress_utf8();
314 #endif
315         int keysym_lookup(XEvent *event);
316 // Get cursor position of last event
317         int get_cursor_x();
318         int get_cursor_y();
319 // Cursor position of drag start
320         int get_drag_x();
321         int get_drag_y();
322         int alt_down();
323         int shift_down();
324         int ctrl_down();
325         int get_double_click();
326         int get_triple_click();
327 // Bottom right corner
328         int get_x2();
329         int get_y2();
330         int get_bg_color();
331         void set_bg_color(int color);
332         BC_Pixmap* get_bg_pixmap();
333         int get_text_ascent(int font);
334         int get_text_descent(int font);
335         int get_text_height(int font, const char *text = 0);
336         int get_text_width(int font, const char *text, int length = -1);
337         int get_text_width(int font, const wchar_t *text, int length = -1);
338         BC_Clipboard* get_clipboard();
339         void set_dragging(int value);
340         int set_w(int w);
341         int set_h(int h);
342         BC_WindowBase* get_top_level();
343         BC_WindowBase* get_parent();
344 // Event happened in this window
345         int is_event_win();
346         int cursor_inside();
347 // Deactivate everything and activate this subwindow
348         virtual int activate();
349 // Deactivate this subwindow
350         virtual int deactivate();
351         void set_active_subwindow(BC_WindowBase *subwindow);
352 // Get value of toggle value when dragging a selection
353         int get_toggle_value();
354 // Get if toggle is being dragged
355         int get_toggle_drag();
356
357 // Set the gc to the color
358         void set_color(int64_t color);
359         void set_line_width(int value);
360         void set_line_dashes(int value);
361         int get_bgcolor();
362         int get_current_font();
363         void set_font(int font);
364 // Set the cursor to a macro from cursors.h
365 // Set override if the caller is enabling hourglass or hiding the cursor
366         void set_cursor(int cursor, int override /* = 0 */, int flush);
367 // Set the cursor to a character in the X cursor library.  Used by test.C
368         void set_x_cursor(int cursor);
369         int get_cursor();
370 // Shows the cursor after it's hidden by video playback
371         void unhide_cursor();
372 // Called by video updating routines to hide the cursor after a timeout
373         void update_video_cursor();
374
375 // Entry point for starting hourglass.
376 // Converts all cursors and saves the previous cursor.
377         void start_hourglass();
378         void stop_hourglass();
379
380 // Recursive part of hourglass commands.
381         void start_hourglass_recursive();
382         void stop_hourglass_recursive();
383 // images, picons...
384         BC_Pixmap *create_pixmap(VFrame *vframe);
385
386 // Drawing
387         void copy_area(int x1, int y1, int x2, int y2, int w, int h, BC_Pixmap *pixmap = 0);
388         void clear_box(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
389         void draw_box(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
390         void draw_circle(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
391         void draw_arc(int x, int y, int w, int h,
392                 int start_angle, int angle_length, BC_Pixmap *pixmap = 0);
393         void draw_disc(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
394         void draw_text(int x, int y, const char *text, int length = -1, BC_Pixmap *pixmap = 0);
395         void draw_utf8_text(int x, int y, const char *text, int length = -1, BC_Pixmap *pixmap = 0);
396         void draw_text_line(int x, int y, const char *text, int len, BC_Pixmap *pixmap = 0);
397         void draw_xft_text(int x, int y, const char *text, int len,
398                 BC_Pixmap *pixmap = 0, int is_utf8 = 0);
399         void draw_xft_text(int x, int y, const wchar_t *text,
400                 int length, BC_Pixmap *pixmap);
401         int draw_single_text(int draw, int font,
402                 int x, int y, const wchar_t *text, int length = -1, BC_Pixmap *pixmap = 0);
403 // truncate the text to a ... version that fits in the width, using the current_font
404         void truncate_text(char *result, const char *text, int w);
405         void draw_center_text(int x, int y, const char *text, int length = -1);
406         void draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap = 0);
407         void draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap = 0);
408         void fill_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap = 0);
409         void draw_rectangle(int x, int y, int w, int h);
410         void draw_3segment(int x, int y, int w, int h, BC_Pixmap *left_image,
411                 BC_Pixmap *mid_image, BC_Pixmap *right_image, BC_Pixmap *pixmap = 0);
412         void draw_3segment(int x, int y, int w, int h, VFrame *left_image,
413                 VFrame *mid_image, VFrame *right_image, BC_Pixmap *pixmap = 0);
414 // For drawing a changing level
415         void draw_3segmenth(int x, int y, int w, int total_x, int total_w,
416                 VFrame *image, BC_Pixmap *pixmap);
417         void draw_3segmenth(int x, int y, int w, int total_x, int total_w,
418                 BC_Pixmap *src, BC_Pixmap *dst = 0);
419         void draw_3segmentv(int x, int y, int h, int total_y, int total_h,
420                 BC_Pixmap *src, BC_Pixmap *dst = 0);
421         void draw_3segmentv(int x, int y, int h, int total_y, int total_h,
422                 VFrame *src, BC_Pixmap *dst = 0);
423 // For drawing a single level
424         void draw_3segmenth(int x, int y, int w, VFrame *image, BC_Pixmap *pixmap = 0);
425         void draw_3segmenth(int x, int y, int w, BC_Pixmap *src, BC_Pixmap *dst = 0);
426         void draw_3segmentv(int x, int y, int h, BC_Pixmap *src, BC_Pixmap *dst = 0);
427         void draw_3segmentv(int x, int y, int h, VFrame *src, BC_Pixmap *dst = 0);
428         void draw_9segment(int x, int y, int w, int h, VFrame *src, BC_Pixmap *dst = 0);
429         void draw_9segment(int x, int y, int w, int h, BC_Pixmap *src, BC_Pixmap *dst = 0);
430         void draw_3d_box(int x, int y, int w, int h, int light1, int light2,
431                 int middle, int shadow1, int shadow2, BC_Pixmap *pixmap = 0);
432         void draw_3d_box(int x, int y, int w, int h, int is_down, BC_Pixmap *pixmap = 0);
433         void draw_3d_border(int x, int y, int w, int h,
434                 int light1, int light2, int shadow1, int shadow2);
435         void draw_3d_border(int x, int y, int w, int h, int is_down);
436         void draw_colored_box(int x, int y, int w, int h, int down, int highlighted);
437         void draw_check(int x, int y);
438         void draw_triangle_down_flat(int x, int y, int w, int h);
439         void draw_triangle_up(int x, int y, int w, int h,
440                 int light1, int light2, int middle, int shadow1, int shadow2);
441         void draw_triangle_down(int x, int y, int w, int h,
442                 int light1, int light2, int middle, int shadow1, int shadow2);
443         void draw_triangle_left(int x, int y, int w, int h,
444                 int light1, int light2, int middle, int shadow1, int shadow2);
445         void draw_triangle_right(int x, int y, int w, int h,
446                 int light1, int light2, int middle, int shadow1, int shadow2);
447 // Set the gc to opaque
448         void set_opaque();
449         void set_inverse();
450         void set_background(VFrame *bitmap);
451 // Change the window title.
452         void put_title(const char *text);
453         void set_title(const char *text, int utf8=1);
454         const char *get_title();
455 // Change the window title.  The title is translated internally.
456         void start_video();
457         void stop_video();
458         int get_id();
459         void set_done(int return_value);
460         void close(int return_value);
461 // Reroute toplevel events
462         int grab(BC_WindowBase *window);
463         int ungrab(BC_WindowBase *window);
464 // Grab button events
465         int grab_buttons();
466         void ungrab_buttons();
467         void grab_cursor();
468         void ungrab_cursor();
469 // Get a bitmap to draw on the window with
470         BC_Bitmap* new_bitmap(int w, int h, int color_model = -1);
471 // Draw a bitmap on the window
472         void draw_bitmap(BC_Bitmap *bitmap, int dont_wait,
473                 int dest_x = 0, int dest_y = 0, int dest_w = 0, int dest_h = 0,
474                 int src_x = 0, int src_y = 0, int src_w = 0, int src_h = 0,
475                 BC_Pixmap *pixmap = 0);
476         void draw_pixel(int x, int y, BC_Pixmap *pixmap = 0);
477 // Draw a pixmap on the window
478         void draw_pixmap(BC_Pixmap *pixmap,
479                 int dest_x = 0, int dest_y = 0, int dest_w = -1, int dest_h = -1,
480                 int src_x = 0, int src_y = 0, BC_Pixmap *dst = 0);
481 // Draw a vframe on the window
482         void draw_vframe(VFrame *frame,
483                 int dest_x = 0, int dest_y = 0, int dest_w = -1, int dest_h = -1,
484                 int src_x = 0, int src_y = 0, int src_w = 0, int src_h = 0,
485                 BC_Pixmap *pixmap = 0);
486         void draw_border(char *text, int x, int y, int w, int h);
487 // Draw a region of the background
488         void draw_top_background(BC_WindowBase *parent_window, int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
489         void draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h);
490         void draw_background(int x, int y, int w, int h);
491         void draw_tiles(BC_Pixmap *tile, int origin_x, int origin_y,
492                 int x, int y, int w, int h);
493         void slide_left(int distance);
494         void slide_right(int distance);
495         void slide_up(int distance);
496         void slide_down(int distance);
497         void flicker(int n=3, int ms=66);
498
499         int cycle_textboxes(int amount);
500
501         int raise_window(int do_flush = 1);
502         int lower_window(int do_flush = 1);
503         void set_force_tooltip(int v);
504         void set_tooltips(int v);
505         int resize_window(int w, int h);
506         int reposition_window(int x, int y);
507         int reposition_window(int x, int y, int w, int h);
508         int reposition_window_relative(int dx, int dy);
509         int reposition_window_relative(int dx, int dy, int w, int h);
510 // Cause a repeat event to be dispatched every duration.
511 // duration is milliseconds
512         int set_repeat(int64_t duration);
513 // Stop a repeat event from being dispatched.
514         int unset_repeat(int64_t duration);
515         const char *get_tooltip();
516         int set_tooltip(const char *text);
517         virtual int show_tooltip(const char *text, int x=-1, int y=-1, int w = -1, int h = -1);
518         int show_tooltip(int w=-1, int h=-1) { return show_tooltip(0, -1, -1, w, h); }
519         int hide_tooltip();
520         int set_icon(VFrame *data);
521         int load_defaults(BC_Hash *defaults);
522         int save_defaults(BC_Hash *defaults);
523
524 #ifdef HAVE_LIBXXF86VM
525 // Mode switch methods.
526    void closest_vm(int *vm, int *width, int *height);
527    void scale_vm(int vm);
528    void restore_vm();
529 #endif
530
531         Atom to_clipboard(const char *data, long len, int clipboard_num);
532         long from_clipboard(char *data, long maxlen, int clipboard_num);
533         long clipboard_len(int clipboard_num);
534
535         int test_keypress;
536         char keys_return[KEYPRESSLEN];
537
538
539 private:
540 // Create a window
541         virtual int create_window(BC_WindowBase *parent_window,
542                 const char *title, int x, int y, int w, int h,
543                 int minw, int minh, int allow_resize, int private_color,
544                 int hide, int bg_color, const char *display_name,
545                 int window_type, BC_Pixmap *bg_pixmap, int group_it);
546
547         static Display* init_display(const char *display_name);
548 // Get display from top level
549         Display* get_display();
550         int get_screen();
551         virtual int initialize();
552         int get_atoms();
553 // Function to overload to recieve customly defined atoms
554         virtual int recieve_custom_xatoms(xatom_event *event);
555
556         void init_cursors();
557         int init_colors();
558         int init_window_shape();
559         static int evaluate_color_model(int client_byte_order, int server_byte_order, int depth);
560         int create_private_colors();
561         int create_color(int color);
562         int create_shared_colors();
563         Cursor create_grab_cursor();
564 // Get width of a single line.  Used by get_text_width
565         int get_single_text_width(int font, const char *text, int length);
566         int get_single_text_width(int font, const wchar_t *text, int length);
567         int allocate_color_table();
568         int init_gc();
569         int init_fonts();
570         void init_xft();
571         void init_im();
572         void finit_im();
573         int get_color_rgb8(int color);
574         int64_t get_color_rgb16(int color);
575         int64_t get_color_bgr16(int color);
576         int64_t get_color_bgr24(int color);
577         XFontStruct* get_font_struct(int font);
578         XftFont* get_xft_struct(int font);
579         Cursor get_cursor_struct(int cursor);
580         XFontSet get_fontset(int font);
581         XFontSet get_curr_fontset(void);
582         void set_fontset(int font);
583         int dispatch_event(XEvent *event);
584
585         int get_key_masks(unsigned int key_state);
586
587         int trigger_tooltip();
588         int untrigger_tooltip();
589         void draw_tooltip(const char *text=0);
590         static XEvent *new_xevent();
591 // delete all repeater opjects for a close
592         int unset_all_repeaters();
593
594 // Block and get event from common events.
595         XEvent* get_event();
596 // Return number of events in table.
597         int get_event_count();
598 // Put event in common events.
599         void put_event(XEvent *event);
600 // remove events queued for win
601         void dequeue_events(Window win);
602 // clear selection
603         int do_selection_clear(Atom selection);
604
605 // Recursive event dispatchers
606         int dispatch_resize_event(int w, int h);
607         int dispatch_flash();
608         int dispatch_focus_in();
609         int dispatch_focus_out();
610         int dispatch_motion_event();
611         int dispatch_keypress_event();
612         int dispatch_keyrelease_event();
613         int dispatch_repeat_event(int64_t duration);
614         int dispatch_repeat_event_master(int64_t duration);
615         int dispatch_button_press();
616         int dispatch_button_release();
617         int dispatch_cursor_leave();
618         int dispatch_cursor_enter();
619         int dispatch_translation_event();
620         int dispatch_drag_start();
621         int dispatch_drag_motion();
622         int dispatch_drag_stop();
623         int dispatch_expose_event();
624         int dispatch_selection_clear();
625
626 // Get the port ID for a color model or return -1 for failure
627         int grab_port_id(int color_model);
628
629         int find_next_textbox(BC_WindowBase **first_textbox, BC_WindowBase **next_textbox, int &result);
630         int find_prev_textbox(BC_WindowBase **last_textbox, BC_WindowBase **prev_textbox, int &result);
631
632         void xft_draw_string(XftColor *xft_color, XftFont *xft_font, int x, int y,
633                 const FcChar32 *fc, int len, BC_Pixmap *pixmap=0);
634
635         void translate_coordinates(Window src_w, Window dest_w,
636                 int src_x, int src_y, int *dest_x_return, int *dest_y_return);
637
638 // Top level window above this window
639         BC_WindowBase* top_level;
640 // Window just above this window
641         BC_WindowBase* parent_window;
642 // list of window bases in this window
643         BC_SubWindowList* subwindows;
644 // list of window bases in this window
645         ArrayList<BC_WindowBase*> popups;
646 // Position of window
647         int x, y, w, h;
648 // Default colors
649         int light1, light2, medium, dark1, dark2, bg_color;
650 // Type of window defined above
651         int window_type;
652 // keypress/pointer active grab
653         BC_WindowBase *active_grab, *grab_active;
654 // Pointer to the active menubar in the window.
655         BC_MenuBar* active_menubar;
656 // pointer to the active popup menu in the window
657         BC_PopupMenu* active_popup_menu;
658 // pointer to the active subwindow
659         BC_WindowBase* active_subwindow;
660 // thread id of display locker
661         pthread_t display_lock_owner;
662
663 // Window parameters
664         int allow_resize;
665         int hidden, private_color, bits_per_pixel, color_model;
666         int server_byte_order, client_byte_order;
667 // number of colors in color table
668         int total_colors;
669 // last color found in table
670         int current_color_value, current_color_pixel;
671 // table for every color allocated
672         int color_table[256][2];
673 // Turn on optimization
674         int video_on;
675 // Event handler completion
676         int done, done_set, window_running;
677 // Enter/Leave notify state
678         int cursor_entered;
679 // Return value of event handler
680         int return_value;
681 // Motion event compression
682         int motion_events, last_motion_x, last_motion_y;
683         unsigned int last_motion_state;
684 // window of buffered motion
685         Window last_motion_win;
686 // Resize event compression
687         int resize_events, last_resize_w, last_resize_h;
688         int translation_events, last_translate_x, last_translate_y;
689         int prev_x, prev_y;
690 // Since the window manager automatically translates the window at boot,
691 // use the first translation event to get correction factors
692         int translation_count;
693         int x_correction, y_correction;
694 // key data
695         KeySym keysym;
696 // Key masks
697         int ctrl_mask, shift_mask, alt_mask;
698 // Cursor motion information
699         int cursor_x, cursor_y;
700 // Button status information
701         int button_down, button_number;
702 // When button was pressed and whether it qualifies as a double click
703         int64_t button_time1;
704         int64_t button_time2;
705         int64_t button_time3;
706         int double_click;
707         int triple_click;
708 // Which button is down.  1, 2, 3, 4, 5
709         int button_pressed;
710 // Last key pressed
711         int key_pressed;
712         int wkey_string_length;
713         wchar_t wkey_string[4];
714 #ifdef X_HAVE_UTF8_STRING
715         char* key_pressed_utf8;
716 #endif
717 // During a selection drag involving toggles, set the same value for each toggle
718         int toggle_value;
719         int toggle_drag;
720 // Whether the window has the focus
721         int has_focus;
722
723         static BC_Resources resources;
724
725 #ifndef SINGLE_THREAD
726 // Array of repeaters for multiple repeating objects.
727         ArrayList<BC_Repeater*> repeaters;
728         int arm_repeat(int64_t duration);
729 #endif
730 // Text for tooltip if one exists
731         const char *tooltip_text;
732 // tooltip forced for this window
733         int force_tooltip;
734 // If the current window's tooltip is visible
735         int tooltip_on;
736 // Repeat ID of tooltip
737 //      int64_t tooltip_id;
738 // Popup window for tooltip
739         BC_Popup *tooltip_popup;
740 // If this subwindow has already shown a tooltip since the last EnterNotify
741         int options;
742         int flash_enabled;
743
744
745 // Font sets
746         XFontSet smallfontset, mediumfontset, largefontset, bigfontset, clockfontset;
747         XFontSet curr_fontset;
748 // Fonts
749         int current_font;
750         XFontStruct *smallfont, *mediumfont, *largefont, *bigfont, *clockfont;
751 // Must be void so users don't need to include the wrong libpng version.
752         void *smallfont_xft, *mediumfont_xft, *largefont_xft, *bigfont_xft, *clockfont_xft;
753         void *bold_smallfont_xft, *bold_mediumfont_xft, *bold_largefont_xft;
754
755         int line_width;
756         int line_dashes;
757         int64_t current_color;
758 // Coordinate of drag start
759         int drag_x, drag_y;
760 // Boundaries the cursor must pass to start a drag
761         int drag_x1, drag_x2, drag_y1, drag_y2;
762 // Dragging is specific to the subwindow
763         int is_dragging;
764 // Don't delete the background pixmap
765         int shared_bg_pixmap;
766         char title[BCTEXTLEN];
767
768 // X Window parameters
769         int screen;
770         Window rootwin;
771 // windows previous events happened in
772         Window event_win, drag_win;
773 // selection clear
774         Atom event_selection;
775         Visual *vis;
776         Colormap cmap;
777 // Name of display
778         char display_name[BCTEXTLEN];
779 // Display for all synchronous operations
780         Display *display;
781         Window win;
782         int xinerama_screens;
783         XineramaScreenInfo *xinerama_info;
784 #ifdef HAVE_GL
785         int glx_fb_configs(int *attrs, GLXFBConfig *&cfgs);
786         int glx_test_fb_configs(int *attrs, GLXFBConfig *&cfgs,
787                 const char *msg, int &msgs);
788         GLXFBConfig *glx_fbcfgs_window, *glx_window_fb_configs();
789         int n_fbcfgs_window;
790         GLXFBConfig *glx_fbcfgs_pbuffer, *glx_pbuffer_fb_configs();
791         int n_fbcfgs_pbuffer;
792         GLXFBConfig *glx_fbcfgs_pixmap, *glx_pixmap_fb_configs();
793         int n_fbcfgs_pixmap;
794         Visual *get_glx_visual(Display *display);
795
796         void sync_lock(const char *cp);
797         void sync_unlock();
798         GLXWindow glx_window();
799
800 // The first context to be created and the one whose texture id
801 // space is shared with the other contexts.
802         GLXContext glx_get_context();
803         bool glx_make_current(GLXDrawable draw);
804         bool glx_make_current(GLXDrawable draw, GLXContext glx_ctxt);
805
806         GLXFBConfig glx_fb_config;
807         GLXContext glx_win_context;
808         GLXWindow glx_win;
809 #endif
810
811         int window_lock;
812         GC gc;
813 // Depth given by the X Server
814         int default_depth;
815         Atom DelWinXAtom;
816         Atom DestroyAtom;
817         Atom ProtoXAtom;
818         Atom RepeaterXAtom;
819         Atom SetDoneXAtom;
820 // Number of times start_hourglass was called
821         int hourglass_total;
822 // Cursor set by last set_cursor which wasn't an hourglass or transparent.
823         int current_cursor;
824 // If hourglass overrides current cursor.  Only effective in top level.
825         int is_hourglass;
826 // If transparent overrides all cursors.  Only effective in subwindow.
827         int is_transparent;
828         Cursor arrow_cursor;
829         Cursor cross_cursor;
830         Cursor ibeam_cursor;
831         Cursor vseparate_cursor;
832         Cursor hseparate_cursor;
833         Cursor move_cursor;
834         Cursor temp_cursor;
835         Cursor left_cursor;
836         Cursor right_cursor;
837         Cursor upright_arrow_cursor;
838         Cursor upleft_resize_cursor;
839         Cursor upright_resize_cursor;
840         Cursor downleft_resize_cursor;
841         Cursor downright_resize_cursor;
842         Cursor hourglass_cursor;
843         Cursor transparent_cursor;
844         Cursor grabbed_cursor;
845
846         int xvideo_port_id;
847         ArrayList<BC_ResizeCall*> resize_history;
848 // Back buffer
849         BC_Pixmap *pixmap;
850 // Background tile if tiled
851         BC_Pixmap *bg_pixmap;
852 // Icon
853         BC_Popup *icon_window;
854         BC_Pixmap *icon_pixmap;
855         BC_Pixmap **_7segment_pixmaps;
856 // Temporary
857         BC_Bitmap *temp_bitmap;
858         BC_ActiveBitmaps active_bitmaps;
859 // Clipboard
860 #ifndef SINGLE_THREAD
861         BC_Clipboard *clipboard;
862 #endif
863
864 #ifdef HAVE_LIBXXF86VM
865 // Mode switch information.
866    int vm_switched;
867    XF86VidModeModeInfo orig_modeline;
868 #endif
869
870
871
872
873 #ifndef SINGLE_THREAD
874 // Common events coming from X server and repeater.
875         ArrayList<XEvent*> common_events;
876 // Locks for common events
877 // Locking order:
878 // 1) event_condition
879 // 2) event_lock
880         Mutex *event_lock;
881         Condition *event_condition;
882 // Lock that waits until the event handler is running
883         Condition *init_lock;
884 #else
885         Condition *completion_lock;
886 #endif
887
888
889         int dump_windows();
890
891
892         BC_WindowEvents *event_thread;
893         int is_deleting;
894 // Hide cursor when video is enabled
895         Timer *cursor_timer;
896 // unique ID of window.
897         int id;
898
899         // Used to communicate with the input method (IM) server
900         XIM input_method;
901         // Used for retaining the state, properties, and semantics
902         //  of communication with the input method (IM) server
903         XIC input_context;
904
905 protected:
906         Atom create_xatom(const char *atom_name);
907         int send_custom_xatom(xatom_event *event);
908
909 };
910
911
912
913 #endif