Skip to content

Commit de95b9a

Browse files
committed
SwiftWin32: work towards 32-bit cleanliness
This corrects the type mismatches at a number of sites to make the code 32-bit clean. This is required to enable the use of Swift/Win32 on 32-bit Windows targets.
1 parent 9a6e5ad commit de95b9a

File tree

8 files changed

+42
-37
lines changed

8 files changed

+42
-37
lines changed

Sources/SwiftWin32/App and Environment/ApplicationMain.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ public func ApplicationMain(_ argc: Int32,
216216
// to execute, we wait until a new message is placed in the thread's message
217217
// queue or the timer must fire, otherwise we proceed to the next iteration
218218
// of mainLoop, using 0 as the wait timeout.
219-
_ = WaitMessage(DWORD(exactly: limitDate?.timeIntervalSinceNow ?? 0 * 1000)
220-
?? DWORD.max)
219+
_ = WaitMessage(UINT(exactly: limitDate?.timeIntervalSinceNow ?? 0 * 1000)
220+
?? UINT.max)
221221
}
222222

223223
Application.shared.delegate?.applicationWillTerminate(Application.shared)

Sources/SwiftWin32/Support/WinSDK+Extensions.swift

+15-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
import WinSDK
55

6+
#if arch(i386) || arch(arm)
7+
internal typealias GetWindowLongPtrW = GetWindowLongW
8+
internal typealias SetWindowLongPtrW = SetWindowLongW
9+
#endif
10+
611
internal let IDC_ARROW: UnsafePointer<WCHAR> =
712
UnsafePointer<WCHAR>(bitPattern: 32512)!
813

@@ -11,52 +16,52 @@ internal let IDC_ARROW: UnsafePointer<WCHAR> =
1116
// winreg.h
1217
@_transparent
1318
internal var HKEY_CLASSES_ROOT: HKEY? {
14-
HKEY(bitPattern: 0x80000000)
19+
HKEY(bitPattern: UInt(0x80000000))
1520
}
1621

1722
@_transparent
1823
internal var HKEY_CURRENT_USER: HKEY? {
19-
HKEY(bitPattern: 0x80000001)
24+
HKEY(bitPattern: UInt(0x80000001))
2025
}
2126

2227
@_transparent
2328
internal var HKEY_LOCAL_MACHINE: HKEY? {
24-
HKEY(bitPattern: 0x80000002)
29+
HKEY(bitPattern: UInt(0x80000002))
2530
}
2631

2732
@_transparent
2833
internal var HKEY_USERS: HKEY? {
29-
HKEY(bitPattern: 0x80000003)
34+
HKEY(bitPattern: UInt(0x80000003))
3035
}
3136

3237
@_transparent
3338
internal var HKEY_PERFORMANCE_DATA: HKEY? {
34-
HKEY(bitPattern: 0x80000004)
39+
HKEY(bitPattern: UInt(0x80000004))
3540
}
3641

3742
@_transparent
3843
internal var HKEY_PERFORMANCE_TEXT: HKEY? {
39-
HKEY(bitPattern: 0x80000050)
44+
HKEY(bitPattern: UInt(0x80000050))
4045
}
4146

4247
@_transparent
4348
internal var HKEY_PERFORMANCE_NLSTEXT: HKEY? {
44-
HKEY(bitPattern: 0x80000060)
49+
HKEY(bitPattern: UInt(0x80000060))
4550
}
4651

4752
@_transparent
4853
internal var HKEY_CURRENT_CONFIG: HKEY? {
49-
HKEY(bitPattern: 0x80000005)
54+
HKEY(bitPattern: UInt(0x80000005))
5055
}
5156

5257
@_transparent
5358
internal var HKEY_DYN_DATA: HKEY? {
54-
HKEY(bitPattern: 0x80000006)
59+
HKEY(bitPattern: UInt(0x80000006))
5560
}
5661

5762
@_transparent
5863
internal var HKEY_CURRENT_USER_LOCAL_SETTINGS: HKEY? {
59-
HKEY(bitPattern: 0x80000007)
64+
HKEY(bitPattern: UInt(0x80000007))
6065
}
6166

6267
#endif

Sources/SwiftWin32/Text Display and Fonts/Font.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public class Font {
231231
log.error("GetObjectW: \(Error(win32: GetLastError()))")
232232
return self
233233
}
234-
lfFont.lfHeight = PointToLogical(fontSize)
234+
lfFont.lfHeight = LONG(PointToLogical(fontSize))
235235

