4 #if defined(HAVE_CONFIG_H)
12 #define POPUP_WINDOW 2
13 #ifdef HAVE_LIBXXF86VM
14 #define VIDMODE_SCALED_WINDOW 3
17 #define TOOLTIP_MARGIN 2
18 #define BC_INFINITY 65536
20 #include "arraylist.h"
22 #include "bcbitmap.inc"
23 #include "bcbutton.inc"
24 #include "bccapture.inc"
25 #include "bcclipboard.inc"
26 #include "bcdragwindow.inc"
27 #include "bcfilebox.inc"
28 #include "bclistbox.inc"
29 #include "bcmenubar.inc"
30 #include "bcmeter.inc"
32 #include "bcpbuffer.inc"
33 #include "bcpixmap.inc"
34 #include "bcpopup.inc"
35 #include "bcpopupmenu.inc"
37 #include "bcprogress.inc"
38 #include "bcrelocatablewidget.h"
39 #include "bcrepeater.inc"
40 #include "bcresources.inc"
41 #include "bcscrollbar.inc"
42 #include "bcslider.inc"
43 #include "bcsubwindow.inc"
44 #include "bcsynchronous.inc"
45 #include "bctextbox.inc"
46 #include "bctimer.inc"
47 #include "bctitle.inc"
48 #include "bctoggle.inc"
49 #include "bctumble.inc"
50 #include "bcwidgetgrid.inc"
51 #include "bcwindow.inc"
52 #include "bcwindowbase.inc"
53 #include "bcwindowevents.inc"
54 #include "condition.inc"
64 #include <X11/Xatom.h>
66 #include <X11/Xft/Xft.h>
69 #include <X11/Xutil.h>
70 #include <X11/keysym.h>
71 #include <X11/cursorfont.h>
72 #ifdef HAVE_LIBXXF86VM
73 #include <X11/extensions/xf86vmode.h>
82 //typedef void* GLXContext;
86 // Struct for async event marshalling, the same as XClientMessageEvent currently, but can be changed if we change toolkit ever
87 // it is defined here so we don't use X headers in /cinelerra
89 int type
; /* ClientMessage */
90 unsigned long serial
; /* # of last request processed by server */
91 Bool send_event
; /* true if this came from a SendEvent request */
92 Display
*display
; /* Display the event was read from */
107 BC_ResizeCall(int w
, int h
);
112 // Windows, subwindows, popupwindows inherit from this
113 class BC_WindowBase
: public BC_RelocatableWidget
117 virtual ~BC_WindowBase();
120 friend class BC_Bitmap
;
121 friend class BC_Button
;
122 friend class BC_GenericButton
;
123 friend class BC_Capture
;
124 friend class BC_Clipboard
;
125 friend class BC_DragWindow
;
126 friend class BC_FileBox
;
127 friend class BC_FullScreen
;
128 friend class BC_ListBox
;
129 friend class BC_Menu
;
130 friend class BC_MenuBar
;
131 friend class BC_MenuItem
;
132 friend class BC_MenuPopup
;
133 friend class BC_Meter
;
135 friend class BC_PBuffer
;
136 friend class BC_Pixmap
;
137 friend class BC_PixmapSW
;
138 friend class BC_Popup
;
139 friend class BC_PopupMenu
;
141 friend class BC_ProgressBar
;
142 friend class BC_Repeater
;
143 friend class BC_Resources
;
144 friend class BC_ScrollBar
;
145 friend class BC_Slider
;
146 friend class BC_SubWindow
;
147 friend class BC_Synchronous
;
148 friend class BC_TextBox
;
149 friend class BC_Title
;
150 friend class BC_Toggle
;
151 friend class BC_Tumbler
;
152 friend class BC_Window
;
153 friend class BC_WindowEvents
;
157 // Terminal event dispatchers
158 virtual int close_event();
159 virtual int resize_event(int w
, int h
);
160 virtual int repeat_event(int64_t duration
) { return 0; };
161 virtual int focus_in_event() { return 0; };
162 virtual int focus_out_event() { return 0; };
163 virtual int button_press_event() { return 0; };
164 virtual int button_release_event() { return 0; };
165 virtual int cursor_motion_event() { return 0; };
166 virtual int cursor_leave_event();
167 virtual int cursor_enter_event();
168 virtual int keypress_event() { return 0; };
169 virtual int translation_event() { return 0; };
170 virtual int drag_start_event() { return 0; };
171 virtual int drag_motion_event() { return 0; };
172 virtual int drag_stop_event() { return 0; };
173 virtual int uses_text() { return 0; };
174 // Only if opengl is enabled
175 virtual int expose_event() { return 0; };
177 // Check if a hardware accelerated colormodel is available and reserve it
178 int accel_available(int color_model
, int lock_it
);
179 // Get color model adjusted for byte order and pixel size
180 int get_color_model();
181 // return the colormap pixel of the color for all bit depths
182 int get_color(int64_t color
);
183 // return the currently selected color
185 int show_window(int flush
= 1);
186 int hide_window(int flush
= 1);
189 // Shouldn't deference a pointer to delete a window if a parent is
190 // currently being deleted. This returns 1 if any parent is being deleted.
195 //============================= OpenGL functions ===============================
196 // OpenGL functions must be called from inside a BC_Synchronous command.
197 // Create openGL context and bind it to the current window.
198 // If it's called inside start_video/stop_video, the context is bound to the window.
199 // If it's called outside start_video/stop_video, the context is bound to the pixmap.
200 // Must be called at the beginning of any opengl routine to make sure
201 // the context is current.
202 // No locking is performed.
203 void enable_opengl();
204 void disable_opengl();
207 // Calls the BC_Synchronous version of the function with the window_id.
208 // Not run in OpenGL thread because it has its own lock.
209 unsigned int get_shader(char *title
, int *got_it
);
210 void put_shader(unsigned int handle
, char *title
);
213 int flash(int x
, int y
, int w
, int h
, int flush
= 1);
214 int flash(int flush
= 1);
217 // Lock out other threads
218 int lock_window(char *location
= 0);
220 int get_window_lock();
222 BC_MenuBar
* add_menubar(BC_MenuBar
*menu_bar
);
223 BC_WindowBase
* add_subwindow(BC_WindowBase
*subwindow
);
224 BC_WindowBase
* add_tool(BC_WindowBase
*subwindow
);
225 BC_WidgetGrid
* add_widgetgrid(BC_WidgetGrid
*widgetgrid
);
228 static BC_Resources
* get_resources();
229 // User must create synchronous object first
230 static BC_Synchronous
* get_synchronous();
237 virtual int reposition_widgets(){ printf("foo1"); return 0; }
238 int get_root_w(int ignore_dualhead
= 0, int lock_display
= 0);
239 int get_root_h(int lock_display
);
240 // Get current position
241 int get_abs_cursor_x(int lock_window
);
242 int get_abs_cursor_y(int lock_window
);
243 int get_relative_cursor_x();
244 int get_relative_cursor_y();
245 // Return 1 if cursor is over an unobscured part of this window.
246 // An argument is provided for excluding a drag popup
247 int get_cursor_over_window();
248 // For traversing windows... return 1 if this or any subwindow is win
249 int match_window(Window win
);
251 // 1 or 0 if a button is down
252 int get_button_down();
253 // Number of button pressed 1 - 5
254 int get_buttonpress();
258 // Get cursor position of last event
261 // Cursor position of drag start
264 int relative_cursor_x(BC_WindowBase
*pov
);
265 int relative_cursor_y(BC_WindowBase
*pov
);
269 int get_double_click();
270 // Bottom right corner
274 BC_Pixmap
* get_bg_pixmap();
275 int get_text_ascent(int font
);
276 int get_text_descent(int font
);
277 int get_text_height(int font
, char *text
= 0);
278 int get_text_width(int font
, char *text
, int length
= -1);
279 BC_Clipboard
* get_clipboard();
280 void set_dragging(int value
);
283 BC_WindowBase
* get_top_level();
284 BC_WindowBase
* get_parent();
285 // Event happened in this window
288 // Deactivate everything and activate this subwindow
289 virtual int activate();
290 // Deactivate this subwindow
291 virtual int deactivate();
292 void set_active_subwindow(BC_WindowBase
*subwindow
);
293 // Get value of toggle value when dragging a selection
294 int get_toggle_value();
295 // Get if toggle is being dragged
296 int get_toggle_drag();
298 // Set the gc to the color
299 void set_color(int64_t color
);
301 void set_font(int font
);
302 // Set the cursor to a macro from cursors.h
303 // Set override if the caller is enabling hourglass or hiding the cursor
304 void set_cursor(int cursor
, int override
= 0);
305 // Set the cursor to a character in the X cursor library. Used by test.C
306 void set_x_cursor(int cursor
);
308 // Shows the cursor after it's hidden by video playback
309 void unhide_cursor();
310 // Called by video updating routines to hide the cursor after a timeout
311 void update_video_cursor();
313 // Entry point for starting hourglass.
314 // Converts all cursors and saves the previous cursor.
315 void start_hourglass();
316 void stop_hourglass();
318 // Recursive part of hourglass commands.
319 void start_hourglass_recursive();
320 void stop_hourglass_recursive();
323 void copy_area(int x1
, int y1
, int x2
, int y2
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
324 void clear_box(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
325 void draw_box(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
326 void draw_circle(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
327 void draw_disc(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
328 void draw_text(int x
, int y
, char *text
, int length
= -1, BC_Pixmap
*pixmap
= 0);
329 void draw_xft_text(int x
,
339 void draw_center_text(int x
, int y
, char *text
, int length
= -1);
340 void draw_line(int x1
, int y1
, int x2
, int y2
, BC_Pixmap
*pixmap
= 0);
341 void draw_polygon(ArrayList
<int> *x
, ArrayList
<int> *y
, BC_Pixmap
*pixmap
= 0);
342 void draw_rectangle(int x
, int y
, int w
, int h
);
343 void draw_3segment(int x
,
347 BC_Pixmap
*left_image
,
348 BC_Pixmap
*mid_image
,
349 BC_Pixmap
*right_image
,
350 BC_Pixmap
*pixmap
= 0);
351 void draw_3segment(int x
,
358 BC_Pixmap
*pixmap
= 0);
359 // For drawing a changing level
360 void draw_3segmenth(int x
,
367 void draw_3segmenth(int x
,
374 void draw_3segmentv(int x
,
381 void draw_3segmentv(int x
,
388 // For drawing a single level
389 void draw_3segmenth(int x
,
393 BC_Pixmap
*pixmap
= 0);
394 void draw_3segmenth(int x
,
399 void draw_3segmentv(int x
,
404 void draw_3segmentv(int x
,
409 void draw_9segment(int x
,
415 void draw_9segment(int x
,
421 void draw_3d_box(int x
,
430 BC_Pixmap
*pixmap
= 0);
431 void draw_3d_border(int x
, int y
, int w
, int h
,
432 int light1
, int light2
, int shadow1
, int shadow2
);
433 void draw_colored_box(int x
, int y
, int w
, int h
, int down
, int highlighted
);
434 void draw_check(int x
, int y
);
435 void draw_triangle_down_flat(int x
, int y
, int w
, int h
);
436 void draw_triangle_up(int x
, int y
, int w
, int h
,
437 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
438 void draw_triangle_down(int x
, int y
, int w
, int h
,
439 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
440 void draw_triangle_left(int x
, int y
, int w
, int h
,
441 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
442 void draw_triangle_right(int x
, int y
, int w
, int h
,
443 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
444 // Set the gc to opaque
447 void set_background(VFrame
*bitmap
);
448 // Change the window title. The title is translated internally.
449 void set_title(char *text
);
454 void set_done(int return_value
);
455 // Get a bitmap to draw on the window with
456 BC_Bitmap
* new_bitmap(int w
, int h
, int color_model
= -1);
457 // Draw a bitmap on the window
458 void draw_bitmap(BC_Bitmap
*bitmap
,
468 BC_Pixmap
*pixmap
= 0);
469 void draw_pixel(int x
, int y
, BC_Pixmap
*pixmap
= 0);
470 // Draw a pixmap on the window
471 void draw_pixmap(BC_Pixmap
*pixmap
,
479 // Draw a vframe on the window
480 void draw_vframe(VFrame
*frame
,
489 BC_Pixmap
*pixmap
= 0);
490 void draw_border(char *text
, int x
, int y
, int w
, int h
);
491 // Draw a region of the background
492 void draw_top_background(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
493 void draw_top_tiles(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
);
494 void draw_background(int x
, int y
, int w
, int h
);
495 void draw_tiles(BC_Pixmap
*tile
,
502 void slide_left(int distance
);
503 void slide_right(int distance
);
504 void slide_up(int distance
);
505 void slide_down(int distance
);
507 int cycle_textboxes(int amount
);
509 int raise_window(int do_flush
= 1);
510 int set_tooltips(int tooltips_enabled
);
511 int resize_window(int w
, int h
);
512 int reposition_widget(int x
, int y
, int w
= -1, int h
= -1);
513 int reposition_window(int x
, int y
, int w
= -1, int h
= -1);
514 // Cause a repeat event to be dispatched every duration.
515 // duration is milliseconds
516 int set_repeat(int64_t duration
);
517 // Stop a repeat event from being dispatched.
518 int unset_repeat(int64_t duration
);
519 int set_tooltip(char *text
);
520 int show_tooltip(int w
= -1, int h
= -1);
522 int set_icon(VFrame
*data
);
523 int load_defaults(BC_Hash
*defaults
);
524 int save_defaults(BC_Hash
*defaults
);
526 #ifdef HAVE_LIBXXF86VM
527 // Mode switch methods.
528 void closest_vm(int *vm
, int *width
, int *height
);
529 void scale_vm(int vm
);
539 virtual int create_window(BC_WindowBase
*parent_window
,
553 BC_Pixmap
*bg_pixmap
,
556 static Display
* init_display(char *display_name
);
557 // Get display from top level
558 Display
* get_display();
560 virtual int initialize();
562 // Function to overload to recieve customly defined atoms
563 virtual int recieve_custom_xatoms(xatom_event
*event
);
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 // Get width of a single line. Used by get_text_width
573 int get_single_text_width(int font
, char *text
, int length
);
574 int allocate_color_table();
578 int get_color_rgb8(int color
);
579 int64_t get_color_rgb16(int color
);
580 int64_t get_color_bgr16(int color
);
581 int64_t get_color_bgr24(int color
);
582 XFontStruct
* get_font_struct(int font
);
584 XftFont
* get_xft_struct(int font
);
586 Cursor
get_cursor_struct(int cursor
);
587 XFontSet
get_fontset(int font
);
588 XFontSet
get_curr_fontset(void);
589 void set_fontset(int font
);
590 int dispatch_event();
592 int get_key_masks(XEvent
*event
);
594 int trigger_tooltip();
595 int untrigger_tooltip();
597 int arm_repeat(int64_t duration
);
598 // delete all repeater opjects for a close
599 int unset_all_repeaters();
601 // Block and get event from common events.
603 // Return number of events in table.
604 int get_event_count();
605 // Put event in common events.
606 void put_event(XEvent
*event
);
608 // Recursive event dispatchers
609 int dispatch_resize_event(int w
, int h
);
610 int dispatch_focus_in();
611 int dispatch_focus_out();
612 int dispatch_motion_event();
613 int dispatch_keypress_event();
614 int dispatch_repeat_event(int64_t duration
);
615 int dispatch_repeat_event_master(int64_t duration
);
616 int dispatch_button_press();
617 int dispatch_button_release();
618 int dispatch_cursor_leave();
619 int dispatch_cursor_enter();
620 int dispatch_translation_event();
621 int dispatch_drag_start();
622 int dispatch_drag_motion();
623 int dispatch_drag_stop();
624 int dispatch_expose_event();
626 // Get the port ID for a color model or return -1 for failure
627 int grab_port_id(BC_WindowBase
*window
, int color_model
);
629 int find_next_textbox(BC_WindowBase
**first_textbox
, BC_WindowBase
**next_textbox
, int &result
);
630 int find_prev_textbox(BC_WindowBase
**last_textbox
, BC_WindowBase
**prev_textbox
, int &result
);
633 void translate_coordinates(Window src_w
,
640 // Top level window above this window
641 BC_WindowBase
* top_level
;
642 // Window just above this window
643 BC_WindowBase
* parent_window
;
644 // list of window bases in this window
645 BC_SubWindowList
* subwindows
;
646 // list of window bases in this window
647 BC_WidgetGridList
* widgetgrids
;
648 // Position of window
651 int light1
, light2
, medium
, dark1
, dark2
, bg_color
;
652 // Type of window defined above
654 // Pointer to the active menubar in the window.
655 BC_MenuBar
* active_menubar
;
656 // pointer to the active popup menu in the window
657 BC_PopupMenu
* active_popup_menu
;
658 // pointer to the active subwindow
659 BC_WindowBase
* active_subwindow
;
663 int hidden
, private_color
, bits_per_pixel
, color_model
;
664 int server_byte_order
, client_byte_order
;
665 // number of colors in color table
667 // last color found in table
668 int current_color_value
, current_color_pixel
;
669 // table for every color allocated
670 int color_table
[256][2];
671 // Turn on optimization
673 // Event handler completion
675 // Return value of event handler
677 // Motion event compression
678 int motion_events
, last_motion_x
, last_motion_y
;
679 // window of buffered motion
680 Window last_motion_win
;
681 // Resize event compression
682 int resize_events
, last_resize_w
, last_resize_h
;
683 int translation_events
, last_translate_x
, last_translate_y
;
685 // Since the window manager automatically translates the window at boot,
686 // use the first translation event to get correction factors
687 int translation_count
;
688 int x_correction
, y_correction
;
690 int ctrl_mask
, shift_mask
, alt_mask
;
691 // Cursor motion information
692 int cursor_x
, cursor_y
;
693 // Button status information
694 int button_down
, button_number
;
695 // When button was pressed and whether it qualifies as a double click
696 uint64_t button_time1
, button_time2
;
698 // Which button is down. 1, 2, 3, 4, 5
702 // During a selection drag involving toggles, set the same value for each toggle
705 // Whether the window has the focus
708 static BC_Resources resources
;
709 // Array of repeaters for multiple repeating objects.
710 ArrayList
<BC_Repeater
*> repeaters
;
711 // int64_t next_repeat_id;
712 // Text for tooltip if one exists
713 char tooltip_text
[BCTEXTLEN
];
714 // If the current window's tooltip is visible
716 // Repeat ID of tooltip
717 // int64_t tooltip_id;
718 // Popup window for tooltip
719 BC_Popup
*tooltip_popup
;
720 // If this subwindow has already shown a tooltip since the last EnterNotify
722 // If the tooltip shouldn't be hidden
723 int persistant_tooltip
;
728 XFontSet largefontset
, mediumfontset
, smallfontset
, curr_fontset
;
732 XFontStruct
*largefont
, *mediumfont
, *smallfont
;
734 // Must be void so users don't need to include the wrong libpng version.
735 void *largefont_xft
, *mediumfont_xft
, *smallfont_xft
;
738 int64_t current_color
;
739 // Coordinate of drag start
741 // Boundaries the cursor must pass to start a drag
742 int drag_x1
, drag_x2
, drag_y1
, drag_y2
;
743 // Dragging is specific to the subwindow
745 // Don't delete the background pixmap
746 int shared_bg_pixmap
;
747 char title
[BCTEXTLEN
];
749 // X Window parameters
752 // windows previous events happened in
753 Window event_win
, drag_win
;
756 // Display for all synchronous operations
758 // Display to send events on
759 Display
*event_display
;
762 // The first context to be created and the one whose texture id
763 // space is shared with the other contexts.
764 GLXContext gl_win_context
;
768 // Depth given by the X Server
774 // Number of times start_hourglass was called
776 // Cursor set by last set_cursor which wasn't an hourglass or transparent.
778 // If hourglass overrides current cursor. Only effective in top level.
780 // If transparent overrides all cursors. Only effective in subwindow.
785 Cursor vseparate_cursor
;
786 Cursor hseparate_cursor
;
791 Cursor upright_arrow_cursor
;
792 Cursor upleft_resize_cursor
;
793 Cursor upright_resize_cursor
;
794 Cursor downleft_resize_cursor
;
795 Cursor downright_resize_cursor
;
796 Cursor hourglass_cursor
;
797 Cursor transparent_cursor
;
800 ArrayList
<BC_ResizeCall
*> resize_history
;
803 // Background tile if tiled
804 BC_Pixmap
*bg_pixmap
;
806 BC_Popup
*icon_window
;
807 BC_Pixmap
*icon_pixmap
;
809 BC_Bitmap
*temp_bitmap
;
811 BC_Clipboard
*clipboard
;
812 #ifdef HAVE_LIBXXF86VM
813 // Mode switch information.
815 XF86VidModeModeInfo orig_modeline
;
818 // Common events coming from X server and repeater.
819 ArrayList
<XEvent
*> common_events
;
820 // Locks for common events
822 // 1) event_condition
825 Condition
*event_condition
;
826 BC_WindowEvents
*event_thread
;
828 // Hide cursor when video is enabled
830 // unique ID of window.
834 Atom
create_xatom(char *atom_name
);
835 int send_custom_xatom(xatom_event
*event
);
845 // c-file-style: "linux"