PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Anonymous on April 09, 2006, 09:19:12 AM

Title: Editable list view with cursor row fixed to centre
Post by: Anonymous on April 09, 2006, 09:19:12 AM
I am currently designing an App in Firefly, but i have come accross a problem with the pattern view.
I require a list view that scrolls up/down the display rather than the cursor. The cursor should remain on the centre row, but allow it to move left and right.
Does anyone have any ideas what control to use?

An example of what i mean is here...
http://en.wikipedia.org/wiki/Tracker
Title: Editable list view with cursor row fixed to centre
Post by: Elias Montoya on April 11, 2006, 09:33:59 PM
That would be very easy with Egrid32. :)
Title: Editable list view with cursor row fixed to centre
Post by: Anonymous on April 12, 2006, 05:19:13 PM
Thanks for reply Elias,
Would it be simple enough to give me an example?
Title: Editable list view with cursor row fixed to centre
Post by: Elias Montoya on April 13, 2006, 02:12:42 AM
Sure... Here is the code. The code points to FORM1 and EGRID321.
It will fail if you create another form or another grid. But the code is fairly
easy to modify to point to another form and grid.

Paul is there an option to do this in firefly?

Important:
This example requires Egrid32 3.21.08, if you dont have it
you can get it here:
http://www.sweetheartgames.com/EGRID32PRODEMO.zip


'------------------------------------------------------------------------------------------------------------------------
' This function Retrieves the number of row that is in the middle of the grid.
FUNCTION GetMiddleRow(Hegrid AS DWORD) AS LONG
LOCAL RC AS RECT
LOCAL Y AS LONG      
GETCLIENTRECT(Hegrid, RC)
Y = ((RC.NBOTTOM-RC.NTOP)/2)
FUNCTION = SENDMESSAGE(Hegrid, %EG_YFROMPOINT, y, Y)
END FUNCTION

'------------------------------------------------------------------------------------------------------------------------
'Returns TRUE if the current selection is below the center.
FUNCTION Belowcenter(Hegrid AS DWORD) AS LONG
LOCAL RC  AS RECT
LOCAL CRC AS RECT                      
GETCLIENTRECT(Hegrid, RC)
SENDMESSAGE(Hegrid, %EG_INTERNALSELECTTL, 1, SENDMESSAGE(Hegrid, %EG_GETFOCUSEDCELLY, 0, 0))                                                
SENDMESSAGE(Hegrid, %EG_GETCELLRECT, VARPTR(CRC), 0)
FUNCTION = (((RC.NBOTTOM-RC.NTOP)/2) < CRC.NTOP)
END FUNCTION

'------------------------------------------------------------------------------------------------------------------------
'Returns TRUE if the current selection is above the center.
FUNCTION Abovecenter(Hegrid AS DWORD) AS LONG
LOCAL RC  AS RECT
LOCAL CRC AS RECT                      
GETCLIENTRECT(Hegrid, RC)
SENDMESSAGE(Hegrid, %EG_INTERNALSELECTTL, 1, SENDMESSAGE(Hegrid, %EG_GETFOCUSEDCELLY, 0, 0))                                                
SENDMESSAGE(Hegrid, %EG_GETCELLRECT, VARPTR(CRC), 0)
FUNCTION = (((RC.NBOTTOM-RC.NTOP)/2) > CRC.Nbottom)
END FUNCTION

'------------------------------------------------------------------------------------------------------------------------
' Initially  Select the middle row, and load some sample strings.
FUNCTION FORM1_EGRID321_EGN_AFTERPROPERTIES (ControlIndex AS DWORD, HwndForm AS DWORD, hEGrid AS LONG, wParam AS DWORD, lParam AS LONG) AS LONG
CALL SENDMESSAGE(Hegrid, %EG_SELECTFULLROW, GetMiddleRow(Hegrid), 0)  
DIM Rows(SENDMESSAGE(Hegrid, %EG_GETMAXROWS, 0, 0)) AS STRING
LOCAL Index AS LONG
FOR Index = 0 TO UBOUND(Rows())
 Rows(Index) = "Sample Text" & $TAB & "  Row #" & FORMAT$(Index) & $TAB & "More items"
NEXT Index
SENDMESSAGE Hegrid, %EG_INTERNALSELECTUD, 1, SENDMESSAGE(Hegrid, %EG_GETMAXROWS, 0, 0)
SENDMESSAGE Hegrid, %EG_LOADARRAY, VARPTR(Rows(0)), UBOUND(Rows())+1
SENDMESSAGE hEGrid, %EG_REFRESHALL, 0, 0  
END FUNCTION

