khchen / wNim

Nim's Windows GUI Framework
MIT License
327 stars 17 forks source link

Cannot compile with nim devel (version 1.9.1) #114

Closed me7 closed 1 year ago

me7 commented 1 year ago

this library cannot compile using nim devel branch (which will become nim 2). How can I compile your lib with devel branch? Or need to wait until library is updated?

image

veksha commented 1 year ago

@khchen @me7 with this diff it compiles. i'm not sure if i done everything correct. all examples compile/work.

Diff ```diff diff --git a/wNim.nim b/wNim.nim index 05afb46..ffb6a05 100644 --- a/wNim.nim +++ b/wNim.nim @@ -143,7 +143,6 @@ ## ---------- ## - `autolayout `_ -{.experimental, deadCodeElim: on.} when not defined(Nimdoc): import diff --git a/wNim/private/controls/wWebView.nim b/wNim/private/controls/wWebView.nim index bd5027f..2015f7c 100644 --- a/wNim/private/controls/wWebView.nim +++ b/wNim/private/controls/wWebView.nim @@ -250,7 +250,7 @@ proc initDispatchVtbl(): ptr IDispatchVtbl = of DISPID_BEFORENAVIGATE2: let win = web.view - url = $args[5].pvarVal.bstrVal + url = $args[5].pvarVal[].bstrVal cancel = args[0].pboolVal event = wWebViewEvent Event(window=win, msg=wEvent_WebViewNavigating) @@ -266,8 +266,8 @@ proc initDispatchVtbl(): ptr IDispatchVtbl = of DISPID_NAVIGATEERROR: let win = web.view - url = $args[3].pvarVal.bstrVal - status = args[1].pvarVal.lVal + url = $args[3].pvarVal[].bstrVal + status = args[1].pvarVal[].lVal cancel = args[0].pboolVal event = wWebViewEvent Event(window=win, msg=wEvent_WebViewError) @@ -866,8 +866,8 @@ proc setHtml*(self: wWebView, html: string) {.validate, property.} = var param: ptr VARIANT SafeArrayAccessData(safeArray, ¶m) - param.vt = VT_BSTR - param.bstrVal = SysAllocString(html) + param[].vt = VT_BSTR + param[].bstrVal = SysAllocString(html) SafeArrayUnaccessData(safeArray) document.write(safeArray) diff --git a/wNim/private/dialogs/wFontDialog.nim b/wNim/private/dialogs/wFontDialog.nim index e9914bb..b60ddfd 100644 --- a/wNim/private/dialogs/wFontDialog.nim +++ b/wNim/private/dialogs/wFontDialog.nim @@ -105,7 +105,7 @@ proc wFontHookProc(hwnd: HWND, msg: UINT, wParam: WPARAM, lParam: LPARAM): UINT_ elif msg == WM_COMMAND: if HIWORD(int32 wParam) == BN_CLICKED and LOWORD(int32 wParam) == 1026: SendMessage(hwnd, WM_CHOOSEFONT_GETLOGFONT, 0, &self.mLf) - self.mChosenFont = Font(&self.mLf) + self.mChosenFont = Font(self.mLf) let event = Event(window=self, msg=wEvent_DialogApply) self.processEvent(event) @@ -135,7 +135,7 @@ proc showModal*(self: wFontDialog): wId {.validate, discardable.} = ## Shows the dialog, returning wIdOk if the user pressed OK, and wIdCancel ## otherwise. if ChooseFont(&self.mCf): - self.mChosenFont = Font(&self.mLf) + self.mChosenFont = Font(self.mLf) result = wIdOk else: result = wIdCancel diff --git a/wNim/private/events/wMoveEvent.nim b/wNim/private/events/wMoveEvent.nim index e98bb55..913974c 100644 --- a/wNim/private/events/wMoveEvent.nim +++ b/wNim/private/events/wMoveEvent.nim @@ -32,7 +32,7 @@ wEventRegister(wMoveEvent): method getPosition*(self: wMoveEvent): wPoint {.property.} = ## Returns the entire size of the window generating the size change event. - if self.mMsg in {WM_MOVE, wEvent_Dragging}: + if self.mMsg in {range[0..65535](WM_MOVE), wEvent_Dragging}: result.x = GET_X_LPARAM(self.mLparam) result.y = GET_Y_LPARAM(self.mLparam) elif self.mMsg == WM_MOVING: diff --git a/wNim/private/pragma.nim b/wNim/private/pragma.nim index 38bd13a..9c90503 100644 --- a/wNim/private/pragma.nim +++ b/wNim/private/pragma.nim @@ -5,7 +5,7 @@ # #==================================================================== -{.experimental, deadCodeElim: on.} +{.experimental: "dotOperators".} {.warning[LockLevel]: off.} diff --git a/wNim/private/wMacros.nim b/wNim/private/wMacros.nim index 8ad482d..885500f 100644 --- a/wNim/private/wMacros.nim +++ b/wNim/private/wMacros.nim @@ -279,7 +279,13 @@ macro wEventRegister*(event, list: untyped): untyped = wEventStorage($event, cint msg[1].intVal()) of nnkIdent: - wEventStorage($event, cint bindSym(msg[1]).getImpl().intVal()) + #wEventStorage($event, cint bindSym(msg[1]).getImpl().intVal()) + #wEventStorage($event, cint bindSym(msg[1]).getImpl()[2].intVal()) + let eventInt = if bindSym(msg[1]).getImpl().kind == nnkConstDef: + cint bindSym(msg[1]).getImpl()[2].intVal() + else: + cint bindSym(msg[1]).getImpl().intVal() + wEventStorage($event, eventInt) else: error("Unexpected a node of kind " & $msg[1].kind, msg[1]) diff --git a/wNim/private/wPrintData.nim b/wNim/private/wPrintData.nim index 61cf137..cc3f314 100644 --- a/wNim/private/wPrintData.nim +++ b/wNim/private/wPrintData.nim @@ -256,7 +256,7 @@ proc getPaper*(self: wPrintData): wPaper {.validate, property, inline.} = result = wPaperA4 if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - result = cast[wPaper](pDevMode.dmPaperSize) + result = cast[wPaper](pDevMode[].dmPaperSize) proc getPaperName*(self: wPrintData): string {.validate, property, inline.} = ## Returns the paper name, if any. @@ -270,7 +270,7 @@ proc getPaperSize*(self: wPrintData): wSize {.validate, property, inline.} = let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) # some printer driver returned wrong value, we fix it here - if pDevMode.dmPaperSize != 0: + if pDevMode[].dmPaperSize != 0: let n = DeviceCapabilities(self.mDevice, nil, DC_PAPERS, nil, nil) if n != 0: var papers = newSeq[int16](n) @@ -279,89 +279,89 @@ proc getPaperSize*(self: wPrintData): wSize {.validate, property, inline.} = DeviceCapabilities(self.mDevice, nil, DC_PAPERSIZE, cast[LPTSTR](&(paperSizes[0])), nil) for i, id in papers: - if id == pDevMode.dmPaperSize: - pDevMode.dmPaperWidth = int16 paperSizes[i].x - pDevMode.dmPaperLength = int16 paperSizes[i].y + if id == pDevMode[].dmPaperSize: + pDevMode[].dmPaperWidth = int16 paperSizes[i].x + pDevMode[].dmPaperLength = int16 paperSizes[i].y break - result.width = int round(pDevMode.dmPaperWidth.float / 10) - result.height = int round(pDevMode.dmPaperLength.float / 10) + result.width = int round(pDevMode[].dmPaperWidth.float / 10) + result.height = int round(pDevMode[].dmPaperLength.float / 10) proc getOrientation*(self: wPrintData): wOrientation {.validate, property, inline.} = ## Gets the orientation. result = wPortrait if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - result = wOrientation pDevMode.dmOrientation + result = wOrientation pDevMode[].dmOrientation proc getCopies*(self: wPrintData): int {.validate, property, inline.} = ## Returns the number of copies. if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - result = int pDevMode.dmCopies + result = int pDevMode[].dmCopies proc getCollate*(self: wPrintData): bool {.validate, property, inline.} = ## Returns true if collation is on. if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - result = pDevMode.dmCollate != DMCOLLATE_FALSE + result = pDevMode[].dmCollate != DMCOLLATE_FALSE proc getColor*(self: wPrintData): bool {.validate, property, inline.} = ## Returns true if colour printing is on. if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - result = pDevMode.dmColor == DMCOLOR_COLOR + result = pDevMode[].dmColor == DMCOLOR_COLOR proc getDuplex*(self: wPrintData): wDuplexMode {.validate, property, inline.} = ## Returns the duplex mode. result = wDuplexSimplex if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - result = wDuplexMode pDevMode.dmDuplex + result = wDuplexMode pDevMode[].dmDuplex proc setPaper*(self: wPrintData, paper: wPaper) {.validate, property, inline.} = ## Sets the paper kind. if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - pDevMode.dmPaperSize = int16 paper - pDevMode.dmFields = (pDevMode.dmFields or DM_PAPERSIZE) and + pDevMode[].dmPaperSize = int16 paper + pDevMode[].dmFields = (pDevMode[].dmFields or DM_PAPERSIZE) and (not (DM_PAPERLENGTH or DM_PAPERWIDTH)) proc setPaperSize*(self: wPrintData, size: wSize) {.validate, property, inline.} = ## Sets the custom paper size, in millimetres. if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - pDevMode.dmPaperWidth = int16 size.width * 10 - pDevMode.dmPaperLength = int16 size.height * 10 - pDevMode.dmPaperSize = DMPAPER_USER - pDevMode.dmFields = (pDevMode.dmFields or DM_PAPERLENGTH or DM_PAPERWIDTH or DM_PAPERSIZE) + pDevMode[].dmPaperWidth = int16 size.width * 10 + pDevMode[].dmPaperLength = int16 size.height * 10 + pDevMode[].dmPaperSize = DMPAPER_USER + pDevMode[].dmFields = (pDevMode[].dmFields or DM_PAPERLENGTH or DM_PAPERWIDTH or DM_PAPERSIZE) proc setOrientation*(self: wPrintData, orientation: wOrientation) {.validate, property, inline.} = ## Sets the orientation. This can be wLandscape or wPortrait. if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - pDevMode.dmOrientation = int16 orientation - pDevMode.dmFields = pDevMode.dmFields or DM_ORIENTATION + pDevMode[].dmOrientation = int16 orientation + pDevMode[].dmFields = pDevMode[].dmFields or DM_ORIENTATION proc setCopies*(self: wPrintData, copies: int) {.validate, property, inline.} = ## Sets the copies. if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - pDevMode.dmCopies = int16 copies - pDevMode.dmFields = pDevMode.dmFields or DM_COPIES + pDevMode[].dmCopies = int16 copies + pDevMode[].dmFields = pDevMode[].dmFields or DM_COPIES proc setColor*(self: wPrintData, flag: bool) {.validate, property, inline.} = ## Sets color printing on or off. if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - pDevMode.dmColor = if flag: DMCOLOR_COLOR else: DMCOLOR_MONOCHROME - pDevMode.dmFields = pDevMode.dmFields or DM_COLOR + pDevMode[].dmColor = if flag: DMCOLOR_COLOR else: DMCOLOR_MONOCHROME + pDevMode[].dmFields = pDevMode[].dmFields or DM_COLOR proc setDuplex*(self: wPrintData, mode: wDuplexMode) {.validate, property, inline.} = ## Sets the duplex mode. This can be wDuplexSimplex, wDuplexVertical, ## or wDuplexHorizontal. if self.isOk(): let pDevMode = cast[ptr DEVMODE](&self.mDevModeBuffer) - pDevMode.dmDuplex = int16 mode - pDevMode.dmFields = pDevMode.dmFields or DM_DUPLEX + pDevMode[].dmDuplex = int16 mode + pDevMode[].dmFields = pDevMode[].dmFields or DM_DUPLEX diff --git a/wNim/private/wWindow.nim b/wNim/private/wWindow.nim index 7e5ffd0..5c43a37 100644 --- a/wNim/private/wWindow.nim +++ b/wNim/private/wWindow.nim @@ -638,7 +638,7 @@ proc refresh*(self: wWindow, eraseBackground = true, rect: wRect) {.validate, in var r = rect.toRECT() InvalidateRect(self.mHwnd, r, eraseBackground) -method show*(self: wWindow, flag = true) {.base, inline.} = +method show*(self: wWindow, flag = true) {.inline.} = ## Shows or hides the window. ShowWindow(self.mHwnd, if flag: SW_SHOWNORMAL else: SW_HIDE) @@ -1257,7 +1257,7 @@ proc processEvent*(self: wWindow, event: wEvent): bool {.validate, discardable.} # so we don't break even the event is processed # notice: use list instead of seq here, # because handler may modify list by disconnect - for node in list.nodes: # FIFO + for node in list[].nodes: # FIFO let connection = node.value connection.callHandler() @@ -1267,7 +1267,7 @@ proc processEvent*(self: wWindow, event: wEvent): bool {.validate, discardable.} var this = self while true: this.mConnectionTable.withValue(msg, list): - for node in list.rnodes: # FILO + for node in list[].rnodes: # FILO let connection = node.value # make sure we clear the skip state before every callHandler event.mSkip = false @@ -1480,9 +1480,9 @@ proc disconnect*(self: wWindow, msg: UINT, limit = -1) {.validate.} = ## Disconnects the given event type from the event handler. var count = 0 self.mConnectionTable.withValue(msg, list): - for node in list.rnodes: + for node in list[].rnodes: if not node.value.undeletable: - list.remove(node) + list[].remove(node) wAppDecMessage(msg) count.inc if limit >= 0 and count >= limit: break @@ -1492,9 +1492,9 @@ proc disconnect*(self: wWindow, msg: UINT, id: wCommandID, limit = -1) ## Disconnects the given event type and specified ID from the event handler. var count = 0 self.mConnectionTable.withValue(msg, list): - for node in list.rnodes: + for node in list[].rnodes: if node.value.id == id and not node.value.undeletable: - list.remove(node) + list[].remove(node) wAppDecMessage(msg) count.inc if limit >= 0 and count >= limit: break @@ -1506,26 +1506,26 @@ proc disconnect*(self: wWindow, id: wCommandID, limit = -1) {.validate.} = proc disconnect*(self: wWindow, msg: UINT, handler: wEventProc) {.validate.} = ## Disconnects the specified handler proc from the event handler. self.mConnectionTable.withValue(msg, list): - for node in list.nodes: + for node in list[].nodes: if node.value.handler.rawProc == handler.rawProc and not node.value.undeletable: - list.remove(node) + list[].remove(node) wAppDecMessage(msg) proc disconnect*(self: wWindow, msg: UINT, handler: wEventNeatProc) {.validate.} = ## Disconnects the specified handler proc from the event handler. self.mConnectionTable.withValue(msg, list): - for node in list.nodes: + for node in list[].nodes: if node.value.neatHandler.rawProc == handler.rawProc and not node.value.undeletable: - list.remove(node) + list[].remove(node) wAppDecMessage(msg) proc disconnect*(self: wWindow, connection: wEventConnection) = ## Disconnects the specified token that returned by connect(). let msg = connection.msg self.mConnectionTable.withValue(msg, list): - for node in list.nodes: + for node in list[].nodes: if node.value == connection: - list.remove(node) + list[].remove(node) wAppDecMessage(msg) proc systemDisconnect(self: wWindow, connection: wEventConnection) {.validate, shield.} = @@ -1533,17 +1533,17 @@ proc systemDisconnect(self: wWindow, connection: wEventConnection) {.validate, s # systemConnect(). let msg = connection.msg self.mSystemConnectionTable.withValue(msg, list): - for node in list.nodes: + for node in list[].nodes: if node.value == connection: - list.remove(node) + list[].remove(node) wAppDecMessage(msg) proc systemDisconnect(self: wWindow, msg: UINT, handler: wEventProc) {.validate.} = # Used internally, disconnects the specified connection. self.mSystemConnectionTable.withValue(msg, list): - for node in list.nodes: + for node in list[].nodes: if node.value.handler.rawProc == handler.rawProc: - list.remove(node) + list[].remove(node) wAppDecMessage(msg) proc `.`*(self: wWindow, msg: UINT, handler: wEventProc): wEventConnection ```
me7 commented 1 year ago

@veksha Thank you very much 😊 with the changes it's compile succesfully

khchen commented 1 year ago

Fixed