From 11eaef5f25bf9e76da521a030f8b17a77ed22a50 Mon Sep 17 00:00:00 2001
From: Ben Avison <bavison@gitlab.riscosopen.org>
Date: Fri, 27 Nov 1998 20:56:19 +0000
Subject: [PATCH] Another bugfix to and a new feature of NC error box code:

* If pointer was hidden-until-next-mouse-move, the act of confining the mouse
  to the error box window no longer causes it to be redisplayed.
* In error boxes, the pointer and the IconHigh highlight are now initially
  positioned over the rightmost (default) button. There is one exception to
  this rule: when "Next task" is clicked in a Watchdog window, the pointer
  stays over the "Next task" button.

Version 4.13. Tagged as 'Wimp-4_13'
---
 VersionASM |  6 +++---
 VersionNum | 12 ++++++------
 s/Watchdog |  5 +++++
 s/Wimp01   |  2 ++
 s/Wimp02   |  2 ++
 s/Wimp04   | 14 ++++++++++++++
 s/Wimp07   | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 7 files changed, 84 insertions(+), 10 deletions(-)

diff --git a/VersionASM b/VersionASM
index b255f0a..b1546d7 100644
--- a/VersionASM
+++ b/VersionASM
@@ -5,8 +5,8 @@
 			GBLA    Module_Version
 			GBLS	Module_MinorVersion
 			GBLS	Module_Date
-Module_MajorVersion	SETS    "4.12"
-Module_Version          SETA    412
+Module_MajorVersion	SETS    "4.13"
+Module_Version          SETA    413
 Module_MinorVersion	SETS	""
-Module_Date		SETS    "26 Nov 1998"
+Module_Date		SETS    "27 Nov 1998"
 		        END
diff --git a/VersionNum b/VersionNum
index 0649c0b..3d27861 100644
--- a/VersionNum
+++ b/VersionNum
@@ -1,14 +1,14 @@
-/* (4.12)
+/* (4.13)
  *
  * This file is automatically maintained by srccommit, do not edit manually.
  *
  */
-#define Module_MajorVersion_CMHG     	4.12
+#define Module_MajorVersion_CMHG     	4.13
 #define Module_MinorVersion_CMHG	
-#define Module_Date_CMHG      		26 Nov 1998
+#define Module_Date_CMHG      		27 Nov 1998
 
-#define Module_MajorVersion     	"4.12"
-#define Module_Version                  412
+#define Module_MajorVersion     	"4.13"
+#define Module_Version                  413
 #define Module_MinorVersion		""
-#define Module_Date      		"26 Nov 1998"
+#define Module_Date      		"27 Nov 1998"
 
diff --git a/s/Watchdog b/s/Watchdog
index adc71e3..f00b899 100644
--- a/s/Watchdog
+++ b/s/Watchdog
@@ -172,6 +172,11 @@ taskloop
         ADR     R0,watchdogcallback
         MOV     R1,R12
         SWI     XOS_AddCallBack
+      [ NCErrorBox
+        ADRL    R1, ptrpreserveflag
+        MOV     R0, #1
+        STR     R0, [R1]                         ; note not to move the pointer
+      ]
         Pull    "R0-R7,PC"
 watchdognext
         CMP     R1,#3                            ; kill
diff --git a/s/Wimp01 b/s/Wimp01
index 61cf40f..981a3ef 100644
--- a/s/Wimp01
+++ b/s/Wimp01
@@ -1459,6 +1459,8 @@ ptrsuspenddata  #       12              ; To store x,y,b last generated by IconH
 ptrsuspendflag  #       4               ; 0 => normal
                                         ; 1 => waiting for mouse move generated by IconHigh
                                         ; 2 => waiting for next mouse move *not* generated by IconHigh
+ptrpreserveflag #       4               ; 0 => position pointer over default error button on box start
+                                        ; 1 => don't move pointer on box start
               ]
 
 maxwork         *       :INDEX:@
diff --git a/s/Wimp02 b/s/Wimp02
index 28e0c8a..74298b3 100644
--- a/s/Wimp02
+++ b/s/Wimp02
@@ -2868,6 +2868,8 @@ inittasks
       ]
       [ NCErrorBox
         ADRL    R14, ptrsuspendflag
+        STR     R0, [R14], #4
+        ASSERT  ptrpreserveflag = ptrsuspendflag + 4
         STR     R0, [R14]
       ]
 ;
