quickwin 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.en.md +7 -7
  2. package/README.md +7 -7
  3. package/constants.ts +1063 -0
  4. package/enum_map.d.ts +129 -0
  5. package/examples/PdfCanvas.js +2 -2
  6. package/examples/PdfCanvas.tsx +3 -2
  7. package/examples/{execd.js → execd/main.js} +563 -122
  8. package/examples/execd/tray.js +192 -0
  9. package/examples/{execd_worker.js → execd/worker.js} +7 -7
  10. package/examples/pdf_preview2.js +46 -46
  11. package/examples/pdf_preview2.ts +55 -54
  12. package/examples/pdf_viewer.js +34 -19
  13. package/examples/pdf_viewer.tsx +6 -5
  14. package/examples/test_gallery.js +35 -20
  15. package/examples/test_gallery.tsx +9 -8
  16. package/examples/test_react_lazy.js +34 -19
  17. package/examples/test_react_lazy.tsx +7 -6
  18. package/examples/test_react_listbox.js +34 -19
  19. package/examples/test_react_listbox.tsx +8 -7
  20. package/examples/test_root_window.js +34 -19
  21. package/examples/test_root_window.tsx +5 -5
  22. package/examples/test_tab.js +34 -19
  23. package/examples/test_tab.tsx +7 -6
  24. package/examples/tray_demo.js +8 -8
  25. package/examples/tray_demo.tsx +9 -8
  26. package/lib/dumpRects.js +2 -2
  27. package/lib/dumpRects.ts +3 -2
  28. package/lib/fetch.js +15 -15
  29. package/lib/fetch.ts +16 -15
  30. package/lib/ffi/bind.js +3 -3
  31. package/lib/ffi/bind.ts +3 -3
  32. package/lib/http-server.js +4 -4
  33. package/lib/http-server.ts +5 -4
  34. package/lib/react-qw/components/Button.js +2 -2
  35. package/lib/react-qw/components/CheckBox.js +4 -4
  36. package/lib/react-qw/components/ComboBox.js +10 -10
  37. package/lib/react-qw/components/DateTimePicker.js +12 -12
  38. package/lib/react-qw/components/Input.js +7 -7
  39. package/lib/react-qw/components/Link.js +4 -4
  40. package/lib/react-qw/components/ListBox.js +12 -12
  41. package/lib/react-qw/components/ListView.js +35 -35
  42. package/lib/react-qw/components/PathPicker.js +3 -3
  43. package/lib/react-qw/components/ProgressBar.js +4 -4
  44. package/lib/react-qw/components/RadioButton.js +4 -4
  45. package/lib/react-qw/components/ScrollView.js +28 -28
  46. package/lib/react-qw/components/Slider.js +11 -11
  47. package/lib/react-qw/components/Tab.js +10 -10
  48. package/lib/react-qw/components/Tooltip.js +8 -8
  49. package/lib/react-qw/components/TreeView.js +20 -20
  50. package/lib/react-qw/index.js +5 -5
  51. package/lib/react-qw/index.ts +6 -5
  52. package/lib/react-qw/props.js +4 -4
  53. package/lib/react-qw/props.ts +5 -4
  54. package/lib/react-qw/reconciler.js +10 -10
  55. package/lib/react-qw/reconciler.ts +11 -10
  56. package/lib/text-measure.js +3 -3
  57. package/lib/text-measure.ts +4 -3
  58. package/lib/websocket.js +17 -17
  59. package/lib/websocket.ts +18 -17
  60. package/lib/windows/advapi32.js +7 -7
  61. package/lib/windows/advapi32.ts +7 -7
  62. package/lib/windows/gdi32.js +16 -16
  63. package/lib/windows/gdi32.ts +16 -16
  64. package/lib/windows/kernel32.js +41 -2
  65. package/lib/windows/kernel32.ts +45 -2
  66. package/lib/windows/shell32.js +24 -3
  67. package/lib/windows/shell32.ts +27 -4
  68. package/lib/windows/structs.js +54 -0
  69. package/lib/windows/structs.ts +63 -1
  70. package/lib/windows/user32.js +18 -6
  71. package/lib/windows/user32.ts +18 -6
  72. package/lib/windows/winspool.js +3 -3
  73. package/lib/windows/winspool.ts +3 -3
  74. package/package.json +4 -3
  75. package/quickwin.d.ts +32 -10
  76. package/qwin-nowasm-x86.exe +0 -0
  77. package/qwin-nowasm.exe +0 -0
  78. package/qwin-x86.exe +0 -0
  79. package/qwin.exe +0 -0
  80. package/test/test_ffi_bind.js +7 -7
  81. package/test/test_ffi_bind.ts +8 -8
  82. package/test/test_ffi_struct.js +2 -2
  83. package/test/test_ffi_struct.ts +3 -3
  84. package/test/test_ffi_windows.js +1 -1
  85. package/test/test_ffi_windows.ts +1 -1
  86. package/test/test_files.js +7 -7
  87. package/test/test_files.ts +8 -8
  88. package/test/test_gdi_draw.js +51 -51
  89. package/test/test_gdi_draw.ts +57 -57
  90. package/test/test_http_server.js +3 -3
  91. package/test/test_http_server.ts +4 -3
  92. package/test/test_ipv6.js +3 -3
  93. package/test/test_ipv6.ts +4 -3
  94. package/test/test_net_event.js +3 -3
  95. package/test/test_net_event.ts +4 -3
  96. package/test/test_printer.js +4 -4
  97. package/test/test_printer.ts +5 -5
  98. package/test/test_react_complex.js +36 -21
  99. package/test/test_react_counter.js +34 -19
  100. package/test/test_react_flex.js +36 -21
  101. package/test/test_react_hidden.js +34 -19
  102. package/test/test_react_listview_link.js +35 -20
  103. package/test/test_react_notify.js +52 -37
  104. package/test/test_react_render.js +34 -19
  105. package/test/test_registry.js +6 -6
  106. package/test/test_registry.ts +8 -8
  107. package/test/test_wolfssl_read.js +8 -8
  108. package/test/test_wolfssl_read.ts +9 -8
  109. package/examples/execd.tsx +0 -798
  110. package/examples/execd_worker.ts +0 -127
  111. package/quickwin_const.d.ts +0 -1063
