From 1118fefe477cfedad29941a3e3c259ae67e2a474 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 17 Nov 2023 17:24:33 -0800 Subject: [PATCH] SwiftWin32: further adopt static libraries on 5.7+ Swift 5.7.0 enables static libraries for non-standard library cases. Use this to extract the CoreGraphics interfaces out of the primary library. --- Examples/Calculator/Calculator.swift | 4 ++++ Examples/UICatalog/UICatalog.swift | 4 ++++ Package.swift | 11 +++++++-- Package@swift-5.7.swift | 11 +++++++-- .../CubicTimingParameters.swift | 4 ++++ .../SpringTimingParameters.swift | 4 ++++ ...ntrollerTransitionCoordinatorContext.swift | 4 ++++ .../ViewControllerContextTransitioning.swift | 4 ++++ .../ListContentConfiguration.swift | 4 ++++ .../SwiftWin32/AutoLayout/LayoutGuide.swift | 4 ++++ Sources/SwiftWin32/CMakeLists.txt | 22 +++++++++++++----- .../AffineTransform.swift | 0 .../{CG => CoreGraphics}/Point.swift | 0 .../{CG => CoreGraphics}/Rect.swift | 14 ----------- .../{CG => CoreGraphics}/Size.swift | 0 .../{CG => CoreGraphics}/Vector.swift | 0 .../Focus-Based Navigation/FocusItem.swift | 4 ++++ .../FocusItemContainer.swift | 4 ++++ .../FocusMovementHint.swift | 1 + Sources/SwiftWin32/Images and PDF/Image.swift | 4 ++++ .../ContextMenuInteraction.swift | 4 ++++ .../ContextMenuInteractionDelegate.swift | 4 ++++ .../Menus and Shortcuts/PreviewTarget.swift | 4 ++++ .../Menus and Shortcuts/TargetedPreview.swift | 4 ++++ .../Pointer Interactions/PointerRegion.swift | 4 ++++ .../PointerRegionRequest.swift | 4 ++++ .../Pointer Interactions/PointerStyle.swift | 4 ++++ .../Support/Point+UIExtensions.swift | 3 +++ .../Support/Rect+UIExtensions.swift | 23 ++++++++++++++++--- .../Support/Size+UIExtensions.swift | 4 ++++ .../Support/WinSDK+Extensions.swift | 15 ++++++++++++ .../FontDescriptor.swift | 4 ++++ .../GestureRecognizer.swift | 4 ++++ .../SwiftWin32/UI/SceneSizeRestrictions.swift | 4 ++++ .../View Controllers/ContentContainer.swift | 4 ++++ .../PresentationController.swift | 4 ++++ .../View Controllers/ViewController.swift | 4 ++++ .../Views and Controls/Button.swift | 4 ++++ .../Views and Controls/DatePicker.swift | 4 ++++ .../Views and Controls/ImageView.swift | 4 ++++ .../SwiftWin32/Views and Controls/Label.swift | 4 ++++ .../Views and Controls/PickerView.swift | 6 ++++- .../Views and Controls/ProgressView.swift | 4 ++++ .../Views and Controls/Slider.swift | 4 ++++ .../Views and Controls/Stepper.swift | 4 ++++ .../Views and Controls/Switch.swift | 4 ++++ .../Table Views/TableView.swift | 4 ++++ .../Table Views/TableViewCell.swift | 4 ++++ .../Table Views/TableViewDelegate.swift | 4 ++++ .../TableViewHeaderFooterView.swift | 6 ++++- .../Views and Controls/TextField.swift | 4 ++++ .../Views and Controls/TextView.swift | 4 ++++ .../SwiftWin32/Views and Controls/View.swift | 8 +++++-- .../Windows and Screens/CoordinateSpace.swift | 4 ++++ .../Windows and Screens/Screen.swift | 4 ++++ .../Windows and Screens/Window.swift | 4 ++++ .../CoreGraphicsTests/CoreGraphicsTests.swift | 6 +++-- 57 files changed, 257 insertions(+), 33 deletions(-) rename Sources/SwiftWin32/{CG => CoreGraphics}/AffineTransform.swift (100%) rename Sources/SwiftWin32/{CG => CoreGraphics}/Point.swift (100%) rename Sources/SwiftWin32/{CG => CoreGraphics}/Rect.swift (95%) rename Sources/SwiftWin32/{CG => CoreGraphics}/Size.swift (100%) rename Sources/SwiftWin32/{CG => CoreGraphics}/Vector.swift (100%) diff --git a/Examples/Calculator/Calculator.swift b/Examples/Calculator/Calculator.swift index 40fa3e0b..2a2962b1 100644 --- a/Examples/Calculator/Calculator.swift +++ b/Examples/Calculator/Calculator.swift @@ -4,6 +4,10 @@ import SwiftWin32 import Foundation +#if swift(>=5.7) +import CoreGraphics +#endif + private extension View { func addSubviews(_ views: [View]) { _ = views.map { self.addSubview($0) } diff --git a/Examples/UICatalog/UICatalog.swift b/Examples/UICatalog/UICatalog.swift index 69f224c9..8282b7ad 100644 --- a/Examples/UICatalog/UICatalog.swift +++ b/Examples/UICatalog/UICatalog.swift @@ -8,6 +8,10 @@ import func WinSDK.MessageBoxW import let WinSDK.MB_OK import struct WinSDK.UINT +#if swift(>=5.7) +import CoreGraphics +#endif + private extension Label { convenience init(frame: Rect, title: String) { self.init(frame: frame) diff --git a/Package.swift b/Package.swift index acfbbf71..ceec4a26 100644 --- a/Package.swift +++ b/Package.swift @@ -27,9 +27,12 @@ let SwiftWin32: Package = targets: [ .target(name: "CoreAnimation", path: "Sources/SwiftWin32/CoreAnimation"), + .target(name: "CoreGraphics", + path: "Sources/SwiftWin32/CoreGraphics"), .target(name: "SwiftWin32", dependencies: [ "CoreAnimation", + "CoreGraphics", .product(name: "Logging", package: "swift-log"), .product(name: "OrderedCollections", package: "swift-collections"), @@ -37,7 +40,11 @@ let SwiftWin32: Package = .product(name: "SwiftCOM", package: "swift-com"), ], path: "Sources/SwiftWin32", - exclude: ["CoreAnimation", "CMakeLists.txt"], + exclude: [ + "CoreAnimation", + "CoreGraphics", + "CMakeLists.txt" + ], swiftSettings: [ .enableExperimentalFeature("AccessLevelOnImport"), ], @@ -76,7 +83,7 @@ let SwiftWin32: Package = ]), .target(name: "TestUtilities", path: "Tests/Utilities"), .testTarget(name: "AutoLayoutTests", dependencies: ["SwiftWin32"]), - .testTarget(name: "CoreGraphicsTests", dependencies: ["SwiftWin32"]), + .testTarget(name: "CoreGraphicsTests", dependencies: ["CoreGraphics"]), .testTarget(name: "SupportTests", dependencies: ["SwiftWin32"]), .testTarget(name: "UICoreTests", dependencies: ["SwiftWin32", "TestUtilities"]) diff --git a/Package@swift-5.7.swift b/Package@swift-5.7.swift index 01415971..e699cc56 100644 --- a/Package@swift-5.7.swift +++ b/Package@swift-5.7.swift @@ -27,9 +27,12 @@ let SwiftWin32: Package = targets: [ .target(name: "CoreAnimation", path: "Sources/SwiftWin32/CoreAnimation"), + .target(name: "CoreGraphics", + path: "Sources/SwiftWin32/CoreGraphics"), .target(name: "SwiftWin32", dependencies: [ "CoreAnimation", + "CoreGraphics", .product(name: "Logging", package: "swift-log"), .product(name: "OrderedCollections", package: "swift-collections"), @@ -37,7 +40,11 @@ let SwiftWin32: Package = .product(name: "SwiftCOM", package: "swift-com"), ], path: "Sources/SwiftWin32", - exclude: ["CoreAnimation", "CMakeLists.txt"], + exclude: [ + "CoreAnimation", + "CoreGraphics", + "CMakeLists.txt", + ], linkerSettings: [ .linkedLibrary("User32"), .linkedLibrary("ComCtl32"), @@ -73,7 +80,7 @@ let SwiftWin32: Package = ]), .target(name: "TestUtilities", path: "Tests/Utilities"), .testTarget(name: "AutoLayoutTests", dependencies: ["SwiftWin32"]), - .testTarget(name: "CoreGraphicsTests", dependencies: ["SwiftWin32"]), + .testTarget(name: "CoreGraphicsTests", dependencies: ["CoreGraphics"]), .testTarget(name: "SupportTests", dependencies: ["SwiftWin32"]), .testTarget(name: "UICoreTests", dependencies: ["SwiftWin32", "TestUtilities"]) diff --git a/Sources/SwiftWin32/Animation and Haptics/Property-Based Animations/CubicTimingParameters.swift b/Sources/SwiftWin32/Animation and Haptics/Property-Based Animations/CubicTimingParameters.swift index 8a3f6758..94b48be6 100644 --- a/Sources/SwiftWin32/Animation and Haptics/Property-Based Animations/CubicTimingParameters.swift +++ b/Sources/SwiftWin32/Animation and Haptics/Property-Based Animations/CubicTimingParameters.swift @@ -1,6 +1,10 @@ // Copyright © 2021 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// The timing information for animations in the form of a cubic Bézier curve. public class CubicTimingParameters { // MARK - Initializing a Cubic Timing Parameters Object diff --git a/Sources/SwiftWin32/Animation and Haptics/Property-Based Animations/SpringTimingParameters.swift b/Sources/SwiftWin32/Animation and Haptics/Property-Based Animations/SpringTimingParameters.swift index 745e742b..5cadc584 100644 --- a/Sources/SwiftWin32/Animation and Haptics/Property-Based Animations/SpringTimingParameters.swift +++ b/Sources/SwiftWin32/Animation and Haptics/Property-Based Animations/SpringTimingParameters.swift @@ -1,6 +1,10 @@ // Copyright © 2021 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// The timing information for animations that mimics the behavior of a spring. public class SpringTimingParameters { // MARK - Initializing a Spring Timing Parameters Object diff --git a/Sources/SwiftWin32/Animation and Haptics/View Controller Transitions/ViewControllerTransitionCoordinatorContext.swift b/Sources/SwiftWin32/Animation and Haptics/View Controller Transitions/ViewControllerTransitionCoordinatorContext.swift index 547f075f..43e3554a 100644 --- a/Sources/SwiftWin32/Animation and Haptics/View Controller Transitions/ViewControllerTransitionCoordinatorContext.swift +++ b/Sources/SwiftWin32/Animation and Haptics/View Controller Transitions/ViewControllerTransitionCoordinatorContext.swift @@ -3,6 +3,10 @@ import struct Foundation.TimeInterval +#if swift(>=5.7) +import CoreGraphics +#endif + /// Modal presentation styles available when presenting view controllers. public enum ModalPresentationStyle: Int { /// The default presentation style chosen by the system. diff --git a/Sources/SwiftWin32/Animation and Haptics/ViewControllerContextTransitioning.swift b/Sources/SwiftWin32/Animation and Haptics/ViewControllerContextTransitioning.swift index a3a021aa..c3b151c5 100644 --- a/Sources/SwiftWin32/Animation and Haptics/ViewControllerContextTransitioning.swift +++ b/Sources/SwiftWin32/Animation and Haptics/ViewControllerContextTransitioning.swift @@ -1,6 +1,10 @@ // Copyright © 2021 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// The keys you use to identify the view controllers involved in a transition. public struct TransitionContextViewControllerKey: Equatable, Hashable, RawRepresentable { public typealias RawValue = String diff --git a/Sources/SwiftWin32/Appearance Customization/Configurations/ListContentConfiguration.swift b/Sources/SwiftWin32/Appearance Customization/Configurations/ListContentConfiguration.swift index 03e31fa7..424b5fe9 100644 --- a/Sources/SwiftWin32/Appearance Customization/Configurations/ListContentConfiguration.swift +++ b/Sources/SwiftWin32/Appearance Customization/Configurations/ListContentConfiguration.swift @@ -3,6 +3,10 @@ import class Foundation.NSAttributedString +#if swift(>=5.7) +import CoreGraphics +#endif + extension ListContentConfiguration { /// Properties that affect the list content configuration's image. public struct ImageProperties { diff --git a/Sources/SwiftWin32/AutoLayout/LayoutGuide.swift b/Sources/SwiftWin32/AutoLayout/LayoutGuide.swift index ea6e288e..953ff580 100644 --- a/Sources/SwiftWin32/AutoLayout/LayoutGuide.swift +++ b/Sources/SwiftWin32/AutoLayout/LayoutGuide.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool . // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + public class LayoutGuide { // MARK - Working with Layout Guides diff --git a/Sources/SwiftWin32/CMakeLists.txt b/Sources/SwiftWin32/CMakeLists.txt index 147a9b77..61f666f5 100644 --- a/Sources/SwiftWin32/CMakeLists.txt +++ b/Sources/SwiftWin32/CMakeLists.txt @@ -134,12 +134,6 @@ target_sources(SwiftWin32 PRIVATE "Windows and Screens/CoordinateSpace.swift" "Windows and Screens/Screen.swift" "Windows and Screens/Window.swift") -target_sources(SwiftWin32 PRIVATE - CG/AffineTransform.swift - CG/Point.swift - CG/Rect.swift - CG/Size.swift - CG/Vector.swift) target_sources(SwiftWin32 PRIVATE Platform/BatteryMonitor.swift Platform/Error.swift @@ -164,11 +158,26 @@ target_sources(SwiftWin32 PRIVATE if(CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.7.0) target_sources(SwiftWin32 PRIVATE CoreAnimation/Transform3D.swift) + target_sources(SwiftWin32 PRIVATE + CoreGraphics/AffineTransform.swift + CoreGraphics/Point.swift + CoreGraphics/Rect.swift + CoreGraphics/Size.swift + CoreGraphics/Vector.swift) else() add_library(CoreAnimation STATIC CoreAnimation/Transform3D.swift) target_link_libraries(SwiftWin32 PRIVATE CoreAnimation) + + add_library(CoreGraphics STATIC + CoreGraphics/AffineTransform.swift + CoreGraphics/Point.swift + CoreGraphics/Rect.swift + CoreGraphics/Size.swift + CoreGraphics/Vector.swift) + target_link_libraries(SwiftWin32 PRIVATE + CoreGraphics) endif() target_link_libraries(SwiftWin32 PUBLIC ComCtl32 @@ -188,5 +197,6 @@ set_target_properties(SwiftWin32 PROPERTIES if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.7.0) _install_target(CoreAnimation) + _install_target(CoreGraphics) endif() _install_target(SwiftWin32) diff --git a/Sources/SwiftWin32/CG/AffineTransform.swift b/Sources/SwiftWin32/CoreGraphics/AffineTransform.swift similarity index 100% rename from Sources/SwiftWin32/CG/AffineTransform.swift rename to Sources/SwiftWin32/CoreGraphics/AffineTransform.swift diff --git a/Sources/SwiftWin32/CG/Point.swift b/Sources/SwiftWin32/CoreGraphics/Point.swift similarity index 100% rename from Sources/SwiftWin32/CG/Point.swift rename to Sources/SwiftWin32/CoreGraphics/Point.swift diff --git a/Sources/SwiftWin32/CG/Rect.swift b/Sources/SwiftWin32/CoreGraphics/Rect.swift similarity index 95% rename from Sources/SwiftWin32/CG/Rect.swift rename to Sources/SwiftWin32/CoreGraphics/Rect.swift index 4c291b06..225c3ade 100644 --- a/Sources/SwiftWin32/CG/Rect.swift +++ b/Sources/SwiftWin32/CoreGraphics/Rect.swift @@ -275,17 +275,3 @@ extension Rect: CustomDebugStringConvertible { return "Rect(origin: \(origin), size: \(size))" } } - -extension Rect { - internal func scaled(for dpi: UINT, style: WindowStyle) -> Rect { - let scale: Double = Double(dpi) / Double(USER_DEFAULT_SCREEN_DPI) - - var r: RECT = - RECT(from: self.applying(AffineTransform(scaleX: scale, y: scale))) - if !AdjustWindowRectExForDpi(&r, style.base, false, style.extended, dpi) { - log.warning("AdjustWindowRectExForDpi: \(Error(win32: GetLastError()))") - } - - return Rect(from: r) - } -} diff --git a/Sources/SwiftWin32/CG/Size.swift b/Sources/SwiftWin32/CoreGraphics/Size.swift similarity index 100% rename from Sources/SwiftWin32/CG/Size.swift rename to Sources/SwiftWin32/CoreGraphics/Size.swift diff --git a/Sources/SwiftWin32/CG/Vector.swift b/Sources/SwiftWin32/CoreGraphics/Vector.swift similarity index 100% rename from Sources/SwiftWin32/CG/Vector.swift rename to Sources/SwiftWin32/CoreGraphics/Vector.swift diff --git a/Sources/SwiftWin32/Focus-Based Navigation/FocusItem.swift b/Sources/SwiftWin32/Focus-Based Navigation/FocusItem.swift index 0ff1de3a..362cef67 100644 --- a/Sources/SwiftWin32/Focus-Based Navigation/FocusItem.swift +++ b/Sources/SwiftWin32/Focus-Based Navigation/FocusItem.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// An object that can become focused. public protocol FocusItem: FocusEnvironment { // MARK - Determining Focusability diff --git a/Sources/SwiftWin32/Focus-Based Navigation/FocusItemContainer.swift b/Sources/SwiftWin32/Focus-Based Navigation/FocusItemContainer.swift index 9d5fe7ad..1d8a025c 100644 --- a/Sources/SwiftWin32/Focus-Based Navigation/FocusItemContainer.swift +++ b/Sources/SwiftWin32/Focus-Based Navigation/FocusItemContainer.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// The container responsible for providing geometric context to focus items /// within a given focus environment. public protocol FocusItemContainer { diff --git a/Sources/SwiftWin32/Focus-Based Navigation/FocusMovementHint.swift b/Sources/SwiftWin32/Focus-Based Navigation/FocusMovementHint.swift index e591df8b..b3c43dee 100644 --- a/Sources/SwiftWin32/Focus-Based Navigation/FocusMovementHint.swift +++ b/Sources/SwiftWin32/Focus-Based Navigation/FocusMovementHint.swift @@ -3,6 +3,7 @@ #if swift(>=5.7) import CoreAnimation +import CoreGraphics #endif /// Provides movement hint information for the focused item. diff --git a/Sources/SwiftWin32/Images and PDF/Image.swift b/Sources/SwiftWin32/Images and PDF/Image.swift index 6467d6d2..d5945651 100644 --- a/Sources/SwiftWin32/Images and PDF/Image.swift +++ b/Sources/SwiftWin32/Images and PDF/Image.swift @@ -4,6 +4,10 @@ import WinSDK import SwiftCOM +#if swift(>=5.7) +import CoreGraphics +#endif + private let WICImagingFactory: SwiftCOM.IWICImagingFactory? = try? IWICImagingFactory.CreateInstance(class: CLSID_WICImagingFactory) diff --git a/Sources/SwiftWin32/Menus and Shortcuts/ContextMenuInteraction.swift b/Sources/SwiftWin32/Menus and Shortcuts/ContextMenuInteraction.swift index 17ebc78e..3c5c8aae 100644 --- a/Sources/SwiftWin32/Menus and Shortcuts/ContextMenuInteraction.swift +++ b/Sources/SwiftWin32/Menus and Shortcuts/ContextMenuInteraction.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + extension ContextMenuInteraction { /// Constants that describe the appearance of the menu. public enum Appearance: Int { diff --git a/Sources/SwiftWin32/Menus and Shortcuts/ContextMenuInteractionDelegate.swift b/Sources/SwiftWin32/Menus and Shortcuts/ContextMenuInteractionDelegate.swift index 6852bbad..b156d8fc 100644 --- a/Sources/SwiftWin32/Menus and Shortcuts/ContextMenuInteractionDelegate.swift +++ b/Sources/SwiftWin32/Menus and Shortcuts/ContextMenuInteractionDelegate.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// The methods for providing the set of actions to perform on your content, /// and for customizing the preview of that content. public protocol ContextMenuInteractionDelegate: AnyObject { diff --git a/Sources/SwiftWin32/Menus and Shortcuts/PreviewTarget.swift b/Sources/SwiftWin32/Menus and Shortcuts/PreviewTarget.swift index 6ef3a8b8..fcb7240a 100644 --- a/Sources/SwiftWin32/Menus and Shortcuts/PreviewTarget.swift +++ b/Sources/SwiftWin32/Menus and Shortcuts/PreviewTarget.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// An object that specifies the container view to use for animations. public class PreviewTarget { /// Creating a Preview Target Object diff --git a/Sources/SwiftWin32/Menus and Shortcuts/TargetedPreview.swift b/Sources/SwiftWin32/Menus and Shortcuts/TargetedPreview.swift index 09aa1c9b..7e7d891c 100644 --- a/Sources/SwiftWin32/Menus and Shortcuts/TargetedPreview.swift +++ b/Sources/SwiftWin32/Menus and Shortcuts/TargetedPreview.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + public class TargetedPreview { /// Creting a Targeted Preview Object diff --git a/Sources/SwiftWin32/Pointer Interactions/PointerRegion.swift b/Sources/SwiftWin32/Pointer Interactions/PointerRegion.swift index a5025d7c..29c3745f 100644 --- a/Sources/SwiftWin32/Pointer Interactions/PointerRegion.swift +++ b/Sources/SwiftWin32/Pointer Interactions/PointerRegion.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + public class PointerRegion { // MARK - Configuring a Region diff --git a/Sources/SwiftWin32/Pointer Interactions/PointerRegionRequest.swift b/Sources/SwiftWin32/Pointer Interactions/PointerRegionRequest.swift index a45d76b7..1d074201 100644 --- a/Sources/SwiftWin32/Pointer Interactions/PointerRegionRequest.swift +++ b/Sources/SwiftWin32/Pointer Interactions/PointerRegionRequest.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// An object to describe the pointer's location in the interaction's view. public class PointerRegionRequest { // MARK - Inspecting the Region Request diff --git a/Sources/SwiftWin32/Pointer Interactions/PointerStyle.swift b/Sources/SwiftWin32/Pointer Interactions/PointerStyle.swift index f731bda2..905a17d2 100644 --- a/Sources/SwiftWin32/Pointer Interactions/PointerStyle.swift +++ b/Sources/SwiftWin32/Pointer Interactions/PointerStyle.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + extension PointerEffect { /// An effect that defines how to apply a tint to a view during a pointer /// interaction. diff --git a/Sources/SwiftWin32/Support/Point+UIExtensions.swift b/Sources/SwiftWin32/Support/Point+UIExtensions.swift index 634b042e..ae62b169 100644 --- a/Sources/SwiftWin32/Support/Point+UIExtensions.swift +++ b/Sources/SwiftWin32/Support/Point+UIExtensions.swift @@ -2,6 +2,9 @@ // SPDX-License-Identifier: BSD-3-Clause import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif extension Point { internal init(from: POINT) { diff --git a/Sources/SwiftWin32/Support/Rect+UIExtensions.swift b/Sources/SwiftWin32/Support/Rect+UIExtensions.swift index 86127868..d3e9d38a 100644 --- a/Sources/SwiftWin32/Support/Rect+UIExtensions.swift +++ b/Sources/SwiftWin32/Support/Rect+UIExtensions.swift @@ -2,12 +2,15 @@ // SPDX-License-Identifier: BSD-3-Clause import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif extension Rect { internal init(from: RECT) { - self.origin = Point(x: from.left, y: from.top) - self.size = Size(width: from.right - from.left, - height: from.bottom - from.top) + self.init(origin: Point(x: from.left, y: from.top), + size: Size(width: from.right - from.left, + height: from.bottom - from.top)) } } @@ -25,3 +28,17 @@ extension Rect { Point(x: self.midX, y: self.midY) } } + +extension Rect { + internal func scaled(for dpi: UINT, style: WindowStyle) -> Rect { + let scale: Double = Double(dpi) / Double(USER_DEFAULT_SCREEN_DPI) + + var r: RECT = + RECT(from: self.applying(AffineTransform(scaleX: scale, y: scale))) + if !AdjustWindowRectExForDpi(&r, style.base, false, style.extended, dpi) { + log.warning("AdjustWindowRectExForDpi: \(Error(win32: GetLastError()))") + } + + return Rect(from: r) + } +} diff --git a/Sources/SwiftWin32/Support/Size+UIExtensions.swift b/Sources/SwiftWin32/Support/Size+UIExtensions.swift index df0b40a3..3e42af38 100644 --- a/Sources/SwiftWin32/Support/Size+UIExtensions.swift +++ b/Sources/SwiftWin32/Support/Size+UIExtensions.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + extension Size { internal init(width: Integer, height: Integer) { self.init(width: Int(width), height: Int(height)) diff --git a/Sources/SwiftWin32/Support/WinSDK+Extensions.swift b/Sources/SwiftWin32/Support/WinSDK+Extensions.swift index 6b496fdc..76bf3e8f 100644 --- a/Sources/SwiftWin32/Support/WinSDK+Extensions.swift +++ b/Sources/SwiftWin32/Support/WinSDK+Extensions.swift @@ -157,6 +157,16 @@ internal var WS_CAPTION: DWORD { DWORD(WinSDK.WS_CAPTION) } +@_transparent +internal var WS_CHILD: DWORD { + DWORD(WinSDK.WS_CHILD) +} + +@_transparent +internal var WS_CLIPSIBLINGS: DWORD { + DWORD(WinSDK.WS_CLIPSIBLINGS) +} + @_transparent internal var WS_HSCROLL: DWORD { DWORD(WinSDK.WS_HSCROLL) @@ -167,6 +177,11 @@ internal var WS_TABSTOP: DWORD { DWORD(WinSDK.WS_TABSTOP) } +@_transparent +internal var WS_VISIBLE: DWORD { + DWORD(WinSDK.WS_VISIBLE) +} + @_transparent internal var WS_VSCROLL: DWORD { DWORD(WinSDK.WS_VSCROLL) diff --git a/Sources/SwiftWin32/Text Display and Fonts/FontDescriptor.swift b/Sources/SwiftWin32/Text Display and Fonts/FontDescriptor.swift index 58327866..7fedfebc 100644 --- a/Sources/SwiftWin32/Text Display and Fonts/FontDescriptor.swift +++ b/Sources/SwiftWin32/Text Display and Fonts/FontDescriptor.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// A collection of attributes that describes a font. public class FontDescriptor { /// Constants that classify certain stylistic qualities of the font. diff --git a/Sources/SwiftWin32/Touches, Presses, and Gestures/GestureRecognizer.swift b/Sources/SwiftWin32/Touches, Presses, and Gestures/GestureRecognizer.swift index 4cfbbc2b..cc63ea4c 100644 --- a/Sources/SwiftWin32/Touches, Presses, and Gestures/GestureRecognizer.swift +++ b/Sources/SwiftWin32/Touches, Presses, and Gestures/GestureRecognizer.swift @@ -1,6 +1,10 @@ // Copyright © 2021 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + // Class constrain the callable to ensure that the value is heap allocated, // permitting us to perform pointer equality for the callback to serve as // identity. Using COW, we can perform pointer equality on the types as a diff --git a/Sources/SwiftWin32/UI/SceneSizeRestrictions.swift b/Sources/SwiftWin32/UI/SceneSizeRestrictions.swift index 6f49172d..56c23d1a 100644 --- a/Sources/SwiftWin32/UI/SceneSizeRestrictions.swift +++ b/Sources/SwiftWin32/UI/SceneSizeRestrictions.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + public class SceneSizeRestrictions { /// Setting the Size Restrictions diff --git a/Sources/SwiftWin32/View Controllers/ContentContainer.swift b/Sources/SwiftWin32/View Controllers/ContentContainer.swift index c7c56718..0cfe8ceb 100644 --- a/Sources/SwiftWin32/View Controllers/ContentContainer.swift +++ b/Sources/SwiftWin32/View Controllers/ContentContainer.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// A set of methods for adapting the contents of your view controllers to size /// and trait changes. public protocol ContentContainer { diff --git a/Sources/SwiftWin32/View Controllers/PresentationController.swift b/Sources/SwiftWin32/View Controllers/PresentationController.swift index f913af4c..637f29be 100644 --- a/Sources/SwiftWin32/View Controllers/PresentationController.swift +++ b/Sources/SwiftWin32/View Controllers/PresentationController.swift @@ -1,6 +1,10 @@ // Copyright © 2021 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// An object that manages the transition animations and the presentation of /// view controllers onscreen. open class PresentationController { diff --git a/Sources/SwiftWin32/View Controllers/ViewController.swift b/Sources/SwiftWin32/View Controllers/ViewController.swift index 7c392a04..9029c43d 100644 --- a/Sources/SwiftWin32/View Controllers/ViewController.swift +++ b/Sources/SwiftWin32/View Controllers/ViewController.swift @@ -6,6 +6,10 @@ import class Foundation.NSNotification import struct Foundation.NSExceptionName import struct Foundation.TimeInterval +#if swift(>=5.7) +import CoreGraphics +#endif + /// Transition styles available when presenting view controllers. public enum ModalTransitionStyle: Int { /// diff --git a/Sources/SwiftWin32/Views and Controls/Button.swift b/Sources/SwiftWin32/Views and Controls/Button.swift index 33f92d7e..5df87dc0 100644 --- a/Sources/SwiftWin32/Views and Controls/Button.swift +++ b/Sources/SwiftWin32/Views and Controls/Button.swift @@ -3,6 +3,10 @@ import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif + private let SwiftButtonProc: SUBCLASSPROC = { (hWnd, uMsg, wParam, lParam, uIdSubclass, dwRefData) in let button: Button? = unsafeBitCast(dwRefData, to: AnyObject.self) as? Button diff --git a/Sources/SwiftWin32/Views and Controls/DatePicker.swift b/Sources/SwiftWin32/Views and Controls/DatePicker.swift index 3336ff13..aa0d1da3 100644 --- a/Sources/SwiftWin32/Views and Controls/DatePicker.swift +++ b/Sources/SwiftWin32/Views and Controls/DatePicker.swift @@ -5,6 +5,10 @@ import WinSDK import struct Foundation.Date +#if swift(>=5.7) +import CoreGraphics +#endif + private let SwiftDatePickerProc: SUBCLASSPROC = { (hWnd, uMsg, wParam, lParam, uIdSubclass, dwRefData) in let datepicker: DatePicker? = unsafeBitCast(dwRefData, to: AnyObject.self) as? DatePicker diff --git a/Sources/SwiftWin32/Views and Controls/ImageView.swift b/Sources/SwiftWin32/Views and Controls/ImageView.swift index f4e29b5d..2bc1c999 100644 --- a/Sources/SwiftWin32/Views and Controls/ImageView.swift +++ b/Sources/SwiftWin32/Views and Controls/ImageView.swift @@ -4,6 +4,10 @@ import WinSDK import SwiftCOM +#if swift(>=5.7) +import CoreGraphics +#endif + extension BitmapHandle { internal convenience init?(from pBitmap: SwiftCOM.IWICBitmapSource?, hWnd: HWND? = nil) { diff --git a/Sources/SwiftWin32/Views and Controls/Label.swift b/Sources/SwiftWin32/Views and Controls/Label.swift index 40890493..1382aa1c 100644 --- a/Sources/SwiftWin32/Views and Controls/Label.swift +++ b/Sources/SwiftWin32/Views and Controls/Label.swift @@ -3,6 +3,10 @@ import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif + private let SwiftLabelProc: SUBCLASSPROC = { (hWnd, uMsg, wParam, lParam, uIdSubclass, dwRefData) in let label: Label? = unsafeBitCast(dwRefData, to: AnyObject.self) as? Label diff --git a/Sources/SwiftWin32/Views and Controls/PickerView.swift b/Sources/SwiftWin32/Views and Controls/PickerView.swift index 8fc1e6ac..9279dcec 100644 --- a/Sources/SwiftWin32/Views and Controls/PickerView.swift +++ b/Sources/SwiftWin32/Views and Controls/PickerView.swift @@ -6,6 +6,10 @@ import WinSDK import struct Foundation.IndexPath import class Foundation.NSAttributedString +#if swift(>=5.7) +import CoreGraphics +#endif + // Notification Proxy // When the Window is created, the initial parent is cached. This cache cannot @@ -383,7 +387,7 @@ public class PickerView: View { _ = SetParent(view.hWnd, cbiInfo.hwndList) view.GWL_STYLE &= ~LONG(bitPattern: WS_POPUP | WS_CAPTION) - view.GWL_STYLE |= WS_CHILD + view.GWL_STYLE |= LONG(WS_CHILD) // FIXME(compnerd) can this be avoided somehow? if view is TextField || view is TextView || view is TableView { view.GWL_STYLE |= WinSDK.WS_BORDER diff --git a/Sources/SwiftWin32/Views and Controls/ProgressView.swift b/Sources/SwiftWin32/Views and Controls/ProgressView.swift index 67c8d218..cc59217d 100644 --- a/Sources/SwiftWin32/Views and Controls/ProgressView.swift +++ b/Sources/SwiftWin32/Views and Controls/ProgressView.swift @@ -3,6 +3,10 @@ import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif + public class ProgressView: Control { private static let `class`: WindowClass = WindowClass(named: PROGRESS_CLASS) private static let style: WindowStyle = (base: WS_POPUP, extended: 0) diff --git a/Sources/SwiftWin32/Views and Controls/Slider.swift b/Sources/SwiftWin32/Views and Controls/Slider.swift index 875621f7..5c68d0b9 100644 --- a/Sources/SwiftWin32/Views and Controls/Slider.swift +++ b/Sources/SwiftWin32/Views and Controls/Slider.swift @@ -3,6 +3,10 @@ import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif + /// A control for selecting a single value from a continuous range of values. public class Slider: Control { private static let `class`: WindowClass = WindowClass(named: TRACKBAR_CLASS) diff --git a/Sources/SwiftWin32/Views and Controls/Stepper.swift b/Sources/SwiftWin32/Views and Controls/Stepper.swift index 88d5b588..85ffeb5a 100644 --- a/Sources/SwiftWin32/Views and Controls/Stepper.swift +++ b/Sources/SwiftWin32/Views and Controls/Stepper.swift @@ -3,6 +3,10 @@ import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif + // Notification Proxy // When the Window is created, the initial parent is cached. This cache cannot diff --git a/Sources/SwiftWin32/Views and Controls/Switch.swift b/Sources/SwiftWin32/Views and Controls/Switch.swift index edc9d574..581a6620 100644 --- a/Sources/SwiftWin32/Views and Controls/Switch.swift +++ b/Sources/SwiftWin32/Views and Controls/Switch.swift @@ -3,6 +3,10 @@ import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif + /// A control that offers a binary choice, such as on/off. public class Switch: Control { private static let `class`: WindowClass = WindowClass(named: WC_BUTTON) diff --git a/Sources/SwiftWin32/Views and Controls/Table Views/TableView.swift b/Sources/SwiftWin32/Views and Controls/Table Views/TableView.swift index 8a471c08..62cff00f 100644 --- a/Sources/SwiftWin32/Views and Controls/Table Views/TableView.swift +++ b/Sources/SwiftWin32/Views and Controls/Table Views/TableView.swift @@ -4,6 +4,10 @@ import WinSDK import struct Foundation.IndexPath +#if swift(>=5.7) +import CoreGraphics +#endif + // Notification Proxy // When the Window is created, the initial parent is cached. This cache cannot diff --git a/Sources/SwiftWin32/Views and Controls/Table Views/TableViewCell.swift b/Sources/SwiftWin32/Views and Controls/Table Views/TableViewCell.swift index 54927331..38138e62 100644 --- a/Sources/SwiftWin32/Views and Controls/Table Views/TableViewCell.swift +++ b/Sources/SwiftWin32/Views and Controls/Table Views/TableViewCell.swift @@ -3,6 +3,10 @@ import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif + extension TableViewCell { public enum CellStyle: Int { /// A simple style for a cell with a text label (black and left-aligned) and diff --git a/Sources/SwiftWin32/Views and Controls/Table Views/TableViewDelegate.swift b/Sources/SwiftWin32/Views and Controls/Table Views/TableViewDelegate.swift index 3c4a8a53..288acc10 100644 --- a/Sources/SwiftWin32/Views and Controls/Table Views/TableViewDelegate.swift +++ b/Sources/SwiftWin32/Views and Controls/Table Views/TableViewDelegate.swift @@ -3,6 +3,10 @@ import struct Foundation.IndexPath +#if swift(>=5.7) +import CoreGraphics +#endif + /// Methods for managing selections, configuring section headers and footers, /// deleting and reordering cells, and performing other actions in a table view. public protocol TableViewDelegate: AnyObject { diff --git a/Sources/SwiftWin32/Views and Controls/Table Views/TableViewHeaderFooterView.swift b/Sources/SwiftWin32/Views and Controls/Table Views/TableViewHeaderFooterView.swift index bc5ed5d2..c5004e5c 100644 --- a/Sources/SwiftWin32/Views and Controls/Table Views/TableViewHeaderFooterView.swift +++ b/Sources/SwiftWin32/Views and Controls/Table Views/TableViewHeaderFooterView.swift @@ -1,7 +1,11 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause - import WinSDK +import WinSDK + +#if swift(>=5.7) +import CoreGraphics +#endif /// A reusable view that you place at the top or bottom of a table section to /// display additional information for that section. diff --git a/Sources/SwiftWin32/Views and Controls/TextField.swift b/Sources/SwiftWin32/Views and Controls/TextField.swift index ebdfa31b..e17dd14d 100644 --- a/Sources/SwiftWin32/Views and Controls/TextField.swift +++ b/Sources/SwiftWin32/Views and Controls/TextField.swift @@ -3,6 +3,10 @@ import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif + public protocol TextFieldDelegate: AnyObject { } diff --git a/Sources/SwiftWin32/Views and Controls/TextView.swift b/Sources/SwiftWin32/Views and Controls/TextView.swift index f682a84b..96e73d78 100644 --- a/Sources/SwiftWin32/Views and Controls/TextView.swift +++ b/Sources/SwiftWin32/Views and Controls/TextView.swift @@ -4,6 +4,10 @@ import WinSDK import Foundation +#if swift(>=5.7) +import CoreGraphics +#endif + // FIXME(compnerd) we would like this to derive from ScrollView public class TextView: View { private static let `class`: WindowClass = WindowClass(named: MSFTEDIT_CLASS) diff --git a/Sources/SwiftWin32/Views and Controls/View.swift b/Sources/SwiftWin32/Views and Controls/View.swift index 41c75daa..b5514567 100644 --- a/Sources/SwiftWin32/Views and Controls/View.swift +++ b/Sources/SwiftWin32/Views and Controls/View.swift @@ -3,6 +3,10 @@ import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif + extension View { internal func interaction() -> InteractionType? { // TODO: how do we handle overlapping entries in the `interactions` array? @@ -644,7 +648,7 @@ public class View: Responder { // Update the Window style. self.GWL_STYLE &= ~LONG(bitPattern: WS_POPUP | WS_CAPTION) - self.GWL_STYLE &= ~WS_CHILD + self.GWL_STYLE &= ~LONG(WS_CHILD) // FIXME(compnerd) can this be avoided somehow? if self is TextField || self is TextView || self is TableView { self.GWL_STYLE |= WinSDK.WS_BORDER @@ -696,7 +700,7 @@ public class View: Responder { // Update the window style. view.GWL_STYLE &= ~LONG(bitPattern: WS_POPUP | WS_CAPTION) - view.GWL_STYLE |= WS_CHILD + view.GWL_STYLE |= LONG(WS_CHILD) // FIXME(compnerd) can this be avoided somehow? if view is TextField || view is TextView || view is TableView { view.GWL_STYLE |= WinSDK.WS_BORDER diff --git a/Sources/SwiftWin32/Windows and Screens/CoordinateSpace.swift b/Sources/SwiftWin32/Windows and Screens/CoordinateSpace.swift index e60133c4..044a24ac 100644 --- a/Sources/SwiftWin32/Windows and Screens/CoordinateSpace.swift +++ b/Sources/SwiftWin32/Windows and Screens/CoordinateSpace.swift @@ -1,6 +1,10 @@ // Copyright © 2020 Saleem Abdulrasool // SPDX-License-Identifier: BSD-3-Clause +#if swift(>=5.7) +import CoreGraphics +#endif + /// A set of methods for converting between different frames of reference on a /// screen. public protocol CoordinateSpace { diff --git a/Sources/SwiftWin32/Windows and Screens/Screen.swift b/Sources/SwiftWin32/Windows and Screens/Screen.swift index f2015b8c..c83a7266 100644 --- a/Sources/SwiftWin32/Windows and Screens/Screen.swift +++ b/Sources/SwiftWin32/Windows and Screens/Screen.swift @@ -3,6 +3,10 @@ import WinSDK +#if swift(>=5.7) +import CoreGraphics +#endif + extension DEVICE_SCALE_FACTOR { internal var factor: Double { switch self { diff --git a/Sources/SwiftWin32/Windows and Screens/Window.swift b/Sources/SwiftWin32/Windows and Screens/Window.swift index 8a297435..7ea06135 100644 --- a/Sources/SwiftWin32/Windows and Screens/Window.swift +++ b/Sources/SwiftWin32/Windows and Screens/Window.swift @@ -5,6 +5,10 @@ import WinSDK import class Foundation.NSNotification import class Foundation.NotificationCenter +#if swift(>=5.7) +import CoreGraphics +#endif + private let SwiftWindowProc: SUBCLASSPROC = { (hWnd, uMsg, wParam, lParam, uIdSubclass, dwRefData) in let window: Window? = unsafeBitCast(dwRefData, to: AnyObject.self) as? Window diff --git a/Tests/CoreGraphicsTests/CoreGraphicsTests.swift b/Tests/CoreGraphicsTests/CoreGraphicsTests.swift index 13de2a94..a8dc37ab 100644 --- a/Tests/CoreGraphicsTests/CoreGraphicsTests.swift +++ b/Tests/CoreGraphicsTests/CoreGraphicsTests.swift @@ -3,9 +3,11 @@ import XCTest +#if swift(>=5.7) +import CoreGraphics +#else import SwiftWin32 - -private typealias AffineTransform = SwiftWin32.AffineTransform +#endif final class CoreGraphicsTests: XCTestCase { func testAffineTransformIdentity() {