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 int flash(int x
, int y
, int w
, int h
, int flush
= 1);
189 int flash(int flush
= 1);
192 // Lock out other threads
193 int lock_window(char *location
= 0);
195 int get_window_lock();
197 BC_MenuBar
* add_menubar(BC_MenuBar
*menu_bar
);
198 BC_WindowBase
* add_subwindow(BC_WindowBase
*subwindow
);
199 BC_WindowBase
* add_tool(BC_WindowBase
*subwindow
);
200 BC_WidgetGrid
* add_widgetgrid(BC_WidgetGrid
*widgetgrid
);
203 static BC_Resources
* get_resources();
204 // User must create synchronous object first
205 static BC_Synchronous
* get_synchronous();
212 virtual int reposition_widgets(){ printf("foo1"); return 0; }
213 int get_root_w(int ignore_dualhead
= 0, int lock_display
= 0);
214 int get_root_h(int lock_display
);
215 // Get current position
216 int get_abs_cursor_x(int lock_window
);
217 int get_abs_cursor_y(int lock_window
);
218 int get_relative_cursor_x();
219 int get_relative_cursor_y();
220 // Return 1 if cursor is over an unobscured part of this window.
221 // An argument is provided for excluding a drag popup
222 int get_cursor_over_window();
223 // For traversing windows... return 1 if this or any subwindow is win
224 int match_window(Window win
);
226 // 1 or 0 if a button is down
227 int get_button_down();
228 // Number of button pressed 1 - 5
229 int get_buttonpress();
233 // Get cursor position of last event
236 // Cursor position of drag start
239 int relative_cursor_x(BC_WindowBase
*pov
);
240 int relative_cursor_y(BC_WindowBase
*pov
);
244 int get_double_click();
245 // Bottom right corner
249 BC_Pixmap
* get_bg_pixmap();
250 int get_text_ascent(int font
);
251 int get_text_descent(int font
);
252 int get_text_height(int font
, char *text
= 0);
253 int get_text_width(int font
, char *text
, int length
= -1);
254 BC_Clipboard
* get_clipboard();
255 void set_dragging(int value
);
258 BC_WindowBase
* get_top_level();
259 BC_WindowBase
* get_parent();
260 // Event happened in this window
263 // Deactivate everything and activate this subwindow
264 virtual int activate();
265 // Deactivate this subwindow
266 virtual int deactivate();
267 void set_active_subwindow(BC_WindowBase
*subwindow
);
268 // Get value of toggle value when dragging a selection
269 int get_toggle_value();
270 // Get if toggle is being dragged
271 int get_toggle_drag();
273 // Set the gc to the color
274 void set_color(int64_t color
);
276 void set_font(int font
);
277 // Set the cursor to a macro from cursors.h
278 // Set override if the caller is enabling hourglass or hiding the cursor
279 void set_cursor(int cursor
, int override
= 0);
280 // Set the cursor to a character in the X cursor library. Used by test.C
281 void set_x_cursor(int cursor
);
283 // Shows the cursor after it's hidden by video playback
284 void unhide_cursor();
285 // Called by video updating routines to hide the cursor after a timeout
286 void update_video_cursor();
288 // Entry point for starting hourglass.
289 // Converts all cursors and saves the previous cursor.
290 void start_hourglass();
291 void stop_hourglass();
293 // Recursive part of hourglass commands.
294 void start_hourglass_recursive();
295 void stop_hourglass_recursive();
298 void copy_area(int x1
, int y1
, int x2
, int y2
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
299 void clear_box(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
300 void draw_box(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
301 void draw_circle(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
302 void draw_disc(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
303 void draw_text(int x
, int y
, char *text
, int length
= -1, BC_Pixmap
*pixmap
= 0);
304 void draw_center_text(int x
, int y
, char *text
, int length
= -1);
305 void draw_line(int x1
, int y1
, int x2
, int y2
, BC_Pixmap
*pixmap
= 0);
306 void draw_polygon(ArrayList
<int> *x
, ArrayList
<int> *y
, BC_Pixmap
*pixmap
= 0);
307 void draw_rectangle(int x
, int y
, int w
, int h
);
308 void draw_3segment(int x
,
312 BC_Pixmap
*left_image
,
313 BC_Pixmap
*mid_image
,
314 BC_Pixmap
*right_image
,
315 BC_Pixmap
*pixmap
= 0);
316 void draw_3segment(int x
,
323 BC_Pixmap
*pixmap
= 0);
324 // For drawing a changing level
325 void draw_3segmenth(int x
,
332 void draw_3segmenth(int x
,
339 void draw_3segmentv(int x
,
346 void draw_3segmentv(int x
,
353 // For drawing a single level
354 void draw_3segmenth(int x
,
358 BC_Pixmap
*pixmap
= 0);
359 void draw_3segmenth(int x
,
364 void draw_3segmentv(int x
,
369 void draw_3segmentv(int x
,
374 void draw_9segment(int x
,
380 void draw_9segment(int x
,
386 void draw_3d_box(int x
,
395 BC_Pixmap
*pixmap
= 0);
396 void draw_3d_border(int x
, int y
, int w
, int h
,
397 int light1
, int light2
, int shadow1
, int shadow2
);
398 void draw_colored_box(int x
, int y
, int w
, int h
, int down
, int highlighted
);
399 void draw_check(int x
, int y
);
400 void draw_triangle_down_flat(int x
, int y
, int w
, int h
);
401 void draw_triangle_up(int x
, int y
, int w
, int h
,
402 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
403 void draw_triangle_down(int x
, int y
, int w
, int h
,
404 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
405 void draw_triangle_left(int x
, int y
, int w
, int h
,
406 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
407 void draw_triangle_right(int x
, int y
, int w
, int h
,
408 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
409 // Set the gc to opaque
412 void set_background(VFrame
*bitmap
);
413 // Change the window title. The title is translated internally.
414 void set_title(char *text
);
419 void set_done(int return_value
);
420 // Get a bitmap to draw on the window with
421 BC_Bitmap
* new_bitmap(int w
, int h
, int color_model
= -1);
422 // Draw a bitmap on the window
423 void draw_bitmap(BC_Bitmap
*bitmap
,
433 BC_Pixmap
*pixmap
= 0);
434 void draw_pixel(int x
, int y
, BC_Pixmap
*pixmap
= 0);
435 // Draw a pixmap on the window
436 void draw_pixmap(BC_Pixmap
*pixmap
,
444 // Draw a vframe on the window
445 void draw_vframe(VFrame
*frame
,
454 BC_Pixmap
*pixmap
= 0);
455 void draw_border(char *text
, int x
, int y
, int w
, int h
);
456 // Draw a region of the background
457 void draw_top_background(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
458 void draw_top_tiles(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
);
459 void draw_background(int x
, int y
, int w
, int h
);
460 void draw_tiles(BC_Pixmap
*tile
,
467 void slide_left(int distance
);
468 void slide_right(int distance
);
469 void slide_up(int distance
);
470 void slide_down(int distance
);
472 int cycle_textboxes(int amount
);
474 int raise_window(int do_flush
= 1);
475 int set_tooltips(int tooltips_enabled
);
476 int resize_window(int w
, int h
);
477 int reposition_widget(int x
, int y
, int w
= -1, int h
= -1);
478 int reposition_window(int x
, int y
, int w
= -1, int h
= -1);
479 // Cause a repeat event to be dispatched every duration.
480 // duration is milliseconds
481 int set_repeat(int64_t duration
);
482 // Stop a repeat event from being dispatched.
483 int unset_repeat(int64_t duration
);
484 int set_tooltip(char *text
);
485 int show_tooltip(int w
= -1, int h
= -1);
487 int set_icon(VFrame
*data
);
488 int load_defaults(BC_Hash
*defaults
);
489 int save_defaults(BC_Hash
*defaults
);
491 #ifdef HAVE_LIBXXF86VM
492 // Mode switch methods.
493 void closest_vm(int *vm
, int *width
, int *height
);
494 void scale_vm(int vm
);
504 virtual int create_window(BC_WindowBase
*parent_window
,
518 BC_Pixmap
*bg_pixmap
,
521 static Display
* init_display(char *display_name
);
522 // Get display from top level
523 Display
* get_display();
525 virtual int initialize();
529 int init_window_shape();
530 static int evaluate_color_model(int client_byte_order
, int server_byte_order
, int depth
);
531 int create_private_colors();
532 int create_color(int color
);
533 int create_shared_colors();
534 // Get width of a single line. Used by get_text_width
535 int get_single_text_width(int font
, char *text
, int length
);
536 int allocate_color_table();
539 int get_color_rgb8(int color
);
540 int64_t get_color_rgb16(int color
);
541 int64_t get_color_bgr16(int color
);
542 int64_t get_color_bgr24(int color
);
543 XFontStruct
* get_font_struct(int font
);
545 XftFont
* get_xft_struct(int font
);
547 Cursor
get_cursor_struct(int cursor
);
548 XFontSet
get_fontset(int font
);
549 XFontSet
get_curr_fontset(void);
550 void set_fontset(int font
);
551 int dispatch_event();
553 int get_key_masks(XEvent
*event
);
555 int trigger_tooltip();
556 int untrigger_tooltip();
558 int arm_repeat(int64_t duration
);
559 // delete all repeater opjects for a close
560 int unset_all_repeaters();
562 // Block and get event from common events.
564 // Return number of events in table.
565 int get_event_count();
566 // Put event in common events.
567 void put_event(XEvent
*event
);
569 // Recursive event dispatchers
570 int dispatch_resize_event(int w
, int h
);
571 int dispatch_focus_in();
572 int dispatch_focus_out();
573 int dispatch_motion_event();
574 int dispatch_keypress_event();
575 int dispatch_repeat_event(int64_t duration
);
576 int dispatch_repeat_event_master(int64_t duration
);
577 int dispatch_button_press();
578 int dispatch_button_release();
579 int dispatch_cursor_leave();
580 int dispatch_cursor_enter();
581 int dispatch_translation_event();
582 int dispatch_drag_start();
583 int dispatch_drag_motion();
584 int dispatch_drag_stop();
585 int dispatch_expose_event();
587 // Get the port ID for a color model or return -1 for failure
588 int grab_port_id(BC_WindowBase
*window
, int color_model
);
590 int find_next_textbox(BC_WindowBase
**first_textbox
, BC_WindowBase
**next_textbox
, int &result
);
591 int find_prev_textbox(BC_WindowBase
**last_textbox
, BC_WindowBase
**prev_textbox
, int &result
);
594 void translate_coordinates(Window src_w
,
601 // Top level window above this window
602 BC_WindowBase
* top_level
;
603 // Window just above this window
604 BC_WindowBase
* parent_window
;
605 // list of window bases in this window
606 BC_SubWindowList
* subwindows
;
607 // list of window bases in this window
608 BC_WidgetGridList
* widgetgrids
;
609 // Position of window
612 int light1
, light2
, medium
, dark1
, dark2
, bg_color
;
613 // Type of window defined above
615 // Pointer to the active menubar in the window.
616 BC_MenuBar
* active_menubar
;
617 // pointer to the active popup menu in the window
618 BC_PopupMenu
* active_popup_menu
;
619 // pointer to the active subwindow
620 BC_WindowBase
* active_subwindow
;
624 int hidden
, private_color
, bits_per_pixel
, color_model
;
625 int server_byte_order
, client_byte_order
;
626 // number of colors in color table
628 // last color found in table
629 int current_color_value
, current_color_pixel
;
630 // table for every color allocated
631 int color_table
[256][2];
632 // Turn on optimization
634 // Event handler completion
636 // Return value of event handler
638 // Motion event compression
639 int motion_events
, last_motion_x
, last_motion_y
;
640 // window of buffered motion
641 Window last_motion_win
;
642 // Resize event compression
643 int resize_events
, last_resize_w
, last_resize_h
;
644 int translation_events
, last_translate_x
, last_translate_y
;
646 // Since the window manager automatically translates the window at boot,
647 // use the first translation event to get correction factors
648 int translation_count
;
649 int x_correction
, y_correction
;
651 int ctrl_mask
, shift_mask
, alt_mask
;
652 // Cursor motion information
653 int cursor_x
, cursor_y
;
654 // Button status information
655 int button_down
, button_number
;
656 // When button was pressed and whether it qualifies as a double click
657 uint64_t button_time1
, button_time2
;
659 // Which button is down. 1, 2, 3, 4, 5
663 // During a selection drag involving toggles, set the same value for each toggle
666 // Whether the window has the focus
669 static BC_Resources resources
;
670 // Array of repeaters for multiple repeating objects.
671 ArrayList
<BC_Repeater
*> repeaters
;
672 // int64_t next_repeat_id;
673 // Text for tooltip if one exists
674 char tooltip_text
[BCTEXTLEN
];
675 // If the current window's tooltip is visible
677 // Repeat ID of tooltip
678 // int64_t tooltip_id;
679 // Popup window for tooltip
680 BC_Popup
*tooltip_popup
;
681 // If this subwindow has already shown a tooltip since the last EnterNotify
683 // If the tooltip shouldn't be hidden
684 int persistant_tooltip
;
689 XFontSet largefontset
, mediumfontset
, smallfontset
, curr_fontset
;
693 XFontStruct
*largefont
, *mediumfont
, *smallfont
;
696 // XftDraw *xft_drawable;
697 // XftFont *largefont_xft, *mediumfont_xft, *smallfont_xft;
698 // Must be void so users don't need to include the wrong libpng version.
700 void *largefont_xft
, *mediumfont_xft
, *smallfont_xft
;
703 int64_t current_color
;
704 // Coordinate of drag start
706 // Boundaries the cursor must pass to start a drag
707 int drag_x1
, drag_x2
, drag_y1
, drag_y2
;
708 // Dragging is specific to the subwindow
710 // Don't delete the background pixmap
711 int shared_bg_pixmap
;
712 char title
[BCTEXTLEN
];
714 // X Window parameters
717 // windows previous events happened in
718 Window event_win
, drag_win
;
721 // Display for all synchronous operations
723 // Display to send events on
724 Display
*event_display
;
727 // The first context to be created and the one whose texture id
728 // space is shared with the other contexts.
729 GLXContext gl_win_context
;
733 // Depth given by the X Server
739 // Number of times start_hourglass was called
741 // Cursor set by last set_cursor which wasn't an hourglass or transparent.
743 // If hourglass overrides current cursor. Only effective in top level.
745 // If transparent overrides all cursors. Only effective in subwindow.
750 Cursor vseparate_cursor
;
751 Cursor hseparate_cursor
;
756 Cursor upright_arrow_cursor
;
757 Cursor upleft_resize_cursor
;
758 Cursor upright_resize_cursor
;
759 Cursor downleft_resize_cursor
;
760 Cursor downright_resize_cursor
;
761 Cursor hourglass_cursor
;
762 Cursor transparent_cursor
;
765 ArrayList
<BC_ResizeCall
*> resize_history
;
768 // Background tile if tiled
769 BC_Pixmap
*bg_pixmap
;
771 BC_Popup
*icon_window
;
772 BC_Pixmap
*icon_pixmap
;
774 BC_Bitmap
*temp_bitmap
;
776 BC_Clipboard
*clipboard
;
777 #ifdef HAVE_LIBXXF86VM
778 // Mode switch information.
780 XF86VidModeModeInfo orig_modeline
;
783 // Common events coming from X server and repeater.
784 ArrayList
<XEvent
*> common_events
;
785 // Locks for common events
787 // 1) event_condition
790 Condition
*event_condition
;
791 BC_WindowEvents
*event_thread
;
793 // Hide cursor when video is enabled
795 // unique ID of window.