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