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 / bcdragwindow.C < prev    next >
C/C++ Source or Header  |  2000-11-29  |  2KB  |  102 lines

  1. #include "bcdragwindow.h"
  2. #include "bcpixmap.h"
  3.  
  4. #include <unistd.h>
  5.  
  6. BC_DragWindow::BC_DragWindow(BC_WindowBase *parent_window, 
  7.     BC_Pixmap *pixmap, 
  8.     int icon_x, 
  9.     int icon_y)
  10.  : BC_Popup(parent_window, 
  11.      get_init_x(parent_window, icon_x), 
  12.     get_init_y(parent_window, icon_y),
  13.     pixmap->get_w(),
  14.     pixmap->get_h(),
  15.     -1,
  16.     0,
  17.     pixmap)
  18. {
  19.     init_x = get_x();
  20.     init_y = get_y();
  21.     end_x = INFINITY;
  22.     end_y = INFINITY;
  23.     icon_offset_x = init_x - parent_window->get_abs_cursor_x();
  24.     icon_offset_y = init_y - parent_window->get_abs_cursor_y();
  25. }
  26.  
  27. BC_DragWindow::~BC_DragWindow()
  28. {
  29. }
  30.  
  31. int BC_DragWindow::get_init_x(BC_WindowBase *parent_window, int icon_x)
  32. {
  33.     int output_x, temp = 0;
  34.     Window tempwin;
  35.     XTranslateCoordinates(parent_window->top_level->display, 
  36.         parent_window->win, 
  37.         parent_window->top_level->rootwin, 
  38.         icon_x, 
  39.         temp, 
  40.         &output_x, 
  41.         &temp, 
  42.         &tempwin);
  43.     return output_x;
  44. }
  45.  
  46. int BC_DragWindow::get_init_y(BC_WindowBase *parent_window, int icon_y)
  47. {
  48.     int output_y, temp = 0;
  49.     Window tempwin;
  50.     XTranslateCoordinates(parent_window->top_level->display, 
  51.         parent_window->win, 
  52.         parent_window->top_level->rootwin, 
  53.         temp, 
  54.         icon_y, 
  55.         &temp, 
  56.         &output_y, 
  57.         &tempwin);
  58.     return output_y;
  59. }
  60.  
  61. int BC_DragWindow::cursor_motion_event()
  62. {
  63.     reposition_window(get_abs_cursor_x() + icon_offset_x, 
  64.         get_abs_cursor_y() + icon_offset_y, 
  65.         get_w(), 
  66.         get_h());
  67.     return 1;
  68. }
  69.  
  70. int BC_DragWindow::get_offset_x()
  71. {
  72.     return icon_offset_x;
  73. }
  74.  
  75. int BC_DragWindow::get_offset_y()
  76. {
  77.     return icon_offset_y;
  78. }
  79.  
  80. int BC_DragWindow::drag_failure_event()
  81. {
  82.     if(end_x == INFINITY)
  83.     {
  84.         end_x = get_x();
  85.         end_y = get_y();
  86.     }
  87.  
  88.     for(int i = 0; i < 10; i++)
  89.     {
  90.         int new_x = end_x + (init_x - end_x) * i / 10;
  91.         int new_y = end_y + (init_y - end_y) * i / 10;
  92.  
  93.         reposition_window(new_x, 
  94.             new_y, 
  95.             get_w(), 
  96.             get_h());
  97.         flush();
  98.         usleep(1000);
  99.     }
  100.     return 0;
  101. }
  102.