-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathViewController.swift
320 lines (250 loc) · 10.2 KB
/
ViewController.swift
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause
import WinSDK
import class Foundation.NSNotification
/// Transition styles available when presenting view controllers.
public enum ModalTransitionStyle: Int {
case coverVertical
case flipHorizontal
case crossDissolve
case partialCurl
}
/// Constants that specify the edges of a rectangle.
public struct RectEdge: OptionSet {
public typealias RawValue = UInt
public let rawValue: RawValue
public init(rawValue: RawValue) {
self.rawValue = rawValue
}
}
extension RectEdge {
/// The top edge of the rectangle.
public static var top: RectEdge {
RectEdge(rawValue: 1 << 0)
}
/// The left edge of the rectangle.
public static var left: RectEdge {
RectEdge(rawValue: 1 << 1)
}
/// The bottom edge of the rectangle.
public static var bottom: RectEdge {
RectEdge(rawValue: 1 << 2)
}
/// The right edge of the rectangle.
public static var right: RectEdge {
RectEdge(rawValue: 1 << 3)
}
/// All edges of the rectangle.
public static var all: RectEdge {
RectEdge(rawValue: 0xf)
}
}
/// An object that manages a view hierarchy for your application.
open class ViewController: Responder {
// MARK - Managing the View
/// The view that the controller manages.
public var view: View! {
get {
loadViewIfNeeded()
return self.viewIfLoaded
}
set {
self.viewIfLoaded = newValue
}
}
/// The controller's view or `nil` if the view is not yet loaded.
public private(set) var viewIfLoaded: View?
/// Indicates if the view is loaded into memory.
public var isViewLoaded: Bool {
return self.viewIfLoaded == nil ? false : true
}
/// Creates the view that the controller manages.
public func loadView() {
self.view = View(frame: .zero)
}
/// Called after the controller's view is loaded info memory.
public func viewDidLoad() {
}
/// Loads the controller's view if it has not yet been loaded.
public func loadViewIfNeeded() {
guard !self.isViewLoaded else { return }
self.loadView()
self.viewDidLoad()
}
/// A localized string that represents the view this controller manages.
public var title: String? {
get {
let szLength: Int32 = GetWindowTextLengthW(view.hWnd)
let buffer: [WCHAR] = Array<WCHAR>(unsafeUninitializedCapacity: Int(szLength) + 1) {
$1 = Int(GetWindowTextW(view.hWnd, $0.baseAddress!, CInt($0.count)))
}
return String(decodingCString: buffer, as: UTF16.self)
}
set(value) { _ = SetWindowTextW(view.hWnd, value?.wide) }
}
/// The preferred size for the view controller's view.
public var preferredContentSize: Size {
fatalError("not yet implemented")
}
// MARK - Responding to View Related Events
/// Notifies the view controller that its view is about to be added to a view
/// hierarchy.
public func viewWillAppear(_ animated: Bool) {
}
/// Notifies the view controller that its view was added to a view hierarchy.
public func viewDidAppear(_ animated: Bool) {
}
/// Notifies the view controller that its view is about to be removed from a
/// view hierarchy.
public func viewWillDisappear(_ animated: Bool) {
}
/// Notifies the view controller that its view was removed from a view
/// hierarchy.
public func viweDidDisappear(_ animated: Bool) {
}
/// A boolean value indicating whether the view controller is being dismissed.
public private(set) var isBeingDismissed: Bool = false
/// A boolean value indicating whether the view controller is being presented.
public private(set) var isBeingPresented: Bool = false
/// A boolean value indicating whether the view controller is being removed
/// from a parent view controller.
public private(set) var isMovingFromParent: Bool = false
/// A boolean value indicating whether the view controller is being moved to a
/// parent view controller.
public private(set) var isMovingToParent: Bool = false
// MARK - Extending the View's Safe Area
/// The inset distances for views.
public var additionalSafeAreaInsets: EdgeInsets = .zero {
didSet { self.viewSafeAreaInsetsDidChange() }
}
/// Notifies the view controller that the safe area insets of its root view
/// changed.
public func viewSafeAreaInsetsDidChange() {
}
// MARK - Managing the View's Margins
/// A boolean value indicating whether the view controller's view uses the
/// system-defined minimum layout margins.
public var viewRespectsSystemMinimumLayoutMargins: Bool = true
/// The minimum layout margins for the view controller's root view.
public private(set) var systemMinimumLayoutMargins: DirectionalEdgeInsets = .zero {
didSet { self.viewLayoutMarginsDidChange() }
}
/// Notifies the view controller that the layout margins of its root view
/// changed.
public func viewLayoutMarginsDidChange() {
}
// MARK - Configuring the View's Layout Behavior
/// The edges that you extend for your view controller.
public var edgesForExtendedLayout: RectEdge = .all
/// A boolean value indicating whether or not the extended layout includes
/// opaque bars.
public var extendedLayoutIncludesOpaqueBars: Bool = false
/// Notifies the view controller that its view is about to layout its
/// subviews.
public func viewWillLayoutSubviews() {
}
/// Notifes the view controller that its view has just laid out its subviews.
public func viewDidLayoutSubviews() {
}
/// Called when the view controller's view needs to update its constraints.
public func updateViewConstraints() {
fatalError("\(#function) not yet implemented")
}
// MARK - Configuring the View Rotation Settings
/// A boolean value that indicates whether the view controller's contents
/// should autorotate.
public private(set) var shouldAutorotate: Bool = true
/// The interface orientations that the view controller supports.
public private(set) var supportedInterfaceOrientations: InterfaceOrientationMask = .allButUpsideDown
/// The interface orientation to use when presenting the view controller.
public private(set) var preferredInterfaceOrientationForPresentation: InterfaceOrientation = .portrait
/// Attempts to rotate all windows to the orientation of the device.
public class func attemptRotationToDeviceOrientation() {
}
// MARK - Presenting a View Controller
/// Presents a view controller in a primary context.
public func show(_ viewController: ViewController, sender: Any?) {
}
/// Presents a view controller in a secondary (or detail) context.
public func showDetailViewController(_ viewController: ViewController,
sender: Any?) {
}
/// Presents a view controller modally.
public func present(_ viewController: ViewController, animated flag: Bool,
completion: (() -> Void)? = nil) {
}
/// Dismisses the view controller that was presented modally by the view
/// controller.
public func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
}
/// The presentation style for modal view controllers.
public var modalPresentationStyle: ModalPresentationStyle = .automatic {
didSet { fatalError("\(#function) not yet implemented") }
}
/// The transition style to use when presenting the view controller.
public var modalTransitionStyle: ModalTransitionStyle = .coverVertical
/// A boolean value indicating whether the view controller enforces a modal
/// behavior.
public var isModalInPresentation: Bool = false {
didSet { fatalError("\(#function) not yet implemented") }
}
/// A boolean value that indicates whether this view controller's view is
/// covered when the view controller or one of its descendants presents a view
/// controller.
public var definesPresentationContext: Bool = false {
didSet { fatalError("\(#function) not yet implemented") }
}
/// A boolean value that indicates whether the view controller specifies the
/// transition style for view controllers it presents.
public var providesPresentationContextTransitionStyle: Bool = false {
didSet { fatalError("\(#function) not yet implemented") }
}
/// Returns a boolean indicating whether the current input view is dismissed
/// automatically when changing controls.
var disablesAutomaticKeyboardDismissal: Bool {
return self.modalPresentationStyle == .formSheet
}
/// Posted when a split view controller is expanded or collapsed.
public class var showDetailTargetDidChangeNotification: NSNotification.Name {
NSNotification.Name(rawValue: "UIViewControllerShowDetailTargetDidChangeNotification")
}
// MARK - Responding to Containment Events
/// Called just before the view controller is added or removed from a
/// container view controller.
public func willMove(toParent viewController: ViewController?) {
}
/// Called after the view controller is added or removed from a container view
/// controller.
public func didMove(toParent viewController: ViewController?) {
}
// MARK -
override public init() {
}
// MARK - Responder Chain
override public var next: Responder? {
return view?.superview
}
}
extension ViewController: ContentContainer {
/// Notifies the container that the size of its view is about to change.
public func willTransition(to: Size,
with coodinator: ViewControllerTransitionCoordinator) {
}
/// Notifies the container that its trait collection changed.
public func willTransition(to: TraitCollection,
with coordinator: ViewControllerTransitionCoordinator) {
}
/// Returns the size of the specified child view controller’s content.
public func size(forChildContentContainer container: ContentContainer,
withParentContainerSize parentSize: Size) -> Size {
return .zero
}
/// Notifies an interested controller that the preferred content size of one
/// of its children changed.
public func preferredContentSizeDidChange(forChildContentContainer container: ContentContainer) {
}
/// Notifies the container that a child view controller was resized using auto
/// layout.
public func systemLayoutFittingSizeDidChange(forChildContentContainer container: ContentContainer) {
}
}