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
4 changes: 2 additions & 2 deletions Sources/SwiftWin32/App and Environment/ApplicationMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ public func ApplicationMain(_ argc: Int32,
// to execute, we wait until a new message is placed in the thread's message
// queue or the timer must fire, otherwise we proceed to the next iteration
// of mainLoop, using 0 as the wait timeout.
_ = WaitMessage(DWORD(exactly: limitDate?.timeIntervalSinceNow ?? 0 * 1000)
?? DWORD.max)
_ = WaitMessage(UINT(exactly: limitDate?.timeIntervalSinceNow ?? 0 * 1000)
?? UINT.max)
}

Application.shared.delegate?.applicationWillTerminate(Application.shared)
Expand Down
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 @@ -25,7 +25,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 @@ -38,8 +38,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 @@ -117,8 +117,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 @@ -133,10 +133,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 @@ -54,7 +54,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 @@ -75,10 +75,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 @@ -137,7 +137,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 @@ -25,8 +25,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
4 changes: 2 additions & 2 deletions Sources/SwiftWin32/Views and Controls/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public class TextView: View {
// Disable compatibility with the original Rich Edit and use the extended
// text limit.
_ = SendMessageW(self.hWnd, UINT(EM_EXLIMITTEXT),
WPARAM(0), LPARAM(bitPattern: UInt64(bitPattern: -1)))
WPARAM(0), LPARAM(UInt(bitPattern: -1)))
}

public func scrollRangeToVisible(_ range: NSRange) {
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)
}

Expand Down