quickwin 3.0.1 → 3.0.3

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 (163) hide show
  1. package/README.en.md +3 -0
  2. package/README.md +2 -0
  3. package/package.json +2 -3
  4. package/qwin-nowasm-x86.exe +0 -0
  5. package/qwin-nowasm.exe +0 -0
  6. package/qwin-x86.exe +0 -0
  7. package/qwin.exe +0 -0
  8. package/examples/PdfCanvas.js +0 -38
  9. package/examples/PdfCanvas.tsx +0 -54
  10. package/examples/execd/main.js +0 -23379
  11. package/examples/execd/tray.js +0 -192
  12. package/examples/execd/worker.js +0 -122
  13. package/examples/pdf_preview2.js +0 -398
  14. package/examples/pdf_preview2.ts +0 -353
  15. package/examples/pdf_viewer.js +0 -22515
  16. package/examples/pdf_viewer.tsx +0 -228
  17. package/examples/test_gallery.js +0 -18692
  18. package/examples/test_gallery.tsx +0 -291
  19. package/examples/test_react_lazy.js +0 -18560
  20. package/examples/test_react_lazy.tsx +0 -65
  21. package/examples/test_react_listbox.js +0 -18562
  22. package/examples/test_react_listbox.tsx +0 -73
  23. package/examples/test_root_window.js +0 -18532
  24. package/examples/test_root_window.tsx +0 -41
  25. package/examples/test_tab.js +0 -18563
  26. package/examples/test_tab.tsx +0 -77
  27. package/examples/tray_demo.js +0 -86
  28. package/examples/tray_demo.tsx +0 -89
  29. package/test/add.wasm +0 -0
  30. package/test/bench_ffi_callraw.js +0 -235
  31. package/test/bench_ffi_callraw.ts +0 -235
  32. package/test/bench_ffi_overhead.js +0 -139
  33. package/test/bench_ffi_overhead.ts +0 -141
  34. package/test/bench_sendmessage.js +0 -104
  35. package/test/bench_sendmessage.ts +0 -100
  36. package/test/bench_sendmessage_nonnull.js +0 -187
  37. package/test/bench_sendmessage_nonnull.ts +0 -188
  38. package/test/complex.wasm +0 -0
  39. package/test/complex_imports.wasm +0 -0
  40. package/test/debug/http_server_e2e.js +0 -31
  41. package/test/debug/minwasm.js +0 -52
  42. package/test/debug/mupdf_debug.js +0 -86
  43. package/test/debug/wasm.js +0 -122
  44. package/test/debug/wasm_export_debug.js +0 -54
  45. package/test/debug/wasm_names.js +0 -36
  46. package/test/example.pdf +0 -0
  47. package/test/global_imports.wasm +0 -0
  48. package/test/import_func.wasm +0 -0
  49. package/test/imports.wasm +0 -0
  50. package/test/mupdf-cdn.js +0 -40
  51. package/test/mupdf-cdn.ts +0 -43
  52. package/test/run.js +0 -111
  53. package/test/run.ts +0 -116
  54. package/test/sjlj.wasm +0 -0
  55. package/test/test_basic.js +0 -7
  56. package/test/test_basic.ts +0 -9
  57. package/test/test_basic_fetch.js +0 -63
  58. package/test/test_basic_fetch.ts +0 -59
  59. package/test/test_brotli.js +0 -48
  60. package/test/test_brotli.ts +0 -52
  61. package/test/test_fetch_cache.js +0 -169
  62. package/test/test_fetch_cache.ts +0 -187
  63. package/test/test_ffi.js +0 -157
  64. package/test/test_ffi.ts +0 -170
  65. package/test/test_ffi_abi.js +0 -290
  66. package/test/test_ffi_abi.ts +0 -274
  67. package/test/test_ffi_array.js +0 -116
  68. package/test/test_ffi_array.ts +0 -141
  69. package/test/test_ffi_bind.js +0 -656
  70. package/test/test_ffi_bind.ts +0 -670
  71. package/test/test_ffi_struct.js +0 -779
  72. package/test/test_ffi_struct.ts +0 -828
  73. package/test/test_ffi_struct_layout.js +0 -495
  74. package/test/test_ffi_struct_layout.ts +0 -543
  75. package/test/test_ffi_user32.js +0 -103
  76. package/test/test_ffi_user32.ts +0 -113
  77. package/test/test_ffi_windows.js +0 -172
  78. package/test/test_ffi_windows.ts +0 -187
  79. package/test/test_files.js +0 -102
  80. package/test/test_files.ts +0 -121
  81. package/test/test_frame_encoding.js +0 -128
  82. package/test/test_frame_encoding.ts +0 -132
  83. package/test/test_gdi_draw.js +0 -681
  84. package/test/test_gdi_draw.ts +0 -725
  85. package/test/test_helper.js +0 -91
  86. package/test/test_helper.ts +0 -88
  87. package/test/test_http_import.js +0 -96
  88. package/test/test_http_import.ts +0 -93
  89. package/test/test_http_server.js +0 -214
  90. package/test/test_http_server.ts +0 -211
  91. package/test/test_import_dir.js +0 -4
  92. package/test/test_import_dir.ts +0 -5
  93. package/test/test_ipv6.js +0 -134
  94. package/test/test_ipv6.ts +0 -130
  95. package/test/test_jsx.js +0 -1314
  96. package/test/test_meta_url.js +0 -3
  97. package/test/test_meta_url.ts +0 -4
  98. package/test/test_mupdf_render.js +0 -51
  99. package/test/test_mupdf_render.ts +0 -55
  100. package/test/test_mupdf_twice.js +0 -62
  101. package/test/test_mupdf_twice.ts +0 -65
  102. package/test/test_mupdf_wasm.js +0 -39
  103. package/test/test_mupdf_wasm.ts +0 -32
  104. package/test/test_net_event.js +0 -57
  105. package/test/test_net_event.ts +0 -56
  106. package/test/test_net_fetch.js +0 -384
  107. package/test/test_net_fetch.ts +0 -373
  108. package/test/test_net_websocket.js +0 -180
  109. package/test/test_net_websocket.ts +0 -164
  110. package/test/test_polyfill.js +0 -144
  111. package/test/test_polyfill.ts +0 -159
  112. package/test/test_printer.js +0 -137
  113. package/test/test_printer.ts +0 -148
  114. package/test/test_proc.js +0 -141
  115. package/test/test_proc.ts +0 -163
  116. package/test/test_react_complex.js +0 -18678
  117. package/test/test_react_counter.js +0 -18555
  118. package/test/test_react_flex.js +0 -18871
  119. package/test/test_react_hidden.js +0 -18560
  120. package/test/test_react_listview_link.js +0 -18590
  121. package/test/test_react_notify.js +0 -18797
  122. package/test/test_react_render.js +0 -18550
  123. package/test/test_registry.js +0 -74
  124. package/test/test_registry.ts +0 -95
  125. package/test/test_sysinfo.js +0 -122
  126. package/test/test_sysinfo.ts +0 -141
  127. package/test/test_url.js +0 -173
  128. package/test/test_url.ts +0 -183
  129. package/test/test_wasm_basic.js +0 -85
  130. package/test/test_wasm_basic.ts +0 -73
  131. package/test/test_wasm_import_global.js +0 -41
  132. package/test/test_wasm_import_global.ts +0 -45
  133. package/test/test_wasm_sjlj.js +0 -145
  134. package/test/test_wasm_sjlj.ts +0 -125
  135. package/test/test_wasm_types.js +0 -97
  136. package/test/test_wasm_types.ts +0 -124
  137. package/test/test_wolfssl_read.js +0 -203
  138. package/test/test_wolfssl_read.ts +0 -184
  139. package/test/test_worker.js +0 -21
  140. package/test/test_worker.ts +0 -24
  141. package/test/test_worker_concurrent.js +0 -45
  142. package/test/test_worker_concurrent.ts +0 -56
  143. package/test/test_worker_data_url.js +0 -46
  144. package/test/test_worker_data_url.ts +0 -51
  145. package/test/test_worker_fetch.js +0 -26
  146. package/test/test_worker_fetch.ts +0 -27
  147. package/test/test_worker_net.js +0 -69
  148. package/test/test_worker_net.ts +0 -66
  149. package/test/test_worker_wasm_concurrent.js +0 -44
  150. package/test/test_worker_wasm_concurrent.ts +0 -45
  151. package/test/types.wasm +0 -0
  152. package/test/worker_fetch.js +0 -13
  153. package/test/worker_fetch.ts +0 -13
  154. package/test/worker_helper.js +0 -1
  155. package/test/worker_helper.ts +0 -1
  156. package/test/worker_http.js +0 -18
  157. package/test/worker_http.ts +0 -20
  158. package/test/worker_import_lib.js +0 -12
  159. package/test/worker_import_lib.ts +0 -13
  160. package/test/worker_module.js +0 -16
  161. package/test/worker_module.ts +0 -17
  162. package/test/worker_wasm_concurrent.js +0 -22
  163. package/test/worker_wasm_concurrent.ts +0 -22
