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 "bcpbuffer.inc"
00033 #include "bcpixmap.inc"
00034 #include "bcpopup.inc"
00035 #include "bcpopupmenu.inc"
00036 #include "bcpot.inc"
00037 #include "bcprogress.inc"
00038 #include "bcrelocatablewidget.h"
00039 #include "bcrepeater.inc"
00040 #include "bcresources.inc"
00041 #include "bcscrollbar.inc"
00042 #include "bcslider.inc"
00043 #include "bcsubwindow.inc"
00044 #include "bcsynchronous.inc"
00045 #include "bctextbox.inc"
00046 #include "bctimer.inc"
00047 #include "bctitle.inc"
00048 #include "bctoggle.inc"
00049 #include "bctumble.inc"
00050 #include "bcwidgetgrid.inc"
00051 #include "bcwindow.inc"
00052 #include "bcwindowbase.inc"
00053 #include "bcwindowevents.inc"
00054 #include "condition.inc"
00055 #include "bchash.inc"
00056 #include "linklist.h"
00057 #include "mutex.inc"
00058 #include "vframe.inc"
00059
00060
00061 #include <stdint.h>
00062 #include <stdio.h>
00063 #include <stdlib.h>
00064 #include <X11/Xatom.h>
00065 #ifdef HAVE_XFT
00066 #include <X11/Xft/Xft.h>
00067 #endif
00068 #include <X11/Xlib.h>
00069 #include <X11/Xutil.h>
00070 #include <X11/keysym.h>
00071 #include <X11/cursorfont.h>
00072 #ifdef HAVE_LIBXXF86VM
00073 #include <X11/extensions/xf86vmode.h>
00074 #endif
00075 #ifdef HAVE_GL
00076 #include <GL/glx.h>
00077 #endif
00078
00079
00080
00081 #ifdef HAVE_GL
00082
00083 #endif
00084
00085
00086
00087
00088 typedef struct {
00089 int type;
00090 unsigned long serial;
00091 Bool send_event;
00092 Display *display;
00093 Window window;
00094 Atom message_type;
00095 int format;
00096 union {
00097 char b[20];
00098 short s[10];
00099 long l[5];
00100 } data;
00101 } xatom_event;
00102
00103
00104 class BC_ResizeCall
00105 {
00106 public:
00107 BC_ResizeCall(int w, int h);
00108 int w, h;
00109 };
00110
00111
00112
00113 class BC_WindowBase : public BC_RelocatableWidget
00114 {
00115 public:
00116 BC_WindowBase();
00117 virtual ~BC_WindowBase();
00118
00119 friend class BC_Bar;
00120 friend class BC_Bitmap;
00121 friend class BC_Button;
00122 friend class BC_GenericButton;
00123 friend class BC_Capture;
00124 friend class BC_Clipboard;
00125 friend class BC_DragWindow;
00126 friend class BC_FileBox;
00127 friend class BC_FullScreen;
00128 friend class BC_ListBox;
00129 friend class BC_Menu;
00130 friend class BC_MenuBar;
00131 friend class BC_MenuItem;
00132 friend class BC_MenuPopup;
00133 friend class BC_Meter;
00134 friend class BC_Pan;
00135 friend class BC_PBuffer;
00136 friend class BC_Pixmap;
00137 friend class BC_PixmapSW;
00138 friend class BC_Popup;
00139 friend class BC_PopupMenu;
00140 friend class BC_Pot;
00141 friend class BC_ProgressBar;
00142 friend class BC_Repeater;
00143 friend class BC_Resources;
00144 friend class BC_ScrollBar;
00145 friend class BC_Slider;
00146 friend class BC_SubWindow;
00147 friend class BC_Synchronous;
00148 friend class BC_TextBox;
00149 friend class BC_Title;
00150 friend class BC_Toggle;
00151 friend class BC_Tumbler;
00152 friend class BC_Window;
00153 friend class BC_WindowEvents;
00154
00155
00156 int run_window();
00157
00158 virtual int close_event();
00159 virtual int resize_event(int w, int h);
00160 virtual int repeat_event(int64_t duration) { return 0; };
00161 virtual int focus_in_event() { return 0; };
00162 virtual int focus_out_event() { return 0; };
00163 virtual int button_press_event() { return 0; };
00164 virtual int button_release_event() { return 0; };
00165 virtual int cursor_motion_event() { return 0; };
00166 virtual int cursor_leave_event();
00167 virtual int cursor_enter_event();
00168 virtual int keypress_event() { return 0; };
00169 virtual int translation_event() { return 0; };
00170 virtual int drag_start_event() { return 0; };
00171 virtual int drag_motion_event() { return 0; };
00172 virtual int drag_stop_event() { return 0; };
00173 virtual int uses_text() { return 0; };
00174
00175 virtual int expose_event() { return 0; };
00176
00177
00178 int accel_available(int color_model, int lock_it);
00179
00180 int get_color_model();
00181
00182 int get_color(int64_t color);
00183
00184 int64_t get_color();
00185 int show_window(int flush = 1);
00186 int hide_window(int flush = 1);
00187 int get_hidden();
00188 int get_video_on();
00189
00190
00191 int get_deleting();
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 void enable_opengl();
00204 void disable_opengl();
00205 void flip_opengl();
00206
00207
00208
00209 unsigned int get_shader(char *title, int *got_it);
00210 void put_shader(unsigned int handle, char *title);
00211
00212
00213 int flash(int x, int y, int w, int h, int flush = 1);
00214 int flash(int flush = 1);
00215 void flush();
00216 void sync_display();
00217
00218 int lock_window(char *location = 0);
00219 int unlock_window();
00220 int get_window_lock();
00221
00222 BC_MenuBar* add_menubar(BC_MenuBar *menu_bar);
00223 BC_WindowBase* add_subwindow(BC_WindowBase *subwindow);
00224 BC_WindowBase* add_tool(BC_WindowBase *subwindow);
00225 BC_WidgetGrid* add_widgetgrid(BC_WidgetGrid *widgetgrid);
00226
00227
00228 static BC_Resources* get_resources();
00229
00230 static BC_Synchronous* get_synchronous();
00231
00232
00233 virtual int get_w();
00234 virtual int get_h();
00235 virtual int get_x();
00236 virtual int get_y();
00237 virtual int reposition_widgets(){ printf("foo1"); return 0; }
00238 int get_root_w(int ignore_dualhead = 0, int lock_display = 0);
00239 int get_root_h(int lock_display);
00240
00241 int get_abs_cursor_x(int lock_window);
00242 int get_abs_cursor_y(int lock_window);
00243 int get_relative_cursor_x();
00244 int get_relative_cursor_y();
00245
00246
00247 int get_cursor_over_window();
00248
00249 int match_window(Window win);
00250
00251
00252 int get_button_down();
00253
00254 int get_buttonpress();
00255 int get_has_focus();
00256 int get_dragging();
00257 int get_keypress();
00258
00259 int get_cursor_x();
00260 int get_cursor_y();
00261
00262 int get_drag_x();
00263 int get_drag_y();
00264 int relative_cursor_x(BC_WindowBase *pov);
00265 int relative_cursor_y(BC_WindowBase *pov);
00266 int alt_down();
00267 int shift_down();
00268 int ctrl_down();
00269 int get_double_click();
00270
00271 int get_x2();
00272 int get_y2();
00273 int get_bg_color();
00274 BC_Pixmap* get_bg_pixmap();
00275 int get_text_ascent(int font);
00276 int get_text_descent(int font);
00277 int get_text_height(int font, char *text = 0);
00278 int get_text_width(int font, char *text, int length = -1);
00279 BC_Clipboard* get_clipboard();
00280 void set_dragging(int value);
00281 int set_w(int w);
00282 int set_h(int h);
00283 BC_WindowBase* get_top_level();
00284 BC_WindowBase* get_parent();
00285
00286 int is_event_win();
00287 int cursor_inside();
00288
00289 virtual int activate();
00290
00291 virtual int deactivate();
00292 void set_active_subwindow(BC_WindowBase *subwindow);
00293
00294 int get_toggle_value();
00295
00296 int get_toggle_drag();
00297
00298
00299 void set_color(int64_t color);
00300 int get_bgcolor();
00301 void set_font(int font);
00302
00303
00304 void set_cursor(int cursor, int override = 0);
00305
00306 void set_x_cursor(int cursor);
00307 int get_cursor();
00308
00309 void unhide_cursor();
00310
00311 void update_video_cursor();
00312
00313
00314
00315 void start_hourglass();
00316 void stop_hourglass();
00317
00318
00319 void start_hourglass_recursive();
00320 void stop_hourglass_recursive();
00321
00322
00323 void copy_area(int x1, int y1, int x2, int y2, int w, int h, BC_Pixmap *pixmap = 0);
00324 void clear_box(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
00325 void draw_box(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
00326 void draw_circle(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
00327 void draw_disc(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
00328 void draw_text(int x, int y, char *text, int length = -1, BC_Pixmap *pixmap = 0);
00329 void draw_xft_text(int x,
00330 int y,
00331 char *text,
00332 int length,
00333 BC_Pixmap *pixmap,
00334 int x2,
00335 int k,
00336 int y2,
00337 int j,
00338 int i);
00339 void draw_center_text(int x, int y, char *text, int length = -1);
00340 void draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap = 0);
00341 void draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap = 0);
00342 void draw_rectangle(int x, int y, int w, int h);
00343 void draw_3segment(int x,
00344 int y,
00345 int w,
00346 int h,
00347 BC_Pixmap *left_image,
00348 BC_Pixmap *mid_image,
00349 BC_Pixmap *right_image,
00350 BC_Pixmap *pixmap = 0);
00351 void draw_3segment(int x,
00352 int y,
00353 int w,
00354 int h,
00355 VFrame *left_image,
00356 VFrame *mid_image,
00357 VFrame *right_image,
00358 BC_Pixmap *pixmap = 0);
00359
00360 void draw_3segmenth(int x,
00361 int y,
00362 int w,
00363 int total_x,
00364 int total_w,
00365 VFrame *image,
00366 BC_Pixmap *pixmap);
00367 void draw_3segmenth(int x,
00368 int y,
00369 int w,
00370 int total_x,
00371 int total_w,
00372 BC_Pixmap *src,
00373 BC_Pixmap *dst = 0);
00374 void draw_3segmentv(int x,
00375 int y,
00376 int h,
00377 int total_y,
00378 int total_h,
00379 BC_Pixmap *src,
00380 BC_Pixmap *dst = 0);
00381 void draw_3segmentv(int x,
00382 int y,
00383 int h,
00384 int total_y,
00385 int total_h,
00386 VFrame *src,
00387 BC_Pixmap *dst = 0);
00388
00389 void draw_3segmenth(int x,
00390 int y,
00391 int w,
00392 VFrame *image,
00393 BC_Pixmap *pixmap = 0);
00394 void draw_3segmenth(int x,
00395 int y,
00396 int w,
00397 BC_Pixmap *src,
00398 BC_Pixmap *dst = 0);
00399 void draw_3segmentv(int x,
00400 int y,
00401 int h,
00402 BC_Pixmap *src,
00403 BC_Pixmap *dst = 0);
00404 void draw_3segmentv(int x,
00405 int y,
00406 int h,
00407 VFrame *src,
00408 BC_Pixmap *dst = 0);
00409 void draw_9segment(int x,
00410 int y,
00411 int w,
00412 int h,
00413 VFrame *src,
00414 BC_Pixmap *dst = 0);
00415 void draw_9segment(int x,
00416 int y,
00417 int w,
00418 int h,
00419 BC_Pixmap *src,
00420 BC_Pixmap *dst = 0);
00421 void draw_3d_box(int x,
00422 int y,
00423 int w,
00424 int h,
00425 int light1,
00426 int light2,
00427 int middle,
00428 int shadow1,
00429 int shadow2,
00430 BC_Pixmap *pixmap = 0);
00431 void draw_3d_border(int x, int y, int w, int h,
00432 int light1, int light2, int shadow1, int shadow2);
00433 void draw_colored_box(int x, int y, int w, int h, int down, int highlighted);
00434 void draw_check(int x, int y);
00435 void draw_triangle_down_flat(int x, int y, int w, int h);
00436 void draw_triangle_up(int x, int y, int w, int h,
00437 int light1, int light2, int middle, int shadow1, int shadow2);
00438 void draw_triangle_down(int x, int y, int w, int h,
00439 int light1, int light2, int middle, int shadow1, int shadow2);
00440 void draw_triangle_left(int x, int y, int w, int h,
00441 int light1, int light2, int middle, int shadow1, int shadow2);
00442 void draw_triangle_right(int x, int y, int w, int h,
00443 int light1, int light2, int middle, int shadow1, int shadow2);
00444
00445 void set_opaque();
00446 void set_inverse();
00447 void set_background(VFrame *bitmap);
00448
00449 void set_title(char *text);
00450 char* get_title();
00451 void start_video();
00452 void stop_video();
00453 int get_id();
00454 void set_done(int return_value);
00455
00456 BC_Bitmap* new_bitmap(int w, int h, int color_model = -1);
00457
00458 void draw_bitmap(BC_Bitmap *bitmap,
00459 int dont_wait,
00460 int dest_x = 0,
00461 int dest_y = 0,
00462 int dest_w = 0,
00463 int dest_h = 0,
00464 int src_x = 0,
00465 int src_y = 0,
00466 int src_w = 0,
00467 int src_h = 0,
00468 BC_Pixmap *pixmap = 0);
00469 void draw_pixel(int x, int y, BC_Pixmap *pixmap = 0);
00470
00471 void draw_pixmap(BC_Pixmap *pixmap,
00472 int dest_x = 0,
00473 int dest_y = 0,
00474 int dest_w = -1,
00475 int dest_h = -1,
00476 int src_x = 0,
00477 int src_y = 0,
00478 BC_Pixmap *dst = 0);
00479
00480 void draw_vframe(VFrame *frame,
00481 int dest_x = 0,
00482 int dest_y = 0,
00483 int dest_w = -1,
00484 int dest_h = -1,
00485 int src_x = 0,
00486 int src_y = 0,
00487 int src_w = 0,
00488 int src_h = 0,
00489 BC_Pixmap *pixmap = 0);
00490 void draw_border(char *text, int x, int y, int w, int h);
00491
00492 void draw_top_background(BC_WindowBase *parent_window, int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
00493 void draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h);
00494 void draw_background(int x, int y, int w, int h);
00495 void draw_tiles(BC_Pixmap *tile,
00496 int origin_x,
00497 int origin_y,
00498 int x,
00499 int y,
00500 int w,
00501 int h);
00502 void slide_left(int distance);
00503 void slide_right(int distance);
00504 void slide_up(int distance);
00505 void slide_down(int distance);
00506
00507 int cycle_textboxes(int amount);
00508
00509 int raise_window(int do_flush = 1);
00510 int set_tooltips(int tooltips_enabled);
00511 int resize_window(int w, int h);
00512 int reposition_widget(int x, int y, int w = -1, int h = -1);
00513 int reposition_window(int x, int y, int w = -1, int h = -1);
00514
00515
00516 int set_repeat(int64_t duration);
00517
00518 int unset_repeat(int64_t duration);
00519 int set_tooltip(char *text);
00520 int show_tooltip(int w = -1, int h = -1);
00521 int hide_tooltip();
00522 int set_icon(VFrame *data);
00523 int load_defaults(BC_Hash *defaults);
00524 int save_defaults(BC_Hash *defaults);
00525
00526 #ifdef HAVE_LIBXXF86VM
00527
00528 void closest_vm(int *vm, int *width, int *height);
00529 void scale_vm(int vm);
00530 void restore_vm();
00531 #endif
00532
00533
00534 int test_keypress;
00535
00536
00537 private:
00538
00539 virtual int create_window(BC_WindowBase *parent_window,
00540 char *title,
00541 int x,
00542 int y,
00543 int w,
00544 int h,
00545 int minw,
00546 int minh,
00547 int allow_resize,
00548 int private_color,
00549 int hide,
00550 int bg_color,
00551 char *display_name,
00552 int window_type,
00553 BC_Pixmap *bg_pixmap,
00554 int group_it);
00555
00556 static Display* init_display(char *display_name);
00557
00558 Display* get_display();
00559 int get_screen();
00560 virtual int initialize();
00561 int get_atoms();
00562
00563 virtual int recieve_custom_xatoms(xatom_event *event);
00564
00565 void init_cursors();
00566 int init_colors();
00567 int init_window_shape();
00568 static int evaluate_color_model(int client_byte_order, int server_byte_order, int depth);
00569 int create_private_colors();
00570 int create_color(int color);
00571 int create_shared_colors();
00572
00573 int get_single_text_width(int font, char *text, int length);
00574 int allocate_color_table();
00575 int init_gc();
00576 int init_fonts();
00577 void init_xft();
00578 int get_color_rgb8(int color);
00579 int64_t get_color_rgb16(int color);
00580 int64_t get_color_bgr16(int color);
00581 int64_t get_color_bgr24(int color);
00582 XFontStruct* get_font_struct(int font);
00583 #ifdef HAVE_XFT
00584 XftFont* get_xft_struct(int font);
00585 #endif
00586 Cursor get_cursor_struct(int cursor);
00587 XFontSet get_fontset(int font);
00588 XFontSet get_curr_fontset(void);
00589 void set_fontset(int font);
00590 int dispatch_event();
00591
00592 int get_key_masks(XEvent *event);
00593
00594 int trigger_tooltip();
00595 int untrigger_tooltip();
00596 void draw_tooltip();
00597 int arm_repeat(int64_t duration);
00598
00599 int unset_all_repeaters();
00600
00601
00602 XEvent* get_event();
00603
00604 int get_event_count();
00605
00606 void put_event(XEvent *event);
00607
00608
00609 int dispatch_resize_event(int w, int h);
00610 int dispatch_focus_in();
00611 int dispatch_focus_out();
00612 int dispatch_motion_event();
00613 int dispatch_keypress_event();
00614 int dispatch_repeat_event(int64_t duration);
00615 int dispatch_repeat_event_master(int64_t duration);
00616 int dispatch_button_press();
00617 int dispatch_button_release();
00618 int dispatch_cursor_leave();
00619 int dispatch_cursor_enter();
00620 int dispatch_translation_event();
00621 int dispatch_drag_start();
00622 int dispatch_drag_motion();
00623 int dispatch_drag_stop();
00624 int dispatch_expose_event();
00625
00626
00627 int grab_port_id(BC_WindowBase *window, int color_model);
00628
00629 int find_next_textbox(BC_WindowBase **first_textbox, BC_WindowBase **next_textbox, int &result);
00630 int find_prev_textbox(BC_WindowBase **last_textbox, BC_WindowBase **prev_textbox, int &result);
00631
00632
00633 void translate_coordinates(Window src_w,
00634 Window dest_w,
00635 int src_x,
00636 int src_y,
00637 int *dest_x_return,
00638 int *dest_y_return);
00639
00640
00641 BC_WindowBase* top_level;
00642
00643 BC_WindowBase* parent_window;
00644
00645 BC_SubWindowList* subwindows;
00646
00647 BC_WidgetGridList* widgetgrids;
00648
00649 int x, y, w, h;
00650
00651 int light1, light2, medium, dark1, dark2, bg_color;
00652
00653 int window_type;
00654
00655 BC_MenuBar* active_menubar;
00656
00657 BC_PopupMenu* active_popup_menu;
00658
00659 BC_WindowBase* active_subwindow;
00660
00661
00662 int allow_resize;
00663 int hidden, private_color, bits_per_pixel, color_model;
00664 int server_byte_order, client_byte_order;
00665
00666 int total_colors;
00667
00668 int current_color_value, current_color_pixel;
00669
00670 int color_table[256][2];
00671
00672 int video_on;
00673
00674 int done;
00675
00676 int return_value;
00677
00678 int motion_events, last_motion_x, last_motion_y;
00679
00680 Window last_motion_win;
00681
00682 int resize_events, last_resize_w, last_resize_h;
00683 int translation_events, last_translate_x, last_translate_y;
00684 int prev_x, prev_y;
00685
00686