2 #include "bcmenuitem.h"
4 #include "bcwindowbase.h"
7 BC_DragBox::BC_DragBox(BC_WindowBase *parent)
10 this->parent = parent;
14 BC_DragBox::~BC_DragBox()
24 void BC_DragBox::start_drag()
26 popup = new BC_DragBoxPopup(this);
27 popup->lock_window("BC_DragBox::start");
28 for( int i=0; i<4; ++i )
29 edge[i] = new BC_Popup(parent, 0,0, 1,1, ORANGE, 1);
30 parent->grab_buttons();
31 parent->grab_cursor();
33 popup->create_objects();
35 popup->unlock_window();
40 void BC_DragBox::run()
42 popup->lock_window("BC_DragBox::run 0");
45 popup->unlock_window();
49 popup->lock_window("BC_DragBox::run 1");
51 int x0 = popup->lx0, y0 = popup->ly0;
52 int x1 = popup->lx1, y1 = popup->ly1;
53 parent->ungrab_cursor();
54 parent->ungrab_buttons();
55 popup->ungrab(parent);
56 for( int i=0; i<4; ++i ) delete edge[i];
57 popup->unlock_window();
58 delete popup; popup = 0;
59 handle_done_event(x0, y0, x1, y1);
62 BC_DragBoxPopup::BC_DragBoxPopup(BC_DragBox *grab_thread)
63 : BC_Popup(grab_thread->parent, 0,0, 16,16, -1,1)
65 this->grab_thread = grab_thread;
68 x0 = y0 = x1 = y1 = -1;
69 lx0 = ly0 = lx1 = ly1 = -1;
72 BC_DragBoxPopup::~BC_DragBoxPopup()
76 int BC_DragBoxPopup::grab_event(XEvent *event)
78 int cur_drag = dragging;
79 switch( event->type ) {
81 if( cur_drag > 0 ) return 1;
82 int x0 = event->xbutton.x_root;
83 int y0 = event->xbutton.y_root;
86 if( event->xbutton.button == RIGHT_BUTTON ) break;
87 if( x0>=get_x() && x0<get_x()+get_w() &&
88 y0>=get_y() && y0<get_y()+get_h() ) break;
90 this->x0 = this->x1 = x0;
91 this->y0 = this->y1 = y0;
99 this->x1 = event->xbutton.x_root;
100 this->y1 = event->xbutton.y_root;
110 grab_thread->done = 1;
114 void BC_DragBoxPopup::update()
116 set_color(grab_color ^= GREEN);
117 draw_box(0,0, get_w(),get_h());
121 void BC_DragBoxPopup::draw_selection(int show)
124 for( int i=0; i<4; ++i ) hide_window(0);
129 int nx0 = x0 < x1 ? x0 : x1;
130 int nx1 = x0 < x1 ? x1 : x0;
131 int ny0 = y0 < y1 ? y0 : y1;
132 int ny1 = y0 < y1 ? y1 : y0;
133 lx0 = nx0; lx1 = nx1;
134 ly0 = ny0; ly1 = ny1;
137 BC_Popup **edge = grab_thread->edge;
138 edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
139 edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
140 edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
141 edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
144 for( int i=0; i<4; ++i ) edge[i]->show_window(0);