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,
51 init_x = parent_window->get_abs_cursor_x(0) + DRAG_OFFSET_X;
52 init_y = parent_window->get_abs_cursor_y(0) + DRAG_OFFSET_Y;
55 icon_offset_x = init_x - parent_window->get_abs_cursor_x(0);
56 icon_offset_y = init_y - parent_window->get_abs_cursor_y(0);
57 //printf("BC_DragWindow::BC_DragWindow 1 %d %d\n", icon_offset_x, icon_offset_y);
62 BC_DragWindow::BC_DragWindow(BC_WindowBase *parent_window,
66 : BC_Popup(parent_window,
69 parent_window->get_abs_cursor_x(0) + DRAG_OFFSET_X,
70 parent_window->get_abs_cursor_y(0) + DRAG_OFFSET_Y,
75 prepare_frame(frame, parent_window))
77 delete temp_frame; // created in prepare_frame inside constructor
81 init_x = parent_window->get_abs_cursor_x(0) + DRAG_OFFSET_X;
82 init_y = parent_window->get_abs_cursor_y(0) + DRAG_OFFSET_Y;
85 icon_offset_x = init_x - parent_window->get_abs_cursor_x(0);
86 icon_offset_y = init_y - parent_window->get_abs_cursor_y(0);
87 //printf("BC_DragWindow::BC_DragWindow 1 %d %d\n", icon_offset_x, icon_offset_y);
91 BC_DragWindow::~BC_DragWindow()
95 int BC_DragWindow::get_init_x(BC_WindowBase *parent_window, int icon_x)
97 int output_x, temp = 0;
99 XTranslateCoordinates(parent_window->top_level->display,
101 parent_window->top_level->rootwin,
110 int BC_DragWindow::get_init_y(BC_WindowBase *parent_window, int icon_y)
112 int output_y, temp = 0;
114 XTranslateCoordinates(parent_window->top_level->display,
116 parent_window->top_level->rootwin,
125 int BC_DragWindow::cursor_motion_event()
127 reposition_window(get_abs_cursor_x(0) + icon_offset_x,
128 get_abs_cursor_y(0) + icon_offset_y,
135 int BC_DragWindow::get_offset_x()
137 return icon_offset_x;
140 int BC_DragWindow::get_offset_y()
142 return icon_offset_y;
145 int BC_DragWindow::drag_failure_event()
147 if(!do_animation) return 0;
149 if(end_x == BC_INFINITY)
155 for(int i = 0; i < 10; i++)
157 int new_x = end_x + (init_x - end_x) * i / 10;
158 int new_y = end_y + (init_y - end_y) * i / 10;
160 reposition_window(new_x,
170 void BC_DragWindow::set_animation(int value)
172 this->do_animation = value;
175 BC_Pixmap *BC_DragWindow::prepare_frame(VFrame *frame, BC_WindowBase *parent_window)
179 if(frame->get_color_model() == BC_RGBA8888)
181 temp_frame = new VFrame(*frame);
185 temp_frame = new VFrame;
186 temp_frame->set_use_shm(0);
187 temp_frame->reallocate(0,
197 BC_CModels::transfer(temp_frame->get_rows(), frame->get_rows(),
199 0, 0, frame->get_w(), frame->get_h(),
200 0, 0, temp_frame->get_w(), temp_frame->get_h(),
201 frame->get_color_model(), temp_frame->get_color_model(),
202 0, frame->get_w(), temp_frame->get_w());
204 temp_frame->get_rows()[(temp_frame->get_h() / 2)][(temp_frame->get_w() / 2) * 4 + 3] = 0;
205 my_pixmap = new BC_Pixmap(parent_window,