@@ -1,5 +1,4 @@
1
1
  import { Tester } from './test_helper.js'
2
- import * as gui from 'gui'
3
2
  import { NULL, PtrArrayBuffer, type Ptr } from '../lib/ffi/ctype.js'
4
3
  import { FrameRect, GetDC, InvertRect, ReleaseDC } from '../lib/windows/user32.js'
5
4
  import {
@@ -14,6 +13,7 @@ import {
14
13
  } from '../lib/windows/gdi32.js'
15
14
  import { AlphaBlend, TransparentBlt } from '../lib/windows/msimg32.js'
16
15
  import { BITMAPINFOHEADER, POINT, SIZE, TEXTMETRICW } from '../lib/windows/structs.js'
16
+ import { ArcDirection, BackgroundMode, HatchStyle, PenStyle, PolyFillMode, RasterMode, RasterOp, StockObject, StretchBltMode, TextAlign, TextOutOptions } from '../constants'
17
17
 
18
18
  // 像素比较统一用 COLORREF 形(0x00BBGGRR)—— 与画图入参同形,读回直接对比。
19
19
  const RED = 0x000000ff
@@ -27,7 +27,7 @@ const H = 240
27
27
  export const suite = {
28
28
  name: 'gdi-draw',
29
29
  run: (t: Tester) => {
30
- // —— 基座:屏幕 DC → 内存 DC + 32bpp 位图(与 execd_worker 截屏同型)——
30
+ // —— 基座:屏幕 DC → 内存 DC + 32bpp 位图(与 execd/worker 截屏同型)——
31
31
  t.section('setup: memory DC + 32bpp bitmap')
32
32
  const screen = GetDC(NULL)
33
33
  const mem = CreateCompatibleDC(screen)
@@ -59,7 +59,7 @@ export const suite = {
59
59
  return (pxU8[i]! << 16) | (pxU8[i + 1]! << 8) | pxU8[i + 2]! // B,G,R → COLORREF
60
60
  }
61
61
  const clearWhite = (): void => {
62
- PatBlt(mem, 0, 0, W, H, gui.RasterOp.WHITENESS) // 与画刷无关的整白
62
+ PatBlt(mem, 0, 0, W, H, RasterOp.WHITENESS) // 与画刷无关的整白
63
63
  readPx()
64
64
  }
65
65
  clearWhite()
@@ -68,10 +68,10 @@ export const suite = {
68
68
 
69
69
  t.section('state: return-previous semantics')
70
70
  t.check('fresh DC default bkMode = OPAQUE',
71
- gui.BackgroundMode.OPAQUE, SetBkMode(mem, gui.BackgroundMode.OPAQUE))
72
- t.check('SetBkMode returns previous', gui.BackgroundMode.OPAQUE,
73
- SetBkMode(mem, gui.BackgroundMode.TRANSPARENT))
74
- SetBkMode(mem, gui.BackgroundMode.OPAQUE)
71
+ BackgroundMode.OPAQUE, SetBkMode(mem, BackgroundMode.OPAQUE))
72
+ t.check('SetBkMode returns previous', BackgroundMode.OPAQUE,
73
+ SetBkMode(mem, BackgroundMode.TRANSPARENT))
74
+ SetBkMode(mem, BackgroundMode.OPAQUE)
75
75
  SetTextColor(mem, RED) // 返回默认色(不假设)
76
76
  t.check('SetTextColor returns previous', RED, SetTextColor(mem, BLUE))
77
77
  SetTextColor(mem, 0)
@@ -82,7 +82,7 @@ export const suite = {
82
82
  // 类型专用块(只过 tsc、不执行)
83
83
  const typeOnly: unknown = () => {
84
84
  // @ts-expect-error 跨枚举 nominal:BackgroundMode 成员进不了 PenStyle 位
85
- CreatePen(gui.BackgroundMode.TRANSPARENT, 1, 0)
85
+ CreatePen(BackgroundMode.TRANSPARENT, 1, 0)
86
86
  // @ts-expect-error '<HDC>ptr!' 禁空位不收 NULL
87
87
  Rectangle(NULL, 0, 0, 1, 1)
88
88
  // @ts-expect-error encoder 数组位不收裸对象(单对象对 C 是越界基址)
@@ -92,39 +92,39 @@ export const suite = {
92
92
  // @ts-expect-error <WCHAR>ptr 文本位收 string / NULL,不收裸数字
93
93
  TextOut(0 as Ptr<'HDC'>, 0, 0, 123, 1)
94
94
  // @ts-expect-error 跨枚举 nominal:PenStyle 成员进不了 StockObject 位
95
- GetStockObject(gui.PenStyle.SOLID)
95
+ GetStockObject(PenStyle.SOLID)
96
96
  // @ts-expect-error 跨枚举 nominal:HatchStyle 成员进不了 PolyFillMode 位
97
- SetPolyFillMode(0 as Ptr<'HDC'>, gui.HatchStyle.CROSS)
97
+ SetPolyFillMode(0 as Ptr<'HDC'>, HatchStyle.CROSS)
98
98
  // @ts-expect-error u32@RasterOp 标注拦枚举外光栅码(字面量不匹配成员值)
99
99
  PatBlt(0 as Ptr<'HDC'>, 0, 0, 1, 1, 0x123456)
100
100
  // @ts-expect-error '<SIZE>ptr!' 出参位不收 NULL
101
101
  GetTextExtentPoint32(0 as Ptr<'HDC'>, 'x', 1, NULL)
102
102
  // @ts-expect-error 跨枚举 nominal:StretchBltMode 成员进不了 ArcDirection 位
103
- SetArcDirection(0 as Ptr<'HDC'>, gui.StretchBltMode.HALFTONE)
103
+ SetArcDirection(0 as Ptr<'HDC'>, StretchBltMode.HALFTONE)
104
104
  }
105
105
  t.checkTrue('type-only block wired', typeof typeOnly === 'function')
106
106
 
107
107
  t.section('SaveDC/RestoreDC: state stack rollback')
108
108
  // 先定基态(断言不依赖前面 section 的收尾值)
109
109
  SetTextColor(mem, 0)
110
- SetBkMode(mem, gui.BackgroundMode.OPAQUE)
110
+ SetBkMode(mem, BackgroundMode.OPAQUE)
111
111
  SetBkColor(mem, WHITE)
112
112
  const saved = SaveDC(mem)
113
113
  t.checkTrue(`SaveDC state id ≠ 0 (${saved})`, saved !== 0)
114
114
  // 打乱:三项绘图状态 + 换一支笔
115
115
  SetTextColor(mem, RED)
116
- SetBkMode(mem, gui.BackgroundMode.TRANSPARENT)
116
+ SetBkMode(mem, BackgroundMode.TRANSPARENT)
117
117
  SetBkColor(mem, BLUE)
118
- const junkPen = CreatePen(gui.PenStyle.DASH, 1, GREEN)
118
+ const junkPen = CreatePen(PenStyle.DASH, 1, GREEN)
119
119
  SelectObject(mem, junkPen)
120
120
  t.checkTrue('RestoreDC ok', RestoreDC(mem, saved) !== 0)
121
121
  DeleteObject(junkPen) // 恢复后已卸下,可安全删
122
122
  // 逐项回滚断言:各 Set 返回的就是回滚后的当前值
123
123
  t.check('text color rolled back', 0, SetTextColor(mem, RED))
124
124
  SetTextColor(mem, 0)
125
- t.check('bkMode rolled back', gui.BackgroundMode.OPAQUE,
126
- SetBkMode(mem, gui.BackgroundMode.TRANSPARENT))
127
- SetBkMode(mem, gui.BackgroundMode.OPAQUE)
125
+ t.check('bkMode rolled back', BackgroundMode.OPAQUE,
126
+ SetBkMode(mem, BackgroundMode.TRANSPARENT))
127
+ SetBkMode(mem, BackgroundMode.OPAQUE)
128
128
  t.check('bkColor rolled back', WHITE, SetBkColor(mem, RED))
129
129
  SetBkColor(mem, WHITE)
130
130
 
@@ -143,7 +143,7 @@ export const suite = {
143
143
 
144
144
  t.section('Polyline: encoder array position + NULL passthrough')
145
145
  clearWhite()
146
- const pen = CreatePen(gui.PenStyle.SOLID, 1, GREEN)
146
+ const pen = CreatePen(PenStyle.SOLID, 1, GREEN)
147
147
  t.checkTrue('pen created', !!pen)
148
148
  const oldPen = SelectObject(mem, pen)
149
149
  t.checkTrue('Polyline success',
@@ -179,10 +179,10 @@ export const suite = {
179
179
  DeleteObject(pen)
180
180
 
181
181
  t.section('SetROP2: R2_XORPEN reversible')
182
- PatBlt(mem, 0, 0, W, H, gui.RasterOp.BLACKNESS) // 黑底:黑^绿=绿,绿^绿=黑
183
- t.check('default raster mode = R2_COPYPEN', gui.RasterMode.R2_COPYPEN,
184
- SetROP2(mem, gui.RasterMode.R2_XORPEN)) // 返回旧值 = 默认,同时设为 XOR
185
- const xorPen = CreatePen(gui.PenStyle.SOLID, 1, GREEN)
182
+ PatBlt(mem, 0, 0, W, H, RasterOp.BLACKNESS) // 黑底:黑^绿=绿,绿^绿=黑
183
+ t.check('default raster mode = R2_COPYPEN', RasterMode.R2_COPYPEN,
184
+ SetROP2(mem, RasterMode.R2_XORPEN)) // 返回旧值 = 默认,同时设为 XOR
185
+ const xorPen = CreatePen(PenStyle.SOLID, 1, GREEN)
186
186
  const xorOld = SelectObject(mem, xorPen)
187
187
  MoveToEx(mem, 10, 200, NULL)
188
188
  LineTo(mem, 100, 200)
@@ -194,7 +194,7 @@ export const suite = {
194
194
  t.check('second pass cancels back to black', BLACK, px(50, 200))
195
195
  SelectObject(mem, xorOld)
196
196
  DeleteObject(xorPen)
197
- SetROP2(mem, gui.RasterMode.R2_COPYPEN) // 恢复
197
+ SetROP2(mem, RasterMode.R2_COPYPEN) // 恢复
198
198
 
199
199
  t.section('Polygon: fill + outline (auto-close)')
200
200
  clearWhite()
@@ -228,7 +228,7 @@ export const suite = {
228
228
  // 圆 (100,100)-(200,200) 心 (150,150) r=50;起 12 点 (150,100) → 终 9 点 (100,150):
229
229
  // GDI 默认逆时针 12→11→10→9 = 左上 90° 弧(SetArcDirection 可改,见 MSDN Arc)
230
230
  clearWhite()
231
- const arcPen = CreatePen(gui.PenStyle.SOLID, 1, RED)
231
+ const arcPen = CreatePen(PenStyle.SOLID, 1, RED)
232
232
  const arcOldPen = SelectObject(mem, arcPen)
233
233
  Arc(mem, 100, 100, 200, 200, 150, 100, 100, 150)
234
234
  readPx()
@@ -272,15 +272,15 @@ export const suite = {
272
272
  clearWhite()
273
273
  const dirBrush = CreateSolidBrush(RED)
274
274
  const dirOldB = SelectObject(mem, dirBrush)
275
- t.check('default arc direction = counterclockwise', gui.ArcDirection.COUNTERCLOCKWISE,
275
+ t.check('default arc direction = counterclockwise', ArcDirection.COUNTERCLOCKWISE,
276
276
  GetArcDirection(mem))
277
- t.check('SetArcDirection returns previous', gui.ArcDirection.COUNTERCLOCKWISE,
278
- SetArcDirection(mem, gui.ArcDirection.CLOCKWISE))
277
+ t.check('SetArcDirection returns previous', ArcDirection.COUNTERCLOCKWISE,
278
+ SetArcDirection(mem, ArcDirection.CLOCKWISE))
279
279
  Pie(mem, 100, 100, 200, 200, 150, 100, 100, 150) // 起 12 点终 9 点:顺时针 → 右下 270°
280
280
  readPx()
281
281
  t.check('clockwise sweep fills opposite side', RED, px(180, 180))
282
282
  t.check('clockwise sweep skips upper-left', WHITE, px(118, 128))
283
- SetArcDirection(mem, gui.ArcDirection.COUNTERCLOCKWISE) // 恢复默认
283
+ SetArcDirection(mem, ArcDirection.COUNTERCLOCKWISE) // 恢复默认
284
284
  SelectObject(mem, dirOldB)
285
285
  DeleteObject(dirBrush)
286
286
 
@@ -293,8 +293,8 @@ export const suite = {
293
293
  V.push({ x: Math.round(150 + 55 * Math.cos(a)), y: Math.round(150 + 55 * Math.sin(a)) })
294
294
  }
295
295
  const star = [V[0]!, V[2]!, V[4]!, V[1]!, V[3]!]
296
- t.check('default fill mode = ALTERNATE', gui.PolyFillMode.ALTERNATE,
297
- SetPolyFillMode(mem, gui.PolyFillMode.ALTERNATE))
296
+ t.check('default fill mode = ALTERNATE', PolyFillMode.ALTERNATE,
297
+ SetPolyFillMode(mem, PolyFillMode.ALTERNATE))
298
298
  const starBrush = CreateSolidBrush(RED)
299
299
  const starOldB = SelectObject(mem, starBrush)
300
300
  Polygon(mem, star, 5)
@@ -307,19 +307,19 @@ export const suite = {
307
307
  }
308
308
  t.checkTrue(`ALTERNATE: star drawn (${starRed}px)`, starRed > 200)
309
309
  t.check('ALTERNATE: center hollow (even-odd)', WHITE, px(150, 150))
310
- SetPolyFillMode(mem, gui.PolyFillMode.WINDING)
310
+ SetPolyFillMode(mem, PolyFillMode.WINDING)
311
311
  clearWhite()
312
312
  Polygon(mem, star, 5)
313
313
  readPx()
314
314
  t.check('WINDING: center filled (nonzero)', RED, px(150, 150))
315
315
  SelectObject(mem, starOldB)
316
316
  DeleteObject(starBrush)
317
- SetPolyFillMode(mem, gui.PolyFillMode.ALTERNATE) // 恢复默认
317
+ SetPolyFillMode(mem, PolyFillMode.ALTERNATE) // 恢复默认
318
318
 
319
319
  t.section('GetStockObject: stock objects, outline-only shape')
320
320
  clearWhite()
321
- const hollow = GetStockObject(gui.StockObject.NULL_BRUSH)
322
- const stkPen = GetStockObject(gui.StockObject.BLACK_PEN)
321
+ const hollow = GetStockObject(StockObject.NULL_BRUSH)
322
+ const stkPen = GetStockObject(StockObject.BLACK_PEN)
323
323
  t.checkTrue(`stock handles non-zero (0x${hollow.toString(16)}, 0x${stkPen.toString(16)})`,
324
324
  hollow !== 0 && stkPen !== 0)
325
325
  const stockOldBrush = SelectObject(mem, hollow)
@@ -347,8 +347,8 @@ export const suite = {
347
347
 
348
348
  t.section('CreateHatchBrush: textured fill')
349
349
  clearWhite()
350
- SetBkMode(mem, gui.BackgroundMode.TRANSPARENT) // 间隙透底 = 白
351
- const hatch = CreateHatchBrush(gui.HatchStyle.HORIZONTAL, RED)
350
+ SetBkMode(mem, BackgroundMode.TRANSPARENT) // 间隙透底 = 白
351
+ const hatch = CreateHatchBrush(HatchStyle.HORIZONTAL, RED)
352
352
  t.checkTrue('hatch brush created', hatch !== 0)
353
353
  const hatchOldB = SelectObject(mem, hatch)
354
354
  Rectangle(mem, 20, 20, 120, 60)
@@ -369,7 +369,7 @@ export const suite = {
369
369
  t.check('no other colors in hatch', 0, hOther)
370
370
  SelectObject(mem, hatchOldB)
371
371
  DeleteObject(hatch)
372
- SetBkMode(mem, gui.BackgroundMode.OPAQUE)
372
+ SetBkMode(mem, BackgroundMode.OPAQUE)
373
373
 
374
374
  t.section('FrameRect/InvertRect: border and invert (user32)')
375
375
  clearWhite()
@@ -401,17 +401,17 @@ export const suite = {
401
401
  const stOldBmp = SelectObject(stTmp, stBmp)
402
402
  const stFill = CreateSolidBrush(RED)
403
403
  SelectObject(stTmp, stFill)
404
- PatBlt(stTmp, 0, 0, 4, 4, gui.RasterOp.PATCOPY) // 源 4×4 全红
404
+ PatBlt(stTmp, 0, 0, 4, 4, RasterOp.PATCOPY) // 源 4×4 全红
405
405
  t.checkTrue('StretchBlt ok',
406
- StretchBlt(mem, 10, 10, 40, 40, stTmp, 0, 0, 4, 4, gui.RasterOp.SRCCOPY) !== 0)
406
+ StretchBlt(mem, 10, 10, 40, 40, stTmp, 0, 0, 4, 4, RasterOp.SRCCOPY) !== 0)
407
407
  readPx()
408
408
  t.check('scaled center red', RED, px(30, 30))
409
409
  t.check('scaled near-origin red', RED, px(11, 11))
410
410
  t.check('outside target untouched', WHITE, px(60, 30))
411
411
  const stMode0 = GetStretchBltMode(mem)
412
412
  t.check('SetStretchBltMode returns current', stMode0,
413
- SetStretchBltMode(mem, gui.StretchBltMode.HALFTONE))
414
- t.check('GetStretchBltMode = HALFTONE', gui.StretchBltMode.HALFTONE, GetStretchBltMode(mem))
413
+ SetStretchBltMode(mem, StretchBltMode.HALFTONE))
414
+ t.check('GetStretchBltMode = HALFTONE', StretchBltMode.HALFTONE, GetStretchBltMode(mem))
415
415
  SelectObject(stTmp, stOldBmp)
416
416
  DeleteObject(stFill)
417
417
  DeleteObject(stBmp)
@@ -428,11 +428,11 @@ export const suite = {
428
428
  const pkOldBmp = SelectObject(pkTmp, pkBmp)
429
429
  const pkRed = CreateSolidBrush(RED)
430
430
  SelectObject(pkTmp, pkRed)
431
- PatBlt(pkTmp, 0, 0, 4, 4, gui.RasterOp.PATCOPY) // 红底
431
+ PatBlt(pkTmp, 0, 0, 4, 4, RasterOp.PATCOPY) // 红底
432
432
  const pkWhite = CreateSolidBrush(WHITE)
433
433
  SelectObject(pkTmp, pkWhite)
434
- PatBlt(pkTmp, 2, 0, 2, 2, gui.RasterOp.PATCOPY) // 挖两白角 = 2×2 棋盘
435
- PatBlt(pkTmp, 0, 2, 2, 2, gui.RasterOp.PATCOPY)
434
+ PatBlt(pkTmp, 2, 0, 2, 2, RasterOp.PATCOPY) // 挖两白角 = 2×2 棋盘
435
+ PatBlt(pkTmp, 0, 2, 2, 2, RasterOp.PATCOPY)
436
436
  SelectObject(pkTmp, pkOldBmp) // 位图退出选入状态
437
437
  const pkPat = CreatePatternBrush(pkBmp)
438
438
  t.checkTrue('pattern brush created', pkPat !== 0)
@@ -477,7 +477,7 @@ export const suite = {
477
477
  clearWhite()
478
478
  t.checkTrue('StretchDIBits ok',
479
479
  StretchDIBits(mem, 20, 20, 40, 40, 0, 0, 4, 4, dibBits, dibBmi, 0,
480
- gui.RasterOp.SRCCOPY) === 4)
480
+ RasterOp.SRCCOPY) === 4)
481
481
  readPx()
482
482
  t.check('stretched top half red', RED, px(40, 30))
483
483
  t.check('stretched bottom half blue', BLUE, px(40, 50))
@@ -491,7 +491,7 @@ export const suite = {
491
491
  const plgOldB = SelectObject(plgTmp, plgBmp)
492
492
  const plgRed = CreateSolidBrush(RED)
493
493
  SelectObject(plgTmp, plgRed)
494
- PatBlt(plgTmp, 0, 0, 40, 40, gui.RasterOp.PATCOPY) // 源 40×40 全红
494
+ PatBlt(plgTmp, 0, 0, 40, 40, RasterOp.PATCOPY) // 源 40×40 全红
495
495
  // 三点 TL(40,60) TR(160,60) BL(70,160) → 方向 s(120,0)+t(30,100),中心 (115,110)
496
496
  t.checkTrue('PlgBlt ok',
497
497
  PlgBlt(mem, [{ x: 40, y: 60 }, { x: 160, y: 60 }, { x: 70, y: 160 }],
@@ -512,7 +512,7 @@ export const suite = {
512
512
  const mkOldB = SelectObject(mkTmp, mkBmp)
513
513
  const mkRed = CreateSolidBrush(RED)
514
514
  SelectObject(mkTmp, mkRed)
515
- PatBlt(mkTmp, 0, 0, 4, 4, gui.RasterOp.PATCOPY) // 源 4×4 全红
515
+ PatBlt(mkTmp, 0, 0, 4, 4, RasterOp.PATCOPY) // 源 4×4 全红
516
516
  // 1bpp 掩码 4×4:行按 word(2B) 对齐(CreateBitmap 惯例,非 DIB 的 4B)——
517
517
  // 行 0/2 = 0xFF(白)、行 1/3 = 0x00(黑)
518
518
  const mkBits = new PtrArrayBuffer(8)
@@ -521,9 +521,9 @@ export const suite = {
521
521
  mkU8[4] = 0xFF
522
522
  const mask = CreateBitmap(4, 4, 1, 1, mkBits)
523
523
  t.checkTrue('CreateBitmap(1bpp) ok', mask !== 0)
524
- PatBlt(mem, 30, 30, 4, 4, gui.RasterOp.BLACKNESS) // 目标底黑 → back 白可辨
524
+ PatBlt(mem, 30, 30, 4, 4, RasterOp.BLACKNESS) // 目标底黑 → back 白可辨
525
525
  // MAKEROP4(fore=SRCCOPY 取源, back=WHITENESS 画白):back 码在 bit31..24、fore 在 bit23..16
526
- const rop4 = (((gui.RasterOp.WHITENESS << 8) & 0xFF000000) | gui.RasterOp.SRCCOPY) >>> 0
526
+ const rop4 = (((RasterOp.WHITENESS << 8) & 0xFF000000) | RasterOp.SRCCOPY) >>> 0
527
527
  t.checkTrue('MaskBlt ok',
528
528
  MaskBlt(mem, 30, 30, 4, 4, mkTmp, 0, 0, mask, 0, 0, rop4) !== 0)
529
529
  readPx()
@@ -545,10 +545,10 @@ export const suite = {
545
545
  const trOldB = SelectObject(trTmp, trBmp)
546
546
  const trRed = CreateSolidBrush(RED)
547
547
  SelectObject(trTmp, trRed)
548
- PatBlt(trTmp, 0, 0, 20, 16, gui.RasterOp.PATCOPY) // 左半红
548
+ PatBlt(trTmp, 0, 0, 20, 16, RasterOp.PATCOPY) // 左半红
549
549
  const trBlue = CreateSolidBrush(BLUE)
550
550
  SelectObject(trTmp, trBlue)
551
- PatBlt(trTmp, 20, 0, 20, 16, gui.RasterOp.PATCOPY) // 右半蓝 = 键色
551
+ PatBlt(trTmp, 20, 0, 20, 16, RasterOp.PATCOPY) // 右半蓝 = 键色
552
552
  t.checkTrue('TransparentBlt ok',
553
553
  TransparentBlt(mem, 20, 20, 40, 16, trTmp, 0, 0, 40, 16, BLUE) !== 0)
554
554
  readPx()
@@ -570,7 +570,7 @@ export const suite = {
570
570
  const abOldB = SelectObject(abTmp, abBmp)
571
571
  const abGreen = CreateSolidBrush(GREEN)
572
572
  SelectObject(abTmp, abGreen)
573
- PatBlt(abTmp, 0, 0, 40, 16, gui.RasterOp.PATCOPY) // 源 = 纯绿(不透明)
573
+ PatBlt(abTmp, 0, 0, 40, 16, RasterOp.PATCOPY) // 源 = 纯绿(不透明)
574
574
  // 完全覆盖:SourceConstantAlpha=255、无调制(BlendFlags=0)、BlendOp=AC_SRC_OVER(0)
575
575
  t.checkTrue('AlphaBlend full alpha ok',
576
576
  AlphaBlend(mem, 20, 20, 40, 16, abTmp, 0, 0, 40, 16,
@@ -604,7 +604,7 @@ export const suite = {
604
604
  t.section('TextOut: transparent background + text color')
605
605
  clearWhite()
606
606
  SetBkColor(mem, BLUE) // 衬底设蓝:若 TRANSPARENT 未生效,字底必现蓝块
607
- SetBkMode(mem, gui.BackgroundMode.TRANSPARENT)
607
+ SetBkMode(mem, BackgroundMode.TRANSPARENT)
608
608
  SetTextColor(mem, RED)
609
609
  t.checkTrue('TextOut success', TextOut(mem, 20, 100, 'Hello GDI', 9) !== 0)
610
610
  readPx()
@@ -620,7 +620,7 @@ export const suite = {
620
620
  }
621
621
  t.checkTrue(`glyph pixels rendered (red=${redPx})`, redPx > 20)
622
622
  t.checkTrue(`transparent bg: zero blue backdrop (blue=${bluePx})`, bluePx === 0)
623
- SetBkMode(mem, gui.BackgroundMode.OPAQUE)
623
+ SetBkMode(mem, BackgroundMode.OPAQUE)
624
624
  SetBkColor(mem, WHITE)
625
625
  SetTextColor(mem, 0)
626
626
 
@@ -648,7 +648,7 @@ export const suite = {
648
648
  // (c) SetTextAlign 右对齐:字形全部落在锚点左侧
649
649
  SetTextColor(mem, RED)
650
650
  t.check('default align = 0 (LEFT|TOP|NOUPDATECP)', 0,
651
- SetTextAlign(mem, gui.TextAlign.TA_RIGHT))
651
+ SetTextAlign(mem, TextAlign.TA_RIGHT))
652
652
  TextOut(mem, 200, 100, 'Right', 5)
653
653
  readPx()
654
654
  let rRight = 0
@@ -664,14 +664,14 @@ export const suite = {
664
664
  }
665
665
  t.checkTrue(`right-aligned glyphs left of anchor (red=${rRight})`, rRight > 10)
666
666
  t.check('no glyphs right of anchor', 0, rWrong)
667
- SetTextAlign(mem, gui.TextAlign.TA_LEFT) // 恢复 0
667
+ SetTextAlign(mem, TextAlign.TA_LEFT) // 恢复 0
668
668
  SetTextColor(mem, 0)
669
669
 
670
670
  // (d) ExtTextOut ETO_OPAQUE 衬底(lprc 对象形直传 = encoder 入参位)
671
671
  SetTextColor(mem, RED)
672
672
  SetBkColor(mem, BLUE)
673
673
  t.checkTrue('ExtTextOut ETO_OPAQUE ok',
674
- ExtTextOut(mem, 20, 100, gui.TextOutOptions.ETO_OPAQUE,
674
+ ExtTextOut(mem, 20, 100, TextOutOptions.ETO_OPAQUE,
675
675
  { left: 18, top: 98, right: 100, bottom: 118 }, 'Opaque', 6, NULL) !== 0)
676
676
  readPx()
677
677
  let oBlue = 0
@@ -24,7 +24,7 @@ function httpSend(host, port, raw, nResponses = 1) {
24
24
  sock.set_on_event(s, (event) => {
25
25
  if (done)
26
26
  return;
27
- if (event.lNetworkEvents & 16 /* sock.FdEvent.FD_CONNECT */) {
27
+ if (event.lNetworkEvents & 16 /* FdEvent.FD_CONNECT */) {
28
28
  const err = event.iErrorCode[0];
29
29
  if (err !== 0) {
30
30
  done = true;
@@ -36,7 +36,7 @@ function httpSend(host, port, raw, nResponses = 1) {
36
36
  const bytes = new TextEncoder().encode(raw);
37
37
  sock.send(s, bytes.buffer);
38
38
  }
39
- if (event.lNetworkEvents & 1 /* sock.FdEvent.FD_READ */) {
39
+ if (event.lNetworkEvents & 1 /* FdEvent.FD_READ */) {
40
40
  while (true) {
41
41
  const d = sock.recv(s, 8192);
42
42
  if (typeof d === 'number')
@@ -53,7 +53,7 @@ function httpSend(host, port, raw, nResponses = 1) {
53
53
  resolve(buf);
54
54
  }
55
55
  }
56
- if (event.lNetworkEvents & 32 /* sock.FdEvent.FD_CLOSE */) {
56
+ if (event.lNetworkEvents & 32 /* FdEvent.FD_CLOSE */) {
57
57
  if (!done) {
58
58
  done = true;
59
59
  os.clearTimeout(timer);
@@ -5,6 +5,7 @@ import * as sock from 'sock'
5
5
  import { Tester } from './test_helper.js'
6
6
  import { createServer } from '../lib/http-server.js'
7
7
  import '../lib/fetch.js'
8
+ import { FdEvent } from '../constants'
8
9
 
9
10
  // ── Minimal raw HTTP client for testing ──
10
11
 
@@ -19,7 +20,7 @@ function httpSend(host: string, port: number, raw: string, nResponses = 1): Prom
19
20
  }, 10000)
20
21
  sock.set_on_event(s, (event) => {
21
22
  if (done) return
22
- if (event.lNetworkEvents & sock.FdEvent.FD_CONNECT) {
23
+ if (event.lNetworkEvents & FdEvent.FD_CONNECT) {
23
24
  const err = event.iErrorCode[0]
24
25
  if (err !== 0) {
25
26
  done = true
@@ -31,7 +32,7 @@ function httpSend(host: string, port: number, raw: string, nResponses = 1): Prom
31
32
  const bytes = new TextEncoder().encode(raw)
32
33
  sock.send(s, bytes.buffer)
33
34
  }
34
- if (event.lNetworkEvents & sock.FdEvent.FD_READ) {
35
+ if (event.lNetworkEvents & FdEvent.FD_READ) {
35
36
  while (true) {
36
37
  const d = sock.recv(s, 8192) as unknown as ArrayBuffer | number
37
38
  if (typeof d === 'number') break
@@ -46,7 +47,7 @@ function httpSend(host: string, port: number, raw: string, nResponses = 1): Prom
46
47
  resolve(buf)
47
48
  }
48
49
  }
49
- if (event.lNetworkEvents & sock.FdEvent.FD_CLOSE) {
50
+ if (event.lNetworkEvents & FdEvent.FD_CLOSE) {
50
51
  if (!done) { done = true; os.clearTimeout(timer); sock.closesocket(s); resolve(buf) }
51
52
  }
52
53
  })
package/test/test_ipv6.js CHANGED
@@ -35,7 +35,7 @@ export const suite = {
35
35
  }
36
36
  let connected = false, gotData = false;
37
37
  sock.set_on_event(s, (event) => {
38
- if (event.lNetworkEvents & 16 /* sock.FdEvent.FD_CONNECT */) {
38
+ if (event.lNetworkEvents & 16 /* FdEvent.FD_CONNECT */) {
39
39
  if (event.iErrorCode[0] === 0) {
40
40
  connected = true;
41
41
  t.ok++;
@@ -51,14 +51,14 @@ export const suite = {
51
51
  reject(new Error('connect error: ' + event.iErrorCode[0]));
52
52
  }
53
53
  }
54
- if (event.lNetworkEvents & 1 /* sock.FdEvent.FD_READ */ && connected && !gotData) {
54
+ if (event.lNetworkEvents & 1 /* FdEvent.FD_READ */ && connected && !gotData) {
55
55
  const data = sock.recv(s, 4096);
56
56
  if (data && data.byteLength > 0) {
57
57
  gotData = true;
58
58
  t.ok++;
59
59
  }
60
60
  }
61
- if (event.lNetworkEvents & 32 /* sock.FdEvent.FD_CLOSE */) {
61
+ if (event.lNetworkEvents & 32 /* FdEvent.FD_CLOSE */) {
62
62
  sock.closesocket(s);
63
63
  if (gotData && connected)
64
64
  resolve();
package/test/test_ipv6.ts CHANGED
@@ -4,6 +4,7 @@ import * as os from 'os'
4
4
  import '../lib/fetch.js'
5
5
  import '../lib/websocket.js'
6
6
  import { Tester } from './test_helper.js'
7
+ import { FdEvent } from '../constants'
7
8
 
8
9
  const HTTP_PORT = 18923
9
10
  const HTTPS_PORT = 18924
@@ -32,7 +33,7 @@ export const suite = {
32
33
  let connected = false, gotData = false
33
34
 
34
35
  sock.set_on_event(s, (event: { lNetworkEvents: number; iErrorCode: number[] }) => {
35
- if (event.lNetworkEvents & sock.FdEvent.FD_CONNECT) {
36
+ if (event.lNetworkEvents & FdEvent.FD_CONNECT) {
36
37
  if (event.iErrorCode[0] === 0) {
37
38
  connected = true; t.ok++
38
39
  const req = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"
@@ -45,11 +46,11 @@ export const suite = {
45
46
  reject(new Error('connect error: ' + event.iErrorCode[0]))
46
47
  }
47
48
  }
48
- if (event.lNetworkEvents & sock.FdEvent.FD_READ && connected && !gotData) {
49
+ if (event.lNetworkEvents & FdEvent.FD_READ && connected && !gotData) {
49
50
  const data = sock.recv(s, 4096)
50
51
  if (data && data.byteLength > 0) { gotData = true; t.ok++ }
51
52
  }
52
- if (event.lNetworkEvents & sock.FdEvent.FD_CLOSE) {
53
+ if (event.lNetworkEvents & FdEvent.FD_CLOSE) {
53
54
  sock.closesocket(s)
54
55
  if (gotData && connected) resolve()
55
56
  else reject(new Error('test incomplete'))
@@ -18,7 +18,7 @@ export const suite = {
18
18
  }
19
19
  }, 5000);
20
20
  sock.set_on_event(s, (event) => {
21
- if (event.lNetworkEvents & 16 /* sock.FdEvent.FD_CONNECT */) {
21
+ if (event.lNetworkEvents & 16 /* FdEvent.FD_CONNECT */) {
22
22
  if (event.iErrorCode[0] === 0) {
23
23
  connected = true;
24
24
  t.ok++;
@@ -35,14 +35,14 @@ export const suite = {
35
35
  reject(new Error('connect error: ' + event.iErrorCode[0]));
36
36
  }
37
37
  }
38
- if (event.lNetworkEvents & 1 /* sock.FdEvent.FD_READ */ && connected && !gotData) {
38
+ if (event.lNetworkEvents & 1 /* FdEvent.FD_READ */ && connected && !gotData) {
39
39
  const data = sock.recv(s, 4096);
40
40
  if (data && data.byteLength > 0) {
41
41
  gotData = true;
42
42
  t.ok++;
43
43
  }
44
44
  }
45
- if (event.lNetworkEvents & 32 /* sock.FdEvent.FD_CLOSE */) {
45
+ if (event.lNetworkEvents & 32 /* FdEvent.FD_CLOSE */) {
46
46
  os.clearTimeout(timeoutId);
47
47
  sock.closesocket(s);
48
48
  if (gotData && connected)
@@ -1,6 +1,7 @@
1
1
  import * as sock from "sock"
2
2
  import * as os from "os"
3
3
  import { Tester } from './test_helper.js'
4
+ import { FdEvent } from '../constants'
4
5
 
5
6
  interface WSAEvent {
6
7
  lNetworkEvents: number;
@@ -24,7 +25,7 @@ export const suite = {
24
25
  }, 5000)
25
26
 
26
27
  sock.set_on_event(s, (event: WSAEvent) => {
27
- if (event.lNetworkEvents & sock.FdEvent.FD_CONNECT) {
28
+ if (event.lNetworkEvents & FdEvent.FD_CONNECT) {
28
29
  if (event.iErrorCode[0] === 0) {
29
30
  connected = true; t.ok++
30
31
  os.clearTimeout(timeoutId)
@@ -38,11 +39,11 @@ export const suite = {
38
39
  reject(new Error('connect error: ' + event.iErrorCode[0]))
39
40
  }
40
41
  }
41
- if (event.lNetworkEvents & sock.FdEvent.FD_READ && connected && !gotData) {
42
+ if (event.lNetworkEvents & FdEvent.FD_READ && connected && !gotData) {
42
43
  const data = sock.recv(s, 4096)
43
44
  if (data && data.byteLength > 0) { gotData = true; t.ok++ }
44
45
  }
45
- if (event.lNetworkEvents & sock.FdEvent.FD_CLOSE) {
46
+ if (event.lNetworkEvents & FdEvent.FD_CLOSE) {
46
47
  os.clearTimeout(timeoutId)
47
48
  sock.closesocket(s)
48
49
  if (gotData && connected) resolve()
@@ -6,7 +6,7 @@ import { NULL, PtrArrayBuffer } from '../lib/ffi/ctype.js';
6
6
  import { CloseHandle, CreateFile, DeleteFile, GetLastError, GetTempPath, GetFileSize, ReadFile } from '../lib/windows/kernel32.js';
7
7
  import { ClosePrinter, DeviceCapabilities, EnumPrinters, EndDocPrinter, EndPagePrinter, GetDefaultPrinter, OpenPrinter, StartDocPrinter, StartPagePrinter, WritePrinter, } from '../lib/windows/winspool.js';
8
8
  import { PRINTER_INFO_2W } from '../lib/windows/structs.js';
9
- // gui.PrinterEnum.LOCAL(0x2) | CONNECTIONS(0x4):可组合 flags 组合 OR 裸传
9
+ // PrinterEnum.LOCAL(0x2) | CONNECTIONS(0x4):可组合 flags 组合 OR 裸传
10
10
  const LOCAL_OR_CONNECTIONS = 0x6;
11
11
  const MAX_WCHARS = 4096;
12
12
  // 指针字段跟进读宽字符串 / 跨架构读指针(test_ffi.ts 同型)
@@ -70,9 +70,9 @@ export const suite = {
70
70
  t.checkTrue(`default in enum list (${defName})`, names.includes(defName));
71
71
  t.section('DeviceCapabilities: numeric caps on default printer');
72
72
  const defPort = ports[defName] ?? NULL;
73
- const horz = DeviceCapabilities(defName, defPort, 8 /* gui.DeviceCap.HORZRES */, NULL, NULL);
73
+ const horz = DeviceCapabilities(defName, defPort, 8 /* DeviceCap.HORZRES */, NULL, NULL);
74
74
  t.checkTrue(`HORZRES sane (${horz})`, horz > 0);
75
- const vert = DeviceCapabilities(defName, defPort, 10 /* gui.DeviceCap.VERTRES */, NULL, NULL);
75
+ const vert = DeviceCapabilities(defName, defPort, 10 /* DeviceCap.VERTRES */, NULL, NULL);
76
76
  t.checkTrue(`VERTRES sane (${vert})`, vert > 0);
77
77
  t.section('raw job chain on default printer (FILE: port -> .prn file, no UI)');
78
78
  // 输出文件放系统 temp(GetTempPath 尾带反斜杠)——FILE: 端口把作业写到 pOutputFile
@@ -116,7 +116,7 @@ export const suite = {
116
116
  t.checkTrue(`EndDocPrinter (lastError=${GetLastError()})`, ed !== 0);
117
117
  t.checkTrue('ClosePrinter', ClosePrinter(hPrinter) !== 0);
118
118
  // 作业落盘断言:FILE: 端口把 RAW 数据写到 pOutputFile
119
- const hOut = CreateFile(outPrn, 0x80000000 /* GENERIC_READ */, 0, NULL, 3 /* gui.FileCreation.OPEN_EXISTING */, 0, NULL);
119
+ const hOut = CreateFile(outPrn, 0x80000000 /* GENERIC_READ */, 0, NULL, 3 /* FileCreation.OPEN_EXISTING */, 0, NULL);
120
120
  t.checkTrue(`job file exists (${outPrn})`, hOut !== -1);
121
121
  if (hOut !== -1) {
122
122
  const fSize = GetFileSize(hOut, NULL);
@@ -1,5 +1,4 @@
1
1
  import * as ffi from 'ffi'
2
- import * as gui from 'gui'
3
2
  import * as os from 'os'
4
3
  import { WCHAR } from '../lib/ffi/bind.js'
5
4
  import { structArray } from '../lib/ffi/struct.js'
@@ -11,8 +10,9 @@ import {
11
10
  } from '../lib/windows/winspool.js'
12
11
  import { PRINTER_INFO_2W } from '../lib/windows/structs.js'
13
12
  import { Tester } from './test_helper.js'
13
+ import { DeviceCap, FileCreation } from '../constants'
14
14
 
15
- // gui.PrinterEnum.LOCAL(0x2) | CONNECTIONS(0x4):可组合 flags 组合 OR 裸传
15
+ // PrinterEnum.LOCAL(0x2) | CONNECTIONS(0x4):可组合 flags 组合 OR 裸传
16
16
  const LOCAL_OR_CONNECTIONS = 0x6
17
17
  const MAX_WCHARS = 4096
18
18
 
@@ -80,9 +80,9 @@ export const suite = {
80
80
 
81
81
  t.section('DeviceCapabilities: numeric caps on default printer')
82
82
  const defPort = ports[defName] ?? NULL
83
- const horz = DeviceCapabilities(defName, defPort, gui.DeviceCap.HORZRES, NULL, NULL)
83
+ const horz = DeviceCapabilities(defName, defPort, DeviceCap.HORZRES, NULL, NULL)
84
84
  t.checkTrue(`HORZRES sane (${horz})`, horz > 0)
85
- const vert = DeviceCapabilities(defName, defPort, gui.DeviceCap.VERTRES, NULL, NULL)
85
+ const vert = DeviceCapabilities(defName, defPort, DeviceCap.VERTRES, NULL, NULL)
86
86
  t.checkTrue(`VERTRES sane (${vert})`, vert > 0)
87
87
 
88
88
  t.section('raw job chain on default printer (FILE: port -> .prn file, no UI)')
@@ -128,7 +128,7 @@ export const suite = {
128
128
 
129
129
  // 作业落盘断言:FILE: 端口把 RAW 数据写到 pOutputFile
130
130
  const hOut = CreateFile(outPrn, 0x80000000 /* GENERIC_READ */, 0, NULL,
131
- gui.FileCreation.OPEN_EXISTING, 0, NULL)
131
+ FileCreation.OPEN_EXISTING, 0, NULL)
132
132
  t.checkTrue(`job file exists (${outPrn})`, hOut !== -1)
133
133
  if (hOut !== -1) {
134
134
  const fSize = GetFileSize(hOut, NULL)