~vcs-imports/gparted/master

1396 by Curtis Gedak
Limit graphic movement according to required boot record space
1
/* Copyright (C) 2004 Bart
2
 * Copyright (C) 2010 Curtis Gedak
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2298 by Daniel Mustieles
Replace obsolete FSF postal address in copyright notices (#721565)
12
 *  GNU General Public License for more details.
1396 by Curtis Gedak
Limit graphic movement according to required boot record space
13
 *
14
 *  You should have received a copy of the GNU General Public License
2298 by Daniel Mustieles
Replace obsolete FSF postal address in copyright notices (#721565)
15
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
1396 by Curtis Gedak
Limit graphic movement according to required boot record space
16
 */
2979 by Mike Fleetwood
Remove "../include/" from GParted header #includes
17
18
#include "Frame_Resizer_Extended.h"
1396 by Curtis Gedak
Limit graphic movement according to required boot record space
19
20
Frame_Resizer_Extended::Frame_Resizer_Extended()
21
{
22
}
23
24
void Frame_Resizer_Extended::set_used_start( int used_start ) 
25
{
26
	if ( used_start <= 0 )
27
		USED_START = GRIPPER ;
28
	else
29
		USED_START = used_start + GRIPPER ;
30
}
31
32
bool Frame_Resizer_Extended::drawingarea_on_mouse_motion( GdkEventMotion * ev ) 
33
{
34
	if ( GRIP_LEFT || GRIP_RIGHT ) 
35
	{
36
		if ( GRIP_LEFT )
37
		{
38
			if (  ev ->x > (GRIPPER + X_MIN_SPACE_BEFORE) &&
39
			      ev ->x < (X_END - MIN_SIZE - BORDER * 2) &&
40
			      ( ev ->x < USED_START || USED == 0 )
41
			   )
42
			{
43
				X_START = static_cast<int>( ev ->x ) ;
44
				
45
				signal_resize .emit( X_START - GRIPPER, X_END - GRIPPER - BORDER * 2, ARROW_LEFT ) ; 
46
			}
47
			else if ( ev ->x <= (GRIPPER + X_MIN_SPACE_BEFORE) )
48
			{
49
				if ( X_START > (GRIPPER + X_MIN_SPACE_BEFORE) )
50
				{
51
					X_START = GRIPPER + X_MIN_SPACE_BEFORE ;
52
53
					signal_resize .emit( X_START - GRIPPER,
54
							     X_END - GRIPPER - BORDER * 2,
55
							     ARROW_LEFT ) ; 
56
				}
57
			}
58
			else if ( USED != 0 && ev ->x >= USED_START )
59
			{
60
				if ( X_START < USED_START )
61
				{
62
					X_START = USED_START ;
63
64
					//+1 to force the spinbutton to its min.
65
					signal_resize .emit( X_START - GRIPPER +1,
66
							     X_END - GRIPPER - BORDER * 2,
67
							     ARROW_LEFT ) ;
68
				}
69
			}
70
			else if ( USED == 0 && ev ->x >= (X_END - MIN_SIZE - BORDER * 2) )
71
			{
72
				if ( X_START < X_END - BORDER * 2 )
73
				{
74
					X_START = X_END - MIN_SIZE - BORDER * 2 ;
75
					
76
					signal_resize .emit( X_START - GRIPPER,
77
							     X_END - GRIPPER - BORDER * 2,
78
							     ARROW_LEFT ) ;
79
				}
80
			}
81
		}
82
		else if ( GRIP_RIGHT )
83
		{
84
			if ( ev ->x < 500 + GRIPPER + BORDER * 2 && 
85
			     ev ->x > (X_START + MIN_SIZE + BORDER * 2) &&
86
			     ( ev ->x > USED_START + USED + BORDER *2 || USED == 0 ) )
87
			{
88
				X_END = static_cast<int>( ev ->x ) ;
89
				
90
				signal_resize .emit( X_START - GRIPPER, X_END - GRIPPER - BORDER * 2, ARROW_RIGHT ) ; 
91
			}
92
			else if ( ev ->x >= 500 + GRIPPER + BORDER * 2 )
93
			{
94
				if ( X_END < 500 + GRIPPER + BORDER * 2 )
95
				{
96
					X_END = 500 + GRIPPER + BORDER * 2 ;
97
98
					signal_resize .emit( X_START - GRIPPER,
99
							     X_END - GRIPPER - BORDER * 2,
100
							     ARROW_RIGHT ) ; 
101
				}
102
			}
103
			else if ( USED != 0 && ev ->x <= USED_START + USED + BORDER *2 )
104
			{
105
				if ( X_END > USED_START + USED + BORDER *2 )
106
				{
107
					X_END = USED_START + USED + BORDER *2 ;
108
109
					//-1 to force the spinbutton to its min.
110
					signal_resize .emit( X_START - GRIPPER,
111
							     X_END - GRIPPER - BORDER * 2 -1, ARROW_RIGHT ) ;
112
				}
113
			}
114
			else if ( USED == 0 && ev ->x <= (X_START + MIN_SIZE + BORDER * 2) )
115
			{
116
				if ( X_END > (X_START + MIN_SIZE + BORDER * 2) )
117
				{
118
					X_END = X_START + MIN_SIZE + BORDER *2 ;
119
					
120
					signal_resize .emit( X_START - GRIPPER,
121
							     X_END - GRIPPER - BORDER * 2,
122
							     ARROW_RIGHT ) ;
123
				}
124
			}
125
		}
126
		
127
		Draw_Partition() ;
128
	}
129
	
130
	//check if pointer is over a gripper
131
	else
132
	{ 
133
		//left grip
134
		if ( ! fixed_start &&
135
		     ev ->x >= X_START - GRIPPER &&
136
		     ev ->x <= X_START &&
137
		     ev ->y >= 5 &&
138
		     ev ->y <= 45 ) 
139
			drawingarea .get_parent_window() ->set_cursor( *cursor_resize ) ;
140
		//right grip
141
		else if (  ev ->x >= X_END &&
142
			   ev ->x <= X_END + GRIPPER &&
143
			   ev ->y >= 5 &&
144
			   ev ->y <= 45 ) 
145
			drawingarea .get_parent_window() ->set_cursor( *cursor_resize ) ;
146
		//normal pointer
147
		else 
148
			drawingarea .get_parent_window() ->set_cursor() ;		
149
	}
150
	
151
	return true ;
152
}
153
154
void Frame_Resizer_Extended::Draw_Partition() 
155
{
156
	//i couldn't find a clear() for a pixmap, that's why ;)
157
	gc_pixmap ->set_foreground( color_background );
158
	pixmap ->draw_rectangle( gc_pixmap, true, 0, 0, 536, 50 );
159
	
160
	//the two rectangles on each side of the partition
161
	gc_pixmap ->set_foreground( color_arrow_rectangle );
162
	pixmap ->draw_rectangle( gc_pixmap, true, 0, 0, 10, 50 );
163
	pixmap ->draw_rectangle( gc_pixmap, true, 526, 0, 10, 50 );
164
	
165
	//used
166
	gc_pixmap ->set_foreground( color_used );
167
	pixmap ->draw_rectangle( gc_pixmap, true, USED_START + BORDER, BORDER, USED, 34 );
168
	
169
	//partition
170
	gc_pixmap ->set_foreground( color_partition );
171
	for( short t = 0; t < 9 ; t++ )
172
		pixmap ->draw_rectangle( gc_pixmap, false, X_START +t, t, X_END - X_START -t*2, 50 - t*2 );
173
			
174
	//resize grips
175
	Draw_Resize_Grip( ARROW_LEFT ) ;
176
	Draw_Resize_Grip( ARROW_RIGHT ) ;
177
	
178
	//and draw everything to "real" screen..
179
	drawingarea .get_window() ->draw_drawable( gc_drawingarea, pixmap, 0, 0, 0, 0 ) ;
180
}