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