00001 #include "bcbitmap.h"
00002 #include "bcclipboard.h"
00003 #include "bcdisplayinfo.h"
00004 #include "bcmenubar.h"
00005 #include "bcpixmap.h"
00006 #include "bcpopup.h"
00007 #include "bcpopupmenu.h"
00008 #include "bcrepeater.h"
00009 #include "bcresources.h"
00010 #include "bcsignals.h"
00011 #include "bcsubwindow.h"
00012 #include "bcsynchronous.h"
00013 #include "bctimer.h"
00014 #include "bcwidgetgrid.h"
00015 #include "bcwindowbase.h"
00016 #include "bcwindowevents.h"
00017 #include "colormodels.h"
00018 #include "colors.h"
00019 #include "condition.h"
00020 #include "cursors.h"
00021 #include "bchash.h"
00022 #include "fonts.h"
00023 #include "keys.h"
00024 #include "language.h"
00025 #include "mutex.h"
00026 #include "sizes.h"
00027 #include "vframe.h"
00028
00029 #ifdef HAVE_GL
00030 #include <GL/gl.h>
00031 #endif
00032 #include <string.h>
00033 #include <unistd.h>
00034
00035 #include <X11/extensions/Xvlib.h>
00036 #include <X11/extensions/shape.h>
00037
00038
00039 BC_ResizeCall::BC_ResizeCall(int w, int h)
00040 {
00041 this->w = w;
00042 this->h = h;
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 BC_Resources BC_WindowBase::resources;
00056
00057 Window XGroupLeader = 0;
00058
00059 BC_WindowBase::BC_WindowBase()
00060 {
00061
00062 BC_WindowBase::initialize();
00063 }
00064
00065 BC_WindowBase::~BC_WindowBase()
00066 {
00067 #ifdef HAVE_LIBXXF86VM
00068 if(window_type == VIDMODE_SCALED_WINDOW && vm_switched)
00069 {
00070 restore_vm();
00071 }
00072 #endif
00073
00074 hide_tooltip();
00075 if(window_type != MAIN_WINDOW)
00076 {
00077 if(top_level->active_menubar == this) top_level->active_menubar = 0;
00078 if(top_level->active_popup_menu == this) top_level->active_popup_menu = 0;
00079 if(top_level->active_subwindow == this) top_level->active_subwindow = 0;
00080
00081 parent_window->subwindows->remove(this);
00082 }
00083
00084
00085
00086 is_deleting = 1;
00087 if(subwindows)
00088 {
00089 while(subwindows->total)
00090 {
00091
00092 delete subwindows->values[0];
00093 }
00094 delete subwindows;
00095 }
00096
00097 if(widgetgrids)
00098 {
00099 while (widgetgrids->total)
00100 {
00101 delete widgetgrids->last();
00102 widgetgrids->remove();
00103 }
00104 delete widgetgrids;
00105 }
00106
00107
00108 delete pixmap;
00109
00110
00111 #ifdef HAVE_GL
00112 if(!gl_win_context || !get_resources()->get_synchronous())
00113 #endif
00114 XDestroyWindow(top_level->display, win);
00115
00116 if(bg_pixmap && !shared_bg_pixmap) delete bg_pixmap;
00117 if(icon_pixmap) delete icon_pixmap;
00118 if(temp_bitmap) delete temp_bitmap;
00119
00120
00121
00122
00123
00124 if(window_type == MAIN_WINDOW)
00125 {
00126 XFreeGC(display, gc);
00127 #ifdef HAVE_XFT
00128 if(largefont_xft)
00129 XftFontClose (display, (XftFont*)largefont_xft);
00130 if(mediumfont_xft)
00131 XftFontClose (display, (XftFont*)mediumfont_xft);
00132 if(smallfont_xft)
00133 XftFontClose (display, (XftFont*)smallfont_xft);
00134 #endif
00135 flush();
00136
00137
00138 #ifdef HAVE_GL
00139 if(!gl_win_context || !get_resources()->get_synchronous())
00140 #endif
00141 XCloseDisplay(display);
00142 clipboard->stop_clipboard();
00143 delete clipboard;
00144 }
00145 else
00146 {
00147 flush();
00148 }
00149
00150
00151
00152
00153 #ifdef HAVE_GL
00154 if(gl_win_context && get_resources()->get_synchronous())
00155 {
00156 printf("BC_WindowBase::~BC_WindowBase window deleted but opengl deletion is not\n"
00157 "implemented for BC_Pixmap.\n");
00158 get_resources()->get_synchronous()->delete_window(this);
00159 }
00160 #endif
00161
00162 resize_history.remove_all_objects();
00163 common_events.remove_all_objects();
00164 delete event_lock;
00165 delete event_condition;
00166
00167 UNSET_ALL_LOCKS(this)
00168 }
00169
00170 int BC_WindowBase::initialize()
00171 {
00172 test_keypress = 0;
00173 is_deleting = 0;
00174 window_lock = 0;
00175 x = 0;
00176 y = 0;
00177 w = 0;
00178 h = 0;
00179 bg_color = -1;
00180 top_level = 0;
00181 parent_window = 0;
00182 subwindows = 0;
00183 widgetgrids = 0;
00184 xvideo_port_id = -1;
00185 video_on = 0;
00186 motion_events = 0;
00187 resize_events = 0;
00188 translation_events = 0;
00189 ctrl_mask = shift_mask = alt_mask = 0;
00190 cursor_x = cursor_y = button_number = 0;
00191 button_down = 0;
00192 button_pressed = 0;
00193 button_time1 = button_time2 = 0;
00194 double_click = 0;
00195 last_motion_win = 0;
00196 key_pressed = 0;
00197 active_menubar = 0;
00198 active_popup_menu = 0;
00199 active_subwindow = 0;
00200 pixmap = 0;
00201 bg_pixmap = 0;
00202 tooltip_text[0] = 0;
00203 persistant_tooltip = 0;
00204
00205 tooltip_popup = 0;
00206 tooltip_done = 0;
00207 current_font = MEDIUMFONT;
00208 current_color = BLACK;
00209 current_cursor = ARROW_CURSOR;
00210 hourglass_total = 0;
00211 is_dragging = 0;
00212 shared_bg_pixmap = 0;
00213 icon_pixmap = 0;
00214 window_type = MAIN_WINDOW;
00215 translation_count = 0;
00216 x_correction = y_correction = 0;
00217 temp_bitmap = 0;
00218 tooltip_on = 0;
00219 temp_cursor = 0;
00220 toggle_value = 0;
00221 toggle_drag = 0;
00222 has_focus = 0;
00223 is_hourglass = 0;
00224 is_transparent = 0;
00225 #ifdef HAVE_LIBXXF86VM
00226 vm_switched = 0;
00227 #endif
00228 largefont_xft = 0;
00229 mediumfont_xft = 0;
00230 smallfont_xft = 0;
00231
00232 event_lock = new Mutex("BC_WindowBase::event_lock");
00233 event_condition = new Condition(0, "BC_WindowBase::event_condition");
00234 cursor_timer = new Timer;
00235 event_thread = 0;
00236 #ifdef HAVE_GL
00237 gl_win_context = 0;
00238 #endif
00239
00240 return 0;
00241 }
00242
00243 #define DEFAULT_EVENT_MASKS EnterWindowMask | \
00244 LeaveWindowMask | \
00245 ButtonPressMask | \
00246 ButtonReleaseMask | \
00247 PointerMotionMask | \
00248 FocusChangeMask
00249
00250
00251 int BC_WindowBase::create_window(BC_WindowBase *parent_window,
00252 char *title,
00253 int x,
00254 int y,
00255 int w,
00256 int h,
00257 int minw,
00258 int minh,
00259 int allow_resize,
00260 int private_color,
00261 int hide,
00262 int bg_color,
00263 char *display_name,
00264 int window_type,
00265 BC_Pixmap *bg_pixmap,
00266 int group_it)
00267 {
00268 XSetWindowAttributes attr;
00269 unsigned long mask;
00270 XSizeHints size_hints;
00271 int root_w;
00272 int root_h;
00273 #ifdef HAVE_LIBXXF86VM
00274 int vm;
00275 #endif
00276
00277 id = get_resources()->get_id();
00278
00279
00280 get_resources()->create_window_lock->lock("BC_WindowBase::create_window");
00281
00282 if(parent_window) top_level = parent_window->top_level;
00283
00284 #ifdef HAVE_LIBXXF86VM
00285 if(window_type == VIDMODE_SCALED_WINDOW)
00286 closest_vm(&vm,&w,&h);
00287 #endif
00288
00289 this->x = x;
00290 this->y = y;
00291 this->w = w;
00292 this->h = h;
00293 this->bg_color = bg_color;
00294 this->window_type = window_type;
00295 this->hidden = hide;
00296 this->private_color = private_color;
00297 this->parent_window = parent_window;
00298 this->bg_pixmap = bg_pixmap;
00299 this->allow_resize = allow_resize;
00300 strcpy(this->title, _(title));
00301 if(bg_pixmap) shared_bg_pixmap = 1;
00302
00303 if(parent_window) top_level = parent_window->top_level;
00304
00305 subwindows = new BC_SubWindowList;
00306 widgetgrids = new BC_WidgetGridList;
00307
00308
00309 if(window_type == MAIN_WINDOW)
00310 {
00311 top_level = this;
00312 parent_window = this;
00313
00314
00315
00316 XInitThreads();
00317
00318
00319
00320 display = init_display(display_name);
00321
00322
00323
00324 root_w = get_root_w(1, 0);
00325 root_h = get_root_h(0);
00326 if(this->x + this->w > root_w) this->x = root_w - this->w;
00327 if(this->y + this->h > root_h) this->y = root_h - this->h;
00328 if(this->x < 0) this->x = 0;
00329 if(this->y < 0) this->y = 0;
00330 screen = DefaultScreen(display);
00331 rootwin = RootWindow(display, screen);
00332
00333
00334 vis = DefaultVisual(display, screen);
00335 default_depth = DefaultDepth(display, screen);
00336
00337 client_byte_order = (*(u_int32_t*)"a ") & 0x00000001;
00338 server_byte_order = (XImageByteOrder(display) == MSBFirst) ? 0 : 1;
00339
00340
00341
00342 init_colors();
00343
00344 if(resources.use_shm < 0) resources.initialize_display(this);
00345 x_correction = get_resources()->get_left_border();
00346 y_correction = get_resources()->get_top_border();
00347
00348 if(this->bg_color == -1)
00349 this->bg_color = resources.get_bg_color();
00350
00351
00352
00353
00354 init_fonts();
00355 init_gc();
00356 init_cursors();
00357
00358
00359 mask = CWEventMask |
00360 CWBackPixel |
00361 CWColormap |
00362 CWCursor;
00363
00364 attr.event_mask = DEFAULT_EVENT_MASKS |
00365 StructureNotifyMask |
00366 KeyPressMask;
00367
00368 attr.background_pixel = get_color(this->bg_color);
00369 attr.colormap = cmap;
00370 attr.cursor = get_cursor_struct(ARROW_CURSOR);
00371
00372 win = XCreateWindow(display,
00373 rootwin,
00374 this->x,
00375 this->y,
00376 this->w,
00377 this->h,
00378 0,
00379 top_level->default_depth,
00380 InputOutput,
00381 vis,
00382 mask,
00383 &attr);
00384
00385 XGetNormalHints(display, win, &size_hints);
00386
00387 size_hints.flags = PSize | PMinSize | PMaxSize;
00388 size_hints.width = this->w;
00389 size_hints.height = this->h;
00390 size_hints.min_width = allow_resize ? minw : this->w;
00391 size_hints.max_width = allow_resize ? 32767 : this->w;
00392 size_hints.min_height = allow_resize ? minh : this->h;
00393 size_hints.max_height = allow_resize ? 32767 : this->h;
00394 if(x > -BC_INFINITY && x < BC_INFINITY)
00395 {
00396 size_hints.flags |= PPosition;
00397 size_hints.x = this->x;
00398 size_hints.y = this->y;
00399 }
00400
00401 XSetStandardProperties(display,
00402 win,
00403 title,
00404 title,
00405 None,
00406 0,
00407 0,
00408 &size_hints);
00409 get_atoms();
00410
00411 clipboard = new BC_Clipboard(display_name);
00412 clipboard->start_clipboard();
00413
00414 if (group_it)
00415 {
00416 Atom ClientLeaderXAtom;
00417 if (XGroupLeader == 0)
00418 XGroupLeader = win;
00419 char *instance_name = "cinelerra";
00420 char *class_name = "Cinelerra";
00421 XClassHint *class_hints = XAllocClassHint();
00422 class_hints->res_name = instance_name;
00423 class_hints->res_class = class_name;
00424 XSetClassHint(top_level->display, win, class_hints);
00425 XFree(class_hints);
00426 ClientLeaderXAtom = XInternAtom(display, "WM_CLIENT_LEADER", True);
00427 XChangeProperty(display,
00428 win,
00429 ClientLeaderXAtom,
00430 XA_WINDOW,
00431 32,
00432 PropModeReplace,
00433 (unsigned char *)&XGroupLeader,
00434 true);
00435
00436 }
00437
00438 }
00439
00440 #ifdef HAVE_LIBXXF86VM
00441 if(window_type == VIDMODE_SCALED_WINDOW && vm != -1)
00442 {
00443 scale_vm (vm);
00444 vm_switched = 1;
00445 }
00446 #endif
00447
00448 #ifdef HAVE_LIBXXF86VM
00449 if(window_type == POPUP_WINDOW || window_type == VIDMODE_SCALED_WINDOW)
00450 #else
00451 if(window_type == POPUP_WINDOW)
00452 #endif
00453 {
00454 mask = CWEventMask |
00455 CWBackPixel |
00456 CWColormap |
00457 CWOverrideRedirect |
00458 CWSaveUnder |
00459 CWCursor;
00460
00461 attr.event_mask = DEFAULT_EVENT_MASKS |
00462 KeyPressMask;
00463
00464 if(this->bg_color == -1)
00465 this->bg_color = resources.get_bg_color();
00466 attr.background_pixel = top_level->get_color(bg_color);
00467 attr.colormap = top_level->cmap;
00468 if(top_level->is_hourglass)
00469 attr.cursor = top_level->get_cursor_struct(HOURGLASS_CURSOR);
00470 else
00471 attr.cursor = top_level->get_cursor_struct(ARROW_CURSOR);
00472 attr.override_redirect = True;
00473 attr.save_under = True;
00474
00475 win = XCreateWindow(top_level->display,
00476 top_level->rootwin,
00477 this->x,
00478 this->y,
00479 this->w,
00480 this->h,
00481 0,
00482 top_level->default_depth,
00483 InputOutput,
00484 top_level->vis,
00485 mask,
00486 &attr);
00487 }
00488
00489 if(window_type == SUB_WINDOW)
00490 {
00491 mask = CWBackPixel |
00492 CWEventMask |
00493 CWCursor;
00494 attr.event_mask = DEFAULT_EVENT_MASKS;
00495 attr.background_pixel = top_level->get_color(this->bg_color);
00496 if(top_level->is_hourglass)
00497 attr.cursor = top_level->get_cursor_struct(HOURGLASS_CURSOR);
00498 else
00499 attr.cursor = top_level->get_cursor_struct(ARROW_CURSOR);
00500 win = XCreateWindow(top_level->display,
00501 parent_window->win,
00502 this->x,
00503 this->y,
00504 this->w,
00505 this->h,
00506 0,
00507 top_level->default_depth,
00508 InputOutput,
00509 top_level->vis,
00510 mask,
00511 &attr);
00512 init_window_shape();
00513 XMapWindow(top_level->display, win);
00514 }
00515
00516
00517 pixmap = new BC_Pixmap(this, this->w, this->h);
00518
00519
00520
00521 if(window_type == MAIN_WINDOW)
00522 {
00523 if(get_resources()->bg_image && !bg_pixmap && bg_color < 0)
00524 {
00525 this->bg_pixmap = new BC_Pixmap(this,
00526 get_resources()->bg_image,
00527 PIXMAP_OPAQUE);
00528 }
00529
00530 if(!hidden) show_window();
00531
00532 }
00533
00534
00535
00536
00537 draw_background(0, 0, this->w, this->h);
00538 flash();
00539
00540
00541 #ifdef HAVE_LIBXXF86VM
00542 if(window_type == POPUP_WINDOW || window_type == VIDMODE_SCALED_WINDOW)
00543 #else
00544 if(window_type == POPUP_WINDOW)
00545 #endif
00546 {
00547 init_window_shape();
00548 if(!hidden) show_window();
00549 }
00550 get_resources()->create_window_lock->unlock();
00551
00552 return 0;
00553 }
00554
00555 Display* BC_WindowBase::init_display(char *display_name)
00556 {
00557 Display* display;
00558
00559 if(display_name && display_name[0] == 0) display_name = NULL;
00560 if((display = XOpenDisplay(display_name)) == NULL)
00561 {
00562 printf("BC_WindowBase::init_display: cannot connect to X server %s\n",
00563 display_name);
00564 if(getenv("DISPLAY") == NULL)
00565 {
00566 printf("'DISPLAY' environment variable not set.\n");
00567 exit(1);
00568 }
00569 else
00570
00571 {
00572 if((display = XOpenDisplay(0)) == NULL)
00573 {
00574 printf("BC_WindowBase::init_display: cannot connect to default X server.\n");
00575 exit(1);
00576 }
00577 }
00578 }
00579 return display;
00580 }
00581
00582 Display* BC_WindowBase::get_display()
00583 {
00584 return top_level->display;
00585 }
00586
00587 int BC_WindowBase::get_screen()
00588 {
00589 return top_level->screen;
00590 }
00591
00592 int BC_WindowBase::run_window()
00593 {
00594 done = 0;
00595 return_value = 0;
00596
00597
00598
00599
00600
00601 if(window_type == MAIN_WINDOW)
00602 {
00603
00604 set_repeat(get_resources()->tooltip_delay);
00605 }
00606
00607
00608 event_thread = new BC_WindowEvents(this);
00609 event_thread->start();
00610
00611
00612 while(!done)
00613 {
00614 dispatch_event();
00615 }
00616
00617 unset_all_repeaters();
00618 hide_tooltip();
00619 delete event_thread;
00620 event_thread = 0;
00621 event_condition->reset();
00622 common_events.remove_all_objects();
00623 done = 0;
00624
00625 return return_value;
00626 }
00627
00628 int BC_WindowBase::get_key_masks(XEvent *event)
00629 {
00630
00631
00632
00633 ctrl_mask = (event->xkey.state & ControlMask) ? 1 : 0;
00634
00635 shift_mask = (event->xkey.state & ShiftMask) ? 1 : 0;
00636 alt_mask = (event->xkey.state & Mod1Mask) ? 1 : 0;
00637 return 0;
00638 }
00639
00640
00641
00642
00643
00644
00645
00646 int BC_WindowBase::dispatch_event()
00647 {
00648 XEvent *event = 0;
00649 Window tempwin;
00650 KeySym keysym;
00651 char keys_return[2];
00652 int result;
00653 XClientMessageEvent *ptr;
00654 int temp;
00655 int cancel_resize, cancel_translation;
00656
00657 key_pressed = 0;
00658
00659
00660
00661 if(get_event_count() ||
00662 (!motion_events && !resize_events && !translation_events))
00663 {
00664
00665 event = get_event();
00666
00667 lock_window("BC_WindowBase::dispatch_event 1");
00668
00669 }
00670 else
00671
00672 {
00673 lock_window("BC_WindowBase::dispatch_event 2");
00674 if(resize_events)
00675 dispatch_resize_event(last_resize_w, last_resize_h);
00676 else
00677 if(motion_events)
00678 dispatch_motion_event();
00679 else
00680 if(translation_events)
00681 dispatch_translation_event();
00682
00683 unlock_window();
00684 return 0;
00685 }
00686
00687
00688 switch(event->type)
00689 {
00690 case ClientMessage:
00691
00692 if(resize_events) dispatch_resize_event(last_resize_w, last_resize_h);
00693
00694 if(motion_events)
00695 {
00696 dispatch_motion_event();
00697 }
00698
00699 ptr = (XClientMessageEvent*)event;
00700
00701
00702 if(ptr->message_type == ProtoXAtom &&
00703 ptr->data.l[0] == DelWinXAtom)
00704 {
00705 close_event();
00706 }
00707 else
00708 if(ptr->message_type == RepeaterXAtom)
00709 {
00710 dispatch_repeat_event(ptr->data.l[0]);
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720 }
00721 else
00722 if(ptr->message_type == SetDoneXAtom)
00723 {
00724 done = 1;
00725 } else
00726 {
00727 recieve_custom_xatoms((xatom_event *)ptr);
00728 }
00729 break;
00730
00731 case FocusIn:
00732 has_focus = 1;
00733 dispatch_focus_in();
00734 break;
00735
00736 case FocusOut:
00737 has_focus = 0;
00738 dispatch_focus_out();
00739 break;
00740
00741
00742 case MapNotify:
00743 break;
00744
00745
00746 case UnmapNotify:
00747 break;
00748
00749 case ButtonPress:
00750 get_key_masks(event);
00751 cursor_x = event->xbutton.x;
00752 cursor_y = event->xbutton.y;
00753 button_number = event->xbutton.button;
00754 event_win = event->xany.window;
00755 if (button_number != 4 && button_number != 5)
00756 button_down = 1;
00757 button_pressed = event->xbutton.button;
00758 button_time1 = button_time2;
00759 button_time2 = event->xbutton.time;
00760 drag_x = cursor_x;
00761 drag_y = cursor_y;
00762 drag_win = event_win;
00763 drag_x1 = cursor_x - get_resources()->drag_radius;
00764 drag_x2 = cursor_x + get_resources()->drag_radius;
00765 drag_y1 = cursor_y - get_resources()->drag_radius;
00766 drag_y2 = cursor_y + get_resources()->drag_radius;
00767
00768 if(button_time2 - button_time1 < resources.double_click)
00769 {
00770
00771 double_click = 1;
00772 button_time2 = button_time1 = 0;
00773 }
00774 else
00775 double_click = 0;
00776
00777 dispatch_button_press();
00778 break;
00779
00780 case ButtonRelease:
00781 get_key_masks(event);
00782 button_number = event->xbutton.button;
00783 event_win = event->xany.window;
00784 if (button_number != 4 && button_number != 5)
00785 button_down = 0;
00786
00787 dispatch_button_release();
00788
00789 break;
00790
00791 case Expose:
00792 event_win = event->xany.window;
00793 dispatch_expose_event();
00794 break;
00795
00796 case MotionNotify:
00797 get_key_masks(event);
00798
00799 if(motion_events && last_motion_win != event->xany.window)
00800 {
00801 dispatch_motion_event();
00802 }
00803
00804
00805 motion_events = 1;
00806 last_motion_x = event->xmotion.x;
00807 last_motion_y = event->xmotion.y;
00808 last_motion_win = event->xany.window;
00809 break;
00810
00811 case ConfigureNotify:
00812 get_key_masks(event);
00813 XTranslateCoordinates(top_level->display,
00814 top_level->win,
00815 top_level->rootwin,
00816 0,
00817 0,
00818 &last_translate_x,
00819 &last_translate_y,
00820 &tempwin);
00821 last_resize_w = event->xconfigure.width;
00822 last_resize_h = event->xconfigure.height;
00823
00824 cancel_resize = 0;
00825 cancel_translation = 0;
00826
00827
00828 for(int i = 0; i < resize_history.total && !cancel_resize; i++)
00829 {
00830 if(resize_history.values[i]->w == last_resize_w &&
00831 resize_history.values[i]->h == last_resize_h)
00832 {
00833 delete resize_history.values[i];
00834 resize_history.remove_number(i);
00835 cancel_resize = 1;
00836 }
00837 }
00838
00839 if(last_resize_w == w && last_resize_h == h)
00840 cancel_resize = 1;
00841
00842 if(!cancel_resize)
00843 {
00844 resize_events = 1;
00845 }
00846
00847 if((last_translate_x == x && last_translate_y == y))
00848 cancel_translation = 1;
00849
00850 if(!cancel_translation)
00851 {
00852 translation_events = 1;
00853 }
00854
00855 translation_count++;
00856 break;
00857
00858 case KeyPress:
00859 get_key_masks(event);
00860 keys_return[0] = 0;
00861 XLookupString((XKeyEvent*)event, keys_return, 1, &keysym, 0);
00862
00863
00864
00865
00866 if(keysym > 0xffe0 && keysym < 0xffff) break;
00867
00868
00869 if(test_keypress) printf("BC_WindowBase::dispatch_event %x\n", keysym);
00870
00871
00872 switch(keysym)
00873 {
00874
00875 case XK_Alt_L:
00876 case XK_Alt_R:
00877 case XK_Shift_L:
00878 case XK_Shift_R:
00879 case XK_Control_L:
00880 case XK_Control_R:
00881 key_pressed = 0;
00882 break;
00883
00884
00885 case XK_Return: key_pressed = RETURN; break;
00886 case XK_Up: key_pressed = UP; break;
00887 case XK_Down: key_pressed = DOWN; break;
00888 case XK_Left: key_pressed = LEFT; break;
00889 case XK_Right: key_pressed = RIGHT; break;
00890 case XK_Next: key_pressed = PGDN; break;
00891 case XK_Prior: key_pressed = PGUP; break;
00892 case XK_BackSpace: key_pressed = BACKSPACE; break;
00893 case XK_Escape: key_pressed = ESC; break;
00894 case XK_Tab:
00895 if(shift_down())
00896 key_pressed = LEFTTAB;
00897 else
00898 key_pressed = TAB;
00899 break;
00900 case XK_ISO_Left_Tab: key_pressed = LEFTTAB; break;
00901 case XK_underscore: key_pressed = '_'; break;
00902 case XK_asciitilde: key_pressed = '~'; break;
00903 case XK_Delete: key_pressed = DELETE; break;
00904 case XK_Home: key_pressed = HOME; break;
00905 case XK_End: key_pressed = END; break;
00906
00907
00908 case XK_KP_Enter: key_pressed = KPENTER; break;
00909 case XK_KP_Add: key_pressed = KPPLUS; break;
00910 case XK_KP_1:
00911 case XK_KP_End: key_pressed = KP1; break;
00912 case XK_KP_2:
00913 case XK_KP_Down: key_pressed = KP2; break;
00914 case XK_KP_3:
00915 case XK_KP_Page_Down: key_pressed = KP3; break;
00916 case XK_KP_4:
00917 case XK_KP_Left: key_pressed = KP4; break;
00918 case XK_KP_5:
00919 case XK_KP_Begin: key_pressed = KP5; break;
00920 case XK_KP_6:
00921 case XK_KP_Right: key_pressed = KP6; break;
00922 case XK_KP_0:
00923 case XK_KP_Insert: key_pressed = KPINS; break;
00924 case XK_KP_Decimal:
00925 case XK_KP_Delete: key_pressed = KPDEL; break;
00926 default:
00927
00928 key_pressed = keysym & 0xff;
00929 break;
00930 }
00931
00932
00933 result = dispatch_keypress_event();
00934
00935 if(!result)
00936 {
00937 if(key_pressed == 'w' ||
00938 key_pressed == 'W')
00939 {
00940 close_event();
00941 }
00942 }
00943 break;
00944
00945 case LeaveNotify:
00946 event_win = event->xany.window;
00947 dispatch_cursor_leave();
00948 break;
00949
00950 case EnterNotify:
00951 event_win = event->xany.window;
00952 cursor_x = event->xcrossing.x;
00953 cursor_y = event->xcrossing.y;
00954 dispatch_cursor_enter();
00955 break;
00956 }
00957
00958
00959 unlock_window();
00960 if(event) delete event;
00961 return 0;
00962 }
00963
00964 int BC_WindowBase::dispatch_expose_event()
00965 {
00966 int result = 0;
00967 for(int i = 0; i < subwindows->total && !result; i++)
00968 {
00969 result = subwindows->values[i]->dispatch_expose_event();
00970 }
00971
00972
00973 if(!result) expose_event();
00974 return result;
00975 }
00976
00977 int BC_WindowBase::dispatch_resize_event(int w, int h)
00978 {
00979
00980
00981
00982 if(window_type == MAIN_WINDOW)
00983 {
00984 resize_events = 0;
00985 delete pixmap;
00986 pixmap = new BC_Pixmap(this, w, h);
00987
00988 clear_box(0, 0, w, h);
00989 }
00990
00991
00992 for(int i = 0; i < subwindows->total; i++)
00993 {
00994 subwindows->values[i]->dispatch_resize_event(w, h);
00995 }
00996
00997
00998 resize_event(w, h);
00999
01000 if(window_type == MAIN_WINDOW)
01001 {
01002 this->w = w;
01003 this->h = h;
01004 }
01005 return 0;
01006 }
01007
01008 int BC_WindowBase::dispatch_translation_event()
01009 {
01010 translation_events = 0;
01011 if(window_type == MAIN_WINDOW)
01012 {
01013 prev_x = x;
01014 prev_y = y;
01015 x = last_translate_x;
01016 y = last_translate_y;
01017
01018 x -= x_correction;
01019 y -= y_correction;
01020 }
01021
01022 for(int i = 0; i < subwindows->total; i++)
01023 {
01024 subwindows->values[i]->dispatch_translation_event();
01025 }
01026
01027 translation_event();
01028 return 0;
01029 }
01030
01031 int BC_WindowBase::dispatch_motion_event()
01032 {
01033 int result = 0;
01034 unhide_cursor();
01035
01036 if(top_level == this)
01037 {
01038 event_win = last_motion_win;
01039 motion_events = 0;
01040
01041
01042 if(get_button_down() && !active_menubar && !active_popup_menu)
01043 {
01044 if(!result)
01045 {
01046 cursor_x = last_motion_x;
01047 cursor_y = last_motion_y;
01048 result = dispatch_drag_motion();
01049 }
01050
01051 if(!result &&
01052 (last_motion_x < drag_x1 || last_motion_x >= drag_x2 ||
01053 last_motion_y < drag_y1 || last_motion_y >= drag_y2))
01054 {
01055 cursor_x = drag_x;
01056 cursor_y = drag_y;
01057
01058 result = dispatch_drag_start();
01059 }
01060 }
01061 cursor_x = last_motion_x;
01062 cursor_y = last_motion_y;
01063
01064 if(active_menubar && !result) result = active_menubar->dispatch_motion_event();
01065 if(active_popup_menu && !result) result = active_popup_menu->dispatch_motion_event();
01066 if(active_subwindow && !result) result = active_subwindow->dispatch_motion_event();
01067 }
01068
01069 for(int i = 0; i < subwindows->total && !result; i++)
01070 {
01071 result = subwindows->values[i]->dispatch_motion_event();
01072 }
01073
01074
01075 if(!result) result = cursor_motion_event();
01076 return result;
01077 }
01078
01079 int BC_WindowBase::dispatch_keypress_event()
01080 {
01081 int result = 0;
01082 if(top_level == this)
01083 {
01084 if(active_subwindow) result = active_subwindow->dispatch_keypress_event();
01085 }
01086
01087 for(int i = 0; i < subwindows->total && !result; i++)
01088 {
01089 result = subwindows->values[i]->dispatch_keypress_event();
01090 }
01091
01092 if(!result) result = keypress_event();
01093
01094 return result;
01095 }
01096
01097 int BC_WindowBase::dispatch_focus_in()
01098 {
01099 for(int i = 0; i < subwindows->total; i++)
01100 {
01101 subwindows->values[i]->dispatch_focus_in();
01102 }
01103
01104 focus_in_event();
01105
01106 return 0;
01107 }
01108
01109 int BC_WindowBase::dispatch_focus_out()
01110 {
01111 for(int i = 0; i < subwindows->total; i++)
01112 {
01113 subwindows->values[i]->dispatch_focus_out();
01114 }
01115
01116 focus_out_event();
01117
01118 return 0;
01119 }
01120
01121 int BC_WindowBase::get_has_focus()
01122 {
01123 return top_level->has_focus;
01124 }
01125
01126 int BC_WindowBase::get_deleting()
01127 {
01128 if(is_deleting) return 1;
01129 if(parent_window && parent_window->get_deleting()) return 1;
01130 return 0;
01131 }
01132
01133 int BC_WindowBase::dispatch_button_press()
01134 {
01135 int result = 0;
01136 if(top_level == this)
01137 {
01138 if(active_menubar) result = active_menubar->dispatch_button_press();
01139 if(active_popup_menu && !result) result = active_popup_menu->dispatch_button_press();
01140 if(active_subwindow && !result) result = active_subwindow->dispatch_button_press();
01141 }
01142
01143 for(int i = 0; i < subwindows->total && !result; i++)
01144 {
01145 result = subwindows->values[i]->dispatch_button_press();
01146 }
01147
01148 if(!result) result = button_press_event();
01149
01150 return result;
01151 }
01152
01153 int BC_WindowBase::dispatch_button_release()
01154 {
01155 int result = 0;
01156 if(top_level == this)
01157 {
01158 if(active_menubar) result = active_menubar->dispatch_button_release();
01159 if(active_popup_menu && !result) result = active_popup_menu->dispatch_button_release();
01160 if(active_subwindow && !result) result = active_subwindow->dispatch_button_release();
01161 if(!result && button_number != 4 && button_number != 5)
01162 result = dispatch_drag_stop();
01163 }
01164
01165 for(int i = 0; i < subwindows->total && !result; i++)
01166 {
01167 result = subwindows->values[i]->dispatch_button_release();
01168 }
01169
01170 if(!result)
01171 {
01172 result = button_release_event();
01173 }
01174
01175 return result;
01176 }
01177
01178
01179 int BC_WindowBase::dispatch_repeat_event(int64_t duration)
01180 {
01181
01182
01183
01184 for(int i = 0; i < subwindows->total; i++)
01185 {
01186 subwindows->values[i]->dispatch_repeat_event(duration);
01187 }
01188
01189
01190 repeat_event(duration);
01191
01192
01193
01194
01195 if(window_type == MAIN_WINDOW)
01196 {
01197 for(int i = 0; i < repeaters.total; i++)
01198 {
01199 if(repeaters.values[i]->delay == duration)
01200 {
01201 repeaters.values[i]->repeat_lock->unlock();
01202 }
01203 }
01204 }
01205
01206 return 0;
01207 }
01208
01209 void BC_WindowBase::unhide_cursor()
01210 {
01211 if(is_transparent)
01212 {
01213 is_transparent = 0;
01214 if(top_level->is_hourglass)
01215 set_cursor(HOURGLASS_CURSOR, 1);
01216 else
01217 set_cursor(current_cursor, 1);
01218 }
01219 cursor_timer->update();
01220 }
01221
01222
01223 void BC_WindowBase::update_video_cursor()
01224 {
01225 if(video_on && !is_transparent)
01226 {
01227 if(cursor_timer->get_difference() > VIDEO_CURSOR_TIMEOUT && !is_transparent)
01228 {
01229 is_transparent = 1;
01230 set_cursor(TRANSPARENT_CURSOR, 1);
01231 cursor_timer->update();
01232 }
01233 }
01234 else
01235 {
01236 cursor_timer->update();
01237 }
01238 }
01239
01240
01241 int BC_WindowBase::dispatch_cursor_leave()
01242 {
01243 unhide_cursor();
01244
01245 for(int i = 0; i < subwindows->total; i++)
01246 {
01247 subwindows->values[i]->dispatch_cursor_leave();
01248 }
01249
01250 cursor_leave_event();
01251 return 0;
01252 }
01253
01254 int BC_WindowBase::dispatch_cursor_enter()
01255 {
01256 int result = 0;
01257
01258 unhide_cursor();
01259
01260 if(active_menubar) result = active_menubar->dispatch_cursor_enter();
01261 if(!result && active_popup_menu) result = active_popup_menu->dispatch_cursor_enter();
01262 if(!result && active_subwindow) result = active_subwindow->dispatch_cursor_enter();
01263
01264 for(int i = 0; !result && i < subwindows->total; i++)
01265 {
01266 result = subwindows->values[i]->dispatch_cursor_enter();
01267 }
01268
01269 if(!result) result = cursor_enter_event();
01270 return result;
01271 }
01272
01273 int BC_WindowBase::cursor_enter_event()
01274 {
01275 return 0;
01276 }
01277
01278 int BC_WindowBase::cursor_leave_event()
01279 {
01280 return 0;
01281 }
01282
01283 int BC_WindowBase::close_event()
01284 {
01285 set_done(1);
01286 return 1;
01287 }
01288
01289 int BC_WindowBase::dispatch_drag_start()
01290 {
01291 int result = 0;
01292 if(active_menubar) result = active_menubar->dispatch_drag_start();
01293 if(!result && active_popup_menu) result = active_popup_menu->dispatch_drag_start();
01294 if(!result && active_subwindow) result = active_subwindow->dispatch_drag_start();
01295
01296 for(int i = 0; i < subwindows->total && !result; i++)
01297 {
01298 result = subwindows->values[i]->dispatch_drag_start();
01299 }
01300
01301 if(!result) result = is_dragging = drag_start_event();
01302 return result;
01303 }
01304
01305 int BC_WindowBase::dispatch_drag_stop()
01306 {
01307 int result = 0;
01308
01309 for(int i = 0; i < subwindows->total && !result; i++)
01310 {
01311 result = subwindows->values[i]->dispatch_drag_stop();
01312 }
01313
01314 if(is_dragging && !result)
01315 {
01316 drag_stop_event();
01317 is_dragging = 0;
01318 result = 1;
01319 }
01320
01321 return result;
01322 }
01323
01324 int BC_WindowBase::dispatch_drag_motion()
01325 {
01326 int result = 0;
01327 for(int i = 0; i < subwindows->total && !result; i++)
01328 {
01329 result = subwindows->values[i]->dispatch_drag_motion();
01330 }
01331
01332 if(is_dragging && !result)
01333 {
01334 drag_motion_event();
01335 result = 1;
01336 }
01337
01338 return result;
01339 }
01340
01341
01342
01343
01344
01345 int BC_WindowBase::show_tooltip(int w, int h)
01346 {
01347 Window tempwin;
01348
01349 if(!tooltip_on && get_resources()->tooltips_enabled)
01350 {
01351 int i, j, x, y;
01352 top_level->hide_tooltip();
01353
01354 tooltip_on = 1;
01355 if(w < 0)
01356 w = get_text_width(MEDIUMFONT, tooltip_text);
01357
01358 if(h < 0)
01359 h = get_text_height(MEDIUMFONT, tooltip_text);
01360
01361 w += TOOLTIP_MARGIN * 2;
01362 h += TOOLTIP_MARGIN * 2;
01363
01364 XTranslateCoordinates(top_level->display,
01365 win,
01366 top_level->rootwin,
01367 get_w(),
01368 get_h(),
01369 &x,
01370 &y,
01371 &tempwin);
01372 tooltip_popup = new BC_Popup(top_level,
01373 x,
01374 y,
01375 w,
01376 h,
01377 get_resources()->tooltip_bg_color);
01378
01379 draw_tooltip();
01380 tooltip_popup->set_font(MEDIUMFONT);
01381 tooltip_popup->flash();
01382 tooltip_popup->flush();
01383 }
01384 return 0;
01385 }
01386
01387 int BC_WindowBase::hide_tooltip()
01388 {
01389 if(subwindows)
01390 for(int i = 0; i < subwindows->total; i++)
01391 {
01392 subwindows->values[i]->hide_tooltip();
01393 }
01394
01395 if(tooltip_on)
01396 {
01397 tooltip_on = 0;
01398 delete tooltip_popup;
01399 tooltip_popup = 0;
01400 }
01401 return 0;
01402 }
01403
01404 int BC_WindowBase::set_tooltip(char *text)
01405 {
01406 strcpy(this->tooltip_text, text);
01407
01408 if(tooltip_on)
01409 {
01410 draw_tooltip();
01411 tooltip_popup->flash();
01412 }
01413 return 0;
01414 }
01415
01416
01417 int BC_WindowBase::set_repeat(int64_t duration)
01418 {
01419 if(duration <= 0)
01420 {
01421 printf("BC_WindowBase::set_repeat duration=%d\n", duration);
01422 return 0;
01423 }
01424 if(window_type != MAIN_WINDOW) return top_level->set_repeat(duration);
01425
01426
01427 for(int i = 0; i < repeaters.total; i++)
01428 {
01429
01430 if(repeaters.values[i]->delay == duration)
01431 {
01432 repeaters.values[i]->start_repeating();
01433 return 0;
01434 }
01435 }
01436
01437 BC_Repeater *repeater = new BC_Repeater(this, duration);
01438 repeater->initialize();
01439 repeaters.append(repeater);
01440 repeater->start_repeating();
01441 return 0;
01442 }
01443
01444 int BC_WindowBase::unset_repeat(int64_t duration)
01445 {
01446 if(window_type != MAIN_WINDOW) return top_level->unset_repeat(duration);
01447
01448 BC_Repeater *repeater = 0;
01449 for(int i = 0; i < repeaters.total; i++)
01450 {
01451 if(repeaters.values[i]->delay == duration)
01452 {
01453 repeaters.values[i]->stop_repeating();
01454 }
01455 }
01456 return 0;
01457 }
01458
01459
01460 int BC_WindowBase::unset_all_repeaters()
01461 {
01462 for(int i = 0; i < repeaters.total; i++)
01463 {
01464 repeaters.values[i]->stop_repeating();
01465 }
01466 repeaters.remove_all_objects();
01467 return 0;
01468 }
01469
01470
01471
01472
01473
01474
01475
01476 int BC_WindowBase::arm_repeat(int64_t duration)
01477 {
01478 XEvent *event = new XEvent;
01479 XClientMessageEvent *ptr = (XClientMessageEvent*)event;
01480 ptr->type = ClientMessage;
01481 ptr->message_type = RepeaterXAtom;
01482 ptr->format = 32;
01483 ptr->data.l[0] = duration;
01484
01485
01486 put_event(event);
01487
01488
01489
01490
01491
01492
01493 return 0;
01494 }
01495
01496 int BC_WindowBase::recieve_custom_xatoms(xatom_event *event)
01497 {
01498 return 0;
01499 }
01500
01501 int BC_WindowBase::send_custom_xatom(xatom_event *event)
01502 {
01503 XEvent *myevent = new XEvent;
01504 XClientMessageEvent *ptr = (XClientMessageEvent*)myevent;
01505 ptr->type = ClientMessage;
01506 ptr->message_type = event->message_type;
01507 ptr->format = event->format;
01508 ptr->data.l[0] = event->data.l[0];
01509 ptr->data.l[1] = event->data.l[1];
01510 ptr->data.l[2] = event->data.l[2];
01511 ptr->data.l[3] = event->data.l[3];
01512 ptr->data.l[4] = event->data.l[4];
01513
01514 put_event(myevent);
01515 return 0;
01516 }
01517
01518
01519
01520 Atom BC_WindowBase::create_xatom(char *atom_name)
01521 {
01522 return XInternAtom(display, atom_name, False);
01523 }
01524
01525 int BC_WindowBase::get_atoms()
01526 {
01527 SetDoneXAtom = create_xatom("BC_REPEAT_EVENT");
01528 RepeaterXAtom = create_xatom("BC_CLOSE_EVENT");
01529 DelWinXAtom = create_xatom("WM_DELETE_WINDOW");
01530 if(ProtoXAtom = create_xatom("WM_PROTOCOLS"))
01531 XChangeProperty(display, win, ProtoXAtom, XA_ATOM, 32, PropModeReplace, (unsigned char *)&DelWinXAtom, True);
01532 return 0;
01533
01534 }
01535
01536
01537 void BC_WindowBase::init_cursors()
01538 {
01539 arrow_cursor = XCreateFontCursor(display, XC_top_left_arrow);
01540 cross_cursor = XCreateFontCursor(display, XC_crosshair);
01541 ibeam_cursor = XCreateFontCursor(display, XC_xterm);
01542 vseparate_cursor = XCreateFontCursor(display, XC_sb_v_double_arrow);
01543 hseparate_cursor = XCreateFontCursor(display, XC_sb_h_double_arrow);
01544 move_cursor = XCreateFontCursor(display, XC_fleur);
01545 left_cursor = XCreateFontCursor(display, XC_sb_left_arrow);
01546 right_cursor = XCreateFontCursor(display, XC_sb_right_arrow);
01547 upright_arrow_cursor = XCreateFontCursor(display, XC_arrow);
01548 upleft_resize_cursor = XCreateFontCursor(display, XC_top_left_corner);
01549 upright_resize_cursor = XCreateFontCursor(display, XC_top_right_corner);
01550 downleft_resize_cursor = XCreateFontCursor(display, XC_bottom_left_corner);
01551 downright_resize_cursor = XCreateFontCursor(display, XC_bottom_right_corner);
01552 hourglass_cursor = XCreateFontCursor(display, XC_watch);
01553
01554
01555 char cursor_data[] = { 0,0,0,0, 0,0,0,0 };
01556 Colormap colormap = DefaultColormap(display, screen);
01557 Pixmap pixmap_bottom = XCreateBitmapFromData(display,
01558 rootwin,
01559 cursor_data,
01560 8,
01561 8);
01562 XColor black, dummy;
01563 XAllocNamedColor(display, colormap, "black", &black, &dummy);
01564 transparent_cursor = XCreatePixmapCursor(display,
01565 pixmap_bottom,
01566 pixmap_bottom,
01567 &black,
01568 &black,
01569 0,
01570 0);
01571
01572 XFreePixmap(display, pixmap_bottom);
01573 }
01574
01575 int BC_WindowBase::evaluate_color_model(int client_byte_order, int server_byte_order, int depth)
01576 {
01577 int color_model;
01578 switch(depth)
01579 {
01580 case 8:
01581 color_model = BC_RGB8;
01582 break;
01583 case 16:
01584 color_model = (server_byte_order == client_byte_order) ? BC_RGB565 : BC_BGR565;
01585 break;
01586 case 24:
01587 color_model = server_byte_order ? BC_BGR888 : BC_RGB888;
01588 break;
01589 case 32:
01590 color_model = server_byte_order ? BC_BGR8888 : BC_ARGB8888;
01591 break;
01592 }
01593 return color_model;
01594 }
01595
01596 int BC_WindowBase::init_colors()
01597 {
01598 total_colors = 0;
01599 current_color_value = current_color_pixel = 0;
01600
01601
01602 char *data = 0;
01603 XImage *ximage;
01604 ximage = XCreateImage(top_level->display,
01605 top_level->vis,
01606 top_level->default_depth,
01607 ZPixmap,
01608 0,
01609 data,
01610 16,
01611 16,
01612 8,
01613 0);
01614 bits_per_pixel = ximage->bits_per_pixel;
01615 XDestroyImage(ximage);
01616
01617 color_model = evaluate_color_model(client_byte_order,
01618 server_byte_order,
01619 bits_per_pixel);
01620
01621 switch(color_model)
01622 {
01623 case BC_RGB8:
01624 if(private_color)
01625 {
01626 cmap = XCreateColormap(display, rootwin, vis, AllocNone);
01627 create_private_colors();
01628 }
01629 else
01630 {
01631 cmap = DefaultColormap(display, screen);
01632 create_shared_colors();
01633 }
01634
01635 allocate_color_table();
01636
01637 get_resources()->use_xft = 0;
01638 break;
01639
01640 default:
01641 cmap = DefaultColormap(display, screen);
01642 break;
01643 }
01644 return 0;
01645 }
01646
01647 int BC_WindowBase::create_private_colors()
01648 {
01649 int color;
01650 total_colors = 256;
01651
01652 for(int i = 0; i < 255; i++)
01653 {
01654 color = (i & 0xc0) << 16;
01655 color += (i & 0x38) << 10;
01656 color += (i & 0x7) << 5;
01657 color_table[i][0] = color;
01658 }
01659 create_shared_colors();
01660 return 0;
01661 }
01662
01663
01664 int BC_WindowBase::create_color(int color)
01665 {
01666 if(total_colors == 256)
01667 {
01668
01669 color_table[get_color_rgb8(color)][0] = color;
01670 }
01671 else
01672 {
01673
01674 color_table[total_colors][0] = color;
01675 total_colors++;
01676 }
01677 return 0;
01678 }
01679
01680 int BC_WindowBase::create_shared_colors()
01681 {
01682 create_color(BLACK);
01683 create_color(WHITE);
01684
01685 create_color(LTGREY);
01686 create_color(MEGREY);
01687 create_color(MDGREY);
01688 create_color(DKGREY);
01689
01690 create_color(LTCYAN);
01691 create_color(MECYAN);
01692 create_color(MDCYAN);
01693 create_color(DKCYAN);
01694
01695 create_color(LTGREEN);
01696 create_color(GREEN);
01697 create_color(DKGREEN);
01698
01699 create_color(LTPINK);
01700 create_color(PINK);
01701 create_color(RED);
01702
01703 create_color(LTBLUE);
01704 create_color(BLUE);
01705 create_color(DKBLUE);
01706
01707 create_color(LTYELLOW);
01708 create_color(MEYELLOW);
01709 create_color(MDYELLOW);
01710 create_color(DKYELLOW);
01711
01712 create_color(LTPURPLE);
01713 create_color(MEPURPLE);
01714 create_color(MDPURPLE);
01715 create_color(DKPURPLE);
01716
01717 create_color(FGGREY);
01718 create_color(MNBLUE);
01719 create_color(ORANGE);
01720 create_color(FTGREY);
01721
01722 return 0;
01723 }
01724
01725 int BC_WindowBase::allocate_color_table()
01726 {
01727 int red, green, blue, color;
01728 int result;
01729 XColor col;
01730
01731 for(int i = 0; i < total_colors; i++)
01732 {
01733 color = color_table[i][0];
01734 red = (color & 0xFF0000) >> 16;
01735 green = (color & 0x00FF00) >> 8;
01736 blue = color & 0xFF;
01737
01738 col.flags = DoRed | DoGreen | DoBlue;
01739 col.red = red<<8 | red;
01740 col.green = green<<8 | green;
01741 col.blue = blue<<8 | blue;
01742
01743 XAllocColor(display, cmap, &col);
01744 color_table[i][1] = col.pixel;
01745 }
01746
01747 XInstallColormap(display, cmap);
01748 return 0;
01749 }
01750
01751 int BC_WindowBase::init_window_shape()
01752 {
01753 if(bg_pixmap && bg_pixmap->use_alpha())
01754 {
01755 XShapeCombineMask(top_level->display,
01756 this->win,
01757 ShapeBounding,
01758 0,
01759 0,
01760 bg_pixmap->get_alpha(),
01761 ShapeSet);
01762 }
01763 return 0;
01764 }
01765
01766
01767 int BC_WindowBase::init_gc()
01768 {
01769 unsigned long gcmask;
01770 gcmask = GCFont | GCGraphicsExposures;
01771
01772 XGCValues gcvalues;
01773 gcvalues.font = mediumfont->fid;
01774 gcvalues.graphics_exposures = 0;
01775 gc = XCreateGC(display, rootwin, gcmask, &gcvalues);
01776 return 0;
01777 }
01778
01779 int BC_WindowBase::init_fonts()
01780 {
01781 if((largefont = XLoadQueryFont(display, _(resources.large_font))) == NULL)
01782 if((largefont = XLoadQueryFont(display, _(resources.large_font2))) == NULL)
01783 largefont = XLoadQueryFont(display, "fixed");
01784
01785 if((mediumfont = XLoadQueryFont(display, _(resources.medium_font))) == NULL)
01786 if((mediumfont = XLoadQueryFont(display, _(resources.medium_font2))) == NULL)
01787 mediumfont = XLoadQueryFont(display, "fixed");
01788
01789 if((smallfont = XLoadQueryFont(display, _(resources.small_font))) == NULL)
01790 if((smallfont = XLoadQueryFont(display, _(resources.small_font2))) == NULL)
01791 smallfont = XLoadQueryFont(display, "fixed");
01792
01793 init_xft();
01794 if(get_resources()->use_fontset)
01795 {
01796 char **m, *d;
01797 int n;
01798
01799
01800 if((largefontset = XCreateFontSet(display,
01801 resources.large_fontset,
01802 &m,
01803 &n,
01804 &d)) == 0)
01805 largefontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
01806 if((mediumfontset = XCreateFontSet(display,
01807 resources.medium_fontset,
01808 &m,
01809 &n,
01810 &d)) == 0)
01811 mediumfontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
01812 if((smallfontset = XCreateFontSet(display,
01813 resources.small_fontset,
01814 &m,
01815 &n,
01816 &d)) == 0)
01817 smallfontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
01818
01819 if(largefontset && mediumfontset && smallfontset)
01820 {
01821 curr_fontset = mediumfontset;
01822 get_resources()->use_fontset = 1;
01823 }
01824 else
01825 {
01826 curr_fontset = 0;
01827 get_resources()->use_fontset = 0;
01828 }
01829 }
01830
01831 return 0;
01832 }
01833
01834
01835 void BC_WindowBase::init_xft()
01836 {
01837 #ifdef HAVE_XFT
01838 if(!(largefont_xft = XftFontOpenXlfd(display,
01839 screen,
01840 resources.large_font_xft)))
01841 if(!(largefont_xft = XftFontOpenXlfd(display,
01842 screen,
01843 resources.large_font_xft2)))
01844 largefont_xft = XftFontOpenXlfd(display,
01845 screen,
01846 "fixed");
01847
01848
01849 if(!(mediumfont_xft = XftFontOpenXlfd(display,
01850 screen,
01851 resources.medium_font_xft)))
01852 if(!(mediumfont_xft = XftFontOpenXlfd(display,
01853 screen,
01854 resources.medium_font_xft2)))
01855 mediumfont_xft = XftFontOpenXlfd(display,
01856 screen,
01857 "fixed");
01858
01859
01860 if(!(smallfont_xft = XftFontOpenXlfd(display,
01861 screen,
01862 resources.small_font_xft)))
01863 if(!(smallfont_xft = XftFontOpenXlfd(display,
01864 screen,
01865 resources.small_font_xft2)))
01866 smallfont_xft = XftFontOpenXlfd(display,
01867 screen,
01868 "fixed");
01869
01870
01871
01872 if(!largefont_xft || !mediumfont_xft || !smallfont_xft)
01873 {
01874 printf("BC_WindowBase::init_fonts: no xft fonts found %s=%p %s=%p %s=%p\n",
01875 resources.large_font_xft,
01876 largefont_xft,
01877 resources.medium_font_xft,
01878 mediumfont_xft,
01879 resources.small_font_xft,
01880 smallfont_xft);
01881 get_resources()->use_xft = 0;
01882 }
01883 #endif
01884 }
01885
01886
01887 int BC_WindowBase::get_color(int64_t color)
01888 {
01889
01890
01891 int i, test, difference, result;
01892
01893 switch(color_model)
01894 {
01895 case BC_RGB8:
01896 if(private_color)
01897 {
01898 return get_color_rgb8(color);
01899 }
01900 else
01901 {
01902
01903 if(current_color_value == color) return current_color_pixel;
01904
01905
01906 current_color_value = color;
01907 for(i = 0; i < total_colors; i++)
01908 {
01909 if(color_table[i][0] == color)
01910 {
01911 current_color_pixel = color_table[i][1];
01912 return current_color_pixel;
01913 }
01914 }
01915
01916
01917 difference = 0xFFFFFF;
01918
01919 for(i = 0, result = 0; i < total_colors; i++)
01920 {
01921 test = abs((int)(color_table[i][0] - color));
01922
01923 if(test < difference)
01924 {
01925 current_color_pixel = color_table[i][1];
01926 difference = test;
01927 }
01928 }
01929
01930 return current_color_pixel;
01931 }
01932 break;
01933
01934 case BC_RGB565:
01935 return get_color_rgb16(color);
01936 break;
01937
01938 case BC_BGR565:
01939 return get_color_bgr16(color);
01940 break;
01941
01942 case BC_RGB888:
01943 case BC_BGR888:
01944 if(client_byte_order == server_byte_order)
01945 return color;
01946 else
01947 get_color_bgr24(color);
01948 break;
01949
01950 default:
01951 return color;
01952 break;
01953 }
01954 return 0;
01955 }
01956
01957 int BC_WindowBase::get_color_rgb8(int color)
01958 {
01959 int pixel;
01960
01961 pixel = (color & 0xc00000) >> 16;
01962 pixel += (color & 0xe000) >> 10;
01963 pixel += (color & 0xe0) >> 5;
01964 return pixel;
01965 }
01966
01967 int64_t BC_WindowBase::get_color_rgb16(int color)
01968 {
01969 int64_t result;
01970 result = (color & 0xf80000) >> 8;
01971 result += (color & 0xfc00) >> 5;
01972 result += (color & 0xf8) >> 3;
01973
01974 return result;
01975 }
01976
01977 int64_t BC_WindowBase::get_color_bgr16(int color)
01978 {
01979 int64_t result;
01980 result = (color & 0xf80000) >> 19;
01981 result += (color & 0xfc00) >> 5;
01982 result += (color & 0xf8) << 8;
01983
01984 return result;
01985 }
01986
01987 int64_t BC_WindowBase::get_color_bgr24(int color)
01988 {
01989 int64_t result;
01990 result = (color & 0xff) << 16;
01991 result += (color & 0xff00);
01992 result += (color & 0xff0000) >> 16;
01993 return result;
01994 }
01995
01996 void BC_WindowBase::start_video()
01997 {
01998 cursor_timer->update();
01999 video_on = 1;
02000
02001
02002
02003 }
02004
02005 void BC_WindowBase::stop_video()
02006 {
02007 video_on = 0;
02008 unhide_cursor();
02009 }
02010
02011
02012
02013 int64_t BC_WindowBase::get_color()
02014 {
02015 return top_level->current_color;
02016 }
02017
02018 void BC_WindowBase::set_color(int64_t color)
02019 {
02020 top_level->current_color = color;
02021 XSetForeground(top_level->display,
02022 top_level->gc,
02023 top_level->get_color(color));
02024 }
02025
02026 void BC_WindowBase::set_opaque()
02027 {
02028 XSetFunction(top_level->display, top_level->gc, GXcopy);
02029 }
02030
02031 void BC_WindowBase::set_inverse()
02032 {
02033 XSetFunction(top_level->display, top_level->gc, GXxor);
02034 }
02035
02036 Cursor BC_WindowBase::get_cursor_struct(int cursor)
02037 {
02038 switch(cursor)
02039 {
02040 case ARROW_CURSOR: return top_level->arrow_cursor; break;
02041 case CROSS_CURSOR: return top_level->cross_cursor;
02042 case IBEAM_CURSOR: return top_level->ibeam_cursor; break;
02043 case VSEPARATE_CURSOR: return top_level->vseparate_cursor; break;
02044 case HSEPARATE_CURSOR: return top_level->hseparate_cursor; break;
02045 case MOVE_CURSOR: return top_level->move_cursor; break;
02046 case LEFT_CURSOR: return top_level->left_cursor; break;
02047 case RIGHT_CURSOR: return top_level->right_cursor; break;
02048 case UPRIGHT_ARROW_CURSOR: return top_level->upright_arrow_cursor; break;
02049 case UPLEFT_RESIZE: return top_level->upleft_resize_cursor; break;
02050 case UPRIGHT_RESIZE: return top_level->upright_resize_cursor; break;
02051 case DOWNLEFT_RESIZE: return top_level->downleft_resize_cursor; break;
02052 case DOWNRIGHT_RESIZE: return top_level->downright_resize_cursor; break;
02053 case HOURGLASS_CURSOR: return top_level->hourglass_cursor; break;
02054 case TRANSPARENT_CURSOR: return top_level->transparent_cursor; break;
02055 }
02056 return 0;
02057 }
02058
02059 void BC_WindowBase::set_cursor(int cursor, int override)
02060 {
02061
02062 if((!top_level->is_hourglass && !is_transparent) ||
02063 override)
02064 {
02065 XDefineCursor(top_level->display, win, get_cursor_struct(cursor));
02066 flush();
02067 }
02068
02069 if(!override) current_cursor = cursor;
02070 }
02071
02072 void BC_WindowBase::set_x_cursor(int cursor)
02073 {
02074 temp_cursor = XCreateFontCursor(top_level->display, cursor);
02075 XDefineCursor(top_level->display, win, temp_cursor);
02076 current_cursor = cursor;
02077 flush();
02078 }
02079
02080 int BC_WindowBase::get_cursor()
02081 {
02082 return current_cursor;
02083 }
02084
02085 void BC_WindowBase::start_hourglass()
02086 {
02087 top_level->start_hourglass_recursive();
02088 top_level->flush();
02089 }
02090
02091 void BC_WindowBase::stop_hourglass()
02092 {
02093 top_level->stop_hourglass_recursive();
02094 top_level->flush();
02095 }
02096
02097 void BC_WindowBase::start_hourglass_recursive()
02098 {
02099 if(this == top_level)
02100 {
02101 hourglass_total++;
02102 is_hourglass = 1;
02103 }
02104
02105 if(!is_transparent)
02106 {
02107 set_cursor(HOURGLASS_CURSOR, 1);
02108 for(int i = 0; i < subwindows->total; i++)
02109 {
02110 subwindows->values[i]->start_hourglass_recursive();
02111 }
02112 }
02113 }
02114
02115 void BC_WindowBase::stop_hourglass_recursive()
02116 {
02117 if(this == top_level)
02118 {
02119 if(hourglass_total == 0) return;
02120 top_level->hourglass_total--;
02121 }
02122
02123 if(!top_level->hourglass_total)
02124 {
02125 top_level->is_hourglass = 0;
02126
02127
02128 if(!is_transparent)
02129 set_cursor(current_cursor, 1);
02130
02131 for(int i = 0; i < subwindows->total; i++)
02132 {
02133 subwindows->values[i]->stop_hourglass_recursive();
02134 }
02135 }
02136 }
02137
02138
02139
02140
02141
02142
02143 XFontStruct* BC_WindowBase::get_font_struct(int font)
02144 {
02145
02146 if(font & BOLDFACE) font ^= BOLDFACE;
02147
02148 switch(font)
02149 {
02150 case MEDIUMFONT: return top_level->mediumfont; break;
02151 case SMALLFONT: return top_level->smallfont; break;
02152 case LARGEFONT: return top_level->largefont; break;
02153 }
02154 return 0;
02155 }
02156
02157 XFontSet BC_WindowBase::get_fontset(int font)
02158 {
02159 XFontSet fs = 0;
02160
02161 if(get_resources()->use_fontset)
02162 {
02163 switch(font)
02164 {
02165 case SMALLFONT: fs = top_level->smallfontset; break;
02166 case LARGEFONT: fs = top_level->largefontset; break;
02167 case MEDIUMFONT: fs = top_level->mediumfontset; break;
02168 }
02169 }
02170
02171 return fs;
02172 }
02173
02174 #ifdef HAVE_XFT
02175 XftFont* BC_WindowBase::get_xft_struct(int font)
02176 {
02177
02178 if(font & BOLDFACE) font ^= BOLDFACE;
02179
02180 switch(font)
02181 {
02182 case MEDIUMFONT: return (XftFont*)top_level->mediumfont_xft; break;
02183 case SMALLFONT: return (XftFont*)top_level->smallfont_xft; break;
02184 case LARGEFONT: return (XftFont*)top_level->largefont_xft; break;
02185 }
02186
02187 return 0;
02188 }
02189 #endif
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201 void BC_WindowBase::set_font(int font)
02202 {
02203 top_level->current_font = font;
02204
02205
02206 #ifdef HAVE_XFT
02207 if(get_resources()->use_xft)
02208 {
02209 ;
02210 }
02211 else
02212 #endif
02213 if(get_resources()->use_fontset)
02214 {
02215 set_fontset(font);
02216 }
02217
02218 if(get_font_struct(font))
02219 {
02220 XSetFont(top_level->display, top_level->gc, get_font_struct(font)->fid);
02221 }
02222
02223 return;
02224 }
02225
02226 void BC_WindowBase::set_fontset(int font)
02227 {
02228 XFontSet fs = 0;
02229
02230 if(get_resources()->use_fontset)
02231 {
02232 switch(font)
02233 {
02234 case SMALLFONT: fs = top_level->smallfontset; break;
02235 case LARGEFONT: fs = top_level->largefontset; break;
02236 case MEDIUMFONT: fs = top_level->mediumfontset; break;
02237 }
02238 }
02239
02240 curr_fontset = fs;
02241 }
02242
02243
02244 XFontSet BC_WindowBase::get_curr_fontset(void)
02245 {
02246 if(get_resources()->use_fontset)
02247 return curr_fontset;
02248 return 0;
02249 }
02250
02251 int BC_WindowBase::get_single_text_width(int font, char *text, int length)
02252 {
02253 #ifdef HAVE_XFT
02254 if(get_resources()->use_xft && get_xft_struct(font))
02255 {
02256 XGlyphInfo extents;
02257 XftTextExtents8(top_level->display,
02258 get_xft_struct(font),
02259 (FcChar8*)text,
02260 length,
02261 &extents);
02262 return extents.xOff;
02263 }
02264 else
02265 #endif
02266 if(get_resources()->use_fontset && top_level->get_fontset(font))
02267 return XmbTextEscapement(top_level->get_fontset(font), text, length);
02268 else
02269 if(get_font_struct(font))
02270 return XTextWidth(get_font_struct(font), text, length);
02271 else
02272 {
02273 int w = 0;
02274 switch(font)
02275 {
02276 case MEDIUM_7SEGMENT:
02277 return get_resources()->medium_7segment[0]->get_w() * length;
02278 break;
02279
02280 default:
02281 return 0;
02282 }
02283 return w;
02284 }
02285 }
02286
02287 int BC_WindowBase::get_text_width(int font, char *text, int length)
02288 {
02289 int i, j, w = 0, line_w = 0;
02290 if(length < 0) length = strlen(text);
02291
02292 for(i = 0, j = 0; i <= length; i++)
02293 {
02294 line_w = 0;
02295 if(text[i] == '\n')
02296 {
02297 line_w = get_single_text_width(font, &text[j], i - j);
02298 j = i + 1;
02299 }
02300 else
02301 if(text[i] == 0)
02302 {
02303 line_w = get_single_text_width(font, &text[j], length - j);
02304 }
02305 if(line_w > w) w = line_w;
02306 }
02307
02308 if(i > length && w == 0)
02309 {
02310 w = get_single_text_width(font, text, length);
02311 }
02312
02313 return w;
02314 }
02315
02316 int BC_WindowBase::get_text_ascent(int font)
02317 {
02318 #ifdef HAVE_XFT
02319 if(get_resources()->use_xft && get_xft_struct(font))
02320 {
02321 XGlyphInfo extents;
02322 XftTextExtents8(top_level->display,
02323 get_xft_struct(font),
02324 (FcChar8*)"O",
02325 1,
02326 &extents);
02327 return extents.y + 2;
02328 }
02329 else
02330 #endif
02331 if(get_resources()->use_fontset && top_level->get_fontset(font))
02332 {
02333 XFontSetExtents *extents;
02334
02335 extents = XExtentsOfFontSet(top_level->get_fontset(font));
02336 return -extents->max_logical_extent.y;
02337 }
02338 else
02339 if(get_font_struct(font))
02340 return top_level->get_font_struct(font)->ascent;
02341 else
02342 switch(font)
02343 {
02344 case MEDIUM_7SEGMENT:
02345 return get_resources()->medium_7segment[0]->get_h();
02346 break;
02347
02348 default:
02349 return 0;
02350 }
02351 }
02352
02353 int BC_WindowBase::get_text_descent(int font)
02354 {
02355 #ifdef HAVE_XFT
02356 if(get_resources()->use_xft && get_xft_struct(font))
02357 {
02358 XGlyphInfo extents;
02359 XftTextExtents8(top_level->display,
02360 get_xft_struct(font),
02361 (FcChar8*)"j",
02362 1,
02363 &extents);
02364 return extents.height - extents.y;
02365 }
02366 else
02367 #endif
02368 if(get_resources()->use_fontset && top_level->get_fontset(font))
02369 {
02370 XFontSetExtents *extents;
02371
02372 extents = XExtentsOfFontSet(top_level->get_fontset(font));
02373 return (extents->max_logical_extent.height
02374 + extents->max_logical_extent.y);
02375 }
02376 else
02377 if(get_font_struct(font))
02378 return top_level->get_font_struct(font)->descent;
02379 else
02380 switch(font)
02381 {
02382 default:
02383 return 0;
02384 }
02385 }
02386
02387 int BC_WindowBase::get_text_height(int font, char *text)
02388 {
02389 if(!text) return get_text_ascent(font) + get_text_descent(font);
02390
02391
02392 int h = 0, i, length = strlen(text);
02393 for(i = 0; i <= length; i++)
02394 {
02395 if(text[i] == '\n')
02396 h++;
02397 else
02398 if(text[i] == 0)
02399 h++;
02400 }
02401 return h * (get_text_ascent(font) + get_text_descent(font));
02402 }
02403
02404 BC_Bitmap* BC_WindowBase::new_bitmap(int w, int h, int color_model)
02405 {
02406 if(color_model < 0) color_model = top_level->get_color_model();
02407 return new BC_Bitmap(top_level, w, h, color_model);
02408 }
02409
02410 int BC_WindowBase::accel_available(int color_model, int lock_it)
02411 {
02412 if(window_type != MAIN_WINDOW)
02413 return top_level->accel_available(color_model, lock_it);
02414
02415 int result = 0;
02416
02417 if(lock_it) lock_window("BC_WindowBase::accel_available");
02418 switch(color_model)
02419 {
02420 case BC_YUV420P:
02421 result = grab_port_id(this, color_model);
02422 if(result >= 0)
02423 {
02424 xvideo_port_id = result;
02425 result = 1;
02426 }
02427 else
02428 result = 0;
02429 break;
02430
02431 case BC_YUV422P:
02432 result = 0;
02433 break;
02434
02435 case BC_YUV422:
02436
02437 result = grab_port_id(this, color_model);
02438
02439 if(result >= 0)
02440 {
02441 xvideo_port_id = result;
02442 result = 1;
02443 }
02444 else
02445 result = 0;
02446
02447 break;
02448
02449 default:
02450 result = 0;
02451 break;
02452 }
02453
02454 if(lock_it) unlock_window();
02455
02456 return result;
02457 }
02458
02459
02460 int BC_WindowBase::grab_port_id(BC_WindowBase *window, int color_model)
02461 {
02462 int numFormats, i, j, k;
02463 unsigned int ver, rev, numAdapt, reqBase, eventBase, errorBase;
02464 int port_id = -1;
02465 XvAdaptorInfo *info;
02466 XvImageFormatValues *formats;
02467 int x_color_model;
02468
02469 if(!get_resources()->use_xvideo) return -1;
02470
02471
02472 x_color_model = cmodel_bc_to_x(color_model);
02473
02474
02475 if(!resources.use_shm) return -1;
02476
02477
02478 if(Success != XvQueryExtension(window->display,
02479 &ver,
02480 &rev,
02481 &reqBase,
02482 &eventBase,
02483 &errorBase))
02484 {
02485 return -1;
02486 }
02487
02488
02489 XvQueryAdaptors(window->display,
02490 DefaultRootWindow(window->display),
02491 &numAdapt,
02492 &info);
02493
02494 if(!numAdapt)
02495 {
02496 return -1;
02497 }
02498
02499
02500 for(i = 0; i < numAdapt && xvideo_port_id == -1; i++)
02501 {
02502
02503 if(info[i].type & XvImageMask)
02504 {
02505 formats = XvListImageFormats(window->display,
02506 info[i].base_id,
02507 &numFormats);
02508
02509
02510
02511 for(j = 0; j < numFormats && xvideo_port_id < 0; j++)
02512 {
02513
02514 if(formats[j].id == x_color_model)
02515 {
02516
02517 for(k = 0; k < info[i].num_ports; k++)
02518 {
02519
02520 if(Success == XvGrabPort(top_level->display,
02521 info[i].base_id + k,
02522 CurrentTime))
02523 {
02524
02525 xvideo_port_id = info[i].base_id + k;
02526 break;
02527 }
02528 }
02529 }
02530 }
02531 if(formats) XFree(formats);
02532 }
02533 }
02534
02535 XvFreeAdaptorInfo(info);
02536
02537 return xvideo_port_id;
02538 }
02539
02540
02541 int BC_WindowBase::show_window(int flush)
02542 {
02543 XMapWindow(top_level->display, win);
02544 if(flush) XFlush(top_level->display);
02545
02546 hidden = 0;
02547 return 0;
02548 }
02549
02550 int BC_WindowBase::hide_window(int flush)
02551 {
02552 XUnmapWindow(top_level->display, win);
02553 if(flush) XFlush(top_level->display);
02554 hidden = 1;
02555 return 0;
02556 }
02557
02558 BC_MenuBar* BC_WindowBase::add_menubar(BC_MenuBar *menu_bar)
02559 {
02560 subwindows->append((BC_SubWindow*)menu_bar);
02561
02562 menu_bar->parent_window = this;
02563 menu_bar->top_level = this->top_level;
02564 menu_bar->initialize();
02565 return menu_bar;
02566 }
02567
02568 BC_WindowBase* BC_WindowBase::add_subwindow(BC_WindowBase *subwindow)
02569 {
02570 subwindows->append(subwindow);
02571
02572 if(subwindow->bg_color == -1) subwindow->bg_color = this->bg_color;
02573
02574
02575 subwindow->parent_window = this;
02576 subwindow->top_level = this->top_level;
02577
02578
02579 subwindow->initialize();
02580 return subwindow;
02581 }
02582
02583
02584 BC_WindowBase* BC_WindowBase::add_tool(BC_WindowBase *subwindow)
02585 {
02586 return add_subwindow(subwindow);
02587 }
02588
02589 BC_WidgetGrid* BC_WindowBase::add_widgetgrid(BC_WidgetGrid *widgetgrid)
02590 {
02591 widgetgrids->append(widgetgrid);
02592 return widgetgrid;
02593 }
02594
02595
02596 int BC_WindowBase::flash(int x, int y, int w, int h, int flush)
02597 {
02598 set_opaque();
02599 XSetWindowBackgroundPixmap(top_level->display, win, pixmap->opaque_pixmap);
02600 if(x >= 0)
02601 {
02602 XClearArea(top_level->display, win, x, y, w, h, 0);
02603 }
02604 else
02605 {
02606 XClearWindow(top_level->display, win);
02607 }
02608
02609 if(flush)
02610 this->flush();
02611 return 0;
02612 }
02613
02614 int BC_WindowBase::flash(int flush)
02615 {
02616 flash(-1, -1, -1, -1, flush);
02617 }
02618
02619 void BC_WindowBase::flush()
02620 {
02621 XFlush(top_level->display);
02622 }
02623
02624 void BC_WindowBase::sync_display()
02625 {
02626 XSync(top_level->display, False);
02627 }
02628
02629 int BC_WindowBase::get_window_lock()
02630 {
02631 return top_level->window_lock;
02632 }
02633
02634 int BC_WindowBase::lock_window(char *location)
02635 {
02636 if(top_level && top_level != this)
02637 {
02638 top_level->lock_window(location);
02639 }
02640 else
02641 if(top_level)
02642 {
02643 SET_LOCK(this, title, location);
02644 XLockDisplay(top_level->display);
02645 SET_LOCK2
02646 top_level->window_lock = 1;
02647 }
02648 else
02649 {
02650 printf("BC_WindowBase::lock_window top_level NULL\n");
02651 }
02652 return 0;
02653 }
02654
02655 int BC_WindowBase::unlock_window()
02656 {
02657 if(top_level && top_level != this)
02658 {
02659 top_level->unlock_window();
02660 }
02661 else
02662 if(top_level)
02663 {
02664 UNSET_LOCK(this);
02665 top_level->window_lock = 0;
02666 XUnlockDisplay(top_level->display);
02667 }
02668 else
02669 {
02670 printf("BC_WindowBase::unlock_window top_level NULL\n");
02671 }
02672 return 0;
02673 }
02674
02675 void BC_WindowBase::set_done(int return_value)
02676 {
02677 if(window_type != MAIN_WINDOW)
02678 top_level->set_done(return_value);
02679 else
02680 {
02681 XEvent *event = new XEvent;
02682 XClientMessageEvent *ptr = (XClientMessageEvent*)event;
02683
02684 event->type = ClientMessage;
02685 ptr->message_type = SetDoneXAtom;
02686 ptr->format = 32;
02687 this->return_value = return_value;
02688
02689
02690
02691
02692
02693
02694
02695 put_event(event);
02696 }
02697 }
02698
02699 int BC_WindowBase::get_w()
02700 {
02701 return w;
02702 }
02703
02704 int BC_WindowBase::get_h()
02705 {
02706 return h;
02707 }
02708
02709 int BC_WindowBase::get_x()
02710 {
02711 return x;
02712 }
02713
02714 int BC_WindowBase::get_y()
02715 {
02716 return y;
02717 }
02718
02719 int BC_WindowBase::get_root_w(int ignore_dualhead, int lock_display)
02720 {
02721 if(lock_display) lock_window("BC_WindowBase::get_root_w");
02722 Screen *screen_ptr = XDefaultScreenOfDisplay(display);
02723 int result = WidthOfScreen(screen_ptr);
02724
02725 if(!ignore_dualhead) if((float)result / HeightOfScreen(screen_ptr) > 1.8) result /= 2;
02726
02727 if(lock_display) unlock_window();
02728 return result;
02729 }
02730
02731 int BC_WindowBase::get_root_h(int lock_display)
02732 {
02733 if(lock_display) lock_window("BC_WindowBase::get_root_h");
02734 Screen *screen_ptr = XDefaultScreenOfDisplay(display);
02735 int result = HeightOfScreen(screen_ptr);
02736 if(lock_display) unlock_window();
02737 return result;
02738 }
02739
02740
02741 int BC_WindowBase::get_x2()
02742 {
02743 return w + x;
02744 }
02745
02746 int BC_WindowBase::get_y2()
02747 {
02748 return y + h;
02749 }
02750
02751 int BC_WindowBase::get_video_on()
02752 {
02753 return video_on;
02754 }
02755
02756 int BC_WindowBase::get_hidden()
02757 {
02758 return top_level->hidden;
02759 }
02760
02761 int BC_WindowBase::cursor_inside()
02762 {
02763 return (top_level->cursor_x >= 0 &&
02764 top_level->cursor_y >= 0 &&
02765 top_level->cursor_x < w &&
02766 top_level->cursor_y < h);
02767 }
02768
02769 BC_WindowBase* BC_WindowBase::get_top_level()
02770 {
02771 return top_level;
02772 }
02773
02774 BC_WindowBase* BC_WindowBase::get_parent()
02775 {
02776 return parent_window;
02777 }
02778
02779 int BC_WindowBase::get_color_model()
02780 {
02781 return top_level->color_model;
02782 }
02783
02784 BC_Resources* BC_WindowBase::get_resources()
02785 {
02786 return &BC_WindowBase::resources;
02787 }
02788
02789 BC_Synchronous* BC_WindowBase::get_synchronous()
02790 {
02791 return BC_WindowBase::resources.get_synchronous();
02792 }
02793
02794 int BC_WindowBase::get_bg_color()
02795 {
02796 return bg_color;
02797 }
02798
02799 BC_Pixmap* BC_WindowBase::get_bg_pixmap()
02800 {
02801 return bg_pixmap;
02802 }
02803
02804 void BC_WindowBase::set_active_subwindow(BC_WindowBase *subwindow)
02805 {
02806 top_level->active_subwindow = subwindow;
02807 }
02808
02809 int BC_WindowBase::activate()
02810 {
02811 return 0;
02812 }
02813
02814 int BC_WindowBase::deactivate()
02815 {
02816 if(window_type == MAIN_WINDOW)
02817 {
02818 if(top_level->active_menubar) top_level->active_menubar->deactivate();
02819 if(top_level->active_popup_menu) top_level->active_popup_menu->deactivate();
02820 if(top_level->active_subwindow) top_level->active_subwindow->deactivate();
02821
02822 top_level->active_menubar = 0;
02823 top_level->active_popup_menu = 0;
02824 top_level->active_subwindow = 0;
02825 }
02826 return 0;
02827 }
02828
02829 int BC_WindowBase::cycle_textboxes(int amount)
02830 {
02831 int result = 0;
02832 BC_WindowBase *new_textbox = 0;
02833
02834 if(amount > 0)
02835 {
02836 BC_WindowBase *first_textbox = 0;
02837 find_next_textbox(&first_textbox, &new_textbox, result);
02838 if(!new_textbox) new_textbox = first_textbox;
02839
02840 }
02841 else
02842 if(amount < 0)
02843 {
02844 BC_WindowBase *last_textbox = 0;
02845 find_prev_textbox(&last_textbox, &new_textbox, result);
02846 if(!new_textbox) new_textbox = last_textbox;
02847
02848 }
02849
02850 if(new_textbox != active_subwindow)
02851 {
02852 deactivate();
02853 new_textbox->activate();
02854 }
02855
02856 return 0;
02857 }
02858
02859 int BC_WindowBase::find_next_textbox(BC_WindowBase **first_textbox, BC_WindowBase **next_textbox, int &result)
02860 {
02861
02862 for(int i = 0; i < subwindows->total && result < 2; i++)
02863 {
02864 BC_WindowBase *test_subwindow = subwindows->values[i];
02865 test_subwindow->find_next_textbox(first_textbox, next_textbox, result);
02866 }
02867
02868 if(result < 2)
02869 {
02870 if(uses_text())
02871 {
02872 if(!*first_textbox) *first_textbox = this;
02873
02874 if(result < 1)
02875 {
02876 if(top_level->active_subwindow == this)
02877 result++;
02878 }
02879 else
02880 {
02881 result++;
02882 *next_textbox = this;
02883 }
02884 }
02885 }
02886 return 0;
02887 }
02888
02889 int BC_WindowBase::find_prev_textbox(BC_WindowBase **last_textbox, BC_WindowBase **prev_textbox, int &result)
02890 {
02891 if(result < 2)
02892 {
02893 if(uses_text())
02894 {
02895 if(!*last_textbox) *last_textbox = this;
02896
02897 if(result < 1)
02898 {
02899 if(top_level->active_subwindow == this)
02900 result++;
02901 }
02902 else
02903 {
02904 result++;
02905 *prev_textbox = this;
02906 }
02907 }
02908 }
02909
02910
02911 for(int i = subwindows->total - 1; i >= 0 && result < 2; i--)
02912 {
02913 BC_WindowBase *test_subwindow = subwindows->values[i];
02914 test_subwindow->find_prev_textbox(last_textbox, prev_textbox, result);
02915 }
02916 return 0;
02917 }
02918
02919 BC_Clipboard* BC_WindowBase::get_clipboard()
02920 {
02921 return top_level->clipboard;
02922 }
02923
02924 int BC_WindowBase::get_relative_cursor_x()
02925 {
02926 int abs_x, abs_y, x, y, win_x, win_y;
02927 unsigned int temp_mask;
02928 Window temp_win;
02929
02930 XQueryPointer(top_level->display,
02931 top_level->win,
02932 &temp_win,
02933 &temp_win,
02934 &abs_x,
02935 &abs_y,
02936 &win_x,
02937 &win_y,
02938 &temp_mask);
02939
02940 XTranslateCoordinates(top_level->display,
02941 top_level->rootwin,
02942 win,
02943 abs_x,
02944 abs_y,
02945 &x,
02946 &y,
02947 &temp_win);
02948
02949 return x;
02950 }
02951
02952 int BC_WindowBase::get_relative_cursor_y()
02953 {
02954 int abs_x, abs_y, x, y, win_x, win_y;
02955 unsigned int temp_mask;
02956 Window temp_win;
02957
02958 XQueryPointer(top_level->display,
02959 top_level->win,
02960 &temp_win,
02961 &temp_win,
02962 &abs_x,
02963 &abs_y,
02964 &win_x,
02965 &win_y,
02966 &temp_mask);
02967
02968 XTranslateCoordinates(top_level->display,
02969 top_level->rootwin,
02970 win,
02971 abs_x,
02972 abs_y,
02973 &x,
02974 &y,
02975 &temp_win);
02976
02977 return y;
02978 }
02979
02980 int BC_WindowBase::get_abs_cursor_x(int lock_window)
02981 {
02982 int abs_x, abs_y, win_x, win_y;
02983 unsigned int temp_mask;
02984 Window temp_win;
02985
02986 if(lock_window) this->lock_window("BC_WindowBase::get_abs_cursor_x");
02987 XQueryPointer(top_level->display,
02988 top_level->win,
02989 &temp_win,
02990 &temp_win,
02991 &abs_x,
02992 &abs_y,
02993 &win_x,
02994 &win_y,
02995 &temp_mask);
02996 if(lock_window) this->unlock_window();
02997 return abs_x;
02998 }
02999
03000 int BC_WindowBase::get_abs_cursor_y(int lock_window)
03001 {
03002 int abs_x, abs_y, win_x, win_y;
03003 unsigned int temp_mask;
03004 Window temp_win;
03005
03006 if(lock_window) this->lock_window("BC_WindowBase::get_abs_cursor_y");
03007 XQueryPointer(top_level->display,
03008 top_level->win,
03009 &temp_win,
03010 &temp_win,
03011 &abs_x,
03012 &abs_y,
03013 &win_x,
03014 &win_y,
03015 &temp_mask);
03016 if(lock_window) this->unlock_window();
03017 return abs_y;
03018 }
03019
03020 int BC_WindowBase::match_window(Window win)
03021 {
03022 if (this->win == win) return 1;
03023 int result = 0;
03024 for(int i = 0; i < subwindows->total; i++)
03025 {
03026 result = subwindows->values[i]->match_window(win);
03027 if (result) return result;
03028 }
03029 return 0;
03030
03031 }
03032
03033 int BC_WindowBase::get_cursor_over_window()
03034 {
03035 if(top_level != this) return top_level->get_cursor_over_window();
03036
03037 int abs_x, abs_y, win_x, win_y;
03038 unsigned int temp_mask;
03039 Window temp_win1, temp_win2;
03040
03041 if (!XQueryPointer(display,
03042 win,
03043 &temp_win1,
03044 &temp_win2,
03045 &abs_x,
03046 &abs_y,
03047 &win_x,
03048 &win_y,
03049 &temp_mask))
03050 return 0;
03051
03052 int result = match_window(temp_win2) ;
03053 return result;
03054 }
03055
03056 int BC_WindowBase::relative_cursor_x(BC_WindowBase *pov)
03057 {
03058 int x, y;
03059 Window tempwin;
03060
03061 translate_coordinates(top_level->event_win,
03062 pov->win,
03063 top_level->cursor_x,
03064 top_level->cursor_y,
03065 &x,
03066 &y);
03067 return x;
03068 }
03069
03070 int BC_WindowBase::relative_cursor_y(BC_WindowBase *pov)
03071 {
03072 int x, y;
03073 Window tempwin;
03074
03075 translate_coordinates(top_level->event_win,
03076 pov->win,
03077 top_level->cursor_x,
03078 top_level->cursor_y,
03079 &x,
03080 &y);
03081 return y;
03082 }
03083
03084 int BC_WindowBase::get_drag_x()
03085 {
03086 return top_level->drag_x;
03087 }
03088
03089 int BC_WindowBase::get_drag_y()
03090 {
03091 return top_level->drag_y;
03092 }
03093
03094 int BC_WindowBase::get_cursor_x()
03095 {
03096 return top_level->cursor_x;
03097 }
03098
03099 int BC_WindowBase::get_cursor_y()
03100 {
03101 return top_level->cursor_y;
03102 }
03103
03104 int BC_WindowBase::is_event_win()
03105 {
03106 return this->win == top_level->event_win;
03107 }
03108
03109 void BC_WindowBase::set_dragging(int value)
03110 {
03111 is_dragging = value;
03112 }
03113
03114 int BC_WindowBase::get_dragging()
03115 {
03116 return is_dragging;
03117 }
03118
03119 int BC_WindowBase::get_buttonpress()
03120 {
03121 return top_level->button_number;
03122 }
03123
03124 int BC_WindowBase::get_button_down()
03125 {
03126 return top_level->button_down;
03127 }
03128
03129 int BC_WindowBase::alt_down()
03130 {
03131 return top_level->alt_mask;
03132 }
03133
03134 int BC_WindowBase::shift_down()
03135 {
03136 return top_level->shift_mask;
03137 }
03138
03139 int BC_WindowBase::ctrl_down()
03140 {
03141 return top_level->ctrl_mask;
03142 }
03143
03144
03145 int BC_WindowBase::get_keypress()
03146 {
03147 return top_level->key_pressed;
03148 }
03149
03150 int BC_WindowBase::get_double_click()
03151 {
03152 return top_level->double_click;
03153 }
03154
03155 int BC_WindowBase::get_bgcolor()
03156 {
03157 return bg_color;
03158 }
03159
03160 int BC_WindowBase::resize_window(int w, int h)
03161 {
03162 if(window_type == MAIN_WINDOW && !allow_resize)
03163 {
03164 XSizeHints size_hints;
03165 size_hints.flags = PSize | PMinSize | PMaxSize;
03166 size_hints.width = w;
03167 size_hints.height = h;
03168 size_hints.min_width = w;
03169 size_hints.max_width = w;
03170 size_hints.min_height = h;
03171 size_hints.max_height = h;
03172 XSetNormalHints(top_level->display, win, &size_hints);
03173 }
03174 XResizeWindow(top_level->display, win, w, h);
03175
03176 this->w = w;
03177 this->h = h;
03178 delete pixmap;
03179 pixmap = new BC_Pixmap(this, w, h);
03180
03181
03182 for(int i = 0; i < subwindows->total; i++)
03183 {
03184 subwindows->values[i]->dispatch_resize_event(w, h);
03185 }
03186
03187 draw_background(0, 0, w, h);
03188 if(top_level == this && get_resources()->recursive_resizing)
03189 resize_history.append(new BC_ResizeCall(w, h));
03190 return 0;
03191 }
03192
03193
03194 int BC_WindowBase::resize_event(int w, int h)
03195 {
03196 if(window_type == MAIN_WINDOW)
03197 {
03198 this->w = w;
03199 this->h = h;
03200 }
03201 return 0;
03202 }
03203
03204 int BC_WindowBase::reposition_widget(int x, int y, int w, int h)
03205 {
03206 return(reposition_window(x, y, w, h));
03207 }
03208
03209 int BC_WindowBase::reposition_window(int x, int y, int w, int h)
03210 {
03211 int resize = 0;
03212
03213
03214
03215 this->x = x;
03216 this->y = y;
03217
03218 if(w > 0 && w != this->w)
03219 {
03220 resize = 1;
03221 this->w = w;
03222 }
03223
03224 if(h > 0 && h != this->h)
03225 {
03226 resize = 1;
03227 this->h = h;
03228 }
03229
03230
03231
03232 if(this->w <= 0)
03233 printf("BC_WindowBase::reposition_window this->w == %d\n", this->w);
03234 if(this->h <= 0)
03235 printf("BC_WindowBase::reposition_window this->h == %d\n", this->h);
03236
03237 if(translation_count && window_type == MAIN_WINDOW)
03238 {
03239
03240
03241 XMoveResizeWindow(top_level->display,
03242 win,
03243 x + BC_DisplayInfo::left_border - BC_DisplayInfo::auto_reposition_x,
03244 y + BC_DisplayInfo::top_border - BC_DisplayInfo::auto_reposition_y,
03245 this->w,
03246 this->h);
03247 }
03248 else
03249 {
03250 XMoveResizeWindow(top_level->display,
03251 win,
03252 x,
03253 y,
03254 this->w,
03255 this->h);
03256 }
03257
03258 if(resize)
03259 {
03260 delete pixmap;
03261 pixmap = new BC_Pixmap(this, this->w, this->h);
03262
03263 for(int i = 0; i < subwindows->total; i++)
03264 {
03265 subwindows->values[i]->dispatch_resize_event(this->w, this->h);
03266 }
03267
03268
03269 }
03270
03271 return 0;
03272 }
03273
03274 int BC_WindowBase::set_tooltips(int tooltips_enabled)
03275 {
03276 get_resources()->tooltips_enabled = tooltips_enabled;
03277 return 0;
03278 }
03279
03280 int BC_WindowBase::raise_window(int do_flush)
03281 {
03282 XRaiseWindow(top_level->display, win);
03283 if(do_flush) XFlush(top_level->display);
03284 return 0;
03285 }
03286
03287 void BC_WindowBase::set_background(VFrame *bitmap)
03288 {
03289 if(bg_pixmap && !shared_bg_pixmap) delete bg_pixmap;
03290
03291 bg_pixmap = new BC_Pixmap(this,
03292 bitmap,
03293 PIXMAP_OPAQUE);
03294 shared_bg_pixmap = 0;
03295 draw_background(0, 0, w, h);
03296 }
03297
03298 void BC_WindowBase::set_title(char *text)
03299 {
03300 XSetStandardProperties(top_level->display, top_level->win, text, text, None, 0, 0, 0);
03301 strcpy(this->title, _(text));
03302 flush();
03303 }
03304
03305 char* BC_WindowBase::get_title()
03306 {
03307 return title;
03308 }
03309
03310 int BC_WindowBase::get_toggle_value()
03311 {
03312 return toggle_value;
03313 }
03314
03315 int BC_WindowBase::get_toggle_drag()
03316 {
03317 return toggle_drag;
03318 }
03319
03320 int BC_WindowBase::set_icon(VFrame *data)
03321 {
03322 if(icon_pixmap) delete icon_pixmap;
03323 icon_pixmap = new BC_Pixmap(top_level,
03324 data,
03325 PIXMAP_ALPHA,
03326 1);
03327
03328 icon_window = new BC_Popup(this,
03329 (int)BC_INFINITY,
03330 (int)BC_INFINITY,
03331 icon_pixmap->get_w(),
03332 icon_pixmap->get_h(),
03333 -1,
03334 1,
03335 icon_pixmap);
03336
03337 XWMHints wm_hints;
03338 wm_hints.flags = WindowGroupHint | IconPixmapHint | IconMaskHint | IconWindowHint;
03339 wm_hints.icon_pixmap = icon_pixmap->get_pixmap();
03340 wm_hints.icon_mask = icon_pixmap->get_alpha();
03341 wm_hints.icon_window = icon_window->win;
03342 wm_hints.window_group = XGroupLeader;
03343
03344
03345
03346
03347
03348 XSetWMHints(top_level->display, top_level->win, &wm_hints);
03349 XSync(top_level->display, 0);
03350 return 0;
03351 }
03352
03353 int BC_WindowBase::set_w(int w)
03354 {
03355 this->w = w;
03356 return 0;
03357 }
03358
03359 int BC_WindowBase::set_h(int h)
03360 {
03361 this->h = h;
03362 return 0;
03363 }
03364
03365 int BC_WindowBase::load_defaults(BC_Hash *defaults)
03366 {
03367 BC_Resources *resources = get_resources();
03368 char string[BCTEXTLEN];
03369 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
03370 {
03371 sprintf(string, "FILEBOX_HISTORY%d", i);
03372 resources->filebox_history[i][0] = 0;
03373 defaults->get(string, resources->filebox_history[i]);
03374 }
03375 resources->filebox_mode = defaults->get("FILEBOX_MODE", get_resources()->filebox_mode);
03376 resources->filebox_w = defaults->get("FILEBOX_W", get_resources()->filebox_w);
03377 resources->filebox_h = defaults->get("FILEBOX_H", get_resources()->filebox_h);
03378 defaults->get("FILEBOX_FILTER", resources->filebox_filter);
03379 return 0;
03380 }
03381
03382 int BC_WindowBase::save_defaults(BC_Hash *defaults)
03383 {
03384 BC_Resources *resources = get_resources();
03385 char string[BCTEXTLEN];
03386 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
03387 {
03388 sprintf(string, "FILEBOX_HISTORY%d", i);
03389 defaults->update(string, resources->filebox_history[i]);
03390 }
03391 defaults->update("FILEBOX_MODE", resources->filebox_mode);
03392 defaults->update("FILEBOX_W", resources->filebox_w);
03393 defaults->update("FILEBOX_H", resources->filebox_h);
03394 defaults->update("FILEBOX_FILTER", resources->filebox_filter);
03395 return 0;
03396 }
03397
03398
03399
03400
03401
03402 void BC_WindowBase::translate_coordinates(Window src_w,
03403 Window dest_w,
03404 int src_x,
03405 int src_y,
03406 int *dest_x_return,
03407 int *dest_y_return)
03408 {
03409 Window tempwin = 0;
03410
03411
03412 if(src_w == dest_w)
03413 {
03414 *dest_x_return = src_x;
03415 *dest_y_return = src_y;
03416 }
03417 else
03418 {
03419 XTranslateCoordinates(top_level->display,
03420 src_w,
03421 dest_w,
03422 src_x,
03423 src_y,
03424 dest_x_return,
03425 dest_y_return,
03426 &tempwin);
03427
03428 }
03429 }
03430
03431
03432
03433
03434
03435
03436
03437 #ifdef HAVE_LIBXXF86VM
03438 void BC_WindowBase::closest_vm(int *vm, int *width, int *height)
03439 {
03440 int foo,bar;
03441 *vm = 0;
03442 if(XF86VidModeQueryExtension(top_level->display,&foo,&bar)) {
03443 int vm_count,i;
03444 XF86VidModeModeInfo **vm_modelines;
03445 XF86VidModeGetAllModeLines(top_level->display,XDefaultScreen(top_level->display),&vm_count,&vm_modelines);
03446 for (i = 0; i < vm_count; i++) {
03447 if (vm_modelines[i]->hdisplay < vm_modelines[*vm]->hdisplay && vm_modelines[i]->hdisplay >= *width)
03448 *vm = i;
03449 }
03450 display = top_level->display;
03451 if (vm_modelines[*vm]->hdisplay == *width)
03452 *vm = -1;
03453 else
03454 {
03455 *width = vm_modelines[*vm]->hdisplay;
03456 *height = vm_modelines[*vm]->vdisplay;
03457 }
03458 }
03459 }
03460
03461 void BC_WindowBase::scale_vm(int vm)
03462 {
03463 int foo,bar,dotclock;
03464 if(XF86VidModeQueryExtension(top_level->display,&foo,&bar))
03465 {
03466 int vm_count;
03467 XF86VidModeModeInfo **vm_modelines;
03468 XF86VidModeModeLine vml;
03469 XF86VidModeGetAllModeLines(top_level->display,XDefaultScreen(top_level->display),&vm_count,&vm_modelines);
03470 XF86VidModeGetModeLine(top_level->display,XDefaultScreen(top_level->display),&dotclock,&vml);
03471 orig_modeline.dotclock = dotclock;
03472 orig_modeline.hdisplay = vml.hdisplay;
03473 orig_modeline.hsyncstart = vml.hsyncstart;
03474 orig_modeline.hsyncend = vml.hsyncend;
03475 orig_modeline.htotal = vml.htotal;
03476 orig_modeline.vdisplay = vml.vdisplay;
03477 orig_modeline.vsyncstart = vml.vsyncstart;
03478 orig_modeline.vsyncend = vml.vsyncend;
03479 orig_modeline.vtotal = vml.vtotal;
03480 orig_modeline.flags = vml.flags;
03481 orig_modeline.privsize = vml.privsize;
03482
03483 XF86VidModeSwitchToMode(top_level->display,XDefaultScreen(top_level->display),vm_modelines[vm]);
03484 XF86VidModeSetViewPort(top_level->display,XDefaultScreen(top_level->display),0,0);
03485 XFlush(top_level->display);
03486 }
03487 }
03488
03489 void BC_WindowBase::restore_vm()
03490 {
03491 XF86VidModeSwitchToMode(top_level->display,XDefaultScreen(top_level->display),&orig_modeline);
03492 XFlush(top_level->display);
03493 }
03494
03495
03496 #endif
03497
03498
03499
03500
03501
03502
03503
03504
03505
03506
03507
03508
03509
03510
03511
03512
03513
03514
03515
03516 int BC_WindowBase::get_event_count()
03517 {
03518 event_lock->lock("BC_WindowBase::get_event_count");
03519 int result = common_events.total;
03520 event_lock->unlock();
03521 return result;
03522 }
03523
03524 XEvent* BC_WindowBase::get_event()
03525 {
03526 XEvent *result = 0;
03527 while(!done && !result)
03528 {
03529 event_condition->lock("BC_WindowBase::get_event");
03530 event_lock->lock("BC_WindowBase::get_event");
03531
03532 if(common_events.total && !done)
03533 {
03534 result = common_events.values[0];
03535 common_events.remove_number(0);
03536 }
03537
03538 event_lock->unlock();
03539 }
03540 return result;
03541 }
03542
03543 void BC_WindowBase::put_event(XEvent *event)
03544 {
03545 event_lock->lock("BC_WindowBase::put_event");
03546 common_events.append(event);
03547 event_lock->unlock();
03548 event_condition->unlock();
03549 }
03550
03551 int BC_WindowBase::get_id()
03552 {
03553 return id;
03554 }
03555
03556
03557
03558
03559