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;
88 BC_ResizeCall(int w
, int h
);
93 // Windows, subwindows, popupwindows inherit from this
94 class BC_WindowBase
: public BC_RelocatableWidget
98 virtual ~BC_WindowBase();
101 friend class BC_Bitmap
;
102 friend class BC_Button
;
103 friend class BC_GenericButton
;
104 friend class BC_Capture
;
105 friend class BC_Clipboard
;
106 friend class BC_DragWindow
;
107 friend class BC_FileBox
;
108 friend class BC_FullScreen
;
109 friend class BC_ListBox
;
110 friend class BC_Menu
;
111 friend class BC_MenuBar
;
112 friend class BC_MenuItem
;
113 friend class BC_MenuPopup
;
114 friend class BC_Meter
;
116 friend class BC_PBuffer
;
117 friend class BC_Pixmap
;
118 friend class BC_PixmapSW
;
119 friend class BC_Popup
;
120 friend class BC_PopupMenu
;
122 friend class BC_ProgressBar
;
123 friend class BC_Repeater
;
124 friend class BC_Resources
;
125 friend class BC_ScrollBar
;
126 friend class BC_Slider
;
127 friend class BC_SubWindow
;
128 friend class BC_Synchronous
;
129 friend class BC_TextBox
;
130 friend class BC_Title
;
131 friend class BC_Toggle
;
132 friend class BC_Tumbler
;
133 friend class BC_Window
;
134 friend class BC_WindowEvents
;
138 // Terminal event dispatchers
139 virtual int close_event();
140 virtual int resize_event(int w
, int h
);
141 virtual int repeat_event(int64_t duration
) { return 0; };
142 virtual int focus_in_event() { return 0; };
143 virtual int focus_out_event() { return 0; };
144 virtual int button_press_event() { return 0; };
145 virtual int button_release_event() { return 0; };
146 virtual int cursor_motion_event() { return 0; };
147 virtual int cursor_leave_event();
148 virtual int cursor_enter_event();
149 virtual int keypress_event() { return 0; };
150 virtual int translation_event() { return 0; };
151 virtual int drag_start_event() { return 0; };
152 virtual int drag_motion_event() { return 0; };
153 virtual int drag_stop_event() { return 0; };
154 virtual int uses_text() { return 0; };
155 // Only if opengl is enabled
156 virtual int expose_event() { return 0; };
158 // Check if a hardware accelerated colormodel is available and reserve it
159 int accel_available(int color_model
, int lock_it
);
160 // Get color model adjusted for byte order and pixel size
161 int get_color_model();
162 // return the colormap pixel of the color for all bit depths
163 int get_color(int64_t color
);
164 // return the currently selected color
166 int show_window(int flush
= 1);
167 int hide_window(int flush
= 1);
170 // Shouldn't deference a pointer to delete a window if a parent is
171 // currently being deleted. This returns 1 if any parent is being deleted.
176 //============================= OpenGL functions ===============================
177 // OpenGL functions must be called from inside a BC_Synchronous command.
178 // Create openGL context and bind it to the current window.
179 // If it's called inside start_video/stop_video, the context is bound to the window.
180 // If it's called outside start_video/stop_video, the context is bound to the pixmap.
181 // Must be called at the beginning of any opengl routine to make sure
182 // the context is current.
183 // No locking is performed.
184 void enable_opengl();
185 void disable_opengl();
188 // Calls the BC_Synchronous version of the function with the window_id.
189 // Not run in OpenGL thread because it has its own lock.
190 unsigned int get_shader(char *title
, int *got_it
);
191 void put_shader(unsigned int handle
, char *title
);
194 int flash(int x
, int y
, int w
, int h
, int flush
= 1);
195 int flash(int flush
= 1);
198 // Lock out other threads
199 int lock_window(char *location
= 0);
201 int get_window_lock();
203 BC_MenuBar
* add_menubar(BC_MenuBar
*menu_bar
);
204 BC_WindowBase
* add_subwindow(BC_WindowBase
*subwindow
);
205 BC_WindowBase
* add_tool(BC_WindowBase
*subwindow
);
206 BC_WidgetGrid
* add_widgetgrid(BC_WidgetGrid
*widgetgrid
);
209 static BC_Resources
* get_resources();
210 // User must create synchronous object first
211 static BC_Synchronous
* get_synchronous();
218 virtual int reposition_widgets(){ printf("foo1"); return 0; }
219 int get_root_w(int ignore_dualhead
= 0, int lock_display
= 0);
220 int get_root_h(int lock_display
);
221 // Get current position
222 int get_abs_cursor_x(int lock_window
);
223 int get_abs_cursor_y(int lock_window
);
224 int get_relative_cursor_x();
225 int get_relative_cursor_y();
226 // Return 1 if cursor is over an unobscured part of this window.
227 // An argument is provided for excluding a drag popup
228 int get_cursor_over_window();
229 // For traversing windows... return 1 if this or any subwindow is win
230 int match_window(Window win
);
232 // 1 or 0 if a button is down
233 int get_button_down();
234 // Number of button pressed 1 - 5
235 int get_buttonpress();
239 // Get cursor position of last event
242 // Cursor position of drag start
245 int relative_cursor_x(BC_WindowBase
*pov
);
246 int relative_cursor_y(BC_WindowBase
*pov
);
250 int get_double_click();
251 // Bottom right corner
255 BC_Pixmap
* get_bg_pixmap();
256 int get_text_ascent(int font
);
257 int get_text_descent(int font
);
258 int get_text_height(int font
, char *text
= 0);
259 int get_text_width(int font
, char *text
, int length
= -1);
260 BC_Clipboard
* get_clipboard();
261 void set_dragging(int value
);
264 BC_WindowBase
* get_top_level();
265 BC_WindowBase
* get_parent();
266 // Event happened in this window
269 // Deactivate everything and activate this subwindow
270 virtual int activate();
271 // Deactivate this subwindow
272 virtual int deactivate();
273 void set_active_subwindow(BC_WindowBase
*subwindow
);
274 // Get value of toggle value when dragging a selection
275 int get_toggle_value();
276 // Get if toggle is being dragged
277 int get_toggle_drag();
279 // Set the gc to the color
280 void set_color(int64_t color
);
282 void set_font(int font
);
283 // Set the cursor to a macro from cursors.h
284 // Set override if the caller is enabling hourglass or hiding the cursor
285 void set_cursor(int cursor
, int override
= 0);
286 // Set the cursor to a character in the X cursor library. Used by test.C
287 void set_x_cursor(int cursor
);
289 // Shows the cursor after it's hidden by video playback
290 void unhide_cursor();
291 // Called by video updating routines to hide the cursor after a timeout
292 void update_video_cursor();
294 // Entry point for starting hourglass.
295 // Converts all cursors and saves the previous cursor.
296 void start_hourglass();
297 void stop_hourglass();
299 // Recursive part of hourglass commands.
300 void start_hourglass_recursive();
301 void stop_hourglass_recursive();
304 void copy_area(int x1
, int y1
, int x2
, int y2
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
305 void clear_box(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
306 void draw_box(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
307 void draw_circle(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
308 void draw_disc(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
309 void draw_text(int x
, int y
, char *text
, int length
= -1, BC_Pixmap
*pixmap
= 0);
310 void draw_xft_text(int x
,
320 void draw_center_text(int x
, int y
, char *text
, int length
= -1);
321 void draw_line(int x1
, int y1
, int x2
, int y2
, BC_Pixmap
*pixmap
= 0);
322 void draw_polygon(ArrayList
<int> *x
, ArrayList
<int> *y
, BC_Pixmap
*pixmap
= 0);
323 void draw_rectangle(int x
, int y
, int w
, int h
);
324 void draw_3segment(int x
,
328 BC_Pixmap
*left_image
,
329 BC_Pixmap
*mid_image
,
330 BC_Pixmap
*right_image
,
331 BC_Pixmap
*pixmap
= 0);
332 void draw_3segment(int x
,
339 BC_Pixmap
*pixmap
= 0);
340 // For drawing a changing level
341 void draw_3segmenth(int x
,
348 void draw_3segmenth(int x
,
355 void draw_3segmentv(int x
,
362 void draw_3segmentv(int x
,
369 // For drawing a single level
370 void draw_3segmenth(int x
,
374 BC_Pixmap
*pixmap
= 0);
375 void draw_3segmenth(int x
,
380 void draw_3segmentv(int x
,
385 void draw_3segmentv(int x
,
390 void draw_9segment(int x
,
396 void draw_9segment(int x
,
402 void draw_3d_box(int x
,
411 BC_Pixmap
*pixmap
= 0);
412 void draw_3d_border(int x
, int y
, int w
, int h
,
413 int light1
, int light2
, int shadow1
, int shadow2
);
414 void draw_colored_box(int x
, int y
, int w
, int h
, int down
, int highlighted
);
415 void draw_check(int x
, int y
);
416 void draw_triangle_down_flat(int x
, int y
, int w
, int h
);
417 void draw_triangle_up(int x
, int y
, int w
, int h
,
418 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
419 void draw_triangle_down(int x
, int y
, int w
, int h
,
420 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
421 void draw_triangle_left(int x
, int y
, int w
, int h
,
422 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
423 void draw_triangle_right(int x
, int y
, int w
, int h
,
424 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
425 // Set the gc to opaque
428 void set_background(VFrame
*bitmap
);
429 // Change the window title. The title is translated internally.
430 void set_title(char *text
);
435 void set_done(int return_value
);
436 // Get a bitmap to draw on the window with
437 BC_Bitmap
* new_bitmap(int w
, int h
, int color_model
= -1);
438 // Draw a bitmap on the window
439 void draw_bitmap(BC_Bitmap
*bitmap
,
449 BC_Pixmap
*pixmap
= 0);
450 void draw_pixel(int x
, int y
, BC_Pixmap
*pixmap
= 0);
451 // Draw a pixmap on the window
452 void draw_pixmap(BC_Pixmap
*pixmap
,
460 // Draw a vframe on the window
461 void draw_vframe(VFrame
*frame
,
470 BC_Pixmap
*pixmap
= 0);
471 void draw_border(char *text
, int x
, int y
, int w
, int h
);
472 // Draw a region of the background
473 void draw_top_background(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
474 void draw_top_tiles(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
);
475 void draw_background(int x
, int y
, int w
, int h
);
476 void draw_tiles(BC_Pixmap
*tile
,
483 void slide_left(int distance
);
484 void slide_right(int distance
);
485 void slide_up(int distance
);
486 void slide_down(int distance
);
488 int cycle_textboxes(int amount
);
490 int raise_window(int do_flush
= 1);
491 int set_tooltips(int tooltips_enabled
);
492 int resize_window(int w
, int h
);
493 int reposition_widget(int x
, int y
, int w
= -1, int h
= -1);
494 int reposition_window(int x
, int y
, int w
= -1, int h
= -1);
495 // Cause a repeat event to be dispatched every duration.
496 // duration is milliseconds
497 int set_repeat(int64_t duration
);
498 // Stop a repeat event from being dispatched.
499 int unset_repeat(int64_t duration
);
500 int set_tooltip(char *text
);
501 int show_tooltip(int w
= -1, int h
= -1);
503 int set_icon(VFrame
*data
);
504 int load_defaults(BC_Hash
*defaults
);
505 int save_defaults(BC_Hash
*defaults
);
507 #ifdef HAVE_LIBXXF86VM
508 // Mode switch methods.
509 void closest_vm(int *vm
, int *width
, int *height
);
510 void scale_vm(int vm
);
520 virtual int create_window(BC_WindowBase
*parent_window
,
534 BC_Pixmap
*bg_pixmap
,
537 static Display
* init_display(char *display_name
);
538 // Get display from top level
539 Display
* get_display();
541 virtual int initialize();
545 int init_window_shape();
546 static int evaluate_color_model(int client_byte_order
, int server_byte_order
, int depth
);
547 int create_private_colors();
548 int create_color(int color
);
549 int create_shared_colors();
550 // Get width of a single line. Used by get_text_width
551 int get_single_text_width(int font
, char *text
, int length
);
552 int allocate_color_table();
556 int get_color_rgb8(int color
);
557 int64_t get_color_rgb16(int color
);
558 int64_t get_color_bgr16(int color
);
559 int64_t get_color_bgr24(int color
);
560 XFontStruct
* get_font_struct(int font
);
562 XftFont
* get_xft_struct(int font
);
564 Cursor
get_cursor_struct(int cursor
);
565 XFontSet
get_fontset(int font
);
566 XFontSet
get_curr_fontset(void);
567 void set_fontset(int font
);
568 int dispatch_event();
570 int get_key_masks(XEvent
*event
);
572 int trigger_tooltip();
573 int untrigger_tooltip();
575 int arm_repeat(int64_t duration
);
576 // delete all repeater opjects for a close
577 int unset_all_repeaters();
579 // Block and get event from common events.
581 // Return number of events in table.
582 int get_event_count();
583 // Put event in common events.
584 void put_event(XEvent
*event
);
586 // Recursive event dispatchers
587 int dispatch_resize_event(int w
, int h
);
588 int dispatch_focus_in();
589 int dispatch_focus_out();
590 int dispatch_motion_event();
591 int dispatch_keypress_event();
592 int dispatch_repeat_event(int64_t duration
);
593 int dispatch_repeat_event_master(int64_t duration
);
594 int dispatch_button_press();
595 int dispatch_button_release();
596 int dispatch_cursor_leave();
597 int dispatch_cursor_enter();
598 int dispatch_translation_event();
599 int dispatch_drag_start();
600 int dispatch_drag_motion();
601 int dispatch_drag_stop();
602 int dispatch_expose_event();
604 // Get the port ID for a color model or return -1 for failure
605 int grab_port_id(BC_WindowBase
*window
, int color_model
);
607 int find_next_textbox(BC_WindowBase
**first_textbox
, BC_WindowBase
**next_textbox
, int &result
);
608 int find_prev_textbox(BC_WindowBase
**last_textbox
, BC_WindowBase
**prev_textbox
, int &result
);
611 void translate_coordinates(Window src_w
,
618 // Top level window above this window
619 BC_WindowBase
* top_level
;
620 // Window just above this window
621 BC_WindowBase
* parent_window
;
622 // list of window bases in this window
623 BC_SubWindowList
* subwindows
;
624 // list of window bases in this window
625 BC_WidgetGridList
* widgetgrids
;
626 // Position of window
629 int light1
, light2
, medium
, dark1
, dark2
, bg_color
;
630 // Type of window defined above
632 // Pointer to the active menubar in the window.
633 BC_MenuBar
* active_menubar
;
634 // pointer to the active popup menu in the window
635 BC_PopupMenu
* active_popup_menu
;
636 // pointer to the active subwindow
637 BC_WindowBase
* active_subwindow
;
641 int hidden
, private_color
, bits_per_pixel
, color_model
;
642 int server_byte_order
, client_byte_order
;
643 // number of colors in color table
645 // last color found in table
646 int current_color_value
, current_color_pixel
;
647 // table for every color allocated
648 int color_table
[256][2];
649 // Turn on optimization
651 // Event handler completion
653 // Return value of event handler
655 // Motion event compression
656 int motion_events
, last_motion_x
, last_motion_y
;
657 // window of buffered motion
658 Window last_motion_win
;
659 // Resize event compression
660 int resize_events
, last_resize_w
, last_resize_h
;
661 int translation_events
, last_translate_x
, last_translate_y
;
663 // Since the window manager automatically translates the window at boot,
664 // use the first translation event to get correction factors
665 int translation_count
;
666 int x_correction
, y_correction
;
668 int ctrl_mask
, shift_mask
, alt_mask
;
669 // Cursor motion information
670 int cursor_x
, cursor_y
;
671 // Button status information
672 int button_down
, button_number
;
673 // When button was pressed and whether it qualifies as a double click
674 uint64_t button_time1
, button_time2
;
676 // Which button is down. 1, 2, 3, 4, 5
680 // During a selection drag involving toggles, set the same value for each toggle
683 // Whether the window has the focus
686 static BC_Resources resources
;
687 // Array of repeaters for multiple repeating objects.
688 ArrayList
<BC_Repeater
*> repeaters
;
689 // int64_t next_repeat_id;
690 // Text for tooltip if one exists
691 char tooltip_text
[BCTEXTLEN
];
692 // If the current window's tooltip is visible
694 // Repeat ID of tooltip
695 // int64_t tooltip_id;
696 // Popup window for tooltip
697 BC_Popup
*tooltip_popup
;
698 // If this subwindow has already shown a tooltip since the last EnterNotify
700 // If the tooltip shouldn't be hidden
701 int persistant_tooltip
;
706 XFontSet largefontset
, mediumfontset
, smallfontset
, curr_fontset
;
710 XFontStruct
*largefont
, *mediumfont
, *smallfont
;
712 // Must be void so users don't need to include the wrong libpng version.
713 void *largefont_xft
, *mediumfont_xft
, *smallfont_xft
;
716 int64_t current_color
;
717 // Coordinate of drag start
719 // Boundaries the cursor must pass to start a drag
720 int drag_x1
, drag_x2
, drag_y1
, drag_y2
;
721 // Dragging is specific to the subwindow
723 // Don't delete the background pixmap
724 int shared_bg_pixmap
;
725 char title
[BCTEXTLEN
];
727 // X Window parameters
730 // windows previous events happened in
731 Window event_win
, drag_win
;
734 // Display for all synchronous operations
736 // Display to send events on
737 Display
*event_display
;
740 // The first context to be created and the one whose texture id
741 // space is shared with the other contexts.
742 GLXContext gl_win_context
;
746 // Depth given by the X Server
752 // Number of times start_hourglass was called
754 // Cursor set by last set_cursor which wasn't an hourglass or transparent.
756 // If hourglass overrides current cursor. Only effective in top level.
758 // If transparent overrides all cursors. Only effective in subwindow.
763 Cursor vseparate_cursor
;
764 Cursor hseparate_cursor
;
769 Cursor upright_arrow_cursor
;
770 Cursor upleft_resize_cursor
;
771 Cursor upright_resize_cursor
;
772 Cursor downleft_resize_cursor
;
773 Cursor downright_resize_cursor
;
774 Cursor hourglass_cursor
;
775 Cursor transparent_cursor
;
778 ArrayList
<BC_ResizeCall
*> resize_history
;
781 // Background tile if tiled
782 BC_Pixmap
*bg_pixmap
;
784 BC_Popup
*icon_window
;
785 BC_Pixmap
*icon_pixmap
;
787 BC_Bitmap
*temp_bitmap
;
789 BC_Clipboard
*clipboard
;
790 #ifdef HAVE_LIBXXF86VM
791 // Mode switch information.
793 XF86VidModeModeInfo orig_modeline
;
796 // Common events coming from X server and repeater.
797 ArrayList
<XEvent
*> common_events
;
798 // Locks for common events
800 // 1) event_condition
803 Condition
*event_condition
;
804 BC_WindowEvents
*event_thread
;
806 // Hide cursor when video is enabled
808 // unique ID of window.