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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
// -*- 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 "MLOScrollerData.h"
#import "MLOMainViewController_Friend.h"
#import "MLOGestureEngine_Impl.h"
#import "MLOScrollerGridViewController.h"
#import "MLOScrollerTooltip.h"
#import "MLOGestureLimiter.h"
#import "mlo_uno.h"
#import "mlo_utils.h"
@interface MLOScrollerData ()
@property int left, top, zoom, visibleLeft, visibleTop, visibleRight, visibleBottom, zoomType, isBooklet;
@property float totalPages, totalHeightInLogic, frameWidth, frameHeight, scrollerX, scrollerTotalHeight,tooltipPageHeight,tooltipX,tooltipMaxY;
@property NSMutableString *mutableString;
@property CGRect maxCanvas,contentCanvas,visibleCanvas;
@property MLOMainViewController * mainViewController;
@end
static const float
SCROLLER_WIDTH=10,
SCROLLER_PADDING = 0,
GRID_TO_TOOLTIP_DISTANCE = 2.0f,
TOOLTIP_HEIGHT=60,
TOOLTIP_WIDTH=100,
FLOAT_RESET=-1.0f;
static const int INT_RESET= -1;
@implementation MLOScrollerData
-(id)initWithMainViewController:(MLOMainViewController *) mainViewController{
self= [super init];
if(self){
self.mutableString = [NSMutableString stringWithString:@""];
self.mainViewController = mainViewController;
[self reset];
}
return self;
}
-(void) showLibreOffice{
}
-(void)hideLibreOffice{
[self reset];
}
-(void)reset{
_tooltipMaxY= _tooltipPageHeight = _tooltipX = _totalPages = _totalHeightInLogic = _frameWidth= _frameHeight= _scrollerX= _scrollerTotalHeight = FLOAT_RESET;
_left = _top = _zoom = _visibleLeft = _visibleTop = _visibleRight = _visibleBottom = _zoomType = _isBooklet = INT_RESET;
}
-(void) updateViewData{
mlo_fetch_view_data(_mutableString);
sscanf([_mutableString UTF8String], "%d;%d;%d;%d;%d;%d;%d;%d;%d;",
&_left,
&_top,
&_zoom,
&_visibleLeft,
&_visibleTop,
&_visibleRight,
&_visibleBottom,
&_zoomType,
&_isBooklet);
if(LOG_GET_VIEW_DATA){
NSLog(@"left=%d top=%d zoom=%d vLeft=%d vTop=%d vRight=%d vBottom=%d zoomType=%d isBooklet=%d",
_left,
_top,
_zoom,
_visibleLeft,
_visibleTop,
_visibleRight,
_visibleBottom,
_zoomType,
_isBooklet);
}
}
-(BOOL)canCalculateDocumentSizeInLogic{
return (_totalHeightInLogic != FLOAT_RESET);
}
-(void) onRotateWithGrid:(MLOScrollerGridViewController *) grid{
static const float SCROLLLER_X_OFFSET =SCROLLER_PADDING + SCROLLER_WIDTH ,
DOUBLE_SCROLLER_PADDING =2*SCROLLER_PADDING,
GRID_X_OFFSET= MLO_SCROLLER_GRID_WIDTH,
TOOLTIP_X_OFFSET= GRID_X_OFFSET + GRID_TO_TOOLTIP_DISTANCE+ TOOLTIP_WIDTH;
CGRect canvasFrame = _mainViewController.canvas.frame;
_frameHeight = canvasFrame.size.height;
_frameWidth = canvasFrame.size.width;
_scrollerX = _frameWidth - SCROLLLER_X_OFFSET;
_tooltipX = _frameWidth - TOOLTIP_X_OFFSET;
_tooltipMaxY = _frameHeight - TOOLTIP_HEIGHT;
_scrollerTotalHeight =_frameHeight -DOUBLE_SCROLLER_PADDING;
_tooltipPageHeight = _frameHeight/_totalPages;
[grid onRotate:_frameWidth - GRID_X_OFFSET];
}
-(NSInteger) getTotalPages{
NSInteger newTotalPages= mlo_get_page_count();
if(newTotalPages!= _totalPages){
_totalPages = newTotalPages;
_totalHeightInLogic = _totalPages* PORTRAIT_PAGE_HEIGHT_IN_LOGIC_WITH_SEPARATOR;
_tooltipPageHeight = _frameHeight/_totalPages;
_mainViewController.gestureEngine.limiter.documentSizeInLogic = CGSizeMake(CANVAS_WIDTH_IN_LOGIC,
_totalHeightInLogic);
}
return newTotalPages;
}
-(CGRect) getShiftedScrollerFrame:(CGFloat) pixelDeltaX{
pixelDeltaX *= PIXEL_TO_LOGIC_RATIO / [_mainViewController getZoom] * 100;
CGFloat newTop = _visibleTop + pixelDeltaX;
CGFloat newBottom = _visibleBottom + pixelDeltaX;
BOOL isOverTop = newTop < 0.0f;
BOOL isBelowBotton = newBottom > _totalHeightInLogic;
if(!isOverTop && !isBelowBotton){
_visibleTop = newTop;
_visibleBottom = newBottom;
}else{
CGFloat scrollerHeightInLogic = _visibleBottom- _visibleTop;
if(isOverTop){
_visibleTop = 0.0f;
_visibleBottom =scrollerHeightInLogic;
}else{
_visibleBottom = _totalHeightInLogic;
_visibleTop = _totalHeightInLogic - scrollerHeightInLogic;
}
}
return [self getNewScrollerFrame];
}
-(CGRect)getNewScrollerFrame{
[self updateViewData];
CGFloat topRatio = max(_visibleTop / _totalHeightInLogic,0.0);
CGFloat heightRatio = min((_visibleBottom / _totalHeightInLogic) - topRatio,1.0);
return CGRectMake(_scrollerX,
SCROLLER_PADDING +topRatio*_scrollerTotalHeight,
SCROLLER_WIDTH,
heightRatio*_scrollerTotalHeight);
}
-(NSInteger) getCurrentPage{
return min(
max(
ceilf(
_visibleTop
/ PORTRAIT_PAGE_HEIGHT_IN_LOGIC_WITH_SEPARATOR
),
1),
_totalPages);
}
-(void) updateTooltip:(MLOScrollerTooltip *) tooltip withGrid:(MLOScrollerGridViewController *) grid{
if(mlo_is_document_open() && _visibleTop>=0){
NSInteger currentPage = [self getCurrentPage];
if(tooltip){
[tooltip updateWithFrame:CGRectMake(_tooltipX,
min(_tooltipPageHeight * (currentPage -1),_tooltipMaxY),
TOOLTIP_WIDTH,
TOOLTIP_HEIGHT) inPage:currentPage];
}
[grid onCurrentPageChanged:currentPage];
}
}
@end
|