blob: ccb9d5df6ffd3fe775c94422c4dc579452262096 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
// -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
//
// This file is part of the LibreOffice project.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#import "MLOScrollerViewController.h"
#import "MLOMainViewController.h"
#import "MLOSubView.h"
#import "MLOScrollerData.h"
#import "MLOScrollerTooltip.h"
#import "MLOScrollerGridViewController.h"
#import "mlo_uno.h"
@interface MLOScrollerViewController ()
@property BOOL isContentChanged,hasUpdated;
@property MLOMainViewController * mainViewController;
@property MLOSubView * scroller;
@property MLOScrollerTooltip * tooltip;
@property MLOScrollerGridViewController * grid;
@property NSDate * fadeOutTime;
@end
static const CGFloat
SCROLLER_CORNER_RADIUS =3.0f,
RESHAPE_ANIMATION_DURATION= 0.05f,
SCROLLER_FADE_OUT_DELAY=0.45f,
SCROLLER_FADE_OUT_DURATION=1.0f,
SCROLLER_FADE_OUT_INVOCATION =SCROLLER_FADE_OUT_DELAY+0.05f;
// Tooltip is removed at request of PM
// Maybe they'll want it back, or similar, in the future
static const BOOL IS_SHOW_TOOLTIP =NO;
@implementation MLOScrollerViewController
-(id) initWithMainViewController:(MLOMainViewController *) mainViewController{
self = [super init];
if(self){
self.mainViewController = mainViewController;
self.scroller = [[MLOSubView alloc] initHiddedWithColor:[UIColor grayColor] cornerRadius:SCROLLER_CORNER_RADIUS];
self.data = [[MLOScrollerData alloc] initWithMainViewController:mainViewController];
if(IS_SHOW_TOOLTIP){
self.tooltip = [MLOScrollerTooltip new];
}else{
self.tooltip = nil;
}
self.fadeOutTime = nil;
self.grid = [[MLOScrollerGridViewController alloc] initWithMainViewController:mainViewController];
_isContentChanged =YES;
_hasUpdated =NO;
[_data onRotateWithGrid:_grid];
}
return self;
}
-(void) addToMainViewController{
[_mainViewController.canvas addSubview:_scroller];
[_mainViewController.canvas addSubview:_tooltip];
}
-(void) showLibreOffice{
[_data showLibreOffice];
[self contentHasChanged];
if(mlo_is_document_open()){
[self updateByLogic:NO];
}
}
-(void)contentHasChanged{
self.isContentChanged = YES;
}
-(void)onRotate{
[self contentHasChanged];
[_data onRotateWithGrid:_grid];
}
-(void)updateByLogic{
[self updateByLogic:YES];
}
-(void)updateByPixelDeltaY:(CGFloat) pixelDeltaY{
[self updateAndShowScroller:YES newScrollerFrame:[_data getShiftedScrollerFrame:pixelDeltaY]];
}
-(void)updateByLogic:(BOOL) isShow {
if(_isContentChanged){
[_grid onPageCountChanged:[_data getTotalPages]];
_isContentChanged=NO;
}
[self updateAndShowScroller:isShow newScrollerFrame:[_data getNewScrollerFrame]];
}
-(void)updateAndShowScroller:(BOOL) isShow newScrollerFrame:(CGRect) newScrollerFrame{
if(isShow){
_scroller.alpha = 0.5;
}
[UIView animateWithDuration:_hasUpdated ? RESHAPE_ANIMATION_DURATION :0.0f
animations:^{ _scroller.frame = newScrollerFrame; }
completion:^(BOOL isCompleted){
self.fadeOutTime = [NSDate dateWithTimeIntervalSinceNow:SCROLLER_FADE_OUT_DELAY];
[self performSelector:@selector(timedFadeOut) withObject:nil afterDelay:SCROLLER_FADE_OUT_INVOCATION];
}];
[_data updateTooltip:_tooltip withGrid:_grid];
_hasUpdated=YES;
}
-(void) reset{
[_scroller hide];
[_tooltip hide];
_hasUpdated=NO;
[self onRotate];
}
-(void) timedFadeOut {
NSDate * date = self.fadeOutTime;
if(![[date laterDate:[NSDate date]] isEqualToDate:date]){
[self fadeOut];
}
}
-(void)fadeOut{
[_scroller fade:OUT];
}
-(void) hideLibreOffice{
[_tooltip hideLibreOffice];
[_grid hide];
[self contentHasChanged];
[_data hideLibreOffice];
}
@end
|