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