3 * Copyright (C) 2020 William Morrow
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 #include "bcdragbox.h"
23 #include "bcmenuitem.h"
25 #include "bcwindowbase.h"
28 BC_DragBox::BC_DragBox(BC_WindowBase *parent)
31 this->parent = parent;
35 BC_DragBox::~BC_DragBox()
45 void BC_DragBox::start_drag()
47 popup = new BC_DragBoxPopup(this);
48 popup->lock_window("BC_DragBox::start");
49 for( int i=0; i<4; ++i )
50 edge[i] = new BC_Popup(parent, 0,0, 1,1, ORANGE, 1);
51 parent->grab_buttons();
52 parent->grab_cursor();
54 popup->create_objects();
56 popup->unlock_window();
61 void BC_DragBox::run()
63 popup->lock_window("BC_DragBox::run 0");
66 popup->unlock_window();
70 popup->lock_window("BC_DragBox::run 1");
72 int x0 = popup->lx0, y0 = popup->ly0;
73 int x1 = popup->lx1, y1 = popup->ly1;
74 parent->ungrab_cursor();
75 parent->ungrab_buttons();
76 popup->ungrab(parent);
77 for( int i=0; i<4; ++i ) delete edge[i];
78 popup->unlock_window();
79 delete popup; popup = 0;
80 handle_done_event(x0, y0, x1, y1);
83 BC_DragBoxPopup::BC_DragBoxPopup(BC_DragBox *grab_thread)
84 : BC_Popup(grab_thread->parent, 0,0, 16,16, -1,1)
86 this->grab_thread = grab_thread;
89 x0 = y0 = x1 = y1 = -1;
90 lx0 = ly0 = lx1 = ly1 = -1;
93 BC_DragBoxPopup::~BC_DragBoxPopup()
97 int BC_DragBoxPopup::grab_event(XEvent *event)
99 int cur_drag = dragging;
100 switch( event->type ) {
102 if( cur_drag > 0 ) return 1;
103 int x0 = event->xbutton.x_root;
104 int y0 = event->xbutton.y_root;
107 if( event->xbutton.button == RIGHT_BUTTON ) break;
108 if( x0>=get_x() && x0<get_x()+get_w() &&
109 y0>=get_y() && y0<get_y()+get_h() ) break;
111 this->x0 = this->x1 = x0;
112 this->y0 = this->y1 = y0;
120 this->x1 = event->xbutton.x_root;
121 this->y1 = event->xbutton.y_root;
131 grab_thread->done = 1;
135 void BC_DragBoxPopup::update()
137 set_color(grab_color ^= GREEN);
138 draw_box(0,0, get_w(),get_h());
142 void BC_DragBoxPopup::draw_selection(int show)
145 for( int i=0; i<4; ++i ) hide_window(0);
150 int nx0 = x0 < x1 ? x0 : x1;
151 int nx1 = x0 < x1 ? x1 : x0;
152 int ny0 = y0 < y1 ? y0 : y1;
153 int ny1 = y0 < y1 ? y1 : y0;
154 lx0 = nx0; lx1 = nx1;
155 ly0 = ny0; ly1 = ny1;
158 BC_Popup **edge = grab_thread->edge;
159 edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
160 edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
161 edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
162 edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
165 for( int i=0; i<4; ++i ) edge[i]->show_window(0);