1/*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef WKView_h
27#define WKView_h
28
29#if TARGET_OS_IPHONE
30
31#import "WKUtilities.h"
32#import <CoreGraphics/CoreGraphics.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38@class WAKWindow;
39
40enum {
41    NSViewNotSizable = 0,
42    NSViewMinXMargin = 1,
43    NSViewWidthSizable = 2,
44    NSViewMaxXMargin = 4,
45    NSViewMinYMargin = 8,
46    NSViewHeightSizable = 16,
47    NSViewMaxYMargin = 32
48};
49
50typedef enum {
51    WKViewNotificationViewDidMoveToWindow,
52    WKViewNotificationViewFrameSizeChanged,
53    WKViewNotificationViewDidScroll
54} WKViewNotificationType;
55
56typedef enum {
57    WKViewResponderAcceptsFirstResponder,
58    WKViewResponderBecomeFirstResponder,
59    WKViewResponderResignFirstResponder,
60} WKViewResponderCallbackType;
61
62typedef void (*WKViewDrawCallback)(WKViewRef view, CGRect dirtyRect, void *userInfo);
63typedef void (*WKViewNotificationCallback)(WKViewRef view, WKViewNotificationType type, void *userInfo);
64typedef bool (*WKViewResponderCallback)(WKViewRef view, WKViewResponderCallbackType type, void *userInfo);
65typedef void (*WKViewWillRemoveSubviewCallback)(WKViewRef view, WKViewRef subview);
66typedef void (*WKViewInvalidateGStateCallback)(WKViewRef view);
67
68typedef struct _WKViewContext {
69    WKViewNotificationCallback notificationCallback;
70    void *notificationUserInfo;
71    WKViewResponderCallback responderCallback;
72    void *responderUserInfo;
73    WKViewWillRemoveSubviewCallback willRemoveSubviewCallback;
74    WKViewInvalidateGStateCallback invalidateGStateCallback;
75} WKViewContext;
76
77struct _WKView {
78    WKObject isa;
79
80    WKViewContext *context;
81
82    __unsafe_unretained WAKWindow *window;
83
84    WKViewRef superview;
85    CFMutableArrayRef subviews;
86
87    CGPoint origin;
88    CGRect bounds;
89
90    unsigned int autoresizingMask;
91
92    float scale;
93
94    // This is really a WAKView.
95    void *wrapper;
96};
97
98extern WKClassInfo WKViewClassInfo;
99
100WKViewRef WKViewCreateWithFrame (CGRect rect, WKViewContext *context);
101void WKViewInitialize (WKViewRef view, CGRect rect, WKViewContext *context);
102
103void WKViewSetViewContext (WKViewRef view, WKViewContext *context);
104void WKViewGetViewContext (WKViewRef view, WKViewContext *context);
105
106CGRect WKViewGetBounds (WKViewRef view);
107
108void WKViewSetFrameOrigin (WKViewRef view, CGPoint newPoint);
109void WKViewSetFrameSize (WKViewRef view, CGSize newSize);
110void WKViewSetBoundsOrigin(WKViewRef view, CGPoint newOrigin);
111void WKViewSetBoundsSize (WKViewRef view, CGSize newSize);
112
113CGRect WKViewGetFrame (WKViewRef view);
114
115void WKViewSetScale (WKViewRef view, float scale);
116float WKViewGetScale (WKViewRef view);
117CGAffineTransform _WKViewGetTransform(WKViewRef view);
118
119WAKWindow *WKViewGetWindow (WKViewRef view);
120
121CFArrayRef WKViewGetSubviews (WKViewRef view);
122
123WKViewRef WKViewGetSuperview (WKViewRef view);
124
125void WKViewAddSubview (WKViewRef view, WKViewRef subview);
126void WKViewRemoveFromSuperview (WKViewRef view);
127
128CGPoint WKViewConvertPointToSuperview (WKViewRef view, CGPoint aPoint);
129CGPoint WKViewConvertPointFromSuperview (WKViewRef view, CGPoint aPoint);
130CGPoint WKViewConvertPointToBase(WKViewRef view, CGPoint aPoint);
131CGPoint WKViewConvertPointFromBase(WKViewRef view, CGPoint aPoint);
132
133CGRect WKViewConvertRectToSuperview (WKViewRef view, CGRect aRect);
134CGRect WKViewConvertRectFromSuperview (WKViewRef view, CGRect aRect);
135CGRect WKViewConvertRectToBase (WKViewRef view, CGRect r);
136CGRect WKViewConvertRectFromBase (WKViewRef view, CGRect aRect);
137
138CGRect WKViewGetVisibleRect (WKViewRef view);
139
140WKViewRef WKViewFirstChild (WKViewRef view);
141WKViewRef WKViewNextSibling (WKViewRef view);
142WKViewRef WKViewTraverseNext (WKViewRef view);
143
144bool WKViewAcceptsFirstResponder (WKViewRef view);
145bool WKViewBecomeFirstResponder (WKViewRef view);
146bool WKViewResignFirstResponder (WKViewRef view);
147
148unsigned int WKViewGetAutoresizingMask(WKViewRef view);
149void WKViewSetAutoresizingMask (WKViewRef view, unsigned int mask);
150
151void WKViewScrollToRect(WKViewRef view, CGRect rect);
152
153#ifdef __cplusplus
154}
155#endif
156
157#endif // TARGET_OS_IPHONE
158
159#endif // WKView_h
160