~ubuntu-branches/ubuntu/jaunty/viewpdf.app/jaunty

« back to all changes in this revision

Viewing changes to NSView+Scrolling.m

  • Committer: Bazaar Package Importer
  • Author(s): Gürkan Sengün
  • Date: 2006-09-16 18:13:34 UTC
  • mfrom: (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060916181334-10mrzvpblr2jpvu7
Tags: 1:0.2dfsg1-2
* Rebuild against latest libgnustep-gui-dev.
* Added co-maintainers.
* Updated build-depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004  Stefan Kleine Stegemann
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (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
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
17
 */
 
18
 
 
19
#import "NSView+Scrolling.h"
 
20
 
 
21
 
 
22
@implementation NSView (Scrolling)
 
23
 
 
24
- (void) scrollToTop
 
25
{
 
26
   if (![self enclosingScrollView])
 
27
   {
 
28
      return;
 
29
   }
 
30
   
 
31
   NSRect visibleRect = [[self enclosingScrollView] documentVisibleRect];
 
32
   [self scrollPoint: NSMakePoint(NSMinX(visibleRect), NSHeight([self frame]))];
 
33
}
 
34
 
 
35
- (void) scrollToBottom
 
36
{
 
37
   if (![self enclosingScrollView])
 
38
   {
 
39
      return;
 
40
   }
 
41
 
 
42
   NSRect visibleRect = [[self enclosingScrollView] documentVisibleRect];
 
43
   [self scrollPoint: NSMakePoint(NSMinX(visibleRect), 0)];
 
44
}
 
45
 
 
46
- (BOOL) scrollPageUp
 
47
{
 
48
   if (![self enclosingScrollView])
 
49
   {
 
50
      return NO;
 
51
   }
 
52
   
 
53
   return [self scrollUp: [[self enclosingScrollView] verticalPageScroll]];
 
54
}
 
55
 
 
56
- (BOOL) scrollPageDown
 
57
{
 
58
   if (![self enclosingScrollView])
 
59
   {
 
60
      return NO;
 
61
   }
 
62
   
 
63
   return [self scrollDown: [[self enclosingScrollView] verticalPageScroll]];
 
64
}
 
65
 
 
66
- (BOOL) scrollLineUp
 
67
{
 
68
   if (![self enclosingScrollView])
 
69
   {
 
70
      return NO;
 
71
   }
 
72
   
 
73
   return [self scrollUp: [[self enclosingScrollView] verticalLineScroll]];
 
74
}
 
75
 
 
76
- (BOOL) scrollLineDown
 
77
{
 
78
   if (![self enclosingScrollView])
 
79
   {
 
80
      return NO;
 
81
   }
 
82
   
 
83
   return [self scrollDown: [[self enclosingScrollView] verticalLineScroll]];
 
84
}
 
85
 
 
86
- (BOOL) scrollUp: (float)amount
 
87
{
 
88
   if (![self enclosingScrollView])
 
89
   {
 
90
      return NO;
 
91
   }
 
92
   
 
93
   NSAssert(amount > 0, @"negative amount");
 
94
   
 
95
   NSRect visibleRect = [[self enclosingScrollView] documentVisibleRect];
 
96
   NSPoint targetPoint = NSMakePoint(NSMinX(visibleRect),
 
97
                         NSMinY(visibleRect) + amount);
 
98
 
 
99
   float maxY = NSHeight([self frame]) - NSHeight(visibleRect);
 
100
   if (targetPoint.y > maxY)
 
101
   {
 
102
      targetPoint.y = maxY;
 
103
   }
 
104
   [self scrollPoint: targetPoint];
 
105
   
 
106
   return !NSEqualRects(visibleRect, [[self enclosingScrollView] documentVisibleRect]);
 
107
}
 
108
 
 
109
- (BOOL) scrollDown: (float)amount
 
110
{
 
111
   if (![self enclosingScrollView])
 
112
   {
 
113
      return NO;
 
114
   }
 
115
   
 
116
   NSAssert(amount > 0, @"negative amount");
 
117
   
 
118
   NSRect visibleRect = [[self enclosingScrollView] documentVisibleRect];
 
119
   NSPoint targetPoint = NSMakePoint(NSMinX(visibleRect),
 
120
                         NSMinY(visibleRect) - amount);
 
121
 
 
122
   if (targetPoint.y < 0)
 
123
   {
 
124
      targetPoint.y = 0;
 
125
   }
 
126
   [self scrollPoint: targetPoint];
 
127
   
 
128
   return !NSEqualRects(visibleRect, [[self enclosingScrollView] documentVisibleRect]);
 
129
}
 
130
 
 
131
- (void) scrollToLeftEdge
 
132
{
 
133
   if (![self enclosingScrollView])
 
134
   {
 
135
      return;
 
136
   }
 
137
   
 
138
   NSRect visibleRect = [[self enclosingScrollView] documentVisibleRect];
 
139
   NSPoint targetPoint = NSMakePoint(0, NSMinY(visibleRect));
 
140
   
 
141
   [self scrollPoint: targetPoint];
 
142
}
 
143
 
 
144
- (void) scrollToRightEdge
 
145
{
 
146
   if (![self enclosingScrollView])
 
147
   {
 
148
      return;
 
149
   }
 
150
 
 
151
   NSRect visibleRect = [[self enclosingScrollView] documentVisibleRect];
 
152
   NSPoint targetPoint = NSMakePoint(NSWidth([self frame]) - NSWidth(visibleRect),
 
153
                                     NSMinY(visibleRect));
 
154
 
 
155
   [self scrollPoint: targetPoint];
 
156
}
 
157
 
 
158
- (BOOL) scrollLineLeft
 
159
{
 
160
   if (![self enclosingScrollView])
 
161
   {
 
162
      return NO;
 
163
   }
 
164
   
 
165
   return [self scrollLeft: [[self enclosingScrollView] horizontalLineScroll]];
 
166
}
 
167
 
 
168
- (BOOL) scrollLineRight
 
169
{
 
170
   if (![self enclosingScrollView])
 
171
   {
 
172
      return NO;
 
173
   }
 
174
 
 
175
   return [self scrollRight: [[self enclosingScrollView] horizontalLineScroll]];
 
176
}
 
177
 
 
178
- (BOOL) scrollLeft: (float)amount
 
179
{
 
180
   if (![self enclosingScrollView])
 
181
   {
 
182
      return NO;
 
183
   }
 
184
 
 
185
   NSAssert(amount > 0, @"negative amount");
 
186
 
 
187
   NSRect visibleRect = [[self enclosingScrollView] documentVisibleRect];
 
188
   NSPoint targetPoint = NSMakePoint(NSMinX(visibleRect) - amount,
 
189
                                     NSMinY(visibleRect));
 
190
 
 
191
   if (targetPoint.x < 0)
 
192
   {
 
193
      targetPoint.x = 0;
 
194
   }
 
195
   [self scrollPoint: targetPoint];
 
196
 
 
197
   return !NSEqualRects(visibleRect, [[self enclosingScrollView] documentVisibleRect]);
 
198
}
 
199
 
 
200
- (BOOL) scrollRight: (float)amount
 
201
{
 
202
   if (![self enclosingScrollView])
 
203
   {
 
204
      return NO;
 
205
   }
 
206
 
 
207
   NSAssert(amount > 0, @"negative amount");
 
208
 
 
209
   NSRect visibleRect = [[self enclosingScrollView] documentVisibleRect];
 
210
   NSPoint targetPoint = NSMakePoint(NSMinX(visibleRect) + amount,
 
211
                                     NSMinY(visibleRect));
 
212
 
 
213
   float maxX = NSWidth([self frame]) - NSWidth(visibleRect);
 
214
   if (targetPoint.x > maxX)
 
215
   {
 
216
      targetPoint.x = maxX;
 
217
   }
 
218
   [self scrollPoint: targetPoint];
 
219
 
 
220
   return !NSEqualRects(visibleRect, [[self enclosingScrollView] documentVisibleRect]);
 
221
}
 
222
 
 
223
@end
 
224