Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions Sources/SwiftWin32/Support/WinSDK+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@

import WinSDK

#if arch(i386) || arch(arm)
@_transparent
internal func GetWindowLongPtrW(_ hWnd: HWND, _ nIndex: CInt) -> LONG {
return GetWindowLongW(hWnd, nIndex)
}

@_transparent
internal func SetWindowLongPtrW(_ hWnd: HWND, _ nIndex: CInt, _ dwNewLong: LONG) -> LONG {
return SetWindowLongW(hWnd, nIndex, dwNewLong)
}
#endif

internal let IDC_ARROW: UnsafePointer<WCHAR> =
UnsafePointer<WCHAR>(bitPattern: 32512)!

Expand All @@ -11,52 +23,52 @@ internal let IDC_ARROW: UnsafePointer<WCHAR> =
// winreg.h
@_transparent
internal var HKEY_CLASSES_ROOT: HKEY? {
HKEY(bitPattern: 0x80000000)
HKEY(bitPattern: UInt(0x80000000))
}

@_transparent
internal var HKEY_CURRENT_USER: HKEY? {
HKEY(bitPattern: 0x80000001)
HKEY(bitPattern: UInt(0x80000001))
}

@_transparent
internal var HKEY_LOCAL_MACHINE: HKEY? {
HKEY(bitPattern: 0x80000002)
HKEY(bitPattern: UInt(0x80000002))
}

@_transparent
internal var HKEY_USERS: HKEY? {
HKEY(bitPattern: 0x80000003)
HKEY(bitPattern: UInt(0x80000003))
}

@_transparent
internal var HKEY_PERFORMANCE_DATA: HKEY? {
HKEY(bitPattern: 0x80000004)
HKEY(bitPattern: UInt(0x80000004))
}

@_transparent
internal var HKEY_PERFORMANCE_TEXT: HKEY? {
HKEY(bitPattern: 0x80000050)
HKEY(bitPattern: UInt(0x80000050))
}

@_transparent
internal var HKEY_PERFORMANCE_NLSTEXT: HKEY? {
HKEY(bitPattern: 0x80000060)
HKEY(bitPattern: UInt(0x80000060))
}

@_transparent
internal var HKEY_CURRENT_CONFIG: HKEY? {
HKEY(bitPattern: 0x80000005)
HKEY(bitPattern: UInt(0x80000005))
}

@_transparent
internal var HKEY_DYN_DATA: HKEY? {
HKEY(bitPattern: 0x80000006)
HKEY(bitPattern: UInt(0x80000006))
}

@_transparent
internal var HKEY_CURRENT_USER_LOCAL_SETTINGS: HKEY? {
HKEY(bitPattern: 0x80000007)
HKEY(bitPattern: UInt(0x80000007))
}

#endif
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftWin32/Text Display and Fonts/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public class Font {
log.error("GetObjectW: \(Error(win32: GetLastError()))")
return self
}
lfFont.lfHeight = PointToLogical(fontSize)
lfFont.lfHeight = LONG(PointToLogical(fontSize))

return Font(owning: CreateFontIndirectW(&lfFont))
}
Expand Down Expand Up @@ -407,7 +407,7 @@ public class Font {
return 0.0
}

return LogicalToPoint(lfFont.lfHeight)
return LogicalToPoint(Int32(lfFont.lfHeight))
}

/// The top y-coordinate, offset from the baseline, of the font's longest
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftWin32/Views and Controls/Control.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,27 +262,27 @@ extension Control.Event {

/// All touch events.
public static var allTouchEvents: Control.Event {
Control.Event(rawValue: 0x00000fff)
Control.Event(rawValue: RawValue(bitPattern: 0x00000fff))
}

/// All editing touches for `TextField` objects.
public static var allEditingEvents: Control.Event {
Control.Event(rawValue: 0x000f0000)
Control.Event(rawValue: RawValue(bitPattern: 0x000f0000))
}

/// A range of control-event values available for application use.
public static var applicationReserved: Control.Event {
Control.Event(rawValue: 0x0f000000)
Control.Event(rawValue: RawValue(bitPattern: 0x0f000000))
}

/// A range of control-event values reserved for internal framework use.
public static var systemReserved: Control.Event {
Control.Event(rawValue: 0xf0000000)
Control.Event(rawValue: RawValue(bitPattern: 0xf0000000))
}

/// All events, including system events.
public static var allEvents: Control.Event {
Control.Event(rawValue: 0xffffffff)
Control.Event(rawValue: RawValue(bitPattern: 0xffffffff))
}
}

