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