Recent

Author Topic: [Solved]How to invoke help for TToolButton and TAction  (Read 3628 times)

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
[Solved]How to invoke help for TToolButton and TAction
« on: January 22, 2019, 10:45:51 pm »
Hi all!
TToolButton and TAction components have HelpContext, HelpKeyWord and HelpType properties. Apparently, it is supposed that a user can invoke help for these components by pressing F1. But when and how?

These components cannot be focused. Even if a ToolButton is pressed with a mouse and F1 is pressed simultaneously, help is invoked for previously focused component.
« Last Edit: February 07, 2019, 12:53:28 am by glorfin »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to invoke help for TToolButton and TAction
« Reply #1 on: January 22, 2019, 11:40:03 pm »
I don't know about TTolButton but TAction's properties, including help related ones, are aplied  to the control it's assigned to, p.e. a TMenuItem. IIRC, actions alone, by themselves, only respond to their shorcut.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
Re: How to invoke help for TToolButton and TAction
« Reply #2 on: January 22, 2019, 11:47:29 pm »
I don't know about TTolButton but TAction's properties, including help related ones, are aplied  to the control it's assigned to, p.e. a TMenuItem. IIRC, actions alone, by themselves, only respond to their shorcut.
And if an Action is applied to TToolButton - question remains...
« Last Edit: January 22, 2019, 11:49:24 pm by glorfin »

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: How to invoke help for TToolButton and TAction
« Reply #3 on: January 22, 2019, 11:59:54 pm »
I think this is not directly possible for a TToolButton (or TSpeedButton, or other TGraphicControl descendants). But I could imagine a special "InvokeHelpButton" which, if Checked, switches the toolbutton to a state in which they invoke the help file instead of executing the regular OnClick code. Such a scenario - which does require some programming, of course - does need the help context information.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to invoke help for TToolButton and TAction
« Reply #4 on: January 23, 2019, 12:17:10 am »
But I could imagine a special "InvokeHelpButton" which, if Checked, switches the toolbutton to a state in which they invoke the help file instead of executing the regular OnClick code.

Or a popup menu with a "help" item; much less hasle! :)

The only way you can get help directly for a control by simply presing F1 is when the control has the focus; and since TGraphicControl descendants (in general) can not have the focus ... You get the drift, don't you?
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
Re: How to invoke help for TToolButton and TAction
« Reply #5 on: January 23, 2019, 12:33:50 am »

The only way you can get help directly for a control by simply presing F1 is when the control has the focus; and since TGraphicControl descendants (in general) can not have the focus ... You get the drift, don't you?
Yes, this is exactly the problem.
Solution with popup menu overloads UI. Probably, special button could be better. I remember, in some old programs there was button which made mouse cursor to "?" and click on an element invoked help for it. Maybe I'll try to do something like this.

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
Re: How to invoke help for TToolButton and TAction
« Reply #6 on: January 23, 2019, 12:36:55 am »
So, gentlemen, thank you for the comments and suggestions. When I have working code, I'll show here the snippets.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to invoke help for TToolButton and TAction
« Reply #7 on: January 23, 2019, 01:16:01 am »
The TabStop property has been detoured in the class to not allow it to be set to TRUE..

I think this is the code I looked at before and this was done to not allow the Toolbar to gain focus which
is what you need.

 The ToolBar control needs a little work so that it can handle the Keyboard input to capture the F1 key which
then could call the selected ToolButton or where ever the cursor is hanging over to generate the correct
info.

 Toolbar does have the keyboard events in it since it is a TwinControl.

 Maybe the boys could undo the stabbing they did to the TabStop..

 There are other ways around this ofcourse, you could put a Tbutton nearby for a Help and have that focused
so that all key input goes there. within that control one could test where the mouse is hanging over and
determine which help context to call.

 Something Like a TPanel first athen place the TToolbar within that and set the tabstop for the panel and
handle the F1 hey within the Tpanel


The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to invoke help for TToolButton and TAction
« Reply #8 on: January 23, 2019, 01:40:46 am »
Toolbar does have the keyboard events in it since it is a TwinControl.
[...]

There are other ways around this ofcourse, you could put a Tbutton nearby for a Help and have that focused
so that all key input goes there. within that control one could test where the mouse is hanging over and
determine which help context to call.
[... etc ...]

You pointed at the solution and then went on with a more problematic one :)

Since the ToolBar itself has keyboard events, it would be easier to just set an OnKeyDown or OnKeyUp handler. It would have to be done in code, since they aren't published but that's not unduly onerous.

Yet another solution is to set biHelp in the form's BorderIcons and create a handler for form's OnHelp event but it's less specific.

As always: lots of options! :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
Re: How to invoke help for TToolButton and TAction
« Reply #9 on: January 23, 2019, 01:41:58 am »
I think I will try help button which sets "help mode" with subsequent use of CursorPos and ControlAtPos to get a button and its context.

Once more thank you!

Related question: it is impossible to have Help border icon for non-dialog forms, right?

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
Re: How to invoke help for TToolButton and TAction
« Reply #10 on: January 23, 2019, 01:54:29 am »
Yet another solution is to set biHelp in the form's BorderIcons and create a handler for form's OnHelp event but it's less specific.
As always: lots of options! :)

It looks like biHelp works only in dialog forms.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to invoke help for TToolButton and TAction
« Reply #11 on: January 23, 2019, 02:04:31 am »
A toolbar won't receive any key messages because you can't tab to it, you can directly set the focus however,.

I just dropped Tpanel and place a Ttoolbar in it.

Assigned the OnkeyUp event to a manual event of the panel

you can tab to the panel so it becomes focused, I changed the color of the bevel to indicate that with the
OnEnter and back to normal with the OnExit

In the keyboard event you test for the F1 key and then use the Application.MouseCOntrol  which reports
the TtoolButton, from there, you can type cast TToolButton(Application.MouseControl)……….
and do what ever you need, force the help system there.


The only true wisdom is knowing you know nothing

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
Re: How to invoke help for TToolButton and TAction
« Reply #12 on: February 07, 2019, 12:52:39 am »
As promiced, my final solution.

I defined a variable:

ToolButtonHelpContext:integer;

Then, in TMainForm.OnAppIdle:
...
MPos := ScreenToClient(Mouse.CursorPos);
  Control := ControlAtPos(MPos,[capfAllowDisabled,capfRecursive,capfAllowWinControls]);
  if Control is TToolButton then
    ToolButtonHelpContext := Control.HelpContext
  else
    ToolButtonHelpContext := 0;
....

In TMainForm, KeyPreview property is set to true, and in TMainForm.FormKeyDown:
...
VK_F1: if MainHelpContext <> 0 then
          Application.HelpContext(ToolButtonHelpContext);
   

 

TinyPortal © 2005-2018