236236
return Font(owning: CreateFontIndirectW(&lfFont))
237237
}
@@ -407,7 +407,7 @@ public class Font {
407407
return 0.0
408408
}
409409

410-
return LogicalToPoint(lfFont.lfHeight)
410+
return LogicalToPoint(Int32(lfFont.lfHeight))
411411
}
412412

413413
/// The top y-coordinate, offset from the baseline, of the font's longest

Sources/SwiftWin32/Views and Controls/Control.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -262,27 +262,27 @@ extension Control.Event {
262262

263263
/// All touch events.
264264
public static var allTouchEvents: Control.Event {
265-
Control.Event(rawValue: 0x00000fff)
265+
Control.Event(rawValue: RawValue(bitPattern: 0x00000fff))
266266
}
267267

268268
/// All editing touches for `TextField` objects.
269269
public static var allEditingEvents: Control.Event {
270-
Control.Event(rawValue: 0x000f0000)
270+
Control.Event(rawValue: RawValue(bitPattern: 0x000f0000))
271271
}
272272

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

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

283283
/// All events, including system events.
284284
public static var allEvents: Control.Event {
285-
Control.Event(rawValue: 0xffffffff)
285+
Control.Event(rawValue: RawValue(bitPattern: 0xffffffff))
286286
}
287287
}
288288

