4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdragwindow.h"
28 // Icon has to be offset so the cursor isn't directly over it.
29 // The cursor has to be over the target window for X to detect the right window.
30 #define DRAG_OFFSET_X 16
31 #define DRAG_OFFSET_Y 16
33 BC_DragWindow::BC_DragWindow(BC_WindowBase *parent_window,
37 : BC_Popup(parent_window,
40 parent_window->get_abs_cursor_x(0) + DRAG_OFFSET_X,
41 parent_window->get_abs_cursor_y(0) + DRAG_OFFSET_Y,
52 init_x = parent_window->get_abs_cursor_x(0) + DRAG_OFFSET_X;
53 init_y = parent_window->get_abs_cursor_y(0) + DRAG_OFFSET_Y;
56 icon_offset_x = init_x - parent_window->get_abs_cursor_x(0);
57 icon_offset_y = init_y - parent_window->get_abs_cursor_y(0);
58 //printf("BC_DragWindow::BC_DragWindow 1 %d %d\n", icon_offset_x, icon_offset_y);
63 BC_DragWindow::BC_DragWindow(BC_WindowBase *parent_window,
67 : BC_Popup(parent_window,
70 parent_window->get_abs_cursor_x(0) + DRAG_OFFSET_X,
71 parent_window->get_abs_cursor_y(0) + DRAG_OFFSET_Y,
76 prepare_frame(frame, parent_window))
78 delete temp_frame; // created in prepare_frame inside constructor
82 init_x = parent_window->get_abs_cursor_x(0) + DRAG_OFFSET_X;
83 init_y = parent_window->get_abs_cursor_y(0) + DRAG_OFFSET_Y;
86 icon_offset_x = init_x - parent_window->get_abs_cursor_x(0);
87 icon_offset_y = init_y - parent_window->get_abs_cursor_y(0);
88 //printf("BC_DragWindow::BC_DragWindow 1 %d %d\n", icon_offset_x, icon_offset_y);
92 BC_DragWindow::~BC_DragWindow()
97 int BC_DragWindow::get_init_x(BC_WindowBase *parent_window, int icon_x)
99 int output_x, temp = 0;
101 XTranslateCoordinates(parent_window->top_level->display,
103 parent_window->top_level->rootwin,
112 int BC_DragWindow::get_init_y(BC_WindowBase *parent_window, int icon_y)
114 int output_y, temp = 0;
116 XTranslateCoordinates(parent_window->top_level->display,
118 parent_window->top_level->rootwin,
127 int BC_DragWindow::cursor_motion_event()
129 reposition_window(get_abs_cursor_x(0) + icon_offset_x,
130 get_abs_cursor_y(0) + icon_offset_y,
137 int BC_DragWindow::get_offset_x()
139 return icon_offset_x;
142 int BC_DragWindow::get_offset_y()
144 return icon_offset_y;
147 int BC_DragWindow::drag_failure_event()
149 if(!do_animation) return 0;
151 if(end_x == BC_INFINITY)
157 for(int i = 0; i < 10; i++)
159 int new_x = end_x + (init_x - end_x) * i / 10;
160 int new_y = end_y + (init_y - end_y) * i / 10;
162 reposition_window(new_x,
172 void BC_DragWindow::set_animation(int value)
174 this->do_animation = value;
177 BC_Pixmap *BC_DragWindow::prepare_frame(VFrame *frame, BC_WindowBase *parent_window)
181 if(frame->get_color_model() == BC_RGBA8888)
183 temp_frame = new VFrame(*frame);
187 temp_frame = new VFrame;
188 temp_frame->set_use_shm(0);
189 temp_frame->reallocate(0,
199 BC_CModels::transfer(temp_frame->get_rows(), frame->get_rows(),
201 0, 0, frame->get_w(), frame->get_h(),
202 0, 0, temp_frame->get_w(), temp_frame->get_h(),
203 frame->get_color_model(), temp_frame->get_color_model(),
204 0, frame->get_w(), temp_frame->get_w());
206 temp_frame->get_rows()[(temp_frame->get_h() / 2)][(temp_frame->get_w() / 2) * 4 + 3] = 0;
207 drag_pixmap = new BC_Pixmap(parent_window,