'------------------------------------------------------------------------------------------------------------------------
FUNCTION FORM1_EGRID321_EGN_KEYDOWN (ControlIndex AS DWORD, HwndForm AS DWORD, hEGrid AS LONG, wParam AS DWORD, lParam AS LONG) AS LONG

LOCAL EGN AS EgridNotify PTR
LOCAL SI  AS SCROLLINFO
                           
EGN = LPARAM
SENDMESSAGE(Hegrid, %EG_GETVSCROLLBAR, VARPTR(SI), 0)

SELECT CASE @EGN.KEY
CASE %VK_UP   ' Proces manually the UP arrow keypress.
   IF @EGN.CELL.Y > 1 THEN
    IF ((SI.NPOS+SI.NPAGE)-1) => SENDMESSAGE(Hegrid, %EG_GETMAXROWS, 0, 0) THEN    
      SENDMESSAGE Hegrid, %EG_MOVECURSORUP, 0, 0
      IF AboveCenter(Hegrid) THEN
       SENDMESSAGE Hegrid, %EG_MOVESCREENUP, 0, 0                                
      ELSE        
       CALL SENDMESSAGE(Hegrid, %EG_SELECTFULLROW,  @EGN.CELL.Y-1, 0)                                
      END IF
    ELSE
     IF SI.NPOS = 1 THEN
      SENDMESSAGE Hegrid, %EG_MOVECURSORUP, 0, 0
      CALL SENDMESSAGE(Hegrid, %EG_SELECTFULLROW,  @EGN.CELL.Y-1, 0)
     ELSE
      SENDMESSAGE Hegrid, %EG_MOVESCREENUP, 0, 0      
     END IF
    END IF
    FUNCTION = %TRUE ' Ask Egrid to ignore next system action (it would overwrite the selection we just made)    
   END IF
 
CASE %VK_DOWN ' Proces manually the DOWN arrow keypress.
    IF @EGN.CELL.Y < SENDMESSAGE(Hegrid, %EG_GETMAXROWS, 0, 0) THEN
     IF SI.NPOS = 1 THEN
       SENDMESSAGE Hegrid, %EG_MOVECURSORDOWN, 0, 0
       IF Belowcenter(Hegrid) THEN
        SENDMESSAGE Hegrid, %EG_MOVESCREENDOWN, 0, 0                                
       ELSE        
        CALL SENDMESSAGE(Hegrid, %EG_SELECTFULLROW,  @EGN.CELL.Y+1, 0)                                
       END IF
     ELSE
      IF ((SI.NPOS+SI.NPAGE)-1) => SENDMESSAGE(Hegrid, %EG_GETMAXROWS, 0, 0) THEN
       SENDMESSAGE Hegrid, %EG_MOVECURSORDOWN, 0, 0
       CALL SENDMESSAGE(Hegrid, %EG_SELECTFULLROW,  @EGN.CELL.Y+1, 0)
      ELSE
       SENDMESSAGE Hegrid, %EG_MOVESCREENDOWN, 0, 0      
      END IF
     END IF
    FUNCTION = %TRUE ' Ask Egrid to ignore next system action (it would overwrite the selection we just made)    
   END IF  
   
CASE ELSE
   ' Ask egrid32 to not process any other keys.
   FUNCTION = %TRUE
   EXIT FUNCTION
END SELECT

END FUNCTION

'------------------------------------------------------------------------------------------------------------------------
FUNCTION FORM1_EGRID321_EGN_MOVEMENTINPIXELS (ControlIndex AS DWORD, HwndForm AS DWORD, hEGrid AS LONG, wParam AS DWORD, lParam AS LONG) AS LONG
CALL SENDMESSAGE(Hegrid, %EG_SELECTFULLROW, GetMiddleRow(Hegrid), 0)
CALL SENDMESSAGE(Hegrid, %EG_REFRESHALL, 0, 0)
END FUNCTION


'------------------------------------------------------------------------------------------------------------------------
FUNCTION FORM1_WM_CREATE ( _
                        hWndForm AS DWORD, _  ' handle of Form
                        BYVAL UserData AS LONG _  'optional user defined Long value
                        ) AS LONG

' Checks the Egrid32 Version in use to be the correct one.                        