Sources/SwiftWin32/Views and Controls/PickerView.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private let SwiftPickerViewProxyWindowProc: WNDPROC = { (hWnd, uMsg, wParam, lPa
2525
switch lpDrawItem.pointee.itemAction {
2626
case UINT(ODA_SELECT):
2727
_ = DrawFocusRect(lpDrawItem.pointee.hDC, &lpDrawItem.pointee.rcItem)
28-
if lpDrawItem.pointee.itemState & DWORD(ODS_SELECTED) == DWORD(ODS_SELECTED) {
28+
if DWORD(lpDrawItem.pointee.itemState) & DWORD(ODS_SELECTED) == DWORD(ODS_SELECTED) {
2929
// If the item is selected, we have drawn the focus rectangle and the
3030
// operation is complete.
3131
return LRESULT(1)
@@ -38,8 +38,8 @@ private let SwiftPickerViewProxyWindowProc: WNDPROC = { (hWnd, uMsg, wParam, lPa
3838
if let view = unsafeBitCast(lpDrawItem.pointee.itemData,
3939
to: AnyObject.self) as? View {
4040
let rctRect: RECT = lpDrawItem.pointee.rcItem
41-
_ = SetWindowPos(view.hWnd, nil, rctRect.left, rctRect.top, 0, 0,
42-
UINT(SWP_NOSIZE))
41+
_ = SetWindowPos(view.hWnd, nil, CInt(rctRect.left), CInt(rctRect.top),
42+
0, 0, UINT(SWP_NOSIZE))
4343
// Setting `isHidden` is necessary for Views generated after initial
4444
// call to `Window.makeKeyAndVisible()`
4545
if IsWindowVisible(GetParent(view.hWnd)) && !IsWindowVisible(view.hWnd) {
@@ -117,8 +117,8 @@ private let SwiftPickerViewWindowProc: SUBCLASSPROC = { (hWnd, uMsg, wParam, lPa
117117
DeviceContextHandle(owning: GetDC(view.hWnd))
118118
let hBitmap: BitmapHandle =
119119
BitmapHandle(owning: CreateCompatibleBitmap(hDCItem.value,
120-
rcClient.right - rcClient.left,
121-
rcClient.bottom - rcClient.top))
120+
CInt(rcClient.right - rcClient.left),
121+
CInt(rcClient.bottom - rcClient.top)))
122122

123123
let hDCMemory: DeviceContextHandle =
124124
DeviceContextHandle(owning: CreateCompatibleDC(nil))
@@ -133,10 +133,10 @@ private let SwiftPickerViewWindowProc: SUBCLASSPROC = { (hWnd, uMsg, wParam, lPa
133133
let hDC: DeviceContextHandle =
134134
DeviceContextHandle(owning: GetDC(hWnd))
135135

136-
_ = BitBlt(hDC.value, cbiInfo.rcItem.left, cbiInfo.rcItem.top,
137-
cbiInfo.rcItem.right - cbiInfo.rcItem.left,
138-
cbiInfo.rcItem.bottom - cbiInfo.rcItem.top, hDCMemory.value,
139-
0, 0, UINT(SRCCOPY))
136+
_ = BitBlt(hDC.value, CInt(cbiInfo.rcItem.left), CInt(cbiInfo.rcItem.top),
137+
CInt(cbiInfo.rcItem.right - cbiInfo.rcItem.left),
138+
CInt(cbiInfo.rcItem.bottom - cbiInfo.rcItem.top),
139+
hDCMemory.value, 0, 0, DWORD(SRCCOPY))
140140

141141
return lResult
142142

Sources/SwiftWin32/Views and Controls/Stepper.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private class StepperProxy {
5454
public class Stepper: Control {
5555
private static let `class`: WindowClass = WindowClass(named: UPDOWN_CLASS)
5656
private static let style: WindowStyle =
57-
(base: UInt32(UDS_HORZ) | WS_POPUP | WS_TABSTOP, extended: 0)
57+
(base: DWORD(UDS_HORZ) | WS_POPUP | WS_TABSTOP, extended: 0)
5858

5959
private static var proxy: StepperProxy = StepperProxy()
6060

@@ -75,10 +75,10 @@ public class Stepper: Control {
7575
/// A boolean value that determines whether the stepper can wrap its value to
7676
/// the minimum or maximum value when incrementing and decrementing the value.
7777
public var wraps: Bool {
78-
get { self.GWL_STYLE & UDS_WRAP == UDS_WRAP }
78+
get { self.GWL_STYLE & LONG(UDS_WRAP) == LONG(UDS_WRAP) }
7979
set {
80-
self.GWL_STYLE = newValue ? self.GWL_STYLE | UDS_WRAP
81-
: self.GWL_STYLE & ~UDS_WRAP
80+
self.GWL_STYLE = newValue ? self.GWL_STYLE | LONG(UDS_WRAP)
81+
: self.GWL_STYLE & ~LONG(UDS_WRAP)
8282
}
8383
}
8484

@@ -137,7 +137,7 @@ public class Stepper: Control {
137137
SendMessageW(self.hWnd, UINT(UDM_GETACCEL),
138138
WPARAM(1), LPARAM(UInt(bitPattern: $0)))
139139
}
140-
value.nInc = DWORD(newValue)
140+
value.nInc = UINT(newValue)
141141
_ = withUnsafeMutablePointer(to: &value) {
142142
SendMessageW(self.hWnd, UINT(UDM_SETACCEL),
143143
WPARAM(1), LPARAM(UInt(bitPattern: $0)))

Sources/SwiftWin32/Views and Controls/Table Views/TableView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ private let SwiftTableViewProxyWindowProc: WNDPROC = { (hWnd, uMsg, wParam, lPar
2525
if let view = unsafeBitCast(lpDrawItem.pointee.itemData,
2626
to: AnyObject.self) as? View {
2727
let rctRect: RECT = lpDrawItem.pointee.rcItem
28-
_ = SetWindowPos(view.hWnd, nil, rctRect.left, rctRect.top, 0, 0,
29-
UINT(SWP_NOSIZE))
28+
_ = SetWindowPos(view.hWnd, nil, CInt(rctRect.left), CInt(rctRect.top),
29+
0, 0, UINT(SWP_NOSIZE))
3030

3131
// Setting `isHidden` is necessary for TableCells generated after
3232
// initial call to `Window.makeKeyAndVisible()`

Sources/SwiftWin32/Views and Controls/TextView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public class TextView: View {
3737
// Disable compatibility with the original Rich Edit and use the extended
3838
// text limit.
3939
_ = SendMessageW(self.hWnd, UINT(EM_EXLIMITTEXT),
40-
WPARAM(0), LPARAM(bitPattern: UInt64(bitPattern: -1)))
40+
WPARAM(0), LPARAM(UInt(bitPattern: -1)))
4141
}
4242

4343
public func scrollRangeToVisible(_ range: NSRange) {
4444
SendMessageW(hWnd, UINT(EM_SETSEL), WPARAM(range.location),
4545
LPARAM(range.location + range.length))
46-
SendMessageW(hWnd, UINT(EM_SETSEL), UInt64(bitPattern: -1), -1)
46+
SendMessageW(hWnd, UINT(EM_SETSEL), WPARAM(bitPattern: -1), -1)
4747
SendMessageW(hWnd, UINT(EM_SCROLLCARET), 0, 0)
4848
}
4949

0 commit comments

Comments
 (0)