macOS: Use dark appearance for panel modals
[vlc.git] / modules / gui / macosx / VLCScrollingClipView.m
blobe058809f1d9260523b521692ba008ff385b305e9
1 /*****************************************************************************
2  * VLCScrollingClipView.m: NSClipView subclass that automatically scrolls
3  *****************************************************************************
4  * Copyright (C) 2015 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Author: Marvin Scholz <epirat07@gmail.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
24 #import "VLCScrollingClipView.h"
26 @implementation VLCScrollingClipView {
27     NSTimer *scrollTimer;
28     NSTimeInterval startInterval;
31 - (void)startScrolling {
32     // Start our timer unless running
33     if (!scrollTimer) {
34         scrollTimer = [NSTimer scheduledTimerWithTimeInterval: 1/6
35                                                        target:self
36                                                      selector:@selector(scrollTick:)
37                                                      userInfo:nil
38                                                       repeats:YES];
39     }
42 - (void)stopScrolling {
43     // Stop timer unless stopped
44     if (scrollTimer) {
45         [scrollTimer invalidate];
46         scrollTimer = nil;
47     }
50 - (void)resetScrolling {
51     startInterval = 0;
52     [self scrollToPoint:NSMakePoint(0.0, 0.0)];
53     if (_parentScrollView) {
54         [_parentScrollView reflectScrolledClipView:self];
55     }
58 - (void)scrollWheel:(NSEvent *)theEvent {
59     // Stop auto-scrolling if the user scrolls
60     [self stopScrolling];
61     [super scrollWheel:theEvent];
64 - (void)scrollTick:(NSTimer *)timer {
65     CGFloat maxHeight = self.documentRect.size.height;
66     CGFloat scrollPosition = self.documentVisibleRect.origin.y;
68     // Delay start
69     if (scrollPosition == 0.0 && !startInterval) {
70         startInterval = [NSDate timeIntervalSinceReferenceDate] + 2.0;
71     }
73     if ([NSDate timeIntervalSinceReferenceDate] >= startInterval) {
74         // Reset if we are past the end
75         if (scrollPosition > maxHeight) {
76             [self resetScrolling];
77             return;
78         }
80         // Scroll the view a bit on each tick
81         [self scrollToPoint:NSMakePoint(0.0, scrollPosition + 0.5)];
83         // Update the parent ScrollView
84         if (_parentScrollView) {
85             [_parentScrollView reflectScrolledClipView:self];
86         }
87     }
90 @end