Expand Down
18 changes: 9 additions & 9 deletions Sources/SwiftWin32/Views and Controls/PickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private let SwiftPickerViewProxyWindowProc: WNDPROC = { (hWnd, uMsg, wParam, lPa
switch lpDrawItem.pointee.itemAction {
case UINT(ODA_SELECT):
_ = DrawFocusRect(lpDrawItem.pointee.hDC, &lpDrawItem.pointee.rcItem)
if lpDrawItem.pointee.itemState & DWORD(ODS_SELECTED) == DWORD(ODS_SELECTED) {
if DWORD(lpDrawItem.pointee.itemState) & DWORD(ODS_SELECTED) == DWORD(ODS_SELECTED) {
// If the item is selected, we have drawn the focus rectangle and the
// operation is complete.
return LRESULT(1)
Expand All @@ -42,8 +42,8 @@ private let SwiftPickerViewProxyWindowProc: WNDPROC = { (hWnd, uMsg, wParam, lPa
if let view = unsafeBitCast(lpDrawItem.pointee.itemData,
to: AnyObject.self) as? View {
let rctRect: RECT = lpDrawItem.pointee.rcItem
_ = SetWindowPos(view.hWnd, nil, rctRect.left, rctRect.top, 0, 0,
UINT(SWP_NOSIZE))
_ = SetWindowPos(view.hWnd, nil, CInt(rctRect.left), CInt(rctRect.top),
0, 0, UINT(SWP_NOSIZE))
// Setting `isHidden` is necessary for Views generated after initial
// call to `Window.makeKeyAndVisible()`
if IsWindowVisible(GetParent(view.hWnd)) && !IsWindowVisible(view.hWnd) {
Expand Down Expand Up @@ -121,8 +121,8 @@ private let SwiftPickerViewWindowProc: SUBCLASSPROC = { (hWnd, uMsg, wParam, lPa
DeviceContextHandle(owning: GetDC(view.hWnd))
let hBitmap: BitmapHandle =
BitmapHandle(owning: CreateCompatibleBitmap(hDCItem.value,
rcClient.right - rcClient.left,
rcClient.bottom - rcClient.top))
CInt(rcClient.right - rcClient.left),
CInt(rcClient.bottom - rcClient.top)))

let hDCMemory: DeviceContextHandle =
DeviceContextHandle(owning: CreateCompatibleDC(nil))
Expand All @@ -137,10 +137,10 @@ private let SwiftPickerViewWindowProc: SUBCLASSPROC = { (hWnd, uMsg, wParam, lPa
let hDC: DeviceContextHandle =
DeviceContextHandle(owning: GetDC(hWnd))

_ = BitBlt(hDC.value, cbiInfo.rcItem.left, cbiInfo.rcItem.top,
cbiInfo.rcItem.right - cbiInfo.rcItem.left,
cbiInfo.rcItem.bottom - cbiInfo.rcItem.top, hDCMemory.value,
0, 0, UINT(SRCCOPY))
_ = BitBlt(hDC.value, CInt(cbiInfo.rcItem.left), CInt(cbiInfo.rcItem.top),
CInt(cbiInfo.rcItem.right - cbiInfo.rcItem.left),
CInt(cbiInfo.rcItem.bottom - cbiInfo.rcItem.top),
hDCMemory.value, 0, 0, DWORD(SRCCOPY))

return lResult

Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftWin32/Views and Controls/Stepper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private class StepperProxy {
public class Stepper: Control {
private static let `class`: WindowClass = WindowClass(named: UPDOWN_CLASS)
private static let style: WindowStyle =
(base: UInt32(UDS_HORZ) | WS_POPUP | WS_TABSTOP, extended: 0)
(base: DWORD(UDS_HORZ) | WS_POPUP | WS_TABSTOP, extended: 0)

private static var proxy: StepperProxy = StepperProxy()

Expand All @@ -79,10 +79,10 @@ public class Stepper: Control {
/// A boolean value that determines whether the stepper can wrap its value to
/// the minimum or maximum value when incrementing and decrementing the value.
public var wraps: Bool {
get { self.GWL_STYLE & UDS_WRAP == UDS_WRAP }
get { self.GWL_STYLE & LONG(UDS_WRAP) == LONG(UDS_WRAP) }
set {
self.GWL_STYLE = newValue ? self.GWL_STYLE | UDS_WRAP
: self.GWL_STYLE & ~UDS_WRAP
self.GWL_STYLE = newValue ? self.GWL_STYLE | LONG(UDS_WRAP)
: self.GWL_STYLE & ~LONG(UDS_WRAP)
}
}

Expand Down Expand Up @@ -141,7 +141,7 @@ public class Stepper: Control {
SendMessageW(self.hWnd, UINT(UDM_GETACCEL),
WPARAM(1), LPARAM(UInt(bitPattern: $0)))
}
value.nInc = DWORD(newValue)
value.nInc = UINT(newValue)
_ = withUnsafeMutablePointer(to: &value) {
SendMessageW(self.hWnd, UINT(UDM_SETACCEL),
WPARAM(1), LPARAM(UInt(bitPattern: $0)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ private let SwiftTableViewProxyWindowProc: WNDPROC = { (hWnd, uMsg, wParam, lPar
if let view = unsafeBitCast(lpDrawItem.pointee.itemData,
to: AnyObject.self) as? View {
let rctRect: RECT = lpDrawItem.pointee.rcItem
_ = SetWindowPos(view.hWnd, nil, rctRect.left, rctRect.top, 0, 0,
UINT(SWP_NOSIZE))
_ = SetWindowPos(view.hWnd, nil, CInt(rctRect.left), CInt(rctRect.top),
0, 0, UINT(SWP_NOSIZE))

// Setting `isHidden` is necessary for TableCells generated after
// initial call to `Window.makeKeyAndVisible()`
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftWin32/Views and Controls/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#endif

// FIXME(compnerd) we would like this to derive from ScrollView
public class TextView: View {

Check warning on line 12 in Sources/SwiftWin32/Views and Controls/TextView.swift

View workflow job for this annotation

GitHub Actions / lint

[AllPublicDeclarationsHaveDocumentation] add a documentation comment for 'TextView'
private static let `class`: WindowClass = WindowClass(named: MSFTEDIT_CLASS)
private static let style: WindowStyle =
(base: WS_BORDER | WS_HSCROLL | WS_POPUP | WS_TABSTOP | WS_VSCROLL | DWORD(ES_MULTILINE),

Check warning on line 15 in Sources/SwiftWin32/Views and Controls/TextView.swift

View workflow job for this annotation

GitHub Actions / lint

[Indentation] unindent by 2 spaces

Check warning on line 15 in Sources/SwiftWin32/Views and Controls/TextView.swift

View workflow job for this annotation

GitHub Actions / lint

[LineLength] line is too long
extended: 0)

Check warning on line 16 in Sources/SwiftWin32/Views and Controls/TextView.swift

View workflow job for this annotation

GitHub Actions / lint

[AddLines] add 1 line break

Check warning on line 16 in Sources/SwiftWin32/Views and Controls/TextView.swift

View workflow job for this annotation

GitHub Actions / lint

[Indentation]

public var editable: Bool {

Check warning on line 18 in Sources/SwiftWin32/Views and Controls/TextView.swift

View workflow job for this annotation

GitHub Actions / lint

[AllPublicDeclarationsHaveDocumentation] add a documentation comment for 'editable'
get {
self.GWL_STYLE & ES_READONLY == ES_READONLY
}
Expand All @@ -29,10 +29,10 @@
set(value) { super.font = value }
}

@_Win32WindowText

Check warning on line 32 in Sources/SwiftWin32/Views and Controls/TextView.swift

View workflow job for this annotation

GitHub Actions / lint

[AllPublicDeclarationsHaveDocumentation] add a documentation comment for 'text'
public var text: String?

public init(frame: Rect) {

Check warning on line 35 in Sources/SwiftWin32/Views and Controls/TextView.swift

View workflow job for this annotation

GitHub Actions / lint

[AllPublicDeclarationsHaveDocumentation] add a documentation comment for 'init'
super.init(frame: frame, class: TextView.class, style: TextView.style)

// Remove the `WS_EX_CLIENTEDGE` which gives it a flat appearance
Expand All @@ -43,15 +43,15 @@
_ = SendMessageW(self.hWnd, UINT(EM_EXLIMITTEXT), WPARAM(0), LPARAM(-1))
}

public func scrollRangeToVisible(_ range: NSRange) {

Check warning on line 46 in Sources/SwiftWin32/Views and Controls/TextView.swift

View workflow job for this annotation

GitHub Actions / lint

[AllPublicDeclarationsHaveDocumentation] add a documentation comment for 'scrollRangeToVisible(_:)'
SendMessageW(hWnd, UINT(EM_SETSEL), WPARAM(range.location),
LPARAM(range.location + range.length))
SendMessageW(hWnd, UINT(EM_SETSEL), UInt64(bitPattern: -1), -1)
SendMessageW(hWnd, UINT(EM_SETSEL), WPARAM(bitPattern: -1), -1)
SendMessageW(hWnd, UINT(EM_SCROLLCARET), 0, 0)
}

// ContentSizeCategoryAdjusting
public var adjustsFontForContentSizeCategory = false

Check warning on line 54 in Sources/SwiftWin32/Views and Controls/TextView.swift

View workflow job for this annotation

GitHub Actions / lint

[AllPublicDeclarationsHaveDocumentation] add a documentation comment for 'adjustsFontForContentSizeCategory '

// TraitEnvironment
override public func traitCollectionDidChange(_ previousTraitCollection: TraitCollection?) {
Expand Down
Loading