summaryrefslogtreecommitdiff
path: root/ios/experimental/LibreOffice/LibreOffice/View.m
blob: a047bb0874f6972aa1036bd14da36f040f23ffb7 (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
// -*- 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 "View.h"

#include <osl/detail/ios-bootstrap.h>

@implementation View

- (void)drawRect:(CGRect)rect
{
    NSLog(@"drawRect: %dx%d@(%d,%d)", (int) rect.size.width, (int) rect.size.height, (int) rect.origin.x, (int) rect.origin.y);
    NSLog(@"statusBarOrientation: %ld", (long)[[UIApplication sharedApplication] statusBarOrientation]);

    // NSDate *startDate = [NSDate date];

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);

    switch ([[UIApplication sharedApplication] statusBarOrientation]) {
    case UIInterfaceOrientationPortrait:
        CGContextTranslateCTM(context, 0, self.frame.size.height);
        CGContextScaleCTM(context, 1, -1);
        break;
    case UIInterfaceOrientationLandscapeLeft:
        CGContextTranslateCTM(context, 0, self.frame.size.width);
        CGContextScaleCTM(context, 1, -1);
        break;
    case UIInterfaceOrientationLandscapeRight:
        CGContextTranslateCTM(context, 0, self.frame.size.width);
        CGContextScaleCTM(context, 1, -1);
        break;
    case UIInterfaceOrientationPortraitUpsideDown:
        CGContextTranslateCTM(context, 0, self.frame.size.height);
        CGContextScaleCTM(context, 1, -1);
        break;
    }
    lo_render_windows(context, rect);
    CGContextRestoreGState(context);

    // NSLog(@"drawRect: lo_render_windows took %f s", [[NSDate date] timeIntervalSinceDate: startDate]);
}

- (void)tapGesture:(UITapGestureRecognizer *)gestureRecognizer
{
    if ([gestureRecognizer state] == UIGestureRecognizerStateEnded) {
        CGPoint location = [gestureRecognizer locationInView: self];

        NSLog(@"tapGesture: at: (%d,%d)", (int)location.x, (int)location.y);

        lo_tap(location.x, location.y);

        [self->textView becomeFirstResponder];
    } else {
        NSLog(@"tapGesture: %@", gestureRecognizer);
    }
}

- (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer
{
    static CGFloat previousX = 0.0f, previousY = 0.0f;

    CGPoint translation = [gestureRecognizer translationInView: self];

    if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
        int deltaX = translation.x - previousX;
        int deltaY = translation.y - previousY;

        NSLog(@"panGesture: pan (delta): (%d,%d)", deltaX, deltaY);

        lo_pan(deltaX, deltaY);
    }

    previousX = translation.x;
    previousY = translation.y;
}

- (void)pinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer
{
    CGPoint location = [gestureRecognizer locationInView: self];
    CGFloat scale = gestureRecognizer.scale;

    NSLog(@"pinchGesture: pinch: (%f) cords (%d,%d)", (float)scale, (int)location.x, (int)location.y );

    lo_zoom((int)location.x, (int)location.y, (float)scale);

    // to reset the gesture scaling
    if (gestureRecognizer.state==UIGestureRecognizerStateEnded) {
        lo_zoom(1, 1, 0.0f);
    }
}

- (void)longPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer
{
    CGPoint point = [gestureRecognizer locationInView:self];

    UIGestureRecognizerState state = gestureRecognizer.state;

    NSLog(@"longPressGesture: state %d cords (%d,%d)",state ,(int)point.x,(int)point.y);

    if (state == UIGestureRecognizerStateBegan) {
        lo_mouse_drag(point.x, point.y, DOWN);
    } else if (state == UIGestureRecognizerStateChanged) {
        lo_mouse_drag(point.x, point.y, MOVE);
    } else if (state == UIGestureRecognizerStateEnded) {
        lo_mouse_drag(point.x, point.y, UP);
    }
}

@end

// vim:set shiftwidth=4 softtabstop=4 expandtab: