r499: This commit was manufactured by cvs2svn to create tag 'r1_2_1-last'.
[cinelerra_cv/mob.git] / hvirtual / guicast / bcwindowbase.h
blobcd6e7ff1fc1b59e89b3edfd61d583f19e318ff82
1 #ifndef BCWINDOWBASE_H
2 #define BCWINDOWBASE_H
4 // Window types
6 #define MAIN_WINDOW 0
7 #define SUB_WINDOW 1
8 #define POPUP_WINDOW 2
9 #ifdef HAVE_LIBXXF86VM
10 #define VIDMODE_SCALED_WINDOW 3
11 #endif
13 #define TOOLTIP_MARGIN 2
14 #define BC_INFINITY 65536
16 #include "bcfilebox.inc"
17 #include "arraylist.h"
18 #include "bcbitmap.inc"
19 #include "bcbutton.inc"
20 #include "bccapture.inc"
21 #include "bcdragwindow.inc"
22 #include "bcclipboard.inc"
23 #include "bclistbox.inc"
24 #include "bcmenubar.inc"
25 #include "bcmeter.inc"
26 #include "bcpan.inc"
27 #include "bcpixmap.inc"
28 #include "bcpopup.inc"
29 #include "bcpopupmenu.inc"
30 #include "bcpot.inc"
31 #include "bcprogress.inc"
32 #include "bcrepeater.inc"
33 #include "bcresources.inc"
34 #include "bcscrollbar.inc"
35 #include "bcslider.inc"
36 #include "bcsubwindow.inc"
37 #include "bctextbox.inc"
38 #include "bctitle.inc"
39 #include "bctoggle.inc"
40 #include "bctumble.inc"
41 #include "bcwindow.inc"
42 #include "bcwindowbase.inc"
43 #include "bcwindowevents.inc"
44 #include "condition.inc"
45 #include "defaults.inc"
46 #include "linklist.h"
47 #include "mutex.h"
48 #include "vframe.inc"
51 #include <stdint.h>
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <X11/Xatom.h>
55 #ifdef HAVE_XFT
56 #include <X11/Xft/Xft.h>
57 #endif
58 #include <X11/Xlib.h>
59 #include <X11/Xutil.h>
60 #include <X11/keysym.h>
61 #include <X11/cursorfont.h>
62 #ifdef HAVE_LIBXXF86VM
63 #include <X11/extensions/xf86vmode.h>
64 #endif
69 #ifdef HAVE_GL
70 typedef void* GLXContext;
71 #endif
73 class BC_ResizeCall
75 public:
76 BC_ResizeCall(int w, int h);
77 int w, h;
81 // Windows, subwindows, popupwindows inherit from this
82 class BC_WindowBase
84 public:
85 BC_WindowBase();
86 virtual ~BC_WindowBase();
88 friend class BC_Bitmap;
89 friend class BC_Button;
90 friend class BC_GenericButton;
91 friend class BC_Capture;
92 friend class BC_Clipboard;
93 friend class BC_DragWindow;
94 friend class BC_FileBox;
95 friend class BC_FullScreen;
96 friend class BC_ListBox;
97 friend class BC_Menu;
98 friend class BC_MenuBar;
99 friend class BC_MenuItem;
100 friend class BC_MenuPopup;
101 friend class BC_Meter;
102 friend class BC_Pan;
103 friend class BC_Pixmap;
104 friend class BC_Popup;
105 friend class BC_PopupMenu;
106 friend class BC_Pot;
107 friend class BC_ProgressBar;
108 friend class BC_Repeater;
109 friend class BC_Resources;
110 friend class BC_ScrollBar;
111 friend class BC_Slider;
112 friend class BC_SubWindow;
113 friend class BC_TextBox;
114 friend class BC_Title;
115 friend class BC_Toggle;
116 friend class BC_Tumbler;
117 friend class BC_Window;
118 friend class BC_WindowEvents;
120 // Main loop
121 int run_window();
122 // Terminal event dispatchers
123 virtual int close_event();
124 virtual int resize_event(int w, int h);
125 virtual int repeat_event(int64_t duration) { return 0; };
126 virtual int focus_in_event() { return 0; };
127 virtual int focus_out_event() { return 0; };
128 virtual int button_press_event() { return 0; };
129 virtual int button_release_event() { return 0; };
130 virtual int cursor_motion_event() { return 0; };
131 virtual int cursor_leave_event();
132 virtual int cursor_enter_event();
133 virtual int keypress_event() { return 0; };
134 virtual int translation_event() { return 0; };
135 virtual int drag_start_event() { return 0; };
136 virtual int drag_motion_event() { return 0; };
137 virtual int drag_stop_event() { return 0; };
138 virtual int uses_text() { return 0; };
139 // Only if opengl is enabled
140 virtual int expose_event() { return 0; };
142 // Check if a hardware accelerated colormodel is available and reserve it
143 int accel_available(int color_model);
144 // Get color model adjusted for byte order and pixel size
145 int get_color_model();
146 // return the colormap pixel of the color for all bit depths
147 int get_color(int64_t color);
148 // return the currently selected color
149 int64_t get_color();
150 int show_window(int flush = 1);
151 int hide_window(int flush = 1);
152 int get_hidden();
153 void enable_opengl();
154 void disable_opengl();
155 void lock_opengl();
156 void unlock_opengl();
157 void flip_opengl();
159 int flash(int x, int y, int w, int h, int flush = 1);
160 int flash(int flush = 1);
161 void flush();
162 void sync_display();
163 // Lock out other threads
164 int lock_window(char *location = 0);
165 int unlock_window();
166 int get_window_lock();
168 BC_MenuBar* add_menubar(BC_MenuBar *menu_bar);
169 BC_WindowBase* add_subwindow(BC_WindowBase *subwindow);
170 BC_WindowBase* add_tool(BC_WindowBase *subwindow);
172 static BC_Resources* get_resources();
173 // Dimensions
174 virtual int get_w();
175 virtual int get_h();
176 virtual int get_x();
177 virtual int get_y();
178 int get_root_w(int ignore_dualhead = 0, int lock_display = 0);
179 int get_root_h(int lock_display);
180 // Get current position
181 int get_abs_cursor_x(int lock_window);
182 int get_abs_cursor_y(int lock_window);
183 int get_relative_cursor_x();
184 int get_relative_cursor_y();
185 // Return 1 if cursor is over an unobscured part of this window.
186 // An argument is provided for excluding a drag popup
187 int get_cursor_over_window();
188 // For traversing windows... return 1 if this or any subwindow is win
189 int match_window(Window win);
191 int get_button_down();
192 int get_buttonpress();
193 int get_has_focus();
194 int get_dragging();
195 int get_keypress();
196 // Get cursor position of last event
197 int get_cursor_x();
198 int get_cursor_y();
199 // Cursor position of drag start
200 int get_drag_x();
201 int get_drag_y();
202 int relative_cursor_x(BC_WindowBase *pov);
203 int relative_cursor_y(BC_WindowBase *pov);
204 int alt_down();
205 int shift_down();
206 int ctrl_down();
207 int get_double_click();
208 // Bottom right corner
209 int get_x2();
210 int get_y2();
211 int get_bg_color();
212 BC_Pixmap* get_bg_pixmap();
213 int get_text_ascent(int font);
214 int get_text_descent(int font);
215 int get_text_height(int font, char *text = 0);
216 int get_text_width(int font, char *text, int length = -1);
217 BC_Clipboard* get_clipboard();
218 void set_dragging(int value);
219 int set_w(int w);
220 int set_h(int h);
221 BC_WindowBase* get_top_level();
222 BC_WindowBase* get_parent();
223 // Event happened in this window
224 int is_event_win();
225 int cursor_inside();
226 // Deactivate everything and activate this subwindow
227 virtual int activate();
228 // Deactivate this subwindow
229 virtual int deactivate();
230 void set_active_subwindow(BC_WindowBase *subwindow);
231 // Get value of toggle value when dragging a selection
232 int get_toggle_value();
233 // Get if toggle is being dragged
234 int get_toggle_drag();
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 // Change the window title. The title is translated internally.
356 void set_title(char *text);
357 char* get_title();
358 void start_video();
359 void stop_video();
360 int video_is_on();
361 void set_done(int return_value);
362 // Get a bitmap to draw on the window with
363 BC_Bitmap* new_bitmap(int w, int h, int color_model = -1);
364 // Draw a bitmap on the window
365 void draw_bitmap(BC_Bitmap *bitmap,
366 int dont_wait,
367 int dest_x = 0,
368 int dest_y = 0,
369 int dest_w = 0,
370 int dest_h = 0,
371 int src_x = 0,
372 int src_y = 0,
373 int src_w = 0,
374 int src_h = 0,
375 BC_Pixmap *pixmap = 0);
376 void draw_pixel(int x, int y, BC_Pixmap *pixmap = 0);
377 // Draw a pixmap on the window
378 void draw_pixmap(BC_Pixmap *pixmap,
379 int dest_x = 0,
380 int dest_y = 0,
381 int dest_w = -1,
382 int dest_h = -1,
383 int src_x = 0,
384 int src_y = 0,
385 BC_Pixmap *dst = 0);
386 // Draw a vframe on the window
387 void draw_vframe(VFrame *frame,
388 int dest_x = 0,
389 int dest_y = 0,
390 int dest_w = -1,
391 int dest_h = -1,
392 int src_x = 0,
393 int src_y = 0,
394 int src_w = 0,
395 int src_h = 0,
396 BC_Pixmap *pixmap = 0);
397 void draw_border(char *text, int x, int y, int w, int h);
398 // Draw a region of the background
399 void draw_top_background(BC_WindowBase *parent_window, int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
400 void draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h);
401 void draw_background(int x, int y, int w, int h);
402 void draw_tiles(BC_Pixmap *tile,
403 int origin_x,
404 int origin_y,
405 int x,
406 int y,
407 int w,
408 int h);
409 void slide_left(int distance);
410 void slide_right(int distance);
411 void slide_up(int distance);
412 void slide_down(int distance);
414 int cycle_textboxes(int amount);
416 int raise_window(int do_flush = 1);
417 int set_tooltips(int tooltips_enabled);
418 int resize_window(int w, int h);
419 int reposition_window(int x, int y, int w = -1, int h = -1);
420 // Cause a repeat event to be dispatched every duration.
421 // duration is milliseconds
422 int set_repeat(int64_t duration);
423 // Stop a repeat event from being dispatched.
424 int unset_repeat(int64_t duration);
425 int set_tooltip(char *text);
426 int show_tooltip(int w = -1, int h = -1);
427 int hide_tooltip();
428 int set_icon(VFrame *data);
429 int load_defaults(Defaults *defaults);
430 int save_defaults(Defaults *defaults);
432 #ifdef HAVE_LIBXXF86VM
433 // Mode switch methods.
434 void closest_vm(int *vm, int *width, int *height);
435 void scale_vm(int vm);
436 void restore_vm();
437 #endif
442 private:
443 // Create a window
444 virtual int create_window(BC_WindowBase *parent_window,
445 char *title,
446 int x,
447 int y,
448 int w,
449 int h,
450 int minw,
451 int minh,
452 int allow_resize,
453 int private_color,
454 int hide,
455 int bg_color,
456 char *display_name,
457 int window_type,
458 BC_Pixmap *bg_pixmap,
459 int group_it);
461 static Display* init_display(char *display_name);
462 virtual int initialize();
463 int get_atoms();
464 void init_cursors();
465 int init_colors();
466 int init_window_shape();
467 static int evaluate_color_model(int client_byte_order, int server_byte_order, int depth);
468 int create_private_colors();
469 int create_color(int color);
470 int create_shared_colors();
471 // Get width of a single line. Used by get_text_width
472 int get_single_text_width(int font, char *text, int length);
473 int allocate_color_table();
474 int init_gc();
475 int init_fonts();
476 int get_color_rgb8(int color);
477 int64_t get_color_rgb16(int color);
478 int64_t get_color_bgr16(int color);
479 int64_t get_color_bgr24(int color);
480 XFontStruct* get_font_struct(int font);
481 #ifdef HAVE_XFT
482 XftFont* get_xft_struct(int font);
483 #endif
484 Cursor get_cursor_struct(int cursor);
485 XFontSet get_fontset(int font);
486 XFontSet get_curr_fontset(void);
487 void set_fontset(int font);
488 int dispatch_event();
490 int get_key_masks(XEvent *event);
492 int trigger_tooltip();
493 int untrigger_tooltip();
494 void draw_tooltip();
495 int arm_repeat(int64_t duration);
496 // delete all repeater opjects for a close
497 int unset_all_repeaters();
499 // Block and get event from common events.
500 XEvent* get_event();
501 // Return number of events in table.
502 int get_event_count();
503 // Put event in common events.
504 void put_event(XEvent *event);
506 // Recursive event dispatchers
507 int dispatch_resize_event(int w, int h);
508 int dispatch_focus_in();
509 int dispatch_focus_out();
510 int dispatch_motion_event();
511 int dispatch_keypress_event();
512 int dispatch_repeat_event(int64_t duration);
513 int dispatch_repeat_event_master(int64_t duration);
514 int dispatch_button_press();
515 int dispatch_button_release();
516 int dispatch_cursor_leave();
517 int dispatch_cursor_enter();
518 int dispatch_translation_event();
519 int dispatch_drag_start();
520 int dispatch_drag_motion();
521 int dispatch_drag_stop();
522 int dispatch_expose_event();
524 // Get the port ID for a color model or return -1 for failure
525 int grab_port_id(BC_WindowBase *window, int color_model);
527 int find_next_textbox(BC_WindowBase **first_textbox, BC_WindowBase **next_textbox, int &result);
528 int find_prev_textbox(BC_WindowBase **last_textbox, BC_WindowBase **prev_textbox, int &result);
532 void translate_coordinates(Window src_w,
533 Window dest_w,
534 int src_x,
535 int src_y,
536 int *dest_x_return,
537 int *dest_y_return);
539 // Top level window above this window
540 BC_WindowBase* top_level;
541 // Window just above this window
542 BC_WindowBase* parent_window;
543 // list of window bases in this window
544 BC_SubWindowList* subwindows;
545 // Position of window
546 int x, y, w, h;
547 // Default colors
548 int light1, light2, medium, dark1, dark2, bg_color;
549 // Type of window defined above
550 int window_type;
551 // Pointer to the active menubar in the window.
552 BC_MenuBar* active_menubar;
553 // pointer to the active popup menu in the window
554 BC_PopupMenu* active_popup_menu;
555 // pointer to the active subwindow
556 BC_WindowBase* active_subwindow;
558 // Window parameters
559 int allow_resize;
560 int hidden, private_color, bits_per_pixel, color_model;
561 int server_byte_order, client_byte_order;
562 // number of colors in color table
563 int total_colors;
564 // last color found in table
565 int current_color_value, current_color_pixel;
566 // table for every color allocated
567 int color_table[256][2];
568 // Turn on optimization
569 int video_on;
570 // Event handler completion
571 int done;
572 // Return value of event handler
573 int return_value;
574 // Motion event compression
575 int motion_events, last_motion_x, last_motion_y;
576 // window of buffered motion
577 Window last_motion_win;
578 // Resize event compression
579 int resize_events, last_resize_w, last_resize_h;
580 int translation_events, last_translate_x, last_translate_y;
581 int prev_x, prev_y;
582 // Since the window manager automatically translates the window at boot,
583 // use the first translation event to get correction factors
584 int translation_count;
585 int x_correction, y_correction;
586 // Key masks
587 int ctrl_mask, shift_mask, alt_mask;
588 // Cursor motion information
589 int cursor_x, cursor_y;
590 // Button status information
591 int button_down, button_number;
592 // When button was pressed and whether it qualifies as a double click
593 uint64_t button_time1, button_time2;
594 int double_click;
595 // Which button is down
596 int button_pressed;
597 // Last key pressed
598 int key_pressed;
599 // During a selection drag involving toggles, set the same value for each toggle
600 int toggle_value;
601 int toggle_drag;
602 // Whether the window has the focus
603 int has_focus;
605 static BC_Resources resources;
606 // Array of repeaters for multiple repeating objects.
607 ArrayList<BC_Repeater*> repeaters;
608 // int64_t next_repeat_id;
609 // Text for tooltip if one exists
610 char tooltip_text[BCTEXTLEN];
611 // If the current window's tooltip is visible
612 int tooltip_on;
613 // Repeat ID of tooltip
614 // int64_t tooltip_id;
615 // Popup window for tooltip
616 BC_Popup *tooltip_popup;
617 // If this subwindow has already shown a tooltip since the last EnterNotify
618 int tooltip_done;
619 // If the tooltip shouldn't be hidden
620 int persistant_tooltip;
624 // Font sets
625 XFontSet largefontset, mediumfontset, smallfontset, curr_fontset;
627 // Fonts
628 int current_font;
629 XFontStruct *largefont, *mediumfont, *smallfont;
631 // Xft
632 // XftDraw *xft_drawable;
633 // XftFont *largefont_xft, *mediumfont_xft, *smallfont_xft;
634 // Must be void so users don't need to include the wrong libpng version.
635 void *xft_drawable;
636 void *largefont_xft, *mediumfont_xft, *smallfont_xft;
639 int64_t current_color;
640 // Coordinate of drag start
641 int drag_x, drag_y;
642 // Boundaries the cursor must pass to start a drag
643 int drag_x1, drag_x2, drag_y1, drag_y2;
644 // Dragging is specific to the subwindow
645 int is_dragging;
646 // Don't delete the background pixmap
647 int shared_bg_pixmap;
648 char title[BCTEXTLEN];
650 // X Window parameters
651 int screen;
652 Window rootwin;
653 // windows previous events happened in
654 Window event_win, drag_win;
655 Visual *vis;
656 Colormap cmap;
657 // Display for all synchronous operations
658 Display *display;
659 // Display to send events on
660 Display *event_display;
661 Window win;
662 Pixmap pixmap;
663 #ifdef HAVE_GL
664 GLXContext gl_context;
665 #endif
666 static Mutex opengl_lock;
667 int window_lock;
668 GC gc;
669 // Depth given by the X Server
670 int default_depth;
671 Atom DelWinXAtom;
672 Atom ProtoXAtom;
673 Atom RepeaterXAtom;
674 Atom SetDoneXAtom;
675 int current_cursor;
676 Cursor arrow_cursor;
677 Cursor cross_cursor;
678 Cursor ibeam_cursor;
679 Cursor vseparate_cursor;
680 Cursor hseparate_cursor;
681 Cursor move_cursor;
682 Cursor temp_cursor;
683 Cursor left_cursor;
684 Cursor right_cursor;
685 Cursor upright_arrow_cursor;
686 Cursor upleft_resize_cursor;
687 Cursor upright_resize_cursor;
688 Cursor downleft_resize_cursor;
689 Cursor downright_resize_cursor;
691 int xvideo_port_id;
692 ArrayList<BC_ResizeCall*> resize_history;
693 // Background tile if tiled
694 BC_Pixmap *bg_pixmap;
695 // Icon
696 BC_Popup *icon_window;
697 BC_Pixmap *icon_pixmap;
698 // Temporary
699 BC_Bitmap *temp_bitmap;
700 // Clipboard
701 BC_Clipboard *clipboard;
702 #ifdef HAVE_LIBXXF86VM
703 // Mode switch information.
704 int vm_switched;
705 XF86VidModeModeInfo orig_modeline;
706 #endif
708 // Common events coming from X server and repeater.
709 ArrayList<XEvent*> common_events;
710 // Locks for common events
711 // Locking order:
712 // 1) event_condition
713 // 2) event_lock
714 Mutex *event_lock;
715 Condition *event_condition;
716 BC_WindowEvents *event_thread;
721 #endif