diff --git a/s/Wimp04 b/s/Wimp04
index d20514a..67edd55 100644
--- a/s/Wimp04
+++ b/s/Wimp04
@@ -4800,6 +4800,20 @@ pointerwindow
         strw    y1,R1,7
         MOV     R0,#&15
         SWI     XOS_Word                    ; OSWORD &15
+      [ NCErrorBox
+        ; If confining the mouse causes it to change position,
+        ; we *don't* want to trigger the reappearance of the pointer
+        ADRL    y1, ptrsuspendflag
+        LDR     x1, [y1]
+        TEQ     x1, #2                  ; waiting for a mouse move?
+        Push    "R2", EQ                ; if so then flush the mouse buffer
+        MOVEQ   R0, #21                 ;   (maybe a bit dodgy, but it's the only way
+        MOVEQ   R1, #Buff_Mouse         ;   to ensure that the next read from the
+        SWIEQ   OS_Byte                 ;   mouse buffer was due to the OS_Word call,
+        Pull    "R2", EQ                ;   which doesn't in itself flush the buffer)
+        MOVEQ   x1, #1                  ; and then flag to ignore the next mouse read
+        STREQ   x1, [y1]
+      ]
 ;
         Pull    "R0,R1,x1,y1,PC"
         LTORG
diff --git a/s/Wimp07 b/s/Wimp07
index 0543230..3cebde5 100644
--- a/s/Wimp07
+++ b/s/Wimp07
@@ -1885,6 +1885,12 @@ ReportError_restored_font_colours
         Pull    "r0-r3"
         ]
 
+      [ NCErrorBox
+        ADRL    R14, ptrpreserveflag
+        MOV     R0, #0
+        STR     R0, [R14]               ; move the pointer the next time the error box is opened
+      ]
+
         MOV     R0, #220                ; restore the old escape key
         LDRB    R1, old_escape
         MOV     R2, #0
@@ -1910,6 +1916,11 @@ notoveryet
         STR     R1,tempworkspace+errtws_icondata
         LDR     R1,tempworkspace+errtws_describebuttons  ; Get back buttons
         STR     R1,tempworkspace+errtws_buttonlist
+      [ false
+        ADRL    R5, ptrpreserveflag
+        MOV     R4, #1
+        STR     R4, [R5]                ; note not to move the pointer
+      ]
         ADRL    R1,progerrsaveblk
         LDMIA   R1,{R4-R7}
         MOV     userblk,R5
@@ -2843,7 +2854,47 @@ donegetr
         BL      flushkbdmouse           ; get ready to read these
 ;
       [ NCErrorBox
-        MOV     R0, #106
+        ADRL    R0, ptrpreserveflag
+        LDR     R0, [R0]
+        TEQ     R0, #0                  ; Should we move the pointer over the default action button?
+        BNE     %FT01
+
+        Push    "cx0-y0"
+        LDR     R14, errorhandle
+        Abs     R14, R14
+
+        LDR     cx0, [R14, #w_wax1]
+        SUB     cx0, cx0, #20           ; 20 OS unit border
+        LDR     cx1, errbut_w_def
+        SUB     cx0, cx0, cx1, ASR #1   ; screen x of icon centre
+
+        LDR     cy1, [R14, #w_way1]
+        LDR     y0, [R14, #w_scy]
+        SUB     y0, cy1, y0             ; screen y of wao
+        LDR     cy0, errbut_y0_def
+        LDR     cy1, errbut_y1_def
+        ADD     cy0, cy0, cy1
+        ADD     cy0, y0, cy0, ASR #1    ; screen y of icon centre
+
+        SUB     sp, sp, #8
+        MOV     R1, sp
+        MOV     R0, #3
+        STRB    R0, [R1]
+        strw    cx0, R1, 1
+        strw    cy0, R1, 3
+        MOV     R0, #&15
+        SWI     XOS_Word                ; Set mouse position
+        ADD     sp, sp, #8
+
+        ADRL    R0, ptrsuspendflag      ; Update our copy of the coords
+        LDR     R1, [R0]                ; because IconHigh reads the mouse
+        TEQ     R1, #2                  ; position using Wimp_GetPointerInfo!
+        MOVEQ   R1, #1                  ; If pointer is currently hidden
+        STREQ   R1, [R0]                ; until the next mouse move, remember
+        BL      getmouseposn            ; to discount next mouse read.
+        Pull    "cx0-y0"
+
+01      MOV     R0, #106
         MOV     R1, #0
         SWI     XOS_Byte                ; Read current pointer number (also turns it off, but we'll soon switch it back)
         ADRL    R14, ptrshlflag
-- 
GitLab