home *** CD-ROM | disk | FTP | other *** search
/ Geek 6 / Geek-006.iso / linux / video / xmovie-1.5.3.tar.gz / xmovie-1.5.3.tar / xmovie-1.5.3 / guicast / bcwindowbase.h < prev    next >
C/C++ Source or Header  |  2000-11-29  |  14KB  |  486 lines

  1. #ifndef BCWINDOWBASE_H
  2. #define BCWINDOWBASE_H
  3.  
  4. // Window types
  5. #define MAIN_WINDOW 0
  6. #define SUB_WINDOW 1
  7. #define POPUP_WINDOW 2
  8.  
  9. #define TOOLTIP_MARGIN 2
  10. #define INFINITY 65536
  11.  
  12. #include "bcfilebox.inc"
  13. #include "arraylist.h"
  14. #include "bcbitmap.inc"
  15. #include "bcbutton.inc"
  16. #include "bccapture.inc"
  17. #include "bcdragwindow.inc"
  18. #include "bcclipboard.inc"
  19. #include "bclistbox.inc"
  20. #include "bcmenubar.inc"
  21. #include "bcmeter.inc"
  22. #include "bcpan.inc"
  23. #include "bcpixmap.inc"
  24. #include "bcpopup.inc"
  25. #include "bcpopupmenu.inc"
  26. #include "bcpot.inc"
  27. #include "bcprogress.inc"
  28. #include "bcrepeater.inc"
  29. #include "bcresources.inc"
  30. #include "bcscrollbar.inc"
  31. #include "bcslider.inc"
  32. #include "bcsubwindow.inc"
  33. #include "bctextbox.inc"
  34. #include "bctitle.inc"
  35. #include "bctoggle.inc"
  36. #include "bctumble.inc"
  37. #include "bcwindow.inc"
  38. #include "bcwindowbase.inc"
  39. #include "defaults.inc"
  40. #include "linklist.h"
  41. #include "vframe.inc"
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <X11/Xatom.h>
  46. #include <X11/Xlib.h>
  47. #include <X11/Xutil.h>
  48. #include <X11/keysym.h>
  49. #include <X11/cursorfont.h>
  50.  
  51. class BC_ResizeCall
  52. {
  53. public:
  54.     BC_ResizeCall(int w, int h);
  55.     int w, h;
  56. };
  57.  
  58. // Windows, subwindows, popupwindows inherit from this
  59. class BC_WindowBase
  60. {
  61. public:
  62.     BC_WindowBase();
  63.     virtual ~BC_WindowBase();
  64.  
  65.     friend BC_Bitmap;
  66.     friend BC_Button;
  67.     friend BC_GenericButton;
  68.     friend BC_Capture;
  69.     friend BC_Clipboard;
  70.     friend BC_DragWindow;
  71.     friend BC_FileBox;
  72.     friend BC_ListBox;
  73.     friend BC_Menu;
  74.     friend BC_MenuBar;
  75.     friend BC_MenuItem;
  76.     friend BC_MenuPopup;
  77.     friend BC_Meter;
  78.     friend BC_Pan;
  79.     friend BC_Pixmap;
  80.     friend BC_Popup;
  81.     friend BC_PopupMenu;
  82.     friend BC_Pot;
  83.     friend BC_ProgressBar;
  84.     friend BC_Repeater;
  85.     friend BC_Resources;
  86.     friend BC_ScrollBar;
  87.     friend BC_Slider;
  88.     friend BC_SubWindow;
  89.     friend BC_TextBox;
  90.     friend BC_Title;
  91.     friend BC_Toggle;
  92.     friend BC_Tumbler;
  93.     friend BC_Window;
  94.  
  95. // Main loop
  96.     int run_window();
  97. // Terminal event dispatchers
  98.     virtual int close_event() { return 0; };
  99.     virtual int resize_event(int w, int h);
  100.     virtual int cursor_motion_event() { return 0; };
  101.     virtual int repeat_event(long duration) { return 0; };
  102.     virtual int button_press_event() { return 0; };
  103.     virtual int button_release_event() { return 0; };
  104.     virtual int cursor_leave_event() { return 0; };
  105.     virtual int cursor_enter_event() { return 0; };
  106.     virtual int keypress_event() { return 0; };
  107.     virtual int translation_event() { return 0; };
  108.     virtual int drag_start_event() { return 0; };
  109.     virtual int drag_motion_event() { return 0; };
  110.     virtual int drag_stop_event() { return 0; };
  111.     virtual int uses_text() { return 0; };
  112.  
  113. // Check if a hardware accelerated colormodel is available and reserve it
  114.     int accel_available(int color_model); 
  115. // Get color model adjusted for byte order and pixel size
  116.     int get_color_model();
  117. // return the colormap pixel of the color for all bit depths
  118.     int get_color(long color);
  119. // return the currently selected color
  120.     long get_color();
  121.     int show_window();
  122.     int hide_window();
  123.     int get_hidden();
  124.     int flash(int x = -1, int y = -1, int w = -1, int h = -1);
  125.     void flush();
  126.     void sync_display();
  127. // Lock out other threads
  128.     int lock_window();
  129.     int unlock_window();
  130.  
  131.     int add_menubar(BC_MenuBar *menu_bar);
  132.     int add_subwindow(BC_WindowBase *subwindow);
  133.     int add_tool(BC_WindowBase *subwindow);
  134.  
  135.     static BC_Resources* get_resources();
  136. // Dimensions
  137.     virtual int get_w();
  138.     virtual int get_h();
  139.     virtual int get_x();
  140.     virtual int get_y();
  141.     int get_root_w();
  142.     int get_root_h();
  143. // Get absolute coords for creating a popup
  144.     int get_abs_cursor_x();
  145.     int get_abs_cursor_y();
  146.     int get_button_down();
  147.     int get_dragging();
  148.     int get_keypress();
  149.     int get_cursor_x();
  150.     int get_cursor_y();
  151.     int shift_down();
  152.     int ctrl_down();
  153.     int get_double_click();
  154. // Bottom right corner
  155.     int get_x2();
  156.     int get_y2();
  157.     int get_bg_color();
  158.     BC_Pixmap* get_bg_pixmap();
  159.     int get_text_ascent(int font);
  160.     int get_text_descent(int font);
  161.     int get_text_height(int font, char *text = 0);
  162.     int get_text_width(int font, char *text, int length = -1);
  163.     BC_Clipboard* get_clipboard();
  164.     void set_dragging(int value);
  165.     int set_w(int w);
  166.     int set_h(int h);
  167.     BC_WindowBase* get_top_level();
  168. // Event happened in this window
  169.     int is_event_win();
  170.     int cursor_inside();
  171. // Deactivate everything and activate this subwindow
  172.     virtual int activate();
  173. // Deactivate this subwindow
  174.     virtual int deactivate();
  175.     int get_buttonpress();
  176.     void set_active_subwindow(BC_WindowBase *subwindow);
  177.  
  178. // Set the gc to the color
  179.     void set_color(long color);
  180.     int get_bgcolor();
  181.     void set_font(int font);
  182.     void set_cursor(int cursor);
  183.  
  184. // Drawing
  185.     void clear_box(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
  186.     void draw_box(int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
  187.     void draw_text(int x, int y, char *text, int length = -1, BC_Pixmap *pixmap = 0);
  188.     void draw_center_text(int x, int y, char *text, int length = -1);
  189.     void draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap = 0);
  190.     void draw_rectangle(int x, int y, int w, int h);
  191.     void draw_3segment(int x, 
  192.         int y, 
  193.         int w, 
  194.         int h, 
  195.         BC_Pixmap *left_image,
  196.         BC_Pixmap *mid_image,
  197.         BC_Pixmap *right_image,
  198.         BC_Pixmap *pixmap = 0);
  199.     void draw_3d_box(int x, 
  200.         int y, 
  201.         int w, 
  202.         int h, 
  203.         int light1, 
  204.         int light2, 
  205.         int middle, 
  206.         int shadow1, 
  207.         int shadow2, 
  208.         BC_Pixmap *pixmap = 0);
  209.     void draw_3d_border(int x, int y, int w, int h, 
  210.         int light1, int light2, int shadow1, int shadow2);
  211.     void draw_colored_box(int x, int y, int w, int h, int down, int highlighted);
  212.     void draw_check(int x, int y);
  213.     void draw_triangle_down_flat(int x, int y, int w, int h);
  214.     void draw_triangle_up(int x, int y, int w, int h, 
  215.         int light1, int light2, int middle, int shadow1, int shadow2);
  216.     void draw_triangle_down(int x, int y, int w, int h, 
  217.         int light1, int light2, int middle, int shadow1, int shadow2);
  218.     void draw_triangle_left(int x, int y, int w, int h, 
  219.         int light1, int light2, int middle, int shadow1, int shadow2);
  220.     void draw_triangle_right(int x, int y, int w, int h, 
  221.         int light1, int light2, int middle, int shadow1, int shadow2);
  222. // Set the gc to opaque
  223.     void set_opaque();
  224.     void set_inverse();
  225.     void set_background(VFrame *bitmap);
  226.     void set_title(char *text);
  227.     char* get_title();
  228.     void start_video();
  229.     void stop_video();
  230.     int video_is_on();
  231.     void set_done(int return_value);
  232. // Get a bitmap to draw on the window with
  233.     BC_Bitmap* new_bitmap(int w, int h, int color_model = -1);
  234. // Draw a bitmap on the window
  235.     void draw_bitmap(BC_Bitmap *bitmap, 
  236.         int dont_wait, 
  237.         int dest_x = 0, 
  238.         int dest_y = 0, 
  239.         int dest_w = 0, 
  240.         int dest_h = 0,
  241.         int src_x = 0,
  242.         int src_y = 0,
  243.         int src_w = 0,
  244.         int src_h = 0,
  245.         BC_Pixmap *pixmap = 0);
  246. // Draw a pixmap on the window
  247.     void draw_pixmap(BC_Pixmap *pixmap, 
  248.         int dest_x = 0, 
  249.         int dest_y = 0, 
  250.         int dest_w = -1, 
  251.         int dest_h = -1,
  252.         int src_x = 0,
  253.         int src_y = 0);
  254. // Draw a vframe on the window
  255.     void draw_vframe(VFrame *frame, 
  256.         int dest_x = 0, 
  257.         int dest_y = 0, 
  258.         int dest_w = -1, 
  259.         int dest_h = -1,
  260.         int src_x = 0,
  261.         int src_y = 0,
  262.         BC_Pixmap *pixmap = 0);
  263.     void draw_border(char *text, int x, int y, int w, int h);
  264. // Draw a region of the background
  265.     void draw_top_background(BC_WindowBase *parent_window, int x, int y, int w, int h, BC_Pixmap *pixmap = 0);
  266.     void draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h);
  267.     void draw_background(int x, int y, int w, int h);
  268.     void draw_tiles(BC_Pixmap *tile, int origin_x, int origin_y, int x, int y, int w, int h);
  269.     void slide_left(int distance);
  270.     void slide_right(int distance);
  271.     void slide_up(int distance);
  272.     void slide_down(int distance);
  273.  
  274.     int cycle_textboxes(int amount);
  275.  
  276.     int raise_window();
  277.     int set_tooltips(int tooltips_enabled);
  278.     int resize_window(int w, int h);
  279.     int reposition_window(int x, int y, int w = -1, int h = -1);
  280. //    long get_repeat_id();
  281.     int set_repeat(long duration);
  282.     int unset_repeat(long id);
  283.     int set_tooltip(char *text);
  284.     int show_tooltip(int w = -1, int h = -1);
  285.     int hide_tooltip();
  286.     int set_icon(VFrame *data);
  287.     int load_defaults(Defaults *defaults);
  288.     int save_defaults(Defaults *defaults);
  289.  
  290. private:
  291. // Create a window
  292.     int create_window(BC_WindowBase *parent_window,
  293.                 char *title, 
  294.                 int x,
  295.                 int y,
  296.                 int w, 
  297.                 int h, 
  298.                 int minw, 
  299.                 int minh, 
  300.                 int allow_resize,
  301.                 int private_color, 
  302.                 int hide,
  303.                 int bg_color,
  304.                 char *display_name,
  305.                 int window_type,
  306.                 BC_Pixmap *bg_pixmap);
  307.  
  308.     static Display* init_display(char *display_name);
  309.     virtual int initialize();
  310.     int get_atoms();
  311.     void init_cursors();
  312.     int init_colors();
  313.     int init_window_shape();
  314.     static int evaluate_color_model(int client_byte_order, int server_byte_order, int depth);
  315.     int create_private_colors();
  316.     int create_color(int color);
  317.     int create_shared_colors();
  318.     int get_single_text_width(int font, char *text, int length);
  319.     int allocate_color_table();
  320.     int init_gc();
  321.     int init_fonts();
  322.     int get_color_rgb8(int color);
  323.     long get_color_rgb16(int color);
  324.     long get_color_bgr16(int color);
  325.     long get_color_bgr24(int color);
  326.     XFontStruct* get_font_struct(int font);
  327.     Cursor get_cursor_struct(int cursor);
  328.     XFontSet get_fontset(int font);
  329.     XFontSet get_curr_fontset(void);
  330.     void set_fontset(int font);    
  331.     int dispatch_event();
  332.  
  333.     int get_key_masks(XEvent &event);
  334.  
  335.     int trigger_tooltip();
  336.     int untrigger_tooltip();
  337.     void draw_tooltip();
  338.     int arm_repeat(long duration);
  339. // delete all repeater opjects for a close
  340.     int unset_all_repeaters();
  341.  
  342. // Recursive event dispatchers
  343.     int dispatch_resize_event(int w, int h);
  344.     int dispatch_motion_event();
  345.     int dispatch_keypress_event();
  346.     int dispatch_repeat_event(long duration);
  347.     int dispatch_repeat_event_master(long duration);
  348.     int dispatch_button_press();
  349.     int dispatch_button_release();
  350.     int dispatch_cursor_leave();
  351.     int dispatch_cursor_enter();
  352.     int dispatch_translation_event();
  353.     int dispatch_drag_start();
  354.     int dispatch_drag_motion();
  355.     int dispatch_drag_stop();
  356.  
  357. // Get the port ID for a color model or return -1 for failure
  358.     int grab_port_id(BC_WindowBase *window, int color_model);
  359.  
  360.     int find_next_textbox(BC_WindowBase **first_textbox, BC_WindowBase **next_textbox, int &result);
  361.     int find_prev_textbox(BC_WindowBase **last_textbox, BC_WindowBase **prev_textbox, int &result);
  362.  
  363. // Top level window above this window
  364.     BC_WindowBase* top_level;
  365. // Window just above this window
  366.     BC_WindowBase* parent_window;
  367. // list of window bases in this window
  368.     BC_SubWindowList* subwindows;
  369. // Position of window
  370.     int x, y, w, h;
  371. // Default colors
  372.     int light1, light2, medium, dark1, dark2, bg_color;
  373. // Type of window defined above
  374.     int window_type;
  375. // Pointer to the active menubar in the window.
  376.     BC_MenuBar* active_menubar;
  377. // pointer to the active popup menu in the window
  378.     BC_PopupMenu* active_popup_menu;    
  379. // pointer to the active subwindow
  380.     BC_WindowBase* active_subwindow;
  381.  
  382. // Window parameters
  383.     int allow_resize;
  384.     int hidden, private_color, bits_per_pixel, color_model;
  385.     int server_byte_order, client_byte_order;
  386. // number of colors in color table
  387.     int total_colors;
  388. // last color found in table
  389.     int current_color_value, current_color_pixel;
  390. // table for every color allocated
  391.     int color_table[256][2];    
  392. // Turn on optimization
  393.     int video_on;
  394. // Event handler completion
  395.     int done;
  396. // Return value of event handler
  397.     int return_value;
  398. // Motion event compression
  399.     int motion_events, last_motion_x, last_motion_y;
  400. // window of buffered motion
  401.     Window last_motion_win;       
  402. // Resize event compression
  403.     int resize_events, last_resize_w, last_resize_h;
  404.     int translation_events, last_translate_x, last_translate_y;
  405. // Since the window manager automatically translates the window at boot, discard
  406. // the first translation event
  407.     int translation_count;
  408. // Key masks
  409.     int ctrl_mask, shift_mask;
  410. // Cursor motion information
  411.     int cursor_x, cursor_y;
  412. // Button status information
  413.     int button_down, button_number;
  414. // When button was pressed and whether it qualifies as a double click
  415.     unsigned long button_time1, button_time2;
  416.     int double_click;
  417. // Which button is down
  418.     int button_pressed;
  419. // Last key pressed
  420.     int key_pressed;
  421.  
  422.     static BC_Resources resources;
  423. // Array of repeaters for multiple repeating objects.
  424.     ArrayList<BC_Repeater*> repeaters;
  425. //    long next_repeat_id;
  426. // Text for tooltip if one exists
  427.     char tooltip_text[BCTEXTLEN];
  428. // If the current window's tooltip is visible
  429.     int tooltip_on;
  430. // Repeat ID of tooltip
  431. //    long tooltip_id;
  432. // Popup window for tooltip
  433.     BC_Popup *tooltip_popup;
  434. // If this subwindow has already shown a tooltip since the last EnterNotify
  435.     int tooltip_done;
  436. // If the tooltip shouldn't be hidden
  437.     int persistant_tooltip;
  438.     int current_font;
  439.     XFontSet largefontset, mediumfontset, smallfontset, curr_fontset;
  440.     long current_color;
  441. // Coordinate of drag start
  442.     int drag_x, drag_y;
  443. // Boundaries the cursor must pass to start a drag
  444.     int drag_x1, drag_x2, drag_y1, drag_y2;
  445. // Dragging is specific to the subwindow
  446.     int is_dragging;
  447. // Don't delete the background pixmap
  448.     int shared_bg_pixmap;
  449.     char title[BCTEXTLEN];
  450.  
  451. // X Window parameters
  452.     int screen;
  453.     Window rootwin;
  454. // windows previous events happened in
  455.      Window event_win, drag_win;
  456.     Visual *vis;
  457.     Colormap cmap;
  458.     Display* display;
  459.      Window win;
  460.     Pixmap pixmap;
  461.     GC gc;
  462. // Depth given by the X Server
  463.     int default_depth;
  464.     Atom DelWinXAtom;
  465.     Atom ProtoXAtom;
  466.     Atom RepeaterXAtom;
  467.     Atom SetDoneXAtom;
  468.     XFontStruct *largefont, *mediumfont, *smallfont;
  469.     Cursor arrow_cursor, ibeam_cursor;
  470.     int xvideo_port_id;
  471.     ArrayList<BC_ResizeCall*> resize_history;
  472. // Background tile if tiled
  473.     BC_Pixmap *bg_pixmap;
  474. // Icon
  475.     BC_Popup *icon_window;
  476.     BC_Pixmap *icon_pixmap;
  477. // Temporary
  478.     BC_Bitmap *temp_bitmap;
  479. // Clipboard
  480.     BC_Clipboard *clipboard;
  481. };
  482.  
  483.  
  484.  
  485. #endif
  486.