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 "bcpixmap.inc"
33 #include "bcpopup.inc"
34 #include "bcpopupmenu.inc"
36 #include "bcprogress.inc"
37 #include "bcrepeater.inc"
38 #include "bcresources.inc"
39 #include "bcscrollbar.inc"
40 #include "bcslider.inc"
41 #include "bcsubwindow.inc"
42 #include "bctextbox.inc"
43 #include "bctitle.inc"
44 #include "bctoggle.inc"
45 #include "bctumble.inc"
46 #include "bcwindow.inc"
47 #include "bcwindowbase.inc"
48 #include "bcwindowevents.inc"
49 #include "condition.inc"
50 #include "defaults.inc"
59 #include <X11/Xatom.h>
61 #include <X11/Xft/Xft.h>
64 #include <X11/Xutil.h>
65 #include <X11/keysym.h>
66 #include <X11/cursorfont.h>
67 #ifdef HAVE_LIBXXF86VM
68 #include <X11/extensions/xf86vmode.h>
75 typedef void* GLXContext
;
81 BC_ResizeCall(int w
, int h
);
86 // Windows, subwindows, popupwindows inherit from this
91 virtual ~BC_WindowBase();
94 friend class BC_Bitmap
;
95 friend class BC_Button
;
96 friend class BC_GenericButton
;
97 friend class BC_Capture
;
98 friend class BC_Clipboard
;
99 friend class BC_DragWindow
;
100 friend class BC_FileBox
;
101 friend class BC_FullScreen
;
102 friend class BC_ListBox
;
103 friend class BC_Menu
;
104 friend class BC_MenuBar
;
105 friend class BC_MenuItem
;
106 friend class BC_MenuPopup
;
107 friend class BC_Meter
;
109 friend class BC_Pixmap
;
110 friend class BC_Popup
;
111 friend class BC_PopupMenu
;
113 friend class BC_ProgressBar
;
114 friend class BC_Repeater
;
115 friend class BC_Resources
;
116 friend class BC_ScrollBar
;
117 friend class BC_Slider
;
118 friend class BC_SubWindow
;
119 friend class BC_TextBox
;
120 friend class BC_Title
;
121 friend class BC_Toggle
;
122 friend class BC_Tumbler
;
123 friend class BC_Window
;
124 friend class BC_WindowEvents
;
128 // Terminal event dispatchers
129 virtual int close_event();
130 virtual int resize_event(int w
, int h
);
131 virtual int repeat_event(int64_t duration
) { return 0; };
132 virtual int focus_in_event() { return 0; };
133 virtual int focus_out_event() { return 0; };
134 virtual int button_press_event() { return 0; };
135 virtual int button_release_event() { return 0; };
136 virtual int cursor_motion_event() { return 0; };
137 virtual int cursor_leave_event();
138 virtual int cursor_enter_event();
139 virtual int keypress_event() { return 0; };
140 virtual int translation_event() { return 0; };
141 virtual int drag_start_event() { return 0; };
142 virtual int drag_motion_event() { return 0; };
143 virtual int drag_stop_event() { return 0; };
144 virtual int uses_text() { return 0; };
145 // Only if opengl is enabled
146 virtual int expose_event() { return 0; };
148 // Check if a hardware accelerated colormodel is available and reserve it
149 int accel_available(int color_model
, int lock_it
);
150 // Get color model adjusted for byte order and pixel size
151 int get_color_model();
152 // return the colormap pixel of the color for all bit depths
153 int get_color(int64_t color
);
154 // return the currently selected color
156 int show_window(int flush
= 1);
157 int hide_window(int flush
= 1);
160 // Shouldn't deference a pointer to delete a window if a parent is
161 // currently being deleted. This returns 1 if any parent is being deleted.
163 void enable_opengl();
164 void disable_opengl();
166 void unlock_opengl();
169 int flash(int x
, int y
, int w
, int h
, int flush
= 1);
170 int flash(int flush
= 1);
173 // Lock out other threads
174 int lock_window(char *location
= 0);
176 int get_window_lock();
178 BC_MenuBar
* add_menubar(BC_MenuBar
*menu_bar
);
179 BC_WindowBase
* add_subwindow(BC_WindowBase
*subwindow
);
180 BC_WindowBase
* add_tool(BC_WindowBase
*subwindow
);
182 static BC_Resources
* get_resources();
188 int get_root_w(int ignore_dualhead
= 0, int lock_display
= 0);
189 int get_root_h(int lock_display
);
190 // Get current position
191 int get_abs_cursor_x(int lock_window
);
192 int get_abs_cursor_y(int lock_window
);
193 int get_relative_cursor_x();
194 int get_relative_cursor_y();
195 // Return 1 if cursor is over an unobscured part of this window.
196 // An argument is provided for excluding a drag popup
197 int get_cursor_over_window();
198 // For traversing windows... return 1 if this or any subwindow is win
199 int match_window(Window win
);
201 // 1 or 0 if a button is down
202 int get_button_down();
203 // Number of button pressed 1 - 5
204 int get_buttonpress();
208 // Get cursor position of last event
211 // Cursor position of drag start
214 int relative_cursor_x(BC_WindowBase
*pov
);
215 int relative_cursor_y(BC_WindowBase
*pov
);
219 int get_double_click();
220 // Bottom right corner
224 BC_Pixmap
* get_bg_pixmap();
225 int get_text_ascent(int font
);
226 int get_text_descent(int font
);
227 int get_text_height(int font
, char *text
= 0);
228 int get_text_width(int font
, char *text
, int length
= -1);
229 BC_Clipboard
* get_clipboard();
230 void set_dragging(int value
);
233 BC_WindowBase
* get_top_level();
234 BC_WindowBase
* get_parent();
235 // Event happened in this window
238 // Deactivate everything and activate this subwindow
239 virtual int activate();
240 // Deactivate this subwindow
241 virtual int deactivate();
242 void set_active_subwindow(BC_WindowBase
*subwindow
);
243 // Get value of toggle value when dragging a selection
244 int get_toggle_value();
245 // Get if toggle is being dragged
246 int get_toggle_drag();
249 // Set the gc to the color
250 void set_color(int64_t color
);
252 void set_font(int font
);
253 // Set the cursor to a macro from cursors.h
254 void set_cursor(int cursor
, int is_hourglass
= 0);
255 // Set the cursor to a character in the X cursor library. Used by test.C
256 void set_x_cursor(int cursor
);
259 // Entry point for starting hourglass.
260 // Converts all cursors and saves the previous cursor.
261 void start_hourglass();
262 void stop_hourglass();
264 // Recursive part of hourglass commands.
265 void start_hourglass_recursive();
266 void stop_hourglass_recursive();
269 void copy_area(int x1
, int y1
, int x2
, int y2
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
270 void clear_box(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
271 void draw_box(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
272 void draw_circle(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
273 void draw_disc(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
274 void draw_text(int x
, int y
, char *text
, int length
= -1, BC_Pixmap
*pixmap
= 0);
275 void draw_center_text(int x
, int y
, char *text
, int length
= -1);
276 void draw_line(int x1
, int y1
, int x2
, int y2
, BC_Pixmap
*pixmap
= 0);
277 void draw_polygon(ArrayList
<int> *x
, ArrayList
<int> *y
, BC_Pixmap
*pixmap
= 0);
278 void draw_rectangle(int x
, int y
, int w
, int h
);
279 void draw_3segment(int x
,
283 BC_Pixmap
*left_image
,
284 BC_Pixmap
*mid_image
,
285 BC_Pixmap
*right_image
,
286 BC_Pixmap
*pixmap
= 0);
287 void draw_3segment(int x
,
294 BC_Pixmap
*pixmap
= 0);
295 // For drawing a changing level
296 void draw_3segmenth(int x
,
303 void draw_3segmenth(int x
,
310 void draw_3segmentv(int x
,
317 void draw_3segmentv(int x
,
324 // For drawing a single level
325 void draw_3segmenth(int x
,
329 BC_Pixmap
*pixmap
= 0);
330 void draw_3segmenth(int x
,
335 void draw_3segmentv(int x
,
340 void draw_3segmentv(int x
,
345 void draw_9segment(int x
,
351 void draw_9segment(int x
,
357 void draw_3d_box(int x
,
366 BC_Pixmap
*pixmap
= 0);
367 void draw_3d_border(int x
, int y
, int w
, int h
,
368 int light1
, int light2
, int shadow1
, int shadow2
);
369 void draw_colored_box(int x
, int y
, int w
, int h
, int down
, int highlighted
);
370 void draw_check(int x
, int y
);
371 void draw_triangle_down_flat(int x
, int y
, int w
, int h
);
372 void draw_triangle_up(int x
, int y
, int w
, int h
,
373 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
374 void draw_triangle_down(int x
, int y
, int w
, int h
,
375 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
376 void draw_triangle_left(int x
, int y
, int w
, int h
,
377 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
378 void draw_triangle_right(int x
, int y
, int w
, int h
,
379 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
380 // Set the gc to opaque
383 void set_background(VFrame
*bitmap
);
384 // Change the window title. The title is translated internally.
385 void set_title(char *text
);
390 void set_done(int return_value
);
391 // Get a bitmap to draw on the window with
392 BC_Bitmap
* new_bitmap(int w
, int h
, int color_model
= -1);
393 // Draw a bitmap on the window
394 void draw_bitmap(BC_Bitmap
*bitmap
,
404 BC_Pixmap
*pixmap
= 0);
405 void draw_pixel(int x
, int y
, BC_Pixmap
*pixmap
= 0);
406 // Draw a pixmap on the window
407 void draw_pixmap(BC_Pixmap
*pixmap
,
415 // Draw a vframe on the window
416 void draw_vframe(VFrame
*frame
,
425 BC_Pixmap
*pixmap
= 0);
426 void draw_border(char *text
, int x
, int y
, int w
, int h
);
427 // Draw a region of the background
428 void draw_top_background(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
429 void draw_top_tiles(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
);
430 void draw_background(int x
, int y
, int w
, int h
);
431 void draw_tiles(BC_Pixmap
*tile
,
438 void slide_left(int distance
);
439 void slide_right(int distance
);
440 void slide_up(int distance
);
441 void slide_down(int distance
);
443 int cycle_textboxes(int amount
);
445 int raise_window(int do_flush
= 1);
446 int set_tooltips(int tooltips_enabled
);
447 int resize_window(int w
, int h
);
448 int reposition_window(int x
, int y
, int w
= -1, int h
= -1);
449 // Cause a repeat event to be dispatched every duration.
450 // duration is milliseconds
451 int set_repeat(int64_t duration
);
452 // Stop a repeat event from being dispatched.
453 int unset_repeat(int64_t duration
);
454 int set_tooltip(char *text
);
455 int show_tooltip(int w
= -1, int h
= -1);
457 int set_icon(VFrame
*data
);
458 int load_defaults(Defaults
*defaults
);
459 int save_defaults(Defaults
*defaults
);
461 #ifdef HAVE_LIBXXF86VM
462 // Mode switch methods.
463 void closest_vm(int *vm
, int *width
, int *height
);
464 void scale_vm(int vm
);
474 virtual int create_window(BC_WindowBase
*parent_window
,
488 BC_Pixmap
*bg_pixmap
,
491 static Display
* init_display(char *display_name
);
492 virtual int initialize();
496 int init_window_shape();
497 static int evaluate_color_model(int client_byte_order
, int server_byte_order
, int depth
);
498 int create_private_colors();
499 int create_color(int color
);
500 int create_shared_colors();
501 // Get width of a single line. Used by get_text_width
502 int get_single_text_width(int font
, char *text
, int length
);
503 int allocate_color_table();
506 int get_color_rgb8(int color
);
507 int64_t get_color_rgb16(int color
);
508 int64_t get_color_bgr16(int color
);
509 int64_t get_color_bgr24(int color
);
510 XFontStruct
* get_font_struct(int font
);
512 XftFont
* get_xft_struct(int font
);
514 Cursor
get_cursor_struct(int cursor
);
515 XFontSet
get_fontset(int font
);
516 XFontSet
get_curr_fontset(void);
517 void set_fontset(int font
);
518 int dispatch_event();
520 int get_key_masks(XEvent
*event
);
522 int trigger_tooltip();
523 int untrigger_tooltip();
525 int arm_repeat(int64_t duration
);
526 // delete all repeater opjects for a close
527 int unset_all_repeaters();
529 // Block and get event from common events.
531 // Return number of events in table.
532 int get_event_count();
533 // Put event in common events.
534 void put_event(XEvent
*event
);
536 // Recursive event dispatchers
537 int dispatch_resize_event(int w
, int h
);
538 int dispatch_focus_in();
539 int dispatch_focus_out();
540 int dispatch_motion_event();
541 int dispatch_keypress_event();
542 int dispatch_repeat_event(int64_t duration
);
543 int dispatch_repeat_event_master(int64_t duration
);
544 int dispatch_button_press();
545 int dispatch_button_release();
546 int dispatch_cursor_leave();
547 int dispatch_cursor_enter();
548 int dispatch_translation_event();
549 int dispatch_drag_start();
550 int dispatch_drag_motion();
551 int dispatch_drag_stop();
552 int dispatch_expose_event();
554 // Get the port ID for a color model or return -1 for failure
555 int grab_port_id(BC_WindowBase
*window
, int color_model
);
557 int find_next_textbox(BC_WindowBase
**first_textbox
, BC_WindowBase
**next_textbox
, int &result
);
558 int find_prev_textbox(BC_WindowBase
**last_textbox
, BC_WindowBase
**prev_textbox
, int &result
);
562 void translate_coordinates(Window src_w
,
569 // Top level window above this window
570 BC_WindowBase
* top_level
;
571 // Window just above this window
572 BC_WindowBase
* parent_window
;
573 // list of window bases in this window
574 BC_SubWindowList
* subwindows
;
575 // Position of window
578 int light1
, light2
, medium
, dark1
, dark2
, bg_color
;
579 // Type of window defined above
581 // Pointer to the active menubar in the window.
582 BC_MenuBar
* active_menubar
;
583 // pointer to the active popup menu in the window
584 BC_PopupMenu
* active_popup_menu
;
585 // pointer to the active subwindow
586 BC_WindowBase
* active_subwindow
;
590 int hidden
, private_color
, bits_per_pixel
, color_model
;
591 int server_byte_order
, client_byte_order
;
592 // number of colors in color table
594 // last color found in table
595 int current_color_value
, current_color_pixel
;
596 // table for every color allocated
597 int color_table
[256][2];
598 // Turn on optimization
600 // Event handler completion
602 // Return value of event handler
604 // Motion event compression
605 int motion_events
, last_motion_x
, last_motion_y
;
606 // window of buffered motion
607 Window last_motion_win
;
608 // Resize event compression
609 int resize_events
, last_resize_w
, last_resize_h
;
610 int translation_events
, last_translate_x
, last_translate_y
;
612 // Since the window manager automatically translates the window at boot,
613 // use the first translation event to get correction factors
614 int translation_count
;
615 int x_correction
, y_correction
;
617 int ctrl_mask
, shift_mask
, alt_mask
;
618 // Cursor motion information
619 int cursor_x
, cursor_y
;
620 // Button status information
621 int button_down
, button_number
;
622 // When button was pressed and whether it qualifies as a double click
623 uint64_t button_time1
, button_time2
;
625 // Which button is down. 1, 2, 3, 4, 5
629 // During a selection drag involving toggles, set the same value for each toggle
632 // Whether the window has the focus
635 static BC_Resources resources
;
636 // Array of repeaters for multiple repeating objects.
637 ArrayList
<BC_Repeater
*> repeaters
;
638 // int64_t next_repeat_id;
639 // Text for tooltip if one exists
640 char tooltip_text
[BCTEXTLEN
];
641 // If the current window's tooltip is visible
643 // Repeat ID of tooltip
644 // int64_t tooltip_id;
645 // Popup window for tooltip
646 BC_Popup
*tooltip_popup
;
647 // If this subwindow has already shown a tooltip since the last EnterNotify
649 // If the tooltip shouldn't be hidden
650 int persistant_tooltip
;
655 XFontSet largefontset
, mediumfontset
, smallfontset
, curr_fontset
;
659 XFontStruct
*largefont
, *mediumfont
, *smallfont
;
662 // XftDraw *xft_drawable;
663 // XftFont *largefont_xft, *mediumfont_xft, *smallfont_xft;
664 // Must be void so users don't need to include the wrong libpng version.
666 void *largefont_xft
, *mediumfont_xft
, *smallfont_xft
;
669 int64_t current_color
;
670 // Coordinate of drag start
672 // Boundaries the cursor must pass to start a drag
673 int drag_x1
, drag_x2
, drag_y1
, drag_y2
;
674 // Dragging is specific to the subwindow
676 // Don't delete the background pixmap
677 int shared_bg_pixmap
;
678 char title
[BCTEXTLEN
];
680 // X Window parameters
683 // windows previous events happened in
684 Window event_win
, drag_win
;
687 // Display for all synchronous operations
689 // Display to send events on
690 Display
*event_display
;
694 GLXContext gl_context
;
696 static Mutex opengl_lock
;
699 // Depth given by the X Server
705 // Cursor before starting an hourglass operation.
707 // Number of times start_hourglass was called
709 // Cursor set by last set_cursor.
714 Cursor vseparate_cursor
;
715 Cursor hseparate_cursor
;
720 Cursor upright_arrow_cursor
;
721 Cursor upleft_resize_cursor
;
722 Cursor upright_resize_cursor
;
723 Cursor downleft_resize_cursor
;
724 Cursor downright_resize_cursor
;
725 Cursor hourglass_cursor
;
728 ArrayList
<BC_ResizeCall
*> resize_history
;
729 // Background tile if tiled
730 BC_Pixmap
*bg_pixmap
;
732 BC_Popup
*icon_window
;
733 BC_Pixmap
*icon_pixmap
;
735 BC_Bitmap
*temp_bitmap
;
737 BC_Clipboard
*clipboard
;
738 #ifdef HAVE_LIBXXF86VM
739 // Mode switch information.
741 XF86VidModeModeInfo orig_modeline
;
744 // Common events coming from X server and repeater.
745 ArrayList
<XEvent
*> common_events
;
746 // Locks for common events
748 // 1) event_condition
751 Condition
*event_condition
;
752 BC_WindowEvents
*event_thread
;