Silverfrost Forums

Welcome to our forums

Using %sp and %gp for text window positioning

17 Dec 2014 5:05 #15217

I want to be able to allow the user to move the starting position of a text window (%tx) so that the next time the text window appears, it will be where the user 'left it'.

I tried using %sp and %gp, but the window moves around. I suspect that this is due to the %sp being relative to a parent window. However, I don't have a parent window that contains the text window. I assumed that the coordinates would be relative to the screen itself, but this is clearly not the case.

I must be missing something in the use of the %sp and %gp commands. Can anyone shed light on what I am doing incorrectly, or can suggest a change/addition to achieve the desired effect?

Thanks, Bill

17 Dec 2014 5:52 #15218

Additional info: I removed the %sp command from the %tx and made a call to GET_WINDOW_LOCATION@ (GWL) at time of window closure. The screen onto which the window is being created is 1680x1050. The %tx window appears to be precisely centered on the screen.

Allowing the window to normally create and close yielded the following data.

%gp (x,y) = 1262,315 GWL (x,y,h,w)= 419,250,550,842

Moving the window to the upper left corner of the monitor yields: %gp (x,y)=847,71 GWL (x,y,h,w)= 4,6,550,842

At first blush, it would appear that the %gp is yielding the right side X coordinate (plus some room for the frame), and the bottom of the caption bar (upper edge of the addressable window) as the Y coordinate. The GET_WINDOW_LOCATION@ seems to be yielding the proper values in absolute coordinate space.

If I write the window as 'naked',

%gp (x,y) = 1240,282 GWL (x,y,h,w) = 440,282,486,800

As a naked window, I lost the capability to move it, so this is all I got, but it certainly is revealing, with the X coordinate from %gp being off on the right hand side.

17 Dec 2014 6:46 #15219

I solved this some years ago with lots of help from Paul.

       INTEGER FUNCTION Sticky_Help_FUNCTION()
       IMPLICIT DOUBLE PRECISION (A-H, O-Z)
       INTEGER, EXTERNAL ::  GET_POSITION_FN
       COMMON/PLACE/  IWINDPOS_X(80), IWINDPOS_Y(80)
       COMMON/STICKY/ NPOS, KHAND, JUMPX1,JUMPY1, INFX(10), INFY(10)
       INCLUDE <WINDOWS.INS>
       NSAVE = NPOS
       KSAVE = KHAND
       NPOS  = 2
       IA=WINIO@('%ca[Help routine]&')
       IA=WINIO@('%sp&', IWINDPOS_X(NPOS), IWINDPOS_Y(NPOS))
       IA=WINIO@('%hw%cc&', KHAND, GET_POSITION_FN)
       IA=WINIO@('%ff%nl%rj%8`bt[Close]')
       NPOS  = NSAVE
       KHAND = KSAVE
       QHelp02_FUNCTION = 1
       RETURN
       END

      INTEGER FUNCTION GET_POSITION_FN()
C     ... called on closure control %cc of a sticky window to get final
C         position, so window can be restored there when next opened.
      COMMON  /PLACE/   IWINDPOS_X(80),     IWINDPOS_Y(80)
      COMMON  /STICKY/  NPOS,     KHAND,    JUMPX1,   JUMPY1,           
     &                  INFX(10), INFY(10)
      COMMON  /FOR_NOW/ NSCREEN,  IXSCRN,   IYSCRN
      INCLUDE <WINDOWS.INS>

      CALL GET_WINDOW_LOCATION@ (KHAND, IX, IY, IWID, IHT)
      IF (NPOS .GT. 0 .AND. NPOS .LE. 80) THEN
         IF (IX .GE. 1 .AND. IX .LE. IXSCRN-100) THEN
         IWINDPOS_X(NPOS) = IX
         ELSE
         IWINDPOS_X(NPOS) = 100
         ENDIF
         IF (IY .GE. 1 .AND. IY .LE. IYSCRN-100) THEN
         IWINDPOS_Y(NPOS) = IY
         ELSE
         IWINDPOS_Y(NPOS) = 100 
         ENDIF
      ENDIF
      GET_POSITION_FN = 0                  ! Guarantees continue to exit
      RETURN
      END

The program has 80 windows that when relaunched appear were they were last closed. The routine is No 2 in ths list, so NPOS is set to 2 at startup. The window is positioned with IWINDPOSX and Y. The exchange of handle and window number is done in case a sticky window calls a sticky window, and this works as each is closed. The window handle is KHAND, fond with %hw.

The stuff in GET_POSITION_FN is all about making sure that a sensible position is saved, and the constant offsets are what works for me. It is called when the window closes via %cc.

Hope this helps.

Eddie

PS: I had 1680x1050 on an Acer laptop. Standard setting was large fonts. This is another minefield.

17 Dec 2014 7:47 #15220

Eddie, thanks for the code segment.

I modified the code to use just the GET_WINDOW_LOCATION@ data and it is working fine.

Still begs the question of why the %gp function returns the upper right of the addressable area in a window, though!

A fix is a fix, however, and I am grateful. Bill

18 Dec 2014 4:29 #15223

I only ever used it for 'whole' windows and never for individual controls.

The help file says about the window coordinates:

For main windows the X,Y location is in absolute screen coordinates. For child windows attached by %aw to a frame, the coordinates are relative to the top left corner of the frame. For controls and other child (%ch) windows X and Y are relative to the parent window.

Eddie

18 Dec 2014 5:24 #15225

The %aw was the confusing part, because the %gp returned such a strange value, I figured it was attached to a parent.

All is good now! Bill

Please login to reply.