Highlight options using K_MOUSEMOVE in TUI (aChoice, Menu To)

60 views
Skip to first unread message

Yakano

unread,
Apr 1, 2026, 6:25:26 AM (3 days ago) Apr 1
to Harbour Users
Hello everyone.

I've been using Harbour for a few years now, and I'd like to thank the great team of developers (past, present, and future) involved with the project and everyone who keeps this group alive.

I'm using a slightly outdated version, "Harbour Make (hbmk2) 3.2.0dev (r2021-04-28 18:02)," and what I'm about to say might not be entirely accurate. I apologize if that's the case.

My applications still use TUI in pure console mode, meaning with CMD running underneath and therefore without GTWVT as the interface (although I still can't control whether they close from the taskbar thumbnail; that's still pending).

Well, a while ago I decided to incorporate mouse support for certain parts of the application (we all know how much users love it), and to achieve this, I had to overcome a minor issue (https://groups.google.com/g/harbour-users/c/v2uzAoaZG3o/m/2k0iFOc3AAAJ) which I was able to resolve using a modified version of the original achoice.prg file that I called "mychoice.prg" (thanks, guys).

That initial idea, which affected aChoice(), was also implemented with the Menu To command, using my own "mymenuto.prg," modified from the original.

Today I want to contribute my humble contribution (just a couple of ideas), which work perfectly for me and which I believe the developers could incorporate into the official version (if they haven't already) so that everyone can use them if they decide to add mouse support to their TUI interface.

The goal of this code is to not only capture mouse clicks, which works well, but also capture mouse movements and highlight the options the mouse hovers over, as if it had been selected using the keyboard.

I don't have enough experience to include .dif files, so I'm writing the code to be included here...

MYCHOICE.PRG => this new code should be included...

      CASE nKeyStd == K_LDBLCLK .OR. nKeyStd == K_LBUTTONDOWN /*line 180 mychoice.prg*/
         /* previous code  */

      /* start insertion  */
      CASE nKeyStd == K_MOUSEMOVE

         IF mRow()>=nTop .and. mCol()>=nLeft .and. mRow()<=nBottom .and. mCol()<=nRight
            nAux := HitTest( nTop, nLeft, nBottom, nRight, MRow(), MCol() )
            nNewPos := nAtTop + nAux - 1
            IF Ach_Select( alSelect, nNewPos )
               IF INRANGE( nAtTop, nNewPos, nAtTop + nNumRows - 1 )
                  DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .F., nNumCols )
                  nPos := Min(nNewPos, nItems)
                  DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .T., nNumCols )
               ELSE
                  nNewPos := nPos
               ENDIF
            ELSE
               nNewPos := nPos
            ENDIF
         ENDIF
      /* end insertion  */

MYMENUTO.PRG => this new code would need to be included...

#ifdef HB_COMPAT_C53 /*line 211 mymenuto.prg*/

         /*start insertion*/
         CASE K_MOUSEMOVE
            // AITsoftware
            IF ( nMouseClik := HitTest( t_aLevel[ nPointer - 1 ], MRow(), MCol() ) ) > 0
               n := nMouseClik
            ENDIF
            EXIT
         /*end insertion*/

I'm aware that the files I have, which were the originals, may have changed, so I'm including them as well, to help locate the code if there have been any changes.

If any developer finds this useful and can incorporate it in future nightly builds, I'd be happy to abandon "my*.prg" and use the official Harbour files.

Thank you very much!

MYCHOICE.prg
MYMENUTO.prg

Yakano

unread,
Apr 1, 2026, 7:05:38 AM (3 days ago) Apr 1
to Harbour Users
Hello, again.

I'm checking out the current code and discovering Eric's (amazing) work on harbour.wiki (my respects, sir).

► src\rtl\achoice.prg

https://harbour.wiki/index.asp?page=ShowHarbourSource&T=A&ID=9720&InFrame=Y

line#186 insert:


      CASE nKeyStd == K_MOUSEMOVE

         IF mRow()>=nTop .and. mCol()>=nLeft .and. mRow()<=nBottom .and. mCol()<=nRight
            nAux := HitTest( nTop, nLeft, nBottom, nRight, MRow(), MCol() )
            nNewPos := nAtTop + nAux - 1
            IF Ach_Select( alSelect, nNewPos )
               IF INRANGE( nAtTop, nNewPos, nAtTop + nNumRows - 1 )
                  DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .F., nNumCols )
                  nPos := Min(nNewPos, nItems)
                  DispLine( acItems[ nPos ], nTop + nPos - nAtTop, nLeft, Ach_Select( alSelect, nPos ), .T., nNumCols )
               ELSE
                  nNewPos := nPos
               ENDIF
            ELSE
               nNewPos := nPos
            ENDIF
         ENDIF

►  src\rtl\menuto.prg

https://harbour.wiki/index.asp?page=ShowHarbourSource&T=F&ID=2780&InFrame=Y

line#209 insert:


            IF ( nMouseClik := HitTest( t_aLevel[ nPointer - 1 ], MRow(), MCol() ) ) > 0
               n := nMouseClik
            ENDIF
            EXIT

Pending: Learning how to use tools to offer achoice.dif and menuto.dif… (my apologies)

Regards!
Reply all
Reply to author
Forward
0 new messages