00001 #ifndef BCWINDOWBASE_H
00002 #define BCWINDOWBASE_H
00003
00004 #if defined(HAVE_CONFIG_H)
00005 #include "config.h"
00006 #endif
00007
00008
00009
00010 #define MAIN_WINDOW 0
00011 #define SUB_WINDOW 1
00012 #define POPUP_WINDOW 2
00013 #ifdef HAVE_LIBXXF86VM
00014 #define VIDMODE_SCALED_WINDOW 3
00015 #endif
00016
00017 #define TOOLTIP_MARGIN 2
00018 #define BC_INFINITY 65536
00019
00020 #include "arraylist.h"
00021 #include "bcbar.inc"
00022 #include "bcbitmap.inc"
00023 #include "bcbutton.inc"
00024 #include "bccapture.inc"
00025 #include "bcclipboard.inc"
00026 #include "bcdragwindow.inc"
00027 #include "bcfilebox.inc"
00028 #include "bclistbox.inc"
00029 #include "bcmenubar.inc"
00030 #include "bcmeter.inc"
00031 #include "bcpan.inc"
00032 #include "bcpixmap.inc"
00033 #include "bcpopup.inc"
00034 #include "bcpopupmenu.inc"
00035 #include "bcpot.inc"
00036 #include "bcprogress.inc"
00037 #include "bcrelocatablewidget.h"
00038 #include "bcrepeater.inc"
00039 #include "bcresources.inc"
00040 #include "bcscrollbar.inc"
00041 #include "bcslider.inc"
00042 #include "bcsubwindow.inc"
00043 #include "bctextbox.inc"
00044 #include "bctitle.inc"
00045 #include "bctoggle.inc"
00046 #include "bctumble.inc"
00047 #include "bcwindow.inc"
00048 #include "bcwindowbase.inc"
00049 #include "bcwindowevents.inc"
00050 #include "condition.inc"
00051 #include "defaults.inc"
00052 #include "linklist.h"
00053 #include "mutex.h"
00054 #include "vframe.inc"
00055
00056
00057 #include <stdint.h>
00058 #include <stdio.h>
00059 #include <stdlib.h>
00060 #include <X11/Xatom.h>
00061 #ifdef HAVE_XFT
00062 #include <X11/Xft/Xft.h>
00063 #endif
00064 #include <X11/Xlib.h>
00065 #include <X11/Xutil.h>
00066 #include <X11/keysym.h>
00067 #include <X11/cursorfont.h>
00068 #ifdef HAVE_LIBXXF86VM
00069 #include <X11/extensions/xf86vmode.h>
00070 #endif
00071
00072
00073
00074
00075 #ifdef HAVE_GL
00076 typedef void* GLXContext;
00077 #endif
00078
00079 class BC_ResizeCall
00080 {
00081 public:
00082 BC_ResizeCall(int w, int h);
00083 int w, h;
00084 };
00085
00086
00087
00088 class BC_WindowBase : public BC_RelocatableWidget
00089 {
00090 public:
00091 BC_WindowBase();
00092 virtual ~BC_WindowBase();
00093
00094 friend class BC_Bar;
00095 friend class BC_Bitmap;
00096 friend class BC_Button;
00097 friend class BC_GenericButton;
00098 friend class BC_Capture;
00099 friend class BC_Clipboard;
00100 friend class BC_DragWindow;
00101 friend class BC_FileBox;
00102 friend class BC_FullScreen;
00103 friend class BC_ListBox;
00104 friend class BC_Menu;
00105 friend class BC_MenuBar;
00106 friend class BC_MenuItem;
00107 friend class BC_MenuPopup;
00108 friend class BC_Meter;
00109 friend class BC_Pan;
00110 friend class BC_Pixmap;
00111 friend class BC_PixmapSW;
00112 friend class BC_Popup;
00113 friend class BC_PopupMenu;
00114 friend class BC_Pot;
00115 friend class BC_ProgressBar;
00116 friend class BC_Repeater;
00117 friend class BC_Resources;
00118 friend class BC_ScrollBar;
00119 friend class BC_Slider;
00120 friend class BC_SubWindow;
00121 friend class BC_TextBox;
00122 friend class BC_Title;
00123 friend class BC_Toggle;
00124 friend class BC_Tumbler;
00125 friend class BC_Window;
00126 friend class BC_WindowEvents;
00127
00128
00129 int run_window();
00130
00131 virtual int close_event();
00132 virtual int resize_event(int w, int h);
00133 virtual int repeat_event(int64_t duration) { return 0; };
00134 virtual int focus_in_event() { return 0; };
00135 virtual int focus_out_event() { return 0; };
00136 virtual int button_press_event() { return 0; };
00137 virtual int button_release_event() { return 0; };
00138 virtual int cursor_motion_event() { return 0; };
00139 virtual int cursor_leave_event();
00140 virtual int cursor_enter_event();
00141 virtual int keypress_event() { return 0; };
00142 virtual int translation_event() { return 0; };
00143 virtual int drag_start_event() { return 0; };
00144 virtual int drag_motion_event() { return 0; };
00145 virtual int drag_stop_event() { return 0; };
00146 virtual int uses_text() { return 0; };
00147
00148 virtual int expose_event() { return 0; };
00149
00150
00151 int accel_available(int color_model, int lock_it);
00152
00153 int get_color_model();
00154
00155 int get_color(int64_t color);
00156
00157 int64_t get_color();
00158 int show_window(int flush = 1);
00159 int hide_window(int flush = 1);
00160 int get_hidden();
00161 int get_video_on();
00162
00163
00164 int get_deleting();
00165 void enable_opengl();
00166 void disable_opengl();
00167 void lock_opengl();
00168 void unlock_opengl();
00169 void flip_opengl();
00170
00171 int flash(int x, int y, int w, int h, int flush = 1);
00172 int flash(int flush = 1);
00173 void flush();
00174 void sync_display();
00175
00176 int lock_window(char *location = 0);
00177 int unlock_window();
00178 int get_window_lock();
00179
00180 BC_MenuBar* add_menubar(BC_MenuBar *menu_bar);
00181 BC_WindowBase* add_subwindow(BC_WindowBase *subwindow);
00182 BC_WindowBase* add_tool(BC_WindowBase *subwindow);
00183
00184 static BC_Resources* get_resources();
00185
00186 virtual int get_w();
00187 virtual int get_h();
00188 virtual int get_x();
00189 virtual int get_y();
00190 int get_root_w(int ignore_dualhead = 0, int lock_display = 0);
00191 int get_root_h(int lock_display);
00192
00193 int get_abs_cursor_x(int lock_window);
00194 int get_abs_cursor_y(int lock_window);
00195 int get_relative_cursor_x();
00196 int get_relative_cursor_y();
00197
00198
00199 int get_cursor_over_window();
00200
00201 int match_window(Window win);
00202
00203
00204 int get_button_down();
00205
00206 int get_buttonpress();
00207 int get_has_focus();
00208 int get_dragging();
00209 int get_keypress();
00210
00211 int get_cursor_x();
00212 int get_cursor_y();
00213
00214 int get_drag_x();
00215 int get_drag_y();
00216 int relative_cursor_x(BC_WindowBase *pov);
00217 int relative_cursor_y(BC_WindowBase *pov);
00218 int alt_down();
00219 int shift_down();
00220 int ctrl_down();
00221 int get_double_click();
00222
00223 int get_x2();
00224 int get_y2();
00225 int get_bg_color();
00226 BC_Pixmap* get_bg_pixmap();
00227 int get_text_ascent(int font);
00228 int get_text_descent(int font);
00229 int get_text_height(int font, char *text = 0);
00230 int get_text_width(int font, char *text, int length = -1);
00231 BC_Clipboard* get_clipboard();
00232 void set_dragging(int value);
00233 int set_w(int w);
00234 int set_h(int h);
00235 BC_WindowBase* get_top_level();
00236 BC_WindowBase* get_parent();
00237
00238 int is_event_win();
00239 int cursor_inside();
00240
00241 virtual int activate();
00242
00243 virtual int deactivate();
00244 void set_active_subwindow(BC_WindowBase *subwindow);
00245
00246 int get_toggle_value();
00247
00248 int get_toggle_drag();
00249
00250
00251
00252 void set_color(int64_t color);
00253 int get_bgcolor();
00254 void set_font(int font);
00255
00256 void set_cursor(int cursor, int is_hourglass = 0);
00257
00258 void set_x_cursor(int cursor);
00259 int get_cursor();
00260
00261
00262
00263 void start_hourglass();
00264 void stop_hourglass();
00265
00266
00267 void start_hourglass_recursive();
00268 void stop_hourglass_recursive();
00269
00270
00271 void copy_area(int x1, int y1, int x2, int y2, int w, int h, BC_Pixmap *pixmap = 0);
00272 void clear_box(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
00273 void draw_box(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
00274 void draw_circle(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
00275 void draw_disc(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
00276 void draw_text(int x, int y, char *text, int length = -1, BC_Pixmap *pixmap = 0);
00277 void draw_center_text(int x, int y, char *text, int length = -1);
00278 void draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap = 0);
00279 void draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap = 0);
00280 void draw_rectangle(int x, int y, int w, int h);
00281 void draw_3segment(int x,
00282 int y,
00283 int w,
00284 int h,
00285 BC_Pixmap *left_image,
00286 BC_Pixmap *mid_image,
00287 BC_Pixmap *right_image,
00288 BC_Pixmap *pixmap = 0);
00289 void draw_3segment(int x,
00290 int y,
00291 int w,
00292 int h,
00293 VFrame *left_image,
00294 VFrame *mid_image,
00295 VFrame *right_image,
00296 BC_Pixmap *pixmap = 0);
00297
00298 void draw_3segmenth(int x,
00299 int y,
00300 int w,
00301 int total_x,
00302 int total_w,
00303 VFrame *image,
00304 BC_Pixmap *pixmap);
00305 void draw_3segmenth(int x,
00306 int y,
00307 int w,
00308 int total_x,
00309 int total_w,
00310 BC_Pixmap *src,
00311 BC_Pixmap *dst = 0);
00312 void draw_3segmentv(int x,
00313 int y,
00314 int h,
00315 int total_y,
00316 int total_h,
00317 BC_Pixmap *src,
00318 BC_Pixmap *dst = 0);
00319 void draw_3segmentv(int x,
00320 int y,
00321 int h,
00322 int total_y,
00323 int total_h,
00324 VFrame *src,
00325 BC_Pixmap *dst = 0);
00326
00327 void draw_3segmenth(int x,
00328 int y,
00329 int w,
00330 VFrame *image,
00331 BC_Pixmap *pixmap = 0);
00332 void draw_3segmenth(int x,
00333 int y,
00334 int w,
00335 BC_Pixmap *src,
00336 BC_Pixmap *dst = 0);
00337 void draw_3segmentv(int x,
00338 int y,
00339 int h,
00340 BC_Pixmap *src,
00341 BC_Pixmap *dst = 0);
00342 void draw_3segmentv(int x,
00343 int y,
00344 int h,
00345 VFrame *src,
00346 BC_Pixmap *dst = 0);
00347 void draw_9segment(int x,
00348 int y,
00349 int w,
00350 int h,
00351 VFrame *src,
00352 BC_Pixmap *dst = 0);
00353 void draw_9segment(int x,
00354 int y,
00355 int w,
00356 int h,
00357 BC_Pixmap *src,
00358 BC_Pixmap *dst = 0);
00359 void draw_3d_box(int x,
00360 int y,
00361 int w,
00362 int h,
00363 int light1,
00364 int light2,
00365 int middle,
00366 int shadow1,
00367 int shadow2,
00368 BC_Pixmap *pixmap = 0);
00369 void draw_3d_border(int x, int y, int w, int h,
00370 int light1, int light2, int shadow1, int shadow2);
00371 void draw_colored_box(int x, int y, int w, int h, int down, int highlighted);
00372 void draw_check(int x, int y);
00373 void draw_triangle_down_flat(int x, int y, int w, int h);
00374 void draw_triangle_up(int x, int y, int w, int h,
00375 int light1, int light2, int middle, int shadow1, int shadow2);
00376 void draw_triangle_down(int x, int y, int w, int h,
00377 int light1, int light2, int middle, int shadow1, int shadow2);
00378 void draw_triangle_left(int x, int y, int w, int h,
00379 int light1, int light2, int middle, int shadow1, int shadow2);
00380 void draw_triangle_right(int x, int y, int w, int h,
00381 int light1, int light2, int middle, int shadow1, int shadow2);
00382
00383 void set_opaque();
00384 void set_inverse();
00385 void set_background(VFrame *bitmap);
00386
00387 void set_title(char *text);
00388 char* get_title();
00389 void start_video();
00390 void stop_video();
00391 int video_is_on();
00392 void set_done(int return_value);
00393
00394 BC_Bitmap* new_bitmap(int w, int h, int color_model = -1);
00395
00396 void draw_bitmap(BC_Bitmap *bitmap,
00397 int dont_wait,
00398 int dest_x = 0,
00399 int dest_y = 0,
00400 int dest_w = 0,
00401 int dest_h = 0,
00402 int src_x = 0,
00403 int src_y = 0,
00404 int src_w = 0,
00405 int src_h = 0,
00406 BC_Pixmap *pixmap = 0);
00407 void draw_pixel(int x, int y, BC_Pixmap *pixmap = 0);
00408
00409 void draw_pixmap(BC_Pixmap *pixmap,
00410 int dest_x = 0,
00411 int dest_y = 0,
00412 int dest_w = -1,
00413 int dest_h = -1,
00414 int src_x = 0,
00415 int src_y = 0,
00416 BC_Pixmap *dst = 0);
00417
00418 void draw_vframe(VFrame *frame,
00419 int dest_x = 0,
00420 int dest_y = 0,
00421 int dest_w = -1,
00422 int dest_h = -1,
00423 int src_x = 0,
00424 int src_y = 0,
00425 int src_w = 0,
00426 int src_h = 0,
00427 BC_Pixmap *pixmap = 0);
00428 void draw_border(char *text, int x, int y, int w, int h);
00429
00430 void draw_top_background(BC_WindowBase *parent_window, int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
00431 void draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h);
00432 void draw_background(int x, int y, int w, int h);
00433 void draw_tiles(BC_Pixmap *tile,
00434 int origin_x,
00435 int origin_y,
00436 int x,
00437 int y,
00438 int w,
00439 int h);
00440 void slide_left(int distance);
00441 void slide_right(int distance);
00442 void slide_up(int distance);
00443 void slide_down(int distance);
00444
00445 int cycle_textboxes(int amount);
00446
00447 int raise_window(int do_flush = 1);
00448 int set_tooltips(int tooltips_enabled);
00449 int resize_window(int w, int h);
00450 int reposition_widget(int x, int y, int w = -1, int h = -1);
00451 int reposition_window(int x, int y, int w = -1, int h = -1);
00452
00453
00454 int set_repeat(int64_t duration);
00455
00456 int unset_repeat(int64_t duration);
00457 int set_tooltip(char *text);
00458 int show_tooltip(int w = -1, int h = -1);
00459 int hide_tooltip();
00460 int set_icon(VFrame *data);
00461 int load_defaults(Defaults *defaults);
00462 int save_defaults(Defaults *defaults);
00463
00464 #ifdef HAVE_LIBXXF86VM
00465
00466 void closest_vm(int *vm, int *width, int *height);
00467 void scale_vm(int vm);
00468 void restore_vm();
00469 #endif
00470
00471
00472 int test_keypress;
00473
00474
00475 private:
00476
00477 virtual int create_window(BC_WindowBase *parent_window,
00478 char *title,
00479 int x,
00480 int y,
00481 int w,
00482 int h,
00483 int minw,
00484 int minh,
00485 int allow_resize,
00486 int private_color,
00487 int hide,
00488 int bg_color,
00489 char *display_name,
00490 int window_type,
00491 BC_Pixmap *bg_pixmap,
00492 int group_it);
00493
00494 static Display* init_display(char *display_name);
00495 virtual int initialize();
00496 int get_atoms();
00497 void init_cursors();
00498 int init_colors();
00499 int init_window_shape();
00500 static int evaluate_color_model(int client_byte_order, int server_byte_order, int depth);
00501 int create_private_colors();
00502 int create_color(int color);
00503 int create_shared_colors();
00504
00505 int get_single_text_width(int font, char *text, int length);
00506 int allocate_color_table();
00507 int init_gc();
00508 int init_fonts();
00509 int get_color_rgb8(int color);
00510 int64_t get_color_rgb16(int color);
00511 int64_t get_color_bgr16(int color);
00512 int64_t get_color_bgr24(int color);
00513 XFontStruct* get_font_struct(int font);
00514 #ifdef HAVE_XFT
00515 XftFont* get_xft_struct(int font);
00516 #endif
00517 Cursor get_cursor_struct(int cursor);
00518 XFontSet get_fontset(int font);
00519 XFontSet get_curr_fontset(void);
00520 void set_fontset(int font);
00521 int dispatch_event();
00522
00523 int get_key_masks(XEvent *event);
00524
00525 int trigger_tooltip();
00526 int untrigger_tooltip();
00527 void draw_tooltip();
00528 int arm_repeat(int64_t duration);
00529
00530 int unset_all_repeaters();
00531
00532
00533 XEvent* get_event();
00534
00535 int get_event_count();
00536
00537 void put_event(XEvent *event);
00538
00539
00540 int dispatch_resize_event(int w, int h);
00541 int dispatch_focus_in();
00542 int dispatch_focus_out();
00543 int dispatch_motion_event();
00544 int dispatch_keypress_event();
00545 int dispatch_repeat_event(int64_t duration);
00546 int dispatch_repeat_event_master(int64_t duration);
00547 int dispatch_button_press();
00548 int dispatch_button_release();
00549 int dispatch_cursor_leave();
00550 int dispatch_cursor_enter();
00551 int dispatch_translation_event();
00552 int dispatch_drag_start();
00553 int dispatch_drag_motion();
00554 int dispatch_drag_stop();
00555 int dispatch_expose_event();
00556
00557
00558 int grab_port_id(BC_WindowBase *window, int color_model);
00559
00560 int find_next_textbox(BC_WindowBase **first_textbox, BC_WindowBase **next_textbox, int &result);
00561 int find_prev_textbox(BC_WindowBase **last_textbox, BC_WindowBase **prev_textbox, int &result);
00562
00563
00564
00565 void translate_coordinates(Window src_w,
00566 Window dest_w,
00567 int src_x,
00568 int src_y,
00569 int *dest_x_return,
00570 int *dest_y_return);
00571
00572
00573 BC_WindowBase* top_level;
00574
00575 BC_WindowBase* parent_window;
00576
00577 BC_SubWindowList* subwindows;
00578
00579 int x, y, w, h;
00580
00581 int light1, light2, medium, dark1, dark2, bg_color;
00582
00583 int window_type;
00584
00585 BC_MenuBar* active_menubar;
00586
00587 BC_PopupMenu* active_popup_menu;
00588
00589 BC_WindowBase* active_subwindow;
00590
00591
00592 int allow_resize;
00593 int hidden, private_color, bits_per_pixel, color_model;
00594 int server_byte_order, client_byte_order;
00595
00596 int total_colors;
00597
00598 int current_color_value, current_color_pixel;
00599
00600 int color_table[256][2];
00601
00602 int video_on;
00603
00604 int done;
00605
00606 int return_value;
00607
00608 int motion_events, last_motion_x, last_motion_y;
00609
00610 Window last_motion_win;
00611
00612 int resize_events, last_resize_w, last_resize_h;
00613 int translation_events, last_translate_x, last_translate_y;
00614 int prev_x, prev_y;
00615
00616
00617 int translation_count;
00618 int x_correction, y_correction;
00619
00620 int ctrl_mask, shift_mask, alt_mask;
00621
00622 int cursor_x, cursor_y;
00623
00624 int button_down, button_number;
00625
00626 uint64_t button_time1, button_time2;
00627 int double_click;
00628
00629 int button_pressed;
00630
00631 int key_pressed;
00632
00633 int toggle_value;
00634 int toggle_drag;
00635
00636 int has_focus;
00637
00638 static BC_Resources resources;
00639
00640 ArrayList<BC_Repeater*> repeaters;
00641
00642
00643 char tooltip_text[BCTEXTLEN];
00644
00645 int tooltip_on;
00646
00647
00648
00649 BC_Popup *tooltip_popup;
00650
00651 int tooltip_done;
00652
00653 int persistant_tooltip;
00654
00655
00656
00657
00658 XFontSet largefontset, mediumfontset, smallfontset, curr_fontset;
00659
00660
00661 int current_font;
00662 XFontStruct *largefont, *mediumfont, *smallfont;
00663
00664
00665
00666
00667
00668 void *xft_drawable;
00669 void *largefont_xft, *mediumfont_xft, *smallfont_xft;
00670
00671
00672 int64_t current_color;
00673
00674 int drag_x, drag_y;
00675
00676 int drag_x1, drag_x2, drag_y1, drag_y2;
00677
00678 int is_dragging;
00679
00680 int shared_bg_pixmap;
00681 char title[BCTEXTLEN];
00682
00683
00684 int screen;
00685 Window rootwin;
00686
00687 Window event_win, drag_win;
00688 Visual *vis;
00689 Colormap cmap;
00690
00691 Display *display;
00692
00693 Display *event_display;
00694 Window win;
00695 Pixmap pixmap;
00696 #ifdef HAVE_GL
00697 GLXContext gl_context;
00698 #endif
00699 static Mutex opengl_lock;
00700 int window_lock;
00701 GC gc;
00702
00703 int default_depth;
00704 Atom DelWinXAtom;
00705 Atom ProtoXAtom;
00706 Atom RepeaterXAtom;
00707 Atom SetDoneXAtom;
00708
00709 int prev_cursor;
00710
00711 int hourglass_total;
00712
00713 int current_cursor;
00714 Cursor arrow_cursor;
00715 Cursor cross_cursor;
00716 Cursor ibeam_cursor;
00717 Cursor vseparate_cursor;
00718 Cursor hseparate_cursor;
00719 Cursor move_cursor;
00720 Cursor temp_cursor;
00721 Cursor left_cursor;
00722 Cursor right_cursor;
00723 Cursor upright_arrow_cursor;
00724 Cursor upleft_resize_cursor;
00725 Cursor upright_resize_cursor;
00726 Cursor downleft_resize_cursor;
00727 Cursor downright_resize_cursor;
00728 Cursor hourglass_cursor;
00729
00730 int xvideo_port_id;
00731 ArrayList<BC_ResizeCall*> resize_history;
00732
00733 BC_Pixmap *bg_pixmap;
00734
00735 BC_Popup *icon_window;
00736 BC_Pixmap *icon_pixmap;
00737
00738 BC_Bitmap *temp_bitmap;
00739
00740 BC_Clipboard *clipboard;
00741 #ifdef HAVE_LIBXXF86VM
00742
00743 int vm_switched;
00744 XF86VidModeModeInfo orig_modeline;
00745 #endif
00746
00747
00748 ArrayList<XEvent*> common_events;
00749
00750
00751
00752
00753 Mutex *event_lock;
00754 Condition *event_condition;
00755 BC_WindowEvents *event_thread;
00756 int is_deleting;
00757 };
00758
00759
00760
00761 #endif