r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / guicast / bcwindowbase.h
blob66f0e5cc36f2590cb38c364938c357cab0e5a1a1
1 #ifndef BCWINDOWBASE_H
2 #define BCWINDOWBASE_H
4 // Window types
5 #define MAIN_WINDOW 0
6 #define SUB_WINDOW 1
7 #define POPUP_WINDOW 2
8 #ifdef HAVE_LIBXXF86VM
9 #define VIDMODE_SCALED_WINDOW 3
10 #endif
12 #define TOOLTIP_MARGIN 2
13 #define BC_INFINITY 65536
15 #include "bcfilebox.inc"
16 #include "arraylist.h"
17 #include "bcbitmap.inc"
18 #include "bcbutton.inc"
19 #include "bccapture.inc"
20 #include "bcdragwindow.inc"
21 #include "bcclipboard.inc"
22 #include "bclistbox.inc"
23 #include "bcmenubar.inc"
24 #include "bcmeter.inc"
25 #include "bcpan.inc"
26 #include "bcpixmap.inc"
27 #include "bcpopup.inc"
28 #include "bcpopupmenu.inc"
29 #include "bcpot.inc"
30 #include "bcprogress.inc"
31 #include "bcrepeater.inc"
32 #include "bcresources.inc"
33 #include "bcscrollbar.inc"
34 #include "bcslider.inc"
35 #include "bcsubwindow.inc"
36 #include "bctextbox.inc"
37 #include "bctitle.inc"
38 #include "bctoggle.inc"
39 #include "bctumble.inc"
40 #include "bcwindow.inc"
41 #include "bcwindowbase.inc"
42 #include "defaults.inc"
43 #include "linklist.h"
44 #include "mutex.h"
45 #include "vframe.inc"
48 #include <stdint.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <X11/Xatom.h>
52 #include <X11/Xlib.h>
53 #include <X11/Xutil.h>
54 #include <X11/keysym.h>
55 #include <X11/cursorfont.h>
56 #ifdef HAVE_LIBXXF86VM
57 #include <X11/extensions/xf86vmode.h>
58 #endif
63 #ifdef HAVE_GL
64 typedef void* GLXContext;
65 #endif
67 class BC_ResizeCall
69 public:
70 BC_ResizeCall(int w, int h);
71 int w, h;
74 class BC_WindowTree
76 public:
77 BC_WindowTree(Display* display, BC_WindowTree *parent_tree, Window root_win);
78 ~BC_WindowTree();
80 void dump(int indent, Window caller_win = 0);
81 BC_WindowTree* get_node(Window win);
82 ArrayList<BC_WindowTree*> windows;
84 Display* display;
85 Window win;
86 BC_WindowTree *parent_tree;
90 // Windows, subwindows, popupwindows inherit from this
91 class BC_WindowBase
93 public:
94 BC_WindowBase();
95 virtual ~BC_WindowBase();
97 friend class BC_Bitmap;
98 friend class BC_Button;
99 friend class BC_GenericButton;
100 friend class BC_Capture;
101 friend class BC_Clipboard;
102 friend class BC_DragWindow;
103 friend class BC_FileBox;
104 friend class BC_FullScreen;
105 friend class BC_ListBox;
106 friend class BC_Menu;
107 friend class BC_MenuBar;
108 friend class BC_MenuItem;
109 friend class BC_MenuPopup;
110 friend class BC_Meter;
111 friend class BC_Pan;
112 friend class BC_Pixmap;
113 friend class BC_Popup;
114 friend class BC_PopupMenu;
115 friend class BC_Pot;
116 friend class BC_ProgressBar;
117 friend class BC_Repeater;
118 friend class BC_Resources;
119 friend class BC_ScrollBar;
120 friend class BC_Slider;
121 friend class BC_SubWindow;
122 friend class BC_TextBox;
123 friend class BC_Title;
124 friend class BC_Toggle;
125 friend class BC_Tumbler;
126 friend class BC_Window;
128 // Main loop
129 int run_window();
131 // Terminal event dispatchers
132 virtual int close_event();
133 virtual int resize_event(int w, int h);
134 virtual int cursor_motion_event() { return 0; };
135 virtual int repeat_event(int64_t duration) { return 0; };
136 virtual int button_press_event() { return 0; };
137 virtual int button_release_event() { return 0; };
138 virtual int cursor_leave_event();
139 virtual int cursor_enter_event();
140 virtual int keypress_event() { return 0; };
141 virtual int translation_event() { return 0; };
142 virtual int drag_start_event() { return 0; };
143 virtual int drag_motion_event() { return 0; };
144 virtual int drag_stop_event() { return 0; };
145 virtual int uses_text() { return 0; };
146 // Only if opengl is enabled
147 virtual int expose_event() { return 0; };
149 // Check if a hardware accelerated colormodel is available and reserve it
150 int accel_available(int color_model);
151 // Get color model adjusted for byte order and pixel size
152 int get_color_model();
153 // return the colormap pixel of the color for all bit depths
154 int get_color(int64_t color);
155 // return the currently selected color
156 int64_t get_color();
157 int show_window();
158 int hide_window();
159 int get_hidden();
160 void enable_opengl();
161 void disable_opengl();
162 void lock_opengl();
163 void unlock_opengl();
164 void flip_opengl();
166 int flash(int x = -1, int y = -1, int w = -1, int h = -1);
167 void flush();
168 void sync_display();
169 // Lock out other threads
170 int lock_window();
171 int unlock_window();
172 int get_window_lock();
174 BC_MenuBar* add_menubar(BC_MenuBar *menu_bar);
175 BC_WindowBase* add_subwindow(BC_WindowBase *subwindow);
176 BC_WindowBase* add_tool(BC_WindowBase *subwindow);
178 static BC_Resources* get_resources();
179 // Dimensions
180 virtual int get_w();
181 virtual int get_h();
182 virtual int get_x();
183 virtual int get_y();
184 int get_root_w(int ignore_dualhead = 0);
185 int get_root_h();
186 // Get current position
187 int get_abs_cursor_x();
188 int get_abs_cursor_y();
189 int get_relative_cursor_x();
190 int get_relative_cursor_y();
191 // Return 1 if cursor is over an unobscured part of this window.
192 // An argument is provided for excluding a drag popup
193 int get_cursor_over_window();
194 int get_button_down();
195 int get_buttonpress();
196 int get_dragging();
197 int get_keypress();
198 // Get cursor position of last event
199 int get_cursor_x();
200 int get_cursor_y();
201 // Cursor position of drag start
202 int get_drag_x();
203 int get_drag_y();
204 int relative_cursor_x(BC_WindowBase *pov);
205 int relative_cursor_y(BC_WindowBase *pov);
206 int alt_down();
207 int shift_down();
208 int ctrl_down();
209 int get_double_click();
210 // Bottom right corner
211 int get_x2();
212 int get_y2();
213 int get_bg_color();
214 BC_Pixmap* get_bg_pixmap();
215 int get_text_ascent(int font);
216 int get_text_descent(int font);
217 int get_text_height(int font, char *text = 0);
218 int get_text_width(int font, char *text, int length = -1);
219 BC_Clipboard* get_clipboard();
220 void set_dragging(int value);
221 int set_w(int w);
222 int set_h(int h);
223 BC_WindowBase* get_top_level();
224 BC_WindowBase* get_parent();
225 // Event happened in this window
226 int is_event_win();
227 int cursor_inside();
228 // Deactivate everything and activate this subwindow
229 virtual int activate();
230 // Deactivate this subwindow
231 virtual int deactivate();
232 void set_active_subwindow(BC_WindowBase *subwindow);
233 // Get value of toggle value when dragging a selection
234 int get_toggle_value();
237 // Set the gc to the color
238 void set_color(int64_t color);
239 int get_bgcolor();
240 void set_font(int font);
241 void set_cursor(int cursor);
242 void set_x_cursor(int cursor);
243 int get_cursor();
245 // Drawing
246 void copy_area(int x1, int y1, int x2, int y2, int w, int h, BC_Pixmap *pixmap = 0);
247 void clear_box(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
248 void draw_box(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
249 void draw_circle(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
250 void draw_disc(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
251 void draw_text(int x, int y, char *text, int length = -1, BC_Pixmap *pixmap = 0);
252 void draw_center_text(int x, int y, char *text, int length = -1);
253 void draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap = 0);
254 void draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap = 0);
255 void draw_rectangle(int x, int y, int w, int h);
256 void draw_3segment(int x,
257 int y,
258 int w,
259 int h,
260 BC_Pixmap *left_image,
261 BC_Pixmap *mid_image,
262 BC_Pixmap *right_image,
263 BC_Pixmap *pixmap = 0);
264 void draw_3segment(int x,
265 int y,
266 int w,
267 int h,
268 VFrame *left_image,
269 VFrame *mid_image,
270 VFrame *right_image,
271 BC_Pixmap *pixmap = 0);
272 // For drawing a changing level
273 void draw_3segmenth(long x,
274 long y,
275 long w,
276 long total_x,
277 long total_w,
278 VFrame *image,
279 BC_Pixmap *pixmap);
280 void draw_3segmenth(long x,
281 long y,
282 long w,
283 long total_x,
284 long total_w,
285 BC_Pixmap *src,
286 BC_Pixmap *dst = 0);
287 void draw_3segmentv(long x,
288 long y,
289 long h,
290 long total_y,
291 long total_h,
292 BC_Pixmap *src,
293 BC_Pixmap *dst = 0);
294 void draw_3segmentv(long x,
295 long y,
296 long h,
297 long total_y,
298 long total_h,
299 VFrame *src,
300 BC_Pixmap *dst = 0);
301 // For drawing a single level
302 void draw_3segmenth(int x,
303 int y,
304 int w,
305 VFrame *image,
306 BC_Pixmap *pixmap = 0);
307 void draw_3segmenth(long x,
308 long y,
309 long w,
310 BC_Pixmap *src,
311 BC_Pixmap *dst = 0);
312 void draw_3segmentv(long x,
313 long y,
314 long h,
315 BC_Pixmap *src,
316 BC_Pixmap *dst = 0);
317 void draw_3segmentv(long x,
318 long y,
319 long h,
320 VFrame *src,
321 BC_Pixmap *dst = 0);
322 void draw_9segment(long x,
323 long y,
324 long w,
325 long h,
326 VFrame *src,
327 BC_Pixmap *dst = 0);
328 void draw_3d_box(int x,
329 int y,
330 int w,
331 int h,
332 int light1,
333 int light2,
334 int middle,
335 int shadow1,
336 int shadow2,
337 BC_Pixmap *pixmap = 0);
338 void draw_3d_border(int x, int y, int w, int h,
339 int light1, int light2, int shadow1, int shadow2);
340 void draw_colored_box(int x, int y, int w, int h, int down, int highlighted);
341 void draw_check(int x, int y);
342 void draw_triangle_down_flat(int x, int y, int w, int h);
343 void draw_triangle_up(int x, int y, int w, int h,
344 int light1, int light2, int middle, int shadow1, int shadow2);
345 void draw_triangle_down(int x, int y, int w, int h,
346 int light1, int light2, int middle, int shadow1, int shadow2);
347 void draw_triangle_left(int x, int y, int w, int h,
348 int light1, int light2, int middle, int shadow1, int shadow2);
349 void draw_triangle_right(int x, int y, int w, int h,
350 int light1, int light2, int middle, int shadow1, int shadow2);
351 // Set the gc to opaque
352 void set_opaque();
353 void set_inverse();
354 void set_background(VFrame *bitmap);
355 void set_title(char *text);
356 char* get_title();
357 void start_video();
358 void stop_video();
359 int video_is_on();
360 void set_done(int return_value);
361 // Get a bitmap to draw on the window with
362 BC_Bitmap* new_bitmap(int w, int h, int color_model = -1);
363 // Draw a bitmap on the window
364 void draw_bitmap(BC_Bitmap *bitmap,
365 int dont_wait,
366 int dest_x = 0,
367 int dest_y = 0,
368 int dest_w = 0,
369 int dest_h = 0,
370 int src_x = 0,
371 int src_y = 0,
372 int src_w = 0,
373 int src_h = 0,
374 BC_Pixmap *pixmap = 0);
375 void draw_pixel(int x, int y, BC_Pixmap *pixmap = 0);
376 // Draw a pixmap on the window
377 void draw_pixmap(BC_Pixmap *pixmap,
378 int dest_x = 0,
379 int dest_y = 0,
380 int dest_w = -1,
381 int dest_h = -1,
382 int src_x = 0,
383 int src_y = 0,
384 BC_Pixmap *dst = 0);
385 // Draw a vframe on the window
386 void draw_vframe(VFrame *frame,
387 int dest_x = 0,
388 int dest_y = 0,
389 int dest_w = -1,
390 int dest_h = -1,
391 int src_x = 0,
392 int src_y = 0,
393 int src_w = 0,
394 int src_h = 0,
395 BC_Pixmap *pixmap = 0);
396 void draw_border(char *text, int x, int y, int w, int h);
397 // Draw a region of the background
398 void draw_top_background(BC_WindowBase *parent_window, int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
399 void draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h);
400 void draw_background(int x, int y, int w, int h);
401 void draw_tiles(BC_Pixmap *tile,
402 int origin_x,
403 int origin_y,
404 int x,
405 int y,
406 int w,
407 int h);
408 void slide_left(int distance);
409 void slide_right(int distance);
410 void slide_up(int distance);
411 void slide_down(int distance);
413 int cycle_textboxes(int amount);
415 int raise_window();
416 int set_tooltips(int tooltips_enabled);
417 int resize_window(int w, int h);
418 int reposition_window(int x, int y, int w = -1, int h = -1);
419 // int64_t get_repeat_id();
420 int set_repeat(int64_t duration);
421 int unset_repeat(int64_t id);
422 int set_tooltip(char *text);
423 int show_tooltip(int w = -1, int h = -1);
424 int hide_tooltip();
425 int set_icon(VFrame *data);
426 int load_defaults(Defaults *defaults);
427 int save_defaults(Defaults *defaults);
429 #ifdef HAVE_LIBXXF86VM
430 // Mode switch methods.
431 void closest_vm(int *vm, int *width, int *height);
432 void scale_vm(int vm);
433 void restore_vm();
434 #endif
439 private:
440 // Create a window
441 virtual int create_window(BC_WindowBase *parent_window,
442 char *title,
443 int x,
444 int y,
445 int w,
446 int h,
447 int minw,
448 int minh,
449 int allow_resize,
450 int private_color,
451 int hide,
452 int bg_color,
453 char *display_name,
454 int window_type,
455 BC_Pixmap *bg_pixmap);
457 static Display* init_display(char *display_name);
458 virtual int initialize();
459 int get_atoms();
460 void init_cursors();
461 int init_colors();
462 int init_window_shape();
463 static int evaluate_color_model(int client_byte_order, int server_byte_order, int depth);
464 int create_private_colors();
465 int create_color(int color);
466 int create_shared_colors();
467 int get_single_text_width(int font, char *text, int length);
468 int allocate_color_table();
469 int init_gc();
470 int init_fonts();
471 int get_color_rgb8(int color);
472 int64_t get_color_rgb16(int color);
473 int64_t get_color_bgr16(int color);
474 int64_t get_color_bgr24(int color);
475 XFontStruct* get_font_struct(int font);
476 Cursor get_cursor_struct(int cursor);
477 XFontSet get_fontset(int font);
478 XFontSet get_curr_fontset(void);
479 void set_fontset(int font);
480 int dispatch_event();
482 int get_key_masks(XEvent &event);
484 int trigger_tooltip();
485 int untrigger_tooltip();
486 void draw_tooltip();
487 int arm_repeat(int64_t duration);
488 // delete all repeater opjects for a close
489 int unset_all_repeaters();
491 // Recursive event dispatchers
492 int dispatch_resize_event(int w, int h);
493 int dispatch_motion_event();
494 int dispatch_keypress_event();
495 int dispatch_repeat_event(int64_t duration);
496 int dispatch_repeat_event_master(int64_t duration);
497 int dispatch_button_press();
498 int dispatch_button_release();
499 int dispatch_cursor_leave();
500 int dispatch_cursor_enter();
501 int dispatch_translation_event();
502 int dispatch_drag_start();
503 int dispatch_drag_motion();
504 int dispatch_drag_stop();
505 int dispatch_expose_event();
507 // Get the port ID for a color model or return -1 for failure
508 int grab_port_id(BC_WindowBase *window, int color_model);
510 int find_next_textbox(BC_WindowBase **first_textbox, BC_WindowBase **next_textbox, int &result);
511 int find_prev_textbox(BC_WindowBase **last_textbox, BC_WindowBase **prev_textbox, int &result);
515 void translate_coordinates(Window src_w,
516 Window dest_w,
517 int src_x,
518 int src_y,
519 int *dest_x_return,
520 int *dest_y_return);
522 // Top level window above this window
523 BC_WindowBase* top_level;
524 // Window just above this window
525 BC_WindowBase* parent_window;
526 // list of window bases in this window
527 BC_SubWindowList* subwindows;
528 // Position of window
529 int x, y, w, h;
530 // Default colors
531 int light1, light2, medium, dark1, dark2, bg_color;
532 // Type of window defined above
533 int window_type;
534 // Pointer to the active menubar in the window.
535 BC_MenuBar* active_menubar;
536 // pointer to the active popup menu in the window
537 BC_PopupMenu* active_popup_menu;
538 // pointer to the active subwindow
539 BC_WindowBase* active_subwindow;
541 // Window parameters
542 int allow_resize;
543 int hidden, private_color, bits_per_pixel, color_model;
544 int server_byte_order, client_byte_order;
545 // number of colors in color table
546 int total_colors;
547 // last color found in table
548 int current_color_value, current_color_pixel;
549 // table for every color allocated
550 int color_table[256][2];
551 // Turn on optimization
552 int video_on;
553 // Event handler completion
554 int done;
555 // Return value of event handler
556 int return_value;
557 // Motion event compression
558 int motion_events, last_motion_x, last_motion_y;
559 // window of buffered motion
560 Window last_motion_win;
561 // Resize event compression
562 int resize_events, last_resize_w, last_resize_h;
563 int translation_events, last_translate_x, last_translate_y;
564 int prev_x, prev_y;
565 // Since the window manager automatically translates the window at boot,
566 // use the first translation event to get correction factors
567 int translation_count;
568 int x_correction, y_correction;
569 // Key masks
570 int ctrl_mask, shift_mask, alt_mask;
571 // Cursor motion information
572 int cursor_x, cursor_y;
573 // Button status information
574 int button_down, button_number;
575 // When button was pressed and whether it qualifies as a double click
576 uint64_t button_time1, button_time2;
577 int double_click;
578 // Which button is down
579 int button_pressed;
580 // Last key pressed
581 int key_pressed;
582 // During a selection drag involving toggles, set the same value for each toggle
583 int toggle_value;
585 static BC_Resources resources;
586 // Array of repeaters for multiple repeating objects.
587 ArrayList<BC_Repeater*> repeaters;
588 // int64_t next_repeat_id;
589 // Text for tooltip if one exists
590 char tooltip_text[BCTEXTLEN];
591 // If the current window's tooltip is visible
592 int tooltip_on;
593 // Repeat ID of tooltip
594 // int64_t tooltip_id;
595 // Popup window for tooltip
596 BC_Popup *tooltip_popup;
597 // If this subwindow has already shown a tooltip since the last EnterNotify
598 int tooltip_done;
599 // If the tooltip shouldn't be hidden
600 int persistant_tooltip;
601 int current_font;
602 XFontSet largefontset, mediumfontset, smallfontset, curr_fontset;
603 int64_t current_color;
604 // Coordinate of drag start
605 int drag_x, drag_y;
606 // Boundaries the cursor must pass to start a drag
607 int drag_x1, drag_x2, drag_y1, drag_y2;
608 // Dragging is specific to the subwindow
609 int is_dragging;
610 // Don't delete the background pixmap
611 int shared_bg_pixmap;
612 char title[BCTEXTLEN];
614 // Window tree for dragging operations
615 static BC_WindowTree *window_tree;
617 // X Window parameters
618 int screen;
619 Window rootwin;
620 // windows previous events happened in
621 Window event_win, drag_win;
622 Visual *vis;
623 Colormap cmap;
624 Display* display;
625 Window win;
626 Pixmap pixmap;
627 #ifdef HAVE_GL
628 GLXContext gl_context;
629 #endif
630 static Mutex opengl_lock;
631 int window_lock;
632 GC gc;
633 // Depth given by the X Server
634 int default_depth;
635 Atom DelWinXAtom;
636 Atom ProtoXAtom;
637 Atom RepeaterXAtom;
638 Atom SetDoneXAtom;
639 XFontStruct *largefont, *mediumfont, *smallfont;
640 int current_cursor;
641 Cursor arrow_cursor;
642 Cursor cross_cursor;
643 Cursor ibeam_cursor;
644 Cursor vseparate_cursor;
645 Cursor hseparate_cursor;
646 Cursor move_cursor;
647 Cursor temp_cursor;
648 Cursor left_cursor;
649 Cursor right_cursor;
650 Cursor upright_arrow_cursor;
651 Cursor upleft_resize_cursor;
652 Cursor upright_resize_cursor;
653 Cursor downleft_resize_cursor;
654 Cursor downright_resize_cursor;
656 int xvideo_port_id;
657 ArrayList<BC_ResizeCall*> resize_history;
658 // Background tile if tiled
659 BC_Pixmap *bg_pixmap;
660 // Icon
661 BC_Popup *icon_window;
662 BC_Pixmap *icon_pixmap;
663 // Temporary
664 BC_Bitmap *temp_bitmap;
665 // Clipboard
666 BC_Clipboard *clipboard;
668 // Cancel button, to be called on close window, if != NULL
669 BC_CancelButton *cancel_button;
671 #ifdef HAVE_LIBXXF86VM
672 // Mode switch information.
673 int vm_switched;
674 XF86VidModeModeInfo orig_modeline;
675 #endif
680 #endif