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