Recent

Author Topic: [SOLVED] TTrackbar - Pointer and Cursor Keys  (Read 1105 times)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 946
  • Former Delphi 1-7, 10.2 User
[SOLVED] TTrackbar - Pointer and Cursor Keys
« on: May 18, 2020, 09:28:15 am »
I finished an AVMIDIPlayer class demo yesterday which uses a TTrackbar to vary the rate of playing the MIDI file.

I created an "OnChange" event handler and initially it seemed to work as I was using the mouse to drag the pointer around. Today I tried tabbing to the trackbar pointer and using the cursor keys - the pointer moves, but its Position property does not change unless I press the spacebar (no other keys have any effect) after moving the pointer with the cursor keys.

Is this normal?

« Last Edit: May 21, 2020, 08:23:03 am by trev »
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 946
  • Former Delphi 1-7, 10.2 User
Re: TTrackbar - Pointer and Cursor Keys
« Reply #1 on: May 19, 2020, 05:59:44 am »
Never having used a TTrackbar before, I created a minimal project (attached, defaults to Cocoa) and tested on Windows XP64 - using the cursor keys does update the TrackBar.Position in Windows, so there's an issue with the Cocoa TTRackbar.
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2515
    • havefunsoft.com
Re: TTrackbar - Pointer and Cursor Keys
« Reply #2 on: May 19, 2020, 09:15:21 pm »
TTrackBar hot keys are widgetset specific... and it might be that Cocoa doesn't have any.

The easiest way to test - find a NSSlider in an Apple's application and see if it's responsive to shortkeys
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

winni

  • Hero Member
  • *****
  • Posts: 1814
Re: TTrackbar - Pointer and Cursor Keys
« Reply #3 on: May 19, 2020, 10:38:11 pm »
Hi!

Yes - very widgetset specific. And it drives you mad if you want to use it for platform indepentend code.

The windows version does not react on application.processMessages if you change the color.
The linux version has no marks or tics.
Both look totaly different.

What Lazarus realy needs is a trackbar that draws itself.

Winni

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 946
  • Former Delphi 1-7, 10.2 User
Re: TTrackbar - Pointer and Cursor Keys
« Reply #4 on: May 20, 2020, 09:35:26 am »
@skalogryz: Aha! iTunes has sliders for its equaliser which do not respond to the cursor keys. So I guess that's the answer.

[EDIT]
I take that back - if I tab to any of the slider controls, I can set it by using the cursor keys. So, a bug in Cocoa's TTRackbar?
[/EDIT]

@winni: argh! Write once, run any^H^H^H onewhere ;)
« Last Edit: May 20, 2020, 10:06:52 am by trev »
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 946
  • Former Delphi 1-7, 10.2 User
Re: TTrackbar - Pointer and Cursor Keys
« Reply #5 on: May 20, 2020, 02:39:46 pm »
I can work around the issue with:

Code: Pascal  [Select][+][-]
  1. // Allow cursor keys to update trackbar position
  2. procedure TForm1.RateTrackBarKeyDown(Sender: TObject; var Key: Word;
  3.   Shift: TShiftState);
  4. begin
  5.   If(key = 39) then
  6.     RateTrackBar.Position := RateTrackBar.Position + 1
  7.   else if (key = 37) then
  8.     RateTrackBar.Position := RateTrackBar.Position - 1
  9.   else if (key = 38) then
  10.     RateTrackBar.Position := RateTrackBar.Position + 1
  11.   else if (key = 40) then
  12.     RateTrackBar.Position := RateTrackBar.Position - 1
  13.   else
  14.     Key := 0;
  15. end;

The issue then becomes the fact that a 32 byte block of memory is no longer being freed on quitting. This happens by merely putting the focus on the TTRackBar pointer (aka knob in macOS nomenclature) using the tab key and then quitting. So long as the pointer does not get focus, the application exits cleanly.

Also, using the mouse on the pointer also results in a  clean exit. Just not if tabbing to the pointer.

Code: [Select]
2257 memory blocks allocated : 1136468/1141064
2256 memory blocks freed     : 1136436/1141032
1 unfreed memory blocks : 32
True heap size : 1802240 (32 used in System startup)
True free heap : 1801952
Should be : 1801984
Call trace for block $000000010CD4D100 size 32
  $000000010BCCE50D
  $000000010BD65B75
  $000000010BD3DF1D
  $000000010BD3D98B
  $000000010BD091B8
  $000000010BD087B7
  $000000010BD09F10
  $000000010BD092BE
  $000000010BBD7460
  $000000010BBDF13C
  $000000010BBE0436
  $000000010BD087B7
  $000000010BD09F10
« Last Edit: May 20, 2020, 02:59:20 pm by trev »
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2515
    • havefunsoft.com
Re: TTrackbar - Pointer and Cursor Keys
« Reply #6 on: May 21, 2020, 04:42:21 am »
I can set it by using the cursor keys. So, a bug in Cocoa's TTRackbar?
hmm, i've tried Lazarus project (with a single TTrackBar on the form) and it actually works fine for macOS 10.6...

now I'm wondering if there's another Cocoa upgrade feature missed.
worked fine on macOS 10.15.4

how to replicate?
actually never mind... i think I see the issue now!
« Last Edit: May 21, 2020, 04:55:31 am by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2515
    • havefunsoft.com
Re: TTrackbar - Pointer and Cursor Keys
« Reply #7 on: May 21, 2020, 06:51:21 am »
how about r63190?

It should resolve the position updated, it doesn't fix the mem leak, though.

The mem leak is somewhat an odd issue.
It only leaks, if the control was FOCUSED at the time the window was closing.
If the slider didn't have a focus at the time, it's frees all of its memory.

I'm somewhat concerned, that this is more Cocoa's internal kitchen. LCL releases all of its "retains" to the Cocoa object. Added a bug report about it.
« Last Edit: May 21, 2020, 06:59:46 am by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 946
  • Former Delphi 1-7, 10.2 User
Re: TTrackbar - Pointer and Cursor Keys
« Reply #8 on: May 21, 2020, 08:22:39 am »
how about r63190?

It should resolve the position updated, it doesn't fix the mem leak, though.

Yes! The position is now updated. Thanks!

Quote
The mem leak is somewhat an odd issue.
It only leaks, if the control was FOCUSED at the time the window was closing.
If the slider didn't have a focus at the time, it's frees all of its memory.

I'm somewhat concerned, that this is more Cocoa's internal kitchen. LCL releases all of its "retains" to the Cocoa object. Added a bug report about it.

Meanwhile, I've worked around that memory leak with a Form1.FormCloseQuery(Form1, Query) which sets the focus to a button on termination.
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

 

TinyPortal © 2005-2018