IF VAL(REMOVE$(UCASE$(Grid_Version()), ANY "VERSION .")) < 32108 THEN
Local lResult As Long
lResult = MESSAGEBOX(hWndForm, BYCOPY "This example requires Egrid32 PRO version 3.21.08 or later." & $CRLF & _
            "Please get the newest version to run this example." & $CrLf, _
            ByCopy "Warning", _
            %MB_OK OR %MB_DEFBUTTON1 OR %MB_ICONWARNING OR %MB_TASKMODAL)
POSTMESSAGE HWndForm, %WM_CLOSE, 0, 0
END IF
END FUNCTION

'------------------------------------------------------------------------------------------------------------------------
FUNCTION FORM1_EGRID321_EGN_CELLLEFTCLICK (ControlIndex AS DWORD, HwndForm AS DWORD, hEGrid AS LONG, wParam AS DWORD, lParam AS LONG) AS LONG
LOCAL EGN AS EgridNotify PTR
EGN = LPARAM
CALL SENDMESSAGE(Hegrid, %EG_SELECTFULLROW, @EGN.CELL.Y, 0)
CALL SENDMESSAGE(Hegrid, %EG_REFRESHALL, 0, 0)
FUNCTION = %TRUE
END FUNCTION
           
'------------------------------------------------------------------------------------------------------------------------
FUNCTION FORM1_EGRID321_EGN_CELLRIGHTCLICK (ControlIndex AS DWORD, HwndForm AS DWORD, hEGrid AS LONG, wParam AS DWORD, lParam AS LONG) AS LONG
LOCAL EGN AS EgridNotify PTR
EGN = LPARAM
CALL SENDMESSAGE(Hegrid, %EG_SELECTFULLROW, @EGN.CELL.Y, 0)
CALL SENDMESSAGE(Hegrid, %EG_REFRESHALL, 0, 0)
FUNCTION = %TRUE
END FUNCTION


The code can still be tweaked to have even more custom behaviour. FAR EASIER than doing it with a listview. Enjoy. :)
Title: Editable list view with cursor row fixed to centre
Post by: Anonymous on April 14, 2006, 07:40:13 AM
The files you linked to contains "EGRID32PRO.INC   v3.20.06"
not v3.21.08.
Tried running and failed because of undefined equate
%EG_GETFOCUSEDCELLY
Title: Editable list view with cursor row fixed to centre
Post by: Marc Van Cauwenberghe on April 14, 2006, 12:27:17 PM
Hello twilighte1,

I just downloaded the egrid32prodemo.zip and it seems to be OK. If Elias referres to version 3.21.08 it means that the dll version should be of the version. The include file *.INC could be of a different version (lower) because there could be changes to the dll which do not need a change in the *.INC file.
If you are using FireFly and I think you are, please check that you have replaced the dll and inc in the customcontrol folder under the FireFly folder with the latest version.

Regards,
Marc
Title: Editable list view with cursor row fixed to centre
Post by: Elias Montoya on April 14, 2006, 05:13:05 PM
Exactly what marc said. I think it will be a good idea to add a little
explanation like this in the INC header.

:)

Note:
Also replace the dll and the inc in the project's folder.
Title: Editable list view with cursor row fixed to centre
Post by: Anonymous on April 24, 2006, 12:50:56 PM
Thanks people, it now works.
Title: One other idea
Post by: Mark Strickland on April 24, 2006, 04:30:02 PM
I had a similar design need and I simply built it myself.  I really did not need a grid and this worked fairly well.

I had 9 lines on the screen with line 5 (the center) being the focus line.

I defined 9 textboxes and stacked them up carefully with the proper borders and background colors to look sort of grid like (no columns).  Set the font in the center one to RED (or anything different).  I used TABSTOPS for columns but a fixed point font would also work.

I setup an array of the keys for the value in each row (1-9).

Searching and Scrolling ---

To search I did this:
Find the first item in the DB by the desired key and put it in row 5 (center).  Read 4 more forward and put them in row 6-9.  Save the keys as you fill the rows.  Go back to row 5 and use the key to read backwards 4 rows and put them in 4-1.  You wil need to handle BOF and EOF if you are near the front/end of the DB and some rows will be blank.

To scroll I did this:
To scroll up/down pick the key one from the end of the list (row 2 or 8 depending on the direction) then just read 9 records forward or backward and put them in the rows from the bottom to the top or vice versa.  Actually you have to find the first non-blank row from the top or bottom.  Scrolling is probably the trickest part of the logic.

This is a bit more code intensive (maybe) than a grid but it may be much less memory intensive since it only uses 9 text labels.  I created a few functions and it works well.  The search function requires one DB key (the center).  The scroll functions don't need any DB keys since they are in an array.

Food for thought.