@@ -1,353 +0,0 @@
1
- import { PtrArrayBuffer, NULL } from '../lib/ffi/ctype.js'
2
- import '../lib/polyfill.js'
3
- import * as std from 'std'
4
- import * as gui from 'gui'
5
- import type { Document, Page, Pixmap } from '@quickwinlabs/mupdf-wasm'
6
- import { MUPDF_JS_URL, preloadMupdfWasm } from '../test/mupdf-cdn.js'
7
- import { assertNonNullable } from '../lib/assert.js'
8
- import { WCHAR } from '../lib/ffi/bind.js'
9
- import { BITMAPINFOHEADER, OPENFILENAMEW, RECT, SCROLLINFO } from '../lib/windows/structs.js'
10
- import { GetOpenFileName } from '../lib/windows/comdlg32.js'
11
- import { GetClientRect, GetDC, GetScrollInfo, GetWindowLongPtr, GetWindowText, GetWindowTextLength, InvalidateRect, MessageBox, PostQuitMessage, ReleaseDC, SetScrollInfo, SetWindowPos, SetWindowLongPtr, SetWindowText, ShowScrollBar, ShowWindow } from '../lib/windows/user32.js'
12
- import { PatBlt, SetDIBitsToDevice } from '../lib/windows/gdi32.js'
13
- import { ColorUse, Gwlp, MouseKeyFlag, ScrollBar, ScrollCmd, ScrollInfoFlag, SetWindowPosFlag, SetWindowPosHwnd, ShowWindowCmd, WindowStyle, WmMsg } from '../constants'
14
-
15
- type MuPdf = typeof import('@quickwinlabs/mupdf-wasm')
16
-
17
- const WHITENESS = 0x00FF0062
18
-
19
- function makeBitmapInfo(w: number, h: number) {
20
- // biHeight 负 = 自顶向下(DIB 原点左上);biCompression 缺省 0 = BI_RGB 无压缩
21
- return BITMAPINFOHEADER.encode({ biSize: BITMAPINFOHEADER.size, biWidth: w, biHeight: -h, biPlanes: 1, biBitCount: 24 })
22
- }
23
-
24
- interface PixmapInfo {
25
- data: PtrArrayBuffer<string>; w: number; h: number
26
- }
27
-
28
- let hwndMain: gui.HWND | null = null
29
- let hwndEdit: gui.HWND | null = null
30
- let hwndCanvas: gui.HWND | null = null
31
- let hwndContent: gui.HWND | null = null
32
- let currentPixmap: PixmapInfo | null = null
33
- let currentPage = 0, totalPages = 0
34
- let scrollX = 0, scrollY = 0
35
-
36
- let cachedPath = ''
37
- let cachedDoc: Document | null = null
38
-
39
- function clearCachedDoc(): void {
40
- if (cachedDoc) { try { cachedDoc.destroy() } catch {} }
41
- cachedDoc = null; cachedPath = ''
42
- }
43
-
44
- async function loadMupdf(): Promise<MuPdf | null> {
45
- try {
46
- await preloadMupdfWasm()
47
- return await import(MUPDF_JS_URL)
48
- } catch (e) {
49
- std.printf('Error: mupdf load failed: %s\n', String(e))
50
- return null
51
- }
52
- }
53
-
54
- function renderPdfPage(mupdf: MuPdf, filePath: string, pageIndex: number): PixmapInfo & { totalPages: number } | null {
55
- if (filePath !== cachedPath) {
56
- clearCachedDoc()
57
- const fp = std.open(filePath, 'rb')
58
- if (!fp) { std.printf('Error: cannot open %s\n', filePath); return null }
59
- let buf: ArrayBuffer | null = null
60
- try {
61
- fp.seek(0, 2); const size = fp.tell(); fp.seek(0, 0)
62
- buf = new ArrayBuffer(size); fp.read(buf, 0, size)
63
- } finally { fp.close() }
64
- if (!buf) return null
65
- try {
66
- cachedDoc = mupdf.Document.openDocument(new Uint8Array(buf), 'application/pdf')
67
- cachedPath = filePath
68
- } catch (e) { std.printf('Error opening document: %s\n', String(e)); return null }
69
- }
70
- if (!cachedDoc) return null
71
- let page: Page | null = null; let pixmap: Pixmap | null = null
72
- try {
73
- page = cachedDoc.loadPage(pageIndex)
74
- pixmap = page.toPixmap(mupdf.Matrix.scale(1.5, 1.5), mupdf.ColorSpace.DeviceRGB, false)
75
- if (!pixmap) return null
76
- const srcPixels = pixmap.getPixels()
77
- const srcStride = pixmap.getStride()
78
- const w = pixmap.getWidth(), h = pixmap.getHeight()
79
- const dibStride = Math.floor((w * 3 + 3) / 4) * 4
80
- const dibBuffer = new PtrArrayBuffer(h * dibStride)
81
- const dib = new Uint8Array(dibBuffer)
82
- for (let y = 0; y < h; y++) {
83
- const srcOff = y * srcStride, dstOff = y * dibStride
84
- for (let x = 0; x < w; x++) {
85
- const sx = srcOff + x * 3, dx = dstOff + x * 3
86
- dib[dx] = srcPixels[sx + 2]!; dib[dx + 1] = srcPixels[sx + 1]!; dib[dx + 2] = srcPixels[sx]!
87
- }
88
- }
89
- const totalPages = cachedDoc.countPages()
90
- return { data: dibBuffer, w, h, totalPages }
91
- } catch (e) { std.printf('Error rendering: %s\n', String(e)); clearCachedDoc(); return null }
92
- finally { if (pixmap) try { pixmap.destroy() } catch {}; if (page) try { page.destroy() } catch {} }
93
- }
94
-
95
- function openPdfFileDialog(): string | null {
96
- assertNonNullable(hwndMain)
97
- const fileBuf = WCHAR.alloc(260)
98
- const filterWide = WCHAR.encode('PDF Files\0*.pdf\0All Files\0*.*\0\0')
99
- // 缺省字段跳过 = fresh buffer 上留 0
100
- const ofn: PtrArrayBuffer<'OPENFILENAMEW'> & { __keep?: ArrayBuffer[] } = OPENFILENAMEW.encode({
101
- lStructSize: OPENFILENAMEW.size,
102
- hwndOwner: hwndMain,
103
- lpstrFilter: filterWide.ptr,
104
- lpstrFile: fileBuf.ptr,
105
- nMaxFile: 260,
106
- Flags: 0x1000 | 0x0800 | 0x0004,
107
- })
108
- ofn.__keep = [fileBuf, filterWide]
109
- const ret = GetOpenFileName(ofn.ptr)
110
- return ret ? WCHAR.decode(fileBuf) : null
111
- }
112
-
113
- function updateScrollRange(): void {
114
- assertNonNullable(hwndCanvas); assertNonNullable(hwndContent)
115
- if (!currentPixmap) return
116
- const crBuf = RECT.alloc()
117
- if (!GetClientRect(hwndCanvas, crBuf.ptr)) return
118
- const { left, top, right, bottom } = RECT.decode(crBuf)
119
- const cw = right - left, ch = bottom - top
120
- const maxX = Math.max(0, currentPixmap.w - cw)
121
- const maxY = Math.max(0, currentPixmap.h - ch)
122
- scrollX = Math.min(scrollX, maxX)
123
- scrollY = Math.min(scrollY, maxY)
124
- if (currentPixmap.w > cw) {
125
- const style = GetWindowLongPtr(hwndCanvas, Gwlp.STYLE)
126
- if (!(style & WindowStyle.HSCROLL)) {
127
- SetWindowLongPtr(hwndCanvas, Gwlp.STYLE, style | WindowStyle.HSCROLL)
128
- SetWindowPos(hwndCanvas, SetWindowPosHwnd.TOP, 0, 0, 0, 0,
129
- SetWindowPosFlag.SWP_NOMOVE | SetWindowPosFlag.SWP_NOSIZE |
130
- SetWindowPosFlag.SWP_NOZORDER | SetWindowPosFlag.SWP_FRAMECHANGED)
131
- }
132
- SetScrollInfo(hwndCanvas, ScrollBar.HORZ, {
133
- cbSize: SCROLLINFO.size, fMask: ScrollInfoFlag.RANGE | ScrollInfoFlag.PAGE | ScrollInfoFlag.POS,
134
- nMin: 0, nMax: currentPixmap.w - 1, nPage: cw, nPos: scrollX,
135
- }, 1)
136
- ShowScrollBar(hwndCanvas, ScrollBar.HORZ, 1)
137
- } else {
138
- scrollX = 0
139
- const style = GetWindowLongPtr(hwndCanvas, Gwlp.STYLE)
140
- if (style & WindowStyle.HSCROLL) {
141
- SetWindowLongPtr(hwndCanvas, Gwlp.STYLE, style & ~WindowStyle.HSCROLL)
142
- SetWindowPos(hwndCanvas, SetWindowPosHwnd.TOP, 0, 0, 0, 0,
143
- SetWindowPosFlag.SWP_NOMOVE | SetWindowPosFlag.SWP_NOSIZE |
144
- SetWindowPosFlag.SWP_NOZORDER | SetWindowPosFlag.SWP_FRAMECHANGED)
145
- }
146
- ShowScrollBar(hwndCanvas, ScrollBar.HORZ, 0)
147
- }
148
- if (currentPixmap.h > ch) {
149
- SetScrollInfo(hwndCanvas, ScrollBar.VERT, {
150
- cbSize: SCROLLINFO.size, fMask: ScrollInfoFlag.RANGE | ScrollInfoFlag.PAGE | ScrollInfoFlag.POS,
151
- nMin: 0, nMax: currentPixmap.h - 1, nPage: ch, nPos: scrollY,
152
- }, 1)
153
- ShowScrollBar(hwndCanvas, ScrollBar.VERT, 1)
154
- } else { scrollY = 0; ShowScrollBar(hwndCanvas, ScrollBar.VERT, 0) }
155
- SetWindowPos(hwndContent, SetWindowPosHwnd.TOP, -scrollX, -scrollY, 0, 0,
156
- SetWindowPosFlag.SWP_NOSIZE | SetWindowPosFlag.SWP_NOZORDER)
157
- }
158
-
159
- function showPdf(mupdf: MuPdf, path: string, pageIdx: number): void {
160
- assertNonNullable(hwndMain); assertNonNullable(hwndContent)
161
- const pix = renderPdfPage(mupdf, path, pageIdx)
162
- if (!pix) { MessageBox(NULL, '渲染 PDF 失败', 'JS Alert', 0); return }
163
- currentPixmap = pix; currentPage = pageIdx; totalPages = pix.totalPages
164
- SetWindowText(hwndMain, 'PDF 预览 - 第 ' + (pageIdx + 1) + '/' + totalPages + ' 页')
165
- scrollX = 0; scrollY = 0
166
- SetWindowPos(hwndContent, SetWindowPosHwnd.TOP, 0, 0, pix.w, pix.h,
167
- SetWindowPosFlag.SWP_NOZORDER | SetWindowPosFlag.SWP_NOMOVE)
168
- updateScrollRange()
169
- InvalidateRect(hwndContent, NULL, 1)
170
- }
171
-
172
- function doScroll(dx: number, dy: number): void {
173
- assertNonNullable(hwndCanvas); assertNonNullable(hwndContent)
174
- const crBuf = RECT.alloc()
175
- if (!GetClientRect(hwndCanvas, crBuf.ptr) || !currentPixmap) return
176
- const { left, top, right, bottom } = RECT.decode(crBuf)
177
- const cw = right - left, ch = bottom - top
178
- const maxX = Math.max(0, currentPixmap.w - cw)
179
- const maxY = Math.max(0, currentPixmap.h - ch)
180
- scrollX = Math.max(0, Math.min(maxX, scrollX + dx))
181
- scrollY = Math.max(0, Math.min(maxY, scrollY + dy))
182
- SetWindowPos(hwndContent, SetWindowPosHwnd.TOP, -scrollX, -scrollY, 0, 0,
183
- SetWindowPosFlag.SWP_NOSIZE | SetWindowPosFlag.SWP_NOZORDER)
184
- SetScrollInfo(hwndCanvas, ScrollBar.HORZ, { cbSize: SCROLLINFO.size, fMask: ScrollInfoFlag.POS, nPos: scrollX }, 1)
185
- SetScrollInfo(hwndCanvas, ScrollBar.VERT, { cbSize: SCROLLINFO.size, fMask: ScrollInfoFlag.POS, nPos: scrollY }, 1)
186
- }
187
-
188
- async function main(): Promise<void> {
189
- const mupdf = await loadMupdf()
190
- if (!mupdf) { MessageBox(NULL, '加载 mupdf WASM 失败', 'JS Alert', 0); return }
191
-
192
- const WS_CHILD = WindowStyle.CHILD
193
- const WS_VIS = WindowStyle.VISIBLE
194
- const WS_BORDER = WindowStyle.BORDER
195
- const ctrlY = 12, ctrlH = 26, gap = 4, btnW = 80, btnPageW = 72
196
-
197
- let hwndBtnOpen: gui.HWND | null = null
198
- let hwndBtnPrev: gui.HWND | null = null
199
- let hwndBtnNext: gui.HWND | null = null
200
-
201
- gui.RegisterClass('PdfViewer2', (hwnd, msg, wParam, lParam) => {
202
- assertNonNullable(hwndCanvas); assertNonNullable(hwndEdit); assertNonNullable(hwndBtnOpen); assertNonNullable(hwndBtnPrev); assertNonNullable(hwndBtnNext)
203
- if (msg === WmMsg.DESTROY) { PostQuitMessage(0); return 0 }
204
- if (msg === WmMsg.SIZE) {
205
- const crBuf = RECT.alloc()
206
- if (GetClientRect(hwnd, crBuf.ptr)) {
207
- const { left, top, right, bottom } = RECT.decode(crBuf)
208
- const cw = right - left, ch = bottom - top
209
- SetWindowPos(hwndCanvas, SetWindowPosHwnd.TOP, 0, 50, cw, Math.max(1, ch - 50), SetWindowPosFlag.SWP_NOZORDER)
210
- SetWindowPos(hwndEdit, SetWindowPosHwnd.TOP, 0, 0, Math.max(100, cw - 320), 0,
211
- SetWindowPosFlag.SWP_NOMOVE | SetWindowPosFlag.SWP_NOZORDER)
212
- }
213
- return gui.DefWindowProc(hwnd, msg, wParam, lParam)
214
- }
215
- if (msg === WmMsg.COMMAND) {
216
- const hCtrl = lParam
217
- if (hCtrl === hwndBtnOpen) {
218
- const path = openPdfFileDialog()
219
- if (path) { SetWindowText(hwndEdit, path); showPdf(mupdf, path, 0) }
220
- } else if (hCtrl === hwndBtnPrev) {
221
- const cap = GetWindowTextLength(hwndEdit) + 1
222
- const buf = WCHAR.alloc(cap)
223
- GetWindowText(hwndEdit, buf, cap)
224
- const path = WCHAR.decode(buf)
225
- if (path && currentPage > 0) showPdf(mupdf, path, currentPage - 1)
226
- } else if (hCtrl === hwndBtnNext) {
227
- const cap = GetWindowTextLength(hwndEdit) + 1
228
- const buf = WCHAR.alloc(cap)
229
- GetWindowText(hwndEdit, buf, cap)
230
- const path = WCHAR.decode(buf)
231
- if (path && currentPage < totalPages - 1) showPdf(mupdf, path, currentPage + 1)
232
- }
233
- return 0
234
- }
235
- return gui.DefWindowProc(hwnd, msg, wParam, lParam)
236
- })
237
- hwndMain = gui.CreateWindow('PdfViewer2', 'PDF 预览 2',
238
- WindowStyle.OVERLAPPEDWINDOW | WindowStyle.CLIPCHILDREN,
239
- 100, 100, 1100, 800, null, null)!
240
- if (!hwndMain) { MessageBox(NULL, '创建主窗口失败', 'JS Alert', 0); return }
241
-
242
- // 控件直接挂在主窗口上
243
- hwndEdit = gui.CreateWindow('EDIT', '',
244
- WS_CHILD | WS_VIS | WS_BORDER,
245
- ctrlY + btnW + gap, ctrlY, 480, ctrlH, hwndMain, null)!
246
- hwndBtnOpen = gui.CreateWindow('BUTTON', '打开 PDF',
247
- WS_CHILD | WS_VIS,
248
- ctrlY, ctrlY, btnW, ctrlH, hwndMain, null)!
249
- hwndBtnPrev = gui.CreateWindow('BUTTON', '上一页',
250
- WS_CHILD | WS_VIS,
251
- ctrlY + btnW + gap + 480 + gap, ctrlY, btnPageW, ctrlH, hwndMain, null)!
252
- hwndBtnNext = gui.CreateWindow('BUTTON', '下一页',
253
- WS_CHILD | WS_VIS,
254
- ctrlY + btnW + gap + 480 + gap + btnPageW + gap, ctrlY, btnPageW, ctrlH, hwndMain, null)!
255
-
256
- // 画布(带滚动条)
257
- hwndCanvas = gui.CreateWindow('STATIC', '',
258
- WS_CHILD | WS_VIS | WindowStyle.CLIPCHILDREN | WindowStyle.VSCROLL | WindowStyle.HSCROLL,
259
- 0, 50, 1100, 750, hwndMain, null)!
260
-
261
- // 内容窗口(画 pixmap)
262
- hwndContent = gui.CreateWindow('STATIC', '',
263
- WS_CHILD | WS_VIS, 0, 0, 100, 100, hwndCanvas, null)!
264
-
265
- assertNonNullable(hwndMain)
266
- assertNonNullable(hwndEdit)
267
- assertNonNullable(hwndCanvas)
268
- assertNonNullable(hwndContent)
269
- assertNonNullable(hwndBtnOpen)
270
- assertNonNullable(hwndBtnPrev)
271
- assertNonNullable(hwndBtnNext)
272
-
273
- // 内容窗口 PAINT
274
- gui.SetWindowProc(hwndContent, (hwnd: gui.HWND, msg: number, wParam: number, lParam: number): number => {
275
- if (msg === WmMsg.ERASEBKGND) return 1
276
- if (msg === WmMsg.PAINT) {
277
- gui.DefWindowProc(hwnd, msg, wParam, lParam)
278
- const pm = currentPixmap
279
- if (!pm) return 0
280
- const hdc = GetDC(hwnd)
281
- if (hdc) {
282
- const bmi = makeBitmapInfo(pm.w, pm.h)
283
- SetDIBitsToDevice(hdc, 0, 0, pm.w, pm.h, 0, 0, 0, pm.h, pm.data, bmi, ColorUse.RGB_COLORS)
284
- ReleaseDC(hwnd, hdc)
285
- }
286
- return 0
287
- }
288
- return gui.DefWindowProc(hwnd, msg, wParam, lParam)
289
- })
290
-
291
- // 画布消息处理(PAINT 填白、滚动条、滚轮)
292
- gui.SetWindowProc(hwndCanvas, (hwnd: gui.HWND, msg: number, wParam: number, lParam: number): number => {
293
- if (msg === WmMsg.ERASEBKGND) return 1
294
- if (msg === WmMsg.PAINT) {
295
- const crBuf = RECT.alloc()
296
- if (GetClientRect(hwnd, crBuf.ptr)) {
297
- const { left, top, right, bottom } = RECT.decode(crBuf)
298
- const cw = right - left, ch = bottom - top
299
- const hdc = GetDC(hwnd)
300
- if (hdc) {
301
- PatBlt(hdc, 0, 0, cw, ch, WHITENESS)
302
- ReleaseDC(hwnd, hdc)
303
- }
304
- }
305
- gui.DefWindowProc(hwnd, msg, wParam, lParam)
306
- return 0
307
- }
308
- if (msg === WmMsg.VSCROLL || msg === WmMsg.HSCROLL) {
309
- const bar = msg === WmMsg.VSCROLL ? ScrollBar.VERT : ScrollBar.HORZ
310
- const si = SCROLLINFO.encode({ cbSize: SCROLLINFO.size, fMask: ScrollInfoFlag.ALL })
311
- GetScrollInfo(hwnd, bar, si.ptr)
312
- const info = SCROLLINFO.decode(si)
313
- const maxPos = info.nMax - info.nPage + 1
314
- const code = wParam & 0xFFFF
315
- let newPos = bar === ScrollBar.VERT ? scrollY : scrollX
316
- if (code === ScrollCmd.THUMBTRACK || code === ScrollCmd.THUMBPOSITION)
317
- newPos = Math.max(0, Math.min(maxPos, (wParam >> 16) & 0xFFFF))
318
- else if (code === ScrollCmd.LINEUP) newPos -= 20
319
- else if (code === ScrollCmd.LINEDOWN) newPos += 20
320
- else if (code === ScrollCmd.PAGEUP) newPos -= info.nPage
321
- else if (code === ScrollCmd.PAGEDOWN) newPos += info.nPage
322
- else return 0
323
- newPos = Math.max(0, Math.min(maxPos, newPos))
324
- if (bar === ScrollBar.VERT) doScroll(0, newPos - scrollY)
325
- else doScroll(newPos - scrollX, 0)
326
- return 0
327
- }
328
- if (msg === WmMsg.MOUSEWHEEL) {
329
- const raw = (wParam >>> 16) & 0xFFFF
330
- const wheel = raw >= 0x8000 ? raw - 0x10000 : raw
331
- const isHorz = (wParam & MouseKeyFlag.MK_SHIFT) !== 0
332
- const bar = isHorz ? ScrollBar.HORZ : ScrollBar.VERT
333
- const si = SCROLLINFO.encode({ cbSize: SCROLLINFO.size, fMask: ScrollInfoFlag.ALL })
334
- GetScrollInfo(hwnd, bar, si.ptr)
335
- const info = SCROLLINFO.decode(si)
336
- const maxPos = info.nMax - info.nPage + 1
337
- let newPos = (isHorz ? scrollX : scrollY) - Math.round(wheel * 40 / 120)
338
- newPos = Math.max(0, Math.min(maxPos, newPos))
339
- if (isHorz) doScroll(newPos - scrollX, 0)
340
- else doScroll(0, newPos - scrollY)
341
- return 0
342
- }
343
- if (msg === WmMsg.SIZE) { updateScrollRange(); return gui.DefWindowProc(hwnd, msg, wParam, lParam) }
344
- return gui.DefWindowProc(hwnd, msg, wParam, lParam)
345
- })
346
-
347
- ShowWindow(hwndMain, ShowWindowCmd.SHOWNORMAL)
348
-
349
- const test = std.open('test/example.pdf', 'rb')
350
- if (test) { test.close(); showPdf(mupdf, 'test/example.pdf', 0) }
351
- }
352
-
353
- main()